1""" 2 weasyprint.css.properties 3 ------------------------- 4 5 Various data about known properties. 6 7 :copyright: Copyright 2011-2019 Simon Sapin and contributors, see AUTHORS. 8 :license: BSD, see LICENSE for details. 9 10""" 11 12import collections 13 14from tinycss2.color3 import parse_color 15 16Dimension = collections.namedtuple('Dimension', ['value', 'unit']) 17 18 19# See http://www.w3.org/TR/CSS21/propidx.html 20INITIAL_VALUES = { 21 'bottom': 'auto', 22 'caption_side': 'top', 23 'clear': 'none', 24 'clip': (), # computed value for 'auto' 25 'color': parse_color('black'), # chosen by the user agent 26 # Means 'none', but allow `display: list-item` to increment the 27 # list-item counter. If we ever have a way for authors to query 28 # computed values (JavaScript?), this value should serialize to 'none'. 29 'counter_increment': 'auto', 30 'counter_reset': (), # parsed value for 'none' 31 # 'counter_set': (), # parsed value for 'none' 32 'direction': 'ltr', 33 'display': 'inline', 34 'empty_cells': 'show', 35 'float': 'none', 36 'height': 'auto', 37 'left': 'auto', 38 'line_height': 'normal', 39 'list_style_image': ('none', None), 40 'list_style_position': 'outside', 41 'list_style_type': 'disc', 42 'margin_top': Dimension(0, 'px'), 43 'margin_right': Dimension(0, 'px'), 44 'margin_bottom': Dimension(0, 'px'), 45 'margin_left': Dimension(0, 'px'), 46 'max_height': Dimension(float('inf'), 'px'), # parsed value for 'none' 47 'max_width': Dimension(float('inf'), 'px'), 48 'padding_top': Dimension(0, 'px'), 49 'padding_right': Dimension(0, 'px'), 50 'padding_bottom': Dimension(0, 'px'), 51 'padding_left': Dimension(0, 'px'), 52 'position': 'static', 53 'right': 'auto', 54 'table_layout': 'auto', 55 'top': 'auto', 56 'unicode_bidi': 'normal', 57 'vertical_align': 'baseline', 58 'visibility': 'visible', 59 'width': 'auto', 60 'z_index': 'auto', 61 62 # Backgrounds and Borders 3 (CR): https://www.w3.org/TR/css3-background/ 63 'background_attachment': ('scroll',), 64 'background_clip': ('border-box',), 65 'background_color': parse_color('transparent'), 66 'background_image': (('none', None),), 67 'background_origin': ('padding-box',), 68 'background_position': (('left', Dimension(0, '%'), 69 'top', Dimension(0, '%')),), 70 'background_repeat': (('repeat', 'repeat'),), 71 'background_size': (('auto', 'auto'),), 72 'border_bottom_color': 'currentColor', 73 'border_bottom_left_radius': (Dimension(0, 'px'), Dimension(0, 'px')), 74 'border_bottom_right_radius': (Dimension(0, 'px'), Dimension(0, 'px')), 75 'border_bottom_style': 'none', 76 'border_bottom_width': 3, 77 'border_collapse': 'separate', 78 'border_left_color': 'currentColor', 79 'border_left_style': 'none', 80 'border_left_width': 3, 81 'border_right_color': 'currentColor', 82 'border_right_style': 'none', 83 'border_right_width': 3, 84 'border_spacing': (0, 0), 85 'border_top_color': 'currentColor', 86 'border_top_left_radius': (Dimension(0, 'px'), Dimension(0, 'px')), 87 'border_top_right_radius': (Dimension(0, 'px'), Dimension(0, 'px')), 88 'border_top_style': 'none', 89 'border_top_width': 3, # computed value for 'medium' 90 91 # Color 3 (REC): https://www.w3.org/TR/css3-color/ 92 'opacity': 1, 93 94 # Multi-column Layout (WD): https://www.w3.org/TR/css-multicol-1/ 95 'column_width': 'auto', 96 'column_count': 'auto', 97 'column_gap': Dimension(1, 'em'), 98 'column_rule_color': 'currentColor', 99 'column_rule_style': 'none', 100 'column_rule_width': 'medium', 101 'column_fill': 'balance', 102 'column_span': 'none', 103 104 # Fonts 3 (REC): https://www.w3.org/TR/css-fonts-3/ 105 'font_family': ('serif',), # depends on user agent 106 'font_feature_settings': 'normal', 107 'font_kerning': 'auto', 108 'font_language_override': 'normal', 109 'font_size': 16, # actually medium, but we define medium from this 110 'font_stretch': 'normal', 111 'font_style': 'normal', 112 'font_variant': 'normal', 113 'font_variant_alternates': 'normal', 114 'font_variant_caps': 'normal', 115 'font_variant_east_asian': 'normal', 116 'font_variant_ligatures': 'normal', 117 'font_variant_numeric': 'normal', 118 'font_variant_position': 'normal', 119 'font_weight': 400, 120 121 # Fragmentation 3/4 (CR/WD): https://www.w3.org/TR/css-break-4/ 122 'box_decoration_break': 'slice', 123 'break_after': 'auto', 124 'break_before': 'auto', 125 'break_inside': 'auto', 126 'margin_break': 'auto', 127 'orphans': 2, 128 'widows': 2, 129 130 # Generated Content 3 (WD): https://www.w3.org/TR/css-content-3/ 131 'bookmark_label': (('content', 'text'),), 132 'bookmark_level': 'none', 133 'bookmark_state': 'open', 134 'content': 'normal', 135 'quotes': list('“”‘’'), # chosen by the user agent 136 'string_set': 'none', 137 138 # Images 3/4 (CR/WD): https://www.w3.org/TR/css4-images/ 139 'image_resolution': 1, # dppx 140 'image_rendering': 'auto', 141 # https://drafts.csswg.org/css-images-3/ 142 'object_fit': 'fill', 143 'object_position': (('left', Dimension(50, '%'), 144 'top', Dimension(50, '%')),), 145 146 # Paged Media 3 (WD): https://www.w3.org/TR/css-page-3/ 147 'size': None, # set to A4 in computed_values 148 'page': 'auto', 149 'bleed_left': 'auto', 150 'bleed_right': 'auto', 151 'bleed_top': 'auto', 152 'bleed_bottom': 'auto', 153 'marks': (), # computed value for 'none' 154 155 # Text 3/4 (WD/WD): https://www.w3.org/TR/css-text-4/ 156 'hyphenate_character': '‐', # computed value chosen by the user agent 157 'hyphenate_limit_chars': (5, 2, 2), 158 'hyphenate_limit_zone': Dimension(0, 'px'), 159 'hyphens': 'manual', 160 'letter_spacing': 'normal', 161 'tab_size': 8, 162 'text_align': '-weasy-start', 163 'text_indent': Dimension(0, 'px'), 164 'text_transform': 'none', 165 'white_space': 'normal', 166 'word_spacing': 0, # computed value for 'normal' 167 168 # Transforms 1 (CR): https://www.w3.org/TR/css-transforms-1/ 169 'transform_origin': (Dimension(50, '%'), Dimension(50, '%')), 170 'transform': (), # computed value for 'none' 171 172 # User Interface 3 (REC): https://www.w3.org/TR/css-ui-3/ 173 'box_sizing': 'content-box', 174 'outline_color': 'currentColor', # invert is not supported 175 'outline_style': 'none', 176 'outline_width': 3, # computed value for 'medium' 177 'overflow_wrap': 'normal', 178 179 # Flexible Box Layout Module 1 (CR): https://www.w3.org/TR/css-flexbox-1/ 180 'align_content': 'stretch', 181 'align_items': 'stretch', 182 'align_self': 'auto', 183 'flex_basis': 'auto', 184 'flex_direction': 'row', 185 'flex_grow': 0, 186 'flex_shrink': 1, 187 'flex_wrap': 'nowrap', 188 'justify_content': 'flex-start', 189 'min_height': 'auto', 190 'min_width': 'auto', 191 'order': 0, 192 193 # Text Decoration Module 3 (CR): https://www.w3.org/TR/css-text-decor-3/ 194 'text_decoration_line': 'none', 195 'text_decoration_color': 'currentColor', 196 'text_decoration_style': 'solid', 197 198 # Overflow Module 3 (WD): https://www.w3.org/TR/css-overflow-3/ 199 'overflow': 'visible', 200 'text_overflow': 'clip', 201 202 # Proprietary 203 'anchor': None, # computed value of 'none' 204 'link': None, # computed value of 'none' 205 'lang': None, # computed value of 'none' 206 207 # Internal, to implement the "static position" for absolute boxes. 208 '_weasy_specified_display': 'inline', 209} 210 211 212KNOWN_PROPERTIES = set(name.replace('_', '-') for name in INITIAL_VALUES) 213 214# Do not list shorthand properties here as we handle them before inheritance. 215# 216# text_decoration is not a really inherited, see 217# http://www.w3.org/TR/CSS2/text.html#propdef-text-decoration 218# 219# link: click events normally bubble up to link ancestors 220# See http://lists.w3.org/Archives/Public/www-style/2012Jun/0315.html 221INHERITED = { 222 'border_collapse', 223 'border_spacing', 224 'caption_side', 225 'color', 226 'direction', 227 'empty_cells', 228 'font_family', 229 'font_feature_settings', 230 'font_kerning', 231 'font_language_override', 232 'font_size', 233 'font_style', 234 'font_stretch', 235 'font_variant', 236 'font_variant_alternates', 237 'font_variant_caps', 238 'font_variant_east_asian', 239 'font_variant_ligatures', 240 'font_variant_numeric', 241 'font_variant_position', 242 'font_weight', 243 'hyphens', 244 'hyphenate_character', 245 'hyphenate_limit_chars', 246 'hyphenate_limit_zone', 247 'image_rendering', 248 'image_resolution', 249 'lang', 250 'letter_spacing', 251 'line_height', 252 'link', 253 'list_style_image', 254 'list_style_position', 255 'list_style_type', 256 'orphans', 257 'overflow_wrap', 258 'quotes', 259 'tab_size', 260 'text_align', 261 'text_decoration_line', 262 'text_decoration_color', 263 'text_decoration_style', 264 'text_indent', 265 'text_transform', 266 'visibility', 267 'white_space', 268 'widows', 269 'word_spacing', 270} 271 272# Inherited but not applicable to print: 273# azimuth 274# cursor 275# elevation 276# pitch_range 277# pitch 278# richness 279# speak_header 280# speak_numeral 281# speak_punctuation 282# speak 283# speech_rate 284# stress 285# voice_family 286# volume 287 288 289# http://www.w3.org/TR/CSS21/tables.html#model 290# See also http://lists.w3.org/Archives/Public/www-style/2012Jun/0066.html 291# Only non-inherited properties need to be included here. 292TABLE_WRAPPER_BOX_PROPERTIES = { 293 'bottom', 294 'break_after', 295 'break_before', 296 'break_inside', 297 'clear', 298 'counter_increment', 299 'counter_reset', 300 'float', 301 'left', 302 'margin_top', 303 'margin_bottom', 304 'margin_left', 305 'margin_right', 306 'opacity', 307 'overflow', 308 'position', 309 'right', 310 'top', 311 'transform', 312 'transform_origin', 313 'vertical_align', 314 'z_index', 315} 316 317 318# Properties that have an initial value that is not always the same when 319# computed. 320INITIAL_NOT_COMPUTED = { 321 'display', 322 'column_gap', 323 'bleed_top', 324 'bleed_left', 325 'bleed_bottom', 326 'bleed_right', 327 'outline_width', 328 'outline_color', 329 'column_rule_width', 330 'column_rule_color', 331 'border_top_width', 332 'border_left_width', 333 'border_bottom_width', 334 'border_right_width', 335 'border_top_color', 336 'border_left_color', 337 'border_bottom_color', 338 'border_right_color', 339} 340