function MakeFont($fontfile, $afmfile, $enc = 'cp1252', $patch = array(), $type = 'TrueType') { //Generate a font definition file set_magic_quotes_runtime(0); ini_set('auto_detect_line_endings', '1'); if ($enc) { $map = ReadMap($enc); foreach ($patch as $cc => $gn) { $map[$cc] = $gn; } } else { $map = array(); } if (!file_exists($afmfile)) { die('<B>Error:</B> AFM file not found: ' . $afmfile); } $fm = ReadAFM($afmfile, $map); if ($enc) { $diff = MakeFontEncoding($map); } else { $diff = ''; } $fd = MakeFontDescriptor($fm, empty($map)); //Find font type if ($fontfile) { $ext = strtolower(substr($fontfile, -3)); if ($ext == 'ttf') { $type = 'TrueType'; } elseif ($ext == 'pfb') { $type = 'Type1'; } else { die('<B>Error:</B> unrecognized font file extension: ' . $ext); } } else { if ($type != 'TrueType' and $type != 'Type1') { die('<B>Error:</B> incorrect font type: ' . $type); } } //Start generation $s = '<?php' . "\n"; $s .= '$type=\'' . $type . "';\n"; $s .= '$name=\'' . $fm['FontName'] . "';\n"; $s .= '$desc=' . $fd . ";\n"; if (!isset($fm['UnderlinePosition'])) { $fm['UnderlinePosition'] = -100; } if (!isset($fm['UnderlineThickness'])) { $fm['UnderlineThickness'] = 50; } $s .= '$up=' . $fm['UnderlinePosition'] . ";\n"; $s .= '$ut=' . $fm['UnderlineThickness'] . ";\n"; $w = MakeWidthArray($fm); $s .= '$cw=' . $w . ";\n"; $s .= '$enc=\'' . $enc . "';\n"; $s .= '$diff=\'' . $diff . "';\n"; $basename = substr(basename($afmfile), 0, -4); if ($fontfile) { //Embedded font if (!file_exists($fontfile)) { die('<B>Error:</B> font file not found: ' . $fontfile); } if ($type == 'TrueType') { CheckTTF($fontfile); } $f = fopen($fontfile, 'rb'); if (!$f) { die('<B>Error:</B> Can\'t open ' . $fontfile); } $file = fread($f, filesize($fontfile)); fclose($f); if ($type == 'Type1') { //Find first two sections and discard third one $header = ord($file[0]) == 128; if ($header) { //Strip first binary header $file = substr($file, 6); } $pos = strpos($file, 'eexec'); if (!$pos) { die('<B>Error:</B> font file does not seem to be valid Type1'); } $size1 = $pos + 6; if ($header and ord($file[$size1]) == 128) { //Strip second binary header $file = substr($file, 0, $size1) . substr($file, $size1 + 6); } $pos = strpos($file, '00000000'); if (!$pos) { die('<B>Error:</B> font file does not seem to be valid Type1'); } $size2 = $pos - $size1; $file = substr($file, 0, $size1 + $size2); } if (function_exists('gzcompress')) { $cmp = $basename . '.z'; SaveToFile($cmp, gzcompress($file), 'b'); $s .= '$file=\'' . $cmp . "';\n"; echo 'Font file compressed (' . $cmp . ')<BR>'; } else { $s .= '$file=\'' . basename($fontfile) . "';\n"; echo '<B>Notice:</B> font file could not be compressed (zlib extension not available)<BR>'; } if ($type == 'Type1') { $s .= '$size1=' . $size1 . ";\n"; $s .= '$size2=' . $size2 . ";\n"; } else { $s .= '$originalsize=' . filesize($fontfile) . ";\n"; } } else { //Not embedded font $s .= '$file=' . "'';\n"; } $s .= "?>\n"; SaveToFile($basename . '.php', $s); echo 'Font definition file generated (' . $basename . '.php' . ')<BR>'; }
/** * * @param string $fontfile path to font file (TTF or PFB). * @param string $fmfile font metrics file (UFM or AFM). * @param boolean $embedded Set to false to not embed the font, true otherwise (default). * @param string $enc Name of the encoding table to use. Omit this parameter for TrueType Unicode, OpenType Unicode and symbolic fonts like Symbol or ZapfDingBats. * @param array $patch Optional modification of the encoding */ function MakeFont($fontfile, $fmfile, $embedded = true, $enc = "cp1252", $patch = array()) { //Generate a font definition file set_magic_quotes_runtime(0); ini_set('auto_detect_line_endings', '1'); if (!file_exists($fontfile)) { die('Error: file not found: ' . $fontfile); } if (!file_exists($fmfile)) { die('Error: file not found: ' . $fmfile); } $cidtogidmap = ''; $map = array(); $diff = ''; $ffext = strtolower(substr($fontfile, -3)); $fmext = strtolower(substr($fmfile, -3)); if ($fmext == 'afm') { if ($ffext == 'ttf') { $type = 'TrueType'; } elseif ($ffext == 'pfb') { $type = 'Type1'; } else { die('Error: unrecognized font file extension: ' . $ext); } if ($enc) { $map = ReadMap($enc); foreach ($patch as $cc => $gn) { $map[$cc] = $gn; } } $fm = ReadAFM($fmfile, $map); if ($enc) { $diff = MakeFontEncoding($map); } $fd = MakeFontDescriptor($fm, empty($map)); } elseif ($fmext == 'ufm') { $enc = ""; if ($ffext == 'ttf') { $type = 'TrueTypeUnicode'; } else { die('Error: not a TrueType font: ' . $ffext); } $fm = ReadUFM($fmfile, $cidtogidmap); $fd = MakeFontDescriptor($fm, false); } //Start generation $s = '<?php' . "\n"; $s .= '$type=\'' . $type . "';\n"; $s .= '$name=\'' . $fm['FontName'] . "';\n"; $s .= '$desc=' . $fd . ";\n"; if (!isset($fm['UnderlinePosition'])) { $fm['UnderlinePosition'] = -100; } if (!isset($fm['UnderlineThickness'])) { $fm['UnderlineThickness'] = 50; } $s .= '$up=' . $fm['UnderlinePosition'] . ";\n"; $s .= '$ut=' . $fm['UnderlineThickness'] . ";\n"; $w = MakeWidthArray($fm); $s .= '$cw=' . $w . ";\n"; $s .= '$enc=\'' . $enc . "';\n"; $s .= '$diff=\'' . $diff . "';\n"; $basename = substr(basename($fmfile), 0, -4); if ($embedded) { //Embedded font if ($type == 'TrueType' or $type == 'TrueTypeUnicode') { CheckTTF($fontfile); } $f = fopen($fontfile, 'rb'); if (!$f) { die('Error: Unable to open ' . $fontfile); } $file = fread($f, filesize($fontfile)); fclose($f); if ($type == 'Type1') { //Find first two sections and discard third one $header = ord($file[0]) == 128; if ($header) { //Strip first binary header $file = substr($file, 6); } $pos = strpos($file, 'eexec'); if (!$pos) { die('Error: font file does not seem to be valid Type1'); } $size1 = $pos + 6; if ($header and ord($file[$size1]) == 128) { //Strip second binary header $file = substr($file, 0, $size1) . substr($file, $size1 + 6); } $pos = strpos($file, '00000000'); if (!$pos) { die('Error: font file does not seem to be valid Type1'); } $size2 = $pos - $size1; $file = substr($file, 0, $size1 + $size2); } if (function_exists('gzcompress')) { $cmp = $basename . '.z'; SaveToFile($cmp, gzcompress($file), 'b'); $s .= '$file=\'' . $cmp . "';\n"; print "Font file compressed (" . $cmp . ")\n"; if (!empty($cidtogidmap)) { $cmp = $basename . '.ctg.z'; SaveToFile($cmp, gzcompress($cidtogidmap), 'b'); print "CIDToGIDMap created and compressed (" . $cmp . ")\n"; $s .= '$ctg=\'' . $cmp . "';\n"; } } else { $s .= '$file=\'' . basename($fontfile) . "';\n"; print "Notice: font file could not be compressed (zlib extension not available)\n"; if (!empty($cidtogidmap)) { $cmp = $basename . '.ctg'; $f = fopen($cmp, 'wb'); fwrite($f, $cidtogidmap); fclose($f); print "CIDToGIDMap created (" . $cmp . ")\n"; $s .= '$ctg=\'' . $cmp . "';\n"; } } if ($type == 'Type1') { $s .= '$size1=' . $size1 . ";\n"; $s .= '$size2=' . $size2 . ";\n"; } else { $s .= '$originalsize=' . filesize($fontfile) . ";\n"; } } else { //Not embedded font $s .= '$file=' . "'';\n"; } $s .= "?>"; SaveToFile($basename . '.php', $s); print "Font definition file generated (" . $basename . ".php)\n"; }
function MakeFont($fontfile, $afmfile, $enc = 'cp1252', $patch = array()) { //Generate a font definition file set_magic_quotes_runtime(0); if ($enc) { $map = ReadMap($enc); foreach ($patch as $cc => $gn) { $map[$cc] = $gn; } } else { $map = array(); } if (!file_exists($afmfile)) { die('<B>Error:</B> AFM file not found: ' . $afmfile); } $fm = ReadAFM($afmfile, $map); if ($enc) { $diff = MakeFontEncoding($map); } else { $diff = ''; } $fd = MakeFontDescriptor($fm, empty($map)); $s = '<?php' . "\n"; $s .= '$type=\'TrueType' . "';\n"; $s .= '$name=\'' . $fm['FontName'] . "';\n"; $s .= '$desc=' . $fd . ";\n"; if (!isset($fm['UnderlinePosition'])) { $fm['UnderlinePosition'] = -100; } if (!isset($fm['UnderlineThickness'])) { $fm['UnderlineThickness'] = 50; } $s .= '$up=' . $fm['UnderlinePosition'] . ";\n"; $s .= '$ut=' . $fm['UnderlineThickness'] . ";\n"; $w = MakeWidthArray($fm); $s .= '$cw=' . $w . ";\n"; $s .= '$enc=\'' . $enc . "';\n"; $s .= '$diff=\'' . $diff . "';\n"; $basename = substr(basename($afmfile), 0, -4); if ($fontfile) { //Embedded font if (!file_exists($fontfile)) { die('<B>Error:</B> font file not found: ' . $fontfile); } if (function_exists('gzcompress')) { $f = fopen($fontfile, 'rb'); $ttf = fread($f, filesize($fontfile)); fclose($f); $cmp = $basename . '.z'; SaveToFile($cmp, gzcompress($ttf), 'b'); $s .= '$file=\'' . $cmp . "';\n"; echo 'Font file compressed (' . $cmp . ')<BR>'; } else { echo '<B>Notice:</B> font file could not be compressed (gzcompress not available)<BR>'; $s .= '$file=\'' . basename($fontfile) . "';\n"; } $s .= '$originalsize=' . filesize($fontfile) . ";\n"; } else { //Not embedded font $s .= '$file=' . "'';\n"; } $s .= "?>\n"; SaveToFile($basename . '.php', $s); echo 'Font definition file generated (' . $basename . '.php' . ')<BR>'; }
function MakeDefinitionFile($file, $type, $enc, $embed, $map, $info) { $s = "<?php\n"; $s .= '$type = \'' . $type . "';\n"; $s .= '$name = \'' . $info['FontName'] . "';\n"; $s .= '$desc = ' . MakeFontDescriptor($info) . ";\n"; $s .= '$up = ' . $info['UnderlinePosition'] . ";\n"; $s .= '$ut = ' . $info['UnderlineThickness'] . ";\n"; $s .= '$cw = ' . MakeWidthArray($info['Widths']) . ";\n"; $s .= '$enc = \'' . $enc . "';\n"; $diff = MakeFontEncoding($map); if ($diff) { $s .= '$diff = \'' . $diff . "';\n"; } if ($embed) { $s .= '$file = \'' . $info['File'] . "';\n"; if ($type == 'Type1') { $s .= '$size1 = ' . $info['Size1'] . ";\n"; $s .= '$size2 = ' . $info['Size2'] . ";\n"; } else { $s .= '$originalsize = ' . $info['OriginalSize'] . ";\n"; } } $s .= "?>\n"; SaveToFile($file, $s, 't'); }
function MakeFont($fontfile, $afmfile, $destdir, $destfile, $enc) { // Generate a font definition file set_magic_quotes_runtime(0); ini_set('auto_detect_line_endings', '1'); $manager = ManagerEncoding::get(); $map = $manager->get_encoding_glyphs($enc); $fm = ReadAFM($afmfile, $map); if (is_null($fm)) { error_log(sprintf("Notice: Missing AFM file '%s'; attempting to parse font file '%s' directly", $afmfile, $fontfile)); $fm = ReadTTF($fontfile, $manager->getEncodingVector($enc)); if (is_null($fm)) { die(sprintf("Cannot get font metrics for '%s'", $fontfile)); } } $diff = MakeFontEncoding($map); $cmap = MakeFontCMap($enc); $fd = MakeFontDescriptor($fm, empty($map)); //Find font type if ($fontfile) { $ext = strtolower(substr($fontfile, -3)); if ($ext == 'ttf') { $type = 'TrueType'; } elseif ($ext == 'pfb') { $type = 'Type1'; } else { die('<B>Error:</B> unrecognized font file extension: ' . $ext); } } else { if ($type != 'TrueType' and $type != 'Type1') { die('<B>Error:</B> incorrect font type: ' . $type); } } //Start generation $s = '<?php' . "\n"; $s .= '$type=\'' . $type . "';\n"; $s .= '$name=\'' . $fm['FontName'] . "';\n"; $s .= '$desc=' . $fd . ";\n"; if (!isset($fm['UnderlinePosition'])) { $fm['UnderlinePosition'] = -100; } if (!isset($fm['UnderlineThickness'])) { $fm['UnderlineThickness'] = 50; } $s .= '$up=' . $fm['UnderlinePosition'] . ";\n"; $s .= '$ut=' . $fm['UnderlineThickness'] . ";\n"; $w = MakeWidthArray($fm); $s .= '$cw=' . $w . ";\n"; $s .= '$enc=\'' . $enc . "';\n"; $s .= '$diff=\'' . $diff . "';\n"; $s .= '$cmap=' . $cmap . ";\n"; $basename = substr(basename($afmfile), 0, -4); if ($fontfile) { //Embedded font if (!file_exists($fontfile)) { die('<B>Error:</B> font file not found: ' . $fontfile); } if ($type == 'TrueType') { CheckTTF($fontfile); } $f = fopen($fontfile, 'rb'); if (!$f) { die('<B>Error:</B> Can\'t open ' . $fontfile); } $file = fread($f, filesize($fontfile)); fclose($f); if ($type == 'Type1') { //Find first two sections and discard third one $header = ord($file[0]) == 128; if ($header) { //Strip first binary header $file = substr($file, 6); } $pos = strpos($file, 'eexec'); if (!$pos) { die('<B>Error:</B> font file does not seem to be valid Type1'); } $size1 = $pos + 6; if ($header and ord($file[$size1]) == 128) { //Strip second binary header $file = substr($file, 0, $size1) . substr($file, $size1 + 6); } $pos = strpos($file, '00000000'); if (!$pos) { die('<B>Error:</B> font file does not seem to be valid Type1'); } $size2 = $pos - $size1; $file = substr($file, 0, $size1 + $size2); } $gzcompress_exists = function_exists('gzcompress'); if ($gzcompress_exists) { $cmp = $basename . '.z'; SaveToFile($destdir . $cmp, gzcompress($file), 'b'); $s .= '$file=\'' . $cmp . "';\n"; } else { $cmp = $basename . '.ttf'; SaveToFile($destdir . $cmp, $file, 'b'); $s .= '$file=\'' . basename($fontfile) . "';\n"; error_log('Notice: font file could not be compressed (zlib extension not available)'); } if ($type == 'Type1') { $s .= '$size1=' . $size1 . ";\n"; $s .= '$size2=' . $size2 . ";\n"; } else { $s .= '$originalsize=' . filesize($fontfile) . ";\n"; } } else { //Not embedded font $s .= '$file=' . "'';\n"; } $s .= "?>\n"; SaveToFile($destdir . $destfile, $s); }
/** * * @param string $fontfile path to font file (TTF, OTF or PFB). * @param string $fmfile font metrics file (UFM or AFM). * @param boolean $embedded Set to false to not embed the font, true otherwise (default). * @param string $enc Name of the encoding table to use. Omit this parameter for TrueType Unicode, OpenType Unicode and symbolic fonts like Symbol or ZapfDingBats. * @param array $patch Optional modification of the encoding */ function MakeFont($fontfile, $fmfile, $embedded = true, $enc = 'cp1252', $patch = array(), $cidInfo = "") { //Generate a font definition file set_magic_quotes_runtime(0); ini_set('auto_detect_line_endings', '1'); if (!file_exists($fontfile)) { die('Error: file not found: ' . $fontfile); } if (!file_exists($fmfile)) { die('Error: file not found: ' . $fmfile); } $cidtogidmap = ''; $map = array(); $diff = ''; $dw = 0; // default width $ffext = strtolower(substr($fontfile, -3)); $fmext = strtolower(substr($fmfile, -3)); if ($fmext == 'afm') { if ($ffext == 'ttf' or $ffext == 'otf') { $type = 'TrueType'; } elseif ($ffext == 'pfb') { $type = 'Type1'; } else { die('Error: unrecognized font file extension: ' . $ffext); } if ($enc) { $map = ReadMap($enc); foreach ($patch as $cc => $gn) { $map[$cc] = $gn; } } $fm = ReadAFM($fmfile, $map); if (isset($widths['.notdef'])) { $dw = $widths['.notdef']; } if ($enc) { $diff = MakeFontEncoding($map); } $fd = MakeFontDescriptor($fm, empty($map)); } elseif ($fmext == 'ufm') { $enc = ''; if ($ffext == 'ttf' or $ffext == 'otf') { $type = 'TrueTypeUnicode'; } else { die('Error: not a TrueType font: ' . $ffext); } $fm = ReadUFM($fmfile, $cidtogidmap); $dw = $fm['MissingWidth']; $fd = MakeFontDescriptor($fm, false); } //Start generation $s = '<?php /* Modification information for LGPL compliance r56990 - 2010-06-16 13:05:36 -0700 (Wed, 16 Jun 2010) - kjing - snapshot "Mango" svn branch to a new one for GitHub sync r56989 - 2010-06-16 13:01:33 -0700 (Wed, 16 Jun 2010) - kjing - defunt "Mango" svn dev branch before github cutover r55980 - 2010-04-19 13:31:28 -0700 (Mon, 19 Apr 2010) - kjing - create Mango (6.1) based on windex r51719 - 2009-10-22 10:18:00 -0700 (Thu, 22 Oct 2009) - mitani - Converted to Build 3 tags and updated the build system r51634 - 2009-10-19 13:32:22 -0700 (Mon, 19 Oct 2009) - mitani - Windex is the branch for Sugar Sales 1.0 development r50375 - 2009-08-24 18:07:43 -0700 (Mon, 24 Aug 2009) - dwong - branch kobe2 from tokyo r50372 r47930 - 2009-06-02 16:21:39 -0700 (Tue, 02 Jun 2009) - jenny - Updating with changes from bsoufflet. */ ' . "\n"; // BEGIN SUGARCRM SPECIFIC if ($embedded) { // END SUGARCRM SPECIFIC $s .= '$type=\'' . $type . "';\n"; // BEGIN SUGARCRM SPECIFIC } else { $s .= '$type=\'' . "cidfont0';\n"; } // END SUGARCRM SPECIFIC $s .= '$name=\'' . $fm['FontName'] . "';\n"; $s .= '$desc=' . $fd . ";\n"; if (!isset($fm['UnderlinePosition'])) { $fm['UnderlinePosition'] = -100; } if (!isset($fm['UnderlineThickness'])) { $fm['UnderlineThickness'] = 50; } $s .= '$up=' . $fm['UnderlinePosition'] . ";\n"; $s .= '$ut=' . $fm['UnderlineThickness'] . ";\n"; if ($dw <= 0) { if (isset($fm['Widths'][32]) and $fm['Widths'][32] > 0) { // assign default space width $dw = $fm['Widths'][32]; } else { $dw = 600; } } // BEGIN SUGARCRM SPECIFIC if ($embedded) { // END SUGARCRM SPECIFIC $s .= '$dw=' . $dw . ";\n"; // BEGIN SUGARCRM SPECIFIC } else { $s .= '$dw=' . "1000;\n"; } // END SUGARCRM SPECIFIC $w = MakeWidthArray($fm); $s .= '$cw=' . $w . ";\n"; // BEGIN SUGARCRM SPECIFIC if ($embedded) { // END SUGARCRM SPECIFIC $s .= '$enc=\'' . $enc . "';\n"; // BEGIN SUGARCRM SPECIFIC } // END SUGARCRM SPECIFIC $s .= '$diff=\'' . $diff . "';\n"; $basename = substr(basename($fmfile), 0, -4); // BEGIN SUGARCRM SPECIFIC $dirname = dirname($fmfile); // END SUGARCRM SPECIFIC if ($embedded) { //Embedded font if ($type == 'TrueType' or $type == 'TrueTypeUnicode') { CheckTTF($fontfile); } $f = fopen($fontfile, 'rb'); if (!$f) { die('Error: Unable to open ' . $fontfile); } $file = stream_get_contents($f); fclose($f); if ($type == 'Type1') { //Find first two sections and discard third one $header = ord($file[0]) == 128; if ($header) { //Strip first binary header $file = substr($file, 6); } $pos = strpos($file, 'eexec'); if (!$pos) { die('Error: font file does not seem to be valid Type1'); } $size1 = $pos + 6; if ($header and ord($file[$size1]) == 128) { //Strip second binary header $file = substr($file, 0, $size1) . substr($file, $size1 + 6); } $pos = strpos($file, '00000000'); if (!$pos) { die('Error: font file does not seem to be valid Type1'); } $size2 = $pos - $size1; $file = substr($file, 0, $size1 + $size2); } $basename = strtolower($basename); if (function_exists('gzcompress')) { $cmp = $basename . '.z'; // BEGIN SUGARCRM SPECIFIC /* // END SUGARCRM SPECIFIC SaveToFile($cmp, gzcompress($file, 9), 'b'); // BEGIN SUGARCRM SPECIFIC */ SaveToFile($dirname . "/" . $cmp, gzcompress($file, 9), 'b'); // END SUGARCRM SPECIFIC $s .= '$file=\'' . $cmp . "';\n"; print "Font file compressed (" . $cmp . ")\n"; if (!empty($cidtogidmap)) { $cmp = $basename . '.ctg.z'; // BEGIN SUGARCRM SPECIFIC /* // END SUGARCRM SPECIFIC SaveToFile($cmp, gzcompress($cidtogidmap, 9), 'b'); // BEGIN SUGARCRM SPECIFIC */ SaveToFile($dirname . "/" . $cmp, gzcompress($cidtogidmap, 9), 'b'); // END SUGARCRM SPECIFIC print "CIDToGIDMap created and compressed (" . $cmp . ")\n"; $s .= '$ctg=\'' . $cmp . "';\n"; } } else { $s .= '$file=\'' . basename($fontfile) . "';\n"; print "Notice: font file could not be compressed (zlib extension not available)\n"; if (!empty($cidtogidmap)) { $cmp = $basename . '.ctg'; // BEGIN SUGARCRM SPECIFIC /* // END SUGARCRM SPECIFIC $f = fopen($cmp, 'wb'); // BEGIN SUGARCRM SPECIFIC */ $f = fopen($dirname . "/" . $cmp, 'wb'); // END SUGARCRM SPECIFIC fwrite($f, $cidtogidmap); fclose($f); print "CIDToGIDMap created (" . $cmp . ")\n"; $s .= '$ctg=\'' . $cmp . "';\n"; } } if ($type == 'Type1') { $s .= '$size1=' . $size1 . ";\n"; $s .= '$size2=' . $size2 . ";\n"; } else { $s .= '$originalsize=' . filesize($fontfile) . ";\n"; } } else { //Not embedded font // BEGIN SUGARCRM SPECIFIC /* // END SUGARCRM SPECIFIC $s .= '$file='."'';\n"; // BEGIN SUGARCRM SPECIFIC */ $s .= $cidInfo; // END SUGARCRM SPECIFIC } $s .= "?>"; // BEGIN SUGARCRM SPECIFIC /* // END SUGARCRM SPECIFIC SaveToFile($basename.'.php',$s); // BEGIN SUGARCRM SPECIFIC */ SaveToFile($dirname . "/" . $basename . '.php', $s); // END SUGARCRM SPECIFIC print "Font definition file generated (" . $basename . ".php)\n"; // BEGIN SUGARCRM SPECIFIC return $dirname . "/" . $basename; // END SUGARCRM SPECIFIC }