1<?php 2 3class CSSFontSize extends CSSSubFieldProperty { 4 var $_defaultValue; 5 6 function CSSFontSize(&$owner, $field) { 7 $this->CSSSubFieldProperty($owner, $field); 8 9 $this->_defaultValue = Value::fromData(BASE_FONT_SIZE_PT, UNIT_PT); 10 } 11 12 function default_value() { 13 return $this->_defaultValue; 14 } 15 16 function parse($value) { 17 if ($value == 'inherit') { 18 return CSS_PROPERTY_INHERIT; 19 } 20 21 $value = trim(strtolower($value)); 22 23 switch(strtolower($value)) { 24 case "xx-small": 25 return Value::fromData(BASE_FONT_SIZE_PT*3/5, UNIT_PT); 26 case "x-small": 27 return Value::fromData(BASE_FONT_SIZE_PT*3/4, UNIT_PT); 28 case "small": 29 return Value::fromData(BASE_FONT_SIZE_PT*8/9, UNIT_PT); 30 case "medium": 31 return Value::fromData(BASE_FONT_SIZE_PT, UNIT_PT); 32 case "large": 33 return Value::fromData(BASE_FONT_SIZE_PT*6/5, UNIT_PT); 34 case "x-large": 35 return Value::fromData(BASE_FONT_SIZE_PT*3/2, UNIT_PT); 36 case "xx-large": 37 return Value::fromData(BASE_FONT_SIZE_PT*2/1, UNIT_PT); 38 }; 39 40 switch(strtolower($value)) { 41 case "larger": 42 return Value::fromData(1.2, UNIT_EM); 43 case "smaller": 44 return Value::fromData(0.83, UNIT_EM); // 0.83 = 1/1.2 45 }; 46 47 if (preg_match("/(\d+\.?\d*)%/i", $value, $matches)) { 48 return Value::fromData($matches[1]/100, UNIT_EM); 49 }; 50 51 return Value::fromString($value); 52 } 53 54 function get_property_code() { 55 return CSS_FONT_SIZE; 56 } 57 58 function get_property_name() { 59 return 'font-size'; 60 } 61} 62 63?>