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 cssText: of type DOMString
23 The parsable textual representation of this rule
24 style: of type CSSStyleDeclaration
25 The declaration-block of this rule.
26
27 cssutils only
28 -------------
29 atkeyword:
30 the literal keyword used
31
32 Inherits properties from CSSRule
33
34 Format
35 ======
36 ::
37
38 font_face
39 : FONT_FACE_SYM S*
40 '{' S* declaration [ ';' S* declaration ]* '}' S*
41 ;
42 """
43 type = cssrule.CSSRule.FONT_FACE_RULE
44
45 - def __init__(self, style=None, parentRule=None,
46 parentStyleSheet=None, readonly=False):
65
66 - def _getCssText(self):
67 """
68 returns serialized property cssText
69 """
70 return cssutils.ser.do_CSSFontFaceRule(self)
71
72 - def _setCssText(self, cssText):
73 """
74 DOMException on setting
75
76 - SYNTAX_ERR: (self, StyleDeclaration)
77 Raised if the specified CSS string value has a syntax error and
78 is unparsable.
79 - INVALID_MODIFICATION_ERR: (self)
80 Raised if the specified CSS string value represents a different
81 type of rule than the current one.
82 - HIERARCHY_REQUEST_ERR: (CSSStylesheet)
83 Raised if the rule cannot be inserted at this point in the
84 style sheet.
85 - NO_MODIFICATION_ALLOWED_ERR: (CSSRule)
86 Raised if the rule is readonly.
87 """
88 super(CSSFontFaceRule, self)._setCssText(cssText)
89
90 tokenizer = self._tokenize2(cssText)
91 attoken = self._nexttoken(tokenizer, None)
92 if not attoken or u'@font-face' != self._tokenvalue(
93 attoken, normalize=True):
94 self._log.error(u'CSSFontFaceRule: No CSSFontFaceRule found: %s' %
95 self._valuestr(cssText),
96 error=xml.dom.InvalidModificationErr)
97 else:
98 valid = True
99 beforetokens = self._tokensupto2(tokenizer, blockstartonly=True)
100 try:
101 bracetoken = beforetokens.pop()
102 except IndexError:
103 bracetoken = None
104 if self._tokenvalue(bracetoken) != u'{':
105 valid = False
106 self._log.error(
107 u'CSSFontFaceRule: No start { of style declaration found: %r' %
108 self._valuestr(cssText), bracetoken)
109
110
111 new = {'valid': True}
112 newseq = []
113 beforevalid, expected = self._parse(expected=':',
114 seq=newseq, tokenizer=self._tokenize2(beforetokens),
115 productions={})
116 valid = valid and beforevalid and new['valid']
117
118 styletokens = self._tokensupto2(tokenizer, blockendonly=True)
119 newstyle = CSSStyleDeclaration()
120 if not styletokens:
121 valid = False
122 self._log.error(
123 u'CSSFontFaceRule: No style declaration or "}" found: %r' %
124 self._valuestr(cssText))
125
126 braceorEOFtoken = styletokens.pop()
127 val, typ = self._tokenvalue(braceorEOFtoken), self._type(braceorEOFtoken)
128 if val != u'}' and typ != 'EOF':
129 valid = False
130 self._log.error(
131 u'CSSFontFaceRule: No "}" after style declaration found: %r' %
132 self._valuestr(cssText))
133 else:
134 if 'EOF' == typ:
135
136 styletokens.append(braceorEOFtoken)
137 newstyle.cssText = styletokens
138
139 if valid:
140 self.valid = True
141 self.style = newstyle
142 self.seq = newseq
143
144 cssText = property(_getCssText, _setCssText,
145 doc="(DOM) The parsable textual representation of the rule.")
146
149
160
161 style = property(_getStyle, _setStyle,
162 doc="(DOM) The declaration-block of this rule set.")
163
165 return "cssutils.css.%s(style=%r)" % (
166 self.__class__.__name__, self.style.cssText)
167
169 return "<cssutils.css.%s object style=%r at 0x%x>" % (
170 self.__class__.__name__, self.style.cssText, id(self))
171