Permalink
Browse files

The generator now embeds the original font's copyright notice to the …

…files it creates.
  • Loading branch information...
sorccu committed Sep 16, 2009
1 parent 0facde1 commit 779e36d2b0eed4a5eab6c9fa91afb23ffd243202
Showing with 65 additions and 2 deletions.
  1. +8 −1 fonts/Vegur.font.js
  2. +25 −1 generate/lib/Cufon.php
  3. +11 −0 generate/lib/SVGFont.php
  4. +21 −0 generate/lib/SVGFontContainer.php
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -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";
+ }
+
}
View
@@ -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
*/
@@ -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
*/

0 comments on commit 779e36d

Please sign in to comment.