PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 1.18
Independent Analytics – WordPress Analytics Plugin v1.18
2.15.5 2.15.4 2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / vendor / phenx / php-font-lib / src / FontLib / AdobeFontMetrics.php
independent-analytics / vendor / phenx / php-font-lib / src / FontLib Last commit date
EOT 3 years ago Exception 3 years ago Glyph 3 years ago OpenType 3 years ago Table 3 years ago TrueType 3 years ago WOFF 3 years ago AdobeFontMetrics.php 3 years ago Autoloader.php 3 years ago BinaryStream.php 3 years ago EncodingMap.php 3 years ago Font.php 3 years ago Header.php 3 years ago
AdobeFontMetrics.php
165 lines
1 <?php
2
3 /**
4 * @package php-font-lib
5 * @link https://github.com/PhenX/php-font-lib
6 * @author Fabien Ménager <fabien.menager@gmail.com>
7 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
8 */
9 namespace IAWP\FontLib;
10
11 use IAWP\FontLib\Table\Type\name;
12 use IAWP\FontLib\TrueType\File;
13 /**
14 * Adobe Font Metrics file creation utility class.
15 *
16 * @package php-font-lib
17 */
18 class AdobeFontMetrics
19 {
20 private $f;
21 /**
22 * @var File
23 */
24 private $font;
25 function __construct(File $font)
26 {
27 $this->font = $font;
28 }
29 function write($file, $encoding = null)
30 {
31 $map_data = array();
32 if ($encoding) {
33 $encoding = \preg_replace("/[^a-z0-9-_]/", "", $encoding);
34 $map_file = \dirname(__FILE__) . "/../maps/{$encoding}.map";
35 if (!\file_exists($map_file)) {
36 throw new \Exception("Unknown encoding ({$encoding})");
37 }
38 $map = new EncodingMap($map_file);
39 $map_data = $map->parse();
40 }
41 $this->f = \fopen($file, "w+");
42 $font = $this->font;
43 $this->startSection("FontMetrics", 4.1);
44 $this->addPair("Notice", "Converted by PHP-font-lib");
45 $this->addPair("Comment", "https://github.com/PhenX/php-font-lib");
46 $encoding_scheme = $encoding ? $encoding : "FontSpecific";
47 $this->addPair("EncodingScheme", $encoding_scheme);
48 $records = $font->getData("name", "records");
49 foreach ($records as $id => $record) {
50 if (!isset(name::$nameIdCodes[$id]) || \preg_match("/[\r\n]/", $record->string)) {
51 continue;
52 }
53 $this->addPair(name::$nameIdCodes[$id], $record->string);
54 }
55 $os2 = $font->getData("OS/2");
56 $this->addPair("Weight", $os2["usWeightClass"] > 400 ? "Bold" : "Medium");
57 $post = $font->getData("post");
58 $this->addPair("ItalicAngle", $post["italicAngle"]);
59 $this->addPair("IsFixedPitch", $post["isFixedPitch"] ? "true" : "false");
60 $this->addPair("UnderlineThickness", $font->normalizeFUnit($post["underlineThickness"]));
61 $this->addPair("UnderlinePosition", $font->normalizeFUnit($post["underlinePosition"]));
62 $hhea = $font->getData("hhea");
63 if (isset($hhea["ascent"])) {
64 $this->addPair("FontHeightOffset", $font->normalizeFUnit($hhea["lineGap"]));
65 $this->addPair("Ascender", $font->normalizeFUnit($hhea["ascent"]));
66 $this->addPair("Descender", $font->normalizeFUnit($hhea["descent"]));
67 } else {
68 $this->addPair("FontHeightOffset", $font->normalizeFUnit($os2["typoLineGap"]));
69 $this->addPair("Ascender", $font->normalizeFUnit($os2["typoAscender"]));
70 $this->addPair("Descender", -\abs($font->normalizeFUnit($os2["typoDescender"])));
71 }
72 $head = $font->getData("head");
73 $this->addArray("FontBBox", array($font->normalizeFUnit($head["xMin"]), $font->normalizeFUnit($head["yMin"]), $font->normalizeFUnit($head["xMax"]), $font->normalizeFUnit($head["yMax"])));
74 $glyphIndexArray = $font->getUnicodeCharMap();
75 if ($glyphIndexArray) {
76 $hmtx = $font->getData("hmtx");
77 $names = $font->getData("post", "names");
78 $this->startSection("CharMetrics", \count($hmtx));
79 if ($encoding) {
80 foreach ($map_data as $code => $value) {
81 list($c, $name) = $value;
82 if (!isset($glyphIndexArray[$c])) {
83 continue;
84 }
85 $g = $glyphIndexArray[$c];
86 if (!isset($hmtx[$g])) {
87 $hmtx[$g] = $hmtx[0];
88 }
89 $this->addMetric(array("C" => $code > 255 ? -1 : $code, "WX" => $font->normalizeFUnit($hmtx[$g][0]), "N" => $name));
90 }
91 } else {
92 foreach ($glyphIndexArray as $c => $g) {
93 if (!isset($hmtx[$g])) {
94 $hmtx[$g] = $hmtx[0];
95 }
96 $this->addMetric(array("U" => $c, "WX" => $font->normalizeFUnit($hmtx[$g][0]), "N" => isset($names[$g]) ? $names[$g] : \sprintf("uni%04x", $c), "G" => $g));
97 }
98 }
99 $this->endSection("CharMetrics");
100 $kern = $font->getData("kern", "subtable");
101 $tree = \is_array($kern) ? $kern["tree"] : null;
102 if (!$encoding && \is_array($tree)) {
103 $this->startSection("KernData");
104 $this->startSection("KernPairs", \count($tree, \COUNT_RECURSIVE) - \count($tree));
105 foreach ($tree as $left => $values) {
106 if (!\is_array($values)) {
107 continue;
108 }
109 if (!isset($glyphIndexArray[$left])) {
110 continue;
111 }
112 $left_gid = $glyphIndexArray[$left];
113 if (!isset($names[$left_gid])) {
114 continue;
115 }
116 $left_name = $names[$left_gid];
117 $this->addLine("");
118 foreach ($values as $right => $value) {
119 if (!isset($glyphIndexArray[$right])) {
120 continue;
121 }
122 $right_gid = $glyphIndexArray[$right];
123 if (!isset($names[$right_gid])) {
124 continue;
125 }
126 $right_name = $names[$right_gid];
127 $this->addPair("KPX", "{$left_name} {$right_name} {$value}");
128 }
129 }
130 $this->endSection("KernPairs");
131 $this->endSection("KernData");
132 }
133 }
134 $this->endSection("FontMetrics");
135 }
136 function addLine($line)
137 {
138 \fwrite($this->f, "{$line}\n");
139 }
140 function addPair($key, $value)
141 {
142 $this->addLine("{$key} {$value}");
143 }
144 function addArray($key, $array)
145 {
146 $this->addLine("{$key} " . \implode(" ", $array));
147 }
148 function addMetric($data)
149 {
150 $array = array();
151 foreach ($data as $key => $value) {
152 $array[] = "{$key} {$value}";
153 }
154 $this->addLine(\implode(" ; ", $array));
155 }
156 function startSection($name, $value = "")
157 {
158 $this->addLine("Start{$name} {$value}");
159 }
160 function endSection($name)
161 {
162 $this->addLine("End{$name}");
163 }
164 }
165