pdf.js 360 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2020 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * Javascript code in this page
  21. */
  22. (function webpackUniversalModuleDefinition(root, factory) {
  23. if(typeof exports === 'object' && typeof module === 'object')
  24. module.exports = factory();
  25. else if(typeof define === 'function' && define.amd)
  26. define("pdfjs-dist/build/pdf", [], factory);
  27. else if(typeof exports === 'object')
  28. exports["pdfjs-dist/build/pdf"] = factory();
  29. else
  30. root["pdfjs-dist/build/pdf"] = root.pdfjsLib = factory();
  31. })(this, function() {
  32. return /******/ (function(modules) { // webpackBootstrap
  33. /******/ // The module cache
  34. /******/ var installedModules = {};
  35. /******/
  36. /******/ // The require function
  37. /******/ function __w_pdfjs_require__(moduleId) {
  38. /******/
  39. /******/ // Check if module is in cache
  40. /******/ if(installedModules[moduleId]) {
  41. /******/ return installedModules[moduleId].exports;
  42. /******/ }
  43. /******/ // Create a new module (and put it into the cache)
  44. /******/ var module = installedModules[moduleId] = {
  45. /******/ i: moduleId,
  46. /******/ l: false,
  47. /******/ exports: {}
  48. /******/ };
  49. /******/
  50. /******/ // Execute the module function
  51. /******/ modules[moduleId].call(module.exports, module, module.exports, __w_pdfjs_require__);
  52. /******/
  53. /******/ // Flag the module as loaded
  54. /******/ module.l = true;
  55. /******/
  56. /******/ // Return the exports of the module
  57. /******/ return module.exports;
  58. /******/ }
  59. /******/
  60. /******/
  61. /******/ // expose the modules object (__webpack_modules__)
  62. /******/ __w_pdfjs_require__.m = modules;
  63. /******/
  64. /******/ // expose the module cache
  65. /******/ __w_pdfjs_require__.c = installedModules;
  66. /******/
  67. /******/ // define getter function for harmony exports
  68. /******/ __w_pdfjs_require__.d = function(exports, name, getter) {
  69. /******/ if(!__w_pdfjs_require__.o(exports, name)) {
  70. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  71. /******/ }
  72. /******/ };
  73. /******/
  74. /******/ // define __esModule on exports
  75. /******/ __w_pdfjs_require__.r = function(exports) {
  76. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  77. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  78. /******/ }
  79. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  80. /******/ };
  81. /******/
  82. /******/ // create a fake namespace object
  83. /******/ // mode & 1: value is a module id, require it
  84. /******/ // mode & 2: merge all properties of value into the ns
  85. /******/ // mode & 4: return value when already ns object
  86. /******/ // mode & 8|1: behave like require
  87. /******/ __w_pdfjs_require__.t = function(value, mode) {
  88. /******/ if(mode & 1) value = __w_pdfjs_require__(value);
  89. /******/ if(mode & 8) return value;
  90. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  91. /******/ var ns = Object.create(null);
  92. /******/ __w_pdfjs_require__.r(ns);
  93. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  94. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __w_pdfjs_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  95. /******/ return ns;
  96. /******/ };
  97. /******/
  98. /******/ // getDefaultExport function for compatibility with non-harmony modules
  99. /******/ __w_pdfjs_require__.n = function(module) {
  100. /******/ var getter = module && module.__esModule ?
  101. /******/ function getDefault() { return module['default']; } :
  102. /******/ function getModuleExports() { return module; };
  103. /******/ __w_pdfjs_require__.d(getter, 'a', getter);
  104. /******/ return getter;
  105. /******/ };
  106. /******/
  107. /******/ // Object.prototype.hasOwnProperty.call
  108. /******/ __w_pdfjs_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  109. /******/
  110. /******/ // __webpack_public_path__
  111. /******/ __w_pdfjs_require__.p = "";
  112. /******/
  113. /******/
  114. /******/ // Load entry module and return exports
  115. /******/ return __w_pdfjs_require__(__w_pdfjs_require__.s = 0);
  116. /******/ })
  117. /************************************************************************/
  118. /******/ ([
  119. /* 0 */
  120. /***/ (function(module, exports, __w_pdfjs_require__) {
  121. "use strict";
  122. var pdfjsVersion = '2.4.456';
  123. var pdfjsBuild = '228a591c';
  124. var pdfjsSharedUtil = __w_pdfjs_require__(1);
  125. var pdfjsDisplayAPI = __w_pdfjs_require__(3);
  126. var pdfjsDisplayTextLayer = __w_pdfjs_require__(16);
  127. var pdfjsDisplayAnnotationLayer = __w_pdfjs_require__(17);
  128. var pdfjsDisplayDisplayUtils = __w_pdfjs_require__(4);
  129. var pdfjsDisplaySVG = __w_pdfjs_require__(18);
  130. const pdfjsDisplayWorkerOptions = __w_pdfjs_require__(10);
  131. const pdfjsDisplayAPICompatibility = __w_pdfjs_require__(6);
  132. {
  133. const {
  134. isNodeJS
  135. } = __w_pdfjs_require__(7);
  136. if (isNodeJS) {
  137. const PDFNodeStream = __w_pdfjs_require__(19).PDFNodeStream;
  138. pdfjsDisplayAPI.setPDFNetworkStreamFactory(params => {
  139. return new PDFNodeStream(params);
  140. });
  141. } else {
  142. const PDFNetworkStream = __w_pdfjs_require__(22).PDFNetworkStream;
  143. let PDFFetchStream;
  144. if (pdfjsDisplayDisplayUtils.isFetchSupported()) {
  145. PDFFetchStream = __w_pdfjs_require__(23).PDFFetchStream;
  146. }
  147. pdfjsDisplayAPI.setPDFNetworkStreamFactory(params => {
  148. if (PDFFetchStream && pdfjsDisplayDisplayUtils.isValidFetchUrl(params.url)) {
  149. return new PDFFetchStream(params);
  150. }
  151. return new PDFNetworkStream(params);
  152. });
  153. }
  154. }
  155. exports.build = pdfjsDisplayAPI.build;
  156. exports.version = pdfjsDisplayAPI.version;
  157. exports.getDocument = pdfjsDisplayAPI.getDocument;
  158. exports.LoopbackPort = pdfjsDisplayAPI.LoopbackPort;
  159. exports.PDFDataRangeTransport = pdfjsDisplayAPI.PDFDataRangeTransport;
  160. exports.PDFWorker = pdfjsDisplayAPI.PDFWorker;
  161. exports.renderTextLayer = pdfjsDisplayTextLayer.renderTextLayer;
  162. exports.AnnotationLayer = pdfjsDisplayAnnotationLayer.AnnotationLayer;
  163. exports.createPromiseCapability = pdfjsSharedUtil.createPromiseCapability;
  164. exports.PasswordResponses = pdfjsSharedUtil.PasswordResponses;
  165. exports.InvalidPDFException = pdfjsSharedUtil.InvalidPDFException;
  166. exports.MissingPDFException = pdfjsSharedUtil.MissingPDFException;
  167. exports.SVGGraphics = pdfjsDisplaySVG.SVGGraphics;
  168. exports.NativeImageDecoding = pdfjsSharedUtil.NativeImageDecoding;
  169. exports.CMapCompressionType = pdfjsSharedUtil.CMapCompressionType;
  170. exports.PermissionFlag = pdfjsSharedUtil.PermissionFlag;
  171. exports.UnexpectedResponseException = pdfjsSharedUtil.UnexpectedResponseException;
  172. exports.OPS = pdfjsSharedUtil.OPS;
  173. exports.VerbosityLevel = pdfjsSharedUtil.VerbosityLevel;
  174. exports.UNSUPPORTED_FEATURES = pdfjsSharedUtil.UNSUPPORTED_FEATURES;
  175. exports.createValidAbsoluteUrl = pdfjsSharedUtil.createValidAbsoluteUrl;
  176. exports.createObjectURL = pdfjsSharedUtil.createObjectURL;
  177. exports.removeNullCharacters = pdfjsSharedUtil.removeNullCharacters;
  178. exports.shadow = pdfjsSharedUtil.shadow;
  179. exports.Util = pdfjsSharedUtil.Util;
  180. exports.RenderingCancelledException = pdfjsDisplayDisplayUtils.RenderingCancelledException;
  181. exports.getFilenameFromUrl = pdfjsDisplayDisplayUtils.getFilenameFromUrl;
  182. exports.LinkTarget = pdfjsDisplayDisplayUtils.LinkTarget;
  183. exports.addLinkAttributes = pdfjsDisplayDisplayUtils.addLinkAttributes;
  184. exports.loadScript = pdfjsDisplayDisplayUtils.loadScript;
  185. exports.PDFDateString = pdfjsDisplayDisplayUtils.PDFDateString;
  186. exports.GlobalWorkerOptions = pdfjsDisplayWorkerOptions.GlobalWorkerOptions;
  187. exports.apiCompatibilityParams = pdfjsDisplayAPICompatibility.apiCompatibilityParams;
  188. /***/ }),
  189. /* 1 */
  190. /***/ (function(module, exports, __w_pdfjs_require__) {
  191. "use strict";
  192. Object.defineProperty(exports, "__esModule", {
  193. value: true
  194. });
  195. exports.arrayByteLength = arrayByteLength;
  196. exports.arraysToBytes = arraysToBytes;
  197. exports.assert = assert;
  198. exports.bytesToString = bytesToString;
  199. exports.createPromiseCapability = createPromiseCapability;
  200. exports.getVerbosityLevel = getVerbosityLevel;
  201. exports.info = info;
  202. exports.isArrayBuffer = isArrayBuffer;
  203. exports.isArrayEqual = isArrayEqual;
  204. exports.isBool = isBool;
  205. exports.isEmptyObj = isEmptyObj;
  206. exports.isNum = isNum;
  207. exports.isString = isString;
  208. exports.isSameOrigin = isSameOrigin;
  209. exports.createValidAbsoluteUrl = createValidAbsoluteUrl;
  210. exports.removeNullCharacters = removeNullCharacters;
  211. exports.setVerbosityLevel = setVerbosityLevel;
  212. exports.shadow = shadow;
  213. exports.string32 = string32;
  214. exports.stringToBytes = stringToBytes;
  215. exports.stringToPDFString = stringToPDFString;
  216. exports.stringToUTF8String = stringToUTF8String;
  217. exports.utf8StringToString = utf8StringToString;
  218. exports.warn = warn;
  219. exports.unreachable = unreachable;
  220. exports.IsEvalSupportedCached = exports.IsLittleEndianCached = exports.createObjectURL = exports.FormatError = exports.Util = exports.UnknownErrorException = exports.UnexpectedResponseException = exports.TextRenderingMode = exports.StreamType = exports.PermissionFlag = exports.PasswordResponses = exports.PasswordException = exports.NativeImageDecoding = exports.MissingPDFException = exports.InvalidPDFException = exports.AbortException = exports.CMapCompressionType = exports.ImageKind = exports.FontType = exports.AnnotationType = exports.AnnotationStateModelType = exports.AnnotationReviewState = exports.AnnotationReplyType = exports.AnnotationMarkedState = exports.AnnotationFlag = exports.AnnotationFieldFlag = exports.AnnotationBorderStyleType = exports.UNSUPPORTED_FEATURES = exports.VerbosityLevel = exports.OPS = exports.IDENTITY_MATRIX = exports.FONT_IDENTITY_MATRIX = exports.BaseException = void 0;
  221. __w_pdfjs_require__(2);
  222. const IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  223. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  224. const FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  225. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  226. const NativeImageDecoding = {
  227. NONE: "none",
  228. DECODE: "decode",
  229. DISPLAY: "display"
  230. };
  231. exports.NativeImageDecoding = NativeImageDecoding;
  232. const PermissionFlag = {
  233. PRINT: 0x04,
  234. MODIFY_CONTENTS: 0x08,
  235. COPY: 0x10,
  236. MODIFY_ANNOTATIONS: 0x20,
  237. FILL_INTERACTIVE_FORMS: 0x100,
  238. COPY_FOR_ACCESSIBILITY: 0x200,
  239. ASSEMBLE: 0x400,
  240. PRINT_HIGH_QUALITY: 0x800
  241. };
  242. exports.PermissionFlag = PermissionFlag;
  243. const TextRenderingMode = {
  244. FILL: 0,
  245. STROKE: 1,
  246. FILL_STROKE: 2,
  247. INVISIBLE: 3,
  248. FILL_ADD_TO_PATH: 4,
  249. STROKE_ADD_TO_PATH: 5,
  250. FILL_STROKE_ADD_TO_PATH: 6,
  251. ADD_TO_PATH: 7,
  252. FILL_STROKE_MASK: 3,
  253. ADD_TO_PATH_FLAG: 4
  254. };
  255. exports.TextRenderingMode = TextRenderingMode;
  256. const ImageKind = {
  257. GRAYSCALE_1BPP: 1,
  258. RGB_24BPP: 2,
  259. RGBA_32BPP: 3
  260. };
  261. exports.ImageKind = ImageKind;
  262. const AnnotationType = {
  263. TEXT: 1,
  264. LINK: 2,
  265. FREETEXT: 3,
  266. LINE: 4,
  267. SQUARE: 5,
  268. CIRCLE: 6,
  269. POLYGON: 7,
  270. POLYLINE: 8,
  271. HIGHLIGHT: 9,
  272. UNDERLINE: 10,
  273. SQUIGGLY: 11,
  274. STRIKEOUT: 12,
  275. STAMP: 13,
  276. CARET: 14,
  277. INK: 15,
  278. POPUP: 16,
  279. FILEATTACHMENT: 17,
  280. SOUND: 18,
  281. MOVIE: 19,
  282. WIDGET: 20,
  283. SCREEN: 21,
  284. PRINTERMARK: 22,
  285. TRAPNET: 23,
  286. WATERMARK: 24,
  287. THREED: 25,
  288. REDACT: 26
  289. };
  290. exports.AnnotationType = AnnotationType;
  291. const AnnotationStateModelType = {
  292. MARKED: "Marked",
  293. REVIEW: "Review"
  294. };
  295. exports.AnnotationStateModelType = AnnotationStateModelType;
  296. const AnnotationMarkedState = {
  297. MARKED: "Marked",
  298. UNMARKED: "Unmarked"
  299. };
  300. exports.AnnotationMarkedState = AnnotationMarkedState;
  301. const AnnotationReviewState = {
  302. ACCEPTED: "Accepted",
  303. REJECTED: "Rejected",
  304. CANCELLED: "Cancelled",
  305. COMPLETED: "Completed",
  306. NONE: "None"
  307. };
  308. exports.AnnotationReviewState = AnnotationReviewState;
  309. const AnnotationReplyType = {
  310. GROUP: "Group",
  311. REPLY: "R"
  312. };
  313. exports.AnnotationReplyType = AnnotationReplyType;
  314. const AnnotationFlag = {
  315. INVISIBLE: 0x01,
  316. HIDDEN: 0x02,
  317. PRINT: 0x04,
  318. NOZOOM: 0x08,
  319. NOROTATE: 0x10,
  320. NOVIEW: 0x20,
  321. READONLY: 0x40,
  322. LOCKED: 0x80,
  323. TOGGLENOVIEW: 0x100,
  324. LOCKEDCONTENTS: 0x200
  325. };
  326. exports.AnnotationFlag = AnnotationFlag;
  327. const AnnotationFieldFlag = {
  328. READONLY: 0x0000001,
  329. REQUIRED: 0x0000002,
  330. NOEXPORT: 0x0000004,
  331. MULTILINE: 0x0001000,
  332. PASSWORD: 0x0002000,
  333. NOTOGGLETOOFF: 0x0004000,
  334. RADIO: 0x0008000,
  335. PUSHBUTTON: 0x0010000,
  336. COMBO: 0x0020000,
  337. EDIT: 0x0040000,
  338. SORT: 0x0080000,
  339. FILESELECT: 0x0100000,
  340. MULTISELECT: 0x0200000,
  341. DONOTSPELLCHECK: 0x0400000,
  342. DONOTSCROLL: 0x0800000,
  343. COMB: 0x1000000,
  344. RICHTEXT: 0x2000000,
  345. RADIOSINUNISON: 0x2000000,
  346. COMMITONSELCHANGE: 0x4000000
  347. };
  348. exports.AnnotationFieldFlag = AnnotationFieldFlag;
  349. const AnnotationBorderStyleType = {
  350. SOLID: 1,
  351. DASHED: 2,
  352. BEVELED: 3,
  353. INSET: 4,
  354. UNDERLINE: 5
  355. };
  356. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  357. const StreamType = {
  358. UNKNOWN: "UNKNOWN",
  359. FLATE: "FLATE",
  360. LZW: "LZW",
  361. DCT: "DCT",
  362. JPX: "JPX",
  363. JBIG: "JBIG",
  364. A85: "A85",
  365. AHX: "AHX",
  366. CCF: "CCF",
  367. RLX: "RLX"
  368. };
  369. exports.StreamType = StreamType;
  370. const FontType = {
  371. UNKNOWN: "UNKNOWN",
  372. TYPE1: "TYPE1",
  373. TYPE1C: "TYPE1C",
  374. CIDFONTTYPE0: "CIDFONTTYPE0",
  375. CIDFONTTYPE0C: "CIDFONTTYPE0C",
  376. TRUETYPE: "TRUETYPE",
  377. CIDFONTTYPE2: "CIDFONTTYPE2",
  378. TYPE3: "TYPE3",
  379. OPENTYPE: "OPENTYPE",
  380. TYPE0: "TYPE0",
  381. MMTYPE1: "MMTYPE1"
  382. };
  383. exports.FontType = FontType;
  384. const VerbosityLevel = {
  385. ERRORS: 0,
  386. WARNINGS: 1,
  387. INFOS: 5
  388. };
  389. exports.VerbosityLevel = VerbosityLevel;
  390. const CMapCompressionType = {
  391. NONE: 0,
  392. BINARY: 1,
  393. STREAM: 2
  394. };
  395. exports.CMapCompressionType = CMapCompressionType;
  396. const OPS = {
  397. dependency: 1,
  398. setLineWidth: 2,
  399. setLineCap: 3,
  400. setLineJoin: 4,
  401. setMiterLimit: 5,
  402. setDash: 6,
  403. setRenderingIntent: 7,
  404. setFlatness: 8,
  405. setGState: 9,
  406. save: 10,
  407. restore: 11,
  408. transform: 12,
  409. moveTo: 13,
  410. lineTo: 14,
  411. curveTo: 15,
  412. curveTo2: 16,
  413. curveTo3: 17,
  414. closePath: 18,
  415. rectangle: 19,
  416. stroke: 20,
  417. closeStroke: 21,
  418. fill: 22,
  419. eoFill: 23,
  420. fillStroke: 24,
  421. eoFillStroke: 25,
  422. closeFillStroke: 26,
  423. closeEOFillStroke: 27,
  424. endPath: 28,
  425. clip: 29,
  426. eoClip: 30,
  427. beginText: 31,
  428. endText: 32,
  429. setCharSpacing: 33,
  430. setWordSpacing: 34,
  431. setHScale: 35,
  432. setLeading: 36,
  433. setFont: 37,
  434. setTextRenderingMode: 38,
  435. setTextRise: 39,
  436. moveText: 40,
  437. setLeadingMoveText: 41,
  438. setTextMatrix: 42,
  439. nextLine: 43,
  440. showText: 44,
  441. showSpacedText: 45,
  442. nextLineShowText: 46,
  443. nextLineSetSpacingShowText: 47,
  444. setCharWidth: 48,
  445. setCharWidthAndBounds: 49,
  446. setStrokeColorSpace: 50,
  447. setFillColorSpace: 51,
  448. setStrokeColor: 52,
  449. setStrokeColorN: 53,
  450. setFillColor: 54,
  451. setFillColorN: 55,
  452. setStrokeGray: 56,
  453. setFillGray: 57,
  454. setStrokeRGBColor: 58,
  455. setFillRGBColor: 59,
  456. setStrokeCMYKColor: 60,
  457. setFillCMYKColor: 61,
  458. shadingFill: 62,
  459. beginInlineImage: 63,
  460. beginImageData: 64,
  461. endInlineImage: 65,
  462. paintXObject: 66,
  463. markPoint: 67,
  464. markPointProps: 68,
  465. beginMarkedContent: 69,
  466. beginMarkedContentProps: 70,
  467. endMarkedContent: 71,
  468. beginCompat: 72,
  469. endCompat: 73,
  470. paintFormXObjectBegin: 74,
  471. paintFormXObjectEnd: 75,
  472. beginGroup: 76,
  473. endGroup: 77,
  474. beginAnnotations: 78,
  475. endAnnotations: 79,
  476. beginAnnotation: 80,
  477. endAnnotation: 81,
  478. paintJpegXObject: 82,
  479. paintImageMaskXObject: 83,
  480. paintImageMaskXObjectGroup: 84,
  481. paintImageXObject: 85,
  482. paintInlineImageXObject: 86,
  483. paintInlineImageXObjectGroup: 87,
  484. paintImageXObjectRepeat: 88,
  485. paintImageMaskXObjectRepeat: 89,
  486. paintSolidColorImageMask: 90,
  487. constructPath: 91
  488. };
  489. exports.OPS = OPS;
  490. const UNSUPPORTED_FEATURES = {
  491. unknown: "unknown",
  492. forms: "forms",
  493. javaScript: "javaScript",
  494. smask: "smask",
  495. shadingPattern: "shadingPattern",
  496. font: "font"
  497. };
  498. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  499. const PasswordResponses = {
  500. NEED_PASSWORD: 1,
  501. INCORRECT_PASSWORD: 2
  502. };
  503. exports.PasswordResponses = PasswordResponses;
  504. let verbosity = VerbosityLevel.WARNINGS;
  505. function setVerbosityLevel(level) {
  506. if (Number.isInteger(level)) {
  507. verbosity = level;
  508. }
  509. }
  510. function getVerbosityLevel() {
  511. return verbosity;
  512. }
  513. function info(msg) {
  514. if (verbosity >= VerbosityLevel.INFOS) {
  515. console.log(`Info: ${msg}`);
  516. }
  517. }
  518. function warn(msg) {
  519. if (verbosity >= VerbosityLevel.WARNINGS) {
  520. console.log(`Warning: ${msg}`);
  521. }
  522. }
  523. function unreachable(msg) {
  524. throw new Error(msg);
  525. }
  526. function assert(cond, msg) {
  527. if (!cond) {
  528. unreachable(msg);
  529. }
  530. }
  531. function isSameOrigin(baseUrl, otherUrl) {
  532. let base;
  533. try {
  534. base = new URL(baseUrl);
  535. if (!base.origin || base.origin === "null") {
  536. return false;
  537. }
  538. } catch (e) {
  539. return false;
  540. }
  541. const other = new URL(otherUrl, base);
  542. return base.origin === other.origin;
  543. }
  544. function _isValidProtocol(url) {
  545. if (!url) {
  546. return false;
  547. }
  548. switch (url.protocol) {
  549. case "http:":
  550. case "https:":
  551. case "ftp:":
  552. case "mailto:":
  553. case "tel:":
  554. return true;
  555. default:
  556. return false;
  557. }
  558. }
  559. function createValidAbsoluteUrl(url, baseUrl) {
  560. if (!url) {
  561. return null;
  562. }
  563. try {
  564. const absoluteUrl = baseUrl ? new URL(url, baseUrl) : new URL(url);
  565. if (_isValidProtocol(absoluteUrl)) {
  566. return absoluteUrl;
  567. }
  568. } catch (ex) {}
  569. return null;
  570. }
  571. function shadow(obj, prop, value) {
  572. Object.defineProperty(obj, prop, {
  573. value,
  574. enumerable: true,
  575. configurable: true,
  576. writable: false
  577. });
  578. return value;
  579. }
  580. const BaseException = function BaseExceptionClosure() {
  581. function BaseException(message) {
  582. if (this.constructor === BaseException) {
  583. unreachable("Cannot initialize BaseException.");
  584. }
  585. this.message = message;
  586. this.name = this.constructor.name;
  587. }
  588. BaseException.prototype = new Error();
  589. BaseException.constructor = BaseException;
  590. return BaseException;
  591. }();
  592. exports.BaseException = BaseException;
  593. class PasswordException extends BaseException {
  594. constructor(msg, code) {
  595. super(msg);
  596. this.code = code;
  597. }
  598. }
  599. exports.PasswordException = PasswordException;
  600. class UnknownErrorException extends BaseException {
  601. constructor(msg, details) {
  602. super(msg);
  603. this.details = details;
  604. }
  605. }
  606. exports.UnknownErrorException = UnknownErrorException;
  607. class InvalidPDFException extends BaseException {}
  608. exports.InvalidPDFException = InvalidPDFException;
  609. class MissingPDFException extends BaseException {}
  610. exports.MissingPDFException = MissingPDFException;
  611. class UnexpectedResponseException extends BaseException {
  612. constructor(msg, status) {
  613. super(msg);
  614. this.status = status;
  615. }
  616. }
  617. exports.UnexpectedResponseException = UnexpectedResponseException;
  618. class FormatError extends BaseException {}
  619. exports.FormatError = FormatError;
  620. class AbortException extends BaseException {}
  621. exports.AbortException = AbortException;
  622. const NullCharactersRegExp = /\x00/g;
  623. function removeNullCharacters(str) {
  624. if (typeof str !== "string") {
  625. warn("The argument for removeNullCharacters must be a string.");
  626. return str;
  627. }
  628. return str.replace(NullCharactersRegExp, "");
  629. }
  630. function bytesToString(bytes) {
  631. assert(bytes !== null && typeof bytes === "object" && bytes.length !== undefined, "Invalid argument for bytesToString");
  632. const length = bytes.length;
  633. const MAX_ARGUMENT_COUNT = 8192;
  634. if (length < MAX_ARGUMENT_COUNT) {
  635. return String.fromCharCode.apply(null, bytes);
  636. }
  637. const strBuf = [];
  638. for (let i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  639. const chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  640. const chunk = bytes.subarray(i, chunkEnd);
  641. strBuf.push(String.fromCharCode.apply(null, chunk));
  642. }
  643. return strBuf.join("");
  644. }
  645. function stringToBytes(str) {
  646. assert(typeof str === "string", "Invalid argument for stringToBytes");
  647. const length = str.length;
  648. const bytes = new Uint8Array(length);
  649. for (let i = 0; i < length; ++i) {
  650. bytes[i] = str.charCodeAt(i) & 0xff;
  651. }
  652. return bytes;
  653. }
  654. function arrayByteLength(arr) {
  655. if (arr.length !== undefined) {
  656. return arr.length;
  657. }
  658. assert(arr.byteLength !== undefined);
  659. return arr.byteLength;
  660. }
  661. function arraysToBytes(arr) {
  662. const length = arr.length;
  663. if (length === 1 && arr[0] instanceof Uint8Array) {
  664. return arr[0];
  665. }
  666. let resultLength = 0;
  667. for (let i = 0; i < length; i++) {
  668. resultLength += arrayByteLength(arr[i]);
  669. }
  670. let pos = 0;
  671. const data = new Uint8Array(resultLength);
  672. for (let i = 0; i < length; i++) {
  673. let item = arr[i];
  674. if (!(item instanceof Uint8Array)) {
  675. if (typeof item === "string") {
  676. item = stringToBytes(item);
  677. } else {
  678. item = new Uint8Array(item);
  679. }
  680. }
  681. const itemLength = item.byteLength;
  682. data.set(item, pos);
  683. pos += itemLength;
  684. }
  685. return data;
  686. }
  687. function string32(value) {
  688. return String.fromCharCode(value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff);
  689. }
  690. function isLittleEndian() {
  691. const buffer8 = new Uint8Array(4);
  692. buffer8[0] = 1;
  693. const view32 = new Uint32Array(buffer8.buffer, 0, 1);
  694. return view32[0] === 1;
  695. }
  696. const IsLittleEndianCached = {
  697. get value() {
  698. return shadow(this, "value", isLittleEndian());
  699. }
  700. };
  701. exports.IsLittleEndianCached = IsLittleEndianCached;
  702. function isEvalSupported() {
  703. try {
  704. new Function("");
  705. return true;
  706. } catch (e) {
  707. return false;
  708. }
  709. }
  710. const IsEvalSupportedCached = {
  711. get value() {
  712. return shadow(this, "value", isEvalSupported());
  713. }
  714. };
  715. exports.IsEvalSupportedCached = IsEvalSupportedCached;
  716. const rgbBuf = ["rgb(", 0, ",", 0, ",", 0, ")"];
  717. class Util {
  718. static makeCssRgb(r, g, b) {
  719. rgbBuf[1] = r;
  720. rgbBuf[3] = g;
  721. rgbBuf[5] = b;
  722. return rgbBuf.join("");
  723. }
  724. static transform(m1, m2) {
  725. return [m1[0] * m2[0] + m1[2] * m2[1], m1[1] * m2[0] + m1[3] * m2[1], m1[0] * m2[2] + m1[2] * m2[3], m1[1] * m2[2] + m1[3] * m2[3], m1[0] * m2[4] + m1[2] * m2[5] + m1[4], m1[1] * m2[4] + m1[3] * m2[5] + m1[5]];
  726. }
  727. static applyTransform(p, m) {
  728. const xt = p[0] * m[0] + p[1] * m[2] + m[4];
  729. const yt = p[0] * m[1] + p[1] * m[3] + m[5];
  730. return [xt, yt];
  731. }
  732. static applyInverseTransform(p, m) {
  733. const d = m[0] * m[3] - m[1] * m[2];
  734. const xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  735. const yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  736. return [xt, yt];
  737. }
  738. static getAxialAlignedBoundingBox(r, m) {
  739. const p1 = Util.applyTransform(r, m);
  740. const p2 = Util.applyTransform(r.slice(2, 4), m);
  741. const p3 = Util.applyTransform([r[0], r[3]], m);
  742. const p4 = Util.applyTransform([r[2], r[1]], m);
  743. return [Math.min(p1[0], p2[0], p3[0], p4[0]), Math.min(p1[1], p2[1], p3[1], p4[1]), Math.max(p1[0], p2[0], p3[0], p4[0]), Math.max(p1[1], p2[1], p3[1], p4[1])];
  744. }
  745. static inverseTransform(m) {
  746. const d = m[0] * m[3] - m[1] * m[2];
  747. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d, (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  748. }
  749. static apply3dTransform(m, v) {
  750. return [m[0] * v[0] + m[1] * v[1] + m[2] * v[2], m[3] * v[0] + m[4] * v[1] + m[5] * v[2], m[6] * v[0] + m[7] * v[1] + m[8] * v[2]];
  751. }
  752. static singularValueDecompose2dScale(m) {
  753. const transpose = [m[0], m[2], m[1], m[3]];
  754. const a = m[0] * transpose[0] + m[1] * transpose[2];
  755. const b = m[0] * transpose[1] + m[1] * transpose[3];
  756. const c = m[2] * transpose[0] + m[3] * transpose[2];
  757. const d = m[2] * transpose[1] + m[3] * transpose[3];
  758. const first = (a + d) / 2;
  759. const second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  760. const sx = first + second || 1;
  761. const sy = first - second || 1;
  762. return [Math.sqrt(sx), Math.sqrt(sy)];
  763. }
  764. static normalizeRect(rect) {
  765. const r = rect.slice(0);
  766. if (rect[0] > rect[2]) {
  767. r[0] = rect[2];
  768. r[2] = rect[0];
  769. }
  770. if (rect[1] > rect[3]) {
  771. r[1] = rect[3];
  772. r[3] = rect[1];
  773. }
  774. return r;
  775. }
  776. static intersect(rect1, rect2) {
  777. function compare(a, b) {
  778. return a - b;
  779. }
  780. const orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare);
  781. const orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare);
  782. const result = [];
  783. rect1 = Util.normalizeRect(rect1);
  784. rect2 = Util.normalizeRect(rect2);
  785. if (orderedX[0] === rect1[0] && orderedX[1] === rect2[0] || orderedX[0] === rect2[0] && orderedX[1] === rect1[0]) {
  786. result[0] = orderedX[1];
  787. result[2] = orderedX[2];
  788. } else {
  789. return null;
  790. }
  791. if (orderedY[0] === rect1[1] && orderedY[1] === rect2[1] || orderedY[0] === rect2[1] && orderedY[1] === rect1[1]) {
  792. result[1] = orderedY[1];
  793. result[3] = orderedY[2];
  794. } else {
  795. return null;
  796. }
  797. return result;
  798. }
  799. }
  800. exports.Util = Util;
  801. const PDFStringTranslateTable = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014, 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C, 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160, 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC];
  802. function stringToPDFString(str) {
  803. const length = str.length,
  804. strBuf = [];
  805. if (str[0] === "\xFE" && str[1] === "\xFF") {
  806. for (let i = 2; i < length; i += 2) {
  807. strBuf.push(String.fromCharCode(str.charCodeAt(i) << 8 | str.charCodeAt(i + 1)));
  808. }
  809. } else if (str[0] === "\xFF" && str[1] === "\xFE") {
  810. for (let i = 2; i < length; i += 2) {
  811. strBuf.push(String.fromCharCode(str.charCodeAt(i + 1) << 8 | str.charCodeAt(i)));
  812. }
  813. } else {
  814. for (let i = 0; i < length; ++i) {
  815. const code = PDFStringTranslateTable[str.charCodeAt(i)];
  816. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  817. }
  818. }
  819. return strBuf.join("");
  820. }
  821. function stringToUTF8String(str) {
  822. return decodeURIComponent(escape(str));
  823. }
  824. function utf8StringToString(str) {
  825. return unescape(encodeURIComponent(str));
  826. }
  827. function isEmptyObj(obj) {
  828. for (const key in obj) {
  829. return false;
  830. }
  831. return true;
  832. }
  833. function isBool(v) {
  834. return typeof v === "boolean";
  835. }
  836. function isNum(v) {
  837. return typeof v === "number";
  838. }
  839. function isString(v) {
  840. return typeof v === "string";
  841. }
  842. function isArrayBuffer(v) {
  843. return typeof v === "object" && v !== null && v.byteLength !== undefined;
  844. }
  845. function isArrayEqual(arr1, arr2) {
  846. if (arr1.length !== arr2.length) {
  847. return false;
  848. }
  849. return arr1.every(function (element, index) {
  850. return element === arr2[index];
  851. });
  852. }
  853. function createPromiseCapability() {
  854. const capability = Object.create(null);
  855. let isSettled = false;
  856. Object.defineProperty(capability, "settled", {
  857. get() {
  858. return isSettled;
  859. }
  860. });
  861. capability.promise = new Promise(function (resolve, reject) {
  862. capability.resolve = function (data) {
  863. isSettled = true;
  864. resolve(data);
  865. };
  866. capability.reject = function (reason) {
  867. isSettled = true;
  868. reject(reason);
  869. };
  870. });
  871. return capability;
  872. }
  873. const createObjectURL = function createObjectURLClosure() {
  874. const digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  875. return function createObjectURL(data, contentType, forceDataSchema = false) {
  876. if (!forceDataSchema && URL.createObjectURL) {
  877. const blob = new Blob([data], {
  878. type: contentType
  879. });
  880. return URL.createObjectURL(blob);
  881. }
  882. let buffer = `data:${contentType};base64,`;
  883. for (let i = 0, ii = data.length; i < ii; i += 3) {
  884. const b1 = data[i] & 0xff;
  885. const b2 = data[i + 1] & 0xff;
  886. const b3 = data[i + 2] & 0xff;
  887. const d1 = b1 >> 2,
  888. d2 = (b1 & 3) << 4 | b2 >> 4;
  889. const d3 = i + 1 < ii ? (b2 & 0xf) << 2 | b3 >> 6 : 64;
  890. const d4 = i + 2 < ii ? b3 & 0x3f : 64;
  891. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  892. }
  893. return buffer;
  894. };
  895. }();
  896. exports.createObjectURL = createObjectURL;
  897. /***/ }),
  898. /* 2 */
  899. /***/ (function(module, exports, __w_pdfjs_require__) {
  900. "use strict";
  901. ;
  902. /***/ }),
  903. /* 3 */
  904. /***/ (function(module, exports, __w_pdfjs_require__) {
  905. "use strict";
  906. Object.defineProperty(exports, "__esModule", {
  907. value: true
  908. });
  909. exports.getDocument = getDocument;
  910. exports.setPDFNetworkStreamFactory = setPDFNetworkStreamFactory;
  911. exports.build = exports.version = exports.PDFPageProxy = exports.PDFDocumentProxy = exports.PDFWorker = exports.PDFDataRangeTransport = exports.LoopbackPort = void 0;
  912. var _util = __w_pdfjs_require__(1);
  913. var _display_utils = __w_pdfjs_require__(4);
  914. var _font_loader = __w_pdfjs_require__(5);
  915. var _api_compatibility = __w_pdfjs_require__(6);
  916. var _canvas = __w_pdfjs_require__(8);
  917. var _worker_options = __w_pdfjs_require__(10);
  918. var _is_node = __w_pdfjs_require__(7);
  919. var _message_handler = __w_pdfjs_require__(11);
  920. var _metadata = __w_pdfjs_require__(12);
  921. var _transport_stream = __w_pdfjs_require__(14);
  922. var _webgl = __w_pdfjs_require__(15);
  923. const DEFAULT_RANGE_CHUNK_SIZE = 65536;
  924. const RENDERING_CANCELLED_TIMEOUT = 100;
  925. let createPDFNetworkStream;
  926. function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) {
  927. createPDFNetworkStream = pdfNetworkStreamFactory;
  928. }
  929. function getDocument(src) {
  930. const task = new PDFDocumentLoadingTask();
  931. let source;
  932. if (typeof src === "string") {
  933. source = {
  934. url: src
  935. };
  936. } else if ((0, _util.isArrayBuffer)(src)) {
  937. source = {
  938. data: src
  939. };
  940. } else if (src instanceof PDFDataRangeTransport) {
  941. source = {
  942. range: src
  943. };
  944. } else {
  945. if (typeof src !== "object") {
  946. throw new Error("Invalid parameter in getDocument, " + "need either Uint8Array, string or a parameter object");
  947. }
  948. if (!src.url && !src.data && !src.range) {
  949. throw new Error("Invalid parameter object: need either .data, .range or .url");
  950. }
  951. source = src;
  952. }
  953. const params = Object.create(null);
  954. let rangeTransport = null,
  955. worker = null;
  956. for (const key in source) {
  957. if (key === "url" && typeof window !== "undefined") {
  958. params[key] = new URL(source[key], window.location).href;
  959. continue;
  960. } else if (key === "range") {
  961. rangeTransport = source[key];
  962. continue;
  963. } else if (key === "worker") {
  964. worker = source[key];
  965. continue;
  966. } else if (key === "data" && !(source[key] instanceof Uint8Array)) {
  967. const pdfBytes = source[key];
  968. if (typeof pdfBytes === "string") {
  969. params[key] = (0, _util.stringToBytes)(pdfBytes);
  970. } else if (typeof pdfBytes === "object" && pdfBytes !== null && !isNaN(pdfBytes.length)) {
  971. params[key] = new Uint8Array(pdfBytes);
  972. } else if ((0, _util.isArrayBuffer)(pdfBytes)) {
  973. params[key] = new Uint8Array(pdfBytes);
  974. } else {
  975. throw new Error("Invalid PDF binary data: either typed array, " + "string or array-like object is expected in the " + "data property.");
  976. }
  977. continue;
  978. }
  979. params[key] = source[key];
  980. }
  981. params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE;
  982. params.CMapReaderFactory = params.CMapReaderFactory || _display_utils.DOMCMapReaderFactory;
  983. params.ignoreErrors = params.stopAtErrors !== true;
  984. params.pdfBug = params.pdfBug === true;
  985. const NativeImageDecoderValues = Object.values(_util.NativeImageDecoding);
  986. if (params.nativeImageDecoderSupport === undefined || !NativeImageDecoderValues.includes(params.nativeImageDecoderSupport)) {
  987. params.nativeImageDecoderSupport = _api_compatibility.apiCompatibilityParams.nativeImageDecoderSupport || _util.NativeImageDecoding.DECODE;
  988. }
  989. if (!Number.isInteger(params.maxImageSize)) {
  990. params.maxImageSize = -1;
  991. }
  992. if (typeof params.isEvalSupported !== "boolean") {
  993. params.isEvalSupported = true;
  994. }
  995. if (typeof params.disableFontFace !== "boolean") {
  996. params.disableFontFace = _api_compatibility.apiCompatibilityParams.disableFontFace || false;
  997. }
  998. if (typeof params.disableRange !== "boolean") {
  999. params.disableRange = false;
  1000. }
  1001. if (typeof params.disableStream !== "boolean") {
  1002. params.disableStream = false;
  1003. }
  1004. if (typeof params.disableAutoFetch !== "boolean") {
  1005. params.disableAutoFetch = false;
  1006. }
  1007. if (typeof params.disableCreateObjectURL !== "boolean") {
  1008. params.disableCreateObjectURL = _api_compatibility.apiCompatibilityParams.disableCreateObjectURL || false;
  1009. }
  1010. (0, _util.setVerbosityLevel)(params.verbosity);
  1011. if (!worker) {
  1012. const workerParams = {
  1013. verbosity: params.verbosity,
  1014. port: _worker_options.GlobalWorkerOptions.workerPort
  1015. };
  1016. worker = workerParams.port ? PDFWorker.fromPort(workerParams) : new PDFWorker(workerParams);
  1017. task._worker = worker;
  1018. }
  1019. const docId = task.docId;
  1020. worker.promise.then(function () {
  1021. if (task.destroyed) {
  1022. throw new Error("Loading aborted");
  1023. }
  1024. return _fetchDocument(worker, params, rangeTransport, docId).then(function (workerId) {
  1025. if (task.destroyed) {
  1026. throw new Error("Loading aborted");
  1027. }
  1028. let networkStream;
  1029. if (rangeTransport) {
  1030. networkStream = new _transport_stream.PDFDataTransportStream({
  1031. length: params.length,
  1032. initialData: params.initialData,
  1033. progressiveDone: params.progressiveDone,
  1034. disableRange: params.disableRange,
  1035. disableStream: params.disableStream
  1036. }, rangeTransport);
  1037. } else if (!params.data) {
  1038. networkStream = createPDFNetworkStream({
  1039. url: params.url,
  1040. length: params.length,
  1041. httpHeaders: params.httpHeaders,
  1042. withCredentials: params.withCredentials,
  1043. rangeChunkSize: params.rangeChunkSize,
  1044. disableRange: params.disableRange,
  1045. disableStream: params.disableStream
  1046. });
  1047. }
  1048. const messageHandler = new _message_handler.MessageHandler(docId, workerId, worker.port);
  1049. messageHandler.postMessageTransfers = worker.postMessageTransfers;
  1050. const transport = new WorkerTransport(messageHandler, task, networkStream, params);
  1051. task._transport = transport;
  1052. messageHandler.send("Ready", null);
  1053. });
  1054. }).catch(task._capability.reject);
  1055. return task;
  1056. }
  1057. function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
  1058. if (worker.destroyed) {
  1059. return Promise.reject(new Error("Worker was destroyed"));
  1060. }
  1061. if (pdfDataRangeTransport) {
  1062. source.length = pdfDataRangeTransport.length;
  1063. source.initialData = pdfDataRangeTransport.initialData;
  1064. source.progressiveDone = pdfDataRangeTransport.progressiveDone;
  1065. }
  1066. return worker.messageHandler.sendWithPromise("GetDocRequest", {
  1067. docId,
  1068. apiVersion: '2.4.456',
  1069. source: {
  1070. data: source.data,
  1071. url: source.url,
  1072. password: source.password,
  1073. disableAutoFetch: source.disableAutoFetch,
  1074. rangeChunkSize: source.rangeChunkSize,
  1075. length: source.length
  1076. },
  1077. maxImageSize: source.maxImageSize,
  1078. disableFontFace: source.disableFontFace,
  1079. disableCreateObjectURL: source.disableCreateObjectURL,
  1080. postMessageTransfers: worker.postMessageTransfers,
  1081. docBaseUrl: source.docBaseUrl,
  1082. nativeImageDecoderSupport: source.nativeImageDecoderSupport,
  1083. ignoreErrors: source.ignoreErrors,
  1084. isEvalSupported: source.isEvalSupported
  1085. }).then(function (workerId) {
  1086. if (worker.destroyed) {
  1087. throw new Error("Worker was destroyed");
  1088. }
  1089. return workerId;
  1090. });
  1091. }
  1092. const PDFDocumentLoadingTask = function PDFDocumentLoadingTaskClosure() {
  1093. let nextDocumentId = 0;
  1094. class PDFDocumentLoadingTask {
  1095. constructor() {
  1096. this._capability = (0, _util.createPromiseCapability)();
  1097. this._transport = null;
  1098. this._worker = null;
  1099. this.docId = "d" + nextDocumentId++;
  1100. this.destroyed = false;
  1101. this.onPassword = null;
  1102. this.onProgress = null;
  1103. this.onUnsupportedFeature = null;
  1104. }
  1105. get promise() {
  1106. return this._capability.promise;
  1107. }
  1108. destroy() {
  1109. this.destroyed = true;
  1110. const transportDestroyed = !this._transport ? Promise.resolve() : this._transport.destroy();
  1111. return transportDestroyed.then(() => {
  1112. this._transport = null;
  1113. if (this._worker) {
  1114. this._worker.destroy();
  1115. this._worker = null;
  1116. }
  1117. });
  1118. }
  1119. then(onFulfilled, onRejected) {
  1120. throw new Error("Removed API method: " + "PDFDocumentLoadingTask.then, use the `promise` getter instead.");
  1121. }
  1122. }
  1123. return PDFDocumentLoadingTask;
  1124. }();
  1125. class PDFDataRangeTransport {
  1126. constructor(length, initialData, progressiveDone = false) {
  1127. this.length = length;
  1128. this.initialData = initialData;
  1129. this.progressiveDone = progressiveDone;
  1130. this._rangeListeners = [];
  1131. this._progressListeners = [];
  1132. this._progressiveReadListeners = [];
  1133. this._progressiveDoneListeners = [];
  1134. this._readyCapability = (0, _util.createPromiseCapability)();
  1135. }
  1136. addRangeListener(listener) {
  1137. this._rangeListeners.push(listener);
  1138. }
  1139. addProgressListener(listener) {
  1140. this._progressListeners.push(listener);
  1141. }
  1142. addProgressiveReadListener(listener) {
  1143. this._progressiveReadListeners.push(listener);
  1144. }
  1145. addProgressiveDoneListener(listener) {
  1146. this._progressiveDoneListeners.push(listener);
  1147. }
  1148. onDataRange(begin, chunk) {
  1149. for (const listener of this._rangeListeners) {
  1150. listener(begin, chunk);
  1151. }
  1152. }
  1153. onDataProgress(loaded, total) {
  1154. this._readyCapability.promise.then(() => {
  1155. for (const listener of this._progressListeners) {
  1156. listener(loaded, total);
  1157. }
  1158. });
  1159. }
  1160. onDataProgressiveRead(chunk) {
  1161. this._readyCapability.promise.then(() => {
  1162. for (const listener of this._progressiveReadListeners) {
  1163. listener(chunk);
  1164. }
  1165. });
  1166. }
  1167. onDataProgressiveDone() {
  1168. this._readyCapability.promise.then(() => {
  1169. for (const listener of this._progressiveDoneListeners) {
  1170. listener();
  1171. }
  1172. });
  1173. }
  1174. transportReady() {
  1175. this._readyCapability.resolve();
  1176. }
  1177. requestDataRange(begin, end) {
  1178. (0, _util.unreachable)("Abstract method PDFDataRangeTransport.requestDataRange");
  1179. }
  1180. abort() {}
  1181. }
  1182. exports.PDFDataRangeTransport = PDFDataRangeTransport;
  1183. class PDFDocumentProxy {
  1184. constructor(pdfInfo, transport) {
  1185. this._pdfInfo = pdfInfo;
  1186. this._transport = transport;
  1187. }
  1188. get numPages() {
  1189. return this._pdfInfo.numPages;
  1190. }
  1191. get fingerprint() {
  1192. return this._pdfInfo.fingerprint;
  1193. }
  1194. getPage(pageNumber) {
  1195. return this._transport.getPage(pageNumber);
  1196. }
  1197. getPageIndex(ref) {
  1198. return this._transport.getPageIndex(ref);
  1199. }
  1200. getDestinations() {
  1201. return this._transport.getDestinations();
  1202. }
  1203. getDestination(id) {
  1204. return this._transport.getDestination(id);
  1205. }
  1206. getPageLabels() {
  1207. return this._transport.getPageLabels();
  1208. }
  1209. getPageLayout() {
  1210. return this._transport.getPageLayout();
  1211. }
  1212. getPageMode() {
  1213. return this._transport.getPageMode();
  1214. }
  1215. getViewerPreferences() {
  1216. return this._transport.getViewerPreferences();
  1217. }
  1218. getOpenAction() {
  1219. return this._transport.getOpenAction();
  1220. }
  1221. getOpenActionDestination() {
  1222. (0, _display_utils.deprecated)("getOpenActionDestination, use getOpenAction instead.");
  1223. return this.getOpenAction().then(function (openAction) {
  1224. return openAction && openAction.dest ? openAction.dest : null;
  1225. });
  1226. }
  1227. getAttachments() {
  1228. return this._transport.getAttachments();
  1229. }
  1230. getJavaScript() {
  1231. return this._transport.getJavaScript();
  1232. }
  1233. getOutline() {
  1234. return this._transport.getOutline();
  1235. }
  1236. getPermissions() {
  1237. return this._transport.getPermissions();
  1238. }
  1239. getMetadata() {
  1240. return this._transport.getMetadata();
  1241. }
  1242. getData() {
  1243. return this._transport.getData();
  1244. }
  1245. getDownloadInfo() {
  1246. return this._transport.downloadInfoCapability.promise;
  1247. }
  1248. getStats() {
  1249. return this._transport.getStats();
  1250. }
  1251. cleanup() {
  1252. return this._transport.startCleanup();
  1253. }
  1254. destroy() {
  1255. return this.loadingTask.destroy();
  1256. }
  1257. get loadingParams() {
  1258. return this._transport.loadingParams;
  1259. }
  1260. get loadingTask() {
  1261. return this._transport.loadingTask;
  1262. }
  1263. }
  1264. exports.PDFDocumentProxy = PDFDocumentProxy;
  1265. class PDFPageProxy {
  1266. constructor(pageIndex, pageInfo, transport, pdfBug = false) {
  1267. this._pageIndex = pageIndex;
  1268. this._pageInfo = pageInfo;
  1269. this._transport = transport;
  1270. this._stats = pdfBug ? new _display_utils.StatTimer() : null;
  1271. this._pdfBug = pdfBug;
  1272. this.commonObjs = transport.commonObjs;
  1273. this.objs = new PDFObjects();
  1274. this.cleanupAfterRender = false;
  1275. this.pendingCleanup = false;
  1276. this.intentStates = Object.create(null);
  1277. this.destroyed = false;
  1278. }
  1279. get pageNumber() {
  1280. return this._pageIndex + 1;
  1281. }
  1282. get rotate() {
  1283. return this._pageInfo.rotate;
  1284. }
  1285. get ref() {
  1286. return this._pageInfo.ref;
  1287. }
  1288. get userUnit() {
  1289. return this._pageInfo.userUnit;
  1290. }
  1291. get view() {
  1292. return this._pageInfo.view;
  1293. }
  1294. getViewport({
  1295. scale,
  1296. rotation = this.rotate,
  1297. offsetX = 0,
  1298. offsetY = 0,
  1299. dontFlip = false
  1300. } = {}) {
  1301. if (arguments.length > 1 || typeof arguments[0] === "number") {
  1302. throw new Error("PDFPageProxy.getViewport is called with obsolete arguments.");
  1303. }
  1304. return new _display_utils.PageViewport({
  1305. viewBox: this.view,
  1306. scale,
  1307. rotation,
  1308. offsetX,
  1309. offsetY,
  1310. dontFlip
  1311. });
  1312. }
  1313. getAnnotations({
  1314. intent = null
  1315. } = {}) {
  1316. if (!this.annotationsPromise || this.annotationsIntent !== intent) {
  1317. this.annotationsPromise = this._transport.getAnnotations(this._pageIndex, intent);
  1318. this.annotationsIntent = intent;
  1319. }
  1320. return this.annotationsPromise;
  1321. }
  1322. render({
  1323. canvasContext,
  1324. viewport,
  1325. intent = "display",
  1326. enableWebGL = false,
  1327. renderInteractiveForms = false,
  1328. transform = null,
  1329. imageLayer = null,
  1330. canvasFactory = null,
  1331. background = null
  1332. }) {
  1333. if (this._stats) {
  1334. this._stats.time("Overall");
  1335. }
  1336. const renderingIntent = intent === "print" ? "print" : "display";
  1337. this.pendingCleanup = false;
  1338. if (!this.intentStates[renderingIntent]) {
  1339. this.intentStates[renderingIntent] = Object.create(null);
  1340. }
  1341. const intentState = this.intentStates[renderingIntent];
  1342. if (intentState.streamReaderCancelTimeout) {
  1343. clearTimeout(intentState.streamReaderCancelTimeout);
  1344. intentState.streamReaderCancelTimeout = null;
  1345. }
  1346. const canvasFactoryInstance = canvasFactory || new _display_utils.DOMCanvasFactory();
  1347. const webGLContext = new _webgl.WebGLContext({
  1348. enable: enableWebGL
  1349. });
  1350. if (!intentState.displayReadyCapability) {
  1351. intentState.displayReadyCapability = (0, _util.createPromiseCapability)();
  1352. intentState.operatorList = {
  1353. fnArray: [],
  1354. argsArray: [],
  1355. lastChunk: false
  1356. };
  1357. if (this._stats) {
  1358. this._stats.time("Page Request");
  1359. }
  1360. this._pumpOperatorList({
  1361. pageIndex: this._pageIndex,
  1362. intent: renderingIntent,
  1363. renderInteractiveForms: renderInteractiveForms === true
  1364. });
  1365. }
  1366. const complete = error => {
  1367. const i = intentState.renderTasks.indexOf(internalRenderTask);
  1368. if (i >= 0) {
  1369. intentState.renderTasks.splice(i, 1);
  1370. }
  1371. if (this.cleanupAfterRender || renderingIntent === "print") {
  1372. this.pendingCleanup = true;
  1373. }
  1374. this._tryCleanup();
  1375. if (error) {
  1376. internalRenderTask.capability.reject(error);
  1377. this._abortOperatorList({
  1378. intentState,
  1379. reason: error
  1380. });
  1381. } else {
  1382. internalRenderTask.capability.resolve();
  1383. }
  1384. if (this._stats) {
  1385. this._stats.timeEnd("Rendering");
  1386. this._stats.timeEnd("Overall");
  1387. }
  1388. };
  1389. const internalRenderTask = new InternalRenderTask({
  1390. callback: complete,
  1391. params: {
  1392. canvasContext,
  1393. viewport,
  1394. transform,
  1395. imageLayer,
  1396. background
  1397. },
  1398. objs: this.objs,
  1399. commonObjs: this.commonObjs,
  1400. operatorList: intentState.operatorList,
  1401. pageIndex: this._pageIndex,
  1402. canvasFactory: canvasFactoryInstance,
  1403. webGLContext,
  1404. useRequestAnimationFrame: renderingIntent !== "print",
  1405. pdfBug: this._pdfBug
  1406. });
  1407. if (!intentState.renderTasks) {
  1408. intentState.renderTasks = [];
  1409. }
  1410. intentState.renderTasks.push(internalRenderTask);
  1411. const renderTask = internalRenderTask.task;
  1412. intentState.displayReadyCapability.promise.then(transparency => {
  1413. if (this.pendingCleanup) {
  1414. complete();
  1415. return;
  1416. }
  1417. if (this._stats) {
  1418. this._stats.time("Rendering");
  1419. }
  1420. internalRenderTask.initializeGraphics(transparency);
  1421. internalRenderTask.operatorListChanged();
  1422. }).catch(complete);
  1423. return renderTask;
  1424. }
  1425. getOperatorList() {
  1426. function operatorListChanged() {
  1427. if (intentState.operatorList.lastChunk) {
  1428. intentState.opListReadCapability.resolve(intentState.operatorList);
  1429. const i = intentState.renderTasks.indexOf(opListTask);
  1430. if (i >= 0) {
  1431. intentState.renderTasks.splice(i, 1);
  1432. }
  1433. }
  1434. }
  1435. const renderingIntent = "oplist";
  1436. if (!this.intentStates[renderingIntent]) {
  1437. this.intentStates[renderingIntent] = Object.create(null);
  1438. }
  1439. const intentState = this.intentStates[renderingIntent];
  1440. let opListTask;
  1441. if (!intentState.opListReadCapability) {
  1442. opListTask = {};
  1443. opListTask.operatorListChanged = operatorListChanged;
  1444. intentState.opListReadCapability = (0, _util.createPromiseCapability)();
  1445. intentState.renderTasks = [];
  1446. intentState.renderTasks.push(opListTask);
  1447. intentState.operatorList = {
  1448. fnArray: [],
  1449. argsArray: [],
  1450. lastChunk: false
  1451. };
  1452. if (this._stats) {
  1453. this._stats.time("Page Request");
  1454. }
  1455. this._pumpOperatorList({
  1456. pageIndex: this._pageIndex,
  1457. intent: renderingIntent
  1458. });
  1459. }
  1460. return intentState.opListReadCapability.promise;
  1461. }
  1462. streamTextContent({
  1463. normalizeWhitespace = false,
  1464. disableCombineTextItems = false
  1465. } = {}) {
  1466. const TEXT_CONTENT_CHUNK_SIZE = 100;
  1467. return this._transport.messageHandler.sendWithStream("GetTextContent", {
  1468. pageIndex: this._pageIndex,
  1469. normalizeWhitespace: normalizeWhitespace === true,
  1470. combineTextItems: disableCombineTextItems !== true
  1471. }, {
  1472. highWaterMark: TEXT_CONTENT_CHUNK_SIZE,
  1473. size(textContent) {
  1474. return textContent.items.length;
  1475. }
  1476. });
  1477. }
  1478. getTextContent(params = {}) {
  1479. const readableStream = this.streamTextContent(params);
  1480. return new Promise(function (resolve, reject) {
  1481. function pump() {
  1482. reader.read().then(function ({
  1483. value,
  1484. done
  1485. }) {
  1486. if (done) {
  1487. resolve(textContent);
  1488. return;
  1489. }
  1490. Object.assign(textContent.styles, value.styles);
  1491. textContent.items.push(...value.items);
  1492. pump();
  1493. }, reject);
  1494. }
  1495. const reader = readableStream.getReader();
  1496. const textContent = {
  1497. items: [],
  1498. styles: Object.create(null)
  1499. };
  1500. pump();
  1501. });
  1502. }
  1503. _destroy() {
  1504. this.destroyed = true;
  1505. this._transport.pageCache[this._pageIndex] = null;
  1506. const waitOn = [];
  1507. Object.keys(this.intentStates).forEach(intent => {
  1508. const intentState = this.intentStates[intent];
  1509. this._abortOperatorList({
  1510. intentState,
  1511. reason: new Error("Page was destroyed."),
  1512. force: true
  1513. });
  1514. if (intent === "oplist") {
  1515. return;
  1516. }
  1517. intentState.renderTasks.forEach(function (renderTask) {
  1518. const renderCompleted = renderTask.capability.promise.catch(function () {});
  1519. waitOn.push(renderCompleted);
  1520. renderTask.cancel();
  1521. });
  1522. });
  1523. this.objs.clear();
  1524. this.annotationsPromise = null;
  1525. this.pendingCleanup = false;
  1526. return Promise.all(waitOn);
  1527. }
  1528. cleanup(resetStats = false) {
  1529. this.pendingCleanup = true;
  1530. return this._tryCleanup(resetStats);
  1531. }
  1532. _tryCleanup(resetStats = false) {
  1533. if (!this.pendingCleanup || Object.keys(this.intentStates).some(intent => {
  1534. const intentState = this.intentStates[intent];
  1535. return intentState.renderTasks.length !== 0 || !intentState.operatorList.lastChunk;
  1536. })) {
  1537. return false;
  1538. }
  1539. Object.keys(this.intentStates).forEach(intent => {
  1540. delete this.intentStates[intent];
  1541. });
  1542. this.objs.clear();
  1543. this.annotationsPromise = null;
  1544. if (resetStats && this._stats) {
  1545. this._stats = new _display_utils.StatTimer();
  1546. }
  1547. this.pendingCleanup = false;
  1548. return true;
  1549. }
  1550. _startRenderPage(transparency, intent) {
  1551. const intentState = this.intentStates[intent];
  1552. if (!intentState) {
  1553. return;
  1554. }
  1555. if (this._stats) {
  1556. this._stats.timeEnd("Page Request");
  1557. }
  1558. if (intentState.displayReadyCapability) {
  1559. intentState.displayReadyCapability.resolve(transparency);
  1560. }
  1561. }
  1562. _renderPageChunk(operatorListChunk, intentState) {
  1563. for (let i = 0, ii = operatorListChunk.length; i < ii; i++) {
  1564. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  1565. intentState.operatorList.argsArray.push(operatorListChunk.argsArray[i]);
  1566. }
  1567. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  1568. for (let i = 0; i < intentState.renderTasks.length; i++) {
  1569. intentState.renderTasks[i].operatorListChanged();
  1570. }
  1571. if (operatorListChunk.lastChunk) {
  1572. this._tryCleanup();
  1573. }
  1574. }
  1575. _pumpOperatorList(args) {
  1576. (0, _util.assert)(args.intent, 'PDFPageProxy._pumpOperatorList: Expected "intent" argument.');
  1577. const readableStream = this._transport.messageHandler.sendWithStream("GetOperatorList", args);
  1578. const reader = readableStream.getReader();
  1579. const intentState = this.intentStates[args.intent];
  1580. intentState.streamReader = reader;
  1581. const pump = () => {
  1582. reader.read().then(({
  1583. value,
  1584. done
  1585. }) => {
  1586. if (done) {
  1587. intentState.streamReader = null;
  1588. return;
  1589. }
  1590. if (this._transport.destroyed) {
  1591. return;
  1592. }
  1593. this._renderPageChunk(value, intentState);
  1594. pump();
  1595. }, reason => {
  1596. intentState.streamReader = null;
  1597. if (this._transport.destroyed) {
  1598. return;
  1599. }
  1600. if (intentState.operatorList) {
  1601. intentState.operatorList.lastChunk = true;
  1602. for (let i = 0; i < intentState.renderTasks.length; i++) {
  1603. intentState.renderTasks[i].operatorListChanged();
  1604. }
  1605. this._tryCleanup();
  1606. }
  1607. if (intentState.displayReadyCapability) {
  1608. intentState.displayReadyCapability.reject(reason);
  1609. } else if (intentState.opListReadCapability) {
  1610. intentState.opListReadCapability.reject(reason);
  1611. } else {
  1612. throw reason;
  1613. }
  1614. });
  1615. };
  1616. pump();
  1617. }
  1618. _abortOperatorList({
  1619. intentState,
  1620. reason,
  1621. force = false
  1622. }) {
  1623. (0, _util.assert)(reason instanceof Error || typeof reason === "object" && reason !== null, 'PDFPageProxy._abortOperatorList: Expected "reason" argument.');
  1624. if (!intentState.streamReader) {
  1625. return;
  1626. }
  1627. if (!force) {
  1628. if (intentState.renderTasks.length !== 0) {
  1629. return;
  1630. }
  1631. if (reason instanceof _display_utils.RenderingCancelledException) {
  1632. intentState.streamReaderCancelTimeout = setTimeout(() => {
  1633. this._abortOperatorList({
  1634. intentState,
  1635. reason,
  1636. force: true
  1637. });
  1638. intentState.streamReaderCancelTimeout = null;
  1639. }, RENDERING_CANCELLED_TIMEOUT);
  1640. return;
  1641. }
  1642. }
  1643. intentState.streamReader.cancel(new _util.AbortException(reason && reason.message));
  1644. intentState.streamReader = null;
  1645. if (this._transport.destroyed) {
  1646. return;
  1647. }
  1648. Object.keys(this.intentStates).some(intent => {
  1649. if (this.intentStates[intent] === intentState) {
  1650. delete this.intentStates[intent];
  1651. return true;
  1652. }
  1653. return false;
  1654. });
  1655. this.cleanup();
  1656. }
  1657. get stats() {
  1658. return this._stats;
  1659. }
  1660. }
  1661. exports.PDFPageProxy = PDFPageProxy;
  1662. class LoopbackPort {
  1663. constructor(defer = true) {
  1664. this._listeners = [];
  1665. this._defer = defer;
  1666. this._deferred = Promise.resolve(undefined);
  1667. }
  1668. postMessage(obj, transfers) {
  1669. function cloneValue(value) {
  1670. if (typeof value !== "object" || value === null) {
  1671. return value;
  1672. }
  1673. if (cloned.has(value)) {
  1674. return cloned.get(value);
  1675. }
  1676. let buffer, result;
  1677. if ((buffer = value.buffer) && (0, _util.isArrayBuffer)(buffer)) {
  1678. const transferable = transfers && transfers.includes(buffer);
  1679. if (transferable) {
  1680. result = new value.constructor(buffer, value.byteOffset, value.byteLength);
  1681. } else {
  1682. result = new value.constructor(value);
  1683. }
  1684. cloned.set(value, result);
  1685. return result;
  1686. }
  1687. result = Array.isArray(value) ? [] : {};
  1688. cloned.set(value, result);
  1689. for (const i in value) {
  1690. let desc,
  1691. p = value;
  1692. while (!(desc = Object.getOwnPropertyDescriptor(p, i))) {
  1693. p = Object.getPrototypeOf(p);
  1694. }
  1695. if (typeof desc.value === "undefined") {
  1696. continue;
  1697. }
  1698. if (typeof desc.value === "function") {
  1699. if (value.hasOwnProperty && value.hasOwnProperty(i)) {
  1700. throw new Error(`LoopbackPort.postMessage - cannot clone: ${value[i]}`);
  1701. }
  1702. continue;
  1703. }
  1704. result[i] = cloneValue(desc.value);
  1705. }
  1706. return result;
  1707. }
  1708. if (!this._defer) {
  1709. this._listeners.forEach(listener => {
  1710. listener.call(this, {
  1711. data: obj
  1712. });
  1713. });
  1714. return;
  1715. }
  1716. const cloned = new WeakMap();
  1717. const e = {
  1718. data: cloneValue(obj)
  1719. };
  1720. this._deferred.then(() => {
  1721. this._listeners.forEach(listener => {
  1722. listener.call(this, e);
  1723. });
  1724. });
  1725. }
  1726. addEventListener(name, listener) {
  1727. this._listeners.push(listener);
  1728. }
  1729. removeEventListener(name, listener) {
  1730. const i = this._listeners.indexOf(listener);
  1731. this._listeners.splice(i, 1);
  1732. }
  1733. terminate() {
  1734. this._listeners.length = 0;
  1735. }
  1736. }
  1737. exports.LoopbackPort = LoopbackPort;
  1738. const PDFWorker = function PDFWorkerClosure() {
  1739. const pdfWorkerPorts = new WeakMap();
  1740. let isWorkerDisabled = false;
  1741. let fallbackWorkerSrc;
  1742. let nextFakeWorkerId = 0;
  1743. let fakeWorkerCapability;
  1744. if (_is_node.isNodeJS && typeof require === "function") {
  1745. isWorkerDisabled = true;
  1746. fallbackWorkerSrc = "./pdf.worker.js";
  1747. } else if (typeof document === "object" && "currentScript" in document) {
  1748. const pdfjsFilePath = document.currentScript && document.currentScript.src;
  1749. if (pdfjsFilePath) {
  1750. fallbackWorkerSrc = pdfjsFilePath.replace(/(\.(?:min\.)?js)(\?.*)?$/i, ".worker$1$2");
  1751. }
  1752. }
  1753. function getWorkerSrc() {
  1754. if (_worker_options.GlobalWorkerOptions.workerSrc) {
  1755. return _worker_options.GlobalWorkerOptions.workerSrc;
  1756. }
  1757. if (typeof fallbackWorkerSrc !== "undefined") {
  1758. if (!_is_node.isNodeJS) {
  1759. (0, _display_utils.deprecated)('No "GlobalWorkerOptions.workerSrc" specified.');
  1760. }
  1761. return fallbackWorkerSrc;
  1762. }
  1763. throw new Error('No "GlobalWorkerOptions.workerSrc" specified.');
  1764. }
  1765. function getMainThreadWorkerMessageHandler() {
  1766. let mainWorkerMessageHandler;
  1767. try {
  1768. mainWorkerMessageHandler = globalThis.pdfjsWorker && globalThis.pdfjsWorker.WorkerMessageHandler;
  1769. } catch (ex) {}
  1770. return mainWorkerMessageHandler || null;
  1771. }
  1772. function setupFakeWorkerGlobal() {
  1773. if (fakeWorkerCapability) {
  1774. return fakeWorkerCapability.promise;
  1775. }
  1776. fakeWorkerCapability = (0, _util.createPromiseCapability)();
  1777. const loader = async function () {
  1778. const mainWorkerMessageHandler = getMainThreadWorkerMessageHandler();
  1779. if (mainWorkerMessageHandler) {
  1780. return mainWorkerMessageHandler;
  1781. }
  1782. if (_is_node.isNodeJS && typeof require === "function") {
  1783. const worker = eval("require")(getWorkerSrc());
  1784. return worker.WorkerMessageHandler;
  1785. }
  1786. await (0, _display_utils.loadScript)(getWorkerSrc());
  1787. return window.pdfjsWorker.WorkerMessageHandler;
  1788. };
  1789. loader().then(fakeWorkerCapability.resolve, fakeWorkerCapability.reject);
  1790. return fakeWorkerCapability.promise;
  1791. }
  1792. function createCDNWrapper(url) {
  1793. const wrapper = "importScripts('" + url + "');";
  1794. return URL.createObjectURL(new Blob([wrapper]));
  1795. }
  1796. class PDFWorker {
  1797. constructor({
  1798. name = null,
  1799. port = null,
  1800. verbosity = (0, _util.getVerbosityLevel)()
  1801. } = {}) {
  1802. if (port && pdfWorkerPorts.has(port)) {
  1803. throw new Error("Cannot use more than one PDFWorker per port");
  1804. }
  1805. this.name = name;
  1806. this.destroyed = false;
  1807. this.postMessageTransfers = true;
  1808. this.verbosity = verbosity;
  1809. this._readyCapability = (0, _util.createPromiseCapability)();
  1810. this._port = null;
  1811. this._webWorker = null;
  1812. this._messageHandler = null;
  1813. if (port) {
  1814. pdfWorkerPorts.set(port, this);
  1815. this._initializeFromPort(port);
  1816. return;
  1817. }
  1818. this._initialize();
  1819. }
  1820. get promise() {
  1821. return this._readyCapability.promise;
  1822. }
  1823. get port() {
  1824. return this._port;
  1825. }
  1826. get messageHandler() {
  1827. return this._messageHandler;
  1828. }
  1829. _initializeFromPort(port) {
  1830. this._port = port;
  1831. this._messageHandler = new _message_handler.MessageHandler("main", "worker", port);
  1832. this._messageHandler.on("ready", function () {});
  1833. this._readyCapability.resolve();
  1834. }
  1835. _initialize() {
  1836. if (typeof Worker !== "undefined" && !isWorkerDisabled && !getMainThreadWorkerMessageHandler()) {
  1837. let workerSrc = getWorkerSrc();
  1838. try {
  1839. if (!(0, _util.isSameOrigin)(window.location.href, workerSrc)) {
  1840. workerSrc = createCDNWrapper(new URL(workerSrc, window.location).href);
  1841. }
  1842. const worker = new Worker(workerSrc);
  1843. const messageHandler = new _message_handler.MessageHandler("main", "worker", worker);
  1844. const terminateEarly = () => {
  1845. worker.removeEventListener("error", onWorkerError);
  1846. messageHandler.destroy();
  1847. worker.terminate();
  1848. if (this.destroyed) {
  1849. this._readyCapability.reject(new Error("Worker was destroyed"));
  1850. } else {
  1851. this._setupFakeWorker();
  1852. }
  1853. };
  1854. const onWorkerError = () => {
  1855. if (!this._webWorker) {
  1856. terminateEarly();
  1857. }
  1858. };
  1859. worker.addEventListener("error", onWorkerError);
  1860. messageHandler.on("test", data => {
  1861. worker.removeEventListener("error", onWorkerError);
  1862. if (this.destroyed) {
  1863. terminateEarly();
  1864. return;
  1865. }
  1866. if (data) {
  1867. this._messageHandler = messageHandler;
  1868. this._port = worker;
  1869. this._webWorker = worker;
  1870. if (!data.supportTransfers) {
  1871. this.postMessageTransfers = false;
  1872. }
  1873. this._readyCapability.resolve();
  1874. messageHandler.send("configure", {
  1875. verbosity: this.verbosity
  1876. });
  1877. } else {
  1878. this._setupFakeWorker();
  1879. messageHandler.destroy();
  1880. worker.terminate();
  1881. }
  1882. });
  1883. messageHandler.on("ready", data => {
  1884. worker.removeEventListener("error", onWorkerError);
  1885. if (this.destroyed) {
  1886. terminateEarly();
  1887. return;
  1888. }
  1889. try {
  1890. sendTest();
  1891. } catch (e) {
  1892. this._setupFakeWorker();
  1893. }
  1894. });
  1895. const sendTest = () => {
  1896. const testObj = new Uint8Array([this.postMessageTransfers ? 255 : 0]);
  1897. try {
  1898. messageHandler.send("test", testObj, [testObj.buffer]);
  1899. } catch (ex) {
  1900. (0, _util.warn)("Cannot use postMessage transfers.");
  1901. testObj[0] = 0;
  1902. messageHandler.send("test", testObj);
  1903. }
  1904. };
  1905. sendTest();
  1906. return;
  1907. } catch (e) {
  1908. (0, _util.info)("The worker has been disabled.");
  1909. }
  1910. }
  1911. this._setupFakeWorker();
  1912. }
  1913. _setupFakeWorker() {
  1914. if (!isWorkerDisabled) {
  1915. (0, _util.warn)("Setting up fake worker.");
  1916. isWorkerDisabled = true;
  1917. }
  1918. setupFakeWorkerGlobal().then(WorkerMessageHandler => {
  1919. if (this.destroyed) {
  1920. this._readyCapability.reject(new Error("Worker was destroyed"));
  1921. return;
  1922. }
  1923. const port = new LoopbackPort();
  1924. this._port = port;
  1925. const id = "fake" + nextFakeWorkerId++;
  1926. const workerHandler = new _message_handler.MessageHandler(id + "_worker", id, port);
  1927. WorkerMessageHandler.setup(workerHandler, port);
  1928. const messageHandler = new _message_handler.MessageHandler(id, id + "_worker", port);
  1929. this._messageHandler = messageHandler;
  1930. this._readyCapability.resolve();
  1931. messageHandler.send("configure", {
  1932. verbosity: this.verbosity
  1933. });
  1934. }).catch(reason => {
  1935. this._readyCapability.reject(new Error(`Setting up fake worker failed: "${reason.message}".`));
  1936. });
  1937. }
  1938. destroy() {
  1939. this.destroyed = true;
  1940. if (this._webWorker) {
  1941. this._webWorker.terminate();
  1942. this._webWorker = null;
  1943. }
  1944. pdfWorkerPorts.delete(this._port);
  1945. this._port = null;
  1946. if (this._messageHandler) {
  1947. this._messageHandler.destroy();
  1948. this._messageHandler = null;
  1949. }
  1950. }
  1951. static fromPort(params) {
  1952. if (!params || !params.port) {
  1953. throw new Error("PDFWorker.fromPort - invalid method signature.");
  1954. }
  1955. if (pdfWorkerPorts.has(params.port)) {
  1956. return pdfWorkerPorts.get(params.port);
  1957. }
  1958. return new PDFWorker(params);
  1959. }
  1960. static getWorkerSrc() {
  1961. return getWorkerSrc();
  1962. }
  1963. }
  1964. return PDFWorker;
  1965. }();
  1966. exports.PDFWorker = PDFWorker;
  1967. class WorkerTransport {
  1968. constructor(messageHandler, loadingTask, networkStream, params) {
  1969. this.messageHandler = messageHandler;
  1970. this.loadingTask = loadingTask;
  1971. this.commonObjs = new PDFObjects();
  1972. this.fontLoader = new _font_loader.FontLoader({
  1973. docId: loadingTask.docId,
  1974. onUnsupportedFeature: this._onUnsupportedFeature.bind(this)
  1975. });
  1976. this._params = params;
  1977. this.CMapReaderFactory = new params.CMapReaderFactory({
  1978. baseUrl: params.cMapUrl,
  1979. isCompressed: params.cMapPacked
  1980. });
  1981. this.destroyed = false;
  1982. this.destroyCapability = null;
  1983. this._passwordCapability = null;
  1984. this._networkStream = networkStream;
  1985. this._fullReader = null;
  1986. this._lastProgress = null;
  1987. this.pageCache = [];
  1988. this.pagePromises = [];
  1989. this.downloadInfoCapability = (0, _util.createPromiseCapability)();
  1990. this.setupMessageHandler();
  1991. }
  1992. destroy() {
  1993. if (this.destroyCapability) {
  1994. return this.destroyCapability.promise;
  1995. }
  1996. this.destroyed = true;
  1997. this.destroyCapability = (0, _util.createPromiseCapability)();
  1998. if (this._passwordCapability) {
  1999. this._passwordCapability.reject(new Error("Worker was destroyed during onPassword callback"));
  2000. }
  2001. const waitOn = [];
  2002. this.pageCache.forEach(function (page) {
  2003. if (page) {
  2004. waitOn.push(page._destroy());
  2005. }
  2006. });
  2007. this.pageCache.length = 0;
  2008. this.pagePromises.length = 0;
  2009. const terminated = this.messageHandler.sendWithPromise("Terminate", null);
  2010. waitOn.push(terminated);
  2011. Promise.all(waitOn).then(() => {
  2012. this.fontLoader.clear();
  2013. if (this._networkStream) {
  2014. this._networkStream.cancelAllRequests(new _util.AbortException("Worker was terminated."));
  2015. }
  2016. if (this.messageHandler) {
  2017. this.messageHandler.destroy();
  2018. this.messageHandler = null;
  2019. }
  2020. this.destroyCapability.resolve();
  2021. }, this.destroyCapability.reject);
  2022. return this.destroyCapability.promise;
  2023. }
  2024. setupMessageHandler() {
  2025. const {
  2026. messageHandler,
  2027. loadingTask
  2028. } = this;
  2029. messageHandler.on("GetReader", (data, sink) => {
  2030. (0, _util.assert)(this._networkStream);
  2031. this._fullReader = this._networkStream.getFullReader();
  2032. this._fullReader.onProgress = evt => {
  2033. this._lastProgress = {
  2034. loaded: evt.loaded,
  2035. total: evt.total
  2036. };
  2037. };
  2038. sink.onPull = () => {
  2039. this._fullReader.read().then(function ({
  2040. value,
  2041. done
  2042. }) {
  2043. if (done) {
  2044. sink.close();
  2045. return;
  2046. }
  2047. (0, _util.assert)((0, _util.isArrayBuffer)(value));
  2048. sink.enqueue(new Uint8Array(value), 1, [value]);
  2049. }).catch(reason => {
  2050. sink.error(reason);
  2051. });
  2052. };
  2053. sink.onCancel = reason => {
  2054. this._fullReader.cancel(reason);
  2055. };
  2056. });
  2057. messageHandler.on("ReaderHeadersReady", data => {
  2058. const headersCapability = (0, _util.createPromiseCapability)();
  2059. const fullReader = this._fullReader;
  2060. fullReader.headersReady.then(() => {
  2061. if (!fullReader.isStreamingSupported || !fullReader.isRangeSupported) {
  2062. if (this._lastProgress && loadingTask.onProgress) {
  2063. loadingTask.onProgress(this._lastProgress);
  2064. }
  2065. fullReader.onProgress = evt => {
  2066. if (loadingTask.onProgress) {
  2067. loadingTask.onProgress({
  2068. loaded: evt.loaded,
  2069. total: evt.total
  2070. });
  2071. }
  2072. };
  2073. }
  2074. headersCapability.resolve({
  2075. isStreamingSupported: fullReader.isStreamingSupported,
  2076. isRangeSupported: fullReader.isRangeSupported,
  2077. contentLength: fullReader.contentLength
  2078. });
  2079. }, headersCapability.reject);
  2080. return headersCapability.promise;
  2081. });
  2082. messageHandler.on("GetRangeReader", (data, sink) => {
  2083. (0, _util.assert)(this._networkStream);
  2084. const rangeReader = this._networkStream.getRangeReader(data.begin, data.end);
  2085. if (!rangeReader) {
  2086. sink.close();
  2087. return;
  2088. }
  2089. sink.onPull = () => {
  2090. rangeReader.read().then(function ({
  2091. value,
  2092. done
  2093. }) {
  2094. if (done) {
  2095. sink.close();
  2096. return;
  2097. }
  2098. (0, _util.assert)((0, _util.isArrayBuffer)(value));
  2099. sink.enqueue(new Uint8Array(value), 1, [value]);
  2100. }).catch(reason => {
  2101. sink.error(reason);
  2102. });
  2103. };
  2104. sink.onCancel = reason => {
  2105. rangeReader.cancel(reason);
  2106. };
  2107. });
  2108. messageHandler.on("GetDoc", ({
  2109. pdfInfo
  2110. }) => {
  2111. this._numPages = pdfInfo.numPages;
  2112. loadingTask._capability.resolve(new PDFDocumentProxy(pdfInfo, this));
  2113. });
  2114. messageHandler.on("DocException", function (ex) {
  2115. let reason;
  2116. switch (ex.name) {
  2117. case "PasswordException":
  2118. reason = new _util.PasswordException(ex.message, ex.code);
  2119. break;
  2120. case "InvalidPDFException":
  2121. reason = new _util.InvalidPDFException(ex.message);
  2122. break;
  2123. case "MissingPDFException":
  2124. reason = new _util.MissingPDFException(ex.message);
  2125. break;
  2126. case "UnexpectedResponseException":
  2127. reason = new _util.UnexpectedResponseException(ex.message, ex.status);
  2128. break;
  2129. case "UnknownErrorException":
  2130. reason = new _util.UnknownErrorException(ex.message, ex.details);
  2131. break;
  2132. }
  2133. loadingTask._capability.reject(reason);
  2134. });
  2135. messageHandler.on("PasswordRequest", exception => {
  2136. this._passwordCapability = (0, _util.createPromiseCapability)();
  2137. if (loadingTask.onPassword) {
  2138. const updatePassword = password => {
  2139. this._passwordCapability.resolve({
  2140. password
  2141. });
  2142. };
  2143. try {
  2144. loadingTask.onPassword(updatePassword, exception.code);
  2145. } catch (ex) {
  2146. this._passwordCapability.reject(ex);
  2147. }
  2148. } else {
  2149. this._passwordCapability.reject(new _util.PasswordException(exception.message, exception.code));
  2150. }
  2151. return this._passwordCapability.promise;
  2152. });
  2153. messageHandler.on("DataLoaded", data => {
  2154. if (loadingTask.onProgress) {
  2155. loadingTask.onProgress({
  2156. loaded: data.length,
  2157. total: data.length
  2158. });
  2159. }
  2160. this.downloadInfoCapability.resolve(data);
  2161. });
  2162. messageHandler.on("StartRenderPage", data => {
  2163. if (this.destroyed) {
  2164. return;
  2165. }
  2166. const page = this.pageCache[data.pageIndex];
  2167. page._startRenderPage(data.transparency, data.intent);
  2168. });
  2169. messageHandler.on("commonobj", data => {
  2170. if (this.destroyed) {
  2171. return;
  2172. }
  2173. const [id, type, exportedData] = data;
  2174. if (this.commonObjs.has(id)) {
  2175. return;
  2176. }
  2177. switch (type) {
  2178. case "Font":
  2179. const params = this._params;
  2180. if ("error" in exportedData) {
  2181. const exportedError = exportedData.error;
  2182. (0, _util.warn)(`Error during font loading: ${exportedError}`);
  2183. this.commonObjs.resolve(id, exportedError);
  2184. break;
  2185. }
  2186. let fontRegistry = null;
  2187. if (params.pdfBug && globalThis.FontInspector && globalThis.FontInspector.enabled) {
  2188. fontRegistry = {
  2189. registerFont(font, url) {
  2190. globalThis.FontInspector.fontAdded(font, url);
  2191. }
  2192. };
  2193. }
  2194. const font = new _font_loader.FontFaceObject(exportedData, {
  2195. isEvalSupported: params.isEvalSupported,
  2196. disableFontFace: params.disableFontFace,
  2197. ignoreErrors: params.ignoreErrors,
  2198. onUnsupportedFeature: this._onUnsupportedFeature.bind(this),
  2199. fontRegistry
  2200. });
  2201. this.fontLoader.bind(font).then(() => {
  2202. this.commonObjs.resolve(id, font);
  2203. }, reason => {
  2204. messageHandler.sendWithPromise("FontFallback", {
  2205. id
  2206. }).finally(() => {
  2207. this.commonObjs.resolve(id, font);
  2208. });
  2209. });
  2210. break;
  2211. case "FontPath":
  2212. case "FontType3Res":
  2213. this.commonObjs.resolve(id, exportedData);
  2214. break;
  2215. default:
  2216. throw new Error(`Got unknown common object type ${type}`);
  2217. }
  2218. });
  2219. messageHandler.on("obj", data => {
  2220. if (this.destroyed) {
  2221. return undefined;
  2222. }
  2223. const [id, pageIndex, type, imageData] = data;
  2224. const pageProxy = this.pageCache[pageIndex];
  2225. if (pageProxy.objs.has(id)) {
  2226. return undefined;
  2227. }
  2228. switch (type) {
  2229. case "JpegStream":
  2230. return new Promise((resolve, reject) => {
  2231. const img = new Image();
  2232. img.onload = function () {
  2233. resolve(img);
  2234. };
  2235. img.onerror = function () {
  2236. reject(new Error("Error during JPEG image loading"));
  2237. (0, _display_utils.releaseImageResources)(img);
  2238. };
  2239. img.src = imageData;
  2240. }).then(img => {
  2241. pageProxy.objs.resolve(id, img);
  2242. });
  2243. case "Image":
  2244. pageProxy.objs.resolve(id, imageData);
  2245. const MAX_IMAGE_SIZE_TO_STORE = 8000000;
  2246. if (imageData && "data" in imageData && imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
  2247. pageProxy.cleanupAfterRender = true;
  2248. }
  2249. break;
  2250. default:
  2251. throw new Error(`Got unknown object type ${type}`);
  2252. }
  2253. return undefined;
  2254. });
  2255. messageHandler.on("DocProgress", data => {
  2256. if (this.destroyed) {
  2257. return;
  2258. }
  2259. if (loadingTask.onProgress) {
  2260. loadingTask.onProgress({
  2261. loaded: data.loaded,
  2262. total: data.total
  2263. });
  2264. }
  2265. });
  2266. messageHandler.on("UnsupportedFeature", this._onUnsupportedFeature.bind(this));
  2267. messageHandler.on("JpegDecode", data => {
  2268. if (this.destroyed) {
  2269. return Promise.reject(new Error("Worker was destroyed"));
  2270. }
  2271. if (typeof document === "undefined") {
  2272. return Promise.reject(new Error('"document" is not defined.'));
  2273. }
  2274. const [imageUrl, components] = data;
  2275. if (components !== 3 && components !== 1) {
  2276. return Promise.reject(new Error("Only 3 components or 1 component can be returned"));
  2277. }
  2278. return new Promise(function (resolve, reject) {
  2279. const img = new Image();
  2280. img.onload = function () {
  2281. const {
  2282. width,
  2283. height
  2284. } = img;
  2285. const size = width * height;
  2286. const rgbaLength = size * 4;
  2287. const buf = new Uint8ClampedArray(size * components);
  2288. let tmpCanvas = document.createElement("canvas");
  2289. tmpCanvas.width = width;
  2290. tmpCanvas.height = height;
  2291. let tmpCtx = tmpCanvas.getContext("2d");
  2292. tmpCtx.drawImage(img, 0, 0);
  2293. const data = tmpCtx.getImageData(0, 0, width, height).data;
  2294. if (components === 3) {
  2295. for (let i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
  2296. buf[j] = data[i];
  2297. buf[j + 1] = data[i + 1];
  2298. buf[j + 2] = data[i + 2];
  2299. }
  2300. } else if (components === 1) {
  2301. for (let i = 0, j = 0; i < rgbaLength; i += 4, j++) {
  2302. buf[j] = data[i];
  2303. }
  2304. }
  2305. resolve({
  2306. data: buf,
  2307. width,
  2308. height
  2309. });
  2310. (0, _display_utils.releaseImageResources)(img);
  2311. tmpCanvas.width = 0;
  2312. tmpCanvas.height = 0;
  2313. tmpCanvas = null;
  2314. tmpCtx = null;
  2315. };
  2316. img.onerror = function () {
  2317. reject(new Error("JpegDecode failed to load image"));
  2318. (0, _display_utils.releaseImageResources)(img);
  2319. };
  2320. img.src = imageUrl;
  2321. });
  2322. });
  2323. messageHandler.on("FetchBuiltInCMap", (data, sink) => {
  2324. if (this.destroyed) {
  2325. sink.error(new Error("Worker was destroyed"));
  2326. return;
  2327. }
  2328. let fetched = false;
  2329. sink.onPull = () => {
  2330. if (fetched) {
  2331. sink.close();
  2332. return;
  2333. }
  2334. fetched = true;
  2335. this.CMapReaderFactory.fetch(data).then(function (builtInCMap) {
  2336. sink.enqueue(builtInCMap, 1, [builtInCMap.cMapData.buffer]);
  2337. }).catch(function (reason) {
  2338. sink.error(reason);
  2339. });
  2340. };
  2341. });
  2342. }
  2343. _onUnsupportedFeature({
  2344. featureId
  2345. }) {
  2346. if (this.destroyed) {
  2347. return;
  2348. }
  2349. if (this.loadingTask.onUnsupportedFeature) {
  2350. this.loadingTask.onUnsupportedFeature(featureId);
  2351. }
  2352. }
  2353. getData() {
  2354. return this.messageHandler.sendWithPromise("GetData", null);
  2355. }
  2356. getPage(pageNumber) {
  2357. if (!Number.isInteger(pageNumber) || pageNumber <= 0 || pageNumber > this._numPages) {
  2358. return Promise.reject(new Error("Invalid page request"));
  2359. }
  2360. const pageIndex = pageNumber - 1;
  2361. if (pageIndex in this.pagePromises) {
  2362. return this.pagePromises[pageIndex];
  2363. }
  2364. const promise = this.messageHandler.sendWithPromise("GetPage", {
  2365. pageIndex
  2366. }).then(pageInfo => {
  2367. if (this.destroyed) {
  2368. throw new Error("Transport destroyed");
  2369. }
  2370. const page = new PDFPageProxy(pageIndex, pageInfo, this, this._params.pdfBug);
  2371. this.pageCache[pageIndex] = page;
  2372. return page;
  2373. });
  2374. this.pagePromises[pageIndex] = promise;
  2375. return promise;
  2376. }
  2377. getPageIndex(ref) {
  2378. return this.messageHandler.sendWithPromise("GetPageIndex", {
  2379. ref
  2380. }).catch(function (reason) {
  2381. return Promise.reject(new Error(reason));
  2382. });
  2383. }
  2384. getAnnotations(pageIndex, intent) {
  2385. return this.messageHandler.sendWithPromise("GetAnnotations", {
  2386. pageIndex,
  2387. intent
  2388. });
  2389. }
  2390. getDestinations() {
  2391. return this.messageHandler.sendWithPromise("GetDestinations", null);
  2392. }
  2393. getDestination(id) {
  2394. if (typeof id !== "string") {
  2395. return Promise.reject(new Error("Invalid destination request."));
  2396. }
  2397. return this.messageHandler.sendWithPromise("GetDestination", {
  2398. id
  2399. });
  2400. }
  2401. getPageLabels() {
  2402. return this.messageHandler.sendWithPromise("GetPageLabels", null);
  2403. }
  2404. getPageLayout() {
  2405. return this.messageHandler.sendWithPromise("GetPageLayout", null);
  2406. }
  2407. getPageMode() {
  2408. return this.messageHandler.sendWithPromise("GetPageMode", null);
  2409. }
  2410. getViewerPreferences() {
  2411. return this.messageHandler.sendWithPromise("GetViewerPreferences", null);
  2412. }
  2413. getOpenAction() {
  2414. return this.messageHandler.sendWithPromise("GetOpenAction", null);
  2415. }
  2416. getAttachments() {
  2417. return this.messageHandler.sendWithPromise("GetAttachments", null);
  2418. }
  2419. getJavaScript() {
  2420. return this.messageHandler.sendWithPromise("GetJavaScript", null);
  2421. }
  2422. getOutline() {
  2423. return this.messageHandler.sendWithPromise("GetOutline", null);
  2424. }
  2425. getPermissions() {
  2426. return this.messageHandler.sendWithPromise("GetPermissions", null);
  2427. }
  2428. getMetadata() {
  2429. return this.messageHandler.sendWithPromise("GetMetadata", null).then(results => {
  2430. return {
  2431. info: results[0],
  2432. metadata: results[1] ? new _metadata.Metadata(results[1]) : null,
  2433. contentDispositionFilename: this._fullReader ? this._fullReader.filename : null
  2434. };
  2435. });
  2436. }
  2437. getStats() {
  2438. return this.messageHandler.sendWithPromise("GetStats", null);
  2439. }
  2440. startCleanup() {
  2441. return this.messageHandler.sendWithPromise("Cleanup", null).then(() => {
  2442. for (let i = 0, ii = this.pageCache.length; i < ii; i++) {
  2443. const page = this.pageCache[i];
  2444. if (page) {
  2445. const cleanupSuccessful = page.cleanup();
  2446. if (!cleanupSuccessful) {
  2447. throw new Error(`startCleanup: Page ${i + 1} is currently rendering.`);
  2448. }
  2449. }
  2450. }
  2451. this.commonObjs.clear();
  2452. this.fontLoader.clear();
  2453. });
  2454. }
  2455. get loadingParams() {
  2456. const params = this._params;
  2457. return (0, _util.shadow)(this, "loadingParams", {
  2458. disableAutoFetch: params.disableAutoFetch,
  2459. disableCreateObjectURL: params.disableCreateObjectURL,
  2460. disableFontFace: params.disableFontFace,
  2461. nativeImageDecoderSupport: params.nativeImageDecoderSupport
  2462. });
  2463. }
  2464. }
  2465. class PDFObjects {
  2466. constructor() {
  2467. this._objs = Object.create(null);
  2468. }
  2469. _ensureObj(objId) {
  2470. if (this._objs[objId]) {
  2471. return this._objs[objId];
  2472. }
  2473. return this._objs[objId] = {
  2474. capability: (0, _util.createPromiseCapability)(),
  2475. data: null,
  2476. resolved: false
  2477. };
  2478. }
  2479. get(objId, callback = null) {
  2480. if (callback) {
  2481. this._ensureObj(objId).capability.promise.then(callback);
  2482. return null;
  2483. }
  2484. const obj = this._objs[objId];
  2485. if (!obj || !obj.resolved) {
  2486. throw new Error(`Requesting object that isn't resolved yet ${objId}.`);
  2487. }
  2488. return obj.data;
  2489. }
  2490. has(objId) {
  2491. const obj = this._objs[objId];
  2492. return obj ? obj.resolved : false;
  2493. }
  2494. resolve(objId, data) {
  2495. const obj = this._ensureObj(objId);
  2496. obj.resolved = true;
  2497. obj.data = data;
  2498. obj.capability.resolve(data);
  2499. }
  2500. clear() {
  2501. for (const objId in this._objs) {
  2502. const {
  2503. data
  2504. } = this._objs[objId];
  2505. if (typeof Image !== "undefined" && data instanceof Image) {
  2506. (0, _display_utils.releaseImageResources)(data);
  2507. }
  2508. }
  2509. this._objs = Object.create(null);
  2510. }
  2511. }
  2512. class RenderTask {
  2513. constructor(internalRenderTask) {
  2514. this._internalRenderTask = internalRenderTask;
  2515. this.onContinue = null;
  2516. }
  2517. get promise() {
  2518. return this._internalRenderTask.capability.promise;
  2519. }
  2520. cancel() {
  2521. this._internalRenderTask.cancel();
  2522. }
  2523. then(onFulfilled, onRejected) {
  2524. throw new Error("Removed API method: " + "RenderTask.then, use the `promise` getter instead.");
  2525. }
  2526. }
  2527. const InternalRenderTask = function InternalRenderTaskClosure() {
  2528. const canvasInRendering = new WeakSet();
  2529. class InternalRenderTask {
  2530. constructor({
  2531. callback,
  2532. params,
  2533. objs,
  2534. commonObjs,
  2535. operatorList,
  2536. pageIndex,
  2537. canvasFactory,
  2538. webGLContext,
  2539. useRequestAnimationFrame = false,
  2540. pdfBug = false
  2541. }) {
  2542. this.callback = callback;
  2543. this.params = params;
  2544. this.objs = objs;
  2545. this.commonObjs = commonObjs;
  2546. this.operatorListIdx = null;
  2547. this.operatorList = operatorList;
  2548. this._pageIndex = pageIndex;
  2549. this.canvasFactory = canvasFactory;
  2550. this.webGLContext = webGLContext;
  2551. this._pdfBug = pdfBug;
  2552. this.running = false;
  2553. this.graphicsReadyCallback = null;
  2554. this.graphicsReady = false;
  2555. this._useRequestAnimationFrame = useRequestAnimationFrame === true && typeof window !== "undefined";
  2556. this.cancelled = false;
  2557. this.capability = (0, _util.createPromiseCapability)();
  2558. this.task = new RenderTask(this);
  2559. this._continueBound = this._continue.bind(this);
  2560. this._scheduleNextBound = this._scheduleNext.bind(this);
  2561. this._nextBound = this._next.bind(this);
  2562. this._canvas = params.canvasContext.canvas;
  2563. }
  2564. initializeGraphics(transparency = false) {
  2565. if (this.cancelled) {
  2566. return;
  2567. }
  2568. if (this._canvas) {
  2569. if (canvasInRendering.has(this._canvas)) {
  2570. throw new Error("Cannot use the same canvas during multiple render() operations. " + "Use different canvas or ensure previous operations were " + "cancelled or completed.");
  2571. }
  2572. canvasInRendering.add(this._canvas);
  2573. }
  2574. if (this._pdfBug && globalThis.StepperManager && globalThis.StepperManager.enabled) {
  2575. this.stepper = globalThis.StepperManager.create(this._pageIndex);
  2576. this.stepper.init(this.operatorList);
  2577. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  2578. }
  2579. const {
  2580. canvasContext,
  2581. viewport,
  2582. transform,
  2583. imageLayer,
  2584. background
  2585. } = this.params;
  2586. this.gfx = new _canvas.CanvasGraphics(canvasContext, this.commonObjs, this.objs, this.canvasFactory, this.webGLContext, imageLayer);
  2587. this.gfx.beginDrawing({
  2588. transform,
  2589. viewport,
  2590. transparency,
  2591. background
  2592. });
  2593. this.operatorListIdx = 0;
  2594. this.graphicsReady = true;
  2595. if (this.graphicsReadyCallback) {
  2596. this.graphicsReadyCallback();
  2597. }
  2598. }
  2599. cancel(error = null) {
  2600. this.running = false;
  2601. this.cancelled = true;
  2602. if (this.gfx) {
  2603. this.gfx.endDrawing();
  2604. }
  2605. if (this._canvas) {
  2606. canvasInRendering.delete(this._canvas);
  2607. }
  2608. this.callback(error || new _display_utils.RenderingCancelledException(`Rendering cancelled, page ${this._pageIndex + 1}`, "canvas"));
  2609. }
  2610. operatorListChanged() {
  2611. if (!this.graphicsReady) {
  2612. if (!this.graphicsReadyCallback) {
  2613. this.graphicsReadyCallback = this._continueBound;
  2614. }
  2615. return;
  2616. }
  2617. if (this.stepper) {
  2618. this.stepper.updateOperatorList(this.operatorList);
  2619. }
  2620. if (this.running) {
  2621. return;
  2622. }
  2623. this._continue();
  2624. }
  2625. _continue() {
  2626. this.running = true;
  2627. if (this.cancelled) {
  2628. return;
  2629. }
  2630. if (this.task.onContinue) {
  2631. this.task.onContinue(this._scheduleNextBound);
  2632. } else {
  2633. this._scheduleNext();
  2634. }
  2635. }
  2636. _scheduleNext() {
  2637. if (this._useRequestAnimationFrame) {
  2638. window.requestAnimationFrame(() => {
  2639. this._nextBound().catch(this.cancel.bind(this));
  2640. });
  2641. } else {
  2642. Promise.resolve().then(this._nextBound).catch(this.cancel.bind(this));
  2643. }
  2644. }
  2645. async _next() {
  2646. if (this.cancelled) {
  2647. return;
  2648. }
  2649. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList, this.operatorListIdx, this._continueBound, this.stepper);
  2650. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  2651. this.running = false;
  2652. if (this.operatorList.lastChunk) {
  2653. this.gfx.endDrawing();
  2654. if (this._canvas) {
  2655. canvasInRendering.delete(this._canvas);
  2656. }
  2657. this.callback();
  2658. }
  2659. }
  2660. }
  2661. }
  2662. return InternalRenderTask;
  2663. }();
  2664. const version = '2.4.456';
  2665. exports.version = version;
  2666. const build = '228a591c';
  2667. exports.build = build;
  2668. /***/ }),
  2669. /* 4 */
  2670. /***/ (function(module, exports, __w_pdfjs_require__) {
  2671. "use strict";
  2672. Object.defineProperty(exports, "__esModule", {
  2673. value: true
  2674. });
  2675. exports.addLinkAttributes = addLinkAttributes;
  2676. exports.getFilenameFromUrl = getFilenameFromUrl;
  2677. exports.isFetchSupported = isFetchSupported;
  2678. exports.isValidFetchUrl = isValidFetchUrl;
  2679. exports.loadScript = loadScript;
  2680. exports.deprecated = deprecated;
  2681. exports.releaseImageResources = releaseImageResources;
  2682. exports.PDFDateString = exports.StatTimer = exports.DOMSVGFactory = exports.DOMCMapReaderFactory = exports.DOMCanvasFactory = exports.DEFAULT_LINK_REL = exports.LinkTarget = exports.RenderingCancelledException = exports.PageViewport = void 0;
  2683. var _util = __w_pdfjs_require__(1);
  2684. const DEFAULT_LINK_REL = "noopener noreferrer nofollow";
  2685. exports.DEFAULT_LINK_REL = DEFAULT_LINK_REL;
  2686. const SVG_NS = "http://www.w3.org/2000/svg";
  2687. class DOMCanvasFactory {
  2688. create(width, height) {
  2689. if (width <= 0 || height <= 0) {
  2690. throw new Error("Invalid canvas size");
  2691. }
  2692. const canvas = document.createElement("canvas");
  2693. const context = canvas.getContext("2d");
  2694. canvas.width = width;
  2695. canvas.height = height;
  2696. return {
  2697. canvas,
  2698. context
  2699. };
  2700. }
  2701. reset(canvasAndContext, width, height) {
  2702. if (!canvasAndContext.canvas) {
  2703. throw new Error("Canvas is not specified");
  2704. }
  2705. if (width <= 0 || height <= 0) {
  2706. throw new Error("Invalid canvas size");
  2707. }
  2708. canvasAndContext.canvas.width = width;
  2709. canvasAndContext.canvas.height = height;
  2710. }
  2711. destroy(canvasAndContext) {
  2712. if (!canvasAndContext.canvas) {
  2713. throw new Error("Canvas is not specified");
  2714. }
  2715. canvasAndContext.canvas.width = 0;
  2716. canvasAndContext.canvas.height = 0;
  2717. canvasAndContext.canvas = null;
  2718. canvasAndContext.context = null;
  2719. }
  2720. }
  2721. exports.DOMCanvasFactory = DOMCanvasFactory;
  2722. class DOMCMapReaderFactory {
  2723. constructor({
  2724. baseUrl = null,
  2725. isCompressed = false
  2726. }) {
  2727. this.baseUrl = baseUrl;
  2728. this.isCompressed = isCompressed;
  2729. }
  2730. async fetch({
  2731. name
  2732. }) {
  2733. if (!this.baseUrl) {
  2734. throw new Error('The CMap "baseUrl" parameter must be specified, ensure that ' + 'the "cMapUrl" and "cMapPacked" API parameters are provided.');
  2735. }
  2736. if (!name) {
  2737. throw new Error("CMap name must be specified.");
  2738. }
  2739. const url = this.baseUrl + name + (this.isCompressed ? ".bcmap" : "");
  2740. const compressionType = this.isCompressed ? _util.CMapCompressionType.BINARY : _util.CMapCompressionType.NONE;
  2741. if (isFetchSupported() && isValidFetchUrl(url, document.baseURI)) {
  2742. return fetch(url).then(async response => {
  2743. if (!response.ok) {
  2744. throw new Error(response.statusText);
  2745. }
  2746. let cMapData;
  2747. if (this.isCompressed) {
  2748. cMapData = new Uint8Array((await response.arrayBuffer()));
  2749. } else {
  2750. cMapData = (0, _util.stringToBytes)((await response.text()));
  2751. }
  2752. return {
  2753. cMapData,
  2754. compressionType
  2755. };
  2756. }).catch(reason => {
  2757. throw new Error(`Unable to load ${this.isCompressed ? "binary " : ""}` + `CMap at: ${url}`);
  2758. });
  2759. }
  2760. return new Promise((resolve, reject) => {
  2761. const request = new XMLHttpRequest();
  2762. request.open("GET", url, true);
  2763. if (this.isCompressed) {
  2764. request.responseType = "arraybuffer";
  2765. }
  2766. request.onreadystatechange = () => {
  2767. if (request.readyState !== XMLHttpRequest.DONE) {
  2768. return;
  2769. }
  2770. if (request.status === 200 || request.status === 0) {
  2771. let cMapData;
  2772. if (this.isCompressed && request.response) {
  2773. cMapData = new Uint8Array(request.response);
  2774. } else if (!this.isCompressed && request.responseText) {
  2775. cMapData = (0, _util.stringToBytes)(request.responseText);
  2776. }
  2777. if (cMapData) {
  2778. resolve({
  2779. cMapData,
  2780. compressionType
  2781. });
  2782. return;
  2783. }
  2784. }
  2785. reject(new Error(request.statusText));
  2786. };
  2787. request.send(null);
  2788. }).catch(reason => {
  2789. throw new Error(`Unable to load ${this.isCompressed ? "binary " : ""}` + `CMap at: ${url}`);
  2790. });
  2791. }
  2792. }
  2793. exports.DOMCMapReaderFactory = DOMCMapReaderFactory;
  2794. class DOMSVGFactory {
  2795. create(width, height) {
  2796. (0, _util.assert)(width > 0 && height > 0, "Invalid SVG dimensions");
  2797. const svg = document.createElementNS(SVG_NS, "svg:svg");
  2798. svg.setAttribute("version", "1.1");
  2799. svg.setAttribute("width", width + "px");
  2800. svg.setAttribute("height", height + "px");
  2801. svg.setAttribute("preserveAspectRatio", "none");
  2802. svg.setAttribute("viewBox", "0 0 " + width + " " + height);
  2803. return svg;
  2804. }
  2805. createElement(type) {
  2806. (0, _util.assert)(typeof type === "string", "Invalid SVG element type");
  2807. return document.createElementNS(SVG_NS, type);
  2808. }
  2809. }
  2810. exports.DOMSVGFactory = DOMSVGFactory;
  2811. class PageViewport {
  2812. constructor({
  2813. viewBox,
  2814. scale,
  2815. rotation,
  2816. offsetX = 0,
  2817. offsetY = 0,
  2818. dontFlip = false
  2819. }) {
  2820. this.viewBox = viewBox;
  2821. this.scale = scale;
  2822. this.rotation = rotation;
  2823. this.offsetX = offsetX;
  2824. this.offsetY = offsetY;
  2825. const centerX = (viewBox[2] + viewBox[0]) / 2;
  2826. const centerY = (viewBox[3] + viewBox[1]) / 2;
  2827. let rotateA, rotateB, rotateC, rotateD;
  2828. rotation = rotation % 360;
  2829. rotation = rotation < 0 ? rotation + 360 : rotation;
  2830. switch (rotation) {
  2831. case 180:
  2832. rotateA = -1;
  2833. rotateB = 0;
  2834. rotateC = 0;
  2835. rotateD = 1;
  2836. break;
  2837. case 90:
  2838. rotateA = 0;
  2839. rotateB = 1;
  2840. rotateC = 1;
  2841. rotateD = 0;
  2842. break;
  2843. case 270:
  2844. rotateA = 0;
  2845. rotateB = -1;
  2846. rotateC = -1;
  2847. rotateD = 0;
  2848. break;
  2849. default:
  2850. rotateA = 1;
  2851. rotateB = 0;
  2852. rotateC = 0;
  2853. rotateD = -1;
  2854. break;
  2855. }
  2856. if (dontFlip) {
  2857. rotateC = -rotateC;
  2858. rotateD = -rotateD;
  2859. }
  2860. let offsetCanvasX, offsetCanvasY;
  2861. let width, height;
  2862. if (rotateA === 0) {
  2863. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  2864. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  2865. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  2866. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  2867. } else {
  2868. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  2869. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  2870. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  2871. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  2872. }
  2873. this.transform = [rotateA * scale, rotateB * scale, rotateC * scale, rotateD * scale, offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY, offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY];
  2874. this.width = width;
  2875. this.height = height;
  2876. }
  2877. clone({
  2878. scale = this.scale,
  2879. rotation = this.rotation,
  2880. offsetX = this.offsetX,
  2881. offsetY = this.offsetY,
  2882. dontFlip = false
  2883. } = {}) {
  2884. return new PageViewport({
  2885. viewBox: this.viewBox.slice(),
  2886. scale,
  2887. rotation,
  2888. offsetX,
  2889. offsetY,
  2890. dontFlip
  2891. });
  2892. }
  2893. convertToViewportPoint(x, y) {
  2894. return _util.Util.applyTransform([x, y], this.transform);
  2895. }
  2896. convertToViewportRectangle(rect) {
  2897. const topLeft = _util.Util.applyTransform([rect[0], rect[1]], this.transform);
  2898. const bottomRight = _util.Util.applyTransform([rect[2], rect[3]], this.transform);
  2899. return [topLeft[0], topLeft[1], bottomRight[0], bottomRight[1]];
  2900. }
  2901. convertToPdfPoint(x, y) {
  2902. return _util.Util.applyInverseTransform([x, y], this.transform);
  2903. }
  2904. }
  2905. exports.PageViewport = PageViewport;
  2906. class RenderingCancelledException extends _util.BaseException {
  2907. constructor(msg, type) {
  2908. super(msg);
  2909. this.type = type;
  2910. }
  2911. }
  2912. exports.RenderingCancelledException = RenderingCancelledException;
  2913. const LinkTarget = {
  2914. NONE: 0,
  2915. SELF: 1,
  2916. BLANK: 2,
  2917. PARENT: 3,
  2918. TOP: 4
  2919. };
  2920. exports.LinkTarget = LinkTarget;
  2921. function addLinkAttributes(link, {
  2922. url,
  2923. target,
  2924. rel,
  2925. enabled = true
  2926. } = {}) {
  2927. (0, _util.assert)(url && typeof url === "string", 'addLinkAttributes: A valid "url" parameter must provided.');
  2928. const urlNullRemoved = (0, _util.removeNullCharacters)(url);
  2929. if (enabled) {
  2930. link.href = link.title = urlNullRemoved;
  2931. } else {
  2932. link.href = "";
  2933. link.title = `Disabled: ${urlNullRemoved}`;
  2934. link.onclick = () => {
  2935. return false;
  2936. };
  2937. }
  2938. let targetStr = "";
  2939. switch (target) {
  2940. case LinkTarget.NONE:
  2941. break;
  2942. case LinkTarget.SELF:
  2943. targetStr = "_self";
  2944. break;
  2945. case LinkTarget.BLANK:
  2946. targetStr = "_blank";
  2947. break;
  2948. case LinkTarget.PARENT:
  2949. targetStr = "_parent";
  2950. break;
  2951. case LinkTarget.TOP:
  2952. targetStr = "_top";
  2953. break;
  2954. }
  2955. link.target = targetStr;
  2956. link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL;
  2957. }
  2958. function getFilenameFromUrl(url) {
  2959. const anchor = url.indexOf("#");
  2960. const query = url.indexOf("?");
  2961. const end = Math.min(anchor > 0 ? anchor : url.length, query > 0 ? query : url.length);
  2962. return url.substring(url.lastIndexOf("/", end) + 1, end);
  2963. }
  2964. class StatTimer {
  2965. constructor() {
  2966. this.started = Object.create(null);
  2967. this.times = [];
  2968. }
  2969. time(name) {
  2970. if (name in this.started) {
  2971. (0, _util.warn)(`Timer is already running for ${name}`);
  2972. }
  2973. this.started[name] = Date.now();
  2974. }
  2975. timeEnd(name) {
  2976. if (!(name in this.started)) {
  2977. (0, _util.warn)(`Timer has not been started for ${name}`);
  2978. }
  2979. this.times.push({
  2980. name,
  2981. start: this.started[name],
  2982. end: Date.now()
  2983. });
  2984. delete this.started[name];
  2985. }
  2986. toString() {
  2987. const outBuf = [];
  2988. let longest = 0;
  2989. for (const time of this.times) {
  2990. const name = time.name;
  2991. if (name.length > longest) {
  2992. longest = name.length;
  2993. }
  2994. }
  2995. for (const time of this.times) {
  2996. const duration = time.end - time.start;
  2997. outBuf.push(`${time.name.padEnd(longest)} ${duration}ms\n`);
  2998. }
  2999. return outBuf.join("");
  3000. }
  3001. }
  3002. exports.StatTimer = StatTimer;
  3003. function isFetchSupported() {
  3004. return typeof fetch !== "undefined" && typeof Response !== "undefined" && "body" in Response.prototype && typeof ReadableStream !== "undefined";
  3005. }
  3006. function isValidFetchUrl(url, baseUrl) {
  3007. try {
  3008. const {
  3009. protocol
  3010. } = baseUrl ? new URL(url, baseUrl) : new URL(url);
  3011. return protocol === "http:" || protocol === "https:";
  3012. } catch (ex) {
  3013. return false;
  3014. }
  3015. }
  3016. function loadScript(src) {
  3017. return new Promise((resolve, reject) => {
  3018. const script = document.createElement("script");
  3019. script.src = src;
  3020. script.onload = resolve;
  3021. script.onerror = function () {
  3022. reject(new Error(`Cannot load script at: ${script.src}`));
  3023. };
  3024. (document.head || document.documentElement).appendChild(script);
  3025. });
  3026. }
  3027. function deprecated(details) {
  3028. console.log("Deprecated API usage: " + details);
  3029. }
  3030. function releaseImageResources(img) {
  3031. (0, _util.assert)(img instanceof Image, "Invalid `img` parameter.");
  3032. const url = img.src;
  3033. if (typeof url === "string" && url.startsWith("blob:") && URL.revokeObjectURL) {
  3034. URL.revokeObjectURL(url);
  3035. }
  3036. img.removeAttribute("src");
  3037. }
  3038. let pdfDateStringRegex;
  3039. class PDFDateString {
  3040. static toDateObject(input) {
  3041. if (!input || !(0, _util.isString)(input)) {
  3042. return null;
  3043. }
  3044. if (!pdfDateStringRegex) {
  3045. pdfDateStringRegex = new RegExp("^D:" + "(\\d{4})" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "(\\d{2})?" + "([Z|+|-])?" + "(\\d{2})?" + "'?" + "(\\d{2})?" + "'?");
  3046. }
  3047. const matches = pdfDateStringRegex.exec(input);
  3048. if (!matches) {
  3049. return null;
  3050. }
  3051. const year = parseInt(matches[1], 10);
  3052. let month = parseInt(matches[2], 10);
  3053. month = month >= 1 && month <= 12 ? month - 1 : 0;
  3054. let day = parseInt(matches[3], 10);
  3055. day = day >= 1 && day <= 31 ? day : 1;
  3056. let hour = parseInt(matches[4], 10);
  3057. hour = hour >= 0 && hour <= 23 ? hour : 0;
  3058. let minute = parseInt(matches[5], 10);
  3059. minute = minute >= 0 && minute <= 59 ? minute : 0;
  3060. let second = parseInt(matches[6], 10);
  3061. second = second >= 0 && second <= 59 ? second : 0;
  3062. const universalTimeRelation = matches[7] || "Z";
  3063. let offsetHour = parseInt(matches[8], 10);
  3064. offsetHour = offsetHour >= 0 && offsetHour <= 23 ? offsetHour : 0;
  3065. let offsetMinute = parseInt(matches[9], 10) || 0;
  3066. offsetMinute = offsetMinute >= 0 && offsetMinute <= 59 ? offsetMinute : 0;
  3067. if (universalTimeRelation === "-") {
  3068. hour += offsetHour;
  3069. minute += offsetMinute;
  3070. } else if (universalTimeRelation === "+") {
  3071. hour -= offsetHour;
  3072. minute -= offsetMinute;
  3073. }
  3074. return new Date(Date.UTC(year, month, day, hour, minute, second));
  3075. }
  3076. }
  3077. exports.PDFDateString = PDFDateString;
  3078. /***/ }),
  3079. /* 5 */
  3080. /***/ (function(module, exports, __w_pdfjs_require__) {
  3081. "use strict";
  3082. Object.defineProperty(exports, "__esModule", {
  3083. value: true
  3084. });
  3085. exports.FontLoader = exports.FontFaceObject = void 0;
  3086. var _util = __w_pdfjs_require__(1);
  3087. class BaseFontLoader {
  3088. constructor({
  3089. docId,
  3090. onUnsupportedFeature
  3091. }) {
  3092. if (this.constructor === BaseFontLoader) {
  3093. (0, _util.unreachable)("Cannot initialize BaseFontLoader.");
  3094. }
  3095. this.docId = docId;
  3096. this._onUnsupportedFeature = onUnsupportedFeature;
  3097. this.nativeFontFaces = [];
  3098. this.styleElement = null;
  3099. }
  3100. addNativeFontFace(nativeFontFace) {
  3101. this.nativeFontFaces.push(nativeFontFace);
  3102. document.fonts.add(nativeFontFace);
  3103. }
  3104. insertRule(rule) {
  3105. let styleElement = this.styleElement;
  3106. if (!styleElement) {
  3107. styleElement = this.styleElement = document.createElement("style");
  3108. styleElement.id = `PDFJS_FONT_STYLE_TAG_${this.docId}`;
  3109. document.documentElement.getElementsByTagName("head")[0].appendChild(styleElement);
  3110. }
  3111. const styleSheet = styleElement.sheet;
  3112. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  3113. }
  3114. clear() {
  3115. this.nativeFontFaces.forEach(function (nativeFontFace) {
  3116. document.fonts.delete(nativeFontFace);
  3117. });
  3118. this.nativeFontFaces.length = 0;
  3119. if (this.styleElement) {
  3120. this.styleElement.remove();
  3121. this.styleElement = null;
  3122. }
  3123. }
  3124. async bind(font) {
  3125. if (font.attached || font.missingFile) {
  3126. return;
  3127. }
  3128. font.attached = true;
  3129. if (this.isFontLoadingAPISupported) {
  3130. const nativeFontFace = font.createNativeFontFace();
  3131. if (nativeFontFace) {
  3132. this.addNativeFontFace(nativeFontFace);
  3133. try {
  3134. await nativeFontFace.loaded;
  3135. } catch (ex) {
  3136. this._onUnsupportedFeature({
  3137. featureId: _util.UNSUPPORTED_FEATURES.font
  3138. });
  3139. (0, _util.warn)(`Failed to load font '${nativeFontFace.family}': '${ex}'.`);
  3140. font.disableFontFace = true;
  3141. throw ex;
  3142. }
  3143. }
  3144. return;
  3145. }
  3146. const rule = font.createFontFaceRule();
  3147. if (rule) {
  3148. this.insertRule(rule);
  3149. if (this.isSyncFontLoadingSupported) {
  3150. return;
  3151. }
  3152. await new Promise(resolve => {
  3153. const request = this._queueLoadingCallback(resolve);
  3154. this._prepareFontLoadEvent([rule], [font], request);
  3155. });
  3156. }
  3157. }
  3158. _queueLoadingCallback(callback) {
  3159. (0, _util.unreachable)("Abstract method `_queueLoadingCallback`.");
  3160. }
  3161. get isFontLoadingAPISupported() {
  3162. const supported = typeof document !== "undefined" && !!document.fonts;
  3163. return (0, _util.shadow)(this, "isFontLoadingAPISupported", supported);
  3164. }
  3165. get isSyncFontLoadingSupported() {
  3166. (0, _util.unreachable)("Abstract method `isSyncFontLoadingSupported`.");
  3167. }
  3168. get _loadTestFont() {
  3169. (0, _util.unreachable)("Abstract method `_loadTestFont`.");
  3170. }
  3171. _prepareFontLoadEvent(rules, fontsToLoad, request) {
  3172. (0, _util.unreachable)("Abstract method `_prepareFontLoadEvent`.");
  3173. }
  3174. }
  3175. let FontLoader;
  3176. exports.FontLoader = FontLoader;
  3177. {
  3178. exports.FontLoader = FontLoader = class GenericFontLoader extends BaseFontLoader {
  3179. constructor(docId) {
  3180. super(docId);
  3181. this.loadingContext = {
  3182. requests: [],
  3183. nextRequestId: 0
  3184. };
  3185. this.loadTestFontId = 0;
  3186. }
  3187. get isSyncFontLoadingSupported() {
  3188. let supported = false;
  3189. if (typeof navigator === "undefined") {
  3190. supported = true;
  3191. } else {
  3192. const m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(navigator.userAgent);
  3193. if (m && m[1] >= 14) {
  3194. supported = true;
  3195. }
  3196. }
  3197. return (0, _util.shadow)(this, "isSyncFontLoadingSupported", supported);
  3198. }
  3199. _queueLoadingCallback(callback) {
  3200. function completeRequest() {
  3201. (0, _util.assert)(!request.done, "completeRequest() cannot be called twice.");
  3202. request.done = true;
  3203. while (context.requests.length > 0 && context.requests[0].done) {
  3204. const otherRequest = context.requests.shift();
  3205. setTimeout(otherRequest.callback, 0);
  3206. }
  3207. }
  3208. const context = this.loadingContext;
  3209. const request = {
  3210. id: `pdfjs-font-loading-${context.nextRequestId++}`,
  3211. done: false,
  3212. complete: completeRequest,
  3213. callback
  3214. };
  3215. context.requests.push(request);
  3216. return request;
  3217. }
  3218. get _loadTestFont() {
  3219. const getLoadTestFont = function () {
  3220. return atob("T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQA" + "FQAABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAA" + "ALwAAAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgA" + "AAAGbmFtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1" + "AAsD6AAAAADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD" + "6AAAAAAD6AABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACM" + "AooCvAAAAeAAMQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4D" + "IP84AFoDIQAAAAAAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAA" + "AAEAAQAAAAEAAAAAAAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUA" + "AQAAAAEAAAAAAAYAAQAAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgAB" + "AAMAAQQJAAMAAgABAAMAAQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABY" + "AAAAAAAAAwAAAAMAAAAcAAEAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAA" + "AC7////TAAEAAAAAAAABBgAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAA" + "AAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgcA/gXBIwMAYuL+nz5tQXkD5j3CBLnEQAC" + "AQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYAAABAQAADwACAQEEE/t3" + "Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQAAAAAAAABAAAAAMmJbzEAAAAAzgTj" + "FQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAgABAAAAAAAAAAAD6AAAAAAAAA==");
  3221. };
  3222. return (0, _util.shadow)(this, "_loadTestFont", getLoadTestFont());
  3223. }
  3224. _prepareFontLoadEvent(rules, fonts, request) {
  3225. function int32(data, offset) {
  3226. return data.charCodeAt(offset) << 24 | data.charCodeAt(offset + 1) << 16 | data.charCodeAt(offset + 2) << 8 | data.charCodeAt(offset + 3) & 0xff;
  3227. }
  3228. function spliceString(s, offset, remove, insert) {
  3229. const chunk1 = s.substring(0, offset);
  3230. const chunk2 = s.substring(offset + remove);
  3231. return chunk1 + insert + chunk2;
  3232. }
  3233. let i, ii;
  3234. const canvas = document.createElement("canvas");
  3235. canvas.width = 1;
  3236. canvas.height = 1;
  3237. const ctx = canvas.getContext("2d");
  3238. let called = 0;
  3239. function isFontReady(name, callback) {
  3240. called++;
  3241. if (called > 30) {
  3242. (0, _util.warn)("Load test font never loaded.");
  3243. callback();
  3244. return;
  3245. }
  3246. ctx.font = "30px " + name;
  3247. ctx.fillText(".", 0, 20);
  3248. const imageData = ctx.getImageData(0, 0, 1, 1);
  3249. if (imageData.data[3] > 0) {
  3250. callback();
  3251. return;
  3252. }
  3253. setTimeout(isFontReady.bind(null, name, callback));
  3254. }
  3255. const loadTestFontId = `lt${Date.now()}${this.loadTestFontId++}`;
  3256. let data = this._loadTestFont;
  3257. const COMMENT_OFFSET = 976;
  3258. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length, loadTestFontId);
  3259. const CFF_CHECKSUM_OFFSET = 16;
  3260. const XXXX_VALUE = 0x58585858;
  3261. let checksum = int32(data, CFF_CHECKSUM_OFFSET);
  3262. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  3263. checksum = checksum - XXXX_VALUE + int32(loadTestFontId, i) | 0;
  3264. }
  3265. if (i < loadTestFontId.length) {
  3266. checksum = checksum - XXXX_VALUE + int32(loadTestFontId + "XXX", i) | 0;
  3267. }
  3268. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, (0, _util.string32)(checksum));
  3269. const url = `url(data:font/opentype;base64,${btoa(data)});`;
  3270. const rule = `@font-face {font-family:"${loadTestFontId}";src:${url}}`;
  3271. this.insertRule(rule);
  3272. const names = [];
  3273. for (i = 0, ii = fonts.length; i < ii; i++) {
  3274. names.push(fonts[i].loadedName);
  3275. }
  3276. names.push(loadTestFontId);
  3277. const div = document.createElement("div");
  3278. div.style.visibility = "hidden";
  3279. div.style.width = div.style.height = "10px";
  3280. div.style.position = "absolute";
  3281. div.style.top = div.style.left = "0px";
  3282. for (i = 0, ii = names.length; i < ii; ++i) {
  3283. const span = document.createElement("span");
  3284. span.textContent = "Hi";
  3285. span.style.fontFamily = names[i];
  3286. div.appendChild(span);
  3287. }
  3288. document.body.appendChild(div);
  3289. isFontReady(loadTestFontId, function () {
  3290. document.body.removeChild(div);
  3291. request.complete();
  3292. });
  3293. }
  3294. };
  3295. }
  3296. class FontFaceObject {
  3297. constructor(translatedData, {
  3298. isEvalSupported = true,
  3299. disableFontFace = false,
  3300. ignoreErrors = false,
  3301. onUnsupportedFeature = null,
  3302. fontRegistry = null
  3303. }) {
  3304. this.compiledGlyphs = Object.create(null);
  3305. for (const i in translatedData) {
  3306. this[i] = translatedData[i];
  3307. }
  3308. this.isEvalSupported = isEvalSupported !== false;
  3309. this.disableFontFace = disableFontFace === true;
  3310. this.ignoreErrors = ignoreErrors === true;
  3311. this._onUnsupportedFeature = onUnsupportedFeature;
  3312. this.fontRegistry = fontRegistry;
  3313. }
  3314. createNativeFontFace() {
  3315. if (!this.data || this.disableFontFace) {
  3316. return null;
  3317. }
  3318. const nativeFontFace = new FontFace(this.loadedName, this.data, {});
  3319. if (this.fontRegistry) {
  3320. this.fontRegistry.registerFont(this);
  3321. }
  3322. return nativeFontFace;
  3323. }
  3324. createFontFaceRule() {
  3325. if (!this.data || this.disableFontFace) {
  3326. return null;
  3327. }
  3328. const data = (0, _util.bytesToString)(new Uint8Array(this.data));
  3329. const url = `url(data:${this.mimetype};base64,${btoa(data)});`;
  3330. const rule = `@font-face {font-family:"${this.loadedName}";src:${url}}`;
  3331. if (this.fontRegistry) {
  3332. this.fontRegistry.registerFont(this, url);
  3333. }
  3334. return rule;
  3335. }
  3336. getPathGenerator(objs, character) {
  3337. if (this.compiledGlyphs[character] !== undefined) {
  3338. return this.compiledGlyphs[character];
  3339. }
  3340. let cmds, current;
  3341. try {
  3342. cmds = objs.get(this.loadedName + "_path_" + character);
  3343. } catch (ex) {
  3344. if (!this.ignoreErrors) {
  3345. throw ex;
  3346. }
  3347. if (this._onUnsupportedFeature) {
  3348. this._onUnsupportedFeature({
  3349. featureId: _util.UNSUPPORTED_FEATURES.font
  3350. });
  3351. }
  3352. (0, _util.warn)(`getPathGenerator - ignoring character: "${ex}".`);
  3353. return this.compiledGlyphs[character] = function (c, size) {};
  3354. }
  3355. if (this.isEvalSupported && _util.IsEvalSupportedCached.value) {
  3356. let args,
  3357. js = "";
  3358. for (let i = 0, ii = cmds.length; i < ii; i++) {
  3359. current = cmds[i];
  3360. if (current.args !== undefined) {
  3361. args = current.args.join(",");
  3362. } else {
  3363. args = "";
  3364. }
  3365. js += "c." + current.cmd + "(" + args + ");\n";
  3366. }
  3367. return this.compiledGlyphs[character] = new Function("c", "size", js);
  3368. }
  3369. return this.compiledGlyphs[character] = function (c, size) {
  3370. for (let i = 0, ii = cmds.length; i < ii; i++) {
  3371. current = cmds[i];
  3372. if (current.cmd === "scale") {
  3373. current.args = [size, -size];
  3374. }
  3375. c[current.cmd].apply(c, current.args);
  3376. }
  3377. };
  3378. }
  3379. }
  3380. exports.FontFaceObject = FontFaceObject;
  3381. /***/ }),
  3382. /* 6 */
  3383. /***/ (function(module, exports, __w_pdfjs_require__) {
  3384. "use strict";
  3385. const compatibilityParams = Object.create(null);
  3386. {
  3387. const {
  3388. isNodeJS
  3389. } = __w_pdfjs_require__(7);
  3390. const userAgent = typeof navigator !== "undefined" && navigator.userAgent || "";
  3391. const isIE = /Trident/.test(userAgent);
  3392. const isIOSChrome = /CriOS/.test(userAgent);
  3393. (function checkOnBlobSupport() {
  3394. if (isIE || isIOSChrome) {
  3395. compatibilityParams.disableCreateObjectURL = true;
  3396. }
  3397. })();
  3398. (function checkFontFaceAndImage() {
  3399. if (isNodeJS) {
  3400. compatibilityParams.disableFontFace = true;
  3401. compatibilityParams.nativeImageDecoderSupport = "none";
  3402. }
  3403. })();
  3404. }
  3405. exports.apiCompatibilityParams = Object.freeze(compatibilityParams);
  3406. /***/ }),
  3407. /* 7 */
  3408. /***/ (function(module, exports, __w_pdfjs_require__) {
  3409. "use strict";
  3410. Object.defineProperty(exports, "__esModule", {
  3411. value: true
  3412. });
  3413. exports.isNodeJS = void 0;
  3414. const isNodeJS = typeof process === "object" && process + "" === "[object process]" && !process.versions["nw"] && !process.versions["electron"];
  3415. exports.isNodeJS = isNodeJS;
  3416. /***/ }),
  3417. /* 8 */
  3418. /***/ (function(module, exports, __w_pdfjs_require__) {
  3419. "use strict";
  3420. Object.defineProperty(exports, "__esModule", {
  3421. value: true
  3422. });
  3423. exports.CanvasGraphics = void 0;
  3424. var _util = __w_pdfjs_require__(1);
  3425. var _pattern_helper = __w_pdfjs_require__(9);
  3426. var MIN_FONT_SIZE = 16;
  3427. var MAX_FONT_SIZE = 100;
  3428. var MAX_GROUP_SIZE = 4096;
  3429. var MIN_WIDTH_FACTOR = 0.65;
  3430. var COMPILE_TYPE3_GLYPHS = true;
  3431. var MAX_SIZE_TO_COMPILE = 1000;
  3432. var FULL_CHUNK_HEIGHT = 16;
  3433. function addContextCurrentTransform(ctx) {
  3434. if (!ctx.mozCurrentTransform) {
  3435. ctx._originalSave = ctx.save;
  3436. ctx._originalRestore = ctx.restore;
  3437. ctx._originalRotate = ctx.rotate;
  3438. ctx._originalScale = ctx.scale;
  3439. ctx._originalTranslate = ctx.translate;
  3440. ctx._originalTransform = ctx.transform;
  3441. ctx._originalSetTransform = ctx.setTransform;
  3442. ctx._transformMatrix = ctx._transformMatrix || [1, 0, 0, 1, 0, 0];
  3443. ctx._transformStack = [];
  3444. Object.defineProperty(ctx, "mozCurrentTransform", {
  3445. get: function getCurrentTransform() {
  3446. return this._transformMatrix;
  3447. }
  3448. });
  3449. Object.defineProperty(ctx, "mozCurrentTransformInverse", {
  3450. get: function getCurrentTransformInverse() {
  3451. var m = this._transformMatrix;
  3452. var a = m[0],
  3453. b = m[1],
  3454. c = m[2],
  3455. d = m[3],
  3456. e = m[4],
  3457. f = m[5];
  3458. var ad_bc = a * d - b * c;
  3459. var bc_ad = b * c - a * d;
  3460. return [d / ad_bc, b / bc_ad, c / bc_ad, a / ad_bc, (d * e - c * f) / bc_ad, (b * e - a * f) / ad_bc];
  3461. }
  3462. });
  3463. ctx.save = function ctxSave() {
  3464. var old = this._transformMatrix;
  3465. this._transformStack.push(old);
  3466. this._transformMatrix = old.slice(0, 6);
  3467. this._originalSave();
  3468. };
  3469. ctx.restore = function ctxRestore() {
  3470. var prev = this._transformStack.pop();
  3471. if (prev) {
  3472. this._transformMatrix = prev;
  3473. this._originalRestore();
  3474. }
  3475. };
  3476. ctx.translate = function ctxTranslate(x, y) {
  3477. var m = this._transformMatrix;
  3478. m[4] = m[0] * x + m[2] * y + m[4];
  3479. m[5] = m[1] * x + m[3] * y + m[5];
  3480. this._originalTranslate(x, y);
  3481. };
  3482. ctx.scale = function ctxScale(x, y) {
  3483. var m = this._transformMatrix;
  3484. m[0] = m[0] * x;
  3485. m[1] = m[1] * x;
  3486. m[2] = m[2] * y;
  3487. m[3] = m[3] * y;
  3488. this._originalScale(x, y);
  3489. };
  3490. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  3491. var m = this._transformMatrix;
  3492. this._transformMatrix = [m[0] * a + m[2] * b, m[1] * a + m[3] * b, m[0] * c + m[2] * d, m[1] * c + m[3] * d, m[0] * e + m[2] * f + m[4], m[1] * e + m[3] * f + m[5]];
  3493. ctx._originalTransform(a, b, c, d, e, f);
  3494. };
  3495. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  3496. this._transformMatrix = [a, b, c, d, e, f];
  3497. ctx._originalSetTransform(a, b, c, d, e, f);
  3498. };
  3499. ctx.rotate = function ctxRotate(angle) {
  3500. var cosValue = Math.cos(angle);
  3501. var sinValue = Math.sin(angle);
  3502. var m = this._transformMatrix;
  3503. this._transformMatrix = [m[0] * cosValue + m[2] * sinValue, m[1] * cosValue + m[3] * sinValue, m[0] * -sinValue + m[2] * cosValue, m[1] * -sinValue + m[3] * cosValue, m[4], m[5]];
  3504. this._originalRotate(angle);
  3505. };
  3506. }
  3507. }
  3508. var CachedCanvases = function CachedCanvasesClosure() {
  3509. function CachedCanvases(canvasFactory) {
  3510. this.canvasFactory = canvasFactory;
  3511. this.cache = Object.create(null);
  3512. }
  3513. CachedCanvases.prototype = {
  3514. getCanvas: function CachedCanvases_getCanvas(id, width, height, trackTransform) {
  3515. var canvasEntry;
  3516. if (this.cache[id] !== undefined) {
  3517. canvasEntry = this.cache[id];
  3518. this.canvasFactory.reset(canvasEntry, width, height);
  3519. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  3520. } else {
  3521. canvasEntry = this.canvasFactory.create(width, height);
  3522. this.cache[id] = canvasEntry;
  3523. }
  3524. if (trackTransform) {
  3525. addContextCurrentTransform(canvasEntry.context);
  3526. }
  3527. return canvasEntry;
  3528. },
  3529. clear() {
  3530. for (var id in this.cache) {
  3531. var canvasEntry = this.cache[id];
  3532. this.canvasFactory.destroy(canvasEntry);
  3533. delete this.cache[id];
  3534. }
  3535. }
  3536. };
  3537. return CachedCanvases;
  3538. }();
  3539. function compileType3Glyph(imgData) {
  3540. var POINT_TO_PROCESS_LIMIT = 1000;
  3541. var width = imgData.width,
  3542. height = imgData.height;
  3543. var i,
  3544. j,
  3545. j0,
  3546. width1 = width + 1;
  3547. var points = new Uint8Array(width1 * (height + 1));
  3548. var POINT_TYPES = new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  3549. var lineSize = width + 7 & ~7,
  3550. data0 = imgData.data;
  3551. var data = new Uint8Array(lineSize * height),
  3552. pos = 0,
  3553. ii;
  3554. for (i = 0, ii = data0.length; i < ii; i++) {
  3555. var mask = 128,
  3556. elem = data0[i];
  3557. while (mask > 0) {
  3558. data[pos++] = elem & mask ? 0 : 255;
  3559. mask >>= 1;
  3560. }
  3561. }
  3562. var count = 0;
  3563. pos = 0;
  3564. if (data[pos] !== 0) {
  3565. points[0] = 1;
  3566. ++count;
  3567. }
  3568. for (j = 1; j < width; j++) {
  3569. if (data[pos] !== data[pos + 1]) {
  3570. points[j] = data[pos] ? 2 : 1;
  3571. ++count;
  3572. }
  3573. pos++;
  3574. }
  3575. if (data[pos] !== 0) {
  3576. points[j] = 2;
  3577. ++count;
  3578. }
  3579. for (i = 1; i < height; i++) {
  3580. pos = i * lineSize;
  3581. j0 = i * width1;
  3582. if (data[pos - lineSize] !== data[pos]) {
  3583. points[j0] = data[pos] ? 1 : 8;
  3584. ++count;
  3585. }
  3586. var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  3587. for (j = 1; j < width; j++) {
  3588. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) + (data[pos - lineSize + 1] ? 8 : 0);
  3589. if (POINT_TYPES[sum]) {
  3590. points[j0 + j] = POINT_TYPES[sum];
  3591. ++count;
  3592. }
  3593. pos++;
  3594. }
  3595. if (data[pos - lineSize] !== data[pos]) {
  3596. points[j0 + j] = data[pos] ? 2 : 4;
  3597. ++count;
  3598. }
  3599. if (count > POINT_TO_PROCESS_LIMIT) {
  3600. return null;
  3601. }
  3602. }
  3603. pos = lineSize * (height - 1);
  3604. j0 = i * width1;
  3605. if (data[pos] !== 0) {
  3606. points[j0] = 8;
  3607. ++count;
  3608. }
  3609. for (j = 1; j < width; j++) {
  3610. if (data[pos] !== data[pos + 1]) {
  3611. points[j0 + j] = data[pos] ? 4 : 8;
  3612. ++count;
  3613. }
  3614. pos++;
  3615. }
  3616. if (data[pos] !== 0) {
  3617. points[j0 + j] = 4;
  3618. ++count;
  3619. }
  3620. if (count > POINT_TO_PROCESS_LIMIT) {
  3621. return null;
  3622. }
  3623. var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  3624. var outlines = [];
  3625. for (i = 0; count && i <= height; i++) {
  3626. var p = i * width1;
  3627. var end = p + width;
  3628. while (p < end && !points[p]) {
  3629. p++;
  3630. }
  3631. if (p === end) {
  3632. continue;
  3633. }
  3634. var coords = [p % width1, i];
  3635. var type = points[p],
  3636. p0 = p,
  3637. pp;
  3638. do {
  3639. var step = steps[type];
  3640. do {
  3641. p += step;
  3642. } while (!points[p]);
  3643. pp = points[p];
  3644. if (pp !== 5 && pp !== 10) {
  3645. type = pp;
  3646. points[p] = 0;
  3647. } else {
  3648. type = pp & 0x33 * type >> 4;
  3649. points[p] &= type >> 2 | type << 2;
  3650. }
  3651. coords.push(p % width1);
  3652. coords.push(p / width1 | 0);
  3653. if (!points[p]) {
  3654. --count;
  3655. }
  3656. } while (p0 !== p);
  3657. outlines.push(coords);
  3658. --i;
  3659. }
  3660. var drawOutline = function (c) {
  3661. c.save();
  3662. c.scale(1 / width, -1 / height);
  3663. c.translate(0, -height);
  3664. c.beginPath();
  3665. for (var i = 0, ii = outlines.length; i < ii; i++) {
  3666. var o = outlines[i];
  3667. c.moveTo(o[0], o[1]);
  3668. for (var j = 2, jj = o.length; j < jj; j += 2) {
  3669. c.lineTo(o[j], o[j + 1]);
  3670. }
  3671. }
  3672. c.fill();
  3673. c.beginPath();
  3674. c.restore();
  3675. };
  3676. return drawOutline;
  3677. }
  3678. var CanvasExtraState = function CanvasExtraStateClosure() {
  3679. function CanvasExtraState() {
  3680. this.alphaIsShape = false;
  3681. this.fontSize = 0;
  3682. this.fontSizeScale = 1;
  3683. this.textMatrix = _util.IDENTITY_MATRIX;
  3684. this.textMatrixScale = 1;
  3685. this.fontMatrix = _util.FONT_IDENTITY_MATRIX;
  3686. this.leading = 0;
  3687. this.x = 0;
  3688. this.y = 0;
  3689. this.lineX = 0;
  3690. this.lineY = 0;
  3691. this.charSpacing = 0;
  3692. this.wordSpacing = 0;
  3693. this.textHScale = 1;
  3694. this.textRenderingMode = _util.TextRenderingMode.FILL;
  3695. this.textRise = 0;
  3696. this.fillColor = "#000000";
  3697. this.strokeColor = "#000000";
  3698. this.patternFill = false;
  3699. this.fillAlpha = 1;
  3700. this.strokeAlpha = 1;
  3701. this.lineWidth = 1;
  3702. this.activeSMask = null;
  3703. this.resumeSMaskCtx = null;
  3704. }
  3705. CanvasExtraState.prototype = {
  3706. clone: function CanvasExtraState_clone() {
  3707. return Object.create(this);
  3708. },
  3709. setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
  3710. this.x = x;
  3711. this.y = y;
  3712. }
  3713. };
  3714. return CanvasExtraState;
  3715. }();
  3716. var CanvasGraphics = function CanvasGraphicsClosure() {
  3717. var EXECUTION_TIME = 15;
  3718. var EXECUTION_STEPS = 10;
  3719. function CanvasGraphics(canvasCtx, commonObjs, objs, canvasFactory, webGLContext, imageLayer) {
  3720. this.ctx = canvasCtx;
  3721. this.current = new CanvasExtraState();
  3722. this.stateStack = [];
  3723. this.pendingClip = null;
  3724. this.pendingEOFill = false;
  3725. this.res = null;
  3726. this.xobjs = null;
  3727. this.commonObjs = commonObjs;
  3728. this.objs = objs;
  3729. this.canvasFactory = canvasFactory;
  3730. this.webGLContext = webGLContext;
  3731. this.imageLayer = imageLayer;
  3732. this.groupStack = [];
  3733. this.processingType3 = null;
  3734. this.baseTransform = null;
  3735. this.baseTransformStack = [];
  3736. this.groupLevel = 0;
  3737. this.smaskStack = [];
  3738. this.smaskCounter = 0;
  3739. this.tempSMask = null;
  3740. this.cachedCanvases = new CachedCanvases(this.canvasFactory);
  3741. if (canvasCtx) {
  3742. addContextCurrentTransform(canvasCtx);
  3743. }
  3744. this._cachedGetSinglePixelWidth = null;
  3745. }
  3746. function putBinaryImageData(ctx, imgData) {
  3747. if (typeof ImageData !== "undefined" && imgData instanceof ImageData) {
  3748. ctx.putImageData(imgData, 0, 0);
  3749. return;
  3750. }
  3751. var height = imgData.height,
  3752. width = imgData.width;
  3753. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  3754. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  3755. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  3756. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  3757. var srcPos = 0,
  3758. destPos;
  3759. var src = imgData.data;
  3760. var dest = chunkImgData.data;
  3761. var i, j, thisChunkHeight, elemsInThisChunk;
  3762. if (imgData.kind === _util.ImageKind.GRAYSCALE_1BPP) {
  3763. var srcLength = src.byteLength;
  3764. var dest32 = new Uint32Array(dest.buffer, 0, dest.byteLength >> 2);
  3765. var dest32DataLength = dest32.length;
  3766. var fullSrcDiff = width + 7 >> 3;
  3767. var white = 0xffffffff;
  3768. var black = _util.IsLittleEndianCached.value ? 0xff000000 : 0x000000ff;
  3769. for (i = 0; i < totalChunks; i++) {
  3770. thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  3771. destPos = 0;
  3772. for (j = 0; j < thisChunkHeight; j++) {
  3773. var srcDiff = srcLength - srcPos;
  3774. var k = 0;
  3775. var kEnd = srcDiff > fullSrcDiff ? width : srcDiff * 8 - 7;
  3776. var kEndUnrolled = kEnd & ~7;
  3777. var mask = 0;
  3778. var srcByte = 0;
  3779. for (; k < kEndUnrolled; k += 8) {
  3780. srcByte = src[srcPos++];
  3781. dest32[destPos++] = srcByte & 128 ? white : black;
  3782. dest32[destPos++] = srcByte & 64 ? white : black;
  3783. dest32[destPos++] = srcByte & 32 ? white : black;
  3784. dest32[destPos++] = srcByte & 16 ? white : black;
  3785. dest32[destPos++] = srcByte & 8 ? white : black;
  3786. dest32[destPos++] = srcByte & 4 ? white : black;
  3787. dest32[destPos++] = srcByte & 2 ? white : black;
  3788. dest32[destPos++] = srcByte & 1 ? white : black;
  3789. }
  3790. for (; k < kEnd; k++) {
  3791. if (mask === 0) {
  3792. srcByte = src[srcPos++];
  3793. mask = 128;
  3794. }
  3795. dest32[destPos++] = srcByte & mask ? white : black;
  3796. mask >>= 1;
  3797. }
  3798. }
  3799. while (destPos < dest32DataLength) {
  3800. dest32[destPos++] = 0;
  3801. }
  3802. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  3803. }
  3804. } else if (imgData.kind === _util.ImageKind.RGBA_32BPP) {
  3805. j = 0;
  3806. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  3807. for (i = 0; i < fullChunks; i++) {
  3808. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  3809. srcPos += elemsInThisChunk;
  3810. ctx.putImageData(chunkImgData, 0, j);
  3811. j += FULL_CHUNK_HEIGHT;
  3812. }
  3813. if (i < totalChunks) {
  3814. elemsInThisChunk = width * partialChunkHeight * 4;
  3815. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  3816. ctx.putImageData(chunkImgData, 0, j);
  3817. }
  3818. } else if (imgData.kind === _util.ImageKind.RGB_24BPP) {
  3819. thisChunkHeight = FULL_CHUNK_HEIGHT;
  3820. elemsInThisChunk = width * thisChunkHeight;
  3821. for (i = 0; i < totalChunks; i++) {
  3822. if (i >= fullChunks) {
  3823. thisChunkHeight = partialChunkHeight;
  3824. elemsInThisChunk = width * thisChunkHeight;
  3825. }
  3826. destPos = 0;
  3827. for (j = elemsInThisChunk; j--;) {
  3828. dest[destPos++] = src[srcPos++];
  3829. dest[destPos++] = src[srcPos++];
  3830. dest[destPos++] = src[srcPos++];
  3831. dest[destPos++] = 255;
  3832. }
  3833. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  3834. }
  3835. } else {
  3836. throw new Error(`bad image kind: ${imgData.kind}`);
  3837. }
  3838. }
  3839. function putBinaryImageMask(ctx, imgData) {
  3840. var height = imgData.height,
  3841. width = imgData.width;
  3842. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  3843. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  3844. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  3845. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  3846. var srcPos = 0;
  3847. var src = imgData.data;
  3848. var dest = chunkImgData.data;
  3849. for (var i = 0; i < totalChunks; i++) {
  3850. var thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  3851. var destPos = 3;
  3852. for (var j = 0; j < thisChunkHeight; j++) {
  3853. var mask = 0;
  3854. for (var k = 0; k < width; k++) {
  3855. if (!mask) {
  3856. var elem = src[srcPos++];
  3857. mask = 128;
  3858. }
  3859. dest[destPos] = elem & mask ? 0 : 255;
  3860. destPos += 4;
  3861. mask >>= 1;
  3862. }
  3863. }
  3864. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  3865. }
  3866. }
  3867. function copyCtxState(sourceCtx, destCtx) {
  3868. var properties = ["strokeStyle", "fillStyle", "fillRule", "globalAlpha", "lineWidth", "lineCap", "lineJoin", "miterLimit", "globalCompositeOperation", "font"];
  3869. for (var i = 0, ii = properties.length; i < ii; i++) {
  3870. var property = properties[i];
  3871. if (sourceCtx[property] !== undefined) {
  3872. destCtx[property] = sourceCtx[property];
  3873. }
  3874. }
  3875. if (sourceCtx.setLineDash !== undefined) {
  3876. destCtx.setLineDash(sourceCtx.getLineDash());
  3877. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  3878. }
  3879. }
  3880. function resetCtxToDefault(ctx) {
  3881. ctx.strokeStyle = "#000000";
  3882. ctx.fillStyle = "#000000";
  3883. ctx.fillRule = "nonzero";
  3884. ctx.globalAlpha = 1;
  3885. ctx.lineWidth = 1;
  3886. ctx.lineCap = "butt";
  3887. ctx.lineJoin = "miter";
  3888. ctx.miterLimit = 10;
  3889. ctx.globalCompositeOperation = "source-over";
  3890. ctx.font = "10px sans-serif";
  3891. if (ctx.setLineDash !== undefined) {
  3892. ctx.setLineDash([]);
  3893. ctx.lineDashOffset = 0;
  3894. }
  3895. }
  3896. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  3897. var length = bytes.length;
  3898. for (var i = 3; i < length; i += 4) {
  3899. var alpha = bytes[i];
  3900. if (alpha === 0) {
  3901. bytes[i - 3] = r0;
  3902. bytes[i - 2] = g0;
  3903. bytes[i - 1] = b0;
  3904. } else if (alpha < 255) {
  3905. var alpha_ = 255 - alpha;
  3906. bytes[i - 3] = bytes[i - 3] * alpha + r0 * alpha_ >> 8;
  3907. bytes[i - 2] = bytes[i - 2] * alpha + g0 * alpha_ >> 8;
  3908. bytes[i - 1] = bytes[i - 1] * alpha + b0 * alpha_ >> 8;
  3909. }
  3910. }
  3911. }
  3912. function composeSMaskAlpha(maskData, layerData, transferMap) {
  3913. var length = maskData.length;
  3914. var scale = 1 / 255;
  3915. for (var i = 3; i < length; i += 4) {
  3916. var alpha = transferMap ? transferMap[maskData[i]] : maskData[i];
  3917. layerData[i] = layerData[i] * alpha * scale | 0;
  3918. }
  3919. }
  3920. function composeSMaskLuminosity(maskData, layerData, transferMap) {
  3921. var length = maskData.length;
  3922. for (var i = 3; i < length; i += 4) {
  3923. var y = maskData[i - 3] * 77 + maskData[i - 2] * 152 + maskData[i - 1] * 28;
  3924. layerData[i] = transferMap ? layerData[i] * transferMap[y >> 8] >> 8 : layerData[i] * y >> 16;
  3925. }
  3926. }
  3927. function genericComposeSMask(maskCtx, layerCtx, width, height, subtype, backdrop, transferMap) {
  3928. var hasBackdrop = !!backdrop;
  3929. var r0 = hasBackdrop ? backdrop[0] : 0;
  3930. var g0 = hasBackdrop ? backdrop[1] : 0;
  3931. var b0 = hasBackdrop ? backdrop[2] : 0;
  3932. var composeFn;
  3933. if (subtype === "Luminosity") {
  3934. composeFn = composeSMaskLuminosity;
  3935. } else {
  3936. composeFn = composeSMaskAlpha;
  3937. }
  3938. var PIXELS_TO_PROCESS = 1048576;
  3939. var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  3940. for (var row = 0; row < height; row += chunkSize) {
  3941. var chunkHeight = Math.min(chunkSize, height - row);
  3942. var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
  3943. var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
  3944. if (hasBackdrop) {
  3945. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  3946. }
  3947. composeFn(maskData.data, layerData.data, transferMap);
  3948. maskCtx.putImageData(layerData, 0, row);
  3949. }
  3950. }
  3951. function composeSMask(ctx, smask, layerCtx, webGLContext) {
  3952. var mask = smask.canvas;
  3953. var maskCtx = smask.context;
  3954. ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY, smask.offsetX, smask.offsetY);
  3955. var backdrop = smask.backdrop || null;
  3956. if (!smask.transferMap && webGLContext.isEnabled) {
  3957. const composed = webGLContext.composeSMask({
  3958. layer: layerCtx.canvas,
  3959. mask,
  3960. properties: {
  3961. subtype: smask.subtype,
  3962. backdrop
  3963. }
  3964. });
  3965. ctx.setTransform(1, 0, 0, 1, 0, 0);
  3966. ctx.drawImage(composed, smask.offsetX, smask.offsetY);
  3967. return;
  3968. }
  3969. genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height, smask.subtype, backdrop, smask.transferMap);
  3970. ctx.drawImage(mask, 0, 0);
  3971. }
  3972. var LINE_CAP_STYLES = ["butt", "round", "square"];
  3973. var LINE_JOIN_STYLES = ["miter", "round", "bevel"];
  3974. var NORMAL_CLIP = {};
  3975. var EO_CLIP = {};
  3976. CanvasGraphics.prototype = {
  3977. beginDrawing({
  3978. transform,
  3979. viewport,
  3980. transparency = false,
  3981. background = null
  3982. }) {
  3983. var width = this.ctx.canvas.width;
  3984. var height = this.ctx.canvas.height;
  3985. this.ctx.save();
  3986. this.ctx.fillStyle = background || "rgb(255, 255, 255)";
  3987. this.ctx.fillRect(0, 0, width, height);
  3988. this.ctx.restore();
  3989. if (transparency) {
  3990. var transparentCanvas = this.cachedCanvases.getCanvas("transparent", width, height, true);
  3991. this.compositeCtx = this.ctx;
  3992. this.transparentCanvas = transparentCanvas.canvas;
  3993. this.ctx = transparentCanvas.context;
  3994. this.ctx.save();
  3995. this.ctx.transform.apply(this.ctx, this.compositeCtx.mozCurrentTransform);
  3996. }
  3997. this.ctx.save();
  3998. resetCtxToDefault(this.ctx);
  3999. if (transform) {
  4000. this.ctx.transform.apply(this.ctx, transform);
  4001. }
  4002. this.ctx.transform.apply(this.ctx, viewport.transform);
  4003. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  4004. if (this.imageLayer) {
  4005. this.imageLayer.beginLayout();
  4006. }
  4007. },
  4008. executeOperatorList: function CanvasGraphics_executeOperatorList(operatorList, executionStartIdx, continueCallback, stepper) {
  4009. var argsArray = operatorList.argsArray;
  4010. var fnArray = operatorList.fnArray;
  4011. var i = executionStartIdx || 0;
  4012. var argsArrayLen = argsArray.length;
  4013. if (argsArrayLen === i) {
  4014. return i;
  4015. }
  4016. var chunkOperations = argsArrayLen - i > EXECUTION_STEPS && typeof continueCallback === "function";
  4017. var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  4018. var steps = 0;
  4019. var commonObjs = this.commonObjs;
  4020. var objs = this.objs;
  4021. var fnId;
  4022. while (true) {
  4023. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  4024. stepper.breakIt(i, continueCallback);
  4025. return i;
  4026. }
  4027. fnId = fnArray[i];
  4028. if (fnId !== _util.OPS.dependency) {
  4029. this[fnId].apply(this, argsArray[i]);
  4030. } else {
  4031. for (const depObjId of argsArray[i]) {
  4032. const objsPool = depObjId.startsWith("g_") ? commonObjs : objs;
  4033. if (!objsPool.has(depObjId)) {
  4034. objsPool.get(depObjId, continueCallback);
  4035. return i;
  4036. }
  4037. }
  4038. }
  4039. i++;
  4040. if (i === argsArrayLen) {
  4041. return i;
  4042. }
  4043. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  4044. if (Date.now() > endTime) {
  4045. continueCallback();
  4046. return i;
  4047. }
  4048. steps = 0;
  4049. }
  4050. }
  4051. },
  4052. endDrawing: function CanvasGraphics_endDrawing() {
  4053. if (this.current.activeSMask !== null) {
  4054. this.endSMaskGroup();
  4055. }
  4056. this.ctx.restore();
  4057. if (this.transparentCanvas) {
  4058. this.ctx = this.compositeCtx;
  4059. this.ctx.save();
  4060. this.ctx.setTransform(1, 0, 0, 1, 0, 0);
  4061. this.ctx.drawImage(this.transparentCanvas, 0, 0);
  4062. this.ctx.restore();
  4063. this.transparentCanvas = null;
  4064. }
  4065. this.cachedCanvases.clear();
  4066. this.webGLContext.clear();
  4067. if (this.imageLayer) {
  4068. this.imageLayer.endLayout();
  4069. }
  4070. },
  4071. setLineWidth: function CanvasGraphics_setLineWidth(width) {
  4072. this.current.lineWidth = width;
  4073. this.ctx.lineWidth = width;
  4074. },
  4075. setLineCap: function CanvasGraphics_setLineCap(style) {
  4076. this.ctx.lineCap = LINE_CAP_STYLES[style];
  4077. },
  4078. setLineJoin: function CanvasGraphics_setLineJoin(style) {
  4079. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  4080. },
  4081. setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
  4082. this.ctx.miterLimit = limit;
  4083. },
  4084. setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
  4085. var ctx = this.ctx;
  4086. if (ctx.setLineDash !== undefined) {
  4087. ctx.setLineDash(dashArray);
  4088. ctx.lineDashOffset = dashPhase;
  4089. }
  4090. },
  4091. setRenderingIntent(intent) {},
  4092. setFlatness(flatness) {},
  4093. setGState: function CanvasGraphics_setGState(states) {
  4094. for (var i = 0, ii = states.length; i < ii; i++) {
  4095. var state = states[i];
  4096. var key = state[0];
  4097. var value = state[1];
  4098. switch (key) {
  4099. case "LW":
  4100. this.setLineWidth(value);
  4101. break;
  4102. case "LC":
  4103. this.setLineCap(value);
  4104. break;
  4105. case "LJ":
  4106. this.setLineJoin(value);
  4107. break;
  4108. case "ML":
  4109. this.setMiterLimit(value);
  4110. break;
  4111. case "D":
  4112. this.setDash(value[0], value[1]);
  4113. break;
  4114. case "RI":
  4115. this.setRenderingIntent(value);
  4116. break;
  4117. case "FL":
  4118. this.setFlatness(value);
  4119. break;
  4120. case "Font":
  4121. this.setFont(value[0], value[1]);
  4122. break;
  4123. case "CA":
  4124. this.current.strokeAlpha = state[1];
  4125. break;
  4126. case "ca":
  4127. this.current.fillAlpha = state[1];
  4128. this.ctx.globalAlpha = state[1];
  4129. break;
  4130. case "BM":
  4131. this.ctx.globalCompositeOperation = value;
  4132. break;
  4133. case "SMask":
  4134. if (this.current.activeSMask) {
  4135. if (this.stateStack.length > 0 && this.stateStack[this.stateStack.length - 1].activeSMask === this.current.activeSMask) {
  4136. this.suspendSMaskGroup();
  4137. } else {
  4138. this.endSMaskGroup();
  4139. }
  4140. }
  4141. this.current.activeSMask = value ? this.tempSMask : null;
  4142. if (this.current.activeSMask) {
  4143. this.beginSMaskGroup();
  4144. }
  4145. this.tempSMask = null;
  4146. break;
  4147. }
  4148. }
  4149. },
  4150. beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
  4151. var activeSMask = this.current.activeSMask;
  4152. var drawnWidth = activeSMask.canvas.width;
  4153. var drawnHeight = activeSMask.canvas.height;
  4154. var cacheId = "smaskGroupAt" + this.groupLevel;
  4155. var scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight, true);
  4156. var currentCtx = this.ctx;
  4157. var currentTransform = currentCtx.mozCurrentTransform;
  4158. this.ctx.save();
  4159. var groupCtx = scratchCanvas.context;
  4160. groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
  4161. groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
  4162. groupCtx.transform.apply(groupCtx, currentTransform);
  4163. activeSMask.startTransformInverse = groupCtx.mozCurrentTransformInverse;
  4164. copyCtxState(currentCtx, groupCtx);
  4165. this.ctx = groupCtx;
  4166. this.setGState([["BM", "source-over"], ["ca", 1], ["CA", 1]]);
  4167. this.groupStack.push(currentCtx);
  4168. this.groupLevel++;
  4169. },
  4170. suspendSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  4171. var groupCtx = this.ctx;
  4172. this.groupLevel--;
  4173. this.ctx = this.groupStack.pop();
  4174. composeSMask(this.ctx, this.current.activeSMask, groupCtx, this.webGLContext);
  4175. this.ctx.restore();
  4176. this.ctx.save();
  4177. copyCtxState(groupCtx, this.ctx);
  4178. this.current.resumeSMaskCtx = groupCtx;
  4179. var deltaTransform = _util.Util.transform(this.current.activeSMask.startTransformInverse, groupCtx.mozCurrentTransform);
  4180. this.ctx.transform.apply(this.ctx, deltaTransform);
  4181. groupCtx.save();
  4182. groupCtx.setTransform(1, 0, 0, 1, 0, 0);
  4183. groupCtx.clearRect(0, 0, groupCtx.canvas.width, groupCtx.canvas.height);
  4184. groupCtx.restore();
  4185. },
  4186. resumeSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  4187. var groupCtx = this.current.resumeSMaskCtx;
  4188. var currentCtx = this.ctx;
  4189. this.ctx = groupCtx;
  4190. this.groupStack.push(currentCtx);
  4191. this.groupLevel++;
  4192. },
  4193. endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  4194. var groupCtx = this.ctx;
  4195. this.groupLevel--;
  4196. this.ctx = this.groupStack.pop();
  4197. composeSMask(this.ctx, this.current.activeSMask, groupCtx, this.webGLContext);
  4198. this.ctx.restore();
  4199. copyCtxState(groupCtx, this.ctx);
  4200. var deltaTransform = _util.Util.transform(this.current.activeSMask.startTransformInverse, groupCtx.mozCurrentTransform);
  4201. this.ctx.transform.apply(this.ctx, deltaTransform);
  4202. },
  4203. save: function CanvasGraphics_save() {
  4204. this.ctx.save();
  4205. var old = this.current;
  4206. this.stateStack.push(old);
  4207. this.current = old.clone();
  4208. this.current.resumeSMaskCtx = null;
  4209. },
  4210. restore: function CanvasGraphics_restore() {
  4211. if (this.current.resumeSMaskCtx) {
  4212. this.resumeSMaskGroup();
  4213. }
  4214. if (this.current.activeSMask !== null && (this.stateStack.length === 0 || this.stateStack[this.stateStack.length - 1].activeSMask !== this.current.activeSMask)) {
  4215. this.endSMaskGroup();
  4216. }
  4217. if (this.stateStack.length !== 0) {
  4218. this.current = this.stateStack.pop();
  4219. this.ctx.restore();
  4220. this.pendingClip = null;
  4221. this._cachedGetSinglePixelWidth = null;
  4222. }
  4223. },
  4224. transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
  4225. this.ctx.transform(a, b, c, d, e, f);
  4226. this._cachedGetSinglePixelWidth = null;
  4227. },
  4228. constructPath: function CanvasGraphics_constructPath(ops, args) {
  4229. var ctx = this.ctx;
  4230. var current = this.current;
  4231. var x = current.x,
  4232. y = current.y;
  4233. for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
  4234. switch (ops[i] | 0) {
  4235. case _util.OPS.rectangle:
  4236. x = args[j++];
  4237. y = args[j++];
  4238. var width = args[j++];
  4239. var height = args[j++];
  4240. if (width === 0) {
  4241. width = this.getSinglePixelWidth();
  4242. }
  4243. if (height === 0) {
  4244. height = this.getSinglePixelWidth();
  4245. }
  4246. var xw = x + width;
  4247. var yh = y + height;
  4248. this.ctx.moveTo(x, y);
  4249. this.ctx.lineTo(xw, y);
  4250. this.ctx.lineTo(xw, yh);
  4251. this.ctx.lineTo(x, yh);
  4252. this.ctx.lineTo(x, y);
  4253. this.ctx.closePath();
  4254. break;
  4255. case _util.OPS.moveTo:
  4256. x = args[j++];
  4257. y = args[j++];
  4258. ctx.moveTo(x, y);
  4259. break;
  4260. case _util.OPS.lineTo:
  4261. x = args[j++];
  4262. y = args[j++];
  4263. ctx.lineTo(x, y);
  4264. break;
  4265. case _util.OPS.curveTo:
  4266. x = args[j + 4];
  4267. y = args[j + 5];
  4268. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3], x, y);
  4269. j += 6;
  4270. break;
  4271. case _util.OPS.curveTo2:
  4272. ctx.bezierCurveTo(x, y, args[j], args[j + 1], args[j + 2], args[j + 3]);
  4273. x = args[j + 2];
  4274. y = args[j + 3];
  4275. j += 4;
  4276. break;
  4277. case _util.OPS.curveTo3:
  4278. x = args[j + 2];
  4279. y = args[j + 3];
  4280. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  4281. j += 4;
  4282. break;
  4283. case _util.OPS.closePath:
  4284. ctx.closePath();
  4285. break;
  4286. }
  4287. }
  4288. current.setCurrentPoint(x, y);
  4289. },
  4290. closePath: function CanvasGraphics_closePath() {
  4291. this.ctx.closePath();
  4292. },
  4293. stroke: function CanvasGraphics_stroke(consumePath) {
  4294. consumePath = typeof consumePath !== "undefined" ? consumePath : true;
  4295. var ctx = this.ctx;
  4296. var strokeColor = this.current.strokeColor;
  4297. ctx.globalAlpha = this.current.strokeAlpha;
  4298. if (strokeColor && strokeColor.hasOwnProperty("type") && strokeColor.type === "Pattern") {
  4299. ctx.save();
  4300. const transform = ctx.mozCurrentTransform;
  4301. const scale = _util.Util.singularValueDecompose2dScale(transform)[0];
  4302. ctx.strokeStyle = strokeColor.getPattern(ctx, this);
  4303. ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR, this.current.lineWidth * scale);
  4304. ctx.stroke();
  4305. ctx.restore();
  4306. } else {
  4307. ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR, this.current.lineWidth);
  4308. ctx.stroke();
  4309. }
  4310. if (consumePath) {
  4311. this.consumePath();
  4312. }
  4313. ctx.globalAlpha = this.current.fillAlpha;
  4314. },
  4315. closeStroke: function CanvasGraphics_closeStroke() {
  4316. this.closePath();
  4317. this.stroke();
  4318. },
  4319. fill: function CanvasGraphics_fill(consumePath) {
  4320. consumePath = typeof consumePath !== "undefined" ? consumePath : true;
  4321. var ctx = this.ctx;
  4322. var fillColor = this.current.fillColor;
  4323. var isPatternFill = this.current.patternFill;
  4324. var needRestore = false;
  4325. if (isPatternFill) {
  4326. ctx.save();
  4327. if (this.baseTransform) {
  4328. ctx.setTransform.apply(ctx, this.baseTransform);
  4329. }
  4330. ctx.fillStyle = fillColor.getPattern(ctx, this);
  4331. needRestore = true;
  4332. }
  4333. if (this.pendingEOFill) {
  4334. ctx.fill("evenodd");
  4335. this.pendingEOFill = false;
  4336. } else {
  4337. ctx.fill();
  4338. }
  4339. if (needRestore) {
  4340. ctx.restore();
  4341. }
  4342. if (consumePath) {
  4343. this.consumePath();
  4344. }
  4345. },
  4346. eoFill: function CanvasGraphics_eoFill() {
  4347. this.pendingEOFill = true;
  4348. this.fill();
  4349. },
  4350. fillStroke: function CanvasGraphics_fillStroke() {
  4351. this.fill(false);
  4352. this.stroke(false);
  4353. this.consumePath();
  4354. },
  4355. eoFillStroke: function CanvasGraphics_eoFillStroke() {
  4356. this.pendingEOFill = true;
  4357. this.fillStroke();
  4358. },
  4359. closeFillStroke: function CanvasGraphics_closeFillStroke() {
  4360. this.closePath();
  4361. this.fillStroke();
  4362. },
  4363. closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
  4364. this.pendingEOFill = true;
  4365. this.closePath();
  4366. this.fillStroke();
  4367. },
  4368. endPath: function CanvasGraphics_endPath() {
  4369. this.consumePath();
  4370. },
  4371. clip: function CanvasGraphics_clip() {
  4372. this.pendingClip = NORMAL_CLIP;
  4373. },
  4374. eoClip: function CanvasGraphics_eoClip() {
  4375. this.pendingClip = EO_CLIP;
  4376. },
  4377. beginText: function CanvasGraphics_beginText() {
  4378. this.current.textMatrix = _util.IDENTITY_MATRIX;
  4379. this.current.textMatrixScale = 1;
  4380. this.current.x = this.current.lineX = 0;
  4381. this.current.y = this.current.lineY = 0;
  4382. },
  4383. endText: function CanvasGraphics_endText() {
  4384. var paths = this.pendingTextPaths;
  4385. var ctx = this.ctx;
  4386. if (paths === undefined) {
  4387. ctx.beginPath();
  4388. return;
  4389. }
  4390. ctx.save();
  4391. ctx.beginPath();
  4392. for (var i = 0; i < paths.length; i++) {
  4393. var path = paths[i];
  4394. ctx.setTransform.apply(ctx, path.transform);
  4395. ctx.translate(path.x, path.y);
  4396. path.addToPath(ctx, path.fontSize);
  4397. }
  4398. ctx.restore();
  4399. ctx.clip();
  4400. ctx.beginPath();
  4401. delete this.pendingTextPaths;
  4402. },
  4403. setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
  4404. this.current.charSpacing = spacing;
  4405. },
  4406. setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
  4407. this.current.wordSpacing = spacing;
  4408. },
  4409. setHScale: function CanvasGraphics_setHScale(scale) {
  4410. this.current.textHScale = scale / 100;
  4411. },
  4412. setLeading: function CanvasGraphics_setLeading(leading) {
  4413. this.current.leading = -leading;
  4414. },
  4415. setFont: function CanvasGraphics_setFont(fontRefName, size) {
  4416. var fontObj = this.commonObjs.get(fontRefName);
  4417. var current = this.current;
  4418. if (!fontObj) {
  4419. throw new Error(`Can't find font for ${fontRefName}`);
  4420. }
  4421. current.fontMatrix = fontObj.fontMatrix ? fontObj.fontMatrix : _util.FONT_IDENTITY_MATRIX;
  4422. if (current.fontMatrix[0] === 0 || current.fontMatrix[3] === 0) {
  4423. (0, _util.warn)("Invalid font matrix for font " + fontRefName);
  4424. }
  4425. if (size < 0) {
  4426. size = -size;
  4427. current.fontDirection = -1;
  4428. } else {
  4429. current.fontDirection = 1;
  4430. }
  4431. this.current.font = fontObj;
  4432. this.current.fontSize = size;
  4433. if (fontObj.isType3Font) {
  4434. return;
  4435. }
  4436. var name = fontObj.loadedName || "sans-serif";
  4437. let bold = "normal";
  4438. if (fontObj.black) {
  4439. bold = "900";
  4440. } else if (fontObj.bold) {
  4441. bold = "bold";
  4442. }
  4443. var italic = fontObj.italic ? "italic" : "normal";
  4444. var typeface = `"${name}", ${fontObj.fallbackName}`;
  4445. let browserFontSize = size;
  4446. if (size < MIN_FONT_SIZE) {
  4447. browserFontSize = MIN_FONT_SIZE;
  4448. } else if (size > MAX_FONT_SIZE) {
  4449. browserFontSize = MAX_FONT_SIZE;
  4450. }
  4451. this.current.fontSizeScale = size / browserFontSize;
  4452. this.ctx.font = `${italic} ${bold} ${browserFontSize}px ${typeface}`;
  4453. },
  4454. setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
  4455. this.current.textRenderingMode = mode;
  4456. },
  4457. setTextRise: function CanvasGraphics_setTextRise(rise) {
  4458. this.current.textRise = rise;
  4459. },
  4460. moveText: function CanvasGraphics_moveText(x, y) {
  4461. this.current.x = this.current.lineX += x;
  4462. this.current.y = this.current.lineY += y;
  4463. },
  4464. setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
  4465. this.setLeading(-y);
  4466. this.moveText(x, y);
  4467. },
  4468. setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
  4469. this.current.textMatrix = [a, b, c, d, e, f];
  4470. this.current.textMatrixScale = Math.sqrt(a * a + b * b);
  4471. this.current.x = this.current.lineX = 0;
  4472. this.current.y = this.current.lineY = 0;
  4473. },
  4474. nextLine: function CanvasGraphics_nextLine() {
  4475. this.moveText(0, this.current.leading);
  4476. },
  4477. paintChar(character, x, y, patternTransform) {
  4478. var ctx = this.ctx;
  4479. var current = this.current;
  4480. var font = current.font;
  4481. var textRenderingMode = current.textRenderingMode;
  4482. var fontSize = current.fontSize / current.fontSizeScale;
  4483. var fillStrokeMode = textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
  4484. var isAddToPathSet = !!(textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG);
  4485. const patternFill = current.patternFill && font.data;
  4486. var addToPath;
  4487. if (font.disableFontFace || isAddToPathSet || patternFill) {
  4488. addToPath = font.getPathGenerator(this.commonObjs, character);
  4489. }
  4490. if (font.disableFontFace || patternFill) {
  4491. ctx.save();
  4492. ctx.translate(x, y);
  4493. ctx.beginPath();
  4494. addToPath(ctx, fontSize);
  4495. if (patternTransform) {
  4496. ctx.setTransform.apply(ctx, patternTransform);
  4497. }
  4498. if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  4499. ctx.fill();
  4500. }
  4501. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  4502. ctx.stroke();
  4503. }
  4504. ctx.restore();
  4505. } else {
  4506. if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  4507. ctx.fillText(character, x, y);
  4508. }
  4509. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  4510. ctx.strokeText(character, x, y);
  4511. }
  4512. }
  4513. if (isAddToPathSet) {
  4514. var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  4515. paths.push({
  4516. transform: ctx.mozCurrentTransform,
  4517. x,
  4518. y,
  4519. fontSize,
  4520. addToPath
  4521. });
  4522. }
  4523. },
  4524. get isFontSubpixelAAEnabled() {
  4525. const {
  4526. context: ctx
  4527. } = this.cachedCanvases.getCanvas("isFontSubpixelAAEnabled", 10, 10);
  4528. ctx.scale(1.5, 1);
  4529. ctx.fillText("I", 0, 10);
  4530. var data = ctx.getImageData(0, 0, 10, 10).data;
  4531. var enabled = false;
  4532. for (var i = 3; i < data.length; i += 4) {
  4533. if (data[i] > 0 && data[i] < 255) {
  4534. enabled = true;
  4535. break;
  4536. }
  4537. }
  4538. return (0, _util.shadow)(this, "isFontSubpixelAAEnabled", enabled);
  4539. },
  4540. showText: function CanvasGraphics_showText(glyphs) {
  4541. var current = this.current;
  4542. var font = current.font;
  4543. if (font.isType3Font) {
  4544. return this.showType3Text(glyphs);
  4545. }
  4546. var fontSize = current.fontSize;
  4547. if (fontSize === 0) {
  4548. return undefined;
  4549. }
  4550. var ctx = this.ctx;
  4551. var fontSizeScale = current.fontSizeScale;
  4552. var charSpacing = current.charSpacing;
  4553. var wordSpacing = current.wordSpacing;
  4554. var fontDirection = current.fontDirection;
  4555. var textHScale = current.textHScale * fontDirection;
  4556. var glyphsLength = glyphs.length;
  4557. var vertical = font.vertical;
  4558. var spacingDir = vertical ? 1 : -1;
  4559. var defaultVMetrics = font.defaultVMetrics;
  4560. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  4561. var simpleFillText = current.textRenderingMode === _util.TextRenderingMode.FILL && !font.disableFontFace && !current.patternFill;
  4562. ctx.save();
  4563. let patternTransform;
  4564. if (current.patternFill) {
  4565. ctx.save();
  4566. const pattern = current.fillColor.getPattern(ctx, this);
  4567. patternTransform = ctx.mozCurrentTransform;
  4568. ctx.restore();
  4569. ctx.fillStyle = pattern;
  4570. }
  4571. ctx.transform.apply(ctx, current.textMatrix);
  4572. ctx.translate(current.x, current.y + current.textRise);
  4573. if (fontDirection > 0) {
  4574. ctx.scale(textHScale, -1);
  4575. } else {
  4576. ctx.scale(textHScale, 1);
  4577. }
  4578. var lineWidth = current.lineWidth;
  4579. var scale = current.textMatrixScale;
  4580. if (scale === 0 || lineWidth === 0) {
  4581. var fillStrokeMode = current.textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
  4582. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  4583. this._cachedGetSinglePixelWidth = null;
  4584. lineWidth = this.getSinglePixelWidth() * MIN_WIDTH_FACTOR;
  4585. }
  4586. } else {
  4587. lineWidth /= scale;
  4588. }
  4589. if (fontSizeScale !== 1.0) {
  4590. ctx.scale(fontSizeScale, fontSizeScale);
  4591. lineWidth /= fontSizeScale;
  4592. }
  4593. ctx.lineWidth = lineWidth;
  4594. var x = 0,
  4595. i;
  4596. for (i = 0; i < glyphsLength; ++i) {
  4597. var glyph = glyphs[i];
  4598. if ((0, _util.isNum)(glyph)) {
  4599. x += spacingDir * glyph * fontSize / 1000;
  4600. continue;
  4601. }
  4602. var restoreNeeded = false;
  4603. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  4604. var character = glyph.fontChar;
  4605. var accent = glyph.accent;
  4606. var scaledX, scaledY, scaledAccentX, scaledAccentY;
  4607. var width = glyph.width;
  4608. if (vertical) {
  4609. var vmetric, vx, vy;
  4610. vmetric = glyph.vmetric || defaultVMetrics;
  4611. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  4612. vx = -vx * widthAdvanceScale;
  4613. vy = vmetric[2] * widthAdvanceScale;
  4614. width = vmetric ? -vmetric[0] : width;
  4615. scaledX = vx / fontSizeScale;
  4616. scaledY = (x + vy) / fontSizeScale;
  4617. } else {
  4618. scaledX = x / fontSizeScale;
  4619. scaledY = 0;
  4620. }
  4621. if (font.remeasure && width > 0) {
  4622. var measuredWidth = ctx.measureText(character).width * 1000 / fontSize * fontSizeScale;
  4623. if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
  4624. var characterScaleX = width / measuredWidth;
  4625. restoreNeeded = true;
  4626. ctx.save();
  4627. ctx.scale(characterScaleX, 1);
  4628. scaledX /= characterScaleX;
  4629. } else if (width !== measuredWidth) {
  4630. scaledX += (width - measuredWidth) / 2000 * fontSize / fontSizeScale;
  4631. }
  4632. }
  4633. if (glyph.isInFont || font.missingFile) {
  4634. if (simpleFillText && !accent) {
  4635. ctx.fillText(character, scaledX, scaledY);
  4636. } else {
  4637. this.paintChar(character, scaledX, scaledY, patternTransform);
  4638. if (accent) {
  4639. scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
  4640. scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
  4641. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY, patternTransform);
  4642. }
  4643. }
  4644. }
  4645. var charWidth;
  4646. if (vertical) {
  4647. charWidth = width * widthAdvanceScale - spacing * fontDirection;
  4648. } else {
  4649. charWidth = width * widthAdvanceScale + spacing * fontDirection;
  4650. }
  4651. x += charWidth;
  4652. if (restoreNeeded) {
  4653. ctx.restore();
  4654. }
  4655. }
  4656. if (vertical) {
  4657. current.y -= x;
  4658. } else {
  4659. current.x += x * textHScale;
  4660. }
  4661. ctx.restore();
  4662. },
  4663. showType3Text: function CanvasGraphics_showType3Text(glyphs) {
  4664. var ctx = this.ctx;
  4665. var current = this.current;
  4666. var font = current.font;
  4667. var fontSize = current.fontSize;
  4668. var fontDirection = current.fontDirection;
  4669. var spacingDir = font.vertical ? 1 : -1;
  4670. var charSpacing = current.charSpacing;
  4671. var wordSpacing = current.wordSpacing;
  4672. var textHScale = current.textHScale * fontDirection;
  4673. var fontMatrix = current.fontMatrix || _util.FONT_IDENTITY_MATRIX;
  4674. var glyphsLength = glyphs.length;
  4675. var isTextInvisible = current.textRenderingMode === _util.TextRenderingMode.INVISIBLE;
  4676. var i, glyph, width, spacingLength;
  4677. if (isTextInvisible || fontSize === 0) {
  4678. return;
  4679. }
  4680. this._cachedGetSinglePixelWidth = null;
  4681. ctx.save();
  4682. ctx.transform.apply(ctx, current.textMatrix);
  4683. ctx.translate(current.x, current.y);
  4684. ctx.scale(textHScale, fontDirection);
  4685. for (i = 0; i < glyphsLength; ++i) {
  4686. glyph = glyphs[i];
  4687. if ((0, _util.isNum)(glyph)) {
  4688. spacingLength = spacingDir * glyph * fontSize / 1000;
  4689. this.ctx.translate(spacingLength, 0);
  4690. current.x += spacingLength * textHScale;
  4691. continue;
  4692. }
  4693. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  4694. var operatorList = font.charProcOperatorList[glyph.operatorListId];
  4695. if (!operatorList) {
  4696. (0, _util.warn)(`Type3 character "${glyph.operatorListId}" is not available.`);
  4697. continue;
  4698. }
  4699. this.processingType3 = glyph;
  4700. this.save();
  4701. ctx.scale(fontSize, fontSize);
  4702. ctx.transform.apply(ctx, fontMatrix);
  4703. this.executeOperatorList(operatorList);
  4704. this.restore();
  4705. var transformed = _util.Util.applyTransform([glyph.width, 0], fontMatrix);
  4706. width = transformed[0] * fontSize + spacing;
  4707. ctx.translate(width, 0);
  4708. current.x += width * textHScale;
  4709. }
  4710. ctx.restore();
  4711. this.processingType3 = null;
  4712. },
  4713. setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {},
  4714. setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth, yWidth, llx, lly, urx, ury) {
  4715. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  4716. this.clip();
  4717. this.endPath();
  4718. },
  4719. getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
  4720. var pattern;
  4721. if (IR[0] === "TilingPattern") {
  4722. var color = IR[1];
  4723. var baseTransform = this.baseTransform || this.ctx.mozCurrentTransform.slice();
  4724. var canvasGraphicsFactory = {
  4725. createCanvasGraphics: ctx => {
  4726. return new CanvasGraphics(ctx, this.commonObjs, this.objs, this.canvasFactory, this.webGLContext);
  4727. }
  4728. };
  4729. pattern = new _pattern_helper.TilingPattern(IR, color, this.ctx, canvasGraphicsFactory, baseTransform);
  4730. } else {
  4731. pattern = (0, _pattern_helper.getShadingPatternFromIR)(IR);
  4732. }
  4733. return pattern;
  4734. },
  4735. setStrokeColorN: function CanvasGraphics_setStrokeColorN() {
  4736. this.current.strokeColor = this.getColorN_Pattern(arguments);
  4737. },
  4738. setFillColorN: function CanvasGraphics_setFillColorN() {
  4739. this.current.fillColor = this.getColorN_Pattern(arguments);
  4740. this.current.patternFill = true;
  4741. },
  4742. setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
  4743. var color = _util.Util.makeCssRgb(r, g, b);
  4744. this.ctx.strokeStyle = color;
  4745. this.current.strokeColor = color;
  4746. },
  4747. setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
  4748. var color = _util.Util.makeCssRgb(r, g, b);
  4749. this.ctx.fillStyle = color;
  4750. this.current.fillColor = color;
  4751. this.current.patternFill = false;
  4752. },
  4753. shadingFill: function CanvasGraphics_shadingFill(patternIR) {
  4754. var ctx = this.ctx;
  4755. this.save();
  4756. var pattern = (0, _pattern_helper.getShadingPatternFromIR)(patternIR);
  4757. ctx.fillStyle = pattern.getPattern(ctx, this, true);
  4758. var inv = ctx.mozCurrentTransformInverse;
  4759. if (inv) {
  4760. var canvas = ctx.canvas;
  4761. var width = canvas.width;
  4762. var height = canvas.height;
  4763. var bl = _util.Util.applyTransform([0, 0], inv);
  4764. var br = _util.Util.applyTransform([0, height], inv);
  4765. var ul = _util.Util.applyTransform([width, 0], inv);
  4766. var ur = _util.Util.applyTransform([width, height], inv);
  4767. var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  4768. var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  4769. var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  4770. var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  4771. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  4772. } else {
  4773. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  4774. }
  4775. this.restore();
  4776. },
  4777. beginInlineImage: function CanvasGraphics_beginInlineImage() {
  4778. (0, _util.unreachable)("Should not call beginInlineImage");
  4779. },
  4780. beginImageData: function CanvasGraphics_beginImageData() {
  4781. (0, _util.unreachable)("Should not call beginImageData");
  4782. },
  4783. paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix, bbox) {
  4784. this.save();
  4785. this.baseTransformStack.push(this.baseTransform);
  4786. if (Array.isArray(matrix) && matrix.length === 6) {
  4787. this.transform.apply(this, matrix);
  4788. }
  4789. this.baseTransform = this.ctx.mozCurrentTransform;
  4790. if (bbox) {
  4791. var width = bbox[2] - bbox[0];
  4792. var height = bbox[3] - bbox[1];
  4793. this.ctx.rect(bbox[0], bbox[1], width, height);
  4794. this.clip();
  4795. this.endPath();
  4796. }
  4797. },
  4798. paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
  4799. this.restore();
  4800. this.baseTransform = this.baseTransformStack.pop();
  4801. },
  4802. beginGroup: function CanvasGraphics_beginGroup(group) {
  4803. this.save();
  4804. var currentCtx = this.ctx;
  4805. if (!group.isolated) {
  4806. (0, _util.info)("TODO: Support non-isolated groups.");
  4807. }
  4808. if (group.knockout) {
  4809. (0, _util.warn)("Knockout groups not supported.");
  4810. }
  4811. var currentTransform = currentCtx.mozCurrentTransform;
  4812. if (group.matrix) {
  4813. currentCtx.transform.apply(currentCtx, group.matrix);
  4814. }
  4815. if (!group.bbox) {
  4816. throw new Error("Bounding box is required.");
  4817. }
  4818. var bounds = _util.Util.getAxialAlignedBoundingBox(group.bbox, currentCtx.mozCurrentTransform);
  4819. var canvasBounds = [0, 0, currentCtx.canvas.width, currentCtx.canvas.height];
  4820. bounds = _util.Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  4821. var offsetX = Math.floor(bounds[0]);
  4822. var offsetY = Math.floor(bounds[1]);
  4823. var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  4824. var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  4825. var scaleX = 1,
  4826. scaleY = 1;
  4827. if (drawnWidth > MAX_GROUP_SIZE) {
  4828. scaleX = drawnWidth / MAX_GROUP_SIZE;
  4829. drawnWidth = MAX_GROUP_SIZE;
  4830. }
  4831. if (drawnHeight > MAX_GROUP_SIZE) {
  4832. scaleY = drawnHeight / MAX_GROUP_SIZE;
  4833. drawnHeight = MAX_GROUP_SIZE;
  4834. }
  4835. var cacheId = "groupAt" + this.groupLevel;
  4836. if (group.smask) {
  4837. cacheId += "_smask_" + this.smaskCounter++ % 2;
  4838. }
  4839. var scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight, true);
  4840. var groupCtx = scratchCanvas.context;
  4841. groupCtx.scale(1 / scaleX, 1 / scaleY);
  4842. groupCtx.translate(-offsetX, -offsetY);
  4843. groupCtx.transform.apply(groupCtx, currentTransform);
  4844. if (group.smask) {
  4845. this.smaskStack.push({
  4846. canvas: scratchCanvas.canvas,
  4847. context: groupCtx,
  4848. offsetX,
  4849. offsetY,
  4850. scaleX,
  4851. scaleY,
  4852. subtype: group.smask.subtype,
  4853. backdrop: group.smask.backdrop,
  4854. transferMap: group.smask.transferMap || null,
  4855. startTransformInverse: null
  4856. });
  4857. } else {
  4858. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  4859. currentCtx.translate(offsetX, offsetY);
  4860. currentCtx.scale(scaleX, scaleY);
  4861. }
  4862. copyCtxState(currentCtx, groupCtx);
  4863. this.ctx = groupCtx;
  4864. this.setGState([["BM", "source-over"], ["ca", 1], ["CA", 1]]);
  4865. this.groupStack.push(currentCtx);
  4866. this.groupLevel++;
  4867. this.current.activeSMask = null;
  4868. },
  4869. endGroup: function CanvasGraphics_endGroup(group) {
  4870. this.groupLevel--;
  4871. var groupCtx = this.ctx;
  4872. this.ctx = this.groupStack.pop();
  4873. if (this.ctx.imageSmoothingEnabled !== undefined) {
  4874. this.ctx.imageSmoothingEnabled = false;
  4875. } else {
  4876. this.ctx.mozImageSmoothingEnabled = false;
  4877. }
  4878. if (group.smask) {
  4879. this.tempSMask = this.smaskStack.pop();
  4880. } else {
  4881. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  4882. }
  4883. this.restore();
  4884. },
  4885. beginAnnotations: function CanvasGraphics_beginAnnotations() {
  4886. this.save();
  4887. if (this.baseTransform) {
  4888. this.ctx.setTransform.apply(this.ctx, this.baseTransform);
  4889. }
  4890. },
  4891. endAnnotations: function CanvasGraphics_endAnnotations() {
  4892. this.restore();
  4893. },
  4894. beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform, matrix) {
  4895. this.save();
  4896. resetCtxToDefault(this.ctx);
  4897. this.current = new CanvasExtraState();
  4898. if (Array.isArray(rect) && rect.length === 4) {
  4899. var width = rect[2] - rect[0];
  4900. var height = rect[3] - rect[1];
  4901. this.ctx.rect(rect[0], rect[1], width, height);
  4902. this.clip();
  4903. this.endPath();
  4904. }
  4905. this.transform.apply(this, transform);
  4906. this.transform.apply(this, matrix);
  4907. },
  4908. endAnnotation: function CanvasGraphics_endAnnotation() {
  4909. this.restore();
  4910. },
  4911. paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
  4912. const domImage = this.processingType3 ? this.commonObjs.get(objId) : this.objs.get(objId);
  4913. if (!domImage) {
  4914. (0, _util.warn)("Dependent image isn't ready yet");
  4915. return;
  4916. }
  4917. this.save();
  4918. var ctx = this.ctx;
  4919. ctx.scale(1 / w, -1 / h);
  4920. ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height, 0, -h, w, h);
  4921. if (this.imageLayer) {
  4922. var currentTransform = ctx.mozCurrentTransformInverse;
  4923. var position = this.getCanvasPosition(0, 0);
  4924. this.imageLayer.appendImage({
  4925. objId,
  4926. left: position[0],
  4927. top: position[1],
  4928. width: w / currentTransform[0],
  4929. height: h / currentTransform[3]
  4930. });
  4931. }
  4932. this.restore();
  4933. },
  4934. paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
  4935. var ctx = this.ctx;
  4936. var width = img.width,
  4937. height = img.height;
  4938. var fillColor = this.current.fillColor;
  4939. var isPatternFill = this.current.patternFill;
  4940. var glyph = this.processingType3;
  4941. if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) {
  4942. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  4943. glyph.compiled = compileType3Glyph({
  4944. data: img.data,
  4945. width,
  4946. height
  4947. });
  4948. } else {
  4949. glyph.compiled = null;
  4950. }
  4951. }
  4952. if (glyph && glyph.compiled) {
  4953. glyph.compiled(ctx);
  4954. return;
  4955. }
  4956. var maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
  4957. var maskCtx = maskCanvas.context;
  4958. maskCtx.save();
  4959. putBinaryImageMask(maskCtx, img);
  4960. maskCtx.globalCompositeOperation = "source-in";
  4961. maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor;
  4962. maskCtx.fillRect(0, 0, width, height);
  4963. maskCtx.restore();
  4964. this.paintInlineImageXObject(maskCanvas.canvas);
  4965. },
  4966. paintImageMaskXObjectRepeat: function CanvasGraphics_paintImageMaskXObjectRepeat(imgData, scaleX, scaleY, positions) {
  4967. var width = imgData.width;
  4968. var height = imgData.height;
  4969. var fillColor = this.current.fillColor;
  4970. var isPatternFill = this.current.patternFill;
  4971. var maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
  4972. var maskCtx = maskCanvas.context;
  4973. maskCtx.save();
  4974. putBinaryImageMask(maskCtx, imgData);
  4975. maskCtx.globalCompositeOperation = "source-in";
  4976. maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor;
  4977. maskCtx.fillRect(0, 0, width, height);
  4978. maskCtx.restore();
  4979. var ctx = this.ctx;
  4980. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  4981. ctx.save();
  4982. ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]);
  4983. ctx.scale(1, -1);
  4984. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height, 0, -1, 1, 1);
  4985. ctx.restore();
  4986. }
  4987. },
  4988. paintImageMaskXObjectGroup: function CanvasGraphics_paintImageMaskXObjectGroup(images) {
  4989. var ctx = this.ctx;
  4990. var fillColor = this.current.fillColor;
  4991. var isPatternFill = this.current.patternFill;
  4992. for (var i = 0, ii = images.length; i < ii; i++) {
  4993. var image = images[i];
  4994. var width = image.width,
  4995. height = image.height;
  4996. var maskCanvas = this.cachedCanvases.getCanvas("maskCanvas", width, height);
  4997. var maskCtx = maskCanvas.context;
  4998. maskCtx.save();
  4999. putBinaryImageMask(maskCtx, image);
  5000. maskCtx.globalCompositeOperation = "source-in";
  5001. maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor;
  5002. maskCtx.fillRect(0, 0, width, height);
  5003. maskCtx.restore();
  5004. ctx.save();
  5005. ctx.transform.apply(ctx, image.transform);
  5006. ctx.scale(1, -1);
  5007. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height, 0, -1, 1, 1);
  5008. ctx.restore();
  5009. }
  5010. },
  5011. paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
  5012. const imgData = this.processingType3 ? this.commonObjs.get(objId) : this.objs.get(objId);
  5013. if (!imgData) {
  5014. (0, _util.warn)("Dependent image isn't ready yet");
  5015. return;
  5016. }
  5017. this.paintInlineImageXObject(imgData);
  5018. },
  5019. paintImageXObjectRepeat: function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY, positions) {
  5020. const imgData = this.processingType3 ? this.commonObjs.get(objId) : this.objs.get(objId);
  5021. if (!imgData) {
  5022. (0, _util.warn)("Dependent image isn't ready yet");
  5023. return;
  5024. }
  5025. var width = imgData.width;
  5026. var height = imgData.height;
  5027. var map = [];
  5028. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  5029. map.push({
  5030. transform: [scaleX, 0, 0, scaleY, positions[i], positions[i + 1]],
  5031. x: 0,
  5032. y: 0,
  5033. w: width,
  5034. h: height
  5035. });
  5036. }
  5037. this.paintInlineImageXObjectGroup(imgData, map);
  5038. },
  5039. paintInlineImageXObject: function CanvasGraphics_paintInlineImageXObject(imgData) {
  5040. var width = imgData.width;
  5041. var height = imgData.height;
  5042. var ctx = this.ctx;
  5043. this.save();
  5044. ctx.scale(1 / width, -1 / height);
  5045. var currentTransform = ctx.mozCurrentTransformInverse;
  5046. var a = currentTransform[0],
  5047. b = currentTransform[1];
  5048. var widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
  5049. var c = currentTransform[2],
  5050. d = currentTransform[3];
  5051. var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
  5052. var imgToPaint, tmpCanvas;
  5053. if (typeof HTMLElement === "function" && imgData instanceof HTMLElement || !imgData.data) {
  5054. imgToPaint = imgData;
  5055. } else {
  5056. tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", width, height);
  5057. var tmpCtx = tmpCanvas.context;
  5058. putBinaryImageData(tmpCtx, imgData);
  5059. imgToPaint = tmpCanvas.canvas;
  5060. }
  5061. var paintWidth = width,
  5062. paintHeight = height;
  5063. var tmpCanvasId = "prescale1";
  5064. while (widthScale > 2 && paintWidth > 1 || heightScale > 2 && paintHeight > 1) {
  5065. var newWidth = paintWidth,
  5066. newHeight = paintHeight;
  5067. if (widthScale > 2 && paintWidth > 1) {
  5068. newWidth = Math.ceil(paintWidth / 2);
  5069. widthScale /= paintWidth / newWidth;
  5070. }
  5071. if (heightScale > 2 && paintHeight > 1) {
  5072. newHeight = Math.ceil(paintHeight / 2);
  5073. heightScale /= paintHeight / newHeight;
  5074. }
  5075. tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight);
  5076. tmpCtx = tmpCanvas.context;
  5077. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  5078. tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight, 0, 0, newWidth, newHeight);
  5079. imgToPaint = tmpCanvas.canvas;
  5080. paintWidth = newWidth;
  5081. paintHeight = newHeight;
  5082. tmpCanvasId = tmpCanvasId === "prescale1" ? "prescale2" : "prescale1";
  5083. }
  5084. ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight, 0, -height, width, height);
  5085. if (this.imageLayer) {
  5086. var position = this.getCanvasPosition(0, -height);
  5087. this.imageLayer.appendImage({
  5088. imgData,
  5089. left: position[0],
  5090. top: position[1],
  5091. width: width / currentTransform[0],
  5092. height: height / currentTransform[3]
  5093. });
  5094. }
  5095. this.restore();
  5096. },
  5097. paintInlineImageXObjectGroup: function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
  5098. var ctx = this.ctx;
  5099. var w = imgData.width;
  5100. var h = imgData.height;
  5101. var tmpCanvas = this.cachedCanvases.getCanvas("inlineImage", w, h);
  5102. var tmpCtx = tmpCanvas.context;
  5103. putBinaryImageData(tmpCtx, imgData);
  5104. for (var i = 0, ii = map.length; i < ii; i++) {
  5105. var entry = map[i];
  5106. ctx.save();
  5107. ctx.transform.apply(ctx, entry.transform);
  5108. ctx.scale(1, -1);
  5109. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h, 0, -1, 1, 1);
  5110. if (this.imageLayer) {
  5111. var position = this.getCanvasPosition(entry.x, entry.y);
  5112. this.imageLayer.appendImage({
  5113. imgData,
  5114. left: position[0],
  5115. top: position[1],
  5116. width: w,
  5117. height: h
  5118. });
  5119. }
  5120. ctx.restore();
  5121. }
  5122. },
  5123. paintSolidColorImageMask: function CanvasGraphics_paintSolidColorImageMask() {
  5124. this.ctx.fillRect(0, 0, 1, 1);
  5125. },
  5126. paintXObject: function CanvasGraphics_paintXObject() {
  5127. (0, _util.warn)("Unsupported 'paintXObject' command.");
  5128. },
  5129. markPoint: function CanvasGraphics_markPoint(tag) {},
  5130. markPointProps: function CanvasGraphics_markPointProps(tag, properties) {},
  5131. beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {},
  5132. beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(tag, properties) {},
  5133. endMarkedContent: function CanvasGraphics_endMarkedContent() {},
  5134. beginCompat: function CanvasGraphics_beginCompat() {},
  5135. endCompat: function CanvasGraphics_endCompat() {},
  5136. consumePath: function CanvasGraphics_consumePath() {
  5137. var ctx = this.ctx;
  5138. if (this.pendingClip) {
  5139. if (this.pendingClip === EO_CLIP) {
  5140. ctx.clip("evenodd");
  5141. } else {
  5142. ctx.clip();
  5143. }
  5144. this.pendingClip = null;
  5145. }
  5146. ctx.beginPath();
  5147. },
  5148. getSinglePixelWidth(scale) {
  5149. if (this._cachedGetSinglePixelWidth === null) {
  5150. const inverse = this.ctx.mozCurrentTransformInverse;
  5151. this._cachedGetSinglePixelWidth = Math.sqrt(Math.max(inverse[0] * inverse[0] + inverse[1] * inverse[1], inverse[2] * inverse[2] + inverse[3] * inverse[3]));
  5152. }
  5153. return this._cachedGetSinglePixelWidth;
  5154. },
  5155. getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
  5156. var transform = this.ctx.mozCurrentTransform;
  5157. return [transform[0] * x + transform[2] * y + transform[4], transform[1] * x + transform[3] * y + transform[5]];
  5158. }
  5159. };
  5160. for (var op in _util.OPS) {
  5161. CanvasGraphics.prototype[_util.OPS[op]] = CanvasGraphics.prototype[op];
  5162. }
  5163. return CanvasGraphics;
  5164. }();
  5165. exports.CanvasGraphics = CanvasGraphics;
  5166. /***/ }),
  5167. /* 9 */
  5168. /***/ (function(module, exports, __w_pdfjs_require__) {
  5169. "use strict";
  5170. Object.defineProperty(exports, "__esModule", {
  5171. value: true
  5172. });
  5173. exports.getShadingPatternFromIR = getShadingPatternFromIR;
  5174. exports.TilingPattern = void 0;
  5175. var _util = __w_pdfjs_require__(1);
  5176. var ShadingIRs = {};
  5177. function applyBoundingBox(ctx, bbox) {
  5178. if (!bbox || typeof Path2D === "undefined") {
  5179. return;
  5180. }
  5181. const width = bbox[2] - bbox[0];
  5182. const height = bbox[3] - bbox[1];
  5183. const region = new Path2D();
  5184. region.rect(bbox[0], bbox[1], width, height);
  5185. ctx.clip(region);
  5186. }
  5187. ShadingIRs.RadialAxial = {
  5188. fromIR: function RadialAxial_fromIR(raw) {
  5189. var type = raw[1];
  5190. var bbox = raw[2];
  5191. var colorStops = raw[3];
  5192. var p0 = raw[4];
  5193. var p1 = raw[5];
  5194. var r0 = raw[6];
  5195. var r1 = raw[7];
  5196. return {
  5197. type: "Pattern",
  5198. getPattern: function RadialAxial_getPattern(ctx) {
  5199. applyBoundingBox(ctx, bbox);
  5200. var grad;
  5201. if (type === "axial") {
  5202. grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
  5203. } else if (type === "radial") {
  5204. grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
  5205. }
  5206. for (var i = 0, ii = colorStops.length; i < ii; ++i) {
  5207. var c = colorStops[i];
  5208. grad.addColorStop(c[0], c[1]);
  5209. }
  5210. return grad;
  5211. }
  5212. };
  5213. }
  5214. };
  5215. var createMeshCanvas = function createMeshCanvasClosure() {
  5216. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  5217. var coords = context.coords,
  5218. colors = context.colors;
  5219. var bytes = data.data,
  5220. rowSize = data.width * 4;
  5221. var tmp;
  5222. if (coords[p1 + 1] > coords[p2 + 1]) {
  5223. tmp = p1;
  5224. p1 = p2;
  5225. p2 = tmp;
  5226. tmp = c1;
  5227. c1 = c2;
  5228. c2 = tmp;
  5229. }
  5230. if (coords[p2 + 1] > coords[p3 + 1]) {
  5231. tmp = p2;
  5232. p2 = p3;
  5233. p3 = tmp;
  5234. tmp = c2;
  5235. c2 = c3;
  5236. c3 = tmp;
  5237. }
  5238. if (coords[p1 + 1] > coords[p2 + 1]) {
  5239. tmp = p1;
  5240. p1 = p2;
  5241. p2 = tmp;
  5242. tmp = c1;
  5243. c1 = c2;
  5244. c2 = tmp;
  5245. }
  5246. var x1 = (coords[p1] + context.offsetX) * context.scaleX;
  5247. var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  5248. var x2 = (coords[p2] + context.offsetX) * context.scaleX;
  5249. var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  5250. var x3 = (coords[p3] + context.offsetX) * context.scaleX;
  5251. var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  5252. if (y1 >= y3) {
  5253. return;
  5254. }
  5255. var c1r = colors[c1],
  5256. c1g = colors[c1 + 1],
  5257. c1b = colors[c1 + 2];
  5258. var c2r = colors[c2],
  5259. c2g = colors[c2 + 1],
  5260. c2b = colors[c2 + 2];
  5261. var c3r = colors[c3],
  5262. c3g = colors[c3 + 1],
  5263. c3b = colors[c3 + 2];
  5264. var minY = Math.round(y1),
  5265. maxY = Math.round(y3);
  5266. var xa, car, cag, cab;
  5267. var xb, cbr, cbg, cbb;
  5268. for (var y = minY; y <= maxY; y++) {
  5269. if (y < y2) {
  5270. let k;
  5271. if (y < y1) {
  5272. k = 0;
  5273. } else if (y1 === y2) {
  5274. k = 1;
  5275. } else {
  5276. k = (y1 - y) / (y1 - y2);
  5277. }
  5278. xa = x1 - (x1 - x2) * k;
  5279. car = c1r - (c1r - c2r) * k;
  5280. cag = c1g - (c1g - c2g) * k;
  5281. cab = c1b - (c1b - c2b) * k;
  5282. } else {
  5283. let k;
  5284. if (y > y3) {
  5285. k = 1;
  5286. } else if (y2 === y3) {
  5287. k = 0;
  5288. } else {
  5289. k = (y2 - y) / (y2 - y3);
  5290. }
  5291. xa = x2 - (x2 - x3) * k;
  5292. car = c2r - (c2r - c3r) * k;
  5293. cag = c2g - (c2g - c3g) * k;
  5294. cab = c2b - (c2b - c3b) * k;
  5295. }
  5296. let k;
  5297. if (y < y1) {
  5298. k = 0;
  5299. } else if (y > y3) {
  5300. k = 1;
  5301. } else {
  5302. k = (y1 - y) / (y1 - y3);
  5303. }
  5304. xb = x1 - (x1 - x3) * k;
  5305. cbr = c1r - (c1r - c3r) * k;
  5306. cbg = c1g - (c1g - c3g) * k;
  5307. cbb = c1b - (c1b - c3b) * k;
  5308. var x1_ = Math.round(Math.min(xa, xb));
  5309. var x2_ = Math.round(Math.max(xa, xb));
  5310. var j = rowSize * y + x1_ * 4;
  5311. for (var x = x1_; x <= x2_; x++) {
  5312. let k = (xa - x) / (xa - xb);
  5313. if (k < 0) {
  5314. k = 0;
  5315. } else if (k > 1) {
  5316. k = 1;
  5317. }
  5318. bytes[j++] = car - (car - cbr) * k | 0;
  5319. bytes[j++] = cag - (cag - cbg) * k | 0;
  5320. bytes[j++] = cab - (cab - cbb) * k | 0;
  5321. bytes[j++] = 255;
  5322. }
  5323. }
  5324. }
  5325. function drawFigure(data, figure, context) {
  5326. var ps = figure.coords;
  5327. var cs = figure.colors;
  5328. var i, ii;
  5329. switch (figure.type) {
  5330. case "lattice":
  5331. var verticesPerRow = figure.verticesPerRow;
  5332. var rows = Math.floor(ps.length / verticesPerRow) - 1;
  5333. var cols = verticesPerRow - 1;
  5334. for (i = 0; i < rows; i++) {
  5335. var q = i * verticesPerRow;
  5336. for (var j = 0; j < cols; j++, q++) {
  5337. drawTriangle(data, context, ps[q], ps[q + 1], ps[q + verticesPerRow], cs[q], cs[q + 1], cs[q + verticesPerRow]);
  5338. drawTriangle(data, context, ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow], cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  5339. }
  5340. }
  5341. break;
  5342. case "triangles":
  5343. for (i = 0, ii = ps.length; i < ii; i += 3) {
  5344. drawTriangle(data, context, ps[i], ps[i + 1], ps[i + 2], cs[i], cs[i + 1], cs[i + 2]);
  5345. }
  5346. break;
  5347. default:
  5348. throw new Error("illegal figure");
  5349. }
  5350. }
  5351. function createMeshCanvas(bounds, combinesScale, coords, colors, figures, backgroundColor, cachedCanvases, webGLContext) {
  5352. var EXPECTED_SCALE = 1.1;
  5353. var MAX_PATTERN_SIZE = 3000;
  5354. var BORDER_SIZE = 2;
  5355. var offsetX = Math.floor(bounds[0]);
  5356. var offsetY = Math.floor(bounds[1]);
  5357. var boundsWidth = Math.ceil(bounds[2]) - offsetX;
  5358. var boundsHeight = Math.ceil(bounds[3]) - offsetY;
  5359. var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5360. var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5361. var scaleX = boundsWidth / width;
  5362. var scaleY = boundsHeight / height;
  5363. var context = {
  5364. coords,
  5365. colors,
  5366. offsetX: -offsetX,
  5367. offsetY: -offsetY,
  5368. scaleX: 1 / scaleX,
  5369. scaleY: 1 / scaleY
  5370. };
  5371. var paddedWidth = width + BORDER_SIZE * 2;
  5372. var paddedHeight = height + BORDER_SIZE * 2;
  5373. var canvas, tmpCanvas, i, ii;
  5374. if (webGLContext.isEnabled) {
  5375. canvas = webGLContext.drawFigures({
  5376. width,
  5377. height,
  5378. backgroundColor,
  5379. figures,
  5380. context
  5381. });
  5382. tmpCanvas = cachedCanvases.getCanvas("mesh", paddedWidth, paddedHeight, false);
  5383. tmpCanvas.context.drawImage(canvas, BORDER_SIZE, BORDER_SIZE);
  5384. canvas = tmpCanvas.canvas;
  5385. } else {
  5386. tmpCanvas = cachedCanvases.getCanvas("mesh", paddedWidth, paddedHeight, false);
  5387. var tmpCtx = tmpCanvas.context;
  5388. var data = tmpCtx.createImageData(width, height);
  5389. if (backgroundColor) {
  5390. var bytes = data.data;
  5391. for (i = 0, ii = bytes.length; i < ii; i += 4) {
  5392. bytes[i] = backgroundColor[0];
  5393. bytes[i + 1] = backgroundColor[1];
  5394. bytes[i + 2] = backgroundColor[2];
  5395. bytes[i + 3] = 255;
  5396. }
  5397. }
  5398. for (i = 0; i < figures.length; i++) {
  5399. drawFigure(data, figures[i], context);
  5400. }
  5401. tmpCtx.putImageData(data, BORDER_SIZE, BORDER_SIZE);
  5402. canvas = tmpCanvas.canvas;
  5403. }
  5404. return {
  5405. canvas,
  5406. offsetX: offsetX - BORDER_SIZE * scaleX,
  5407. offsetY: offsetY - BORDER_SIZE * scaleY,
  5408. scaleX,
  5409. scaleY
  5410. };
  5411. }
  5412. return createMeshCanvas;
  5413. }();
  5414. ShadingIRs.Mesh = {
  5415. fromIR: function Mesh_fromIR(raw) {
  5416. var coords = raw[2];
  5417. var colors = raw[3];
  5418. var figures = raw[4];
  5419. var bounds = raw[5];
  5420. var matrix = raw[6];
  5421. var bbox = raw[7];
  5422. var background = raw[8];
  5423. return {
  5424. type: "Pattern",
  5425. getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
  5426. applyBoundingBox(ctx, bbox);
  5427. var scale;
  5428. if (shadingFill) {
  5429. scale = _util.Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  5430. } else {
  5431. scale = _util.Util.singularValueDecompose2dScale(owner.baseTransform);
  5432. if (matrix) {
  5433. var matrixScale = _util.Util.singularValueDecompose2dScale(matrix);
  5434. scale = [scale[0] * matrixScale[0], scale[1] * matrixScale[1]];
  5435. }
  5436. }
  5437. var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords, colors, figures, shadingFill ? null : background, owner.cachedCanvases, owner.webGLContext);
  5438. if (!shadingFill) {
  5439. ctx.setTransform.apply(ctx, owner.baseTransform);
  5440. if (matrix) {
  5441. ctx.transform.apply(ctx, matrix);
  5442. }
  5443. }
  5444. ctx.translate(temporaryPatternCanvas.offsetX, temporaryPatternCanvas.offsetY);
  5445. ctx.scale(temporaryPatternCanvas.scaleX, temporaryPatternCanvas.scaleY);
  5446. return ctx.createPattern(temporaryPatternCanvas.canvas, "no-repeat");
  5447. }
  5448. };
  5449. }
  5450. };
  5451. ShadingIRs.Dummy = {
  5452. fromIR: function Dummy_fromIR() {
  5453. return {
  5454. type: "Pattern",
  5455. getPattern: function Dummy_fromIR_getPattern() {
  5456. return "hotpink";
  5457. }
  5458. };
  5459. }
  5460. };
  5461. function getShadingPatternFromIR(raw) {
  5462. var shadingIR = ShadingIRs[raw[0]];
  5463. if (!shadingIR) {
  5464. throw new Error(`Unknown IR type: ${raw[0]}`);
  5465. }
  5466. return shadingIR.fromIR(raw);
  5467. }
  5468. var TilingPattern = function TilingPatternClosure() {
  5469. var PaintType = {
  5470. COLORED: 1,
  5471. UNCOLORED: 2
  5472. };
  5473. var MAX_PATTERN_SIZE = 3000;
  5474. function TilingPattern(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
  5475. this.operatorList = IR[2];
  5476. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  5477. this.bbox = IR[4];
  5478. this.xstep = IR[5];
  5479. this.ystep = IR[6];
  5480. this.paintType = IR[7];
  5481. this.tilingType = IR[8];
  5482. this.color = color;
  5483. this.canvasGraphicsFactory = canvasGraphicsFactory;
  5484. this.baseTransform = baseTransform;
  5485. this.type = "Pattern";
  5486. this.ctx = ctx;
  5487. }
  5488. TilingPattern.prototype = {
  5489. createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
  5490. var operatorList = this.operatorList;
  5491. var bbox = this.bbox;
  5492. var xstep = this.xstep;
  5493. var ystep = this.ystep;
  5494. var paintType = this.paintType;
  5495. var tilingType = this.tilingType;
  5496. var color = this.color;
  5497. var canvasGraphicsFactory = this.canvasGraphicsFactory;
  5498. (0, _util.info)("TilingType: " + tilingType);
  5499. var x0 = bbox[0],
  5500. y0 = bbox[1],
  5501. x1 = bbox[2],
  5502. y1 = bbox[3];
  5503. var matrixScale = _util.Util.singularValueDecompose2dScale(this.matrix);
  5504. var curMatrixScale = _util.Util.singularValueDecompose2dScale(this.baseTransform);
  5505. var combinedScale = [matrixScale[0] * curMatrixScale[0], matrixScale[1] * curMatrixScale[1]];
  5506. var dimx = this.getSizeAndScale(xstep, this.ctx.canvas.width, combinedScale[0]);
  5507. var dimy = this.getSizeAndScale(ystep, this.ctx.canvas.height, combinedScale[1]);
  5508. var tmpCanvas = owner.cachedCanvases.getCanvas("pattern", dimx.size, dimy.size, true);
  5509. var tmpCtx = tmpCanvas.context;
  5510. var graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
  5511. graphics.groupLevel = owner.groupLevel;
  5512. this.setFillAndStrokeStyleToContext(graphics, paintType, color);
  5513. graphics.transform(dimx.scale, 0, 0, dimy.scale, 0, 0);
  5514. graphics.transform(1, 0, 0, 1, -x0, -y0);
  5515. this.clipBbox(graphics, bbox, x0, y0, x1, y1);
  5516. graphics.executeOperatorList(operatorList);
  5517. this.ctx.transform(1, 0, 0, 1, x0, y0);
  5518. this.ctx.scale(1 / dimx.scale, 1 / dimy.scale);
  5519. return tmpCanvas.canvas;
  5520. },
  5521. getSizeAndScale: function TilingPattern_getSizeAndScale(step, realOutputSize, scale) {
  5522. step = Math.abs(step);
  5523. var maxSize = Math.max(MAX_PATTERN_SIZE, realOutputSize);
  5524. var size = Math.ceil(step * scale);
  5525. if (size >= maxSize) {
  5526. size = maxSize;
  5527. } else {
  5528. scale = size / step;
  5529. }
  5530. return {
  5531. scale,
  5532. size
  5533. };
  5534. },
  5535. clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
  5536. if (Array.isArray(bbox) && bbox.length === 4) {
  5537. var bboxWidth = x1 - x0;
  5538. var bboxHeight = y1 - y0;
  5539. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  5540. graphics.clip();
  5541. graphics.endPath();
  5542. }
  5543. },
  5544. setFillAndStrokeStyleToContext: function setFillAndStrokeStyleToContext(graphics, paintType, color) {
  5545. const context = graphics.ctx,
  5546. current = graphics.current;
  5547. switch (paintType) {
  5548. case PaintType.COLORED:
  5549. var ctx = this.ctx;
  5550. context.fillStyle = ctx.fillStyle;
  5551. context.strokeStyle = ctx.strokeStyle;
  5552. current.fillColor = ctx.fillStyle;
  5553. current.strokeColor = ctx.strokeStyle;
  5554. break;
  5555. case PaintType.UNCOLORED:
  5556. var cssColor = _util.Util.makeCssRgb(color[0], color[1], color[2]);
  5557. context.fillStyle = cssColor;
  5558. context.strokeStyle = cssColor;
  5559. current.fillColor = cssColor;
  5560. current.strokeColor = cssColor;
  5561. break;
  5562. default:
  5563. throw new _util.FormatError(`Unsupported paint type: ${paintType}`);
  5564. }
  5565. },
  5566. getPattern: function TilingPattern_getPattern(ctx, owner) {
  5567. ctx = this.ctx;
  5568. ctx.setTransform.apply(ctx, this.baseTransform);
  5569. ctx.transform.apply(ctx, this.matrix);
  5570. var temporaryPatternCanvas = this.createPatternCanvas(owner);
  5571. return ctx.createPattern(temporaryPatternCanvas, "repeat");
  5572. }
  5573. };
  5574. return TilingPattern;
  5575. }();
  5576. exports.TilingPattern = TilingPattern;
  5577. /***/ }),
  5578. /* 10 */
  5579. /***/ (function(module, exports, __w_pdfjs_require__) {
  5580. "use strict";
  5581. Object.defineProperty(exports, "__esModule", {
  5582. value: true
  5583. });
  5584. exports.GlobalWorkerOptions = void 0;
  5585. const GlobalWorkerOptions = Object.create(null);
  5586. exports.GlobalWorkerOptions = GlobalWorkerOptions;
  5587. GlobalWorkerOptions.workerPort = GlobalWorkerOptions.workerPort === undefined ? null : GlobalWorkerOptions.workerPort;
  5588. GlobalWorkerOptions.workerSrc = GlobalWorkerOptions.workerSrc === undefined ? "" : GlobalWorkerOptions.workerSrc;
  5589. /***/ }),
  5590. /* 11 */
  5591. /***/ (function(module, exports, __w_pdfjs_require__) {
  5592. "use strict";
  5593. Object.defineProperty(exports, "__esModule", {
  5594. value: true
  5595. });
  5596. exports.MessageHandler = void 0;
  5597. var _util = __w_pdfjs_require__(1);
  5598. const CallbackKind = {
  5599. UNKNOWN: 0,
  5600. DATA: 1,
  5601. ERROR: 2
  5602. };
  5603. const StreamKind = {
  5604. UNKNOWN: 0,
  5605. CANCEL: 1,
  5606. CANCEL_COMPLETE: 2,
  5607. CLOSE: 3,
  5608. ENQUEUE: 4,
  5609. ERROR: 5,
  5610. PULL: 6,
  5611. PULL_COMPLETE: 7,
  5612. START_COMPLETE: 8
  5613. };
  5614. function wrapReason(reason) {
  5615. if (typeof reason !== "object" || reason === null) {
  5616. return reason;
  5617. }
  5618. switch (reason.name) {
  5619. case "AbortException":
  5620. return new _util.AbortException(reason.message);
  5621. case "MissingPDFException":
  5622. return new _util.MissingPDFException(reason.message);
  5623. case "UnexpectedResponseException":
  5624. return new _util.UnexpectedResponseException(reason.message, reason.status);
  5625. case "UnknownErrorException":
  5626. return new _util.UnknownErrorException(reason.message, reason.details);
  5627. default:
  5628. return new _util.UnknownErrorException(reason.message, reason.toString());
  5629. }
  5630. }
  5631. class MessageHandler {
  5632. constructor(sourceName, targetName, comObj) {
  5633. this.sourceName = sourceName;
  5634. this.targetName = targetName;
  5635. this.comObj = comObj;
  5636. this.callbackId = 1;
  5637. this.streamId = 1;
  5638. this.postMessageTransfers = true;
  5639. this.streamSinks = Object.create(null);
  5640. this.streamControllers = Object.create(null);
  5641. this.callbackCapabilities = Object.create(null);
  5642. this.actionHandler = Object.create(null);
  5643. this._onComObjOnMessage = event => {
  5644. const data = event.data;
  5645. if (data.targetName !== this.sourceName) {
  5646. return;
  5647. }
  5648. if (data.stream) {
  5649. this._processStreamMessage(data);
  5650. return;
  5651. }
  5652. if (data.callback) {
  5653. const callbackId = data.callbackId;
  5654. const capability = this.callbackCapabilities[callbackId];
  5655. if (!capability) {
  5656. throw new Error(`Cannot resolve callback ${callbackId}`);
  5657. }
  5658. delete this.callbackCapabilities[callbackId];
  5659. if (data.callback === CallbackKind.DATA) {
  5660. capability.resolve(data.data);
  5661. } else if (data.callback === CallbackKind.ERROR) {
  5662. capability.reject(wrapReason(data.reason));
  5663. } else {
  5664. throw new Error("Unexpected callback case");
  5665. }
  5666. return;
  5667. }
  5668. const action = this.actionHandler[data.action];
  5669. if (!action) {
  5670. throw new Error(`Unknown action from worker: ${data.action}`);
  5671. }
  5672. if (data.callbackId) {
  5673. const sourceName = this.sourceName;
  5674. const targetName = data.sourceName;
  5675. new Promise(function (resolve) {
  5676. resolve(action(data.data));
  5677. }).then(function (result) {
  5678. comObj.postMessage({
  5679. sourceName,
  5680. targetName,
  5681. callback: CallbackKind.DATA,
  5682. callbackId: data.callbackId,
  5683. data: result
  5684. });
  5685. }, function (reason) {
  5686. comObj.postMessage({
  5687. sourceName,
  5688. targetName,
  5689. callback: CallbackKind.ERROR,
  5690. callbackId: data.callbackId,
  5691. reason: wrapReason(reason)
  5692. });
  5693. });
  5694. return;
  5695. }
  5696. if (data.streamId) {
  5697. this._createStreamSink(data);
  5698. return;
  5699. }
  5700. action(data.data);
  5701. };
  5702. comObj.addEventListener("message", this._onComObjOnMessage);
  5703. }
  5704. on(actionName, handler) {
  5705. const ah = this.actionHandler;
  5706. if (ah[actionName]) {
  5707. throw new Error(`There is already an actionName called "${actionName}"`);
  5708. }
  5709. ah[actionName] = handler;
  5710. }
  5711. send(actionName, data, transfers) {
  5712. this._postMessage({
  5713. sourceName: this.sourceName,
  5714. targetName: this.targetName,
  5715. action: actionName,
  5716. data
  5717. }, transfers);
  5718. }
  5719. sendWithPromise(actionName, data, transfers) {
  5720. const callbackId = this.callbackId++;
  5721. const capability = (0, _util.createPromiseCapability)();
  5722. this.callbackCapabilities[callbackId] = capability;
  5723. try {
  5724. this._postMessage({
  5725. sourceName: this.sourceName,
  5726. targetName: this.targetName,
  5727. action: actionName,
  5728. callbackId,
  5729. data
  5730. }, transfers);
  5731. } catch (ex) {
  5732. capability.reject(ex);
  5733. }
  5734. return capability.promise;
  5735. }
  5736. sendWithStream(actionName, data, queueingStrategy, transfers) {
  5737. const streamId = this.streamId++;
  5738. const sourceName = this.sourceName;
  5739. const targetName = this.targetName;
  5740. const comObj = this.comObj;
  5741. return new ReadableStream({
  5742. start: controller => {
  5743. const startCapability = (0, _util.createPromiseCapability)();
  5744. this.streamControllers[streamId] = {
  5745. controller,
  5746. startCall: startCapability,
  5747. pullCall: null,
  5748. cancelCall: null,
  5749. isClosed: false
  5750. };
  5751. this._postMessage({
  5752. sourceName,
  5753. targetName,
  5754. action: actionName,
  5755. streamId,
  5756. data,
  5757. desiredSize: controller.desiredSize
  5758. }, transfers);
  5759. return startCapability.promise;
  5760. },
  5761. pull: controller => {
  5762. const pullCapability = (0, _util.createPromiseCapability)();
  5763. this.streamControllers[streamId].pullCall = pullCapability;
  5764. comObj.postMessage({
  5765. sourceName,
  5766. targetName,
  5767. stream: StreamKind.PULL,
  5768. streamId,
  5769. desiredSize: controller.desiredSize
  5770. });
  5771. return pullCapability.promise;
  5772. },
  5773. cancel: reason => {
  5774. (0, _util.assert)(reason instanceof Error, "cancel must have a valid reason");
  5775. const cancelCapability = (0, _util.createPromiseCapability)();
  5776. this.streamControllers[streamId].cancelCall = cancelCapability;
  5777. this.streamControllers[streamId].isClosed = true;
  5778. comObj.postMessage({
  5779. sourceName,
  5780. targetName,
  5781. stream: StreamKind.CANCEL,
  5782. streamId,
  5783. reason: wrapReason(reason)
  5784. });
  5785. return cancelCapability.promise;
  5786. }
  5787. }, queueingStrategy);
  5788. }
  5789. _createStreamSink(data) {
  5790. const self = this;
  5791. const action = this.actionHandler[data.action];
  5792. const streamId = data.streamId;
  5793. const sourceName = this.sourceName;
  5794. const targetName = data.sourceName;
  5795. const comObj = this.comObj;
  5796. const streamSink = {
  5797. enqueue(chunk, size = 1, transfers) {
  5798. if (this.isCancelled) {
  5799. return;
  5800. }
  5801. const lastDesiredSize = this.desiredSize;
  5802. this.desiredSize -= size;
  5803. if (lastDesiredSize > 0 && this.desiredSize <= 0) {
  5804. this.sinkCapability = (0, _util.createPromiseCapability)();
  5805. this.ready = this.sinkCapability.promise;
  5806. }
  5807. self._postMessage({
  5808. sourceName,
  5809. targetName,
  5810. stream: StreamKind.ENQUEUE,
  5811. streamId,
  5812. chunk
  5813. }, transfers);
  5814. },
  5815. close() {
  5816. if (this.isCancelled) {
  5817. return;
  5818. }
  5819. this.isCancelled = true;
  5820. comObj.postMessage({
  5821. sourceName,
  5822. targetName,
  5823. stream: StreamKind.CLOSE,
  5824. streamId
  5825. });
  5826. delete self.streamSinks[streamId];
  5827. },
  5828. error(reason) {
  5829. (0, _util.assert)(reason instanceof Error, "error must have a valid reason");
  5830. if (this.isCancelled) {
  5831. return;
  5832. }
  5833. this.isCancelled = true;
  5834. comObj.postMessage({
  5835. sourceName,
  5836. targetName,
  5837. stream: StreamKind.ERROR,
  5838. streamId,
  5839. reason: wrapReason(reason)
  5840. });
  5841. },
  5842. sinkCapability: (0, _util.createPromiseCapability)(),
  5843. onPull: null,
  5844. onCancel: null,
  5845. isCancelled: false,
  5846. desiredSize: data.desiredSize,
  5847. ready: null
  5848. };
  5849. streamSink.sinkCapability.resolve();
  5850. streamSink.ready = streamSink.sinkCapability.promise;
  5851. this.streamSinks[streamId] = streamSink;
  5852. new Promise(function (resolve) {
  5853. resolve(action(data.data, streamSink));
  5854. }).then(function () {
  5855. comObj.postMessage({
  5856. sourceName,
  5857. targetName,
  5858. stream: StreamKind.START_COMPLETE,
  5859. streamId,
  5860. success: true
  5861. });
  5862. }, function (reason) {
  5863. comObj.postMessage({
  5864. sourceName,
  5865. targetName,
  5866. stream: StreamKind.START_COMPLETE,
  5867. streamId,
  5868. reason: wrapReason(reason)
  5869. });
  5870. });
  5871. }
  5872. _processStreamMessage(data) {
  5873. const streamId = data.streamId;
  5874. const sourceName = this.sourceName;
  5875. const targetName = data.sourceName;
  5876. const comObj = this.comObj;
  5877. switch (data.stream) {
  5878. case StreamKind.START_COMPLETE:
  5879. if (data.success) {
  5880. this.streamControllers[streamId].startCall.resolve();
  5881. } else {
  5882. this.streamControllers[streamId].startCall.reject(wrapReason(data.reason));
  5883. }
  5884. break;
  5885. case StreamKind.PULL_COMPLETE:
  5886. if (data.success) {
  5887. this.streamControllers[streamId].pullCall.resolve();
  5888. } else {
  5889. this.streamControllers[streamId].pullCall.reject(wrapReason(data.reason));
  5890. }
  5891. break;
  5892. case StreamKind.PULL:
  5893. if (!this.streamSinks[streamId]) {
  5894. comObj.postMessage({
  5895. sourceName,
  5896. targetName,
  5897. stream: StreamKind.PULL_COMPLETE,
  5898. streamId,
  5899. success: true
  5900. });
  5901. break;
  5902. }
  5903. if (this.streamSinks[streamId].desiredSize <= 0 && data.desiredSize > 0) {
  5904. this.streamSinks[streamId].sinkCapability.resolve();
  5905. }
  5906. this.streamSinks[streamId].desiredSize = data.desiredSize;
  5907. const {
  5908. onPull
  5909. } = this.streamSinks[data.streamId];
  5910. new Promise(function (resolve) {
  5911. resolve(onPull && onPull());
  5912. }).then(function () {
  5913. comObj.postMessage({
  5914. sourceName,
  5915. targetName,
  5916. stream: StreamKind.PULL_COMPLETE,
  5917. streamId,
  5918. success: true
  5919. });
  5920. }, function (reason) {
  5921. comObj.postMessage({
  5922. sourceName,
  5923. targetName,
  5924. stream: StreamKind.PULL_COMPLETE,
  5925. streamId,
  5926. reason: wrapReason(reason)
  5927. });
  5928. });
  5929. break;
  5930. case StreamKind.ENQUEUE:
  5931. (0, _util.assert)(this.streamControllers[streamId], "enqueue should have stream controller");
  5932. if (this.streamControllers[streamId].isClosed) {
  5933. break;
  5934. }
  5935. this.streamControllers[streamId].controller.enqueue(data.chunk);
  5936. break;
  5937. case StreamKind.CLOSE:
  5938. (0, _util.assert)(this.streamControllers[streamId], "close should have stream controller");
  5939. if (this.streamControllers[streamId].isClosed) {
  5940. break;
  5941. }
  5942. this.streamControllers[streamId].isClosed = true;
  5943. this.streamControllers[streamId].controller.close();
  5944. this._deleteStreamController(streamId);
  5945. break;
  5946. case StreamKind.ERROR:
  5947. (0, _util.assert)(this.streamControllers[streamId], "error should have stream controller");
  5948. this.streamControllers[streamId].controller.error(wrapReason(data.reason));
  5949. this._deleteStreamController(streamId);
  5950. break;
  5951. case StreamKind.CANCEL_COMPLETE:
  5952. if (data.success) {
  5953. this.streamControllers[streamId].cancelCall.resolve();
  5954. } else {
  5955. this.streamControllers[streamId].cancelCall.reject(wrapReason(data.reason));
  5956. }
  5957. this._deleteStreamController(streamId);
  5958. break;
  5959. case StreamKind.CANCEL:
  5960. if (!this.streamSinks[streamId]) {
  5961. break;
  5962. }
  5963. const {
  5964. onCancel
  5965. } = this.streamSinks[data.streamId];
  5966. new Promise(function (resolve) {
  5967. resolve(onCancel && onCancel(wrapReason(data.reason)));
  5968. }).then(function () {
  5969. comObj.postMessage({
  5970. sourceName,
  5971. targetName,
  5972. stream: StreamKind.CANCEL_COMPLETE,
  5973. streamId,
  5974. success: true
  5975. });
  5976. }, function (reason) {
  5977. comObj.postMessage({
  5978. sourceName,
  5979. targetName,
  5980. stream: StreamKind.CANCEL_COMPLETE,
  5981. streamId,
  5982. reason: wrapReason(reason)
  5983. });
  5984. });
  5985. this.streamSinks[streamId].sinkCapability.reject(wrapReason(data.reason));
  5986. this.streamSinks[streamId].isCancelled = true;
  5987. delete this.streamSinks[streamId];
  5988. break;
  5989. default:
  5990. throw new Error("Unexpected stream case");
  5991. }
  5992. }
  5993. async _deleteStreamController(streamId) {
  5994. await Promise.allSettled([this.streamControllers[streamId].startCall, this.streamControllers[streamId].pullCall, this.streamControllers[streamId].cancelCall].map(function (capability) {
  5995. return capability && capability.promise;
  5996. }));
  5997. delete this.streamControllers[streamId];
  5998. }
  5999. _postMessage(message, transfers) {
  6000. if (transfers && this.postMessageTransfers) {
  6001. this.comObj.postMessage(message, transfers);
  6002. } else {
  6003. this.comObj.postMessage(message);
  6004. }
  6005. }
  6006. destroy() {
  6007. this.comObj.removeEventListener("message", this._onComObjOnMessage);
  6008. }
  6009. }
  6010. exports.MessageHandler = MessageHandler;
  6011. /***/ }),
  6012. /* 12 */
  6013. /***/ (function(module, exports, __w_pdfjs_require__) {
  6014. "use strict";
  6015. Object.defineProperty(exports, "__esModule", {
  6016. value: true
  6017. });
  6018. exports.Metadata = void 0;
  6019. var _util = __w_pdfjs_require__(1);
  6020. var _xml_parser = __w_pdfjs_require__(13);
  6021. class Metadata {
  6022. constructor(data) {
  6023. (0, _util.assert)(typeof data === "string", "Metadata: input is not a string");
  6024. data = this._repair(data);
  6025. const parser = new _xml_parser.SimpleXMLParser();
  6026. const xmlDocument = parser.parseFromString(data);
  6027. this._metadataMap = new Map();
  6028. if (xmlDocument) {
  6029. this._parse(xmlDocument);
  6030. }
  6031. }
  6032. _repair(data) {
  6033. return data.replace(/^[^<]+/, "").replace(/>\\376\\377([^<]+)/g, function (all, codes) {
  6034. const bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g, function (code, d1, d2, d3) {
  6035. return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
  6036. }).replace(/&(amp|apos|gt|lt|quot);/g, function (str, name) {
  6037. switch (name) {
  6038. case "amp":
  6039. return "&";
  6040. case "apos":
  6041. return "'";
  6042. case "gt":
  6043. return ">";
  6044. case "lt":
  6045. return "<";
  6046. case "quot":
  6047. return '"';
  6048. }
  6049. throw new Error(`_repair: ${name} isn't defined.`);
  6050. });
  6051. let chars = "";
  6052. for (let i = 0, ii = bytes.length; i < ii; i += 2) {
  6053. const code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
  6054. if (code >= 32 && code < 127 && code !== 60 && code !== 62 && code !== 38) {
  6055. chars += String.fromCharCode(code);
  6056. } else {
  6057. chars += "&#x" + (0x10000 + code).toString(16).substring(1) + ";";
  6058. }
  6059. }
  6060. return ">" + chars;
  6061. });
  6062. }
  6063. _parse(xmlDocument) {
  6064. let rdf = xmlDocument.documentElement;
  6065. if (rdf.nodeName.toLowerCase() !== "rdf:rdf") {
  6066. rdf = rdf.firstChild;
  6067. while (rdf && rdf.nodeName.toLowerCase() !== "rdf:rdf") {
  6068. rdf = rdf.nextSibling;
  6069. }
  6070. }
  6071. const nodeName = rdf ? rdf.nodeName.toLowerCase() : null;
  6072. if (!rdf || nodeName !== "rdf:rdf" || !rdf.hasChildNodes()) {
  6073. return;
  6074. }
  6075. const children = rdf.childNodes;
  6076. for (let i = 0, ii = children.length; i < ii; i++) {
  6077. const desc = children[i];
  6078. if (desc.nodeName.toLowerCase() !== "rdf:description") {
  6079. continue;
  6080. }
  6081. for (let j = 0, jj = desc.childNodes.length; j < jj; j++) {
  6082. if (desc.childNodes[j].nodeName.toLowerCase() !== "#text") {
  6083. const entry = desc.childNodes[j];
  6084. const name = entry.nodeName.toLowerCase();
  6085. this._metadataMap.set(name, entry.textContent.trim());
  6086. }
  6087. }
  6088. }
  6089. }
  6090. get(name) {
  6091. return this._metadataMap.has(name) ? this._metadataMap.get(name) : null;
  6092. }
  6093. getAll() {
  6094. const obj = Object.create(null);
  6095. for (const [key, value] of this._metadataMap) {
  6096. obj[key] = value;
  6097. }
  6098. return obj;
  6099. }
  6100. has(name) {
  6101. return this._metadataMap.has(name);
  6102. }
  6103. }
  6104. exports.Metadata = Metadata;
  6105. /***/ }),
  6106. /* 13 */
  6107. /***/ (function(module, exports, __w_pdfjs_require__) {
  6108. "use strict";
  6109. Object.defineProperty(exports, "__esModule", {
  6110. value: true
  6111. });
  6112. exports.SimpleXMLParser = void 0;
  6113. const XMLParserErrorCode = {
  6114. NoError: 0,
  6115. EndOfDocument: -1,
  6116. UnterminatedCdat: -2,
  6117. UnterminatedXmlDeclaration: -3,
  6118. UnterminatedDoctypeDeclaration: -4,
  6119. UnterminatedComment: -5,
  6120. MalformedElement: -6,
  6121. OutOfMemory: -7,
  6122. UnterminatedAttributeValue: -8,
  6123. UnterminatedElement: -9,
  6124. ElementNeverBegun: -10
  6125. };
  6126. function isWhitespace(s, index) {
  6127. const ch = s[index];
  6128. return ch === " " || ch === "\n" || ch === "\r" || ch === "\t";
  6129. }
  6130. function isWhitespaceString(s) {
  6131. for (let i = 0, ii = s.length; i < ii; i++) {
  6132. if (!isWhitespace(s, i)) {
  6133. return false;
  6134. }
  6135. }
  6136. return true;
  6137. }
  6138. class XMLParserBase {
  6139. _resolveEntities(s) {
  6140. return s.replace(/&([^;]+);/g, (all, entity) => {
  6141. if (entity.substring(0, 2) === "#x") {
  6142. return String.fromCharCode(parseInt(entity.substring(2), 16));
  6143. } else if (entity.substring(0, 1) === "#") {
  6144. return String.fromCharCode(parseInt(entity.substring(1), 10));
  6145. }
  6146. switch (entity) {
  6147. case "lt":
  6148. return "<";
  6149. case "gt":
  6150. return ">";
  6151. case "amp":
  6152. return "&";
  6153. case "quot":
  6154. return '"';
  6155. }
  6156. return this.onResolveEntity(entity);
  6157. });
  6158. }
  6159. _parseContent(s, start) {
  6160. const attributes = [];
  6161. let pos = start;
  6162. function skipWs() {
  6163. while (pos < s.length && isWhitespace(s, pos)) {
  6164. ++pos;
  6165. }
  6166. }
  6167. while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== ">" && s[pos] !== "/") {
  6168. ++pos;
  6169. }
  6170. const name = s.substring(start, pos);
  6171. skipWs();
  6172. while (pos < s.length && s[pos] !== ">" && s[pos] !== "/" && s[pos] !== "?") {
  6173. skipWs();
  6174. let attrName = "",
  6175. attrValue = "";
  6176. while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== "=") {
  6177. attrName += s[pos];
  6178. ++pos;
  6179. }
  6180. skipWs();
  6181. if (s[pos] !== "=") {
  6182. return null;
  6183. }
  6184. ++pos;
  6185. skipWs();
  6186. const attrEndChar = s[pos];
  6187. if (attrEndChar !== '"' && attrEndChar !== "'") {
  6188. return null;
  6189. }
  6190. const attrEndIndex = s.indexOf(attrEndChar, ++pos);
  6191. if (attrEndIndex < 0) {
  6192. return null;
  6193. }
  6194. attrValue = s.substring(pos, attrEndIndex);
  6195. attributes.push({
  6196. name: attrName,
  6197. value: this._resolveEntities(attrValue)
  6198. });
  6199. pos = attrEndIndex + 1;
  6200. skipWs();
  6201. }
  6202. return {
  6203. name,
  6204. attributes,
  6205. parsed: pos - start
  6206. };
  6207. }
  6208. _parseProcessingInstruction(s, start) {
  6209. let pos = start;
  6210. function skipWs() {
  6211. while (pos < s.length && isWhitespace(s, pos)) {
  6212. ++pos;
  6213. }
  6214. }
  6215. while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== ">" && s[pos] !== "/") {
  6216. ++pos;
  6217. }
  6218. const name = s.substring(start, pos);
  6219. skipWs();
  6220. const attrStart = pos;
  6221. while (pos < s.length && (s[pos] !== "?" || s[pos + 1] !== ">")) {
  6222. ++pos;
  6223. }
  6224. const value = s.substring(attrStart, pos);
  6225. return {
  6226. name,
  6227. value,
  6228. parsed: pos - start
  6229. };
  6230. }
  6231. parseXml(s) {
  6232. let i = 0;
  6233. while (i < s.length) {
  6234. const ch = s[i];
  6235. let j = i;
  6236. if (ch === "<") {
  6237. ++j;
  6238. const ch2 = s[j];
  6239. let q;
  6240. switch (ch2) {
  6241. case "/":
  6242. ++j;
  6243. q = s.indexOf(">", j);
  6244. if (q < 0) {
  6245. this.onError(XMLParserErrorCode.UnterminatedElement);
  6246. return;
  6247. }
  6248. this.onEndElement(s.substring(j, q));
  6249. j = q + 1;
  6250. break;
  6251. case "?":
  6252. ++j;
  6253. const pi = this._parseProcessingInstruction(s, j);
  6254. if (s.substring(j + pi.parsed, j + pi.parsed + 2) !== "?>") {
  6255. this.onError(XMLParserErrorCode.UnterminatedXmlDeclaration);
  6256. return;
  6257. }
  6258. this.onPi(pi.name, pi.value);
  6259. j += pi.parsed + 2;
  6260. break;
  6261. case "!":
  6262. if (s.substring(j + 1, j + 3) === "--") {
  6263. q = s.indexOf("-->", j + 3);
  6264. if (q < 0) {
  6265. this.onError(XMLParserErrorCode.UnterminatedComment);
  6266. return;
  6267. }
  6268. this.onComment(s.substring(j + 3, q));
  6269. j = q + 3;
  6270. } else if (s.substring(j + 1, j + 8) === "[CDATA[") {
  6271. q = s.indexOf("]]>", j + 8);
  6272. if (q < 0) {
  6273. this.onError(XMLParserErrorCode.UnterminatedCdat);
  6274. return;
  6275. }
  6276. this.onCdata(s.substring(j + 8, q));
  6277. j = q + 3;
  6278. } else if (s.substring(j + 1, j + 8) === "DOCTYPE") {
  6279. const q2 = s.indexOf("[", j + 8);
  6280. let complexDoctype = false;
  6281. q = s.indexOf(">", j + 8);
  6282. if (q < 0) {
  6283. this.onError(XMLParserErrorCode.UnterminatedDoctypeDeclaration);
  6284. return;
  6285. }
  6286. if (q2 > 0 && q > q2) {
  6287. q = s.indexOf("]>", j + 8);
  6288. if (q < 0) {
  6289. this.onError(XMLParserErrorCode.UnterminatedDoctypeDeclaration);
  6290. return;
  6291. }
  6292. complexDoctype = true;
  6293. }
  6294. const doctypeContent = s.substring(j + 8, q + (complexDoctype ? 1 : 0));
  6295. this.onDoctype(doctypeContent);
  6296. j = q + (complexDoctype ? 2 : 1);
  6297. } else {
  6298. this.onError(XMLParserErrorCode.MalformedElement);
  6299. return;
  6300. }
  6301. break;
  6302. default:
  6303. const content = this._parseContent(s, j);
  6304. if (content === null) {
  6305. this.onError(XMLParserErrorCode.MalformedElement);
  6306. return;
  6307. }
  6308. let isClosed = false;
  6309. if (s.substring(j + content.parsed, j + content.parsed + 2) === "/>") {
  6310. isClosed = true;
  6311. } else if (s.substring(j + content.parsed, j + content.parsed + 1) !== ">") {
  6312. this.onError(XMLParserErrorCode.UnterminatedElement);
  6313. return;
  6314. }
  6315. this.onBeginElement(content.name, content.attributes, isClosed);
  6316. j += content.parsed + (isClosed ? 2 : 1);
  6317. break;
  6318. }
  6319. } else {
  6320. while (j < s.length && s[j] !== "<") {
  6321. j++;
  6322. }
  6323. const text = s.substring(i, j);
  6324. this.onText(this._resolveEntities(text));
  6325. }
  6326. i = j;
  6327. }
  6328. }
  6329. onResolveEntity(name) {
  6330. return `&${name};`;
  6331. }
  6332. onPi(name, value) {}
  6333. onComment(text) {}
  6334. onCdata(text) {}
  6335. onDoctype(doctypeContent) {}
  6336. onText(text) {}
  6337. onBeginElement(name, attributes, isEmpty) {}
  6338. onEndElement(name) {}
  6339. onError(code) {}
  6340. }
  6341. class SimpleDOMNode {
  6342. constructor(nodeName, nodeValue) {
  6343. this.nodeName = nodeName;
  6344. this.nodeValue = nodeValue;
  6345. Object.defineProperty(this, "parentNode", {
  6346. value: null,
  6347. writable: true
  6348. });
  6349. }
  6350. get firstChild() {
  6351. return this.childNodes && this.childNodes[0];
  6352. }
  6353. get nextSibling() {
  6354. const childNodes = this.parentNode.childNodes;
  6355. if (!childNodes) {
  6356. return undefined;
  6357. }
  6358. const index = childNodes.indexOf(this);
  6359. if (index === -1) {
  6360. return undefined;
  6361. }
  6362. return childNodes[index + 1];
  6363. }
  6364. get textContent() {
  6365. if (!this.childNodes) {
  6366. return this.nodeValue || "";
  6367. }
  6368. return this.childNodes.map(function (child) {
  6369. return child.textContent;
  6370. }).join("");
  6371. }
  6372. hasChildNodes() {
  6373. return this.childNodes && this.childNodes.length > 0;
  6374. }
  6375. }
  6376. class SimpleXMLParser extends XMLParserBase {
  6377. constructor() {
  6378. super();
  6379. this._currentFragment = null;
  6380. this._stack = null;
  6381. this._errorCode = XMLParserErrorCode.NoError;
  6382. }
  6383. parseFromString(data) {
  6384. this._currentFragment = [];
  6385. this._stack = [];
  6386. this._errorCode = XMLParserErrorCode.NoError;
  6387. this.parseXml(data);
  6388. if (this._errorCode !== XMLParserErrorCode.NoError) {
  6389. return undefined;
  6390. }
  6391. const [documentElement] = this._currentFragment;
  6392. if (!documentElement) {
  6393. return undefined;
  6394. }
  6395. return {
  6396. documentElement
  6397. };
  6398. }
  6399. onResolveEntity(name) {
  6400. switch (name) {
  6401. case "apos":
  6402. return "'";
  6403. }
  6404. return super.onResolveEntity(name);
  6405. }
  6406. onText(text) {
  6407. if (isWhitespaceString(text)) {
  6408. return;
  6409. }
  6410. const node = new SimpleDOMNode("#text", text);
  6411. this._currentFragment.push(node);
  6412. }
  6413. onCdata(text) {
  6414. const node = new SimpleDOMNode("#text", text);
  6415. this._currentFragment.push(node);
  6416. }
  6417. onBeginElement(name, attributes, isEmpty) {
  6418. const node = new SimpleDOMNode(name);
  6419. node.childNodes = [];
  6420. this._currentFragment.push(node);
  6421. if (isEmpty) {
  6422. return;
  6423. }
  6424. this._stack.push(this._currentFragment);
  6425. this._currentFragment = node.childNodes;
  6426. }
  6427. onEndElement(name) {
  6428. this._currentFragment = this._stack.pop() || [];
  6429. const lastElement = this._currentFragment[this._currentFragment.length - 1];
  6430. if (!lastElement) {
  6431. return;
  6432. }
  6433. for (let i = 0, ii = lastElement.childNodes.length; i < ii; i++) {
  6434. lastElement.childNodes[i].parentNode = lastElement;
  6435. }
  6436. }
  6437. onError(code) {
  6438. this._errorCode = code;
  6439. }
  6440. }
  6441. exports.SimpleXMLParser = SimpleXMLParser;
  6442. /***/ }),
  6443. /* 14 */
  6444. /***/ (function(module, exports, __w_pdfjs_require__) {
  6445. "use strict";
  6446. Object.defineProperty(exports, "__esModule", {
  6447. value: true
  6448. });
  6449. exports.PDFDataTransportStream = void 0;
  6450. var _util = __w_pdfjs_require__(1);
  6451. class PDFDataTransportStream {
  6452. constructor(params, pdfDataRangeTransport) {
  6453. (0, _util.assert)(pdfDataRangeTransport);
  6454. this._queuedChunks = [];
  6455. this._progressiveDone = params.progressiveDone || false;
  6456. const initialData = params.initialData;
  6457. if (initialData && initialData.length > 0) {
  6458. const buffer = new Uint8Array(initialData).buffer;
  6459. this._queuedChunks.push(buffer);
  6460. }
  6461. this._pdfDataRangeTransport = pdfDataRangeTransport;
  6462. this._isStreamingSupported = !params.disableStream;
  6463. this._isRangeSupported = !params.disableRange;
  6464. this._contentLength = params.length;
  6465. this._fullRequestReader = null;
  6466. this._rangeReaders = [];
  6467. this._pdfDataRangeTransport.addRangeListener((begin, chunk) => {
  6468. this._onReceiveData({
  6469. begin,
  6470. chunk
  6471. });
  6472. });
  6473. this._pdfDataRangeTransport.addProgressListener((loaded, total) => {
  6474. this._onProgress({
  6475. loaded,
  6476. total
  6477. });
  6478. });
  6479. this._pdfDataRangeTransport.addProgressiveReadListener(chunk => {
  6480. this._onReceiveData({
  6481. chunk
  6482. });
  6483. });
  6484. this._pdfDataRangeTransport.addProgressiveDoneListener(() => {
  6485. this._onProgressiveDone();
  6486. });
  6487. this._pdfDataRangeTransport.transportReady();
  6488. }
  6489. _onReceiveData(args) {
  6490. const buffer = new Uint8Array(args.chunk).buffer;
  6491. if (args.begin === undefined) {
  6492. if (this._fullRequestReader) {
  6493. this._fullRequestReader._enqueue(buffer);
  6494. } else {
  6495. this._queuedChunks.push(buffer);
  6496. }
  6497. } else {
  6498. const found = this._rangeReaders.some(function (rangeReader) {
  6499. if (rangeReader._begin !== args.begin) {
  6500. return false;
  6501. }
  6502. rangeReader._enqueue(buffer);
  6503. return true;
  6504. });
  6505. (0, _util.assert)(found);
  6506. }
  6507. }
  6508. get _progressiveDataLength() {
  6509. return this._fullRequestReader ? this._fullRequestReader._loaded : 0;
  6510. }
  6511. _onProgress(evt) {
  6512. if (evt.total === undefined) {
  6513. const firstReader = this._rangeReaders[0];
  6514. if (firstReader && firstReader.onProgress) {
  6515. firstReader.onProgress({
  6516. loaded: evt.loaded
  6517. });
  6518. }
  6519. } else {
  6520. const fullReader = this._fullRequestReader;
  6521. if (fullReader && fullReader.onProgress) {
  6522. fullReader.onProgress({
  6523. loaded: evt.loaded,
  6524. total: evt.total
  6525. });
  6526. }
  6527. }
  6528. }
  6529. _onProgressiveDone() {
  6530. if (this._fullRequestReader) {
  6531. this._fullRequestReader.progressiveDone();
  6532. }
  6533. this._progressiveDone = true;
  6534. }
  6535. _removeRangeReader(reader) {
  6536. const i = this._rangeReaders.indexOf(reader);
  6537. if (i >= 0) {
  6538. this._rangeReaders.splice(i, 1);
  6539. }
  6540. }
  6541. getFullReader() {
  6542. (0, _util.assert)(!this._fullRequestReader);
  6543. const queuedChunks = this._queuedChunks;
  6544. this._queuedChunks = null;
  6545. return new PDFDataTransportStreamReader(this, queuedChunks, this._progressiveDone);
  6546. }
  6547. getRangeReader(begin, end) {
  6548. if (end <= this._progressiveDataLength) {
  6549. return null;
  6550. }
  6551. const reader = new PDFDataTransportStreamRangeReader(this, begin, end);
  6552. this._pdfDataRangeTransport.requestDataRange(begin, end);
  6553. this._rangeReaders.push(reader);
  6554. return reader;
  6555. }
  6556. cancelAllRequests(reason) {
  6557. if (this._fullRequestReader) {
  6558. this._fullRequestReader.cancel(reason);
  6559. }
  6560. const readers = this._rangeReaders.slice(0);
  6561. readers.forEach(function (rangeReader) {
  6562. rangeReader.cancel(reason);
  6563. });
  6564. this._pdfDataRangeTransport.abort();
  6565. }
  6566. }
  6567. exports.PDFDataTransportStream = PDFDataTransportStream;
  6568. class PDFDataTransportStreamReader {
  6569. constructor(stream, queuedChunks, progressiveDone = false) {
  6570. this._stream = stream;
  6571. this._done = progressiveDone || false;
  6572. this._filename = null;
  6573. this._queuedChunks = queuedChunks || [];
  6574. this._loaded = 0;
  6575. for (const chunk of this._queuedChunks) {
  6576. this._loaded += chunk.byteLength;
  6577. }
  6578. this._requests = [];
  6579. this._headersReady = Promise.resolve();
  6580. stream._fullRequestReader = this;
  6581. this.onProgress = null;
  6582. }
  6583. _enqueue(chunk) {
  6584. if (this._done) {
  6585. return;
  6586. }
  6587. if (this._requests.length > 0) {
  6588. const requestCapability = this._requests.shift();
  6589. requestCapability.resolve({
  6590. value: chunk,
  6591. done: false
  6592. });
  6593. } else {
  6594. this._queuedChunks.push(chunk);
  6595. }
  6596. this._loaded += chunk.byteLength;
  6597. }
  6598. get headersReady() {
  6599. return this._headersReady;
  6600. }
  6601. get filename() {
  6602. return this._filename;
  6603. }
  6604. get isRangeSupported() {
  6605. return this._stream._isRangeSupported;
  6606. }
  6607. get isStreamingSupported() {
  6608. return this._stream._isStreamingSupported;
  6609. }
  6610. get contentLength() {
  6611. return this._stream._contentLength;
  6612. }
  6613. async read() {
  6614. if (this._queuedChunks.length > 0) {
  6615. const chunk = this._queuedChunks.shift();
  6616. return {
  6617. value: chunk,
  6618. done: false
  6619. };
  6620. }
  6621. if (this._done) {
  6622. return {
  6623. value: undefined,
  6624. done: true
  6625. };
  6626. }
  6627. const requestCapability = (0, _util.createPromiseCapability)();
  6628. this._requests.push(requestCapability);
  6629. return requestCapability.promise;
  6630. }
  6631. cancel(reason) {
  6632. this._done = true;
  6633. this._requests.forEach(function (requestCapability) {
  6634. requestCapability.resolve({
  6635. value: undefined,
  6636. done: true
  6637. });
  6638. });
  6639. this._requests = [];
  6640. }
  6641. progressiveDone() {
  6642. if (this._done) {
  6643. return;
  6644. }
  6645. this._done = true;
  6646. }
  6647. }
  6648. class PDFDataTransportStreamRangeReader {
  6649. constructor(stream, begin, end) {
  6650. this._stream = stream;
  6651. this._begin = begin;
  6652. this._end = end;
  6653. this._queuedChunk = null;
  6654. this._requests = [];
  6655. this._done = false;
  6656. this.onProgress = null;
  6657. }
  6658. _enqueue(chunk) {
  6659. if (this._done) {
  6660. return;
  6661. }
  6662. if (this._requests.length === 0) {
  6663. this._queuedChunk = chunk;
  6664. } else {
  6665. const requestsCapability = this._requests.shift();
  6666. requestsCapability.resolve({
  6667. value: chunk,
  6668. done: false
  6669. });
  6670. this._requests.forEach(function (requestCapability) {
  6671. requestCapability.resolve({
  6672. value: undefined,
  6673. done: true
  6674. });
  6675. });
  6676. this._requests = [];
  6677. }
  6678. this._done = true;
  6679. this._stream._removeRangeReader(this);
  6680. }
  6681. get isStreamingSupported() {
  6682. return false;
  6683. }
  6684. async read() {
  6685. if (this._queuedChunk) {
  6686. const chunk = this._queuedChunk;
  6687. this._queuedChunk = null;
  6688. return {
  6689. value: chunk,
  6690. done: false
  6691. };
  6692. }
  6693. if (this._done) {
  6694. return {
  6695. value: undefined,
  6696. done: true
  6697. };
  6698. }
  6699. const requestCapability = (0, _util.createPromiseCapability)();
  6700. this._requests.push(requestCapability);
  6701. return requestCapability.promise;
  6702. }
  6703. cancel(reason) {
  6704. this._done = true;
  6705. this._requests.forEach(function (requestCapability) {
  6706. requestCapability.resolve({
  6707. value: undefined,
  6708. done: true
  6709. });
  6710. });
  6711. this._requests = [];
  6712. this._stream._removeRangeReader(this);
  6713. }
  6714. }
  6715. /***/ }),
  6716. /* 15 */
  6717. /***/ (function(module, exports, __w_pdfjs_require__) {
  6718. "use strict";
  6719. Object.defineProperty(exports, "__esModule", {
  6720. value: true
  6721. });
  6722. exports.WebGLContext = void 0;
  6723. var _util = __w_pdfjs_require__(1);
  6724. class WebGLContext {
  6725. constructor({
  6726. enable = false
  6727. }) {
  6728. this._enabled = enable === true;
  6729. }
  6730. get isEnabled() {
  6731. let enabled = this._enabled;
  6732. if (enabled) {
  6733. enabled = WebGLUtils.tryInitGL();
  6734. }
  6735. return (0, _util.shadow)(this, "isEnabled", enabled);
  6736. }
  6737. composeSMask({
  6738. layer,
  6739. mask,
  6740. properties
  6741. }) {
  6742. return WebGLUtils.composeSMask(layer, mask, properties);
  6743. }
  6744. drawFigures({
  6745. width,
  6746. height,
  6747. backgroundColor,
  6748. figures,
  6749. context
  6750. }) {
  6751. return WebGLUtils.drawFigures(width, height, backgroundColor, figures, context);
  6752. }
  6753. clear() {
  6754. WebGLUtils.cleanup();
  6755. }
  6756. }
  6757. exports.WebGLContext = WebGLContext;
  6758. var WebGLUtils = function WebGLUtilsClosure() {
  6759. function loadShader(gl, code, shaderType) {
  6760. var shader = gl.createShader(shaderType);
  6761. gl.shaderSource(shader, code);
  6762. gl.compileShader(shader);
  6763. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  6764. if (!compiled) {
  6765. var errorMsg = gl.getShaderInfoLog(shader);
  6766. throw new Error("Error during shader compilation: " + errorMsg);
  6767. }
  6768. return shader;
  6769. }
  6770. function createVertexShader(gl, code) {
  6771. return loadShader(gl, code, gl.VERTEX_SHADER);
  6772. }
  6773. function createFragmentShader(gl, code) {
  6774. return loadShader(gl, code, gl.FRAGMENT_SHADER);
  6775. }
  6776. function createProgram(gl, shaders) {
  6777. var program = gl.createProgram();
  6778. for (var i = 0, ii = shaders.length; i < ii; ++i) {
  6779. gl.attachShader(program, shaders[i]);
  6780. }
  6781. gl.linkProgram(program);
  6782. var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  6783. if (!linked) {
  6784. var errorMsg = gl.getProgramInfoLog(program);
  6785. throw new Error("Error during program linking: " + errorMsg);
  6786. }
  6787. return program;
  6788. }
  6789. function createTexture(gl, image, textureId) {
  6790. gl.activeTexture(textureId);
  6791. var texture = gl.createTexture();
  6792. gl.bindTexture(gl.TEXTURE_2D, texture);
  6793. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  6794. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  6795. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  6796. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  6797. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  6798. return texture;
  6799. }
  6800. var currentGL, currentCanvas;
  6801. function generateGL() {
  6802. if (currentGL) {
  6803. return;
  6804. }
  6805. currentCanvas = document.createElement("canvas");
  6806. currentGL = currentCanvas.getContext("webgl", {
  6807. premultipliedalpha: false
  6808. });
  6809. }
  6810. var smaskVertexShaderCode = "\
  6811. attribute vec2 a_position; \
  6812. attribute vec2 a_texCoord; \
  6813. \
  6814. uniform vec2 u_resolution; \
  6815. \
  6816. varying vec2 v_texCoord; \
  6817. \
  6818. void main() { \
  6819. vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
  6820. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  6821. \
  6822. v_texCoord = a_texCoord; \
  6823. } ";
  6824. var smaskFragmentShaderCode = "\
  6825. precision mediump float; \
  6826. \
  6827. uniform vec4 u_backdrop; \
  6828. uniform int u_subtype; \
  6829. uniform sampler2D u_image; \
  6830. uniform sampler2D u_mask; \
  6831. \
  6832. varying vec2 v_texCoord; \
  6833. \
  6834. void main() { \
  6835. vec4 imageColor = texture2D(u_image, v_texCoord); \
  6836. vec4 maskColor = texture2D(u_mask, v_texCoord); \
  6837. if (u_backdrop.a > 0.0) { \
  6838. maskColor.rgb = maskColor.rgb * maskColor.a + \
  6839. u_backdrop.rgb * (1.0 - maskColor.a); \
  6840. } \
  6841. float lum; \
  6842. if (u_subtype == 0) { \
  6843. lum = maskColor.a; \
  6844. } else { \
  6845. lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
  6846. maskColor.b * 0.11; \
  6847. } \
  6848. imageColor.a *= lum; \
  6849. imageColor.rgb *= imageColor.a; \
  6850. gl_FragColor = imageColor; \
  6851. } ";
  6852. var smaskCache = null;
  6853. function initSmaskGL() {
  6854. var canvas, gl;
  6855. generateGL();
  6856. canvas = currentCanvas;
  6857. currentCanvas = null;
  6858. gl = currentGL;
  6859. currentGL = null;
  6860. var vertexShader = createVertexShader(gl, smaskVertexShaderCode);
  6861. var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
  6862. var program = createProgram(gl, [vertexShader, fragmentShader]);
  6863. gl.useProgram(program);
  6864. var cache = {};
  6865. cache.gl = gl;
  6866. cache.canvas = canvas;
  6867. cache.resolutionLocation = gl.getUniformLocation(program, "u_resolution");
  6868. cache.positionLocation = gl.getAttribLocation(program, "a_position");
  6869. cache.backdropLocation = gl.getUniformLocation(program, "u_backdrop");
  6870. cache.subtypeLocation = gl.getUniformLocation(program, "u_subtype");
  6871. var texCoordLocation = gl.getAttribLocation(program, "a_texCoord");
  6872. var texLayerLocation = gl.getUniformLocation(program, "u_image");
  6873. var texMaskLocation = gl.getUniformLocation(program, "u_mask");
  6874. var texCoordBuffer = gl.createBuffer();
  6875. gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
  6876. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0]), gl.STATIC_DRAW);
  6877. gl.enableVertexAttribArray(texCoordLocation);
  6878. gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
  6879. gl.uniform1i(texLayerLocation, 0);
  6880. gl.uniform1i(texMaskLocation, 1);
  6881. smaskCache = cache;
  6882. }
  6883. function composeSMask(layer, mask, properties) {
  6884. var width = layer.width,
  6885. height = layer.height;
  6886. if (!smaskCache) {
  6887. initSmaskGL();
  6888. }
  6889. var cache = smaskCache,
  6890. canvas = cache.canvas,
  6891. gl = cache.gl;
  6892. canvas.width = width;
  6893. canvas.height = height;
  6894. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  6895. gl.uniform2f(cache.resolutionLocation, width, height);
  6896. if (properties.backdrop) {
  6897. gl.uniform4f(cache.resolutionLocation, properties.backdrop[0], properties.backdrop[1], properties.backdrop[2], 1);
  6898. } else {
  6899. gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
  6900. }
  6901. gl.uniform1i(cache.subtypeLocation, properties.subtype === "Luminosity" ? 1 : 0);
  6902. var texture = createTexture(gl, layer, gl.TEXTURE0);
  6903. var maskTexture = createTexture(gl, mask, gl.TEXTURE1);
  6904. var buffer = gl.createBuffer();
  6905. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  6906. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0, 0, width, 0, 0, height, 0, height, width, 0, width, height]), gl.STATIC_DRAW);
  6907. gl.enableVertexAttribArray(cache.positionLocation);
  6908. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  6909. gl.clearColor(0, 0, 0, 0);
  6910. gl.enable(gl.BLEND);
  6911. gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  6912. gl.clear(gl.COLOR_BUFFER_BIT);
  6913. gl.drawArrays(gl.TRIANGLES, 0, 6);
  6914. gl.flush();
  6915. gl.deleteTexture(texture);
  6916. gl.deleteTexture(maskTexture);
  6917. gl.deleteBuffer(buffer);
  6918. return canvas;
  6919. }
  6920. var figuresVertexShaderCode = "\
  6921. attribute vec2 a_position; \
  6922. attribute vec3 a_color; \
  6923. \
  6924. uniform vec2 u_resolution; \
  6925. uniform vec2 u_scale; \
  6926. uniform vec2 u_offset; \
  6927. \
  6928. varying vec4 v_color; \
  6929. \
  6930. void main() { \
  6931. vec2 position = (a_position + u_offset) * u_scale; \
  6932. vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
  6933. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  6934. \
  6935. v_color = vec4(a_color / 255.0, 1.0); \
  6936. } ";
  6937. var figuresFragmentShaderCode = "\
  6938. precision mediump float; \
  6939. \
  6940. varying vec4 v_color; \
  6941. \
  6942. void main() { \
  6943. gl_FragColor = v_color; \
  6944. } ";
  6945. var figuresCache = null;
  6946. function initFiguresGL() {
  6947. var canvas, gl;
  6948. generateGL();
  6949. canvas = currentCanvas;
  6950. currentCanvas = null;
  6951. gl = currentGL;
  6952. currentGL = null;
  6953. var vertexShader = createVertexShader(gl, figuresVertexShaderCode);
  6954. var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
  6955. var program = createProgram(gl, [vertexShader, fragmentShader]);
  6956. gl.useProgram(program);
  6957. var cache = {};
  6958. cache.gl = gl;
  6959. cache.canvas = canvas;
  6960. cache.resolutionLocation = gl.getUniformLocation(program, "u_resolution");
  6961. cache.scaleLocation = gl.getUniformLocation(program, "u_scale");
  6962. cache.offsetLocation = gl.getUniformLocation(program, "u_offset");
  6963. cache.positionLocation = gl.getAttribLocation(program, "a_position");
  6964. cache.colorLocation = gl.getAttribLocation(program, "a_color");
  6965. figuresCache = cache;
  6966. }
  6967. function drawFigures(width, height, backgroundColor, figures, context) {
  6968. if (!figuresCache) {
  6969. initFiguresGL();
  6970. }
  6971. var cache = figuresCache,
  6972. canvas = cache.canvas,
  6973. gl = cache.gl;
  6974. canvas.width = width;
  6975. canvas.height = height;
  6976. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  6977. gl.uniform2f(cache.resolutionLocation, width, height);
  6978. var count = 0;
  6979. var i, ii, rows;
  6980. for (i = 0, ii = figures.length; i < ii; i++) {
  6981. switch (figures[i].type) {
  6982. case "lattice":
  6983. rows = figures[i].coords.length / figures[i].verticesPerRow | 0;
  6984. count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
  6985. break;
  6986. case "triangles":
  6987. count += figures[i].coords.length;
  6988. break;
  6989. }
  6990. }
  6991. var coords = new Float32Array(count * 2);
  6992. var colors = new Uint8Array(count * 3);
  6993. var coordsMap = context.coords,
  6994. colorsMap = context.colors;
  6995. var pIndex = 0,
  6996. cIndex = 0;
  6997. for (i = 0, ii = figures.length; i < ii; i++) {
  6998. var figure = figures[i],
  6999. ps = figure.coords,
  7000. cs = figure.colors;
  7001. switch (figure.type) {
  7002. case "lattice":
  7003. var cols = figure.verticesPerRow;
  7004. rows = ps.length / cols | 0;
  7005. for (var row = 1; row < rows; row++) {
  7006. var offset = row * cols + 1;
  7007. for (var col = 1; col < cols; col++, offset++) {
  7008. coords[pIndex] = coordsMap[ps[offset - cols - 1]];
  7009. coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
  7010. coords[pIndex + 2] = coordsMap[ps[offset - cols]];
  7011. coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
  7012. coords[pIndex + 4] = coordsMap[ps[offset - 1]];
  7013. coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
  7014. colors[cIndex] = colorsMap[cs[offset - cols - 1]];
  7015. colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
  7016. colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
  7017. colors[cIndex + 3] = colorsMap[cs[offset - cols]];
  7018. colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
  7019. colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
  7020. colors[cIndex + 6] = colorsMap[cs[offset - 1]];
  7021. colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
  7022. colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
  7023. coords[pIndex + 6] = coords[pIndex + 2];
  7024. coords[pIndex + 7] = coords[pIndex + 3];
  7025. coords[pIndex + 8] = coords[pIndex + 4];
  7026. coords[pIndex + 9] = coords[pIndex + 5];
  7027. coords[pIndex + 10] = coordsMap[ps[offset]];
  7028. coords[pIndex + 11] = coordsMap[ps[offset] + 1];
  7029. colors[cIndex + 9] = colors[cIndex + 3];
  7030. colors[cIndex + 10] = colors[cIndex + 4];
  7031. colors[cIndex + 11] = colors[cIndex + 5];
  7032. colors[cIndex + 12] = colors[cIndex + 6];
  7033. colors[cIndex + 13] = colors[cIndex + 7];
  7034. colors[cIndex + 14] = colors[cIndex + 8];
  7035. colors[cIndex + 15] = colorsMap[cs[offset]];
  7036. colors[cIndex + 16] = colorsMap[cs[offset] + 1];
  7037. colors[cIndex + 17] = colorsMap[cs[offset] + 2];
  7038. pIndex += 12;
  7039. cIndex += 18;
  7040. }
  7041. }
  7042. break;
  7043. case "triangles":
  7044. for (var j = 0, jj = ps.length; j < jj; j++) {
  7045. coords[pIndex] = coordsMap[ps[j]];
  7046. coords[pIndex + 1] = coordsMap[ps[j] + 1];
  7047. colors[cIndex] = colorsMap[cs[j]];
  7048. colors[cIndex + 1] = colorsMap[cs[j] + 1];
  7049. colors[cIndex + 2] = colorsMap[cs[j] + 2];
  7050. pIndex += 2;
  7051. cIndex += 3;
  7052. }
  7053. break;
  7054. }
  7055. }
  7056. if (backgroundColor) {
  7057. gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255, backgroundColor[2] / 255, 1.0);
  7058. } else {
  7059. gl.clearColor(0, 0, 0, 0);
  7060. }
  7061. gl.clear(gl.COLOR_BUFFER_BIT);
  7062. var coordsBuffer = gl.createBuffer();
  7063. gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
  7064. gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
  7065. gl.enableVertexAttribArray(cache.positionLocation);
  7066. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  7067. var colorsBuffer = gl.createBuffer();
  7068. gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
  7069. gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
  7070. gl.enableVertexAttribArray(cache.colorLocation);
  7071. gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false, 0, 0);
  7072. gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
  7073. gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
  7074. gl.drawArrays(gl.TRIANGLES, 0, count);
  7075. gl.flush();
  7076. gl.deleteBuffer(coordsBuffer);
  7077. gl.deleteBuffer(colorsBuffer);
  7078. return canvas;
  7079. }
  7080. return {
  7081. tryInitGL() {
  7082. try {
  7083. generateGL();
  7084. return !!currentGL;
  7085. } catch (ex) {}
  7086. return false;
  7087. },
  7088. composeSMask,
  7089. drawFigures,
  7090. cleanup() {
  7091. if (smaskCache && smaskCache.canvas) {
  7092. smaskCache.canvas.width = 0;
  7093. smaskCache.canvas.height = 0;
  7094. }
  7095. if (figuresCache && figuresCache.canvas) {
  7096. figuresCache.canvas.width = 0;
  7097. figuresCache.canvas.height = 0;
  7098. }
  7099. smaskCache = null;
  7100. figuresCache = null;
  7101. }
  7102. };
  7103. }();
  7104. /***/ }),
  7105. /* 16 */
  7106. /***/ (function(module, exports, __w_pdfjs_require__) {
  7107. "use strict";
  7108. Object.defineProperty(exports, "__esModule", {
  7109. value: true
  7110. });
  7111. exports.renderTextLayer = void 0;
  7112. var _util = __w_pdfjs_require__(1);
  7113. var renderTextLayer = function renderTextLayerClosure() {
  7114. var MAX_TEXT_DIVS_TO_RENDER = 100000;
  7115. var NonWhitespaceRegexp = /\S/;
  7116. function isAllWhitespace(str) {
  7117. return !NonWhitespaceRegexp.test(str);
  7118. }
  7119. function appendText(task, geom, styles) {
  7120. var textDiv = document.createElement("span");
  7121. var textDivProperties = {
  7122. angle: 0,
  7123. canvasWidth: 0,
  7124. isWhitespace: false,
  7125. originalTransform: null,
  7126. paddingBottom: 0,
  7127. paddingLeft: 0,
  7128. paddingRight: 0,
  7129. paddingTop: 0,
  7130. scale: 1
  7131. };
  7132. task._textDivs.push(textDiv);
  7133. if (isAllWhitespace(geom.str)) {
  7134. textDivProperties.isWhitespace = true;
  7135. task._textDivProperties.set(textDiv, textDivProperties);
  7136. return;
  7137. }
  7138. var tx = _util.Util.transform(task._viewport.transform, geom.transform);
  7139. var angle = Math.atan2(tx[1], tx[0]);
  7140. var style = styles[geom.fontName];
  7141. if (style.vertical) {
  7142. angle += Math.PI / 2;
  7143. }
  7144. var fontHeight = Math.sqrt(tx[2] * tx[2] + tx[3] * tx[3]);
  7145. var fontAscent = fontHeight;
  7146. if (style.ascent) {
  7147. fontAscent = style.ascent * fontAscent;
  7148. } else if (style.descent) {
  7149. fontAscent = (1 + style.descent) * fontAscent;
  7150. }
  7151. let left, top;
  7152. if (angle === 0) {
  7153. left = tx[4];
  7154. top = tx[5] - fontAscent;
  7155. } else {
  7156. left = tx[4] + fontAscent * Math.sin(angle);
  7157. top = tx[5] - fontAscent * Math.cos(angle);
  7158. }
  7159. textDiv.style.left = `${left}px`;
  7160. textDiv.style.top = `${top}px`;
  7161. textDiv.style.fontSize = `${fontHeight}px`;
  7162. textDiv.style.fontFamily = style.fontFamily;
  7163. textDiv.textContent = geom.str;
  7164. if (task._fontInspectorEnabled) {
  7165. textDiv.dataset.fontName = geom.fontName;
  7166. }
  7167. if (angle !== 0) {
  7168. textDivProperties.angle = angle * (180 / Math.PI);
  7169. }
  7170. if (geom.str.length > 1) {
  7171. if (style.vertical) {
  7172. textDivProperties.canvasWidth = geom.height * task._viewport.scale;
  7173. } else {
  7174. textDivProperties.canvasWidth = geom.width * task._viewport.scale;
  7175. }
  7176. }
  7177. task._textDivProperties.set(textDiv, textDivProperties);
  7178. if (task._textContentStream) {
  7179. task._layoutText(textDiv);
  7180. }
  7181. if (task._enhanceTextSelection) {
  7182. var angleCos = 1,
  7183. angleSin = 0;
  7184. if (angle !== 0) {
  7185. angleCos = Math.cos(angle);
  7186. angleSin = Math.sin(angle);
  7187. }
  7188. var divWidth = (style.vertical ? geom.height : geom.width) * task._viewport.scale;
  7189. var divHeight = fontHeight;
  7190. var m, b;
  7191. if (angle !== 0) {
  7192. m = [angleCos, angleSin, -angleSin, angleCos, left, top];
  7193. b = _util.Util.getAxialAlignedBoundingBox([0, 0, divWidth, divHeight], m);
  7194. } else {
  7195. b = [left, top, left + divWidth, top + divHeight];
  7196. }
  7197. task._bounds.push({
  7198. left: b[0],
  7199. top: b[1],
  7200. right: b[2],
  7201. bottom: b[3],
  7202. div: textDiv,
  7203. size: [divWidth, divHeight],
  7204. m
  7205. });
  7206. }
  7207. }
  7208. function render(task) {
  7209. if (task._canceled) {
  7210. return;
  7211. }
  7212. var textDivs = task._textDivs;
  7213. var capability = task._capability;
  7214. var textDivsLength = textDivs.length;
  7215. if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
  7216. task._renderingDone = true;
  7217. capability.resolve();
  7218. return;
  7219. }
  7220. if (!task._textContentStream) {
  7221. for (var i = 0; i < textDivsLength; i++) {
  7222. task._layoutText(textDivs[i]);
  7223. }
  7224. }
  7225. task._renderingDone = true;
  7226. capability.resolve();
  7227. }
  7228. function expand(task) {
  7229. var bounds = task._bounds;
  7230. var viewport = task._viewport;
  7231. var expanded = expandBounds(viewport.width, viewport.height, bounds);
  7232. for (var i = 0; i < expanded.length; i++) {
  7233. var div = bounds[i].div;
  7234. var divProperties = task._textDivProperties.get(div);
  7235. if (divProperties.angle === 0) {
  7236. divProperties.paddingLeft = bounds[i].left - expanded[i].left;
  7237. divProperties.paddingTop = bounds[i].top - expanded[i].top;
  7238. divProperties.paddingRight = expanded[i].right - bounds[i].right;
  7239. divProperties.paddingBottom = expanded[i].bottom - bounds[i].bottom;
  7240. task._textDivProperties.set(div, divProperties);
  7241. continue;
  7242. }
  7243. var e = expanded[i],
  7244. b = bounds[i];
  7245. var m = b.m,
  7246. c = m[0],
  7247. s = m[1];
  7248. var points = [[0, 0], [0, b.size[1]], [b.size[0], 0], b.size];
  7249. var ts = new Float64Array(64);
  7250. points.forEach(function (p, i) {
  7251. var t = _util.Util.applyTransform(p, m);
  7252. ts[i + 0] = c && (e.left - t[0]) / c;
  7253. ts[i + 4] = s && (e.top - t[1]) / s;
  7254. ts[i + 8] = c && (e.right - t[0]) / c;
  7255. ts[i + 12] = s && (e.bottom - t[1]) / s;
  7256. ts[i + 16] = s && (e.left - t[0]) / -s;
  7257. ts[i + 20] = c && (e.top - t[1]) / c;
  7258. ts[i + 24] = s && (e.right - t[0]) / -s;
  7259. ts[i + 28] = c && (e.bottom - t[1]) / c;
  7260. ts[i + 32] = c && (e.left - t[0]) / -c;
  7261. ts[i + 36] = s && (e.top - t[1]) / -s;
  7262. ts[i + 40] = c && (e.right - t[0]) / -c;
  7263. ts[i + 44] = s && (e.bottom - t[1]) / -s;
  7264. ts[i + 48] = s && (e.left - t[0]) / s;
  7265. ts[i + 52] = c && (e.top - t[1]) / -c;
  7266. ts[i + 56] = s && (e.right - t[0]) / s;
  7267. ts[i + 60] = c && (e.bottom - t[1]) / -c;
  7268. });
  7269. var findPositiveMin = function (ts, offset, count) {
  7270. var result = 0;
  7271. for (var i = 0; i < count; i++) {
  7272. var t = ts[offset++];
  7273. if (t > 0) {
  7274. result = result ? Math.min(t, result) : t;
  7275. }
  7276. }
  7277. return result;
  7278. };
  7279. var boxScale = 1 + Math.min(Math.abs(c), Math.abs(s));
  7280. divProperties.paddingLeft = findPositiveMin(ts, 32, 16) / boxScale;
  7281. divProperties.paddingTop = findPositiveMin(ts, 48, 16) / boxScale;
  7282. divProperties.paddingRight = findPositiveMin(ts, 0, 16) / boxScale;
  7283. divProperties.paddingBottom = findPositiveMin(ts, 16, 16) / boxScale;
  7284. task._textDivProperties.set(div, divProperties);
  7285. }
  7286. }
  7287. function expandBounds(width, height, boxes) {
  7288. var bounds = boxes.map(function (box, i) {
  7289. return {
  7290. x1: box.left,
  7291. y1: box.top,
  7292. x2: box.right,
  7293. y2: box.bottom,
  7294. index: i,
  7295. x1New: undefined,
  7296. x2New: undefined
  7297. };
  7298. });
  7299. expandBoundsLTR(width, bounds);
  7300. var expanded = new Array(boxes.length);
  7301. bounds.forEach(function (b) {
  7302. var i = b.index;
  7303. expanded[i] = {
  7304. left: b.x1New,
  7305. top: 0,
  7306. right: b.x2New,
  7307. bottom: 0
  7308. };
  7309. });
  7310. boxes.map(function (box, i) {
  7311. var e = expanded[i],
  7312. b = bounds[i];
  7313. b.x1 = box.top;
  7314. b.y1 = width - e.right;
  7315. b.x2 = box.bottom;
  7316. b.y2 = width - e.left;
  7317. b.index = i;
  7318. b.x1New = undefined;
  7319. b.x2New = undefined;
  7320. });
  7321. expandBoundsLTR(height, bounds);
  7322. bounds.forEach(function (b) {
  7323. var i = b.index;
  7324. expanded[i].top = b.x1New;
  7325. expanded[i].bottom = b.x2New;
  7326. });
  7327. return expanded;
  7328. }
  7329. function expandBoundsLTR(width, bounds) {
  7330. bounds.sort(function (a, b) {
  7331. return a.x1 - b.x1 || a.index - b.index;
  7332. });
  7333. var fakeBoundary = {
  7334. x1: -Infinity,
  7335. y1: -Infinity,
  7336. x2: 0,
  7337. y2: Infinity,
  7338. index: -1,
  7339. x1New: 0,
  7340. x2New: 0
  7341. };
  7342. var horizon = [{
  7343. start: -Infinity,
  7344. end: Infinity,
  7345. boundary: fakeBoundary
  7346. }];
  7347. bounds.forEach(function (boundary) {
  7348. var i = 0;
  7349. while (i < horizon.length && horizon[i].end <= boundary.y1) {
  7350. i++;
  7351. }
  7352. var j = horizon.length - 1;
  7353. while (j >= 0 && horizon[j].start >= boundary.y2) {
  7354. j--;
  7355. }
  7356. var horizonPart, affectedBoundary;
  7357. var q,
  7358. k,
  7359. maxXNew = -Infinity;
  7360. for (q = i; q <= j; q++) {
  7361. horizonPart = horizon[q];
  7362. affectedBoundary = horizonPart.boundary;
  7363. var xNew;
  7364. if (affectedBoundary.x2 > boundary.x1) {
  7365. xNew = affectedBoundary.index > boundary.index ? affectedBoundary.x1New : boundary.x1;
  7366. } else if (affectedBoundary.x2New === undefined) {
  7367. xNew = (affectedBoundary.x2 + boundary.x1) / 2;
  7368. } else {
  7369. xNew = affectedBoundary.x2New;
  7370. }
  7371. if (xNew > maxXNew) {
  7372. maxXNew = xNew;
  7373. }
  7374. }
  7375. boundary.x1New = maxXNew;
  7376. for (q = i; q <= j; q++) {
  7377. horizonPart = horizon[q];
  7378. affectedBoundary = horizonPart.boundary;
  7379. if (affectedBoundary.x2New === undefined) {
  7380. if (affectedBoundary.x2 > boundary.x1) {
  7381. if (affectedBoundary.index > boundary.index) {
  7382. affectedBoundary.x2New = affectedBoundary.x2;
  7383. }
  7384. } else {
  7385. affectedBoundary.x2New = maxXNew;
  7386. }
  7387. } else if (affectedBoundary.x2New > maxXNew) {
  7388. affectedBoundary.x2New = Math.max(maxXNew, affectedBoundary.x2);
  7389. }
  7390. }
  7391. var changedHorizon = [],
  7392. lastBoundary = null;
  7393. for (q = i; q <= j; q++) {
  7394. horizonPart = horizon[q];
  7395. affectedBoundary = horizonPart.boundary;
  7396. var useBoundary = affectedBoundary.x2 > boundary.x2 ? affectedBoundary : boundary;
  7397. if (lastBoundary === useBoundary) {
  7398. changedHorizon[changedHorizon.length - 1].end = horizonPart.end;
  7399. } else {
  7400. changedHorizon.push({
  7401. start: horizonPart.start,
  7402. end: horizonPart.end,
  7403. boundary: useBoundary
  7404. });
  7405. lastBoundary = useBoundary;
  7406. }
  7407. }
  7408. if (horizon[i].start < boundary.y1) {
  7409. changedHorizon[0].start = boundary.y1;
  7410. changedHorizon.unshift({
  7411. start: horizon[i].start,
  7412. end: boundary.y1,
  7413. boundary: horizon[i].boundary
  7414. });
  7415. }
  7416. if (boundary.y2 < horizon[j].end) {
  7417. changedHorizon[changedHorizon.length - 1].end = boundary.y2;
  7418. changedHorizon.push({
  7419. start: boundary.y2,
  7420. end: horizon[j].end,
  7421. boundary: horizon[j].boundary
  7422. });
  7423. }
  7424. for (q = i; q <= j; q++) {
  7425. horizonPart = horizon[q];
  7426. affectedBoundary = horizonPart.boundary;
  7427. if (affectedBoundary.x2New !== undefined) {
  7428. continue;
  7429. }
  7430. var used = false;
  7431. for (k = i - 1; !used && k >= 0 && horizon[k].start >= affectedBoundary.y1; k--) {
  7432. used = horizon[k].boundary === affectedBoundary;
  7433. }
  7434. for (k = j + 1; !used && k < horizon.length && horizon[k].end <= affectedBoundary.y2; k++) {
  7435. used = horizon[k].boundary === affectedBoundary;
  7436. }
  7437. for (k = 0; !used && k < changedHorizon.length; k++) {
  7438. used = changedHorizon[k].boundary === affectedBoundary;
  7439. }
  7440. if (!used) {
  7441. affectedBoundary.x2New = maxXNew;
  7442. }
  7443. }
  7444. Array.prototype.splice.apply(horizon, [i, j - i + 1].concat(changedHorizon));
  7445. });
  7446. horizon.forEach(function (horizonPart) {
  7447. var affectedBoundary = horizonPart.boundary;
  7448. if (affectedBoundary.x2New === undefined) {
  7449. affectedBoundary.x2New = Math.max(width, affectedBoundary.x2);
  7450. }
  7451. });
  7452. }
  7453. function TextLayerRenderTask({
  7454. textContent,
  7455. textContentStream,
  7456. container,
  7457. viewport,
  7458. textDivs,
  7459. textContentItemsStr,
  7460. enhanceTextSelection
  7461. }) {
  7462. this._textContent = textContent;
  7463. this._textContentStream = textContentStream;
  7464. this._container = container;
  7465. this._viewport = viewport;
  7466. this._textDivs = textDivs || [];
  7467. this._textContentItemsStr = textContentItemsStr || [];
  7468. this._enhanceTextSelection = !!enhanceTextSelection;
  7469. this._fontInspectorEnabled = !!(globalThis.FontInspector && globalThis.FontInspector.enabled);
  7470. this._reader = null;
  7471. this._layoutTextLastFontSize = null;
  7472. this._layoutTextLastFontFamily = null;
  7473. this._layoutTextCtx = null;
  7474. this._textDivProperties = new WeakMap();
  7475. this._renderingDone = false;
  7476. this._canceled = false;
  7477. this._capability = (0, _util.createPromiseCapability)();
  7478. this._renderTimer = null;
  7479. this._bounds = [];
  7480. this._capability.promise.finally(() => {
  7481. if (this._layoutTextCtx) {
  7482. this._layoutTextCtx.canvas.width = 0;
  7483. this._layoutTextCtx.canvas.height = 0;
  7484. this._layoutTextCtx = null;
  7485. }
  7486. }).catch(() => {});
  7487. }
  7488. TextLayerRenderTask.prototype = {
  7489. get promise() {
  7490. return this._capability.promise;
  7491. },
  7492. cancel: function TextLayer_cancel() {
  7493. this._canceled = true;
  7494. if (this._reader) {
  7495. this._reader.cancel(new _util.AbortException("TextLayer task cancelled."));
  7496. this._reader = null;
  7497. }
  7498. if (this._renderTimer !== null) {
  7499. clearTimeout(this._renderTimer);
  7500. this._renderTimer = null;
  7501. }
  7502. this._capability.reject(new Error("TextLayer task cancelled."));
  7503. },
  7504. _processItems(items, styleCache) {
  7505. for (let i = 0, len = items.length; i < len; i++) {
  7506. this._textContentItemsStr.push(items[i].str);
  7507. appendText(this, items[i], styleCache);
  7508. }
  7509. },
  7510. _layoutText(textDiv) {
  7511. const textDivProperties = this._textDivProperties.get(textDiv);
  7512. if (textDivProperties.isWhitespace) {
  7513. return;
  7514. }
  7515. let transform = "";
  7516. if (textDivProperties.canvasWidth !== 0) {
  7517. const {
  7518. fontSize,
  7519. fontFamily
  7520. } = textDiv.style;
  7521. if (fontSize !== this._layoutTextLastFontSize || fontFamily !== this._layoutTextLastFontFamily) {
  7522. this._layoutTextCtx.font = `${fontSize} ${fontFamily}`;
  7523. this._layoutTextLastFontSize = fontSize;
  7524. this._layoutTextLastFontFamily = fontFamily;
  7525. }
  7526. const {
  7527. width
  7528. } = this._layoutTextCtx.measureText(textDiv.textContent);
  7529. if (width > 0) {
  7530. textDivProperties.scale = textDivProperties.canvasWidth / width;
  7531. transform = `scaleX(${textDivProperties.scale})`;
  7532. }
  7533. }
  7534. if (textDivProperties.angle !== 0) {
  7535. transform = `rotate(${textDivProperties.angle}deg) ${transform}`;
  7536. }
  7537. if (transform.length > 0) {
  7538. if (this._enhanceTextSelection) {
  7539. textDivProperties.originalTransform = transform;
  7540. }
  7541. textDiv.style.transform = transform;
  7542. }
  7543. this._textDivProperties.set(textDiv, textDivProperties);
  7544. this._container.appendChild(textDiv);
  7545. },
  7546. _render: function TextLayer_render(timeout) {
  7547. const capability = (0, _util.createPromiseCapability)();
  7548. let styleCache = Object.create(null);
  7549. const canvas = document.createElement("canvas");
  7550. canvas.mozOpaque = true;
  7551. this._layoutTextCtx = canvas.getContext("2d", {
  7552. alpha: false
  7553. });
  7554. if (this._textContent) {
  7555. const textItems = this._textContent.items;
  7556. const textStyles = this._textContent.styles;
  7557. this._processItems(textItems, textStyles);
  7558. capability.resolve();
  7559. } else if (this._textContentStream) {
  7560. const pump = () => {
  7561. this._reader.read().then(({
  7562. value,
  7563. done
  7564. }) => {
  7565. if (done) {
  7566. capability.resolve();
  7567. return;
  7568. }
  7569. Object.assign(styleCache, value.styles);
  7570. this._processItems(value.items, styleCache);
  7571. pump();
  7572. }, capability.reject);
  7573. };
  7574. this._reader = this._textContentStream.getReader();
  7575. pump();
  7576. } else {
  7577. throw new Error('Neither "textContent" nor "textContentStream"' + " parameters specified.");
  7578. }
  7579. capability.promise.then(() => {
  7580. styleCache = null;
  7581. if (!timeout) {
  7582. render(this);
  7583. } else {
  7584. this._renderTimer = setTimeout(() => {
  7585. render(this);
  7586. this._renderTimer = null;
  7587. }, timeout);
  7588. }
  7589. }, this._capability.reject);
  7590. },
  7591. expandTextDivs: function TextLayer_expandTextDivs(expandDivs) {
  7592. if (!this._enhanceTextSelection || !this._renderingDone) {
  7593. return;
  7594. }
  7595. if (this._bounds !== null) {
  7596. expand(this);
  7597. this._bounds = null;
  7598. }
  7599. const transformBuf = [],
  7600. paddingBuf = [];
  7601. for (var i = 0, ii = this._textDivs.length; i < ii; i++) {
  7602. const div = this._textDivs[i];
  7603. const divProps = this._textDivProperties.get(div);
  7604. if (divProps.isWhitespace) {
  7605. continue;
  7606. }
  7607. if (expandDivs) {
  7608. transformBuf.length = 0;
  7609. paddingBuf.length = 0;
  7610. if (divProps.originalTransform) {
  7611. transformBuf.push(divProps.originalTransform);
  7612. }
  7613. if (divProps.paddingTop > 0) {
  7614. paddingBuf.push(`${divProps.paddingTop}px`);
  7615. transformBuf.push(`translateY(${-divProps.paddingTop}px)`);
  7616. } else {
  7617. paddingBuf.push(0);
  7618. }
  7619. if (divProps.paddingRight > 0) {
  7620. paddingBuf.push(`${divProps.paddingRight / divProps.scale}px`);
  7621. } else {
  7622. paddingBuf.push(0);
  7623. }
  7624. if (divProps.paddingBottom > 0) {
  7625. paddingBuf.push(`${divProps.paddingBottom}px`);
  7626. } else {
  7627. paddingBuf.push(0);
  7628. }
  7629. if (divProps.paddingLeft > 0) {
  7630. paddingBuf.push(`${divProps.paddingLeft / divProps.scale}px`);
  7631. transformBuf.push(`translateX(${-divProps.paddingLeft / divProps.scale}px)`);
  7632. } else {
  7633. paddingBuf.push(0);
  7634. }
  7635. div.style.padding = paddingBuf.join(" ");
  7636. if (transformBuf.length) {
  7637. div.style.transform = transformBuf.join(" ");
  7638. }
  7639. } else {
  7640. div.style.padding = null;
  7641. div.style.transform = divProps.originalTransform;
  7642. }
  7643. }
  7644. }
  7645. };
  7646. function renderTextLayer(renderParameters) {
  7647. var task = new TextLayerRenderTask({
  7648. textContent: renderParameters.textContent,
  7649. textContentStream: renderParameters.textContentStream,
  7650. container: renderParameters.container,
  7651. viewport: renderParameters.viewport,
  7652. textDivs: renderParameters.textDivs,
  7653. textContentItemsStr: renderParameters.textContentItemsStr,
  7654. enhanceTextSelection: renderParameters.enhanceTextSelection
  7655. });
  7656. task._render(renderParameters.timeout);
  7657. return task;
  7658. }
  7659. return renderTextLayer;
  7660. }();
  7661. exports.renderTextLayer = renderTextLayer;
  7662. /***/ }),
  7663. /* 17 */
  7664. /***/ (function(module, exports, __w_pdfjs_require__) {
  7665. "use strict";
  7666. Object.defineProperty(exports, "__esModule", {
  7667. value: true
  7668. });
  7669. exports.AnnotationLayer = void 0;
  7670. var _display_utils = __w_pdfjs_require__(4);
  7671. var _util = __w_pdfjs_require__(1);
  7672. class AnnotationElementFactory {
  7673. static create(parameters) {
  7674. const subtype = parameters.data.annotationType;
  7675. switch (subtype) {
  7676. case _util.AnnotationType.LINK:
  7677. return new LinkAnnotationElement(parameters);
  7678. case _util.AnnotationType.TEXT:
  7679. return new TextAnnotationElement(parameters);
  7680. case _util.AnnotationType.WIDGET:
  7681. const fieldType = parameters.data.fieldType;
  7682. switch (fieldType) {
  7683. case "Tx":
  7684. return new TextWidgetAnnotationElement(parameters);
  7685. case "Btn":
  7686. if (parameters.data.radioButton) {
  7687. return new RadioButtonWidgetAnnotationElement(parameters);
  7688. } else if (parameters.data.checkBox) {
  7689. return new CheckboxWidgetAnnotationElement(parameters);
  7690. }
  7691. return new PushButtonWidgetAnnotationElement(parameters);
  7692. case "Ch":
  7693. return new ChoiceWidgetAnnotationElement(parameters);
  7694. }
  7695. return new WidgetAnnotationElement(parameters);
  7696. case _util.AnnotationType.POPUP:
  7697. return new PopupAnnotationElement(parameters);
  7698. case _util.AnnotationType.FREETEXT:
  7699. return new FreeTextAnnotationElement(parameters);
  7700. case _util.AnnotationType.LINE:
  7701. return new LineAnnotationElement(parameters);
  7702. case _util.AnnotationType.SQUARE:
  7703. return new SquareAnnotationElement(parameters);
  7704. case _util.AnnotationType.CIRCLE:
  7705. return new CircleAnnotationElement(parameters);
  7706. case _util.AnnotationType.POLYLINE:
  7707. return new PolylineAnnotationElement(parameters);
  7708. case _util.AnnotationType.CARET:
  7709. return new CaretAnnotationElement(parameters);
  7710. case _util.AnnotationType.INK:
  7711. return new InkAnnotationElement(parameters);
  7712. case _util.AnnotationType.POLYGON:
  7713. return new PolygonAnnotationElement(parameters);
  7714. case _util.AnnotationType.HIGHLIGHT:
  7715. return new HighlightAnnotationElement(parameters);
  7716. case _util.AnnotationType.UNDERLINE:
  7717. return new UnderlineAnnotationElement(parameters);
  7718. case _util.AnnotationType.SQUIGGLY:
  7719. return new SquigglyAnnotationElement(parameters);
  7720. case _util.AnnotationType.STRIKEOUT:
  7721. return new StrikeOutAnnotationElement(parameters);
  7722. case _util.AnnotationType.STAMP:
  7723. return new StampAnnotationElement(parameters);
  7724. case _util.AnnotationType.FILEATTACHMENT:
  7725. return new FileAttachmentAnnotationElement(parameters);
  7726. default:
  7727. return new AnnotationElement(parameters);
  7728. }
  7729. }
  7730. }
  7731. class AnnotationElement {
  7732. constructor(parameters, isRenderable = false, ignoreBorder = false) {
  7733. this.isRenderable = isRenderable;
  7734. this.data = parameters.data;
  7735. this.layer = parameters.layer;
  7736. this.page = parameters.page;
  7737. this.viewport = parameters.viewport;
  7738. this.linkService = parameters.linkService;
  7739. this.downloadManager = parameters.downloadManager;
  7740. this.imageResourcesPath = parameters.imageResourcesPath;
  7741. this.renderInteractiveForms = parameters.renderInteractiveForms;
  7742. this.svgFactory = parameters.svgFactory;
  7743. if (isRenderable) {
  7744. this.container = this._createContainer(ignoreBorder);
  7745. }
  7746. }
  7747. _createContainer(ignoreBorder = false) {
  7748. const data = this.data,
  7749. page = this.page,
  7750. viewport = this.viewport;
  7751. const container = document.createElement("section");
  7752. let width = data.rect[2] - data.rect[0];
  7753. let height = data.rect[3] - data.rect[1];
  7754. container.setAttribute("data-annotation-id", data.id);
  7755. const rect = _util.Util.normalizeRect([data.rect[0], page.view[3] - data.rect[1] + page.view[1], data.rect[2], page.view[3] - data.rect[3] + page.view[1]]);
  7756. container.style.transform = `matrix(${viewport.transform.join(",")})`;
  7757. container.style.transformOrigin = `-${rect[0]}px -${rect[1]}px`;
  7758. if (!ignoreBorder && data.borderStyle.width > 0) {
  7759. container.style.borderWidth = `${data.borderStyle.width}px`;
  7760. if (data.borderStyle.style !== _util.AnnotationBorderStyleType.UNDERLINE) {
  7761. width = width - 2 * data.borderStyle.width;
  7762. height = height - 2 * data.borderStyle.width;
  7763. }
  7764. const horizontalRadius = data.borderStyle.horizontalCornerRadius;
  7765. const verticalRadius = data.borderStyle.verticalCornerRadius;
  7766. if (horizontalRadius > 0 || verticalRadius > 0) {
  7767. const radius = `${horizontalRadius}px / ${verticalRadius}px`;
  7768. container.style.borderRadius = radius;
  7769. }
  7770. switch (data.borderStyle.style) {
  7771. case _util.AnnotationBorderStyleType.SOLID:
  7772. container.style.borderStyle = "solid";
  7773. break;
  7774. case _util.AnnotationBorderStyleType.DASHED:
  7775. container.style.borderStyle = "dashed";
  7776. break;
  7777. case _util.AnnotationBorderStyleType.BEVELED:
  7778. (0, _util.warn)("Unimplemented border style: beveled");
  7779. break;
  7780. case _util.AnnotationBorderStyleType.INSET:
  7781. (0, _util.warn)("Unimplemented border style: inset");
  7782. break;
  7783. case _util.AnnotationBorderStyleType.UNDERLINE:
  7784. container.style.borderBottomStyle = "solid";
  7785. break;
  7786. default:
  7787. break;
  7788. }
  7789. if (data.color) {
  7790. container.style.borderColor = _util.Util.makeCssRgb(data.color[0] | 0, data.color[1] | 0, data.color[2] | 0);
  7791. } else {
  7792. container.style.borderWidth = 0;
  7793. }
  7794. }
  7795. container.style.left = `${rect[0]}px`;
  7796. container.style.top = `${rect[1]}px`;
  7797. container.style.width = `${width}px`;
  7798. container.style.height = `${height}px`;
  7799. return container;
  7800. }
  7801. _createPopup(container, trigger, data) {
  7802. if (!trigger) {
  7803. trigger = document.createElement("div");
  7804. trigger.style.height = container.style.height;
  7805. trigger.style.width = container.style.width;
  7806. container.appendChild(trigger);
  7807. }
  7808. const popupElement = new PopupElement({
  7809. container,
  7810. trigger,
  7811. color: data.color,
  7812. title: data.title,
  7813. modificationDate: data.modificationDate,
  7814. contents: data.contents,
  7815. hideWrapper: true
  7816. });
  7817. const popup = popupElement.render();
  7818. popup.style.left = container.style.width;
  7819. container.appendChild(popup);
  7820. }
  7821. render() {
  7822. (0, _util.unreachable)("Abstract method `AnnotationElement.render` called");
  7823. }
  7824. }
  7825. class LinkAnnotationElement extends AnnotationElement {
  7826. constructor(parameters) {
  7827. const isRenderable = !!(parameters.data.url || parameters.data.dest || parameters.data.action);
  7828. super(parameters, isRenderable);
  7829. }
  7830. render() {
  7831. this.container.className = "linkAnnotation";
  7832. const {
  7833. data,
  7834. linkService
  7835. } = this;
  7836. const link = document.createElement("a");
  7837. if (data.url) {
  7838. (0, _display_utils.addLinkAttributes)(link, {
  7839. url: data.url,
  7840. target: data.newWindow ? _display_utils.LinkTarget.BLANK : linkService.externalLinkTarget,
  7841. rel: linkService.externalLinkRel,
  7842. enabled: linkService.externalLinkEnabled
  7843. });
  7844. } else if (data.action) {
  7845. this._bindNamedAction(link, data.action);
  7846. } else {
  7847. this._bindLink(link, data.dest);
  7848. }
  7849. this.container.appendChild(link);
  7850. return this.container;
  7851. }
  7852. _bindLink(link, destination) {
  7853. link.href = this.linkService.getDestinationHash(destination);
  7854. link.onclick = () => {
  7855. if (destination) {
  7856. this.linkService.navigateTo(destination);
  7857. }
  7858. return false;
  7859. };
  7860. if (destination) {
  7861. link.className = "internalLink";
  7862. }
  7863. }
  7864. _bindNamedAction(link, action) {
  7865. link.href = this.linkService.getAnchorUrl("");
  7866. link.onclick = () => {
  7867. this.linkService.executeNamedAction(action);
  7868. return false;
  7869. };
  7870. link.className = "internalLink";
  7871. }
  7872. }
  7873. class TextAnnotationElement extends AnnotationElement {
  7874. constructor(parameters) {
  7875. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  7876. super(parameters, isRenderable);
  7877. }
  7878. render() {
  7879. this.container.className = "textAnnotation";
  7880. const image = document.createElement("img");
  7881. image.style.height = this.container.style.height;
  7882. image.style.width = this.container.style.width;
  7883. image.src = this.imageResourcesPath + "annotation-" + this.data.name.toLowerCase() + ".svg";
  7884. image.alt = "[{{type}} Annotation]";
  7885. image.dataset.l10nId = "text_annotation_type";
  7886. image.dataset.l10nArgs = JSON.stringify({
  7887. type: this.data.name
  7888. });
  7889. if (!this.data.hasPopup) {
  7890. this._createPopup(this.container, image, this.data);
  7891. }
  7892. this.container.appendChild(image);
  7893. return this.container;
  7894. }
  7895. }
  7896. class WidgetAnnotationElement extends AnnotationElement {
  7897. render() {
  7898. return this.container;
  7899. }
  7900. }
  7901. class TextWidgetAnnotationElement extends WidgetAnnotationElement {
  7902. constructor(parameters) {
  7903. const isRenderable = parameters.renderInteractiveForms || !parameters.data.hasAppearance && !!parameters.data.fieldValue;
  7904. super(parameters, isRenderable);
  7905. }
  7906. render() {
  7907. const TEXT_ALIGNMENT = ["left", "center", "right"];
  7908. this.container.className = "textWidgetAnnotation";
  7909. let element = null;
  7910. if (this.renderInteractiveForms) {
  7911. if (this.data.multiLine) {
  7912. element = document.createElement("textarea");
  7913. element.textContent = this.data.fieldValue;
  7914. } else {
  7915. element = document.createElement("input");
  7916. element.type = "text";
  7917. element.setAttribute("value", this.data.fieldValue);
  7918. }
  7919. element.disabled = this.data.readOnly;
  7920. if (this.data.maxLen !== null) {
  7921. element.maxLength = this.data.maxLen;
  7922. }
  7923. if (this.data.comb) {
  7924. const fieldWidth = this.data.rect[2] - this.data.rect[0];
  7925. const combWidth = fieldWidth / this.data.maxLen;
  7926. element.classList.add("comb");
  7927. element.style.letterSpacing = `calc(${combWidth}px - 1ch)`;
  7928. }
  7929. } else {
  7930. element = document.createElement("div");
  7931. element.textContent = this.data.fieldValue;
  7932. element.style.verticalAlign = "middle";
  7933. element.style.display = "table-cell";
  7934. let font = null;
  7935. if (this.data.fontRefName && this.page.commonObjs.has(this.data.fontRefName)) {
  7936. font = this.page.commonObjs.get(this.data.fontRefName);
  7937. }
  7938. this._setTextStyle(element, font);
  7939. }
  7940. if (this.data.textAlignment !== null) {
  7941. element.style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];
  7942. }
  7943. this.container.appendChild(element);
  7944. return this.container;
  7945. }
  7946. _setTextStyle(element, font) {
  7947. const style = element.style;
  7948. style.fontSize = `${this.data.fontSize}px`;
  7949. style.direction = this.data.fontDirection < 0 ? "rtl" : "ltr";
  7950. if (!font) {
  7951. return;
  7952. }
  7953. let bold = "normal";
  7954. if (font.black) {
  7955. bold = "900";
  7956. } else if (font.bold) {
  7957. bold = "bold";
  7958. }
  7959. style.fontWeight = bold;
  7960. style.fontStyle = font.italic ? "italic" : "normal";
  7961. const fontFamily = font.loadedName ? `"${font.loadedName}", ` : "";
  7962. const fallbackName = font.fallbackName || "Helvetica, sans-serif";
  7963. style.fontFamily = fontFamily + fallbackName;
  7964. }
  7965. }
  7966. class CheckboxWidgetAnnotationElement extends WidgetAnnotationElement {
  7967. constructor(parameters) {
  7968. super(parameters, parameters.renderInteractiveForms);
  7969. }
  7970. render() {
  7971. this.container.className = "buttonWidgetAnnotation checkBox";
  7972. const element = document.createElement("input");
  7973. element.disabled = this.data.readOnly;
  7974. element.type = "checkbox";
  7975. if (this.data.fieldValue && this.data.fieldValue !== "Off") {
  7976. element.setAttribute("checked", true);
  7977. }
  7978. this.container.appendChild(element);
  7979. return this.container;
  7980. }
  7981. }
  7982. class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement {
  7983. constructor(parameters) {
  7984. super(parameters, parameters.renderInteractiveForms);
  7985. }
  7986. render() {
  7987. this.container.className = "buttonWidgetAnnotation radioButton";
  7988. const element = document.createElement("input");
  7989. element.disabled = this.data.readOnly;
  7990. element.type = "radio";
  7991. element.name = this.data.fieldName;
  7992. if (this.data.fieldValue === this.data.buttonValue) {
  7993. element.setAttribute("checked", true);
  7994. }
  7995. this.container.appendChild(element);
  7996. return this.container;
  7997. }
  7998. }
  7999. class PushButtonWidgetAnnotationElement extends LinkAnnotationElement {
  8000. render() {
  8001. const container = super.render();
  8002. container.className = "buttonWidgetAnnotation pushButton";
  8003. return container;
  8004. }
  8005. }
  8006. class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
  8007. constructor(parameters) {
  8008. super(parameters, parameters.renderInteractiveForms);
  8009. }
  8010. render() {
  8011. this.container.className = "choiceWidgetAnnotation";
  8012. const selectElement = document.createElement("select");
  8013. selectElement.disabled = this.data.readOnly;
  8014. if (!this.data.combo) {
  8015. selectElement.size = this.data.options.length;
  8016. if (this.data.multiSelect) {
  8017. selectElement.multiple = true;
  8018. }
  8019. }
  8020. for (const option of this.data.options) {
  8021. const optionElement = document.createElement("option");
  8022. optionElement.textContent = option.displayValue;
  8023. optionElement.value = option.exportValue;
  8024. if (this.data.fieldValue.includes(option.displayValue)) {
  8025. optionElement.setAttribute("selected", true);
  8026. }
  8027. selectElement.appendChild(optionElement);
  8028. }
  8029. this.container.appendChild(selectElement);
  8030. return this.container;
  8031. }
  8032. }
  8033. class PopupAnnotationElement extends AnnotationElement {
  8034. constructor(parameters) {
  8035. const isRenderable = !!(parameters.data.title || parameters.data.contents);
  8036. super(parameters, isRenderable);
  8037. }
  8038. render() {
  8039. const IGNORE_TYPES = ["Line", "Square", "Circle", "PolyLine", "Polygon", "Ink"];
  8040. this.container.className = "popupAnnotation";
  8041. if (IGNORE_TYPES.includes(this.data.parentType)) {
  8042. return this.container;
  8043. }
  8044. const selector = `[data-annotation-id="${this.data.parentId}"]`;
  8045. const parentElement = this.layer.querySelector(selector);
  8046. if (!parentElement) {
  8047. return this.container;
  8048. }
  8049. const popup = new PopupElement({
  8050. container: this.container,
  8051. trigger: parentElement,
  8052. color: this.data.color,
  8053. title: this.data.title,
  8054. modificationDate: this.data.modificationDate,
  8055. contents: this.data.contents
  8056. });
  8057. const parentLeft = parseFloat(parentElement.style.left);
  8058. const parentWidth = parseFloat(parentElement.style.width);
  8059. this.container.style.transformOrigin = `-${parentLeft + parentWidth}px -${parentElement.style.top}`;
  8060. this.container.style.left = `${parentLeft + parentWidth}px`;
  8061. this.container.appendChild(popup.render());
  8062. return this.container;
  8063. }
  8064. }
  8065. class PopupElement {
  8066. constructor(parameters) {
  8067. this.container = parameters.container;
  8068. this.trigger = parameters.trigger;
  8069. this.color = parameters.color;
  8070. this.title = parameters.title;
  8071. this.modificationDate = parameters.modificationDate;
  8072. this.contents = parameters.contents;
  8073. this.hideWrapper = parameters.hideWrapper || false;
  8074. this.pinned = false;
  8075. }
  8076. render() {
  8077. const BACKGROUND_ENLIGHT = 0.7;
  8078. const wrapper = document.createElement("div");
  8079. wrapper.className = "popupWrapper";
  8080. this.hideElement = this.hideWrapper ? wrapper : this.container;
  8081. this.hideElement.setAttribute("hidden", true);
  8082. const popup = document.createElement("div");
  8083. popup.className = "popup";
  8084. const color = this.color;
  8085. if (color) {
  8086. const r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
  8087. const g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
  8088. const b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
  8089. popup.style.backgroundColor = _util.Util.makeCssRgb(r | 0, g | 0, b | 0);
  8090. }
  8091. const title = document.createElement("h1");
  8092. title.textContent = this.title;
  8093. popup.appendChild(title);
  8094. const dateObject = _display_utils.PDFDateString.toDateObject(this.modificationDate);
  8095. if (dateObject) {
  8096. const modificationDate = document.createElement("span");
  8097. modificationDate.textContent = "{{date}}, {{time}}";
  8098. modificationDate.dataset.l10nId = "annotation_date_string";
  8099. modificationDate.dataset.l10nArgs = JSON.stringify({
  8100. date: dateObject.toLocaleDateString(),
  8101. time: dateObject.toLocaleTimeString()
  8102. });
  8103. popup.appendChild(modificationDate);
  8104. }
  8105. const contents = this._formatContents(this.contents);
  8106. popup.appendChild(contents);
  8107. this.trigger.addEventListener("click", this._toggle.bind(this));
  8108. this.trigger.addEventListener("mouseover", this._show.bind(this, false));
  8109. this.trigger.addEventListener("mouseout", this._hide.bind(this, false));
  8110. popup.addEventListener("click", this._hide.bind(this, true));
  8111. wrapper.appendChild(popup);
  8112. return wrapper;
  8113. }
  8114. _formatContents(contents) {
  8115. const p = document.createElement("p");
  8116. const lines = contents.split(/(?:\r\n?|\n)/);
  8117. for (let i = 0, ii = lines.length; i < ii; ++i) {
  8118. const line = lines[i];
  8119. p.appendChild(document.createTextNode(line));
  8120. if (i < ii - 1) {
  8121. p.appendChild(document.createElement("br"));
  8122. }
  8123. }
  8124. return p;
  8125. }
  8126. _toggle() {
  8127. if (this.pinned) {
  8128. this._hide(true);
  8129. } else {
  8130. this._show(true);
  8131. }
  8132. }
  8133. _show(pin = false) {
  8134. if (pin) {
  8135. this.pinned = true;
  8136. }
  8137. if (this.hideElement.hasAttribute("hidden")) {
  8138. this.hideElement.removeAttribute("hidden");
  8139. this.container.style.zIndex += 1;
  8140. }
  8141. }
  8142. _hide(unpin = true) {
  8143. if (unpin) {
  8144. this.pinned = false;
  8145. }
  8146. if (!this.hideElement.hasAttribute("hidden") && !this.pinned) {
  8147. this.hideElement.setAttribute("hidden", true);
  8148. this.container.style.zIndex -= 1;
  8149. }
  8150. }
  8151. }
  8152. class FreeTextAnnotationElement extends AnnotationElement {
  8153. constructor(parameters) {
  8154. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8155. super(parameters, isRenderable, true);
  8156. }
  8157. render() {
  8158. this.container.className = "freeTextAnnotation";
  8159. if (!this.data.hasPopup) {
  8160. this._createPopup(this.container, null, this.data);
  8161. }
  8162. return this.container;
  8163. }
  8164. }
  8165. class LineAnnotationElement extends AnnotationElement {
  8166. constructor(parameters) {
  8167. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8168. super(parameters, isRenderable, true);
  8169. }
  8170. render() {
  8171. this.container.className = "lineAnnotation";
  8172. const data = this.data;
  8173. const width = data.rect[2] - data.rect[0];
  8174. const height = data.rect[3] - data.rect[1];
  8175. const svg = this.svgFactory.create(width, height);
  8176. const line = this.svgFactory.createElement("svg:line");
  8177. line.setAttribute("x1", data.rect[2] - data.lineCoordinates[0]);
  8178. line.setAttribute("y1", data.rect[3] - data.lineCoordinates[1]);
  8179. line.setAttribute("x2", data.rect[2] - data.lineCoordinates[2]);
  8180. line.setAttribute("y2", data.rect[3] - data.lineCoordinates[3]);
  8181. line.setAttribute("stroke-width", data.borderStyle.width || 1);
  8182. line.setAttribute("stroke", "transparent");
  8183. svg.appendChild(line);
  8184. this.container.append(svg);
  8185. this._createPopup(this.container, line, data);
  8186. return this.container;
  8187. }
  8188. }
  8189. class SquareAnnotationElement extends AnnotationElement {
  8190. constructor(parameters) {
  8191. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8192. super(parameters, isRenderable, true);
  8193. }
  8194. render() {
  8195. this.container.className = "squareAnnotation";
  8196. const data = this.data;
  8197. const width = data.rect[2] - data.rect[0];
  8198. const height = data.rect[3] - data.rect[1];
  8199. const svg = this.svgFactory.create(width, height);
  8200. const borderWidth = data.borderStyle.width;
  8201. const square = this.svgFactory.createElement("svg:rect");
  8202. square.setAttribute("x", borderWidth / 2);
  8203. square.setAttribute("y", borderWidth / 2);
  8204. square.setAttribute("width", width - borderWidth);
  8205. square.setAttribute("height", height - borderWidth);
  8206. square.setAttribute("stroke-width", borderWidth || 1);
  8207. square.setAttribute("stroke", "transparent");
  8208. square.setAttribute("fill", "none");
  8209. svg.appendChild(square);
  8210. this.container.append(svg);
  8211. this._createPopup(this.container, square, data);
  8212. return this.container;
  8213. }
  8214. }
  8215. class CircleAnnotationElement extends AnnotationElement {
  8216. constructor(parameters) {
  8217. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8218. super(parameters, isRenderable, true);
  8219. }
  8220. render() {
  8221. this.container.className = "circleAnnotation";
  8222. const data = this.data;
  8223. const width = data.rect[2] - data.rect[0];
  8224. const height = data.rect[3] - data.rect[1];
  8225. const svg = this.svgFactory.create(width, height);
  8226. const borderWidth = data.borderStyle.width;
  8227. const circle = this.svgFactory.createElement("svg:ellipse");
  8228. circle.setAttribute("cx", width / 2);
  8229. circle.setAttribute("cy", height / 2);
  8230. circle.setAttribute("rx", width / 2 - borderWidth / 2);
  8231. circle.setAttribute("ry", height / 2 - borderWidth / 2);
  8232. circle.setAttribute("stroke-width", borderWidth || 1);
  8233. circle.setAttribute("stroke", "transparent");
  8234. circle.setAttribute("fill", "none");
  8235. svg.appendChild(circle);
  8236. this.container.append(svg);
  8237. this._createPopup(this.container, circle, data);
  8238. return this.container;
  8239. }
  8240. }
  8241. class PolylineAnnotationElement extends AnnotationElement {
  8242. constructor(parameters) {
  8243. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8244. super(parameters, isRenderable, true);
  8245. this.containerClassName = "polylineAnnotation";
  8246. this.svgElementName = "svg:polyline";
  8247. }
  8248. render() {
  8249. this.container.className = this.containerClassName;
  8250. const data = this.data;
  8251. const width = data.rect[2] - data.rect[0];
  8252. const height = data.rect[3] - data.rect[1];
  8253. const svg = this.svgFactory.create(width, height);
  8254. let points = [];
  8255. for (const coordinate of data.vertices) {
  8256. const x = coordinate.x - data.rect[0];
  8257. const y = data.rect[3] - coordinate.y;
  8258. points.push(x + "," + y);
  8259. }
  8260. points = points.join(" ");
  8261. const polyline = this.svgFactory.createElement(this.svgElementName);
  8262. polyline.setAttribute("points", points);
  8263. polyline.setAttribute("stroke-width", data.borderStyle.width || 1);
  8264. polyline.setAttribute("stroke", "transparent");
  8265. polyline.setAttribute("fill", "none");
  8266. svg.appendChild(polyline);
  8267. this.container.append(svg);
  8268. this._createPopup(this.container, polyline, data);
  8269. return this.container;
  8270. }
  8271. }
  8272. class PolygonAnnotationElement extends PolylineAnnotationElement {
  8273. constructor(parameters) {
  8274. super(parameters);
  8275. this.containerClassName = "polygonAnnotation";
  8276. this.svgElementName = "svg:polygon";
  8277. }
  8278. }
  8279. class CaretAnnotationElement extends AnnotationElement {
  8280. constructor(parameters) {
  8281. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8282. super(parameters, isRenderable, true);
  8283. }
  8284. render() {
  8285. this.container.className = "caretAnnotation";
  8286. if (!this.data.hasPopup) {
  8287. this._createPopup(this.container, null, this.data);
  8288. }
  8289. return this.container;
  8290. }
  8291. }
  8292. class InkAnnotationElement extends AnnotationElement {
  8293. constructor(parameters) {
  8294. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8295. super(parameters, isRenderable, true);
  8296. this.containerClassName = "inkAnnotation";
  8297. this.svgElementName = "svg:polyline";
  8298. }
  8299. render() {
  8300. this.container.className = this.containerClassName;
  8301. const data = this.data;
  8302. const width = data.rect[2] - data.rect[0];
  8303. const height = data.rect[3] - data.rect[1];
  8304. const svg = this.svgFactory.create(width, height);
  8305. for (const inkList of data.inkLists) {
  8306. let points = [];
  8307. for (const coordinate of inkList) {
  8308. const x = coordinate.x - data.rect[0];
  8309. const y = data.rect[3] - coordinate.y;
  8310. points.push(`${x},${y}`);
  8311. }
  8312. points = points.join(" ");
  8313. const polyline = this.svgFactory.createElement(this.svgElementName);
  8314. polyline.setAttribute("points", points);
  8315. polyline.setAttribute("stroke-width", data.borderStyle.width || 1);
  8316. polyline.setAttribute("stroke", "transparent");
  8317. polyline.setAttribute("fill", "none");
  8318. this._createPopup(this.container, polyline, data);
  8319. svg.appendChild(polyline);
  8320. }
  8321. this.container.append(svg);
  8322. return this.container;
  8323. }
  8324. }
  8325. class HighlightAnnotationElement extends AnnotationElement {
  8326. constructor(parameters) {
  8327. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8328. super(parameters, isRenderable, true);
  8329. }
  8330. render() {
  8331. this.container.className = "highlightAnnotation";
  8332. if (!this.data.hasPopup) {
  8333. this._createPopup(this.container, null, this.data);
  8334. }
  8335. return this.container;
  8336. }
  8337. }
  8338. class UnderlineAnnotationElement extends AnnotationElement {
  8339. constructor(parameters) {
  8340. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8341. super(parameters, isRenderable, true);
  8342. }
  8343. render() {
  8344. this.container.className = "underlineAnnotation";
  8345. if (!this.data.hasPopup) {
  8346. this._createPopup(this.container, null, this.data);
  8347. }
  8348. return this.container;
  8349. }
  8350. }
  8351. class SquigglyAnnotationElement extends AnnotationElement {
  8352. constructor(parameters) {
  8353. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8354. super(parameters, isRenderable, true);
  8355. }
  8356. render() {
  8357. this.container.className = "squigglyAnnotation";
  8358. if (!this.data.hasPopup) {
  8359. this._createPopup(this.container, null, this.data);
  8360. }
  8361. return this.container;
  8362. }
  8363. }
  8364. class StrikeOutAnnotationElement extends AnnotationElement {
  8365. constructor(parameters) {
  8366. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8367. super(parameters, isRenderable, true);
  8368. }
  8369. render() {
  8370. this.container.className = "strikeoutAnnotation";
  8371. if (!this.data.hasPopup) {
  8372. this._createPopup(this.container, null, this.data);
  8373. }
  8374. return this.container;
  8375. }
  8376. }
  8377. class StampAnnotationElement extends AnnotationElement {
  8378. constructor(parameters) {
  8379. const isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  8380. super(parameters, isRenderable, true);
  8381. }
  8382. render() {
  8383. this.container.className = "stampAnnotation";
  8384. if (!this.data.hasPopup) {
  8385. this._createPopup(this.container, null, this.data);
  8386. }
  8387. return this.container;
  8388. }
  8389. }
  8390. class FileAttachmentAnnotationElement extends AnnotationElement {
  8391. constructor(parameters) {
  8392. super(parameters, true);
  8393. const {
  8394. filename,
  8395. content
  8396. } = this.data.file;
  8397. this.filename = (0, _display_utils.getFilenameFromUrl)(filename);
  8398. this.content = content;
  8399. if (this.linkService.eventBus) {
  8400. this.linkService.eventBus.dispatch("fileattachmentannotation", {
  8401. source: this,
  8402. id: (0, _util.stringToPDFString)(filename),
  8403. filename,
  8404. content
  8405. });
  8406. }
  8407. }
  8408. render() {
  8409. this.container.className = "fileAttachmentAnnotation";
  8410. const trigger = document.createElement("div");
  8411. trigger.style.height = this.container.style.height;
  8412. trigger.style.width = this.container.style.width;
  8413. trigger.addEventListener("dblclick", this._download.bind(this));
  8414. if (!this.data.hasPopup && (this.data.title || this.data.contents)) {
  8415. this._createPopup(this.container, trigger, this.data);
  8416. }
  8417. this.container.appendChild(trigger);
  8418. return this.container;
  8419. }
  8420. _download() {
  8421. if (!this.downloadManager) {
  8422. (0, _util.warn)("Download cannot be started due to unavailable download manager");
  8423. return;
  8424. }
  8425. this.downloadManager.downloadData(this.content, this.filename, "");
  8426. }
  8427. }
  8428. class AnnotationLayer {
  8429. static render(parameters) {
  8430. const sortedAnnotations = [],
  8431. popupAnnotations = [];
  8432. for (const data of parameters.annotations) {
  8433. if (!data) {
  8434. continue;
  8435. }
  8436. if (data.annotationType === _util.AnnotationType.POPUP) {
  8437. popupAnnotations.push(data);
  8438. continue;
  8439. }
  8440. sortedAnnotations.push(data);
  8441. }
  8442. if (popupAnnotations.length) {
  8443. sortedAnnotations.push(...popupAnnotations);
  8444. }
  8445. for (const data of sortedAnnotations) {
  8446. const element = AnnotationElementFactory.create({
  8447. data,
  8448. layer: parameters.div,
  8449. page: parameters.page,
  8450. viewport: parameters.viewport,
  8451. linkService: parameters.linkService,
  8452. downloadManager: parameters.downloadManager,
  8453. imageResourcesPath: parameters.imageResourcesPath || "",
  8454. renderInteractiveForms: parameters.renderInteractiveForms || false,
  8455. svgFactory: new _display_utils.DOMSVGFactory()
  8456. });
  8457. if (element.isRenderable) {
  8458. parameters.div.appendChild(element.render());
  8459. }
  8460. }
  8461. }
  8462. static update(parameters) {
  8463. for (const data of parameters.annotations) {
  8464. const element = parameters.div.querySelector(`[data-annotation-id="${data.id}"]`);
  8465. if (element) {
  8466. element.style.transform = `matrix(${parameters.viewport.transform.join(",")})`;
  8467. }
  8468. }
  8469. parameters.div.removeAttribute("hidden");
  8470. }
  8471. }
  8472. exports.AnnotationLayer = AnnotationLayer;
  8473. /***/ }),
  8474. /* 18 */
  8475. /***/ (function(module, exports, __w_pdfjs_require__) {
  8476. "use strict";
  8477. Object.defineProperty(exports, "__esModule", {
  8478. value: true
  8479. });
  8480. exports.SVGGraphics = void 0;
  8481. var _util = __w_pdfjs_require__(1);
  8482. var _display_utils = __w_pdfjs_require__(4);
  8483. var _is_node = __w_pdfjs_require__(7);
  8484. let SVGGraphics = function () {
  8485. throw new Error("Not implemented: SVGGraphics");
  8486. };
  8487. exports.SVGGraphics = SVGGraphics;
  8488. {
  8489. const SVG_DEFAULTS = {
  8490. fontStyle: "normal",
  8491. fontWeight: "normal",
  8492. fillColor: "#000000"
  8493. };
  8494. const XML_NS = "http://www.w3.org/XML/1998/namespace";
  8495. const XLINK_NS = "http://www.w3.org/1999/xlink";
  8496. const LINE_CAP_STYLES = ["butt", "round", "square"];
  8497. const LINE_JOIN_STYLES = ["miter", "round", "bevel"];
  8498. const convertImgDataToPng = function () {
  8499. const PNG_HEADER = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  8500. const CHUNK_WRAPPER_SIZE = 12;
  8501. const crcTable = new Int32Array(256);
  8502. for (let i = 0; i < 256; i++) {
  8503. let c = i;
  8504. for (let h = 0; h < 8; h++) {
  8505. if (c & 1) {
  8506. c = 0xedb88320 ^ c >> 1 & 0x7fffffff;
  8507. } else {
  8508. c = c >> 1 & 0x7fffffff;
  8509. }
  8510. }
  8511. crcTable[i] = c;
  8512. }
  8513. function crc32(data, start, end) {
  8514. let crc = -1;
  8515. for (let i = start; i < end; i++) {
  8516. const a = (crc ^ data[i]) & 0xff;
  8517. const b = crcTable[a];
  8518. crc = crc >>> 8 ^ b;
  8519. }
  8520. return crc ^ -1;
  8521. }
  8522. function writePngChunk(type, body, data, offset) {
  8523. let p = offset;
  8524. const len = body.length;
  8525. data[p] = len >> 24 & 0xff;
  8526. data[p + 1] = len >> 16 & 0xff;
  8527. data[p + 2] = len >> 8 & 0xff;
  8528. data[p + 3] = len & 0xff;
  8529. p += 4;
  8530. data[p] = type.charCodeAt(0) & 0xff;
  8531. data[p + 1] = type.charCodeAt(1) & 0xff;
  8532. data[p + 2] = type.charCodeAt(2) & 0xff;
  8533. data[p + 3] = type.charCodeAt(3) & 0xff;
  8534. p += 4;
  8535. data.set(body, p);
  8536. p += body.length;
  8537. const crc = crc32(data, offset + 4, p);
  8538. data[p] = crc >> 24 & 0xff;
  8539. data[p + 1] = crc >> 16 & 0xff;
  8540. data[p + 2] = crc >> 8 & 0xff;
  8541. data[p + 3] = crc & 0xff;
  8542. }
  8543. function adler32(data, start, end) {
  8544. let a = 1;
  8545. let b = 0;
  8546. for (let i = start; i < end; ++i) {
  8547. a = (a + (data[i] & 0xff)) % 65521;
  8548. b = (b + a) % 65521;
  8549. }
  8550. return b << 16 | a;
  8551. }
  8552. function deflateSync(literals) {
  8553. if (!_is_node.isNodeJS) {
  8554. return deflateSyncUncompressed(literals);
  8555. }
  8556. try {
  8557. let input;
  8558. if (parseInt(process.versions.node) >= 8) {
  8559. input = literals;
  8560. } else {
  8561. input = Buffer.from(literals);
  8562. }
  8563. const output = require("zlib").deflateSync(input, {
  8564. level: 9
  8565. });
  8566. return output instanceof Uint8Array ? output : new Uint8Array(output);
  8567. } catch (e) {
  8568. (0, _util.warn)("Not compressing PNG because zlib.deflateSync is unavailable: " + e);
  8569. }
  8570. return deflateSyncUncompressed(literals);
  8571. }
  8572. function deflateSyncUncompressed(literals) {
  8573. let len = literals.length;
  8574. const maxBlockLength = 0xffff;
  8575. const deflateBlocks = Math.ceil(len / maxBlockLength);
  8576. const idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  8577. let pi = 0;
  8578. idat[pi++] = 0x78;
  8579. idat[pi++] = 0x9c;
  8580. let pos = 0;
  8581. while (len > maxBlockLength) {
  8582. idat[pi++] = 0x00;
  8583. idat[pi++] = 0xff;
  8584. idat[pi++] = 0xff;
  8585. idat[pi++] = 0x00;
  8586. idat[pi++] = 0x00;
  8587. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  8588. pi += maxBlockLength;
  8589. pos += maxBlockLength;
  8590. len -= maxBlockLength;
  8591. }
  8592. idat[pi++] = 0x01;
  8593. idat[pi++] = len & 0xff;
  8594. idat[pi++] = len >> 8 & 0xff;
  8595. idat[pi++] = ~len & 0xffff & 0xff;
  8596. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  8597. idat.set(literals.subarray(pos), pi);
  8598. pi += literals.length - pos;
  8599. const adler = adler32(literals, 0, literals.length);
  8600. idat[pi++] = adler >> 24 & 0xff;
  8601. idat[pi++] = adler >> 16 & 0xff;
  8602. idat[pi++] = adler >> 8 & 0xff;
  8603. idat[pi++] = adler & 0xff;
  8604. return idat;
  8605. }
  8606. function encode(imgData, kind, forceDataSchema, isMask) {
  8607. const width = imgData.width;
  8608. const height = imgData.height;
  8609. let bitDepth, colorType, lineSize;
  8610. const bytes = imgData.data;
  8611. switch (kind) {
  8612. case _util.ImageKind.GRAYSCALE_1BPP:
  8613. colorType = 0;
  8614. bitDepth = 1;
  8615. lineSize = width + 7 >> 3;
  8616. break;
  8617. case _util.ImageKind.RGB_24BPP:
  8618. colorType = 2;
  8619. bitDepth = 8;
  8620. lineSize = width * 3;
  8621. break;
  8622. case _util.ImageKind.RGBA_32BPP:
  8623. colorType = 6;
  8624. bitDepth = 8;
  8625. lineSize = width * 4;
  8626. break;
  8627. default:
  8628. throw new Error("invalid format");
  8629. }
  8630. const literals = new Uint8Array((1 + lineSize) * height);
  8631. let offsetLiterals = 0,
  8632. offsetBytes = 0;
  8633. for (let y = 0; y < height; ++y) {
  8634. literals[offsetLiterals++] = 0;
  8635. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize), offsetLiterals);
  8636. offsetBytes += lineSize;
  8637. offsetLiterals += lineSize;
  8638. }
  8639. if (kind === _util.ImageKind.GRAYSCALE_1BPP && isMask) {
  8640. offsetLiterals = 0;
  8641. for (let y = 0; y < height; y++) {
  8642. offsetLiterals++;
  8643. for (let i = 0; i < lineSize; i++) {
  8644. literals[offsetLiterals++] ^= 0xff;
  8645. }
  8646. }
  8647. }
  8648. const ihdr = new Uint8Array([width >> 24 & 0xff, width >> 16 & 0xff, width >> 8 & 0xff, width & 0xff, height >> 24 & 0xff, height >> 16 & 0xff, height >> 8 & 0xff, height & 0xff, bitDepth, colorType, 0x00, 0x00, 0x00]);
  8649. const idat = deflateSync(literals);
  8650. const pngLength = PNG_HEADER.length + CHUNK_WRAPPER_SIZE * 3 + ihdr.length + idat.length;
  8651. const data = new Uint8Array(pngLength);
  8652. let offset = 0;
  8653. data.set(PNG_HEADER, offset);
  8654. offset += PNG_HEADER.length;
  8655. writePngChunk("IHDR", ihdr, data, offset);
  8656. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  8657. writePngChunk("IDATA", idat, data, offset);
  8658. offset += CHUNK_WRAPPER_SIZE + idat.length;
  8659. writePngChunk("IEND", new Uint8Array(0), data, offset);
  8660. return (0, _util.createObjectURL)(data, "image/png", forceDataSchema);
  8661. }
  8662. return function convertImgDataToPng(imgData, forceDataSchema, isMask) {
  8663. const kind = imgData.kind === undefined ? _util.ImageKind.GRAYSCALE_1BPP : imgData.kind;
  8664. return encode(imgData, kind, forceDataSchema, isMask);
  8665. };
  8666. }();
  8667. class SVGExtraState {
  8668. constructor() {
  8669. this.fontSizeScale = 1;
  8670. this.fontWeight = SVG_DEFAULTS.fontWeight;
  8671. this.fontSize = 0;
  8672. this.textMatrix = _util.IDENTITY_MATRIX;
  8673. this.fontMatrix = _util.FONT_IDENTITY_MATRIX;
  8674. this.leading = 0;
  8675. this.textRenderingMode = _util.TextRenderingMode.FILL;
  8676. this.textMatrixScale = 1;
  8677. this.x = 0;
  8678. this.y = 0;
  8679. this.lineX = 0;
  8680. this.lineY = 0;
  8681. this.charSpacing = 0;
  8682. this.wordSpacing = 0;
  8683. this.textHScale = 1;
  8684. this.textRise = 0;
  8685. this.fillColor = SVG_DEFAULTS.fillColor;
  8686. this.strokeColor = "#000000";
  8687. this.fillAlpha = 1;
  8688. this.strokeAlpha = 1;
  8689. this.lineWidth = 1;
  8690. this.lineJoin = "";
  8691. this.lineCap = "";
  8692. this.miterLimit = 0;
  8693. this.dashArray = [];
  8694. this.dashPhase = 0;
  8695. this.dependencies = [];
  8696. this.activeClipUrl = null;
  8697. this.clipGroup = null;
  8698. this.maskId = "";
  8699. }
  8700. clone() {
  8701. return Object.create(this);
  8702. }
  8703. setCurrentPoint(x, y) {
  8704. this.x = x;
  8705. this.y = y;
  8706. }
  8707. }
  8708. function opListToTree(opList) {
  8709. let opTree = [];
  8710. const tmp = [];
  8711. for (const opListElement of opList) {
  8712. if (opListElement.fn === "save") {
  8713. opTree.push({
  8714. fnId: 92,
  8715. fn: "group",
  8716. items: []
  8717. });
  8718. tmp.push(opTree);
  8719. opTree = opTree[opTree.length - 1].items;
  8720. continue;
  8721. }
  8722. if (opListElement.fn === "restore") {
  8723. opTree = tmp.pop();
  8724. } else {
  8725. opTree.push(opListElement);
  8726. }
  8727. }
  8728. return opTree;
  8729. }
  8730. function pf(value) {
  8731. if (Number.isInteger(value)) {
  8732. return value.toString();
  8733. }
  8734. const s = value.toFixed(10);
  8735. let i = s.length - 1;
  8736. if (s[i] !== "0") {
  8737. return s;
  8738. }
  8739. do {
  8740. i--;
  8741. } while (s[i] === "0");
  8742. return s.substring(0, s[i] === "." ? i : i + 1);
  8743. }
  8744. function pm(m) {
  8745. if (m[4] === 0 && m[5] === 0) {
  8746. if (m[1] === 0 && m[2] === 0) {
  8747. if (m[0] === 1 && m[3] === 1) {
  8748. return "";
  8749. }
  8750. return `scale(${pf(m[0])} ${pf(m[3])})`;
  8751. }
  8752. if (m[0] === m[3] && m[1] === -m[2]) {
  8753. const a = Math.acos(m[0]) * 180 / Math.PI;
  8754. return `rotate(${pf(a)})`;
  8755. }
  8756. } else {
  8757. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  8758. return `translate(${pf(m[4])} ${pf(m[5])})`;
  8759. }
  8760. }
  8761. return `matrix(${pf(m[0])} ${pf(m[1])} ${pf(m[2])} ${pf(m[3])} ${pf(m[4])} ` + `${pf(m[5])})`;
  8762. }
  8763. let clipCount = 0;
  8764. let maskCount = 0;
  8765. let shadingCount = 0;
  8766. exports.SVGGraphics = SVGGraphics = class SVGGraphics {
  8767. constructor(commonObjs, objs, forceDataSchema) {
  8768. this.svgFactory = new _display_utils.DOMSVGFactory();
  8769. this.current = new SVGExtraState();
  8770. this.transformMatrix = _util.IDENTITY_MATRIX;
  8771. this.transformStack = [];
  8772. this.extraStack = [];
  8773. this.commonObjs = commonObjs;
  8774. this.objs = objs;
  8775. this.pendingClip = null;
  8776. this.pendingEOFill = false;
  8777. this.embedFonts = false;
  8778. this.embeddedFonts = Object.create(null);
  8779. this.cssStyle = null;
  8780. this.forceDataSchema = !!forceDataSchema;
  8781. this._operatorIdMapping = [];
  8782. for (const op in _util.OPS) {
  8783. this._operatorIdMapping[_util.OPS[op]] = op;
  8784. }
  8785. }
  8786. save() {
  8787. this.transformStack.push(this.transformMatrix);
  8788. const old = this.current;
  8789. this.extraStack.push(old);
  8790. this.current = old.clone();
  8791. }
  8792. restore() {
  8793. this.transformMatrix = this.transformStack.pop();
  8794. this.current = this.extraStack.pop();
  8795. this.pendingClip = null;
  8796. this.tgrp = null;
  8797. }
  8798. group(items) {
  8799. this.save();
  8800. this.executeOpTree(items);
  8801. this.restore();
  8802. }
  8803. loadDependencies(operatorList) {
  8804. const fnArray = operatorList.fnArray;
  8805. const argsArray = operatorList.argsArray;
  8806. for (let i = 0, ii = fnArray.length; i < ii; i++) {
  8807. if (fnArray[i] !== _util.OPS.dependency) {
  8808. continue;
  8809. }
  8810. for (const obj of argsArray[i]) {
  8811. const objsPool = obj.startsWith("g_") ? this.commonObjs : this.objs;
  8812. const promise = new Promise(resolve => {
  8813. objsPool.get(obj, resolve);
  8814. });
  8815. this.current.dependencies.push(promise);
  8816. }
  8817. }
  8818. return Promise.all(this.current.dependencies);
  8819. }
  8820. transform(a, b, c, d, e, f) {
  8821. const transformMatrix = [a, b, c, d, e, f];
  8822. this.transformMatrix = _util.Util.transform(this.transformMatrix, transformMatrix);
  8823. this.tgrp = null;
  8824. }
  8825. getSVG(operatorList, viewport) {
  8826. this.viewport = viewport;
  8827. const svgElement = this._initialize(viewport);
  8828. return this.loadDependencies(operatorList).then(() => {
  8829. this.transformMatrix = _util.IDENTITY_MATRIX;
  8830. this.executeOpTree(this.convertOpList(operatorList));
  8831. return svgElement;
  8832. });
  8833. }
  8834. convertOpList(operatorList) {
  8835. const operatorIdMapping = this._operatorIdMapping;
  8836. const argsArray = operatorList.argsArray;
  8837. const fnArray = operatorList.fnArray;
  8838. const opList = [];
  8839. for (let i = 0, ii = fnArray.length; i < ii; i++) {
  8840. const fnId = fnArray[i];
  8841. opList.push({
  8842. fnId,
  8843. fn: operatorIdMapping[fnId],
  8844. args: argsArray[i]
  8845. });
  8846. }
  8847. return opListToTree(opList);
  8848. }
  8849. executeOpTree(opTree) {
  8850. for (const opTreeElement of opTree) {
  8851. const fn = opTreeElement.fn;
  8852. const fnId = opTreeElement.fnId;
  8853. const args = opTreeElement.args;
  8854. switch (fnId | 0) {
  8855. case _util.OPS.beginText:
  8856. this.beginText();
  8857. break;
  8858. case _util.OPS.dependency:
  8859. break;
  8860. case _util.OPS.setLeading:
  8861. this.setLeading(args);
  8862. break;
  8863. case _util.OPS.setLeadingMoveText:
  8864. this.setLeadingMoveText(args[0], args[1]);
  8865. break;
  8866. case _util.OPS.setFont:
  8867. this.setFont(args);
  8868. break;
  8869. case _util.OPS.showText:
  8870. this.showText(args[0]);
  8871. break;
  8872. case _util.OPS.showSpacedText:
  8873. this.showText(args[0]);
  8874. break;
  8875. case _util.OPS.endText:
  8876. this.endText();
  8877. break;
  8878. case _util.OPS.moveText:
  8879. this.moveText(args[0], args[1]);
  8880. break;
  8881. case _util.OPS.setCharSpacing:
  8882. this.setCharSpacing(args[0]);
  8883. break;
  8884. case _util.OPS.setWordSpacing:
  8885. this.setWordSpacing(args[0]);
  8886. break;
  8887. case _util.OPS.setHScale:
  8888. this.setHScale(args[0]);
  8889. break;
  8890. case _util.OPS.setTextMatrix:
  8891. this.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
  8892. break;
  8893. case _util.OPS.setTextRise:
  8894. this.setTextRise(args[0]);
  8895. break;
  8896. case _util.OPS.setTextRenderingMode:
  8897. this.setTextRenderingMode(args[0]);
  8898. break;
  8899. case _util.OPS.setLineWidth:
  8900. this.setLineWidth(args[0]);
  8901. break;
  8902. case _util.OPS.setLineJoin:
  8903. this.setLineJoin(args[0]);
  8904. break;
  8905. case _util.OPS.setLineCap:
  8906. this.setLineCap(args[0]);
  8907. break;
  8908. case _util.OPS.setMiterLimit:
  8909. this.setMiterLimit(args[0]);
  8910. break;
  8911. case _util.OPS.setFillRGBColor:
  8912. this.setFillRGBColor(args[0], args[1], args[2]);
  8913. break;
  8914. case _util.OPS.setStrokeRGBColor:
  8915. this.setStrokeRGBColor(args[0], args[1], args[2]);
  8916. break;
  8917. case _util.OPS.setStrokeColorN:
  8918. this.setStrokeColorN(args);
  8919. break;
  8920. case _util.OPS.setFillColorN:
  8921. this.setFillColorN(args);
  8922. break;
  8923. case _util.OPS.shadingFill:
  8924. this.shadingFill(args[0]);
  8925. break;
  8926. case _util.OPS.setDash:
  8927. this.setDash(args[0], args[1]);
  8928. break;
  8929. case _util.OPS.setRenderingIntent:
  8930. this.setRenderingIntent(args[0]);
  8931. break;
  8932. case _util.OPS.setFlatness:
  8933. this.setFlatness(args[0]);
  8934. break;
  8935. case _util.OPS.setGState:
  8936. this.setGState(args[0]);
  8937. break;
  8938. case _util.OPS.fill:
  8939. this.fill();
  8940. break;
  8941. case _util.OPS.eoFill:
  8942. this.eoFill();
  8943. break;
  8944. case _util.OPS.stroke:
  8945. this.stroke();
  8946. break;
  8947. case _util.OPS.fillStroke:
  8948. this.fillStroke();
  8949. break;
  8950. case _util.OPS.eoFillStroke:
  8951. this.eoFillStroke();
  8952. break;
  8953. case _util.OPS.clip:
  8954. this.clip("nonzero");
  8955. break;
  8956. case _util.OPS.eoClip:
  8957. this.clip("evenodd");
  8958. break;
  8959. case _util.OPS.paintSolidColorImageMask:
  8960. this.paintSolidColorImageMask();
  8961. break;
  8962. case _util.OPS.paintJpegXObject:
  8963. this.paintJpegXObject(args[0], args[1], args[2]);
  8964. break;
  8965. case _util.OPS.paintImageXObject:
  8966. this.paintImageXObject(args[0]);
  8967. break;
  8968. case _util.OPS.paintInlineImageXObject:
  8969. this.paintInlineImageXObject(args[0]);
  8970. break;
  8971. case _util.OPS.paintImageMaskXObject:
  8972. this.paintImageMaskXObject(args[0]);
  8973. break;
  8974. case _util.OPS.paintFormXObjectBegin:
  8975. this.paintFormXObjectBegin(args[0], args[1]);
  8976. break;
  8977. case _util.OPS.paintFormXObjectEnd:
  8978. this.paintFormXObjectEnd();
  8979. break;
  8980. case _util.OPS.closePath:
  8981. this.closePath();
  8982. break;
  8983. case _util.OPS.closeStroke:
  8984. this.closeStroke();
  8985. break;
  8986. case _util.OPS.closeFillStroke:
  8987. this.closeFillStroke();
  8988. break;
  8989. case _util.OPS.closeEOFillStroke:
  8990. this.closeEOFillStroke();
  8991. break;
  8992. case _util.OPS.nextLine:
  8993. this.nextLine();
  8994. break;
  8995. case _util.OPS.transform:
  8996. this.transform(args[0], args[1], args[2], args[3], args[4], args[5]);
  8997. break;
  8998. case _util.OPS.constructPath:
  8999. this.constructPath(args[0], args[1]);
  9000. break;
  9001. case _util.OPS.endPath:
  9002. this.endPath();
  9003. break;
  9004. case 92:
  9005. this.group(opTreeElement.items);
  9006. break;
  9007. default:
  9008. (0, _util.warn)(`Unimplemented operator ${fn}`);
  9009. break;
  9010. }
  9011. }
  9012. }
  9013. setWordSpacing(wordSpacing) {
  9014. this.current.wordSpacing = wordSpacing;
  9015. }
  9016. setCharSpacing(charSpacing) {
  9017. this.current.charSpacing = charSpacing;
  9018. }
  9019. nextLine() {
  9020. this.moveText(0, this.current.leading);
  9021. }
  9022. setTextMatrix(a, b, c, d, e, f) {
  9023. const current = this.current;
  9024. current.textMatrix = current.lineMatrix = [a, b, c, d, e, f];
  9025. current.textMatrixScale = Math.sqrt(a * a + b * b);
  9026. current.x = current.lineX = 0;
  9027. current.y = current.lineY = 0;
  9028. current.xcoords = [];
  9029. current.tspan = this.svgFactory.createElement("svg:tspan");
  9030. current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
  9031. current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
  9032. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  9033. current.txtElement = this.svgFactory.createElement("svg:text");
  9034. current.txtElement.appendChild(current.tspan);
  9035. }
  9036. beginText() {
  9037. const current = this.current;
  9038. current.x = current.lineX = 0;
  9039. current.y = current.lineY = 0;
  9040. current.textMatrix = _util.IDENTITY_MATRIX;
  9041. current.lineMatrix = _util.IDENTITY_MATRIX;
  9042. current.textMatrixScale = 1;
  9043. current.tspan = this.svgFactory.createElement("svg:tspan");
  9044. current.txtElement = this.svgFactory.createElement("svg:text");
  9045. current.txtgrp = this.svgFactory.createElement("svg:g");
  9046. current.xcoords = [];
  9047. }
  9048. moveText(x, y) {
  9049. const current = this.current;
  9050. current.x = current.lineX += x;
  9051. current.y = current.lineY += y;
  9052. current.xcoords = [];
  9053. current.tspan = this.svgFactory.createElement("svg:tspan");
  9054. current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
  9055. current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
  9056. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  9057. }
  9058. showText(glyphs) {
  9059. const current = this.current;
  9060. const font = current.font;
  9061. const fontSize = current.fontSize;
  9062. if (fontSize === 0) {
  9063. return;
  9064. }
  9065. const charSpacing = current.charSpacing;
  9066. const wordSpacing = current.wordSpacing;
  9067. const fontDirection = current.fontDirection;
  9068. const textHScale = current.textHScale * fontDirection;
  9069. const vertical = font.vertical;
  9070. const widthAdvanceScale = fontSize * current.fontMatrix[0];
  9071. let x = 0;
  9072. for (const glyph of glyphs) {
  9073. if (glyph === null) {
  9074. x += fontDirection * wordSpacing;
  9075. continue;
  9076. } else if ((0, _util.isNum)(glyph)) {
  9077. x += -glyph * fontSize * 0.001;
  9078. continue;
  9079. }
  9080. const width = glyph.width;
  9081. const character = glyph.fontChar;
  9082. const spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  9083. const charWidth = width * widthAdvanceScale + spacing * fontDirection;
  9084. if (!glyph.isInFont && !font.missingFile) {
  9085. x += charWidth;
  9086. continue;
  9087. }
  9088. current.xcoords.push(current.x + x);
  9089. current.tspan.textContent += character;
  9090. x += charWidth;
  9091. }
  9092. if (vertical) {
  9093. current.y -= x * textHScale;
  9094. } else {
  9095. current.x += x * textHScale;
  9096. }
  9097. current.tspan.setAttributeNS(null, "x", current.xcoords.map(pf).join(" "));
  9098. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  9099. current.tspan.setAttributeNS(null, "font-family", current.fontFamily);
  9100. current.tspan.setAttributeNS(null, "font-size", `${pf(current.fontSize)}px`);
  9101. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  9102. current.tspan.setAttributeNS(null, "font-style", current.fontStyle);
  9103. }
  9104. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  9105. current.tspan.setAttributeNS(null, "font-weight", current.fontWeight);
  9106. }
  9107. const fillStrokeMode = current.textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK;
  9108. if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  9109. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  9110. current.tspan.setAttributeNS(null, "fill", current.fillColor);
  9111. }
  9112. if (current.fillAlpha < 1) {
  9113. current.tspan.setAttributeNS(null, "fill-opacity", current.fillAlpha);
  9114. }
  9115. } else if (current.textRenderingMode === _util.TextRenderingMode.ADD_TO_PATH) {
  9116. current.tspan.setAttributeNS(null, "fill", "transparent");
  9117. } else {
  9118. current.tspan.setAttributeNS(null, "fill", "none");
  9119. }
  9120. if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) {
  9121. const lineWidthScale = 1 / (current.textMatrixScale || 1);
  9122. this._setStrokeAttributes(current.tspan, lineWidthScale);
  9123. }
  9124. let textMatrix = current.textMatrix;
  9125. if (current.textRise !== 0) {
  9126. textMatrix = textMatrix.slice();
  9127. textMatrix[5] += current.textRise;
  9128. }
  9129. current.txtElement.setAttributeNS(null, "transform", `${pm(textMatrix)} scale(${pf(textHScale)}, -1)`);
  9130. current.txtElement.setAttributeNS(XML_NS, "xml:space", "preserve");
  9131. current.txtElement.appendChild(current.tspan);
  9132. current.txtgrp.appendChild(current.txtElement);
  9133. this._ensureTransformGroup().appendChild(current.txtElement);
  9134. }
  9135. setLeadingMoveText(x, y) {
  9136. this.setLeading(-y);
  9137. this.moveText(x, y);
  9138. }
  9139. addFontStyle(fontObj) {
  9140. if (!this.cssStyle) {
  9141. this.cssStyle = this.svgFactory.createElement("svg:style");
  9142. this.cssStyle.setAttributeNS(null, "type", "text/css");
  9143. this.defs.appendChild(this.cssStyle);
  9144. }
  9145. const url = (0, _util.createObjectURL)(fontObj.data, fontObj.mimetype, this.forceDataSchema);
  9146. this.cssStyle.textContent += `@font-face { font-family: "${fontObj.loadedName}";` + ` src: url(${url}); }\n`;
  9147. }
  9148. setFont(details) {
  9149. const current = this.current;
  9150. const fontObj = this.commonObjs.get(details[0]);
  9151. let size = details[1];
  9152. current.font = fontObj;
  9153. if (this.embedFonts && fontObj.data && !this.embeddedFonts[fontObj.loadedName]) {
  9154. this.addFontStyle(fontObj);
  9155. this.embeddedFonts[fontObj.loadedName] = fontObj;
  9156. }
  9157. current.fontMatrix = fontObj.fontMatrix ? fontObj.fontMatrix : _util.FONT_IDENTITY_MATRIX;
  9158. let bold = "normal";
  9159. if (fontObj.black) {
  9160. bold = "900";
  9161. } else if (fontObj.bold) {
  9162. bold = "bold";
  9163. }
  9164. const italic = fontObj.italic ? "italic" : "normal";
  9165. if (size < 0) {
  9166. size = -size;
  9167. current.fontDirection = -1;
  9168. } else {
  9169. current.fontDirection = 1;
  9170. }
  9171. current.fontSize = size;
  9172. current.fontFamily = fontObj.loadedName;
  9173. current.fontWeight = bold;
  9174. current.fontStyle = italic;
  9175. current.tspan = this.svgFactory.createElement("svg:tspan");
  9176. current.tspan.setAttributeNS(null, "y", pf(-current.y));
  9177. current.xcoords = [];
  9178. }
  9179. endText() {
  9180. const current = this.current;
  9181. if (current.textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG && current.txtElement && current.txtElement.hasChildNodes()) {
  9182. current.element = current.txtElement;
  9183. this.clip("nonzero");
  9184. this.endPath();
  9185. }
  9186. }
  9187. setLineWidth(width) {
  9188. if (width > 0) {
  9189. this.current.lineWidth = width;
  9190. }
  9191. }
  9192. setLineCap(style) {
  9193. this.current.lineCap = LINE_CAP_STYLES[style];
  9194. }
  9195. setLineJoin(style) {
  9196. this.current.lineJoin = LINE_JOIN_STYLES[style];
  9197. }
  9198. setMiterLimit(limit) {
  9199. this.current.miterLimit = limit;
  9200. }
  9201. setStrokeAlpha(strokeAlpha) {
  9202. this.current.strokeAlpha = strokeAlpha;
  9203. }
  9204. setStrokeRGBColor(r, g, b) {
  9205. this.current.strokeColor = _util.Util.makeCssRgb(r, g, b);
  9206. }
  9207. setFillAlpha(fillAlpha) {
  9208. this.current.fillAlpha = fillAlpha;
  9209. }
  9210. setFillRGBColor(r, g, b) {
  9211. this.current.fillColor = _util.Util.makeCssRgb(r, g, b);
  9212. this.current.tspan = this.svgFactory.createElement("svg:tspan");
  9213. this.current.xcoords = [];
  9214. }
  9215. setStrokeColorN(args) {
  9216. this.current.strokeColor = this._makeColorN_Pattern(args);
  9217. }
  9218. setFillColorN(args) {
  9219. this.current.fillColor = this._makeColorN_Pattern(args);
  9220. }
  9221. shadingFill(args) {
  9222. const width = this.viewport.width;
  9223. const height = this.viewport.height;
  9224. const inv = _util.Util.inverseTransform(this.transformMatrix);
  9225. const bl = _util.Util.applyTransform([0, 0], inv);
  9226. const br = _util.Util.applyTransform([0, height], inv);
  9227. const ul = _util.Util.applyTransform([width, 0], inv);
  9228. const ur = _util.Util.applyTransform([width, height], inv);
  9229. const x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  9230. const y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  9231. const x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  9232. const y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  9233. const rect = this.svgFactory.createElement("svg:rect");
  9234. rect.setAttributeNS(null, "x", x0);
  9235. rect.setAttributeNS(null, "y", y0);
  9236. rect.setAttributeNS(null, "width", x1 - x0);
  9237. rect.setAttributeNS(null, "height", y1 - y0);
  9238. rect.setAttributeNS(null, "fill", this._makeShadingPattern(args));
  9239. this._ensureTransformGroup().appendChild(rect);
  9240. }
  9241. _makeColorN_Pattern(args) {
  9242. if (args[0] === "TilingPattern") {
  9243. return this._makeTilingPattern(args);
  9244. }
  9245. return this._makeShadingPattern(args);
  9246. }
  9247. _makeTilingPattern(args) {
  9248. const color = args[1];
  9249. const operatorList = args[2];
  9250. const matrix = args[3] || _util.IDENTITY_MATRIX;
  9251. const [x0, y0, x1, y1] = args[4];
  9252. const xstep = args[5];
  9253. const ystep = args[6];
  9254. const paintType = args[7];
  9255. const tilingId = `shading${shadingCount++}`;
  9256. const [tx0, ty0] = _util.Util.applyTransform([x0, y0], matrix);
  9257. const [tx1, ty1] = _util.Util.applyTransform([x1, y1], matrix);
  9258. const [xscale, yscale] = _util.Util.singularValueDecompose2dScale(matrix);
  9259. const txstep = xstep * xscale;
  9260. const tystep = ystep * yscale;
  9261. const tiling = this.svgFactory.createElement("svg:pattern");
  9262. tiling.setAttributeNS(null, "id", tilingId);
  9263. tiling.setAttributeNS(null, "patternUnits", "userSpaceOnUse");
  9264. tiling.setAttributeNS(null, "width", txstep);
  9265. tiling.setAttributeNS(null, "height", tystep);
  9266. tiling.setAttributeNS(null, "x", `${tx0}`);
  9267. tiling.setAttributeNS(null, "y", `${ty0}`);
  9268. const svg = this.svg;
  9269. const transformMatrix = this.transformMatrix;
  9270. const fillColor = this.current.fillColor;
  9271. const strokeColor = this.current.strokeColor;
  9272. const bbox = this.svgFactory.create(tx1 - tx0, ty1 - ty0);
  9273. this.svg = bbox;
  9274. this.transformMatrix = matrix;
  9275. if (paintType === 2) {
  9276. const cssColor = _util.Util.makeCssRgb(...color);
  9277. this.current.fillColor = cssColor;
  9278. this.current.strokeColor = cssColor;
  9279. }
  9280. this.executeOpTree(this.convertOpList(operatorList));
  9281. this.svg = svg;
  9282. this.transformMatrix = transformMatrix;
  9283. this.current.fillColor = fillColor;
  9284. this.current.strokeColor = strokeColor;
  9285. tiling.appendChild(bbox.childNodes[0]);
  9286. this.defs.appendChild(tiling);
  9287. return `url(#${tilingId})`;
  9288. }
  9289. _makeShadingPattern(args) {
  9290. switch (args[0]) {
  9291. case "RadialAxial":
  9292. const shadingId = `shading${shadingCount++}`;
  9293. const colorStops = args[3];
  9294. let gradient;
  9295. switch (args[1]) {
  9296. case "axial":
  9297. const point0 = args[4];
  9298. const point1 = args[5];
  9299. gradient = this.svgFactory.createElement("svg:linearGradient");
  9300. gradient.setAttributeNS(null, "id", shadingId);
  9301. gradient.setAttributeNS(null, "gradientUnits", "userSpaceOnUse");
  9302. gradient.setAttributeNS(null, "x1", point0[0]);
  9303. gradient.setAttributeNS(null, "y1", point0[1]);
  9304. gradient.setAttributeNS(null, "x2", point1[0]);
  9305. gradient.setAttributeNS(null, "y2", point1[1]);
  9306. break;
  9307. case "radial":
  9308. const focalPoint = args[4];
  9309. const circlePoint = args[5];
  9310. const focalRadius = args[6];
  9311. const circleRadius = args[7];
  9312. gradient = this.svgFactory.createElement("svg:radialGradient");
  9313. gradient.setAttributeNS(null, "id", shadingId);
  9314. gradient.setAttributeNS(null, "gradientUnits", "userSpaceOnUse");
  9315. gradient.setAttributeNS(null, "cx", circlePoint[0]);
  9316. gradient.setAttributeNS(null, "cy", circlePoint[1]);
  9317. gradient.setAttributeNS(null, "r", circleRadius);
  9318. gradient.setAttributeNS(null, "fx", focalPoint[0]);
  9319. gradient.setAttributeNS(null, "fy", focalPoint[1]);
  9320. gradient.setAttributeNS(null, "fr", focalRadius);
  9321. break;
  9322. default:
  9323. throw new Error(`Unknown RadialAxial type: ${args[1]}`);
  9324. }
  9325. for (const colorStop of colorStops) {
  9326. const stop = this.svgFactory.createElement("svg:stop");
  9327. stop.setAttributeNS(null, "offset", colorStop[0]);
  9328. stop.setAttributeNS(null, "stop-color", colorStop[1]);
  9329. gradient.appendChild(stop);
  9330. }
  9331. this.defs.appendChild(gradient);
  9332. return `url(#${shadingId})`;
  9333. case "Mesh":
  9334. (0, _util.warn)("Unimplemented pattern Mesh");
  9335. return null;
  9336. case "Dummy":
  9337. return "hotpink";
  9338. default:
  9339. throw new Error(`Unknown IR type: ${args[0]}`);
  9340. }
  9341. }
  9342. setDash(dashArray, dashPhase) {
  9343. this.current.dashArray = dashArray;
  9344. this.current.dashPhase = dashPhase;
  9345. }
  9346. constructPath(ops, args) {
  9347. const current = this.current;
  9348. let x = current.x,
  9349. y = current.y;
  9350. let d = [];
  9351. let j = 0;
  9352. for (const op of ops) {
  9353. switch (op | 0) {
  9354. case _util.OPS.rectangle:
  9355. x = args[j++];
  9356. y = args[j++];
  9357. const width = args[j++];
  9358. const height = args[j++];
  9359. const xw = x + width;
  9360. const yh = y + height;
  9361. d.push("M", pf(x), pf(y), "L", pf(xw), pf(y), "L", pf(xw), pf(yh), "L", pf(x), pf(yh), "Z");
  9362. break;
  9363. case _util.OPS.moveTo:
  9364. x = args[j++];
  9365. y = args[j++];
  9366. d.push("M", pf(x), pf(y));
  9367. break;
  9368. case _util.OPS.lineTo:
  9369. x = args[j++];
  9370. y = args[j++];
  9371. d.push("L", pf(x), pf(y));
  9372. break;
  9373. case _util.OPS.curveTo:
  9374. x = args[j + 4];
  9375. y = args[j + 5];
  9376. d.push("C", pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]), pf(x), pf(y));
  9377. j += 6;
  9378. break;
  9379. case _util.OPS.curveTo2:
  9380. d.push("C", pf(x), pf(y), pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]));
  9381. x = args[j + 2];
  9382. y = args[j + 3];
  9383. j += 4;
  9384. break;
  9385. case _util.OPS.curveTo3:
  9386. x = args[j + 2];
  9387. y = args[j + 3];
  9388. d.push("C", pf(args[j]), pf(args[j + 1]), pf(x), pf(y), pf(x), pf(y));
  9389. j += 4;
  9390. break;
  9391. case _util.OPS.closePath:
  9392. d.push("Z");
  9393. break;
  9394. }
  9395. }
  9396. d = d.join(" ");
  9397. if (current.path && ops.length > 0 && ops[0] !== _util.OPS.rectangle && ops[0] !== _util.OPS.moveTo) {
  9398. d = current.path.getAttributeNS(null, "d") + d;
  9399. } else {
  9400. current.path = this.svgFactory.createElement("svg:path");
  9401. this._ensureTransformGroup().appendChild(current.path);
  9402. }
  9403. current.path.setAttributeNS(null, "d", d);
  9404. current.path.setAttributeNS(null, "fill", "none");
  9405. current.element = current.path;
  9406. current.setCurrentPoint(x, y);
  9407. }
  9408. endPath() {
  9409. const current = this.current;
  9410. current.path = null;
  9411. if (!this.pendingClip) {
  9412. return;
  9413. }
  9414. if (!current.element) {
  9415. this.pendingClip = null;
  9416. return;
  9417. }
  9418. const clipId = `clippath${clipCount++}`;
  9419. const clipPath = this.svgFactory.createElement("svg:clipPath");
  9420. clipPath.setAttributeNS(null, "id", clipId);
  9421. clipPath.setAttributeNS(null, "transform", pm(this.transformMatrix));
  9422. const clipElement = current.element.cloneNode(true);
  9423. if (this.pendingClip === "evenodd") {
  9424. clipElement.setAttributeNS(null, "clip-rule", "evenodd");
  9425. } else {
  9426. clipElement.setAttributeNS(null, "clip-rule", "nonzero");
  9427. }
  9428. this.pendingClip = null;
  9429. clipPath.appendChild(clipElement);
  9430. this.defs.appendChild(clipPath);
  9431. if (current.activeClipUrl) {
  9432. current.clipGroup = null;
  9433. this.extraStack.forEach(function (prev) {
  9434. prev.clipGroup = null;
  9435. });
  9436. clipPath.setAttributeNS(null, "clip-path", current.activeClipUrl);
  9437. }
  9438. current.activeClipUrl = `url(#${clipId})`;
  9439. this.tgrp = null;
  9440. }
  9441. clip(type) {
  9442. this.pendingClip = type;
  9443. }
  9444. closePath() {
  9445. const current = this.current;
  9446. if (current.path) {
  9447. const d = `${current.path.getAttributeNS(null, "d")}Z`;
  9448. current.path.setAttributeNS(null, "d", d);
  9449. }
  9450. }
  9451. setLeading(leading) {
  9452. this.current.leading = -leading;
  9453. }
  9454. setTextRise(textRise) {
  9455. this.current.textRise = textRise;
  9456. }
  9457. setTextRenderingMode(textRenderingMode) {
  9458. this.current.textRenderingMode = textRenderingMode;
  9459. }
  9460. setHScale(scale) {
  9461. this.current.textHScale = scale / 100;
  9462. }
  9463. setRenderingIntent(intent) {}
  9464. setFlatness(flatness) {}
  9465. setGState(states) {
  9466. for (const [key, value] of states) {
  9467. switch (key) {
  9468. case "LW":
  9469. this.setLineWidth(value);
  9470. break;
  9471. case "LC":
  9472. this.setLineCap(value);
  9473. break;
  9474. case "LJ":
  9475. this.setLineJoin(value);
  9476. break;
  9477. case "ML":
  9478. this.setMiterLimit(value);
  9479. break;
  9480. case "D":
  9481. this.setDash(value[0], value[1]);
  9482. break;
  9483. case "RI":
  9484. this.setRenderingIntent(value);
  9485. break;
  9486. case "FL":
  9487. this.setFlatness(value);
  9488. break;
  9489. case "Font":
  9490. this.setFont(value);
  9491. break;
  9492. case "CA":
  9493. this.setStrokeAlpha(value);
  9494. break;
  9495. case "ca":
  9496. this.setFillAlpha(value);
  9497. break;
  9498. default:
  9499. (0, _util.warn)(`Unimplemented graphic state operator ${key}`);
  9500. break;
  9501. }
  9502. }
  9503. }
  9504. fill() {
  9505. const current = this.current;
  9506. if (current.element) {
  9507. current.element.setAttributeNS(null, "fill", current.fillColor);
  9508. current.element.setAttributeNS(null, "fill-opacity", current.fillAlpha);
  9509. this.endPath();
  9510. }
  9511. }
  9512. stroke() {
  9513. const current = this.current;
  9514. if (current.element) {
  9515. this._setStrokeAttributes(current.element);
  9516. current.element.setAttributeNS(null, "fill", "none");
  9517. this.endPath();
  9518. }
  9519. }
  9520. _setStrokeAttributes(element, lineWidthScale = 1) {
  9521. const current = this.current;
  9522. let dashArray = current.dashArray;
  9523. if (lineWidthScale !== 1 && dashArray.length > 0) {
  9524. dashArray = dashArray.map(function (value) {
  9525. return lineWidthScale * value;
  9526. });
  9527. }
  9528. element.setAttributeNS(null, "stroke", current.strokeColor);
  9529. element.setAttributeNS(null, "stroke-opacity", current.strokeAlpha);
  9530. element.setAttributeNS(null, "stroke-miterlimit", pf(current.miterLimit));
  9531. element.setAttributeNS(null, "stroke-linecap", current.lineCap);
  9532. element.setAttributeNS(null, "stroke-linejoin", current.lineJoin);
  9533. element.setAttributeNS(null, "stroke-width", pf(lineWidthScale * current.lineWidth) + "px");
  9534. element.setAttributeNS(null, "stroke-dasharray", dashArray.map(pf).join(" "));
  9535. element.setAttributeNS(null, "stroke-dashoffset", pf(lineWidthScale * current.dashPhase) + "px");
  9536. }
  9537. eoFill() {
  9538. if (this.current.element) {
  9539. this.current.element.setAttributeNS(null, "fill-rule", "evenodd");
  9540. }
  9541. this.fill();
  9542. }
  9543. fillStroke() {
  9544. this.stroke();
  9545. this.fill();
  9546. }
  9547. eoFillStroke() {
  9548. if (this.current.element) {
  9549. this.current.element.setAttributeNS(null, "fill-rule", "evenodd");
  9550. }
  9551. this.fillStroke();
  9552. }
  9553. closeStroke() {
  9554. this.closePath();
  9555. this.stroke();
  9556. }
  9557. closeFillStroke() {
  9558. this.closePath();
  9559. this.fillStroke();
  9560. }
  9561. closeEOFillStroke() {
  9562. this.closePath();
  9563. this.eoFillStroke();
  9564. }
  9565. paintSolidColorImageMask() {
  9566. const rect = this.svgFactory.createElement("svg:rect");
  9567. rect.setAttributeNS(null, "x", "0");
  9568. rect.setAttributeNS(null, "y", "0");
  9569. rect.setAttributeNS(null, "width", "1px");
  9570. rect.setAttributeNS(null, "height", "1px");
  9571. rect.setAttributeNS(null, "fill", this.current.fillColor);
  9572. this._ensureTransformGroup().appendChild(rect);
  9573. }
  9574. paintJpegXObject(objId, w, h) {
  9575. const imgObj = this.objs.get(objId);
  9576. const imgEl = this.svgFactory.createElement("svg:image");
  9577. imgEl.setAttributeNS(XLINK_NS, "xlink:href", imgObj.src);
  9578. imgEl.setAttributeNS(null, "width", pf(w));
  9579. imgEl.setAttributeNS(null, "height", pf(h));
  9580. imgEl.setAttributeNS(null, "x", "0");
  9581. imgEl.setAttributeNS(null, "y", pf(-h));
  9582. imgEl.setAttributeNS(null, "transform", `scale(${pf(1 / w)} ${pf(-1 / h)})`);
  9583. this._ensureTransformGroup().appendChild(imgEl);
  9584. }
  9585. paintImageXObject(objId) {
  9586. const imgData = this.objs.get(objId);
  9587. if (!imgData) {
  9588. (0, _util.warn)(`Dependent image with object ID ${objId} is not ready yet`);
  9589. return;
  9590. }
  9591. this.paintInlineImageXObject(imgData);
  9592. }
  9593. paintInlineImageXObject(imgData, mask) {
  9594. const width = imgData.width;
  9595. const height = imgData.height;
  9596. const imgSrc = convertImgDataToPng(imgData, this.forceDataSchema, !!mask);
  9597. const cliprect = this.svgFactory.createElement("svg:rect");
  9598. cliprect.setAttributeNS(null, "x", "0");
  9599. cliprect.setAttributeNS(null, "y", "0");
  9600. cliprect.setAttributeNS(null, "width", pf(width));
  9601. cliprect.setAttributeNS(null, "height", pf(height));
  9602. this.current.element = cliprect;
  9603. this.clip("nonzero");
  9604. const imgEl = this.svgFactory.createElement("svg:image");
  9605. imgEl.setAttributeNS(XLINK_NS, "xlink:href", imgSrc);
  9606. imgEl.setAttributeNS(null, "x", "0");
  9607. imgEl.setAttributeNS(null, "y", pf(-height));
  9608. imgEl.setAttributeNS(null, "width", pf(width) + "px");
  9609. imgEl.setAttributeNS(null, "height", pf(height) + "px");
  9610. imgEl.setAttributeNS(null, "transform", `scale(${pf(1 / width)} ${pf(-1 / height)})`);
  9611. if (mask) {
  9612. mask.appendChild(imgEl);
  9613. } else {
  9614. this._ensureTransformGroup().appendChild(imgEl);
  9615. }
  9616. }
  9617. paintImageMaskXObject(imgData) {
  9618. const current = this.current;
  9619. const width = imgData.width;
  9620. const height = imgData.height;
  9621. const fillColor = current.fillColor;
  9622. current.maskId = `mask${maskCount++}`;
  9623. const mask = this.svgFactory.createElement("svg:mask");
  9624. mask.setAttributeNS(null, "id", current.maskId);
  9625. const rect = this.svgFactory.createElement("svg:rect");
  9626. rect.setAttributeNS(null, "x", "0");
  9627. rect.setAttributeNS(null, "y", "0");
  9628. rect.setAttributeNS(null, "width", pf(width));
  9629. rect.setAttributeNS(null, "height", pf(height));
  9630. rect.setAttributeNS(null, "fill", fillColor);
  9631. rect.setAttributeNS(null, "mask", `url(#${current.maskId})`);
  9632. this.defs.appendChild(mask);
  9633. this._ensureTransformGroup().appendChild(rect);
  9634. this.paintInlineImageXObject(imgData, mask);
  9635. }
  9636. paintFormXObjectBegin(matrix, bbox) {
  9637. if (Array.isArray(matrix) && matrix.length === 6) {
  9638. this.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
  9639. }
  9640. if (bbox) {
  9641. const width = bbox[2] - bbox[0];
  9642. const height = bbox[3] - bbox[1];
  9643. const cliprect = this.svgFactory.createElement("svg:rect");
  9644. cliprect.setAttributeNS(null, "x", bbox[0]);
  9645. cliprect.setAttributeNS(null, "y", bbox[1]);
  9646. cliprect.setAttributeNS(null, "width", pf(width));
  9647. cliprect.setAttributeNS(null, "height", pf(height));
  9648. this.current.element = cliprect;
  9649. this.clip("nonzero");
  9650. this.endPath();
  9651. }
  9652. }
  9653. paintFormXObjectEnd() {}
  9654. _initialize(viewport) {
  9655. const svg = this.svgFactory.create(viewport.width, viewport.height);
  9656. const definitions = this.svgFactory.createElement("svg:defs");
  9657. svg.appendChild(definitions);
  9658. this.defs = definitions;
  9659. const rootGroup = this.svgFactory.createElement("svg:g");
  9660. rootGroup.setAttributeNS(null, "transform", pm(viewport.transform));
  9661. svg.appendChild(rootGroup);
  9662. this.svg = rootGroup;
  9663. return svg;
  9664. }
  9665. _ensureClipGroup() {
  9666. if (!this.current.clipGroup) {
  9667. const clipGroup = this.svgFactory.createElement("svg:g");
  9668. clipGroup.setAttributeNS(null, "clip-path", this.current.activeClipUrl);
  9669. this.svg.appendChild(clipGroup);
  9670. this.current.clipGroup = clipGroup;
  9671. }
  9672. return this.current.clipGroup;
  9673. }
  9674. _ensureTransformGroup() {
  9675. if (!this.tgrp) {
  9676. this.tgrp = this.svgFactory.createElement("svg:g");
  9677. this.tgrp.setAttributeNS(null, "transform", pm(this.transformMatrix));
  9678. if (this.current.activeClipUrl) {
  9679. this._ensureClipGroup().appendChild(this.tgrp);
  9680. } else {
  9681. this.svg.appendChild(this.tgrp);
  9682. }
  9683. }
  9684. return this.tgrp;
  9685. }
  9686. };
  9687. }
  9688. /***/ }),
  9689. /* 19 */
  9690. /***/ (function(module, exports, __w_pdfjs_require__) {
  9691. "use strict";
  9692. Object.defineProperty(exports, "__esModule", {
  9693. value: true
  9694. });
  9695. exports.PDFNodeStream = void 0;
  9696. var _util = __w_pdfjs_require__(1);
  9697. var _network_utils = __w_pdfjs_require__(20);
  9698. const fs = require("fs");
  9699. const http = require("http");
  9700. const https = require("https");
  9701. const url = require("url");
  9702. const fileUriRegex = /^file:\/\/\/[a-zA-Z]:\//;
  9703. function parseUrl(sourceUrl) {
  9704. const parsedUrl = url.parse(sourceUrl);
  9705. if (parsedUrl.protocol === "file:" || parsedUrl.host) {
  9706. return parsedUrl;
  9707. }
  9708. if (/^[a-z]:[/\\]/i.test(sourceUrl)) {
  9709. return url.parse(`file:///${sourceUrl}`);
  9710. }
  9711. if (!parsedUrl.host) {
  9712. parsedUrl.protocol = "file:";
  9713. }
  9714. return parsedUrl;
  9715. }
  9716. class PDFNodeStream {
  9717. constructor(source) {
  9718. this.source = source;
  9719. this.url = parseUrl(source.url);
  9720. this.isHttp = this.url.protocol === "http:" || this.url.protocol === "https:";
  9721. this.isFsUrl = this.url.protocol === "file:";
  9722. this.httpHeaders = this.isHttp && source.httpHeaders || {};
  9723. this._fullRequestReader = null;
  9724. this._rangeRequestReaders = [];
  9725. }
  9726. get _progressiveDataLength() {
  9727. return this._fullRequestReader ? this._fullRequestReader._loaded : 0;
  9728. }
  9729. getFullReader() {
  9730. (0, _util.assert)(!this._fullRequestReader);
  9731. this._fullRequestReader = this.isFsUrl ? new PDFNodeStreamFsFullReader(this) : new PDFNodeStreamFullReader(this);
  9732. return this._fullRequestReader;
  9733. }
  9734. getRangeReader(start, end) {
  9735. if (end <= this._progressiveDataLength) {
  9736. return null;
  9737. }
  9738. const rangeReader = this.isFsUrl ? new PDFNodeStreamFsRangeReader(this, start, end) : new PDFNodeStreamRangeReader(this, start, end);
  9739. this._rangeRequestReaders.push(rangeReader);
  9740. return rangeReader;
  9741. }
  9742. cancelAllRequests(reason) {
  9743. if (this._fullRequestReader) {
  9744. this._fullRequestReader.cancel(reason);
  9745. }
  9746. const readers = this._rangeRequestReaders.slice(0);
  9747. readers.forEach(function (reader) {
  9748. reader.cancel(reason);
  9749. });
  9750. }
  9751. }
  9752. exports.PDFNodeStream = PDFNodeStream;
  9753. class BaseFullReader {
  9754. constructor(stream) {
  9755. this._url = stream.url;
  9756. this._done = false;
  9757. this._storedError = null;
  9758. this.onProgress = null;
  9759. const source = stream.source;
  9760. this._contentLength = source.length;
  9761. this._loaded = 0;
  9762. this._filename = null;
  9763. this._disableRange = source.disableRange || false;
  9764. this._rangeChunkSize = source.rangeChunkSize;
  9765. if (!this._rangeChunkSize && !this._disableRange) {
  9766. this._disableRange = true;
  9767. }
  9768. this._isStreamingSupported = !source.disableStream;
  9769. this._isRangeSupported = !source.disableRange;
  9770. this._readableStream = null;
  9771. this._readCapability = (0, _util.createPromiseCapability)();
  9772. this._headersCapability = (0, _util.createPromiseCapability)();
  9773. }
  9774. get headersReady() {
  9775. return this._headersCapability.promise;
  9776. }
  9777. get filename() {
  9778. return this._filename;
  9779. }
  9780. get contentLength() {
  9781. return this._contentLength;
  9782. }
  9783. get isRangeSupported() {
  9784. return this._isRangeSupported;
  9785. }
  9786. get isStreamingSupported() {
  9787. return this._isStreamingSupported;
  9788. }
  9789. async read() {
  9790. await this._readCapability.promise;
  9791. if (this._done) {
  9792. return {
  9793. value: undefined,
  9794. done: true
  9795. };
  9796. }
  9797. if (this._storedError) {
  9798. throw this._storedError;
  9799. }
  9800. const chunk = this._readableStream.read();
  9801. if (chunk === null) {
  9802. this._readCapability = (0, _util.createPromiseCapability)();
  9803. return this.read();
  9804. }
  9805. this._loaded += chunk.length;
  9806. if (this.onProgress) {
  9807. this.onProgress({
  9808. loaded: this._loaded,
  9809. total: this._contentLength
  9810. });
  9811. }
  9812. const buffer = new Uint8Array(chunk).buffer;
  9813. return {
  9814. value: buffer,
  9815. done: false
  9816. };
  9817. }
  9818. cancel(reason) {
  9819. if (!this._readableStream) {
  9820. this._error(reason);
  9821. return;
  9822. }
  9823. this._readableStream.destroy(reason);
  9824. }
  9825. _error(reason) {
  9826. this._storedError = reason;
  9827. this._readCapability.resolve();
  9828. }
  9829. _setReadableStream(readableStream) {
  9830. this._readableStream = readableStream;
  9831. readableStream.on("readable", () => {
  9832. this._readCapability.resolve();
  9833. });
  9834. readableStream.on("end", () => {
  9835. readableStream.destroy();
  9836. this._done = true;
  9837. this._readCapability.resolve();
  9838. });
  9839. readableStream.on("error", reason => {
  9840. this._error(reason);
  9841. });
  9842. if (!this._isStreamingSupported && this._isRangeSupported) {
  9843. this._error(new _util.AbortException("streaming is disabled"));
  9844. }
  9845. if (this._storedError) {
  9846. this._readableStream.destroy(this._storedError);
  9847. }
  9848. }
  9849. }
  9850. class BaseRangeReader {
  9851. constructor(stream) {
  9852. this._url = stream.url;
  9853. this._done = false;
  9854. this._storedError = null;
  9855. this.onProgress = null;
  9856. this._loaded = 0;
  9857. this._readableStream = null;
  9858. this._readCapability = (0, _util.createPromiseCapability)();
  9859. const source = stream.source;
  9860. this._isStreamingSupported = !source.disableStream;
  9861. }
  9862. get isStreamingSupported() {
  9863. return this._isStreamingSupported;
  9864. }
  9865. async read() {
  9866. await this._readCapability.promise;
  9867. if (this._done) {
  9868. return {
  9869. value: undefined,
  9870. done: true
  9871. };
  9872. }
  9873. if (this._storedError) {
  9874. throw this._storedError;
  9875. }
  9876. const chunk = this._readableStream.read();
  9877. if (chunk === null) {
  9878. this._readCapability = (0, _util.createPromiseCapability)();
  9879. return this.read();
  9880. }
  9881. this._loaded += chunk.length;
  9882. if (this.onProgress) {
  9883. this.onProgress({
  9884. loaded: this._loaded
  9885. });
  9886. }
  9887. const buffer = new Uint8Array(chunk).buffer;
  9888. return {
  9889. value: buffer,
  9890. done: false
  9891. };
  9892. }
  9893. cancel(reason) {
  9894. if (!this._readableStream) {
  9895. this._error(reason);
  9896. return;
  9897. }
  9898. this._readableStream.destroy(reason);
  9899. }
  9900. _error(reason) {
  9901. this._storedError = reason;
  9902. this._readCapability.resolve();
  9903. }
  9904. _setReadableStream(readableStream) {
  9905. this._readableStream = readableStream;
  9906. readableStream.on("readable", () => {
  9907. this._readCapability.resolve();
  9908. });
  9909. readableStream.on("end", () => {
  9910. readableStream.destroy();
  9911. this._done = true;
  9912. this._readCapability.resolve();
  9913. });
  9914. readableStream.on("error", reason => {
  9915. this._error(reason);
  9916. });
  9917. if (this._storedError) {
  9918. this._readableStream.destroy(this._storedError);
  9919. }
  9920. }
  9921. }
  9922. function createRequestOptions(url, headers) {
  9923. return {
  9924. protocol: url.protocol,
  9925. auth: url.auth,
  9926. host: url.hostname,
  9927. port: url.port,
  9928. path: url.path,
  9929. method: "GET",
  9930. headers
  9931. };
  9932. }
  9933. class PDFNodeStreamFullReader extends BaseFullReader {
  9934. constructor(stream) {
  9935. super(stream);
  9936. const handleResponse = response => {
  9937. if (response.statusCode === 404) {
  9938. const error = new _util.MissingPDFException(`Missing PDF "${this._url}".`);
  9939. this._storedError = error;
  9940. this._headersCapability.reject(error);
  9941. return;
  9942. }
  9943. this._headersCapability.resolve();
  9944. this._setReadableStream(response);
  9945. const getResponseHeader = name => {
  9946. return this._readableStream.headers[name.toLowerCase()];
  9947. };
  9948. const {
  9949. allowRangeRequests,
  9950. suggestedLength
  9951. } = (0, _network_utils.validateRangeRequestCapabilities)({
  9952. getResponseHeader,
  9953. isHttp: stream.isHttp,
  9954. rangeChunkSize: this._rangeChunkSize,
  9955. disableRange: this._disableRange
  9956. });
  9957. this._isRangeSupported = allowRangeRequests;
  9958. this._contentLength = suggestedLength || this._contentLength;
  9959. this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
  9960. };
  9961. this._request = null;
  9962. if (this._url.protocol === "http:") {
  9963. this._request = http.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
  9964. } else {
  9965. this._request = https.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
  9966. }
  9967. this._request.on("error", reason => {
  9968. this._storedError = reason;
  9969. this._headersCapability.reject(reason);
  9970. });
  9971. this._request.end();
  9972. }
  9973. }
  9974. class PDFNodeStreamRangeReader extends BaseRangeReader {
  9975. constructor(stream, start, end) {
  9976. super(stream);
  9977. this._httpHeaders = {};
  9978. for (const property in stream.httpHeaders) {
  9979. const value = stream.httpHeaders[property];
  9980. if (typeof value === "undefined") {
  9981. continue;
  9982. }
  9983. this._httpHeaders[property] = value;
  9984. }
  9985. this._httpHeaders["Range"] = `bytes=${start}-${end - 1}`;
  9986. const handleResponse = response => {
  9987. if (response.statusCode === 404) {
  9988. const error = new _util.MissingPDFException(`Missing PDF "${this._url}".`);
  9989. this._storedError = error;
  9990. return;
  9991. }
  9992. this._setReadableStream(response);
  9993. };
  9994. this._request = null;
  9995. if (this._url.protocol === "http:") {
  9996. this._request = http.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
  9997. } else {
  9998. this._request = https.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
  9999. }
  10000. this._request.on("error", reason => {
  10001. this._storedError = reason;
  10002. });
  10003. this._request.end();
  10004. }
  10005. }
  10006. class PDFNodeStreamFsFullReader extends BaseFullReader {
  10007. constructor(stream) {
  10008. super(stream);
  10009. let path = decodeURIComponent(this._url.path);
  10010. if (fileUriRegex.test(this._url.href)) {
  10011. path = path.replace(/^\//, "");
  10012. }
  10013. fs.lstat(path, (error, stat) => {
  10014. if (error) {
  10015. if (error.code === "ENOENT") {
  10016. error = new _util.MissingPDFException(`Missing PDF "${path}".`);
  10017. }
  10018. this._storedError = error;
  10019. this._headersCapability.reject(error);
  10020. return;
  10021. }
  10022. this._contentLength = stat.size;
  10023. this._setReadableStream(fs.createReadStream(path));
  10024. this._headersCapability.resolve();
  10025. });
  10026. }
  10027. }
  10028. class PDFNodeStreamFsRangeReader extends BaseRangeReader {
  10029. constructor(stream, start, end) {
  10030. super(stream);
  10031. let path = decodeURIComponent(this._url.path);
  10032. if (fileUriRegex.test(this._url.href)) {
  10033. path = path.replace(/^\//, "");
  10034. }
  10035. this._setReadableStream(fs.createReadStream(path, {
  10036. start,
  10037. end: end - 1
  10038. }));
  10039. }
  10040. }
  10041. /***/ }),
  10042. /* 20 */
  10043. /***/ (function(module, exports, __w_pdfjs_require__) {
  10044. "use strict";
  10045. Object.defineProperty(exports, "__esModule", {
  10046. value: true
  10047. });
  10048. exports.createResponseStatusError = createResponseStatusError;
  10049. exports.extractFilenameFromHeader = extractFilenameFromHeader;
  10050. exports.validateRangeRequestCapabilities = validateRangeRequestCapabilities;
  10051. exports.validateResponseStatus = validateResponseStatus;
  10052. var _util = __w_pdfjs_require__(1);
  10053. var _content_disposition = __w_pdfjs_require__(21);
  10054. function validateRangeRequestCapabilities({
  10055. getResponseHeader,
  10056. isHttp,
  10057. rangeChunkSize,
  10058. disableRange
  10059. }) {
  10060. (0, _util.assert)(rangeChunkSize > 0, "Range chunk size must be larger than zero");
  10061. const returnValues = {
  10062. allowRangeRequests: false,
  10063. suggestedLength: undefined
  10064. };
  10065. const length = parseInt(getResponseHeader("Content-Length"), 10);
  10066. if (!Number.isInteger(length)) {
  10067. return returnValues;
  10068. }
  10069. returnValues.suggestedLength = length;
  10070. if (length <= 2 * rangeChunkSize) {
  10071. return returnValues;
  10072. }
  10073. if (disableRange || !isHttp) {
  10074. return returnValues;
  10075. }
  10076. if (getResponseHeader("Accept-Ranges") !== "bytes") {
  10077. return returnValues;
  10078. }
  10079. const contentEncoding = getResponseHeader("Content-Encoding") || "identity";
  10080. if (contentEncoding !== "identity") {
  10081. return returnValues;
  10082. }
  10083. returnValues.allowRangeRequests = true;
  10084. return returnValues;
  10085. }
  10086. function extractFilenameFromHeader(getResponseHeader) {
  10087. const contentDisposition = getResponseHeader("Content-Disposition");
  10088. if (contentDisposition) {
  10089. let filename = (0, _content_disposition.getFilenameFromContentDispositionHeader)(contentDisposition);
  10090. if (filename.includes("%")) {
  10091. try {
  10092. filename = decodeURIComponent(filename);
  10093. } catch (ex) {}
  10094. }
  10095. if (/\.pdf$/i.test(filename)) {
  10096. return filename;
  10097. }
  10098. }
  10099. return null;
  10100. }
  10101. function createResponseStatusError(status, url) {
  10102. if (status === 404 || status === 0 && url.startsWith("file:")) {
  10103. return new _util.MissingPDFException('Missing PDF "' + url + '".');
  10104. }
  10105. return new _util.UnexpectedResponseException("Unexpected server response (" + status + ') while retrieving PDF "' + url + '".', status);
  10106. }
  10107. function validateResponseStatus(status) {
  10108. return status === 200 || status === 206;
  10109. }
  10110. /***/ }),
  10111. /* 21 */
  10112. /***/ (function(module, exports, __w_pdfjs_require__) {
  10113. "use strict";
  10114. Object.defineProperty(exports, "__esModule", {
  10115. value: true
  10116. });
  10117. exports.getFilenameFromContentDispositionHeader = getFilenameFromContentDispositionHeader;
  10118. function getFilenameFromContentDispositionHeader(contentDisposition) {
  10119. let needsEncodingFixup = true;
  10120. let tmp = toParamRegExp("filename\\*", "i").exec(contentDisposition);
  10121. if (tmp) {
  10122. tmp = tmp[1];
  10123. let filename = rfc2616unquote(tmp);
  10124. filename = unescape(filename);
  10125. filename = rfc5987decode(filename);
  10126. filename = rfc2047decode(filename);
  10127. return fixupEncoding(filename);
  10128. }
  10129. tmp = rfc2231getparam(contentDisposition);
  10130. if (tmp) {
  10131. const filename = rfc2047decode(tmp);
  10132. return fixupEncoding(filename);
  10133. }
  10134. tmp = toParamRegExp("filename", "i").exec(contentDisposition);
  10135. if (tmp) {
  10136. tmp = tmp[1];
  10137. let filename = rfc2616unquote(tmp);
  10138. filename = rfc2047decode(filename);
  10139. return fixupEncoding(filename);
  10140. }
  10141. function toParamRegExp(attributePattern, flags) {
  10142. return new RegExp("(?:^|;)\\s*" + attributePattern + "\\s*=\\s*" + "(" + '[^";\\s][^;\\s]*' + "|" + '"(?:[^"\\\\]|\\\\"?)+"?' + ")", flags);
  10143. }
  10144. function textdecode(encoding, value) {
  10145. if (encoding) {
  10146. if (!/^[\x00-\xFF]+$/.test(value)) {
  10147. return value;
  10148. }
  10149. try {
  10150. const decoder = new TextDecoder(encoding, {
  10151. fatal: true
  10152. });
  10153. const bytes = Array.from(value, function (ch) {
  10154. return ch.charCodeAt(0) & 0xff;
  10155. });
  10156. value = decoder.decode(new Uint8Array(bytes));
  10157. needsEncodingFixup = false;
  10158. } catch (e) {
  10159. if (/^utf-?8$/i.test(encoding)) {
  10160. try {
  10161. value = decodeURIComponent(escape(value));
  10162. needsEncodingFixup = false;
  10163. } catch (err) {}
  10164. }
  10165. }
  10166. }
  10167. return value;
  10168. }
  10169. function fixupEncoding(value) {
  10170. if (needsEncodingFixup && /[\x80-\xff]/.test(value)) {
  10171. value = textdecode("utf-8", value);
  10172. if (needsEncodingFixup) {
  10173. value = textdecode("iso-8859-1", value);
  10174. }
  10175. }
  10176. return value;
  10177. }
  10178. function rfc2231getparam(contentDisposition) {
  10179. const matches = [];
  10180. let match;
  10181. const iter = toParamRegExp("filename\\*((?!0\\d)\\d+)(\\*?)", "ig");
  10182. while ((match = iter.exec(contentDisposition)) !== null) {
  10183. let [, n, quot, part] = match;
  10184. n = parseInt(n, 10);
  10185. if (n in matches) {
  10186. if (n === 0) {
  10187. break;
  10188. }
  10189. continue;
  10190. }
  10191. matches[n] = [quot, part];
  10192. }
  10193. const parts = [];
  10194. for (let n = 0; n < matches.length; ++n) {
  10195. if (!(n in matches)) {
  10196. break;
  10197. }
  10198. let [quot, part] = matches[n];
  10199. part = rfc2616unquote(part);
  10200. if (quot) {
  10201. part = unescape(part);
  10202. if (n === 0) {
  10203. part = rfc5987decode(part);
  10204. }
  10205. }
  10206. parts.push(part);
  10207. }
  10208. return parts.join("");
  10209. }
  10210. function rfc2616unquote(value) {
  10211. if (value.startsWith('"')) {
  10212. const parts = value.slice(1).split('\\"');
  10213. for (let i = 0; i < parts.length; ++i) {
  10214. const quotindex = parts[i].indexOf('"');
  10215. if (quotindex !== -1) {
  10216. parts[i] = parts[i].slice(0, quotindex);
  10217. parts.length = i + 1;
  10218. }
  10219. parts[i] = parts[i].replace(/\\(.)/g, "$1");
  10220. }
  10221. value = parts.join('"');
  10222. }
  10223. return value;
  10224. }
  10225. function rfc5987decode(extvalue) {
  10226. const encodingend = extvalue.indexOf("'");
  10227. if (encodingend === -1) {
  10228. return extvalue;
  10229. }
  10230. const encoding = extvalue.slice(0, encodingend);
  10231. const langvalue = extvalue.slice(encodingend + 1);
  10232. const value = langvalue.replace(/^[^']*'/, "");
  10233. return textdecode(encoding, value);
  10234. }
  10235. function rfc2047decode(value) {
  10236. if (!value.startsWith("=?") || /[\x00-\x19\x80-\xff]/.test(value)) {
  10237. return value;
  10238. }
  10239. return value.replace(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g, function (_, charset, encoding, text) {
  10240. if (encoding === "q" || encoding === "Q") {
  10241. text = text.replace(/_/g, " ");
  10242. text = text.replace(/=([0-9a-fA-F]{2})/g, function (_, hex) {
  10243. return String.fromCharCode(parseInt(hex, 16));
  10244. });
  10245. return textdecode(charset, text);
  10246. }
  10247. try {
  10248. text = atob(text);
  10249. } catch (e) {}
  10250. return textdecode(charset, text);
  10251. });
  10252. }
  10253. return "";
  10254. }
  10255. /***/ }),
  10256. /* 22 */
  10257. /***/ (function(module, exports, __w_pdfjs_require__) {
  10258. "use strict";
  10259. Object.defineProperty(exports, "__esModule", {
  10260. value: true
  10261. });
  10262. exports.PDFNetworkStream = void 0;
  10263. var _util = __w_pdfjs_require__(1);
  10264. var _network_utils = __w_pdfjs_require__(20);
  10265. ;
  10266. const OK_RESPONSE = 200;
  10267. const PARTIAL_CONTENT_RESPONSE = 206;
  10268. function getArrayBuffer(xhr) {
  10269. const data = xhr.response;
  10270. if (typeof data !== "string") {
  10271. return data;
  10272. }
  10273. const array = (0, _util.stringToBytes)(data);
  10274. return array.buffer;
  10275. }
  10276. class NetworkManager {
  10277. constructor(url, args) {
  10278. this.url = url;
  10279. args = args || {};
  10280. this.isHttp = /^https?:/i.test(url);
  10281. this.httpHeaders = this.isHttp && args.httpHeaders || {};
  10282. this.withCredentials = args.withCredentials || false;
  10283. this.getXhr = args.getXhr || function NetworkManager_getXhr() {
  10284. return new XMLHttpRequest();
  10285. };
  10286. this.currXhrId = 0;
  10287. this.pendingRequests = Object.create(null);
  10288. }
  10289. requestRange(begin, end, listeners) {
  10290. const args = {
  10291. begin,
  10292. end
  10293. };
  10294. for (const prop in listeners) {
  10295. args[prop] = listeners[prop];
  10296. }
  10297. return this.request(args);
  10298. }
  10299. requestFull(listeners) {
  10300. return this.request(listeners);
  10301. }
  10302. request(args) {
  10303. const xhr = this.getXhr();
  10304. const xhrId = this.currXhrId++;
  10305. const pendingRequest = this.pendingRequests[xhrId] = {
  10306. xhr
  10307. };
  10308. xhr.open("GET", this.url);
  10309. xhr.withCredentials = this.withCredentials;
  10310. for (const property in this.httpHeaders) {
  10311. const value = this.httpHeaders[property];
  10312. if (typeof value === "undefined") {
  10313. continue;
  10314. }
  10315. xhr.setRequestHeader(property, value);
  10316. }
  10317. if (this.isHttp && "begin" in args && "end" in args) {
  10318. xhr.setRequestHeader("Range", `bytes=${args.begin}-${args.end - 1}`);
  10319. pendingRequest.expectedStatus = PARTIAL_CONTENT_RESPONSE;
  10320. } else {
  10321. pendingRequest.expectedStatus = OK_RESPONSE;
  10322. }
  10323. xhr.responseType = "arraybuffer";
  10324. if (args.onError) {
  10325. xhr.onerror = function (evt) {
  10326. args.onError(xhr.status);
  10327. };
  10328. }
  10329. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  10330. xhr.onprogress = this.onProgress.bind(this, xhrId);
  10331. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  10332. pendingRequest.onDone = args.onDone;
  10333. pendingRequest.onError = args.onError;
  10334. pendingRequest.onProgress = args.onProgress;
  10335. xhr.send(null);
  10336. return xhrId;
  10337. }
  10338. onProgress(xhrId, evt) {
  10339. const pendingRequest = this.pendingRequests[xhrId];
  10340. if (!pendingRequest) {
  10341. return;
  10342. }
  10343. if (pendingRequest.onProgress) {
  10344. pendingRequest.onProgress(evt);
  10345. }
  10346. }
  10347. onStateChange(xhrId, evt) {
  10348. const pendingRequest = this.pendingRequests[xhrId];
  10349. if (!pendingRequest) {
  10350. return;
  10351. }
  10352. const xhr = pendingRequest.xhr;
  10353. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  10354. pendingRequest.onHeadersReceived();
  10355. delete pendingRequest.onHeadersReceived;
  10356. }
  10357. if (xhr.readyState !== 4) {
  10358. return;
  10359. }
  10360. if (!(xhrId in this.pendingRequests)) {
  10361. return;
  10362. }
  10363. delete this.pendingRequests[xhrId];
  10364. if (xhr.status === 0 && this.isHttp) {
  10365. if (pendingRequest.onError) {
  10366. pendingRequest.onError(xhr.status);
  10367. }
  10368. return;
  10369. }
  10370. const xhrStatus = xhr.status || OK_RESPONSE;
  10371. const ok_response_on_range_request = xhrStatus === OK_RESPONSE && pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  10372. if (!ok_response_on_range_request && xhrStatus !== pendingRequest.expectedStatus) {
  10373. if (pendingRequest.onError) {
  10374. pendingRequest.onError(xhr.status);
  10375. }
  10376. return;
  10377. }
  10378. const chunk = getArrayBuffer(xhr);
  10379. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  10380. const rangeHeader = xhr.getResponseHeader("Content-Range");
  10381. const matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  10382. pendingRequest.onDone({
  10383. begin: parseInt(matches[1], 10),
  10384. chunk
  10385. });
  10386. } else if (chunk) {
  10387. pendingRequest.onDone({
  10388. begin: 0,
  10389. chunk
  10390. });
  10391. } else if (pendingRequest.onError) {
  10392. pendingRequest.onError(xhr.status);
  10393. }
  10394. }
  10395. hasPendingRequests() {
  10396. for (const xhrId in this.pendingRequests) {
  10397. return true;
  10398. }
  10399. return false;
  10400. }
  10401. getRequestXhr(xhrId) {
  10402. return this.pendingRequests[xhrId].xhr;
  10403. }
  10404. isPendingRequest(xhrId) {
  10405. return xhrId in this.pendingRequests;
  10406. }
  10407. abortAllRequests() {
  10408. for (const xhrId in this.pendingRequests) {
  10409. this.abortRequest(xhrId | 0);
  10410. }
  10411. }
  10412. abortRequest(xhrId) {
  10413. const xhr = this.pendingRequests[xhrId].xhr;
  10414. delete this.pendingRequests[xhrId];
  10415. xhr.abort();
  10416. }
  10417. }
  10418. class PDFNetworkStream {
  10419. constructor(source) {
  10420. this._source = source;
  10421. this._manager = new NetworkManager(source.url, {
  10422. httpHeaders: source.httpHeaders,
  10423. withCredentials: source.withCredentials
  10424. });
  10425. this._rangeChunkSize = source.rangeChunkSize;
  10426. this._fullRequestReader = null;
  10427. this._rangeRequestReaders = [];
  10428. }
  10429. _onRangeRequestReaderClosed(reader) {
  10430. const i = this._rangeRequestReaders.indexOf(reader);
  10431. if (i >= 0) {
  10432. this._rangeRequestReaders.splice(i, 1);
  10433. }
  10434. }
  10435. getFullReader() {
  10436. (0, _util.assert)(!this._fullRequestReader);
  10437. this._fullRequestReader = new PDFNetworkStreamFullRequestReader(this._manager, this._source);
  10438. return this._fullRequestReader;
  10439. }
  10440. getRangeReader(begin, end) {
  10441. const reader = new PDFNetworkStreamRangeRequestReader(this._manager, begin, end);
  10442. reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
  10443. this._rangeRequestReaders.push(reader);
  10444. return reader;
  10445. }
  10446. cancelAllRequests(reason) {
  10447. if (this._fullRequestReader) {
  10448. this._fullRequestReader.cancel(reason);
  10449. }
  10450. const readers = this._rangeRequestReaders.slice(0);
  10451. readers.forEach(function (reader) {
  10452. reader.cancel(reason);
  10453. });
  10454. }
  10455. }
  10456. exports.PDFNetworkStream = PDFNetworkStream;
  10457. class PDFNetworkStreamFullRequestReader {
  10458. constructor(manager, source) {
  10459. this._manager = manager;
  10460. const args = {
  10461. onHeadersReceived: this._onHeadersReceived.bind(this),
  10462. onDone: this._onDone.bind(this),
  10463. onError: this._onError.bind(this),
  10464. onProgress: this._onProgress.bind(this)
  10465. };
  10466. this._url = source.url;
  10467. this._fullRequestId = manager.requestFull(args);
  10468. this._headersReceivedCapability = (0, _util.createPromiseCapability)();
  10469. this._disableRange = source.disableRange || false;
  10470. this._contentLength = source.length;
  10471. this._rangeChunkSize = source.rangeChunkSize;
  10472. if (!this._rangeChunkSize && !this._disableRange) {
  10473. this._disableRange = true;
  10474. }
  10475. this._isStreamingSupported = false;
  10476. this._isRangeSupported = false;
  10477. this._cachedChunks = [];
  10478. this._requests = [];
  10479. this._done = false;
  10480. this._storedError = undefined;
  10481. this._filename = null;
  10482. this.onProgress = null;
  10483. }
  10484. _onHeadersReceived() {
  10485. const fullRequestXhrId = this._fullRequestId;
  10486. const fullRequestXhr = this._manager.getRequestXhr(fullRequestXhrId);
  10487. const getResponseHeader = name => {
  10488. return fullRequestXhr.getResponseHeader(name);
  10489. };
  10490. const {
  10491. allowRangeRequests,
  10492. suggestedLength
  10493. } = (0, _network_utils.validateRangeRequestCapabilities)({
  10494. getResponseHeader,
  10495. isHttp: this._manager.isHttp,
  10496. rangeChunkSize: this._rangeChunkSize,
  10497. disableRange: this._disableRange
  10498. });
  10499. if (allowRangeRequests) {
  10500. this._isRangeSupported = true;
  10501. }
  10502. this._contentLength = suggestedLength || this._contentLength;
  10503. this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
  10504. if (this._isRangeSupported) {
  10505. this._manager.abortRequest(fullRequestXhrId);
  10506. }
  10507. this._headersReceivedCapability.resolve();
  10508. }
  10509. _onDone(args) {
  10510. if (args) {
  10511. if (this._requests.length > 0) {
  10512. const requestCapability = this._requests.shift();
  10513. requestCapability.resolve({
  10514. value: args.chunk,
  10515. done: false
  10516. });
  10517. } else {
  10518. this._cachedChunks.push(args.chunk);
  10519. }
  10520. }
  10521. this._done = true;
  10522. if (this._cachedChunks.length > 0) {
  10523. return;
  10524. }
  10525. this._requests.forEach(function (requestCapability) {
  10526. requestCapability.resolve({
  10527. value: undefined,
  10528. done: true
  10529. });
  10530. });
  10531. this._requests = [];
  10532. }
  10533. _onError(status) {
  10534. const url = this._url;
  10535. const exception = (0, _network_utils.createResponseStatusError)(status, url);
  10536. this._storedError = exception;
  10537. this._headersReceivedCapability.reject(exception);
  10538. this._requests.forEach(function (requestCapability) {
  10539. requestCapability.reject(exception);
  10540. });
  10541. this._requests = [];
  10542. this._cachedChunks = [];
  10543. }
  10544. _onProgress(data) {
  10545. if (this.onProgress) {
  10546. this.onProgress({
  10547. loaded: data.loaded,
  10548. total: data.lengthComputable ? data.total : this._contentLength
  10549. });
  10550. }
  10551. }
  10552. get filename() {
  10553. return this._filename;
  10554. }
  10555. get isRangeSupported() {
  10556. return this._isRangeSupported;
  10557. }
  10558. get isStreamingSupported() {
  10559. return this._isStreamingSupported;
  10560. }
  10561. get contentLength() {
  10562. return this._contentLength;
  10563. }
  10564. get headersReady() {
  10565. return this._headersReceivedCapability.promise;
  10566. }
  10567. async read() {
  10568. if (this._storedError) {
  10569. throw this._storedError;
  10570. }
  10571. if (this._cachedChunks.length > 0) {
  10572. const chunk = this._cachedChunks.shift();
  10573. return {
  10574. value: chunk,
  10575. done: false
  10576. };
  10577. }
  10578. if (this._done) {
  10579. return {
  10580. value: undefined,
  10581. done: true
  10582. };
  10583. }
  10584. const requestCapability = (0, _util.createPromiseCapability)();
  10585. this._requests.push(requestCapability);
  10586. return requestCapability.promise;
  10587. }
  10588. cancel(reason) {
  10589. this._done = true;
  10590. this._headersReceivedCapability.reject(reason);
  10591. this._requests.forEach(function (requestCapability) {
  10592. requestCapability.resolve({
  10593. value: undefined,
  10594. done: true
  10595. });
  10596. });
  10597. this._requests = [];
  10598. if (this._manager.isPendingRequest(this._fullRequestId)) {
  10599. this._manager.abortRequest(this._fullRequestId);
  10600. }
  10601. this._fullRequestReader = null;
  10602. }
  10603. }
  10604. class PDFNetworkStreamRangeRequestReader {
  10605. constructor(manager, begin, end) {
  10606. this._manager = manager;
  10607. const args = {
  10608. onDone: this._onDone.bind(this),
  10609. onProgress: this._onProgress.bind(this)
  10610. };
  10611. this._requestId = manager.requestRange(begin, end, args);
  10612. this._requests = [];
  10613. this._queuedChunk = null;
  10614. this._done = false;
  10615. this.onProgress = null;
  10616. this.onClosed = null;
  10617. }
  10618. _close() {
  10619. if (this.onClosed) {
  10620. this.onClosed(this);
  10621. }
  10622. }
  10623. _onDone(data) {
  10624. const chunk = data.chunk;
  10625. if (this._requests.length > 0) {
  10626. const requestCapability = this._requests.shift();
  10627. requestCapability.resolve({
  10628. value: chunk,
  10629. done: false
  10630. });
  10631. } else {
  10632. this._queuedChunk = chunk;
  10633. }
  10634. this._done = true;
  10635. this._requests.forEach(function (requestCapability) {
  10636. requestCapability.resolve({
  10637. value: undefined,
  10638. done: true
  10639. });
  10640. });
  10641. this._requests = [];
  10642. this._close();
  10643. }
  10644. _onProgress(evt) {
  10645. if (!this.isStreamingSupported && this.onProgress) {
  10646. this.onProgress({
  10647. loaded: evt.loaded
  10648. });
  10649. }
  10650. }
  10651. get isStreamingSupported() {
  10652. return false;
  10653. }
  10654. async read() {
  10655. if (this._queuedChunk !== null) {
  10656. const chunk = this._queuedChunk;
  10657. this._queuedChunk = null;
  10658. return {
  10659. value: chunk,
  10660. done: false
  10661. };
  10662. }
  10663. if (this._done) {
  10664. return {
  10665. value: undefined,
  10666. done: true
  10667. };
  10668. }
  10669. const requestCapability = (0, _util.createPromiseCapability)();
  10670. this._requests.push(requestCapability);
  10671. return requestCapability.promise;
  10672. }
  10673. cancel(reason) {
  10674. this._done = true;
  10675. this._requests.forEach(function (requestCapability) {
  10676. requestCapability.resolve({
  10677. value: undefined,
  10678. done: true
  10679. });
  10680. });
  10681. this._requests = [];
  10682. if (this._manager.isPendingRequest(this._requestId)) {
  10683. this._manager.abortRequest(this._requestId);
  10684. }
  10685. this._close();
  10686. }
  10687. }
  10688. /***/ }),
  10689. /* 23 */
  10690. /***/ (function(module, exports, __w_pdfjs_require__) {
  10691. "use strict";
  10692. Object.defineProperty(exports, "__esModule", {
  10693. value: true
  10694. });
  10695. exports.PDFFetchStream = void 0;
  10696. var _util = __w_pdfjs_require__(1);
  10697. var _network_utils = __w_pdfjs_require__(20);
  10698. function createFetchOptions(headers, withCredentials, abortController) {
  10699. return {
  10700. method: "GET",
  10701. headers,
  10702. signal: abortController && abortController.signal,
  10703. mode: "cors",
  10704. credentials: withCredentials ? "include" : "same-origin",
  10705. redirect: "follow"
  10706. };
  10707. }
  10708. function createHeaders(httpHeaders) {
  10709. const headers = new Headers();
  10710. for (const property in httpHeaders) {
  10711. const value = httpHeaders[property];
  10712. if (typeof value === "undefined") {
  10713. continue;
  10714. }
  10715. headers.append(property, value);
  10716. }
  10717. return headers;
  10718. }
  10719. class PDFFetchStream {
  10720. constructor(source) {
  10721. this.source = source;
  10722. this.isHttp = /^https?:/i.test(source.url);
  10723. this.httpHeaders = this.isHttp && source.httpHeaders || {};
  10724. this._fullRequestReader = null;
  10725. this._rangeRequestReaders = [];
  10726. }
  10727. get _progressiveDataLength() {
  10728. return this._fullRequestReader ? this._fullRequestReader._loaded : 0;
  10729. }
  10730. getFullReader() {
  10731. (0, _util.assert)(!this._fullRequestReader);
  10732. this._fullRequestReader = new PDFFetchStreamReader(this);
  10733. return this._fullRequestReader;
  10734. }
  10735. getRangeReader(begin, end) {
  10736. if (end <= this._progressiveDataLength) {
  10737. return null;
  10738. }
  10739. const reader = new PDFFetchStreamRangeReader(this, begin, end);
  10740. this._rangeRequestReaders.push(reader);
  10741. return reader;
  10742. }
  10743. cancelAllRequests(reason) {
  10744. if (this._fullRequestReader) {
  10745. this._fullRequestReader.cancel(reason);
  10746. }
  10747. const readers = this._rangeRequestReaders.slice(0);
  10748. readers.forEach(function (reader) {
  10749. reader.cancel(reason);
  10750. });
  10751. }
  10752. }
  10753. exports.PDFFetchStream = PDFFetchStream;
  10754. class PDFFetchStreamReader {
  10755. constructor(stream) {
  10756. this._stream = stream;
  10757. this._reader = null;
  10758. this._loaded = 0;
  10759. this._filename = null;
  10760. const source = stream.source;
  10761. this._withCredentials = source.withCredentials || false;
  10762. this._contentLength = source.length;
  10763. this._headersCapability = (0, _util.createPromiseCapability)();
  10764. this._disableRange = source.disableRange || false;
  10765. this._rangeChunkSize = source.rangeChunkSize;
  10766. if (!this._rangeChunkSize && !this._disableRange) {
  10767. this._disableRange = true;
  10768. }
  10769. if (typeof AbortController !== "undefined") {
  10770. this._abortController = new AbortController();
  10771. }
  10772. this._isStreamingSupported = !source.disableStream;
  10773. this._isRangeSupported = !source.disableRange;
  10774. this._headers = createHeaders(this._stream.httpHeaders);
  10775. const url = source.url;
  10776. fetch(url, createFetchOptions(this._headers, this._withCredentials, this._abortController)).then(response => {
  10777. if (!(0, _network_utils.validateResponseStatus)(response.status)) {
  10778. throw (0, _network_utils.createResponseStatusError)(response.status, url);
  10779. }
  10780. this._reader = response.body.getReader();
  10781. this._headersCapability.resolve();
  10782. const getResponseHeader = name => {
  10783. return response.headers.get(name);
  10784. };
  10785. const {
  10786. allowRangeRequests,
  10787. suggestedLength
  10788. } = (0, _network_utils.validateRangeRequestCapabilities)({
  10789. getResponseHeader,
  10790. isHttp: this._stream.isHttp,
  10791. rangeChunkSize: this._rangeChunkSize,
  10792. disableRange: this._disableRange
  10793. });
  10794. this._isRangeSupported = allowRangeRequests;
  10795. this._contentLength = suggestedLength || this._contentLength;
  10796. this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader);
  10797. if (!this._isStreamingSupported && this._isRangeSupported) {
  10798. this.cancel(new _util.AbortException("Streaming is disabled."));
  10799. }
  10800. }).catch(this._headersCapability.reject);
  10801. this.onProgress = null;
  10802. }
  10803. get headersReady() {
  10804. return this._headersCapability.promise;
  10805. }
  10806. get filename() {
  10807. return this._filename;
  10808. }
  10809. get contentLength() {
  10810. return this._contentLength;
  10811. }
  10812. get isRangeSupported() {
  10813. return this._isRangeSupported;
  10814. }
  10815. get isStreamingSupported() {
  10816. return this._isStreamingSupported;
  10817. }
  10818. async read() {
  10819. await this._headersCapability.promise;
  10820. const {
  10821. value,
  10822. done
  10823. } = await this._reader.read();
  10824. if (done) {
  10825. return {
  10826. value,
  10827. done
  10828. };
  10829. }
  10830. this._loaded += value.byteLength;
  10831. if (this.onProgress) {
  10832. this.onProgress({
  10833. loaded: this._loaded,
  10834. total: this._contentLength
  10835. });
  10836. }
  10837. const buffer = new Uint8Array(value).buffer;
  10838. return {
  10839. value: buffer,
  10840. done: false
  10841. };
  10842. }
  10843. cancel(reason) {
  10844. if (this._reader) {
  10845. this._reader.cancel(reason);
  10846. }
  10847. if (this._abortController) {
  10848. this._abortController.abort();
  10849. }
  10850. }
  10851. }
  10852. class PDFFetchStreamRangeReader {
  10853. constructor(stream, begin, end) {
  10854. this._stream = stream;
  10855. this._reader = null;
  10856. this._loaded = 0;
  10857. const source = stream.source;
  10858. this._withCredentials = source.withCredentials || false;
  10859. this._readCapability = (0, _util.createPromiseCapability)();
  10860. this._isStreamingSupported = !source.disableStream;
  10861. if (typeof AbortController !== "undefined") {
  10862. this._abortController = new AbortController();
  10863. }
  10864. this._headers = createHeaders(this._stream.httpHeaders);
  10865. this._headers.append("Range", `bytes=${begin}-${end - 1}`);
  10866. const url = source.url;
  10867. fetch(url, createFetchOptions(this._headers, this._withCredentials, this._abortController)).then(response => {
  10868. if (!(0, _network_utils.validateResponseStatus)(response.status)) {
  10869. throw (0, _network_utils.createResponseStatusError)(response.status, url);
  10870. }
  10871. this._readCapability.resolve();
  10872. this._reader = response.body.getReader();
  10873. });
  10874. this.onProgress = null;
  10875. }
  10876. get isStreamingSupported() {
  10877. return this._isStreamingSupported;
  10878. }
  10879. async read() {
  10880. await this._readCapability.promise;
  10881. const {
  10882. value,
  10883. done
  10884. } = await this._reader.read();
  10885. if (done) {
  10886. return {
  10887. value,
  10888. done
  10889. };
  10890. }
  10891. this._loaded += value.byteLength;
  10892. if (this.onProgress) {
  10893. this.onProgress({
  10894. loaded: this._loaded
  10895. });
  10896. }
  10897. const buffer = new Uint8Array(value).buffer;
  10898. return {
  10899. value: buffer,
  10900. done: false
  10901. };
  10902. }
  10903. cancel(reason) {
  10904. if (this._reader) {
  10905. this._reader.cancel(reason);
  10906. }
  10907. if (this._abortController) {
  10908. this._abortController.abort();
  10909. }
  10910. }
  10911. }
  10912. /***/ })
  10913. /******/ ]);
  10914. });
  10915. //# sourceMappingURL=pdf.js.map