コード例 #1
0
 public static function fontSizeToPt($e)
 {
     global $tag_size;
     $tag_size = BasicChecks::get_p_css($e, "font-size");
     while ($tag_size == null && ($e->tag != "body" && $e->tag != "html")) {
         $h = BasicChecks::checkHeadingLevel($e);
         if ($h != null && $tag_size == null) {
             $tag_size = $h * BasicChecks::fontSizeToPt($e->parent());
             //heading tag found
             return $tag_size;
         } else {
             //not an heading
             if ($e != null) {
                 $e = $e->parent();
                 $tag_size = BasicChecks::get_p_css($e, "font-size");
             }
         }
     }
     if ($tag_size == null) {
         $tag_size = DEFAULT_FONT_SIZE;
         $format = DEFAULT_FONT_FORMAT;
         return $tag_size;
     } else {
         if (substr($tag_size, -1) == "%") {
             //percent
             $s = substr($tag_size, 0, strlen($tag_size) - 1) / 100;
             if ($e->tag == "body" || $e->tag == "html") {
                 $tag_size = DEFAULT_FONT_SIZE * $s;
                 return $tag_size;
             } else {
                 $tag_size = $s * BasicChecks::fontSizeToPt($e->parent());
                 return $tag_size;
             }
         } else {
             //em,px,pt
             $format = substr($tag_size, -2);
             $s = substr($tag_size, 0, strlen($tag_size) - 2);
             switch ($format) {
                 case "pt":
                     $tag_size = $s;
                     return $tag_size;
                     break;
                 case "px":
                     $tag_size = $s / 1.32;
                     return $tag_size;
                     break;
                 case "em":
                     if ($e->tag == "body" || $e->tag == "html") {
                         $tag_size = DEFAULT_FONT_SIZE * $s;
                         return $tag_size;
                     } else {
                         $tag_size = $s * BasicChecks::fontSizeToPt($e->parent());
                         return $tag_size;
                     }
                     break;
                 default:
                     //formato non supportato
                     return -1;
             }
         }
     }
 }