2011-05-10 16:37:59 +04:00
|
|
|
# coding: utf8
|
|
|
|
|
|
|
|
# WeasyPrint converts web documents (HTML, CSS, ...) to PDF.
|
2012-03-21 14:36:00 +04:00
|
|
|
# Copyright (C) 2011-2012 Simon Sapin
|
2011-05-10 16:37:59 +04:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
"""
|
2011-10-08 17:46:41 +04:00
|
|
|
Data about known CSS properties.
|
2011-05-10 16:37:59 +04:00
|
|
|
"""
|
|
|
|
|
2012-02-17 21:49:58 +04:00
|
|
|
from __future__ import division, unicode_literals
|
2011-07-21 14:31:08 +04:00
|
|
|
|
2011-08-15 16:19:33 +04:00
|
|
|
from cssutils.css import PropertyValue
|
|
|
|
|
|
|
|
|
2011-10-08 16:41:12 +04:00
|
|
|
# See http://www.w3.org/TR/CSS21/propidx.html
|
2011-11-15 21:58:43 +04:00
|
|
|
INITIAL_VALUES = {
|
|
|
|
'background_attachment': 'scroll',
|
2011-12-26 15:47:26 +04:00
|
|
|
'background_color': PropertyValue('transparent')[0],
|
2011-11-15 21:58:43 +04:00
|
|
|
'background_image': 'none',
|
2011-12-26 15:47:26 +04:00
|
|
|
'background_position': list(PropertyValue('0% 0%')),
|
2011-11-15 21:58:43 +04:00
|
|
|
'background_repeat': 'repeat',
|
2012-01-30 20:23:25 +04:00
|
|
|
'background_clip': 'border-box', # CSS3
|
|
|
|
'background_origin': 'padding-box', # CSS3
|
2012-01-31 14:45:24 +04:00
|
|
|
'background_size': ('auto', 'auto'), # CSS3
|
2011-11-15 21:58:43 +04:00
|
|
|
'border_collapse': 'separate',
|
2011-10-08 16:41:12 +04:00
|
|
|
# http://www.w3.org/TR/css3-color/#currentcolor
|
2011-11-15 21:58:43 +04:00
|
|
|
'border_top_color': 'currentColor',
|
|
|
|
'border_right_color': 'currentColor',
|
|
|
|
'border_bottom_color': 'currentColor',
|
|
|
|
'border_left_color': 'currentColor',
|
2011-11-22 16:06:50 +04:00
|
|
|
'border_spacing': (0, 0),
|
2011-11-15 21:58:43 +04:00
|
|
|
'border_top_style': 'none',
|
|
|
|
'border_right_style': 'none',
|
|
|
|
'border_bottom_style': 'none',
|
|
|
|
'border_left_style': 'none',
|
2011-12-16 20:53:11 +04:00
|
|
|
'border_top_width': 3, # Computed value for 'medium'
|
|
|
|
'border_right_width': 3,
|
|
|
|
'border_bottom_width': 3,
|
|
|
|
'border_left_width': 3,
|
2011-10-08 16:41:12 +04:00
|
|
|
'bottom': 'auto',
|
2011-11-15 21:58:43 +04:00
|
|
|
'caption_side': 'top',
|
2011-10-08 16:41:12 +04:00
|
|
|
'clear': 'none',
|
2012-02-07 21:06:59 +04:00
|
|
|
'clip': (), # empty collection, computed value for 'auto'
|
2011-12-26 15:47:26 +04:00
|
|
|
'color': PropertyValue('#000')[0], # depends on user agent
|
2011-10-08 16:41:12 +04:00
|
|
|
'content': 'normal',
|
2011-12-08 12:56:55 +04:00
|
|
|
# Means 'none', but allow `display: list-item` to increment the
|
|
|
|
# list-item counter. If we ever have a way for authors to query
|
|
|
|
# computed values (JavaScript?), this value should serialize to 'none'.
|
|
|
|
'counter_increment': 'auto',
|
2011-12-07 20:09:59 +04:00
|
|
|
'counter_reset': [], # parsed value for 'none'
|
|
|
|
# 'counter_set': [], # parsed value for 'none'
|
2011-10-08 16:41:12 +04:00
|
|
|
'direction': 'ltr',
|
|
|
|
'display': 'inline',
|
2011-11-15 21:58:43 +04:00
|
|
|
'empty_cells': 'show',
|
2011-10-08 16:41:12 +04:00
|
|
|
'float': 'none',
|
2011-11-15 21:58:43 +04:00
|
|
|
'font_family': ['serif'], # depends on user agent
|
2011-12-16 18:18:47 +04:00
|
|
|
'font_size': 16, # Actually medium, but we define medium from this.
|
2011-11-15 21:58:43 +04:00
|
|
|
'font_style': 'normal',
|
|
|
|
'font_variant': 'normal',
|
2011-12-16 18:18:47 +04:00
|
|
|
'font_weight': 400,
|
2011-10-08 16:41:12 +04:00
|
|
|
'height': 'auto',
|
|
|
|
'left': 'auto',
|
2011-11-15 21:58:43 +04:00
|
|
|
'letter_spacing': 'normal',
|
|
|
|
'line_height': 'normal',
|
|
|
|
'list_style_image': 'none',
|
|
|
|
'list_style_position': 'outside',
|
|
|
|
'list_style_type': 'disc',
|
|
|
|
'margin_top': 0,
|
|
|
|
'margin_right': 0,
|
|
|
|
'margin_bottom': 0,
|
|
|
|
'margin_left': 0,
|
|
|
|
'max_height': 'none',
|
|
|
|
'max_width': 'none',
|
|
|
|
'min_height': 0,
|
|
|
|
'min_width': 0,
|
2011-10-08 16:41:12 +04:00
|
|
|
'orphans': 2,
|
|
|
|
'overflow': 'visible',
|
2011-11-15 21:58:43 +04:00
|
|
|
'padding_top': 0,
|
|
|
|
'padding_right': 0,
|
|
|
|
'padding_bottom': 0,
|
|
|
|
'padding_left': 0,
|
|
|
|
'page_break_after': 'auto',
|
|
|
|
'page_break_before': 'auto',
|
|
|
|
'page_break_inside': 'auto',
|
2012-02-17 21:49:58 +04:00
|
|
|
'quotes': list('“”‘’'), # depends on user agent
|
2011-10-08 16:41:12 +04:00
|
|
|
'position': 'static',
|
|
|
|
'right': 'auto',
|
2011-11-15 21:58:43 +04:00
|
|
|
'table_layout': 'auto',
|
2011-12-16 19:02:49 +04:00
|
|
|
'text_align': '-weasy-start', # Taken from CSS3 Text.
|
|
|
|
# The only other supported value form CSS3 is -weasy-end.
|
2011-11-15 21:58:43 +04:00
|
|
|
'text_decoration': 'none',
|
|
|
|
'text_indent': 0,
|
|
|
|
'text_transform': 'none',
|
2011-10-08 16:41:12 +04:00
|
|
|
'top': 'auto',
|
2011-11-15 21:58:43 +04:00
|
|
|
'unicode_bidi': 'normal',
|
2011-11-23 21:23:33 +04:00
|
|
|
'vertical_align': 'baseline',
|
2011-10-08 16:41:12 +04:00
|
|
|
'visibility': 'visible',
|
2011-11-15 21:58:43 +04:00
|
|
|
'white_space': 'normal',
|
2011-10-08 16:41:12 +04:00
|
|
|
'widows': 2,
|
|
|
|
'width': 'auto',
|
2012-02-01 19:13:47 +04:00
|
|
|
'word_spacing': 0, # computed value for 'normal'
|
2011-11-15 21:58:43 +04:00
|
|
|
'z_index': 'auto',
|
2011-08-15 16:19:33 +04:00
|
|
|
|
2011-10-08 16:41:12 +04:00
|
|
|
# CSS3 Paged Media: http://www.w3.org/TR/css3-page/#page-size
|
2011-12-16 18:06:59 +04:00
|
|
|
'size': None, # XXX set to A4 in computed_values
|
2011-11-21 17:25:43 +04:00
|
|
|
|
|
|
|
# CSS3 User Interface: http://www.w3.org/TR/css3-ui/#box-sizing
|
|
|
|
'box_sizing': 'content-box',
|
2012-01-31 14:45:24 +04:00
|
|
|
|
2012-02-07 21:26:23 +04:00
|
|
|
# CSS3 Color: http://www.w3.org/TR/css3-color/#transparency
|
|
|
|
'opacity': 1,
|
|
|
|
|
2012-02-08 18:44:03 +04:00
|
|
|
# CSS3 2D Transforms: http://www.w3.org/TR/css3-2d-transforms
|
|
|
|
'transform_origin': list(PropertyValue('50% 50%')),
|
|
|
|
'transform': (), # computed value for 'none'
|
|
|
|
|
2012-01-31 14:45:24 +04:00
|
|
|
# Taken from SVG:
|
|
|
|
# http://www.w3.org/TR/SVG/painting.html#ImageRenderingProperty
|
|
|
|
'image_rendering': 'auto',
|
2011-11-15 21:58:43 +04:00
|
|
|
}
|
2011-08-15 16:19:33 +04:00
|
|
|
|
|
|
|
# Not applicable to the print media
|
2011-11-15 21:58:43 +04:00
|
|
|
NOT_PRINT_MEDIA = set([
|
2011-08-15 16:19:33 +04:00
|
|
|
# Aural media:
|
|
|
|
'azimuth',
|
|
|
|
'cue',
|
2011-11-15 21:58:43 +04:00
|
|
|
'cue_after',
|
|
|
|
'cue_before',
|
2011-08-15 16:19:33 +04:00
|
|
|
'cursor',
|
|
|
|
'elevation',
|
|
|
|
'pause',
|
2011-11-15 21:58:43 +04:00
|
|
|
'pause_after',
|
|
|
|
'pause_before',
|
|
|
|
'pitch_range',
|
2011-08-15 16:19:33 +04:00
|
|
|
'pitch',
|
2011-11-15 21:58:43 +04:00
|
|
|
'play_during',
|
2011-08-15 16:19:33 +04:00
|
|
|
'richness',
|
2011-11-15 21:58:43 +04:00
|
|
|
'speak_header',
|
|
|
|
'speak_numeral',
|
|
|
|
'speak_punctuation',
|
2011-08-15 16:19:33 +04:00
|
|
|
'speak',
|
2011-11-15 21:58:43 +04:00
|
|
|
'speech_rate',
|
2011-08-15 16:19:33 +04:00
|
|
|
'stress',
|
2011-11-15 21:58:43 +04:00
|
|
|
'voice_family',
|
2011-08-15 16:19:33 +04:00
|
|
|
'volume',
|
|
|
|
|
|
|
|
# Outlines only apply to interactive media, just like cursor.
|
|
|
|
'outline'
|
2011-11-15 21:58:43 +04:00
|
|
|
'outline_color',
|
|
|
|
'outline_style',
|
|
|
|
'outline_width',
|
2011-08-15 16:19:33 +04:00
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
# Do not list shorthand properties here as we handle them before inheritance.
|
|
|
|
#
|
2011-11-15 21:58:43 +04:00
|
|
|
# text_decoration is not a really inherited, see
|
2011-08-15 16:19:33 +04:00
|
|
|
# http://www.w3.org/TR/CSS2/text.html#propdef-text-decoration
|
2011-11-15 21:58:43 +04:00
|
|
|
INHERITED = set("""
|
|
|
|
border_collapse
|
|
|
|
border_spacing
|
|
|
|
caption_side
|
2011-08-15 16:19:33 +04:00
|
|
|
color
|
|
|
|
direction
|
2011-11-15 21:58:43 +04:00
|
|
|
empty_cells
|
|
|
|
font_family
|
|
|
|
font_size
|
|
|
|
font_style
|
|
|
|
font_variant
|
|
|
|
font_weight
|
|
|
|
letter_spacing
|
|
|
|
line_height
|
|
|
|
list_style_image
|
|
|
|
list_style_position
|
|
|
|
list_style_type
|
2011-08-15 16:19:33 +04:00
|
|
|
orphans
|
|
|
|
quotes
|
2011-11-15 21:58:43 +04:00
|
|
|
text_align
|
|
|
|
text_decoration
|
|
|
|
text_indent
|
|
|
|
text_transform
|
2011-08-15 16:19:33 +04:00
|
|
|
visibility
|
2011-11-15 21:58:43 +04:00
|
|
|
white_space
|
2011-08-15 16:19:33 +04:00
|
|
|
widows
|
2011-11-15 21:58:43 +04:00
|
|
|
word_spacing
|
2012-02-08 18:44:03 +04:00
|
|
|
|
|
|
|
image_rendering
|
2011-08-15 16:19:33 +04:00
|
|
|
""".split())
|
|
|
|
|
|
|
|
# Inherited but not applicable to print:
|
|
|
|
# azimuth
|
|
|
|
# cursor
|
|
|
|
# elevation
|
2011-11-15 21:58:43 +04:00
|
|
|
# pitch_range
|
2011-08-15 16:19:33 +04:00
|
|
|
# pitch
|
|
|
|
# richness
|
2011-11-15 21:58:43 +04:00
|
|
|
# speak_header
|
|
|
|
# speak_numeral
|
|
|
|
# speak_punctuation
|
2011-08-15 16:19:33 +04:00
|
|
|
# speak
|
2011-11-15 21:58:43 +04:00
|
|
|
# speech_rate
|
2011-08-15 16:19:33 +04:00
|
|
|
# stress
|
2011-11-15 21:58:43 +04:00
|
|
|
# voice_family
|
2011-08-15 16:19:33 +04:00
|
|
|
# volume
|
2011-11-15 21:58:43 +04:00
|
|
|
|
|
|
|
|
|
|
|
# http://www.w3.org/TR/CSS21/tables.html#model
|
|
|
|
TABLE_WRAPPER_BOX_PROPERTIES = set('''
|
|
|
|
position
|
|
|
|
float
|
|
|
|
margin_top
|
|
|
|
margin_bottom
|
|
|
|
margin_left
|
|
|
|
margin_right
|
|
|
|
top
|
|
|
|
bottom
|
|
|
|
left
|
|
|
|
right
|
|
|
|
'''.split())
|
2012-01-27 19:53:16 +04:00
|
|
|
|
|
|
|
|
|
|
|
BACKGROUND_INITIAL = dict(
|
2012-02-17 21:49:58 +04:00
|
|
|
(name, value) for name, value in INITIAL_VALUES.items()
|
2012-01-27 19:53:16 +04:00
|
|
|
if name.startswith('background'))
|