Extract CFFParser
from fonts.js (issue 6777)
This commit is contained in:
parent
a250c150ab
commit
b961e1d21b
1646
src/core/cff_parser.js
Normal file
1646
src/core/cff_parser.js
Normal file
File diff suppressed because it is too large
Load Diff
@ -17,17 +17,19 @@
|
||||
(function (root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define('pdfjs/core/font_renderer', ['exports', 'pdfjs/shared/util',
|
||||
'pdfjs/core/stream', 'pdfjs/core/glyphlist', 'pdfjs/core/encodings'],
|
||||
factory);
|
||||
'pdfjs/core/stream', 'pdfjs/core/glyphlist', 'pdfjs/core/encodings',
|
||||
'pdfjs/core/cff_parser'], factory);
|
||||
} else if (typeof exports !== 'undefined') {
|
||||
factory(exports, require('../shared/util.js'), require('./stream.js'),
|
||||
require('./glyphlist.js'), require('./encodings.js'));
|
||||
require('./glyphlist.js'), require('./encodings.js'),
|
||||
require('./cff_parser.js'));
|
||||
} else {
|
||||
factory((root.pdfjsCoreFontRenderer = {}), root.pdfjsSharedUtil,
|
||||
root.pdfjsCoreStream, root.pdfjsCoreGlyphList, root.pdfjsCoreEncodings);
|
||||
root.pdfjsCoreStream, root.pdfjsCoreGlyphList, root.pdfjsCoreEncodings,
|
||||
root.pdfjsCoreCFFParser);
|
||||
}
|
||||
}(this, function (exports, sharedUtil, coreStream, coreGlyphList,
|
||||
coreEncodings) {
|
||||
coreEncodings, coreCFFParser) {
|
||||
|
||||
var Util = sharedUtil.Util;
|
||||
var bytesToString = sharedUtil.bytesToString;
|
||||
@ -35,9 +37,7 @@ var error = sharedUtil.error;
|
||||
var Stream = coreStream.Stream;
|
||||
var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
|
||||
var StandardEncoding = coreEncodings.StandardEncoding;
|
||||
|
||||
var coreFonts; // see _setCoreFonts below
|
||||
var CFFParser; // = coreFonts.CFFParser;
|
||||
var CFFParser = coreCFFParser.CFFParser;
|
||||
|
||||
var FontRendererFactory = (function FontRendererFactoryClosure() {
|
||||
function getLong(data, offset) {
|
||||
@ -99,10 +99,10 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
|
||||
error('not supported cmap: ' + format);
|
||||
}
|
||||
|
||||
function parseCff(data, start, end) {
|
||||
function parseCff(data, start, end, seacAnalysisEnabled) {
|
||||
var properties = {};
|
||||
var parser = new CFFParser(new Stream(data, start, end - start),
|
||||
properties);
|
||||
properties, seacAnalysisEnabled);
|
||||
var cff = parser.parse();
|
||||
return {
|
||||
glyphs: cff.charStrings.objects,
|
||||
@ -696,7 +696,7 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
|
||||
|
||||
|
||||
return {
|
||||
create: function FontRendererFactory_create(font) {
|
||||
create: function FontRendererFactory_create(font, seacAnalysisEnabled) {
|
||||
var data = new Uint8Array(font.data);
|
||||
var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
|
||||
var numTables = getUshort(data, 4);
|
||||
@ -719,7 +719,7 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
|
||||
indexToLocFormat = getUshort(data, offset + 50);
|
||||
break;
|
||||
case 'CFF ':
|
||||
cff = parseCff(data, offset, offset + length);
|
||||
cff = parseCff(data, offset, offset + length, seacAnalysisEnabled);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -736,13 +736,5 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
|
||||
};
|
||||
})();
|
||||
|
||||
|
||||
// TODO refactor to remove cyclic dependency on fonts.js
|
||||
function _setCoreFonts(coreFonts_) {
|
||||
coreFonts = coreFonts_;
|
||||
CFFParser = coreFonts_.CFFParser;
|
||||
}
|
||||
exports._setCoreFonts = _setCoreFonts;
|
||||
|
||||
exports.FontRendererFactory = FontRendererFactory;
|
||||
}));
|
||||
|
1634
src/core/fonts.js
1634
src/core/fonts.js
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,5 @@
|
||||
/* globals expect, it, describe, CFFCompiler, CFFParser, CFFIndex, CFFStrings,
|
||||
SEAC_ANALYSIS_ENABLED, Type1Parser, StringStream,
|
||||
_enableSeacAnalysis */
|
||||
Type1Parser, StringStream, SEAC_ANALYSIS_ENABLED */
|
||||
|
||||
'use strict';
|
||||
|
||||
@ -38,7 +37,7 @@ describe('font', function() {
|
||||
}
|
||||
|
||||
describe('CFFParser', function() {
|
||||
var parser = new CFFParser(fontData, {});
|
||||
var parser = new CFFParser(fontData, {}, SEAC_ANALYSIS_ENABLED);
|
||||
var cff = parser.parse();
|
||||
|
||||
it('parses header', function() {
|
||||
@ -117,46 +116,42 @@ describe('font', function() {
|
||||
});
|
||||
|
||||
it('parses a CharString endchar with 4 args w/seac enabled', function() {
|
||||
var seacAnalysisState = SEAC_ANALYSIS_ENABLED;
|
||||
try {
|
||||
_enableSeacAnalysis(true);
|
||||
var bytes = new Uint8Array([0, 1, // count
|
||||
1, // offsetSize
|
||||
0, // offset[0]
|
||||
237, 247, 22, 247, 72, 204, 247, 86, 14]);
|
||||
parser.bytes = bytes;
|
||||
var charStringsIndex = parser.parseIndex(0).obj;
|
||||
var result = parser.parseCharStrings(charStringsIndex);
|
||||
expect(result.charStrings.count).toEqual(1);
|
||||
expect(result.charStrings.get(0).length).toEqual(1);
|
||||
expect(result.seacs.length).toEqual(1);
|
||||
expect(result.seacs[0].length).toEqual(4);
|
||||
expect(result.seacs[0][0]).toEqual(130);
|
||||
expect(result.seacs[0][1]).toEqual(180);
|
||||
expect(result.seacs[0][2]).toEqual(65);
|
||||
expect(result.seacs[0][3]).toEqual(194);
|
||||
} finally {
|
||||
_enableSeacAnalysis(seacAnalysisState);
|
||||
}
|
||||
var parser = new CFFParser(fontData, {},
|
||||
/* seacAnalysisEnabled = */ true);
|
||||
var cff = parser.parse();
|
||||
|
||||
var bytes = new Uint8Array([0, 1, // count
|
||||
1, // offsetSize
|
||||
0, // offset[0]
|
||||
237, 247, 22, 247, 72, 204, 247, 86, 14]);
|
||||
parser.bytes = bytes;
|
||||
var charStringsIndex = parser.parseIndex(0).obj;
|
||||
var result = parser.parseCharStrings(charStringsIndex);
|
||||
expect(result.charStrings.count).toEqual(1);
|
||||
expect(result.charStrings.get(0).length).toEqual(1);
|
||||
expect(result.seacs.length).toEqual(1);
|
||||
expect(result.seacs[0].length).toEqual(4);
|
||||
expect(result.seacs[0][0]).toEqual(130);
|
||||
expect(result.seacs[0][1]).toEqual(180);
|
||||
expect(result.seacs[0][2]).toEqual(65);
|
||||
expect(result.seacs[0][3]).toEqual(194);
|
||||
});
|
||||
|
||||
it('parses a CharString endchar with 4 args w/seac disabled', function() {
|
||||
var seacAnalysisState = SEAC_ANALYSIS_ENABLED;
|
||||
try {
|
||||
_enableSeacAnalysis(false);
|
||||
var bytes = new Uint8Array([0, 1, // count
|
||||
1, // offsetSize
|
||||
0, // offset[0]
|
||||
237, 247, 22, 247, 72, 204, 247, 86, 14]);
|
||||
parser.bytes = bytes;
|
||||
var charStringsIndex = parser.parseIndex(0).obj;
|
||||
var result = parser.parseCharStrings(charStringsIndex);
|
||||
expect(result.charStrings.count).toEqual(1);
|
||||
expect(result.charStrings.get(0).length).toEqual(9);
|
||||
expect(result.seacs.length).toEqual(0);
|
||||
} finally {
|
||||
_enableSeacAnalysis(seacAnalysisState);
|
||||
}
|
||||
var parser = new CFFParser(fontData, {},
|
||||
/* seacAnalysisEnabled = */ false);
|
||||
var cff = parser.parse();
|
||||
|
||||
var bytes = new Uint8Array([0, 1, // count
|
||||
1, // offsetSize
|
||||
0, // offset[0]
|
||||
237, 247, 22, 247, 72, 204, 247, 86, 14]);
|
||||
parser.bytes = bytes;
|
||||
var charStringsIndex = parser.parseIndex(0).obj;
|
||||
var result = parser.parseCharStrings(charStringsIndex);
|
||||
expect(result.charStrings.count).toEqual(1);
|
||||
expect(result.charStrings.get(0).length).toEqual(9);
|
||||
expect(result.seacs.length).toEqual(0);
|
||||
});
|
||||
|
||||
it('parses a CharString endchar no args', function() {
|
||||
|
@ -48,12 +48,12 @@ function initializePDFJS(callback) {
|
||||
'pdfjs/core/annotation', 'pdfjs/core/crypto', 'pdfjs/core/stream',
|
||||
'pdfjs/core/fonts', 'pdfjs/core/ps_parser', 'pdfjs/core/function',
|
||||
'pdfjs/core/parser', 'pdfjs/core/evaluator', 'pdfjs/core/cmap',
|
||||
'pdfjs/core/worker', 'pdfjs/core/network', 'pdfjs/display/api',
|
||||
'pdfjs/display/metadata', 'pdfjs/display/dom_utils'],
|
||||
'pdfjs/core/worker', 'pdfjs/core/network', 'pdfjs/core/cff_parser',
|
||||
'pdfjs/display/api', 'pdfjs/display/metadata', 'pdfjs/display/dom_utils'],
|
||||
function (sharedUtil, displayGlobal, corePrimitives, coreAnnotation,
|
||||
coreCrypto, coreStream, coreFonts, corePsParser, coreFunction,
|
||||
coreParser, coreEvaluator, coreCMap, coreWorker, coreNetwork,
|
||||
displayAPI, displayMetadata, displayDOMUtils) {
|
||||
coreCFFParser, displayAPI, displayMetadata, displayDOMUtils) {
|
||||
|
||||
pdfjsLibs = {
|
||||
sharedUtil: sharedUtil,
|
||||
@ -70,6 +70,7 @@ function initializePDFJS(callback) {
|
||||
coreCMap: coreCMap,
|
||||
coreWorker: coreWorker,
|
||||
coreNetwork: coreNetwork,
|
||||
coreCFFParser: coreCFFParser,
|
||||
displayAPI: displayAPI,
|
||||
displayMetadata: displayMetadata,
|
||||
displayDOMUtils: displayDOMUtils
|
||||
|
Loading…
Reference in New Issue
Block a user