Convert src/core/cff_font.js
to use standard classes
This commit is contained in:
parent
542ee0d798
commit
e803584fe7
@ -17,9 +17,8 @@ import { CFFCompiler, CFFParser } from "./cff_parser.js";
|
|||||||
import { SEAC_ANALYSIS_ENABLED, type1FontGlyphMapping } from "./fonts_utils.js";
|
import { SEAC_ANALYSIS_ENABLED, type1FontGlyphMapping } from "./fonts_utils.js";
|
||||||
import { warn } from "../shared/util.js";
|
import { warn } from "../shared/util.js";
|
||||||
|
|
||||||
const CFFFont = (function CFFFontClosure() {
|
class CFFFont {
|
||||||
// eslint-disable-next-line no-shadow
|
constructor(file, properties) {
|
||||||
function CFFFont(file, properties) {
|
|
||||||
this.properties = properties;
|
this.properties = properties;
|
||||||
|
|
||||||
const parser = new CFFParser(file, properties, SEAC_ANALYSIS_ENABLED);
|
const parser = new CFFParser(file, properties, SEAC_ANALYSIS_ENABLED);
|
||||||
@ -38,78 +37,77 @@ const CFFFont = (function CFFFontClosure() {
|
|||||||
this._createBuiltInEncoding();
|
this._createBuiltInEncoding();
|
||||||
}
|
}
|
||||||
|
|
||||||
CFFFont.prototype = {
|
get numGlyphs() {
|
||||||
get numGlyphs() {
|
return this.cff.charStrings.count;
|
||||||
return this.cff.charStrings.count;
|
}
|
||||||
},
|
|
||||||
getCharset: function CFFFont_getCharset() {
|
|
||||||
return this.cff.charset.charset;
|
|
||||||
},
|
|
||||||
getGlyphMapping: function CFFFont_getGlyphMapping() {
|
|
||||||
const cff = this.cff;
|
|
||||||
const properties = this.properties;
|
|
||||||
const charsets = cff.charset.charset;
|
|
||||||
let charCodeToGlyphId;
|
|
||||||
let glyphId;
|
|
||||||
|
|
||||||
if (properties.composite) {
|
getCharset() {
|
||||||
charCodeToGlyphId = Object.create(null);
|
return this.cff.charset.charset;
|
||||||
let charCode;
|
}
|
||||||
if (cff.isCIDFont) {
|
|
||||||
// If the font is actually a CID font then we should use the charset
|
getGlyphMapping() {
|
||||||
// to map CIDs to GIDs.
|
const cff = this.cff;
|
||||||
for (glyphId = 0; glyphId < charsets.length; glyphId++) {
|
const properties = this.properties;
|
||||||
const cid = charsets[glyphId];
|
const charsets = cff.charset.charset;
|
||||||
charCode = properties.cMap.charCodeOf(cid);
|
let charCodeToGlyphId;
|
||||||
charCodeToGlyphId[charCode] = glyphId;
|
let glyphId;
|
||||||
}
|
|
||||||
} else {
|
if (properties.composite) {
|
||||||
// If it is NOT actually a CID font then CIDs should be mapped
|
charCodeToGlyphId = Object.create(null);
|
||||||
// directly to GIDs.
|
let charCode;
|
||||||
for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
|
if (cff.isCIDFont) {
|
||||||
charCode = properties.cMap.charCodeOf(glyphId);
|
// If the font is actually a CID font then we should use the charset
|
||||||
charCodeToGlyphId[charCode] = glyphId;
|
// to map CIDs to GIDs.
|
||||||
}
|
for (glyphId = 0; glyphId < charsets.length; glyphId++) {
|
||||||
|
const cid = charsets[glyphId];
|
||||||
|
charCode = properties.cMap.charCodeOf(cid);
|
||||||
|
charCodeToGlyphId[charCode] = glyphId;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// If it is NOT actually a CID font then CIDs should be mapped
|
||||||
|
// directly to GIDs.
|
||||||
|
for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
|
||||||
|
charCode = properties.cMap.charCodeOf(glyphId);
|
||||||
|
charCodeToGlyphId[charCode] = glyphId;
|
||||||
}
|
}
|
||||||
return charCodeToGlyphId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const encoding = cff.encoding ? cff.encoding.encoding : null;
|
|
||||||
charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
|
|
||||||
return charCodeToGlyphId;
|
return charCodeToGlyphId;
|
||||||
},
|
}
|
||||||
hasGlyphId: function CFFFont_hasGlyphID(id) {
|
|
||||||
return this.cff.hasGlyphId(id);
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
const encoding = cff.encoding ? cff.encoding.encoding : null;
|
||||||
* @private
|
charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
|
||||||
*/
|
return charCodeToGlyphId;
|
||||||
_createBuiltInEncoding() {
|
}
|
||||||
const { charset, encoding } = this.cff;
|
|
||||||
if (!charset || !encoding) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const charsets = charset.charset,
|
|
||||||
encodings = encoding.encoding;
|
|
||||||
const map = [];
|
|
||||||
|
|
||||||
for (const charCode in encodings) {
|
hasGlyphId(id) {
|
||||||
const glyphId = encodings[charCode];
|
return this.cff.hasGlyphId(id);
|
||||||
if (glyphId >= 0) {
|
}
|
||||||
const glyphName = charsets[glyphId];
|
|
||||||
if (glyphName) {
|
/**
|
||||||
map[charCode] = glyphName;
|
* @private
|
||||||
}
|
*/
|
||||||
|
_createBuiltInEncoding() {
|
||||||
|
const { charset, encoding } = this.cff;
|
||||||
|
if (!charset || !encoding) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const charsets = charset.charset,
|
||||||
|
encodings = encoding.encoding;
|
||||||
|
const map = [];
|
||||||
|
|
||||||
|
for (const charCode in encodings) {
|
||||||
|
const glyphId = encodings[charCode];
|
||||||
|
if (glyphId >= 0) {
|
||||||
|
const glyphName = charsets[glyphId];
|
||||||
|
if (glyphName) {
|
||||||
|
map[charCode] = glyphName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (map.length > 0) {
|
}
|
||||||
this.properties.builtInEncoding = map;
|
if (map.length > 0) {
|
||||||
}
|
this.properties.builtInEncoding = map;
|
||||||
},
|
}
|
||||||
};
|
}
|
||||||
|
}
|
||||||
return CFFFont;
|
|
||||||
})();
|
|
||||||
|
|
||||||
export { CFFFont };
|
export { CFFFont };
|
||||||
|
Loading…
Reference in New Issue
Block a user