--- /dev/null
+<?php
+
+namespace Fluidbook\Tools;
+
+use Cubist\Util\CommandLine;
+use Cubist\Util\Graphics\Color;
+
+class FluidbookFontToWoff
+{
+ public static function fontforge($dest, $filepath) {
+ if (!file_exists($dest) || filemtime($dest) < filemtime($filepath)) {
+ $script = resource_path('tools/fonts/convertrn.pe');
+ if (!is_executable($script)) {
+ chmod($script, 755);
+ }
+ $fontforge = new CommandLine('fontforge');
+ $fontforge->setArg('-script', $script);
+ $fontforge->setArg(null, $filepath);
+ $fontforge->setArg(null, $dest);
+ $fontforge->execute();
+ //$fontforge->debug();
+ }
+ }
+
+ /**
+ * @param $f
+ * $f = filepath
+ * @return CommandLine
+ */
+ public static function fontline($f) {
+ $fontline = new CommandLine('font-line');
+ $fontline->setArg(null, 'report');
+ $fontline->setArg(null, $f);
+ $fontline->execute();
+
+ return $fontline;
+ }
+
+ public static function configFont($fontFile, $hash = null, $filepath = null) {
+ $fontline = self::fontline($filepath);
+ if(!$hash) {
+ $hash = 'fb_' . substr(md5($fontFile), 0, 10);
+ }
+ $report = explode("\n", $fontline->getOutput());
+
+ foreach ($report as $item) {
+ $item = trim($item);
+ if (!stristr($item, ':')) {
+ continue;
+ }
+ list($k, $v) = explode(':', $item, 2);
+ $v = trim($v);
+ if ($k == '[head] Units per Em') {
+ $fontHeight = $v;
+ }
+ if ($k == '[OS/2] CapHeight') {
+ $fontCapHeight = $v;
+ }
+ if ($k == '[OS/2] TypoAscender') {
+ $ascender = abs($v);
+ }
+ if ($k == '[OS/2] TypoDescender') {
+ $descender = abs($v);
+ }
+ }
+ $capHeight = 1;
+ if (isset($fontCapHeight) && isset($fontHeight) && is_numeric($fontCapHeight) && is_numeric($fontHeight)) {
+ $capHeight = $fontCapHeight / $fontHeight;
+ }
+ return ['family' => $hash, 'capHeight' => $capHeight, 'ascender' => $fontHeight > 0 ? $ascender / $fontHeight : 1, 'descender' => $fontHeight > 0 ? $descender / $fontHeight : 1];
+ }
+}