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