/** * @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(); $script->selectUnicode(0x20); // space if (!empty($options['useGlyphCSSRange']) && !empty($options['customGlyphs'])) { $options['glyphs'][] = UnicodeRange::fromCSSValue($options['customGlyphs'])->asHexString(); $options['customGlyphs'] = ''; } 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 (empty($options['disableScaling'])) { $script->scaleToEm($options['emSize']); } $script->selectAll(); $script->verticalFlip(0); if (!empty($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 (new SVGFontContainer($svgFile, $options) as $font) { $fonts[$font->getFaceBasedId()] = sprintf("%s%s(%s);\n", $copyright, isset($options['callback']) ? $options['callback'] : '', $font->toJavaScript()); } unlink($svgFile); return $fonts; }
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':