1 """CSSFontFaceRule implements DOM Level 2 CSS CSSFontFaceRule.
2 """
3 __all__ = ['CSSFontFaceRule']
4 __docformat__ = 'restructuredtext'
5 __author__ = '$LastChangedBy: cthedot $'
6 __date__ = '$LastChangedDate: 2007-10-18 22:44:54 +0200 (Do, 18 Okt 2007) $'
7 __version__ = '$LastChangedRevision: 507 $'
8
9 import xml.dom
10 import cssrule
11 import cssutils
12 from cssstyledeclaration import CSSStyleDeclaration
13
15 """
16 The CSSFontFaceRule interface represents a @font-face rule in a CSS
17 style sheet. The @font-face rule is used to hold a set of font
18 descriptions.
19
20 Properties
21 ==========
22 atkeyword (cssutils only)
23 the literal keyword used
24 cssText: of type DOMString
25 The parsable textual representation of this rule
26 style: of type CSSStyleDeclaration
27 The declaration-block of this rule.
28
29 Inherits properties from CSSRule
30
31 Format
32 ======
33 ::
34
35 font_face
36 : FONT_FACE_SYM S*
37 '{' S* declaration [ ';' S* declaration ]* '}' S*
38 ;
39 """
40 type = cssrule.CSSRule.FONT_FACE_RULE
41
42 wellformed = True
43
44 - def __init__(self, style=None, parentRule=None,
45 parentStyleSheet=None, readonly=False):
61
62 - def _getCssText(self):
63 """
64 returns serialized property cssText
65 """
66 return cssutils.ser.do_CSSFontFaceRule(self)
67
68 - def _setCssText(self, cssText):
69 """
70 DOMException on setting
71
72 - SYNTAX_ERR: (self, StyleDeclaration)
73 Raised if the specified CSS string value has a syntax error and
74 is unparsable.
75 - INVALID_MODIFICATION_ERR: (self)
76 Raised if the specified CSS string value represents a different
77 type of rule than the current one.
78 - HIERARCHY_REQUEST_ERR: (CSSStylesheet)
79 Raised if the rule cannot be inserted at this point in the
80 style sheet.
81 - NO_MODIFICATION_ALLOWED_ERR: (CSSRule)
82 Raised if the rule is readonly.
83 """
84 super(CSSFontFaceRule, self)._setCssText(cssText)
85
86 tokenizer = self._tokenize2(cssText)
87 attoken = self._nexttoken(tokenizer, None)
88 if self._type(attoken) != self._prods.FONT_FACE_SYM:
89 self._log.error(u'CSSFontFaceRule: No CSSFontFaceRule found: %s' %
90 self._valuestr(cssText),
91 error=xml.dom.InvalidModificationErr)
92 else:
93 wellformed = True
94 beforetokens, brace = self._tokensupto2(tokenizer,
95 blockstartonly=True,
96 separateEnd=True)
97 if self._tokenvalue(brace) != u'{':
98 wellformed = False
99 self._log.error(
100 u'CSSFontFaceRule: No start { of style declaration found: %r' %
101 self._valuestr(cssText), brace)
102
103
104 new = {'wellformed': True}
105 newseq = self._tempSeq()
106
107 beforewellformed, expected = self._parse(expected=':',
108 seq=newseq, tokenizer=self._tokenize2(beforetokens),
109 productions={})
110 wellformed = wellformed and beforewellformed and new['wellformed']
111
112 styletokens, braceorEOFtoken = self._tokensupto2(tokenizer,
113 blockendonly=True,
114 separateEnd=True)
115
116 val, typ = self._tokenvalue(braceorEOFtoken), self._type(braceorEOFtoken)
117 if val != u'}' and typ != 'EOF':
118 wellformed = False
119 self._log.error(
120 u'CSSFontFaceRule: No "}" after style declaration found: %r' %
121 self._valuestr(cssText))
122
123 newstyle = CSSStyleDeclaration()
124 if 'EOF' == typ:
125
126 styletokens.append(braceorEOFtoken)
127 newstyle.cssText = styletokens
128
129 if wellformed:
130 self.style = newstyle
131 self._setSeq(newseq)
132
133 cssText = property(_getCssText, _setCssText,
134 doc="(DOM) The parsable textual representation of the rule.")
135
138
149
150 style = property(_getStyle, _setStyle,
151 doc="(DOM) The declaration-block of this rule set.")
152
154 return "cssutils.css.%s(style=%r)" % (
155 self.__class__.__name__, self.style.cssText)
156
158 return "<cssutils.css.%s object style=%r at 0x%x>" % (
159 self.__class__.__name__, self.style.cssText, id(self))
160