12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446 |
- /**
- * @licstart The following is the entire license notice for the
- * Javascript code in this page
- *
- * Copyright 2019 Mozilla Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * @licend The above is the entire license notice for the
- * Javascript code in this page
- */
- "use strict";
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.PartialEvaluator = void 0;
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
- var _util = require("../shared/util");
- var _cmap = require("./cmap");
- var _primitives = require("./primitives");
- var _fonts = require("./fonts");
- var _encodings = require("./encodings");
- var _unicode = require("./unicode");
- var _standard_fonts = require("./standard_fonts");
- var _pattern = require("./pattern");
- var _parser = require("./parser");
- var _bidi = require("./bidi");
- var _colorspace = require("./colorspace");
- var _stream = require("./stream");
- var _glyphlist = require("./glyphlist");
- var _core_utils = require("./core_utils");
- var _metrics = require("./metrics");
- var _function = require("./function");
- var _jpeg_stream = require("./jpeg_stream");
- var _murmurhash = require("./murmurhash3");
- var _image_utils = require("./image_utils");
- var _operator_list = require("./operator_list");
- var _image = require("./image");
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
- var PartialEvaluator = function PartialEvaluatorClosure() {
- var DefaultPartialEvaluatorOptions = {
- forceDataSchema: false,
- maxImageSize: -1,
- disableFontFace: false,
- nativeImageDecoderSupport: _util.NativeImageDecoding.DECODE,
- ignoreErrors: false,
- isEvalSupported: true
- };
- function PartialEvaluator(_ref) {
- var _this = this;
- var xref = _ref.xref,
- handler = _ref.handler,
- pageIndex = _ref.pageIndex,
- idFactory = _ref.idFactory,
- fontCache = _ref.fontCache,
- builtInCMapCache = _ref.builtInCMapCache,
- _ref$options = _ref.options,
- options = _ref$options === void 0 ? null : _ref$options,
- pdfFunctionFactory = _ref.pdfFunctionFactory;
- this.xref = xref;
- this.handler = handler;
- this.pageIndex = pageIndex;
- this.idFactory = idFactory;
- this.fontCache = fontCache;
- this.builtInCMapCache = builtInCMapCache;
- this.options = options || DefaultPartialEvaluatorOptions;
- this.pdfFunctionFactory = pdfFunctionFactory;
- this.parsingType3Font = false;
- this.fetchBuiltInCMap =
- /*#__PURE__*/
- function () {
- var _ref2 = _asyncToGenerator(
- /*#__PURE__*/
- _regenerator["default"].mark(function _callee(name) {
- var data;
- return _regenerator["default"].wrap(function _callee$(_context) {
- while (1) {
- switch (_context.prev = _context.next) {
- case 0:
- if (!_this.builtInCMapCache.has(name)) {
- _context.next = 2;
- break;
- }
- return _context.abrupt("return", _this.builtInCMapCache.get(name));
- case 2:
- _context.next = 4;
- return _this.handler.sendWithPromise('FetchBuiltInCMap', {
- name: name
- });
- case 4:
- data = _context.sent;
- if (data.compressionType !== _util.CMapCompressionType.NONE) {
- _this.builtInCMapCache.set(name, data);
- }
- return _context.abrupt("return", data);
- case 7:
- case "end":
- return _context.stop();
- }
- }
- }, _callee);
- }));
- return function (_x) {
- return _ref2.apply(this, arguments);
- };
- }();
- }
- var TIME_SLOT_DURATION_MS = 20;
- var CHECK_TIME_EVERY = 100;
- function TimeSlotManager() {
- this.reset();
- }
- TimeSlotManager.prototype = {
- check: function TimeSlotManager_check() {
- if (++this.checked < CHECK_TIME_EVERY) {
- return false;
- }
- this.checked = 0;
- return this.endTime <= Date.now();
- },
- reset: function TimeSlotManager_reset() {
- this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
- this.checked = 0;
- }
- };
- function normalizeBlendMode(value) {
- if (!(0, _primitives.isName)(value)) {
- return 'source-over';
- }
- switch (value.name) {
- case 'Normal':
- case 'Compatible':
- return 'source-over';
- case 'Multiply':
- return 'multiply';
- case 'Screen':
- return 'screen';
- case 'Overlay':
- return 'overlay';
- case 'Darken':
- return 'darken';
- case 'Lighten':
- return 'lighten';
- case 'ColorDodge':
- return 'color-dodge';
- case 'ColorBurn':
- return 'color-burn';
- case 'HardLight':
- return 'hard-light';
- case 'SoftLight':
- return 'soft-light';
- case 'Difference':
- return 'difference';
- case 'Exclusion':
- return 'exclusion';
- case 'Hue':
- return 'hue';
- case 'Saturation':
- return 'saturation';
- case 'Color':
- return 'color';
- case 'Luminosity':
- return 'luminosity';
- }
- (0, _util.warn)('Unsupported blend mode: ' + value.name);
- return 'source-over';
- }
- var deferred = Promise.resolve();
- var TILING_PATTERN = 1,
- SHADING_PATTERN = 2;
- PartialEvaluator.prototype = {
- clone: function clone() {
- var newOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DefaultPartialEvaluatorOptions;
- var newEvaluator = Object.create(this);
- newEvaluator.options = newOptions;
- return newEvaluator;
- },
- hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
- if (!(0, _primitives.isDict)(resources)) {
- return false;
- }
- var processed = Object.create(null);
- if (resources.objId) {
- processed[resources.objId] = true;
- }
- var nodes = [resources],
- xref = this.xref;
- while (nodes.length) {
- var key, i, ii;
- var node = nodes.shift();
- var graphicStates = node.get('ExtGState');
- if ((0, _primitives.isDict)(graphicStates)) {
- var graphicStatesKeys = graphicStates.getKeys();
- for (i = 0, ii = graphicStatesKeys.length; i < ii; i++) {
- key = graphicStatesKeys[i];
- var graphicState = graphicStates.get(key);
- var bm = graphicState.get('BM');
- if ((0, _primitives.isName)(bm) && bm.name !== 'Normal') {
- return true;
- }
- }
- }
- var xObjects = node.get('XObject');
- if (!(0, _primitives.isDict)(xObjects)) {
- continue;
- }
- var xObjectsKeys = xObjects.getKeys();
- for (i = 0, ii = xObjectsKeys.length; i < ii; i++) {
- key = xObjectsKeys[i];
- var xObject = xObjects.getRaw(key);
- if ((0, _primitives.isRef)(xObject)) {
- if (processed[xObject.toString()]) {
- continue;
- }
- xObject = xref.fetch(xObject);
- }
- if (!(0, _primitives.isStream)(xObject)) {
- continue;
- }
- if (xObject.dict.objId) {
- if (processed[xObject.dict.objId]) {
- continue;
- }
- processed[xObject.dict.objId] = true;
- }
- var xResources = xObject.dict.get('Resources');
- if ((0, _primitives.isDict)(xResources) && (!xResources.objId || !processed[xResources.objId])) {
- nodes.push(xResources);
- if (xResources.objId) {
- processed[xResources.objId] = true;
- }
- }
- }
- }
- return false;
- },
- buildFormXObject: function PartialEvaluator_buildFormXObject(resources, xobj, smask, operatorList, task, initialState) {
- var dict = xobj.dict;
- var matrix = dict.getArray('Matrix');
- var bbox = dict.getArray('BBox');
- if (Array.isArray(bbox) && bbox.length === 4) {
- bbox = _util.Util.normalizeRect(bbox);
- } else {
- bbox = null;
- }
- var group = dict.get('Group');
- if (group) {
- var groupOptions = {
- matrix: matrix,
- bbox: bbox,
- smask: smask,
- isolated: false,
- knockout: false
- };
- var groupSubtype = group.get('S');
- var colorSpace = null;
- if ((0, _primitives.isName)(groupSubtype, 'Transparency')) {
- groupOptions.isolated = group.get('I') || false;
- groupOptions.knockout = group.get('K') || false;
- if (group.has('CS')) {
- colorSpace = _colorspace.ColorSpace.parse(group.get('CS'), this.xref, resources, this.pdfFunctionFactory);
- }
- }
- if (smask && smask.backdrop) {
- colorSpace = colorSpace || _colorspace.ColorSpace.singletons.rgb;
- smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
- }
- operatorList.addOp(_util.OPS.beginGroup, [groupOptions]);
- }
- operatorList.addOp(_util.OPS.paintFormXObjectBegin, [matrix, bbox]);
- return this.getOperatorList({
- stream: xobj,
- task: task,
- resources: dict.get('Resources') || resources,
- operatorList: operatorList,
- initialState: initialState
- }).then(function () {
- operatorList.addOp(_util.OPS.paintFormXObjectEnd, []);
- if (group) {
- operatorList.addOp(_util.OPS.endGroup, [groupOptions]);
- }
- });
- },
- buildPaintImageXObject: function () {
- var _buildPaintImageXObject = _asyncToGenerator(
- /*#__PURE__*/
- _regenerator["default"].mark(function _callee2(_ref3) {
- var _this2 = this;
- var resources, image, _ref3$isInline, isInline, operatorList, cacheKey, imageCache, _ref3$forceDisableNat, forceDisableNativeImageDecoder, dict, w, h, maxImageSize, imageMask, imgData, args, width, height, bitStrideLength, imgArray, decode, softMask, mask, SMALL_IMAGE_DIMENSIONS, imageObj, nativeImageDecoderSupport, objId, nativeImageDecoder, imgPromise;
- return _regenerator["default"].wrap(function _callee2$(_context2) {
- while (1) {
- switch (_context2.prev = _context2.next) {
- case 0:
- resources = _ref3.resources, image = _ref3.image, _ref3$isInline = _ref3.isInline, isInline = _ref3$isInline === void 0 ? false : _ref3$isInline, operatorList = _ref3.operatorList, cacheKey = _ref3.cacheKey, imageCache = _ref3.imageCache, _ref3$forceDisableNat = _ref3.forceDisableNativeImageDecoder, forceDisableNativeImageDecoder = _ref3$forceDisableNat === void 0 ? false : _ref3$forceDisableNat;
- dict = image.dict;
- w = dict.get('Width', 'W');
- h = dict.get('Height', 'H');
- if (!(!(w && (0, _util.isNum)(w)) || !(h && (0, _util.isNum)(h)))) {
- _context2.next = 7;
- break;
- }
- (0, _util.warn)('Image dimensions are missing, or not numbers.');
- return _context2.abrupt("return", undefined);
- case 7:
- maxImageSize = this.options.maxImageSize;
- if (!(maxImageSize !== -1 && w * h > maxImageSize)) {
- _context2.next = 11;
- break;
- }
- (0, _util.warn)('Image exceeded maximum allowed size and was removed.');
- return _context2.abrupt("return", undefined);
- case 11:
- imageMask = dict.get('ImageMask', 'IM') || false;
- if (!imageMask) {
- _context2.next = 24;
- break;
- }
- width = dict.get('Width', 'W');
- height = dict.get('Height', 'H');
- bitStrideLength = width + 7 >> 3;
- imgArray = image.getBytes(bitStrideLength * height, true);
- decode = dict.getArray('Decode', 'D');
- imgData = _image.PDFImage.createMask({
- imgArray: imgArray,
- width: width,
- height: height,
- imageIsFromDecodeStream: image instanceof _stream.DecodeStream,
- inverseDecode: !!decode && decode[0] > 0
- });
- imgData.cached = !!cacheKey;
- args = [imgData];
- operatorList.addOp(_util.OPS.paintImageMaskXObject, args);
- if (cacheKey) {
- imageCache[cacheKey] = {
- fn: _util.OPS.paintImageMaskXObject,
- args: args
- };
- }
- return _context2.abrupt("return", undefined);
- case 24:
- softMask = dict.get('SMask', 'SM') || false;
- mask = dict.get('Mask') || false;
- SMALL_IMAGE_DIMENSIONS = 200;
- if (!(isInline && !softMask && !mask && !(image instanceof _jpeg_stream.JpegStream) && w + h < SMALL_IMAGE_DIMENSIONS)) {
- _context2.next = 32;
- break;
- }
- imageObj = new _image.PDFImage({
- xref: this.xref,
- res: resources,
- image: image,
- isInline: isInline,
- pdfFunctionFactory: this.pdfFunctionFactory
- });
- imgData = imageObj.createImageData(true);
- operatorList.addOp(_util.OPS.paintInlineImageXObject, [imgData]);
- return _context2.abrupt("return", undefined);
- case 32:
- nativeImageDecoderSupport = forceDisableNativeImageDecoder ? _util.NativeImageDecoding.NONE : this.options.nativeImageDecoderSupport;
- objId = "img_".concat(this.idFactory.createObjId());
- if (this.parsingType3Font) {
- (0, _util.assert)(nativeImageDecoderSupport === _util.NativeImageDecoding.NONE, 'Type3 image resources should be completely decoded in the worker.');
- objId = "".concat(this.idFactory.getDocId(), "_type3res_").concat(objId);
- }
- if (!(nativeImageDecoderSupport !== _util.NativeImageDecoding.NONE && !softMask && !mask && image instanceof _jpeg_stream.JpegStream && _image_utils.NativeImageDecoder.isSupported(image, this.xref, resources, this.pdfFunctionFactory))) {
- _context2.next = 37;
- break;
- }
- return _context2.abrupt("return", this.handler.sendWithPromise('obj', [objId, this.pageIndex, 'JpegStream', image.getIR(this.options.forceDataSchema)]).then(function () {
- operatorList.addDependency(objId);
- args = [objId, w, h];
- operatorList.addOp(_util.OPS.paintJpegXObject, args);
- if (cacheKey) {
- imageCache[cacheKey] = {
- fn: _util.OPS.paintJpegXObject,
- args: args
- };
- }
- }, function (reason) {
- (0, _util.warn)('Native JPEG decoding failed -- trying to recover: ' + (reason && reason.message));
- return _this2.buildPaintImageXObject({
- resources: resources,
- image: image,
- isInline: isInline,
- operatorList: operatorList,
- cacheKey: cacheKey,
- imageCache: imageCache,
- forceDisableNativeImageDecoder: true
- });
- }));
- case 37:
- nativeImageDecoder = null;
- if (nativeImageDecoderSupport === _util.NativeImageDecoding.DECODE && (image instanceof _jpeg_stream.JpegStream || mask instanceof _jpeg_stream.JpegStream || softMask instanceof _jpeg_stream.JpegStream)) {
- nativeImageDecoder = new _image_utils.NativeImageDecoder({
- xref: this.xref,
- resources: resources,
- handler: this.handler,
- forceDataSchema: this.options.forceDataSchema,
- pdfFunctionFactory: this.pdfFunctionFactory
- });
- }
- operatorList.addDependency(objId);
- args = [objId, w, h];
- imgPromise = _image.PDFImage.buildImage({
- handler: this.handler,
- xref: this.xref,
- res: resources,
- image: image,
- isInline: isInline,
- nativeDecoder: nativeImageDecoder,
- pdfFunctionFactory: this.pdfFunctionFactory
- }).then(function (imageObj) {
- var imgData = imageObj.createImageData(false);
- if (_this2.parsingType3Font) {
- return _this2.handler.sendWithPromise('commonobj', [objId, 'FontType3Res', imgData], [imgData.data.buffer]);
- }
- _this2.handler.send('obj', [objId, _this2.pageIndex, 'Image', imgData], [imgData.data.buffer]);
- return undefined;
- })["catch"](function (reason) {
- (0, _util.warn)('Unable to decode image: ' + reason);
- if (_this2.parsingType3Font) {
- return _this2.handler.sendWithPromise('commonobj', [objId, 'FontType3Res', null]);
- }
- _this2.handler.send('obj', [objId, _this2.pageIndex, 'Image', null]);
- return undefined;
- });
- if (!this.parsingType3Font) {
- _context2.next = 45;
- break;
- }
- _context2.next = 45;
- return imgPromise;
- case 45:
- operatorList.addOp(_util.OPS.paintImageXObject, args);
- if (cacheKey) {
- imageCache[cacheKey] = {
- fn: _util.OPS.paintImageXObject,
- args: args
- };
- }
- return _context2.abrupt("return", undefined);
- case 48:
- case "end":
- return _context2.stop();
- }
- }
- }, _callee2, this);
- }));
- function buildPaintImageXObject(_x2) {
- return _buildPaintImageXObject.apply(this, arguments);
- }
- return buildPaintImageXObject;
- }(),
- handleSMask: function PartialEvaluator_handleSmask(smask, resources, operatorList, task, stateManager) {
- var smaskContent = smask.get('G');
- var smaskOptions = {
- subtype: smask.get('S').name,
- backdrop: smask.get('BC')
- };
- var transferObj = smask.get('TR');
- if ((0, _function.isPDFFunction)(transferObj)) {
- var transferFn = this.pdfFunctionFactory.create(transferObj);
- var transferMap = new Uint8Array(256);
- var tmp = new Float32Array(1);
- for (var i = 0; i < 256; i++) {
- tmp[0] = i / 255;
- transferFn(tmp, 0, tmp, 0);
- transferMap[i] = tmp[0] * 255 | 0;
- }
- smaskOptions.transferMap = transferMap;
- }
- return this.buildFormXObject(resources, smaskContent, smaskOptions, operatorList, task, stateManager.state.clone());
- },
- handleTilingType: function handleTilingType(fn, args, resources, pattern, patternDict, operatorList, task) {
- var _this3 = this;
- var tilingOpList = new _operator_list.OperatorList();
- var resourcesArray = [patternDict.get('Resources'), resources];
- var patternResources = _primitives.Dict.merge(this.xref, resourcesArray);
- return this.getOperatorList({
- stream: pattern,
- task: task,
- resources: patternResources,
- operatorList: tilingOpList
- }).then(function () {
- return (0, _pattern.getTilingPatternIR)({
- fnArray: tilingOpList.fnArray,
- argsArray: tilingOpList.argsArray
- }, patternDict, args);
- }).then(function (tilingPatternIR) {
- operatorList.addDependencies(tilingOpList.dependencies);
- operatorList.addOp(fn, tilingPatternIR);
- }, function (reason) {
- if (_this3.options.ignoreErrors) {
- _this3.handler.send('UnsupportedFeature', {
- featureId: _util.UNSUPPORTED_FEATURES.unknown
- });
- (0, _util.warn)("handleTilingType - ignoring pattern: \"".concat(reason, "\"."));
- return;
- }
- throw reason;
- });
- },
- handleSetFont: function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef, operatorList, task, state) {
- var _this4 = this;
- var fontName;
- if (fontArgs) {
- fontArgs = fontArgs.slice();
- fontName = fontArgs[0].name;
- }
- return this.loadFont(fontName, fontRef, resources).then(function (translated) {
- if (!translated.font.isType3Font) {
- return translated;
- }
- return translated.loadType3Data(_this4, resources, operatorList, task).then(function () {
- return translated;
- })["catch"](function (reason) {
- _this4.handler.send('UnsupportedFeature', {
- featureId: _util.UNSUPPORTED_FEATURES.font
- });
- return new TranslatedFont('g_font_error', new _fonts.ErrorFont('Type3 font load error: ' + reason), translated.font);
- });
- }).then(function (translated) {
- state.font = translated.font;
- translated.send(_this4.handler);
- return translated.loadedName;
- });
- },
- handleText: function handleText(chars, state) {
- var font = state.font;
- var glyphs = font.charsToGlyphs(chars);
- if (font.data) {
- var isAddToPathSet = !!(state.textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG);
- if (isAddToPathSet || state.fillColorSpace.name === 'Pattern' || font.disableFontFace || this.options.disableFontFace) {
- PartialEvaluator.buildFontPaths(font, glyphs, this.handler);
- }
- }
- return glyphs;
- },
- setGState: function PartialEvaluator_setGState(resources, gState, operatorList, task, stateManager) {
- var _this5 = this;
- var gStateObj = [];
- var gStateKeys = gState.getKeys();
- var promise = Promise.resolve();
- var _loop = function _loop() {
- var key = gStateKeys[i];
- var value = gState.get(key);
- switch (key) {
- case 'Type':
- break;
- case 'LW':
- case 'LC':
- case 'LJ':
- case 'ML':
- case 'D':
- case 'RI':
- case 'FL':
- case 'CA':
- case 'ca':
- gStateObj.push([key, value]);
- break;
- case 'Font':
- promise = promise.then(function () {
- return _this5.handleSetFont(resources, null, value[0], operatorList, task, stateManager.state).then(function (loadedName) {
- operatorList.addDependency(loadedName);
- gStateObj.push([key, [loadedName, value[1]]]);
- });
- });
- break;
- case 'BM':
- gStateObj.push([key, normalizeBlendMode(value)]);
- break;
- case 'SMask':
- if ((0, _primitives.isName)(value, 'None')) {
- gStateObj.push([key, false]);
- break;
- }
- if ((0, _primitives.isDict)(value)) {
- promise = promise.then(function () {
- return _this5.handleSMask(value, resources, operatorList, task, stateManager);
- });
- gStateObj.push([key, true]);
- } else {
- (0, _util.warn)('Unsupported SMask type');
- }
- break;
- case 'OP':
- case 'op':
- case 'OPM':
- case 'BG':
- case 'BG2':
- case 'UCR':
- case 'UCR2':
- case 'TR':
- case 'TR2':
- case 'HT':
- case 'SM':
- case 'SA':
- case 'AIS':
- case 'TK':
- (0, _util.info)('graphic state operator ' + key);
- break;
- default:
- (0, _util.info)('Unknown graphic state operator ' + key);
- break;
- }
- };
- for (var i = 0, ii = gStateKeys.length; i < ii; i++) {
- _loop();
- }
- return promise.then(function () {
- if (gStateObj.length > 0) {
- operatorList.addOp(_util.OPS.setGState, [gStateObj]);
- }
- });
- },
- loadFont: function PartialEvaluator_loadFont(fontName, font, resources) {
- var _this6 = this;
- function errorFont() {
- return Promise.resolve(new TranslatedFont('g_font_error', new _fonts.ErrorFont('Font ' + fontName + ' is not available'), font));
- }
- var fontRef,
- xref = this.xref;
- if (font) {
- if (!(0, _primitives.isRef)(font)) {
- throw new Error('The "font" object should be a reference.');
- }
- fontRef = font;
- } else {
- var fontRes = resources.get('Font');
- if (fontRes) {
- fontRef = fontRes.getRaw(fontName);
- } else {
- (0, _util.warn)('fontRes not available');
- return errorFont();
- }
- }
- if (!fontRef) {
- (0, _util.warn)('fontRef not available');
- return errorFont();
- }
- if (this.fontCache.has(fontRef)) {
- return this.fontCache.get(fontRef);
- }
- font = xref.fetchIfRef(fontRef);
- if (!(0, _primitives.isDict)(font)) {
- return errorFont();
- }
- if (font.translated) {
- return font.translated;
- }
- var fontCapability = (0, _util.createPromiseCapability)();
- var preEvaluatedFont = this.preEvaluateFont(font);
- var descriptor = preEvaluatedFont.descriptor,
- hash = preEvaluatedFont.hash;
- var fontRefIsRef = (0, _primitives.isRef)(fontRef),
- fontID;
- if (fontRefIsRef) {
- fontID = fontRef.toString();
- }
- if (hash && (0, _primitives.isDict)(descriptor)) {
- if (!descriptor.fontAliases) {
- descriptor.fontAliases = Object.create(null);
- }
- var fontAliases = descriptor.fontAliases;
- if (fontAliases[hash]) {
- var aliasFontRef = fontAliases[hash].aliasRef;
- if (fontRefIsRef && aliasFontRef && this.fontCache.has(aliasFontRef)) {
- this.fontCache.putAlias(fontRef, aliasFontRef);
- return this.fontCache.get(fontRef);
- }
- } else {
- fontAliases[hash] = {
- fontID: _fonts.Font.getFontID()
- };
- }
- if (fontRefIsRef) {
- fontAliases[hash].aliasRef = fontRef;
- }
- fontID = fontAliases[hash].fontID;
- }
- if (fontRefIsRef) {
- this.fontCache.put(fontRef, fontCapability.promise);
- } else {
- if (!fontID) {
- fontID = this.idFactory.createObjId();
- }
- this.fontCache.put("id_".concat(fontID), fontCapability.promise);
- }
- (0, _util.assert)(fontID, 'The "fontID" must be defined.');
- font.loadedName = "".concat(this.idFactory.getDocId(), "_f").concat(fontID);
- font.translated = fontCapability.promise;
- var translatedPromise;
- try {
- translatedPromise = this.translateFont(preEvaluatedFont);
- } catch (e) {
- translatedPromise = Promise.reject(e);
- }
- translatedPromise.then(function (translatedFont) {
- if (translatedFont.fontType !== undefined) {
- var xrefFontStats = xref.stats.fontTypes;
- xrefFontStats[translatedFont.fontType] = true;
- }
- fontCapability.resolve(new TranslatedFont(font.loadedName, translatedFont, font));
- })["catch"](function (reason) {
- _this6.handler.send('UnsupportedFeature', {
- featureId: _util.UNSUPPORTED_FEATURES.font
- });
- try {
- var fontFile3 = descriptor && descriptor.get('FontFile3');
- var subtype = fontFile3 && fontFile3.get('Subtype');
- var fontType = (0, _fonts.getFontType)(preEvaluatedFont.type, subtype && subtype.name);
- var xrefFontStats = xref.stats.fontTypes;
- xrefFontStats[fontType] = true;
- } catch (ex) {}
- fontCapability.resolve(new TranslatedFont(font.loadedName, new _fonts.ErrorFont(reason instanceof Error ? reason.message : reason), font));
- });
- return fontCapability.promise;
- },
- buildPath: function buildPath(operatorList, fn, args) {
- var parsingText = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
- var lastIndex = operatorList.length - 1;
- if (!args) {
- args = [];
- }
- if (lastIndex < 0 || operatorList.fnArray[lastIndex] !== _util.OPS.constructPath) {
- if (parsingText) {
- (0, _util.warn)("Encountered path operator \"".concat(fn, "\" inside of a text object."));
- operatorList.addOp(_util.OPS.save, null);
- }
- operatorList.addOp(_util.OPS.constructPath, [[fn], args]);
- if (parsingText) {
- operatorList.addOp(_util.OPS.restore, null);
- }
- } else {
- var opArgs = operatorList.argsArray[lastIndex];
- opArgs[0].push(fn);
- Array.prototype.push.apply(opArgs[1], args);
- }
- },
- handleColorN: function () {
- var _handleColorN = _asyncToGenerator(
- /*#__PURE__*/
- _regenerator["default"].mark(function _callee3(operatorList, fn, args, cs, patterns, resources, task) {
- var patternName, pattern, dict, typeNum, color, shading, matrix;
- return _regenerator["default"].wrap(function _callee3$(_context3) {
- while (1) {
- switch (_context3.prev = _context3.next) {
- case 0:
- patternName = args[args.length - 1];
- if (!((0, _primitives.isName)(patternName) && (pattern = patterns.get(patternName.name)))) {
- _context3.next = 16;
- break;
- }
- dict = (0, _primitives.isStream)(pattern) ? pattern.dict : pattern;
- typeNum = dict.get('PatternType');
- if (!(typeNum === TILING_PATTERN)) {
- _context3.next = 9;
- break;
- }
- color = cs.base ? cs.base.getRgb(args, 0) : null;
- return _context3.abrupt("return", this.handleTilingType(fn, color, resources, pattern, dict, operatorList, task));
- case 9:
- if (!(typeNum === SHADING_PATTERN)) {
- _context3.next = 15;
- break;
- }
- shading = dict.get('Shading');
- matrix = dict.getArray('Matrix');
- pattern = _pattern.Pattern.parseShading(shading, matrix, this.xref, resources, this.handler, this.pdfFunctionFactory);
- operatorList.addOp(fn, pattern.getIR());
- return _context3.abrupt("return", undefined);
- case 15:
- throw new _util.FormatError("Unknown PatternType: ".concat(typeNum));
- case 16:
- throw new _util.FormatError("Unknown PatternName: ".concat(patternName));
- case 17:
- case "end":
- return _context3.stop();
- }
- }
- }, _callee3, this);
- }));
- function handleColorN(_x3, _x4, _x5, _x6, _x7, _x8, _x9) {
- return _handleColorN.apply(this, arguments);
- }
- return handleColorN;
- }(),
- getOperatorList: function getOperatorList(_ref4) {
- var _this7 = this;
- var stream = _ref4.stream,
- task = _ref4.task,
- resources = _ref4.resources,
- operatorList = _ref4.operatorList,
- _ref4$initialState = _ref4.initialState,
- initialState = _ref4$initialState === void 0 ? null : _ref4$initialState;
- resources = resources || _primitives.Dict.empty;
- initialState = initialState || new EvalState();
- if (!operatorList) {
- throw new Error('getOperatorList: missing "operatorList" parameter');
- }
- var self = this;
- var xref = this.xref;
- var parsingText = false;
- var imageCache = Object.create(null);
- var xobjs = resources.get('XObject') || _primitives.Dict.empty;
- var patterns = resources.get('Pattern') || _primitives.Dict.empty;
- var stateManager = new StateManager(initialState);
- var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
- var timeSlotManager = new TimeSlotManager();
- function closePendingRestoreOPS(argument) {
- for (var i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
- operatorList.addOp(_util.OPS.restore, []);
- }
- }
- return new Promise(function promiseBody(resolve, reject) {
- var next = function next(promise) {
- promise.then(function () {
- try {
- promiseBody(resolve, reject);
- } catch (ex) {
- reject(ex);
- }
- }, reject);
- };
- task.ensureNotTerminated();
- timeSlotManager.reset();
- var stop,
- operation = {},
- i,
- ii,
- cs;
- while (!(stop = timeSlotManager.check())) {
- operation.args = null;
- if (!preprocessor.read(operation)) {
- break;
- }
- var args = operation.args;
- var fn = operation.fn;
- switch (fn | 0) {
- case _util.OPS.paintXObject:
- var name = args[0].name;
- if (name && imageCache[name] !== undefined) {
- operatorList.addOp(imageCache[name].fn, imageCache[name].args);
- args = null;
- continue;
- }
- next(new Promise(function (resolveXObject, rejectXObject) {
- if (!name) {
- throw new _util.FormatError('XObject must be referred to by name.');
- }
- var xobj = xobjs.get(name);
- if (!xobj) {
- operatorList.addOp(fn, args);
- resolveXObject();
- return;
- }
- if (!(0, _primitives.isStream)(xobj)) {
- throw new _util.FormatError('XObject should be a stream');
- }
- var type = xobj.dict.get('Subtype');
- if (!(0, _primitives.isName)(type)) {
- throw new _util.FormatError('XObject should have a Name subtype');
- }
- if (type.name === 'Form') {
- stateManager.save();
- self.buildFormXObject(resources, xobj, null, operatorList, task, stateManager.state.clone()).then(function () {
- stateManager.restore();
- resolveXObject();
- }, rejectXObject);
- return;
- } else if (type.name === 'Image') {
- self.buildPaintImageXObject({
- resources: resources,
- image: xobj,
- operatorList: operatorList,
- cacheKey: name,
- imageCache: imageCache
- }).then(resolveXObject, rejectXObject);
- return;
- } else if (type.name === 'PS') {
- (0, _util.info)('Ignored XObject subtype PS');
- } else {
- throw new _util.FormatError("Unhandled XObject subtype ".concat(type.name));
- }
- resolveXObject();
- })["catch"](function (reason) {
- if (self.options.ignoreErrors) {
- self.handler.send('UnsupportedFeature', {
- featureId: _util.UNSUPPORTED_FEATURES.unknown
- });
- (0, _util.warn)("getOperatorList - ignoring XObject: \"".concat(reason, "\"."));
- return;
- }
- throw reason;
- }));
- return;
- case _util.OPS.setFont:
- var fontSize = args[1];
- next(self.handleSetFont(resources, args, null, operatorList, task, stateManager.state).then(function (loadedName) {
- operatorList.addDependency(loadedName);
- operatorList.addOp(_util.OPS.setFont, [loadedName, fontSize]);
- }));
- return;
- case _util.OPS.beginText:
- parsingText = true;
- break;
- case _util.OPS.endText:
- parsingText = false;
- break;
- case _util.OPS.endInlineImage:
- var cacheKey = args[0].cacheKey;
- if (cacheKey) {
- var cacheEntry = imageCache[cacheKey];
- if (cacheEntry !== undefined) {
- operatorList.addOp(cacheEntry.fn, cacheEntry.args);
- args = null;
- continue;
- }
- }
- next(self.buildPaintImageXObject({
- resources: resources,
- image: args[0],
- isInline: true,
- operatorList: operatorList,
- cacheKey: cacheKey,
- imageCache: imageCache
- }));
- return;
- case _util.OPS.showText:
- args[0] = self.handleText(args[0], stateManager.state);
- break;
- case _util.OPS.showSpacedText:
- var arr = args[0];
- var combinedGlyphs = [];
- var arrLength = arr.length;
- var state = stateManager.state;
- for (i = 0; i < arrLength; ++i) {
- var arrItem = arr[i];
- if ((0, _util.isString)(arrItem)) {
- Array.prototype.push.apply(combinedGlyphs, self.handleText(arrItem, state));
- } else if ((0, _util.isNum)(arrItem)) {
- combinedGlyphs.push(arrItem);
- }
- }
- args[0] = combinedGlyphs;
- fn = _util.OPS.showText;
- break;
- case _util.OPS.nextLineShowText:
- operatorList.addOp(_util.OPS.nextLine);
- args[0] = self.handleText(args[0], stateManager.state);
- fn = _util.OPS.showText;
- break;
- case _util.OPS.nextLineSetSpacingShowText:
- operatorList.addOp(_util.OPS.nextLine);
- operatorList.addOp(_util.OPS.setWordSpacing, [args.shift()]);
- operatorList.addOp(_util.OPS.setCharSpacing, [args.shift()]);
- args[0] = self.handleText(args[0], stateManager.state);
- fn = _util.OPS.showText;
- break;
- case _util.OPS.setTextRenderingMode:
- stateManager.state.textRenderingMode = args[0];
- break;
- case _util.OPS.setFillColorSpace:
- stateManager.state.fillColorSpace = _colorspace.ColorSpace.parse(args[0], xref, resources, self.pdfFunctionFactory);
- continue;
- case _util.OPS.setStrokeColorSpace:
- stateManager.state.strokeColorSpace = _colorspace.ColorSpace.parse(args[0], xref, resources, self.pdfFunctionFactory);
- continue;
- case _util.OPS.setFillColor:
- cs = stateManager.state.fillColorSpace;
- args = cs.getRgb(args, 0);
- fn = _util.OPS.setFillRGBColor;
- break;
- case _util.OPS.setStrokeColor:
- cs = stateManager.state.strokeColorSpace;
- args = cs.getRgb(args, 0);
- fn = _util.OPS.setStrokeRGBColor;
- break;
- case _util.OPS.setFillGray:
- stateManager.state.fillColorSpace = _colorspace.ColorSpace.singletons.gray;
- args = _colorspace.ColorSpace.singletons.gray.getRgb(args, 0);
- fn = _util.OPS.setFillRGBColor;
- break;
- case _util.OPS.setStrokeGray:
- stateManager.state.strokeColorSpace = _colorspace.ColorSpace.singletons.gray;
- args = _colorspace.ColorSpace.singletons.gray.getRgb(args, 0);
- fn = _util.OPS.setStrokeRGBColor;
- break;
- case _util.OPS.setFillCMYKColor:
- stateManager.state.fillColorSpace = _colorspace.ColorSpace.singletons.cmyk;
- args = _colorspace.ColorSpace.singletons.cmyk.getRgb(args, 0);
- fn = _util.OPS.setFillRGBColor;
- break;
- case _util.OPS.setStrokeCMYKColor:
- stateManager.state.strokeColorSpace = _colorspace.ColorSpace.singletons.cmyk;
- args = _colorspace.ColorSpace.singletons.cmyk.getRgb(args, 0);
- fn = _util.OPS.setStrokeRGBColor;
- break;
- case _util.OPS.setFillRGBColor:
- stateManager.state.fillColorSpace = _colorspace.ColorSpace.singletons.rgb;
- args = _colorspace.ColorSpace.singletons.rgb.getRgb(args, 0);
- break;
- case _util.OPS.setStrokeRGBColor:
- stateManager.state.strokeColorSpace = _colorspace.ColorSpace.singletons.rgb;
- args = _colorspace.ColorSpace.singletons.rgb.getRgb(args, 0);
- break;
- case _util.OPS.setFillColorN:
- cs = stateManager.state.fillColorSpace;
- if (cs.name === 'Pattern') {
- next(self.handleColorN(operatorList, _util.OPS.setFillColorN, args, cs, patterns, resources, task));
- return;
- }
- args = cs.getRgb(args, 0);
- fn = _util.OPS.setFillRGBColor;
- break;
- case _util.OPS.setStrokeColorN:
- cs = stateManager.state.strokeColorSpace;
- if (cs.name === 'Pattern') {
- next(self.handleColorN(operatorList, _util.OPS.setStrokeColorN, args, cs, patterns, resources, task));
- return;
- }
- args = cs.getRgb(args, 0);
- fn = _util.OPS.setStrokeRGBColor;
- break;
- case _util.OPS.shadingFill:
- var shadingRes = resources.get('Shading');
- if (!shadingRes) {
- throw new _util.FormatError('No shading resource found');
- }
- var shading = shadingRes.get(args[0].name);
- if (!shading) {
- throw new _util.FormatError('No shading object found');
- }
- var shadingFill = _pattern.Pattern.parseShading(shading, null, xref, resources, self.handler, self.pdfFunctionFactory);
- var patternIR = shadingFill.getIR();
- args = [patternIR];
- fn = _util.OPS.shadingFill;
- break;
- case _util.OPS.setGState:
- var dictName = args[0];
- var extGState = resources.get('ExtGState');
- if (!(0, _primitives.isDict)(extGState) || !extGState.has(dictName.name)) {
- break;
- }
- var gState = extGState.get(dictName.name);
- next(self.setGState(resources, gState, operatorList, task, stateManager));
- return;
- case _util.OPS.moveTo:
- case _util.OPS.lineTo:
- case _util.OPS.curveTo:
- case _util.OPS.curveTo2:
- case _util.OPS.curveTo3:
- case _util.OPS.closePath:
- case _util.OPS.rectangle:
- self.buildPath(operatorList, fn, args, parsingText);
- continue;
- case _util.OPS.markPoint:
- case _util.OPS.markPointProps:
- case _util.OPS.beginMarkedContent:
- case _util.OPS.beginMarkedContentProps:
- case _util.OPS.endMarkedContent:
- case _util.OPS.beginCompat:
- case _util.OPS.endCompat:
- continue;
- default:
- if (args !== null) {
- for (i = 0, ii = args.length; i < ii; i++) {
- if (args[i] instanceof _primitives.Dict) {
- break;
- }
- }
- if (i < ii) {
- (0, _util.warn)('getOperatorList - ignoring operator: ' + fn);
- continue;
- }
- }
- }
- operatorList.addOp(fn, args);
- }
- if (stop) {
- next(deferred);
- return;
- }
- closePendingRestoreOPS();
- resolve();
- })["catch"](function (reason) {
- if (_this7.options.ignoreErrors) {
- _this7.handler.send('UnsupportedFeature', {
- featureId: _util.UNSUPPORTED_FEATURES.unknown
- });
- (0, _util.warn)("getOperatorList - ignoring errors during \"".concat(task.name, "\" ") + "task: \"".concat(reason, "\"."));
- closePendingRestoreOPS();
- return;
- }
- throw reason;
- });
- },
- getTextContent: function getTextContent(_ref5) {
- var _this8 = this;
- var stream = _ref5.stream,
- task = _ref5.task,
- resources = _ref5.resources,
- _ref5$stateManager = _ref5.stateManager,
- stateManager = _ref5$stateManager === void 0 ? null : _ref5$stateManager,
- _ref5$normalizeWhites = _ref5.normalizeWhitespace,
- normalizeWhitespace = _ref5$normalizeWhites === void 0 ? false : _ref5$normalizeWhites,
- _ref5$combineTextItem = _ref5.combineTextItems,
- combineTextItems = _ref5$combineTextItem === void 0 ? false : _ref5$combineTextItem,
- sink = _ref5.sink,
- _ref5$seenStyles = _ref5.seenStyles,
- seenStyles = _ref5$seenStyles === void 0 ? Object.create(null) : _ref5$seenStyles;
- resources = resources || _primitives.Dict.empty;
- stateManager = stateManager || new StateManager(new TextState());
- var WhitespaceRegexp = /\s/g;
- var textContent = {
- items: [],
- styles: Object.create(null)
- };
- var textContentItem = {
- initialized: false,
- str: [],
- width: 0,
- height: 0,
- vertical: false,
- lastAdvanceWidth: 0,
- lastAdvanceHeight: 0,
- textAdvanceScale: 0,
- spaceWidth: 0,
- fakeSpaceMin: Infinity,
- fakeMultiSpaceMin: Infinity,
- fakeMultiSpaceMax: -0,
- textRunBreakAllowed: false,
- transform: null,
- fontName: null
- };
- var SPACE_FACTOR = 0.3;
- var MULTI_SPACE_FACTOR = 1.5;
- var MULTI_SPACE_FACTOR_MAX = 4;
- var self = this;
- var xref = this.xref;
- var xobjs = null;
- var skipEmptyXObjs = Object.create(null);
- var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
- var textState;
- function ensureTextContentItem() {
- if (textContentItem.initialized) {
- return textContentItem;
- }
- var font = textState.font;
- if (!(font.loadedName in seenStyles)) {
- seenStyles[font.loadedName] = true;
- textContent.styles[font.loadedName] = {
- fontFamily: font.fallbackName,
- ascent: font.ascent,
- descent: font.descent,
- vertical: !!font.vertical
- };
- }
- textContentItem.fontName = font.loadedName;
- var tsm = [textState.fontSize * textState.textHScale, 0, 0, textState.fontSize, 0, textState.textRise];
- if (font.isType3Font && textState.fontSize <= 1 && !(0, _util.isArrayEqual)(textState.fontMatrix, _util.FONT_IDENTITY_MATRIX)) {
- var glyphHeight = font.bbox[3] - font.bbox[1];
- if (glyphHeight > 0) {
- tsm[3] *= glyphHeight * textState.fontMatrix[3];
- }
- }
- var trm = _util.Util.transform(textState.ctm, _util.Util.transform(textState.textMatrix, tsm));
- textContentItem.transform = trm;
- if (!font.vertical) {
- textContentItem.width = 0;
- textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
- textContentItem.vertical = false;
- } else {
- textContentItem.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
- textContentItem.height = 0;
- textContentItem.vertical = true;
- }
- var a = textState.textLineMatrix[0];
- var b = textState.textLineMatrix[1];
- var scaleLineX = Math.sqrt(a * a + b * b);
- a = textState.ctm[0];
- b = textState.ctm[1];
- var scaleCtmX = Math.sqrt(a * a + b * b);
- textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
- textContentItem.lastAdvanceWidth = 0;
- textContentItem.lastAdvanceHeight = 0;
- var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
- if (spaceWidth) {
- textContentItem.spaceWidth = spaceWidth;
- textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
- textContentItem.fakeMultiSpaceMin = spaceWidth * MULTI_SPACE_FACTOR;
- textContentItem.fakeMultiSpaceMax = spaceWidth * MULTI_SPACE_FACTOR_MAX;
- textContentItem.textRunBreakAllowed = !font.isMonospace;
- } else {
- textContentItem.spaceWidth = 0;
- textContentItem.fakeSpaceMin = Infinity;
- textContentItem.fakeMultiSpaceMin = Infinity;
- textContentItem.fakeMultiSpaceMax = 0;
- textContentItem.textRunBreakAllowed = false;
- }
- textContentItem.initialized = true;
- return textContentItem;
- }
- function replaceWhitespace(str) {
- var i = 0,
- ii = str.length,
- code;
- while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7F) {
- i++;
- }
- return i < ii ? str.replace(WhitespaceRegexp, ' ') : str;
- }
- function runBidiTransform(textChunk) {
- var str = textChunk.str.join('');
- var bidiResult = (0, _bidi.bidi)(str, -1, textChunk.vertical);
- return {
- str: normalizeWhitespace ? replaceWhitespace(bidiResult.str) : bidiResult.str,
- dir: bidiResult.dir,
- width: textChunk.width,
- height: textChunk.height,
- transform: textChunk.transform,
- fontName: textChunk.fontName
- };
- }
- function handleSetFont(fontName, fontRef) {
- return self.loadFont(fontName, fontRef, resources).then(function (translated) {
- textState.font = translated.font;
- textState.fontMatrix = translated.font.fontMatrix || _util.FONT_IDENTITY_MATRIX;
- });
- }
- function buildTextContentItem(chars) {
- var font = textState.font;
- var textChunk = ensureTextContentItem();
- var width = 0;
- var height = 0;
- var glyphs = font.charsToGlyphs(chars);
- for (var i = 0; i < glyphs.length; i++) {
- var glyph = glyphs[i];
- var glyphWidth = null;
- if (font.vertical && glyph.vmetric) {
- glyphWidth = glyph.vmetric[0];
- } else {
- glyphWidth = glyph.width;
- }
- var glyphUnicode = glyph.unicode;
- var NormalizedUnicodes = (0, _unicode.getNormalizedUnicodes)();
- if (NormalizedUnicodes[glyphUnicode] !== undefined) {
- glyphUnicode = NormalizedUnicodes[glyphUnicode];
- }
- glyphUnicode = (0, _unicode.reverseIfRtl)(glyphUnicode);
- var charSpacing = textState.charSpacing;
- if (glyph.isSpace) {
- var wordSpacing = textState.wordSpacing;
- charSpacing += wordSpacing;
- if (wordSpacing > 0) {
- addFakeSpaces(wordSpacing, textChunk.str);
- }
- }
- var tx = 0;
- var ty = 0;
- if (!font.vertical) {
- var w0 = glyphWidth * textState.fontMatrix[0];
- tx = (w0 * textState.fontSize + charSpacing) * textState.textHScale;
- width += tx;
- } else {
- var w1 = glyphWidth * textState.fontMatrix[0];
- ty = w1 * textState.fontSize + charSpacing;
- height += ty;
- }
- textState.translateTextMatrix(tx, ty);
- textChunk.str.push(glyphUnicode);
- }
- if (!font.vertical) {
- textChunk.lastAdvanceWidth = width;
- textChunk.width += width;
- } else {
- textChunk.lastAdvanceHeight = height;
- textChunk.height += Math.abs(height);
- }
- return textChunk;
- }
- function addFakeSpaces(width, strBuf) {
- if (width < textContentItem.fakeSpaceMin) {
- return;
- }
- if (width < textContentItem.fakeMultiSpaceMin) {
- strBuf.push(' ');
- return;
- }
- var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
- while (fakeSpaces-- > 0) {
- strBuf.push(' ');
- }
- }
- function flushTextContentItem() {
- if (!textContentItem.initialized) {
- return;
- }
- if (!textContentItem.vertical) {
- textContentItem.width *= textContentItem.textAdvanceScale;
- } else {
- textContentItem.height *= textContentItem.textAdvanceScale;
- }
- textContent.items.push(runBidiTransform(textContentItem));
- textContentItem.initialized = false;
- textContentItem.str.length = 0;
- }
- function enqueueChunk() {
- var length = textContent.items.length;
- if (length > 0) {
- sink.enqueue(textContent, length);
- textContent.items = [];
- textContent.styles = Object.create(null);
- }
- }
- var timeSlotManager = new TimeSlotManager();
- return new Promise(function promiseBody(resolve, reject) {
- var next = function next(promise) {
- enqueueChunk();
- Promise.all([promise, sink.ready]).then(function () {
- try {
- promiseBody(resolve, reject);
- } catch (ex) {
- reject(ex);
- }
- }, reject);
- };
- task.ensureNotTerminated();
- timeSlotManager.reset();
- var stop,
- operation = {},
- args = [];
- while (!(stop = timeSlotManager.check())) {
- args.length = 0;
- operation.args = args;
- if (!preprocessor.read(operation)) {
- break;
- }
- textState = stateManager.state;
- var fn = operation.fn;
- args = operation.args;
- var advance, diff;
- switch (fn | 0) {
- case _util.OPS.setFont:
- var fontNameArg = args[0].name,
- fontSizeArg = args[1];
- if (textState.font && fontNameArg === textState.fontName && fontSizeArg === textState.fontSize) {
- break;
- }
- flushTextContentItem();
- textState.fontName = fontNameArg;
- textState.fontSize = fontSizeArg;
- next(handleSetFont(fontNameArg, null));
- return;
- case _util.OPS.setTextRise:
- flushTextContentItem();
- textState.textRise = args[0];
- break;
- case _util.OPS.setHScale:
- flushTextContentItem();
- textState.textHScale = args[0] / 100;
- break;
- case _util.OPS.setLeading:
- flushTextContentItem();
- textState.leading = args[0];
- break;
- case _util.OPS.moveText:
- var isSameTextLine = !textState.font ? false : (textState.font.vertical ? args[0] : args[1]) === 0;
- advance = args[0] - args[1];
- if (combineTextItems && isSameTextLine && textContentItem.initialized && advance > 0 && advance <= textContentItem.fakeMultiSpaceMax) {
- textState.translateTextLineMatrix(args[0], args[1]);
- textContentItem.width += args[0] - textContentItem.lastAdvanceWidth;
- textContentItem.height += args[1] - textContentItem.lastAdvanceHeight;
- diff = args[0] - textContentItem.lastAdvanceWidth - (args[1] - textContentItem.lastAdvanceHeight);
- addFakeSpaces(diff, textContentItem.str);
- break;
- }
- flushTextContentItem();
- textState.translateTextLineMatrix(args[0], args[1]);
- textState.textMatrix = textState.textLineMatrix.slice();
- break;
- case _util.OPS.setLeadingMoveText:
- flushTextContentItem();
- textState.leading = -args[1];
- textState.translateTextLineMatrix(args[0], args[1]);
- textState.textMatrix = textState.textLineMatrix.slice();
- break;
- case _util.OPS.nextLine:
- flushTextContentItem();
- textState.carriageReturn();
- break;
- case _util.OPS.setTextMatrix:
- advance = textState.calcTextLineMatrixAdvance(args[0], args[1], args[2], args[3], args[4], args[5]);
- if (combineTextItems && advance !== null && textContentItem.initialized && advance.value > 0 && advance.value <= textContentItem.fakeMultiSpaceMax) {
- textState.translateTextLineMatrix(advance.width, advance.height);
- textContentItem.width += advance.width - textContentItem.lastAdvanceWidth;
- textContentItem.height += advance.height - textContentItem.lastAdvanceHeight;
- diff = advance.width - textContentItem.lastAdvanceWidth - (advance.height - textContentItem.lastAdvanceHeight);
- addFakeSpaces(diff, textContentItem.str);
- break;
- }
- flushTextContentItem();
- textState.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
- textState.setTextLineMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
- break;
- case _util.OPS.setCharSpacing:
- textState.charSpacing = args[0];
- break;
- case _util.OPS.setWordSpacing:
- textState.wordSpacing = args[0];
- break;
- case _util.OPS.beginText:
- flushTextContentItem();
- textState.textMatrix = _util.IDENTITY_MATRIX.slice();
- textState.textLineMatrix = _util.IDENTITY_MATRIX.slice();
- break;
- case _util.OPS.showSpacedText:
- var items = args[0];
- var offset;
- for (var j = 0, jj = items.length; j < jj; j++) {
- if (typeof items[j] === 'string') {
- buildTextContentItem(items[j]);
- } else if ((0, _util.isNum)(items[j])) {
- ensureTextContentItem();
- advance = items[j] * textState.fontSize / 1000;
- var breakTextRun = false;
- if (textState.font.vertical) {
- offset = advance;
- textState.translateTextMatrix(0, offset);
- breakTextRun = textContentItem.textRunBreakAllowed && advance > textContentItem.fakeMultiSpaceMax;
- if (!breakTextRun) {
- textContentItem.height += offset;
- }
- } else {
- advance = -advance;
- offset = advance * textState.textHScale;
- textState.translateTextMatrix(offset, 0);
- breakTextRun = textContentItem.textRunBreakAllowed && advance > textContentItem.fakeMultiSpaceMax;
- if (!breakTextRun) {
- textContentItem.width += offset;
- }
- }
- if (breakTextRun) {
- flushTextContentItem();
- } else if (advance > 0) {
- addFakeSpaces(advance, textContentItem.str);
- }
- }
- }
- break;
- case _util.OPS.showText:
- buildTextContentItem(args[0]);
- break;
- case _util.OPS.nextLineShowText:
- flushTextContentItem();
- textState.carriageReturn();
- buildTextContentItem(args[0]);
- break;
- case _util.OPS.nextLineSetSpacingShowText:
- flushTextContentItem();
- textState.wordSpacing = args[0];
- textState.charSpacing = args[1];
- textState.carriageReturn();
- buildTextContentItem(args[2]);
- break;
- case _util.OPS.paintXObject:
- flushTextContentItem();
- if (!xobjs) {
- xobjs = resources.get('XObject') || _primitives.Dict.empty;
- }
- var name = args[0].name;
- if (name && skipEmptyXObjs[name] !== undefined) {
- break;
- }
- next(new Promise(function (resolveXObject, rejectXObject) {
- if (!name) {
- throw new _util.FormatError('XObject must be referred to by name.');
- }
- var xobj = xobjs.get(name);
- if (!xobj) {
- resolveXObject();
- return;
- }
- if (!(0, _primitives.isStream)(xobj)) {
- throw new _util.FormatError('XObject should be a stream');
- }
- var type = xobj.dict.get('Subtype');
- if (!(0, _primitives.isName)(type)) {
- throw new _util.FormatError('XObject should have a Name subtype');
- }
- if (type.name !== 'Form') {
- skipEmptyXObjs[name] = true;
- resolveXObject();
- return;
- }
- var currentState = stateManager.state.clone();
- var xObjStateManager = new StateManager(currentState);
- var matrix = xobj.dict.getArray('Matrix');
- if (Array.isArray(matrix) && matrix.length === 6) {
- xObjStateManager.transform(matrix);
- }
- enqueueChunk();
- var sinkWrapper = {
- enqueueInvoked: false,
- enqueue: function enqueue(chunk, size) {
- this.enqueueInvoked = true;
- sink.enqueue(chunk, size);
- },
- get desiredSize() {
- return sink.desiredSize;
- },
- get ready() {
- return sink.ready;
- }
- };
- self.getTextContent({
- stream: xobj,
- task: task,
- resources: xobj.dict.get('Resources') || resources,
- stateManager: xObjStateManager,
- normalizeWhitespace: normalizeWhitespace,
- combineTextItems: combineTextItems,
- sink: sinkWrapper,
- seenStyles: seenStyles
- }).then(function () {
- if (!sinkWrapper.enqueueInvoked) {
- skipEmptyXObjs[name] = true;
- }
- resolveXObject();
- }, rejectXObject);
- })["catch"](function (reason) {
- if (reason instanceof _util.AbortException) {
- return;
- }
- if (self.options.ignoreErrors) {
- (0, _util.warn)("getTextContent - ignoring XObject: \"".concat(reason, "\"."));
- return;
- }
- throw reason;
- }));
- return;
- case _util.OPS.setGState:
- flushTextContentItem();
- var dictName = args[0];
- var extGState = resources.get('ExtGState');
- if (!(0, _primitives.isDict)(extGState) || !(0, _primitives.isName)(dictName)) {
- break;
- }
- var gState = extGState.get(dictName.name);
- if (!(0, _primitives.isDict)(gState)) {
- break;
- }
- var gStateFont = gState.get('Font');
- if (gStateFont) {
- textState.fontName = null;
- textState.fontSize = gStateFont[1];
- next(handleSetFont(null, gStateFont[0]));
- return;
- }
- break;
- }
- if (textContent.items.length >= sink.desiredSize) {
- stop = true;
- break;
- }
- }
- if (stop) {
- next(deferred);
- return;
- }
- flushTextContentItem();
- enqueueChunk();
- resolve();
- })["catch"](function (reason) {
- if (reason instanceof _util.AbortException) {
- return;
- }
- if (_this8.options.ignoreErrors) {
- (0, _util.warn)("getTextContent - ignoring errors during \"".concat(task.name, "\" ") + "task: \"".concat(reason, "\"."));
- flushTextContentItem();
- enqueueChunk();
- return;
- }
- throw reason;
- });
- },
- extractDataStructures: function PartialEvaluator_extractDataStructures(dict, baseDict, properties) {
- var _this9 = this;
- var xref = this.xref,
- cidToGidBytes;
- var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
- var toUnicodePromise = toUnicode ? this.readToUnicode(toUnicode) : Promise.resolve(undefined);
- if (properties.composite) {
- var cidSystemInfo = dict.get('CIDSystemInfo');
- if ((0, _primitives.isDict)(cidSystemInfo)) {
- properties.cidSystemInfo = {
- registry: (0, _util.stringToPDFString)(cidSystemInfo.get('Registry')),
- ordering: (0, _util.stringToPDFString)(cidSystemInfo.get('Ordering')),
- supplement: cidSystemInfo.get('Supplement')
- };
- }
- var cidToGidMap = dict.get('CIDToGIDMap');
- if ((0, _primitives.isStream)(cidToGidMap)) {
- cidToGidBytes = cidToGidMap.getBytes();
- }
- }
- var differences = [];
- var baseEncodingName = null;
- var encoding;
- if (dict.has('Encoding')) {
- encoding = dict.get('Encoding');
- if ((0, _primitives.isDict)(encoding)) {
- baseEncodingName = encoding.get('BaseEncoding');
- baseEncodingName = (0, _primitives.isName)(baseEncodingName) ? baseEncodingName.name : null;
- if (encoding.has('Differences')) {
- var diffEncoding = encoding.get('Differences');
- var index = 0;
- for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
- var data = xref.fetchIfRef(diffEncoding[j]);
- if ((0, _util.isNum)(data)) {
- index = data;
- } else if ((0, _primitives.isName)(data)) {
- differences[index++] = data.name;
- } else {
- throw new _util.FormatError("Invalid entry in 'Differences' array: ".concat(data));
- }
- }
- }
- } else if ((0, _primitives.isName)(encoding)) {
- baseEncodingName = encoding.name;
- } else {
- throw new _util.FormatError('Encoding is not a Name nor a Dict');
- }
- if (baseEncodingName !== 'MacRomanEncoding' && baseEncodingName !== 'MacExpertEncoding' && baseEncodingName !== 'WinAnsiEncoding') {
- baseEncodingName = null;
- }
- }
- if (baseEncodingName) {
- properties.defaultEncoding = (0, _encodings.getEncoding)(baseEncodingName).slice();
- } else {
- var isSymbolicFont = !!(properties.flags & _fonts.FontFlags.Symbolic);
- var isNonsymbolicFont = !!(properties.flags & _fonts.FontFlags.Nonsymbolic);
- encoding = _encodings.StandardEncoding;
- if (properties.type === 'TrueType' && !isNonsymbolicFont) {
- encoding = _encodings.WinAnsiEncoding;
- }
- if (isSymbolicFont) {
- encoding = _encodings.MacRomanEncoding;
- if (!properties.file) {
- if (/Symbol/i.test(properties.name)) {
- encoding = _encodings.SymbolSetEncoding;
- } else if (/Dingbats/i.test(properties.name)) {
- encoding = _encodings.ZapfDingbatsEncoding;
- }
- }
- }
- properties.defaultEncoding = encoding;
- }
- properties.differences = differences;
- properties.baseEncodingName = baseEncodingName;
- properties.hasEncoding = !!baseEncodingName || differences.length > 0;
- properties.dict = dict;
- return toUnicodePromise.then(function (toUnicode) {
- properties.toUnicode = toUnicode;
- return _this9.buildToUnicode(properties);
- }).then(function (toUnicode) {
- properties.toUnicode = toUnicode;
- if (cidToGidBytes) {
- properties.cidToGidMap = _this9.readCidToGidMap(cidToGidBytes, toUnicode);
- }
- return properties;
- });
- },
- _buildSimpleFontToUnicode: function _buildSimpleFontToUnicode(properties) {
- (0, _util.assert)(!properties.composite, 'Must be a simple font.');
- var toUnicode = [],
- charcode,
- glyphName;
- var encoding = properties.defaultEncoding.slice();
- var baseEncodingName = properties.baseEncodingName;
- var differences = properties.differences;
- for (charcode in differences) {
- glyphName = differences[charcode];
- if (glyphName === '.notdef') {
- continue;
- }
- encoding[charcode] = glyphName;
- }
- var glyphsUnicodeMap = (0, _glyphlist.getGlyphsUnicode)();
- for (charcode in encoding) {
- glyphName = encoding[charcode];
- if (glyphName === '') {
- continue;
- } else if (glyphsUnicodeMap[glyphName] === undefined) {
- var code = 0;
- switch (glyphName[0]) {
- case 'G':
- if (glyphName.length === 3) {
- code = parseInt(glyphName.substring(1), 16);
- }
- break;
- case 'g':
- if (glyphName.length === 5) {
- code = parseInt(glyphName.substring(1), 16);
- }
- break;
- case 'C':
- case 'c':
- if (glyphName.length >= 3) {
- code = +glyphName.substring(1);
- }
- break;
- default:
- var unicode = (0, _unicode.getUnicodeForGlyph)(glyphName, glyphsUnicodeMap);
- if (unicode !== -1) {
- code = unicode;
- }
- }
- if (code) {
- if (baseEncodingName && code === +charcode) {
- var baseEncoding = (0, _encodings.getEncoding)(baseEncodingName);
- if (baseEncoding && (glyphName = baseEncoding[charcode])) {
- toUnicode[charcode] = String.fromCharCode(glyphsUnicodeMap[glyphName]);
- continue;
- }
- }
- toUnicode[charcode] = String.fromCodePoint(code);
- }
- continue;
- }
- toUnicode[charcode] = String.fromCharCode(glyphsUnicodeMap[glyphName]);
- }
- return new _fonts.ToUnicodeMap(toUnicode);
- },
- buildToUnicode: function buildToUnicode(properties) {
- properties.hasIncludedToUnicodeMap = !!properties.toUnicode && properties.toUnicode.length > 0;
- if (properties.hasIncludedToUnicodeMap) {
- if (!properties.composite && properties.hasEncoding) {
- properties.fallbackToUnicode = this._buildSimpleFontToUnicode(properties);
- }
- return Promise.resolve(properties.toUnicode);
- }
- if (!properties.composite) {
- return Promise.resolve(this._buildSimpleFontToUnicode(properties));
- }
- if (properties.composite && (properties.cMap.builtInCMap && !(properties.cMap instanceof _cmap.IdentityCMap) || properties.cidSystemInfo.registry === 'Adobe' && (properties.cidSystemInfo.ordering === 'GB1' || properties.cidSystemInfo.ordering === 'CNS1' || properties.cidSystemInfo.ordering === 'Japan1' || properties.cidSystemInfo.ordering === 'Korea1'))) {
- var registry = properties.cidSystemInfo.registry;
- var ordering = properties.cidSystemInfo.ordering;
- var ucs2CMapName = _primitives.Name.get(registry + '-' + ordering + '-UCS2');
- return _cmap.CMapFactory.create({
- encoding: ucs2CMapName,
- fetchBuiltInCMap: this.fetchBuiltInCMap,
- useCMap: null
- }).then(function (ucs2CMap) {
- var cMap = properties.cMap;
- var toUnicode = [];
- cMap.forEach(function (charcode, cid) {
- if (cid > 0xffff) {
- throw new _util.FormatError('Max size of CID is 65,535');
- }
- var ucs2 = ucs2CMap.lookup(cid);
- if (ucs2) {
- toUnicode[charcode] = String.fromCharCode((ucs2.charCodeAt(0) << 8) + ucs2.charCodeAt(1));
- }
- });
- return new _fonts.ToUnicodeMap(toUnicode);
- });
- }
- return Promise.resolve(new _fonts.IdentityToUnicodeMap(properties.firstChar, properties.lastChar));
- },
- readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
- var cmapObj = toUnicode;
- if ((0, _primitives.isName)(cmapObj)) {
- return _cmap.CMapFactory.create({
- encoding: cmapObj,
- fetchBuiltInCMap: this.fetchBuiltInCMap,
- useCMap: null
- }).then(function (cmap) {
- if (cmap instanceof _cmap.IdentityCMap) {
- return new _fonts.IdentityToUnicodeMap(0, 0xFFFF);
- }
- return new _fonts.ToUnicodeMap(cmap.getMap());
- });
- } else if ((0, _primitives.isStream)(cmapObj)) {
- return _cmap.CMapFactory.create({
- encoding: cmapObj,
- fetchBuiltInCMap: this.fetchBuiltInCMap,
- useCMap: null
- }).then(function (cmap) {
- if (cmap instanceof _cmap.IdentityCMap) {
- return new _fonts.IdentityToUnicodeMap(0, 0xFFFF);
- }
- var map = new Array(cmap.length);
- cmap.forEach(function (charCode, token) {
- var str = [];
- for (var k = 0; k < token.length; k += 2) {
- var w1 = token.charCodeAt(k) << 8 | token.charCodeAt(k + 1);
- if ((w1 & 0xF800) !== 0xD800) {
- str.push(w1);
- continue;
- }
- k += 2;
- var w2 = token.charCodeAt(k) << 8 | token.charCodeAt(k + 1);
- str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
- }
- map[charCode] = String.fromCodePoint.apply(String, str);
- });
- return new _fonts.ToUnicodeMap(map);
- });
- }
- return Promise.resolve(null);
- },
- readCidToGidMap: function readCidToGidMap(glyphsData, toUnicode) {
- var result = [];
- for (var j = 0, jj = glyphsData.length; j < jj; j++) {
- var glyphID = glyphsData[j++] << 8 | glyphsData[j];
- var code = j >> 1;
- if (glyphID === 0 && !toUnicode.has(code)) {
- continue;
- }
- result[code] = glyphID;
- }
- return result;
- },
- extractWidths: function PartialEvaluator_extractWidths(dict, descriptor, properties) {
- var xref = this.xref;
- var glyphsWidths = [];
- var defaultWidth = 0;
- var glyphsVMetrics = [];
- var defaultVMetrics;
- var i, ii, j, jj, start, code, widths;
- if (properties.composite) {
- defaultWidth = dict.has('DW') ? dict.get('DW') : 1000;
- widths = dict.get('W');
- if (widths) {
- for (i = 0, ii = widths.length; i < ii; i++) {
- start = xref.fetchIfRef(widths[i++]);
- code = xref.fetchIfRef(widths[i]);
- if (Array.isArray(code)) {
- for (j = 0, jj = code.length; j < jj; j++) {
- glyphsWidths[start++] = xref.fetchIfRef(code[j]);
- }
- } else {
- var width = xref.fetchIfRef(widths[++i]);
- for (j = start; j <= code; j++) {
- glyphsWidths[j] = width;
- }
- }
- }
- }
- if (properties.vertical) {
- var vmetrics = dict.getArray('DW2') || [880, -1000];
- defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
- vmetrics = dict.get('W2');
- if (vmetrics) {
- for (i = 0, ii = vmetrics.length; i < ii; i++) {
- start = xref.fetchIfRef(vmetrics[i++]);
- code = xref.fetchIfRef(vmetrics[i]);
- if (Array.isArray(code)) {
- for (j = 0, jj = code.length; j < jj; j++) {
- glyphsVMetrics[start++] = [xref.fetchIfRef(code[j++]), xref.fetchIfRef(code[j++]), xref.fetchIfRef(code[j])];
- }
- } else {
- var vmetric = [xref.fetchIfRef(vmetrics[++i]), xref.fetchIfRef(vmetrics[++i]), xref.fetchIfRef(vmetrics[++i])];
- for (j = start; j <= code; j++) {
- glyphsVMetrics[j] = vmetric;
- }
- }
- }
- }
- }
- } else {
- var firstChar = properties.firstChar;
- widths = dict.get('Widths');
- if (widths) {
- j = firstChar;
- for (i = 0, ii = widths.length; i < ii; i++) {
- glyphsWidths[j++] = xref.fetchIfRef(widths[i]);
- }
- defaultWidth = parseFloat(descriptor.get('MissingWidth')) || 0;
- } else {
- var baseFontName = dict.get('BaseFont');
- if ((0, _primitives.isName)(baseFontName)) {
- var metrics = this.getBaseFontMetrics(baseFontName.name);
- glyphsWidths = this.buildCharCodeToWidth(metrics.widths, properties);
- defaultWidth = metrics.defaultWidth;
- }
- }
- }
- var isMonospace = true;
- var firstWidth = defaultWidth;
- for (var glyph in glyphsWidths) {
- var glyphWidth = glyphsWidths[glyph];
- if (!glyphWidth) {
- continue;
- }
- if (!firstWidth) {
- firstWidth = glyphWidth;
- continue;
- }
- if (firstWidth !== glyphWidth) {
- isMonospace = false;
- break;
- }
- }
- if (isMonospace) {
- properties.flags |= _fonts.FontFlags.FixedPitch;
- }
- properties.defaultWidth = defaultWidth;
- properties.widths = glyphsWidths;
- properties.defaultVMetrics = defaultVMetrics;
- properties.vmetrics = glyphsVMetrics;
- },
- isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
- var fontNameWoStyle = baseFontName.split('-')[0];
- return fontNameWoStyle in (0, _standard_fonts.getSerifFonts)() || fontNameWoStyle.search(/serif/gi) !== -1;
- },
- getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
- var defaultWidth = 0;
- var widths = [];
- var monospace = false;
- var stdFontMap = (0, _standard_fonts.getStdFontMap)();
- var lookupName = stdFontMap[name] || name;
- var Metrics = (0, _metrics.getMetrics)();
- if (!(lookupName in Metrics)) {
- if (this.isSerifFont(name)) {
- lookupName = 'Times-Roman';
- } else {
- lookupName = 'Helvetica';
- }
- }
- var glyphWidths = Metrics[lookupName];
- if ((0, _util.isNum)(glyphWidths)) {
- defaultWidth = glyphWidths;
- monospace = true;
- } else {
- widths = glyphWidths();
- }
- return {
- defaultWidth: defaultWidth,
- monospace: monospace,
- widths: widths
- };
- },
- buildCharCodeToWidth: function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName, properties) {
- var widths = Object.create(null);
- var differences = properties.differences;
- var encoding = properties.defaultEncoding;
- for (var charCode = 0; charCode < 256; charCode++) {
- if (charCode in differences && widthsByGlyphName[differences[charCode]]) {
- widths[charCode] = widthsByGlyphName[differences[charCode]];
- continue;
- }
- if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
- widths[charCode] = widthsByGlyphName[encoding[charCode]];
- continue;
- }
- }
- return widths;
- },
- preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict) {
- var baseDict = dict;
- var type = dict.get('Subtype');
- if (!(0, _primitives.isName)(type)) {
- throw new _util.FormatError('invalid font Subtype');
- }
- var composite = false;
- var uint8array;
- if (type.name === 'Type0') {
- var df = dict.get('DescendantFonts');
- if (!df) {
- throw new _util.FormatError('Descendant fonts are not specified');
- }
- dict = Array.isArray(df) ? this.xref.fetchIfRef(df[0]) : df;
- type = dict.get('Subtype');
- if (!(0, _primitives.isName)(type)) {
- throw new _util.FormatError('invalid font Subtype');
- }
- composite = true;
- }
- var descriptor = dict.get('FontDescriptor');
- if (descriptor) {
- var hash = new _murmurhash.MurmurHash3_64();
- var encoding = baseDict.getRaw('Encoding');
- if ((0, _primitives.isName)(encoding)) {
- hash.update(encoding.name);
- } else if ((0, _primitives.isRef)(encoding)) {
- hash.update(encoding.toString());
- } else if ((0, _primitives.isDict)(encoding)) {
- var keys = encoding.getKeys();
- for (var i = 0, ii = keys.length; i < ii; i++) {
- var entry = encoding.getRaw(keys[i]);
- if ((0, _primitives.isName)(entry)) {
- hash.update(entry.name);
- } else if ((0, _primitives.isRef)(entry)) {
- hash.update(entry.toString());
- } else if (Array.isArray(entry)) {
- var diffLength = entry.length,
- diffBuf = new Array(diffLength);
- for (var j = 0; j < diffLength; j++) {
- var diffEntry = entry[j];
- if ((0, _primitives.isName)(diffEntry)) {
- diffBuf[j] = diffEntry.name;
- } else if ((0, _util.isNum)(diffEntry) || (0, _primitives.isRef)(diffEntry)) {
- diffBuf[j] = diffEntry.toString();
- }
- }
- hash.update(diffBuf.join());
- }
- }
- }
- var firstChar = dict.get('FirstChar') || 0;
- var lastChar = dict.get('LastChar') || (composite ? 0xFFFF : 0xFF);
- hash.update("".concat(firstChar, "-").concat(lastChar));
- var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
- if ((0, _primitives.isStream)(toUnicode)) {
- var stream = toUnicode.str || toUnicode;
- uint8array = stream.buffer ? new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) : new Uint8Array(stream.bytes.buffer, stream.start, stream.end - stream.start);
- hash.update(uint8array);
- } else if ((0, _primitives.isName)(toUnicode)) {
- hash.update(toUnicode.name);
- }
- var widths = dict.get('Widths') || baseDict.get('Widths');
- if (widths) {
- uint8array = new Uint8Array(new Uint32Array(widths).buffer);
- hash.update(uint8array);
- }
- }
- return {
- descriptor: descriptor,
- dict: dict,
- baseDict: baseDict,
- composite: composite,
- type: type.name,
- hash: hash ? hash.hexdigest() : ''
- };
- },
- translateFont: function PartialEvaluator_translateFont(preEvaluatedFont) {
- var _this10 = this;
- var baseDict = preEvaluatedFont.baseDict;
- var dict = preEvaluatedFont.dict;
- var composite = preEvaluatedFont.composite;
- var descriptor = preEvaluatedFont.descriptor;
- var type = preEvaluatedFont.type;
- var maxCharIndex = composite ? 0xFFFF : 0xFF;
- var properties;
- if (!descriptor) {
- if (type === 'Type3') {
- descriptor = new _primitives.Dict(null);
- descriptor.set('FontName', _primitives.Name.get(type));
- descriptor.set('FontBBox', dict.getArray('FontBBox'));
- } else {
- var baseFontName = dict.get('BaseFont');
- if (!(0, _primitives.isName)(baseFontName)) {
- throw new _util.FormatError('Base font is not specified');
- }
- baseFontName = baseFontName.name.replace(/[,_]/g, '-');
- var metrics = this.getBaseFontMetrics(baseFontName);
- var fontNameWoStyle = baseFontName.split('-')[0];
- var flags = (this.isSerifFont(fontNameWoStyle) ? _fonts.FontFlags.Serif : 0) | (metrics.monospace ? _fonts.FontFlags.FixedPitch : 0) | ((0, _standard_fonts.getSymbolsFonts)()[fontNameWoStyle] ? _fonts.FontFlags.Symbolic : _fonts.FontFlags.Nonsymbolic);
- properties = {
- type: type,
- name: baseFontName,
- widths: metrics.widths,
- defaultWidth: metrics.defaultWidth,
- flags: flags,
- firstChar: 0,
- lastChar: maxCharIndex
- };
- return this.extractDataStructures(dict, dict, properties).then(function (properties) {
- properties.widths = _this10.buildCharCodeToWidth(metrics.widths, properties);
- return new _fonts.Font(baseFontName, null, properties);
- });
- }
- }
- var firstChar = dict.get('FirstChar') || 0;
- var lastChar = dict.get('LastChar') || maxCharIndex;
- var fontName = descriptor.get('FontName');
- var baseFont = dict.get('BaseFont');
- if ((0, _util.isString)(fontName)) {
- fontName = _primitives.Name.get(fontName);
- }
- if ((0, _util.isString)(baseFont)) {
- baseFont = _primitives.Name.get(baseFont);
- }
- if (type !== 'Type3') {
- var fontNameStr = fontName && fontName.name;
- var baseFontStr = baseFont && baseFont.name;
- if (fontNameStr !== baseFontStr) {
- (0, _util.info)("The FontDescriptor's FontName is \"".concat(fontNameStr, "\" but ") + "should be the same as the Font's BaseFont \"".concat(baseFontStr, "\"."));
- if (fontNameStr && baseFontStr && baseFontStr.startsWith(fontNameStr)) {
- fontName = baseFont;
- }
- }
- }
- fontName = fontName || baseFont;
- if (!(0, _primitives.isName)(fontName)) {
- throw new _util.FormatError('invalid font name');
- }
- var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
- if (fontFile) {
- if (fontFile.dict) {
- var subtype = fontFile.dict.get('Subtype');
- if (subtype) {
- subtype = subtype.name;
- }
- var length1 = fontFile.dict.get('Length1');
- var length2 = fontFile.dict.get('Length2');
- var length3 = fontFile.dict.get('Length3');
- }
- }
- properties = {
- type: type,
- name: fontName.name,
- subtype: subtype,
- file: fontFile,
- length1: length1,
- length2: length2,
- length3: length3,
- loadedName: baseDict.loadedName,
- composite: composite,
- wideChars: composite,
- fixedPitch: false,
- fontMatrix: dict.getArray('FontMatrix') || _util.FONT_IDENTITY_MATRIX,
- firstChar: firstChar || 0,
- lastChar: lastChar || maxCharIndex,
- bbox: descriptor.getArray('FontBBox'),
- ascent: descriptor.get('Ascent'),
- descent: descriptor.get('Descent'),
- xHeight: descriptor.get('XHeight'),
- capHeight: descriptor.get('CapHeight'),
- flags: descriptor.get('Flags'),
- italicAngle: descriptor.get('ItalicAngle'),
- isType3Font: false
- };
- var cMapPromise;
- if (composite) {
- var cidEncoding = baseDict.get('Encoding');
- if ((0, _primitives.isName)(cidEncoding)) {
- properties.cidEncoding = cidEncoding.name;
- }
- cMapPromise = _cmap.CMapFactory.create({
- encoding: cidEncoding,
- fetchBuiltInCMap: this.fetchBuiltInCMap,
- useCMap: null
- }).then(function (cMap) {
- properties.cMap = cMap;
- properties.vertical = properties.cMap.vertical;
- });
- } else {
- cMapPromise = Promise.resolve(undefined);
- }
- return cMapPromise.then(function () {
- return _this10.extractDataStructures(dict, baseDict, properties);
- }).then(function (properties) {
- _this10.extractWidths(dict, descriptor, properties);
- if (type === 'Type3') {
- properties.isType3Font = true;
- }
- return new _fonts.Font(fontName.name, fontFile, properties);
- });
- }
- };
- PartialEvaluator.buildFontPaths = function (font, glyphs, handler) {
- function buildPath(fontChar) {
- if (font.renderer.hasBuiltPath(fontChar)) {
- return;
- }
- handler.send('commonobj', ["".concat(font.loadedName, "_path_").concat(fontChar), 'FontPath', font.renderer.getPathJs(fontChar)]);
- }
- var _iteratorNormalCompletion = true;
- var _didIteratorError = false;
- var _iteratorError = undefined;
- try {
- for (var _iterator = glyphs[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
- var glyph = _step.value;
- buildPath(glyph.fontChar);
- var accent = glyph.accent;
- if (accent && accent.fontChar) {
- buildPath(accent.fontChar);
- }
- }
- } catch (err) {
- _didIteratorError = true;
- _iteratorError = err;
- } finally {
- try {
- if (!_iteratorNormalCompletion && _iterator["return"] != null) {
- _iterator["return"]();
- }
- } finally {
- if (_didIteratorError) {
- throw _iteratorError;
- }
- }
- }
- };
- return PartialEvaluator;
- }();
- exports.PartialEvaluator = PartialEvaluator;
- var TranslatedFont = function TranslatedFontClosure() {
- function TranslatedFont(loadedName, font, dict) {
- this.loadedName = loadedName;
- this.font = font;
- this.dict = dict;
- this.type3Loaded = null;
- this.sent = false;
- }
- TranslatedFont.prototype = {
- send: function send(handler) {
- if (this.sent) {
- return;
- }
- this.sent = true;
- handler.send('commonobj', [this.loadedName, 'Font', this.font.exportData()]);
- },
- fallback: function fallback(handler) {
- if (!this.font.data) {
- return;
- }
- this.font.disableFontFace = true;
- var glyphs = this.font.glyphCacheValues;
- PartialEvaluator.buildFontPaths(this.font, glyphs, handler);
- },
- loadType3Data: function loadType3Data(evaluator, resources, parentOperatorList, task) {
- if (!this.font.isType3Font) {
- throw new Error('Must be a Type3 font.');
- }
- if (this.type3Loaded) {
- return this.type3Loaded;
- }
- var type3Options = Object.create(evaluator.options);
- type3Options.ignoreErrors = false;
- type3Options.nativeImageDecoderSupport = _util.NativeImageDecoding.NONE;
- var type3Evaluator = evaluator.clone(type3Options);
- type3Evaluator.parsingType3Font = true;
- var translatedFont = this.font;
- var loadCharProcsPromise = Promise.resolve();
- var charProcs = this.dict.get('CharProcs');
- var fontResources = this.dict.get('Resources') || resources;
- var charProcKeys = charProcs.getKeys();
- var charProcOperatorList = Object.create(null);
- var _loop2 = function _loop2() {
- var key = charProcKeys[i];
- loadCharProcsPromise = loadCharProcsPromise.then(function () {
- var glyphStream = charProcs.get(key);
- var operatorList = new _operator_list.OperatorList();
- return type3Evaluator.getOperatorList({
- stream: glyphStream,
- task: task,
- resources: fontResources,
- operatorList: operatorList
- }).then(function () {
- charProcOperatorList[key] = operatorList.getIR();
- parentOperatorList.addDependencies(operatorList.dependencies);
- })["catch"](function (reason) {
- (0, _util.warn)("Type3 font resource \"".concat(key, "\" is not available."));
- var operatorList = new _operator_list.OperatorList();
- charProcOperatorList[key] = operatorList.getIR();
- });
- });
- };
- for (var i = 0, n = charProcKeys.length; i < n; ++i) {
- _loop2();
- }
- this.type3Loaded = loadCharProcsPromise.then(function () {
- translatedFont.charProcOperatorList = charProcOperatorList;
- });
- return this.type3Loaded;
- }
- };
- return TranslatedFont;
- }();
- var StateManager = function StateManagerClosure() {
- function StateManager(initialState) {
- this.state = initialState;
- this.stateStack = [];
- }
- StateManager.prototype = {
- save: function save() {
- var old = this.state;
- this.stateStack.push(this.state);
- this.state = old.clone();
- },
- restore: function restore() {
- var prev = this.stateStack.pop();
- if (prev) {
- this.state = prev;
- }
- },
- transform: function transform(args) {
- this.state.ctm = _util.Util.transform(this.state.ctm, args);
- }
- };
- return StateManager;
- }();
- var TextState = function TextStateClosure() {
- function TextState() {
- this.ctm = new Float32Array(_util.IDENTITY_MATRIX);
- this.fontName = null;
- this.fontSize = 0;
- this.font = null;
- this.fontMatrix = _util.FONT_IDENTITY_MATRIX;
- this.textMatrix = _util.IDENTITY_MATRIX.slice();
- this.textLineMatrix = _util.IDENTITY_MATRIX.slice();
- this.charSpacing = 0;
- this.wordSpacing = 0;
- this.leading = 0;
- this.textHScale = 1;
- this.textRise = 0;
- }
- TextState.prototype = {
- setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
- var m = this.textMatrix;
- m[0] = a;
- m[1] = b;
- m[2] = c;
- m[3] = d;
- m[4] = e;
- m[5] = f;
- },
- setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
- var m = this.textLineMatrix;
- m[0] = a;
- m[1] = b;
- m[2] = c;
- m[3] = d;
- m[4] = e;
- m[5] = f;
- },
- translateTextMatrix: function TextState_translateTextMatrix(x, y) {
- var m = this.textMatrix;
- m[4] = m[0] * x + m[2] * y + m[4];
- m[5] = m[1] * x + m[3] * y + m[5];
- },
- translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
- var m = this.textLineMatrix;
- m[4] = m[0] * x + m[2] * y + m[4];
- m[5] = m[1] * x + m[3] * y + m[5];
- },
- calcTextLineMatrixAdvance: function TextState_calcTextLineMatrixAdvance(a, b, c, d, e, f) {
- var font = this.font;
- if (!font) {
- return null;
- }
- var m = this.textLineMatrix;
- if (!(a === m[0] && b === m[1] && c === m[2] && d === m[3])) {
- return null;
- }
- var txDiff = e - m[4],
- tyDiff = f - m[5];
- if (font.vertical && txDiff !== 0 || !font.vertical && tyDiff !== 0) {
- return null;
- }
- var tx,
- ty,
- denominator = a * d - b * c;
- if (font.vertical) {
- tx = -tyDiff * c / denominator;
- ty = tyDiff * a / denominator;
- } else {
- tx = txDiff * d / denominator;
- ty = -txDiff * b / denominator;
- }
- return {
- width: tx,
- height: ty,
- value: font.vertical ? ty : tx
- };
- },
- calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
- var tsm = [this.fontSize * this.textHScale, 0, 0, this.fontSize, 0, this.textRise];
- return _util.Util.transform(ctm, _util.Util.transform(this.textMatrix, tsm));
- },
- carriageReturn: function TextState_carriageReturn() {
- this.translateTextLineMatrix(0, -this.leading);
- this.textMatrix = this.textLineMatrix.slice();
- },
- clone: function TextState_clone() {
- var clone = Object.create(this);
- clone.textMatrix = this.textMatrix.slice();
- clone.textLineMatrix = this.textLineMatrix.slice();
- clone.fontMatrix = this.fontMatrix.slice();
- return clone;
- }
- };
- return TextState;
- }();
- var EvalState = function EvalStateClosure() {
- function EvalState() {
- this.ctm = new Float32Array(_util.IDENTITY_MATRIX);
- this.font = null;
- this.textRenderingMode = _util.TextRenderingMode.FILL;
- this.fillColorSpace = _colorspace.ColorSpace.singletons.gray;
- this.strokeColorSpace = _colorspace.ColorSpace.singletons.gray;
- }
- EvalState.prototype = {
- clone: function CanvasExtraState_clone() {
- return Object.create(this);
- }
- };
- return EvalState;
- }();
- var EvaluatorPreprocessor = function EvaluatorPreprocessorClosure() {
- var getOPMap = (0, _core_utils.getLookupTableFactory)(function (t) {
- t['w'] = {
- id: _util.OPS.setLineWidth,
- numArgs: 1,
- variableArgs: false
- };
- t['J'] = {
- id: _util.OPS.setLineCap,
- numArgs: 1,
- variableArgs: false
- };
- t['j'] = {
- id: _util.OPS.setLineJoin,
- numArgs: 1,
- variableArgs: false
- };
- t['M'] = {
- id: _util.OPS.setMiterLimit,
- numArgs: 1,
- variableArgs: false
- };
- t['d'] = {
- id: _util.OPS.setDash,
- numArgs: 2,
- variableArgs: false
- };
- t['ri'] = {
- id: _util.OPS.setRenderingIntent,
- numArgs: 1,
- variableArgs: false
- };
- t['i'] = {
- id: _util.OPS.setFlatness,
- numArgs: 1,
- variableArgs: false
- };
- t['gs'] = {
- id: _util.OPS.setGState,
- numArgs: 1,
- variableArgs: false
- };
- t['q'] = {
- id: _util.OPS.save,
- numArgs: 0,
- variableArgs: false
- };
- t['Q'] = {
- id: _util.OPS.restore,
- numArgs: 0,
- variableArgs: false
- };
- t['cm'] = {
- id: _util.OPS.transform,
- numArgs: 6,
- variableArgs: false
- };
- t['m'] = {
- id: _util.OPS.moveTo,
- numArgs: 2,
- variableArgs: false
- };
- t['l'] = {
- id: _util.OPS.lineTo,
- numArgs: 2,
- variableArgs: false
- };
- t['c'] = {
- id: _util.OPS.curveTo,
- numArgs: 6,
- variableArgs: false
- };
- t['v'] = {
- id: _util.OPS.curveTo2,
- numArgs: 4,
- variableArgs: false
- };
- t['y'] = {
- id: _util.OPS.curveTo3,
- numArgs: 4,
- variableArgs: false
- };
- t['h'] = {
- id: _util.OPS.closePath,
- numArgs: 0,
- variableArgs: false
- };
- t['re'] = {
- id: _util.OPS.rectangle,
- numArgs: 4,
- variableArgs: false
- };
- t['S'] = {
- id: _util.OPS.stroke,
- numArgs: 0,
- variableArgs: false
- };
- t['s'] = {
- id: _util.OPS.closeStroke,
- numArgs: 0,
- variableArgs: false
- };
- t['f'] = {
- id: _util.OPS.fill,
- numArgs: 0,
- variableArgs: false
- };
- t['F'] = {
- id: _util.OPS.fill,
- numArgs: 0,
- variableArgs: false
- };
- t['f*'] = {
- id: _util.OPS.eoFill,
- numArgs: 0,
- variableArgs: false
- };
- t['B'] = {
- id: _util.OPS.fillStroke,
- numArgs: 0,
- variableArgs: false
- };
- t['B*'] = {
- id: _util.OPS.eoFillStroke,
- numArgs: 0,
- variableArgs: false
- };
- t['b'] = {
- id: _util.OPS.closeFillStroke,
- numArgs: 0,
- variableArgs: false
- };
- t['b*'] = {
- id: _util.OPS.closeEOFillStroke,
- numArgs: 0,
- variableArgs: false
- };
- t['n'] = {
- id: _util.OPS.endPath,
- numArgs: 0,
- variableArgs: false
- };
- t['W'] = {
- id: _util.OPS.clip,
- numArgs: 0,
- variableArgs: false
- };
- t['W*'] = {
- id: _util.OPS.eoClip,
- numArgs: 0,
- variableArgs: false
- };
- t['BT'] = {
- id: _util.OPS.beginText,
- numArgs: 0,
- variableArgs: false
- };
- t['ET'] = {
- id: _util.OPS.endText,
- numArgs: 0,
- variableArgs: false
- };
- t['Tc'] = {
- id: _util.OPS.setCharSpacing,
- numArgs: 1,
- variableArgs: false
- };
- t['Tw'] = {
- id: _util.OPS.setWordSpacing,
- numArgs: 1,
- variableArgs: false
- };
- t['Tz'] = {
- id: _util.OPS.setHScale,
- numArgs: 1,
- variableArgs: false
- };
- t['TL'] = {
- id: _util.OPS.setLeading,
- numArgs: 1,
- variableArgs: false
- };
- t['Tf'] = {
- id: _util.OPS.setFont,
- numArgs: 2,
- variableArgs: false
- };
- t['Tr'] = {
- id: _util.OPS.setTextRenderingMode,
- numArgs: 1,
- variableArgs: false
- };
- t['Ts'] = {
- id: _util.OPS.setTextRise,
- numArgs: 1,
- variableArgs: false
- };
- t['Td'] = {
- id: _util.OPS.moveText,
- numArgs: 2,
- variableArgs: false
- };
- t['TD'] = {
- id: _util.OPS.setLeadingMoveText,
- numArgs: 2,
- variableArgs: false
- };
- t['Tm'] = {
- id: _util.OPS.setTextMatrix,
- numArgs: 6,
- variableArgs: false
- };
- t['T*'] = {
- id: _util.OPS.nextLine,
- numArgs: 0,
- variableArgs: false
- };
- t['Tj'] = {
- id: _util.OPS.showText,
- numArgs: 1,
- variableArgs: false
- };
- t['TJ'] = {
- id: _util.OPS.showSpacedText,
- numArgs: 1,
- variableArgs: false
- };
- t['\''] = {
- id: _util.OPS.nextLineShowText,
- numArgs: 1,
- variableArgs: false
- };
- t['"'] = {
- id: _util.OPS.nextLineSetSpacingShowText,
- numArgs: 3,
- variableArgs: false
- };
- t['d0'] = {
- id: _util.OPS.setCharWidth,
- numArgs: 2,
- variableArgs: false
- };
- t['d1'] = {
- id: _util.OPS.setCharWidthAndBounds,
- numArgs: 6,
- variableArgs: false
- };
- t['CS'] = {
- id: _util.OPS.setStrokeColorSpace,
- numArgs: 1,
- variableArgs: false
- };
- t['cs'] = {
- id: _util.OPS.setFillColorSpace,
- numArgs: 1,
- variableArgs: false
- };
- t['SC'] = {
- id: _util.OPS.setStrokeColor,
- numArgs: 4,
- variableArgs: true
- };
- t['SCN'] = {
- id: _util.OPS.setStrokeColorN,
- numArgs: 33,
- variableArgs: true
- };
- t['sc'] = {
- id: _util.OPS.setFillColor,
- numArgs: 4,
- variableArgs: true
- };
- t['scn'] = {
- id: _util.OPS.setFillColorN,
- numArgs: 33,
- variableArgs: true
- };
- t['G'] = {
- id: _util.OPS.setStrokeGray,
- numArgs: 1,
- variableArgs: false
- };
- t['g'] = {
- id: _util.OPS.setFillGray,
- numArgs: 1,
- variableArgs: false
- };
- t['RG'] = {
- id: _util.OPS.setStrokeRGBColor,
- numArgs: 3,
- variableArgs: false
- };
- t['rg'] = {
- id: _util.OPS.setFillRGBColor,
- numArgs: 3,
- variableArgs: false
- };
- t['K'] = {
- id: _util.OPS.setStrokeCMYKColor,
- numArgs: 4,
- variableArgs: false
- };
- t['k'] = {
- id: _util.OPS.setFillCMYKColor,
- numArgs: 4,
- variableArgs: false
- };
- t['sh'] = {
- id: _util.OPS.shadingFill,
- numArgs: 1,
- variableArgs: false
- };
- t['BI'] = {
- id: _util.OPS.beginInlineImage,
- numArgs: 0,
- variableArgs: false
- };
- t['ID'] = {
- id: _util.OPS.beginImageData,
- numArgs: 0,
- variableArgs: false
- };
- t['EI'] = {
- id: _util.OPS.endInlineImage,
- numArgs: 1,
- variableArgs: false
- };
- t['Do'] = {
- id: _util.OPS.paintXObject,
- numArgs: 1,
- variableArgs: false
- };
- t['MP'] = {
- id: _util.OPS.markPoint,
- numArgs: 1,
- variableArgs: false
- };
- t['DP'] = {
- id: _util.OPS.markPointProps,
- numArgs: 2,
- variableArgs: false
- };
- t['BMC'] = {
- id: _util.OPS.beginMarkedContent,
- numArgs: 1,
- variableArgs: false
- };
- t['BDC'] = {
- id: _util.OPS.beginMarkedContentProps,
- numArgs: 2,
- variableArgs: false
- };
- t['EMC'] = {
- id: _util.OPS.endMarkedContent,
- numArgs: 0,
- variableArgs: false
- };
- t['BX'] = {
- id: _util.OPS.beginCompat,
- numArgs: 0,
- variableArgs: false
- };
- t['EX'] = {
- id: _util.OPS.endCompat,
- numArgs: 0,
- variableArgs: false
- };
- t['BM'] = null;
- t['BD'] = null;
- t['true'] = null;
- t['fa'] = null;
- t['fal'] = null;
- t['fals'] = null;
- t['false'] = null;
- t['nu'] = null;
- t['nul'] = null;
- t['null'] = null;
- });
- var MAX_INVALID_PATH_OPS = 20;
- function EvaluatorPreprocessor(stream, xref, stateManager) {
- this.opMap = getOPMap();
- this.parser = new _parser.Parser({
- lexer: new _parser.Lexer(stream, this.opMap),
- xref: xref
- });
- this.stateManager = stateManager;
- this.nonProcessedArgs = [];
- this._numInvalidPathOPS = 0;
- }
- EvaluatorPreprocessor.prototype = {
- get savedStatesDepth() {
- return this.stateManager.stateStack.length;
- },
- read: function EvaluatorPreprocessor_read(operation) {
- var args = operation.args;
- while (true) {
- var obj = this.parser.getObj();
- if ((0, _primitives.isCmd)(obj)) {
- var cmd = obj.cmd;
- var opSpec = this.opMap[cmd];
- if (!opSpec) {
- (0, _util.warn)("Unknown command \"".concat(cmd, "\"."));
- continue;
- }
- var fn = opSpec.id;
- var numArgs = opSpec.numArgs;
- var argsLength = args !== null ? args.length : 0;
- if (!opSpec.variableArgs) {
- if (argsLength !== numArgs) {
- var nonProcessedArgs = this.nonProcessedArgs;
- while (argsLength > numArgs) {
- nonProcessedArgs.push(args.shift());
- argsLength--;
- }
- while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
- if (args === null) {
- args = [];
- }
- args.unshift(nonProcessedArgs.pop());
- argsLength++;
- }
- }
- if (argsLength < numArgs) {
- var partialMsg = "command ".concat(cmd, ": expected ").concat(numArgs, " args, ") + "but received ".concat(argsLength, " args.");
- if (fn >= _util.OPS.moveTo && fn <= _util.OPS.endPath && ++this._numInvalidPathOPS > MAX_INVALID_PATH_OPS) {
- throw new _util.FormatError("Invalid ".concat(partialMsg));
- }
- (0, _util.warn)("Skipping ".concat(partialMsg));
- if (args !== null) {
- args.length = 0;
- }
- continue;
- }
- } else if (argsLength > numArgs) {
- (0, _util.info)("Command ".concat(cmd, ": expected [0, ").concat(numArgs, "] args, ") + "but received ".concat(argsLength, " args."));
- }
- this.preprocessCommand(fn, args);
- operation.fn = fn;
- operation.args = args;
- return true;
- }
- if ((0, _primitives.isEOF)(obj)) {
- return false;
- }
- if (obj !== null) {
- if (args === null) {
- args = [];
- }
- args.push(obj);
- if (args.length > 33) {
- throw new _util.FormatError('Too many arguments');
- }
- }
- }
- },
- preprocessCommand: function EvaluatorPreprocessor_preprocessCommand(fn, args) {
- switch (fn | 0) {
- case _util.OPS.save:
- this.stateManager.save();
- break;
- case _util.OPS.restore:
- this.stateManager.restore();
- break;
- case _util.OPS.transform:
- this.stateManager.transform(args);
- break;
- }
- }
- };
- return EvaluatorPreprocessor;
- }();
|