1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | "use strict";
|
23 |
|
24 | Object.defineProperty(exports, "__esModule", {
|
25 | value: true
|
26 | });
|
27 | exports.CFFFont = void 0;
|
28 |
|
29 | var _cff_parser = require("./cff_parser.js");
|
30 |
|
31 | var _fonts_utils = require("./fonts_utils.js");
|
32 |
|
33 | var _util = require("../shared/util.js");
|
34 |
|
35 | class CFFFont {
|
36 | constructor(file, properties) {
|
37 | this.properties = properties;
|
38 | const parser = new _cff_parser.CFFParser(file, properties, _fonts_utils.SEAC_ANALYSIS_ENABLED);
|
39 | this.cff = parser.parse();
|
40 | this.cff.duplicateFirstGlyph();
|
41 | const compiler = new _cff_parser.CFFCompiler(this.cff);
|
42 | this.seacs = this.cff.seacs;
|
43 |
|
44 | try {
|
45 | this.data = compiler.compile();
|
46 | } catch (e) {
|
47 | (0, _util.warn)("Failed to compile font " + properties.loadedName);
|
48 | this.data = file;
|
49 | }
|
50 |
|
51 | this._createBuiltInEncoding();
|
52 | }
|
53 |
|
54 | get numGlyphs() {
|
55 | return this.cff.charStrings.count;
|
56 | }
|
57 |
|
58 | getCharset() {
|
59 | return this.cff.charset.charset;
|
60 | }
|
61 |
|
62 | getGlyphMapping() {
|
63 | const cff = this.cff;
|
64 | const properties = this.properties;
|
65 | const charsets = cff.charset.charset;
|
66 | let charCodeToGlyphId;
|
67 | let glyphId;
|
68 |
|
69 | if (properties.composite) {
|
70 | charCodeToGlyphId = Object.create(null);
|
71 | let charCode;
|
72 |
|
73 | if (cff.isCIDFont) {
|
74 | for (glyphId = 0; glyphId < charsets.length; glyphId++) {
|
75 | const cid = charsets[glyphId];
|
76 | charCode = properties.cMap.charCodeOf(cid);
|
77 | charCodeToGlyphId[charCode] = glyphId;
|
78 | }
|
79 | } else {
|
80 | for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
|
81 | charCode = properties.cMap.charCodeOf(glyphId);
|
82 | charCodeToGlyphId[charCode] = glyphId;
|
83 | }
|
84 | }
|
85 |
|
86 | return charCodeToGlyphId;
|
87 | }
|
88 |
|
89 | let encoding = cff.encoding ? cff.encoding.encoding : null;
|
90 |
|
91 | if (properties.isInternalFont) {
|
92 | encoding = properties.defaultEncoding;
|
93 | }
|
94 |
|
95 | charCodeToGlyphId = (0, _fonts_utils.type1FontGlyphMapping)(properties, encoding, charsets);
|
96 | return charCodeToGlyphId;
|
97 | }
|
98 |
|
99 | hasGlyphId(id) {
|
100 | return this.cff.hasGlyphId(id);
|
101 | }
|
102 |
|
103 | _createBuiltInEncoding() {
|
104 | const {
|
105 | charset,
|
106 | encoding
|
107 | } = this.cff;
|
108 |
|
109 | if (!charset || !encoding) {
|
110 | return;
|
111 | }
|
112 |
|
113 | const charsets = charset.charset,
|
114 | encodings = encoding.encoding;
|
115 | const map = [];
|
116 |
|
117 | for (const charCode in encodings) {
|
118 | const glyphId = encodings[charCode];
|
119 |
|
120 | if (glyphId >= 0) {
|
121 | const glyphName = charsets[glyphId];
|
122 |
|
123 | if (glyphName) {
|
124 | map[charCode] = glyphName;
|
125 | }
|
126 | }
|
127 | }
|
128 |
|
129 | if (map.length > 0) {
|
130 | this.properties.builtInEncoding = map;
|
131 | }
|
132 | }
|
133 |
|
134 | }
|
135 |
|
136 | exports.CFFFont = CFFFont; |
\ | No newline at end of file |