/usr/share/pyshared/sx/w3c/cssSpecial.py is in python-pisa 3.0.32-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | # -*- coding: ISO-8859-1 -*-
#############################################
## (C)opyright by Dirk Holtwick, 2002-2007 ##
## All rights reserved ##
#############################################
__reversion__ = "$Revision: 20 $"
__author__ = "$Author: holtwick $"
__date__ = "$Date: 2007-10-09 12:58:24 +0200 (Di, 09 Okt 2007) $"
"""
Helper for complex CSS definitons like font, margin, padding and border
Optimized for use with PISA
"""
import types
import logging
log = logging.getLogger("ho.css")
def toList(value):
if type(value)!=types.ListType:
return [value]
return value
_styleTable = {
"normal": "",
"italic": "",
"oblique": "",
}
_variantTable = {
"normal": None,
"small-caps": None,
}
_weightTable = {
"light": 300,
"lighter": 300, # fake relativness for now
"normal": 400,
"bold": 700,
"bolder": 700, # fake relativness for now
"100": 100,
"200": 200,
"300": 300,
"400": 400,
"500": 500,
"600": 600,
"700": 700,
"800": 800,
"900": 900,
#wx.LIGHT: 300,
#wx.NORMAL: 400,
#wx.BOLD: 700,
}
#_absSizeTable = {
# "xx-small" : 3./5.,
# "x-small": 3./4.,
# "small": 8./9.,
# "medium": 1./1.,
# "large": 6./5.,
# "x-large": 3./2.,
# "xx-large": 2./1.,
# "xxx-large": 3./1.,
# "larger": 1.25, # XXX Not totaly CSS conform:
# "smaller": 0.75, # http://www.w3.org/TR/CSS21/fonts.html#propdef-font-size
# }
_borderStyleTable = {
"none": 0,
"hidden": 0,
"dotted": 1,
"dashed": 1,
"solid": 1,
"double": 1,
"groove": 1,
"ridge": 1,
"inset": 1,
"outset": 1,
}
'''
_relSizeTable = {
'pt':
# pt: absolute point size
# Note: this is 1/72th of an inch
(lambda value, pt: value),
'px':
# px: pixels, relative to the viewing device
# Note: approximate at the size of a pt
(lambda value, pt: value),
'ex':
# ex: proportional to the 'x-height' of the parent font
# Note: can't seem to dervie this value from wx.Font methods,
# so we'll approximate by calling it 1/2 a pt
(lambda value, pt: 2 * value),
'pc':
# pc: 12:1 pica:point size
# Note: this is 1/6th of an inch
(lambda value, pt: 12*value),
'in':
# in: 72 inches per point
(lambda value, pt: 72*value),
'cm':
# in: 72 inches per point, 2.54 cm per inch
(lambda value, pt,_r=72./2.54: _r*value),
'mm':
# in: 72 inches per point, 25.4 mm per inch
(lambda value, pt,_r=72./25.4: _r*value),
'%':
# %: percentage of the parent's pointSize
(lambda value, pt: 0.01 * pt * value),
'em':
# em: proportional to the 'font-size' of the parent font
(lambda value, pt: pt * value),
}
'''
def getNextPart(parts):
if parts:
part = parts.pop(0)
else:
part = None
return part
def isSize(value):
return value and ((type(value) is types.TupleType) or value=="0")
def splitBorder(parts):
"""
The order of the elements seems to be of no importance:
http://www.w3.org/TR/CSS21/box.html#border-shorthand-properties
"""
width = style = color = None
copy_parts = parts[:]
# part = getNextPart(parts)
if len(parts)>3:
log.warn("To many elements for border style %r", parts)
for part in parts:
# Width
if isSize(part):
width = part
# part = getNextPart(parts)
# Style
elif _borderStyleTable.has_key(part.lower()):
style = part
# part = getNextPart(parts)
# Color
else:
color = part
# log.debug("Border styles: %r -> %r ", copy_parts, (width, style, color))
return (width, style, color)
def parseSpecialRules(declarations, debug=0):
# print selectors, declarations
# CSS MODIFY!
dd = []
for d in declarations:
if debug:
log.debug("CSS special IN: %r", d)
name, parts, last = d
oparts = parts
parts = toList(parts)
# FONT
if name == "font":
# [ [ <'font-style'> || <'font-variant'> || <'font-weight'> ]? <'font-size'> [ / <'line-height'> ]? <'font-family'> ] | inherit
ddlen = len(dd)
part = getNextPart(parts)
# Style
if part and _styleTable.has_key(part):
dd.append(("font-style", part, last))
part = getNextPart(parts)
# Variant
if part and _variantTable.has_key(part):
dd.append(("font-variant", part, last))
part = getNextPart(parts)
# Weight
if part and _weightTable.has_key(part):
dd.append(("font-weight", part, last))
part = getNextPart(parts)
# Size and Line Height
if isinstance(part, tuple) and len(part) == 3:
fontSize, slash, lineHeight = part
assert slash == '/'
dd.append(("font-size", fontSize, last))
dd.append(("line-height", lineHeight, last))
else:
dd.append(("font-size", part, last))
# Face/ Family
dd.append(("font-face", parts, last))
# BACKGROUND
elif name == "background":
# [<'background-color'> || <'background-image'> || <'background-repeat'> || <'background-attachment'> || <'background-position'>] | inherit
# XXX We do not receive url() and parts list, so we go for a dirty work arround
part = getNextPart(parts) or oparts
if part:
if ("." in part) or ("data:" in part):
dd.append(("background-image", part, last))
else:
dd.append(("background-color", part, last))
if 0:
part = getNextPart(parts) or oparts
print "~", part, parts, oparts, declarations
# Color
if part and (not part.startswith("url")):
dd.append(("background-color", part, last))
part = getNextPart(parts)
# Background
if part:
dd.append(("background-image", part, last))
# XXX Incomplete! Error in url()!
# MARGIN
elif name == "margin":
if len(parts)==1:
top = bottom = left = right = parts[0]
elif len(parts)==2:
top = bottom = parts[0]
left = right = parts[1]
elif len(parts)==3:
top = parts[0]
left = right = parts[1]
bottom = parts[2]
elif len(parts)==4:
top = parts[0]
right = parts[1]
bottom = parts[2]
left = parts[3]
else:
continue
dd.append(("margin-left", left, last))
dd.append(("margin-right", right, last))
dd.append(("margin-top", top, last))
dd.append(("margin-bottom", bottom, last))
# PADDING
elif name == "padding":
if len(parts)==1:
top = bottom = left = right = parts[0]
elif len(parts)==2:
top = bottom = parts[0]
left = right = parts[1]
elif len(parts)==3:
top = parts[0]
left = right = parts[1]
bottom = parts[2]
elif len(parts)==4:
top = parts[0]
right = parts[1]
bottom = parts[2]
left = parts[3]
else:
continue
dd.append(("padding-left", left, last))
dd.append(("padding-right", right, last))
dd.append(("padding-top", top, last))
dd.append(("padding-bottom", bottom, last))
# BORDER WIDTH
elif name == "border-width":
if len(parts)==1:
top = bottom = left = right = parts[0]
elif len(parts)==2:
top = bottom = parts[0]
left = right = parts[1]
elif len(parts)==3:
top = parts[0]
left = right = parts[1]
bottom = parts[2]
elif len(parts)==4:
top = parts[0]
right = parts[1]
bottom = parts[2]
left = parts[3]
else:
continue
dd.append(("border-left-width", left, last))
dd.append(("border-right-width", right, last))
dd.append(("border-top-width", top, last))
dd.append(("border-bottom-width", bottom, last))
# BORDER COLOR
elif name == "border-color":
if len(parts)==1:
top = bottom = left = right = parts[0]
elif len(parts)==2:
top = bottom = parts[0]
left = right = parts[1]
elif len(parts)==3:
top = parts[0]
left = right = parts[1]
bottom = parts[2]
elif len(parts)==4:
top = parts[0]
right = parts[1]
bottom = parts[2]
left = parts[3]
else:
continue
dd.append(("border-left-color", left, last))
dd.append(("border-right-color", right, last))
dd.append(("border-top-color", top, last))
dd.append(("border-bottom-color", bottom, last))
# BORDER STYLE
elif name == "border-style":
if len(parts)==1:
top = bottom = left = right = parts[0]
elif len(parts)==2:
top = bottom = parts[0]
left = right = parts[1]
elif len(parts)==3:
top = parts[0]
left = right = parts[1]
bottom = parts[2]
elif len(parts)==4:
top = parts[0]
right = parts[1]
bottom = parts[2]
left = parts[3]
else:
continue
dd.append(("border-left-style", left, last))
dd.append(("border-right-style", right, last))
dd.append(("border-top-style", top, last))
dd.append(("border-bottom-style", bottom, last))
# BORDER
elif name == "border":
width, style, color = splitBorder(parts)
if width is not None:
dd.append(("border-left-width", width, last))
dd.append(("border-right-width", width, last))
dd.append(("border-top-width", width, last))
dd.append(("border-bottom-width", width, last))
if style is not None:
dd.append(("border-left-style", style, last))
dd.append(("border-right-style", style, last))
dd.append(("border-top-style", style, last))
dd.append(("border-bottom-style", style, last))
if color is not None:
dd.append(("border-left-color", color, last))
dd.append(("border-right-color", color, last))
dd.append(("border-top-color", color, last))
dd.append(("border-bottom-color", color, last))
# BORDER TOP, BOTTOM, LEFT, RIGHT
elif name in ("border-top", "border-bottom", "border-left", "border-right"):
direction = name[7:]
width, style, color = splitBorder(parts)
# print direction, width
if width is not None:
dd.append(("border-" + direction + "-width", width, last))
if style is not None:
dd.append(("border-" + direction + "-style", style, last))
if color is not None:
dd.append(("border-" + direction + "-color", color, last))
# REST
else:
dd.append(d)
if debug and dd:
log.debug("CSS special OUT:\n%s", "\n".join([repr(d) for d in dd]))
if 0: #declarations!=dd:
print "###", declarations
print "#->", dd
# CSS MODIFY! END
return dd
#import re
#_rxhttp = re.compile(r"url\([\'\"]?http\:\/\/[^\/]", re.IGNORECASE|re.DOTALL)
def cleanupCSS(src):
# src = _rxhttp.sub('url(', src)
return src
|