Skip to content

Commit

Permalink
Added numerous other fields to the font copyright notice, including T…
Browse files Browse the repository at this point in the history
…rademark, Designer, Vendor URL and License information.
  • Loading branch information
sorccu committed Sep 24, 2009
1 parent a50d62d commit d626df1
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 38 deletions.
17 changes: 14 additions & 3 deletions generate/lib/Cufon.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,26 @@ public static function generate($file, array $options)

Cufon::log('Converting to SVG with filename %s', $svgFile);

$script->printNameIDs();
$script->generate($svgFile);
$script->execute();

$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",
self::createJSDocComment($font->getCopyright()),
$copyright,
$options['callback'],
$font->toJavaScript()
);
Expand All @@ -132,7 +143,7 @@ public static function createJSDocComment($comment)
return '';
}

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

for ($i = 0, $l = count($lines); $i < $l; ++$i)
{
Expand Down
46 changes: 40 additions & 6 deletions generate/lib/FontForgeScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function detachAndRemoveGlyphs()
}

/**
* @return void
* @return string
*/
public function execute()
{
Expand All @@ -90,7 +90,7 @@ public function execute()

chmod($filename, 0777);

$command = sprintf('env %s -script %s 2>&1', CUFON_FONTFORGE, escapeshellarg($filename));
$command = sprintf('env %s -script %s', CUFON_FONTFORGE, escapeshellarg($filename));

Cufon::log('Executing command: %s', $command);

Expand All @@ -100,14 +100,14 @@ public function execute()

exec($command, $output, $status);

Cufon::log('Exited with status %d, output: %s', $status, implode(' / ', $output));
Cufon::log('Exited with status %d', $status);

if ($status > 0)
{
throw new ConversionException('Conversion failed');
}

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

/**
Expand All @@ -131,6 +131,42 @@ public function generate($filename)
return $this;
}

/**
* @return FontForgeScript
*/
public function printNameIDs()
{
$fields = array(
'Copyright' => array(0, '$copyright'),
'Trademark' => array(7, null),
'Full name' => array(4, null),
'Description' => array(10, null),
'Manufacturer' => array(8, null),
'Designer' => array(9, null),
'Vendor URL' => array(11, null),
'License information' => array(14, null)
);

foreach ($fields as $field => $info)
{
list($code, $alt) = $info;

$this->commands[] =
"if (GetTTFName(0x409, ${code}) != '')\n" .
"\tPrint('${field}:')\n" .
"\tPrint(GetTTFName(0x409, ${code}))\n" .
"\tPrint('')\n" .
(!empty($alt) ?
"elseif (${alt} != '')" .
"\tPrint('${field}:')\n" .
"\tPrint(${alt})\n" .
"\tPrint('')\n" : '') .
"endif";
}

return $this;
}

/**
* @param int $at
* @return FontForgeScript
Expand All @@ -150,8 +186,6 @@ public function open($filename)
{
$this->commands[] = sprintf('Open("%s")', addslashes($filename));

chmod($filename, 0777);

return $this;
}

Expand Down
8 changes: 0 additions & 8 deletions generate/lib/SVGFont.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,6 @@ public function __toString()
return $this->document->asXML();
}

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

/**
* @return string
*/
Expand Down
21 changes: 0 additions & 21 deletions generate/lib/SVGFontContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,6 @@ 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 d626df1

Please sign in to comment.