From: soufiane Date: Tue, 16 Apr 2024 10:31:24 +0000 (+0200) Subject: outils : font vers woff X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=c4eb68ef6ecf34ded123c8202d792df24366bd2b;p=fluidbook_tools.git outils : font vers woff --- diff --git a/src/FluidbookFontToWoff.php b/src/FluidbookFontToWoff.php new file mode 100644 index 0000000..8054d4d --- /dev/null +++ b/src/FluidbookFontToWoff.php @@ -0,0 +1,72 @@ +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]; + } +}