3 require_once 'HTMLPurifier/TagTransform.php';
6 * Transforms FONT tags to the proper form (SPAN with CSS styling)
8 * This transformation takes the three proprietary attributes of FONT and
9 * transforms them into their corresponding CSS attributes. These are color,
12 * @note Size is an interesting case because it doesn't map cleanly to CSS.
14 * http://style.cleverchimp.com/font_size_intervals/altintervals.html
15 * for reasonable mappings.
17 class HTMLPurifier_TagTransform_Font
extends HTMLPurifier_TagTransform
20 var $transform_to = 'span';
22 var $_size_lookup = array(
39 function transform($tag, $config, &$context) {
41 if ($tag->type
== 'end') {
42 $new_tag = new HTMLPurifier_Token_End($this->transform_to
);
49 // handle color transform
50 if (isset($attr['color'])) {
51 $prepend_style .= 'color:' . $attr['color'] . ';';
52 unset($attr['color']);
55 // handle face transform
56 if (isset($attr['face'])) {
57 $prepend_style .= 'font-family:' . $attr['face'] . ';';
61 // handle size transform
62 if (isset($attr['size'])) {
63 // normalize large numbers
64 if ($attr['size']{0} == '+' ||
$attr['size']{0} == '-') {
65 $size = (int) $attr['size'];
66 if ($size < -2) $attr['size'] = '-2';
67 if ($size > 4) $attr['size'] = '+4';
69 $size = (int) $attr['size'];
70 if ($size > 7) $attr['size'] = '7';
72 if (isset($this->_size_lookup
[$attr['size']])) {
73 $prepend_style .= 'font-size:' .
74 $this->_size_lookup
[$attr['size']] . ';';
80 $attr['style'] = isset($attr['style']) ?
81 $prepend_style . $attr['style'] :
85 $new_tag = $tag->copy();
86 $new_tag->name
= $this->transform_to
;
87 $new_tag->attr
= $attr;