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
23 public $transform_to = 'span';
28 protected $_size_lookup = array(
46 * @param HTMLPurifier_Token_Tag $tag
47 * @param HTMLPurifier_Config $config
48 * @param HTMLPurifier_Context $context
49 * @return HTMLPurifier_Token_End|string
51 public function transform($tag, $config, $context)
53 if ($tag instanceof HTMLPurifier_Token_End
) {
54 $new_tag = clone $tag;
55 $new_tag->name
= $this->transform_to
;
62 // handle color transform
63 if (isset($attr['color'])) {
64 $prepend_style .= 'color:' . $attr['color'] . ';';
65 unset($attr['color']);
68 // handle face transform
69 if (isset($attr['face'])) {
70 $prepend_style .= 'font-family:' . $attr['face'] . ';';
74 // handle size transform
75 if (isset($attr['size'])) {
76 // normalize large numbers
77 if ($attr['size'] !== '') {
78 if ($attr['size']{0} == '+' ||
$attr['size']{0} == '-') {
79 $size = (int)$attr['size'];
87 $size = (int)$attr['size'];
93 if (isset($this->_size_lookup
[$attr['size']])) {
94 $prepend_style .= 'font-size:' .
95 $this->_size_lookup
[$attr['size']] . ';';
100 if ($prepend_style) {
101 $attr['style'] = isset($attr['style']) ?
102 $prepend_style . $attr['style'] :
106 $new_tag = clone $tag;
107 $new_tag->name
= $this->transform_to
;
108 $new_tag->attr
= $attr;
114 // vim: et sw=4 sts=4