Package cssutils :: Package css :: Module cssfontfacerule
[hide private]
[frames] | no frames]

Source Code for Module cssutils.css.cssfontfacerule

  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   
14 -class CSSFontFaceRule(cssrule.CSSRule):
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):
47 """ 48 if readonly allows setting of properties in constructor only 49 50 style 51 CSSStyleDeclaration for this CSSStyleRule 52 """ 53 super(CSSFontFaceRule, self).__init__(parentRule=parentRule, 54 parentStyleSheet=parentStyleSheet) 55 56 self.atkeyword = u'@font-face' 57 58 if style: 59 self.style = style 60 self.seq.append(self.style) 61 else: 62 self._style = CSSStyleDeclaration(parentRule=self) 63 64 self._readonly = readonly
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 # parse stuff before { which should be comments and S only 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 # add again as style needs it 136 styletokens.append(braceorEOFtoken) 137 newstyle.cssText = styletokens 138 139 if valid: 140 self.valid = True 141 self.style = newstyle 142 self.seq = newseq # contains upto { only
143 144 cssText = property(_getCssText, _setCssText, 145 doc="(DOM) The parsable textual representation of the rule.") 146
147 - def _getStyle(self):
148 return self._style
149
150 - def _setStyle(self, style):
151 """ 152 style 153 StyleDeclaration or string 154 """ 155 self._checkReadonly() 156 if isinstance(style, basestring): 157 self._style = CSSStyleDeclaration(parentRule=self, cssText=style) 158 else: 159 self._style.seq = style.seq
160 161 style = property(_getStyle, _setStyle, 162 doc="(DOM) The declaration-block of this rule set.") 163
164 - def __repr__(self):
165 return "cssutils.css.%s(style=%r)" % ( 166 self.__class__.__name__, self.style.cssText)
167
168 - def __str__(self):
169 return "<cssutils.css.%s object style=%r at 0x%x>" % ( 170 self.__class__.__name__, self.style.cssText, id(self))
171