1<?php
2// $Header: /cvsroot/html2ps/css.list-style-type.inc.php,v 1.13 2006/09/07 18:38:14 Konstantin Exp $
3
4// FIXME: supported only partially
5define('LST_NONE',0);
6define('LST_DISC',1);
7define('LST_CIRCLE',2);
8define('LST_SQUARE',3);
9define('LST_DECIMAL',4);
10define('LST_DECIMAL_LEADING_ZERO',5);
11define('LST_LOWER_ROMAN',6);
12define('LST_UPPER_ROMAN',7);
13define('LST_LOWER_LATIN',8);
14define('LST_UPPER_LATIN',9);
15
16class CSSListStyleType extends CSSSubFieldProperty {
17  // CSS 2.1: default value for list-style-type is 'disc'
18  function default_value() { return LST_DISC; }
19
20  function parse($value) {
21    if (preg_match('/\bnone\b/',$value))    { return LST_NONE; };
22    if (preg_match('/\bdisc\b/',$value))    { return LST_DISC; };
23    if (preg_match('/\bcircle\b/',$value))  { return LST_CIRCLE; };
24    if (preg_match('/\bsquare\b/',$value))  { return LST_SQUARE; };
25    if (preg_match('/\bdecimal-leading-zero\b/',$value)) { return LST_DECIMAL_LEADING_ZERO; }
26    if (preg_match('/\bdecimal\b/',$value)) { return LST_DECIMAL; };
27    if (preg_match('/\blower-roman\b/',$value)) { return LST_LOWER_ROMAN; }
28    if (preg_match('/\bupper-roman\b/',$value)) { return LST_UPPER_ROMAN; }
29    if (preg_match('/\blower-latin\b/',$value)) { return LST_LOWER_LATIN; }
30    if (preg_match('/\bupper-latin\b/',$value)) { return LST_UPPER_LATIN; }
31    if (preg_match('/\blower-alpha\b/',$value)) { return LST_LOWER_LATIN; }
32    if (preg_match('/\bupper-alpha\b/',$value)) { return LST_UPPER_LATIN; }
33
34    // Unsupported CSS values:
35    // According to CSS 2.1 specs 12.6.2, a user agent that does not recognize a numbering system should use 'decimal'.
36    if (preg_match('/\bhebrew\b/',$value)) { return LST_DECIMAL; };
37    if (preg_match('/\bgeorgian\b/',$value)) { return LST_DECIMAL; };
38    if (preg_match('/\barmenian\b/',$value)) { return LST_DECIMAL; };
39    if (preg_match('/\bcjk-ideographic\b/',$value)) { return LST_DECIMAL; };
40    if (preg_match('/\bhiragana\b/',$value)) { return LST_DECIMAL; };
41    if (preg_match('/\bkarakana\b/',$value)) { return LST_DECIMAL; };
42    if (preg_match('/\bhiragana-iroha\b/',$value)) { return LST_DECIMAL; };
43    if (preg_match('/\bkatakana-iroha\b/',$value)) { return LST_DECIMAL; };
44    if (preg_match('/\blower-greek\b/',$value)) { return LST_DECIMAL; };
45
46    return null;
47  }
48
49  function format_number($type,$num) {
50    // NOTE: according to CSS 2.1 specs 12.6.2, "This specification does not define how alphabetic systems wrap
51    // at the end of the alphabet. For instance, after 26 list items, 'lower-latin' rendering is undefined.
52    // Therefore, for long lists, we recommend that authors specify true numbers.".
53    // In our case we chose just to wrap over the beginning of alphabet (so, 'a' will again appear after 'z')
54    //
55    // Also, we're hoping that encoding we're using contains character codes in alphabetic order
56    // It is true for ASCII, but there's some other crazy encodings... :-)
57    //
58    // Also, I really do not understand _WHY_ PHP is spewing a lot of notice messages complaining about
59    // undefined constants if I'm using the equivalent 'switch' construct instead of 'if'
60    switch ($type) {
61    case LST_DECIMAL:
62      return $num;
63    case LST_DECIMAL_LEADING_ZERO:
64      return sprintf("%02d",$num);
65    case LST_LOWER_LATIN:
66      return chr(ord('a')+($num-1) % 26);
67    case LST_UPPER_LATIN:
68      return chr(ord('A')+($num-1) % 26);
69    case LST_LOWER_ROMAN:
70      return strtolower(arabic_to_roman($num));
71    case LST_UPPER_ROMAN:
72      return arabic_to_roman($num);
73    default:
74      return "";
75    }
76  }
77
78  function get_property_code() {
79    return CSS_LIST_STYLE_TYPE;
80  }
81
82  function get_property_name() {
83    return 'list-style-type';
84  }
85}
86
87?>