Add a (basic) isCFFFile
helper function to detect CFF font files
Compared to most other font formats, the CFF doesn't have a constant header which makes is slightly more difficult to detect such font files. Please refer to the Compact Font Format specification: https://www.adobe.com/content/dam/acom/en/devnet/font/pdfs/5176.CFF.pdf#G3.32094
This commit is contained in:
parent
f4db38aadf
commit
9bbca04579
@ -708,6 +708,22 @@ var Font = (function FontClosure() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compared to other font formats, the header in CFF files is not constant
|
||||||
|
* but contains version numbers. To reduce the possibility of misclassifying
|
||||||
|
* font files as CFF, it's recommended to check for other font formats first.
|
||||||
|
*/
|
||||||
|
function isCFFFile(file) {
|
||||||
|
const header = file.peekBytes(4);
|
||||||
|
if (/* major version, [1, 255] */ header[0] >= 1 &&
|
||||||
|
/* minor version, [0, 255]; header[1] */
|
||||||
|
/* header size, [0, 255]; header[2] */
|
||||||
|
/* offset(0) size, [1, 4] */ (header[3] >= 1 && header[3] <= 4)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
function buildToFontChar(encoding, glyphsUnicodeMap, differences) {
|
function buildToFontChar(encoding, glyphsUnicodeMap, differences) {
|
||||||
var toFontChar = [], unicode;
|
var toFontChar = [], unicode;
|
||||||
for (var i = 0, ii = encoding.length; i < ii; i++) {
|
for (var i = 0, ii = encoding.length; i < ii; i++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user