case UPLOAD_ERR_NO_TMP_DIR: echo "Missing a temporary folder."; break; default: echo "Unknown error"; } continue; } $weight = "normal"; $style = "normal"; switch ($name) { case "bold": $weight = "bold"; break; case "italic": $style = "italic"; break; case "bold_italic": $weight = "bold"; $style = "italic"; break; } $style_arr = array("family" => $family, "weight" => $weight, "style" => $style); if (!Font_Metrics::register_font($style_arr, $data["tmp_name"][$name])) { echo $data["name"][$name] . " is not a valid font file"; } else { echo "The <strong>{$family} {$weight} {$style}</strong> font was successfully installed !<br />"; } } break; }
/** * parse @font-face{} sections * http://www.w3.org/TR/css3-fonts/#the-font-face-rule * * @param string $str CSS @font-face rules * * @return Style */ private function _parse_font_face($str) { $descriptors = $this->_parse_properties($str); preg_match_all("/(url|local)\\s*\\([\"\\']?([^\"\\'\\)]+)[\"\\']?\\)\\s*(format\\s*\\([\"\\']?([^\"\\'\\)]+)[\"\\']?\\))?/i", $descriptors->src, $src); $sources = array(); $valid_sources = array(); foreach ($src[0] as $i => $value) { $source = array("local" => strtolower($src[1][$i]) === "local", "uri" => $src[2][$i], "format" => $src[4][$i], "path" => build_url($this->_protocol, $this->_base_host, $this->_base_path, $src[2][$i])); if (!$source["local"] && in_array($source["format"], array("", "woff", "opentype", "truetype"))) { $valid_sources[] = $source; } $sources[] = $source; } // No valid sources if (empty($valid_sources)) { return; } $style = array("family" => $descriptors->get_font_family_raw(), "weight" => $descriptors->font_weight, "style" => $descriptors->font_style); Font_Metrics::register_font($style, $valid_sources[0]["path"]); }