예제 #1
0
파일: Cufon.php 프로젝트: srobbin/cufon
 /**
  * @param string $file
  * @param array $options
  * @return array
  */
 public static function generate($file, array $options)
 {
     Cufon::log('Processing %s', $file);
     $script = new FontForgeScript();
     $script->open($file);
     $script->flattenCID();
     $script->reEncode('unicode');
     $script->selectNone();
     if (!empty($options['glyphs'])) {
         foreach ($options['glyphs'] as $glyph) {
             $ranges = explode(',', $glyph);
             foreach ($ranges as $range) {
                 if (strpos($range, '-')) {
                     // the range regex allows for things like 0xff-0xff-0xff, so we'll
                     // just ignore everything between the first and last one.
                     $points = explode('-', $range);
                     $script->selectUnicodeRange(intval(reset($points), 16), intval(end($points), 16));
                 } else {
                     $script->selectUnicode(intval($range, 16));
                 }
             }
         }
     }
     if (!empty($options['customGlyphs'])) {
         $glyphs = preg_split('//u', $options['customGlyphs'], -1, PREG_SPLIT_NO_EMPTY);
         foreach ($glyphs as $glyph) {
             $script->selectUnicode(UnicodeRange::getCodePoint($glyph));
         }
     }
     $script->selectInvert();
     $script->detachAndRemoveGlyphs();
     $script->setFontOrder(FontForgeScript::ORDER_CUBIC);
     if (!$options['disableScaling']) {
         $script->scaleToEm($options['emSize']);
     }
     $script->selectAll();
     $script->verticalFlip(0);
     if ($options['simplify']) {
         $script->simplify($options['simplifyDelta']);
     }
     $script->roundToInt(1);
     $svgFile = Cufon::getUnusedFilename('.svg');
     Cufon::log('Converting to SVG with filename %s', $svgFile);
     $script->printNameIDs();
     $script->generate($svgFile);
     $output = trim($script->execute());
     $fonts = array();
     $copyright = '';
     if (!empty($output)) {
         $copyright = self::createJSDocComment("The following copyright notice may not be removed under " . "any circumstances.\n\n{$output}");
     }
     foreach (SVGFontContainer::fromFile($svgFile, $options) as $font) {
         $fonts[$font->getId()] = sprintf("%s%s(%s);\n", $copyright, $options['callback'], $font->toJavaScript());
     }
     unlink($svgFile);
     return $fonts;
 }