/** * @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; }
/** * @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->generate($svgFile); $script->execute(); $fonts = array(); foreach (SVGFontContainer::fromFile($svgFile, $options) as $font) { $fonts[$font->getId()] = $options['callback'] . '(' . $font->toJavaScript() . ');'; } unlink($svgFile); return $fonts; }