Example #1
0
 /**
  * @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;
 }
Example #2
0
 case '-f':
 case '--fontforge':
     $fontforge = next($args);
     break;
 case '-h':
 case '--help':
     usage();
     exit(0);
     break;
 case '-n':
 case '--family-name':
     $options['family'] = next($args);
     break;
 case '-u':
 case '--unicode-range':
     $options['glyphs'][] = UnicodeRange::fromCSSValue(next($args))->asHexString();
     break;
 case '-s':
 case '--scale':
     $options['emSize'] = next($args);
     break;
 case '-k':
 case '--no-kerning':
     $options['kerning'] = 'no';
     break;
 case '-l':
 case '--no-scaling':
     $options['disableScaling'] = 'yes';
     break;
 case '-m':
 case '--no-simplify':
Example #3
0
 /**
  * add another range to the set
  */
 public function addRange(UnicodeRange $range)
 {
     $this->_prepare();
     $set = $range->get();
     $this->set = array_unique(array_merge($this->set, $set));
     return $this;
 }
Example #4
0
 /**
  * @param string $unicodeRange
  * @param array $charIndex
  * @return array
  */
 private static function getMatchingCharsFromUnicodeRange($unicodeRange, $charIndex)
 {
     $matches = array();
     $range = new UnicodeRange($unicodeRange);
     if ($range->isSimple()) {
         if ($charIndex[$unicodeRange]) {
             $matches[] = $unicodeRange;
         }
     } else {
         reset($charIndex);
         while (list($char) = each($charIndex)) {
             if ($range->contains($char)) {
                 $matches[] = $char;
             }
         }
     }
     return $matches;
 }