4 * Transforms FONT tags to the proper form (SPAN with CSS styling)
6 * This transformation takes the three proprietary attributes of FONT and
7 * transforms them into their corresponding CSS attributes. These are color,
10 * @note Size is an interesting case because it doesn't map cleanly to CSS.
12 * http://style.cleverchimp.com/font_size_intervals/altintervals.html
13 * for reasonable mappings.
14 * @warning This doesn't work completely correctly; specifically, this
15 * TagTransform operates before well-formedness is enforced, so
16 * the "active formatting elements" algorithm doesn't get applied.
18 class HTMLPurifier_TagTransform_Font extends HTMLPurifier_TagTransform
21 public $transform_to = 'span';
23 protected $_size_lookup = array(
40 public function transform($tag, $config, $context) {
42 if ($tag instanceof HTMLPurifier_Token_End) {
43 $new_tag = clone $tag;
44 $new_tag->name = $this->transform_to;
51 // handle color transform
52 if (isset($attr['color'])) {
53 $prepend_style .= 'color:' . $attr['color'] . ';';
54 unset($attr['color']);
57 // handle face transform
58 if (isset($attr['face'])) {
59 $prepend_style .= 'font-family:' . $attr['face'] . ';';
63 // handle size transform
64 if (isset($attr['size'])) {
65 // normalize large numbers
66 if ($attr['size']{0} == '+' || $attr['size']{0} == '-') {
67 $size = (int) $attr['size'];
68 if ($size < -2) $attr['size'] = '-2';
69 if ($size > 4) $attr['size'] = '+4';
71 $size = (int) $attr['size'];
72 if ($size > 7) $attr['size'] = '7';
74 if (isset($this->_size_lookup[$attr['size']])) {
75 $prepend_style .= 'font-size:' .
76 $this->_size_lookup[$attr['size']] . ';';
82 $attr['style'] = isset($attr['style']) ?
83 $prepend_style . $attr['style'] :
87 $new_tag = clone $tag;
88 $new_tag->name = $this->transform_to;
89 $new_tag->attr = $attr;