Skip to content

Commit

Permalink
The generator now embeds the original font's copyright notice to the …
Browse files Browse the repository at this point in the history
…files it creates.
  • Loading branch information
sorccu committed Sep 16, 2009
1 parent 0facde1 commit 779e36d
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
9 changes: 8 additions & 1 deletion fonts/Vegur.font.js

Large diffs are not rendered by default.

26 changes: 25 additions & 1 deletion generate/lib/Cufon.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,36 @@ public static function generate($file, array $options)

foreach (SVGFontContainer::fromFile($svgFile, $options) as $font)
{
$fonts[$font->getId()] = $options['callback'] . '(' . $font->toJavaScript() . ');';
$fonts[$font->getId()] = sprintf("%s%s(%s);\n",
self::createJSDocComment($font->getCopyright()),
$options['callback'],
$font->toJavaScript()
);
}

unlink($svgFile);

return $fonts;
}

/**
* @return string
*/
public static function createJSDocComment($comment)
{
if ($comment === '')
{
return '';
}

$lines = explode("\n", wordwrap($comment, 72));

for ($i = 0, $l = count($lines); $i < $l; ++$i)
{
$lines[$i] = ' * ' . $lines[$i];
}

return "/*!\n" . implode("\n", $lines) . "\n */\n";
}

}
11 changes: 11 additions & 0 deletions generate/lib/SVGFont.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,22 @@ public function __construct(SimpleXMLElement $document, SVGFontContainer $contai
$this->container = $container;
}

/**
* @return string
*/
public function __toString()
{
return $this->document->asXML();
}

/**
* @return string
*/
public function getCopyright()
{
return $this->container->getCopyright();
}

/**
* @return string
*/
Expand Down
21 changes: 21 additions & 0 deletions generate/lib/SVGFontContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,27 @@ public function __construct(SimpleXMLElement $document, array $options)
$this->options = $options;
}

/**
* @return string
*/
public function getCopyright()
{
$parts = array();

foreach ($this->document->xpath('//metadata') as $meta)
{
$content = preg_replace('/\.(?=\p{L})/u', '. ', trim((string) $meta));

$lines = explode("\n", $content);

array_splice($lines, 0, 2);

$parts[] = implode("\n", $lines);
}

return implode("\n\n", $parts);
}

/**
* @return array of SVGFont
*/
Expand Down

0 comments on commit 779e36d

Please sign in to comment.