pdf.combined.js 2.0 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593385943859538596385973859838599386003860138602386033860438605386063860738608386093861038611386123861338614386153861638617386183861938620386213862238623386243862538626386273862838629386303863138632386333863438635386363863738638386393864038641386423864338644386453864638647386483864938650386513865238653386543865538656386573865838659386603866138662386633866438665386663866738668386693867038671386723867338674386753867638677386783867938680386813868238683386843868538686386873868838689386903869138692386933869438695386963869738698386993870038701387023870338704387053870638707387083870938710387113871238713387143871538716387173871838719387203872138722387233872438725387263872738728387293873038731387323873338734387353873638737387383873938740387413874238743387443874538746387473874838749387503875138752387533875438755387563875738758387593876038761387623876338764387653876638767387683876938770387713877238773387743877538776387773877838779387803878138782387833878438785387863878738788387893879038791387923879338794387953879638797387983879938800388013880238803388043880538806388073880838809388103881138812388133881438815388163881738818388193882038821388223882338824388253882638827388283882938830388313883238833388343883538836388373883838839388403884138842388433884438845388463884738848388493885038851388523885338854388553885638857388583885938860388613886238863388643886538866388673886838869388703887138872388733887438875388763887738878388793888038881388823888338884388853888638887388883888938890388913889238893388943889538896388973889838899389003890138902389033890438905389063890738908389093891038911389123891338914389153891638917389183891938920389213892238923389243892538926389273892838929389303893138932389333893438935389363893738938389393894038941389423894338944389453894638947389483894938950389513895238953389543895538956389573895838959389603896138962389633896438965389663896738968389693897038971389723897338974389753897638977389783897938980389813898238983389843898538986389873898838989389903899138992389933899438995389963899738998389993900039001390023900339004390053900639007390083900939010390113901239013390143901539016390173901839019390203902139022390233902439025390263902739028390293903039031390323903339034390353903639037390383903939040390413904239043390443904539046390473904839049390503905139052390533905439055390563905739058390593906039061390623906339064390653906639067390683906939070390713907239073390743907539076390773907839079390803908139082390833908439085390863908739088390893909039091390923909339094390953909639097390983909939100391013910239103391043910539106391073910839109391103911139112391133911439115391163911739118391193912039121391223912339124391253912639127391283912939130391313913239133391343913539136391373913839139391403914139142391433914439145391463914739148391493915039151391523915339154391553915639157391583915939160391613916239163391643916539166391673916839169391703917139172391733917439175391763917739178391793918039181391823918339184391853918639187391883918939190391913919239193391943919539196391973919839199392003920139202392033920439205392063920739208392093921039211392123921339214392153921639217392183921939220392213922239223392243922539226392273922839229392303923139232392333923439235392363923739238392393924039241392423924339244392453924639247392483924939250392513925239253392543925539256392573925839259392603926139262392633926439265392663926739268392693927039271392723927339274392753927639277392783927939280392813928239283392843928539286392873928839289392903929139292392933929439295392963929739298392993930039301393023930339304393053930639307393083930939310393113931239313393143931539316393173931839319393203932139322393233932439325393263932739328393293933039331393323933339334393353933639337393383933939340393413934239343393443934539346393473934839349393503935139352393533935439355393563935739358393593936039361393623936339364393653936639367393683936939370393713937239373393743937539376393773937839379393803938139382393833938439385393863938739388393893939039391393923939339394393953939639397393983939939400394013940239403394043940539406394073940839409394103941139412394133941439415394163941739418394193942039421394223942339424394253942639427394283942939430394313943239433394343943539436394373943839439394403944139442394433944439445394463944739448394493945039451394523945339454394553945639457394583945939460394613946239463394643946539466394673946839469394703947139472394733947439475394763947739478394793948039481394823948339484394853948639487394883948939490394913949239493394943949539496394973949839499395003950139502395033950439505395063950739508395093951039511395123951339514395153951639517395183951939520395213952239523395243952539526395273952839529395303953139532395333953439535395363953739538395393954039541395423954339544395453954639547395483954939550395513955239553395543955539556395573955839559395603956139562395633956439565395663956739568395693957039571395723957339574395753957639577395783957939580395813958239583395843958539586395873958839589395903959139592395933959439595395963959739598395993960039601396023960339604396053960639607396083960939610396113961239613396143961539616396173961839619396203962139622396233962439625396263962739628396293963039631396323963339634396353963639637396383963939640396413964239643396443964539646396473964839649396503965139652396533965439655396563965739658396593966039661396623966339664396653966639667396683966939670396713967239673396743967539676396773967839679396803968139682396833968439685396863968739688396893969039691396923969339694396953969639697396983969939700397013970239703397043970539706397073970839709397103971139712397133971439715397163971739718397193972039721397223972339724397253972639727397283972939730397313973239733397343973539736397373973839739397403974139742397433974439745397463974739748397493975039751397523975339754397553975639757397583975939760397613976239763397643976539766397673976839769397703977139772397733977439775397763977739778397793978039781397823978339784397853978639787397883978939790397913979239793397943979539796397973979839799398003980139802398033980439805398063980739808398093981039811398123981339814398153981639817398183981939820398213982239823398243982539826398273982839829398303983139832398333983439835398363983739838398393984039841398423984339844398453984639847398483984939850398513985239853398543985539856398573985839859398603986139862398633986439865398663986739868398693987039871398723987339874398753987639877398783987939880398813988239883398843988539886398873988839889398903989139892398933989439895398963989739898398993990039901399023990339904399053990639907399083990939910399113991239913399143991539916399173991839919399203992139922399233992439925399263992739928399293993039931399323993339934399353993639937399383993939940399413994239943399443994539946399473994839949399503995139952399533995439955399563995739958399593996039961399623996339964399653996639967399683996939970399713997239973399743997539976399773997839979399803998139982399833998439985399863998739988399893999039991399923999339994399953999639997399983999940000400014000240003400044000540006400074000840009400104001140012400134001440015400164001740018400194002040021400224002340024400254002640027400284002940030400314003240033400344003540036400374003840039400404004140042400434004440045400464004740048400494005040051400524005340054400554005640057400584005940060400614006240063400644006540066400674006840069400704007140072400734007440075400764007740078400794008040081400824008340084400854008640087400884008940090400914009240093400944009540096400974009840099401004010140102401034010440105401064010740108401094011040111401124011340114401154011640117401184011940120401214012240123401244012540126401274012840129401304013140132401334013440135401364013740138401394014040141401424014340144401454014640147401484014940150401514015240153401544015540156401574015840159401604016140162401634016440165401664016740168401694017040171401724017340174401754017640177401784017940180401814018240183401844018540186401874018840189401904019140192401934019440195401964019740198401994020040201402024020340204402054020640207402084020940210402114021240213402144021540216402174021840219402204022140222402234022440225402264022740228402294023040231402324023340234402354023640237402384023940240402414024240243402444024540246402474024840249402504025140252402534025440255402564025740258402594026040261402624026340264402654026640267402684026940270402714027240273402744027540276402774027840279402804028140282402834028440285402864028740288402894029040291402924029340294402954029640297402984029940300403014030240303403044030540306403074030840309403104031140312403134031440315403164031740318403194032040321403224032340324403254032640327403284032940330403314033240333403344033540336403374033840339403404034140342403434034440345403464034740348403494035040351403524035340354403554035640357403584035940360403614036240363403644036540366403674036840369403704037140372403734037440375403764037740378403794038040381403824038340384403854038640387403884038940390403914039240393403944039540396403974039840399404004040140402404034040440405404064040740408404094041040411404124041340414404154041640417404184041940420404214042240423404244042540426404274042840429404304043140432404334043440435404364043740438404394044040441404424044340444404454044640447404484044940450404514045240453404544045540456404574045840459404604046140462404634046440465404664046740468404694047040471404724047340474404754047640477404784047940480404814048240483404844048540486404874048840489404904049140492404934049440495404964049740498404994050040501405024050340504405054050640507405084050940510405114051240513405144051540516405174051840519405204052140522405234052440525405264052740528405294053040531405324053340534405354053640537405384053940540405414054240543405444054540546405474054840549405504055140552405534055440555405564055740558405594056040561405624056340564405654056640567405684056940570405714057240573405744057540576405774057840579405804058140582405834058440585405864058740588405894059040591405924059340594405954059640597405984059940600406014060240603406044060540606406074060840609406104061140612406134061440615406164061740618406194062040621406224062340624406254062640627406284062940630406314063240633406344063540636406374063840639406404064140642406434064440645406464064740648406494065040651406524065340654406554065640657406584065940660406614066240663406644066540666406674066840669406704067140672406734067440675406764067740678406794068040681406824068340684406854068640687406884068940690406914069240693406944069540696406974069840699407004070140702407034070440705407064070740708407094071040711407124071340714407154071640717407184071940720407214072240723407244072540726407274072840729407304073140732407334073440735407364073740738407394074040741407424074340744407454074640747407484074940750407514075240753407544075540756407574075840759407604076140762407634076440765407664076740768407694077040771407724077340774407754077640777407784077940780407814078240783407844078540786407874078840789407904079140792407934079440795407964079740798407994080040801408024080340804408054080640807408084080940810408114081240813408144081540816408174081840819408204082140822408234082440825408264082740828408294083040831408324083340834408354083640837408384083940840408414084240843408444084540846408474084840849408504085140852408534085440855408564085740858408594086040861408624086340864408654086640867408684086940870408714087240873408744087540876408774087840879408804088140882408834088440885408864088740888408894089040891408924089340894408954089640897408984089940900409014090240903409044090540906409074090840909409104091140912409134091440915409164091740918409194092040921409224092340924409254092640927409284092940930409314093240933409344093540936409374093840939409404094140942409434094440945409464094740948409494095040951409524095340954409554095640957409584095940960409614096240963409644096540966409674096840969409704097140972409734097440975409764097740978409794098040981409824098340984409854098640987409884098940990409914099240993409944099540996409974099840999410004100141002410034100441005410064100741008410094101041011410124101341014410154101641017410184101941020410214102241023410244102541026410274102841029410304103141032410334103441035410364103741038410394104041041410424104341044410454104641047410484104941050410514105241053410544105541056410574105841059410604106141062410634106441065410664106741068410694107041071410724107341074410754107641077410784107941080410814108241083410844108541086410874108841089410904109141092410934109441095410964109741098410994110041101411024110341104411054110641107411084110941110411114111241113411144111541116411174111841119411204112141122411234112441125411264112741128411294113041131411324113341134411354113641137411384113941140411414114241143411444114541146411474114841149411504115141152411534115441155411564115741158411594116041161411624116341164411654116641167411684116941170411714117241173411744117541176411774117841179411804118141182411834118441185411864118741188411894119041191411924119341194411954119641197411984119941200412014120241203412044120541206412074120841209412104121141212412134121441215412164121741218412194122041221412224122341224412254122641227412284122941230412314123241233412344123541236412374123841239412404124141242412434124441245412464124741248412494125041251412524125341254412554125641257412584125941260412614126241263412644126541266412674126841269412704127141272412734127441275412764127741278412794128041281412824128341284412854128641287412884128941290412914129241293412944129541296412974129841299413004130141302413034130441305413064130741308413094131041311413124131341314413154131641317413184131941320413214132241323413244132541326413274132841329413304133141332413334133441335413364133741338413394134041341413424134341344413454134641347413484134941350413514135241353413544135541356413574135841359413604136141362413634136441365413664136741368413694137041371413724137341374413754137641377413784137941380413814138241383413844138541386413874138841389413904139141392413934139441395413964139741398413994140041401414024140341404414054140641407414084140941410414114141241413414144141541416414174141841419414204142141422414234142441425414264142741428414294143041431414324143341434414354143641437414384143941440414414144241443414444144541446414474144841449414504145141452414534145441455414564145741458414594146041461414624146341464414654146641467414684146941470414714147241473414744147541476414774147841479414804148141482414834148441485414864148741488414894149041491414924149341494414954149641497414984149941500415014150241503415044150541506415074150841509415104151141512415134151441515415164151741518415194152041521415224152341524415254152641527415284152941530415314153241533415344153541536415374153841539415404154141542415434154441545415464154741548415494155041551415524155341554415554155641557415584155941560415614156241563415644156541566415674156841569415704157141572415734157441575415764157741578415794158041581415824158341584415854158641587415884158941590415914159241593415944159541596415974159841599416004160141602416034160441605416064160741608416094161041611416124161341614416154161641617416184161941620416214162241623416244162541626416274162841629416304163141632416334163441635416364163741638416394164041641416424164341644416454164641647416484164941650416514165241653416544165541656416574165841659416604166141662416634166441665416664166741668416694167041671416724167341674416754167641677416784167941680416814168241683416844168541686416874168841689416904169141692416934169441695416964169741698416994170041701417024170341704417054170641707417084170941710417114171241713417144171541716417174171841719417204172141722417234172441725417264172741728417294173041731417324173341734417354173641737417384173941740417414174241743417444174541746417474174841749417504175141752417534175441755417564175741758417594176041761417624176341764417654176641767417684176941770417714177241773417744177541776417774177841779417804178141782417834178441785417864178741788417894179041791417924179341794417954179641797417984179941800418014180241803418044180541806418074180841809418104181141812418134181441815418164181741818418194182041821418224182341824418254182641827418284182941830418314183241833418344183541836418374183841839418404184141842418434184441845418464184741848418494185041851418524185341854418554185641857418584185941860418614186241863418644186541866418674186841869418704187141872418734187441875418764187741878418794188041881418824188341884418854188641887418884188941890418914189241893418944189541896418974189841899419004190141902419034190441905419064190741908419094191041911419124191341914419154191641917419184191941920419214192241923419244192541926419274192841929419304193141932419334193441935419364193741938419394194041941419424194341944419454194641947419484194941950419514195241953419544195541956419574195841959419604196141962419634196441965419664196741968419694197041971419724197341974419754197641977419784197941980419814198241983419844198541986419874198841989419904199141992419934199441995419964199741998419994200042001420024200342004420054200642007420084200942010420114201242013420144201542016420174201842019420204202142022420234202442025420264202742028420294203042031420324203342034420354203642037420384203942040420414204242043420444204542046420474204842049420504205142052420534205442055420564205742058420594206042061420624206342064420654206642067420684206942070420714207242073420744207542076420774207842079420804208142082420834208442085420864208742088420894209042091420924209342094420954209642097420984209942100421014210242103421044210542106421074210842109421104211142112421134211442115421164211742118421194212042121421224212342124421254212642127421284212942130421314213242133421344213542136421374213842139421404214142142421434214442145421464214742148421494215042151421524215342154421554215642157421584215942160421614216242163421644216542166421674216842169421704217142172421734217442175421764217742178421794218042181421824218342184421854218642187421884218942190421914219242193421944219542196421974219842199422004220142202422034220442205422064220742208422094221042211422124221342214422154221642217422184221942220422214222242223422244222542226422274222842229422304223142232422334223442235422364223742238422394224042241422424224342244422454224642247422484224942250422514225242253422544225542256422574225842259422604226142262422634226442265422664226742268422694227042271422724227342274422754227642277422784227942280422814228242283422844228542286422874228842289422904229142292422934229442295422964229742298422994230042301423024230342304423054230642307423084230942310423114231242313423144231542316423174231842319423204232142322423234232442325423264232742328423294233042331423324233342334423354233642337423384233942340423414234242343423444234542346423474234842349423504235142352423534235442355423564235742358423594236042361423624236342364423654236642367423684236942370423714237242373423744237542376423774237842379423804238142382423834238442385423864238742388423894239042391423924239342394423954239642397423984239942400424014240242403424044240542406424074240842409424104241142412424134241442415424164241742418424194242042421424224242342424424254242642427424284242942430424314243242433424344243542436424374243842439424404244142442424434244442445424464244742448424494245042451424524245342454424554245642457424584245942460424614246242463424644246542466424674246842469424704247142472424734247442475424764247742478424794248042481424824248342484424854248642487424884248942490424914249242493424944249542496424974249842499425004250142502425034250442505425064250742508425094251042511425124251342514425154251642517425184251942520425214252242523425244252542526425274252842529425304253142532425334253442535425364253742538425394254042541425424254342544425454254642547425484254942550425514255242553425544255542556425574255842559425604256142562425634256442565425664256742568425694257042571425724257342574425754257642577425784257942580425814258242583425844258542586425874258842589425904259142592425934259442595425964259742598425994260042601426024260342604426054260642607426084260942610426114261242613426144261542616426174261842619426204262142622426234262442625426264262742628426294263042631426324263342634426354263642637426384263942640426414264242643426444264542646426474264842649426504265142652426534265442655426564265742658426594266042661426624266342664426654266642667426684266942670426714267242673426744267542676426774267842679426804268142682426834268442685426864268742688426894269042691426924269342694426954269642697426984269942700427014270242703427044270542706427074270842709427104271142712427134271442715427164271742718427194272042721427224272342724427254272642727427284272942730427314273242733427344273542736427374273842739427404274142742427434274442745427464274742748427494275042751427524275342754427554275642757427584275942760427614276242763427644276542766427674276842769427704277142772427734277442775427764277742778427794278042781427824278342784427854278642787427884278942790427914279242793427944279542796427974279842799428004280142802428034280442805428064280742808428094281042811428124281342814428154281642817428184281942820428214282242823428244282542826428274282842829428304283142832428334283442835428364283742838428394284042841428424284342844428454284642847428484284942850428514285242853428544285542856428574285842859428604286142862428634286442865428664286742868428694287042871428724287342874428754287642877428784287942880428814288242883428844288542886428874288842889428904289142892428934289442895428964289742898428994290042901429024290342904429054290642907429084290942910429114291242913429144291542916429174291842919429204292142922429234292442925429264292742928429294293042931429324293342934429354293642937429384293942940429414294242943429444294542946429474294842949429504295142952429534295442955429564295742958429594296042961429624296342964429654296642967429684296942970429714297242973429744297542976429774297842979429804298142982429834298442985429864298742988429894299042991429924299342994429954299642997429984299943000430014300243003430044300543006430074300843009430104301143012430134301443015430164301743018430194302043021430224302343024430254302643027430284302943030430314303243033430344303543036430374303843039430404304143042430434304443045430464304743048430494305043051430524305343054430554305643057430584305943060430614306243063430644306543066430674306843069430704307143072430734307443075430764307743078430794308043081430824308343084430854308643087430884308943090430914309243093430944309543096430974309843099431004310143102431034310443105431064310743108431094311043111431124311343114431154311643117431184311943120431214312243123431244312543126431274312843129431304313143132431334313443135431364313743138431394314043141431424314343144431454314643147431484314943150431514315243153431544315543156431574315843159431604316143162431634316443165431664316743168431694317043171431724317343174431754317643177431784317943180431814318243183431844318543186431874318843189431904319143192431934319443195431964319743198431994320043201432024320343204432054320643207432084320943210432114321243213432144321543216432174321843219432204322143222432234322443225432264322743228432294323043231432324323343234432354323643237432384323943240432414324243243432444324543246432474324843249432504325143252432534325443255432564325743258432594326043261432624326343264432654326643267432684326943270432714327243273432744327543276432774327843279432804328143282432834328443285432864328743288432894329043291432924329343294432954329643297432984329943300433014330243303433044330543306433074330843309433104331143312433134331443315433164331743318433194332043321433224332343324433254332643327433284332943330433314333243333433344333543336433374333843339433404334143342433434334443345433464334743348433494335043351433524335343354433554335643357433584335943360433614336243363433644336543366433674336843369433704337143372433734337443375433764337743378433794338043381433824338343384433854338643387433884338943390433914339243393433944339543396433974339843399434004340143402434034340443405434064340743408434094341043411434124341343414434154341643417434184341943420434214342243423434244342543426434274342843429434304343143432434334343443435434364343743438434394344043441434424344343444434454344643447434484344943450434514345243453434544345543456434574345843459434604346143462434634346443465434664346743468434694347043471434724347343474434754347643477434784347943480434814348243483434844348543486434874348843489434904349143492434934349443495434964349743498434994350043501435024350343504435054350643507435084350943510435114351243513435144351543516435174351843519435204352143522435234352443525435264352743528435294353043531435324353343534435354353643537435384353943540435414354243543435444354543546435474354843549435504355143552435534355443555435564355743558435594356043561435624356343564435654356643567435684356943570435714357243573435744357543576435774357843579435804358143582435834358443585435864358743588435894359043591435924359343594435954359643597435984359943600436014360243603436044360543606436074360843609436104361143612436134361443615436164361743618436194362043621436224362343624436254362643627436284362943630436314363243633436344363543636436374363843639436404364143642436434364443645436464364743648436494365043651436524365343654436554365643657436584365943660436614366243663436644366543666436674366843669436704367143672436734367443675436764367743678436794368043681436824368343684436854368643687436884368943690436914369243693436944369543696436974369843699437004370143702437034370443705437064370743708437094371043711437124371343714437154371643717437184371943720437214372243723437244372543726437274372843729437304373143732437334373443735437364373743738437394374043741437424374343744437454374643747437484374943750437514375243753437544375543756437574375843759437604376143762437634376443765437664376743768437694377043771437724377343774437754377643777437784377943780437814378243783437844378543786437874378843789437904379143792437934379443795437964379743798437994380043801438024380343804438054380643807438084380943810438114381243813438144381543816438174381843819438204382143822438234382443825438264382743828438294383043831438324383343834438354383643837438384383943840438414384243843438444384543846438474384843849438504385143852438534385443855438564385743858438594386043861438624386343864438654386643867438684386943870438714387243873438744387543876438774387843879438804388143882438834388443885438864388743888438894389043891438924389343894438954389643897438984389943900439014390243903439044390543906439074390843909439104391143912439134391443915439164391743918439194392043921439224392343924439254392643927439284392943930439314393243933439344393543936439374393843939439404394143942439434394443945439464394743948439494395043951439524395343954439554395643957439584395943960439614396243963439644396543966439674396843969439704397143972439734397443975439764397743978439794398043981439824398343984439854398643987439884398943990439914399243993439944399543996439974399843999440004400144002440034400444005440064400744008440094401044011440124401344014440154401644017440184401944020440214402244023440244402544026440274402844029440304403144032440334403444035440364403744038440394404044041440424404344044440454404644047440484404944050440514405244053440544405544056440574405844059440604406144062440634406444065440664406744068440694407044071440724407344074440754407644077440784407944080440814408244083440844408544086440874408844089440904409144092440934409444095440964409744098440994410044101441024410344104441054410644107441084410944110441114411244113441144411544116441174411844119441204412144122441234412444125441264412744128441294413044131441324413344134441354413644137441384413944140441414414244143441444414544146441474414844149441504415144152441534415444155441564415744158441594416044161441624416344164441654416644167441684416944170441714417244173441744417544176441774417844179441804418144182441834418444185441864418744188441894419044191441924419344194441954419644197441984419944200442014420244203442044420544206442074420844209442104421144212442134421444215442164421744218442194422044221442224422344224442254422644227442284422944230442314423244233442344423544236442374423844239442404424144242442434424444245442464424744248442494425044251442524425344254442554425644257442584425944260442614426244263442644426544266442674426844269442704427144272442734427444275442764427744278442794428044281442824428344284442854428644287442884428944290442914429244293442944429544296442974429844299443004430144302443034430444305443064430744308443094431044311443124431344314443154431644317443184431944320443214432244323443244432544326443274432844329443304433144332443334433444335443364433744338443394434044341443424434344344443454434644347443484434944350443514435244353443544435544356443574435844359443604436144362443634436444365443664436744368443694437044371443724437344374443754437644377443784437944380443814438244383443844438544386443874438844389443904439144392443934439444395443964439744398443994440044401444024440344404444054440644407444084440944410444114441244413444144441544416444174441844419444204442144422444234442444425444264442744428444294443044431444324443344434444354443644437444384443944440444414444244443444444444544446444474444844449444504445144452444534445444455444564445744458444594446044461444624446344464444654446644467444684446944470444714447244473444744447544476444774447844479444804448144482444834448444485444864448744488444894449044491444924449344494444954449644497444984449944500445014450244503445044450544506445074450844509445104451144512445134451444515445164451744518445194452044521445224452344524445254452644527445284452944530445314453244533445344453544536445374453844539445404454144542445434454444545445464454744548445494455044551445524455344554445554455644557445584455944560445614456244563445644456544566445674456844569445704457144572445734457444575445764457744578445794458044581445824458344584445854458644587445884458944590445914459244593445944459544596445974459844599446004460144602446034460444605446064460744608446094461044611446124461344614446154461644617446184461944620446214462244623446244462544626446274462844629446304463144632446334463444635446364463744638446394464044641446424464344644446454464644647446484464944650446514465244653446544465544656446574465844659446604466144662446634466444665446664466744668446694467044671446724467344674446754467644677446784467944680446814468244683446844468544686446874468844689446904469144692446934469444695446964469744698446994470044701447024470344704447054470644707447084470944710447114471244713447144471544716447174471844719447204472144722447234472444725447264472744728447294473044731447324473344734447354473644737447384473944740447414474244743447444474544746447474474844749447504475144752447534475444755447564475744758447594476044761447624476344764447654476644767447684476944770447714477244773447744477544776447774477844779447804478144782447834478444785447864478744788447894479044791447924479344794447954479644797447984479944800448014480244803448044480544806448074480844809448104481144812448134481444815448164481744818448194482044821448224482344824448254482644827448284482944830448314483244833448344483544836448374483844839448404484144842448434484444845448464484744848448494485044851448524485344854448554485644857448584485944860448614486244863448644486544866448674486844869448704487144872448734487444875448764487744878448794488044881448824488344884448854488644887448884488944890448914489244893448944489544896448974489844899449004490144902449034490444905449064490744908449094491044911449124491344914449154491644917449184491944920449214492244923449244492544926449274492844929449304493144932449334493444935449364493744938449394494044941449424494344944449454494644947449484494944950449514495244953449544495544956449574495844959449604496144962449634496444965449664496744968449694497044971449724497344974449754497644977449784497944980449814498244983449844498544986449874498844989449904499144992449934499444995449964499744998449994500045001450024500345004450054500645007450084500945010450114501245013450144501545016450174501845019450204502145022450234502445025450264502745028450294503045031450324503345034450354503645037450384503945040450414504245043450444504545046450474504845049450504505145052450534505445055450564505745058450594506045061450624506345064450654506645067450684506945070450714507245073450744507545076450774507845079450804508145082450834508445085450864508745088450894509045091450924509345094450954509645097450984509945100451014510245103451044510545106451074510845109451104511145112451134511445115451164511745118451194512045121451224512345124451254512645127451284512945130451314513245133451344513545136451374513845139451404514145142451434514445145451464514745148451494515045151451524515345154451554515645157451584515945160451614516245163451644516545166451674516845169451704517145172451734517445175451764517745178451794518045181451824518345184451854518645187451884518945190451914519245193451944519545196451974519845199452004520145202452034520445205452064520745208452094521045211452124521345214452154521645217452184521945220452214522245223452244522545226452274522845229452304523145232452334523445235452364523745238452394524045241452424524345244452454524645247452484524945250452514525245253452544525545256452574525845259452604526145262452634526445265452664526745268452694527045271452724527345274452754527645277452784527945280452814528245283452844528545286452874528845289452904529145292452934529445295452964529745298452994530045301453024530345304453054530645307453084530945310453114531245313453144531545316453174531845319453204532145322453234532445325453264532745328453294533045331453324533345334453354533645337453384533945340453414534245343453444534545346453474534845349453504535145352453534535445355453564535745358453594536045361453624536345364453654536645367453684536945370453714537245373453744537545376453774537845379453804538145382453834538445385453864538745388453894539045391453924539345394453954539645397453984539945400454014540245403454044540545406454074540845409454104541145412454134541445415454164541745418454194542045421454224542345424454254542645427454284542945430454314543245433454344543545436454374543845439454404544145442454434544445445454464544745448454494545045451454524545345454454554545645457454584545945460454614546245463454644546545466454674546845469454704547145472454734547445475454764547745478454794548045481454824548345484454854548645487454884548945490454914549245493454944549545496454974549845499455004550145502455034550445505455064550745508455094551045511455124551345514455154551645517455184551945520455214552245523455244552545526455274552845529455304553145532455334553445535455364553745538455394554045541455424554345544455454554645547455484554945550455514555245553455544555545556455574555845559455604556145562455634556445565455664556745568455694557045571455724557345574455754557645577455784557945580455814558245583455844558545586455874558845589455904559145592455934559445595455964559745598455994560045601456024560345604456054560645607456084560945610456114561245613456144561545616456174561845619456204562145622456234562445625456264562745628456294563045631456324563345634456354563645637456384563945640456414564245643456444564545646456474564845649456504565145652456534565445655456564565745658456594566045661456624566345664456654566645667456684566945670456714567245673456744567545676456774567845679456804568145682456834568445685456864568745688456894569045691456924569345694456954569645697456984569945700457014570245703457044570545706457074570845709457104571145712457134571445715457164571745718457194572045721457224572345724457254572645727457284572945730457314573245733457344573545736457374573845739457404574145742457434574445745457464574745748457494575045751457524575345754457554575645757457584575945760457614576245763457644576545766457674576845769457704577145772457734577445775457764577745778457794578045781457824578345784457854578645787457884578945790457914579245793457944579545796457974579845799458004580145802458034580445805458064580745808458094581045811458124581345814458154581645817458184581945820458214582245823458244582545826458274582845829458304583145832458334583445835458364583745838458394584045841458424584345844458454584645847458484584945850458514585245853458544585545856458574585845859458604586145862458634586445865458664586745868458694587045871458724587345874458754587645877458784587945880458814588245883458844588545886458874588845889458904589145892458934589445895458964589745898458994590045901459024590345904459054590645907459084590945910459114591245913459144591545916459174591845919459204592145922459234592445925459264592745928459294593045931459324593345934459354593645937459384593945940459414594245943459444594545946459474594845949459504595145952459534595445955459564595745958459594596045961459624596345964459654596645967459684596945970459714597245973459744597545976459774597845979459804598145982459834598445985459864598745988459894599045991459924599345994459954599645997459984599946000460014600246003460044600546006460074600846009460104601146012460134601446015460164601746018460194602046021460224602346024460254602646027460284602946030460314603246033460344603546036460374603846039460404604146042460434604446045460464604746048460494605046051460524605346054460554605646057460584605946060460614606246063460644606546066460674606846069460704607146072460734607446075460764607746078460794608046081460824608346084460854608646087460884608946090460914609246093460944609546096460974609846099461004610146102461034610446105461064610746108461094611046111461124611346114461154611646117461184611946120461214612246123461244612546126461274612846129461304613146132461334613446135461364613746138461394614046141461424614346144461454614646147461484614946150461514615246153461544615546156461574615846159461604616146162461634616446165461664616746168461694617046171461724617346174461754617646177461784617946180461814618246183461844618546186461874618846189461904619146192461934619446195461964619746198461994620046201462024620346204462054620646207462084620946210462114621246213462144621546216462174621846219462204622146222462234622446225462264622746228462294623046231462324623346234462354623646237462384623946240462414624246243462444624546246462474624846249462504625146252462534625446255462564625746258462594626046261462624626346264462654626646267462684626946270462714627246273462744627546276462774627846279462804628146282462834628446285462864628746288462894629046291462924629346294462954629646297462984629946300463014630246303463044630546306463074630846309463104631146312463134631446315463164631746318463194632046321463224632346324463254632646327463284632946330463314633246333463344633546336463374633846339463404634146342463434634446345463464634746348463494635046351463524635346354463554635646357463584635946360463614636246363463644636546366463674636846369463704637146372463734637446375463764637746378463794638046381463824638346384463854638646387463884638946390463914639246393463944639546396463974639846399464004640146402464034640446405464064640746408464094641046411464124641346414464154641646417464184641946420464214642246423464244642546426464274642846429464304643146432464334643446435464364643746438464394644046441464424644346444464454644646447464484644946450464514645246453464544645546456464574645846459464604646146462464634646446465464664646746468464694647046471464724647346474464754647646477464784647946480464814648246483464844648546486464874648846489464904649146492464934649446495464964649746498464994650046501465024650346504465054650646507465084650946510465114651246513465144651546516465174651846519465204652146522465234652446525465264652746528465294653046531465324653346534465354653646537465384653946540465414654246543465444654546546465474654846549465504655146552465534655446555465564655746558465594656046561465624656346564465654656646567465684656946570465714657246573465744657546576465774657846579465804658146582465834658446585465864658746588465894659046591465924659346594465954659646597465984659946600466014660246603466044660546606466074660846609466104661146612466134661446615466164661746618466194662046621466224662346624466254662646627466284662946630466314663246633466344663546636466374663846639466404664146642466434664446645466464664746648466494665046651466524665346654466554665646657466584665946660466614666246663466644666546666466674666846669466704667146672466734667446675466764667746678466794668046681466824668346684466854668646687466884668946690466914669246693466944669546696466974669846699467004670146702467034670446705467064670746708467094671046711467124671346714467154671646717467184671946720467214672246723467244672546726467274672846729467304673146732467334673446735467364673746738467394674046741467424674346744467454674646747467484674946750467514675246753467544675546756467574675846759467604676146762467634676446765467664676746768467694677046771467724677346774467754677646777467784677946780467814678246783467844678546786467874678846789467904679146792467934679446795467964679746798467994680046801468024680346804468054680646807468084680946810468114681246813468144681546816468174681846819468204682146822468234682446825468264682746828468294683046831468324683346834468354683646837468384683946840468414684246843468444684546846468474684846849468504685146852468534685446855468564685746858468594686046861468624686346864468654686646867468684686946870468714687246873468744687546876468774687846879468804688146882468834688446885468864688746888468894689046891468924689346894468954689646897468984689946900469014690246903469044690546906469074690846909469104691146912469134691446915469164691746918469194692046921469224692346924469254692646927469284692946930469314693246933469344693546936469374693846939469404694146942469434694446945469464694746948469494695046951469524695346954469554695646957469584695946960469614696246963469644696546966469674696846969469704697146972469734697446975469764697746978469794698046981469824698346984469854698646987469884698946990469914699246993469944699546996469974699846999470004700147002470034700447005470064700747008470094701047011470124701347014470154701647017470184701947020470214702247023470244702547026470274702847029470304703147032470334703447035470364703747038470394704047041470424704347044470454704647047470484704947050470514705247053470544705547056470574705847059470604706147062470634706447065470664706747068470694707047071470724707347074470754707647077470784707947080470814708247083470844708547086470874708847089470904709147092470934709447095470964709747098470994710047101471024710347104471054710647107471084710947110471114711247113471144711547116471174711847119471204712147122471234712447125471264712747128471294713047131471324713347134471354713647137471384713947140471414714247143471444714547146471474714847149471504715147152471534715447155471564715747158471594716047161471624716347164471654716647167471684716947170471714717247173471744717547176471774717847179471804718147182471834718447185471864718747188471894719047191471924719347194471954719647197471984719947200472014720247203472044720547206472074720847209472104721147212472134721447215472164721747218472194722047221472224722347224472254722647227472284722947230472314723247233472344723547236472374723847239472404724147242472434724447245472464724747248472494725047251472524725347254472554725647257472584725947260472614726247263472644726547266472674726847269472704727147272472734727447275472764727747278472794728047281472824728347284472854728647287472884728947290472914729247293472944729547296472974729847299473004730147302473034730447305473064730747308473094731047311473124731347314473154731647317473184731947320473214732247323473244732547326473274732847329473304733147332473334733447335473364733747338473394734047341473424734347344473454734647347473484734947350473514735247353473544735547356473574735847359473604736147362473634736447365473664736747368473694737047371473724737347374473754737647377473784737947380473814738247383473844738547386473874738847389473904739147392473934739447395473964739747398473994740047401474024740347404474054740647407474084740947410474114741247413474144741547416474174741847419474204742147422474234742447425474264742747428474294743047431474324743347434474354743647437474384743947440474414744247443474444744547446474474744847449474504745147452474534745447455474564745747458474594746047461474624746347464474654746647467474684746947470474714747247473474744747547476474774747847479474804748147482474834748447485474864748747488474894749047491474924749347494474954749647497474984749947500475014750247503475044750547506475074750847509475104751147512475134751447515475164751747518475194752047521475224752347524475254752647527475284752947530475314753247533475344753547536475374753847539475404754147542475434754447545475464754747548475494755047551475524755347554475554755647557475584755947560475614756247563475644756547566475674756847569475704757147572475734757447575475764757747578475794758047581475824758347584475854758647587475884758947590475914759247593475944759547596475974759847599476004760147602476034760447605476064760747608476094761047611476124761347614476154761647617476184761947620476214762247623476244762547626476274762847629476304763147632476334763447635476364763747638476394764047641476424764347644476454764647647476484764947650476514765247653476544765547656476574765847659476604766147662476634766447665476664766747668476694767047671476724767347674476754767647677476784767947680476814768247683476844768547686476874768847689476904769147692476934769447695476964769747698476994770047701477024770347704477054770647707477084770947710477114771247713477144771547716477174771847719477204772147722477234772447725477264772747728477294773047731477324773347734477354773647737477384773947740477414774247743477444774547746477474774847749477504775147752477534775447755477564775747758477594776047761477624776347764477654776647767477684776947770477714777247773477744777547776477774777847779477804778147782477834778447785477864778747788477894779047791477924779347794477954779647797477984779947800478014780247803478044780547806478074780847809478104781147812478134781447815478164781747818478194782047821478224782347824478254782647827478284782947830478314783247833478344783547836478374783847839478404784147842478434784447845478464784747848478494785047851478524785347854478554785647857478584785947860478614786247863478644786547866478674786847869478704787147872478734787447875478764787747878478794788047881478824788347884478854788647887478884788947890478914789247893478944789547896478974789847899479004790147902479034790447905479064790747908479094791047911479124791347914479154791647917479184791947920479214792247923479244792547926479274792847929479304793147932479334793447935479364793747938479394794047941479424794347944479454794647947479484794947950479514795247953479544795547956479574795847959479604796147962479634796447965479664796747968479694797047971479724797347974479754797647977479784797947980479814798247983479844798547986479874798847989479904799147992479934799447995479964799747998479994800048001480024800348004480054800648007480084800948010480114801248013480144801548016480174801848019480204802148022480234802448025480264802748028480294803048031480324803348034480354803648037480384803948040480414804248043480444804548046480474804848049480504805148052480534805448055480564805748058480594806048061480624806348064480654806648067480684806948070480714807248073480744807548076480774807848079480804808148082480834808448085480864808748088480894809048091480924809348094480954809648097480984809948100481014810248103481044810548106481074810848109481104811148112481134811448115481164811748118481194812048121481224812348124481254812648127481284812948130481314813248133481344813548136481374813848139481404814148142481434814448145481464814748148481494815048151481524815348154481554815648157481584815948160481614816248163481644816548166481674816848169481704817148172481734817448175481764817748178481794818048181481824818348184481854818648187481884818948190481914819248193481944819548196481974819848199482004820148202482034820448205482064820748208482094821048211482124821348214482154821648217482184821948220482214822248223482244822548226482274822848229482304823148232482334823448235482364823748238482394824048241482424824348244482454824648247482484824948250482514825248253482544825548256482574825848259482604826148262482634826448265482664826748268482694827048271482724827348274482754827648277482784827948280482814828248283482844828548286482874828848289482904829148292482934829448295482964829748298482994830048301483024830348304483054830648307483084830948310483114831248313483144831548316483174831848319483204832148322483234832448325483264832748328483294833048331483324833348334483354833648337483384833948340483414834248343483444834548346483474834848349483504835148352483534835448355483564835748358483594836048361483624836348364483654836648367483684836948370483714837248373483744837548376483774837848379483804838148382483834838448385483864838748388483894839048391483924839348394483954839648397483984839948400484014840248403484044840548406484074840848409484104841148412484134841448415484164841748418484194842048421484224842348424484254842648427484284842948430484314843248433484344843548436484374843848439484404844148442484434844448445484464844748448484494845048451484524845348454484554845648457484584845948460484614846248463484644846548466484674846848469484704847148472484734847448475484764847748478484794848048481484824848348484484854848648487484884848948490484914849248493484944849548496484974849848499485004850148502485034850448505485064850748508485094851048511485124851348514485154851648517485184851948520485214852248523485244852548526485274852848529485304853148532485334853448535485364853748538485394854048541485424854348544485454854648547485484854948550485514855248553485544855548556485574855848559485604856148562485634856448565485664856748568485694857048571485724857348574485754857648577485784857948580485814858248583485844858548586485874858848589485904859148592485934859448595485964859748598485994860048601486024860348604486054860648607486084860948610486114861248613486144861548616486174861848619486204862148622486234862448625486264862748628486294863048631486324863348634486354863648637486384863948640486414864248643486444864548646486474864848649486504865148652486534865448655486564865748658486594866048661486624866348664486654866648667486684866948670486714867248673486744867548676486774867848679486804868148682486834868448685486864868748688486894869048691486924869348694486954869648697486984869948700487014870248703487044870548706487074870848709487104871148712487134871448715487164871748718487194872048721487224872348724487254872648727487284872948730487314873248733487344873548736487374873848739487404874148742487434874448745487464874748748487494875048751487524875348754487554875648757487584875948760487614876248763487644876548766487674876848769487704877148772487734877448775487764877748778487794878048781487824878348784487854878648787487884878948790487914879248793487944879548796487974879848799488004880148802488034880448805488064880748808488094881048811488124881348814488154881648817488184881948820488214882248823488244882548826488274882848829488304883148832488334883448835488364883748838488394884048841488424884348844488454884648847488484884948850488514885248853488544885548856488574885848859488604886148862488634886448865488664886748868488694887048871488724887348874488754887648877488784887948880488814888248883488844888548886488874888848889488904889148892488934889448895488964889748898488994890048901489024890348904489054890648907489084890948910489114891248913489144891548916489174891848919489204892148922489234892448925489264892748928489294893048931489324893348934489354893648937489384893948940489414894248943489444894548946489474894848949489504895148952489534895448955489564895748958489594896048961489624896348964489654896648967489684896948970489714897248973489744897548976489774897848979489804898148982489834898448985489864898748988489894899048991489924899348994489954899648997489984899949000490014900249003490044900549006490074900849009490104901149012490134901449015490164901749018490194902049021490224902349024490254902649027490284902949030490314903249033490344903549036490374903849039490404904149042490434904449045490464904749048490494905049051490524905349054490554905649057490584905949060490614906249063490644906549066490674906849069490704907149072490734907449075490764907749078490794908049081490824908349084490854908649087490884908949090490914909249093490944909549096490974909849099491004910149102491034910449105491064910749108491094911049111491124911349114491154911649117491184911949120491214912249123491244912549126491274912849129491304913149132491334913449135491364913749138491394914049141491424914349144491454914649147491484914949150491514915249153491544915549156491574915849159491604916149162491634916449165491664916749168491694917049171491724917349174491754917649177491784917949180491814918249183491844918549186491874918849189491904919149192491934919449195491964919749198491994920049201492024920349204492054920649207492084920949210492114921249213492144921549216492174921849219492204922149222492234922449225492264922749228492294923049231492324923349234492354923649237492384923949240492414924249243492444924549246492474924849249492504925149252492534925449255492564925749258492594926049261492624926349264492654926649267492684926949270492714927249273492744927549276492774927849279492804928149282492834928449285492864928749288492894929049291492924929349294492954929649297492984929949300493014930249303493044930549306493074930849309493104931149312493134931449315493164931749318493194932049321493224932349324493254932649327493284932949330493314933249333493344933549336493374933849339493404934149342493434934449345493464934749348493494935049351493524935349354493554935649357493584935949360493614936249363493644936549366493674936849369493704937149372493734937449375493764937749378493794938049381493824938349384493854938649387493884938949390493914939249393493944939549396493974939849399494004940149402494034940449405494064940749408494094941049411494124941349414494154941649417494184941949420494214942249423494244942549426494274942849429494304943149432494334943449435494364943749438494394944049441494424944349444494454944649447494484944949450494514945249453494544945549456494574945849459494604946149462494634946449465494664946749468494694947049471494724947349474494754947649477494784947949480494814948249483494844948549486494874948849489494904949149492494934949449495494964949749498494994950049501495024950349504495054950649507495084950949510495114951249513495144951549516495174951849519495204952149522495234952449525495264952749528495294953049531495324953349534495354953649537495384953949540495414954249543495444954549546495474954849549495504955149552495534955449555495564955749558495594956049561495624956349564495654956649567495684956949570495714957249573495744957549576495774957849579495804958149582495834958449585495864958749588495894959049591495924959349594495954959649597495984959949600496014960249603496044960549606496074960849609496104961149612496134961449615496164961749618496194962049621496224962349624496254962649627496284962949630496314963249633496344963549636496374963849639496404964149642496434964449645496464964749648496494965049651496524965349654496554965649657496584965949660496614966249663496644966549666496674966849669496704967149672496734967449675496764967749678496794968049681496824968349684496854968649687496884968949690496914969249693496944969549696496974969849699497004970149702497034970449705497064970749708497094971049711497124971349714497154971649717497184971949720497214972249723497244972549726497274972849729497304973149732497334973449735497364973749738497394974049741497424974349744497454974649747497484974949750497514975249753497544975549756497574975849759497604976149762497634976449765497664976749768497694977049771497724977349774497754977649777497784977949780497814978249783497844978549786497874978849789497904979149792497934979449795497964979749798497994980049801498024980349804498054980649807498084980949810498114981249813498144981549816498174981849819498204982149822498234982449825498264982749828498294983049831498324983349834498354983649837498384983949840498414984249843498444984549846498474984849849498504985149852498534985449855498564985749858498594986049861498624986349864498654986649867498684986949870498714987249873498744987549876498774987849879498804988149882498834988449885498864988749888498894989049891498924989349894498954989649897498984989949900499014990249903499044990549906499074990849909499104991149912499134991449915499164991749918499194992049921499224992349924499254992649927499284992949930499314993249933499344993549936499374993849939499404994149942499434994449945499464994749948499494995049951499524995349954499554995649957499584995949960499614996249963499644996549966499674996849969499704997149972499734997449975499764997749978499794998049981499824998349984499854998649987499884998949990499914999249993499944999549996499974999849999500005000150002500035000450005500065000750008500095001050011500125001350014500155001650017500185001950020500215002250023500245002550026500275002850029500305003150032500335003450035500365003750038500395004050041500425004350044500455004650047500485004950050500515005250053500545005550056500575005850059500605006150062500635006450065500665006750068500695007050071500725007350074500755007650077500785007950080500815008250083500845008550086500875008850089500905009150092500935009450095500965009750098500995010050101501025010350104501055010650107501085010950110501115011250113501145011550116501175011850119501205012150122501235012450125501265012750128501295013050131501325013350134501355013650137501385013950140501415014250143501445014550146501475014850149501505015150152501535015450155501565015750158501595016050161501625016350164501655016650167501685016950170501715017250173501745017550176501775017850179501805018150182501835018450185501865018750188501895019050191501925019350194501955019650197501985019950200502015020250203502045020550206502075020850209502105021150212502135021450215502165021750218502195022050221502225022350224502255022650227502285022950230502315023250233502345023550236502375023850239502405024150242502435024450245502465024750248502495025050251502525025350254502555025650257502585025950260502615026250263502645026550266502675026850269502705027150272502735027450275502765027750278502795028050281502825028350284502855028650287502885028950290502915029250293502945029550296502975029850299503005030150302503035030450305503065030750308503095031050311503125031350314503155031650317503185031950320503215032250323503245032550326503275032850329503305033150332503335033450335503365033750338503395034050341503425034350344503455034650347503485034950350503515035250353503545035550356503575035850359503605036150362503635036450365503665036750368503695037050371503725037350374503755037650377503785037950380503815038250383503845038550386503875038850389503905039150392503935039450395503965039750398503995040050401504025040350404504055040650407504085040950410504115041250413504145041550416504175041850419504205042150422504235042450425504265042750428504295043050431504325043350434504355043650437504385043950440504415044250443504445044550446504475044850449504505045150452504535045450455504565045750458504595046050461504625046350464504655046650467504685046950470504715047250473504745047550476504775047850479504805048150482504835048450485504865048750488504895049050491504925049350494504955049650497504985049950500505015050250503505045050550506505075050850509505105051150512505135051450515505165051750518505195052050521505225052350524505255052650527505285052950530505315053250533505345053550536505375053850539505405054150542505435054450545505465054750548505495055050551505525055350554505555055650557505585055950560505615056250563505645056550566505675056850569505705057150572505735057450575505765057750578505795058050581505825058350584505855058650587505885058950590505915059250593505945059550596505975059850599506005060150602506035060450605506065060750608506095061050611506125061350614506155061650617506185061950620506215062250623506245062550626506275062850629506305063150632506335063450635506365063750638506395064050641506425064350644506455064650647506485064950650506515065250653506545065550656506575065850659506605066150662506635066450665506665066750668506695067050671506725067350674506755067650677506785067950680506815068250683506845068550686506875068850689506905069150692506935069450695506965069750698506995070050701507025070350704507055070650707507085070950710507115071250713507145071550716507175071850719507205072150722507235072450725507265072750728507295073050731507325073350734507355073650737507385073950740507415074250743507445074550746507475074850749507505075150752507535075450755507565075750758507595076050761507625076350764507655076650767507685076950770507715077250773507745077550776507775077850779507805078150782507835078450785507865078750788507895079050791507925079350794507955079650797507985079950800508015080250803508045080550806508075080850809508105081150812508135081450815508165081750818508195082050821508225082350824508255082650827508285082950830508315083250833508345083550836508375083850839508405084150842508435084450845508465084750848508495085050851508525085350854508555085650857508585085950860508615086250863508645086550866508675086850869508705087150872508735087450875508765087750878508795088050881508825088350884508855088650887508885088950890508915089250893508945089550896508975089850899509005090150902509035090450905509065090750908509095091050911509125091350914509155091650917509185091950920509215092250923509245092550926509275092850929509305093150932509335093450935509365093750938509395094050941509425094350944509455094650947509485094950950509515095250953509545095550956509575095850959509605096150962509635096450965509665096750968509695097050971509725097350974509755097650977509785097950980509815098250983509845098550986509875098850989509905099150992509935099450995509965099750998509995100051001510025100351004510055100651007510085100951010510115101251013510145101551016510175101851019510205102151022510235102451025510265102751028510295103051031510325103351034510355103651037510385103951040510415104251043510445104551046510475104851049510505105151052510535105451055510565105751058510595106051061510625106351064510655106651067510685106951070510715107251073510745107551076510775107851079510805108151082510835108451085510865108751088510895109051091510925109351094510955109651097510985109951100511015110251103511045110551106511075110851109511105111151112511135111451115511165111751118511195112051121511225112351124511255112651127511285112951130511315113251133511345113551136511375113851139511405114151142511435114451145511465114751148511495115051151511525115351154511555115651157511585115951160511615116251163511645116551166511675116851169511705117151172511735117451175511765117751178511795118051181511825118351184511855118651187511885118951190511915119251193511945119551196511975119851199512005120151202512035120451205512065120751208512095121051211512125121351214512155121651217512185121951220512215122251223512245122551226512275122851229512305123151232512335123451235512365123751238512395124051241512425124351244512455124651247512485124951250512515125251253512545125551256512575125851259512605126151262512635126451265512665126751268512695127051271512725127351274512755127651277512785127951280512815128251283512845128551286512875128851289512905129151292512935129451295512965129751298512995130051301513025130351304513055130651307513085130951310513115131251313513145131551316513175131851319513205132151322513235132451325513265132751328513295133051331513325133351334513355133651337513385133951340513415134251343513445134551346513475134851349513505135151352513535135451355513565135751358513595136051361513625136351364513655136651367513685136951370513715137251373513745137551376513775137851379513805138151382513835138451385513865138751388513895139051391513925139351394513955139651397513985139951400514015140251403514045140551406514075140851409514105141151412514135141451415514165141751418514195142051421514225142351424514255142651427514285142951430514315143251433514345143551436514375143851439514405144151442514435144451445514465144751448514495145051451514525145351454514555145651457514585145951460514615146251463514645146551466514675146851469514705147151472514735147451475514765147751478514795148051481514825148351484514855148651487514885148951490514915149251493514945149551496514975149851499515005150151502515035150451505515065150751508515095151051511515125151351514515155151651517515185151951520515215152251523515245152551526515275152851529515305153151532515335153451535515365153751538515395154051541515425154351544515455154651547515485154951550515515155251553515545155551556515575155851559515605156151562515635156451565515665156751568515695157051571515725157351574515755157651577515785157951580515815158251583515845158551586515875158851589515905159151592515935159451595515965159751598515995160051601516025160351604516055160651607516085160951610516115161251613516145161551616516175161851619516205162151622516235162451625516265162751628516295163051631516325163351634516355163651637516385163951640516415164251643516445164551646516475164851649516505165151652516535165451655516565165751658516595166051661516625166351664516655166651667516685166951670516715167251673516745167551676516775167851679516805168151682516835168451685516865168751688516895169051691516925169351694516955169651697516985169951700517015170251703517045170551706517075170851709517105171151712517135171451715517165171751718517195172051721517225172351724517255172651727517285172951730517315173251733517345173551736517375173851739517405174151742517435174451745517465174751748517495175051751517525175351754517555175651757517585175951760517615176251763517645176551766517675176851769517705177151772517735177451775517765177751778517795178051781517825178351784517855178651787517885178951790517915179251793517945179551796517975179851799518005180151802518035180451805518065180751808518095181051811518125181351814518155181651817518185181951820518215182251823518245182551826518275182851829518305183151832518335183451835518365183751838518395184051841518425184351844518455184651847518485184951850518515185251853518545185551856518575185851859518605186151862518635186451865518665186751868518695187051871518725187351874518755187651877518785187951880518815188251883518845188551886518875188851889518905189151892518935189451895518965189751898518995190051901519025190351904519055190651907519085190951910519115191251913519145191551916519175191851919519205192151922519235192451925519265192751928519295193051931519325193351934519355193651937519385193951940519415194251943519445194551946519475194851949519505195151952519535195451955519565195751958519595196051961519625196351964519655196651967519685196951970519715197251973519745197551976519775197851979519805198151982519835198451985519865198751988519895199051991519925199351994519955199651997519985199952000520015200252003520045200552006520075200852009520105201152012520135201452015520165201752018520195202052021520225202352024520255202652027520285202952030520315203252033520345203552036520375203852039520405204152042520435204452045520465204752048520495205052051520525205352054520555205652057520585205952060520615206252063520645206552066520675206852069520705207152072520735207452075520765207752078520795208052081520825208352084520855208652087520885208952090520915209252093520945209552096520975209852099521005210152102521035210452105521065210752108521095211052111521125211352114521155211652117521185211952120521215212252123521245212552126521275212852129521305213152132521335213452135521365213752138521395214052141521425214352144521455214652147521485214952150521515215252153521545215552156521575215852159521605216152162521635216452165521665216752168521695217052171521725217352174521755217652177521785217952180521815218252183521845218552186521875218852189521905219152192521935219452195521965219752198521995220052201522025220352204522055220652207522085220952210522115221252213522145221552216522175221852219522205222152222522235222452225522265222752228522295223052231522325223352234522355223652237522385223952240522415224252243522445224552246522475224852249522505225152252522535225452255522565225752258522595226052261522625226352264522655226652267522685226952270522715227252273522745227552276522775227852279522805228152282522835228452285522865228752288522895229052291522925229352294522955229652297522985229952300523015230252303523045230552306523075230852309523105231152312523135231452315523165231752318523195232052321523225232352324523255232652327523285232952330523315233252333523345233552336523375233852339523405234152342523435234452345523465234752348523495235052351523525235352354523555235652357523585235952360523615236252363523645236552366523675236852369523705237152372523735237452375523765237752378523795238052381523825238352384523855238652387523885238952390523915239252393523945239552396523975239852399524005240152402524035240452405524065240752408524095241052411524125241352414524155241652417524185241952420524215242252423524245242552426524275242852429524305243152432524335243452435524365243752438524395244052441524425244352444524455244652447524485244952450524515245252453524545245552456524575245852459524605246152462524635246452465524665246752468524695247052471524725247352474524755247652477524785247952480524815248252483524845248552486524875248852489524905249152492524935249452495524965249752498524995250052501525025250352504525055250652507525085250952510525115251252513525145251552516525175251852519525205252152522525235252452525525265252752528525295253052531525325253352534525355253652537525385253952540525415254252543525445254552546525475254852549525505255152552525535255452555525565255752558525595256052561525625256352564525655256652567525685256952570525715257252573525745257552576525775257852579525805258152582525835258452585525865258752588525895259052591525925259352594525955259652597525985259952600526015260252603526045260552606526075260852609526105261152612526135261452615526165261752618526195262052621526225262352624526255262652627526285262952630526315263252633526345263552636526375263852639526405264152642526435264452645526465264752648526495265052651526525265352654526555265652657526585265952660526615266252663526645266552666526675266852669526705267152672526735267452675526765267752678526795268052681526825268352684526855268652687526885268952690526915269252693526945269552696526975269852699527005270152702527035270452705527065270752708527095271052711527125271352714527155271652717527185271952720527215272252723527245272552726527275272852729527305273152732527335273452735527365273752738527395274052741527425274352744527455274652747527485274952750527515275252753527545275552756527575275852759527605276152762527635276452765527665276752768527695277052771527725277352774527755277652777527785277952780527815278252783527845278552786527875278852789527905279152792527935279452795527965279752798527995280052801528025280352804528055280652807528085280952810528115281252813528145281552816528175281852819528205282152822528235282452825528265282752828528295283052831528325283352834528355283652837528385283952840528415284252843528445284552846528475284852849528505285152852528535285452855528565285752858528595286052861528625286352864528655286652867528685286952870528715287252873528745287552876528775287852879528805288152882528835288452885528865288752888528895289052891528925289352894528955289652897528985289952900529015290252903529045290552906529075290852909529105291152912529135291452915529165291752918529195292052921529225292352924529255292652927529285292952930529315293252933529345293552936529375293852939529405294152942529435294452945529465294752948529495295052951529525295352954529555295652957529585295952960529615296252963529645296552966529675296852969529705297152972529735297452975529765297752978529795298052981529825298352984529855298652987529885298952990529915299252993529945299552996529975299852999530005300153002530035300453005530065300753008530095301053011530125301353014530155301653017530185301953020530215302253023530245302553026530275302853029530305303153032530335303453035530365303753038530395304053041530425304353044530455304653047530485304953050530515305253053530545305553056530575305853059530605306153062530635306453065530665306753068530695307053071530725307353074530755307653077530785307953080530815308253083530845308553086530875308853089530905309153092530935309453095530965309753098530995310053101531025310353104531055310653107531085310953110531115311253113531145311553116531175311853119531205312153122531235312453125531265312753128531295313053131531325313353134531355313653137531385313953140531415314253143531445314553146531475314853149531505315153152531535315453155531565315753158531595316053161531625316353164531655316653167531685316953170531715317253173531745317553176531775317853179531805318153182531835318453185531865318753188531895319053191531925319353194531955319653197531985319953200532015320253203532045320553206532075320853209532105321153212532135321453215532165321753218532195322053221532225322353224532255322653227532285322953230532315323253233532345323553236532375323853239532405324153242532435324453245532465324753248532495325053251532525325353254532555325653257532585325953260532615326253263532645326553266532675326853269532705327153272532735327453275532765327753278532795328053281532825328353284532855328653287532885328953290532915329253293532945329553296532975329853299533005330153302533035330453305533065330753308533095331053311533125331353314533155331653317533185331953320533215332253323533245332553326533275332853329533305333153332533335333453335533365333753338533395334053341533425334353344533455334653347533485334953350533515335253353533545335553356533575335853359533605336153362533635336453365533665336753368533695337053371533725337353374533755337653377533785337953380533815338253383533845338553386533875338853389533905339153392533935339453395533965339753398533995340053401534025340353404534055340653407534085340953410534115341253413534145341553416534175341853419534205342153422534235342453425534265342753428534295343053431534325343353434534355343653437534385343953440534415344253443534445344553446534475344853449534505345153452534535345453455534565345753458534595346053461534625346353464534655346653467534685346953470534715347253473534745347553476534775347853479534805348153482534835348453485534865348753488534895349053491534925349353494534955349653497534985349953500535015350253503535045350553506535075350853509535105351153512535135351453515535165351753518535195352053521535225352353524535255352653527535285352953530535315353253533535345353553536535375353853539535405354153542535435354453545535465354753548535495355053551535525355353554535555355653557535585355953560535615356253563535645356553566535675356853569535705357153572535735357453575535765357753578535795358053581535825358353584535855358653587535885358953590535915359253593535945359553596535975359853599536005360153602536035360453605536065360753608536095361053611536125361353614536155361653617536185361953620536215362253623536245362553626536275362853629536305363153632536335363453635536365363753638536395364053641536425364353644536455364653647536485364953650536515365253653536545365553656536575365853659536605366153662536635366453665536665366753668536695367053671536725367353674536755367653677536785367953680536815368253683536845368553686536875368853689536905369153692536935369453695536965369753698536995370053701537025370353704537055370653707537085370953710537115371253713537145371553716537175371853719537205372153722537235372453725537265372753728537295373053731537325373353734537355373653737537385373953740537415374253743537445374553746537475374853749537505375153752537535375453755537565375753758537595376053761537625376353764537655376653767537685376953770537715377253773537745377553776537775377853779537805378153782537835378453785537865378753788537895379053791537925379353794537955379653797537985379953800538015380253803538045380553806538075380853809538105381153812538135381453815538165381753818538195382053821538225382353824538255382653827538285382953830538315383253833538345383553836538375383853839538405384153842538435384453845538465384753848538495385053851538525385353854538555385653857538585385953860538615386253863538645386553866538675386853869538705387153872538735387453875538765387753878538795388053881538825388353884538855388653887538885388953890538915389253893538945389553896538975389853899539005390153902539035390453905539065390753908539095391053911539125391353914539155391653917539185391953920539215392253923539245392553926539275392853929539305393153932539335393453935539365393753938539395394053941539425394353944539455394653947539485394953950539515395253953539545395553956539575395853959539605396153962539635396453965539665396753968539695397053971539725397353974539755397653977539785397953980539815398253983539845398553986539875398853989539905399153992539935399453995539965399753998539995400054001540025400354004540055400654007540085400954010540115401254013540145401554016540175401854019540205402154022540235402454025540265402754028540295403054031540325403354034540355403654037540385403954040540415404254043540445404554046540475404854049540505405154052540535405454055540565405754058540595406054061540625406354064540655406654067540685406954070540715407254073540745407554076540775407854079540805408154082540835408454085540865408754088540895409054091540925409354094540955409654097540985409954100541015410254103541045410554106541075410854109541105411154112541135411454115541165411754118541195412054121541225412354124541255412654127541285412954130541315413254133541345413554136541375413854139541405414154142541435414454145541465414754148541495415054151541525415354154541555415654157541585415954160541615416254163541645416554166541675416854169541705417154172541735417454175541765417754178541795418054181541825418354184541855418654187541885418954190541915419254193541945419554196541975419854199542005420154202542035420454205542065420754208542095421054211542125421354214542155421654217542185421954220542215422254223542245422554226542275422854229542305423154232542335423454235542365423754238542395424054241542425424354244542455424654247542485424954250542515425254253542545425554256542575425854259542605426154262542635426454265542665426754268542695427054271542725427354274542755427654277542785427954280542815428254283542845428554286542875428854289542905429154292542935429454295542965429754298542995430054301543025430354304543055430654307543085430954310543115431254313543145431554316543175431854319543205432154322543235432454325543265432754328543295433054331543325433354334543355433654337543385433954340543415434254343543445434554346543475434854349543505435154352543535435454355543565435754358543595436054361543625436354364543655436654367543685436954370543715437254373543745437554376543775437854379543805438154382543835438454385543865438754388543895439054391543925439354394543955439654397543985439954400544015440254403544045440554406544075440854409544105441154412544135441454415544165441754418544195442054421544225442354424544255442654427544285442954430544315443254433544345443554436544375443854439544405444154442544435444454445544465444754448544495445054451544525445354454544555445654457544585445954460544615446254463544645446554466544675446854469544705447154472544735447454475544765447754478544795448054481544825448354484544855448654487544885448954490544915449254493544945449554496544975449854499545005450154502545035450454505545065450754508545095451054511545125451354514545155451654517545185451954520545215452254523545245452554526545275452854529545305453154532545335453454535545365453754538545395454054541545425454354544545455454654547545485454954550545515455254553545545455554556545575455854559545605456154562545635456454565545665456754568545695457054571545725457354574545755457654577545785457954580545815458254583545845458554586545875458854589545905459154592545935459454595545965459754598545995460054601546025460354604546055460654607546085460954610546115461254613546145461554616546175461854619546205462154622546235462454625546265462754628546295463054631546325463354634546355463654637546385463954640546415464254643546445464554646546475464854649546505465154652546535465454655546565465754658546595466054661546625466354664546655466654667546685466954670546715467254673546745467554676546775467854679546805468154682546835468454685546865468754688546895469054691546925469354694546955469654697546985469954700547015470254703547045470554706547075470854709547105471154712547135471454715547165471754718547195472054721547225472354724547255472654727547285472954730547315473254733547345473554736547375473854739547405474154742547435474454745547465474754748547495475054751547525475354754547555475654757547585475954760547615476254763547645476554766547675476854769547705477154772547735477454775547765477754778547795478054781547825478354784547855478654787547885478954790547915479254793547945479554796547975479854799548005480154802548035480454805548065480754808548095481054811548125481354814548155481654817548185481954820548215482254823548245482554826548275482854829548305483154832548335483454835548365483754838548395484054841548425484354844548455484654847548485484954850548515485254853548545485554856548575485854859548605486154862548635486454865548665486754868548695487054871548725487354874548755487654877548785487954880548815488254883548845488554886548875488854889548905489154892548935489454895548965489754898548995490054901549025490354904549055490654907549085490954910549115491254913549145491554916549175491854919549205492154922549235492454925549265492754928549295493054931549325493354934549355493654937549385493954940549415494254943549445494554946549475494854949549505495154952549535495454955549565495754958549595496054961549625496354964549655496654967549685496954970549715497254973549745497554976549775497854979549805498154982549835498454985549865498754988549895499054991549925499354994549955499654997549985499955000550015500255003550045500555006550075500855009550105501155012550135501455015550165501755018550195502055021550225502355024550255502655027550285502955030550315503255033550345503555036550375503855039550405504155042550435504455045550465504755048550495505055051550525505355054550555505655057550585505955060550615506255063550645506555066550675506855069550705507155072550735507455075550765507755078550795508055081550825508355084550855508655087550885508955090550915509255093550945509555096550975509855099551005510155102551035510455105551065510755108551095511055111551125511355114551155511655117551185511955120551215512255123551245512555126551275512855129551305513155132551335513455135551365513755138551395514055141551425514355144551455514655147551485514955150551515515255153551545515555156551575515855159551605516155162551635516455165551665516755168551695517055171551725517355174551755517655177551785517955180551815518255183551845518555186551875518855189551905519155192551935519455195551965519755198551995520055201552025520355204552055520655207552085520955210552115521255213552145521555216552175521855219552205522155222552235522455225552265522755228552295523055231552325523355234552355523655237552385523955240552415524255243552445524555246552475524855249552505525155252552535525455255552565525755258552595526055261552625526355264552655526655267552685526955270552715527255273552745527555276552775527855279552805528155282552835528455285552865528755288552895529055291552925529355294552955529655297552985529955300553015530255303553045530555306553075530855309553105531155312553135531455315553165531755318553195532055321553225532355324553255532655327553285532955330553315533255333553345533555336553375533855339553405534155342553435534455345553465534755348553495535055351553525535355354553555535655357553585535955360553615536255363553645536555366553675536855369553705537155372553735537455375553765537755378553795538055381553825538355384553855538655387553885538955390553915539255393553945539555396553975539855399554005540155402554035540455405554065540755408554095541055411554125541355414554155541655417554185541955420554215542255423554245542555426554275542855429554305543155432554335543455435554365543755438554395544055441554425544355444554455544655447554485544955450554515545255453554545545555456554575545855459554605546155462554635546455465554665546755468554695547055471554725547355474554755547655477554785547955480554815548255483554845548555486554875548855489554905549155492554935549455495554965549755498554995550055501555025550355504555055550655507555085550955510555115551255513555145551555516555175551855519555205552155522555235552455525555265552755528555295553055531555325553355534555355553655537555385553955540555415554255543555445554555546555475554855549555505555155552555535555455555555565555755558555595556055561555625556355564555655556655567555685556955570555715557255573555745557555576555775557855579555805558155582555835558455585555865558755588555895559055591555925559355594555955559655597555985559955600556015560255603556045560555606556075560855609556105561155612556135561455615556165561755618556195562055621556225562355624556255562655627556285562955630556315563255633556345563555636556375563855639556405564155642556435564455645556465564755648556495565055651556525565355654556555565655657556585565955660556615566255663556645566555666556675566855669556705567155672556735567455675556765567755678556795568055681556825568355684556855568655687556885568955690556915569255693556945569555696556975569855699557005570155702557035570455705557065570755708557095571055711557125571355714557155571655717557185571955720557215572255723557245572555726557275572855729557305573155732557335573455735557365573755738557395574055741557425574355744557455574655747557485574955750557515575255753557545575555756557575575855759557605576155762557635576455765557665576755768557695577055771557725577355774557755577655777557785577955780557815578255783557845578555786557875578855789557905579155792557935579455795557965579755798557995580055801558025580355804558055580655807558085580955810558115581255813558145581555816558175581855819558205582155822558235582455825558265582755828558295583055831558325583355834558355583655837558385583955840558415584255843558445584555846558475584855849558505585155852558535585455855558565585755858558595586055861558625586355864558655586655867558685586955870558715587255873558745587555876558775587855879558805588155882558835588455885558865588755888558895589055891558925589355894558955589655897558985589955900559015590255903559045590555906559075590855909559105591155912559135591455915559165591755918559195592055921559225592355924559255592655927559285592955930559315593255933559345593555936559375593855939559405594155942559435594455945559465594755948559495595055951559525595355954559555595655957559585595955960559615596255963559645596555966559675596855969559705597155972559735597455975559765597755978559795598055981559825598355984559855598655987559885598955990559915599255993559945599555996559975599855999560005600156002560035600456005560065600756008560095601056011560125601356014560155601656017560185601956020560215602256023560245602556026560275602856029560305603156032560335603456035560365603756038560395604056041560425604356044560455604656047560485604956050560515605256053560545605556056560575605856059560605606156062560635606456065560665606756068560695607056071560725607356074560755607656077560785607956080560815608256083560845608556086560875608856089560905609156092560935609456095560965609756098560995610056101561025610356104561055610656107561085610956110561115611256113561145611556116561175611856119561205612156122561235612456125561265612756128561295613056131561325613356134561355613656137561385613956140561415614256143561445614556146561475614856149561505615156152561535615456155561565615756158561595616056161561625616356164561655616656167561685616956170561715617256173561745617556176561775617856179561805618156182561835618456185561865618756188561895619056191561925619356194561955619656197561985619956200562015620256203562045620556206562075620856209562105621156212562135621456215562165621756218562195622056221562225622356224562255622656227562285622956230562315623256233562345623556236562375623856239562405624156242562435624456245562465624756248562495625056251562525625356254562555625656257562585625956260562615626256263562645626556266562675626856269562705627156272562735627456275562765627756278562795628056281562825628356284562855628656287562885628956290562915629256293562945629556296562975629856299563005630156302563035630456305563065630756308563095631056311563125631356314563155631656317563185631956320563215632256323563245632556326563275632856329563305633156332563335633456335563365633756338563395634056341563425634356344563455634656347563485634956350563515635256353563545635556356563575635856359563605636156362563635636456365563665636756368563695637056371563725637356374563755637656377563785637956380563815638256383563845638556386563875638856389563905639156392563935639456395563965639756398563995640056401564025640356404564055640656407564085640956410564115641256413564145641556416564175641856419564205642156422564235642456425564265642756428564295643056431564325643356434564355643656437564385643956440564415644256443564445644556446564475644856449564505645156452564535645456455564565645756458564595646056461564625646356464564655646656467564685646956470564715647256473564745647556476564775647856479564805648156482564835648456485564865648756488564895649056491564925649356494564955649656497564985649956500565015650256503565045650556506565075650856509565105651156512565135651456515565165651756518565195652056521565225652356524565255652656527565285652956530565315653256533565345653556536565375653856539565405654156542565435654456545565465654756548565495655056551565525655356554565555655656557565585655956560565615656256563565645656556566565675656856569565705657156572565735657456575565765657756578565795658056581565825658356584565855658656587565885658956590565915659256593565945659556596565975659856599566005660156602566035660456605566065660756608566095661056611566125661356614566155661656617566185661956620566215662256623566245662556626566275662856629566305663156632566335663456635566365663756638566395664056641566425664356644566455664656647566485664956650566515665256653566545665556656566575665856659566605666156662566635666456665566665666756668566695667056671566725667356674566755667656677566785667956680566815668256683566845668556686566875668856689566905669156692566935669456695566965669756698566995670056701567025670356704567055670656707567085670956710567115671256713567145671556716567175671856719567205672156722567235672456725567265672756728567295673056731567325673356734567355673656737567385673956740567415674256743567445674556746567475674856749567505675156752567535675456755567565675756758567595676056761567625676356764567655676656767567685676956770567715677256773567745677556776567775677856779567805678156782567835678456785567865678756788567895679056791567925679356794567955679656797567985679956800568015680256803568045680556806568075680856809568105681156812568135681456815568165681756818568195682056821568225682356824568255682656827568285682956830568315683256833568345683556836568375683856839568405684156842568435684456845568465684756848568495685056851568525685356854568555685656857568585685956860568615686256863568645686556866568675686856869568705687156872568735687456875568765687756878568795688056881568825688356884568855688656887568885688956890568915689256893568945689556896568975689856899569005690156902569035690456905569065690756908569095691056911569125691356914569155691656917569185691956920569215692256923569245692556926569275692856929569305693156932569335693456935569365693756938569395694056941569425694356944569455694656947569485694956950569515695256953569545695556956569575695856959569605696156962569635696456965569665696756968569695697056971569725697356974569755697656977569785697956980569815698256983569845698556986569875698856989569905699156992569935699456995569965699756998569995700057001570025700357004570055700657007570085700957010570115701257013570145701557016570175701857019570205702157022570235702457025570265702757028570295703057031570325703357034570355703657037570385703957040570415704257043570445704557046570475704857049570505705157052570535705457055570565705757058570595706057061570625706357064570655706657067570685706957070570715707257073570745707557076570775707857079570805708157082570835708457085570865708757088570895709057091570925709357094570955709657097570985709957100571015710257103571045710557106571075710857109571105711157112571135711457115571165711757118571195712057121571225712357124571255712657127571285712957130571315713257133571345713557136571375713857139571405714157142571435714457145571465714757148571495715057151571525715357154571555715657157571585715957160571615716257163571645716557166571675716857169571705717157172571735717457175571765717757178571795718057181571825718357184571855718657187571885718957190571915719257193571945719557196571975719857199572005720157202572035720457205572065720757208572095721057211572125721357214572155721657217572185721957220572215722257223572245722557226572275722857229572305723157232572335723457235572365723757238572395724057241572425724357244572455724657247572485724957250572515725257253572545725557256572575725857259572605726157262572635726457265572665726757268572695727057271572725727357274572755727657277572785727957280572815728257283572845728557286572875728857289572905729157292572935729457295572965729757298572995730057301573025730357304573055730657307573085730957310573115731257313573145731557316573175731857319573205732157322573235732457325573265732757328573295733057331573325733357334573355733657337573385733957340573415734257343573445734557346573475734857349573505735157352573535735457355573565735757358573595736057361573625736357364573655736657367573685736957370573715737257373573745737557376573775737857379573805738157382573835738457385573865738757388573895739057391573925739357394573955739657397573985739957400574015740257403574045740557406574075740857409574105741157412574135741457415574165741757418574195742057421574225742357424574255742657427574285742957430574315743257433574345743557436574375743857439574405744157442574435744457445574465744757448574495745057451574525745357454574555745657457574585745957460574615746257463574645746557466574675746857469574705747157472574735747457475574765747757478574795748057481574825748357484574855748657487574885748957490574915749257493574945749557496574975749857499575005750157502575035750457505575065750757508575095751057511575125751357514575155751657517575185751957520575215752257523575245752557526575275752857529575305753157532575335753457535575365753757538575395754057541575425754357544575455754657547575485754957550575515755257553575545755557556575575755857559575605756157562575635756457565575665756757568575695757057571575725757357574575755757657577575785757957580575815758257583575845758557586575875758857589575905759157592575935759457595575965759757598575995760057601576025760357604576055760657607576085760957610576115761257613576145761557616576175761857619576205762157622576235762457625576265762757628576295763057631576325763357634576355763657637576385763957640576415764257643576445764557646576475764857649576505765157652576535765457655576565765757658576595766057661576625766357664576655766657667576685766957670576715767257673576745767557676576775767857679576805768157682576835768457685576865768757688576895769057691576925769357694576955769657697576985769957700577015770257703577045770557706577075770857709577105771157712577135771457715577165771757718577195772057721577225772357724577255772657727577285772957730577315773257733577345773557736577375773857739577405774157742577435774457745577465774757748577495775057751577525775357754577555775657757577585775957760577615776257763577645776557766577675776857769577705777157772577735777457775577765777757778577795778057781577825778357784577855778657787577885778957790577915779257793577945779557796577975779857799578005780157802578035780457805578065780757808578095781057811578125781357814578155781657817578185781957820578215782257823578245782557826578275782857829578305783157832578335783457835578365783757838578395784057841578425784357844578455784657847578485784957850578515785257853578545785557856578575785857859578605786157862578635786457865578665786757868578695787057871578725787357874578755787657877578785787957880578815788257883578845788557886578875788857889578905789157892578935789457895578965789757898578995790057901579025790357904579055790657907579085790957910579115791257913579145791557916579175791857919579205792157922579235792457925579265792757928579295793057931579325793357934579355793657937579385793957940579415794257943579445794557946579475794857949579505795157952579535795457955579565795757958579595796057961579625796357964579655796657967579685796957970579715797257973579745797557976579775797857979579805798157982579835798457985579865798757988579895799057991579925799357994579955799657997579985799958000580015800258003580045800558006580075800858009580105801158012580135801458015580165801758018580195802058021580225802358024580255802658027580285802958030580315803258033580345803558036580375803858039580405804158042580435804458045580465804758048580495805058051580525805358054580555805658057580585805958060580615806258063580645806558066580675806858069580705807158072580735807458075580765807758078580795808058081580825808358084580855808658087580885808958090580915809258093580945809558096580975809858099581005810158102581035810458105581065810758108581095811058111581125811358114581155811658117581185811958120581215812258123581245812558126581275812858129581305813158132581335813458135581365813758138581395814058141581425814358144581455814658147581485814958150581515815258153581545815558156581575815858159581605816158162581635816458165581665816758168581695817058171581725817358174581755817658177581785817958180581815818258183581845818558186581875818858189581905819158192581935819458195581965819758198581995820058201582025820358204582055820658207582085820958210582115821258213582145821558216582175821858219582205822158222582235822458225582265822758228582295823058231582325823358234582355823658237582385823958240582415824258243582445824558246582475824858249582505825158252582535825458255582565825758258582595826058261582625826358264582655826658267582685826958270582715827258273582745827558276582775827858279582805828158282582835828458285582865828758288582895829058291582925829358294582955829658297582985829958300583015830258303583045830558306583075830858309583105831158312583135831458315583165831758318583195832058321583225832358324583255832658327583285832958330583315833258333583345833558336583375833858339583405834158342583435834458345583465834758348583495835058351583525835358354583555835658357583585835958360583615836258363583645836558366583675836858369583705837158372583735837458375583765837758378583795838058381583825838358384583855838658387583885838958390583915839258393583945839558396583975839858399584005840158402584035840458405584065840758408584095841058411584125841358414584155841658417584185841958420584215842258423584245842558426584275842858429584305843158432584335843458435584365843758438584395844058441584425844358444584455844658447584485844958450584515845258453584545845558456584575845858459584605846158462584635846458465584665846758468584695847058471584725847358474584755847658477584785847958480584815848258483584845848558486584875848858489584905849158492584935849458495584965849758498584995850058501585025850358504585055850658507585085850958510585115851258513585145851558516585175851858519585205852158522585235852458525585265852758528585295853058531585325853358534585355853658537585385853958540585415854258543585445854558546585475854858549585505855158552585535855458555585565855758558585595856058561585625856358564585655856658567585685856958570585715857258573585745857558576585775857858579585805858158582585835858458585585865858758588585895859058591585925859358594585955859658597585985859958600586015860258603586045860558606586075860858609586105861158612586135861458615586165861758618586195862058621586225862358624586255862658627586285862958630586315863258633586345863558636586375863858639586405864158642586435864458645586465864758648586495865058651586525865358654586555865658657586585865958660586615866258663586645866558666586675866858669586705867158672586735867458675586765867758678586795868058681586825868358684586855868658687586885868958690586915869258693586945869558696586975869858699587005870158702587035870458705587065870758708587095871058711587125871358714587155871658717587185871958720587215872258723587245872558726587275872858729587305873158732587335873458735587365873758738587395874058741587425874358744587455874658747587485874958750587515875258753587545875558756587575875858759587605876158762587635876458765587665876758768587695877058771587725877358774587755877658777587785877958780587815878258783587845878558786587875878858789587905879158792587935879458795587965879758798587995880058801588025880358804588055880658807588085880958810588115881258813588145881558816588175881858819588205882158822588235882458825588265882758828588295883058831588325883358834588355883658837588385883958840588415884258843588445884558846588475884858849588505885158852588535885458855588565885758858588595886058861588625886358864588655886658867588685886958870588715887258873588745887558876588775887858879588805888158882588835888458885588865888758888588895889058891588925889358894588955889658897588985889958900589015890258903589045890558906589075890858909589105891158912589135891458915589165891758918589195892058921589225892358924589255892658927589285892958930589315893258933589345893558936589375893858939589405894158942589435894458945589465894758948589495895058951589525895358954589555895658957589585895958960589615896258963589645896558966589675896858969589705897158972589735897458975589765897758978589795898058981589825898358984589855898658987589885898958990589915899258993589945899558996589975899858999590005900159002590035900459005590065900759008590095901059011590125901359014590155901659017590185901959020590215902259023590245902559026590275902859029590305903159032590335903459035590365903759038590395904059041590425904359044590455904659047590485904959050590515905259053590545905559056590575905859059590605906159062590635906459065590665906759068590695907059071590725907359074590755907659077590785907959080590815908259083590845908559086590875908859089590905909159092590935909459095590965909759098590995910059101591025910359104591055910659107591085910959110591115911259113591145911559116591175911859119591205912159122591235912459125591265912759128591295913059131591325913359134591355913659137591385913959140591415914259143591445914559146591475914859149591505915159152591535915459155591565915759158591595916059161591625916359164591655916659167591685916959170591715917259173591745917559176591775917859179591805918159182591835918459185591865918759188591895919059191591925919359194591955919659197591985919959200592015920259203592045920559206592075920859209592105921159212592135921459215592165921759218592195922059221592225922359224592255922659227592285922959230592315923259233592345923559236592375923859239592405924159242592435924459245592465924759248592495925059251592525925359254592555925659257592585925959260592615926259263592645926559266592675926859269592705927159272592735927459275592765927759278592795928059281592825928359284592855928659287592885928959290592915929259293592945929559296592975929859299593005930159302593035930459305593065930759308593095931059311593125931359314593155931659317593185931959320593215932259323593245932559326593275932859329593305933159332593335933459335593365933759338593395934059341593425934359344593455934659347593485934959350593515935259353593545935559356593575935859359593605936159362593635936459365593665936759368593695937059371593725937359374593755937659377593785937959380593815938259383593845938559386593875938859389593905939159392593935939459395593965939759398593995940059401594025940359404594055940659407594085940959410594115941259413594145941559416594175941859419594205942159422594235942459425594265942759428594295943059431594325943359434594355943659437594385943959440594415944259443594445944559446594475944859449594505945159452594535945459455594565945759458594595946059461594625946359464594655946659467594685946959470594715947259473594745947559476594775947859479594805948159482594835948459485594865948759488594895949059491594925949359494594955949659497594985949959500595015950259503595045950559506595075950859509595105951159512595135951459515595165951759518595195952059521595225952359524595255952659527595285952959530595315953259533595345953559536595375953859539595405954159542595435954459545595465954759548595495955059551595525955359554595555955659557595585955959560595615956259563595645956559566595675956859569595705957159572595735957459575595765957759578595795958059581595825958359584595855958659587595885958959590595915959259593595945959559596595975959859599596005960159602596035960459605596065960759608596095961059611596125961359614596155961659617596185961959620596215962259623596245962559626596275962859629596305963159632596335963459635596365963759638596395964059641596425964359644596455964659647596485964959650596515965259653596545965559656596575965859659596605966159662596635966459665596665966759668596695967059671596725967359674596755967659677596785967959680596815968259683596845968559686596875968859689596905969159692596935969459695596965969759698596995970059701597025970359704597055970659707597085970959710597115971259713597145971559716597175971859719597205972159722597235972459725597265972759728597295973059731597325973359734597355973659737597385973959740597415974259743597445974559746597475974859749597505975159752597535975459755597565975759758597595976059761597625976359764597655976659767597685976959770597715977259773597745977559776597775977859779597805978159782597835978459785597865978759788597895979059791597925979359794597955979659797597985979959800598015980259803598045980559806598075980859809598105981159812598135981459815598165981759818598195982059821598225982359824598255982659827598285982959830598315983259833598345983559836598375983859839598405984159842598435984459845598465984759848598495985059851598525985359854598555985659857598585985959860598615986259863598645986559866598675986859869598705987159872598735987459875598765987759878598795988059881598825988359884598855988659887598885988959890598915989259893598945989559896598975989859899599005990159902599035990459905599065990759908599095991059911599125991359914599155991659917599185991959920599215992259923599245992559926599275992859929599305993159932599335993459935599365993759938599395994059941599425994359944599455994659947599485994959950599515995259953599545995559956599575995859959599605996159962599635996459965599665996759968599695997059971599725997359974599755997659977599785997959980599815998259983599845998559986599875998859989599905999159992599935999459995599965999759998599996000060001600026000360004600056000660007600086000960010600116001260013600146001560016600176001860019600206002160022600236002460025600266002760028600296003060031600326003360034600356003660037600386003960040600416004260043600446004560046600476004860049600506005160052600536005460055600566005760058600596006060061600626006360064600656006660067600686006960070600716007260073600746007560076600776007860079600806008160082600836008460085600866008760088600896009060091600926009360094600956009660097600986009960100601016010260103601046010560106601076010860109601106011160112601136011460115601166011760118601196012060121601226012360124601256012660127601286012960130601316013260133601346013560136601376013860139601406014160142601436014460145601466014760148601496015060151601526015360154601556015660157601586015960160601616016260163601646016560166601676016860169601706017160172601736017460175601766017760178601796018060181601826018360184601856018660187601886018960190601916019260193601946019560196601976019860199602006020160202602036020460205602066020760208602096021060211602126021360214602156021660217602186021960220602216022260223602246022560226602276022860229602306023160232602336023460235602366023760238602396024060241602426024360244602456024660247602486024960250602516025260253602546025560256602576025860259602606026160262602636026460265602666026760268602696027060271602726027360274602756027660277602786027960280602816028260283602846028560286602876028860289602906029160292602936029460295602966029760298602996030060301603026030360304603056030660307603086030960310603116031260313603146031560316603176031860319603206032160322603236032460325603266032760328603296033060331603326033360334603356033660337603386033960340603416034260343603446034560346603476034860349603506035160352603536035460355603566035760358603596036060361603626036360364603656036660367603686036960370603716037260373603746037560376603776037860379603806038160382603836038460385603866038760388603896039060391603926039360394603956039660397603986039960400604016040260403604046040560406604076040860409604106041160412604136041460415604166041760418604196042060421604226042360424604256042660427604286042960430604316043260433604346043560436604376043860439604406044160442604436044460445604466044760448604496045060451604526045360454604556045660457604586045960460604616046260463604646046560466604676046860469604706047160472604736047460475604766047760478604796048060481604826048360484604856048660487604886048960490604916049260493604946049560496604976049860499605006050160502605036050460505605066050760508605096051060511605126051360514605156051660517605186051960520605216052260523605246052560526605276052860529605306053160532605336053460535605366053760538605396054060541605426054360544605456054660547605486054960550605516055260553605546055560556605576055860559605606056160562605636056460565605666056760568605696057060571605726057360574605756057660577605786057960580605816058260583605846058560586605876058860589605906059160592605936059460595605966059760598605996060060601606026060360604606056060660607606086060960610606116061260613606146061560616606176061860619606206062160622606236062460625606266062760628606296063060631606326063360634606356063660637606386063960640606416064260643606446064560646606476064860649606506065160652606536065460655606566065760658606596066060661606626066360664606656066660667606686066960670606716067260673606746067560676606776067860679606806068160682606836068460685606866068760688606896069060691606926069360694606956069660697606986069960700607016070260703607046070560706607076070860709607106071160712607136071460715607166071760718607196072060721607226072360724607256072660727607286072960730607316073260733607346073560736607376073860739607406074160742607436074460745607466074760748607496075060751607526075360754607556075660757607586075960760607616076260763607646076560766607676076860769607706077160772607736077460775607766077760778607796078060781607826078360784607856078660787607886078960790607916079260793607946079560796607976079860799608006080160802608036080460805608066080760808608096081060811608126081360814608156081660817608186081960820608216082260823608246082560826608276082860829608306083160832608336083460835608366083760838608396084060841608426084360844608456084660847608486084960850608516085260853608546085560856608576085860859608606086160862608636086460865608666086760868608696087060871608726087360874608756087660877608786087960880608816088260883608846088560886608876088860889608906089160892608936089460895608966089760898608996090060901609026090360904609056090660907609086090960910609116091260913609146091560916609176091860919609206092160922609236092460925609266092760928609296093060931609326093360934609356093660937609386093960940609416094260943609446094560946609476094860949609506095160952609536095460955609566095760958609596096060961609626096360964609656096660967609686096960970609716097260973609746097560976609776097860979609806098160982609836098460985609866098760988609896099060991609926099360994609956099660997609986099961000610016100261003610046100561006610076100861009610106101161012610136101461015610166101761018610196102061021610226102361024610256102661027610286102961030610316103261033610346103561036610376103861039610406104161042610436104461045610466104761048610496105061051610526105361054610556105661057610586105961060610616106261063610646106561066610676106861069610706107161072610736107461075610766107761078610796108061081610826108361084610856108661087610886108961090610916109261093610946109561096610976109861099611006110161102611036110461105611066110761108611096111061111611126111361114611156111661117611186111961120611216112261123611246112561126611276112861129611306113161132611336113461135611366113761138611396114061141611426114361144611456114661147611486114961150611516115261153611546115561156611576115861159611606116161162611636116461165611666116761168611696117061171611726117361174611756117661177611786117961180611816118261183611846118561186611876118861189611906119161192611936119461195611966119761198611996120061201612026120361204612056120661207612086120961210612116121261213612146121561216612176121861219612206122161222612236122461225612266122761228612296123061231612326123361234612356123661237612386123961240612416124261243612446124561246612476124861249612506125161252612536125461255612566125761258612596126061261612626126361264612656126661267612686126961270612716127261273612746127561276612776127861279612806128161282612836128461285612866128761288612896129061291612926129361294612956129661297612986129961300613016130261303613046130561306613076130861309613106131161312613136131461315613166131761318613196132061321613226132361324613256132661327613286132961330613316133261333613346133561336613376133861339613406134161342613436134461345613466134761348613496135061351613526135361354613556135661357613586135961360613616136261363613646136561366613676136861369613706137161372613736137461375613766137761378613796138061381613826138361384613856138661387613886138961390613916139261393613946139561396613976139861399614006140161402614036140461405614066140761408614096141061411614126141361414614156141661417614186141961420614216142261423614246142561426614276142861429614306143161432614336143461435614366143761438614396144061441614426144361444614456144661447614486144961450614516145261453614546145561456614576145861459614606146161462614636146461465614666146761468614696147061471614726147361474614756147661477614786147961480614816148261483614846148561486614876148861489614906149161492614936149461495614966149761498614996150061501615026150361504615056150661507615086150961510615116151261513615146151561516615176151861519615206152161522615236152461525615266152761528615296153061531615326153361534615356153661537615386153961540615416154261543615446154561546615476154861549615506155161552615536155461555615566155761558615596156061561615626156361564615656156661567615686156961570615716157261573615746157561576615776157861579615806158161582615836158461585615866158761588615896159061591615926159361594615956159661597615986159961600616016160261603616046160561606616076160861609616106161161612616136161461615616166161761618616196162061621616226162361624616256162661627616286162961630616316163261633616346163561636616376163861639616406164161642616436164461645616466164761648616496165061651616526165361654616556165661657616586165961660616616166261663616646166561666616676166861669616706167161672616736167461675616766167761678616796168061681616826168361684616856168661687616886168961690616916169261693616946169561696616976169861699617006170161702617036170461705617066170761708617096171061711617126171361714617156171661717617186171961720617216172261723617246172561726617276172861729617306173161732617336173461735617366173761738617396174061741617426174361744617456174661747617486174961750617516175261753617546175561756617576175861759617606176161762617636176461765617666176761768617696177061771617726177361774617756177661777
  1. /* Copyright 2012 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. (function (root, factory) {
  16. 'use strict';
  17. if (typeof define === 'function' && define.amd) {
  18. define('pdfjs-dist/build/pdf.combined', ['exports'], factory);
  19. } else if (typeof exports !== 'undefined') {
  20. factory(exports);
  21. } else {
  22. factory(root['pdfjsDistBuildPdfCombined'] = {});
  23. }
  24. }(this, function (exports) {
  25. // Use strict in our context only - users might not want it
  26. 'use strict';
  27. var pdfjsVersion = '1.6.250';
  28. var pdfjsBuild = '960e344';
  29. var pdfjsFilePath = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : null;
  30. var pdfjsLibs = {};
  31. (function pdfjsWrapper() {
  32. (function (root, factory) {
  33. factory(root.pdfjsCoreArithmeticDecoder = {});
  34. }(this, function (exports) {
  35. /* This class implements the QM Coder decoding as defined in
  36. * JPEG 2000 Part I Final Committee Draft Version 1.0
  37. * Annex C.3 Arithmetic decoding procedure
  38. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  39. *
  40. * The arithmetic decoder is used in conjunction with context models to decode
  41. * JPEG2000 and JBIG2 streams.
  42. */
  43. var ArithmeticDecoder = function ArithmeticDecoderClosure() {
  44. // Table C-2
  45. var QeTable = [
  46. {
  47. qe: 0x5601,
  48. nmps: 1,
  49. nlps: 1,
  50. switchFlag: 1
  51. },
  52. {
  53. qe: 0x3401,
  54. nmps: 2,
  55. nlps: 6,
  56. switchFlag: 0
  57. },
  58. {
  59. qe: 0x1801,
  60. nmps: 3,
  61. nlps: 9,
  62. switchFlag: 0
  63. },
  64. {
  65. qe: 0x0AC1,
  66. nmps: 4,
  67. nlps: 12,
  68. switchFlag: 0
  69. },
  70. {
  71. qe: 0x0521,
  72. nmps: 5,
  73. nlps: 29,
  74. switchFlag: 0
  75. },
  76. {
  77. qe: 0x0221,
  78. nmps: 38,
  79. nlps: 33,
  80. switchFlag: 0
  81. },
  82. {
  83. qe: 0x5601,
  84. nmps: 7,
  85. nlps: 6,
  86. switchFlag: 1
  87. },
  88. {
  89. qe: 0x5401,
  90. nmps: 8,
  91. nlps: 14,
  92. switchFlag: 0
  93. },
  94. {
  95. qe: 0x4801,
  96. nmps: 9,
  97. nlps: 14,
  98. switchFlag: 0
  99. },
  100. {
  101. qe: 0x3801,
  102. nmps: 10,
  103. nlps: 14,
  104. switchFlag: 0
  105. },
  106. {
  107. qe: 0x3001,
  108. nmps: 11,
  109. nlps: 17,
  110. switchFlag: 0
  111. },
  112. {
  113. qe: 0x2401,
  114. nmps: 12,
  115. nlps: 18,
  116. switchFlag: 0
  117. },
  118. {
  119. qe: 0x1C01,
  120. nmps: 13,
  121. nlps: 20,
  122. switchFlag: 0
  123. },
  124. {
  125. qe: 0x1601,
  126. nmps: 29,
  127. nlps: 21,
  128. switchFlag: 0
  129. },
  130. {
  131. qe: 0x5601,
  132. nmps: 15,
  133. nlps: 14,
  134. switchFlag: 1
  135. },
  136. {
  137. qe: 0x5401,
  138. nmps: 16,
  139. nlps: 14,
  140. switchFlag: 0
  141. },
  142. {
  143. qe: 0x5101,
  144. nmps: 17,
  145. nlps: 15,
  146. switchFlag: 0
  147. },
  148. {
  149. qe: 0x4801,
  150. nmps: 18,
  151. nlps: 16,
  152. switchFlag: 0
  153. },
  154. {
  155. qe: 0x3801,
  156. nmps: 19,
  157. nlps: 17,
  158. switchFlag: 0
  159. },
  160. {
  161. qe: 0x3401,
  162. nmps: 20,
  163. nlps: 18,
  164. switchFlag: 0
  165. },
  166. {
  167. qe: 0x3001,
  168. nmps: 21,
  169. nlps: 19,
  170. switchFlag: 0
  171. },
  172. {
  173. qe: 0x2801,
  174. nmps: 22,
  175. nlps: 19,
  176. switchFlag: 0
  177. },
  178. {
  179. qe: 0x2401,
  180. nmps: 23,
  181. nlps: 20,
  182. switchFlag: 0
  183. },
  184. {
  185. qe: 0x2201,
  186. nmps: 24,
  187. nlps: 21,
  188. switchFlag: 0
  189. },
  190. {
  191. qe: 0x1C01,
  192. nmps: 25,
  193. nlps: 22,
  194. switchFlag: 0
  195. },
  196. {
  197. qe: 0x1801,
  198. nmps: 26,
  199. nlps: 23,
  200. switchFlag: 0
  201. },
  202. {
  203. qe: 0x1601,
  204. nmps: 27,
  205. nlps: 24,
  206. switchFlag: 0
  207. },
  208. {
  209. qe: 0x1401,
  210. nmps: 28,
  211. nlps: 25,
  212. switchFlag: 0
  213. },
  214. {
  215. qe: 0x1201,
  216. nmps: 29,
  217. nlps: 26,
  218. switchFlag: 0
  219. },
  220. {
  221. qe: 0x1101,
  222. nmps: 30,
  223. nlps: 27,
  224. switchFlag: 0
  225. },
  226. {
  227. qe: 0x0AC1,
  228. nmps: 31,
  229. nlps: 28,
  230. switchFlag: 0
  231. },
  232. {
  233. qe: 0x09C1,
  234. nmps: 32,
  235. nlps: 29,
  236. switchFlag: 0
  237. },
  238. {
  239. qe: 0x08A1,
  240. nmps: 33,
  241. nlps: 30,
  242. switchFlag: 0
  243. },
  244. {
  245. qe: 0x0521,
  246. nmps: 34,
  247. nlps: 31,
  248. switchFlag: 0
  249. },
  250. {
  251. qe: 0x0441,
  252. nmps: 35,
  253. nlps: 32,
  254. switchFlag: 0
  255. },
  256. {
  257. qe: 0x02A1,
  258. nmps: 36,
  259. nlps: 33,
  260. switchFlag: 0
  261. },
  262. {
  263. qe: 0x0221,
  264. nmps: 37,
  265. nlps: 34,
  266. switchFlag: 0
  267. },
  268. {
  269. qe: 0x0141,
  270. nmps: 38,
  271. nlps: 35,
  272. switchFlag: 0
  273. },
  274. {
  275. qe: 0x0111,
  276. nmps: 39,
  277. nlps: 36,
  278. switchFlag: 0
  279. },
  280. {
  281. qe: 0x0085,
  282. nmps: 40,
  283. nlps: 37,
  284. switchFlag: 0
  285. },
  286. {
  287. qe: 0x0049,
  288. nmps: 41,
  289. nlps: 38,
  290. switchFlag: 0
  291. },
  292. {
  293. qe: 0x0025,
  294. nmps: 42,
  295. nlps: 39,
  296. switchFlag: 0
  297. },
  298. {
  299. qe: 0x0015,
  300. nmps: 43,
  301. nlps: 40,
  302. switchFlag: 0
  303. },
  304. {
  305. qe: 0x0009,
  306. nmps: 44,
  307. nlps: 41,
  308. switchFlag: 0
  309. },
  310. {
  311. qe: 0x0005,
  312. nmps: 45,
  313. nlps: 42,
  314. switchFlag: 0
  315. },
  316. {
  317. qe: 0x0001,
  318. nmps: 45,
  319. nlps: 43,
  320. switchFlag: 0
  321. },
  322. {
  323. qe: 0x5601,
  324. nmps: 46,
  325. nlps: 46,
  326. switchFlag: 0
  327. }
  328. ];
  329. // C.3.5 Initialisation of the decoder (INITDEC)
  330. function ArithmeticDecoder(data, start, end) {
  331. this.data = data;
  332. this.bp = start;
  333. this.dataEnd = end;
  334. this.chigh = data[start];
  335. this.clow = 0;
  336. this.byteIn();
  337. this.chigh = this.chigh << 7 & 0xFFFF | this.clow >> 9 & 0x7F;
  338. this.clow = this.clow << 7 & 0xFFFF;
  339. this.ct -= 7;
  340. this.a = 0x8000;
  341. }
  342. ArithmeticDecoder.prototype = {
  343. // C.3.4 Compressed data input (BYTEIN)
  344. byteIn: function ArithmeticDecoder_byteIn() {
  345. var data = this.data;
  346. var bp = this.bp;
  347. if (data[bp] === 0xFF) {
  348. var b1 = data[bp + 1];
  349. if (b1 > 0x8F) {
  350. this.clow += 0xFF00;
  351. this.ct = 8;
  352. } else {
  353. bp++;
  354. this.clow += data[bp] << 9;
  355. this.ct = 7;
  356. this.bp = bp;
  357. }
  358. } else {
  359. bp++;
  360. this.clow += bp < this.dataEnd ? data[bp] << 8 : 0xFF00;
  361. this.ct = 8;
  362. this.bp = bp;
  363. }
  364. if (this.clow > 0xFFFF) {
  365. this.chigh += this.clow >> 16;
  366. this.clow &= 0xFFFF;
  367. }
  368. },
  369. // C.3.2 Decoding a decision (DECODE)
  370. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  371. // contexts are packed into 1 byte:
  372. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  373. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  374. var qeTableIcx = QeTable[cx_index];
  375. var qeIcx = qeTableIcx.qe;
  376. var d;
  377. var a = this.a - qeIcx;
  378. if (this.chigh < qeIcx) {
  379. // exchangeLps
  380. if (a < qeIcx) {
  381. a = qeIcx;
  382. d = cx_mps;
  383. cx_index = qeTableIcx.nmps;
  384. } else {
  385. a = qeIcx;
  386. d = 1 ^ cx_mps;
  387. if (qeTableIcx.switchFlag === 1) {
  388. cx_mps = d;
  389. }
  390. cx_index = qeTableIcx.nlps;
  391. }
  392. } else {
  393. this.chigh -= qeIcx;
  394. if ((a & 0x8000) !== 0) {
  395. this.a = a;
  396. return cx_mps;
  397. }
  398. // exchangeMps
  399. if (a < qeIcx) {
  400. d = 1 ^ cx_mps;
  401. if (qeTableIcx.switchFlag === 1) {
  402. cx_mps = d;
  403. }
  404. cx_index = qeTableIcx.nlps;
  405. } else {
  406. d = cx_mps;
  407. cx_index = qeTableIcx.nmps;
  408. }
  409. }
  410. // C.3.3 renormD;
  411. do {
  412. if (this.ct === 0) {
  413. this.byteIn();
  414. }
  415. a <<= 1;
  416. this.chigh = this.chigh << 1 & 0xFFFF | this.clow >> 15 & 1;
  417. this.clow = this.clow << 1 & 0xFFFF;
  418. this.ct--;
  419. } while ((a & 0x8000) === 0);
  420. this.a = a;
  421. contexts[pos] = cx_index << 1 | cx_mps;
  422. return d;
  423. }
  424. };
  425. return ArithmeticDecoder;
  426. }();
  427. exports.ArithmeticDecoder = ArithmeticDecoder;
  428. }));
  429. (function (root, factory) {
  430. factory(root.pdfjsCoreBidi = {});
  431. }(this, function (exports) {
  432. // Character types for symbols from 0000 to 00FF.
  433. var baseTypes = [
  434. 'BN',
  435. 'BN',
  436. 'BN',
  437. 'BN',
  438. 'BN',
  439. 'BN',
  440. 'BN',
  441. 'BN',
  442. 'BN',
  443. 'S',
  444. 'B',
  445. 'S',
  446. 'WS',
  447. 'B',
  448. 'BN',
  449. 'BN',
  450. 'BN',
  451. 'BN',
  452. 'BN',
  453. 'BN',
  454. 'BN',
  455. 'BN',
  456. 'BN',
  457. 'BN',
  458. 'BN',
  459. 'BN',
  460. 'BN',
  461. 'BN',
  462. 'B',
  463. 'B',
  464. 'B',
  465. 'S',
  466. 'WS',
  467. 'ON',
  468. 'ON',
  469. 'ET',
  470. 'ET',
  471. 'ET',
  472. 'ON',
  473. 'ON',
  474. 'ON',
  475. 'ON',
  476. 'ON',
  477. 'ON',
  478. 'CS',
  479. 'ON',
  480. 'CS',
  481. 'ON',
  482. 'EN',
  483. 'EN',
  484. 'EN',
  485. 'EN',
  486. 'EN',
  487. 'EN',
  488. 'EN',
  489. 'EN',
  490. 'EN',
  491. 'EN',
  492. 'ON',
  493. 'ON',
  494. 'ON',
  495. 'ON',
  496. 'ON',
  497. 'ON',
  498. 'ON',
  499. 'L',
  500. 'L',
  501. 'L',
  502. 'L',
  503. 'L',
  504. 'L',
  505. 'L',
  506. 'L',
  507. 'L',
  508. 'L',
  509. 'L',
  510. 'L',
  511. 'L',
  512. 'L',
  513. 'L',
  514. 'L',
  515. 'L',
  516. 'L',
  517. 'L',
  518. 'L',
  519. 'L',
  520. 'L',
  521. 'L',
  522. 'L',
  523. 'L',
  524. 'L',
  525. 'ON',
  526. 'ON',
  527. 'ON',
  528. 'ON',
  529. 'ON',
  530. 'ON',
  531. 'L',
  532. 'L',
  533. 'L',
  534. 'L',
  535. 'L',
  536. 'L',
  537. 'L',
  538. 'L',
  539. 'L',
  540. 'L',
  541. 'L',
  542. 'L',
  543. 'L',
  544. 'L',
  545. 'L',
  546. 'L',
  547. 'L',
  548. 'L',
  549. 'L',
  550. 'L',
  551. 'L',
  552. 'L',
  553. 'L',
  554. 'L',
  555. 'L',
  556. 'L',
  557. 'ON',
  558. 'ON',
  559. 'ON',
  560. 'ON',
  561. 'BN',
  562. 'BN',
  563. 'BN',
  564. 'BN',
  565. 'BN',
  566. 'BN',
  567. 'B',
  568. 'BN',
  569. 'BN',
  570. 'BN',
  571. 'BN',
  572. 'BN',
  573. 'BN',
  574. 'BN',
  575. 'BN',
  576. 'BN',
  577. 'BN',
  578. 'BN',
  579. 'BN',
  580. 'BN',
  581. 'BN',
  582. 'BN',
  583. 'BN',
  584. 'BN',
  585. 'BN',
  586. 'BN',
  587. 'BN',
  588. 'BN',
  589. 'BN',
  590. 'BN',
  591. 'BN',
  592. 'BN',
  593. 'BN',
  594. 'CS',
  595. 'ON',
  596. 'ET',
  597. 'ET',
  598. 'ET',
  599. 'ET',
  600. 'ON',
  601. 'ON',
  602. 'ON',
  603. 'ON',
  604. 'L',
  605. 'ON',
  606. 'ON',
  607. 'ON',
  608. 'ON',
  609. 'ON',
  610. 'ET',
  611. 'ET',
  612. 'EN',
  613. 'EN',
  614. 'ON',
  615. 'L',
  616. 'ON',
  617. 'ON',
  618. 'ON',
  619. 'EN',
  620. 'L',
  621. 'ON',
  622. 'ON',
  623. 'ON',
  624. 'ON',
  625. 'ON',
  626. 'L',
  627. 'L',
  628. 'L',
  629. 'L',
  630. 'L',
  631. 'L',
  632. 'L',
  633. 'L',
  634. 'L',
  635. 'L',
  636. 'L',
  637. 'L',
  638. 'L',
  639. 'L',
  640. 'L',
  641. 'L',
  642. 'L',
  643. 'L',
  644. 'L',
  645. 'L',
  646. 'L',
  647. 'L',
  648. 'L',
  649. 'ON',
  650. 'L',
  651. 'L',
  652. 'L',
  653. 'L',
  654. 'L',
  655. 'L',
  656. 'L',
  657. 'L',
  658. 'L',
  659. 'L',
  660. 'L',
  661. 'L',
  662. 'L',
  663. 'L',
  664. 'L',
  665. 'L',
  666. 'L',
  667. 'L',
  668. 'L',
  669. 'L',
  670. 'L',
  671. 'L',
  672. 'L',
  673. 'L',
  674. 'L',
  675. 'L',
  676. 'L',
  677. 'L',
  678. 'L',
  679. 'L',
  680. 'L',
  681. 'ON',
  682. 'L',
  683. 'L',
  684. 'L',
  685. 'L',
  686. 'L',
  687. 'L',
  688. 'L',
  689. 'L'
  690. ];
  691. // Character types for symbols from 0600 to 06FF
  692. var arabicTypes = [
  693. 'AL',
  694. 'AL',
  695. 'AL',
  696. 'AL',
  697. 'AL',
  698. 'AL',
  699. 'AL',
  700. 'AL',
  701. 'AL',
  702. 'AL',
  703. 'AL',
  704. 'AL',
  705. 'CS',
  706. 'AL',
  707. 'ON',
  708. 'ON',
  709. 'NSM',
  710. 'NSM',
  711. 'NSM',
  712. 'NSM',
  713. 'NSM',
  714. 'NSM',
  715. 'AL',
  716. 'AL',
  717. 'AL',
  718. 'AL',
  719. 'AL',
  720. 'AL',
  721. 'AL',
  722. 'AL',
  723. 'AL',
  724. 'AL',
  725. 'AL',
  726. 'AL',
  727. 'AL',
  728. 'AL',
  729. 'AL',
  730. 'AL',
  731. 'AL',
  732. 'AL',
  733. 'AL',
  734. 'AL',
  735. 'AL',
  736. 'AL',
  737. 'AL',
  738. 'AL',
  739. 'AL',
  740. 'AL',
  741. 'AL',
  742. 'AL',
  743. 'AL',
  744. 'AL',
  745. 'AL',
  746. 'AL',
  747. 'AL',
  748. 'AL',
  749. 'AL',
  750. 'AL',
  751. 'AL',
  752. 'AL',
  753. 'AL',
  754. 'AL',
  755. 'AL',
  756. 'AL',
  757. 'AL',
  758. 'AL',
  759. 'AL',
  760. 'AL',
  761. 'AL',
  762. 'AL',
  763. 'AL',
  764. 'AL',
  765. 'AL',
  766. 'AL',
  767. 'AL',
  768. 'NSM',
  769. 'NSM',
  770. 'NSM',
  771. 'NSM',
  772. 'NSM',
  773. 'NSM',
  774. 'NSM',
  775. 'NSM',
  776. 'NSM',
  777. 'NSM',
  778. 'NSM',
  779. 'NSM',
  780. 'NSM',
  781. 'NSM',
  782. 'AL',
  783. 'AL',
  784. 'AL',
  785. 'AL',
  786. 'AL',
  787. 'AL',
  788. 'AL',
  789. 'AN',
  790. 'AN',
  791. 'AN',
  792. 'AN',
  793. 'AN',
  794. 'AN',
  795. 'AN',
  796. 'AN',
  797. 'AN',
  798. 'AN',
  799. 'ET',
  800. 'AN',
  801. 'AN',
  802. 'AL',
  803. 'AL',
  804. 'AL',
  805. 'NSM',
  806. 'AL',
  807. 'AL',
  808. 'AL',
  809. 'AL',
  810. 'AL',
  811. 'AL',
  812. 'AL',
  813. 'AL',
  814. 'AL',
  815. 'AL',
  816. 'AL',
  817. 'AL',
  818. 'AL',
  819. 'AL',
  820. 'AL',
  821. 'AL',
  822. 'AL',
  823. 'AL',
  824. 'AL',
  825. 'AL',
  826. 'AL',
  827. 'AL',
  828. 'AL',
  829. 'AL',
  830. 'AL',
  831. 'AL',
  832. 'AL',
  833. 'AL',
  834. 'AL',
  835. 'AL',
  836. 'AL',
  837. 'AL',
  838. 'AL',
  839. 'AL',
  840. 'AL',
  841. 'AL',
  842. 'AL',
  843. 'AL',
  844. 'AL',
  845. 'AL',
  846. 'AL',
  847. 'AL',
  848. 'AL',
  849. 'AL',
  850. 'AL',
  851. 'AL',
  852. 'AL',
  853. 'AL',
  854. 'AL',
  855. 'AL',
  856. 'AL',
  857. 'AL',
  858. 'AL',
  859. 'AL',
  860. 'AL',
  861. 'AL',
  862. 'AL',
  863. 'AL',
  864. 'AL',
  865. 'AL',
  866. 'AL',
  867. 'AL',
  868. 'AL',
  869. 'AL',
  870. 'AL',
  871. 'AL',
  872. 'AL',
  873. 'AL',
  874. 'AL',
  875. 'AL',
  876. 'AL',
  877. 'AL',
  878. 'AL',
  879. 'AL',
  880. 'AL',
  881. 'AL',
  882. 'AL',
  883. 'AL',
  884. 'AL',
  885. 'AL',
  886. 'AL',
  887. 'AL',
  888. 'AL',
  889. 'AL',
  890. 'AL',
  891. 'AL',
  892. 'AL',
  893. 'AL',
  894. 'AL',
  895. 'AL',
  896. 'AL',
  897. 'AL',
  898. 'AL',
  899. 'AL',
  900. 'AL',
  901. 'AL',
  902. 'AL',
  903. 'AL',
  904. 'AL',
  905. 'AL',
  906. 'AL',
  907. 'NSM',
  908. 'NSM',
  909. 'NSM',
  910. 'NSM',
  911. 'NSM',
  912. 'NSM',
  913. 'NSM',
  914. 'NSM',
  915. 'NSM',
  916. 'NSM',
  917. 'NSM',
  918. 'NSM',
  919. 'NSM',
  920. 'NSM',
  921. 'NSM',
  922. 'NSM',
  923. 'NSM',
  924. 'NSM',
  925. 'NSM',
  926. 'ON',
  927. 'NSM',
  928. 'NSM',
  929. 'NSM',
  930. 'NSM',
  931. 'AL',
  932. 'AL',
  933. 'AL',
  934. 'AL',
  935. 'AL',
  936. 'AL',
  937. 'AL',
  938. 'AL',
  939. 'AL',
  940. 'AL',
  941. 'AL',
  942. 'AL',
  943. 'AL',
  944. 'AL',
  945. 'AL',
  946. 'AL',
  947. 'AL',
  948. 'AL'
  949. ];
  950. function isOdd(i) {
  951. return (i & 1) !== 0;
  952. }
  953. function isEven(i) {
  954. return (i & 1) === 0;
  955. }
  956. function findUnequal(arr, start, value) {
  957. for (var j = start, jj = arr.length; j < jj; ++j) {
  958. if (arr[j] !== value) {
  959. return j;
  960. }
  961. }
  962. return j;
  963. }
  964. function setValues(arr, start, end, value) {
  965. for (var j = start; j < end; ++j) {
  966. arr[j] = value;
  967. }
  968. }
  969. function reverseValues(arr, start, end) {
  970. for (var i = start, j = end - 1; i < j; ++i, --j) {
  971. var temp = arr[i];
  972. arr[i] = arr[j];
  973. arr[j] = temp;
  974. }
  975. }
  976. function createBidiText(str, isLTR, vertical) {
  977. return {
  978. str: str,
  979. dir: vertical ? 'ttb' : isLTR ? 'ltr' : 'rtl'
  980. };
  981. }
  982. // These are used in bidi(), which is called frequently. We re-use them on
  983. // each call to avoid unnecessary allocations.
  984. var chars = [];
  985. var types = [];
  986. function bidi(str, startLevel, vertical) {
  987. var isLTR = true;
  988. var strLength = str.length;
  989. if (strLength === 0 || vertical) {
  990. return createBidiText(str, isLTR, vertical);
  991. }
  992. // Get types and fill arrays
  993. chars.length = strLength;
  994. types.length = strLength;
  995. var numBidi = 0;
  996. var i, ii;
  997. for (i = 0; i < strLength; ++i) {
  998. chars[i] = str.charAt(i);
  999. var charCode = str.charCodeAt(i);
  1000. var charType = 'L';
  1001. if (charCode <= 0x00ff) {
  1002. charType = baseTypes[charCode];
  1003. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  1004. charType = 'R';
  1005. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  1006. charType = arabicTypes[charCode & 0xff];
  1007. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  1008. charType = 'AL';
  1009. }
  1010. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  1011. numBidi++;
  1012. }
  1013. types[i] = charType;
  1014. }
  1015. // Detect the bidi method
  1016. // - If there are no rtl characters then no bidi needed
  1017. // - If less than 30% chars are rtl then string is primarily ltr
  1018. // - If more than 30% chars are rtl then string is primarily rtl
  1019. if (numBidi === 0) {
  1020. isLTR = true;
  1021. return createBidiText(str, isLTR);
  1022. }
  1023. if (startLevel === -1) {
  1024. if (strLength / numBidi < 0.3) {
  1025. isLTR = true;
  1026. startLevel = 0;
  1027. } else {
  1028. isLTR = false;
  1029. startLevel = 1;
  1030. }
  1031. }
  1032. var levels = [];
  1033. for (i = 0; i < strLength; ++i) {
  1034. levels[i] = startLevel;
  1035. }
  1036. /*
  1037. X1-X10: skip most of this, since we are NOT doing the embeddings.
  1038. */
  1039. var e = isOdd(startLevel) ? 'R' : 'L';
  1040. var sor = e;
  1041. var eor = sor;
  1042. /*
  1043. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  1044. type of the NSM to the type of the previous character. If the NSM is at the
  1045. start of the level run, it will get the type of sor.
  1046. */
  1047. var lastType = sor;
  1048. for (i = 0; i < strLength; ++i) {
  1049. if (types[i] === 'NSM') {
  1050. types[i] = lastType;
  1051. } else {
  1052. lastType = types[i];
  1053. }
  1054. }
  1055. /*
  1056. W2. Search backwards from each instance of a European number until the
  1057. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  1058. the type of the European number to Arabic number.
  1059. */
  1060. lastType = sor;
  1061. var t;
  1062. for (i = 0; i < strLength; ++i) {
  1063. t = types[i];
  1064. if (t === 'EN') {
  1065. types[i] = lastType === 'AL' ? 'AN' : 'EN';
  1066. } else if (t === 'R' || t === 'L' || t === 'AL') {
  1067. lastType = t;
  1068. }
  1069. }
  1070. /*
  1071. W3. Change all ALs to R.
  1072. */
  1073. for (i = 0; i < strLength; ++i) {
  1074. t = types[i];
  1075. if (t === 'AL') {
  1076. types[i] = 'R';
  1077. }
  1078. }
  1079. /*
  1080. W4. A single European separator between two European numbers changes to a
  1081. European number. A single common separator between two numbers of the same
  1082. type changes to that type:
  1083. */
  1084. for (i = 1; i < strLength - 1; ++i) {
  1085. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  1086. types[i] = 'EN';
  1087. }
  1088. if (types[i] === 'CS' && (types[i - 1] === 'EN' || types[i - 1] === 'AN') && types[i + 1] === types[i - 1]) {
  1089. types[i] = types[i - 1];
  1090. }
  1091. }
  1092. /*
  1093. W5. A sequence of European terminators adjacent to European numbers changes
  1094. to all European numbers:
  1095. */
  1096. for (i = 0; i < strLength; ++i) {
  1097. if (types[i] === 'EN') {
  1098. // do before
  1099. var j;
  1100. for (j = i - 1; j >= 0; --j) {
  1101. if (types[j] !== 'ET') {
  1102. break;
  1103. }
  1104. types[j] = 'EN';
  1105. }
  1106. // do after
  1107. for (j = i + 1; j < strLength; ++j) {
  1108. if (types[j] !== 'ET') {
  1109. break;
  1110. }
  1111. types[j] = 'EN';
  1112. }
  1113. }
  1114. }
  1115. /*
  1116. W6. Otherwise, separators and terminators change to Other Neutral:
  1117. */
  1118. for (i = 0; i < strLength; ++i) {
  1119. t = types[i];
  1120. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  1121. types[i] = 'ON';
  1122. }
  1123. }
  1124. /*
  1125. W7. Search backwards from each instance of a European number until the
  1126. first strong type (R, L, or sor) is found. If an L is found, then change
  1127. the type of the European number to L.
  1128. */
  1129. lastType = sor;
  1130. for (i = 0; i < strLength; ++i) {
  1131. t = types[i];
  1132. if (t === 'EN') {
  1133. types[i] = lastType === 'L' ? 'L' : 'EN';
  1134. } else if (t === 'R' || t === 'L') {
  1135. lastType = t;
  1136. }
  1137. }
  1138. /*
  1139. N1. A sequence of neutrals takes the direction of the surrounding strong
  1140. text if the text on both sides has the same direction. European and Arabic
  1141. numbers are treated as though they were R. Start-of-level-run (sor) and
  1142. end-of-level-run (eor) are used at level run boundaries.
  1143. */
  1144. for (i = 0; i < strLength; ++i) {
  1145. if (types[i] === 'ON') {
  1146. var end = findUnequal(types, i + 1, 'ON');
  1147. var before = sor;
  1148. if (i > 0) {
  1149. before = types[i - 1];
  1150. }
  1151. var after = eor;
  1152. if (end + 1 < strLength) {
  1153. after = types[end + 1];
  1154. }
  1155. if (before !== 'L') {
  1156. before = 'R';
  1157. }
  1158. if (after !== 'L') {
  1159. after = 'R';
  1160. }
  1161. if (before === after) {
  1162. setValues(types, i, end, before);
  1163. }
  1164. i = end - 1;
  1165. }
  1166. }
  1167. // reset to end (-1 so next iteration is ok)
  1168. /*
  1169. N2. Any remaining neutrals take the embedding direction.
  1170. */
  1171. for (i = 0; i < strLength; ++i) {
  1172. if (types[i] === 'ON') {
  1173. types[i] = e;
  1174. }
  1175. }
  1176. /*
  1177. I1. For all characters with an even (left-to-right) embedding direction,
  1178. those of type R go up one level and those of type AN or EN go up two
  1179. levels.
  1180. I2. For all characters with an odd (right-to-left) embedding direction,
  1181. those of type L, EN or AN go up one level.
  1182. */
  1183. for (i = 0; i < strLength; ++i) {
  1184. t = types[i];
  1185. if (isEven(levels[i])) {
  1186. if (t === 'R') {
  1187. levels[i] += 1;
  1188. } else if (t === 'AN' || t === 'EN') {
  1189. levels[i] += 2;
  1190. }
  1191. } else {
  1192. // isOdd
  1193. if (t === 'L' || t === 'AN' || t === 'EN') {
  1194. levels[i] += 1;
  1195. }
  1196. }
  1197. }
  1198. /*
  1199. L1. On each line, reset the embedding level of the following characters to
  1200. the paragraph embedding level:
  1201. segment separators,
  1202. paragraph separators,
  1203. any sequence of whitespace characters preceding a segment separator or
  1204. paragraph separator, and any sequence of white space characters at the end
  1205. of the line.
  1206. */
  1207. // don't bother as text is only single line
  1208. /*
  1209. L2. From the highest level found in the text to the lowest odd level on
  1210. each line, reverse any contiguous sequence of characters that are at that
  1211. level or higher.
  1212. */
  1213. // find highest level & lowest odd level
  1214. var highestLevel = -1;
  1215. var lowestOddLevel = 99;
  1216. var level;
  1217. for (i = 0, ii = levels.length; i < ii; ++i) {
  1218. level = levels[i];
  1219. if (highestLevel < level) {
  1220. highestLevel = level;
  1221. }
  1222. if (lowestOddLevel > level && isOdd(level)) {
  1223. lowestOddLevel = level;
  1224. }
  1225. }
  1226. // now reverse between those limits
  1227. for (level = highestLevel; level >= lowestOddLevel; --level) {
  1228. // find segments to reverse
  1229. var start = -1;
  1230. for (i = 0, ii = levels.length; i < ii; ++i) {
  1231. if (levels[i] < level) {
  1232. if (start >= 0) {
  1233. reverseValues(chars, start, i);
  1234. start = -1;
  1235. }
  1236. } else if (start < 0) {
  1237. start = i;
  1238. }
  1239. }
  1240. if (start >= 0) {
  1241. reverseValues(chars, start, levels.length);
  1242. }
  1243. }
  1244. /*
  1245. L3. Combining marks applied to a right-to-left base character will at this
  1246. point precede their base character. If the rendering engine expects them to
  1247. follow the base characters in the final display process, then the ordering
  1248. of the marks and the base character must be reversed.
  1249. */
  1250. // don't bother for now
  1251. /*
  1252. L4. A character that possesses the mirrored property as specified by
  1253. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  1254. directionality of that character is R.
  1255. */
  1256. // don't mirror as characters are already mirrored in the pdf
  1257. // Finally, return string
  1258. for (i = 0, ii = chars.length; i < ii; ++i) {
  1259. var ch = chars[i];
  1260. if (ch === '<' || ch === '>') {
  1261. chars[i] = '';
  1262. }
  1263. }
  1264. return createBidiText(chars.join(''), isLTR);
  1265. }
  1266. exports.bidi = bidi;
  1267. }));
  1268. (function (root, factory) {
  1269. factory(root.pdfjsCoreCharsets = {});
  1270. }(this, function (exports) {
  1271. var ISOAdobeCharset = [
  1272. '.notdef',
  1273. 'space',
  1274. 'exclam',
  1275. 'quotedbl',
  1276. 'numbersign',
  1277. 'dollar',
  1278. 'percent',
  1279. 'ampersand',
  1280. 'quoteright',
  1281. 'parenleft',
  1282. 'parenright',
  1283. 'asterisk',
  1284. 'plus',
  1285. 'comma',
  1286. 'hyphen',
  1287. 'period',
  1288. 'slash',
  1289. 'zero',
  1290. 'one',
  1291. 'two',
  1292. 'three',
  1293. 'four',
  1294. 'five',
  1295. 'six',
  1296. 'seven',
  1297. 'eight',
  1298. 'nine',
  1299. 'colon',
  1300. 'semicolon',
  1301. 'less',
  1302. 'equal',
  1303. 'greater',
  1304. 'question',
  1305. 'at',
  1306. 'A',
  1307. 'B',
  1308. 'C',
  1309. 'D',
  1310. 'E',
  1311. 'F',
  1312. 'G',
  1313. 'H',
  1314. 'I',
  1315. 'J',
  1316. 'K',
  1317. 'L',
  1318. 'M',
  1319. 'N',
  1320. 'O',
  1321. 'P',
  1322. 'Q',
  1323. 'R',
  1324. 'S',
  1325. 'T',
  1326. 'U',
  1327. 'V',
  1328. 'W',
  1329. 'X',
  1330. 'Y',
  1331. 'Z',
  1332. 'bracketleft',
  1333. 'backslash',
  1334. 'bracketright',
  1335. 'asciicircum',
  1336. 'underscore',
  1337. 'quoteleft',
  1338. 'a',
  1339. 'b',
  1340. 'c',
  1341. 'd',
  1342. 'e',
  1343. 'f',
  1344. 'g',
  1345. 'h',
  1346. 'i',
  1347. 'j',
  1348. 'k',
  1349. 'l',
  1350. 'm',
  1351. 'n',
  1352. 'o',
  1353. 'p',
  1354. 'q',
  1355. 'r',
  1356. 's',
  1357. 't',
  1358. 'u',
  1359. 'v',
  1360. 'w',
  1361. 'x',
  1362. 'y',
  1363. 'z',
  1364. 'braceleft',
  1365. 'bar',
  1366. 'braceright',
  1367. 'asciitilde',
  1368. 'exclamdown',
  1369. 'cent',
  1370. 'sterling',
  1371. 'fraction',
  1372. 'yen',
  1373. 'florin',
  1374. 'section',
  1375. 'currency',
  1376. 'quotesingle',
  1377. 'quotedblleft',
  1378. 'guillemotleft',
  1379. 'guilsinglleft',
  1380. 'guilsinglright',
  1381. 'fi',
  1382. 'fl',
  1383. 'endash',
  1384. 'dagger',
  1385. 'daggerdbl',
  1386. 'periodcentered',
  1387. 'paragraph',
  1388. 'bullet',
  1389. 'quotesinglbase',
  1390. 'quotedblbase',
  1391. 'quotedblright',
  1392. 'guillemotright',
  1393. 'ellipsis',
  1394. 'perthousand',
  1395. 'questiondown',
  1396. 'grave',
  1397. 'acute',
  1398. 'circumflex',
  1399. 'tilde',
  1400. 'macron',
  1401. 'breve',
  1402. 'dotaccent',
  1403. 'dieresis',
  1404. 'ring',
  1405. 'cedilla',
  1406. 'hungarumlaut',
  1407. 'ogonek',
  1408. 'caron',
  1409. 'emdash',
  1410. 'AE',
  1411. 'ordfeminine',
  1412. 'Lslash',
  1413. 'Oslash',
  1414. 'OE',
  1415. 'ordmasculine',
  1416. 'ae',
  1417. 'dotlessi',
  1418. 'lslash',
  1419. 'oslash',
  1420. 'oe',
  1421. 'germandbls',
  1422. 'onesuperior',
  1423. 'logicalnot',
  1424. 'mu',
  1425. 'trademark',
  1426. 'Eth',
  1427. 'onehalf',
  1428. 'plusminus',
  1429. 'Thorn',
  1430. 'onequarter',
  1431. 'divide',
  1432. 'brokenbar',
  1433. 'degree',
  1434. 'thorn',
  1435. 'threequarters',
  1436. 'twosuperior',
  1437. 'registered',
  1438. 'minus',
  1439. 'eth',
  1440. 'multiply',
  1441. 'threesuperior',
  1442. 'copyright',
  1443. 'Aacute',
  1444. 'Acircumflex',
  1445. 'Adieresis',
  1446. 'Agrave',
  1447. 'Aring',
  1448. 'Atilde',
  1449. 'Ccedilla',
  1450. 'Eacute',
  1451. 'Ecircumflex',
  1452. 'Edieresis',
  1453. 'Egrave',
  1454. 'Iacute',
  1455. 'Icircumflex',
  1456. 'Idieresis',
  1457. 'Igrave',
  1458. 'Ntilde',
  1459. 'Oacute',
  1460. 'Ocircumflex',
  1461. 'Odieresis',
  1462. 'Ograve',
  1463. 'Otilde',
  1464. 'Scaron',
  1465. 'Uacute',
  1466. 'Ucircumflex',
  1467. 'Udieresis',
  1468. 'Ugrave',
  1469. 'Yacute',
  1470. 'Ydieresis',
  1471. 'Zcaron',
  1472. 'aacute',
  1473. 'acircumflex',
  1474. 'adieresis',
  1475. 'agrave',
  1476. 'aring',
  1477. 'atilde',
  1478. 'ccedilla',
  1479. 'eacute',
  1480. 'ecircumflex',
  1481. 'edieresis',
  1482. 'egrave',
  1483. 'iacute',
  1484. 'icircumflex',
  1485. 'idieresis',
  1486. 'igrave',
  1487. 'ntilde',
  1488. 'oacute',
  1489. 'ocircumflex',
  1490. 'odieresis',
  1491. 'ograve',
  1492. 'otilde',
  1493. 'scaron',
  1494. 'uacute',
  1495. 'ucircumflex',
  1496. 'udieresis',
  1497. 'ugrave',
  1498. 'yacute',
  1499. 'ydieresis',
  1500. 'zcaron'
  1501. ];
  1502. var ExpertCharset = [
  1503. '.notdef',
  1504. 'space',
  1505. 'exclamsmall',
  1506. 'Hungarumlautsmall',
  1507. 'dollaroldstyle',
  1508. 'dollarsuperior',
  1509. 'ampersandsmall',
  1510. 'Acutesmall',
  1511. 'parenleftsuperior',
  1512. 'parenrightsuperior',
  1513. 'twodotenleader',
  1514. 'onedotenleader',
  1515. 'comma',
  1516. 'hyphen',
  1517. 'period',
  1518. 'fraction',
  1519. 'zerooldstyle',
  1520. 'oneoldstyle',
  1521. 'twooldstyle',
  1522. 'threeoldstyle',
  1523. 'fouroldstyle',
  1524. 'fiveoldstyle',
  1525. 'sixoldstyle',
  1526. 'sevenoldstyle',
  1527. 'eightoldstyle',
  1528. 'nineoldstyle',
  1529. 'colon',
  1530. 'semicolon',
  1531. 'commasuperior',
  1532. 'threequartersemdash',
  1533. 'periodsuperior',
  1534. 'questionsmall',
  1535. 'asuperior',
  1536. 'bsuperior',
  1537. 'centsuperior',
  1538. 'dsuperior',
  1539. 'esuperior',
  1540. 'isuperior',
  1541. 'lsuperior',
  1542. 'msuperior',
  1543. 'nsuperior',
  1544. 'osuperior',
  1545. 'rsuperior',
  1546. 'ssuperior',
  1547. 'tsuperior',
  1548. 'ff',
  1549. 'fi',
  1550. 'fl',
  1551. 'ffi',
  1552. 'ffl',
  1553. 'parenleftinferior',
  1554. 'parenrightinferior',
  1555. 'Circumflexsmall',
  1556. 'hyphensuperior',
  1557. 'Gravesmall',
  1558. 'Asmall',
  1559. 'Bsmall',
  1560. 'Csmall',
  1561. 'Dsmall',
  1562. 'Esmall',
  1563. 'Fsmall',
  1564. 'Gsmall',
  1565. 'Hsmall',
  1566. 'Ismall',
  1567. 'Jsmall',
  1568. 'Ksmall',
  1569. 'Lsmall',
  1570. 'Msmall',
  1571. 'Nsmall',
  1572. 'Osmall',
  1573. 'Psmall',
  1574. 'Qsmall',
  1575. 'Rsmall',
  1576. 'Ssmall',
  1577. 'Tsmall',
  1578. 'Usmall',
  1579. 'Vsmall',
  1580. 'Wsmall',
  1581. 'Xsmall',
  1582. 'Ysmall',
  1583. 'Zsmall',
  1584. 'colonmonetary',
  1585. 'onefitted',
  1586. 'rupiah',
  1587. 'Tildesmall',
  1588. 'exclamdownsmall',
  1589. 'centoldstyle',
  1590. 'Lslashsmall',
  1591. 'Scaronsmall',
  1592. 'Zcaronsmall',
  1593. 'Dieresissmall',
  1594. 'Brevesmall',
  1595. 'Caronsmall',
  1596. 'Dotaccentsmall',
  1597. 'Macronsmall',
  1598. 'figuredash',
  1599. 'hypheninferior',
  1600. 'Ogoneksmall',
  1601. 'Ringsmall',
  1602. 'Cedillasmall',
  1603. 'onequarter',
  1604. 'onehalf',
  1605. 'threequarters',
  1606. 'questiondownsmall',
  1607. 'oneeighth',
  1608. 'threeeighths',
  1609. 'fiveeighths',
  1610. 'seveneighths',
  1611. 'onethird',
  1612. 'twothirds',
  1613. 'zerosuperior',
  1614. 'onesuperior',
  1615. 'twosuperior',
  1616. 'threesuperior',
  1617. 'foursuperior',
  1618. 'fivesuperior',
  1619. 'sixsuperior',
  1620. 'sevensuperior',
  1621. 'eightsuperior',
  1622. 'ninesuperior',
  1623. 'zeroinferior',
  1624. 'oneinferior',
  1625. 'twoinferior',
  1626. 'threeinferior',
  1627. 'fourinferior',
  1628. 'fiveinferior',
  1629. 'sixinferior',
  1630. 'seveninferior',
  1631. 'eightinferior',
  1632. 'nineinferior',
  1633. 'centinferior',
  1634. 'dollarinferior',
  1635. 'periodinferior',
  1636. 'commainferior',
  1637. 'Agravesmall',
  1638. 'Aacutesmall',
  1639. 'Acircumflexsmall',
  1640. 'Atildesmall',
  1641. 'Adieresissmall',
  1642. 'Aringsmall',
  1643. 'AEsmall',
  1644. 'Ccedillasmall',
  1645. 'Egravesmall',
  1646. 'Eacutesmall',
  1647. 'Ecircumflexsmall',
  1648. 'Edieresissmall',
  1649. 'Igravesmall',
  1650. 'Iacutesmall',
  1651. 'Icircumflexsmall',
  1652. 'Idieresissmall',
  1653. 'Ethsmall',
  1654. 'Ntildesmall',
  1655. 'Ogravesmall',
  1656. 'Oacutesmall',
  1657. 'Ocircumflexsmall',
  1658. 'Otildesmall',
  1659. 'Odieresissmall',
  1660. 'OEsmall',
  1661. 'Oslashsmall',
  1662. 'Ugravesmall',
  1663. 'Uacutesmall',
  1664. 'Ucircumflexsmall',
  1665. 'Udieresissmall',
  1666. 'Yacutesmall',
  1667. 'Thornsmall',
  1668. 'Ydieresissmall'
  1669. ];
  1670. var ExpertSubsetCharset = [
  1671. '.notdef',
  1672. 'space',
  1673. 'dollaroldstyle',
  1674. 'dollarsuperior',
  1675. 'parenleftsuperior',
  1676. 'parenrightsuperior',
  1677. 'twodotenleader',
  1678. 'onedotenleader',
  1679. 'comma',
  1680. 'hyphen',
  1681. 'period',
  1682. 'fraction',
  1683. 'zerooldstyle',
  1684. 'oneoldstyle',
  1685. 'twooldstyle',
  1686. 'threeoldstyle',
  1687. 'fouroldstyle',
  1688. 'fiveoldstyle',
  1689. 'sixoldstyle',
  1690. 'sevenoldstyle',
  1691. 'eightoldstyle',
  1692. 'nineoldstyle',
  1693. 'colon',
  1694. 'semicolon',
  1695. 'commasuperior',
  1696. 'threequartersemdash',
  1697. 'periodsuperior',
  1698. 'asuperior',
  1699. 'bsuperior',
  1700. 'centsuperior',
  1701. 'dsuperior',
  1702. 'esuperior',
  1703. 'isuperior',
  1704. 'lsuperior',
  1705. 'msuperior',
  1706. 'nsuperior',
  1707. 'osuperior',
  1708. 'rsuperior',
  1709. 'ssuperior',
  1710. 'tsuperior',
  1711. 'ff',
  1712. 'fi',
  1713. 'fl',
  1714. 'ffi',
  1715. 'ffl',
  1716. 'parenleftinferior',
  1717. 'parenrightinferior',
  1718. 'hyphensuperior',
  1719. 'colonmonetary',
  1720. 'onefitted',
  1721. 'rupiah',
  1722. 'centoldstyle',
  1723. 'figuredash',
  1724. 'hypheninferior',
  1725. 'onequarter',
  1726. 'onehalf',
  1727. 'threequarters',
  1728. 'oneeighth',
  1729. 'threeeighths',
  1730. 'fiveeighths',
  1731. 'seveneighths',
  1732. 'onethird',
  1733. 'twothirds',
  1734. 'zerosuperior',
  1735. 'onesuperior',
  1736. 'twosuperior',
  1737. 'threesuperior',
  1738. 'foursuperior',
  1739. 'fivesuperior',
  1740. 'sixsuperior',
  1741. 'sevensuperior',
  1742. 'eightsuperior',
  1743. 'ninesuperior',
  1744. 'zeroinferior',
  1745. 'oneinferior',
  1746. 'twoinferior',
  1747. 'threeinferior',
  1748. 'fourinferior',
  1749. 'fiveinferior',
  1750. 'sixinferior',
  1751. 'seveninferior',
  1752. 'eightinferior',
  1753. 'nineinferior',
  1754. 'centinferior',
  1755. 'dollarinferior',
  1756. 'periodinferior',
  1757. 'commainferior'
  1758. ];
  1759. exports.ISOAdobeCharset = ISOAdobeCharset;
  1760. exports.ExpertCharset = ExpertCharset;
  1761. exports.ExpertSubsetCharset = ExpertSubsetCharset;
  1762. }));
  1763. (function (root, factory) {
  1764. factory(root.pdfjsCoreEncodings = {});
  1765. }(this, function (exports) {
  1766. var ExpertEncoding = [
  1767. '',
  1768. '',
  1769. '',
  1770. '',
  1771. '',
  1772. '',
  1773. '',
  1774. '',
  1775. '',
  1776. '',
  1777. '',
  1778. '',
  1779. '',
  1780. '',
  1781. '',
  1782. '',
  1783. '',
  1784. '',
  1785. '',
  1786. '',
  1787. '',
  1788. '',
  1789. '',
  1790. '',
  1791. '',
  1792. '',
  1793. '',
  1794. '',
  1795. '',
  1796. '',
  1797. '',
  1798. '',
  1799. 'space',
  1800. 'exclamsmall',
  1801. 'Hungarumlautsmall',
  1802. '',
  1803. 'dollaroldstyle',
  1804. 'dollarsuperior',
  1805. 'ampersandsmall',
  1806. 'Acutesmall',
  1807. 'parenleftsuperior',
  1808. 'parenrightsuperior',
  1809. 'twodotenleader',
  1810. 'onedotenleader',
  1811. 'comma',
  1812. 'hyphen',
  1813. 'period',
  1814. 'fraction',
  1815. 'zerooldstyle',
  1816. 'oneoldstyle',
  1817. 'twooldstyle',
  1818. 'threeoldstyle',
  1819. 'fouroldstyle',
  1820. 'fiveoldstyle',
  1821. 'sixoldstyle',
  1822. 'sevenoldstyle',
  1823. 'eightoldstyle',
  1824. 'nineoldstyle',
  1825. 'colon',
  1826. 'semicolon',
  1827. 'commasuperior',
  1828. 'threequartersemdash',
  1829. 'periodsuperior',
  1830. 'questionsmall',
  1831. '',
  1832. 'asuperior',
  1833. 'bsuperior',
  1834. 'centsuperior',
  1835. 'dsuperior',
  1836. 'esuperior',
  1837. '',
  1838. '',
  1839. 'isuperior',
  1840. '',
  1841. '',
  1842. 'lsuperior',
  1843. 'msuperior',
  1844. 'nsuperior',
  1845. 'osuperior',
  1846. '',
  1847. '',
  1848. 'rsuperior',
  1849. 'ssuperior',
  1850. 'tsuperior',
  1851. '',
  1852. 'ff',
  1853. 'fi',
  1854. 'fl',
  1855. 'ffi',
  1856. 'ffl',
  1857. 'parenleftinferior',
  1858. '',
  1859. 'parenrightinferior',
  1860. 'Circumflexsmall',
  1861. 'hyphensuperior',
  1862. 'Gravesmall',
  1863. 'Asmall',
  1864. 'Bsmall',
  1865. 'Csmall',
  1866. 'Dsmall',
  1867. 'Esmall',
  1868. 'Fsmall',
  1869. 'Gsmall',
  1870. 'Hsmall',
  1871. 'Ismall',
  1872. 'Jsmall',
  1873. 'Ksmall',
  1874. 'Lsmall',
  1875. 'Msmall',
  1876. 'Nsmall',
  1877. 'Osmall',
  1878. 'Psmall',
  1879. 'Qsmall',
  1880. 'Rsmall',
  1881. 'Ssmall',
  1882. 'Tsmall',
  1883. 'Usmall',
  1884. 'Vsmall',
  1885. 'Wsmall',
  1886. 'Xsmall',
  1887. 'Ysmall',
  1888. 'Zsmall',
  1889. 'colonmonetary',
  1890. 'onefitted',
  1891. 'rupiah',
  1892. 'Tildesmall',
  1893. '',
  1894. '',
  1895. '',
  1896. '',
  1897. '',
  1898. '',
  1899. '',
  1900. '',
  1901. '',
  1902. '',
  1903. '',
  1904. '',
  1905. '',
  1906. '',
  1907. '',
  1908. '',
  1909. '',
  1910. '',
  1911. '',
  1912. '',
  1913. '',
  1914. '',
  1915. '',
  1916. '',
  1917. '',
  1918. '',
  1919. '',
  1920. '',
  1921. '',
  1922. '',
  1923. '',
  1924. '',
  1925. '',
  1926. '',
  1927. 'exclamdownsmall',
  1928. 'centoldstyle',
  1929. 'Lslashsmall',
  1930. '',
  1931. '',
  1932. 'Scaronsmall',
  1933. 'Zcaronsmall',
  1934. 'Dieresissmall',
  1935. 'Brevesmall',
  1936. 'Caronsmall',
  1937. '',
  1938. 'Dotaccentsmall',
  1939. '',
  1940. '',
  1941. 'Macronsmall',
  1942. '',
  1943. '',
  1944. 'figuredash',
  1945. 'hypheninferior',
  1946. '',
  1947. '',
  1948. 'Ogoneksmall',
  1949. 'Ringsmall',
  1950. 'Cedillasmall',
  1951. '',
  1952. '',
  1953. '',
  1954. 'onequarter',
  1955. 'onehalf',
  1956. 'threequarters',
  1957. 'questiondownsmall',
  1958. 'oneeighth',
  1959. 'threeeighths',
  1960. 'fiveeighths',
  1961. 'seveneighths',
  1962. 'onethird',
  1963. 'twothirds',
  1964. '',
  1965. '',
  1966. 'zerosuperior',
  1967. 'onesuperior',
  1968. 'twosuperior',
  1969. 'threesuperior',
  1970. 'foursuperior',
  1971. 'fivesuperior',
  1972. 'sixsuperior',
  1973. 'sevensuperior',
  1974. 'eightsuperior',
  1975. 'ninesuperior',
  1976. 'zeroinferior',
  1977. 'oneinferior',
  1978. 'twoinferior',
  1979. 'threeinferior',
  1980. 'fourinferior',
  1981. 'fiveinferior',
  1982. 'sixinferior',
  1983. 'seveninferior',
  1984. 'eightinferior',
  1985. 'nineinferior',
  1986. 'centinferior',
  1987. 'dollarinferior',
  1988. 'periodinferior',
  1989. 'commainferior',
  1990. 'Agravesmall',
  1991. 'Aacutesmall',
  1992. 'Acircumflexsmall',
  1993. 'Atildesmall',
  1994. 'Adieresissmall',
  1995. 'Aringsmall',
  1996. 'AEsmall',
  1997. 'Ccedillasmall',
  1998. 'Egravesmall',
  1999. 'Eacutesmall',
  2000. 'Ecircumflexsmall',
  2001. 'Edieresissmall',
  2002. 'Igravesmall',
  2003. 'Iacutesmall',
  2004. 'Icircumflexsmall',
  2005. 'Idieresissmall',
  2006. 'Ethsmall',
  2007. 'Ntildesmall',
  2008. 'Ogravesmall',
  2009. 'Oacutesmall',
  2010. 'Ocircumflexsmall',
  2011. 'Otildesmall',
  2012. 'Odieresissmall',
  2013. 'OEsmall',
  2014. 'Oslashsmall',
  2015. 'Ugravesmall',
  2016. 'Uacutesmall',
  2017. 'Ucircumflexsmall',
  2018. 'Udieresissmall',
  2019. 'Yacutesmall',
  2020. 'Thornsmall',
  2021. 'Ydieresissmall'
  2022. ];
  2023. var MacExpertEncoding = [
  2024. '',
  2025. '',
  2026. '',
  2027. '',
  2028. '',
  2029. '',
  2030. '',
  2031. '',
  2032. '',
  2033. '',
  2034. '',
  2035. '',
  2036. '',
  2037. '',
  2038. '',
  2039. '',
  2040. '',
  2041. '',
  2042. '',
  2043. '',
  2044. '',
  2045. '',
  2046. '',
  2047. '',
  2048. '',
  2049. '',
  2050. '',
  2051. '',
  2052. '',
  2053. '',
  2054. '',
  2055. '',
  2056. 'space',
  2057. 'exclamsmall',
  2058. 'Hungarumlautsmall',
  2059. 'centoldstyle',
  2060. 'dollaroldstyle',
  2061. 'dollarsuperior',
  2062. 'ampersandsmall',
  2063. 'Acutesmall',
  2064. 'parenleftsuperior',
  2065. 'parenrightsuperior',
  2066. 'twodotenleader',
  2067. 'onedotenleader',
  2068. 'comma',
  2069. 'hyphen',
  2070. 'period',
  2071. 'fraction',
  2072. 'zerooldstyle',
  2073. 'oneoldstyle',
  2074. 'twooldstyle',
  2075. 'threeoldstyle',
  2076. 'fouroldstyle',
  2077. 'fiveoldstyle',
  2078. 'sixoldstyle',
  2079. 'sevenoldstyle',
  2080. 'eightoldstyle',
  2081. 'nineoldstyle',
  2082. 'colon',
  2083. 'semicolon',
  2084. '',
  2085. 'threequartersemdash',
  2086. '',
  2087. 'questionsmall',
  2088. '',
  2089. '',
  2090. '',
  2091. '',
  2092. 'Ethsmall',
  2093. '',
  2094. '',
  2095. 'onequarter',
  2096. 'onehalf',
  2097. 'threequarters',
  2098. 'oneeighth',
  2099. 'threeeighths',
  2100. 'fiveeighths',
  2101. 'seveneighths',
  2102. 'onethird',
  2103. 'twothirds',
  2104. '',
  2105. '',
  2106. '',
  2107. '',
  2108. '',
  2109. '',
  2110. 'ff',
  2111. 'fi',
  2112. 'fl',
  2113. 'ffi',
  2114. 'ffl',
  2115. 'parenleftinferior',
  2116. '',
  2117. 'parenrightinferior',
  2118. 'Circumflexsmall',
  2119. 'hypheninferior',
  2120. 'Gravesmall',
  2121. 'Asmall',
  2122. 'Bsmall',
  2123. 'Csmall',
  2124. 'Dsmall',
  2125. 'Esmall',
  2126. 'Fsmall',
  2127. 'Gsmall',
  2128. 'Hsmall',
  2129. 'Ismall',
  2130. 'Jsmall',
  2131. 'Ksmall',
  2132. 'Lsmall',
  2133. 'Msmall',
  2134. 'Nsmall',
  2135. 'Osmall',
  2136. 'Psmall',
  2137. 'Qsmall',
  2138. 'Rsmall',
  2139. 'Ssmall',
  2140. 'Tsmall',
  2141. 'Usmall',
  2142. 'Vsmall',
  2143. 'Wsmall',
  2144. 'Xsmall',
  2145. 'Ysmall',
  2146. 'Zsmall',
  2147. 'colonmonetary',
  2148. 'onefitted',
  2149. 'rupiah',
  2150. 'Tildesmall',
  2151. '',
  2152. '',
  2153. 'asuperior',
  2154. 'centsuperior',
  2155. '',
  2156. '',
  2157. '',
  2158. '',
  2159. 'Aacutesmall',
  2160. 'Agravesmall',
  2161. 'Acircumflexsmall',
  2162. 'Adieresissmall',
  2163. 'Atildesmall',
  2164. 'Aringsmall',
  2165. 'Ccedillasmall',
  2166. 'Eacutesmall',
  2167. 'Egravesmall',
  2168. 'Ecircumflexsmall',
  2169. 'Edieresissmall',
  2170. 'Iacutesmall',
  2171. 'Igravesmall',
  2172. 'Icircumflexsmall',
  2173. 'Idieresissmall',
  2174. 'Ntildesmall',
  2175. 'Oacutesmall',
  2176. 'Ogravesmall',
  2177. 'Ocircumflexsmall',
  2178. 'Odieresissmall',
  2179. 'Otildesmall',
  2180. 'Uacutesmall',
  2181. 'Ugravesmall',
  2182. 'Ucircumflexsmall',
  2183. 'Udieresissmall',
  2184. '',
  2185. 'eightsuperior',
  2186. 'fourinferior',
  2187. 'threeinferior',
  2188. 'sixinferior',
  2189. 'eightinferior',
  2190. 'seveninferior',
  2191. 'Scaronsmall',
  2192. '',
  2193. 'centinferior',
  2194. 'twoinferior',
  2195. '',
  2196. 'Dieresissmall',
  2197. '',
  2198. 'Caronsmall',
  2199. 'osuperior',
  2200. 'fiveinferior',
  2201. '',
  2202. 'commainferior',
  2203. 'periodinferior',
  2204. 'Yacutesmall',
  2205. '',
  2206. 'dollarinferior',
  2207. '',
  2208. 'Thornsmall',
  2209. '',
  2210. 'nineinferior',
  2211. 'zeroinferior',
  2212. 'Zcaronsmall',
  2213. 'AEsmall',
  2214. 'Oslashsmall',
  2215. 'questiondownsmall',
  2216. 'oneinferior',
  2217. 'Lslashsmall',
  2218. '',
  2219. '',
  2220. '',
  2221. '',
  2222. '',
  2223. '',
  2224. 'Cedillasmall',
  2225. '',
  2226. '',
  2227. '',
  2228. '',
  2229. '',
  2230. 'OEsmall',
  2231. 'figuredash',
  2232. 'hyphensuperior',
  2233. '',
  2234. '',
  2235. '',
  2236. '',
  2237. 'exclamdownsmall',
  2238. '',
  2239. 'Ydieresissmall',
  2240. '',
  2241. 'onesuperior',
  2242. 'twosuperior',
  2243. 'threesuperior',
  2244. 'foursuperior',
  2245. 'fivesuperior',
  2246. 'sixsuperior',
  2247. 'sevensuperior',
  2248. 'ninesuperior',
  2249. 'zerosuperior',
  2250. '',
  2251. 'esuperior',
  2252. 'rsuperior',
  2253. 'tsuperior',
  2254. '',
  2255. '',
  2256. 'isuperior',
  2257. 'ssuperior',
  2258. 'dsuperior',
  2259. '',
  2260. '',
  2261. '',
  2262. '',
  2263. '',
  2264. 'lsuperior',
  2265. 'Ogoneksmall',
  2266. 'Brevesmall',
  2267. 'Macronsmall',
  2268. 'bsuperior',
  2269. 'nsuperior',
  2270. 'msuperior',
  2271. 'commasuperior',
  2272. 'periodsuperior',
  2273. 'Dotaccentsmall',
  2274. 'Ringsmall'
  2275. ];
  2276. var MacRomanEncoding = [
  2277. '',
  2278. '',
  2279. '',
  2280. '',
  2281. '',
  2282. '',
  2283. '',
  2284. '',
  2285. '',
  2286. '',
  2287. '',
  2288. '',
  2289. '',
  2290. '',
  2291. '',
  2292. '',
  2293. '',
  2294. '',
  2295. '',
  2296. '',
  2297. '',
  2298. '',
  2299. '',
  2300. '',
  2301. '',
  2302. '',
  2303. '',
  2304. '',
  2305. '',
  2306. '',
  2307. '',
  2308. '',
  2309. 'space',
  2310. 'exclam',
  2311. 'quotedbl',
  2312. 'numbersign',
  2313. 'dollar',
  2314. 'percent',
  2315. 'ampersand',
  2316. 'quotesingle',
  2317. 'parenleft',
  2318. 'parenright',
  2319. 'asterisk',
  2320. 'plus',
  2321. 'comma',
  2322. 'hyphen',
  2323. 'period',
  2324. 'slash',
  2325. 'zero',
  2326. 'one',
  2327. 'two',
  2328. 'three',
  2329. 'four',
  2330. 'five',
  2331. 'six',
  2332. 'seven',
  2333. 'eight',
  2334. 'nine',
  2335. 'colon',
  2336. 'semicolon',
  2337. 'less',
  2338. 'equal',
  2339. 'greater',
  2340. 'question',
  2341. 'at',
  2342. 'A',
  2343. 'B',
  2344. 'C',
  2345. 'D',
  2346. 'E',
  2347. 'F',
  2348. 'G',
  2349. 'H',
  2350. 'I',
  2351. 'J',
  2352. 'K',
  2353. 'L',
  2354. 'M',
  2355. 'N',
  2356. 'O',
  2357. 'P',
  2358. 'Q',
  2359. 'R',
  2360. 'S',
  2361. 'T',
  2362. 'U',
  2363. 'V',
  2364. 'W',
  2365. 'X',
  2366. 'Y',
  2367. 'Z',
  2368. 'bracketleft',
  2369. 'backslash',
  2370. 'bracketright',
  2371. 'asciicircum',
  2372. 'underscore',
  2373. 'grave',
  2374. 'a',
  2375. 'b',
  2376. 'c',
  2377. 'd',
  2378. 'e',
  2379. 'f',
  2380. 'g',
  2381. 'h',
  2382. 'i',
  2383. 'j',
  2384. 'k',
  2385. 'l',
  2386. 'm',
  2387. 'n',
  2388. 'o',
  2389. 'p',
  2390. 'q',
  2391. 'r',
  2392. 's',
  2393. 't',
  2394. 'u',
  2395. 'v',
  2396. 'w',
  2397. 'x',
  2398. 'y',
  2399. 'z',
  2400. 'braceleft',
  2401. 'bar',
  2402. 'braceright',
  2403. 'asciitilde',
  2404. '',
  2405. 'Adieresis',
  2406. 'Aring',
  2407. 'Ccedilla',
  2408. 'Eacute',
  2409. 'Ntilde',
  2410. 'Odieresis',
  2411. 'Udieresis',
  2412. 'aacute',
  2413. 'agrave',
  2414. 'acircumflex',
  2415. 'adieresis',
  2416. 'atilde',
  2417. 'aring',
  2418. 'ccedilla',
  2419. 'eacute',
  2420. 'egrave',
  2421. 'ecircumflex',
  2422. 'edieresis',
  2423. 'iacute',
  2424. 'igrave',
  2425. 'icircumflex',
  2426. 'idieresis',
  2427. 'ntilde',
  2428. 'oacute',
  2429. 'ograve',
  2430. 'ocircumflex',
  2431. 'odieresis',
  2432. 'otilde',
  2433. 'uacute',
  2434. 'ugrave',
  2435. 'ucircumflex',
  2436. 'udieresis',
  2437. 'dagger',
  2438. 'degree',
  2439. 'cent',
  2440. 'sterling',
  2441. 'section',
  2442. 'bullet',
  2443. 'paragraph',
  2444. 'germandbls',
  2445. 'registered',
  2446. 'copyright',
  2447. 'trademark',
  2448. 'acute',
  2449. 'dieresis',
  2450. 'notequal',
  2451. 'AE',
  2452. 'Oslash',
  2453. 'infinity',
  2454. 'plusminus',
  2455. 'lessequal',
  2456. 'greaterequal',
  2457. 'yen',
  2458. 'mu',
  2459. 'partialdiff',
  2460. 'summation',
  2461. 'product',
  2462. 'pi',
  2463. 'integral',
  2464. 'ordfeminine',
  2465. 'ordmasculine',
  2466. 'Omega',
  2467. 'ae',
  2468. 'oslash',
  2469. 'questiondown',
  2470. 'exclamdown',
  2471. 'logicalnot',
  2472. 'radical',
  2473. 'florin',
  2474. 'approxequal',
  2475. 'Delta',
  2476. 'guillemotleft',
  2477. 'guillemotright',
  2478. 'ellipsis',
  2479. 'space',
  2480. 'Agrave',
  2481. 'Atilde',
  2482. 'Otilde',
  2483. 'OE',
  2484. 'oe',
  2485. 'endash',
  2486. 'emdash',
  2487. 'quotedblleft',
  2488. 'quotedblright',
  2489. 'quoteleft',
  2490. 'quoteright',
  2491. 'divide',
  2492. 'lozenge',
  2493. 'ydieresis',
  2494. 'Ydieresis',
  2495. 'fraction',
  2496. 'currency',
  2497. 'guilsinglleft',
  2498. 'guilsinglright',
  2499. 'fi',
  2500. 'fl',
  2501. 'daggerdbl',
  2502. 'periodcentered',
  2503. 'quotesinglbase',
  2504. 'quotedblbase',
  2505. 'perthousand',
  2506. 'Acircumflex',
  2507. 'Ecircumflex',
  2508. 'Aacute',
  2509. 'Edieresis',
  2510. 'Egrave',
  2511. 'Iacute',
  2512. 'Icircumflex',
  2513. 'Idieresis',
  2514. 'Igrave',
  2515. 'Oacute',
  2516. 'Ocircumflex',
  2517. 'apple',
  2518. 'Ograve',
  2519. 'Uacute',
  2520. 'Ucircumflex',
  2521. 'Ugrave',
  2522. 'dotlessi',
  2523. 'circumflex',
  2524. 'tilde',
  2525. 'macron',
  2526. 'breve',
  2527. 'dotaccent',
  2528. 'ring',
  2529. 'cedilla',
  2530. 'hungarumlaut',
  2531. 'ogonek',
  2532. 'caron'
  2533. ];
  2534. var StandardEncoding = [
  2535. '',
  2536. '',
  2537. '',
  2538. '',
  2539. '',
  2540. '',
  2541. '',
  2542. '',
  2543. '',
  2544. '',
  2545. '',
  2546. '',
  2547. '',
  2548. '',
  2549. '',
  2550. '',
  2551. '',
  2552. '',
  2553. '',
  2554. '',
  2555. '',
  2556. '',
  2557. '',
  2558. '',
  2559. '',
  2560. '',
  2561. '',
  2562. '',
  2563. '',
  2564. '',
  2565. '',
  2566. '',
  2567. 'space',
  2568. 'exclam',
  2569. 'quotedbl',
  2570. 'numbersign',
  2571. 'dollar',
  2572. 'percent',
  2573. 'ampersand',
  2574. 'quoteright',
  2575. 'parenleft',
  2576. 'parenright',
  2577. 'asterisk',
  2578. 'plus',
  2579. 'comma',
  2580. 'hyphen',
  2581. 'period',
  2582. 'slash',
  2583. 'zero',
  2584. 'one',
  2585. 'two',
  2586. 'three',
  2587. 'four',
  2588. 'five',
  2589. 'six',
  2590. 'seven',
  2591. 'eight',
  2592. 'nine',
  2593. 'colon',
  2594. 'semicolon',
  2595. 'less',
  2596. 'equal',
  2597. 'greater',
  2598. 'question',
  2599. 'at',
  2600. 'A',
  2601. 'B',
  2602. 'C',
  2603. 'D',
  2604. 'E',
  2605. 'F',
  2606. 'G',
  2607. 'H',
  2608. 'I',
  2609. 'J',
  2610. 'K',
  2611. 'L',
  2612. 'M',
  2613. 'N',
  2614. 'O',
  2615. 'P',
  2616. 'Q',
  2617. 'R',
  2618. 'S',
  2619. 'T',
  2620. 'U',
  2621. 'V',
  2622. 'W',
  2623. 'X',
  2624. 'Y',
  2625. 'Z',
  2626. 'bracketleft',
  2627. 'backslash',
  2628. 'bracketright',
  2629. 'asciicircum',
  2630. 'underscore',
  2631. 'quoteleft',
  2632. 'a',
  2633. 'b',
  2634. 'c',
  2635. 'd',
  2636. 'e',
  2637. 'f',
  2638. 'g',
  2639. 'h',
  2640. 'i',
  2641. 'j',
  2642. 'k',
  2643. 'l',
  2644. 'm',
  2645. 'n',
  2646. 'o',
  2647. 'p',
  2648. 'q',
  2649. 'r',
  2650. 's',
  2651. 't',
  2652. 'u',
  2653. 'v',
  2654. 'w',
  2655. 'x',
  2656. 'y',
  2657. 'z',
  2658. 'braceleft',
  2659. 'bar',
  2660. 'braceright',
  2661. 'asciitilde',
  2662. '',
  2663. '',
  2664. '',
  2665. '',
  2666. '',
  2667. '',
  2668. '',
  2669. '',
  2670. '',
  2671. '',
  2672. '',
  2673. '',
  2674. '',
  2675. '',
  2676. '',
  2677. '',
  2678. '',
  2679. '',
  2680. '',
  2681. '',
  2682. '',
  2683. '',
  2684. '',
  2685. '',
  2686. '',
  2687. '',
  2688. '',
  2689. '',
  2690. '',
  2691. '',
  2692. '',
  2693. '',
  2694. '',
  2695. '',
  2696. 'exclamdown',
  2697. 'cent',
  2698. 'sterling',
  2699. 'fraction',
  2700. 'yen',
  2701. 'florin',
  2702. 'section',
  2703. 'currency',
  2704. 'quotesingle',
  2705. 'quotedblleft',
  2706. 'guillemotleft',
  2707. 'guilsinglleft',
  2708. 'guilsinglright',
  2709. 'fi',
  2710. 'fl',
  2711. '',
  2712. 'endash',
  2713. 'dagger',
  2714. 'daggerdbl',
  2715. 'periodcentered',
  2716. '',
  2717. 'paragraph',
  2718. 'bullet',
  2719. 'quotesinglbase',
  2720. 'quotedblbase',
  2721. 'quotedblright',
  2722. 'guillemotright',
  2723. 'ellipsis',
  2724. 'perthousand',
  2725. '',
  2726. 'questiondown',
  2727. '',
  2728. 'grave',
  2729. 'acute',
  2730. 'circumflex',
  2731. 'tilde',
  2732. 'macron',
  2733. 'breve',
  2734. 'dotaccent',
  2735. 'dieresis',
  2736. '',
  2737. 'ring',
  2738. 'cedilla',
  2739. '',
  2740. 'hungarumlaut',
  2741. 'ogonek',
  2742. 'caron',
  2743. 'emdash',
  2744. '',
  2745. '',
  2746. '',
  2747. '',
  2748. '',
  2749. '',
  2750. '',
  2751. '',
  2752. '',
  2753. '',
  2754. '',
  2755. '',
  2756. '',
  2757. '',
  2758. '',
  2759. '',
  2760. 'AE',
  2761. '',
  2762. 'ordfeminine',
  2763. '',
  2764. '',
  2765. '',
  2766. '',
  2767. 'Lslash',
  2768. 'Oslash',
  2769. 'OE',
  2770. 'ordmasculine',
  2771. '',
  2772. '',
  2773. '',
  2774. '',
  2775. '',
  2776. 'ae',
  2777. '',
  2778. '',
  2779. '',
  2780. 'dotlessi',
  2781. '',
  2782. '',
  2783. 'lslash',
  2784. 'oslash',
  2785. 'oe',
  2786. 'germandbls'
  2787. ];
  2788. var WinAnsiEncoding = [
  2789. '',
  2790. '',
  2791. '',
  2792. '',
  2793. '',
  2794. '',
  2795. '',
  2796. '',
  2797. '',
  2798. '',
  2799. '',
  2800. '',
  2801. '',
  2802. '',
  2803. '',
  2804. '',
  2805. '',
  2806. '',
  2807. '',
  2808. '',
  2809. '',
  2810. '',
  2811. '',
  2812. '',
  2813. '',
  2814. '',
  2815. '',
  2816. '',
  2817. '',
  2818. '',
  2819. '',
  2820. '',
  2821. 'space',
  2822. 'exclam',
  2823. 'quotedbl',
  2824. 'numbersign',
  2825. 'dollar',
  2826. 'percent',
  2827. 'ampersand',
  2828. 'quotesingle',
  2829. 'parenleft',
  2830. 'parenright',
  2831. 'asterisk',
  2832. 'plus',
  2833. 'comma',
  2834. 'hyphen',
  2835. 'period',
  2836. 'slash',
  2837. 'zero',
  2838. 'one',
  2839. 'two',
  2840. 'three',
  2841. 'four',
  2842. 'five',
  2843. 'six',
  2844. 'seven',
  2845. 'eight',
  2846. 'nine',
  2847. 'colon',
  2848. 'semicolon',
  2849. 'less',
  2850. 'equal',
  2851. 'greater',
  2852. 'question',
  2853. 'at',
  2854. 'A',
  2855. 'B',
  2856. 'C',
  2857. 'D',
  2858. 'E',
  2859. 'F',
  2860. 'G',
  2861. 'H',
  2862. 'I',
  2863. 'J',
  2864. 'K',
  2865. 'L',
  2866. 'M',
  2867. 'N',
  2868. 'O',
  2869. 'P',
  2870. 'Q',
  2871. 'R',
  2872. 'S',
  2873. 'T',
  2874. 'U',
  2875. 'V',
  2876. 'W',
  2877. 'X',
  2878. 'Y',
  2879. 'Z',
  2880. 'bracketleft',
  2881. 'backslash',
  2882. 'bracketright',
  2883. 'asciicircum',
  2884. 'underscore',
  2885. 'grave',
  2886. 'a',
  2887. 'b',
  2888. 'c',
  2889. 'd',
  2890. 'e',
  2891. 'f',
  2892. 'g',
  2893. 'h',
  2894. 'i',
  2895. 'j',
  2896. 'k',
  2897. 'l',
  2898. 'm',
  2899. 'n',
  2900. 'o',
  2901. 'p',
  2902. 'q',
  2903. 'r',
  2904. 's',
  2905. 't',
  2906. 'u',
  2907. 'v',
  2908. 'w',
  2909. 'x',
  2910. 'y',
  2911. 'z',
  2912. 'braceleft',
  2913. 'bar',
  2914. 'braceright',
  2915. 'asciitilde',
  2916. 'bullet',
  2917. 'Euro',
  2918. 'bullet',
  2919. 'quotesinglbase',
  2920. 'florin',
  2921. 'quotedblbase',
  2922. 'ellipsis',
  2923. 'dagger',
  2924. 'daggerdbl',
  2925. 'circumflex',
  2926. 'perthousand',
  2927. 'Scaron',
  2928. 'guilsinglleft',
  2929. 'OE',
  2930. 'bullet',
  2931. 'Zcaron',
  2932. 'bullet',
  2933. 'bullet',
  2934. 'quoteleft',
  2935. 'quoteright',
  2936. 'quotedblleft',
  2937. 'quotedblright',
  2938. 'bullet',
  2939. 'endash',
  2940. 'emdash',
  2941. 'tilde',
  2942. 'trademark',
  2943. 'scaron',
  2944. 'guilsinglright',
  2945. 'oe',
  2946. 'bullet',
  2947. 'zcaron',
  2948. 'Ydieresis',
  2949. 'space',
  2950. 'exclamdown',
  2951. 'cent',
  2952. 'sterling',
  2953. 'currency',
  2954. 'yen',
  2955. 'brokenbar',
  2956. 'section',
  2957. 'dieresis',
  2958. 'copyright',
  2959. 'ordfeminine',
  2960. 'guillemotleft',
  2961. 'logicalnot',
  2962. 'hyphen',
  2963. 'registered',
  2964. 'macron',
  2965. 'degree',
  2966. 'plusminus',
  2967. 'twosuperior',
  2968. 'threesuperior',
  2969. 'acute',
  2970. 'mu',
  2971. 'paragraph',
  2972. 'periodcentered',
  2973. 'cedilla',
  2974. 'onesuperior',
  2975. 'ordmasculine',
  2976. 'guillemotright',
  2977. 'onequarter',
  2978. 'onehalf',
  2979. 'threequarters',
  2980. 'questiondown',
  2981. 'Agrave',
  2982. 'Aacute',
  2983. 'Acircumflex',
  2984. 'Atilde',
  2985. 'Adieresis',
  2986. 'Aring',
  2987. 'AE',
  2988. 'Ccedilla',
  2989. 'Egrave',
  2990. 'Eacute',
  2991. 'Ecircumflex',
  2992. 'Edieresis',
  2993. 'Igrave',
  2994. 'Iacute',
  2995. 'Icircumflex',
  2996. 'Idieresis',
  2997. 'Eth',
  2998. 'Ntilde',
  2999. 'Ograve',
  3000. 'Oacute',
  3001. 'Ocircumflex',
  3002. 'Otilde',
  3003. 'Odieresis',
  3004. 'multiply',
  3005. 'Oslash',
  3006. 'Ugrave',
  3007. 'Uacute',
  3008. 'Ucircumflex',
  3009. 'Udieresis',
  3010. 'Yacute',
  3011. 'Thorn',
  3012. 'germandbls',
  3013. 'agrave',
  3014. 'aacute',
  3015. 'acircumflex',
  3016. 'atilde',
  3017. 'adieresis',
  3018. 'aring',
  3019. 'ae',
  3020. 'ccedilla',
  3021. 'egrave',
  3022. 'eacute',
  3023. 'ecircumflex',
  3024. 'edieresis',
  3025. 'igrave',
  3026. 'iacute',
  3027. 'icircumflex',
  3028. 'idieresis',
  3029. 'eth',
  3030. 'ntilde',
  3031. 'ograve',
  3032. 'oacute',
  3033. 'ocircumflex',
  3034. 'otilde',
  3035. 'odieresis',
  3036. 'divide',
  3037. 'oslash',
  3038. 'ugrave',
  3039. 'uacute',
  3040. 'ucircumflex',
  3041. 'udieresis',
  3042. 'yacute',
  3043. 'thorn',
  3044. 'ydieresis'
  3045. ];
  3046. var SymbolSetEncoding = [
  3047. '',
  3048. '',
  3049. '',
  3050. '',
  3051. '',
  3052. '',
  3053. '',
  3054. '',
  3055. '',
  3056. '',
  3057. '',
  3058. '',
  3059. '',
  3060. '',
  3061. '',
  3062. '',
  3063. '',
  3064. '',
  3065. '',
  3066. '',
  3067. '',
  3068. '',
  3069. '',
  3070. '',
  3071. '',
  3072. '',
  3073. '',
  3074. '',
  3075. '',
  3076. '',
  3077. '',
  3078. '',
  3079. 'space',
  3080. 'exclam',
  3081. 'universal',
  3082. 'numbersign',
  3083. 'existential',
  3084. 'percent',
  3085. 'ampersand',
  3086. 'suchthat',
  3087. 'parenleft',
  3088. 'parenright',
  3089. 'asteriskmath',
  3090. 'plus',
  3091. 'comma',
  3092. 'minus',
  3093. 'period',
  3094. 'slash',
  3095. 'zero',
  3096. 'one',
  3097. 'two',
  3098. 'three',
  3099. 'four',
  3100. 'five',
  3101. 'six',
  3102. 'seven',
  3103. 'eight',
  3104. 'nine',
  3105. 'colon',
  3106. 'semicolon',
  3107. 'less',
  3108. 'equal',
  3109. 'greater',
  3110. 'question',
  3111. 'congruent',
  3112. 'Alpha',
  3113. 'Beta',
  3114. 'Chi',
  3115. 'Delta',
  3116. 'Epsilon',
  3117. 'Phi',
  3118. 'Gamma',
  3119. 'Eta',
  3120. 'Iota',
  3121. 'theta1',
  3122. 'Kappa',
  3123. 'Lambda',
  3124. 'Mu',
  3125. 'Nu',
  3126. 'Omicron',
  3127. 'Pi',
  3128. 'Theta',
  3129. 'Rho',
  3130. 'Sigma',
  3131. 'Tau',
  3132. 'Upsilon',
  3133. 'sigma1',
  3134. 'Omega',
  3135. 'Xi',
  3136. 'Psi',
  3137. 'Zeta',
  3138. 'bracketleft',
  3139. 'therefore',
  3140. 'bracketright',
  3141. 'perpendicular',
  3142. 'underscore',
  3143. 'radicalex',
  3144. 'alpha',
  3145. 'beta',
  3146. 'chi',
  3147. 'delta',
  3148. 'epsilon',
  3149. 'phi',
  3150. 'gamma',
  3151. 'eta',
  3152. 'iota',
  3153. 'phi1',
  3154. 'kappa',
  3155. 'lambda',
  3156. 'mu',
  3157. 'nu',
  3158. 'omicron',
  3159. 'pi',
  3160. 'theta',
  3161. 'rho',
  3162. 'sigma',
  3163. 'tau',
  3164. 'upsilon',
  3165. 'omega1',
  3166. 'omega',
  3167. 'xi',
  3168. 'psi',
  3169. 'zeta',
  3170. 'braceleft',
  3171. 'bar',
  3172. 'braceright',
  3173. 'similar',
  3174. '',
  3175. '',
  3176. '',
  3177. '',
  3178. '',
  3179. '',
  3180. '',
  3181. '',
  3182. '',
  3183. '',
  3184. '',
  3185. '',
  3186. '',
  3187. '',
  3188. '',
  3189. '',
  3190. '',
  3191. '',
  3192. '',
  3193. '',
  3194. '',
  3195. '',
  3196. '',
  3197. '',
  3198. '',
  3199. '',
  3200. '',
  3201. '',
  3202. '',
  3203. '',
  3204. '',
  3205. '',
  3206. '',
  3207. 'Euro',
  3208. 'Upsilon1',
  3209. 'minute',
  3210. 'lessequal',
  3211. 'fraction',
  3212. 'infinity',
  3213. 'florin',
  3214. 'club',
  3215. 'diamond',
  3216. 'heart',
  3217. 'spade',
  3218. 'arrowboth',
  3219. 'arrowleft',
  3220. 'arrowup',
  3221. 'arrowright',
  3222. 'arrowdown',
  3223. 'degree',
  3224. 'plusminus',
  3225. 'second',
  3226. 'greaterequal',
  3227. 'multiply',
  3228. 'proportional',
  3229. 'partialdiff',
  3230. 'bullet',
  3231. 'divide',
  3232. 'notequal',
  3233. 'equivalence',
  3234. 'approxequal',
  3235. 'ellipsis',
  3236. 'arrowvertex',
  3237. 'arrowhorizex',
  3238. 'carriagereturn',
  3239. 'aleph',
  3240. 'Ifraktur',
  3241. 'Rfraktur',
  3242. 'weierstrass',
  3243. 'circlemultiply',
  3244. 'circleplus',
  3245. 'emptyset',
  3246. 'intersection',
  3247. 'union',
  3248. 'propersuperset',
  3249. 'reflexsuperset',
  3250. 'notsubset',
  3251. 'propersubset',
  3252. 'reflexsubset',
  3253. 'element',
  3254. 'notelement',
  3255. 'angle',
  3256. 'gradient',
  3257. 'registerserif',
  3258. 'copyrightserif',
  3259. 'trademarkserif',
  3260. 'product',
  3261. 'radical',
  3262. 'dotmath',
  3263. 'logicalnot',
  3264. 'logicaland',
  3265. 'logicalor',
  3266. 'arrowdblboth',
  3267. 'arrowdblleft',
  3268. 'arrowdblup',
  3269. 'arrowdblright',
  3270. 'arrowdbldown',
  3271. 'lozenge',
  3272. 'angleleft',
  3273. 'registersans',
  3274. 'copyrightsans',
  3275. 'trademarksans',
  3276. 'summation',
  3277. 'parenlefttp',
  3278. 'parenleftex',
  3279. 'parenleftbt',
  3280. 'bracketlefttp',
  3281. 'bracketleftex',
  3282. 'bracketleftbt',
  3283. 'bracelefttp',
  3284. 'braceleftmid',
  3285. 'braceleftbt',
  3286. 'braceex',
  3287. '',
  3288. 'angleright',
  3289. 'integral',
  3290. 'integraltp',
  3291. 'integralex',
  3292. 'integralbt',
  3293. 'parenrighttp',
  3294. 'parenrightex',
  3295. 'parenrightbt',
  3296. 'bracketrighttp',
  3297. 'bracketrightex',
  3298. 'bracketrightbt',
  3299. 'bracerighttp',
  3300. 'bracerightmid',
  3301. 'bracerightbt'
  3302. ];
  3303. var ZapfDingbatsEncoding = [
  3304. '',
  3305. '',
  3306. '',
  3307. '',
  3308. '',
  3309. '',
  3310. '',
  3311. '',
  3312. '',
  3313. '',
  3314. '',
  3315. '',
  3316. '',
  3317. '',
  3318. '',
  3319. '',
  3320. '',
  3321. '',
  3322. '',
  3323. '',
  3324. '',
  3325. '',
  3326. '',
  3327. '',
  3328. '',
  3329. '',
  3330. '',
  3331. '',
  3332. '',
  3333. '',
  3334. '',
  3335. '',
  3336. 'space',
  3337. 'a1',
  3338. 'a2',
  3339. 'a202',
  3340. 'a3',
  3341. 'a4',
  3342. 'a5',
  3343. 'a119',
  3344. 'a118',
  3345. 'a117',
  3346. 'a11',
  3347. 'a12',
  3348. 'a13',
  3349. 'a14',
  3350. 'a15',
  3351. 'a16',
  3352. 'a105',
  3353. 'a17',
  3354. 'a18',
  3355. 'a19',
  3356. 'a20',
  3357. 'a21',
  3358. 'a22',
  3359. 'a23',
  3360. 'a24',
  3361. 'a25',
  3362. 'a26',
  3363. 'a27',
  3364. 'a28',
  3365. 'a6',
  3366. 'a7',
  3367. 'a8',
  3368. 'a9',
  3369. 'a10',
  3370. 'a29',
  3371. 'a30',
  3372. 'a31',
  3373. 'a32',
  3374. 'a33',
  3375. 'a34',
  3376. 'a35',
  3377. 'a36',
  3378. 'a37',
  3379. 'a38',
  3380. 'a39',
  3381. 'a40',
  3382. 'a41',
  3383. 'a42',
  3384. 'a43',
  3385. 'a44',
  3386. 'a45',
  3387. 'a46',
  3388. 'a47',
  3389. 'a48',
  3390. 'a49',
  3391. 'a50',
  3392. 'a51',
  3393. 'a52',
  3394. 'a53',
  3395. 'a54',
  3396. 'a55',
  3397. 'a56',
  3398. 'a57',
  3399. 'a58',
  3400. 'a59',
  3401. 'a60',
  3402. 'a61',
  3403. 'a62',
  3404. 'a63',
  3405. 'a64',
  3406. 'a65',
  3407. 'a66',
  3408. 'a67',
  3409. 'a68',
  3410. 'a69',
  3411. 'a70',
  3412. 'a71',
  3413. 'a72',
  3414. 'a73',
  3415. 'a74',
  3416. 'a203',
  3417. 'a75',
  3418. 'a204',
  3419. 'a76',
  3420. 'a77',
  3421. 'a78',
  3422. 'a79',
  3423. 'a81',
  3424. 'a82',
  3425. 'a83',
  3426. 'a84',
  3427. 'a97',
  3428. 'a98',
  3429. 'a99',
  3430. 'a100',
  3431. '',
  3432. 'a89',
  3433. 'a90',
  3434. 'a93',
  3435. 'a94',
  3436. 'a91',
  3437. 'a92',
  3438. 'a205',
  3439. 'a85',
  3440. 'a206',
  3441. 'a86',
  3442. 'a87',
  3443. 'a88',
  3444. 'a95',
  3445. 'a96',
  3446. '',
  3447. '',
  3448. '',
  3449. '',
  3450. '',
  3451. '',
  3452. '',
  3453. '',
  3454. '',
  3455. '',
  3456. '',
  3457. '',
  3458. '',
  3459. '',
  3460. '',
  3461. '',
  3462. '',
  3463. '',
  3464. '',
  3465. 'a101',
  3466. 'a102',
  3467. 'a103',
  3468. 'a104',
  3469. 'a106',
  3470. 'a107',
  3471. 'a108',
  3472. 'a112',
  3473. 'a111',
  3474. 'a110',
  3475. 'a109',
  3476. 'a120',
  3477. 'a121',
  3478. 'a122',
  3479. 'a123',
  3480. 'a124',
  3481. 'a125',
  3482. 'a126',
  3483. 'a127',
  3484. 'a128',
  3485. 'a129',
  3486. 'a130',
  3487. 'a131',
  3488. 'a132',
  3489. 'a133',
  3490. 'a134',
  3491. 'a135',
  3492. 'a136',
  3493. 'a137',
  3494. 'a138',
  3495. 'a139',
  3496. 'a140',
  3497. 'a141',
  3498. 'a142',
  3499. 'a143',
  3500. 'a144',
  3501. 'a145',
  3502. 'a146',
  3503. 'a147',
  3504. 'a148',
  3505. 'a149',
  3506. 'a150',
  3507. 'a151',
  3508. 'a152',
  3509. 'a153',
  3510. 'a154',
  3511. 'a155',
  3512. 'a156',
  3513. 'a157',
  3514. 'a158',
  3515. 'a159',
  3516. 'a160',
  3517. 'a161',
  3518. 'a163',
  3519. 'a164',
  3520. 'a196',
  3521. 'a165',
  3522. 'a192',
  3523. 'a166',
  3524. 'a167',
  3525. 'a168',
  3526. 'a169',
  3527. 'a170',
  3528. 'a171',
  3529. 'a172',
  3530. 'a173',
  3531. 'a162',
  3532. 'a174',
  3533. 'a175',
  3534. 'a176',
  3535. 'a177',
  3536. 'a178',
  3537. 'a179',
  3538. 'a193',
  3539. 'a180',
  3540. 'a199',
  3541. 'a181',
  3542. 'a200',
  3543. 'a182',
  3544. '',
  3545. 'a201',
  3546. 'a183',
  3547. 'a184',
  3548. 'a197',
  3549. 'a185',
  3550. 'a194',
  3551. 'a198',
  3552. 'a186',
  3553. 'a195',
  3554. 'a187',
  3555. 'a188',
  3556. 'a189',
  3557. 'a190',
  3558. 'a191'
  3559. ];
  3560. function getEncoding(encodingName) {
  3561. switch (encodingName) {
  3562. case 'WinAnsiEncoding':
  3563. return WinAnsiEncoding;
  3564. case 'StandardEncoding':
  3565. return StandardEncoding;
  3566. case 'MacRomanEncoding':
  3567. return MacRomanEncoding;
  3568. case 'SymbolSetEncoding':
  3569. return SymbolSetEncoding;
  3570. case 'ZapfDingbatsEncoding':
  3571. return ZapfDingbatsEncoding;
  3572. case 'ExpertEncoding':
  3573. return ExpertEncoding;
  3574. case 'MacExpertEncoding':
  3575. return MacExpertEncoding;
  3576. default:
  3577. return null;
  3578. }
  3579. }
  3580. exports.WinAnsiEncoding = WinAnsiEncoding;
  3581. exports.StandardEncoding = StandardEncoding;
  3582. exports.MacRomanEncoding = MacRomanEncoding;
  3583. exports.SymbolSetEncoding = SymbolSetEncoding;
  3584. exports.ZapfDingbatsEncoding = ZapfDingbatsEncoding;
  3585. exports.ExpertEncoding = ExpertEncoding;
  3586. exports.getEncoding = getEncoding;
  3587. }));
  3588. (function (root, factory) {
  3589. factory(root.pdfjsSharedUtil = {});
  3590. }(this, function (exports) {
  3591. var globalScope = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : this;
  3592. var FONT_IDENTITY_MATRIX = [
  3593. 0.001,
  3594. 0,
  3595. 0,
  3596. 0.001,
  3597. 0,
  3598. 0
  3599. ];
  3600. var TextRenderingMode = {
  3601. FILL: 0,
  3602. STROKE: 1,
  3603. FILL_STROKE: 2,
  3604. INVISIBLE: 3,
  3605. FILL_ADD_TO_PATH: 4,
  3606. STROKE_ADD_TO_PATH: 5,
  3607. FILL_STROKE_ADD_TO_PATH: 6,
  3608. ADD_TO_PATH: 7,
  3609. FILL_STROKE_MASK: 3,
  3610. ADD_TO_PATH_FLAG: 4
  3611. };
  3612. var ImageKind = {
  3613. GRAYSCALE_1BPP: 1,
  3614. RGB_24BPP: 2,
  3615. RGBA_32BPP: 3
  3616. };
  3617. var AnnotationType = {
  3618. TEXT: 1,
  3619. LINK: 2,
  3620. FREETEXT: 3,
  3621. LINE: 4,
  3622. SQUARE: 5,
  3623. CIRCLE: 6,
  3624. POLYGON: 7,
  3625. POLYLINE: 8,
  3626. HIGHLIGHT: 9,
  3627. UNDERLINE: 10,
  3628. SQUIGGLY: 11,
  3629. STRIKEOUT: 12,
  3630. STAMP: 13,
  3631. CARET: 14,
  3632. INK: 15,
  3633. POPUP: 16,
  3634. FILEATTACHMENT: 17,
  3635. SOUND: 18,
  3636. MOVIE: 19,
  3637. WIDGET: 20,
  3638. SCREEN: 21,
  3639. PRINTERMARK: 22,
  3640. TRAPNET: 23,
  3641. WATERMARK: 24,
  3642. THREED: 25,
  3643. REDACT: 26
  3644. };
  3645. var AnnotationFlag = {
  3646. INVISIBLE: 0x01,
  3647. HIDDEN: 0x02,
  3648. PRINT: 0x04,
  3649. NOZOOM: 0x08,
  3650. NOROTATE: 0x10,
  3651. NOVIEW: 0x20,
  3652. READONLY: 0x40,
  3653. LOCKED: 0x80,
  3654. TOGGLENOVIEW: 0x100,
  3655. LOCKEDCONTENTS: 0x200
  3656. };
  3657. var AnnotationFieldFlag = {
  3658. READONLY: 0x0000001,
  3659. REQUIRED: 0x0000002,
  3660. NOEXPORT: 0x0000004,
  3661. MULTILINE: 0x0001000,
  3662. PASSWORD: 0x0002000,
  3663. NOTOGGLETOOFF: 0x0004000,
  3664. RADIO: 0x0008000,
  3665. PUSHBUTTON: 0x0010000,
  3666. COMBO: 0x0020000,
  3667. EDIT: 0x0040000,
  3668. SORT: 0x0080000,
  3669. FILESELECT: 0x0100000,
  3670. MULTISELECT: 0x0200000,
  3671. DONOTSPELLCHECK: 0x0400000,
  3672. DONOTSCROLL: 0x0800000,
  3673. COMB: 0x1000000,
  3674. RICHTEXT: 0x2000000,
  3675. RADIOSINUNISON: 0x2000000,
  3676. COMMITONSELCHANGE: 0x4000000
  3677. };
  3678. var AnnotationBorderStyleType = {
  3679. SOLID: 1,
  3680. DASHED: 2,
  3681. BEVELED: 3,
  3682. INSET: 4,
  3683. UNDERLINE: 5
  3684. };
  3685. var StreamType = {
  3686. UNKNOWN: 0,
  3687. FLATE: 1,
  3688. LZW: 2,
  3689. DCT: 3,
  3690. JPX: 4,
  3691. JBIG: 5,
  3692. A85: 6,
  3693. AHX: 7,
  3694. CCF: 8,
  3695. RL: 9
  3696. };
  3697. var FontType = {
  3698. UNKNOWN: 0,
  3699. TYPE1: 1,
  3700. TYPE1C: 2,
  3701. CIDFONTTYPE0: 3,
  3702. CIDFONTTYPE0C: 4,
  3703. TRUETYPE: 5,
  3704. CIDFONTTYPE2: 6,
  3705. TYPE3: 7,
  3706. OPENTYPE: 8,
  3707. TYPE0: 9,
  3708. MMTYPE1: 10
  3709. };
  3710. var VERBOSITY_LEVELS = {
  3711. errors: 0,
  3712. warnings: 1,
  3713. infos: 5
  3714. };
  3715. // All the possible operations for an operator list.
  3716. var OPS = {
  3717. // Intentionally start from 1 so it is easy to spot bad operators that will be
  3718. // 0's.
  3719. dependency: 1,
  3720. setLineWidth: 2,
  3721. setLineCap: 3,
  3722. setLineJoin: 4,
  3723. setMiterLimit: 5,
  3724. setDash: 6,
  3725. setRenderingIntent: 7,
  3726. setFlatness: 8,
  3727. setGState: 9,
  3728. save: 10,
  3729. restore: 11,
  3730. transform: 12,
  3731. moveTo: 13,
  3732. lineTo: 14,
  3733. curveTo: 15,
  3734. curveTo2: 16,
  3735. curveTo3: 17,
  3736. closePath: 18,
  3737. rectangle: 19,
  3738. stroke: 20,
  3739. closeStroke: 21,
  3740. fill: 22,
  3741. eoFill: 23,
  3742. fillStroke: 24,
  3743. eoFillStroke: 25,
  3744. closeFillStroke: 26,
  3745. closeEOFillStroke: 27,
  3746. endPath: 28,
  3747. clip: 29,
  3748. eoClip: 30,
  3749. beginText: 31,
  3750. endText: 32,
  3751. setCharSpacing: 33,
  3752. setWordSpacing: 34,
  3753. setHScale: 35,
  3754. setLeading: 36,
  3755. setFont: 37,
  3756. setTextRenderingMode: 38,
  3757. setTextRise: 39,
  3758. moveText: 40,
  3759. setLeadingMoveText: 41,
  3760. setTextMatrix: 42,
  3761. nextLine: 43,
  3762. showText: 44,
  3763. showSpacedText: 45,
  3764. nextLineShowText: 46,
  3765. nextLineSetSpacingShowText: 47,
  3766. setCharWidth: 48,
  3767. setCharWidthAndBounds: 49,
  3768. setStrokeColorSpace: 50,
  3769. setFillColorSpace: 51,
  3770. setStrokeColor: 52,
  3771. setStrokeColorN: 53,
  3772. setFillColor: 54,
  3773. setFillColorN: 55,
  3774. setStrokeGray: 56,
  3775. setFillGray: 57,
  3776. setStrokeRGBColor: 58,
  3777. setFillRGBColor: 59,
  3778. setStrokeCMYKColor: 60,
  3779. setFillCMYKColor: 61,
  3780. shadingFill: 62,
  3781. beginInlineImage: 63,
  3782. beginImageData: 64,
  3783. endInlineImage: 65,
  3784. paintXObject: 66,
  3785. markPoint: 67,
  3786. markPointProps: 68,
  3787. beginMarkedContent: 69,
  3788. beginMarkedContentProps: 70,
  3789. endMarkedContent: 71,
  3790. beginCompat: 72,
  3791. endCompat: 73,
  3792. paintFormXObjectBegin: 74,
  3793. paintFormXObjectEnd: 75,
  3794. beginGroup: 76,
  3795. endGroup: 77,
  3796. beginAnnotations: 78,
  3797. endAnnotations: 79,
  3798. beginAnnotation: 80,
  3799. endAnnotation: 81,
  3800. paintJpegXObject: 82,
  3801. paintImageMaskXObject: 83,
  3802. paintImageMaskXObjectGroup: 84,
  3803. paintImageXObject: 85,
  3804. paintInlineImageXObject: 86,
  3805. paintInlineImageXObjectGroup: 87,
  3806. paintImageXObjectRepeat: 88,
  3807. paintImageMaskXObjectRepeat: 89,
  3808. paintSolidColorImageMask: 90,
  3809. constructPath: 91
  3810. };
  3811. var verbosity = VERBOSITY_LEVELS.warnings;
  3812. function setVerbosityLevel(level) {
  3813. verbosity = level;
  3814. }
  3815. function getVerbosityLevel() {
  3816. return verbosity;
  3817. }
  3818. // A notice for devs. These are good for things that are helpful to devs, such
  3819. // as warning that Workers were disabled, which is important to devs but not
  3820. // end users.
  3821. function info(msg) {
  3822. if (verbosity >= VERBOSITY_LEVELS.infos) {
  3823. console.log('Info: ' + msg);
  3824. }
  3825. }
  3826. // Non-fatal warnings.
  3827. function warn(msg) {
  3828. if (verbosity >= VERBOSITY_LEVELS.warnings) {
  3829. console.log('Warning: ' + msg);
  3830. }
  3831. }
  3832. // Deprecated API function -- display regardless of the PDFJS.verbosity setting.
  3833. function deprecated(details) {
  3834. console.log('Deprecated API usage: ' + details);
  3835. }
  3836. // Fatal errors that should trigger the fallback UI and halt execution by
  3837. // throwing an exception.
  3838. function error(msg) {
  3839. if (verbosity >= VERBOSITY_LEVELS.errors) {
  3840. console.log('Error: ' + msg);
  3841. console.log(backtrace());
  3842. }
  3843. throw new Error(msg);
  3844. }
  3845. function backtrace() {
  3846. try {
  3847. throw new Error();
  3848. } catch (e) {
  3849. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  3850. }
  3851. }
  3852. function assert(cond, msg) {
  3853. if (!cond) {
  3854. error(msg);
  3855. }
  3856. }
  3857. var UNSUPPORTED_FEATURES = {
  3858. unknown: 'unknown',
  3859. forms: 'forms',
  3860. javaScript: 'javaScript',
  3861. smask: 'smask',
  3862. shadingPattern: 'shadingPattern',
  3863. font: 'font'
  3864. };
  3865. // Checks if URLs have the same origin. For non-HTTP based URLs, returns false.
  3866. function isSameOrigin(baseUrl, otherUrl) {
  3867. try {
  3868. var base = new URL(baseUrl);
  3869. if (!base.origin || base.origin === 'null') {
  3870. return false;
  3871. }
  3872. } // non-HTTP url
  3873. catch (e) {
  3874. return false;
  3875. }
  3876. var other = new URL(otherUrl, base);
  3877. return base.origin === other.origin;
  3878. }
  3879. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  3880. function isValidUrl(url, allowRelative) {
  3881. if (!url || typeof url !== 'string') {
  3882. return false;
  3883. }
  3884. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  3885. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  3886. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  3887. if (!protocol) {
  3888. return allowRelative;
  3889. }
  3890. protocol = protocol[0].toLowerCase();
  3891. switch (protocol) {
  3892. case 'http':
  3893. case 'https':
  3894. case 'ftp':
  3895. case 'mailto':
  3896. case 'tel':
  3897. return true;
  3898. default:
  3899. return false;
  3900. }
  3901. }
  3902. function shadow(obj, prop, value) {
  3903. Object.defineProperty(obj, prop, {
  3904. value: value,
  3905. enumerable: true,
  3906. configurable: true,
  3907. writable: false
  3908. });
  3909. return value;
  3910. }
  3911. function getLookupTableFactory(initializer) {
  3912. var lookup;
  3913. return function () {
  3914. if (initializer) {
  3915. lookup = Object.create(null);
  3916. initializer(lookup);
  3917. initializer = null;
  3918. }
  3919. return lookup;
  3920. };
  3921. }
  3922. var PasswordResponses = {
  3923. NEED_PASSWORD: 1,
  3924. INCORRECT_PASSWORD: 2
  3925. };
  3926. var PasswordException = function PasswordExceptionClosure() {
  3927. function PasswordException(msg, code) {
  3928. this.name = 'PasswordException';
  3929. this.message = msg;
  3930. this.code = code;
  3931. }
  3932. PasswordException.prototype = new Error();
  3933. PasswordException.constructor = PasswordException;
  3934. return PasswordException;
  3935. }();
  3936. var UnknownErrorException = function UnknownErrorExceptionClosure() {
  3937. function UnknownErrorException(msg, details) {
  3938. this.name = 'UnknownErrorException';
  3939. this.message = msg;
  3940. this.details = details;
  3941. }
  3942. UnknownErrorException.prototype = new Error();
  3943. UnknownErrorException.constructor = UnknownErrorException;
  3944. return UnknownErrorException;
  3945. }();
  3946. var InvalidPDFException = function InvalidPDFExceptionClosure() {
  3947. function InvalidPDFException(msg) {
  3948. this.name = 'InvalidPDFException';
  3949. this.message = msg;
  3950. }
  3951. InvalidPDFException.prototype = new Error();
  3952. InvalidPDFException.constructor = InvalidPDFException;
  3953. return InvalidPDFException;
  3954. }();
  3955. var MissingPDFException = function MissingPDFExceptionClosure() {
  3956. function MissingPDFException(msg) {
  3957. this.name = 'MissingPDFException';
  3958. this.message = msg;
  3959. }
  3960. MissingPDFException.prototype = new Error();
  3961. MissingPDFException.constructor = MissingPDFException;
  3962. return MissingPDFException;
  3963. }();
  3964. var UnexpectedResponseException = function UnexpectedResponseExceptionClosure() {
  3965. function UnexpectedResponseException(msg, status) {
  3966. this.name = 'UnexpectedResponseException';
  3967. this.message = msg;
  3968. this.status = status;
  3969. }
  3970. UnexpectedResponseException.prototype = new Error();
  3971. UnexpectedResponseException.constructor = UnexpectedResponseException;
  3972. return UnexpectedResponseException;
  3973. }();
  3974. var NotImplementedException = function NotImplementedExceptionClosure() {
  3975. function NotImplementedException(msg) {
  3976. this.message = msg;
  3977. }
  3978. NotImplementedException.prototype = new Error();
  3979. NotImplementedException.prototype.name = 'NotImplementedException';
  3980. NotImplementedException.constructor = NotImplementedException;
  3981. return NotImplementedException;
  3982. }();
  3983. var MissingDataException = function MissingDataExceptionClosure() {
  3984. function MissingDataException(begin, end) {
  3985. this.begin = begin;
  3986. this.end = end;
  3987. this.message = 'Missing data [' + begin + ', ' + end + ')';
  3988. }
  3989. MissingDataException.prototype = new Error();
  3990. MissingDataException.prototype.name = 'MissingDataException';
  3991. MissingDataException.constructor = MissingDataException;
  3992. return MissingDataException;
  3993. }();
  3994. var XRefParseException = function XRefParseExceptionClosure() {
  3995. function XRefParseException(msg) {
  3996. this.message = msg;
  3997. }
  3998. XRefParseException.prototype = new Error();
  3999. XRefParseException.prototype.name = 'XRefParseException';
  4000. XRefParseException.constructor = XRefParseException;
  4001. return XRefParseException;
  4002. }();
  4003. var NullCharactersRegExp = /\x00/g;
  4004. function removeNullCharacters(str) {
  4005. if (typeof str !== 'string') {
  4006. warn('The argument for removeNullCharacters must be a string.');
  4007. return str;
  4008. }
  4009. return str.replace(NullCharactersRegExp, '');
  4010. }
  4011. function bytesToString(bytes) {
  4012. assert(bytes !== null && typeof bytes === 'object' && bytes.length !== undefined, 'Invalid argument for bytesToString');
  4013. var length = bytes.length;
  4014. var MAX_ARGUMENT_COUNT = 8192;
  4015. if (length < MAX_ARGUMENT_COUNT) {
  4016. return String.fromCharCode.apply(null, bytes);
  4017. }
  4018. var strBuf = [];
  4019. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  4020. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  4021. var chunk = bytes.subarray(i, chunkEnd);
  4022. strBuf.push(String.fromCharCode.apply(null, chunk));
  4023. }
  4024. return strBuf.join('');
  4025. }
  4026. function stringToBytes(str) {
  4027. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  4028. var length = str.length;
  4029. var bytes = new Uint8Array(length);
  4030. for (var i = 0; i < length; ++i) {
  4031. bytes[i] = str.charCodeAt(i) & 0xFF;
  4032. }
  4033. return bytes;
  4034. }
  4035. /**
  4036. * Gets length of the array (Array, Uint8Array, or string) in bytes.
  4037. * @param {Array|Uint8Array|string} arr
  4038. * @returns {number}
  4039. */
  4040. function arrayByteLength(arr) {
  4041. if (arr.length !== undefined) {
  4042. return arr.length;
  4043. }
  4044. assert(arr.byteLength !== undefined);
  4045. return arr.byteLength;
  4046. }
  4047. /**
  4048. * Combines array items (arrays) into single Uint8Array object.
  4049. * @param {Array} arr - the array of the arrays (Array, Uint8Array, or string).
  4050. * @returns {Uint8Array}
  4051. */
  4052. function arraysToBytes(arr) {
  4053. // Shortcut: if first and only item is Uint8Array, return it.
  4054. if (arr.length === 1 && arr[0] instanceof Uint8Array) {
  4055. return arr[0];
  4056. }
  4057. var resultLength = 0;
  4058. var i, ii = arr.length;
  4059. var item, itemLength;
  4060. for (i = 0; i < ii; i++) {
  4061. item = arr[i];
  4062. itemLength = arrayByteLength(item);
  4063. resultLength += itemLength;
  4064. }
  4065. var pos = 0;
  4066. var data = new Uint8Array(resultLength);
  4067. for (i = 0; i < ii; i++) {
  4068. item = arr[i];
  4069. if (!(item instanceof Uint8Array)) {
  4070. if (typeof item === 'string') {
  4071. item = stringToBytes(item);
  4072. } else {
  4073. item = new Uint8Array(item);
  4074. }
  4075. }
  4076. itemLength = item.byteLength;
  4077. data.set(item, pos);
  4078. pos += itemLength;
  4079. }
  4080. return data;
  4081. }
  4082. function string32(value) {
  4083. return String.fromCharCode(value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff);
  4084. }
  4085. function log2(x) {
  4086. var n = 1, i = 0;
  4087. while (x > n) {
  4088. n <<= 1;
  4089. i++;
  4090. }
  4091. return i;
  4092. }
  4093. function readInt8(data, start) {
  4094. return data[start] << 24 >> 24;
  4095. }
  4096. function readUint16(data, offset) {
  4097. return data[offset] << 8 | data[offset + 1];
  4098. }
  4099. function readUint32(data, offset) {
  4100. return (data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3]) >>> 0;
  4101. }
  4102. // Lazy test the endianness of the platform
  4103. // NOTE: This will be 'true' for simulated TypedArrays
  4104. function isLittleEndian() {
  4105. var buffer8 = new Uint8Array(2);
  4106. buffer8[0] = 1;
  4107. var buffer16 = new Uint16Array(buffer8.buffer);
  4108. return buffer16[0] === 1;
  4109. }
  4110. // Checks if it's possible to eval JS expressions.
  4111. function isEvalSupported() {
  4112. try {
  4113. new Function('');
  4114. return true;
  4115. } catch (e) {
  4116. return false;
  4117. }
  4118. }
  4119. var Uint32ArrayView = function Uint32ArrayViewClosure() {
  4120. function Uint32ArrayView(buffer, length) {
  4121. this.buffer = buffer;
  4122. this.byteLength = buffer.length;
  4123. this.length = length === undefined ? this.byteLength >> 2 : length;
  4124. ensureUint32ArrayViewProps(this.length);
  4125. }
  4126. Uint32ArrayView.prototype = Object.create(null);
  4127. var uint32ArrayViewSetters = 0;
  4128. function createUint32ArrayProp(index) {
  4129. return {
  4130. get: function () {
  4131. var buffer = this.buffer, offset = index << 2;
  4132. return (buffer[offset] | buffer[offset + 1] << 8 | buffer[offset + 2] << 16 | buffer[offset + 3] << 24) >>> 0;
  4133. },
  4134. set: function (value) {
  4135. var buffer = this.buffer, offset = index << 2;
  4136. buffer[offset] = value & 255;
  4137. buffer[offset + 1] = value >> 8 & 255;
  4138. buffer[offset + 2] = value >> 16 & 255;
  4139. buffer[offset + 3] = value >>> 24 & 255;
  4140. }
  4141. };
  4142. }
  4143. function ensureUint32ArrayViewProps(length) {
  4144. while (uint32ArrayViewSetters < length) {
  4145. Object.defineProperty(Uint32ArrayView.prototype, uint32ArrayViewSetters, createUint32ArrayProp(uint32ArrayViewSetters));
  4146. uint32ArrayViewSetters++;
  4147. }
  4148. }
  4149. return Uint32ArrayView;
  4150. }();
  4151. exports.Uint32ArrayView = Uint32ArrayView;
  4152. var IDENTITY_MATRIX = [
  4153. 1,
  4154. 0,
  4155. 0,
  4156. 1,
  4157. 0,
  4158. 0
  4159. ];
  4160. var Util = function UtilClosure() {
  4161. function Util() {
  4162. }
  4163. var rgbBuf = [
  4164. 'rgb(',
  4165. 0,
  4166. ',',
  4167. 0,
  4168. ',',
  4169. 0,
  4170. ')'
  4171. ];
  4172. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  4173. // creating many intermediate strings.
  4174. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  4175. rgbBuf[1] = r;
  4176. rgbBuf[3] = g;
  4177. rgbBuf[5] = b;
  4178. return rgbBuf.join('');
  4179. };
  4180. // Concatenates two transformation matrices together and returns the result.
  4181. Util.transform = function Util_transform(m1, m2) {
  4182. return [
  4183. m1[0] * m2[0] + m1[2] * m2[1],
  4184. m1[1] * m2[0] + m1[3] * m2[1],
  4185. m1[0] * m2[2] + m1[2] * m2[3],
  4186. m1[1] * m2[2] + m1[3] * m2[3],
  4187. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  4188. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  4189. ];
  4190. };
  4191. // For 2d affine transforms
  4192. Util.applyTransform = function Util_applyTransform(p, m) {
  4193. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  4194. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  4195. return [
  4196. xt,
  4197. yt
  4198. ];
  4199. };
  4200. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  4201. var d = m[0] * m[3] - m[1] * m[2];
  4202. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  4203. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  4204. return [
  4205. xt,
  4206. yt
  4207. ];
  4208. };
  4209. // Applies the transform to the rectangle and finds the minimum axially
  4210. // aligned bounding box.
  4211. Util.getAxialAlignedBoundingBox = function Util_getAxialAlignedBoundingBox(r, m) {
  4212. var p1 = Util.applyTransform(r, m);
  4213. var p2 = Util.applyTransform(r.slice(2, 4), m);
  4214. var p3 = Util.applyTransform([
  4215. r[0],
  4216. r[3]
  4217. ], m);
  4218. var p4 = Util.applyTransform([
  4219. r[2],
  4220. r[1]
  4221. ], m);
  4222. return [
  4223. Math.min(p1[0], p2[0], p3[0], p4[0]),
  4224. Math.min(p1[1], p2[1], p3[1], p4[1]),
  4225. Math.max(p1[0], p2[0], p3[0], p4[0]),
  4226. Math.max(p1[1], p2[1], p3[1], p4[1])
  4227. ];
  4228. };
  4229. Util.inverseTransform = function Util_inverseTransform(m) {
  4230. var d = m[0] * m[3] - m[1] * m[2];
  4231. return [
  4232. m[3] / d,
  4233. -m[1] / d,
  4234. -m[2] / d,
  4235. m[0] / d,
  4236. (m[2] * m[5] - m[4] * m[3]) / d,
  4237. (m[4] * m[1] - m[5] * m[0]) / d
  4238. ];
  4239. };
  4240. // Apply a generic 3d matrix M on a 3-vector v:
  4241. // | a b c | | X |
  4242. // | d e f | x | Y |
  4243. // | g h i | | Z |
  4244. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  4245. // with v as [X,Y,Z]
  4246. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  4247. return [
  4248. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  4249. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  4250. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  4251. ];
  4252. };
  4253. // This calculation uses Singular Value Decomposition.
  4254. // The SVD can be represented with formula A = USV. We are interested in the
  4255. // matrix S here because it represents the scale values.
  4256. Util.singularValueDecompose2dScale = function Util_singularValueDecompose2dScale(m) {
  4257. var transpose = [
  4258. m[0],
  4259. m[2],
  4260. m[1],
  4261. m[3]
  4262. ];
  4263. // Multiply matrix m with its transpose.
  4264. var a = m[0] * transpose[0] + m[1] * transpose[2];
  4265. var b = m[0] * transpose[1] + m[1] * transpose[3];
  4266. var c = m[2] * transpose[0] + m[3] * transpose[2];
  4267. var d = m[2] * transpose[1] + m[3] * transpose[3];
  4268. // Solve the second degree polynomial to get roots.
  4269. var first = (a + d) / 2;
  4270. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  4271. var sx = first + second || 1;
  4272. var sy = first - second || 1;
  4273. // Scale values are the square roots of the eigenvalues.
  4274. return [
  4275. Math.sqrt(sx),
  4276. Math.sqrt(sy)
  4277. ];
  4278. };
  4279. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  4280. // For coordinate systems whose origin lies in the bottom-left, this
  4281. // means normalization to (BL,TR) ordering. For systems with origin in the
  4282. // top-left, this means (TL,BR) ordering.
  4283. Util.normalizeRect = function Util_normalizeRect(rect) {
  4284. var r = rect.slice(0);
  4285. // clone rect
  4286. if (rect[0] > rect[2]) {
  4287. r[0] = rect[2];
  4288. r[2] = rect[0];
  4289. }
  4290. if (rect[1] > rect[3]) {
  4291. r[1] = rect[3];
  4292. r[3] = rect[1];
  4293. }
  4294. return r;
  4295. };
  4296. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  4297. // intersection of rect1 and rect2. If no intersection, returns 'false'
  4298. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  4299. Util.intersect = function Util_intersect(rect1, rect2) {
  4300. function compare(a, b) {
  4301. return a - b;
  4302. }
  4303. // Order points along the axes
  4304. var orderedX = [
  4305. rect1[0],
  4306. rect1[2],
  4307. rect2[0],
  4308. rect2[2]
  4309. ].sort(compare), orderedY = [
  4310. rect1[1],
  4311. rect1[3],
  4312. rect2[1],
  4313. rect2[3]
  4314. ].sort(compare), result = [];
  4315. rect1 = Util.normalizeRect(rect1);
  4316. rect2 = Util.normalizeRect(rect2);
  4317. // X: first and second points belong to different rectangles?
  4318. if (orderedX[0] === rect1[0] && orderedX[1] === rect2[0] || orderedX[0] === rect2[0] && orderedX[1] === rect1[0]) {
  4319. // Intersection must be between second and third points
  4320. result[0] = orderedX[1];
  4321. result[2] = orderedX[2];
  4322. } else {
  4323. return false;
  4324. }
  4325. // Y: first and second points belong to different rectangles?
  4326. if (orderedY[0] === rect1[1] && orderedY[1] === rect2[1] || orderedY[0] === rect2[1] && orderedY[1] === rect1[1]) {
  4327. // Intersection must be between second and third points
  4328. result[1] = orderedY[1];
  4329. result[3] = orderedY[2];
  4330. } else {
  4331. return false;
  4332. }
  4333. return result;
  4334. };
  4335. Util.sign = function Util_sign(num) {
  4336. return num < 0 ? -1 : 1;
  4337. };
  4338. var ROMAN_NUMBER_MAP = [
  4339. '',
  4340. 'C',
  4341. 'CC',
  4342. 'CCC',
  4343. 'CD',
  4344. 'D',
  4345. 'DC',
  4346. 'DCC',
  4347. 'DCCC',
  4348. 'CM',
  4349. '',
  4350. 'X',
  4351. 'XX',
  4352. 'XXX',
  4353. 'XL',
  4354. 'L',
  4355. 'LX',
  4356. 'LXX',
  4357. 'LXXX',
  4358. 'XC',
  4359. '',
  4360. 'I',
  4361. 'II',
  4362. 'III',
  4363. 'IV',
  4364. 'V',
  4365. 'VI',
  4366. 'VII',
  4367. 'VIII',
  4368. 'IX'
  4369. ];
  4370. /**
  4371. * Converts positive integers to (upper case) Roman numerals.
  4372. * @param {integer} number - The number that should be converted.
  4373. * @param {boolean} lowerCase - Indicates if the result should be converted
  4374. * to lower case letters. The default is false.
  4375. * @return {string} The resulting Roman number.
  4376. */
  4377. Util.toRoman = function Util_toRoman(number, lowerCase) {
  4378. assert(isInt(number) && number > 0, 'The number should be a positive integer.');
  4379. var pos, romanBuf = [];
  4380. // Thousands
  4381. while (number >= 1000) {
  4382. number -= 1000;
  4383. romanBuf.push('M');
  4384. }
  4385. // Hundreds
  4386. pos = number / 100 | 0;
  4387. number %= 100;
  4388. romanBuf.push(ROMAN_NUMBER_MAP[pos]);
  4389. // Tens
  4390. pos = number / 10 | 0;
  4391. number %= 10;
  4392. romanBuf.push(ROMAN_NUMBER_MAP[10 + pos]);
  4393. // Ones
  4394. romanBuf.push(ROMAN_NUMBER_MAP[20 + number]);
  4395. var romanStr = romanBuf.join('');
  4396. return lowerCase ? romanStr.toLowerCase() : romanStr;
  4397. };
  4398. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  4399. Array.prototype.push.apply(arr1, arr2);
  4400. };
  4401. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  4402. Array.prototype.unshift.apply(arr1, arr2);
  4403. };
  4404. Util.extendObj = function extendObj(obj1, obj2) {
  4405. for (var key in obj2) {
  4406. obj1[key] = obj2[key];
  4407. }
  4408. };
  4409. Util.getInheritableProperty = function Util_getInheritableProperty(dict, name, getArray) {
  4410. while (dict && !dict.has(name)) {
  4411. dict = dict.get('Parent');
  4412. }
  4413. if (!dict) {
  4414. return null;
  4415. }
  4416. return getArray ? dict.getArray(name) : dict.get(name);
  4417. };
  4418. Util.inherit = function Util_inherit(sub, base, prototype) {
  4419. sub.prototype = Object.create(base.prototype);
  4420. sub.prototype.constructor = sub;
  4421. for (var prop in prototype) {
  4422. sub.prototype[prop] = prototype[prop];
  4423. }
  4424. };
  4425. Util.loadScript = function Util_loadScript(src, callback) {
  4426. var script = document.createElement('script');
  4427. var loaded = false;
  4428. script.setAttribute('src', src);
  4429. if (callback) {
  4430. script.onload = function () {
  4431. if (!loaded) {
  4432. callback();
  4433. }
  4434. loaded = true;
  4435. };
  4436. }
  4437. document.getElementsByTagName('head')[0].appendChild(script);
  4438. };
  4439. return Util;
  4440. }();
  4441. /**
  4442. * PDF page viewport created based on scale, rotation and offset.
  4443. * @class
  4444. * @alias PageViewport
  4445. */
  4446. var PageViewport = function PageViewportClosure() {
  4447. /**
  4448. * @constructor
  4449. * @private
  4450. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  4451. * @param scale {number} scale of the viewport.
  4452. * @param rotation {number} rotations of the viewport in degrees.
  4453. * @param offsetX {number} offset X
  4454. * @param offsetY {number} offset Y
  4455. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  4456. */
  4457. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  4458. this.viewBox = viewBox;
  4459. this.scale = scale;
  4460. this.rotation = rotation;
  4461. this.offsetX = offsetX;
  4462. this.offsetY = offsetY;
  4463. // creating transform to convert pdf coordinate system to the normal
  4464. // canvas like coordinates taking in account scale and rotation
  4465. var centerX = (viewBox[2] + viewBox[0]) / 2;
  4466. var centerY = (viewBox[3] + viewBox[1]) / 2;
  4467. var rotateA, rotateB, rotateC, rotateD;
  4468. rotation = rotation % 360;
  4469. rotation = rotation < 0 ? rotation + 360 : rotation;
  4470. switch (rotation) {
  4471. case 180:
  4472. rotateA = -1;
  4473. rotateB = 0;
  4474. rotateC = 0;
  4475. rotateD = 1;
  4476. break;
  4477. case 90:
  4478. rotateA = 0;
  4479. rotateB = 1;
  4480. rotateC = 1;
  4481. rotateD = 0;
  4482. break;
  4483. case 270:
  4484. rotateA = 0;
  4485. rotateB = -1;
  4486. rotateC = -1;
  4487. rotateD = 0;
  4488. break;
  4489. //case 0:
  4490. default:
  4491. rotateA = 1;
  4492. rotateB = 0;
  4493. rotateC = 0;
  4494. rotateD = -1;
  4495. break;
  4496. }
  4497. if (dontFlip) {
  4498. rotateC = -rotateC;
  4499. rotateD = -rotateD;
  4500. }
  4501. var offsetCanvasX, offsetCanvasY;
  4502. var width, height;
  4503. if (rotateA === 0) {
  4504. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  4505. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  4506. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  4507. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  4508. } else {
  4509. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  4510. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  4511. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  4512. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  4513. }
  4514. // creating transform for the following operations:
  4515. // translate(-centerX, -centerY), rotate and flip vertically,
  4516. // scale, and translate(offsetCanvasX, offsetCanvasY)
  4517. this.transform = [
  4518. rotateA * scale,
  4519. rotateB * scale,
  4520. rotateC * scale,
  4521. rotateD * scale,
  4522. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  4523. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  4524. ];
  4525. this.width = width;
  4526. this.height = height;
  4527. this.fontScale = scale;
  4528. }
  4529. PageViewport.prototype = /** @lends PageViewport.prototype */
  4530. {
  4531. /**
  4532. * Clones viewport with additional properties.
  4533. * @param args {Object} (optional) If specified, may contain the 'scale' or
  4534. * 'rotation' properties to override the corresponding properties in
  4535. * the cloned viewport.
  4536. * @returns {PageViewport} Cloned viewport.
  4537. */
  4538. clone: function PageViewPort_clone(args) {
  4539. args = args || {};
  4540. var scale = 'scale' in args ? args.scale : this.scale;
  4541. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  4542. return new PageViewport(this.viewBox.slice(), scale, rotation, this.offsetX, this.offsetY, args.dontFlip);
  4543. },
  4544. /**
  4545. * Converts PDF point to the viewport coordinates. For examples, useful for
  4546. * converting PDF location into canvas pixel coordinates.
  4547. * @param x {number} X coordinate.
  4548. * @param y {number} Y coordinate.
  4549. * @returns {Object} Object that contains 'x' and 'y' properties of the
  4550. * point in the viewport coordinate space.
  4551. * @see {@link convertToPdfPoint}
  4552. * @see {@link convertToViewportRectangle}
  4553. */
  4554. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  4555. return Util.applyTransform([
  4556. x,
  4557. y
  4558. ], this.transform);
  4559. },
  4560. /**
  4561. * Converts PDF rectangle to the viewport coordinates.
  4562. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  4563. * @returns {Array} Contains corresponding coordinates of the rectangle
  4564. * in the viewport coordinate space.
  4565. * @see {@link convertToViewportPoint}
  4566. */
  4567. convertToViewportRectangle: function PageViewport_convertToViewportRectangle(rect) {
  4568. var tl = Util.applyTransform([
  4569. rect[0],
  4570. rect[1]
  4571. ], this.transform);
  4572. var br = Util.applyTransform([
  4573. rect[2],
  4574. rect[3]
  4575. ], this.transform);
  4576. return [
  4577. tl[0],
  4578. tl[1],
  4579. br[0],
  4580. br[1]
  4581. ];
  4582. },
  4583. /**
  4584. * Converts viewport coordinates to the PDF location. For examples, useful
  4585. * for converting canvas pixel location into PDF one.
  4586. * @param x {number} X coordinate.
  4587. * @param y {number} Y coordinate.
  4588. * @returns {Object} Object that contains 'x' and 'y' properties of the
  4589. * point in the PDF coordinate space.
  4590. * @see {@link convertToViewportPoint}
  4591. */
  4592. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  4593. return Util.applyInverseTransform([
  4594. x,
  4595. y
  4596. ], this.transform);
  4597. }
  4598. };
  4599. return PageViewport;
  4600. }();
  4601. var PDFStringTranslateTable = [
  4602. 0,
  4603. 0,
  4604. 0,
  4605. 0,
  4606. 0,
  4607. 0,
  4608. 0,
  4609. 0,
  4610. 0,
  4611. 0,
  4612. 0,
  4613. 0,
  4614. 0,
  4615. 0,
  4616. 0,
  4617. 0,
  4618. 0,
  4619. 0,
  4620. 0,
  4621. 0,
  4622. 0,
  4623. 0,
  4624. 0,
  4625. 0,
  4626. 0x2D8,
  4627. 0x2C7,
  4628. 0x2C6,
  4629. 0x2D9,
  4630. 0x2DD,
  4631. 0x2DB,
  4632. 0x2DA,
  4633. 0x2DC,
  4634. 0,
  4635. 0,
  4636. 0,
  4637. 0,
  4638. 0,
  4639. 0,
  4640. 0,
  4641. 0,
  4642. 0,
  4643. 0,
  4644. 0,
  4645. 0,
  4646. 0,
  4647. 0,
  4648. 0,
  4649. 0,
  4650. 0,
  4651. 0,
  4652. 0,
  4653. 0,
  4654. 0,
  4655. 0,
  4656. 0,
  4657. 0,
  4658. 0,
  4659. 0,
  4660. 0,
  4661. 0,
  4662. 0,
  4663. 0,
  4664. 0,
  4665. 0,
  4666. 0,
  4667. 0,
  4668. 0,
  4669. 0,
  4670. 0,
  4671. 0,
  4672. 0,
  4673. 0,
  4674. 0,
  4675. 0,
  4676. 0,
  4677. 0,
  4678. 0,
  4679. 0,
  4680. 0,
  4681. 0,
  4682. 0,
  4683. 0,
  4684. 0,
  4685. 0,
  4686. 0,
  4687. 0,
  4688. 0,
  4689. 0,
  4690. 0,
  4691. 0,
  4692. 0,
  4693. 0,
  4694. 0,
  4695. 0,
  4696. 0,
  4697. 0,
  4698. 0,
  4699. 0,
  4700. 0,
  4701. 0,
  4702. 0,
  4703. 0,
  4704. 0,
  4705. 0,
  4706. 0,
  4707. 0,
  4708. 0,
  4709. 0,
  4710. 0,
  4711. 0,
  4712. 0,
  4713. 0,
  4714. 0,
  4715. 0,
  4716. 0,
  4717. 0,
  4718. 0,
  4719. 0,
  4720. 0,
  4721. 0,
  4722. 0,
  4723. 0,
  4724. 0,
  4725. 0,
  4726. 0,
  4727. 0,
  4728. 0,
  4729. 0,
  4730. 0x2022,
  4731. 0x2020,
  4732. 0x2021,
  4733. 0x2026,
  4734. 0x2014,
  4735. 0x2013,
  4736. 0x192,
  4737. 0x2044,
  4738. 0x2039,
  4739. 0x203A,
  4740. 0x2212,
  4741. 0x2030,
  4742. 0x201E,
  4743. 0x201C,
  4744. 0x201D,
  4745. 0x2018,
  4746. 0x2019,
  4747. 0x201A,
  4748. 0x2122,
  4749. 0xFB01,
  4750. 0xFB02,
  4751. 0x141,
  4752. 0x152,
  4753. 0x160,
  4754. 0x178,
  4755. 0x17D,
  4756. 0x131,
  4757. 0x142,
  4758. 0x153,
  4759. 0x161,
  4760. 0x17E,
  4761. 0,
  4762. 0x20AC
  4763. ];
  4764. function stringToPDFString(str) {
  4765. var i, n = str.length, strBuf = [];
  4766. if (str[0] === '\xFE' && str[1] === '\xFF') {
  4767. // UTF16BE BOM
  4768. for (i = 2; i < n; i += 2) {
  4769. strBuf.push(String.fromCharCode(str.charCodeAt(i) << 8 | str.charCodeAt(i + 1)));
  4770. }
  4771. } else {
  4772. for (i = 0; i < n; ++i) {
  4773. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  4774. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  4775. }
  4776. }
  4777. return strBuf.join('');
  4778. }
  4779. function stringToUTF8String(str) {
  4780. return decodeURIComponent(escape(str));
  4781. }
  4782. function utf8StringToString(str) {
  4783. return unescape(encodeURIComponent(str));
  4784. }
  4785. function isEmptyObj(obj) {
  4786. for (var key in obj) {
  4787. return false;
  4788. }
  4789. return true;
  4790. }
  4791. function isBool(v) {
  4792. return typeof v === 'boolean';
  4793. }
  4794. function isInt(v) {
  4795. return typeof v === 'number' && (v | 0) === v;
  4796. }
  4797. function isNum(v) {
  4798. return typeof v === 'number';
  4799. }
  4800. function isString(v) {
  4801. return typeof v === 'string';
  4802. }
  4803. function isArray(v) {
  4804. return v instanceof Array;
  4805. }
  4806. function isArrayBuffer(v) {
  4807. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  4808. }
  4809. // Checks if ch is one of the following characters: SPACE, TAB, CR or LF.
  4810. function isSpace(ch) {
  4811. return ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A;
  4812. }
  4813. /**
  4814. * Promise Capability object.
  4815. *
  4816. * @typedef {Object} PromiseCapability
  4817. * @property {Promise} promise - A promise object.
  4818. * @property {function} resolve - Fulfills the promise.
  4819. * @property {function} reject - Rejects the promise.
  4820. */
  4821. /**
  4822. * Creates a promise capability object.
  4823. * @alias createPromiseCapability
  4824. *
  4825. * @return {PromiseCapability} A capability object contains:
  4826. * - a Promise, resolve and reject methods.
  4827. */
  4828. function createPromiseCapability() {
  4829. var capability = {};
  4830. capability.promise = new Promise(function (resolve, reject) {
  4831. capability.resolve = resolve;
  4832. capability.reject = reject;
  4833. });
  4834. return capability;
  4835. }
  4836. /**
  4837. * Polyfill for Promises:
  4838. * The following promise implementation tries to generally implement the
  4839. * Promise/A+ spec. Some notable differences from other promise libraries are:
  4840. * - There currently isn't a separate deferred and promise object.
  4841. * - Unhandled rejections eventually show an error if they aren't handled.
  4842. *
  4843. * Based off of the work in:
  4844. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  4845. */
  4846. (function PromiseClosure() {
  4847. if (globalScope.Promise) {
  4848. // Promises existing in the DOM/Worker, checking presence of all/resolve
  4849. if (typeof globalScope.Promise.all !== 'function') {
  4850. globalScope.Promise.all = function (iterable) {
  4851. var count = 0, results = [], resolve, reject;
  4852. var promise = new globalScope.Promise(function (resolve_, reject_) {
  4853. resolve = resolve_;
  4854. reject = reject_;
  4855. });
  4856. iterable.forEach(function (p, i) {
  4857. count++;
  4858. p.then(function (result) {
  4859. results[i] = result;
  4860. count--;
  4861. if (count === 0) {
  4862. resolve(results);
  4863. }
  4864. }, reject);
  4865. });
  4866. if (count === 0) {
  4867. resolve(results);
  4868. }
  4869. return promise;
  4870. };
  4871. }
  4872. if (typeof globalScope.Promise.resolve !== 'function') {
  4873. globalScope.Promise.resolve = function (value) {
  4874. return new globalScope.Promise(function (resolve) {
  4875. resolve(value);
  4876. });
  4877. };
  4878. }
  4879. if (typeof globalScope.Promise.reject !== 'function') {
  4880. globalScope.Promise.reject = function (reason) {
  4881. return new globalScope.Promise(function (resolve, reject) {
  4882. reject(reason);
  4883. });
  4884. };
  4885. }
  4886. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  4887. globalScope.Promise.prototype.catch = function (onReject) {
  4888. return globalScope.Promise.prototype.then(undefined, onReject);
  4889. };
  4890. }
  4891. return;
  4892. }
  4893. var STATUS_PENDING = 0;
  4894. var STATUS_RESOLVED = 1;
  4895. var STATUS_REJECTED = 2;
  4896. // In an attempt to avoid silent exceptions, unhandled rejections are
  4897. // tracked and if they aren't handled in a certain amount of time an
  4898. // error is logged.
  4899. var REJECTION_TIMEOUT = 500;
  4900. var HandlerManager = {
  4901. handlers: [],
  4902. running: false,
  4903. unhandledRejections: [],
  4904. pendingRejectionCheck: false,
  4905. scheduleHandlers: function scheduleHandlers(promise) {
  4906. if (promise._status === STATUS_PENDING) {
  4907. return;
  4908. }
  4909. this.handlers = this.handlers.concat(promise._handlers);
  4910. promise._handlers = [];
  4911. if (this.running) {
  4912. return;
  4913. }
  4914. this.running = true;
  4915. setTimeout(this.runHandlers.bind(this), 0);
  4916. },
  4917. runHandlers: function runHandlers() {
  4918. var RUN_TIMEOUT = 1;
  4919. // ms
  4920. var timeoutAt = Date.now() + RUN_TIMEOUT;
  4921. while (this.handlers.length > 0) {
  4922. var handler = this.handlers.shift();
  4923. var nextStatus = handler.thisPromise._status;
  4924. var nextValue = handler.thisPromise._value;
  4925. try {
  4926. if (nextStatus === STATUS_RESOLVED) {
  4927. if (typeof handler.onResolve === 'function') {
  4928. nextValue = handler.onResolve(nextValue);
  4929. }
  4930. } else if (typeof handler.onReject === 'function') {
  4931. nextValue = handler.onReject(nextValue);
  4932. nextStatus = STATUS_RESOLVED;
  4933. if (handler.thisPromise._unhandledRejection) {
  4934. this.removeUnhandeledRejection(handler.thisPromise);
  4935. }
  4936. }
  4937. } catch (ex) {
  4938. nextStatus = STATUS_REJECTED;
  4939. nextValue = ex;
  4940. }
  4941. handler.nextPromise._updateStatus(nextStatus, nextValue);
  4942. if (Date.now() >= timeoutAt) {
  4943. break;
  4944. }
  4945. }
  4946. if (this.handlers.length > 0) {
  4947. setTimeout(this.runHandlers.bind(this), 0);
  4948. return;
  4949. }
  4950. this.running = false;
  4951. },
  4952. addUnhandledRejection: function addUnhandledRejection(promise) {
  4953. this.unhandledRejections.push({
  4954. promise: promise,
  4955. time: Date.now()
  4956. });
  4957. this.scheduleRejectionCheck();
  4958. },
  4959. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  4960. promise._unhandledRejection = false;
  4961. for (var i = 0; i < this.unhandledRejections.length; i++) {
  4962. if (this.unhandledRejections[i].promise === promise) {
  4963. this.unhandledRejections.splice(i);
  4964. i--;
  4965. }
  4966. }
  4967. },
  4968. scheduleRejectionCheck: function scheduleRejectionCheck() {
  4969. if (this.pendingRejectionCheck) {
  4970. return;
  4971. }
  4972. this.pendingRejectionCheck = true;
  4973. setTimeout(function rejectionCheck() {
  4974. this.pendingRejectionCheck = false;
  4975. var now = Date.now();
  4976. for (var i = 0; i < this.unhandledRejections.length; i++) {
  4977. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  4978. var unhandled = this.unhandledRejections[i].promise._value;
  4979. var msg = 'Unhandled rejection: ' + unhandled;
  4980. if (unhandled.stack) {
  4981. msg += '\n' + unhandled.stack;
  4982. }
  4983. warn(msg);
  4984. this.unhandledRejections.splice(i);
  4985. i--;
  4986. }
  4987. }
  4988. if (this.unhandledRejections.length) {
  4989. this.scheduleRejectionCheck();
  4990. }
  4991. }.bind(this), REJECTION_TIMEOUT);
  4992. }
  4993. };
  4994. var Promise = function Promise(resolver) {
  4995. this._status = STATUS_PENDING;
  4996. this._handlers = [];
  4997. try {
  4998. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  4999. } catch (e) {
  5000. this._reject(e);
  5001. }
  5002. };
  5003. /**
  5004. * Builds a promise that is resolved when all the passed in promises are
  5005. * resolved.
  5006. * @param {array} promises array of data and/or promises to wait for.
  5007. * @return {Promise} New dependent promise.
  5008. */
  5009. Promise.all = function Promise_all(promises) {
  5010. var resolveAll, rejectAll;
  5011. var deferred = new Promise(function (resolve, reject) {
  5012. resolveAll = resolve;
  5013. rejectAll = reject;
  5014. });
  5015. var unresolved = promises.length;
  5016. var results = [];
  5017. if (unresolved === 0) {
  5018. resolveAll(results);
  5019. return deferred;
  5020. }
  5021. function reject(reason) {
  5022. if (deferred._status === STATUS_REJECTED) {
  5023. return;
  5024. }
  5025. results = [];
  5026. rejectAll(reason);
  5027. }
  5028. for (var i = 0, ii = promises.length; i < ii; ++i) {
  5029. var promise = promises[i];
  5030. var resolve = function (i) {
  5031. return function (value) {
  5032. if (deferred._status === STATUS_REJECTED) {
  5033. return;
  5034. }
  5035. results[i] = value;
  5036. unresolved--;
  5037. if (unresolved === 0) {
  5038. resolveAll(results);
  5039. }
  5040. };
  5041. }(i);
  5042. if (Promise.isPromise(promise)) {
  5043. promise.then(resolve, reject);
  5044. } else {
  5045. resolve(promise);
  5046. }
  5047. }
  5048. return deferred;
  5049. };
  5050. /**
  5051. * Checks if the value is likely a promise (has a 'then' function).
  5052. * @return {boolean} true if value is thenable
  5053. */
  5054. Promise.isPromise = function Promise_isPromise(value) {
  5055. return value && typeof value.then === 'function';
  5056. };
  5057. /**
  5058. * Creates resolved promise
  5059. * @param value resolve value
  5060. * @returns {Promise}
  5061. */
  5062. Promise.resolve = function Promise_resolve(value) {
  5063. return new Promise(function (resolve) {
  5064. resolve(value);
  5065. });
  5066. };
  5067. /**
  5068. * Creates rejected promise
  5069. * @param reason rejection value
  5070. * @returns {Promise}
  5071. */
  5072. Promise.reject = function Promise_reject(reason) {
  5073. return new Promise(function (resolve, reject) {
  5074. reject(reason);
  5075. });
  5076. };
  5077. Promise.prototype = {
  5078. _status: null,
  5079. _value: null,
  5080. _handlers: null,
  5081. _unhandledRejection: null,
  5082. _updateStatus: function Promise__updateStatus(status, value) {
  5083. if (this._status === STATUS_RESOLVED || this._status === STATUS_REJECTED) {
  5084. return;
  5085. }
  5086. if (status === STATUS_RESOLVED && Promise.isPromise(value)) {
  5087. value.then(this._updateStatus.bind(this, STATUS_RESOLVED), this._updateStatus.bind(this, STATUS_REJECTED));
  5088. return;
  5089. }
  5090. this._status = status;
  5091. this._value = value;
  5092. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  5093. this._unhandledRejection = true;
  5094. HandlerManager.addUnhandledRejection(this);
  5095. }
  5096. HandlerManager.scheduleHandlers(this);
  5097. },
  5098. _resolve: function Promise_resolve(value) {
  5099. this._updateStatus(STATUS_RESOLVED, value);
  5100. },
  5101. _reject: function Promise_reject(reason) {
  5102. this._updateStatus(STATUS_REJECTED, reason);
  5103. },
  5104. then: function Promise_then(onResolve, onReject) {
  5105. var nextPromise = new Promise(function (resolve, reject) {
  5106. this.resolve = resolve;
  5107. this.reject = reject;
  5108. });
  5109. this._handlers.push({
  5110. thisPromise: this,
  5111. onResolve: onResolve,
  5112. onReject: onReject,
  5113. nextPromise: nextPromise
  5114. });
  5115. HandlerManager.scheduleHandlers(this);
  5116. return nextPromise;
  5117. },
  5118. catch: function Promise_catch(onReject) {
  5119. return this.then(undefined, onReject);
  5120. }
  5121. };
  5122. globalScope.Promise = Promise;
  5123. }());
  5124. (function WeakMapClosure() {
  5125. if (globalScope.WeakMap) {
  5126. return;
  5127. }
  5128. var id = 0;
  5129. function WeakMap() {
  5130. this.id = '$weakmap' + id++;
  5131. }
  5132. WeakMap.prototype = {
  5133. has: function (obj) {
  5134. return !!Object.getOwnPropertyDescriptor(obj, this.id);
  5135. },
  5136. get: function (obj, defaultValue) {
  5137. return this.has(obj) ? obj[this.id] : defaultValue;
  5138. },
  5139. set: function (obj, value) {
  5140. Object.defineProperty(obj, this.id, {
  5141. value: value,
  5142. enumerable: false,
  5143. configurable: true
  5144. });
  5145. },
  5146. delete: function (obj) {
  5147. delete obj[this.id];
  5148. }
  5149. };
  5150. globalScope.WeakMap = WeakMap;
  5151. }());
  5152. var StatTimer = function StatTimerClosure() {
  5153. function rpad(str, pad, length) {
  5154. while (str.length < length) {
  5155. str += pad;
  5156. }
  5157. return str;
  5158. }
  5159. function StatTimer() {
  5160. this.started = Object.create(null);
  5161. this.times = [];
  5162. this.enabled = true;
  5163. }
  5164. StatTimer.prototype = {
  5165. time: function StatTimer_time(name) {
  5166. if (!this.enabled) {
  5167. return;
  5168. }
  5169. if (name in this.started) {
  5170. warn('Timer is already running for ' + name);
  5171. }
  5172. this.started[name] = Date.now();
  5173. },
  5174. timeEnd: function StatTimer_timeEnd(name) {
  5175. if (!this.enabled) {
  5176. return;
  5177. }
  5178. if (!(name in this.started)) {
  5179. warn('Timer has not been started for ' + name);
  5180. }
  5181. this.times.push({
  5182. 'name': name,
  5183. 'start': this.started[name],
  5184. 'end': Date.now()
  5185. });
  5186. // Remove timer from started so it can be called again.
  5187. delete this.started[name];
  5188. },
  5189. toString: function StatTimer_toString() {
  5190. var i, ii;
  5191. var times = this.times;
  5192. var out = '';
  5193. // Find the longest name for padding purposes.
  5194. var longest = 0;
  5195. for (i = 0, ii = times.length; i < ii; ++i) {
  5196. var name = times[i]['name'];
  5197. if (name.length > longest) {
  5198. longest = name.length;
  5199. }
  5200. }
  5201. for (i = 0, ii = times.length; i < ii; ++i) {
  5202. var span = times[i];
  5203. var duration = span.end - span.start;
  5204. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  5205. }
  5206. return out;
  5207. }
  5208. };
  5209. return StatTimer;
  5210. }();
  5211. var createBlob = function createBlob(data, contentType) {
  5212. if (typeof Blob !== 'undefined') {
  5213. return new Blob([data], { type: contentType });
  5214. }
  5215. warn('The "Blob" constructor is not supported.');
  5216. };
  5217. var createObjectURL = function createObjectURLClosure() {
  5218. // Blob/createObjectURL is not available, falling back to data schema.
  5219. var digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  5220. return function createObjectURL(data, contentType, forceDataSchema) {
  5221. if (!forceDataSchema && typeof URL !== 'undefined' && URL.createObjectURL) {
  5222. var blob = createBlob(data, contentType);
  5223. return URL.createObjectURL(blob);
  5224. }
  5225. var buffer = 'data:' + contentType + ';base64,';
  5226. for (var i = 0, ii = data.length; i < ii; i += 3) {
  5227. var b1 = data[i] & 0xFF;
  5228. var b2 = data[i + 1] & 0xFF;
  5229. var b3 = data[i + 2] & 0xFF;
  5230. var d1 = b1 >> 2, d2 = (b1 & 3) << 4 | b2 >> 4;
  5231. var d3 = i + 1 < ii ? (b2 & 0xF) << 2 | b3 >> 6 : 64;
  5232. var d4 = i + 2 < ii ? b3 & 0x3F : 64;
  5233. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  5234. }
  5235. return buffer;
  5236. };
  5237. }();
  5238. function MessageHandler(sourceName, targetName, comObj) {
  5239. this.sourceName = sourceName;
  5240. this.targetName = targetName;
  5241. this.comObj = comObj;
  5242. this.callbackIndex = 1;
  5243. this.postMessageTransfers = true;
  5244. var callbacksCapabilities = this.callbacksCapabilities = Object.create(null);
  5245. var ah = this.actionHandler = Object.create(null);
  5246. this._onComObjOnMessage = function messageHandlerComObjOnMessage(event) {
  5247. var data = event.data;
  5248. if (data.targetName !== this.sourceName) {
  5249. return;
  5250. }
  5251. if (data.isReply) {
  5252. var callbackId = data.callbackId;
  5253. if (data.callbackId in callbacksCapabilities) {
  5254. var callback = callbacksCapabilities[callbackId];
  5255. delete callbacksCapabilities[callbackId];
  5256. if ('error' in data) {
  5257. callback.reject(data.error);
  5258. } else {
  5259. callback.resolve(data.data);
  5260. }
  5261. } else {
  5262. error('Cannot resolve callback ' + callbackId);
  5263. }
  5264. } else if (data.action in ah) {
  5265. var action = ah[data.action];
  5266. if (data.callbackId) {
  5267. var sourceName = this.sourceName;
  5268. var targetName = data.sourceName;
  5269. Promise.resolve().then(function () {
  5270. return action[0].call(action[1], data.data);
  5271. }).then(function (result) {
  5272. comObj.postMessage({
  5273. sourceName: sourceName,
  5274. targetName: targetName,
  5275. isReply: true,
  5276. callbackId: data.callbackId,
  5277. data: result
  5278. });
  5279. }, function (reason) {
  5280. if (reason instanceof Error) {
  5281. // Serialize error to avoid "DataCloneError"
  5282. reason = reason + '';
  5283. }
  5284. comObj.postMessage({
  5285. sourceName: sourceName,
  5286. targetName: targetName,
  5287. isReply: true,
  5288. callbackId: data.callbackId,
  5289. error: reason
  5290. });
  5291. });
  5292. } else {
  5293. action[0].call(action[1], data.data);
  5294. }
  5295. } else {
  5296. error('Unknown action from worker: ' + data.action);
  5297. }
  5298. }.bind(this);
  5299. comObj.addEventListener('message', this._onComObjOnMessage);
  5300. }
  5301. MessageHandler.prototype = {
  5302. on: function messageHandlerOn(actionName, handler, scope) {
  5303. var ah = this.actionHandler;
  5304. if (ah[actionName]) {
  5305. error('There is already an actionName called "' + actionName + '"');
  5306. }
  5307. ah[actionName] = [
  5308. handler,
  5309. scope
  5310. ];
  5311. },
  5312. /**
  5313. * Sends a message to the comObj to invoke the action with the supplied data.
  5314. * @param {String} actionName Action to call.
  5315. * @param {JSON} data JSON data to send.
  5316. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  5317. */
  5318. send: function messageHandlerSend(actionName, data, transfers) {
  5319. var message = {
  5320. sourceName: this.sourceName,
  5321. targetName: this.targetName,
  5322. action: actionName,
  5323. data: data
  5324. };
  5325. this.postMessage(message, transfers);
  5326. },
  5327. /**
  5328. * Sends a message to the comObj to invoke the action with the supplied data.
  5329. * Expects that other side will callback with the response.
  5330. * @param {String} actionName Action to call.
  5331. * @param {JSON} data JSON data to send.
  5332. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  5333. * @returns {Promise} Promise to be resolved with response data.
  5334. */
  5335. sendWithPromise: function messageHandlerSendWithPromise(actionName, data, transfers) {
  5336. var callbackId = this.callbackIndex++;
  5337. var message = {
  5338. sourceName: this.sourceName,
  5339. targetName: this.targetName,
  5340. action: actionName,
  5341. data: data,
  5342. callbackId: callbackId
  5343. };
  5344. var capability = createPromiseCapability();
  5345. this.callbacksCapabilities[callbackId] = capability;
  5346. try {
  5347. this.postMessage(message, transfers);
  5348. } catch (e) {
  5349. capability.reject(e);
  5350. }
  5351. return capability.promise;
  5352. },
  5353. /**
  5354. * Sends raw message to the comObj.
  5355. * @private
  5356. * @param message {Object} Raw message.
  5357. * @param transfers List of transfers/ArrayBuffers, or undefined.
  5358. */
  5359. postMessage: function (message, transfers) {
  5360. if (transfers && this.postMessageTransfers) {
  5361. this.comObj.postMessage(message, transfers);
  5362. } else {
  5363. this.comObj.postMessage(message);
  5364. }
  5365. },
  5366. destroy: function () {
  5367. this.comObj.removeEventListener('message', this._onComObjOnMessage);
  5368. }
  5369. };
  5370. function loadJpegStream(id, imageUrl, objs) {
  5371. var img = new Image();
  5372. img.onload = function loadJpegStream_onloadClosure() {
  5373. objs.resolve(id, img);
  5374. };
  5375. img.onerror = function loadJpegStream_onerrorClosure() {
  5376. objs.resolve(id, null);
  5377. warn('Error during JPEG image loading');
  5378. };
  5379. img.src = imageUrl;
  5380. }
  5381. // Polyfill from https://github.com/Polymer/URL
  5382. /* Any copyright is dedicated to the Public Domain.
  5383. * http://creativecommons.org/publicdomain/zero/1.0/ */
  5384. (function checkURLConstructor(scope) {
  5385. // feature detect for URL constructor
  5386. var hasWorkingUrl = false;
  5387. try {
  5388. if (typeof URL === 'function' && typeof URL.prototype === 'object' && 'origin' in URL.prototype) {
  5389. var u = new URL('b', 'http://a');
  5390. u.pathname = 'c%20d';
  5391. hasWorkingUrl = u.href === 'http://a/c%20d';
  5392. }
  5393. } catch (e) {
  5394. }
  5395. if (hasWorkingUrl) {
  5396. return;
  5397. }
  5398. var relative = Object.create(null);
  5399. relative['ftp'] = 21;
  5400. relative['file'] = 0;
  5401. relative['gopher'] = 70;
  5402. relative['http'] = 80;
  5403. relative['https'] = 443;
  5404. relative['ws'] = 80;
  5405. relative['wss'] = 443;
  5406. var relativePathDotMapping = Object.create(null);
  5407. relativePathDotMapping['%2e'] = '.';
  5408. relativePathDotMapping['.%2e'] = '..';
  5409. relativePathDotMapping['%2e.'] = '..';
  5410. relativePathDotMapping['%2e%2e'] = '..';
  5411. function isRelativeScheme(scheme) {
  5412. return relative[scheme] !== undefined;
  5413. }
  5414. function invalid() {
  5415. clear.call(this);
  5416. this._isInvalid = true;
  5417. }
  5418. function IDNAToASCII(h) {
  5419. if ('' === h) {
  5420. invalid.call(this);
  5421. }
  5422. // XXX
  5423. return h.toLowerCase();
  5424. }
  5425. function percentEscape(c) {
  5426. var unicode = c.charCodeAt(0);
  5427. if (unicode > 0x20 && unicode < 0x7F && // " # < > ? `
  5428. [
  5429. 0x22,
  5430. 0x23,
  5431. 0x3C,
  5432. 0x3E,
  5433. 0x3F,
  5434. 0x60
  5435. ].indexOf(unicode) === -1) {
  5436. return c;
  5437. }
  5438. return encodeURIComponent(c);
  5439. }
  5440. function percentEscapeQuery(c) {
  5441. // XXX This actually needs to encode c using encoding and then
  5442. // convert the bytes one-by-one.
  5443. var unicode = c.charCodeAt(0);
  5444. if (unicode > 0x20 && unicode < 0x7F && // " # < > ` (do not escape '?')
  5445. [
  5446. 0x22,
  5447. 0x23,
  5448. 0x3C,
  5449. 0x3E,
  5450. 0x60
  5451. ].indexOf(unicode) === -1) {
  5452. return c;
  5453. }
  5454. return encodeURIComponent(c);
  5455. }
  5456. var EOF, ALPHA = /[a-zA-Z]/, ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/;
  5457. function parse(input, stateOverride, base) {
  5458. function err(message) {
  5459. errors.push(message);
  5460. }
  5461. var state = stateOverride || 'scheme start', cursor = 0, buffer = '', seenAt = false, seenBracket = false, errors = [];
  5462. loop:
  5463. while ((input[cursor - 1] !== EOF || cursor === 0) && !this._isInvalid) {
  5464. var c = input[cursor];
  5465. switch (state) {
  5466. case 'scheme start':
  5467. if (c && ALPHA.test(c)) {
  5468. buffer += c.toLowerCase();
  5469. // ASCII-safe
  5470. state = 'scheme';
  5471. } else if (!stateOverride) {
  5472. buffer = '';
  5473. state = 'no scheme';
  5474. continue;
  5475. } else {
  5476. err('Invalid scheme.');
  5477. break loop;
  5478. }
  5479. break;
  5480. case 'scheme':
  5481. if (c && ALPHANUMERIC.test(c)) {
  5482. buffer += c.toLowerCase();
  5483. } else // ASCII-safe
  5484. if (':' === c) {
  5485. this._scheme = buffer;
  5486. buffer = '';
  5487. if (stateOverride) {
  5488. break loop;
  5489. }
  5490. if (isRelativeScheme(this._scheme)) {
  5491. this._isRelative = true;
  5492. }
  5493. if ('file' === this._scheme) {
  5494. state = 'relative';
  5495. } else if (this._isRelative && base && base._scheme === this._scheme) {
  5496. state = 'relative or authority';
  5497. } else if (this._isRelative) {
  5498. state = 'authority first slash';
  5499. } else {
  5500. state = 'scheme data';
  5501. }
  5502. } else if (!stateOverride) {
  5503. buffer = '';
  5504. cursor = 0;
  5505. state = 'no scheme';
  5506. continue;
  5507. } else if (EOF === c) {
  5508. break loop;
  5509. } else {
  5510. err('Code point not allowed in scheme: ' + c);
  5511. break loop;
  5512. }
  5513. break;
  5514. case 'scheme data':
  5515. if ('?' === c) {
  5516. this._query = '?';
  5517. state = 'query';
  5518. } else if ('#' === c) {
  5519. this._fragment = '#';
  5520. state = 'fragment';
  5521. } else {
  5522. // XXX error handling
  5523. if (EOF !== c && '\t' !== c && '\n' !== c && '\r' !== c) {
  5524. this._schemeData += percentEscape(c);
  5525. }
  5526. }
  5527. break;
  5528. case 'no scheme':
  5529. if (!base || !isRelativeScheme(base._scheme)) {
  5530. err('Missing scheme.');
  5531. invalid.call(this);
  5532. } else {
  5533. state = 'relative';
  5534. continue;
  5535. }
  5536. break;
  5537. case 'relative or authority':
  5538. if ('/' === c && '/' === input[cursor + 1]) {
  5539. state = 'authority ignore slashes';
  5540. } else {
  5541. err('Expected /, got: ' + c);
  5542. state = 'relative';
  5543. continue;
  5544. }
  5545. break;
  5546. case 'relative':
  5547. this._isRelative = true;
  5548. if ('file' !== this._scheme) {
  5549. this._scheme = base._scheme;
  5550. }
  5551. if (EOF === c) {
  5552. this._host = base._host;
  5553. this._port = base._port;
  5554. this._path = base._path.slice();
  5555. this._query = base._query;
  5556. this._username = base._username;
  5557. this._password = base._password;
  5558. break loop;
  5559. } else if ('/' === c || '\\' === c) {
  5560. if ('\\' === c) {
  5561. err('\\ is an invalid code point.');
  5562. }
  5563. state = 'relative slash';
  5564. } else if ('?' === c) {
  5565. this._host = base._host;
  5566. this._port = base._port;
  5567. this._path = base._path.slice();
  5568. this._query = '?';
  5569. this._username = base._username;
  5570. this._password = base._password;
  5571. state = 'query';
  5572. } else if ('#' === c) {
  5573. this._host = base._host;
  5574. this._port = base._port;
  5575. this._path = base._path.slice();
  5576. this._query = base._query;
  5577. this._fragment = '#';
  5578. this._username = base._username;
  5579. this._password = base._password;
  5580. state = 'fragment';
  5581. } else {
  5582. var nextC = input[cursor + 1];
  5583. var nextNextC = input[cursor + 2];
  5584. if ('file' !== this._scheme || !ALPHA.test(c) || nextC !== ':' && nextC !== '|' || EOF !== nextNextC && '/' !== nextNextC && '\\' !== nextNextC && '?' !== nextNextC && '#' !== nextNextC) {
  5585. this._host = base._host;
  5586. this._port = base._port;
  5587. this._username = base._username;
  5588. this._password = base._password;
  5589. this._path = base._path.slice();
  5590. this._path.pop();
  5591. }
  5592. state = 'relative path';
  5593. continue;
  5594. }
  5595. break;
  5596. case 'relative slash':
  5597. if ('/' === c || '\\' === c) {
  5598. if ('\\' === c) {
  5599. err('\\ is an invalid code point.');
  5600. }
  5601. if ('file' === this._scheme) {
  5602. state = 'file host';
  5603. } else {
  5604. state = 'authority ignore slashes';
  5605. }
  5606. } else {
  5607. if ('file' !== this._scheme) {
  5608. this._host = base._host;
  5609. this._port = base._port;
  5610. this._username = base._username;
  5611. this._password = base._password;
  5612. }
  5613. state = 'relative path';
  5614. continue;
  5615. }
  5616. break;
  5617. case 'authority first slash':
  5618. if ('/' === c) {
  5619. state = 'authority second slash';
  5620. } else {
  5621. err('Expected \'/\', got: ' + c);
  5622. state = 'authority ignore slashes';
  5623. continue;
  5624. }
  5625. break;
  5626. case 'authority second slash':
  5627. state = 'authority ignore slashes';
  5628. if ('/' !== c) {
  5629. err('Expected \'/\', got: ' + c);
  5630. continue;
  5631. }
  5632. break;
  5633. case 'authority ignore slashes':
  5634. if ('/' !== c && '\\' !== c) {
  5635. state = 'authority';
  5636. continue;
  5637. } else {
  5638. err('Expected authority, got: ' + c);
  5639. }
  5640. break;
  5641. case 'authority':
  5642. if ('@' === c) {
  5643. if (seenAt) {
  5644. err('@ already seen.');
  5645. buffer += '%40';
  5646. }
  5647. seenAt = true;
  5648. for (var i = 0; i < buffer.length; i++) {
  5649. var cp = buffer[i];
  5650. if ('\t' === cp || '\n' === cp || '\r' === cp) {
  5651. err('Invalid whitespace in authority.');
  5652. continue;
  5653. }
  5654. // XXX check URL code points
  5655. if (':' === cp && null === this._password) {
  5656. this._password = '';
  5657. continue;
  5658. }
  5659. var tempC = percentEscape(cp);
  5660. if (null !== this._password) {
  5661. this._password += tempC;
  5662. } else {
  5663. this._username += tempC;
  5664. }
  5665. }
  5666. buffer = '';
  5667. } else if (EOF === c || '/' === c || '\\' === c || '?' === c || '#' === c) {
  5668. cursor -= buffer.length;
  5669. buffer = '';
  5670. state = 'host';
  5671. continue;
  5672. } else {
  5673. buffer += c;
  5674. }
  5675. break;
  5676. case 'file host':
  5677. if (EOF === c || '/' === c || '\\' === c || '?' === c || '#' === c) {
  5678. if (buffer.length === 2 && ALPHA.test(buffer[0]) && (buffer[1] === ':' || buffer[1] === '|')) {
  5679. state = 'relative path';
  5680. } else if (buffer.length === 0) {
  5681. state = 'relative path start';
  5682. } else {
  5683. this._host = IDNAToASCII.call(this, buffer);
  5684. buffer = '';
  5685. state = 'relative path start';
  5686. }
  5687. continue;
  5688. } else if ('\t' === c || '\n' === c || '\r' === c) {
  5689. err('Invalid whitespace in file host.');
  5690. } else {
  5691. buffer += c;
  5692. }
  5693. break;
  5694. case 'host':
  5695. case 'hostname':
  5696. if (':' === c && !seenBracket) {
  5697. // XXX host parsing
  5698. this._host = IDNAToASCII.call(this, buffer);
  5699. buffer = '';
  5700. state = 'port';
  5701. if ('hostname' === stateOverride) {
  5702. break loop;
  5703. }
  5704. } else if (EOF === c || '/' === c || '\\' === c || '?' === c || '#' === c) {
  5705. this._host = IDNAToASCII.call(this, buffer);
  5706. buffer = '';
  5707. state = 'relative path start';
  5708. if (stateOverride) {
  5709. break loop;
  5710. }
  5711. continue;
  5712. } else if ('\t' !== c && '\n' !== c && '\r' !== c) {
  5713. if ('[' === c) {
  5714. seenBracket = true;
  5715. } else if (']' === c) {
  5716. seenBracket = false;
  5717. }
  5718. buffer += c;
  5719. } else {
  5720. err('Invalid code point in host/hostname: ' + c);
  5721. }
  5722. break;
  5723. case 'port':
  5724. if (/[0-9]/.test(c)) {
  5725. buffer += c;
  5726. } else if (EOF === c || '/' === c || '\\' === c || '?' === c || '#' === c || stateOverride) {
  5727. if ('' !== buffer) {
  5728. var temp = parseInt(buffer, 10);
  5729. if (temp !== relative[this._scheme]) {
  5730. this._port = temp + '';
  5731. }
  5732. buffer = '';
  5733. }
  5734. if (stateOverride) {
  5735. break loop;
  5736. }
  5737. state = 'relative path start';
  5738. continue;
  5739. } else if ('\t' === c || '\n' === c || '\r' === c) {
  5740. err('Invalid code point in port: ' + c);
  5741. } else {
  5742. invalid.call(this);
  5743. }
  5744. break;
  5745. case 'relative path start':
  5746. if ('\\' === c) {
  5747. err('\'\\\' not allowed in path.');
  5748. }
  5749. state = 'relative path';
  5750. if ('/' !== c && '\\' !== c) {
  5751. continue;
  5752. }
  5753. break;
  5754. case 'relative path':
  5755. if (EOF === c || '/' === c || '\\' === c || !stateOverride && ('?' === c || '#' === c)) {
  5756. if ('\\' === c) {
  5757. err('\\ not allowed in relative path.');
  5758. }
  5759. var tmp;
  5760. if (tmp = relativePathDotMapping[buffer.toLowerCase()]) {
  5761. buffer = tmp;
  5762. }
  5763. if ('..' === buffer) {
  5764. this._path.pop();
  5765. if ('/' !== c && '\\' !== c) {
  5766. this._path.push('');
  5767. }
  5768. } else if ('.' === buffer && '/' !== c && '\\' !== c) {
  5769. this._path.push('');
  5770. } else if ('.' !== buffer) {
  5771. if ('file' === this._scheme && this._path.length === 0 && buffer.length === 2 && ALPHA.test(buffer[0]) && buffer[1] === '|') {
  5772. buffer = buffer[0] + ':';
  5773. }
  5774. this._path.push(buffer);
  5775. }
  5776. buffer = '';
  5777. if ('?' === c) {
  5778. this._query = '?';
  5779. state = 'query';
  5780. } else if ('#' === c) {
  5781. this._fragment = '#';
  5782. state = 'fragment';
  5783. }
  5784. } else if ('\t' !== c && '\n' !== c && '\r' !== c) {
  5785. buffer += percentEscape(c);
  5786. }
  5787. break;
  5788. case 'query':
  5789. if (!stateOverride && '#' === c) {
  5790. this._fragment = '#';
  5791. state = 'fragment';
  5792. } else if (EOF !== c && '\t' !== c && '\n' !== c && '\r' !== c) {
  5793. this._query += percentEscapeQuery(c);
  5794. }
  5795. break;
  5796. case 'fragment':
  5797. if (EOF !== c && '\t' !== c && '\n' !== c && '\r' !== c) {
  5798. this._fragment += c;
  5799. }
  5800. break;
  5801. }
  5802. cursor++;
  5803. }
  5804. }
  5805. function clear() {
  5806. this._scheme = '';
  5807. this._schemeData = '';
  5808. this._username = '';
  5809. this._password = null;
  5810. this._host = '';
  5811. this._port = '';
  5812. this._path = [];
  5813. this._query = '';
  5814. this._fragment = '';
  5815. this._isInvalid = false;
  5816. this._isRelative = false;
  5817. }
  5818. // Does not process domain names or IP addresses.
  5819. // Does not handle encoding for the query parameter.
  5820. function JURL(url, base)
  5821. /* , encoding */
  5822. {
  5823. if (base !== undefined && !(base instanceof JURL)) {
  5824. base = new JURL(String(base));
  5825. }
  5826. this._url = url;
  5827. clear.call(this);
  5828. var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, '');
  5829. // encoding = encoding || 'utf-8'
  5830. parse.call(this, input, null, base);
  5831. }
  5832. JURL.prototype = {
  5833. toString: function () {
  5834. return this.href;
  5835. },
  5836. get href() {
  5837. if (this._isInvalid) {
  5838. return this._url;
  5839. }
  5840. var authority = '';
  5841. if ('' !== this._username || null !== this._password) {
  5842. authority = this._username + (null !== this._password ? ':' + this._password : '') + '@';
  5843. }
  5844. return this.protocol + (this._isRelative ? '//' + authority + this.host : '') + this.pathname + this._query + this._fragment;
  5845. },
  5846. set href(href) {
  5847. clear.call(this);
  5848. parse.call(this, href);
  5849. },
  5850. get protocol() {
  5851. return this._scheme + ':';
  5852. },
  5853. set protocol(protocol) {
  5854. if (this._isInvalid) {
  5855. return;
  5856. }
  5857. parse.call(this, protocol + ':', 'scheme start');
  5858. },
  5859. get host() {
  5860. return this._isInvalid ? '' : this._port ? this._host + ':' + this._port : this._host;
  5861. },
  5862. set host(host) {
  5863. if (this._isInvalid || !this._isRelative) {
  5864. return;
  5865. }
  5866. parse.call(this, host, 'host');
  5867. },
  5868. get hostname() {
  5869. return this._host;
  5870. },
  5871. set hostname(hostname) {
  5872. if (this._isInvalid || !this._isRelative) {
  5873. return;
  5874. }
  5875. parse.call(this, hostname, 'hostname');
  5876. },
  5877. get port() {
  5878. return this._port;
  5879. },
  5880. set port(port) {
  5881. if (this._isInvalid || !this._isRelative) {
  5882. return;
  5883. }
  5884. parse.call(this, port, 'port');
  5885. },
  5886. get pathname() {
  5887. return this._isInvalid ? '' : this._isRelative ? '/' + this._path.join('/') : this._schemeData;
  5888. },
  5889. set pathname(pathname) {
  5890. if (this._isInvalid || !this._isRelative) {
  5891. return;
  5892. }
  5893. this._path = [];
  5894. parse.call(this, pathname, 'relative path start');
  5895. },
  5896. get search() {
  5897. return this._isInvalid || !this._query || '?' === this._query ? '' : this._query;
  5898. },
  5899. set search(search) {
  5900. if (this._isInvalid || !this._isRelative) {
  5901. return;
  5902. }
  5903. this._query = '?';
  5904. if ('?' === search[0]) {
  5905. search = search.slice(1);
  5906. }
  5907. parse.call(this, search, 'query');
  5908. },
  5909. get hash() {
  5910. return this._isInvalid || !this._fragment || '#' === this._fragment ? '' : this._fragment;
  5911. },
  5912. set hash(hash) {
  5913. if (this._isInvalid) {
  5914. return;
  5915. }
  5916. this._fragment = '#';
  5917. if ('#' === hash[0]) {
  5918. hash = hash.slice(1);
  5919. }
  5920. parse.call(this, hash, 'fragment');
  5921. },
  5922. get origin() {
  5923. var host;
  5924. if (this._isInvalid || !this._scheme) {
  5925. return '';
  5926. }
  5927. // javascript: Gecko returns String(""), WebKit/Blink String("null")
  5928. // Gecko throws error for "data://"
  5929. // data: Gecko returns "", Blink returns "data://", WebKit returns "null"
  5930. // Gecko returns String("") for file: mailto:
  5931. // WebKit/Blink returns String("SCHEME://") for file: mailto:
  5932. switch (this._scheme) {
  5933. case 'data':
  5934. case 'file':
  5935. case 'javascript':
  5936. case 'mailto':
  5937. return 'null';
  5938. }
  5939. host = this.host;
  5940. if (!host) {
  5941. return '';
  5942. }
  5943. return this._scheme + '://' + host;
  5944. }
  5945. };
  5946. // Copy over the static methods
  5947. var OriginalURL = scope.URL;
  5948. if (OriginalURL) {
  5949. JURL.createObjectURL = function (blob) {
  5950. // IE extension allows a second optional options argument.
  5951. // http://msdn.microsoft.com/en-us/library/ie/hh772302(v=vs.85).aspx
  5952. return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
  5953. };
  5954. JURL.revokeObjectURL = function (url) {
  5955. OriginalURL.revokeObjectURL(url);
  5956. };
  5957. }
  5958. scope.URL = JURL;
  5959. }(globalScope));
  5960. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  5961. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  5962. exports.OPS = OPS;
  5963. exports.VERBOSITY_LEVELS = VERBOSITY_LEVELS;
  5964. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  5965. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  5966. exports.AnnotationFieldFlag = AnnotationFieldFlag;
  5967. exports.AnnotationFlag = AnnotationFlag;
  5968. exports.AnnotationType = AnnotationType;
  5969. exports.FontType = FontType;
  5970. exports.ImageKind = ImageKind;
  5971. exports.InvalidPDFException = InvalidPDFException;
  5972. exports.MessageHandler = MessageHandler;
  5973. exports.MissingDataException = MissingDataException;
  5974. exports.MissingPDFException = MissingPDFException;
  5975. exports.NotImplementedException = NotImplementedException;
  5976. exports.PageViewport = PageViewport;
  5977. exports.PasswordException = PasswordException;
  5978. exports.PasswordResponses = PasswordResponses;
  5979. exports.StatTimer = StatTimer;
  5980. exports.StreamType = StreamType;
  5981. exports.TextRenderingMode = TextRenderingMode;
  5982. exports.UnexpectedResponseException = UnexpectedResponseException;
  5983. exports.UnknownErrorException = UnknownErrorException;
  5984. exports.Util = Util;
  5985. exports.XRefParseException = XRefParseException;
  5986. exports.arrayByteLength = arrayByteLength;
  5987. exports.arraysToBytes = arraysToBytes;
  5988. exports.assert = assert;
  5989. exports.bytesToString = bytesToString;
  5990. exports.createBlob = createBlob;
  5991. exports.createPromiseCapability = createPromiseCapability;
  5992. exports.createObjectURL = createObjectURL;
  5993. exports.deprecated = deprecated;
  5994. exports.error = error;
  5995. exports.getLookupTableFactory = getLookupTableFactory;
  5996. exports.getVerbosityLevel = getVerbosityLevel;
  5997. exports.globalScope = globalScope;
  5998. exports.info = info;
  5999. exports.isArray = isArray;
  6000. exports.isArrayBuffer = isArrayBuffer;
  6001. exports.isBool = isBool;
  6002. exports.isEmptyObj = isEmptyObj;
  6003. exports.isInt = isInt;
  6004. exports.isNum = isNum;
  6005. exports.isString = isString;
  6006. exports.isSpace = isSpace;
  6007. exports.isSameOrigin = isSameOrigin;
  6008. exports.isValidUrl = isValidUrl;
  6009. exports.isLittleEndian = isLittleEndian;
  6010. exports.isEvalSupported = isEvalSupported;
  6011. exports.loadJpegStream = loadJpegStream;
  6012. exports.log2 = log2;
  6013. exports.readInt8 = readInt8;
  6014. exports.readUint16 = readUint16;
  6015. exports.readUint32 = readUint32;
  6016. exports.removeNullCharacters = removeNullCharacters;
  6017. exports.setVerbosityLevel = setVerbosityLevel;
  6018. exports.shadow = shadow;
  6019. exports.string32 = string32;
  6020. exports.stringToBytes = stringToBytes;
  6021. exports.stringToPDFString = stringToPDFString;
  6022. exports.stringToUTF8String = stringToUTF8String;
  6023. exports.utf8StringToString = utf8StringToString;
  6024. exports.warn = warn;
  6025. }));
  6026. (function (root, factory) {
  6027. factory(root.pdfjsCoreCFFParser = {}, root.pdfjsSharedUtil, root.pdfjsCoreCharsets, root.pdfjsCoreEncodings);
  6028. }(this, function (exports, sharedUtil, coreCharsets, coreEncodings) {
  6029. var error = sharedUtil.error;
  6030. var info = sharedUtil.info;
  6031. var bytesToString = sharedUtil.bytesToString;
  6032. var warn = sharedUtil.warn;
  6033. var isArray = sharedUtil.isArray;
  6034. var Util = sharedUtil.Util;
  6035. var stringToBytes = sharedUtil.stringToBytes;
  6036. var assert = sharedUtil.assert;
  6037. var ISOAdobeCharset = coreCharsets.ISOAdobeCharset;
  6038. var ExpertCharset = coreCharsets.ExpertCharset;
  6039. var ExpertSubsetCharset = coreCharsets.ExpertSubsetCharset;
  6040. var StandardEncoding = coreEncodings.StandardEncoding;
  6041. var ExpertEncoding = coreEncodings.ExpertEncoding;
  6042. // Maximum subroutine call depth of type 2 chartrings. Matches OTS.
  6043. var MAX_SUBR_NESTING = 10;
  6044. /**
  6045. * The CFF class takes a Type1 file and wrap it into a
  6046. * 'Compact Font Format' which itself embed Type2 charstrings.
  6047. */
  6048. var CFFStandardStrings = [
  6049. '.notdef',
  6050. 'space',
  6051. 'exclam',
  6052. 'quotedbl',
  6053. 'numbersign',
  6054. 'dollar',
  6055. 'percent',
  6056. 'ampersand',
  6057. 'quoteright',
  6058. 'parenleft',
  6059. 'parenright',
  6060. 'asterisk',
  6061. 'plus',
  6062. 'comma',
  6063. 'hyphen',
  6064. 'period',
  6065. 'slash',
  6066. 'zero',
  6067. 'one',
  6068. 'two',
  6069. 'three',
  6070. 'four',
  6071. 'five',
  6072. 'six',
  6073. 'seven',
  6074. 'eight',
  6075. 'nine',
  6076. 'colon',
  6077. 'semicolon',
  6078. 'less',
  6079. 'equal',
  6080. 'greater',
  6081. 'question',
  6082. 'at',
  6083. 'A',
  6084. 'B',
  6085. 'C',
  6086. 'D',
  6087. 'E',
  6088. 'F',
  6089. 'G',
  6090. 'H',
  6091. 'I',
  6092. 'J',
  6093. 'K',
  6094. 'L',
  6095. 'M',
  6096. 'N',
  6097. 'O',
  6098. 'P',
  6099. 'Q',
  6100. 'R',
  6101. 'S',
  6102. 'T',
  6103. 'U',
  6104. 'V',
  6105. 'W',
  6106. 'X',
  6107. 'Y',
  6108. 'Z',
  6109. 'bracketleft',
  6110. 'backslash',
  6111. 'bracketright',
  6112. 'asciicircum',
  6113. 'underscore',
  6114. 'quoteleft',
  6115. 'a',
  6116. 'b',
  6117. 'c',
  6118. 'd',
  6119. 'e',
  6120. 'f',
  6121. 'g',
  6122. 'h',
  6123. 'i',
  6124. 'j',
  6125. 'k',
  6126. 'l',
  6127. 'm',
  6128. 'n',
  6129. 'o',
  6130. 'p',
  6131. 'q',
  6132. 'r',
  6133. 's',
  6134. 't',
  6135. 'u',
  6136. 'v',
  6137. 'w',
  6138. 'x',
  6139. 'y',
  6140. 'z',
  6141. 'braceleft',
  6142. 'bar',
  6143. 'braceright',
  6144. 'asciitilde',
  6145. 'exclamdown',
  6146. 'cent',
  6147. 'sterling',
  6148. 'fraction',
  6149. 'yen',
  6150. 'florin',
  6151. 'section',
  6152. 'currency',
  6153. 'quotesingle',
  6154. 'quotedblleft',
  6155. 'guillemotleft',
  6156. 'guilsinglleft',
  6157. 'guilsinglright',
  6158. 'fi',
  6159. 'fl',
  6160. 'endash',
  6161. 'dagger',
  6162. 'daggerdbl',
  6163. 'periodcentered',
  6164. 'paragraph',
  6165. 'bullet',
  6166. 'quotesinglbase',
  6167. 'quotedblbase',
  6168. 'quotedblright',
  6169. 'guillemotright',
  6170. 'ellipsis',
  6171. 'perthousand',
  6172. 'questiondown',
  6173. 'grave',
  6174. 'acute',
  6175. 'circumflex',
  6176. 'tilde',
  6177. 'macron',
  6178. 'breve',
  6179. 'dotaccent',
  6180. 'dieresis',
  6181. 'ring',
  6182. 'cedilla',
  6183. 'hungarumlaut',
  6184. 'ogonek',
  6185. 'caron',
  6186. 'emdash',
  6187. 'AE',
  6188. 'ordfeminine',
  6189. 'Lslash',
  6190. 'Oslash',
  6191. 'OE',
  6192. 'ordmasculine',
  6193. 'ae',
  6194. 'dotlessi',
  6195. 'lslash',
  6196. 'oslash',
  6197. 'oe',
  6198. 'germandbls',
  6199. 'onesuperior',
  6200. 'logicalnot',
  6201. 'mu',
  6202. 'trademark',
  6203. 'Eth',
  6204. 'onehalf',
  6205. 'plusminus',
  6206. 'Thorn',
  6207. 'onequarter',
  6208. 'divide',
  6209. 'brokenbar',
  6210. 'degree',
  6211. 'thorn',
  6212. 'threequarters',
  6213. 'twosuperior',
  6214. 'registered',
  6215. 'minus',
  6216. 'eth',
  6217. 'multiply',
  6218. 'threesuperior',
  6219. 'copyright',
  6220. 'Aacute',
  6221. 'Acircumflex',
  6222. 'Adieresis',
  6223. 'Agrave',
  6224. 'Aring',
  6225. 'Atilde',
  6226. 'Ccedilla',
  6227. 'Eacute',
  6228. 'Ecircumflex',
  6229. 'Edieresis',
  6230. 'Egrave',
  6231. 'Iacute',
  6232. 'Icircumflex',
  6233. 'Idieresis',
  6234. 'Igrave',
  6235. 'Ntilde',
  6236. 'Oacute',
  6237. 'Ocircumflex',
  6238. 'Odieresis',
  6239. 'Ograve',
  6240. 'Otilde',
  6241. 'Scaron',
  6242. 'Uacute',
  6243. 'Ucircumflex',
  6244. 'Udieresis',
  6245. 'Ugrave',
  6246. 'Yacute',
  6247. 'Ydieresis',
  6248. 'Zcaron',
  6249. 'aacute',
  6250. 'acircumflex',
  6251. 'adieresis',
  6252. 'agrave',
  6253. 'aring',
  6254. 'atilde',
  6255. 'ccedilla',
  6256. 'eacute',
  6257. 'ecircumflex',
  6258. 'edieresis',
  6259. 'egrave',
  6260. 'iacute',
  6261. 'icircumflex',
  6262. 'idieresis',
  6263. 'igrave',
  6264. 'ntilde',
  6265. 'oacute',
  6266. 'ocircumflex',
  6267. 'odieresis',
  6268. 'ograve',
  6269. 'otilde',
  6270. 'scaron',
  6271. 'uacute',
  6272. 'ucircumflex',
  6273. 'udieresis',
  6274. 'ugrave',
  6275. 'yacute',
  6276. 'ydieresis',
  6277. 'zcaron',
  6278. 'exclamsmall',
  6279. 'Hungarumlautsmall',
  6280. 'dollaroldstyle',
  6281. 'dollarsuperior',
  6282. 'ampersandsmall',
  6283. 'Acutesmall',
  6284. 'parenleftsuperior',
  6285. 'parenrightsuperior',
  6286. 'twodotenleader',
  6287. 'onedotenleader',
  6288. 'zerooldstyle',
  6289. 'oneoldstyle',
  6290. 'twooldstyle',
  6291. 'threeoldstyle',
  6292. 'fouroldstyle',
  6293. 'fiveoldstyle',
  6294. 'sixoldstyle',
  6295. 'sevenoldstyle',
  6296. 'eightoldstyle',
  6297. 'nineoldstyle',
  6298. 'commasuperior',
  6299. 'threequartersemdash',
  6300. 'periodsuperior',
  6301. 'questionsmall',
  6302. 'asuperior',
  6303. 'bsuperior',
  6304. 'centsuperior',
  6305. 'dsuperior',
  6306. 'esuperior',
  6307. 'isuperior',
  6308. 'lsuperior',
  6309. 'msuperior',
  6310. 'nsuperior',
  6311. 'osuperior',
  6312. 'rsuperior',
  6313. 'ssuperior',
  6314. 'tsuperior',
  6315. 'ff',
  6316. 'ffi',
  6317. 'ffl',
  6318. 'parenleftinferior',
  6319. 'parenrightinferior',
  6320. 'Circumflexsmall',
  6321. 'hyphensuperior',
  6322. 'Gravesmall',
  6323. 'Asmall',
  6324. 'Bsmall',
  6325. 'Csmall',
  6326. 'Dsmall',
  6327. 'Esmall',
  6328. 'Fsmall',
  6329. 'Gsmall',
  6330. 'Hsmall',
  6331. 'Ismall',
  6332. 'Jsmall',
  6333. 'Ksmall',
  6334. 'Lsmall',
  6335. 'Msmall',
  6336. 'Nsmall',
  6337. 'Osmall',
  6338. 'Psmall',
  6339. 'Qsmall',
  6340. 'Rsmall',
  6341. 'Ssmall',
  6342. 'Tsmall',
  6343. 'Usmall',
  6344. 'Vsmall',
  6345. 'Wsmall',
  6346. 'Xsmall',
  6347. 'Ysmall',
  6348. 'Zsmall',
  6349. 'colonmonetary',
  6350. 'onefitted',
  6351. 'rupiah',
  6352. 'Tildesmall',
  6353. 'exclamdownsmall',
  6354. 'centoldstyle',
  6355. 'Lslashsmall',
  6356. 'Scaronsmall',
  6357. 'Zcaronsmall',
  6358. 'Dieresissmall',
  6359. 'Brevesmall',
  6360. 'Caronsmall',
  6361. 'Dotaccentsmall',
  6362. 'Macronsmall',
  6363. 'figuredash',
  6364. 'hypheninferior',
  6365. 'Ogoneksmall',
  6366. 'Ringsmall',
  6367. 'Cedillasmall',
  6368. 'questiondownsmall',
  6369. 'oneeighth',
  6370. 'threeeighths',
  6371. 'fiveeighths',
  6372. 'seveneighths',
  6373. 'onethird',
  6374. 'twothirds',
  6375. 'zerosuperior',
  6376. 'foursuperior',
  6377. 'fivesuperior',
  6378. 'sixsuperior',
  6379. 'sevensuperior',
  6380. 'eightsuperior',
  6381. 'ninesuperior',
  6382. 'zeroinferior',
  6383. 'oneinferior',
  6384. 'twoinferior',
  6385. 'threeinferior',
  6386. 'fourinferior',
  6387. 'fiveinferior',
  6388. 'sixinferior',
  6389. 'seveninferior',
  6390. 'eightinferior',
  6391. 'nineinferior',
  6392. 'centinferior',
  6393. 'dollarinferior',
  6394. 'periodinferior',
  6395. 'commainferior',
  6396. 'Agravesmall',
  6397. 'Aacutesmall',
  6398. 'Acircumflexsmall',
  6399. 'Atildesmall',
  6400. 'Adieresissmall',
  6401. 'Aringsmall',
  6402. 'AEsmall',
  6403. 'Ccedillasmall',
  6404. 'Egravesmall',
  6405. 'Eacutesmall',
  6406. 'Ecircumflexsmall',
  6407. 'Edieresissmall',
  6408. 'Igravesmall',
  6409. 'Iacutesmall',
  6410. 'Icircumflexsmall',
  6411. 'Idieresissmall',
  6412. 'Ethsmall',
  6413. 'Ntildesmall',
  6414. 'Ogravesmall',
  6415. 'Oacutesmall',
  6416. 'Ocircumflexsmall',
  6417. 'Otildesmall',
  6418. 'Odieresissmall',
  6419. 'OEsmall',
  6420. 'Oslashsmall',
  6421. 'Ugravesmall',
  6422. 'Uacutesmall',
  6423. 'Ucircumflexsmall',
  6424. 'Udieresissmall',
  6425. 'Yacutesmall',
  6426. 'Thornsmall',
  6427. 'Ydieresissmall',
  6428. '001.000',
  6429. '001.001',
  6430. '001.002',
  6431. '001.003',
  6432. 'Black',
  6433. 'Bold',
  6434. 'Book',
  6435. 'Light',
  6436. 'Medium',
  6437. 'Regular',
  6438. 'Roman',
  6439. 'Semibold'
  6440. ];
  6441. var CFFParser = function CFFParserClosure() {
  6442. var CharstringValidationData = [
  6443. null,
  6444. {
  6445. id: 'hstem',
  6446. min: 2,
  6447. stackClearing: true,
  6448. stem: true
  6449. },
  6450. null,
  6451. {
  6452. id: 'vstem',
  6453. min: 2,
  6454. stackClearing: true,
  6455. stem: true
  6456. },
  6457. {
  6458. id: 'vmoveto',
  6459. min: 1,
  6460. stackClearing: true
  6461. },
  6462. {
  6463. id: 'rlineto',
  6464. min: 2,
  6465. resetStack: true
  6466. },
  6467. {
  6468. id: 'hlineto',
  6469. min: 1,
  6470. resetStack: true
  6471. },
  6472. {
  6473. id: 'vlineto',
  6474. min: 1,
  6475. resetStack: true
  6476. },
  6477. {
  6478. id: 'rrcurveto',
  6479. min: 6,
  6480. resetStack: true
  6481. },
  6482. null,
  6483. {
  6484. id: 'callsubr',
  6485. min: 1,
  6486. undefStack: true
  6487. },
  6488. {
  6489. id: 'return',
  6490. min: 0,
  6491. undefStack: true
  6492. },
  6493. null,
  6494. // 12
  6495. null,
  6496. {
  6497. id: 'endchar',
  6498. min: 0,
  6499. stackClearing: true
  6500. },
  6501. null,
  6502. null,
  6503. null,
  6504. {
  6505. id: 'hstemhm',
  6506. min: 2,
  6507. stackClearing: true,
  6508. stem: true
  6509. },
  6510. {
  6511. id: 'hintmask',
  6512. min: 0,
  6513. stackClearing: true
  6514. },
  6515. {
  6516. id: 'cntrmask',
  6517. min: 0,
  6518. stackClearing: true
  6519. },
  6520. {
  6521. id: 'rmoveto',
  6522. min: 2,
  6523. stackClearing: true
  6524. },
  6525. {
  6526. id: 'hmoveto',
  6527. min: 1,
  6528. stackClearing: true
  6529. },
  6530. {
  6531. id: 'vstemhm',
  6532. min: 2,
  6533. stackClearing: true,
  6534. stem: true
  6535. },
  6536. {
  6537. id: 'rcurveline',
  6538. min: 8,
  6539. resetStack: true
  6540. },
  6541. {
  6542. id: 'rlinecurve',
  6543. min: 8,
  6544. resetStack: true
  6545. },
  6546. {
  6547. id: 'vvcurveto',
  6548. min: 4,
  6549. resetStack: true
  6550. },
  6551. {
  6552. id: 'hhcurveto',
  6553. min: 4,
  6554. resetStack: true
  6555. },
  6556. null,
  6557. // shortint
  6558. {
  6559. id: 'callgsubr',
  6560. min: 1,
  6561. undefStack: true
  6562. },
  6563. {
  6564. id: 'vhcurveto',
  6565. min: 4,
  6566. resetStack: true
  6567. },
  6568. {
  6569. id: 'hvcurveto',
  6570. min: 4,
  6571. resetStack: true
  6572. }
  6573. ];
  6574. var CharstringValidationData12 = [
  6575. null,
  6576. null,
  6577. null,
  6578. {
  6579. id: 'and',
  6580. min: 2,
  6581. stackDelta: -1
  6582. },
  6583. {
  6584. id: 'or',
  6585. min: 2,
  6586. stackDelta: -1
  6587. },
  6588. {
  6589. id: 'not',
  6590. min: 1,
  6591. stackDelta: 0
  6592. },
  6593. null,
  6594. null,
  6595. null,
  6596. {
  6597. id: 'abs',
  6598. min: 1,
  6599. stackDelta: 0
  6600. },
  6601. {
  6602. id: 'add',
  6603. min: 2,
  6604. stackDelta: -1,
  6605. stackFn: function stack_div(stack, index) {
  6606. stack[index - 2] = stack[index - 2] + stack[index - 1];
  6607. }
  6608. },
  6609. {
  6610. id: 'sub',
  6611. min: 2,
  6612. stackDelta: -1,
  6613. stackFn: function stack_div(stack, index) {
  6614. stack[index - 2] = stack[index - 2] - stack[index - 1];
  6615. }
  6616. },
  6617. {
  6618. id: 'div',
  6619. min: 2,
  6620. stackDelta: -1,
  6621. stackFn: function stack_div(stack, index) {
  6622. stack[index - 2] = stack[index - 2] / stack[index - 1];
  6623. }
  6624. },
  6625. null,
  6626. {
  6627. id: 'neg',
  6628. min: 1,
  6629. stackDelta: 0,
  6630. stackFn: function stack_div(stack, index) {
  6631. stack[index - 1] = -stack[index - 1];
  6632. }
  6633. },
  6634. {
  6635. id: 'eq',
  6636. min: 2,
  6637. stackDelta: -1
  6638. },
  6639. null,
  6640. null,
  6641. {
  6642. id: 'drop',
  6643. min: 1,
  6644. stackDelta: -1
  6645. },
  6646. null,
  6647. {
  6648. id: 'put',
  6649. min: 2,
  6650. stackDelta: -2
  6651. },
  6652. {
  6653. id: 'get',
  6654. min: 1,
  6655. stackDelta: 0
  6656. },
  6657. {
  6658. id: 'ifelse',
  6659. min: 4,
  6660. stackDelta: -3
  6661. },
  6662. {
  6663. id: 'random',
  6664. min: 0,
  6665. stackDelta: 1
  6666. },
  6667. {
  6668. id: 'mul',
  6669. min: 2,
  6670. stackDelta: -1,
  6671. stackFn: function stack_div(stack, index) {
  6672. stack[index - 2] = stack[index - 2] * stack[index - 1];
  6673. }
  6674. },
  6675. null,
  6676. {
  6677. id: 'sqrt',
  6678. min: 1,
  6679. stackDelta: 0
  6680. },
  6681. {
  6682. id: 'dup',
  6683. min: 1,
  6684. stackDelta: 1
  6685. },
  6686. {
  6687. id: 'exch',
  6688. min: 2,
  6689. stackDelta: 0
  6690. },
  6691. {
  6692. id: 'index',
  6693. min: 2,
  6694. stackDelta: 0
  6695. },
  6696. {
  6697. id: 'roll',
  6698. min: 3,
  6699. stackDelta: -2
  6700. },
  6701. null,
  6702. null,
  6703. null,
  6704. {
  6705. id: 'hflex',
  6706. min: 7,
  6707. resetStack: true
  6708. },
  6709. {
  6710. id: 'flex',
  6711. min: 13,
  6712. resetStack: true
  6713. },
  6714. {
  6715. id: 'hflex1',
  6716. min: 9,
  6717. resetStack: true
  6718. },
  6719. {
  6720. id: 'flex1',
  6721. min: 11,
  6722. resetStack: true
  6723. }
  6724. ];
  6725. function CFFParser(file, properties, seacAnalysisEnabled) {
  6726. this.bytes = file.getBytes();
  6727. this.properties = properties;
  6728. this.seacAnalysisEnabled = !!seacAnalysisEnabled;
  6729. }
  6730. CFFParser.prototype = {
  6731. parse: function CFFParser_parse() {
  6732. var properties = this.properties;
  6733. var cff = new CFF();
  6734. this.cff = cff;
  6735. // The first five sections must be in order, all the others are reached
  6736. // via offsets contained in one of the below.
  6737. var header = this.parseHeader();
  6738. var nameIndex = this.parseIndex(header.endPos);
  6739. var topDictIndex = this.parseIndex(nameIndex.endPos);
  6740. var stringIndex = this.parseIndex(topDictIndex.endPos);
  6741. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  6742. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  6743. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  6744. cff.header = header.obj;
  6745. cff.names = this.parseNameIndex(nameIndex.obj);
  6746. cff.strings = this.parseStringIndex(stringIndex.obj);
  6747. cff.topDict = topDict;
  6748. cff.globalSubrIndex = globalSubrIndex.obj;
  6749. this.parsePrivateDict(cff.topDict);
  6750. cff.isCIDFont = topDict.hasName('ROS');
  6751. var charStringOffset = topDict.getByName('CharStrings');
  6752. var charStringIndex = this.parseIndex(charStringOffset).obj;
  6753. var fontMatrix = topDict.getByName('FontMatrix');
  6754. if (fontMatrix) {
  6755. properties.fontMatrix = fontMatrix;
  6756. }
  6757. var fontBBox = topDict.getByName('FontBBox');
  6758. if (fontBBox) {
  6759. // adjusting ascent/descent
  6760. properties.ascent = fontBBox[3];
  6761. properties.descent = fontBBox[1];
  6762. properties.ascentScaled = true;
  6763. }
  6764. var charset, encoding;
  6765. if (cff.isCIDFont) {
  6766. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  6767. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  6768. var dictRaw = fdArrayIndex.get(i);
  6769. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw), cff.strings);
  6770. this.parsePrivateDict(fontDict);
  6771. cff.fdArray.push(fontDict);
  6772. }
  6773. // cid fonts don't have an encoding
  6774. encoding = null;
  6775. charset = this.parseCharsets(topDict.getByName('charset'), charStringIndex.count, cff.strings, true);
  6776. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'), charStringIndex.count);
  6777. } else {
  6778. charset = this.parseCharsets(topDict.getByName('charset'), charStringIndex.count, cff.strings, false);
  6779. encoding = this.parseEncoding(topDict.getByName('Encoding'), properties, cff.strings, charset.charset);
  6780. }
  6781. cff.charset = charset;
  6782. cff.encoding = encoding;
  6783. var charStringsAndSeacs = this.parseCharStrings(charStringIndex, topDict.privateDict.subrsIndex, globalSubrIndex.obj, cff.fdSelect, cff.fdArray);
  6784. cff.charStrings = charStringsAndSeacs.charStrings;
  6785. cff.seacs = charStringsAndSeacs.seacs;
  6786. cff.widths = charStringsAndSeacs.widths;
  6787. return cff;
  6788. },
  6789. parseHeader: function CFFParser_parseHeader() {
  6790. var bytes = this.bytes;
  6791. var bytesLength = bytes.length;
  6792. var offset = 0;
  6793. // Prevent an infinite loop, by checking that the offset is within the
  6794. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  6795. while (offset < bytesLength && bytes[offset] !== 1) {
  6796. ++offset;
  6797. }
  6798. if (offset >= bytesLength) {
  6799. error('Invalid CFF header');
  6800. } else if (offset !== 0) {
  6801. info('cff data is shifted');
  6802. bytes = bytes.subarray(offset);
  6803. this.bytes = bytes;
  6804. }
  6805. var major = bytes[0];
  6806. var minor = bytes[1];
  6807. var hdrSize = bytes[2];
  6808. var offSize = bytes[3];
  6809. var header = new CFFHeader(major, minor, hdrSize, offSize);
  6810. return {
  6811. obj: header,
  6812. endPos: hdrSize
  6813. };
  6814. },
  6815. parseDict: function CFFParser_parseDict(dict) {
  6816. var pos = 0;
  6817. function parseOperand() {
  6818. var value = dict[pos++];
  6819. if (value === 30) {
  6820. return parseFloatOperand();
  6821. } else if (value === 28) {
  6822. value = dict[pos++];
  6823. value = (value << 24 | dict[pos++] << 16) >> 16;
  6824. return value;
  6825. } else if (value === 29) {
  6826. value = dict[pos++];
  6827. value = value << 8 | dict[pos++];
  6828. value = value << 8 | dict[pos++];
  6829. value = value << 8 | dict[pos++];
  6830. return value;
  6831. } else if (value >= 32 && value <= 246) {
  6832. return value - 139;
  6833. } else if (value >= 247 && value <= 250) {
  6834. return (value - 247) * 256 + dict[pos++] + 108;
  6835. } else if (value >= 251 && value <= 254) {
  6836. return -((value - 251) * 256) - dict[pos++] - 108;
  6837. } else {
  6838. error('255 is not a valid DICT command');
  6839. }
  6840. return -1;
  6841. }
  6842. function parseFloatOperand() {
  6843. var str = '';
  6844. var eof = 15;
  6845. var lookup = [
  6846. '0',
  6847. '1',
  6848. '2',
  6849. '3',
  6850. '4',
  6851. '5',
  6852. '6',
  6853. '7',
  6854. '8',
  6855. '9',
  6856. '.',
  6857. 'E',
  6858. 'E-',
  6859. null,
  6860. '-'
  6861. ];
  6862. var length = dict.length;
  6863. while (pos < length) {
  6864. var b = dict[pos++];
  6865. var b1 = b >> 4;
  6866. var b2 = b & 15;
  6867. if (b1 === eof) {
  6868. break;
  6869. }
  6870. str += lookup[b1];
  6871. if (b2 === eof) {
  6872. break;
  6873. }
  6874. str += lookup[b2];
  6875. }
  6876. return parseFloat(str);
  6877. }
  6878. var operands = [];
  6879. var entries = [];
  6880. pos = 0;
  6881. var end = dict.length;
  6882. while (pos < end) {
  6883. var b = dict[pos];
  6884. if (b <= 21) {
  6885. if (b === 12) {
  6886. b = b << 8 | dict[++pos];
  6887. }
  6888. entries.push([
  6889. b,
  6890. operands
  6891. ]);
  6892. operands = [];
  6893. ++pos;
  6894. } else {
  6895. operands.push(parseOperand());
  6896. }
  6897. }
  6898. return entries;
  6899. },
  6900. parseIndex: function CFFParser_parseIndex(pos) {
  6901. var cffIndex = new CFFIndex();
  6902. var bytes = this.bytes;
  6903. var count = bytes[pos++] << 8 | bytes[pos++];
  6904. var offsets = [];
  6905. var end = pos;
  6906. var i, ii;
  6907. if (count !== 0) {
  6908. var offsetSize = bytes[pos++];
  6909. // add 1 for offset to determine size of last object
  6910. var startPos = pos + (count + 1) * offsetSize - 1;
  6911. for (i = 0, ii = count + 1; i < ii; ++i) {
  6912. var offset = 0;
  6913. for (var j = 0; j < offsetSize; ++j) {
  6914. offset <<= 8;
  6915. offset += bytes[pos++];
  6916. }
  6917. offsets.push(startPos + offset);
  6918. }
  6919. end = offsets[count];
  6920. }
  6921. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  6922. var offsetStart = offsets[i];
  6923. var offsetEnd = offsets[i + 1];
  6924. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  6925. }
  6926. return {
  6927. obj: cffIndex,
  6928. endPos: end
  6929. };
  6930. },
  6931. parseNameIndex: function CFFParser_parseNameIndex(index) {
  6932. var names = [];
  6933. for (var i = 0, ii = index.count; i < ii; ++i) {
  6934. var name = index.get(i);
  6935. // OTS doesn't allow names to be over 127 characters.
  6936. var length = Math.min(name.length, 127);
  6937. var data = [];
  6938. // OTS also only permits certain characters in the name.
  6939. for (var j = 0; j < length; ++j) {
  6940. var c = name[j];
  6941. if (j === 0 && c === 0) {
  6942. data[j] = c;
  6943. continue;
  6944. }
  6945. if (c < 33 || c > 126 || c === 91 || /* [ */
  6946. c === 93 || /* ] */
  6947. c === 40 || /* ( */
  6948. c === 41 || /* ) */
  6949. c === 123 || /* { */
  6950. c === 125 || /* } */
  6951. c === 60 || /* < */
  6952. c === 62 || /* > */
  6953. c === 47 || /* / */
  6954. c === 37 || /* % */
  6955. c === 35)
  6956. /* # */
  6957. {
  6958. data[j] = 95;
  6959. continue;
  6960. }
  6961. data[j] = c;
  6962. }
  6963. names.push(bytesToString(data));
  6964. }
  6965. return names;
  6966. },
  6967. parseStringIndex: function CFFParser_parseStringIndex(index) {
  6968. var strings = new CFFStrings();
  6969. for (var i = 0, ii = index.count; i < ii; ++i) {
  6970. var data = index.get(i);
  6971. strings.add(bytesToString(data));
  6972. }
  6973. return strings;
  6974. },
  6975. createDict: function CFFParser_createDict(Type, dict, strings) {
  6976. var cffDict = new Type(strings);
  6977. for (var i = 0, ii = dict.length; i < ii; ++i) {
  6978. var pair = dict[i];
  6979. var key = pair[0];
  6980. var value = pair[1];
  6981. cffDict.setByKey(key, value);
  6982. }
  6983. return cffDict;
  6984. },
  6985. parseCharString: function CFFParser_parseCharString(state, data, localSubrIndex, globalSubrIndex) {
  6986. if (state.callDepth > MAX_SUBR_NESTING) {
  6987. return false;
  6988. }
  6989. var stackSize = state.stackSize;
  6990. var stack = state.stack;
  6991. var length = data.length;
  6992. for (var j = 0; j < length;) {
  6993. var value = data[j++];
  6994. var validationCommand = null;
  6995. if (value === 12) {
  6996. var q = data[j++];
  6997. if (q === 0) {
  6998. // The CFF specification state that the 'dotsection' command
  6999. // (12, 0) is deprecated and treated as a no-op, but all Type2
  7000. // charstrings processors should support them. Unfortunately
  7001. // the font sanitizer don't. As a workaround the sequence (12, 0)
  7002. // is replaced by a useless (0, hmoveto).
  7003. data[j - 2] = 139;
  7004. data[j - 1] = 22;
  7005. stackSize = 0;
  7006. } else {
  7007. validationCommand = CharstringValidationData12[q];
  7008. }
  7009. } else if (value === 28) {
  7010. // number (16 bit)
  7011. stack[stackSize] = (data[j] << 24 | data[j + 1] << 16) >> 16;
  7012. j += 2;
  7013. stackSize++;
  7014. } else if (value === 14) {
  7015. if (stackSize >= 4) {
  7016. stackSize -= 4;
  7017. if (this.seacAnalysisEnabled) {
  7018. state.seac = stack.slice(stackSize, stackSize + 4);
  7019. return false;
  7020. }
  7021. }
  7022. validationCommand = CharstringValidationData[value];
  7023. } else if (value >= 32 && value <= 246) {
  7024. // number
  7025. stack[stackSize] = value - 139;
  7026. stackSize++;
  7027. } else if (value >= 247 && value <= 254) {
  7028. // number (+1 bytes)
  7029. stack[stackSize] = value < 251 ? (value - 247 << 8) + data[j] + 108 : -(value - 251 << 8) - data[j] - 108;
  7030. j++;
  7031. stackSize++;
  7032. } else if (value === 255) {
  7033. // number (32 bit)
  7034. stack[stackSize] = (data[j] << 24 | data[j + 1] << 16 | data[j + 2] << 8 | data[j + 3]) / 65536;
  7035. j += 4;
  7036. stackSize++;
  7037. } else if (value === 19 || value === 20) {
  7038. state.hints += stackSize >> 1;
  7039. // skipping right amount of hints flag data
  7040. j += state.hints + 7 >> 3;
  7041. stackSize %= 2;
  7042. validationCommand = CharstringValidationData[value];
  7043. } else if (value === 10 || value === 29) {
  7044. var subrsIndex;
  7045. if (value === 10) {
  7046. subrsIndex = localSubrIndex;
  7047. } else {
  7048. subrsIndex = globalSubrIndex;
  7049. }
  7050. if (!subrsIndex) {
  7051. validationCommand = CharstringValidationData[value];
  7052. warn('Missing subrsIndex for ' + validationCommand.id);
  7053. return false;
  7054. }
  7055. var bias = 32768;
  7056. if (subrsIndex.count < 1240) {
  7057. bias = 107;
  7058. } else if (subrsIndex.count < 33900) {
  7059. bias = 1131;
  7060. }
  7061. var subrNumber = stack[--stackSize] + bias;
  7062. if (subrNumber < 0 || subrNumber >= subrsIndex.count) {
  7063. validationCommand = CharstringValidationData[value];
  7064. warn('Out of bounds subrIndex for ' + validationCommand.id);
  7065. return false;
  7066. }
  7067. state.stackSize = stackSize;
  7068. state.callDepth++;
  7069. var valid = this.parseCharString(state, subrsIndex.get(subrNumber), localSubrIndex, globalSubrIndex);
  7070. if (!valid) {
  7071. return false;
  7072. }
  7073. state.callDepth--;
  7074. stackSize = state.stackSize;
  7075. continue;
  7076. } else if (value === 11) {
  7077. state.stackSize = stackSize;
  7078. return true;
  7079. } else {
  7080. validationCommand = CharstringValidationData[value];
  7081. }
  7082. if (validationCommand) {
  7083. if (validationCommand.stem) {
  7084. state.hints += stackSize >> 1;
  7085. }
  7086. if ('min' in validationCommand) {
  7087. if (!state.undefStack && stackSize < validationCommand.min) {
  7088. warn('Not enough parameters for ' + validationCommand.id + '; actual: ' + stackSize + ', expected: ' + validationCommand.min);
  7089. return false;
  7090. }
  7091. }
  7092. if (state.firstStackClearing && validationCommand.stackClearing) {
  7093. state.firstStackClearing = false;
  7094. // the optional character width can be found before the first
  7095. // stack-clearing command arguments
  7096. stackSize -= validationCommand.min;
  7097. if (stackSize >= 2 && validationCommand.stem) {
  7098. // there are even amount of arguments for stem commands
  7099. stackSize %= 2;
  7100. } else if (stackSize > 1) {
  7101. warn('Found too many parameters for stack-clearing command');
  7102. }
  7103. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  7104. state.width = stack[stackSize - 1];
  7105. }
  7106. }
  7107. if ('stackDelta' in validationCommand) {
  7108. if ('stackFn' in validationCommand) {
  7109. validationCommand.stackFn(stack, stackSize);
  7110. }
  7111. stackSize += validationCommand.stackDelta;
  7112. } else if (validationCommand.stackClearing) {
  7113. stackSize = 0;
  7114. } else if (validationCommand.resetStack) {
  7115. stackSize = 0;
  7116. state.undefStack = false;
  7117. } else if (validationCommand.undefStack) {
  7118. stackSize = 0;
  7119. state.undefStack = true;
  7120. state.firstStackClearing = false;
  7121. }
  7122. }
  7123. }
  7124. state.stackSize = stackSize;
  7125. return true;
  7126. },
  7127. parseCharStrings: function CFFParser_parseCharStrings(charStrings, localSubrIndex, globalSubrIndex, fdSelect, fdArray) {
  7128. var seacs = [];
  7129. var widths = [];
  7130. var count = charStrings.count;
  7131. for (var i = 0; i < count; i++) {
  7132. var charstring = charStrings.get(i);
  7133. var state = {
  7134. callDepth: 0,
  7135. stackSize: 0,
  7136. stack: [],
  7137. undefStack: true,
  7138. hints: 0,
  7139. firstStackClearing: true,
  7140. seac: null,
  7141. width: null
  7142. };
  7143. var valid = true;
  7144. var localSubrToUse = null;
  7145. if (fdSelect && fdArray.length) {
  7146. var fdIndex = fdSelect.getFDIndex(i);
  7147. if (fdIndex === -1) {
  7148. warn('Glyph index is not in fd select.');
  7149. valid = false;
  7150. }
  7151. if (fdIndex >= fdArray.length) {
  7152. warn('Invalid fd index for glyph index.');
  7153. valid = false;
  7154. }
  7155. if (valid) {
  7156. localSubrToUse = fdArray[fdIndex].privateDict.subrsIndex;
  7157. }
  7158. } else if (localSubrIndex) {
  7159. localSubrToUse = localSubrIndex;
  7160. }
  7161. if (valid) {
  7162. valid = this.parseCharString(state, charstring, localSubrToUse, globalSubrIndex);
  7163. }
  7164. if (state.width !== null) {
  7165. widths[i] = state.width;
  7166. }
  7167. if (state.seac !== null) {
  7168. seacs[i] = state.seac;
  7169. }
  7170. if (!valid) {
  7171. // resetting invalid charstring to single 'endchar'
  7172. charStrings.set(i, new Uint8Array([14]));
  7173. }
  7174. }
  7175. return {
  7176. charStrings: charStrings,
  7177. seacs: seacs,
  7178. widths: widths
  7179. };
  7180. },
  7181. emptyPrivateDictionary: function CFFParser_emptyPrivateDictionary(parentDict) {
  7182. var privateDict = this.createDict(CFFPrivateDict, [], parentDict.strings);
  7183. parentDict.setByKey(18, [
  7184. 0,
  7185. 0
  7186. ]);
  7187. parentDict.privateDict = privateDict;
  7188. },
  7189. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  7190. // no private dict, do nothing
  7191. if (!parentDict.hasName('Private')) {
  7192. this.emptyPrivateDictionary(parentDict);
  7193. return;
  7194. }
  7195. var privateOffset = parentDict.getByName('Private');
  7196. // make sure the params are formatted correctly
  7197. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  7198. parentDict.removeByName('Private');
  7199. return;
  7200. }
  7201. var size = privateOffset[0];
  7202. var offset = privateOffset[1];
  7203. // remove empty dicts or ones that refer to invalid location
  7204. if (size === 0 || offset >= this.bytes.length) {
  7205. this.emptyPrivateDictionary(parentDict);
  7206. return;
  7207. }
  7208. var privateDictEnd = offset + size;
  7209. var dictData = this.bytes.subarray(offset, privateDictEnd);
  7210. var dict = this.parseDict(dictData);
  7211. var privateDict = this.createDict(CFFPrivateDict, dict, parentDict.strings);
  7212. parentDict.privateDict = privateDict;
  7213. // Parse the Subrs index also since it's relative to the private dict.
  7214. if (!privateDict.getByName('Subrs')) {
  7215. return;
  7216. }
  7217. var subrsOffset = privateDict.getByName('Subrs');
  7218. var relativeOffset = offset + subrsOffset;
  7219. // Validate the offset.
  7220. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  7221. this.emptyPrivateDictionary(parentDict);
  7222. return;
  7223. }
  7224. var subrsIndex = this.parseIndex(relativeOffset);
  7225. privateDict.subrsIndex = subrsIndex.obj;
  7226. },
  7227. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  7228. if (pos === 0) {
  7229. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE, ISOAdobeCharset);
  7230. } else if (pos === 1) {
  7231. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT, ExpertCharset);
  7232. } else if (pos === 2) {
  7233. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET, ExpertSubsetCharset);
  7234. }
  7235. var bytes = this.bytes;
  7236. var start = pos;
  7237. var format = bytes[pos++];
  7238. var charset = ['.notdef'];
  7239. var id, count, i;
  7240. // subtract 1 for the .notdef glyph
  7241. length -= 1;
  7242. switch (format) {
  7243. case 0:
  7244. for (i = 0; i < length; i++) {
  7245. id = bytes[pos++] << 8 | bytes[pos++];
  7246. charset.push(cid ? id : strings.get(id));
  7247. }
  7248. break;
  7249. case 1:
  7250. while (charset.length <= length) {
  7251. id = bytes[pos++] << 8 | bytes[pos++];
  7252. count = bytes[pos++];
  7253. for (i = 0; i <= count; i++) {
  7254. charset.push(cid ? id++ : strings.get(id++));
  7255. }
  7256. }
  7257. break;
  7258. case 2:
  7259. while (charset.length <= length) {
  7260. id = bytes[pos++] << 8 | bytes[pos++];
  7261. count = bytes[pos++] << 8 | bytes[pos++];
  7262. for (i = 0; i <= count; i++) {
  7263. charset.push(cid ? id++ : strings.get(id++));
  7264. }
  7265. }
  7266. break;
  7267. default:
  7268. error('Unknown charset format');
  7269. }
  7270. // Raw won't be needed if we actually compile the charset.
  7271. var end = pos;
  7272. var raw = bytes.subarray(start, end);
  7273. return new CFFCharset(false, format, charset, raw);
  7274. },
  7275. parseEncoding: function CFFParser_parseEncoding(pos, properties, strings, charset) {
  7276. var encoding = Object.create(null);
  7277. var bytes = this.bytes;
  7278. var predefined = false;
  7279. var hasSupplement = false;
  7280. var format, i, ii;
  7281. var raw = null;
  7282. function readSupplement() {
  7283. var supplementsCount = bytes[pos++];
  7284. for (i = 0; i < supplementsCount; i++) {
  7285. var code = bytes[pos++];
  7286. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  7287. encoding[code] = charset.indexOf(strings.get(sid));
  7288. }
  7289. }
  7290. if (pos === 0 || pos === 1) {
  7291. predefined = true;
  7292. format = pos;
  7293. var baseEncoding = pos ? ExpertEncoding : StandardEncoding;
  7294. for (i = 0, ii = charset.length; i < ii; i++) {
  7295. var index = baseEncoding.indexOf(charset[i]);
  7296. if (index !== -1) {
  7297. encoding[index] = i;
  7298. }
  7299. }
  7300. } else {
  7301. var dataStart = pos;
  7302. format = bytes[pos++];
  7303. switch (format & 0x7f) {
  7304. case 0:
  7305. var glyphsCount = bytes[pos++];
  7306. for (i = 1; i <= glyphsCount; i++) {
  7307. encoding[bytes[pos++]] = i;
  7308. }
  7309. break;
  7310. case 1:
  7311. var rangesCount = bytes[pos++];
  7312. var gid = 1;
  7313. for (i = 0; i < rangesCount; i++) {
  7314. var start = bytes[pos++];
  7315. var left = bytes[pos++];
  7316. for (var j = start; j <= start + left; j++) {
  7317. encoding[j] = gid++;
  7318. }
  7319. }
  7320. break;
  7321. default:
  7322. error('Unknown encoding format: ' + format + ' in CFF');
  7323. break;
  7324. }
  7325. var dataEnd = pos;
  7326. if (format & 0x80) {
  7327. // The font sanitizer does not support CFF encoding with a
  7328. // supplement, since the encoding is not really used to map
  7329. // between gid to glyph, let's overwrite what is declared in
  7330. // the top dictionary to let the sanitizer think the font use
  7331. // StandardEncoding, that's a lie but that's ok.
  7332. bytes[dataStart] &= 0x7f;
  7333. readSupplement();
  7334. hasSupplement = true;
  7335. }
  7336. raw = bytes.subarray(dataStart, dataEnd);
  7337. }
  7338. format = format & 0x7f;
  7339. return new CFFEncoding(predefined, format, encoding, raw);
  7340. },
  7341. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  7342. var start = pos;
  7343. var bytes = this.bytes;
  7344. var format = bytes[pos++];
  7345. var fdSelect = [], rawBytes;
  7346. var i, invalidFirstGID = false;
  7347. switch (format) {
  7348. case 0:
  7349. for (i = 0; i < length; ++i) {
  7350. var id = bytes[pos++];
  7351. fdSelect.push(id);
  7352. }
  7353. rawBytes = bytes.subarray(start, pos);
  7354. break;
  7355. case 3:
  7356. var rangesCount = bytes[pos++] << 8 | bytes[pos++];
  7357. for (i = 0; i < rangesCount; ++i) {
  7358. var first = bytes[pos++] << 8 | bytes[pos++];
  7359. if (i === 0 && first !== 0) {
  7360. warn('parseFDSelect: The first range must have a first GID of 0' + ' -- trying to recover.');
  7361. invalidFirstGID = true;
  7362. first = 0;
  7363. }
  7364. var fdIndex = bytes[pos++];
  7365. var next = bytes[pos] << 8 | bytes[pos + 1];
  7366. for (var j = first; j < next; ++j) {
  7367. fdSelect.push(fdIndex);
  7368. }
  7369. }
  7370. // Advance past the sentinel(next).
  7371. pos += 2;
  7372. rawBytes = bytes.subarray(start, pos);
  7373. if (invalidFirstGID) {
  7374. rawBytes[3] = rawBytes[4] = 0;
  7375. }
  7376. // Adjust the first range, first GID.
  7377. break;
  7378. default:
  7379. error('parseFDSelect: Unknown format "' + format + '".');
  7380. break;
  7381. }
  7382. assert(fdSelect.length === length, 'parseFDSelect: Invalid font data.');
  7383. return new CFFFDSelect(fdSelect, rawBytes);
  7384. }
  7385. };
  7386. return CFFParser;
  7387. }();
  7388. // Compact Font Format
  7389. var CFF = function CFFClosure() {
  7390. function CFF() {
  7391. this.header = null;
  7392. this.names = [];
  7393. this.topDict = null;
  7394. this.strings = new CFFStrings();
  7395. this.globalSubrIndex = null;
  7396. // The following could really be per font, but since we only have one font
  7397. // store them here.
  7398. this.encoding = null;
  7399. this.charset = null;
  7400. this.charStrings = null;
  7401. this.fdArray = [];
  7402. this.fdSelect = null;
  7403. this.isCIDFont = false;
  7404. }
  7405. return CFF;
  7406. }();
  7407. var CFFHeader = function CFFHeaderClosure() {
  7408. function CFFHeader(major, minor, hdrSize, offSize) {
  7409. this.major = major;
  7410. this.minor = minor;
  7411. this.hdrSize = hdrSize;
  7412. this.offSize = offSize;
  7413. }
  7414. return CFFHeader;
  7415. }();
  7416. var CFFStrings = function CFFStringsClosure() {
  7417. function CFFStrings() {
  7418. this.strings = [];
  7419. }
  7420. CFFStrings.prototype = {
  7421. get: function CFFStrings_get(index) {
  7422. if (index >= 0 && index <= 390) {
  7423. return CFFStandardStrings[index];
  7424. }
  7425. if (index - 391 <= this.strings.length) {
  7426. return this.strings[index - 391];
  7427. }
  7428. return CFFStandardStrings[0];
  7429. },
  7430. add: function CFFStrings_add(value) {
  7431. this.strings.push(value);
  7432. },
  7433. get count() {
  7434. return this.strings.length;
  7435. }
  7436. };
  7437. return CFFStrings;
  7438. }();
  7439. var CFFIndex = function CFFIndexClosure() {
  7440. function CFFIndex() {
  7441. this.objects = [];
  7442. this.length = 0;
  7443. }
  7444. CFFIndex.prototype = {
  7445. add: function CFFIndex_add(data) {
  7446. this.length += data.length;
  7447. this.objects.push(data);
  7448. },
  7449. set: function CFFIndex_set(index, data) {
  7450. this.length += data.length - this.objects[index].length;
  7451. this.objects[index] = data;
  7452. },
  7453. get: function CFFIndex_get(index) {
  7454. return this.objects[index];
  7455. },
  7456. get count() {
  7457. return this.objects.length;
  7458. }
  7459. };
  7460. return CFFIndex;
  7461. }();
  7462. var CFFDict = function CFFDictClosure() {
  7463. function CFFDict(tables, strings) {
  7464. this.keyToNameMap = tables.keyToNameMap;
  7465. this.nameToKeyMap = tables.nameToKeyMap;
  7466. this.defaults = tables.defaults;
  7467. this.types = tables.types;
  7468. this.opcodes = tables.opcodes;
  7469. this.order = tables.order;
  7470. this.strings = strings;
  7471. this.values = Object.create(null);
  7472. }
  7473. CFFDict.prototype = {
  7474. // value should always be an array
  7475. setByKey: function CFFDict_setByKey(key, value) {
  7476. if (!(key in this.keyToNameMap)) {
  7477. return false;
  7478. }
  7479. // ignore empty values
  7480. if (value.length === 0) {
  7481. return true;
  7482. }
  7483. var type = this.types[key];
  7484. // remove the array wrapping these types of values
  7485. if (type === 'num' || type === 'sid' || type === 'offset') {
  7486. value = value[0];
  7487. // Ignore invalid values (fixes bug 1068432).
  7488. if (isNaN(value)) {
  7489. warn('Invalid CFFDict value: ' + value + ', for key: ' + key + '.');
  7490. return true;
  7491. }
  7492. }
  7493. this.values[key] = value;
  7494. return true;
  7495. },
  7496. setByName: function CFFDict_setByName(name, value) {
  7497. if (!(name in this.nameToKeyMap)) {
  7498. error('Invalid dictionary name "' + name + '"');
  7499. }
  7500. this.values[this.nameToKeyMap[name]] = value;
  7501. },
  7502. hasName: function CFFDict_hasName(name) {
  7503. return this.nameToKeyMap[name] in this.values;
  7504. },
  7505. getByName: function CFFDict_getByName(name) {
  7506. if (!(name in this.nameToKeyMap)) {
  7507. error('Invalid dictionary name "' + name + '"');
  7508. }
  7509. var key = this.nameToKeyMap[name];
  7510. if (!(key in this.values)) {
  7511. return this.defaults[key];
  7512. }
  7513. return this.values[key];
  7514. },
  7515. removeByName: function CFFDict_removeByName(name) {
  7516. delete this.values[this.nameToKeyMap[name]];
  7517. }
  7518. };
  7519. CFFDict.createTables = function CFFDict_createTables(layout) {
  7520. var tables = {
  7521. keyToNameMap: {},
  7522. nameToKeyMap: {},
  7523. defaults: {},
  7524. types: {},
  7525. opcodes: {},
  7526. order: []
  7527. };
  7528. for (var i = 0, ii = layout.length; i < ii; ++i) {
  7529. var entry = layout[i];
  7530. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  7531. tables.keyToNameMap[key] = entry[1];
  7532. tables.nameToKeyMap[entry[1]] = key;
  7533. tables.types[key] = entry[2];
  7534. tables.defaults[key] = entry[3];
  7535. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  7536. tables.order.push(key);
  7537. }
  7538. return tables;
  7539. };
  7540. return CFFDict;
  7541. }();
  7542. var CFFTopDict = function CFFTopDictClosure() {
  7543. var layout = [
  7544. [
  7545. [
  7546. 12,
  7547. 30
  7548. ],
  7549. 'ROS',
  7550. [
  7551. 'sid',
  7552. 'sid',
  7553. 'num'
  7554. ],
  7555. null
  7556. ],
  7557. [
  7558. [
  7559. 12,
  7560. 20
  7561. ],
  7562. 'SyntheticBase',
  7563. 'num',
  7564. null
  7565. ],
  7566. [
  7567. 0,
  7568. 'version',
  7569. 'sid',
  7570. null
  7571. ],
  7572. [
  7573. 1,
  7574. 'Notice',
  7575. 'sid',
  7576. null
  7577. ],
  7578. [
  7579. [
  7580. 12,
  7581. 0
  7582. ],
  7583. 'Copyright',
  7584. 'sid',
  7585. null
  7586. ],
  7587. [
  7588. 2,
  7589. 'FullName',
  7590. 'sid',
  7591. null
  7592. ],
  7593. [
  7594. 3,
  7595. 'FamilyName',
  7596. 'sid',
  7597. null
  7598. ],
  7599. [
  7600. 4,
  7601. 'Weight',
  7602. 'sid',
  7603. null
  7604. ],
  7605. [
  7606. [
  7607. 12,
  7608. 1
  7609. ],
  7610. 'isFixedPitch',
  7611. 'num',
  7612. 0
  7613. ],
  7614. [
  7615. [
  7616. 12,
  7617. 2
  7618. ],
  7619. 'ItalicAngle',
  7620. 'num',
  7621. 0
  7622. ],
  7623. [
  7624. [
  7625. 12,
  7626. 3
  7627. ],
  7628. 'UnderlinePosition',
  7629. 'num',
  7630. -100
  7631. ],
  7632. [
  7633. [
  7634. 12,
  7635. 4
  7636. ],
  7637. 'UnderlineThickness',
  7638. 'num',
  7639. 50
  7640. ],
  7641. [
  7642. [
  7643. 12,
  7644. 5
  7645. ],
  7646. 'PaintType',
  7647. 'num',
  7648. 0
  7649. ],
  7650. [
  7651. [
  7652. 12,
  7653. 6
  7654. ],
  7655. 'CharstringType',
  7656. 'num',
  7657. 2
  7658. ],
  7659. [
  7660. [
  7661. 12,
  7662. 7
  7663. ],
  7664. 'FontMatrix',
  7665. [
  7666. 'num',
  7667. 'num',
  7668. 'num',
  7669. 'num',
  7670. 'num',
  7671. 'num'
  7672. ],
  7673. [
  7674. 0.001,
  7675. 0,
  7676. 0,
  7677. 0.001,
  7678. 0,
  7679. 0
  7680. ]
  7681. ],
  7682. [
  7683. 13,
  7684. 'UniqueID',
  7685. 'num',
  7686. null
  7687. ],
  7688. [
  7689. 5,
  7690. 'FontBBox',
  7691. [
  7692. 'num',
  7693. 'num',
  7694. 'num',
  7695. 'num'
  7696. ],
  7697. [
  7698. 0,
  7699. 0,
  7700. 0,
  7701. 0
  7702. ]
  7703. ],
  7704. [
  7705. [
  7706. 12,
  7707. 8
  7708. ],
  7709. 'StrokeWidth',
  7710. 'num',
  7711. 0
  7712. ],
  7713. [
  7714. 14,
  7715. 'XUID',
  7716. 'array',
  7717. null
  7718. ],
  7719. [
  7720. 15,
  7721. 'charset',
  7722. 'offset',
  7723. 0
  7724. ],
  7725. [
  7726. 16,
  7727. 'Encoding',
  7728. 'offset',
  7729. 0
  7730. ],
  7731. [
  7732. 17,
  7733. 'CharStrings',
  7734. 'offset',
  7735. 0
  7736. ],
  7737. [
  7738. 18,
  7739. 'Private',
  7740. [
  7741. 'offset',
  7742. 'offset'
  7743. ],
  7744. null
  7745. ],
  7746. [
  7747. [
  7748. 12,
  7749. 21
  7750. ],
  7751. 'PostScript',
  7752. 'sid',
  7753. null
  7754. ],
  7755. [
  7756. [
  7757. 12,
  7758. 22
  7759. ],
  7760. 'BaseFontName',
  7761. 'sid',
  7762. null
  7763. ],
  7764. [
  7765. [
  7766. 12,
  7767. 23
  7768. ],
  7769. 'BaseFontBlend',
  7770. 'delta',
  7771. null
  7772. ],
  7773. [
  7774. [
  7775. 12,
  7776. 31
  7777. ],
  7778. 'CIDFontVersion',
  7779. 'num',
  7780. 0
  7781. ],
  7782. [
  7783. [
  7784. 12,
  7785. 32
  7786. ],
  7787. 'CIDFontRevision',
  7788. 'num',
  7789. 0
  7790. ],
  7791. [
  7792. [
  7793. 12,
  7794. 33
  7795. ],
  7796. 'CIDFontType',
  7797. 'num',
  7798. 0
  7799. ],
  7800. [
  7801. [
  7802. 12,
  7803. 34
  7804. ],
  7805. 'CIDCount',
  7806. 'num',
  7807. 8720
  7808. ],
  7809. [
  7810. [
  7811. 12,
  7812. 35
  7813. ],
  7814. 'UIDBase',
  7815. 'num',
  7816. null
  7817. ],
  7818. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  7819. // before FDArray.
  7820. [
  7821. [
  7822. 12,
  7823. 37
  7824. ],
  7825. 'FDSelect',
  7826. 'offset',
  7827. null
  7828. ],
  7829. [
  7830. [
  7831. 12,
  7832. 36
  7833. ],
  7834. 'FDArray',
  7835. 'offset',
  7836. null
  7837. ],
  7838. [
  7839. [
  7840. 12,
  7841. 38
  7842. ],
  7843. 'FontName',
  7844. 'sid',
  7845. null
  7846. ]
  7847. ];
  7848. var tables = null;
  7849. function CFFTopDict(strings) {
  7850. if (tables === null) {
  7851. tables = CFFDict.createTables(layout);
  7852. }
  7853. CFFDict.call(this, tables, strings);
  7854. this.privateDict = null;
  7855. }
  7856. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  7857. return CFFTopDict;
  7858. }();
  7859. var CFFPrivateDict = function CFFPrivateDictClosure() {
  7860. var layout = [
  7861. [
  7862. 6,
  7863. 'BlueValues',
  7864. 'delta',
  7865. null
  7866. ],
  7867. [
  7868. 7,
  7869. 'OtherBlues',
  7870. 'delta',
  7871. null
  7872. ],
  7873. [
  7874. 8,
  7875. 'FamilyBlues',
  7876. 'delta',
  7877. null
  7878. ],
  7879. [
  7880. 9,
  7881. 'FamilyOtherBlues',
  7882. 'delta',
  7883. null
  7884. ],
  7885. [
  7886. [
  7887. 12,
  7888. 9
  7889. ],
  7890. 'BlueScale',
  7891. 'num',
  7892. 0.039625
  7893. ],
  7894. [
  7895. [
  7896. 12,
  7897. 10
  7898. ],
  7899. 'BlueShift',
  7900. 'num',
  7901. 7
  7902. ],
  7903. [
  7904. [
  7905. 12,
  7906. 11
  7907. ],
  7908. 'BlueFuzz',
  7909. 'num',
  7910. 1
  7911. ],
  7912. [
  7913. 10,
  7914. 'StdHW',
  7915. 'num',
  7916. null
  7917. ],
  7918. [
  7919. 11,
  7920. 'StdVW',
  7921. 'num',
  7922. null
  7923. ],
  7924. [
  7925. [
  7926. 12,
  7927. 12
  7928. ],
  7929. 'StemSnapH',
  7930. 'delta',
  7931. null
  7932. ],
  7933. [
  7934. [
  7935. 12,
  7936. 13
  7937. ],
  7938. 'StemSnapV',
  7939. 'delta',
  7940. null
  7941. ],
  7942. [
  7943. [
  7944. 12,
  7945. 14
  7946. ],
  7947. 'ForceBold',
  7948. 'num',
  7949. 0
  7950. ],
  7951. [
  7952. [
  7953. 12,
  7954. 17
  7955. ],
  7956. 'LanguageGroup',
  7957. 'num',
  7958. 0
  7959. ],
  7960. [
  7961. [
  7962. 12,
  7963. 18
  7964. ],
  7965. 'ExpansionFactor',
  7966. 'num',
  7967. 0.06
  7968. ],
  7969. [
  7970. [
  7971. 12,
  7972. 19
  7973. ],
  7974. 'initialRandomSeed',
  7975. 'num',
  7976. 0
  7977. ],
  7978. [
  7979. 20,
  7980. 'defaultWidthX',
  7981. 'num',
  7982. 0
  7983. ],
  7984. [
  7985. 21,
  7986. 'nominalWidthX',
  7987. 'num',
  7988. 0
  7989. ],
  7990. [
  7991. 19,
  7992. 'Subrs',
  7993. 'offset',
  7994. null
  7995. ]
  7996. ];
  7997. var tables = null;
  7998. function CFFPrivateDict(strings) {
  7999. if (tables === null) {
  8000. tables = CFFDict.createTables(layout);
  8001. }
  8002. CFFDict.call(this, tables, strings);
  8003. this.subrsIndex = null;
  8004. }
  8005. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  8006. return CFFPrivateDict;
  8007. }();
  8008. var CFFCharsetPredefinedTypes = {
  8009. ISO_ADOBE: 0,
  8010. EXPERT: 1,
  8011. EXPERT_SUBSET: 2
  8012. };
  8013. var CFFCharset = function CFFCharsetClosure() {
  8014. function CFFCharset(predefined, format, charset, raw) {
  8015. this.predefined = predefined;
  8016. this.format = format;
  8017. this.charset = charset;
  8018. this.raw = raw;
  8019. }
  8020. return CFFCharset;
  8021. }();
  8022. var CFFEncoding = function CFFEncodingClosure() {
  8023. function CFFEncoding(predefined, format, encoding, raw) {
  8024. this.predefined = predefined;
  8025. this.format = format;
  8026. this.encoding = encoding;
  8027. this.raw = raw;
  8028. }
  8029. return CFFEncoding;
  8030. }();
  8031. var CFFFDSelect = function CFFFDSelectClosure() {
  8032. function CFFFDSelect(fdSelect, raw) {
  8033. this.fdSelect = fdSelect;
  8034. this.raw = raw;
  8035. }
  8036. CFFFDSelect.prototype = {
  8037. getFDIndex: function CFFFDSelect_get(glyphIndex) {
  8038. if (glyphIndex < 0 || glyphIndex >= this.fdSelect.length) {
  8039. return -1;
  8040. }
  8041. return this.fdSelect[glyphIndex];
  8042. }
  8043. };
  8044. return CFFFDSelect;
  8045. }();
  8046. // Helper class to keep track of where an offset is within the data and helps
  8047. // filling in that offset once it's known.
  8048. var CFFOffsetTracker = function CFFOffsetTrackerClosure() {
  8049. function CFFOffsetTracker() {
  8050. this.offsets = Object.create(null);
  8051. }
  8052. CFFOffsetTracker.prototype = {
  8053. isTracking: function CFFOffsetTracker_isTracking(key) {
  8054. return key in this.offsets;
  8055. },
  8056. track: function CFFOffsetTracker_track(key, location) {
  8057. if (key in this.offsets) {
  8058. error('Already tracking location of ' + key);
  8059. }
  8060. this.offsets[key] = location;
  8061. },
  8062. offset: function CFFOffsetTracker_offset(value) {
  8063. for (var key in this.offsets) {
  8064. this.offsets[key] += value;
  8065. }
  8066. },
  8067. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key, values, output) {
  8068. if (!(key in this.offsets)) {
  8069. error('Not tracking location of ' + key);
  8070. }
  8071. var data = output.data;
  8072. var dataOffset = this.offsets[key];
  8073. var size = 5;
  8074. for (var i = 0, ii = values.length; i < ii; ++i) {
  8075. var offset0 = i * size + dataOffset;
  8076. var offset1 = offset0 + 1;
  8077. var offset2 = offset0 + 2;
  8078. var offset3 = offset0 + 3;
  8079. var offset4 = offset0 + 4;
  8080. // It's easy to screw up offsets so perform this sanity check.
  8081. if (data[offset0] !== 0x1d || data[offset1] !== 0 || data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  8082. error('writing to an offset that is not empty');
  8083. }
  8084. var value = values[i];
  8085. data[offset0] = 0x1d;
  8086. data[offset1] = value >> 24 & 0xFF;
  8087. data[offset2] = value >> 16 & 0xFF;
  8088. data[offset3] = value >> 8 & 0xFF;
  8089. data[offset4] = value & 0xFF;
  8090. }
  8091. }
  8092. };
  8093. return CFFOffsetTracker;
  8094. }();
  8095. // Takes a CFF and converts it to the binary representation.
  8096. var CFFCompiler = function CFFCompilerClosure() {
  8097. function CFFCompiler(cff) {
  8098. this.cff = cff;
  8099. }
  8100. CFFCompiler.prototype = {
  8101. compile: function CFFCompiler_compile() {
  8102. var cff = this.cff;
  8103. var output = {
  8104. data: [],
  8105. length: 0,
  8106. add: function CFFCompiler_add(data) {
  8107. this.data = this.data.concat(data);
  8108. this.length = this.data.length;
  8109. }
  8110. };
  8111. // Compile the five entries that must be in order.
  8112. var header = this.compileHeader(cff.header);
  8113. output.add(header);
  8114. var nameIndex = this.compileNameIndex(cff.names);
  8115. output.add(nameIndex);
  8116. if (cff.isCIDFont) {
  8117. // The spec is unclear on how font matrices should relate to each other
  8118. // when there is one in the main top dict and the sub top dicts.
  8119. // Windows handles this differently than linux and osx so we have to
  8120. // normalize to work on all.
  8121. // Rules based off of some mailing list discussions:
  8122. // - If main font has a matrix and subfont doesn't, use the main matrix.
  8123. // - If no main font matrix and there is a subfont matrix, use the
  8124. // subfont matrix.
  8125. // - If both have matrices, concat together.
  8126. // - If neither have matrices, use default.
  8127. // To make this work on all platforms we move the top matrix into each
  8128. // sub top dict and concat if necessary.
  8129. if (cff.topDict.hasName('FontMatrix')) {
  8130. var base = cff.topDict.getByName('FontMatrix');
  8131. cff.topDict.removeByName('FontMatrix');
  8132. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  8133. var subDict = cff.fdArray[i];
  8134. var matrix = base.slice(0);
  8135. if (subDict.hasName('FontMatrix')) {
  8136. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  8137. }
  8138. subDict.setByName('FontMatrix', matrix);
  8139. }
  8140. }
  8141. }
  8142. var compiled = this.compileTopDicts([cff.topDict], output.length, cff.isCIDFont);
  8143. output.add(compiled.output);
  8144. var topDictTracker = compiled.trackers[0];
  8145. var stringIndex = this.compileStringIndex(cff.strings.strings);
  8146. output.add(stringIndex);
  8147. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  8148. output.add(globalSubrIndex);
  8149. // Now start on the other entries that have no specific order.
  8150. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  8151. if (cff.encoding.predefined) {
  8152. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format], output);
  8153. } else {
  8154. var encoding = this.compileEncoding(cff.encoding);
  8155. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  8156. output.add(encoding);
  8157. }
  8158. }
  8159. if (cff.charset && cff.topDict.hasName('charset')) {
  8160. if (cff.charset.predefined) {
  8161. topDictTracker.setEntryLocation('charset', [cff.charset.format], output);
  8162. } else {
  8163. var charset = this.compileCharset(cff.charset);
  8164. topDictTracker.setEntryLocation('charset', [output.length], output);
  8165. output.add(charset);
  8166. }
  8167. }
  8168. var charStrings = this.compileCharStrings(cff.charStrings);
  8169. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  8170. output.add(charStrings);
  8171. if (cff.isCIDFont) {
  8172. // For some reason FDSelect must be in front of FDArray on windows. OSX
  8173. // and linux don't seem to care.
  8174. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  8175. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  8176. output.add(fdSelect);
  8177. // It is unclear if the sub font dictionary can have CID related
  8178. // dictionary keys, but the sanitizer doesn't like them so remove them.
  8179. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  8180. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  8181. output.add(compiled.output);
  8182. var fontDictTrackers = compiled.trackers;
  8183. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  8184. }
  8185. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  8186. // If the font data ends with INDEX whose object data is zero-length,
  8187. // the sanitizer will bail out. Add a dummy byte to avoid that.
  8188. output.add([0]);
  8189. return output.data;
  8190. },
  8191. encodeNumber: function CFFCompiler_encodeNumber(value) {
  8192. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) {
  8193. // isInt
  8194. return this.encodeInteger(value);
  8195. } else {
  8196. return this.encodeFloat(value);
  8197. }
  8198. },
  8199. encodeFloat: function CFFCompiler_encodeFloat(num) {
  8200. var value = num.toString();
  8201. // rounding inaccurate doubles
  8202. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  8203. if (m) {
  8204. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  8205. value = (Math.round(num * epsilon) / epsilon).toString();
  8206. }
  8207. var nibbles = '';
  8208. var i, ii;
  8209. for (i = 0, ii = value.length; i < ii; ++i) {
  8210. var a = value[i];
  8211. if (a === 'e') {
  8212. nibbles += value[++i] === '-' ? 'c' : 'b';
  8213. } else if (a === '.') {
  8214. nibbles += 'a';
  8215. } else if (a === '-') {
  8216. nibbles += 'e';
  8217. } else {
  8218. nibbles += a;
  8219. }
  8220. }
  8221. nibbles += nibbles.length & 1 ? 'f' : 'ff';
  8222. var out = [30];
  8223. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  8224. out.push(parseInt(nibbles.substr(i, 2), 16));
  8225. }
  8226. return out;
  8227. },
  8228. encodeInteger: function CFFCompiler_encodeInteger(value) {
  8229. var code;
  8230. if (value >= -107 && value <= 107) {
  8231. code = [value + 139];
  8232. } else if (value >= 108 && value <= 1131) {
  8233. value = value - 108;
  8234. code = [
  8235. (value >> 8) + 247,
  8236. value & 0xFF
  8237. ];
  8238. } else if (value >= -1131 && value <= -108) {
  8239. value = -value - 108;
  8240. code = [
  8241. (value >> 8) + 251,
  8242. value & 0xFF
  8243. ];
  8244. } else if (value >= -32768 && value <= 32767) {
  8245. code = [
  8246. 0x1c,
  8247. value >> 8 & 0xFF,
  8248. value & 0xFF
  8249. ];
  8250. } else {
  8251. code = [
  8252. 0x1d,
  8253. value >> 24 & 0xFF,
  8254. value >> 16 & 0xFF,
  8255. value >> 8 & 0xFF,
  8256. value & 0xFF
  8257. ];
  8258. }
  8259. return code;
  8260. },
  8261. compileHeader: function CFFCompiler_compileHeader(header) {
  8262. return [
  8263. header.major,
  8264. header.minor,
  8265. header.hdrSize,
  8266. header.offSize
  8267. ];
  8268. },
  8269. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  8270. var nameIndex = new CFFIndex();
  8271. for (var i = 0, ii = names.length; i < ii; ++i) {
  8272. nameIndex.add(stringToBytes(names[i]));
  8273. }
  8274. return this.compileIndex(nameIndex);
  8275. },
  8276. compileTopDicts: function CFFCompiler_compileTopDicts(dicts, length, removeCidKeys) {
  8277. var fontDictTrackers = [];
  8278. var fdArrayIndex = new CFFIndex();
  8279. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  8280. var fontDict = dicts[i];
  8281. if (removeCidKeys) {
  8282. fontDict.removeByName('CIDFontVersion');
  8283. fontDict.removeByName('CIDFontRevision');
  8284. fontDict.removeByName('CIDFontType');
  8285. fontDict.removeByName('CIDCount');
  8286. fontDict.removeByName('UIDBase');
  8287. }
  8288. var fontDictTracker = new CFFOffsetTracker();
  8289. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  8290. fontDictTrackers.push(fontDictTracker);
  8291. fdArrayIndex.add(fontDictData);
  8292. fontDictTracker.offset(length);
  8293. }
  8294. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  8295. return {
  8296. trackers: fontDictTrackers,
  8297. output: fdArrayIndex
  8298. };
  8299. },
  8300. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts, trackers, output) {
  8301. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  8302. var fontDict = dicts[i];
  8303. assert(fontDict.privateDict && fontDict.hasName('Private'), 'There must be an private dictionary.');
  8304. var privateDict = fontDict.privateDict;
  8305. var privateDictTracker = new CFFOffsetTracker();
  8306. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  8307. var outputLength = output.length;
  8308. privateDictTracker.offset(outputLength);
  8309. if (!privateDictData.length) {
  8310. // The private dictionary was empty, set the output length to zero to
  8311. // ensure the offset length isn't out of bounds in the eyes of the
  8312. // sanitizer.
  8313. outputLength = 0;
  8314. }
  8315. trackers[i].setEntryLocation('Private', [
  8316. privateDictData.length,
  8317. outputLength
  8318. ], output);
  8319. output.add(privateDictData);
  8320. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  8321. var subrs = this.compileIndex(privateDict.subrsIndex);
  8322. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length], output);
  8323. output.add(subrs);
  8324. }
  8325. }
  8326. },
  8327. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  8328. var out = [];
  8329. // The dictionary keys must be in a certain order.
  8330. var order = dict.order;
  8331. for (var i = 0; i < order.length; ++i) {
  8332. var key = order[i];
  8333. if (!(key in dict.values)) {
  8334. continue;
  8335. }
  8336. var values = dict.values[key];
  8337. var types = dict.types[key];
  8338. if (!isArray(types)) {
  8339. types = [types];
  8340. }
  8341. if (!isArray(values)) {
  8342. values = [values];
  8343. }
  8344. // Remove any empty dict values.
  8345. if (values.length === 0) {
  8346. continue;
  8347. }
  8348. for (var j = 0, jj = types.length; j < jj; ++j) {
  8349. var type = types[j];
  8350. var value = values[j];
  8351. switch (type) {
  8352. case 'num':
  8353. case 'sid':
  8354. out = out.concat(this.encodeNumber(value));
  8355. break;
  8356. case 'offset':
  8357. // For offsets we just insert a 32bit integer so we don't have to
  8358. // deal with figuring out the length of the offset when it gets
  8359. // replaced later on by the compiler.
  8360. var name = dict.keyToNameMap[key];
  8361. // Some offsets have the offset and the length, so just record the
  8362. // position of the first one.
  8363. if (!offsetTracker.isTracking(name)) {
  8364. offsetTracker.track(name, out.length);
  8365. }
  8366. out = out.concat([
  8367. 0x1d,
  8368. 0,
  8369. 0,
  8370. 0,
  8371. 0
  8372. ]);
  8373. break;
  8374. case 'array':
  8375. case 'delta':
  8376. out = out.concat(this.encodeNumber(value));
  8377. for (var k = 1, kk = values.length; k < kk; ++k) {
  8378. out = out.concat(this.encodeNumber(values[k]));
  8379. }
  8380. break;
  8381. default:
  8382. error('Unknown data type of ' + type);
  8383. break;
  8384. }
  8385. }
  8386. out = out.concat(dict.opcodes[key]);
  8387. }
  8388. return out;
  8389. },
  8390. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  8391. var stringIndex = new CFFIndex();
  8392. for (var i = 0, ii = strings.length; i < ii; ++i) {
  8393. stringIndex.add(stringToBytes(strings[i]));
  8394. }
  8395. return this.compileIndex(stringIndex);
  8396. },
  8397. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  8398. var globalSubrIndex = this.cff.globalSubrIndex;
  8399. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  8400. },
  8401. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  8402. return this.compileIndex(charStrings);
  8403. },
  8404. compileCharset: function CFFCompiler_compileCharset(charset) {
  8405. return this.compileTypedArray(charset.raw);
  8406. },
  8407. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  8408. return this.compileTypedArray(encoding.raw);
  8409. },
  8410. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  8411. return this.compileTypedArray(fdSelect);
  8412. },
  8413. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  8414. var out = [];
  8415. for (var i = 0, ii = data.length; i < ii; ++i) {
  8416. out[i] = data[i];
  8417. }
  8418. return out;
  8419. },
  8420. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  8421. trackers = trackers || [];
  8422. var objects = index.objects;
  8423. // First 2 bytes contains the number of objects contained into this index
  8424. var count = objects.length;
  8425. // If there is no object, just create an index. This technically
  8426. // should just be [0, 0] but OTS has an issue with that.
  8427. if (count === 0) {
  8428. return [
  8429. 0,
  8430. 0,
  8431. 0
  8432. ];
  8433. }
  8434. var data = [
  8435. count >> 8 & 0xFF,
  8436. count & 0xff
  8437. ];
  8438. var lastOffset = 1, i;
  8439. for (i = 0; i < count; ++i) {
  8440. lastOffset += objects[i].length;
  8441. }
  8442. var offsetSize;
  8443. if (lastOffset < 0x100) {
  8444. offsetSize = 1;
  8445. } else if (lastOffset < 0x10000) {
  8446. offsetSize = 2;
  8447. } else if (lastOffset < 0x1000000) {
  8448. offsetSize = 3;
  8449. } else {
  8450. offsetSize = 4;
  8451. }
  8452. // Next byte contains the offset size use to reference object in the file
  8453. data.push(offsetSize);
  8454. // Add another offset after this one because we need a new offset
  8455. var relativeOffset = 1;
  8456. for (i = 0; i < count + 1; i++) {
  8457. if (offsetSize === 1) {
  8458. data.push(relativeOffset & 0xFF);
  8459. } else if (offsetSize === 2) {
  8460. data.push(relativeOffset >> 8 & 0xFF, relativeOffset & 0xFF);
  8461. } else if (offsetSize === 3) {
  8462. data.push(relativeOffset >> 16 & 0xFF, relativeOffset >> 8 & 0xFF, relativeOffset & 0xFF);
  8463. } else {
  8464. data.push(relativeOffset >>> 24 & 0xFF, relativeOffset >> 16 & 0xFF, relativeOffset >> 8 & 0xFF, relativeOffset & 0xFF);
  8465. }
  8466. if (objects[i]) {
  8467. relativeOffset += objects[i].length;
  8468. }
  8469. }
  8470. for (i = 0; i < count; i++) {
  8471. // Notify the tracker where the object will be offset in the data.
  8472. if (trackers[i]) {
  8473. trackers[i].offset(data.length);
  8474. }
  8475. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  8476. data.push(objects[i][j]);
  8477. }
  8478. }
  8479. return data;
  8480. }
  8481. };
  8482. return CFFCompiler;
  8483. }();
  8484. exports.CFFStandardStrings = CFFStandardStrings;
  8485. exports.CFFParser = CFFParser;
  8486. exports.CFF = CFF;
  8487. exports.CFFHeader = CFFHeader;
  8488. exports.CFFStrings = CFFStrings;
  8489. exports.CFFIndex = CFFIndex;
  8490. exports.CFFCharset = CFFCharset;
  8491. exports.CFFTopDict = CFFTopDict;
  8492. exports.CFFPrivateDict = CFFPrivateDict;
  8493. exports.CFFCompiler = CFFCompiler;
  8494. }));
  8495. (function (root, factory) {
  8496. factory(root.pdfjsCoreChunkedStream = {}, root.pdfjsSharedUtil);
  8497. }(this, function (exports, sharedUtil) {
  8498. var MissingDataException = sharedUtil.MissingDataException;
  8499. var arrayByteLength = sharedUtil.arrayByteLength;
  8500. var arraysToBytes = sharedUtil.arraysToBytes;
  8501. var assert = sharedUtil.assert;
  8502. var createPromiseCapability = sharedUtil.createPromiseCapability;
  8503. var isInt = sharedUtil.isInt;
  8504. var isEmptyObj = sharedUtil.isEmptyObj;
  8505. var ChunkedStream = function ChunkedStreamClosure() {
  8506. function ChunkedStream(length, chunkSize, manager) {
  8507. this.bytes = new Uint8Array(length);
  8508. this.start = 0;
  8509. this.pos = 0;
  8510. this.end = length;
  8511. this.chunkSize = chunkSize;
  8512. this.loadedChunks = [];
  8513. this.numChunksLoaded = 0;
  8514. this.numChunks = Math.ceil(length / chunkSize);
  8515. this.manager = manager;
  8516. this.progressiveDataLength = 0;
  8517. this.lastSuccessfulEnsureByteChunk = -1;
  8518. }
  8519. // a single-entry cache
  8520. // required methods for a stream. if a particular stream does not
  8521. // implement these, an error should be thrown
  8522. ChunkedStream.prototype = {
  8523. getMissingChunks: function ChunkedStream_getMissingChunks() {
  8524. var chunks = [];
  8525. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  8526. if (!this.loadedChunks[chunk]) {
  8527. chunks.push(chunk);
  8528. }
  8529. }
  8530. return chunks;
  8531. },
  8532. getBaseStreams: function ChunkedStream_getBaseStreams() {
  8533. return [this];
  8534. },
  8535. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  8536. return this.numChunksLoaded === this.numChunks;
  8537. },
  8538. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  8539. var end = begin + chunk.byteLength;
  8540. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  8541. // Using this.length is inaccurate here since this.start can be moved
  8542. // See ChunkedStream.moveStart()
  8543. var length = this.bytes.length;
  8544. assert(end % this.chunkSize === 0 || end === length, 'Bad end offset: ' + end);
  8545. this.bytes.set(new Uint8Array(chunk), begin);
  8546. var chunkSize = this.chunkSize;
  8547. var beginChunk = Math.floor(begin / chunkSize);
  8548. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  8549. var curChunk;
  8550. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  8551. if (!this.loadedChunks[curChunk]) {
  8552. this.loadedChunks[curChunk] = true;
  8553. ++this.numChunksLoaded;
  8554. }
  8555. }
  8556. },
  8557. onReceiveProgressiveData: function ChunkedStream_onReceiveProgressiveData(data) {
  8558. var position = this.progressiveDataLength;
  8559. var beginChunk = Math.floor(position / this.chunkSize);
  8560. this.bytes.set(new Uint8Array(data), position);
  8561. position += data.byteLength;
  8562. this.progressiveDataLength = position;
  8563. var endChunk = position >= this.end ? this.numChunks : Math.floor(position / this.chunkSize);
  8564. var curChunk;
  8565. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  8566. if (!this.loadedChunks[curChunk]) {
  8567. this.loadedChunks[curChunk] = true;
  8568. ++this.numChunksLoaded;
  8569. }
  8570. }
  8571. },
  8572. ensureByte: function ChunkedStream_ensureByte(pos) {
  8573. var chunk = Math.floor(pos / this.chunkSize);
  8574. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  8575. return;
  8576. }
  8577. if (!this.loadedChunks[chunk]) {
  8578. throw new MissingDataException(pos, pos + 1);
  8579. }
  8580. this.lastSuccessfulEnsureByteChunk = chunk;
  8581. },
  8582. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  8583. if (begin >= end) {
  8584. return;
  8585. }
  8586. if (end <= this.progressiveDataLength) {
  8587. return;
  8588. }
  8589. var chunkSize = this.chunkSize;
  8590. var beginChunk = Math.floor(begin / chunkSize);
  8591. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  8592. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  8593. if (!this.loadedChunks[chunk]) {
  8594. throw new MissingDataException(begin, end);
  8595. }
  8596. }
  8597. },
  8598. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  8599. var chunk, numChunks = this.numChunks;
  8600. for (var i = 0; i < numChunks; ++i) {
  8601. chunk = (beginChunk + i) % numChunks;
  8602. // Wrap around to beginning
  8603. if (!this.loadedChunks[chunk]) {
  8604. return chunk;
  8605. }
  8606. }
  8607. return null;
  8608. },
  8609. hasChunk: function ChunkedStream_hasChunk(chunk) {
  8610. return !!this.loadedChunks[chunk];
  8611. },
  8612. get length() {
  8613. return this.end - this.start;
  8614. },
  8615. get isEmpty() {
  8616. return this.length === 0;
  8617. },
  8618. getByte: function ChunkedStream_getByte() {
  8619. var pos = this.pos;
  8620. if (pos >= this.end) {
  8621. return -1;
  8622. }
  8623. this.ensureByte(pos);
  8624. return this.bytes[this.pos++];
  8625. },
  8626. getUint16: function ChunkedStream_getUint16() {
  8627. var b0 = this.getByte();
  8628. var b1 = this.getByte();
  8629. if (b0 === -1 || b1 === -1) {
  8630. return -1;
  8631. }
  8632. return (b0 << 8) + b1;
  8633. },
  8634. getInt32: function ChunkedStream_getInt32() {
  8635. var b0 = this.getByte();
  8636. var b1 = this.getByte();
  8637. var b2 = this.getByte();
  8638. var b3 = this.getByte();
  8639. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  8640. },
  8641. // returns subarray of original buffer
  8642. // should only be read
  8643. getBytes: function ChunkedStream_getBytes(length) {
  8644. var bytes = this.bytes;
  8645. var pos = this.pos;
  8646. var strEnd = this.end;
  8647. if (!length) {
  8648. this.ensureRange(pos, strEnd);
  8649. return bytes.subarray(pos, strEnd);
  8650. }
  8651. var end = pos + length;
  8652. if (end > strEnd) {
  8653. end = strEnd;
  8654. }
  8655. this.ensureRange(pos, end);
  8656. this.pos = end;
  8657. return bytes.subarray(pos, end);
  8658. },
  8659. peekByte: function ChunkedStream_peekByte() {
  8660. var peekedByte = this.getByte();
  8661. this.pos--;
  8662. return peekedByte;
  8663. },
  8664. peekBytes: function ChunkedStream_peekBytes(length) {
  8665. var bytes = this.getBytes(length);
  8666. this.pos -= bytes.length;
  8667. return bytes;
  8668. },
  8669. getByteRange: function ChunkedStream_getBytes(begin, end) {
  8670. this.ensureRange(begin, end);
  8671. return this.bytes.subarray(begin, end);
  8672. },
  8673. skip: function ChunkedStream_skip(n) {
  8674. if (!n) {
  8675. n = 1;
  8676. }
  8677. this.pos += n;
  8678. },
  8679. reset: function ChunkedStream_reset() {
  8680. this.pos = this.start;
  8681. },
  8682. moveStart: function ChunkedStream_moveStart() {
  8683. this.start = this.pos;
  8684. },
  8685. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  8686. this.ensureRange(start, start + length);
  8687. function ChunkedStreamSubstream() {
  8688. }
  8689. ChunkedStreamSubstream.prototype = Object.create(this);
  8690. ChunkedStreamSubstream.prototype.getMissingChunks = function () {
  8691. var chunkSize = this.chunkSize;
  8692. var beginChunk = Math.floor(this.start / chunkSize);
  8693. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  8694. var missingChunks = [];
  8695. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  8696. if (!this.loadedChunks[chunk]) {
  8697. missingChunks.push(chunk);
  8698. }
  8699. }
  8700. return missingChunks;
  8701. };
  8702. var subStream = new ChunkedStreamSubstream();
  8703. subStream.pos = subStream.start = start;
  8704. subStream.end = start + length || this.end;
  8705. subStream.dict = dict;
  8706. return subStream;
  8707. },
  8708. isStream: true
  8709. };
  8710. return ChunkedStream;
  8711. }();
  8712. var ChunkedStreamManager = function ChunkedStreamManagerClosure() {
  8713. function ChunkedStreamManager(pdfNetworkStream, args) {
  8714. var chunkSize = args.rangeChunkSize;
  8715. var length = args.length;
  8716. this.stream = new ChunkedStream(length, chunkSize, this);
  8717. this.length = length;
  8718. this.chunkSize = chunkSize;
  8719. this.pdfNetworkStream = pdfNetworkStream;
  8720. this.url = args.url;
  8721. this.disableAutoFetch = args.disableAutoFetch;
  8722. this.msgHandler = args.msgHandler;
  8723. this.currRequestId = 0;
  8724. this.chunksNeededByRequest = Object.create(null);
  8725. this.requestsByChunk = Object.create(null);
  8726. this.promisesByRequest = Object.create(null);
  8727. this.progressiveDataLength = 0;
  8728. this.aborted = false;
  8729. this._loadedStreamCapability = createPromiseCapability();
  8730. }
  8731. ChunkedStreamManager.prototype = {
  8732. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  8733. return this._loadedStreamCapability.promise;
  8734. },
  8735. sendRequest: function ChunkedStreamManager_sendRequest(begin, end) {
  8736. var rangeReader = this.pdfNetworkStream.getRangeReader(begin, end);
  8737. if (!rangeReader.isStreamingSupported) {
  8738. rangeReader.onProgress = this.onProgress.bind(this);
  8739. }
  8740. var chunks = [], loaded = 0;
  8741. var manager = this;
  8742. var promise = new Promise(function (resolve, reject) {
  8743. var readChunk = function (chunk) {
  8744. try {
  8745. if (!chunk.done) {
  8746. var data = chunk.value;
  8747. chunks.push(data);
  8748. loaded += arrayByteLength(data);
  8749. if (rangeReader.isStreamingSupported) {
  8750. manager.onProgress({ loaded: loaded });
  8751. }
  8752. rangeReader.read().then(readChunk, reject);
  8753. return;
  8754. }
  8755. var chunkData = arraysToBytes(chunks);
  8756. chunks = null;
  8757. resolve(chunkData);
  8758. } catch (e) {
  8759. reject(e);
  8760. }
  8761. };
  8762. rangeReader.read().then(readChunk, reject);
  8763. });
  8764. promise.then(function (data) {
  8765. if (this.aborted) {
  8766. return;
  8767. }
  8768. // ignoring any data after abort
  8769. this.onReceiveData({
  8770. chunk: data,
  8771. begin: begin
  8772. });
  8773. }.bind(this));
  8774. },
  8775. // TODO check errors
  8776. // Get all the chunks that are not yet loaded and groups them into
  8777. // contiguous ranges to load in as few requests as possible
  8778. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  8779. var missingChunks = this.stream.getMissingChunks();
  8780. this._requestChunks(missingChunks);
  8781. return this._loadedStreamCapability.promise;
  8782. },
  8783. _requestChunks: function ChunkedStreamManager_requestChunks(chunks) {
  8784. var requestId = this.currRequestId++;
  8785. var i, ii;
  8786. var chunksNeeded = Object.create(null);
  8787. this.chunksNeededByRequest[requestId] = chunksNeeded;
  8788. for (i = 0, ii = chunks.length; i < ii; i++) {
  8789. if (!this.stream.hasChunk(chunks[i])) {
  8790. chunksNeeded[chunks[i]] = true;
  8791. }
  8792. }
  8793. if (isEmptyObj(chunksNeeded)) {
  8794. return Promise.resolve();
  8795. }
  8796. var capability = createPromiseCapability();
  8797. this.promisesByRequest[requestId] = capability;
  8798. var chunksToRequest = [];
  8799. for (var chunk in chunksNeeded) {
  8800. chunk = chunk | 0;
  8801. if (!(chunk in this.requestsByChunk)) {
  8802. this.requestsByChunk[chunk] = [];
  8803. chunksToRequest.push(chunk);
  8804. }
  8805. this.requestsByChunk[chunk].push(requestId);
  8806. }
  8807. if (!chunksToRequest.length) {
  8808. return capability.promise;
  8809. }
  8810. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  8811. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  8812. var groupedChunk = groupedChunksToRequest[i];
  8813. var begin = groupedChunk.beginChunk * this.chunkSize;
  8814. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  8815. this.sendRequest(begin, end);
  8816. }
  8817. return capability.promise;
  8818. },
  8819. getStream: function ChunkedStreamManager_getStream() {
  8820. return this.stream;
  8821. },
  8822. // Loads any chunks in the requested range that are not yet loaded
  8823. requestRange: function ChunkedStreamManager_requestRange(begin, end) {
  8824. end = Math.min(end, this.length);
  8825. var beginChunk = this.getBeginChunk(begin);
  8826. var endChunk = this.getEndChunk(end);
  8827. var chunks = [];
  8828. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  8829. chunks.push(chunk);
  8830. }
  8831. return this._requestChunks(chunks);
  8832. },
  8833. requestRanges: function ChunkedStreamManager_requestRanges(ranges) {
  8834. ranges = ranges || [];
  8835. var chunksToRequest = [];
  8836. for (var i = 0; i < ranges.length; i++) {
  8837. var beginChunk = this.getBeginChunk(ranges[i].begin);
  8838. var endChunk = this.getEndChunk(ranges[i].end);
  8839. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  8840. if (chunksToRequest.indexOf(chunk) < 0) {
  8841. chunksToRequest.push(chunk);
  8842. }
  8843. }
  8844. }
  8845. chunksToRequest.sort(function (a, b) {
  8846. return a - b;
  8847. });
  8848. return this._requestChunks(chunksToRequest);
  8849. },
  8850. // Groups a sorted array of chunks into as few contiguous larger
  8851. // chunks as possible
  8852. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  8853. var groupedChunks = [];
  8854. var beginChunk = -1;
  8855. var prevChunk = -1;
  8856. for (var i = 0; i < chunks.length; ++i) {
  8857. var chunk = chunks[i];
  8858. if (beginChunk < 0) {
  8859. beginChunk = chunk;
  8860. }
  8861. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  8862. groupedChunks.push({
  8863. beginChunk: beginChunk,
  8864. endChunk: prevChunk + 1
  8865. });
  8866. beginChunk = chunk;
  8867. }
  8868. if (i + 1 === chunks.length) {
  8869. groupedChunks.push({
  8870. beginChunk: beginChunk,
  8871. endChunk: chunk + 1
  8872. });
  8873. }
  8874. prevChunk = chunk;
  8875. }
  8876. return groupedChunks;
  8877. },
  8878. onProgress: function ChunkedStreamManager_onProgress(args) {
  8879. var bytesLoaded = this.stream.numChunksLoaded * this.chunkSize + args.loaded;
  8880. this.msgHandler.send('DocProgress', {
  8881. loaded: bytesLoaded,
  8882. total: this.length
  8883. });
  8884. },
  8885. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  8886. var chunk = args.chunk;
  8887. var isProgressive = args.begin === undefined;
  8888. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  8889. var end = begin + chunk.byteLength;
  8890. var beginChunk = Math.floor(begin / this.chunkSize);
  8891. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) : Math.ceil(end / this.chunkSize);
  8892. if (isProgressive) {
  8893. this.stream.onReceiveProgressiveData(chunk);
  8894. this.progressiveDataLength = end;
  8895. } else {
  8896. this.stream.onReceiveData(begin, chunk);
  8897. }
  8898. if (this.stream.allChunksLoaded()) {
  8899. this._loadedStreamCapability.resolve(this.stream);
  8900. }
  8901. var loadedRequests = [];
  8902. var i, requestId;
  8903. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  8904. // The server might return more chunks than requested
  8905. var requestIds = this.requestsByChunk[chunk] || [];
  8906. delete this.requestsByChunk[chunk];
  8907. for (i = 0; i < requestIds.length; ++i) {
  8908. requestId = requestIds[i];
  8909. var chunksNeeded = this.chunksNeededByRequest[requestId];
  8910. if (chunk in chunksNeeded) {
  8911. delete chunksNeeded[chunk];
  8912. }
  8913. if (!isEmptyObj(chunksNeeded)) {
  8914. continue;
  8915. }
  8916. loadedRequests.push(requestId);
  8917. }
  8918. }
  8919. // If there are no pending requests, automatically fetch the next
  8920. // unfetched chunk of the PDF
  8921. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  8922. var nextEmptyChunk;
  8923. if (this.stream.numChunksLoaded === 1) {
  8924. // This is a special optimization so that after fetching the first
  8925. // chunk, rather than fetching the second chunk, we fetch the last
  8926. // chunk.
  8927. var lastChunk = this.stream.numChunks - 1;
  8928. if (!this.stream.hasChunk(lastChunk)) {
  8929. nextEmptyChunk = lastChunk;
  8930. }
  8931. } else {
  8932. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  8933. }
  8934. if (isInt(nextEmptyChunk)) {
  8935. this._requestChunks([nextEmptyChunk]);
  8936. }
  8937. }
  8938. for (i = 0; i < loadedRequests.length; ++i) {
  8939. requestId = loadedRequests[i];
  8940. var capability = this.promisesByRequest[requestId];
  8941. delete this.promisesByRequest[requestId];
  8942. capability.resolve();
  8943. }
  8944. this.msgHandler.send('DocProgress', {
  8945. loaded: this.stream.numChunksLoaded * this.chunkSize,
  8946. total: this.length
  8947. });
  8948. },
  8949. onError: function ChunkedStreamManager_onError(err) {
  8950. this._loadedStreamCapability.reject(err);
  8951. },
  8952. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  8953. var chunk = Math.floor(begin / this.chunkSize);
  8954. return chunk;
  8955. },
  8956. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  8957. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  8958. return chunk;
  8959. },
  8960. abort: function ChunkedStreamManager_abort() {
  8961. this.aborted = true;
  8962. if (this.pdfNetworkStream) {
  8963. this.pdfNetworkStream.cancelAllRequests('abort');
  8964. }
  8965. for (var requestId in this.promisesByRequest) {
  8966. var capability = this.promisesByRequest[requestId];
  8967. capability.reject(new Error('Request was aborted'));
  8968. }
  8969. }
  8970. };
  8971. return ChunkedStreamManager;
  8972. }();
  8973. exports.ChunkedStream = ChunkedStream;
  8974. exports.ChunkedStreamManager = ChunkedStreamManager;
  8975. }));
  8976. (function (root, factory) {
  8977. factory(root.pdfjsCoreGlyphList = {}, root.pdfjsSharedUtil);
  8978. }(this, function (exports, sharedUtil) {
  8979. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  8980. var getGlyphsUnicode = getLookupTableFactory(function (t) {
  8981. t['A'] = 0x0041;
  8982. t['AE'] = 0x00C6;
  8983. t['AEacute'] = 0x01FC;
  8984. t['AEmacron'] = 0x01E2;
  8985. t['AEsmall'] = 0xF7E6;
  8986. t['Aacute'] = 0x00C1;
  8987. t['Aacutesmall'] = 0xF7E1;
  8988. t['Abreve'] = 0x0102;
  8989. t['Abreveacute'] = 0x1EAE;
  8990. t['Abrevecyrillic'] = 0x04D0;
  8991. t['Abrevedotbelow'] = 0x1EB6;
  8992. t['Abrevegrave'] = 0x1EB0;
  8993. t['Abrevehookabove'] = 0x1EB2;
  8994. t['Abrevetilde'] = 0x1EB4;
  8995. t['Acaron'] = 0x01CD;
  8996. t['Acircle'] = 0x24B6;
  8997. t['Acircumflex'] = 0x00C2;
  8998. t['Acircumflexacute'] = 0x1EA4;
  8999. t['Acircumflexdotbelow'] = 0x1EAC;
  9000. t['Acircumflexgrave'] = 0x1EA6;
  9001. t['Acircumflexhookabove'] = 0x1EA8;
  9002. t['Acircumflexsmall'] = 0xF7E2;
  9003. t['Acircumflextilde'] = 0x1EAA;
  9004. t['Acute'] = 0xF6C9;
  9005. t['Acutesmall'] = 0xF7B4;
  9006. t['Acyrillic'] = 0x0410;
  9007. t['Adblgrave'] = 0x0200;
  9008. t['Adieresis'] = 0x00C4;
  9009. t['Adieresiscyrillic'] = 0x04D2;
  9010. t['Adieresismacron'] = 0x01DE;
  9011. t['Adieresissmall'] = 0xF7E4;
  9012. t['Adotbelow'] = 0x1EA0;
  9013. t['Adotmacron'] = 0x01E0;
  9014. t['Agrave'] = 0x00C0;
  9015. t['Agravesmall'] = 0xF7E0;
  9016. t['Ahookabove'] = 0x1EA2;
  9017. t['Aiecyrillic'] = 0x04D4;
  9018. t['Ainvertedbreve'] = 0x0202;
  9019. t['Alpha'] = 0x0391;
  9020. t['Alphatonos'] = 0x0386;
  9021. t['Amacron'] = 0x0100;
  9022. t['Amonospace'] = 0xFF21;
  9023. t['Aogonek'] = 0x0104;
  9024. t['Aring'] = 0x00C5;
  9025. t['Aringacute'] = 0x01FA;
  9026. t['Aringbelow'] = 0x1E00;
  9027. t['Aringsmall'] = 0xF7E5;
  9028. t['Asmall'] = 0xF761;
  9029. t['Atilde'] = 0x00C3;
  9030. t['Atildesmall'] = 0xF7E3;
  9031. t['Aybarmenian'] = 0x0531;
  9032. t['B'] = 0x0042;
  9033. t['Bcircle'] = 0x24B7;
  9034. t['Bdotaccent'] = 0x1E02;
  9035. t['Bdotbelow'] = 0x1E04;
  9036. t['Becyrillic'] = 0x0411;
  9037. t['Benarmenian'] = 0x0532;
  9038. t['Beta'] = 0x0392;
  9039. t['Bhook'] = 0x0181;
  9040. t['Blinebelow'] = 0x1E06;
  9041. t['Bmonospace'] = 0xFF22;
  9042. t['Brevesmall'] = 0xF6F4;
  9043. t['Bsmall'] = 0xF762;
  9044. t['Btopbar'] = 0x0182;
  9045. t['C'] = 0x0043;
  9046. t['Caarmenian'] = 0x053E;
  9047. t['Cacute'] = 0x0106;
  9048. t['Caron'] = 0xF6CA;
  9049. t['Caronsmall'] = 0xF6F5;
  9050. t['Ccaron'] = 0x010C;
  9051. t['Ccedilla'] = 0x00C7;
  9052. t['Ccedillaacute'] = 0x1E08;
  9053. t['Ccedillasmall'] = 0xF7E7;
  9054. t['Ccircle'] = 0x24B8;
  9055. t['Ccircumflex'] = 0x0108;
  9056. t['Cdot'] = 0x010A;
  9057. t['Cdotaccent'] = 0x010A;
  9058. t['Cedillasmall'] = 0xF7B8;
  9059. t['Chaarmenian'] = 0x0549;
  9060. t['Cheabkhasiancyrillic'] = 0x04BC;
  9061. t['Checyrillic'] = 0x0427;
  9062. t['Chedescenderabkhasiancyrillic'] = 0x04BE;
  9063. t['Chedescendercyrillic'] = 0x04B6;
  9064. t['Chedieresiscyrillic'] = 0x04F4;
  9065. t['Cheharmenian'] = 0x0543;
  9066. t['Chekhakassiancyrillic'] = 0x04CB;
  9067. t['Cheverticalstrokecyrillic'] = 0x04B8;
  9068. t['Chi'] = 0x03A7;
  9069. t['Chook'] = 0x0187;
  9070. t['Circumflexsmall'] = 0xF6F6;
  9071. t['Cmonospace'] = 0xFF23;
  9072. t['Coarmenian'] = 0x0551;
  9073. t['Csmall'] = 0xF763;
  9074. t['D'] = 0x0044;
  9075. t['DZ'] = 0x01F1;
  9076. t['DZcaron'] = 0x01C4;
  9077. t['Daarmenian'] = 0x0534;
  9078. t['Dafrican'] = 0x0189;
  9079. t['Dcaron'] = 0x010E;
  9080. t['Dcedilla'] = 0x1E10;
  9081. t['Dcircle'] = 0x24B9;
  9082. t['Dcircumflexbelow'] = 0x1E12;
  9083. t['Dcroat'] = 0x0110;
  9084. t['Ddotaccent'] = 0x1E0A;
  9085. t['Ddotbelow'] = 0x1E0C;
  9086. t['Decyrillic'] = 0x0414;
  9087. t['Deicoptic'] = 0x03EE;
  9088. t['Delta'] = 0x2206;
  9089. t['Deltagreek'] = 0x0394;
  9090. t['Dhook'] = 0x018A;
  9091. t['Dieresis'] = 0xF6CB;
  9092. t['DieresisAcute'] = 0xF6CC;
  9093. t['DieresisGrave'] = 0xF6CD;
  9094. t['Dieresissmall'] = 0xF7A8;
  9095. t['Digammagreek'] = 0x03DC;
  9096. t['Djecyrillic'] = 0x0402;
  9097. t['Dlinebelow'] = 0x1E0E;
  9098. t['Dmonospace'] = 0xFF24;
  9099. t['Dotaccentsmall'] = 0xF6F7;
  9100. t['Dslash'] = 0x0110;
  9101. t['Dsmall'] = 0xF764;
  9102. t['Dtopbar'] = 0x018B;
  9103. t['Dz'] = 0x01F2;
  9104. t['Dzcaron'] = 0x01C5;
  9105. t['Dzeabkhasiancyrillic'] = 0x04E0;
  9106. t['Dzecyrillic'] = 0x0405;
  9107. t['Dzhecyrillic'] = 0x040F;
  9108. t['E'] = 0x0045;
  9109. t['Eacute'] = 0x00C9;
  9110. t['Eacutesmall'] = 0xF7E9;
  9111. t['Ebreve'] = 0x0114;
  9112. t['Ecaron'] = 0x011A;
  9113. t['Ecedillabreve'] = 0x1E1C;
  9114. t['Echarmenian'] = 0x0535;
  9115. t['Ecircle'] = 0x24BA;
  9116. t['Ecircumflex'] = 0x00CA;
  9117. t['Ecircumflexacute'] = 0x1EBE;
  9118. t['Ecircumflexbelow'] = 0x1E18;
  9119. t['Ecircumflexdotbelow'] = 0x1EC6;
  9120. t['Ecircumflexgrave'] = 0x1EC0;
  9121. t['Ecircumflexhookabove'] = 0x1EC2;
  9122. t['Ecircumflexsmall'] = 0xF7EA;
  9123. t['Ecircumflextilde'] = 0x1EC4;
  9124. t['Ecyrillic'] = 0x0404;
  9125. t['Edblgrave'] = 0x0204;
  9126. t['Edieresis'] = 0x00CB;
  9127. t['Edieresissmall'] = 0xF7EB;
  9128. t['Edot'] = 0x0116;
  9129. t['Edotaccent'] = 0x0116;
  9130. t['Edotbelow'] = 0x1EB8;
  9131. t['Efcyrillic'] = 0x0424;
  9132. t['Egrave'] = 0x00C8;
  9133. t['Egravesmall'] = 0xF7E8;
  9134. t['Eharmenian'] = 0x0537;
  9135. t['Ehookabove'] = 0x1EBA;
  9136. t['Eightroman'] = 0x2167;
  9137. t['Einvertedbreve'] = 0x0206;
  9138. t['Eiotifiedcyrillic'] = 0x0464;
  9139. t['Elcyrillic'] = 0x041B;
  9140. t['Elevenroman'] = 0x216A;
  9141. t['Emacron'] = 0x0112;
  9142. t['Emacronacute'] = 0x1E16;
  9143. t['Emacrongrave'] = 0x1E14;
  9144. t['Emcyrillic'] = 0x041C;
  9145. t['Emonospace'] = 0xFF25;
  9146. t['Encyrillic'] = 0x041D;
  9147. t['Endescendercyrillic'] = 0x04A2;
  9148. t['Eng'] = 0x014A;
  9149. t['Enghecyrillic'] = 0x04A4;
  9150. t['Enhookcyrillic'] = 0x04C7;
  9151. t['Eogonek'] = 0x0118;
  9152. t['Eopen'] = 0x0190;
  9153. t['Epsilon'] = 0x0395;
  9154. t['Epsilontonos'] = 0x0388;
  9155. t['Ercyrillic'] = 0x0420;
  9156. t['Ereversed'] = 0x018E;
  9157. t['Ereversedcyrillic'] = 0x042D;
  9158. t['Escyrillic'] = 0x0421;
  9159. t['Esdescendercyrillic'] = 0x04AA;
  9160. t['Esh'] = 0x01A9;
  9161. t['Esmall'] = 0xF765;
  9162. t['Eta'] = 0x0397;
  9163. t['Etarmenian'] = 0x0538;
  9164. t['Etatonos'] = 0x0389;
  9165. t['Eth'] = 0x00D0;
  9166. t['Ethsmall'] = 0xF7F0;
  9167. t['Etilde'] = 0x1EBC;
  9168. t['Etildebelow'] = 0x1E1A;
  9169. t['Euro'] = 0x20AC;
  9170. t['Ezh'] = 0x01B7;
  9171. t['Ezhcaron'] = 0x01EE;
  9172. t['Ezhreversed'] = 0x01B8;
  9173. t['F'] = 0x0046;
  9174. t['Fcircle'] = 0x24BB;
  9175. t['Fdotaccent'] = 0x1E1E;
  9176. t['Feharmenian'] = 0x0556;
  9177. t['Feicoptic'] = 0x03E4;
  9178. t['Fhook'] = 0x0191;
  9179. t['Fitacyrillic'] = 0x0472;
  9180. t['Fiveroman'] = 0x2164;
  9181. t['Fmonospace'] = 0xFF26;
  9182. t['Fourroman'] = 0x2163;
  9183. t['Fsmall'] = 0xF766;
  9184. t['G'] = 0x0047;
  9185. t['GBsquare'] = 0x3387;
  9186. t['Gacute'] = 0x01F4;
  9187. t['Gamma'] = 0x0393;
  9188. t['Gammaafrican'] = 0x0194;
  9189. t['Gangiacoptic'] = 0x03EA;
  9190. t['Gbreve'] = 0x011E;
  9191. t['Gcaron'] = 0x01E6;
  9192. t['Gcedilla'] = 0x0122;
  9193. t['Gcircle'] = 0x24BC;
  9194. t['Gcircumflex'] = 0x011C;
  9195. t['Gcommaaccent'] = 0x0122;
  9196. t['Gdot'] = 0x0120;
  9197. t['Gdotaccent'] = 0x0120;
  9198. t['Gecyrillic'] = 0x0413;
  9199. t['Ghadarmenian'] = 0x0542;
  9200. t['Ghemiddlehookcyrillic'] = 0x0494;
  9201. t['Ghestrokecyrillic'] = 0x0492;
  9202. t['Gheupturncyrillic'] = 0x0490;
  9203. t['Ghook'] = 0x0193;
  9204. t['Gimarmenian'] = 0x0533;
  9205. t['Gjecyrillic'] = 0x0403;
  9206. t['Gmacron'] = 0x1E20;
  9207. t['Gmonospace'] = 0xFF27;
  9208. t['Grave'] = 0xF6CE;
  9209. t['Gravesmall'] = 0xF760;
  9210. t['Gsmall'] = 0xF767;
  9211. t['Gsmallhook'] = 0x029B;
  9212. t['Gstroke'] = 0x01E4;
  9213. t['H'] = 0x0048;
  9214. t['H18533'] = 0x25CF;
  9215. t['H18543'] = 0x25AA;
  9216. t['H18551'] = 0x25AB;
  9217. t['H22073'] = 0x25A1;
  9218. t['HPsquare'] = 0x33CB;
  9219. t['Haabkhasiancyrillic'] = 0x04A8;
  9220. t['Hadescendercyrillic'] = 0x04B2;
  9221. t['Hardsigncyrillic'] = 0x042A;
  9222. t['Hbar'] = 0x0126;
  9223. t['Hbrevebelow'] = 0x1E2A;
  9224. t['Hcedilla'] = 0x1E28;
  9225. t['Hcircle'] = 0x24BD;
  9226. t['Hcircumflex'] = 0x0124;
  9227. t['Hdieresis'] = 0x1E26;
  9228. t['Hdotaccent'] = 0x1E22;
  9229. t['Hdotbelow'] = 0x1E24;
  9230. t['Hmonospace'] = 0xFF28;
  9231. t['Hoarmenian'] = 0x0540;
  9232. t['Horicoptic'] = 0x03E8;
  9233. t['Hsmall'] = 0xF768;
  9234. t['Hungarumlaut'] = 0xF6CF;
  9235. t['Hungarumlautsmall'] = 0xF6F8;
  9236. t['Hzsquare'] = 0x3390;
  9237. t['I'] = 0x0049;
  9238. t['IAcyrillic'] = 0x042F;
  9239. t['IJ'] = 0x0132;
  9240. t['IUcyrillic'] = 0x042E;
  9241. t['Iacute'] = 0x00CD;
  9242. t['Iacutesmall'] = 0xF7ED;
  9243. t['Ibreve'] = 0x012C;
  9244. t['Icaron'] = 0x01CF;
  9245. t['Icircle'] = 0x24BE;
  9246. t['Icircumflex'] = 0x00CE;
  9247. t['Icircumflexsmall'] = 0xF7EE;
  9248. t['Icyrillic'] = 0x0406;
  9249. t['Idblgrave'] = 0x0208;
  9250. t['Idieresis'] = 0x00CF;
  9251. t['Idieresisacute'] = 0x1E2E;
  9252. t['Idieresiscyrillic'] = 0x04E4;
  9253. t['Idieresissmall'] = 0xF7EF;
  9254. t['Idot'] = 0x0130;
  9255. t['Idotaccent'] = 0x0130;
  9256. t['Idotbelow'] = 0x1ECA;
  9257. t['Iebrevecyrillic'] = 0x04D6;
  9258. t['Iecyrillic'] = 0x0415;
  9259. t['Ifraktur'] = 0x2111;
  9260. t['Igrave'] = 0x00CC;
  9261. t['Igravesmall'] = 0xF7EC;
  9262. t['Ihookabove'] = 0x1EC8;
  9263. t['Iicyrillic'] = 0x0418;
  9264. t['Iinvertedbreve'] = 0x020A;
  9265. t['Iishortcyrillic'] = 0x0419;
  9266. t['Imacron'] = 0x012A;
  9267. t['Imacroncyrillic'] = 0x04E2;
  9268. t['Imonospace'] = 0xFF29;
  9269. t['Iniarmenian'] = 0x053B;
  9270. t['Iocyrillic'] = 0x0401;
  9271. t['Iogonek'] = 0x012E;
  9272. t['Iota'] = 0x0399;
  9273. t['Iotaafrican'] = 0x0196;
  9274. t['Iotadieresis'] = 0x03AA;
  9275. t['Iotatonos'] = 0x038A;
  9276. t['Ismall'] = 0xF769;
  9277. t['Istroke'] = 0x0197;
  9278. t['Itilde'] = 0x0128;
  9279. t['Itildebelow'] = 0x1E2C;
  9280. t['Izhitsacyrillic'] = 0x0474;
  9281. t['Izhitsadblgravecyrillic'] = 0x0476;
  9282. t['J'] = 0x004A;
  9283. t['Jaarmenian'] = 0x0541;
  9284. t['Jcircle'] = 0x24BF;
  9285. t['Jcircumflex'] = 0x0134;
  9286. t['Jecyrillic'] = 0x0408;
  9287. t['Jheharmenian'] = 0x054B;
  9288. t['Jmonospace'] = 0xFF2A;
  9289. t['Jsmall'] = 0xF76A;
  9290. t['K'] = 0x004B;
  9291. t['KBsquare'] = 0x3385;
  9292. t['KKsquare'] = 0x33CD;
  9293. t['Kabashkircyrillic'] = 0x04A0;
  9294. t['Kacute'] = 0x1E30;
  9295. t['Kacyrillic'] = 0x041A;
  9296. t['Kadescendercyrillic'] = 0x049A;
  9297. t['Kahookcyrillic'] = 0x04C3;
  9298. t['Kappa'] = 0x039A;
  9299. t['Kastrokecyrillic'] = 0x049E;
  9300. t['Kaverticalstrokecyrillic'] = 0x049C;
  9301. t['Kcaron'] = 0x01E8;
  9302. t['Kcedilla'] = 0x0136;
  9303. t['Kcircle'] = 0x24C0;
  9304. t['Kcommaaccent'] = 0x0136;
  9305. t['Kdotbelow'] = 0x1E32;
  9306. t['Keharmenian'] = 0x0554;
  9307. t['Kenarmenian'] = 0x053F;
  9308. t['Khacyrillic'] = 0x0425;
  9309. t['Kheicoptic'] = 0x03E6;
  9310. t['Khook'] = 0x0198;
  9311. t['Kjecyrillic'] = 0x040C;
  9312. t['Klinebelow'] = 0x1E34;
  9313. t['Kmonospace'] = 0xFF2B;
  9314. t['Koppacyrillic'] = 0x0480;
  9315. t['Koppagreek'] = 0x03DE;
  9316. t['Ksicyrillic'] = 0x046E;
  9317. t['Ksmall'] = 0xF76B;
  9318. t['L'] = 0x004C;
  9319. t['LJ'] = 0x01C7;
  9320. t['LL'] = 0xF6BF;
  9321. t['Lacute'] = 0x0139;
  9322. t['Lambda'] = 0x039B;
  9323. t['Lcaron'] = 0x013D;
  9324. t['Lcedilla'] = 0x013B;
  9325. t['Lcircle'] = 0x24C1;
  9326. t['Lcircumflexbelow'] = 0x1E3C;
  9327. t['Lcommaaccent'] = 0x013B;
  9328. t['Ldot'] = 0x013F;
  9329. t['Ldotaccent'] = 0x013F;
  9330. t['Ldotbelow'] = 0x1E36;
  9331. t['Ldotbelowmacron'] = 0x1E38;
  9332. t['Liwnarmenian'] = 0x053C;
  9333. t['Lj'] = 0x01C8;
  9334. t['Ljecyrillic'] = 0x0409;
  9335. t['Llinebelow'] = 0x1E3A;
  9336. t['Lmonospace'] = 0xFF2C;
  9337. t['Lslash'] = 0x0141;
  9338. t['Lslashsmall'] = 0xF6F9;
  9339. t['Lsmall'] = 0xF76C;
  9340. t['M'] = 0x004D;
  9341. t['MBsquare'] = 0x3386;
  9342. t['Macron'] = 0xF6D0;
  9343. t['Macronsmall'] = 0xF7AF;
  9344. t['Macute'] = 0x1E3E;
  9345. t['Mcircle'] = 0x24C2;
  9346. t['Mdotaccent'] = 0x1E40;
  9347. t['Mdotbelow'] = 0x1E42;
  9348. t['Menarmenian'] = 0x0544;
  9349. t['Mmonospace'] = 0xFF2D;
  9350. t['Msmall'] = 0xF76D;
  9351. t['Mturned'] = 0x019C;
  9352. t['Mu'] = 0x039C;
  9353. t['N'] = 0x004E;
  9354. t['NJ'] = 0x01CA;
  9355. t['Nacute'] = 0x0143;
  9356. t['Ncaron'] = 0x0147;
  9357. t['Ncedilla'] = 0x0145;
  9358. t['Ncircle'] = 0x24C3;
  9359. t['Ncircumflexbelow'] = 0x1E4A;
  9360. t['Ncommaaccent'] = 0x0145;
  9361. t['Ndotaccent'] = 0x1E44;
  9362. t['Ndotbelow'] = 0x1E46;
  9363. t['Nhookleft'] = 0x019D;
  9364. t['Nineroman'] = 0x2168;
  9365. t['Nj'] = 0x01CB;
  9366. t['Njecyrillic'] = 0x040A;
  9367. t['Nlinebelow'] = 0x1E48;
  9368. t['Nmonospace'] = 0xFF2E;
  9369. t['Nowarmenian'] = 0x0546;
  9370. t['Nsmall'] = 0xF76E;
  9371. t['Ntilde'] = 0x00D1;
  9372. t['Ntildesmall'] = 0xF7F1;
  9373. t['Nu'] = 0x039D;
  9374. t['O'] = 0x004F;
  9375. t['OE'] = 0x0152;
  9376. t['OEsmall'] = 0xF6FA;
  9377. t['Oacute'] = 0x00D3;
  9378. t['Oacutesmall'] = 0xF7F3;
  9379. t['Obarredcyrillic'] = 0x04E8;
  9380. t['Obarreddieresiscyrillic'] = 0x04EA;
  9381. t['Obreve'] = 0x014E;
  9382. t['Ocaron'] = 0x01D1;
  9383. t['Ocenteredtilde'] = 0x019F;
  9384. t['Ocircle'] = 0x24C4;
  9385. t['Ocircumflex'] = 0x00D4;
  9386. t['Ocircumflexacute'] = 0x1ED0;
  9387. t['Ocircumflexdotbelow'] = 0x1ED8;
  9388. t['Ocircumflexgrave'] = 0x1ED2;
  9389. t['Ocircumflexhookabove'] = 0x1ED4;
  9390. t['Ocircumflexsmall'] = 0xF7F4;
  9391. t['Ocircumflextilde'] = 0x1ED6;
  9392. t['Ocyrillic'] = 0x041E;
  9393. t['Odblacute'] = 0x0150;
  9394. t['Odblgrave'] = 0x020C;
  9395. t['Odieresis'] = 0x00D6;
  9396. t['Odieresiscyrillic'] = 0x04E6;
  9397. t['Odieresissmall'] = 0xF7F6;
  9398. t['Odotbelow'] = 0x1ECC;
  9399. t['Ogoneksmall'] = 0xF6FB;
  9400. t['Ograve'] = 0x00D2;
  9401. t['Ogravesmall'] = 0xF7F2;
  9402. t['Oharmenian'] = 0x0555;
  9403. t['Ohm'] = 0x2126;
  9404. t['Ohookabove'] = 0x1ECE;
  9405. t['Ohorn'] = 0x01A0;
  9406. t['Ohornacute'] = 0x1EDA;
  9407. t['Ohorndotbelow'] = 0x1EE2;
  9408. t['Ohorngrave'] = 0x1EDC;
  9409. t['Ohornhookabove'] = 0x1EDE;
  9410. t['Ohorntilde'] = 0x1EE0;
  9411. t['Ohungarumlaut'] = 0x0150;
  9412. t['Oi'] = 0x01A2;
  9413. t['Oinvertedbreve'] = 0x020E;
  9414. t['Omacron'] = 0x014C;
  9415. t['Omacronacute'] = 0x1E52;
  9416. t['Omacrongrave'] = 0x1E50;
  9417. t['Omega'] = 0x2126;
  9418. t['Omegacyrillic'] = 0x0460;
  9419. t['Omegagreek'] = 0x03A9;
  9420. t['Omegaroundcyrillic'] = 0x047A;
  9421. t['Omegatitlocyrillic'] = 0x047C;
  9422. t['Omegatonos'] = 0x038F;
  9423. t['Omicron'] = 0x039F;
  9424. t['Omicrontonos'] = 0x038C;
  9425. t['Omonospace'] = 0xFF2F;
  9426. t['Oneroman'] = 0x2160;
  9427. t['Oogonek'] = 0x01EA;
  9428. t['Oogonekmacron'] = 0x01EC;
  9429. t['Oopen'] = 0x0186;
  9430. t['Oslash'] = 0x00D8;
  9431. t['Oslashacute'] = 0x01FE;
  9432. t['Oslashsmall'] = 0xF7F8;
  9433. t['Osmall'] = 0xF76F;
  9434. t['Ostrokeacute'] = 0x01FE;
  9435. t['Otcyrillic'] = 0x047E;
  9436. t['Otilde'] = 0x00D5;
  9437. t['Otildeacute'] = 0x1E4C;
  9438. t['Otildedieresis'] = 0x1E4E;
  9439. t['Otildesmall'] = 0xF7F5;
  9440. t['P'] = 0x0050;
  9441. t['Pacute'] = 0x1E54;
  9442. t['Pcircle'] = 0x24C5;
  9443. t['Pdotaccent'] = 0x1E56;
  9444. t['Pecyrillic'] = 0x041F;
  9445. t['Peharmenian'] = 0x054A;
  9446. t['Pemiddlehookcyrillic'] = 0x04A6;
  9447. t['Phi'] = 0x03A6;
  9448. t['Phook'] = 0x01A4;
  9449. t['Pi'] = 0x03A0;
  9450. t['Piwrarmenian'] = 0x0553;
  9451. t['Pmonospace'] = 0xFF30;
  9452. t['Psi'] = 0x03A8;
  9453. t['Psicyrillic'] = 0x0470;
  9454. t['Psmall'] = 0xF770;
  9455. t['Q'] = 0x0051;
  9456. t['Qcircle'] = 0x24C6;
  9457. t['Qmonospace'] = 0xFF31;
  9458. t['Qsmall'] = 0xF771;
  9459. t['R'] = 0x0052;
  9460. t['Raarmenian'] = 0x054C;
  9461. t['Racute'] = 0x0154;
  9462. t['Rcaron'] = 0x0158;
  9463. t['Rcedilla'] = 0x0156;
  9464. t['Rcircle'] = 0x24C7;
  9465. t['Rcommaaccent'] = 0x0156;
  9466. t['Rdblgrave'] = 0x0210;
  9467. t['Rdotaccent'] = 0x1E58;
  9468. t['Rdotbelow'] = 0x1E5A;
  9469. t['Rdotbelowmacron'] = 0x1E5C;
  9470. t['Reharmenian'] = 0x0550;
  9471. t['Rfraktur'] = 0x211C;
  9472. t['Rho'] = 0x03A1;
  9473. t['Ringsmall'] = 0xF6FC;
  9474. t['Rinvertedbreve'] = 0x0212;
  9475. t['Rlinebelow'] = 0x1E5E;
  9476. t['Rmonospace'] = 0xFF32;
  9477. t['Rsmall'] = 0xF772;
  9478. t['Rsmallinverted'] = 0x0281;
  9479. t['Rsmallinvertedsuperior'] = 0x02B6;
  9480. t['S'] = 0x0053;
  9481. t['SF010000'] = 0x250C;
  9482. t['SF020000'] = 0x2514;
  9483. t['SF030000'] = 0x2510;
  9484. t['SF040000'] = 0x2518;
  9485. t['SF050000'] = 0x253C;
  9486. t['SF060000'] = 0x252C;
  9487. t['SF070000'] = 0x2534;
  9488. t['SF080000'] = 0x251C;
  9489. t['SF090000'] = 0x2524;
  9490. t['SF100000'] = 0x2500;
  9491. t['SF110000'] = 0x2502;
  9492. t['SF190000'] = 0x2561;
  9493. t['SF200000'] = 0x2562;
  9494. t['SF210000'] = 0x2556;
  9495. t['SF220000'] = 0x2555;
  9496. t['SF230000'] = 0x2563;
  9497. t['SF240000'] = 0x2551;
  9498. t['SF250000'] = 0x2557;
  9499. t['SF260000'] = 0x255D;
  9500. t['SF270000'] = 0x255C;
  9501. t['SF280000'] = 0x255B;
  9502. t['SF360000'] = 0x255E;
  9503. t['SF370000'] = 0x255F;
  9504. t['SF380000'] = 0x255A;
  9505. t['SF390000'] = 0x2554;
  9506. t['SF400000'] = 0x2569;
  9507. t['SF410000'] = 0x2566;
  9508. t['SF420000'] = 0x2560;
  9509. t['SF430000'] = 0x2550;
  9510. t['SF440000'] = 0x256C;
  9511. t['SF450000'] = 0x2567;
  9512. t['SF460000'] = 0x2568;
  9513. t['SF470000'] = 0x2564;
  9514. t['SF480000'] = 0x2565;
  9515. t['SF490000'] = 0x2559;
  9516. t['SF500000'] = 0x2558;
  9517. t['SF510000'] = 0x2552;
  9518. t['SF520000'] = 0x2553;
  9519. t['SF530000'] = 0x256B;
  9520. t['SF540000'] = 0x256A;
  9521. t['Sacute'] = 0x015A;
  9522. t['Sacutedotaccent'] = 0x1E64;
  9523. t['Sampigreek'] = 0x03E0;
  9524. t['Scaron'] = 0x0160;
  9525. t['Scarondotaccent'] = 0x1E66;
  9526. t['Scaronsmall'] = 0xF6FD;
  9527. t['Scedilla'] = 0x015E;
  9528. t['Schwa'] = 0x018F;
  9529. t['Schwacyrillic'] = 0x04D8;
  9530. t['Schwadieresiscyrillic'] = 0x04DA;
  9531. t['Scircle'] = 0x24C8;
  9532. t['Scircumflex'] = 0x015C;
  9533. t['Scommaaccent'] = 0x0218;
  9534. t['Sdotaccent'] = 0x1E60;
  9535. t['Sdotbelow'] = 0x1E62;
  9536. t['Sdotbelowdotaccent'] = 0x1E68;
  9537. t['Seharmenian'] = 0x054D;
  9538. t['Sevenroman'] = 0x2166;
  9539. t['Shaarmenian'] = 0x0547;
  9540. t['Shacyrillic'] = 0x0428;
  9541. t['Shchacyrillic'] = 0x0429;
  9542. t['Sheicoptic'] = 0x03E2;
  9543. t['Shhacyrillic'] = 0x04BA;
  9544. t['Shimacoptic'] = 0x03EC;
  9545. t['Sigma'] = 0x03A3;
  9546. t['Sixroman'] = 0x2165;
  9547. t['Smonospace'] = 0xFF33;
  9548. t['Softsigncyrillic'] = 0x042C;
  9549. t['Ssmall'] = 0xF773;
  9550. t['Stigmagreek'] = 0x03DA;
  9551. t['T'] = 0x0054;
  9552. t['Tau'] = 0x03A4;
  9553. t['Tbar'] = 0x0166;
  9554. t['Tcaron'] = 0x0164;
  9555. t['Tcedilla'] = 0x0162;
  9556. t['Tcircle'] = 0x24C9;
  9557. t['Tcircumflexbelow'] = 0x1E70;
  9558. t['Tcommaaccent'] = 0x0162;
  9559. t['Tdotaccent'] = 0x1E6A;
  9560. t['Tdotbelow'] = 0x1E6C;
  9561. t['Tecyrillic'] = 0x0422;
  9562. t['Tedescendercyrillic'] = 0x04AC;
  9563. t['Tenroman'] = 0x2169;
  9564. t['Tetsecyrillic'] = 0x04B4;
  9565. t['Theta'] = 0x0398;
  9566. t['Thook'] = 0x01AC;
  9567. t['Thorn'] = 0x00DE;
  9568. t['Thornsmall'] = 0xF7FE;
  9569. t['Threeroman'] = 0x2162;
  9570. t['Tildesmall'] = 0xF6FE;
  9571. t['Tiwnarmenian'] = 0x054F;
  9572. t['Tlinebelow'] = 0x1E6E;
  9573. t['Tmonospace'] = 0xFF34;
  9574. t['Toarmenian'] = 0x0539;
  9575. t['Tonefive'] = 0x01BC;
  9576. t['Tonesix'] = 0x0184;
  9577. t['Tonetwo'] = 0x01A7;
  9578. t['Tretroflexhook'] = 0x01AE;
  9579. t['Tsecyrillic'] = 0x0426;
  9580. t['Tshecyrillic'] = 0x040B;
  9581. t['Tsmall'] = 0xF774;
  9582. t['Twelveroman'] = 0x216B;
  9583. t['Tworoman'] = 0x2161;
  9584. t['U'] = 0x0055;
  9585. t['Uacute'] = 0x00DA;
  9586. t['Uacutesmall'] = 0xF7FA;
  9587. t['Ubreve'] = 0x016C;
  9588. t['Ucaron'] = 0x01D3;
  9589. t['Ucircle'] = 0x24CA;
  9590. t['Ucircumflex'] = 0x00DB;
  9591. t['Ucircumflexbelow'] = 0x1E76;
  9592. t['Ucircumflexsmall'] = 0xF7FB;
  9593. t['Ucyrillic'] = 0x0423;
  9594. t['Udblacute'] = 0x0170;
  9595. t['Udblgrave'] = 0x0214;
  9596. t['Udieresis'] = 0x00DC;
  9597. t['Udieresisacute'] = 0x01D7;
  9598. t['Udieresisbelow'] = 0x1E72;
  9599. t['Udieresiscaron'] = 0x01D9;
  9600. t['Udieresiscyrillic'] = 0x04F0;
  9601. t['Udieresisgrave'] = 0x01DB;
  9602. t['Udieresismacron'] = 0x01D5;
  9603. t['Udieresissmall'] = 0xF7FC;
  9604. t['Udotbelow'] = 0x1EE4;
  9605. t['Ugrave'] = 0x00D9;
  9606. t['Ugravesmall'] = 0xF7F9;
  9607. t['Uhookabove'] = 0x1EE6;
  9608. t['Uhorn'] = 0x01AF;
  9609. t['Uhornacute'] = 0x1EE8;
  9610. t['Uhorndotbelow'] = 0x1EF0;
  9611. t['Uhorngrave'] = 0x1EEA;
  9612. t['Uhornhookabove'] = 0x1EEC;
  9613. t['Uhorntilde'] = 0x1EEE;
  9614. t['Uhungarumlaut'] = 0x0170;
  9615. t['Uhungarumlautcyrillic'] = 0x04F2;
  9616. t['Uinvertedbreve'] = 0x0216;
  9617. t['Ukcyrillic'] = 0x0478;
  9618. t['Umacron'] = 0x016A;
  9619. t['Umacroncyrillic'] = 0x04EE;
  9620. t['Umacrondieresis'] = 0x1E7A;
  9621. t['Umonospace'] = 0xFF35;
  9622. t['Uogonek'] = 0x0172;
  9623. t['Upsilon'] = 0x03A5;
  9624. t['Upsilon1'] = 0x03D2;
  9625. t['Upsilonacutehooksymbolgreek'] = 0x03D3;
  9626. t['Upsilonafrican'] = 0x01B1;
  9627. t['Upsilondieresis'] = 0x03AB;
  9628. t['Upsilondieresishooksymbolgreek'] = 0x03D4;
  9629. t['Upsilonhooksymbol'] = 0x03D2;
  9630. t['Upsilontonos'] = 0x038E;
  9631. t['Uring'] = 0x016E;
  9632. t['Ushortcyrillic'] = 0x040E;
  9633. t['Usmall'] = 0xF775;
  9634. t['Ustraightcyrillic'] = 0x04AE;
  9635. t['Ustraightstrokecyrillic'] = 0x04B0;
  9636. t['Utilde'] = 0x0168;
  9637. t['Utildeacute'] = 0x1E78;
  9638. t['Utildebelow'] = 0x1E74;
  9639. t['V'] = 0x0056;
  9640. t['Vcircle'] = 0x24CB;
  9641. t['Vdotbelow'] = 0x1E7E;
  9642. t['Vecyrillic'] = 0x0412;
  9643. t['Vewarmenian'] = 0x054E;
  9644. t['Vhook'] = 0x01B2;
  9645. t['Vmonospace'] = 0xFF36;
  9646. t['Voarmenian'] = 0x0548;
  9647. t['Vsmall'] = 0xF776;
  9648. t['Vtilde'] = 0x1E7C;
  9649. t['W'] = 0x0057;
  9650. t['Wacute'] = 0x1E82;
  9651. t['Wcircle'] = 0x24CC;
  9652. t['Wcircumflex'] = 0x0174;
  9653. t['Wdieresis'] = 0x1E84;
  9654. t['Wdotaccent'] = 0x1E86;
  9655. t['Wdotbelow'] = 0x1E88;
  9656. t['Wgrave'] = 0x1E80;
  9657. t['Wmonospace'] = 0xFF37;
  9658. t['Wsmall'] = 0xF777;
  9659. t['X'] = 0x0058;
  9660. t['Xcircle'] = 0x24CD;
  9661. t['Xdieresis'] = 0x1E8C;
  9662. t['Xdotaccent'] = 0x1E8A;
  9663. t['Xeharmenian'] = 0x053D;
  9664. t['Xi'] = 0x039E;
  9665. t['Xmonospace'] = 0xFF38;
  9666. t['Xsmall'] = 0xF778;
  9667. t['Y'] = 0x0059;
  9668. t['Yacute'] = 0x00DD;
  9669. t['Yacutesmall'] = 0xF7FD;
  9670. t['Yatcyrillic'] = 0x0462;
  9671. t['Ycircle'] = 0x24CE;
  9672. t['Ycircumflex'] = 0x0176;
  9673. t['Ydieresis'] = 0x0178;
  9674. t['Ydieresissmall'] = 0xF7FF;
  9675. t['Ydotaccent'] = 0x1E8E;
  9676. t['Ydotbelow'] = 0x1EF4;
  9677. t['Yericyrillic'] = 0x042B;
  9678. t['Yerudieresiscyrillic'] = 0x04F8;
  9679. t['Ygrave'] = 0x1EF2;
  9680. t['Yhook'] = 0x01B3;
  9681. t['Yhookabove'] = 0x1EF6;
  9682. t['Yiarmenian'] = 0x0545;
  9683. t['Yicyrillic'] = 0x0407;
  9684. t['Yiwnarmenian'] = 0x0552;
  9685. t['Ymonospace'] = 0xFF39;
  9686. t['Ysmall'] = 0xF779;
  9687. t['Ytilde'] = 0x1EF8;
  9688. t['Yusbigcyrillic'] = 0x046A;
  9689. t['Yusbigiotifiedcyrillic'] = 0x046C;
  9690. t['Yuslittlecyrillic'] = 0x0466;
  9691. t['Yuslittleiotifiedcyrillic'] = 0x0468;
  9692. t['Z'] = 0x005A;
  9693. t['Zaarmenian'] = 0x0536;
  9694. t['Zacute'] = 0x0179;
  9695. t['Zcaron'] = 0x017D;
  9696. t['Zcaronsmall'] = 0xF6FF;
  9697. t['Zcircle'] = 0x24CF;
  9698. t['Zcircumflex'] = 0x1E90;
  9699. t['Zdot'] = 0x017B;
  9700. t['Zdotaccent'] = 0x017B;
  9701. t['Zdotbelow'] = 0x1E92;
  9702. t['Zecyrillic'] = 0x0417;
  9703. t['Zedescendercyrillic'] = 0x0498;
  9704. t['Zedieresiscyrillic'] = 0x04DE;
  9705. t['Zeta'] = 0x0396;
  9706. t['Zhearmenian'] = 0x053A;
  9707. t['Zhebrevecyrillic'] = 0x04C1;
  9708. t['Zhecyrillic'] = 0x0416;
  9709. t['Zhedescendercyrillic'] = 0x0496;
  9710. t['Zhedieresiscyrillic'] = 0x04DC;
  9711. t['Zlinebelow'] = 0x1E94;
  9712. t['Zmonospace'] = 0xFF3A;
  9713. t['Zsmall'] = 0xF77A;
  9714. t['Zstroke'] = 0x01B5;
  9715. t['a'] = 0x0061;
  9716. t['aabengali'] = 0x0986;
  9717. t['aacute'] = 0x00E1;
  9718. t['aadeva'] = 0x0906;
  9719. t['aagujarati'] = 0x0A86;
  9720. t['aagurmukhi'] = 0x0A06;
  9721. t['aamatragurmukhi'] = 0x0A3E;
  9722. t['aarusquare'] = 0x3303;
  9723. t['aavowelsignbengali'] = 0x09BE;
  9724. t['aavowelsigndeva'] = 0x093E;
  9725. t['aavowelsigngujarati'] = 0x0ABE;
  9726. t['abbreviationmarkarmenian'] = 0x055F;
  9727. t['abbreviationsigndeva'] = 0x0970;
  9728. t['abengali'] = 0x0985;
  9729. t['abopomofo'] = 0x311A;
  9730. t['abreve'] = 0x0103;
  9731. t['abreveacute'] = 0x1EAF;
  9732. t['abrevecyrillic'] = 0x04D1;
  9733. t['abrevedotbelow'] = 0x1EB7;
  9734. t['abrevegrave'] = 0x1EB1;
  9735. t['abrevehookabove'] = 0x1EB3;
  9736. t['abrevetilde'] = 0x1EB5;
  9737. t['acaron'] = 0x01CE;
  9738. t['acircle'] = 0x24D0;
  9739. t['acircumflex'] = 0x00E2;
  9740. t['acircumflexacute'] = 0x1EA5;
  9741. t['acircumflexdotbelow'] = 0x1EAD;
  9742. t['acircumflexgrave'] = 0x1EA7;
  9743. t['acircumflexhookabove'] = 0x1EA9;
  9744. t['acircumflextilde'] = 0x1EAB;
  9745. t['acute'] = 0x00B4;
  9746. t['acutebelowcmb'] = 0x0317;
  9747. t['acutecmb'] = 0x0301;
  9748. t['acutecomb'] = 0x0301;
  9749. t['acutedeva'] = 0x0954;
  9750. t['acutelowmod'] = 0x02CF;
  9751. t['acutetonecmb'] = 0x0341;
  9752. t['acyrillic'] = 0x0430;
  9753. t['adblgrave'] = 0x0201;
  9754. t['addakgurmukhi'] = 0x0A71;
  9755. t['adeva'] = 0x0905;
  9756. t['adieresis'] = 0x00E4;
  9757. t['adieresiscyrillic'] = 0x04D3;
  9758. t['adieresismacron'] = 0x01DF;
  9759. t['adotbelow'] = 0x1EA1;
  9760. t['adotmacron'] = 0x01E1;
  9761. t['ae'] = 0x00E6;
  9762. t['aeacute'] = 0x01FD;
  9763. t['aekorean'] = 0x3150;
  9764. t['aemacron'] = 0x01E3;
  9765. t['afii00208'] = 0x2015;
  9766. t['afii08941'] = 0x20A4;
  9767. t['afii10017'] = 0x0410;
  9768. t['afii10018'] = 0x0411;
  9769. t['afii10019'] = 0x0412;
  9770. t['afii10020'] = 0x0413;
  9771. t['afii10021'] = 0x0414;
  9772. t['afii10022'] = 0x0415;
  9773. t['afii10023'] = 0x0401;
  9774. t['afii10024'] = 0x0416;
  9775. t['afii10025'] = 0x0417;
  9776. t['afii10026'] = 0x0418;
  9777. t['afii10027'] = 0x0419;
  9778. t['afii10028'] = 0x041A;
  9779. t['afii10029'] = 0x041B;
  9780. t['afii10030'] = 0x041C;
  9781. t['afii10031'] = 0x041D;
  9782. t['afii10032'] = 0x041E;
  9783. t['afii10033'] = 0x041F;
  9784. t['afii10034'] = 0x0420;
  9785. t['afii10035'] = 0x0421;
  9786. t['afii10036'] = 0x0422;
  9787. t['afii10037'] = 0x0423;
  9788. t['afii10038'] = 0x0424;
  9789. t['afii10039'] = 0x0425;
  9790. t['afii10040'] = 0x0426;
  9791. t['afii10041'] = 0x0427;
  9792. t['afii10042'] = 0x0428;
  9793. t['afii10043'] = 0x0429;
  9794. t['afii10044'] = 0x042A;
  9795. t['afii10045'] = 0x042B;
  9796. t['afii10046'] = 0x042C;
  9797. t['afii10047'] = 0x042D;
  9798. t['afii10048'] = 0x042E;
  9799. t['afii10049'] = 0x042F;
  9800. t['afii10050'] = 0x0490;
  9801. t['afii10051'] = 0x0402;
  9802. t['afii10052'] = 0x0403;
  9803. t['afii10053'] = 0x0404;
  9804. t['afii10054'] = 0x0405;
  9805. t['afii10055'] = 0x0406;
  9806. t['afii10056'] = 0x0407;
  9807. t['afii10057'] = 0x0408;
  9808. t['afii10058'] = 0x0409;
  9809. t['afii10059'] = 0x040A;
  9810. t['afii10060'] = 0x040B;
  9811. t['afii10061'] = 0x040C;
  9812. t['afii10062'] = 0x040E;
  9813. t['afii10063'] = 0xF6C4;
  9814. t['afii10064'] = 0xF6C5;
  9815. t['afii10065'] = 0x0430;
  9816. t['afii10066'] = 0x0431;
  9817. t['afii10067'] = 0x0432;
  9818. t['afii10068'] = 0x0433;
  9819. t['afii10069'] = 0x0434;
  9820. t['afii10070'] = 0x0435;
  9821. t['afii10071'] = 0x0451;
  9822. t['afii10072'] = 0x0436;
  9823. t['afii10073'] = 0x0437;
  9824. t['afii10074'] = 0x0438;
  9825. t['afii10075'] = 0x0439;
  9826. t['afii10076'] = 0x043A;
  9827. t['afii10077'] = 0x043B;
  9828. t['afii10078'] = 0x043C;
  9829. t['afii10079'] = 0x043D;
  9830. t['afii10080'] = 0x043E;
  9831. t['afii10081'] = 0x043F;
  9832. t['afii10082'] = 0x0440;
  9833. t['afii10083'] = 0x0441;
  9834. t['afii10084'] = 0x0442;
  9835. t['afii10085'] = 0x0443;
  9836. t['afii10086'] = 0x0444;
  9837. t['afii10087'] = 0x0445;
  9838. t['afii10088'] = 0x0446;
  9839. t['afii10089'] = 0x0447;
  9840. t['afii10090'] = 0x0448;
  9841. t['afii10091'] = 0x0449;
  9842. t['afii10092'] = 0x044A;
  9843. t['afii10093'] = 0x044B;
  9844. t['afii10094'] = 0x044C;
  9845. t['afii10095'] = 0x044D;
  9846. t['afii10096'] = 0x044E;
  9847. t['afii10097'] = 0x044F;
  9848. t['afii10098'] = 0x0491;
  9849. t['afii10099'] = 0x0452;
  9850. t['afii10100'] = 0x0453;
  9851. t['afii10101'] = 0x0454;
  9852. t['afii10102'] = 0x0455;
  9853. t['afii10103'] = 0x0456;
  9854. t['afii10104'] = 0x0457;
  9855. t['afii10105'] = 0x0458;
  9856. t['afii10106'] = 0x0459;
  9857. t['afii10107'] = 0x045A;
  9858. t['afii10108'] = 0x045B;
  9859. t['afii10109'] = 0x045C;
  9860. t['afii10110'] = 0x045E;
  9861. t['afii10145'] = 0x040F;
  9862. t['afii10146'] = 0x0462;
  9863. t['afii10147'] = 0x0472;
  9864. t['afii10148'] = 0x0474;
  9865. t['afii10192'] = 0xF6C6;
  9866. t['afii10193'] = 0x045F;
  9867. t['afii10194'] = 0x0463;
  9868. t['afii10195'] = 0x0473;
  9869. t['afii10196'] = 0x0475;
  9870. t['afii10831'] = 0xF6C7;
  9871. t['afii10832'] = 0xF6C8;
  9872. t['afii10846'] = 0x04D9;
  9873. t['afii299'] = 0x200E;
  9874. t['afii300'] = 0x200F;
  9875. t['afii301'] = 0x200D;
  9876. t['afii57381'] = 0x066A;
  9877. t['afii57388'] = 0x060C;
  9878. t['afii57392'] = 0x0660;
  9879. t['afii57393'] = 0x0661;
  9880. t['afii57394'] = 0x0662;
  9881. t['afii57395'] = 0x0663;
  9882. t['afii57396'] = 0x0664;
  9883. t['afii57397'] = 0x0665;
  9884. t['afii57398'] = 0x0666;
  9885. t['afii57399'] = 0x0667;
  9886. t['afii57400'] = 0x0668;
  9887. t['afii57401'] = 0x0669;
  9888. t['afii57403'] = 0x061B;
  9889. t['afii57407'] = 0x061F;
  9890. t['afii57409'] = 0x0621;
  9891. t['afii57410'] = 0x0622;
  9892. t['afii57411'] = 0x0623;
  9893. t['afii57412'] = 0x0624;
  9894. t['afii57413'] = 0x0625;
  9895. t['afii57414'] = 0x0626;
  9896. t['afii57415'] = 0x0627;
  9897. t['afii57416'] = 0x0628;
  9898. t['afii57417'] = 0x0629;
  9899. t['afii57418'] = 0x062A;
  9900. t['afii57419'] = 0x062B;
  9901. t['afii57420'] = 0x062C;
  9902. t['afii57421'] = 0x062D;
  9903. t['afii57422'] = 0x062E;
  9904. t['afii57423'] = 0x062F;
  9905. t['afii57424'] = 0x0630;
  9906. t['afii57425'] = 0x0631;
  9907. t['afii57426'] = 0x0632;
  9908. t['afii57427'] = 0x0633;
  9909. t['afii57428'] = 0x0634;
  9910. t['afii57429'] = 0x0635;
  9911. t['afii57430'] = 0x0636;
  9912. t['afii57431'] = 0x0637;
  9913. t['afii57432'] = 0x0638;
  9914. t['afii57433'] = 0x0639;
  9915. t['afii57434'] = 0x063A;
  9916. t['afii57440'] = 0x0640;
  9917. t['afii57441'] = 0x0641;
  9918. t['afii57442'] = 0x0642;
  9919. t['afii57443'] = 0x0643;
  9920. t['afii57444'] = 0x0644;
  9921. t['afii57445'] = 0x0645;
  9922. t['afii57446'] = 0x0646;
  9923. t['afii57448'] = 0x0648;
  9924. t['afii57449'] = 0x0649;
  9925. t['afii57450'] = 0x064A;
  9926. t['afii57451'] = 0x064B;
  9927. t['afii57452'] = 0x064C;
  9928. t['afii57453'] = 0x064D;
  9929. t['afii57454'] = 0x064E;
  9930. t['afii57455'] = 0x064F;
  9931. t['afii57456'] = 0x0650;
  9932. t['afii57457'] = 0x0651;
  9933. t['afii57458'] = 0x0652;
  9934. t['afii57470'] = 0x0647;
  9935. t['afii57505'] = 0x06A4;
  9936. t['afii57506'] = 0x067E;
  9937. t['afii57507'] = 0x0686;
  9938. t['afii57508'] = 0x0698;
  9939. t['afii57509'] = 0x06AF;
  9940. t['afii57511'] = 0x0679;
  9941. t['afii57512'] = 0x0688;
  9942. t['afii57513'] = 0x0691;
  9943. t['afii57514'] = 0x06BA;
  9944. t['afii57519'] = 0x06D2;
  9945. t['afii57534'] = 0x06D5;
  9946. t['afii57636'] = 0x20AA;
  9947. t['afii57645'] = 0x05BE;
  9948. t['afii57658'] = 0x05C3;
  9949. t['afii57664'] = 0x05D0;
  9950. t['afii57665'] = 0x05D1;
  9951. t['afii57666'] = 0x05D2;
  9952. t['afii57667'] = 0x05D3;
  9953. t['afii57668'] = 0x05D4;
  9954. t['afii57669'] = 0x05D5;
  9955. t['afii57670'] = 0x05D6;
  9956. t['afii57671'] = 0x05D7;
  9957. t['afii57672'] = 0x05D8;
  9958. t['afii57673'] = 0x05D9;
  9959. t['afii57674'] = 0x05DA;
  9960. t['afii57675'] = 0x05DB;
  9961. t['afii57676'] = 0x05DC;
  9962. t['afii57677'] = 0x05DD;
  9963. t['afii57678'] = 0x05DE;
  9964. t['afii57679'] = 0x05DF;
  9965. t['afii57680'] = 0x05E0;
  9966. t['afii57681'] = 0x05E1;
  9967. t['afii57682'] = 0x05E2;
  9968. t['afii57683'] = 0x05E3;
  9969. t['afii57684'] = 0x05E4;
  9970. t['afii57685'] = 0x05E5;
  9971. t['afii57686'] = 0x05E6;
  9972. t['afii57687'] = 0x05E7;
  9973. t['afii57688'] = 0x05E8;
  9974. t['afii57689'] = 0x05E9;
  9975. t['afii57690'] = 0x05EA;
  9976. t['afii57694'] = 0xFB2A;
  9977. t['afii57695'] = 0xFB2B;
  9978. t['afii57700'] = 0xFB4B;
  9979. t['afii57705'] = 0xFB1F;
  9980. t['afii57716'] = 0x05F0;
  9981. t['afii57717'] = 0x05F1;
  9982. t['afii57718'] = 0x05F2;
  9983. t['afii57723'] = 0xFB35;
  9984. t['afii57793'] = 0x05B4;
  9985. t['afii57794'] = 0x05B5;
  9986. t['afii57795'] = 0x05B6;
  9987. t['afii57796'] = 0x05BB;
  9988. t['afii57797'] = 0x05B8;
  9989. t['afii57798'] = 0x05B7;
  9990. t['afii57799'] = 0x05B0;
  9991. t['afii57800'] = 0x05B2;
  9992. t['afii57801'] = 0x05B1;
  9993. t['afii57802'] = 0x05B3;
  9994. t['afii57803'] = 0x05C2;
  9995. t['afii57804'] = 0x05C1;
  9996. t['afii57806'] = 0x05B9;
  9997. t['afii57807'] = 0x05BC;
  9998. t['afii57839'] = 0x05BD;
  9999. t['afii57841'] = 0x05BF;
  10000. t['afii57842'] = 0x05C0;
  10001. t['afii57929'] = 0x02BC;
  10002. t['afii61248'] = 0x2105;
  10003. t['afii61289'] = 0x2113;
  10004. t['afii61352'] = 0x2116;
  10005. t['afii61573'] = 0x202C;
  10006. t['afii61574'] = 0x202D;
  10007. t['afii61575'] = 0x202E;
  10008. t['afii61664'] = 0x200C;
  10009. t['afii63167'] = 0x066D;
  10010. t['afii64937'] = 0x02BD;
  10011. t['agrave'] = 0x00E0;
  10012. t['agujarati'] = 0x0A85;
  10013. t['agurmukhi'] = 0x0A05;
  10014. t['ahiragana'] = 0x3042;
  10015. t['ahookabove'] = 0x1EA3;
  10016. t['aibengali'] = 0x0990;
  10017. t['aibopomofo'] = 0x311E;
  10018. t['aideva'] = 0x0910;
  10019. t['aiecyrillic'] = 0x04D5;
  10020. t['aigujarati'] = 0x0A90;
  10021. t['aigurmukhi'] = 0x0A10;
  10022. t['aimatragurmukhi'] = 0x0A48;
  10023. t['ainarabic'] = 0x0639;
  10024. t['ainfinalarabic'] = 0xFECA;
  10025. t['aininitialarabic'] = 0xFECB;
  10026. t['ainmedialarabic'] = 0xFECC;
  10027. t['ainvertedbreve'] = 0x0203;
  10028. t['aivowelsignbengali'] = 0x09C8;
  10029. t['aivowelsigndeva'] = 0x0948;
  10030. t['aivowelsigngujarati'] = 0x0AC8;
  10031. t['akatakana'] = 0x30A2;
  10032. t['akatakanahalfwidth'] = 0xFF71;
  10033. t['akorean'] = 0x314F;
  10034. t['alef'] = 0x05D0;
  10035. t['alefarabic'] = 0x0627;
  10036. t['alefdageshhebrew'] = 0xFB30;
  10037. t['aleffinalarabic'] = 0xFE8E;
  10038. t['alefhamzaabovearabic'] = 0x0623;
  10039. t['alefhamzaabovefinalarabic'] = 0xFE84;
  10040. t['alefhamzabelowarabic'] = 0x0625;
  10041. t['alefhamzabelowfinalarabic'] = 0xFE88;
  10042. t['alefhebrew'] = 0x05D0;
  10043. t['aleflamedhebrew'] = 0xFB4F;
  10044. t['alefmaddaabovearabic'] = 0x0622;
  10045. t['alefmaddaabovefinalarabic'] = 0xFE82;
  10046. t['alefmaksuraarabic'] = 0x0649;
  10047. t['alefmaksurafinalarabic'] = 0xFEF0;
  10048. t['alefmaksurainitialarabic'] = 0xFEF3;
  10049. t['alefmaksuramedialarabic'] = 0xFEF4;
  10050. t['alefpatahhebrew'] = 0xFB2E;
  10051. t['alefqamatshebrew'] = 0xFB2F;
  10052. t['aleph'] = 0x2135;
  10053. t['allequal'] = 0x224C;
  10054. t['alpha'] = 0x03B1;
  10055. t['alphatonos'] = 0x03AC;
  10056. t['amacron'] = 0x0101;
  10057. t['amonospace'] = 0xFF41;
  10058. t['ampersand'] = 0x0026;
  10059. t['ampersandmonospace'] = 0xFF06;
  10060. t['ampersandsmall'] = 0xF726;
  10061. t['amsquare'] = 0x33C2;
  10062. t['anbopomofo'] = 0x3122;
  10063. t['angbopomofo'] = 0x3124;
  10064. t['angbracketleft'] = 0x3008;
  10065. // Glyph is missing from Adobe's original list.
  10066. t['angbracketright'] = 0x3009;
  10067. // Glyph is missing from Adobe's original list.
  10068. t['angkhankhuthai'] = 0x0E5A;
  10069. t['angle'] = 0x2220;
  10070. t['anglebracketleft'] = 0x3008;
  10071. t['anglebracketleftvertical'] = 0xFE3F;
  10072. t['anglebracketright'] = 0x3009;
  10073. t['anglebracketrightvertical'] = 0xFE40;
  10074. t['angleleft'] = 0x2329;
  10075. t['angleright'] = 0x232A;
  10076. t['angstrom'] = 0x212B;
  10077. t['anoteleia'] = 0x0387;
  10078. t['anudattadeva'] = 0x0952;
  10079. t['anusvarabengali'] = 0x0982;
  10080. t['anusvaradeva'] = 0x0902;
  10081. t['anusvaragujarati'] = 0x0A82;
  10082. t['aogonek'] = 0x0105;
  10083. t['apaatosquare'] = 0x3300;
  10084. t['aparen'] = 0x249C;
  10085. t['apostrophearmenian'] = 0x055A;
  10086. t['apostrophemod'] = 0x02BC;
  10087. t['apple'] = 0xF8FF;
  10088. t['approaches'] = 0x2250;
  10089. t['approxequal'] = 0x2248;
  10090. t['approxequalorimage'] = 0x2252;
  10091. t['approximatelyequal'] = 0x2245;
  10092. t['araeaekorean'] = 0x318E;
  10093. t['araeakorean'] = 0x318D;
  10094. t['arc'] = 0x2312;
  10095. t['arighthalfring'] = 0x1E9A;
  10096. t['aring'] = 0x00E5;
  10097. t['aringacute'] = 0x01FB;
  10098. t['aringbelow'] = 0x1E01;
  10099. t['arrowboth'] = 0x2194;
  10100. t['arrowdashdown'] = 0x21E3;
  10101. t['arrowdashleft'] = 0x21E0;
  10102. t['arrowdashright'] = 0x21E2;
  10103. t['arrowdashup'] = 0x21E1;
  10104. t['arrowdblboth'] = 0x21D4;
  10105. t['arrowdbldown'] = 0x21D3;
  10106. t['arrowdblleft'] = 0x21D0;
  10107. t['arrowdblright'] = 0x21D2;
  10108. t['arrowdblup'] = 0x21D1;
  10109. t['arrowdown'] = 0x2193;
  10110. t['arrowdownleft'] = 0x2199;
  10111. t['arrowdownright'] = 0x2198;
  10112. t['arrowdownwhite'] = 0x21E9;
  10113. t['arrowheaddownmod'] = 0x02C5;
  10114. t['arrowheadleftmod'] = 0x02C2;
  10115. t['arrowheadrightmod'] = 0x02C3;
  10116. t['arrowheadupmod'] = 0x02C4;
  10117. t['arrowhorizex'] = 0xF8E7;
  10118. t['arrowleft'] = 0x2190;
  10119. t['arrowleftdbl'] = 0x21D0;
  10120. t['arrowleftdblstroke'] = 0x21CD;
  10121. t['arrowleftoverright'] = 0x21C6;
  10122. t['arrowleftwhite'] = 0x21E6;
  10123. t['arrowright'] = 0x2192;
  10124. t['arrowrightdblstroke'] = 0x21CF;
  10125. t['arrowrightheavy'] = 0x279E;
  10126. t['arrowrightoverleft'] = 0x21C4;
  10127. t['arrowrightwhite'] = 0x21E8;
  10128. t['arrowtableft'] = 0x21E4;
  10129. t['arrowtabright'] = 0x21E5;
  10130. t['arrowup'] = 0x2191;
  10131. t['arrowupdn'] = 0x2195;
  10132. t['arrowupdnbse'] = 0x21A8;
  10133. t['arrowupdownbase'] = 0x21A8;
  10134. t['arrowupleft'] = 0x2196;
  10135. t['arrowupleftofdown'] = 0x21C5;
  10136. t['arrowupright'] = 0x2197;
  10137. t['arrowupwhite'] = 0x21E7;
  10138. t['arrowvertex'] = 0xF8E6;
  10139. t['asciicircum'] = 0x005E;
  10140. t['asciicircummonospace'] = 0xFF3E;
  10141. t['asciitilde'] = 0x007E;
  10142. t['asciitildemonospace'] = 0xFF5E;
  10143. t['ascript'] = 0x0251;
  10144. t['ascriptturned'] = 0x0252;
  10145. t['asmallhiragana'] = 0x3041;
  10146. t['asmallkatakana'] = 0x30A1;
  10147. t['asmallkatakanahalfwidth'] = 0xFF67;
  10148. t['asterisk'] = 0x002A;
  10149. t['asteriskaltonearabic'] = 0x066D;
  10150. t['asteriskarabic'] = 0x066D;
  10151. t['asteriskmath'] = 0x2217;
  10152. t['asteriskmonospace'] = 0xFF0A;
  10153. t['asterisksmall'] = 0xFE61;
  10154. t['asterism'] = 0x2042;
  10155. t['asuperior'] = 0xF6E9;
  10156. t['asymptoticallyequal'] = 0x2243;
  10157. t['at'] = 0x0040;
  10158. t['atilde'] = 0x00E3;
  10159. t['atmonospace'] = 0xFF20;
  10160. t['atsmall'] = 0xFE6B;
  10161. t['aturned'] = 0x0250;
  10162. t['aubengali'] = 0x0994;
  10163. t['aubopomofo'] = 0x3120;
  10164. t['audeva'] = 0x0914;
  10165. t['augujarati'] = 0x0A94;
  10166. t['augurmukhi'] = 0x0A14;
  10167. t['aulengthmarkbengali'] = 0x09D7;
  10168. t['aumatragurmukhi'] = 0x0A4C;
  10169. t['auvowelsignbengali'] = 0x09CC;
  10170. t['auvowelsigndeva'] = 0x094C;
  10171. t['auvowelsigngujarati'] = 0x0ACC;
  10172. t['avagrahadeva'] = 0x093D;
  10173. t['aybarmenian'] = 0x0561;
  10174. t['ayin'] = 0x05E2;
  10175. t['ayinaltonehebrew'] = 0xFB20;
  10176. t['ayinhebrew'] = 0x05E2;
  10177. t['b'] = 0x0062;
  10178. t['babengali'] = 0x09AC;
  10179. t['backslash'] = 0x005C;
  10180. t['backslashmonospace'] = 0xFF3C;
  10181. t['badeva'] = 0x092C;
  10182. t['bagujarati'] = 0x0AAC;
  10183. t['bagurmukhi'] = 0x0A2C;
  10184. t['bahiragana'] = 0x3070;
  10185. t['bahtthai'] = 0x0E3F;
  10186. t['bakatakana'] = 0x30D0;
  10187. t['bar'] = 0x007C;
  10188. t['barmonospace'] = 0xFF5C;
  10189. t['bbopomofo'] = 0x3105;
  10190. t['bcircle'] = 0x24D1;
  10191. t['bdotaccent'] = 0x1E03;
  10192. t['bdotbelow'] = 0x1E05;
  10193. t['beamedsixteenthnotes'] = 0x266C;
  10194. t['because'] = 0x2235;
  10195. t['becyrillic'] = 0x0431;
  10196. t['beharabic'] = 0x0628;
  10197. t['behfinalarabic'] = 0xFE90;
  10198. t['behinitialarabic'] = 0xFE91;
  10199. t['behiragana'] = 0x3079;
  10200. t['behmedialarabic'] = 0xFE92;
  10201. t['behmeeminitialarabic'] = 0xFC9F;
  10202. t['behmeemisolatedarabic'] = 0xFC08;
  10203. t['behnoonfinalarabic'] = 0xFC6D;
  10204. t['bekatakana'] = 0x30D9;
  10205. t['benarmenian'] = 0x0562;
  10206. t['bet'] = 0x05D1;
  10207. t['beta'] = 0x03B2;
  10208. t['betasymbolgreek'] = 0x03D0;
  10209. t['betdagesh'] = 0xFB31;
  10210. t['betdageshhebrew'] = 0xFB31;
  10211. t['bethebrew'] = 0x05D1;
  10212. t['betrafehebrew'] = 0xFB4C;
  10213. t['bhabengali'] = 0x09AD;
  10214. t['bhadeva'] = 0x092D;
  10215. t['bhagujarati'] = 0x0AAD;
  10216. t['bhagurmukhi'] = 0x0A2D;
  10217. t['bhook'] = 0x0253;
  10218. t['bihiragana'] = 0x3073;
  10219. t['bikatakana'] = 0x30D3;
  10220. t['bilabialclick'] = 0x0298;
  10221. t['bindigurmukhi'] = 0x0A02;
  10222. t['birusquare'] = 0x3331;
  10223. t['blackcircle'] = 0x25CF;
  10224. t['blackdiamond'] = 0x25C6;
  10225. t['blackdownpointingtriangle'] = 0x25BC;
  10226. t['blackleftpointingpointer'] = 0x25C4;
  10227. t['blackleftpointingtriangle'] = 0x25C0;
  10228. t['blacklenticularbracketleft'] = 0x3010;
  10229. t['blacklenticularbracketleftvertical'] = 0xFE3B;
  10230. t['blacklenticularbracketright'] = 0x3011;
  10231. t['blacklenticularbracketrightvertical'] = 0xFE3C;
  10232. t['blacklowerlefttriangle'] = 0x25E3;
  10233. t['blacklowerrighttriangle'] = 0x25E2;
  10234. t['blackrectangle'] = 0x25AC;
  10235. t['blackrightpointingpointer'] = 0x25BA;
  10236. t['blackrightpointingtriangle'] = 0x25B6;
  10237. t['blacksmallsquare'] = 0x25AA;
  10238. t['blacksmilingface'] = 0x263B;
  10239. t['blacksquare'] = 0x25A0;
  10240. t['blackstar'] = 0x2605;
  10241. t['blackupperlefttriangle'] = 0x25E4;
  10242. t['blackupperrighttriangle'] = 0x25E5;
  10243. t['blackuppointingsmalltriangle'] = 0x25B4;
  10244. t['blackuppointingtriangle'] = 0x25B2;
  10245. t['blank'] = 0x2423;
  10246. t['blinebelow'] = 0x1E07;
  10247. t['block'] = 0x2588;
  10248. t['bmonospace'] = 0xFF42;
  10249. t['bobaimaithai'] = 0x0E1A;
  10250. t['bohiragana'] = 0x307C;
  10251. t['bokatakana'] = 0x30DC;
  10252. t['bparen'] = 0x249D;
  10253. t['bqsquare'] = 0x33C3;
  10254. t['braceex'] = 0xF8F4;
  10255. t['braceleft'] = 0x007B;
  10256. t['braceleftbt'] = 0xF8F3;
  10257. t['braceleftmid'] = 0xF8F2;
  10258. t['braceleftmonospace'] = 0xFF5B;
  10259. t['braceleftsmall'] = 0xFE5B;
  10260. t['bracelefttp'] = 0xF8F1;
  10261. t['braceleftvertical'] = 0xFE37;
  10262. t['braceright'] = 0x007D;
  10263. t['bracerightbt'] = 0xF8FE;
  10264. t['bracerightmid'] = 0xF8FD;
  10265. t['bracerightmonospace'] = 0xFF5D;
  10266. t['bracerightsmall'] = 0xFE5C;
  10267. t['bracerighttp'] = 0xF8FC;
  10268. t['bracerightvertical'] = 0xFE38;
  10269. t['bracketleft'] = 0x005B;
  10270. t['bracketleftbt'] = 0xF8F0;
  10271. t['bracketleftex'] = 0xF8EF;
  10272. t['bracketleftmonospace'] = 0xFF3B;
  10273. t['bracketlefttp'] = 0xF8EE;
  10274. t['bracketright'] = 0x005D;
  10275. t['bracketrightbt'] = 0xF8FB;
  10276. t['bracketrightex'] = 0xF8FA;
  10277. t['bracketrightmonospace'] = 0xFF3D;
  10278. t['bracketrighttp'] = 0xF8F9;
  10279. t['breve'] = 0x02D8;
  10280. t['brevebelowcmb'] = 0x032E;
  10281. t['brevecmb'] = 0x0306;
  10282. t['breveinvertedbelowcmb'] = 0x032F;
  10283. t['breveinvertedcmb'] = 0x0311;
  10284. t['breveinverteddoublecmb'] = 0x0361;
  10285. t['bridgebelowcmb'] = 0x032A;
  10286. t['bridgeinvertedbelowcmb'] = 0x033A;
  10287. t['brokenbar'] = 0x00A6;
  10288. t['bstroke'] = 0x0180;
  10289. t['bsuperior'] = 0xF6EA;
  10290. t['btopbar'] = 0x0183;
  10291. t['buhiragana'] = 0x3076;
  10292. t['bukatakana'] = 0x30D6;
  10293. t['bullet'] = 0x2022;
  10294. t['bulletinverse'] = 0x25D8;
  10295. t['bulletoperator'] = 0x2219;
  10296. t['bullseye'] = 0x25CE;
  10297. t['c'] = 0x0063;
  10298. t['caarmenian'] = 0x056E;
  10299. t['cabengali'] = 0x099A;
  10300. t['cacute'] = 0x0107;
  10301. t['cadeva'] = 0x091A;
  10302. t['cagujarati'] = 0x0A9A;
  10303. t['cagurmukhi'] = 0x0A1A;
  10304. t['calsquare'] = 0x3388;
  10305. t['candrabindubengali'] = 0x0981;
  10306. t['candrabinducmb'] = 0x0310;
  10307. t['candrabindudeva'] = 0x0901;
  10308. t['candrabindugujarati'] = 0x0A81;
  10309. t['capslock'] = 0x21EA;
  10310. t['careof'] = 0x2105;
  10311. t['caron'] = 0x02C7;
  10312. t['caronbelowcmb'] = 0x032C;
  10313. t['caroncmb'] = 0x030C;
  10314. t['carriagereturn'] = 0x21B5;
  10315. t['cbopomofo'] = 0x3118;
  10316. t['ccaron'] = 0x010D;
  10317. t['ccedilla'] = 0x00E7;
  10318. t['ccedillaacute'] = 0x1E09;
  10319. t['ccircle'] = 0x24D2;
  10320. t['ccircumflex'] = 0x0109;
  10321. t['ccurl'] = 0x0255;
  10322. t['cdot'] = 0x010B;
  10323. t['cdotaccent'] = 0x010B;
  10324. t['cdsquare'] = 0x33C5;
  10325. t['cedilla'] = 0x00B8;
  10326. t['cedillacmb'] = 0x0327;
  10327. t['cent'] = 0x00A2;
  10328. t['centigrade'] = 0x2103;
  10329. t['centinferior'] = 0xF6DF;
  10330. t['centmonospace'] = 0xFFE0;
  10331. t['centoldstyle'] = 0xF7A2;
  10332. t['centsuperior'] = 0xF6E0;
  10333. t['chaarmenian'] = 0x0579;
  10334. t['chabengali'] = 0x099B;
  10335. t['chadeva'] = 0x091B;
  10336. t['chagujarati'] = 0x0A9B;
  10337. t['chagurmukhi'] = 0x0A1B;
  10338. t['chbopomofo'] = 0x3114;
  10339. t['cheabkhasiancyrillic'] = 0x04BD;
  10340. t['checkmark'] = 0x2713;
  10341. t['checyrillic'] = 0x0447;
  10342. t['chedescenderabkhasiancyrillic'] = 0x04BF;
  10343. t['chedescendercyrillic'] = 0x04B7;
  10344. t['chedieresiscyrillic'] = 0x04F5;
  10345. t['cheharmenian'] = 0x0573;
  10346. t['chekhakassiancyrillic'] = 0x04CC;
  10347. t['cheverticalstrokecyrillic'] = 0x04B9;
  10348. t['chi'] = 0x03C7;
  10349. t['chieuchacirclekorean'] = 0x3277;
  10350. t['chieuchaparenkorean'] = 0x3217;
  10351. t['chieuchcirclekorean'] = 0x3269;
  10352. t['chieuchkorean'] = 0x314A;
  10353. t['chieuchparenkorean'] = 0x3209;
  10354. t['chochangthai'] = 0x0E0A;
  10355. t['chochanthai'] = 0x0E08;
  10356. t['chochingthai'] = 0x0E09;
  10357. t['chochoethai'] = 0x0E0C;
  10358. t['chook'] = 0x0188;
  10359. t['cieucacirclekorean'] = 0x3276;
  10360. t['cieucaparenkorean'] = 0x3216;
  10361. t['cieuccirclekorean'] = 0x3268;
  10362. t['cieuckorean'] = 0x3148;
  10363. t['cieucparenkorean'] = 0x3208;
  10364. t['cieucuparenkorean'] = 0x321C;
  10365. t['circle'] = 0x25CB;
  10366. t['circlecopyrt'] = 0x00A9;
  10367. // Glyph is missing from Adobe's original list.
  10368. t['circlemultiply'] = 0x2297;
  10369. t['circleot'] = 0x2299;
  10370. t['circleplus'] = 0x2295;
  10371. t['circlepostalmark'] = 0x3036;
  10372. t['circlewithlefthalfblack'] = 0x25D0;
  10373. t['circlewithrighthalfblack'] = 0x25D1;
  10374. t['circumflex'] = 0x02C6;
  10375. t['circumflexbelowcmb'] = 0x032D;
  10376. t['circumflexcmb'] = 0x0302;
  10377. t['clear'] = 0x2327;
  10378. t['clickalveolar'] = 0x01C2;
  10379. t['clickdental'] = 0x01C0;
  10380. t['clicklateral'] = 0x01C1;
  10381. t['clickretroflex'] = 0x01C3;
  10382. t['club'] = 0x2663;
  10383. t['clubsuitblack'] = 0x2663;
  10384. t['clubsuitwhite'] = 0x2667;
  10385. t['cmcubedsquare'] = 0x33A4;
  10386. t['cmonospace'] = 0xFF43;
  10387. t['cmsquaredsquare'] = 0x33A0;
  10388. t['coarmenian'] = 0x0581;
  10389. t['colon'] = 0x003A;
  10390. t['colonmonetary'] = 0x20A1;
  10391. t['colonmonospace'] = 0xFF1A;
  10392. t['colonsign'] = 0x20A1;
  10393. t['colonsmall'] = 0xFE55;
  10394. t['colontriangularhalfmod'] = 0x02D1;
  10395. t['colontriangularmod'] = 0x02D0;
  10396. t['comma'] = 0x002C;
  10397. t['commaabovecmb'] = 0x0313;
  10398. t['commaaboverightcmb'] = 0x0315;
  10399. t['commaaccent'] = 0xF6C3;
  10400. t['commaarabic'] = 0x060C;
  10401. t['commaarmenian'] = 0x055D;
  10402. t['commainferior'] = 0xF6E1;
  10403. t['commamonospace'] = 0xFF0C;
  10404. t['commareversedabovecmb'] = 0x0314;
  10405. t['commareversedmod'] = 0x02BD;
  10406. t['commasmall'] = 0xFE50;
  10407. t['commasuperior'] = 0xF6E2;
  10408. t['commaturnedabovecmb'] = 0x0312;
  10409. t['commaturnedmod'] = 0x02BB;
  10410. t['compass'] = 0x263C;
  10411. t['congruent'] = 0x2245;
  10412. t['contourintegral'] = 0x222E;
  10413. t['control'] = 0x2303;
  10414. t['controlACK'] = 0x0006;
  10415. t['controlBEL'] = 0x0007;
  10416. t['controlBS'] = 0x0008;
  10417. t['controlCAN'] = 0x0018;
  10418. t['controlCR'] = 0x000D;
  10419. t['controlDC1'] = 0x0011;
  10420. t['controlDC2'] = 0x0012;
  10421. t['controlDC3'] = 0x0013;
  10422. t['controlDC4'] = 0x0014;
  10423. t['controlDEL'] = 0x007F;
  10424. t['controlDLE'] = 0x0010;
  10425. t['controlEM'] = 0x0019;
  10426. t['controlENQ'] = 0x0005;
  10427. t['controlEOT'] = 0x0004;
  10428. t['controlESC'] = 0x001B;
  10429. t['controlETB'] = 0x0017;
  10430. t['controlETX'] = 0x0003;
  10431. t['controlFF'] = 0x000C;
  10432. t['controlFS'] = 0x001C;
  10433. t['controlGS'] = 0x001D;
  10434. t['controlHT'] = 0x0009;
  10435. t['controlLF'] = 0x000A;
  10436. t['controlNAK'] = 0x0015;
  10437. t['controlRS'] = 0x001E;
  10438. t['controlSI'] = 0x000F;
  10439. t['controlSO'] = 0x000E;
  10440. t['controlSOT'] = 0x0002;
  10441. t['controlSTX'] = 0x0001;
  10442. t['controlSUB'] = 0x001A;
  10443. t['controlSYN'] = 0x0016;
  10444. t['controlUS'] = 0x001F;
  10445. t['controlVT'] = 0x000B;
  10446. t['copyright'] = 0x00A9;
  10447. t['copyrightsans'] = 0xF8E9;
  10448. t['copyrightserif'] = 0xF6D9;
  10449. t['cornerbracketleft'] = 0x300C;
  10450. t['cornerbracketlefthalfwidth'] = 0xFF62;
  10451. t['cornerbracketleftvertical'] = 0xFE41;
  10452. t['cornerbracketright'] = 0x300D;
  10453. t['cornerbracketrighthalfwidth'] = 0xFF63;
  10454. t['cornerbracketrightvertical'] = 0xFE42;
  10455. t['corporationsquare'] = 0x337F;
  10456. t['cosquare'] = 0x33C7;
  10457. t['coverkgsquare'] = 0x33C6;
  10458. t['cparen'] = 0x249E;
  10459. t['cruzeiro'] = 0x20A2;
  10460. t['cstretched'] = 0x0297;
  10461. t['curlyand'] = 0x22CF;
  10462. t['curlyor'] = 0x22CE;
  10463. t['currency'] = 0x00A4;
  10464. t['cyrBreve'] = 0xF6D1;
  10465. t['cyrFlex'] = 0xF6D2;
  10466. t['cyrbreve'] = 0xF6D4;
  10467. t['cyrflex'] = 0xF6D5;
  10468. t['d'] = 0x0064;
  10469. t['daarmenian'] = 0x0564;
  10470. t['dabengali'] = 0x09A6;
  10471. t['dadarabic'] = 0x0636;
  10472. t['dadeva'] = 0x0926;
  10473. t['dadfinalarabic'] = 0xFEBE;
  10474. t['dadinitialarabic'] = 0xFEBF;
  10475. t['dadmedialarabic'] = 0xFEC0;
  10476. t['dagesh'] = 0x05BC;
  10477. t['dageshhebrew'] = 0x05BC;
  10478. t['dagger'] = 0x2020;
  10479. t['daggerdbl'] = 0x2021;
  10480. t['dagujarati'] = 0x0AA6;
  10481. t['dagurmukhi'] = 0x0A26;
  10482. t['dahiragana'] = 0x3060;
  10483. t['dakatakana'] = 0x30C0;
  10484. t['dalarabic'] = 0x062F;
  10485. t['dalet'] = 0x05D3;
  10486. t['daletdagesh'] = 0xFB33;
  10487. t['daletdageshhebrew'] = 0xFB33;
  10488. t['dalethebrew'] = 0x05D3;
  10489. t['dalfinalarabic'] = 0xFEAA;
  10490. t['dammaarabic'] = 0x064F;
  10491. t['dammalowarabic'] = 0x064F;
  10492. t['dammatanaltonearabic'] = 0x064C;
  10493. t['dammatanarabic'] = 0x064C;
  10494. t['danda'] = 0x0964;
  10495. t['dargahebrew'] = 0x05A7;
  10496. t['dargalefthebrew'] = 0x05A7;
  10497. t['dasiapneumatacyrilliccmb'] = 0x0485;
  10498. t['dblGrave'] = 0xF6D3;
  10499. t['dblanglebracketleft'] = 0x300A;
  10500. t['dblanglebracketleftvertical'] = 0xFE3D;
  10501. t['dblanglebracketright'] = 0x300B;
  10502. t['dblanglebracketrightvertical'] = 0xFE3E;
  10503. t['dblarchinvertedbelowcmb'] = 0x032B;
  10504. t['dblarrowleft'] = 0x21D4;
  10505. t['dblarrowright'] = 0x21D2;
  10506. t['dbldanda'] = 0x0965;
  10507. t['dblgrave'] = 0xF6D6;
  10508. t['dblgravecmb'] = 0x030F;
  10509. t['dblintegral'] = 0x222C;
  10510. t['dbllowline'] = 0x2017;
  10511. t['dbllowlinecmb'] = 0x0333;
  10512. t['dbloverlinecmb'] = 0x033F;
  10513. t['dblprimemod'] = 0x02BA;
  10514. t['dblverticalbar'] = 0x2016;
  10515. t['dblverticallineabovecmb'] = 0x030E;
  10516. t['dbopomofo'] = 0x3109;
  10517. t['dbsquare'] = 0x33C8;
  10518. t['dcaron'] = 0x010F;
  10519. t['dcedilla'] = 0x1E11;
  10520. t['dcircle'] = 0x24D3;
  10521. t['dcircumflexbelow'] = 0x1E13;
  10522. t['dcroat'] = 0x0111;
  10523. t['ddabengali'] = 0x09A1;
  10524. t['ddadeva'] = 0x0921;
  10525. t['ddagujarati'] = 0x0AA1;
  10526. t['ddagurmukhi'] = 0x0A21;
  10527. t['ddalarabic'] = 0x0688;
  10528. t['ddalfinalarabic'] = 0xFB89;
  10529. t['dddhadeva'] = 0x095C;
  10530. t['ddhabengali'] = 0x09A2;
  10531. t['ddhadeva'] = 0x0922;
  10532. t['ddhagujarati'] = 0x0AA2;
  10533. t['ddhagurmukhi'] = 0x0A22;
  10534. t['ddotaccent'] = 0x1E0B;
  10535. t['ddotbelow'] = 0x1E0D;
  10536. t['decimalseparatorarabic'] = 0x066B;
  10537. t['decimalseparatorpersian'] = 0x066B;
  10538. t['decyrillic'] = 0x0434;
  10539. t['degree'] = 0x00B0;
  10540. t['dehihebrew'] = 0x05AD;
  10541. t['dehiragana'] = 0x3067;
  10542. t['deicoptic'] = 0x03EF;
  10543. t['dekatakana'] = 0x30C7;
  10544. t['deleteleft'] = 0x232B;
  10545. t['deleteright'] = 0x2326;
  10546. t['delta'] = 0x03B4;
  10547. t['deltaturned'] = 0x018D;
  10548. t['denominatorminusonenumeratorbengali'] = 0x09F8;
  10549. t['dezh'] = 0x02A4;
  10550. t['dhabengali'] = 0x09A7;
  10551. t['dhadeva'] = 0x0927;
  10552. t['dhagujarati'] = 0x0AA7;
  10553. t['dhagurmukhi'] = 0x0A27;
  10554. t['dhook'] = 0x0257;
  10555. t['dialytikatonos'] = 0x0385;
  10556. t['dialytikatonoscmb'] = 0x0344;
  10557. t['diamond'] = 0x2666;
  10558. t['diamondsuitwhite'] = 0x2662;
  10559. t['dieresis'] = 0x00A8;
  10560. t['dieresisacute'] = 0xF6D7;
  10561. t['dieresisbelowcmb'] = 0x0324;
  10562. t['dieresiscmb'] = 0x0308;
  10563. t['dieresisgrave'] = 0xF6D8;
  10564. t['dieresistonos'] = 0x0385;
  10565. t['dihiragana'] = 0x3062;
  10566. t['dikatakana'] = 0x30C2;
  10567. t['dittomark'] = 0x3003;
  10568. t['divide'] = 0x00F7;
  10569. t['divides'] = 0x2223;
  10570. t['divisionslash'] = 0x2215;
  10571. t['djecyrillic'] = 0x0452;
  10572. t['dkshade'] = 0x2593;
  10573. t['dlinebelow'] = 0x1E0F;
  10574. t['dlsquare'] = 0x3397;
  10575. t['dmacron'] = 0x0111;
  10576. t['dmonospace'] = 0xFF44;
  10577. t['dnblock'] = 0x2584;
  10578. t['dochadathai'] = 0x0E0E;
  10579. t['dodekthai'] = 0x0E14;
  10580. t['dohiragana'] = 0x3069;
  10581. t['dokatakana'] = 0x30C9;
  10582. t['dollar'] = 0x0024;
  10583. t['dollarinferior'] = 0xF6E3;
  10584. t['dollarmonospace'] = 0xFF04;
  10585. t['dollaroldstyle'] = 0xF724;
  10586. t['dollarsmall'] = 0xFE69;
  10587. t['dollarsuperior'] = 0xF6E4;
  10588. t['dong'] = 0x20AB;
  10589. t['dorusquare'] = 0x3326;
  10590. t['dotaccent'] = 0x02D9;
  10591. t['dotaccentcmb'] = 0x0307;
  10592. t['dotbelowcmb'] = 0x0323;
  10593. t['dotbelowcomb'] = 0x0323;
  10594. t['dotkatakana'] = 0x30FB;
  10595. t['dotlessi'] = 0x0131;
  10596. t['dotlessj'] = 0xF6BE;
  10597. t['dotlessjstrokehook'] = 0x0284;
  10598. t['dotmath'] = 0x22C5;
  10599. t['dottedcircle'] = 0x25CC;
  10600. t['doubleyodpatah'] = 0xFB1F;
  10601. t['doubleyodpatahhebrew'] = 0xFB1F;
  10602. t['downtackbelowcmb'] = 0x031E;
  10603. t['downtackmod'] = 0x02D5;
  10604. t['dparen'] = 0x249F;
  10605. t['dsuperior'] = 0xF6EB;
  10606. t['dtail'] = 0x0256;
  10607. t['dtopbar'] = 0x018C;
  10608. t['duhiragana'] = 0x3065;
  10609. t['dukatakana'] = 0x30C5;
  10610. t['dz'] = 0x01F3;
  10611. t['dzaltone'] = 0x02A3;
  10612. t['dzcaron'] = 0x01C6;
  10613. t['dzcurl'] = 0x02A5;
  10614. t['dzeabkhasiancyrillic'] = 0x04E1;
  10615. t['dzecyrillic'] = 0x0455;
  10616. t['dzhecyrillic'] = 0x045F;
  10617. t['e'] = 0x0065;
  10618. t['eacute'] = 0x00E9;
  10619. t['earth'] = 0x2641;
  10620. t['ebengali'] = 0x098F;
  10621. t['ebopomofo'] = 0x311C;
  10622. t['ebreve'] = 0x0115;
  10623. t['ecandradeva'] = 0x090D;
  10624. t['ecandragujarati'] = 0x0A8D;
  10625. t['ecandravowelsigndeva'] = 0x0945;
  10626. t['ecandravowelsigngujarati'] = 0x0AC5;
  10627. t['ecaron'] = 0x011B;
  10628. t['ecedillabreve'] = 0x1E1D;
  10629. t['echarmenian'] = 0x0565;
  10630. t['echyiwnarmenian'] = 0x0587;
  10631. t['ecircle'] = 0x24D4;
  10632. t['ecircumflex'] = 0x00EA;
  10633. t['ecircumflexacute'] = 0x1EBF;
  10634. t['ecircumflexbelow'] = 0x1E19;
  10635. t['ecircumflexdotbelow'] = 0x1EC7;
  10636. t['ecircumflexgrave'] = 0x1EC1;
  10637. t['ecircumflexhookabove'] = 0x1EC3;
  10638. t['ecircumflextilde'] = 0x1EC5;
  10639. t['ecyrillic'] = 0x0454;
  10640. t['edblgrave'] = 0x0205;
  10641. t['edeva'] = 0x090F;
  10642. t['edieresis'] = 0x00EB;
  10643. t['edot'] = 0x0117;
  10644. t['edotaccent'] = 0x0117;
  10645. t['edotbelow'] = 0x1EB9;
  10646. t['eegurmukhi'] = 0x0A0F;
  10647. t['eematragurmukhi'] = 0x0A47;
  10648. t['efcyrillic'] = 0x0444;
  10649. t['egrave'] = 0x00E8;
  10650. t['egujarati'] = 0x0A8F;
  10651. t['eharmenian'] = 0x0567;
  10652. t['ehbopomofo'] = 0x311D;
  10653. t['ehiragana'] = 0x3048;
  10654. t['ehookabove'] = 0x1EBB;
  10655. t['eibopomofo'] = 0x311F;
  10656. t['eight'] = 0x0038;
  10657. t['eightarabic'] = 0x0668;
  10658. t['eightbengali'] = 0x09EE;
  10659. t['eightcircle'] = 0x2467;
  10660. t['eightcircleinversesansserif'] = 0x2791;
  10661. t['eightdeva'] = 0x096E;
  10662. t['eighteencircle'] = 0x2471;
  10663. t['eighteenparen'] = 0x2485;
  10664. t['eighteenperiod'] = 0x2499;
  10665. t['eightgujarati'] = 0x0AEE;
  10666. t['eightgurmukhi'] = 0x0A6E;
  10667. t['eighthackarabic'] = 0x0668;
  10668. t['eighthangzhou'] = 0x3028;
  10669. t['eighthnotebeamed'] = 0x266B;
  10670. t['eightideographicparen'] = 0x3227;
  10671. t['eightinferior'] = 0x2088;
  10672. t['eightmonospace'] = 0xFF18;
  10673. t['eightoldstyle'] = 0xF738;
  10674. t['eightparen'] = 0x247B;
  10675. t['eightperiod'] = 0x248F;
  10676. t['eightpersian'] = 0x06F8;
  10677. t['eightroman'] = 0x2177;
  10678. t['eightsuperior'] = 0x2078;
  10679. t['eightthai'] = 0x0E58;
  10680. t['einvertedbreve'] = 0x0207;
  10681. t['eiotifiedcyrillic'] = 0x0465;
  10682. t['ekatakana'] = 0x30A8;
  10683. t['ekatakanahalfwidth'] = 0xFF74;
  10684. t['ekonkargurmukhi'] = 0x0A74;
  10685. t['ekorean'] = 0x3154;
  10686. t['elcyrillic'] = 0x043B;
  10687. t['element'] = 0x2208;
  10688. t['elevencircle'] = 0x246A;
  10689. t['elevenparen'] = 0x247E;
  10690. t['elevenperiod'] = 0x2492;
  10691. t['elevenroman'] = 0x217A;
  10692. t['ellipsis'] = 0x2026;
  10693. t['ellipsisvertical'] = 0x22EE;
  10694. t['emacron'] = 0x0113;
  10695. t['emacronacute'] = 0x1E17;
  10696. t['emacrongrave'] = 0x1E15;
  10697. t['emcyrillic'] = 0x043C;
  10698. t['emdash'] = 0x2014;
  10699. t['emdashvertical'] = 0xFE31;
  10700. t['emonospace'] = 0xFF45;
  10701. t['emphasismarkarmenian'] = 0x055B;
  10702. t['emptyset'] = 0x2205;
  10703. t['enbopomofo'] = 0x3123;
  10704. t['encyrillic'] = 0x043D;
  10705. t['endash'] = 0x2013;
  10706. t['endashvertical'] = 0xFE32;
  10707. t['endescendercyrillic'] = 0x04A3;
  10708. t['eng'] = 0x014B;
  10709. t['engbopomofo'] = 0x3125;
  10710. t['enghecyrillic'] = 0x04A5;
  10711. t['enhookcyrillic'] = 0x04C8;
  10712. t['enspace'] = 0x2002;
  10713. t['eogonek'] = 0x0119;
  10714. t['eokorean'] = 0x3153;
  10715. t['eopen'] = 0x025B;
  10716. t['eopenclosed'] = 0x029A;
  10717. t['eopenreversed'] = 0x025C;
  10718. t['eopenreversedclosed'] = 0x025E;
  10719. t['eopenreversedhook'] = 0x025D;
  10720. t['eparen'] = 0x24A0;
  10721. t['epsilon'] = 0x03B5;
  10722. t['epsilontonos'] = 0x03AD;
  10723. t['equal'] = 0x003D;
  10724. t['equalmonospace'] = 0xFF1D;
  10725. t['equalsmall'] = 0xFE66;
  10726. t['equalsuperior'] = 0x207C;
  10727. t['equivalence'] = 0x2261;
  10728. t['erbopomofo'] = 0x3126;
  10729. t['ercyrillic'] = 0x0440;
  10730. t['ereversed'] = 0x0258;
  10731. t['ereversedcyrillic'] = 0x044D;
  10732. t['escyrillic'] = 0x0441;
  10733. t['esdescendercyrillic'] = 0x04AB;
  10734. t['esh'] = 0x0283;
  10735. t['eshcurl'] = 0x0286;
  10736. t['eshortdeva'] = 0x090E;
  10737. t['eshortvowelsigndeva'] = 0x0946;
  10738. t['eshreversedloop'] = 0x01AA;
  10739. t['eshsquatreversed'] = 0x0285;
  10740. t['esmallhiragana'] = 0x3047;
  10741. t['esmallkatakana'] = 0x30A7;
  10742. t['esmallkatakanahalfwidth'] = 0xFF6A;
  10743. t['estimated'] = 0x212E;
  10744. t['esuperior'] = 0xF6EC;
  10745. t['eta'] = 0x03B7;
  10746. t['etarmenian'] = 0x0568;
  10747. t['etatonos'] = 0x03AE;
  10748. t['eth'] = 0x00F0;
  10749. t['etilde'] = 0x1EBD;
  10750. t['etildebelow'] = 0x1E1B;
  10751. t['etnahtafoukhhebrew'] = 0x0591;
  10752. t['etnahtafoukhlefthebrew'] = 0x0591;
  10753. t['etnahtahebrew'] = 0x0591;
  10754. t['etnahtalefthebrew'] = 0x0591;
  10755. t['eturned'] = 0x01DD;
  10756. t['eukorean'] = 0x3161;
  10757. t['euro'] = 0x20AC;
  10758. t['evowelsignbengali'] = 0x09C7;
  10759. t['evowelsigndeva'] = 0x0947;
  10760. t['evowelsigngujarati'] = 0x0AC7;
  10761. t['exclam'] = 0x0021;
  10762. t['exclamarmenian'] = 0x055C;
  10763. t['exclamdbl'] = 0x203C;
  10764. t['exclamdown'] = 0x00A1;
  10765. t['exclamdownsmall'] = 0xF7A1;
  10766. t['exclammonospace'] = 0xFF01;
  10767. t['exclamsmall'] = 0xF721;
  10768. t['existential'] = 0x2203;
  10769. t['ezh'] = 0x0292;
  10770. t['ezhcaron'] = 0x01EF;
  10771. t['ezhcurl'] = 0x0293;
  10772. t['ezhreversed'] = 0x01B9;
  10773. t['ezhtail'] = 0x01BA;
  10774. t['f'] = 0x0066;
  10775. t['fadeva'] = 0x095E;
  10776. t['fagurmukhi'] = 0x0A5E;
  10777. t['fahrenheit'] = 0x2109;
  10778. t['fathaarabic'] = 0x064E;
  10779. t['fathalowarabic'] = 0x064E;
  10780. t['fathatanarabic'] = 0x064B;
  10781. t['fbopomofo'] = 0x3108;
  10782. t['fcircle'] = 0x24D5;
  10783. t['fdotaccent'] = 0x1E1F;
  10784. t['feharabic'] = 0x0641;
  10785. t['feharmenian'] = 0x0586;
  10786. t['fehfinalarabic'] = 0xFED2;
  10787. t['fehinitialarabic'] = 0xFED3;
  10788. t['fehmedialarabic'] = 0xFED4;
  10789. t['feicoptic'] = 0x03E5;
  10790. t['female'] = 0x2640;
  10791. t['ff'] = 0xFB00;
  10792. t['ffi'] = 0xFB03;
  10793. t['ffl'] = 0xFB04;
  10794. t['fi'] = 0xFB01;
  10795. t['fifteencircle'] = 0x246E;
  10796. t['fifteenparen'] = 0x2482;
  10797. t['fifteenperiod'] = 0x2496;
  10798. t['figuredash'] = 0x2012;
  10799. t['filledbox'] = 0x25A0;
  10800. t['filledrect'] = 0x25AC;
  10801. t['finalkaf'] = 0x05DA;
  10802. t['finalkafdagesh'] = 0xFB3A;
  10803. t['finalkafdageshhebrew'] = 0xFB3A;
  10804. t['finalkafhebrew'] = 0x05DA;
  10805. t['finalmem'] = 0x05DD;
  10806. t['finalmemhebrew'] = 0x05DD;
  10807. t['finalnun'] = 0x05DF;
  10808. t['finalnunhebrew'] = 0x05DF;
  10809. t['finalpe'] = 0x05E3;
  10810. t['finalpehebrew'] = 0x05E3;
  10811. t['finaltsadi'] = 0x05E5;
  10812. t['finaltsadihebrew'] = 0x05E5;
  10813. t['firsttonechinese'] = 0x02C9;
  10814. t['fisheye'] = 0x25C9;
  10815. t['fitacyrillic'] = 0x0473;
  10816. t['five'] = 0x0035;
  10817. t['fivearabic'] = 0x0665;
  10818. t['fivebengali'] = 0x09EB;
  10819. t['fivecircle'] = 0x2464;
  10820. t['fivecircleinversesansserif'] = 0x278E;
  10821. t['fivedeva'] = 0x096B;
  10822. t['fiveeighths'] = 0x215D;
  10823. t['fivegujarati'] = 0x0AEB;
  10824. t['fivegurmukhi'] = 0x0A6B;
  10825. t['fivehackarabic'] = 0x0665;
  10826. t['fivehangzhou'] = 0x3025;
  10827. t['fiveideographicparen'] = 0x3224;
  10828. t['fiveinferior'] = 0x2085;
  10829. t['fivemonospace'] = 0xFF15;
  10830. t['fiveoldstyle'] = 0xF735;
  10831. t['fiveparen'] = 0x2478;
  10832. t['fiveperiod'] = 0x248C;
  10833. t['fivepersian'] = 0x06F5;
  10834. t['fiveroman'] = 0x2174;
  10835. t['fivesuperior'] = 0x2075;
  10836. t['fivethai'] = 0x0E55;
  10837. t['fl'] = 0xFB02;
  10838. t['florin'] = 0x0192;
  10839. t['fmonospace'] = 0xFF46;
  10840. t['fmsquare'] = 0x3399;
  10841. t['fofanthai'] = 0x0E1F;
  10842. t['fofathai'] = 0x0E1D;
  10843. t['fongmanthai'] = 0x0E4F;
  10844. t['forall'] = 0x2200;
  10845. t['four'] = 0x0034;
  10846. t['fourarabic'] = 0x0664;
  10847. t['fourbengali'] = 0x09EA;
  10848. t['fourcircle'] = 0x2463;
  10849. t['fourcircleinversesansserif'] = 0x278D;
  10850. t['fourdeva'] = 0x096A;
  10851. t['fourgujarati'] = 0x0AEA;
  10852. t['fourgurmukhi'] = 0x0A6A;
  10853. t['fourhackarabic'] = 0x0664;
  10854. t['fourhangzhou'] = 0x3024;
  10855. t['fourideographicparen'] = 0x3223;
  10856. t['fourinferior'] = 0x2084;
  10857. t['fourmonospace'] = 0xFF14;
  10858. t['fournumeratorbengali'] = 0x09F7;
  10859. t['fouroldstyle'] = 0xF734;
  10860. t['fourparen'] = 0x2477;
  10861. t['fourperiod'] = 0x248B;
  10862. t['fourpersian'] = 0x06F4;
  10863. t['fourroman'] = 0x2173;
  10864. t['foursuperior'] = 0x2074;
  10865. t['fourteencircle'] = 0x246D;
  10866. t['fourteenparen'] = 0x2481;
  10867. t['fourteenperiod'] = 0x2495;
  10868. t['fourthai'] = 0x0E54;
  10869. t['fourthtonechinese'] = 0x02CB;
  10870. t['fparen'] = 0x24A1;
  10871. t['fraction'] = 0x2044;
  10872. t['franc'] = 0x20A3;
  10873. t['g'] = 0x0067;
  10874. t['gabengali'] = 0x0997;
  10875. t['gacute'] = 0x01F5;
  10876. t['gadeva'] = 0x0917;
  10877. t['gafarabic'] = 0x06AF;
  10878. t['gaffinalarabic'] = 0xFB93;
  10879. t['gafinitialarabic'] = 0xFB94;
  10880. t['gafmedialarabic'] = 0xFB95;
  10881. t['gagujarati'] = 0x0A97;
  10882. t['gagurmukhi'] = 0x0A17;
  10883. t['gahiragana'] = 0x304C;
  10884. t['gakatakana'] = 0x30AC;
  10885. t['gamma'] = 0x03B3;
  10886. t['gammalatinsmall'] = 0x0263;
  10887. t['gammasuperior'] = 0x02E0;
  10888. t['gangiacoptic'] = 0x03EB;
  10889. t['gbopomofo'] = 0x310D;
  10890. t['gbreve'] = 0x011F;
  10891. t['gcaron'] = 0x01E7;
  10892. t['gcedilla'] = 0x0123;
  10893. t['gcircle'] = 0x24D6;
  10894. t['gcircumflex'] = 0x011D;
  10895. t['gcommaaccent'] = 0x0123;
  10896. t['gdot'] = 0x0121;
  10897. t['gdotaccent'] = 0x0121;
  10898. t['gecyrillic'] = 0x0433;
  10899. t['gehiragana'] = 0x3052;
  10900. t['gekatakana'] = 0x30B2;
  10901. t['geometricallyequal'] = 0x2251;
  10902. t['gereshaccenthebrew'] = 0x059C;
  10903. t['gereshhebrew'] = 0x05F3;
  10904. t['gereshmuqdamhebrew'] = 0x059D;
  10905. t['germandbls'] = 0x00DF;
  10906. t['gershayimaccenthebrew'] = 0x059E;
  10907. t['gershayimhebrew'] = 0x05F4;
  10908. t['getamark'] = 0x3013;
  10909. t['ghabengali'] = 0x0998;
  10910. t['ghadarmenian'] = 0x0572;
  10911. t['ghadeva'] = 0x0918;
  10912. t['ghagujarati'] = 0x0A98;
  10913. t['ghagurmukhi'] = 0x0A18;
  10914. t['ghainarabic'] = 0x063A;
  10915. t['ghainfinalarabic'] = 0xFECE;
  10916. t['ghaininitialarabic'] = 0xFECF;
  10917. t['ghainmedialarabic'] = 0xFED0;
  10918. t['ghemiddlehookcyrillic'] = 0x0495;
  10919. t['ghestrokecyrillic'] = 0x0493;
  10920. t['gheupturncyrillic'] = 0x0491;
  10921. t['ghhadeva'] = 0x095A;
  10922. t['ghhagurmukhi'] = 0x0A5A;
  10923. t['ghook'] = 0x0260;
  10924. t['ghzsquare'] = 0x3393;
  10925. t['gihiragana'] = 0x304E;
  10926. t['gikatakana'] = 0x30AE;
  10927. t['gimarmenian'] = 0x0563;
  10928. t['gimel'] = 0x05D2;
  10929. t['gimeldagesh'] = 0xFB32;
  10930. t['gimeldageshhebrew'] = 0xFB32;
  10931. t['gimelhebrew'] = 0x05D2;
  10932. t['gjecyrillic'] = 0x0453;
  10933. t['glottalinvertedstroke'] = 0x01BE;
  10934. t['glottalstop'] = 0x0294;
  10935. t['glottalstopinverted'] = 0x0296;
  10936. t['glottalstopmod'] = 0x02C0;
  10937. t['glottalstopreversed'] = 0x0295;
  10938. t['glottalstopreversedmod'] = 0x02C1;
  10939. t['glottalstopreversedsuperior'] = 0x02E4;
  10940. t['glottalstopstroke'] = 0x02A1;
  10941. t['glottalstopstrokereversed'] = 0x02A2;
  10942. t['gmacron'] = 0x1E21;
  10943. t['gmonospace'] = 0xFF47;
  10944. t['gohiragana'] = 0x3054;
  10945. t['gokatakana'] = 0x30B4;
  10946. t['gparen'] = 0x24A2;
  10947. t['gpasquare'] = 0x33AC;
  10948. t['gradient'] = 0x2207;
  10949. t['grave'] = 0x0060;
  10950. t['gravebelowcmb'] = 0x0316;
  10951. t['gravecmb'] = 0x0300;
  10952. t['gravecomb'] = 0x0300;
  10953. t['gravedeva'] = 0x0953;
  10954. t['gravelowmod'] = 0x02CE;
  10955. t['gravemonospace'] = 0xFF40;
  10956. t['gravetonecmb'] = 0x0340;
  10957. t['greater'] = 0x003E;
  10958. t['greaterequal'] = 0x2265;
  10959. t['greaterequalorless'] = 0x22DB;
  10960. t['greatermonospace'] = 0xFF1E;
  10961. t['greaterorequivalent'] = 0x2273;
  10962. t['greaterorless'] = 0x2277;
  10963. t['greateroverequal'] = 0x2267;
  10964. t['greatersmall'] = 0xFE65;
  10965. t['gscript'] = 0x0261;
  10966. t['gstroke'] = 0x01E5;
  10967. t['guhiragana'] = 0x3050;
  10968. t['guillemotleft'] = 0x00AB;
  10969. t['guillemotright'] = 0x00BB;
  10970. t['guilsinglleft'] = 0x2039;
  10971. t['guilsinglright'] = 0x203A;
  10972. t['gukatakana'] = 0x30B0;
  10973. t['guramusquare'] = 0x3318;
  10974. t['gysquare'] = 0x33C9;
  10975. t['h'] = 0x0068;
  10976. t['haabkhasiancyrillic'] = 0x04A9;
  10977. t['haaltonearabic'] = 0x06C1;
  10978. t['habengali'] = 0x09B9;
  10979. t['hadescendercyrillic'] = 0x04B3;
  10980. t['hadeva'] = 0x0939;
  10981. t['hagujarati'] = 0x0AB9;
  10982. t['hagurmukhi'] = 0x0A39;
  10983. t['haharabic'] = 0x062D;
  10984. t['hahfinalarabic'] = 0xFEA2;
  10985. t['hahinitialarabic'] = 0xFEA3;
  10986. t['hahiragana'] = 0x306F;
  10987. t['hahmedialarabic'] = 0xFEA4;
  10988. t['haitusquare'] = 0x332A;
  10989. t['hakatakana'] = 0x30CF;
  10990. t['hakatakanahalfwidth'] = 0xFF8A;
  10991. t['halantgurmukhi'] = 0x0A4D;
  10992. t['hamzaarabic'] = 0x0621;
  10993. t['hamzalowarabic'] = 0x0621;
  10994. t['hangulfiller'] = 0x3164;
  10995. t['hardsigncyrillic'] = 0x044A;
  10996. t['harpoonleftbarbup'] = 0x21BC;
  10997. t['harpoonrightbarbup'] = 0x21C0;
  10998. t['hasquare'] = 0x33CA;
  10999. t['hatafpatah'] = 0x05B2;
  11000. t['hatafpatah16'] = 0x05B2;
  11001. t['hatafpatah23'] = 0x05B2;
  11002. t['hatafpatah2f'] = 0x05B2;
  11003. t['hatafpatahhebrew'] = 0x05B2;
  11004. t['hatafpatahnarrowhebrew'] = 0x05B2;
  11005. t['hatafpatahquarterhebrew'] = 0x05B2;
  11006. t['hatafpatahwidehebrew'] = 0x05B2;
  11007. t['hatafqamats'] = 0x05B3;
  11008. t['hatafqamats1b'] = 0x05B3;
  11009. t['hatafqamats28'] = 0x05B3;
  11010. t['hatafqamats34'] = 0x05B3;
  11011. t['hatafqamatshebrew'] = 0x05B3;
  11012. t['hatafqamatsnarrowhebrew'] = 0x05B3;
  11013. t['hatafqamatsquarterhebrew'] = 0x05B3;
  11014. t['hatafqamatswidehebrew'] = 0x05B3;
  11015. t['hatafsegol'] = 0x05B1;
  11016. t['hatafsegol17'] = 0x05B1;
  11017. t['hatafsegol24'] = 0x05B1;
  11018. t['hatafsegol30'] = 0x05B1;
  11019. t['hatafsegolhebrew'] = 0x05B1;
  11020. t['hatafsegolnarrowhebrew'] = 0x05B1;
  11021. t['hatafsegolquarterhebrew'] = 0x05B1;
  11022. t['hatafsegolwidehebrew'] = 0x05B1;
  11023. t['hbar'] = 0x0127;
  11024. t['hbopomofo'] = 0x310F;
  11025. t['hbrevebelow'] = 0x1E2B;
  11026. t['hcedilla'] = 0x1E29;
  11027. t['hcircle'] = 0x24D7;
  11028. t['hcircumflex'] = 0x0125;
  11029. t['hdieresis'] = 0x1E27;
  11030. t['hdotaccent'] = 0x1E23;
  11031. t['hdotbelow'] = 0x1E25;
  11032. t['he'] = 0x05D4;
  11033. t['heart'] = 0x2665;
  11034. t['heartsuitblack'] = 0x2665;
  11035. t['heartsuitwhite'] = 0x2661;
  11036. t['hedagesh'] = 0xFB34;
  11037. t['hedageshhebrew'] = 0xFB34;
  11038. t['hehaltonearabic'] = 0x06C1;
  11039. t['heharabic'] = 0x0647;
  11040. t['hehebrew'] = 0x05D4;
  11041. t['hehfinalaltonearabic'] = 0xFBA7;
  11042. t['hehfinalalttwoarabic'] = 0xFEEA;
  11043. t['hehfinalarabic'] = 0xFEEA;
  11044. t['hehhamzaabovefinalarabic'] = 0xFBA5;
  11045. t['hehhamzaaboveisolatedarabic'] = 0xFBA4;
  11046. t['hehinitialaltonearabic'] = 0xFBA8;
  11047. t['hehinitialarabic'] = 0xFEEB;
  11048. t['hehiragana'] = 0x3078;
  11049. t['hehmedialaltonearabic'] = 0xFBA9;
  11050. t['hehmedialarabic'] = 0xFEEC;
  11051. t['heiseierasquare'] = 0x337B;
  11052. t['hekatakana'] = 0x30D8;
  11053. t['hekatakanahalfwidth'] = 0xFF8D;
  11054. t['hekutaarusquare'] = 0x3336;
  11055. t['henghook'] = 0x0267;
  11056. t['herutusquare'] = 0x3339;
  11057. t['het'] = 0x05D7;
  11058. t['hethebrew'] = 0x05D7;
  11059. t['hhook'] = 0x0266;
  11060. t['hhooksuperior'] = 0x02B1;
  11061. t['hieuhacirclekorean'] = 0x327B;
  11062. t['hieuhaparenkorean'] = 0x321B;
  11063. t['hieuhcirclekorean'] = 0x326D;
  11064. t['hieuhkorean'] = 0x314E;
  11065. t['hieuhparenkorean'] = 0x320D;
  11066. t['hihiragana'] = 0x3072;
  11067. t['hikatakana'] = 0x30D2;
  11068. t['hikatakanahalfwidth'] = 0xFF8B;
  11069. t['hiriq'] = 0x05B4;
  11070. t['hiriq14'] = 0x05B4;
  11071. t['hiriq21'] = 0x05B4;
  11072. t['hiriq2d'] = 0x05B4;
  11073. t['hiriqhebrew'] = 0x05B4;
  11074. t['hiriqnarrowhebrew'] = 0x05B4;
  11075. t['hiriqquarterhebrew'] = 0x05B4;
  11076. t['hiriqwidehebrew'] = 0x05B4;
  11077. t['hlinebelow'] = 0x1E96;
  11078. t['hmonospace'] = 0xFF48;
  11079. t['hoarmenian'] = 0x0570;
  11080. t['hohipthai'] = 0x0E2B;
  11081. t['hohiragana'] = 0x307B;
  11082. t['hokatakana'] = 0x30DB;
  11083. t['hokatakanahalfwidth'] = 0xFF8E;
  11084. t['holam'] = 0x05B9;
  11085. t['holam19'] = 0x05B9;
  11086. t['holam26'] = 0x05B9;
  11087. t['holam32'] = 0x05B9;
  11088. t['holamhebrew'] = 0x05B9;
  11089. t['holamnarrowhebrew'] = 0x05B9;
  11090. t['holamquarterhebrew'] = 0x05B9;
  11091. t['holamwidehebrew'] = 0x05B9;
  11092. t['honokhukthai'] = 0x0E2E;
  11093. t['hookabovecomb'] = 0x0309;
  11094. t['hookcmb'] = 0x0309;
  11095. t['hookpalatalizedbelowcmb'] = 0x0321;
  11096. t['hookretroflexbelowcmb'] = 0x0322;
  11097. t['hoonsquare'] = 0x3342;
  11098. t['horicoptic'] = 0x03E9;
  11099. t['horizontalbar'] = 0x2015;
  11100. t['horncmb'] = 0x031B;
  11101. t['hotsprings'] = 0x2668;
  11102. t['house'] = 0x2302;
  11103. t['hparen'] = 0x24A3;
  11104. t['hsuperior'] = 0x02B0;
  11105. t['hturned'] = 0x0265;
  11106. t['huhiragana'] = 0x3075;
  11107. t['huiitosquare'] = 0x3333;
  11108. t['hukatakana'] = 0x30D5;
  11109. t['hukatakanahalfwidth'] = 0xFF8C;
  11110. t['hungarumlaut'] = 0x02DD;
  11111. t['hungarumlautcmb'] = 0x030B;
  11112. t['hv'] = 0x0195;
  11113. t['hyphen'] = 0x002D;
  11114. t['hypheninferior'] = 0xF6E5;
  11115. t['hyphenmonospace'] = 0xFF0D;
  11116. t['hyphensmall'] = 0xFE63;
  11117. t['hyphensuperior'] = 0xF6E6;
  11118. t['hyphentwo'] = 0x2010;
  11119. t['i'] = 0x0069;
  11120. t['iacute'] = 0x00ED;
  11121. t['iacyrillic'] = 0x044F;
  11122. t['ibengali'] = 0x0987;
  11123. t['ibopomofo'] = 0x3127;
  11124. t['ibreve'] = 0x012D;
  11125. t['icaron'] = 0x01D0;
  11126. t['icircle'] = 0x24D8;
  11127. t['icircumflex'] = 0x00EE;
  11128. t['icyrillic'] = 0x0456;
  11129. t['idblgrave'] = 0x0209;
  11130. t['ideographearthcircle'] = 0x328F;
  11131. t['ideographfirecircle'] = 0x328B;
  11132. t['ideographicallianceparen'] = 0x323F;
  11133. t['ideographiccallparen'] = 0x323A;
  11134. t['ideographiccentrecircle'] = 0x32A5;
  11135. t['ideographicclose'] = 0x3006;
  11136. t['ideographiccomma'] = 0x3001;
  11137. t['ideographiccommaleft'] = 0xFF64;
  11138. t['ideographiccongratulationparen'] = 0x3237;
  11139. t['ideographiccorrectcircle'] = 0x32A3;
  11140. t['ideographicearthparen'] = 0x322F;
  11141. t['ideographicenterpriseparen'] = 0x323D;
  11142. t['ideographicexcellentcircle'] = 0x329D;
  11143. t['ideographicfestivalparen'] = 0x3240;
  11144. t['ideographicfinancialcircle'] = 0x3296;
  11145. t['ideographicfinancialparen'] = 0x3236;
  11146. t['ideographicfireparen'] = 0x322B;
  11147. t['ideographichaveparen'] = 0x3232;
  11148. t['ideographichighcircle'] = 0x32A4;
  11149. t['ideographiciterationmark'] = 0x3005;
  11150. t['ideographiclaborcircle'] = 0x3298;
  11151. t['ideographiclaborparen'] = 0x3238;
  11152. t['ideographicleftcircle'] = 0x32A7;
  11153. t['ideographiclowcircle'] = 0x32A6;
  11154. t['ideographicmedicinecircle'] = 0x32A9;
  11155. t['ideographicmetalparen'] = 0x322E;
  11156. t['ideographicmoonparen'] = 0x322A;
  11157. t['ideographicnameparen'] = 0x3234;
  11158. t['ideographicperiod'] = 0x3002;
  11159. t['ideographicprintcircle'] = 0x329E;
  11160. t['ideographicreachparen'] = 0x3243;
  11161. t['ideographicrepresentparen'] = 0x3239;
  11162. t['ideographicresourceparen'] = 0x323E;
  11163. t['ideographicrightcircle'] = 0x32A8;
  11164. t['ideographicsecretcircle'] = 0x3299;
  11165. t['ideographicselfparen'] = 0x3242;
  11166. t['ideographicsocietyparen'] = 0x3233;
  11167. t['ideographicspace'] = 0x3000;
  11168. t['ideographicspecialparen'] = 0x3235;
  11169. t['ideographicstockparen'] = 0x3231;
  11170. t['ideographicstudyparen'] = 0x323B;
  11171. t['ideographicsunparen'] = 0x3230;
  11172. t['ideographicsuperviseparen'] = 0x323C;
  11173. t['ideographicwaterparen'] = 0x322C;
  11174. t['ideographicwoodparen'] = 0x322D;
  11175. t['ideographiczero'] = 0x3007;
  11176. t['ideographmetalcircle'] = 0x328E;
  11177. t['ideographmooncircle'] = 0x328A;
  11178. t['ideographnamecircle'] = 0x3294;
  11179. t['ideographsuncircle'] = 0x3290;
  11180. t['ideographwatercircle'] = 0x328C;
  11181. t['ideographwoodcircle'] = 0x328D;
  11182. t['ideva'] = 0x0907;
  11183. t['idieresis'] = 0x00EF;
  11184. t['idieresisacute'] = 0x1E2F;
  11185. t['idieresiscyrillic'] = 0x04E5;
  11186. t['idotbelow'] = 0x1ECB;
  11187. t['iebrevecyrillic'] = 0x04D7;
  11188. t['iecyrillic'] = 0x0435;
  11189. t['ieungacirclekorean'] = 0x3275;
  11190. t['ieungaparenkorean'] = 0x3215;
  11191. t['ieungcirclekorean'] = 0x3267;
  11192. t['ieungkorean'] = 0x3147;
  11193. t['ieungparenkorean'] = 0x3207;
  11194. t['igrave'] = 0x00EC;
  11195. t['igujarati'] = 0x0A87;
  11196. t['igurmukhi'] = 0x0A07;
  11197. t['ihiragana'] = 0x3044;
  11198. t['ihookabove'] = 0x1EC9;
  11199. t['iibengali'] = 0x0988;
  11200. t['iicyrillic'] = 0x0438;
  11201. t['iideva'] = 0x0908;
  11202. t['iigujarati'] = 0x0A88;
  11203. t['iigurmukhi'] = 0x0A08;
  11204. t['iimatragurmukhi'] = 0x0A40;
  11205. t['iinvertedbreve'] = 0x020B;
  11206. t['iishortcyrillic'] = 0x0439;
  11207. t['iivowelsignbengali'] = 0x09C0;
  11208. t['iivowelsigndeva'] = 0x0940;
  11209. t['iivowelsigngujarati'] = 0x0AC0;
  11210. t['ij'] = 0x0133;
  11211. t['ikatakana'] = 0x30A4;
  11212. t['ikatakanahalfwidth'] = 0xFF72;
  11213. t['ikorean'] = 0x3163;
  11214. t['ilde'] = 0x02DC;
  11215. t['iluyhebrew'] = 0x05AC;
  11216. t['imacron'] = 0x012B;
  11217. t['imacroncyrillic'] = 0x04E3;
  11218. t['imageorapproximatelyequal'] = 0x2253;
  11219. t['imatragurmukhi'] = 0x0A3F;
  11220. t['imonospace'] = 0xFF49;
  11221. t['increment'] = 0x2206;
  11222. t['infinity'] = 0x221E;
  11223. t['iniarmenian'] = 0x056B;
  11224. t['integral'] = 0x222B;
  11225. t['integralbottom'] = 0x2321;
  11226. t['integralbt'] = 0x2321;
  11227. t['integralex'] = 0xF8F5;
  11228. t['integraltop'] = 0x2320;
  11229. t['integraltp'] = 0x2320;
  11230. t['intersection'] = 0x2229;
  11231. t['intisquare'] = 0x3305;
  11232. t['invbullet'] = 0x25D8;
  11233. t['invcircle'] = 0x25D9;
  11234. t['invsmileface'] = 0x263B;
  11235. t['iocyrillic'] = 0x0451;
  11236. t['iogonek'] = 0x012F;
  11237. t['iota'] = 0x03B9;
  11238. t['iotadieresis'] = 0x03CA;
  11239. t['iotadieresistonos'] = 0x0390;
  11240. t['iotalatin'] = 0x0269;
  11241. t['iotatonos'] = 0x03AF;
  11242. t['iparen'] = 0x24A4;
  11243. t['irigurmukhi'] = 0x0A72;
  11244. t['ismallhiragana'] = 0x3043;
  11245. t['ismallkatakana'] = 0x30A3;
  11246. t['ismallkatakanahalfwidth'] = 0xFF68;
  11247. t['issharbengali'] = 0x09FA;
  11248. t['istroke'] = 0x0268;
  11249. t['isuperior'] = 0xF6ED;
  11250. t['iterationhiragana'] = 0x309D;
  11251. t['iterationkatakana'] = 0x30FD;
  11252. t['itilde'] = 0x0129;
  11253. t['itildebelow'] = 0x1E2D;
  11254. t['iubopomofo'] = 0x3129;
  11255. t['iucyrillic'] = 0x044E;
  11256. t['ivowelsignbengali'] = 0x09BF;
  11257. t['ivowelsigndeva'] = 0x093F;
  11258. t['ivowelsigngujarati'] = 0x0ABF;
  11259. t['izhitsacyrillic'] = 0x0475;
  11260. t['izhitsadblgravecyrillic'] = 0x0477;
  11261. t['j'] = 0x006A;
  11262. t['jaarmenian'] = 0x0571;
  11263. t['jabengali'] = 0x099C;
  11264. t['jadeva'] = 0x091C;
  11265. t['jagujarati'] = 0x0A9C;
  11266. t['jagurmukhi'] = 0x0A1C;
  11267. t['jbopomofo'] = 0x3110;
  11268. t['jcaron'] = 0x01F0;
  11269. t['jcircle'] = 0x24D9;
  11270. t['jcircumflex'] = 0x0135;
  11271. t['jcrossedtail'] = 0x029D;
  11272. t['jdotlessstroke'] = 0x025F;
  11273. t['jecyrillic'] = 0x0458;
  11274. t['jeemarabic'] = 0x062C;
  11275. t['jeemfinalarabic'] = 0xFE9E;
  11276. t['jeeminitialarabic'] = 0xFE9F;
  11277. t['jeemmedialarabic'] = 0xFEA0;
  11278. t['jeharabic'] = 0x0698;
  11279. t['jehfinalarabic'] = 0xFB8B;
  11280. t['jhabengali'] = 0x099D;
  11281. t['jhadeva'] = 0x091D;
  11282. t['jhagujarati'] = 0x0A9D;
  11283. t['jhagurmukhi'] = 0x0A1D;
  11284. t['jheharmenian'] = 0x057B;
  11285. t['jis'] = 0x3004;
  11286. t['jmonospace'] = 0xFF4A;
  11287. t['jparen'] = 0x24A5;
  11288. t['jsuperior'] = 0x02B2;
  11289. t['k'] = 0x006B;
  11290. t['kabashkircyrillic'] = 0x04A1;
  11291. t['kabengali'] = 0x0995;
  11292. t['kacute'] = 0x1E31;
  11293. t['kacyrillic'] = 0x043A;
  11294. t['kadescendercyrillic'] = 0x049B;
  11295. t['kadeva'] = 0x0915;
  11296. t['kaf'] = 0x05DB;
  11297. t['kafarabic'] = 0x0643;
  11298. t['kafdagesh'] = 0xFB3B;
  11299. t['kafdageshhebrew'] = 0xFB3B;
  11300. t['kaffinalarabic'] = 0xFEDA;
  11301. t['kafhebrew'] = 0x05DB;
  11302. t['kafinitialarabic'] = 0xFEDB;
  11303. t['kafmedialarabic'] = 0xFEDC;
  11304. t['kafrafehebrew'] = 0xFB4D;
  11305. t['kagujarati'] = 0x0A95;
  11306. t['kagurmukhi'] = 0x0A15;
  11307. t['kahiragana'] = 0x304B;
  11308. t['kahookcyrillic'] = 0x04C4;
  11309. t['kakatakana'] = 0x30AB;
  11310. t['kakatakanahalfwidth'] = 0xFF76;
  11311. t['kappa'] = 0x03BA;
  11312. t['kappasymbolgreek'] = 0x03F0;
  11313. t['kapyeounmieumkorean'] = 0x3171;
  11314. t['kapyeounphieuphkorean'] = 0x3184;
  11315. t['kapyeounpieupkorean'] = 0x3178;
  11316. t['kapyeounssangpieupkorean'] = 0x3179;
  11317. t['karoriisquare'] = 0x330D;
  11318. t['kashidaautoarabic'] = 0x0640;
  11319. t['kashidaautonosidebearingarabic'] = 0x0640;
  11320. t['kasmallkatakana'] = 0x30F5;
  11321. t['kasquare'] = 0x3384;
  11322. t['kasraarabic'] = 0x0650;
  11323. t['kasratanarabic'] = 0x064D;
  11324. t['kastrokecyrillic'] = 0x049F;
  11325. t['katahiraprolongmarkhalfwidth'] = 0xFF70;
  11326. t['kaverticalstrokecyrillic'] = 0x049D;
  11327. t['kbopomofo'] = 0x310E;
  11328. t['kcalsquare'] = 0x3389;
  11329. t['kcaron'] = 0x01E9;
  11330. t['kcedilla'] = 0x0137;
  11331. t['kcircle'] = 0x24DA;
  11332. t['kcommaaccent'] = 0x0137;
  11333. t['kdotbelow'] = 0x1E33;
  11334. t['keharmenian'] = 0x0584;
  11335. t['kehiragana'] = 0x3051;
  11336. t['kekatakana'] = 0x30B1;
  11337. t['kekatakanahalfwidth'] = 0xFF79;
  11338. t['kenarmenian'] = 0x056F;
  11339. t['kesmallkatakana'] = 0x30F6;
  11340. t['kgreenlandic'] = 0x0138;
  11341. t['khabengali'] = 0x0996;
  11342. t['khacyrillic'] = 0x0445;
  11343. t['khadeva'] = 0x0916;
  11344. t['khagujarati'] = 0x0A96;
  11345. t['khagurmukhi'] = 0x0A16;
  11346. t['khaharabic'] = 0x062E;
  11347. t['khahfinalarabic'] = 0xFEA6;
  11348. t['khahinitialarabic'] = 0xFEA7;
  11349. t['khahmedialarabic'] = 0xFEA8;
  11350. t['kheicoptic'] = 0x03E7;
  11351. t['khhadeva'] = 0x0959;
  11352. t['khhagurmukhi'] = 0x0A59;
  11353. t['khieukhacirclekorean'] = 0x3278;
  11354. t['khieukhaparenkorean'] = 0x3218;
  11355. t['khieukhcirclekorean'] = 0x326A;
  11356. t['khieukhkorean'] = 0x314B;
  11357. t['khieukhparenkorean'] = 0x320A;
  11358. t['khokhaithai'] = 0x0E02;
  11359. t['khokhonthai'] = 0x0E05;
  11360. t['khokhuatthai'] = 0x0E03;
  11361. t['khokhwaithai'] = 0x0E04;
  11362. t['khomutthai'] = 0x0E5B;
  11363. t['khook'] = 0x0199;
  11364. t['khorakhangthai'] = 0x0E06;
  11365. t['khzsquare'] = 0x3391;
  11366. t['kihiragana'] = 0x304D;
  11367. t['kikatakana'] = 0x30AD;
  11368. t['kikatakanahalfwidth'] = 0xFF77;
  11369. t['kiroguramusquare'] = 0x3315;
  11370. t['kiromeetorusquare'] = 0x3316;
  11371. t['kirosquare'] = 0x3314;
  11372. t['kiyeokacirclekorean'] = 0x326E;
  11373. t['kiyeokaparenkorean'] = 0x320E;
  11374. t['kiyeokcirclekorean'] = 0x3260;
  11375. t['kiyeokkorean'] = 0x3131;
  11376. t['kiyeokparenkorean'] = 0x3200;
  11377. t['kiyeoksioskorean'] = 0x3133;
  11378. t['kjecyrillic'] = 0x045C;
  11379. t['klinebelow'] = 0x1E35;
  11380. t['klsquare'] = 0x3398;
  11381. t['kmcubedsquare'] = 0x33A6;
  11382. t['kmonospace'] = 0xFF4B;
  11383. t['kmsquaredsquare'] = 0x33A2;
  11384. t['kohiragana'] = 0x3053;
  11385. t['kohmsquare'] = 0x33C0;
  11386. t['kokaithai'] = 0x0E01;
  11387. t['kokatakana'] = 0x30B3;
  11388. t['kokatakanahalfwidth'] = 0xFF7A;
  11389. t['kooposquare'] = 0x331E;
  11390. t['koppacyrillic'] = 0x0481;
  11391. t['koreanstandardsymbol'] = 0x327F;
  11392. t['koroniscmb'] = 0x0343;
  11393. t['kparen'] = 0x24A6;
  11394. t['kpasquare'] = 0x33AA;
  11395. t['ksicyrillic'] = 0x046F;
  11396. t['ktsquare'] = 0x33CF;
  11397. t['kturned'] = 0x029E;
  11398. t['kuhiragana'] = 0x304F;
  11399. t['kukatakana'] = 0x30AF;
  11400. t['kukatakanahalfwidth'] = 0xFF78;
  11401. t['kvsquare'] = 0x33B8;
  11402. t['kwsquare'] = 0x33BE;
  11403. t['l'] = 0x006C;
  11404. t['labengali'] = 0x09B2;
  11405. t['lacute'] = 0x013A;
  11406. t['ladeva'] = 0x0932;
  11407. t['lagujarati'] = 0x0AB2;
  11408. t['lagurmukhi'] = 0x0A32;
  11409. t['lakkhangyaothai'] = 0x0E45;
  11410. t['lamaleffinalarabic'] = 0xFEFC;
  11411. t['lamalefhamzaabovefinalarabic'] = 0xFEF8;
  11412. t['lamalefhamzaaboveisolatedarabic'] = 0xFEF7;
  11413. t['lamalefhamzabelowfinalarabic'] = 0xFEFA;
  11414. t['lamalefhamzabelowisolatedarabic'] = 0xFEF9;
  11415. t['lamalefisolatedarabic'] = 0xFEFB;
  11416. t['lamalefmaddaabovefinalarabic'] = 0xFEF6;
  11417. t['lamalefmaddaaboveisolatedarabic'] = 0xFEF5;
  11418. t['lamarabic'] = 0x0644;
  11419. t['lambda'] = 0x03BB;
  11420. t['lambdastroke'] = 0x019B;
  11421. t['lamed'] = 0x05DC;
  11422. t['lameddagesh'] = 0xFB3C;
  11423. t['lameddageshhebrew'] = 0xFB3C;
  11424. t['lamedhebrew'] = 0x05DC;
  11425. t['lamfinalarabic'] = 0xFEDE;
  11426. t['lamhahinitialarabic'] = 0xFCCA;
  11427. t['laminitialarabic'] = 0xFEDF;
  11428. t['lamjeeminitialarabic'] = 0xFCC9;
  11429. t['lamkhahinitialarabic'] = 0xFCCB;
  11430. t['lamlamhehisolatedarabic'] = 0xFDF2;
  11431. t['lammedialarabic'] = 0xFEE0;
  11432. t['lammeemhahinitialarabic'] = 0xFD88;
  11433. t['lammeeminitialarabic'] = 0xFCCC;
  11434. t['largecircle'] = 0x25EF;
  11435. t['lbar'] = 0x019A;
  11436. t['lbelt'] = 0x026C;
  11437. t['lbopomofo'] = 0x310C;
  11438. t['lcaron'] = 0x013E;
  11439. t['lcedilla'] = 0x013C;
  11440. t['lcircle'] = 0x24DB;
  11441. t['lcircumflexbelow'] = 0x1E3D;
  11442. t['lcommaaccent'] = 0x013C;
  11443. t['ldot'] = 0x0140;
  11444. t['ldotaccent'] = 0x0140;
  11445. t['ldotbelow'] = 0x1E37;
  11446. t['ldotbelowmacron'] = 0x1E39;
  11447. t['leftangleabovecmb'] = 0x031A;
  11448. t['lefttackbelowcmb'] = 0x0318;
  11449. t['less'] = 0x003C;
  11450. t['lessequal'] = 0x2264;
  11451. t['lessequalorgreater'] = 0x22DA;
  11452. t['lessmonospace'] = 0xFF1C;
  11453. t['lessorequivalent'] = 0x2272;
  11454. t['lessorgreater'] = 0x2276;
  11455. t['lessoverequal'] = 0x2266;
  11456. t['lesssmall'] = 0xFE64;
  11457. t['lezh'] = 0x026E;
  11458. t['lfblock'] = 0x258C;
  11459. t['lhookretroflex'] = 0x026D;
  11460. t['lira'] = 0x20A4;
  11461. t['liwnarmenian'] = 0x056C;
  11462. t['lj'] = 0x01C9;
  11463. t['ljecyrillic'] = 0x0459;
  11464. t['ll'] = 0xF6C0;
  11465. t['lladeva'] = 0x0933;
  11466. t['llagujarati'] = 0x0AB3;
  11467. t['llinebelow'] = 0x1E3B;
  11468. t['llladeva'] = 0x0934;
  11469. t['llvocalicbengali'] = 0x09E1;
  11470. t['llvocalicdeva'] = 0x0961;
  11471. t['llvocalicvowelsignbengali'] = 0x09E3;
  11472. t['llvocalicvowelsigndeva'] = 0x0963;
  11473. t['lmiddletilde'] = 0x026B;
  11474. t['lmonospace'] = 0xFF4C;
  11475. t['lmsquare'] = 0x33D0;
  11476. t['lochulathai'] = 0x0E2C;
  11477. t['logicaland'] = 0x2227;
  11478. t['logicalnot'] = 0x00AC;
  11479. t['logicalnotreversed'] = 0x2310;
  11480. t['logicalor'] = 0x2228;
  11481. t['lolingthai'] = 0x0E25;
  11482. t['longs'] = 0x017F;
  11483. t['lowlinecenterline'] = 0xFE4E;
  11484. t['lowlinecmb'] = 0x0332;
  11485. t['lowlinedashed'] = 0xFE4D;
  11486. t['lozenge'] = 0x25CA;
  11487. t['lparen'] = 0x24A7;
  11488. t['lslash'] = 0x0142;
  11489. t['lsquare'] = 0x2113;
  11490. t['lsuperior'] = 0xF6EE;
  11491. t['ltshade'] = 0x2591;
  11492. t['luthai'] = 0x0E26;
  11493. t['lvocalicbengali'] = 0x098C;
  11494. t['lvocalicdeva'] = 0x090C;
  11495. t['lvocalicvowelsignbengali'] = 0x09E2;
  11496. t['lvocalicvowelsigndeva'] = 0x0962;
  11497. t['lxsquare'] = 0x33D3;
  11498. t['m'] = 0x006D;
  11499. t['mabengali'] = 0x09AE;
  11500. t['macron'] = 0x00AF;
  11501. t['macronbelowcmb'] = 0x0331;
  11502. t['macroncmb'] = 0x0304;
  11503. t['macronlowmod'] = 0x02CD;
  11504. t['macronmonospace'] = 0xFFE3;
  11505. t['macute'] = 0x1E3F;
  11506. t['madeva'] = 0x092E;
  11507. t['magujarati'] = 0x0AAE;
  11508. t['magurmukhi'] = 0x0A2E;
  11509. t['mahapakhhebrew'] = 0x05A4;
  11510. t['mahapakhlefthebrew'] = 0x05A4;
  11511. t['mahiragana'] = 0x307E;
  11512. t['maichattawalowleftthai'] = 0xF895;
  11513. t['maichattawalowrightthai'] = 0xF894;
  11514. t['maichattawathai'] = 0x0E4B;
  11515. t['maichattawaupperleftthai'] = 0xF893;
  11516. t['maieklowleftthai'] = 0xF88C;
  11517. t['maieklowrightthai'] = 0xF88B;
  11518. t['maiekthai'] = 0x0E48;
  11519. t['maiekupperleftthai'] = 0xF88A;
  11520. t['maihanakatleftthai'] = 0xF884;
  11521. t['maihanakatthai'] = 0x0E31;
  11522. t['maitaikhuleftthai'] = 0xF889;
  11523. t['maitaikhuthai'] = 0x0E47;
  11524. t['maitholowleftthai'] = 0xF88F;
  11525. t['maitholowrightthai'] = 0xF88E;
  11526. t['maithothai'] = 0x0E49;
  11527. t['maithoupperleftthai'] = 0xF88D;
  11528. t['maitrilowleftthai'] = 0xF892;
  11529. t['maitrilowrightthai'] = 0xF891;
  11530. t['maitrithai'] = 0x0E4A;
  11531. t['maitriupperleftthai'] = 0xF890;
  11532. t['maiyamokthai'] = 0x0E46;
  11533. t['makatakana'] = 0x30DE;
  11534. t['makatakanahalfwidth'] = 0xFF8F;
  11535. t['male'] = 0x2642;
  11536. t['mansyonsquare'] = 0x3347;
  11537. t['maqafhebrew'] = 0x05BE;
  11538. t['mars'] = 0x2642;
  11539. t['masoracirclehebrew'] = 0x05AF;
  11540. t['masquare'] = 0x3383;
  11541. t['mbopomofo'] = 0x3107;
  11542. t['mbsquare'] = 0x33D4;
  11543. t['mcircle'] = 0x24DC;
  11544. t['mcubedsquare'] = 0x33A5;
  11545. t['mdotaccent'] = 0x1E41;
  11546. t['mdotbelow'] = 0x1E43;
  11547. t['meemarabic'] = 0x0645;
  11548. t['meemfinalarabic'] = 0xFEE2;
  11549. t['meeminitialarabic'] = 0xFEE3;
  11550. t['meemmedialarabic'] = 0xFEE4;
  11551. t['meemmeeminitialarabic'] = 0xFCD1;
  11552. t['meemmeemisolatedarabic'] = 0xFC48;
  11553. t['meetorusquare'] = 0x334D;
  11554. t['mehiragana'] = 0x3081;
  11555. t['meizierasquare'] = 0x337E;
  11556. t['mekatakana'] = 0x30E1;
  11557. t['mekatakanahalfwidth'] = 0xFF92;
  11558. t['mem'] = 0x05DE;
  11559. t['memdagesh'] = 0xFB3E;
  11560. t['memdageshhebrew'] = 0xFB3E;
  11561. t['memhebrew'] = 0x05DE;
  11562. t['menarmenian'] = 0x0574;
  11563. t['merkhahebrew'] = 0x05A5;
  11564. t['merkhakefulahebrew'] = 0x05A6;
  11565. t['merkhakefulalefthebrew'] = 0x05A6;
  11566. t['merkhalefthebrew'] = 0x05A5;
  11567. t['mhook'] = 0x0271;
  11568. t['mhzsquare'] = 0x3392;
  11569. t['middledotkatakanahalfwidth'] = 0xFF65;
  11570. t['middot'] = 0x00B7;
  11571. t['mieumacirclekorean'] = 0x3272;
  11572. t['mieumaparenkorean'] = 0x3212;
  11573. t['mieumcirclekorean'] = 0x3264;
  11574. t['mieumkorean'] = 0x3141;
  11575. t['mieumpansioskorean'] = 0x3170;
  11576. t['mieumparenkorean'] = 0x3204;
  11577. t['mieumpieupkorean'] = 0x316E;
  11578. t['mieumsioskorean'] = 0x316F;
  11579. t['mihiragana'] = 0x307F;
  11580. t['mikatakana'] = 0x30DF;
  11581. t['mikatakanahalfwidth'] = 0xFF90;
  11582. t['minus'] = 0x2212;
  11583. t['minusbelowcmb'] = 0x0320;
  11584. t['minuscircle'] = 0x2296;
  11585. t['minusmod'] = 0x02D7;
  11586. t['minusplus'] = 0x2213;
  11587. t['minute'] = 0x2032;
  11588. t['miribaarusquare'] = 0x334A;
  11589. t['mirisquare'] = 0x3349;
  11590. t['mlonglegturned'] = 0x0270;
  11591. t['mlsquare'] = 0x3396;
  11592. t['mmcubedsquare'] = 0x33A3;
  11593. t['mmonospace'] = 0xFF4D;
  11594. t['mmsquaredsquare'] = 0x339F;
  11595. t['mohiragana'] = 0x3082;
  11596. t['mohmsquare'] = 0x33C1;
  11597. t['mokatakana'] = 0x30E2;
  11598. t['mokatakanahalfwidth'] = 0xFF93;
  11599. t['molsquare'] = 0x33D6;
  11600. t['momathai'] = 0x0E21;
  11601. t['moverssquare'] = 0x33A7;
  11602. t['moverssquaredsquare'] = 0x33A8;
  11603. t['mparen'] = 0x24A8;
  11604. t['mpasquare'] = 0x33AB;
  11605. t['mssquare'] = 0x33B3;
  11606. t['msuperior'] = 0xF6EF;
  11607. t['mturned'] = 0x026F;
  11608. t['mu'] = 0x00B5;
  11609. t['mu1'] = 0x00B5;
  11610. t['muasquare'] = 0x3382;
  11611. t['muchgreater'] = 0x226B;
  11612. t['muchless'] = 0x226A;
  11613. t['mufsquare'] = 0x338C;
  11614. t['mugreek'] = 0x03BC;
  11615. t['mugsquare'] = 0x338D;
  11616. t['muhiragana'] = 0x3080;
  11617. t['mukatakana'] = 0x30E0;
  11618. t['mukatakanahalfwidth'] = 0xFF91;
  11619. t['mulsquare'] = 0x3395;
  11620. t['multiply'] = 0x00D7;
  11621. t['mumsquare'] = 0x339B;
  11622. t['munahhebrew'] = 0x05A3;
  11623. t['munahlefthebrew'] = 0x05A3;
  11624. t['musicalnote'] = 0x266A;
  11625. t['musicalnotedbl'] = 0x266B;
  11626. t['musicflatsign'] = 0x266D;
  11627. t['musicsharpsign'] = 0x266F;
  11628. t['mussquare'] = 0x33B2;
  11629. t['muvsquare'] = 0x33B6;
  11630. t['muwsquare'] = 0x33BC;
  11631. t['mvmegasquare'] = 0x33B9;
  11632. t['mvsquare'] = 0x33B7;
  11633. t['mwmegasquare'] = 0x33BF;
  11634. t['mwsquare'] = 0x33BD;
  11635. t['n'] = 0x006E;
  11636. t['nabengali'] = 0x09A8;
  11637. t['nabla'] = 0x2207;
  11638. t['nacute'] = 0x0144;
  11639. t['nadeva'] = 0x0928;
  11640. t['nagujarati'] = 0x0AA8;
  11641. t['nagurmukhi'] = 0x0A28;
  11642. t['nahiragana'] = 0x306A;
  11643. t['nakatakana'] = 0x30CA;
  11644. t['nakatakanahalfwidth'] = 0xFF85;
  11645. t['napostrophe'] = 0x0149;
  11646. t['nasquare'] = 0x3381;
  11647. t['nbopomofo'] = 0x310B;
  11648. t['nbspace'] = 0x00A0;
  11649. t['ncaron'] = 0x0148;
  11650. t['ncedilla'] = 0x0146;
  11651. t['ncircle'] = 0x24DD;
  11652. t['ncircumflexbelow'] = 0x1E4B;
  11653. t['ncommaaccent'] = 0x0146;
  11654. t['ndotaccent'] = 0x1E45;
  11655. t['ndotbelow'] = 0x1E47;
  11656. t['nehiragana'] = 0x306D;
  11657. t['nekatakana'] = 0x30CD;
  11658. t['nekatakanahalfwidth'] = 0xFF88;
  11659. t['newsheqelsign'] = 0x20AA;
  11660. t['nfsquare'] = 0x338B;
  11661. t['ngabengali'] = 0x0999;
  11662. t['ngadeva'] = 0x0919;
  11663. t['ngagujarati'] = 0x0A99;
  11664. t['ngagurmukhi'] = 0x0A19;
  11665. t['ngonguthai'] = 0x0E07;
  11666. t['nhiragana'] = 0x3093;
  11667. t['nhookleft'] = 0x0272;
  11668. t['nhookretroflex'] = 0x0273;
  11669. t['nieunacirclekorean'] = 0x326F;
  11670. t['nieunaparenkorean'] = 0x320F;
  11671. t['nieuncieuckorean'] = 0x3135;
  11672. t['nieuncirclekorean'] = 0x3261;
  11673. t['nieunhieuhkorean'] = 0x3136;
  11674. t['nieunkorean'] = 0x3134;
  11675. t['nieunpansioskorean'] = 0x3168;
  11676. t['nieunparenkorean'] = 0x3201;
  11677. t['nieunsioskorean'] = 0x3167;
  11678. t['nieuntikeutkorean'] = 0x3166;
  11679. t['nihiragana'] = 0x306B;
  11680. t['nikatakana'] = 0x30CB;
  11681. t['nikatakanahalfwidth'] = 0xFF86;
  11682. t['nikhahitleftthai'] = 0xF899;
  11683. t['nikhahitthai'] = 0x0E4D;
  11684. t['nine'] = 0x0039;
  11685. t['ninearabic'] = 0x0669;
  11686. t['ninebengali'] = 0x09EF;
  11687. t['ninecircle'] = 0x2468;
  11688. t['ninecircleinversesansserif'] = 0x2792;
  11689. t['ninedeva'] = 0x096F;
  11690. t['ninegujarati'] = 0x0AEF;
  11691. t['ninegurmukhi'] = 0x0A6F;
  11692. t['ninehackarabic'] = 0x0669;
  11693. t['ninehangzhou'] = 0x3029;
  11694. t['nineideographicparen'] = 0x3228;
  11695. t['nineinferior'] = 0x2089;
  11696. t['ninemonospace'] = 0xFF19;
  11697. t['nineoldstyle'] = 0xF739;
  11698. t['nineparen'] = 0x247C;
  11699. t['nineperiod'] = 0x2490;
  11700. t['ninepersian'] = 0x06F9;
  11701. t['nineroman'] = 0x2178;
  11702. t['ninesuperior'] = 0x2079;
  11703. t['nineteencircle'] = 0x2472;
  11704. t['nineteenparen'] = 0x2486;
  11705. t['nineteenperiod'] = 0x249A;
  11706. t['ninethai'] = 0x0E59;
  11707. t['nj'] = 0x01CC;
  11708. t['njecyrillic'] = 0x045A;
  11709. t['nkatakana'] = 0x30F3;
  11710. t['nkatakanahalfwidth'] = 0xFF9D;
  11711. t['nlegrightlong'] = 0x019E;
  11712. t['nlinebelow'] = 0x1E49;
  11713. t['nmonospace'] = 0xFF4E;
  11714. t['nmsquare'] = 0x339A;
  11715. t['nnabengali'] = 0x09A3;
  11716. t['nnadeva'] = 0x0923;
  11717. t['nnagujarati'] = 0x0AA3;
  11718. t['nnagurmukhi'] = 0x0A23;
  11719. t['nnnadeva'] = 0x0929;
  11720. t['nohiragana'] = 0x306E;
  11721. t['nokatakana'] = 0x30CE;
  11722. t['nokatakanahalfwidth'] = 0xFF89;
  11723. t['nonbreakingspace'] = 0x00A0;
  11724. t['nonenthai'] = 0x0E13;
  11725. t['nonuthai'] = 0x0E19;
  11726. t['noonarabic'] = 0x0646;
  11727. t['noonfinalarabic'] = 0xFEE6;
  11728. t['noonghunnaarabic'] = 0x06BA;
  11729. t['noonghunnafinalarabic'] = 0xFB9F;
  11730. t['nooninitialarabic'] = 0xFEE7;
  11731. t['noonjeeminitialarabic'] = 0xFCD2;
  11732. t['noonjeemisolatedarabic'] = 0xFC4B;
  11733. t['noonmedialarabic'] = 0xFEE8;
  11734. t['noonmeeminitialarabic'] = 0xFCD5;
  11735. t['noonmeemisolatedarabic'] = 0xFC4E;
  11736. t['noonnoonfinalarabic'] = 0xFC8D;
  11737. t['notcontains'] = 0x220C;
  11738. t['notelement'] = 0x2209;
  11739. t['notelementof'] = 0x2209;
  11740. t['notequal'] = 0x2260;
  11741. t['notgreater'] = 0x226F;
  11742. t['notgreaternorequal'] = 0x2271;
  11743. t['notgreaternorless'] = 0x2279;
  11744. t['notidentical'] = 0x2262;
  11745. t['notless'] = 0x226E;
  11746. t['notlessnorequal'] = 0x2270;
  11747. t['notparallel'] = 0x2226;
  11748. t['notprecedes'] = 0x2280;
  11749. t['notsubset'] = 0x2284;
  11750. t['notsucceeds'] = 0x2281;
  11751. t['notsuperset'] = 0x2285;
  11752. t['nowarmenian'] = 0x0576;
  11753. t['nparen'] = 0x24A9;
  11754. t['nssquare'] = 0x33B1;
  11755. t['nsuperior'] = 0x207F;
  11756. t['ntilde'] = 0x00F1;
  11757. t['nu'] = 0x03BD;
  11758. t['nuhiragana'] = 0x306C;
  11759. t['nukatakana'] = 0x30CC;
  11760. t['nukatakanahalfwidth'] = 0xFF87;
  11761. t['nuktabengali'] = 0x09BC;
  11762. t['nuktadeva'] = 0x093C;
  11763. t['nuktagujarati'] = 0x0ABC;
  11764. t['nuktagurmukhi'] = 0x0A3C;
  11765. t['numbersign'] = 0x0023;
  11766. t['numbersignmonospace'] = 0xFF03;
  11767. t['numbersignsmall'] = 0xFE5F;
  11768. t['numeralsigngreek'] = 0x0374;
  11769. t['numeralsignlowergreek'] = 0x0375;
  11770. t['numero'] = 0x2116;
  11771. t['nun'] = 0x05E0;
  11772. t['nundagesh'] = 0xFB40;
  11773. t['nundageshhebrew'] = 0xFB40;
  11774. t['nunhebrew'] = 0x05E0;
  11775. t['nvsquare'] = 0x33B5;
  11776. t['nwsquare'] = 0x33BB;
  11777. t['nyabengali'] = 0x099E;
  11778. t['nyadeva'] = 0x091E;
  11779. t['nyagujarati'] = 0x0A9E;
  11780. t['nyagurmukhi'] = 0x0A1E;
  11781. t['o'] = 0x006F;
  11782. t['oacute'] = 0x00F3;
  11783. t['oangthai'] = 0x0E2D;
  11784. t['obarred'] = 0x0275;
  11785. t['obarredcyrillic'] = 0x04E9;
  11786. t['obarreddieresiscyrillic'] = 0x04EB;
  11787. t['obengali'] = 0x0993;
  11788. t['obopomofo'] = 0x311B;
  11789. t['obreve'] = 0x014F;
  11790. t['ocandradeva'] = 0x0911;
  11791. t['ocandragujarati'] = 0x0A91;
  11792. t['ocandravowelsigndeva'] = 0x0949;
  11793. t['ocandravowelsigngujarati'] = 0x0AC9;
  11794. t['ocaron'] = 0x01D2;
  11795. t['ocircle'] = 0x24DE;
  11796. t['ocircumflex'] = 0x00F4;
  11797. t['ocircumflexacute'] = 0x1ED1;
  11798. t['ocircumflexdotbelow'] = 0x1ED9;
  11799. t['ocircumflexgrave'] = 0x1ED3;
  11800. t['ocircumflexhookabove'] = 0x1ED5;
  11801. t['ocircumflextilde'] = 0x1ED7;
  11802. t['ocyrillic'] = 0x043E;
  11803. t['odblacute'] = 0x0151;
  11804. t['odblgrave'] = 0x020D;
  11805. t['odeva'] = 0x0913;
  11806. t['odieresis'] = 0x00F6;
  11807. t['odieresiscyrillic'] = 0x04E7;
  11808. t['odotbelow'] = 0x1ECD;
  11809. t['oe'] = 0x0153;
  11810. t['oekorean'] = 0x315A;
  11811. t['ogonek'] = 0x02DB;
  11812. t['ogonekcmb'] = 0x0328;
  11813. t['ograve'] = 0x00F2;
  11814. t['ogujarati'] = 0x0A93;
  11815. t['oharmenian'] = 0x0585;
  11816. t['ohiragana'] = 0x304A;
  11817. t['ohookabove'] = 0x1ECF;
  11818. t['ohorn'] = 0x01A1;
  11819. t['ohornacute'] = 0x1EDB;
  11820. t['ohorndotbelow'] = 0x1EE3;
  11821. t['ohorngrave'] = 0x1EDD;
  11822. t['ohornhookabove'] = 0x1EDF;
  11823. t['ohorntilde'] = 0x1EE1;
  11824. t['ohungarumlaut'] = 0x0151;
  11825. t['oi'] = 0x01A3;
  11826. t['oinvertedbreve'] = 0x020F;
  11827. t['okatakana'] = 0x30AA;
  11828. t['okatakanahalfwidth'] = 0xFF75;
  11829. t['okorean'] = 0x3157;
  11830. t['olehebrew'] = 0x05AB;
  11831. t['omacron'] = 0x014D;
  11832. t['omacronacute'] = 0x1E53;
  11833. t['omacrongrave'] = 0x1E51;
  11834. t['omdeva'] = 0x0950;
  11835. t['omega'] = 0x03C9;
  11836. t['omega1'] = 0x03D6;
  11837. t['omegacyrillic'] = 0x0461;
  11838. t['omegalatinclosed'] = 0x0277;
  11839. t['omegaroundcyrillic'] = 0x047B;
  11840. t['omegatitlocyrillic'] = 0x047D;
  11841. t['omegatonos'] = 0x03CE;
  11842. t['omgujarati'] = 0x0AD0;
  11843. t['omicron'] = 0x03BF;
  11844. t['omicrontonos'] = 0x03CC;
  11845. t['omonospace'] = 0xFF4F;
  11846. t['one'] = 0x0031;
  11847. t['onearabic'] = 0x0661;
  11848. t['onebengali'] = 0x09E7;
  11849. t['onecircle'] = 0x2460;
  11850. t['onecircleinversesansserif'] = 0x278A;
  11851. t['onedeva'] = 0x0967;
  11852. t['onedotenleader'] = 0x2024;
  11853. t['oneeighth'] = 0x215B;
  11854. t['onefitted'] = 0xF6DC;
  11855. t['onegujarati'] = 0x0AE7;
  11856. t['onegurmukhi'] = 0x0A67;
  11857. t['onehackarabic'] = 0x0661;
  11858. t['onehalf'] = 0x00BD;
  11859. t['onehangzhou'] = 0x3021;
  11860. t['oneideographicparen'] = 0x3220;
  11861. t['oneinferior'] = 0x2081;
  11862. t['onemonospace'] = 0xFF11;
  11863. t['onenumeratorbengali'] = 0x09F4;
  11864. t['oneoldstyle'] = 0xF731;
  11865. t['oneparen'] = 0x2474;
  11866. t['oneperiod'] = 0x2488;
  11867. t['onepersian'] = 0x06F1;
  11868. t['onequarter'] = 0x00BC;
  11869. t['oneroman'] = 0x2170;
  11870. t['onesuperior'] = 0x00B9;
  11871. t['onethai'] = 0x0E51;
  11872. t['onethird'] = 0x2153;
  11873. t['oogonek'] = 0x01EB;
  11874. t['oogonekmacron'] = 0x01ED;
  11875. t['oogurmukhi'] = 0x0A13;
  11876. t['oomatragurmukhi'] = 0x0A4B;
  11877. t['oopen'] = 0x0254;
  11878. t['oparen'] = 0x24AA;
  11879. t['openbullet'] = 0x25E6;
  11880. t['option'] = 0x2325;
  11881. t['ordfeminine'] = 0x00AA;
  11882. t['ordmasculine'] = 0x00BA;
  11883. t['orthogonal'] = 0x221F;
  11884. t['oshortdeva'] = 0x0912;
  11885. t['oshortvowelsigndeva'] = 0x094A;
  11886. t['oslash'] = 0x00F8;
  11887. t['oslashacute'] = 0x01FF;
  11888. t['osmallhiragana'] = 0x3049;
  11889. t['osmallkatakana'] = 0x30A9;
  11890. t['osmallkatakanahalfwidth'] = 0xFF6B;
  11891. t['ostrokeacute'] = 0x01FF;
  11892. t['osuperior'] = 0xF6F0;
  11893. t['otcyrillic'] = 0x047F;
  11894. t['otilde'] = 0x00F5;
  11895. t['otildeacute'] = 0x1E4D;
  11896. t['otildedieresis'] = 0x1E4F;
  11897. t['oubopomofo'] = 0x3121;
  11898. t['overline'] = 0x203E;
  11899. t['overlinecenterline'] = 0xFE4A;
  11900. t['overlinecmb'] = 0x0305;
  11901. t['overlinedashed'] = 0xFE49;
  11902. t['overlinedblwavy'] = 0xFE4C;
  11903. t['overlinewavy'] = 0xFE4B;
  11904. t['overscore'] = 0x00AF;
  11905. t['ovowelsignbengali'] = 0x09CB;
  11906. t['ovowelsigndeva'] = 0x094B;
  11907. t['ovowelsigngujarati'] = 0x0ACB;
  11908. t['p'] = 0x0070;
  11909. t['paampssquare'] = 0x3380;
  11910. t['paasentosquare'] = 0x332B;
  11911. t['pabengali'] = 0x09AA;
  11912. t['pacute'] = 0x1E55;
  11913. t['padeva'] = 0x092A;
  11914. t['pagedown'] = 0x21DF;
  11915. t['pageup'] = 0x21DE;
  11916. t['pagujarati'] = 0x0AAA;
  11917. t['pagurmukhi'] = 0x0A2A;
  11918. t['pahiragana'] = 0x3071;
  11919. t['paiyannoithai'] = 0x0E2F;
  11920. t['pakatakana'] = 0x30D1;
  11921. t['palatalizationcyrilliccmb'] = 0x0484;
  11922. t['palochkacyrillic'] = 0x04C0;
  11923. t['pansioskorean'] = 0x317F;
  11924. t['paragraph'] = 0x00B6;
  11925. t['parallel'] = 0x2225;
  11926. t['parenleft'] = 0x0028;
  11927. t['parenleftaltonearabic'] = 0xFD3E;
  11928. t['parenleftbt'] = 0xF8ED;
  11929. t['parenleftex'] = 0xF8EC;
  11930. t['parenleftinferior'] = 0x208D;
  11931. t['parenleftmonospace'] = 0xFF08;
  11932. t['parenleftsmall'] = 0xFE59;
  11933. t['parenleftsuperior'] = 0x207D;
  11934. t['parenlefttp'] = 0xF8EB;
  11935. t['parenleftvertical'] = 0xFE35;
  11936. t['parenright'] = 0x0029;
  11937. t['parenrightaltonearabic'] = 0xFD3F;
  11938. t['parenrightbt'] = 0xF8F8;
  11939. t['parenrightex'] = 0xF8F7;
  11940. t['parenrightinferior'] = 0x208E;
  11941. t['parenrightmonospace'] = 0xFF09;
  11942. t['parenrightsmall'] = 0xFE5A;
  11943. t['parenrightsuperior'] = 0x207E;
  11944. t['parenrighttp'] = 0xF8F6;
  11945. t['parenrightvertical'] = 0xFE36;
  11946. t['partialdiff'] = 0x2202;
  11947. t['paseqhebrew'] = 0x05C0;
  11948. t['pashtahebrew'] = 0x0599;
  11949. t['pasquare'] = 0x33A9;
  11950. t['patah'] = 0x05B7;
  11951. t['patah11'] = 0x05B7;
  11952. t['patah1d'] = 0x05B7;
  11953. t['patah2a'] = 0x05B7;
  11954. t['patahhebrew'] = 0x05B7;
  11955. t['patahnarrowhebrew'] = 0x05B7;
  11956. t['patahquarterhebrew'] = 0x05B7;
  11957. t['patahwidehebrew'] = 0x05B7;
  11958. t['pazerhebrew'] = 0x05A1;
  11959. t['pbopomofo'] = 0x3106;
  11960. t['pcircle'] = 0x24DF;
  11961. t['pdotaccent'] = 0x1E57;
  11962. t['pe'] = 0x05E4;
  11963. t['pecyrillic'] = 0x043F;
  11964. t['pedagesh'] = 0xFB44;
  11965. t['pedageshhebrew'] = 0xFB44;
  11966. t['peezisquare'] = 0x333B;
  11967. t['pefinaldageshhebrew'] = 0xFB43;
  11968. t['peharabic'] = 0x067E;
  11969. t['peharmenian'] = 0x057A;
  11970. t['pehebrew'] = 0x05E4;
  11971. t['pehfinalarabic'] = 0xFB57;
  11972. t['pehinitialarabic'] = 0xFB58;
  11973. t['pehiragana'] = 0x307A;
  11974. t['pehmedialarabic'] = 0xFB59;
  11975. t['pekatakana'] = 0x30DA;
  11976. t['pemiddlehookcyrillic'] = 0x04A7;
  11977. t['perafehebrew'] = 0xFB4E;
  11978. t['percent'] = 0x0025;
  11979. t['percentarabic'] = 0x066A;
  11980. t['percentmonospace'] = 0xFF05;
  11981. t['percentsmall'] = 0xFE6A;
  11982. t['period'] = 0x002E;
  11983. t['periodarmenian'] = 0x0589;
  11984. t['periodcentered'] = 0x00B7;
  11985. t['periodhalfwidth'] = 0xFF61;
  11986. t['periodinferior'] = 0xF6E7;
  11987. t['periodmonospace'] = 0xFF0E;
  11988. t['periodsmall'] = 0xFE52;
  11989. t['periodsuperior'] = 0xF6E8;
  11990. t['perispomenigreekcmb'] = 0x0342;
  11991. t['perpendicular'] = 0x22A5;
  11992. t['perthousand'] = 0x2030;
  11993. t['peseta'] = 0x20A7;
  11994. t['pfsquare'] = 0x338A;
  11995. t['phabengali'] = 0x09AB;
  11996. t['phadeva'] = 0x092B;
  11997. t['phagujarati'] = 0x0AAB;
  11998. t['phagurmukhi'] = 0x0A2B;
  11999. t['phi'] = 0x03C6;
  12000. t['phi1'] = 0x03D5;
  12001. t['phieuphacirclekorean'] = 0x327A;
  12002. t['phieuphaparenkorean'] = 0x321A;
  12003. t['phieuphcirclekorean'] = 0x326C;
  12004. t['phieuphkorean'] = 0x314D;
  12005. t['phieuphparenkorean'] = 0x320C;
  12006. t['philatin'] = 0x0278;
  12007. t['phinthuthai'] = 0x0E3A;
  12008. t['phisymbolgreek'] = 0x03D5;
  12009. t['phook'] = 0x01A5;
  12010. t['phophanthai'] = 0x0E1E;
  12011. t['phophungthai'] = 0x0E1C;
  12012. t['phosamphaothai'] = 0x0E20;
  12013. t['pi'] = 0x03C0;
  12014. t['pieupacirclekorean'] = 0x3273;
  12015. t['pieupaparenkorean'] = 0x3213;
  12016. t['pieupcieuckorean'] = 0x3176;
  12017. t['pieupcirclekorean'] = 0x3265;
  12018. t['pieupkiyeokkorean'] = 0x3172;
  12019. t['pieupkorean'] = 0x3142;
  12020. t['pieupparenkorean'] = 0x3205;
  12021. t['pieupsioskiyeokkorean'] = 0x3174;
  12022. t['pieupsioskorean'] = 0x3144;
  12023. t['pieupsiostikeutkorean'] = 0x3175;
  12024. t['pieupthieuthkorean'] = 0x3177;
  12025. t['pieuptikeutkorean'] = 0x3173;
  12026. t['pihiragana'] = 0x3074;
  12027. t['pikatakana'] = 0x30D4;
  12028. t['pisymbolgreek'] = 0x03D6;
  12029. t['piwrarmenian'] = 0x0583;
  12030. t['plus'] = 0x002B;
  12031. t['plusbelowcmb'] = 0x031F;
  12032. t['pluscircle'] = 0x2295;
  12033. t['plusminus'] = 0x00B1;
  12034. t['plusmod'] = 0x02D6;
  12035. t['plusmonospace'] = 0xFF0B;
  12036. t['plussmall'] = 0xFE62;
  12037. t['plussuperior'] = 0x207A;
  12038. t['pmonospace'] = 0xFF50;
  12039. t['pmsquare'] = 0x33D8;
  12040. t['pohiragana'] = 0x307D;
  12041. t['pointingindexdownwhite'] = 0x261F;
  12042. t['pointingindexleftwhite'] = 0x261C;
  12043. t['pointingindexrightwhite'] = 0x261E;
  12044. t['pointingindexupwhite'] = 0x261D;
  12045. t['pokatakana'] = 0x30DD;
  12046. t['poplathai'] = 0x0E1B;
  12047. t['postalmark'] = 0x3012;
  12048. t['postalmarkface'] = 0x3020;
  12049. t['pparen'] = 0x24AB;
  12050. t['precedes'] = 0x227A;
  12051. t['prescription'] = 0x211E;
  12052. t['primemod'] = 0x02B9;
  12053. t['primereversed'] = 0x2035;
  12054. t['product'] = 0x220F;
  12055. t['projective'] = 0x2305;
  12056. t['prolongedkana'] = 0x30FC;
  12057. t['propellor'] = 0x2318;
  12058. t['propersubset'] = 0x2282;
  12059. t['propersuperset'] = 0x2283;
  12060. t['proportion'] = 0x2237;
  12061. t['proportional'] = 0x221D;
  12062. t['psi'] = 0x03C8;
  12063. t['psicyrillic'] = 0x0471;
  12064. t['psilipneumatacyrilliccmb'] = 0x0486;
  12065. t['pssquare'] = 0x33B0;
  12066. t['puhiragana'] = 0x3077;
  12067. t['pukatakana'] = 0x30D7;
  12068. t['pvsquare'] = 0x33B4;
  12069. t['pwsquare'] = 0x33BA;
  12070. t['q'] = 0x0071;
  12071. t['qadeva'] = 0x0958;
  12072. t['qadmahebrew'] = 0x05A8;
  12073. t['qafarabic'] = 0x0642;
  12074. t['qaffinalarabic'] = 0xFED6;
  12075. t['qafinitialarabic'] = 0xFED7;
  12076. t['qafmedialarabic'] = 0xFED8;
  12077. t['qamats'] = 0x05B8;
  12078. t['qamats10'] = 0x05B8;
  12079. t['qamats1a'] = 0x05B8;
  12080. t['qamats1c'] = 0x05B8;
  12081. t['qamats27'] = 0x05B8;
  12082. t['qamats29'] = 0x05B8;
  12083. t['qamats33'] = 0x05B8;
  12084. t['qamatsde'] = 0x05B8;
  12085. t['qamatshebrew'] = 0x05B8;
  12086. t['qamatsnarrowhebrew'] = 0x05B8;
  12087. t['qamatsqatanhebrew'] = 0x05B8;
  12088. t['qamatsqatannarrowhebrew'] = 0x05B8;
  12089. t['qamatsqatanquarterhebrew'] = 0x05B8;
  12090. t['qamatsqatanwidehebrew'] = 0x05B8;
  12091. t['qamatsquarterhebrew'] = 0x05B8;
  12092. t['qamatswidehebrew'] = 0x05B8;
  12093. t['qarneyparahebrew'] = 0x059F;
  12094. t['qbopomofo'] = 0x3111;
  12095. t['qcircle'] = 0x24E0;
  12096. t['qhook'] = 0x02A0;
  12097. t['qmonospace'] = 0xFF51;
  12098. t['qof'] = 0x05E7;
  12099. t['qofdagesh'] = 0xFB47;
  12100. t['qofdageshhebrew'] = 0xFB47;
  12101. t['qofhebrew'] = 0x05E7;
  12102. t['qparen'] = 0x24AC;
  12103. t['quarternote'] = 0x2669;
  12104. t['qubuts'] = 0x05BB;
  12105. t['qubuts18'] = 0x05BB;
  12106. t['qubuts25'] = 0x05BB;
  12107. t['qubuts31'] = 0x05BB;
  12108. t['qubutshebrew'] = 0x05BB;
  12109. t['qubutsnarrowhebrew'] = 0x05BB;
  12110. t['qubutsquarterhebrew'] = 0x05BB;
  12111. t['qubutswidehebrew'] = 0x05BB;
  12112. t['question'] = 0x003F;
  12113. t['questionarabic'] = 0x061F;
  12114. t['questionarmenian'] = 0x055E;
  12115. t['questiondown'] = 0x00BF;
  12116. t['questiondownsmall'] = 0xF7BF;
  12117. t['questiongreek'] = 0x037E;
  12118. t['questionmonospace'] = 0xFF1F;
  12119. t['questionsmall'] = 0xF73F;
  12120. t['quotedbl'] = 0x0022;
  12121. t['quotedblbase'] = 0x201E;
  12122. t['quotedblleft'] = 0x201C;
  12123. t['quotedblmonospace'] = 0xFF02;
  12124. t['quotedblprime'] = 0x301E;
  12125. t['quotedblprimereversed'] = 0x301D;
  12126. t['quotedblright'] = 0x201D;
  12127. t['quoteleft'] = 0x2018;
  12128. t['quoteleftreversed'] = 0x201B;
  12129. t['quotereversed'] = 0x201B;
  12130. t['quoteright'] = 0x2019;
  12131. t['quoterightn'] = 0x0149;
  12132. t['quotesinglbase'] = 0x201A;
  12133. t['quotesingle'] = 0x0027;
  12134. t['quotesinglemonospace'] = 0xFF07;
  12135. t['r'] = 0x0072;
  12136. t['raarmenian'] = 0x057C;
  12137. t['rabengali'] = 0x09B0;
  12138. t['racute'] = 0x0155;
  12139. t['radeva'] = 0x0930;
  12140. t['radical'] = 0x221A;
  12141. t['radicalex'] = 0xF8E5;
  12142. t['radoverssquare'] = 0x33AE;
  12143. t['radoverssquaredsquare'] = 0x33AF;
  12144. t['radsquare'] = 0x33AD;
  12145. t['rafe'] = 0x05BF;
  12146. t['rafehebrew'] = 0x05BF;
  12147. t['ragujarati'] = 0x0AB0;
  12148. t['ragurmukhi'] = 0x0A30;
  12149. t['rahiragana'] = 0x3089;
  12150. t['rakatakana'] = 0x30E9;
  12151. t['rakatakanahalfwidth'] = 0xFF97;
  12152. t['ralowerdiagonalbengali'] = 0x09F1;
  12153. t['ramiddlediagonalbengali'] = 0x09F0;
  12154. t['ramshorn'] = 0x0264;
  12155. t['ratio'] = 0x2236;
  12156. t['rbopomofo'] = 0x3116;
  12157. t['rcaron'] = 0x0159;
  12158. t['rcedilla'] = 0x0157;
  12159. t['rcircle'] = 0x24E1;
  12160. t['rcommaaccent'] = 0x0157;
  12161. t['rdblgrave'] = 0x0211;
  12162. t['rdotaccent'] = 0x1E59;
  12163. t['rdotbelow'] = 0x1E5B;
  12164. t['rdotbelowmacron'] = 0x1E5D;
  12165. t['referencemark'] = 0x203B;
  12166. t['reflexsubset'] = 0x2286;
  12167. t['reflexsuperset'] = 0x2287;
  12168. t['registered'] = 0x00AE;
  12169. t['registersans'] = 0xF8E8;
  12170. t['registerserif'] = 0xF6DA;
  12171. t['reharabic'] = 0x0631;
  12172. t['reharmenian'] = 0x0580;
  12173. t['rehfinalarabic'] = 0xFEAE;
  12174. t['rehiragana'] = 0x308C;
  12175. t['rekatakana'] = 0x30EC;
  12176. t['rekatakanahalfwidth'] = 0xFF9A;
  12177. t['resh'] = 0x05E8;
  12178. t['reshdageshhebrew'] = 0xFB48;
  12179. t['reshhebrew'] = 0x05E8;
  12180. t['reversedtilde'] = 0x223D;
  12181. t['reviahebrew'] = 0x0597;
  12182. t['reviamugrashhebrew'] = 0x0597;
  12183. t['revlogicalnot'] = 0x2310;
  12184. t['rfishhook'] = 0x027E;
  12185. t['rfishhookreversed'] = 0x027F;
  12186. t['rhabengali'] = 0x09DD;
  12187. t['rhadeva'] = 0x095D;
  12188. t['rho'] = 0x03C1;
  12189. t['rhook'] = 0x027D;
  12190. t['rhookturned'] = 0x027B;
  12191. t['rhookturnedsuperior'] = 0x02B5;
  12192. t['rhosymbolgreek'] = 0x03F1;
  12193. t['rhotichookmod'] = 0x02DE;
  12194. t['rieulacirclekorean'] = 0x3271;
  12195. t['rieulaparenkorean'] = 0x3211;
  12196. t['rieulcirclekorean'] = 0x3263;
  12197. t['rieulhieuhkorean'] = 0x3140;
  12198. t['rieulkiyeokkorean'] = 0x313A;
  12199. t['rieulkiyeoksioskorean'] = 0x3169;
  12200. t['rieulkorean'] = 0x3139;
  12201. t['rieulmieumkorean'] = 0x313B;
  12202. t['rieulpansioskorean'] = 0x316C;
  12203. t['rieulparenkorean'] = 0x3203;
  12204. t['rieulphieuphkorean'] = 0x313F;
  12205. t['rieulpieupkorean'] = 0x313C;
  12206. t['rieulpieupsioskorean'] = 0x316B;
  12207. t['rieulsioskorean'] = 0x313D;
  12208. t['rieulthieuthkorean'] = 0x313E;
  12209. t['rieultikeutkorean'] = 0x316A;
  12210. t['rieulyeorinhieuhkorean'] = 0x316D;
  12211. t['rightangle'] = 0x221F;
  12212. t['righttackbelowcmb'] = 0x0319;
  12213. t['righttriangle'] = 0x22BF;
  12214. t['rihiragana'] = 0x308A;
  12215. t['rikatakana'] = 0x30EA;
  12216. t['rikatakanahalfwidth'] = 0xFF98;
  12217. t['ring'] = 0x02DA;
  12218. t['ringbelowcmb'] = 0x0325;
  12219. t['ringcmb'] = 0x030A;
  12220. t['ringhalfleft'] = 0x02BF;
  12221. t['ringhalfleftarmenian'] = 0x0559;
  12222. t['ringhalfleftbelowcmb'] = 0x031C;
  12223. t['ringhalfleftcentered'] = 0x02D3;
  12224. t['ringhalfright'] = 0x02BE;
  12225. t['ringhalfrightbelowcmb'] = 0x0339;
  12226. t['ringhalfrightcentered'] = 0x02D2;
  12227. t['rinvertedbreve'] = 0x0213;
  12228. t['rittorusquare'] = 0x3351;
  12229. t['rlinebelow'] = 0x1E5F;
  12230. t['rlongleg'] = 0x027C;
  12231. t['rlonglegturned'] = 0x027A;
  12232. t['rmonospace'] = 0xFF52;
  12233. t['rohiragana'] = 0x308D;
  12234. t['rokatakana'] = 0x30ED;
  12235. t['rokatakanahalfwidth'] = 0xFF9B;
  12236. t['roruathai'] = 0x0E23;
  12237. t['rparen'] = 0x24AD;
  12238. t['rrabengali'] = 0x09DC;
  12239. t['rradeva'] = 0x0931;
  12240. t['rragurmukhi'] = 0x0A5C;
  12241. t['rreharabic'] = 0x0691;
  12242. t['rrehfinalarabic'] = 0xFB8D;
  12243. t['rrvocalicbengali'] = 0x09E0;
  12244. t['rrvocalicdeva'] = 0x0960;
  12245. t['rrvocalicgujarati'] = 0x0AE0;
  12246. t['rrvocalicvowelsignbengali'] = 0x09C4;
  12247. t['rrvocalicvowelsigndeva'] = 0x0944;
  12248. t['rrvocalicvowelsigngujarati'] = 0x0AC4;
  12249. t['rsuperior'] = 0xF6F1;
  12250. t['rtblock'] = 0x2590;
  12251. t['rturned'] = 0x0279;
  12252. t['rturnedsuperior'] = 0x02B4;
  12253. t['ruhiragana'] = 0x308B;
  12254. t['rukatakana'] = 0x30EB;
  12255. t['rukatakanahalfwidth'] = 0xFF99;
  12256. t['rupeemarkbengali'] = 0x09F2;
  12257. t['rupeesignbengali'] = 0x09F3;
  12258. t['rupiah'] = 0xF6DD;
  12259. t['ruthai'] = 0x0E24;
  12260. t['rvocalicbengali'] = 0x098B;
  12261. t['rvocalicdeva'] = 0x090B;
  12262. t['rvocalicgujarati'] = 0x0A8B;
  12263. t['rvocalicvowelsignbengali'] = 0x09C3;
  12264. t['rvocalicvowelsigndeva'] = 0x0943;
  12265. t['rvocalicvowelsigngujarati'] = 0x0AC3;
  12266. t['s'] = 0x0073;
  12267. t['sabengali'] = 0x09B8;
  12268. t['sacute'] = 0x015B;
  12269. t['sacutedotaccent'] = 0x1E65;
  12270. t['sadarabic'] = 0x0635;
  12271. t['sadeva'] = 0x0938;
  12272. t['sadfinalarabic'] = 0xFEBA;
  12273. t['sadinitialarabic'] = 0xFEBB;
  12274. t['sadmedialarabic'] = 0xFEBC;
  12275. t['sagujarati'] = 0x0AB8;
  12276. t['sagurmukhi'] = 0x0A38;
  12277. t['sahiragana'] = 0x3055;
  12278. t['sakatakana'] = 0x30B5;
  12279. t['sakatakanahalfwidth'] = 0xFF7B;
  12280. t['sallallahoualayhewasallamarabic'] = 0xFDFA;
  12281. t['samekh'] = 0x05E1;
  12282. t['samekhdagesh'] = 0xFB41;
  12283. t['samekhdageshhebrew'] = 0xFB41;
  12284. t['samekhhebrew'] = 0x05E1;
  12285. t['saraaathai'] = 0x0E32;
  12286. t['saraaethai'] = 0x0E41;
  12287. t['saraaimaimalaithai'] = 0x0E44;
  12288. t['saraaimaimuanthai'] = 0x0E43;
  12289. t['saraamthai'] = 0x0E33;
  12290. t['saraathai'] = 0x0E30;
  12291. t['saraethai'] = 0x0E40;
  12292. t['saraiileftthai'] = 0xF886;
  12293. t['saraiithai'] = 0x0E35;
  12294. t['saraileftthai'] = 0xF885;
  12295. t['saraithai'] = 0x0E34;
  12296. t['saraothai'] = 0x0E42;
  12297. t['saraueeleftthai'] = 0xF888;
  12298. t['saraueethai'] = 0x0E37;
  12299. t['saraueleftthai'] = 0xF887;
  12300. t['sarauethai'] = 0x0E36;
  12301. t['sarauthai'] = 0x0E38;
  12302. t['sarauuthai'] = 0x0E39;
  12303. t['sbopomofo'] = 0x3119;
  12304. t['scaron'] = 0x0161;
  12305. t['scarondotaccent'] = 0x1E67;
  12306. t['scedilla'] = 0x015F;
  12307. t['schwa'] = 0x0259;
  12308. t['schwacyrillic'] = 0x04D9;
  12309. t['schwadieresiscyrillic'] = 0x04DB;
  12310. t['schwahook'] = 0x025A;
  12311. t['scircle'] = 0x24E2;
  12312. t['scircumflex'] = 0x015D;
  12313. t['scommaaccent'] = 0x0219;
  12314. t['sdotaccent'] = 0x1E61;
  12315. t['sdotbelow'] = 0x1E63;
  12316. t['sdotbelowdotaccent'] = 0x1E69;
  12317. t['seagullbelowcmb'] = 0x033C;
  12318. t['second'] = 0x2033;
  12319. t['secondtonechinese'] = 0x02CA;
  12320. t['section'] = 0x00A7;
  12321. t['seenarabic'] = 0x0633;
  12322. t['seenfinalarabic'] = 0xFEB2;
  12323. t['seeninitialarabic'] = 0xFEB3;
  12324. t['seenmedialarabic'] = 0xFEB4;
  12325. t['segol'] = 0x05B6;
  12326. t['segol13'] = 0x05B6;
  12327. t['segol1f'] = 0x05B6;
  12328. t['segol2c'] = 0x05B6;
  12329. t['segolhebrew'] = 0x05B6;
  12330. t['segolnarrowhebrew'] = 0x05B6;
  12331. t['segolquarterhebrew'] = 0x05B6;
  12332. t['segoltahebrew'] = 0x0592;
  12333. t['segolwidehebrew'] = 0x05B6;
  12334. t['seharmenian'] = 0x057D;
  12335. t['sehiragana'] = 0x305B;
  12336. t['sekatakana'] = 0x30BB;
  12337. t['sekatakanahalfwidth'] = 0xFF7E;
  12338. t['semicolon'] = 0x003B;
  12339. t['semicolonarabic'] = 0x061B;
  12340. t['semicolonmonospace'] = 0xFF1B;
  12341. t['semicolonsmall'] = 0xFE54;
  12342. t['semivoicedmarkkana'] = 0x309C;
  12343. t['semivoicedmarkkanahalfwidth'] = 0xFF9F;
  12344. t['sentisquare'] = 0x3322;
  12345. t['sentosquare'] = 0x3323;
  12346. t['seven'] = 0x0037;
  12347. t['sevenarabic'] = 0x0667;
  12348. t['sevenbengali'] = 0x09ED;
  12349. t['sevencircle'] = 0x2466;
  12350. t['sevencircleinversesansserif'] = 0x2790;
  12351. t['sevendeva'] = 0x096D;
  12352. t['seveneighths'] = 0x215E;
  12353. t['sevengujarati'] = 0x0AED;
  12354. t['sevengurmukhi'] = 0x0A6D;
  12355. t['sevenhackarabic'] = 0x0667;
  12356. t['sevenhangzhou'] = 0x3027;
  12357. t['sevenideographicparen'] = 0x3226;
  12358. t['seveninferior'] = 0x2087;
  12359. t['sevenmonospace'] = 0xFF17;
  12360. t['sevenoldstyle'] = 0xF737;
  12361. t['sevenparen'] = 0x247A;
  12362. t['sevenperiod'] = 0x248E;
  12363. t['sevenpersian'] = 0x06F7;
  12364. t['sevenroman'] = 0x2176;
  12365. t['sevensuperior'] = 0x2077;
  12366. t['seventeencircle'] = 0x2470;
  12367. t['seventeenparen'] = 0x2484;
  12368. t['seventeenperiod'] = 0x2498;
  12369. t['seventhai'] = 0x0E57;
  12370. t['sfthyphen'] = 0x00AD;
  12371. t['shaarmenian'] = 0x0577;
  12372. t['shabengali'] = 0x09B6;
  12373. t['shacyrillic'] = 0x0448;
  12374. t['shaddaarabic'] = 0x0651;
  12375. t['shaddadammaarabic'] = 0xFC61;
  12376. t['shaddadammatanarabic'] = 0xFC5E;
  12377. t['shaddafathaarabic'] = 0xFC60;
  12378. t['shaddakasraarabic'] = 0xFC62;
  12379. t['shaddakasratanarabic'] = 0xFC5F;
  12380. t['shade'] = 0x2592;
  12381. t['shadedark'] = 0x2593;
  12382. t['shadelight'] = 0x2591;
  12383. t['shademedium'] = 0x2592;
  12384. t['shadeva'] = 0x0936;
  12385. t['shagujarati'] = 0x0AB6;
  12386. t['shagurmukhi'] = 0x0A36;
  12387. t['shalshelethebrew'] = 0x0593;
  12388. t['shbopomofo'] = 0x3115;
  12389. t['shchacyrillic'] = 0x0449;
  12390. t['sheenarabic'] = 0x0634;
  12391. t['sheenfinalarabic'] = 0xFEB6;
  12392. t['sheeninitialarabic'] = 0xFEB7;
  12393. t['sheenmedialarabic'] = 0xFEB8;
  12394. t['sheicoptic'] = 0x03E3;
  12395. t['sheqel'] = 0x20AA;
  12396. t['sheqelhebrew'] = 0x20AA;
  12397. t['sheva'] = 0x05B0;
  12398. t['sheva115'] = 0x05B0;
  12399. t['sheva15'] = 0x05B0;
  12400. t['sheva22'] = 0x05B0;
  12401. t['sheva2e'] = 0x05B0;
  12402. t['shevahebrew'] = 0x05B0;
  12403. t['shevanarrowhebrew'] = 0x05B0;
  12404. t['shevaquarterhebrew'] = 0x05B0;
  12405. t['shevawidehebrew'] = 0x05B0;
  12406. t['shhacyrillic'] = 0x04BB;
  12407. t['shimacoptic'] = 0x03ED;
  12408. t['shin'] = 0x05E9;
  12409. t['shindagesh'] = 0xFB49;
  12410. t['shindageshhebrew'] = 0xFB49;
  12411. t['shindageshshindot'] = 0xFB2C;
  12412. t['shindageshshindothebrew'] = 0xFB2C;
  12413. t['shindageshsindot'] = 0xFB2D;
  12414. t['shindageshsindothebrew'] = 0xFB2D;
  12415. t['shindothebrew'] = 0x05C1;
  12416. t['shinhebrew'] = 0x05E9;
  12417. t['shinshindot'] = 0xFB2A;
  12418. t['shinshindothebrew'] = 0xFB2A;
  12419. t['shinsindot'] = 0xFB2B;
  12420. t['shinsindothebrew'] = 0xFB2B;
  12421. t['shook'] = 0x0282;
  12422. t['sigma'] = 0x03C3;
  12423. t['sigma1'] = 0x03C2;
  12424. t['sigmafinal'] = 0x03C2;
  12425. t['sigmalunatesymbolgreek'] = 0x03F2;
  12426. t['sihiragana'] = 0x3057;
  12427. t['sikatakana'] = 0x30B7;
  12428. t['sikatakanahalfwidth'] = 0xFF7C;
  12429. t['siluqhebrew'] = 0x05BD;
  12430. t['siluqlefthebrew'] = 0x05BD;
  12431. t['similar'] = 0x223C;
  12432. t['sindothebrew'] = 0x05C2;
  12433. t['siosacirclekorean'] = 0x3274;
  12434. t['siosaparenkorean'] = 0x3214;
  12435. t['sioscieuckorean'] = 0x317E;
  12436. t['sioscirclekorean'] = 0x3266;
  12437. t['sioskiyeokkorean'] = 0x317A;
  12438. t['sioskorean'] = 0x3145;
  12439. t['siosnieunkorean'] = 0x317B;
  12440. t['siosparenkorean'] = 0x3206;
  12441. t['siospieupkorean'] = 0x317D;
  12442. t['siostikeutkorean'] = 0x317C;
  12443. t['six'] = 0x0036;
  12444. t['sixarabic'] = 0x0666;
  12445. t['sixbengali'] = 0x09EC;
  12446. t['sixcircle'] = 0x2465;
  12447. t['sixcircleinversesansserif'] = 0x278F;
  12448. t['sixdeva'] = 0x096C;
  12449. t['sixgujarati'] = 0x0AEC;
  12450. t['sixgurmukhi'] = 0x0A6C;
  12451. t['sixhackarabic'] = 0x0666;
  12452. t['sixhangzhou'] = 0x3026;
  12453. t['sixideographicparen'] = 0x3225;
  12454. t['sixinferior'] = 0x2086;
  12455. t['sixmonospace'] = 0xFF16;
  12456. t['sixoldstyle'] = 0xF736;
  12457. t['sixparen'] = 0x2479;
  12458. t['sixperiod'] = 0x248D;
  12459. t['sixpersian'] = 0x06F6;
  12460. t['sixroman'] = 0x2175;
  12461. t['sixsuperior'] = 0x2076;
  12462. t['sixteencircle'] = 0x246F;
  12463. t['sixteencurrencydenominatorbengali'] = 0x09F9;
  12464. t['sixteenparen'] = 0x2483;
  12465. t['sixteenperiod'] = 0x2497;
  12466. t['sixthai'] = 0x0E56;
  12467. t['slash'] = 0x002F;
  12468. t['slashmonospace'] = 0xFF0F;
  12469. t['slong'] = 0x017F;
  12470. t['slongdotaccent'] = 0x1E9B;
  12471. t['smileface'] = 0x263A;
  12472. t['smonospace'] = 0xFF53;
  12473. t['sofpasuqhebrew'] = 0x05C3;
  12474. t['softhyphen'] = 0x00AD;
  12475. t['softsigncyrillic'] = 0x044C;
  12476. t['sohiragana'] = 0x305D;
  12477. t['sokatakana'] = 0x30BD;
  12478. t['sokatakanahalfwidth'] = 0xFF7F;
  12479. t['soliduslongoverlaycmb'] = 0x0338;
  12480. t['solidusshortoverlaycmb'] = 0x0337;
  12481. t['sorusithai'] = 0x0E29;
  12482. t['sosalathai'] = 0x0E28;
  12483. t['sosothai'] = 0x0E0B;
  12484. t['sosuathai'] = 0x0E2A;
  12485. t['space'] = 0x0020;
  12486. t['spacehackarabic'] = 0x0020;
  12487. t['spade'] = 0x2660;
  12488. t['spadesuitblack'] = 0x2660;
  12489. t['spadesuitwhite'] = 0x2664;
  12490. t['sparen'] = 0x24AE;
  12491. t['squarebelowcmb'] = 0x033B;
  12492. t['squarecc'] = 0x33C4;
  12493. t['squarecm'] = 0x339D;
  12494. t['squarediagonalcrosshatchfill'] = 0x25A9;
  12495. t['squarehorizontalfill'] = 0x25A4;
  12496. t['squarekg'] = 0x338F;
  12497. t['squarekm'] = 0x339E;
  12498. t['squarekmcapital'] = 0x33CE;
  12499. t['squareln'] = 0x33D1;
  12500. t['squarelog'] = 0x33D2;
  12501. t['squaremg'] = 0x338E;
  12502. t['squaremil'] = 0x33D5;
  12503. t['squaremm'] = 0x339C;
  12504. t['squaremsquared'] = 0x33A1;
  12505. t['squareorthogonalcrosshatchfill'] = 0x25A6;
  12506. t['squareupperlefttolowerrightfill'] = 0x25A7;
  12507. t['squareupperrighttolowerleftfill'] = 0x25A8;
  12508. t['squareverticalfill'] = 0x25A5;
  12509. t['squarewhitewithsmallblack'] = 0x25A3;
  12510. t['srsquare'] = 0x33DB;
  12511. t['ssabengali'] = 0x09B7;
  12512. t['ssadeva'] = 0x0937;
  12513. t['ssagujarati'] = 0x0AB7;
  12514. t['ssangcieuckorean'] = 0x3149;
  12515. t['ssanghieuhkorean'] = 0x3185;
  12516. t['ssangieungkorean'] = 0x3180;
  12517. t['ssangkiyeokkorean'] = 0x3132;
  12518. t['ssangnieunkorean'] = 0x3165;
  12519. t['ssangpieupkorean'] = 0x3143;
  12520. t['ssangsioskorean'] = 0x3146;
  12521. t['ssangtikeutkorean'] = 0x3138;
  12522. t['ssuperior'] = 0xF6F2;
  12523. t['sterling'] = 0x00A3;
  12524. t['sterlingmonospace'] = 0xFFE1;
  12525. t['strokelongoverlaycmb'] = 0x0336;
  12526. t['strokeshortoverlaycmb'] = 0x0335;
  12527. t['subset'] = 0x2282;
  12528. t['subsetnotequal'] = 0x228A;
  12529. t['subsetorequal'] = 0x2286;
  12530. t['succeeds'] = 0x227B;
  12531. t['suchthat'] = 0x220B;
  12532. t['suhiragana'] = 0x3059;
  12533. t['sukatakana'] = 0x30B9;
  12534. t['sukatakanahalfwidth'] = 0xFF7D;
  12535. t['sukunarabic'] = 0x0652;
  12536. t['summation'] = 0x2211;
  12537. t['sun'] = 0x263C;
  12538. t['superset'] = 0x2283;
  12539. t['supersetnotequal'] = 0x228B;
  12540. t['supersetorequal'] = 0x2287;
  12541. t['svsquare'] = 0x33DC;
  12542. t['syouwaerasquare'] = 0x337C;
  12543. t['t'] = 0x0074;
  12544. t['tabengali'] = 0x09A4;
  12545. t['tackdown'] = 0x22A4;
  12546. t['tackleft'] = 0x22A3;
  12547. t['tadeva'] = 0x0924;
  12548. t['tagujarati'] = 0x0AA4;
  12549. t['tagurmukhi'] = 0x0A24;
  12550. t['taharabic'] = 0x0637;
  12551. t['tahfinalarabic'] = 0xFEC2;
  12552. t['tahinitialarabic'] = 0xFEC3;
  12553. t['tahiragana'] = 0x305F;
  12554. t['tahmedialarabic'] = 0xFEC4;
  12555. t['taisyouerasquare'] = 0x337D;
  12556. t['takatakana'] = 0x30BF;
  12557. t['takatakanahalfwidth'] = 0xFF80;
  12558. t['tatweelarabic'] = 0x0640;
  12559. t['tau'] = 0x03C4;
  12560. t['tav'] = 0x05EA;
  12561. t['tavdages'] = 0xFB4A;
  12562. t['tavdagesh'] = 0xFB4A;
  12563. t['tavdageshhebrew'] = 0xFB4A;
  12564. t['tavhebrew'] = 0x05EA;
  12565. t['tbar'] = 0x0167;
  12566. t['tbopomofo'] = 0x310A;
  12567. t['tcaron'] = 0x0165;
  12568. t['tccurl'] = 0x02A8;
  12569. t['tcedilla'] = 0x0163;
  12570. t['tcheharabic'] = 0x0686;
  12571. t['tchehfinalarabic'] = 0xFB7B;
  12572. t['tchehinitialarabic'] = 0xFB7C;
  12573. t['tchehmedialarabic'] = 0xFB7D;
  12574. t['tcircle'] = 0x24E3;
  12575. t['tcircumflexbelow'] = 0x1E71;
  12576. t['tcommaaccent'] = 0x0163;
  12577. t['tdieresis'] = 0x1E97;
  12578. t['tdotaccent'] = 0x1E6B;
  12579. t['tdotbelow'] = 0x1E6D;
  12580. t['tecyrillic'] = 0x0442;
  12581. t['tedescendercyrillic'] = 0x04AD;
  12582. t['teharabic'] = 0x062A;
  12583. t['tehfinalarabic'] = 0xFE96;
  12584. t['tehhahinitialarabic'] = 0xFCA2;
  12585. t['tehhahisolatedarabic'] = 0xFC0C;
  12586. t['tehinitialarabic'] = 0xFE97;
  12587. t['tehiragana'] = 0x3066;
  12588. t['tehjeeminitialarabic'] = 0xFCA1;
  12589. t['tehjeemisolatedarabic'] = 0xFC0B;
  12590. t['tehmarbutaarabic'] = 0x0629;
  12591. t['tehmarbutafinalarabic'] = 0xFE94;
  12592. t['tehmedialarabic'] = 0xFE98;
  12593. t['tehmeeminitialarabic'] = 0xFCA4;
  12594. t['tehmeemisolatedarabic'] = 0xFC0E;
  12595. t['tehnoonfinalarabic'] = 0xFC73;
  12596. t['tekatakana'] = 0x30C6;
  12597. t['tekatakanahalfwidth'] = 0xFF83;
  12598. t['telephone'] = 0x2121;
  12599. t['telephoneblack'] = 0x260E;
  12600. t['telishagedolahebrew'] = 0x05A0;
  12601. t['telishaqetanahebrew'] = 0x05A9;
  12602. t['tencircle'] = 0x2469;
  12603. t['tenideographicparen'] = 0x3229;
  12604. t['tenparen'] = 0x247D;
  12605. t['tenperiod'] = 0x2491;
  12606. t['tenroman'] = 0x2179;
  12607. t['tesh'] = 0x02A7;
  12608. t['tet'] = 0x05D8;
  12609. t['tetdagesh'] = 0xFB38;
  12610. t['tetdageshhebrew'] = 0xFB38;
  12611. t['tethebrew'] = 0x05D8;
  12612. t['tetsecyrillic'] = 0x04B5;
  12613. t['tevirhebrew'] = 0x059B;
  12614. t['tevirlefthebrew'] = 0x059B;
  12615. t['thabengali'] = 0x09A5;
  12616. t['thadeva'] = 0x0925;
  12617. t['thagujarati'] = 0x0AA5;
  12618. t['thagurmukhi'] = 0x0A25;
  12619. t['thalarabic'] = 0x0630;
  12620. t['thalfinalarabic'] = 0xFEAC;
  12621. t['thanthakhatlowleftthai'] = 0xF898;
  12622. t['thanthakhatlowrightthai'] = 0xF897;
  12623. t['thanthakhatthai'] = 0x0E4C;
  12624. t['thanthakhatupperleftthai'] = 0xF896;
  12625. t['theharabic'] = 0x062B;
  12626. t['thehfinalarabic'] = 0xFE9A;
  12627. t['thehinitialarabic'] = 0xFE9B;
  12628. t['thehmedialarabic'] = 0xFE9C;
  12629. t['thereexists'] = 0x2203;
  12630. t['therefore'] = 0x2234;
  12631. t['theta'] = 0x03B8;
  12632. t['theta1'] = 0x03D1;
  12633. t['thetasymbolgreek'] = 0x03D1;
  12634. t['thieuthacirclekorean'] = 0x3279;
  12635. t['thieuthaparenkorean'] = 0x3219;
  12636. t['thieuthcirclekorean'] = 0x326B;
  12637. t['thieuthkorean'] = 0x314C;
  12638. t['thieuthparenkorean'] = 0x320B;
  12639. t['thirteencircle'] = 0x246C;
  12640. t['thirteenparen'] = 0x2480;
  12641. t['thirteenperiod'] = 0x2494;
  12642. t['thonangmonthothai'] = 0x0E11;
  12643. t['thook'] = 0x01AD;
  12644. t['thophuthaothai'] = 0x0E12;
  12645. t['thorn'] = 0x00FE;
  12646. t['thothahanthai'] = 0x0E17;
  12647. t['thothanthai'] = 0x0E10;
  12648. t['thothongthai'] = 0x0E18;
  12649. t['thothungthai'] = 0x0E16;
  12650. t['thousandcyrillic'] = 0x0482;
  12651. t['thousandsseparatorarabic'] = 0x066C;
  12652. t['thousandsseparatorpersian'] = 0x066C;
  12653. t['three'] = 0x0033;
  12654. t['threearabic'] = 0x0663;
  12655. t['threebengali'] = 0x09E9;
  12656. t['threecircle'] = 0x2462;
  12657. t['threecircleinversesansserif'] = 0x278C;
  12658. t['threedeva'] = 0x0969;
  12659. t['threeeighths'] = 0x215C;
  12660. t['threegujarati'] = 0x0AE9;
  12661. t['threegurmukhi'] = 0x0A69;
  12662. t['threehackarabic'] = 0x0663;
  12663. t['threehangzhou'] = 0x3023;
  12664. t['threeideographicparen'] = 0x3222;
  12665. t['threeinferior'] = 0x2083;
  12666. t['threemonospace'] = 0xFF13;
  12667. t['threenumeratorbengali'] = 0x09F6;
  12668. t['threeoldstyle'] = 0xF733;
  12669. t['threeparen'] = 0x2476;
  12670. t['threeperiod'] = 0x248A;
  12671. t['threepersian'] = 0x06F3;
  12672. t['threequarters'] = 0x00BE;
  12673. t['threequartersemdash'] = 0xF6DE;
  12674. t['threeroman'] = 0x2172;
  12675. t['threesuperior'] = 0x00B3;
  12676. t['threethai'] = 0x0E53;
  12677. t['thzsquare'] = 0x3394;
  12678. t['tihiragana'] = 0x3061;
  12679. t['tikatakana'] = 0x30C1;
  12680. t['tikatakanahalfwidth'] = 0xFF81;
  12681. t['tikeutacirclekorean'] = 0x3270;
  12682. t['tikeutaparenkorean'] = 0x3210;
  12683. t['tikeutcirclekorean'] = 0x3262;
  12684. t['tikeutkorean'] = 0x3137;
  12685. t['tikeutparenkorean'] = 0x3202;
  12686. t['tilde'] = 0x02DC;
  12687. t['tildebelowcmb'] = 0x0330;
  12688. t['tildecmb'] = 0x0303;
  12689. t['tildecomb'] = 0x0303;
  12690. t['tildedoublecmb'] = 0x0360;
  12691. t['tildeoperator'] = 0x223C;
  12692. t['tildeoverlaycmb'] = 0x0334;
  12693. t['tildeverticalcmb'] = 0x033E;
  12694. t['timescircle'] = 0x2297;
  12695. t['tipehahebrew'] = 0x0596;
  12696. t['tipehalefthebrew'] = 0x0596;
  12697. t['tippigurmukhi'] = 0x0A70;
  12698. t['titlocyrilliccmb'] = 0x0483;
  12699. t['tiwnarmenian'] = 0x057F;
  12700. t['tlinebelow'] = 0x1E6F;
  12701. t['tmonospace'] = 0xFF54;
  12702. t['toarmenian'] = 0x0569;
  12703. t['tohiragana'] = 0x3068;
  12704. t['tokatakana'] = 0x30C8;
  12705. t['tokatakanahalfwidth'] = 0xFF84;
  12706. t['tonebarextrahighmod'] = 0x02E5;
  12707. t['tonebarextralowmod'] = 0x02E9;
  12708. t['tonebarhighmod'] = 0x02E6;
  12709. t['tonebarlowmod'] = 0x02E8;
  12710. t['tonebarmidmod'] = 0x02E7;
  12711. t['tonefive'] = 0x01BD;
  12712. t['tonesix'] = 0x0185;
  12713. t['tonetwo'] = 0x01A8;
  12714. t['tonos'] = 0x0384;
  12715. t['tonsquare'] = 0x3327;
  12716. t['topatakthai'] = 0x0E0F;
  12717. t['tortoiseshellbracketleft'] = 0x3014;
  12718. t['tortoiseshellbracketleftsmall'] = 0xFE5D;
  12719. t['tortoiseshellbracketleftvertical'] = 0xFE39;
  12720. t['tortoiseshellbracketright'] = 0x3015;
  12721. t['tortoiseshellbracketrightsmall'] = 0xFE5E;
  12722. t['tortoiseshellbracketrightvertical'] = 0xFE3A;
  12723. t['totaothai'] = 0x0E15;
  12724. t['tpalatalhook'] = 0x01AB;
  12725. t['tparen'] = 0x24AF;
  12726. t['trademark'] = 0x2122;
  12727. t['trademarksans'] = 0xF8EA;
  12728. t['trademarkserif'] = 0xF6DB;
  12729. t['tretroflexhook'] = 0x0288;
  12730. t['triagdn'] = 0x25BC;
  12731. t['triaglf'] = 0x25C4;
  12732. t['triagrt'] = 0x25BA;
  12733. t['triagup'] = 0x25B2;
  12734. t['ts'] = 0x02A6;
  12735. t['tsadi'] = 0x05E6;
  12736. t['tsadidagesh'] = 0xFB46;
  12737. t['tsadidageshhebrew'] = 0xFB46;
  12738. t['tsadihebrew'] = 0x05E6;
  12739. t['tsecyrillic'] = 0x0446;
  12740. t['tsere'] = 0x05B5;
  12741. t['tsere12'] = 0x05B5;
  12742. t['tsere1e'] = 0x05B5;
  12743. t['tsere2b'] = 0x05B5;
  12744. t['tserehebrew'] = 0x05B5;
  12745. t['tserenarrowhebrew'] = 0x05B5;
  12746. t['tserequarterhebrew'] = 0x05B5;
  12747. t['tserewidehebrew'] = 0x05B5;
  12748. t['tshecyrillic'] = 0x045B;
  12749. t['tsuperior'] = 0xF6F3;
  12750. t['ttabengali'] = 0x099F;
  12751. t['ttadeva'] = 0x091F;
  12752. t['ttagujarati'] = 0x0A9F;
  12753. t['ttagurmukhi'] = 0x0A1F;
  12754. t['tteharabic'] = 0x0679;
  12755. t['ttehfinalarabic'] = 0xFB67;
  12756. t['ttehinitialarabic'] = 0xFB68;
  12757. t['ttehmedialarabic'] = 0xFB69;
  12758. t['tthabengali'] = 0x09A0;
  12759. t['tthadeva'] = 0x0920;
  12760. t['tthagujarati'] = 0x0AA0;
  12761. t['tthagurmukhi'] = 0x0A20;
  12762. t['tturned'] = 0x0287;
  12763. t['tuhiragana'] = 0x3064;
  12764. t['tukatakana'] = 0x30C4;
  12765. t['tukatakanahalfwidth'] = 0xFF82;
  12766. t['tusmallhiragana'] = 0x3063;
  12767. t['tusmallkatakana'] = 0x30C3;
  12768. t['tusmallkatakanahalfwidth'] = 0xFF6F;
  12769. t['twelvecircle'] = 0x246B;
  12770. t['twelveparen'] = 0x247F;
  12771. t['twelveperiod'] = 0x2493;
  12772. t['twelveroman'] = 0x217B;
  12773. t['twentycircle'] = 0x2473;
  12774. t['twentyhangzhou'] = 0x5344;
  12775. t['twentyparen'] = 0x2487;
  12776. t['twentyperiod'] = 0x249B;
  12777. t['two'] = 0x0032;
  12778. t['twoarabic'] = 0x0662;
  12779. t['twobengali'] = 0x09E8;
  12780. t['twocircle'] = 0x2461;
  12781. t['twocircleinversesansserif'] = 0x278B;
  12782. t['twodeva'] = 0x0968;
  12783. t['twodotenleader'] = 0x2025;
  12784. t['twodotleader'] = 0x2025;
  12785. t['twodotleadervertical'] = 0xFE30;
  12786. t['twogujarati'] = 0x0AE8;
  12787. t['twogurmukhi'] = 0x0A68;
  12788. t['twohackarabic'] = 0x0662;
  12789. t['twohangzhou'] = 0x3022;
  12790. t['twoideographicparen'] = 0x3221;
  12791. t['twoinferior'] = 0x2082;
  12792. t['twomonospace'] = 0xFF12;
  12793. t['twonumeratorbengali'] = 0x09F5;
  12794. t['twooldstyle'] = 0xF732;
  12795. t['twoparen'] = 0x2475;
  12796. t['twoperiod'] = 0x2489;
  12797. t['twopersian'] = 0x06F2;
  12798. t['tworoman'] = 0x2171;
  12799. t['twostroke'] = 0x01BB;
  12800. t['twosuperior'] = 0x00B2;
  12801. t['twothai'] = 0x0E52;
  12802. t['twothirds'] = 0x2154;
  12803. t['u'] = 0x0075;
  12804. t['uacute'] = 0x00FA;
  12805. t['ubar'] = 0x0289;
  12806. t['ubengali'] = 0x0989;
  12807. t['ubopomofo'] = 0x3128;
  12808. t['ubreve'] = 0x016D;
  12809. t['ucaron'] = 0x01D4;
  12810. t['ucircle'] = 0x24E4;
  12811. t['ucircumflex'] = 0x00FB;
  12812. t['ucircumflexbelow'] = 0x1E77;
  12813. t['ucyrillic'] = 0x0443;
  12814. t['udattadeva'] = 0x0951;
  12815. t['udblacute'] = 0x0171;
  12816. t['udblgrave'] = 0x0215;
  12817. t['udeva'] = 0x0909;
  12818. t['udieresis'] = 0x00FC;
  12819. t['udieresisacute'] = 0x01D8;
  12820. t['udieresisbelow'] = 0x1E73;
  12821. t['udieresiscaron'] = 0x01DA;
  12822. t['udieresiscyrillic'] = 0x04F1;
  12823. t['udieresisgrave'] = 0x01DC;
  12824. t['udieresismacron'] = 0x01D6;
  12825. t['udotbelow'] = 0x1EE5;
  12826. t['ugrave'] = 0x00F9;
  12827. t['ugujarati'] = 0x0A89;
  12828. t['ugurmukhi'] = 0x0A09;
  12829. t['uhiragana'] = 0x3046;
  12830. t['uhookabove'] = 0x1EE7;
  12831. t['uhorn'] = 0x01B0;
  12832. t['uhornacute'] = 0x1EE9;
  12833. t['uhorndotbelow'] = 0x1EF1;
  12834. t['uhorngrave'] = 0x1EEB;
  12835. t['uhornhookabove'] = 0x1EED;
  12836. t['uhorntilde'] = 0x1EEF;
  12837. t['uhungarumlaut'] = 0x0171;
  12838. t['uhungarumlautcyrillic'] = 0x04F3;
  12839. t['uinvertedbreve'] = 0x0217;
  12840. t['ukatakana'] = 0x30A6;
  12841. t['ukatakanahalfwidth'] = 0xFF73;
  12842. t['ukcyrillic'] = 0x0479;
  12843. t['ukorean'] = 0x315C;
  12844. t['umacron'] = 0x016B;
  12845. t['umacroncyrillic'] = 0x04EF;
  12846. t['umacrondieresis'] = 0x1E7B;
  12847. t['umatragurmukhi'] = 0x0A41;
  12848. t['umonospace'] = 0xFF55;
  12849. t['underscore'] = 0x005F;
  12850. t['underscoredbl'] = 0x2017;
  12851. t['underscoremonospace'] = 0xFF3F;
  12852. t['underscorevertical'] = 0xFE33;
  12853. t['underscorewavy'] = 0xFE4F;
  12854. t['union'] = 0x222A;
  12855. t['universal'] = 0x2200;
  12856. t['uogonek'] = 0x0173;
  12857. t['uparen'] = 0x24B0;
  12858. t['upblock'] = 0x2580;
  12859. t['upperdothebrew'] = 0x05C4;
  12860. t['upsilon'] = 0x03C5;
  12861. t['upsilondieresis'] = 0x03CB;
  12862. t['upsilondieresistonos'] = 0x03B0;
  12863. t['upsilonlatin'] = 0x028A;
  12864. t['upsilontonos'] = 0x03CD;
  12865. t['uptackbelowcmb'] = 0x031D;
  12866. t['uptackmod'] = 0x02D4;
  12867. t['uragurmukhi'] = 0x0A73;
  12868. t['uring'] = 0x016F;
  12869. t['ushortcyrillic'] = 0x045E;
  12870. t['usmallhiragana'] = 0x3045;
  12871. t['usmallkatakana'] = 0x30A5;
  12872. t['usmallkatakanahalfwidth'] = 0xFF69;
  12873. t['ustraightcyrillic'] = 0x04AF;
  12874. t['ustraightstrokecyrillic'] = 0x04B1;
  12875. t['utilde'] = 0x0169;
  12876. t['utildeacute'] = 0x1E79;
  12877. t['utildebelow'] = 0x1E75;
  12878. t['uubengali'] = 0x098A;
  12879. t['uudeva'] = 0x090A;
  12880. t['uugujarati'] = 0x0A8A;
  12881. t['uugurmukhi'] = 0x0A0A;
  12882. t['uumatragurmukhi'] = 0x0A42;
  12883. t['uuvowelsignbengali'] = 0x09C2;
  12884. t['uuvowelsigndeva'] = 0x0942;
  12885. t['uuvowelsigngujarati'] = 0x0AC2;
  12886. t['uvowelsignbengali'] = 0x09C1;
  12887. t['uvowelsigndeva'] = 0x0941;
  12888. t['uvowelsigngujarati'] = 0x0AC1;
  12889. t['v'] = 0x0076;
  12890. t['vadeva'] = 0x0935;
  12891. t['vagujarati'] = 0x0AB5;
  12892. t['vagurmukhi'] = 0x0A35;
  12893. t['vakatakana'] = 0x30F7;
  12894. t['vav'] = 0x05D5;
  12895. t['vavdagesh'] = 0xFB35;
  12896. t['vavdagesh65'] = 0xFB35;
  12897. t['vavdageshhebrew'] = 0xFB35;
  12898. t['vavhebrew'] = 0x05D5;
  12899. t['vavholam'] = 0xFB4B;
  12900. t['vavholamhebrew'] = 0xFB4B;
  12901. t['vavvavhebrew'] = 0x05F0;
  12902. t['vavyodhebrew'] = 0x05F1;
  12903. t['vcircle'] = 0x24E5;
  12904. t['vdotbelow'] = 0x1E7F;
  12905. t['vecyrillic'] = 0x0432;
  12906. t['veharabic'] = 0x06A4;
  12907. t['vehfinalarabic'] = 0xFB6B;
  12908. t['vehinitialarabic'] = 0xFB6C;
  12909. t['vehmedialarabic'] = 0xFB6D;
  12910. t['vekatakana'] = 0x30F9;
  12911. t['venus'] = 0x2640;
  12912. t['verticalbar'] = 0x007C;
  12913. t['verticallineabovecmb'] = 0x030D;
  12914. t['verticallinebelowcmb'] = 0x0329;
  12915. t['verticallinelowmod'] = 0x02CC;
  12916. t['verticallinemod'] = 0x02C8;
  12917. t['vewarmenian'] = 0x057E;
  12918. t['vhook'] = 0x028B;
  12919. t['vikatakana'] = 0x30F8;
  12920. t['viramabengali'] = 0x09CD;
  12921. t['viramadeva'] = 0x094D;
  12922. t['viramagujarati'] = 0x0ACD;
  12923. t['visargabengali'] = 0x0983;
  12924. t['visargadeva'] = 0x0903;
  12925. t['visargagujarati'] = 0x0A83;
  12926. t['vmonospace'] = 0xFF56;
  12927. t['voarmenian'] = 0x0578;
  12928. t['voicediterationhiragana'] = 0x309E;
  12929. t['voicediterationkatakana'] = 0x30FE;
  12930. t['voicedmarkkana'] = 0x309B;
  12931. t['voicedmarkkanahalfwidth'] = 0xFF9E;
  12932. t['vokatakana'] = 0x30FA;
  12933. t['vparen'] = 0x24B1;
  12934. t['vtilde'] = 0x1E7D;
  12935. t['vturned'] = 0x028C;
  12936. t['vuhiragana'] = 0x3094;
  12937. t['vukatakana'] = 0x30F4;
  12938. t['w'] = 0x0077;
  12939. t['wacute'] = 0x1E83;
  12940. t['waekorean'] = 0x3159;
  12941. t['wahiragana'] = 0x308F;
  12942. t['wakatakana'] = 0x30EF;
  12943. t['wakatakanahalfwidth'] = 0xFF9C;
  12944. t['wakorean'] = 0x3158;
  12945. t['wasmallhiragana'] = 0x308E;
  12946. t['wasmallkatakana'] = 0x30EE;
  12947. t['wattosquare'] = 0x3357;
  12948. t['wavedash'] = 0x301C;
  12949. t['wavyunderscorevertical'] = 0xFE34;
  12950. t['wawarabic'] = 0x0648;
  12951. t['wawfinalarabic'] = 0xFEEE;
  12952. t['wawhamzaabovearabic'] = 0x0624;
  12953. t['wawhamzaabovefinalarabic'] = 0xFE86;
  12954. t['wbsquare'] = 0x33DD;
  12955. t['wcircle'] = 0x24E6;
  12956. t['wcircumflex'] = 0x0175;
  12957. t['wdieresis'] = 0x1E85;
  12958. t['wdotaccent'] = 0x1E87;
  12959. t['wdotbelow'] = 0x1E89;
  12960. t['wehiragana'] = 0x3091;
  12961. t['weierstrass'] = 0x2118;
  12962. t['wekatakana'] = 0x30F1;
  12963. t['wekorean'] = 0x315E;
  12964. t['weokorean'] = 0x315D;
  12965. t['wgrave'] = 0x1E81;
  12966. t['whitebullet'] = 0x25E6;
  12967. t['whitecircle'] = 0x25CB;
  12968. t['whitecircleinverse'] = 0x25D9;
  12969. t['whitecornerbracketleft'] = 0x300E;
  12970. t['whitecornerbracketleftvertical'] = 0xFE43;
  12971. t['whitecornerbracketright'] = 0x300F;
  12972. t['whitecornerbracketrightvertical'] = 0xFE44;
  12973. t['whitediamond'] = 0x25C7;
  12974. t['whitediamondcontainingblacksmalldiamond'] = 0x25C8;
  12975. t['whitedownpointingsmalltriangle'] = 0x25BF;
  12976. t['whitedownpointingtriangle'] = 0x25BD;
  12977. t['whiteleftpointingsmalltriangle'] = 0x25C3;
  12978. t['whiteleftpointingtriangle'] = 0x25C1;
  12979. t['whitelenticularbracketleft'] = 0x3016;
  12980. t['whitelenticularbracketright'] = 0x3017;
  12981. t['whiterightpointingsmalltriangle'] = 0x25B9;
  12982. t['whiterightpointingtriangle'] = 0x25B7;
  12983. t['whitesmallsquare'] = 0x25AB;
  12984. t['whitesmilingface'] = 0x263A;
  12985. t['whitesquare'] = 0x25A1;
  12986. t['whitestar'] = 0x2606;
  12987. t['whitetelephone'] = 0x260F;
  12988. t['whitetortoiseshellbracketleft'] = 0x3018;
  12989. t['whitetortoiseshellbracketright'] = 0x3019;
  12990. t['whiteuppointingsmalltriangle'] = 0x25B5;
  12991. t['whiteuppointingtriangle'] = 0x25B3;
  12992. t['wihiragana'] = 0x3090;
  12993. t['wikatakana'] = 0x30F0;
  12994. t['wikorean'] = 0x315F;
  12995. t['wmonospace'] = 0xFF57;
  12996. t['wohiragana'] = 0x3092;
  12997. t['wokatakana'] = 0x30F2;
  12998. t['wokatakanahalfwidth'] = 0xFF66;
  12999. t['won'] = 0x20A9;
  13000. t['wonmonospace'] = 0xFFE6;
  13001. t['wowaenthai'] = 0x0E27;
  13002. t['wparen'] = 0x24B2;
  13003. t['wring'] = 0x1E98;
  13004. t['wsuperior'] = 0x02B7;
  13005. t['wturned'] = 0x028D;
  13006. t['wynn'] = 0x01BF;
  13007. t['x'] = 0x0078;
  13008. t['xabovecmb'] = 0x033D;
  13009. t['xbopomofo'] = 0x3112;
  13010. t['xcircle'] = 0x24E7;
  13011. t['xdieresis'] = 0x1E8D;
  13012. t['xdotaccent'] = 0x1E8B;
  13013. t['xeharmenian'] = 0x056D;
  13014. t['xi'] = 0x03BE;
  13015. t['xmonospace'] = 0xFF58;
  13016. t['xparen'] = 0x24B3;
  13017. t['xsuperior'] = 0x02E3;
  13018. t['y'] = 0x0079;
  13019. t['yaadosquare'] = 0x334E;
  13020. t['yabengali'] = 0x09AF;
  13021. t['yacute'] = 0x00FD;
  13022. t['yadeva'] = 0x092F;
  13023. t['yaekorean'] = 0x3152;
  13024. t['yagujarati'] = 0x0AAF;
  13025. t['yagurmukhi'] = 0x0A2F;
  13026. t['yahiragana'] = 0x3084;
  13027. t['yakatakana'] = 0x30E4;
  13028. t['yakatakanahalfwidth'] = 0xFF94;
  13029. t['yakorean'] = 0x3151;
  13030. t['yamakkanthai'] = 0x0E4E;
  13031. t['yasmallhiragana'] = 0x3083;
  13032. t['yasmallkatakana'] = 0x30E3;
  13033. t['yasmallkatakanahalfwidth'] = 0xFF6C;
  13034. t['yatcyrillic'] = 0x0463;
  13035. t['ycircle'] = 0x24E8;
  13036. t['ycircumflex'] = 0x0177;
  13037. t['ydieresis'] = 0x00FF;
  13038. t['ydotaccent'] = 0x1E8F;
  13039. t['ydotbelow'] = 0x1EF5;
  13040. t['yeharabic'] = 0x064A;
  13041. t['yehbarreearabic'] = 0x06D2;
  13042. t['yehbarreefinalarabic'] = 0xFBAF;
  13043. t['yehfinalarabic'] = 0xFEF2;
  13044. t['yehhamzaabovearabic'] = 0x0626;
  13045. t['yehhamzaabovefinalarabic'] = 0xFE8A;
  13046. t['yehhamzaaboveinitialarabic'] = 0xFE8B;
  13047. t['yehhamzaabovemedialarabic'] = 0xFE8C;
  13048. t['yehinitialarabic'] = 0xFEF3;
  13049. t['yehmedialarabic'] = 0xFEF4;
  13050. t['yehmeeminitialarabic'] = 0xFCDD;
  13051. t['yehmeemisolatedarabic'] = 0xFC58;
  13052. t['yehnoonfinalarabic'] = 0xFC94;
  13053. t['yehthreedotsbelowarabic'] = 0x06D1;
  13054. t['yekorean'] = 0x3156;
  13055. t['yen'] = 0x00A5;
  13056. t['yenmonospace'] = 0xFFE5;
  13057. t['yeokorean'] = 0x3155;
  13058. t['yeorinhieuhkorean'] = 0x3186;
  13059. t['yerahbenyomohebrew'] = 0x05AA;
  13060. t['yerahbenyomolefthebrew'] = 0x05AA;
  13061. t['yericyrillic'] = 0x044B;
  13062. t['yerudieresiscyrillic'] = 0x04F9;
  13063. t['yesieungkorean'] = 0x3181;
  13064. t['yesieungpansioskorean'] = 0x3183;
  13065. t['yesieungsioskorean'] = 0x3182;
  13066. t['yetivhebrew'] = 0x059A;
  13067. t['ygrave'] = 0x1EF3;
  13068. t['yhook'] = 0x01B4;
  13069. t['yhookabove'] = 0x1EF7;
  13070. t['yiarmenian'] = 0x0575;
  13071. t['yicyrillic'] = 0x0457;
  13072. t['yikorean'] = 0x3162;
  13073. t['yinyang'] = 0x262F;
  13074. t['yiwnarmenian'] = 0x0582;
  13075. t['ymonospace'] = 0xFF59;
  13076. t['yod'] = 0x05D9;
  13077. t['yoddagesh'] = 0xFB39;
  13078. t['yoddageshhebrew'] = 0xFB39;
  13079. t['yodhebrew'] = 0x05D9;
  13080. t['yodyodhebrew'] = 0x05F2;
  13081. t['yodyodpatahhebrew'] = 0xFB1F;
  13082. t['yohiragana'] = 0x3088;
  13083. t['yoikorean'] = 0x3189;
  13084. t['yokatakana'] = 0x30E8;
  13085. t['yokatakanahalfwidth'] = 0xFF96;
  13086. t['yokorean'] = 0x315B;
  13087. t['yosmallhiragana'] = 0x3087;
  13088. t['yosmallkatakana'] = 0x30E7;
  13089. t['yosmallkatakanahalfwidth'] = 0xFF6E;
  13090. t['yotgreek'] = 0x03F3;
  13091. t['yoyaekorean'] = 0x3188;
  13092. t['yoyakorean'] = 0x3187;
  13093. t['yoyakthai'] = 0x0E22;
  13094. t['yoyingthai'] = 0x0E0D;
  13095. t['yparen'] = 0x24B4;
  13096. t['ypogegrammeni'] = 0x037A;
  13097. t['ypogegrammenigreekcmb'] = 0x0345;
  13098. t['yr'] = 0x01A6;
  13099. t['yring'] = 0x1E99;
  13100. t['ysuperior'] = 0x02B8;
  13101. t['ytilde'] = 0x1EF9;
  13102. t['yturned'] = 0x028E;
  13103. t['yuhiragana'] = 0x3086;
  13104. t['yuikorean'] = 0x318C;
  13105. t['yukatakana'] = 0x30E6;
  13106. t['yukatakanahalfwidth'] = 0xFF95;
  13107. t['yukorean'] = 0x3160;
  13108. t['yusbigcyrillic'] = 0x046B;
  13109. t['yusbigiotifiedcyrillic'] = 0x046D;
  13110. t['yuslittlecyrillic'] = 0x0467;
  13111. t['yuslittleiotifiedcyrillic'] = 0x0469;
  13112. t['yusmallhiragana'] = 0x3085;
  13113. t['yusmallkatakana'] = 0x30E5;
  13114. t['yusmallkatakanahalfwidth'] = 0xFF6D;
  13115. t['yuyekorean'] = 0x318B;
  13116. t['yuyeokorean'] = 0x318A;
  13117. t['yyabengali'] = 0x09DF;
  13118. t['yyadeva'] = 0x095F;
  13119. t['z'] = 0x007A;
  13120. t['zaarmenian'] = 0x0566;
  13121. t['zacute'] = 0x017A;
  13122. t['zadeva'] = 0x095B;
  13123. t['zagurmukhi'] = 0x0A5B;
  13124. t['zaharabic'] = 0x0638;
  13125. t['zahfinalarabic'] = 0xFEC6;
  13126. t['zahinitialarabic'] = 0xFEC7;
  13127. t['zahiragana'] = 0x3056;
  13128. t['zahmedialarabic'] = 0xFEC8;
  13129. t['zainarabic'] = 0x0632;
  13130. t['zainfinalarabic'] = 0xFEB0;
  13131. t['zakatakana'] = 0x30B6;
  13132. t['zaqefgadolhebrew'] = 0x0595;
  13133. t['zaqefqatanhebrew'] = 0x0594;
  13134. t['zarqahebrew'] = 0x0598;
  13135. t['zayin'] = 0x05D6;
  13136. t['zayindagesh'] = 0xFB36;
  13137. t['zayindageshhebrew'] = 0xFB36;
  13138. t['zayinhebrew'] = 0x05D6;
  13139. t['zbopomofo'] = 0x3117;
  13140. t['zcaron'] = 0x017E;
  13141. t['zcircle'] = 0x24E9;
  13142. t['zcircumflex'] = 0x1E91;
  13143. t['zcurl'] = 0x0291;
  13144. t['zdot'] = 0x017C;
  13145. t['zdotaccent'] = 0x017C;
  13146. t['zdotbelow'] = 0x1E93;
  13147. t['zecyrillic'] = 0x0437;
  13148. t['zedescendercyrillic'] = 0x0499;
  13149. t['zedieresiscyrillic'] = 0x04DF;
  13150. t['zehiragana'] = 0x305C;
  13151. t['zekatakana'] = 0x30BC;
  13152. t['zero'] = 0x0030;
  13153. t['zeroarabic'] = 0x0660;
  13154. t['zerobengali'] = 0x09E6;
  13155. t['zerodeva'] = 0x0966;
  13156. t['zerogujarati'] = 0x0AE6;
  13157. t['zerogurmukhi'] = 0x0A66;
  13158. t['zerohackarabic'] = 0x0660;
  13159. t['zeroinferior'] = 0x2080;
  13160. t['zeromonospace'] = 0xFF10;
  13161. t['zerooldstyle'] = 0xF730;
  13162. t['zeropersian'] = 0x06F0;
  13163. t['zerosuperior'] = 0x2070;
  13164. t['zerothai'] = 0x0E50;
  13165. t['zerowidthjoiner'] = 0xFEFF;
  13166. t['zerowidthnonjoiner'] = 0x200C;
  13167. t['zerowidthspace'] = 0x200B;
  13168. t['zeta'] = 0x03B6;
  13169. t['zhbopomofo'] = 0x3113;
  13170. t['zhearmenian'] = 0x056A;
  13171. t['zhebrevecyrillic'] = 0x04C2;
  13172. t['zhecyrillic'] = 0x0436;
  13173. t['zhedescendercyrillic'] = 0x0497;
  13174. t['zhedieresiscyrillic'] = 0x04DD;
  13175. t['zihiragana'] = 0x3058;
  13176. t['zikatakana'] = 0x30B8;
  13177. t['zinorhebrew'] = 0x05AE;
  13178. t['zlinebelow'] = 0x1E95;
  13179. t['zmonospace'] = 0xFF5A;
  13180. t['zohiragana'] = 0x305E;
  13181. t['zokatakana'] = 0x30BE;
  13182. t['zparen'] = 0x24B5;
  13183. t['zretroflexhook'] = 0x0290;
  13184. t['zstroke'] = 0x01B6;
  13185. t['zuhiragana'] = 0x305A;
  13186. t['zukatakana'] = 0x30BA;
  13187. t['.notdef'] = 0x0000;
  13188. });
  13189. var getDingbatsGlyphsUnicode = getLookupTableFactory(function (t) {
  13190. t['space'] = 0x0020;
  13191. t['a1'] = 0x2701;
  13192. t['a2'] = 0x2702;
  13193. t['a202'] = 0x2703;
  13194. t['a3'] = 0x2704;
  13195. t['a4'] = 0x260E;
  13196. t['a5'] = 0x2706;
  13197. t['a119'] = 0x2707;
  13198. t['a118'] = 0x2708;
  13199. t['a117'] = 0x2709;
  13200. t['a11'] = 0x261B;
  13201. t['a12'] = 0x261E;
  13202. t['a13'] = 0x270C;
  13203. t['a14'] = 0x270D;
  13204. t['a15'] = 0x270E;
  13205. t['a16'] = 0x270F;
  13206. t['a105'] = 0x2710;
  13207. t['a17'] = 0x2711;
  13208. t['a18'] = 0x2712;
  13209. t['a19'] = 0x2713;
  13210. t['a20'] = 0x2714;
  13211. t['a21'] = 0x2715;
  13212. t['a22'] = 0x2716;
  13213. t['a23'] = 0x2717;
  13214. t['a24'] = 0x2718;
  13215. t['a25'] = 0x2719;
  13216. t['a26'] = 0x271A;
  13217. t['a27'] = 0x271B;
  13218. t['a28'] = 0x271C;
  13219. t['a6'] = 0x271D;
  13220. t['a7'] = 0x271E;
  13221. t['a8'] = 0x271F;
  13222. t['a9'] = 0x2720;
  13223. t['a10'] = 0x2721;
  13224. t['a29'] = 0x2722;
  13225. t['a30'] = 0x2723;
  13226. t['a31'] = 0x2724;
  13227. t['a32'] = 0x2725;
  13228. t['a33'] = 0x2726;
  13229. t['a34'] = 0x2727;
  13230. t['a35'] = 0x2605;
  13231. t['a36'] = 0x2729;
  13232. t['a37'] = 0x272A;
  13233. t['a38'] = 0x272B;
  13234. t['a39'] = 0x272C;
  13235. t['a40'] = 0x272D;
  13236. t['a41'] = 0x272E;
  13237. t['a42'] = 0x272F;
  13238. t['a43'] = 0x2730;
  13239. t['a44'] = 0x2731;
  13240. t['a45'] = 0x2732;
  13241. t['a46'] = 0x2733;
  13242. t['a47'] = 0x2734;
  13243. t['a48'] = 0x2735;
  13244. t['a49'] = 0x2736;
  13245. t['a50'] = 0x2737;
  13246. t['a51'] = 0x2738;
  13247. t['a52'] = 0x2739;
  13248. t['a53'] = 0x273A;
  13249. t['a54'] = 0x273B;
  13250. t['a55'] = 0x273C;
  13251. t['a56'] = 0x273D;
  13252. t['a57'] = 0x273E;
  13253. t['a58'] = 0x273F;
  13254. t['a59'] = 0x2740;
  13255. t['a60'] = 0x2741;
  13256. t['a61'] = 0x2742;
  13257. t['a62'] = 0x2743;
  13258. t['a63'] = 0x2744;
  13259. t['a64'] = 0x2745;
  13260. t['a65'] = 0x2746;
  13261. t['a66'] = 0x2747;
  13262. t['a67'] = 0x2748;
  13263. t['a68'] = 0x2749;
  13264. t['a69'] = 0x274A;
  13265. t['a70'] = 0x274B;
  13266. t['a71'] = 0x25CF;
  13267. t['a72'] = 0x274D;
  13268. t['a73'] = 0x25A0;
  13269. t['a74'] = 0x274F;
  13270. t['a203'] = 0x2750;
  13271. t['a75'] = 0x2751;
  13272. t['a204'] = 0x2752;
  13273. t['a76'] = 0x25B2;
  13274. t['a77'] = 0x25BC;
  13275. t['a78'] = 0x25C6;
  13276. t['a79'] = 0x2756;
  13277. t['a81'] = 0x25D7;
  13278. t['a82'] = 0x2758;
  13279. t['a83'] = 0x2759;
  13280. t['a84'] = 0x275A;
  13281. t['a97'] = 0x275B;
  13282. t['a98'] = 0x275C;
  13283. t['a99'] = 0x275D;
  13284. t['a100'] = 0x275E;
  13285. t['a101'] = 0x2761;
  13286. t['a102'] = 0x2762;
  13287. t['a103'] = 0x2763;
  13288. t['a104'] = 0x2764;
  13289. t['a106'] = 0x2765;
  13290. t['a107'] = 0x2766;
  13291. t['a108'] = 0x2767;
  13292. t['a112'] = 0x2663;
  13293. t['a111'] = 0x2666;
  13294. t['a110'] = 0x2665;
  13295. t['a109'] = 0x2660;
  13296. t['a120'] = 0x2460;
  13297. t['a121'] = 0x2461;
  13298. t['a122'] = 0x2462;
  13299. t['a123'] = 0x2463;
  13300. t['a124'] = 0x2464;
  13301. t['a125'] = 0x2465;
  13302. t['a126'] = 0x2466;
  13303. t['a127'] = 0x2467;
  13304. t['a128'] = 0x2468;
  13305. t['a129'] = 0x2469;
  13306. t['a130'] = 0x2776;
  13307. t['a131'] = 0x2777;
  13308. t['a132'] = 0x2778;
  13309. t['a133'] = 0x2779;
  13310. t['a134'] = 0x277A;
  13311. t['a135'] = 0x277B;
  13312. t['a136'] = 0x277C;
  13313. t['a137'] = 0x277D;
  13314. t['a138'] = 0x277E;
  13315. t['a139'] = 0x277F;
  13316. t['a140'] = 0x2780;
  13317. t['a141'] = 0x2781;
  13318. t['a142'] = 0x2782;
  13319. t['a143'] = 0x2783;
  13320. t['a144'] = 0x2784;
  13321. t['a145'] = 0x2785;
  13322. t['a146'] = 0x2786;
  13323. t['a147'] = 0x2787;
  13324. t['a148'] = 0x2788;
  13325. t['a149'] = 0x2789;
  13326. t['a150'] = 0x278A;
  13327. t['a151'] = 0x278B;
  13328. t['a152'] = 0x278C;
  13329. t['a153'] = 0x278D;
  13330. t['a154'] = 0x278E;
  13331. t['a155'] = 0x278F;
  13332. t['a156'] = 0x2790;
  13333. t['a157'] = 0x2791;
  13334. t['a158'] = 0x2792;
  13335. t['a159'] = 0x2793;
  13336. t['a160'] = 0x2794;
  13337. t['a161'] = 0x2192;
  13338. t['a163'] = 0x2194;
  13339. t['a164'] = 0x2195;
  13340. t['a196'] = 0x2798;
  13341. t['a165'] = 0x2799;
  13342. t['a192'] = 0x279A;
  13343. t['a166'] = 0x279B;
  13344. t['a167'] = 0x279C;
  13345. t['a168'] = 0x279D;
  13346. t['a169'] = 0x279E;
  13347. t['a170'] = 0x279F;
  13348. t['a171'] = 0x27A0;
  13349. t['a172'] = 0x27A1;
  13350. t['a173'] = 0x27A2;
  13351. t['a162'] = 0x27A3;
  13352. t['a174'] = 0x27A4;
  13353. t['a175'] = 0x27A5;
  13354. t['a176'] = 0x27A6;
  13355. t['a177'] = 0x27A7;
  13356. t['a178'] = 0x27A8;
  13357. t['a179'] = 0x27A9;
  13358. t['a193'] = 0x27AA;
  13359. t['a180'] = 0x27AB;
  13360. t['a199'] = 0x27AC;
  13361. t['a181'] = 0x27AD;
  13362. t['a200'] = 0x27AE;
  13363. t['a182'] = 0x27AF;
  13364. t['a201'] = 0x27B1;
  13365. t['a183'] = 0x27B2;
  13366. t['a184'] = 0x27B3;
  13367. t['a197'] = 0x27B4;
  13368. t['a185'] = 0x27B5;
  13369. t['a194'] = 0x27B6;
  13370. t['a198'] = 0x27B7;
  13371. t['a186'] = 0x27B8;
  13372. t['a195'] = 0x27B9;
  13373. t['a187'] = 0x27BA;
  13374. t['a188'] = 0x27BB;
  13375. t['a189'] = 0x27BC;
  13376. t['a190'] = 0x27BD;
  13377. t['a191'] = 0x27BE;
  13378. t['a89'] = 0x2768;
  13379. // 0xF8D7
  13380. t['a90'] = 0x2769;
  13381. // 0xF8D8
  13382. t['a93'] = 0x276A;
  13383. // 0xF8D9
  13384. t['a94'] = 0x276B;
  13385. // 0xF8DA
  13386. t['a91'] = 0x276C;
  13387. // 0xF8DB
  13388. t['a92'] = 0x276D;
  13389. // 0xF8DC
  13390. t['a205'] = 0x276E;
  13391. // 0xF8DD
  13392. t['a85'] = 0x276F;
  13393. // 0xF8DE
  13394. t['a206'] = 0x2770;
  13395. // 0xF8DF
  13396. t['a86'] = 0x2771;
  13397. // 0xF8E0
  13398. t['a87'] = 0x2772;
  13399. // 0xF8E1
  13400. t['a88'] = 0x2773;
  13401. // 0xF8E2
  13402. t['a95'] = 0x2774;
  13403. // 0xF8E3
  13404. t['a96'] = 0x2775;
  13405. // 0xF8E4
  13406. t['.notdef'] = 0x0000;
  13407. });
  13408. exports.getGlyphsUnicode = getGlyphsUnicode;
  13409. exports.getDingbatsGlyphsUnicode = getDingbatsGlyphsUnicode;
  13410. }));
  13411. (function (root, factory) {
  13412. factory(root.pdfjsCoreJbig2 = {}, root.pdfjsSharedUtil, root.pdfjsCoreArithmeticDecoder);
  13413. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  13414. var error = sharedUtil.error;
  13415. var log2 = sharedUtil.log2;
  13416. var readInt8 = sharedUtil.readInt8;
  13417. var readUint16 = sharedUtil.readUint16;
  13418. var readUint32 = sharedUtil.readUint32;
  13419. var shadow = sharedUtil.shadow;
  13420. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  13421. var Jbig2Image = function Jbig2ImageClosure() {
  13422. // Utility data structures
  13423. function ContextCache() {
  13424. }
  13425. ContextCache.prototype = {
  13426. getContexts: function (id) {
  13427. if (id in this) {
  13428. return this[id];
  13429. }
  13430. return this[id] = new Int8Array(1 << 16);
  13431. }
  13432. };
  13433. function DecodingContext(data, start, end) {
  13434. this.data = data;
  13435. this.start = start;
  13436. this.end = end;
  13437. }
  13438. DecodingContext.prototype = {
  13439. get decoder() {
  13440. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  13441. return shadow(this, 'decoder', decoder);
  13442. },
  13443. get contextCache() {
  13444. var cache = new ContextCache();
  13445. return shadow(this, 'contextCache', cache);
  13446. }
  13447. };
  13448. // Annex A. Arithmetic Integer Decoding Procedure
  13449. // A.2 Procedure for decoding values
  13450. function decodeInteger(contextCache, procedure, decoder) {
  13451. var contexts = contextCache.getContexts(procedure);
  13452. var prev = 1;
  13453. function readBits(length) {
  13454. var v = 0;
  13455. for (var i = 0; i < length; i++) {
  13456. var bit = decoder.readBit(contexts, prev);
  13457. prev = prev < 256 ? prev << 1 | bit : (prev << 1 | bit) & 511 | 256;
  13458. v = v << 1 | bit;
  13459. }
  13460. return v >>> 0;
  13461. }
  13462. var sign = readBits(1);
  13463. var value = readBits(1) ? readBits(1) ? readBits(1) ? readBits(1) ? readBits(1) ? readBits(32) + 4436 : readBits(12) + 340 : readBits(8) + 84 : readBits(6) + 20 : readBits(4) + 4 : readBits(2);
  13464. return sign === 0 ? value : value > 0 ? -value : null;
  13465. }
  13466. // A.3 The IAID decoding procedure
  13467. function decodeIAID(contextCache, decoder, codeLength) {
  13468. var contexts = contextCache.getContexts('IAID');
  13469. var prev = 1;
  13470. for (var i = 0; i < codeLength; i++) {
  13471. var bit = decoder.readBit(contexts, prev);
  13472. prev = prev << 1 | bit;
  13473. }
  13474. if (codeLength < 31) {
  13475. return prev & (1 << codeLength) - 1;
  13476. }
  13477. return prev & 0x7FFFFFFF;
  13478. }
  13479. // 7.3 Segment types
  13480. var SegmentTypes = [
  13481. 'SymbolDictionary',
  13482. null,
  13483. null,
  13484. null,
  13485. 'IntermediateTextRegion',
  13486. null,
  13487. 'ImmediateTextRegion',
  13488. 'ImmediateLosslessTextRegion',
  13489. null,
  13490. null,
  13491. null,
  13492. null,
  13493. null,
  13494. null,
  13495. null,
  13496. null,
  13497. 'patternDictionary',
  13498. null,
  13499. null,
  13500. null,
  13501. 'IntermediateHalftoneRegion',
  13502. null,
  13503. 'ImmediateHalftoneRegion',
  13504. 'ImmediateLosslessHalftoneRegion',
  13505. null,
  13506. null,
  13507. null,
  13508. null,
  13509. null,
  13510. null,
  13511. null,
  13512. null,
  13513. null,
  13514. null,
  13515. null,
  13516. null,
  13517. 'IntermediateGenericRegion',
  13518. null,
  13519. 'ImmediateGenericRegion',
  13520. 'ImmediateLosslessGenericRegion',
  13521. 'IntermediateGenericRefinementRegion',
  13522. null,
  13523. 'ImmediateGenericRefinementRegion',
  13524. 'ImmediateLosslessGenericRefinementRegion',
  13525. null,
  13526. null,
  13527. null,
  13528. null,
  13529. 'PageInformation',
  13530. 'EndOfPage',
  13531. 'EndOfStripe',
  13532. 'EndOfFile',
  13533. 'Profiles',
  13534. 'Tables',
  13535. null,
  13536. null,
  13537. null,
  13538. null,
  13539. null,
  13540. null,
  13541. null,
  13542. null,
  13543. 'Extension'
  13544. ];
  13545. var CodingTemplates = [
  13546. [
  13547. {
  13548. x: -1,
  13549. y: -2
  13550. },
  13551. {
  13552. x: 0,
  13553. y: -2
  13554. },
  13555. {
  13556. x: 1,
  13557. y: -2
  13558. },
  13559. {
  13560. x: -2,
  13561. y: -1
  13562. },
  13563. {
  13564. x: -1,
  13565. y: -1
  13566. },
  13567. {
  13568. x: 0,
  13569. y: -1
  13570. },
  13571. {
  13572. x: 1,
  13573. y: -1
  13574. },
  13575. {
  13576. x: 2,
  13577. y: -1
  13578. },
  13579. {
  13580. x: -4,
  13581. y: 0
  13582. },
  13583. {
  13584. x: -3,
  13585. y: 0
  13586. },
  13587. {
  13588. x: -2,
  13589. y: 0
  13590. },
  13591. {
  13592. x: -1,
  13593. y: 0
  13594. }
  13595. ],
  13596. [
  13597. {
  13598. x: -1,
  13599. y: -2
  13600. },
  13601. {
  13602. x: 0,
  13603. y: -2
  13604. },
  13605. {
  13606. x: 1,
  13607. y: -2
  13608. },
  13609. {
  13610. x: 2,
  13611. y: -2
  13612. },
  13613. {
  13614. x: -2,
  13615. y: -1
  13616. },
  13617. {
  13618. x: -1,
  13619. y: -1
  13620. },
  13621. {
  13622. x: 0,
  13623. y: -1
  13624. },
  13625. {
  13626. x: 1,
  13627. y: -1
  13628. },
  13629. {
  13630. x: 2,
  13631. y: -1
  13632. },
  13633. {
  13634. x: -3,
  13635. y: 0
  13636. },
  13637. {
  13638. x: -2,
  13639. y: 0
  13640. },
  13641. {
  13642. x: -1,
  13643. y: 0
  13644. }
  13645. ],
  13646. [
  13647. {
  13648. x: -1,
  13649. y: -2
  13650. },
  13651. {
  13652. x: 0,
  13653. y: -2
  13654. },
  13655. {
  13656. x: 1,
  13657. y: -2
  13658. },
  13659. {
  13660. x: -2,
  13661. y: -1
  13662. },
  13663. {
  13664. x: -1,
  13665. y: -1
  13666. },
  13667. {
  13668. x: 0,
  13669. y: -1
  13670. },
  13671. {
  13672. x: 1,
  13673. y: -1
  13674. },
  13675. {
  13676. x: -2,
  13677. y: 0
  13678. },
  13679. {
  13680. x: -1,
  13681. y: 0
  13682. }
  13683. ],
  13684. [
  13685. {
  13686. x: -3,
  13687. y: -1
  13688. },
  13689. {
  13690. x: -2,
  13691. y: -1
  13692. },
  13693. {
  13694. x: -1,
  13695. y: -1
  13696. },
  13697. {
  13698. x: 0,
  13699. y: -1
  13700. },
  13701. {
  13702. x: 1,
  13703. y: -1
  13704. },
  13705. {
  13706. x: -4,
  13707. y: 0
  13708. },
  13709. {
  13710. x: -3,
  13711. y: 0
  13712. },
  13713. {
  13714. x: -2,
  13715. y: 0
  13716. },
  13717. {
  13718. x: -1,
  13719. y: 0
  13720. }
  13721. ]
  13722. ];
  13723. var RefinementTemplates = [
  13724. {
  13725. coding: [
  13726. {
  13727. x: 0,
  13728. y: -1
  13729. },
  13730. {
  13731. x: 1,
  13732. y: -1
  13733. },
  13734. {
  13735. x: -1,
  13736. y: 0
  13737. }
  13738. ],
  13739. reference: [
  13740. {
  13741. x: 0,
  13742. y: -1
  13743. },
  13744. {
  13745. x: 1,
  13746. y: -1
  13747. },
  13748. {
  13749. x: -1,
  13750. y: 0
  13751. },
  13752. {
  13753. x: 0,
  13754. y: 0
  13755. },
  13756. {
  13757. x: 1,
  13758. y: 0
  13759. },
  13760. {
  13761. x: -1,
  13762. y: 1
  13763. },
  13764. {
  13765. x: 0,
  13766. y: 1
  13767. },
  13768. {
  13769. x: 1,
  13770. y: 1
  13771. }
  13772. ]
  13773. },
  13774. {
  13775. coding: [
  13776. {
  13777. x: -1,
  13778. y: -1
  13779. },
  13780. {
  13781. x: 0,
  13782. y: -1
  13783. },
  13784. {
  13785. x: 1,
  13786. y: -1
  13787. },
  13788. {
  13789. x: -1,
  13790. y: 0
  13791. }
  13792. ],
  13793. reference: [
  13794. {
  13795. x: 0,
  13796. y: -1
  13797. },
  13798. {
  13799. x: -1,
  13800. y: 0
  13801. },
  13802. {
  13803. x: 0,
  13804. y: 0
  13805. },
  13806. {
  13807. x: 1,
  13808. y: 0
  13809. },
  13810. {
  13811. x: 0,
  13812. y: 1
  13813. },
  13814. {
  13815. x: 1,
  13816. y: 1
  13817. }
  13818. ]
  13819. }
  13820. ];
  13821. // See 6.2.5.7 Decoding the bitmap.
  13822. var ReusedContexts = [
  13823. 0x9B25,
  13824. // 10011 0110010 0101
  13825. 0x0795,
  13826. // 0011 110010 101
  13827. 0x00E5,
  13828. // 001 11001 01
  13829. 0x0195
  13830. ];
  13831. // 011001 0101
  13832. var RefinementReusedContexts = [
  13833. 0x0020,
  13834. // '000' + '0' (coding) + '00010000' + '0' (reference)
  13835. 0x0008
  13836. ];
  13837. // '0000' + '001000'
  13838. function decodeBitmapTemplate0(width, height, decodingContext) {
  13839. var decoder = decodingContext.decoder;
  13840. var contexts = decodingContext.contextCache.getContexts('GB');
  13841. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  13842. // ...ooooo....
  13843. // ..ooooooo... Context template for current pixel (X)
  13844. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  13845. var OLD_PIXEL_MASK = 0x7BF7;
  13846. // 01111 0111111 0111
  13847. for (i = 0; i < height; i++) {
  13848. row = bitmap[i] = new Uint8Array(width);
  13849. row1 = i < 1 ? row : bitmap[i - 1];
  13850. row2 = i < 2 ? row : bitmap[i - 2];
  13851. // At the beginning of each row:
  13852. // Fill contextLabel with pixels that are above/right of (X)
  13853. contextLabel = row2[0] << 13 | row2[1] << 12 | row2[2] << 11 | row1[0] << 7 | row1[1] << 6 | row1[2] << 5 | row1[3] << 4;
  13854. for (j = 0; j < width; j++) {
  13855. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  13856. // At each pixel: Clear contextLabel pixels that are shifted
  13857. // out of the context, then add new ones.
  13858. contextLabel = (contextLabel & OLD_PIXEL_MASK) << 1 | (j + 3 < width ? row2[j + 3] << 11 : 0) | (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  13859. }
  13860. }
  13861. return bitmap;
  13862. }
  13863. // 6.2 Generic Region Decoding Procedure
  13864. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at, decodingContext) {
  13865. if (mmr) {
  13866. error('JBIG2 error: MMR encoding is not supported');
  13867. }
  13868. // Use optimized version for the most common case
  13869. if (templateIndex === 0 && !skip && !prediction && at.length === 4 && at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 && at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  13870. return decodeBitmapTemplate0(width, height, decodingContext);
  13871. }
  13872. var useskip = !!skip;
  13873. var template = CodingTemplates[templateIndex].concat(at);
  13874. // Sorting is non-standard, and it is not required. But sorting increases
  13875. // the number of template bits that can be reused from the previous
  13876. // contextLabel in the main loop.
  13877. template.sort(function (a, b) {
  13878. return a.y - b.y || a.x - b.x;
  13879. });
  13880. var templateLength = template.length;
  13881. var templateX = new Int8Array(templateLength);
  13882. var templateY = new Int8Array(templateLength);
  13883. var changingTemplateEntries = [];
  13884. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  13885. var c, k;
  13886. for (k = 0; k < templateLength; k++) {
  13887. templateX[k] = template[k].x;
  13888. templateY[k] = template[k].y;
  13889. minX = Math.min(minX, template[k].x);
  13890. maxX = Math.max(maxX, template[k].x);
  13891. minY = Math.min(minY, template[k].y);
  13892. // Check if the template pixel appears in two consecutive context labels,
  13893. // so it can be reused. Otherwise, we add it to the list of changing
  13894. // template entries.
  13895. if (k < templateLength - 1 && template[k].y === template[k + 1].y && template[k].x === template[k + 1].x - 1) {
  13896. reuseMask |= 1 << templateLength - 1 - k;
  13897. } else {
  13898. changingTemplateEntries.push(k);
  13899. }
  13900. }
  13901. var changingEntriesLength = changingTemplateEntries.length;
  13902. var changingTemplateX = new Int8Array(changingEntriesLength);
  13903. var changingTemplateY = new Int8Array(changingEntriesLength);
  13904. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  13905. for (c = 0; c < changingEntriesLength; c++) {
  13906. k = changingTemplateEntries[c];
  13907. changingTemplateX[c] = template[k].x;
  13908. changingTemplateY[c] = template[k].y;
  13909. changingTemplateBit[c] = 1 << templateLength - 1 - k;
  13910. }
  13911. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  13912. var sbb_left = -minX;
  13913. var sbb_top = -minY;
  13914. var sbb_right = width - maxX;
  13915. var pseudoPixelContext = ReusedContexts[templateIndex];
  13916. var row = new Uint8Array(width);
  13917. var bitmap = [];
  13918. var decoder = decodingContext.decoder;
  13919. var contexts = decodingContext.contextCache.getContexts('GB');
  13920. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  13921. for (var i = 0; i < height; i++) {
  13922. if (prediction) {
  13923. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  13924. ltp ^= sltp;
  13925. if (ltp) {
  13926. bitmap.push(row);
  13927. // duplicate previous row
  13928. continue;
  13929. }
  13930. }
  13931. row = new Uint8Array(row);
  13932. bitmap.push(row);
  13933. for (j = 0; j < width; j++) {
  13934. if (useskip && skip[i][j]) {
  13935. row[j] = 0;
  13936. continue;
  13937. }
  13938. // Are we in the middle of a scanline, so we can reuse contextLabel
  13939. // bits?
  13940. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  13941. // If yes, we can just shift the bits that are reusable and only
  13942. // fetch the remaining ones.
  13943. contextLabel = contextLabel << 1 & reuseMask;
  13944. for (k = 0; k < changingEntriesLength; k++) {
  13945. i0 = i + changingTemplateY[k];
  13946. j0 = j + changingTemplateX[k];
  13947. bit = bitmap[i0][j0];
  13948. if (bit) {
  13949. bit = changingTemplateBit[k];
  13950. contextLabel |= bit;
  13951. }
  13952. }
  13953. } else {
  13954. // compute the contextLabel from scratch
  13955. contextLabel = 0;
  13956. shift = templateLength - 1;
  13957. for (k = 0; k < templateLength; k++, shift--) {
  13958. j0 = j + templateX[k];
  13959. if (j0 >= 0 && j0 < width) {
  13960. i0 = i + templateY[k];
  13961. if (i0 >= 0) {
  13962. bit = bitmap[i0][j0];
  13963. if (bit) {
  13964. contextLabel |= bit << shift;
  13965. }
  13966. }
  13967. }
  13968. }
  13969. }
  13970. var pixel = decoder.readBit(contexts, contextLabel);
  13971. row[j] = pixel;
  13972. }
  13973. }
  13974. return bitmap;
  13975. }
  13976. // 6.3.2 Generic Refinement Region Decoding Procedure
  13977. function decodeRefinement(width, height, templateIndex, referenceBitmap, offsetX, offsetY, prediction, at, decodingContext) {
  13978. var codingTemplate = RefinementTemplates[templateIndex].coding;
  13979. if (templateIndex === 0) {
  13980. codingTemplate = codingTemplate.concat([at[0]]);
  13981. }
  13982. var codingTemplateLength = codingTemplate.length;
  13983. var codingTemplateX = new Int32Array(codingTemplateLength);
  13984. var codingTemplateY = new Int32Array(codingTemplateLength);
  13985. var k;
  13986. for (k = 0; k < codingTemplateLength; k++) {
  13987. codingTemplateX[k] = codingTemplate[k].x;
  13988. codingTemplateY[k] = codingTemplate[k].y;
  13989. }
  13990. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  13991. if (templateIndex === 0) {
  13992. referenceTemplate = referenceTemplate.concat([at[1]]);
  13993. }
  13994. var referenceTemplateLength = referenceTemplate.length;
  13995. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  13996. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  13997. for (k = 0; k < referenceTemplateLength; k++) {
  13998. referenceTemplateX[k] = referenceTemplate[k].x;
  13999. referenceTemplateY[k] = referenceTemplate[k].y;
  14000. }
  14001. var referenceWidth = referenceBitmap[0].length;
  14002. var referenceHeight = referenceBitmap.length;
  14003. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  14004. var bitmap = [];
  14005. var decoder = decodingContext.decoder;
  14006. var contexts = decodingContext.contextCache.getContexts('GR');
  14007. var ltp = 0;
  14008. for (var i = 0; i < height; i++) {
  14009. if (prediction) {
  14010. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  14011. ltp ^= sltp;
  14012. if (ltp) {
  14013. error('JBIG2 error: prediction is not supported');
  14014. }
  14015. }
  14016. var row = new Uint8Array(width);
  14017. bitmap.push(row);
  14018. for (var j = 0; j < width; j++) {
  14019. var i0, j0;
  14020. var contextLabel = 0;
  14021. for (k = 0; k < codingTemplateLength; k++) {
  14022. i0 = i + codingTemplateY[k];
  14023. j0 = j + codingTemplateX[k];
  14024. if (i0 < 0 || j0 < 0 || j0 >= width) {
  14025. contextLabel <<= 1;
  14026. } else
  14027. // out of bound pixel
  14028. {
  14029. contextLabel = contextLabel << 1 | bitmap[i0][j0];
  14030. }
  14031. }
  14032. for (k = 0; k < referenceTemplateLength; k++) {
  14033. i0 = i + referenceTemplateY[k] + offsetY;
  14034. j0 = j + referenceTemplateX[k] + offsetX;
  14035. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 || j0 >= referenceWidth) {
  14036. contextLabel <<= 1;
  14037. } else
  14038. // out of bound pixel
  14039. {
  14040. contextLabel = contextLabel << 1 | referenceBitmap[i0][j0];
  14041. }
  14042. }
  14043. var pixel = decoder.readBit(contexts, contextLabel);
  14044. row[j] = pixel;
  14045. }
  14046. }
  14047. return bitmap;
  14048. }
  14049. // 6.5.5 Decoding the symbol dictionary
  14050. function decodeSymbolDictionary(huffman, refinement, symbols, numberOfNewSymbols, numberOfExportedSymbols, huffmanTables, templateIndex, at, refinementTemplateIndex, refinementAt, decodingContext) {
  14051. if (huffman) {
  14052. error('JBIG2 error: huffman is not supported');
  14053. }
  14054. var newSymbols = [];
  14055. var currentHeight = 0;
  14056. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  14057. var decoder = decodingContext.decoder;
  14058. var contextCache = decodingContext.contextCache;
  14059. while (newSymbols.length < numberOfNewSymbols) {
  14060. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder);
  14061. // 6.5.6
  14062. currentHeight += deltaHeight;
  14063. var currentWidth = 0;
  14064. var totalWidth = 0;
  14065. while (true) {
  14066. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder);
  14067. // 6.5.7
  14068. if (deltaWidth === null) {
  14069. break;
  14070. }
  14071. // OOB
  14072. currentWidth += deltaWidth;
  14073. totalWidth += currentWidth;
  14074. var bitmap;
  14075. if (refinement) {
  14076. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  14077. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  14078. if (numberOfInstances > 1) {
  14079. bitmap = decodeTextRegion(huffman, refinement, currentWidth, currentHeight, 0, numberOfInstances, 1, //strip size
  14080. symbols.concat(newSymbols), symbolCodeLength, 0, //transposed
  14081. 0, //ds offset
  14082. 1, //top left 7.4.3.1.1
  14083. 0, //OR operator
  14084. huffmanTables, refinementTemplateIndex, refinementAt, decodingContext);
  14085. } else {
  14086. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  14087. var rdx = decodeInteger(contextCache, 'IARDX', decoder);
  14088. // 6.4.11.3
  14089. var rdy = decodeInteger(contextCache, 'IARDY', decoder);
  14090. // 6.4.11.4
  14091. var symbol = symbolId < symbols.length ? symbols[symbolId] : newSymbols[symbolId - symbols.length];
  14092. bitmap = decodeRefinement(currentWidth, currentHeight, refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt, decodingContext);
  14093. }
  14094. } else {
  14095. // 6.5.8.1 Direct-coded symbol bitmap
  14096. bitmap = decodeBitmap(false, currentWidth, currentHeight, templateIndex, false, null, at, decodingContext);
  14097. }
  14098. newSymbols.push(bitmap);
  14099. }
  14100. }
  14101. // 6.5.10 Exported symbols
  14102. var exportedSymbols = [];
  14103. var flags = [], currentFlag = false;
  14104. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  14105. while (flags.length < totalSymbolsLength) {
  14106. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  14107. while (runLength--) {
  14108. flags.push(currentFlag);
  14109. }
  14110. currentFlag = !currentFlag;
  14111. }
  14112. for (var i = 0, ii = symbols.length; i < ii; i++) {
  14113. if (flags[i]) {
  14114. exportedSymbols.push(symbols[i]);
  14115. }
  14116. }
  14117. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  14118. if (flags[i]) {
  14119. exportedSymbols.push(newSymbols[j]);
  14120. }
  14121. }
  14122. return exportedSymbols;
  14123. }
  14124. function decodeTextRegion(huffman, refinement, width, height, defaultPixelValue, numberOfSymbolInstances, stripSize, inputSymbols, symbolCodeLength, transposed, dsOffset, referenceCorner, combinationOperator, huffmanTables, refinementTemplateIndex, refinementAt, decodingContext) {
  14125. if (huffman) {
  14126. error('JBIG2 error: huffman is not supported');
  14127. }
  14128. // Prepare bitmap
  14129. var bitmap = [];
  14130. var i, row;
  14131. for (i = 0; i < height; i++) {
  14132. row = new Uint8Array(width);
  14133. if (defaultPixelValue) {
  14134. for (var j = 0; j < width; j++) {
  14135. row[j] = defaultPixelValue;
  14136. }
  14137. }
  14138. bitmap.push(row);
  14139. }
  14140. var decoder = decodingContext.decoder;
  14141. var contextCache = decodingContext.contextCache;
  14142. var stripT = -decodeInteger(contextCache, 'IADT', decoder);
  14143. // 6.4.6
  14144. var firstS = 0;
  14145. i = 0;
  14146. while (i < numberOfSymbolInstances) {
  14147. var deltaT = decodeInteger(contextCache, 'IADT', decoder);
  14148. // 6.4.6
  14149. stripT += deltaT;
  14150. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder);
  14151. // 6.4.7
  14152. firstS += deltaFirstS;
  14153. var currentS = firstS;
  14154. do {
  14155. var currentT = stripSize === 1 ? 0 : decodeInteger(contextCache, 'IAIT', decoder);
  14156. // 6.4.9
  14157. var t = stripSize * stripT + currentT;
  14158. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  14159. var applyRefinement = refinement && decodeInteger(contextCache, 'IARI', decoder);
  14160. var symbolBitmap = inputSymbols[symbolId];
  14161. var symbolWidth = symbolBitmap[0].length;
  14162. var symbolHeight = symbolBitmap.length;
  14163. if (applyRefinement) {
  14164. var rdw = decodeInteger(contextCache, 'IARDW', decoder);
  14165. // 6.4.11.1
  14166. var rdh = decodeInteger(contextCache, 'IARDH', decoder);
  14167. // 6.4.11.2
  14168. var rdx = decodeInteger(contextCache, 'IARDX', decoder);
  14169. // 6.4.11.3
  14170. var rdy = decodeInteger(contextCache, 'IARDY', decoder);
  14171. // 6.4.11.4
  14172. symbolWidth += rdw;
  14173. symbolHeight += rdh;
  14174. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight, refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx, (rdh >> 1) + rdy, false, refinementAt, decodingContext);
  14175. }
  14176. var offsetT = t - (referenceCorner & 1 ? 0 : symbolHeight);
  14177. var offsetS = currentS - (referenceCorner & 2 ? symbolWidth : 0);
  14178. var s2, t2, symbolRow;
  14179. if (transposed) {
  14180. // Place Symbol Bitmap from T1,S1
  14181. for (s2 = 0; s2 < symbolHeight; s2++) {
  14182. row = bitmap[offsetS + s2];
  14183. if (!row) {
  14184. continue;
  14185. }
  14186. symbolRow = symbolBitmap[s2];
  14187. // To ignore Parts of Symbol bitmap which goes
  14188. // outside bitmap region
  14189. var maxWidth = Math.min(width - offsetT, symbolWidth);
  14190. switch (combinationOperator) {
  14191. case 0:
  14192. // OR
  14193. for (t2 = 0; t2 < maxWidth; t2++) {
  14194. row[offsetT + t2] |= symbolRow[t2];
  14195. }
  14196. break;
  14197. case 2:
  14198. // XOR
  14199. for (t2 = 0; t2 < maxWidth; t2++) {
  14200. row[offsetT + t2] ^= symbolRow[t2];
  14201. }
  14202. break;
  14203. default:
  14204. error('JBIG2 error: operator ' + combinationOperator + ' is not supported');
  14205. }
  14206. }
  14207. currentS += symbolHeight - 1;
  14208. } else {
  14209. for (t2 = 0; t2 < symbolHeight; t2++) {
  14210. row = bitmap[offsetT + t2];
  14211. if (!row) {
  14212. continue;
  14213. }
  14214. symbolRow = symbolBitmap[t2];
  14215. switch (combinationOperator) {
  14216. case 0:
  14217. // OR
  14218. for (s2 = 0; s2 < symbolWidth; s2++) {
  14219. row[offsetS + s2] |= symbolRow[s2];
  14220. }
  14221. break;
  14222. case 2:
  14223. // XOR
  14224. for (s2 = 0; s2 < symbolWidth; s2++) {
  14225. row[offsetS + s2] ^= symbolRow[s2];
  14226. }
  14227. break;
  14228. default:
  14229. error('JBIG2 error: operator ' + combinationOperator + ' is not supported');
  14230. }
  14231. }
  14232. currentS += symbolWidth - 1;
  14233. }
  14234. i++;
  14235. var deltaS = decodeInteger(contextCache, 'IADS', decoder);
  14236. // 6.4.8
  14237. if (deltaS === null) {
  14238. break;
  14239. }
  14240. // OOB
  14241. currentS += deltaS + dsOffset;
  14242. } while (true);
  14243. }
  14244. return bitmap;
  14245. }
  14246. function readSegmentHeader(data, start) {
  14247. var segmentHeader = {};
  14248. segmentHeader.number = readUint32(data, start);
  14249. var flags = data[start + 4];
  14250. var segmentType = flags & 0x3F;
  14251. if (!SegmentTypes[segmentType]) {
  14252. error('JBIG2 error: invalid segment type: ' + segmentType);
  14253. }
  14254. segmentHeader.type = segmentType;
  14255. segmentHeader.typeName = SegmentTypes[segmentType];
  14256. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  14257. var pageAssociationFieldSize = !!(flags & 0x40);
  14258. var referredFlags = data[start + 5];
  14259. var referredToCount = referredFlags >> 5 & 7;
  14260. var retainBits = [referredFlags & 31];
  14261. var position = start + 6;
  14262. if (referredFlags === 7) {
  14263. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  14264. position += 3;
  14265. var bytes = referredToCount + 7 >> 3;
  14266. retainBits[0] = data[position++];
  14267. while (--bytes > 0) {
  14268. retainBits.push(data[position++]);
  14269. }
  14270. } else if (referredFlags === 5 || referredFlags === 6) {
  14271. error('JBIG2 error: invalid referred-to flags');
  14272. }
  14273. segmentHeader.retainBits = retainBits;
  14274. var referredToSegmentNumberSize = segmentHeader.number <= 256 ? 1 : segmentHeader.number <= 65536 ? 2 : 4;
  14275. var referredTo = [];
  14276. var i, ii;
  14277. for (i = 0; i < referredToCount; i++) {
  14278. var number = referredToSegmentNumberSize === 1 ? data[position] : referredToSegmentNumberSize === 2 ? readUint16(data, position) : readUint32(data, position);
  14279. referredTo.push(number);
  14280. position += referredToSegmentNumberSize;
  14281. }
  14282. segmentHeader.referredTo = referredTo;
  14283. if (!pageAssociationFieldSize) {
  14284. segmentHeader.pageAssociation = data[position++];
  14285. } else {
  14286. segmentHeader.pageAssociation = readUint32(data, position);
  14287. position += 4;
  14288. }
  14289. segmentHeader.length = readUint32(data, position);
  14290. position += 4;
  14291. if (segmentHeader.length === 0xFFFFFFFF) {
  14292. // 7.2.7 Segment data length, unknown segment length
  14293. if (segmentType === 38) {
  14294. // ImmediateGenericRegion
  14295. var genericRegionInfo = readRegionSegmentInformation(data, position);
  14296. var genericRegionSegmentFlags = data[position + RegionSegmentInformationFieldLength];
  14297. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  14298. // searching for the segment end
  14299. var searchPatternLength = 6;
  14300. var searchPattern = new Uint8Array(searchPatternLength);
  14301. if (!genericRegionMmr) {
  14302. searchPattern[0] = 0xFF;
  14303. searchPattern[1] = 0xAC;
  14304. }
  14305. searchPattern[2] = genericRegionInfo.height >>> 24 & 0xFF;
  14306. searchPattern[3] = genericRegionInfo.height >> 16 & 0xFF;
  14307. searchPattern[4] = genericRegionInfo.height >> 8 & 0xFF;
  14308. searchPattern[5] = genericRegionInfo.height & 0xFF;
  14309. for (i = position, ii = data.length; i < ii; i++) {
  14310. var j = 0;
  14311. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  14312. j++;
  14313. }
  14314. if (j === searchPatternLength) {
  14315. segmentHeader.length = i + searchPatternLength;
  14316. break;
  14317. }
  14318. }
  14319. if (segmentHeader.length === 0xFFFFFFFF) {
  14320. error('JBIG2 error: segment end was not found');
  14321. }
  14322. } else {
  14323. error('JBIG2 error: invalid unknown segment length');
  14324. }
  14325. }
  14326. segmentHeader.headerEnd = position;
  14327. return segmentHeader;
  14328. }
  14329. function readSegments(header, data, start, end) {
  14330. var segments = [];
  14331. var position = start;
  14332. while (position < end) {
  14333. var segmentHeader = readSegmentHeader(data, position);
  14334. position = segmentHeader.headerEnd;
  14335. var segment = {
  14336. header: segmentHeader,
  14337. data: data
  14338. };
  14339. if (!header.randomAccess) {
  14340. segment.start = position;
  14341. position += segmentHeader.length;
  14342. segment.end = position;
  14343. }
  14344. segments.push(segment);
  14345. if (segmentHeader.type === 51) {
  14346. break;
  14347. }
  14348. }
  14349. // end of file is found
  14350. if (header.randomAccess) {
  14351. for (var i = 0, ii = segments.length; i < ii; i++) {
  14352. segments[i].start = position;
  14353. position += segments[i].header.length;
  14354. segments[i].end = position;
  14355. }
  14356. }
  14357. return segments;
  14358. }
  14359. // 7.4.1 Region segment information field
  14360. function readRegionSegmentInformation(data, start) {
  14361. return {
  14362. width: readUint32(data, start),
  14363. height: readUint32(data, start + 4),
  14364. x: readUint32(data, start + 8),
  14365. y: readUint32(data, start + 12),
  14366. combinationOperator: data[start + 16] & 7
  14367. };
  14368. }
  14369. var RegionSegmentInformationFieldLength = 17;
  14370. function processSegment(segment, visitor) {
  14371. var header = segment.header;
  14372. var data = segment.data, position = segment.start, end = segment.end;
  14373. var args, at, i, atLength;
  14374. switch (header.type) {
  14375. case 0:
  14376. // SymbolDictionary
  14377. // 7.4.2 Symbol dictionary segment syntax
  14378. var dictionary = {};
  14379. var dictionaryFlags = readUint16(data, position);
  14380. // 7.4.2.1.1
  14381. dictionary.huffman = !!(dictionaryFlags & 1);
  14382. dictionary.refinement = !!(dictionaryFlags & 2);
  14383. dictionary.huffmanDHSelector = dictionaryFlags >> 2 & 3;
  14384. dictionary.huffmanDWSelector = dictionaryFlags >> 4 & 3;
  14385. dictionary.bitmapSizeSelector = dictionaryFlags >> 6 & 1;
  14386. dictionary.aggregationInstancesSelector = dictionaryFlags >> 7 & 1;
  14387. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  14388. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  14389. dictionary.template = dictionaryFlags >> 10 & 3;
  14390. dictionary.refinementTemplate = dictionaryFlags >> 12 & 1;
  14391. position += 2;
  14392. if (!dictionary.huffman) {
  14393. atLength = dictionary.template === 0 ? 4 : 1;
  14394. at = [];
  14395. for (i = 0; i < atLength; i++) {
  14396. at.push({
  14397. x: readInt8(data, position),
  14398. y: readInt8(data, position + 1)
  14399. });
  14400. position += 2;
  14401. }
  14402. dictionary.at = at;
  14403. }
  14404. if (dictionary.refinement && !dictionary.refinementTemplate) {
  14405. at = [];
  14406. for (i = 0; i < 2; i++) {
  14407. at.push({
  14408. x: readInt8(data, position),
  14409. y: readInt8(data, position + 1)
  14410. });
  14411. position += 2;
  14412. }
  14413. dictionary.refinementAt = at;
  14414. }
  14415. dictionary.numberOfExportedSymbols = readUint32(data, position);
  14416. position += 4;
  14417. dictionary.numberOfNewSymbols = readUint32(data, position);
  14418. position += 4;
  14419. args = [
  14420. dictionary,
  14421. header.number,
  14422. header.referredTo,
  14423. data,
  14424. position,
  14425. end
  14426. ];
  14427. break;
  14428. case 6:
  14429. // ImmediateTextRegion
  14430. case 7:
  14431. // ImmediateLosslessTextRegion
  14432. var textRegion = {};
  14433. textRegion.info = readRegionSegmentInformation(data, position);
  14434. position += RegionSegmentInformationFieldLength;
  14435. var textRegionSegmentFlags = readUint16(data, position);
  14436. position += 2;
  14437. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  14438. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  14439. textRegion.stripSize = 1 << (textRegionSegmentFlags >> 2 & 3);
  14440. textRegion.referenceCorner = textRegionSegmentFlags >> 4 & 3;
  14441. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  14442. textRegion.combinationOperator = textRegionSegmentFlags >> 7 & 3;
  14443. textRegion.defaultPixelValue = textRegionSegmentFlags >> 9 & 1;
  14444. textRegion.dsOffset = textRegionSegmentFlags << 17 >> 27;
  14445. textRegion.refinementTemplate = textRegionSegmentFlags >> 15 & 1;
  14446. if (textRegion.huffman) {
  14447. var textRegionHuffmanFlags = readUint16(data, position);
  14448. position += 2;
  14449. textRegion.huffmanFS = textRegionHuffmanFlags & 3;
  14450. textRegion.huffmanDS = textRegionHuffmanFlags >> 2 & 3;
  14451. textRegion.huffmanDT = textRegionHuffmanFlags >> 4 & 3;
  14452. textRegion.huffmanRefinementDW = textRegionHuffmanFlags >> 6 & 3;
  14453. textRegion.huffmanRefinementDH = textRegionHuffmanFlags >> 8 & 3;
  14454. textRegion.huffmanRefinementDX = textRegionHuffmanFlags >> 10 & 3;
  14455. textRegion.huffmanRefinementDY = textRegionHuffmanFlags >> 12 & 3;
  14456. textRegion.huffmanRefinementSizeSelector = !!(textRegionHuffmanFlags & 14);
  14457. }
  14458. if (textRegion.refinement && !textRegion.refinementTemplate) {
  14459. at = [];
  14460. for (i = 0; i < 2; i++) {
  14461. at.push({
  14462. x: readInt8(data, position),
  14463. y: readInt8(data, position + 1)
  14464. });
  14465. position += 2;
  14466. }
  14467. textRegion.refinementAt = at;
  14468. }
  14469. textRegion.numberOfSymbolInstances = readUint32(data, position);
  14470. position += 4;
  14471. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  14472. if (textRegion.huffman) {
  14473. error('JBIG2 error: huffman is not supported');
  14474. }
  14475. args = [
  14476. textRegion,
  14477. header.referredTo,
  14478. data,
  14479. position,
  14480. end
  14481. ];
  14482. break;
  14483. case 38:
  14484. // ImmediateGenericRegion
  14485. case 39:
  14486. // ImmediateLosslessGenericRegion
  14487. var genericRegion = {};
  14488. genericRegion.info = readRegionSegmentInformation(data, position);
  14489. position += RegionSegmentInformationFieldLength;
  14490. var genericRegionSegmentFlags = data[position++];
  14491. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  14492. genericRegion.template = genericRegionSegmentFlags >> 1 & 3;
  14493. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  14494. if (!genericRegion.mmr) {
  14495. atLength = genericRegion.template === 0 ? 4 : 1;
  14496. at = [];
  14497. for (i = 0; i < atLength; i++) {
  14498. at.push({
  14499. x: readInt8(data, position),
  14500. y: readInt8(data, position + 1)
  14501. });
  14502. position += 2;
  14503. }
  14504. genericRegion.at = at;
  14505. }
  14506. args = [
  14507. genericRegion,
  14508. data,
  14509. position,
  14510. end
  14511. ];
  14512. break;
  14513. case 48:
  14514. // PageInformation
  14515. var pageInfo = {
  14516. width: readUint32(data, position),
  14517. height: readUint32(data, position + 4),
  14518. resolutionX: readUint32(data, position + 8),
  14519. resolutionY: readUint32(data, position + 12)
  14520. };
  14521. if (pageInfo.height === 0xFFFFFFFF) {
  14522. delete pageInfo.height;
  14523. }
  14524. var pageSegmentFlags = data[position + 16];
  14525. var pageStripingInformation = readUint16(data, position + 17);
  14526. pageInfo.lossless = !!(pageSegmentFlags & 1);
  14527. pageInfo.refinement = !!(pageSegmentFlags & 2);
  14528. pageInfo.defaultPixelValue = pageSegmentFlags >> 2 & 1;
  14529. pageInfo.combinationOperator = pageSegmentFlags >> 3 & 3;
  14530. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  14531. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  14532. args = [pageInfo];
  14533. break;
  14534. case 49:
  14535. // EndOfPage
  14536. break;
  14537. case 50:
  14538. // EndOfStripe
  14539. break;
  14540. case 51:
  14541. // EndOfFile
  14542. break;
  14543. case 62:
  14544. // 7.4.15 defines 2 extension types which
  14545. // are comments and can be ignored.
  14546. break;
  14547. default:
  14548. error('JBIG2 error: segment type ' + header.typeName + '(' + header.type + ') is not implemented');
  14549. }
  14550. var callbackName = 'on' + header.typeName;
  14551. if (callbackName in visitor) {
  14552. visitor[callbackName].apply(visitor, args);
  14553. }
  14554. }
  14555. function processSegments(segments, visitor) {
  14556. for (var i = 0, ii = segments.length; i < ii; i++) {
  14557. processSegment(segments[i], visitor);
  14558. }
  14559. }
  14560. function parseJbig2(data, start, end) {
  14561. var position = start;
  14562. if (data[position] !== 0x97 || data[position + 1] !== 0x4A || data[position + 2] !== 0x42 || data[position + 3] !== 0x32 || data[position + 4] !== 0x0D || data[position + 5] !== 0x0A || data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  14563. error('JBIG2 error: invalid header');
  14564. }
  14565. var header = {};
  14566. position += 8;
  14567. var flags = data[position++];
  14568. header.randomAccess = !(flags & 1);
  14569. if (!(flags & 2)) {
  14570. header.numberOfPages = readUint32(data, position);
  14571. position += 4;
  14572. }
  14573. var segments = readSegments(header, data, position, end);
  14574. error('Not implemented');
  14575. }
  14576. // processSegments(segments, new SimpleSegmentVisitor());
  14577. function parseJbig2Chunks(chunks) {
  14578. var visitor = new SimpleSegmentVisitor();
  14579. for (var i = 0, ii = chunks.length; i < ii; i++) {
  14580. var chunk = chunks[i];
  14581. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  14582. processSegments(segments, visitor);
  14583. }
  14584. return visitor.buffer;
  14585. }
  14586. function SimpleSegmentVisitor() {
  14587. }
  14588. SimpleSegmentVisitor.prototype = {
  14589. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  14590. this.currentPageInfo = info;
  14591. var rowSize = info.width + 7 >> 3;
  14592. var buffer = new Uint8Array(rowSize * info.height);
  14593. // The contents of ArrayBuffers are initialized to 0.
  14594. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  14595. if (info.defaultPixelValue) {
  14596. for (var i = 0, ii = buffer.length; i < ii; i++) {
  14597. buffer[i] = 0xFF;
  14598. }
  14599. }
  14600. this.buffer = buffer;
  14601. },
  14602. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  14603. var pageInfo = this.currentPageInfo;
  14604. var width = regionInfo.width, height = regionInfo.height;
  14605. var rowSize = pageInfo.width + 7 >> 3;
  14606. var combinationOperator = pageInfo.combinationOperatorOverride ? regionInfo.combinationOperator : pageInfo.combinationOperator;
  14607. var buffer = this.buffer;
  14608. var mask0 = 128 >> (regionInfo.x & 7);
  14609. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  14610. var i, j, mask, offset;
  14611. switch (combinationOperator) {
  14612. case 0:
  14613. // OR
  14614. for (i = 0; i < height; i++) {
  14615. mask = mask0;
  14616. offset = offset0;
  14617. for (j = 0; j < width; j++) {
  14618. if (bitmap[i][j]) {
  14619. buffer[offset] |= mask;
  14620. }
  14621. mask >>= 1;
  14622. if (!mask) {
  14623. mask = 128;
  14624. offset++;
  14625. }
  14626. }
  14627. offset0 += rowSize;
  14628. }
  14629. break;
  14630. case 2:
  14631. // XOR
  14632. for (i = 0; i < height; i++) {
  14633. mask = mask0;
  14634. offset = offset0;
  14635. for (j = 0; j < width; j++) {
  14636. if (bitmap[i][j]) {
  14637. buffer[offset] ^= mask;
  14638. }
  14639. mask >>= 1;
  14640. if (!mask) {
  14641. mask = 128;
  14642. offset++;
  14643. }
  14644. }
  14645. offset0 += rowSize;
  14646. }
  14647. break;
  14648. default:
  14649. error('JBIG2 error: operator ' + combinationOperator + ' is not supported');
  14650. }
  14651. },
  14652. onImmediateGenericRegion: function SimpleSegmentVisitor_onImmediateGenericRegion(region, data, start, end) {
  14653. var regionInfo = region.info;
  14654. var decodingContext = new DecodingContext(data, start, end);
  14655. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height, region.template, region.prediction, null, region.at, decodingContext);
  14656. this.drawBitmap(regionInfo, bitmap);
  14657. },
  14658. onImmediateLosslessGenericRegion: function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  14659. this.onImmediateGenericRegion.apply(this, arguments);
  14660. },
  14661. onSymbolDictionary: function SimpleSegmentVisitor_onSymbolDictionary(dictionary, currentSegment, referredSegments, data, start, end) {
  14662. var huffmanTables;
  14663. if (dictionary.huffman) {
  14664. error('JBIG2 error: huffman is not supported');
  14665. }
  14666. // Combines exported symbols from all referred segments
  14667. var symbols = this.symbols;
  14668. if (!symbols) {
  14669. this.symbols = symbols = {};
  14670. }
  14671. var inputSymbols = [];
  14672. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  14673. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  14674. }
  14675. var decodingContext = new DecodingContext(data, start, end);
  14676. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman, dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols, dictionary.numberOfExportedSymbols, huffmanTables, dictionary.template, dictionary.at, dictionary.refinementTemplate, dictionary.refinementAt, decodingContext);
  14677. },
  14678. onImmediateTextRegion: function SimpleSegmentVisitor_onImmediateTextRegion(region, referredSegments, data, start, end) {
  14679. var regionInfo = region.info;
  14680. var huffmanTables;
  14681. // Combines exported symbols from all referred segments
  14682. var symbols = this.symbols;
  14683. var inputSymbols = [];
  14684. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  14685. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  14686. }
  14687. var symbolCodeLength = log2(inputSymbols.length);
  14688. var decodingContext = new DecodingContext(data, start, end);
  14689. var bitmap = decodeTextRegion(region.huffman, region.refinement, regionInfo.width, regionInfo.height, region.defaultPixelValue, region.numberOfSymbolInstances, region.stripSize, inputSymbols, symbolCodeLength, region.transposed, region.dsOffset, region.referenceCorner, region.combinationOperator, huffmanTables, region.refinementTemplate, region.refinementAt, decodingContext);
  14690. this.drawBitmap(regionInfo, bitmap);
  14691. },
  14692. onImmediateLosslessTextRegion: function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  14693. this.onImmediateTextRegion.apply(this, arguments);
  14694. }
  14695. };
  14696. function Jbig2Image() {
  14697. }
  14698. Jbig2Image.prototype = {
  14699. parseChunks: function Jbig2Image_parseChunks(chunks) {
  14700. return parseJbig2Chunks(chunks);
  14701. }
  14702. };
  14703. return Jbig2Image;
  14704. }();
  14705. exports.Jbig2Image = Jbig2Image;
  14706. }));
  14707. (function (root, factory) {
  14708. factory(root.pdfjsCoreJpg = {}, root.pdfjsSharedUtil);
  14709. }(this, function (exports, sharedUtil) {
  14710. var error = sharedUtil.error;
  14711. /**
  14712. * This code was forked from https://github.com/notmasteryet/jpgjs.
  14713. * The original version was created by GitHub user notmasteryet.
  14714. *
  14715. * - The JPEG specification can be found in the ITU CCITT Recommendation T.81
  14716. * (www.w3.org/Graphics/JPEG/itu-t81.pdf)
  14717. * - The JFIF specification can be found in the JPEG File Interchange Format
  14718. * (www.w3.org/Graphics/JPEG/jfif3.pdf)
  14719. * - The Adobe Application-Specific JPEG markers in the
  14720. * Supporting the DCT Filters in PostScript Level 2, Technical Note #5116
  14721. * (partners.adobe.com/public/developer/en/ps/sdk/5116.DCT_Filter.pdf)
  14722. */
  14723. var JpegImage = function JpegImageClosure() {
  14724. var dctZigZag = new Uint8Array([
  14725. 0,
  14726. 1,
  14727. 8,
  14728. 16,
  14729. 9,
  14730. 2,
  14731. 3,
  14732. 10,
  14733. 17,
  14734. 24,
  14735. 32,
  14736. 25,
  14737. 18,
  14738. 11,
  14739. 4,
  14740. 5,
  14741. 12,
  14742. 19,
  14743. 26,
  14744. 33,
  14745. 40,
  14746. 48,
  14747. 41,
  14748. 34,
  14749. 27,
  14750. 20,
  14751. 13,
  14752. 6,
  14753. 7,
  14754. 14,
  14755. 21,
  14756. 28,
  14757. 35,
  14758. 42,
  14759. 49,
  14760. 56,
  14761. 57,
  14762. 50,
  14763. 43,
  14764. 36,
  14765. 29,
  14766. 22,
  14767. 15,
  14768. 23,
  14769. 30,
  14770. 37,
  14771. 44,
  14772. 51,
  14773. 58,
  14774. 59,
  14775. 52,
  14776. 45,
  14777. 38,
  14778. 31,
  14779. 39,
  14780. 46,
  14781. 53,
  14782. 60,
  14783. 61,
  14784. 54,
  14785. 47,
  14786. 55,
  14787. 62,
  14788. 63
  14789. ]);
  14790. var dctCos1 = 4017;
  14791. // cos(pi/16)
  14792. var dctSin1 = 799;
  14793. // sin(pi/16)
  14794. var dctCos3 = 3406;
  14795. // cos(3*pi/16)
  14796. var dctSin3 = 2276;
  14797. // sin(3*pi/16)
  14798. var dctCos6 = 1567;
  14799. // cos(6*pi/16)
  14800. var dctSin6 = 3784;
  14801. // sin(6*pi/16)
  14802. var dctSqrt2 = 5793;
  14803. // sqrt(2)
  14804. var dctSqrt1d2 = 2896;
  14805. // sqrt(2) / 2
  14806. function JpegImage() {
  14807. this.decodeTransform = null;
  14808. this.colorTransform = -1;
  14809. }
  14810. function buildHuffmanTable(codeLengths, values) {
  14811. var k = 0, code = [], i, j, length = 16;
  14812. while (length > 0 && !codeLengths[length - 1]) {
  14813. length--;
  14814. }
  14815. code.push({
  14816. children: [],
  14817. index: 0
  14818. });
  14819. var p = code[0], q;
  14820. for (i = 0; i < length; i++) {
  14821. for (j = 0; j < codeLengths[i]; j++) {
  14822. p = code.pop();
  14823. p.children[p.index] = values[k];
  14824. while (p.index > 0) {
  14825. p = code.pop();
  14826. }
  14827. p.index++;
  14828. code.push(p);
  14829. while (code.length <= i) {
  14830. code.push(q = {
  14831. children: [],
  14832. index: 0
  14833. });
  14834. p.children[p.index] = q.children;
  14835. p = q;
  14836. }
  14837. k++;
  14838. }
  14839. if (i + 1 < length) {
  14840. // p here points to last code
  14841. code.push(q = {
  14842. children: [],
  14843. index: 0
  14844. });
  14845. p.children[p.index] = q.children;
  14846. p = q;
  14847. }
  14848. }
  14849. return code[0].children;
  14850. }
  14851. function getBlockBufferOffset(component, row, col) {
  14852. return 64 * ((component.blocksPerLine + 1) * row + col);
  14853. }
  14854. function decodeScan(data, offset, frame, components, resetInterval, spectralStart, spectralEnd, successivePrev, successive) {
  14855. var mcusPerLine = frame.mcusPerLine;
  14856. var progressive = frame.progressive;
  14857. var startOffset = offset, bitsData = 0, bitsCount = 0;
  14858. function readBit() {
  14859. if (bitsCount > 0) {
  14860. bitsCount--;
  14861. return bitsData >> bitsCount & 1;
  14862. }
  14863. bitsData = data[offset++];
  14864. if (bitsData === 0xFF) {
  14865. var nextByte = data[offset++];
  14866. if (nextByte) {
  14867. error('JPEG error: unexpected marker ' + (bitsData << 8 | nextByte).toString(16));
  14868. }
  14869. }
  14870. // unstuff 0
  14871. bitsCount = 7;
  14872. return bitsData >>> 7;
  14873. }
  14874. function decodeHuffman(tree) {
  14875. var node = tree;
  14876. while (true) {
  14877. node = node[readBit()];
  14878. if (typeof node === 'number') {
  14879. return node;
  14880. }
  14881. if (typeof node !== 'object') {
  14882. error('JPEG error: invalid huffman sequence');
  14883. }
  14884. }
  14885. }
  14886. function receive(length) {
  14887. var n = 0;
  14888. while (length > 0) {
  14889. n = n << 1 | readBit();
  14890. length--;
  14891. }
  14892. return n;
  14893. }
  14894. function receiveAndExtend(length) {
  14895. if (length === 1) {
  14896. return readBit() === 1 ? 1 : -1;
  14897. }
  14898. var n = receive(length);
  14899. if (n >= 1 << length - 1) {
  14900. return n;
  14901. }
  14902. return n + (-1 << length) + 1;
  14903. }
  14904. function decodeBaseline(component, offset) {
  14905. var t = decodeHuffman(component.huffmanTableDC);
  14906. var diff = t === 0 ? 0 : receiveAndExtend(t);
  14907. component.blockData[offset] = component.pred += diff;
  14908. var k = 1;
  14909. while (k < 64) {
  14910. var rs = decodeHuffman(component.huffmanTableAC);
  14911. var s = rs & 15, r = rs >> 4;
  14912. if (s === 0) {
  14913. if (r < 15) {
  14914. break;
  14915. }
  14916. k += 16;
  14917. continue;
  14918. }
  14919. k += r;
  14920. var z = dctZigZag[k];
  14921. component.blockData[offset + z] = receiveAndExtend(s);
  14922. k++;
  14923. }
  14924. }
  14925. function decodeDCFirst(component, offset) {
  14926. var t = decodeHuffman(component.huffmanTableDC);
  14927. var diff = t === 0 ? 0 : receiveAndExtend(t) << successive;
  14928. component.blockData[offset] = component.pred += diff;
  14929. }
  14930. function decodeDCSuccessive(component, offset) {
  14931. component.blockData[offset] |= readBit() << successive;
  14932. }
  14933. var eobrun = 0;
  14934. function decodeACFirst(component, offset) {
  14935. if (eobrun > 0) {
  14936. eobrun--;
  14937. return;
  14938. }
  14939. var k = spectralStart, e = spectralEnd;
  14940. while (k <= e) {
  14941. var rs = decodeHuffman(component.huffmanTableAC);
  14942. var s = rs & 15, r = rs >> 4;
  14943. if (s === 0) {
  14944. if (r < 15) {
  14945. eobrun = receive(r) + (1 << r) - 1;
  14946. break;
  14947. }
  14948. k += 16;
  14949. continue;
  14950. }
  14951. k += r;
  14952. var z = dctZigZag[k];
  14953. component.blockData[offset + z] = receiveAndExtend(s) * (1 << successive);
  14954. k++;
  14955. }
  14956. }
  14957. var successiveACState = 0, successiveACNextValue;
  14958. function decodeACSuccessive(component, offset) {
  14959. var k = spectralStart;
  14960. var e = spectralEnd;
  14961. var r = 0;
  14962. var s;
  14963. var rs;
  14964. while (k <= e) {
  14965. var z = dctZigZag[k];
  14966. switch (successiveACState) {
  14967. case 0:
  14968. // initial state
  14969. rs = decodeHuffman(component.huffmanTableAC);
  14970. s = rs & 15;
  14971. r = rs >> 4;
  14972. if (s === 0) {
  14973. if (r < 15) {
  14974. eobrun = receive(r) + (1 << r);
  14975. successiveACState = 4;
  14976. } else {
  14977. r = 16;
  14978. successiveACState = 1;
  14979. }
  14980. } else {
  14981. if (s !== 1) {
  14982. error('JPEG error: invalid ACn encoding');
  14983. }
  14984. successiveACNextValue = receiveAndExtend(s);
  14985. successiveACState = r ? 2 : 3;
  14986. }
  14987. continue;
  14988. case 1:
  14989. // skipping r zero items
  14990. case 2:
  14991. if (component.blockData[offset + z]) {
  14992. component.blockData[offset + z] += readBit() << successive;
  14993. } else {
  14994. r--;
  14995. if (r === 0) {
  14996. successiveACState = successiveACState === 2 ? 3 : 0;
  14997. }
  14998. }
  14999. break;
  15000. case 3:
  15001. // set value for a zero item
  15002. if (component.blockData[offset + z]) {
  15003. component.blockData[offset + z] += readBit() << successive;
  15004. } else {
  15005. component.blockData[offset + z] = successiveACNextValue << successive;
  15006. successiveACState = 0;
  15007. }
  15008. break;
  15009. case 4:
  15010. // eob
  15011. if (component.blockData[offset + z]) {
  15012. component.blockData[offset + z] += readBit() << successive;
  15013. }
  15014. break;
  15015. }
  15016. k++;
  15017. }
  15018. if (successiveACState === 4) {
  15019. eobrun--;
  15020. if (eobrun === 0) {
  15021. successiveACState = 0;
  15022. }
  15023. }
  15024. }
  15025. function decodeMcu(component, decode, mcu, row, col) {
  15026. var mcuRow = mcu / mcusPerLine | 0;
  15027. var mcuCol = mcu % mcusPerLine;
  15028. var blockRow = mcuRow * component.v + row;
  15029. var blockCol = mcuCol * component.h + col;
  15030. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  15031. decode(component, offset);
  15032. }
  15033. function decodeBlock(component, decode, mcu) {
  15034. var blockRow = mcu / component.blocksPerLine | 0;
  15035. var blockCol = mcu % component.blocksPerLine;
  15036. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  15037. decode(component, offset);
  15038. }
  15039. var componentsLength = components.length;
  15040. var component, i, j, k, n;
  15041. var decodeFn;
  15042. if (progressive) {
  15043. if (spectralStart === 0) {
  15044. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  15045. } else {
  15046. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  15047. }
  15048. } else {
  15049. decodeFn = decodeBaseline;
  15050. }
  15051. var mcu = 0, marker;
  15052. var mcuExpected;
  15053. if (componentsLength === 1) {
  15054. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  15055. } else {
  15056. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  15057. }
  15058. if (!resetInterval) {
  15059. resetInterval = mcuExpected;
  15060. }
  15061. var h, v;
  15062. while (mcu < mcuExpected) {
  15063. // reset interval stuff
  15064. for (i = 0; i < componentsLength; i++) {
  15065. components[i].pred = 0;
  15066. }
  15067. eobrun = 0;
  15068. if (componentsLength === 1) {
  15069. component = components[0];
  15070. for (n = 0; n < resetInterval; n++) {
  15071. decodeBlock(component, decodeFn, mcu);
  15072. mcu++;
  15073. }
  15074. } else {
  15075. for (n = 0; n < resetInterval; n++) {
  15076. for (i = 0; i < componentsLength; i++) {
  15077. component = components[i];
  15078. h = component.h;
  15079. v = component.v;
  15080. for (j = 0; j < v; j++) {
  15081. for (k = 0; k < h; k++) {
  15082. decodeMcu(component, decodeFn, mcu, j, k);
  15083. }
  15084. }
  15085. }
  15086. mcu++;
  15087. }
  15088. }
  15089. // find marker
  15090. bitsCount = 0;
  15091. marker = data[offset] << 8 | data[offset + 1];
  15092. // Some bad images seem to pad Scan blocks with zero bytes, skip past
  15093. // those to attempt to find a valid marker (fixes issue4090.pdf).
  15094. while (data[offset] === 0x00 && offset < data.length - 1) {
  15095. offset++;
  15096. marker = data[offset] << 8 | data[offset + 1];
  15097. }
  15098. if (marker <= 0xFF00) {
  15099. error('JPEG error: marker was not found');
  15100. }
  15101. if (marker >= 0xFFD0 && marker <= 0xFFD7) {
  15102. // RSTx
  15103. offset += 2;
  15104. } else {
  15105. break;
  15106. }
  15107. }
  15108. return offset - startOffset;
  15109. }
  15110. // A port of poppler's IDCT method which in turn is taken from:
  15111. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  15112. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  15113. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  15114. // 988-991.
  15115. function quantizeAndInverse(component, blockBufferOffset, p) {
  15116. var qt = component.quantizationTable, blockData = component.blockData;
  15117. var v0, v1, v2, v3, v4, v5, v6, v7;
  15118. var p0, p1, p2, p3, p4, p5, p6, p7;
  15119. var t;
  15120. if (!qt) {
  15121. error('JPEG error: missing required Quantization Table.');
  15122. }
  15123. // inverse DCT on rows
  15124. for (var row = 0; row < 64; row += 8) {
  15125. // gather block data
  15126. p0 = blockData[blockBufferOffset + row];
  15127. p1 = blockData[blockBufferOffset + row + 1];
  15128. p2 = blockData[blockBufferOffset + row + 2];
  15129. p3 = blockData[blockBufferOffset + row + 3];
  15130. p4 = blockData[blockBufferOffset + row + 4];
  15131. p5 = blockData[blockBufferOffset + row + 5];
  15132. p6 = blockData[blockBufferOffset + row + 6];
  15133. p7 = blockData[blockBufferOffset + row + 7];
  15134. // dequant p0
  15135. p0 *= qt[row];
  15136. // check for all-zero AC coefficients
  15137. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  15138. t = dctSqrt2 * p0 + 512 >> 10;
  15139. p[row] = t;
  15140. p[row + 1] = t;
  15141. p[row + 2] = t;
  15142. p[row + 3] = t;
  15143. p[row + 4] = t;
  15144. p[row + 5] = t;
  15145. p[row + 6] = t;
  15146. p[row + 7] = t;
  15147. continue;
  15148. }
  15149. // dequant p1 ... p7
  15150. p1 *= qt[row + 1];
  15151. p2 *= qt[row + 2];
  15152. p3 *= qt[row + 3];
  15153. p4 *= qt[row + 4];
  15154. p5 *= qt[row + 5];
  15155. p6 *= qt[row + 6];
  15156. p7 *= qt[row + 7];
  15157. // stage 4
  15158. v0 = dctSqrt2 * p0 + 128 >> 8;
  15159. v1 = dctSqrt2 * p4 + 128 >> 8;
  15160. v2 = p2;
  15161. v3 = p6;
  15162. v4 = dctSqrt1d2 * (p1 - p7) + 128 >> 8;
  15163. v7 = dctSqrt1d2 * (p1 + p7) + 128 >> 8;
  15164. v5 = p3 << 4;
  15165. v6 = p5 << 4;
  15166. // stage 3
  15167. v0 = v0 + v1 + 1 >> 1;
  15168. v1 = v0 - v1;
  15169. t = v2 * dctSin6 + v3 * dctCos6 + 128 >> 8;
  15170. v2 = v2 * dctCos6 - v3 * dctSin6 + 128 >> 8;
  15171. v3 = t;
  15172. v4 = v4 + v6 + 1 >> 1;
  15173. v6 = v4 - v6;
  15174. v7 = v7 + v5 + 1 >> 1;
  15175. v5 = v7 - v5;
  15176. // stage 2
  15177. v0 = v0 + v3 + 1 >> 1;
  15178. v3 = v0 - v3;
  15179. v1 = v1 + v2 + 1 >> 1;
  15180. v2 = v1 - v2;
  15181. t = v4 * dctSin3 + v7 * dctCos3 + 2048 >> 12;
  15182. v4 = v4 * dctCos3 - v7 * dctSin3 + 2048 >> 12;
  15183. v7 = t;
  15184. t = v5 * dctSin1 + v6 * dctCos1 + 2048 >> 12;
  15185. v5 = v5 * dctCos1 - v6 * dctSin1 + 2048 >> 12;
  15186. v6 = t;
  15187. // stage 1
  15188. p[row] = v0 + v7;
  15189. p[row + 7] = v0 - v7;
  15190. p[row + 1] = v1 + v6;
  15191. p[row + 6] = v1 - v6;
  15192. p[row + 2] = v2 + v5;
  15193. p[row + 5] = v2 - v5;
  15194. p[row + 3] = v3 + v4;
  15195. p[row + 4] = v3 - v4;
  15196. }
  15197. // inverse DCT on columns
  15198. for (var col = 0; col < 8; ++col) {
  15199. p0 = p[col];
  15200. p1 = p[col + 8];
  15201. p2 = p[col + 16];
  15202. p3 = p[col + 24];
  15203. p4 = p[col + 32];
  15204. p5 = p[col + 40];
  15205. p6 = p[col + 48];
  15206. p7 = p[col + 56];
  15207. // check for all-zero AC coefficients
  15208. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  15209. t = dctSqrt2 * p0 + 8192 >> 14;
  15210. // convert to 8 bit
  15211. t = t < -2040 ? 0 : t >= 2024 ? 255 : t + 2056 >> 4;
  15212. blockData[blockBufferOffset + col] = t;
  15213. blockData[blockBufferOffset + col + 8] = t;
  15214. blockData[blockBufferOffset + col + 16] = t;
  15215. blockData[blockBufferOffset + col + 24] = t;
  15216. blockData[blockBufferOffset + col + 32] = t;
  15217. blockData[blockBufferOffset + col + 40] = t;
  15218. blockData[blockBufferOffset + col + 48] = t;
  15219. blockData[blockBufferOffset + col + 56] = t;
  15220. continue;
  15221. }
  15222. // stage 4
  15223. v0 = dctSqrt2 * p0 + 2048 >> 12;
  15224. v1 = dctSqrt2 * p4 + 2048 >> 12;
  15225. v2 = p2;
  15226. v3 = p6;
  15227. v4 = dctSqrt1d2 * (p1 - p7) + 2048 >> 12;
  15228. v7 = dctSqrt1d2 * (p1 + p7) + 2048 >> 12;
  15229. v5 = p3;
  15230. v6 = p5;
  15231. // stage 3
  15232. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  15233. // converting to UInt8 range later.
  15234. v0 = (v0 + v1 + 1 >> 1) + 4112;
  15235. v1 = v0 - v1;
  15236. t = v2 * dctSin6 + v3 * dctCos6 + 2048 >> 12;
  15237. v2 = v2 * dctCos6 - v3 * dctSin6 + 2048 >> 12;
  15238. v3 = t;
  15239. v4 = v4 + v6 + 1 >> 1;
  15240. v6 = v4 - v6;
  15241. v7 = v7 + v5 + 1 >> 1;
  15242. v5 = v7 - v5;
  15243. // stage 2
  15244. v0 = v0 + v3 + 1 >> 1;
  15245. v3 = v0 - v3;
  15246. v1 = v1 + v2 + 1 >> 1;
  15247. v2 = v1 - v2;
  15248. t = v4 * dctSin3 + v7 * dctCos3 + 2048 >> 12;
  15249. v4 = v4 * dctCos3 - v7 * dctSin3 + 2048 >> 12;
  15250. v7 = t;
  15251. t = v5 * dctSin1 + v6 * dctCos1 + 2048 >> 12;
  15252. v5 = v5 * dctCos1 - v6 * dctSin1 + 2048 >> 12;
  15253. v6 = t;
  15254. // stage 1
  15255. p0 = v0 + v7;
  15256. p7 = v0 - v7;
  15257. p1 = v1 + v6;
  15258. p6 = v1 - v6;
  15259. p2 = v2 + v5;
  15260. p5 = v2 - v5;
  15261. p3 = v3 + v4;
  15262. p4 = v3 - v4;
  15263. // convert to 8-bit integers
  15264. p0 = p0 < 16 ? 0 : p0 >= 4080 ? 255 : p0 >> 4;
  15265. p1 = p1 < 16 ? 0 : p1 >= 4080 ? 255 : p1 >> 4;
  15266. p2 = p2 < 16 ? 0 : p2 >= 4080 ? 255 : p2 >> 4;
  15267. p3 = p3 < 16 ? 0 : p3 >= 4080 ? 255 : p3 >> 4;
  15268. p4 = p4 < 16 ? 0 : p4 >= 4080 ? 255 : p4 >> 4;
  15269. p5 = p5 < 16 ? 0 : p5 >= 4080 ? 255 : p5 >> 4;
  15270. p6 = p6 < 16 ? 0 : p6 >= 4080 ? 255 : p6 >> 4;
  15271. p7 = p7 < 16 ? 0 : p7 >= 4080 ? 255 : p7 >> 4;
  15272. // store block data
  15273. blockData[blockBufferOffset + col] = p0;
  15274. blockData[blockBufferOffset + col + 8] = p1;
  15275. blockData[blockBufferOffset + col + 16] = p2;
  15276. blockData[blockBufferOffset + col + 24] = p3;
  15277. blockData[blockBufferOffset + col + 32] = p4;
  15278. blockData[blockBufferOffset + col + 40] = p5;
  15279. blockData[blockBufferOffset + col + 48] = p6;
  15280. blockData[blockBufferOffset + col + 56] = p7;
  15281. }
  15282. }
  15283. function buildComponentData(frame, component) {
  15284. var blocksPerLine = component.blocksPerLine;
  15285. var blocksPerColumn = component.blocksPerColumn;
  15286. var computationBuffer = new Int16Array(64);
  15287. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  15288. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  15289. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  15290. quantizeAndInverse(component, offset, computationBuffer);
  15291. }
  15292. }
  15293. return component.blockData;
  15294. }
  15295. function clamp0to255(a) {
  15296. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  15297. }
  15298. JpegImage.prototype = {
  15299. parse: function parse(data) {
  15300. function readUint16() {
  15301. var value = data[offset] << 8 | data[offset + 1];
  15302. offset += 2;
  15303. return value;
  15304. }
  15305. function readDataBlock() {
  15306. var length = readUint16();
  15307. var array = data.subarray(offset, offset + length - 2);
  15308. offset += array.length;
  15309. return array;
  15310. }
  15311. function prepareComponents(frame) {
  15312. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  15313. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  15314. for (var i = 0; i < frame.components.length; i++) {
  15315. component = frame.components[i];
  15316. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) * component.h / frame.maxH);
  15317. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) * component.v / frame.maxV);
  15318. var blocksPerLineForMcu = mcusPerLine * component.h;
  15319. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  15320. var blocksBufferSize = 64 * blocksPerColumnForMcu * (blocksPerLineForMcu + 1);
  15321. component.blockData = new Int16Array(blocksBufferSize);
  15322. component.blocksPerLine = blocksPerLine;
  15323. component.blocksPerColumn = blocksPerColumn;
  15324. }
  15325. frame.mcusPerLine = mcusPerLine;
  15326. frame.mcusPerColumn = mcusPerColumn;
  15327. }
  15328. var offset = 0;
  15329. var jfif = null;
  15330. var adobe = null;
  15331. var frame, resetInterval;
  15332. var quantizationTables = [];
  15333. var huffmanTablesAC = [], huffmanTablesDC = [];
  15334. var fileMarker = readUint16();
  15335. if (fileMarker !== 0xFFD8) {
  15336. // SOI (Start of Image)
  15337. error('JPEG error: SOI not found');
  15338. }
  15339. fileMarker = readUint16();
  15340. while (fileMarker !== 0xFFD9) {
  15341. // EOI (End of image)
  15342. var i, j, l;
  15343. switch (fileMarker) {
  15344. case 0xFFE0:
  15345. // APP0 (Application Specific)
  15346. case 0xFFE1:
  15347. // APP1
  15348. case 0xFFE2:
  15349. // APP2
  15350. case 0xFFE3:
  15351. // APP3
  15352. case 0xFFE4:
  15353. // APP4
  15354. case 0xFFE5:
  15355. // APP5
  15356. case 0xFFE6:
  15357. // APP6
  15358. case 0xFFE7:
  15359. // APP7
  15360. case 0xFFE8:
  15361. // APP8
  15362. case 0xFFE9:
  15363. // APP9
  15364. case 0xFFEA:
  15365. // APP10
  15366. case 0xFFEB:
  15367. // APP11
  15368. case 0xFFEC:
  15369. // APP12
  15370. case 0xFFED:
  15371. // APP13
  15372. case 0xFFEE:
  15373. // APP14
  15374. case 0xFFEF:
  15375. // APP15
  15376. case 0xFFFE:
  15377. // COM (Comment)
  15378. var appData = readDataBlock();
  15379. if (fileMarker === 0xFFE0) {
  15380. if (appData[0] === 0x4A && appData[1] === 0x46 && appData[2] === 0x49 && appData[3] === 0x46 && appData[4] === 0) {
  15381. // 'JFIF\x00'
  15382. jfif = {
  15383. version: {
  15384. major: appData[5],
  15385. minor: appData[6]
  15386. },
  15387. densityUnits: appData[7],
  15388. xDensity: appData[8] << 8 | appData[9],
  15389. yDensity: appData[10] << 8 | appData[11],
  15390. thumbWidth: appData[12],
  15391. thumbHeight: appData[13],
  15392. thumbData: appData.subarray(14, 14 + 3 * appData[12] * appData[13])
  15393. };
  15394. }
  15395. }
  15396. // TODO APP1 - Exif
  15397. if (fileMarker === 0xFFEE) {
  15398. if (appData[0] === 0x41 && appData[1] === 0x64 && appData[2] === 0x6F && appData[3] === 0x62 && appData[4] === 0x65) {
  15399. // 'Adobe'
  15400. adobe = {
  15401. version: appData[5] << 8 | appData[6],
  15402. flags0: appData[7] << 8 | appData[8],
  15403. flags1: appData[9] << 8 | appData[10],
  15404. transformCode: appData[11]
  15405. };
  15406. }
  15407. }
  15408. break;
  15409. case 0xFFDB:
  15410. // DQT (Define Quantization Tables)
  15411. var quantizationTablesLength = readUint16();
  15412. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  15413. var z;
  15414. while (offset < quantizationTablesEnd) {
  15415. var quantizationTableSpec = data[offset++];
  15416. var tableData = new Uint16Array(64);
  15417. if (quantizationTableSpec >> 4 === 0) {
  15418. // 8 bit values
  15419. for (j = 0; j < 64; j++) {
  15420. z = dctZigZag[j];
  15421. tableData[z] = data[offset++];
  15422. }
  15423. } else if (quantizationTableSpec >> 4 === 1) {
  15424. //16 bit
  15425. for (j = 0; j < 64; j++) {
  15426. z = dctZigZag[j];
  15427. tableData[z] = readUint16();
  15428. }
  15429. } else {
  15430. error('JPEG error: DQT - invalid table spec');
  15431. }
  15432. quantizationTables[quantizationTableSpec & 15] = tableData;
  15433. }
  15434. break;
  15435. case 0xFFC0:
  15436. // SOF0 (Start of Frame, Baseline DCT)
  15437. case 0xFFC1:
  15438. // SOF1 (Start of Frame, Extended DCT)
  15439. case 0xFFC2:
  15440. // SOF2 (Start of Frame, Progressive DCT)
  15441. if (frame) {
  15442. error('JPEG error: Only single frame JPEGs supported');
  15443. }
  15444. readUint16();
  15445. // skip data length
  15446. frame = {};
  15447. frame.extended = fileMarker === 0xFFC1;
  15448. frame.progressive = fileMarker === 0xFFC2;
  15449. frame.precision = data[offset++];
  15450. frame.scanLines = readUint16();
  15451. frame.samplesPerLine = readUint16();
  15452. frame.components = [];
  15453. frame.componentIds = {};
  15454. var componentsCount = data[offset++], componentId;
  15455. var maxH = 0, maxV = 0;
  15456. for (i = 0; i < componentsCount; i++) {
  15457. componentId = data[offset];
  15458. var h = data[offset + 1] >> 4;
  15459. var v = data[offset + 1] & 15;
  15460. if (maxH < h) {
  15461. maxH = h;
  15462. }
  15463. if (maxV < v) {
  15464. maxV = v;
  15465. }
  15466. var qId = data[offset + 2];
  15467. l = frame.components.push({
  15468. h: h,
  15469. v: v,
  15470. quantizationId: qId,
  15471. quantizationTable: null
  15472. });
  15473. // See comment below.
  15474. frame.componentIds[componentId] = l - 1;
  15475. offset += 3;
  15476. }
  15477. frame.maxH = maxH;
  15478. frame.maxV = maxV;
  15479. prepareComponents(frame);
  15480. break;
  15481. case 0xFFC4:
  15482. // DHT (Define Huffman Tables)
  15483. var huffmanLength = readUint16();
  15484. for (i = 2; i < huffmanLength;) {
  15485. var huffmanTableSpec = data[offset++];
  15486. var codeLengths = new Uint8Array(16);
  15487. var codeLengthSum = 0;
  15488. for (j = 0; j < 16; j++, offset++) {
  15489. codeLengthSum += codeLengths[j] = data[offset];
  15490. }
  15491. var huffmanValues = new Uint8Array(codeLengthSum);
  15492. for (j = 0; j < codeLengthSum; j++, offset++) {
  15493. huffmanValues[j] = data[offset];
  15494. }
  15495. i += 17 + codeLengthSum;
  15496. (huffmanTableSpec >> 4 === 0 ? huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] = buildHuffmanTable(codeLengths, huffmanValues);
  15497. }
  15498. break;
  15499. case 0xFFDD:
  15500. // DRI (Define Restart Interval)
  15501. readUint16();
  15502. // skip data length
  15503. resetInterval = readUint16();
  15504. break;
  15505. case 0xFFDA:
  15506. // SOS (Start of Scan)
  15507. var scanLength = readUint16();
  15508. var selectorsCount = data[offset++];
  15509. var components = [], component;
  15510. for (i = 0; i < selectorsCount; i++) {
  15511. var componentIndex = frame.componentIds[data[offset++]];
  15512. component = frame.components[componentIndex];
  15513. var tableSpec = data[offset++];
  15514. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  15515. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  15516. components.push(component);
  15517. }
  15518. var spectralStart = data[offset++];
  15519. var spectralEnd = data[offset++];
  15520. var successiveApproximation = data[offset++];
  15521. var processed = decodeScan(data, offset, frame, components, resetInterval, spectralStart, spectralEnd, successiveApproximation >> 4, successiveApproximation & 15);
  15522. offset += processed;
  15523. break;
  15524. case 0xFFFF:
  15525. // Fill bytes
  15526. if (data[offset] !== 0xFF) {
  15527. // Avoid skipping a valid marker.
  15528. offset--;
  15529. }
  15530. break;
  15531. default:
  15532. if (data[offset - 3] === 0xFF && data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  15533. // could be incorrect encoding -- last 0xFF byte of the previous
  15534. // block was eaten by the encoder
  15535. offset -= 3;
  15536. break;
  15537. }
  15538. error('JPEG error: unknown marker ' + fileMarker.toString(16));
  15539. }
  15540. fileMarker = readUint16();
  15541. }
  15542. this.width = frame.samplesPerLine;
  15543. this.height = frame.scanLines;
  15544. this.jfif = jfif;
  15545. this.adobe = adobe;
  15546. this.components = [];
  15547. for (i = 0; i < frame.components.length; i++) {
  15548. component = frame.components[i];
  15549. // Prevent errors when DQT markers are placed after SOF{n} markers,
  15550. // by assigning the `quantizationTable` entry after the entire image
  15551. // has been parsed (fixes issue7406.pdf).
  15552. var quantizationTable = quantizationTables[component.quantizationId];
  15553. if (quantizationTable) {
  15554. component.quantizationTable = quantizationTable;
  15555. }
  15556. this.components.push({
  15557. output: buildComponentData(frame, component),
  15558. scaleX: component.h / frame.maxH,
  15559. scaleY: component.v / frame.maxV,
  15560. blocksPerLine: component.blocksPerLine,
  15561. blocksPerColumn: component.blocksPerColumn
  15562. });
  15563. }
  15564. this.numComponents = this.components.length;
  15565. },
  15566. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  15567. var scaleX = this.width / width, scaleY = this.height / height;
  15568. var component, componentScaleX, componentScaleY, blocksPerScanline;
  15569. var x, y, i, j, k;
  15570. var index;
  15571. var offset = 0;
  15572. var output;
  15573. var numComponents = this.components.length;
  15574. var dataLength = width * height * numComponents;
  15575. var data = new Uint8Array(dataLength);
  15576. var xScaleBlockOffset = new Uint32Array(width);
  15577. var mask3LSB = 0xfffffff8;
  15578. // used to clear the 3 LSBs
  15579. for (i = 0; i < numComponents; i++) {
  15580. component = this.components[i];
  15581. componentScaleX = component.scaleX * scaleX;
  15582. componentScaleY = component.scaleY * scaleY;
  15583. offset = i;
  15584. output = component.output;
  15585. blocksPerScanline = component.blocksPerLine + 1 << 3;
  15586. // precalculate the xScaleBlockOffset
  15587. for (x = 0; x < width; x++) {
  15588. j = 0 | x * componentScaleX;
  15589. xScaleBlockOffset[x] = (j & mask3LSB) << 3 | j & 7;
  15590. }
  15591. // linearize the blocks of the component
  15592. for (y = 0; y < height; y++) {
  15593. j = 0 | y * componentScaleY;
  15594. index = blocksPerScanline * (j & mask3LSB) | (j & 7) << 3;
  15595. for (x = 0; x < width; x++) {
  15596. data[offset] = output[index + xScaleBlockOffset[x]];
  15597. offset += numComponents;
  15598. }
  15599. }
  15600. }
  15601. // decodeTransform contains pairs of multiplier (-256..256) and additive
  15602. var transform = this.decodeTransform;
  15603. if (transform) {
  15604. for (i = 0; i < dataLength;) {
  15605. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  15606. data[i] = (data[i] * transform[k] >> 8) + transform[k + 1];
  15607. }
  15608. }
  15609. }
  15610. return data;
  15611. },
  15612. _isColorConversionNeeded: function isColorConversionNeeded() {
  15613. if (this.adobe && this.adobe.transformCode) {
  15614. // The adobe transform marker overrides any previous setting
  15615. return true;
  15616. } else if (this.numComponents === 3) {
  15617. if (!this.adobe && this.colorTransform === 0) {
  15618. // If the Adobe transform marker is not present and the image
  15619. // dictionary has a 'ColorTransform' entry, explicitly set to `0`,
  15620. // then the colours should *not* be transformed.
  15621. return false;
  15622. }
  15623. return true;
  15624. } else {
  15625. // `this.numComponents !== 3`
  15626. if (!this.adobe && this.colorTransform === 1) {
  15627. // If the Adobe transform marker is not present and the image
  15628. // dictionary has a 'ColorTransform' entry, explicitly set to `1`,
  15629. // then the colours should be transformed.
  15630. return true;
  15631. }
  15632. return false;
  15633. }
  15634. },
  15635. _convertYccToRgb: function convertYccToRgb(data) {
  15636. var Y, Cb, Cr;
  15637. for (var i = 0, length = data.length; i < length; i += 3) {
  15638. Y = data[i];
  15639. Cb = data[i + 1];
  15640. Cr = data[i + 2];
  15641. data[i] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  15642. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  15643. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  15644. }
  15645. return data;
  15646. },
  15647. _convertYcckToRgb: function convertYcckToRgb(data) {
  15648. var Y, Cb, Cr, k;
  15649. var offset = 0;
  15650. for (var i = 0, length = data.length; i < length; i += 4) {
  15651. Y = data[i];
  15652. Cb = data[i + 1];
  15653. Cr = data[i + 2];
  15654. k = data[i + 3];
  15655. var r = -122.67195406894 + Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr - 5.4080610064599e-5 * Y + 0.00048449797120281 * k - 0.154362151871126) + Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y - 0.00477271405408747 * k + 1.53380253221734) + Y * (0.000961250184130688 * Y - 0.00266257332283933 * k + 0.48357088451265) + k * (-0.000336197177618394 * k + 0.484791561490776);
  15656. var g = 107.268039397724 + Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr + 0.000659397001245577 * Y + 0.000426105652938837 * k - 0.176491792462875) + Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y + 0.000770482631801132 * k - 0.151051492775562) + Y * (0.00126935368114843 * Y - 0.00265090189010898 * k + 0.25802910206845) + k * (-0.000318913117588328 * k - 0.213742400323665);
  15657. var b = -20.810012546947 + Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr + 0.0020741088115012 * Y - 0.00288260236853442 * k + 0.814272968359295) + Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y + 0.000560833691242812 * k - 0.195152027534049) + Y * (0.00174418132927582 * Y - 0.00255243321439347 * k + 0.116935020465145) + k * (-0.000343531996510555 * k + 0.24165260232407);
  15658. data[offset++] = clamp0to255(r);
  15659. data[offset++] = clamp0to255(g);
  15660. data[offset++] = clamp0to255(b);
  15661. }
  15662. return data;
  15663. },
  15664. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  15665. var Y, Cb, Cr;
  15666. for (var i = 0, length = data.length; i < length; i += 4) {
  15667. Y = data[i];
  15668. Cb = data[i + 1];
  15669. Cr = data[i + 2];
  15670. data[i] = clamp0to255(434.456 - Y - 1.402 * Cr);
  15671. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  15672. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  15673. }
  15674. // K in data[i + 3] is unchanged
  15675. return data;
  15676. },
  15677. _convertCmykToRgb: function convertCmykToRgb(data) {
  15678. var c, m, y, k;
  15679. var offset = 0;
  15680. var min = -255 * 255 * 255;
  15681. var scale = 1 / 255 / 255;
  15682. for (var i = 0, length = data.length; i < length; i += 4) {
  15683. c = data[i];
  15684. m = data[i + 1];
  15685. y = data[i + 2];
  15686. k = data[i + 3];
  15687. var r = c * (-4.387332384609988 * c + 54.48615194189176 * m + 18.82290502165302 * y + 212.25662451639585 * k - 72734.4411664936) + m * (1.7149763477362134 * m - 5.6096736904047315 * y - 17.873870861415444 * k - 1401.7366389350734) + y * (-2.5217340131683033 * y - 21.248923337353073 * k + 4465.541406466231) - k * (21.86122147463605 * k + 48317.86113160301);
  15688. var g = c * (8.841041422036149 * c + 60.118027045597366 * m + 6.871425592049007 * y + 31.159100130055922 * k - 20220.756542821975) + m * (-15.310361306967817 * m + 17.575251261109482 * y + 131.35250912493976 * k - 48691.05921601825) + y * (4.444339102852739 * y + 9.8632861493405 * k - 6341.191035517494) - k * (20.737325471181034 * k + 47890.15695978492);
  15689. var b = c * (0.8842522430003296 * c + 8.078677503112928 * m + 30.89978309703729 * y - 0.23883238689178934 * k - 3616.812083916688) + m * (10.49593273432072 * m + 63.02378494754052 * y + 50.606957656360734 * k - 28620.90484698408) + y * (0.03296041114873217 * y + 115.60384449646641 * k - 49363.43385999684) - k * (22.33816807309886 * k + 45932.16563550634);
  15690. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  15691. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  15692. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  15693. }
  15694. return data;
  15695. },
  15696. getData: function getData(width, height, forceRGBoutput) {
  15697. if (this.numComponents > 4) {
  15698. error('JPEG error: Unsupported color mode');
  15699. }
  15700. // type of data: Uint8Array(width * height * numComponents)
  15701. var data = this._getLinearizedBlockData(width, height);
  15702. if (this.numComponents === 1 && forceRGBoutput) {
  15703. var dataLength = data.length;
  15704. var rgbData = new Uint8Array(dataLength * 3);
  15705. var offset = 0;
  15706. for (var i = 0; i < dataLength; i++) {
  15707. var grayColor = data[i];
  15708. rgbData[offset++] = grayColor;
  15709. rgbData[offset++] = grayColor;
  15710. rgbData[offset++] = grayColor;
  15711. }
  15712. return rgbData;
  15713. } else if (this.numComponents === 3 && this._isColorConversionNeeded()) {
  15714. return this._convertYccToRgb(data);
  15715. } else if (this.numComponents === 4) {
  15716. if (this._isColorConversionNeeded()) {
  15717. if (forceRGBoutput) {
  15718. return this._convertYcckToRgb(data);
  15719. } else {
  15720. return this._convertYcckToCmyk(data);
  15721. }
  15722. } else if (forceRGBoutput) {
  15723. return this._convertCmykToRgb(data);
  15724. }
  15725. }
  15726. return data;
  15727. }
  15728. };
  15729. return JpegImage;
  15730. }();
  15731. exports.JpegImage = JpegImage;
  15732. }));
  15733. (function (root, factory) {
  15734. factory(root.pdfjsCoreJpx = {}, root.pdfjsSharedUtil, root.pdfjsCoreArithmeticDecoder);
  15735. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  15736. var info = sharedUtil.info;
  15737. var warn = sharedUtil.warn;
  15738. var error = sharedUtil.error;
  15739. var log2 = sharedUtil.log2;
  15740. var readUint16 = sharedUtil.readUint16;
  15741. var readUint32 = sharedUtil.readUint32;
  15742. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  15743. var JpxImage = function JpxImageClosure() {
  15744. // Table E.1
  15745. var SubbandsGainLog2 = {
  15746. 'LL': 0,
  15747. 'LH': 1,
  15748. 'HL': 1,
  15749. 'HH': 2
  15750. };
  15751. function JpxImage() {
  15752. this.failOnCorruptedImage = false;
  15753. }
  15754. JpxImage.prototype = {
  15755. parse: function JpxImage_parse(data) {
  15756. var head = readUint16(data, 0);
  15757. // No box header, immediate start of codestream (SOC)
  15758. if (head === 0xFF4F) {
  15759. this.parseCodestream(data, 0, data.length);
  15760. return;
  15761. }
  15762. var position = 0, length = data.length;
  15763. while (position < length) {
  15764. var headerSize = 8;
  15765. var lbox = readUint32(data, position);
  15766. var tbox = readUint32(data, position + 4);
  15767. position += headerSize;
  15768. if (lbox === 1) {
  15769. // XLBox: read UInt64 according to spec.
  15770. // JavaScript's int precision of 53 bit should be sufficient here.
  15771. lbox = readUint32(data, position) * 4294967296 + readUint32(data, position + 4);
  15772. position += 8;
  15773. headerSize += 8;
  15774. }
  15775. if (lbox === 0) {
  15776. lbox = length - position + headerSize;
  15777. }
  15778. if (lbox < headerSize) {
  15779. error('JPX Error: Invalid box field size');
  15780. }
  15781. var dataLength = lbox - headerSize;
  15782. var jumpDataLength = true;
  15783. switch (tbox) {
  15784. case 0x6A703268:
  15785. // 'jp2h'
  15786. jumpDataLength = false;
  15787. // parsing child boxes
  15788. break;
  15789. case 0x636F6C72:
  15790. // 'colr'
  15791. // Colorspaces are not used, the CS from the PDF is used.
  15792. var method = data[position];
  15793. if (method === 1) {
  15794. // enumerated colorspace
  15795. var colorspace = readUint32(data, position + 3);
  15796. switch (colorspace) {
  15797. case 16:
  15798. // this indicates a sRGB colorspace
  15799. case 17:
  15800. // this indicates a grayscale colorspace
  15801. case 18:
  15802. // this indicates a YUV colorspace
  15803. break;
  15804. default:
  15805. warn('Unknown colorspace ' + colorspace);
  15806. break;
  15807. }
  15808. } else if (method === 2) {
  15809. info('ICC profile not supported');
  15810. }
  15811. break;
  15812. case 0x6A703263:
  15813. // 'jp2c'
  15814. this.parseCodestream(data, position, position + dataLength);
  15815. break;
  15816. case 0x6A502020:
  15817. // 'jP\024\024'
  15818. if (0x0d0a870a !== readUint32(data, position)) {
  15819. warn('Invalid JP2 signature');
  15820. }
  15821. break;
  15822. // The following header types are valid but currently not used:
  15823. case 0x6A501A1A:
  15824. // 'jP\032\032'
  15825. case 0x66747970:
  15826. // 'ftyp'
  15827. case 0x72726571:
  15828. // 'rreq'
  15829. case 0x72657320:
  15830. // 'res '
  15831. case 0x69686472:
  15832. // 'ihdr'
  15833. break;
  15834. default:
  15835. var headerType = String.fromCharCode(tbox >> 24 & 0xFF, tbox >> 16 & 0xFF, tbox >> 8 & 0xFF, tbox & 0xFF);
  15836. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  15837. break;
  15838. }
  15839. if (jumpDataLength) {
  15840. position += dataLength;
  15841. }
  15842. }
  15843. },
  15844. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  15845. var newByte = stream.getByte();
  15846. while (newByte >= 0) {
  15847. var oldByte = newByte;
  15848. newByte = stream.getByte();
  15849. var code = oldByte << 8 | newByte;
  15850. // Image and tile size (SIZ)
  15851. if (code === 0xFF51) {
  15852. stream.skip(4);
  15853. var Xsiz = stream.getInt32() >>> 0;
  15854. // Byte 4
  15855. var Ysiz = stream.getInt32() >>> 0;
  15856. // Byte 8
  15857. var XOsiz = stream.getInt32() >>> 0;
  15858. // Byte 12
  15859. var YOsiz = stream.getInt32() >>> 0;
  15860. // Byte 16
  15861. stream.skip(16);
  15862. var Csiz = stream.getUint16();
  15863. // Byte 36
  15864. this.width = Xsiz - XOsiz;
  15865. this.height = Ysiz - YOsiz;
  15866. this.componentsCount = Csiz;
  15867. // Results are always returned as Uint8Arrays
  15868. this.bitsPerComponent = 8;
  15869. return;
  15870. }
  15871. }
  15872. error('JPX Error: No size marker found in JPX stream');
  15873. },
  15874. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  15875. var context = {};
  15876. var doNotRecover = false;
  15877. try {
  15878. var position = start;
  15879. while (position + 1 < end) {
  15880. var code = readUint16(data, position);
  15881. position += 2;
  15882. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  15883. switch (code) {
  15884. case 0xFF4F:
  15885. // Start of codestream (SOC)
  15886. context.mainHeader = true;
  15887. break;
  15888. case 0xFFD9:
  15889. // End of codestream (EOC)
  15890. break;
  15891. case 0xFF51:
  15892. // Image and tile size (SIZ)
  15893. length = readUint16(data, position);
  15894. var siz = {};
  15895. siz.Xsiz = readUint32(data, position + 4);
  15896. siz.Ysiz = readUint32(data, position + 8);
  15897. siz.XOsiz = readUint32(data, position + 12);
  15898. siz.YOsiz = readUint32(data, position + 16);
  15899. siz.XTsiz = readUint32(data, position + 20);
  15900. siz.YTsiz = readUint32(data, position + 24);
  15901. siz.XTOsiz = readUint32(data, position + 28);
  15902. siz.YTOsiz = readUint32(data, position + 32);
  15903. var componentsCount = readUint16(data, position + 36);
  15904. siz.Csiz = componentsCount;
  15905. var components = [];
  15906. j = position + 38;
  15907. for (var i = 0; i < componentsCount; i++) {
  15908. var component = {
  15909. precision: (data[j] & 0x7F) + 1,
  15910. isSigned: !!(data[j] & 0x80),
  15911. XRsiz: data[j + 1],
  15912. YRsiz: data[j + 1]
  15913. };
  15914. calculateComponentDimensions(component, siz);
  15915. components.push(component);
  15916. }
  15917. context.SIZ = siz;
  15918. context.components = components;
  15919. calculateTileGrids(context, components);
  15920. context.QCC = [];
  15921. context.COC = [];
  15922. break;
  15923. case 0xFF5C:
  15924. // Quantization default (QCD)
  15925. length = readUint16(data, position);
  15926. var qcd = {};
  15927. j = position + 2;
  15928. sqcd = data[j++];
  15929. switch (sqcd & 0x1F) {
  15930. case 0:
  15931. spqcdSize = 8;
  15932. scalarExpounded = true;
  15933. break;
  15934. case 1:
  15935. spqcdSize = 16;
  15936. scalarExpounded = false;
  15937. break;
  15938. case 2:
  15939. spqcdSize = 16;
  15940. scalarExpounded = true;
  15941. break;
  15942. default:
  15943. throw new Error('Invalid SQcd value ' + sqcd);
  15944. }
  15945. qcd.noQuantization = spqcdSize === 8;
  15946. qcd.scalarExpounded = scalarExpounded;
  15947. qcd.guardBits = sqcd >> 5;
  15948. spqcds = [];
  15949. while (j < length + position) {
  15950. var spqcd = {};
  15951. if (spqcdSize === 8) {
  15952. spqcd.epsilon = data[j++] >> 3;
  15953. spqcd.mu = 0;
  15954. } else {
  15955. spqcd.epsilon = data[j] >> 3;
  15956. spqcd.mu = (data[j] & 0x7) << 8 | data[j + 1];
  15957. j += 2;
  15958. }
  15959. spqcds.push(spqcd);
  15960. }
  15961. qcd.SPqcds = spqcds;
  15962. if (context.mainHeader) {
  15963. context.QCD = qcd;
  15964. } else {
  15965. context.currentTile.QCD = qcd;
  15966. context.currentTile.QCC = [];
  15967. }
  15968. break;
  15969. case 0xFF5D:
  15970. // Quantization component (QCC)
  15971. length = readUint16(data, position);
  15972. var qcc = {};
  15973. j = position + 2;
  15974. var cqcc;
  15975. if (context.SIZ.Csiz < 257) {
  15976. cqcc = data[j++];
  15977. } else {
  15978. cqcc = readUint16(data, j);
  15979. j += 2;
  15980. }
  15981. sqcd = data[j++];
  15982. switch (sqcd & 0x1F) {
  15983. case 0:
  15984. spqcdSize = 8;
  15985. scalarExpounded = true;
  15986. break;
  15987. case 1:
  15988. spqcdSize = 16;
  15989. scalarExpounded = false;
  15990. break;
  15991. case 2:
  15992. spqcdSize = 16;
  15993. scalarExpounded = true;
  15994. break;
  15995. default:
  15996. throw new Error('Invalid SQcd value ' + sqcd);
  15997. }
  15998. qcc.noQuantization = spqcdSize === 8;
  15999. qcc.scalarExpounded = scalarExpounded;
  16000. qcc.guardBits = sqcd >> 5;
  16001. spqcds = [];
  16002. while (j < length + position) {
  16003. spqcd = {};
  16004. if (spqcdSize === 8) {
  16005. spqcd.epsilon = data[j++] >> 3;
  16006. spqcd.mu = 0;
  16007. } else {
  16008. spqcd.epsilon = data[j] >> 3;
  16009. spqcd.mu = (data[j] & 0x7) << 8 | data[j + 1];
  16010. j += 2;
  16011. }
  16012. spqcds.push(spqcd);
  16013. }
  16014. qcc.SPqcds = spqcds;
  16015. if (context.mainHeader) {
  16016. context.QCC[cqcc] = qcc;
  16017. } else {
  16018. context.currentTile.QCC[cqcc] = qcc;
  16019. }
  16020. break;
  16021. case 0xFF52:
  16022. // Coding style default (COD)
  16023. length = readUint16(data, position);
  16024. var cod = {};
  16025. j = position + 2;
  16026. var scod = data[j++];
  16027. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  16028. cod.sopMarkerUsed = !!(scod & 2);
  16029. cod.ephMarkerUsed = !!(scod & 4);
  16030. cod.progressionOrder = data[j++];
  16031. cod.layersCount = readUint16(data, j);
  16032. j += 2;
  16033. cod.multipleComponentTransform = data[j++];
  16034. cod.decompositionLevelsCount = data[j++];
  16035. cod.xcb = (data[j++] & 0xF) + 2;
  16036. cod.ycb = (data[j++] & 0xF) + 2;
  16037. var blockStyle = data[j++];
  16038. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  16039. cod.resetContextProbabilities = !!(blockStyle & 2);
  16040. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  16041. cod.verticalyStripe = !!(blockStyle & 8);
  16042. cod.predictableTermination = !!(blockStyle & 16);
  16043. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  16044. cod.reversibleTransformation = data[j++];
  16045. if (cod.entropyCoderWithCustomPrecincts) {
  16046. var precinctsSizes = [];
  16047. while (j < length + position) {
  16048. var precinctsSize = data[j++];
  16049. precinctsSizes.push({
  16050. PPx: precinctsSize & 0xF,
  16051. PPy: precinctsSize >> 4
  16052. });
  16053. }
  16054. cod.precinctsSizes = precinctsSizes;
  16055. }
  16056. var unsupported = [];
  16057. if (cod.selectiveArithmeticCodingBypass) {
  16058. unsupported.push('selectiveArithmeticCodingBypass');
  16059. }
  16060. if (cod.resetContextProbabilities) {
  16061. unsupported.push('resetContextProbabilities');
  16062. }
  16063. if (cod.terminationOnEachCodingPass) {
  16064. unsupported.push('terminationOnEachCodingPass');
  16065. }
  16066. if (cod.verticalyStripe) {
  16067. unsupported.push('verticalyStripe');
  16068. }
  16069. if (cod.predictableTermination) {
  16070. unsupported.push('predictableTermination');
  16071. }
  16072. if (unsupported.length > 0) {
  16073. doNotRecover = true;
  16074. throw new Error('Unsupported COD options (' + unsupported.join(', ') + ')');
  16075. }
  16076. if (context.mainHeader) {
  16077. context.COD = cod;
  16078. } else {
  16079. context.currentTile.COD = cod;
  16080. context.currentTile.COC = [];
  16081. }
  16082. break;
  16083. case 0xFF90:
  16084. // Start of tile-part (SOT)
  16085. length = readUint16(data, position);
  16086. tile = {};
  16087. tile.index = readUint16(data, position + 2);
  16088. tile.length = readUint32(data, position + 4);
  16089. tile.dataEnd = tile.length + position - 2;
  16090. tile.partIndex = data[position + 8];
  16091. tile.partsCount = data[position + 9];
  16092. context.mainHeader = false;
  16093. if (tile.partIndex === 0) {
  16094. // reset component specific settings
  16095. tile.COD = context.COD;
  16096. tile.COC = context.COC.slice(0);
  16097. // clone of the global COC
  16098. tile.QCD = context.QCD;
  16099. tile.QCC = context.QCC.slice(0);
  16100. }
  16101. // clone of the global COC
  16102. context.currentTile = tile;
  16103. break;
  16104. case 0xFF93:
  16105. // Start of data (SOD)
  16106. tile = context.currentTile;
  16107. if (tile.partIndex === 0) {
  16108. initializeTile(context, tile.index);
  16109. buildPackets(context);
  16110. }
  16111. // moving to the end of the data
  16112. length = tile.dataEnd - position;
  16113. parseTilePackets(context, data, position, length);
  16114. break;
  16115. case 0xFF55:
  16116. // Tile-part lengths, main header (TLM)
  16117. case 0xFF57:
  16118. // Packet length, main header (PLM)
  16119. case 0xFF58:
  16120. // Packet length, tile-part header (PLT)
  16121. case 0xFF64:
  16122. // Comment (COM)
  16123. length = readUint16(data, position);
  16124. // skipping content
  16125. break;
  16126. case 0xFF53:
  16127. // Coding style component (COC)
  16128. throw new Error('Codestream code 0xFF53 (COC) is ' + 'not implemented');
  16129. default:
  16130. throw new Error('Unknown codestream code: ' + code.toString(16));
  16131. }
  16132. position += length;
  16133. }
  16134. } catch (e) {
  16135. if (doNotRecover || this.failOnCorruptedImage) {
  16136. error('JPX Error: ' + e.message);
  16137. } else {
  16138. warn('JPX: Trying to recover from: ' + e.message);
  16139. }
  16140. }
  16141. this.tiles = transformComponents(context);
  16142. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  16143. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  16144. this.componentsCount = context.SIZ.Csiz;
  16145. }
  16146. };
  16147. function calculateComponentDimensions(component, siz) {
  16148. // Section B.2 Component mapping
  16149. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  16150. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  16151. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  16152. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  16153. component.width = component.x1 - component.x0;
  16154. component.height = component.y1 - component.y0;
  16155. }
  16156. function calculateTileGrids(context, components) {
  16157. var siz = context.SIZ;
  16158. // Section B.3 Division into tile and tile-components
  16159. var tile, tiles = [];
  16160. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  16161. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  16162. for (var q = 0; q < numYtiles; q++) {
  16163. for (var p = 0; p < numXtiles; p++) {
  16164. tile = {};
  16165. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  16166. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  16167. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  16168. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  16169. tile.width = tile.tx1 - tile.tx0;
  16170. tile.height = tile.ty1 - tile.ty0;
  16171. tile.components = [];
  16172. tiles.push(tile);
  16173. }
  16174. }
  16175. context.tiles = tiles;
  16176. var componentsCount = siz.Csiz;
  16177. for (var i = 0, ii = componentsCount; i < ii; i++) {
  16178. var component = components[i];
  16179. for (var j = 0, jj = tiles.length; j < jj; j++) {
  16180. var tileComponent = {};
  16181. tile = tiles[j];
  16182. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  16183. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  16184. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  16185. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  16186. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  16187. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  16188. tile.components[i] = tileComponent;
  16189. }
  16190. }
  16191. }
  16192. function getBlocksDimensions(context, component, r) {
  16193. var codOrCoc = component.codingStyleParameters;
  16194. var result = {};
  16195. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  16196. result.PPx = 15;
  16197. result.PPy = 15;
  16198. } else {
  16199. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  16200. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  16201. }
  16202. // calculate codeblock size as described in section B.7
  16203. result.xcb_ = r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) : Math.min(codOrCoc.xcb, result.PPx);
  16204. result.ycb_ = r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) : Math.min(codOrCoc.ycb, result.PPy);
  16205. return result;
  16206. }
  16207. function buildPrecincts(context, resolution, dimensions) {
  16208. // Section B.6 Division resolution to precincts
  16209. var precinctWidth = 1 << dimensions.PPx;
  16210. var precinctHeight = 1 << dimensions.PPy;
  16211. // Jasper introduces codeblock groups for mapping each subband codeblocks
  16212. // to precincts. Precinct partition divides a resolution according to width
  16213. // and height parameters. The subband that belongs to the resolution level
  16214. // has a different size than the level, unless it is the zero resolution.
  16215. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  16216. // The precinct partitioning for a particular subband is derived from a
  16217. // partitioning of its parent LL band (i.e., the LL band at the next higher
  16218. // resolution level)... The LL band associated with each resolution level is
  16219. // divided into precincts... Each of the resulting precinct regions is then
  16220. // mapped into its child subbands (if any) at the next lower resolution
  16221. // level. This is accomplished by using the coordinate transformation
  16222. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  16223. // coordinates of a point in the LL band and child subband, respectively.
  16224. var isZeroRes = resolution.resLevel === 0;
  16225. var precinctWidthInSubband = 1 << dimensions.PPx + (isZeroRes ? 0 : -1);
  16226. var precinctHeightInSubband = 1 << dimensions.PPy + (isZeroRes ? 0 : -1);
  16227. var numprecinctswide = resolution.trx1 > resolution.trx0 ? Math.ceil(resolution.trx1 / precinctWidth) - Math.floor(resolution.trx0 / precinctWidth) : 0;
  16228. var numprecinctshigh = resolution.try1 > resolution.try0 ? Math.ceil(resolution.try1 / precinctHeight) - Math.floor(resolution.try0 / precinctHeight) : 0;
  16229. var numprecincts = numprecinctswide * numprecinctshigh;
  16230. resolution.precinctParameters = {
  16231. precinctWidth: precinctWidth,
  16232. precinctHeight: precinctHeight,
  16233. numprecinctswide: numprecinctswide,
  16234. numprecinctshigh: numprecinctshigh,
  16235. numprecincts: numprecincts,
  16236. precinctWidthInSubband: precinctWidthInSubband,
  16237. precinctHeightInSubband: precinctHeightInSubband
  16238. };
  16239. }
  16240. function buildCodeblocks(context, subband, dimensions) {
  16241. // Section B.7 Division sub-band into code-blocks
  16242. var xcb_ = dimensions.xcb_;
  16243. var ycb_ = dimensions.ycb_;
  16244. var codeblockWidth = 1 << xcb_;
  16245. var codeblockHeight = 1 << ycb_;
  16246. var cbx0 = subband.tbx0 >> xcb_;
  16247. var cby0 = subband.tby0 >> ycb_;
  16248. var cbx1 = subband.tbx1 + codeblockWidth - 1 >> xcb_;
  16249. var cby1 = subband.tby1 + codeblockHeight - 1 >> ycb_;
  16250. var precinctParameters = subband.resolution.precinctParameters;
  16251. var codeblocks = [];
  16252. var precincts = [];
  16253. var i, j, codeblock, precinctNumber;
  16254. for (j = cby0; j < cby1; j++) {
  16255. for (i = cbx0; i < cbx1; i++) {
  16256. codeblock = {
  16257. cbx: i,
  16258. cby: j,
  16259. tbx0: codeblockWidth * i,
  16260. tby0: codeblockHeight * j,
  16261. tbx1: codeblockWidth * (i + 1),
  16262. tby1: codeblockHeight * (j + 1)
  16263. };
  16264. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  16265. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  16266. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  16267. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  16268. // Calculate precinct number for this codeblock, codeblock position
  16269. // should be relative to its subband, use actual dimension and position
  16270. // See comment about codeblock group width and height
  16271. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) / precinctParameters.precinctWidthInSubband);
  16272. var pj = Math.floor((codeblock.tby0_ - subband.tby0) / precinctParameters.precinctHeightInSubband);
  16273. precinctNumber = pi + pj * precinctParameters.numprecinctswide;
  16274. codeblock.precinctNumber = precinctNumber;
  16275. codeblock.subbandType = subband.type;
  16276. codeblock.Lblock = 3;
  16277. if (codeblock.tbx1_ <= codeblock.tbx0_ || codeblock.tby1_ <= codeblock.tby0_) {
  16278. continue;
  16279. }
  16280. codeblocks.push(codeblock);
  16281. // building precinct for the sub-band
  16282. var precinct = precincts[precinctNumber];
  16283. if (precinct !== undefined) {
  16284. if (i < precinct.cbxMin) {
  16285. precinct.cbxMin = i;
  16286. } else if (i > precinct.cbxMax) {
  16287. precinct.cbxMax = i;
  16288. }
  16289. if (j < precinct.cbyMin) {
  16290. precinct.cbxMin = j;
  16291. } else if (j > precinct.cbyMax) {
  16292. precinct.cbyMax = j;
  16293. }
  16294. } else {
  16295. precincts[precinctNumber] = precinct = {
  16296. cbxMin: i,
  16297. cbyMin: j,
  16298. cbxMax: i,
  16299. cbyMax: j
  16300. };
  16301. }
  16302. codeblock.precinct = precinct;
  16303. }
  16304. }
  16305. subband.codeblockParameters = {
  16306. codeblockWidth: xcb_,
  16307. codeblockHeight: ycb_,
  16308. numcodeblockwide: cbx1 - cbx0 + 1,
  16309. numcodeblockhigh: cby1 - cby0 + 1
  16310. };
  16311. subband.codeblocks = codeblocks;
  16312. subband.precincts = precincts;
  16313. }
  16314. function createPacket(resolution, precinctNumber, layerNumber) {
  16315. var precinctCodeblocks = [];
  16316. // Section B.10.8 Order of info in packet
  16317. var subbands = resolution.subbands;
  16318. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  16319. for (var i = 0, ii = subbands.length; i < ii; i++) {
  16320. var subband = subbands[i];
  16321. var codeblocks = subband.codeblocks;
  16322. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  16323. var codeblock = codeblocks[j];
  16324. if (codeblock.precinctNumber !== precinctNumber) {
  16325. continue;
  16326. }
  16327. precinctCodeblocks.push(codeblock);
  16328. }
  16329. }
  16330. return {
  16331. layerNumber: layerNumber,
  16332. codeblocks: precinctCodeblocks
  16333. };
  16334. }
  16335. function LayerResolutionComponentPositionIterator(context) {
  16336. var siz = context.SIZ;
  16337. var tileIndex = context.currentTile.index;
  16338. var tile = context.tiles[tileIndex];
  16339. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  16340. var componentsCount = siz.Csiz;
  16341. var maxDecompositionLevelsCount = 0;
  16342. for (var q = 0; q < componentsCount; q++) {
  16343. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, tile.components[q].codingStyleParameters.decompositionLevelsCount);
  16344. }
  16345. var l = 0, r = 0, i = 0, k = 0;
  16346. this.nextPacket = function JpxImage_nextPacket() {
  16347. // Section B.12.1.1 Layer-resolution-component-position
  16348. for (; l < layersCount; l++) {
  16349. for (; r <= maxDecompositionLevelsCount; r++) {
  16350. for (; i < componentsCount; i++) {
  16351. var component = tile.components[i];
  16352. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  16353. continue;
  16354. }
  16355. var resolution = component.resolutions[r];
  16356. var numprecincts = resolution.precinctParameters.numprecincts;
  16357. for (; k < numprecincts;) {
  16358. var packet = createPacket(resolution, k, l);
  16359. k++;
  16360. return packet;
  16361. }
  16362. k = 0;
  16363. }
  16364. i = 0;
  16365. }
  16366. r = 0;
  16367. }
  16368. error('JPX Error: Out of packets');
  16369. };
  16370. }
  16371. function ResolutionLayerComponentPositionIterator(context) {
  16372. var siz = context.SIZ;
  16373. var tileIndex = context.currentTile.index;
  16374. var tile = context.tiles[tileIndex];
  16375. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  16376. var componentsCount = siz.Csiz;
  16377. var maxDecompositionLevelsCount = 0;
  16378. for (var q = 0; q < componentsCount; q++) {
  16379. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, tile.components[q].codingStyleParameters.decompositionLevelsCount);
  16380. }
  16381. var r = 0, l = 0, i = 0, k = 0;
  16382. this.nextPacket = function JpxImage_nextPacket() {
  16383. // Section B.12.1.2 Resolution-layer-component-position
  16384. for (; r <= maxDecompositionLevelsCount; r++) {
  16385. for (; l < layersCount; l++) {
  16386. for (; i < componentsCount; i++) {
  16387. var component = tile.components[i];
  16388. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  16389. continue;
  16390. }
  16391. var resolution = component.resolutions[r];
  16392. var numprecincts = resolution.precinctParameters.numprecincts;
  16393. for (; k < numprecincts;) {
  16394. var packet = createPacket(resolution, k, l);
  16395. k++;
  16396. return packet;
  16397. }
  16398. k = 0;
  16399. }
  16400. i = 0;
  16401. }
  16402. l = 0;
  16403. }
  16404. error('JPX Error: Out of packets');
  16405. };
  16406. }
  16407. function ResolutionPositionComponentLayerIterator(context) {
  16408. var siz = context.SIZ;
  16409. var tileIndex = context.currentTile.index;
  16410. var tile = context.tiles[tileIndex];
  16411. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  16412. var componentsCount = siz.Csiz;
  16413. var l, r, c, p;
  16414. var maxDecompositionLevelsCount = 0;
  16415. for (c = 0; c < componentsCount; c++) {
  16416. var component = tile.components[c];
  16417. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, component.codingStyleParameters.decompositionLevelsCount);
  16418. }
  16419. var maxNumPrecinctsInLevel = new Int32Array(maxDecompositionLevelsCount + 1);
  16420. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  16421. var maxNumPrecincts = 0;
  16422. for (c = 0; c < componentsCount; ++c) {
  16423. var resolutions = tile.components[c].resolutions;
  16424. if (r < resolutions.length) {
  16425. maxNumPrecincts = Math.max(maxNumPrecincts, resolutions[r].precinctParameters.numprecincts);
  16426. }
  16427. }
  16428. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  16429. }
  16430. l = 0;
  16431. r = 0;
  16432. c = 0;
  16433. p = 0;
  16434. this.nextPacket = function JpxImage_nextPacket() {
  16435. // Section B.12.1.3 Resolution-position-component-layer
  16436. for (; r <= maxDecompositionLevelsCount; r++) {
  16437. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  16438. for (; c < componentsCount; c++) {
  16439. var component = tile.components[c];
  16440. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  16441. continue;
  16442. }
  16443. var resolution = component.resolutions[r];
  16444. var numprecincts = resolution.precinctParameters.numprecincts;
  16445. if (p >= numprecincts) {
  16446. continue;
  16447. }
  16448. for (; l < layersCount;) {
  16449. var packet = createPacket(resolution, p, l);
  16450. l++;
  16451. return packet;
  16452. }
  16453. l = 0;
  16454. }
  16455. c = 0;
  16456. }
  16457. p = 0;
  16458. }
  16459. error('JPX Error: Out of packets');
  16460. };
  16461. }
  16462. function PositionComponentResolutionLayerIterator(context) {
  16463. var siz = context.SIZ;
  16464. var tileIndex = context.currentTile.index;
  16465. var tile = context.tiles[tileIndex];
  16466. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  16467. var componentsCount = siz.Csiz;
  16468. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  16469. var precinctsIterationSizes = precinctsSizes;
  16470. var l = 0, r = 0, c = 0, px = 0, py = 0;
  16471. this.nextPacket = function JpxImage_nextPacket() {
  16472. // Section B.12.1.4 Position-component-resolution-layer
  16473. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  16474. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  16475. for (; c < componentsCount; c++) {
  16476. var component = tile.components[c];
  16477. var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
  16478. for (; r <= decompositionLevelsCount; r++) {
  16479. var resolution = component.resolutions[r];
  16480. var sizeInImageScale = precinctsSizes.components[c].resolutions[r];
  16481. var k = getPrecinctIndexIfExist(px, py, sizeInImageScale, precinctsIterationSizes, resolution);
  16482. if (k === null) {
  16483. continue;
  16484. }
  16485. for (; l < layersCount;) {
  16486. var packet = createPacket(resolution, k, l);
  16487. l++;
  16488. return packet;
  16489. }
  16490. l = 0;
  16491. }
  16492. r = 0;
  16493. }
  16494. c = 0;
  16495. }
  16496. px = 0;
  16497. }
  16498. error('JPX Error: Out of packets');
  16499. };
  16500. }
  16501. function ComponentPositionResolutionLayerIterator(context) {
  16502. var siz = context.SIZ;
  16503. var tileIndex = context.currentTile.index;
  16504. var tile = context.tiles[tileIndex];
  16505. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  16506. var componentsCount = siz.Csiz;
  16507. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  16508. var l = 0, r = 0, c = 0, px = 0, py = 0;
  16509. this.nextPacket = function JpxImage_nextPacket() {
  16510. // Section B.12.1.5 Component-position-resolution-layer
  16511. for (; c < componentsCount; ++c) {
  16512. var component = tile.components[c];
  16513. var precinctsIterationSizes = precinctsSizes.components[c];
  16514. var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
  16515. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  16516. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  16517. for (; r <= decompositionLevelsCount; r++) {
  16518. var resolution = component.resolutions[r];
  16519. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  16520. var k = getPrecinctIndexIfExist(px, py, sizeInImageScale, precinctsIterationSizes, resolution);
  16521. if (k === null) {
  16522. continue;
  16523. }
  16524. for (; l < layersCount;) {
  16525. var packet = createPacket(resolution, k, l);
  16526. l++;
  16527. return packet;
  16528. }
  16529. l = 0;
  16530. }
  16531. r = 0;
  16532. }
  16533. px = 0;
  16534. }
  16535. py = 0;
  16536. }
  16537. error('JPX Error: Out of packets');
  16538. };
  16539. }
  16540. function getPrecinctIndexIfExist(pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  16541. var posX = pxIndex * precinctIterationSizes.minWidth;
  16542. var posY = pyIndex * precinctIterationSizes.minHeight;
  16543. if (posX % sizeInImageScale.width !== 0 || posY % sizeInImageScale.height !== 0) {
  16544. return null;
  16545. }
  16546. var startPrecinctRowIndex = posY / sizeInImageScale.width * resolution.precinctParameters.numprecinctswide;
  16547. return posX / sizeInImageScale.height + startPrecinctRowIndex;
  16548. }
  16549. function getPrecinctSizesInImageScale(tile) {
  16550. var componentsCount = tile.components.length;
  16551. var minWidth = Number.MAX_VALUE;
  16552. var minHeight = Number.MAX_VALUE;
  16553. var maxNumWide = 0;
  16554. var maxNumHigh = 0;
  16555. var sizePerComponent = new Array(componentsCount);
  16556. for (var c = 0; c < componentsCount; c++) {
  16557. var component = tile.components[c];
  16558. var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
  16559. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  16560. var minWidthCurrentComponent = Number.MAX_VALUE;
  16561. var minHeightCurrentComponent = Number.MAX_VALUE;
  16562. var maxNumWideCurrentComponent = 0;
  16563. var maxNumHighCurrentComponent = 0;
  16564. var scale = 1;
  16565. for (var r = decompositionLevelsCount; r >= 0; --r) {
  16566. var resolution = component.resolutions[r];
  16567. var widthCurrentResolution = scale * resolution.precinctParameters.precinctWidth;
  16568. var heightCurrentResolution = scale * resolution.precinctParameters.precinctHeight;
  16569. minWidthCurrentComponent = Math.min(minWidthCurrentComponent, widthCurrentResolution);
  16570. minHeightCurrentComponent = Math.min(minHeightCurrentComponent, heightCurrentResolution);
  16571. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent, resolution.precinctParameters.numprecinctswide);
  16572. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent, resolution.precinctParameters.numprecinctshigh);
  16573. sizePerResolution[r] = {
  16574. width: widthCurrentResolution,
  16575. height: heightCurrentResolution
  16576. };
  16577. scale <<= 1;
  16578. }
  16579. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  16580. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  16581. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  16582. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  16583. sizePerComponent[c] = {
  16584. resolutions: sizePerResolution,
  16585. minWidth: minWidthCurrentComponent,
  16586. minHeight: minHeightCurrentComponent,
  16587. maxNumWide: maxNumWideCurrentComponent,
  16588. maxNumHigh: maxNumHighCurrentComponent
  16589. };
  16590. }
  16591. return {
  16592. components: sizePerComponent,
  16593. minWidth: minWidth,
  16594. minHeight: minHeight,
  16595. maxNumWide: maxNumWide,
  16596. maxNumHigh: maxNumHigh
  16597. };
  16598. }
  16599. function buildPackets(context) {
  16600. var siz = context.SIZ;
  16601. var tileIndex = context.currentTile.index;
  16602. var tile = context.tiles[tileIndex];
  16603. var componentsCount = siz.Csiz;
  16604. // Creating resolutions and sub-bands for each component
  16605. for (var c = 0; c < componentsCount; c++) {
  16606. var component = tile.components[c];
  16607. var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
  16608. // Section B.5 Resolution levels and sub-bands
  16609. var resolutions = [];
  16610. var subbands = [];
  16611. for (var r = 0; r <= decompositionLevelsCount; r++) {
  16612. var blocksDimensions = getBlocksDimensions(context, component, r);
  16613. var resolution = {};
  16614. var scale = 1 << decompositionLevelsCount - r;
  16615. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  16616. resolution.try0 = Math.ceil(component.tcy0 / scale);
  16617. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  16618. resolution.try1 = Math.ceil(component.tcy1 / scale);
  16619. resolution.resLevel = r;
  16620. buildPrecincts(context, resolution, blocksDimensions);
  16621. resolutions.push(resolution);
  16622. var subband;
  16623. if (r === 0) {
  16624. // one sub-band (LL) with last decomposition
  16625. subband = {};
  16626. subband.type = 'LL';
  16627. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  16628. subband.tby0 = Math.ceil(component.tcy0 / scale);
  16629. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  16630. subband.tby1 = Math.ceil(component.tcy1 / scale);
  16631. subband.resolution = resolution;
  16632. buildCodeblocks(context, subband, blocksDimensions);
  16633. subbands.push(subband);
  16634. resolution.subbands = [subband];
  16635. } else {
  16636. var bscale = 1 << decompositionLevelsCount - r + 1;
  16637. var resolutionSubbands = [];
  16638. // three sub-bands (HL, LH and HH) with rest of decompositions
  16639. subband = {};
  16640. subband.type = 'HL';
  16641. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  16642. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  16643. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  16644. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  16645. subband.resolution = resolution;
  16646. buildCodeblocks(context, subband, blocksDimensions);
  16647. subbands.push(subband);
  16648. resolutionSubbands.push(subband);
  16649. subband = {};
  16650. subband.type = 'LH';
  16651. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  16652. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  16653. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  16654. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  16655. subband.resolution = resolution;
  16656. buildCodeblocks(context, subband, blocksDimensions);
  16657. subbands.push(subband);
  16658. resolutionSubbands.push(subband);
  16659. subband = {};
  16660. subband.type = 'HH';
  16661. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  16662. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  16663. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  16664. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  16665. subband.resolution = resolution;
  16666. buildCodeblocks(context, subband, blocksDimensions);
  16667. subbands.push(subband);
  16668. resolutionSubbands.push(subband);
  16669. resolution.subbands = resolutionSubbands;
  16670. }
  16671. }
  16672. component.resolutions = resolutions;
  16673. component.subbands = subbands;
  16674. }
  16675. // Generate the packets sequence
  16676. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  16677. switch (progressionOrder) {
  16678. case 0:
  16679. tile.packetsIterator = new LayerResolutionComponentPositionIterator(context);
  16680. break;
  16681. case 1:
  16682. tile.packetsIterator = new ResolutionLayerComponentPositionIterator(context);
  16683. break;
  16684. case 2:
  16685. tile.packetsIterator = new ResolutionPositionComponentLayerIterator(context);
  16686. break;
  16687. case 3:
  16688. tile.packetsIterator = new PositionComponentResolutionLayerIterator(context);
  16689. break;
  16690. case 4:
  16691. tile.packetsIterator = new ComponentPositionResolutionLayerIterator(context);
  16692. break;
  16693. default:
  16694. error('JPX Error: Unsupported progression order ' + progressionOrder);
  16695. }
  16696. }
  16697. function parseTilePackets(context, data, offset, dataLength) {
  16698. var position = 0;
  16699. var buffer, bufferSize = 0, skipNextBit = false;
  16700. function readBits(count) {
  16701. while (bufferSize < count) {
  16702. var b = data[offset + position];
  16703. position++;
  16704. if (skipNextBit) {
  16705. buffer = buffer << 7 | b;
  16706. bufferSize += 7;
  16707. skipNextBit = false;
  16708. } else {
  16709. buffer = buffer << 8 | b;
  16710. bufferSize += 8;
  16711. }
  16712. if (b === 0xFF) {
  16713. skipNextBit = true;
  16714. }
  16715. }
  16716. bufferSize -= count;
  16717. return buffer >>> bufferSize & (1 << count) - 1;
  16718. }
  16719. function skipMarkerIfEqual(value) {
  16720. if (data[offset + position - 1] === 0xFF && data[offset + position] === value) {
  16721. skipBytes(1);
  16722. return true;
  16723. } else if (data[offset + position] === 0xFF && data[offset + position + 1] === value) {
  16724. skipBytes(2);
  16725. return true;
  16726. }
  16727. return false;
  16728. }
  16729. function skipBytes(count) {
  16730. position += count;
  16731. }
  16732. function alignToByte() {
  16733. bufferSize = 0;
  16734. if (skipNextBit) {
  16735. position++;
  16736. skipNextBit = false;
  16737. }
  16738. }
  16739. function readCodingpasses() {
  16740. if (readBits(1) === 0) {
  16741. return 1;
  16742. }
  16743. if (readBits(1) === 0) {
  16744. return 2;
  16745. }
  16746. var value = readBits(2);
  16747. if (value < 3) {
  16748. return value + 3;
  16749. }
  16750. value = readBits(5);
  16751. if (value < 31) {
  16752. return value + 6;
  16753. }
  16754. value = readBits(7);
  16755. return value + 37;
  16756. }
  16757. var tileIndex = context.currentTile.index;
  16758. var tile = context.tiles[tileIndex];
  16759. var sopMarkerUsed = context.COD.sopMarkerUsed;
  16760. var ephMarkerUsed = context.COD.ephMarkerUsed;
  16761. var packetsIterator = tile.packetsIterator;
  16762. while (position < dataLength) {
  16763. alignToByte();
  16764. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  16765. // Skip also marker segment length and packet sequence ID
  16766. skipBytes(4);
  16767. }
  16768. var packet = packetsIterator.nextPacket();
  16769. if (!readBits(1)) {
  16770. continue;
  16771. }
  16772. var layerNumber = packet.layerNumber;
  16773. var queue = [], codeblock;
  16774. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  16775. codeblock = packet.codeblocks[i];
  16776. var precinct = codeblock.precinct;
  16777. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  16778. var codeblockRow = codeblock.cby - precinct.cbyMin;
  16779. var codeblockIncluded = false;
  16780. var firstTimeInclusion = false;
  16781. var valueReady;
  16782. if (codeblock['included'] !== undefined) {
  16783. codeblockIncluded = !!readBits(1);
  16784. } else {
  16785. // reading inclusion tree
  16786. precinct = codeblock.precinct;
  16787. var inclusionTree, zeroBitPlanesTree;
  16788. if (precinct['inclusionTree'] !== undefined) {
  16789. inclusionTree = precinct.inclusionTree;
  16790. } else {
  16791. // building inclusion and zero bit-planes trees
  16792. var width = precinct.cbxMax - precinct.cbxMin + 1;
  16793. var height = precinct.cbyMax - precinct.cbyMin + 1;
  16794. inclusionTree = new InclusionTree(width, height, layerNumber);
  16795. zeroBitPlanesTree = new TagTree(width, height);
  16796. precinct.inclusionTree = inclusionTree;
  16797. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  16798. }
  16799. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  16800. while (true) {
  16801. if (readBits(1)) {
  16802. valueReady = !inclusionTree.nextLevel();
  16803. if (valueReady) {
  16804. codeblock.included = true;
  16805. codeblockIncluded = firstTimeInclusion = true;
  16806. break;
  16807. }
  16808. } else {
  16809. inclusionTree.incrementValue(layerNumber);
  16810. break;
  16811. }
  16812. }
  16813. }
  16814. }
  16815. if (!codeblockIncluded) {
  16816. continue;
  16817. }
  16818. if (firstTimeInclusion) {
  16819. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  16820. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  16821. while (true) {
  16822. if (readBits(1)) {
  16823. valueReady = !zeroBitPlanesTree.nextLevel();
  16824. if (valueReady) {
  16825. break;
  16826. }
  16827. } else {
  16828. zeroBitPlanesTree.incrementValue();
  16829. }
  16830. }
  16831. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  16832. }
  16833. var codingpasses = readCodingpasses();
  16834. while (readBits(1)) {
  16835. codeblock.Lblock++;
  16836. }
  16837. var codingpassesLog2 = log2(codingpasses);
  16838. // rounding down log2
  16839. var bits = (codingpasses < 1 << codingpassesLog2 ? codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  16840. var codedDataLength = readBits(bits);
  16841. queue.push({
  16842. codeblock: codeblock,
  16843. codingpasses: codingpasses,
  16844. dataLength: codedDataLength
  16845. });
  16846. }
  16847. alignToByte();
  16848. if (ephMarkerUsed) {
  16849. skipMarkerIfEqual(0x92);
  16850. }
  16851. while (queue.length > 0) {
  16852. var packetItem = queue.shift();
  16853. codeblock = packetItem.codeblock;
  16854. if (codeblock['data'] === undefined) {
  16855. codeblock.data = [];
  16856. }
  16857. codeblock.data.push({
  16858. data: data,
  16859. start: offset + position,
  16860. end: offset + position + packetItem.dataLength,
  16861. codingpasses: packetItem.codingpasses
  16862. });
  16863. position += packetItem.dataLength;
  16864. }
  16865. }
  16866. return position;
  16867. }
  16868. function copyCoefficients(coefficients, levelWidth, levelHeight, subband, delta, mb, reversible, segmentationSymbolUsed) {
  16869. var x0 = subband.tbx0;
  16870. var y0 = subband.tby0;
  16871. var width = subband.tbx1 - subband.tbx0;
  16872. var codeblocks = subband.codeblocks;
  16873. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  16874. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  16875. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  16876. var codeblock = codeblocks[i];
  16877. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  16878. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  16879. if (blockWidth === 0 || blockHeight === 0) {
  16880. continue;
  16881. }
  16882. if (codeblock['data'] === undefined) {
  16883. continue;
  16884. }
  16885. var bitModel, currentCodingpassType;
  16886. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType, codeblock.zeroBitPlanes, mb);
  16887. currentCodingpassType = 2;
  16888. // first bit plane starts from cleanup
  16889. // collect data
  16890. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  16891. var j, jj, dataItem;
  16892. for (j = 0, jj = data.length; j < jj; j++) {
  16893. dataItem = data[j];
  16894. totalLength += dataItem.end - dataItem.start;
  16895. codingpasses += dataItem.codingpasses;
  16896. }
  16897. var encodedData = new Uint8Array(totalLength);
  16898. var position = 0;
  16899. for (j = 0, jj = data.length; j < jj; j++) {
  16900. dataItem = data[j];
  16901. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  16902. encodedData.set(chunk, position);
  16903. position += chunk.length;
  16904. }
  16905. // decoding the item
  16906. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  16907. bitModel.setDecoder(decoder);
  16908. for (j = 0; j < codingpasses; j++) {
  16909. switch (currentCodingpassType) {
  16910. case 0:
  16911. bitModel.runSignificancePropagationPass();
  16912. break;
  16913. case 1:
  16914. bitModel.runMagnitudeRefinementPass();
  16915. break;
  16916. case 2:
  16917. bitModel.runCleanupPass();
  16918. if (segmentationSymbolUsed) {
  16919. bitModel.checkSegmentationSymbol();
  16920. }
  16921. break;
  16922. }
  16923. currentCodingpassType = (currentCodingpassType + 1) % 3;
  16924. }
  16925. var offset = codeblock.tbx0_ - x0 + (codeblock.tby0_ - y0) * width;
  16926. var sign = bitModel.coefficentsSign;
  16927. var magnitude = bitModel.coefficentsMagnitude;
  16928. var bitsDecoded = bitModel.bitsDecoded;
  16929. var magnitudeCorrection = reversible ? 0 : 0.5;
  16930. var k, n, nb;
  16931. position = 0;
  16932. // Do the interleaving of Section F.3.3 here, so we do not need
  16933. // to copy later. LL level is not interleaved, just copied.
  16934. var interleave = subband.type !== 'LL';
  16935. for (j = 0; j < blockHeight; j++) {
  16936. var row = offset / width | 0;
  16937. // row in the non-interleaved subband
  16938. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  16939. for (k = 0; k < blockWidth; k++) {
  16940. n = magnitude[position];
  16941. if (n !== 0) {
  16942. n = (n + magnitudeCorrection) * delta;
  16943. if (sign[position] !== 0) {
  16944. n = -n;
  16945. }
  16946. nb = bitsDecoded[position];
  16947. var pos = interleave ? levelOffset + (offset << 1) : offset;
  16948. if (reversible && nb >= mb) {
  16949. coefficients[pos] = n;
  16950. } else {
  16951. coefficients[pos] = n * (1 << mb - nb);
  16952. }
  16953. }
  16954. offset++;
  16955. position++;
  16956. }
  16957. offset += width - blockWidth;
  16958. }
  16959. }
  16960. }
  16961. function transformTile(context, tile, c) {
  16962. var component = tile.components[c];
  16963. var codingStyleParameters = component.codingStyleParameters;
  16964. var quantizationParameters = component.quantizationParameters;
  16965. var decompositionLevelsCount = codingStyleParameters.decompositionLevelsCount;
  16966. var spqcds = quantizationParameters.SPqcds;
  16967. var scalarExpounded = quantizationParameters.scalarExpounded;
  16968. var guardBits = quantizationParameters.guardBits;
  16969. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  16970. var precision = context.components[c].precision;
  16971. var reversible = codingStyleParameters.reversibleTransformation;
  16972. var transform = reversible ? new ReversibleTransform() : new IrreversibleTransform();
  16973. var subbandCoefficients = [];
  16974. var b = 0;
  16975. for (var i = 0; i <= decompositionLevelsCount; i++) {
  16976. var resolution = component.resolutions[i];
  16977. var width = resolution.trx1 - resolution.trx0;
  16978. var height = resolution.try1 - resolution.try0;
  16979. // Allocate space for the whole sublevel.
  16980. var coefficients = new Float32Array(width * height);
  16981. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  16982. var mu, epsilon;
  16983. if (!scalarExpounded) {
  16984. // formula E-5
  16985. mu = spqcds[0].mu;
  16986. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  16987. } else {
  16988. mu = spqcds[b].mu;
  16989. epsilon = spqcds[b].epsilon;
  16990. b++;
  16991. }
  16992. var subband = resolution.subbands[j];
  16993. var gainLog2 = SubbandsGainLog2[subband.type];
  16994. // calculate quantization coefficient (Section E.1.1.1)
  16995. var delta = reversible ? 1 : Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048);
  16996. var mb = guardBits + epsilon - 1;
  16997. // In the first resolution level, copyCoefficients will fill the
  16998. // whole array with coefficients. In the succeeding passes,
  16999. // copyCoefficients will consecutively fill in the values that belong
  17000. // to the interleaved positions of the HL, LH, and HH coefficients.
  17001. // The LL coefficients will then be interleaved in Transform.iterate().
  17002. copyCoefficients(coefficients, width, height, subband, delta, mb, reversible, segmentationSymbolUsed);
  17003. }
  17004. subbandCoefficients.push({
  17005. width: width,
  17006. height: height,
  17007. items: coefficients
  17008. });
  17009. }
  17010. var result = transform.calculate(subbandCoefficients, component.tcx0, component.tcy0);
  17011. return {
  17012. left: component.tcx0,
  17013. top: component.tcy0,
  17014. width: result.width,
  17015. height: result.height,
  17016. items: result.items
  17017. };
  17018. }
  17019. function transformComponents(context) {
  17020. var siz = context.SIZ;
  17021. var components = context.components;
  17022. var componentsCount = siz.Csiz;
  17023. var resultImages = [];
  17024. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  17025. var tile = context.tiles[i];
  17026. var transformedTiles = [];
  17027. var c;
  17028. for (c = 0; c < componentsCount; c++) {
  17029. transformedTiles[c] = transformTile(context, tile, c);
  17030. }
  17031. var tile0 = transformedTiles[0];
  17032. var out = new Uint8Array(tile0.items.length * componentsCount);
  17033. var result = {
  17034. left: tile0.left,
  17035. top: tile0.top,
  17036. width: tile0.width,
  17037. height: tile0.height,
  17038. items: out
  17039. };
  17040. // Section G.2.2 Inverse multi component transform
  17041. var shift, offset, max, min, maxK;
  17042. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  17043. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  17044. var fourComponents = componentsCount === 4;
  17045. var y0items = transformedTiles[0].items;
  17046. var y1items = transformedTiles[1].items;
  17047. var y2items = transformedTiles[2].items;
  17048. var y3items = fourComponents ? transformedTiles[3].items : null;
  17049. // HACK: The multiple component transform formulas below assume that
  17050. // all components have the same precision. With this in mind, we
  17051. // compute shift and offset only once.
  17052. shift = components[0].precision - 8;
  17053. offset = (128 << shift) + 0.5;
  17054. max = 255 * (1 << shift);
  17055. maxK = max * 0.5;
  17056. min = -maxK;
  17057. var component0 = tile.components[0];
  17058. var alpha01 = componentsCount - 3;
  17059. jj = y0items.length;
  17060. if (!component0.codingStyleParameters.reversibleTransformation) {
  17061. // inverse irreversible multiple component transform
  17062. for (j = 0; j < jj; j++, pos += alpha01) {
  17063. y0 = y0items[j] + offset;
  17064. y1 = y1items[j];
  17065. y2 = y2items[j];
  17066. r = y0 + 1.402 * y2;
  17067. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  17068. b = y0 + 1.772 * y1;
  17069. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  17070. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  17071. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  17072. }
  17073. } else {
  17074. // inverse reversible multiple component transform
  17075. for (j = 0; j < jj; j++, pos += alpha01) {
  17076. y0 = y0items[j] + offset;
  17077. y1 = y1items[j];
  17078. y2 = y2items[j];
  17079. g = y0 - (y2 + y1 >> 2);
  17080. r = g + y2;
  17081. b = g + y1;
  17082. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  17083. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  17084. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  17085. }
  17086. }
  17087. if (fourComponents) {
  17088. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  17089. k = y3items[j];
  17090. out[pos] = k <= min ? 0 : k >= maxK ? 255 : k + offset >> shift;
  17091. }
  17092. }
  17093. } else {
  17094. // no multi-component transform
  17095. for (c = 0; c < componentsCount; c++) {
  17096. var items = transformedTiles[c].items;
  17097. shift = components[c].precision - 8;
  17098. offset = (128 << shift) + 0.5;
  17099. max = 127.5 * (1 << shift);
  17100. min = -max;
  17101. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  17102. val = items[j];
  17103. out[pos] = val <= min ? 0 : val >= max ? 255 : val + offset >> shift;
  17104. pos += componentsCount;
  17105. }
  17106. }
  17107. }
  17108. resultImages.push(result);
  17109. }
  17110. return resultImages;
  17111. }
  17112. function initializeTile(context, tileIndex) {
  17113. var siz = context.SIZ;
  17114. var componentsCount = siz.Csiz;
  17115. var tile = context.tiles[tileIndex];
  17116. for (var c = 0; c < componentsCount; c++) {
  17117. var component = tile.components[c];
  17118. var qcdOrQcc = context.currentTile.QCC[c] !== undefined ? context.currentTile.QCC[c] : context.currentTile.QCD;
  17119. component.quantizationParameters = qcdOrQcc;
  17120. var codOrCoc = context.currentTile.COC[c] !== undefined ? context.currentTile.COC[c] : context.currentTile.COD;
  17121. component.codingStyleParameters = codOrCoc;
  17122. }
  17123. tile.codingStyleDefaultParameters = context.currentTile.COD;
  17124. }
  17125. // Section B.10.2 Tag trees
  17126. var TagTree = function TagTreeClosure() {
  17127. function TagTree(width, height) {
  17128. var levelsLength = log2(Math.max(width, height)) + 1;
  17129. this.levels = [];
  17130. for (var i = 0; i < levelsLength; i++) {
  17131. var level = {
  17132. width: width,
  17133. height: height,
  17134. items: []
  17135. };
  17136. this.levels.push(level);
  17137. width = Math.ceil(width / 2);
  17138. height = Math.ceil(height / 2);
  17139. }
  17140. }
  17141. TagTree.prototype = {
  17142. reset: function TagTree_reset(i, j) {
  17143. var currentLevel = 0, value = 0, level;
  17144. while (currentLevel < this.levels.length) {
  17145. level = this.levels[currentLevel];
  17146. var index = i + j * level.width;
  17147. if (level.items[index] !== undefined) {
  17148. value = level.items[index];
  17149. break;
  17150. }
  17151. level.index = index;
  17152. i >>= 1;
  17153. j >>= 1;
  17154. currentLevel++;
  17155. }
  17156. currentLevel--;
  17157. level = this.levels[currentLevel];
  17158. level.items[level.index] = value;
  17159. this.currentLevel = currentLevel;
  17160. delete this.value;
  17161. },
  17162. incrementValue: function TagTree_incrementValue() {
  17163. var level = this.levels[this.currentLevel];
  17164. level.items[level.index]++;
  17165. },
  17166. nextLevel: function TagTree_nextLevel() {
  17167. var currentLevel = this.currentLevel;
  17168. var level = this.levels[currentLevel];
  17169. var value = level.items[level.index];
  17170. currentLevel--;
  17171. if (currentLevel < 0) {
  17172. this.value = value;
  17173. return false;
  17174. }
  17175. this.currentLevel = currentLevel;
  17176. level = this.levels[currentLevel];
  17177. level.items[level.index] = value;
  17178. return true;
  17179. }
  17180. };
  17181. return TagTree;
  17182. }();
  17183. var InclusionTree = function InclusionTreeClosure() {
  17184. function InclusionTree(width, height, defaultValue) {
  17185. var levelsLength = log2(Math.max(width, height)) + 1;
  17186. this.levels = [];
  17187. for (var i = 0; i < levelsLength; i++) {
  17188. var items = new Uint8Array(width * height);
  17189. for (var j = 0, jj = items.length; j < jj; j++) {
  17190. items[j] = defaultValue;
  17191. }
  17192. var level = {
  17193. width: width,
  17194. height: height,
  17195. items: items
  17196. };
  17197. this.levels.push(level);
  17198. width = Math.ceil(width / 2);
  17199. height = Math.ceil(height / 2);
  17200. }
  17201. }
  17202. InclusionTree.prototype = {
  17203. reset: function InclusionTree_reset(i, j, stopValue) {
  17204. var currentLevel = 0;
  17205. while (currentLevel < this.levels.length) {
  17206. var level = this.levels[currentLevel];
  17207. var index = i + j * level.width;
  17208. level.index = index;
  17209. var value = level.items[index];
  17210. if (value === 0xFF) {
  17211. break;
  17212. }
  17213. if (value > stopValue) {
  17214. this.currentLevel = currentLevel;
  17215. // already know about this one, propagating the value to top levels
  17216. this.propagateValues();
  17217. return false;
  17218. }
  17219. i >>= 1;
  17220. j >>= 1;
  17221. currentLevel++;
  17222. }
  17223. this.currentLevel = currentLevel - 1;
  17224. return true;
  17225. },
  17226. incrementValue: function InclusionTree_incrementValue(stopValue) {
  17227. var level = this.levels[this.currentLevel];
  17228. level.items[level.index] = stopValue + 1;
  17229. this.propagateValues();
  17230. },
  17231. propagateValues: function InclusionTree_propagateValues() {
  17232. var levelIndex = this.currentLevel;
  17233. var level = this.levels[levelIndex];
  17234. var currentValue = level.items[level.index];
  17235. while (--levelIndex >= 0) {
  17236. level = this.levels[levelIndex];
  17237. level.items[level.index] = currentValue;
  17238. }
  17239. },
  17240. nextLevel: function InclusionTree_nextLevel() {
  17241. var currentLevel = this.currentLevel;
  17242. var level = this.levels[currentLevel];
  17243. var value = level.items[level.index];
  17244. level.items[level.index] = 0xFF;
  17245. currentLevel--;
  17246. if (currentLevel < 0) {
  17247. return false;
  17248. }
  17249. this.currentLevel = currentLevel;
  17250. level = this.levels[currentLevel];
  17251. level.items[level.index] = value;
  17252. return true;
  17253. }
  17254. };
  17255. return InclusionTree;
  17256. }();
  17257. // Section D. Coefficient bit modeling
  17258. var BitModel = function BitModelClosure() {
  17259. var UNIFORM_CONTEXT = 17;
  17260. var RUNLENGTH_CONTEXT = 18;
  17261. // Table D-1
  17262. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  17263. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  17264. var LLAndLHContextsLabel = new Uint8Array([
  17265. 0,
  17266. 5,
  17267. 8,
  17268. 0,
  17269. 3,
  17270. 7,
  17271. 8,
  17272. 0,
  17273. 4,
  17274. 7,
  17275. 8,
  17276. 0,
  17277. 0,
  17278. 0,
  17279. 0,
  17280. 0,
  17281. 1,
  17282. 6,
  17283. 8,
  17284. 0,
  17285. 3,
  17286. 7,
  17287. 8,
  17288. 0,
  17289. 4,
  17290. 7,
  17291. 8,
  17292. 0,
  17293. 0,
  17294. 0,
  17295. 0,
  17296. 0,
  17297. 2,
  17298. 6,
  17299. 8,
  17300. 0,
  17301. 3,
  17302. 7,
  17303. 8,
  17304. 0,
  17305. 4,
  17306. 7,
  17307. 8,
  17308. 0,
  17309. 0,
  17310. 0,
  17311. 0,
  17312. 0,
  17313. 2,
  17314. 6,
  17315. 8,
  17316. 0,
  17317. 3,
  17318. 7,
  17319. 8,
  17320. 0,
  17321. 4,
  17322. 7,
  17323. 8,
  17324. 0,
  17325. 0,
  17326. 0,
  17327. 0,
  17328. 0,
  17329. 2,
  17330. 6,
  17331. 8,
  17332. 0,
  17333. 3,
  17334. 7,
  17335. 8,
  17336. 0,
  17337. 4,
  17338. 7,
  17339. 8
  17340. ]);
  17341. var HLContextLabel = new Uint8Array([
  17342. 0,
  17343. 3,
  17344. 4,
  17345. 0,
  17346. 5,
  17347. 7,
  17348. 7,
  17349. 0,
  17350. 8,
  17351. 8,
  17352. 8,
  17353. 0,
  17354. 0,
  17355. 0,
  17356. 0,
  17357. 0,
  17358. 1,
  17359. 3,
  17360. 4,
  17361. 0,
  17362. 6,
  17363. 7,
  17364. 7,
  17365. 0,
  17366. 8,
  17367. 8,
  17368. 8,
  17369. 0,
  17370. 0,
  17371. 0,
  17372. 0,
  17373. 0,
  17374. 2,
  17375. 3,
  17376. 4,
  17377. 0,
  17378. 6,
  17379. 7,
  17380. 7,
  17381. 0,
  17382. 8,
  17383. 8,
  17384. 8,
  17385. 0,
  17386. 0,
  17387. 0,
  17388. 0,
  17389. 0,
  17390. 2,
  17391. 3,
  17392. 4,
  17393. 0,
  17394. 6,
  17395. 7,
  17396. 7,
  17397. 0,
  17398. 8,
  17399. 8,
  17400. 8,
  17401. 0,
  17402. 0,
  17403. 0,
  17404. 0,
  17405. 0,
  17406. 2,
  17407. 3,
  17408. 4,
  17409. 0,
  17410. 6,
  17411. 7,
  17412. 7,
  17413. 0,
  17414. 8,
  17415. 8,
  17416. 8
  17417. ]);
  17418. var HHContextLabel = new Uint8Array([
  17419. 0,
  17420. 1,
  17421. 2,
  17422. 0,
  17423. 1,
  17424. 2,
  17425. 2,
  17426. 0,
  17427. 2,
  17428. 2,
  17429. 2,
  17430. 0,
  17431. 0,
  17432. 0,
  17433. 0,
  17434. 0,
  17435. 3,
  17436. 4,
  17437. 5,
  17438. 0,
  17439. 4,
  17440. 5,
  17441. 5,
  17442. 0,
  17443. 5,
  17444. 5,
  17445. 5,
  17446. 0,
  17447. 0,
  17448. 0,
  17449. 0,
  17450. 0,
  17451. 6,
  17452. 7,
  17453. 7,
  17454. 0,
  17455. 7,
  17456. 7,
  17457. 7,
  17458. 0,
  17459. 7,
  17460. 7,
  17461. 7,
  17462. 0,
  17463. 0,
  17464. 0,
  17465. 0,
  17466. 0,
  17467. 8,
  17468. 8,
  17469. 8,
  17470. 0,
  17471. 8,
  17472. 8,
  17473. 8,
  17474. 0,
  17475. 8,
  17476. 8,
  17477. 8,
  17478. 0,
  17479. 0,
  17480. 0,
  17481. 0,
  17482. 0,
  17483. 8,
  17484. 8,
  17485. 8,
  17486. 0,
  17487. 8,
  17488. 8,
  17489. 8,
  17490. 0,
  17491. 8,
  17492. 8,
  17493. 8
  17494. ]);
  17495. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  17496. this.width = width;
  17497. this.height = height;
  17498. this.contextLabelTable = subband === 'HH' ? HHContextLabel : subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel;
  17499. var coefficientCount = width * height;
  17500. // coefficients outside the encoding region treated as insignificant
  17501. // add border state cells for significanceState
  17502. this.neighborsSignificance = new Uint8Array(coefficientCount);
  17503. this.coefficentsSign = new Uint8Array(coefficientCount);
  17504. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) : mb > 6 ? new Uint16Array(coefficientCount) : new Uint8Array(coefficientCount);
  17505. this.processingFlags = new Uint8Array(coefficientCount);
  17506. var bitsDecoded = new Uint8Array(coefficientCount);
  17507. if (zeroBitPlanes !== 0) {
  17508. for (var i = 0; i < coefficientCount; i++) {
  17509. bitsDecoded[i] = zeroBitPlanes;
  17510. }
  17511. }
  17512. this.bitsDecoded = bitsDecoded;
  17513. this.reset();
  17514. }
  17515. BitModel.prototype = {
  17516. setDecoder: function BitModel_setDecoder(decoder) {
  17517. this.decoder = decoder;
  17518. },
  17519. reset: function BitModel_reset() {
  17520. // We have 17 contexts that are accessed via context labels,
  17521. // plus the uniform and runlength context.
  17522. this.contexts = new Int8Array(19);
  17523. // Contexts are packed into 1 byte:
  17524. // highest 7 bits carry the index, lowest bit carries mps
  17525. this.contexts[0] = 4 << 1 | 0;
  17526. this.contexts[UNIFORM_CONTEXT] = 46 << 1 | 0;
  17527. this.contexts[RUNLENGTH_CONTEXT] = 3 << 1 | 0;
  17528. },
  17529. setNeighborsSignificance: function BitModel_setNeighborsSignificance(row, column, index) {
  17530. var neighborsSignificance = this.neighborsSignificance;
  17531. var width = this.width, height = this.height;
  17532. var left = column > 0;
  17533. var right = column + 1 < width;
  17534. var i;
  17535. if (row > 0) {
  17536. i = index - width;
  17537. if (left) {
  17538. neighborsSignificance[i - 1] += 0x10;
  17539. }
  17540. if (right) {
  17541. neighborsSignificance[i + 1] += 0x10;
  17542. }
  17543. neighborsSignificance[i] += 0x04;
  17544. }
  17545. if (row + 1 < height) {
  17546. i = index + width;
  17547. if (left) {
  17548. neighborsSignificance[i - 1] += 0x10;
  17549. }
  17550. if (right) {
  17551. neighborsSignificance[i + 1] += 0x10;
  17552. }
  17553. neighborsSignificance[i] += 0x04;
  17554. }
  17555. if (left) {
  17556. neighborsSignificance[index - 1] += 0x01;
  17557. }
  17558. if (right) {
  17559. neighborsSignificance[index + 1] += 0x01;
  17560. }
  17561. neighborsSignificance[index] |= 0x80;
  17562. },
  17563. runSignificancePropagationPass: function BitModel_runSignificancePropagationPass() {
  17564. var decoder = this.decoder;
  17565. var width = this.width, height = this.height;
  17566. var coefficentsMagnitude = this.coefficentsMagnitude;
  17567. var coefficentsSign = this.coefficentsSign;
  17568. var neighborsSignificance = this.neighborsSignificance;
  17569. var processingFlags = this.processingFlags;
  17570. var contexts = this.contexts;
  17571. var labels = this.contextLabelTable;
  17572. var bitsDecoded = this.bitsDecoded;
  17573. var processedInverseMask = ~1;
  17574. var processedMask = 1;
  17575. var firstMagnitudeBitMask = 2;
  17576. for (var i0 = 0; i0 < height; i0 += 4) {
  17577. for (var j = 0; j < width; j++) {
  17578. var index = i0 * width + j;
  17579. for (var i1 = 0; i1 < 4; i1++, index += width) {
  17580. var i = i0 + i1;
  17581. if (i >= height) {
  17582. break;
  17583. }
  17584. // clear processed flag first
  17585. processingFlags[index] &= processedInverseMask;
  17586. if (coefficentsMagnitude[index] || !neighborsSignificance[index]) {
  17587. continue;
  17588. }
  17589. var contextLabel = labels[neighborsSignificance[index]];
  17590. var decision = decoder.readBit(contexts, contextLabel);
  17591. if (decision) {
  17592. var sign = this.decodeSignBit(i, j, index);
  17593. coefficentsSign[index] = sign;
  17594. coefficentsMagnitude[index] = 1;
  17595. this.setNeighborsSignificance(i, j, index);
  17596. processingFlags[index] |= firstMagnitudeBitMask;
  17597. }
  17598. bitsDecoded[index]++;
  17599. processingFlags[index] |= processedMask;
  17600. }
  17601. }
  17602. }
  17603. },
  17604. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  17605. var width = this.width, height = this.height;
  17606. var coefficentsMagnitude = this.coefficentsMagnitude;
  17607. var coefficentsSign = this.coefficentsSign;
  17608. var contribution, sign0, sign1, significance1;
  17609. var contextLabel, decoded;
  17610. // calculate horizontal contribution
  17611. significance1 = column > 0 && coefficentsMagnitude[index - 1] !== 0;
  17612. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  17613. sign1 = coefficentsSign[index + 1];
  17614. if (significance1) {
  17615. sign0 = coefficentsSign[index - 1];
  17616. contribution = 1 - sign1 - sign0;
  17617. } else {
  17618. contribution = 1 - sign1 - sign1;
  17619. }
  17620. } else if (significance1) {
  17621. sign0 = coefficentsSign[index - 1];
  17622. contribution = 1 - sign0 - sign0;
  17623. } else {
  17624. contribution = 0;
  17625. }
  17626. var horizontalContribution = 3 * contribution;
  17627. // calculate vertical contribution and combine with the horizontal
  17628. significance1 = row > 0 && coefficentsMagnitude[index - width] !== 0;
  17629. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  17630. sign1 = coefficentsSign[index + width];
  17631. if (significance1) {
  17632. sign0 = coefficentsSign[index - width];
  17633. contribution = 1 - sign1 - sign0 + horizontalContribution;
  17634. } else {
  17635. contribution = 1 - sign1 - sign1 + horizontalContribution;
  17636. }
  17637. } else if (significance1) {
  17638. sign0 = coefficentsSign[index - width];
  17639. contribution = 1 - sign0 - sign0 + horizontalContribution;
  17640. } else {
  17641. contribution = horizontalContribution;
  17642. }
  17643. if (contribution >= 0) {
  17644. contextLabel = 9 + contribution;
  17645. decoded = this.decoder.readBit(this.contexts, contextLabel);
  17646. } else {
  17647. contextLabel = 9 - contribution;
  17648. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  17649. }
  17650. return decoded;
  17651. },
  17652. runMagnitudeRefinementPass: function BitModel_runMagnitudeRefinementPass() {
  17653. var decoder = this.decoder;
  17654. var width = this.width, height = this.height;
  17655. var coefficentsMagnitude = this.coefficentsMagnitude;
  17656. var neighborsSignificance = this.neighborsSignificance;
  17657. var contexts = this.contexts;
  17658. var bitsDecoded = this.bitsDecoded;
  17659. var processingFlags = this.processingFlags;
  17660. var processedMask = 1;
  17661. var firstMagnitudeBitMask = 2;
  17662. var length = width * height;
  17663. var width4 = width * 4;
  17664. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  17665. indexNext = Math.min(length, index0 + width4);
  17666. for (var j = 0; j < width; j++) {
  17667. for (var index = index0 + j; index < indexNext; index += width) {
  17668. // significant but not those that have just become
  17669. if (!coefficentsMagnitude[index] || (processingFlags[index] & processedMask) !== 0) {
  17670. continue;
  17671. }
  17672. var contextLabel = 16;
  17673. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  17674. processingFlags[index] ^= firstMagnitudeBitMask;
  17675. // first refinement
  17676. var significance = neighborsSignificance[index] & 127;
  17677. contextLabel = significance === 0 ? 15 : 14;
  17678. }
  17679. var bit = decoder.readBit(contexts, contextLabel);
  17680. coefficentsMagnitude[index] = coefficentsMagnitude[index] << 1 | bit;
  17681. bitsDecoded[index]++;
  17682. processingFlags[index] |= processedMask;
  17683. }
  17684. }
  17685. }
  17686. },
  17687. runCleanupPass: function BitModel_runCleanupPass() {
  17688. var decoder = this.decoder;
  17689. var width = this.width, height = this.height;
  17690. var neighborsSignificance = this.neighborsSignificance;
  17691. var coefficentsMagnitude = this.coefficentsMagnitude;
  17692. var coefficentsSign = this.coefficentsSign;
  17693. var contexts = this.contexts;
  17694. var labels = this.contextLabelTable;
  17695. var bitsDecoded = this.bitsDecoded;
  17696. var processingFlags = this.processingFlags;
  17697. var processedMask = 1;
  17698. var firstMagnitudeBitMask = 2;
  17699. var oneRowDown = width;
  17700. var twoRowsDown = width * 2;
  17701. var threeRowsDown = width * 3;
  17702. var iNext;
  17703. for (var i0 = 0; i0 < height; i0 = iNext) {
  17704. iNext = Math.min(i0 + 4, height);
  17705. var indexBase = i0 * width;
  17706. var checkAllEmpty = i0 + 3 < height;
  17707. for (var j = 0; j < width; j++) {
  17708. var index0 = indexBase + j;
  17709. // using the property: labels[neighborsSignificance[index]] === 0
  17710. // when neighborsSignificance[index] === 0
  17711. var allEmpty = checkAllEmpty && processingFlags[index0] === 0 && processingFlags[index0 + oneRowDown] === 0 && processingFlags[index0 + twoRowsDown] === 0 && processingFlags[index0 + threeRowsDown] === 0 && neighborsSignificance[index0] === 0 && neighborsSignificance[index0 + oneRowDown] === 0 && neighborsSignificance[index0 + twoRowsDown] === 0 && neighborsSignificance[index0 + threeRowsDown] === 0;
  17712. var i1 = 0, index = index0;
  17713. var i = i0, sign;
  17714. if (allEmpty) {
  17715. var hasSignificantCoefficent = decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  17716. if (!hasSignificantCoefficent) {
  17717. bitsDecoded[index0]++;
  17718. bitsDecoded[index0 + oneRowDown]++;
  17719. bitsDecoded[index0 + twoRowsDown]++;
  17720. bitsDecoded[index0 + threeRowsDown]++;
  17721. continue;
  17722. }
  17723. // next column
  17724. i1 = decoder.readBit(contexts, UNIFORM_CONTEXT) << 1 | decoder.readBit(contexts, UNIFORM_CONTEXT);
  17725. if (i1 !== 0) {
  17726. i = i0 + i1;
  17727. index += i1 * width;
  17728. }
  17729. sign = this.decodeSignBit(i, j, index);
  17730. coefficentsSign[index] = sign;
  17731. coefficentsMagnitude[index] = 1;
  17732. this.setNeighborsSignificance(i, j, index);
  17733. processingFlags[index] |= firstMagnitudeBitMask;
  17734. index = index0;
  17735. for (var i2 = i0; i2 <= i; i2++, index += width) {
  17736. bitsDecoded[index]++;
  17737. }
  17738. i1++;
  17739. }
  17740. for (i = i0 + i1; i < iNext; i++, index += width) {
  17741. if (coefficentsMagnitude[index] || (processingFlags[index] & processedMask) !== 0) {
  17742. continue;
  17743. }
  17744. var contextLabel = labels[neighborsSignificance[index]];
  17745. var decision = decoder.readBit(contexts, contextLabel);
  17746. if (decision === 1) {
  17747. sign = this.decodeSignBit(i, j, index);
  17748. coefficentsSign[index] = sign;
  17749. coefficentsMagnitude[index] = 1;
  17750. this.setNeighborsSignificance(i, j, index);
  17751. processingFlags[index] |= firstMagnitudeBitMask;
  17752. }
  17753. bitsDecoded[index]++;
  17754. }
  17755. }
  17756. }
  17757. },
  17758. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  17759. var decoder = this.decoder;
  17760. var contexts = this.contexts;
  17761. var symbol = decoder.readBit(contexts, UNIFORM_CONTEXT) << 3 | decoder.readBit(contexts, UNIFORM_CONTEXT) << 2 | decoder.readBit(contexts, UNIFORM_CONTEXT) << 1 | decoder.readBit(contexts, UNIFORM_CONTEXT);
  17762. if (symbol !== 0xA) {
  17763. error('JPX Error: Invalid segmentation symbol');
  17764. }
  17765. }
  17766. };
  17767. return BitModel;
  17768. }();
  17769. // Section F, Discrete wavelet transformation
  17770. var Transform = function TransformClosure() {
  17771. function Transform() {
  17772. }
  17773. Transform.prototype.calculate = function transformCalculate(subbands, u0, v0) {
  17774. var ll = subbands[0];
  17775. for (var i = 1, ii = subbands.length; i < ii; i++) {
  17776. ll = this.iterate(ll, subbands[i], u0, v0);
  17777. }
  17778. return ll;
  17779. };
  17780. Transform.prototype.extend = function extend(buffer, offset, size) {
  17781. // Section F.3.7 extending... using max extension of 4
  17782. var i1 = offset - 1, j1 = offset + 1;
  17783. var i2 = offset + size - 2, j2 = offset + size;
  17784. buffer[i1--] = buffer[j1++];
  17785. buffer[j2++] = buffer[i2--];
  17786. buffer[i1--] = buffer[j1++];
  17787. buffer[j2++] = buffer[i2--];
  17788. buffer[i1--] = buffer[j1++];
  17789. buffer[j2++] = buffer[i2--];
  17790. buffer[i1] = buffer[j1];
  17791. buffer[j2] = buffer[i2];
  17792. };
  17793. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh, u0, v0) {
  17794. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  17795. var width = hl_lh_hh.width;
  17796. var height = hl_lh_hh.height;
  17797. var items = hl_lh_hh.items;
  17798. var i, j, k, l, u, v;
  17799. // Interleave LL according to Section F.3.3
  17800. for (k = 0, i = 0; i < llHeight; i++) {
  17801. l = i * 2 * width;
  17802. for (j = 0; j < llWidth; j++, k++, l += 2) {
  17803. items[l] = llItems[k];
  17804. }
  17805. }
  17806. // The LL band is not needed anymore.
  17807. llItems = ll.items = null;
  17808. var bufferPadding = 4;
  17809. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  17810. // Section F.3.4 HOR_SR
  17811. if (width === 1) {
  17812. // if width = 1, when u0 even keep items as is, when odd divide by 2
  17813. if ((u0 & 1) !== 0) {
  17814. for (v = 0, k = 0; v < height; v++, k += width) {
  17815. items[k] *= 0.5;
  17816. }
  17817. }
  17818. } else {
  17819. for (v = 0, k = 0; v < height; v++, k += width) {
  17820. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  17821. this.extend(rowBuffer, bufferPadding, width);
  17822. this.filter(rowBuffer, bufferPadding, width);
  17823. items.set(rowBuffer.subarray(bufferPadding, bufferPadding + width), k);
  17824. }
  17825. }
  17826. // Accesses to the items array can take long, because it may not fit into
  17827. // CPU cache and has to be fetched from main memory. Since subsequent
  17828. // accesses to the items array are not local when reading columns, we
  17829. // have a cache miss every time. To reduce cache misses, get up to
  17830. // 'numBuffers' items at a time and store them into the individual
  17831. // buffers. The colBuffers should be small enough to fit into CPU cache.
  17832. var numBuffers = 16;
  17833. var colBuffers = [];
  17834. for (i = 0; i < numBuffers; i++) {
  17835. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  17836. }
  17837. var b, currentBuffer = 0;
  17838. ll = bufferPadding + height;
  17839. // Section F.3.5 VER_SR
  17840. if (height === 1) {
  17841. // if height = 1, when v0 even keep items as is, when odd divide by 2
  17842. if ((v0 & 1) !== 0) {
  17843. for (u = 0; u < width; u++) {
  17844. items[u] *= 0.5;
  17845. }
  17846. }
  17847. } else {
  17848. for (u = 0; u < width; u++) {
  17849. // if we ran out of buffers, copy several image columns at once
  17850. if (currentBuffer === 0) {
  17851. numBuffers = Math.min(width - u, numBuffers);
  17852. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  17853. for (b = 0; b < numBuffers; b++) {
  17854. colBuffers[b][l] = items[k + b];
  17855. }
  17856. }
  17857. currentBuffer = numBuffers;
  17858. }
  17859. currentBuffer--;
  17860. var buffer = colBuffers[currentBuffer];
  17861. this.extend(buffer, bufferPadding, height);
  17862. this.filter(buffer, bufferPadding, height);
  17863. // If this is last buffer in this group of buffers, flush all buffers.
  17864. if (currentBuffer === 0) {
  17865. k = u - numBuffers + 1;
  17866. for (l = bufferPadding; l < ll; k += width, l++) {
  17867. for (b = 0; b < numBuffers; b++) {
  17868. items[k + b] = colBuffers[b][l];
  17869. }
  17870. }
  17871. }
  17872. }
  17873. }
  17874. return {
  17875. width: width,
  17876. height: height,
  17877. items: items
  17878. };
  17879. };
  17880. return Transform;
  17881. }();
  17882. // Section 3.8.2 Irreversible 9-7 filter
  17883. var IrreversibleTransform = function IrreversibleTransformClosure() {
  17884. function IrreversibleTransform() {
  17885. Transform.call(this);
  17886. }
  17887. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  17888. IrreversibleTransform.prototype.filter = function irreversibleTransformFilter(x, offset, length) {
  17889. var len = length >> 1;
  17890. offset = offset | 0;
  17891. var j, n, current, next;
  17892. var alpha = -1.586134342059924;
  17893. var beta = -0.052980118572961;
  17894. var gamma = 0.882911075530934;
  17895. var delta = 0.443506852043971;
  17896. var K = 1.230174104914001;
  17897. var K_ = 1 / K;
  17898. // step 1 is combined with step 3
  17899. // step 2
  17900. j = offset - 3;
  17901. for (n = len + 4; n--; j += 2) {
  17902. x[j] *= K_;
  17903. }
  17904. // step 1 & 3
  17905. j = offset - 2;
  17906. current = delta * x[j - 1];
  17907. for (n = len + 3; n--; j += 2) {
  17908. next = delta * x[j + 1];
  17909. x[j] = K * x[j] - current - next;
  17910. if (n--) {
  17911. j += 2;
  17912. current = delta * x[j + 1];
  17913. x[j] = K * x[j] - current - next;
  17914. } else {
  17915. break;
  17916. }
  17917. }
  17918. // step 4
  17919. j = offset - 1;
  17920. current = gamma * x[j - 1];
  17921. for (n = len + 2; n--; j += 2) {
  17922. next = gamma * x[j + 1];
  17923. x[j] -= current + next;
  17924. if (n--) {
  17925. j += 2;
  17926. current = gamma * x[j + 1];
  17927. x[j] -= current + next;
  17928. } else {
  17929. break;
  17930. }
  17931. }
  17932. // step 5
  17933. j = offset;
  17934. current = beta * x[j - 1];
  17935. for (n = len + 1; n--; j += 2) {
  17936. next = beta * x[j + 1];
  17937. x[j] -= current + next;
  17938. if (n--) {
  17939. j += 2;
  17940. current = beta * x[j + 1];
  17941. x[j] -= current + next;
  17942. } else {
  17943. break;
  17944. }
  17945. }
  17946. // step 6
  17947. if (len !== 0) {
  17948. j = offset + 1;
  17949. current = alpha * x[j - 1];
  17950. for (n = len; n--; j += 2) {
  17951. next = alpha * x[j + 1];
  17952. x[j] -= current + next;
  17953. if (n--) {
  17954. j += 2;
  17955. current = alpha * x[j + 1];
  17956. x[j] -= current + next;
  17957. } else {
  17958. break;
  17959. }
  17960. }
  17961. }
  17962. };
  17963. return IrreversibleTransform;
  17964. }();
  17965. // Section 3.8.1 Reversible 5-3 filter
  17966. var ReversibleTransform = function ReversibleTransformClosure() {
  17967. function ReversibleTransform() {
  17968. Transform.call(this);
  17969. }
  17970. ReversibleTransform.prototype = Object.create(Transform.prototype);
  17971. ReversibleTransform.prototype.filter = function reversibleTransformFilter(x, offset, length) {
  17972. var len = length >> 1;
  17973. offset = offset | 0;
  17974. var j, n;
  17975. for (j = offset, n = len + 1; n--; j += 2) {
  17976. x[j] -= x[j - 1] + x[j + 1] + 2 >> 2;
  17977. }
  17978. for (j = offset + 1, n = len; n--; j += 2) {
  17979. x[j] += x[j - 1] + x[j + 1] >> 1;
  17980. }
  17981. };
  17982. return ReversibleTransform;
  17983. }();
  17984. return JpxImage;
  17985. }();
  17986. exports.JpxImage = JpxImage;
  17987. }));
  17988. (function (root, factory) {
  17989. factory(root.pdfjsCoreMetrics = {}, root.pdfjsSharedUtil);
  17990. }(this, function (exports, sharedUtil) {
  17991. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  17992. // The Metrics object contains glyph widths (in glyph space units).
  17993. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  17994. // space unit corresponds to 1/1000th of text space unit.
  17995. var getMetrics = getLookupTableFactory(function (t) {
  17996. t['Courier'] = 600;
  17997. t['Courier-Bold'] = 600;
  17998. t['Courier-BoldOblique'] = 600;
  17999. t['Courier-Oblique'] = 600;
  18000. t['Helvetica'] = getLookupTableFactory(function (t) {
  18001. t['space'] = 278;
  18002. t['exclam'] = 278;
  18003. t['quotedbl'] = 355;
  18004. t['numbersign'] = 556;
  18005. t['dollar'] = 556;
  18006. t['percent'] = 889;
  18007. t['ampersand'] = 667;
  18008. t['quoteright'] = 222;
  18009. t['parenleft'] = 333;
  18010. t['parenright'] = 333;
  18011. t['asterisk'] = 389;
  18012. t['plus'] = 584;
  18013. t['comma'] = 278;
  18014. t['hyphen'] = 333;
  18015. t['period'] = 278;
  18016. t['slash'] = 278;
  18017. t['zero'] = 556;
  18018. t['one'] = 556;
  18019. t['two'] = 556;
  18020. t['three'] = 556;
  18021. t['four'] = 556;
  18022. t['five'] = 556;
  18023. t['six'] = 556;
  18024. t['seven'] = 556;
  18025. t['eight'] = 556;
  18026. t['nine'] = 556;
  18027. t['colon'] = 278;
  18028. t['semicolon'] = 278;
  18029. t['less'] = 584;
  18030. t['equal'] = 584;
  18031. t['greater'] = 584;
  18032. t['question'] = 556;
  18033. t['at'] = 1015;
  18034. t['A'] = 667;
  18035. t['B'] = 667;
  18036. t['C'] = 722;
  18037. t['D'] = 722;
  18038. t['E'] = 667;
  18039. t['F'] = 611;
  18040. t['G'] = 778;
  18041. t['H'] = 722;
  18042. t['I'] = 278;
  18043. t['J'] = 500;
  18044. t['K'] = 667;
  18045. t['L'] = 556;
  18046. t['M'] = 833;
  18047. t['N'] = 722;
  18048. t['O'] = 778;
  18049. t['P'] = 667;
  18050. t['Q'] = 778;
  18051. t['R'] = 722;
  18052. t['S'] = 667;
  18053. t['T'] = 611;
  18054. t['U'] = 722;
  18055. t['V'] = 667;
  18056. t['W'] = 944;
  18057. t['X'] = 667;
  18058. t['Y'] = 667;
  18059. t['Z'] = 611;
  18060. t['bracketleft'] = 278;
  18061. t['backslash'] = 278;
  18062. t['bracketright'] = 278;
  18063. t['asciicircum'] = 469;
  18064. t['underscore'] = 556;
  18065. t['quoteleft'] = 222;
  18066. t['a'] = 556;
  18067. t['b'] = 556;
  18068. t['c'] = 500;
  18069. t['d'] = 556;
  18070. t['e'] = 556;
  18071. t['f'] = 278;
  18072. t['g'] = 556;
  18073. t['h'] = 556;
  18074. t['i'] = 222;
  18075. t['j'] = 222;
  18076. t['k'] = 500;
  18077. t['l'] = 222;
  18078. t['m'] = 833;
  18079. t['n'] = 556;
  18080. t['o'] = 556;
  18081. t['p'] = 556;
  18082. t['q'] = 556;
  18083. t['r'] = 333;
  18084. t['s'] = 500;
  18085. t['t'] = 278;
  18086. t['u'] = 556;
  18087. t['v'] = 500;
  18088. t['w'] = 722;
  18089. t['x'] = 500;
  18090. t['y'] = 500;
  18091. t['z'] = 500;
  18092. t['braceleft'] = 334;
  18093. t['bar'] = 260;
  18094. t['braceright'] = 334;
  18095. t['asciitilde'] = 584;
  18096. t['exclamdown'] = 333;
  18097. t['cent'] = 556;
  18098. t['sterling'] = 556;
  18099. t['fraction'] = 167;
  18100. t['yen'] = 556;
  18101. t['florin'] = 556;
  18102. t['section'] = 556;
  18103. t['currency'] = 556;
  18104. t['quotesingle'] = 191;
  18105. t['quotedblleft'] = 333;
  18106. t['guillemotleft'] = 556;
  18107. t['guilsinglleft'] = 333;
  18108. t['guilsinglright'] = 333;
  18109. t['fi'] = 500;
  18110. t['fl'] = 500;
  18111. t['endash'] = 556;
  18112. t['dagger'] = 556;
  18113. t['daggerdbl'] = 556;
  18114. t['periodcentered'] = 278;
  18115. t['paragraph'] = 537;
  18116. t['bullet'] = 350;
  18117. t['quotesinglbase'] = 222;
  18118. t['quotedblbase'] = 333;
  18119. t['quotedblright'] = 333;
  18120. t['guillemotright'] = 556;
  18121. t['ellipsis'] = 1000;
  18122. t['perthousand'] = 1000;
  18123. t['questiondown'] = 611;
  18124. t['grave'] = 333;
  18125. t['acute'] = 333;
  18126. t['circumflex'] = 333;
  18127. t['tilde'] = 333;
  18128. t['macron'] = 333;
  18129. t['breve'] = 333;
  18130. t['dotaccent'] = 333;
  18131. t['dieresis'] = 333;
  18132. t['ring'] = 333;
  18133. t['cedilla'] = 333;
  18134. t['hungarumlaut'] = 333;
  18135. t['ogonek'] = 333;
  18136. t['caron'] = 333;
  18137. t['emdash'] = 1000;
  18138. t['AE'] = 1000;
  18139. t['ordfeminine'] = 370;
  18140. t['Lslash'] = 556;
  18141. t['Oslash'] = 778;
  18142. t['OE'] = 1000;
  18143. t['ordmasculine'] = 365;
  18144. t['ae'] = 889;
  18145. t['dotlessi'] = 278;
  18146. t['lslash'] = 222;
  18147. t['oslash'] = 611;
  18148. t['oe'] = 944;
  18149. t['germandbls'] = 611;
  18150. t['Idieresis'] = 278;
  18151. t['eacute'] = 556;
  18152. t['abreve'] = 556;
  18153. t['uhungarumlaut'] = 556;
  18154. t['ecaron'] = 556;
  18155. t['Ydieresis'] = 667;
  18156. t['divide'] = 584;
  18157. t['Yacute'] = 667;
  18158. t['Acircumflex'] = 667;
  18159. t['aacute'] = 556;
  18160. t['Ucircumflex'] = 722;
  18161. t['yacute'] = 500;
  18162. t['scommaaccent'] = 500;
  18163. t['ecircumflex'] = 556;
  18164. t['Uring'] = 722;
  18165. t['Udieresis'] = 722;
  18166. t['aogonek'] = 556;
  18167. t['Uacute'] = 722;
  18168. t['uogonek'] = 556;
  18169. t['Edieresis'] = 667;
  18170. t['Dcroat'] = 722;
  18171. t['commaaccent'] = 250;
  18172. t['copyright'] = 737;
  18173. t['Emacron'] = 667;
  18174. t['ccaron'] = 500;
  18175. t['aring'] = 556;
  18176. t['Ncommaaccent'] = 722;
  18177. t['lacute'] = 222;
  18178. t['agrave'] = 556;
  18179. t['Tcommaaccent'] = 611;
  18180. t['Cacute'] = 722;
  18181. t['atilde'] = 556;
  18182. t['Edotaccent'] = 667;
  18183. t['scaron'] = 500;
  18184. t['scedilla'] = 500;
  18185. t['iacute'] = 278;
  18186. t['lozenge'] = 471;
  18187. t['Rcaron'] = 722;
  18188. t['Gcommaaccent'] = 778;
  18189. t['ucircumflex'] = 556;
  18190. t['acircumflex'] = 556;
  18191. t['Amacron'] = 667;
  18192. t['rcaron'] = 333;
  18193. t['ccedilla'] = 500;
  18194. t['Zdotaccent'] = 611;
  18195. t['Thorn'] = 667;
  18196. t['Omacron'] = 778;
  18197. t['Racute'] = 722;
  18198. t['Sacute'] = 667;
  18199. t['dcaron'] = 643;
  18200. t['Umacron'] = 722;
  18201. t['uring'] = 556;
  18202. t['threesuperior'] = 333;
  18203. t['Ograve'] = 778;
  18204. t['Agrave'] = 667;
  18205. t['Abreve'] = 667;
  18206. t['multiply'] = 584;
  18207. t['uacute'] = 556;
  18208. t['Tcaron'] = 611;
  18209. t['partialdiff'] = 476;
  18210. t['ydieresis'] = 500;
  18211. t['Nacute'] = 722;
  18212. t['icircumflex'] = 278;
  18213. t['Ecircumflex'] = 667;
  18214. t['adieresis'] = 556;
  18215. t['edieresis'] = 556;
  18216. t['cacute'] = 500;
  18217. t['nacute'] = 556;
  18218. t['umacron'] = 556;
  18219. t['Ncaron'] = 722;
  18220. t['Iacute'] = 278;
  18221. t['plusminus'] = 584;
  18222. t['brokenbar'] = 260;
  18223. t['registered'] = 737;
  18224. t['Gbreve'] = 778;
  18225. t['Idotaccent'] = 278;
  18226. t['summation'] = 600;
  18227. t['Egrave'] = 667;
  18228. t['racute'] = 333;
  18229. t['omacron'] = 556;
  18230. t['Zacute'] = 611;
  18231. t['Zcaron'] = 611;
  18232. t['greaterequal'] = 549;
  18233. t['Eth'] = 722;
  18234. t['Ccedilla'] = 722;
  18235. t['lcommaaccent'] = 222;
  18236. t['tcaron'] = 317;
  18237. t['eogonek'] = 556;
  18238. t['Uogonek'] = 722;
  18239. t['Aacute'] = 667;
  18240. t['Adieresis'] = 667;
  18241. t['egrave'] = 556;
  18242. t['zacute'] = 500;
  18243. t['iogonek'] = 222;
  18244. t['Oacute'] = 778;
  18245. t['oacute'] = 556;
  18246. t['amacron'] = 556;
  18247. t['sacute'] = 500;
  18248. t['idieresis'] = 278;
  18249. t['Ocircumflex'] = 778;
  18250. t['Ugrave'] = 722;
  18251. t['Delta'] = 612;
  18252. t['thorn'] = 556;
  18253. t['twosuperior'] = 333;
  18254. t['Odieresis'] = 778;
  18255. t['mu'] = 556;
  18256. t['igrave'] = 278;
  18257. t['ohungarumlaut'] = 556;
  18258. t['Eogonek'] = 667;
  18259. t['dcroat'] = 556;
  18260. t['threequarters'] = 834;
  18261. t['Scedilla'] = 667;
  18262. t['lcaron'] = 299;
  18263. t['Kcommaaccent'] = 667;
  18264. t['Lacute'] = 556;
  18265. t['trademark'] = 1000;
  18266. t['edotaccent'] = 556;
  18267. t['Igrave'] = 278;
  18268. t['Imacron'] = 278;
  18269. t['Lcaron'] = 556;
  18270. t['onehalf'] = 834;
  18271. t['lessequal'] = 549;
  18272. t['ocircumflex'] = 556;
  18273. t['ntilde'] = 556;
  18274. t['Uhungarumlaut'] = 722;
  18275. t['Eacute'] = 667;
  18276. t['emacron'] = 556;
  18277. t['gbreve'] = 556;
  18278. t['onequarter'] = 834;
  18279. t['Scaron'] = 667;
  18280. t['Scommaaccent'] = 667;
  18281. t['Ohungarumlaut'] = 778;
  18282. t['degree'] = 400;
  18283. t['ograve'] = 556;
  18284. t['Ccaron'] = 722;
  18285. t['ugrave'] = 556;
  18286. t['radical'] = 453;
  18287. t['Dcaron'] = 722;
  18288. t['rcommaaccent'] = 333;
  18289. t['Ntilde'] = 722;
  18290. t['otilde'] = 556;
  18291. t['Rcommaaccent'] = 722;
  18292. t['Lcommaaccent'] = 556;
  18293. t['Atilde'] = 667;
  18294. t['Aogonek'] = 667;
  18295. t['Aring'] = 667;
  18296. t['Otilde'] = 778;
  18297. t['zdotaccent'] = 500;
  18298. t['Ecaron'] = 667;
  18299. t['Iogonek'] = 278;
  18300. t['kcommaaccent'] = 500;
  18301. t['minus'] = 584;
  18302. t['Icircumflex'] = 278;
  18303. t['ncaron'] = 556;
  18304. t['tcommaaccent'] = 278;
  18305. t['logicalnot'] = 584;
  18306. t['odieresis'] = 556;
  18307. t['udieresis'] = 556;
  18308. t['notequal'] = 549;
  18309. t['gcommaaccent'] = 556;
  18310. t['eth'] = 556;
  18311. t['zcaron'] = 500;
  18312. t['ncommaaccent'] = 556;
  18313. t['onesuperior'] = 333;
  18314. t['imacron'] = 278;
  18315. t['Euro'] = 556;
  18316. });
  18317. t['Helvetica-Bold'] = getLookupTableFactory(function (t) {
  18318. t['space'] = 278;
  18319. t['exclam'] = 333;
  18320. t['quotedbl'] = 474;
  18321. t['numbersign'] = 556;
  18322. t['dollar'] = 556;
  18323. t['percent'] = 889;
  18324. t['ampersand'] = 722;
  18325. t['quoteright'] = 278;
  18326. t['parenleft'] = 333;
  18327. t['parenright'] = 333;
  18328. t['asterisk'] = 389;
  18329. t['plus'] = 584;
  18330. t['comma'] = 278;
  18331. t['hyphen'] = 333;
  18332. t['period'] = 278;
  18333. t['slash'] = 278;
  18334. t['zero'] = 556;
  18335. t['one'] = 556;
  18336. t['two'] = 556;
  18337. t['three'] = 556;
  18338. t['four'] = 556;
  18339. t['five'] = 556;
  18340. t['six'] = 556;
  18341. t['seven'] = 556;
  18342. t['eight'] = 556;
  18343. t['nine'] = 556;
  18344. t['colon'] = 333;
  18345. t['semicolon'] = 333;
  18346. t['less'] = 584;
  18347. t['equal'] = 584;
  18348. t['greater'] = 584;
  18349. t['question'] = 611;
  18350. t['at'] = 975;
  18351. t['A'] = 722;
  18352. t['B'] = 722;
  18353. t['C'] = 722;
  18354. t['D'] = 722;
  18355. t['E'] = 667;
  18356. t['F'] = 611;
  18357. t['G'] = 778;
  18358. t['H'] = 722;
  18359. t['I'] = 278;
  18360. t['J'] = 556;
  18361. t['K'] = 722;
  18362. t['L'] = 611;
  18363. t['M'] = 833;
  18364. t['N'] = 722;
  18365. t['O'] = 778;
  18366. t['P'] = 667;
  18367. t['Q'] = 778;
  18368. t['R'] = 722;
  18369. t['S'] = 667;
  18370. t['T'] = 611;
  18371. t['U'] = 722;
  18372. t['V'] = 667;
  18373. t['W'] = 944;
  18374. t['X'] = 667;
  18375. t['Y'] = 667;
  18376. t['Z'] = 611;
  18377. t['bracketleft'] = 333;
  18378. t['backslash'] = 278;
  18379. t['bracketright'] = 333;
  18380. t['asciicircum'] = 584;
  18381. t['underscore'] = 556;
  18382. t['quoteleft'] = 278;
  18383. t['a'] = 556;
  18384. t['b'] = 611;
  18385. t['c'] = 556;
  18386. t['d'] = 611;
  18387. t['e'] = 556;
  18388. t['f'] = 333;
  18389. t['g'] = 611;
  18390. t['h'] = 611;
  18391. t['i'] = 278;
  18392. t['j'] = 278;
  18393. t['k'] = 556;
  18394. t['l'] = 278;
  18395. t['m'] = 889;
  18396. t['n'] = 611;
  18397. t['o'] = 611;
  18398. t['p'] = 611;
  18399. t['q'] = 611;
  18400. t['r'] = 389;
  18401. t['s'] = 556;
  18402. t['t'] = 333;
  18403. t['u'] = 611;
  18404. t['v'] = 556;
  18405. t['w'] = 778;
  18406. t['x'] = 556;
  18407. t['y'] = 556;
  18408. t['z'] = 500;
  18409. t['braceleft'] = 389;
  18410. t['bar'] = 280;
  18411. t['braceright'] = 389;
  18412. t['asciitilde'] = 584;
  18413. t['exclamdown'] = 333;
  18414. t['cent'] = 556;
  18415. t['sterling'] = 556;
  18416. t['fraction'] = 167;
  18417. t['yen'] = 556;
  18418. t['florin'] = 556;
  18419. t['section'] = 556;
  18420. t['currency'] = 556;
  18421. t['quotesingle'] = 238;
  18422. t['quotedblleft'] = 500;
  18423. t['guillemotleft'] = 556;
  18424. t['guilsinglleft'] = 333;
  18425. t['guilsinglright'] = 333;
  18426. t['fi'] = 611;
  18427. t['fl'] = 611;
  18428. t['endash'] = 556;
  18429. t['dagger'] = 556;
  18430. t['daggerdbl'] = 556;
  18431. t['periodcentered'] = 278;
  18432. t['paragraph'] = 556;
  18433. t['bullet'] = 350;
  18434. t['quotesinglbase'] = 278;
  18435. t['quotedblbase'] = 500;
  18436. t['quotedblright'] = 500;
  18437. t['guillemotright'] = 556;
  18438. t['ellipsis'] = 1000;
  18439. t['perthousand'] = 1000;
  18440. t['questiondown'] = 611;
  18441. t['grave'] = 333;
  18442. t['acute'] = 333;
  18443. t['circumflex'] = 333;
  18444. t['tilde'] = 333;
  18445. t['macron'] = 333;
  18446. t['breve'] = 333;
  18447. t['dotaccent'] = 333;
  18448. t['dieresis'] = 333;
  18449. t['ring'] = 333;
  18450. t['cedilla'] = 333;
  18451. t['hungarumlaut'] = 333;
  18452. t['ogonek'] = 333;
  18453. t['caron'] = 333;
  18454. t['emdash'] = 1000;
  18455. t['AE'] = 1000;
  18456. t['ordfeminine'] = 370;
  18457. t['Lslash'] = 611;
  18458. t['Oslash'] = 778;
  18459. t['OE'] = 1000;
  18460. t['ordmasculine'] = 365;
  18461. t['ae'] = 889;
  18462. t['dotlessi'] = 278;
  18463. t['lslash'] = 278;
  18464. t['oslash'] = 611;
  18465. t['oe'] = 944;
  18466. t['germandbls'] = 611;
  18467. t['Idieresis'] = 278;
  18468. t['eacute'] = 556;
  18469. t['abreve'] = 556;
  18470. t['uhungarumlaut'] = 611;
  18471. t['ecaron'] = 556;
  18472. t['Ydieresis'] = 667;
  18473. t['divide'] = 584;
  18474. t['Yacute'] = 667;
  18475. t['Acircumflex'] = 722;
  18476. t['aacute'] = 556;
  18477. t['Ucircumflex'] = 722;
  18478. t['yacute'] = 556;
  18479. t['scommaaccent'] = 556;
  18480. t['ecircumflex'] = 556;
  18481. t['Uring'] = 722;
  18482. t['Udieresis'] = 722;
  18483. t['aogonek'] = 556;
  18484. t['Uacute'] = 722;
  18485. t['uogonek'] = 611;
  18486. t['Edieresis'] = 667;
  18487. t['Dcroat'] = 722;
  18488. t['commaaccent'] = 250;
  18489. t['copyright'] = 737;
  18490. t['Emacron'] = 667;
  18491. t['ccaron'] = 556;
  18492. t['aring'] = 556;
  18493. t['Ncommaaccent'] = 722;
  18494. t['lacute'] = 278;
  18495. t['agrave'] = 556;
  18496. t['Tcommaaccent'] = 611;
  18497. t['Cacute'] = 722;
  18498. t['atilde'] = 556;
  18499. t['Edotaccent'] = 667;
  18500. t['scaron'] = 556;
  18501. t['scedilla'] = 556;
  18502. t['iacute'] = 278;
  18503. t['lozenge'] = 494;
  18504. t['Rcaron'] = 722;
  18505. t['Gcommaaccent'] = 778;
  18506. t['ucircumflex'] = 611;
  18507. t['acircumflex'] = 556;
  18508. t['Amacron'] = 722;
  18509. t['rcaron'] = 389;
  18510. t['ccedilla'] = 556;
  18511. t['Zdotaccent'] = 611;
  18512. t['Thorn'] = 667;
  18513. t['Omacron'] = 778;
  18514. t['Racute'] = 722;
  18515. t['Sacute'] = 667;
  18516. t['dcaron'] = 743;
  18517. t['Umacron'] = 722;
  18518. t['uring'] = 611;
  18519. t['threesuperior'] = 333;
  18520. t['Ograve'] = 778;
  18521. t['Agrave'] = 722;
  18522. t['Abreve'] = 722;
  18523. t['multiply'] = 584;
  18524. t['uacute'] = 611;
  18525. t['Tcaron'] = 611;
  18526. t['partialdiff'] = 494;
  18527. t['ydieresis'] = 556;
  18528. t['Nacute'] = 722;
  18529. t['icircumflex'] = 278;
  18530. t['Ecircumflex'] = 667;
  18531. t['adieresis'] = 556;
  18532. t['edieresis'] = 556;
  18533. t['cacute'] = 556;
  18534. t['nacute'] = 611;
  18535. t['umacron'] = 611;
  18536. t['Ncaron'] = 722;
  18537. t['Iacute'] = 278;
  18538. t['plusminus'] = 584;
  18539. t['brokenbar'] = 280;
  18540. t['registered'] = 737;
  18541. t['Gbreve'] = 778;
  18542. t['Idotaccent'] = 278;
  18543. t['summation'] = 600;
  18544. t['Egrave'] = 667;
  18545. t['racute'] = 389;
  18546. t['omacron'] = 611;
  18547. t['Zacute'] = 611;
  18548. t['Zcaron'] = 611;
  18549. t['greaterequal'] = 549;
  18550. t['Eth'] = 722;
  18551. t['Ccedilla'] = 722;
  18552. t['lcommaaccent'] = 278;
  18553. t['tcaron'] = 389;
  18554. t['eogonek'] = 556;
  18555. t['Uogonek'] = 722;
  18556. t['Aacute'] = 722;
  18557. t['Adieresis'] = 722;
  18558. t['egrave'] = 556;
  18559. t['zacute'] = 500;
  18560. t['iogonek'] = 278;
  18561. t['Oacute'] = 778;
  18562. t['oacute'] = 611;
  18563. t['amacron'] = 556;
  18564. t['sacute'] = 556;
  18565. t['idieresis'] = 278;
  18566. t['Ocircumflex'] = 778;
  18567. t['Ugrave'] = 722;
  18568. t['Delta'] = 612;
  18569. t['thorn'] = 611;
  18570. t['twosuperior'] = 333;
  18571. t['Odieresis'] = 778;
  18572. t['mu'] = 611;
  18573. t['igrave'] = 278;
  18574. t['ohungarumlaut'] = 611;
  18575. t['Eogonek'] = 667;
  18576. t['dcroat'] = 611;
  18577. t['threequarters'] = 834;
  18578. t['Scedilla'] = 667;
  18579. t['lcaron'] = 400;
  18580. t['Kcommaaccent'] = 722;
  18581. t['Lacute'] = 611;
  18582. t['trademark'] = 1000;
  18583. t['edotaccent'] = 556;
  18584. t['Igrave'] = 278;
  18585. t['Imacron'] = 278;
  18586. t['Lcaron'] = 611;
  18587. t['onehalf'] = 834;
  18588. t['lessequal'] = 549;
  18589. t['ocircumflex'] = 611;
  18590. t['ntilde'] = 611;
  18591. t['Uhungarumlaut'] = 722;
  18592. t['Eacute'] = 667;
  18593. t['emacron'] = 556;
  18594. t['gbreve'] = 611;
  18595. t['onequarter'] = 834;
  18596. t['Scaron'] = 667;
  18597. t['Scommaaccent'] = 667;
  18598. t['Ohungarumlaut'] = 778;
  18599. t['degree'] = 400;
  18600. t['ograve'] = 611;
  18601. t['Ccaron'] = 722;
  18602. t['ugrave'] = 611;
  18603. t['radical'] = 549;
  18604. t['Dcaron'] = 722;
  18605. t['rcommaaccent'] = 389;
  18606. t['Ntilde'] = 722;
  18607. t['otilde'] = 611;
  18608. t['Rcommaaccent'] = 722;
  18609. t['Lcommaaccent'] = 611;
  18610. t['Atilde'] = 722;
  18611. t['Aogonek'] = 722;
  18612. t['Aring'] = 722;
  18613. t['Otilde'] = 778;
  18614. t['zdotaccent'] = 500;
  18615. t['Ecaron'] = 667;
  18616. t['Iogonek'] = 278;
  18617. t['kcommaaccent'] = 556;
  18618. t['minus'] = 584;
  18619. t['Icircumflex'] = 278;
  18620. t['ncaron'] = 611;
  18621. t['tcommaaccent'] = 333;
  18622. t['logicalnot'] = 584;
  18623. t['odieresis'] = 611;
  18624. t['udieresis'] = 611;
  18625. t['notequal'] = 549;
  18626. t['gcommaaccent'] = 611;
  18627. t['eth'] = 611;
  18628. t['zcaron'] = 500;
  18629. t['ncommaaccent'] = 611;
  18630. t['onesuperior'] = 333;
  18631. t['imacron'] = 278;
  18632. t['Euro'] = 556;
  18633. });
  18634. t['Helvetica-BoldOblique'] = getLookupTableFactory(function (t) {
  18635. t['space'] = 278;
  18636. t['exclam'] = 333;
  18637. t['quotedbl'] = 474;
  18638. t['numbersign'] = 556;
  18639. t['dollar'] = 556;
  18640. t['percent'] = 889;
  18641. t['ampersand'] = 722;
  18642. t['quoteright'] = 278;
  18643. t['parenleft'] = 333;
  18644. t['parenright'] = 333;
  18645. t['asterisk'] = 389;
  18646. t['plus'] = 584;
  18647. t['comma'] = 278;
  18648. t['hyphen'] = 333;
  18649. t['period'] = 278;
  18650. t['slash'] = 278;
  18651. t['zero'] = 556;
  18652. t['one'] = 556;
  18653. t['two'] = 556;
  18654. t['three'] = 556;
  18655. t['four'] = 556;
  18656. t['five'] = 556;
  18657. t['six'] = 556;
  18658. t['seven'] = 556;
  18659. t['eight'] = 556;
  18660. t['nine'] = 556;
  18661. t['colon'] = 333;
  18662. t['semicolon'] = 333;
  18663. t['less'] = 584;
  18664. t['equal'] = 584;
  18665. t['greater'] = 584;
  18666. t['question'] = 611;
  18667. t['at'] = 975;
  18668. t['A'] = 722;
  18669. t['B'] = 722;
  18670. t['C'] = 722;
  18671. t['D'] = 722;
  18672. t['E'] = 667;
  18673. t['F'] = 611;
  18674. t['G'] = 778;
  18675. t['H'] = 722;
  18676. t['I'] = 278;
  18677. t['J'] = 556;
  18678. t['K'] = 722;
  18679. t['L'] = 611;
  18680. t['M'] = 833;
  18681. t['N'] = 722;
  18682. t['O'] = 778;
  18683. t['P'] = 667;
  18684. t['Q'] = 778;
  18685. t['R'] = 722;
  18686. t['S'] = 667;
  18687. t['T'] = 611;
  18688. t['U'] = 722;
  18689. t['V'] = 667;
  18690. t['W'] = 944;
  18691. t['X'] = 667;
  18692. t['Y'] = 667;
  18693. t['Z'] = 611;
  18694. t['bracketleft'] = 333;
  18695. t['backslash'] = 278;
  18696. t['bracketright'] = 333;
  18697. t['asciicircum'] = 584;
  18698. t['underscore'] = 556;
  18699. t['quoteleft'] = 278;
  18700. t['a'] = 556;
  18701. t['b'] = 611;
  18702. t['c'] = 556;
  18703. t['d'] = 611;
  18704. t['e'] = 556;
  18705. t['f'] = 333;
  18706. t['g'] = 611;
  18707. t['h'] = 611;
  18708. t['i'] = 278;
  18709. t['j'] = 278;
  18710. t['k'] = 556;
  18711. t['l'] = 278;
  18712. t['m'] = 889;
  18713. t['n'] = 611;
  18714. t['o'] = 611;
  18715. t['p'] = 611;
  18716. t['q'] = 611;
  18717. t['r'] = 389;
  18718. t['s'] = 556;
  18719. t['t'] = 333;
  18720. t['u'] = 611;
  18721. t['v'] = 556;
  18722. t['w'] = 778;
  18723. t['x'] = 556;
  18724. t['y'] = 556;
  18725. t['z'] = 500;
  18726. t['braceleft'] = 389;
  18727. t['bar'] = 280;
  18728. t['braceright'] = 389;
  18729. t['asciitilde'] = 584;
  18730. t['exclamdown'] = 333;
  18731. t['cent'] = 556;
  18732. t['sterling'] = 556;
  18733. t['fraction'] = 167;
  18734. t['yen'] = 556;
  18735. t['florin'] = 556;
  18736. t['section'] = 556;
  18737. t['currency'] = 556;
  18738. t['quotesingle'] = 238;
  18739. t['quotedblleft'] = 500;
  18740. t['guillemotleft'] = 556;
  18741. t['guilsinglleft'] = 333;
  18742. t['guilsinglright'] = 333;
  18743. t['fi'] = 611;
  18744. t['fl'] = 611;
  18745. t['endash'] = 556;
  18746. t['dagger'] = 556;
  18747. t['daggerdbl'] = 556;
  18748. t['periodcentered'] = 278;
  18749. t['paragraph'] = 556;
  18750. t['bullet'] = 350;
  18751. t['quotesinglbase'] = 278;
  18752. t['quotedblbase'] = 500;
  18753. t['quotedblright'] = 500;
  18754. t['guillemotright'] = 556;
  18755. t['ellipsis'] = 1000;
  18756. t['perthousand'] = 1000;
  18757. t['questiondown'] = 611;
  18758. t['grave'] = 333;
  18759. t['acute'] = 333;
  18760. t['circumflex'] = 333;
  18761. t['tilde'] = 333;
  18762. t['macron'] = 333;
  18763. t['breve'] = 333;
  18764. t['dotaccent'] = 333;
  18765. t['dieresis'] = 333;
  18766. t['ring'] = 333;
  18767. t['cedilla'] = 333;
  18768. t['hungarumlaut'] = 333;
  18769. t['ogonek'] = 333;
  18770. t['caron'] = 333;
  18771. t['emdash'] = 1000;
  18772. t['AE'] = 1000;
  18773. t['ordfeminine'] = 370;
  18774. t['Lslash'] = 611;
  18775. t['Oslash'] = 778;
  18776. t['OE'] = 1000;
  18777. t['ordmasculine'] = 365;
  18778. t['ae'] = 889;
  18779. t['dotlessi'] = 278;
  18780. t['lslash'] = 278;
  18781. t['oslash'] = 611;
  18782. t['oe'] = 944;
  18783. t['germandbls'] = 611;
  18784. t['Idieresis'] = 278;
  18785. t['eacute'] = 556;
  18786. t['abreve'] = 556;
  18787. t['uhungarumlaut'] = 611;
  18788. t['ecaron'] = 556;
  18789. t['Ydieresis'] = 667;
  18790. t['divide'] = 584;
  18791. t['Yacute'] = 667;
  18792. t['Acircumflex'] = 722;
  18793. t['aacute'] = 556;
  18794. t['Ucircumflex'] = 722;
  18795. t['yacute'] = 556;
  18796. t['scommaaccent'] = 556;
  18797. t['ecircumflex'] = 556;
  18798. t['Uring'] = 722;
  18799. t['Udieresis'] = 722;
  18800. t['aogonek'] = 556;
  18801. t['Uacute'] = 722;
  18802. t['uogonek'] = 611;
  18803. t['Edieresis'] = 667;
  18804. t['Dcroat'] = 722;
  18805. t['commaaccent'] = 250;
  18806. t['copyright'] = 737;
  18807. t['Emacron'] = 667;
  18808. t['ccaron'] = 556;
  18809. t['aring'] = 556;
  18810. t['Ncommaaccent'] = 722;
  18811. t['lacute'] = 278;
  18812. t['agrave'] = 556;
  18813. t['Tcommaaccent'] = 611;
  18814. t['Cacute'] = 722;
  18815. t['atilde'] = 556;
  18816. t['Edotaccent'] = 667;
  18817. t['scaron'] = 556;
  18818. t['scedilla'] = 556;
  18819. t['iacute'] = 278;
  18820. t['lozenge'] = 494;
  18821. t['Rcaron'] = 722;
  18822. t['Gcommaaccent'] = 778;
  18823. t['ucircumflex'] = 611;
  18824. t['acircumflex'] = 556;
  18825. t['Amacron'] = 722;
  18826. t['rcaron'] = 389;
  18827. t['ccedilla'] = 556;
  18828. t['Zdotaccent'] = 611;
  18829. t['Thorn'] = 667;
  18830. t['Omacron'] = 778;
  18831. t['Racute'] = 722;
  18832. t['Sacute'] = 667;
  18833. t['dcaron'] = 743;
  18834. t['Umacron'] = 722;
  18835. t['uring'] = 611;
  18836. t['threesuperior'] = 333;
  18837. t['Ograve'] = 778;
  18838. t['Agrave'] = 722;
  18839. t['Abreve'] = 722;
  18840. t['multiply'] = 584;
  18841. t['uacute'] = 611;
  18842. t['Tcaron'] = 611;
  18843. t['partialdiff'] = 494;
  18844. t['ydieresis'] = 556;
  18845. t['Nacute'] = 722;
  18846. t['icircumflex'] = 278;
  18847. t['Ecircumflex'] = 667;
  18848. t['adieresis'] = 556;
  18849. t['edieresis'] = 556;
  18850. t['cacute'] = 556;
  18851. t['nacute'] = 611;
  18852. t['umacron'] = 611;
  18853. t['Ncaron'] = 722;
  18854. t['Iacute'] = 278;
  18855. t['plusminus'] = 584;
  18856. t['brokenbar'] = 280;
  18857. t['registered'] = 737;
  18858. t['Gbreve'] = 778;
  18859. t['Idotaccent'] = 278;
  18860. t['summation'] = 600;
  18861. t['Egrave'] = 667;
  18862. t['racute'] = 389;
  18863. t['omacron'] = 611;
  18864. t['Zacute'] = 611;
  18865. t['Zcaron'] = 611;
  18866. t['greaterequal'] = 549;
  18867. t['Eth'] = 722;
  18868. t['Ccedilla'] = 722;
  18869. t['lcommaaccent'] = 278;
  18870. t['tcaron'] = 389;
  18871. t['eogonek'] = 556;
  18872. t['Uogonek'] = 722;
  18873. t['Aacute'] = 722;
  18874. t['Adieresis'] = 722;
  18875. t['egrave'] = 556;
  18876. t['zacute'] = 500;
  18877. t['iogonek'] = 278;
  18878. t['Oacute'] = 778;
  18879. t['oacute'] = 611;
  18880. t['amacron'] = 556;
  18881. t['sacute'] = 556;
  18882. t['idieresis'] = 278;
  18883. t['Ocircumflex'] = 778;
  18884. t['Ugrave'] = 722;
  18885. t['Delta'] = 612;
  18886. t['thorn'] = 611;
  18887. t['twosuperior'] = 333;
  18888. t['Odieresis'] = 778;
  18889. t['mu'] = 611;
  18890. t['igrave'] = 278;
  18891. t['ohungarumlaut'] = 611;
  18892. t['Eogonek'] = 667;
  18893. t['dcroat'] = 611;
  18894. t['threequarters'] = 834;
  18895. t['Scedilla'] = 667;
  18896. t['lcaron'] = 400;
  18897. t['Kcommaaccent'] = 722;
  18898. t['Lacute'] = 611;
  18899. t['trademark'] = 1000;
  18900. t['edotaccent'] = 556;
  18901. t['Igrave'] = 278;
  18902. t['Imacron'] = 278;
  18903. t['Lcaron'] = 611;
  18904. t['onehalf'] = 834;
  18905. t['lessequal'] = 549;
  18906. t['ocircumflex'] = 611;
  18907. t['ntilde'] = 611;
  18908. t['Uhungarumlaut'] = 722;
  18909. t['Eacute'] = 667;
  18910. t['emacron'] = 556;
  18911. t['gbreve'] = 611;
  18912. t['onequarter'] = 834;
  18913. t['Scaron'] = 667;
  18914. t['Scommaaccent'] = 667;
  18915. t['Ohungarumlaut'] = 778;
  18916. t['degree'] = 400;
  18917. t['ograve'] = 611;
  18918. t['Ccaron'] = 722;
  18919. t['ugrave'] = 611;
  18920. t['radical'] = 549;
  18921. t['Dcaron'] = 722;
  18922. t['rcommaaccent'] = 389;
  18923. t['Ntilde'] = 722;
  18924. t['otilde'] = 611;
  18925. t['Rcommaaccent'] = 722;
  18926. t['Lcommaaccent'] = 611;
  18927. t['Atilde'] = 722;
  18928. t['Aogonek'] = 722;
  18929. t['Aring'] = 722;
  18930. t['Otilde'] = 778;
  18931. t['zdotaccent'] = 500;
  18932. t['Ecaron'] = 667;
  18933. t['Iogonek'] = 278;
  18934. t['kcommaaccent'] = 556;
  18935. t['minus'] = 584;
  18936. t['Icircumflex'] = 278;
  18937. t['ncaron'] = 611;
  18938. t['tcommaaccent'] = 333;
  18939. t['logicalnot'] = 584;
  18940. t['odieresis'] = 611;
  18941. t['udieresis'] = 611;
  18942. t['notequal'] = 549;
  18943. t['gcommaaccent'] = 611;
  18944. t['eth'] = 611;
  18945. t['zcaron'] = 500;
  18946. t['ncommaaccent'] = 611;
  18947. t['onesuperior'] = 333;
  18948. t['imacron'] = 278;
  18949. t['Euro'] = 556;
  18950. });
  18951. t['Helvetica-Oblique'] = getLookupTableFactory(function (t) {
  18952. t['space'] = 278;
  18953. t['exclam'] = 278;
  18954. t['quotedbl'] = 355;
  18955. t['numbersign'] = 556;
  18956. t['dollar'] = 556;
  18957. t['percent'] = 889;
  18958. t['ampersand'] = 667;
  18959. t['quoteright'] = 222;
  18960. t['parenleft'] = 333;
  18961. t['parenright'] = 333;
  18962. t['asterisk'] = 389;
  18963. t['plus'] = 584;
  18964. t['comma'] = 278;
  18965. t['hyphen'] = 333;
  18966. t['period'] = 278;
  18967. t['slash'] = 278;
  18968. t['zero'] = 556;
  18969. t['one'] = 556;
  18970. t['two'] = 556;
  18971. t['three'] = 556;
  18972. t['four'] = 556;
  18973. t['five'] = 556;
  18974. t['six'] = 556;
  18975. t['seven'] = 556;
  18976. t['eight'] = 556;
  18977. t['nine'] = 556;
  18978. t['colon'] = 278;
  18979. t['semicolon'] = 278;
  18980. t['less'] = 584;
  18981. t['equal'] = 584;
  18982. t['greater'] = 584;
  18983. t['question'] = 556;
  18984. t['at'] = 1015;
  18985. t['A'] = 667;
  18986. t['B'] = 667;
  18987. t['C'] = 722;
  18988. t['D'] = 722;
  18989. t['E'] = 667;
  18990. t['F'] = 611;
  18991. t['G'] = 778;
  18992. t['H'] = 722;
  18993. t['I'] = 278;
  18994. t['J'] = 500;
  18995. t['K'] = 667;
  18996. t['L'] = 556;
  18997. t['M'] = 833;
  18998. t['N'] = 722;
  18999. t['O'] = 778;
  19000. t['P'] = 667;
  19001. t['Q'] = 778;
  19002. t['R'] = 722;
  19003. t['S'] = 667;
  19004. t['T'] = 611;
  19005. t['U'] = 722;
  19006. t['V'] = 667;
  19007. t['W'] = 944;
  19008. t['X'] = 667;
  19009. t['Y'] = 667;
  19010. t['Z'] = 611;
  19011. t['bracketleft'] = 278;
  19012. t['backslash'] = 278;
  19013. t['bracketright'] = 278;
  19014. t['asciicircum'] = 469;
  19015. t['underscore'] = 556;
  19016. t['quoteleft'] = 222;
  19017. t['a'] = 556;
  19018. t['b'] = 556;
  19019. t['c'] = 500;
  19020. t['d'] = 556;
  19021. t['e'] = 556;
  19022. t['f'] = 278;
  19023. t['g'] = 556;
  19024. t['h'] = 556;
  19025. t['i'] = 222;
  19026. t['j'] = 222;
  19027. t['k'] = 500;
  19028. t['l'] = 222;
  19029. t['m'] = 833;
  19030. t['n'] = 556;
  19031. t['o'] = 556;
  19032. t['p'] = 556;
  19033. t['q'] = 556;
  19034. t['r'] = 333;
  19035. t['s'] = 500;
  19036. t['t'] = 278;
  19037. t['u'] = 556;
  19038. t['v'] = 500;
  19039. t['w'] = 722;
  19040. t['x'] = 500;
  19041. t['y'] = 500;
  19042. t['z'] = 500;
  19043. t['braceleft'] = 334;
  19044. t['bar'] = 260;
  19045. t['braceright'] = 334;
  19046. t['asciitilde'] = 584;
  19047. t['exclamdown'] = 333;
  19048. t['cent'] = 556;
  19049. t['sterling'] = 556;
  19050. t['fraction'] = 167;
  19051. t['yen'] = 556;
  19052. t['florin'] = 556;
  19053. t['section'] = 556;
  19054. t['currency'] = 556;
  19055. t['quotesingle'] = 191;
  19056. t['quotedblleft'] = 333;
  19057. t['guillemotleft'] = 556;
  19058. t['guilsinglleft'] = 333;
  19059. t['guilsinglright'] = 333;
  19060. t['fi'] = 500;
  19061. t['fl'] = 500;
  19062. t['endash'] = 556;
  19063. t['dagger'] = 556;
  19064. t['daggerdbl'] = 556;
  19065. t['periodcentered'] = 278;
  19066. t['paragraph'] = 537;
  19067. t['bullet'] = 350;
  19068. t['quotesinglbase'] = 222;
  19069. t['quotedblbase'] = 333;
  19070. t['quotedblright'] = 333;
  19071. t['guillemotright'] = 556;
  19072. t['ellipsis'] = 1000;
  19073. t['perthousand'] = 1000;
  19074. t['questiondown'] = 611;
  19075. t['grave'] = 333;
  19076. t['acute'] = 333;
  19077. t['circumflex'] = 333;
  19078. t['tilde'] = 333;
  19079. t['macron'] = 333;
  19080. t['breve'] = 333;
  19081. t['dotaccent'] = 333;
  19082. t['dieresis'] = 333;
  19083. t['ring'] = 333;
  19084. t['cedilla'] = 333;
  19085. t['hungarumlaut'] = 333;
  19086. t['ogonek'] = 333;
  19087. t['caron'] = 333;
  19088. t['emdash'] = 1000;
  19089. t['AE'] = 1000;
  19090. t['ordfeminine'] = 370;
  19091. t['Lslash'] = 556;
  19092. t['Oslash'] = 778;
  19093. t['OE'] = 1000;
  19094. t['ordmasculine'] = 365;
  19095. t['ae'] = 889;
  19096. t['dotlessi'] = 278;
  19097. t['lslash'] = 222;
  19098. t['oslash'] = 611;
  19099. t['oe'] = 944;
  19100. t['germandbls'] = 611;
  19101. t['Idieresis'] = 278;
  19102. t['eacute'] = 556;
  19103. t['abreve'] = 556;
  19104. t['uhungarumlaut'] = 556;
  19105. t['ecaron'] = 556;
  19106. t['Ydieresis'] = 667;
  19107. t['divide'] = 584;
  19108. t['Yacute'] = 667;
  19109. t['Acircumflex'] = 667;
  19110. t['aacute'] = 556;
  19111. t['Ucircumflex'] = 722;
  19112. t['yacute'] = 500;
  19113. t['scommaaccent'] = 500;
  19114. t['ecircumflex'] = 556;
  19115. t['Uring'] = 722;
  19116. t['Udieresis'] = 722;
  19117. t['aogonek'] = 556;
  19118. t['Uacute'] = 722;
  19119. t['uogonek'] = 556;
  19120. t['Edieresis'] = 667;
  19121. t['Dcroat'] = 722;
  19122. t['commaaccent'] = 250;
  19123. t['copyright'] = 737;
  19124. t['Emacron'] = 667;
  19125. t['ccaron'] = 500;
  19126. t['aring'] = 556;
  19127. t['Ncommaaccent'] = 722;
  19128. t['lacute'] = 222;
  19129. t['agrave'] = 556;
  19130. t['Tcommaaccent'] = 611;
  19131. t['Cacute'] = 722;
  19132. t['atilde'] = 556;
  19133. t['Edotaccent'] = 667;
  19134. t['scaron'] = 500;
  19135. t['scedilla'] = 500;
  19136. t['iacute'] = 278;
  19137. t['lozenge'] = 471;
  19138. t['Rcaron'] = 722;
  19139. t['Gcommaaccent'] = 778;
  19140. t['ucircumflex'] = 556;
  19141. t['acircumflex'] = 556;
  19142. t['Amacron'] = 667;
  19143. t['rcaron'] = 333;
  19144. t['ccedilla'] = 500;
  19145. t['Zdotaccent'] = 611;
  19146. t['Thorn'] = 667;
  19147. t['Omacron'] = 778;
  19148. t['Racute'] = 722;
  19149. t['Sacute'] = 667;
  19150. t['dcaron'] = 643;
  19151. t['Umacron'] = 722;
  19152. t['uring'] = 556;
  19153. t['threesuperior'] = 333;
  19154. t['Ograve'] = 778;
  19155. t['Agrave'] = 667;
  19156. t['Abreve'] = 667;
  19157. t['multiply'] = 584;
  19158. t['uacute'] = 556;
  19159. t['Tcaron'] = 611;
  19160. t['partialdiff'] = 476;
  19161. t['ydieresis'] = 500;
  19162. t['Nacute'] = 722;
  19163. t['icircumflex'] = 278;
  19164. t['Ecircumflex'] = 667;
  19165. t['adieresis'] = 556;
  19166. t['edieresis'] = 556;
  19167. t['cacute'] = 500;
  19168. t['nacute'] = 556;
  19169. t['umacron'] = 556;
  19170. t['Ncaron'] = 722;
  19171. t['Iacute'] = 278;
  19172. t['plusminus'] = 584;
  19173. t['brokenbar'] = 260;
  19174. t['registered'] = 737;
  19175. t['Gbreve'] = 778;
  19176. t['Idotaccent'] = 278;
  19177. t['summation'] = 600;
  19178. t['Egrave'] = 667;
  19179. t['racute'] = 333;
  19180. t['omacron'] = 556;
  19181. t['Zacute'] = 611;
  19182. t['Zcaron'] = 611;
  19183. t['greaterequal'] = 549;
  19184. t['Eth'] = 722;
  19185. t['Ccedilla'] = 722;
  19186. t['lcommaaccent'] = 222;
  19187. t['tcaron'] = 317;
  19188. t['eogonek'] = 556;
  19189. t['Uogonek'] = 722;
  19190. t['Aacute'] = 667;
  19191. t['Adieresis'] = 667;
  19192. t['egrave'] = 556;
  19193. t['zacute'] = 500;
  19194. t['iogonek'] = 222;
  19195. t['Oacute'] = 778;
  19196. t['oacute'] = 556;
  19197. t['amacron'] = 556;
  19198. t['sacute'] = 500;
  19199. t['idieresis'] = 278;
  19200. t['Ocircumflex'] = 778;
  19201. t['Ugrave'] = 722;
  19202. t['Delta'] = 612;
  19203. t['thorn'] = 556;
  19204. t['twosuperior'] = 333;
  19205. t['Odieresis'] = 778;
  19206. t['mu'] = 556;
  19207. t['igrave'] = 278;
  19208. t['ohungarumlaut'] = 556;
  19209. t['Eogonek'] = 667;
  19210. t['dcroat'] = 556;
  19211. t['threequarters'] = 834;
  19212. t['Scedilla'] = 667;
  19213. t['lcaron'] = 299;
  19214. t['Kcommaaccent'] = 667;
  19215. t['Lacute'] = 556;
  19216. t['trademark'] = 1000;
  19217. t['edotaccent'] = 556;
  19218. t['Igrave'] = 278;
  19219. t['Imacron'] = 278;
  19220. t['Lcaron'] = 556;
  19221. t['onehalf'] = 834;
  19222. t['lessequal'] = 549;
  19223. t['ocircumflex'] = 556;
  19224. t['ntilde'] = 556;
  19225. t['Uhungarumlaut'] = 722;
  19226. t['Eacute'] = 667;
  19227. t['emacron'] = 556;
  19228. t['gbreve'] = 556;
  19229. t['onequarter'] = 834;
  19230. t['Scaron'] = 667;
  19231. t['Scommaaccent'] = 667;
  19232. t['Ohungarumlaut'] = 778;
  19233. t['degree'] = 400;
  19234. t['ograve'] = 556;
  19235. t['Ccaron'] = 722;
  19236. t['ugrave'] = 556;
  19237. t['radical'] = 453;
  19238. t['Dcaron'] = 722;
  19239. t['rcommaaccent'] = 333;
  19240. t['Ntilde'] = 722;
  19241. t['otilde'] = 556;
  19242. t['Rcommaaccent'] = 722;
  19243. t['Lcommaaccent'] = 556;
  19244. t['Atilde'] = 667;
  19245. t['Aogonek'] = 667;
  19246. t['Aring'] = 667;
  19247. t['Otilde'] = 778;
  19248. t['zdotaccent'] = 500;
  19249. t['Ecaron'] = 667;
  19250. t['Iogonek'] = 278;
  19251. t['kcommaaccent'] = 500;
  19252. t['minus'] = 584;
  19253. t['Icircumflex'] = 278;
  19254. t['ncaron'] = 556;
  19255. t['tcommaaccent'] = 278;
  19256. t['logicalnot'] = 584;
  19257. t['odieresis'] = 556;
  19258. t['udieresis'] = 556;
  19259. t['notequal'] = 549;
  19260. t['gcommaaccent'] = 556;
  19261. t['eth'] = 556;
  19262. t['zcaron'] = 500;
  19263. t['ncommaaccent'] = 556;
  19264. t['onesuperior'] = 333;
  19265. t['imacron'] = 278;
  19266. t['Euro'] = 556;
  19267. });
  19268. t['Symbol'] = getLookupTableFactory(function (t) {
  19269. t['space'] = 250;
  19270. t['exclam'] = 333;
  19271. t['universal'] = 713;
  19272. t['numbersign'] = 500;
  19273. t['existential'] = 549;
  19274. t['percent'] = 833;
  19275. t['ampersand'] = 778;
  19276. t['suchthat'] = 439;
  19277. t['parenleft'] = 333;
  19278. t['parenright'] = 333;
  19279. t['asteriskmath'] = 500;
  19280. t['plus'] = 549;
  19281. t['comma'] = 250;
  19282. t['minus'] = 549;
  19283. t['period'] = 250;
  19284. t['slash'] = 278;
  19285. t['zero'] = 500;
  19286. t['one'] = 500;
  19287. t['two'] = 500;
  19288. t['three'] = 500;
  19289. t['four'] = 500;
  19290. t['five'] = 500;
  19291. t['six'] = 500;
  19292. t['seven'] = 500;
  19293. t['eight'] = 500;
  19294. t['nine'] = 500;
  19295. t['colon'] = 278;
  19296. t['semicolon'] = 278;
  19297. t['less'] = 549;
  19298. t['equal'] = 549;
  19299. t['greater'] = 549;
  19300. t['question'] = 444;
  19301. t['congruent'] = 549;
  19302. t['Alpha'] = 722;
  19303. t['Beta'] = 667;
  19304. t['Chi'] = 722;
  19305. t['Delta'] = 612;
  19306. t['Epsilon'] = 611;
  19307. t['Phi'] = 763;
  19308. t['Gamma'] = 603;
  19309. t['Eta'] = 722;
  19310. t['Iota'] = 333;
  19311. t['theta1'] = 631;
  19312. t['Kappa'] = 722;
  19313. t['Lambda'] = 686;
  19314. t['Mu'] = 889;
  19315. t['Nu'] = 722;
  19316. t['Omicron'] = 722;
  19317. t['Pi'] = 768;
  19318. t['Theta'] = 741;
  19319. t['Rho'] = 556;
  19320. t['Sigma'] = 592;
  19321. t['Tau'] = 611;
  19322. t['Upsilon'] = 690;
  19323. t['sigma1'] = 439;
  19324. t['Omega'] = 768;
  19325. t['Xi'] = 645;
  19326. t['Psi'] = 795;
  19327. t['Zeta'] = 611;
  19328. t['bracketleft'] = 333;
  19329. t['therefore'] = 863;
  19330. t['bracketright'] = 333;
  19331. t['perpendicular'] = 658;
  19332. t['underscore'] = 500;
  19333. t['radicalex'] = 500;
  19334. t['alpha'] = 631;
  19335. t['beta'] = 549;
  19336. t['chi'] = 549;
  19337. t['delta'] = 494;
  19338. t['epsilon'] = 439;
  19339. t['phi'] = 521;
  19340. t['gamma'] = 411;
  19341. t['eta'] = 603;
  19342. t['iota'] = 329;
  19343. t['phi1'] = 603;
  19344. t['kappa'] = 549;
  19345. t['lambda'] = 549;
  19346. t['mu'] = 576;
  19347. t['nu'] = 521;
  19348. t['omicron'] = 549;
  19349. t['pi'] = 549;
  19350. t['theta'] = 521;
  19351. t['rho'] = 549;
  19352. t['sigma'] = 603;
  19353. t['tau'] = 439;
  19354. t['upsilon'] = 576;
  19355. t['omega1'] = 713;
  19356. t['omega'] = 686;
  19357. t['xi'] = 493;
  19358. t['psi'] = 686;
  19359. t['zeta'] = 494;
  19360. t['braceleft'] = 480;
  19361. t['bar'] = 200;
  19362. t['braceright'] = 480;
  19363. t['similar'] = 549;
  19364. t['Euro'] = 750;
  19365. t['Upsilon1'] = 620;
  19366. t['minute'] = 247;
  19367. t['lessequal'] = 549;
  19368. t['fraction'] = 167;
  19369. t['infinity'] = 713;
  19370. t['florin'] = 500;
  19371. t['club'] = 753;
  19372. t['diamond'] = 753;
  19373. t['heart'] = 753;
  19374. t['spade'] = 753;
  19375. t['arrowboth'] = 1042;
  19376. t['arrowleft'] = 987;
  19377. t['arrowup'] = 603;
  19378. t['arrowright'] = 987;
  19379. t['arrowdown'] = 603;
  19380. t['degree'] = 400;
  19381. t['plusminus'] = 549;
  19382. t['second'] = 411;
  19383. t['greaterequal'] = 549;
  19384. t['multiply'] = 549;
  19385. t['proportional'] = 713;
  19386. t['partialdiff'] = 494;
  19387. t['bullet'] = 460;
  19388. t['divide'] = 549;
  19389. t['notequal'] = 549;
  19390. t['equivalence'] = 549;
  19391. t['approxequal'] = 549;
  19392. t['ellipsis'] = 1000;
  19393. t['arrowvertex'] = 603;
  19394. t['arrowhorizex'] = 1000;
  19395. t['carriagereturn'] = 658;
  19396. t['aleph'] = 823;
  19397. t['Ifraktur'] = 686;
  19398. t['Rfraktur'] = 795;
  19399. t['weierstrass'] = 987;
  19400. t['circlemultiply'] = 768;
  19401. t['circleplus'] = 768;
  19402. t['emptyset'] = 823;
  19403. t['intersection'] = 768;
  19404. t['union'] = 768;
  19405. t['propersuperset'] = 713;
  19406. t['reflexsuperset'] = 713;
  19407. t['notsubset'] = 713;
  19408. t['propersubset'] = 713;
  19409. t['reflexsubset'] = 713;
  19410. t['element'] = 713;
  19411. t['notelement'] = 713;
  19412. t['angle'] = 768;
  19413. t['gradient'] = 713;
  19414. t['registerserif'] = 790;
  19415. t['copyrightserif'] = 790;
  19416. t['trademarkserif'] = 890;
  19417. t['product'] = 823;
  19418. t['radical'] = 549;
  19419. t['dotmath'] = 250;
  19420. t['logicalnot'] = 713;
  19421. t['logicaland'] = 603;
  19422. t['logicalor'] = 603;
  19423. t['arrowdblboth'] = 1042;
  19424. t['arrowdblleft'] = 987;
  19425. t['arrowdblup'] = 603;
  19426. t['arrowdblright'] = 987;
  19427. t['arrowdbldown'] = 603;
  19428. t['lozenge'] = 494;
  19429. t['angleleft'] = 329;
  19430. t['registersans'] = 790;
  19431. t['copyrightsans'] = 790;
  19432. t['trademarksans'] = 786;
  19433. t['summation'] = 713;
  19434. t['parenlefttp'] = 384;
  19435. t['parenleftex'] = 384;
  19436. t['parenleftbt'] = 384;
  19437. t['bracketlefttp'] = 384;
  19438. t['bracketleftex'] = 384;
  19439. t['bracketleftbt'] = 384;
  19440. t['bracelefttp'] = 494;
  19441. t['braceleftmid'] = 494;
  19442. t['braceleftbt'] = 494;
  19443. t['braceex'] = 494;
  19444. t['angleright'] = 329;
  19445. t['integral'] = 274;
  19446. t['integraltp'] = 686;
  19447. t['integralex'] = 686;
  19448. t['integralbt'] = 686;
  19449. t['parenrighttp'] = 384;
  19450. t['parenrightex'] = 384;
  19451. t['parenrightbt'] = 384;
  19452. t['bracketrighttp'] = 384;
  19453. t['bracketrightex'] = 384;
  19454. t['bracketrightbt'] = 384;
  19455. t['bracerighttp'] = 494;
  19456. t['bracerightmid'] = 494;
  19457. t['bracerightbt'] = 494;
  19458. t['apple'] = 790;
  19459. });
  19460. t['Times-Roman'] = getLookupTableFactory(function (t) {
  19461. t['space'] = 250;
  19462. t['exclam'] = 333;
  19463. t['quotedbl'] = 408;
  19464. t['numbersign'] = 500;
  19465. t['dollar'] = 500;
  19466. t['percent'] = 833;
  19467. t['ampersand'] = 778;
  19468. t['quoteright'] = 333;
  19469. t['parenleft'] = 333;
  19470. t['parenright'] = 333;
  19471. t['asterisk'] = 500;
  19472. t['plus'] = 564;
  19473. t['comma'] = 250;
  19474. t['hyphen'] = 333;
  19475. t['period'] = 250;
  19476. t['slash'] = 278;
  19477. t['zero'] = 500;
  19478. t['one'] = 500;
  19479. t['two'] = 500;
  19480. t['three'] = 500;
  19481. t['four'] = 500;
  19482. t['five'] = 500;
  19483. t['six'] = 500;
  19484. t['seven'] = 500;
  19485. t['eight'] = 500;
  19486. t['nine'] = 500;
  19487. t['colon'] = 278;
  19488. t['semicolon'] = 278;
  19489. t['less'] = 564;
  19490. t['equal'] = 564;
  19491. t['greater'] = 564;
  19492. t['question'] = 444;
  19493. t['at'] = 921;
  19494. t['A'] = 722;
  19495. t['B'] = 667;
  19496. t['C'] = 667;
  19497. t['D'] = 722;
  19498. t['E'] = 611;
  19499. t['F'] = 556;
  19500. t['G'] = 722;
  19501. t['H'] = 722;
  19502. t['I'] = 333;
  19503. t['J'] = 389;
  19504. t['K'] = 722;
  19505. t['L'] = 611;
  19506. t['M'] = 889;
  19507. t['N'] = 722;
  19508. t['O'] = 722;
  19509. t['P'] = 556;
  19510. t['Q'] = 722;
  19511. t['R'] = 667;
  19512. t['S'] = 556;
  19513. t['T'] = 611;
  19514. t['U'] = 722;
  19515. t['V'] = 722;
  19516. t['W'] = 944;
  19517. t['X'] = 722;
  19518. t['Y'] = 722;
  19519. t['Z'] = 611;
  19520. t['bracketleft'] = 333;
  19521. t['backslash'] = 278;
  19522. t['bracketright'] = 333;
  19523. t['asciicircum'] = 469;
  19524. t['underscore'] = 500;
  19525. t['quoteleft'] = 333;
  19526. t['a'] = 444;
  19527. t['b'] = 500;
  19528. t['c'] = 444;
  19529. t['d'] = 500;
  19530. t['e'] = 444;
  19531. t['f'] = 333;
  19532. t['g'] = 500;
  19533. t['h'] = 500;
  19534. t['i'] = 278;
  19535. t['j'] = 278;
  19536. t['k'] = 500;
  19537. t['l'] = 278;
  19538. t['m'] = 778;
  19539. t['n'] = 500;
  19540. t['o'] = 500;
  19541. t['p'] = 500;
  19542. t['q'] = 500;
  19543. t['r'] = 333;
  19544. t['s'] = 389;
  19545. t['t'] = 278;
  19546. t['u'] = 500;
  19547. t['v'] = 500;
  19548. t['w'] = 722;
  19549. t['x'] = 500;
  19550. t['y'] = 500;
  19551. t['z'] = 444;
  19552. t['braceleft'] = 480;
  19553. t['bar'] = 200;
  19554. t['braceright'] = 480;
  19555. t['asciitilde'] = 541;
  19556. t['exclamdown'] = 333;
  19557. t['cent'] = 500;
  19558. t['sterling'] = 500;
  19559. t['fraction'] = 167;
  19560. t['yen'] = 500;
  19561. t['florin'] = 500;
  19562. t['section'] = 500;
  19563. t['currency'] = 500;
  19564. t['quotesingle'] = 180;
  19565. t['quotedblleft'] = 444;
  19566. t['guillemotleft'] = 500;
  19567. t['guilsinglleft'] = 333;
  19568. t['guilsinglright'] = 333;
  19569. t['fi'] = 556;
  19570. t['fl'] = 556;
  19571. t['endash'] = 500;
  19572. t['dagger'] = 500;
  19573. t['daggerdbl'] = 500;
  19574. t['periodcentered'] = 250;
  19575. t['paragraph'] = 453;
  19576. t['bullet'] = 350;
  19577. t['quotesinglbase'] = 333;
  19578. t['quotedblbase'] = 444;
  19579. t['quotedblright'] = 444;
  19580. t['guillemotright'] = 500;
  19581. t['ellipsis'] = 1000;
  19582. t['perthousand'] = 1000;
  19583. t['questiondown'] = 444;
  19584. t['grave'] = 333;
  19585. t['acute'] = 333;
  19586. t['circumflex'] = 333;
  19587. t['tilde'] = 333;
  19588. t['macron'] = 333;
  19589. t['breve'] = 333;
  19590. t['dotaccent'] = 333;
  19591. t['dieresis'] = 333;
  19592. t['ring'] = 333;
  19593. t['cedilla'] = 333;
  19594. t['hungarumlaut'] = 333;
  19595. t['ogonek'] = 333;
  19596. t['caron'] = 333;
  19597. t['emdash'] = 1000;
  19598. t['AE'] = 889;
  19599. t['ordfeminine'] = 276;
  19600. t['Lslash'] = 611;
  19601. t['Oslash'] = 722;
  19602. t['OE'] = 889;
  19603. t['ordmasculine'] = 310;
  19604. t['ae'] = 667;
  19605. t['dotlessi'] = 278;
  19606. t['lslash'] = 278;
  19607. t['oslash'] = 500;
  19608. t['oe'] = 722;
  19609. t['germandbls'] = 500;
  19610. t['Idieresis'] = 333;
  19611. t['eacute'] = 444;
  19612. t['abreve'] = 444;
  19613. t['uhungarumlaut'] = 500;
  19614. t['ecaron'] = 444;
  19615. t['Ydieresis'] = 722;
  19616. t['divide'] = 564;
  19617. t['Yacute'] = 722;
  19618. t['Acircumflex'] = 722;
  19619. t['aacute'] = 444;
  19620. t['Ucircumflex'] = 722;
  19621. t['yacute'] = 500;
  19622. t['scommaaccent'] = 389;
  19623. t['ecircumflex'] = 444;
  19624. t['Uring'] = 722;
  19625. t['Udieresis'] = 722;
  19626. t['aogonek'] = 444;
  19627. t['Uacute'] = 722;
  19628. t['uogonek'] = 500;
  19629. t['Edieresis'] = 611;
  19630. t['Dcroat'] = 722;
  19631. t['commaaccent'] = 250;
  19632. t['copyright'] = 760;
  19633. t['Emacron'] = 611;
  19634. t['ccaron'] = 444;
  19635. t['aring'] = 444;
  19636. t['Ncommaaccent'] = 722;
  19637. t['lacute'] = 278;
  19638. t['agrave'] = 444;
  19639. t['Tcommaaccent'] = 611;
  19640. t['Cacute'] = 667;
  19641. t['atilde'] = 444;
  19642. t['Edotaccent'] = 611;
  19643. t['scaron'] = 389;
  19644. t['scedilla'] = 389;
  19645. t['iacute'] = 278;
  19646. t['lozenge'] = 471;
  19647. t['Rcaron'] = 667;
  19648. t['Gcommaaccent'] = 722;
  19649. t['ucircumflex'] = 500;
  19650. t['acircumflex'] = 444;
  19651. t['Amacron'] = 722;
  19652. t['rcaron'] = 333;
  19653. t['ccedilla'] = 444;
  19654. t['Zdotaccent'] = 611;
  19655. t['Thorn'] = 556;
  19656. t['Omacron'] = 722;
  19657. t['Racute'] = 667;
  19658. t['Sacute'] = 556;
  19659. t['dcaron'] = 588;
  19660. t['Umacron'] = 722;
  19661. t['uring'] = 500;
  19662. t['threesuperior'] = 300;
  19663. t['Ograve'] = 722;
  19664. t['Agrave'] = 722;
  19665. t['Abreve'] = 722;
  19666. t['multiply'] = 564;
  19667. t['uacute'] = 500;
  19668. t['Tcaron'] = 611;
  19669. t['partialdiff'] = 476;
  19670. t['ydieresis'] = 500;
  19671. t['Nacute'] = 722;
  19672. t['icircumflex'] = 278;
  19673. t['Ecircumflex'] = 611;
  19674. t['adieresis'] = 444;
  19675. t['edieresis'] = 444;
  19676. t['cacute'] = 444;
  19677. t['nacute'] = 500;
  19678. t['umacron'] = 500;
  19679. t['Ncaron'] = 722;
  19680. t['Iacute'] = 333;
  19681. t['plusminus'] = 564;
  19682. t['brokenbar'] = 200;
  19683. t['registered'] = 760;
  19684. t['Gbreve'] = 722;
  19685. t['Idotaccent'] = 333;
  19686. t['summation'] = 600;
  19687. t['Egrave'] = 611;
  19688. t['racute'] = 333;
  19689. t['omacron'] = 500;
  19690. t['Zacute'] = 611;
  19691. t['Zcaron'] = 611;
  19692. t['greaterequal'] = 549;
  19693. t['Eth'] = 722;
  19694. t['Ccedilla'] = 667;
  19695. t['lcommaaccent'] = 278;
  19696. t['tcaron'] = 326;
  19697. t['eogonek'] = 444;
  19698. t['Uogonek'] = 722;
  19699. t['Aacute'] = 722;
  19700. t['Adieresis'] = 722;
  19701. t['egrave'] = 444;
  19702. t['zacute'] = 444;
  19703. t['iogonek'] = 278;
  19704. t['Oacute'] = 722;
  19705. t['oacute'] = 500;
  19706. t['amacron'] = 444;
  19707. t['sacute'] = 389;
  19708. t['idieresis'] = 278;
  19709. t['Ocircumflex'] = 722;
  19710. t['Ugrave'] = 722;
  19711. t['Delta'] = 612;
  19712. t['thorn'] = 500;
  19713. t['twosuperior'] = 300;
  19714. t['Odieresis'] = 722;
  19715. t['mu'] = 500;
  19716. t['igrave'] = 278;
  19717. t['ohungarumlaut'] = 500;
  19718. t['Eogonek'] = 611;
  19719. t['dcroat'] = 500;
  19720. t['threequarters'] = 750;
  19721. t['Scedilla'] = 556;
  19722. t['lcaron'] = 344;
  19723. t['Kcommaaccent'] = 722;
  19724. t['Lacute'] = 611;
  19725. t['trademark'] = 980;
  19726. t['edotaccent'] = 444;
  19727. t['Igrave'] = 333;
  19728. t['Imacron'] = 333;
  19729. t['Lcaron'] = 611;
  19730. t['onehalf'] = 750;
  19731. t['lessequal'] = 549;
  19732. t['ocircumflex'] = 500;
  19733. t['ntilde'] = 500;
  19734. t['Uhungarumlaut'] = 722;
  19735. t['Eacute'] = 611;
  19736. t['emacron'] = 444;
  19737. t['gbreve'] = 500;
  19738. t['onequarter'] = 750;
  19739. t['Scaron'] = 556;
  19740. t['Scommaaccent'] = 556;
  19741. t['Ohungarumlaut'] = 722;
  19742. t['degree'] = 400;
  19743. t['ograve'] = 500;
  19744. t['Ccaron'] = 667;
  19745. t['ugrave'] = 500;
  19746. t['radical'] = 453;
  19747. t['Dcaron'] = 722;
  19748. t['rcommaaccent'] = 333;
  19749. t['Ntilde'] = 722;
  19750. t['otilde'] = 500;
  19751. t['Rcommaaccent'] = 667;
  19752. t['Lcommaaccent'] = 611;
  19753. t['Atilde'] = 722;
  19754. t['Aogonek'] = 722;
  19755. t['Aring'] = 722;
  19756. t['Otilde'] = 722;
  19757. t['zdotaccent'] = 444;
  19758. t['Ecaron'] = 611;
  19759. t['Iogonek'] = 333;
  19760. t['kcommaaccent'] = 500;
  19761. t['minus'] = 564;
  19762. t['Icircumflex'] = 333;
  19763. t['ncaron'] = 500;
  19764. t['tcommaaccent'] = 278;
  19765. t['logicalnot'] = 564;
  19766. t['odieresis'] = 500;
  19767. t['udieresis'] = 500;
  19768. t['notequal'] = 549;
  19769. t['gcommaaccent'] = 500;
  19770. t['eth'] = 500;
  19771. t['zcaron'] = 444;
  19772. t['ncommaaccent'] = 500;
  19773. t['onesuperior'] = 300;
  19774. t['imacron'] = 278;
  19775. t['Euro'] = 500;
  19776. });
  19777. t['Times-Bold'] = getLookupTableFactory(function (t) {
  19778. t['space'] = 250;
  19779. t['exclam'] = 333;
  19780. t['quotedbl'] = 555;
  19781. t['numbersign'] = 500;
  19782. t['dollar'] = 500;
  19783. t['percent'] = 1000;
  19784. t['ampersand'] = 833;
  19785. t['quoteright'] = 333;
  19786. t['parenleft'] = 333;
  19787. t['parenright'] = 333;
  19788. t['asterisk'] = 500;
  19789. t['plus'] = 570;
  19790. t['comma'] = 250;
  19791. t['hyphen'] = 333;
  19792. t['period'] = 250;
  19793. t['slash'] = 278;
  19794. t['zero'] = 500;
  19795. t['one'] = 500;
  19796. t['two'] = 500;
  19797. t['three'] = 500;
  19798. t['four'] = 500;
  19799. t['five'] = 500;
  19800. t['six'] = 500;
  19801. t['seven'] = 500;
  19802. t['eight'] = 500;
  19803. t['nine'] = 500;
  19804. t['colon'] = 333;
  19805. t['semicolon'] = 333;
  19806. t['less'] = 570;
  19807. t['equal'] = 570;
  19808. t['greater'] = 570;
  19809. t['question'] = 500;
  19810. t['at'] = 930;
  19811. t['A'] = 722;
  19812. t['B'] = 667;
  19813. t['C'] = 722;
  19814. t['D'] = 722;
  19815. t['E'] = 667;
  19816. t['F'] = 611;
  19817. t['G'] = 778;
  19818. t['H'] = 778;
  19819. t['I'] = 389;
  19820. t['J'] = 500;
  19821. t['K'] = 778;
  19822. t['L'] = 667;
  19823. t['M'] = 944;
  19824. t['N'] = 722;
  19825. t['O'] = 778;
  19826. t['P'] = 611;
  19827. t['Q'] = 778;
  19828. t['R'] = 722;
  19829. t['S'] = 556;
  19830. t['T'] = 667;
  19831. t['U'] = 722;
  19832. t['V'] = 722;
  19833. t['W'] = 1000;
  19834. t['X'] = 722;
  19835. t['Y'] = 722;
  19836. t['Z'] = 667;
  19837. t['bracketleft'] = 333;
  19838. t['backslash'] = 278;
  19839. t['bracketright'] = 333;
  19840. t['asciicircum'] = 581;
  19841. t['underscore'] = 500;
  19842. t['quoteleft'] = 333;
  19843. t['a'] = 500;
  19844. t['b'] = 556;
  19845. t['c'] = 444;
  19846. t['d'] = 556;
  19847. t['e'] = 444;
  19848. t['f'] = 333;
  19849. t['g'] = 500;
  19850. t['h'] = 556;
  19851. t['i'] = 278;
  19852. t['j'] = 333;
  19853. t['k'] = 556;
  19854. t['l'] = 278;
  19855. t['m'] = 833;
  19856. t['n'] = 556;
  19857. t['o'] = 500;
  19858. t['p'] = 556;
  19859. t['q'] = 556;
  19860. t['r'] = 444;
  19861. t['s'] = 389;
  19862. t['t'] = 333;
  19863. t['u'] = 556;
  19864. t['v'] = 500;
  19865. t['w'] = 722;
  19866. t['x'] = 500;
  19867. t['y'] = 500;
  19868. t['z'] = 444;
  19869. t['braceleft'] = 394;
  19870. t['bar'] = 220;
  19871. t['braceright'] = 394;
  19872. t['asciitilde'] = 520;
  19873. t['exclamdown'] = 333;
  19874. t['cent'] = 500;
  19875. t['sterling'] = 500;
  19876. t['fraction'] = 167;
  19877. t['yen'] = 500;
  19878. t['florin'] = 500;
  19879. t['section'] = 500;
  19880. t['currency'] = 500;
  19881. t['quotesingle'] = 278;
  19882. t['quotedblleft'] = 500;
  19883. t['guillemotleft'] = 500;
  19884. t['guilsinglleft'] = 333;
  19885. t['guilsinglright'] = 333;
  19886. t['fi'] = 556;
  19887. t['fl'] = 556;
  19888. t['endash'] = 500;
  19889. t['dagger'] = 500;
  19890. t['daggerdbl'] = 500;
  19891. t['periodcentered'] = 250;
  19892. t['paragraph'] = 540;
  19893. t['bullet'] = 350;
  19894. t['quotesinglbase'] = 333;
  19895. t['quotedblbase'] = 500;
  19896. t['quotedblright'] = 500;
  19897. t['guillemotright'] = 500;
  19898. t['ellipsis'] = 1000;
  19899. t['perthousand'] = 1000;
  19900. t['questiondown'] = 500;
  19901. t['grave'] = 333;
  19902. t['acute'] = 333;
  19903. t['circumflex'] = 333;
  19904. t['tilde'] = 333;
  19905. t['macron'] = 333;
  19906. t['breve'] = 333;
  19907. t['dotaccent'] = 333;
  19908. t['dieresis'] = 333;
  19909. t['ring'] = 333;
  19910. t['cedilla'] = 333;
  19911. t['hungarumlaut'] = 333;
  19912. t['ogonek'] = 333;
  19913. t['caron'] = 333;
  19914. t['emdash'] = 1000;
  19915. t['AE'] = 1000;
  19916. t['ordfeminine'] = 300;
  19917. t['Lslash'] = 667;
  19918. t['Oslash'] = 778;
  19919. t['OE'] = 1000;
  19920. t['ordmasculine'] = 330;
  19921. t['ae'] = 722;
  19922. t['dotlessi'] = 278;
  19923. t['lslash'] = 278;
  19924. t['oslash'] = 500;
  19925. t['oe'] = 722;
  19926. t['germandbls'] = 556;
  19927. t['Idieresis'] = 389;
  19928. t['eacute'] = 444;
  19929. t['abreve'] = 500;
  19930. t['uhungarumlaut'] = 556;
  19931. t['ecaron'] = 444;
  19932. t['Ydieresis'] = 722;
  19933. t['divide'] = 570;
  19934. t['Yacute'] = 722;
  19935. t['Acircumflex'] = 722;
  19936. t['aacute'] = 500;
  19937. t['Ucircumflex'] = 722;
  19938. t['yacute'] = 500;
  19939. t['scommaaccent'] = 389;
  19940. t['ecircumflex'] = 444;
  19941. t['Uring'] = 722;
  19942. t['Udieresis'] = 722;
  19943. t['aogonek'] = 500;
  19944. t['Uacute'] = 722;
  19945. t['uogonek'] = 556;
  19946. t['Edieresis'] = 667;
  19947. t['Dcroat'] = 722;
  19948. t['commaaccent'] = 250;
  19949. t['copyright'] = 747;
  19950. t['Emacron'] = 667;
  19951. t['ccaron'] = 444;
  19952. t['aring'] = 500;
  19953. t['Ncommaaccent'] = 722;
  19954. t['lacute'] = 278;
  19955. t['agrave'] = 500;
  19956. t['Tcommaaccent'] = 667;
  19957. t['Cacute'] = 722;
  19958. t['atilde'] = 500;
  19959. t['Edotaccent'] = 667;
  19960. t['scaron'] = 389;
  19961. t['scedilla'] = 389;
  19962. t['iacute'] = 278;
  19963. t['lozenge'] = 494;
  19964. t['Rcaron'] = 722;
  19965. t['Gcommaaccent'] = 778;
  19966. t['ucircumflex'] = 556;
  19967. t['acircumflex'] = 500;
  19968. t['Amacron'] = 722;
  19969. t['rcaron'] = 444;
  19970. t['ccedilla'] = 444;
  19971. t['Zdotaccent'] = 667;
  19972. t['Thorn'] = 611;
  19973. t['Omacron'] = 778;
  19974. t['Racute'] = 722;
  19975. t['Sacute'] = 556;
  19976. t['dcaron'] = 672;
  19977. t['Umacron'] = 722;
  19978. t['uring'] = 556;
  19979. t['threesuperior'] = 300;
  19980. t['Ograve'] = 778;
  19981. t['Agrave'] = 722;
  19982. t['Abreve'] = 722;
  19983. t['multiply'] = 570;
  19984. t['uacute'] = 556;
  19985. t['Tcaron'] = 667;
  19986. t['partialdiff'] = 494;
  19987. t['ydieresis'] = 500;
  19988. t['Nacute'] = 722;
  19989. t['icircumflex'] = 278;
  19990. t['Ecircumflex'] = 667;
  19991. t['adieresis'] = 500;
  19992. t['edieresis'] = 444;
  19993. t['cacute'] = 444;
  19994. t['nacute'] = 556;
  19995. t['umacron'] = 556;
  19996. t['Ncaron'] = 722;
  19997. t['Iacute'] = 389;
  19998. t['plusminus'] = 570;
  19999. t['brokenbar'] = 220;
  20000. t['registered'] = 747;
  20001. t['Gbreve'] = 778;
  20002. t['Idotaccent'] = 389;
  20003. t['summation'] = 600;
  20004. t['Egrave'] = 667;
  20005. t['racute'] = 444;
  20006. t['omacron'] = 500;
  20007. t['Zacute'] = 667;
  20008. t['Zcaron'] = 667;
  20009. t['greaterequal'] = 549;
  20010. t['Eth'] = 722;
  20011. t['Ccedilla'] = 722;
  20012. t['lcommaaccent'] = 278;
  20013. t['tcaron'] = 416;
  20014. t['eogonek'] = 444;
  20015. t['Uogonek'] = 722;
  20016. t['Aacute'] = 722;
  20017. t['Adieresis'] = 722;
  20018. t['egrave'] = 444;
  20019. t['zacute'] = 444;
  20020. t['iogonek'] = 278;
  20021. t['Oacute'] = 778;
  20022. t['oacute'] = 500;
  20023. t['amacron'] = 500;
  20024. t['sacute'] = 389;
  20025. t['idieresis'] = 278;
  20026. t['Ocircumflex'] = 778;
  20027. t['Ugrave'] = 722;
  20028. t['Delta'] = 612;
  20029. t['thorn'] = 556;
  20030. t['twosuperior'] = 300;
  20031. t['Odieresis'] = 778;
  20032. t['mu'] = 556;
  20033. t['igrave'] = 278;
  20034. t['ohungarumlaut'] = 500;
  20035. t['Eogonek'] = 667;
  20036. t['dcroat'] = 556;
  20037. t['threequarters'] = 750;
  20038. t['Scedilla'] = 556;
  20039. t['lcaron'] = 394;
  20040. t['Kcommaaccent'] = 778;
  20041. t['Lacute'] = 667;
  20042. t['trademark'] = 1000;
  20043. t['edotaccent'] = 444;
  20044. t['Igrave'] = 389;
  20045. t['Imacron'] = 389;
  20046. t['Lcaron'] = 667;
  20047. t['onehalf'] = 750;
  20048. t['lessequal'] = 549;
  20049. t['ocircumflex'] = 500;
  20050. t['ntilde'] = 556;
  20051. t['Uhungarumlaut'] = 722;
  20052. t['Eacute'] = 667;
  20053. t['emacron'] = 444;
  20054. t['gbreve'] = 500;
  20055. t['onequarter'] = 750;
  20056. t['Scaron'] = 556;
  20057. t['Scommaaccent'] = 556;
  20058. t['Ohungarumlaut'] = 778;
  20059. t['degree'] = 400;
  20060. t['ograve'] = 500;
  20061. t['Ccaron'] = 722;
  20062. t['ugrave'] = 556;
  20063. t['radical'] = 549;
  20064. t['Dcaron'] = 722;
  20065. t['rcommaaccent'] = 444;
  20066. t['Ntilde'] = 722;
  20067. t['otilde'] = 500;
  20068. t['Rcommaaccent'] = 722;
  20069. t['Lcommaaccent'] = 667;
  20070. t['Atilde'] = 722;
  20071. t['Aogonek'] = 722;
  20072. t['Aring'] = 722;
  20073. t['Otilde'] = 778;
  20074. t['zdotaccent'] = 444;
  20075. t['Ecaron'] = 667;
  20076. t['Iogonek'] = 389;
  20077. t['kcommaaccent'] = 556;
  20078. t['minus'] = 570;
  20079. t['Icircumflex'] = 389;
  20080. t['ncaron'] = 556;
  20081. t['tcommaaccent'] = 333;
  20082. t['logicalnot'] = 570;
  20083. t['odieresis'] = 500;
  20084. t['udieresis'] = 556;
  20085. t['notequal'] = 549;
  20086. t['gcommaaccent'] = 500;
  20087. t['eth'] = 500;
  20088. t['zcaron'] = 444;
  20089. t['ncommaaccent'] = 556;
  20090. t['onesuperior'] = 300;
  20091. t['imacron'] = 278;
  20092. t['Euro'] = 500;
  20093. });
  20094. t['Times-BoldItalic'] = getLookupTableFactory(function (t) {
  20095. t['space'] = 250;
  20096. t['exclam'] = 389;
  20097. t['quotedbl'] = 555;
  20098. t['numbersign'] = 500;
  20099. t['dollar'] = 500;
  20100. t['percent'] = 833;
  20101. t['ampersand'] = 778;
  20102. t['quoteright'] = 333;
  20103. t['parenleft'] = 333;
  20104. t['parenright'] = 333;
  20105. t['asterisk'] = 500;
  20106. t['plus'] = 570;
  20107. t['comma'] = 250;
  20108. t['hyphen'] = 333;
  20109. t['period'] = 250;
  20110. t['slash'] = 278;
  20111. t['zero'] = 500;
  20112. t['one'] = 500;
  20113. t['two'] = 500;
  20114. t['three'] = 500;
  20115. t['four'] = 500;
  20116. t['five'] = 500;
  20117. t['six'] = 500;
  20118. t['seven'] = 500;
  20119. t['eight'] = 500;
  20120. t['nine'] = 500;
  20121. t['colon'] = 333;
  20122. t['semicolon'] = 333;
  20123. t['less'] = 570;
  20124. t['equal'] = 570;
  20125. t['greater'] = 570;
  20126. t['question'] = 500;
  20127. t['at'] = 832;
  20128. t['A'] = 667;
  20129. t['B'] = 667;
  20130. t['C'] = 667;
  20131. t['D'] = 722;
  20132. t['E'] = 667;
  20133. t['F'] = 667;
  20134. t['G'] = 722;
  20135. t['H'] = 778;
  20136. t['I'] = 389;
  20137. t['J'] = 500;
  20138. t['K'] = 667;
  20139. t['L'] = 611;
  20140. t['M'] = 889;
  20141. t['N'] = 722;
  20142. t['O'] = 722;
  20143. t['P'] = 611;
  20144. t['Q'] = 722;
  20145. t['R'] = 667;
  20146. t['S'] = 556;
  20147. t['T'] = 611;
  20148. t['U'] = 722;
  20149. t['V'] = 667;
  20150. t['W'] = 889;
  20151. t['X'] = 667;
  20152. t['Y'] = 611;
  20153. t['Z'] = 611;
  20154. t['bracketleft'] = 333;
  20155. t['backslash'] = 278;
  20156. t['bracketright'] = 333;
  20157. t['asciicircum'] = 570;
  20158. t['underscore'] = 500;
  20159. t['quoteleft'] = 333;
  20160. t['a'] = 500;
  20161. t['b'] = 500;
  20162. t['c'] = 444;
  20163. t['d'] = 500;
  20164. t['e'] = 444;
  20165. t['f'] = 333;
  20166. t['g'] = 500;
  20167. t['h'] = 556;
  20168. t['i'] = 278;
  20169. t['j'] = 278;
  20170. t['k'] = 500;
  20171. t['l'] = 278;
  20172. t['m'] = 778;
  20173. t['n'] = 556;
  20174. t['o'] = 500;
  20175. t['p'] = 500;
  20176. t['q'] = 500;
  20177. t['r'] = 389;
  20178. t['s'] = 389;
  20179. t['t'] = 278;
  20180. t['u'] = 556;
  20181. t['v'] = 444;
  20182. t['w'] = 667;
  20183. t['x'] = 500;
  20184. t['y'] = 444;
  20185. t['z'] = 389;
  20186. t['braceleft'] = 348;
  20187. t['bar'] = 220;
  20188. t['braceright'] = 348;
  20189. t['asciitilde'] = 570;
  20190. t['exclamdown'] = 389;
  20191. t['cent'] = 500;
  20192. t['sterling'] = 500;
  20193. t['fraction'] = 167;
  20194. t['yen'] = 500;
  20195. t['florin'] = 500;
  20196. t['section'] = 500;
  20197. t['currency'] = 500;
  20198. t['quotesingle'] = 278;
  20199. t['quotedblleft'] = 500;
  20200. t['guillemotleft'] = 500;
  20201. t['guilsinglleft'] = 333;
  20202. t['guilsinglright'] = 333;
  20203. t['fi'] = 556;
  20204. t['fl'] = 556;
  20205. t['endash'] = 500;
  20206. t['dagger'] = 500;
  20207. t['daggerdbl'] = 500;
  20208. t['periodcentered'] = 250;
  20209. t['paragraph'] = 500;
  20210. t['bullet'] = 350;
  20211. t['quotesinglbase'] = 333;
  20212. t['quotedblbase'] = 500;
  20213. t['quotedblright'] = 500;
  20214. t['guillemotright'] = 500;
  20215. t['ellipsis'] = 1000;
  20216. t['perthousand'] = 1000;
  20217. t['questiondown'] = 500;
  20218. t['grave'] = 333;
  20219. t['acute'] = 333;
  20220. t['circumflex'] = 333;
  20221. t['tilde'] = 333;
  20222. t['macron'] = 333;
  20223. t['breve'] = 333;
  20224. t['dotaccent'] = 333;
  20225. t['dieresis'] = 333;
  20226. t['ring'] = 333;
  20227. t['cedilla'] = 333;
  20228. t['hungarumlaut'] = 333;
  20229. t['ogonek'] = 333;
  20230. t['caron'] = 333;
  20231. t['emdash'] = 1000;
  20232. t['AE'] = 944;
  20233. t['ordfeminine'] = 266;
  20234. t['Lslash'] = 611;
  20235. t['Oslash'] = 722;
  20236. t['OE'] = 944;
  20237. t['ordmasculine'] = 300;
  20238. t['ae'] = 722;
  20239. t['dotlessi'] = 278;
  20240. t['lslash'] = 278;
  20241. t['oslash'] = 500;
  20242. t['oe'] = 722;
  20243. t['germandbls'] = 500;
  20244. t['Idieresis'] = 389;
  20245. t['eacute'] = 444;
  20246. t['abreve'] = 500;
  20247. t['uhungarumlaut'] = 556;
  20248. t['ecaron'] = 444;
  20249. t['Ydieresis'] = 611;
  20250. t['divide'] = 570;
  20251. t['Yacute'] = 611;
  20252. t['Acircumflex'] = 667;
  20253. t['aacute'] = 500;
  20254. t['Ucircumflex'] = 722;
  20255. t['yacute'] = 444;
  20256. t['scommaaccent'] = 389;
  20257. t['ecircumflex'] = 444;
  20258. t['Uring'] = 722;
  20259. t['Udieresis'] = 722;
  20260. t['aogonek'] = 500;
  20261. t['Uacute'] = 722;
  20262. t['uogonek'] = 556;
  20263. t['Edieresis'] = 667;
  20264. t['Dcroat'] = 722;
  20265. t['commaaccent'] = 250;
  20266. t['copyright'] = 747;
  20267. t['Emacron'] = 667;
  20268. t['ccaron'] = 444;
  20269. t['aring'] = 500;
  20270. t['Ncommaaccent'] = 722;
  20271. t['lacute'] = 278;
  20272. t['agrave'] = 500;
  20273. t['Tcommaaccent'] = 611;
  20274. t['Cacute'] = 667;
  20275. t['atilde'] = 500;
  20276. t['Edotaccent'] = 667;
  20277. t['scaron'] = 389;
  20278. t['scedilla'] = 389;
  20279. t['iacute'] = 278;
  20280. t['lozenge'] = 494;
  20281. t['Rcaron'] = 667;
  20282. t['Gcommaaccent'] = 722;
  20283. t['ucircumflex'] = 556;
  20284. t['acircumflex'] = 500;
  20285. t['Amacron'] = 667;
  20286. t['rcaron'] = 389;
  20287. t['ccedilla'] = 444;
  20288. t['Zdotaccent'] = 611;
  20289. t['Thorn'] = 611;
  20290. t['Omacron'] = 722;
  20291. t['Racute'] = 667;
  20292. t['Sacute'] = 556;
  20293. t['dcaron'] = 608;
  20294. t['Umacron'] = 722;
  20295. t['uring'] = 556;
  20296. t['threesuperior'] = 300;
  20297. t['Ograve'] = 722;
  20298. t['Agrave'] = 667;
  20299. t['Abreve'] = 667;
  20300. t['multiply'] = 570;
  20301. t['uacute'] = 556;
  20302. t['Tcaron'] = 611;
  20303. t['partialdiff'] = 494;
  20304. t['ydieresis'] = 444;
  20305. t['Nacute'] = 722;
  20306. t['icircumflex'] = 278;
  20307. t['Ecircumflex'] = 667;
  20308. t['adieresis'] = 500;
  20309. t['edieresis'] = 444;
  20310. t['cacute'] = 444;
  20311. t['nacute'] = 556;
  20312. t['umacron'] = 556;
  20313. t['Ncaron'] = 722;
  20314. t['Iacute'] = 389;
  20315. t['plusminus'] = 570;
  20316. t['brokenbar'] = 220;
  20317. t['registered'] = 747;
  20318. t['Gbreve'] = 722;
  20319. t['Idotaccent'] = 389;
  20320. t['summation'] = 600;
  20321. t['Egrave'] = 667;
  20322. t['racute'] = 389;
  20323. t['omacron'] = 500;
  20324. t['Zacute'] = 611;
  20325. t['Zcaron'] = 611;
  20326. t['greaterequal'] = 549;
  20327. t['Eth'] = 722;
  20328. t['Ccedilla'] = 667;
  20329. t['lcommaaccent'] = 278;
  20330. t['tcaron'] = 366;
  20331. t['eogonek'] = 444;
  20332. t['Uogonek'] = 722;
  20333. t['Aacute'] = 667;
  20334. t['Adieresis'] = 667;
  20335. t['egrave'] = 444;
  20336. t['zacute'] = 389;
  20337. t['iogonek'] = 278;
  20338. t['Oacute'] = 722;
  20339. t['oacute'] = 500;
  20340. t['amacron'] = 500;
  20341. t['sacute'] = 389;
  20342. t['idieresis'] = 278;
  20343. t['Ocircumflex'] = 722;
  20344. t['Ugrave'] = 722;
  20345. t['Delta'] = 612;
  20346. t['thorn'] = 500;
  20347. t['twosuperior'] = 300;
  20348. t['Odieresis'] = 722;
  20349. t['mu'] = 576;
  20350. t['igrave'] = 278;
  20351. t['ohungarumlaut'] = 500;
  20352. t['Eogonek'] = 667;
  20353. t['dcroat'] = 500;
  20354. t['threequarters'] = 750;
  20355. t['Scedilla'] = 556;
  20356. t['lcaron'] = 382;
  20357. t['Kcommaaccent'] = 667;
  20358. t['Lacute'] = 611;
  20359. t['trademark'] = 1000;
  20360. t['edotaccent'] = 444;
  20361. t['Igrave'] = 389;
  20362. t['Imacron'] = 389;
  20363. t['Lcaron'] = 611;
  20364. t['onehalf'] = 750;
  20365. t['lessequal'] = 549;
  20366. t['ocircumflex'] = 500;
  20367. t['ntilde'] = 556;
  20368. t['Uhungarumlaut'] = 722;
  20369. t['Eacute'] = 667;
  20370. t['emacron'] = 444;
  20371. t['gbreve'] = 500;
  20372. t['onequarter'] = 750;
  20373. t['Scaron'] = 556;
  20374. t['Scommaaccent'] = 556;
  20375. t['Ohungarumlaut'] = 722;
  20376. t['degree'] = 400;
  20377. t['ograve'] = 500;
  20378. t['Ccaron'] = 667;
  20379. t['ugrave'] = 556;
  20380. t['radical'] = 549;
  20381. t['Dcaron'] = 722;
  20382. t['rcommaaccent'] = 389;
  20383. t['Ntilde'] = 722;
  20384. t['otilde'] = 500;
  20385. t['Rcommaaccent'] = 667;
  20386. t['Lcommaaccent'] = 611;
  20387. t['Atilde'] = 667;
  20388. t['Aogonek'] = 667;
  20389. t['Aring'] = 667;
  20390. t['Otilde'] = 722;
  20391. t['zdotaccent'] = 389;
  20392. t['Ecaron'] = 667;
  20393. t['Iogonek'] = 389;
  20394. t['kcommaaccent'] = 500;
  20395. t['minus'] = 606;
  20396. t['Icircumflex'] = 389;
  20397. t['ncaron'] = 556;
  20398. t['tcommaaccent'] = 278;
  20399. t['logicalnot'] = 606;
  20400. t['odieresis'] = 500;
  20401. t['udieresis'] = 556;
  20402. t['notequal'] = 549;
  20403. t['gcommaaccent'] = 500;
  20404. t['eth'] = 500;
  20405. t['zcaron'] = 389;
  20406. t['ncommaaccent'] = 556;
  20407. t['onesuperior'] = 300;
  20408. t['imacron'] = 278;
  20409. t['Euro'] = 500;
  20410. });
  20411. t['Times-Italic'] = getLookupTableFactory(function (t) {
  20412. t['space'] = 250;
  20413. t['exclam'] = 333;
  20414. t['quotedbl'] = 420;
  20415. t['numbersign'] = 500;
  20416. t['dollar'] = 500;
  20417. t['percent'] = 833;
  20418. t['ampersand'] = 778;
  20419. t['quoteright'] = 333;
  20420. t['parenleft'] = 333;
  20421. t['parenright'] = 333;
  20422. t['asterisk'] = 500;
  20423. t['plus'] = 675;
  20424. t['comma'] = 250;
  20425. t['hyphen'] = 333;
  20426. t['period'] = 250;
  20427. t['slash'] = 278;
  20428. t['zero'] = 500;
  20429. t['one'] = 500;
  20430. t['two'] = 500;
  20431. t['three'] = 500;
  20432. t['four'] = 500;
  20433. t['five'] = 500;
  20434. t['six'] = 500;
  20435. t['seven'] = 500;
  20436. t['eight'] = 500;
  20437. t['nine'] = 500;
  20438. t['colon'] = 333;
  20439. t['semicolon'] = 333;
  20440. t['less'] = 675;
  20441. t['equal'] = 675;
  20442. t['greater'] = 675;
  20443. t['question'] = 500;
  20444. t['at'] = 920;
  20445. t['A'] = 611;
  20446. t['B'] = 611;
  20447. t['C'] = 667;
  20448. t['D'] = 722;
  20449. t['E'] = 611;
  20450. t['F'] = 611;
  20451. t['G'] = 722;
  20452. t['H'] = 722;
  20453. t['I'] = 333;
  20454. t['J'] = 444;
  20455. t['K'] = 667;
  20456. t['L'] = 556;
  20457. t['M'] = 833;
  20458. t['N'] = 667;
  20459. t['O'] = 722;
  20460. t['P'] = 611;
  20461. t['Q'] = 722;
  20462. t['R'] = 611;
  20463. t['S'] = 500;
  20464. t['T'] = 556;
  20465. t['U'] = 722;
  20466. t['V'] = 611;
  20467. t['W'] = 833;
  20468. t['X'] = 611;
  20469. t['Y'] = 556;
  20470. t['Z'] = 556;
  20471. t['bracketleft'] = 389;
  20472. t['backslash'] = 278;
  20473. t['bracketright'] = 389;
  20474. t['asciicircum'] = 422;
  20475. t['underscore'] = 500;
  20476. t['quoteleft'] = 333;
  20477. t['a'] = 500;
  20478. t['b'] = 500;
  20479. t['c'] = 444;
  20480. t['d'] = 500;
  20481. t['e'] = 444;
  20482. t['f'] = 278;
  20483. t['g'] = 500;
  20484. t['h'] = 500;
  20485. t['i'] = 278;
  20486. t['j'] = 278;
  20487. t['k'] = 444;
  20488. t['l'] = 278;
  20489. t['m'] = 722;
  20490. t['n'] = 500;
  20491. t['o'] = 500;
  20492. t['p'] = 500;
  20493. t['q'] = 500;
  20494. t['r'] = 389;
  20495. t['s'] = 389;
  20496. t['t'] = 278;
  20497. t['u'] = 500;
  20498. t['v'] = 444;
  20499. t['w'] = 667;
  20500. t['x'] = 444;
  20501. t['y'] = 444;
  20502. t['z'] = 389;
  20503. t['braceleft'] = 400;
  20504. t['bar'] = 275;
  20505. t['braceright'] = 400;
  20506. t['asciitilde'] = 541;
  20507. t['exclamdown'] = 389;
  20508. t['cent'] = 500;
  20509. t['sterling'] = 500;
  20510. t['fraction'] = 167;
  20511. t['yen'] = 500;
  20512. t['florin'] = 500;
  20513. t['section'] = 500;
  20514. t['currency'] = 500;
  20515. t['quotesingle'] = 214;
  20516. t['quotedblleft'] = 556;
  20517. t['guillemotleft'] = 500;
  20518. t['guilsinglleft'] = 333;
  20519. t['guilsinglright'] = 333;
  20520. t['fi'] = 500;
  20521. t['fl'] = 500;
  20522. t['endash'] = 500;
  20523. t['dagger'] = 500;
  20524. t['daggerdbl'] = 500;
  20525. t['periodcentered'] = 250;
  20526. t['paragraph'] = 523;
  20527. t['bullet'] = 350;
  20528. t['quotesinglbase'] = 333;
  20529. t['quotedblbase'] = 556;
  20530. t['quotedblright'] = 556;
  20531. t['guillemotright'] = 500;
  20532. t['ellipsis'] = 889;
  20533. t['perthousand'] = 1000;
  20534. t['questiondown'] = 500;
  20535. t['grave'] = 333;
  20536. t['acute'] = 333;
  20537. t['circumflex'] = 333;
  20538. t['tilde'] = 333;
  20539. t['macron'] = 333;
  20540. t['breve'] = 333;
  20541. t['dotaccent'] = 333;
  20542. t['dieresis'] = 333;
  20543. t['ring'] = 333;
  20544. t['cedilla'] = 333;
  20545. t['hungarumlaut'] = 333;
  20546. t['ogonek'] = 333;
  20547. t['caron'] = 333;
  20548. t['emdash'] = 889;
  20549. t['AE'] = 889;
  20550. t['ordfeminine'] = 276;
  20551. t['Lslash'] = 556;
  20552. t['Oslash'] = 722;
  20553. t['OE'] = 944;
  20554. t['ordmasculine'] = 310;
  20555. t['ae'] = 667;
  20556. t['dotlessi'] = 278;
  20557. t['lslash'] = 278;
  20558. t['oslash'] = 500;
  20559. t['oe'] = 667;
  20560. t['germandbls'] = 500;
  20561. t['Idieresis'] = 333;
  20562. t['eacute'] = 444;
  20563. t['abreve'] = 500;
  20564. t['uhungarumlaut'] = 500;
  20565. t['ecaron'] = 444;
  20566. t['Ydieresis'] = 556;
  20567. t['divide'] = 675;
  20568. t['Yacute'] = 556;
  20569. t['Acircumflex'] = 611;
  20570. t['aacute'] = 500;
  20571. t['Ucircumflex'] = 722;
  20572. t['yacute'] = 444;
  20573. t['scommaaccent'] = 389;
  20574. t['ecircumflex'] = 444;
  20575. t['Uring'] = 722;
  20576. t['Udieresis'] = 722;
  20577. t['aogonek'] = 500;
  20578. t['Uacute'] = 722;
  20579. t['uogonek'] = 500;
  20580. t['Edieresis'] = 611;
  20581. t['Dcroat'] = 722;
  20582. t['commaaccent'] = 250;
  20583. t['copyright'] = 760;
  20584. t['Emacron'] = 611;
  20585. t['ccaron'] = 444;
  20586. t['aring'] = 500;
  20587. t['Ncommaaccent'] = 667;
  20588. t['lacute'] = 278;
  20589. t['agrave'] = 500;
  20590. t['Tcommaaccent'] = 556;
  20591. t['Cacute'] = 667;
  20592. t['atilde'] = 500;
  20593. t['Edotaccent'] = 611;
  20594. t['scaron'] = 389;
  20595. t['scedilla'] = 389;
  20596. t['iacute'] = 278;
  20597. t['lozenge'] = 471;
  20598. t['Rcaron'] = 611;
  20599. t['Gcommaaccent'] = 722;
  20600. t['ucircumflex'] = 500;
  20601. t['acircumflex'] = 500;
  20602. t['Amacron'] = 611;
  20603. t['rcaron'] = 389;
  20604. t['ccedilla'] = 444;
  20605. t['Zdotaccent'] = 556;
  20606. t['Thorn'] = 611;
  20607. t['Omacron'] = 722;
  20608. t['Racute'] = 611;
  20609. t['Sacute'] = 500;
  20610. t['dcaron'] = 544;
  20611. t['Umacron'] = 722;
  20612. t['uring'] = 500;
  20613. t['threesuperior'] = 300;
  20614. t['Ograve'] = 722;
  20615. t['Agrave'] = 611;
  20616. t['Abreve'] = 611;
  20617. t['multiply'] = 675;
  20618. t['uacute'] = 500;
  20619. t['Tcaron'] = 556;
  20620. t['partialdiff'] = 476;
  20621. t['ydieresis'] = 444;
  20622. t['Nacute'] = 667;
  20623. t['icircumflex'] = 278;
  20624. t['Ecircumflex'] = 611;
  20625. t['adieresis'] = 500;
  20626. t['edieresis'] = 444;
  20627. t['cacute'] = 444;
  20628. t['nacute'] = 500;
  20629. t['umacron'] = 500;
  20630. t['Ncaron'] = 667;
  20631. t['Iacute'] = 333;
  20632. t['plusminus'] = 675;
  20633. t['brokenbar'] = 275;
  20634. t['registered'] = 760;
  20635. t['Gbreve'] = 722;
  20636. t['Idotaccent'] = 333;
  20637. t['summation'] = 600;
  20638. t['Egrave'] = 611;
  20639. t['racute'] = 389;
  20640. t['omacron'] = 500;
  20641. t['Zacute'] = 556;
  20642. t['Zcaron'] = 556;
  20643. t['greaterequal'] = 549;
  20644. t['Eth'] = 722;
  20645. t['Ccedilla'] = 667;
  20646. t['lcommaaccent'] = 278;
  20647. t['tcaron'] = 300;
  20648. t['eogonek'] = 444;
  20649. t['Uogonek'] = 722;
  20650. t['Aacute'] = 611;
  20651. t['Adieresis'] = 611;
  20652. t['egrave'] = 444;
  20653. t['zacute'] = 389;
  20654. t['iogonek'] = 278;
  20655. t['Oacute'] = 722;
  20656. t['oacute'] = 500;
  20657. t['amacron'] = 500;
  20658. t['sacute'] = 389;
  20659. t['idieresis'] = 278;
  20660. t['Ocircumflex'] = 722;
  20661. t['Ugrave'] = 722;
  20662. t['Delta'] = 612;
  20663. t['thorn'] = 500;
  20664. t['twosuperior'] = 300;
  20665. t['Odieresis'] = 722;
  20666. t['mu'] = 500;
  20667. t['igrave'] = 278;
  20668. t['ohungarumlaut'] = 500;
  20669. t['Eogonek'] = 611;
  20670. t['dcroat'] = 500;
  20671. t['threequarters'] = 750;
  20672. t['Scedilla'] = 500;
  20673. t['lcaron'] = 300;
  20674. t['Kcommaaccent'] = 667;
  20675. t['Lacute'] = 556;
  20676. t['trademark'] = 980;
  20677. t['edotaccent'] = 444;
  20678. t['Igrave'] = 333;
  20679. t['Imacron'] = 333;
  20680. t['Lcaron'] = 611;
  20681. t['onehalf'] = 750;
  20682. t['lessequal'] = 549;
  20683. t['ocircumflex'] = 500;
  20684. t['ntilde'] = 500;
  20685. t['Uhungarumlaut'] = 722;
  20686. t['Eacute'] = 611;
  20687. t['emacron'] = 444;
  20688. t['gbreve'] = 500;
  20689. t['onequarter'] = 750;
  20690. t['Scaron'] = 500;
  20691. t['Scommaaccent'] = 500;
  20692. t['Ohungarumlaut'] = 722;
  20693. t['degree'] = 400;
  20694. t['ograve'] = 500;
  20695. t['Ccaron'] = 667;
  20696. t['ugrave'] = 500;
  20697. t['radical'] = 453;
  20698. t['Dcaron'] = 722;
  20699. t['rcommaaccent'] = 389;
  20700. t['Ntilde'] = 667;
  20701. t['otilde'] = 500;
  20702. t['Rcommaaccent'] = 611;
  20703. t['Lcommaaccent'] = 556;
  20704. t['Atilde'] = 611;
  20705. t['Aogonek'] = 611;
  20706. t['Aring'] = 611;
  20707. t['Otilde'] = 722;
  20708. t['zdotaccent'] = 389;
  20709. t['Ecaron'] = 611;
  20710. t['Iogonek'] = 333;
  20711. t['kcommaaccent'] = 444;
  20712. t['minus'] = 675;
  20713. t['Icircumflex'] = 333;
  20714. t['ncaron'] = 500;
  20715. t['tcommaaccent'] = 278;
  20716. t['logicalnot'] = 675;
  20717. t['odieresis'] = 500;
  20718. t['udieresis'] = 500;
  20719. t['notequal'] = 549;
  20720. t['gcommaaccent'] = 500;
  20721. t['eth'] = 500;
  20722. t['zcaron'] = 389;
  20723. t['ncommaaccent'] = 500;
  20724. t['onesuperior'] = 300;
  20725. t['imacron'] = 278;
  20726. t['Euro'] = 500;
  20727. });
  20728. t['ZapfDingbats'] = getLookupTableFactory(function (t) {
  20729. t['space'] = 278;
  20730. t['a1'] = 974;
  20731. t['a2'] = 961;
  20732. t['a202'] = 974;
  20733. t['a3'] = 980;
  20734. t['a4'] = 719;
  20735. t['a5'] = 789;
  20736. t['a119'] = 790;
  20737. t['a118'] = 791;
  20738. t['a117'] = 690;
  20739. t['a11'] = 960;
  20740. t['a12'] = 939;
  20741. t['a13'] = 549;
  20742. t['a14'] = 855;
  20743. t['a15'] = 911;
  20744. t['a16'] = 933;
  20745. t['a105'] = 911;
  20746. t['a17'] = 945;
  20747. t['a18'] = 974;
  20748. t['a19'] = 755;
  20749. t['a20'] = 846;
  20750. t['a21'] = 762;
  20751. t['a22'] = 761;
  20752. t['a23'] = 571;
  20753. t['a24'] = 677;
  20754. t['a25'] = 763;
  20755. t['a26'] = 760;
  20756. t['a27'] = 759;
  20757. t['a28'] = 754;
  20758. t['a6'] = 494;
  20759. t['a7'] = 552;
  20760. t['a8'] = 537;
  20761. t['a9'] = 577;
  20762. t['a10'] = 692;
  20763. t['a29'] = 786;
  20764. t['a30'] = 788;
  20765. t['a31'] = 788;
  20766. t['a32'] = 790;
  20767. t['a33'] = 793;
  20768. t['a34'] = 794;
  20769. t['a35'] = 816;
  20770. t['a36'] = 823;
  20771. t['a37'] = 789;
  20772. t['a38'] = 841;
  20773. t['a39'] = 823;
  20774. t['a40'] = 833;
  20775. t['a41'] = 816;
  20776. t['a42'] = 831;
  20777. t['a43'] = 923;
  20778. t['a44'] = 744;
  20779. t['a45'] = 723;
  20780. t['a46'] = 749;
  20781. t['a47'] = 790;
  20782. t['a48'] = 792;
  20783. t['a49'] = 695;
  20784. t['a50'] = 776;
  20785. t['a51'] = 768;
  20786. t['a52'] = 792;
  20787. t['a53'] = 759;
  20788. t['a54'] = 707;
  20789. t['a55'] = 708;
  20790. t['a56'] = 682;
  20791. t['a57'] = 701;
  20792. t['a58'] = 826;
  20793. t['a59'] = 815;
  20794. t['a60'] = 789;
  20795. t['a61'] = 789;
  20796. t['a62'] = 707;
  20797. t['a63'] = 687;
  20798. t['a64'] = 696;
  20799. t['a65'] = 689;
  20800. t['a66'] = 786;
  20801. t['a67'] = 787;
  20802. t['a68'] = 713;
  20803. t['a69'] = 791;
  20804. t['a70'] = 785;
  20805. t['a71'] = 791;
  20806. t['a72'] = 873;
  20807. t['a73'] = 761;
  20808. t['a74'] = 762;
  20809. t['a203'] = 762;
  20810. t['a75'] = 759;
  20811. t['a204'] = 759;
  20812. t['a76'] = 892;
  20813. t['a77'] = 892;
  20814. t['a78'] = 788;
  20815. t['a79'] = 784;
  20816. t['a81'] = 438;
  20817. t['a82'] = 138;
  20818. t['a83'] = 277;
  20819. t['a84'] = 415;
  20820. t['a97'] = 392;
  20821. t['a98'] = 392;
  20822. t['a99'] = 668;
  20823. t['a100'] = 668;
  20824. t['a89'] = 390;
  20825. t['a90'] = 390;
  20826. t['a93'] = 317;
  20827. t['a94'] = 317;
  20828. t['a91'] = 276;
  20829. t['a92'] = 276;
  20830. t['a205'] = 509;
  20831. t['a85'] = 509;
  20832. t['a206'] = 410;
  20833. t['a86'] = 410;
  20834. t['a87'] = 234;
  20835. t['a88'] = 234;
  20836. t['a95'] = 334;
  20837. t['a96'] = 334;
  20838. t['a101'] = 732;
  20839. t['a102'] = 544;
  20840. t['a103'] = 544;
  20841. t['a104'] = 910;
  20842. t['a106'] = 667;
  20843. t['a107'] = 760;
  20844. t['a108'] = 760;
  20845. t['a112'] = 776;
  20846. t['a111'] = 595;
  20847. t['a110'] = 694;
  20848. t['a109'] = 626;
  20849. t['a120'] = 788;
  20850. t['a121'] = 788;
  20851. t['a122'] = 788;
  20852. t['a123'] = 788;
  20853. t['a124'] = 788;
  20854. t['a125'] = 788;
  20855. t['a126'] = 788;
  20856. t['a127'] = 788;
  20857. t['a128'] = 788;
  20858. t['a129'] = 788;
  20859. t['a130'] = 788;
  20860. t['a131'] = 788;
  20861. t['a132'] = 788;
  20862. t['a133'] = 788;
  20863. t['a134'] = 788;
  20864. t['a135'] = 788;
  20865. t['a136'] = 788;
  20866. t['a137'] = 788;
  20867. t['a138'] = 788;
  20868. t['a139'] = 788;
  20869. t['a140'] = 788;
  20870. t['a141'] = 788;
  20871. t['a142'] = 788;
  20872. t['a143'] = 788;
  20873. t['a144'] = 788;
  20874. t['a145'] = 788;
  20875. t['a146'] = 788;
  20876. t['a147'] = 788;
  20877. t['a148'] = 788;
  20878. t['a149'] = 788;
  20879. t['a150'] = 788;
  20880. t['a151'] = 788;
  20881. t['a152'] = 788;
  20882. t['a153'] = 788;
  20883. t['a154'] = 788;
  20884. t['a155'] = 788;
  20885. t['a156'] = 788;
  20886. t['a157'] = 788;
  20887. t['a158'] = 788;
  20888. t['a159'] = 788;
  20889. t['a160'] = 894;
  20890. t['a161'] = 838;
  20891. t['a163'] = 1016;
  20892. t['a164'] = 458;
  20893. t['a196'] = 748;
  20894. t['a165'] = 924;
  20895. t['a192'] = 748;
  20896. t['a166'] = 918;
  20897. t['a167'] = 927;
  20898. t['a168'] = 928;
  20899. t['a169'] = 928;
  20900. t['a170'] = 834;
  20901. t['a171'] = 873;
  20902. t['a172'] = 828;
  20903. t['a173'] = 924;
  20904. t['a162'] = 924;
  20905. t['a174'] = 917;
  20906. t['a175'] = 930;
  20907. t['a176'] = 931;
  20908. t['a177'] = 463;
  20909. t['a178'] = 883;
  20910. t['a179'] = 836;
  20911. t['a193'] = 836;
  20912. t['a180'] = 867;
  20913. t['a199'] = 867;
  20914. t['a181'] = 696;
  20915. t['a200'] = 696;
  20916. t['a182'] = 874;
  20917. t['a201'] = 874;
  20918. t['a183'] = 760;
  20919. t['a184'] = 946;
  20920. t['a197'] = 771;
  20921. t['a185'] = 865;
  20922. t['a194'] = 771;
  20923. t['a198'] = 888;
  20924. t['a186'] = 967;
  20925. t['a195'] = 888;
  20926. t['a187'] = 831;
  20927. t['a188'] = 873;
  20928. t['a189'] = 927;
  20929. t['a190'] = 970;
  20930. t['a191'] = 918;
  20931. });
  20932. });
  20933. exports.getMetrics = getMetrics;
  20934. }));
  20935. (function (root, factory) {
  20936. factory(root.pdfjsCoreMurmurHash3 = {}, root.pdfjsSharedUtil);
  20937. }(this, function (exports, sharedUtil) {
  20938. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  20939. var MurmurHash3_64 = function MurmurHash3_64Closure(seed) {
  20940. // Workaround for missing math precision in JS.
  20941. var MASK_HIGH = 0xffff0000;
  20942. var MASK_LOW = 0xffff;
  20943. function MurmurHash3_64(seed) {
  20944. var SEED = 0xc3d2e1f0;
  20945. this.h1 = seed ? seed & 0xffffffff : SEED;
  20946. this.h2 = seed ? seed & 0xffffffff : SEED;
  20947. }
  20948. var alwaysUseUint32ArrayView = false;
  20949. // old webkits have issues with non-aligned arrays
  20950. try {
  20951. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  20952. } catch (e) {
  20953. alwaysUseUint32ArrayView = true;
  20954. }
  20955. MurmurHash3_64.prototype = {
  20956. update: function MurmurHash3_64_update(input) {
  20957. var useUint32ArrayView = alwaysUseUint32ArrayView;
  20958. var i;
  20959. if (typeof input === 'string') {
  20960. var data = new Uint8Array(input.length * 2);
  20961. var length = 0;
  20962. for (i = 0; i < input.length; i++) {
  20963. var code = input.charCodeAt(i);
  20964. if (code <= 0xff) {
  20965. data[length++] = code;
  20966. } else {
  20967. data[length++] = code >>> 8;
  20968. data[length++] = code & 0xff;
  20969. }
  20970. }
  20971. } else if (input instanceof Uint8Array) {
  20972. data = input;
  20973. length = data.length;
  20974. } else if (typeof input === 'object' && 'length' in input) {
  20975. // processing regular arrays as well, e.g. for IE9
  20976. data = input;
  20977. length = data.length;
  20978. useUint32ArrayView = true;
  20979. } else {
  20980. throw new Error('Wrong data format in MurmurHash3_64_update. ' + 'Input must be a string or array.');
  20981. }
  20982. var blockCounts = length >> 2;
  20983. var tailLength = length - blockCounts * 4;
  20984. // we don't care about endianness here
  20985. var dataUint32 = useUint32ArrayView ? new Uint32ArrayView(data, blockCounts) : new Uint32Array(data.buffer, 0, blockCounts);
  20986. var k1 = 0;
  20987. var k2 = 0;
  20988. var h1 = this.h1;
  20989. var h2 = this.h2;
  20990. var C1 = 0xcc9e2d51;
  20991. var C2 = 0x1b873593;
  20992. var C1_LOW = C1 & MASK_LOW;
  20993. var C2_LOW = C2 & MASK_LOW;
  20994. for (i = 0; i < blockCounts; i++) {
  20995. if (i & 1) {
  20996. k1 = dataUint32[i];
  20997. k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
  20998. k1 = k1 << 15 | k1 >>> 17;
  20999. k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
  21000. h1 ^= k1;
  21001. h1 = h1 << 13 | h1 >>> 19;
  21002. h1 = h1 * 5 + 0xe6546b64;
  21003. } else {
  21004. k2 = dataUint32[i];
  21005. k2 = k2 * C1 & MASK_HIGH | k2 * C1_LOW & MASK_LOW;
  21006. k2 = k2 << 15 | k2 >>> 17;
  21007. k2 = k2 * C2 & MASK_HIGH | k2 * C2_LOW & MASK_LOW;
  21008. h2 ^= k2;
  21009. h2 = h2 << 13 | h2 >>> 19;
  21010. h2 = h2 * 5 + 0xe6546b64;
  21011. }
  21012. }
  21013. k1 = 0;
  21014. switch (tailLength) {
  21015. case 3:
  21016. k1 ^= data[blockCounts * 4 + 2] << 16;
  21017. case 2:
  21018. k1 ^= data[blockCounts * 4 + 1] << 8;
  21019. case 1:
  21020. k1 ^= data[blockCounts * 4];
  21021. k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
  21022. k1 = k1 << 15 | k1 >>> 17;
  21023. k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
  21024. if (blockCounts & 1) {
  21025. h1 ^= k1;
  21026. } else {
  21027. h2 ^= k1;
  21028. }
  21029. }
  21030. this.h1 = h1;
  21031. this.h2 = h2;
  21032. return this;
  21033. },
  21034. hexdigest: function MurmurHash3_64_hexdigest() {
  21035. var h1 = this.h1;
  21036. var h2 = this.h2;
  21037. h1 ^= h2 >>> 1;
  21038. h1 = h1 * 0xed558ccd & MASK_HIGH | h1 * 0x8ccd & MASK_LOW;
  21039. h2 = h2 * 0xff51afd7 & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16;
  21040. h1 ^= h2 >>> 1;
  21041. h1 = h1 * 0x1a85ec53 & MASK_HIGH | h1 * 0xec53 & MASK_LOW;
  21042. h2 = h2 * 0xc4ceb9fe & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16;
  21043. h1 ^= h2 >>> 1;
  21044. for (var i = 0, arr = [
  21045. h1,
  21046. h2
  21047. ], str = ''; i < arr.length; i++) {
  21048. var hex = (arr[i] >>> 0).toString(16);
  21049. while (hex.length < 8) {
  21050. hex = '0' + hex;
  21051. }
  21052. str += hex;
  21053. }
  21054. return str;
  21055. }
  21056. };
  21057. return MurmurHash3_64;
  21058. }();
  21059. exports.MurmurHash3_64 = MurmurHash3_64;
  21060. }));
  21061. (function (root, factory) {
  21062. factory(root.pdfjsCorePrimitives = {}, root.pdfjsSharedUtil);
  21063. }(this, function (exports, sharedUtil) {
  21064. var isArray = sharedUtil.isArray;
  21065. var Name = function NameClosure() {
  21066. function Name(name) {
  21067. this.name = name;
  21068. }
  21069. Name.prototype = {};
  21070. var nameCache = Object.create(null);
  21071. Name.get = function Name_get(name) {
  21072. var nameValue = nameCache[name];
  21073. return nameValue ? nameValue : nameCache[name] = new Name(name);
  21074. };
  21075. return Name;
  21076. }();
  21077. var Cmd = function CmdClosure() {
  21078. function Cmd(cmd) {
  21079. this.cmd = cmd;
  21080. }
  21081. Cmd.prototype = {};
  21082. var cmdCache = Object.create(null);
  21083. Cmd.get = function Cmd_get(cmd) {
  21084. var cmdValue = cmdCache[cmd];
  21085. return cmdValue ? cmdValue : cmdCache[cmd] = new Cmd(cmd);
  21086. };
  21087. return Cmd;
  21088. }();
  21089. var Dict = function DictClosure() {
  21090. var nonSerializable = function nonSerializableClosure() {
  21091. return nonSerializable;
  21092. };
  21093. // creating closure on some variable
  21094. // xref is optional
  21095. function Dict(xref) {
  21096. // Map should only be used internally, use functions below to access.
  21097. this.map = Object.create(null);
  21098. this.xref = xref;
  21099. this.objId = null;
  21100. this.suppressEncryption = false;
  21101. this.__nonSerializable__ = nonSerializable;
  21102. }
  21103. // disable cloning of the Dict
  21104. Dict.prototype = {
  21105. assignXref: function Dict_assignXref(newXref) {
  21106. this.xref = newXref;
  21107. },
  21108. // automatically dereferences Ref objects
  21109. get: function Dict_get(key1, key2, key3) {
  21110. var value;
  21111. var xref = this.xref, suppressEncryption = this.suppressEncryption;
  21112. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map || typeof key2 === 'undefined') {
  21113. return xref ? xref.fetchIfRef(value, suppressEncryption) : value;
  21114. }
  21115. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map || typeof key3 === 'undefined') {
  21116. return xref ? xref.fetchIfRef(value, suppressEncryption) : value;
  21117. }
  21118. value = this.map[key3] || null;
  21119. return xref ? xref.fetchIfRef(value, suppressEncryption) : value;
  21120. },
  21121. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  21122. getAsync: function Dict_getAsync(key1, key2, key3) {
  21123. var value;
  21124. var xref = this.xref, suppressEncryption = this.suppressEncryption;
  21125. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map || typeof key2 === 'undefined') {
  21126. if (xref) {
  21127. return xref.fetchIfRefAsync(value, suppressEncryption);
  21128. }
  21129. return Promise.resolve(value);
  21130. }
  21131. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map || typeof key3 === 'undefined') {
  21132. if (xref) {
  21133. return xref.fetchIfRefAsync(value, suppressEncryption);
  21134. }
  21135. return Promise.resolve(value);
  21136. }
  21137. value = this.map[key3] || null;
  21138. if (xref) {
  21139. return xref.fetchIfRefAsync(value, suppressEncryption);
  21140. }
  21141. return Promise.resolve(value);
  21142. },
  21143. // Same as get(), but dereferences all elements if the result is an Array.
  21144. getArray: function Dict_getArray(key1, key2, key3) {
  21145. var value = this.get(key1, key2, key3);
  21146. var xref = this.xref, suppressEncryption = this.suppressEncryption;
  21147. if (!isArray(value) || !xref) {
  21148. return value;
  21149. }
  21150. value = value.slice();
  21151. // Ensure that we don't modify the Dict data.
  21152. for (var i = 0, ii = value.length; i < ii; i++) {
  21153. if (!isRef(value[i])) {
  21154. continue;
  21155. }
  21156. value[i] = xref.fetch(value[i], suppressEncryption);
  21157. }
  21158. return value;
  21159. },
  21160. // no dereferencing
  21161. getRaw: function Dict_getRaw(key) {
  21162. return this.map[key];
  21163. },
  21164. getKeys: function Dict_getKeys() {
  21165. return Object.keys(this.map);
  21166. },
  21167. set: function Dict_set(key, value) {
  21168. this.map[key] = value;
  21169. },
  21170. has: function Dict_has(key) {
  21171. return key in this.map;
  21172. },
  21173. forEach: function Dict_forEach(callback) {
  21174. for (var key in this.map) {
  21175. callback(key, this.get(key));
  21176. }
  21177. }
  21178. };
  21179. Dict.empty = new Dict(null);
  21180. Dict.merge = function Dict_merge(xref, dictArray) {
  21181. var mergedDict = new Dict(xref);
  21182. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  21183. var dict = dictArray[i];
  21184. if (!isDict(dict)) {
  21185. continue;
  21186. }
  21187. for (var keyName in dict.map) {
  21188. if (mergedDict.map[keyName]) {
  21189. continue;
  21190. }
  21191. mergedDict.map[keyName] = dict.map[keyName];
  21192. }
  21193. }
  21194. return mergedDict;
  21195. };
  21196. return Dict;
  21197. }();
  21198. var Ref = function RefClosure() {
  21199. function Ref(num, gen) {
  21200. this.num = num;
  21201. this.gen = gen;
  21202. }
  21203. Ref.prototype = {
  21204. toString: function Ref_toString() {
  21205. // This function is hot, so we make the string as compact as possible.
  21206. // |this.gen| is almost always zero, so we treat that case specially.
  21207. var str = this.num + 'R';
  21208. if (this.gen !== 0) {
  21209. str += this.gen;
  21210. }
  21211. return str;
  21212. }
  21213. };
  21214. return Ref;
  21215. }();
  21216. // The reference is identified by number and generation.
  21217. // This structure stores only one instance of the reference.
  21218. var RefSet = function RefSetClosure() {
  21219. function RefSet() {
  21220. this.dict = Object.create(null);
  21221. }
  21222. RefSet.prototype = {
  21223. has: function RefSet_has(ref) {
  21224. return ref.toString() in this.dict;
  21225. },
  21226. put: function RefSet_put(ref) {
  21227. this.dict[ref.toString()] = true;
  21228. },
  21229. remove: function RefSet_remove(ref) {
  21230. delete this.dict[ref.toString()];
  21231. }
  21232. };
  21233. return RefSet;
  21234. }();
  21235. var RefSetCache = function RefSetCacheClosure() {
  21236. function RefSetCache() {
  21237. this.dict = Object.create(null);
  21238. }
  21239. RefSetCache.prototype = {
  21240. get: function RefSetCache_get(ref) {
  21241. return this.dict[ref.toString()];
  21242. },
  21243. has: function RefSetCache_has(ref) {
  21244. return ref.toString() in this.dict;
  21245. },
  21246. put: function RefSetCache_put(ref, obj) {
  21247. this.dict[ref.toString()] = obj;
  21248. },
  21249. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  21250. this.dict[ref.toString()] = this.get(aliasRef);
  21251. },
  21252. forEach: function RefSetCache_forEach(fn, thisArg) {
  21253. for (var i in this.dict) {
  21254. fn.call(thisArg, this.dict[i]);
  21255. }
  21256. },
  21257. clear: function RefSetCache_clear() {
  21258. this.dict = Object.create(null);
  21259. }
  21260. };
  21261. return RefSetCache;
  21262. }();
  21263. function isName(v, name) {
  21264. return v instanceof Name && (name === undefined || v.name === name);
  21265. }
  21266. function isCmd(v, cmd) {
  21267. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  21268. }
  21269. function isDict(v, type) {
  21270. return v instanceof Dict && (type === undefined || isName(v.get('Type'), type));
  21271. }
  21272. function isRef(v) {
  21273. return v instanceof Ref;
  21274. }
  21275. function isRefsEqual(v1, v2) {
  21276. return v1.num === v2.num && v1.gen === v2.gen;
  21277. }
  21278. function isStream(v) {
  21279. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  21280. }
  21281. exports.Cmd = Cmd;
  21282. exports.Dict = Dict;
  21283. exports.Name = Name;
  21284. exports.Ref = Ref;
  21285. exports.RefSet = RefSet;
  21286. exports.RefSetCache = RefSetCache;
  21287. exports.isCmd = isCmd;
  21288. exports.isDict = isDict;
  21289. exports.isName = isName;
  21290. exports.isRef = isRef;
  21291. exports.isRefsEqual = isRefsEqual;
  21292. exports.isStream = isStream;
  21293. }));
  21294. (function (root, factory) {
  21295. factory(root.pdfjsCoreStandardFonts = {}, root.pdfjsSharedUtil);
  21296. }(this, function (exports, sharedUtil) {
  21297. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  21298. /**
  21299. * Hold a map of decoded fonts and of the standard fourteen Type1
  21300. * fonts and their acronyms.
  21301. */
  21302. var getStdFontMap = getLookupTableFactory(function (t) {
  21303. t['ArialNarrow'] = 'Helvetica';
  21304. t['ArialNarrow-Bold'] = 'Helvetica-Bold';
  21305. t['ArialNarrow-BoldItalic'] = 'Helvetica-BoldOblique';
  21306. t['ArialNarrow-Italic'] = 'Helvetica-Oblique';
  21307. t['ArialBlack'] = 'Helvetica';
  21308. t['ArialBlack-Bold'] = 'Helvetica-Bold';
  21309. t['ArialBlack-BoldItalic'] = 'Helvetica-BoldOblique';
  21310. t['ArialBlack-Italic'] = 'Helvetica-Oblique';
  21311. t['Arial'] = 'Helvetica';
  21312. t['Arial-Bold'] = 'Helvetica-Bold';
  21313. t['Arial-BoldItalic'] = 'Helvetica-BoldOblique';
  21314. t['Arial-Italic'] = 'Helvetica-Oblique';
  21315. t['Arial-BoldItalicMT'] = 'Helvetica-BoldOblique';
  21316. t['Arial-BoldMT'] = 'Helvetica-Bold';
  21317. t['Arial-ItalicMT'] = 'Helvetica-Oblique';
  21318. t['ArialMT'] = 'Helvetica';
  21319. t['Courier-Bold'] = 'Courier-Bold';
  21320. t['Courier-BoldItalic'] = 'Courier-BoldOblique';
  21321. t['Courier-Italic'] = 'Courier-Oblique';
  21322. t['CourierNew'] = 'Courier';
  21323. t['CourierNew-Bold'] = 'Courier-Bold';
  21324. t['CourierNew-BoldItalic'] = 'Courier-BoldOblique';
  21325. t['CourierNew-Italic'] = 'Courier-Oblique';
  21326. t['CourierNewPS-BoldItalicMT'] = 'Courier-BoldOblique';
  21327. t['CourierNewPS-BoldMT'] = 'Courier-Bold';
  21328. t['CourierNewPS-ItalicMT'] = 'Courier-Oblique';
  21329. t['CourierNewPSMT'] = 'Courier';
  21330. t['Helvetica'] = 'Helvetica';
  21331. t['Helvetica-Bold'] = 'Helvetica-Bold';
  21332. t['Helvetica-BoldItalic'] = 'Helvetica-BoldOblique';
  21333. t['Helvetica-BoldOblique'] = 'Helvetica-BoldOblique';
  21334. t['Helvetica-Italic'] = 'Helvetica-Oblique';
  21335. t['Helvetica-Oblique'] = 'Helvetica-Oblique';
  21336. t['Symbol-Bold'] = 'Symbol';
  21337. t['Symbol-BoldItalic'] = 'Symbol';
  21338. t['Symbol-Italic'] = 'Symbol';
  21339. t['TimesNewRoman'] = 'Times-Roman';
  21340. t['TimesNewRoman-Bold'] = 'Times-Bold';
  21341. t['TimesNewRoman-BoldItalic'] = 'Times-BoldItalic';
  21342. t['TimesNewRoman-Italic'] = 'Times-Italic';
  21343. t['TimesNewRomanPS'] = 'Times-Roman';
  21344. t['TimesNewRomanPS-Bold'] = 'Times-Bold';
  21345. t['TimesNewRomanPS-BoldItalic'] = 'Times-BoldItalic';
  21346. t['TimesNewRomanPS-BoldItalicMT'] = 'Times-BoldItalic';
  21347. t['TimesNewRomanPS-BoldMT'] = 'Times-Bold';
  21348. t['TimesNewRomanPS-Italic'] = 'Times-Italic';
  21349. t['TimesNewRomanPS-ItalicMT'] = 'Times-Italic';
  21350. t['TimesNewRomanPSMT'] = 'Times-Roman';
  21351. t['TimesNewRomanPSMT-Bold'] = 'Times-Bold';
  21352. t['TimesNewRomanPSMT-BoldItalic'] = 'Times-BoldItalic';
  21353. t['TimesNewRomanPSMT-Italic'] = 'Times-Italic';
  21354. });
  21355. /**
  21356. * Holds the map of the non-standard fonts that might be included as
  21357. * a standard fonts without glyph data.
  21358. */
  21359. var getNonStdFontMap = getLookupTableFactory(function (t) {
  21360. t['CenturyGothic'] = 'Helvetica';
  21361. t['CenturyGothic-Bold'] = 'Helvetica-Bold';
  21362. t['CenturyGothic-BoldItalic'] = 'Helvetica-BoldOblique';
  21363. t['CenturyGothic-Italic'] = 'Helvetica-Oblique';
  21364. t['ComicSansMS'] = 'Comic Sans MS';
  21365. t['ComicSansMS-Bold'] = 'Comic Sans MS-Bold';
  21366. t['ComicSansMS-BoldItalic'] = 'Comic Sans MS-BoldItalic';
  21367. t['ComicSansMS-Italic'] = 'Comic Sans MS-Italic';
  21368. t['LucidaConsole'] = 'Courier';
  21369. t['LucidaConsole-Bold'] = 'Courier-Bold';
  21370. t['LucidaConsole-BoldItalic'] = 'Courier-BoldOblique';
  21371. t['LucidaConsole-Italic'] = 'Courier-Oblique';
  21372. t['MS-Gothic'] = 'MS Gothic';
  21373. t['MS-Gothic-Bold'] = 'MS Gothic-Bold';
  21374. t['MS-Gothic-BoldItalic'] = 'MS Gothic-BoldItalic';
  21375. t['MS-Gothic-Italic'] = 'MS Gothic-Italic';
  21376. t['MS-Mincho'] = 'MS Mincho';
  21377. t['MS-Mincho-Bold'] = 'MS Mincho-Bold';
  21378. t['MS-Mincho-BoldItalic'] = 'MS Mincho-BoldItalic';
  21379. t['MS-Mincho-Italic'] = 'MS Mincho-Italic';
  21380. t['MS-PGothic'] = 'MS PGothic';
  21381. t['MS-PGothic-Bold'] = 'MS PGothic-Bold';
  21382. t['MS-PGothic-BoldItalic'] = 'MS PGothic-BoldItalic';
  21383. t['MS-PGothic-Italic'] = 'MS PGothic-Italic';
  21384. t['MS-PMincho'] = 'MS PMincho';
  21385. t['MS-PMincho-Bold'] = 'MS PMincho-Bold';
  21386. t['MS-PMincho-BoldItalic'] = 'MS PMincho-BoldItalic';
  21387. t['MS-PMincho-Italic'] = 'MS PMincho-Italic';
  21388. t['Wingdings'] = 'ZapfDingbats';
  21389. });
  21390. var getSerifFonts = getLookupTableFactory(function (t) {
  21391. t['Adobe Jenson'] = true;
  21392. t['Adobe Text'] = true;
  21393. t['Albertus'] = true;
  21394. t['Aldus'] = true;
  21395. t['Alexandria'] = true;
  21396. t['Algerian'] = true;
  21397. t['American Typewriter'] = true;
  21398. t['Antiqua'] = true;
  21399. t['Apex'] = true;
  21400. t['Arno'] = true;
  21401. t['Aster'] = true;
  21402. t['Aurora'] = true;
  21403. t['Baskerville'] = true;
  21404. t['Bell'] = true;
  21405. t['Bembo'] = true;
  21406. t['Bembo Schoolbook'] = true;
  21407. t['Benguiat'] = true;
  21408. t['Berkeley Old Style'] = true;
  21409. t['Bernhard Modern'] = true;
  21410. t['Berthold City'] = true;
  21411. t['Bodoni'] = true;
  21412. t['Bauer Bodoni'] = true;
  21413. t['Book Antiqua'] = true;
  21414. t['Bookman'] = true;
  21415. t['Bordeaux Roman'] = true;
  21416. t['Californian FB'] = true;
  21417. t['Calisto'] = true;
  21418. t['Calvert'] = true;
  21419. t['Capitals'] = true;
  21420. t['Cambria'] = true;
  21421. t['Cartier'] = true;
  21422. t['Caslon'] = true;
  21423. t['Catull'] = true;
  21424. t['Centaur'] = true;
  21425. t['Century Old Style'] = true;
  21426. t['Century Schoolbook'] = true;
  21427. t['Chaparral'] = true;
  21428. t['Charis SIL'] = true;
  21429. t['Cheltenham'] = true;
  21430. t['Cholla Slab'] = true;
  21431. t['Clarendon'] = true;
  21432. t['Clearface'] = true;
  21433. t['Cochin'] = true;
  21434. t['Colonna'] = true;
  21435. t['Computer Modern'] = true;
  21436. t['Concrete Roman'] = true;
  21437. t['Constantia'] = true;
  21438. t['Cooper Black'] = true;
  21439. t['Corona'] = true;
  21440. t['Ecotype'] = true;
  21441. t['Egyptienne'] = true;
  21442. t['Elephant'] = true;
  21443. t['Excelsior'] = true;
  21444. t['Fairfield'] = true;
  21445. t['FF Scala'] = true;
  21446. t['Folkard'] = true;
  21447. t['Footlight'] = true;
  21448. t['FreeSerif'] = true;
  21449. t['Friz Quadrata'] = true;
  21450. t['Garamond'] = true;
  21451. t['Gentium'] = true;
  21452. t['Georgia'] = true;
  21453. t['Gloucester'] = true;
  21454. t['Goudy Old Style'] = true;
  21455. t['Goudy Schoolbook'] = true;
  21456. t['Goudy Pro Font'] = true;
  21457. t['Granjon'] = true;
  21458. t['Guardian Egyptian'] = true;
  21459. t['Heather'] = true;
  21460. t['Hercules'] = true;
  21461. t['High Tower Text'] = true;
  21462. t['Hiroshige'] = true;
  21463. t['Hoefler Text'] = true;
  21464. t['Humana Serif'] = true;
  21465. t['Imprint'] = true;
  21466. t['Ionic No. 5'] = true;
  21467. t['Janson'] = true;
  21468. t['Joanna'] = true;
  21469. t['Korinna'] = true;
  21470. t['Lexicon'] = true;
  21471. t['Liberation Serif'] = true;
  21472. t['Linux Libertine'] = true;
  21473. t['Literaturnaya'] = true;
  21474. t['Lucida'] = true;
  21475. t['Lucida Bright'] = true;
  21476. t['Melior'] = true;
  21477. t['Memphis'] = true;
  21478. t['Miller'] = true;
  21479. t['Minion'] = true;
  21480. t['Modern'] = true;
  21481. t['Mona Lisa'] = true;
  21482. t['Mrs Eaves'] = true;
  21483. t['MS Serif'] = true;
  21484. t['Museo Slab'] = true;
  21485. t['New York'] = true;
  21486. t['Nimbus Roman'] = true;
  21487. t['NPS Rawlinson Roadway'] = true;
  21488. t['Palatino'] = true;
  21489. t['Perpetua'] = true;
  21490. t['Plantin'] = true;
  21491. t['Plantin Schoolbook'] = true;
  21492. t['Playbill'] = true;
  21493. t['Poor Richard'] = true;
  21494. t['Rawlinson Roadway'] = true;
  21495. t['Renault'] = true;
  21496. t['Requiem'] = true;
  21497. t['Rockwell'] = true;
  21498. t['Roman'] = true;
  21499. t['Rotis Serif'] = true;
  21500. t['Sabon'] = true;
  21501. t['Scala'] = true;
  21502. t['Seagull'] = true;
  21503. t['Sistina'] = true;
  21504. t['Souvenir'] = true;
  21505. t['STIX'] = true;
  21506. t['Stone Informal'] = true;
  21507. t['Stone Serif'] = true;
  21508. t['Sylfaen'] = true;
  21509. t['Times'] = true;
  21510. t['Trajan'] = true;
  21511. t['Trinité'] = true;
  21512. t['Trump Mediaeval'] = true;
  21513. t['Utopia'] = true;
  21514. t['Vale Type'] = true;
  21515. t['Bitstream Vera'] = true;
  21516. t['Vera Serif'] = true;
  21517. t['Versailles'] = true;
  21518. t['Wanted'] = true;
  21519. t['Weiss'] = true;
  21520. t['Wide Latin'] = true;
  21521. t['Windsor'] = true;
  21522. t['XITS'] = true;
  21523. });
  21524. var getSymbolsFonts = getLookupTableFactory(function (t) {
  21525. t['Dingbats'] = true;
  21526. t['Symbol'] = true;
  21527. t['ZapfDingbats'] = true;
  21528. });
  21529. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID
  21530. // fonts, but does not embed the CID to GID mapping. The mapping is incomplete
  21531. // for all glyphs, but common for some set of the standard fonts.
  21532. var getGlyphMapForStandardFonts = getLookupTableFactory(function (t) {
  21533. t[2] = 10;
  21534. t[3] = 32;
  21535. t[4] = 33;
  21536. t[5] = 34;
  21537. t[6] = 35;
  21538. t[7] = 36;
  21539. t[8] = 37;
  21540. t[9] = 38;
  21541. t[10] = 39;
  21542. t[11] = 40;
  21543. t[12] = 41;
  21544. t[13] = 42;
  21545. t[14] = 43;
  21546. t[15] = 44;
  21547. t[16] = 45;
  21548. t[17] = 46;
  21549. t[18] = 47;
  21550. t[19] = 48;
  21551. t[20] = 49;
  21552. t[21] = 50;
  21553. t[22] = 51;
  21554. t[23] = 52;
  21555. t[24] = 53;
  21556. t[25] = 54;
  21557. t[26] = 55;
  21558. t[27] = 56;
  21559. t[28] = 57;
  21560. t[29] = 58;
  21561. t[30] = 894;
  21562. t[31] = 60;
  21563. t[32] = 61;
  21564. t[33] = 62;
  21565. t[34] = 63;
  21566. t[35] = 64;
  21567. t[36] = 65;
  21568. t[37] = 66;
  21569. t[38] = 67;
  21570. t[39] = 68;
  21571. t[40] = 69;
  21572. t[41] = 70;
  21573. t[42] = 71;
  21574. t[43] = 72;
  21575. t[44] = 73;
  21576. t[45] = 74;
  21577. t[46] = 75;
  21578. t[47] = 76;
  21579. t[48] = 77;
  21580. t[49] = 78;
  21581. t[50] = 79;
  21582. t[51] = 80;
  21583. t[52] = 81;
  21584. t[53] = 82;
  21585. t[54] = 83;
  21586. t[55] = 84;
  21587. t[56] = 85;
  21588. t[57] = 86;
  21589. t[58] = 87;
  21590. t[59] = 88;
  21591. t[60] = 89;
  21592. t[61] = 90;
  21593. t[62] = 91;
  21594. t[63] = 92;
  21595. t[64] = 93;
  21596. t[65] = 94;
  21597. t[66] = 95;
  21598. t[67] = 96;
  21599. t[68] = 97;
  21600. t[69] = 98;
  21601. t[70] = 99;
  21602. t[71] = 100;
  21603. t[72] = 101;
  21604. t[73] = 102;
  21605. t[74] = 103;
  21606. t[75] = 104;
  21607. t[76] = 105;
  21608. t[77] = 106;
  21609. t[78] = 107;
  21610. t[79] = 108;
  21611. t[80] = 109;
  21612. t[81] = 110;
  21613. t[82] = 111;
  21614. t[83] = 112;
  21615. t[84] = 113;
  21616. t[85] = 114;
  21617. t[86] = 115;
  21618. t[87] = 116;
  21619. t[88] = 117;
  21620. t[89] = 118;
  21621. t[90] = 119;
  21622. t[91] = 120;
  21623. t[92] = 121;
  21624. t[93] = 122;
  21625. t[94] = 123;
  21626. t[95] = 124;
  21627. t[96] = 125;
  21628. t[97] = 126;
  21629. t[98] = 196;
  21630. t[99] = 197;
  21631. t[100] = 199;
  21632. t[101] = 201;
  21633. t[102] = 209;
  21634. t[103] = 214;
  21635. t[104] = 220;
  21636. t[105] = 225;
  21637. t[106] = 224;
  21638. t[107] = 226;
  21639. t[108] = 228;
  21640. t[109] = 227;
  21641. t[110] = 229;
  21642. t[111] = 231;
  21643. t[112] = 233;
  21644. t[113] = 232;
  21645. t[114] = 234;
  21646. t[115] = 235;
  21647. t[116] = 237;
  21648. t[117] = 236;
  21649. t[118] = 238;
  21650. t[119] = 239;
  21651. t[120] = 241;
  21652. t[121] = 243;
  21653. t[122] = 242;
  21654. t[123] = 244;
  21655. t[124] = 246;
  21656. t[125] = 245;
  21657. t[126] = 250;
  21658. t[127] = 249;
  21659. t[128] = 251;
  21660. t[129] = 252;
  21661. t[130] = 8224;
  21662. t[131] = 176;
  21663. t[132] = 162;
  21664. t[133] = 163;
  21665. t[134] = 167;
  21666. t[135] = 8226;
  21667. t[136] = 182;
  21668. t[137] = 223;
  21669. t[138] = 174;
  21670. t[139] = 169;
  21671. t[140] = 8482;
  21672. t[141] = 180;
  21673. t[142] = 168;
  21674. t[143] = 8800;
  21675. t[144] = 198;
  21676. t[145] = 216;
  21677. t[146] = 8734;
  21678. t[147] = 177;
  21679. t[148] = 8804;
  21680. t[149] = 8805;
  21681. t[150] = 165;
  21682. t[151] = 181;
  21683. t[152] = 8706;
  21684. t[153] = 8721;
  21685. t[154] = 8719;
  21686. t[156] = 8747;
  21687. t[157] = 170;
  21688. t[158] = 186;
  21689. t[159] = 8486;
  21690. t[160] = 230;
  21691. t[161] = 248;
  21692. t[162] = 191;
  21693. t[163] = 161;
  21694. t[164] = 172;
  21695. t[165] = 8730;
  21696. t[166] = 402;
  21697. t[167] = 8776;
  21698. t[168] = 8710;
  21699. t[169] = 171;
  21700. t[170] = 187;
  21701. t[171] = 8230;
  21702. t[210] = 218;
  21703. t[223] = 711;
  21704. t[224] = 321;
  21705. t[225] = 322;
  21706. t[227] = 353;
  21707. t[229] = 382;
  21708. t[234] = 253;
  21709. t[252] = 263;
  21710. t[253] = 268;
  21711. t[254] = 269;
  21712. t[258] = 258;
  21713. t[260] = 260;
  21714. t[261] = 261;
  21715. t[265] = 280;
  21716. t[266] = 281;
  21717. t[268] = 283;
  21718. t[269] = 313;
  21719. t[275] = 323;
  21720. t[276] = 324;
  21721. t[278] = 328;
  21722. t[284] = 345;
  21723. t[285] = 346;
  21724. t[286] = 347;
  21725. t[292] = 367;
  21726. t[295] = 377;
  21727. t[296] = 378;
  21728. t[298] = 380;
  21729. t[305] = 963;
  21730. t[306] = 964;
  21731. t[307] = 966;
  21732. t[308] = 8215;
  21733. t[309] = 8252;
  21734. t[310] = 8319;
  21735. t[311] = 8359;
  21736. t[312] = 8592;
  21737. t[313] = 8593;
  21738. t[337] = 9552;
  21739. t[493] = 1039;
  21740. t[494] = 1040;
  21741. t[705] = 1524;
  21742. t[706] = 8362;
  21743. t[710] = 64288;
  21744. t[711] = 64298;
  21745. t[759] = 1617;
  21746. t[761] = 1776;
  21747. t[763] = 1778;
  21748. t[775] = 1652;
  21749. t[777] = 1764;
  21750. t[778] = 1780;
  21751. t[779] = 1781;
  21752. t[780] = 1782;
  21753. t[782] = 771;
  21754. t[783] = 64726;
  21755. t[786] = 8363;
  21756. t[788] = 8532;
  21757. t[790] = 768;
  21758. t[791] = 769;
  21759. t[792] = 768;
  21760. t[795] = 803;
  21761. t[797] = 64336;
  21762. t[798] = 64337;
  21763. t[799] = 64342;
  21764. t[800] = 64343;
  21765. t[801] = 64344;
  21766. t[802] = 64345;
  21767. t[803] = 64362;
  21768. t[804] = 64363;
  21769. t[805] = 64364;
  21770. t[2424] = 7821;
  21771. t[2425] = 7822;
  21772. t[2426] = 7823;
  21773. t[2427] = 7824;
  21774. t[2428] = 7825;
  21775. t[2429] = 7826;
  21776. t[2430] = 7827;
  21777. t[2433] = 7682;
  21778. t[2678] = 8045;
  21779. t[2679] = 8046;
  21780. t[2830] = 1552;
  21781. t[2838] = 686;
  21782. t[2840] = 751;
  21783. t[2842] = 753;
  21784. t[2843] = 754;
  21785. t[2844] = 755;
  21786. t[2846] = 757;
  21787. t[2856] = 767;
  21788. t[2857] = 848;
  21789. t[2858] = 849;
  21790. t[2862] = 853;
  21791. t[2863] = 854;
  21792. t[2864] = 855;
  21793. t[2865] = 861;
  21794. t[2866] = 862;
  21795. t[2906] = 7460;
  21796. t[2908] = 7462;
  21797. t[2909] = 7463;
  21798. t[2910] = 7464;
  21799. t[2912] = 7466;
  21800. t[2913] = 7467;
  21801. t[2914] = 7468;
  21802. t[2916] = 7470;
  21803. t[2917] = 7471;
  21804. t[2918] = 7472;
  21805. t[2920] = 7474;
  21806. t[2921] = 7475;
  21807. t[2922] = 7476;
  21808. t[2924] = 7478;
  21809. t[2925] = 7479;
  21810. t[2926] = 7480;
  21811. t[2928] = 7482;
  21812. t[2929] = 7483;
  21813. t[2930] = 7484;
  21814. t[2932] = 7486;
  21815. t[2933] = 7487;
  21816. t[2934] = 7488;
  21817. t[2936] = 7490;
  21818. t[2937] = 7491;
  21819. t[2938] = 7492;
  21820. t[2940] = 7494;
  21821. t[2941] = 7495;
  21822. t[2942] = 7496;
  21823. t[2944] = 7498;
  21824. t[2946] = 7500;
  21825. t[2948] = 7502;
  21826. t[2950] = 7504;
  21827. t[2951] = 7505;
  21828. t[2952] = 7506;
  21829. t[2954] = 7508;
  21830. t[2955] = 7509;
  21831. t[2956] = 7510;
  21832. t[2958] = 7512;
  21833. t[2959] = 7513;
  21834. t[2960] = 7514;
  21835. t[2962] = 7516;
  21836. t[2963] = 7517;
  21837. t[2964] = 7518;
  21838. t[2966] = 7520;
  21839. t[2967] = 7521;
  21840. t[2968] = 7522;
  21841. t[2970] = 7524;
  21842. t[2971] = 7525;
  21843. t[2972] = 7526;
  21844. t[2974] = 7528;
  21845. t[2975] = 7529;
  21846. t[2976] = 7530;
  21847. t[2978] = 1537;
  21848. t[2979] = 1538;
  21849. t[2980] = 1539;
  21850. t[2982] = 1549;
  21851. t[2983] = 1551;
  21852. t[2984] = 1552;
  21853. t[2986] = 1554;
  21854. t[2987] = 1555;
  21855. t[2988] = 1556;
  21856. t[2990] = 1623;
  21857. t[2991] = 1624;
  21858. t[2995] = 1775;
  21859. t[2999] = 1791;
  21860. t[3002] = 64290;
  21861. t[3003] = 64291;
  21862. t[3004] = 64292;
  21863. t[3006] = 64294;
  21864. t[3007] = 64295;
  21865. t[3008] = 64296;
  21866. t[3011] = 1900;
  21867. t[3014] = 8223;
  21868. t[3015] = 8244;
  21869. t[3017] = 7532;
  21870. t[3018] = 7533;
  21871. t[3019] = 7534;
  21872. t[3075] = 7590;
  21873. t[3076] = 7591;
  21874. t[3079] = 7594;
  21875. t[3080] = 7595;
  21876. t[3083] = 7598;
  21877. t[3084] = 7599;
  21878. t[3087] = 7602;
  21879. t[3088] = 7603;
  21880. t[3091] = 7606;
  21881. t[3092] = 7607;
  21882. t[3095] = 7610;
  21883. t[3096] = 7611;
  21884. t[3099] = 7614;
  21885. t[3100] = 7615;
  21886. t[3103] = 7618;
  21887. t[3104] = 7619;
  21888. t[3107] = 8337;
  21889. t[3108] = 8338;
  21890. t[3116] = 1884;
  21891. t[3119] = 1885;
  21892. t[3120] = 1885;
  21893. t[3123] = 1886;
  21894. t[3124] = 1886;
  21895. t[3127] = 1887;
  21896. t[3128] = 1887;
  21897. t[3131] = 1888;
  21898. t[3132] = 1888;
  21899. t[3135] = 1889;
  21900. t[3136] = 1889;
  21901. t[3139] = 1890;
  21902. t[3140] = 1890;
  21903. t[3143] = 1891;
  21904. t[3144] = 1891;
  21905. t[3147] = 1892;
  21906. t[3148] = 1892;
  21907. t[3153] = 580;
  21908. t[3154] = 581;
  21909. t[3157] = 584;
  21910. t[3158] = 585;
  21911. t[3161] = 588;
  21912. t[3162] = 589;
  21913. t[3165] = 891;
  21914. t[3166] = 892;
  21915. t[3169] = 1274;
  21916. t[3170] = 1275;
  21917. t[3173] = 1278;
  21918. t[3174] = 1279;
  21919. t[3181] = 7622;
  21920. t[3182] = 7623;
  21921. t[3282] = 11799;
  21922. t[3316] = 578;
  21923. t[3379] = 42785;
  21924. t[3393] = 1159;
  21925. t[3416] = 8377;
  21926. });
  21927. // The glyph map for ArialBlack differs slightly from the glyph map used for
  21928. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  21929. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  21930. var getSupplementalGlyphMapForArialBlack = getLookupTableFactory(function (t) {
  21931. t[227] = 322;
  21932. t[264] = 261;
  21933. t[291] = 346;
  21934. });
  21935. exports.getStdFontMap = getStdFontMap;
  21936. exports.getNonStdFontMap = getNonStdFontMap;
  21937. exports.getSerifFonts = getSerifFonts;
  21938. exports.getSymbolsFonts = getSymbolsFonts;
  21939. exports.getGlyphMapForStandardFonts = getGlyphMapForStandardFonts;
  21940. exports.getSupplementalGlyphMapForArialBlack = getSupplementalGlyphMapForArialBlack;
  21941. }));
  21942. (function (root, factory) {
  21943. factory(root.pdfjsCoreUnicode = {}, root.pdfjsSharedUtil);
  21944. }(this, function (exports, sharedUtil) {
  21945. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  21946. // Some characters, e.g. copyrightserif, are mapped to the private use area
  21947. // and might not be displayed using standard fonts. Mapping/hacking well-known
  21948. // chars to the similar equivalents in the normal characters range.
  21949. var getSpecialPUASymbols = getLookupTableFactory(function (t) {
  21950. t[63721] = 0x00A9;
  21951. // copyrightsans (0xF8E9) => copyright
  21952. t[63193] = 0x00A9;
  21953. // copyrightserif (0xF6D9) => copyright
  21954. t[63720] = 0x00AE;
  21955. // registersans (0xF8E8) => registered
  21956. t[63194] = 0x00AE;
  21957. // registerserif (0xF6DA) => registered
  21958. t[63722] = 0x2122;
  21959. // trademarksans (0xF8EA) => trademark
  21960. t[63195] = 0x2122;
  21961. // trademarkserif (0xF6DB) => trademark
  21962. t[63729] = 0x23A7;
  21963. // bracelefttp (0xF8F1)
  21964. t[63730] = 0x23A8;
  21965. // braceleftmid (0xF8F2)
  21966. t[63731] = 0x23A9;
  21967. // braceleftbt (0xF8F3)
  21968. t[63740] = 0x23AB;
  21969. // bracerighttp (0xF8FC)
  21970. t[63741] = 0x23AC;
  21971. // bracerightmid (0xF8FD)
  21972. t[63742] = 0x23AD;
  21973. // bracerightbt (0xF8FE)
  21974. t[63726] = 0x23A1;
  21975. // bracketlefttp (0xF8EE)
  21976. t[63727] = 0x23A2;
  21977. // bracketleftex (0xF8EF)
  21978. t[63728] = 0x23A3;
  21979. // bracketleftbt (0xF8F0)
  21980. t[63737] = 0x23A4;
  21981. // bracketrighttp (0xF8F9)
  21982. t[63738] = 0x23A5;
  21983. // bracketrightex (0xF8FA)
  21984. t[63739] = 0x23A6;
  21985. // bracketrightbt (0xF8FB)
  21986. t[63723] = 0x239B;
  21987. // parenlefttp (0xF8EB)
  21988. t[63724] = 0x239C;
  21989. // parenleftex (0xF8EC)
  21990. t[63725] = 0x239D;
  21991. // parenleftbt (0xF8ED)
  21992. t[63734] = 0x239E;
  21993. // parenrighttp (0xF8F6)
  21994. t[63735] = 0x239F;
  21995. // parenrightex (0xF8F7)
  21996. t[63736] = 0x23A0;
  21997. });
  21998. // parenrightbt (0xF8F8)
  21999. function mapSpecialUnicodeValues(code) {
  22000. if (code >= 0xFFF0 && code <= 0xFFFF) {
  22001. // Specials unicode block.
  22002. return 0;
  22003. } else if (code >= 0xF600 && code <= 0xF8FF) {
  22004. return getSpecialPUASymbols()[code] || code;
  22005. }
  22006. return code;
  22007. }
  22008. function getUnicodeForGlyph(name, glyphsUnicodeMap) {
  22009. var unicode = glyphsUnicodeMap[name];
  22010. if (unicode !== undefined) {
  22011. return unicode;
  22012. }
  22013. if (!name) {
  22014. return -1;
  22015. }
  22016. // Try to recover valid Unicode values from 'uniXXXX'/'uXXXX{XX}' glyphs.
  22017. if (name[0] === 'u') {
  22018. var nameLen = name.length, hexStr;
  22019. if (nameLen === 7 && name[1] === 'n' && name[2] === 'i') {
  22020. // 'uniXXXX'
  22021. hexStr = name.substr(3);
  22022. } else if (nameLen >= 5 && nameLen <= 7) {
  22023. // 'uXXXX{XX}'
  22024. hexStr = name.substr(1);
  22025. } else {
  22026. return -1;
  22027. }
  22028. // Check for upper-case hexadecimal characters, to avoid false positives.
  22029. if (hexStr === hexStr.toUpperCase()) {
  22030. unicode = parseInt(hexStr, 16);
  22031. if (unicode >= 0) {
  22032. return unicode;
  22033. }
  22034. }
  22035. }
  22036. return -1;
  22037. }
  22038. var UnicodeRanges = [
  22039. {
  22040. 'begin': 0x0000,
  22041. 'end': 0x007F
  22042. },
  22043. // Basic Latin
  22044. {
  22045. 'begin': 0x0080,
  22046. 'end': 0x00FF
  22047. },
  22048. // Latin-1 Supplement
  22049. {
  22050. 'begin': 0x0100,
  22051. 'end': 0x017F
  22052. },
  22053. // Latin Extended-A
  22054. {
  22055. 'begin': 0x0180,
  22056. 'end': 0x024F
  22057. },
  22058. // Latin Extended-B
  22059. {
  22060. 'begin': 0x0250,
  22061. 'end': 0x02AF
  22062. },
  22063. // IPA Extensions
  22064. {
  22065. 'begin': 0x02B0,
  22066. 'end': 0x02FF
  22067. },
  22068. // Spacing Modifier Letters
  22069. {
  22070. 'begin': 0x0300,
  22071. 'end': 0x036F
  22072. },
  22073. // Combining Diacritical Marks
  22074. {
  22075. 'begin': 0x0370,
  22076. 'end': 0x03FF
  22077. },
  22078. // Greek and Coptic
  22079. {
  22080. 'begin': 0x2C80,
  22081. 'end': 0x2CFF
  22082. },
  22083. // Coptic
  22084. {
  22085. 'begin': 0x0400,
  22086. 'end': 0x04FF
  22087. },
  22088. // Cyrillic
  22089. {
  22090. 'begin': 0x0530,
  22091. 'end': 0x058F
  22092. },
  22093. // Armenian
  22094. {
  22095. 'begin': 0x0590,
  22096. 'end': 0x05FF
  22097. },
  22098. // Hebrew
  22099. {
  22100. 'begin': 0xA500,
  22101. 'end': 0xA63F
  22102. },
  22103. // Vai
  22104. {
  22105. 'begin': 0x0600,
  22106. 'end': 0x06FF
  22107. },
  22108. // Arabic
  22109. {
  22110. 'begin': 0x07C0,
  22111. 'end': 0x07FF
  22112. },
  22113. // NKo
  22114. {
  22115. 'begin': 0x0900,
  22116. 'end': 0x097F
  22117. },
  22118. // Devanagari
  22119. {
  22120. 'begin': 0x0980,
  22121. 'end': 0x09FF
  22122. },
  22123. // Bengali
  22124. {
  22125. 'begin': 0x0A00,
  22126. 'end': 0x0A7F
  22127. },
  22128. // Gurmukhi
  22129. {
  22130. 'begin': 0x0A80,
  22131. 'end': 0x0AFF
  22132. },
  22133. // Gujarati
  22134. {
  22135. 'begin': 0x0B00,
  22136. 'end': 0x0B7F
  22137. },
  22138. // Oriya
  22139. {
  22140. 'begin': 0x0B80,
  22141. 'end': 0x0BFF
  22142. },
  22143. // Tamil
  22144. {
  22145. 'begin': 0x0C00,
  22146. 'end': 0x0C7F
  22147. },
  22148. // Telugu
  22149. {
  22150. 'begin': 0x0C80,
  22151. 'end': 0x0CFF
  22152. },
  22153. // Kannada
  22154. {
  22155. 'begin': 0x0D00,
  22156. 'end': 0x0D7F
  22157. },
  22158. // Malayalam
  22159. {
  22160. 'begin': 0x0E00,
  22161. 'end': 0x0E7F
  22162. },
  22163. // Thai
  22164. {
  22165. 'begin': 0x0E80,
  22166. 'end': 0x0EFF
  22167. },
  22168. // Lao
  22169. {
  22170. 'begin': 0x10A0,
  22171. 'end': 0x10FF
  22172. },
  22173. // Georgian
  22174. {
  22175. 'begin': 0x1B00,
  22176. 'end': 0x1B7F
  22177. },
  22178. // Balinese
  22179. {
  22180. 'begin': 0x1100,
  22181. 'end': 0x11FF
  22182. },
  22183. // Hangul Jamo
  22184. {
  22185. 'begin': 0x1E00,
  22186. 'end': 0x1EFF
  22187. },
  22188. // Latin Extended Additional
  22189. {
  22190. 'begin': 0x1F00,
  22191. 'end': 0x1FFF
  22192. },
  22193. // Greek Extended
  22194. {
  22195. 'begin': 0x2000,
  22196. 'end': 0x206F
  22197. },
  22198. // General Punctuation
  22199. {
  22200. 'begin': 0x2070,
  22201. 'end': 0x209F
  22202. },
  22203. // Superscripts And Subscripts
  22204. {
  22205. 'begin': 0x20A0,
  22206. 'end': 0x20CF
  22207. },
  22208. // Currency Symbol
  22209. {
  22210. 'begin': 0x20D0,
  22211. 'end': 0x20FF
  22212. },
  22213. // Combining Diacritical Marks
  22214. {
  22215. 'begin': 0x2100,
  22216. 'end': 0x214F
  22217. },
  22218. // Letterlike Symbols
  22219. {
  22220. 'begin': 0x2150,
  22221. 'end': 0x218F
  22222. },
  22223. // Number Forms
  22224. {
  22225. 'begin': 0x2190,
  22226. 'end': 0x21FF
  22227. },
  22228. // Arrows
  22229. {
  22230. 'begin': 0x2200,
  22231. 'end': 0x22FF
  22232. },
  22233. // Mathematical Operators
  22234. {
  22235. 'begin': 0x2300,
  22236. 'end': 0x23FF
  22237. },
  22238. // Miscellaneous Technical
  22239. {
  22240. 'begin': 0x2400,
  22241. 'end': 0x243F
  22242. },
  22243. // Control Pictures
  22244. {
  22245. 'begin': 0x2440,
  22246. 'end': 0x245F
  22247. },
  22248. // Optical Character Recognition
  22249. {
  22250. 'begin': 0x2460,
  22251. 'end': 0x24FF
  22252. },
  22253. // Enclosed Alphanumerics
  22254. {
  22255. 'begin': 0x2500,
  22256. 'end': 0x257F
  22257. },
  22258. // Box Drawing
  22259. {
  22260. 'begin': 0x2580,
  22261. 'end': 0x259F
  22262. },
  22263. // Block Elements
  22264. {
  22265. 'begin': 0x25A0,
  22266. 'end': 0x25FF
  22267. },
  22268. // Geometric Shapes
  22269. {
  22270. 'begin': 0x2600,
  22271. 'end': 0x26FF
  22272. },
  22273. // Miscellaneous Symbols
  22274. {
  22275. 'begin': 0x2700,
  22276. 'end': 0x27BF
  22277. },
  22278. // Dingbats
  22279. {
  22280. 'begin': 0x3000,
  22281. 'end': 0x303F
  22282. },
  22283. // CJK Symbols And Punctuation
  22284. {
  22285. 'begin': 0x3040,
  22286. 'end': 0x309F
  22287. },
  22288. // Hiragana
  22289. {
  22290. 'begin': 0x30A0,
  22291. 'end': 0x30FF
  22292. },
  22293. // Katakana
  22294. {
  22295. 'begin': 0x3100,
  22296. 'end': 0x312F
  22297. },
  22298. // Bopomofo
  22299. {
  22300. 'begin': 0x3130,
  22301. 'end': 0x318F
  22302. },
  22303. // Hangul Compatibility Jamo
  22304. {
  22305. 'begin': 0xA840,
  22306. 'end': 0xA87F
  22307. },
  22308. // Phags-pa
  22309. {
  22310. 'begin': 0x3200,
  22311. 'end': 0x32FF
  22312. },
  22313. // Enclosed CJK Letters And Months
  22314. {
  22315. 'begin': 0x3300,
  22316. 'end': 0x33FF
  22317. },
  22318. // CJK Compatibility
  22319. {
  22320. 'begin': 0xAC00,
  22321. 'end': 0xD7AF
  22322. },
  22323. // Hangul Syllables
  22324. {
  22325. 'begin': 0xD800,
  22326. 'end': 0xDFFF
  22327. },
  22328. // Non-Plane 0 *
  22329. {
  22330. 'begin': 0x10900,
  22331. 'end': 0x1091F
  22332. },
  22333. // Phoenicia
  22334. {
  22335. 'begin': 0x4E00,
  22336. 'end': 0x9FFF
  22337. },
  22338. // CJK Unified Ideographs
  22339. {
  22340. 'begin': 0xE000,
  22341. 'end': 0xF8FF
  22342. },
  22343. // Private Use Area (plane 0)
  22344. {
  22345. 'begin': 0x31C0,
  22346. 'end': 0x31EF
  22347. },
  22348. // CJK Strokes
  22349. {
  22350. 'begin': 0xFB00,
  22351. 'end': 0xFB4F
  22352. },
  22353. // Alphabetic Presentation Forms
  22354. {
  22355. 'begin': 0xFB50,
  22356. 'end': 0xFDFF
  22357. },
  22358. // Arabic Presentation Forms-A
  22359. {
  22360. 'begin': 0xFE20,
  22361. 'end': 0xFE2F
  22362. },
  22363. // Combining Half Marks
  22364. {
  22365. 'begin': 0xFE10,
  22366. 'end': 0xFE1F
  22367. },
  22368. // Vertical Forms
  22369. {
  22370. 'begin': 0xFE50,
  22371. 'end': 0xFE6F
  22372. },
  22373. // Small Form Variants
  22374. {
  22375. 'begin': 0xFE70,
  22376. 'end': 0xFEFF
  22377. },
  22378. // Arabic Presentation Forms-B
  22379. {
  22380. 'begin': 0xFF00,
  22381. 'end': 0xFFEF
  22382. },
  22383. // Halfwidth And Fullwidth Forms
  22384. {
  22385. 'begin': 0xFFF0,
  22386. 'end': 0xFFFF
  22387. },
  22388. // Specials
  22389. {
  22390. 'begin': 0x0F00,
  22391. 'end': 0x0FFF
  22392. },
  22393. // Tibetan
  22394. {
  22395. 'begin': 0x0700,
  22396. 'end': 0x074F
  22397. },
  22398. // Syriac
  22399. {
  22400. 'begin': 0x0780,
  22401. 'end': 0x07BF
  22402. },
  22403. // Thaana
  22404. {
  22405. 'begin': 0x0D80,
  22406. 'end': 0x0DFF
  22407. },
  22408. // Sinhala
  22409. {
  22410. 'begin': 0x1000,
  22411. 'end': 0x109F
  22412. },
  22413. // Myanmar
  22414. {
  22415. 'begin': 0x1200,
  22416. 'end': 0x137F
  22417. },
  22418. // Ethiopic
  22419. {
  22420. 'begin': 0x13A0,
  22421. 'end': 0x13FF
  22422. },
  22423. // Cherokee
  22424. {
  22425. 'begin': 0x1400,
  22426. 'end': 0x167F
  22427. },
  22428. // Unified Canadian Aboriginal Syllabics
  22429. {
  22430. 'begin': 0x1680,
  22431. 'end': 0x169F
  22432. },
  22433. // Ogham
  22434. {
  22435. 'begin': 0x16A0,
  22436. 'end': 0x16FF
  22437. },
  22438. // Runic
  22439. {
  22440. 'begin': 0x1780,
  22441. 'end': 0x17FF
  22442. },
  22443. // Khmer
  22444. {
  22445. 'begin': 0x1800,
  22446. 'end': 0x18AF
  22447. },
  22448. // Mongolian
  22449. {
  22450. 'begin': 0x2800,
  22451. 'end': 0x28FF
  22452. },
  22453. // Braille Patterns
  22454. {
  22455. 'begin': 0xA000,
  22456. 'end': 0xA48F
  22457. },
  22458. // Yi Syllables
  22459. {
  22460. 'begin': 0x1700,
  22461. 'end': 0x171F
  22462. },
  22463. // Tagalog
  22464. {
  22465. 'begin': 0x10300,
  22466. 'end': 0x1032F
  22467. },
  22468. // Old Italic
  22469. {
  22470. 'begin': 0x10330,
  22471. 'end': 0x1034F
  22472. },
  22473. // Gothic
  22474. {
  22475. 'begin': 0x10400,
  22476. 'end': 0x1044F
  22477. },
  22478. // Deseret
  22479. {
  22480. 'begin': 0x1D000,
  22481. 'end': 0x1D0FF
  22482. },
  22483. // Byzantine Musical Symbols
  22484. {
  22485. 'begin': 0x1D400,
  22486. 'end': 0x1D7FF
  22487. },
  22488. // Mathematical Alphanumeric Symbols
  22489. {
  22490. 'begin': 0xFF000,
  22491. 'end': 0xFFFFD
  22492. },
  22493. // Private Use (plane 15)
  22494. {
  22495. 'begin': 0xFE00,
  22496. 'end': 0xFE0F
  22497. },
  22498. // Variation Selectors
  22499. {
  22500. 'begin': 0xE0000,
  22501. 'end': 0xE007F
  22502. },
  22503. // Tags
  22504. {
  22505. 'begin': 0x1900,
  22506. 'end': 0x194F
  22507. },
  22508. // Limbu
  22509. {
  22510. 'begin': 0x1950,
  22511. 'end': 0x197F
  22512. },
  22513. // Tai Le
  22514. {
  22515. 'begin': 0x1980,
  22516. 'end': 0x19DF
  22517. },
  22518. // New Tai Lue
  22519. {
  22520. 'begin': 0x1A00,
  22521. 'end': 0x1A1F
  22522. },
  22523. // Buginese
  22524. {
  22525. 'begin': 0x2C00,
  22526. 'end': 0x2C5F
  22527. },
  22528. // Glagolitic
  22529. {
  22530. 'begin': 0x2D30,
  22531. 'end': 0x2D7F
  22532. },
  22533. // Tifinagh
  22534. {
  22535. 'begin': 0x4DC0,
  22536. 'end': 0x4DFF
  22537. },
  22538. // Yijing Hexagram Symbols
  22539. {
  22540. 'begin': 0xA800,
  22541. 'end': 0xA82F
  22542. },
  22543. // Syloti Nagri
  22544. {
  22545. 'begin': 0x10000,
  22546. 'end': 0x1007F
  22547. },
  22548. // Linear B Syllabary
  22549. {
  22550. 'begin': 0x10140,
  22551. 'end': 0x1018F
  22552. },
  22553. // Ancient Greek Numbers
  22554. {
  22555. 'begin': 0x10380,
  22556. 'end': 0x1039F
  22557. },
  22558. // Ugaritic
  22559. {
  22560. 'begin': 0x103A0,
  22561. 'end': 0x103DF
  22562. },
  22563. // Old Persian
  22564. {
  22565. 'begin': 0x10450,
  22566. 'end': 0x1047F
  22567. },
  22568. // Shavian
  22569. {
  22570. 'begin': 0x10480,
  22571. 'end': 0x104AF
  22572. },
  22573. // Osmanya
  22574. {
  22575. 'begin': 0x10800,
  22576. 'end': 0x1083F
  22577. },
  22578. // Cypriot Syllabary
  22579. {
  22580. 'begin': 0x10A00,
  22581. 'end': 0x10A5F
  22582. },
  22583. // Kharoshthi
  22584. {
  22585. 'begin': 0x1D300,
  22586. 'end': 0x1D35F
  22587. },
  22588. // Tai Xuan Jing Symbols
  22589. {
  22590. 'begin': 0x12000,
  22591. 'end': 0x123FF
  22592. },
  22593. // Cuneiform
  22594. {
  22595. 'begin': 0x1D360,
  22596. 'end': 0x1D37F
  22597. },
  22598. // Counting Rod Numerals
  22599. {
  22600. 'begin': 0x1B80,
  22601. 'end': 0x1BBF
  22602. },
  22603. // Sundanese
  22604. {
  22605. 'begin': 0x1C00,
  22606. 'end': 0x1C4F
  22607. },
  22608. // Lepcha
  22609. {
  22610. 'begin': 0x1C50,
  22611. 'end': 0x1C7F
  22612. },
  22613. // Ol Chiki
  22614. {
  22615. 'begin': 0xA880,
  22616. 'end': 0xA8DF
  22617. },
  22618. // Saurashtra
  22619. {
  22620. 'begin': 0xA900,
  22621. 'end': 0xA92F
  22622. },
  22623. // Kayah Li
  22624. {
  22625. 'begin': 0xA930,
  22626. 'end': 0xA95F
  22627. },
  22628. // Rejang
  22629. {
  22630. 'begin': 0xAA00,
  22631. 'end': 0xAA5F
  22632. },
  22633. // Cham
  22634. {
  22635. 'begin': 0x10190,
  22636. 'end': 0x101CF
  22637. },
  22638. // Ancient Symbols
  22639. {
  22640. 'begin': 0x101D0,
  22641. 'end': 0x101FF
  22642. },
  22643. // Phaistos Disc
  22644. {
  22645. 'begin': 0x102A0,
  22646. 'end': 0x102DF
  22647. },
  22648. // Carian
  22649. {
  22650. 'begin': 0x1F030,
  22651. 'end': 0x1F09F
  22652. }
  22653. ];
  22654. // Domino Tiles
  22655. function getUnicodeRangeFor(value) {
  22656. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  22657. var range = UnicodeRanges[i];
  22658. if (value >= range.begin && value < range.end) {
  22659. return i;
  22660. }
  22661. }
  22662. return -1;
  22663. }
  22664. function isRTLRangeFor(value) {
  22665. var range = UnicodeRanges[13];
  22666. if (value >= range.begin && value < range.end) {
  22667. return true;
  22668. }
  22669. range = UnicodeRanges[11];
  22670. if (value >= range.begin && value < range.end) {
  22671. return true;
  22672. }
  22673. return false;
  22674. }
  22675. // The normalization table is obtained by filtering the Unicode characters
  22676. // database with <compat> entries.
  22677. var getNormalizedUnicodes = getLookupTableFactory(function (t) {
  22678. t['\u00A8'] = '\u0020\u0308';
  22679. t['\u00AF'] = '\u0020\u0304';
  22680. t['\u00B4'] = '\u0020\u0301';
  22681. t['\u00B5'] = '\u03BC';
  22682. t['\u00B8'] = '\u0020\u0327';
  22683. t['\u0132'] = '\u0049\u004A';
  22684. t['\u0133'] = '\u0069\u006A';
  22685. t['\u013F'] = '\u004C\u00B7';
  22686. t['\u0140'] = '\u006C\u00B7';
  22687. t['\u0149'] = '\u02BC\u006E';
  22688. t['\u017F'] = '\u0073';
  22689. t['\u01C4'] = '\u0044\u017D';
  22690. t['\u01C5'] = '\u0044\u017E';
  22691. t['\u01C6'] = '\u0064\u017E';
  22692. t['\u01C7'] = '\u004C\u004A';
  22693. t['\u01C8'] = '\u004C\u006A';
  22694. t['\u01C9'] = '\u006C\u006A';
  22695. t['\u01CA'] = '\u004E\u004A';
  22696. t['\u01CB'] = '\u004E\u006A';
  22697. t['\u01CC'] = '\u006E\u006A';
  22698. t['\u01F1'] = '\u0044\u005A';
  22699. t['\u01F2'] = '\u0044\u007A';
  22700. t['\u01F3'] = '\u0064\u007A';
  22701. t['\u02D8'] = '\u0020\u0306';
  22702. t['\u02D9'] = '\u0020\u0307';
  22703. t['\u02DA'] = '\u0020\u030A';
  22704. t['\u02DB'] = '\u0020\u0328';
  22705. t['\u02DC'] = '\u0020\u0303';
  22706. t['\u02DD'] = '\u0020\u030B';
  22707. t['\u037A'] = '\u0020\u0345';
  22708. t['\u0384'] = '\u0020\u0301';
  22709. t['\u03D0'] = '\u03B2';
  22710. t['\u03D1'] = '\u03B8';
  22711. t['\u03D2'] = '\u03A5';
  22712. t['\u03D5'] = '\u03C6';
  22713. t['\u03D6'] = '\u03C0';
  22714. t['\u03F0'] = '\u03BA';
  22715. t['\u03F1'] = '\u03C1';
  22716. t['\u03F2'] = '\u03C2';
  22717. t['\u03F4'] = '\u0398';
  22718. t['\u03F5'] = '\u03B5';
  22719. t['\u03F9'] = '\u03A3';
  22720. t['\u0587'] = '\u0565\u0582';
  22721. t['\u0675'] = '\u0627\u0674';
  22722. t['\u0676'] = '\u0648\u0674';
  22723. t['\u0677'] = '\u06C7\u0674';
  22724. t['\u0678'] = '\u064A\u0674';
  22725. t['\u0E33'] = '\u0E4D\u0E32';
  22726. t['\u0EB3'] = '\u0ECD\u0EB2';
  22727. t['\u0EDC'] = '\u0EAB\u0E99';
  22728. t['\u0EDD'] = '\u0EAB\u0EA1';
  22729. t['\u0F77'] = '\u0FB2\u0F81';
  22730. t['\u0F79'] = '\u0FB3\u0F81';
  22731. t['\u1E9A'] = '\u0061\u02BE';
  22732. t['\u1FBD'] = '\u0020\u0313';
  22733. t['\u1FBF'] = '\u0020\u0313';
  22734. t['\u1FC0'] = '\u0020\u0342';
  22735. t['\u1FFE'] = '\u0020\u0314';
  22736. t['\u2002'] = '\u0020';
  22737. t['\u2003'] = '\u0020';
  22738. t['\u2004'] = '\u0020';
  22739. t['\u2005'] = '\u0020';
  22740. t['\u2006'] = '\u0020';
  22741. t['\u2008'] = '\u0020';
  22742. t['\u2009'] = '\u0020';
  22743. t['\u200A'] = '\u0020';
  22744. t['\u2017'] = '\u0020\u0333';
  22745. t['\u2024'] = '\u002E';
  22746. t['\u2025'] = '\u002E\u002E';
  22747. t['\u2026'] = '\u002E\u002E\u002E';
  22748. t['\u2033'] = '\u2032\u2032';
  22749. t['\u2034'] = '\u2032\u2032\u2032';
  22750. t['\u2036'] = '\u2035\u2035';
  22751. t['\u2037'] = '\u2035\u2035\u2035';
  22752. t['\u203C'] = '\u0021\u0021';
  22753. t['\u203E'] = '\u0020\u0305';
  22754. t['\u2047'] = '\u003F\u003F';
  22755. t['\u2048'] = '\u003F\u0021';
  22756. t['\u2049'] = '\u0021\u003F';
  22757. t['\u2057'] = '\u2032\u2032\u2032\u2032';
  22758. t['\u205F'] = '\u0020';
  22759. t['\u20A8'] = '\u0052\u0073';
  22760. t['\u2100'] = '\u0061\u002F\u0063';
  22761. t['\u2101'] = '\u0061\u002F\u0073';
  22762. t['\u2103'] = '\u00B0\u0043';
  22763. t['\u2105'] = '\u0063\u002F\u006F';
  22764. t['\u2106'] = '\u0063\u002F\u0075';
  22765. t['\u2107'] = '\u0190';
  22766. t['\u2109'] = '\u00B0\u0046';
  22767. t['\u2116'] = '\u004E\u006F';
  22768. t['\u2121'] = '\u0054\u0045\u004C';
  22769. t['\u2135'] = '\u05D0';
  22770. t['\u2136'] = '\u05D1';
  22771. t['\u2137'] = '\u05D2';
  22772. t['\u2138'] = '\u05D3';
  22773. t['\u213B'] = '\u0046\u0041\u0058';
  22774. t['\u2160'] = '\u0049';
  22775. t['\u2161'] = '\u0049\u0049';
  22776. t['\u2162'] = '\u0049\u0049\u0049';
  22777. t['\u2163'] = '\u0049\u0056';
  22778. t['\u2164'] = '\u0056';
  22779. t['\u2165'] = '\u0056\u0049';
  22780. t['\u2166'] = '\u0056\u0049\u0049';
  22781. t['\u2167'] = '\u0056\u0049\u0049\u0049';
  22782. t['\u2168'] = '\u0049\u0058';
  22783. t['\u2169'] = '\u0058';
  22784. t['\u216A'] = '\u0058\u0049';
  22785. t['\u216B'] = '\u0058\u0049\u0049';
  22786. t['\u216C'] = '\u004C';
  22787. t['\u216D'] = '\u0043';
  22788. t['\u216E'] = '\u0044';
  22789. t['\u216F'] = '\u004D';
  22790. t['\u2170'] = '\u0069';
  22791. t['\u2171'] = '\u0069\u0069';
  22792. t['\u2172'] = '\u0069\u0069\u0069';
  22793. t['\u2173'] = '\u0069\u0076';
  22794. t['\u2174'] = '\u0076';
  22795. t['\u2175'] = '\u0076\u0069';
  22796. t['\u2176'] = '\u0076\u0069\u0069';
  22797. t['\u2177'] = '\u0076\u0069\u0069\u0069';
  22798. t['\u2178'] = '\u0069\u0078';
  22799. t['\u2179'] = '\u0078';
  22800. t['\u217A'] = '\u0078\u0069';
  22801. t['\u217B'] = '\u0078\u0069\u0069';
  22802. t['\u217C'] = '\u006C';
  22803. t['\u217D'] = '\u0063';
  22804. t['\u217E'] = '\u0064';
  22805. t['\u217F'] = '\u006D';
  22806. t['\u222C'] = '\u222B\u222B';
  22807. t['\u222D'] = '\u222B\u222B\u222B';
  22808. t['\u222F'] = '\u222E\u222E';
  22809. t['\u2230'] = '\u222E\u222E\u222E';
  22810. t['\u2474'] = '\u0028\u0031\u0029';
  22811. t['\u2475'] = '\u0028\u0032\u0029';
  22812. t['\u2476'] = '\u0028\u0033\u0029';
  22813. t['\u2477'] = '\u0028\u0034\u0029';
  22814. t['\u2478'] = '\u0028\u0035\u0029';
  22815. t['\u2479'] = '\u0028\u0036\u0029';
  22816. t['\u247A'] = '\u0028\u0037\u0029';
  22817. t['\u247B'] = '\u0028\u0038\u0029';
  22818. t['\u247C'] = '\u0028\u0039\u0029';
  22819. t['\u247D'] = '\u0028\u0031\u0030\u0029';
  22820. t['\u247E'] = '\u0028\u0031\u0031\u0029';
  22821. t['\u247F'] = '\u0028\u0031\u0032\u0029';
  22822. t['\u2480'] = '\u0028\u0031\u0033\u0029';
  22823. t['\u2481'] = '\u0028\u0031\u0034\u0029';
  22824. t['\u2482'] = '\u0028\u0031\u0035\u0029';
  22825. t['\u2483'] = '\u0028\u0031\u0036\u0029';
  22826. t['\u2484'] = '\u0028\u0031\u0037\u0029';
  22827. t['\u2485'] = '\u0028\u0031\u0038\u0029';
  22828. t['\u2486'] = '\u0028\u0031\u0039\u0029';
  22829. t['\u2487'] = '\u0028\u0032\u0030\u0029';
  22830. t['\u2488'] = '\u0031\u002E';
  22831. t['\u2489'] = '\u0032\u002E';
  22832. t['\u248A'] = '\u0033\u002E';
  22833. t['\u248B'] = '\u0034\u002E';
  22834. t['\u248C'] = '\u0035\u002E';
  22835. t['\u248D'] = '\u0036\u002E';
  22836. t['\u248E'] = '\u0037\u002E';
  22837. t['\u248F'] = '\u0038\u002E';
  22838. t['\u2490'] = '\u0039\u002E';
  22839. t['\u2491'] = '\u0031\u0030\u002E';
  22840. t['\u2492'] = '\u0031\u0031\u002E';
  22841. t['\u2493'] = '\u0031\u0032\u002E';
  22842. t['\u2494'] = '\u0031\u0033\u002E';
  22843. t['\u2495'] = '\u0031\u0034\u002E';
  22844. t['\u2496'] = '\u0031\u0035\u002E';
  22845. t['\u2497'] = '\u0031\u0036\u002E';
  22846. t['\u2498'] = '\u0031\u0037\u002E';
  22847. t['\u2499'] = '\u0031\u0038\u002E';
  22848. t['\u249A'] = '\u0031\u0039\u002E';
  22849. t['\u249B'] = '\u0032\u0030\u002E';
  22850. t['\u249C'] = '\u0028\u0061\u0029';
  22851. t['\u249D'] = '\u0028\u0062\u0029';
  22852. t['\u249E'] = '\u0028\u0063\u0029';
  22853. t['\u249F'] = '\u0028\u0064\u0029';
  22854. t['\u24A0'] = '\u0028\u0065\u0029';
  22855. t['\u24A1'] = '\u0028\u0066\u0029';
  22856. t['\u24A2'] = '\u0028\u0067\u0029';
  22857. t['\u24A3'] = '\u0028\u0068\u0029';
  22858. t['\u24A4'] = '\u0028\u0069\u0029';
  22859. t['\u24A5'] = '\u0028\u006A\u0029';
  22860. t['\u24A6'] = '\u0028\u006B\u0029';
  22861. t['\u24A7'] = '\u0028\u006C\u0029';
  22862. t['\u24A8'] = '\u0028\u006D\u0029';
  22863. t['\u24A9'] = '\u0028\u006E\u0029';
  22864. t['\u24AA'] = '\u0028\u006F\u0029';
  22865. t['\u24AB'] = '\u0028\u0070\u0029';
  22866. t['\u24AC'] = '\u0028\u0071\u0029';
  22867. t['\u24AD'] = '\u0028\u0072\u0029';
  22868. t['\u24AE'] = '\u0028\u0073\u0029';
  22869. t['\u24AF'] = '\u0028\u0074\u0029';
  22870. t['\u24B0'] = '\u0028\u0075\u0029';
  22871. t['\u24B1'] = '\u0028\u0076\u0029';
  22872. t['\u24B2'] = '\u0028\u0077\u0029';
  22873. t['\u24B3'] = '\u0028\u0078\u0029';
  22874. t['\u24B4'] = '\u0028\u0079\u0029';
  22875. t['\u24B5'] = '\u0028\u007A\u0029';
  22876. t['\u2A0C'] = '\u222B\u222B\u222B\u222B';
  22877. t['\u2A74'] = '\u003A\u003A\u003D';
  22878. t['\u2A75'] = '\u003D\u003D';
  22879. t['\u2A76'] = '\u003D\u003D\u003D';
  22880. t['\u2E9F'] = '\u6BCD';
  22881. t['\u2EF3'] = '\u9F9F';
  22882. t['\u2F00'] = '\u4E00';
  22883. t['\u2F01'] = '\u4E28';
  22884. t['\u2F02'] = '\u4E36';
  22885. t['\u2F03'] = '\u4E3F';
  22886. t['\u2F04'] = '\u4E59';
  22887. t['\u2F05'] = '\u4E85';
  22888. t['\u2F06'] = '\u4E8C';
  22889. t['\u2F07'] = '\u4EA0';
  22890. t['\u2F08'] = '\u4EBA';
  22891. t['\u2F09'] = '\u513F';
  22892. t['\u2F0A'] = '\u5165';
  22893. t['\u2F0B'] = '\u516B';
  22894. t['\u2F0C'] = '\u5182';
  22895. t['\u2F0D'] = '\u5196';
  22896. t['\u2F0E'] = '\u51AB';
  22897. t['\u2F0F'] = '\u51E0';
  22898. t['\u2F10'] = '\u51F5';
  22899. t['\u2F11'] = '\u5200';
  22900. t['\u2F12'] = '\u529B';
  22901. t['\u2F13'] = '\u52F9';
  22902. t['\u2F14'] = '\u5315';
  22903. t['\u2F15'] = '\u531A';
  22904. t['\u2F16'] = '\u5338';
  22905. t['\u2F17'] = '\u5341';
  22906. t['\u2F18'] = '\u535C';
  22907. t['\u2F19'] = '\u5369';
  22908. t['\u2F1A'] = '\u5382';
  22909. t['\u2F1B'] = '\u53B6';
  22910. t['\u2F1C'] = '\u53C8';
  22911. t['\u2F1D'] = '\u53E3';
  22912. t['\u2F1E'] = '\u56D7';
  22913. t['\u2F1F'] = '\u571F';
  22914. t['\u2F20'] = '\u58EB';
  22915. t['\u2F21'] = '\u5902';
  22916. t['\u2F22'] = '\u590A';
  22917. t['\u2F23'] = '\u5915';
  22918. t['\u2F24'] = '\u5927';
  22919. t['\u2F25'] = '\u5973';
  22920. t['\u2F26'] = '\u5B50';
  22921. t['\u2F27'] = '\u5B80';
  22922. t['\u2F28'] = '\u5BF8';
  22923. t['\u2F29'] = '\u5C0F';
  22924. t['\u2F2A'] = '\u5C22';
  22925. t['\u2F2B'] = '\u5C38';
  22926. t['\u2F2C'] = '\u5C6E';
  22927. t['\u2F2D'] = '\u5C71';
  22928. t['\u2F2E'] = '\u5DDB';
  22929. t['\u2F2F'] = '\u5DE5';
  22930. t['\u2F30'] = '\u5DF1';
  22931. t['\u2F31'] = '\u5DFE';
  22932. t['\u2F32'] = '\u5E72';
  22933. t['\u2F33'] = '\u5E7A';
  22934. t['\u2F34'] = '\u5E7F';
  22935. t['\u2F35'] = '\u5EF4';
  22936. t['\u2F36'] = '\u5EFE';
  22937. t['\u2F37'] = '\u5F0B';
  22938. t['\u2F38'] = '\u5F13';
  22939. t['\u2F39'] = '\u5F50';
  22940. t['\u2F3A'] = '\u5F61';
  22941. t['\u2F3B'] = '\u5F73';
  22942. t['\u2F3C'] = '\u5FC3';
  22943. t['\u2F3D'] = '\u6208';
  22944. t['\u2F3E'] = '\u6236';
  22945. t['\u2F3F'] = '\u624B';
  22946. t['\u2F40'] = '\u652F';
  22947. t['\u2F41'] = '\u6534';
  22948. t['\u2F42'] = '\u6587';
  22949. t['\u2F43'] = '\u6597';
  22950. t['\u2F44'] = '\u65A4';
  22951. t['\u2F45'] = '\u65B9';
  22952. t['\u2F46'] = '\u65E0';
  22953. t['\u2F47'] = '\u65E5';
  22954. t['\u2F48'] = '\u66F0';
  22955. t['\u2F49'] = '\u6708';
  22956. t['\u2F4A'] = '\u6728';
  22957. t['\u2F4B'] = '\u6B20';
  22958. t['\u2F4C'] = '\u6B62';
  22959. t['\u2F4D'] = '\u6B79';
  22960. t['\u2F4E'] = '\u6BB3';
  22961. t['\u2F4F'] = '\u6BCB';
  22962. t['\u2F50'] = '\u6BD4';
  22963. t['\u2F51'] = '\u6BDB';
  22964. t['\u2F52'] = '\u6C0F';
  22965. t['\u2F53'] = '\u6C14';
  22966. t['\u2F54'] = '\u6C34';
  22967. t['\u2F55'] = '\u706B';
  22968. t['\u2F56'] = '\u722A';
  22969. t['\u2F57'] = '\u7236';
  22970. t['\u2F58'] = '\u723B';
  22971. t['\u2F59'] = '\u723F';
  22972. t['\u2F5A'] = '\u7247';
  22973. t['\u2F5B'] = '\u7259';
  22974. t['\u2F5C'] = '\u725B';
  22975. t['\u2F5D'] = '\u72AC';
  22976. t['\u2F5E'] = '\u7384';
  22977. t['\u2F5F'] = '\u7389';
  22978. t['\u2F60'] = '\u74DC';
  22979. t['\u2F61'] = '\u74E6';
  22980. t['\u2F62'] = '\u7518';
  22981. t['\u2F63'] = '\u751F';
  22982. t['\u2F64'] = '\u7528';
  22983. t['\u2F65'] = '\u7530';
  22984. t['\u2F66'] = '\u758B';
  22985. t['\u2F67'] = '\u7592';
  22986. t['\u2F68'] = '\u7676';
  22987. t['\u2F69'] = '\u767D';
  22988. t['\u2F6A'] = '\u76AE';
  22989. t['\u2F6B'] = '\u76BF';
  22990. t['\u2F6C'] = '\u76EE';
  22991. t['\u2F6D'] = '\u77DB';
  22992. t['\u2F6E'] = '\u77E2';
  22993. t['\u2F6F'] = '\u77F3';
  22994. t['\u2F70'] = '\u793A';
  22995. t['\u2F71'] = '\u79B8';
  22996. t['\u2F72'] = '\u79BE';
  22997. t['\u2F73'] = '\u7A74';
  22998. t['\u2F74'] = '\u7ACB';
  22999. t['\u2F75'] = '\u7AF9';
  23000. t['\u2F76'] = '\u7C73';
  23001. t['\u2F77'] = '\u7CF8';
  23002. t['\u2F78'] = '\u7F36';
  23003. t['\u2F79'] = '\u7F51';
  23004. t['\u2F7A'] = '\u7F8A';
  23005. t['\u2F7B'] = '\u7FBD';
  23006. t['\u2F7C'] = '\u8001';
  23007. t['\u2F7D'] = '\u800C';
  23008. t['\u2F7E'] = '\u8012';
  23009. t['\u2F7F'] = '\u8033';
  23010. t['\u2F80'] = '\u807F';
  23011. t['\u2F81'] = '\u8089';
  23012. t['\u2F82'] = '\u81E3';
  23013. t['\u2F83'] = '\u81EA';
  23014. t['\u2F84'] = '\u81F3';
  23015. t['\u2F85'] = '\u81FC';
  23016. t['\u2F86'] = '\u820C';
  23017. t['\u2F87'] = '\u821B';
  23018. t['\u2F88'] = '\u821F';
  23019. t['\u2F89'] = '\u826E';
  23020. t['\u2F8A'] = '\u8272';
  23021. t['\u2F8B'] = '\u8278';
  23022. t['\u2F8C'] = '\u864D';
  23023. t['\u2F8D'] = '\u866B';
  23024. t['\u2F8E'] = '\u8840';
  23025. t['\u2F8F'] = '\u884C';
  23026. t['\u2F90'] = '\u8863';
  23027. t['\u2F91'] = '\u897E';
  23028. t['\u2F92'] = '\u898B';
  23029. t['\u2F93'] = '\u89D2';
  23030. t['\u2F94'] = '\u8A00';
  23031. t['\u2F95'] = '\u8C37';
  23032. t['\u2F96'] = '\u8C46';
  23033. t['\u2F97'] = '\u8C55';
  23034. t['\u2F98'] = '\u8C78';
  23035. t['\u2F99'] = '\u8C9D';
  23036. t['\u2F9A'] = '\u8D64';
  23037. t['\u2F9B'] = '\u8D70';
  23038. t['\u2F9C'] = '\u8DB3';
  23039. t['\u2F9D'] = '\u8EAB';
  23040. t['\u2F9E'] = '\u8ECA';
  23041. t['\u2F9F'] = '\u8F9B';
  23042. t['\u2FA0'] = '\u8FB0';
  23043. t['\u2FA1'] = '\u8FB5';
  23044. t['\u2FA2'] = '\u9091';
  23045. t['\u2FA3'] = '\u9149';
  23046. t['\u2FA4'] = '\u91C6';
  23047. t['\u2FA5'] = '\u91CC';
  23048. t['\u2FA6'] = '\u91D1';
  23049. t['\u2FA7'] = '\u9577';
  23050. t['\u2FA8'] = '\u9580';
  23051. t['\u2FA9'] = '\u961C';
  23052. t['\u2FAA'] = '\u96B6';
  23053. t['\u2FAB'] = '\u96B9';
  23054. t['\u2FAC'] = '\u96E8';
  23055. t['\u2FAD'] = '\u9751';
  23056. t['\u2FAE'] = '\u975E';
  23057. t['\u2FAF'] = '\u9762';
  23058. t['\u2FB0'] = '\u9769';
  23059. t['\u2FB1'] = '\u97CB';
  23060. t['\u2FB2'] = '\u97ED';
  23061. t['\u2FB3'] = '\u97F3';
  23062. t['\u2FB4'] = '\u9801';
  23063. t['\u2FB5'] = '\u98A8';
  23064. t['\u2FB6'] = '\u98DB';
  23065. t['\u2FB7'] = '\u98DF';
  23066. t['\u2FB8'] = '\u9996';
  23067. t['\u2FB9'] = '\u9999';
  23068. t['\u2FBA'] = '\u99AC';
  23069. t['\u2FBB'] = '\u9AA8';
  23070. t['\u2FBC'] = '\u9AD8';
  23071. t['\u2FBD'] = '\u9ADF';
  23072. t['\u2FBE'] = '\u9B25';
  23073. t['\u2FBF'] = '\u9B2F';
  23074. t['\u2FC0'] = '\u9B32';
  23075. t['\u2FC1'] = '\u9B3C';
  23076. t['\u2FC2'] = '\u9B5A';
  23077. t['\u2FC3'] = '\u9CE5';
  23078. t['\u2FC4'] = '\u9E75';
  23079. t['\u2FC5'] = '\u9E7F';
  23080. t['\u2FC6'] = '\u9EA5';
  23081. t['\u2FC7'] = '\u9EBB';
  23082. t['\u2FC8'] = '\u9EC3';
  23083. t['\u2FC9'] = '\u9ECD';
  23084. t['\u2FCA'] = '\u9ED1';
  23085. t['\u2FCB'] = '\u9EF9';
  23086. t['\u2FCC'] = '\u9EFD';
  23087. t['\u2FCD'] = '\u9F0E';
  23088. t['\u2FCE'] = '\u9F13';
  23089. t['\u2FCF'] = '\u9F20';
  23090. t['\u2FD0'] = '\u9F3B';
  23091. t['\u2FD1'] = '\u9F4A';
  23092. t['\u2FD2'] = '\u9F52';
  23093. t['\u2FD3'] = '\u9F8D';
  23094. t['\u2FD4'] = '\u9F9C';
  23095. t['\u2FD5'] = '\u9FA0';
  23096. t['\u3036'] = '\u3012';
  23097. t['\u3038'] = '\u5341';
  23098. t['\u3039'] = '\u5344';
  23099. t['\u303A'] = '\u5345';
  23100. t['\u309B'] = '\u0020\u3099';
  23101. t['\u309C'] = '\u0020\u309A';
  23102. t['\u3131'] = '\u1100';
  23103. t['\u3132'] = '\u1101';
  23104. t['\u3133'] = '\u11AA';
  23105. t['\u3134'] = '\u1102';
  23106. t['\u3135'] = '\u11AC';
  23107. t['\u3136'] = '\u11AD';
  23108. t['\u3137'] = '\u1103';
  23109. t['\u3138'] = '\u1104';
  23110. t['\u3139'] = '\u1105';
  23111. t['\u313A'] = '\u11B0';
  23112. t['\u313B'] = '\u11B1';
  23113. t['\u313C'] = '\u11B2';
  23114. t['\u313D'] = '\u11B3';
  23115. t['\u313E'] = '\u11B4';
  23116. t['\u313F'] = '\u11B5';
  23117. t['\u3140'] = '\u111A';
  23118. t['\u3141'] = '\u1106';
  23119. t['\u3142'] = '\u1107';
  23120. t['\u3143'] = '\u1108';
  23121. t['\u3144'] = '\u1121';
  23122. t['\u3145'] = '\u1109';
  23123. t['\u3146'] = '\u110A';
  23124. t['\u3147'] = '\u110B';
  23125. t['\u3148'] = '\u110C';
  23126. t['\u3149'] = '\u110D';
  23127. t['\u314A'] = '\u110E';
  23128. t['\u314B'] = '\u110F';
  23129. t['\u314C'] = '\u1110';
  23130. t['\u314D'] = '\u1111';
  23131. t['\u314E'] = '\u1112';
  23132. t['\u314F'] = '\u1161';
  23133. t['\u3150'] = '\u1162';
  23134. t['\u3151'] = '\u1163';
  23135. t['\u3152'] = '\u1164';
  23136. t['\u3153'] = '\u1165';
  23137. t['\u3154'] = '\u1166';
  23138. t['\u3155'] = '\u1167';
  23139. t['\u3156'] = '\u1168';
  23140. t['\u3157'] = '\u1169';
  23141. t['\u3158'] = '\u116A';
  23142. t['\u3159'] = '\u116B';
  23143. t['\u315A'] = '\u116C';
  23144. t['\u315B'] = '\u116D';
  23145. t['\u315C'] = '\u116E';
  23146. t['\u315D'] = '\u116F';
  23147. t['\u315E'] = '\u1170';
  23148. t['\u315F'] = '\u1171';
  23149. t['\u3160'] = '\u1172';
  23150. t['\u3161'] = '\u1173';
  23151. t['\u3162'] = '\u1174';
  23152. t['\u3163'] = '\u1175';
  23153. t['\u3164'] = '\u1160';
  23154. t['\u3165'] = '\u1114';
  23155. t['\u3166'] = '\u1115';
  23156. t['\u3167'] = '\u11C7';
  23157. t['\u3168'] = '\u11C8';
  23158. t['\u3169'] = '\u11CC';
  23159. t['\u316A'] = '\u11CE';
  23160. t['\u316B'] = '\u11D3';
  23161. t['\u316C'] = '\u11D7';
  23162. t['\u316D'] = '\u11D9';
  23163. t['\u316E'] = '\u111C';
  23164. t['\u316F'] = '\u11DD';
  23165. t['\u3170'] = '\u11DF';
  23166. t['\u3171'] = '\u111D';
  23167. t['\u3172'] = '\u111E';
  23168. t['\u3173'] = '\u1120';
  23169. t['\u3174'] = '\u1122';
  23170. t['\u3175'] = '\u1123';
  23171. t['\u3176'] = '\u1127';
  23172. t['\u3177'] = '\u1129';
  23173. t['\u3178'] = '\u112B';
  23174. t['\u3179'] = '\u112C';
  23175. t['\u317A'] = '\u112D';
  23176. t['\u317B'] = '\u112E';
  23177. t['\u317C'] = '\u112F';
  23178. t['\u317D'] = '\u1132';
  23179. t['\u317E'] = '\u1136';
  23180. t['\u317F'] = '\u1140';
  23181. t['\u3180'] = '\u1147';
  23182. t['\u3181'] = '\u114C';
  23183. t['\u3182'] = '\u11F1';
  23184. t['\u3183'] = '\u11F2';
  23185. t['\u3184'] = '\u1157';
  23186. t['\u3185'] = '\u1158';
  23187. t['\u3186'] = '\u1159';
  23188. t['\u3187'] = '\u1184';
  23189. t['\u3188'] = '\u1185';
  23190. t['\u3189'] = '\u1188';
  23191. t['\u318A'] = '\u1191';
  23192. t['\u318B'] = '\u1192';
  23193. t['\u318C'] = '\u1194';
  23194. t['\u318D'] = '\u119E';
  23195. t['\u318E'] = '\u11A1';
  23196. t['\u3200'] = '\u0028\u1100\u0029';
  23197. t['\u3201'] = '\u0028\u1102\u0029';
  23198. t['\u3202'] = '\u0028\u1103\u0029';
  23199. t['\u3203'] = '\u0028\u1105\u0029';
  23200. t['\u3204'] = '\u0028\u1106\u0029';
  23201. t['\u3205'] = '\u0028\u1107\u0029';
  23202. t['\u3206'] = '\u0028\u1109\u0029';
  23203. t['\u3207'] = '\u0028\u110B\u0029';
  23204. t['\u3208'] = '\u0028\u110C\u0029';
  23205. t['\u3209'] = '\u0028\u110E\u0029';
  23206. t['\u320A'] = '\u0028\u110F\u0029';
  23207. t['\u320B'] = '\u0028\u1110\u0029';
  23208. t['\u320C'] = '\u0028\u1111\u0029';
  23209. t['\u320D'] = '\u0028\u1112\u0029';
  23210. t['\u320E'] = '\u0028\u1100\u1161\u0029';
  23211. t['\u320F'] = '\u0028\u1102\u1161\u0029';
  23212. t['\u3210'] = '\u0028\u1103\u1161\u0029';
  23213. t['\u3211'] = '\u0028\u1105\u1161\u0029';
  23214. t['\u3212'] = '\u0028\u1106\u1161\u0029';
  23215. t['\u3213'] = '\u0028\u1107\u1161\u0029';
  23216. t['\u3214'] = '\u0028\u1109\u1161\u0029';
  23217. t['\u3215'] = '\u0028\u110B\u1161\u0029';
  23218. t['\u3216'] = '\u0028\u110C\u1161\u0029';
  23219. t['\u3217'] = '\u0028\u110E\u1161\u0029';
  23220. t['\u3218'] = '\u0028\u110F\u1161\u0029';
  23221. t['\u3219'] = '\u0028\u1110\u1161\u0029';
  23222. t['\u321A'] = '\u0028\u1111\u1161\u0029';
  23223. t['\u321B'] = '\u0028\u1112\u1161\u0029';
  23224. t['\u321C'] = '\u0028\u110C\u116E\u0029';
  23225. t['\u321D'] = '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029';
  23226. t['\u321E'] = '\u0028\u110B\u1169\u1112\u116E\u0029';
  23227. t['\u3220'] = '\u0028\u4E00\u0029';
  23228. t['\u3221'] = '\u0028\u4E8C\u0029';
  23229. t['\u3222'] = '\u0028\u4E09\u0029';
  23230. t['\u3223'] = '\u0028\u56DB\u0029';
  23231. t['\u3224'] = '\u0028\u4E94\u0029';
  23232. t['\u3225'] = '\u0028\u516D\u0029';
  23233. t['\u3226'] = '\u0028\u4E03\u0029';
  23234. t['\u3227'] = '\u0028\u516B\u0029';
  23235. t['\u3228'] = '\u0028\u4E5D\u0029';
  23236. t['\u3229'] = '\u0028\u5341\u0029';
  23237. t['\u322A'] = '\u0028\u6708\u0029';
  23238. t['\u322B'] = '\u0028\u706B\u0029';
  23239. t['\u322C'] = '\u0028\u6C34\u0029';
  23240. t['\u322D'] = '\u0028\u6728\u0029';
  23241. t['\u322E'] = '\u0028\u91D1\u0029';
  23242. t['\u322F'] = '\u0028\u571F\u0029';
  23243. t['\u3230'] = '\u0028\u65E5\u0029';
  23244. t['\u3231'] = '\u0028\u682A\u0029';
  23245. t['\u3232'] = '\u0028\u6709\u0029';
  23246. t['\u3233'] = '\u0028\u793E\u0029';
  23247. t['\u3234'] = '\u0028\u540D\u0029';
  23248. t['\u3235'] = '\u0028\u7279\u0029';
  23249. t['\u3236'] = '\u0028\u8CA1\u0029';
  23250. t['\u3237'] = '\u0028\u795D\u0029';
  23251. t['\u3238'] = '\u0028\u52B4\u0029';
  23252. t['\u3239'] = '\u0028\u4EE3\u0029';
  23253. t['\u323A'] = '\u0028\u547C\u0029';
  23254. t['\u323B'] = '\u0028\u5B66\u0029';
  23255. t['\u323C'] = '\u0028\u76E3\u0029';
  23256. t['\u323D'] = '\u0028\u4F01\u0029';
  23257. t['\u323E'] = '\u0028\u8CC7\u0029';
  23258. t['\u323F'] = '\u0028\u5354\u0029';
  23259. t['\u3240'] = '\u0028\u796D\u0029';
  23260. t['\u3241'] = '\u0028\u4F11\u0029';
  23261. t['\u3242'] = '\u0028\u81EA\u0029';
  23262. t['\u3243'] = '\u0028\u81F3\u0029';
  23263. t['\u32C0'] = '\u0031\u6708';
  23264. t['\u32C1'] = '\u0032\u6708';
  23265. t['\u32C2'] = '\u0033\u6708';
  23266. t['\u32C3'] = '\u0034\u6708';
  23267. t['\u32C4'] = '\u0035\u6708';
  23268. t['\u32C5'] = '\u0036\u6708';
  23269. t['\u32C6'] = '\u0037\u6708';
  23270. t['\u32C7'] = '\u0038\u6708';
  23271. t['\u32C8'] = '\u0039\u6708';
  23272. t['\u32C9'] = '\u0031\u0030\u6708';
  23273. t['\u32CA'] = '\u0031\u0031\u6708';
  23274. t['\u32CB'] = '\u0031\u0032\u6708';
  23275. t['\u3358'] = '\u0030\u70B9';
  23276. t['\u3359'] = '\u0031\u70B9';
  23277. t['\u335A'] = '\u0032\u70B9';
  23278. t['\u335B'] = '\u0033\u70B9';
  23279. t['\u335C'] = '\u0034\u70B9';
  23280. t['\u335D'] = '\u0035\u70B9';
  23281. t['\u335E'] = '\u0036\u70B9';
  23282. t['\u335F'] = '\u0037\u70B9';
  23283. t['\u3360'] = '\u0038\u70B9';
  23284. t['\u3361'] = '\u0039\u70B9';
  23285. t['\u3362'] = '\u0031\u0030\u70B9';
  23286. t['\u3363'] = '\u0031\u0031\u70B9';
  23287. t['\u3364'] = '\u0031\u0032\u70B9';
  23288. t['\u3365'] = '\u0031\u0033\u70B9';
  23289. t['\u3366'] = '\u0031\u0034\u70B9';
  23290. t['\u3367'] = '\u0031\u0035\u70B9';
  23291. t['\u3368'] = '\u0031\u0036\u70B9';
  23292. t['\u3369'] = '\u0031\u0037\u70B9';
  23293. t['\u336A'] = '\u0031\u0038\u70B9';
  23294. t['\u336B'] = '\u0031\u0039\u70B9';
  23295. t['\u336C'] = '\u0032\u0030\u70B9';
  23296. t['\u336D'] = '\u0032\u0031\u70B9';
  23297. t['\u336E'] = '\u0032\u0032\u70B9';
  23298. t['\u336F'] = '\u0032\u0033\u70B9';
  23299. t['\u3370'] = '\u0032\u0034\u70B9';
  23300. t['\u33E0'] = '\u0031\u65E5';
  23301. t['\u33E1'] = '\u0032\u65E5';
  23302. t['\u33E2'] = '\u0033\u65E5';
  23303. t['\u33E3'] = '\u0034\u65E5';
  23304. t['\u33E4'] = '\u0035\u65E5';
  23305. t['\u33E5'] = '\u0036\u65E5';
  23306. t['\u33E6'] = '\u0037\u65E5';
  23307. t['\u33E7'] = '\u0038\u65E5';
  23308. t['\u33E8'] = '\u0039\u65E5';
  23309. t['\u33E9'] = '\u0031\u0030\u65E5';
  23310. t['\u33EA'] = '\u0031\u0031\u65E5';
  23311. t['\u33EB'] = '\u0031\u0032\u65E5';
  23312. t['\u33EC'] = '\u0031\u0033\u65E5';
  23313. t['\u33ED'] = '\u0031\u0034\u65E5';
  23314. t['\u33EE'] = '\u0031\u0035\u65E5';
  23315. t['\u33EF'] = '\u0031\u0036\u65E5';
  23316. t['\u33F0'] = '\u0031\u0037\u65E5';
  23317. t['\u33F1'] = '\u0031\u0038\u65E5';
  23318. t['\u33F2'] = '\u0031\u0039\u65E5';
  23319. t['\u33F3'] = '\u0032\u0030\u65E5';
  23320. t['\u33F4'] = '\u0032\u0031\u65E5';
  23321. t['\u33F5'] = '\u0032\u0032\u65E5';
  23322. t['\u33F6'] = '\u0032\u0033\u65E5';
  23323. t['\u33F7'] = '\u0032\u0034\u65E5';
  23324. t['\u33F8'] = '\u0032\u0035\u65E5';
  23325. t['\u33F9'] = '\u0032\u0036\u65E5';
  23326. t['\u33FA'] = '\u0032\u0037\u65E5';
  23327. t['\u33FB'] = '\u0032\u0038\u65E5';
  23328. t['\u33FC'] = '\u0032\u0039\u65E5';
  23329. t['\u33FD'] = '\u0033\u0030\u65E5';
  23330. t['\u33FE'] = '\u0033\u0031\u65E5';
  23331. t['\uFB00'] = '\u0066\u0066';
  23332. t['\uFB01'] = '\u0066\u0069';
  23333. t['\uFB02'] = '\u0066\u006C';
  23334. t['\uFB03'] = '\u0066\u0066\u0069';
  23335. t['\uFB04'] = '\u0066\u0066\u006C';
  23336. t['\uFB05'] = '\u017F\u0074';
  23337. t['\uFB06'] = '\u0073\u0074';
  23338. t['\uFB13'] = '\u0574\u0576';
  23339. t['\uFB14'] = '\u0574\u0565';
  23340. t['\uFB15'] = '\u0574\u056B';
  23341. t['\uFB16'] = '\u057E\u0576';
  23342. t['\uFB17'] = '\u0574\u056D';
  23343. t['\uFB4F'] = '\u05D0\u05DC';
  23344. t['\uFB50'] = '\u0671';
  23345. t['\uFB51'] = '\u0671';
  23346. t['\uFB52'] = '\u067B';
  23347. t['\uFB53'] = '\u067B';
  23348. t['\uFB54'] = '\u067B';
  23349. t['\uFB55'] = '\u067B';
  23350. t['\uFB56'] = '\u067E';
  23351. t['\uFB57'] = '\u067E';
  23352. t['\uFB58'] = '\u067E';
  23353. t['\uFB59'] = '\u067E';
  23354. t['\uFB5A'] = '\u0680';
  23355. t['\uFB5B'] = '\u0680';
  23356. t['\uFB5C'] = '\u0680';
  23357. t['\uFB5D'] = '\u0680';
  23358. t['\uFB5E'] = '\u067A';
  23359. t['\uFB5F'] = '\u067A';
  23360. t['\uFB60'] = '\u067A';
  23361. t['\uFB61'] = '\u067A';
  23362. t['\uFB62'] = '\u067F';
  23363. t['\uFB63'] = '\u067F';
  23364. t['\uFB64'] = '\u067F';
  23365. t['\uFB65'] = '\u067F';
  23366. t['\uFB66'] = '\u0679';
  23367. t['\uFB67'] = '\u0679';
  23368. t['\uFB68'] = '\u0679';
  23369. t['\uFB69'] = '\u0679';
  23370. t['\uFB6A'] = '\u06A4';
  23371. t['\uFB6B'] = '\u06A4';
  23372. t['\uFB6C'] = '\u06A4';
  23373. t['\uFB6D'] = '\u06A4';
  23374. t['\uFB6E'] = '\u06A6';
  23375. t['\uFB6F'] = '\u06A6';
  23376. t['\uFB70'] = '\u06A6';
  23377. t['\uFB71'] = '\u06A6';
  23378. t['\uFB72'] = '\u0684';
  23379. t['\uFB73'] = '\u0684';
  23380. t['\uFB74'] = '\u0684';
  23381. t['\uFB75'] = '\u0684';
  23382. t['\uFB76'] = '\u0683';
  23383. t['\uFB77'] = '\u0683';
  23384. t['\uFB78'] = '\u0683';
  23385. t['\uFB79'] = '\u0683';
  23386. t['\uFB7A'] = '\u0686';
  23387. t['\uFB7B'] = '\u0686';
  23388. t['\uFB7C'] = '\u0686';
  23389. t['\uFB7D'] = '\u0686';
  23390. t['\uFB7E'] = '\u0687';
  23391. t['\uFB7F'] = '\u0687';
  23392. t['\uFB80'] = '\u0687';
  23393. t['\uFB81'] = '\u0687';
  23394. t['\uFB82'] = '\u068D';
  23395. t['\uFB83'] = '\u068D';
  23396. t['\uFB84'] = '\u068C';
  23397. t['\uFB85'] = '\u068C';
  23398. t['\uFB86'] = '\u068E';
  23399. t['\uFB87'] = '\u068E';
  23400. t['\uFB88'] = '\u0688';
  23401. t['\uFB89'] = '\u0688';
  23402. t['\uFB8A'] = '\u0698';
  23403. t['\uFB8B'] = '\u0698';
  23404. t['\uFB8C'] = '\u0691';
  23405. t['\uFB8D'] = '\u0691';
  23406. t['\uFB8E'] = '\u06A9';
  23407. t['\uFB8F'] = '\u06A9';
  23408. t['\uFB90'] = '\u06A9';
  23409. t['\uFB91'] = '\u06A9';
  23410. t['\uFB92'] = '\u06AF';
  23411. t['\uFB93'] = '\u06AF';
  23412. t['\uFB94'] = '\u06AF';
  23413. t['\uFB95'] = '\u06AF';
  23414. t['\uFB96'] = '\u06B3';
  23415. t['\uFB97'] = '\u06B3';
  23416. t['\uFB98'] = '\u06B3';
  23417. t['\uFB99'] = '\u06B3';
  23418. t['\uFB9A'] = '\u06B1';
  23419. t['\uFB9B'] = '\u06B1';
  23420. t['\uFB9C'] = '\u06B1';
  23421. t['\uFB9D'] = '\u06B1';
  23422. t['\uFB9E'] = '\u06BA';
  23423. t['\uFB9F'] = '\u06BA';
  23424. t['\uFBA0'] = '\u06BB';
  23425. t['\uFBA1'] = '\u06BB';
  23426. t['\uFBA2'] = '\u06BB';
  23427. t['\uFBA3'] = '\u06BB';
  23428. t['\uFBA4'] = '\u06C0';
  23429. t['\uFBA5'] = '\u06C0';
  23430. t['\uFBA6'] = '\u06C1';
  23431. t['\uFBA7'] = '\u06C1';
  23432. t['\uFBA8'] = '\u06C1';
  23433. t['\uFBA9'] = '\u06C1';
  23434. t['\uFBAA'] = '\u06BE';
  23435. t['\uFBAB'] = '\u06BE';
  23436. t['\uFBAC'] = '\u06BE';
  23437. t['\uFBAD'] = '\u06BE';
  23438. t['\uFBAE'] = '\u06D2';
  23439. t['\uFBAF'] = '\u06D2';
  23440. t['\uFBB0'] = '\u06D3';
  23441. t['\uFBB1'] = '\u06D3';
  23442. t['\uFBD3'] = '\u06AD';
  23443. t['\uFBD4'] = '\u06AD';
  23444. t['\uFBD5'] = '\u06AD';
  23445. t['\uFBD6'] = '\u06AD';
  23446. t['\uFBD7'] = '\u06C7';
  23447. t['\uFBD8'] = '\u06C7';
  23448. t['\uFBD9'] = '\u06C6';
  23449. t['\uFBDA'] = '\u06C6';
  23450. t['\uFBDB'] = '\u06C8';
  23451. t['\uFBDC'] = '\u06C8';
  23452. t['\uFBDD'] = '\u0677';
  23453. t['\uFBDE'] = '\u06CB';
  23454. t['\uFBDF'] = '\u06CB';
  23455. t['\uFBE0'] = '\u06C5';
  23456. t['\uFBE1'] = '\u06C5';
  23457. t['\uFBE2'] = '\u06C9';
  23458. t['\uFBE3'] = '\u06C9';
  23459. t['\uFBE4'] = '\u06D0';
  23460. t['\uFBE5'] = '\u06D0';
  23461. t['\uFBE6'] = '\u06D0';
  23462. t['\uFBE7'] = '\u06D0';
  23463. t['\uFBE8'] = '\u0649';
  23464. t['\uFBE9'] = '\u0649';
  23465. t['\uFBEA'] = '\u0626\u0627';
  23466. t['\uFBEB'] = '\u0626\u0627';
  23467. t['\uFBEC'] = '\u0626\u06D5';
  23468. t['\uFBED'] = '\u0626\u06D5';
  23469. t['\uFBEE'] = '\u0626\u0648';
  23470. t['\uFBEF'] = '\u0626\u0648';
  23471. t['\uFBF0'] = '\u0626\u06C7';
  23472. t['\uFBF1'] = '\u0626\u06C7';
  23473. t['\uFBF2'] = '\u0626\u06C6';
  23474. t['\uFBF3'] = '\u0626\u06C6';
  23475. t['\uFBF4'] = '\u0626\u06C8';
  23476. t['\uFBF5'] = '\u0626\u06C8';
  23477. t['\uFBF6'] = '\u0626\u06D0';
  23478. t['\uFBF7'] = '\u0626\u06D0';
  23479. t['\uFBF8'] = '\u0626\u06D0';
  23480. t['\uFBF9'] = '\u0626\u0649';
  23481. t['\uFBFA'] = '\u0626\u0649';
  23482. t['\uFBFB'] = '\u0626\u0649';
  23483. t['\uFBFC'] = '\u06CC';
  23484. t['\uFBFD'] = '\u06CC';
  23485. t['\uFBFE'] = '\u06CC';
  23486. t['\uFBFF'] = '\u06CC';
  23487. t['\uFC00'] = '\u0626\u062C';
  23488. t['\uFC01'] = '\u0626\u062D';
  23489. t['\uFC02'] = '\u0626\u0645';
  23490. t['\uFC03'] = '\u0626\u0649';
  23491. t['\uFC04'] = '\u0626\u064A';
  23492. t['\uFC05'] = '\u0628\u062C';
  23493. t['\uFC06'] = '\u0628\u062D';
  23494. t['\uFC07'] = '\u0628\u062E';
  23495. t['\uFC08'] = '\u0628\u0645';
  23496. t['\uFC09'] = '\u0628\u0649';
  23497. t['\uFC0A'] = '\u0628\u064A';
  23498. t['\uFC0B'] = '\u062A\u062C';
  23499. t['\uFC0C'] = '\u062A\u062D';
  23500. t['\uFC0D'] = '\u062A\u062E';
  23501. t['\uFC0E'] = '\u062A\u0645';
  23502. t['\uFC0F'] = '\u062A\u0649';
  23503. t['\uFC10'] = '\u062A\u064A';
  23504. t['\uFC11'] = '\u062B\u062C';
  23505. t['\uFC12'] = '\u062B\u0645';
  23506. t['\uFC13'] = '\u062B\u0649';
  23507. t['\uFC14'] = '\u062B\u064A';
  23508. t['\uFC15'] = '\u062C\u062D';
  23509. t['\uFC16'] = '\u062C\u0645';
  23510. t['\uFC17'] = '\u062D\u062C';
  23511. t['\uFC18'] = '\u062D\u0645';
  23512. t['\uFC19'] = '\u062E\u062C';
  23513. t['\uFC1A'] = '\u062E\u062D';
  23514. t['\uFC1B'] = '\u062E\u0645';
  23515. t['\uFC1C'] = '\u0633\u062C';
  23516. t['\uFC1D'] = '\u0633\u062D';
  23517. t['\uFC1E'] = '\u0633\u062E';
  23518. t['\uFC1F'] = '\u0633\u0645';
  23519. t['\uFC20'] = '\u0635\u062D';
  23520. t['\uFC21'] = '\u0635\u0645';
  23521. t['\uFC22'] = '\u0636\u062C';
  23522. t['\uFC23'] = '\u0636\u062D';
  23523. t['\uFC24'] = '\u0636\u062E';
  23524. t['\uFC25'] = '\u0636\u0645';
  23525. t['\uFC26'] = '\u0637\u062D';
  23526. t['\uFC27'] = '\u0637\u0645';
  23527. t['\uFC28'] = '\u0638\u0645';
  23528. t['\uFC29'] = '\u0639\u062C';
  23529. t['\uFC2A'] = '\u0639\u0645';
  23530. t['\uFC2B'] = '\u063A\u062C';
  23531. t['\uFC2C'] = '\u063A\u0645';
  23532. t['\uFC2D'] = '\u0641\u062C';
  23533. t['\uFC2E'] = '\u0641\u062D';
  23534. t['\uFC2F'] = '\u0641\u062E';
  23535. t['\uFC30'] = '\u0641\u0645';
  23536. t['\uFC31'] = '\u0641\u0649';
  23537. t['\uFC32'] = '\u0641\u064A';
  23538. t['\uFC33'] = '\u0642\u062D';
  23539. t['\uFC34'] = '\u0642\u0645';
  23540. t['\uFC35'] = '\u0642\u0649';
  23541. t['\uFC36'] = '\u0642\u064A';
  23542. t['\uFC37'] = '\u0643\u0627';
  23543. t['\uFC38'] = '\u0643\u062C';
  23544. t['\uFC39'] = '\u0643\u062D';
  23545. t['\uFC3A'] = '\u0643\u062E';
  23546. t['\uFC3B'] = '\u0643\u0644';
  23547. t['\uFC3C'] = '\u0643\u0645';
  23548. t['\uFC3D'] = '\u0643\u0649';
  23549. t['\uFC3E'] = '\u0643\u064A';
  23550. t['\uFC3F'] = '\u0644\u062C';
  23551. t['\uFC40'] = '\u0644\u062D';
  23552. t['\uFC41'] = '\u0644\u062E';
  23553. t['\uFC42'] = '\u0644\u0645';
  23554. t['\uFC43'] = '\u0644\u0649';
  23555. t['\uFC44'] = '\u0644\u064A';
  23556. t['\uFC45'] = '\u0645\u062C';
  23557. t['\uFC46'] = '\u0645\u062D';
  23558. t['\uFC47'] = '\u0645\u062E';
  23559. t['\uFC48'] = '\u0645\u0645';
  23560. t['\uFC49'] = '\u0645\u0649';
  23561. t['\uFC4A'] = '\u0645\u064A';
  23562. t['\uFC4B'] = '\u0646\u062C';
  23563. t['\uFC4C'] = '\u0646\u062D';
  23564. t['\uFC4D'] = '\u0646\u062E';
  23565. t['\uFC4E'] = '\u0646\u0645';
  23566. t['\uFC4F'] = '\u0646\u0649';
  23567. t['\uFC50'] = '\u0646\u064A';
  23568. t['\uFC51'] = '\u0647\u062C';
  23569. t['\uFC52'] = '\u0647\u0645';
  23570. t['\uFC53'] = '\u0647\u0649';
  23571. t['\uFC54'] = '\u0647\u064A';
  23572. t['\uFC55'] = '\u064A\u062C';
  23573. t['\uFC56'] = '\u064A\u062D';
  23574. t['\uFC57'] = '\u064A\u062E';
  23575. t['\uFC58'] = '\u064A\u0645';
  23576. t['\uFC59'] = '\u064A\u0649';
  23577. t['\uFC5A'] = '\u064A\u064A';
  23578. t['\uFC5B'] = '\u0630\u0670';
  23579. t['\uFC5C'] = '\u0631\u0670';
  23580. t['\uFC5D'] = '\u0649\u0670';
  23581. t['\uFC5E'] = '\u0020\u064C\u0651';
  23582. t['\uFC5F'] = '\u0020\u064D\u0651';
  23583. t['\uFC60'] = '\u0020\u064E\u0651';
  23584. t['\uFC61'] = '\u0020\u064F\u0651';
  23585. t['\uFC62'] = '\u0020\u0650\u0651';
  23586. t['\uFC63'] = '\u0020\u0651\u0670';
  23587. t['\uFC64'] = '\u0626\u0631';
  23588. t['\uFC65'] = '\u0626\u0632';
  23589. t['\uFC66'] = '\u0626\u0645';
  23590. t['\uFC67'] = '\u0626\u0646';
  23591. t['\uFC68'] = '\u0626\u0649';
  23592. t['\uFC69'] = '\u0626\u064A';
  23593. t['\uFC6A'] = '\u0628\u0631';
  23594. t['\uFC6B'] = '\u0628\u0632';
  23595. t['\uFC6C'] = '\u0628\u0645';
  23596. t['\uFC6D'] = '\u0628\u0646';
  23597. t['\uFC6E'] = '\u0628\u0649';
  23598. t['\uFC6F'] = '\u0628\u064A';
  23599. t['\uFC70'] = '\u062A\u0631';
  23600. t['\uFC71'] = '\u062A\u0632';
  23601. t['\uFC72'] = '\u062A\u0645';
  23602. t['\uFC73'] = '\u062A\u0646';
  23603. t['\uFC74'] = '\u062A\u0649';
  23604. t['\uFC75'] = '\u062A\u064A';
  23605. t['\uFC76'] = '\u062B\u0631';
  23606. t['\uFC77'] = '\u062B\u0632';
  23607. t['\uFC78'] = '\u062B\u0645';
  23608. t['\uFC79'] = '\u062B\u0646';
  23609. t['\uFC7A'] = '\u062B\u0649';
  23610. t['\uFC7B'] = '\u062B\u064A';
  23611. t['\uFC7C'] = '\u0641\u0649';
  23612. t['\uFC7D'] = '\u0641\u064A';
  23613. t['\uFC7E'] = '\u0642\u0649';
  23614. t['\uFC7F'] = '\u0642\u064A';
  23615. t['\uFC80'] = '\u0643\u0627';
  23616. t['\uFC81'] = '\u0643\u0644';
  23617. t['\uFC82'] = '\u0643\u0645';
  23618. t['\uFC83'] = '\u0643\u0649';
  23619. t['\uFC84'] = '\u0643\u064A';
  23620. t['\uFC85'] = '\u0644\u0645';
  23621. t['\uFC86'] = '\u0644\u0649';
  23622. t['\uFC87'] = '\u0644\u064A';
  23623. t['\uFC88'] = '\u0645\u0627';
  23624. t['\uFC89'] = '\u0645\u0645';
  23625. t['\uFC8A'] = '\u0646\u0631';
  23626. t['\uFC8B'] = '\u0646\u0632';
  23627. t['\uFC8C'] = '\u0646\u0645';
  23628. t['\uFC8D'] = '\u0646\u0646';
  23629. t['\uFC8E'] = '\u0646\u0649';
  23630. t['\uFC8F'] = '\u0646\u064A';
  23631. t['\uFC90'] = '\u0649\u0670';
  23632. t['\uFC91'] = '\u064A\u0631';
  23633. t['\uFC92'] = '\u064A\u0632';
  23634. t['\uFC93'] = '\u064A\u0645';
  23635. t['\uFC94'] = '\u064A\u0646';
  23636. t['\uFC95'] = '\u064A\u0649';
  23637. t['\uFC96'] = '\u064A\u064A';
  23638. t['\uFC97'] = '\u0626\u062C';
  23639. t['\uFC98'] = '\u0626\u062D';
  23640. t['\uFC99'] = '\u0626\u062E';
  23641. t['\uFC9A'] = '\u0626\u0645';
  23642. t['\uFC9B'] = '\u0626\u0647';
  23643. t['\uFC9C'] = '\u0628\u062C';
  23644. t['\uFC9D'] = '\u0628\u062D';
  23645. t['\uFC9E'] = '\u0628\u062E';
  23646. t['\uFC9F'] = '\u0628\u0645';
  23647. t['\uFCA0'] = '\u0628\u0647';
  23648. t['\uFCA1'] = '\u062A\u062C';
  23649. t['\uFCA2'] = '\u062A\u062D';
  23650. t['\uFCA3'] = '\u062A\u062E';
  23651. t['\uFCA4'] = '\u062A\u0645';
  23652. t['\uFCA5'] = '\u062A\u0647';
  23653. t['\uFCA6'] = '\u062B\u0645';
  23654. t['\uFCA7'] = '\u062C\u062D';
  23655. t['\uFCA8'] = '\u062C\u0645';
  23656. t['\uFCA9'] = '\u062D\u062C';
  23657. t['\uFCAA'] = '\u062D\u0645';
  23658. t['\uFCAB'] = '\u062E\u062C';
  23659. t['\uFCAC'] = '\u062E\u0645';
  23660. t['\uFCAD'] = '\u0633\u062C';
  23661. t['\uFCAE'] = '\u0633\u062D';
  23662. t['\uFCAF'] = '\u0633\u062E';
  23663. t['\uFCB0'] = '\u0633\u0645';
  23664. t['\uFCB1'] = '\u0635\u062D';
  23665. t['\uFCB2'] = '\u0635\u062E';
  23666. t['\uFCB3'] = '\u0635\u0645';
  23667. t['\uFCB4'] = '\u0636\u062C';
  23668. t['\uFCB5'] = '\u0636\u062D';
  23669. t['\uFCB6'] = '\u0636\u062E';
  23670. t['\uFCB7'] = '\u0636\u0645';
  23671. t['\uFCB8'] = '\u0637\u062D';
  23672. t['\uFCB9'] = '\u0638\u0645';
  23673. t['\uFCBA'] = '\u0639\u062C';
  23674. t['\uFCBB'] = '\u0639\u0645';
  23675. t['\uFCBC'] = '\u063A\u062C';
  23676. t['\uFCBD'] = '\u063A\u0645';
  23677. t['\uFCBE'] = '\u0641\u062C';
  23678. t['\uFCBF'] = '\u0641\u062D';
  23679. t['\uFCC0'] = '\u0641\u062E';
  23680. t['\uFCC1'] = '\u0641\u0645';
  23681. t['\uFCC2'] = '\u0642\u062D';
  23682. t['\uFCC3'] = '\u0642\u0645';
  23683. t['\uFCC4'] = '\u0643\u062C';
  23684. t['\uFCC5'] = '\u0643\u062D';
  23685. t['\uFCC6'] = '\u0643\u062E';
  23686. t['\uFCC7'] = '\u0643\u0644';
  23687. t['\uFCC8'] = '\u0643\u0645';
  23688. t['\uFCC9'] = '\u0644\u062C';
  23689. t['\uFCCA'] = '\u0644\u062D';
  23690. t['\uFCCB'] = '\u0644\u062E';
  23691. t['\uFCCC'] = '\u0644\u0645';
  23692. t['\uFCCD'] = '\u0644\u0647';
  23693. t['\uFCCE'] = '\u0645\u062C';
  23694. t['\uFCCF'] = '\u0645\u062D';
  23695. t['\uFCD0'] = '\u0645\u062E';
  23696. t['\uFCD1'] = '\u0645\u0645';
  23697. t['\uFCD2'] = '\u0646\u062C';
  23698. t['\uFCD3'] = '\u0646\u062D';
  23699. t['\uFCD4'] = '\u0646\u062E';
  23700. t['\uFCD5'] = '\u0646\u0645';
  23701. t['\uFCD6'] = '\u0646\u0647';
  23702. t['\uFCD7'] = '\u0647\u062C';
  23703. t['\uFCD8'] = '\u0647\u0645';
  23704. t['\uFCD9'] = '\u0647\u0670';
  23705. t['\uFCDA'] = '\u064A\u062C';
  23706. t['\uFCDB'] = '\u064A\u062D';
  23707. t['\uFCDC'] = '\u064A\u062E';
  23708. t['\uFCDD'] = '\u064A\u0645';
  23709. t['\uFCDE'] = '\u064A\u0647';
  23710. t['\uFCDF'] = '\u0626\u0645';
  23711. t['\uFCE0'] = '\u0626\u0647';
  23712. t['\uFCE1'] = '\u0628\u0645';
  23713. t['\uFCE2'] = '\u0628\u0647';
  23714. t['\uFCE3'] = '\u062A\u0645';
  23715. t['\uFCE4'] = '\u062A\u0647';
  23716. t['\uFCE5'] = '\u062B\u0645';
  23717. t['\uFCE6'] = '\u062B\u0647';
  23718. t['\uFCE7'] = '\u0633\u0645';
  23719. t['\uFCE8'] = '\u0633\u0647';
  23720. t['\uFCE9'] = '\u0634\u0645';
  23721. t['\uFCEA'] = '\u0634\u0647';
  23722. t['\uFCEB'] = '\u0643\u0644';
  23723. t['\uFCEC'] = '\u0643\u0645';
  23724. t['\uFCED'] = '\u0644\u0645';
  23725. t['\uFCEE'] = '\u0646\u0645';
  23726. t['\uFCEF'] = '\u0646\u0647';
  23727. t['\uFCF0'] = '\u064A\u0645';
  23728. t['\uFCF1'] = '\u064A\u0647';
  23729. t['\uFCF2'] = '\u0640\u064E\u0651';
  23730. t['\uFCF3'] = '\u0640\u064F\u0651';
  23731. t['\uFCF4'] = '\u0640\u0650\u0651';
  23732. t['\uFCF5'] = '\u0637\u0649';
  23733. t['\uFCF6'] = '\u0637\u064A';
  23734. t['\uFCF7'] = '\u0639\u0649';
  23735. t['\uFCF8'] = '\u0639\u064A';
  23736. t['\uFCF9'] = '\u063A\u0649';
  23737. t['\uFCFA'] = '\u063A\u064A';
  23738. t['\uFCFB'] = '\u0633\u0649';
  23739. t['\uFCFC'] = '\u0633\u064A';
  23740. t['\uFCFD'] = '\u0634\u0649';
  23741. t['\uFCFE'] = '\u0634\u064A';
  23742. t['\uFCFF'] = '\u062D\u0649';
  23743. t['\uFD00'] = '\u062D\u064A';
  23744. t['\uFD01'] = '\u062C\u0649';
  23745. t['\uFD02'] = '\u062C\u064A';
  23746. t['\uFD03'] = '\u062E\u0649';
  23747. t['\uFD04'] = '\u062E\u064A';
  23748. t['\uFD05'] = '\u0635\u0649';
  23749. t['\uFD06'] = '\u0635\u064A';
  23750. t['\uFD07'] = '\u0636\u0649';
  23751. t['\uFD08'] = '\u0636\u064A';
  23752. t['\uFD09'] = '\u0634\u062C';
  23753. t['\uFD0A'] = '\u0634\u062D';
  23754. t['\uFD0B'] = '\u0634\u062E';
  23755. t['\uFD0C'] = '\u0634\u0645';
  23756. t['\uFD0D'] = '\u0634\u0631';
  23757. t['\uFD0E'] = '\u0633\u0631';
  23758. t['\uFD0F'] = '\u0635\u0631';
  23759. t['\uFD10'] = '\u0636\u0631';
  23760. t['\uFD11'] = '\u0637\u0649';
  23761. t['\uFD12'] = '\u0637\u064A';
  23762. t['\uFD13'] = '\u0639\u0649';
  23763. t['\uFD14'] = '\u0639\u064A';
  23764. t['\uFD15'] = '\u063A\u0649';
  23765. t['\uFD16'] = '\u063A\u064A';
  23766. t['\uFD17'] = '\u0633\u0649';
  23767. t['\uFD18'] = '\u0633\u064A';
  23768. t['\uFD19'] = '\u0634\u0649';
  23769. t['\uFD1A'] = '\u0634\u064A';
  23770. t['\uFD1B'] = '\u062D\u0649';
  23771. t['\uFD1C'] = '\u062D\u064A';
  23772. t['\uFD1D'] = '\u062C\u0649';
  23773. t['\uFD1E'] = '\u062C\u064A';
  23774. t['\uFD1F'] = '\u062E\u0649';
  23775. t['\uFD20'] = '\u062E\u064A';
  23776. t['\uFD21'] = '\u0635\u0649';
  23777. t['\uFD22'] = '\u0635\u064A';
  23778. t['\uFD23'] = '\u0636\u0649';
  23779. t['\uFD24'] = '\u0636\u064A';
  23780. t['\uFD25'] = '\u0634\u062C';
  23781. t['\uFD26'] = '\u0634\u062D';
  23782. t['\uFD27'] = '\u0634\u062E';
  23783. t['\uFD28'] = '\u0634\u0645';
  23784. t['\uFD29'] = '\u0634\u0631';
  23785. t['\uFD2A'] = '\u0633\u0631';
  23786. t['\uFD2B'] = '\u0635\u0631';
  23787. t['\uFD2C'] = '\u0636\u0631';
  23788. t['\uFD2D'] = '\u0634\u062C';
  23789. t['\uFD2E'] = '\u0634\u062D';
  23790. t['\uFD2F'] = '\u0634\u062E';
  23791. t['\uFD30'] = '\u0634\u0645';
  23792. t['\uFD31'] = '\u0633\u0647';
  23793. t['\uFD32'] = '\u0634\u0647';
  23794. t['\uFD33'] = '\u0637\u0645';
  23795. t['\uFD34'] = '\u0633\u062C';
  23796. t['\uFD35'] = '\u0633\u062D';
  23797. t['\uFD36'] = '\u0633\u062E';
  23798. t['\uFD37'] = '\u0634\u062C';
  23799. t['\uFD38'] = '\u0634\u062D';
  23800. t['\uFD39'] = '\u0634\u062E';
  23801. t['\uFD3A'] = '\u0637\u0645';
  23802. t['\uFD3B'] = '\u0638\u0645';
  23803. t['\uFD3C'] = '\u0627\u064B';
  23804. t['\uFD3D'] = '\u0627\u064B';
  23805. t['\uFD50'] = '\u062A\u062C\u0645';
  23806. t['\uFD51'] = '\u062A\u062D\u062C';
  23807. t['\uFD52'] = '\u062A\u062D\u062C';
  23808. t['\uFD53'] = '\u062A\u062D\u0645';
  23809. t['\uFD54'] = '\u062A\u062E\u0645';
  23810. t['\uFD55'] = '\u062A\u0645\u062C';
  23811. t['\uFD56'] = '\u062A\u0645\u062D';
  23812. t['\uFD57'] = '\u062A\u0645\u062E';
  23813. t['\uFD58'] = '\u062C\u0645\u062D';
  23814. t['\uFD59'] = '\u062C\u0645\u062D';
  23815. t['\uFD5A'] = '\u062D\u0645\u064A';
  23816. t['\uFD5B'] = '\u062D\u0645\u0649';
  23817. t['\uFD5C'] = '\u0633\u062D\u062C';
  23818. t['\uFD5D'] = '\u0633\u062C\u062D';
  23819. t['\uFD5E'] = '\u0633\u062C\u0649';
  23820. t['\uFD5F'] = '\u0633\u0645\u062D';
  23821. t['\uFD60'] = '\u0633\u0645\u062D';
  23822. t['\uFD61'] = '\u0633\u0645\u062C';
  23823. t['\uFD62'] = '\u0633\u0645\u0645';
  23824. t['\uFD63'] = '\u0633\u0645\u0645';
  23825. t['\uFD64'] = '\u0635\u062D\u062D';
  23826. t['\uFD65'] = '\u0635\u062D\u062D';
  23827. t['\uFD66'] = '\u0635\u0645\u0645';
  23828. t['\uFD67'] = '\u0634\u062D\u0645';
  23829. t['\uFD68'] = '\u0634\u062D\u0645';
  23830. t['\uFD69'] = '\u0634\u062C\u064A';
  23831. t['\uFD6A'] = '\u0634\u0645\u062E';
  23832. t['\uFD6B'] = '\u0634\u0645\u062E';
  23833. t['\uFD6C'] = '\u0634\u0645\u0645';
  23834. t['\uFD6D'] = '\u0634\u0645\u0645';
  23835. t['\uFD6E'] = '\u0636\u062D\u0649';
  23836. t['\uFD6F'] = '\u0636\u062E\u0645';
  23837. t['\uFD70'] = '\u0636\u062E\u0645';
  23838. t['\uFD71'] = '\u0637\u0645\u062D';
  23839. t['\uFD72'] = '\u0637\u0645\u062D';
  23840. t['\uFD73'] = '\u0637\u0645\u0645';
  23841. t['\uFD74'] = '\u0637\u0645\u064A';
  23842. t['\uFD75'] = '\u0639\u062C\u0645';
  23843. t['\uFD76'] = '\u0639\u0645\u0645';
  23844. t['\uFD77'] = '\u0639\u0645\u0645';
  23845. t['\uFD78'] = '\u0639\u0645\u0649';
  23846. t['\uFD79'] = '\u063A\u0645\u0645';
  23847. t['\uFD7A'] = '\u063A\u0645\u064A';
  23848. t['\uFD7B'] = '\u063A\u0645\u0649';
  23849. t['\uFD7C'] = '\u0641\u062E\u0645';
  23850. t['\uFD7D'] = '\u0641\u062E\u0645';
  23851. t['\uFD7E'] = '\u0642\u0645\u062D';
  23852. t['\uFD7F'] = '\u0642\u0645\u0645';
  23853. t['\uFD80'] = '\u0644\u062D\u0645';
  23854. t['\uFD81'] = '\u0644\u062D\u064A';
  23855. t['\uFD82'] = '\u0644\u062D\u0649';
  23856. t['\uFD83'] = '\u0644\u062C\u062C';
  23857. t['\uFD84'] = '\u0644\u062C\u062C';
  23858. t['\uFD85'] = '\u0644\u062E\u0645';
  23859. t['\uFD86'] = '\u0644\u062E\u0645';
  23860. t['\uFD87'] = '\u0644\u0645\u062D';
  23861. t['\uFD88'] = '\u0644\u0645\u062D';
  23862. t['\uFD89'] = '\u0645\u062D\u062C';
  23863. t['\uFD8A'] = '\u0645\u062D\u0645';
  23864. t['\uFD8B'] = '\u0645\u062D\u064A';
  23865. t['\uFD8C'] = '\u0645\u062C\u062D';
  23866. t['\uFD8D'] = '\u0645\u062C\u0645';
  23867. t['\uFD8E'] = '\u0645\u062E\u062C';
  23868. t['\uFD8F'] = '\u0645\u062E\u0645';
  23869. t['\uFD92'] = '\u0645\u062C\u062E';
  23870. t['\uFD93'] = '\u0647\u0645\u062C';
  23871. t['\uFD94'] = '\u0647\u0645\u0645';
  23872. t['\uFD95'] = '\u0646\u062D\u0645';
  23873. t['\uFD96'] = '\u0646\u062D\u0649';
  23874. t['\uFD97'] = '\u0646\u062C\u0645';
  23875. t['\uFD98'] = '\u0646\u062C\u0645';
  23876. t['\uFD99'] = '\u0646\u062C\u0649';
  23877. t['\uFD9A'] = '\u0646\u0645\u064A';
  23878. t['\uFD9B'] = '\u0646\u0645\u0649';
  23879. t['\uFD9C'] = '\u064A\u0645\u0645';
  23880. t['\uFD9D'] = '\u064A\u0645\u0645';
  23881. t['\uFD9E'] = '\u0628\u062E\u064A';
  23882. t['\uFD9F'] = '\u062A\u062C\u064A';
  23883. t['\uFDA0'] = '\u062A\u062C\u0649';
  23884. t['\uFDA1'] = '\u062A\u062E\u064A';
  23885. t['\uFDA2'] = '\u062A\u062E\u0649';
  23886. t['\uFDA3'] = '\u062A\u0645\u064A';
  23887. t['\uFDA4'] = '\u062A\u0645\u0649';
  23888. t['\uFDA5'] = '\u062C\u0645\u064A';
  23889. t['\uFDA6'] = '\u062C\u062D\u0649';
  23890. t['\uFDA7'] = '\u062C\u0645\u0649';
  23891. t['\uFDA8'] = '\u0633\u062E\u0649';
  23892. t['\uFDA9'] = '\u0635\u062D\u064A';
  23893. t['\uFDAA'] = '\u0634\u062D\u064A';
  23894. t['\uFDAB'] = '\u0636\u062D\u064A';
  23895. t['\uFDAC'] = '\u0644\u062C\u064A';
  23896. t['\uFDAD'] = '\u0644\u0645\u064A';
  23897. t['\uFDAE'] = '\u064A\u062D\u064A';
  23898. t['\uFDAF'] = '\u064A\u062C\u064A';
  23899. t['\uFDB0'] = '\u064A\u0645\u064A';
  23900. t['\uFDB1'] = '\u0645\u0645\u064A';
  23901. t['\uFDB2'] = '\u0642\u0645\u064A';
  23902. t['\uFDB3'] = '\u0646\u062D\u064A';
  23903. t['\uFDB4'] = '\u0642\u0645\u062D';
  23904. t['\uFDB5'] = '\u0644\u062D\u0645';
  23905. t['\uFDB6'] = '\u0639\u0645\u064A';
  23906. t['\uFDB7'] = '\u0643\u0645\u064A';
  23907. t['\uFDB8'] = '\u0646\u062C\u062D';
  23908. t['\uFDB9'] = '\u0645\u062E\u064A';
  23909. t['\uFDBA'] = '\u0644\u062C\u0645';
  23910. t['\uFDBB'] = '\u0643\u0645\u0645';
  23911. t['\uFDBC'] = '\u0644\u062C\u0645';
  23912. t['\uFDBD'] = '\u0646\u062C\u062D';
  23913. t['\uFDBE'] = '\u062C\u062D\u064A';
  23914. t['\uFDBF'] = '\u062D\u062C\u064A';
  23915. t['\uFDC0'] = '\u0645\u062C\u064A';
  23916. t['\uFDC1'] = '\u0641\u0645\u064A';
  23917. t['\uFDC2'] = '\u0628\u062D\u064A';
  23918. t['\uFDC3'] = '\u0643\u0645\u0645';
  23919. t['\uFDC4'] = '\u0639\u062C\u0645';
  23920. t['\uFDC5'] = '\u0635\u0645\u0645';
  23921. t['\uFDC6'] = '\u0633\u062E\u064A';
  23922. t['\uFDC7'] = '\u0646\u062C\u064A';
  23923. t['\uFE49'] = '\u203E';
  23924. t['\uFE4A'] = '\u203E';
  23925. t['\uFE4B'] = '\u203E';
  23926. t['\uFE4C'] = '\u203E';
  23927. t['\uFE4D'] = '\u005F';
  23928. t['\uFE4E'] = '\u005F';
  23929. t['\uFE4F'] = '\u005F';
  23930. t['\uFE80'] = '\u0621';
  23931. t['\uFE81'] = '\u0622';
  23932. t['\uFE82'] = '\u0622';
  23933. t['\uFE83'] = '\u0623';
  23934. t['\uFE84'] = '\u0623';
  23935. t['\uFE85'] = '\u0624';
  23936. t['\uFE86'] = '\u0624';
  23937. t['\uFE87'] = '\u0625';
  23938. t['\uFE88'] = '\u0625';
  23939. t['\uFE89'] = '\u0626';
  23940. t['\uFE8A'] = '\u0626';
  23941. t['\uFE8B'] = '\u0626';
  23942. t['\uFE8C'] = '\u0626';
  23943. t['\uFE8D'] = '\u0627';
  23944. t['\uFE8E'] = '\u0627';
  23945. t['\uFE8F'] = '\u0628';
  23946. t['\uFE90'] = '\u0628';
  23947. t['\uFE91'] = '\u0628';
  23948. t['\uFE92'] = '\u0628';
  23949. t['\uFE93'] = '\u0629';
  23950. t['\uFE94'] = '\u0629';
  23951. t['\uFE95'] = '\u062A';
  23952. t['\uFE96'] = '\u062A';
  23953. t['\uFE97'] = '\u062A';
  23954. t['\uFE98'] = '\u062A';
  23955. t['\uFE99'] = '\u062B';
  23956. t['\uFE9A'] = '\u062B';
  23957. t['\uFE9B'] = '\u062B';
  23958. t['\uFE9C'] = '\u062B';
  23959. t['\uFE9D'] = '\u062C';
  23960. t['\uFE9E'] = '\u062C';
  23961. t['\uFE9F'] = '\u062C';
  23962. t['\uFEA0'] = '\u062C';
  23963. t['\uFEA1'] = '\u062D';
  23964. t['\uFEA2'] = '\u062D';
  23965. t['\uFEA3'] = '\u062D';
  23966. t['\uFEA4'] = '\u062D';
  23967. t['\uFEA5'] = '\u062E';
  23968. t['\uFEA6'] = '\u062E';
  23969. t['\uFEA7'] = '\u062E';
  23970. t['\uFEA8'] = '\u062E';
  23971. t['\uFEA9'] = '\u062F';
  23972. t['\uFEAA'] = '\u062F';
  23973. t['\uFEAB'] = '\u0630';
  23974. t['\uFEAC'] = '\u0630';
  23975. t['\uFEAD'] = '\u0631';
  23976. t['\uFEAE'] = '\u0631';
  23977. t['\uFEAF'] = '\u0632';
  23978. t['\uFEB0'] = '\u0632';
  23979. t['\uFEB1'] = '\u0633';
  23980. t['\uFEB2'] = '\u0633';
  23981. t['\uFEB3'] = '\u0633';
  23982. t['\uFEB4'] = '\u0633';
  23983. t['\uFEB5'] = '\u0634';
  23984. t['\uFEB6'] = '\u0634';
  23985. t['\uFEB7'] = '\u0634';
  23986. t['\uFEB8'] = '\u0634';
  23987. t['\uFEB9'] = '\u0635';
  23988. t['\uFEBA'] = '\u0635';
  23989. t['\uFEBB'] = '\u0635';
  23990. t['\uFEBC'] = '\u0635';
  23991. t['\uFEBD'] = '\u0636';
  23992. t['\uFEBE'] = '\u0636';
  23993. t['\uFEBF'] = '\u0636';
  23994. t['\uFEC0'] = '\u0636';
  23995. t['\uFEC1'] = '\u0637';
  23996. t['\uFEC2'] = '\u0637';
  23997. t['\uFEC3'] = '\u0637';
  23998. t['\uFEC4'] = '\u0637';
  23999. t['\uFEC5'] = '\u0638';
  24000. t['\uFEC6'] = '\u0638';
  24001. t['\uFEC7'] = '\u0638';
  24002. t['\uFEC8'] = '\u0638';
  24003. t['\uFEC9'] = '\u0639';
  24004. t['\uFECA'] = '\u0639';
  24005. t['\uFECB'] = '\u0639';
  24006. t['\uFECC'] = '\u0639';
  24007. t['\uFECD'] = '\u063A';
  24008. t['\uFECE'] = '\u063A';
  24009. t['\uFECF'] = '\u063A';
  24010. t['\uFED0'] = '\u063A';
  24011. t['\uFED1'] = '\u0641';
  24012. t['\uFED2'] = '\u0641';
  24013. t['\uFED3'] = '\u0641';
  24014. t['\uFED4'] = '\u0641';
  24015. t['\uFED5'] = '\u0642';
  24016. t['\uFED6'] = '\u0642';
  24017. t['\uFED7'] = '\u0642';
  24018. t['\uFED8'] = '\u0642';
  24019. t['\uFED9'] = '\u0643';
  24020. t['\uFEDA'] = '\u0643';
  24021. t['\uFEDB'] = '\u0643';
  24022. t['\uFEDC'] = '\u0643';
  24023. t['\uFEDD'] = '\u0644';
  24024. t['\uFEDE'] = '\u0644';
  24025. t['\uFEDF'] = '\u0644';
  24026. t['\uFEE0'] = '\u0644';
  24027. t['\uFEE1'] = '\u0645';
  24028. t['\uFEE2'] = '\u0645';
  24029. t['\uFEE3'] = '\u0645';
  24030. t['\uFEE4'] = '\u0645';
  24031. t['\uFEE5'] = '\u0646';
  24032. t['\uFEE6'] = '\u0646';
  24033. t['\uFEE7'] = '\u0646';
  24034. t['\uFEE8'] = '\u0646';
  24035. t['\uFEE9'] = '\u0647';
  24036. t['\uFEEA'] = '\u0647';
  24037. t['\uFEEB'] = '\u0647';
  24038. t['\uFEEC'] = '\u0647';
  24039. t['\uFEED'] = '\u0648';
  24040. t['\uFEEE'] = '\u0648';
  24041. t['\uFEEF'] = '\u0649';
  24042. t['\uFEF0'] = '\u0649';
  24043. t['\uFEF1'] = '\u064A';
  24044. t['\uFEF2'] = '\u064A';
  24045. t['\uFEF3'] = '\u064A';
  24046. t['\uFEF4'] = '\u064A';
  24047. t['\uFEF5'] = '\u0644\u0622';
  24048. t['\uFEF6'] = '\u0644\u0622';
  24049. t['\uFEF7'] = '\u0644\u0623';
  24050. t['\uFEF8'] = '\u0644\u0623';
  24051. t['\uFEF9'] = '\u0644\u0625';
  24052. t['\uFEFA'] = '\u0644\u0625';
  24053. t['\uFEFB'] = '\u0644\u0627';
  24054. t['\uFEFC'] = '\u0644\u0627';
  24055. });
  24056. function reverseIfRtl(chars) {
  24057. var charsLength = chars.length;
  24058. //reverse an arabic ligature
  24059. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  24060. return chars;
  24061. }
  24062. var s = '';
  24063. for (var ii = charsLength - 1; ii >= 0; ii--) {
  24064. s += chars[ii];
  24065. }
  24066. return s;
  24067. }
  24068. exports.mapSpecialUnicodeValues = mapSpecialUnicodeValues;
  24069. exports.reverseIfRtl = reverseIfRtl;
  24070. exports.getUnicodeRangeFor = getUnicodeRangeFor;
  24071. exports.getNormalizedUnicodes = getNormalizedUnicodes;
  24072. exports.getUnicodeForGlyph = getUnicodeForGlyph;
  24073. }));
  24074. (function (root, factory) {
  24075. factory(root.pdfjsDisplayDOMUtils = {}, root.pdfjsSharedUtil);
  24076. }(this, function (exports, sharedUtil) {
  24077. var removeNullCharacters = sharedUtil.removeNullCharacters;
  24078. var warn = sharedUtil.warn;
  24079. /**
  24080. * Optimised CSS custom property getter/setter.
  24081. * @class
  24082. */
  24083. var CustomStyle = function CustomStyleClosure() {
  24084. // As noted on: http://www.zachstronaut.com/posts/2009/02/17/
  24085. // animate-css-transforms-firefox-webkit.html
  24086. // in some versions of IE9 it is critical that ms appear in this list
  24087. // before Moz
  24088. var prefixes = [
  24089. 'ms',
  24090. 'Moz',
  24091. 'Webkit',
  24092. 'O'
  24093. ];
  24094. var _cache = Object.create(null);
  24095. function CustomStyle() {
  24096. }
  24097. CustomStyle.getProp = function get(propName, element) {
  24098. // check cache only when no element is given
  24099. if (arguments.length === 1 && typeof _cache[propName] === 'string') {
  24100. return _cache[propName];
  24101. }
  24102. element = element || document.documentElement;
  24103. var style = element.style, prefixed, uPropName;
  24104. // test standard property first
  24105. if (typeof style[propName] === 'string') {
  24106. return _cache[propName] = propName;
  24107. }
  24108. // capitalize
  24109. uPropName = propName.charAt(0).toUpperCase() + propName.slice(1);
  24110. // test vendor specific properties
  24111. for (var i = 0, l = prefixes.length; i < l; i++) {
  24112. prefixed = prefixes[i] + uPropName;
  24113. if (typeof style[prefixed] === 'string') {
  24114. return _cache[propName] = prefixed;
  24115. }
  24116. }
  24117. //if all fails then set to undefined
  24118. return _cache[propName] = 'undefined';
  24119. };
  24120. CustomStyle.setProp = function set(propName, element, str) {
  24121. var prop = this.getProp(propName);
  24122. if (prop !== 'undefined') {
  24123. element.style[prop] = str;
  24124. }
  24125. };
  24126. return CustomStyle;
  24127. }();
  24128. var hasCanvasTypedArrays;
  24129. hasCanvasTypedArrays = function hasCanvasTypedArrays() {
  24130. var canvas = document.createElement('canvas');
  24131. canvas.width = canvas.height = 1;
  24132. var ctx = canvas.getContext('2d');
  24133. var imageData = ctx.createImageData(1, 1);
  24134. return typeof imageData.data.buffer !== 'undefined';
  24135. };
  24136. var LinkTarget = {
  24137. NONE: 0,
  24138. // Default value.
  24139. SELF: 1,
  24140. BLANK: 2,
  24141. PARENT: 3,
  24142. TOP: 4
  24143. };
  24144. var LinkTargetStringMap = [
  24145. '',
  24146. '_self',
  24147. '_blank',
  24148. '_parent',
  24149. '_top'
  24150. ];
  24151. /**
  24152. * @typedef ExternalLinkParameters
  24153. * @typedef {Object} ExternalLinkParameters
  24154. * @property {string} url - An absolute URL.
  24155. * @property {LinkTarget} target - The link target.
  24156. * @property {string} rel - The link relationship.
  24157. */
  24158. /**
  24159. * Adds various attributes (href, title, target, rel) to hyperlinks.
  24160. * @param {HTMLLinkElement} link - The link element.
  24161. * @param {ExternalLinkParameters} params
  24162. */
  24163. function addLinkAttributes(link, params) {
  24164. var url = params && params.url;
  24165. link.href = link.title = url ? removeNullCharacters(url) : '';
  24166. if (url) {
  24167. var target = params.target;
  24168. if (typeof target === 'undefined') {
  24169. target = getDefaultSetting('externalLinkTarget');
  24170. }
  24171. link.target = LinkTargetStringMap[target];
  24172. var rel = params.rel;
  24173. if (typeof rel === 'undefined') {
  24174. rel = getDefaultSetting('externalLinkRel');
  24175. }
  24176. link.rel = rel;
  24177. }
  24178. }
  24179. // Gets the file name from a given URL.
  24180. function getFilenameFromUrl(url) {
  24181. var anchor = url.indexOf('#');
  24182. var query = url.indexOf('?');
  24183. var end = Math.min(anchor > 0 ? anchor : url.length, query > 0 ? query : url.length);
  24184. return url.substring(url.lastIndexOf('/', end) + 1, end);
  24185. }
  24186. function getDefaultSetting(id) {
  24187. // The list of the settings and their default is maintained for backward
  24188. // compatibility and shall not be extended or modified. See also global.js.
  24189. var globalSettings = sharedUtil.globalScope.PDFJS;
  24190. switch (id) {
  24191. case 'pdfBug':
  24192. return globalSettings ? globalSettings.pdfBug : false;
  24193. case 'disableAutoFetch':
  24194. return globalSettings ? globalSettings.disableAutoFetch : false;
  24195. case 'disableStream':
  24196. return globalSettings ? globalSettings.disableStream : false;
  24197. case 'disableRange':
  24198. return globalSettings ? globalSettings.disableRange : false;
  24199. case 'disableFontFace':
  24200. return globalSettings ? globalSettings.disableFontFace : false;
  24201. case 'disableCreateObjectURL':
  24202. return globalSettings ? globalSettings.disableCreateObjectURL : false;
  24203. case 'disableWebGL':
  24204. return globalSettings ? globalSettings.disableWebGL : true;
  24205. case 'cMapUrl':
  24206. return globalSettings ? globalSettings.cMapUrl : null;
  24207. case 'cMapPacked':
  24208. return globalSettings ? globalSettings.cMapPacked : false;
  24209. case 'postMessageTransfers':
  24210. return globalSettings ? globalSettings.postMessageTransfers : true;
  24211. case 'workerSrc':
  24212. return globalSettings ? globalSettings.workerSrc : null;
  24213. case 'disableWorker':
  24214. return globalSettings ? globalSettings.disableWorker : false;
  24215. case 'maxImageSize':
  24216. return globalSettings ? globalSettings.maxImageSize : -1;
  24217. case 'imageResourcesPath':
  24218. return globalSettings ? globalSettings.imageResourcesPath : '';
  24219. case 'isEvalSupported':
  24220. return globalSettings ? globalSettings.isEvalSupported : true;
  24221. case 'externalLinkTarget':
  24222. if (!globalSettings) {
  24223. return LinkTarget.NONE;
  24224. }
  24225. switch (globalSettings.externalLinkTarget) {
  24226. case LinkTarget.NONE:
  24227. case LinkTarget.SELF:
  24228. case LinkTarget.BLANK:
  24229. case LinkTarget.PARENT:
  24230. case LinkTarget.TOP:
  24231. return globalSettings.externalLinkTarget;
  24232. }
  24233. warn('PDFJS.externalLinkTarget is invalid: ' + globalSettings.externalLinkTarget);
  24234. // Reset the external link target, to suppress further warnings.
  24235. globalSettings.externalLinkTarget = LinkTarget.NONE;
  24236. return LinkTarget.NONE;
  24237. case 'externalLinkRel':
  24238. return globalSettings ? globalSettings.externalLinkRel : 'noreferrer';
  24239. case 'enableStats':
  24240. return !!(globalSettings && globalSettings.enableStats);
  24241. default:
  24242. throw new Error('Unknown default setting: ' + id);
  24243. }
  24244. }
  24245. function isExternalLinkTargetSet() {
  24246. var externalLinkTarget = getDefaultSetting('externalLinkTarget');
  24247. switch (externalLinkTarget) {
  24248. case LinkTarget.NONE:
  24249. return false;
  24250. case LinkTarget.SELF:
  24251. case LinkTarget.BLANK:
  24252. case LinkTarget.PARENT:
  24253. case LinkTarget.TOP:
  24254. return true;
  24255. }
  24256. }
  24257. exports.CustomStyle = CustomStyle;
  24258. exports.addLinkAttributes = addLinkAttributes;
  24259. exports.isExternalLinkTargetSet = isExternalLinkTargetSet;
  24260. exports.getFilenameFromUrl = getFilenameFromUrl;
  24261. exports.LinkTarget = LinkTarget;
  24262. exports.hasCanvasTypedArrays = hasCanvasTypedArrays;
  24263. exports.getDefaultSetting = getDefaultSetting;
  24264. }));
  24265. (function (root, factory) {
  24266. factory(root.pdfjsDisplayFontLoader = {}, root.pdfjsSharedUtil);
  24267. }(this, function (exports, sharedUtil) {
  24268. var assert = sharedUtil.assert;
  24269. var bytesToString = sharedUtil.bytesToString;
  24270. var string32 = sharedUtil.string32;
  24271. var shadow = sharedUtil.shadow;
  24272. var warn = sharedUtil.warn;
  24273. function FontLoader(docId) {
  24274. this.docId = docId;
  24275. this.styleElement = null;
  24276. this.nativeFontFaces = [];
  24277. this.loadTestFontId = 0;
  24278. this.loadingContext = {
  24279. requests: [],
  24280. nextRequestId: 0
  24281. };
  24282. }
  24283. FontLoader.prototype = {
  24284. insertRule: function fontLoaderInsertRule(rule) {
  24285. var styleElement = this.styleElement;
  24286. if (!styleElement) {
  24287. styleElement = this.styleElement = document.createElement('style');
  24288. styleElement.id = 'PDFJS_FONT_STYLE_TAG_' + this.docId;
  24289. document.documentElement.getElementsByTagName('head')[0].appendChild(styleElement);
  24290. }
  24291. var styleSheet = styleElement.sheet;
  24292. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  24293. },
  24294. clear: function fontLoaderClear() {
  24295. var styleElement = this.styleElement;
  24296. if (styleElement) {
  24297. styleElement.parentNode.removeChild(styleElement);
  24298. styleElement = this.styleElement = null;
  24299. }
  24300. this.nativeFontFaces.forEach(function (nativeFontFace) {
  24301. document.fonts.delete(nativeFontFace);
  24302. });
  24303. this.nativeFontFaces.length = 0;
  24304. }
  24305. };
  24306. var getLoadTestFont = function () {
  24307. // This is a CFF font with 1 glyph for '.' that fills its entire width and
  24308. // height.
  24309. return atob('T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQ' + 'AABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwA' + 'AAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbm' + 'FtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAA' + 'AADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6A' + 'ABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAA' + 'MQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAA' + 'AAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAA' + 'AAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQ' + 'AAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMA' + 'AQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAA' + 'EAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAA' + 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAA' + 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' + 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' + 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' + 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAA' + 'AAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgc' + 'A/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWF' + 'hYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQA' + 'AAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAg' + 'ABAAAAAAAAAAAD6AAAAAAAAA==');
  24310. };
  24311. Object.defineProperty(FontLoader.prototype, 'loadTestFont', {
  24312. get: function () {
  24313. return shadow(this, 'loadTestFont', getLoadTestFont());
  24314. },
  24315. configurable: true
  24316. });
  24317. FontLoader.prototype.addNativeFontFace = function fontLoader_addNativeFontFace(nativeFontFace) {
  24318. this.nativeFontFaces.push(nativeFontFace);
  24319. document.fonts.add(nativeFontFace);
  24320. };
  24321. FontLoader.prototype.bind = function fontLoaderBind(fonts, callback) {
  24322. var rules = [];
  24323. var fontsToLoad = [];
  24324. var fontLoadPromises = [];
  24325. var getNativeFontPromise = function (nativeFontFace) {
  24326. // Return a promise that is always fulfilled, even when the font fails to
  24327. // load.
  24328. return nativeFontFace.loaded.catch(function (e) {
  24329. warn('Failed to load font "' + nativeFontFace.family + '": ' + e);
  24330. });
  24331. };
  24332. // Firefox Font Loading API does not work with mozPrintCallback --
  24333. // disabling it in this case.
  24334. var isFontLoadingAPISupported = FontLoader.isFontLoadingAPISupported && !FontLoader.isSyncFontLoadingSupported;
  24335. for (var i = 0, ii = fonts.length; i < ii; i++) {
  24336. var font = fonts[i];
  24337. // Add the font to the DOM only once or skip if the font
  24338. // is already loaded.
  24339. if (font.attached || font.loading === false) {
  24340. continue;
  24341. }
  24342. font.attached = true;
  24343. if (isFontLoadingAPISupported) {
  24344. var nativeFontFace = font.createNativeFontFace();
  24345. if (nativeFontFace) {
  24346. this.addNativeFontFace(nativeFontFace);
  24347. fontLoadPromises.push(getNativeFontPromise(nativeFontFace));
  24348. }
  24349. } else {
  24350. var rule = font.createFontFaceRule();
  24351. if (rule) {
  24352. this.insertRule(rule);
  24353. rules.push(rule);
  24354. fontsToLoad.push(font);
  24355. }
  24356. }
  24357. }
  24358. var request = this.queueLoadingCallback(callback);
  24359. if (isFontLoadingAPISupported) {
  24360. Promise.all(fontLoadPromises).then(function () {
  24361. request.complete();
  24362. });
  24363. } else if (rules.length > 0 && !FontLoader.isSyncFontLoadingSupported) {
  24364. this.prepareFontLoadEvent(rules, fontsToLoad, request);
  24365. } else {
  24366. request.complete();
  24367. }
  24368. };
  24369. FontLoader.prototype.queueLoadingCallback = function FontLoader_queueLoadingCallback(callback) {
  24370. function LoadLoader_completeRequest() {
  24371. assert(!request.end, 'completeRequest() cannot be called twice');
  24372. request.end = Date.now();
  24373. // sending all completed requests in order how they were queued
  24374. while (context.requests.length > 0 && context.requests[0].end) {
  24375. var otherRequest = context.requests.shift();
  24376. setTimeout(otherRequest.callback, 0);
  24377. }
  24378. }
  24379. var context = this.loadingContext;
  24380. var requestId = 'pdfjs-font-loading-' + context.nextRequestId++;
  24381. var request = {
  24382. id: requestId,
  24383. complete: LoadLoader_completeRequest,
  24384. callback: callback,
  24385. started: Date.now()
  24386. };
  24387. context.requests.push(request);
  24388. return request;
  24389. };
  24390. FontLoader.prototype.prepareFontLoadEvent = function fontLoaderPrepareFontLoadEvent(rules, fonts, request) {
  24391. /** Hack begin */
  24392. // There's currently no event when a font has finished downloading so the
  24393. // following code is a dirty hack to 'guess' when a font is
  24394. // ready. It's assumed fonts are loaded in order, so add a known test
  24395. // font after the desired fonts and then test for the loading of that
  24396. // test font.
  24397. function int32(data, offset) {
  24398. return data.charCodeAt(offset) << 24 | data.charCodeAt(offset + 1) << 16 | data.charCodeAt(offset + 2) << 8 | data.charCodeAt(offset + 3) & 0xff;
  24399. }
  24400. function spliceString(s, offset, remove, insert) {
  24401. var chunk1 = s.substr(0, offset);
  24402. var chunk2 = s.substr(offset + remove);
  24403. return chunk1 + insert + chunk2;
  24404. }
  24405. var i, ii;
  24406. var canvas = document.createElement('canvas');
  24407. canvas.width = 1;
  24408. canvas.height = 1;
  24409. var ctx = canvas.getContext('2d');
  24410. var called = 0;
  24411. function isFontReady(name, callback) {
  24412. called++;
  24413. // With setTimeout clamping this gives the font ~100ms to load.
  24414. if (called > 30) {
  24415. warn('Load test font never loaded.');
  24416. callback();
  24417. return;
  24418. }
  24419. ctx.font = '30px ' + name;
  24420. ctx.fillText('.', 0, 20);
  24421. var imageData = ctx.getImageData(0, 0, 1, 1);
  24422. if (imageData.data[3] > 0) {
  24423. callback();
  24424. return;
  24425. }
  24426. setTimeout(isFontReady.bind(null, name, callback));
  24427. }
  24428. var loadTestFontId = 'lt' + Date.now() + this.loadTestFontId++;
  24429. // Chromium seems to cache fonts based on a hash of the actual font data,
  24430. // so the font must be modified for each load test else it will appear to
  24431. // be loaded already.
  24432. // TODO: This could maybe be made faster by avoiding the btoa of the full
  24433. // font by splitting it in chunks before hand and padding the font id.
  24434. var data = this.loadTestFont;
  24435. var COMMENT_OFFSET = 976;
  24436. // has to be on 4 byte boundary (for checksum)
  24437. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length, loadTestFontId);
  24438. // CFF checksum is important for IE, adjusting it
  24439. var CFF_CHECKSUM_OFFSET = 16;
  24440. var XXXX_VALUE = 0x58585858;
  24441. // the "comment" filled with 'X'
  24442. var checksum = int32(data, CFF_CHECKSUM_OFFSET);
  24443. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  24444. checksum = checksum - XXXX_VALUE + int32(loadTestFontId, i) | 0;
  24445. }
  24446. if (i < loadTestFontId.length) {
  24447. // align to 4 bytes boundary
  24448. checksum = checksum - XXXX_VALUE + int32(loadTestFontId + 'XXX', i) | 0;
  24449. }
  24450. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, string32(checksum));
  24451. var url = 'url(data:font/opentype;base64,' + btoa(data) + ');';
  24452. var rule = '@font-face { font-family:"' + loadTestFontId + '";src:' + url + '}';
  24453. this.insertRule(rule);
  24454. var names = [];
  24455. for (i = 0, ii = fonts.length; i < ii; i++) {
  24456. names.push(fonts[i].loadedName);
  24457. }
  24458. names.push(loadTestFontId);
  24459. var div = document.createElement('div');
  24460. div.setAttribute('style', 'visibility: hidden;' + 'width: 10px; height: 10px;' + 'position: absolute; top: 0px; left: 0px;');
  24461. for (i = 0, ii = names.length; i < ii; ++i) {
  24462. var span = document.createElement('span');
  24463. span.textContent = 'Hi';
  24464. span.style.fontFamily = names[i];
  24465. div.appendChild(span);
  24466. }
  24467. document.body.appendChild(div);
  24468. isFontReady(loadTestFontId, function () {
  24469. document.body.removeChild(div);
  24470. request.complete();
  24471. });
  24472. };
  24473. FontLoader.isFontLoadingAPISupported = typeof document !== 'undefined' && !!document.fonts;
  24474. var isSyncFontLoadingSupported = function isSyncFontLoadingSupported() {
  24475. if (typeof navigator === 'undefined') {
  24476. // node.js - we can pretend sync font loading is supported.
  24477. return true;
  24478. }
  24479. var supported = false;
  24480. // User agent string sniffing is bad, but there is no reliable way to tell
  24481. // if font is fully loaded and ready to be used with canvas.
  24482. var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(navigator.userAgent);
  24483. if (m && m[1] >= 14) {
  24484. supported = true;
  24485. }
  24486. // TODO other browsers
  24487. return supported;
  24488. };
  24489. Object.defineProperty(FontLoader, 'isSyncFontLoadingSupported', {
  24490. get: function () {
  24491. return shadow(FontLoader, 'isSyncFontLoadingSupported', isSyncFontLoadingSupported());
  24492. },
  24493. enumerable: true,
  24494. configurable: true
  24495. });
  24496. var IsEvalSupportedCached = {
  24497. get value() {
  24498. return shadow(this, 'value', sharedUtil.isEvalSupported());
  24499. }
  24500. };
  24501. var FontFaceObject = function FontFaceObjectClosure() {
  24502. function FontFaceObject(translatedData, options) {
  24503. this.compiledGlyphs = Object.create(null);
  24504. // importing translated data
  24505. for (var i in translatedData) {
  24506. this[i] = translatedData[i];
  24507. }
  24508. this.options = options;
  24509. }
  24510. FontFaceObject.prototype = {
  24511. createNativeFontFace: function FontFaceObject_createNativeFontFace() {
  24512. if (!this.data) {
  24513. return null;
  24514. }
  24515. if (this.options.disableFontFace) {
  24516. this.disableFontFace = true;
  24517. return null;
  24518. }
  24519. var nativeFontFace = new FontFace(this.loadedName, this.data, {});
  24520. if (this.options.fontRegistry) {
  24521. this.options.fontRegistry.registerFont(this);
  24522. }
  24523. return nativeFontFace;
  24524. },
  24525. createFontFaceRule: function FontFaceObject_createFontFaceRule() {
  24526. if (!this.data) {
  24527. return null;
  24528. }
  24529. if (this.options.disableFontFace) {
  24530. this.disableFontFace = true;
  24531. return null;
  24532. }
  24533. var data = bytesToString(new Uint8Array(this.data));
  24534. var fontName = this.loadedName;
  24535. // Add the font-face rule to the document
  24536. var url = 'url(data:' + this.mimetype + ';base64,' + btoa(data) + ');';
  24537. var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
  24538. if (this.options.fontRegistry) {
  24539. this.options.fontRegistry.registerFont(this, url);
  24540. }
  24541. return rule;
  24542. },
  24543. getPathGenerator: function FontFaceObject_getPathGenerator(objs, character) {
  24544. if (!(character in this.compiledGlyphs)) {
  24545. var cmds = objs.get(this.loadedName + '_path_' + character);
  24546. var current, i, len;
  24547. // If we can, compile cmds into JS for MAXIMUM SPEED
  24548. if (this.options.isEvalSupported && IsEvalSupportedCached.value) {
  24549. var args, js = '';
  24550. for (i = 0, len = cmds.length; i < len; i++) {
  24551. current = cmds[i];
  24552. if (current.args !== undefined) {
  24553. args = current.args.join(',');
  24554. } else {
  24555. args = '';
  24556. }
  24557. js += 'c.' + current.cmd + '(' + args + ');\n';
  24558. }
  24559. this.compiledGlyphs[character] = new Function('c', 'size', js);
  24560. } else {
  24561. // But fall back on using Function.prototype.apply() if we're
  24562. // blocked from using eval() for whatever reason (like CSP policies)
  24563. this.compiledGlyphs[character] = function (c, size) {
  24564. for (i = 0, len = cmds.length; i < len; i++) {
  24565. current = cmds[i];
  24566. if (current.cmd === 'scale') {
  24567. current.args = [
  24568. size,
  24569. -size
  24570. ];
  24571. }
  24572. c[current.cmd].apply(c, current.args);
  24573. }
  24574. };
  24575. }
  24576. }
  24577. return this.compiledGlyphs[character];
  24578. }
  24579. };
  24580. return FontFaceObject;
  24581. }();
  24582. exports.FontFaceObject = FontFaceObject;
  24583. exports.FontLoader = FontLoader;
  24584. }));
  24585. (function (root, factory) {
  24586. factory(root.pdfjsDisplayMetadata = {}, root.pdfjsSharedUtil);
  24587. }(this, function (exports, sharedUtil) {
  24588. var error = sharedUtil.error;
  24589. function fixMetadata(meta) {
  24590. return meta.replace(/>\\376\\377([^<]+)/g, function (all, codes) {
  24591. var bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g, function (code, d1, d2, d3) {
  24592. return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
  24593. });
  24594. var chars = '';
  24595. for (var i = 0; i < bytes.length; i += 2) {
  24596. var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
  24597. chars += code >= 32 && code < 127 && code !== 60 && code !== 62 && code !== 38 && false ? String.fromCharCode(code) : '&#x' + (0x10000 + code).toString(16).substring(1) + ';';
  24598. }
  24599. return '>' + chars;
  24600. });
  24601. }
  24602. function Metadata(meta) {
  24603. if (typeof meta === 'string') {
  24604. // Ghostscript produces invalid metadata
  24605. meta = fixMetadata(meta);
  24606. var parser = new DOMParser();
  24607. meta = parser.parseFromString(meta, 'application/xml');
  24608. } else if (!(meta instanceof Document)) {
  24609. error('Metadata: Invalid metadata object');
  24610. }
  24611. this.metaDocument = meta;
  24612. this.metadata = Object.create(null);
  24613. this.parse();
  24614. }
  24615. Metadata.prototype = {
  24616. parse: function Metadata_parse() {
  24617. var doc = this.metaDocument;
  24618. var rdf = doc.documentElement;
  24619. if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  24620. // Wrapped in <xmpmeta>
  24621. rdf = rdf.firstChild;
  24622. while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  24623. rdf = rdf.nextSibling;
  24624. }
  24625. }
  24626. var nodeName = rdf ? rdf.nodeName.toLowerCase() : null;
  24627. if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) {
  24628. return;
  24629. }
  24630. var children = rdf.childNodes, desc, entry, name, i, ii, length, iLength;
  24631. for (i = 0, length = children.length; i < length; i++) {
  24632. desc = children[i];
  24633. if (desc.nodeName.toLowerCase() !== 'rdf:description') {
  24634. continue;
  24635. }
  24636. for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
  24637. if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') {
  24638. entry = desc.childNodes[ii];
  24639. name = entry.nodeName.toLowerCase();
  24640. this.metadata[name] = entry.textContent.trim();
  24641. }
  24642. }
  24643. }
  24644. },
  24645. get: function Metadata_get(name) {
  24646. return this.metadata[name] || null;
  24647. },
  24648. has: function Metadata_has(name) {
  24649. return typeof this.metadata[name] !== 'undefined';
  24650. }
  24651. };
  24652. exports.Metadata = Metadata;
  24653. }));
  24654. (function (root, factory) {
  24655. factory(root.pdfjsDisplaySVG = {}, root.pdfjsSharedUtil);
  24656. }(this, function (exports, sharedUtil) {
  24657. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  24658. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  24659. var ImageKind = sharedUtil.ImageKind;
  24660. var OPS = sharedUtil.OPS;
  24661. var Util = sharedUtil.Util;
  24662. var isNum = sharedUtil.isNum;
  24663. var isArray = sharedUtil.isArray;
  24664. var warn = sharedUtil.warn;
  24665. var createObjectURL = sharedUtil.createObjectURL;
  24666. var SVG_DEFAULTS = {
  24667. fontStyle: 'normal',
  24668. fontWeight: 'normal',
  24669. fillColor: '#000000'
  24670. };
  24671. var convertImgDataToPng = function convertImgDataToPngClosure() {
  24672. var PNG_HEADER = new Uint8Array([
  24673. 0x89,
  24674. 0x50,
  24675. 0x4e,
  24676. 0x47,
  24677. 0x0d,
  24678. 0x0a,
  24679. 0x1a,
  24680. 0x0a
  24681. ]);
  24682. var CHUNK_WRAPPER_SIZE = 12;
  24683. var crcTable = new Int32Array(256);
  24684. for (var i = 0; i < 256; i++) {
  24685. var c = i;
  24686. for (var h = 0; h < 8; h++) {
  24687. if (c & 1) {
  24688. c = 0xedB88320 ^ c >> 1 & 0x7fffffff;
  24689. } else {
  24690. c = c >> 1 & 0x7fffffff;
  24691. }
  24692. }
  24693. crcTable[i] = c;
  24694. }
  24695. function crc32(data, start, end) {
  24696. var crc = -1;
  24697. for (var i = start; i < end; i++) {
  24698. var a = (crc ^ data[i]) & 0xff;
  24699. var b = crcTable[a];
  24700. crc = crc >>> 8 ^ b;
  24701. }
  24702. return crc ^ -1;
  24703. }
  24704. function writePngChunk(type, body, data, offset) {
  24705. var p = offset;
  24706. var len = body.length;
  24707. data[p] = len >> 24 & 0xff;
  24708. data[p + 1] = len >> 16 & 0xff;
  24709. data[p + 2] = len >> 8 & 0xff;
  24710. data[p + 3] = len & 0xff;
  24711. p += 4;
  24712. data[p] = type.charCodeAt(0) & 0xff;
  24713. data[p + 1] = type.charCodeAt(1) & 0xff;
  24714. data[p + 2] = type.charCodeAt(2) & 0xff;
  24715. data[p + 3] = type.charCodeAt(3) & 0xff;
  24716. p += 4;
  24717. data.set(body, p);
  24718. p += body.length;
  24719. var crc = crc32(data, offset + 4, p);
  24720. data[p] = crc >> 24 & 0xff;
  24721. data[p + 1] = crc >> 16 & 0xff;
  24722. data[p + 2] = crc >> 8 & 0xff;
  24723. data[p + 3] = crc & 0xff;
  24724. }
  24725. function adler32(data, start, end) {
  24726. var a = 1;
  24727. var b = 0;
  24728. for (var i = start; i < end; ++i) {
  24729. a = (a + (data[i] & 0xff)) % 65521;
  24730. b = (b + a) % 65521;
  24731. }
  24732. return b << 16 | a;
  24733. }
  24734. function encode(imgData, kind, forceDataSchema) {
  24735. var width = imgData.width;
  24736. var height = imgData.height;
  24737. var bitDepth, colorType, lineSize;
  24738. var bytes = imgData.data;
  24739. switch (kind) {
  24740. case ImageKind.GRAYSCALE_1BPP:
  24741. colorType = 0;
  24742. bitDepth = 1;
  24743. lineSize = width + 7 >> 3;
  24744. break;
  24745. case ImageKind.RGB_24BPP:
  24746. colorType = 2;
  24747. bitDepth = 8;
  24748. lineSize = width * 3;
  24749. break;
  24750. case ImageKind.RGBA_32BPP:
  24751. colorType = 6;
  24752. bitDepth = 8;
  24753. lineSize = width * 4;
  24754. break;
  24755. default:
  24756. throw new Error('invalid format');
  24757. }
  24758. // prefix every row with predictor 0
  24759. var literals = new Uint8Array((1 + lineSize) * height);
  24760. var offsetLiterals = 0, offsetBytes = 0;
  24761. var y, i;
  24762. for (y = 0; y < height; ++y) {
  24763. literals[offsetLiterals++] = 0;
  24764. // no prediction
  24765. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize), offsetLiterals);
  24766. offsetBytes += lineSize;
  24767. offsetLiterals += lineSize;
  24768. }
  24769. if (kind === ImageKind.GRAYSCALE_1BPP) {
  24770. // inverting for B/W
  24771. offsetLiterals = 0;
  24772. for (y = 0; y < height; y++) {
  24773. offsetLiterals++;
  24774. // skipping predictor
  24775. for (i = 0; i < lineSize; i++) {
  24776. literals[offsetLiterals++] ^= 0xFF;
  24777. }
  24778. }
  24779. }
  24780. var ihdr = new Uint8Array([
  24781. width >> 24 & 0xff,
  24782. width >> 16 & 0xff,
  24783. width >> 8 & 0xff,
  24784. width & 0xff,
  24785. height >> 24 & 0xff,
  24786. height >> 16 & 0xff,
  24787. height >> 8 & 0xff,
  24788. height & 0xff,
  24789. bitDepth,
  24790. // bit depth
  24791. colorType,
  24792. // color type
  24793. 0x00,
  24794. // compression method
  24795. 0x00,
  24796. // filter method
  24797. 0x00
  24798. ]);
  24799. // interlace method
  24800. var len = literals.length;
  24801. var maxBlockLength = 0xFFFF;
  24802. var deflateBlocks = Math.ceil(len / maxBlockLength);
  24803. var idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  24804. var pi = 0;
  24805. idat[pi++] = 0x78;
  24806. // compression method and flags
  24807. idat[pi++] = 0x9c;
  24808. // flags
  24809. var pos = 0;
  24810. while (len > maxBlockLength) {
  24811. // writing non-final DEFLATE blocks type 0 and length of 65535
  24812. idat[pi++] = 0x00;
  24813. idat[pi++] = 0xff;
  24814. idat[pi++] = 0xff;
  24815. idat[pi++] = 0x00;
  24816. idat[pi++] = 0x00;
  24817. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  24818. pi += maxBlockLength;
  24819. pos += maxBlockLength;
  24820. len -= maxBlockLength;
  24821. }
  24822. // writing non-final DEFLATE blocks type 0
  24823. idat[pi++] = 0x01;
  24824. idat[pi++] = len & 0xff;
  24825. idat[pi++] = len >> 8 & 0xff;
  24826. idat[pi++] = ~len & 0xffff & 0xff;
  24827. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  24828. idat.set(literals.subarray(pos), pi);
  24829. pi += literals.length - pos;
  24830. var adler = adler32(literals, 0, literals.length);
  24831. // checksum
  24832. idat[pi++] = adler >> 24 & 0xff;
  24833. idat[pi++] = adler >> 16 & 0xff;
  24834. idat[pi++] = adler >> 8 & 0xff;
  24835. idat[pi++] = adler & 0xff;
  24836. // PNG will consists: header, IHDR+data, IDAT+data, and IEND.
  24837. var pngLength = PNG_HEADER.length + CHUNK_WRAPPER_SIZE * 3 + ihdr.length + idat.length;
  24838. var data = new Uint8Array(pngLength);
  24839. var offset = 0;
  24840. data.set(PNG_HEADER, offset);
  24841. offset += PNG_HEADER.length;
  24842. writePngChunk('IHDR', ihdr, data, offset);
  24843. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  24844. writePngChunk('IDATA', idat, data, offset);
  24845. offset += CHUNK_WRAPPER_SIZE + idat.length;
  24846. writePngChunk('IEND', new Uint8Array(0), data, offset);
  24847. return createObjectURL(data, 'image/png', forceDataSchema);
  24848. }
  24849. return function convertImgDataToPng(imgData, forceDataSchema) {
  24850. var kind = imgData.kind === undefined ? ImageKind.GRAYSCALE_1BPP : imgData.kind;
  24851. return encode(imgData, kind, forceDataSchema);
  24852. };
  24853. }();
  24854. var SVGExtraState = function SVGExtraStateClosure() {
  24855. function SVGExtraState() {
  24856. this.fontSizeScale = 1;
  24857. this.fontWeight = SVG_DEFAULTS.fontWeight;
  24858. this.fontSize = 0;
  24859. this.textMatrix = IDENTITY_MATRIX;
  24860. this.fontMatrix = FONT_IDENTITY_MATRIX;
  24861. this.leading = 0;
  24862. // Current point (in user coordinates)
  24863. this.x = 0;
  24864. this.y = 0;
  24865. // Start of text line (in text coordinates)
  24866. this.lineX = 0;
  24867. this.lineY = 0;
  24868. // Character and word spacing
  24869. this.charSpacing = 0;
  24870. this.wordSpacing = 0;
  24871. this.textHScale = 1;
  24872. this.textRise = 0;
  24873. // Default foreground and background colors
  24874. this.fillColor = SVG_DEFAULTS.fillColor;
  24875. this.strokeColor = '#000000';
  24876. this.fillAlpha = 1;
  24877. this.strokeAlpha = 1;
  24878. this.lineWidth = 1;
  24879. this.lineJoin = '';
  24880. this.lineCap = '';
  24881. this.miterLimit = 0;
  24882. this.dashArray = [];
  24883. this.dashPhase = 0;
  24884. this.dependencies = [];
  24885. // Clipping
  24886. this.clipId = '';
  24887. this.pendingClip = false;
  24888. this.maskId = '';
  24889. }
  24890. SVGExtraState.prototype = {
  24891. clone: function SVGExtraState_clone() {
  24892. return Object.create(this);
  24893. },
  24894. setCurrentPoint: function SVGExtraState_setCurrentPoint(x, y) {
  24895. this.x = x;
  24896. this.y = y;
  24897. }
  24898. };
  24899. return SVGExtraState;
  24900. }();
  24901. var SVGGraphics = function SVGGraphicsClosure() {
  24902. function createScratchSVG(width, height) {
  24903. var NS = 'http://www.w3.org/2000/svg';
  24904. var svg = document.createElementNS(NS, 'svg:svg');
  24905. svg.setAttributeNS(null, 'version', '1.1');
  24906. svg.setAttributeNS(null, 'width', width + 'px');
  24907. svg.setAttributeNS(null, 'height', height + 'px');
  24908. svg.setAttributeNS(null, 'viewBox', '0 0 ' + width + ' ' + height);
  24909. return svg;
  24910. }
  24911. function opListToTree(opList) {
  24912. var opTree = [];
  24913. var tmp = [];
  24914. var opListLen = opList.length;
  24915. for (var x = 0; x < opListLen; x++) {
  24916. if (opList[x].fn === 'save') {
  24917. opTree.push({
  24918. 'fnId': 92,
  24919. 'fn': 'group',
  24920. 'items': []
  24921. });
  24922. tmp.push(opTree);
  24923. opTree = opTree[opTree.length - 1].items;
  24924. continue;
  24925. }
  24926. if (opList[x].fn === 'restore') {
  24927. opTree = tmp.pop();
  24928. } else {
  24929. opTree.push(opList[x]);
  24930. }
  24931. }
  24932. return opTree;
  24933. }
  24934. /**
  24935. * Formats float number.
  24936. * @param value {number} number to format.
  24937. * @returns {string}
  24938. */
  24939. function pf(value) {
  24940. if (value === (value | 0)) {
  24941. // integer number
  24942. return value.toString();
  24943. }
  24944. var s = value.toFixed(10);
  24945. var i = s.length - 1;
  24946. if (s[i] !== '0') {
  24947. return s;
  24948. }
  24949. // removing trailing zeros
  24950. do {
  24951. i--;
  24952. } while (s[i] === '0');
  24953. return s.substr(0, s[i] === '.' ? i : i + 1);
  24954. }
  24955. /**
  24956. * Formats transform matrix. The standard rotation, scale and translate
  24957. * matrices are replaced by their shorter forms, and for identity matrix
  24958. * returns empty string to save the memory.
  24959. * @param m {Array} matrix to format.
  24960. * @returns {string}
  24961. */
  24962. function pm(m) {
  24963. if (m[4] === 0 && m[5] === 0) {
  24964. if (m[1] === 0 && m[2] === 0) {
  24965. if (m[0] === 1 && m[3] === 1) {
  24966. return '';
  24967. }
  24968. return 'scale(' + pf(m[0]) + ' ' + pf(m[3]) + ')';
  24969. }
  24970. if (m[0] === m[3] && m[1] === -m[2]) {
  24971. var a = Math.acos(m[0]) * 180 / Math.PI;
  24972. return 'rotate(' + pf(a) + ')';
  24973. }
  24974. } else {
  24975. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  24976. return 'translate(' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  24977. }
  24978. }
  24979. return 'matrix(' + pf(m[0]) + ' ' + pf(m[1]) + ' ' + pf(m[2]) + ' ' + pf(m[3]) + ' ' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  24980. }
  24981. function SVGGraphics(commonObjs, objs, forceDataSchema) {
  24982. this.current = new SVGExtraState();
  24983. this.transformMatrix = IDENTITY_MATRIX;
  24984. // Graphics state matrix
  24985. this.transformStack = [];
  24986. this.extraStack = [];
  24987. this.commonObjs = commonObjs;
  24988. this.objs = objs;
  24989. this.pendingEOFill = false;
  24990. this.embedFonts = false;
  24991. this.embeddedFonts = Object.create(null);
  24992. this.cssStyle = null;
  24993. this.forceDataSchema = !!forceDataSchema;
  24994. }
  24995. var NS = 'http://www.w3.org/2000/svg';
  24996. var XML_NS = 'http://www.w3.org/XML/1998/namespace';
  24997. var XLINK_NS = 'http://www.w3.org/1999/xlink';
  24998. var LINE_CAP_STYLES = [
  24999. 'butt',
  25000. 'round',
  25001. 'square'
  25002. ];
  25003. var LINE_JOIN_STYLES = [
  25004. 'miter',
  25005. 'round',
  25006. 'bevel'
  25007. ];
  25008. var clipCount = 0;
  25009. var maskCount = 0;
  25010. SVGGraphics.prototype = {
  25011. save: function SVGGraphics_save() {
  25012. this.transformStack.push(this.transformMatrix);
  25013. var old = this.current;
  25014. this.extraStack.push(old);
  25015. this.current = old.clone();
  25016. },
  25017. restore: function SVGGraphics_restore() {
  25018. this.transformMatrix = this.transformStack.pop();
  25019. this.current = this.extraStack.pop();
  25020. this.tgrp = document.createElementNS(NS, 'svg:g');
  25021. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  25022. this.pgrp.appendChild(this.tgrp);
  25023. },
  25024. group: function SVGGraphics_group(items) {
  25025. this.save();
  25026. this.executeOpTree(items);
  25027. this.restore();
  25028. },
  25029. loadDependencies: function SVGGraphics_loadDependencies(operatorList) {
  25030. var fnArray = operatorList.fnArray;
  25031. var fnArrayLen = fnArray.length;
  25032. var argsArray = operatorList.argsArray;
  25033. var self = this;
  25034. for (var i = 0; i < fnArrayLen; i++) {
  25035. if (OPS.dependency === fnArray[i]) {
  25036. var deps = argsArray[i];
  25037. for (var n = 0, nn = deps.length; n < nn; n++) {
  25038. var obj = deps[n];
  25039. var common = obj.substring(0, 2) === 'g_';
  25040. var promise;
  25041. if (common) {
  25042. promise = new Promise(function (resolve) {
  25043. self.commonObjs.get(obj, resolve);
  25044. });
  25045. } else {
  25046. promise = new Promise(function (resolve) {
  25047. self.objs.get(obj, resolve);
  25048. });
  25049. }
  25050. this.current.dependencies.push(promise);
  25051. }
  25052. }
  25053. }
  25054. return Promise.all(this.current.dependencies);
  25055. },
  25056. transform: function SVGGraphics_transform(a, b, c, d, e, f) {
  25057. var transformMatrix = [
  25058. a,
  25059. b,
  25060. c,
  25061. d,
  25062. e,
  25063. f
  25064. ];
  25065. this.transformMatrix = Util.transform(this.transformMatrix, transformMatrix);
  25066. this.tgrp = document.createElementNS(NS, 'svg:g');
  25067. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  25068. },
  25069. getSVG: function SVGGraphics_getSVG(operatorList, viewport) {
  25070. this.svg = createScratchSVG(viewport.width, viewport.height);
  25071. this.viewport = viewport;
  25072. return this.loadDependencies(operatorList).then(function () {
  25073. this.transformMatrix = IDENTITY_MATRIX;
  25074. this.pgrp = document.createElementNS(NS, 'svg:g');
  25075. // Parent group
  25076. this.pgrp.setAttributeNS(null, 'transform', pm(viewport.transform));
  25077. this.tgrp = document.createElementNS(NS, 'svg:g');
  25078. // Transform group
  25079. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  25080. this.defs = document.createElementNS(NS, 'svg:defs');
  25081. this.pgrp.appendChild(this.defs);
  25082. this.pgrp.appendChild(this.tgrp);
  25083. this.svg.appendChild(this.pgrp);
  25084. var opTree = this.convertOpList(operatorList);
  25085. this.executeOpTree(opTree);
  25086. return this.svg;
  25087. }.bind(this));
  25088. },
  25089. convertOpList: function SVGGraphics_convertOpList(operatorList) {
  25090. var argsArray = operatorList.argsArray;
  25091. var fnArray = operatorList.fnArray;
  25092. var fnArrayLen = fnArray.length;
  25093. var REVOPS = [];
  25094. var opList = [];
  25095. for (var op in OPS) {
  25096. REVOPS[OPS[op]] = op;
  25097. }
  25098. for (var x = 0; x < fnArrayLen; x++) {
  25099. var fnId = fnArray[x];
  25100. opList.push({
  25101. 'fnId': fnId,
  25102. 'fn': REVOPS[fnId],
  25103. 'args': argsArray[x]
  25104. });
  25105. }
  25106. return opListToTree(opList);
  25107. },
  25108. executeOpTree: function SVGGraphics_executeOpTree(opTree) {
  25109. var opTreeLen = opTree.length;
  25110. for (var x = 0; x < opTreeLen; x++) {
  25111. var fn = opTree[x].fn;
  25112. var fnId = opTree[x].fnId;
  25113. var args = opTree[x].args;
  25114. switch (fnId | 0) {
  25115. case OPS.beginText:
  25116. this.beginText();
  25117. break;
  25118. case OPS.setLeading:
  25119. this.setLeading(args);
  25120. break;
  25121. case OPS.setLeadingMoveText:
  25122. this.setLeadingMoveText(args[0], args[1]);
  25123. break;
  25124. case OPS.setFont:
  25125. this.setFont(args);
  25126. break;
  25127. case OPS.showText:
  25128. this.showText(args[0]);
  25129. break;
  25130. case OPS.showSpacedText:
  25131. this.showText(args[0]);
  25132. break;
  25133. case OPS.endText:
  25134. this.endText();
  25135. break;
  25136. case OPS.moveText:
  25137. this.moveText(args[0], args[1]);
  25138. break;
  25139. case OPS.setCharSpacing:
  25140. this.setCharSpacing(args[0]);
  25141. break;
  25142. case OPS.setWordSpacing:
  25143. this.setWordSpacing(args[0]);
  25144. break;
  25145. case OPS.setHScale:
  25146. this.setHScale(args[0]);
  25147. break;
  25148. case OPS.setTextMatrix:
  25149. this.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
  25150. break;
  25151. case OPS.setLineWidth:
  25152. this.setLineWidth(args[0]);
  25153. break;
  25154. case OPS.setLineJoin:
  25155. this.setLineJoin(args[0]);
  25156. break;
  25157. case OPS.setLineCap:
  25158. this.setLineCap(args[0]);
  25159. break;
  25160. case OPS.setMiterLimit:
  25161. this.setMiterLimit(args[0]);
  25162. break;
  25163. case OPS.setFillRGBColor:
  25164. this.setFillRGBColor(args[0], args[1], args[2]);
  25165. break;
  25166. case OPS.setStrokeRGBColor:
  25167. this.setStrokeRGBColor(args[0], args[1], args[2]);
  25168. break;
  25169. case OPS.setDash:
  25170. this.setDash(args[0], args[1]);
  25171. break;
  25172. case OPS.setGState:
  25173. this.setGState(args[0]);
  25174. break;
  25175. case OPS.fill:
  25176. this.fill();
  25177. break;
  25178. case OPS.eoFill:
  25179. this.eoFill();
  25180. break;
  25181. case OPS.stroke:
  25182. this.stroke();
  25183. break;
  25184. case OPS.fillStroke:
  25185. this.fillStroke();
  25186. break;
  25187. case OPS.eoFillStroke:
  25188. this.eoFillStroke();
  25189. break;
  25190. case OPS.clip:
  25191. this.clip('nonzero');
  25192. break;
  25193. case OPS.eoClip:
  25194. this.clip('evenodd');
  25195. break;
  25196. case OPS.paintSolidColorImageMask:
  25197. this.paintSolidColorImageMask();
  25198. break;
  25199. case OPS.paintJpegXObject:
  25200. this.paintJpegXObject(args[0], args[1], args[2]);
  25201. break;
  25202. case OPS.paintImageXObject:
  25203. this.paintImageXObject(args[0]);
  25204. break;
  25205. case OPS.paintInlineImageXObject:
  25206. this.paintInlineImageXObject(args[0]);
  25207. break;
  25208. case OPS.paintImageMaskXObject:
  25209. this.paintImageMaskXObject(args[0]);
  25210. break;
  25211. case OPS.paintFormXObjectBegin:
  25212. this.paintFormXObjectBegin(args[0], args[1]);
  25213. break;
  25214. case OPS.paintFormXObjectEnd:
  25215. this.paintFormXObjectEnd();
  25216. break;
  25217. case OPS.closePath:
  25218. this.closePath();
  25219. break;
  25220. case OPS.closeStroke:
  25221. this.closeStroke();
  25222. break;
  25223. case OPS.closeFillStroke:
  25224. this.closeFillStroke();
  25225. break;
  25226. case OPS.nextLine:
  25227. this.nextLine();
  25228. break;
  25229. case OPS.transform:
  25230. this.transform(args[0], args[1], args[2], args[3], args[4], args[5]);
  25231. break;
  25232. case OPS.constructPath:
  25233. this.constructPath(args[0], args[1]);
  25234. break;
  25235. case OPS.endPath:
  25236. this.endPath();
  25237. break;
  25238. case 92:
  25239. this.group(opTree[x].items);
  25240. break;
  25241. default:
  25242. warn('Unimplemented method ' + fn);
  25243. break;
  25244. }
  25245. }
  25246. },
  25247. setWordSpacing: function SVGGraphics_setWordSpacing(wordSpacing) {
  25248. this.current.wordSpacing = wordSpacing;
  25249. },
  25250. setCharSpacing: function SVGGraphics_setCharSpacing(charSpacing) {
  25251. this.current.charSpacing = charSpacing;
  25252. },
  25253. nextLine: function SVGGraphics_nextLine() {
  25254. this.moveText(0, this.current.leading);
  25255. },
  25256. setTextMatrix: function SVGGraphics_setTextMatrix(a, b, c, d, e, f) {
  25257. var current = this.current;
  25258. this.current.textMatrix = this.current.lineMatrix = [
  25259. a,
  25260. b,
  25261. c,
  25262. d,
  25263. e,
  25264. f
  25265. ];
  25266. this.current.x = this.current.lineX = 0;
  25267. this.current.y = this.current.lineY = 0;
  25268. current.xcoords = [];
  25269. current.tspan = document.createElementNS(NS, 'svg:tspan');
  25270. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  25271. current.tspan.setAttributeNS(null, 'font-size', pf(current.fontSize) + 'px');
  25272. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  25273. current.txtElement = document.createElementNS(NS, 'svg:text');
  25274. current.txtElement.appendChild(current.tspan);
  25275. },
  25276. beginText: function SVGGraphics_beginText() {
  25277. this.current.x = this.current.lineX = 0;
  25278. this.current.y = this.current.lineY = 0;
  25279. this.current.textMatrix = IDENTITY_MATRIX;
  25280. this.current.lineMatrix = IDENTITY_MATRIX;
  25281. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  25282. this.current.txtElement = document.createElementNS(NS, 'svg:text');
  25283. this.current.txtgrp = document.createElementNS(NS, 'svg:g');
  25284. this.current.xcoords = [];
  25285. },
  25286. moveText: function SVGGraphics_moveText(x, y) {
  25287. var current = this.current;
  25288. this.current.x = this.current.lineX += x;
  25289. this.current.y = this.current.lineY += y;
  25290. current.xcoords = [];
  25291. current.tspan = document.createElementNS(NS, 'svg:tspan');
  25292. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  25293. current.tspan.setAttributeNS(null, 'font-size', pf(current.fontSize) + 'px');
  25294. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  25295. },
  25296. showText: function SVGGraphics_showText(glyphs) {
  25297. var current = this.current;
  25298. var font = current.font;
  25299. var fontSize = current.fontSize;
  25300. if (fontSize === 0) {
  25301. return;
  25302. }
  25303. var charSpacing = current.charSpacing;
  25304. var wordSpacing = current.wordSpacing;
  25305. var fontDirection = current.fontDirection;
  25306. var textHScale = current.textHScale * fontDirection;
  25307. var glyphsLength = glyphs.length;
  25308. var vertical = font.vertical;
  25309. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  25310. var x = 0, i;
  25311. for (i = 0; i < glyphsLength; ++i) {
  25312. var glyph = glyphs[i];
  25313. if (glyph === null) {
  25314. // word break
  25315. x += fontDirection * wordSpacing;
  25316. continue;
  25317. } else if (isNum(glyph)) {
  25318. x += -glyph * fontSize * 0.001;
  25319. continue;
  25320. }
  25321. current.xcoords.push(current.x + x * textHScale);
  25322. var width = glyph.width;
  25323. var character = glyph.fontChar;
  25324. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  25325. x += charWidth;
  25326. current.tspan.textContent += character;
  25327. }
  25328. if (vertical) {
  25329. current.y -= x * textHScale;
  25330. } else {
  25331. current.x += x * textHScale;
  25332. }
  25333. current.tspan.setAttributeNS(null, 'x', current.xcoords.map(pf).join(' '));
  25334. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  25335. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  25336. current.tspan.setAttributeNS(null, 'font-size', pf(current.fontSize) + 'px');
  25337. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  25338. current.tspan.setAttributeNS(null, 'font-style', current.fontStyle);
  25339. }
  25340. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  25341. current.tspan.setAttributeNS(null, 'font-weight', current.fontWeight);
  25342. }
  25343. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  25344. current.tspan.setAttributeNS(null, 'fill', current.fillColor);
  25345. }
  25346. current.txtElement.setAttributeNS(null, 'transform', pm(current.textMatrix) + ' scale(1, -1)');
  25347. current.txtElement.setAttributeNS(XML_NS, 'xml:space', 'preserve');
  25348. current.txtElement.appendChild(current.tspan);
  25349. current.txtgrp.appendChild(current.txtElement);
  25350. this.tgrp.appendChild(current.txtElement);
  25351. },
  25352. setLeadingMoveText: function SVGGraphics_setLeadingMoveText(x, y) {
  25353. this.setLeading(-y);
  25354. this.moveText(x, y);
  25355. },
  25356. addFontStyle: function SVGGraphics_addFontStyle(fontObj) {
  25357. if (!this.cssStyle) {
  25358. this.cssStyle = document.createElementNS(NS, 'svg:style');
  25359. this.cssStyle.setAttributeNS(null, 'type', 'text/css');
  25360. this.defs.appendChild(this.cssStyle);
  25361. }
  25362. var url = createObjectURL(fontObj.data, fontObj.mimetype, this.forceDataSchema);
  25363. this.cssStyle.textContent += '@font-face { font-family: "' + fontObj.loadedName + '";' + ' src: url(' + url + '); }\n';
  25364. },
  25365. setFont: function SVGGraphics_setFont(details) {
  25366. var current = this.current;
  25367. var fontObj = this.commonObjs.get(details[0]);
  25368. var size = details[1];
  25369. this.current.font = fontObj;
  25370. if (this.embedFonts && fontObj.data && !this.embeddedFonts[fontObj.loadedName]) {
  25371. this.addFontStyle(fontObj);
  25372. this.embeddedFonts[fontObj.loadedName] = fontObj;
  25373. }
  25374. current.fontMatrix = fontObj.fontMatrix ? fontObj.fontMatrix : FONT_IDENTITY_MATRIX;
  25375. var bold = fontObj.black ? fontObj.bold ? 'bolder' : 'bold' : fontObj.bold ? 'bold' : 'normal';
  25376. var italic = fontObj.italic ? 'italic' : 'normal';
  25377. if (size < 0) {
  25378. size = -size;
  25379. current.fontDirection = -1;
  25380. } else {
  25381. current.fontDirection = 1;
  25382. }
  25383. current.fontSize = size;
  25384. current.fontFamily = fontObj.loadedName;
  25385. current.fontWeight = bold;
  25386. current.fontStyle = italic;
  25387. current.tspan = document.createElementNS(NS, 'svg:tspan');
  25388. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  25389. current.xcoords = [];
  25390. },
  25391. endText: function SVGGraphics_endText() {
  25392. if (this.current.pendingClip) {
  25393. this.cgrp.appendChild(this.tgrp);
  25394. this.pgrp.appendChild(this.cgrp);
  25395. } else {
  25396. this.pgrp.appendChild(this.tgrp);
  25397. }
  25398. this.tgrp = document.createElementNS(NS, 'svg:g');
  25399. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  25400. },
  25401. // Path properties
  25402. setLineWidth: function SVGGraphics_setLineWidth(width) {
  25403. this.current.lineWidth = width;
  25404. },
  25405. setLineCap: function SVGGraphics_setLineCap(style) {
  25406. this.current.lineCap = LINE_CAP_STYLES[style];
  25407. },
  25408. setLineJoin: function SVGGraphics_setLineJoin(style) {
  25409. this.current.lineJoin = LINE_JOIN_STYLES[style];
  25410. },
  25411. setMiterLimit: function SVGGraphics_setMiterLimit(limit) {
  25412. this.current.miterLimit = limit;
  25413. },
  25414. setStrokeRGBColor: function SVGGraphics_setStrokeRGBColor(r, g, b) {
  25415. var color = Util.makeCssRgb(r, g, b);
  25416. this.current.strokeColor = color;
  25417. },
  25418. setFillRGBColor: function SVGGraphics_setFillRGBColor(r, g, b) {
  25419. var color = Util.makeCssRgb(r, g, b);
  25420. this.current.fillColor = color;
  25421. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  25422. this.current.xcoords = [];
  25423. },
  25424. setDash: function SVGGraphics_setDash(dashArray, dashPhase) {
  25425. this.current.dashArray = dashArray;
  25426. this.current.dashPhase = dashPhase;
  25427. },
  25428. constructPath: function SVGGraphics_constructPath(ops, args) {
  25429. var current = this.current;
  25430. var x = current.x, y = current.y;
  25431. current.path = document.createElementNS(NS, 'svg:path');
  25432. var d = [];
  25433. var opLength = ops.length;
  25434. for (var i = 0, j = 0; i < opLength; i++) {
  25435. switch (ops[i] | 0) {
  25436. case OPS.rectangle:
  25437. x = args[j++];
  25438. y = args[j++];
  25439. var width = args[j++];
  25440. var height = args[j++];
  25441. var xw = x + width;
  25442. var yh = y + height;
  25443. d.push('M', pf(x), pf(y), 'L', pf(xw), pf(y), 'L', pf(xw), pf(yh), 'L', pf(x), pf(yh), 'Z');
  25444. break;
  25445. case OPS.moveTo:
  25446. x = args[j++];
  25447. y = args[j++];
  25448. d.push('M', pf(x), pf(y));
  25449. break;
  25450. case OPS.lineTo:
  25451. x = args[j++];
  25452. y = args[j++];
  25453. d.push('L', pf(x), pf(y));
  25454. break;
  25455. case OPS.curveTo:
  25456. x = args[j + 4];
  25457. y = args[j + 5];
  25458. d.push('C', pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]), pf(x), pf(y));
  25459. j += 6;
  25460. break;
  25461. case OPS.curveTo2:
  25462. x = args[j + 2];
  25463. y = args[j + 3];
  25464. d.push('C', pf(x), pf(y), pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]));
  25465. j += 4;
  25466. break;
  25467. case OPS.curveTo3:
  25468. x = args[j + 2];
  25469. y = args[j + 3];
  25470. d.push('C', pf(args[j]), pf(args[j + 1]), pf(x), pf(y), pf(x), pf(y));
  25471. j += 4;
  25472. break;
  25473. case OPS.closePath:
  25474. d.push('Z');
  25475. break;
  25476. }
  25477. }
  25478. current.path.setAttributeNS(null, 'd', d.join(' '));
  25479. current.path.setAttributeNS(null, 'stroke-miterlimit', pf(current.miterLimit));
  25480. current.path.setAttributeNS(null, 'stroke-linecap', current.lineCap);
  25481. current.path.setAttributeNS(null, 'stroke-linejoin', current.lineJoin);
  25482. current.path.setAttributeNS(null, 'stroke-width', pf(current.lineWidth) + 'px');
  25483. current.path.setAttributeNS(null, 'stroke-dasharray', current.dashArray.map(pf).join(' '));
  25484. current.path.setAttributeNS(null, 'stroke-dashoffset', pf(current.dashPhase) + 'px');
  25485. current.path.setAttributeNS(null, 'fill', 'none');
  25486. this.tgrp.appendChild(current.path);
  25487. if (current.pendingClip) {
  25488. this.cgrp.appendChild(this.tgrp);
  25489. this.pgrp.appendChild(this.cgrp);
  25490. } else {
  25491. this.pgrp.appendChild(this.tgrp);
  25492. }
  25493. // Saving a reference in current.element so that it can be addressed
  25494. // in 'fill' and 'stroke'
  25495. current.element = current.path;
  25496. current.setCurrentPoint(x, y);
  25497. },
  25498. endPath: function SVGGraphics_endPath() {
  25499. var current = this.current;
  25500. if (current.pendingClip) {
  25501. this.cgrp.appendChild(this.tgrp);
  25502. this.pgrp.appendChild(this.cgrp);
  25503. } else {
  25504. this.pgrp.appendChild(this.tgrp);
  25505. }
  25506. this.tgrp = document.createElementNS(NS, 'svg:g');
  25507. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  25508. },
  25509. clip: function SVGGraphics_clip(type) {
  25510. var current = this.current;
  25511. // Add current path to clipping path
  25512. current.clipId = 'clippath' + clipCount;
  25513. clipCount++;
  25514. this.clippath = document.createElementNS(NS, 'svg:clipPath');
  25515. this.clippath.setAttributeNS(null, 'id', current.clipId);
  25516. var clipElement = current.element.cloneNode();
  25517. if (type === 'evenodd') {
  25518. clipElement.setAttributeNS(null, 'clip-rule', 'evenodd');
  25519. } else {
  25520. clipElement.setAttributeNS(null, 'clip-rule', 'nonzero');
  25521. }
  25522. this.clippath.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  25523. this.clippath.appendChild(clipElement);
  25524. this.defs.appendChild(this.clippath);
  25525. // Create a new group with that attribute
  25526. current.pendingClip = true;
  25527. this.cgrp = document.createElementNS(NS, 'svg:g');
  25528. this.cgrp.setAttributeNS(null, 'clip-path', 'url(#' + current.clipId + ')');
  25529. this.pgrp.appendChild(this.cgrp);
  25530. },
  25531. closePath: function SVGGraphics_closePath() {
  25532. var current = this.current;
  25533. var d = current.path.getAttributeNS(null, 'd');
  25534. d += 'Z';
  25535. current.path.setAttributeNS(null, 'd', d);
  25536. },
  25537. setLeading: function SVGGraphics_setLeading(leading) {
  25538. this.current.leading = -leading;
  25539. },
  25540. setTextRise: function SVGGraphics_setTextRise(textRise) {
  25541. this.current.textRise = textRise;
  25542. },
  25543. setHScale: function SVGGraphics_setHScale(scale) {
  25544. this.current.textHScale = scale / 100;
  25545. },
  25546. setGState: function SVGGraphics_setGState(states) {
  25547. for (var i = 0, ii = states.length; i < ii; i++) {
  25548. var state = states[i];
  25549. var key = state[0];
  25550. var value = state[1];
  25551. switch (key) {
  25552. case 'LW':
  25553. this.setLineWidth(value);
  25554. break;
  25555. case 'LC':
  25556. this.setLineCap(value);
  25557. break;
  25558. case 'LJ':
  25559. this.setLineJoin(value);
  25560. break;
  25561. case 'ML':
  25562. this.setMiterLimit(value);
  25563. break;
  25564. case 'D':
  25565. this.setDash(value[0], value[1]);
  25566. break;
  25567. case 'RI':
  25568. break;
  25569. case 'FL':
  25570. break;
  25571. case 'Font':
  25572. this.setFont(value);
  25573. break;
  25574. case 'CA':
  25575. break;
  25576. case 'ca':
  25577. break;
  25578. case 'BM':
  25579. break;
  25580. case 'SMask':
  25581. break;
  25582. }
  25583. }
  25584. },
  25585. fill: function SVGGraphics_fill() {
  25586. var current = this.current;
  25587. current.element.setAttributeNS(null, 'fill', current.fillColor);
  25588. },
  25589. stroke: function SVGGraphics_stroke() {
  25590. var current = this.current;
  25591. current.element.setAttributeNS(null, 'stroke', current.strokeColor);
  25592. current.element.setAttributeNS(null, 'fill', 'none');
  25593. },
  25594. eoFill: function SVGGraphics_eoFill() {
  25595. var current = this.current;
  25596. current.element.setAttributeNS(null, 'fill', current.fillColor);
  25597. current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  25598. },
  25599. fillStroke: function SVGGraphics_fillStroke() {
  25600. // Order is important since stroke wants fill to be none.
  25601. // First stroke, then if fill needed, it will be overwritten.
  25602. this.stroke();
  25603. this.fill();
  25604. },
  25605. eoFillStroke: function SVGGraphics_eoFillStroke() {
  25606. this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  25607. this.fillStroke();
  25608. },
  25609. closeStroke: function SVGGraphics_closeStroke() {
  25610. this.closePath();
  25611. this.stroke();
  25612. },
  25613. closeFillStroke: function SVGGraphics_closeFillStroke() {
  25614. this.closePath();
  25615. this.fillStroke();
  25616. },
  25617. paintSolidColorImageMask: function SVGGraphics_paintSolidColorImageMask() {
  25618. var current = this.current;
  25619. var rect = document.createElementNS(NS, 'svg:rect');
  25620. rect.setAttributeNS(null, 'x', '0');
  25621. rect.setAttributeNS(null, 'y', '0');
  25622. rect.setAttributeNS(null, 'width', '1px');
  25623. rect.setAttributeNS(null, 'height', '1px');
  25624. rect.setAttributeNS(null, 'fill', current.fillColor);
  25625. this.tgrp.appendChild(rect);
  25626. },
  25627. paintJpegXObject: function SVGGraphics_paintJpegXObject(objId, w, h) {
  25628. var current = this.current;
  25629. var imgObj = this.objs.get(objId);
  25630. var imgEl = document.createElementNS(NS, 'svg:image');
  25631. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgObj.src);
  25632. imgEl.setAttributeNS(null, 'width', imgObj.width + 'px');
  25633. imgEl.setAttributeNS(null, 'height', imgObj.height + 'px');
  25634. imgEl.setAttributeNS(null, 'x', '0');
  25635. imgEl.setAttributeNS(null, 'y', pf(-h));
  25636. imgEl.setAttributeNS(null, 'transform', 'scale(' + pf(1 / w) + ' ' + pf(-1 / h) + ')');
  25637. this.tgrp.appendChild(imgEl);
  25638. if (current.pendingClip) {
  25639. this.cgrp.appendChild(this.tgrp);
  25640. this.pgrp.appendChild(this.cgrp);
  25641. } else {
  25642. this.pgrp.appendChild(this.tgrp);
  25643. }
  25644. },
  25645. paintImageXObject: function SVGGraphics_paintImageXObject(objId) {
  25646. var imgData = this.objs.get(objId);
  25647. if (!imgData) {
  25648. warn('Dependent image isn\'t ready yet');
  25649. return;
  25650. }
  25651. this.paintInlineImageXObject(imgData);
  25652. },
  25653. paintInlineImageXObject: function SVGGraphics_paintInlineImageXObject(imgData, mask) {
  25654. var current = this.current;
  25655. var width = imgData.width;
  25656. var height = imgData.height;
  25657. var imgSrc = convertImgDataToPng(imgData, this.forceDataSchema);
  25658. var cliprect = document.createElementNS(NS, 'svg:rect');
  25659. cliprect.setAttributeNS(null, 'x', '0');
  25660. cliprect.setAttributeNS(null, 'y', '0');
  25661. cliprect.setAttributeNS(null, 'width', pf(width));
  25662. cliprect.setAttributeNS(null, 'height', pf(height));
  25663. current.element = cliprect;
  25664. this.clip('nonzero');
  25665. var imgEl = document.createElementNS(NS, 'svg:image');
  25666. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgSrc);
  25667. imgEl.setAttributeNS(null, 'x', '0');
  25668. imgEl.setAttributeNS(null, 'y', pf(-height));
  25669. imgEl.setAttributeNS(null, 'width', pf(width) + 'px');
  25670. imgEl.setAttributeNS(null, 'height', pf(height) + 'px');
  25671. imgEl.setAttributeNS(null, 'transform', 'scale(' + pf(1 / width) + ' ' + pf(-1 / height) + ')');
  25672. if (mask) {
  25673. mask.appendChild(imgEl);
  25674. } else {
  25675. this.tgrp.appendChild(imgEl);
  25676. }
  25677. if (current.pendingClip) {
  25678. this.cgrp.appendChild(this.tgrp);
  25679. this.pgrp.appendChild(this.cgrp);
  25680. } else {
  25681. this.pgrp.appendChild(this.tgrp);
  25682. }
  25683. },
  25684. paintImageMaskXObject: function SVGGraphics_paintImageMaskXObject(imgData) {
  25685. var current = this.current;
  25686. var width = imgData.width;
  25687. var height = imgData.height;
  25688. var fillColor = current.fillColor;
  25689. current.maskId = 'mask' + maskCount++;
  25690. var mask = document.createElementNS(NS, 'svg:mask');
  25691. mask.setAttributeNS(null, 'id', current.maskId);
  25692. var rect = document.createElementNS(NS, 'svg:rect');
  25693. rect.setAttributeNS(null, 'x', '0');
  25694. rect.setAttributeNS(null, 'y', '0');
  25695. rect.setAttributeNS(null, 'width', pf(width));
  25696. rect.setAttributeNS(null, 'height', pf(height));
  25697. rect.setAttributeNS(null, 'fill', fillColor);
  25698. rect.setAttributeNS(null, 'mask', 'url(#' + current.maskId + ')');
  25699. this.defs.appendChild(mask);
  25700. this.tgrp.appendChild(rect);
  25701. this.paintInlineImageXObject(imgData, mask);
  25702. },
  25703. paintFormXObjectBegin: function SVGGraphics_paintFormXObjectBegin(matrix, bbox) {
  25704. this.save();
  25705. if (isArray(matrix) && matrix.length === 6) {
  25706. this.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
  25707. }
  25708. if (isArray(bbox) && bbox.length === 4) {
  25709. var width = bbox[2] - bbox[0];
  25710. var height = bbox[3] - bbox[1];
  25711. var cliprect = document.createElementNS(NS, 'svg:rect');
  25712. cliprect.setAttributeNS(null, 'x', bbox[0]);
  25713. cliprect.setAttributeNS(null, 'y', bbox[1]);
  25714. cliprect.setAttributeNS(null, 'width', pf(width));
  25715. cliprect.setAttributeNS(null, 'height', pf(height));
  25716. this.current.element = cliprect;
  25717. this.clip('nonzero');
  25718. this.endPath();
  25719. }
  25720. },
  25721. paintFormXObjectEnd: function SVGGraphics_paintFormXObjectEnd() {
  25722. this.restore();
  25723. }
  25724. };
  25725. return SVGGraphics;
  25726. }();
  25727. exports.SVGGraphics = SVGGraphics;
  25728. }));
  25729. (function (root, factory) {
  25730. factory(root.pdfjsCoreStream = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreJbig2, root.pdfjsCoreJpg, root.pdfjsCoreJpx);
  25731. }(this, function (exports, sharedUtil, corePrimitives, coreJbig2, coreJpg, coreJpx) {
  25732. var Util = sharedUtil.Util;
  25733. var error = sharedUtil.error;
  25734. var info = sharedUtil.info;
  25735. var isInt = sharedUtil.isInt;
  25736. var isArray = sharedUtil.isArray;
  25737. var createObjectURL = sharedUtil.createObjectURL;
  25738. var shadow = sharedUtil.shadow;
  25739. var warn = sharedUtil.warn;
  25740. var isSpace = sharedUtil.isSpace;
  25741. var Dict = corePrimitives.Dict;
  25742. var isDict = corePrimitives.isDict;
  25743. var isStream = corePrimitives.isStream;
  25744. var Jbig2Image = coreJbig2.Jbig2Image;
  25745. var JpegImage = coreJpg.JpegImage;
  25746. var JpxImage = coreJpx.JpxImage;
  25747. var Stream = function StreamClosure() {
  25748. function Stream(arrayBuffer, start, length, dict) {
  25749. this.bytes = arrayBuffer instanceof Uint8Array ? arrayBuffer : new Uint8Array(arrayBuffer);
  25750. this.start = start || 0;
  25751. this.pos = this.start;
  25752. this.end = start + length || this.bytes.length;
  25753. this.dict = dict;
  25754. }
  25755. // required methods for a stream. if a particular stream does not
  25756. // implement these, an error should be thrown
  25757. Stream.prototype = {
  25758. get length() {
  25759. return this.end - this.start;
  25760. },
  25761. get isEmpty() {
  25762. return this.length === 0;
  25763. },
  25764. getByte: function Stream_getByte() {
  25765. if (this.pos >= this.end) {
  25766. return -1;
  25767. }
  25768. return this.bytes[this.pos++];
  25769. },
  25770. getUint16: function Stream_getUint16() {
  25771. var b0 = this.getByte();
  25772. var b1 = this.getByte();
  25773. if (b0 === -1 || b1 === -1) {
  25774. return -1;
  25775. }
  25776. return (b0 << 8) + b1;
  25777. },
  25778. getInt32: function Stream_getInt32() {
  25779. var b0 = this.getByte();
  25780. var b1 = this.getByte();
  25781. var b2 = this.getByte();
  25782. var b3 = this.getByte();
  25783. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  25784. },
  25785. // returns subarray of original buffer
  25786. // should only be read
  25787. getBytes: function Stream_getBytes(length) {
  25788. var bytes = this.bytes;
  25789. var pos = this.pos;
  25790. var strEnd = this.end;
  25791. if (!length) {
  25792. return bytes.subarray(pos, strEnd);
  25793. }
  25794. var end = pos + length;
  25795. if (end > strEnd) {
  25796. end = strEnd;
  25797. }
  25798. this.pos = end;
  25799. return bytes.subarray(pos, end);
  25800. },
  25801. peekByte: function Stream_peekByte() {
  25802. var peekedByte = this.getByte();
  25803. this.pos--;
  25804. return peekedByte;
  25805. },
  25806. peekBytes: function Stream_peekBytes(length) {
  25807. var bytes = this.getBytes(length);
  25808. this.pos -= bytes.length;
  25809. return bytes;
  25810. },
  25811. skip: function Stream_skip(n) {
  25812. if (!n) {
  25813. n = 1;
  25814. }
  25815. this.pos += n;
  25816. },
  25817. reset: function Stream_reset() {
  25818. this.pos = this.start;
  25819. },
  25820. moveStart: function Stream_moveStart() {
  25821. this.start = this.pos;
  25822. },
  25823. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  25824. return new Stream(this.bytes.buffer, start, length, dict);
  25825. },
  25826. isStream: true
  25827. };
  25828. return Stream;
  25829. }();
  25830. var StringStream = function StringStreamClosure() {
  25831. function StringStream(str) {
  25832. var length = str.length;
  25833. var bytes = new Uint8Array(length);
  25834. for (var n = 0; n < length; ++n) {
  25835. bytes[n] = str.charCodeAt(n);
  25836. }
  25837. Stream.call(this, bytes);
  25838. }
  25839. StringStream.prototype = Stream.prototype;
  25840. return StringStream;
  25841. }();
  25842. // super class for the decoding streams
  25843. var DecodeStream = function DecodeStreamClosure() {
  25844. // Lots of DecodeStreams are created whose buffers are never used. For these
  25845. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  25846. // having special cases that would be required if we used |null| for an empty
  25847. // buffer.
  25848. var emptyBuffer = new Uint8Array(0);
  25849. function DecodeStream(maybeMinBufferLength) {
  25850. this.pos = 0;
  25851. this.bufferLength = 0;
  25852. this.eof = false;
  25853. this.buffer = emptyBuffer;
  25854. this.minBufferLength = 512;
  25855. if (maybeMinBufferLength) {
  25856. // Compute the first power of two that is as big as maybeMinBufferLength.
  25857. while (this.minBufferLength < maybeMinBufferLength) {
  25858. this.minBufferLength *= 2;
  25859. }
  25860. }
  25861. }
  25862. DecodeStream.prototype = {
  25863. get isEmpty() {
  25864. while (!this.eof && this.bufferLength === 0) {
  25865. this.readBlock();
  25866. }
  25867. return this.bufferLength === 0;
  25868. },
  25869. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  25870. var buffer = this.buffer;
  25871. if (requested <= buffer.byteLength) {
  25872. return buffer;
  25873. }
  25874. var size = this.minBufferLength;
  25875. while (size < requested) {
  25876. size *= 2;
  25877. }
  25878. var buffer2 = new Uint8Array(size);
  25879. buffer2.set(buffer);
  25880. return this.buffer = buffer2;
  25881. },
  25882. getByte: function DecodeStream_getByte() {
  25883. var pos = this.pos;
  25884. while (this.bufferLength <= pos) {
  25885. if (this.eof) {
  25886. return -1;
  25887. }
  25888. this.readBlock();
  25889. }
  25890. return this.buffer[this.pos++];
  25891. },
  25892. getUint16: function DecodeStream_getUint16() {
  25893. var b0 = this.getByte();
  25894. var b1 = this.getByte();
  25895. if (b0 === -1 || b1 === -1) {
  25896. return -1;
  25897. }
  25898. return (b0 << 8) + b1;
  25899. },
  25900. getInt32: function DecodeStream_getInt32() {
  25901. var b0 = this.getByte();
  25902. var b1 = this.getByte();
  25903. var b2 = this.getByte();
  25904. var b3 = this.getByte();
  25905. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  25906. },
  25907. getBytes: function DecodeStream_getBytes(length) {
  25908. var end, pos = this.pos;
  25909. if (length) {
  25910. this.ensureBuffer(pos + length);
  25911. end = pos + length;
  25912. while (!this.eof && this.bufferLength < end) {
  25913. this.readBlock();
  25914. }
  25915. var bufEnd = this.bufferLength;
  25916. if (end > bufEnd) {
  25917. end = bufEnd;
  25918. }
  25919. } else {
  25920. while (!this.eof) {
  25921. this.readBlock();
  25922. }
  25923. end = this.bufferLength;
  25924. }
  25925. this.pos = end;
  25926. return this.buffer.subarray(pos, end);
  25927. },
  25928. peekByte: function DecodeStream_peekByte() {
  25929. var peekedByte = this.getByte();
  25930. this.pos--;
  25931. return peekedByte;
  25932. },
  25933. peekBytes: function DecodeStream_peekBytes(length) {
  25934. var bytes = this.getBytes(length);
  25935. this.pos -= bytes.length;
  25936. return bytes;
  25937. },
  25938. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  25939. var end = start + length;
  25940. while (this.bufferLength <= end && !this.eof) {
  25941. this.readBlock();
  25942. }
  25943. return new Stream(this.buffer, start, length, dict);
  25944. },
  25945. skip: function DecodeStream_skip(n) {
  25946. if (!n) {
  25947. n = 1;
  25948. }
  25949. this.pos += n;
  25950. },
  25951. reset: function DecodeStream_reset() {
  25952. this.pos = 0;
  25953. },
  25954. getBaseStreams: function DecodeStream_getBaseStreams() {
  25955. if (this.str && this.str.getBaseStreams) {
  25956. return this.str.getBaseStreams();
  25957. }
  25958. return [];
  25959. }
  25960. };
  25961. return DecodeStream;
  25962. }();
  25963. var StreamsSequenceStream = function StreamsSequenceStreamClosure() {
  25964. function StreamsSequenceStream(streams) {
  25965. this.streams = streams;
  25966. DecodeStream.call(this, /* maybeLength = */
  25967. null);
  25968. }
  25969. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  25970. StreamsSequenceStream.prototype.readBlock = function streamSequenceStreamReadBlock() {
  25971. var streams = this.streams;
  25972. if (streams.length === 0) {
  25973. this.eof = true;
  25974. return;
  25975. }
  25976. var stream = streams.shift();
  25977. var chunk = stream.getBytes();
  25978. var bufferLength = this.bufferLength;
  25979. var newLength = bufferLength + chunk.length;
  25980. var buffer = this.ensureBuffer(newLength);
  25981. buffer.set(chunk, bufferLength);
  25982. this.bufferLength = newLength;
  25983. };
  25984. StreamsSequenceStream.prototype.getBaseStreams = function StreamsSequenceStream_getBaseStreams() {
  25985. var baseStreams = [];
  25986. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  25987. var stream = this.streams[i];
  25988. if (stream.getBaseStreams) {
  25989. Util.appendToArray(baseStreams, stream.getBaseStreams());
  25990. }
  25991. }
  25992. return baseStreams;
  25993. };
  25994. return StreamsSequenceStream;
  25995. }();
  25996. var FlateStream = function FlateStreamClosure() {
  25997. var codeLenCodeMap = new Int32Array([
  25998. 16,
  25999. 17,
  26000. 18,
  26001. 0,
  26002. 8,
  26003. 7,
  26004. 9,
  26005. 6,
  26006. 10,
  26007. 5,
  26008. 11,
  26009. 4,
  26010. 12,
  26011. 3,
  26012. 13,
  26013. 2,
  26014. 14,
  26015. 1,
  26016. 15
  26017. ]);
  26018. var lengthDecode = new Int32Array([
  26019. 0x00003,
  26020. 0x00004,
  26021. 0x00005,
  26022. 0x00006,
  26023. 0x00007,
  26024. 0x00008,
  26025. 0x00009,
  26026. 0x0000a,
  26027. 0x1000b,
  26028. 0x1000d,
  26029. 0x1000f,
  26030. 0x10011,
  26031. 0x20013,
  26032. 0x20017,
  26033. 0x2001b,
  26034. 0x2001f,
  26035. 0x30023,
  26036. 0x3002b,
  26037. 0x30033,
  26038. 0x3003b,
  26039. 0x40043,
  26040. 0x40053,
  26041. 0x40063,
  26042. 0x40073,
  26043. 0x50083,
  26044. 0x500a3,
  26045. 0x500c3,
  26046. 0x500e3,
  26047. 0x00102,
  26048. 0x00102,
  26049. 0x00102
  26050. ]);
  26051. var distDecode = new Int32Array([
  26052. 0x00001,
  26053. 0x00002,
  26054. 0x00003,
  26055. 0x00004,
  26056. 0x10005,
  26057. 0x10007,
  26058. 0x20009,
  26059. 0x2000d,
  26060. 0x30011,
  26061. 0x30019,
  26062. 0x40021,
  26063. 0x40031,
  26064. 0x50041,
  26065. 0x50061,
  26066. 0x60081,
  26067. 0x600c1,
  26068. 0x70101,
  26069. 0x70181,
  26070. 0x80201,
  26071. 0x80301,
  26072. 0x90401,
  26073. 0x90601,
  26074. 0xa0801,
  26075. 0xa0c01,
  26076. 0xb1001,
  26077. 0xb1801,
  26078. 0xc2001,
  26079. 0xc3001,
  26080. 0xd4001,
  26081. 0xd6001
  26082. ]);
  26083. var fixedLitCodeTab = [
  26084. new Int32Array([
  26085. 0x70100,
  26086. 0x80050,
  26087. 0x80010,
  26088. 0x80118,
  26089. 0x70110,
  26090. 0x80070,
  26091. 0x80030,
  26092. 0x900c0,
  26093. 0x70108,
  26094. 0x80060,
  26095. 0x80020,
  26096. 0x900a0,
  26097. 0x80000,
  26098. 0x80080,
  26099. 0x80040,
  26100. 0x900e0,
  26101. 0x70104,
  26102. 0x80058,
  26103. 0x80018,
  26104. 0x90090,
  26105. 0x70114,
  26106. 0x80078,
  26107. 0x80038,
  26108. 0x900d0,
  26109. 0x7010c,
  26110. 0x80068,
  26111. 0x80028,
  26112. 0x900b0,
  26113. 0x80008,
  26114. 0x80088,
  26115. 0x80048,
  26116. 0x900f0,
  26117. 0x70102,
  26118. 0x80054,
  26119. 0x80014,
  26120. 0x8011c,
  26121. 0x70112,
  26122. 0x80074,
  26123. 0x80034,
  26124. 0x900c8,
  26125. 0x7010a,
  26126. 0x80064,
  26127. 0x80024,
  26128. 0x900a8,
  26129. 0x80004,
  26130. 0x80084,
  26131. 0x80044,
  26132. 0x900e8,
  26133. 0x70106,
  26134. 0x8005c,
  26135. 0x8001c,
  26136. 0x90098,
  26137. 0x70116,
  26138. 0x8007c,
  26139. 0x8003c,
  26140. 0x900d8,
  26141. 0x7010e,
  26142. 0x8006c,
  26143. 0x8002c,
  26144. 0x900b8,
  26145. 0x8000c,
  26146. 0x8008c,
  26147. 0x8004c,
  26148. 0x900f8,
  26149. 0x70101,
  26150. 0x80052,
  26151. 0x80012,
  26152. 0x8011a,
  26153. 0x70111,
  26154. 0x80072,
  26155. 0x80032,
  26156. 0x900c4,
  26157. 0x70109,
  26158. 0x80062,
  26159. 0x80022,
  26160. 0x900a4,
  26161. 0x80002,
  26162. 0x80082,
  26163. 0x80042,
  26164. 0x900e4,
  26165. 0x70105,
  26166. 0x8005a,
  26167. 0x8001a,
  26168. 0x90094,
  26169. 0x70115,
  26170. 0x8007a,
  26171. 0x8003a,
  26172. 0x900d4,
  26173. 0x7010d,
  26174. 0x8006a,
  26175. 0x8002a,
  26176. 0x900b4,
  26177. 0x8000a,
  26178. 0x8008a,
  26179. 0x8004a,
  26180. 0x900f4,
  26181. 0x70103,
  26182. 0x80056,
  26183. 0x80016,
  26184. 0x8011e,
  26185. 0x70113,
  26186. 0x80076,
  26187. 0x80036,
  26188. 0x900cc,
  26189. 0x7010b,
  26190. 0x80066,
  26191. 0x80026,
  26192. 0x900ac,
  26193. 0x80006,
  26194. 0x80086,
  26195. 0x80046,
  26196. 0x900ec,
  26197. 0x70107,
  26198. 0x8005e,
  26199. 0x8001e,
  26200. 0x9009c,
  26201. 0x70117,
  26202. 0x8007e,
  26203. 0x8003e,
  26204. 0x900dc,
  26205. 0x7010f,
  26206. 0x8006e,
  26207. 0x8002e,
  26208. 0x900bc,
  26209. 0x8000e,
  26210. 0x8008e,
  26211. 0x8004e,
  26212. 0x900fc,
  26213. 0x70100,
  26214. 0x80051,
  26215. 0x80011,
  26216. 0x80119,
  26217. 0x70110,
  26218. 0x80071,
  26219. 0x80031,
  26220. 0x900c2,
  26221. 0x70108,
  26222. 0x80061,
  26223. 0x80021,
  26224. 0x900a2,
  26225. 0x80001,
  26226. 0x80081,
  26227. 0x80041,
  26228. 0x900e2,
  26229. 0x70104,
  26230. 0x80059,
  26231. 0x80019,
  26232. 0x90092,
  26233. 0x70114,
  26234. 0x80079,
  26235. 0x80039,
  26236. 0x900d2,
  26237. 0x7010c,
  26238. 0x80069,
  26239. 0x80029,
  26240. 0x900b2,
  26241. 0x80009,
  26242. 0x80089,
  26243. 0x80049,
  26244. 0x900f2,
  26245. 0x70102,
  26246. 0x80055,
  26247. 0x80015,
  26248. 0x8011d,
  26249. 0x70112,
  26250. 0x80075,
  26251. 0x80035,
  26252. 0x900ca,
  26253. 0x7010a,
  26254. 0x80065,
  26255. 0x80025,
  26256. 0x900aa,
  26257. 0x80005,
  26258. 0x80085,
  26259. 0x80045,
  26260. 0x900ea,
  26261. 0x70106,
  26262. 0x8005d,
  26263. 0x8001d,
  26264. 0x9009a,
  26265. 0x70116,
  26266. 0x8007d,
  26267. 0x8003d,
  26268. 0x900da,
  26269. 0x7010e,
  26270. 0x8006d,
  26271. 0x8002d,
  26272. 0x900ba,
  26273. 0x8000d,
  26274. 0x8008d,
  26275. 0x8004d,
  26276. 0x900fa,
  26277. 0x70101,
  26278. 0x80053,
  26279. 0x80013,
  26280. 0x8011b,
  26281. 0x70111,
  26282. 0x80073,
  26283. 0x80033,
  26284. 0x900c6,
  26285. 0x70109,
  26286. 0x80063,
  26287. 0x80023,
  26288. 0x900a6,
  26289. 0x80003,
  26290. 0x80083,
  26291. 0x80043,
  26292. 0x900e6,
  26293. 0x70105,
  26294. 0x8005b,
  26295. 0x8001b,
  26296. 0x90096,
  26297. 0x70115,
  26298. 0x8007b,
  26299. 0x8003b,
  26300. 0x900d6,
  26301. 0x7010d,
  26302. 0x8006b,
  26303. 0x8002b,
  26304. 0x900b6,
  26305. 0x8000b,
  26306. 0x8008b,
  26307. 0x8004b,
  26308. 0x900f6,
  26309. 0x70103,
  26310. 0x80057,
  26311. 0x80017,
  26312. 0x8011f,
  26313. 0x70113,
  26314. 0x80077,
  26315. 0x80037,
  26316. 0x900ce,
  26317. 0x7010b,
  26318. 0x80067,
  26319. 0x80027,
  26320. 0x900ae,
  26321. 0x80007,
  26322. 0x80087,
  26323. 0x80047,
  26324. 0x900ee,
  26325. 0x70107,
  26326. 0x8005f,
  26327. 0x8001f,
  26328. 0x9009e,
  26329. 0x70117,
  26330. 0x8007f,
  26331. 0x8003f,
  26332. 0x900de,
  26333. 0x7010f,
  26334. 0x8006f,
  26335. 0x8002f,
  26336. 0x900be,
  26337. 0x8000f,
  26338. 0x8008f,
  26339. 0x8004f,
  26340. 0x900fe,
  26341. 0x70100,
  26342. 0x80050,
  26343. 0x80010,
  26344. 0x80118,
  26345. 0x70110,
  26346. 0x80070,
  26347. 0x80030,
  26348. 0x900c1,
  26349. 0x70108,
  26350. 0x80060,
  26351. 0x80020,
  26352. 0x900a1,
  26353. 0x80000,
  26354. 0x80080,
  26355. 0x80040,
  26356. 0x900e1,
  26357. 0x70104,
  26358. 0x80058,
  26359. 0x80018,
  26360. 0x90091,
  26361. 0x70114,
  26362. 0x80078,
  26363. 0x80038,
  26364. 0x900d1,
  26365. 0x7010c,
  26366. 0x80068,
  26367. 0x80028,
  26368. 0x900b1,
  26369. 0x80008,
  26370. 0x80088,
  26371. 0x80048,
  26372. 0x900f1,
  26373. 0x70102,
  26374. 0x80054,
  26375. 0x80014,
  26376. 0x8011c,
  26377. 0x70112,
  26378. 0x80074,
  26379. 0x80034,
  26380. 0x900c9,
  26381. 0x7010a,
  26382. 0x80064,
  26383. 0x80024,
  26384. 0x900a9,
  26385. 0x80004,
  26386. 0x80084,
  26387. 0x80044,
  26388. 0x900e9,
  26389. 0x70106,
  26390. 0x8005c,
  26391. 0x8001c,
  26392. 0x90099,
  26393. 0x70116,
  26394. 0x8007c,
  26395. 0x8003c,
  26396. 0x900d9,
  26397. 0x7010e,
  26398. 0x8006c,
  26399. 0x8002c,
  26400. 0x900b9,
  26401. 0x8000c,
  26402. 0x8008c,
  26403. 0x8004c,
  26404. 0x900f9,
  26405. 0x70101,
  26406. 0x80052,
  26407. 0x80012,
  26408. 0x8011a,
  26409. 0x70111,
  26410. 0x80072,
  26411. 0x80032,
  26412. 0x900c5,
  26413. 0x70109,
  26414. 0x80062,
  26415. 0x80022,
  26416. 0x900a5,
  26417. 0x80002,
  26418. 0x80082,
  26419. 0x80042,
  26420. 0x900e5,
  26421. 0x70105,
  26422. 0x8005a,
  26423. 0x8001a,
  26424. 0x90095,
  26425. 0x70115,
  26426. 0x8007a,
  26427. 0x8003a,
  26428. 0x900d5,
  26429. 0x7010d,
  26430. 0x8006a,
  26431. 0x8002a,
  26432. 0x900b5,
  26433. 0x8000a,
  26434. 0x8008a,
  26435. 0x8004a,
  26436. 0x900f5,
  26437. 0x70103,
  26438. 0x80056,
  26439. 0x80016,
  26440. 0x8011e,
  26441. 0x70113,
  26442. 0x80076,
  26443. 0x80036,
  26444. 0x900cd,
  26445. 0x7010b,
  26446. 0x80066,
  26447. 0x80026,
  26448. 0x900ad,
  26449. 0x80006,
  26450. 0x80086,
  26451. 0x80046,
  26452. 0x900ed,
  26453. 0x70107,
  26454. 0x8005e,
  26455. 0x8001e,
  26456. 0x9009d,
  26457. 0x70117,
  26458. 0x8007e,
  26459. 0x8003e,
  26460. 0x900dd,
  26461. 0x7010f,
  26462. 0x8006e,
  26463. 0x8002e,
  26464. 0x900bd,
  26465. 0x8000e,
  26466. 0x8008e,
  26467. 0x8004e,
  26468. 0x900fd,
  26469. 0x70100,
  26470. 0x80051,
  26471. 0x80011,
  26472. 0x80119,
  26473. 0x70110,
  26474. 0x80071,
  26475. 0x80031,
  26476. 0x900c3,
  26477. 0x70108,
  26478. 0x80061,
  26479. 0x80021,
  26480. 0x900a3,
  26481. 0x80001,
  26482. 0x80081,
  26483. 0x80041,
  26484. 0x900e3,
  26485. 0x70104,
  26486. 0x80059,
  26487. 0x80019,
  26488. 0x90093,
  26489. 0x70114,
  26490. 0x80079,
  26491. 0x80039,
  26492. 0x900d3,
  26493. 0x7010c,
  26494. 0x80069,
  26495. 0x80029,
  26496. 0x900b3,
  26497. 0x80009,
  26498. 0x80089,
  26499. 0x80049,
  26500. 0x900f3,
  26501. 0x70102,
  26502. 0x80055,
  26503. 0x80015,
  26504. 0x8011d,
  26505. 0x70112,
  26506. 0x80075,
  26507. 0x80035,
  26508. 0x900cb,
  26509. 0x7010a,
  26510. 0x80065,
  26511. 0x80025,
  26512. 0x900ab,
  26513. 0x80005,
  26514. 0x80085,
  26515. 0x80045,
  26516. 0x900eb,
  26517. 0x70106,
  26518. 0x8005d,
  26519. 0x8001d,
  26520. 0x9009b,
  26521. 0x70116,
  26522. 0x8007d,
  26523. 0x8003d,
  26524. 0x900db,
  26525. 0x7010e,
  26526. 0x8006d,
  26527. 0x8002d,
  26528. 0x900bb,
  26529. 0x8000d,
  26530. 0x8008d,
  26531. 0x8004d,
  26532. 0x900fb,
  26533. 0x70101,
  26534. 0x80053,
  26535. 0x80013,
  26536. 0x8011b,
  26537. 0x70111,
  26538. 0x80073,
  26539. 0x80033,
  26540. 0x900c7,
  26541. 0x70109,
  26542. 0x80063,
  26543. 0x80023,
  26544. 0x900a7,
  26545. 0x80003,
  26546. 0x80083,
  26547. 0x80043,
  26548. 0x900e7,
  26549. 0x70105,
  26550. 0x8005b,
  26551. 0x8001b,
  26552. 0x90097,
  26553. 0x70115,
  26554. 0x8007b,
  26555. 0x8003b,
  26556. 0x900d7,
  26557. 0x7010d,
  26558. 0x8006b,
  26559. 0x8002b,
  26560. 0x900b7,
  26561. 0x8000b,
  26562. 0x8008b,
  26563. 0x8004b,
  26564. 0x900f7,
  26565. 0x70103,
  26566. 0x80057,
  26567. 0x80017,
  26568. 0x8011f,
  26569. 0x70113,
  26570. 0x80077,
  26571. 0x80037,
  26572. 0x900cf,
  26573. 0x7010b,
  26574. 0x80067,
  26575. 0x80027,
  26576. 0x900af,
  26577. 0x80007,
  26578. 0x80087,
  26579. 0x80047,
  26580. 0x900ef,
  26581. 0x70107,
  26582. 0x8005f,
  26583. 0x8001f,
  26584. 0x9009f,
  26585. 0x70117,
  26586. 0x8007f,
  26587. 0x8003f,
  26588. 0x900df,
  26589. 0x7010f,
  26590. 0x8006f,
  26591. 0x8002f,
  26592. 0x900bf,
  26593. 0x8000f,
  26594. 0x8008f,
  26595. 0x8004f,
  26596. 0x900ff
  26597. ]),
  26598. 9
  26599. ];
  26600. var fixedDistCodeTab = [
  26601. new Int32Array([
  26602. 0x50000,
  26603. 0x50010,
  26604. 0x50008,
  26605. 0x50018,
  26606. 0x50004,
  26607. 0x50014,
  26608. 0x5000c,
  26609. 0x5001c,
  26610. 0x50002,
  26611. 0x50012,
  26612. 0x5000a,
  26613. 0x5001a,
  26614. 0x50006,
  26615. 0x50016,
  26616. 0x5000e,
  26617. 0x00000,
  26618. 0x50001,
  26619. 0x50011,
  26620. 0x50009,
  26621. 0x50019,
  26622. 0x50005,
  26623. 0x50015,
  26624. 0x5000d,
  26625. 0x5001d,
  26626. 0x50003,
  26627. 0x50013,
  26628. 0x5000b,
  26629. 0x5001b,
  26630. 0x50007,
  26631. 0x50017,
  26632. 0x5000f,
  26633. 0x00000
  26634. ]),
  26635. 5
  26636. ];
  26637. function FlateStream(str, maybeLength) {
  26638. this.str = str;
  26639. this.dict = str.dict;
  26640. var cmf = str.getByte();
  26641. var flg = str.getByte();
  26642. if (cmf === -1 || flg === -1) {
  26643. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  26644. }
  26645. if ((cmf & 0x0f) !== 0x08) {
  26646. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  26647. }
  26648. if (((cmf << 8) + flg) % 31 !== 0) {
  26649. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  26650. }
  26651. if (flg & 0x20) {
  26652. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  26653. }
  26654. this.codeSize = 0;
  26655. this.codeBuf = 0;
  26656. DecodeStream.call(this, maybeLength);
  26657. }
  26658. FlateStream.prototype = Object.create(DecodeStream.prototype);
  26659. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  26660. var str = this.str;
  26661. var codeSize = this.codeSize;
  26662. var codeBuf = this.codeBuf;
  26663. var b;
  26664. while (codeSize < bits) {
  26665. if ((b = str.getByte()) === -1) {
  26666. error('Bad encoding in flate stream');
  26667. }
  26668. codeBuf |= b << codeSize;
  26669. codeSize += 8;
  26670. }
  26671. b = codeBuf & (1 << bits) - 1;
  26672. this.codeBuf = codeBuf >> bits;
  26673. this.codeSize = codeSize -= bits;
  26674. return b;
  26675. };
  26676. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  26677. var str = this.str;
  26678. var codes = table[0];
  26679. var maxLen = table[1];
  26680. var codeSize = this.codeSize;
  26681. var codeBuf = this.codeBuf;
  26682. var b;
  26683. while (codeSize < maxLen) {
  26684. if ((b = str.getByte()) === -1) {
  26685. // premature end of stream. code might however still be valid.
  26686. // codeSize < codeLen check below guards against incomplete codeVal.
  26687. break;
  26688. }
  26689. codeBuf |= b << codeSize;
  26690. codeSize += 8;
  26691. }
  26692. var code = codes[codeBuf & (1 << maxLen) - 1];
  26693. var codeLen = code >> 16;
  26694. var codeVal = code & 0xffff;
  26695. if (codeLen < 1 || codeSize < codeLen) {
  26696. error('Bad encoding in flate stream');
  26697. }
  26698. this.codeBuf = codeBuf >> codeLen;
  26699. this.codeSize = codeSize - codeLen;
  26700. return codeVal;
  26701. };
  26702. FlateStream.prototype.generateHuffmanTable = function flateStreamGenerateHuffmanTable(lengths) {
  26703. var n = lengths.length;
  26704. // find max code length
  26705. var maxLen = 0;
  26706. var i;
  26707. for (i = 0; i < n; ++i) {
  26708. if (lengths[i] > maxLen) {
  26709. maxLen = lengths[i];
  26710. }
  26711. }
  26712. // build the table
  26713. var size = 1 << maxLen;
  26714. var codes = new Int32Array(size);
  26715. for (var len = 1, code = 0, skip = 2; len <= maxLen; ++len, code <<= 1, skip <<= 1) {
  26716. for (var val = 0; val < n; ++val) {
  26717. if (lengths[val] === len) {
  26718. // bit-reverse the code
  26719. var code2 = 0;
  26720. var t = code;
  26721. for (i = 0; i < len; ++i) {
  26722. code2 = code2 << 1 | t & 1;
  26723. t >>= 1;
  26724. }
  26725. // fill the table entries
  26726. for (i = code2; i < size; i += skip) {
  26727. codes[i] = len << 16 | val;
  26728. }
  26729. ++code;
  26730. }
  26731. }
  26732. }
  26733. return [
  26734. codes,
  26735. maxLen
  26736. ];
  26737. };
  26738. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  26739. var buffer, len;
  26740. var str = this.str;
  26741. // read block header
  26742. var hdr = this.getBits(3);
  26743. if (hdr & 1) {
  26744. this.eof = true;
  26745. }
  26746. hdr >>= 1;
  26747. if (hdr === 0) {
  26748. // uncompressed block
  26749. var b;
  26750. if ((b = str.getByte()) === -1) {
  26751. error('Bad block header in flate stream');
  26752. }
  26753. var blockLen = b;
  26754. if ((b = str.getByte()) === -1) {
  26755. error('Bad block header in flate stream');
  26756. }
  26757. blockLen |= b << 8;
  26758. if ((b = str.getByte()) === -1) {
  26759. error('Bad block header in flate stream');
  26760. }
  26761. var check = b;
  26762. if ((b = str.getByte()) === -1) {
  26763. error('Bad block header in flate stream');
  26764. }
  26765. check |= b << 8;
  26766. if (check !== (~blockLen & 0xffff) && (blockLen !== 0 || check !== 0)) {
  26767. // Ignoring error for bad "empty" block (see issue 1277)
  26768. error('Bad uncompressed block length in flate stream');
  26769. }
  26770. this.codeBuf = 0;
  26771. this.codeSize = 0;
  26772. var bufferLength = this.bufferLength;
  26773. buffer = this.ensureBuffer(bufferLength + blockLen);
  26774. var end = bufferLength + blockLen;
  26775. this.bufferLength = end;
  26776. if (blockLen === 0) {
  26777. if (str.peekByte() === -1) {
  26778. this.eof = true;
  26779. }
  26780. } else {
  26781. for (var n = bufferLength; n < end; ++n) {
  26782. if ((b = str.getByte()) === -1) {
  26783. this.eof = true;
  26784. break;
  26785. }
  26786. buffer[n] = b;
  26787. }
  26788. }
  26789. return;
  26790. }
  26791. var litCodeTable;
  26792. var distCodeTable;
  26793. if (hdr === 1) {
  26794. // compressed block, fixed codes
  26795. litCodeTable = fixedLitCodeTab;
  26796. distCodeTable = fixedDistCodeTab;
  26797. } else if (hdr === 2) {
  26798. // compressed block, dynamic codes
  26799. var numLitCodes = this.getBits(5) + 257;
  26800. var numDistCodes = this.getBits(5) + 1;
  26801. var numCodeLenCodes = this.getBits(4) + 4;
  26802. // build the code lengths code table
  26803. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  26804. var i;
  26805. for (i = 0; i < numCodeLenCodes; ++i) {
  26806. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  26807. }
  26808. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  26809. // build the literal and distance code tables
  26810. len = 0;
  26811. i = 0;
  26812. var codes = numLitCodes + numDistCodes;
  26813. var codeLengths = new Uint8Array(codes);
  26814. var bitsLength, bitsOffset, what;
  26815. while (i < codes) {
  26816. var code = this.getCode(codeLenCodeTab);
  26817. if (code === 16) {
  26818. bitsLength = 2;
  26819. bitsOffset = 3;
  26820. what = len;
  26821. } else if (code === 17) {
  26822. bitsLength = 3;
  26823. bitsOffset = 3;
  26824. what = len = 0;
  26825. } else if (code === 18) {
  26826. bitsLength = 7;
  26827. bitsOffset = 11;
  26828. what = len = 0;
  26829. } else {
  26830. codeLengths[i++] = len = code;
  26831. continue;
  26832. }
  26833. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  26834. while (repeatLength-- > 0) {
  26835. codeLengths[i++] = what;
  26836. }
  26837. }
  26838. litCodeTable = this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  26839. distCodeTable = this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  26840. } else {
  26841. error('Unknown block type in flate stream');
  26842. }
  26843. buffer = this.buffer;
  26844. var limit = buffer ? buffer.length : 0;
  26845. var pos = this.bufferLength;
  26846. while (true) {
  26847. var code1 = this.getCode(litCodeTable);
  26848. if (code1 < 256) {
  26849. if (pos + 1 >= limit) {
  26850. buffer = this.ensureBuffer(pos + 1);
  26851. limit = buffer.length;
  26852. }
  26853. buffer[pos++] = code1;
  26854. continue;
  26855. }
  26856. if (code1 === 256) {
  26857. this.bufferLength = pos;
  26858. return;
  26859. }
  26860. code1 -= 257;
  26861. code1 = lengthDecode[code1];
  26862. var code2 = code1 >> 16;
  26863. if (code2 > 0) {
  26864. code2 = this.getBits(code2);
  26865. }
  26866. len = (code1 & 0xffff) + code2;
  26867. code1 = this.getCode(distCodeTable);
  26868. code1 = distDecode[code1];
  26869. code2 = code1 >> 16;
  26870. if (code2 > 0) {
  26871. code2 = this.getBits(code2);
  26872. }
  26873. var dist = (code1 & 0xffff) + code2;
  26874. if (pos + len >= limit) {
  26875. buffer = this.ensureBuffer(pos + len);
  26876. limit = buffer.length;
  26877. }
  26878. for (var k = 0; k < len; ++k, ++pos) {
  26879. buffer[pos] = buffer[pos - dist];
  26880. }
  26881. }
  26882. };
  26883. return FlateStream;
  26884. }();
  26885. var PredictorStream = function PredictorStreamClosure() {
  26886. function PredictorStream(str, maybeLength, params) {
  26887. if (!isDict(params)) {
  26888. return str;
  26889. }
  26890. // no prediction
  26891. var predictor = this.predictor = params.get('Predictor') || 1;
  26892. if (predictor <= 1) {
  26893. return str;
  26894. }
  26895. // no prediction
  26896. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  26897. error('Unsupported predictor: ' + predictor);
  26898. }
  26899. if (predictor === 2) {
  26900. this.readBlock = this.readBlockTiff;
  26901. } else {
  26902. this.readBlock = this.readBlockPng;
  26903. }
  26904. this.str = str;
  26905. this.dict = str.dict;
  26906. var colors = this.colors = params.get('Colors') || 1;
  26907. var bits = this.bits = params.get('BitsPerComponent') || 8;
  26908. var columns = this.columns = params.get('Columns') || 1;
  26909. this.pixBytes = colors * bits + 7 >> 3;
  26910. this.rowBytes = columns * colors * bits + 7 >> 3;
  26911. DecodeStream.call(this, maybeLength);
  26912. return this;
  26913. }
  26914. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  26915. PredictorStream.prototype.readBlockTiff = function predictorStreamReadBlockTiff() {
  26916. var rowBytes = this.rowBytes;
  26917. var bufferLength = this.bufferLength;
  26918. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  26919. var bits = this.bits;
  26920. var colors = this.colors;
  26921. var rawBytes = this.str.getBytes(rowBytes);
  26922. this.eof = !rawBytes.length;
  26923. if (this.eof) {
  26924. return;
  26925. }
  26926. var inbuf = 0, outbuf = 0;
  26927. var inbits = 0, outbits = 0;
  26928. var pos = bufferLength;
  26929. var i;
  26930. if (bits === 1) {
  26931. for (i = 0; i < rowBytes; ++i) {
  26932. var c = rawBytes[i];
  26933. inbuf = inbuf << 8 | c;
  26934. // bitwise addition is exclusive or
  26935. // first shift inbuf and then add
  26936. buffer[pos++] = (c ^ inbuf >> colors) & 0xFF;
  26937. // truncate inbuf (assumes colors < 16)
  26938. inbuf &= 0xFFFF;
  26939. }
  26940. } else if (bits === 8) {
  26941. for (i = 0; i < colors; ++i) {
  26942. buffer[pos++] = rawBytes[i];
  26943. }
  26944. for (; i < rowBytes; ++i) {
  26945. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  26946. pos++;
  26947. }
  26948. } else {
  26949. var compArray = new Uint8Array(colors + 1);
  26950. var bitMask = (1 << bits) - 1;
  26951. var j = 0, k = bufferLength;
  26952. var columns = this.columns;
  26953. for (i = 0; i < columns; ++i) {
  26954. for (var kk = 0; kk < colors; ++kk) {
  26955. if (inbits < bits) {
  26956. inbuf = inbuf << 8 | rawBytes[j++] & 0xFF;
  26957. inbits += 8;
  26958. }
  26959. compArray[kk] = compArray[kk] + (inbuf >> inbits - bits) & bitMask;
  26960. inbits -= bits;
  26961. outbuf = outbuf << bits | compArray[kk];
  26962. outbits += bits;
  26963. if (outbits >= 8) {
  26964. buffer[k++] = outbuf >> outbits - 8 & 0xFF;
  26965. outbits -= 8;
  26966. }
  26967. }
  26968. }
  26969. if (outbits > 0) {
  26970. buffer[k++] = (outbuf << 8 - outbits) + (inbuf & (1 << 8 - outbits) - 1);
  26971. }
  26972. }
  26973. this.bufferLength += rowBytes;
  26974. };
  26975. PredictorStream.prototype.readBlockPng = function predictorStreamReadBlockPng() {
  26976. var rowBytes = this.rowBytes;
  26977. var pixBytes = this.pixBytes;
  26978. var predictor = this.str.getByte();
  26979. var rawBytes = this.str.getBytes(rowBytes);
  26980. this.eof = !rawBytes.length;
  26981. if (this.eof) {
  26982. return;
  26983. }
  26984. var bufferLength = this.bufferLength;
  26985. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  26986. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  26987. if (prevRow.length === 0) {
  26988. prevRow = new Uint8Array(rowBytes);
  26989. }
  26990. var i, j = bufferLength, up, c;
  26991. switch (predictor) {
  26992. case 0:
  26993. for (i = 0; i < rowBytes; ++i) {
  26994. buffer[j++] = rawBytes[i];
  26995. }
  26996. break;
  26997. case 1:
  26998. for (i = 0; i < pixBytes; ++i) {
  26999. buffer[j++] = rawBytes[i];
  27000. }
  27001. for (; i < rowBytes; ++i) {
  27002. buffer[j] = buffer[j - pixBytes] + rawBytes[i] & 0xFF;
  27003. j++;
  27004. }
  27005. break;
  27006. case 2:
  27007. for (i = 0; i < rowBytes; ++i) {
  27008. buffer[j++] = prevRow[i] + rawBytes[i] & 0xFF;
  27009. }
  27010. break;
  27011. case 3:
  27012. for (i = 0; i < pixBytes; ++i) {
  27013. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  27014. }
  27015. for (; i < rowBytes; ++i) {
  27016. buffer[j] = (prevRow[i] + buffer[j - pixBytes] >> 1) + rawBytes[i] & 0xFF;
  27017. j++;
  27018. }
  27019. break;
  27020. case 4:
  27021. // we need to save the up left pixels values. the simplest way
  27022. // is to create a new buffer
  27023. for (i = 0; i < pixBytes; ++i) {
  27024. up = prevRow[i];
  27025. c = rawBytes[i];
  27026. buffer[j++] = up + c;
  27027. }
  27028. for (; i < rowBytes; ++i) {
  27029. up = prevRow[i];
  27030. var upLeft = prevRow[i - pixBytes];
  27031. var left = buffer[j - pixBytes];
  27032. var p = left + up - upLeft;
  27033. var pa = p - left;
  27034. if (pa < 0) {
  27035. pa = -pa;
  27036. }
  27037. var pb = p - up;
  27038. if (pb < 0) {
  27039. pb = -pb;
  27040. }
  27041. var pc = p - upLeft;
  27042. if (pc < 0) {
  27043. pc = -pc;
  27044. }
  27045. c = rawBytes[i];
  27046. if (pa <= pb && pa <= pc) {
  27047. buffer[j++] = left + c;
  27048. } else if (pb <= pc) {
  27049. buffer[j++] = up + c;
  27050. } else {
  27051. buffer[j++] = upLeft + c;
  27052. }
  27053. }
  27054. break;
  27055. default:
  27056. error('Unsupported predictor: ' + predictor);
  27057. }
  27058. this.bufferLength += rowBytes;
  27059. };
  27060. return PredictorStream;
  27061. }();
  27062. /**
  27063. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  27064. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  27065. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  27066. * a library to decode these images and the stream behaves like all the other
  27067. * DecodeStreams.
  27068. */
  27069. var JpegStream = function JpegStreamClosure() {
  27070. function JpegStream(stream, maybeLength, dict, params) {
  27071. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  27072. // Note: this seems to mainly affect inline images.
  27073. var ch;
  27074. while ((ch = stream.getByte()) !== -1) {
  27075. if (ch === 0xFF) {
  27076. // Find the first byte of the SOI marker (0xFFD8).
  27077. stream.skip(-1);
  27078. // Reset the stream position to the SOI.
  27079. break;
  27080. }
  27081. }
  27082. this.stream = stream;
  27083. this.maybeLength = maybeLength;
  27084. this.dict = dict;
  27085. this.params = params;
  27086. DecodeStream.call(this, maybeLength);
  27087. }
  27088. JpegStream.prototype = Object.create(DecodeStream.prototype);
  27089. Object.defineProperty(JpegStream.prototype, 'bytes', {
  27090. get: function JpegStream_bytes() {
  27091. // If this.maybeLength is null, we'll get the entire stream.
  27092. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  27093. },
  27094. configurable: true
  27095. });
  27096. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  27097. if (this.bufferLength) {
  27098. return;
  27099. }
  27100. var jpegImage = new JpegImage();
  27101. // Checking if values need to be transformed before conversion.
  27102. var decodeArr = this.dict.getArray('Decode', 'D');
  27103. if (this.forceRGB && isArray(decodeArr)) {
  27104. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  27105. var decodeArrLength = decodeArr.length;
  27106. var transform = new Int32Array(decodeArrLength);
  27107. var transformNeeded = false;
  27108. var maxValue = (1 << bitsPerComponent) - 1;
  27109. for (var i = 0; i < decodeArrLength; i += 2) {
  27110. transform[i] = (decodeArr[i + 1] - decodeArr[i]) * 256 | 0;
  27111. transform[i + 1] = decodeArr[i] * maxValue | 0;
  27112. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  27113. transformNeeded = true;
  27114. }
  27115. }
  27116. if (transformNeeded) {
  27117. jpegImage.decodeTransform = transform;
  27118. }
  27119. }
  27120. // Fetching the 'ColorTransform' entry, if it exists.
  27121. if (isDict(this.params)) {
  27122. var colorTransform = this.params.get('ColorTransform');
  27123. if (isInt(colorTransform)) {
  27124. jpegImage.colorTransform = colorTransform;
  27125. }
  27126. }
  27127. jpegImage.parse(this.bytes);
  27128. var data = jpegImage.getData(this.drawWidth, this.drawHeight, this.forceRGB);
  27129. this.buffer = data;
  27130. this.bufferLength = data.length;
  27131. this.eof = true;
  27132. };
  27133. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  27134. this.ensureBuffer();
  27135. return this.buffer;
  27136. };
  27137. JpegStream.prototype.getIR = function JpegStream_getIR(forceDataSchema) {
  27138. return createObjectURL(this.bytes, 'image/jpeg', forceDataSchema);
  27139. };
  27140. return JpegStream;
  27141. }();
  27142. /**
  27143. * For JPEG 2000's we use a library to decode these images and
  27144. * the stream behaves like all the other DecodeStreams.
  27145. */
  27146. var JpxStream = function JpxStreamClosure() {
  27147. function JpxStream(stream, maybeLength, dict, params) {
  27148. this.stream = stream;
  27149. this.maybeLength = maybeLength;
  27150. this.dict = dict;
  27151. this.params = params;
  27152. DecodeStream.call(this, maybeLength);
  27153. }
  27154. JpxStream.prototype = Object.create(DecodeStream.prototype);
  27155. Object.defineProperty(JpxStream.prototype, 'bytes', {
  27156. get: function JpxStream_bytes() {
  27157. // If this.maybeLength is null, we'll get the entire stream.
  27158. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  27159. },
  27160. configurable: true
  27161. });
  27162. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  27163. if (this.bufferLength) {
  27164. return;
  27165. }
  27166. var jpxImage = new JpxImage();
  27167. jpxImage.parse(this.bytes);
  27168. var width = jpxImage.width;
  27169. var height = jpxImage.height;
  27170. var componentsCount = jpxImage.componentsCount;
  27171. var tileCount = jpxImage.tiles.length;
  27172. if (tileCount === 1) {
  27173. this.buffer = jpxImage.tiles[0].items;
  27174. } else {
  27175. var data = new Uint8Array(width * height * componentsCount);
  27176. for (var k = 0; k < tileCount; k++) {
  27177. var tileComponents = jpxImage.tiles[k];
  27178. var tileWidth = tileComponents.width;
  27179. var tileHeight = tileComponents.height;
  27180. var tileLeft = tileComponents.left;
  27181. var tileTop = tileComponents.top;
  27182. var src = tileComponents.items;
  27183. var srcPosition = 0;
  27184. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  27185. var imgRowSize = width * componentsCount;
  27186. var tileRowSize = tileWidth * componentsCount;
  27187. for (var j = 0; j < tileHeight; j++) {
  27188. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  27189. data.set(rowBytes, dataPosition);
  27190. srcPosition += tileRowSize;
  27191. dataPosition += imgRowSize;
  27192. }
  27193. }
  27194. this.buffer = data;
  27195. }
  27196. this.bufferLength = this.buffer.length;
  27197. this.eof = true;
  27198. };
  27199. return JpxStream;
  27200. }();
  27201. /**
  27202. * For JBIG2's we use a library to decode these images and
  27203. * the stream behaves like all the other DecodeStreams.
  27204. */
  27205. var Jbig2Stream = function Jbig2StreamClosure() {
  27206. function Jbig2Stream(stream, maybeLength, dict, params) {
  27207. this.stream = stream;
  27208. this.maybeLength = maybeLength;
  27209. this.dict = dict;
  27210. this.params = params;
  27211. DecodeStream.call(this, maybeLength);
  27212. }
  27213. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  27214. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  27215. get: function Jbig2Stream_bytes() {
  27216. // If this.maybeLength is null, we'll get the entire stream.
  27217. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  27218. },
  27219. configurable: true
  27220. });
  27221. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  27222. if (this.bufferLength) {
  27223. return;
  27224. }
  27225. var jbig2Image = new Jbig2Image();
  27226. var chunks = [];
  27227. if (isDict(this.params)) {
  27228. var globalsStream = this.params.get('JBIG2Globals');
  27229. if (isStream(globalsStream)) {
  27230. var globals = globalsStream.getBytes();
  27231. chunks.push({
  27232. data: globals,
  27233. start: 0,
  27234. end: globals.length
  27235. });
  27236. }
  27237. }
  27238. chunks.push({
  27239. data: this.bytes,
  27240. start: 0,
  27241. end: this.bytes.length
  27242. });
  27243. var data = jbig2Image.parseChunks(chunks);
  27244. var dataLength = data.length;
  27245. // JBIG2 had black as 1 and white as 0, inverting the colors
  27246. for (var i = 0; i < dataLength; i++) {
  27247. data[i] ^= 0xFF;
  27248. }
  27249. this.buffer = data;
  27250. this.bufferLength = dataLength;
  27251. this.eof = true;
  27252. };
  27253. return Jbig2Stream;
  27254. }();
  27255. var DecryptStream = function DecryptStreamClosure() {
  27256. function DecryptStream(str, maybeLength, decrypt) {
  27257. this.str = str;
  27258. this.dict = str.dict;
  27259. this.decrypt = decrypt;
  27260. this.nextChunk = null;
  27261. this.initialized = false;
  27262. DecodeStream.call(this, maybeLength);
  27263. }
  27264. var chunkSize = 512;
  27265. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  27266. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  27267. var chunk;
  27268. if (this.initialized) {
  27269. chunk = this.nextChunk;
  27270. } else {
  27271. chunk = this.str.getBytes(chunkSize);
  27272. this.initialized = true;
  27273. }
  27274. if (!chunk || chunk.length === 0) {
  27275. this.eof = true;
  27276. return;
  27277. }
  27278. this.nextChunk = this.str.getBytes(chunkSize);
  27279. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  27280. var decrypt = this.decrypt;
  27281. chunk = decrypt(chunk, !hasMoreData);
  27282. var bufferLength = this.bufferLength;
  27283. var i, n = chunk.length;
  27284. var buffer = this.ensureBuffer(bufferLength + n);
  27285. for (i = 0; i < n; i++) {
  27286. buffer[bufferLength++] = chunk[i];
  27287. }
  27288. this.bufferLength = bufferLength;
  27289. };
  27290. return DecryptStream;
  27291. }();
  27292. var Ascii85Stream = function Ascii85StreamClosure() {
  27293. function Ascii85Stream(str, maybeLength) {
  27294. this.str = str;
  27295. this.dict = str.dict;
  27296. this.input = new Uint8Array(5);
  27297. // Most streams increase in size when decoded, but Ascii85 streams
  27298. // typically shrink by ~20%.
  27299. if (maybeLength) {
  27300. maybeLength = 0.8 * maybeLength;
  27301. }
  27302. DecodeStream.call(this, maybeLength);
  27303. }
  27304. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  27305. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  27306. var TILDA_CHAR = 0x7E;
  27307. // '~'
  27308. var Z_LOWER_CHAR = 0x7A;
  27309. // 'z'
  27310. var EOF = -1;
  27311. var str = this.str;
  27312. var c = str.getByte();
  27313. while (isSpace(c)) {
  27314. c = str.getByte();
  27315. }
  27316. if (c === EOF || c === TILDA_CHAR) {
  27317. this.eof = true;
  27318. return;
  27319. }
  27320. var bufferLength = this.bufferLength, buffer;
  27321. var i;
  27322. // special code for z
  27323. if (c === Z_LOWER_CHAR) {
  27324. buffer = this.ensureBuffer(bufferLength + 4);
  27325. for (i = 0; i < 4; ++i) {
  27326. buffer[bufferLength + i] = 0;
  27327. }
  27328. this.bufferLength += 4;
  27329. } else {
  27330. var input = this.input;
  27331. input[0] = c;
  27332. for (i = 1; i < 5; ++i) {
  27333. c = str.getByte();
  27334. while (isSpace(c)) {
  27335. c = str.getByte();
  27336. }
  27337. input[i] = c;
  27338. if (c === EOF || c === TILDA_CHAR) {
  27339. break;
  27340. }
  27341. }
  27342. buffer = this.ensureBuffer(bufferLength + i - 1);
  27343. this.bufferLength += i - 1;
  27344. // partial ending;
  27345. if (i < 5) {
  27346. for (; i < 5; ++i) {
  27347. input[i] = 0x21 + 84;
  27348. }
  27349. this.eof = true;
  27350. }
  27351. var t = 0;
  27352. for (i = 0; i < 5; ++i) {
  27353. t = t * 85 + (input[i] - 0x21);
  27354. }
  27355. for (i = 3; i >= 0; --i) {
  27356. buffer[bufferLength + i] = t & 0xFF;
  27357. t >>= 8;
  27358. }
  27359. }
  27360. };
  27361. return Ascii85Stream;
  27362. }();
  27363. var AsciiHexStream = function AsciiHexStreamClosure() {
  27364. function AsciiHexStream(str, maybeLength) {
  27365. this.str = str;
  27366. this.dict = str.dict;
  27367. this.firstDigit = -1;
  27368. // Most streams increase in size when decoded, but AsciiHex streams shrink
  27369. // by 50%.
  27370. if (maybeLength) {
  27371. maybeLength = 0.5 * maybeLength;
  27372. }
  27373. DecodeStream.call(this, maybeLength);
  27374. }
  27375. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  27376. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  27377. var UPSTREAM_BLOCK_SIZE = 8000;
  27378. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  27379. if (!bytes.length) {
  27380. this.eof = true;
  27381. return;
  27382. }
  27383. var maxDecodeLength = bytes.length + 1 >> 1;
  27384. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  27385. var bufferLength = this.bufferLength;
  27386. var firstDigit = this.firstDigit;
  27387. for (var i = 0, ii = bytes.length; i < ii; i++) {
  27388. var ch = bytes[i], digit;
  27389. if (ch >= 0x30 && ch <= 0x39) {
  27390. // '0'-'9'
  27391. digit = ch & 0x0F;
  27392. } else if (ch >= 0x41 && ch <= 0x46 || ch >= 0x61 && ch <= 0x66) {
  27393. // 'A'-'Z', 'a'-'z'
  27394. digit = (ch & 0x0F) + 9;
  27395. } else if (ch === 0x3E) {
  27396. // '>'
  27397. this.eof = true;
  27398. break;
  27399. } else {
  27400. // probably whitespace
  27401. continue;
  27402. }
  27403. // ignoring
  27404. if (firstDigit < 0) {
  27405. firstDigit = digit;
  27406. } else {
  27407. buffer[bufferLength++] = firstDigit << 4 | digit;
  27408. firstDigit = -1;
  27409. }
  27410. }
  27411. if (firstDigit >= 0 && this.eof) {
  27412. // incomplete byte
  27413. buffer[bufferLength++] = firstDigit << 4;
  27414. firstDigit = -1;
  27415. }
  27416. this.firstDigit = firstDigit;
  27417. this.bufferLength = bufferLength;
  27418. };
  27419. return AsciiHexStream;
  27420. }();
  27421. var RunLengthStream = function RunLengthStreamClosure() {
  27422. function RunLengthStream(str, maybeLength) {
  27423. this.str = str;
  27424. this.dict = str.dict;
  27425. DecodeStream.call(this, maybeLength);
  27426. }
  27427. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  27428. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  27429. // The repeatHeader has following format. The first byte defines type of run
  27430. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  27431. // (in addition to the second byte from the header), n = 129 through 255 -
  27432. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  27433. var repeatHeader = this.str.getBytes(2);
  27434. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  27435. this.eof = true;
  27436. return;
  27437. }
  27438. var buffer;
  27439. var bufferLength = this.bufferLength;
  27440. var n = repeatHeader[0];
  27441. if (n < 128) {
  27442. // copy n bytes
  27443. buffer = this.ensureBuffer(bufferLength + n + 1);
  27444. buffer[bufferLength++] = repeatHeader[1];
  27445. if (n > 0) {
  27446. var source = this.str.getBytes(n);
  27447. buffer.set(source, bufferLength);
  27448. bufferLength += n;
  27449. }
  27450. } else {
  27451. n = 257 - n;
  27452. var b = repeatHeader[1];
  27453. buffer = this.ensureBuffer(bufferLength + n + 1);
  27454. for (var i = 0; i < n; i++) {
  27455. buffer[bufferLength++] = b;
  27456. }
  27457. }
  27458. this.bufferLength = bufferLength;
  27459. };
  27460. return RunLengthStream;
  27461. }();
  27462. var CCITTFaxStream = function CCITTFaxStreamClosure() {
  27463. var ccittEOL = -2;
  27464. var ccittEOF = -1;
  27465. var twoDimPass = 0;
  27466. var twoDimHoriz = 1;
  27467. var twoDimVert0 = 2;
  27468. var twoDimVertR1 = 3;
  27469. var twoDimVertL1 = 4;
  27470. var twoDimVertR2 = 5;
  27471. var twoDimVertL2 = 6;
  27472. var twoDimVertR3 = 7;
  27473. var twoDimVertL3 = 8;
  27474. var twoDimTable = [
  27475. [
  27476. -1,
  27477. -1
  27478. ],
  27479. [
  27480. -1,
  27481. -1
  27482. ],
  27483. // 000000x
  27484. [
  27485. 7,
  27486. twoDimVertL3
  27487. ],
  27488. // 0000010
  27489. [
  27490. 7,
  27491. twoDimVertR3
  27492. ],
  27493. // 0000011
  27494. [
  27495. 6,
  27496. twoDimVertL2
  27497. ],
  27498. [
  27499. 6,
  27500. twoDimVertL2
  27501. ],
  27502. // 000010x
  27503. [
  27504. 6,
  27505. twoDimVertR2
  27506. ],
  27507. [
  27508. 6,
  27509. twoDimVertR2
  27510. ],
  27511. // 000011x
  27512. [
  27513. 4,
  27514. twoDimPass
  27515. ],
  27516. [
  27517. 4,
  27518. twoDimPass
  27519. ],
  27520. // 0001xxx
  27521. [
  27522. 4,
  27523. twoDimPass
  27524. ],
  27525. [
  27526. 4,
  27527. twoDimPass
  27528. ],
  27529. [
  27530. 4,
  27531. twoDimPass
  27532. ],
  27533. [
  27534. 4,
  27535. twoDimPass
  27536. ],
  27537. [
  27538. 4,
  27539. twoDimPass
  27540. ],
  27541. [
  27542. 4,
  27543. twoDimPass
  27544. ],
  27545. [
  27546. 3,
  27547. twoDimHoriz
  27548. ],
  27549. [
  27550. 3,
  27551. twoDimHoriz
  27552. ],
  27553. // 001xxxx
  27554. [
  27555. 3,
  27556. twoDimHoriz
  27557. ],
  27558. [
  27559. 3,
  27560. twoDimHoriz
  27561. ],
  27562. [
  27563. 3,
  27564. twoDimHoriz
  27565. ],
  27566. [
  27567. 3,
  27568. twoDimHoriz
  27569. ],
  27570. [
  27571. 3,
  27572. twoDimHoriz
  27573. ],
  27574. [
  27575. 3,
  27576. twoDimHoriz
  27577. ],
  27578. [
  27579. 3,
  27580. twoDimHoriz
  27581. ],
  27582. [
  27583. 3,
  27584. twoDimHoriz
  27585. ],
  27586. [
  27587. 3,
  27588. twoDimHoriz
  27589. ],
  27590. [
  27591. 3,
  27592. twoDimHoriz
  27593. ],
  27594. [
  27595. 3,
  27596. twoDimHoriz
  27597. ],
  27598. [
  27599. 3,
  27600. twoDimHoriz
  27601. ],
  27602. [
  27603. 3,
  27604. twoDimHoriz
  27605. ],
  27606. [
  27607. 3,
  27608. twoDimHoriz
  27609. ],
  27610. [
  27611. 3,
  27612. twoDimVertL1
  27613. ],
  27614. [
  27615. 3,
  27616. twoDimVertL1
  27617. ],
  27618. // 010xxxx
  27619. [
  27620. 3,
  27621. twoDimVertL1
  27622. ],
  27623. [
  27624. 3,
  27625. twoDimVertL1
  27626. ],
  27627. [
  27628. 3,
  27629. twoDimVertL1
  27630. ],
  27631. [
  27632. 3,
  27633. twoDimVertL1
  27634. ],
  27635. [
  27636. 3,
  27637. twoDimVertL1
  27638. ],
  27639. [
  27640. 3,
  27641. twoDimVertL1
  27642. ],
  27643. [
  27644. 3,
  27645. twoDimVertL1
  27646. ],
  27647. [
  27648. 3,
  27649. twoDimVertL1
  27650. ],
  27651. [
  27652. 3,
  27653. twoDimVertL1
  27654. ],
  27655. [
  27656. 3,
  27657. twoDimVertL1
  27658. ],
  27659. [
  27660. 3,
  27661. twoDimVertL1
  27662. ],
  27663. [
  27664. 3,
  27665. twoDimVertL1
  27666. ],
  27667. [
  27668. 3,
  27669. twoDimVertL1
  27670. ],
  27671. [
  27672. 3,
  27673. twoDimVertL1
  27674. ],
  27675. [
  27676. 3,
  27677. twoDimVertR1
  27678. ],
  27679. [
  27680. 3,
  27681. twoDimVertR1
  27682. ],
  27683. // 011xxxx
  27684. [
  27685. 3,
  27686. twoDimVertR1
  27687. ],
  27688. [
  27689. 3,
  27690. twoDimVertR1
  27691. ],
  27692. [
  27693. 3,
  27694. twoDimVertR1
  27695. ],
  27696. [
  27697. 3,
  27698. twoDimVertR1
  27699. ],
  27700. [
  27701. 3,
  27702. twoDimVertR1
  27703. ],
  27704. [
  27705. 3,
  27706. twoDimVertR1
  27707. ],
  27708. [
  27709. 3,
  27710. twoDimVertR1
  27711. ],
  27712. [
  27713. 3,
  27714. twoDimVertR1
  27715. ],
  27716. [
  27717. 3,
  27718. twoDimVertR1
  27719. ],
  27720. [
  27721. 3,
  27722. twoDimVertR1
  27723. ],
  27724. [
  27725. 3,
  27726. twoDimVertR1
  27727. ],
  27728. [
  27729. 3,
  27730. twoDimVertR1
  27731. ],
  27732. [
  27733. 3,
  27734. twoDimVertR1
  27735. ],
  27736. [
  27737. 3,
  27738. twoDimVertR1
  27739. ],
  27740. [
  27741. 1,
  27742. twoDimVert0
  27743. ],
  27744. [
  27745. 1,
  27746. twoDimVert0
  27747. ],
  27748. // 1xxxxxx
  27749. [
  27750. 1,
  27751. twoDimVert0
  27752. ],
  27753. [
  27754. 1,
  27755. twoDimVert0
  27756. ],
  27757. [
  27758. 1,
  27759. twoDimVert0
  27760. ],
  27761. [
  27762. 1,
  27763. twoDimVert0
  27764. ],
  27765. [
  27766. 1,
  27767. twoDimVert0
  27768. ],
  27769. [
  27770. 1,
  27771. twoDimVert0
  27772. ],
  27773. [
  27774. 1,
  27775. twoDimVert0
  27776. ],
  27777. [
  27778. 1,
  27779. twoDimVert0
  27780. ],
  27781. [
  27782. 1,
  27783. twoDimVert0
  27784. ],
  27785. [
  27786. 1,
  27787. twoDimVert0
  27788. ],
  27789. [
  27790. 1,
  27791. twoDimVert0
  27792. ],
  27793. [
  27794. 1,
  27795. twoDimVert0
  27796. ],
  27797. [
  27798. 1,
  27799. twoDimVert0
  27800. ],
  27801. [
  27802. 1,
  27803. twoDimVert0
  27804. ],
  27805. [
  27806. 1,
  27807. twoDimVert0
  27808. ],
  27809. [
  27810. 1,
  27811. twoDimVert0
  27812. ],
  27813. [
  27814. 1,
  27815. twoDimVert0
  27816. ],
  27817. [
  27818. 1,
  27819. twoDimVert0
  27820. ],
  27821. [
  27822. 1,
  27823. twoDimVert0
  27824. ],
  27825. [
  27826. 1,
  27827. twoDimVert0
  27828. ],
  27829. [
  27830. 1,
  27831. twoDimVert0
  27832. ],
  27833. [
  27834. 1,
  27835. twoDimVert0
  27836. ],
  27837. [
  27838. 1,
  27839. twoDimVert0
  27840. ],
  27841. [
  27842. 1,
  27843. twoDimVert0
  27844. ],
  27845. [
  27846. 1,
  27847. twoDimVert0
  27848. ],
  27849. [
  27850. 1,
  27851. twoDimVert0
  27852. ],
  27853. [
  27854. 1,
  27855. twoDimVert0
  27856. ],
  27857. [
  27858. 1,
  27859. twoDimVert0
  27860. ],
  27861. [
  27862. 1,
  27863. twoDimVert0
  27864. ],
  27865. [
  27866. 1,
  27867. twoDimVert0
  27868. ],
  27869. [
  27870. 1,
  27871. twoDimVert0
  27872. ],
  27873. [
  27874. 1,
  27875. twoDimVert0
  27876. ],
  27877. [
  27878. 1,
  27879. twoDimVert0
  27880. ],
  27881. [
  27882. 1,
  27883. twoDimVert0
  27884. ],
  27885. [
  27886. 1,
  27887. twoDimVert0
  27888. ],
  27889. [
  27890. 1,
  27891. twoDimVert0
  27892. ],
  27893. [
  27894. 1,
  27895. twoDimVert0
  27896. ],
  27897. [
  27898. 1,
  27899. twoDimVert0
  27900. ],
  27901. [
  27902. 1,
  27903. twoDimVert0
  27904. ],
  27905. [
  27906. 1,
  27907. twoDimVert0
  27908. ],
  27909. [
  27910. 1,
  27911. twoDimVert0
  27912. ],
  27913. [
  27914. 1,
  27915. twoDimVert0
  27916. ],
  27917. [
  27918. 1,
  27919. twoDimVert0
  27920. ],
  27921. [
  27922. 1,
  27923. twoDimVert0
  27924. ],
  27925. [
  27926. 1,
  27927. twoDimVert0
  27928. ],
  27929. [
  27930. 1,
  27931. twoDimVert0
  27932. ],
  27933. [
  27934. 1,
  27935. twoDimVert0
  27936. ],
  27937. [
  27938. 1,
  27939. twoDimVert0
  27940. ],
  27941. [
  27942. 1,
  27943. twoDimVert0
  27944. ],
  27945. [
  27946. 1,
  27947. twoDimVert0
  27948. ],
  27949. [
  27950. 1,
  27951. twoDimVert0
  27952. ],
  27953. [
  27954. 1,
  27955. twoDimVert0
  27956. ],
  27957. [
  27958. 1,
  27959. twoDimVert0
  27960. ],
  27961. [
  27962. 1,
  27963. twoDimVert0
  27964. ],
  27965. [
  27966. 1,
  27967. twoDimVert0
  27968. ],
  27969. [
  27970. 1,
  27971. twoDimVert0
  27972. ],
  27973. [
  27974. 1,
  27975. twoDimVert0
  27976. ],
  27977. [
  27978. 1,
  27979. twoDimVert0
  27980. ],
  27981. [
  27982. 1,
  27983. twoDimVert0
  27984. ],
  27985. [
  27986. 1,
  27987. twoDimVert0
  27988. ],
  27989. [
  27990. 1,
  27991. twoDimVert0
  27992. ],
  27993. [
  27994. 1,
  27995. twoDimVert0
  27996. ]
  27997. ];
  27998. var whiteTable1 = [
  27999. [
  28000. -1,
  28001. -1
  28002. ],
  28003. // 00000
  28004. [
  28005. 12,
  28006. ccittEOL
  28007. ],
  28008. // 00001
  28009. [
  28010. -1,
  28011. -1
  28012. ],
  28013. [
  28014. -1,
  28015. -1
  28016. ],
  28017. // 0001x
  28018. [
  28019. -1,
  28020. -1
  28021. ],
  28022. [
  28023. -1,
  28024. -1
  28025. ],
  28026. [
  28027. -1,
  28028. -1
  28029. ],
  28030. [
  28031. -1,
  28032. -1
  28033. ],
  28034. // 001xx
  28035. [
  28036. -1,
  28037. -1
  28038. ],
  28039. [
  28040. -1,
  28041. -1
  28042. ],
  28043. [
  28044. -1,
  28045. -1
  28046. ],
  28047. [
  28048. -1,
  28049. -1
  28050. ],
  28051. // 010xx
  28052. [
  28053. -1,
  28054. -1
  28055. ],
  28056. [
  28057. -1,
  28058. -1
  28059. ],
  28060. [
  28061. -1,
  28062. -1
  28063. ],
  28064. [
  28065. -1,
  28066. -1
  28067. ],
  28068. // 011xx
  28069. [
  28070. 11,
  28071. 1792
  28072. ],
  28073. [
  28074. 11,
  28075. 1792
  28076. ],
  28077. // 1000x
  28078. [
  28079. 12,
  28080. 1984
  28081. ],
  28082. // 10010
  28083. [
  28084. 12,
  28085. 2048
  28086. ],
  28087. // 10011
  28088. [
  28089. 12,
  28090. 2112
  28091. ],
  28092. // 10100
  28093. [
  28094. 12,
  28095. 2176
  28096. ],
  28097. // 10101
  28098. [
  28099. 12,
  28100. 2240
  28101. ],
  28102. // 10110
  28103. [
  28104. 12,
  28105. 2304
  28106. ],
  28107. // 10111
  28108. [
  28109. 11,
  28110. 1856
  28111. ],
  28112. [
  28113. 11,
  28114. 1856
  28115. ],
  28116. // 1100x
  28117. [
  28118. 11,
  28119. 1920
  28120. ],
  28121. [
  28122. 11,
  28123. 1920
  28124. ],
  28125. // 1101x
  28126. [
  28127. 12,
  28128. 2368
  28129. ],
  28130. // 11100
  28131. [
  28132. 12,
  28133. 2432
  28134. ],
  28135. // 11101
  28136. [
  28137. 12,
  28138. 2496
  28139. ],
  28140. // 11110
  28141. [
  28142. 12,
  28143. 2560
  28144. ]
  28145. ];
  28146. // 11111
  28147. var whiteTable2 = [
  28148. [
  28149. -1,
  28150. -1
  28151. ],
  28152. [
  28153. -1,
  28154. -1
  28155. ],
  28156. [
  28157. -1,
  28158. -1
  28159. ],
  28160. [
  28161. -1,
  28162. -1
  28163. ],
  28164. // 0000000xx
  28165. [
  28166. 8,
  28167. 29
  28168. ],
  28169. [
  28170. 8,
  28171. 29
  28172. ],
  28173. // 00000010x
  28174. [
  28175. 8,
  28176. 30
  28177. ],
  28178. [
  28179. 8,
  28180. 30
  28181. ],
  28182. // 00000011x
  28183. [
  28184. 8,
  28185. 45
  28186. ],
  28187. [
  28188. 8,
  28189. 45
  28190. ],
  28191. // 00000100x
  28192. [
  28193. 8,
  28194. 46
  28195. ],
  28196. [
  28197. 8,
  28198. 46
  28199. ],
  28200. // 00000101x
  28201. [
  28202. 7,
  28203. 22
  28204. ],
  28205. [
  28206. 7,
  28207. 22
  28208. ],
  28209. [
  28210. 7,
  28211. 22
  28212. ],
  28213. [
  28214. 7,
  28215. 22
  28216. ],
  28217. // 0000011xx
  28218. [
  28219. 7,
  28220. 23
  28221. ],
  28222. [
  28223. 7,
  28224. 23
  28225. ],
  28226. [
  28227. 7,
  28228. 23
  28229. ],
  28230. [
  28231. 7,
  28232. 23
  28233. ],
  28234. // 0000100xx
  28235. [
  28236. 8,
  28237. 47
  28238. ],
  28239. [
  28240. 8,
  28241. 47
  28242. ],
  28243. // 00001010x
  28244. [
  28245. 8,
  28246. 48
  28247. ],
  28248. [
  28249. 8,
  28250. 48
  28251. ],
  28252. // 00001011x
  28253. [
  28254. 6,
  28255. 13
  28256. ],
  28257. [
  28258. 6,
  28259. 13
  28260. ],
  28261. [
  28262. 6,
  28263. 13
  28264. ],
  28265. [
  28266. 6,
  28267. 13
  28268. ],
  28269. // 000011xxx
  28270. [
  28271. 6,
  28272. 13
  28273. ],
  28274. [
  28275. 6,
  28276. 13
  28277. ],
  28278. [
  28279. 6,
  28280. 13
  28281. ],
  28282. [
  28283. 6,
  28284. 13
  28285. ],
  28286. [
  28287. 7,
  28288. 20
  28289. ],
  28290. [
  28291. 7,
  28292. 20
  28293. ],
  28294. [
  28295. 7,
  28296. 20
  28297. ],
  28298. [
  28299. 7,
  28300. 20
  28301. ],
  28302. // 0001000xx
  28303. [
  28304. 8,
  28305. 33
  28306. ],
  28307. [
  28308. 8,
  28309. 33
  28310. ],
  28311. // 00010010x
  28312. [
  28313. 8,
  28314. 34
  28315. ],
  28316. [
  28317. 8,
  28318. 34
  28319. ],
  28320. // 00010011x
  28321. [
  28322. 8,
  28323. 35
  28324. ],
  28325. [
  28326. 8,
  28327. 35
  28328. ],
  28329. // 00010100x
  28330. [
  28331. 8,
  28332. 36
  28333. ],
  28334. [
  28335. 8,
  28336. 36
  28337. ],
  28338. // 00010101x
  28339. [
  28340. 8,
  28341. 37
  28342. ],
  28343. [
  28344. 8,
  28345. 37
  28346. ],
  28347. // 00010110x
  28348. [
  28349. 8,
  28350. 38
  28351. ],
  28352. [
  28353. 8,
  28354. 38
  28355. ],
  28356. // 00010111x
  28357. [
  28358. 7,
  28359. 19
  28360. ],
  28361. [
  28362. 7,
  28363. 19
  28364. ],
  28365. [
  28366. 7,
  28367. 19
  28368. ],
  28369. [
  28370. 7,
  28371. 19
  28372. ],
  28373. // 0001100xx
  28374. [
  28375. 8,
  28376. 31
  28377. ],
  28378. [
  28379. 8,
  28380. 31
  28381. ],
  28382. // 00011010x
  28383. [
  28384. 8,
  28385. 32
  28386. ],
  28387. [
  28388. 8,
  28389. 32
  28390. ],
  28391. // 00011011x
  28392. [
  28393. 6,
  28394. 1
  28395. ],
  28396. [
  28397. 6,
  28398. 1
  28399. ],
  28400. [
  28401. 6,
  28402. 1
  28403. ],
  28404. [
  28405. 6,
  28406. 1
  28407. ],
  28408. // 000111xxx
  28409. [
  28410. 6,
  28411. 1
  28412. ],
  28413. [
  28414. 6,
  28415. 1
  28416. ],
  28417. [
  28418. 6,
  28419. 1
  28420. ],
  28421. [
  28422. 6,
  28423. 1
  28424. ],
  28425. [
  28426. 6,
  28427. 12
  28428. ],
  28429. [
  28430. 6,
  28431. 12
  28432. ],
  28433. [
  28434. 6,
  28435. 12
  28436. ],
  28437. [
  28438. 6,
  28439. 12
  28440. ],
  28441. // 001000xxx
  28442. [
  28443. 6,
  28444. 12
  28445. ],
  28446. [
  28447. 6,
  28448. 12
  28449. ],
  28450. [
  28451. 6,
  28452. 12
  28453. ],
  28454. [
  28455. 6,
  28456. 12
  28457. ],
  28458. [
  28459. 8,
  28460. 53
  28461. ],
  28462. [
  28463. 8,
  28464. 53
  28465. ],
  28466. // 00100100x
  28467. [
  28468. 8,
  28469. 54
  28470. ],
  28471. [
  28472. 8,
  28473. 54
  28474. ],
  28475. // 00100101x
  28476. [
  28477. 7,
  28478. 26
  28479. ],
  28480. [
  28481. 7,
  28482. 26
  28483. ],
  28484. [
  28485. 7,
  28486. 26
  28487. ],
  28488. [
  28489. 7,
  28490. 26
  28491. ],
  28492. // 0010011xx
  28493. [
  28494. 8,
  28495. 39
  28496. ],
  28497. [
  28498. 8,
  28499. 39
  28500. ],
  28501. // 00101000x
  28502. [
  28503. 8,
  28504. 40
  28505. ],
  28506. [
  28507. 8,
  28508. 40
  28509. ],
  28510. // 00101001x
  28511. [
  28512. 8,
  28513. 41
  28514. ],
  28515. [
  28516. 8,
  28517. 41
  28518. ],
  28519. // 00101010x
  28520. [
  28521. 8,
  28522. 42
  28523. ],
  28524. [
  28525. 8,
  28526. 42
  28527. ],
  28528. // 00101011x
  28529. [
  28530. 8,
  28531. 43
  28532. ],
  28533. [
  28534. 8,
  28535. 43
  28536. ],
  28537. // 00101100x
  28538. [
  28539. 8,
  28540. 44
  28541. ],
  28542. [
  28543. 8,
  28544. 44
  28545. ],
  28546. // 00101101x
  28547. [
  28548. 7,
  28549. 21
  28550. ],
  28551. [
  28552. 7,
  28553. 21
  28554. ],
  28555. [
  28556. 7,
  28557. 21
  28558. ],
  28559. [
  28560. 7,
  28561. 21
  28562. ],
  28563. // 0010111xx
  28564. [
  28565. 7,
  28566. 28
  28567. ],
  28568. [
  28569. 7,
  28570. 28
  28571. ],
  28572. [
  28573. 7,
  28574. 28
  28575. ],
  28576. [
  28577. 7,
  28578. 28
  28579. ],
  28580. // 0011000xx
  28581. [
  28582. 8,
  28583. 61
  28584. ],
  28585. [
  28586. 8,
  28587. 61
  28588. ],
  28589. // 00110010x
  28590. [
  28591. 8,
  28592. 62
  28593. ],
  28594. [
  28595. 8,
  28596. 62
  28597. ],
  28598. // 00110011x
  28599. [
  28600. 8,
  28601. 63
  28602. ],
  28603. [
  28604. 8,
  28605. 63
  28606. ],
  28607. // 00110100x
  28608. [
  28609. 8,
  28610. 0
  28611. ],
  28612. [
  28613. 8,
  28614. 0
  28615. ],
  28616. // 00110101x
  28617. [
  28618. 8,
  28619. 320
  28620. ],
  28621. [
  28622. 8,
  28623. 320
  28624. ],
  28625. // 00110110x
  28626. [
  28627. 8,
  28628. 384
  28629. ],
  28630. [
  28631. 8,
  28632. 384
  28633. ],
  28634. // 00110111x
  28635. [
  28636. 5,
  28637. 10
  28638. ],
  28639. [
  28640. 5,
  28641. 10
  28642. ],
  28643. [
  28644. 5,
  28645. 10
  28646. ],
  28647. [
  28648. 5,
  28649. 10
  28650. ],
  28651. // 00111xxxx
  28652. [
  28653. 5,
  28654. 10
  28655. ],
  28656. [
  28657. 5,
  28658. 10
  28659. ],
  28660. [
  28661. 5,
  28662. 10
  28663. ],
  28664. [
  28665. 5,
  28666. 10
  28667. ],
  28668. [
  28669. 5,
  28670. 10
  28671. ],
  28672. [
  28673. 5,
  28674. 10
  28675. ],
  28676. [
  28677. 5,
  28678. 10
  28679. ],
  28680. [
  28681. 5,
  28682. 10
  28683. ],
  28684. [
  28685. 5,
  28686. 10
  28687. ],
  28688. [
  28689. 5,
  28690. 10
  28691. ],
  28692. [
  28693. 5,
  28694. 10
  28695. ],
  28696. [
  28697. 5,
  28698. 10
  28699. ],
  28700. [
  28701. 5,
  28702. 11
  28703. ],
  28704. [
  28705. 5,
  28706. 11
  28707. ],
  28708. [
  28709. 5,
  28710. 11
  28711. ],
  28712. [
  28713. 5,
  28714. 11
  28715. ],
  28716. // 01000xxxx
  28717. [
  28718. 5,
  28719. 11
  28720. ],
  28721. [
  28722. 5,
  28723. 11
  28724. ],
  28725. [
  28726. 5,
  28727. 11
  28728. ],
  28729. [
  28730. 5,
  28731. 11
  28732. ],
  28733. [
  28734. 5,
  28735. 11
  28736. ],
  28737. [
  28738. 5,
  28739. 11
  28740. ],
  28741. [
  28742. 5,
  28743. 11
  28744. ],
  28745. [
  28746. 5,
  28747. 11
  28748. ],
  28749. [
  28750. 5,
  28751. 11
  28752. ],
  28753. [
  28754. 5,
  28755. 11
  28756. ],
  28757. [
  28758. 5,
  28759. 11
  28760. ],
  28761. [
  28762. 5,
  28763. 11
  28764. ],
  28765. [
  28766. 7,
  28767. 27
  28768. ],
  28769. [
  28770. 7,
  28771. 27
  28772. ],
  28773. [
  28774. 7,
  28775. 27
  28776. ],
  28777. [
  28778. 7,
  28779. 27
  28780. ],
  28781. // 0100100xx
  28782. [
  28783. 8,
  28784. 59
  28785. ],
  28786. [
  28787. 8,
  28788. 59
  28789. ],
  28790. // 01001010x
  28791. [
  28792. 8,
  28793. 60
  28794. ],
  28795. [
  28796. 8,
  28797. 60
  28798. ],
  28799. // 01001011x
  28800. [
  28801. 9,
  28802. 1472
  28803. ],
  28804. // 010011000
  28805. [
  28806. 9,
  28807. 1536
  28808. ],
  28809. // 010011001
  28810. [
  28811. 9,
  28812. 1600
  28813. ],
  28814. // 010011010
  28815. [
  28816. 9,
  28817. 1728
  28818. ],
  28819. // 010011011
  28820. [
  28821. 7,
  28822. 18
  28823. ],
  28824. [
  28825. 7,
  28826. 18
  28827. ],
  28828. [
  28829. 7,
  28830. 18
  28831. ],
  28832. [
  28833. 7,
  28834. 18
  28835. ],
  28836. // 0100111xx
  28837. [
  28838. 7,
  28839. 24
  28840. ],
  28841. [
  28842. 7,
  28843. 24
  28844. ],
  28845. [
  28846. 7,
  28847. 24
  28848. ],
  28849. [
  28850. 7,
  28851. 24
  28852. ],
  28853. // 0101000xx
  28854. [
  28855. 8,
  28856. 49
  28857. ],
  28858. [
  28859. 8,
  28860. 49
  28861. ],
  28862. // 01010010x
  28863. [
  28864. 8,
  28865. 50
  28866. ],
  28867. [
  28868. 8,
  28869. 50
  28870. ],
  28871. // 01010011x
  28872. [
  28873. 8,
  28874. 51
  28875. ],
  28876. [
  28877. 8,
  28878. 51
  28879. ],
  28880. // 01010100x
  28881. [
  28882. 8,
  28883. 52
  28884. ],
  28885. [
  28886. 8,
  28887. 52
  28888. ],
  28889. // 01010101x
  28890. [
  28891. 7,
  28892. 25
  28893. ],
  28894. [
  28895. 7,
  28896. 25
  28897. ],
  28898. [
  28899. 7,
  28900. 25
  28901. ],
  28902. [
  28903. 7,
  28904. 25
  28905. ],
  28906. // 0101011xx
  28907. [
  28908. 8,
  28909. 55
  28910. ],
  28911. [
  28912. 8,
  28913. 55
  28914. ],
  28915. // 01011000x
  28916. [
  28917. 8,
  28918. 56
  28919. ],
  28920. [
  28921. 8,
  28922. 56
  28923. ],
  28924. // 01011001x
  28925. [
  28926. 8,
  28927. 57
  28928. ],
  28929. [
  28930. 8,
  28931. 57
  28932. ],
  28933. // 01011010x
  28934. [
  28935. 8,
  28936. 58
  28937. ],
  28938. [
  28939. 8,
  28940. 58
  28941. ],
  28942. // 01011011x
  28943. [
  28944. 6,
  28945. 192
  28946. ],
  28947. [
  28948. 6,
  28949. 192
  28950. ],
  28951. [
  28952. 6,
  28953. 192
  28954. ],
  28955. [
  28956. 6,
  28957. 192
  28958. ],
  28959. // 010111xxx
  28960. [
  28961. 6,
  28962. 192
  28963. ],
  28964. [
  28965. 6,
  28966. 192
  28967. ],
  28968. [
  28969. 6,
  28970. 192
  28971. ],
  28972. [
  28973. 6,
  28974. 192
  28975. ],
  28976. [
  28977. 6,
  28978. 1664
  28979. ],
  28980. [
  28981. 6,
  28982. 1664
  28983. ],
  28984. [
  28985. 6,
  28986. 1664
  28987. ],
  28988. [
  28989. 6,
  28990. 1664
  28991. ],
  28992. // 011000xxx
  28993. [
  28994. 6,
  28995. 1664
  28996. ],
  28997. [
  28998. 6,
  28999. 1664
  29000. ],
  29001. [
  29002. 6,
  29003. 1664
  29004. ],
  29005. [
  29006. 6,
  29007. 1664
  29008. ],
  29009. [
  29010. 8,
  29011. 448
  29012. ],
  29013. [
  29014. 8,
  29015. 448
  29016. ],
  29017. // 01100100x
  29018. [
  29019. 8,
  29020. 512
  29021. ],
  29022. [
  29023. 8,
  29024. 512
  29025. ],
  29026. // 01100101x
  29027. [
  29028. 9,
  29029. 704
  29030. ],
  29031. // 011001100
  29032. [
  29033. 9,
  29034. 768
  29035. ],
  29036. // 011001101
  29037. [
  29038. 8,
  29039. 640
  29040. ],
  29041. [
  29042. 8,
  29043. 640
  29044. ],
  29045. // 01100111x
  29046. [
  29047. 8,
  29048. 576
  29049. ],
  29050. [
  29051. 8,
  29052. 576
  29053. ],
  29054. // 01101000x
  29055. [
  29056. 9,
  29057. 832
  29058. ],
  29059. // 011010010
  29060. [
  29061. 9,
  29062. 896
  29063. ],
  29064. // 011010011
  29065. [
  29066. 9,
  29067. 960
  29068. ],
  29069. // 011010100
  29070. [
  29071. 9,
  29072. 1024
  29073. ],
  29074. // 011010101
  29075. [
  29076. 9,
  29077. 1088
  29078. ],
  29079. // 011010110
  29080. [
  29081. 9,
  29082. 1152
  29083. ],
  29084. // 011010111
  29085. [
  29086. 9,
  29087. 1216
  29088. ],
  29089. // 011011000
  29090. [
  29091. 9,
  29092. 1280
  29093. ],
  29094. // 011011001
  29095. [
  29096. 9,
  29097. 1344
  29098. ],
  29099. // 011011010
  29100. [
  29101. 9,
  29102. 1408
  29103. ],
  29104. // 011011011
  29105. [
  29106. 7,
  29107. 256
  29108. ],
  29109. [
  29110. 7,
  29111. 256
  29112. ],
  29113. [
  29114. 7,
  29115. 256
  29116. ],
  29117. [
  29118. 7,
  29119. 256
  29120. ],
  29121. // 0110111xx
  29122. [
  29123. 4,
  29124. 2
  29125. ],
  29126. [
  29127. 4,
  29128. 2
  29129. ],
  29130. [
  29131. 4,
  29132. 2
  29133. ],
  29134. [
  29135. 4,
  29136. 2
  29137. ],
  29138. // 0111xxxxx
  29139. [
  29140. 4,
  29141. 2
  29142. ],
  29143. [
  29144. 4,
  29145. 2
  29146. ],
  29147. [
  29148. 4,
  29149. 2
  29150. ],
  29151. [
  29152. 4,
  29153. 2
  29154. ],
  29155. [
  29156. 4,
  29157. 2
  29158. ],
  29159. [
  29160. 4,
  29161. 2
  29162. ],
  29163. [
  29164. 4,
  29165. 2
  29166. ],
  29167. [
  29168. 4,
  29169. 2
  29170. ],
  29171. [
  29172. 4,
  29173. 2
  29174. ],
  29175. [
  29176. 4,
  29177. 2
  29178. ],
  29179. [
  29180. 4,
  29181. 2
  29182. ],
  29183. [
  29184. 4,
  29185. 2
  29186. ],
  29187. [
  29188. 4,
  29189. 2
  29190. ],
  29191. [
  29192. 4,
  29193. 2
  29194. ],
  29195. [
  29196. 4,
  29197. 2
  29198. ],
  29199. [
  29200. 4,
  29201. 2
  29202. ],
  29203. [
  29204. 4,
  29205. 2
  29206. ],
  29207. [
  29208. 4,
  29209. 2
  29210. ],
  29211. [
  29212. 4,
  29213. 2
  29214. ],
  29215. [
  29216. 4,
  29217. 2
  29218. ],
  29219. [
  29220. 4,
  29221. 2
  29222. ],
  29223. [
  29224. 4,
  29225. 2
  29226. ],
  29227. [
  29228. 4,
  29229. 2
  29230. ],
  29231. [
  29232. 4,
  29233. 2
  29234. ],
  29235. [
  29236. 4,
  29237. 2
  29238. ],
  29239. [
  29240. 4,
  29241. 2
  29242. ],
  29243. [
  29244. 4,
  29245. 2
  29246. ],
  29247. [
  29248. 4,
  29249. 2
  29250. ],
  29251. [
  29252. 4,
  29253. 3
  29254. ],
  29255. [
  29256. 4,
  29257. 3
  29258. ],
  29259. [
  29260. 4,
  29261. 3
  29262. ],
  29263. [
  29264. 4,
  29265. 3
  29266. ],
  29267. // 1000xxxxx
  29268. [
  29269. 4,
  29270. 3
  29271. ],
  29272. [
  29273. 4,
  29274. 3
  29275. ],
  29276. [
  29277. 4,
  29278. 3
  29279. ],
  29280. [
  29281. 4,
  29282. 3
  29283. ],
  29284. [
  29285. 4,
  29286. 3
  29287. ],
  29288. [
  29289. 4,
  29290. 3
  29291. ],
  29292. [
  29293. 4,
  29294. 3
  29295. ],
  29296. [
  29297. 4,
  29298. 3
  29299. ],
  29300. [
  29301. 4,
  29302. 3
  29303. ],
  29304. [
  29305. 4,
  29306. 3
  29307. ],
  29308. [
  29309. 4,
  29310. 3
  29311. ],
  29312. [
  29313. 4,
  29314. 3
  29315. ],
  29316. [
  29317. 4,
  29318. 3
  29319. ],
  29320. [
  29321. 4,
  29322. 3
  29323. ],
  29324. [
  29325. 4,
  29326. 3
  29327. ],
  29328. [
  29329. 4,
  29330. 3
  29331. ],
  29332. [
  29333. 4,
  29334. 3
  29335. ],
  29336. [
  29337. 4,
  29338. 3
  29339. ],
  29340. [
  29341. 4,
  29342. 3
  29343. ],
  29344. [
  29345. 4,
  29346. 3
  29347. ],
  29348. [
  29349. 4,
  29350. 3
  29351. ],
  29352. [
  29353. 4,
  29354. 3
  29355. ],
  29356. [
  29357. 4,
  29358. 3
  29359. ],
  29360. [
  29361. 4,
  29362. 3
  29363. ],
  29364. [
  29365. 4,
  29366. 3
  29367. ],
  29368. [
  29369. 4,
  29370. 3
  29371. ],
  29372. [
  29373. 4,
  29374. 3
  29375. ],
  29376. [
  29377. 4,
  29378. 3
  29379. ],
  29380. [
  29381. 5,
  29382. 128
  29383. ],
  29384. [
  29385. 5,
  29386. 128
  29387. ],
  29388. [
  29389. 5,
  29390. 128
  29391. ],
  29392. [
  29393. 5,
  29394. 128
  29395. ],
  29396. // 10010xxxx
  29397. [
  29398. 5,
  29399. 128
  29400. ],
  29401. [
  29402. 5,
  29403. 128
  29404. ],
  29405. [
  29406. 5,
  29407. 128
  29408. ],
  29409. [
  29410. 5,
  29411. 128
  29412. ],
  29413. [
  29414. 5,
  29415. 128
  29416. ],
  29417. [
  29418. 5,
  29419. 128
  29420. ],
  29421. [
  29422. 5,
  29423. 128
  29424. ],
  29425. [
  29426. 5,
  29427. 128
  29428. ],
  29429. [
  29430. 5,
  29431. 128
  29432. ],
  29433. [
  29434. 5,
  29435. 128
  29436. ],
  29437. [
  29438. 5,
  29439. 128
  29440. ],
  29441. [
  29442. 5,
  29443. 128
  29444. ],
  29445. [
  29446. 5,
  29447. 8
  29448. ],
  29449. [
  29450. 5,
  29451. 8
  29452. ],
  29453. [
  29454. 5,
  29455. 8
  29456. ],
  29457. [
  29458. 5,
  29459. 8
  29460. ],
  29461. // 10011xxxx
  29462. [
  29463. 5,
  29464. 8
  29465. ],
  29466. [
  29467. 5,
  29468. 8
  29469. ],
  29470. [
  29471. 5,
  29472. 8
  29473. ],
  29474. [
  29475. 5,
  29476. 8
  29477. ],
  29478. [
  29479. 5,
  29480. 8
  29481. ],
  29482. [
  29483. 5,
  29484. 8
  29485. ],
  29486. [
  29487. 5,
  29488. 8
  29489. ],
  29490. [
  29491. 5,
  29492. 8
  29493. ],
  29494. [
  29495. 5,
  29496. 8
  29497. ],
  29498. [
  29499. 5,
  29500. 8
  29501. ],
  29502. [
  29503. 5,
  29504. 8
  29505. ],
  29506. [
  29507. 5,
  29508. 8
  29509. ],
  29510. [
  29511. 5,
  29512. 9
  29513. ],
  29514. [
  29515. 5,
  29516. 9
  29517. ],
  29518. [
  29519. 5,
  29520. 9
  29521. ],
  29522. [
  29523. 5,
  29524. 9
  29525. ],
  29526. // 10100xxxx
  29527. [
  29528. 5,
  29529. 9
  29530. ],
  29531. [
  29532. 5,
  29533. 9
  29534. ],
  29535. [
  29536. 5,
  29537. 9
  29538. ],
  29539. [
  29540. 5,
  29541. 9
  29542. ],
  29543. [
  29544. 5,
  29545. 9
  29546. ],
  29547. [
  29548. 5,
  29549. 9
  29550. ],
  29551. [
  29552. 5,
  29553. 9
  29554. ],
  29555. [
  29556. 5,
  29557. 9
  29558. ],
  29559. [
  29560. 5,
  29561. 9
  29562. ],
  29563. [
  29564. 5,
  29565. 9
  29566. ],
  29567. [
  29568. 5,
  29569. 9
  29570. ],
  29571. [
  29572. 5,
  29573. 9
  29574. ],
  29575. [
  29576. 6,
  29577. 16
  29578. ],
  29579. [
  29580. 6,
  29581. 16
  29582. ],
  29583. [
  29584. 6,
  29585. 16
  29586. ],
  29587. [
  29588. 6,
  29589. 16
  29590. ],
  29591. // 101010xxx
  29592. [
  29593. 6,
  29594. 16
  29595. ],
  29596. [
  29597. 6,
  29598. 16
  29599. ],
  29600. [
  29601. 6,
  29602. 16
  29603. ],
  29604. [
  29605. 6,
  29606. 16
  29607. ],
  29608. [
  29609. 6,
  29610. 17
  29611. ],
  29612. [
  29613. 6,
  29614. 17
  29615. ],
  29616. [
  29617. 6,
  29618. 17
  29619. ],
  29620. [
  29621. 6,
  29622. 17
  29623. ],
  29624. // 101011xxx
  29625. [
  29626. 6,
  29627. 17
  29628. ],
  29629. [
  29630. 6,
  29631. 17
  29632. ],
  29633. [
  29634. 6,
  29635. 17
  29636. ],
  29637. [
  29638. 6,
  29639. 17
  29640. ],
  29641. [
  29642. 4,
  29643. 4
  29644. ],
  29645. [
  29646. 4,
  29647. 4
  29648. ],
  29649. [
  29650. 4,
  29651. 4
  29652. ],
  29653. [
  29654. 4,
  29655. 4
  29656. ],
  29657. // 1011xxxxx
  29658. [
  29659. 4,
  29660. 4
  29661. ],
  29662. [
  29663. 4,
  29664. 4
  29665. ],
  29666. [
  29667. 4,
  29668. 4
  29669. ],
  29670. [
  29671. 4,
  29672. 4
  29673. ],
  29674. [
  29675. 4,
  29676. 4
  29677. ],
  29678. [
  29679. 4,
  29680. 4
  29681. ],
  29682. [
  29683. 4,
  29684. 4
  29685. ],
  29686. [
  29687. 4,
  29688. 4
  29689. ],
  29690. [
  29691. 4,
  29692. 4
  29693. ],
  29694. [
  29695. 4,
  29696. 4
  29697. ],
  29698. [
  29699. 4,
  29700. 4
  29701. ],
  29702. [
  29703. 4,
  29704. 4
  29705. ],
  29706. [
  29707. 4,
  29708. 4
  29709. ],
  29710. [
  29711. 4,
  29712. 4
  29713. ],
  29714. [
  29715. 4,
  29716. 4
  29717. ],
  29718. [
  29719. 4,
  29720. 4
  29721. ],
  29722. [
  29723. 4,
  29724. 4
  29725. ],
  29726. [
  29727. 4,
  29728. 4
  29729. ],
  29730. [
  29731. 4,
  29732. 4
  29733. ],
  29734. [
  29735. 4,
  29736. 4
  29737. ],
  29738. [
  29739. 4,
  29740. 4
  29741. ],
  29742. [
  29743. 4,
  29744. 4
  29745. ],
  29746. [
  29747. 4,
  29748. 4
  29749. ],
  29750. [
  29751. 4,
  29752. 4
  29753. ],
  29754. [
  29755. 4,
  29756. 4
  29757. ],
  29758. [
  29759. 4,
  29760. 4
  29761. ],
  29762. [
  29763. 4,
  29764. 4
  29765. ],
  29766. [
  29767. 4,
  29768. 4
  29769. ],
  29770. [
  29771. 4,
  29772. 5
  29773. ],
  29774. [
  29775. 4,
  29776. 5
  29777. ],
  29778. [
  29779. 4,
  29780. 5
  29781. ],
  29782. [
  29783. 4,
  29784. 5
  29785. ],
  29786. // 1100xxxxx
  29787. [
  29788. 4,
  29789. 5
  29790. ],
  29791. [
  29792. 4,
  29793. 5
  29794. ],
  29795. [
  29796. 4,
  29797. 5
  29798. ],
  29799. [
  29800. 4,
  29801. 5
  29802. ],
  29803. [
  29804. 4,
  29805. 5
  29806. ],
  29807. [
  29808. 4,
  29809. 5
  29810. ],
  29811. [
  29812. 4,
  29813. 5
  29814. ],
  29815. [
  29816. 4,
  29817. 5
  29818. ],
  29819. [
  29820. 4,
  29821. 5
  29822. ],
  29823. [
  29824. 4,
  29825. 5
  29826. ],
  29827. [
  29828. 4,
  29829. 5
  29830. ],
  29831. [
  29832. 4,
  29833. 5
  29834. ],
  29835. [
  29836. 4,
  29837. 5
  29838. ],
  29839. [
  29840. 4,
  29841. 5
  29842. ],
  29843. [
  29844. 4,
  29845. 5
  29846. ],
  29847. [
  29848. 4,
  29849. 5
  29850. ],
  29851. [
  29852. 4,
  29853. 5
  29854. ],
  29855. [
  29856. 4,
  29857. 5
  29858. ],
  29859. [
  29860. 4,
  29861. 5
  29862. ],
  29863. [
  29864. 4,
  29865. 5
  29866. ],
  29867. [
  29868. 4,
  29869. 5
  29870. ],
  29871. [
  29872. 4,
  29873. 5
  29874. ],
  29875. [
  29876. 4,
  29877. 5
  29878. ],
  29879. [
  29880. 4,
  29881. 5
  29882. ],
  29883. [
  29884. 4,
  29885. 5
  29886. ],
  29887. [
  29888. 4,
  29889. 5
  29890. ],
  29891. [
  29892. 4,
  29893. 5
  29894. ],
  29895. [
  29896. 4,
  29897. 5
  29898. ],
  29899. [
  29900. 6,
  29901. 14
  29902. ],
  29903. [
  29904. 6,
  29905. 14
  29906. ],
  29907. [
  29908. 6,
  29909. 14
  29910. ],
  29911. [
  29912. 6,
  29913. 14
  29914. ],
  29915. // 110100xxx
  29916. [
  29917. 6,
  29918. 14
  29919. ],
  29920. [
  29921. 6,
  29922. 14
  29923. ],
  29924. [
  29925. 6,
  29926. 14
  29927. ],
  29928. [
  29929. 6,
  29930. 14
  29931. ],
  29932. [
  29933. 6,
  29934. 15
  29935. ],
  29936. [
  29937. 6,
  29938. 15
  29939. ],
  29940. [
  29941. 6,
  29942. 15
  29943. ],
  29944. [
  29945. 6,
  29946. 15
  29947. ],
  29948. // 110101xxx
  29949. [
  29950. 6,
  29951. 15
  29952. ],
  29953. [
  29954. 6,
  29955. 15
  29956. ],
  29957. [
  29958. 6,
  29959. 15
  29960. ],
  29961. [
  29962. 6,
  29963. 15
  29964. ],
  29965. [
  29966. 5,
  29967. 64
  29968. ],
  29969. [
  29970. 5,
  29971. 64
  29972. ],
  29973. [
  29974. 5,
  29975. 64
  29976. ],
  29977. [
  29978. 5,
  29979. 64
  29980. ],
  29981. // 11011xxxx
  29982. [
  29983. 5,
  29984. 64
  29985. ],
  29986. [
  29987. 5,
  29988. 64
  29989. ],
  29990. [
  29991. 5,
  29992. 64
  29993. ],
  29994. [
  29995. 5,
  29996. 64
  29997. ],
  29998. [
  29999. 5,
  30000. 64
  30001. ],
  30002. [
  30003. 5,
  30004. 64
  30005. ],
  30006. [
  30007. 5,
  30008. 64
  30009. ],
  30010. [
  30011. 5,
  30012. 64
  30013. ],
  30014. [
  30015. 5,
  30016. 64
  30017. ],
  30018. [
  30019. 5,
  30020. 64
  30021. ],
  30022. [
  30023. 5,
  30024. 64
  30025. ],
  30026. [
  30027. 5,
  30028. 64
  30029. ],
  30030. [
  30031. 4,
  30032. 6
  30033. ],
  30034. [
  30035. 4,
  30036. 6
  30037. ],
  30038. [
  30039. 4,
  30040. 6
  30041. ],
  30042. [
  30043. 4,
  30044. 6
  30045. ],
  30046. // 1110xxxxx
  30047. [
  30048. 4,
  30049. 6
  30050. ],
  30051. [
  30052. 4,
  30053. 6
  30054. ],
  30055. [
  30056. 4,
  30057. 6
  30058. ],
  30059. [
  30060. 4,
  30061. 6
  30062. ],
  30063. [
  30064. 4,
  30065. 6
  30066. ],
  30067. [
  30068. 4,
  30069. 6
  30070. ],
  30071. [
  30072. 4,
  30073. 6
  30074. ],
  30075. [
  30076. 4,
  30077. 6
  30078. ],
  30079. [
  30080. 4,
  30081. 6
  30082. ],
  30083. [
  30084. 4,
  30085. 6
  30086. ],
  30087. [
  30088. 4,
  30089. 6
  30090. ],
  30091. [
  30092. 4,
  30093. 6
  30094. ],
  30095. [
  30096. 4,
  30097. 6
  30098. ],
  30099. [
  30100. 4,
  30101. 6
  30102. ],
  30103. [
  30104. 4,
  30105. 6
  30106. ],
  30107. [
  30108. 4,
  30109. 6
  30110. ],
  30111. [
  30112. 4,
  30113. 6
  30114. ],
  30115. [
  30116. 4,
  30117. 6
  30118. ],
  30119. [
  30120. 4,
  30121. 6
  30122. ],
  30123. [
  30124. 4,
  30125. 6
  30126. ],
  30127. [
  30128. 4,
  30129. 6
  30130. ],
  30131. [
  30132. 4,
  30133. 6
  30134. ],
  30135. [
  30136. 4,
  30137. 6
  30138. ],
  30139. [
  30140. 4,
  30141. 6
  30142. ],
  30143. [
  30144. 4,
  30145. 6
  30146. ],
  30147. [
  30148. 4,
  30149. 6
  30150. ],
  30151. [
  30152. 4,
  30153. 6
  30154. ],
  30155. [
  30156. 4,
  30157. 6
  30158. ],
  30159. [
  30160. 4,
  30161. 7
  30162. ],
  30163. [
  30164. 4,
  30165. 7
  30166. ],
  30167. [
  30168. 4,
  30169. 7
  30170. ],
  30171. [
  30172. 4,
  30173. 7
  30174. ],
  30175. // 1111xxxxx
  30176. [
  30177. 4,
  30178. 7
  30179. ],
  30180. [
  30181. 4,
  30182. 7
  30183. ],
  30184. [
  30185. 4,
  30186. 7
  30187. ],
  30188. [
  30189. 4,
  30190. 7
  30191. ],
  30192. [
  30193. 4,
  30194. 7
  30195. ],
  30196. [
  30197. 4,
  30198. 7
  30199. ],
  30200. [
  30201. 4,
  30202. 7
  30203. ],
  30204. [
  30205. 4,
  30206. 7
  30207. ],
  30208. [
  30209. 4,
  30210. 7
  30211. ],
  30212. [
  30213. 4,
  30214. 7
  30215. ],
  30216. [
  30217. 4,
  30218. 7
  30219. ],
  30220. [
  30221. 4,
  30222. 7
  30223. ],
  30224. [
  30225. 4,
  30226. 7
  30227. ],
  30228. [
  30229. 4,
  30230. 7
  30231. ],
  30232. [
  30233. 4,
  30234. 7
  30235. ],
  30236. [
  30237. 4,
  30238. 7
  30239. ],
  30240. [
  30241. 4,
  30242. 7
  30243. ],
  30244. [
  30245. 4,
  30246. 7
  30247. ],
  30248. [
  30249. 4,
  30250. 7
  30251. ],
  30252. [
  30253. 4,
  30254. 7
  30255. ],
  30256. [
  30257. 4,
  30258. 7
  30259. ],
  30260. [
  30261. 4,
  30262. 7
  30263. ],
  30264. [
  30265. 4,
  30266. 7
  30267. ],
  30268. [
  30269. 4,
  30270. 7
  30271. ],
  30272. [
  30273. 4,
  30274. 7
  30275. ],
  30276. [
  30277. 4,
  30278. 7
  30279. ],
  30280. [
  30281. 4,
  30282. 7
  30283. ],
  30284. [
  30285. 4,
  30286. 7
  30287. ]
  30288. ];
  30289. var blackTable1 = [
  30290. [
  30291. -1,
  30292. -1
  30293. ],
  30294. [
  30295. -1,
  30296. -1
  30297. ],
  30298. // 000000000000x
  30299. [
  30300. 12,
  30301. ccittEOL
  30302. ],
  30303. [
  30304. 12,
  30305. ccittEOL
  30306. ],
  30307. // 000000000001x
  30308. [
  30309. -1,
  30310. -1
  30311. ],
  30312. [
  30313. -1,
  30314. -1
  30315. ],
  30316. [
  30317. -1,
  30318. -1
  30319. ],
  30320. [
  30321. -1,
  30322. -1
  30323. ],
  30324. // 00000000001xx
  30325. [
  30326. -1,
  30327. -1
  30328. ],
  30329. [
  30330. -1,
  30331. -1
  30332. ],
  30333. [
  30334. -1,
  30335. -1
  30336. ],
  30337. [
  30338. -1,
  30339. -1
  30340. ],
  30341. // 00000000010xx
  30342. [
  30343. -1,
  30344. -1
  30345. ],
  30346. [
  30347. -1,
  30348. -1
  30349. ],
  30350. [
  30351. -1,
  30352. -1
  30353. ],
  30354. [
  30355. -1,
  30356. -1
  30357. ],
  30358. // 00000000011xx
  30359. [
  30360. -1,
  30361. -1
  30362. ],
  30363. [
  30364. -1,
  30365. -1
  30366. ],
  30367. [
  30368. -1,
  30369. -1
  30370. ],
  30371. [
  30372. -1,
  30373. -1
  30374. ],
  30375. // 00000000100xx
  30376. [
  30377. -1,
  30378. -1
  30379. ],
  30380. [
  30381. -1,
  30382. -1
  30383. ],
  30384. [
  30385. -1,
  30386. -1
  30387. ],
  30388. [
  30389. -1,
  30390. -1
  30391. ],
  30392. // 00000000101xx
  30393. [
  30394. -1,
  30395. -1
  30396. ],
  30397. [
  30398. -1,
  30399. -1
  30400. ],
  30401. [
  30402. -1,
  30403. -1
  30404. ],
  30405. [
  30406. -1,
  30407. -1
  30408. ],
  30409. // 00000000110xx
  30410. [
  30411. -1,
  30412. -1
  30413. ],
  30414. [
  30415. -1,
  30416. -1
  30417. ],
  30418. [
  30419. -1,
  30420. -1
  30421. ],
  30422. [
  30423. -1,
  30424. -1
  30425. ],
  30426. // 00000000111xx
  30427. [
  30428. 11,
  30429. 1792
  30430. ],
  30431. [
  30432. 11,
  30433. 1792
  30434. ],
  30435. [
  30436. 11,
  30437. 1792
  30438. ],
  30439. [
  30440. 11,
  30441. 1792
  30442. ],
  30443. // 00000001000xx
  30444. [
  30445. 12,
  30446. 1984
  30447. ],
  30448. [
  30449. 12,
  30450. 1984
  30451. ],
  30452. // 000000010010x
  30453. [
  30454. 12,
  30455. 2048
  30456. ],
  30457. [
  30458. 12,
  30459. 2048
  30460. ],
  30461. // 000000010011x
  30462. [
  30463. 12,
  30464. 2112
  30465. ],
  30466. [
  30467. 12,
  30468. 2112
  30469. ],
  30470. // 000000010100x
  30471. [
  30472. 12,
  30473. 2176
  30474. ],
  30475. [
  30476. 12,
  30477. 2176
  30478. ],
  30479. // 000000010101x
  30480. [
  30481. 12,
  30482. 2240
  30483. ],
  30484. [
  30485. 12,
  30486. 2240
  30487. ],
  30488. // 000000010110x
  30489. [
  30490. 12,
  30491. 2304
  30492. ],
  30493. [
  30494. 12,
  30495. 2304
  30496. ],
  30497. // 000000010111x
  30498. [
  30499. 11,
  30500. 1856
  30501. ],
  30502. [
  30503. 11,
  30504. 1856
  30505. ],
  30506. [
  30507. 11,
  30508. 1856
  30509. ],
  30510. [
  30511. 11,
  30512. 1856
  30513. ],
  30514. // 00000001100xx
  30515. [
  30516. 11,
  30517. 1920
  30518. ],
  30519. [
  30520. 11,
  30521. 1920
  30522. ],
  30523. [
  30524. 11,
  30525. 1920
  30526. ],
  30527. [
  30528. 11,
  30529. 1920
  30530. ],
  30531. // 00000001101xx
  30532. [
  30533. 12,
  30534. 2368
  30535. ],
  30536. [
  30537. 12,
  30538. 2368
  30539. ],
  30540. // 000000011100x
  30541. [
  30542. 12,
  30543. 2432
  30544. ],
  30545. [
  30546. 12,
  30547. 2432
  30548. ],
  30549. // 000000011101x
  30550. [
  30551. 12,
  30552. 2496
  30553. ],
  30554. [
  30555. 12,
  30556. 2496
  30557. ],
  30558. // 000000011110x
  30559. [
  30560. 12,
  30561. 2560
  30562. ],
  30563. [
  30564. 12,
  30565. 2560
  30566. ],
  30567. // 000000011111x
  30568. [
  30569. 10,
  30570. 18
  30571. ],
  30572. [
  30573. 10,
  30574. 18
  30575. ],
  30576. [
  30577. 10,
  30578. 18
  30579. ],
  30580. [
  30581. 10,
  30582. 18
  30583. ],
  30584. // 0000001000xxx
  30585. [
  30586. 10,
  30587. 18
  30588. ],
  30589. [
  30590. 10,
  30591. 18
  30592. ],
  30593. [
  30594. 10,
  30595. 18
  30596. ],
  30597. [
  30598. 10,
  30599. 18
  30600. ],
  30601. [
  30602. 12,
  30603. 52
  30604. ],
  30605. [
  30606. 12,
  30607. 52
  30608. ],
  30609. // 000000100100x
  30610. [
  30611. 13,
  30612. 640
  30613. ],
  30614. // 0000001001010
  30615. [
  30616. 13,
  30617. 704
  30618. ],
  30619. // 0000001001011
  30620. [
  30621. 13,
  30622. 768
  30623. ],
  30624. // 0000001001100
  30625. [
  30626. 13,
  30627. 832
  30628. ],
  30629. // 0000001001101
  30630. [
  30631. 12,
  30632. 55
  30633. ],
  30634. [
  30635. 12,
  30636. 55
  30637. ],
  30638. // 000000100111x
  30639. [
  30640. 12,
  30641. 56
  30642. ],
  30643. [
  30644. 12,
  30645. 56
  30646. ],
  30647. // 000000101000x
  30648. [
  30649. 13,
  30650. 1280
  30651. ],
  30652. // 0000001010010
  30653. [
  30654. 13,
  30655. 1344
  30656. ],
  30657. // 0000001010011
  30658. [
  30659. 13,
  30660. 1408
  30661. ],
  30662. // 0000001010100
  30663. [
  30664. 13,
  30665. 1472
  30666. ],
  30667. // 0000001010101
  30668. [
  30669. 12,
  30670. 59
  30671. ],
  30672. [
  30673. 12,
  30674. 59
  30675. ],
  30676. // 000000101011x
  30677. [
  30678. 12,
  30679. 60
  30680. ],
  30681. [
  30682. 12,
  30683. 60
  30684. ],
  30685. // 000000101100x
  30686. [
  30687. 13,
  30688. 1536
  30689. ],
  30690. // 0000001011010
  30691. [
  30692. 13,
  30693. 1600
  30694. ],
  30695. // 0000001011011
  30696. [
  30697. 11,
  30698. 24
  30699. ],
  30700. [
  30701. 11,
  30702. 24
  30703. ],
  30704. [
  30705. 11,
  30706. 24
  30707. ],
  30708. [
  30709. 11,
  30710. 24
  30711. ],
  30712. // 00000010111xx
  30713. [
  30714. 11,
  30715. 25
  30716. ],
  30717. [
  30718. 11,
  30719. 25
  30720. ],
  30721. [
  30722. 11,
  30723. 25
  30724. ],
  30725. [
  30726. 11,
  30727. 25
  30728. ],
  30729. // 00000011000xx
  30730. [
  30731. 13,
  30732. 1664
  30733. ],
  30734. // 0000001100100
  30735. [
  30736. 13,
  30737. 1728
  30738. ],
  30739. // 0000001100101
  30740. [
  30741. 12,
  30742. 320
  30743. ],
  30744. [
  30745. 12,
  30746. 320
  30747. ],
  30748. // 000000110011x
  30749. [
  30750. 12,
  30751. 384
  30752. ],
  30753. [
  30754. 12,
  30755. 384
  30756. ],
  30757. // 000000110100x
  30758. [
  30759. 12,
  30760. 448
  30761. ],
  30762. [
  30763. 12,
  30764. 448
  30765. ],
  30766. // 000000110101x
  30767. [
  30768. 13,
  30769. 512
  30770. ],
  30771. // 0000001101100
  30772. [
  30773. 13,
  30774. 576
  30775. ],
  30776. // 0000001101101
  30777. [
  30778. 12,
  30779. 53
  30780. ],
  30781. [
  30782. 12,
  30783. 53
  30784. ],
  30785. // 000000110111x
  30786. [
  30787. 12,
  30788. 54
  30789. ],
  30790. [
  30791. 12,
  30792. 54
  30793. ],
  30794. // 000000111000x
  30795. [
  30796. 13,
  30797. 896
  30798. ],
  30799. // 0000001110010
  30800. [
  30801. 13,
  30802. 960
  30803. ],
  30804. // 0000001110011
  30805. [
  30806. 13,
  30807. 1024
  30808. ],
  30809. // 0000001110100
  30810. [
  30811. 13,
  30812. 1088
  30813. ],
  30814. // 0000001110101
  30815. [
  30816. 13,
  30817. 1152
  30818. ],
  30819. // 0000001110110
  30820. [
  30821. 13,
  30822. 1216
  30823. ],
  30824. // 0000001110111
  30825. [
  30826. 10,
  30827. 64
  30828. ],
  30829. [
  30830. 10,
  30831. 64
  30832. ],
  30833. [
  30834. 10,
  30835. 64
  30836. ],
  30837. [
  30838. 10,
  30839. 64
  30840. ],
  30841. // 0000001111xxx
  30842. [
  30843. 10,
  30844. 64
  30845. ],
  30846. [
  30847. 10,
  30848. 64
  30849. ],
  30850. [
  30851. 10,
  30852. 64
  30853. ],
  30854. [
  30855. 10,
  30856. 64
  30857. ]
  30858. ];
  30859. var blackTable2 = [
  30860. [
  30861. 8,
  30862. 13
  30863. ],
  30864. [
  30865. 8,
  30866. 13
  30867. ],
  30868. [
  30869. 8,
  30870. 13
  30871. ],
  30872. [
  30873. 8,
  30874. 13
  30875. ],
  30876. // 00000100xxxx
  30877. [
  30878. 8,
  30879. 13
  30880. ],
  30881. [
  30882. 8,
  30883. 13
  30884. ],
  30885. [
  30886. 8,
  30887. 13
  30888. ],
  30889. [
  30890. 8,
  30891. 13
  30892. ],
  30893. [
  30894. 8,
  30895. 13
  30896. ],
  30897. [
  30898. 8,
  30899. 13
  30900. ],
  30901. [
  30902. 8,
  30903. 13
  30904. ],
  30905. [
  30906. 8,
  30907. 13
  30908. ],
  30909. [
  30910. 8,
  30911. 13
  30912. ],
  30913. [
  30914. 8,
  30915. 13
  30916. ],
  30917. [
  30918. 8,
  30919. 13
  30920. ],
  30921. [
  30922. 8,
  30923. 13
  30924. ],
  30925. [
  30926. 11,
  30927. 23
  30928. ],
  30929. [
  30930. 11,
  30931. 23
  30932. ],
  30933. // 00000101000x
  30934. [
  30935. 12,
  30936. 50
  30937. ],
  30938. // 000001010010
  30939. [
  30940. 12,
  30941. 51
  30942. ],
  30943. // 000001010011
  30944. [
  30945. 12,
  30946. 44
  30947. ],
  30948. // 000001010100
  30949. [
  30950. 12,
  30951. 45
  30952. ],
  30953. // 000001010101
  30954. [
  30955. 12,
  30956. 46
  30957. ],
  30958. // 000001010110
  30959. [
  30960. 12,
  30961. 47
  30962. ],
  30963. // 000001010111
  30964. [
  30965. 12,
  30966. 57
  30967. ],
  30968. // 000001011000
  30969. [
  30970. 12,
  30971. 58
  30972. ],
  30973. // 000001011001
  30974. [
  30975. 12,
  30976. 61
  30977. ],
  30978. // 000001011010
  30979. [
  30980. 12,
  30981. 256
  30982. ],
  30983. // 000001011011
  30984. [
  30985. 10,
  30986. 16
  30987. ],
  30988. [
  30989. 10,
  30990. 16
  30991. ],
  30992. [
  30993. 10,
  30994. 16
  30995. ],
  30996. [
  30997. 10,
  30998. 16
  30999. ],
  31000. // 0000010111xx
  31001. [
  31002. 10,
  31003. 17
  31004. ],
  31005. [
  31006. 10,
  31007. 17
  31008. ],
  31009. [
  31010. 10,
  31011. 17
  31012. ],
  31013. [
  31014. 10,
  31015. 17
  31016. ],
  31017. // 0000011000xx
  31018. [
  31019. 12,
  31020. 48
  31021. ],
  31022. // 000001100100
  31023. [
  31024. 12,
  31025. 49
  31026. ],
  31027. // 000001100101
  31028. [
  31029. 12,
  31030. 62
  31031. ],
  31032. // 000001100110
  31033. [
  31034. 12,
  31035. 63
  31036. ],
  31037. // 000001100111
  31038. [
  31039. 12,
  31040. 30
  31041. ],
  31042. // 000001101000
  31043. [
  31044. 12,
  31045. 31
  31046. ],
  31047. // 000001101001
  31048. [
  31049. 12,
  31050. 32
  31051. ],
  31052. // 000001101010
  31053. [
  31054. 12,
  31055. 33
  31056. ],
  31057. // 000001101011
  31058. [
  31059. 12,
  31060. 40
  31061. ],
  31062. // 000001101100
  31063. [
  31064. 12,
  31065. 41
  31066. ],
  31067. // 000001101101
  31068. [
  31069. 11,
  31070. 22
  31071. ],
  31072. [
  31073. 11,
  31074. 22
  31075. ],
  31076. // 00000110111x
  31077. [
  31078. 8,
  31079. 14
  31080. ],
  31081. [
  31082. 8,
  31083. 14
  31084. ],
  31085. [
  31086. 8,
  31087. 14
  31088. ],
  31089. [
  31090. 8,
  31091. 14
  31092. ],
  31093. // 00000111xxxx
  31094. [
  31095. 8,
  31096. 14
  31097. ],
  31098. [
  31099. 8,
  31100. 14
  31101. ],
  31102. [
  31103. 8,
  31104. 14
  31105. ],
  31106. [
  31107. 8,
  31108. 14
  31109. ],
  31110. [
  31111. 8,
  31112. 14
  31113. ],
  31114. [
  31115. 8,
  31116. 14
  31117. ],
  31118. [
  31119. 8,
  31120. 14
  31121. ],
  31122. [
  31123. 8,
  31124. 14
  31125. ],
  31126. [
  31127. 8,
  31128. 14
  31129. ],
  31130. [
  31131. 8,
  31132. 14
  31133. ],
  31134. [
  31135. 8,
  31136. 14
  31137. ],
  31138. [
  31139. 8,
  31140. 14
  31141. ],
  31142. [
  31143. 7,
  31144. 10
  31145. ],
  31146. [
  31147. 7,
  31148. 10
  31149. ],
  31150. [
  31151. 7,
  31152. 10
  31153. ],
  31154. [
  31155. 7,
  31156. 10
  31157. ],
  31158. // 0000100xxxxx
  31159. [
  31160. 7,
  31161. 10
  31162. ],
  31163. [
  31164. 7,
  31165. 10
  31166. ],
  31167. [
  31168. 7,
  31169. 10
  31170. ],
  31171. [
  31172. 7,
  31173. 10
  31174. ],
  31175. [
  31176. 7,
  31177. 10
  31178. ],
  31179. [
  31180. 7,
  31181. 10
  31182. ],
  31183. [
  31184. 7,
  31185. 10
  31186. ],
  31187. [
  31188. 7,
  31189. 10
  31190. ],
  31191. [
  31192. 7,
  31193. 10
  31194. ],
  31195. [
  31196. 7,
  31197. 10
  31198. ],
  31199. [
  31200. 7,
  31201. 10
  31202. ],
  31203. [
  31204. 7,
  31205. 10
  31206. ],
  31207. [
  31208. 7,
  31209. 10
  31210. ],
  31211. [
  31212. 7,
  31213. 10
  31214. ],
  31215. [
  31216. 7,
  31217. 10
  31218. ],
  31219. [
  31220. 7,
  31221. 10
  31222. ],
  31223. [
  31224. 7,
  31225. 10
  31226. ],
  31227. [
  31228. 7,
  31229. 10
  31230. ],
  31231. [
  31232. 7,
  31233. 10
  31234. ],
  31235. [
  31236. 7,
  31237. 10
  31238. ],
  31239. [
  31240. 7,
  31241. 10
  31242. ],
  31243. [
  31244. 7,
  31245. 10
  31246. ],
  31247. [
  31248. 7,
  31249. 10
  31250. ],
  31251. [
  31252. 7,
  31253. 10
  31254. ],
  31255. [
  31256. 7,
  31257. 10
  31258. ],
  31259. [
  31260. 7,
  31261. 10
  31262. ],
  31263. [
  31264. 7,
  31265. 10
  31266. ],
  31267. [
  31268. 7,
  31269. 10
  31270. ],
  31271. [
  31272. 7,
  31273. 11
  31274. ],
  31275. [
  31276. 7,
  31277. 11
  31278. ],
  31279. [
  31280. 7,
  31281. 11
  31282. ],
  31283. [
  31284. 7,
  31285. 11
  31286. ],
  31287. // 0000101xxxxx
  31288. [
  31289. 7,
  31290. 11
  31291. ],
  31292. [
  31293. 7,
  31294. 11
  31295. ],
  31296. [
  31297. 7,
  31298. 11
  31299. ],
  31300. [
  31301. 7,
  31302. 11
  31303. ],
  31304. [
  31305. 7,
  31306. 11
  31307. ],
  31308. [
  31309. 7,
  31310. 11
  31311. ],
  31312. [
  31313. 7,
  31314. 11
  31315. ],
  31316. [
  31317. 7,
  31318. 11
  31319. ],
  31320. [
  31321. 7,
  31322. 11
  31323. ],
  31324. [
  31325. 7,
  31326. 11
  31327. ],
  31328. [
  31329. 7,
  31330. 11
  31331. ],
  31332. [
  31333. 7,
  31334. 11
  31335. ],
  31336. [
  31337. 7,
  31338. 11
  31339. ],
  31340. [
  31341. 7,
  31342. 11
  31343. ],
  31344. [
  31345. 7,
  31346. 11
  31347. ],
  31348. [
  31349. 7,
  31350. 11
  31351. ],
  31352. [
  31353. 7,
  31354. 11
  31355. ],
  31356. [
  31357. 7,
  31358. 11
  31359. ],
  31360. [
  31361. 7,
  31362. 11
  31363. ],
  31364. [
  31365. 7,
  31366. 11
  31367. ],
  31368. [
  31369. 7,
  31370. 11
  31371. ],
  31372. [
  31373. 7,
  31374. 11
  31375. ],
  31376. [
  31377. 7,
  31378. 11
  31379. ],
  31380. [
  31381. 7,
  31382. 11
  31383. ],
  31384. [
  31385. 7,
  31386. 11
  31387. ],
  31388. [
  31389. 7,
  31390. 11
  31391. ],
  31392. [
  31393. 7,
  31394. 11
  31395. ],
  31396. [
  31397. 7,
  31398. 11
  31399. ],
  31400. [
  31401. 9,
  31402. 15
  31403. ],
  31404. [
  31405. 9,
  31406. 15
  31407. ],
  31408. [
  31409. 9,
  31410. 15
  31411. ],
  31412. [
  31413. 9,
  31414. 15
  31415. ],
  31416. // 000011000xxx
  31417. [
  31418. 9,
  31419. 15
  31420. ],
  31421. [
  31422. 9,
  31423. 15
  31424. ],
  31425. [
  31426. 9,
  31427. 15
  31428. ],
  31429. [
  31430. 9,
  31431. 15
  31432. ],
  31433. [
  31434. 12,
  31435. 128
  31436. ],
  31437. // 000011001000
  31438. [
  31439. 12,
  31440. 192
  31441. ],
  31442. // 000011001001
  31443. [
  31444. 12,
  31445. 26
  31446. ],
  31447. // 000011001010
  31448. [
  31449. 12,
  31450. 27
  31451. ],
  31452. // 000011001011
  31453. [
  31454. 12,
  31455. 28
  31456. ],
  31457. // 000011001100
  31458. [
  31459. 12,
  31460. 29
  31461. ],
  31462. // 000011001101
  31463. [
  31464. 11,
  31465. 19
  31466. ],
  31467. [
  31468. 11,
  31469. 19
  31470. ],
  31471. // 00001100111x
  31472. [
  31473. 11,
  31474. 20
  31475. ],
  31476. [
  31477. 11,
  31478. 20
  31479. ],
  31480. // 00001101000x
  31481. [
  31482. 12,
  31483. 34
  31484. ],
  31485. // 000011010010
  31486. [
  31487. 12,
  31488. 35
  31489. ],
  31490. // 000011010011
  31491. [
  31492. 12,
  31493. 36
  31494. ],
  31495. // 000011010100
  31496. [
  31497. 12,
  31498. 37
  31499. ],
  31500. // 000011010101
  31501. [
  31502. 12,
  31503. 38
  31504. ],
  31505. // 000011010110
  31506. [
  31507. 12,
  31508. 39
  31509. ],
  31510. // 000011010111
  31511. [
  31512. 11,
  31513. 21
  31514. ],
  31515. [
  31516. 11,
  31517. 21
  31518. ],
  31519. // 00001101100x
  31520. [
  31521. 12,
  31522. 42
  31523. ],
  31524. // 000011011010
  31525. [
  31526. 12,
  31527. 43
  31528. ],
  31529. // 000011011011
  31530. [
  31531. 10,
  31532. 0
  31533. ],
  31534. [
  31535. 10,
  31536. 0
  31537. ],
  31538. [
  31539. 10,
  31540. 0
  31541. ],
  31542. [
  31543. 10,
  31544. 0
  31545. ],
  31546. // 0000110111xx
  31547. [
  31548. 7,
  31549. 12
  31550. ],
  31551. [
  31552. 7,
  31553. 12
  31554. ],
  31555. [
  31556. 7,
  31557. 12
  31558. ],
  31559. [
  31560. 7,
  31561. 12
  31562. ],
  31563. // 0000111xxxxx
  31564. [
  31565. 7,
  31566. 12
  31567. ],
  31568. [
  31569. 7,
  31570. 12
  31571. ],
  31572. [
  31573. 7,
  31574. 12
  31575. ],
  31576. [
  31577. 7,
  31578. 12
  31579. ],
  31580. [
  31581. 7,
  31582. 12
  31583. ],
  31584. [
  31585. 7,
  31586. 12
  31587. ],
  31588. [
  31589. 7,
  31590. 12
  31591. ],
  31592. [
  31593. 7,
  31594. 12
  31595. ],
  31596. [
  31597. 7,
  31598. 12
  31599. ],
  31600. [
  31601. 7,
  31602. 12
  31603. ],
  31604. [
  31605. 7,
  31606. 12
  31607. ],
  31608. [
  31609. 7,
  31610. 12
  31611. ],
  31612. [
  31613. 7,
  31614. 12
  31615. ],
  31616. [
  31617. 7,
  31618. 12
  31619. ],
  31620. [
  31621. 7,
  31622. 12
  31623. ],
  31624. [
  31625. 7,
  31626. 12
  31627. ],
  31628. [
  31629. 7,
  31630. 12
  31631. ],
  31632. [
  31633. 7,
  31634. 12
  31635. ],
  31636. [
  31637. 7,
  31638. 12
  31639. ],
  31640. [
  31641. 7,
  31642. 12
  31643. ],
  31644. [
  31645. 7,
  31646. 12
  31647. ],
  31648. [
  31649. 7,
  31650. 12
  31651. ],
  31652. [
  31653. 7,
  31654. 12
  31655. ],
  31656. [
  31657. 7,
  31658. 12
  31659. ],
  31660. [
  31661. 7,
  31662. 12
  31663. ],
  31664. [
  31665. 7,
  31666. 12
  31667. ],
  31668. [
  31669. 7,
  31670. 12
  31671. ],
  31672. [
  31673. 7,
  31674. 12
  31675. ]
  31676. ];
  31677. var blackTable3 = [
  31678. [
  31679. -1,
  31680. -1
  31681. ],
  31682. [
  31683. -1,
  31684. -1
  31685. ],
  31686. [
  31687. -1,
  31688. -1
  31689. ],
  31690. [
  31691. -1,
  31692. -1
  31693. ],
  31694. // 0000xx
  31695. [
  31696. 6,
  31697. 9
  31698. ],
  31699. // 000100
  31700. [
  31701. 6,
  31702. 8
  31703. ],
  31704. // 000101
  31705. [
  31706. 5,
  31707. 7
  31708. ],
  31709. [
  31710. 5,
  31711. 7
  31712. ],
  31713. // 00011x
  31714. [
  31715. 4,
  31716. 6
  31717. ],
  31718. [
  31719. 4,
  31720. 6
  31721. ],
  31722. [
  31723. 4,
  31724. 6
  31725. ],
  31726. [
  31727. 4,
  31728. 6
  31729. ],
  31730. // 0010xx
  31731. [
  31732. 4,
  31733. 5
  31734. ],
  31735. [
  31736. 4,
  31737. 5
  31738. ],
  31739. [
  31740. 4,
  31741. 5
  31742. ],
  31743. [
  31744. 4,
  31745. 5
  31746. ],
  31747. // 0011xx
  31748. [
  31749. 3,
  31750. 1
  31751. ],
  31752. [
  31753. 3,
  31754. 1
  31755. ],
  31756. [
  31757. 3,
  31758. 1
  31759. ],
  31760. [
  31761. 3,
  31762. 1
  31763. ],
  31764. // 010xxx
  31765. [
  31766. 3,
  31767. 1
  31768. ],
  31769. [
  31770. 3,
  31771. 1
  31772. ],
  31773. [
  31774. 3,
  31775. 1
  31776. ],
  31777. [
  31778. 3,
  31779. 1
  31780. ],
  31781. [
  31782. 3,
  31783. 4
  31784. ],
  31785. [
  31786. 3,
  31787. 4
  31788. ],
  31789. [
  31790. 3,
  31791. 4
  31792. ],
  31793. [
  31794. 3,
  31795. 4
  31796. ],
  31797. // 011xxx
  31798. [
  31799. 3,
  31800. 4
  31801. ],
  31802. [
  31803. 3,
  31804. 4
  31805. ],
  31806. [
  31807. 3,
  31808. 4
  31809. ],
  31810. [
  31811. 3,
  31812. 4
  31813. ],
  31814. [
  31815. 2,
  31816. 3
  31817. ],
  31818. [
  31819. 2,
  31820. 3
  31821. ],
  31822. [
  31823. 2,
  31824. 3
  31825. ],
  31826. [
  31827. 2,
  31828. 3
  31829. ],
  31830. // 10xxxx
  31831. [
  31832. 2,
  31833. 3
  31834. ],
  31835. [
  31836. 2,
  31837. 3
  31838. ],
  31839. [
  31840. 2,
  31841. 3
  31842. ],
  31843. [
  31844. 2,
  31845. 3
  31846. ],
  31847. [
  31848. 2,
  31849. 3
  31850. ],
  31851. [
  31852. 2,
  31853. 3
  31854. ],
  31855. [
  31856. 2,
  31857. 3
  31858. ],
  31859. [
  31860. 2,
  31861. 3
  31862. ],
  31863. [
  31864. 2,
  31865. 3
  31866. ],
  31867. [
  31868. 2,
  31869. 3
  31870. ],
  31871. [
  31872. 2,
  31873. 3
  31874. ],
  31875. [
  31876. 2,
  31877. 3
  31878. ],
  31879. [
  31880. 2,
  31881. 2
  31882. ],
  31883. [
  31884. 2,
  31885. 2
  31886. ],
  31887. [
  31888. 2,
  31889. 2
  31890. ],
  31891. [
  31892. 2,
  31893. 2
  31894. ],
  31895. // 11xxxx
  31896. [
  31897. 2,
  31898. 2
  31899. ],
  31900. [
  31901. 2,
  31902. 2
  31903. ],
  31904. [
  31905. 2,
  31906. 2
  31907. ],
  31908. [
  31909. 2,
  31910. 2
  31911. ],
  31912. [
  31913. 2,
  31914. 2
  31915. ],
  31916. [
  31917. 2,
  31918. 2
  31919. ],
  31920. [
  31921. 2,
  31922. 2
  31923. ],
  31924. [
  31925. 2,
  31926. 2
  31927. ],
  31928. [
  31929. 2,
  31930. 2
  31931. ],
  31932. [
  31933. 2,
  31934. 2
  31935. ],
  31936. [
  31937. 2,
  31938. 2
  31939. ],
  31940. [
  31941. 2,
  31942. 2
  31943. ]
  31944. ];
  31945. function CCITTFaxStream(str, maybeLength, params) {
  31946. this.str = str;
  31947. this.dict = str.dict;
  31948. params = params || Dict.empty;
  31949. this.encoding = params.get('K') || 0;
  31950. this.eoline = params.get('EndOfLine') || false;
  31951. this.byteAlign = params.get('EncodedByteAlign') || false;
  31952. this.columns = params.get('Columns') || 1728;
  31953. this.rows = params.get('Rows') || 0;
  31954. var eoblock = params.get('EndOfBlock');
  31955. if (eoblock === null || eoblock === undefined) {
  31956. eoblock = true;
  31957. }
  31958. this.eoblock = eoblock;
  31959. this.black = params.get('BlackIs1') || false;
  31960. this.codingLine = new Uint32Array(this.columns + 1);
  31961. this.refLine = new Uint32Array(this.columns + 2);
  31962. this.codingLine[0] = this.columns;
  31963. this.codingPos = 0;
  31964. this.row = 0;
  31965. this.nextLine2D = this.encoding < 0;
  31966. this.inputBits = 0;
  31967. this.inputBuf = 0;
  31968. this.outputBits = 0;
  31969. var code1;
  31970. while ((code1 = this.lookBits(12)) === 0) {
  31971. this.eatBits(1);
  31972. }
  31973. if (code1 === 1) {
  31974. this.eatBits(12);
  31975. }
  31976. if (this.encoding > 0) {
  31977. this.nextLine2D = !this.lookBits(1);
  31978. this.eatBits(1);
  31979. }
  31980. DecodeStream.call(this, maybeLength);
  31981. }
  31982. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  31983. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  31984. while (!this.eof) {
  31985. var c = this.lookChar();
  31986. this.ensureBuffer(this.bufferLength + 1);
  31987. this.buffer[this.bufferLength++] = c;
  31988. }
  31989. };
  31990. CCITTFaxStream.prototype.addPixels = function ccittFaxStreamAddPixels(a1, blackPixels) {
  31991. var codingLine = this.codingLine;
  31992. var codingPos = this.codingPos;
  31993. if (a1 > codingLine[codingPos]) {
  31994. if (a1 > this.columns) {
  31995. info('row is wrong length');
  31996. this.err = true;
  31997. a1 = this.columns;
  31998. }
  31999. if (codingPos & 1 ^ blackPixels) {
  32000. ++codingPos;
  32001. }
  32002. codingLine[codingPos] = a1;
  32003. }
  32004. this.codingPos = codingPos;
  32005. };
  32006. CCITTFaxStream.prototype.addPixelsNeg = function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  32007. var codingLine = this.codingLine;
  32008. var codingPos = this.codingPos;
  32009. if (a1 > codingLine[codingPos]) {
  32010. if (a1 > this.columns) {
  32011. info('row is wrong length');
  32012. this.err = true;
  32013. a1 = this.columns;
  32014. }
  32015. if (codingPos & 1 ^ blackPixels) {
  32016. ++codingPos;
  32017. }
  32018. codingLine[codingPos] = a1;
  32019. } else if (a1 < codingLine[codingPos]) {
  32020. if (a1 < 0) {
  32021. info('invalid code');
  32022. this.err = true;
  32023. a1 = 0;
  32024. }
  32025. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  32026. --codingPos;
  32027. }
  32028. codingLine[codingPos] = a1;
  32029. }
  32030. this.codingPos = codingPos;
  32031. };
  32032. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  32033. var refLine = this.refLine;
  32034. var codingLine = this.codingLine;
  32035. var columns = this.columns;
  32036. var refPos, blackPixels, bits, i;
  32037. if (this.outputBits === 0) {
  32038. if (this.eof) {
  32039. return null;
  32040. }
  32041. this.err = false;
  32042. var code1, code2, code3;
  32043. if (this.nextLine2D) {
  32044. for (i = 0; codingLine[i] < columns; ++i) {
  32045. refLine[i] = codingLine[i];
  32046. }
  32047. refLine[i++] = columns;
  32048. refLine[i] = columns;
  32049. codingLine[0] = 0;
  32050. this.codingPos = 0;
  32051. refPos = 0;
  32052. blackPixels = 0;
  32053. while (codingLine[this.codingPos] < columns) {
  32054. code1 = this.getTwoDimCode();
  32055. switch (code1) {
  32056. case twoDimPass:
  32057. this.addPixels(refLine[refPos + 1], blackPixels);
  32058. if (refLine[refPos + 1] < columns) {
  32059. refPos += 2;
  32060. }
  32061. break;
  32062. case twoDimHoriz:
  32063. code1 = code2 = 0;
  32064. if (blackPixels) {
  32065. do {
  32066. code1 += code3 = this.getBlackCode();
  32067. } while (code3 >= 64);
  32068. do {
  32069. code2 += code3 = this.getWhiteCode();
  32070. } while (code3 >= 64);
  32071. } else {
  32072. do {
  32073. code1 += code3 = this.getWhiteCode();
  32074. } while (code3 >= 64);
  32075. do {
  32076. code2 += code3 = this.getBlackCode();
  32077. } while (code3 >= 64);
  32078. }
  32079. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  32080. if (codingLine[this.codingPos] < columns) {
  32081. this.addPixels(codingLine[this.codingPos] + code2, blackPixels ^ 1);
  32082. }
  32083. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  32084. refPos += 2;
  32085. }
  32086. break;
  32087. case twoDimVertR3:
  32088. this.addPixels(refLine[refPos] + 3, blackPixels);
  32089. blackPixels ^= 1;
  32090. if (codingLine[this.codingPos] < columns) {
  32091. ++refPos;
  32092. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  32093. refPos += 2;
  32094. }
  32095. }
  32096. break;
  32097. case twoDimVertR2:
  32098. this.addPixels(refLine[refPos] + 2, blackPixels);
  32099. blackPixels ^= 1;
  32100. if (codingLine[this.codingPos] < columns) {
  32101. ++refPos;
  32102. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  32103. refPos += 2;
  32104. }
  32105. }
  32106. break;
  32107. case twoDimVertR1:
  32108. this.addPixels(refLine[refPos] + 1, blackPixels);
  32109. blackPixels ^= 1;
  32110. if (codingLine[this.codingPos] < columns) {
  32111. ++refPos;
  32112. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  32113. refPos += 2;
  32114. }
  32115. }
  32116. break;
  32117. case twoDimVert0:
  32118. this.addPixels(refLine[refPos], blackPixels);
  32119. blackPixels ^= 1;
  32120. if (codingLine[this.codingPos] < columns) {
  32121. ++refPos;
  32122. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  32123. refPos += 2;
  32124. }
  32125. }
  32126. break;
  32127. case twoDimVertL3:
  32128. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  32129. blackPixels ^= 1;
  32130. if (codingLine[this.codingPos] < columns) {
  32131. if (refPos > 0) {
  32132. --refPos;
  32133. } else {
  32134. ++refPos;
  32135. }
  32136. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  32137. refPos += 2;
  32138. }
  32139. }
  32140. break;
  32141. case twoDimVertL2:
  32142. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  32143. blackPixels ^= 1;
  32144. if (codingLine[this.codingPos] < columns) {
  32145. if (refPos > 0) {
  32146. --refPos;
  32147. } else {
  32148. ++refPos;
  32149. }
  32150. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  32151. refPos += 2;
  32152. }
  32153. }
  32154. break;
  32155. case twoDimVertL1:
  32156. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  32157. blackPixels ^= 1;
  32158. if (codingLine[this.codingPos] < columns) {
  32159. if (refPos > 0) {
  32160. --refPos;
  32161. } else {
  32162. ++refPos;
  32163. }
  32164. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  32165. refPos += 2;
  32166. }
  32167. }
  32168. break;
  32169. case ccittEOF:
  32170. this.addPixels(columns, 0);
  32171. this.eof = true;
  32172. break;
  32173. default:
  32174. info('bad 2d code');
  32175. this.addPixels(columns, 0);
  32176. this.err = true;
  32177. }
  32178. }
  32179. } else {
  32180. codingLine[0] = 0;
  32181. this.codingPos = 0;
  32182. blackPixels = 0;
  32183. while (codingLine[this.codingPos] < columns) {
  32184. code1 = 0;
  32185. if (blackPixels) {
  32186. do {
  32187. code1 += code3 = this.getBlackCode();
  32188. } while (code3 >= 64);
  32189. } else {
  32190. do {
  32191. code1 += code3 = this.getWhiteCode();
  32192. } while (code3 >= 64);
  32193. }
  32194. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  32195. blackPixels ^= 1;
  32196. }
  32197. }
  32198. var gotEOL = false;
  32199. if (this.byteAlign) {
  32200. this.inputBits &= ~7;
  32201. }
  32202. if (!this.eoblock && this.row === this.rows - 1) {
  32203. this.eof = true;
  32204. } else {
  32205. code1 = this.lookBits(12);
  32206. if (this.eoline) {
  32207. while (code1 !== ccittEOF && code1 !== 1) {
  32208. this.eatBits(1);
  32209. code1 = this.lookBits(12);
  32210. }
  32211. } else {
  32212. while (code1 === 0) {
  32213. this.eatBits(1);
  32214. code1 = this.lookBits(12);
  32215. }
  32216. }
  32217. if (code1 === 1) {
  32218. this.eatBits(12);
  32219. gotEOL = true;
  32220. } else if (code1 === ccittEOF) {
  32221. this.eof = true;
  32222. }
  32223. }
  32224. if (!this.eof && this.encoding > 0) {
  32225. this.nextLine2D = !this.lookBits(1);
  32226. this.eatBits(1);
  32227. }
  32228. if (this.eoblock && gotEOL && this.byteAlign) {
  32229. code1 = this.lookBits(12);
  32230. if (code1 === 1) {
  32231. this.eatBits(12);
  32232. if (this.encoding > 0) {
  32233. this.lookBits(1);
  32234. this.eatBits(1);
  32235. }
  32236. if (this.encoding >= 0) {
  32237. for (i = 0; i < 4; ++i) {
  32238. code1 = this.lookBits(12);
  32239. if (code1 !== 1) {
  32240. info('bad rtc code: ' + code1);
  32241. }
  32242. this.eatBits(12);
  32243. if (this.encoding > 0) {
  32244. this.lookBits(1);
  32245. this.eatBits(1);
  32246. }
  32247. }
  32248. }
  32249. this.eof = true;
  32250. }
  32251. } else if (this.err && this.eoline) {
  32252. while (true) {
  32253. code1 = this.lookBits(13);
  32254. if (code1 === ccittEOF) {
  32255. this.eof = true;
  32256. return null;
  32257. }
  32258. if (code1 >> 1 === 1) {
  32259. break;
  32260. }
  32261. this.eatBits(1);
  32262. }
  32263. this.eatBits(12);
  32264. if (this.encoding > 0) {
  32265. this.eatBits(1);
  32266. this.nextLine2D = !(code1 & 1);
  32267. }
  32268. }
  32269. if (codingLine[0] > 0) {
  32270. this.outputBits = codingLine[this.codingPos = 0];
  32271. } else {
  32272. this.outputBits = codingLine[this.codingPos = 1];
  32273. }
  32274. this.row++;
  32275. }
  32276. var c;
  32277. if (this.outputBits >= 8) {
  32278. c = this.codingPos & 1 ? 0 : 0xFF;
  32279. this.outputBits -= 8;
  32280. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  32281. this.codingPos++;
  32282. this.outputBits = codingLine[this.codingPos] - codingLine[this.codingPos - 1];
  32283. }
  32284. } else {
  32285. bits = 8;
  32286. c = 0;
  32287. do {
  32288. if (this.outputBits > bits) {
  32289. c <<= bits;
  32290. if (!(this.codingPos & 1)) {
  32291. c |= 0xFF >> 8 - bits;
  32292. }
  32293. this.outputBits -= bits;
  32294. bits = 0;
  32295. } else {
  32296. c <<= this.outputBits;
  32297. if (!(this.codingPos & 1)) {
  32298. c |= 0xFF >> 8 - this.outputBits;
  32299. }
  32300. bits -= this.outputBits;
  32301. this.outputBits = 0;
  32302. if (codingLine[this.codingPos] < columns) {
  32303. this.codingPos++;
  32304. this.outputBits = codingLine[this.codingPos] - codingLine[this.codingPos - 1];
  32305. } else if (bits > 0) {
  32306. c <<= bits;
  32307. bits = 0;
  32308. }
  32309. }
  32310. } while (bits);
  32311. }
  32312. if (this.black) {
  32313. c ^= 0xFF;
  32314. }
  32315. return c;
  32316. };
  32317. // This functions returns the code found from the table.
  32318. // The start and end parameters set the boundaries for searching the table.
  32319. // The limit parameter is optional. Function returns an array with three
  32320. // values. The first array element indicates whether a valid code is being
  32321. // returned. The second array element is the actual code. The third array
  32322. // element indicates whether EOF was reached.
  32323. CCITTFaxStream.prototype.findTableCode = function ccittFaxStreamFindTableCode(start, end, table, limit) {
  32324. var limitValue = limit || 0;
  32325. for (var i = start; i <= end; ++i) {
  32326. var code = this.lookBits(i);
  32327. if (code === ccittEOF) {
  32328. return [
  32329. true,
  32330. 1,
  32331. false
  32332. ];
  32333. }
  32334. if (i < end) {
  32335. code <<= end - i;
  32336. }
  32337. if (!limitValue || code >= limitValue) {
  32338. var p = table[code - limitValue];
  32339. if (p[0] === i) {
  32340. this.eatBits(i);
  32341. return [
  32342. true,
  32343. p[1],
  32344. true
  32345. ];
  32346. }
  32347. }
  32348. }
  32349. return [
  32350. false,
  32351. 0,
  32352. false
  32353. ];
  32354. };
  32355. CCITTFaxStream.prototype.getTwoDimCode = function ccittFaxStreamGetTwoDimCode() {
  32356. var code = 0;
  32357. var p;
  32358. if (this.eoblock) {
  32359. code = this.lookBits(7);
  32360. p = twoDimTable[code];
  32361. if (p && p[0] > 0) {
  32362. this.eatBits(p[0]);
  32363. return p[1];
  32364. }
  32365. } else {
  32366. var result = this.findTableCode(1, 7, twoDimTable);
  32367. if (result[0] && result[2]) {
  32368. return result[1];
  32369. }
  32370. }
  32371. info('Bad two dim code');
  32372. return ccittEOF;
  32373. };
  32374. CCITTFaxStream.prototype.getWhiteCode = function ccittFaxStreamGetWhiteCode() {
  32375. var code = 0;
  32376. var p;
  32377. if (this.eoblock) {
  32378. code = this.lookBits(12);
  32379. if (code === ccittEOF) {
  32380. return 1;
  32381. }
  32382. if (code >> 5 === 0) {
  32383. p = whiteTable1[code];
  32384. } else {
  32385. p = whiteTable2[code >> 3];
  32386. }
  32387. if (p[0] > 0) {
  32388. this.eatBits(p[0]);
  32389. return p[1];
  32390. }
  32391. } else {
  32392. var result = this.findTableCode(1, 9, whiteTable2);
  32393. if (result[0]) {
  32394. return result[1];
  32395. }
  32396. result = this.findTableCode(11, 12, whiteTable1);
  32397. if (result[0]) {
  32398. return result[1];
  32399. }
  32400. }
  32401. info('bad white code');
  32402. this.eatBits(1);
  32403. return 1;
  32404. };
  32405. CCITTFaxStream.prototype.getBlackCode = function ccittFaxStreamGetBlackCode() {
  32406. var code, p;
  32407. if (this.eoblock) {
  32408. code = this.lookBits(13);
  32409. if (code === ccittEOF) {
  32410. return 1;
  32411. }
  32412. if (code >> 7 === 0) {
  32413. p = blackTable1[code];
  32414. } else if (code >> 9 === 0 && code >> 7 !== 0) {
  32415. p = blackTable2[(code >> 1) - 64];
  32416. } else {
  32417. p = blackTable3[code >> 7];
  32418. }
  32419. if (p[0] > 0) {
  32420. this.eatBits(p[0]);
  32421. return p[1];
  32422. }
  32423. } else {
  32424. var result = this.findTableCode(2, 6, blackTable3);
  32425. if (result[0]) {
  32426. return result[1];
  32427. }
  32428. result = this.findTableCode(7, 12, blackTable2, 64);
  32429. if (result[0]) {
  32430. return result[1];
  32431. }
  32432. result = this.findTableCode(10, 13, blackTable1);
  32433. if (result[0]) {
  32434. return result[1];
  32435. }
  32436. }
  32437. info('bad black code');
  32438. this.eatBits(1);
  32439. return 1;
  32440. };
  32441. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  32442. var c;
  32443. while (this.inputBits < n) {
  32444. if ((c = this.str.getByte()) === -1) {
  32445. if (this.inputBits === 0) {
  32446. return ccittEOF;
  32447. }
  32448. return this.inputBuf << n - this.inputBits & 0xFFFF >> 16 - n;
  32449. }
  32450. this.inputBuf = this.inputBuf << 8 | c;
  32451. this.inputBits += 8;
  32452. }
  32453. return this.inputBuf >> this.inputBits - n & 0xFFFF >> 16 - n;
  32454. };
  32455. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  32456. if ((this.inputBits -= n) < 0) {
  32457. this.inputBits = 0;
  32458. }
  32459. };
  32460. return CCITTFaxStream;
  32461. }();
  32462. var LZWStream = function LZWStreamClosure() {
  32463. function LZWStream(str, maybeLength, earlyChange) {
  32464. this.str = str;
  32465. this.dict = str.dict;
  32466. this.cachedData = 0;
  32467. this.bitsCached = 0;
  32468. var maxLzwDictionarySize = 4096;
  32469. var lzwState = {
  32470. earlyChange: earlyChange,
  32471. codeLength: 9,
  32472. nextCode: 258,
  32473. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  32474. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  32475. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  32476. currentSequence: new Uint8Array(maxLzwDictionarySize),
  32477. currentSequenceLength: 0
  32478. };
  32479. for (var i = 0; i < 256; ++i) {
  32480. lzwState.dictionaryValues[i] = i;
  32481. lzwState.dictionaryLengths[i] = 1;
  32482. }
  32483. this.lzwState = lzwState;
  32484. DecodeStream.call(this, maybeLength);
  32485. }
  32486. LZWStream.prototype = Object.create(DecodeStream.prototype);
  32487. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  32488. var bitsCached = this.bitsCached;
  32489. var cachedData = this.cachedData;
  32490. while (bitsCached < n) {
  32491. var c = this.str.getByte();
  32492. if (c === -1) {
  32493. this.eof = true;
  32494. return null;
  32495. }
  32496. cachedData = cachedData << 8 | c;
  32497. bitsCached += 8;
  32498. }
  32499. this.bitsCached = bitsCached -= n;
  32500. this.cachedData = cachedData;
  32501. this.lastCode = null;
  32502. return cachedData >>> bitsCached & (1 << n) - 1;
  32503. };
  32504. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  32505. var blockSize = 512;
  32506. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  32507. var i, j, q;
  32508. var lzwState = this.lzwState;
  32509. if (!lzwState) {
  32510. return;
  32511. }
  32512. // eof was found
  32513. var earlyChange = lzwState.earlyChange;
  32514. var nextCode = lzwState.nextCode;
  32515. var dictionaryValues = lzwState.dictionaryValues;
  32516. var dictionaryLengths = lzwState.dictionaryLengths;
  32517. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  32518. var codeLength = lzwState.codeLength;
  32519. var prevCode = lzwState.prevCode;
  32520. var currentSequence = lzwState.currentSequence;
  32521. var currentSequenceLength = lzwState.currentSequenceLength;
  32522. var decodedLength = 0;
  32523. var currentBufferLength = this.bufferLength;
  32524. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  32525. for (i = 0; i < blockSize; i++) {
  32526. var code = this.readBits(codeLength);
  32527. var hasPrev = currentSequenceLength > 0;
  32528. if (code < 256) {
  32529. currentSequence[0] = code;
  32530. currentSequenceLength = 1;
  32531. } else if (code >= 258) {
  32532. if (code < nextCode) {
  32533. currentSequenceLength = dictionaryLengths[code];
  32534. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  32535. currentSequence[j] = dictionaryValues[q];
  32536. q = dictionaryPrevCodes[q];
  32537. }
  32538. } else {
  32539. currentSequence[currentSequenceLength++] = currentSequence[0];
  32540. }
  32541. } else if (code === 256) {
  32542. codeLength = 9;
  32543. nextCode = 258;
  32544. currentSequenceLength = 0;
  32545. continue;
  32546. } else {
  32547. this.eof = true;
  32548. delete this.lzwState;
  32549. break;
  32550. }
  32551. if (hasPrev) {
  32552. dictionaryPrevCodes[nextCode] = prevCode;
  32553. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  32554. dictionaryValues[nextCode] = currentSequence[0];
  32555. nextCode++;
  32556. codeLength = nextCode + earlyChange & nextCode + earlyChange - 1 ? codeLength : Math.min(Math.log(nextCode + earlyChange) / 0.6931471805599453 + 1, 12) | 0;
  32557. }
  32558. prevCode = code;
  32559. decodedLength += currentSequenceLength;
  32560. if (estimatedDecodedSize < decodedLength) {
  32561. do {
  32562. estimatedDecodedSize += decodedSizeDelta;
  32563. } while (estimatedDecodedSize < decodedLength);
  32564. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  32565. }
  32566. for (j = 0; j < currentSequenceLength; j++) {
  32567. buffer[currentBufferLength++] = currentSequence[j];
  32568. }
  32569. }
  32570. lzwState.nextCode = nextCode;
  32571. lzwState.codeLength = codeLength;
  32572. lzwState.prevCode = prevCode;
  32573. lzwState.currentSequenceLength = currentSequenceLength;
  32574. this.bufferLength = currentBufferLength;
  32575. };
  32576. return LZWStream;
  32577. }();
  32578. var NullStream = function NullStreamClosure() {
  32579. function NullStream() {
  32580. Stream.call(this, new Uint8Array(0));
  32581. }
  32582. NullStream.prototype = Stream.prototype;
  32583. return NullStream;
  32584. }();
  32585. exports.Ascii85Stream = Ascii85Stream;
  32586. exports.AsciiHexStream = AsciiHexStream;
  32587. exports.CCITTFaxStream = CCITTFaxStream;
  32588. exports.DecryptStream = DecryptStream;
  32589. exports.DecodeStream = DecodeStream;
  32590. exports.FlateStream = FlateStream;
  32591. exports.Jbig2Stream = Jbig2Stream;
  32592. exports.JpegStream = JpegStream;
  32593. exports.JpxStream = JpxStream;
  32594. exports.NullStream = NullStream;
  32595. exports.PredictorStream = PredictorStream;
  32596. exports.RunLengthStream = RunLengthStream;
  32597. exports.Stream = Stream;
  32598. exports.StreamsSequenceStream = StreamsSequenceStream;
  32599. exports.StringStream = StringStream;
  32600. exports.LZWStream = LZWStream;
  32601. }));
  32602. (function (root, factory) {
  32603. factory(root.pdfjsDisplayAnnotationLayer = {}, root.pdfjsSharedUtil, root.pdfjsDisplayDOMUtils);
  32604. }(this, function (exports, sharedUtil, displayDOMUtils) {
  32605. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  32606. var AnnotationType = sharedUtil.AnnotationType;
  32607. var Util = sharedUtil.Util;
  32608. var addLinkAttributes = displayDOMUtils.addLinkAttributes;
  32609. var LinkTarget = displayDOMUtils.LinkTarget;
  32610. var getFilenameFromUrl = displayDOMUtils.getFilenameFromUrl;
  32611. var warn = sharedUtil.warn;
  32612. var CustomStyle = displayDOMUtils.CustomStyle;
  32613. var getDefaultSetting = displayDOMUtils.getDefaultSetting;
  32614. /**
  32615. * @typedef {Object} AnnotationElementParameters
  32616. * @property {Object} data
  32617. * @property {HTMLDivElement} layer
  32618. * @property {PDFPage} page
  32619. * @property {PageViewport} viewport
  32620. * @property {IPDFLinkService} linkService
  32621. * @property {DownloadManager} downloadManager
  32622. * @property {string} imageResourcesPath
  32623. * @property {boolean} renderInteractiveForms
  32624. */
  32625. /**
  32626. * @class
  32627. * @alias AnnotationElementFactory
  32628. */
  32629. function AnnotationElementFactory() {
  32630. }
  32631. AnnotationElementFactory.prototype = /** @lends AnnotationElementFactory.prototype */
  32632. {
  32633. /**
  32634. * @param {AnnotationElementParameters} parameters
  32635. * @returns {AnnotationElement}
  32636. */
  32637. create: function AnnotationElementFactory_create(parameters) {
  32638. var subtype = parameters.data.annotationType;
  32639. switch (subtype) {
  32640. case AnnotationType.LINK:
  32641. return new LinkAnnotationElement(parameters);
  32642. case AnnotationType.TEXT:
  32643. return new TextAnnotationElement(parameters);
  32644. case AnnotationType.WIDGET:
  32645. var fieldType = parameters.data.fieldType;
  32646. switch (fieldType) {
  32647. case 'Tx':
  32648. return new TextWidgetAnnotationElement(parameters);
  32649. case 'Ch':
  32650. return new ChoiceWidgetAnnotationElement(parameters);
  32651. }
  32652. return new WidgetAnnotationElement(parameters);
  32653. case AnnotationType.POPUP:
  32654. return new PopupAnnotationElement(parameters);
  32655. case AnnotationType.HIGHLIGHT:
  32656. return new HighlightAnnotationElement(parameters);
  32657. case AnnotationType.UNDERLINE:
  32658. return new UnderlineAnnotationElement(parameters);
  32659. case AnnotationType.SQUIGGLY:
  32660. return new SquigglyAnnotationElement(parameters);
  32661. case AnnotationType.STRIKEOUT:
  32662. return new StrikeOutAnnotationElement(parameters);
  32663. case AnnotationType.FILEATTACHMENT:
  32664. return new FileAttachmentAnnotationElement(parameters);
  32665. default:
  32666. return new AnnotationElement(parameters);
  32667. }
  32668. }
  32669. };
  32670. /**
  32671. * @class
  32672. * @alias AnnotationElement
  32673. */
  32674. var AnnotationElement = function AnnotationElementClosure() {
  32675. function AnnotationElement(parameters, isRenderable) {
  32676. this.isRenderable = isRenderable || false;
  32677. this.data = parameters.data;
  32678. this.layer = parameters.layer;
  32679. this.page = parameters.page;
  32680. this.viewport = parameters.viewport;
  32681. this.linkService = parameters.linkService;
  32682. this.downloadManager = parameters.downloadManager;
  32683. this.imageResourcesPath = parameters.imageResourcesPath;
  32684. this.renderInteractiveForms = parameters.renderInteractiveForms;
  32685. if (isRenderable) {
  32686. this.container = this._createContainer();
  32687. }
  32688. }
  32689. AnnotationElement.prototype = /** @lends AnnotationElement.prototype */
  32690. {
  32691. /**
  32692. * Create an empty container for the annotation's HTML element.
  32693. *
  32694. * @private
  32695. * @memberof AnnotationElement
  32696. * @returns {HTMLSectionElement}
  32697. */
  32698. _createContainer: function AnnotationElement_createContainer() {
  32699. var data = this.data, page = this.page, viewport = this.viewport;
  32700. var container = document.createElement('section');
  32701. var width = data.rect[2] - data.rect[0];
  32702. var height = data.rect[3] - data.rect[1];
  32703. container.setAttribute('data-annotation-id', data.id);
  32704. // Do *not* modify `data.rect`, since that will corrupt the annotation
  32705. // position on subsequent calls to `_createContainer` (see issue 6804).
  32706. var rect = Util.normalizeRect([
  32707. data.rect[0],
  32708. page.view[3] - data.rect[1] + page.view[1],
  32709. data.rect[2],
  32710. page.view[3] - data.rect[3] + page.view[1]
  32711. ]);
  32712. CustomStyle.setProp('transform', container, 'matrix(' + viewport.transform.join(',') + ')');
  32713. CustomStyle.setProp('transformOrigin', container, -rect[0] + 'px ' + -rect[1] + 'px');
  32714. if (data.borderStyle.width > 0) {
  32715. container.style.borderWidth = data.borderStyle.width + 'px';
  32716. if (data.borderStyle.style !== AnnotationBorderStyleType.UNDERLINE) {
  32717. // Underline styles only have a bottom border, so we do not need
  32718. // to adjust for all borders. This yields a similar result as
  32719. // Adobe Acrobat/Reader.
  32720. width = width - 2 * data.borderStyle.width;
  32721. height = height - 2 * data.borderStyle.width;
  32722. }
  32723. var horizontalRadius = data.borderStyle.horizontalCornerRadius;
  32724. var verticalRadius = data.borderStyle.verticalCornerRadius;
  32725. if (horizontalRadius > 0 || verticalRadius > 0) {
  32726. var radius = horizontalRadius + 'px / ' + verticalRadius + 'px';
  32727. CustomStyle.setProp('borderRadius', container, radius);
  32728. }
  32729. switch (data.borderStyle.style) {
  32730. case AnnotationBorderStyleType.SOLID:
  32731. container.style.borderStyle = 'solid';
  32732. break;
  32733. case AnnotationBorderStyleType.DASHED:
  32734. container.style.borderStyle = 'dashed';
  32735. break;
  32736. case AnnotationBorderStyleType.BEVELED:
  32737. warn('Unimplemented border style: beveled');
  32738. break;
  32739. case AnnotationBorderStyleType.INSET:
  32740. warn('Unimplemented border style: inset');
  32741. break;
  32742. case AnnotationBorderStyleType.UNDERLINE:
  32743. container.style.borderBottomStyle = 'solid';
  32744. break;
  32745. default:
  32746. break;
  32747. }
  32748. if (data.color) {
  32749. container.style.borderColor = Util.makeCssRgb(data.color[0] | 0, data.color[1] | 0, data.color[2] | 0);
  32750. } else {
  32751. // Transparent (invisible) border, so do not draw it at all.
  32752. container.style.borderWidth = 0;
  32753. }
  32754. }
  32755. container.style.left = rect[0] + 'px';
  32756. container.style.top = rect[1] + 'px';
  32757. container.style.width = width + 'px';
  32758. container.style.height = height + 'px';
  32759. return container;
  32760. },
  32761. /**
  32762. * Create a popup for the annotation's HTML element. This is used for
  32763. * annotations that do not have a Popup entry in the dictionary, but
  32764. * are of a type that works with popups (such as Highlight annotations).
  32765. *
  32766. * @private
  32767. * @param {HTMLSectionElement} container
  32768. * @param {HTMLDivElement|HTMLImageElement|null} trigger
  32769. * @param {Object} data
  32770. * @memberof AnnotationElement
  32771. */
  32772. _createPopup: function AnnotationElement_createPopup(container, trigger, data) {
  32773. // If no trigger element is specified, create it.
  32774. if (!trigger) {
  32775. trigger = document.createElement('div');
  32776. trigger.style.height = container.style.height;
  32777. trigger.style.width = container.style.width;
  32778. container.appendChild(trigger);
  32779. }
  32780. var popupElement = new PopupElement({
  32781. container: container,
  32782. trigger: trigger,
  32783. color: data.color,
  32784. title: data.title,
  32785. contents: data.contents,
  32786. hideWrapper: true
  32787. });
  32788. var popup = popupElement.render();
  32789. // Position the popup next to the annotation's container.
  32790. popup.style.left = container.style.width;
  32791. container.appendChild(popup);
  32792. },
  32793. /**
  32794. * Render the annotation's HTML element in the empty container.
  32795. *
  32796. * @public
  32797. * @memberof AnnotationElement
  32798. */
  32799. render: function AnnotationElement_render() {
  32800. throw new Error('Abstract method AnnotationElement.render called');
  32801. }
  32802. };
  32803. return AnnotationElement;
  32804. }();
  32805. /**
  32806. * @class
  32807. * @alias LinkAnnotationElement
  32808. */
  32809. var LinkAnnotationElement = function LinkAnnotationElementClosure() {
  32810. function LinkAnnotationElement(parameters) {
  32811. AnnotationElement.call(this, parameters, true);
  32812. }
  32813. Util.inherit(LinkAnnotationElement, AnnotationElement, {
  32814. /**
  32815. * Render the link annotation's HTML element in the empty container.
  32816. *
  32817. * @public
  32818. * @memberof LinkAnnotationElement
  32819. * @returns {HTMLSectionElement}
  32820. */
  32821. render: function LinkAnnotationElement_render() {
  32822. this.container.className = 'linkAnnotation';
  32823. var link = document.createElement('a');
  32824. addLinkAttributes(link, {
  32825. url: this.data.url,
  32826. target: this.data.newWindow ? LinkTarget.BLANK : undefined
  32827. });
  32828. if (!this.data.url) {
  32829. if (this.data.action) {
  32830. this._bindNamedAction(link, this.data.action);
  32831. } else {
  32832. this._bindLink(link, this.data.dest || null);
  32833. }
  32834. }
  32835. this.container.appendChild(link);
  32836. return this.container;
  32837. },
  32838. /**
  32839. * Bind internal links to the link element.
  32840. *
  32841. * @private
  32842. * @param {Object} link
  32843. * @param {Object} destination
  32844. * @memberof LinkAnnotationElement
  32845. */
  32846. _bindLink: function LinkAnnotationElement_bindLink(link, destination) {
  32847. var self = this;
  32848. link.href = this.linkService.getDestinationHash(destination);
  32849. link.onclick = function () {
  32850. if (destination) {
  32851. self.linkService.navigateTo(destination);
  32852. }
  32853. return false;
  32854. };
  32855. if (destination) {
  32856. link.className = 'internalLink';
  32857. }
  32858. },
  32859. /**
  32860. * Bind named actions to the link element.
  32861. *
  32862. * @private
  32863. * @param {Object} link
  32864. * @param {Object} action
  32865. * @memberof LinkAnnotationElement
  32866. */
  32867. _bindNamedAction: function LinkAnnotationElement_bindNamedAction(link, action) {
  32868. var self = this;
  32869. link.href = this.linkService.getAnchorUrl('');
  32870. link.onclick = function () {
  32871. self.linkService.executeNamedAction(action);
  32872. return false;
  32873. };
  32874. link.className = 'internalLink';
  32875. }
  32876. });
  32877. return LinkAnnotationElement;
  32878. }();
  32879. /**
  32880. * @class
  32881. * @alias TextAnnotationElement
  32882. */
  32883. var TextAnnotationElement = function TextAnnotationElementClosure() {
  32884. function TextAnnotationElement(parameters) {
  32885. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  32886. AnnotationElement.call(this, parameters, isRenderable);
  32887. }
  32888. Util.inherit(TextAnnotationElement, AnnotationElement, {
  32889. /**
  32890. * Render the text annotation's HTML element in the empty container.
  32891. *
  32892. * @public
  32893. * @memberof TextAnnotationElement
  32894. * @returns {HTMLSectionElement}
  32895. */
  32896. render: function TextAnnotationElement_render() {
  32897. this.container.className = 'textAnnotation';
  32898. var image = document.createElement('img');
  32899. image.style.height = this.container.style.height;
  32900. image.style.width = this.container.style.width;
  32901. image.src = this.imageResourcesPath + 'annotation-' + this.data.name.toLowerCase() + '.svg';
  32902. image.alt = '[{{type}} Annotation]';
  32903. image.dataset.l10nId = 'text_annotation_type';
  32904. image.dataset.l10nArgs = JSON.stringify({ type: this.data.name });
  32905. if (!this.data.hasPopup) {
  32906. this._createPopup(this.container, image, this.data);
  32907. }
  32908. this.container.appendChild(image);
  32909. return this.container;
  32910. }
  32911. });
  32912. return TextAnnotationElement;
  32913. }();
  32914. /**
  32915. * @class
  32916. * @alias WidgetAnnotationElement
  32917. */
  32918. var WidgetAnnotationElement = function WidgetAnnotationElementClosure() {
  32919. function WidgetAnnotationElement(parameters, isRenderable) {
  32920. AnnotationElement.call(this, parameters, isRenderable);
  32921. }
  32922. Util.inherit(WidgetAnnotationElement, AnnotationElement, {
  32923. /**
  32924. * Render the widget annotation's HTML element in the empty container.
  32925. *
  32926. * @public
  32927. * @memberof WidgetAnnotationElement
  32928. * @returns {HTMLSectionElement}
  32929. */
  32930. render: function WidgetAnnotationElement_render() {
  32931. // Show only the container for unsupported field types.
  32932. return this.container;
  32933. }
  32934. });
  32935. return WidgetAnnotationElement;
  32936. }();
  32937. /**
  32938. * @class
  32939. * @alias TextWidgetAnnotationElement
  32940. */
  32941. var TextWidgetAnnotationElement = function TextWidgetAnnotationElementClosure() {
  32942. var TEXT_ALIGNMENT = [
  32943. 'left',
  32944. 'center',
  32945. 'right'
  32946. ];
  32947. function TextWidgetAnnotationElement(parameters) {
  32948. var isRenderable = parameters.renderInteractiveForms || !parameters.data.hasAppearance && !!parameters.data.fieldValue;
  32949. WidgetAnnotationElement.call(this, parameters, isRenderable);
  32950. }
  32951. Util.inherit(TextWidgetAnnotationElement, WidgetAnnotationElement, {
  32952. /**
  32953. * Render the text widget annotation's HTML element in the empty container.
  32954. *
  32955. * @public
  32956. * @memberof TextWidgetAnnotationElement
  32957. * @returns {HTMLSectionElement}
  32958. */
  32959. render: function TextWidgetAnnotationElement_render() {
  32960. this.container.className = 'textWidgetAnnotation';
  32961. var element = null;
  32962. if (this.renderInteractiveForms) {
  32963. // NOTE: We cannot set the values using `element.value` below, since it
  32964. // prevents the AnnotationLayer rasterizer in `test/driver.js`
  32965. // from parsing the elements correctly for the reference tests.
  32966. if (this.data.multiLine) {
  32967. element = document.createElement('textarea');
  32968. element.textContent = this.data.fieldValue;
  32969. } else {
  32970. element = document.createElement('input');
  32971. element.type = 'text';
  32972. element.setAttribute('value', this.data.fieldValue);
  32973. }
  32974. element.disabled = this.data.readOnly;
  32975. if (this.data.maxLen !== null) {
  32976. element.maxLength = this.data.maxLen;
  32977. }
  32978. if (this.data.comb) {
  32979. var fieldWidth = this.data.rect[2] - this.data.rect[0];
  32980. var combWidth = fieldWidth / this.data.maxLen;
  32981. element.classList.add('comb');
  32982. element.style.letterSpacing = 'calc(' + combWidth + 'px - 1ch)';
  32983. }
  32984. } else {
  32985. element = document.createElement('div');
  32986. element.textContent = this.data.fieldValue;
  32987. element.style.verticalAlign = 'middle';
  32988. element.style.display = 'table-cell';
  32989. var font = null;
  32990. if (this.data.fontRefName) {
  32991. font = this.page.commonObjs.getData(this.data.fontRefName);
  32992. }
  32993. this._setTextStyle(element, font);
  32994. }
  32995. if (this.data.textAlignment !== null) {
  32996. element.style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];
  32997. }
  32998. this.container.appendChild(element);
  32999. return this.container;
  33000. },
  33001. /**
  33002. * Apply text styles to the text in the element.
  33003. *
  33004. * @private
  33005. * @param {HTMLDivElement} element
  33006. * @param {Object} font
  33007. * @memberof TextWidgetAnnotationElement
  33008. */
  33009. _setTextStyle: function TextWidgetAnnotationElement_setTextStyle(element, font) {
  33010. // TODO: This duplicates some of the logic in CanvasGraphics.setFont().
  33011. var style = element.style;
  33012. style.fontSize = this.data.fontSize + 'px';
  33013. style.direction = this.data.fontDirection < 0 ? 'rtl' : 'ltr';
  33014. if (!font) {
  33015. return;
  33016. }
  33017. style.fontWeight = font.black ? font.bold ? '900' : 'bold' : font.bold ? 'bold' : 'normal';
  33018. style.fontStyle = font.italic ? 'italic' : 'normal';
  33019. // Use a reasonable default font if the font doesn't specify a fallback.
  33020. var fontFamily = font.loadedName ? '"' + font.loadedName + '", ' : '';
  33021. var fallbackName = font.fallbackName || 'Helvetica, sans-serif';
  33022. style.fontFamily = fontFamily + fallbackName;
  33023. }
  33024. });
  33025. return TextWidgetAnnotationElement;
  33026. }();
  33027. /**
  33028. * @class
  33029. * @alias ChoiceWidgetAnnotationElement
  33030. */
  33031. var ChoiceWidgetAnnotationElement = function ChoiceWidgetAnnotationElementClosure() {
  33032. function ChoiceWidgetAnnotationElement(parameters) {
  33033. WidgetAnnotationElement.call(this, parameters, parameters.renderInteractiveForms);
  33034. }
  33035. Util.inherit(ChoiceWidgetAnnotationElement, WidgetAnnotationElement, {
  33036. /**
  33037. * Render the choice widget annotation's HTML element in the empty
  33038. * container.
  33039. *
  33040. * @public
  33041. * @memberof ChoiceWidgetAnnotationElement
  33042. * @returns {HTMLSectionElement}
  33043. */
  33044. render: function ChoiceWidgetAnnotationElement_render() {
  33045. this.container.className = 'choiceWidgetAnnotation';
  33046. var selectElement = document.createElement('select');
  33047. selectElement.disabled = this.data.readOnly;
  33048. if (!this.data.combo) {
  33049. // List boxes have a size and (optionally) multiple selection.
  33050. selectElement.size = this.data.options.length;
  33051. if (this.data.multiSelect) {
  33052. selectElement.multiple = true;
  33053. }
  33054. }
  33055. // Insert the options into the choice field.
  33056. for (var i = 0, ii = this.data.options.length; i < ii; i++) {
  33057. var option = this.data.options[i];
  33058. var optionElement = document.createElement('option');
  33059. optionElement.textContent = option.displayValue;
  33060. optionElement.value = option.exportValue;
  33061. if (this.data.fieldValue.indexOf(option.displayValue) >= 0) {
  33062. optionElement.setAttribute('selected', true);
  33063. }
  33064. selectElement.appendChild(optionElement);
  33065. }
  33066. this.container.appendChild(selectElement);
  33067. return this.container;
  33068. }
  33069. });
  33070. return ChoiceWidgetAnnotationElement;
  33071. }();
  33072. /**
  33073. * @class
  33074. * @alias PopupAnnotationElement
  33075. */
  33076. var PopupAnnotationElement = function PopupAnnotationElementClosure() {
  33077. function PopupAnnotationElement(parameters) {
  33078. var isRenderable = !!(parameters.data.title || parameters.data.contents);
  33079. AnnotationElement.call(this, parameters, isRenderable);
  33080. }
  33081. Util.inherit(PopupAnnotationElement, AnnotationElement, {
  33082. /**
  33083. * Render the popup annotation's HTML element in the empty container.
  33084. *
  33085. * @public
  33086. * @memberof PopupAnnotationElement
  33087. * @returns {HTMLSectionElement}
  33088. */
  33089. render: function PopupAnnotationElement_render() {
  33090. this.container.className = 'popupAnnotation';
  33091. var selector = '[data-annotation-id="' + this.data.parentId + '"]';
  33092. var parentElement = this.layer.querySelector(selector);
  33093. if (!parentElement) {
  33094. return this.container;
  33095. }
  33096. var popup = new PopupElement({
  33097. container: this.container,
  33098. trigger: parentElement,
  33099. color: this.data.color,
  33100. title: this.data.title,
  33101. contents: this.data.contents
  33102. });
  33103. // Position the popup next to the parent annotation's container.
  33104. // PDF viewers ignore a popup annotation's rectangle.
  33105. var parentLeft = parseFloat(parentElement.style.left);
  33106. var parentWidth = parseFloat(parentElement.style.width);
  33107. CustomStyle.setProp('transformOrigin', this.container, -(parentLeft + parentWidth) + 'px -' + parentElement.style.top);
  33108. this.container.style.left = parentLeft + parentWidth + 'px';
  33109. this.container.appendChild(popup.render());
  33110. return this.container;
  33111. }
  33112. });
  33113. return PopupAnnotationElement;
  33114. }();
  33115. /**
  33116. * @class
  33117. * @alias PopupElement
  33118. */
  33119. var PopupElement = function PopupElementClosure() {
  33120. var BACKGROUND_ENLIGHT = 0.7;
  33121. function PopupElement(parameters) {
  33122. this.container = parameters.container;
  33123. this.trigger = parameters.trigger;
  33124. this.color = parameters.color;
  33125. this.title = parameters.title;
  33126. this.contents = parameters.contents;
  33127. this.hideWrapper = parameters.hideWrapper || false;
  33128. this.pinned = false;
  33129. }
  33130. PopupElement.prototype = /** @lends PopupElement.prototype */
  33131. {
  33132. /**
  33133. * Render the popup's HTML element.
  33134. *
  33135. * @public
  33136. * @memberof PopupElement
  33137. * @returns {HTMLSectionElement}
  33138. */
  33139. render: function PopupElement_render() {
  33140. var wrapper = document.createElement('div');
  33141. wrapper.className = 'popupWrapper';
  33142. // For Popup annotations we hide the entire section because it contains
  33143. // only the popup. However, for Text annotations without a separate Popup
  33144. // annotation, we cannot hide the entire container as the image would
  33145. // disappear too. In that special case, hiding the wrapper suffices.
  33146. this.hideElement = this.hideWrapper ? wrapper : this.container;
  33147. this.hideElement.setAttribute('hidden', true);
  33148. var popup = document.createElement('div');
  33149. popup.className = 'popup';
  33150. var color = this.color;
  33151. if (color) {
  33152. // Enlighten the color.
  33153. var r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
  33154. var g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
  33155. var b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
  33156. popup.style.backgroundColor = Util.makeCssRgb(r | 0, g | 0, b | 0);
  33157. }
  33158. var contents = this._formatContents(this.contents);
  33159. var title = document.createElement('h1');
  33160. title.textContent = this.title;
  33161. // Attach the event listeners to the trigger element.
  33162. this.trigger.addEventListener('click', this._toggle.bind(this));
  33163. this.trigger.addEventListener('mouseover', this._show.bind(this, false));
  33164. this.trigger.addEventListener('mouseout', this._hide.bind(this, false));
  33165. popup.addEventListener('click', this._hide.bind(this, true));
  33166. popup.appendChild(title);
  33167. popup.appendChild(contents);
  33168. wrapper.appendChild(popup);
  33169. return wrapper;
  33170. },
  33171. /**
  33172. * Format the contents of the popup by adding newlines where necessary.
  33173. *
  33174. * @private
  33175. * @param {string} contents
  33176. * @memberof PopupElement
  33177. * @returns {HTMLParagraphElement}
  33178. */
  33179. _formatContents: function PopupElement_formatContents(contents) {
  33180. var p = document.createElement('p');
  33181. var lines = contents.split(/(?:\r\n?|\n)/);
  33182. for (var i = 0, ii = lines.length; i < ii; ++i) {
  33183. var line = lines[i];
  33184. p.appendChild(document.createTextNode(line));
  33185. if (i < ii - 1) {
  33186. p.appendChild(document.createElement('br'));
  33187. }
  33188. }
  33189. return p;
  33190. },
  33191. /**
  33192. * Toggle the visibility of the popup.
  33193. *
  33194. * @private
  33195. * @memberof PopupElement
  33196. */
  33197. _toggle: function PopupElement_toggle() {
  33198. if (this.pinned) {
  33199. this._hide(true);
  33200. } else {
  33201. this._show(true);
  33202. }
  33203. },
  33204. /**
  33205. * Show the popup.
  33206. *
  33207. * @private
  33208. * @param {boolean} pin
  33209. * @memberof PopupElement
  33210. */
  33211. _show: function PopupElement_show(pin) {
  33212. if (pin) {
  33213. this.pinned = true;
  33214. }
  33215. if (this.hideElement.hasAttribute('hidden')) {
  33216. this.hideElement.removeAttribute('hidden');
  33217. this.container.style.zIndex += 1;
  33218. }
  33219. },
  33220. /**
  33221. * Hide the popup.
  33222. *
  33223. * @private
  33224. * @param {boolean} unpin
  33225. * @memberof PopupElement
  33226. */
  33227. _hide: function PopupElement_hide(unpin) {
  33228. if (unpin) {
  33229. this.pinned = false;
  33230. }
  33231. if (!this.hideElement.hasAttribute('hidden') && !this.pinned) {
  33232. this.hideElement.setAttribute('hidden', true);
  33233. this.container.style.zIndex -= 1;
  33234. }
  33235. }
  33236. };
  33237. return PopupElement;
  33238. }();
  33239. /**
  33240. * @class
  33241. * @alias HighlightAnnotationElement
  33242. */
  33243. var HighlightAnnotationElement = function HighlightAnnotationElementClosure() {
  33244. function HighlightAnnotationElement(parameters) {
  33245. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  33246. AnnotationElement.call(this, parameters, isRenderable);
  33247. }
  33248. Util.inherit(HighlightAnnotationElement, AnnotationElement, {
  33249. /**
  33250. * Render the highlight annotation's HTML element in the empty container.
  33251. *
  33252. * @public
  33253. * @memberof HighlightAnnotationElement
  33254. * @returns {HTMLSectionElement}
  33255. */
  33256. render: function HighlightAnnotationElement_render() {
  33257. this.container.className = 'highlightAnnotation';
  33258. if (!this.data.hasPopup) {
  33259. this._createPopup(this.container, null, this.data);
  33260. }
  33261. return this.container;
  33262. }
  33263. });
  33264. return HighlightAnnotationElement;
  33265. }();
  33266. /**
  33267. * @class
  33268. * @alias UnderlineAnnotationElement
  33269. */
  33270. var UnderlineAnnotationElement = function UnderlineAnnotationElementClosure() {
  33271. function UnderlineAnnotationElement(parameters) {
  33272. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  33273. AnnotationElement.call(this, parameters, isRenderable);
  33274. }
  33275. Util.inherit(UnderlineAnnotationElement, AnnotationElement, {
  33276. /**
  33277. * Render the underline annotation's HTML element in the empty container.
  33278. *
  33279. * @public
  33280. * @memberof UnderlineAnnotationElement
  33281. * @returns {HTMLSectionElement}
  33282. */
  33283. render: function UnderlineAnnotationElement_render() {
  33284. this.container.className = 'underlineAnnotation';
  33285. if (!this.data.hasPopup) {
  33286. this._createPopup(this.container, null, this.data);
  33287. }
  33288. return this.container;
  33289. }
  33290. });
  33291. return UnderlineAnnotationElement;
  33292. }();
  33293. /**
  33294. * @class
  33295. * @alias SquigglyAnnotationElement
  33296. */
  33297. var SquigglyAnnotationElement = function SquigglyAnnotationElementClosure() {
  33298. function SquigglyAnnotationElement(parameters) {
  33299. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  33300. AnnotationElement.call(this, parameters, isRenderable);
  33301. }
  33302. Util.inherit(SquigglyAnnotationElement, AnnotationElement, {
  33303. /**
  33304. * Render the squiggly annotation's HTML element in the empty container.
  33305. *
  33306. * @public
  33307. * @memberof SquigglyAnnotationElement
  33308. * @returns {HTMLSectionElement}
  33309. */
  33310. render: function SquigglyAnnotationElement_render() {
  33311. this.container.className = 'squigglyAnnotation';
  33312. if (!this.data.hasPopup) {
  33313. this._createPopup(this.container, null, this.data);
  33314. }
  33315. return this.container;
  33316. }
  33317. });
  33318. return SquigglyAnnotationElement;
  33319. }();
  33320. /**
  33321. * @class
  33322. * @alias StrikeOutAnnotationElement
  33323. */
  33324. var StrikeOutAnnotationElement = function StrikeOutAnnotationElementClosure() {
  33325. function StrikeOutAnnotationElement(parameters) {
  33326. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  33327. AnnotationElement.call(this, parameters, isRenderable);
  33328. }
  33329. Util.inherit(StrikeOutAnnotationElement, AnnotationElement, {
  33330. /**
  33331. * Render the strikeout annotation's HTML element in the empty container.
  33332. *
  33333. * @public
  33334. * @memberof StrikeOutAnnotationElement
  33335. * @returns {HTMLSectionElement}
  33336. */
  33337. render: function StrikeOutAnnotationElement_render() {
  33338. this.container.className = 'strikeoutAnnotation';
  33339. if (!this.data.hasPopup) {
  33340. this._createPopup(this.container, null, this.data);
  33341. }
  33342. return this.container;
  33343. }
  33344. });
  33345. return StrikeOutAnnotationElement;
  33346. }();
  33347. /**
  33348. * @class
  33349. * @alias FileAttachmentAnnotationElement
  33350. */
  33351. var FileAttachmentAnnotationElement = function FileAttachmentAnnotationElementClosure() {
  33352. function FileAttachmentAnnotationElement(parameters) {
  33353. AnnotationElement.call(this, parameters, true);
  33354. this.filename = getFilenameFromUrl(parameters.data.file.filename);
  33355. this.content = parameters.data.file.content;
  33356. }
  33357. Util.inherit(FileAttachmentAnnotationElement, AnnotationElement, {
  33358. /**
  33359. * Render the file attachment annotation's HTML element in the empty
  33360. * container.
  33361. *
  33362. * @public
  33363. * @memberof FileAttachmentAnnotationElement
  33364. * @returns {HTMLSectionElement}
  33365. */
  33366. render: function FileAttachmentAnnotationElement_render() {
  33367. this.container.className = 'fileAttachmentAnnotation';
  33368. var trigger = document.createElement('div');
  33369. trigger.style.height = this.container.style.height;
  33370. trigger.style.width = this.container.style.width;
  33371. trigger.addEventListener('dblclick', this._download.bind(this));
  33372. if (!this.data.hasPopup && (this.data.title || this.data.contents)) {
  33373. this._createPopup(this.container, trigger, this.data);
  33374. }
  33375. this.container.appendChild(trigger);
  33376. return this.container;
  33377. },
  33378. /**
  33379. * Download the file attachment associated with this annotation.
  33380. *
  33381. * @private
  33382. * @memberof FileAttachmentAnnotationElement
  33383. */
  33384. _download: function FileAttachmentAnnotationElement_download() {
  33385. if (!this.downloadManager) {
  33386. warn('Download cannot be started due to unavailable download manager');
  33387. return;
  33388. }
  33389. this.downloadManager.downloadData(this.content, this.filename, '');
  33390. }
  33391. });
  33392. return FileAttachmentAnnotationElement;
  33393. }();
  33394. /**
  33395. * @typedef {Object} AnnotationLayerParameters
  33396. * @property {PageViewport} viewport
  33397. * @property {HTMLDivElement} div
  33398. * @property {Array} annotations
  33399. * @property {PDFPage} page
  33400. * @property {IPDFLinkService} linkService
  33401. * @property {string} imageResourcesPath
  33402. * @property {boolean} renderInteractiveForms
  33403. */
  33404. /**
  33405. * @class
  33406. * @alias AnnotationLayer
  33407. */
  33408. var AnnotationLayer = function AnnotationLayerClosure() {
  33409. return {
  33410. /**
  33411. * Render a new annotation layer with all annotation elements.
  33412. *
  33413. * @public
  33414. * @param {AnnotationLayerParameters} parameters
  33415. * @memberof AnnotationLayer
  33416. */
  33417. render: function AnnotationLayer_render(parameters) {
  33418. var annotationElementFactory = new AnnotationElementFactory();
  33419. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  33420. var data = parameters.annotations[i];
  33421. if (!data) {
  33422. continue;
  33423. }
  33424. var properties = {
  33425. data: data,
  33426. layer: parameters.div,
  33427. page: parameters.page,
  33428. viewport: parameters.viewport,
  33429. linkService: parameters.linkService,
  33430. downloadManager: parameters.downloadManager,
  33431. imageResourcesPath: parameters.imageResourcesPath || getDefaultSetting('imageResourcesPath'),
  33432. renderInteractiveForms: parameters.renderInteractiveForms || false
  33433. };
  33434. var element = annotationElementFactory.create(properties);
  33435. if (element.isRenderable) {
  33436. parameters.div.appendChild(element.render());
  33437. }
  33438. }
  33439. },
  33440. /**
  33441. * Update the annotation elements on existing annotation layer.
  33442. *
  33443. * @public
  33444. * @param {AnnotationLayerParameters} parameters
  33445. * @memberof AnnotationLayer
  33446. */
  33447. update: function AnnotationLayer_update(parameters) {
  33448. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  33449. var data = parameters.annotations[i];
  33450. var element = parameters.div.querySelector('[data-annotation-id="' + data.id + '"]');
  33451. if (element) {
  33452. CustomStyle.setProp('transform', element, 'matrix(' + parameters.viewport.transform.join(',') + ')');
  33453. }
  33454. }
  33455. parameters.div.removeAttribute('hidden');
  33456. }
  33457. };
  33458. }();
  33459. exports.AnnotationLayer = AnnotationLayer;
  33460. }));
  33461. (function (root, factory) {
  33462. factory(root.pdfjsDisplayTextLayer = {}, root.pdfjsSharedUtil, root.pdfjsDisplayDOMUtils);
  33463. }(this, function (exports, sharedUtil, displayDOMUtils) {
  33464. var Util = sharedUtil.Util;
  33465. var createPromiseCapability = sharedUtil.createPromiseCapability;
  33466. var CustomStyle = displayDOMUtils.CustomStyle;
  33467. var getDefaultSetting = displayDOMUtils.getDefaultSetting;
  33468. /**
  33469. * Text layer render parameters.
  33470. *
  33471. * @typedef {Object} TextLayerRenderParameters
  33472. * @property {TextContent} textContent - Text content to render (the object is
  33473. * returned by the page's getTextContent() method).
  33474. * @property {HTMLElement} container - HTML element that will contain text runs.
  33475. * @property {PageViewport} viewport - The target viewport to properly
  33476. * layout the text runs.
  33477. * @property {Array} textDivs - (optional) HTML elements that are correspond
  33478. * the text items of the textContent input. This is output and shall be
  33479. * initially be set to empty array.
  33480. * @property {number} timeout - (optional) Delay in milliseconds before
  33481. * rendering of the text runs occurs.
  33482. * @property {boolean} enhanceTextSelection - (optional) Whether to turn on the
  33483. * text selection enhancement.
  33484. */
  33485. var renderTextLayer = function renderTextLayerClosure() {
  33486. var MAX_TEXT_DIVS_TO_RENDER = 100000;
  33487. var NonWhitespaceRegexp = /\S/;
  33488. function isAllWhitespace(str) {
  33489. return !NonWhitespaceRegexp.test(str);
  33490. }
  33491. // Text layers may contain many thousand div's, and using `styleBuf` avoids
  33492. // creating many intermediate strings when building their 'style' properties.
  33493. var styleBuf = [
  33494. 'left: ',
  33495. 0,
  33496. 'px; top: ',
  33497. 0,
  33498. 'px; font-size: ',
  33499. 0,
  33500. 'px; font-family: ',
  33501. '',
  33502. ';'
  33503. ];
  33504. function appendText(task, geom, styles) {
  33505. // Initialize all used properties to keep the caches monomorphic.
  33506. var textDiv = document.createElement('div');
  33507. var textDivProperties = {
  33508. style: null,
  33509. angle: 0,
  33510. canvasWidth: 0,
  33511. isWhitespace: false,
  33512. originalTransform: null,
  33513. paddingBottom: 0,
  33514. paddingLeft: 0,
  33515. paddingRight: 0,
  33516. paddingTop: 0,
  33517. scale: 1
  33518. };
  33519. task._textDivs.push(textDiv);
  33520. if (isAllWhitespace(geom.str)) {
  33521. textDivProperties.isWhitespace = true;
  33522. task._textDivProperties.set(textDiv, textDivProperties);
  33523. return;
  33524. }
  33525. var tx = Util.transform(task._viewport.transform, geom.transform);
  33526. var angle = Math.atan2(tx[1], tx[0]);
  33527. var style = styles[geom.fontName];
  33528. if (style.vertical) {
  33529. angle += Math.PI / 2;
  33530. }
  33531. var fontHeight = Math.sqrt(tx[2] * tx[2] + tx[3] * tx[3]);
  33532. var fontAscent = fontHeight;
  33533. if (style.ascent) {
  33534. fontAscent = style.ascent * fontAscent;
  33535. } else if (style.descent) {
  33536. fontAscent = (1 + style.descent) * fontAscent;
  33537. }
  33538. var left;
  33539. var top;
  33540. if (angle === 0) {
  33541. left = tx[4];
  33542. top = tx[5] - fontAscent;
  33543. } else {
  33544. left = tx[4] + fontAscent * Math.sin(angle);
  33545. top = tx[5] - fontAscent * Math.cos(angle);
  33546. }
  33547. styleBuf[1] = left;
  33548. styleBuf[3] = top;
  33549. styleBuf[5] = fontHeight;
  33550. styleBuf[7] = style.fontFamily;
  33551. textDivProperties.style = styleBuf.join('');
  33552. textDiv.setAttribute('style', textDivProperties.style);
  33553. textDiv.textContent = geom.str;
  33554. // |fontName| is only used by the Font Inspector. This test will succeed
  33555. // when e.g. the Font Inspector is off but the Stepper is on, but it's
  33556. // not worth the effort to do a more accurate test. We only use `dataset`
  33557. // here to make the font name available for the debugger.
  33558. if (getDefaultSetting('pdfBug')) {
  33559. textDiv.dataset.fontName = geom.fontName;
  33560. }
  33561. if (angle !== 0) {
  33562. textDivProperties.angle = angle * (180 / Math.PI);
  33563. }
  33564. // We don't bother scaling single-char text divs, because it has very
  33565. // little effect on text highlighting. This makes scrolling on docs with
  33566. // lots of such divs a lot faster.
  33567. if (geom.str.length > 1) {
  33568. if (style.vertical) {
  33569. textDivProperties.canvasWidth = geom.height * task._viewport.scale;
  33570. } else {
  33571. textDivProperties.canvasWidth = geom.width * task._viewport.scale;
  33572. }
  33573. }
  33574. task._textDivProperties.set(textDiv, textDivProperties);
  33575. if (task._enhanceTextSelection) {
  33576. var angleCos = 1, angleSin = 0;
  33577. if (angle !== 0) {
  33578. angleCos = Math.cos(angle);
  33579. angleSin = Math.sin(angle);
  33580. }
  33581. var divWidth = (style.vertical ? geom.height : geom.width) * task._viewport.scale;
  33582. var divHeight = fontHeight;
  33583. var m, b;
  33584. if (angle !== 0) {
  33585. m = [
  33586. angleCos,
  33587. angleSin,
  33588. -angleSin,
  33589. angleCos,
  33590. left,
  33591. top
  33592. ];
  33593. b = Util.getAxialAlignedBoundingBox([
  33594. 0,
  33595. 0,
  33596. divWidth,
  33597. divHeight
  33598. ], m);
  33599. } else {
  33600. b = [
  33601. left,
  33602. top,
  33603. left + divWidth,
  33604. top + divHeight
  33605. ];
  33606. }
  33607. task._bounds.push({
  33608. left: b[0],
  33609. top: b[1],
  33610. right: b[2],
  33611. bottom: b[3],
  33612. div: textDiv,
  33613. size: [
  33614. divWidth,
  33615. divHeight
  33616. ],
  33617. m: m
  33618. });
  33619. }
  33620. }
  33621. function render(task) {
  33622. if (task._canceled) {
  33623. return;
  33624. }
  33625. var textLayerFrag = task._container;
  33626. var textDivs = task._textDivs;
  33627. var capability = task._capability;
  33628. var textDivsLength = textDivs.length;
  33629. // No point in rendering many divs as it would make the browser
  33630. // unusable even after the divs are rendered.
  33631. if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
  33632. task._renderingDone = true;
  33633. capability.resolve();
  33634. return;
  33635. }
  33636. var canvas = document.createElement('canvas');
  33637. var ctx = canvas.getContext('2d', { alpha: false });
  33638. var lastFontSize;
  33639. var lastFontFamily;
  33640. for (var i = 0; i < textDivsLength; i++) {
  33641. var textDiv = textDivs[i];
  33642. var textDivProperties = task._textDivProperties.get(textDiv);
  33643. if (textDivProperties.isWhitespace) {
  33644. continue;
  33645. }
  33646. var fontSize = textDiv.style.fontSize;
  33647. var fontFamily = textDiv.style.fontFamily;
  33648. // Only build font string and set to context if different from last.
  33649. if (fontSize !== lastFontSize || fontFamily !== lastFontFamily) {
  33650. ctx.font = fontSize + ' ' + fontFamily;
  33651. lastFontSize = fontSize;
  33652. lastFontFamily = fontFamily;
  33653. }
  33654. var width = ctx.measureText(textDiv.textContent).width;
  33655. textLayerFrag.appendChild(textDiv);
  33656. var transform = '';
  33657. if (textDivProperties.canvasWidth !== 0 && width > 0) {
  33658. textDivProperties.scale = textDivProperties.canvasWidth / width;
  33659. transform = 'scaleX(' + textDivProperties.scale + ')';
  33660. }
  33661. if (textDivProperties.angle !== 0) {
  33662. transform = 'rotate(' + textDivProperties.angle + 'deg) ' + transform;
  33663. }
  33664. if (transform !== '') {
  33665. textDivProperties.originalTransform = transform;
  33666. CustomStyle.setProp('transform', textDiv, transform);
  33667. }
  33668. task._textDivProperties.set(textDiv, textDivProperties);
  33669. }
  33670. task._renderingDone = true;
  33671. capability.resolve();
  33672. }
  33673. function expand(task) {
  33674. var bounds = task._bounds;
  33675. var viewport = task._viewport;
  33676. var expanded = expandBounds(viewport.width, viewport.height, bounds);
  33677. for (var i = 0; i < expanded.length; i++) {
  33678. var div = bounds[i].div;
  33679. var divProperties = task._textDivProperties.get(div);
  33680. if (divProperties.angle === 0) {
  33681. divProperties.paddingLeft = bounds[i].left - expanded[i].left;
  33682. divProperties.paddingTop = bounds[i].top - expanded[i].top;
  33683. divProperties.paddingRight = expanded[i].right - bounds[i].right;
  33684. divProperties.paddingBottom = expanded[i].bottom - bounds[i].bottom;
  33685. task._textDivProperties.set(div, divProperties);
  33686. continue;
  33687. }
  33688. // Box is rotated -- trying to find padding so rotated div will not
  33689. // exceed its expanded bounds.
  33690. var e = expanded[i], b = bounds[i];
  33691. var m = b.m, c = m[0], s = m[1];
  33692. // Finding intersections with expanded box.
  33693. var points = [
  33694. [
  33695. 0,
  33696. 0
  33697. ],
  33698. [
  33699. 0,
  33700. b.size[1]
  33701. ],
  33702. [
  33703. b.size[0],
  33704. 0
  33705. ],
  33706. b.size
  33707. ];
  33708. var ts = new Float64Array(64);
  33709. points.forEach(function (p, i) {
  33710. var t = Util.applyTransform(p, m);
  33711. ts[i + 0] = c && (e.left - t[0]) / c;
  33712. ts[i + 4] = s && (e.top - t[1]) / s;
  33713. ts[i + 8] = c && (e.right - t[0]) / c;
  33714. ts[i + 12] = s && (e.bottom - t[1]) / s;
  33715. ts[i + 16] = s && (e.left - t[0]) / -s;
  33716. ts[i + 20] = c && (e.top - t[1]) / c;
  33717. ts[i + 24] = s && (e.right - t[0]) / -s;
  33718. ts[i + 28] = c && (e.bottom - t[1]) / c;
  33719. ts[i + 32] = c && (e.left - t[0]) / -c;
  33720. ts[i + 36] = s && (e.top - t[1]) / -s;
  33721. ts[i + 40] = c && (e.right - t[0]) / -c;
  33722. ts[i + 44] = s && (e.bottom - t[1]) / -s;
  33723. ts[i + 48] = s && (e.left - t[0]) / s;
  33724. ts[i + 52] = c && (e.top - t[1]) / -c;
  33725. ts[i + 56] = s && (e.right - t[0]) / s;
  33726. ts[i + 60] = c && (e.bottom - t[1]) / -c;
  33727. });
  33728. var findPositiveMin = function (ts, offset, count) {
  33729. var result = 0;
  33730. for (var i = 0; i < count; i++) {
  33731. var t = ts[offset++];
  33732. if (t > 0) {
  33733. result = result ? Math.min(t, result) : t;
  33734. }
  33735. }
  33736. return result;
  33737. };
  33738. // Not based on math, but to simplify calculations, using cos and sin
  33739. // absolute values to not exceed the box (it can but insignificantly).
  33740. var boxScale = 1 + Math.min(Math.abs(c), Math.abs(s));
  33741. divProperties.paddingLeft = findPositiveMin(ts, 32, 16) / boxScale;
  33742. divProperties.paddingTop = findPositiveMin(ts, 48, 16) / boxScale;
  33743. divProperties.paddingRight = findPositiveMin(ts, 0, 16) / boxScale;
  33744. divProperties.paddingBottom = findPositiveMin(ts, 16, 16) / boxScale;
  33745. task._textDivProperties.set(div, divProperties);
  33746. }
  33747. }
  33748. function expandBounds(width, height, boxes) {
  33749. var bounds = boxes.map(function (box, i) {
  33750. return {
  33751. x1: box.left,
  33752. y1: box.top,
  33753. x2: box.right,
  33754. y2: box.bottom,
  33755. index: i,
  33756. x1New: undefined,
  33757. x2New: undefined
  33758. };
  33759. });
  33760. expandBoundsLTR(width, bounds);
  33761. var expanded = new Array(boxes.length);
  33762. bounds.forEach(function (b) {
  33763. var i = b.index;
  33764. expanded[i] = {
  33765. left: b.x1New,
  33766. top: 0,
  33767. right: b.x2New,
  33768. bottom: 0
  33769. };
  33770. });
  33771. // Rotating on 90 degrees and extending extended boxes. Reusing the bounds
  33772. // array and objects.
  33773. boxes.map(function (box, i) {
  33774. var e = expanded[i], b = bounds[i];
  33775. b.x1 = box.top;
  33776. b.y1 = width - e.right;
  33777. b.x2 = box.bottom;
  33778. b.y2 = width - e.left;
  33779. b.index = i;
  33780. b.x1New = undefined;
  33781. b.x2New = undefined;
  33782. });
  33783. expandBoundsLTR(height, bounds);
  33784. bounds.forEach(function (b) {
  33785. var i = b.index;
  33786. expanded[i].top = b.x1New;
  33787. expanded[i].bottom = b.x2New;
  33788. });
  33789. return expanded;
  33790. }
  33791. function expandBoundsLTR(width, bounds) {
  33792. // Sorting by x1 coordinate and walk by the bounds in the same order.
  33793. bounds.sort(function (a, b) {
  33794. return a.x1 - b.x1 || a.index - b.index;
  33795. });
  33796. // First we see on the horizon is a fake boundary.
  33797. var fakeBoundary = {
  33798. x1: -Infinity,
  33799. y1: -Infinity,
  33800. x2: 0,
  33801. y2: Infinity,
  33802. index: -1,
  33803. x1New: 0,
  33804. x2New: 0
  33805. };
  33806. var horizon = [{
  33807. start: -Infinity,
  33808. end: Infinity,
  33809. boundary: fakeBoundary
  33810. }];
  33811. bounds.forEach(function (boundary) {
  33812. // Searching for the affected part of horizon.
  33813. // TODO red-black tree or simple binary search
  33814. var i = 0;
  33815. while (i < horizon.length && horizon[i].end <= boundary.y1) {
  33816. i++;
  33817. }
  33818. var j = horizon.length - 1;
  33819. while (j >= 0 && horizon[j].start >= boundary.y2) {
  33820. j--;
  33821. }
  33822. var horizonPart, affectedBoundary;
  33823. var q, k, maxXNew = -Infinity;
  33824. for (q = i; q <= j; q++) {
  33825. horizonPart = horizon[q];
  33826. affectedBoundary = horizonPart.boundary;
  33827. var xNew;
  33828. if (affectedBoundary.x2 > boundary.x1) {
  33829. // In the middle of the previous element, new x shall be at the
  33830. // boundary start. Extending if further if the affected bondary
  33831. // placed on top of the current one.
  33832. xNew = affectedBoundary.index > boundary.index ? affectedBoundary.x1New : boundary.x1;
  33833. } else if (affectedBoundary.x2New === undefined) {
  33834. // We have some space in between, new x in middle will be a fair
  33835. // choice.
  33836. xNew = (affectedBoundary.x2 + boundary.x1) / 2;
  33837. } else {
  33838. // Affected boundary has x2new set, using it as new x.
  33839. xNew = affectedBoundary.x2New;
  33840. }
  33841. if (xNew > maxXNew) {
  33842. maxXNew = xNew;
  33843. }
  33844. }
  33845. // Set new x1 for current boundary.
  33846. boundary.x1New = maxXNew;
  33847. // Adjusts new x2 for the affected boundaries.
  33848. for (q = i; q <= j; q++) {
  33849. horizonPart = horizon[q];
  33850. affectedBoundary = horizonPart.boundary;
  33851. if (affectedBoundary.x2New === undefined) {
  33852. // Was not set yet, choosing new x if possible.
  33853. if (affectedBoundary.x2 > boundary.x1) {
  33854. // Current and affected boundaries intersect. If affected boundary
  33855. // is placed on top of the current, shrinking the affected.
  33856. if (affectedBoundary.index > boundary.index) {
  33857. affectedBoundary.x2New = affectedBoundary.x2;
  33858. }
  33859. } else {
  33860. affectedBoundary.x2New = maxXNew;
  33861. }
  33862. } else if (affectedBoundary.x2New > maxXNew) {
  33863. // Affected boundary is touching new x, pushing it back.
  33864. affectedBoundary.x2New = Math.max(maxXNew, affectedBoundary.x2);
  33865. }
  33866. }
  33867. // Fixing the horizon.
  33868. var changedHorizon = [], lastBoundary = null;
  33869. for (q = i; q <= j; q++) {
  33870. horizonPart = horizon[q];
  33871. affectedBoundary = horizonPart.boundary;
  33872. // Checking which boundary will be visible.
  33873. var useBoundary = affectedBoundary.x2 > boundary.x2 ? affectedBoundary : boundary;
  33874. if (lastBoundary === useBoundary) {
  33875. // Merging with previous.
  33876. changedHorizon[changedHorizon.length - 1].end = horizonPart.end;
  33877. } else {
  33878. changedHorizon.push({
  33879. start: horizonPart.start,
  33880. end: horizonPart.end,
  33881. boundary: useBoundary
  33882. });
  33883. lastBoundary = useBoundary;
  33884. }
  33885. }
  33886. if (horizon[i].start < boundary.y1) {
  33887. changedHorizon[0].start = boundary.y1;
  33888. changedHorizon.unshift({
  33889. start: horizon[i].start,
  33890. end: boundary.y1,
  33891. boundary: horizon[i].boundary
  33892. });
  33893. }
  33894. if (boundary.y2 < horizon[j].end) {
  33895. changedHorizon[changedHorizon.length - 1].end = boundary.y2;
  33896. changedHorizon.push({
  33897. start: boundary.y2,
  33898. end: horizon[j].end,
  33899. boundary: horizon[j].boundary
  33900. });
  33901. }
  33902. // Set x2 new of boundary that is no longer visible (see overlapping case
  33903. // above).
  33904. // TODO more efficient, e.g. via reference counting.
  33905. for (q = i; q <= j; q++) {
  33906. horizonPart = horizon[q];
  33907. affectedBoundary = horizonPart.boundary;
  33908. if (affectedBoundary.x2New !== undefined) {
  33909. continue;
  33910. }
  33911. var used = false;
  33912. for (k = i - 1; !used && k >= 0 && horizon[k].start >= affectedBoundary.y1; k--) {
  33913. used = horizon[k].boundary === affectedBoundary;
  33914. }
  33915. for (k = j + 1; !used && k < horizon.length && horizon[k].end <= affectedBoundary.y2; k++) {
  33916. used = horizon[k].boundary === affectedBoundary;
  33917. }
  33918. for (k = 0; !used && k < changedHorizon.length; k++) {
  33919. used = changedHorizon[k].boundary === affectedBoundary;
  33920. }
  33921. if (!used) {
  33922. affectedBoundary.x2New = maxXNew;
  33923. }
  33924. }
  33925. Array.prototype.splice.apply(horizon, [
  33926. i,
  33927. j - i + 1
  33928. ].concat(changedHorizon));
  33929. });
  33930. // Set new x2 for all unset boundaries.
  33931. horizon.forEach(function (horizonPart) {
  33932. var affectedBoundary = horizonPart.boundary;
  33933. if (affectedBoundary.x2New === undefined) {
  33934. affectedBoundary.x2New = Math.max(width, affectedBoundary.x2);
  33935. }
  33936. });
  33937. }
  33938. /**
  33939. * Text layer rendering task.
  33940. *
  33941. * @param {TextContent} textContent
  33942. * @param {HTMLElement} container
  33943. * @param {PageViewport} viewport
  33944. * @param {Array} textDivs
  33945. * @param {boolean} enhanceTextSelection
  33946. * @private
  33947. */
  33948. function TextLayerRenderTask(textContent, container, viewport, textDivs, enhanceTextSelection) {
  33949. this._textContent = textContent;
  33950. this._container = container;
  33951. this._viewport = viewport;
  33952. this._textDivs = textDivs || [];
  33953. this._textDivProperties = new WeakMap();
  33954. this._renderingDone = false;
  33955. this._canceled = false;
  33956. this._capability = createPromiseCapability();
  33957. this._renderTimer = null;
  33958. this._bounds = [];
  33959. this._enhanceTextSelection = !!enhanceTextSelection;
  33960. }
  33961. TextLayerRenderTask.prototype = {
  33962. get promise() {
  33963. return this._capability.promise;
  33964. },
  33965. cancel: function TextLayer_cancel() {
  33966. this._canceled = true;
  33967. if (this._renderTimer !== null) {
  33968. clearTimeout(this._renderTimer);
  33969. this._renderTimer = null;
  33970. }
  33971. this._capability.reject('canceled');
  33972. },
  33973. _render: function TextLayer_render(timeout) {
  33974. var textItems = this._textContent.items;
  33975. var textStyles = this._textContent.styles;
  33976. for (var i = 0, len = textItems.length; i < len; i++) {
  33977. appendText(this, textItems[i], textStyles);
  33978. }
  33979. if (!timeout) {
  33980. // Render right away
  33981. render(this);
  33982. } else {
  33983. // Schedule
  33984. var self = this;
  33985. this._renderTimer = setTimeout(function () {
  33986. render(self);
  33987. self._renderTimer = null;
  33988. }, timeout);
  33989. }
  33990. },
  33991. expandTextDivs: function TextLayer_expandTextDivs(expandDivs) {
  33992. if (!this._enhanceTextSelection || !this._renderingDone) {
  33993. return;
  33994. }
  33995. if (this._bounds !== null) {
  33996. expand(this);
  33997. this._bounds = null;
  33998. }
  33999. for (var i = 0, ii = this._textDivs.length; i < ii; i++) {
  34000. var div = this._textDivs[i];
  34001. var divProperties = this._textDivProperties.get(div);
  34002. if (divProperties.isWhitespace) {
  34003. continue;
  34004. }
  34005. if (expandDivs) {
  34006. var transform = '', padding = '';
  34007. if (divProperties.scale !== 1) {
  34008. transform = 'scaleX(' + divProperties.scale + ')';
  34009. }
  34010. if (divProperties.angle !== 0) {
  34011. transform = 'rotate(' + divProperties.angle + 'deg) ' + transform;
  34012. }
  34013. if (divProperties.paddingLeft !== 0) {
  34014. padding += ' padding-left: ' + divProperties.paddingLeft / divProperties.scale + 'px;';
  34015. transform += ' translateX(' + -divProperties.paddingLeft / divProperties.scale + 'px)';
  34016. }
  34017. if (divProperties.paddingTop !== 0) {
  34018. padding += ' padding-top: ' + divProperties.paddingTop + 'px;';
  34019. transform += ' translateY(' + -divProperties.paddingTop + 'px)';
  34020. }
  34021. if (divProperties.paddingRight !== 0) {
  34022. padding += ' padding-right: ' + divProperties.paddingRight / divProperties.scale + 'px;';
  34023. }
  34024. if (divProperties.paddingBottom !== 0) {
  34025. padding += ' padding-bottom: ' + divProperties.paddingBottom + 'px;';
  34026. }
  34027. if (padding !== '') {
  34028. div.setAttribute('style', divProperties.style + padding);
  34029. }
  34030. if (transform !== '') {
  34031. CustomStyle.setProp('transform', div, transform);
  34032. }
  34033. } else {
  34034. div.style.padding = 0;
  34035. CustomStyle.setProp('transform', div, divProperties.originalTransform || '');
  34036. }
  34037. }
  34038. }
  34039. };
  34040. /**
  34041. * Starts rendering of the text layer.
  34042. *
  34043. * @param {TextLayerRenderParameters} renderParameters
  34044. * @returns {TextLayerRenderTask}
  34045. */
  34046. function renderTextLayer(renderParameters) {
  34047. var task = new TextLayerRenderTask(renderParameters.textContent, renderParameters.container, renderParameters.viewport, renderParameters.textDivs, renderParameters.enhanceTextSelection);
  34048. task._render(renderParameters.timeout);
  34049. return task;
  34050. }
  34051. return renderTextLayer;
  34052. }();
  34053. exports.renderTextLayer = renderTextLayer;
  34054. }));
  34055. (function (root, factory) {
  34056. factory(root.pdfjsDisplayWebGL = {}, root.pdfjsSharedUtil, root.pdfjsDisplayDOMUtils);
  34057. }(this, function (exports, sharedUtil, displayDOMUtils) {
  34058. var shadow = sharedUtil.shadow;
  34059. var getDefaultSetting = displayDOMUtils.getDefaultSetting;
  34060. var WebGLUtils = function WebGLUtilsClosure() {
  34061. function loadShader(gl, code, shaderType) {
  34062. var shader = gl.createShader(shaderType);
  34063. gl.shaderSource(shader, code);
  34064. gl.compileShader(shader);
  34065. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  34066. if (!compiled) {
  34067. var errorMsg = gl.getShaderInfoLog(shader);
  34068. throw new Error('Error during shader compilation: ' + errorMsg);
  34069. }
  34070. return shader;
  34071. }
  34072. function createVertexShader(gl, code) {
  34073. return loadShader(gl, code, gl.VERTEX_SHADER);
  34074. }
  34075. function createFragmentShader(gl, code) {
  34076. return loadShader(gl, code, gl.FRAGMENT_SHADER);
  34077. }
  34078. function createProgram(gl, shaders) {
  34079. var program = gl.createProgram();
  34080. for (var i = 0, ii = shaders.length; i < ii; ++i) {
  34081. gl.attachShader(program, shaders[i]);
  34082. }
  34083. gl.linkProgram(program);
  34084. var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  34085. if (!linked) {
  34086. var errorMsg = gl.getProgramInfoLog(program);
  34087. throw new Error('Error during program linking: ' + errorMsg);
  34088. }
  34089. return program;
  34090. }
  34091. function createTexture(gl, image, textureId) {
  34092. gl.activeTexture(textureId);
  34093. var texture = gl.createTexture();
  34094. gl.bindTexture(gl.TEXTURE_2D, texture);
  34095. // Set the parameters so we can render any size image.
  34096. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  34097. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  34098. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  34099. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  34100. // Upload the image into the texture.
  34101. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  34102. return texture;
  34103. }
  34104. var currentGL, currentCanvas;
  34105. function generateGL() {
  34106. if (currentGL) {
  34107. return;
  34108. }
  34109. currentCanvas = document.createElement('canvas');
  34110. currentGL = currentCanvas.getContext('webgl', { premultipliedalpha: false });
  34111. }
  34112. var smaskVertexShaderCode = '\
  34113. attribute vec2 a_position; \
  34114. attribute vec2 a_texCoord; \
  34115. \
  34116. uniform vec2 u_resolution; \
  34117. \
  34118. varying vec2 v_texCoord; \
  34119. \
  34120. void main() { \
  34121. vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
  34122. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  34123. \
  34124. v_texCoord = a_texCoord; \
  34125. } ';
  34126. var smaskFragmentShaderCode = '\
  34127. precision mediump float; \
  34128. \
  34129. uniform vec4 u_backdrop; \
  34130. uniform int u_subtype; \
  34131. uniform sampler2D u_image; \
  34132. uniform sampler2D u_mask; \
  34133. \
  34134. varying vec2 v_texCoord; \
  34135. \
  34136. void main() { \
  34137. vec4 imageColor = texture2D(u_image, v_texCoord); \
  34138. vec4 maskColor = texture2D(u_mask, v_texCoord); \
  34139. if (u_backdrop.a > 0.0) { \
  34140. maskColor.rgb = maskColor.rgb * maskColor.a + \
  34141. u_backdrop.rgb * (1.0 - maskColor.a); \
  34142. } \
  34143. float lum; \
  34144. if (u_subtype == 0) { \
  34145. lum = maskColor.a; \
  34146. } else { \
  34147. lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
  34148. maskColor.b * 0.11; \
  34149. } \
  34150. imageColor.a *= lum; \
  34151. imageColor.rgb *= imageColor.a; \
  34152. gl_FragColor = imageColor; \
  34153. } ';
  34154. var smaskCache = null;
  34155. function initSmaskGL() {
  34156. var canvas, gl;
  34157. generateGL();
  34158. canvas = currentCanvas;
  34159. currentCanvas = null;
  34160. gl = currentGL;
  34161. currentGL = null;
  34162. // setup a GLSL program
  34163. var vertexShader = createVertexShader(gl, smaskVertexShaderCode);
  34164. var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
  34165. var program = createProgram(gl, [
  34166. vertexShader,
  34167. fragmentShader
  34168. ]);
  34169. gl.useProgram(program);
  34170. var cache = {};
  34171. cache.gl = gl;
  34172. cache.canvas = canvas;
  34173. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  34174. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  34175. cache.backdropLocation = gl.getUniformLocation(program, 'u_backdrop');
  34176. cache.subtypeLocation = gl.getUniformLocation(program, 'u_subtype');
  34177. var texCoordLocation = gl.getAttribLocation(program, 'a_texCoord');
  34178. var texLayerLocation = gl.getUniformLocation(program, 'u_image');
  34179. var texMaskLocation = gl.getUniformLocation(program, 'u_mask');
  34180. // provide texture coordinates for the rectangle.
  34181. var texCoordBuffer = gl.createBuffer();
  34182. gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
  34183. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  34184. 0.0,
  34185. 0.0,
  34186. 1.0,
  34187. 0.0,
  34188. 0.0,
  34189. 1.0,
  34190. 0.0,
  34191. 1.0,
  34192. 1.0,
  34193. 0.0,
  34194. 1.0,
  34195. 1.0
  34196. ]), gl.STATIC_DRAW);
  34197. gl.enableVertexAttribArray(texCoordLocation);
  34198. gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
  34199. gl.uniform1i(texLayerLocation, 0);
  34200. gl.uniform1i(texMaskLocation, 1);
  34201. smaskCache = cache;
  34202. }
  34203. function composeSMask(layer, mask, properties) {
  34204. var width = layer.width, height = layer.height;
  34205. if (!smaskCache) {
  34206. initSmaskGL();
  34207. }
  34208. var cache = smaskCache, canvas = cache.canvas, gl = cache.gl;
  34209. canvas.width = width;
  34210. canvas.height = height;
  34211. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  34212. gl.uniform2f(cache.resolutionLocation, width, height);
  34213. if (properties.backdrop) {
  34214. gl.uniform4f(cache.resolutionLocation, properties.backdrop[0], properties.backdrop[1], properties.backdrop[2], 1);
  34215. } else {
  34216. gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
  34217. }
  34218. gl.uniform1i(cache.subtypeLocation, properties.subtype === 'Luminosity' ? 1 : 0);
  34219. // Create a textures
  34220. var texture = createTexture(gl, layer, gl.TEXTURE0);
  34221. var maskTexture = createTexture(gl, mask, gl.TEXTURE1);
  34222. // Create a buffer and put a single clipspace rectangle in
  34223. // it (2 triangles)
  34224. var buffer = gl.createBuffer();
  34225. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  34226. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  34227. 0,
  34228. 0,
  34229. width,
  34230. 0,
  34231. 0,
  34232. height,
  34233. 0,
  34234. height,
  34235. width,
  34236. 0,
  34237. width,
  34238. height
  34239. ]), gl.STATIC_DRAW);
  34240. gl.enableVertexAttribArray(cache.positionLocation);
  34241. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  34242. // draw
  34243. gl.clearColor(0, 0, 0, 0);
  34244. gl.enable(gl.BLEND);
  34245. gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  34246. gl.clear(gl.COLOR_BUFFER_BIT);
  34247. gl.drawArrays(gl.TRIANGLES, 0, 6);
  34248. gl.flush();
  34249. gl.deleteTexture(texture);
  34250. gl.deleteTexture(maskTexture);
  34251. gl.deleteBuffer(buffer);
  34252. return canvas;
  34253. }
  34254. var figuresVertexShaderCode = '\
  34255. attribute vec2 a_position; \
  34256. attribute vec3 a_color; \
  34257. \
  34258. uniform vec2 u_resolution; \
  34259. uniform vec2 u_scale; \
  34260. uniform vec2 u_offset; \
  34261. \
  34262. varying vec4 v_color; \
  34263. \
  34264. void main() { \
  34265. vec2 position = (a_position + u_offset) * u_scale; \
  34266. vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
  34267. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  34268. \
  34269. v_color = vec4(a_color / 255.0, 1.0); \
  34270. } ';
  34271. var figuresFragmentShaderCode = '\
  34272. precision mediump float; \
  34273. \
  34274. varying vec4 v_color; \
  34275. \
  34276. void main() { \
  34277. gl_FragColor = v_color; \
  34278. } ';
  34279. var figuresCache = null;
  34280. function initFiguresGL() {
  34281. var canvas, gl;
  34282. generateGL();
  34283. canvas = currentCanvas;
  34284. currentCanvas = null;
  34285. gl = currentGL;
  34286. currentGL = null;
  34287. // setup a GLSL program
  34288. var vertexShader = createVertexShader(gl, figuresVertexShaderCode);
  34289. var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
  34290. var program = createProgram(gl, [
  34291. vertexShader,
  34292. fragmentShader
  34293. ]);
  34294. gl.useProgram(program);
  34295. var cache = {};
  34296. cache.gl = gl;
  34297. cache.canvas = canvas;
  34298. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  34299. cache.scaleLocation = gl.getUniformLocation(program, 'u_scale');
  34300. cache.offsetLocation = gl.getUniformLocation(program, 'u_offset');
  34301. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  34302. cache.colorLocation = gl.getAttribLocation(program, 'a_color');
  34303. figuresCache = cache;
  34304. }
  34305. function drawFigures(width, height, backgroundColor, figures, context) {
  34306. if (!figuresCache) {
  34307. initFiguresGL();
  34308. }
  34309. var cache = figuresCache, canvas = cache.canvas, gl = cache.gl;
  34310. canvas.width = width;
  34311. canvas.height = height;
  34312. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  34313. gl.uniform2f(cache.resolutionLocation, width, height);
  34314. // count triangle points
  34315. var count = 0;
  34316. var i, ii, rows;
  34317. for (i = 0, ii = figures.length; i < ii; i++) {
  34318. switch (figures[i].type) {
  34319. case 'lattice':
  34320. rows = figures[i].coords.length / figures[i].verticesPerRow | 0;
  34321. count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
  34322. break;
  34323. case 'triangles':
  34324. count += figures[i].coords.length;
  34325. break;
  34326. }
  34327. }
  34328. // transfer data
  34329. var coords = new Float32Array(count * 2);
  34330. var colors = new Uint8Array(count * 3);
  34331. var coordsMap = context.coords, colorsMap = context.colors;
  34332. var pIndex = 0, cIndex = 0;
  34333. for (i = 0, ii = figures.length; i < ii; i++) {
  34334. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  34335. switch (figure.type) {
  34336. case 'lattice':
  34337. var cols = figure.verticesPerRow;
  34338. rows = ps.length / cols | 0;
  34339. for (var row = 1; row < rows; row++) {
  34340. var offset = row * cols + 1;
  34341. for (var col = 1; col < cols; col++, offset++) {
  34342. coords[pIndex] = coordsMap[ps[offset - cols - 1]];
  34343. coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
  34344. coords[pIndex + 2] = coordsMap[ps[offset - cols]];
  34345. coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
  34346. coords[pIndex + 4] = coordsMap[ps[offset - 1]];
  34347. coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
  34348. colors[cIndex] = colorsMap[cs[offset - cols - 1]];
  34349. colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
  34350. colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
  34351. colors[cIndex + 3] = colorsMap[cs[offset - cols]];
  34352. colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
  34353. colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
  34354. colors[cIndex + 6] = colorsMap[cs[offset - 1]];
  34355. colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
  34356. colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
  34357. coords[pIndex + 6] = coords[pIndex + 2];
  34358. coords[pIndex + 7] = coords[pIndex + 3];
  34359. coords[pIndex + 8] = coords[pIndex + 4];
  34360. coords[pIndex + 9] = coords[pIndex + 5];
  34361. coords[pIndex + 10] = coordsMap[ps[offset]];
  34362. coords[pIndex + 11] = coordsMap[ps[offset] + 1];
  34363. colors[cIndex + 9] = colors[cIndex + 3];
  34364. colors[cIndex + 10] = colors[cIndex + 4];
  34365. colors[cIndex + 11] = colors[cIndex + 5];
  34366. colors[cIndex + 12] = colors[cIndex + 6];
  34367. colors[cIndex + 13] = colors[cIndex + 7];
  34368. colors[cIndex + 14] = colors[cIndex + 8];
  34369. colors[cIndex + 15] = colorsMap[cs[offset]];
  34370. colors[cIndex + 16] = colorsMap[cs[offset] + 1];
  34371. colors[cIndex + 17] = colorsMap[cs[offset] + 2];
  34372. pIndex += 12;
  34373. cIndex += 18;
  34374. }
  34375. }
  34376. break;
  34377. case 'triangles':
  34378. for (var j = 0, jj = ps.length; j < jj; j++) {
  34379. coords[pIndex] = coordsMap[ps[j]];
  34380. coords[pIndex + 1] = coordsMap[ps[j] + 1];
  34381. colors[cIndex] = colorsMap[cs[j]];
  34382. colors[cIndex + 1] = colorsMap[cs[j] + 1];
  34383. colors[cIndex + 2] = colorsMap[cs[j] + 2];
  34384. pIndex += 2;
  34385. cIndex += 3;
  34386. }
  34387. break;
  34388. }
  34389. }
  34390. // draw
  34391. if (backgroundColor) {
  34392. gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255, backgroundColor[2] / 255, 1.0);
  34393. } else {
  34394. gl.clearColor(0, 0, 0, 0);
  34395. }
  34396. gl.clear(gl.COLOR_BUFFER_BIT);
  34397. var coordsBuffer = gl.createBuffer();
  34398. gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
  34399. gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
  34400. gl.enableVertexAttribArray(cache.positionLocation);
  34401. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  34402. var colorsBuffer = gl.createBuffer();
  34403. gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
  34404. gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
  34405. gl.enableVertexAttribArray(cache.colorLocation);
  34406. gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false, 0, 0);
  34407. gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
  34408. gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
  34409. gl.drawArrays(gl.TRIANGLES, 0, count);
  34410. gl.flush();
  34411. gl.deleteBuffer(coordsBuffer);
  34412. gl.deleteBuffer(colorsBuffer);
  34413. return canvas;
  34414. }
  34415. function cleanup() {
  34416. if (smaskCache && smaskCache.canvas) {
  34417. smaskCache.canvas.width = 0;
  34418. smaskCache.canvas.height = 0;
  34419. }
  34420. if (figuresCache && figuresCache.canvas) {
  34421. figuresCache.canvas.width = 0;
  34422. figuresCache.canvas.height = 0;
  34423. }
  34424. smaskCache = null;
  34425. figuresCache = null;
  34426. }
  34427. return {
  34428. get isEnabled() {
  34429. if (getDefaultSetting('disableWebGL')) {
  34430. return false;
  34431. }
  34432. var enabled = false;
  34433. try {
  34434. generateGL();
  34435. enabled = !!currentGL;
  34436. } catch (e) {
  34437. }
  34438. return shadow(this, 'isEnabled', enabled);
  34439. },
  34440. composeSMask: composeSMask,
  34441. drawFigures: drawFigures,
  34442. clear: cleanup
  34443. };
  34444. }();
  34445. exports.WebGLUtils = WebGLUtils;
  34446. }));
  34447. (function (root, factory) {
  34448. factory(root.pdfjsCoreCrypto = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  34449. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  34450. var PasswordException = sharedUtil.PasswordException;
  34451. var PasswordResponses = sharedUtil.PasswordResponses;
  34452. var bytesToString = sharedUtil.bytesToString;
  34453. var warn = sharedUtil.warn;
  34454. var error = sharedUtil.error;
  34455. var assert = sharedUtil.assert;
  34456. var isInt = sharedUtil.isInt;
  34457. var stringToBytes = sharedUtil.stringToBytes;
  34458. var utf8StringToString = sharedUtil.utf8StringToString;
  34459. var Name = corePrimitives.Name;
  34460. var isName = corePrimitives.isName;
  34461. var isDict = corePrimitives.isDict;
  34462. var DecryptStream = coreStream.DecryptStream;
  34463. var ARCFourCipher = function ARCFourCipherClosure() {
  34464. function ARCFourCipher(key) {
  34465. this.a = 0;
  34466. this.b = 0;
  34467. var s = new Uint8Array(256);
  34468. var i, j = 0, tmp, keyLength = key.length;
  34469. for (i = 0; i < 256; ++i) {
  34470. s[i] = i;
  34471. }
  34472. for (i = 0; i < 256; ++i) {
  34473. tmp = s[i];
  34474. j = j + tmp + key[i % keyLength] & 0xFF;
  34475. s[i] = s[j];
  34476. s[j] = tmp;
  34477. }
  34478. this.s = s;
  34479. }
  34480. ARCFourCipher.prototype = {
  34481. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  34482. var i, n = data.length, tmp, tmp2;
  34483. var a = this.a, b = this.b, s = this.s;
  34484. var output = new Uint8Array(n);
  34485. for (i = 0; i < n; ++i) {
  34486. a = a + 1 & 0xFF;
  34487. tmp = s[a];
  34488. b = b + tmp & 0xFF;
  34489. tmp2 = s[b];
  34490. s[a] = tmp2;
  34491. s[b] = tmp;
  34492. output[i] = data[i] ^ s[tmp + tmp2 & 0xFF];
  34493. }
  34494. this.a = a;
  34495. this.b = b;
  34496. return output;
  34497. }
  34498. };
  34499. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  34500. return ARCFourCipher;
  34501. }();
  34502. var calculateMD5 = function calculateMD5Closure() {
  34503. var r = new Uint8Array([
  34504. 7,
  34505. 12,
  34506. 17,
  34507. 22,
  34508. 7,
  34509. 12,
  34510. 17,
  34511. 22,
  34512. 7,
  34513. 12,
  34514. 17,
  34515. 22,
  34516. 7,
  34517. 12,
  34518. 17,
  34519. 22,
  34520. 5,
  34521. 9,
  34522. 14,
  34523. 20,
  34524. 5,
  34525. 9,
  34526. 14,
  34527. 20,
  34528. 5,
  34529. 9,
  34530. 14,
  34531. 20,
  34532. 5,
  34533. 9,
  34534. 14,
  34535. 20,
  34536. 4,
  34537. 11,
  34538. 16,
  34539. 23,
  34540. 4,
  34541. 11,
  34542. 16,
  34543. 23,
  34544. 4,
  34545. 11,
  34546. 16,
  34547. 23,
  34548. 4,
  34549. 11,
  34550. 16,
  34551. 23,
  34552. 6,
  34553. 10,
  34554. 15,
  34555. 21,
  34556. 6,
  34557. 10,
  34558. 15,
  34559. 21,
  34560. 6,
  34561. 10,
  34562. 15,
  34563. 21,
  34564. 6,
  34565. 10,
  34566. 15,
  34567. 21
  34568. ]);
  34569. var k = new Int32Array([
  34570. -680876936,
  34571. -389564586,
  34572. 606105819,
  34573. -1044525330,
  34574. -176418897,
  34575. 1200080426,
  34576. -1473231341,
  34577. -45705983,
  34578. 1770035416,
  34579. -1958414417,
  34580. -42063,
  34581. -1990404162,
  34582. 1804603682,
  34583. -40341101,
  34584. -1502002290,
  34585. 1236535329,
  34586. -165796510,
  34587. -1069501632,
  34588. 643717713,
  34589. -373897302,
  34590. -701558691,
  34591. 38016083,
  34592. -660478335,
  34593. -405537848,
  34594. 568446438,
  34595. -1019803690,
  34596. -187363961,
  34597. 1163531501,
  34598. -1444681467,
  34599. -51403784,
  34600. 1735328473,
  34601. -1926607734,
  34602. -378558,
  34603. -2022574463,
  34604. 1839030562,
  34605. -35309556,
  34606. -1530992060,
  34607. 1272893353,
  34608. -155497632,
  34609. -1094730640,
  34610. 681279174,
  34611. -358537222,
  34612. -722521979,
  34613. 76029189,
  34614. -640364487,
  34615. -421815835,
  34616. 530742520,
  34617. -995338651,
  34618. -198630844,
  34619. 1126891415,
  34620. -1416354905,
  34621. -57434055,
  34622. 1700485571,
  34623. -1894986606,
  34624. -1051523,
  34625. -2054922799,
  34626. 1873313359,
  34627. -30611744,
  34628. -1560198380,
  34629. 1309151649,
  34630. -145523070,
  34631. -1120210379,
  34632. 718787259,
  34633. -343485551
  34634. ]);
  34635. function hash(data, offset, length) {
  34636. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  34637. // pre-processing
  34638. var paddedLength = length + 72 & ~63;
  34639. // data + 9 extra bytes
  34640. var padded = new Uint8Array(paddedLength);
  34641. var i, j, n;
  34642. for (i = 0; i < length; ++i) {
  34643. padded[i] = data[offset++];
  34644. }
  34645. padded[i++] = 0x80;
  34646. n = paddedLength - 8;
  34647. while (i < n) {
  34648. padded[i++] = 0;
  34649. }
  34650. padded[i++] = length << 3 & 0xFF;
  34651. padded[i++] = length >> 5 & 0xFF;
  34652. padded[i++] = length >> 13 & 0xFF;
  34653. padded[i++] = length >> 21 & 0xFF;
  34654. padded[i++] = length >>> 29 & 0xFF;
  34655. padded[i++] = 0;
  34656. padded[i++] = 0;
  34657. padded[i++] = 0;
  34658. var w = new Int32Array(16);
  34659. for (i = 0; i < paddedLength;) {
  34660. for (j = 0; j < 16; ++j, i += 4) {
  34661. w[j] = padded[i] | padded[i + 1] << 8 | padded[i + 2] << 16 | padded[i + 3] << 24;
  34662. }
  34663. var a = h0, b = h1, c = h2, d = h3, f, g;
  34664. for (j = 0; j < 64; ++j) {
  34665. if (j < 16) {
  34666. f = b & c | ~b & d;
  34667. g = j;
  34668. } else if (j < 32) {
  34669. f = d & b | ~d & c;
  34670. g = 5 * j + 1 & 15;
  34671. } else if (j < 48) {
  34672. f = b ^ c ^ d;
  34673. g = 3 * j + 5 & 15;
  34674. } else {
  34675. f = c ^ (b | ~d);
  34676. g = 7 * j & 15;
  34677. }
  34678. var tmp = d, rotateArg = a + f + k[j] + w[g] | 0, rotate = r[j];
  34679. d = c;
  34680. c = b;
  34681. b = b + (rotateArg << rotate | rotateArg >>> 32 - rotate) | 0;
  34682. a = tmp;
  34683. }
  34684. h0 = h0 + a | 0;
  34685. h1 = h1 + b | 0;
  34686. h2 = h2 + c | 0;
  34687. h3 = h3 + d | 0;
  34688. }
  34689. return new Uint8Array([
  34690. h0 & 0xFF,
  34691. h0 >> 8 & 0xFF,
  34692. h0 >> 16 & 0xFF,
  34693. h0 >>> 24 & 0xFF,
  34694. h1 & 0xFF,
  34695. h1 >> 8 & 0xFF,
  34696. h1 >> 16 & 0xFF,
  34697. h1 >>> 24 & 0xFF,
  34698. h2 & 0xFF,
  34699. h2 >> 8 & 0xFF,
  34700. h2 >> 16 & 0xFF,
  34701. h2 >>> 24 & 0xFF,
  34702. h3 & 0xFF,
  34703. h3 >> 8 & 0xFF,
  34704. h3 >> 16 & 0xFF,
  34705. h3 >>> 24 & 0xFF
  34706. ]);
  34707. }
  34708. return hash;
  34709. }();
  34710. var Word64 = function Word64Closure() {
  34711. function Word64(highInteger, lowInteger) {
  34712. this.high = highInteger | 0;
  34713. this.low = lowInteger | 0;
  34714. }
  34715. Word64.prototype = {
  34716. and: function Word64_and(word) {
  34717. this.high &= word.high;
  34718. this.low &= word.low;
  34719. },
  34720. xor: function Word64_xor(word) {
  34721. this.high ^= word.high;
  34722. this.low ^= word.low;
  34723. },
  34724. or: function Word64_or(word) {
  34725. this.high |= word.high;
  34726. this.low |= word.low;
  34727. },
  34728. shiftRight: function Word64_shiftRight(places) {
  34729. if (places >= 32) {
  34730. this.low = this.high >>> places - 32 | 0;
  34731. this.high = 0;
  34732. } else {
  34733. this.low = this.low >>> places | this.high << 32 - places;
  34734. this.high = this.high >>> places | 0;
  34735. }
  34736. },
  34737. shiftLeft: function Word64_shiftLeft(places) {
  34738. if (places >= 32) {
  34739. this.high = this.low << places - 32;
  34740. this.low = 0;
  34741. } else {
  34742. this.high = this.high << places | this.low >>> 32 - places;
  34743. this.low = this.low << places;
  34744. }
  34745. },
  34746. rotateRight: function Word64_rotateRight(places) {
  34747. var low, high;
  34748. if (places & 32) {
  34749. high = this.low;
  34750. low = this.high;
  34751. } else {
  34752. low = this.low;
  34753. high = this.high;
  34754. }
  34755. places &= 31;
  34756. this.low = low >>> places | high << 32 - places;
  34757. this.high = high >>> places | low << 32 - places;
  34758. },
  34759. not: function Word64_not() {
  34760. this.high = ~this.high;
  34761. this.low = ~this.low;
  34762. },
  34763. add: function Word64_add(word) {
  34764. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  34765. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  34766. if (lowAdd > 0xFFFFFFFF) {
  34767. highAdd += 1;
  34768. }
  34769. this.low = lowAdd | 0;
  34770. this.high = highAdd | 0;
  34771. },
  34772. copyTo: function Word64_copyTo(bytes, offset) {
  34773. bytes[offset] = this.high >>> 24 & 0xFF;
  34774. bytes[offset + 1] = this.high >> 16 & 0xFF;
  34775. bytes[offset + 2] = this.high >> 8 & 0xFF;
  34776. bytes[offset + 3] = this.high & 0xFF;
  34777. bytes[offset + 4] = this.low >>> 24 & 0xFF;
  34778. bytes[offset + 5] = this.low >> 16 & 0xFF;
  34779. bytes[offset + 6] = this.low >> 8 & 0xFF;
  34780. bytes[offset + 7] = this.low & 0xFF;
  34781. },
  34782. assign: function Word64_assign(word) {
  34783. this.high = word.high;
  34784. this.low = word.low;
  34785. }
  34786. };
  34787. return Word64;
  34788. }();
  34789. var calculateSHA256 = function calculateSHA256Closure() {
  34790. function rotr(x, n) {
  34791. return x >>> n | x << 32 - n;
  34792. }
  34793. function ch(x, y, z) {
  34794. return x & y ^ ~x & z;
  34795. }
  34796. function maj(x, y, z) {
  34797. return x & y ^ x & z ^ y & z;
  34798. }
  34799. function sigma(x) {
  34800. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  34801. }
  34802. function sigmaPrime(x) {
  34803. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  34804. }
  34805. function littleSigma(x) {
  34806. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  34807. }
  34808. function littleSigmaPrime(x) {
  34809. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  34810. }
  34811. var k = [
  34812. 0x428a2f98,
  34813. 0x71374491,
  34814. 0xb5c0fbcf,
  34815. 0xe9b5dba5,
  34816. 0x3956c25b,
  34817. 0x59f111f1,
  34818. 0x923f82a4,
  34819. 0xab1c5ed5,
  34820. 0xd807aa98,
  34821. 0x12835b01,
  34822. 0x243185be,
  34823. 0x550c7dc3,
  34824. 0x72be5d74,
  34825. 0x80deb1fe,
  34826. 0x9bdc06a7,
  34827. 0xc19bf174,
  34828. 0xe49b69c1,
  34829. 0xefbe4786,
  34830. 0x0fc19dc6,
  34831. 0x240ca1cc,
  34832. 0x2de92c6f,
  34833. 0x4a7484aa,
  34834. 0x5cb0a9dc,
  34835. 0x76f988da,
  34836. 0x983e5152,
  34837. 0xa831c66d,
  34838. 0xb00327c8,
  34839. 0xbf597fc7,
  34840. 0xc6e00bf3,
  34841. 0xd5a79147,
  34842. 0x06ca6351,
  34843. 0x14292967,
  34844. 0x27b70a85,
  34845. 0x2e1b2138,
  34846. 0x4d2c6dfc,
  34847. 0x53380d13,
  34848. 0x650a7354,
  34849. 0x766a0abb,
  34850. 0x81c2c92e,
  34851. 0x92722c85,
  34852. 0xa2bfe8a1,
  34853. 0xa81a664b,
  34854. 0xc24b8b70,
  34855. 0xc76c51a3,
  34856. 0xd192e819,
  34857. 0xd6990624,
  34858. 0xf40e3585,
  34859. 0x106aa070,
  34860. 0x19a4c116,
  34861. 0x1e376c08,
  34862. 0x2748774c,
  34863. 0x34b0bcb5,
  34864. 0x391c0cb3,
  34865. 0x4ed8aa4a,
  34866. 0x5b9cca4f,
  34867. 0x682e6ff3,
  34868. 0x748f82ee,
  34869. 0x78a5636f,
  34870. 0x84c87814,
  34871. 0x8cc70208,
  34872. 0x90befffa,
  34873. 0xa4506ceb,
  34874. 0xbef9a3f7,
  34875. 0xc67178f2
  34876. ];
  34877. function hash(data, offset, length) {
  34878. // initial hash values
  34879. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372, h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c, h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  34880. // pre-processing
  34881. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  34882. var padded = new Uint8Array(paddedLength);
  34883. var i, j, n;
  34884. for (i = 0; i < length; ++i) {
  34885. padded[i] = data[offset++];
  34886. }
  34887. padded[i++] = 0x80;
  34888. n = paddedLength - 8;
  34889. while (i < n) {
  34890. padded[i++] = 0;
  34891. }
  34892. padded[i++] = 0;
  34893. padded[i++] = 0;
  34894. padded[i++] = 0;
  34895. padded[i++] = length >>> 29 & 0xFF;
  34896. padded[i++] = length >> 21 & 0xFF;
  34897. padded[i++] = length >> 13 & 0xFF;
  34898. padded[i++] = length >> 5 & 0xFF;
  34899. padded[i++] = length << 3 & 0xFF;
  34900. var w = new Uint32Array(64);
  34901. // for each 512 bit block
  34902. for (i = 0; i < paddedLength;) {
  34903. for (j = 0; j < 16; ++j) {
  34904. w[j] = padded[i] << 24 | padded[i + 1] << 16 | padded[i + 2] << 8 | padded[i + 3];
  34905. i += 4;
  34906. }
  34907. for (j = 16; j < 64; ++j) {
  34908. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] + littleSigma(w[j - 15]) + w[j - 16] | 0;
  34909. }
  34910. var a = h0, b = h1, c = h2, d = h3, e = h4, f = h5, g = h6, h = h7, t1, t2;
  34911. for (j = 0; j < 64; ++j) {
  34912. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  34913. t2 = sigma(a) + maj(a, b, c);
  34914. h = g;
  34915. g = f;
  34916. f = e;
  34917. e = d + t1 | 0;
  34918. d = c;
  34919. c = b;
  34920. b = a;
  34921. a = t1 + t2 | 0;
  34922. }
  34923. h0 = h0 + a | 0;
  34924. h1 = h1 + b | 0;
  34925. h2 = h2 + c | 0;
  34926. h3 = h3 + d | 0;
  34927. h4 = h4 + e | 0;
  34928. h5 = h5 + f | 0;
  34929. h6 = h6 + g | 0;
  34930. h7 = h7 + h | 0;
  34931. }
  34932. return new Uint8Array([
  34933. h0 >> 24 & 0xFF,
  34934. h0 >> 16 & 0xFF,
  34935. h0 >> 8 & 0xFF,
  34936. h0 & 0xFF,
  34937. h1 >> 24 & 0xFF,
  34938. h1 >> 16 & 0xFF,
  34939. h1 >> 8 & 0xFF,
  34940. h1 & 0xFF,
  34941. h2 >> 24 & 0xFF,
  34942. h2 >> 16 & 0xFF,
  34943. h2 >> 8 & 0xFF,
  34944. h2 & 0xFF,
  34945. h3 >> 24 & 0xFF,
  34946. h3 >> 16 & 0xFF,
  34947. h3 >> 8 & 0xFF,
  34948. h3 & 0xFF,
  34949. h4 >> 24 & 0xFF,
  34950. h4 >> 16 & 0xFF,
  34951. h4 >> 8 & 0xFF,
  34952. h4 & 0xFF,
  34953. h5 >> 24 & 0xFF,
  34954. h5 >> 16 & 0xFF,
  34955. h5 >> 8 & 0xFF,
  34956. h5 & 0xFF,
  34957. h6 >> 24 & 0xFF,
  34958. h6 >> 16 & 0xFF,
  34959. h6 >> 8 & 0xFF,
  34960. h6 & 0xFF,
  34961. h7 >> 24 & 0xFF,
  34962. h7 >> 16 & 0xFF,
  34963. h7 >> 8 & 0xFF,
  34964. h7 & 0xFF
  34965. ]);
  34966. }
  34967. return hash;
  34968. }();
  34969. var calculateSHA512 = function calculateSHA512Closure() {
  34970. function ch(result, x, y, z, tmp) {
  34971. result.assign(x);
  34972. result.and(y);
  34973. tmp.assign(x);
  34974. tmp.not();
  34975. tmp.and(z);
  34976. result.xor(tmp);
  34977. }
  34978. function maj(result, x, y, z, tmp) {
  34979. result.assign(x);
  34980. result.and(y);
  34981. tmp.assign(x);
  34982. tmp.and(z);
  34983. result.xor(tmp);
  34984. tmp.assign(y);
  34985. tmp.and(z);
  34986. result.xor(tmp);
  34987. }
  34988. function sigma(result, x, tmp) {
  34989. result.assign(x);
  34990. result.rotateRight(28);
  34991. tmp.assign(x);
  34992. tmp.rotateRight(34);
  34993. result.xor(tmp);
  34994. tmp.assign(x);
  34995. tmp.rotateRight(39);
  34996. result.xor(tmp);
  34997. }
  34998. function sigmaPrime(result, x, tmp) {
  34999. result.assign(x);
  35000. result.rotateRight(14);
  35001. tmp.assign(x);
  35002. tmp.rotateRight(18);
  35003. result.xor(tmp);
  35004. tmp.assign(x);
  35005. tmp.rotateRight(41);
  35006. result.xor(tmp);
  35007. }
  35008. function littleSigma(result, x, tmp) {
  35009. result.assign(x);
  35010. result.rotateRight(1);
  35011. tmp.assign(x);
  35012. tmp.rotateRight(8);
  35013. result.xor(tmp);
  35014. tmp.assign(x);
  35015. tmp.shiftRight(7);
  35016. result.xor(tmp);
  35017. }
  35018. function littleSigmaPrime(result, x, tmp) {
  35019. result.assign(x);
  35020. result.rotateRight(19);
  35021. tmp.assign(x);
  35022. tmp.rotateRight(61);
  35023. result.xor(tmp);
  35024. tmp.assign(x);
  35025. tmp.shiftRight(6);
  35026. result.xor(tmp);
  35027. }
  35028. var k = [
  35029. new Word64(0x428a2f98, 0xd728ae22),
  35030. new Word64(0x71374491, 0x23ef65cd),
  35031. new Word64(0xb5c0fbcf, 0xec4d3b2f),
  35032. new Word64(0xe9b5dba5, 0x8189dbbc),
  35033. new Word64(0x3956c25b, 0xf348b538),
  35034. new Word64(0x59f111f1, 0xb605d019),
  35035. new Word64(0x923f82a4, 0xaf194f9b),
  35036. new Word64(0xab1c5ed5, 0xda6d8118),
  35037. new Word64(0xd807aa98, 0xa3030242),
  35038. new Word64(0x12835b01, 0x45706fbe),
  35039. new Word64(0x243185be, 0x4ee4b28c),
  35040. new Word64(0x550c7dc3, 0xd5ffb4e2),
  35041. new Word64(0x72be5d74, 0xf27b896f),
  35042. new Word64(0x80deb1fe, 0x3b1696b1),
  35043. new Word64(0x9bdc06a7, 0x25c71235),
  35044. new Word64(0xc19bf174, 0xcf692694),
  35045. new Word64(0xe49b69c1, 0x9ef14ad2),
  35046. new Word64(0xefbe4786, 0x384f25e3),
  35047. new Word64(0x0fc19dc6, 0x8b8cd5b5),
  35048. new Word64(0x240ca1cc, 0x77ac9c65),
  35049. new Word64(0x2de92c6f, 0x592b0275),
  35050. new Word64(0x4a7484aa, 0x6ea6e483),
  35051. new Word64(0x5cb0a9dc, 0xbd41fbd4),
  35052. new Word64(0x76f988da, 0x831153b5),
  35053. new Word64(0x983e5152, 0xee66dfab),
  35054. new Word64(0xa831c66d, 0x2db43210),
  35055. new Word64(0xb00327c8, 0x98fb213f),
  35056. new Word64(0xbf597fc7, 0xbeef0ee4),
  35057. new Word64(0xc6e00bf3, 0x3da88fc2),
  35058. new Word64(0xd5a79147, 0x930aa725),
  35059. new Word64(0x06ca6351, 0xe003826f),
  35060. new Word64(0x14292967, 0x0a0e6e70),
  35061. new Word64(0x27b70a85, 0x46d22ffc),
  35062. new Word64(0x2e1b2138, 0x5c26c926),
  35063. new Word64(0x4d2c6dfc, 0x5ac42aed),
  35064. new Word64(0x53380d13, 0x9d95b3df),
  35065. new Word64(0x650a7354, 0x8baf63de),
  35066. new Word64(0x766a0abb, 0x3c77b2a8),
  35067. new Word64(0x81c2c92e, 0x47edaee6),
  35068. new Word64(0x92722c85, 0x1482353b),
  35069. new Word64(0xa2bfe8a1, 0x4cf10364),
  35070. new Word64(0xa81a664b, 0xbc423001),
  35071. new Word64(0xc24b8b70, 0xd0f89791),
  35072. new Word64(0xc76c51a3, 0x0654be30),
  35073. new Word64(0xd192e819, 0xd6ef5218),
  35074. new Word64(0xd6990624, 0x5565a910),
  35075. new Word64(0xf40e3585, 0x5771202a),
  35076. new Word64(0x106aa070, 0x32bbd1b8),
  35077. new Word64(0x19a4c116, 0xb8d2d0c8),
  35078. new Word64(0x1e376c08, 0x5141ab53),
  35079. new Word64(0x2748774c, 0xdf8eeb99),
  35080. new Word64(0x34b0bcb5, 0xe19b48a8),
  35081. new Word64(0x391c0cb3, 0xc5c95a63),
  35082. new Word64(0x4ed8aa4a, 0xe3418acb),
  35083. new Word64(0x5b9cca4f, 0x7763e373),
  35084. new Word64(0x682e6ff3, 0xd6b2b8a3),
  35085. new Word64(0x748f82ee, 0x5defb2fc),
  35086. new Word64(0x78a5636f, 0x43172f60),
  35087. new Word64(0x84c87814, 0xa1f0ab72),
  35088. new Word64(0x8cc70208, 0x1a6439ec),
  35089. new Word64(0x90befffa, 0x23631e28),
  35090. new Word64(0xa4506ceb, 0xde82bde9),
  35091. new Word64(0xbef9a3f7, 0xb2c67915),
  35092. new Word64(0xc67178f2, 0xe372532b),
  35093. new Word64(0xca273ece, 0xea26619c),
  35094. new Word64(0xd186b8c7, 0x21c0c207),
  35095. new Word64(0xeada7dd6, 0xcde0eb1e),
  35096. new Word64(0xf57d4f7f, 0xee6ed178),
  35097. new Word64(0x06f067aa, 0x72176fba),
  35098. new Word64(0x0a637dc5, 0xa2c898a6),
  35099. new Word64(0x113f9804, 0xbef90dae),
  35100. new Word64(0x1b710b35, 0x131c471b),
  35101. new Word64(0x28db77f5, 0x23047d84),
  35102. new Word64(0x32caab7b, 0x40c72493),
  35103. new Word64(0x3c9ebe0a, 0x15c9bebc),
  35104. new Word64(0x431d67c4, 0x9c100d4c),
  35105. new Word64(0x4cc5d4be, 0xcb3e42b6),
  35106. new Word64(0x597f299c, 0xfc657e2a),
  35107. new Word64(0x5fcb6fab, 0x3ad6faec),
  35108. new Word64(0x6c44198c, 0x4a475817)
  35109. ];
  35110. function hash(data, offset, length, mode384) {
  35111. mode384 = !!mode384;
  35112. // initial hash values
  35113. var h0, h1, h2, h3, h4, h5, h6, h7;
  35114. if (!mode384) {
  35115. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  35116. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  35117. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  35118. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  35119. h4 = new Word64(0x510e527f, 0xade682d1);
  35120. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  35121. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  35122. h7 = new Word64(0x5be0cd19, 0x137e2179);
  35123. } else {
  35124. // SHA384 is exactly the same
  35125. // except with different starting values and a trimmed result
  35126. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  35127. h1 = new Word64(0x629a292a, 0x367cd507);
  35128. h2 = new Word64(0x9159015a, 0x3070dd17);
  35129. h3 = new Word64(0x152fecd8, 0xf70e5939);
  35130. h4 = new Word64(0x67332667, 0xffc00b31);
  35131. h5 = new Word64(0x8eb44a87, 0x68581511);
  35132. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  35133. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  35134. }
  35135. // pre-processing
  35136. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  35137. var padded = new Uint8Array(paddedLength);
  35138. var i, j, n;
  35139. for (i = 0; i < length; ++i) {
  35140. padded[i] = data[offset++];
  35141. }
  35142. padded[i++] = 0x80;
  35143. n = paddedLength - 16;
  35144. while (i < n) {
  35145. padded[i++] = 0;
  35146. }
  35147. padded[i++] = 0;
  35148. padded[i++] = 0;
  35149. padded[i++] = 0;
  35150. padded[i++] = 0;
  35151. padded[i++] = 0;
  35152. padded[i++] = 0;
  35153. padded[i++] = 0;
  35154. padded[i++] = 0;
  35155. padded[i++] = 0;
  35156. padded[i++] = 0;
  35157. padded[i++] = 0;
  35158. padded[i++] = length >>> 29 & 0xFF;
  35159. padded[i++] = length >> 21 & 0xFF;
  35160. padded[i++] = length >> 13 & 0xFF;
  35161. padded[i++] = length >> 5 & 0xFF;
  35162. padded[i++] = length << 3 & 0xFF;
  35163. var w = new Array(80);
  35164. for (i = 0; i < 80; i++) {
  35165. w[i] = new Word64(0, 0);
  35166. }
  35167. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  35168. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  35169. var g = new Word64(0, 0), h = new Word64(0, 0);
  35170. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  35171. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  35172. // for each 1024 bit block
  35173. for (i = 0; i < paddedLength;) {
  35174. for (j = 0; j < 16; ++j) {
  35175. w[j].high = padded[i] << 24 | padded[i + 1] << 16 | padded[i + 2] << 8 | padded[i + 3];
  35176. w[j].low = padded[i + 4] << 24 | padded[i + 5] << 16 | padded[i + 6] << 8 | padded[i + 7];
  35177. i += 8;
  35178. }
  35179. for (j = 16; j < 80; ++j) {
  35180. tmp3 = w[j];
  35181. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  35182. tmp3.add(w[j - 7]);
  35183. littleSigma(tmp1, w[j - 15], tmp2);
  35184. tmp3.add(tmp1);
  35185. tmp3.add(w[j - 16]);
  35186. }
  35187. a.assign(h0);
  35188. b.assign(h1);
  35189. c.assign(h2);
  35190. d.assign(h3);
  35191. e.assign(h4);
  35192. f.assign(h5);
  35193. g.assign(h6);
  35194. h.assign(h7);
  35195. for (j = 0; j < 80; ++j) {
  35196. t1.assign(h);
  35197. sigmaPrime(tmp1, e, tmp2);
  35198. t1.add(tmp1);
  35199. ch(tmp1, e, f, g, tmp2);
  35200. t1.add(tmp1);
  35201. t1.add(k[j]);
  35202. t1.add(w[j]);
  35203. sigma(t2, a, tmp2);
  35204. maj(tmp1, a, b, c, tmp2);
  35205. t2.add(tmp1);
  35206. tmp3 = h;
  35207. h = g;
  35208. g = f;
  35209. f = e;
  35210. d.add(t1);
  35211. e = d;
  35212. d = c;
  35213. c = b;
  35214. b = a;
  35215. tmp3.assign(t1);
  35216. tmp3.add(t2);
  35217. a = tmp3;
  35218. }
  35219. h0.add(a);
  35220. h1.add(b);
  35221. h2.add(c);
  35222. h3.add(d);
  35223. h4.add(e);
  35224. h5.add(f);
  35225. h6.add(g);
  35226. h7.add(h);
  35227. }
  35228. var result;
  35229. if (!mode384) {
  35230. result = new Uint8Array(64);
  35231. h0.copyTo(result, 0);
  35232. h1.copyTo(result, 8);
  35233. h2.copyTo(result, 16);
  35234. h3.copyTo(result, 24);
  35235. h4.copyTo(result, 32);
  35236. h5.copyTo(result, 40);
  35237. h6.copyTo(result, 48);
  35238. h7.copyTo(result, 56);
  35239. } else {
  35240. result = new Uint8Array(48);
  35241. h0.copyTo(result, 0);
  35242. h1.copyTo(result, 8);
  35243. h2.copyTo(result, 16);
  35244. h3.copyTo(result, 24);
  35245. h4.copyTo(result, 32);
  35246. h5.copyTo(result, 40);
  35247. }
  35248. return result;
  35249. }
  35250. return hash;
  35251. }();
  35252. var calculateSHA384 = function calculateSHA384Closure() {
  35253. function hash(data, offset, length) {
  35254. return calculateSHA512(data, offset, length, true);
  35255. }
  35256. return hash;
  35257. }();
  35258. var NullCipher = function NullCipherClosure() {
  35259. function NullCipher() {
  35260. }
  35261. NullCipher.prototype = {
  35262. decryptBlock: function NullCipher_decryptBlock(data) {
  35263. return data;
  35264. }
  35265. };
  35266. return NullCipher;
  35267. }();
  35268. var AES128Cipher = function AES128CipherClosure() {
  35269. var rcon = new Uint8Array([
  35270. 0x8d,
  35271. 0x01,
  35272. 0x02,
  35273. 0x04,
  35274. 0x08,
  35275. 0x10,
  35276. 0x20,
  35277. 0x40,
  35278. 0x80,
  35279. 0x1b,
  35280. 0x36,
  35281. 0x6c,
  35282. 0xd8,
  35283. 0xab,
  35284. 0x4d,
  35285. 0x9a,
  35286. 0x2f,
  35287. 0x5e,
  35288. 0xbc,
  35289. 0x63,
  35290. 0xc6,
  35291. 0x97,
  35292. 0x35,
  35293. 0x6a,
  35294. 0xd4,
  35295. 0xb3,
  35296. 0x7d,
  35297. 0xfa,
  35298. 0xef,
  35299. 0xc5,
  35300. 0x91,
  35301. 0x39,
  35302. 0x72,
  35303. 0xe4,
  35304. 0xd3,
  35305. 0xbd,
  35306. 0x61,
  35307. 0xc2,
  35308. 0x9f,
  35309. 0x25,
  35310. 0x4a,
  35311. 0x94,
  35312. 0x33,
  35313. 0x66,
  35314. 0xcc,
  35315. 0x83,
  35316. 0x1d,
  35317. 0x3a,
  35318. 0x74,
  35319. 0xe8,
  35320. 0xcb,
  35321. 0x8d,
  35322. 0x01,
  35323. 0x02,
  35324. 0x04,
  35325. 0x08,
  35326. 0x10,
  35327. 0x20,
  35328. 0x40,
  35329. 0x80,
  35330. 0x1b,
  35331. 0x36,
  35332. 0x6c,
  35333. 0xd8,
  35334. 0xab,
  35335. 0x4d,
  35336. 0x9a,
  35337. 0x2f,
  35338. 0x5e,
  35339. 0xbc,
  35340. 0x63,
  35341. 0xc6,
  35342. 0x97,
  35343. 0x35,
  35344. 0x6a,
  35345. 0xd4,
  35346. 0xb3,
  35347. 0x7d,
  35348. 0xfa,
  35349. 0xef,
  35350. 0xc5,
  35351. 0x91,
  35352. 0x39,
  35353. 0x72,
  35354. 0xe4,
  35355. 0xd3,
  35356. 0xbd,
  35357. 0x61,
  35358. 0xc2,
  35359. 0x9f,
  35360. 0x25,
  35361. 0x4a,
  35362. 0x94,
  35363. 0x33,
  35364. 0x66,
  35365. 0xcc,
  35366. 0x83,
  35367. 0x1d,
  35368. 0x3a,
  35369. 0x74,
  35370. 0xe8,
  35371. 0xcb,
  35372. 0x8d,
  35373. 0x01,
  35374. 0x02,
  35375. 0x04,
  35376. 0x08,
  35377. 0x10,
  35378. 0x20,
  35379. 0x40,
  35380. 0x80,
  35381. 0x1b,
  35382. 0x36,
  35383. 0x6c,
  35384. 0xd8,
  35385. 0xab,
  35386. 0x4d,
  35387. 0x9a,
  35388. 0x2f,
  35389. 0x5e,
  35390. 0xbc,
  35391. 0x63,
  35392. 0xc6,
  35393. 0x97,
  35394. 0x35,
  35395. 0x6a,
  35396. 0xd4,
  35397. 0xb3,
  35398. 0x7d,
  35399. 0xfa,
  35400. 0xef,
  35401. 0xc5,
  35402. 0x91,
  35403. 0x39,
  35404. 0x72,
  35405. 0xe4,
  35406. 0xd3,
  35407. 0xbd,
  35408. 0x61,
  35409. 0xc2,
  35410. 0x9f,
  35411. 0x25,
  35412. 0x4a,
  35413. 0x94,
  35414. 0x33,
  35415. 0x66,
  35416. 0xcc,
  35417. 0x83,
  35418. 0x1d,
  35419. 0x3a,
  35420. 0x74,
  35421. 0xe8,
  35422. 0xcb,
  35423. 0x8d,
  35424. 0x01,
  35425. 0x02,
  35426. 0x04,
  35427. 0x08,
  35428. 0x10,
  35429. 0x20,
  35430. 0x40,
  35431. 0x80,
  35432. 0x1b,
  35433. 0x36,
  35434. 0x6c,
  35435. 0xd8,
  35436. 0xab,
  35437. 0x4d,
  35438. 0x9a,
  35439. 0x2f,
  35440. 0x5e,
  35441. 0xbc,
  35442. 0x63,
  35443. 0xc6,
  35444. 0x97,
  35445. 0x35,
  35446. 0x6a,
  35447. 0xd4,
  35448. 0xb3,
  35449. 0x7d,
  35450. 0xfa,
  35451. 0xef,
  35452. 0xc5,
  35453. 0x91,
  35454. 0x39,
  35455. 0x72,
  35456. 0xe4,
  35457. 0xd3,
  35458. 0xbd,
  35459. 0x61,
  35460. 0xc2,
  35461. 0x9f,
  35462. 0x25,
  35463. 0x4a,
  35464. 0x94,
  35465. 0x33,
  35466. 0x66,
  35467. 0xcc,
  35468. 0x83,
  35469. 0x1d,
  35470. 0x3a,
  35471. 0x74,
  35472. 0xe8,
  35473. 0xcb,
  35474. 0x8d,
  35475. 0x01,
  35476. 0x02,
  35477. 0x04,
  35478. 0x08,
  35479. 0x10,
  35480. 0x20,
  35481. 0x40,
  35482. 0x80,
  35483. 0x1b,
  35484. 0x36,
  35485. 0x6c,
  35486. 0xd8,
  35487. 0xab,
  35488. 0x4d,
  35489. 0x9a,
  35490. 0x2f,
  35491. 0x5e,
  35492. 0xbc,
  35493. 0x63,
  35494. 0xc6,
  35495. 0x97,
  35496. 0x35,
  35497. 0x6a,
  35498. 0xd4,
  35499. 0xb3,
  35500. 0x7d,
  35501. 0xfa,
  35502. 0xef,
  35503. 0xc5,
  35504. 0x91,
  35505. 0x39,
  35506. 0x72,
  35507. 0xe4,
  35508. 0xd3,
  35509. 0xbd,
  35510. 0x61,
  35511. 0xc2,
  35512. 0x9f,
  35513. 0x25,
  35514. 0x4a,
  35515. 0x94,
  35516. 0x33,
  35517. 0x66,
  35518. 0xcc,
  35519. 0x83,
  35520. 0x1d,
  35521. 0x3a,
  35522. 0x74,
  35523. 0xe8,
  35524. 0xcb,
  35525. 0x8d
  35526. ]);
  35527. var s = new Uint8Array([
  35528. 0x63,
  35529. 0x7c,
  35530. 0x77,
  35531. 0x7b,
  35532. 0xf2,
  35533. 0x6b,
  35534. 0x6f,
  35535. 0xc5,
  35536. 0x30,
  35537. 0x01,
  35538. 0x67,
  35539. 0x2b,
  35540. 0xfe,
  35541. 0xd7,
  35542. 0xab,
  35543. 0x76,
  35544. 0xca,
  35545. 0x82,
  35546. 0xc9,
  35547. 0x7d,
  35548. 0xfa,
  35549. 0x59,
  35550. 0x47,
  35551. 0xf0,
  35552. 0xad,
  35553. 0xd4,
  35554. 0xa2,
  35555. 0xaf,
  35556. 0x9c,
  35557. 0xa4,
  35558. 0x72,
  35559. 0xc0,
  35560. 0xb7,
  35561. 0xfd,
  35562. 0x93,
  35563. 0x26,
  35564. 0x36,
  35565. 0x3f,
  35566. 0xf7,
  35567. 0xcc,
  35568. 0x34,
  35569. 0xa5,
  35570. 0xe5,
  35571. 0xf1,
  35572. 0x71,
  35573. 0xd8,
  35574. 0x31,
  35575. 0x15,
  35576. 0x04,
  35577. 0xc7,
  35578. 0x23,
  35579. 0xc3,
  35580. 0x18,
  35581. 0x96,
  35582. 0x05,
  35583. 0x9a,
  35584. 0x07,
  35585. 0x12,
  35586. 0x80,
  35587. 0xe2,
  35588. 0xeb,
  35589. 0x27,
  35590. 0xb2,
  35591. 0x75,
  35592. 0x09,
  35593. 0x83,
  35594. 0x2c,
  35595. 0x1a,
  35596. 0x1b,
  35597. 0x6e,
  35598. 0x5a,
  35599. 0xa0,
  35600. 0x52,
  35601. 0x3b,
  35602. 0xd6,
  35603. 0xb3,
  35604. 0x29,
  35605. 0xe3,
  35606. 0x2f,
  35607. 0x84,
  35608. 0x53,
  35609. 0xd1,
  35610. 0x00,
  35611. 0xed,
  35612. 0x20,
  35613. 0xfc,
  35614. 0xb1,
  35615. 0x5b,
  35616. 0x6a,
  35617. 0xcb,
  35618. 0xbe,
  35619. 0x39,
  35620. 0x4a,
  35621. 0x4c,
  35622. 0x58,
  35623. 0xcf,
  35624. 0xd0,
  35625. 0xef,
  35626. 0xaa,
  35627. 0xfb,
  35628. 0x43,
  35629. 0x4d,
  35630. 0x33,
  35631. 0x85,
  35632. 0x45,
  35633. 0xf9,
  35634. 0x02,
  35635. 0x7f,
  35636. 0x50,
  35637. 0x3c,
  35638. 0x9f,
  35639. 0xa8,
  35640. 0x51,
  35641. 0xa3,
  35642. 0x40,
  35643. 0x8f,
  35644. 0x92,
  35645. 0x9d,
  35646. 0x38,
  35647. 0xf5,
  35648. 0xbc,
  35649. 0xb6,
  35650. 0xda,
  35651. 0x21,
  35652. 0x10,
  35653. 0xff,
  35654. 0xf3,
  35655. 0xd2,
  35656. 0xcd,
  35657. 0x0c,
  35658. 0x13,
  35659. 0xec,
  35660. 0x5f,
  35661. 0x97,
  35662. 0x44,
  35663. 0x17,
  35664. 0xc4,
  35665. 0xa7,
  35666. 0x7e,
  35667. 0x3d,
  35668. 0x64,
  35669. 0x5d,
  35670. 0x19,
  35671. 0x73,
  35672. 0x60,
  35673. 0x81,
  35674. 0x4f,
  35675. 0xdc,
  35676. 0x22,
  35677. 0x2a,
  35678. 0x90,
  35679. 0x88,
  35680. 0x46,
  35681. 0xee,
  35682. 0xb8,
  35683. 0x14,
  35684. 0xde,
  35685. 0x5e,
  35686. 0x0b,
  35687. 0xdb,
  35688. 0xe0,
  35689. 0x32,
  35690. 0x3a,
  35691. 0x0a,
  35692. 0x49,
  35693. 0x06,
  35694. 0x24,
  35695. 0x5c,
  35696. 0xc2,
  35697. 0xd3,
  35698. 0xac,
  35699. 0x62,
  35700. 0x91,
  35701. 0x95,
  35702. 0xe4,
  35703. 0x79,
  35704. 0xe7,
  35705. 0xc8,
  35706. 0x37,
  35707. 0x6d,
  35708. 0x8d,
  35709. 0xd5,
  35710. 0x4e,
  35711. 0xa9,
  35712. 0x6c,
  35713. 0x56,
  35714. 0xf4,
  35715. 0xea,
  35716. 0x65,
  35717. 0x7a,
  35718. 0xae,
  35719. 0x08,
  35720. 0xba,
  35721. 0x78,
  35722. 0x25,
  35723. 0x2e,
  35724. 0x1c,
  35725. 0xa6,
  35726. 0xb4,
  35727. 0xc6,
  35728. 0xe8,
  35729. 0xdd,
  35730. 0x74,
  35731. 0x1f,
  35732. 0x4b,
  35733. 0xbd,
  35734. 0x8b,
  35735. 0x8a,
  35736. 0x70,
  35737. 0x3e,
  35738. 0xb5,
  35739. 0x66,
  35740. 0x48,
  35741. 0x03,
  35742. 0xf6,
  35743. 0x0e,
  35744. 0x61,
  35745. 0x35,
  35746. 0x57,
  35747. 0xb9,
  35748. 0x86,
  35749. 0xc1,
  35750. 0x1d,
  35751. 0x9e,
  35752. 0xe1,
  35753. 0xf8,
  35754. 0x98,
  35755. 0x11,
  35756. 0x69,
  35757. 0xd9,
  35758. 0x8e,
  35759. 0x94,
  35760. 0x9b,
  35761. 0x1e,
  35762. 0x87,
  35763. 0xe9,
  35764. 0xce,
  35765. 0x55,
  35766. 0x28,
  35767. 0xdf,
  35768. 0x8c,
  35769. 0xa1,
  35770. 0x89,
  35771. 0x0d,
  35772. 0xbf,
  35773. 0xe6,
  35774. 0x42,
  35775. 0x68,
  35776. 0x41,
  35777. 0x99,
  35778. 0x2d,
  35779. 0x0f,
  35780. 0xb0,
  35781. 0x54,
  35782. 0xbb,
  35783. 0x16
  35784. ]);
  35785. var inv_s = new Uint8Array([
  35786. 0x52,
  35787. 0x09,
  35788. 0x6a,
  35789. 0xd5,
  35790. 0x30,
  35791. 0x36,
  35792. 0xa5,
  35793. 0x38,
  35794. 0xbf,
  35795. 0x40,
  35796. 0xa3,
  35797. 0x9e,
  35798. 0x81,
  35799. 0xf3,
  35800. 0xd7,
  35801. 0xfb,
  35802. 0x7c,
  35803. 0xe3,
  35804. 0x39,
  35805. 0x82,
  35806. 0x9b,
  35807. 0x2f,
  35808. 0xff,
  35809. 0x87,
  35810. 0x34,
  35811. 0x8e,
  35812. 0x43,
  35813. 0x44,
  35814. 0xc4,
  35815. 0xde,
  35816. 0xe9,
  35817. 0xcb,
  35818. 0x54,
  35819. 0x7b,
  35820. 0x94,
  35821. 0x32,
  35822. 0xa6,
  35823. 0xc2,
  35824. 0x23,
  35825. 0x3d,
  35826. 0xee,
  35827. 0x4c,
  35828. 0x95,
  35829. 0x0b,
  35830. 0x42,
  35831. 0xfa,
  35832. 0xc3,
  35833. 0x4e,
  35834. 0x08,
  35835. 0x2e,
  35836. 0xa1,
  35837. 0x66,
  35838. 0x28,
  35839. 0xd9,
  35840. 0x24,
  35841. 0xb2,
  35842. 0x76,
  35843. 0x5b,
  35844. 0xa2,
  35845. 0x49,
  35846. 0x6d,
  35847. 0x8b,
  35848. 0xd1,
  35849. 0x25,
  35850. 0x72,
  35851. 0xf8,
  35852. 0xf6,
  35853. 0x64,
  35854. 0x86,
  35855. 0x68,
  35856. 0x98,
  35857. 0x16,
  35858. 0xd4,
  35859. 0xa4,
  35860. 0x5c,
  35861. 0xcc,
  35862. 0x5d,
  35863. 0x65,
  35864. 0xb6,
  35865. 0x92,
  35866. 0x6c,
  35867. 0x70,
  35868. 0x48,
  35869. 0x50,
  35870. 0xfd,
  35871. 0xed,
  35872. 0xb9,
  35873. 0xda,
  35874. 0x5e,
  35875. 0x15,
  35876. 0x46,
  35877. 0x57,
  35878. 0xa7,
  35879. 0x8d,
  35880. 0x9d,
  35881. 0x84,
  35882. 0x90,
  35883. 0xd8,
  35884. 0xab,
  35885. 0x00,
  35886. 0x8c,
  35887. 0xbc,
  35888. 0xd3,
  35889. 0x0a,
  35890. 0xf7,
  35891. 0xe4,
  35892. 0x58,
  35893. 0x05,
  35894. 0xb8,
  35895. 0xb3,
  35896. 0x45,
  35897. 0x06,
  35898. 0xd0,
  35899. 0x2c,
  35900. 0x1e,
  35901. 0x8f,
  35902. 0xca,
  35903. 0x3f,
  35904. 0x0f,
  35905. 0x02,
  35906. 0xc1,
  35907. 0xaf,
  35908. 0xbd,
  35909. 0x03,
  35910. 0x01,
  35911. 0x13,
  35912. 0x8a,
  35913. 0x6b,
  35914. 0x3a,
  35915. 0x91,
  35916. 0x11,
  35917. 0x41,
  35918. 0x4f,
  35919. 0x67,
  35920. 0xdc,
  35921. 0xea,
  35922. 0x97,
  35923. 0xf2,
  35924. 0xcf,
  35925. 0xce,
  35926. 0xf0,
  35927. 0xb4,
  35928. 0xe6,
  35929. 0x73,
  35930. 0x96,
  35931. 0xac,
  35932. 0x74,
  35933. 0x22,
  35934. 0xe7,
  35935. 0xad,
  35936. 0x35,
  35937. 0x85,
  35938. 0xe2,
  35939. 0xf9,
  35940. 0x37,
  35941. 0xe8,
  35942. 0x1c,
  35943. 0x75,
  35944. 0xdf,
  35945. 0x6e,
  35946. 0x47,
  35947. 0xf1,
  35948. 0x1a,
  35949. 0x71,
  35950. 0x1d,
  35951. 0x29,
  35952. 0xc5,
  35953. 0x89,
  35954. 0x6f,
  35955. 0xb7,
  35956. 0x62,
  35957. 0x0e,
  35958. 0xaa,
  35959. 0x18,
  35960. 0xbe,
  35961. 0x1b,
  35962. 0xfc,
  35963. 0x56,
  35964. 0x3e,
  35965. 0x4b,
  35966. 0xc6,
  35967. 0xd2,
  35968. 0x79,
  35969. 0x20,
  35970. 0x9a,
  35971. 0xdb,
  35972. 0xc0,
  35973. 0xfe,
  35974. 0x78,
  35975. 0xcd,
  35976. 0x5a,
  35977. 0xf4,
  35978. 0x1f,
  35979. 0xdd,
  35980. 0xa8,
  35981. 0x33,
  35982. 0x88,
  35983. 0x07,
  35984. 0xc7,
  35985. 0x31,
  35986. 0xb1,
  35987. 0x12,
  35988. 0x10,
  35989. 0x59,
  35990. 0x27,
  35991. 0x80,
  35992. 0xec,
  35993. 0x5f,
  35994. 0x60,
  35995. 0x51,
  35996. 0x7f,
  35997. 0xa9,
  35998. 0x19,
  35999. 0xb5,
  36000. 0x4a,
  36001. 0x0d,
  36002. 0x2d,
  36003. 0xe5,
  36004. 0x7a,
  36005. 0x9f,
  36006. 0x93,
  36007. 0xc9,
  36008. 0x9c,
  36009. 0xef,
  36010. 0xa0,
  36011. 0xe0,
  36012. 0x3b,
  36013. 0x4d,
  36014. 0xae,
  36015. 0x2a,
  36016. 0xf5,
  36017. 0xb0,
  36018. 0xc8,
  36019. 0xeb,
  36020. 0xbb,
  36021. 0x3c,
  36022. 0x83,
  36023. 0x53,
  36024. 0x99,
  36025. 0x61,
  36026. 0x17,
  36027. 0x2b,
  36028. 0x04,
  36029. 0x7e,
  36030. 0xba,
  36031. 0x77,
  36032. 0xd6,
  36033. 0x26,
  36034. 0xe1,
  36035. 0x69,
  36036. 0x14,
  36037. 0x63,
  36038. 0x55,
  36039. 0x21,
  36040. 0x0c,
  36041. 0x7d
  36042. ]);
  36043. var mixCol = new Uint8Array(256);
  36044. for (var i = 0; i < 256; i++) {
  36045. if (i < 128) {
  36046. mixCol[i] = i << 1;
  36047. } else {
  36048. mixCol[i] = i << 1 ^ 0x1b;
  36049. }
  36050. }
  36051. var mix = new Uint32Array([
  36052. 0x00000000,
  36053. 0x0e090d0b,
  36054. 0x1c121a16,
  36055. 0x121b171d,
  36056. 0x3824342c,
  36057. 0x362d3927,
  36058. 0x24362e3a,
  36059. 0x2a3f2331,
  36060. 0x70486858,
  36061. 0x7e416553,
  36062. 0x6c5a724e,
  36063. 0x62537f45,
  36064. 0x486c5c74,
  36065. 0x4665517f,
  36066. 0x547e4662,
  36067. 0x5a774b69,
  36068. 0xe090d0b0,
  36069. 0xee99ddbb,
  36070. 0xfc82caa6,
  36071. 0xf28bc7ad,
  36072. 0xd8b4e49c,
  36073. 0xd6bde997,
  36074. 0xc4a6fe8a,
  36075. 0xcaaff381,
  36076. 0x90d8b8e8,
  36077. 0x9ed1b5e3,
  36078. 0x8ccaa2fe,
  36079. 0x82c3aff5,
  36080. 0xa8fc8cc4,
  36081. 0xa6f581cf,
  36082. 0xb4ee96d2,
  36083. 0xbae79bd9,
  36084. 0xdb3bbb7b,
  36085. 0xd532b670,
  36086. 0xc729a16d,
  36087. 0xc920ac66,
  36088. 0xe31f8f57,
  36089. 0xed16825c,
  36090. 0xff0d9541,
  36091. 0xf104984a,
  36092. 0xab73d323,
  36093. 0xa57ade28,
  36094. 0xb761c935,
  36095. 0xb968c43e,
  36096. 0x9357e70f,
  36097. 0x9d5eea04,
  36098. 0x8f45fd19,
  36099. 0x814cf012,
  36100. 0x3bab6bcb,
  36101. 0x35a266c0,
  36102. 0x27b971dd,
  36103. 0x29b07cd6,
  36104. 0x038f5fe7,
  36105. 0x0d8652ec,
  36106. 0x1f9d45f1,
  36107. 0x119448fa,
  36108. 0x4be30393,
  36109. 0x45ea0e98,
  36110. 0x57f11985,
  36111. 0x59f8148e,
  36112. 0x73c737bf,
  36113. 0x7dce3ab4,
  36114. 0x6fd52da9,
  36115. 0x61dc20a2,
  36116. 0xad766df6,
  36117. 0xa37f60fd,
  36118. 0xb16477e0,
  36119. 0xbf6d7aeb,
  36120. 0x955259da,
  36121. 0x9b5b54d1,
  36122. 0x894043cc,
  36123. 0x87494ec7,
  36124. 0xdd3e05ae,
  36125. 0xd33708a5,
  36126. 0xc12c1fb8,
  36127. 0xcf2512b3,
  36128. 0xe51a3182,
  36129. 0xeb133c89,
  36130. 0xf9082b94,
  36131. 0xf701269f,
  36132. 0x4de6bd46,
  36133. 0x43efb04d,
  36134. 0x51f4a750,
  36135. 0x5ffdaa5b,
  36136. 0x75c2896a,
  36137. 0x7bcb8461,
  36138. 0x69d0937c,
  36139. 0x67d99e77,
  36140. 0x3daed51e,
  36141. 0x33a7d815,
  36142. 0x21bccf08,
  36143. 0x2fb5c203,
  36144. 0x058ae132,
  36145. 0x0b83ec39,
  36146. 0x1998fb24,
  36147. 0x1791f62f,
  36148. 0x764dd68d,
  36149. 0x7844db86,
  36150. 0x6a5fcc9b,
  36151. 0x6456c190,
  36152. 0x4e69e2a1,
  36153. 0x4060efaa,
  36154. 0x527bf8b7,
  36155. 0x5c72f5bc,
  36156. 0x0605bed5,
  36157. 0x080cb3de,
  36158. 0x1a17a4c3,
  36159. 0x141ea9c8,
  36160. 0x3e218af9,
  36161. 0x302887f2,
  36162. 0x223390ef,
  36163. 0x2c3a9de4,
  36164. 0x96dd063d,
  36165. 0x98d40b36,
  36166. 0x8acf1c2b,
  36167. 0x84c61120,
  36168. 0xaef93211,
  36169. 0xa0f03f1a,
  36170. 0xb2eb2807,
  36171. 0xbce2250c,
  36172. 0xe6956e65,
  36173. 0xe89c636e,
  36174. 0xfa877473,
  36175. 0xf48e7978,
  36176. 0xdeb15a49,
  36177. 0xd0b85742,
  36178. 0xc2a3405f,
  36179. 0xccaa4d54,
  36180. 0x41ecdaf7,
  36181. 0x4fe5d7fc,
  36182. 0x5dfec0e1,
  36183. 0x53f7cdea,
  36184. 0x79c8eedb,
  36185. 0x77c1e3d0,
  36186. 0x65daf4cd,
  36187. 0x6bd3f9c6,
  36188. 0x31a4b2af,
  36189. 0x3fadbfa4,
  36190. 0x2db6a8b9,
  36191. 0x23bfa5b2,
  36192. 0x09808683,
  36193. 0x07898b88,
  36194. 0x15929c95,
  36195. 0x1b9b919e,
  36196. 0xa17c0a47,
  36197. 0xaf75074c,
  36198. 0xbd6e1051,
  36199. 0xb3671d5a,
  36200. 0x99583e6b,
  36201. 0x97513360,
  36202. 0x854a247d,
  36203. 0x8b432976,
  36204. 0xd134621f,
  36205. 0xdf3d6f14,
  36206. 0xcd267809,
  36207. 0xc32f7502,
  36208. 0xe9105633,
  36209. 0xe7195b38,
  36210. 0xf5024c25,
  36211. 0xfb0b412e,
  36212. 0x9ad7618c,
  36213. 0x94de6c87,
  36214. 0x86c57b9a,
  36215. 0x88cc7691,
  36216. 0xa2f355a0,
  36217. 0xacfa58ab,
  36218. 0xbee14fb6,
  36219. 0xb0e842bd,
  36220. 0xea9f09d4,
  36221. 0xe49604df,
  36222. 0xf68d13c2,
  36223. 0xf8841ec9,
  36224. 0xd2bb3df8,
  36225. 0xdcb230f3,
  36226. 0xcea927ee,
  36227. 0xc0a02ae5,
  36228. 0x7a47b13c,
  36229. 0x744ebc37,
  36230. 0x6655ab2a,
  36231. 0x685ca621,
  36232. 0x42638510,
  36233. 0x4c6a881b,
  36234. 0x5e719f06,
  36235. 0x5078920d,
  36236. 0x0a0fd964,
  36237. 0x0406d46f,
  36238. 0x161dc372,
  36239. 0x1814ce79,
  36240. 0x322bed48,
  36241. 0x3c22e043,
  36242. 0x2e39f75e,
  36243. 0x2030fa55,
  36244. 0xec9ab701,
  36245. 0xe293ba0a,
  36246. 0xf088ad17,
  36247. 0xfe81a01c,
  36248. 0xd4be832d,
  36249. 0xdab78e26,
  36250. 0xc8ac993b,
  36251. 0xc6a59430,
  36252. 0x9cd2df59,
  36253. 0x92dbd252,
  36254. 0x80c0c54f,
  36255. 0x8ec9c844,
  36256. 0xa4f6eb75,
  36257. 0xaaffe67e,
  36258. 0xb8e4f163,
  36259. 0xb6edfc68,
  36260. 0x0c0a67b1,
  36261. 0x02036aba,
  36262. 0x10187da7,
  36263. 0x1e1170ac,
  36264. 0x342e539d,
  36265. 0x3a275e96,
  36266. 0x283c498b,
  36267. 0x26354480,
  36268. 0x7c420fe9,
  36269. 0x724b02e2,
  36270. 0x605015ff,
  36271. 0x6e5918f4,
  36272. 0x44663bc5,
  36273. 0x4a6f36ce,
  36274. 0x587421d3,
  36275. 0x567d2cd8,
  36276. 0x37a10c7a,
  36277. 0x39a80171,
  36278. 0x2bb3166c,
  36279. 0x25ba1b67,
  36280. 0x0f853856,
  36281. 0x018c355d,
  36282. 0x13972240,
  36283. 0x1d9e2f4b,
  36284. 0x47e96422,
  36285. 0x49e06929,
  36286. 0x5bfb7e34,
  36287. 0x55f2733f,
  36288. 0x7fcd500e,
  36289. 0x71c45d05,
  36290. 0x63df4a18,
  36291. 0x6dd64713,
  36292. 0xd731dcca,
  36293. 0xd938d1c1,
  36294. 0xcb23c6dc,
  36295. 0xc52acbd7,
  36296. 0xef15e8e6,
  36297. 0xe11ce5ed,
  36298. 0xf307f2f0,
  36299. 0xfd0efffb,
  36300. 0xa779b492,
  36301. 0xa970b999,
  36302. 0xbb6bae84,
  36303. 0xb562a38f,
  36304. 0x9f5d80be,
  36305. 0x91548db5,
  36306. 0x834f9aa8,
  36307. 0x8d4697a3
  36308. ]);
  36309. function expandKey128(cipherKey) {
  36310. var b = 176, result = new Uint8Array(b);
  36311. result.set(cipherKey);
  36312. for (var j = 16, i = 1; j < b; ++i) {
  36313. // RotWord
  36314. var t1 = result[j - 3], t2 = result[j - 2], t3 = result[j - 1], t4 = result[j - 4];
  36315. // SubWord
  36316. t1 = s[t1];
  36317. t2 = s[t2];
  36318. t3 = s[t3];
  36319. t4 = s[t4];
  36320. // Rcon
  36321. t1 = t1 ^ rcon[i];
  36322. for (var n = 0; n < 4; ++n) {
  36323. result[j] = t1 ^= result[j - 16];
  36324. j++;
  36325. result[j] = t2 ^= result[j - 16];
  36326. j++;
  36327. result[j] = t3 ^= result[j - 16];
  36328. j++;
  36329. result[j] = t4 ^= result[j - 16];
  36330. j++;
  36331. }
  36332. }
  36333. return result;
  36334. }
  36335. function decrypt128(input, key) {
  36336. var state = new Uint8Array(16);
  36337. state.set(input);
  36338. var i, j, k;
  36339. var t, u, v;
  36340. // AddRoundKey
  36341. for (j = 0, k = 160; j < 16; ++j, ++k) {
  36342. state[j] ^= key[k];
  36343. }
  36344. for (i = 9; i >= 1; --i) {
  36345. // InvShiftRows
  36346. t = state[13];
  36347. state[13] = state[9];
  36348. state[9] = state[5];
  36349. state[5] = state[1];
  36350. state[1] = t;
  36351. t = state[14];
  36352. u = state[10];
  36353. state[14] = state[6];
  36354. state[10] = state[2];
  36355. state[6] = t;
  36356. state[2] = u;
  36357. t = state[15];
  36358. u = state[11];
  36359. v = state[7];
  36360. state[15] = state[3];
  36361. state[11] = t;
  36362. state[7] = u;
  36363. state[3] = v;
  36364. // InvSubBytes
  36365. for (j = 0; j < 16; ++j) {
  36366. state[j] = inv_s[state[j]];
  36367. }
  36368. // AddRoundKey
  36369. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  36370. state[j] ^= key[k];
  36371. }
  36372. // InvMixColumns
  36373. for (j = 0; j < 16; j += 4) {
  36374. var s0 = mix[state[j]], s1 = mix[state[j + 1]], s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  36375. t = s0 ^ s1 >>> 8 ^ s1 << 24 ^ s2 >>> 16 ^ s2 << 16 ^ s3 >>> 24 ^ s3 << 8;
  36376. state[j] = t >>> 24 & 0xFF;
  36377. state[j + 1] = t >> 16 & 0xFF;
  36378. state[j + 2] = t >> 8 & 0xFF;
  36379. state[j + 3] = t & 0xFF;
  36380. }
  36381. }
  36382. // InvShiftRows
  36383. t = state[13];
  36384. state[13] = state[9];
  36385. state[9] = state[5];
  36386. state[5] = state[1];
  36387. state[1] = t;
  36388. t = state[14];
  36389. u = state[10];
  36390. state[14] = state[6];
  36391. state[10] = state[2];
  36392. state[6] = t;
  36393. state[2] = u;
  36394. t = state[15];
  36395. u = state[11];
  36396. v = state[7];
  36397. state[15] = state[3];
  36398. state[11] = t;
  36399. state[7] = u;
  36400. state[3] = v;
  36401. for (j = 0; j < 16; ++j) {
  36402. // InvSubBytes
  36403. state[j] = inv_s[state[j]];
  36404. // AddRoundKey
  36405. state[j] ^= key[j];
  36406. }
  36407. return state;
  36408. }
  36409. function encrypt128(input, key) {
  36410. var t, u, v, k;
  36411. var state = new Uint8Array(16);
  36412. state.set(input);
  36413. for (j = 0; j < 16; ++j) {
  36414. // AddRoundKey
  36415. state[j] ^= key[j];
  36416. }
  36417. for (i = 1; i < 10; i++) {
  36418. //SubBytes
  36419. for (j = 0; j < 16; ++j) {
  36420. state[j] = s[state[j]];
  36421. }
  36422. //ShiftRows
  36423. v = state[1];
  36424. state[1] = state[5];
  36425. state[5] = state[9];
  36426. state[9] = state[13];
  36427. state[13] = v;
  36428. v = state[2];
  36429. u = state[6];
  36430. state[2] = state[10];
  36431. state[6] = state[14];
  36432. state[10] = v;
  36433. state[14] = u;
  36434. v = state[3];
  36435. u = state[7];
  36436. t = state[11];
  36437. state[3] = state[15];
  36438. state[7] = v;
  36439. state[11] = u;
  36440. state[15] = t;
  36441. //MixColumns
  36442. for (var j = 0; j < 16; j += 4) {
  36443. var s0 = state[j + 0], s1 = state[j + 1];
  36444. var s2 = state[j + 2], s3 = state[j + 3];
  36445. t = s0 ^ s1 ^ s2 ^ s3;
  36446. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  36447. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  36448. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  36449. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  36450. }
  36451. //AddRoundKey
  36452. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  36453. state[j] ^= key[k];
  36454. }
  36455. }
  36456. //SubBytes
  36457. for (j = 0; j < 16; ++j) {
  36458. state[j] = s[state[j]];
  36459. }
  36460. //ShiftRows
  36461. v = state[1];
  36462. state[1] = state[5];
  36463. state[5] = state[9];
  36464. state[9] = state[13];
  36465. state[13] = v;
  36466. v = state[2];
  36467. u = state[6];
  36468. state[2] = state[10];
  36469. state[6] = state[14];
  36470. state[10] = v;
  36471. state[14] = u;
  36472. v = state[3];
  36473. u = state[7];
  36474. t = state[11];
  36475. state[3] = state[15];
  36476. state[7] = v;
  36477. state[11] = u;
  36478. state[15] = t;
  36479. //AddRoundKey
  36480. for (j = 0, k = 160; j < 16; ++j, ++k) {
  36481. state[j] ^= key[k];
  36482. }
  36483. return state;
  36484. }
  36485. function AES128Cipher(key) {
  36486. this.key = expandKey128(key);
  36487. this.buffer = new Uint8Array(16);
  36488. this.bufferPosition = 0;
  36489. }
  36490. function decryptBlock2(data, finalize) {
  36491. var i, j, ii, sourceLength = data.length, buffer = this.buffer, bufferLength = this.bufferPosition, result = [], iv = this.iv;
  36492. for (i = 0; i < sourceLength; ++i) {
  36493. buffer[bufferLength] = data[i];
  36494. ++bufferLength;
  36495. if (bufferLength < 16) {
  36496. continue;
  36497. }
  36498. // buffer is full, decrypting
  36499. var plain = decrypt128(buffer, this.key);
  36500. // xor-ing the IV vector to get plain text
  36501. for (j = 0; j < 16; ++j) {
  36502. plain[j] ^= iv[j];
  36503. }
  36504. iv = buffer;
  36505. result.push(plain);
  36506. buffer = new Uint8Array(16);
  36507. bufferLength = 0;
  36508. }
  36509. // saving incomplete buffer
  36510. this.buffer = buffer;
  36511. this.bufferLength = bufferLength;
  36512. this.iv = iv;
  36513. if (result.length === 0) {
  36514. return new Uint8Array([]);
  36515. }
  36516. // combining plain text blocks into one
  36517. var outputLength = 16 * result.length;
  36518. if (finalize) {
  36519. // undo a padding that is described in RFC 2898
  36520. var lastBlock = result[result.length - 1];
  36521. var psLen = lastBlock[15];
  36522. if (psLen <= 16) {
  36523. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  36524. if (lastBlock[i] !== psLen) {
  36525. // Invalid padding, assume that the block has no padding.
  36526. psLen = 0;
  36527. break;
  36528. }
  36529. }
  36530. outputLength -= psLen;
  36531. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  36532. }
  36533. }
  36534. var output = new Uint8Array(outputLength);
  36535. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  36536. output.set(result[i], j);
  36537. }
  36538. return output;
  36539. }
  36540. AES128Cipher.prototype = {
  36541. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  36542. var i, sourceLength = data.length;
  36543. var buffer = this.buffer, bufferLength = this.bufferPosition;
  36544. // waiting for IV values -- they are at the start of the stream
  36545. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  36546. buffer[bufferLength] = data[i];
  36547. }
  36548. if (bufferLength < 16) {
  36549. // need more data
  36550. this.bufferLength = bufferLength;
  36551. return new Uint8Array([]);
  36552. }
  36553. this.iv = buffer;
  36554. this.buffer = new Uint8Array(16);
  36555. this.bufferLength = 0;
  36556. // starting decryption
  36557. this.decryptBlock = decryptBlock2;
  36558. return this.decryptBlock(data.subarray(16), finalize);
  36559. },
  36560. encrypt: function AES128Cipher_encrypt(data, iv) {
  36561. var i, j, ii, sourceLength = data.length, buffer = this.buffer, bufferLength = this.bufferPosition, result = [];
  36562. if (!iv) {
  36563. iv = new Uint8Array(16);
  36564. }
  36565. for (i = 0; i < sourceLength; ++i) {
  36566. buffer[bufferLength] = data[i];
  36567. ++bufferLength;
  36568. if (bufferLength < 16) {
  36569. continue;
  36570. }
  36571. for (j = 0; j < 16; ++j) {
  36572. buffer[j] ^= iv[j];
  36573. }
  36574. // buffer is full, encrypting
  36575. var cipher = encrypt128(buffer, this.key);
  36576. iv = cipher;
  36577. result.push(cipher);
  36578. buffer = new Uint8Array(16);
  36579. bufferLength = 0;
  36580. }
  36581. // saving incomplete buffer
  36582. this.buffer = buffer;
  36583. this.bufferLength = bufferLength;
  36584. this.iv = iv;
  36585. if (result.length === 0) {
  36586. return new Uint8Array([]);
  36587. }
  36588. // combining plain text blocks into one
  36589. var outputLength = 16 * result.length;
  36590. var output = new Uint8Array(outputLength);
  36591. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  36592. output.set(result[i], j);
  36593. }
  36594. return output;
  36595. }
  36596. };
  36597. return AES128Cipher;
  36598. }();
  36599. var AES256Cipher = function AES256CipherClosure() {
  36600. var rcon = new Uint8Array([
  36601. 0x8d,
  36602. 0x01,
  36603. 0x02,
  36604. 0x04,
  36605. 0x08,
  36606. 0x10,
  36607. 0x20,
  36608. 0x40,
  36609. 0x80,
  36610. 0x1b,
  36611. 0x36,
  36612. 0x6c,
  36613. 0xd8,
  36614. 0xab,
  36615. 0x4d,
  36616. 0x9a,
  36617. 0x2f,
  36618. 0x5e,
  36619. 0xbc,
  36620. 0x63,
  36621. 0xc6,
  36622. 0x97,
  36623. 0x35,
  36624. 0x6a,
  36625. 0xd4,
  36626. 0xb3,
  36627. 0x7d,
  36628. 0xfa,
  36629. 0xef,
  36630. 0xc5,
  36631. 0x91,
  36632. 0x39,
  36633. 0x72,
  36634. 0xe4,
  36635. 0xd3,
  36636. 0xbd,
  36637. 0x61,
  36638. 0xc2,
  36639. 0x9f,
  36640. 0x25,
  36641. 0x4a,
  36642. 0x94,
  36643. 0x33,
  36644. 0x66,
  36645. 0xcc,
  36646. 0x83,
  36647. 0x1d,
  36648. 0x3a,
  36649. 0x74,
  36650. 0xe8,
  36651. 0xcb,
  36652. 0x8d,
  36653. 0x01,
  36654. 0x02,
  36655. 0x04,
  36656. 0x08,
  36657. 0x10,
  36658. 0x20,
  36659. 0x40,
  36660. 0x80,
  36661. 0x1b,
  36662. 0x36,
  36663. 0x6c,
  36664. 0xd8,
  36665. 0xab,
  36666. 0x4d,
  36667. 0x9a,
  36668. 0x2f,
  36669. 0x5e,
  36670. 0xbc,
  36671. 0x63,
  36672. 0xc6,
  36673. 0x97,
  36674. 0x35,
  36675. 0x6a,
  36676. 0xd4,
  36677. 0xb3,
  36678. 0x7d,
  36679. 0xfa,
  36680. 0xef,
  36681. 0xc5,
  36682. 0x91,
  36683. 0x39,
  36684. 0x72,
  36685. 0xe4,
  36686. 0xd3,
  36687. 0xbd,
  36688. 0x61,
  36689. 0xc2,
  36690. 0x9f,
  36691. 0x25,
  36692. 0x4a,
  36693. 0x94,
  36694. 0x33,
  36695. 0x66,
  36696. 0xcc,
  36697. 0x83,
  36698. 0x1d,
  36699. 0x3a,
  36700. 0x74,
  36701. 0xe8,
  36702. 0xcb,
  36703. 0x8d,
  36704. 0x01,
  36705. 0x02,
  36706. 0x04,
  36707. 0x08,
  36708. 0x10,
  36709. 0x20,
  36710. 0x40,
  36711. 0x80,
  36712. 0x1b,
  36713. 0x36,
  36714. 0x6c,
  36715. 0xd8,
  36716. 0xab,
  36717. 0x4d,
  36718. 0x9a,
  36719. 0x2f,
  36720. 0x5e,
  36721. 0xbc,
  36722. 0x63,
  36723. 0xc6,
  36724. 0x97,
  36725. 0x35,
  36726. 0x6a,
  36727. 0xd4,
  36728. 0xb3,
  36729. 0x7d,
  36730. 0xfa,
  36731. 0xef,
  36732. 0xc5,
  36733. 0x91,
  36734. 0x39,
  36735. 0x72,
  36736. 0xe4,
  36737. 0xd3,
  36738. 0xbd,
  36739. 0x61,
  36740. 0xc2,
  36741. 0x9f,
  36742. 0x25,
  36743. 0x4a,
  36744. 0x94,
  36745. 0x33,
  36746. 0x66,
  36747. 0xcc,
  36748. 0x83,
  36749. 0x1d,
  36750. 0x3a,
  36751. 0x74,
  36752. 0xe8,
  36753. 0xcb,
  36754. 0x8d,
  36755. 0x01,
  36756. 0x02,
  36757. 0x04,
  36758. 0x08,
  36759. 0x10,
  36760. 0x20,
  36761. 0x40,
  36762. 0x80,
  36763. 0x1b,
  36764. 0x36,
  36765. 0x6c,
  36766. 0xd8,
  36767. 0xab,
  36768. 0x4d,
  36769. 0x9a,
  36770. 0x2f,
  36771. 0x5e,
  36772. 0xbc,
  36773. 0x63,
  36774. 0xc6,
  36775. 0x97,
  36776. 0x35,
  36777. 0x6a,
  36778. 0xd4,
  36779. 0xb3,
  36780. 0x7d,
  36781. 0xfa,
  36782. 0xef,
  36783. 0xc5,
  36784. 0x91,
  36785. 0x39,
  36786. 0x72,
  36787. 0xe4,
  36788. 0xd3,
  36789. 0xbd,
  36790. 0x61,
  36791. 0xc2,
  36792. 0x9f,
  36793. 0x25,
  36794. 0x4a,
  36795. 0x94,
  36796. 0x33,
  36797. 0x66,
  36798. 0xcc,
  36799. 0x83,
  36800. 0x1d,
  36801. 0x3a,
  36802. 0x74,
  36803. 0xe8,
  36804. 0xcb,
  36805. 0x8d,
  36806. 0x01,
  36807. 0x02,
  36808. 0x04,
  36809. 0x08,
  36810. 0x10,
  36811. 0x20,
  36812. 0x40,
  36813. 0x80,
  36814. 0x1b,
  36815. 0x36,
  36816. 0x6c,
  36817. 0xd8,
  36818. 0xab,
  36819. 0x4d,
  36820. 0x9a,
  36821. 0x2f,
  36822. 0x5e,
  36823. 0xbc,
  36824. 0x63,
  36825. 0xc6,
  36826. 0x97,
  36827. 0x35,
  36828. 0x6a,
  36829. 0xd4,
  36830. 0xb3,
  36831. 0x7d,
  36832. 0xfa,
  36833. 0xef,
  36834. 0xc5,
  36835. 0x91,
  36836. 0x39,
  36837. 0x72,
  36838. 0xe4,
  36839. 0xd3,
  36840. 0xbd,
  36841. 0x61,
  36842. 0xc2,
  36843. 0x9f,
  36844. 0x25,
  36845. 0x4a,
  36846. 0x94,
  36847. 0x33,
  36848. 0x66,
  36849. 0xcc,
  36850. 0x83,
  36851. 0x1d,
  36852. 0x3a,
  36853. 0x74,
  36854. 0xe8,
  36855. 0xcb,
  36856. 0x8d
  36857. ]);
  36858. var s = new Uint8Array([
  36859. 0x63,
  36860. 0x7c,
  36861. 0x77,
  36862. 0x7b,
  36863. 0xf2,
  36864. 0x6b,
  36865. 0x6f,
  36866. 0xc5,
  36867. 0x30,
  36868. 0x01,
  36869. 0x67,
  36870. 0x2b,
  36871. 0xfe,
  36872. 0xd7,
  36873. 0xab,
  36874. 0x76,
  36875. 0xca,
  36876. 0x82,
  36877. 0xc9,
  36878. 0x7d,
  36879. 0xfa,
  36880. 0x59,
  36881. 0x47,
  36882. 0xf0,
  36883. 0xad,
  36884. 0xd4,
  36885. 0xa2,
  36886. 0xaf,
  36887. 0x9c,
  36888. 0xa4,
  36889. 0x72,
  36890. 0xc0,
  36891. 0xb7,
  36892. 0xfd,
  36893. 0x93,
  36894. 0x26,
  36895. 0x36,
  36896. 0x3f,
  36897. 0xf7,
  36898. 0xcc,
  36899. 0x34,
  36900. 0xa5,
  36901. 0xe5,
  36902. 0xf1,
  36903. 0x71,
  36904. 0xd8,
  36905. 0x31,
  36906. 0x15,
  36907. 0x04,
  36908. 0xc7,
  36909. 0x23,
  36910. 0xc3,
  36911. 0x18,
  36912. 0x96,
  36913. 0x05,
  36914. 0x9a,
  36915. 0x07,
  36916. 0x12,
  36917. 0x80,
  36918. 0xe2,
  36919. 0xeb,
  36920. 0x27,
  36921. 0xb2,
  36922. 0x75,
  36923. 0x09,
  36924. 0x83,
  36925. 0x2c,
  36926. 0x1a,
  36927. 0x1b,
  36928. 0x6e,
  36929. 0x5a,
  36930. 0xa0,
  36931. 0x52,
  36932. 0x3b,
  36933. 0xd6,
  36934. 0xb3,
  36935. 0x29,
  36936. 0xe3,
  36937. 0x2f,
  36938. 0x84,
  36939. 0x53,
  36940. 0xd1,
  36941. 0x00,
  36942. 0xed,
  36943. 0x20,
  36944. 0xfc,
  36945. 0xb1,
  36946. 0x5b,
  36947. 0x6a,
  36948. 0xcb,
  36949. 0xbe,
  36950. 0x39,
  36951. 0x4a,
  36952. 0x4c,
  36953. 0x58,
  36954. 0xcf,
  36955. 0xd0,
  36956. 0xef,
  36957. 0xaa,
  36958. 0xfb,
  36959. 0x43,
  36960. 0x4d,
  36961. 0x33,
  36962. 0x85,
  36963. 0x45,
  36964. 0xf9,
  36965. 0x02,
  36966. 0x7f,
  36967. 0x50,
  36968. 0x3c,
  36969. 0x9f,
  36970. 0xa8,
  36971. 0x51,
  36972. 0xa3,
  36973. 0x40,
  36974. 0x8f,
  36975. 0x92,
  36976. 0x9d,
  36977. 0x38,
  36978. 0xf5,
  36979. 0xbc,
  36980. 0xb6,
  36981. 0xda,
  36982. 0x21,
  36983. 0x10,
  36984. 0xff,
  36985. 0xf3,
  36986. 0xd2,
  36987. 0xcd,
  36988. 0x0c,
  36989. 0x13,
  36990. 0xec,
  36991. 0x5f,
  36992. 0x97,
  36993. 0x44,
  36994. 0x17,
  36995. 0xc4,
  36996. 0xa7,
  36997. 0x7e,
  36998. 0x3d,
  36999. 0x64,
  37000. 0x5d,
  37001. 0x19,
  37002. 0x73,
  37003. 0x60,
  37004. 0x81,
  37005. 0x4f,
  37006. 0xdc,
  37007. 0x22,
  37008. 0x2a,
  37009. 0x90,
  37010. 0x88,
  37011. 0x46,
  37012. 0xee,
  37013. 0xb8,
  37014. 0x14,
  37015. 0xde,
  37016. 0x5e,
  37017. 0x0b,
  37018. 0xdb,
  37019. 0xe0,
  37020. 0x32,
  37021. 0x3a,
  37022. 0x0a,
  37023. 0x49,
  37024. 0x06,
  37025. 0x24,
  37026. 0x5c,
  37027. 0xc2,
  37028. 0xd3,
  37029. 0xac,
  37030. 0x62,
  37031. 0x91,
  37032. 0x95,
  37033. 0xe4,
  37034. 0x79,
  37035. 0xe7,
  37036. 0xc8,
  37037. 0x37,
  37038. 0x6d,
  37039. 0x8d,
  37040. 0xd5,
  37041. 0x4e,
  37042. 0xa9,
  37043. 0x6c,
  37044. 0x56,
  37045. 0xf4,
  37046. 0xea,
  37047. 0x65,
  37048. 0x7a,
  37049. 0xae,
  37050. 0x08,
  37051. 0xba,
  37052. 0x78,
  37053. 0x25,
  37054. 0x2e,
  37055. 0x1c,
  37056. 0xa6,
  37057. 0xb4,
  37058. 0xc6,
  37059. 0xe8,
  37060. 0xdd,
  37061. 0x74,
  37062. 0x1f,
  37063. 0x4b,
  37064. 0xbd,
  37065. 0x8b,
  37066. 0x8a,
  37067. 0x70,
  37068. 0x3e,
  37069. 0xb5,
  37070. 0x66,
  37071. 0x48,
  37072. 0x03,
  37073. 0xf6,
  37074. 0x0e,
  37075. 0x61,
  37076. 0x35,
  37077. 0x57,
  37078. 0xb9,
  37079. 0x86,
  37080. 0xc1,
  37081. 0x1d,
  37082. 0x9e,
  37083. 0xe1,
  37084. 0xf8,
  37085. 0x98,
  37086. 0x11,
  37087. 0x69,
  37088. 0xd9,
  37089. 0x8e,
  37090. 0x94,
  37091. 0x9b,
  37092. 0x1e,
  37093. 0x87,
  37094. 0xe9,
  37095. 0xce,
  37096. 0x55,
  37097. 0x28,
  37098. 0xdf,
  37099. 0x8c,
  37100. 0xa1,
  37101. 0x89,
  37102. 0x0d,
  37103. 0xbf,
  37104. 0xe6,
  37105. 0x42,
  37106. 0x68,
  37107. 0x41,
  37108. 0x99,
  37109. 0x2d,
  37110. 0x0f,
  37111. 0xb0,
  37112. 0x54,
  37113. 0xbb,
  37114. 0x16
  37115. ]);
  37116. var inv_s = new Uint8Array([
  37117. 0x52,
  37118. 0x09,
  37119. 0x6a,
  37120. 0xd5,
  37121. 0x30,
  37122. 0x36,
  37123. 0xa5,
  37124. 0x38,
  37125. 0xbf,
  37126. 0x40,
  37127. 0xa3,
  37128. 0x9e,
  37129. 0x81,
  37130. 0xf3,
  37131. 0xd7,
  37132. 0xfb,
  37133. 0x7c,
  37134. 0xe3,
  37135. 0x39,
  37136. 0x82,
  37137. 0x9b,
  37138. 0x2f,
  37139. 0xff,
  37140. 0x87,
  37141. 0x34,
  37142. 0x8e,
  37143. 0x43,
  37144. 0x44,
  37145. 0xc4,
  37146. 0xde,
  37147. 0xe9,
  37148. 0xcb,
  37149. 0x54,
  37150. 0x7b,
  37151. 0x94,
  37152. 0x32,
  37153. 0xa6,
  37154. 0xc2,
  37155. 0x23,
  37156. 0x3d,
  37157. 0xee,
  37158. 0x4c,
  37159. 0x95,
  37160. 0x0b,
  37161. 0x42,
  37162. 0xfa,
  37163. 0xc3,
  37164. 0x4e,
  37165. 0x08,
  37166. 0x2e,
  37167. 0xa1,
  37168. 0x66,
  37169. 0x28,
  37170. 0xd9,
  37171. 0x24,
  37172. 0xb2,
  37173. 0x76,
  37174. 0x5b,
  37175. 0xa2,
  37176. 0x49,
  37177. 0x6d,
  37178. 0x8b,
  37179. 0xd1,
  37180. 0x25,
  37181. 0x72,
  37182. 0xf8,
  37183. 0xf6,
  37184. 0x64,
  37185. 0x86,
  37186. 0x68,
  37187. 0x98,
  37188. 0x16,
  37189. 0xd4,
  37190. 0xa4,
  37191. 0x5c,
  37192. 0xcc,
  37193. 0x5d,
  37194. 0x65,
  37195. 0xb6,
  37196. 0x92,
  37197. 0x6c,
  37198. 0x70,
  37199. 0x48,
  37200. 0x50,
  37201. 0xfd,
  37202. 0xed,
  37203. 0xb9,
  37204. 0xda,
  37205. 0x5e,
  37206. 0x15,
  37207. 0x46,
  37208. 0x57,
  37209. 0xa7,
  37210. 0x8d,
  37211. 0x9d,
  37212. 0x84,
  37213. 0x90,
  37214. 0xd8,
  37215. 0xab,
  37216. 0x00,
  37217. 0x8c,
  37218. 0xbc,
  37219. 0xd3,
  37220. 0x0a,
  37221. 0xf7,
  37222. 0xe4,
  37223. 0x58,
  37224. 0x05,
  37225. 0xb8,
  37226. 0xb3,
  37227. 0x45,
  37228. 0x06,
  37229. 0xd0,
  37230. 0x2c,
  37231. 0x1e,
  37232. 0x8f,
  37233. 0xca,
  37234. 0x3f,
  37235. 0x0f,
  37236. 0x02,
  37237. 0xc1,
  37238. 0xaf,
  37239. 0xbd,
  37240. 0x03,
  37241. 0x01,
  37242. 0x13,
  37243. 0x8a,
  37244. 0x6b,
  37245. 0x3a,
  37246. 0x91,
  37247. 0x11,
  37248. 0x41,
  37249. 0x4f,
  37250. 0x67,
  37251. 0xdc,
  37252. 0xea,
  37253. 0x97,
  37254. 0xf2,
  37255. 0xcf,
  37256. 0xce,
  37257. 0xf0,
  37258. 0xb4,
  37259. 0xe6,
  37260. 0x73,
  37261. 0x96,
  37262. 0xac,
  37263. 0x74,
  37264. 0x22,
  37265. 0xe7,
  37266. 0xad,
  37267. 0x35,
  37268. 0x85,
  37269. 0xe2,
  37270. 0xf9,
  37271. 0x37,
  37272. 0xe8,
  37273. 0x1c,
  37274. 0x75,
  37275. 0xdf,
  37276. 0x6e,
  37277. 0x47,
  37278. 0xf1,
  37279. 0x1a,
  37280. 0x71,
  37281. 0x1d,
  37282. 0x29,
  37283. 0xc5,
  37284. 0x89,
  37285. 0x6f,
  37286. 0xb7,
  37287. 0x62,
  37288. 0x0e,
  37289. 0xaa,
  37290. 0x18,
  37291. 0xbe,
  37292. 0x1b,
  37293. 0xfc,
  37294. 0x56,
  37295. 0x3e,
  37296. 0x4b,
  37297. 0xc6,
  37298. 0xd2,
  37299. 0x79,
  37300. 0x20,
  37301. 0x9a,
  37302. 0xdb,
  37303. 0xc0,
  37304. 0xfe,
  37305. 0x78,
  37306. 0xcd,
  37307. 0x5a,
  37308. 0xf4,
  37309. 0x1f,
  37310. 0xdd,
  37311. 0xa8,
  37312. 0x33,
  37313. 0x88,
  37314. 0x07,
  37315. 0xc7,
  37316. 0x31,
  37317. 0xb1,
  37318. 0x12,
  37319. 0x10,
  37320. 0x59,
  37321. 0x27,
  37322. 0x80,
  37323. 0xec,
  37324. 0x5f,
  37325. 0x60,
  37326. 0x51,
  37327. 0x7f,
  37328. 0xa9,
  37329. 0x19,
  37330. 0xb5,
  37331. 0x4a,
  37332. 0x0d,
  37333. 0x2d,
  37334. 0xe5,
  37335. 0x7a,
  37336. 0x9f,
  37337. 0x93,
  37338. 0xc9,
  37339. 0x9c,
  37340. 0xef,
  37341. 0xa0,
  37342. 0xe0,
  37343. 0x3b,
  37344. 0x4d,
  37345. 0xae,
  37346. 0x2a,
  37347. 0xf5,
  37348. 0xb0,
  37349. 0xc8,
  37350. 0xeb,
  37351. 0xbb,
  37352. 0x3c,
  37353. 0x83,
  37354. 0x53,
  37355. 0x99,
  37356. 0x61,
  37357. 0x17,
  37358. 0x2b,
  37359. 0x04,
  37360. 0x7e,
  37361. 0xba,
  37362. 0x77,
  37363. 0xd6,
  37364. 0x26,
  37365. 0xe1,
  37366. 0x69,
  37367. 0x14,
  37368. 0x63,
  37369. 0x55,
  37370. 0x21,
  37371. 0x0c,
  37372. 0x7d
  37373. ]);
  37374. var mixCol = new Uint8Array(256);
  37375. for (var i = 0; i < 256; i++) {
  37376. if (i < 128) {
  37377. mixCol[i] = i << 1;
  37378. } else {
  37379. mixCol[i] = i << 1 ^ 0x1b;
  37380. }
  37381. }
  37382. var mix = new Uint32Array([
  37383. 0x00000000,
  37384. 0x0e090d0b,
  37385. 0x1c121a16,
  37386. 0x121b171d,
  37387. 0x3824342c,
  37388. 0x362d3927,
  37389. 0x24362e3a,
  37390. 0x2a3f2331,
  37391. 0x70486858,
  37392. 0x7e416553,
  37393. 0x6c5a724e,
  37394. 0x62537f45,
  37395. 0x486c5c74,
  37396. 0x4665517f,
  37397. 0x547e4662,
  37398. 0x5a774b69,
  37399. 0xe090d0b0,
  37400. 0xee99ddbb,
  37401. 0xfc82caa6,
  37402. 0xf28bc7ad,
  37403. 0xd8b4e49c,
  37404. 0xd6bde997,
  37405. 0xc4a6fe8a,
  37406. 0xcaaff381,
  37407. 0x90d8b8e8,
  37408. 0x9ed1b5e3,
  37409. 0x8ccaa2fe,
  37410. 0x82c3aff5,
  37411. 0xa8fc8cc4,
  37412. 0xa6f581cf,
  37413. 0xb4ee96d2,
  37414. 0xbae79bd9,
  37415. 0xdb3bbb7b,
  37416. 0xd532b670,
  37417. 0xc729a16d,
  37418. 0xc920ac66,
  37419. 0xe31f8f57,
  37420. 0xed16825c,
  37421. 0xff0d9541,
  37422. 0xf104984a,
  37423. 0xab73d323,
  37424. 0xa57ade28,
  37425. 0xb761c935,
  37426. 0xb968c43e,
  37427. 0x9357e70f,
  37428. 0x9d5eea04,
  37429. 0x8f45fd19,
  37430. 0x814cf012,
  37431. 0x3bab6bcb,
  37432. 0x35a266c0,
  37433. 0x27b971dd,
  37434. 0x29b07cd6,
  37435. 0x038f5fe7,
  37436. 0x0d8652ec,
  37437. 0x1f9d45f1,
  37438. 0x119448fa,
  37439. 0x4be30393,
  37440. 0x45ea0e98,
  37441. 0x57f11985,
  37442. 0x59f8148e,
  37443. 0x73c737bf,
  37444. 0x7dce3ab4,
  37445. 0x6fd52da9,
  37446. 0x61dc20a2,
  37447. 0xad766df6,
  37448. 0xa37f60fd,
  37449. 0xb16477e0,
  37450. 0xbf6d7aeb,
  37451. 0x955259da,
  37452. 0x9b5b54d1,
  37453. 0x894043cc,
  37454. 0x87494ec7,
  37455. 0xdd3e05ae,
  37456. 0xd33708a5,
  37457. 0xc12c1fb8,
  37458. 0xcf2512b3,
  37459. 0xe51a3182,
  37460. 0xeb133c89,
  37461. 0xf9082b94,
  37462. 0xf701269f,
  37463. 0x4de6bd46,
  37464. 0x43efb04d,
  37465. 0x51f4a750,
  37466. 0x5ffdaa5b,
  37467. 0x75c2896a,
  37468. 0x7bcb8461,
  37469. 0x69d0937c,
  37470. 0x67d99e77,
  37471. 0x3daed51e,
  37472. 0x33a7d815,
  37473. 0x21bccf08,
  37474. 0x2fb5c203,
  37475. 0x058ae132,
  37476. 0x0b83ec39,
  37477. 0x1998fb24,
  37478. 0x1791f62f,
  37479. 0x764dd68d,
  37480. 0x7844db86,
  37481. 0x6a5fcc9b,
  37482. 0x6456c190,
  37483. 0x4e69e2a1,
  37484. 0x4060efaa,
  37485. 0x527bf8b7,
  37486. 0x5c72f5bc,
  37487. 0x0605bed5,
  37488. 0x080cb3de,
  37489. 0x1a17a4c3,
  37490. 0x141ea9c8,
  37491. 0x3e218af9,
  37492. 0x302887f2,
  37493. 0x223390ef,
  37494. 0x2c3a9de4,
  37495. 0x96dd063d,
  37496. 0x98d40b36,
  37497. 0x8acf1c2b,
  37498. 0x84c61120,
  37499. 0xaef93211,
  37500. 0xa0f03f1a,
  37501. 0xb2eb2807,
  37502. 0xbce2250c,
  37503. 0xe6956e65,
  37504. 0xe89c636e,
  37505. 0xfa877473,
  37506. 0xf48e7978,
  37507. 0xdeb15a49,
  37508. 0xd0b85742,
  37509. 0xc2a3405f,
  37510. 0xccaa4d54,
  37511. 0x41ecdaf7,
  37512. 0x4fe5d7fc,
  37513. 0x5dfec0e1,
  37514. 0x53f7cdea,
  37515. 0x79c8eedb,
  37516. 0x77c1e3d0,
  37517. 0x65daf4cd,
  37518. 0x6bd3f9c6,
  37519. 0x31a4b2af,
  37520. 0x3fadbfa4,
  37521. 0x2db6a8b9,
  37522. 0x23bfa5b2,
  37523. 0x09808683,
  37524. 0x07898b88,
  37525. 0x15929c95,
  37526. 0x1b9b919e,
  37527. 0xa17c0a47,
  37528. 0xaf75074c,
  37529. 0xbd6e1051,
  37530. 0xb3671d5a,
  37531. 0x99583e6b,
  37532. 0x97513360,
  37533. 0x854a247d,
  37534. 0x8b432976,
  37535. 0xd134621f,
  37536. 0xdf3d6f14,
  37537. 0xcd267809,
  37538. 0xc32f7502,
  37539. 0xe9105633,
  37540. 0xe7195b38,
  37541. 0xf5024c25,
  37542. 0xfb0b412e,
  37543. 0x9ad7618c,
  37544. 0x94de6c87,
  37545. 0x86c57b9a,
  37546. 0x88cc7691,
  37547. 0xa2f355a0,
  37548. 0xacfa58ab,
  37549. 0xbee14fb6,
  37550. 0xb0e842bd,
  37551. 0xea9f09d4,
  37552. 0xe49604df,
  37553. 0xf68d13c2,
  37554. 0xf8841ec9,
  37555. 0xd2bb3df8,
  37556. 0xdcb230f3,
  37557. 0xcea927ee,
  37558. 0xc0a02ae5,
  37559. 0x7a47b13c,
  37560. 0x744ebc37,
  37561. 0x6655ab2a,
  37562. 0x685ca621,
  37563. 0x42638510,
  37564. 0x4c6a881b,
  37565. 0x5e719f06,
  37566. 0x5078920d,
  37567. 0x0a0fd964,
  37568. 0x0406d46f,
  37569. 0x161dc372,
  37570. 0x1814ce79,
  37571. 0x322bed48,
  37572. 0x3c22e043,
  37573. 0x2e39f75e,
  37574. 0x2030fa55,
  37575. 0xec9ab701,
  37576. 0xe293ba0a,
  37577. 0xf088ad17,
  37578. 0xfe81a01c,
  37579. 0xd4be832d,
  37580. 0xdab78e26,
  37581. 0xc8ac993b,
  37582. 0xc6a59430,
  37583. 0x9cd2df59,
  37584. 0x92dbd252,
  37585. 0x80c0c54f,
  37586. 0x8ec9c844,
  37587. 0xa4f6eb75,
  37588. 0xaaffe67e,
  37589. 0xb8e4f163,
  37590. 0xb6edfc68,
  37591. 0x0c0a67b1,
  37592. 0x02036aba,
  37593. 0x10187da7,
  37594. 0x1e1170ac,
  37595. 0x342e539d,
  37596. 0x3a275e96,
  37597. 0x283c498b,
  37598. 0x26354480,
  37599. 0x7c420fe9,
  37600. 0x724b02e2,
  37601. 0x605015ff,
  37602. 0x6e5918f4,
  37603. 0x44663bc5,
  37604. 0x4a6f36ce,
  37605. 0x587421d3,
  37606. 0x567d2cd8,
  37607. 0x37a10c7a,
  37608. 0x39a80171,
  37609. 0x2bb3166c,
  37610. 0x25ba1b67,
  37611. 0x0f853856,
  37612. 0x018c355d,
  37613. 0x13972240,
  37614. 0x1d9e2f4b,
  37615. 0x47e96422,
  37616. 0x49e06929,
  37617. 0x5bfb7e34,
  37618. 0x55f2733f,
  37619. 0x7fcd500e,
  37620. 0x71c45d05,
  37621. 0x63df4a18,
  37622. 0x6dd64713,
  37623. 0xd731dcca,
  37624. 0xd938d1c1,
  37625. 0xcb23c6dc,
  37626. 0xc52acbd7,
  37627. 0xef15e8e6,
  37628. 0xe11ce5ed,
  37629. 0xf307f2f0,
  37630. 0xfd0efffb,
  37631. 0xa779b492,
  37632. 0xa970b999,
  37633. 0xbb6bae84,
  37634. 0xb562a38f,
  37635. 0x9f5d80be,
  37636. 0x91548db5,
  37637. 0x834f9aa8,
  37638. 0x8d4697a3
  37639. ]);
  37640. function expandKey256(cipherKey) {
  37641. var b = 240, result = new Uint8Array(b);
  37642. var r = 1;
  37643. result.set(cipherKey);
  37644. for (var j = 32, i = 1; j < b; ++i) {
  37645. if (j % 32 === 16) {
  37646. t1 = s[t1];
  37647. t2 = s[t2];
  37648. t3 = s[t3];
  37649. t4 = s[t4];
  37650. } else if (j % 32 === 0) {
  37651. // RotWord
  37652. var t1 = result[j - 3], t2 = result[j - 2], t3 = result[j - 1], t4 = result[j - 4];
  37653. // SubWord
  37654. t1 = s[t1];
  37655. t2 = s[t2];
  37656. t3 = s[t3];
  37657. t4 = s[t4];
  37658. // Rcon
  37659. t1 = t1 ^ r;
  37660. if ((r <<= 1) >= 256) {
  37661. r = (r ^ 0x1b) & 0xFF;
  37662. }
  37663. }
  37664. for (var n = 0; n < 4; ++n) {
  37665. result[j] = t1 ^= result[j - 32];
  37666. j++;
  37667. result[j] = t2 ^= result[j - 32];
  37668. j++;
  37669. result[j] = t3 ^= result[j - 32];
  37670. j++;
  37671. result[j] = t4 ^= result[j - 32];
  37672. j++;
  37673. }
  37674. }
  37675. return result;
  37676. }
  37677. function decrypt256(input, key) {
  37678. var state = new Uint8Array(16);
  37679. state.set(input);
  37680. var i, j, k;
  37681. var t, u, v;
  37682. // AddRoundKey
  37683. for (j = 0, k = 224; j < 16; ++j, ++k) {
  37684. state[j] ^= key[k];
  37685. }
  37686. for (i = 13; i >= 1; --i) {
  37687. // InvShiftRows
  37688. t = state[13];
  37689. state[13] = state[9];
  37690. state[9] = state[5];
  37691. state[5] = state[1];
  37692. state[1] = t;
  37693. t = state[14];
  37694. u = state[10];
  37695. state[14] = state[6];
  37696. state[10] = state[2];
  37697. state[6] = t;
  37698. state[2] = u;
  37699. t = state[15];
  37700. u = state[11];
  37701. v = state[7];
  37702. state[15] = state[3];
  37703. state[11] = t;
  37704. state[7] = u;
  37705. state[3] = v;
  37706. // InvSubBytes
  37707. for (j = 0; j < 16; ++j) {
  37708. state[j] = inv_s[state[j]];
  37709. }
  37710. // AddRoundKey
  37711. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  37712. state[j] ^= key[k];
  37713. }
  37714. // InvMixColumns
  37715. for (j = 0; j < 16; j += 4) {
  37716. var s0 = mix[state[j]], s1 = mix[state[j + 1]], s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  37717. t = s0 ^ s1 >>> 8 ^ s1 << 24 ^ s2 >>> 16 ^ s2 << 16 ^ s3 >>> 24 ^ s3 << 8;
  37718. state[j] = t >>> 24 & 0xFF;
  37719. state[j + 1] = t >> 16 & 0xFF;
  37720. state[j + 2] = t >> 8 & 0xFF;
  37721. state[j + 3] = t & 0xFF;
  37722. }
  37723. }
  37724. // InvShiftRows
  37725. t = state[13];
  37726. state[13] = state[9];
  37727. state[9] = state[5];
  37728. state[5] = state[1];
  37729. state[1] = t;
  37730. t = state[14];
  37731. u = state[10];
  37732. state[14] = state[6];
  37733. state[10] = state[2];
  37734. state[6] = t;
  37735. state[2] = u;
  37736. t = state[15];
  37737. u = state[11];
  37738. v = state[7];
  37739. state[15] = state[3];
  37740. state[11] = t;
  37741. state[7] = u;
  37742. state[3] = v;
  37743. for (j = 0; j < 16; ++j) {
  37744. // InvSubBytes
  37745. state[j] = inv_s[state[j]];
  37746. // AddRoundKey
  37747. state[j] ^= key[j];
  37748. }
  37749. return state;
  37750. }
  37751. function encrypt256(input, key) {
  37752. var t, u, v, k;
  37753. var state = new Uint8Array(16);
  37754. state.set(input);
  37755. for (j = 0; j < 16; ++j) {
  37756. // AddRoundKey
  37757. state[j] ^= key[j];
  37758. }
  37759. for (i = 1; i < 14; i++) {
  37760. //SubBytes
  37761. for (j = 0; j < 16; ++j) {
  37762. state[j] = s[state[j]];
  37763. }
  37764. //ShiftRows
  37765. v = state[1];
  37766. state[1] = state[5];
  37767. state[5] = state[9];
  37768. state[9] = state[13];
  37769. state[13] = v;
  37770. v = state[2];
  37771. u = state[6];
  37772. state[2] = state[10];
  37773. state[6] = state[14];
  37774. state[10] = v;
  37775. state[14] = u;
  37776. v = state[3];
  37777. u = state[7];
  37778. t = state[11];
  37779. state[3] = state[15];
  37780. state[7] = v;
  37781. state[11] = u;
  37782. state[15] = t;
  37783. //MixColumns
  37784. for (var j = 0; j < 16; j += 4) {
  37785. var s0 = state[j + 0], s1 = state[j + 1];
  37786. var s2 = state[j + 2], s3 = state[j + 3];
  37787. t = s0 ^ s1 ^ s2 ^ s3;
  37788. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  37789. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  37790. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  37791. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  37792. }
  37793. //AddRoundKey
  37794. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  37795. state[j] ^= key[k];
  37796. }
  37797. }
  37798. //SubBytes
  37799. for (j = 0; j < 16; ++j) {
  37800. state[j] = s[state[j]];
  37801. }
  37802. //ShiftRows
  37803. v = state[1];
  37804. state[1] = state[5];
  37805. state[5] = state[9];
  37806. state[9] = state[13];
  37807. state[13] = v;
  37808. v = state[2];
  37809. u = state[6];
  37810. state[2] = state[10];
  37811. state[6] = state[14];
  37812. state[10] = v;
  37813. state[14] = u;
  37814. v = state[3];
  37815. u = state[7];
  37816. t = state[11];
  37817. state[3] = state[15];
  37818. state[7] = v;
  37819. state[11] = u;
  37820. state[15] = t;
  37821. //AddRoundKey
  37822. for (j = 0, k = 224; j < 16; ++j, ++k) {
  37823. state[j] ^= key[k];
  37824. }
  37825. return state;
  37826. }
  37827. function AES256Cipher(key) {
  37828. this.key = expandKey256(key);
  37829. this.buffer = new Uint8Array(16);
  37830. this.bufferPosition = 0;
  37831. }
  37832. function decryptBlock2(data, finalize) {
  37833. var i, j, ii, sourceLength = data.length, buffer = this.buffer, bufferLength = this.bufferPosition, result = [], iv = this.iv;
  37834. for (i = 0; i < sourceLength; ++i) {
  37835. buffer[bufferLength] = data[i];
  37836. ++bufferLength;
  37837. if (bufferLength < 16) {
  37838. continue;
  37839. }
  37840. // buffer is full, decrypting
  37841. var plain = decrypt256(buffer, this.key);
  37842. // xor-ing the IV vector to get plain text
  37843. for (j = 0; j < 16; ++j) {
  37844. plain[j] ^= iv[j];
  37845. }
  37846. iv = buffer;
  37847. result.push(plain);
  37848. buffer = new Uint8Array(16);
  37849. bufferLength = 0;
  37850. }
  37851. // saving incomplete buffer
  37852. this.buffer = buffer;
  37853. this.bufferLength = bufferLength;
  37854. this.iv = iv;
  37855. if (result.length === 0) {
  37856. return new Uint8Array([]);
  37857. }
  37858. // combining plain text blocks into one
  37859. var outputLength = 16 * result.length;
  37860. if (finalize) {
  37861. // undo a padding that is described in RFC 2898
  37862. var lastBlock = result[result.length - 1];
  37863. var psLen = lastBlock[15];
  37864. if (psLen <= 16) {
  37865. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  37866. if (lastBlock[i] !== psLen) {
  37867. // Invalid padding, assume that the block has no padding.
  37868. psLen = 0;
  37869. break;
  37870. }
  37871. }
  37872. outputLength -= psLen;
  37873. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  37874. }
  37875. }
  37876. var output = new Uint8Array(outputLength);
  37877. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  37878. output.set(result[i], j);
  37879. }
  37880. return output;
  37881. }
  37882. AES256Cipher.prototype = {
  37883. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  37884. var i, sourceLength = data.length;
  37885. var buffer = this.buffer, bufferLength = this.bufferPosition;
  37886. // if not supplied an IV wait for IV values
  37887. // they are at the start of the stream
  37888. if (iv) {
  37889. this.iv = iv;
  37890. } else {
  37891. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  37892. buffer[bufferLength] = data[i];
  37893. }
  37894. if (bufferLength < 16) {
  37895. //need more data
  37896. this.bufferLength = bufferLength;
  37897. return new Uint8Array([]);
  37898. }
  37899. this.iv = buffer;
  37900. data = data.subarray(16);
  37901. }
  37902. this.buffer = new Uint8Array(16);
  37903. this.bufferLength = 0;
  37904. // starting decryption
  37905. this.decryptBlock = decryptBlock2;
  37906. return this.decryptBlock(data, finalize);
  37907. },
  37908. encrypt: function AES256Cipher_encrypt(data, iv) {
  37909. var i, j, ii, sourceLength = data.length, buffer = this.buffer, bufferLength = this.bufferPosition, result = [];
  37910. if (!iv) {
  37911. iv = new Uint8Array(16);
  37912. }
  37913. for (i = 0; i < sourceLength; ++i) {
  37914. buffer[bufferLength] = data[i];
  37915. ++bufferLength;
  37916. if (bufferLength < 16) {
  37917. continue;
  37918. }
  37919. for (j = 0; j < 16; ++j) {
  37920. buffer[j] ^= iv[j];
  37921. }
  37922. // buffer is full, encrypting
  37923. var cipher = encrypt256(buffer, this.key);
  37924. this.iv = cipher;
  37925. result.push(cipher);
  37926. buffer = new Uint8Array(16);
  37927. bufferLength = 0;
  37928. }
  37929. // saving incomplete buffer
  37930. this.buffer = buffer;
  37931. this.bufferLength = bufferLength;
  37932. this.iv = iv;
  37933. if (result.length === 0) {
  37934. return new Uint8Array([]);
  37935. }
  37936. // combining plain text blocks into one
  37937. var outputLength = 16 * result.length;
  37938. var output = new Uint8Array(outputLength);
  37939. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  37940. output.set(result[i], j);
  37941. }
  37942. return output;
  37943. }
  37944. };
  37945. return AES256Cipher;
  37946. }();
  37947. var PDF17 = function PDF17Closure() {
  37948. function compareByteArrays(array1, array2) {
  37949. if (array1.length !== array2.length) {
  37950. return false;
  37951. }
  37952. for (var i = 0; i < array1.length; i++) {
  37953. if (array1[i] !== array2[i]) {
  37954. return false;
  37955. }
  37956. }
  37957. return true;
  37958. }
  37959. function PDF17() {
  37960. }
  37961. PDF17.prototype = {
  37962. checkOwnerPassword: function PDF17_checkOwnerPassword(password, ownerValidationSalt, userBytes, ownerPassword) {
  37963. var hashData = new Uint8Array(password.length + 56);
  37964. hashData.set(password, 0);
  37965. hashData.set(ownerValidationSalt, password.length);
  37966. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  37967. var result = calculateSHA256(hashData, 0, hashData.length);
  37968. return compareByteArrays(result, ownerPassword);
  37969. },
  37970. checkUserPassword: function PDF17_checkUserPassword(password, userValidationSalt, userPassword) {
  37971. var hashData = new Uint8Array(password.length + 8);
  37972. hashData.set(password, 0);
  37973. hashData.set(userValidationSalt, password.length);
  37974. var result = calculateSHA256(hashData, 0, hashData.length);
  37975. return compareByteArrays(result, userPassword);
  37976. },
  37977. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes, ownerEncryption) {
  37978. var hashData = new Uint8Array(password.length + 56);
  37979. hashData.set(password, 0);
  37980. hashData.set(ownerKeySalt, password.length);
  37981. hashData.set(userBytes, password.length + ownerKeySalt.length);
  37982. var key = calculateSHA256(hashData, 0, hashData.length);
  37983. var cipher = new AES256Cipher(key);
  37984. return cipher.decryptBlock(ownerEncryption, false, new Uint8Array(16));
  37985. },
  37986. getUserKey: function PDF17_getUserKey(password, userKeySalt, userEncryption) {
  37987. var hashData = new Uint8Array(password.length + 8);
  37988. hashData.set(password, 0);
  37989. hashData.set(userKeySalt, password.length);
  37990. //key is the decryption key for the UE string
  37991. var key = calculateSHA256(hashData, 0, hashData.length);
  37992. var cipher = new AES256Cipher(key);
  37993. return cipher.decryptBlock(userEncryption, false, new Uint8Array(16));
  37994. }
  37995. };
  37996. return PDF17;
  37997. }();
  37998. var PDF20 = function PDF20Closure() {
  37999. function concatArrays(array1, array2) {
  38000. var t = new Uint8Array(array1.length + array2.length);
  38001. t.set(array1, 0);
  38002. t.set(array2, array1.length);
  38003. return t;
  38004. }
  38005. function calculatePDF20Hash(password, input, userBytes) {
  38006. //This refers to Algorithm 2.B as defined in ISO 32000-2
  38007. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  38008. var e = [0];
  38009. var i = 0;
  38010. while (i < 64 || e[e.length - 1] > i - 32) {
  38011. var arrayLength = password.length + k.length + userBytes.length;
  38012. var k1 = new Uint8Array(arrayLength * 64);
  38013. var array = concatArrays(password, k);
  38014. array = concatArrays(array, userBytes);
  38015. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  38016. k1.set(array, pos);
  38017. }
  38018. //AES128 CBC NO PADDING with
  38019. //first 16 bytes of k as the key and the second 16 as the iv.
  38020. var cipher = new AES128Cipher(k.subarray(0, 16));
  38021. e = cipher.encrypt(k1, k.subarray(16, 32));
  38022. //Now we have to take the first 16 bytes of an unsigned
  38023. //big endian integer... and compute the remainder
  38024. //modulo 3.... That is a fairly large number and
  38025. //JavaScript isn't going to handle that well...
  38026. //So we're using a trick that allows us to perform
  38027. //modulo math byte by byte
  38028. var remainder = 0;
  38029. for (var z = 0; z < 16; z++) {
  38030. remainder *= 256 % 3;
  38031. remainder %= 3;
  38032. remainder += (e[z] >>> 0) % 3;
  38033. remainder %= 3;
  38034. }
  38035. if (remainder === 0) {
  38036. k = calculateSHA256(e, 0, e.length);
  38037. } else if (remainder === 1) {
  38038. k = calculateSHA384(e, 0, e.length);
  38039. } else if (remainder === 2) {
  38040. k = calculateSHA512(e, 0, e.length);
  38041. }
  38042. i++;
  38043. }
  38044. return k.subarray(0, 32);
  38045. }
  38046. function PDF20() {
  38047. }
  38048. function compareByteArrays(array1, array2) {
  38049. if (array1.length !== array2.length) {
  38050. return false;
  38051. }
  38052. for (var i = 0; i < array1.length; i++) {
  38053. if (array1[i] !== array2[i]) {
  38054. return false;
  38055. }
  38056. }
  38057. return true;
  38058. }
  38059. PDF20.prototype = {
  38060. hash: function PDF20_hash(password, concatBytes, userBytes) {
  38061. return calculatePDF20Hash(password, concatBytes, userBytes);
  38062. },
  38063. checkOwnerPassword: function PDF20_checkOwnerPassword(password, ownerValidationSalt, userBytes, ownerPassword) {
  38064. var hashData = new Uint8Array(password.length + 56);
  38065. hashData.set(password, 0);
  38066. hashData.set(ownerValidationSalt, password.length);
  38067. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  38068. var result = calculatePDF20Hash(password, hashData, userBytes);
  38069. return compareByteArrays(result, ownerPassword);
  38070. },
  38071. checkUserPassword: function PDF20_checkUserPassword(password, userValidationSalt, userPassword) {
  38072. var hashData = new Uint8Array(password.length + 8);
  38073. hashData.set(password, 0);
  38074. hashData.set(userValidationSalt, password.length);
  38075. var result = calculatePDF20Hash(password, hashData, []);
  38076. return compareByteArrays(result, userPassword);
  38077. },
  38078. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes, ownerEncryption) {
  38079. var hashData = new Uint8Array(password.length + 56);
  38080. hashData.set(password, 0);
  38081. hashData.set(ownerKeySalt, password.length);
  38082. hashData.set(userBytes, password.length + ownerKeySalt.length);
  38083. var key = calculatePDF20Hash(password, hashData, userBytes);
  38084. var cipher = new AES256Cipher(key);
  38085. return cipher.decryptBlock(ownerEncryption, false, new Uint8Array(16));
  38086. },
  38087. getUserKey: function PDF20_getUserKey(password, userKeySalt, userEncryption) {
  38088. var hashData = new Uint8Array(password.length + 8);
  38089. hashData.set(password, 0);
  38090. hashData.set(userKeySalt, password.length);
  38091. //key is the decryption key for the UE string
  38092. var key = calculatePDF20Hash(password, hashData, []);
  38093. var cipher = new AES256Cipher(key);
  38094. return cipher.decryptBlock(userEncryption, false, new Uint8Array(16));
  38095. }
  38096. };
  38097. return PDF20;
  38098. }();
  38099. var CipherTransform = function CipherTransformClosure() {
  38100. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  38101. this.stringCipherConstructor = stringCipherConstructor;
  38102. this.streamCipherConstructor = streamCipherConstructor;
  38103. }
  38104. CipherTransform.prototype = {
  38105. createStream: function CipherTransform_createStream(stream, length) {
  38106. var cipher = new this.streamCipherConstructor();
  38107. return new DecryptStream(stream, length, function cipherTransformDecryptStream(data, finalize) {
  38108. return cipher.decryptBlock(data, finalize);
  38109. });
  38110. },
  38111. decryptString: function CipherTransform_decryptString(s) {
  38112. var cipher = new this.stringCipherConstructor();
  38113. var data = stringToBytes(s);
  38114. data = cipher.decryptBlock(data, true);
  38115. return bytesToString(data);
  38116. }
  38117. };
  38118. return CipherTransform;
  38119. }();
  38120. var CipherTransformFactory = function CipherTransformFactoryClosure() {
  38121. var defaultPasswordBytes = new Uint8Array([
  38122. 0x28,
  38123. 0xBF,
  38124. 0x4E,
  38125. 0x5E,
  38126. 0x4E,
  38127. 0x75,
  38128. 0x8A,
  38129. 0x41,
  38130. 0x64,
  38131. 0x00,
  38132. 0x4E,
  38133. 0x56,
  38134. 0xFF,
  38135. 0xFA,
  38136. 0x01,
  38137. 0x08,
  38138. 0x2E,
  38139. 0x2E,
  38140. 0x00,
  38141. 0xB6,
  38142. 0xD0,
  38143. 0x68,
  38144. 0x3E,
  38145. 0x80,
  38146. 0x2F,
  38147. 0x0C,
  38148. 0xA9,
  38149. 0xFE,
  38150. 0x64,
  38151. 0x53,
  38152. 0x69,
  38153. 0x7A
  38154. ]);
  38155. function createEncryptionKey20(revision, password, ownerPassword, ownerValidationSalt, ownerKeySalt, uBytes, userPassword, userValidationSalt, userKeySalt, ownerEncryption, userEncryption, perms) {
  38156. if (password) {
  38157. var passwordLength = Math.min(127, password.length);
  38158. password = password.subarray(0, passwordLength);
  38159. } else {
  38160. password = [];
  38161. }
  38162. var pdfAlgorithm;
  38163. if (revision === 6) {
  38164. pdfAlgorithm = new PDF20();
  38165. } else {
  38166. pdfAlgorithm = new PDF17();
  38167. }
  38168. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt, userPassword)) {
  38169. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  38170. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt, uBytes, ownerPassword)) {
  38171. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes, ownerEncryption);
  38172. }
  38173. return null;
  38174. }
  38175. function prepareKeyData(fileId, password, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata) {
  38176. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  38177. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  38178. if (password) {
  38179. n = Math.min(32, password.length);
  38180. for (; i < n; ++i) {
  38181. hashData[i] = password[i];
  38182. }
  38183. }
  38184. j = 0;
  38185. while (i < 32) {
  38186. hashData[i++] = defaultPasswordBytes[j++];
  38187. }
  38188. // as now the padded password in the hashData[0..i]
  38189. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  38190. hashData[i++] = ownerPassword[j];
  38191. }
  38192. hashData[i++] = flags & 0xFF;
  38193. hashData[i++] = flags >> 8 & 0xFF;
  38194. hashData[i++] = flags >> 16 & 0xFF;
  38195. hashData[i++] = flags >>> 24 & 0xFF;
  38196. for (j = 0, n = fileId.length; j < n; ++j) {
  38197. hashData[i++] = fileId[j];
  38198. }
  38199. if (revision >= 4 && !encryptMetadata) {
  38200. hashData[i++] = 0xFF;
  38201. hashData[i++] = 0xFF;
  38202. hashData[i++] = 0xFF;
  38203. hashData[i++] = 0xFF;
  38204. }
  38205. var hash = calculateMD5(hashData, 0, i);
  38206. var keyLengthInBytes = keyLength >> 3;
  38207. if (revision >= 3) {
  38208. for (j = 0; j < 50; ++j) {
  38209. hash = calculateMD5(hash, 0, keyLengthInBytes);
  38210. }
  38211. }
  38212. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  38213. var cipher, checkData;
  38214. if (revision >= 3) {
  38215. for (i = 0; i < 32; ++i) {
  38216. hashData[i] = defaultPasswordBytes[i];
  38217. }
  38218. for (j = 0, n = fileId.length; j < n; ++j) {
  38219. hashData[i++] = fileId[j];
  38220. }
  38221. cipher = new ARCFourCipher(encryptionKey);
  38222. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  38223. n = encryptionKey.length;
  38224. var derivedKey = new Uint8Array(n), k;
  38225. for (j = 1; j <= 19; ++j) {
  38226. for (k = 0; k < n; ++k) {
  38227. derivedKey[k] = encryptionKey[k] ^ j;
  38228. }
  38229. cipher = new ARCFourCipher(derivedKey);
  38230. checkData = cipher.encryptBlock(checkData);
  38231. }
  38232. for (j = 0, n = checkData.length; j < n; ++j) {
  38233. if (userPassword[j] !== checkData[j]) {
  38234. return null;
  38235. }
  38236. }
  38237. } else {
  38238. cipher = new ARCFourCipher(encryptionKey);
  38239. checkData = cipher.encryptBlock(defaultPasswordBytes);
  38240. for (j = 0, n = checkData.length; j < n; ++j) {
  38241. if (userPassword[j] !== checkData[j]) {
  38242. return null;
  38243. }
  38244. }
  38245. }
  38246. return encryptionKey;
  38247. }
  38248. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  38249. var hashData = new Uint8Array(32), i = 0, j, n;
  38250. n = Math.min(32, password.length);
  38251. for (; i < n; ++i) {
  38252. hashData[i] = password[i];
  38253. }
  38254. j = 0;
  38255. while (i < 32) {
  38256. hashData[i++] = defaultPasswordBytes[j++];
  38257. }
  38258. var hash = calculateMD5(hashData, 0, i);
  38259. var keyLengthInBytes = keyLength >> 3;
  38260. if (revision >= 3) {
  38261. for (j = 0; j < 50; ++j) {
  38262. hash = calculateMD5(hash, 0, hash.length);
  38263. }
  38264. }
  38265. var cipher, userPassword;
  38266. if (revision >= 3) {
  38267. userPassword = ownerPassword;
  38268. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  38269. for (j = 19; j >= 0; j--) {
  38270. for (k = 0; k < keyLengthInBytes; ++k) {
  38271. derivedKey[k] = hash[k] ^ j;
  38272. }
  38273. cipher = new ARCFourCipher(derivedKey);
  38274. userPassword = cipher.encryptBlock(userPassword);
  38275. }
  38276. } else {
  38277. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  38278. userPassword = cipher.encryptBlock(ownerPassword);
  38279. }
  38280. return userPassword;
  38281. }
  38282. var identityName = Name.get('Identity');
  38283. function CipherTransformFactory(dict, fileId, password) {
  38284. var filter = dict.get('Filter');
  38285. if (!isName(filter, 'Standard')) {
  38286. error('unknown encryption method');
  38287. }
  38288. this.dict = dict;
  38289. var algorithm = dict.get('V');
  38290. if (!isInt(algorithm) || algorithm !== 1 && algorithm !== 2 && algorithm !== 4 && algorithm !== 5) {
  38291. error('unsupported encryption algorithm');
  38292. }
  38293. this.algorithm = algorithm;
  38294. var keyLength = dict.get('Length');
  38295. if (!keyLength) {
  38296. // Spec asks to rely on encryption dictionary's Length entry, however
  38297. // some PDFs don't have it. Trying to recover.
  38298. if (algorithm <= 3) {
  38299. // For 1 and 2 it's fixed to 40-bit, for 3 40-bit is a minimal value.
  38300. keyLength = 40;
  38301. } else {
  38302. // Trying to find default handler -- it usually has Length.
  38303. var cfDict = dict.get('CF');
  38304. var streamCryptoName = dict.get('StmF');
  38305. if (isDict(cfDict) && isName(streamCryptoName)) {
  38306. cfDict.suppressEncryption = true;
  38307. // See comment below.
  38308. var handlerDict = cfDict.get(streamCryptoName.name);
  38309. keyLength = handlerDict && handlerDict.get('Length') || 128;
  38310. if (keyLength < 40) {
  38311. // Sometimes it's incorrect value of bits, generators specify bytes.
  38312. keyLength <<= 3;
  38313. }
  38314. }
  38315. }
  38316. }
  38317. if (!isInt(keyLength) || keyLength < 40 || keyLength % 8 !== 0) {
  38318. error('invalid key length');
  38319. }
  38320. // prepare keys
  38321. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  38322. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  38323. var flags = dict.get('P');
  38324. var revision = dict.get('R');
  38325. // meaningful when V is 4 or 5
  38326. var encryptMetadata = (algorithm === 4 || algorithm === 5) && dict.get('EncryptMetadata') !== false;
  38327. this.encryptMetadata = encryptMetadata;
  38328. var fileIdBytes = stringToBytes(fileId);
  38329. var passwordBytes;
  38330. if (password) {
  38331. if (revision === 6) {
  38332. try {
  38333. password = utf8StringToString(password);
  38334. } catch (ex) {
  38335. warn('CipherTransformFactory: ' + 'Unable to convert UTF8 encoded password.');
  38336. }
  38337. }
  38338. passwordBytes = stringToBytes(password);
  38339. }
  38340. var encryptionKey;
  38341. if (algorithm !== 5) {
  38342. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata);
  38343. } else {
  38344. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  38345. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  38346. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  38347. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  38348. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  38349. var ownerEncryption = stringToBytes(dict.get('OE'));
  38350. var userEncryption = stringToBytes(dict.get('UE'));
  38351. var perms = stringToBytes(dict.get('Perms'));
  38352. encryptionKey = createEncryptionKey20(revision, passwordBytes, ownerPassword, ownerValidationSalt, ownerKeySalt, uBytes, userPassword, userValidationSalt, userKeySalt, ownerEncryption, userEncryption, perms);
  38353. }
  38354. if (!encryptionKey && !password) {
  38355. throw new PasswordException('No password given', PasswordResponses.NEED_PASSWORD);
  38356. } else if (!encryptionKey && password) {
  38357. // Attempting use the password as an owner password
  38358. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword, revision, keyLength);
  38359. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata);
  38360. }
  38361. if (!encryptionKey) {
  38362. throw new PasswordException('Incorrect Password', PasswordResponses.INCORRECT_PASSWORD);
  38363. }
  38364. this.encryptionKey = encryptionKey;
  38365. if (algorithm >= 4) {
  38366. var cf = dict.get('CF');
  38367. if (isDict(cf)) {
  38368. // The 'CF' dictionary itself should not be encrypted, and by setting
  38369. // `suppressEncryption` we can prevent an infinite loop inside of
  38370. // `XRef_fetchUncompressed` if the dictionary contains indirect objects
  38371. // (fixes issue7665.pdf).
  38372. cf.suppressEncryption = true;
  38373. }
  38374. this.cf = cf;
  38375. this.stmf = dict.get('StmF') || identityName;
  38376. this.strf = dict.get('StrF') || identityName;
  38377. this.eff = dict.get('EFF') || this.stmf;
  38378. }
  38379. }
  38380. function buildObjectKey(num, gen, encryptionKey, isAes) {
  38381. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  38382. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  38383. key[i] = encryptionKey[i];
  38384. }
  38385. key[i++] = num & 0xFF;
  38386. key[i++] = num >> 8 & 0xFF;
  38387. key[i++] = num >> 16 & 0xFF;
  38388. key[i++] = gen & 0xFF;
  38389. key[i++] = gen >> 8 & 0xFF;
  38390. if (isAes) {
  38391. key[i++] = 0x73;
  38392. key[i++] = 0x41;
  38393. key[i++] = 0x6C;
  38394. key[i++] = 0x54;
  38395. }
  38396. var hash = calculateMD5(key, 0, i);
  38397. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  38398. }
  38399. function buildCipherConstructor(cf, name, num, gen, key) {
  38400. assert(isName(name), 'Invalid crypt filter name.');
  38401. var cryptFilter = cf.get(name.name);
  38402. var cfm;
  38403. if (cryptFilter !== null && cryptFilter !== undefined) {
  38404. cfm = cryptFilter.get('CFM');
  38405. }
  38406. if (!cfm || cfm.name === 'None') {
  38407. return function cipherTransformFactoryBuildCipherConstructorNone() {
  38408. return new NullCipher();
  38409. };
  38410. }
  38411. if ('V2' === cfm.name) {
  38412. return function cipherTransformFactoryBuildCipherConstructorV2() {
  38413. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  38414. };
  38415. }
  38416. if ('AESV2' === cfm.name) {
  38417. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  38418. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  38419. };
  38420. }
  38421. if ('AESV3' === cfm.name) {
  38422. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  38423. return new AES256Cipher(key);
  38424. };
  38425. }
  38426. error('Unknown crypto method');
  38427. }
  38428. CipherTransformFactory.prototype = {
  38429. createCipherTransform: function CipherTransformFactory_createCipherTransform(num, gen) {
  38430. if (this.algorithm === 4 || this.algorithm === 5) {
  38431. return new CipherTransform(buildCipherConstructor(this.cf, this.stmf, num, gen, this.encryptionKey), buildCipherConstructor(this.cf, this.strf, num, gen, this.encryptionKey));
  38432. }
  38433. // algorithms 1 and 2
  38434. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  38435. var cipherConstructor = function buildCipherCipherConstructor() {
  38436. return new ARCFourCipher(key);
  38437. };
  38438. return new CipherTransform(cipherConstructor, cipherConstructor);
  38439. }
  38440. };
  38441. return CipherTransformFactory;
  38442. }();
  38443. exports.AES128Cipher = AES128Cipher;
  38444. exports.AES256Cipher = AES256Cipher;
  38445. exports.ARCFourCipher = ARCFourCipher;
  38446. exports.CipherTransformFactory = CipherTransformFactory;
  38447. exports.PDF17 = PDF17;
  38448. exports.PDF20 = PDF20;
  38449. exports.calculateMD5 = calculateMD5;
  38450. exports.calculateSHA256 = calculateSHA256;
  38451. exports.calculateSHA384 = calculateSHA384;
  38452. exports.calculateSHA512 = calculateSHA512;
  38453. }));
  38454. (function (root, factory) {
  38455. factory(root.pdfjsCoreFontRenderer = {}, root.pdfjsSharedUtil, root.pdfjsCoreStream, root.pdfjsCoreGlyphList, root.pdfjsCoreEncodings, root.pdfjsCoreCFFParser);
  38456. }(this, function (exports, sharedUtil, coreStream, coreGlyphList, coreEncodings, coreCFFParser) {
  38457. var Util = sharedUtil.Util;
  38458. var bytesToString = sharedUtil.bytesToString;
  38459. var error = sharedUtil.error;
  38460. var Stream = coreStream.Stream;
  38461. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  38462. var StandardEncoding = coreEncodings.StandardEncoding;
  38463. var CFFParser = coreCFFParser.CFFParser;
  38464. var FontRendererFactory = function FontRendererFactoryClosure() {
  38465. function getLong(data, offset) {
  38466. return data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3];
  38467. }
  38468. function getUshort(data, offset) {
  38469. return data[offset] << 8 | data[offset + 1];
  38470. }
  38471. function parseCmap(data, start, end) {
  38472. var offset = getUshort(data, start + 2) === 1 ? getLong(data, start + 8) : getLong(data, start + 16);
  38473. var format = getUshort(data, start + offset);
  38474. var length, ranges, p, i;
  38475. if (format === 4) {
  38476. length = getUshort(data, start + offset + 2);
  38477. var segCount = getUshort(data, start + offset + 6) >> 1;
  38478. p = start + offset + 14;
  38479. ranges = [];
  38480. for (i = 0; i < segCount; i++, p += 2) {
  38481. ranges[i] = { end: getUshort(data, p) };
  38482. }
  38483. p += 2;
  38484. for (i = 0; i < segCount; i++, p += 2) {
  38485. ranges[i].start = getUshort(data, p);
  38486. }
  38487. for (i = 0; i < segCount; i++, p += 2) {
  38488. ranges[i].idDelta = getUshort(data, p);
  38489. }
  38490. for (i = 0; i < segCount; i++, p += 2) {
  38491. var idOffset = getUshort(data, p);
  38492. if (idOffset === 0) {
  38493. continue;
  38494. }
  38495. ranges[i].ids = [];
  38496. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  38497. ranges[i].ids[j] = getUshort(data, p + idOffset);
  38498. idOffset += 2;
  38499. }
  38500. }
  38501. return ranges;
  38502. } else if (format === 12) {
  38503. length = getLong(data, start + offset + 4);
  38504. var groups = getLong(data, start + offset + 12);
  38505. p = start + offset + 16;
  38506. ranges = [];
  38507. for (i = 0; i < groups; i++) {
  38508. ranges.push({
  38509. start: getLong(data, p),
  38510. end: getLong(data, p + 4),
  38511. idDelta: getLong(data, p + 8) - getLong(data, p)
  38512. });
  38513. p += 12;
  38514. }
  38515. return ranges;
  38516. }
  38517. error('not supported cmap: ' + format);
  38518. }
  38519. function parseCff(data, start, end, seacAnalysisEnabled) {
  38520. var properties = {};
  38521. var parser = new CFFParser(new Stream(data, start, end - start), properties, seacAnalysisEnabled);
  38522. var cff = parser.parse();
  38523. return {
  38524. glyphs: cff.charStrings.objects,
  38525. subrs: cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex && cff.topDict.privateDict.subrsIndex.objects,
  38526. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  38527. };
  38528. }
  38529. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  38530. var itemSize, itemDecode;
  38531. if (isGlyphLocationsLong) {
  38532. itemSize = 4;
  38533. itemDecode = function fontItemDecodeLong(data, offset) {
  38534. return data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3];
  38535. };
  38536. } else {
  38537. itemSize = 2;
  38538. itemDecode = function fontItemDecode(data, offset) {
  38539. return data[offset] << 9 | data[offset + 1] << 1;
  38540. };
  38541. }
  38542. var glyphs = [];
  38543. var startOffset = itemDecode(loca, 0);
  38544. for (var j = itemSize; j < loca.length; j += itemSize) {
  38545. var endOffset = itemDecode(loca, j);
  38546. glyphs.push(glyf.subarray(startOffset, endOffset));
  38547. startOffset = endOffset;
  38548. }
  38549. return glyphs;
  38550. }
  38551. function lookupCmap(ranges, unicode) {
  38552. var code = unicode.charCodeAt(0), gid = 0;
  38553. var l = 0, r = ranges.length - 1;
  38554. while (l < r) {
  38555. var c = l + r + 1 >> 1;
  38556. if (code < ranges[c].start) {
  38557. r = c - 1;
  38558. } else {
  38559. l = c;
  38560. }
  38561. }
  38562. if (ranges[l].start <= code && code <= ranges[l].end) {
  38563. gid = ranges[l].idDelta + (ranges[l].ids ? ranges[l].ids[code - ranges[l].start] : code) & 0xFFFF;
  38564. }
  38565. return {
  38566. charCode: code,
  38567. glyphId: gid
  38568. };
  38569. }
  38570. function compileGlyf(code, cmds, font) {
  38571. function moveTo(x, y) {
  38572. cmds.push({
  38573. cmd: 'moveTo',
  38574. args: [
  38575. x,
  38576. y
  38577. ]
  38578. });
  38579. }
  38580. function lineTo(x, y) {
  38581. cmds.push({
  38582. cmd: 'lineTo',
  38583. args: [
  38584. x,
  38585. y
  38586. ]
  38587. });
  38588. }
  38589. function quadraticCurveTo(xa, ya, x, y) {
  38590. cmds.push({
  38591. cmd: 'quadraticCurveTo',
  38592. args: [
  38593. xa,
  38594. ya,
  38595. x,
  38596. y
  38597. ]
  38598. });
  38599. }
  38600. var i = 0;
  38601. var numberOfContours = (code[i] << 24 | code[i + 1] << 16) >> 16;
  38602. var flags;
  38603. var x = 0, y = 0;
  38604. i += 10;
  38605. if (numberOfContours < 0) {
  38606. // composite glyph
  38607. do {
  38608. flags = code[i] << 8 | code[i + 1];
  38609. var glyphIndex = code[i + 2] << 8 | code[i + 3];
  38610. i += 4;
  38611. var arg1, arg2;
  38612. if (flags & 0x01) {
  38613. arg1 = (code[i] << 24 | code[i + 1] << 16) >> 16;
  38614. arg2 = (code[i + 2] << 24 | code[i + 3] << 16) >> 16;
  38615. i += 4;
  38616. } else {
  38617. arg1 = code[i++];
  38618. arg2 = code[i++];
  38619. }
  38620. if (flags & 0x02) {
  38621. x = arg1;
  38622. y = arg2;
  38623. } else {
  38624. x = 0;
  38625. y = 0;
  38626. }
  38627. // TODO "they are points" ?
  38628. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  38629. if (flags & 0x08) {
  38630. scaleX = scaleY = (code[i] << 24 | code[i + 1] << 16) / 1073741824;
  38631. i += 2;
  38632. } else if (flags & 0x40) {
  38633. scaleX = (code[i] << 24 | code[i + 1] << 16) / 1073741824;
  38634. scaleY = (code[i + 2] << 24 | code[i + 3] << 16) / 1073741824;
  38635. i += 4;
  38636. } else if (flags & 0x80) {
  38637. scaleX = (code[i] << 24 | code[i + 1] << 16) / 1073741824;
  38638. scale01 = (code[i + 2] << 24 | code[i + 3] << 16) / 1073741824;
  38639. scale10 = (code[i + 4] << 24 | code[i + 5] << 16) / 1073741824;
  38640. scaleY = (code[i + 6] << 24 | code[i + 7] << 16) / 1073741824;
  38641. i += 8;
  38642. }
  38643. var subglyph = font.glyphs[glyphIndex];
  38644. if (subglyph) {
  38645. cmds.push({ cmd: 'save' });
  38646. cmds.push({
  38647. cmd: 'transform',
  38648. args: [
  38649. scaleX,
  38650. scale01,
  38651. scale10,
  38652. scaleY,
  38653. x,
  38654. y
  38655. ]
  38656. });
  38657. compileGlyf(subglyph, cmds, font);
  38658. cmds.push({ cmd: 'restore' });
  38659. }
  38660. } while (flags & 0x20);
  38661. } else {
  38662. // simple glyph
  38663. var endPtsOfContours = [];
  38664. var j, jj;
  38665. for (j = 0; j < numberOfContours; j++) {
  38666. endPtsOfContours.push(code[i] << 8 | code[i + 1]);
  38667. i += 2;
  38668. }
  38669. var instructionLength = code[i] << 8 | code[i + 1];
  38670. i += 2 + instructionLength;
  38671. // skipping the instructions
  38672. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  38673. var points = [];
  38674. while (points.length < numberOfPoints) {
  38675. flags = code[i++];
  38676. var repeat = 1;
  38677. if (flags & 0x08) {
  38678. repeat += code[i++];
  38679. }
  38680. while (repeat-- > 0) {
  38681. points.push({ flags: flags });
  38682. }
  38683. }
  38684. for (j = 0; j < numberOfPoints; j++) {
  38685. switch (points[j].flags & 0x12) {
  38686. case 0x00:
  38687. x += (code[i] << 24 | code[i + 1] << 16) >> 16;
  38688. i += 2;
  38689. break;
  38690. case 0x02:
  38691. x -= code[i++];
  38692. break;
  38693. case 0x12:
  38694. x += code[i++];
  38695. break;
  38696. }
  38697. points[j].x = x;
  38698. }
  38699. for (j = 0; j < numberOfPoints; j++) {
  38700. switch (points[j].flags & 0x24) {
  38701. case 0x00:
  38702. y += (code[i] << 24 | code[i + 1] << 16) >> 16;
  38703. i += 2;
  38704. break;
  38705. case 0x04:
  38706. y -= code[i++];
  38707. break;
  38708. case 0x24:
  38709. y += code[i++];
  38710. break;
  38711. }
  38712. points[j].y = y;
  38713. }
  38714. var startPoint = 0;
  38715. for (i = 0; i < numberOfContours; i++) {
  38716. var endPoint = endPtsOfContours[i];
  38717. // contours might have implicit points, which is located in the middle
  38718. // between two neighboring off-curve points
  38719. var contour = points.slice(startPoint, endPoint + 1);
  38720. if (contour[0].flags & 1) {
  38721. contour.push(contour[0]);
  38722. } else // using start point at the contour end
  38723. if (contour[contour.length - 1].flags & 1) {
  38724. // first is off-curve point, trying to use one from the end
  38725. contour.unshift(contour[contour.length - 1]);
  38726. } else {
  38727. // start and end are off-curve points, creating implicit one
  38728. var p = {
  38729. flags: 1,
  38730. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  38731. y: (contour[0].y + contour[contour.length - 1].y) / 2
  38732. };
  38733. contour.unshift(p);
  38734. contour.push(p);
  38735. }
  38736. moveTo(contour[0].x, contour[0].y);
  38737. for (j = 1, jj = contour.length; j < jj; j++) {
  38738. if (contour[j].flags & 1) {
  38739. lineTo(contour[j].x, contour[j].y);
  38740. } else if (contour[j + 1].flags & 1) {
  38741. quadraticCurveTo(contour[j].x, contour[j].y, contour[j + 1].x, contour[j + 1].y);
  38742. j++;
  38743. } else {
  38744. quadraticCurveTo(contour[j].x, contour[j].y, (contour[j].x + contour[j + 1].x) / 2, (contour[j].y + contour[j + 1].y) / 2);
  38745. }
  38746. }
  38747. startPoint = endPoint + 1;
  38748. }
  38749. }
  38750. }
  38751. function compileCharString(code, cmds, font) {
  38752. var stack = [];
  38753. var x = 0, y = 0;
  38754. var stems = 0;
  38755. function moveTo(x, y) {
  38756. cmds.push({
  38757. cmd: 'moveTo',
  38758. args: [
  38759. x,
  38760. y
  38761. ]
  38762. });
  38763. }
  38764. function lineTo(x, y) {
  38765. cmds.push({
  38766. cmd: 'lineTo',
  38767. args: [
  38768. x,
  38769. y
  38770. ]
  38771. });
  38772. }
  38773. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  38774. cmds.push({
  38775. cmd: 'bezierCurveTo',
  38776. args: [
  38777. x1,
  38778. y1,
  38779. x2,
  38780. y2,
  38781. x,
  38782. y
  38783. ]
  38784. });
  38785. }
  38786. function parse(code) {
  38787. var i = 0;
  38788. while (i < code.length) {
  38789. var stackClean = false;
  38790. var v = code[i++];
  38791. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  38792. switch (v) {
  38793. case 1:
  38794. // hstem
  38795. stems += stack.length >> 1;
  38796. stackClean = true;
  38797. break;
  38798. case 3:
  38799. // vstem
  38800. stems += stack.length >> 1;
  38801. stackClean = true;
  38802. break;
  38803. case 4:
  38804. // vmoveto
  38805. y += stack.pop();
  38806. moveTo(x, y);
  38807. stackClean = true;
  38808. break;
  38809. case 5:
  38810. // rlineto
  38811. while (stack.length > 0) {
  38812. x += stack.shift();
  38813. y += stack.shift();
  38814. lineTo(x, y);
  38815. }
  38816. break;
  38817. case 6:
  38818. // hlineto
  38819. while (stack.length > 0) {
  38820. x += stack.shift();
  38821. lineTo(x, y);
  38822. if (stack.length === 0) {
  38823. break;
  38824. }
  38825. y += stack.shift();
  38826. lineTo(x, y);
  38827. }
  38828. break;
  38829. case 7:
  38830. // vlineto
  38831. while (stack.length > 0) {
  38832. y += stack.shift();
  38833. lineTo(x, y);
  38834. if (stack.length === 0) {
  38835. break;
  38836. }
  38837. x += stack.shift();
  38838. lineTo(x, y);
  38839. }
  38840. break;
  38841. case 8:
  38842. // rrcurveto
  38843. while (stack.length > 0) {
  38844. xa = x + stack.shift();
  38845. ya = y + stack.shift();
  38846. xb = xa + stack.shift();
  38847. yb = ya + stack.shift();
  38848. x = xb + stack.shift();
  38849. y = yb + stack.shift();
  38850. bezierCurveTo(xa, ya, xb, yb, x, y);
  38851. }
  38852. break;
  38853. case 10:
  38854. // callsubr
  38855. n = stack.pop() + font.subrsBias;
  38856. subrCode = font.subrs[n];
  38857. if (subrCode) {
  38858. parse(subrCode);
  38859. }
  38860. break;
  38861. case 11:
  38862. // return
  38863. return;
  38864. case 12:
  38865. v = code[i++];
  38866. switch (v) {
  38867. case 34:
  38868. // flex
  38869. xa = x + stack.shift();
  38870. xb = xa + stack.shift();
  38871. y1 = y + stack.shift();
  38872. x = xb + stack.shift();
  38873. bezierCurveTo(xa, y, xb, y1, x, y1);
  38874. xa = x + stack.shift();
  38875. xb = xa + stack.shift();
  38876. x = xb + stack.shift();
  38877. bezierCurveTo(xa, y1, xb, y, x, y);
  38878. break;
  38879. case 35:
  38880. // flex
  38881. xa = x + stack.shift();
  38882. ya = y + stack.shift();
  38883. xb = xa + stack.shift();
  38884. yb = ya + stack.shift();
  38885. x = xb + stack.shift();
  38886. y = yb + stack.shift();
  38887. bezierCurveTo(xa, ya, xb, yb, x, y);
  38888. xa = x + stack.shift();
  38889. ya = y + stack.shift();
  38890. xb = xa + stack.shift();
  38891. yb = ya + stack.shift();
  38892. x = xb + stack.shift();
  38893. y = yb + stack.shift();
  38894. bezierCurveTo(xa, ya, xb, yb, x, y);
  38895. stack.pop();
  38896. // fd
  38897. break;
  38898. case 36:
  38899. // hflex1
  38900. xa = x + stack.shift();
  38901. y1 = y + stack.shift();
  38902. xb = xa + stack.shift();
  38903. y2 = y1 + stack.shift();
  38904. x = xb + stack.shift();
  38905. bezierCurveTo(xa, y1, xb, y2, x, y2);
  38906. xa = x + stack.shift();
  38907. xb = xa + stack.shift();
  38908. y3 = y2 + stack.shift();
  38909. x = xb + stack.shift();
  38910. bezierCurveTo(xa, y2, xb, y3, x, y);
  38911. break;
  38912. case 37:
  38913. // flex1
  38914. var x0 = x, y0 = y;
  38915. xa = x + stack.shift();
  38916. ya = y + stack.shift();
  38917. xb = xa + stack.shift();
  38918. yb = ya + stack.shift();
  38919. x = xb + stack.shift();
  38920. y = yb + stack.shift();
  38921. bezierCurveTo(xa, ya, xb, yb, x, y);
  38922. xa = x + stack.shift();
  38923. ya = y + stack.shift();
  38924. xb = xa + stack.shift();
  38925. yb = ya + stack.shift();
  38926. x = xb;
  38927. y = yb;
  38928. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  38929. x += stack.shift();
  38930. } else {
  38931. y += stack.shift();
  38932. }
  38933. bezierCurveTo(xa, ya, xb, yb, x, y);
  38934. break;
  38935. default:
  38936. error('unknown operator: 12 ' + v);
  38937. }
  38938. break;
  38939. case 14:
  38940. // endchar
  38941. if (stack.length >= 4) {
  38942. var achar = stack.pop();
  38943. var bchar = stack.pop();
  38944. y = stack.pop();
  38945. x = stack.pop();
  38946. cmds.push({ cmd: 'save' });
  38947. cmds.push({
  38948. cmd: 'translate',
  38949. args: [
  38950. x,
  38951. y
  38952. ]
  38953. });
  38954. var cmap = lookupCmap(font.cmap, String.fromCharCode(font.glyphNameMap[StandardEncoding[achar]]));
  38955. compileCharString(font.glyphs[cmap.glyphId], cmds, font);
  38956. cmds.push({ cmd: 'restore' });
  38957. cmap = lookupCmap(font.cmap, String.fromCharCode(font.glyphNameMap[StandardEncoding[bchar]]));
  38958. compileCharString(font.glyphs[cmap.glyphId], cmds, font);
  38959. }
  38960. return;
  38961. case 18:
  38962. // hstemhm
  38963. stems += stack.length >> 1;
  38964. stackClean = true;
  38965. break;
  38966. case 19:
  38967. // hintmask
  38968. stems += stack.length >> 1;
  38969. i += stems + 7 >> 3;
  38970. stackClean = true;
  38971. break;
  38972. case 20:
  38973. // cntrmask
  38974. stems += stack.length >> 1;
  38975. i += stems + 7 >> 3;
  38976. stackClean = true;
  38977. break;
  38978. case 21:
  38979. // rmoveto
  38980. y += stack.pop();
  38981. x += stack.pop();
  38982. moveTo(x, y);
  38983. stackClean = true;
  38984. break;
  38985. case 22:
  38986. // hmoveto
  38987. x += stack.pop();
  38988. moveTo(x, y);
  38989. stackClean = true;
  38990. break;
  38991. case 23:
  38992. // vstemhm
  38993. stems += stack.length >> 1;
  38994. stackClean = true;
  38995. break;
  38996. case 24:
  38997. // rcurveline
  38998. while (stack.length > 2) {
  38999. xa = x + stack.shift();
  39000. ya = y + stack.shift();
  39001. xb = xa + stack.shift();
  39002. yb = ya + stack.shift();
  39003. x = xb + stack.shift();
  39004. y = yb + stack.shift();
  39005. bezierCurveTo(xa, ya, xb, yb, x, y);
  39006. }
  39007. x += stack.shift();
  39008. y += stack.shift();
  39009. lineTo(x, y);
  39010. break;
  39011. case 25:
  39012. // rlinecurve
  39013. while (stack.length > 6) {
  39014. x += stack.shift();
  39015. y += stack.shift();
  39016. lineTo(x, y);
  39017. }
  39018. xa = x + stack.shift();
  39019. ya = y + stack.shift();
  39020. xb = xa + stack.shift();
  39021. yb = ya + stack.shift();
  39022. x = xb + stack.shift();
  39023. y = yb + stack.shift();
  39024. bezierCurveTo(xa, ya, xb, yb, x, y);
  39025. break;
  39026. case 26:
  39027. // vvcurveto
  39028. if (stack.length % 2) {
  39029. x += stack.shift();
  39030. }
  39031. while (stack.length > 0) {
  39032. xa = x;
  39033. ya = y + stack.shift();
  39034. xb = xa + stack.shift();
  39035. yb = ya + stack.shift();
  39036. x = xb;
  39037. y = yb + stack.shift();
  39038. bezierCurveTo(xa, ya, xb, yb, x, y);
  39039. }
  39040. break;
  39041. case 27:
  39042. // hhcurveto
  39043. if (stack.length % 2) {
  39044. y += stack.shift();
  39045. }
  39046. while (stack.length > 0) {
  39047. xa = x + stack.shift();
  39048. ya = y;
  39049. xb = xa + stack.shift();
  39050. yb = ya + stack.shift();
  39051. x = xb + stack.shift();
  39052. y = yb;
  39053. bezierCurveTo(xa, ya, xb, yb, x, y);
  39054. }
  39055. break;
  39056. case 28:
  39057. stack.push((code[i] << 24 | code[i + 1] << 16) >> 16);
  39058. i += 2;
  39059. break;
  39060. case 29:
  39061. // callgsubr
  39062. n = stack.pop() + font.gsubrsBias;
  39063. subrCode = font.gsubrs[n];
  39064. if (subrCode) {
  39065. parse(subrCode);
  39066. }
  39067. break;
  39068. case 30:
  39069. // vhcurveto
  39070. while (stack.length > 0) {
  39071. xa = x;
  39072. ya = y + stack.shift();
  39073. xb = xa + stack.shift();
  39074. yb = ya + stack.shift();
  39075. x = xb + stack.shift();
  39076. y = yb + (stack.length === 1 ? stack.shift() : 0);
  39077. bezierCurveTo(xa, ya, xb, yb, x, y);
  39078. if (stack.length === 0) {
  39079. break;
  39080. }
  39081. xa = x + stack.shift();
  39082. ya = y;
  39083. xb = xa + stack.shift();
  39084. yb = ya + stack.shift();
  39085. y = yb + stack.shift();
  39086. x = xb + (stack.length === 1 ? stack.shift() : 0);
  39087. bezierCurveTo(xa, ya, xb, yb, x, y);
  39088. }
  39089. break;
  39090. case 31:
  39091. // hvcurveto
  39092. while (stack.length > 0) {
  39093. xa = x + stack.shift();
  39094. ya = y;
  39095. xb = xa + stack.shift();
  39096. yb = ya + stack.shift();
  39097. y = yb + stack.shift();
  39098. x = xb + (stack.length === 1 ? stack.shift() : 0);
  39099. bezierCurveTo(xa, ya, xb, yb, x, y);
  39100. if (stack.length === 0) {
  39101. break;
  39102. }
  39103. xa = x;
  39104. ya = y + stack.shift();
  39105. xb = xa + stack.shift();
  39106. yb = ya + stack.shift();
  39107. x = xb + stack.shift();
  39108. y = yb + (stack.length === 1 ? stack.shift() : 0);
  39109. bezierCurveTo(xa, ya, xb, yb, x, y);
  39110. }
  39111. break;
  39112. default:
  39113. if (v < 32) {
  39114. error('unknown operator: ' + v);
  39115. }
  39116. if (v < 247) {
  39117. stack.push(v - 139);
  39118. } else if (v < 251) {
  39119. stack.push((v - 247) * 256 + code[i++] + 108);
  39120. } else if (v < 255) {
  39121. stack.push(-(v - 251) * 256 - code[i++] - 108);
  39122. } else {
  39123. stack.push((code[i] << 24 | code[i + 1] << 16 | code[i + 2] << 8 | code[i + 3]) / 65536);
  39124. i += 4;
  39125. }
  39126. break;
  39127. }
  39128. if (stackClean) {
  39129. stack.length = 0;
  39130. }
  39131. }
  39132. }
  39133. parse(code);
  39134. }
  39135. var noop = '';
  39136. function CompiledFont(fontMatrix) {
  39137. this.compiledGlyphs = Object.create(null);
  39138. this.compiledCharCodeToGlyphId = Object.create(null);
  39139. this.fontMatrix = fontMatrix;
  39140. }
  39141. CompiledFont.prototype = {
  39142. getPathJs: function (unicode) {
  39143. var cmap = lookupCmap(this.cmap, unicode);
  39144. var fn = this.compiledGlyphs[cmap.glyphId];
  39145. if (!fn) {
  39146. fn = this.compileGlyph(this.glyphs[cmap.glyphId]);
  39147. this.compiledGlyphs[cmap.glyphId] = fn;
  39148. }
  39149. if (this.compiledCharCodeToGlyphId[cmap.charCode] === undefined) {
  39150. this.compiledCharCodeToGlyphId[cmap.charCode] = cmap.glyphId;
  39151. }
  39152. return fn;
  39153. },
  39154. compileGlyph: function (code) {
  39155. if (!code || code.length === 0 || code[0] === 14) {
  39156. return noop;
  39157. }
  39158. var cmds = [];
  39159. cmds.push({ cmd: 'save' });
  39160. cmds.push({
  39161. cmd: 'transform',
  39162. args: this.fontMatrix.slice()
  39163. });
  39164. cmds.push({
  39165. cmd: 'scale',
  39166. args: [
  39167. 'size',
  39168. '-size'
  39169. ]
  39170. });
  39171. this.compileGlyphImpl(code, cmds);
  39172. cmds.push({ cmd: 'restore' });
  39173. return cmds;
  39174. },
  39175. compileGlyphImpl: function () {
  39176. error('Children classes should implement this.');
  39177. },
  39178. hasBuiltPath: function (unicode) {
  39179. var cmap = lookupCmap(this.cmap, unicode);
  39180. return this.compiledGlyphs[cmap.glyphId] !== undefined && this.compiledCharCodeToGlyphId[cmap.charCode] !== undefined;
  39181. }
  39182. };
  39183. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  39184. fontMatrix = fontMatrix || [
  39185. 0.000488,
  39186. 0,
  39187. 0,
  39188. 0.000488,
  39189. 0,
  39190. 0
  39191. ];
  39192. CompiledFont.call(this, fontMatrix);
  39193. this.glyphs = glyphs;
  39194. this.cmap = cmap;
  39195. }
  39196. Util.inherit(TrueTypeCompiled, CompiledFont, {
  39197. compileGlyphImpl: function (code, cmds) {
  39198. compileGlyf(code, cmds, this);
  39199. }
  39200. });
  39201. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  39202. fontMatrix = fontMatrix || [
  39203. 0.001,
  39204. 0,
  39205. 0,
  39206. 0.001,
  39207. 0,
  39208. 0
  39209. ];
  39210. CompiledFont.call(this, fontMatrix);
  39211. this.glyphs = cffInfo.glyphs;
  39212. this.gsubrs = cffInfo.gsubrs || [];
  39213. this.subrs = cffInfo.subrs || [];
  39214. this.cmap = cmap;
  39215. this.glyphNameMap = glyphNameMap || getGlyphsUnicode();
  39216. this.gsubrsBias = this.gsubrs.length < 1240 ? 107 : this.gsubrs.length < 33900 ? 1131 : 32768;
  39217. this.subrsBias = this.subrs.length < 1240 ? 107 : this.subrs.length < 33900 ? 1131 : 32768;
  39218. }
  39219. Util.inherit(Type2Compiled, CompiledFont, {
  39220. compileGlyphImpl: function (code, cmds) {
  39221. compileCharString(code, cmds, this);
  39222. }
  39223. });
  39224. return {
  39225. create: function FontRendererFactory_create(font, seacAnalysisEnabled) {
  39226. var data = new Uint8Array(font.data);
  39227. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  39228. var numTables = getUshort(data, 4);
  39229. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  39230. var tag = bytesToString(data.subarray(p, p + 4));
  39231. var offset = getLong(data, p + 8);
  39232. var length = getLong(data, p + 12);
  39233. switch (tag) {
  39234. case 'cmap':
  39235. cmap = parseCmap(data, offset, offset + length);
  39236. break;
  39237. case 'glyf':
  39238. glyf = data.subarray(offset, offset + length);
  39239. break;
  39240. case 'loca':
  39241. loca = data.subarray(offset, offset + length);
  39242. break;
  39243. case 'head':
  39244. unitsPerEm = getUshort(data, offset + 18);
  39245. indexToLocFormat = getUshort(data, offset + 50);
  39246. break;
  39247. case 'CFF ':
  39248. cff = parseCff(data, offset, offset + length, seacAnalysisEnabled);
  39249. break;
  39250. }
  39251. }
  39252. if (glyf) {
  39253. var fontMatrix = !unitsPerEm ? font.fontMatrix : [
  39254. 1 / unitsPerEm,
  39255. 0,
  39256. 0,
  39257. 1 / unitsPerEm,
  39258. 0,
  39259. 0
  39260. ];
  39261. return new TrueTypeCompiled(parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  39262. } else {
  39263. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  39264. }
  39265. }
  39266. };
  39267. }();
  39268. exports.FontRendererFactory = FontRendererFactory;
  39269. }));
  39270. (function (root, factory) {
  39271. factory(root.pdfjsCoreParser = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  39272. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  39273. var MissingDataException = sharedUtil.MissingDataException;
  39274. var StreamType = sharedUtil.StreamType;
  39275. var assert = sharedUtil.assert;
  39276. var error = sharedUtil.error;
  39277. var info = sharedUtil.info;
  39278. var isArray = sharedUtil.isArray;
  39279. var isInt = sharedUtil.isInt;
  39280. var isNum = sharedUtil.isNum;
  39281. var isString = sharedUtil.isString;
  39282. var warn = sharedUtil.warn;
  39283. var Cmd = corePrimitives.Cmd;
  39284. var Dict = corePrimitives.Dict;
  39285. var Name = corePrimitives.Name;
  39286. var Ref = corePrimitives.Ref;
  39287. var isCmd = corePrimitives.isCmd;
  39288. var isDict = corePrimitives.isDict;
  39289. var isName = corePrimitives.isName;
  39290. var Ascii85Stream = coreStream.Ascii85Stream;
  39291. var AsciiHexStream = coreStream.AsciiHexStream;
  39292. var CCITTFaxStream = coreStream.CCITTFaxStream;
  39293. var FlateStream = coreStream.FlateStream;
  39294. var Jbig2Stream = coreStream.Jbig2Stream;
  39295. var JpegStream = coreStream.JpegStream;
  39296. var JpxStream = coreStream.JpxStream;
  39297. var LZWStream = coreStream.LZWStream;
  39298. var NullStream = coreStream.NullStream;
  39299. var PredictorStream = coreStream.PredictorStream;
  39300. var RunLengthStream = coreStream.RunLengthStream;
  39301. var EOF = {};
  39302. function isEOF(v) {
  39303. return v === EOF;
  39304. }
  39305. var MAX_LENGTH_TO_CACHE = 1000;
  39306. var Parser = function ParserClosure() {
  39307. function Parser(lexer, allowStreams, xref, recoveryMode) {
  39308. this.lexer = lexer;
  39309. this.allowStreams = allowStreams;
  39310. this.xref = xref;
  39311. this.recoveryMode = recoveryMode || false;
  39312. this.imageCache = Object.create(null);
  39313. this.refill();
  39314. }
  39315. Parser.prototype = {
  39316. refill: function Parser_refill() {
  39317. this.buf1 = this.lexer.getObj();
  39318. this.buf2 = this.lexer.getObj();
  39319. },
  39320. shift: function Parser_shift() {
  39321. if (isCmd(this.buf2, 'ID')) {
  39322. this.buf1 = this.buf2;
  39323. this.buf2 = null;
  39324. } else {
  39325. this.buf1 = this.buf2;
  39326. this.buf2 = this.lexer.getObj();
  39327. }
  39328. },
  39329. tryShift: function Parser_tryShift() {
  39330. try {
  39331. this.shift();
  39332. return true;
  39333. } catch (e) {
  39334. if (e instanceof MissingDataException) {
  39335. throw e;
  39336. }
  39337. // Upon failure, the caller should reset this.lexer.pos to a known good
  39338. // state and call this.shift() twice to reset the buffers.
  39339. return false;
  39340. }
  39341. },
  39342. getObj: function Parser_getObj(cipherTransform) {
  39343. var buf1 = this.buf1;
  39344. this.shift();
  39345. if (buf1 instanceof Cmd) {
  39346. switch (buf1.cmd) {
  39347. case 'BI':
  39348. // inline image
  39349. return this.makeInlineImage(cipherTransform);
  39350. case '[':
  39351. // array
  39352. var array = [];
  39353. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  39354. array.push(this.getObj(cipherTransform));
  39355. }
  39356. if (isEOF(this.buf1)) {
  39357. if (!this.recoveryMode) {
  39358. error('End of file inside array');
  39359. }
  39360. return array;
  39361. }
  39362. this.shift();
  39363. return array;
  39364. case '<<':
  39365. // dictionary or stream
  39366. var dict = new Dict(this.xref);
  39367. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  39368. if (!isName(this.buf1)) {
  39369. info('Malformed dictionary: key must be a name object');
  39370. this.shift();
  39371. continue;
  39372. }
  39373. var key = this.buf1.name;
  39374. this.shift();
  39375. if (isEOF(this.buf1)) {
  39376. break;
  39377. }
  39378. dict.set(key, this.getObj(cipherTransform));
  39379. }
  39380. if (isEOF(this.buf1)) {
  39381. if (!this.recoveryMode) {
  39382. error('End of file inside dictionary');
  39383. }
  39384. return dict;
  39385. }
  39386. // Stream objects are not allowed inside content streams or
  39387. // object streams.
  39388. if (isCmd(this.buf2, 'stream')) {
  39389. return this.allowStreams ? this.makeStream(dict, cipherTransform) : dict;
  39390. }
  39391. this.shift();
  39392. return dict;
  39393. default:
  39394. // simple object
  39395. return buf1;
  39396. }
  39397. }
  39398. if (isInt(buf1)) {
  39399. // indirect reference or integer
  39400. var num = buf1;
  39401. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  39402. var ref = new Ref(num, this.buf1);
  39403. this.shift();
  39404. this.shift();
  39405. return ref;
  39406. }
  39407. return num;
  39408. }
  39409. if (isString(buf1)) {
  39410. // string
  39411. var str = buf1;
  39412. if (cipherTransform) {
  39413. str = cipherTransform.decryptString(str);
  39414. }
  39415. return str;
  39416. }
  39417. // simple object
  39418. return buf1;
  39419. },
  39420. /**
  39421. * Find the end of the stream by searching for the /EI\s/.
  39422. * @returns {number} The inline stream length.
  39423. */
  39424. findDefaultInlineStreamEnd: function Parser_findDefaultInlineStreamEnd(stream) {
  39425. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  39426. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  39427. while ((ch = stream.getByte()) !== -1) {
  39428. if (state === 0) {
  39429. state = ch === E ? 1 : 0;
  39430. } else if (state === 1) {
  39431. state = ch === I ? 2 : 0;
  39432. } else {
  39433. assert(state === 2);
  39434. if (ch === SPACE || ch === LF || ch === CR) {
  39435. // Let's check the next five bytes are ASCII... just be sure.
  39436. n = 5;
  39437. followingBytes = stream.peekBytes(n);
  39438. for (i = 0; i < n; i++) {
  39439. ch = followingBytes[i];
  39440. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  39441. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  39442. // it's binary stuff. Resetting the state.
  39443. state = 0;
  39444. break;
  39445. }
  39446. }
  39447. if (state === 2) {
  39448. break;
  39449. }
  39450. } else
  39451. // Finished!
  39452. {
  39453. state = 0;
  39454. }
  39455. }
  39456. }
  39457. return stream.pos - 4 - startPos;
  39458. },
  39459. /**
  39460. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  39461. * @returns {number} The inline stream length.
  39462. */
  39463. findDCTDecodeInlineStreamEnd: function Parser_findDCTDecodeInlineStreamEnd(stream) {
  39464. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  39465. while ((b = stream.getByte()) !== -1) {
  39466. if (b !== 0xFF) {
  39467. // Not a valid marker.
  39468. continue;
  39469. }
  39470. switch (stream.getByte()) {
  39471. case 0x00:
  39472. // Byte stuffing.
  39473. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  39474. break;
  39475. case 0xFF:
  39476. // Fill byte.
  39477. // Avoid skipping a valid marker, resetting the stream position.
  39478. stream.skip(-1);
  39479. break;
  39480. case 0xD9:
  39481. // EOI
  39482. foundEOI = true;
  39483. break;
  39484. case 0xC0:
  39485. // SOF0
  39486. case 0xC1:
  39487. // SOF1
  39488. case 0xC2:
  39489. // SOF2
  39490. case 0xC3:
  39491. // SOF3
  39492. case 0xC5:
  39493. // SOF5
  39494. case 0xC6:
  39495. // SOF6
  39496. case 0xC7:
  39497. // SOF7
  39498. case 0xC9:
  39499. // SOF9
  39500. case 0xCA:
  39501. // SOF10
  39502. case 0xCB:
  39503. // SOF11
  39504. case 0xCD:
  39505. // SOF13
  39506. case 0xCE:
  39507. // SOF14
  39508. case 0xCF:
  39509. // SOF15
  39510. case 0xC4:
  39511. // DHT
  39512. case 0xCC:
  39513. // DAC
  39514. case 0xDA:
  39515. // SOS
  39516. case 0xDB:
  39517. // DQT
  39518. case 0xDC:
  39519. // DNL
  39520. case 0xDD:
  39521. // DRI
  39522. case 0xDE:
  39523. // DHP
  39524. case 0xDF:
  39525. // EXP
  39526. case 0xE0:
  39527. // APP0
  39528. case 0xE1:
  39529. // APP1
  39530. case 0xE2:
  39531. // APP2
  39532. case 0xE3:
  39533. // APP3
  39534. case 0xE4:
  39535. // APP4
  39536. case 0xE5:
  39537. // APP5
  39538. case 0xE6:
  39539. // APP6
  39540. case 0xE7:
  39541. // APP7
  39542. case 0xE8:
  39543. // APP8
  39544. case 0xE9:
  39545. // APP9
  39546. case 0xEA:
  39547. // APP10
  39548. case 0xEB:
  39549. // APP11
  39550. case 0xEC:
  39551. // APP12
  39552. case 0xED:
  39553. // APP13
  39554. case 0xEE:
  39555. // APP14
  39556. case 0xEF:
  39557. // APP15
  39558. case 0xFE:
  39559. // COM
  39560. // The marker should be followed by the length of the segment.
  39561. markerLength = stream.getUint16();
  39562. if (markerLength > 2) {
  39563. // |markerLength| contains the byte length of the marker segment,
  39564. // including its own length (2 bytes) and excluding the marker.
  39565. stream.skip(markerLength - 2);
  39566. } else
  39567. // Jump to the next marker.
  39568. {
  39569. // The marker length is invalid, resetting the stream position.
  39570. stream.skip(-2);
  39571. }
  39572. break;
  39573. }
  39574. if (foundEOI) {
  39575. break;
  39576. }
  39577. }
  39578. length = stream.pos - startPos;
  39579. if (b === -1) {
  39580. warn('Inline DCTDecode image stream: ' + 'EOI marker not found, searching for /EI/ instead.');
  39581. stream.skip(-length);
  39582. // Reset the stream position.
  39583. return this.findDefaultInlineStreamEnd(stream);
  39584. }
  39585. this.inlineStreamSkipEI(stream);
  39586. return length;
  39587. },
  39588. /**
  39589. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  39590. * @returns {number} The inline stream length.
  39591. */
  39592. findASCII85DecodeInlineStreamEnd: function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  39593. var TILDE = 0x7E, GT = 0x3E;
  39594. var startPos = stream.pos, ch, length;
  39595. while ((ch = stream.getByte()) !== -1) {
  39596. if (ch === TILDE && stream.peekByte() === GT) {
  39597. stream.skip();
  39598. break;
  39599. }
  39600. }
  39601. length = stream.pos - startPos;
  39602. if (ch === -1) {
  39603. warn('Inline ASCII85Decode image stream: ' + 'EOD marker not found, searching for /EI/ instead.');
  39604. stream.skip(-length);
  39605. // Reset the stream position.
  39606. return this.findDefaultInlineStreamEnd(stream);
  39607. }
  39608. this.inlineStreamSkipEI(stream);
  39609. return length;
  39610. },
  39611. /**
  39612. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  39613. * @returns {number} The inline stream length.
  39614. */
  39615. findASCIIHexDecodeInlineStreamEnd: function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  39616. var GT = 0x3E;
  39617. var startPos = stream.pos, ch, length;
  39618. while ((ch = stream.getByte()) !== -1) {
  39619. if (ch === GT) {
  39620. break;
  39621. }
  39622. }
  39623. length = stream.pos - startPos;
  39624. if (ch === -1) {
  39625. warn('Inline ASCIIHexDecode image stream: ' + 'EOD marker not found, searching for /EI/ instead.');
  39626. stream.skip(-length);
  39627. // Reset the stream position.
  39628. return this.findDefaultInlineStreamEnd(stream);
  39629. }
  39630. this.inlineStreamSkipEI(stream);
  39631. return length;
  39632. },
  39633. /**
  39634. * Skip over the /EI/ for streams where we search for an EOD marker.
  39635. */
  39636. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  39637. var E = 0x45, I = 0x49;
  39638. var state = 0, ch;
  39639. while ((ch = stream.getByte()) !== -1) {
  39640. if (state === 0) {
  39641. state = ch === E ? 1 : 0;
  39642. } else if (state === 1) {
  39643. state = ch === I ? 2 : 0;
  39644. } else if (state === 2) {
  39645. break;
  39646. }
  39647. }
  39648. },
  39649. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  39650. var lexer = this.lexer;
  39651. var stream = lexer.stream;
  39652. // Parse dictionary.
  39653. var dict = new Dict(this.xref);
  39654. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  39655. if (!isName(this.buf1)) {
  39656. error('Dictionary key must be a name object');
  39657. }
  39658. var key = this.buf1.name;
  39659. this.shift();
  39660. if (isEOF(this.buf1)) {
  39661. break;
  39662. }
  39663. dict.set(key, this.getObj(cipherTransform));
  39664. }
  39665. // Extract the name of the first (i.e. the current) image filter.
  39666. var filter = dict.get('Filter', 'F'), filterName;
  39667. if (isName(filter)) {
  39668. filterName = filter.name;
  39669. } else if (isArray(filter) && isName(filter[0])) {
  39670. filterName = filter[0].name;
  39671. }
  39672. // Parse image stream.
  39673. var startPos = stream.pos, length, i, ii;
  39674. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  39675. length = this.findDCTDecodeInlineStreamEnd(stream);
  39676. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  39677. length = this.findASCII85DecodeInlineStreamEnd(stream);
  39678. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  39679. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  39680. } else {
  39681. length = this.findDefaultInlineStreamEnd(stream);
  39682. }
  39683. var imageStream = stream.makeSubStream(startPos, length, dict);
  39684. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  39685. // adler32 checksum.
  39686. var adler32;
  39687. if (length < MAX_LENGTH_TO_CACHE) {
  39688. var imageBytes = imageStream.getBytes();
  39689. imageStream.reset();
  39690. var a = 1;
  39691. var b = 0;
  39692. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  39693. // No modulo required in the loop if imageBytes.length < 5552.
  39694. a += imageBytes[i] & 0xff;
  39695. b += a;
  39696. }
  39697. adler32 = b % 65521 << 16 | a % 65521;
  39698. if (this.imageCache.adler32 === adler32) {
  39699. this.buf2 = Cmd.get('EI');
  39700. this.shift();
  39701. this.imageCache[adler32].reset();
  39702. return this.imageCache[adler32];
  39703. }
  39704. }
  39705. if (cipherTransform) {
  39706. imageStream = cipherTransform.createStream(imageStream, length);
  39707. }
  39708. imageStream = this.filter(imageStream, dict, length);
  39709. imageStream.dict = dict;
  39710. if (adler32 !== undefined) {
  39711. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  39712. this.imageCache[adler32] = imageStream;
  39713. }
  39714. this.buf2 = Cmd.get('EI');
  39715. this.shift();
  39716. return imageStream;
  39717. },
  39718. makeStream: function Parser_makeStream(dict, cipherTransform) {
  39719. var lexer = this.lexer;
  39720. var stream = lexer.stream;
  39721. // get stream start position
  39722. lexer.skipToNextLine();
  39723. var pos = stream.pos - 1;
  39724. // get length
  39725. var length = dict.get('Length');
  39726. if (!isInt(length)) {
  39727. info('Bad ' + length + ' attribute in stream');
  39728. length = 0;
  39729. }
  39730. // skip over the stream data
  39731. stream.pos = pos + length;
  39732. lexer.nextChar();
  39733. // Shift '>>' and check whether the new object marks the end of the stream
  39734. if (this.tryShift() && isCmd(this.buf2, 'endstream')) {
  39735. this.shift();
  39736. } else
  39737. // 'stream'
  39738. {
  39739. // bad stream length, scanning for endstream
  39740. stream.pos = pos;
  39741. var SCAN_BLOCK_SIZE = 2048;
  39742. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  39743. var ENDSTREAM_SIGNATURE = [
  39744. 0x65,
  39745. 0x6E,
  39746. 0x64,
  39747. 0x73,
  39748. 0x74,
  39749. 0x72,
  39750. 0x65,
  39751. 0x61,
  39752. 0x6D
  39753. ];
  39754. var skipped = 0, found = false, i, j;
  39755. while (stream.pos < stream.end) {
  39756. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  39757. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  39758. if (scanLength <= 0) {
  39759. break;
  39760. }
  39761. found = false;
  39762. i = 0;
  39763. while (i < scanLength) {
  39764. j = 0;
  39765. while (j < ENDSTREAM_SIGNATURE_LENGTH && scanBytes[i + j] === ENDSTREAM_SIGNATURE[j]) {
  39766. j++;
  39767. }
  39768. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  39769. found = true;
  39770. break;
  39771. }
  39772. i++;
  39773. }
  39774. if (found) {
  39775. skipped += i;
  39776. stream.pos += i;
  39777. break;
  39778. }
  39779. skipped += scanLength;
  39780. stream.pos += scanLength;
  39781. }
  39782. if (!found) {
  39783. error('Missing endstream');
  39784. }
  39785. length = skipped;
  39786. lexer.nextChar();
  39787. this.shift();
  39788. this.shift();
  39789. }
  39790. this.shift();
  39791. // 'endstream'
  39792. stream = stream.makeSubStream(pos, length, dict);
  39793. if (cipherTransform) {
  39794. stream = cipherTransform.createStream(stream, length);
  39795. }
  39796. stream = this.filter(stream, dict, length);
  39797. stream.dict = dict;
  39798. return stream;
  39799. },
  39800. filter: function Parser_filter(stream, dict, length) {
  39801. var filter = dict.get('Filter', 'F');
  39802. var params = dict.get('DecodeParms', 'DP');
  39803. if (isName(filter)) {
  39804. if (isArray(params)) {
  39805. params = params[0];
  39806. }
  39807. return this.makeFilter(stream, filter.name, length, params);
  39808. }
  39809. var maybeLength = length;
  39810. if (isArray(filter)) {
  39811. var filterArray = filter;
  39812. var paramsArray = params;
  39813. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  39814. filter = filterArray[i];
  39815. if (!isName(filter)) {
  39816. error('Bad filter name: ' + filter);
  39817. }
  39818. params = null;
  39819. if (isArray(paramsArray) && i in paramsArray) {
  39820. params = paramsArray[i];
  39821. }
  39822. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  39823. // after the first stream the length variable is invalid
  39824. maybeLength = null;
  39825. }
  39826. }
  39827. return stream;
  39828. },
  39829. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  39830. // Since the 'Length' entry in the stream dictionary can be completely
  39831. // wrong, e.g. zero for non-empty streams, only skip parsing the stream
  39832. // when we can be absolutely certain that it actually is empty.
  39833. if (maybeLength === 0) {
  39834. warn('Empty "' + name + '" stream.');
  39835. return new NullStream(stream);
  39836. }
  39837. try {
  39838. if (params && this.xref) {
  39839. params = this.xref.fetchIfRef(params);
  39840. }
  39841. var xrefStreamStats = this.xref.stats.streamTypes;
  39842. if (name === 'FlateDecode' || name === 'Fl') {
  39843. xrefStreamStats[StreamType.FLATE] = true;
  39844. if (params) {
  39845. return new PredictorStream(new FlateStream(stream, maybeLength), maybeLength, params);
  39846. }
  39847. return new FlateStream(stream, maybeLength);
  39848. }
  39849. if (name === 'LZWDecode' || name === 'LZW') {
  39850. xrefStreamStats[StreamType.LZW] = true;
  39851. var earlyChange = 1;
  39852. if (params) {
  39853. if (params.has('EarlyChange')) {
  39854. earlyChange = params.get('EarlyChange');
  39855. }
  39856. return new PredictorStream(new LZWStream(stream, maybeLength, earlyChange), maybeLength, params);
  39857. }
  39858. return new LZWStream(stream, maybeLength, earlyChange);
  39859. }
  39860. if (name === 'DCTDecode' || name === 'DCT') {
  39861. xrefStreamStats[StreamType.DCT] = true;
  39862. return new JpegStream(stream, maybeLength, stream.dict, params);
  39863. }
  39864. if (name === 'JPXDecode' || name === 'JPX') {
  39865. xrefStreamStats[StreamType.JPX] = true;
  39866. return new JpxStream(stream, maybeLength, stream.dict, params);
  39867. }
  39868. if (name === 'ASCII85Decode' || name === 'A85') {
  39869. xrefStreamStats[StreamType.A85] = true;
  39870. return new Ascii85Stream(stream, maybeLength);
  39871. }
  39872. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  39873. xrefStreamStats[StreamType.AHX] = true;
  39874. return new AsciiHexStream(stream, maybeLength);
  39875. }
  39876. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  39877. xrefStreamStats[StreamType.CCF] = true;
  39878. return new CCITTFaxStream(stream, maybeLength, params);
  39879. }
  39880. if (name === 'RunLengthDecode' || name === 'RL') {
  39881. xrefStreamStats[StreamType.RL] = true;
  39882. return new RunLengthStream(stream, maybeLength);
  39883. }
  39884. if (name === 'JBIG2Decode') {
  39885. xrefStreamStats[StreamType.JBIG] = true;
  39886. return new Jbig2Stream(stream, maybeLength, stream.dict, params);
  39887. }
  39888. warn('filter "' + name + '" not supported yet');
  39889. return stream;
  39890. } catch (ex) {
  39891. if (ex instanceof MissingDataException) {
  39892. throw ex;
  39893. }
  39894. warn('Invalid stream: \"' + ex + '\"');
  39895. return new NullStream(stream);
  39896. }
  39897. }
  39898. };
  39899. return Parser;
  39900. }();
  39901. var Lexer = function LexerClosure() {
  39902. function Lexer(stream, knownCommands) {
  39903. this.stream = stream;
  39904. this.nextChar();
  39905. // While lexing, we build up many strings one char at a time. Using += for
  39906. // this can result in lots of garbage strings. It's better to build an
  39907. // array of single-char strings and then join() them together at the end.
  39908. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  39909. // purpose uses less memory than using a new array for each string.
  39910. this.strBuf = [];
  39911. // The PDFs might have "glued" commands with other commands, operands or
  39912. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  39913. // commands and their prefixes. The prefixes are built the following way:
  39914. // if there a command that is a prefix of the other valid command or
  39915. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  39916. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  39917. // other commands or literals as a prefix. The knowCommands is optional.
  39918. this.knownCommands = knownCommands;
  39919. }
  39920. // A '1' in this array means the character is white space. A '1' or
  39921. // '2' means the character ends a name or command.
  39922. var specialChars = [
  39923. 1,
  39924. 0,
  39925. 0,
  39926. 0,
  39927. 0,
  39928. 0,
  39929. 0,
  39930. 0,
  39931. 0,
  39932. 1,
  39933. 1,
  39934. 0,
  39935. 1,
  39936. 1,
  39937. 0,
  39938. 0,
  39939. // 0x
  39940. 0,
  39941. 0,
  39942. 0,
  39943. 0,
  39944. 0,
  39945. 0,
  39946. 0,
  39947. 0,
  39948. 0,
  39949. 0,
  39950. 0,
  39951. 0,
  39952. 0,
  39953. 0,
  39954. 0,
  39955. 0,
  39956. // 1x
  39957. 1,
  39958. 0,
  39959. 0,
  39960. 0,
  39961. 0,
  39962. 2,
  39963. 0,
  39964. 0,
  39965. 2,
  39966. 2,
  39967. 0,
  39968. 0,
  39969. 0,
  39970. 0,
  39971. 0,
  39972. 2,
  39973. // 2x
  39974. 0,
  39975. 0,
  39976. 0,
  39977. 0,
  39978. 0,
  39979. 0,
  39980. 0,
  39981. 0,
  39982. 0,
  39983. 0,
  39984. 0,
  39985. 0,
  39986. 2,
  39987. 0,
  39988. 2,
  39989. 0,
  39990. // 3x
  39991. 0,
  39992. 0,
  39993. 0,
  39994. 0,
  39995. 0,
  39996. 0,
  39997. 0,
  39998. 0,
  39999. 0,
  40000. 0,
  40001. 0,
  40002. 0,
  40003. 0,
  40004. 0,
  40005. 0,
  40006. 0,
  40007. // 4x
  40008. 0,
  40009. 0,
  40010. 0,
  40011. 0,
  40012. 0,
  40013. 0,
  40014. 0,
  40015. 0,
  40016. 0,
  40017. 0,
  40018. 0,
  40019. 2,
  40020. 0,
  40021. 2,
  40022. 0,
  40023. 0,
  40024. // 5x
  40025. 0,
  40026. 0,
  40027. 0,
  40028. 0,
  40029. 0,
  40030. 0,
  40031. 0,
  40032. 0,
  40033. 0,
  40034. 0,
  40035. 0,
  40036. 0,
  40037. 0,
  40038. 0,
  40039. 0,
  40040. 0,
  40041. // 6x
  40042. 0,
  40043. 0,
  40044. 0,
  40045. 0,
  40046. 0,
  40047. 0,
  40048. 0,
  40049. 0,
  40050. 0,
  40051. 0,
  40052. 0,
  40053. 2,
  40054. 0,
  40055. 2,
  40056. 0,
  40057. 0,
  40058. // 7x
  40059. 0,
  40060. 0,
  40061. 0,
  40062. 0,
  40063. 0,
  40064. 0,
  40065. 0,
  40066. 0,
  40067. 0,
  40068. 0,
  40069. 0,
  40070. 0,
  40071. 0,
  40072. 0,
  40073. 0,
  40074. 0,
  40075. // 8x
  40076. 0,
  40077. 0,
  40078. 0,
  40079. 0,
  40080. 0,
  40081. 0,
  40082. 0,
  40083. 0,
  40084. 0,
  40085. 0,
  40086. 0,
  40087. 0,
  40088. 0,
  40089. 0,
  40090. 0,
  40091. 0,
  40092. // 9x
  40093. 0,
  40094. 0,
  40095. 0,
  40096. 0,
  40097. 0,
  40098. 0,
  40099. 0,
  40100. 0,
  40101. 0,
  40102. 0,
  40103. 0,
  40104. 0,
  40105. 0,
  40106. 0,
  40107. 0,
  40108. 0,
  40109. // ax
  40110. 0,
  40111. 0,
  40112. 0,
  40113. 0,
  40114. 0,
  40115. 0,
  40116. 0,
  40117. 0,
  40118. 0,
  40119. 0,
  40120. 0,
  40121. 0,
  40122. 0,
  40123. 0,
  40124. 0,
  40125. 0,
  40126. // bx
  40127. 0,
  40128. 0,
  40129. 0,
  40130. 0,
  40131. 0,
  40132. 0,
  40133. 0,
  40134. 0,
  40135. 0,
  40136. 0,
  40137. 0,
  40138. 0,
  40139. 0,
  40140. 0,
  40141. 0,
  40142. 0,
  40143. // cx
  40144. 0,
  40145. 0,
  40146. 0,
  40147. 0,
  40148. 0,
  40149. 0,
  40150. 0,
  40151. 0,
  40152. 0,
  40153. 0,
  40154. 0,
  40155. 0,
  40156. 0,
  40157. 0,
  40158. 0,
  40159. 0,
  40160. // dx
  40161. 0,
  40162. 0,
  40163. 0,
  40164. 0,
  40165. 0,
  40166. 0,
  40167. 0,
  40168. 0,
  40169. 0,
  40170. 0,
  40171. 0,
  40172. 0,
  40173. 0,
  40174. 0,
  40175. 0,
  40176. 0,
  40177. // ex
  40178. 0,
  40179. 0,
  40180. 0,
  40181. 0,
  40182. 0,
  40183. 0,
  40184. 0,
  40185. 0,
  40186. 0,
  40187. 0,
  40188. 0,
  40189. 0,
  40190. 0,
  40191. 0,
  40192. 0,
  40193. 0
  40194. ];
  40195. // fx
  40196. function toHexDigit(ch) {
  40197. if (ch >= 0x30 && ch <= 0x39) {
  40198. // '0'-'9'
  40199. return ch & 0x0F;
  40200. }
  40201. if (ch >= 0x41 && ch <= 0x46 || ch >= 0x61 && ch <= 0x66) {
  40202. // 'A'-'F', 'a'-'f'
  40203. return (ch & 0x0F) + 9;
  40204. }
  40205. return -1;
  40206. }
  40207. Lexer.prototype = {
  40208. nextChar: function Lexer_nextChar() {
  40209. return this.currentChar = this.stream.getByte();
  40210. },
  40211. peekChar: function Lexer_peekChar() {
  40212. return this.stream.peekByte();
  40213. },
  40214. getNumber: function Lexer_getNumber() {
  40215. var ch = this.currentChar;
  40216. var eNotation = false;
  40217. var divideBy = 0;
  40218. // different from 0 if it's a floating point value
  40219. var sign = 1;
  40220. if (ch === 0x2D) {
  40221. // '-'
  40222. sign = -1;
  40223. ch = this.nextChar();
  40224. if (ch === 0x2D) {
  40225. // '-'
  40226. // Ignore double negative (this is consistent with Adobe Reader).
  40227. ch = this.nextChar();
  40228. }
  40229. } else if (ch === 0x2B) {
  40230. // '+'
  40231. ch = this.nextChar();
  40232. }
  40233. if (ch === 0x2E) {
  40234. // '.'
  40235. divideBy = 10;
  40236. ch = this.nextChar();
  40237. }
  40238. if (ch < 0x30 || ch > 0x39) {
  40239. // '0' - '9'
  40240. error('Invalid number: ' + String.fromCharCode(ch));
  40241. return 0;
  40242. }
  40243. var baseValue = ch - 0x30;
  40244. // '0'
  40245. var powerValue = 0;
  40246. var powerValueSign = 1;
  40247. while ((ch = this.nextChar()) >= 0) {
  40248. if (0x30 <= ch && ch <= 0x39) {
  40249. // '0' - '9'
  40250. var currentDigit = ch - 0x30;
  40251. // '0'
  40252. if (eNotation) {
  40253. // We are after an 'e' or 'E'
  40254. powerValue = powerValue * 10 + currentDigit;
  40255. } else {
  40256. if (divideBy !== 0) {
  40257. // We are after a point
  40258. divideBy *= 10;
  40259. }
  40260. baseValue = baseValue * 10 + currentDigit;
  40261. }
  40262. } else if (ch === 0x2E) {
  40263. // '.'
  40264. if (divideBy === 0) {
  40265. divideBy = 1;
  40266. } else {
  40267. // A number can have only one '.'
  40268. break;
  40269. }
  40270. } else if (ch === 0x2D) {
  40271. // '-'
  40272. // ignore minus signs in the middle of numbers to match
  40273. // Adobe's behavior
  40274. warn('Badly formatted number');
  40275. } else if (ch === 0x45 || ch === 0x65) {
  40276. // 'E', 'e'
  40277. // 'E' can be either a scientific notation or the beginning of a new
  40278. // operator
  40279. ch = this.peekChar();
  40280. if (ch === 0x2B || ch === 0x2D) {
  40281. // '+', '-'
  40282. powerValueSign = ch === 0x2D ? -1 : 1;
  40283. this.nextChar();
  40284. } else // Consume the sign character
  40285. if (ch < 0x30 || ch > 0x39) {
  40286. // '0' - '9'
  40287. // The 'E' must be the beginning of a new operator
  40288. break;
  40289. }
  40290. eNotation = true;
  40291. } else {
  40292. // the last character doesn't belong to us
  40293. break;
  40294. }
  40295. }
  40296. if (divideBy !== 0) {
  40297. baseValue /= divideBy;
  40298. }
  40299. if (eNotation) {
  40300. baseValue *= Math.pow(10, powerValueSign * powerValue);
  40301. }
  40302. return sign * baseValue;
  40303. },
  40304. getString: function Lexer_getString() {
  40305. var numParen = 1;
  40306. var done = false;
  40307. var strBuf = this.strBuf;
  40308. strBuf.length = 0;
  40309. var ch = this.nextChar();
  40310. while (true) {
  40311. var charBuffered = false;
  40312. switch (ch | 0) {
  40313. case -1:
  40314. warn('Unterminated string');
  40315. done = true;
  40316. break;
  40317. case 0x28:
  40318. // '('
  40319. ++numParen;
  40320. strBuf.push('(');
  40321. break;
  40322. case 0x29:
  40323. // ')'
  40324. if (--numParen === 0) {
  40325. this.nextChar();
  40326. // consume strings ')'
  40327. done = true;
  40328. } else {
  40329. strBuf.push(')');
  40330. }
  40331. break;
  40332. case 0x5C:
  40333. // '\\'
  40334. ch = this.nextChar();
  40335. switch (ch) {
  40336. case -1:
  40337. warn('Unterminated string');
  40338. done = true;
  40339. break;
  40340. case 0x6E:
  40341. // 'n'
  40342. strBuf.push('\n');
  40343. break;
  40344. case 0x72:
  40345. // 'r'
  40346. strBuf.push('\r');
  40347. break;
  40348. case 0x74:
  40349. // 't'
  40350. strBuf.push('\t');
  40351. break;
  40352. case 0x62:
  40353. // 'b'
  40354. strBuf.push('\b');
  40355. break;
  40356. case 0x66:
  40357. // 'f'
  40358. strBuf.push('\f');
  40359. break;
  40360. case 0x5C:
  40361. // '\'
  40362. case 0x28:
  40363. // '('
  40364. case 0x29:
  40365. // ')'
  40366. strBuf.push(String.fromCharCode(ch));
  40367. break;
  40368. case 0x30:
  40369. case 0x31:
  40370. case 0x32:
  40371. case 0x33:
  40372. // '0'-'3'
  40373. case 0x34:
  40374. case 0x35:
  40375. case 0x36:
  40376. case 0x37:
  40377. // '4'-'7'
  40378. var x = ch & 0x0F;
  40379. ch = this.nextChar();
  40380. charBuffered = true;
  40381. if (ch >= 0x30 && ch <= 0x37) {
  40382. // '0'-'7'
  40383. x = (x << 3) + (ch & 0x0F);
  40384. ch = this.nextChar();
  40385. if (ch >= 0x30 && ch <= 0x37) {
  40386. // '0'-'7'
  40387. charBuffered = false;
  40388. x = (x << 3) + (ch & 0x0F);
  40389. }
  40390. }
  40391. strBuf.push(String.fromCharCode(x));
  40392. break;
  40393. case 0x0D:
  40394. // CR
  40395. if (this.peekChar() === 0x0A) {
  40396. // LF
  40397. this.nextChar();
  40398. }
  40399. break;
  40400. case 0x0A:
  40401. // LF
  40402. break;
  40403. default:
  40404. strBuf.push(String.fromCharCode(ch));
  40405. break;
  40406. }
  40407. break;
  40408. default:
  40409. strBuf.push(String.fromCharCode(ch));
  40410. break;
  40411. }
  40412. if (done) {
  40413. break;
  40414. }
  40415. if (!charBuffered) {
  40416. ch = this.nextChar();
  40417. }
  40418. }
  40419. return strBuf.join('');
  40420. },
  40421. getName: function Lexer_getName() {
  40422. var ch, previousCh;
  40423. var strBuf = this.strBuf;
  40424. strBuf.length = 0;
  40425. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  40426. if (ch === 0x23) {
  40427. // '#'
  40428. ch = this.nextChar();
  40429. if (specialChars[ch]) {
  40430. warn('Lexer_getName: ' + 'NUMBER SIGN (#) should be followed by a hexadecimal number.');
  40431. strBuf.push('#');
  40432. break;
  40433. }
  40434. var x = toHexDigit(ch);
  40435. if (x !== -1) {
  40436. previousCh = ch;
  40437. ch = this.nextChar();
  40438. var x2 = toHexDigit(ch);
  40439. if (x2 === -1) {
  40440. warn('Lexer_getName: Illegal digit (' + String.fromCharCode(ch) + ') in hexadecimal number.');
  40441. strBuf.push('#', String.fromCharCode(previousCh));
  40442. if (specialChars[ch]) {
  40443. break;
  40444. }
  40445. strBuf.push(String.fromCharCode(ch));
  40446. continue;
  40447. }
  40448. strBuf.push(String.fromCharCode(x << 4 | x2));
  40449. } else {
  40450. strBuf.push('#', String.fromCharCode(ch));
  40451. }
  40452. } else {
  40453. strBuf.push(String.fromCharCode(ch));
  40454. }
  40455. }
  40456. if (strBuf.length > 127) {
  40457. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  40458. }
  40459. return Name.get(strBuf.join(''));
  40460. },
  40461. getHexString: function Lexer_getHexString() {
  40462. var strBuf = this.strBuf;
  40463. strBuf.length = 0;
  40464. var ch = this.currentChar;
  40465. var isFirstHex = true;
  40466. var firstDigit;
  40467. var secondDigit;
  40468. while (true) {
  40469. if (ch < 0) {
  40470. warn('Unterminated hex string');
  40471. break;
  40472. } else if (ch === 0x3E) {
  40473. // '>'
  40474. this.nextChar();
  40475. break;
  40476. } else if (specialChars[ch] === 1) {
  40477. ch = this.nextChar();
  40478. continue;
  40479. } else {
  40480. if (isFirstHex) {
  40481. firstDigit = toHexDigit(ch);
  40482. if (firstDigit === -1) {
  40483. warn('Ignoring invalid character "' + ch + '" in hex string');
  40484. ch = this.nextChar();
  40485. continue;
  40486. }
  40487. } else {
  40488. secondDigit = toHexDigit(ch);
  40489. if (secondDigit === -1) {
  40490. warn('Ignoring invalid character "' + ch + '" in hex string');
  40491. ch = this.nextChar();
  40492. continue;
  40493. }
  40494. strBuf.push(String.fromCharCode(firstDigit << 4 | secondDigit));
  40495. }
  40496. isFirstHex = !isFirstHex;
  40497. ch = this.nextChar();
  40498. }
  40499. }
  40500. return strBuf.join('');
  40501. },
  40502. getObj: function Lexer_getObj() {
  40503. // skip whitespace and comments
  40504. var comment = false;
  40505. var ch = this.currentChar;
  40506. while (true) {
  40507. if (ch < 0) {
  40508. return EOF;
  40509. }
  40510. if (comment) {
  40511. if (ch === 0x0A || ch === 0x0D) {
  40512. // LF, CR
  40513. comment = false;
  40514. }
  40515. } else if (ch === 0x25) {
  40516. // '%'
  40517. comment = true;
  40518. } else if (specialChars[ch] !== 1) {
  40519. break;
  40520. }
  40521. ch = this.nextChar();
  40522. }
  40523. // start reading token
  40524. switch (ch | 0) {
  40525. case 0x30:
  40526. case 0x31:
  40527. case 0x32:
  40528. case 0x33:
  40529. case 0x34:
  40530. // '0'-'4'
  40531. case 0x35:
  40532. case 0x36:
  40533. case 0x37:
  40534. case 0x38:
  40535. case 0x39:
  40536. // '5'-'9'
  40537. case 0x2B:
  40538. case 0x2D:
  40539. case 0x2E:
  40540. // '+', '-', '.'
  40541. return this.getNumber();
  40542. case 0x28:
  40543. // '('
  40544. return this.getString();
  40545. case 0x2F:
  40546. // '/'
  40547. return this.getName();
  40548. // array punctuation
  40549. case 0x5B:
  40550. // '['
  40551. this.nextChar();
  40552. return Cmd.get('[');
  40553. case 0x5D:
  40554. // ']'
  40555. this.nextChar();
  40556. return Cmd.get(']');
  40557. // hex string or dict punctuation
  40558. case 0x3C:
  40559. // '<'
  40560. ch = this.nextChar();
  40561. if (ch === 0x3C) {
  40562. // dict punctuation
  40563. this.nextChar();
  40564. return Cmd.get('<<');
  40565. }
  40566. return this.getHexString();
  40567. // dict punctuation
  40568. case 0x3E:
  40569. // '>'
  40570. ch = this.nextChar();
  40571. if (ch === 0x3E) {
  40572. this.nextChar();
  40573. return Cmd.get('>>');
  40574. }
  40575. return Cmd.get('>');
  40576. case 0x7B:
  40577. // '{'
  40578. this.nextChar();
  40579. return Cmd.get('{');
  40580. case 0x7D:
  40581. // '}'
  40582. this.nextChar();
  40583. return Cmd.get('}');
  40584. case 0x29:
  40585. // ')'
  40586. error('Illegal character: ' + ch);
  40587. break;
  40588. }
  40589. // command
  40590. var str = String.fromCharCode(ch);
  40591. var knownCommands = this.knownCommands;
  40592. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  40593. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  40594. // stop if known command is found and next character does not make
  40595. // the str a command
  40596. var possibleCommand = str + String.fromCharCode(ch);
  40597. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  40598. break;
  40599. }
  40600. if (str.length === 128) {
  40601. error('Command token too long: ' + str.length);
  40602. }
  40603. str = possibleCommand;
  40604. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  40605. }
  40606. if (str === 'true') {
  40607. return true;
  40608. }
  40609. if (str === 'false') {
  40610. return false;
  40611. }
  40612. if (str === 'null') {
  40613. return null;
  40614. }
  40615. return Cmd.get(str);
  40616. },
  40617. skipToNextLine: function Lexer_skipToNextLine() {
  40618. var ch = this.currentChar;
  40619. while (ch >= 0) {
  40620. if (ch === 0x0D) {
  40621. // CR
  40622. ch = this.nextChar();
  40623. if (ch === 0x0A) {
  40624. // LF
  40625. this.nextChar();
  40626. }
  40627. break;
  40628. } else if (ch === 0x0A) {
  40629. // LF
  40630. this.nextChar();
  40631. break;
  40632. }
  40633. ch = this.nextChar();
  40634. }
  40635. }
  40636. };
  40637. return Lexer;
  40638. }();
  40639. var Linearization = {
  40640. create: function LinearizationCreate(stream) {
  40641. function getInt(name, allowZeroValue) {
  40642. var obj = linDict.get(name);
  40643. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  40644. return obj;
  40645. }
  40646. throw new Error('The "' + name + '" parameter in the linearization ' + 'dictionary is invalid.');
  40647. }
  40648. function getHints() {
  40649. var hints = linDict.get('H'), hintsLength, item;
  40650. if (isArray(hints) && ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  40651. for (var index = 0; index < hintsLength; index++) {
  40652. if (!(isInt(item = hints[index]) && item > 0)) {
  40653. throw new Error('Hint (' + index + ') in the linearization dictionary is invalid.');
  40654. }
  40655. }
  40656. return hints;
  40657. }
  40658. throw new Error('Hint array in the linearization dictionary is invalid.');
  40659. }
  40660. var parser = new Parser(new Lexer(stream), false, null);
  40661. var obj1 = parser.getObj();
  40662. var obj2 = parser.getObj();
  40663. var obj3 = parser.getObj();
  40664. var linDict = parser.getObj();
  40665. var obj, length;
  40666. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) && isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  40667. return null;
  40668. } else // No valid linearization dictionary found.
  40669. if ((length = getInt('L')) !== stream.length) {
  40670. throw new Error('The "L" parameter in the linearization dictionary ' + 'does not equal the stream length.');
  40671. }
  40672. return {
  40673. length: length,
  40674. hints: getHints(),
  40675. objectNumberFirst: getInt('O'),
  40676. endFirst: getInt('E'),
  40677. numPages: getInt('N'),
  40678. mainXRefEntriesOffset: getInt('T'),
  40679. pageFirst: linDict.has('P') ? getInt('P', true) : 0
  40680. };
  40681. }
  40682. };
  40683. exports.EOF = EOF;
  40684. exports.Lexer = Lexer;
  40685. exports.Linearization = Linearization;
  40686. exports.Parser = Parser;
  40687. exports.isEOF = isEOF;
  40688. }));
  40689. (function (root, factory) {
  40690. factory(root.pdfjsCoreType1Parser = {}, root.pdfjsSharedUtil, root.pdfjsCoreStream, root.pdfjsCoreEncodings);
  40691. }(this, function (exports, sharedUtil, coreStream, coreEncodings) {
  40692. var warn = sharedUtil.warn;
  40693. var isSpace = sharedUtil.isSpace;
  40694. var Stream = coreStream.Stream;
  40695. var getEncoding = coreEncodings.getEncoding;
  40696. // Hinting is currently disabled due to unknown problems on windows
  40697. // in tracemonkey and various other pdfs with type1 fonts.
  40698. var HINTING_ENABLED = false;
  40699. /*
  40700. * CharStrings are encoded following the the CharString Encoding sequence
  40701. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  40702. * The value in a byte indicates a command, a number, or subsequent bytes
  40703. * that are to be interpreted in a special way.
  40704. *
  40705. * CharString Number Encoding:
  40706. * A CharString byte containing the values from 32 through 255 inclusive
  40707. * indicate an integer. These values are decoded in four ranges.
  40708. *
  40709. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  40710. * indicate the integer v - 139. Thus, the integer values from -107 through
  40711. * 107 inclusive may be encoded in single byte.
  40712. *
  40713. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  40714. * indicates an integer involving the next byte, w, according to the formula:
  40715. * [(v - 247) x 256] + w + 108
  40716. *
  40717. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  40718. * indicates an integer involving the next byte, w, according to the formula:
  40719. * -[(v - 251) * 256] - w - 108
  40720. *
  40721. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  40722. * are a two complement signed integer. The first of these bytes contains the
  40723. * highest order bits, the second byte contains the next higher order bits
  40724. * and the fourth byte contain the lowest order bits.
  40725. *
  40726. *
  40727. * CharString Command Encoding:
  40728. * CharStrings commands are encoded in 1 or 2 bytes.
  40729. *
  40730. * Single byte commands are encoded in 1 byte that contains a value between
  40731. * 0 and 31 inclusive.
  40732. * If a command byte contains the value 12, then the value in the next byte
  40733. * indicates a command. This "escape" mechanism allows many extra commands
  40734. * to be encoded and this encoding technique helps to minimize the length of
  40735. * the charStrings.
  40736. */
  40737. var Type1CharString = function Type1CharStringClosure() {
  40738. var COMMAND_MAP = {
  40739. 'hstem': [1],
  40740. 'vstem': [3],
  40741. 'vmoveto': [4],
  40742. 'rlineto': [5],
  40743. 'hlineto': [6],
  40744. 'vlineto': [7],
  40745. 'rrcurveto': [8],
  40746. 'callsubr': [10],
  40747. 'flex': [
  40748. 12,
  40749. 35
  40750. ],
  40751. 'drop': [
  40752. 12,
  40753. 18
  40754. ],
  40755. 'endchar': [14],
  40756. 'rmoveto': [21],
  40757. 'hmoveto': [22],
  40758. 'vhcurveto': [30],
  40759. 'hvcurveto': [31]
  40760. };
  40761. function Type1CharString() {
  40762. this.width = 0;
  40763. this.lsb = 0;
  40764. this.flexing = false;
  40765. this.output = [];
  40766. this.stack = [];
  40767. }
  40768. Type1CharString.prototype = {
  40769. convert: function Type1CharString_convert(encoded, subrs, seacAnalysisEnabled) {
  40770. var count = encoded.length;
  40771. var error = false;
  40772. var wx, sbx, subrNumber;
  40773. for (var i = 0; i < count; i++) {
  40774. var value = encoded[i];
  40775. if (value < 32) {
  40776. if (value === 12) {
  40777. value = (value << 8) + encoded[++i];
  40778. }
  40779. switch (value) {
  40780. case 1:
  40781. // hstem
  40782. if (!HINTING_ENABLED) {
  40783. this.stack = [];
  40784. break;
  40785. }
  40786. error = this.executeCommand(2, COMMAND_MAP.hstem);
  40787. break;
  40788. case 3:
  40789. // vstem
  40790. if (!HINTING_ENABLED) {
  40791. this.stack = [];
  40792. break;
  40793. }
  40794. error = this.executeCommand(2, COMMAND_MAP.vstem);
  40795. break;
  40796. case 4:
  40797. // vmoveto
  40798. if (this.flexing) {
  40799. if (this.stack.length < 1) {
  40800. error = true;
  40801. break;
  40802. }
  40803. // Add the dx for flex and but also swap the values so they are
  40804. // the right order.
  40805. var dy = this.stack.pop();
  40806. this.stack.push(0, dy);
  40807. break;
  40808. }
  40809. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  40810. break;
  40811. case 5:
  40812. // rlineto
  40813. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  40814. break;
  40815. case 6:
  40816. // hlineto
  40817. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  40818. break;
  40819. case 7:
  40820. // vlineto
  40821. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  40822. break;
  40823. case 8:
  40824. // rrcurveto
  40825. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  40826. break;
  40827. case 9:
  40828. // closepath
  40829. // closepath is a Type1 command that does not take argument and is
  40830. // useless in Type2 and it can simply be ignored.
  40831. this.stack = [];
  40832. break;
  40833. case 10:
  40834. // callsubr
  40835. if (this.stack.length < 1) {
  40836. error = true;
  40837. break;
  40838. }
  40839. subrNumber = this.stack.pop();
  40840. error = this.convert(subrs[subrNumber], subrs, seacAnalysisEnabled);
  40841. break;
  40842. case 11:
  40843. // return
  40844. return error;
  40845. case 13:
  40846. // hsbw
  40847. if (this.stack.length < 2) {
  40848. error = true;
  40849. break;
  40850. }
  40851. // To convert to type2 we have to move the width value to the
  40852. // first part of the charstring and then use hmoveto with lsb.
  40853. wx = this.stack.pop();
  40854. sbx = this.stack.pop();
  40855. this.lsb = sbx;
  40856. this.width = wx;
  40857. this.stack.push(wx, sbx);
  40858. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  40859. break;
  40860. case 14:
  40861. // endchar
  40862. this.output.push(COMMAND_MAP.endchar[0]);
  40863. break;
  40864. case 21:
  40865. // rmoveto
  40866. if (this.flexing) {
  40867. break;
  40868. }
  40869. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  40870. break;
  40871. case 22:
  40872. // hmoveto
  40873. if (this.flexing) {
  40874. // Add the dy for flex.
  40875. this.stack.push(0);
  40876. break;
  40877. }
  40878. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  40879. break;
  40880. case 30:
  40881. // vhcurveto
  40882. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  40883. break;
  40884. case 31:
  40885. // hvcurveto
  40886. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  40887. break;
  40888. case (12 << 8) + 0:
  40889. // dotsection
  40890. // dotsection is a Type1 command to specify some hinting feature
  40891. // for dots that do not take a parameter and it can safely be
  40892. // ignored for Type2.
  40893. this.stack = [];
  40894. break;
  40895. case (12 << 8) + 1:
  40896. // vstem3
  40897. if (!HINTING_ENABLED) {
  40898. this.stack = [];
  40899. break;
  40900. }
  40901. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  40902. // multiple parameters, so instead of returning [vh]stem3 take a
  40903. // shortcut and return [vhstem] instead.
  40904. error = this.executeCommand(2, COMMAND_MAP.vstem);
  40905. break;
  40906. case (12 << 8) + 2:
  40907. // hstem3
  40908. if (!HINTING_ENABLED) {
  40909. this.stack = [];
  40910. break;
  40911. }
  40912. // See vstem3.
  40913. error = this.executeCommand(2, COMMAND_MAP.hstem);
  40914. break;
  40915. case (12 << 8) + 6:
  40916. // seac
  40917. // seac is like type 2's special endchar but it doesn't use the
  40918. // first argument asb, so remove it.
  40919. if (seacAnalysisEnabled) {
  40920. this.seac = this.stack.splice(-4, 4);
  40921. error = this.executeCommand(0, COMMAND_MAP.endchar);
  40922. } else {
  40923. error = this.executeCommand(4, COMMAND_MAP.endchar);
  40924. }
  40925. break;
  40926. case (12 << 8) + 7:
  40927. // sbw
  40928. if (this.stack.length < 4) {
  40929. error = true;
  40930. break;
  40931. }
  40932. // To convert to type2 we have to move the width value to the
  40933. // first part of the charstring and then use rmoveto with
  40934. // (dx, dy). The height argument will not be used for vmtx and
  40935. // vhea tables reconstruction -- ignoring it.
  40936. var wy = this.stack.pop();
  40937. wx = this.stack.pop();
  40938. var sby = this.stack.pop();
  40939. sbx = this.stack.pop();
  40940. this.lsb = sbx;
  40941. this.width = wx;
  40942. this.stack.push(wx, sbx, sby);
  40943. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  40944. break;
  40945. case (12 << 8) + 12:
  40946. // div
  40947. if (this.stack.length < 2) {
  40948. error = true;
  40949. break;
  40950. }
  40951. var num2 = this.stack.pop();
  40952. var num1 = this.stack.pop();
  40953. this.stack.push(num1 / num2);
  40954. break;
  40955. case (12 << 8) + 16:
  40956. // callothersubr
  40957. if (this.stack.length < 2) {
  40958. error = true;
  40959. break;
  40960. }
  40961. subrNumber = this.stack.pop();
  40962. var numArgs = this.stack.pop();
  40963. if (subrNumber === 0 && numArgs === 3) {
  40964. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  40965. this.stack.push(flexArgs[2] + flexArgs[0], // bcp1x + rpx
  40966. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  40967. flexArgs[4], // bcp2x
  40968. flexArgs[5], // bcp2y
  40969. flexArgs[6], // p2x
  40970. flexArgs[7], // p2y
  40971. flexArgs[8], // bcp3x
  40972. flexArgs[9], // bcp3y
  40973. flexArgs[10], // bcp4x
  40974. flexArgs[11], // bcp4y
  40975. flexArgs[12], // p3x
  40976. flexArgs[13], // p3y
  40977. flexArgs[14]);
  40978. // flexDepth
  40979. // 15 = finalx unused by flex
  40980. // 16 = finaly unused by flex
  40981. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  40982. this.flexing = false;
  40983. this.stack.push(flexArgs[15], flexArgs[16]);
  40984. } else if (subrNumber === 1 && numArgs === 0) {
  40985. this.flexing = true;
  40986. }
  40987. break;
  40988. case (12 << 8) + 17:
  40989. // pop
  40990. // Ignore this since it is only used with othersubr.
  40991. break;
  40992. case (12 << 8) + 33:
  40993. // setcurrentpoint
  40994. // Ignore for now.
  40995. this.stack = [];
  40996. break;
  40997. default:
  40998. warn('Unknown type 1 charstring command of "' + value + '"');
  40999. break;
  41000. }
  41001. if (error) {
  41002. break;
  41003. }
  41004. continue;
  41005. } else if (value <= 246) {
  41006. value = value - 139;
  41007. } else if (value <= 250) {
  41008. value = (value - 247) * 256 + encoded[++i] + 108;
  41009. } else if (value <= 254) {
  41010. value = -((value - 251) * 256) - encoded[++i] - 108;
  41011. } else {
  41012. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 | (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  41013. }
  41014. this.stack.push(value);
  41015. }
  41016. return error;
  41017. },
  41018. executeCommand: function (howManyArgs, command, keepStack) {
  41019. var stackLength = this.stack.length;
  41020. if (howManyArgs > stackLength) {
  41021. return true;
  41022. }
  41023. var start = stackLength - howManyArgs;
  41024. for (var i = start; i < stackLength; i++) {
  41025. var value = this.stack[i];
  41026. if (value === (value | 0)) {
  41027. // int
  41028. this.output.push(28, value >> 8 & 0xff, value & 0xff);
  41029. } else {
  41030. // fixed point
  41031. value = 65536 * value | 0;
  41032. this.output.push(255, value >> 24 & 0xFF, value >> 16 & 0xFF, value >> 8 & 0xFF, value & 0xFF);
  41033. }
  41034. }
  41035. this.output.push.apply(this.output, command);
  41036. if (keepStack) {
  41037. this.stack.splice(start, howManyArgs);
  41038. } else {
  41039. this.stack.length = 0;
  41040. }
  41041. return false;
  41042. }
  41043. };
  41044. return Type1CharString;
  41045. }();
  41046. /*
  41047. * Type1Parser encapsulate the needed code for parsing a Type1 font
  41048. * program. Some of its logic depends on the Type2 charstrings
  41049. * structure.
  41050. * Note: this doesn't really parse the font since that would require evaluation
  41051. * of PostScript, but it is possible in most cases to extract what we need
  41052. * without a full parse.
  41053. */
  41054. var Type1Parser = function Type1ParserClosure() {
  41055. /*
  41056. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  41057. * of Plaintext Bytes. The function took a key as a parameter which can be
  41058. * for decrypting the eexec block of for decoding charStrings.
  41059. */
  41060. var EEXEC_ENCRYPT_KEY = 55665;
  41061. var CHAR_STRS_ENCRYPT_KEY = 4330;
  41062. function isHexDigit(code) {
  41063. return code >= 48 && code <= 57 || // '0'-'9'
  41064. code >= 65 && code <= 70 || // 'A'-'F'
  41065. code >= 97 && code <= 102;
  41066. }
  41067. // 'a'-'f'
  41068. function decrypt(data, key, discardNumber) {
  41069. if (discardNumber >= data.length) {
  41070. return new Uint8Array(0);
  41071. }
  41072. var r = key | 0, c1 = 52845, c2 = 22719, i, j;
  41073. for (i = 0; i < discardNumber; i++) {
  41074. r = (data[i] + r) * c1 + c2 & (1 << 16) - 1;
  41075. }
  41076. var count = data.length - discardNumber;
  41077. var decrypted = new Uint8Array(count);
  41078. for (i = discardNumber, j = 0; j < count; i++, j++) {
  41079. var value = data[i];
  41080. decrypted[j] = value ^ r >> 8;
  41081. r = (value + r) * c1 + c2 & (1 << 16) - 1;
  41082. }
  41083. return decrypted;
  41084. }
  41085. function decryptAscii(data, key, discardNumber) {
  41086. var r = key | 0, c1 = 52845, c2 = 22719;
  41087. var count = data.length, maybeLength = count >>> 1;
  41088. var decrypted = new Uint8Array(maybeLength);
  41089. var i, j;
  41090. for (i = 0, j = 0; i < count; i++) {
  41091. var digit1 = data[i];
  41092. if (!isHexDigit(digit1)) {
  41093. continue;
  41094. }
  41095. i++;
  41096. var digit2;
  41097. while (i < count && !isHexDigit(digit2 = data[i])) {
  41098. i++;
  41099. }
  41100. if (i < count) {
  41101. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  41102. decrypted[j++] = value ^ r >> 8;
  41103. r = (value + r) * c1 + c2 & (1 << 16) - 1;
  41104. }
  41105. }
  41106. return Array.prototype.slice.call(decrypted, discardNumber, j);
  41107. }
  41108. function isSpecial(c) {
  41109. return c === 0x2F || // '/'
  41110. c === 0x5B || c === 0x5D || // '[', ']'
  41111. c === 0x7B || c === 0x7D || // '{', '}'
  41112. c === 0x28 || c === 0x29;
  41113. }
  41114. // '(', ')'
  41115. function Type1Parser(stream, encrypted, seacAnalysisEnabled) {
  41116. if (encrypted) {
  41117. var data = stream.getBytes();
  41118. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) && isHexDigit(data[2]) && isHexDigit(data[3]));
  41119. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) : decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  41120. }
  41121. this.seacAnalysisEnabled = !!seacAnalysisEnabled;
  41122. this.stream = stream;
  41123. this.nextChar();
  41124. }
  41125. Type1Parser.prototype = {
  41126. readNumberArray: function Type1Parser_readNumberArray() {
  41127. this.getToken();
  41128. // read '[' or '{' (arrays can start with either)
  41129. var array = [];
  41130. while (true) {
  41131. var token = this.getToken();
  41132. if (token === null || token === ']' || token === '}') {
  41133. break;
  41134. }
  41135. array.push(parseFloat(token || 0));
  41136. }
  41137. return array;
  41138. },
  41139. readNumber: function Type1Parser_readNumber() {
  41140. var token = this.getToken();
  41141. return parseFloat(token || 0);
  41142. },
  41143. readInt: function Type1Parser_readInt() {
  41144. // Use '| 0' to prevent setting a double into length such as the double
  41145. // does not flow into the loop variable.
  41146. var token = this.getToken();
  41147. return parseInt(token || 0, 10) | 0;
  41148. },
  41149. readBoolean: function Type1Parser_readBoolean() {
  41150. var token = this.getToken();
  41151. // Use 1 and 0 since that's what type2 charstrings use.
  41152. return token === 'true' ? 1 : 0;
  41153. },
  41154. nextChar: function Type1_nextChar() {
  41155. return this.currentChar = this.stream.getByte();
  41156. },
  41157. getToken: function Type1Parser_getToken() {
  41158. // Eat whitespace and comments.
  41159. var comment = false;
  41160. var ch = this.currentChar;
  41161. while (true) {
  41162. if (ch === -1) {
  41163. return null;
  41164. }
  41165. if (comment) {
  41166. if (ch === 0x0A || ch === 0x0D) {
  41167. comment = false;
  41168. }
  41169. } else if (ch === 0x25) {
  41170. // '%'
  41171. comment = true;
  41172. } else if (!isSpace(ch)) {
  41173. break;
  41174. }
  41175. ch = this.nextChar();
  41176. }
  41177. if (isSpecial(ch)) {
  41178. this.nextChar();
  41179. return String.fromCharCode(ch);
  41180. }
  41181. var token = '';
  41182. do {
  41183. token += String.fromCharCode(ch);
  41184. ch = this.nextChar();
  41185. } while (ch >= 0 && !isSpace(ch) && !isSpecial(ch));
  41186. return token;
  41187. },
  41188. /*
  41189. * Returns an object containing a Subrs array and a CharStrings
  41190. * array extracted from and eexec encrypted block of data
  41191. */
  41192. extractFontProgram: function Type1Parser_extractFontProgram() {
  41193. var stream = this.stream;
  41194. var subrs = [], charstrings = [];
  41195. var privateData = Object.create(null);
  41196. privateData['lenIV'] = 4;
  41197. var program = {
  41198. subrs: [],
  41199. charstrings: [],
  41200. properties: { 'privateData': privateData }
  41201. };
  41202. var token, length, data, lenIV, encoded;
  41203. while ((token = this.getToken()) !== null) {
  41204. if (token !== '/') {
  41205. continue;
  41206. }
  41207. token = this.getToken();
  41208. switch (token) {
  41209. case 'CharStrings':
  41210. // The number immediately following CharStrings must be greater or
  41211. // equal to the number of CharStrings.
  41212. this.getToken();
  41213. this.getToken();
  41214. // read in 'dict'
  41215. this.getToken();
  41216. // read in 'dup'
  41217. this.getToken();
  41218. // read in 'begin'
  41219. while (true) {
  41220. token = this.getToken();
  41221. if (token === null || token === 'end') {
  41222. break;
  41223. }
  41224. if (token !== '/') {
  41225. continue;
  41226. }
  41227. var glyph = this.getToken();
  41228. length = this.readInt();
  41229. this.getToken();
  41230. // read in 'RD' or '-|'
  41231. data = stream.makeSubStream(stream.pos, length);
  41232. lenIV = program.properties.privateData['lenIV'];
  41233. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  41234. // Skip past the required space and binary data.
  41235. stream.skip(length);
  41236. this.nextChar();
  41237. token = this.getToken();
  41238. // read in 'ND' or '|-'
  41239. if (token === 'noaccess') {
  41240. this.getToken();
  41241. }
  41242. // read in 'def'
  41243. charstrings.push({
  41244. glyph: glyph,
  41245. encoded: encoded
  41246. });
  41247. }
  41248. break;
  41249. case 'Subrs':
  41250. var num = this.readInt();
  41251. this.getToken();
  41252. // read in 'array'
  41253. while ((token = this.getToken()) === 'dup') {
  41254. var index = this.readInt();
  41255. length = this.readInt();
  41256. this.getToken();
  41257. // read in 'RD' or '-|'
  41258. data = stream.makeSubStream(stream.pos, length);
  41259. lenIV = program.properties.privateData['lenIV'];
  41260. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  41261. // Skip past the required space and binary data.
  41262. stream.skip(length);
  41263. this.nextChar();
  41264. token = this.getToken();
  41265. // read in 'NP' or '|'
  41266. if (token === 'noaccess') {
  41267. this.getToken();
  41268. }
  41269. // read in 'put'
  41270. subrs[index] = encoded;
  41271. }
  41272. break;
  41273. case 'BlueValues':
  41274. case 'OtherBlues':
  41275. case 'FamilyBlues':
  41276. case 'FamilyOtherBlues':
  41277. var blueArray = this.readNumberArray();
  41278. // *Blue* values may contain invalid data: disables reading of
  41279. // those values when hinting is disabled.
  41280. if (blueArray.length > 0 && blueArray.length % 2 === 0 && HINTING_ENABLED) {
  41281. program.properties.privateData[token] = blueArray;
  41282. }
  41283. break;
  41284. case 'StemSnapH':
  41285. case 'StemSnapV':
  41286. program.properties.privateData[token] = this.readNumberArray();
  41287. break;
  41288. case 'StdHW':
  41289. case 'StdVW':
  41290. program.properties.privateData[token] = this.readNumberArray()[0];
  41291. break;
  41292. case 'BlueShift':
  41293. case 'lenIV':
  41294. case 'BlueFuzz':
  41295. case 'BlueScale':
  41296. case 'LanguageGroup':
  41297. case 'ExpansionFactor':
  41298. program.properties.privateData[token] = this.readNumber();
  41299. break;
  41300. case 'ForceBold':
  41301. program.properties.privateData[token] = this.readBoolean();
  41302. break;
  41303. }
  41304. }
  41305. for (var i = 0; i < charstrings.length; i++) {
  41306. glyph = charstrings[i].glyph;
  41307. encoded = charstrings[i].encoded;
  41308. var charString = new Type1CharString();
  41309. var error = charString.convert(encoded, subrs, this.seacAnalysisEnabled);
  41310. var output = charString.output;
  41311. if (error) {
  41312. // It seems when FreeType encounters an error while evaluating a glyph
  41313. // that it completely ignores the glyph so we'll mimic that behaviour
  41314. // here and put an endchar to make the validator happy.
  41315. output = [14];
  41316. }
  41317. program.charstrings.push({
  41318. glyphName: glyph,
  41319. charstring: output,
  41320. width: charString.width,
  41321. lsb: charString.lsb,
  41322. seac: charString.seac
  41323. });
  41324. }
  41325. return program;
  41326. },
  41327. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  41328. var token;
  41329. while ((token = this.getToken()) !== null) {
  41330. if (token !== '/') {
  41331. continue;
  41332. }
  41333. token = this.getToken();
  41334. switch (token) {
  41335. case 'FontMatrix':
  41336. var matrix = this.readNumberArray();
  41337. properties.fontMatrix = matrix;
  41338. break;
  41339. case 'Encoding':
  41340. var encodingArg = this.getToken();
  41341. var encoding;
  41342. if (!/^\d+$/.test(encodingArg)) {
  41343. // encoding name is specified
  41344. encoding = getEncoding(encodingArg);
  41345. } else {
  41346. encoding = [];
  41347. var size = parseInt(encodingArg, 10) | 0;
  41348. this.getToken();
  41349. // read in 'array'
  41350. for (var j = 0; j < size; j++) {
  41351. token = this.getToken();
  41352. // skipping till first dup or def (e.g. ignoring for statement)
  41353. while (token !== 'dup' && token !== 'def') {
  41354. token = this.getToken();
  41355. if (token === null) {
  41356. return;
  41357. }
  41358. }
  41359. // invalid header
  41360. if (token === 'def') {
  41361. break;
  41362. }
  41363. // read all array data
  41364. var index = this.readInt();
  41365. this.getToken();
  41366. // read in '/'
  41367. var glyph = this.getToken();
  41368. encoding[index] = glyph;
  41369. this.getToken();
  41370. }
  41371. }
  41372. // read the in 'put'
  41373. properties.builtInEncoding = encoding;
  41374. break;
  41375. case 'FontBBox':
  41376. var fontBBox = this.readNumberArray();
  41377. // adjusting ascent/descent
  41378. properties.ascent = fontBBox[3];
  41379. properties.descent = fontBBox[1];
  41380. properties.ascentScaled = true;
  41381. break;
  41382. }
  41383. }
  41384. }
  41385. };
  41386. return Type1Parser;
  41387. }();
  41388. exports.Type1Parser = Type1Parser;
  41389. }));
  41390. (function (root, factory) {
  41391. factory(root.pdfjsDisplayPatternHelper = {}, root.pdfjsSharedUtil, root.pdfjsDisplayWebGL);
  41392. }(this, function (exports, sharedUtil, displayWebGL) {
  41393. var Util = sharedUtil.Util;
  41394. var info = sharedUtil.info;
  41395. var isArray = sharedUtil.isArray;
  41396. var error = sharedUtil.error;
  41397. var WebGLUtils = displayWebGL.WebGLUtils;
  41398. var ShadingIRs = {};
  41399. ShadingIRs.RadialAxial = {
  41400. fromIR: function RadialAxial_fromIR(raw) {
  41401. var type = raw[1];
  41402. var colorStops = raw[2];
  41403. var p0 = raw[3];
  41404. var p1 = raw[4];
  41405. var r0 = raw[5];
  41406. var r1 = raw[6];
  41407. return {
  41408. type: 'Pattern',
  41409. getPattern: function RadialAxial_getPattern(ctx) {
  41410. var grad;
  41411. if (type === 'axial') {
  41412. grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
  41413. } else if (type === 'radial') {
  41414. grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
  41415. }
  41416. for (var i = 0, ii = colorStops.length; i < ii; ++i) {
  41417. var c = colorStops[i];
  41418. grad.addColorStop(c[0], c[1]);
  41419. }
  41420. return grad;
  41421. }
  41422. };
  41423. }
  41424. };
  41425. var createMeshCanvas = function createMeshCanvasClosure() {
  41426. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  41427. // Very basic Gouraud-shaded triangle rasterization algorithm.
  41428. var coords = context.coords, colors = context.colors;
  41429. var bytes = data.data, rowSize = data.width * 4;
  41430. var tmp;
  41431. if (coords[p1 + 1] > coords[p2 + 1]) {
  41432. tmp = p1;
  41433. p1 = p2;
  41434. p2 = tmp;
  41435. tmp = c1;
  41436. c1 = c2;
  41437. c2 = tmp;
  41438. }
  41439. if (coords[p2 + 1] > coords[p3 + 1]) {
  41440. tmp = p2;
  41441. p2 = p3;
  41442. p3 = tmp;
  41443. tmp = c2;
  41444. c2 = c3;
  41445. c3 = tmp;
  41446. }
  41447. if (coords[p1 + 1] > coords[p2 + 1]) {
  41448. tmp = p1;
  41449. p1 = p2;
  41450. p2 = tmp;
  41451. tmp = c1;
  41452. c1 = c2;
  41453. c2 = tmp;
  41454. }
  41455. var x1 = (coords[p1] + context.offsetX) * context.scaleX;
  41456. var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  41457. var x2 = (coords[p2] + context.offsetX) * context.scaleX;
  41458. var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  41459. var x3 = (coords[p3] + context.offsetX) * context.scaleX;
  41460. var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  41461. if (y1 >= y3) {
  41462. return;
  41463. }
  41464. var c1r = colors[c1], c1g = colors[c1 + 1], c1b = colors[c1 + 2];
  41465. var c2r = colors[c2], c2g = colors[c2 + 1], c2b = colors[c2 + 2];
  41466. var c3r = colors[c3], c3g = colors[c3 + 1], c3b = colors[c3 + 2];
  41467. var minY = Math.round(y1), maxY = Math.round(y3);
  41468. var xa, car, cag, cab;
  41469. var xb, cbr, cbg, cbb;
  41470. var k;
  41471. for (var y = minY; y <= maxY; y++) {
  41472. if (y < y2) {
  41473. k = y < y1 ? 0 : y1 === y2 ? 1 : (y1 - y) / (y1 - y2);
  41474. xa = x1 - (x1 - x2) * k;
  41475. car = c1r - (c1r - c2r) * k;
  41476. cag = c1g - (c1g - c2g) * k;
  41477. cab = c1b - (c1b - c2b) * k;
  41478. } else {
  41479. k = y > y3 ? 1 : y2 === y3 ? 0 : (y2 - y) / (y2 - y3);
  41480. xa = x2 - (x2 - x3) * k;
  41481. car = c2r - (c2r - c3r) * k;
  41482. cag = c2g - (c2g - c3g) * k;
  41483. cab = c2b - (c2b - c3b) * k;
  41484. }
  41485. k = y < y1 ? 0 : y > y3 ? 1 : (y1 - y) / (y1 - y3);
  41486. xb = x1 - (x1 - x3) * k;
  41487. cbr = c1r - (c1r - c3r) * k;
  41488. cbg = c1g - (c1g - c3g) * k;
  41489. cbb = c1b - (c1b - c3b) * k;
  41490. var x1_ = Math.round(Math.min(xa, xb));
  41491. var x2_ = Math.round(Math.max(xa, xb));
  41492. var j = rowSize * y + x1_ * 4;
  41493. for (var x = x1_; x <= x2_; x++) {
  41494. k = (xa - x) / (xa - xb);
  41495. k = k < 0 ? 0 : k > 1 ? 1 : k;
  41496. bytes[j++] = car - (car - cbr) * k | 0;
  41497. bytes[j++] = cag - (cag - cbg) * k | 0;
  41498. bytes[j++] = cab - (cab - cbb) * k | 0;
  41499. bytes[j++] = 255;
  41500. }
  41501. }
  41502. }
  41503. function drawFigure(data, figure, context) {
  41504. var ps = figure.coords;
  41505. var cs = figure.colors;
  41506. var i, ii;
  41507. switch (figure.type) {
  41508. case 'lattice':
  41509. var verticesPerRow = figure.verticesPerRow;
  41510. var rows = Math.floor(ps.length / verticesPerRow) - 1;
  41511. var cols = verticesPerRow - 1;
  41512. for (i = 0; i < rows; i++) {
  41513. var q = i * verticesPerRow;
  41514. for (var j = 0; j < cols; j++, q++) {
  41515. drawTriangle(data, context, ps[q], ps[q + 1], ps[q + verticesPerRow], cs[q], cs[q + 1], cs[q + verticesPerRow]);
  41516. drawTriangle(data, context, ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow], cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  41517. }
  41518. }
  41519. break;
  41520. case 'triangles':
  41521. for (i = 0, ii = ps.length; i < ii; i += 3) {
  41522. drawTriangle(data, context, ps[i], ps[i + 1], ps[i + 2], cs[i], cs[i + 1], cs[i + 2]);
  41523. }
  41524. break;
  41525. default:
  41526. error('illigal figure');
  41527. break;
  41528. }
  41529. }
  41530. function createMeshCanvas(bounds, combinesScale, coords, colors, figures, backgroundColor, cachedCanvases) {
  41531. // we will increase scale on some weird factor to let antialiasing take
  41532. // care of "rough" edges
  41533. var EXPECTED_SCALE = 1.1;
  41534. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  41535. var MAX_PATTERN_SIZE = 3000;
  41536. // 10in @ 300dpi shall be enough
  41537. // We need to keep transparent border around our pattern for fill():
  41538. // createPattern with 'no-repeat' will bleed edges across entire area.
  41539. var BORDER_SIZE = 2;
  41540. var offsetX = Math.floor(bounds[0]);
  41541. var offsetY = Math.floor(bounds[1]);
  41542. var boundsWidth = Math.ceil(bounds[2]) - offsetX;
  41543. var boundsHeight = Math.ceil(bounds[3]) - offsetY;
  41544. var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  41545. var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  41546. var scaleX = boundsWidth / width;
  41547. var scaleY = boundsHeight / height;
  41548. var context = {
  41549. coords: coords,
  41550. colors: colors,
  41551. offsetX: -offsetX,
  41552. offsetY: -offsetY,
  41553. scaleX: 1 / scaleX,
  41554. scaleY: 1 / scaleY
  41555. };
  41556. var paddedWidth = width + BORDER_SIZE * 2;
  41557. var paddedHeight = height + BORDER_SIZE * 2;
  41558. var canvas, tmpCanvas, i, ii;
  41559. if (WebGLUtils.isEnabled) {
  41560. canvas = WebGLUtils.drawFigures(width, height, backgroundColor, figures, context);
  41561. // https://bugzilla.mozilla.org/show_bug.cgi?id=972126
  41562. tmpCanvas = cachedCanvases.getCanvas('mesh', paddedWidth, paddedHeight, false);
  41563. tmpCanvas.context.drawImage(canvas, BORDER_SIZE, BORDER_SIZE);
  41564. canvas = tmpCanvas.canvas;
  41565. } else {
  41566. tmpCanvas = cachedCanvases.getCanvas('mesh', paddedWidth, paddedHeight, false);
  41567. var tmpCtx = tmpCanvas.context;
  41568. var data = tmpCtx.createImageData(width, height);
  41569. if (backgroundColor) {
  41570. var bytes = data.data;
  41571. for (i = 0, ii = bytes.length; i < ii; i += 4) {
  41572. bytes[i] = backgroundColor[0];
  41573. bytes[i + 1] = backgroundColor[1];
  41574. bytes[i + 2] = backgroundColor[2];
  41575. bytes[i + 3] = 255;
  41576. }
  41577. }
  41578. for (i = 0; i < figures.length; i++) {
  41579. drawFigure(data, figures[i], context);
  41580. }
  41581. tmpCtx.putImageData(data, BORDER_SIZE, BORDER_SIZE);
  41582. canvas = tmpCanvas.canvas;
  41583. }
  41584. return {
  41585. canvas: canvas,
  41586. offsetX: offsetX - BORDER_SIZE * scaleX,
  41587. offsetY: offsetY - BORDER_SIZE * scaleY,
  41588. scaleX: scaleX,
  41589. scaleY: scaleY
  41590. };
  41591. }
  41592. return createMeshCanvas;
  41593. }();
  41594. ShadingIRs.Mesh = {
  41595. fromIR: function Mesh_fromIR(raw) {
  41596. //var type = raw[1];
  41597. var coords = raw[2];
  41598. var colors = raw[3];
  41599. var figures = raw[4];
  41600. var bounds = raw[5];
  41601. var matrix = raw[6];
  41602. //var bbox = raw[7];
  41603. var background = raw[8];
  41604. return {
  41605. type: 'Pattern',
  41606. getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
  41607. var scale;
  41608. if (shadingFill) {
  41609. scale = Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  41610. } else {
  41611. // Obtain scale from matrix and current transformation matrix.
  41612. scale = Util.singularValueDecompose2dScale(owner.baseTransform);
  41613. if (matrix) {
  41614. var matrixScale = Util.singularValueDecompose2dScale(matrix);
  41615. scale = [
  41616. scale[0] * matrixScale[0],
  41617. scale[1] * matrixScale[1]
  41618. ];
  41619. }
  41620. }
  41621. // Rasterizing on the main thread since sending/queue large canvases
  41622. // might cause OOM.
  41623. var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords, colors, figures, shadingFill ? null : background, owner.cachedCanvases);
  41624. if (!shadingFill) {
  41625. ctx.setTransform.apply(ctx, owner.baseTransform);
  41626. if (matrix) {
  41627. ctx.transform.apply(ctx, matrix);
  41628. }
  41629. }
  41630. ctx.translate(temporaryPatternCanvas.offsetX, temporaryPatternCanvas.offsetY);
  41631. ctx.scale(temporaryPatternCanvas.scaleX, temporaryPatternCanvas.scaleY);
  41632. return ctx.createPattern(temporaryPatternCanvas.canvas, 'no-repeat');
  41633. }
  41634. };
  41635. }
  41636. };
  41637. ShadingIRs.Dummy = {
  41638. fromIR: function Dummy_fromIR() {
  41639. return {
  41640. type: 'Pattern',
  41641. getPattern: function Dummy_fromIR_getPattern() {
  41642. return 'hotpink';
  41643. }
  41644. };
  41645. }
  41646. };
  41647. function getShadingPatternFromIR(raw) {
  41648. var shadingIR = ShadingIRs[raw[0]];
  41649. if (!shadingIR) {
  41650. error('Unknown IR type: ' + raw[0]);
  41651. }
  41652. return shadingIR.fromIR(raw);
  41653. }
  41654. var TilingPattern = function TilingPatternClosure() {
  41655. var PaintType = {
  41656. COLORED: 1,
  41657. UNCOLORED: 2
  41658. };
  41659. var MAX_PATTERN_SIZE = 3000;
  41660. // 10in @ 300dpi shall be enough
  41661. function TilingPattern(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
  41662. this.operatorList = IR[2];
  41663. this.matrix = IR[3] || [
  41664. 1,
  41665. 0,
  41666. 0,
  41667. 1,
  41668. 0,
  41669. 0
  41670. ];
  41671. this.bbox = IR[4];
  41672. this.xstep = IR[5];
  41673. this.ystep = IR[6];
  41674. this.paintType = IR[7];
  41675. this.tilingType = IR[8];
  41676. this.color = color;
  41677. this.canvasGraphicsFactory = canvasGraphicsFactory;
  41678. this.baseTransform = baseTransform;
  41679. this.type = 'Pattern';
  41680. this.ctx = ctx;
  41681. }
  41682. TilingPattern.prototype = {
  41683. createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
  41684. var operatorList = this.operatorList;
  41685. var bbox = this.bbox;
  41686. var xstep = this.xstep;
  41687. var ystep = this.ystep;
  41688. var paintType = this.paintType;
  41689. var tilingType = this.tilingType;
  41690. var color = this.color;
  41691. var canvasGraphicsFactory = this.canvasGraphicsFactory;
  41692. info('TilingType: ' + tilingType);
  41693. var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
  41694. var topLeft = [
  41695. x0,
  41696. y0
  41697. ];
  41698. // we want the canvas to be as large as the step size
  41699. var botRight = [
  41700. x0 + xstep,
  41701. y0 + ystep
  41702. ];
  41703. var width = botRight[0] - topLeft[0];
  41704. var height = botRight[1] - topLeft[1];
  41705. // Obtain scale from matrix and current transformation matrix.
  41706. var matrixScale = Util.singularValueDecompose2dScale(this.matrix);
  41707. var curMatrixScale = Util.singularValueDecompose2dScale(this.baseTransform);
  41708. var combinedScale = [
  41709. matrixScale[0] * curMatrixScale[0],
  41710. matrixScale[1] * curMatrixScale[1]
  41711. ];
  41712. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  41713. // Use width and height values that are as close as possible to the end
  41714. // result when the pattern is used. Too low value makes the pattern look
  41715. // blurry. Too large value makes it look too crispy.
  41716. width = Math.min(Math.ceil(Math.abs(width * combinedScale[0])), MAX_PATTERN_SIZE);
  41717. height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])), MAX_PATTERN_SIZE);
  41718. var tmpCanvas = owner.cachedCanvases.getCanvas('pattern', width, height, true);
  41719. var tmpCtx = tmpCanvas.context;
  41720. var graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
  41721. graphics.groupLevel = owner.groupLevel;
  41722. this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color);
  41723. this.setScale(width, height, xstep, ystep);
  41724. this.transformToScale(graphics);
  41725. // transform coordinates to pattern space
  41726. var tmpTranslate = [
  41727. 1,
  41728. 0,
  41729. 0,
  41730. 1,
  41731. -topLeft[0],
  41732. -topLeft[1]
  41733. ];
  41734. graphics.transform.apply(graphics, tmpTranslate);
  41735. this.clipBbox(graphics, bbox, x0, y0, x1, y1);
  41736. graphics.executeOperatorList(operatorList);
  41737. return tmpCanvas.canvas;
  41738. },
  41739. setScale: function TilingPattern_setScale(width, height, xstep, ystep) {
  41740. this.scale = [
  41741. width / xstep,
  41742. height / ystep
  41743. ];
  41744. },
  41745. transformToScale: function TilingPattern_transformToScale(graphics) {
  41746. var scale = this.scale;
  41747. var tmpScale = [
  41748. scale[0],
  41749. 0,
  41750. 0,
  41751. scale[1],
  41752. 0,
  41753. 0
  41754. ];
  41755. graphics.transform.apply(graphics, tmpScale);
  41756. },
  41757. scaleToContext: function TilingPattern_scaleToContext() {
  41758. var scale = this.scale;
  41759. this.ctx.scale(1 / scale[0], 1 / scale[1]);
  41760. },
  41761. clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
  41762. if (bbox && isArray(bbox) && bbox.length === 4) {
  41763. var bboxWidth = x1 - x0;
  41764. var bboxHeight = y1 - y0;
  41765. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  41766. graphics.clip();
  41767. graphics.endPath();
  41768. }
  41769. },
  41770. setFillAndStrokeStyleToContext: function setFillAndStrokeStyleToContext(context, paintType, color) {
  41771. switch (paintType) {
  41772. case PaintType.COLORED:
  41773. var ctx = this.ctx;
  41774. context.fillStyle = ctx.fillStyle;
  41775. context.strokeStyle = ctx.strokeStyle;
  41776. break;
  41777. case PaintType.UNCOLORED:
  41778. var cssColor = Util.makeCssRgb(color[0], color[1], color[2]);
  41779. context.fillStyle = cssColor;
  41780. context.strokeStyle = cssColor;
  41781. break;
  41782. default:
  41783. error('Unsupported paint type: ' + paintType);
  41784. }
  41785. },
  41786. getPattern: function TilingPattern_getPattern(ctx, owner) {
  41787. var temporaryPatternCanvas = this.createPatternCanvas(owner);
  41788. ctx = this.ctx;
  41789. ctx.setTransform.apply(ctx, this.baseTransform);
  41790. ctx.transform.apply(ctx, this.matrix);
  41791. this.scaleToContext();
  41792. return ctx.createPattern(temporaryPatternCanvas, 'repeat');
  41793. }
  41794. };
  41795. return TilingPattern;
  41796. }();
  41797. exports.getShadingPatternFromIR = getShadingPatternFromIR;
  41798. exports.TilingPattern = TilingPattern;
  41799. }));
  41800. (function (root, factory) {
  41801. factory(root.pdfjsCoreCMap = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser);
  41802. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser) {
  41803. var Util = sharedUtil.Util;
  41804. var assert = sharedUtil.assert;
  41805. var warn = sharedUtil.warn;
  41806. var error = sharedUtil.error;
  41807. var isInt = sharedUtil.isInt;
  41808. var isString = sharedUtil.isString;
  41809. var MissingDataException = sharedUtil.MissingDataException;
  41810. var isName = corePrimitives.isName;
  41811. var isCmd = corePrimitives.isCmd;
  41812. var isStream = corePrimitives.isStream;
  41813. var StringStream = coreStream.StringStream;
  41814. var Lexer = coreParser.Lexer;
  41815. var isEOF = coreParser.isEOF;
  41816. var BUILT_IN_CMAPS = [
  41817. // << Start unicode maps.
  41818. 'Adobe-GB1-UCS2',
  41819. 'Adobe-CNS1-UCS2',
  41820. 'Adobe-Japan1-UCS2',
  41821. 'Adobe-Korea1-UCS2',
  41822. // >> End unicode maps.
  41823. '78-EUC-H',
  41824. '78-EUC-V',
  41825. '78-H',
  41826. '78-RKSJ-H',
  41827. '78-RKSJ-V',
  41828. '78-V',
  41829. '78ms-RKSJ-H',
  41830. '78ms-RKSJ-V',
  41831. '83pv-RKSJ-H',
  41832. '90ms-RKSJ-H',
  41833. '90ms-RKSJ-V',
  41834. '90msp-RKSJ-H',
  41835. '90msp-RKSJ-V',
  41836. '90pv-RKSJ-H',
  41837. '90pv-RKSJ-V',
  41838. 'Add-H',
  41839. 'Add-RKSJ-H',
  41840. 'Add-RKSJ-V',
  41841. 'Add-V',
  41842. 'Adobe-CNS1-0',
  41843. 'Adobe-CNS1-1',
  41844. 'Adobe-CNS1-2',
  41845. 'Adobe-CNS1-3',
  41846. 'Adobe-CNS1-4',
  41847. 'Adobe-CNS1-5',
  41848. 'Adobe-CNS1-6',
  41849. 'Adobe-GB1-0',
  41850. 'Adobe-GB1-1',
  41851. 'Adobe-GB1-2',
  41852. 'Adobe-GB1-3',
  41853. 'Adobe-GB1-4',
  41854. 'Adobe-GB1-5',
  41855. 'Adobe-Japan1-0',
  41856. 'Adobe-Japan1-1',
  41857. 'Adobe-Japan1-2',
  41858. 'Adobe-Japan1-3',
  41859. 'Adobe-Japan1-4',
  41860. 'Adobe-Japan1-5',
  41861. 'Adobe-Japan1-6',
  41862. 'Adobe-Korea1-0',
  41863. 'Adobe-Korea1-1',
  41864. 'Adobe-Korea1-2',
  41865. 'B5-H',
  41866. 'B5-V',
  41867. 'B5pc-H',
  41868. 'B5pc-V',
  41869. 'CNS-EUC-H',
  41870. 'CNS-EUC-V',
  41871. 'CNS1-H',
  41872. 'CNS1-V',
  41873. 'CNS2-H',
  41874. 'CNS2-V',
  41875. 'ETHK-B5-H',
  41876. 'ETHK-B5-V',
  41877. 'ETen-B5-H',
  41878. 'ETen-B5-V',
  41879. 'ETenms-B5-H',
  41880. 'ETenms-B5-V',
  41881. 'EUC-H',
  41882. 'EUC-V',
  41883. 'Ext-H',
  41884. 'Ext-RKSJ-H',
  41885. 'Ext-RKSJ-V',
  41886. 'Ext-V',
  41887. 'GB-EUC-H',
  41888. 'GB-EUC-V',
  41889. 'GB-H',
  41890. 'GB-V',
  41891. 'GBK-EUC-H',
  41892. 'GBK-EUC-V',
  41893. 'GBK2K-H',
  41894. 'GBK2K-V',
  41895. 'GBKp-EUC-H',
  41896. 'GBKp-EUC-V',
  41897. 'GBT-EUC-H',
  41898. 'GBT-EUC-V',
  41899. 'GBT-H',
  41900. 'GBT-V',
  41901. 'GBTpc-EUC-H',
  41902. 'GBTpc-EUC-V',
  41903. 'GBpc-EUC-H',
  41904. 'GBpc-EUC-V',
  41905. 'H',
  41906. 'HKdla-B5-H',
  41907. 'HKdla-B5-V',
  41908. 'HKdlb-B5-H',
  41909. 'HKdlb-B5-V',
  41910. 'HKgccs-B5-H',
  41911. 'HKgccs-B5-V',
  41912. 'HKm314-B5-H',
  41913. 'HKm314-B5-V',
  41914. 'HKm471-B5-H',
  41915. 'HKm471-B5-V',
  41916. 'HKscs-B5-H',
  41917. 'HKscs-B5-V',
  41918. 'Hankaku',
  41919. 'Hiragana',
  41920. 'KSC-EUC-H',
  41921. 'KSC-EUC-V',
  41922. 'KSC-H',
  41923. 'KSC-Johab-H',
  41924. 'KSC-Johab-V',
  41925. 'KSC-V',
  41926. 'KSCms-UHC-H',
  41927. 'KSCms-UHC-HW-H',
  41928. 'KSCms-UHC-HW-V',
  41929. 'KSCms-UHC-V',
  41930. 'KSCpc-EUC-H',
  41931. 'KSCpc-EUC-V',
  41932. 'Katakana',
  41933. 'NWP-H',
  41934. 'NWP-V',
  41935. 'RKSJ-H',
  41936. 'RKSJ-V',
  41937. 'Roman',
  41938. 'UniCNS-UCS2-H',
  41939. 'UniCNS-UCS2-V',
  41940. 'UniCNS-UTF16-H',
  41941. 'UniCNS-UTF16-V',
  41942. 'UniCNS-UTF32-H',
  41943. 'UniCNS-UTF32-V',
  41944. 'UniCNS-UTF8-H',
  41945. 'UniCNS-UTF8-V',
  41946. 'UniGB-UCS2-H',
  41947. 'UniGB-UCS2-V',
  41948. 'UniGB-UTF16-H',
  41949. 'UniGB-UTF16-V',
  41950. 'UniGB-UTF32-H',
  41951. 'UniGB-UTF32-V',
  41952. 'UniGB-UTF8-H',
  41953. 'UniGB-UTF8-V',
  41954. 'UniJIS-UCS2-H',
  41955. 'UniJIS-UCS2-HW-H',
  41956. 'UniJIS-UCS2-HW-V',
  41957. 'UniJIS-UCS2-V',
  41958. 'UniJIS-UTF16-H',
  41959. 'UniJIS-UTF16-V',
  41960. 'UniJIS-UTF32-H',
  41961. 'UniJIS-UTF32-V',
  41962. 'UniJIS-UTF8-H',
  41963. 'UniJIS-UTF8-V',
  41964. 'UniJIS2004-UTF16-H',
  41965. 'UniJIS2004-UTF16-V',
  41966. 'UniJIS2004-UTF32-H',
  41967. 'UniJIS2004-UTF32-V',
  41968. 'UniJIS2004-UTF8-H',
  41969. 'UniJIS2004-UTF8-V',
  41970. 'UniJISPro-UCS2-HW-V',
  41971. 'UniJISPro-UCS2-V',
  41972. 'UniJISPro-UTF8-V',
  41973. 'UniJISX0213-UTF32-H',
  41974. 'UniJISX0213-UTF32-V',
  41975. 'UniJISX02132004-UTF32-H',
  41976. 'UniJISX02132004-UTF32-V',
  41977. 'UniKS-UCS2-H',
  41978. 'UniKS-UCS2-V',
  41979. 'UniKS-UTF16-H',
  41980. 'UniKS-UTF16-V',
  41981. 'UniKS-UTF32-H',
  41982. 'UniKS-UTF32-V',
  41983. 'UniKS-UTF8-H',
  41984. 'UniKS-UTF8-V',
  41985. 'V',
  41986. 'WP-Symbol'
  41987. ];
  41988. // CMap, not to be confused with TrueType's cmap.
  41989. var CMap = function CMapClosure() {
  41990. function CMap(builtInCMap) {
  41991. // Codespace ranges are stored as follows:
  41992. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  41993. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  41994. this.codespaceRanges = [
  41995. [],
  41996. [],
  41997. [],
  41998. []
  41999. ];
  42000. this.numCodespaceRanges = 0;
  42001. // Map entries have one of two forms.
  42002. // - cid chars are 16-bit unsigned integers, stored as integers.
  42003. // - bf chars are variable-length byte sequences, stored as strings, with
  42004. // one byte per character.
  42005. this._map = [];
  42006. this.name = '';
  42007. this.vertical = false;
  42008. this.useCMap = null;
  42009. this.builtInCMap = builtInCMap;
  42010. }
  42011. CMap.prototype = {
  42012. addCodespaceRange: function (n, low, high) {
  42013. this.codespaceRanges[n - 1].push(low, high);
  42014. this.numCodespaceRanges++;
  42015. },
  42016. mapCidRange: function (low, high, dstLow) {
  42017. while (low <= high) {
  42018. this._map[low++] = dstLow++;
  42019. }
  42020. },
  42021. mapBfRange: function (low, high, dstLow) {
  42022. var lastByte = dstLow.length - 1;
  42023. while (low <= high) {
  42024. this._map[low++] = dstLow;
  42025. // Only the last byte has to be incremented.
  42026. dstLow = dstLow.substr(0, lastByte) + String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  42027. }
  42028. },
  42029. mapBfRangeToArray: function (low, high, array) {
  42030. var i = 0, ii = array.length;
  42031. while (low <= high && i < ii) {
  42032. this._map[low] = array[i++];
  42033. ++low;
  42034. }
  42035. },
  42036. // This is used for both bf and cid chars.
  42037. mapOne: function (src, dst) {
  42038. this._map[src] = dst;
  42039. },
  42040. lookup: function (code) {
  42041. return this._map[code];
  42042. },
  42043. contains: function (code) {
  42044. return this._map[code] !== undefined;
  42045. },
  42046. forEach: function (callback) {
  42047. // Most maps have fewer than 65536 entries, and for those we use normal
  42048. // array iteration. But really sparse tables are possible -- e.g. with
  42049. // indices in the *billions*. For such tables we use for..in, which isn't
  42050. // ideal because it stringifies the indices for all present elements, but
  42051. // it does avoid iterating over every undefined entry.
  42052. var map = this._map;
  42053. var length = map.length;
  42054. var i;
  42055. if (length <= 0x10000) {
  42056. for (i = 0; i < length; i++) {
  42057. if (map[i] !== undefined) {
  42058. callback(i, map[i]);
  42059. }
  42060. }
  42061. } else {
  42062. for (i in this._map) {
  42063. callback(i, map[i]);
  42064. }
  42065. }
  42066. },
  42067. charCodeOf: function (value) {
  42068. return this._map.indexOf(value);
  42069. },
  42070. getMap: function () {
  42071. return this._map;
  42072. },
  42073. readCharCode: function (str, offset, out) {
  42074. var c = 0;
  42075. var codespaceRanges = this.codespaceRanges;
  42076. var codespaceRangesLen = this.codespaceRanges.length;
  42077. // 9.7.6.2 CMap Mapping
  42078. // The code length is at most 4.
  42079. for (var n = 0; n < codespaceRangesLen; n++) {
  42080. c = (c << 8 | str.charCodeAt(offset + n)) >>> 0;
  42081. // Check each codespace range to see if it falls within.
  42082. var codespaceRange = codespaceRanges[n];
  42083. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  42084. var low = codespaceRange[k++];
  42085. var high = codespaceRange[k++];
  42086. if (c >= low && c <= high) {
  42087. out.charcode = c;
  42088. out.length = n + 1;
  42089. return;
  42090. }
  42091. }
  42092. }
  42093. out.charcode = 0;
  42094. out.length = 1;
  42095. },
  42096. get length() {
  42097. return this._map.length;
  42098. },
  42099. get isIdentityCMap() {
  42100. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  42101. return false;
  42102. }
  42103. if (this._map.length !== 0x10000) {
  42104. return false;
  42105. }
  42106. for (var i = 0; i < 0x10000; i++) {
  42107. if (this._map[i] !== i) {
  42108. return false;
  42109. }
  42110. }
  42111. return true;
  42112. }
  42113. };
  42114. return CMap;
  42115. }();
  42116. // A special case of CMap, where the _map array implicitly has a length of
  42117. // 65536 and each element is equal to its index.
  42118. var IdentityCMap = function IdentityCMapClosure() {
  42119. function IdentityCMap(vertical, n) {
  42120. CMap.call(this);
  42121. this.vertical = vertical;
  42122. this.addCodespaceRange(n, 0, 0xffff);
  42123. }
  42124. Util.inherit(IdentityCMap, CMap, {});
  42125. IdentityCMap.prototype = {
  42126. addCodespaceRange: CMap.prototype.addCodespaceRange,
  42127. mapCidRange: function (low, high, dstLow) {
  42128. error('should not call mapCidRange');
  42129. },
  42130. mapBfRange: function (low, high, dstLow) {
  42131. error('should not call mapBfRange');
  42132. },
  42133. mapBfRangeToArray: function (low, high, array) {
  42134. error('should not call mapBfRangeToArray');
  42135. },
  42136. mapOne: function (src, dst) {
  42137. error('should not call mapCidOne');
  42138. },
  42139. lookup: function (code) {
  42140. return isInt(code) && code <= 0xffff ? code : undefined;
  42141. },
  42142. contains: function (code) {
  42143. return isInt(code) && code <= 0xffff;
  42144. },
  42145. forEach: function (callback) {
  42146. for (var i = 0; i <= 0xffff; i++) {
  42147. callback(i, i);
  42148. }
  42149. },
  42150. charCodeOf: function (value) {
  42151. return isInt(value) && value <= 0xffff ? value : -1;
  42152. },
  42153. getMap: function () {
  42154. // Sometimes identity maps must be instantiated, but it's rare.
  42155. var map = new Array(0x10000);
  42156. for (var i = 0; i <= 0xffff; i++) {
  42157. map[i] = i;
  42158. }
  42159. return map;
  42160. },
  42161. readCharCode: CMap.prototype.readCharCode,
  42162. get length() {
  42163. return 0x10000;
  42164. },
  42165. get isIdentityCMap() {
  42166. error('should not access .isIdentityCMap');
  42167. }
  42168. };
  42169. return IdentityCMap;
  42170. }();
  42171. var BinaryCMapReader = function BinaryCMapReaderClosure() {
  42172. function fetchBinaryData(url) {
  42173. return new Promise(function (resolve, reject) {
  42174. var request = new XMLHttpRequest();
  42175. request.open('GET', url, true);
  42176. request.responseType = 'arraybuffer';
  42177. request.onreadystatechange = function () {
  42178. if (request.readyState === XMLHttpRequest.DONE) {
  42179. if (!request.response || request.status !== 200 && request.status !== 0) {
  42180. reject(new Error('Unable to get binary cMap at: ' + url));
  42181. } else {
  42182. resolve(new Uint8Array(request.response));
  42183. }
  42184. }
  42185. };
  42186. request.send(null);
  42187. });
  42188. }
  42189. function hexToInt(a, size) {
  42190. var n = 0;
  42191. for (var i = 0; i <= size; i++) {
  42192. n = n << 8 | a[i];
  42193. }
  42194. return n >>> 0;
  42195. }
  42196. function hexToStr(a, size) {
  42197. // This code is hot. Special-case some common values to avoid creating an
  42198. // object with subarray().
  42199. if (size === 1) {
  42200. return String.fromCharCode(a[0], a[1]);
  42201. }
  42202. if (size === 3) {
  42203. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  42204. }
  42205. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  42206. }
  42207. function addHex(a, b, size) {
  42208. var c = 0;
  42209. for (var i = size; i >= 0; i--) {
  42210. c += a[i] + b[i];
  42211. a[i] = c & 255;
  42212. c >>= 8;
  42213. }
  42214. }
  42215. function incHex(a, size) {
  42216. var c = 1;
  42217. for (var i = size; i >= 0 && c > 0; i--) {
  42218. c += a[i];
  42219. a[i] = c & 255;
  42220. c >>= 8;
  42221. }
  42222. }
  42223. var MAX_NUM_SIZE = 16;
  42224. var MAX_ENCODED_NUM_SIZE = 19;
  42225. // ceil(MAX_NUM_SIZE * 7 / 8)
  42226. function BinaryCMapStream(data) {
  42227. this.buffer = data;
  42228. this.pos = 0;
  42229. this.end = data.length;
  42230. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  42231. }
  42232. BinaryCMapStream.prototype = {
  42233. readByte: function () {
  42234. if (this.pos >= this.end) {
  42235. return -1;
  42236. }
  42237. return this.buffer[this.pos++];
  42238. },
  42239. readNumber: function () {
  42240. var n = 0;
  42241. var last;
  42242. do {
  42243. var b = this.readByte();
  42244. if (b < 0) {
  42245. error('unexpected EOF in bcmap');
  42246. }
  42247. last = !(b & 0x80);
  42248. n = n << 7 | b & 0x7F;
  42249. } while (!last);
  42250. return n;
  42251. },
  42252. readSigned: function () {
  42253. var n = this.readNumber();
  42254. return n & 1 ? ~(n >>> 1) : n >>> 1;
  42255. },
  42256. readHex: function (num, size) {
  42257. num.set(this.buffer.subarray(this.pos, this.pos + size + 1));
  42258. this.pos += size + 1;
  42259. },
  42260. readHexNumber: function (num, size) {
  42261. var last;
  42262. var stack = this.tmpBuf, sp = 0;
  42263. do {
  42264. var b = this.readByte();
  42265. if (b < 0) {
  42266. error('unexpected EOF in bcmap');
  42267. }
  42268. last = !(b & 0x80);
  42269. stack[sp++] = b & 0x7F;
  42270. } while (!last);
  42271. var i = size, buffer = 0, bufferSize = 0;
  42272. while (i >= 0) {
  42273. while (bufferSize < 8 && stack.length > 0) {
  42274. buffer = stack[--sp] << bufferSize | buffer;
  42275. bufferSize += 7;
  42276. }
  42277. num[i] = buffer & 255;
  42278. i--;
  42279. buffer >>= 8;
  42280. bufferSize -= 8;
  42281. }
  42282. },
  42283. readHexSigned: function (num, size) {
  42284. this.readHexNumber(num, size);
  42285. var sign = num[size] & 1 ? 255 : 0;
  42286. var c = 0;
  42287. for (var i = 0; i <= size; i++) {
  42288. c = (c & 1) << 8 | num[i];
  42289. num[i] = c >> 1 ^ sign;
  42290. }
  42291. },
  42292. readString: function () {
  42293. var len = this.readNumber();
  42294. var s = '';
  42295. for (var i = 0; i < len; i++) {
  42296. s += String.fromCharCode(this.readNumber());
  42297. }
  42298. return s;
  42299. }
  42300. };
  42301. function processBinaryCMap(url, cMap, extend) {
  42302. return fetchBinaryData(url).then(function (data) {
  42303. var stream = new BinaryCMapStream(data);
  42304. var header = stream.readByte();
  42305. cMap.vertical = !!(header & 1);
  42306. var useCMap = null;
  42307. var start = new Uint8Array(MAX_NUM_SIZE);
  42308. var end = new Uint8Array(MAX_NUM_SIZE);
  42309. var char = new Uint8Array(MAX_NUM_SIZE);
  42310. var charCode = new Uint8Array(MAX_NUM_SIZE);
  42311. var tmp = new Uint8Array(MAX_NUM_SIZE);
  42312. var code;
  42313. var b;
  42314. while ((b = stream.readByte()) >= 0) {
  42315. var type = b >> 5;
  42316. if (type === 7) {
  42317. // metadata, e.g. comment or usecmap
  42318. switch (b & 0x1F) {
  42319. case 0:
  42320. stream.readString();
  42321. // skipping comment
  42322. break;
  42323. case 1:
  42324. useCMap = stream.readString();
  42325. break;
  42326. }
  42327. continue;
  42328. }
  42329. var sequence = !!(b & 0x10);
  42330. var dataSize = b & 15;
  42331. assert(dataSize + 1 <= MAX_NUM_SIZE);
  42332. var ucs2DataSize = 1;
  42333. var subitemsCount = stream.readNumber();
  42334. var i;
  42335. switch (type) {
  42336. case 0:
  42337. // codespacerange
  42338. stream.readHex(start, dataSize);
  42339. stream.readHexNumber(end, dataSize);
  42340. addHex(end, start, dataSize);
  42341. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize), hexToInt(end, dataSize));
  42342. for (i = 1; i < subitemsCount; i++) {
  42343. incHex(end, dataSize);
  42344. stream.readHexNumber(start, dataSize);
  42345. addHex(start, end, dataSize);
  42346. stream.readHexNumber(end, dataSize);
  42347. addHex(end, start, dataSize);
  42348. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize), hexToInt(end, dataSize));
  42349. }
  42350. break;
  42351. case 1:
  42352. // notdefrange
  42353. stream.readHex(start, dataSize);
  42354. stream.readHexNumber(end, dataSize);
  42355. addHex(end, start, dataSize);
  42356. code = stream.readNumber();
  42357. // undefined range, skipping
  42358. for (i = 1; i < subitemsCount; i++) {
  42359. incHex(end, dataSize);
  42360. stream.readHexNumber(start, dataSize);
  42361. addHex(start, end, dataSize);
  42362. stream.readHexNumber(end, dataSize);
  42363. addHex(end, start, dataSize);
  42364. code = stream.readNumber();
  42365. }
  42366. // nop
  42367. break;
  42368. case 2:
  42369. // cidchar
  42370. stream.readHex(char, dataSize);
  42371. code = stream.readNumber();
  42372. cMap.mapOne(hexToInt(char, dataSize), code);
  42373. for (i = 1; i < subitemsCount; i++) {
  42374. incHex(char, dataSize);
  42375. if (!sequence) {
  42376. stream.readHexNumber(tmp, dataSize);
  42377. addHex(char, tmp, dataSize);
  42378. }
  42379. code = stream.readSigned() + (code + 1);
  42380. cMap.mapOne(hexToInt(char, dataSize), code);
  42381. }
  42382. break;
  42383. case 3:
  42384. // cidrange
  42385. stream.readHex(start, dataSize);
  42386. stream.readHexNumber(end, dataSize);
  42387. addHex(end, start, dataSize);
  42388. code = stream.readNumber();
  42389. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize), code);
  42390. for (i = 1; i < subitemsCount; i++) {
  42391. incHex(end, dataSize);
  42392. if (!sequence) {
  42393. stream.readHexNumber(start, dataSize);
  42394. addHex(start, end, dataSize);
  42395. } else {
  42396. start.set(end);
  42397. }
  42398. stream.readHexNumber(end, dataSize);
  42399. addHex(end, start, dataSize);
  42400. code = stream.readNumber();
  42401. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize), code);
  42402. }
  42403. break;
  42404. case 4:
  42405. // bfchar
  42406. stream.readHex(char, ucs2DataSize);
  42407. stream.readHex(charCode, dataSize);
  42408. cMap.mapOne(hexToInt(char, ucs2DataSize), hexToStr(charCode, dataSize));
  42409. for (i = 1; i < subitemsCount; i++) {
  42410. incHex(char, ucs2DataSize);
  42411. if (!sequence) {
  42412. stream.readHexNumber(tmp, ucs2DataSize);
  42413. addHex(char, tmp, ucs2DataSize);
  42414. }
  42415. incHex(charCode, dataSize);
  42416. stream.readHexSigned(tmp, dataSize);
  42417. addHex(charCode, tmp, dataSize);
  42418. cMap.mapOne(hexToInt(char, ucs2DataSize), hexToStr(charCode, dataSize));
  42419. }
  42420. break;
  42421. case 5:
  42422. // bfrange
  42423. stream.readHex(start, ucs2DataSize);
  42424. stream.readHexNumber(end, ucs2DataSize);
  42425. addHex(end, start, ucs2DataSize);
  42426. stream.readHex(charCode, dataSize);
  42427. cMap.mapBfRange(hexToInt(start, ucs2DataSize), hexToInt(end, ucs2DataSize), hexToStr(charCode, dataSize));
  42428. for (i = 1; i < subitemsCount; i++) {
  42429. incHex(end, ucs2DataSize);
  42430. if (!sequence) {
  42431. stream.readHexNumber(start, ucs2DataSize);
  42432. addHex(start, end, ucs2DataSize);
  42433. } else {
  42434. start.set(end);
  42435. }
  42436. stream.readHexNumber(end, ucs2DataSize);
  42437. addHex(end, start, ucs2DataSize);
  42438. stream.readHex(charCode, dataSize);
  42439. cMap.mapBfRange(hexToInt(start, ucs2DataSize), hexToInt(end, ucs2DataSize), hexToStr(charCode, dataSize));
  42440. }
  42441. break;
  42442. default:
  42443. error('Unknown type: ' + type);
  42444. break;
  42445. }
  42446. }
  42447. if (useCMap) {
  42448. return extend(useCMap);
  42449. }
  42450. return cMap;
  42451. });
  42452. }
  42453. function BinaryCMapReader() {
  42454. }
  42455. BinaryCMapReader.prototype = { read: processBinaryCMap };
  42456. return BinaryCMapReader;
  42457. }();
  42458. var CMapFactory = function CMapFactoryClosure() {
  42459. function strToInt(str) {
  42460. var a = 0;
  42461. for (var i = 0; i < str.length; i++) {
  42462. a = a << 8 | str.charCodeAt(i);
  42463. }
  42464. return a >>> 0;
  42465. }
  42466. function expectString(obj) {
  42467. if (!isString(obj)) {
  42468. error('Malformed CMap: expected string.');
  42469. }
  42470. }
  42471. function expectInt(obj) {
  42472. if (!isInt(obj)) {
  42473. error('Malformed CMap: expected int.');
  42474. }
  42475. }
  42476. function parseBfChar(cMap, lexer) {
  42477. while (true) {
  42478. var obj = lexer.getObj();
  42479. if (isEOF(obj)) {
  42480. break;
  42481. }
  42482. if (isCmd(obj, 'endbfchar')) {
  42483. return;
  42484. }
  42485. expectString(obj);
  42486. var src = strToInt(obj);
  42487. obj = lexer.getObj();
  42488. // TODO are /dstName used?
  42489. expectString(obj);
  42490. var dst = obj;
  42491. cMap.mapOne(src, dst);
  42492. }
  42493. }
  42494. function parseBfRange(cMap, lexer) {
  42495. while (true) {
  42496. var obj = lexer.getObj();
  42497. if (isEOF(obj)) {
  42498. break;
  42499. }
  42500. if (isCmd(obj, 'endbfrange')) {
  42501. return;
  42502. }
  42503. expectString(obj);
  42504. var low = strToInt(obj);
  42505. obj = lexer.getObj();
  42506. expectString(obj);
  42507. var high = strToInt(obj);
  42508. obj = lexer.getObj();
  42509. if (isInt(obj) || isString(obj)) {
  42510. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  42511. cMap.mapBfRange(low, high, dstLow);
  42512. } else if (isCmd(obj, '[')) {
  42513. obj = lexer.getObj();
  42514. var array = [];
  42515. while (!isCmd(obj, ']') && !isEOF(obj)) {
  42516. array.push(obj);
  42517. obj = lexer.getObj();
  42518. }
  42519. cMap.mapBfRangeToArray(low, high, array);
  42520. } else {
  42521. break;
  42522. }
  42523. }
  42524. error('Invalid bf range.');
  42525. }
  42526. function parseCidChar(cMap, lexer) {
  42527. while (true) {
  42528. var obj = lexer.getObj();
  42529. if (isEOF(obj)) {
  42530. break;
  42531. }
  42532. if (isCmd(obj, 'endcidchar')) {
  42533. return;
  42534. }
  42535. expectString(obj);
  42536. var src = strToInt(obj);
  42537. obj = lexer.getObj();
  42538. expectInt(obj);
  42539. var dst = obj;
  42540. cMap.mapOne(src, dst);
  42541. }
  42542. }
  42543. function parseCidRange(cMap, lexer) {
  42544. while (true) {
  42545. var obj = lexer.getObj();
  42546. if (isEOF(obj)) {
  42547. break;
  42548. }
  42549. if (isCmd(obj, 'endcidrange')) {
  42550. return;
  42551. }
  42552. expectString(obj);
  42553. var low = strToInt(obj);
  42554. obj = lexer.getObj();
  42555. expectString(obj);
  42556. var high = strToInt(obj);
  42557. obj = lexer.getObj();
  42558. expectInt(obj);
  42559. var dstLow = obj;
  42560. cMap.mapCidRange(low, high, dstLow);
  42561. }
  42562. }
  42563. function parseCodespaceRange(cMap, lexer) {
  42564. while (true) {
  42565. var obj = lexer.getObj();
  42566. if (isEOF(obj)) {
  42567. break;
  42568. }
  42569. if (isCmd(obj, 'endcodespacerange')) {
  42570. return;
  42571. }
  42572. if (!isString(obj)) {
  42573. break;
  42574. }
  42575. var low = strToInt(obj);
  42576. obj = lexer.getObj();
  42577. if (!isString(obj)) {
  42578. break;
  42579. }
  42580. var high = strToInt(obj);
  42581. cMap.addCodespaceRange(obj.length, low, high);
  42582. }
  42583. error('Invalid codespace range.');
  42584. }
  42585. function parseWMode(cMap, lexer) {
  42586. var obj = lexer.getObj();
  42587. if (isInt(obj)) {
  42588. cMap.vertical = !!obj;
  42589. }
  42590. }
  42591. function parseCMapName(cMap, lexer) {
  42592. var obj = lexer.getObj();
  42593. if (isName(obj) && isString(obj.name)) {
  42594. cMap.name = obj.name;
  42595. }
  42596. }
  42597. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  42598. var previous;
  42599. var embededUseCMap;
  42600. objLoop:
  42601. while (true) {
  42602. try {
  42603. var obj = lexer.getObj();
  42604. if (isEOF(obj)) {
  42605. break;
  42606. } else if (isName(obj)) {
  42607. if (obj.name === 'WMode') {
  42608. parseWMode(cMap, lexer);
  42609. } else if (obj.name === 'CMapName') {
  42610. parseCMapName(cMap, lexer);
  42611. }
  42612. previous = obj;
  42613. } else if (isCmd(obj)) {
  42614. switch (obj.cmd) {
  42615. case 'endcmap':
  42616. break objLoop;
  42617. case 'usecmap':
  42618. if (isName(previous)) {
  42619. embededUseCMap = previous.name;
  42620. }
  42621. break;
  42622. case 'begincodespacerange':
  42623. parseCodespaceRange(cMap, lexer);
  42624. break;
  42625. case 'beginbfchar':
  42626. parseBfChar(cMap, lexer);
  42627. break;
  42628. case 'begincidchar':
  42629. parseCidChar(cMap, lexer);
  42630. break;
  42631. case 'beginbfrange':
  42632. parseBfRange(cMap, lexer);
  42633. break;
  42634. case 'begincidrange':
  42635. parseCidRange(cMap, lexer);
  42636. break;
  42637. }
  42638. }
  42639. } catch (ex) {
  42640. if (ex instanceof MissingDataException) {
  42641. throw ex;
  42642. }
  42643. warn('Invalid cMap data: ' + ex);
  42644. continue;
  42645. }
  42646. }
  42647. if (!useCMap && embededUseCMap) {
  42648. // Load the usecmap definition from the file only if there wasn't one
  42649. // specified.
  42650. useCMap = embededUseCMap;
  42651. }
  42652. if (useCMap) {
  42653. return extendCMap(cMap, builtInCMapParams, useCMap);
  42654. }
  42655. return Promise.resolve(cMap);
  42656. }
  42657. function extendCMap(cMap, builtInCMapParams, useCMap) {
  42658. return createBuiltInCMap(useCMap, builtInCMapParams).then(function (newCMap) {
  42659. cMap.useCMap = newCMap;
  42660. // If there aren't any code space ranges defined clone all the parent ones
  42661. // into this cMap.
  42662. if (cMap.numCodespaceRanges === 0) {
  42663. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  42664. for (var i = 0; i < useCodespaceRanges.length; i++) {
  42665. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  42666. }
  42667. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  42668. }
  42669. // Merge the map into the current one, making sure not to override
  42670. // any previously defined entries.
  42671. cMap.useCMap.forEach(function (key, value) {
  42672. if (!cMap.contains(key)) {
  42673. cMap.mapOne(key, cMap.useCMap.lookup(key));
  42674. }
  42675. });
  42676. return cMap;
  42677. });
  42678. }
  42679. function parseBinaryCMap(name, builtInCMapParams) {
  42680. var url = builtInCMapParams.url + name + '.bcmap';
  42681. var cMap = new CMap(true);
  42682. return new BinaryCMapReader().read(url, cMap, function (useCMap) {
  42683. return extendCMap(cMap, builtInCMapParams, useCMap);
  42684. });
  42685. }
  42686. function createBuiltInCMap(name, builtInCMapParams) {
  42687. if (name === 'Identity-H') {
  42688. return Promise.resolve(new IdentityCMap(false, 2));
  42689. } else if (name === 'Identity-V') {
  42690. return Promise.resolve(new IdentityCMap(true, 2));
  42691. }
  42692. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  42693. return Promise.reject(new Error('Unknown cMap name: ' + name));
  42694. }
  42695. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  42696. if (builtInCMapParams.packed) {
  42697. return parseBinaryCMap(name, builtInCMapParams);
  42698. }
  42699. return new Promise(function (resolve, reject) {
  42700. var url = builtInCMapParams.url + name;
  42701. var request = new XMLHttpRequest();
  42702. request.onreadystatechange = function () {
  42703. if (request.readyState === XMLHttpRequest.DONE) {
  42704. if (request.status === 200 || request.status === 0) {
  42705. var cMap = new CMap(true);
  42706. var lexer = new Lexer(new StringStream(request.responseText));
  42707. parseCMap(cMap, lexer, builtInCMapParams, null).then(function (parsedCMap) {
  42708. resolve(parsedCMap);
  42709. });
  42710. } else {
  42711. reject(new Error('Unable to get cMap at: ' + url));
  42712. }
  42713. }
  42714. };
  42715. request.open('GET', url, true);
  42716. request.send(null);
  42717. });
  42718. }
  42719. return {
  42720. create: function (encoding, builtInCMapParams, useCMap) {
  42721. if (isName(encoding)) {
  42722. return createBuiltInCMap(encoding.name, builtInCMapParams);
  42723. } else if (isStream(encoding)) {
  42724. var cMap = new CMap();
  42725. var lexer = new Lexer(encoding);
  42726. return parseCMap(cMap, lexer, builtInCMapParams, useCMap).then(function (parsedCMap) {
  42727. if (parsedCMap.isIdentityCMap) {
  42728. return createBuiltInCMap(parsedCMap.name, builtInCMapParams);
  42729. }
  42730. return parsedCMap;
  42731. });
  42732. }
  42733. return Promise.reject(new Error('Encoding required.'));
  42734. }
  42735. };
  42736. }();
  42737. exports.CMap = CMap;
  42738. exports.CMapFactory = CMapFactory;
  42739. exports.IdentityCMap = IdentityCMap;
  42740. }));
  42741. (function (root, factory) {
  42742. factory(root.pdfjsCoreFonts = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreGlyphList, root.pdfjsCoreFontRenderer, root.pdfjsCoreEncodings, root.pdfjsCoreStandardFonts, root.pdfjsCoreUnicode, root.pdfjsCoreType1Parser, root.pdfjsCoreCFFParser);
  42743. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreGlyphList, coreFontRenderer, coreEncodings, coreStandardFonts, coreUnicode, coreType1Parser, coreCFFParser) {
  42744. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  42745. var FontType = sharedUtil.FontType;
  42746. var assert = sharedUtil.assert;
  42747. var bytesToString = sharedUtil.bytesToString;
  42748. var error = sharedUtil.error;
  42749. var info = sharedUtil.info;
  42750. var isArray = sharedUtil.isArray;
  42751. var isInt = sharedUtil.isInt;
  42752. var isNum = sharedUtil.isNum;
  42753. var readUint32 = sharedUtil.readUint32;
  42754. var shadow = sharedUtil.shadow;
  42755. var string32 = sharedUtil.string32;
  42756. var warn = sharedUtil.warn;
  42757. var MissingDataException = sharedUtil.MissingDataException;
  42758. var isSpace = sharedUtil.isSpace;
  42759. var Stream = coreStream.Stream;
  42760. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  42761. var getDingbatsGlyphsUnicode = coreGlyphList.getDingbatsGlyphsUnicode;
  42762. var FontRendererFactory = coreFontRenderer.FontRendererFactory;
  42763. var StandardEncoding = coreEncodings.StandardEncoding;
  42764. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  42765. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  42766. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  42767. var getEncoding = coreEncodings.getEncoding;
  42768. var getStdFontMap = coreStandardFonts.getStdFontMap;
  42769. var getNonStdFontMap = coreStandardFonts.getNonStdFontMap;
  42770. var getGlyphMapForStandardFonts = coreStandardFonts.getGlyphMapForStandardFonts;
  42771. var getSupplementalGlyphMapForArialBlack = coreStandardFonts.getSupplementalGlyphMapForArialBlack;
  42772. var getUnicodeRangeFor = coreUnicode.getUnicodeRangeFor;
  42773. var mapSpecialUnicodeValues = coreUnicode.mapSpecialUnicodeValues;
  42774. var getUnicodeForGlyph = coreUnicode.getUnicodeForGlyph;
  42775. var Type1Parser = coreType1Parser.Type1Parser;
  42776. var CFFStandardStrings = coreCFFParser.CFFStandardStrings;
  42777. var CFFParser = coreCFFParser.CFFParser;
  42778. var CFFCompiler = coreCFFParser.CFFCompiler;
  42779. var CFF = coreCFFParser.CFF;
  42780. var CFFHeader = coreCFFParser.CFFHeader;
  42781. var CFFTopDict = coreCFFParser.CFFTopDict;
  42782. var CFFPrivateDict = coreCFFParser.CFFPrivateDict;
  42783. var CFFStrings = coreCFFParser.CFFStrings;
  42784. var CFFIndex = coreCFFParser.CFFIndex;
  42785. var CFFCharset = coreCFFParser.CFFCharset;
  42786. // Unicode Private Use Area
  42787. var PRIVATE_USE_OFFSET_START = 0xE000;
  42788. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  42789. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  42790. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  42791. // except for Type 3 fonts
  42792. var PDF_GLYPH_SPACE_UNITS = 1000;
  42793. // Accented charactars are not displayed properly on Windows, using this flag
  42794. // to control analysis of seac charstrings.
  42795. var SEAC_ANALYSIS_ENABLED = false;
  42796. var FontFlags = {
  42797. FixedPitch: 1,
  42798. Serif: 2,
  42799. Symbolic: 4,
  42800. Script: 8,
  42801. Nonsymbolic: 32,
  42802. Italic: 64,
  42803. AllCap: 65536,
  42804. SmallCap: 131072,
  42805. ForceBold: 262144
  42806. };
  42807. var MacStandardGlyphOrdering = [
  42808. '.notdef',
  42809. '.null',
  42810. 'nonmarkingreturn',
  42811. 'space',
  42812. 'exclam',
  42813. 'quotedbl',
  42814. 'numbersign',
  42815. 'dollar',
  42816. 'percent',
  42817. 'ampersand',
  42818. 'quotesingle',
  42819. 'parenleft',
  42820. 'parenright',
  42821. 'asterisk',
  42822. 'plus',
  42823. 'comma',
  42824. 'hyphen',
  42825. 'period',
  42826. 'slash',
  42827. 'zero',
  42828. 'one',
  42829. 'two',
  42830. 'three',
  42831. 'four',
  42832. 'five',
  42833. 'six',
  42834. 'seven',
  42835. 'eight',
  42836. 'nine',
  42837. 'colon',
  42838. 'semicolon',
  42839. 'less',
  42840. 'equal',
  42841. 'greater',
  42842. 'question',
  42843. 'at',
  42844. 'A',
  42845. 'B',
  42846. 'C',
  42847. 'D',
  42848. 'E',
  42849. 'F',
  42850. 'G',
  42851. 'H',
  42852. 'I',
  42853. 'J',
  42854. 'K',
  42855. 'L',
  42856. 'M',
  42857. 'N',
  42858. 'O',
  42859. 'P',
  42860. 'Q',
  42861. 'R',
  42862. 'S',
  42863. 'T',
  42864. 'U',
  42865. 'V',
  42866. 'W',
  42867. 'X',
  42868. 'Y',
  42869. 'Z',
  42870. 'bracketleft',
  42871. 'backslash',
  42872. 'bracketright',
  42873. 'asciicircum',
  42874. 'underscore',
  42875. 'grave',
  42876. 'a',
  42877. 'b',
  42878. 'c',
  42879. 'd',
  42880. 'e',
  42881. 'f',
  42882. 'g',
  42883. 'h',
  42884. 'i',
  42885. 'j',
  42886. 'k',
  42887. 'l',
  42888. 'm',
  42889. 'n',
  42890. 'o',
  42891. 'p',
  42892. 'q',
  42893. 'r',
  42894. 's',
  42895. 't',
  42896. 'u',
  42897. 'v',
  42898. 'w',
  42899. 'x',
  42900. 'y',
  42901. 'z',
  42902. 'braceleft',
  42903. 'bar',
  42904. 'braceright',
  42905. 'asciitilde',
  42906. 'Adieresis',
  42907. 'Aring',
  42908. 'Ccedilla',
  42909. 'Eacute',
  42910. 'Ntilde',
  42911. 'Odieresis',
  42912. 'Udieresis',
  42913. 'aacute',
  42914. 'agrave',
  42915. 'acircumflex',
  42916. 'adieresis',
  42917. 'atilde',
  42918. 'aring',
  42919. 'ccedilla',
  42920. 'eacute',
  42921. 'egrave',
  42922. 'ecircumflex',
  42923. 'edieresis',
  42924. 'iacute',
  42925. 'igrave',
  42926. 'icircumflex',
  42927. 'idieresis',
  42928. 'ntilde',
  42929. 'oacute',
  42930. 'ograve',
  42931. 'ocircumflex',
  42932. 'odieresis',
  42933. 'otilde',
  42934. 'uacute',
  42935. 'ugrave',
  42936. 'ucircumflex',
  42937. 'udieresis',
  42938. 'dagger',
  42939. 'degree',
  42940. 'cent',
  42941. 'sterling',
  42942. 'section',
  42943. 'bullet',
  42944. 'paragraph',
  42945. 'germandbls',
  42946. 'registered',
  42947. 'copyright',
  42948. 'trademark',
  42949. 'acute',
  42950. 'dieresis',
  42951. 'notequal',
  42952. 'AE',
  42953. 'Oslash',
  42954. 'infinity',
  42955. 'plusminus',
  42956. 'lessequal',
  42957. 'greaterequal',
  42958. 'yen',
  42959. 'mu',
  42960. 'partialdiff',
  42961. 'summation',
  42962. 'product',
  42963. 'pi',
  42964. 'integral',
  42965. 'ordfeminine',
  42966. 'ordmasculine',
  42967. 'Omega',
  42968. 'ae',
  42969. 'oslash',
  42970. 'questiondown',
  42971. 'exclamdown',
  42972. 'logicalnot',
  42973. 'radical',
  42974. 'florin',
  42975. 'approxequal',
  42976. 'Delta',
  42977. 'guillemotleft',
  42978. 'guillemotright',
  42979. 'ellipsis',
  42980. 'nonbreakingspace',
  42981. 'Agrave',
  42982. 'Atilde',
  42983. 'Otilde',
  42984. 'OE',
  42985. 'oe',
  42986. 'endash',
  42987. 'emdash',
  42988. 'quotedblleft',
  42989. 'quotedblright',
  42990. 'quoteleft',
  42991. 'quoteright',
  42992. 'divide',
  42993. 'lozenge',
  42994. 'ydieresis',
  42995. 'Ydieresis',
  42996. 'fraction',
  42997. 'currency',
  42998. 'guilsinglleft',
  42999. 'guilsinglright',
  43000. 'fi',
  43001. 'fl',
  43002. 'daggerdbl',
  43003. 'periodcentered',
  43004. 'quotesinglbase',
  43005. 'quotedblbase',
  43006. 'perthousand',
  43007. 'Acircumflex',
  43008. 'Ecircumflex',
  43009. 'Aacute',
  43010. 'Edieresis',
  43011. 'Egrave',
  43012. 'Iacute',
  43013. 'Icircumflex',
  43014. 'Idieresis',
  43015. 'Igrave',
  43016. 'Oacute',
  43017. 'Ocircumflex',
  43018. 'apple',
  43019. 'Ograve',
  43020. 'Uacute',
  43021. 'Ucircumflex',
  43022. 'Ugrave',
  43023. 'dotlessi',
  43024. 'circumflex',
  43025. 'tilde',
  43026. 'macron',
  43027. 'breve',
  43028. 'dotaccent',
  43029. 'ring',
  43030. 'cedilla',
  43031. 'hungarumlaut',
  43032. 'ogonek',
  43033. 'caron',
  43034. 'Lslash',
  43035. 'lslash',
  43036. 'Scaron',
  43037. 'scaron',
  43038. 'Zcaron',
  43039. 'zcaron',
  43040. 'brokenbar',
  43041. 'Eth',
  43042. 'eth',
  43043. 'Yacute',
  43044. 'yacute',
  43045. 'Thorn',
  43046. 'thorn',
  43047. 'minus',
  43048. 'multiply',
  43049. 'onesuperior',
  43050. 'twosuperior',
  43051. 'threesuperior',
  43052. 'onehalf',
  43053. 'onequarter',
  43054. 'threequarters',
  43055. 'franc',
  43056. 'Gbreve',
  43057. 'gbreve',
  43058. 'Idotaccent',
  43059. 'Scedilla',
  43060. 'scedilla',
  43061. 'Cacute',
  43062. 'cacute',
  43063. 'Ccaron',
  43064. 'ccaron',
  43065. 'dcroat'
  43066. ];
  43067. function adjustWidths(properties) {
  43068. if (!properties.fontMatrix) {
  43069. return;
  43070. }
  43071. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  43072. return;
  43073. }
  43074. // adjusting width to fontMatrix scale
  43075. var scale = 0.001 / properties.fontMatrix[0];
  43076. var glyphsWidths = properties.widths;
  43077. for (var glyph in glyphsWidths) {
  43078. glyphsWidths[glyph] *= scale;
  43079. }
  43080. properties.defaultWidth *= scale;
  43081. }
  43082. function adjustToUnicode(properties, builtInEncoding) {
  43083. if (properties.hasIncludedToUnicodeMap) {
  43084. return;
  43085. }
  43086. // The font dictionary has a `ToUnicode` entry.
  43087. if (properties.hasEncoding) {
  43088. return;
  43089. }
  43090. // The font dictionary has an `Encoding` entry.
  43091. if (builtInEncoding === properties.defaultEncoding) {
  43092. return;
  43093. }
  43094. // No point in trying to adjust `toUnicode` if the encodings match.
  43095. if (properties.toUnicode instanceof IdentityToUnicodeMap) {
  43096. return;
  43097. }
  43098. var toUnicode = [], glyphsUnicodeMap = getGlyphsUnicode();
  43099. for (var charCode in builtInEncoding) {
  43100. var glyphName = builtInEncoding[charCode];
  43101. var unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  43102. if (unicode !== -1) {
  43103. toUnicode[charCode] = String.fromCharCode(unicode);
  43104. }
  43105. }
  43106. properties.toUnicode.amend(toUnicode);
  43107. }
  43108. function getFontType(type, subtype) {
  43109. switch (type) {
  43110. case 'Type1':
  43111. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  43112. case 'CIDFontType0':
  43113. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C : FontType.CIDFONTTYPE0;
  43114. case 'OpenType':
  43115. return FontType.OPENTYPE;
  43116. case 'TrueType':
  43117. return FontType.TRUETYPE;
  43118. case 'CIDFontType2':
  43119. return FontType.CIDFONTTYPE2;
  43120. case 'MMType1':
  43121. return FontType.MMTYPE1;
  43122. case 'Type0':
  43123. return FontType.TYPE0;
  43124. default:
  43125. return FontType.UNKNOWN;
  43126. }
  43127. }
  43128. // Some bad PDF generators, e.g. Scribus PDF, include glyph names
  43129. // in a 'uniXXXX' format -- attempting to recover proper ones.
  43130. function recoverGlyphName(name, glyphsUnicodeMap) {
  43131. if (glyphsUnicodeMap[name] !== undefined) {
  43132. return name;
  43133. }
  43134. // The glyph name is non-standard, trying to recover.
  43135. var unicode = getUnicodeForGlyph(name, glyphsUnicodeMap);
  43136. if (unicode !== -1) {
  43137. for (var key in glyphsUnicodeMap) {
  43138. if (glyphsUnicodeMap[key] === unicode) {
  43139. return key;
  43140. }
  43141. }
  43142. }
  43143. info('Unable to recover a standard glyph name for: ' + name);
  43144. return name;
  43145. }
  43146. var Glyph = function GlyphClosure() {
  43147. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont) {
  43148. this.fontChar = fontChar;
  43149. this.unicode = unicode;
  43150. this.accent = accent;
  43151. this.width = width;
  43152. this.vmetric = vmetric;
  43153. this.operatorListId = operatorListId;
  43154. this.isSpace = isSpace;
  43155. this.isInFont = isInFont;
  43156. }
  43157. Glyph.prototype.matchesForCache = function (fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont) {
  43158. return this.fontChar === fontChar && this.unicode === unicode && this.accent === accent && this.width === width && this.vmetric === vmetric && this.operatorListId === operatorListId && this.isSpace === isSpace && this.isInFont === isInFont;
  43159. };
  43160. return Glyph;
  43161. }();
  43162. var ToUnicodeMap = function ToUnicodeMapClosure() {
  43163. function ToUnicodeMap(cmap) {
  43164. // The elements of this._map can be integers or strings, depending on how
  43165. // |cmap| was created.
  43166. this._map = cmap;
  43167. }
  43168. ToUnicodeMap.prototype = {
  43169. get length() {
  43170. return this._map.length;
  43171. },
  43172. forEach: function (callback) {
  43173. for (var charCode in this._map) {
  43174. callback(charCode, this._map[charCode].charCodeAt(0));
  43175. }
  43176. },
  43177. has: function (i) {
  43178. return this._map[i] !== undefined;
  43179. },
  43180. get: function (i) {
  43181. return this._map[i];
  43182. },
  43183. charCodeOf: function (v) {
  43184. return this._map.indexOf(v);
  43185. },
  43186. amend: function (map) {
  43187. for (var charCode in map) {
  43188. this._map[charCode] = map[charCode];
  43189. }
  43190. }
  43191. };
  43192. return ToUnicodeMap;
  43193. }();
  43194. var IdentityToUnicodeMap = function IdentityToUnicodeMapClosure() {
  43195. function IdentityToUnicodeMap(firstChar, lastChar) {
  43196. this.firstChar = firstChar;
  43197. this.lastChar = lastChar;
  43198. }
  43199. IdentityToUnicodeMap.prototype = {
  43200. get length() {
  43201. return this.lastChar + 1 - this.firstChar;
  43202. },
  43203. forEach: function (callback) {
  43204. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  43205. callback(i, i);
  43206. }
  43207. },
  43208. has: function (i) {
  43209. return this.firstChar <= i && i <= this.lastChar;
  43210. },
  43211. get: function (i) {
  43212. if (this.firstChar <= i && i <= this.lastChar) {
  43213. return String.fromCharCode(i);
  43214. }
  43215. return undefined;
  43216. },
  43217. charCodeOf: function (v) {
  43218. return isInt(v) && v >= this.firstChar && v <= this.lastChar ? v : -1;
  43219. },
  43220. amend: function (map) {
  43221. error('Should not call amend()');
  43222. }
  43223. };
  43224. return IdentityToUnicodeMap;
  43225. }();
  43226. var OpenTypeFileBuilder = function OpenTypeFileBuilderClosure() {
  43227. function writeInt16(dest, offset, num) {
  43228. dest[offset] = num >> 8 & 0xFF;
  43229. dest[offset + 1] = num & 0xFF;
  43230. }
  43231. function writeInt32(dest, offset, num) {
  43232. dest[offset] = num >> 24 & 0xFF;
  43233. dest[offset + 1] = num >> 16 & 0xFF;
  43234. dest[offset + 2] = num >> 8 & 0xFF;
  43235. dest[offset + 3] = num & 0xFF;
  43236. }
  43237. function writeData(dest, offset, data) {
  43238. var i, ii;
  43239. if (data instanceof Uint8Array) {
  43240. dest.set(data, offset);
  43241. } else if (typeof data === 'string') {
  43242. for (i = 0, ii = data.length; i < ii; i++) {
  43243. dest[offset++] = data.charCodeAt(i) & 0xFF;
  43244. }
  43245. } else {
  43246. // treating everything else as array
  43247. for (i = 0, ii = data.length; i < ii; i++) {
  43248. dest[offset++] = data[i] & 0xFF;
  43249. }
  43250. }
  43251. }
  43252. function OpenTypeFileBuilder(sfnt) {
  43253. this.sfnt = sfnt;
  43254. this.tables = Object.create(null);
  43255. }
  43256. OpenTypeFileBuilder.getSearchParams = function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  43257. var maxPower2 = 1, log2 = 0;
  43258. while ((maxPower2 ^ entriesCount) > maxPower2) {
  43259. maxPower2 <<= 1;
  43260. log2++;
  43261. }
  43262. var searchRange = maxPower2 * entrySize;
  43263. return {
  43264. range: searchRange,
  43265. entry: log2,
  43266. rangeShift: entrySize * entriesCount - searchRange
  43267. };
  43268. };
  43269. var OTF_HEADER_SIZE = 12;
  43270. var OTF_TABLE_ENTRY_SIZE = 16;
  43271. OpenTypeFileBuilder.prototype = {
  43272. toArray: function OpenTypeFileBuilder_toArray() {
  43273. var sfnt = this.sfnt;
  43274. // Tables needs to be written by ascendant alphabetic order
  43275. var tables = this.tables;
  43276. var tablesNames = Object.keys(tables);
  43277. tablesNames.sort();
  43278. var numTables = tablesNames.length;
  43279. var i, j, jj, table, tableName;
  43280. // layout the tables data
  43281. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  43282. var tableOffsets = [offset];
  43283. for (i = 0; i < numTables; i++) {
  43284. table = tables[tablesNames[i]];
  43285. var paddedLength = (table.length + 3 & ~3) >>> 0;
  43286. offset += paddedLength;
  43287. tableOffsets.push(offset);
  43288. }
  43289. var file = new Uint8Array(offset);
  43290. // write the table data first (mostly for checksum)
  43291. for (i = 0; i < numTables; i++) {
  43292. table = tables[tablesNames[i]];
  43293. writeData(file, tableOffsets[i], table);
  43294. }
  43295. // sfnt version (4 bytes)
  43296. if (sfnt === 'true') {
  43297. // Windows hates the Mac TrueType sfnt version number
  43298. sfnt = string32(0x00010000);
  43299. }
  43300. file[0] = sfnt.charCodeAt(0) & 0xFF;
  43301. file[1] = sfnt.charCodeAt(1) & 0xFF;
  43302. file[2] = sfnt.charCodeAt(2) & 0xFF;
  43303. file[3] = sfnt.charCodeAt(3) & 0xFF;
  43304. // numTables (2 bytes)
  43305. writeInt16(file, 4, numTables);
  43306. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  43307. // searchRange (2 bytes)
  43308. writeInt16(file, 6, searchParams.range);
  43309. // entrySelector (2 bytes)
  43310. writeInt16(file, 8, searchParams.entry);
  43311. // rangeShift (2 bytes)
  43312. writeInt16(file, 10, searchParams.rangeShift);
  43313. offset = OTF_HEADER_SIZE;
  43314. // writing table entries
  43315. for (i = 0; i < numTables; i++) {
  43316. tableName = tablesNames[i];
  43317. file[offset] = tableName.charCodeAt(0) & 0xFF;
  43318. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  43319. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  43320. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  43321. // checksum
  43322. var checksum = 0;
  43323. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  43324. var quad = readUint32(file, j);
  43325. checksum = checksum + quad >>> 0;
  43326. }
  43327. writeInt32(file, offset + 4, checksum);
  43328. // offset
  43329. writeInt32(file, offset + 8, tableOffsets[i]);
  43330. // length
  43331. writeInt32(file, offset + 12, tables[tableName].length);
  43332. offset += OTF_TABLE_ENTRY_SIZE;
  43333. }
  43334. return file;
  43335. },
  43336. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  43337. if (tag in this.tables) {
  43338. throw new Error('Table ' + tag + ' already exists');
  43339. }
  43340. this.tables[tag] = data;
  43341. }
  43342. };
  43343. return OpenTypeFileBuilder;
  43344. }();
  43345. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  43346. // issues when they are painted on the canvas, e.g. complex-script shaping or
  43347. // control/whitespace characters. The ranges are listed in pairs: the first item
  43348. // is a code of the first problematic code, the second one is the next
  43349. // non-problematic code. The ranges must be in sorted order.
  43350. var ProblematicCharRanges = new Int32Array([
  43351. // Control characters.
  43352. 0x0000,
  43353. 0x0020,
  43354. 0x007F,
  43355. 0x00A1,
  43356. 0x00AD,
  43357. 0x00AE,
  43358. // Chars that is used in complex-script shaping.
  43359. 0x0600,
  43360. 0x0780,
  43361. 0x08A0,
  43362. 0x10A0,
  43363. 0x1780,
  43364. 0x1800,
  43365. 0x1C00,
  43366. 0x1C50,
  43367. // General punctuation chars.
  43368. 0x2000,
  43369. 0x2010,
  43370. 0x2011,
  43371. 0x2012,
  43372. 0x2028,
  43373. 0x2030,
  43374. 0x205F,
  43375. 0x2070,
  43376. 0x25CC,
  43377. 0x25CD,
  43378. 0x3000,
  43379. 0x3001,
  43380. // Chars that is used in complex-script shaping.
  43381. 0xAA60,
  43382. 0xAA80,
  43383. // Specials Unicode block.
  43384. 0xFFF0,
  43385. 0x10000
  43386. ]);
  43387. /**
  43388. * 'Font' is the class the outside world should use, it encapsulate all the font
  43389. * decoding logics whatever type it is (assuming the font type is supported).
  43390. *
  43391. * For example to read a Type1 font and to attach it to the document:
  43392. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  43393. * type1Font.bind();
  43394. */
  43395. var Font = function FontClosure() {
  43396. function Font(name, file, properties) {
  43397. var charCode, glyphName, unicode;
  43398. this.name = name;
  43399. this.loadedName = properties.loadedName;
  43400. this.isType3Font = properties.isType3Font;
  43401. this.sizes = [];
  43402. this.missingFile = false;
  43403. this.glyphCache = Object.create(null);
  43404. var names = name.split('+');
  43405. names = names.length > 1 ? names[1] : names[0];
  43406. names = names.split(/[-,_]/g)[0];
  43407. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  43408. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  43409. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  43410. var type = properties.type;
  43411. var subtype = properties.subtype;
  43412. this.type = type;
  43413. this.fallbackName = this.isMonospace ? 'monospace' : this.isSerifFont ? 'serif' : 'sans-serif';
  43414. this.differences = properties.differences;
  43415. this.widths = properties.widths;
  43416. this.defaultWidth = properties.defaultWidth;
  43417. this.composite = properties.composite;
  43418. this.wideChars = properties.wideChars;
  43419. this.cMap = properties.cMap;
  43420. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  43421. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  43422. this.fontMatrix = properties.fontMatrix;
  43423. this.bbox = properties.bbox;
  43424. this.toUnicode = properties.toUnicode;
  43425. this.toFontChar = [];
  43426. if (properties.type === 'Type3') {
  43427. for (charCode = 0; charCode < 256; charCode++) {
  43428. this.toFontChar[charCode] = this.differences[charCode] || properties.defaultEncoding[charCode];
  43429. }
  43430. this.fontType = FontType.TYPE3;
  43431. return;
  43432. }
  43433. this.cidEncoding = properties.cidEncoding;
  43434. this.vertical = properties.vertical;
  43435. if (this.vertical) {
  43436. this.vmetrics = properties.vmetrics;
  43437. this.defaultVMetrics = properties.defaultVMetrics;
  43438. }
  43439. var glyphsUnicodeMap;
  43440. if (!file || file.isEmpty) {
  43441. if (file) {
  43442. // Some bad PDF generators will include empty font files,
  43443. // attempting to recover by assuming that no file exists.
  43444. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  43445. }
  43446. this.missingFile = true;
  43447. // The file data is not specified. Trying to fix the font name
  43448. // to be used with the canvas.font.
  43449. var fontName = name.replace(/[,_]/g, '-');
  43450. var stdFontMap = getStdFontMap(), nonStdFontMap = getNonStdFontMap();
  43451. var isStandardFont = !!stdFontMap[fontName] || !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  43452. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  43453. this.bold = fontName.search(/bold/gi) !== -1;
  43454. this.italic = fontName.search(/oblique/gi) !== -1 || fontName.search(/italic/gi) !== -1;
  43455. // Use 'name' instead of 'fontName' here because the original
  43456. // name ArialBlack for example will be replaced by Helvetica.
  43457. this.black = name.search(/Black/g) !== -1;
  43458. // if at least one width is present, remeasure all chars when exists
  43459. this.remeasure = Object.keys(this.widths).length > 0;
  43460. if (isStandardFont && type === 'CIDFontType2' && properties.cidEncoding.indexOf('Identity-') === 0) {
  43461. var GlyphMapForStandardFonts = getGlyphMapForStandardFonts();
  43462. // Standard fonts might be embedded as CID font without glyph mapping.
  43463. // Building one based on GlyphMapForStandardFonts.
  43464. var map = [];
  43465. for (charCode in GlyphMapForStandardFonts) {
  43466. map[+charCode] = GlyphMapForStandardFonts[charCode];
  43467. }
  43468. if (/ArialBlack/i.test(name)) {
  43469. var SupplementalGlyphMapForArialBlack = getSupplementalGlyphMapForArialBlack();
  43470. for (charCode in SupplementalGlyphMapForArialBlack) {
  43471. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  43472. }
  43473. }
  43474. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  43475. if (!isIdentityUnicode) {
  43476. this.toUnicode.forEach(function (charCode, unicodeCharCode) {
  43477. map[+charCode] = unicodeCharCode;
  43478. });
  43479. }
  43480. this.toFontChar = map;
  43481. this.toUnicode = new ToUnicodeMap(map);
  43482. } else if (/Symbol/i.test(fontName)) {
  43483. this.toFontChar = buildToFontChar(SymbolSetEncoding, getGlyphsUnicode(), properties.differences);
  43484. } else if (/Dingbats/i.test(fontName)) {
  43485. if (/Wingdings/i.test(name)) {
  43486. warn('Non-embedded Wingdings font, falling back to ZapfDingbats.');
  43487. }
  43488. this.toFontChar = buildToFontChar(ZapfDingbatsEncoding, getDingbatsGlyphsUnicode(), properties.differences);
  43489. } else if (isStandardFont) {
  43490. this.toFontChar = buildToFontChar(properties.defaultEncoding, getGlyphsUnicode(), properties.differences);
  43491. } else {
  43492. glyphsUnicodeMap = getGlyphsUnicode();
  43493. this.toUnicode.forEach(function (charCode, unicodeCharCode) {
  43494. if (!this.composite) {
  43495. glyphName = properties.differences[charCode] || properties.defaultEncoding[charCode];
  43496. unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  43497. if (unicode !== -1) {
  43498. unicodeCharCode = unicode;
  43499. }
  43500. }
  43501. this.toFontChar[charCode] = unicodeCharCode;
  43502. }.bind(this));
  43503. }
  43504. this.loadedName = fontName.split('-')[0];
  43505. this.loading = false;
  43506. this.fontType = getFontType(type, subtype);
  43507. return;
  43508. }
  43509. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  43510. if (subtype === 'Type1C') {
  43511. if (type !== 'Type1' && type !== 'MMType1') {
  43512. // Some TrueType fonts by mistake claim Type1C
  43513. if (isTrueTypeFile(file)) {
  43514. subtype = 'TrueType';
  43515. } else {
  43516. type = 'Type1';
  43517. }
  43518. } else if (isOpenTypeFile(file)) {
  43519. // Sometimes the type/subtype can be a complete lie (see issue7598.pdf).
  43520. type = subtype = 'OpenType';
  43521. }
  43522. }
  43523. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  43524. type = 'CIDFontType0';
  43525. }
  43526. if (subtype === 'OpenType') {
  43527. type = 'OpenType';
  43528. }
  43529. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  43530. if (type === 'CIDFontType0') {
  43531. if (isType1File(file)) {
  43532. subtype = 'CIDFontType0';
  43533. } else if (isOpenTypeFile(file)) {
  43534. // Sometimes the type/subtype can be a complete lie (see issue6782.pdf).
  43535. type = subtype = 'OpenType';
  43536. } else {
  43537. subtype = 'CIDFontType0C';
  43538. }
  43539. }
  43540. var data;
  43541. switch (type) {
  43542. case 'MMType1':
  43543. info('MMType1 font (' + name + '), falling back to Type1.');
  43544. case 'Type1':
  43545. case 'CIDFontType0':
  43546. this.mimetype = 'font/opentype';
  43547. var cff = subtype === 'Type1C' || subtype === 'CIDFontType0C' ? new CFFFont(file, properties) : new Type1Font(name, file, properties);
  43548. adjustWidths(properties);
  43549. // Wrap the CFF data inside an OTF font file
  43550. data = this.convert(name, cff, properties);
  43551. break;
  43552. case 'OpenType':
  43553. case 'TrueType':
  43554. case 'CIDFontType2':
  43555. this.mimetype = 'font/opentype';
  43556. // Repair the TrueType file. It is can be damaged in the point of
  43557. // view of the sanitizer
  43558. data = this.checkAndRepair(name, file, properties);
  43559. if (this.isOpenType) {
  43560. adjustWidths(properties);
  43561. type = 'OpenType';
  43562. }
  43563. break;
  43564. default:
  43565. error('Font ' + type + ' is not supported');
  43566. break;
  43567. }
  43568. this.data = data;
  43569. this.fontType = getFontType(type, subtype);
  43570. // Transfer some properties again that could change during font conversion
  43571. this.fontMatrix = properties.fontMatrix;
  43572. this.widths = properties.widths;
  43573. this.defaultWidth = properties.defaultWidth;
  43574. this.toUnicode = properties.toUnicode;
  43575. this.encoding = properties.baseEncoding;
  43576. this.seacMap = properties.seacMap;
  43577. this.loading = true;
  43578. }
  43579. Font.getFontID = function () {
  43580. var ID = 1;
  43581. return function Font_getFontID() {
  43582. return String(ID++);
  43583. };
  43584. }();
  43585. function int16(b0, b1) {
  43586. return (b0 << 8) + b1;
  43587. }
  43588. function signedInt16(b0, b1) {
  43589. var value = (b0 << 8) + b1;
  43590. return value & 1 << 15 ? value - 0x10000 : value;
  43591. }
  43592. function int32(b0, b1, b2, b3) {
  43593. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  43594. }
  43595. function string16(value) {
  43596. return String.fromCharCode(value >> 8 & 0xff, value & 0xff);
  43597. }
  43598. function safeString16(value) {
  43599. // clamp value to the 16-bit int range
  43600. value = value > 0x7FFF ? 0x7FFF : value < -0x8000 ? -0x8000 : value;
  43601. return String.fromCharCode(value >> 8 & 0xff, value & 0xff);
  43602. }
  43603. function isTrueTypeFile(file) {
  43604. var header = file.peekBytes(4);
  43605. return readUint32(header, 0) === 0x00010000;
  43606. }
  43607. function isOpenTypeFile(file) {
  43608. var header = file.peekBytes(4);
  43609. return bytesToString(header) === 'OTTO';
  43610. }
  43611. function isType1File(file) {
  43612. var header = file.peekBytes(2);
  43613. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  43614. if (header[0] === 0x25 && header[1] === 0x21) {
  43615. return true;
  43616. }
  43617. // ... obviously some fonts violate that part of the specification,
  43618. // please refer to the comment in |Type1Font| below.
  43619. if (header[0] === 0x80 && header[1] === 0x01) {
  43620. // pfb file header.
  43621. return true;
  43622. }
  43623. return false;
  43624. }
  43625. function buildToFontChar(encoding, glyphsUnicodeMap, differences) {
  43626. var toFontChar = [], unicode;
  43627. for (var i = 0, ii = encoding.length; i < ii; i++) {
  43628. unicode = getUnicodeForGlyph(encoding[i], glyphsUnicodeMap);
  43629. if (unicode !== -1) {
  43630. toFontChar[i] = unicode;
  43631. }
  43632. }
  43633. for (var charCode in differences) {
  43634. unicode = getUnicodeForGlyph(differences[charCode], glyphsUnicodeMap);
  43635. if (unicode !== -1) {
  43636. toFontChar[+charCode] = unicode;
  43637. }
  43638. }
  43639. return toFontChar;
  43640. }
  43641. /**
  43642. * Helper function for |adjustMapping|.
  43643. * @return {boolean}
  43644. */
  43645. function isProblematicUnicodeLocation(code) {
  43646. // Using binary search to find a range start.
  43647. var i = 0, j = ProblematicCharRanges.length - 1;
  43648. while (i < j) {
  43649. var c = i + j + 1 >> 1;
  43650. if (code < ProblematicCharRanges[c]) {
  43651. j = c - 1;
  43652. } else {
  43653. i = c;
  43654. }
  43655. }
  43656. // Even index means code in problematic range.
  43657. return !(i & 1);
  43658. }
  43659. /**
  43660. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  43661. * with their unicode value. It also moves char codes that are in known
  43662. * problematic locations.
  43663. * @return {Object} Two properties:
  43664. * 'toFontChar' - maps original char codes(the value that will be read
  43665. * from commands such as show text) to the char codes that will be used in the
  43666. * font that we build
  43667. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  43668. */
  43669. function adjustMapping(charCodeToGlyphId, properties) {
  43670. var toUnicode = properties.toUnicode;
  43671. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  43672. var isIdentityUnicode = properties.toUnicode instanceof IdentityToUnicodeMap;
  43673. var newMap = Object.create(null);
  43674. var toFontChar = [];
  43675. var usedFontCharCodes = [];
  43676. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  43677. for (var originalCharCode in charCodeToGlyphId) {
  43678. originalCharCode |= 0;
  43679. var glyphId = charCodeToGlyphId[originalCharCode];
  43680. var fontCharCode = originalCharCode;
  43681. // First try to map the value to a unicode position if a non identity map
  43682. // was created.
  43683. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  43684. var unicode = toUnicode.get(fontCharCode);
  43685. // TODO: Try to map ligatures to the correct spot.
  43686. if (unicode.length === 1) {
  43687. fontCharCode = unicode.charCodeAt(0);
  43688. }
  43689. }
  43690. // Try to move control characters, special characters and already mapped
  43691. // characters to the private use area since they will not be drawn by
  43692. // canvas if left in their current position. Also, move characters if the
  43693. // font was symbolic and there is only an identity unicode map since the
  43694. // characters probably aren't in the correct position (fixes an issue
  43695. // with firefox and thuluthfont).
  43696. if ((usedFontCharCodes[fontCharCode] !== undefined || isProblematicUnicodeLocation(fontCharCode) || isSymbolic && isIdentityUnicode) && nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) {
  43697. // Room left.
  43698. // Loop to try and find a free spot in the private use area.
  43699. do {
  43700. fontCharCode = nextAvailableFontCharCode++;
  43701. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  43702. fontCharCode = 0xF020;
  43703. nextAvailableFontCharCode = fontCharCode + 1;
  43704. }
  43705. } while (usedFontCharCodes[fontCharCode] !== undefined && nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  43706. }
  43707. newMap[fontCharCode] = glyphId;
  43708. toFontChar[originalCharCode] = fontCharCode;
  43709. usedFontCharCodes[fontCharCode] = true;
  43710. }
  43711. return {
  43712. toFontChar: toFontChar,
  43713. charCodeToGlyphId: newMap,
  43714. nextAvailableFontCharCode: nextAvailableFontCharCode
  43715. };
  43716. }
  43717. function getRanges(glyphs, numGlyphs) {
  43718. // Array.sort() sorts by characters, not numerically, so convert to an
  43719. // array of characters.
  43720. var codes = [];
  43721. for (var charCode in glyphs) {
  43722. // Remove an invalid glyph ID mappings to make OTS happy.
  43723. if (glyphs[charCode] >= numGlyphs) {
  43724. continue;
  43725. }
  43726. codes.push({
  43727. fontCharCode: charCode | 0,
  43728. glyphId: glyphs[charCode]
  43729. });
  43730. }
  43731. codes.sort(function fontGetRangesSort(a, b) {
  43732. return a.fontCharCode - b.fontCharCode;
  43733. });
  43734. // Split the sorted codes into ranges.
  43735. var ranges = [];
  43736. var length = codes.length;
  43737. for (var n = 0; n < length;) {
  43738. var start = codes[n].fontCharCode;
  43739. var codeIndices = [codes[n].glyphId];
  43740. ++n;
  43741. var end = start;
  43742. while (n < length && end + 1 === codes[n].fontCharCode) {
  43743. codeIndices.push(codes[n].glyphId);
  43744. ++end;
  43745. ++n;
  43746. if (end === 0xFFFF) {
  43747. break;
  43748. }
  43749. }
  43750. ranges.push([
  43751. start,
  43752. end,
  43753. codeIndices
  43754. ]);
  43755. }
  43756. return ranges;
  43757. }
  43758. function createCmapTable(glyphs, numGlyphs) {
  43759. var ranges = getRanges(glyphs, numGlyphs);
  43760. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  43761. var cmap = '\x00\x00' + // version
  43762. string16(numTables) + // numTables
  43763. '\x00\x03' + // platformID
  43764. '\x00\x01' + // encodingID
  43765. string32(4 + numTables * 8);
  43766. // start of the table record
  43767. var i, ii, j, jj;
  43768. for (i = ranges.length - 1; i >= 0; --i) {
  43769. if (ranges[i][0] <= 0xFFFF) {
  43770. break;
  43771. }
  43772. }
  43773. var bmpLength = i + 1;
  43774. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  43775. ranges[i][1] = 0xFFFE;
  43776. }
  43777. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  43778. var segCount = bmpLength + trailingRangesCount;
  43779. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  43780. // Fill up the 4 parallel arrays describing the segments.
  43781. var startCount = '';
  43782. var endCount = '';
  43783. var idDeltas = '';
  43784. var idRangeOffsets = '';
  43785. var glyphsIds = '';
  43786. var bias = 0;
  43787. var range, start, end, codes;
  43788. for (i = 0, ii = bmpLength; i < ii; i++) {
  43789. range = ranges[i];
  43790. start = range[0];
  43791. end = range[1];
  43792. startCount += string16(start);
  43793. endCount += string16(end);
  43794. codes = range[2];
  43795. var contiguous = true;
  43796. for (j = 1, jj = codes.length; j < jj; ++j) {
  43797. if (codes[j] !== codes[j - 1] + 1) {
  43798. contiguous = false;
  43799. break;
  43800. }
  43801. }
  43802. if (!contiguous) {
  43803. var offset = (segCount - i) * 2 + bias * 2;
  43804. bias += end - start + 1;
  43805. idDeltas += string16(0);
  43806. idRangeOffsets += string16(offset);
  43807. for (j = 0, jj = codes.length; j < jj; ++j) {
  43808. glyphsIds += string16(codes[j]);
  43809. }
  43810. } else {
  43811. var startCode = codes[0];
  43812. idDeltas += string16(startCode - start & 0xFFFF);
  43813. idRangeOffsets += string16(0);
  43814. }
  43815. }
  43816. if (trailingRangesCount > 0) {
  43817. endCount += '\xFF\xFF';
  43818. startCount += '\xFF\xFF';
  43819. idDeltas += '\x00\x01';
  43820. idRangeOffsets += '\x00\x00';
  43821. }
  43822. var format314 = '\x00\x00' + // language
  43823. string16(2 * segCount) + string16(searchParams.range) + string16(searchParams.entry) + string16(searchParams.rangeShift) + endCount + '\x00\x00' + startCount + idDeltas + idRangeOffsets + glyphsIds;
  43824. var format31012 = '';
  43825. var header31012 = '';
  43826. if (numTables > 1) {
  43827. cmap += '\x00\x03' + // platformID
  43828. '\x00\x0A' + // encodingID
  43829. string32(4 + numTables * 8 + 4 + format314.length);
  43830. // start of the table record
  43831. format31012 = '';
  43832. for (i = 0, ii = ranges.length; i < ii; i++) {
  43833. range = ranges[i];
  43834. start = range[0];
  43835. codes = range[2];
  43836. var code = codes[0];
  43837. for (j = 1, jj = codes.length; j < jj; ++j) {
  43838. if (codes[j] !== codes[j - 1] + 1) {
  43839. end = range[0] + j - 1;
  43840. format31012 += string32(start) + // startCharCode
  43841. string32(end) + // endCharCode
  43842. string32(code);
  43843. // startGlyphID
  43844. start = end + 1;
  43845. code = codes[j];
  43846. }
  43847. }
  43848. format31012 += string32(start) + // startCharCode
  43849. string32(range[1]) + // endCharCode
  43850. string32(code);
  43851. }
  43852. // startGlyphID
  43853. header31012 = '\x00\x0C' + // format
  43854. '\x00\x00' + // reserved
  43855. string32(format31012.length + 16) + // length
  43856. '\x00\x00\x00\x00' + // language
  43857. string32(format31012.length / 12);
  43858. }
  43859. // nGroups
  43860. return cmap + '\x00\x04' + // format
  43861. string16(format314.length + 4) + // length
  43862. format314 + header31012 + format31012;
  43863. }
  43864. function validateOS2Table(os2) {
  43865. var stream = new Stream(os2.data);
  43866. var version = stream.getUint16();
  43867. // TODO verify all OS/2 tables fields, but currently we validate only those
  43868. // that give us issues
  43869. stream.getBytes(60);
  43870. // skipping type, misc sizes, panose, unicode ranges
  43871. var selection = stream.getUint16();
  43872. if (version < 4 && selection & 0x0300) {
  43873. return false;
  43874. }
  43875. var firstChar = stream.getUint16();
  43876. var lastChar = stream.getUint16();
  43877. if (firstChar > lastChar) {
  43878. return false;
  43879. }
  43880. stream.getBytes(6);
  43881. // skipping sTypoAscender/Descender/LineGap
  43882. var usWinAscent = stream.getUint16();
  43883. if (usWinAscent === 0) {
  43884. // makes font unreadable by windows
  43885. return false;
  43886. }
  43887. // OS/2 appears to be valid, resetting some fields
  43888. os2.data[8] = os2.data[9] = 0;
  43889. // IE rejects fonts if fsType != 0
  43890. return true;
  43891. }
  43892. function createOS2Table(properties, charstrings, override) {
  43893. override = override || {
  43894. unitsPerEm: 0,
  43895. yMax: 0,
  43896. yMin: 0,
  43897. ascent: 0,
  43898. descent: 0
  43899. };
  43900. var ulUnicodeRange1 = 0;
  43901. var ulUnicodeRange2 = 0;
  43902. var ulUnicodeRange3 = 0;
  43903. var ulUnicodeRange4 = 0;
  43904. var firstCharIndex = null;
  43905. var lastCharIndex = 0;
  43906. if (charstrings) {
  43907. for (var code in charstrings) {
  43908. code |= 0;
  43909. if (firstCharIndex > code || !firstCharIndex) {
  43910. firstCharIndex = code;
  43911. }
  43912. if (lastCharIndex < code) {
  43913. lastCharIndex = code;
  43914. }
  43915. var position = getUnicodeRangeFor(code);
  43916. if (position < 32) {
  43917. ulUnicodeRange1 |= 1 << position;
  43918. } else if (position < 64) {
  43919. ulUnicodeRange2 |= 1 << position - 32;
  43920. } else if (position < 96) {
  43921. ulUnicodeRange3 |= 1 << position - 64;
  43922. } else if (position < 123) {
  43923. ulUnicodeRange4 |= 1 << position - 96;
  43924. } else {
  43925. error('Unicode ranges Bits > 123 are reserved for internal usage');
  43926. }
  43927. }
  43928. } else {
  43929. // TODO
  43930. firstCharIndex = 0;
  43931. lastCharIndex = 255;
  43932. }
  43933. var bbox = properties.bbox || [
  43934. 0,
  43935. 0,
  43936. 0,
  43937. 0
  43938. ];
  43939. var unitsPerEm = override.unitsPerEm || 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  43940. // if the font units differ to the PDF glyph space units
  43941. // then scale up the values
  43942. var scale = properties.ascentScaled ? 1.0 : unitsPerEm / PDF_GLYPH_SPACE_UNITS;
  43943. var typoAscent = override.ascent || Math.round(scale * (properties.ascent || bbox[3]));
  43944. var typoDescent = override.descent || Math.round(scale * (properties.descent || bbox[1]));
  43945. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  43946. typoDescent = -typoDescent;
  43947. }
  43948. // fixing incorrect descent
  43949. var winAscent = override.yMax || typoAscent;
  43950. var winDescent = -override.yMin || -typoDescent;
  43951. return '\x00\x03' + // version
  43952. '\x02\x24' + // xAvgCharWidth
  43953. '\x01\xF4' + // usWeightClass
  43954. '\x00\x05' + // usWidthClass
  43955. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  43956. '\x02\x8A' + // ySubscriptXSize
  43957. '\x02\xBB' + // ySubscriptYSize
  43958. '\x00\x00' + // ySubscriptXOffset
  43959. '\x00\x8C' + // ySubscriptYOffset
  43960. '\x02\x8A' + // ySuperScriptXSize
  43961. '\x02\xBB' + // ySuperScriptYSize
  43962. '\x00\x00' + // ySuperScriptXOffset
  43963. '\x01\xDF' + // ySuperScriptYOffset
  43964. '\x00\x31' + // yStrikeOutSize
  43965. '\x01\x02' + // yStrikeOutPosition
  43966. '\x00\x00' + // sFamilyClass
  43967. '\x00\x00\x06' + String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) + '\x00\x00\x00\x00\x00\x00' + // Panose
  43968. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  43969. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  43970. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  43971. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  43972. '\x2A\x32\x31\x2A' + // achVendID
  43973. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  43974. string16(firstCharIndex || properties.firstChar) + // usFirstCharIndex
  43975. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  43976. string16(typoAscent) + // sTypoAscender
  43977. string16(typoDescent) + // sTypoDescender
  43978. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  43979. string16(winAscent) + // usWinAscent
  43980. string16(winDescent) + // usWinDescent
  43981. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  43982. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  43983. string16(properties.xHeight) + // sxHeight
  43984. string16(properties.capHeight) + // sCapHeight
  43985. string16(0) + // usDefaultChar
  43986. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  43987. '\x00\x03';
  43988. }
  43989. // usMaxContext
  43990. function createPostTable(properties) {
  43991. var angle = Math.floor(properties.italicAngle * Math.pow(2, 16));
  43992. return '\x00\x03\x00\x00' + // Version number
  43993. string32(angle) + // italicAngle
  43994. '\x00\x00' + // underlinePosition
  43995. '\x00\x00' + // underlineThickness
  43996. string32(properties.fixedPitch) + // isFixedPitch
  43997. '\x00\x00\x00\x00' + // minMemType42
  43998. '\x00\x00\x00\x00' + // maxMemType42
  43999. '\x00\x00\x00\x00' + // minMemType1
  44000. '\x00\x00\x00\x00';
  44001. }
  44002. // maxMemType1
  44003. function createNameTable(name, proto) {
  44004. if (!proto) {
  44005. proto = [
  44006. [],
  44007. []
  44008. ];
  44009. }
  44010. // no strings and unicode strings
  44011. var strings = [
  44012. proto[0][0] || 'Original licence',
  44013. // 0.Copyright
  44014. proto[0][1] || name,
  44015. // 1.Font family
  44016. proto[0][2] || 'Unknown',
  44017. // 2.Font subfamily (font weight)
  44018. proto[0][3] || 'uniqueID',
  44019. // 3.Unique ID
  44020. proto[0][4] || name,
  44021. // 4.Full font name
  44022. proto[0][5] || 'Version 0.11',
  44023. // 5.Version
  44024. proto[0][6] || '',
  44025. // 6.Postscript name
  44026. proto[0][7] || 'Unknown',
  44027. // 7.Trademark
  44028. proto[0][8] || 'Unknown',
  44029. // 8.Manufacturer
  44030. proto[0][9] || 'Unknown'
  44031. ];
  44032. // 9.Designer
  44033. // Mac want 1-byte per character strings while Windows want
  44034. // 2-bytes per character, so duplicate the names table
  44035. var stringsUnicode = [];
  44036. var i, ii, j, jj, str;
  44037. for (i = 0, ii = strings.length; i < ii; i++) {
  44038. str = proto[1][i] || strings[i];
  44039. var strBufUnicode = [];
  44040. for (j = 0, jj = str.length; j < jj; j++) {
  44041. strBufUnicode.push(string16(str.charCodeAt(j)));
  44042. }
  44043. stringsUnicode.push(strBufUnicode.join(''));
  44044. }
  44045. var names = [
  44046. strings,
  44047. stringsUnicode
  44048. ];
  44049. var platforms = [
  44050. '\x00\x01',
  44051. '\x00\x03'
  44052. ];
  44053. var encodings = [
  44054. '\x00\x00',
  44055. '\x00\x01'
  44056. ];
  44057. var languages = [
  44058. '\x00\x00',
  44059. '\x04\x09'
  44060. ];
  44061. var namesRecordCount = strings.length * platforms.length;
  44062. var nameTable = '\x00\x00' + // format
  44063. string16(namesRecordCount) + // Number of names Record
  44064. string16(namesRecordCount * 12 + 6);
  44065. // Storage
  44066. // Build the name records field
  44067. var strOffset = 0;
  44068. for (i = 0, ii = platforms.length; i < ii; i++) {
  44069. var strs = names[i];
  44070. for (j = 0, jj = strs.length; j < jj; j++) {
  44071. str = strs[j];
  44072. var nameRecord = platforms[i] + // platform ID
  44073. encodings[i] + // encoding ID
  44074. languages[i] + // language ID
  44075. string16(j) + // name ID
  44076. string16(str.length) + string16(strOffset);
  44077. nameTable += nameRecord;
  44078. strOffset += str.length;
  44079. }
  44080. }
  44081. nameTable += strings.join('') + stringsUnicode.join('');
  44082. return nameTable;
  44083. }
  44084. Font.prototype = {
  44085. name: null,
  44086. font: null,
  44087. mimetype: null,
  44088. encoding: null,
  44089. get renderer() {
  44090. var renderer = FontRendererFactory.create(this, SEAC_ANALYSIS_ENABLED);
  44091. return shadow(this, 'renderer', renderer);
  44092. },
  44093. exportData: function Font_exportData() {
  44094. // TODO remove enumerating of the properties, e.g. hardcode exact names.
  44095. var data = {};
  44096. for (var i in this) {
  44097. if (this.hasOwnProperty(i)) {
  44098. data[i] = this[i];
  44099. }
  44100. }
  44101. return data;
  44102. },
  44103. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  44104. function readTableEntry(file) {
  44105. var tag = bytesToString(file.getBytes(4));
  44106. var checksum = file.getInt32() >>> 0;
  44107. var offset = file.getInt32() >>> 0;
  44108. var length = file.getInt32() >>> 0;
  44109. // Read the table associated data
  44110. var previousPosition = file.pos;
  44111. file.pos = file.start ? file.start : 0;
  44112. file.skip(offset);
  44113. var data = file.getBytes(length);
  44114. file.pos = previousPosition;
  44115. if (tag === 'head') {
  44116. // clearing checksum adjustment
  44117. data[8] = data[9] = data[10] = data[11] = 0;
  44118. data[17] |= 0x20;
  44119. }
  44120. //Set font optimized for cleartype flag
  44121. return {
  44122. tag: tag,
  44123. checksum: checksum,
  44124. length: length,
  44125. offset: offset,
  44126. data: data
  44127. };
  44128. }
  44129. function readOpenTypeHeader(ttf) {
  44130. return {
  44131. version: bytesToString(ttf.getBytes(4)),
  44132. numTables: ttf.getUint16(),
  44133. searchRange: ttf.getUint16(),
  44134. entrySelector: ttf.getUint16(),
  44135. rangeShift: ttf.getUint16()
  44136. };
  44137. }
  44138. /**
  44139. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  44140. * PDF spec
  44141. */
  44142. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  44143. if (!cmap) {
  44144. warn('No cmap table available.');
  44145. return {
  44146. platformId: -1,
  44147. encodingId: -1,
  44148. mappings: [],
  44149. hasShortCmap: false
  44150. };
  44151. }
  44152. var segment;
  44153. var start = (font.start ? font.start : 0) + cmap.offset;
  44154. font.pos = start;
  44155. var version = font.getUint16();
  44156. var numTables = font.getUint16();
  44157. var potentialTable;
  44158. var canBreak = false;
  44159. // There's an order of preference in terms of which cmap subtable to
  44160. // use:
  44161. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  44162. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  44163. // The following takes advantage of the fact that the tables are sorted
  44164. // to work.
  44165. for (var i = 0; i < numTables; i++) {
  44166. var platformId = font.getUint16();
  44167. var encodingId = font.getUint16();
  44168. var offset = font.getInt32() >>> 0;
  44169. var useTable = false;
  44170. if (platformId === 0 && encodingId === 0) {
  44171. useTable = true;
  44172. } else // Continue the loop since there still may be a higher priority
  44173. // table.
  44174. if (platformId === 1 && encodingId === 0) {
  44175. useTable = true;
  44176. } else // Continue the loop since there still may be a higher priority
  44177. // table.
  44178. if (platformId === 3 && encodingId === 1 && (!isSymbolicFont && hasEncoding || !potentialTable)) {
  44179. useTable = true;
  44180. if (!isSymbolicFont) {
  44181. canBreak = true;
  44182. }
  44183. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  44184. useTable = true;
  44185. canBreak = true;
  44186. }
  44187. if (useTable) {
  44188. potentialTable = {
  44189. platformId: platformId,
  44190. encodingId: encodingId,
  44191. offset: offset
  44192. };
  44193. }
  44194. if (canBreak) {
  44195. break;
  44196. }
  44197. }
  44198. if (potentialTable) {
  44199. font.pos = start + potentialTable.offset;
  44200. }
  44201. if (!potentialTable || font.peekByte() === -1) {
  44202. warn('Could not find a preferred cmap table.');
  44203. return {
  44204. platformId: -1,
  44205. encodingId: -1,
  44206. mappings: [],
  44207. hasShortCmap: false
  44208. };
  44209. }
  44210. var format = font.getUint16();
  44211. var length = font.getUint16();
  44212. var language = font.getUint16();
  44213. var hasShortCmap = false;
  44214. var mappings = [];
  44215. var j, glyphId;
  44216. // TODO(mack): refactor this cmap subtable reading logic out
  44217. if (format === 0) {
  44218. for (j = 0; j < 256; j++) {
  44219. var index = font.getByte();
  44220. if (!index) {
  44221. continue;
  44222. }
  44223. mappings.push({
  44224. charCode: j,
  44225. glyphId: index
  44226. });
  44227. }
  44228. hasShortCmap = true;
  44229. } else if (format === 4) {
  44230. // re-creating the table in format 4 since the encoding
  44231. // might be changed
  44232. var segCount = font.getUint16() >> 1;
  44233. font.getBytes(6);
  44234. // skipping range fields
  44235. var segIndex, segments = [];
  44236. for (segIndex = 0; segIndex < segCount; segIndex++) {
  44237. segments.push({ end: font.getUint16() });
  44238. }
  44239. font.getUint16();
  44240. for (segIndex = 0; segIndex < segCount; segIndex++) {
  44241. segments[segIndex].start = font.getUint16();
  44242. }
  44243. for (segIndex = 0; segIndex < segCount; segIndex++) {
  44244. segments[segIndex].delta = font.getUint16();
  44245. }
  44246. var offsetsCount = 0;
  44247. for (segIndex = 0; segIndex < segCount; segIndex++) {
  44248. segment = segments[segIndex];
  44249. var rangeOffset = font.getUint16();
  44250. if (!rangeOffset) {
  44251. segment.offsetIndex = -1;
  44252. continue;
  44253. }
  44254. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  44255. segment.offsetIndex = offsetIndex;
  44256. offsetsCount = Math.max(offsetsCount, offsetIndex + segment.end - segment.start + 1);
  44257. }
  44258. var offsets = [];
  44259. for (j = 0; j < offsetsCount; j++) {
  44260. offsets.push(font.getUint16());
  44261. }
  44262. for (segIndex = 0; segIndex < segCount; segIndex++) {
  44263. segment = segments[segIndex];
  44264. start = segment.start;
  44265. var end = segment.end;
  44266. var delta = segment.delta;
  44267. offsetIndex = segment.offsetIndex;
  44268. for (j = start; j <= end; j++) {
  44269. if (j === 0xFFFF) {
  44270. continue;
  44271. }
  44272. glyphId = offsetIndex < 0 ? j : offsets[offsetIndex + j - start];
  44273. glyphId = glyphId + delta & 0xFFFF;
  44274. if (glyphId === 0) {
  44275. continue;
  44276. }
  44277. mappings.push({
  44278. charCode: j,
  44279. glyphId: glyphId
  44280. });
  44281. }
  44282. }
  44283. } else if (format === 6) {
  44284. // Format 6 is a 2-bytes dense mapping, which means the font data
  44285. // lives glue together even if they are pretty far in the unicode
  44286. // table. (This looks weird, so I can have missed something), this
  44287. // works on Linux but seems to fails on Mac so let's rewrite the
  44288. // cmap table to a 3-1-4 style
  44289. var firstCode = font.getUint16();
  44290. var entryCount = font.getUint16();
  44291. for (j = 0; j < entryCount; j++) {
  44292. glyphId = font.getUint16();
  44293. var charCode = firstCode + j;
  44294. mappings.push({
  44295. charCode: charCode,
  44296. glyphId: glyphId
  44297. });
  44298. }
  44299. } else {
  44300. warn('cmap table has unsupported format: ' + format);
  44301. return {
  44302. platformId: -1,
  44303. encodingId: -1,
  44304. mappings: [],
  44305. hasShortCmap: false
  44306. };
  44307. }
  44308. // removing duplicate entries
  44309. mappings.sort(function (a, b) {
  44310. return a.charCode - b.charCode;
  44311. });
  44312. for (i = 1; i < mappings.length; i++) {
  44313. if (mappings[i - 1].charCode === mappings[i].charCode) {
  44314. mappings.splice(i, 1);
  44315. i--;
  44316. }
  44317. }
  44318. return {
  44319. platformId: potentialTable.platformId,
  44320. encodingId: potentialTable.encodingId,
  44321. mappings: mappings,
  44322. hasShortCmap: hasShortCmap
  44323. };
  44324. }
  44325. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  44326. if (!header) {
  44327. if (metrics) {
  44328. metrics.data = null;
  44329. }
  44330. return;
  44331. }
  44332. font.pos = (font.start ? font.start : 0) + header.offset;
  44333. font.pos += header.length - 2;
  44334. var numOfMetrics = font.getUint16();
  44335. if (numOfMetrics > numGlyphs) {
  44336. info('The numOfMetrics (' + numOfMetrics + ') should not be ' + 'greater than the numGlyphs (' + numGlyphs + ')');
  44337. // Reduce numOfMetrics if it is greater than numGlyphs
  44338. numOfMetrics = numGlyphs;
  44339. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  44340. header.data[35] = numOfMetrics & 0x00ff;
  44341. }
  44342. var numOfSidebearings = numGlyphs - numOfMetrics;
  44343. var numMissing = numOfSidebearings - (metrics.length - numOfMetrics * 4 >> 1);
  44344. if (numMissing > 0) {
  44345. // For each missing glyph, we set both the width and lsb to 0 (zero).
  44346. // Since we need to add two properties for each glyph, this explains
  44347. // the use of |numMissing * 2| when initializing the typed array.
  44348. var entries = new Uint8Array(metrics.length + numMissing * 2);
  44349. entries.set(metrics.data);
  44350. metrics.data = entries;
  44351. }
  44352. }
  44353. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart, hintsValid) {
  44354. if (sourceEnd - sourceStart <= 12) {
  44355. // glyph with data less than 12 is invalid one
  44356. return 0;
  44357. }
  44358. var glyf = source.subarray(sourceStart, sourceEnd);
  44359. var contoursCount = glyf[0] << 8 | glyf[1];
  44360. if (contoursCount & 0x8000) {
  44361. // complex glyph, writing as is
  44362. dest.set(glyf, destStart);
  44363. return glyf.length;
  44364. }
  44365. var i, j = 10, flagsCount = 0;
  44366. for (i = 0; i < contoursCount; i++) {
  44367. var endPoint = glyf[j] << 8 | glyf[j + 1];
  44368. flagsCount = endPoint + 1;
  44369. j += 2;
  44370. }
  44371. // skipping instructions
  44372. var instructionsStart = j;
  44373. var instructionsLength = glyf[j] << 8 | glyf[j + 1];
  44374. j += 2 + instructionsLength;
  44375. var instructionsEnd = j;
  44376. // validating flags
  44377. var coordinatesLength = 0;
  44378. for (i = 0; i < flagsCount; i++) {
  44379. var flag = glyf[j++];
  44380. if (flag & 0xC0) {
  44381. // reserved flags must be zero, cleaning up
  44382. glyf[j - 1] = flag & 0x3F;
  44383. }
  44384. var xyLength = (flag & 2 ? 1 : flag & 16 ? 0 : 2) + (flag & 4 ? 1 : flag & 32 ? 0 : 2);
  44385. coordinatesLength += xyLength;
  44386. if (flag & 8) {
  44387. var repeat = glyf[j++];
  44388. i += repeat;
  44389. coordinatesLength += repeat * xyLength;
  44390. }
  44391. }
  44392. // glyph without coordinates will be rejected
  44393. if (coordinatesLength === 0) {
  44394. return 0;
  44395. }
  44396. var glyphDataLength = j + coordinatesLength;
  44397. if (glyphDataLength > glyf.length) {
  44398. // not enough data for coordinates
  44399. return 0;
  44400. }
  44401. if (!hintsValid && instructionsLength > 0) {
  44402. dest.set(glyf.subarray(0, instructionsStart), destStart);
  44403. dest.set([
  44404. 0,
  44405. 0
  44406. ], destStart + instructionsStart);
  44407. dest.set(glyf.subarray(instructionsEnd, glyphDataLength), destStart + instructionsStart + 2);
  44408. glyphDataLength -= instructionsLength;
  44409. if (glyf.length - glyphDataLength > 3) {
  44410. glyphDataLength = glyphDataLength + 3 & ~3;
  44411. }
  44412. return glyphDataLength;
  44413. }
  44414. if (glyf.length - glyphDataLength > 3) {
  44415. // truncating and aligning to 4 bytes the long glyph data
  44416. glyphDataLength = glyphDataLength + 3 & ~3;
  44417. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  44418. return glyphDataLength;
  44419. }
  44420. // glyph data is fine
  44421. dest.set(glyf, destStart);
  44422. return glyf.length;
  44423. }
  44424. function sanitizeHead(head, numGlyphs, locaLength) {
  44425. var data = head.data;
  44426. // Validate version:
  44427. // Should always be 0x00010000
  44428. var version = int32(data[0], data[1], data[2], data[3]);
  44429. if (version >> 16 !== 1) {
  44430. info('Attempting to fix invalid version in head table: ' + version);
  44431. data[0] = 0;
  44432. data[1] = 1;
  44433. data[2] = 0;
  44434. data[3] = 0;
  44435. }
  44436. var indexToLocFormat = int16(data[50], data[51]);
  44437. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  44438. info('Attempting to fix invalid indexToLocFormat in head table: ' + indexToLocFormat);
  44439. // The value of indexToLocFormat should be 0 if the loca table
  44440. // consists of short offsets, and should be 1 if the loca table
  44441. // consists of long offsets.
  44442. //
  44443. // The number of entries in the loca table should be numGlyphs + 1.
  44444. //
  44445. // Using this information, we can work backwards to deduce if the
  44446. // size of each offset in the loca table, and thus figure out the
  44447. // appropriate value for indexToLocFormat.
  44448. var numGlyphsPlusOne = numGlyphs + 1;
  44449. if (locaLength === numGlyphsPlusOne << 1) {
  44450. // 0x0000 indicates the loca table consists of short offsets
  44451. data[50] = 0;
  44452. data[51] = 0;
  44453. } else if (locaLength === numGlyphsPlusOne << 2) {
  44454. // 0x0001 indicates the loca table consists of long offsets
  44455. data[50] = 0;
  44456. data[51] = 1;
  44457. } else {
  44458. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  44459. }
  44460. }
  44461. }
  44462. function sanitizeGlyphLocations(loca, glyf, numGlyphs, isGlyphLocationsLong, hintsValid, dupFirstEntry) {
  44463. var itemSize, itemDecode, itemEncode;
  44464. if (isGlyphLocationsLong) {
  44465. itemSize = 4;
  44466. itemDecode = function fontItemDecodeLong(data, offset) {
  44467. return data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3];
  44468. };
  44469. itemEncode = function fontItemEncodeLong(data, offset, value) {
  44470. data[offset] = value >>> 24 & 0xFF;
  44471. data[offset + 1] = value >> 16 & 0xFF;
  44472. data[offset + 2] = value >> 8 & 0xFF;
  44473. data[offset + 3] = value & 0xFF;
  44474. };
  44475. } else {
  44476. itemSize = 2;
  44477. itemDecode = function fontItemDecode(data, offset) {
  44478. return data[offset] << 9 | data[offset + 1] << 1;
  44479. };
  44480. itemEncode = function fontItemEncode(data, offset, value) {
  44481. data[offset] = value >> 9 & 0xFF;
  44482. data[offset + 1] = value >> 1 & 0xFF;
  44483. };
  44484. }
  44485. var locaData = loca.data;
  44486. var locaDataSize = itemSize * (1 + numGlyphs);
  44487. // is loca.data too short or long?
  44488. if (locaData.length !== locaDataSize) {
  44489. locaData = new Uint8Array(locaDataSize);
  44490. locaData.set(loca.data.subarray(0, locaDataSize));
  44491. loca.data = locaData;
  44492. }
  44493. // removing the invalid glyphs
  44494. var oldGlyfData = glyf.data;
  44495. var oldGlyfDataLength = oldGlyfData.length;
  44496. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  44497. var startOffset = itemDecode(locaData, 0);
  44498. var writeOffset = 0;
  44499. var missingGlyphData = Object.create(null);
  44500. itemEncode(locaData, 0, writeOffset);
  44501. var i, j;
  44502. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  44503. var endOffset = itemDecode(locaData, j);
  44504. if (endOffset > oldGlyfDataLength && (oldGlyfDataLength + 3 & ~3) === endOffset) {
  44505. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  44506. // the glyf table size, which makes last glyph out of range.
  44507. endOffset = oldGlyfDataLength;
  44508. }
  44509. if (endOffset > oldGlyfDataLength) {
  44510. // glyph end offset points outside glyf data, rejecting the glyph
  44511. itemEncode(locaData, j, writeOffset);
  44512. startOffset = endOffset;
  44513. continue;
  44514. }
  44515. if (startOffset === endOffset) {
  44516. missingGlyphData[i] = true;
  44517. }
  44518. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset, newGlyfData, writeOffset, hintsValid);
  44519. writeOffset += newLength;
  44520. itemEncode(locaData, j, writeOffset);
  44521. startOffset = endOffset;
  44522. }
  44523. if (writeOffset === 0) {
  44524. // glyf table cannot be empty -- redoing the glyf and loca tables
  44525. // to have single glyph with one point
  44526. var simpleGlyph = new Uint8Array([
  44527. 0,
  44528. 1,
  44529. 0,
  44530. 0,
  44531. 0,
  44532. 0,
  44533. 0,
  44534. 0,
  44535. 0,
  44536. 0,
  44537. 0,
  44538. 0,
  44539. 0,
  44540. 0,
  44541. 49,
  44542. 0
  44543. ]);
  44544. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  44545. itemEncode(locaData, j, simpleGlyph.length);
  44546. }
  44547. glyf.data = simpleGlyph;
  44548. return missingGlyphData;
  44549. }
  44550. if (dupFirstEntry) {
  44551. var firstEntryLength = itemDecode(locaData, itemSize);
  44552. if (newGlyfData.length > firstEntryLength + writeOffset) {
  44553. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  44554. } else {
  44555. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  44556. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  44557. }
  44558. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  44559. itemEncode(loca.data, locaData.length - itemSize, writeOffset + firstEntryLength);
  44560. } else {
  44561. glyf.data = newGlyfData.subarray(0, writeOffset);
  44562. }
  44563. return missingGlyphData;
  44564. }
  44565. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  44566. var start = (font.start ? font.start : 0) + post.offset;
  44567. font.pos = start;
  44568. var length = post.length, end = start + length;
  44569. var version = font.getInt32();
  44570. // skip rest to the tables
  44571. font.getBytes(28);
  44572. var glyphNames;
  44573. var valid = true;
  44574. var i;
  44575. switch (version) {
  44576. case 0x00010000:
  44577. glyphNames = MacStandardGlyphOrdering;
  44578. break;
  44579. case 0x00020000:
  44580. var numGlyphs = font.getUint16();
  44581. if (numGlyphs !== maxpNumGlyphs) {
  44582. valid = false;
  44583. break;
  44584. }
  44585. var glyphNameIndexes = [];
  44586. for (i = 0; i < numGlyphs; ++i) {
  44587. var index = font.getUint16();
  44588. if (index >= 32768) {
  44589. valid = false;
  44590. break;
  44591. }
  44592. glyphNameIndexes.push(index);
  44593. }
  44594. if (!valid) {
  44595. break;
  44596. }
  44597. var customNames = [];
  44598. var strBuf = [];
  44599. while (font.pos < end) {
  44600. var stringLength = font.getByte();
  44601. strBuf.length = stringLength;
  44602. for (i = 0; i < stringLength; ++i) {
  44603. strBuf[i] = String.fromCharCode(font.getByte());
  44604. }
  44605. customNames.push(strBuf.join(''));
  44606. }
  44607. glyphNames = [];
  44608. for (i = 0; i < numGlyphs; ++i) {
  44609. var j = glyphNameIndexes[i];
  44610. if (j < 258) {
  44611. glyphNames.push(MacStandardGlyphOrdering[j]);
  44612. continue;
  44613. }
  44614. glyphNames.push(customNames[j - 258]);
  44615. }
  44616. break;
  44617. case 0x00030000:
  44618. break;
  44619. default:
  44620. warn('Unknown/unsupported post table version ' + version);
  44621. valid = false;
  44622. if (properties.defaultEncoding) {
  44623. glyphNames = properties.defaultEncoding;
  44624. }
  44625. break;
  44626. }
  44627. properties.glyphNames = glyphNames;
  44628. return valid;
  44629. }
  44630. function readNameTable(nameTable) {
  44631. var start = (font.start ? font.start : 0) + nameTable.offset;
  44632. font.pos = start;
  44633. var names = [
  44634. [],
  44635. []
  44636. ];
  44637. var length = nameTable.length, end = start + length;
  44638. var format = font.getUint16();
  44639. var FORMAT_0_HEADER_LENGTH = 6;
  44640. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  44641. // unsupported name table format or table "too" small
  44642. return names;
  44643. }
  44644. var numRecords = font.getUint16();
  44645. var stringsStart = font.getUint16();
  44646. var records = [];
  44647. var NAME_RECORD_LENGTH = 12;
  44648. var i, ii;
  44649. for (i = 0; i < numRecords && font.pos + NAME_RECORD_LENGTH <= end; i++) {
  44650. var r = {
  44651. platform: font.getUint16(),
  44652. encoding: font.getUint16(),
  44653. language: font.getUint16(),
  44654. name: font.getUint16(),
  44655. length: font.getUint16(),
  44656. offset: font.getUint16()
  44657. };
  44658. // using only Macintosh and Windows platform/encoding names
  44659. if (r.platform === 1 && r.encoding === 0 && r.language === 0 || r.platform === 3 && r.encoding === 1 && r.language === 0x409) {
  44660. records.push(r);
  44661. }
  44662. }
  44663. for (i = 0, ii = records.length; i < ii; i++) {
  44664. var record = records[i];
  44665. if (record.length <= 0) {
  44666. continue;
  44667. }
  44668. // Nothing to process, ignoring.
  44669. var pos = start + stringsStart + record.offset;
  44670. if (pos + record.length > end) {
  44671. continue;
  44672. }
  44673. // outside of name table, ignoring
  44674. font.pos = pos;
  44675. var nameIndex = record.name;
  44676. if (record.encoding) {
  44677. // unicode
  44678. var str = '';
  44679. for (var j = 0, jj = record.length; j < jj; j += 2) {
  44680. str += String.fromCharCode(font.getUint16());
  44681. }
  44682. names[1][nameIndex] = str;
  44683. } else {
  44684. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  44685. }
  44686. }
  44687. return names;
  44688. }
  44689. var TTOpsStackDeltas = [
  44690. 0,
  44691. 0,
  44692. 0,
  44693. 0,
  44694. 0,
  44695. 0,
  44696. 0,
  44697. 0,
  44698. -2,
  44699. -2,
  44700. -2,
  44701. -2,
  44702. 0,
  44703. 0,
  44704. -2,
  44705. -5,
  44706. -1,
  44707. -1,
  44708. -1,
  44709. -1,
  44710. -1,
  44711. -1,
  44712. -1,
  44713. -1,
  44714. 0,
  44715. 0,
  44716. -1,
  44717. 0,
  44718. -1,
  44719. -1,
  44720. -1,
  44721. -1,
  44722. 1,
  44723. -1,
  44724. -999,
  44725. 0,
  44726. 1,
  44727. 0,
  44728. -1,
  44729. -2,
  44730. 0,
  44731. -1,
  44732. -2,
  44733. -1,
  44734. -1,
  44735. 0,
  44736. -1,
  44737. -1,
  44738. 0,
  44739. 0,
  44740. -999,
  44741. -999,
  44742. -1,
  44743. -1,
  44744. -1,
  44745. -1,
  44746. -2,
  44747. -999,
  44748. -2,
  44749. -2,
  44750. -999,
  44751. 0,
  44752. -2,
  44753. -2,
  44754. 0,
  44755. 0,
  44756. -2,
  44757. 0,
  44758. -2,
  44759. 0,
  44760. 0,
  44761. 0,
  44762. -2,
  44763. -1,
  44764. -1,
  44765. 1,
  44766. 1,
  44767. 0,
  44768. 0,
  44769. -1,
  44770. -1,
  44771. -1,
  44772. -1,
  44773. -1,
  44774. -1,
  44775. -1,
  44776. 0,
  44777. 0,
  44778. -1,
  44779. 0,
  44780. -1,
  44781. -1,
  44782. 0,
  44783. -999,
  44784. -1,
  44785. -1,
  44786. -1,
  44787. -1,
  44788. -1,
  44789. -1,
  44790. 0,
  44791. 0,
  44792. 0,
  44793. 0,
  44794. 0,
  44795. 0,
  44796. 0,
  44797. 0,
  44798. 0,
  44799. 0,
  44800. 0,
  44801. 0,
  44802. -2,
  44803. -999,
  44804. -999,
  44805. -999,
  44806. -999,
  44807. -999,
  44808. -1,
  44809. -1,
  44810. -2,
  44811. -2,
  44812. 0,
  44813. 0,
  44814. 0,
  44815. 0,
  44816. -1,
  44817. -1,
  44818. -999,
  44819. -2,
  44820. -2,
  44821. 0,
  44822. 0,
  44823. -1,
  44824. -2,
  44825. -2,
  44826. 0,
  44827. 0,
  44828. 0,
  44829. -1,
  44830. -1,
  44831. -1,
  44832. -2
  44833. ];
  44834. // 0xC0-DF == -1 and 0xE0-FF == -2
  44835. function sanitizeTTProgram(table, ttContext) {
  44836. var data = table.data;
  44837. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  44838. var stack = [];
  44839. var callstack = [];
  44840. var functionsCalled = [];
  44841. var tooComplexToFollowFunctions = ttContext.tooComplexToFollowFunctions;
  44842. var inFDEF = false, ifLevel = 0, inELSE = 0;
  44843. for (var ii = data.length; i < ii;) {
  44844. var op = data[i++];
  44845. // The TrueType instruction set docs can be found at
  44846. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  44847. if (op === 0x40) {
  44848. // NPUSHB - pushes n bytes
  44849. n = data[i++];
  44850. if (inFDEF || inELSE) {
  44851. i += n;
  44852. } else {
  44853. for (j = 0; j < n; j++) {
  44854. stack.push(data[i++]);
  44855. }
  44856. }
  44857. } else if (op === 0x41) {
  44858. // NPUSHW - pushes n words
  44859. n = data[i++];
  44860. if (inFDEF || inELSE) {
  44861. i += n * 2;
  44862. } else {
  44863. for (j = 0; j < n; j++) {
  44864. b = data[i++];
  44865. stack.push(b << 8 | data[i++]);
  44866. }
  44867. }
  44868. } else if ((op & 0xF8) === 0xB0) {
  44869. // PUSHB - pushes bytes
  44870. n = op - 0xB0 + 1;
  44871. if (inFDEF || inELSE) {
  44872. i += n;
  44873. } else {
  44874. for (j = 0; j < n; j++) {
  44875. stack.push(data[i++]);
  44876. }
  44877. }
  44878. } else if ((op & 0xF8) === 0xB8) {
  44879. // PUSHW - pushes words
  44880. n = op - 0xB8 + 1;
  44881. if (inFDEF || inELSE) {
  44882. i += n * 2;
  44883. } else {
  44884. for (j = 0; j < n; j++) {
  44885. b = data[i++];
  44886. stack.push(b << 8 | data[i++]);
  44887. }
  44888. }
  44889. } else if (op === 0x2B && !tooComplexToFollowFunctions) {
  44890. // CALL
  44891. if (!inFDEF && !inELSE) {
  44892. // collecting inforamtion about which functions are used
  44893. funcId = stack[stack.length - 1];
  44894. ttContext.functionsUsed[funcId] = true;
  44895. if (funcId in ttContext.functionsStackDeltas) {
  44896. stack.length += ttContext.functionsStackDeltas[funcId];
  44897. } else if (funcId in ttContext.functionsDefined && functionsCalled.indexOf(funcId) < 0) {
  44898. callstack.push({
  44899. data: data,
  44900. i: i,
  44901. stackTop: stack.length - 1
  44902. });
  44903. functionsCalled.push(funcId);
  44904. pc = ttContext.functionsDefined[funcId];
  44905. if (!pc) {
  44906. warn('TT: CALL non-existent function');
  44907. ttContext.hintsValid = false;
  44908. return;
  44909. }
  44910. data = pc.data;
  44911. i = pc.i;
  44912. }
  44913. }
  44914. } else if (op === 0x2C && !tooComplexToFollowFunctions) {
  44915. // FDEF
  44916. if (inFDEF || inELSE) {
  44917. warn('TT: nested FDEFs not allowed');
  44918. tooComplexToFollowFunctions = true;
  44919. }
  44920. inFDEF = true;
  44921. // collecting inforamtion about which functions are defined
  44922. lastDeff = i;
  44923. funcId = stack.pop();
  44924. ttContext.functionsDefined[funcId] = {
  44925. data: data,
  44926. i: i
  44927. };
  44928. } else if (op === 0x2D) {
  44929. // ENDF - end of function
  44930. if (inFDEF) {
  44931. inFDEF = false;
  44932. lastEndf = i;
  44933. } else {
  44934. pc = callstack.pop();
  44935. if (!pc) {
  44936. warn('TT: ENDF bad stack');
  44937. ttContext.hintsValid = false;
  44938. return;
  44939. }
  44940. funcId = functionsCalled.pop();
  44941. data = pc.data;
  44942. i = pc.i;
  44943. ttContext.functionsStackDeltas[funcId] = stack.length - pc.stackTop;
  44944. }
  44945. } else if (op === 0x89) {
  44946. // IDEF - instruction definition
  44947. if (inFDEF || inELSE) {
  44948. warn('TT: nested IDEFs not allowed');
  44949. tooComplexToFollowFunctions = true;
  44950. }
  44951. inFDEF = true;
  44952. // recording it as a function to track ENDF
  44953. lastDeff = i;
  44954. } else if (op === 0x58) {
  44955. // IF
  44956. ++ifLevel;
  44957. } else if (op === 0x1B) {
  44958. // ELSE
  44959. inELSE = ifLevel;
  44960. } else if (op === 0x59) {
  44961. // EIF
  44962. if (inELSE === ifLevel) {
  44963. inELSE = 0;
  44964. }
  44965. --ifLevel;
  44966. } else if (op === 0x1C) {
  44967. // JMPR
  44968. if (!inFDEF && !inELSE) {
  44969. var offset = stack[stack.length - 1];
  44970. // only jumping forward to prevent infinite loop
  44971. if (offset > 0) {
  44972. i += offset - 1;
  44973. }
  44974. }
  44975. }
  44976. // Adjusting stack not extactly, but just enough to get function id
  44977. if (!inFDEF && !inELSE) {
  44978. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] : op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  44979. if (op >= 0x71 && op <= 0x75) {
  44980. n = stack.pop();
  44981. if (n === n) {
  44982. stackDelta = -n * 2;
  44983. }
  44984. }
  44985. while (stackDelta < 0 && stack.length > 0) {
  44986. stack.pop();
  44987. stackDelta++;
  44988. }
  44989. while (stackDelta > 0) {
  44990. stack.push(NaN);
  44991. // pushing any number into stack
  44992. stackDelta--;
  44993. }
  44994. }
  44995. }
  44996. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  44997. var content = [data];
  44998. if (i > data.length) {
  44999. content.push(new Uint8Array(i - data.length));
  45000. }
  45001. if (lastDeff > lastEndf) {
  45002. warn('TT: complementing a missing function tail');
  45003. // new function definition started, but not finished
  45004. // complete function by [CLEAR, ENDF]
  45005. content.push(new Uint8Array([
  45006. 0x22,
  45007. 0x2D
  45008. ]));
  45009. }
  45010. foldTTTable(table, content);
  45011. }
  45012. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  45013. if (ttContext.tooComplexToFollowFunctions) {
  45014. return;
  45015. }
  45016. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  45017. warn('TT: more functions defined than expected');
  45018. ttContext.hintsValid = false;
  45019. return;
  45020. }
  45021. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  45022. if (j > maxFunctionDefs) {
  45023. warn('TT: invalid function id: ' + j);
  45024. ttContext.hintsValid = false;
  45025. return;
  45026. }
  45027. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  45028. warn('TT: undefined function: ' + j);
  45029. ttContext.hintsValid = false;
  45030. return;
  45031. }
  45032. }
  45033. }
  45034. function foldTTTable(table, content) {
  45035. if (content.length > 1) {
  45036. // concatenating the content items
  45037. var newLength = 0;
  45038. var j, jj;
  45039. for (j = 0, jj = content.length; j < jj; j++) {
  45040. newLength += content[j].length;
  45041. }
  45042. newLength = newLength + 3 & ~3;
  45043. var result = new Uint8Array(newLength);
  45044. var pos = 0;
  45045. for (j = 0, jj = content.length; j < jj; j++) {
  45046. result.set(content[j], pos);
  45047. pos += content[j].length;
  45048. }
  45049. table.data = result;
  45050. table.length = newLength;
  45051. }
  45052. }
  45053. function sanitizeTTPrograms(fpgm, prep, cvt, maxFunctionDefs) {
  45054. var ttContext = {
  45055. functionsDefined: [],
  45056. functionsUsed: [],
  45057. functionsStackDeltas: [],
  45058. tooComplexToFollowFunctions: false,
  45059. hintsValid: true
  45060. };
  45061. if (fpgm) {
  45062. sanitizeTTProgram(fpgm, ttContext);
  45063. }
  45064. if (prep) {
  45065. sanitizeTTProgram(prep, ttContext);
  45066. }
  45067. if (fpgm) {
  45068. checkInvalidFunctions(ttContext, maxFunctionDefs);
  45069. }
  45070. if (cvt && cvt.length & 1) {
  45071. var cvtData = new Uint8Array(cvt.length + 1);
  45072. cvtData.set(cvt.data);
  45073. cvt.data = cvtData;
  45074. }
  45075. return ttContext.hintsValid;
  45076. }
  45077. // The following steps modify the original font data, making copy
  45078. font = new Stream(new Uint8Array(font.getBytes()));
  45079. var VALID_TABLES = [
  45080. 'OS/2',
  45081. 'cmap',
  45082. 'head',
  45083. 'hhea',
  45084. 'hmtx',
  45085. 'maxp',
  45086. 'name',
  45087. 'post',
  45088. 'loca',
  45089. 'glyf',
  45090. 'fpgm',
  45091. 'prep',
  45092. 'cvt ',
  45093. 'CFF '
  45094. ];
  45095. var header = readOpenTypeHeader(font);
  45096. var numTables = header.numTables;
  45097. var cff, cffFile;
  45098. var tables = Object.create(null);
  45099. tables['OS/2'] = null;
  45100. tables['cmap'] = null;
  45101. tables['head'] = null;
  45102. tables['hhea'] = null;
  45103. tables['hmtx'] = null;
  45104. tables['maxp'] = null;
  45105. tables['name'] = null;
  45106. tables['post'] = null;
  45107. var table;
  45108. for (var i = 0; i < numTables; i++) {
  45109. table = readTableEntry(font);
  45110. if (VALID_TABLES.indexOf(table.tag) < 0) {
  45111. continue;
  45112. }
  45113. // skipping table if it's not a required or optional table
  45114. if (table.length === 0) {
  45115. continue;
  45116. }
  45117. // skipping empty tables
  45118. tables[table.tag] = table;
  45119. }
  45120. var isTrueType = !tables['CFF '];
  45121. if (!isTrueType) {
  45122. // OpenType font
  45123. if (header.version === 'OTTO' && properties.type !== 'CIDFontType2' || !tables['head'] || !tables['hhea'] || !tables['maxp'] || !tables['post']) {
  45124. // no major tables: throwing everything at CFFFont
  45125. cffFile = new Stream(tables['CFF '].data);
  45126. cff = new CFFFont(cffFile, properties);
  45127. adjustWidths(properties);
  45128. return this.convert(name, cff, properties);
  45129. }
  45130. delete tables['glyf'];
  45131. delete tables['loca'];
  45132. delete tables['fpgm'];
  45133. delete tables['prep'];
  45134. delete tables['cvt '];
  45135. this.isOpenType = true;
  45136. } else {
  45137. if (!tables['loca']) {
  45138. error('Required "loca" table is not found');
  45139. }
  45140. if (!tables['glyf']) {
  45141. warn('Required "glyf" table is not found -- trying to recover.');
  45142. // Note: We use `sanitizeGlyphLocations` to add dummy glyf data below.
  45143. tables['glyf'] = {
  45144. tag: 'glyf',
  45145. data: new Uint8Array(0)
  45146. };
  45147. }
  45148. this.isOpenType = false;
  45149. }
  45150. if (!tables['maxp']) {
  45151. error('Required "maxp" table is not found');
  45152. }
  45153. font.pos = (font.start || 0) + tables['maxp'].offset;
  45154. var version = font.getInt32();
  45155. var numGlyphs = font.getUint16();
  45156. var maxFunctionDefs = 0;
  45157. if (version >= 0x00010000 && tables['maxp'].length >= 22) {
  45158. // maxZones can be invalid
  45159. font.pos += 8;
  45160. var maxZones = font.getUint16();
  45161. if (maxZones > 2) {
  45162. // reset to 2 if font has invalid maxZones
  45163. tables['maxp'].data[14] = 0;
  45164. tables['maxp'].data[15] = 2;
  45165. }
  45166. font.pos += 4;
  45167. maxFunctionDefs = font.getUint16();
  45168. }
  45169. var dupFirstEntry = false;
  45170. if (properties.type === 'CIDFontType2' && properties.toUnicode && properties.toUnicode.get(0) > '\u0000') {
  45171. // oracle's defect (see 3427), duplicating first entry
  45172. dupFirstEntry = true;
  45173. numGlyphs++;
  45174. tables['maxp'].data[4] = numGlyphs >> 8;
  45175. tables['maxp'].data[5] = numGlyphs & 255;
  45176. }
  45177. var hintsValid = sanitizeTTPrograms(tables['fpgm'], tables['prep'], tables['cvt '], maxFunctionDefs);
  45178. if (!hintsValid) {
  45179. delete tables['fpgm'];
  45180. delete tables['prep'];
  45181. delete tables['cvt '];
  45182. }
  45183. // Ensure the hmtx table contains the advance width and
  45184. // sidebearings information for numGlyphs in the maxp table
  45185. sanitizeMetrics(font, tables['hhea'], tables['hmtx'], numGlyphs);
  45186. if (!tables['head']) {
  45187. error('Required "head" table is not found');
  45188. }
  45189. sanitizeHead(tables['head'], numGlyphs, isTrueType ? tables['loca'].length : 0);
  45190. var missingGlyphs = Object.create(null);
  45191. if (isTrueType) {
  45192. var isGlyphLocationsLong = int16(tables['head'].data[50], tables['head'].data[51]);
  45193. missingGlyphs = sanitizeGlyphLocations(tables['loca'], tables['glyf'], numGlyphs, isGlyphLocationsLong, hintsValid, dupFirstEntry);
  45194. }
  45195. if (!tables['hhea']) {
  45196. error('Required "hhea" table is not found');
  45197. }
  45198. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  45199. // Sometimes it's 0. That needs to be fixed
  45200. if (tables['hhea'].data[10] === 0 && tables['hhea'].data[11] === 0) {
  45201. tables['hhea'].data[10] = 0xFF;
  45202. tables['hhea'].data[11] = 0xFF;
  45203. }
  45204. // Extract some more font properties from the OpenType head and
  45205. // hhea tables; yMin and descent value are always negative.
  45206. var metricsOverride = {
  45207. unitsPerEm: int16(tables['head'].data[18], tables['head'].data[19]),
  45208. yMax: int16(tables['head'].data[42], tables['head'].data[43]),
  45209. yMin: signedInt16(tables['head'].data[38], tables['head'].data[39]),
  45210. ascent: int16(tables['hhea'].data[4], tables['hhea'].data[5]),
  45211. descent: signedInt16(tables['hhea'].data[6], tables['hhea'].data[7])
  45212. };
  45213. // PDF FontDescriptor metrics lie -- using data from actual font.
  45214. this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
  45215. this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
  45216. // The 'post' table has glyphs names.
  45217. if (tables['post']) {
  45218. var valid = readPostScriptTable(tables['post'], properties, numGlyphs);
  45219. if (!valid) {
  45220. tables['post'] = null;
  45221. }
  45222. }
  45223. var charCodeToGlyphId = [], charCode;
  45224. var toUnicode = properties.toUnicode, widths = properties.widths;
  45225. var skipToUnicode = toUnicode instanceof IdentityToUnicodeMap || toUnicode.length === 0x10000;
  45226. // Helper function to try to skip mapping of empty glyphs.
  45227. // Note: In some cases, just relying on the glyph data doesn't work,
  45228. // hence we also use a few heuristics to fix various PDF files.
  45229. function hasGlyph(glyphId, charCode, widthCode) {
  45230. if (!missingGlyphs[glyphId]) {
  45231. return true;
  45232. }
  45233. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  45234. return true;
  45235. }
  45236. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  45237. return true;
  45238. }
  45239. return false;
  45240. }
  45241. if (properties.type === 'CIDFontType2') {
  45242. var cidToGidMap = properties.cidToGidMap || [];
  45243. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  45244. properties.cMap.forEach(function (charCode, cid) {
  45245. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  45246. var glyphId = -1;
  45247. if (isCidToGidMapEmpty) {
  45248. glyphId = cid;
  45249. } else if (cidToGidMap[cid] !== undefined) {
  45250. glyphId = cidToGidMap[cid];
  45251. }
  45252. if (glyphId >= 0 && glyphId < numGlyphs && hasGlyph(glyphId, charCode, cid)) {
  45253. charCodeToGlyphId[charCode] = glyphId;
  45254. }
  45255. });
  45256. if (dupFirstEntry && (isCidToGidMapEmpty || !charCodeToGlyphId[0])) {
  45257. // We don't duplicate the first entry in the `charCodeToGlyphId` map
  45258. // if the font has a `CIDToGIDMap` which has already mapped the first
  45259. // entry to a non-zero `glyphId` (fixes issue7544.pdf).
  45260. charCodeToGlyphId[0] = numGlyphs - 1;
  45261. }
  45262. } else {
  45263. // Most of the following logic in this code branch is based on the
  45264. // 9.6.6.4 of the PDF spec.
  45265. var cmapTable = readCmapTable(tables['cmap'], font, this.isSymbolicFont, properties.hasEncoding);
  45266. var cmapPlatformId = cmapTable.platformId;
  45267. var cmapEncodingId = cmapTable.encodingId;
  45268. var cmapMappings = cmapTable.mappings;
  45269. var cmapMappingsLength = cmapMappings.length;
  45270. // The spec seems to imply that if the font is symbolic the encoding
  45271. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  45272. // where the the font is symbolic and it has an encoding.
  45273. if (properties.hasEncoding && (cmapPlatformId === 3 && cmapEncodingId === 1 || cmapPlatformId === 1 && cmapEncodingId === 0) || cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  45274. !!getEncoding(properties.baseEncodingName)) {
  45275. // Temporary hack
  45276. // When no preferred cmap table was found and |baseEncodingName| is
  45277. // one of the predefined encodings, we seem to obtain a better
  45278. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  45279. // TODO: Note that this is a hack which should be removed as soon as
  45280. // we have proper support for more exotic cmap tables.
  45281. var baseEncoding = [];
  45282. if (properties.baseEncodingName === 'MacRomanEncoding' || properties.baseEncodingName === 'WinAnsiEncoding') {
  45283. baseEncoding = getEncoding(properties.baseEncodingName);
  45284. }
  45285. var glyphsUnicodeMap = getGlyphsUnicode();
  45286. for (charCode = 0; charCode < 256; charCode++) {
  45287. var glyphName, standardGlyphName;
  45288. if (this.differences && charCode in this.differences) {
  45289. glyphName = this.differences[charCode];
  45290. } else if (charCode in baseEncoding && baseEncoding[charCode] !== '') {
  45291. glyphName = baseEncoding[charCode];
  45292. } else {
  45293. glyphName = StandardEncoding[charCode];
  45294. }
  45295. if (!glyphName) {
  45296. continue;
  45297. }
  45298. // Ensure that non-standard glyph names are resolved to valid ones.
  45299. standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
  45300. var unicodeOrCharCode, isUnicode = false;
  45301. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  45302. unicodeOrCharCode = glyphsUnicodeMap[standardGlyphName];
  45303. isUnicode = true;
  45304. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  45305. // TODO: the encoding needs to be updated with mac os table.
  45306. unicodeOrCharCode = MacRomanEncoding.indexOf(standardGlyphName);
  45307. }
  45308. var found = false;
  45309. for (i = 0; i < cmapMappingsLength; ++i) {
  45310. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  45311. continue;
  45312. }
  45313. var code = isUnicode ? charCode : unicodeOrCharCode;
  45314. if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
  45315. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  45316. found = true;
  45317. break;
  45318. }
  45319. }
  45320. if (!found && properties.glyphNames) {
  45321. // Try to map using the post table.
  45322. var glyphId = properties.glyphNames.indexOf(glyphName);
  45323. // The post table ought to use the same kind of glyph names as the
  45324. // `differences` array, but check the standard ones as a fallback.
  45325. if (glyphId === -1 && standardGlyphName !== glyphName) {
  45326. glyphId = properties.glyphNames.indexOf(standardGlyphName);
  45327. }
  45328. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  45329. charCodeToGlyphId[charCode] = glyphId;
  45330. found = true;
  45331. }
  45332. }
  45333. if (!found) {
  45334. charCodeToGlyphId[charCode] = 0;
  45335. }
  45336. }
  45337. } else // notdef
  45338. if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  45339. // Default Unicode semantics, use the charcodes as is.
  45340. for (i = 0; i < cmapMappingsLength; ++i) {
  45341. charCodeToGlyphId[cmapMappings[i].charCode] = cmapMappings[i].glyphId;
  45342. }
  45343. } else {
  45344. // For (3, 0) cmap tables:
  45345. // The charcode key being stored in charCodeToGlyphId is the lower
  45346. // byte of the two-byte charcodes of the cmap table since according to
  45347. // the spec: 'each byte from the string shall be prepended with the
  45348. // high byte of the range [of charcodes in the cmap table], to form
  45349. // a two-byte character, which shall be used to select the
  45350. // associated glyph description from the subtable'.
  45351. //
  45352. // For (1, 0) cmap tables:
  45353. // 'single bytes from the string shall be used to look up the
  45354. // associated glyph descriptions from the subtable'. This means
  45355. // charcodes in the cmap will be single bytes, so no-op since
  45356. // glyph.charCode & 0xFF === glyph.charCode
  45357. for (i = 0; i < cmapMappingsLength; ++i) {
  45358. charCode = cmapMappings[i].charCode & 0xFF;
  45359. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  45360. }
  45361. }
  45362. }
  45363. if (charCodeToGlyphId.length === 0) {
  45364. // defines at least one glyph
  45365. charCodeToGlyphId[0] = 0;
  45366. }
  45367. // Converting glyphs and ids into font's cmap table
  45368. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  45369. this.toFontChar = newMapping.toFontChar;
  45370. tables['cmap'] = {
  45371. tag: 'cmap',
  45372. data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphs)
  45373. };
  45374. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  45375. tables['OS/2'] = {
  45376. tag: 'OS/2',
  45377. data: createOS2Table(properties, newMapping.charCodeToGlyphId, metricsOverride)
  45378. };
  45379. }
  45380. // Rewrite the 'post' table if needed
  45381. if (!tables['post']) {
  45382. tables['post'] = {
  45383. tag: 'post',
  45384. data: createPostTable(properties)
  45385. };
  45386. }
  45387. if (!isTrueType) {
  45388. try {
  45389. // Trying to repair CFF file
  45390. cffFile = new Stream(tables['CFF '].data);
  45391. var parser = new CFFParser(cffFile, properties, SEAC_ANALYSIS_ENABLED);
  45392. cff = parser.parse();
  45393. var compiler = new CFFCompiler(cff);
  45394. tables['CFF '].data = compiler.compile();
  45395. } catch (e) {
  45396. warn('Failed to compile font ' + properties.loadedName);
  45397. }
  45398. }
  45399. // Re-creating 'name' table
  45400. if (!tables['name']) {
  45401. tables['name'] = {
  45402. tag: 'name',
  45403. data: createNameTable(this.name)
  45404. };
  45405. } else {
  45406. // ... using existing 'name' table as prototype
  45407. var namePrototype = readNameTable(tables['name']);
  45408. tables['name'].data = createNameTable(name, namePrototype);
  45409. }
  45410. var builder = new OpenTypeFileBuilder(header.version);
  45411. for (var tableTag in tables) {
  45412. builder.addTable(tableTag, tables[tableTag].data);
  45413. }
  45414. return builder.toArray();
  45415. },
  45416. convert: function Font_convert(fontName, font, properties) {
  45417. // TODO: Check the charstring widths to determine this.
  45418. properties.fixedPitch = false;
  45419. if (properties.builtInEncoding) {
  45420. // For Type1 fonts that do not include either `ToUnicode` or `Encoding`
  45421. // data, attempt to use the `builtInEncoding` to improve text selection.
  45422. adjustToUnicode(properties, properties.builtInEncoding);
  45423. }
  45424. var mapping = font.getGlyphMapping(properties);
  45425. var newMapping = adjustMapping(mapping, properties);
  45426. this.toFontChar = newMapping.toFontChar;
  45427. var numGlyphs = font.numGlyphs;
  45428. function getCharCodes(charCodeToGlyphId, glyphId) {
  45429. var charCodes = null;
  45430. for (var charCode in charCodeToGlyphId) {
  45431. if (glyphId === charCodeToGlyphId[charCode]) {
  45432. if (!charCodes) {
  45433. charCodes = [];
  45434. }
  45435. charCodes.push(charCode | 0);
  45436. }
  45437. }
  45438. return charCodes;
  45439. }
  45440. function createCharCode(charCodeToGlyphId, glyphId) {
  45441. for (var charCode in charCodeToGlyphId) {
  45442. if (glyphId === charCodeToGlyphId[charCode]) {
  45443. return charCode | 0;
  45444. }
  45445. }
  45446. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] = glyphId;
  45447. return newMapping.nextAvailableFontCharCode++;
  45448. }
  45449. var seacs = font.seacs;
  45450. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  45451. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  45452. var charset = font.getCharset();
  45453. var seacMap = Object.create(null);
  45454. for (var glyphId in seacs) {
  45455. glyphId |= 0;
  45456. var seac = seacs[glyphId];
  45457. var baseGlyphName = StandardEncoding[seac[2]];
  45458. var accentGlyphName = StandardEncoding[seac[3]];
  45459. var baseGlyphId = charset.indexOf(baseGlyphName);
  45460. var accentGlyphId = charset.indexOf(accentGlyphName);
  45461. if (baseGlyphId < 0 || accentGlyphId < 0) {
  45462. continue;
  45463. }
  45464. var accentOffset = {
  45465. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  45466. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  45467. };
  45468. var charCodes = getCharCodes(mapping, glyphId);
  45469. if (!charCodes) {
  45470. // There's no point in mapping it if the char code was never mapped
  45471. // to begin with.
  45472. continue;
  45473. }
  45474. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  45475. var charCode = charCodes[i];
  45476. // Find a fontCharCode that maps to the base and accent glyphs.
  45477. // If one doesn't exists, create it.
  45478. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  45479. var baseFontCharCode = createCharCode(charCodeToGlyphId, baseGlyphId);
  45480. var accentFontCharCode = createCharCode(charCodeToGlyphId, accentGlyphId);
  45481. seacMap[charCode] = {
  45482. baseFontCharCode: baseFontCharCode,
  45483. accentFontCharCode: accentFontCharCode,
  45484. accentOffset: accentOffset
  45485. };
  45486. }
  45487. }
  45488. properties.seacMap = seacMap;
  45489. }
  45490. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  45491. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  45492. // PostScript Font Program
  45493. builder.addTable('CFF ', font.data);
  45494. // OS/2 and Windows Specific metrics
  45495. builder.addTable('OS/2', createOS2Table(properties, newMapping.charCodeToGlyphId));
  45496. // Character to glyphs mapping
  45497. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId, numGlyphs));
  45498. // Font header
  45499. builder.addTable('head', '\x00\x01\x00\x00' + // Version number
  45500. '\x00\x00\x10\x00' + // fontRevision
  45501. '\x00\x00\x00\x00' + // checksumAdjustement
  45502. '\x5F\x0F\x3C\xF5' + // magicNumber
  45503. '\x00\x00' + // Flags
  45504. safeString16(unitsPerEm) + // unitsPerEM
  45505. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  45506. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  45507. '\x00\x00' + // xMin
  45508. safeString16(properties.descent) + // yMin
  45509. '\x0F\xFF' + // xMax
  45510. safeString16(properties.ascent) + // yMax
  45511. string16(properties.italicAngle ? 2 : 0) + // macStyle
  45512. '\x00\x11' + // lowestRecPPEM
  45513. '\x00\x00' + // fontDirectionHint
  45514. '\x00\x00' + // indexToLocFormat
  45515. '\x00\x00');
  45516. // glyphDataFormat
  45517. // Horizontal header
  45518. builder.addTable('hhea', '\x00\x01\x00\x00' + // Version number
  45519. safeString16(properties.ascent) + // Typographic Ascent
  45520. safeString16(properties.descent) + // Typographic Descent
  45521. '\x00\x00' + // Line Gap
  45522. '\xFF\xFF' + // advanceWidthMax
  45523. '\x00\x00' + // minLeftSidebearing
  45524. '\x00\x00' + // minRightSidebearing
  45525. '\x00\x00' + // xMaxExtent
  45526. safeString16(properties.capHeight) + // caretSlopeRise
  45527. safeString16(Math.tan(properties.italicAngle) * properties.xHeight) + // caretSlopeRun
  45528. '\x00\x00' + // caretOffset
  45529. '\x00\x00' + // -reserved-
  45530. '\x00\x00' + // -reserved-
  45531. '\x00\x00' + // -reserved-
  45532. '\x00\x00' + // -reserved-
  45533. '\x00\x00' + // metricDataFormat
  45534. string16(numGlyphs));
  45535. // Number of HMetrics
  45536. // Horizontal metrics
  45537. builder.addTable('hmtx', function fontFieldsHmtx() {
  45538. var charstrings = font.charstrings;
  45539. var cffWidths = font.cff ? font.cff.widths : null;
  45540. var hmtx = '\x00\x00\x00\x00';
  45541. // Fake .notdef
  45542. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  45543. var width = 0;
  45544. if (charstrings) {
  45545. var charstring = charstrings[i - 1];
  45546. width = 'width' in charstring ? charstring.width : 0;
  45547. } else if (cffWidths) {
  45548. width = Math.ceil(cffWidths[i] || 0);
  45549. }
  45550. hmtx += string16(width) + string16(0);
  45551. }
  45552. return hmtx;
  45553. }());
  45554. // Maximum profile
  45555. builder.addTable('maxp', '\x00\x00\x50\x00' + // Version number
  45556. string16(numGlyphs));
  45557. // Num of glyphs
  45558. // Naming tables
  45559. builder.addTable('name', createNameTable(fontName));
  45560. // PostScript information
  45561. builder.addTable('post', createPostTable(properties));
  45562. return builder.toArray();
  45563. },
  45564. get spaceWidth() {
  45565. if ('_shadowWidth' in this) {
  45566. return this._shadowWidth;
  45567. }
  45568. // trying to estimate space character width
  45569. var possibleSpaceReplacements = [
  45570. 'space',
  45571. 'minus',
  45572. 'one',
  45573. 'i',
  45574. 'I'
  45575. ];
  45576. var width;
  45577. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  45578. var glyphName = possibleSpaceReplacements[i];
  45579. // if possible, getting width by glyph name
  45580. if (glyphName in this.widths) {
  45581. width = this.widths[glyphName];
  45582. break;
  45583. }
  45584. var glyphsUnicodeMap = getGlyphsUnicode();
  45585. var glyphUnicode = glyphsUnicodeMap[glyphName];
  45586. // finding the charcode via unicodeToCID map
  45587. var charcode = 0;
  45588. if (this.composite) {
  45589. if (this.cMap.contains(glyphUnicode)) {
  45590. charcode = this.cMap.lookup(glyphUnicode);
  45591. }
  45592. }
  45593. // ... via toUnicode map
  45594. if (!charcode && this.toUnicode) {
  45595. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  45596. }
  45597. // setting it to unicode if negative or undefined
  45598. if (charcode <= 0) {
  45599. charcode = glyphUnicode;
  45600. }
  45601. // trying to get width via charcode
  45602. width = this.widths[charcode];
  45603. if (width) {
  45604. break;
  45605. }
  45606. }
  45607. // the non-zero width found
  45608. width = width || this.defaultWidth;
  45609. // Do not shadow the property here. See discussion:
  45610. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  45611. this._shadowWidth = width;
  45612. return width;
  45613. },
  45614. charToGlyph: function Font_charToGlyph(charcode, isSpace) {
  45615. var fontCharCode, width, operatorListId;
  45616. var widthCode = charcode;
  45617. if (this.cMap && this.cMap.contains(charcode)) {
  45618. widthCode = this.cMap.lookup(charcode);
  45619. }
  45620. width = this.widths[widthCode];
  45621. width = isNum(width) ? width : this.defaultWidth;
  45622. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  45623. var unicode = this.toUnicode.get(charcode) || charcode;
  45624. if (typeof unicode === 'number') {
  45625. unicode = String.fromCharCode(unicode);
  45626. }
  45627. var isInFont = charcode in this.toFontChar;
  45628. // First try the toFontChar map, if it's not there then try falling
  45629. // back to the char code.
  45630. fontCharCode = this.toFontChar[charcode] || charcode;
  45631. if (this.missingFile) {
  45632. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  45633. }
  45634. if (this.isType3Font) {
  45635. // Font char code in this case is actually a glyph name.
  45636. operatorListId = fontCharCode;
  45637. }
  45638. var accent = null;
  45639. if (this.seacMap && this.seacMap[charcode]) {
  45640. isInFont = true;
  45641. var seac = this.seacMap[charcode];
  45642. fontCharCode = seac.baseFontCharCode;
  45643. accent = {
  45644. fontChar: String.fromCharCode(seac.accentFontCharCode),
  45645. offset: seac.accentOffset
  45646. };
  45647. }
  45648. var fontChar = String.fromCharCode(fontCharCode);
  45649. var glyph = this.glyphCache[charcode];
  45650. if (!glyph || !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont)) {
  45651. glyph = new Glyph(fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont);
  45652. this.glyphCache[charcode] = glyph;
  45653. }
  45654. return glyph;
  45655. },
  45656. charsToGlyphs: function Font_charsToGlyphs(chars) {
  45657. var charsCache = this.charsCache;
  45658. var glyphs, glyph, charcode;
  45659. // if we translated this string before, just grab it from the cache
  45660. if (charsCache) {
  45661. glyphs = charsCache[chars];
  45662. if (glyphs) {
  45663. return glyphs;
  45664. }
  45665. }
  45666. // lazily create the translation cache
  45667. if (!charsCache) {
  45668. charsCache = this.charsCache = Object.create(null);
  45669. }
  45670. glyphs = [];
  45671. var charsCacheKey = chars;
  45672. var i = 0, ii;
  45673. if (this.cMap) {
  45674. // composite fonts have multi-byte strings convert the string from
  45675. // single-byte to multi-byte
  45676. var c = Object.create(null);
  45677. while (i < chars.length) {
  45678. this.cMap.readCharCode(chars, i, c);
  45679. charcode = c.charcode;
  45680. var length = c.length;
  45681. i += length;
  45682. // Space is char with code 0x20 and length 1 in multiple-byte codes.
  45683. var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
  45684. glyph = this.charToGlyph(charcode, isSpace);
  45685. glyphs.push(glyph);
  45686. }
  45687. } else {
  45688. for (i = 0, ii = chars.length; i < ii; ++i) {
  45689. charcode = chars.charCodeAt(i);
  45690. glyph = this.charToGlyph(charcode, charcode === 0x20);
  45691. glyphs.push(glyph);
  45692. }
  45693. }
  45694. // Enter the translated string into the cache
  45695. return charsCache[charsCacheKey] = glyphs;
  45696. }
  45697. };
  45698. return Font;
  45699. }();
  45700. var ErrorFont = function ErrorFontClosure() {
  45701. function ErrorFont(error) {
  45702. this.error = error;
  45703. this.loadedName = 'g_font_error';
  45704. this.loading = false;
  45705. }
  45706. ErrorFont.prototype = {
  45707. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  45708. return [];
  45709. },
  45710. exportData: function ErrorFont_exportData() {
  45711. return { error: this.error };
  45712. }
  45713. };
  45714. return ErrorFont;
  45715. }();
  45716. /**
  45717. * Shared logic for building a char code to glyph id mapping for Type1 and
  45718. * simple CFF fonts. See section 9.6.6.2 of the spec.
  45719. * @param {Object} properties Font properties object.
  45720. * @param {Object} builtInEncoding The encoding contained within the actual font
  45721. * data.
  45722. * @param {Array} glyphNames Array of glyph names where the index is the
  45723. * glyph ID.
  45724. * @returns {Object} A char code to glyph ID map.
  45725. */
  45726. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  45727. var charCodeToGlyphId = Object.create(null);
  45728. var glyphId, charCode, baseEncoding;
  45729. if (properties.baseEncodingName) {
  45730. // If a valid base encoding name was used, the mapping is initialized with
  45731. // that.
  45732. baseEncoding = getEncoding(properties.baseEncodingName);
  45733. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  45734. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  45735. if (glyphId >= 0) {
  45736. charCodeToGlyphId[charCode] = glyphId;
  45737. } else {
  45738. charCodeToGlyphId[charCode] = 0;
  45739. }
  45740. }
  45741. } else // notdef
  45742. if (!!(properties.flags & FontFlags.Symbolic)) {
  45743. // For a symbolic font the encoding should be the fonts built-in
  45744. // encoding.
  45745. for (charCode in builtInEncoding) {
  45746. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  45747. }
  45748. } else {
  45749. // For non-symbolic fonts that don't have a base encoding the standard
  45750. // encoding should be used.
  45751. baseEncoding = StandardEncoding;
  45752. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  45753. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  45754. if (glyphId >= 0) {
  45755. charCodeToGlyphId[charCode] = glyphId;
  45756. } else {
  45757. charCodeToGlyphId[charCode] = 0;
  45758. }
  45759. }
  45760. }
  45761. // notdef
  45762. // Lastly, merge in the differences.
  45763. var differences = properties.differences, glyphsUnicodeMap;
  45764. if (differences) {
  45765. for (charCode in differences) {
  45766. var glyphName = differences[charCode];
  45767. glyphId = glyphNames.indexOf(glyphName);
  45768. if (glyphId === -1) {
  45769. if (!glyphsUnicodeMap) {
  45770. glyphsUnicodeMap = getGlyphsUnicode();
  45771. }
  45772. var standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
  45773. if (standardGlyphName !== glyphName) {
  45774. glyphId = glyphNames.indexOf(standardGlyphName);
  45775. }
  45776. }
  45777. if (glyphId >= 0) {
  45778. charCodeToGlyphId[charCode] = glyphId;
  45779. } else {
  45780. charCodeToGlyphId[charCode] = 0;
  45781. }
  45782. }
  45783. }
  45784. // notdef
  45785. return charCodeToGlyphId;
  45786. }
  45787. // Type1Font is also a CIDFontType0.
  45788. var Type1Font = function Type1FontClosure() {
  45789. function findBlock(streamBytes, signature, startIndex) {
  45790. var streamBytesLength = streamBytes.length;
  45791. var signatureLength = signature.length;
  45792. var scanLength = streamBytesLength - signatureLength;
  45793. var i = startIndex, j, found = false;
  45794. while (i < scanLength) {
  45795. j = 0;
  45796. while (j < signatureLength && streamBytes[i + j] === signature[j]) {
  45797. j++;
  45798. }
  45799. if (j >= signatureLength) {
  45800. // `signature` found, skip over whitespace.
  45801. i += j;
  45802. while (i < streamBytesLength && isSpace(streamBytes[i])) {
  45803. i++;
  45804. }
  45805. found = true;
  45806. break;
  45807. }
  45808. i++;
  45809. }
  45810. return {
  45811. found: found,
  45812. length: i
  45813. };
  45814. }
  45815. function getHeaderBlock(stream, suggestedLength) {
  45816. var EEXEC_SIGNATURE = [
  45817. 0x65,
  45818. 0x65,
  45819. 0x78,
  45820. 0x65,
  45821. 0x63
  45822. ];
  45823. var streamStartPos = stream.pos;
  45824. // Save the initial stream position.
  45825. var headerBytes, headerBytesLength, block;
  45826. try {
  45827. headerBytes = stream.getBytes(suggestedLength);
  45828. headerBytesLength = headerBytes.length;
  45829. } catch (ex) {
  45830. if (ex instanceof MissingDataException) {
  45831. throw ex;
  45832. }
  45833. }
  45834. // Ignore errors if the `suggestedLength` is huge enough that a Uint8Array
  45835. // cannot hold the result of `getBytes`, and fallback to simply checking
  45836. // the entire stream (fixes issue3928.pdf).
  45837. if (headerBytesLength === suggestedLength) {
  45838. // Most of the time `suggestedLength` is correct, so to speed things up we
  45839. // initially only check the last few bytes to see if the header was found.
  45840. // Otherwise we (potentially) check the entire stream to prevent errors in
  45841. // `Type1Parser` (fixes issue5686.pdf).
  45842. block = findBlock(headerBytes, EEXEC_SIGNATURE, suggestedLength - 2 * EEXEC_SIGNATURE.length);
  45843. if (block.found && block.length === suggestedLength) {
  45844. return {
  45845. stream: new Stream(headerBytes),
  45846. length: suggestedLength
  45847. };
  45848. }
  45849. }
  45850. warn('Invalid "Length1" property in Type1 font -- trying to recover.');
  45851. stream.pos = streamStartPos;
  45852. // Reset the stream position.
  45853. var SCAN_BLOCK_LENGTH = 2048;
  45854. var actualLength;
  45855. while (true) {
  45856. var scanBytes = stream.peekBytes(SCAN_BLOCK_LENGTH);
  45857. block = findBlock(scanBytes, EEXEC_SIGNATURE, 0);
  45858. if (block.length === 0) {
  45859. break;
  45860. }
  45861. stream.pos += block.length;
  45862. // Update the stream position.
  45863. if (block.found) {
  45864. actualLength = stream.pos - streamStartPos;
  45865. break;
  45866. }
  45867. }
  45868. stream.pos = streamStartPos;
  45869. // Reset the stream position.
  45870. if (actualLength) {
  45871. return {
  45872. stream: new Stream(stream.getBytes(actualLength)),
  45873. length: actualLength
  45874. };
  45875. }
  45876. warn('Unable to recover "Length1" property in Type1 font -- using as is.');
  45877. return {
  45878. stream: new Stream(stream.getBytes(suggestedLength)),
  45879. length: suggestedLength
  45880. };
  45881. }
  45882. function getEexecBlock(stream, suggestedLength) {
  45883. // We should ideally parse the eexec block to ensure that `suggestedLength`
  45884. // is correct, so we don't truncate the block data if it's too small.
  45885. // However, this would also require checking if the fixed-content portion
  45886. // exists (using the 'Length3' property), and ensuring that it's valid.
  45887. //
  45888. // Given that `suggestedLength` almost always is correct, all the validation
  45889. // would require a great deal of unnecessary parsing for most fonts.
  45890. // To save time, we always fetch the entire stream instead, which also avoid
  45891. // issues if `suggestedLength` is huge (see comment in `getHeaderBlock`).
  45892. //
  45893. // NOTE: This means that the function can include the fixed-content portion
  45894. // in the returned eexec block. In practice this does *not* seem to matter,
  45895. // since `Type1Parser_extractFontProgram` will skip over any non-commands.
  45896. var eexecBytes = stream.getBytes();
  45897. return {
  45898. stream: new Stream(eexecBytes),
  45899. length: eexecBytes.length
  45900. };
  45901. }
  45902. function Type1Font(name, file, properties) {
  45903. // Some bad generators embed pfb file as is, we have to strip 6-byte header.
  45904. // Also, length1 and length2 might be off by 6 bytes as well.
  45905. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  45906. var PFB_HEADER_SIZE = 6;
  45907. var headerBlockLength = properties.length1;
  45908. var eexecBlockLength = properties.length2;
  45909. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  45910. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  45911. if (pfbHeaderPresent) {
  45912. file.skip(PFB_HEADER_SIZE);
  45913. headerBlockLength = pfbHeader[5] << 24 | pfbHeader[4] << 16 | pfbHeader[3] << 8 | pfbHeader[2];
  45914. }
  45915. // Get the data block containing glyphs and subrs information
  45916. var headerBlock = getHeaderBlock(file, headerBlockLength);
  45917. headerBlockLength = headerBlock.length;
  45918. var headerBlockParser = new Type1Parser(headerBlock.stream, false, SEAC_ANALYSIS_ENABLED);
  45919. headerBlockParser.extractFontHeader(properties);
  45920. if (pfbHeaderPresent) {
  45921. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  45922. eexecBlockLength = pfbHeader[5] << 24 | pfbHeader[4] << 16 | pfbHeader[3] << 8 | pfbHeader[2];
  45923. }
  45924. // Decrypt the data blocks and retrieve it's content
  45925. var eexecBlock = getEexecBlock(file, eexecBlockLength);
  45926. eexecBlockLength = eexecBlock.length;
  45927. var eexecBlockParser = new Type1Parser(eexecBlock.stream, true, SEAC_ANALYSIS_ENABLED);
  45928. var data = eexecBlockParser.extractFontProgram();
  45929. for (var info in data.properties) {
  45930. properties[info] = data.properties[info];
  45931. }
  45932. var charstrings = data.charstrings;
  45933. var type2Charstrings = this.getType2Charstrings(charstrings);
  45934. var subrs = this.getType2Subrs(data.subrs);
  45935. this.charstrings = charstrings;
  45936. this.data = this.wrap(name, type2Charstrings, this.charstrings, subrs, properties);
  45937. this.seacs = this.getSeacs(data.charstrings);
  45938. }
  45939. Type1Font.prototype = {
  45940. get numGlyphs() {
  45941. return this.charstrings.length + 1;
  45942. },
  45943. getCharset: function Type1Font_getCharset() {
  45944. var charset = ['.notdef'];
  45945. var charstrings = this.charstrings;
  45946. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  45947. charset.push(charstrings[glyphId].glyphName);
  45948. }
  45949. return charset;
  45950. },
  45951. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  45952. var charstrings = this.charstrings;
  45953. var glyphNames = ['.notdef'], glyphId;
  45954. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  45955. glyphNames.push(charstrings[glyphId].glyphName);
  45956. }
  45957. var encoding = properties.builtInEncoding;
  45958. if (encoding) {
  45959. var builtInEncoding = Object.create(null);
  45960. for (var charCode in encoding) {
  45961. glyphId = glyphNames.indexOf(encoding[charCode]);
  45962. if (glyphId >= 0) {
  45963. builtInEncoding[charCode] = glyphId;
  45964. }
  45965. }
  45966. }
  45967. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  45968. },
  45969. getSeacs: function Type1Font_getSeacs(charstrings) {
  45970. var i, ii;
  45971. var seacMap = [];
  45972. for (i = 0, ii = charstrings.length; i < ii; i++) {
  45973. var charstring = charstrings[i];
  45974. if (charstring.seac) {
  45975. // Offset by 1 for .notdef
  45976. seacMap[i + 1] = charstring.seac;
  45977. }
  45978. }
  45979. return seacMap;
  45980. },
  45981. getType2Charstrings: function Type1Font_getType2Charstrings(type1Charstrings) {
  45982. var type2Charstrings = [];
  45983. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  45984. type2Charstrings.push(type1Charstrings[i].charstring);
  45985. }
  45986. return type2Charstrings;
  45987. },
  45988. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  45989. var bias = 0;
  45990. var count = type1Subrs.length;
  45991. if (count < 1133) {
  45992. bias = 107;
  45993. } else if (count < 33769) {
  45994. bias = 1131;
  45995. } else {
  45996. bias = 32768;
  45997. }
  45998. // Add a bunch of empty subrs to deal with the Type2 bias
  45999. var type2Subrs = [];
  46000. var i;
  46001. for (i = 0; i < bias; i++) {
  46002. type2Subrs.push([0x0B]);
  46003. }
  46004. for (i = 0; i < count; i++) {
  46005. type2Subrs.push(type1Subrs[i]);
  46006. }
  46007. return type2Subrs;
  46008. },
  46009. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  46010. var cff = new CFF();
  46011. cff.header = new CFFHeader(1, 0, 4, 4);
  46012. cff.names = [name];
  46013. var topDict = new CFFTopDict();
  46014. // CFF strings IDs 0...390 are predefined names, so refering
  46015. // to entries in our own String INDEX starts at SID 391.
  46016. topDict.setByName('version', 391);
  46017. topDict.setByName('Notice', 392);
  46018. topDict.setByName('FullName', 393);
  46019. topDict.setByName('FamilyName', 394);
  46020. topDict.setByName('Weight', 395);
  46021. topDict.setByName('Encoding', null);
  46022. // placeholder
  46023. topDict.setByName('FontMatrix', properties.fontMatrix);
  46024. topDict.setByName('FontBBox', properties.bbox);
  46025. topDict.setByName('charset', null);
  46026. // placeholder
  46027. topDict.setByName('CharStrings', null);
  46028. // placeholder
  46029. topDict.setByName('Private', null);
  46030. // placeholder
  46031. cff.topDict = topDict;
  46032. var strings = new CFFStrings();
  46033. strings.add('Version 0.11');
  46034. // Version
  46035. strings.add('See original notice');
  46036. // Notice
  46037. strings.add(name);
  46038. // FullName
  46039. strings.add(name);
  46040. // FamilyName
  46041. strings.add('Medium');
  46042. // Weight
  46043. cff.strings = strings;
  46044. cff.globalSubrIndex = new CFFIndex();
  46045. var count = glyphs.length;
  46046. var charsetArray = [0];
  46047. var i, ii;
  46048. for (i = 0; i < count; i++) {
  46049. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  46050. // TODO: Insert the string and correctly map it. Previously it was
  46051. // thought mapping names that aren't in the standard strings to .notdef
  46052. // was fine, however in issue818 when mapping them all to .notdef the
  46053. // adieresis glyph no longer worked.
  46054. if (index === -1) {
  46055. index = 0;
  46056. }
  46057. charsetArray.push(index >> 8 & 0xff, index & 0xff);
  46058. }
  46059. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  46060. var charStringsIndex = new CFFIndex();
  46061. charStringsIndex.add([
  46062. 0x8B,
  46063. 0x0E
  46064. ]);
  46065. // .notdef
  46066. for (i = 0; i < count; i++) {
  46067. var glyph = glyphs[i];
  46068. // If the CharString outline is empty, replace it with .notdef to
  46069. // prevent OTS from rejecting the font (fixes bug1252420.pdf).
  46070. if (glyph.length === 0) {
  46071. charStringsIndex.add([
  46072. 0x8B,
  46073. 0x0E
  46074. ]);
  46075. // .notdef
  46076. continue;
  46077. }
  46078. charStringsIndex.add(glyph);
  46079. }
  46080. cff.charStrings = charStringsIndex;
  46081. var privateDict = new CFFPrivateDict();
  46082. privateDict.setByName('Subrs', null);
  46083. // placeholder
  46084. var fields = [
  46085. 'BlueValues',
  46086. 'OtherBlues',
  46087. 'FamilyBlues',
  46088. 'FamilyOtherBlues',
  46089. 'StemSnapH',
  46090. 'StemSnapV',
  46091. 'BlueShift',
  46092. 'BlueFuzz',
  46093. 'BlueScale',
  46094. 'LanguageGroup',
  46095. 'ExpansionFactor',
  46096. 'ForceBold',
  46097. 'StdHW',
  46098. 'StdVW'
  46099. ];
  46100. for (i = 0, ii = fields.length; i < ii; i++) {
  46101. var field = fields[i];
  46102. if (!(field in properties.privateData)) {
  46103. continue;
  46104. }
  46105. var value = properties.privateData[field];
  46106. if (isArray(value)) {
  46107. // All of the private dictionary array data in CFF must be stored as
  46108. // "delta-encoded" numbers.
  46109. for (var j = value.length - 1; j > 0; j--) {
  46110. value[j] -= value[j - 1];
  46111. }
  46112. }
  46113. // ... difference from previous value
  46114. privateDict.setByName(field, value);
  46115. }
  46116. cff.topDict.privateDict = privateDict;
  46117. var subrIndex = new CFFIndex();
  46118. for (i = 0, ii = subrs.length; i < ii; i++) {
  46119. subrIndex.add(subrs[i]);
  46120. }
  46121. privateDict.subrsIndex = subrIndex;
  46122. var compiler = new CFFCompiler(cff);
  46123. return compiler.compile();
  46124. }
  46125. };
  46126. return Type1Font;
  46127. }();
  46128. var CFFFont = function CFFFontClosure() {
  46129. function CFFFont(file, properties) {
  46130. this.properties = properties;
  46131. var parser = new CFFParser(file, properties, SEAC_ANALYSIS_ENABLED);
  46132. this.cff = parser.parse();
  46133. var compiler = new CFFCompiler(this.cff);
  46134. this.seacs = this.cff.seacs;
  46135. try {
  46136. this.data = compiler.compile();
  46137. } catch (e) {
  46138. warn('Failed to compile font ' + properties.loadedName);
  46139. // There may have just been an issue with the compiler, set the data
  46140. // anyway and hope the font loaded.
  46141. this.data = file;
  46142. }
  46143. }
  46144. CFFFont.prototype = {
  46145. get numGlyphs() {
  46146. return this.cff.charStrings.count;
  46147. },
  46148. getCharset: function CFFFont_getCharset() {
  46149. return this.cff.charset.charset;
  46150. },
  46151. getGlyphMapping: function CFFFont_getGlyphMapping() {
  46152. var cff = this.cff;
  46153. var properties = this.properties;
  46154. var charsets = cff.charset.charset;
  46155. var charCodeToGlyphId;
  46156. var glyphId;
  46157. if (properties.composite) {
  46158. charCodeToGlyphId = Object.create(null);
  46159. if (cff.isCIDFont) {
  46160. // If the font is actually a CID font then we should use the charset
  46161. // to map CIDs to GIDs.
  46162. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  46163. var cid = charsets[glyphId];
  46164. var charCode = properties.cMap.charCodeOf(cid);
  46165. charCodeToGlyphId[charCode] = glyphId;
  46166. }
  46167. } else {
  46168. // If it is NOT actually a CID font then CIDs should be mapped
  46169. // directly to GIDs.
  46170. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  46171. charCodeToGlyphId[glyphId] = glyphId;
  46172. }
  46173. }
  46174. return charCodeToGlyphId;
  46175. }
  46176. var encoding = cff.encoding ? cff.encoding.encoding : null;
  46177. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  46178. return charCodeToGlyphId;
  46179. }
  46180. };
  46181. return CFFFont;
  46182. }();
  46183. // Workaround for seac on Windows.
  46184. (function checkSeacSupport() {
  46185. if (typeof navigator !== 'undefined' && /Windows/.test(navigator.userAgent)) {
  46186. SEAC_ANALYSIS_ENABLED = true;
  46187. }
  46188. }());
  46189. // Workaround for Private Use Area characters in Chrome on Windows
  46190. // http://code.google.com/p/chromium/issues/detail?id=122465
  46191. // https://github.com/mozilla/pdf.js/issues/1689
  46192. (function checkChromeWindows() {
  46193. if (typeof navigator !== 'undefined' && /Windows.*Chrome/.test(navigator.userAgent)) {
  46194. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  46195. }
  46196. }());
  46197. exports.ErrorFont = ErrorFont;
  46198. exports.Font = Font;
  46199. exports.FontFlags = FontFlags;
  46200. exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
  46201. exports.ToUnicodeMap = ToUnicodeMap;
  46202. exports.getFontType = getFontType;
  46203. }));
  46204. (function (root, factory) {
  46205. factory(root.pdfjsCorePsParser = {}, root.pdfjsSharedUtil, root.pdfjsCoreParser);
  46206. }(this, function (exports, sharedUtil, coreParser) {
  46207. var error = sharedUtil.error;
  46208. var isSpace = sharedUtil.isSpace;
  46209. var EOF = coreParser.EOF;
  46210. var PostScriptParser = function PostScriptParserClosure() {
  46211. function PostScriptParser(lexer) {
  46212. this.lexer = lexer;
  46213. this.operators = [];
  46214. this.token = null;
  46215. this.prev = null;
  46216. }
  46217. PostScriptParser.prototype = {
  46218. nextToken: function PostScriptParser_nextToken() {
  46219. this.prev = this.token;
  46220. this.token = this.lexer.getToken();
  46221. },
  46222. accept: function PostScriptParser_accept(type) {
  46223. if (this.token.type === type) {
  46224. this.nextToken();
  46225. return true;
  46226. }
  46227. return false;
  46228. },
  46229. expect: function PostScriptParser_expect(type) {
  46230. if (this.accept(type)) {
  46231. return true;
  46232. }
  46233. error('Unexpected symbol: found ' + this.token.type + ' expected ' + type + '.');
  46234. },
  46235. parse: function PostScriptParser_parse() {
  46236. this.nextToken();
  46237. this.expect(PostScriptTokenTypes.LBRACE);
  46238. this.parseBlock();
  46239. this.expect(PostScriptTokenTypes.RBRACE);
  46240. return this.operators;
  46241. },
  46242. parseBlock: function PostScriptParser_parseBlock() {
  46243. while (true) {
  46244. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  46245. this.operators.push(this.prev.value);
  46246. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  46247. this.operators.push(this.prev.value);
  46248. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  46249. this.parseCondition();
  46250. } else {
  46251. return;
  46252. }
  46253. }
  46254. },
  46255. parseCondition: function PostScriptParser_parseCondition() {
  46256. // Add two place holders that will be updated later
  46257. var conditionLocation = this.operators.length;
  46258. this.operators.push(null, null);
  46259. this.parseBlock();
  46260. this.expect(PostScriptTokenTypes.RBRACE);
  46261. if (this.accept(PostScriptTokenTypes.IF)) {
  46262. // The true block is right after the 'if' so it just falls through on
  46263. // true else it jumps and skips the true block.
  46264. this.operators[conditionLocation] = this.operators.length;
  46265. this.operators[conditionLocation + 1] = 'jz';
  46266. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  46267. var jumpLocation = this.operators.length;
  46268. this.operators.push(null, null);
  46269. var endOfTrue = this.operators.length;
  46270. this.parseBlock();
  46271. this.expect(PostScriptTokenTypes.RBRACE);
  46272. this.expect(PostScriptTokenTypes.IFELSE);
  46273. // The jump is added at the end of the true block to skip the false
  46274. // block.
  46275. this.operators[jumpLocation] = this.operators.length;
  46276. this.operators[jumpLocation + 1] = 'j';
  46277. this.operators[conditionLocation] = endOfTrue;
  46278. this.operators[conditionLocation + 1] = 'jz';
  46279. } else {
  46280. error('PS Function: error parsing conditional.');
  46281. }
  46282. }
  46283. };
  46284. return PostScriptParser;
  46285. }();
  46286. var PostScriptTokenTypes = {
  46287. LBRACE: 0,
  46288. RBRACE: 1,
  46289. NUMBER: 2,
  46290. OPERATOR: 3,
  46291. IF: 4,
  46292. IFELSE: 5
  46293. };
  46294. var PostScriptToken = function PostScriptTokenClosure() {
  46295. function PostScriptToken(type, value) {
  46296. this.type = type;
  46297. this.value = value;
  46298. }
  46299. var opCache = Object.create(null);
  46300. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  46301. var opValue = opCache[op];
  46302. if (opValue) {
  46303. return opValue;
  46304. }
  46305. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  46306. };
  46307. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE, '{');
  46308. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE, '}');
  46309. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  46310. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE, 'IFELSE');
  46311. return PostScriptToken;
  46312. }();
  46313. var PostScriptLexer = function PostScriptLexerClosure() {
  46314. function PostScriptLexer(stream) {
  46315. this.stream = stream;
  46316. this.nextChar();
  46317. this.strBuf = [];
  46318. }
  46319. PostScriptLexer.prototype = {
  46320. nextChar: function PostScriptLexer_nextChar() {
  46321. return this.currentChar = this.stream.getByte();
  46322. },
  46323. getToken: function PostScriptLexer_getToken() {
  46324. var comment = false;
  46325. var ch = this.currentChar;
  46326. // skip comments
  46327. while (true) {
  46328. if (ch < 0) {
  46329. return EOF;
  46330. }
  46331. if (comment) {
  46332. if (ch === 0x0A || ch === 0x0D) {
  46333. comment = false;
  46334. }
  46335. } else if (ch === 0x25) {
  46336. // '%'
  46337. comment = true;
  46338. } else if (!isSpace(ch)) {
  46339. break;
  46340. }
  46341. ch = this.nextChar();
  46342. }
  46343. switch (ch | 0) {
  46344. case 0x30:
  46345. case 0x31:
  46346. case 0x32:
  46347. case 0x33:
  46348. case 0x34:
  46349. // '0'-'4'
  46350. case 0x35:
  46351. case 0x36:
  46352. case 0x37:
  46353. case 0x38:
  46354. case 0x39:
  46355. // '5'-'9'
  46356. case 0x2B:
  46357. case 0x2D:
  46358. case 0x2E:
  46359. // '+', '-', '.'
  46360. return new PostScriptToken(PostScriptTokenTypes.NUMBER, this.getNumber());
  46361. case 0x7B:
  46362. // '{'
  46363. this.nextChar();
  46364. return PostScriptToken.LBRACE;
  46365. case 0x7D:
  46366. // '}'
  46367. this.nextChar();
  46368. return PostScriptToken.RBRACE;
  46369. }
  46370. // operator
  46371. var strBuf = this.strBuf;
  46372. strBuf.length = 0;
  46373. strBuf[0] = String.fromCharCode(ch);
  46374. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  46375. (ch >= 0x41 && ch <= 0x5A || ch >= 0x61 && ch <= 0x7A)) {
  46376. strBuf.push(String.fromCharCode(ch));
  46377. }
  46378. var str = strBuf.join('');
  46379. switch (str.toLowerCase()) {
  46380. case 'if':
  46381. return PostScriptToken.IF;
  46382. case 'ifelse':
  46383. return PostScriptToken.IFELSE;
  46384. default:
  46385. return PostScriptToken.getOperator(str);
  46386. }
  46387. },
  46388. getNumber: function PostScriptLexer_getNumber() {
  46389. var ch = this.currentChar;
  46390. var strBuf = this.strBuf;
  46391. strBuf.length = 0;
  46392. strBuf[0] = String.fromCharCode(ch);
  46393. while ((ch = this.nextChar()) >= 0) {
  46394. if (ch >= 0x30 && ch <= 0x39 || // '0'-'9'
  46395. ch === 0x2D || ch === 0x2E) {
  46396. // '-', '.'
  46397. strBuf.push(String.fromCharCode(ch));
  46398. } else {
  46399. break;
  46400. }
  46401. }
  46402. var value = parseFloat(strBuf.join(''));
  46403. if (isNaN(value)) {
  46404. error('Invalid floating point number: ' + value);
  46405. }
  46406. return value;
  46407. }
  46408. };
  46409. return PostScriptLexer;
  46410. }();
  46411. exports.PostScriptLexer = PostScriptLexer;
  46412. exports.PostScriptParser = PostScriptParser;
  46413. }));
  46414. (function (root, factory) {
  46415. factory(root.pdfjsDisplayCanvas = {}, root.pdfjsSharedUtil, root.pdfjsDisplayDOMUtils, root.pdfjsDisplayPatternHelper, root.pdfjsDisplayWebGL);
  46416. }(this, function (exports, sharedUtil, displayDOMUtils, displayPatternHelper, displayWebGL) {
  46417. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  46418. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  46419. var ImageKind = sharedUtil.ImageKind;
  46420. var OPS = sharedUtil.OPS;
  46421. var TextRenderingMode = sharedUtil.TextRenderingMode;
  46422. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  46423. var Util = sharedUtil.Util;
  46424. var assert = sharedUtil.assert;
  46425. var info = sharedUtil.info;
  46426. var isNum = sharedUtil.isNum;
  46427. var isArray = sharedUtil.isArray;
  46428. var isLittleEndian = sharedUtil.isLittleEndian;
  46429. var error = sharedUtil.error;
  46430. var shadow = sharedUtil.shadow;
  46431. var warn = sharedUtil.warn;
  46432. var TilingPattern = displayPatternHelper.TilingPattern;
  46433. var getShadingPatternFromIR = displayPatternHelper.getShadingPatternFromIR;
  46434. var WebGLUtils = displayWebGL.WebGLUtils;
  46435. var hasCanvasTypedArrays = displayDOMUtils.hasCanvasTypedArrays;
  46436. // <canvas> contexts store most of the state we need natively.
  46437. // However, PDF needs a bit more state, which we store here.
  46438. // Minimal font size that would be used during canvas fillText operations.
  46439. var MIN_FONT_SIZE = 16;
  46440. // Maximum font size that would be used during canvas fillText operations.
  46441. var MAX_FONT_SIZE = 100;
  46442. var MAX_GROUP_SIZE = 4096;
  46443. // Heuristic value used when enforcing minimum line widths.
  46444. var MIN_WIDTH_FACTOR = 0.65;
  46445. var COMPILE_TYPE3_GLYPHS = true;
  46446. var MAX_SIZE_TO_COMPILE = 1000;
  46447. var FULL_CHUNK_HEIGHT = 16;
  46448. var HasCanvasTypedArraysCached = {
  46449. get value() {
  46450. return shadow(HasCanvasTypedArraysCached, 'value', hasCanvasTypedArrays());
  46451. }
  46452. };
  46453. var IsLittleEndianCached = {
  46454. get value() {
  46455. return shadow(IsLittleEndianCached, 'value', isLittleEndian());
  46456. }
  46457. };
  46458. function createScratchCanvas(width, height) {
  46459. var canvas = document.createElement('canvas');
  46460. canvas.width = width;
  46461. canvas.height = height;
  46462. return canvas;
  46463. }
  46464. function addContextCurrentTransform(ctx) {
  46465. // If the context doesn't expose a `mozCurrentTransform`, add a JS based one.
  46466. if (!ctx.mozCurrentTransform) {
  46467. ctx._originalSave = ctx.save;
  46468. ctx._originalRestore = ctx.restore;
  46469. ctx._originalRotate = ctx.rotate;
  46470. ctx._originalScale = ctx.scale;
  46471. ctx._originalTranslate = ctx.translate;
  46472. ctx._originalTransform = ctx.transform;
  46473. ctx._originalSetTransform = ctx.setTransform;
  46474. ctx._transformMatrix = ctx._transformMatrix || [
  46475. 1,
  46476. 0,
  46477. 0,
  46478. 1,
  46479. 0,
  46480. 0
  46481. ];
  46482. ctx._transformStack = [];
  46483. Object.defineProperty(ctx, 'mozCurrentTransform', {
  46484. get: function getCurrentTransform() {
  46485. return this._transformMatrix;
  46486. }
  46487. });
  46488. Object.defineProperty(ctx, 'mozCurrentTransformInverse', {
  46489. get: function getCurrentTransformInverse() {
  46490. // Calculation done using WolframAlpha:
  46491. // http://www.wolframalpha.com/input/?
  46492. // i=Inverse+{{a%2C+c%2C+e}%2C+{b%2C+d%2C+f}%2C+{0%2C+0%2C+1}}
  46493. var m = this._transformMatrix;
  46494. var a = m[0], b = m[1], c = m[2], d = m[3], e = m[4], f = m[5];
  46495. var ad_bc = a * d - b * c;
  46496. var bc_ad = b * c - a * d;
  46497. return [
  46498. d / ad_bc,
  46499. b / bc_ad,
  46500. c / bc_ad,
  46501. a / ad_bc,
  46502. (d * e - c * f) / bc_ad,
  46503. (b * e - a * f) / ad_bc
  46504. ];
  46505. }
  46506. });
  46507. ctx.save = function ctxSave() {
  46508. var old = this._transformMatrix;
  46509. this._transformStack.push(old);
  46510. this._transformMatrix = old.slice(0, 6);
  46511. this._originalSave();
  46512. };
  46513. ctx.restore = function ctxRestore() {
  46514. var prev = this._transformStack.pop();
  46515. if (prev) {
  46516. this._transformMatrix = prev;
  46517. this._originalRestore();
  46518. }
  46519. };
  46520. ctx.translate = function ctxTranslate(x, y) {
  46521. var m = this._transformMatrix;
  46522. m[4] = m[0] * x + m[2] * y + m[4];
  46523. m[5] = m[1] * x + m[3] * y + m[5];
  46524. this._originalTranslate(x, y);
  46525. };
  46526. ctx.scale = function ctxScale(x, y) {
  46527. var m = this._transformMatrix;
  46528. m[0] = m[0] * x;
  46529. m[1] = m[1] * x;
  46530. m[2] = m[2] * y;
  46531. m[3] = m[3] * y;
  46532. this._originalScale(x, y);
  46533. };
  46534. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  46535. var m = this._transformMatrix;
  46536. this._transformMatrix = [
  46537. m[0] * a + m[2] * b,
  46538. m[1] * a + m[3] * b,
  46539. m[0] * c + m[2] * d,
  46540. m[1] * c + m[3] * d,
  46541. m[0] * e + m[2] * f + m[4],
  46542. m[1] * e + m[3] * f + m[5]
  46543. ];
  46544. ctx._originalTransform(a, b, c, d, e, f);
  46545. };
  46546. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  46547. this._transformMatrix = [
  46548. a,
  46549. b,
  46550. c,
  46551. d,
  46552. e,
  46553. f
  46554. ];
  46555. ctx._originalSetTransform(a, b, c, d, e, f);
  46556. };
  46557. ctx.rotate = function ctxRotate(angle) {
  46558. var cosValue = Math.cos(angle);
  46559. var sinValue = Math.sin(angle);
  46560. var m = this._transformMatrix;
  46561. this._transformMatrix = [
  46562. m[0] * cosValue + m[2] * sinValue,
  46563. m[1] * cosValue + m[3] * sinValue,
  46564. m[0] * -sinValue + m[2] * cosValue,
  46565. m[1] * -sinValue + m[3] * cosValue,
  46566. m[4],
  46567. m[5]
  46568. ];
  46569. this._originalRotate(angle);
  46570. };
  46571. }
  46572. }
  46573. var CachedCanvases = function CachedCanvasesClosure() {
  46574. function CachedCanvases() {
  46575. this.cache = Object.create(null);
  46576. }
  46577. CachedCanvases.prototype = {
  46578. getCanvas: function CachedCanvases_getCanvas(id, width, height, trackTransform) {
  46579. var canvasEntry;
  46580. if (this.cache[id] !== undefined) {
  46581. canvasEntry = this.cache[id];
  46582. canvasEntry.canvas.width = width;
  46583. canvasEntry.canvas.height = height;
  46584. // reset canvas transform for emulated mozCurrentTransform, if needed
  46585. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  46586. } else {
  46587. var canvas = createScratchCanvas(width, height);
  46588. var ctx = canvas.getContext('2d');
  46589. if (trackTransform) {
  46590. addContextCurrentTransform(ctx);
  46591. }
  46592. this.cache[id] = canvasEntry = {
  46593. canvas: canvas,
  46594. context: ctx
  46595. };
  46596. }
  46597. return canvasEntry;
  46598. },
  46599. clear: function () {
  46600. for (var id in this.cache) {
  46601. var canvasEntry = this.cache[id];
  46602. // Zeroing the width and height causes Firefox to release graphics
  46603. // resources immediately, which can greatly reduce memory consumption.
  46604. canvasEntry.canvas.width = 0;
  46605. canvasEntry.canvas.height = 0;
  46606. delete this.cache[id];
  46607. }
  46608. }
  46609. };
  46610. return CachedCanvases;
  46611. }();
  46612. function compileType3Glyph(imgData) {
  46613. var POINT_TO_PROCESS_LIMIT = 1000;
  46614. var width = imgData.width, height = imgData.height;
  46615. var i, j, j0, width1 = width + 1;
  46616. var points = new Uint8Array(width1 * (height + 1));
  46617. var POINT_TYPES = new Uint8Array([
  46618. 0,
  46619. 2,
  46620. 4,
  46621. 0,
  46622. 1,
  46623. 0,
  46624. 5,
  46625. 4,
  46626. 8,
  46627. 10,
  46628. 0,
  46629. 8,
  46630. 0,
  46631. 2,
  46632. 1,
  46633. 0
  46634. ]);
  46635. // decodes bit-packed mask data
  46636. var lineSize = width + 7 & ~7, data0 = imgData.data;
  46637. var data = new Uint8Array(lineSize * height), pos = 0, ii;
  46638. for (i = 0, ii = data0.length; i < ii; i++) {
  46639. var mask = 128, elem = data0[i];
  46640. while (mask > 0) {
  46641. data[pos++] = elem & mask ? 0 : 255;
  46642. mask >>= 1;
  46643. }
  46644. }
  46645. // finding iteresting points: every point is located between mask pixels,
  46646. // so there will be points of the (width + 1)x(height + 1) grid. Every point
  46647. // will have flags assigned based on neighboring mask pixels:
  46648. // 4 | 8
  46649. // --P--
  46650. // 2 | 1
  46651. // We are interested only in points with the flags:
  46652. // - outside corners: 1, 2, 4, 8;
  46653. // - inside corners: 7, 11, 13, 14;
  46654. // - and, intersections: 5, 10.
  46655. var count = 0;
  46656. pos = 0;
  46657. if (data[pos] !== 0) {
  46658. points[0] = 1;
  46659. ++count;
  46660. }
  46661. for (j = 1; j < width; j++) {
  46662. if (data[pos] !== data[pos + 1]) {
  46663. points[j] = data[pos] ? 2 : 1;
  46664. ++count;
  46665. }
  46666. pos++;
  46667. }
  46668. if (data[pos] !== 0) {
  46669. points[j] = 2;
  46670. ++count;
  46671. }
  46672. for (i = 1; i < height; i++) {
  46673. pos = i * lineSize;
  46674. j0 = i * width1;
  46675. if (data[pos - lineSize] !== data[pos]) {
  46676. points[j0] = data[pos] ? 1 : 8;
  46677. ++count;
  46678. }
  46679. // 'sum' is the position of the current pixel configuration in the 'TYPES'
  46680. // array (in order 8-1-2-4, so we can use '>>2' to shift the column).
  46681. var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  46682. for (j = 1; j < width; j++) {
  46683. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) + (data[pos - lineSize + 1] ? 8 : 0);
  46684. if (POINT_TYPES[sum]) {
  46685. points[j0 + j] = POINT_TYPES[sum];
  46686. ++count;
  46687. }
  46688. pos++;
  46689. }
  46690. if (data[pos - lineSize] !== data[pos]) {
  46691. points[j0 + j] = data[pos] ? 2 : 4;
  46692. ++count;
  46693. }
  46694. if (count > POINT_TO_PROCESS_LIMIT) {
  46695. return null;
  46696. }
  46697. }
  46698. pos = lineSize * (height - 1);
  46699. j0 = i * width1;
  46700. if (data[pos] !== 0) {
  46701. points[j0] = 8;
  46702. ++count;
  46703. }
  46704. for (j = 1; j < width; j++) {
  46705. if (data[pos] !== data[pos + 1]) {
  46706. points[j0 + j] = data[pos] ? 4 : 8;
  46707. ++count;
  46708. }
  46709. pos++;
  46710. }
  46711. if (data[pos] !== 0) {
  46712. points[j0 + j] = 4;
  46713. ++count;
  46714. }
  46715. if (count > POINT_TO_PROCESS_LIMIT) {
  46716. return null;
  46717. }
  46718. // building outlines
  46719. var steps = new Int32Array([
  46720. 0,
  46721. width1,
  46722. -1,
  46723. 0,
  46724. -width1,
  46725. 0,
  46726. 0,
  46727. 0,
  46728. 1
  46729. ]);
  46730. var outlines = [];
  46731. for (i = 0; count && i <= height; i++) {
  46732. var p = i * width1;
  46733. var end = p + width;
  46734. while (p < end && !points[p]) {
  46735. p++;
  46736. }
  46737. if (p === end) {
  46738. continue;
  46739. }
  46740. var coords = [
  46741. p % width1,
  46742. i
  46743. ];
  46744. var type = points[p], p0 = p, pp;
  46745. do {
  46746. var step = steps[type];
  46747. do {
  46748. p += step;
  46749. } while (!points[p]);
  46750. pp = points[p];
  46751. if (pp !== 5 && pp !== 10) {
  46752. // set new direction
  46753. type = pp;
  46754. // delete mark
  46755. points[p] = 0;
  46756. } else {
  46757. // type is 5 or 10, ie, a crossing
  46758. // set new direction
  46759. type = pp & 0x33 * type >> 4;
  46760. // set new type for "future hit"
  46761. points[p] &= type >> 2 | type << 2;
  46762. }
  46763. coords.push(p % width1);
  46764. coords.push(p / width1 | 0);
  46765. --count;
  46766. } while (p0 !== p);
  46767. outlines.push(coords);
  46768. --i;
  46769. }
  46770. var drawOutline = function (c) {
  46771. c.save();
  46772. // the path shall be painted in [0..1]x[0..1] space
  46773. c.scale(1 / width, -1 / height);
  46774. c.translate(0, -height);
  46775. c.beginPath();
  46776. for (var i = 0, ii = outlines.length; i < ii; i++) {
  46777. var o = outlines[i];
  46778. c.moveTo(o[0], o[1]);
  46779. for (var j = 2, jj = o.length; j < jj; j += 2) {
  46780. c.lineTo(o[j], o[j + 1]);
  46781. }
  46782. }
  46783. c.fill();
  46784. c.beginPath();
  46785. c.restore();
  46786. };
  46787. return drawOutline;
  46788. }
  46789. var CanvasExtraState = function CanvasExtraStateClosure() {
  46790. function CanvasExtraState(old) {
  46791. // Are soft masks and alpha values shapes or opacities?
  46792. this.alphaIsShape = false;
  46793. this.fontSize = 0;
  46794. this.fontSizeScale = 1;
  46795. this.textMatrix = IDENTITY_MATRIX;
  46796. this.textMatrixScale = 1;
  46797. this.fontMatrix = FONT_IDENTITY_MATRIX;
  46798. this.leading = 0;
  46799. // Current point (in user coordinates)
  46800. this.x = 0;
  46801. this.y = 0;
  46802. // Start of text line (in text coordinates)
  46803. this.lineX = 0;
  46804. this.lineY = 0;
  46805. // Character and word spacing
  46806. this.charSpacing = 0;
  46807. this.wordSpacing = 0;
  46808. this.textHScale = 1;
  46809. this.textRenderingMode = TextRenderingMode.FILL;
  46810. this.textRise = 0;
  46811. // Default fore and background colors
  46812. this.fillColor = '#000000';
  46813. this.strokeColor = '#000000';
  46814. this.patternFill = false;
  46815. // Note: fill alpha applies to all non-stroking operations
  46816. this.fillAlpha = 1;
  46817. this.strokeAlpha = 1;
  46818. this.lineWidth = 1;
  46819. this.activeSMask = null;
  46820. this.resumeSMaskCtx = null;
  46821. // nonclonable field (see the save method below)
  46822. this.old = old;
  46823. }
  46824. CanvasExtraState.prototype = {
  46825. clone: function CanvasExtraState_clone() {
  46826. return Object.create(this);
  46827. },
  46828. setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
  46829. this.x = x;
  46830. this.y = y;
  46831. }
  46832. };
  46833. return CanvasExtraState;
  46834. }();
  46835. var CanvasGraphics = function CanvasGraphicsClosure() {
  46836. // Defines the time the executeOperatorList is going to be executing
  46837. // before it stops and shedules a continue of execution.
  46838. var EXECUTION_TIME = 15;
  46839. // Defines the number of steps before checking the execution time
  46840. var EXECUTION_STEPS = 10;
  46841. function CanvasGraphics(canvasCtx, commonObjs, objs, imageLayer) {
  46842. this.ctx = canvasCtx;
  46843. this.current = new CanvasExtraState();
  46844. this.stateStack = [];
  46845. this.pendingClip = null;
  46846. this.pendingEOFill = false;
  46847. this.res = null;
  46848. this.xobjs = null;
  46849. this.commonObjs = commonObjs;
  46850. this.objs = objs;
  46851. this.imageLayer = imageLayer;
  46852. this.groupStack = [];
  46853. this.processingType3 = null;
  46854. // Patterns are painted relative to the initial page/form transform, see pdf
  46855. // spec 8.7.2 NOTE 1.
  46856. this.baseTransform = null;
  46857. this.baseTransformStack = [];
  46858. this.groupLevel = 0;
  46859. this.smaskStack = [];
  46860. this.smaskCounter = 0;
  46861. this.tempSMask = null;
  46862. this.cachedCanvases = new CachedCanvases();
  46863. if (canvasCtx) {
  46864. // NOTE: if mozCurrentTransform is polyfilled, then the current state of
  46865. // the transformation must already be set in canvasCtx._transformMatrix.
  46866. addContextCurrentTransform(canvasCtx);
  46867. }
  46868. this.cachedGetSinglePixelWidth = null;
  46869. }
  46870. function putBinaryImageData(ctx, imgData) {
  46871. if (typeof ImageData !== 'undefined' && imgData instanceof ImageData) {
  46872. ctx.putImageData(imgData, 0, 0);
  46873. return;
  46874. }
  46875. // Put the image data to the canvas in chunks, rather than putting the
  46876. // whole image at once. This saves JS memory, because the ImageData object
  46877. // is smaller. It also possibly saves C++ memory within the implementation
  46878. // of putImageData(). (E.g. in Firefox we make two short-lived copies of
  46879. // the data passed to putImageData()). |n| shouldn't be too small, however,
  46880. // because too many putImageData() calls will slow things down.
  46881. //
  46882. // Note: as written, if the last chunk is partial, the putImageData() call
  46883. // will (conceptually) put pixels past the bounds of the canvas. But
  46884. // that's ok; any such pixels are ignored.
  46885. var height = imgData.height, width = imgData.width;
  46886. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  46887. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  46888. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  46889. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  46890. var srcPos = 0, destPos;
  46891. var src = imgData.data;
  46892. var dest = chunkImgData.data;
  46893. var i, j, thisChunkHeight, elemsInThisChunk;
  46894. // There are multiple forms in which the pixel data can be passed, and
  46895. // imgData.kind tells us which one this is.
  46896. if (imgData.kind === ImageKind.GRAYSCALE_1BPP) {
  46897. // Grayscale, 1 bit per pixel (i.e. black-and-white).
  46898. var srcLength = src.byteLength;
  46899. var dest32 = HasCanvasTypedArraysCached.value ? new Uint32Array(dest.buffer) : new Uint32ArrayView(dest);
  46900. var dest32DataLength = dest32.length;
  46901. var fullSrcDiff = width + 7 >> 3;
  46902. var white = 0xFFFFFFFF;
  46903. var black = IsLittleEndianCached.value || !HasCanvasTypedArraysCached.value ? 0xFF000000 : 0x000000FF;
  46904. for (i = 0; i < totalChunks; i++) {
  46905. thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  46906. destPos = 0;
  46907. for (j = 0; j < thisChunkHeight; j++) {
  46908. var srcDiff = srcLength - srcPos;
  46909. var k = 0;
  46910. var kEnd = srcDiff > fullSrcDiff ? width : srcDiff * 8 - 7;
  46911. var kEndUnrolled = kEnd & ~7;
  46912. var mask = 0;
  46913. var srcByte = 0;
  46914. for (; k < kEndUnrolled; k += 8) {
  46915. srcByte = src[srcPos++];
  46916. dest32[destPos++] = srcByte & 128 ? white : black;
  46917. dest32[destPos++] = srcByte & 64 ? white : black;
  46918. dest32[destPos++] = srcByte & 32 ? white : black;
  46919. dest32[destPos++] = srcByte & 16 ? white : black;
  46920. dest32[destPos++] = srcByte & 8 ? white : black;
  46921. dest32[destPos++] = srcByte & 4 ? white : black;
  46922. dest32[destPos++] = srcByte & 2 ? white : black;
  46923. dest32[destPos++] = srcByte & 1 ? white : black;
  46924. }
  46925. for (; k < kEnd; k++) {
  46926. if (mask === 0) {
  46927. srcByte = src[srcPos++];
  46928. mask = 128;
  46929. }
  46930. dest32[destPos++] = srcByte & mask ? white : black;
  46931. mask >>= 1;
  46932. }
  46933. }
  46934. // We ran out of input. Make all remaining pixels transparent.
  46935. while (destPos < dest32DataLength) {
  46936. dest32[destPos++] = 0;
  46937. }
  46938. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  46939. }
  46940. } else if (imgData.kind === ImageKind.RGBA_32BPP) {
  46941. // RGBA, 32-bits per pixel.
  46942. j = 0;
  46943. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  46944. for (i = 0; i < fullChunks; i++) {
  46945. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  46946. srcPos += elemsInThisChunk;
  46947. ctx.putImageData(chunkImgData, 0, j);
  46948. j += FULL_CHUNK_HEIGHT;
  46949. }
  46950. if (i < totalChunks) {
  46951. elemsInThisChunk = width * partialChunkHeight * 4;
  46952. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  46953. ctx.putImageData(chunkImgData, 0, j);
  46954. }
  46955. } else if (imgData.kind === ImageKind.RGB_24BPP) {
  46956. // RGB, 24-bits per pixel.
  46957. thisChunkHeight = FULL_CHUNK_HEIGHT;
  46958. elemsInThisChunk = width * thisChunkHeight;
  46959. for (i = 0; i < totalChunks; i++) {
  46960. if (i >= fullChunks) {
  46961. thisChunkHeight = partialChunkHeight;
  46962. elemsInThisChunk = width * thisChunkHeight;
  46963. }
  46964. destPos = 0;
  46965. for (j = elemsInThisChunk; j--;) {
  46966. dest[destPos++] = src[srcPos++];
  46967. dest[destPos++] = src[srcPos++];
  46968. dest[destPos++] = src[srcPos++];
  46969. dest[destPos++] = 255;
  46970. }
  46971. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  46972. }
  46973. } else {
  46974. error('bad image kind: ' + imgData.kind);
  46975. }
  46976. }
  46977. function putBinaryImageMask(ctx, imgData) {
  46978. var height = imgData.height, width = imgData.width;
  46979. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  46980. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  46981. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  46982. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  46983. var srcPos = 0;
  46984. var src = imgData.data;
  46985. var dest = chunkImgData.data;
  46986. for (var i = 0; i < totalChunks; i++) {
  46987. var thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  46988. // Expand the mask so it can be used by the canvas. Any required
  46989. // inversion has already been handled.
  46990. var destPos = 3;
  46991. // alpha component offset
  46992. for (var j = 0; j < thisChunkHeight; j++) {
  46993. var mask = 0;
  46994. for (var k = 0; k < width; k++) {
  46995. if (!mask) {
  46996. var elem = src[srcPos++];
  46997. mask = 128;
  46998. }
  46999. dest[destPos] = elem & mask ? 0 : 255;
  47000. destPos += 4;
  47001. mask >>= 1;
  47002. }
  47003. }
  47004. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  47005. }
  47006. }
  47007. function copyCtxState(sourceCtx, destCtx) {
  47008. var properties = [
  47009. 'strokeStyle',
  47010. 'fillStyle',
  47011. 'fillRule',
  47012. 'globalAlpha',
  47013. 'lineWidth',
  47014. 'lineCap',
  47015. 'lineJoin',
  47016. 'miterLimit',
  47017. 'globalCompositeOperation',
  47018. 'font'
  47019. ];
  47020. for (var i = 0, ii = properties.length; i < ii; i++) {
  47021. var property = properties[i];
  47022. if (sourceCtx[property] !== undefined) {
  47023. destCtx[property] = sourceCtx[property];
  47024. }
  47025. }
  47026. if (sourceCtx.setLineDash !== undefined) {
  47027. destCtx.setLineDash(sourceCtx.getLineDash());
  47028. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  47029. }
  47030. }
  47031. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  47032. var length = bytes.length;
  47033. for (var i = 3; i < length; i += 4) {
  47034. var alpha = bytes[i];
  47035. if (alpha === 0) {
  47036. bytes[i - 3] = r0;
  47037. bytes[i - 2] = g0;
  47038. bytes[i - 1] = b0;
  47039. } else if (alpha < 255) {
  47040. var alpha_ = 255 - alpha;
  47041. bytes[i - 3] = bytes[i - 3] * alpha + r0 * alpha_ >> 8;
  47042. bytes[i - 2] = bytes[i - 2] * alpha + g0 * alpha_ >> 8;
  47043. bytes[i - 1] = bytes[i - 1] * alpha + b0 * alpha_ >> 8;
  47044. }
  47045. }
  47046. }
  47047. function composeSMaskAlpha(maskData, layerData, transferMap) {
  47048. var length = maskData.length;
  47049. var scale = 1 / 255;
  47050. for (var i = 3; i < length; i += 4) {
  47051. var alpha = transferMap ? transferMap[maskData[i]] : maskData[i];
  47052. layerData[i] = layerData[i] * alpha * scale | 0;
  47053. }
  47054. }
  47055. function composeSMaskLuminosity(maskData, layerData, transferMap) {
  47056. var length = maskData.length;
  47057. for (var i = 3; i < length; i += 4) {
  47058. var y = maskData[i - 3] * 77 + // * 0.3 / 255 * 0x10000
  47059. maskData[i - 2] * 152 + // * 0.59 ....
  47060. maskData[i - 1] * 28;
  47061. // * 0.11 ....
  47062. layerData[i] = transferMap ? layerData[i] * transferMap[y >> 8] >> 8 : layerData[i] * y >> 16;
  47063. }
  47064. }
  47065. function genericComposeSMask(maskCtx, layerCtx, width, height, subtype, backdrop, transferMap) {
  47066. var hasBackdrop = !!backdrop;
  47067. var r0 = hasBackdrop ? backdrop[0] : 0;
  47068. var g0 = hasBackdrop ? backdrop[1] : 0;
  47069. var b0 = hasBackdrop ? backdrop[2] : 0;
  47070. var composeFn;
  47071. if (subtype === 'Luminosity') {
  47072. composeFn = composeSMaskLuminosity;
  47073. } else {
  47074. composeFn = composeSMaskAlpha;
  47075. }
  47076. // processing image in chunks to save memory
  47077. var PIXELS_TO_PROCESS = 1048576;
  47078. var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  47079. for (var row = 0; row < height; row += chunkSize) {
  47080. var chunkHeight = Math.min(chunkSize, height - row);
  47081. var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
  47082. var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
  47083. if (hasBackdrop) {
  47084. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  47085. }
  47086. composeFn(maskData.data, layerData.data, transferMap);
  47087. maskCtx.putImageData(layerData, 0, row);
  47088. }
  47089. }
  47090. function composeSMask(ctx, smask, layerCtx) {
  47091. var mask = smask.canvas;
  47092. var maskCtx = smask.context;
  47093. ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY, smask.offsetX, smask.offsetY);
  47094. var backdrop = smask.backdrop || null;
  47095. if (!smask.transferMap && WebGLUtils.isEnabled) {
  47096. var composed = WebGLUtils.composeSMask(layerCtx.canvas, mask, {
  47097. subtype: smask.subtype,
  47098. backdrop: backdrop
  47099. });
  47100. ctx.setTransform(1, 0, 0, 1, 0, 0);
  47101. ctx.drawImage(composed, smask.offsetX, smask.offsetY);
  47102. return;
  47103. }
  47104. genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height, smask.subtype, backdrop, smask.transferMap);
  47105. ctx.drawImage(mask, 0, 0);
  47106. }
  47107. var LINE_CAP_STYLES = [
  47108. 'butt',
  47109. 'round',
  47110. 'square'
  47111. ];
  47112. var LINE_JOIN_STYLES = [
  47113. 'miter',
  47114. 'round',
  47115. 'bevel'
  47116. ];
  47117. var NORMAL_CLIP = {};
  47118. var EO_CLIP = {};
  47119. CanvasGraphics.prototype = {
  47120. beginDrawing: function CanvasGraphics_beginDrawing(transform, viewport, transparency) {
  47121. // For pdfs that use blend modes we have to clear the canvas else certain
  47122. // blend modes can look wrong since we'd be blending with a white
  47123. // backdrop. The problem with a transparent backdrop though is we then
  47124. // don't get sub pixel anti aliasing on text, creating temporary
  47125. // transparent canvas when we have blend modes.
  47126. var width = this.ctx.canvas.width;
  47127. var height = this.ctx.canvas.height;
  47128. this.ctx.save();
  47129. this.ctx.fillStyle = 'rgb(255, 255, 255)';
  47130. this.ctx.fillRect(0, 0, width, height);
  47131. this.ctx.restore();
  47132. if (transparency) {
  47133. var transparentCanvas = this.cachedCanvases.getCanvas('transparent', width, height, true);
  47134. this.compositeCtx = this.ctx;
  47135. this.transparentCanvas = transparentCanvas.canvas;
  47136. this.ctx = transparentCanvas.context;
  47137. this.ctx.save();
  47138. // The transform can be applied before rendering, transferring it to
  47139. // the new canvas.
  47140. this.ctx.transform.apply(this.ctx, this.compositeCtx.mozCurrentTransform);
  47141. }
  47142. this.ctx.save();
  47143. if (transform) {
  47144. this.ctx.transform.apply(this.ctx, transform);
  47145. }
  47146. this.ctx.transform.apply(this.ctx, viewport.transform);
  47147. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  47148. if (this.imageLayer) {
  47149. this.imageLayer.beginLayout();
  47150. }
  47151. },
  47152. executeOperatorList: function CanvasGraphics_executeOperatorList(operatorList, executionStartIdx, continueCallback, stepper) {
  47153. var argsArray = operatorList.argsArray;
  47154. var fnArray = operatorList.fnArray;
  47155. var i = executionStartIdx || 0;
  47156. var argsArrayLen = argsArray.length;
  47157. // Sometimes the OperatorList to execute is empty.
  47158. if (argsArrayLen === i) {
  47159. return i;
  47160. }
  47161. var chunkOperations = argsArrayLen - i > EXECUTION_STEPS && typeof continueCallback === 'function';
  47162. var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  47163. var steps = 0;
  47164. var commonObjs = this.commonObjs;
  47165. var objs = this.objs;
  47166. var fnId;
  47167. while (true) {
  47168. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  47169. stepper.breakIt(i, continueCallback);
  47170. return i;
  47171. }
  47172. fnId = fnArray[i];
  47173. if (fnId !== OPS.dependency) {
  47174. this[fnId].apply(this, argsArray[i]);
  47175. } else {
  47176. var deps = argsArray[i];
  47177. for (var n = 0, nn = deps.length; n < nn; n++) {
  47178. var depObjId = deps[n];
  47179. var common = depObjId[0] === 'g' && depObjId[1] === '_';
  47180. var objsPool = common ? commonObjs : objs;
  47181. // If the promise isn't resolved yet, add the continueCallback
  47182. // to the promise and bail out.
  47183. if (!objsPool.isResolved(depObjId)) {
  47184. objsPool.get(depObjId, continueCallback);
  47185. return i;
  47186. }
  47187. }
  47188. }
  47189. i++;
  47190. // If the entire operatorList was executed, stop as were done.
  47191. if (i === argsArrayLen) {
  47192. return i;
  47193. }
  47194. // If the execution took longer then a certain amount of time and
  47195. // `continueCallback` is specified, interrupt the execution.
  47196. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  47197. if (Date.now() > endTime) {
  47198. continueCallback();
  47199. return i;
  47200. }
  47201. steps = 0;
  47202. }
  47203. }
  47204. },
  47205. // If the operatorList isn't executed completely yet OR the execution
  47206. // time was short enough, do another execution round.
  47207. endDrawing: function CanvasGraphics_endDrawing() {
  47208. // Finishing all opened operations such as SMask group painting.
  47209. if (this.current.activeSMask !== null) {
  47210. this.endSMaskGroup();
  47211. }
  47212. this.ctx.restore();
  47213. if (this.transparentCanvas) {
  47214. this.ctx = this.compositeCtx;
  47215. this.ctx.save();
  47216. this.ctx.setTransform(1, 0, 0, 1, 0, 0);
  47217. // Avoid apply transform twice
  47218. this.ctx.drawImage(this.transparentCanvas, 0, 0);
  47219. this.ctx.restore();
  47220. this.transparentCanvas = null;
  47221. }
  47222. this.cachedCanvases.clear();
  47223. WebGLUtils.clear();
  47224. if (this.imageLayer) {
  47225. this.imageLayer.endLayout();
  47226. }
  47227. },
  47228. // Graphics state
  47229. setLineWidth: function CanvasGraphics_setLineWidth(width) {
  47230. this.current.lineWidth = width;
  47231. this.ctx.lineWidth = width;
  47232. },
  47233. setLineCap: function CanvasGraphics_setLineCap(style) {
  47234. this.ctx.lineCap = LINE_CAP_STYLES[style];
  47235. },
  47236. setLineJoin: function CanvasGraphics_setLineJoin(style) {
  47237. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  47238. },
  47239. setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
  47240. this.ctx.miterLimit = limit;
  47241. },
  47242. setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
  47243. var ctx = this.ctx;
  47244. if (ctx.setLineDash !== undefined) {
  47245. ctx.setLineDash(dashArray);
  47246. ctx.lineDashOffset = dashPhase;
  47247. }
  47248. },
  47249. setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {
  47250. },
  47251. setFlatness: function CanvasGraphics_setFlatness(flatness) {
  47252. },
  47253. setGState: function CanvasGraphics_setGState(states) {
  47254. for (var i = 0, ii = states.length; i < ii; i++) {
  47255. var state = states[i];
  47256. var key = state[0];
  47257. var value = state[1];
  47258. switch (key) {
  47259. case 'LW':
  47260. this.setLineWidth(value);
  47261. break;
  47262. case 'LC':
  47263. this.setLineCap(value);
  47264. break;
  47265. case 'LJ':
  47266. this.setLineJoin(value);
  47267. break;
  47268. case 'ML':
  47269. this.setMiterLimit(value);
  47270. break;
  47271. case 'D':
  47272. this.setDash(value[0], value[1]);
  47273. break;
  47274. case 'RI':
  47275. this.setRenderingIntent(value);
  47276. break;
  47277. case 'FL':
  47278. this.setFlatness(value);
  47279. break;
  47280. case 'Font':
  47281. this.setFont(value[0], value[1]);
  47282. break;
  47283. case 'CA':
  47284. this.current.strokeAlpha = state[1];
  47285. break;
  47286. case 'ca':
  47287. this.current.fillAlpha = state[1];
  47288. this.ctx.globalAlpha = state[1];
  47289. break;
  47290. case 'BM':
  47291. if (value && value.name && value.name !== 'Normal') {
  47292. var mode = value.name.replace(/([A-Z])/g, function (c) {
  47293. return '-' + c.toLowerCase();
  47294. }).substring(1);
  47295. this.ctx.globalCompositeOperation = mode;
  47296. if (this.ctx.globalCompositeOperation !== mode) {
  47297. warn('globalCompositeOperation "' + mode + '" is not supported');
  47298. }
  47299. } else {
  47300. this.ctx.globalCompositeOperation = 'source-over';
  47301. }
  47302. break;
  47303. case 'SMask':
  47304. if (this.current.activeSMask) {
  47305. // If SMask is currrenly used, it needs to be suspended or
  47306. // finished. Suspend only makes sense when at least one save()
  47307. // was performed and state needs to be reverted on restore().
  47308. if (this.stateStack.length > 0 && this.stateStack[this.stateStack.length - 1].activeSMask === this.current.activeSMask) {
  47309. this.suspendSMaskGroup();
  47310. } else {
  47311. this.endSMaskGroup();
  47312. }
  47313. }
  47314. this.current.activeSMask = value ? this.tempSMask : null;
  47315. if (this.current.activeSMask) {
  47316. this.beginSMaskGroup();
  47317. }
  47318. this.tempSMask = null;
  47319. break;
  47320. }
  47321. }
  47322. },
  47323. beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
  47324. var activeSMask = this.current.activeSMask;
  47325. var drawnWidth = activeSMask.canvas.width;
  47326. var drawnHeight = activeSMask.canvas.height;
  47327. var cacheId = 'smaskGroupAt' + this.groupLevel;
  47328. var scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight, true);
  47329. var currentCtx = this.ctx;
  47330. var currentTransform = currentCtx.mozCurrentTransform;
  47331. this.ctx.save();
  47332. var groupCtx = scratchCanvas.context;
  47333. groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
  47334. groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
  47335. groupCtx.transform.apply(groupCtx, currentTransform);
  47336. activeSMask.startTransformInverse = groupCtx.mozCurrentTransformInverse;
  47337. copyCtxState(currentCtx, groupCtx);
  47338. this.ctx = groupCtx;
  47339. this.setGState([
  47340. [
  47341. 'BM',
  47342. 'Normal'
  47343. ],
  47344. [
  47345. 'ca',
  47346. 1
  47347. ],
  47348. [
  47349. 'CA',
  47350. 1
  47351. ]
  47352. ]);
  47353. this.groupStack.push(currentCtx);
  47354. this.groupLevel++;
  47355. },
  47356. suspendSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  47357. // Similar to endSMaskGroup, the intermediate canvas has to be composed
  47358. // and future ctx state restored.
  47359. var groupCtx = this.ctx;
  47360. this.groupLevel--;
  47361. this.ctx = this.groupStack.pop();
  47362. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  47363. this.ctx.restore();
  47364. this.ctx.save();
  47365. // save is needed since SMask will be resumed.
  47366. copyCtxState(groupCtx, this.ctx);
  47367. // Saving state for resuming.
  47368. this.current.resumeSMaskCtx = groupCtx;
  47369. // Transform was changed in the SMask canvas, reflecting this change on
  47370. // this.ctx.
  47371. var deltaTransform = Util.transform(this.current.activeSMask.startTransformInverse, groupCtx.mozCurrentTransform);
  47372. this.ctx.transform.apply(this.ctx, deltaTransform);
  47373. // SMask was composed, the results at the groupCtx can be cleared.
  47374. groupCtx.save();
  47375. groupCtx.setTransform(1, 0, 0, 1, 0, 0);
  47376. groupCtx.clearRect(0, 0, groupCtx.canvas.width, groupCtx.canvas.height);
  47377. groupCtx.restore();
  47378. },
  47379. resumeSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  47380. // Resuming state saved by suspendSMaskGroup. We don't need to restore
  47381. // any groupCtx state since restore() command (the only caller) will do
  47382. // that for us. See also beginSMaskGroup.
  47383. var groupCtx = this.current.resumeSMaskCtx;
  47384. var currentCtx = this.ctx;
  47385. this.ctx = groupCtx;
  47386. this.groupStack.push(currentCtx);
  47387. this.groupLevel++;
  47388. },
  47389. endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  47390. var groupCtx = this.ctx;
  47391. this.groupLevel--;
  47392. this.ctx = this.groupStack.pop();
  47393. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  47394. this.ctx.restore();
  47395. copyCtxState(groupCtx, this.ctx);
  47396. // Transform was changed in the SMask canvas, reflecting this change on
  47397. // this.ctx.
  47398. var deltaTransform = Util.transform(this.current.activeSMask.startTransformInverse, groupCtx.mozCurrentTransform);
  47399. this.ctx.transform.apply(this.ctx, deltaTransform);
  47400. },
  47401. save: function CanvasGraphics_save() {
  47402. this.ctx.save();
  47403. var old = this.current;
  47404. this.stateStack.push(old);
  47405. this.current = old.clone();
  47406. this.current.resumeSMaskCtx = null;
  47407. },
  47408. restore: function CanvasGraphics_restore() {
  47409. // SMask was suspended, we just need to resume it.
  47410. if (this.current.resumeSMaskCtx) {
  47411. this.resumeSMaskGroup();
  47412. }
  47413. // SMask has to be finished once there is no states that are using the
  47414. // same SMask.
  47415. if (this.current.activeSMask !== null && (this.stateStack.length === 0 || this.stateStack[this.stateStack.length - 1].activeSMask !== this.current.activeSMask)) {
  47416. this.endSMaskGroup();
  47417. }
  47418. if (this.stateStack.length !== 0) {
  47419. this.current = this.stateStack.pop();
  47420. this.ctx.restore();
  47421. // Ensure that the clipping path is reset (fixes issue6413.pdf).
  47422. this.pendingClip = null;
  47423. this.cachedGetSinglePixelWidth = null;
  47424. }
  47425. },
  47426. transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
  47427. this.ctx.transform(a, b, c, d, e, f);
  47428. this.cachedGetSinglePixelWidth = null;
  47429. },
  47430. // Path
  47431. constructPath: function CanvasGraphics_constructPath(ops, args) {
  47432. var ctx = this.ctx;
  47433. var current = this.current;
  47434. var x = current.x, y = current.y;
  47435. for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
  47436. switch (ops[i] | 0) {
  47437. case OPS.rectangle:
  47438. x = args[j++];
  47439. y = args[j++];
  47440. var width = args[j++];
  47441. var height = args[j++];
  47442. if (width === 0) {
  47443. width = this.getSinglePixelWidth();
  47444. }
  47445. if (height === 0) {
  47446. height = this.getSinglePixelWidth();
  47447. }
  47448. var xw = x + width;
  47449. var yh = y + height;
  47450. this.ctx.moveTo(x, y);
  47451. this.ctx.lineTo(xw, y);
  47452. this.ctx.lineTo(xw, yh);
  47453. this.ctx.lineTo(x, yh);
  47454. this.ctx.lineTo(x, y);
  47455. this.ctx.closePath();
  47456. break;
  47457. case OPS.moveTo:
  47458. x = args[j++];
  47459. y = args[j++];
  47460. ctx.moveTo(x, y);
  47461. break;
  47462. case OPS.lineTo:
  47463. x = args[j++];
  47464. y = args[j++];
  47465. ctx.lineTo(x, y);
  47466. break;
  47467. case OPS.curveTo:
  47468. x = args[j + 4];
  47469. y = args[j + 5];
  47470. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3], x, y);
  47471. j += 6;
  47472. break;
  47473. case OPS.curveTo2:
  47474. ctx.bezierCurveTo(x, y, args[j], args[j + 1], args[j + 2], args[j + 3]);
  47475. x = args[j + 2];
  47476. y = args[j + 3];
  47477. j += 4;
  47478. break;
  47479. case OPS.curveTo3:
  47480. x = args[j + 2];
  47481. y = args[j + 3];
  47482. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  47483. j += 4;
  47484. break;
  47485. case OPS.closePath:
  47486. ctx.closePath();
  47487. break;
  47488. }
  47489. }
  47490. current.setCurrentPoint(x, y);
  47491. },
  47492. closePath: function CanvasGraphics_closePath() {
  47493. this.ctx.closePath();
  47494. },
  47495. stroke: function CanvasGraphics_stroke(consumePath) {
  47496. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  47497. var ctx = this.ctx;
  47498. var strokeColor = this.current.strokeColor;
  47499. // Prevent drawing too thin lines by enforcing a minimum line width.
  47500. ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR, this.current.lineWidth);
  47501. // For stroke we want to temporarily change the global alpha to the
  47502. // stroking alpha.
  47503. ctx.globalAlpha = this.current.strokeAlpha;
  47504. if (strokeColor && strokeColor.hasOwnProperty('type') && strokeColor.type === 'Pattern') {
  47505. // for patterns, we transform to pattern space, calculate
  47506. // the pattern, call stroke, and restore to user space
  47507. ctx.save();
  47508. ctx.strokeStyle = strokeColor.getPattern(ctx, this);
  47509. ctx.stroke();
  47510. ctx.restore();
  47511. } else {
  47512. ctx.stroke();
  47513. }
  47514. if (consumePath) {
  47515. this.consumePath();
  47516. }
  47517. // Restore the global alpha to the fill alpha
  47518. ctx.globalAlpha = this.current.fillAlpha;
  47519. },
  47520. closeStroke: function CanvasGraphics_closeStroke() {
  47521. this.closePath();
  47522. this.stroke();
  47523. },
  47524. fill: function CanvasGraphics_fill(consumePath) {
  47525. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  47526. var ctx = this.ctx;
  47527. var fillColor = this.current.fillColor;
  47528. var isPatternFill = this.current.patternFill;
  47529. var needRestore = false;
  47530. if (isPatternFill) {
  47531. ctx.save();
  47532. if (this.baseTransform) {
  47533. ctx.setTransform.apply(ctx, this.baseTransform);
  47534. }
  47535. ctx.fillStyle = fillColor.getPattern(ctx, this);
  47536. needRestore = true;
  47537. }
  47538. if (this.pendingEOFill) {
  47539. if (ctx.mozFillRule !== undefined) {
  47540. ctx.mozFillRule = 'evenodd';
  47541. ctx.fill();
  47542. ctx.mozFillRule = 'nonzero';
  47543. } else {
  47544. ctx.fill('evenodd');
  47545. }
  47546. this.pendingEOFill = false;
  47547. } else {
  47548. ctx.fill();
  47549. }
  47550. if (needRestore) {
  47551. ctx.restore();
  47552. }
  47553. if (consumePath) {
  47554. this.consumePath();
  47555. }
  47556. },
  47557. eoFill: function CanvasGraphics_eoFill() {
  47558. this.pendingEOFill = true;
  47559. this.fill();
  47560. },
  47561. fillStroke: function CanvasGraphics_fillStroke() {
  47562. this.fill(false);
  47563. this.stroke(false);
  47564. this.consumePath();
  47565. },
  47566. eoFillStroke: function CanvasGraphics_eoFillStroke() {
  47567. this.pendingEOFill = true;
  47568. this.fillStroke();
  47569. },
  47570. closeFillStroke: function CanvasGraphics_closeFillStroke() {
  47571. this.closePath();
  47572. this.fillStroke();
  47573. },
  47574. closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
  47575. this.pendingEOFill = true;
  47576. this.closePath();
  47577. this.fillStroke();
  47578. },
  47579. endPath: function CanvasGraphics_endPath() {
  47580. this.consumePath();
  47581. },
  47582. // Clipping
  47583. clip: function CanvasGraphics_clip() {
  47584. this.pendingClip = NORMAL_CLIP;
  47585. },
  47586. eoClip: function CanvasGraphics_eoClip() {
  47587. this.pendingClip = EO_CLIP;
  47588. },
  47589. // Text
  47590. beginText: function CanvasGraphics_beginText() {
  47591. this.current.textMatrix = IDENTITY_MATRIX;
  47592. this.current.textMatrixScale = 1;
  47593. this.current.x = this.current.lineX = 0;
  47594. this.current.y = this.current.lineY = 0;
  47595. },
  47596. endText: function CanvasGraphics_endText() {
  47597. var paths = this.pendingTextPaths;
  47598. var ctx = this.ctx;
  47599. if (paths === undefined) {
  47600. ctx.beginPath();
  47601. return;
  47602. }
  47603. ctx.save();
  47604. ctx.beginPath();
  47605. for (var i = 0; i < paths.length; i++) {
  47606. var path = paths[i];
  47607. ctx.setTransform.apply(ctx, path.transform);
  47608. ctx.translate(path.x, path.y);
  47609. path.addToPath(ctx, path.fontSize);
  47610. }
  47611. ctx.restore();
  47612. ctx.clip();
  47613. ctx.beginPath();
  47614. delete this.pendingTextPaths;
  47615. },
  47616. setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
  47617. this.current.charSpacing = spacing;
  47618. },
  47619. setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
  47620. this.current.wordSpacing = spacing;
  47621. },
  47622. setHScale: function CanvasGraphics_setHScale(scale) {
  47623. this.current.textHScale = scale / 100;
  47624. },
  47625. setLeading: function CanvasGraphics_setLeading(leading) {
  47626. this.current.leading = -leading;
  47627. },
  47628. setFont: function CanvasGraphics_setFont(fontRefName, size) {
  47629. var fontObj = this.commonObjs.get(fontRefName);
  47630. var current = this.current;
  47631. if (!fontObj) {
  47632. error('Can\'t find font for ' + fontRefName);
  47633. }
  47634. current.fontMatrix = fontObj.fontMatrix ? fontObj.fontMatrix : FONT_IDENTITY_MATRIX;
  47635. // A valid matrix needs all main diagonal elements to be non-zero
  47636. // This also ensures we bypass FF bugzilla bug #719844.
  47637. if (current.fontMatrix[0] === 0 || current.fontMatrix[3] === 0) {
  47638. warn('Invalid font matrix for font ' + fontRefName);
  47639. }
  47640. // The spec for Tf (setFont) says that 'size' specifies the font 'scale',
  47641. // and in some docs this can be negative (inverted x-y axes).
  47642. if (size < 0) {
  47643. size = -size;
  47644. current.fontDirection = -1;
  47645. } else {
  47646. current.fontDirection = 1;
  47647. }
  47648. this.current.font = fontObj;
  47649. this.current.fontSize = size;
  47650. if (fontObj.isType3Font) {
  47651. return;
  47652. }
  47653. // we don't need ctx.font for Type3 fonts
  47654. var name = fontObj.loadedName || 'sans-serif';
  47655. var bold = fontObj.black ? fontObj.bold ? '900' : 'bold' : fontObj.bold ? 'bold' : 'normal';
  47656. var italic = fontObj.italic ? 'italic' : 'normal';
  47657. var typeface = '"' + name + '", ' + fontObj.fallbackName;
  47658. // Some font backends cannot handle fonts below certain size.
  47659. // Keeping the font at minimal size and using the fontSizeScale to change
  47660. // the current transformation matrix before the fillText/strokeText.
  47661. // See https://bugzilla.mozilla.org/show_bug.cgi?id=726227
  47662. var browserFontSize = size < MIN_FONT_SIZE ? MIN_FONT_SIZE : size > MAX_FONT_SIZE ? MAX_FONT_SIZE : size;
  47663. this.current.fontSizeScale = size / browserFontSize;
  47664. var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
  47665. this.ctx.font = rule;
  47666. },
  47667. setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
  47668. this.current.textRenderingMode = mode;
  47669. },
  47670. setTextRise: function CanvasGraphics_setTextRise(rise) {
  47671. this.current.textRise = rise;
  47672. },
  47673. moveText: function CanvasGraphics_moveText(x, y) {
  47674. this.current.x = this.current.lineX += x;
  47675. this.current.y = this.current.lineY += y;
  47676. },
  47677. setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
  47678. this.setLeading(-y);
  47679. this.moveText(x, y);
  47680. },
  47681. setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
  47682. this.current.textMatrix = [
  47683. a,
  47684. b,
  47685. c,
  47686. d,
  47687. e,
  47688. f
  47689. ];
  47690. this.current.textMatrixScale = Math.sqrt(a * a + b * b);
  47691. this.current.x = this.current.lineX = 0;
  47692. this.current.y = this.current.lineY = 0;
  47693. },
  47694. nextLine: function CanvasGraphics_nextLine() {
  47695. this.moveText(0, this.current.leading);
  47696. },
  47697. paintChar: function CanvasGraphics_paintChar(character, x, y) {
  47698. var ctx = this.ctx;
  47699. var current = this.current;
  47700. var font = current.font;
  47701. var textRenderingMode = current.textRenderingMode;
  47702. var fontSize = current.fontSize / current.fontSizeScale;
  47703. var fillStrokeMode = textRenderingMode & TextRenderingMode.FILL_STROKE_MASK;
  47704. var isAddToPathSet = !!(textRenderingMode & TextRenderingMode.ADD_TO_PATH_FLAG);
  47705. var addToPath;
  47706. if (font.disableFontFace || isAddToPathSet) {
  47707. addToPath = font.getPathGenerator(this.commonObjs, character);
  47708. }
  47709. if (font.disableFontFace) {
  47710. ctx.save();
  47711. ctx.translate(x, y);
  47712. ctx.beginPath();
  47713. addToPath(ctx, fontSize);
  47714. if (fillStrokeMode === TextRenderingMode.FILL || fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  47715. ctx.fill();
  47716. }
  47717. if (fillStrokeMode === TextRenderingMode.STROKE || fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  47718. ctx.stroke();
  47719. }
  47720. ctx.restore();
  47721. } else {
  47722. if (fillStrokeMode === TextRenderingMode.FILL || fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  47723. ctx.fillText(character, x, y);
  47724. }
  47725. if (fillStrokeMode === TextRenderingMode.STROKE || fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  47726. ctx.strokeText(character, x, y);
  47727. }
  47728. }
  47729. if (isAddToPathSet) {
  47730. var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  47731. paths.push({
  47732. transform: ctx.mozCurrentTransform,
  47733. x: x,
  47734. y: y,
  47735. fontSize: fontSize,
  47736. addToPath: addToPath
  47737. });
  47738. }
  47739. },
  47740. get isFontSubpixelAAEnabled() {
  47741. // Checks if anti-aliasing is enabled when scaled text is painted.
  47742. // On Windows GDI scaled fonts looks bad.
  47743. var ctx = document.createElement('canvas').getContext('2d');
  47744. ctx.scale(1.5, 1);
  47745. ctx.fillText('I', 0, 10);
  47746. var data = ctx.getImageData(0, 0, 10, 10).data;
  47747. var enabled = false;
  47748. for (var i = 3; i < data.length; i += 4) {
  47749. if (data[i] > 0 && data[i] < 255) {
  47750. enabled = true;
  47751. break;
  47752. }
  47753. }
  47754. return shadow(this, 'isFontSubpixelAAEnabled', enabled);
  47755. },
  47756. showText: function CanvasGraphics_showText(glyphs) {
  47757. var current = this.current;
  47758. var font = current.font;
  47759. if (font.isType3Font) {
  47760. return this.showType3Text(glyphs);
  47761. }
  47762. var fontSize = current.fontSize;
  47763. if (fontSize === 0) {
  47764. return;
  47765. }
  47766. var ctx = this.ctx;
  47767. var fontSizeScale = current.fontSizeScale;
  47768. var charSpacing = current.charSpacing;
  47769. var wordSpacing = current.wordSpacing;
  47770. var fontDirection = current.fontDirection;
  47771. var textHScale = current.textHScale * fontDirection;
  47772. var glyphsLength = glyphs.length;
  47773. var vertical = font.vertical;
  47774. var spacingDir = vertical ? 1 : -1;
  47775. var defaultVMetrics = font.defaultVMetrics;
  47776. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  47777. var simpleFillText = current.textRenderingMode === TextRenderingMode.FILL && !font.disableFontFace;
  47778. ctx.save();
  47779. ctx.transform.apply(ctx, current.textMatrix);
  47780. ctx.translate(current.x, current.y + current.textRise);
  47781. if (current.patternFill) {
  47782. // TODO: Some shading patterns are not applied correctly to text,
  47783. // e.g. issues 3988 and 5432, and ShowText-ShadingPattern.pdf.
  47784. ctx.fillStyle = current.fillColor.getPattern(ctx, this);
  47785. }
  47786. if (fontDirection > 0) {
  47787. ctx.scale(textHScale, -1);
  47788. } else {
  47789. ctx.scale(textHScale, 1);
  47790. }
  47791. var lineWidth = current.lineWidth;
  47792. var scale = current.textMatrixScale;
  47793. if (scale === 0 || lineWidth === 0) {
  47794. var fillStrokeMode = current.textRenderingMode & TextRenderingMode.FILL_STROKE_MASK;
  47795. if (fillStrokeMode === TextRenderingMode.STROKE || fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  47796. this.cachedGetSinglePixelWidth = null;
  47797. lineWidth = this.getSinglePixelWidth() * MIN_WIDTH_FACTOR;
  47798. }
  47799. } else {
  47800. lineWidth /= scale;
  47801. }
  47802. if (fontSizeScale !== 1.0) {
  47803. ctx.scale(fontSizeScale, fontSizeScale);
  47804. lineWidth /= fontSizeScale;
  47805. }
  47806. ctx.lineWidth = lineWidth;
  47807. var x = 0, i;
  47808. for (i = 0; i < glyphsLength; ++i) {
  47809. var glyph = glyphs[i];
  47810. if (isNum(glyph)) {
  47811. x += spacingDir * glyph * fontSize / 1000;
  47812. continue;
  47813. }
  47814. var restoreNeeded = false;
  47815. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  47816. var character = glyph.fontChar;
  47817. var accent = glyph.accent;
  47818. var scaledX, scaledY, scaledAccentX, scaledAccentY;
  47819. var width = glyph.width;
  47820. if (vertical) {
  47821. var vmetric, vx, vy;
  47822. vmetric = glyph.vmetric || defaultVMetrics;
  47823. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  47824. vx = -vx * widthAdvanceScale;
  47825. vy = vmetric[2] * widthAdvanceScale;
  47826. width = vmetric ? -vmetric[0] : width;
  47827. scaledX = vx / fontSizeScale;
  47828. scaledY = (x + vy) / fontSizeScale;
  47829. } else {
  47830. scaledX = x / fontSizeScale;
  47831. scaledY = 0;
  47832. }
  47833. if (font.remeasure && width > 0) {
  47834. // Some standard fonts may not have the exact width: rescale per
  47835. // character if measured width is greater than expected glyph width
  47836. // and subpixel-aa is enabled, otherwise just center the glyph.
  47837. var measuredWidth = ctx.measureText(character).width * 1000 / fontSize * fontSizeScale;
  47838. if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
  47839. var characterScaleX = width / measuredWidth;
  47840. restoreNeeded = true;
  47841. ctx.save();
  47842. ctx.scale(characterScaleX, 1);
  47843. scaledX /= characterScaleX;
  47844. } else if (width !== measuredWidth) {
  47845. scaledX += (width - measuredWidth) / 2000 * fontSize / fontSizeScale;
  47846. }
  47847. }
  47848. // Only attempt to draw the glyph if it is actually in the embedded font
  47849. // file or if there isn't a font file so the fallback font is shown.
  47850. if (glyph.isInFont || font.missingFile) {
  47851. if (simpleFillText && !accent) {
  47852. // common case
  47853. ctx.fillText(character, scaledX, scaledY);
  47854. } else {
  47855. this.paintChar(character, scaledX, scaledY);
  47856. if (accent) {
  47857. scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
  47858. scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
  47859. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
  47860. }
  47861. }
  47862. }
  47863. var charWidth = width * widthAdvanceScale + spacing * fontDirection;
  47864. x += charWidth;
  47865. if (restoreNeeded) {
  47866. ctx.restore();
  47867. }
  47868. }
  47869. if (vertical) {
  47870. current.y -= x * textHScale;
  47871. } else {
  47872. current.x += x * textHScale;
  47873. }
  47874. ctx.restore();
  47875. },
  47876. showType3Text: function CanvasGraphics_showType3Text(glyphs) {
  47877. // Type3 fonts - each glyph is a "mini-PDF"
  47878. var ctx = this.ctx;
  47879. var current = this.current;
  47880. var font = current.font;
  47881. var fontSize = current.fontSize;
  47882. var fontDirection = current.fontDirection;
  47883. var spacingDir = font.vertical ? 1 : -1;
  47884. var charSpacing = current.charSpacing;
  47885. var wordSpacing = current.wordSpacing;
  47886. var textHScale = current.textHScale * fontDirection;
  47887. var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX;
  47888. var glyphsLength = glyphs.length;
  47889. var isTextInvisible = current.textRenderingMode === TextRenderingMode.INVISIBLE;
  47890. var i, glyph, width, spacingLength;
  47891. if (isTextInvisible || fontSize === 0) {
  47892. return;
  47893. }
  47894. this.cachedGetSinglePixelWidth = null;
  47895. ctx.save();
  47896. ctx.transform.apply(ctx, current.textMatrix);
  47897. ctx.translate(current.x, current.y);
  47898. ctx.scale(textHScale, fontDirection);
  47899. for (i = 0; i < glyphsLength; ++i) {
  47900. glyph = glyphs[i];
  47901. if (isNum(glyph)) {
  47902. spacingLength = spacingDir * glyph * fontSize / 1000;
  47903. this.ctx.translate(spacingLength, 0);
  47904. current.x += spacingLength * textHScale;
  47905. continue;
  47906. }
  47907. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  47908. var operatorList = font.charProcOperatorList[glyph.operatorListId];
  47909. if (!operatorList) {
  47910. warn('Type3 character \"' + glyph.operatorListId + '\" is not available');
  47911. continue;
  47912. }
  47913. this.processingType3 = glyph;
  47914. this.save();
  47915. ctx.scale(fontSize, fontSize);
  47916. ctx.transform.apply(ctx, fontMatrix);
  47917. this.executeOperatorList(operatorList);
  47918. this.restore();
  47919. var transformed = Util.applyTransform([
  47920. glyph.width,
  47921. 0
  47922. ], fontMatrix);
  47923. width = transformed[0] * fontSize + spacing;
  47924. ctx.translate(width, 0);
  47925. current.x += width * textHScale;
  47926. }
  47927. ctx.restore();
  47928. this.processingType3 = null;
  47929. },
  47930. // Type3 fonts
  47931. setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {
  47932. },
  47933. setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth, yWidth, llx, lly, urx, ury) {
  47934. // TODO According to the spec we're also suppose to ignore any operators
  47935. // that set color or include images while processing this type3 font.
  47936. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  47937. this.clip();
  47938. this.endPath();
  47939. },
  47940. // Color
  47941. getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
  47942. var pattern;
  47943. if (IR[0] === 'TilingPattern') {
  47944. var color = IR[1];
  47945. var baseTransform = this.baseTransform || this.ctx.mozCurrentTransform.slice();
  47946. var self = this;
  47947. var canvasGraphicsFactory = {
  47948. createCanvasGraphics: function (ctx) {
  47949. return new CanvasGraphics(ctx, self.commonObjs, self.objs);
  47950. }
  47951. };
  47952. pattern = new TilingPattern(IR, color, this.ctx, canvasGraphicsFactory, baseTransform);
  47953. } else {
  47954. pattern = getShadingPatternFromIR(IR);
  47955. }
  47956. return pattern;
  47957. },
  47958. setStrokeColorN: function CanvasGraphics_setStrokeColorN()
  47959. /*...*/
  47960. {
  47961. this.current.strokeColor = this.getColorN_Pattern(arguments);
  47962. },
  47963. setFillColorN: function CanvasGraphics_setFillColorN()
  47964. /*...*/
  47965. {
  47966. this.current.fillColor = this.getColorN_Pattern(arguments);
  47967. this.current.patternFill = true;
  47968. },
  47969. setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
  47970. var color = Util.makeCssRgb(r, g, b);
  47971. this.ctx.strokeStyle = color;
  47972. this.current.strokeColor = color;
  47973. },
  47974. setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
  47975. var color = Util.makeCssRgb(r, g, b);
  47976. this.ctx.fillStyle = color;
  47977. this.current.fillColor = color;
  47978. this.current.patternFill = false;
  47979. },
  47980. shadingFill: function CanvasGraphics_shadingFill(patternIR) {
  47981. var ctx = this.ctx;
  47982. this.save();
  47983. var pattern = getShadingPatternFromIR(patternIR);
  47984. ctx.fillStyle = pattern.getPattern(ctx, this, true);
  47985. var inv = ctx.mozCurrentTransformInverse;
  47986. if (inv) {
  47987. var canvas = ctx.canvas;
  47988. var width = canvas.width;
  47989. var height = canvas.height;
  47990. var bl = Util.applyTransform([
  47991. 0,
  47992. 0
  47993. ], inv);
  47994. var br = Util.applyTransform([
  47995. 0,
  47996. height
  47997. ], inv);
  47998. var ul = Util.applyTransform([
  47999. width,
  48000. 0
  48001. ], inv);
  48002. var ur = Util.applyTransform([
  48003. width,
  48004. height
  48005. ], inv);
  48006. var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  48007. var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  48008. var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  48009. var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  48010. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  48011. } else {
  48012. // HACK to draw the gradient onto an infinite rectangle.
  48013. // PDF gradients are drawn across the entire image while
  48014. // Canvas only allows gradients to be drawn in a rectangle
  48015. // The following bug should allow us to remove this.
  48016. // https://bugzilla.mozilla.org/show_bug.cgi?id=664884
  48017. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  48018. }
  48019. this.restore();
  48020. },
  48021. // Images
  48022. beginInlineImage: function CanvasGraphics_beginInlineImage() {
  48023. error('Should not call beginInlineImage');
  48024. },
  48025. beginImageData: function CanvasGraphics_beginImageData() {
  48026. error('Should not call beginImageData');
  48027. },
  48028. paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix, bbox) {
  48029. this.save();
  48030. this.baseTransformStack.push(this.baseTransform);
  48031. if (isArray(matrix) && 6 === matrix.length) {
  48032. this.transform.apply(this, matrix);
  48033. }
  48034. this.baseTransform = this.ctx.mozCurrentTransform;
  48035. if (isArray(bbox) && 4 === bbox.length) {
  48036. var width = bbox[2] - bbox[0];
  48037. var height = bbox[3] - bbox[1];
  48038. this.ctx.rect(bbox[0], bbox[1], width, height);
  48039. this.clip();
  48040. this.endPath();
  48041. }
  48042. },
  48043. paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
  48044. this.restore();
  48045. this.baseTransform = this.baseTransformStack.pop();
  48046. },
  48047. beginGroup: function CanvasGraphics_beginGroup(group) {
  48048. this.save();
  48049. var currentCtx = this.ctx;
  48050. // TODO non-isolated groups - according to Rik at adobe non-isolated
  48051. // group results aren't usually that different and they even have tools
  48052. // that ignore this setting. Notes from Rik on implementing:
  48053. // - When you encounter an transparency group, create a new canvas with
  48054. // the dimensions of the bbox
  48055. // - copy the content from the previous canvas to the new canvas
  48056. // - draw as usual
  48057. // - remove the backdrop alpha:
  48058. // alphaNew = 1 - (1 - alpha)/(1 - alphaBackdrop) with 'alpha' the alpha
  48059. // value of your transparency group and 'alphaBackdrop' the alpha of the
  48060. // backdrop
  48061. // - remove background color:
  48062. // colorNew = color - alphaNew *colorBackdrop /(1 - alphaNew)
  48063. if (!group.isolated) {
  48064. info('TODO: Support non-isolated groups.');
  48065. }
  48066. // TODO knockout - supposedly possible with the clever use of compositing
  48067. // modes.
  48068. if (group.knockout) {
  48069. warn('Knockout groups not supported.');
  48070. }
  48071. var currentTransform = currentCtx.mozCurrentTransform;
  48072. if (group.matrix) {
  48073. currentCtx.transform.apply(currentCtx, group.matrix);
  48074. }
  48075. assert(group.bbox, 'Bounding box is required.');
  48076. // Based on the current transform figure out how big the bounding box
  48077. // will actually be.
  48078. var bounds = Util.getAxialAlignedBoundingBox(group.bbox, currentCtx.mozCurrentTransform);
  48079. // Clip the bounding box to the current canvas.
  48080. var canvasBounds = [
  48081. 0,
  48082. 0,
  48083. currentCtx.canvas.width,
  48084. currentCtx.canvas.height
  48085. ];
  48086. bounds = Util.intersect(bounds, canvasBounds) || [
  48087. 0,
  48088. 0,
  48089. 0,
  48090. 0
  48091. ];
  48092. // Use ceil in case we're between sizes so we don't create canvas that is
  48093. // too small and make the canvas at least 1x1 pixels.
  48094. var offsetX = Math.floor(bounds[0]);
  48095. var offsetY = Math.floor(bounds[1]);
  48096. var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  48097. var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  48098. var scaleX = 1, scaleY = 1;
  48099. if (drawnWidth > MAX_GROUP_SIZE) {
  48100. scaleX = drawnWidth / MAX_GROUP_SIZE;
  48101. drawnWidth = MAX_GROUP_SIZE;
  48102. }
  48103. if (drawnHeight > MAX_GROUP_SIZE) {
  48104. scaleY = drawnHeight / MAX_GROUP_SIZE;
  48105. drawnHeight = MAX_GROUP_SIZE;
  48106. }
  48107. var cacheId = 'groupAt' + this.groupLevel;
  48108. if (group.smask) {
  48109. // Using two cache entries is case if masks are used one after another.
  48110. cacheId += '_smask_' + this.smaskCounter++ % 2;
  48111. }
  48112. var scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight, true);
  48113. var groupCtx = scratchCanvas.context;
  48114. // Since we created a new canvas that is just the size of the bounding box
  48115. // we have to translate the group ctx.
  48116. groupCtx.scale(1 / scaleX, 1 / scaleY);
  48117. groupCtx.translate(-offsetX, -offsetY);
  48118. groupCtx.transform.apply(groupCtx, currentTransform);
  48119. if (group.smask) {
  48120. // Saving state and cached mask to be used in setGState.
  48121. this.smaskStack.push({
  48122. canvas: scratchCanvas.canvas,
  48123. context: groupCtx,
  48124. offsetX: offsetX,
  48125. offsetY: offsetY,
  48126. scaleX: scaleX,
  48127. scaleY: scaleY,
  48128. subtype: group.smask.subtype,
  48129. backdrop: group.smask.backdrop,
  48130. transferMap: group.smask.transferMap || null,
  48131. startTransformInverse: null
  48132. });
  48133. } else
  48134. // used during suspend operation
  48135. {
  48136. // Setup the current ctx so when the group is popped we draw it at the
  48137. // right location.
  48138. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  48139. currentCtx.translate(offsetX, offsetY);
  48140. currentCtx.scale(scaleX, scaleY);
  48141. }
  48142. // The transparency group inherits all off the current graphics state
  48143. // except the blend mode, soft mask, and alpha constants.
  48144. copyCtxState(currentCtx, groupCtx);
  48145. this.ctx = groupCtx;
  48146. this.setGState([
  48147. [
  48148. 'BM',
  48149. 'Normal'
  48150. ],
  48151. [
  48152. 'ca',
  48153. 1
  48154. ],
  48155. [
  48156. 'CA',
  48157. 1
  48158. ]
  48159. ]);
  48160. this.groupStack.push(currentCtx);
  48161. this.groupLevel++;
  48162. // Reseting mask state, masks will be applied on restore of the group.
  48163. this.current.activeSMask = null;
  48164. },
  48165. endGroup: function CanvasGraphics_endGroup(group) {
  48166. this.groupLevel--;
  48167. var groupCtx = this.ctx;
  48168. this.ctx = this.groupStack.pop();
  48169. // Turn off image smoothing to avoid sub pixel interpolation which can
  48170. // look kind of blurry for some pdfs.
  48171. if (this.ctx.imageSmoothingEnabled !== undefined) {
  48172. this.ctx.imageSmoothingEnabled = false;
  48173. } else {
  48174. this.ctx.mozImageSmoothingEnabled = false;
  48175. }
  48176. if (group.smask) {
  48177. this.tempSMask = this.smaskStack.pop();
  48178. } else {
  48179. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  48180. }
  48181. this.restore();
  48182. },
  48183. beginAnnotations: function CanvasGraphics_beginAnnotations() {
  48184. this.save();
  48185. this.current = new CanvasExtraState();
  48186. if (this.baseTransform) {
  48187. this.ctx.setTransform.apply(this.ctx, this.baseTransform);
  48188. }
  48189. },
  48190. endAnnotations: function CanvasGraphics_endAnnotations() {
  48191. this.restore();
  48192. },
  48193. beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform, matrix) {
  48194. this.save();
  48195. if (isArray(rect) && 4 === rect.length) {
  48196. var width = rect[2] - rect[0];
  48197. var height = rect[3] - rect[1];
  48198. this.ctx.rect(rect[0], rect[1], width, height);
  48199. this.clip();
  48200. this.endPath();
  48201. }
  48202. this.transform.apply(this, transform);
  48203. this.transform.apply(this, matrix);
  48204. },
  48205. endAnnotation: function CanvasGraphics_endAnnotation() {
  48206. this.restore();
  48207. },
  48208. paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
  48209. var domImage = this.objs.get(objId);
  48210. if (!domImage) {
  48211. warn('Dependent image isn\'t ready yet');
  48212. return;
  48213. }
  48214. this.save();
  48215. var ctx = this.ctx;
  48216. // scale the image to the unit square
  48217. ctx.scale(1 / w, -1 / h);
  48218. ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height, 0, -h, w, h);
  48219. if (this.imageLayer) {
  48220. var currentTransform = ctx.mozCurrentTransformInverse;
  48221. var position = this.getCanvasPosition(0, 0);
  48222. this.imageLayer.appendImage({
  48223. objId: objId,
  48224. left: position[0],
  48225. top: position[1],
  48226. width: w / currentTransform[0],
  48227. height: h / currentTransform[3]
  48228. });
  48229. }
  48230. this.restore();
  48231. },
  48232. paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
  48233. var ctx = this.ctx;
  48234. var width = img.width, height = img.height;
  48235. var fillColor = this.current.fillColor;
  48236. var isPatternFill = this.current.patternFill;
  48237. var glyph = this.processingType3;
  48238. if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) {
  48239. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  48240. glyph.compiled = compileType3Glyph({
  48241. data: img.data,
  48242. width: width,
  48243. height: height
  48244. });
  48245. } else {
  48246. glyph.compiled = null;
  48247. }
  48248. }
  48249. if (glyph && glyph.compiled) {
  48250. glyph.compiled(ctx);
  48251. return;
  48252. }
  48253. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas', width, height);
  48254. var maskCtx = maskCanvas.context;
  48255. maskCtx.save();
  48256. putBinaryImageMask(maskCtx, img);
  48257. maskCtx.globalCompositeOperation = 'source-in';
  48258. maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor;
  48259. maskCtx.fillRect(0, 0, width, height);
  48260. maskCtx.restore();
  48261. this.paintInlineImageXObject(maskCanvas.canvas);
  48262. },
  48263. paintImageMaskXObjectRepeat: function CanvasGraphics_paintImageMaskXObjectRepeat(imgData, scaleX, scaleY, positions) {
  48264. var width = imgData.width;
  48265. var height = imgData.height;
  48266. var fillColor = this.current.fillColor;
  48267. var isPatternFill = this.current.patternFill;
  48268. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas', width, height);
  48269. var maskCtx = maskCanvas.context;
  48270. maskCtx.save();
  48271. putBinaryImageMask(maskCtx, imgData);
  48272. maskCtx.globalCompositeOperation = 'source-in';
  48273. maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor;
  48274. maskCtx.fillRect(0, 0, width, height);
  48275. maskCtx.restore();
  48276. var ctx = this.ctx;
  48277. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  48278. ctx.save();
  48279. ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]);
  48280. ctx.scale(1, -1);
  48281. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height, 0, -1, 1, 1);
  48282. ctx.restore();
  48283. }
  48284. },
  48285. paintImageMaskXObjectGroup: function CanvasGraphics_paintImageMaskXObjectGroup(images) {
  48286. var ctx = this.ctx;
  48287. var fillColor = this.current.fillColor;
  48288. var isPatternFill = this.current.patternFill;
  48289. for (var i = 0, ii = images.length; i < ii; i++) {
  48290. var image = images[i];
  48291. var width = image.width, height = image.height;
  48292. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas', width, height);
  48293. var maskCtx = maskCanvas.context;
  48294. maskCtx.save();
  48295. putBinaryImageMask(maskCtx, image);
  48296. maskCtx.globalCompositeOperation = 'source-in';
  48297. maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor;
  48298. maskCtx.fillRect(0, 0, width, height);
  48299. maskCtx.restore();
  48300. ctx.save();
  48301. ctx.transform.apply(ctx, image.transform);
  48302. ctx.scale(1, -1);
  48303. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height, 0, -1, 1, 1);
  48304. ctx.restore();
  48305. }
  48306. },
  48307. paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
  48308. var imgData = this.objs.get(objId);
  48309. if (!imgData) {
  48310. warn('Dependent image isn\'t ready yet');
  48311. return;
  48312. }
  48313. this.paintInlineImageXObject(imgData);
  48314. },
  48315. paintImageXObjectRepeat: function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY, positions) {
  48316. var imgData = this.objs.get(objId);
  48317. if (!imgData) {
  48318. warn('Dependent image isn\'t ready yet');
  48319. return;
  48320. }
  48321. var width = imgData.width;
  48322. var height = imgData.height;
  48323. var map = [];
  48324. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  48325. map.push({
  48326. transform: [
  48327. scaleX,
  48328. 0,
  48329. 0,
  48330. scaleY,
  48331. positions[i],
  48332. positions[i + 1]
  48333. ],
  48334. x: 0,
  48335. y: 0,
  48336. w: width,
  48337. h: height
  48338. });
  48339. }
  48340. this.paintInlineImageXObjectGroup(imgData, map);
  48341. },
  48342. paintInlineImageXObject: function CanvasGraphics_paintInlineImageXObject(imgData) {
  48343. var width = imgData.width;
  48344. var height = imgData.height;
  48345. var ctx = this.ctx;
  48346. this.save();
  48347. // scale the image to the unit square
  48348. ctx.scale(1 / width, -1 / height);
  48349. var currentTransform = ctx.mozCurrentTransformInverse;
  48350. var a = currentTransform[0], b = currentTransform[1];
  48351. var widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
  48352. var c = currentTransform[2], d = currentTransform[3];
  48353. var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
  48354. var imgToPaint, tmpCanvas;
  48355. // instanceof HTMLElement does not work in jsdom node.js module
  48356. if (imgData instanceof HTMLElement || !imgData.data) {
  48357. imgToPaint = imgData;
  48358. } else {
  48359. tmpCanvas = this.cachedCanvases.getCanvas('inlineImage', width, height);
  48360. var tmpCtx = tmpCanvas.context;
  48361. putBinaryImageData(tmpCtx, imgData);
  48362. imgToPaint = tmpCanvas.canvas;
  48363. }
  48364. var paintWidth = width, paintHeight = height;
  48365. var tmpCanvasId = 'prescale1';
  48366. // Vertial or horizontal scaling shall not be more than 2 to not loose the
  48367. // pixels during drawImage operation, painting on the temporary canvas(es)
  48368. // that are twice smaller in size
  48369. while (widthScale > 2 && paintWidth > 1 || heightScale > 2 && paintHeight > 1) {
  48370. var newWidth = paintWidth, newHeight = paintHeight;
  48371. if (widthScale > 2 && paintWidth > 1) {
  48372. newWidth = Math.ceil(paintWidth / 2);
  48373. widthScale /= paintWidth / newWidth;
  48374. }
  48375. if (heightScale > 2 && paintHeight > 1) {
  48376. newHeight = Math.ceil(paintHeight / 2);
  48377. heightScale /= paintHeight / newHeight;
  48378. }
  48379. tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight);
  48380. tmpCtx = tmpCanvas.context;
  48381. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  48382. tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight, 0, 0, newWidth, newHeight);
  48383. imgToPaint = tmpCanvas.canvas;
  48384. paintWidth = newWidth;
  48385. paintHeight = newHeight;
  48386. tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1';
  48387. }
  48388. ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight, 0, -height, width, height);
  48389. if (this.imageLayer) {
  48390. var position = this.getCanvasPosition(0, -height);
  48391. this.imageLayer.appendImage({
  48392. imgData: imgData,
  48393. left: position[0],
  48394. top: position[1],
  48395. width: width / currentTransform[0],
  48396. height: height / currentTransform[3]
  48397. });
  48398. }
  48399. this.restore();
  48400. },
  48401. paintInlineImageXObjectGroup: function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
  48402. var ctx = this.ctx;
  48403. var w = imgData.width;
  48404. var h = imgData.height;
  48405. var tmpCanvas = this.cachedCanvases.getCanvas('inlineImage', w, h);
  48406. var tmpCtx = tmpCanvas.context;
  48407. putBinaryImageData(tmpCtx, imgData);
  48408. for (var i = 0, ii = map.length; i < ii; i++) {
  48409. var entry = map[i];
  48410. ctx.save();
  48411. ctx.transform.apply(ctx, entry.transform);
  48412. ctx.scale(1, -1);
  48413. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h, 0, -1, 1, 1);
  48414. if (this.imageLayer) {
  48415. var position = this.getCanvasPosition(entry.x, entry.y);
  48416. this.imageLayer.appendImage({
  48417. imgData: imgData,
  48418. left: position[0],
  48419. top: position[1],
  48420. width: w,
  48421. height: h
  48422. });
  48423. }
  48424. ctx.restore();
  48425. }
  48426. },
  48427. paintSolidColorImageMask: function CanvasGraphics_paintSolidColorImageMask() {
  48428. this.ctx.fillRect(0, 0, 1, 1);
  48429. },
  48430. paintXObject: function CanvasGraphics_paintXObject() {
  48431. warn('Unsupported \'paintXObject\' command.');
  48432. },
  48433. // Marked content
  48434. markPoint: function CanvasGraphics_markPoint(tag) {
  48435. },
  48436. markPointProps: function CanvasGraphics_markPointProps(tag, properties) {
  48437. },
  48438. beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {
  48439. },
  48440. beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(tag, properties) {
  48441. },
  48442. endMarkedContent: function CanvasGraphics_endMarkedContent() {
  48443. },
  48444. // Compatibility
  48445. beginCompat: function CanvasGraphics_beginCompat() {
  48446. },
  48447. endCompat: function CanvasGraphics_endCompat() {
  48448. },
  48449. // Helper functions
  48450. consumePath: function CanvasGraphics_consumePath() {
  48451. var ctx = this.ctx;
  48452. if (this.pendingClip) {
  48453. if (this.pendingClip === EO_CLIP) {
  48454. if (ctx.mozFillRule !== undefined) {
  48455. ctx.mozFillRule = 'evenodd';
  48456. ctx.clip();
  48457. ctx.mozFillRule = 'nonzero';
  48458. } else {
  48459. ctx.clip('evenodd');
  48460. }
  48461. } else {
  48462. ctx.clip();
  48463. }
  48464. this.pendingClip = null;
  48465. }
  48466. ctx.beginPath();
  48467. },
  48468. getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
  48469. if (this.cachedGetSinglePixelWidth === null) {
  48470. // NOTE: The `save` and `restore` commands used below is a workaround
  48471. // that is necessary in order to prevent `mozCurrentTransformInverse`
  48472. // from intermittently returning incorrect values in Firefox, see:
  48473. // https://github.com/mozilla/pdf.js/issues/7188.
  48474. this.ctx.save();
  48475. var inverse = this.ctx.mozCurrentTransformInverse;
  48476. this.ctx.restore();
  48477. // max of the current horizontal and vertical scale
  48478. this.cachedGetSinglePixelWidth = Math.sqrt(Math.max(inverse[0] * inverse[0] + inverse[1] * inverse[1], inverse[2] * inverse[2] + inverse[3] * inverse[3]));
  48479. }
  48480. return this.cachedGetSinglePixelWidth;
  48481. },
  48482. getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
  48483. var transform = this.ctx.mozCurrentTransform;
  48484. return [
  48485. transform[0] * x + transform[2] * y + transform[4],
  48486. transform[1] * x + transform[3] * y + transform[5]
  48487. ];
  48488. }
  48489. };
  48490. for (var op in OPS) {
  48491. CanvasGraphics.prototype[OPS[op]] = CanvasGraphics.prototype[op];
  48492. }
  48493. return CanvasGraphics;
  48494. }();
  48495. exports.CanvasGraphics = CanvasGraphics;
  48496. exports.createScratchCanvas = createScratchCanvas;
  48497. }));
  48498. (function (root, factory) {
  48499. factory(root.pdfjsCoreFunction = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCorePsParser);
  48500. }(this, function (exports, sharedUtil, corePrimitives, corePsParser) {
  48501. var error = sharedUtil.error;
  48502. var info = sharedUtil.info;
  48503. var isArray = sharedUtil.isArray;
  48504. var isBool = sharedUtil.isBool;
  48505. var isDict = corePrimitives.isDict;
  48506. var isStream = corePrimitives.isStream;
  48507. var PostScriptLexer = corePsParser.PostScriptLexer;
  48508. var PostScriptParser = corePsParser.PostScriptParser;
  48509. var PDFFunction = function PDFFunctionClosure() {
  48510. var CONSTRUCT_SAMPLED = 0;
  48511. var CONSTRUCT_INTERPOLATED = 2;
  48512. var CONSTRUCT_STICHED = 3;
  48513. var CONSTRUCT_POSTSCRIPT = 4;
  48514. return {
  48515. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps, str) {
  48516. var i, ii;
  48517. var length = 1;
  48518. for (i = 0, ii = size.length; i < ii; i++) {
  48519. length *= size[i];
  48520. }
  48521. length *= outputSize;
  48522. var array = new Array(length);
  48523. var codeSize = 0;
  48524. var codeBuf = 0;
  48525. // 32 is a valid bps so shifting won't work
  48526. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  48527. var strBytes = str.getBytes((length * bps + 7) / 8);
  48528. var strIdx = 0;
  48529. for (i = 0; i < length; i++) {
  48530. while (codeSize < bps) {
  48531. codeBuf <<= 8;
  48532. codeBuf |= strBytes[strIdx++];
  48533. codeSize += 8;
  48534. }
  48535. codeSize -= bps;
  48536. array[i] = (codeBuf >> codeSize) * sampleMul;
  48537. codeBuf &= (1 << codeSize) - 1;
  48538. }
  48539. return array;
  48540. },
  48541. getIR: function PDFFunction_getIR(xref, fn) {
  48542. var dict = fn.dict;
  48543. if (!dict) {
  48544. dict = fn;
  48545. }
  48546. var types = [
  48547. this.constructSampled,
  48548. null,
  48549. this.constructInterpolated,
  48550. this.constructStiched,
  48551. this.constructPostScript
  48552. ];
  48553. var typeNum = dict.get('FunctionType');
  48554. var typeFn = types[typeNum];
  48555. if (!typeFn) {
  48556. error('Unknown type of function');
  48557. }
  48558. return typeFn.call(this, fn, dict, xref);
  48559. },
  48560. fromIR: function PDFFunction_fromIR(IR) {
  48561. var type = IR[0];
  48562. switch (type) {
  48563. case CONSTRUCT_SAMPLED:
  48564. return this.constructSampledFromIR(IR);
  48565. case CONSTRUCT_INTERPOLATED:
  48566. return this.constructInterpolatedFromIR(IR);
  48567. case CONSTRUCT_STICHED:
  48568. return this.constructStichedFromIR(IR);
  48569. //case CONSTRUCT_POSTSCRIPT:
  48570. default:
  48571. return this.constructPostScriptFromIR(IR);
  48572. }
  48573. },
  48574. parse: function PDFFunction_parse(xref, fn) {
  48575. var IR = this.getIR(xref, fn);
  48576. return this.fromIR(IR);
  48577. },
  48578. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  48579. if (!isArray(fnObj)) {
  48580. // not an array -- parsing as regular function
  48581. return this.parse(xref, fnObj);
  48582. }
  48583. var fnArray = [];
  48584. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  48585. var obj = xref.fetchIfRef(fnObj[j]);
  48586. fnArray.push(PDFFunction.parse(xref, obj));
  48587. }
  48588. return function (src, srcOffset, dest, destOffset) {
  48589. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  48590. fnArray[i](src, srcOffset, dest, destOffset + i);
  48591. }
  48592. };
  48593. },
  48594. constructSampled: function PDFFunction_constructSampled(str, dict) {
  48595. function toMultiArray(arr) {
  48596. var inputLength = arr.length;
  48597. var out = [];
  48598. var index = 0;
  48599. for (var i = 0; i < inputLength; i += 2) {
  48600. out[index] = [
  48601. arr[i],
  48602. arr[i + 1]
  48603. ];
  48604. ++index;
  48605. }
  48606. return out;
  48607. }
  48608. var domain = dict.getArray('Domain');
  48609. var range = dict.getArray('Range');
  48610. if (!domain || !range) {
  48611. error('No domain or range');
  48612. }
  48613. var inputSize = domain.length / 2;
  48614. var outputSize = range.length / 2;
  48615. domain = toMultiArray(domain);
  48616. range = toMultiArray(range);
  48617. var size = dict.get('Size');
  48618. var bps = dict.get('BitsPerSample');
  48619. var order = dict.get('Order') || 1;
  48620. if (order !== 1) {
  48621. // No description how cubic spline interpolation works in PDF32000:2008
  48622. // As in poppler, ignoring order, linear interpolation may work as good
  48623. info('No support for cubic spline interpolation: ' + order);
  48624. }
  48625. var encode = dict.getArray('Encode');
  48626. if (!encode) {
  48627. encode = [];
  48628. for (var i = 0; i < inputSize; ++i) {
  48629. encode.push(0);
  48630. encode.push(size[i] - 1);
  48631. }
  48632. }
  48633. encode = toMultiArray(encode);
  48634. var decode = dict.getArray('Decode');
  48635. if (!decode) {
  48636. decode = range;
  48637. } else {
  48638. decode = toMultiArray(decode);
  48639. }
  48640. var samples = this.getSampleArray(size, outputSize, bps, str);
  48641. return [
  48642. CONSTRUCT_SAMPLED,
  48643. inputSize,
  48644. domain,
  48645. encode,
  48646. decode,
  48647. samples,
  48648. size,
  48649. outputSize,
  48650. Math.pow(2, bps) - 1,
  48651. range
  48652. ];
  48653. },
  48654. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  48655. // See chapter 3, page 109 of the PDF reference
  48656. function interpolate(x, xmin, xmax, ymin, ymax) {
  48657. return ymin + (x - xmin) * ((ymax - ymin) / (xmax - xmin));
  48658. }
  48659. return function constructSampledFromIRResult(src, srcOffset, dest, destOffset) {
  48660. // See chapter 3, page 110 of the PDF reference.
  48661. var m = IR[1];
  48662. var domain = IR[2];
  48663. var encode = IR[3];
  48664. var decode = IR[4];
  48665. var samples = IR[5];
  48666. var size = IR[6];
  48667. var n = IR[7];
  48668. //var mask = IR[8];
  48669. var range = IR[9];
  48670. // Building the cube vertices: its part and sample index
  48671. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  48672. var cubeVertices = 1 << m;
  48673. var cubeN = new Float64Array(cubeVertices);
  48674. var cubeVertex = new Uint32Array(cubeVertices);
  48675. var i, j;
  48676. for (j = 0; j < cubeVertices; j++) {
  48677. cubeN[j] = 1;
  48678. }
  48679. var k = n, pos = 1;
  48680. // Map x_i to y_j for 0 <= i < m using the sampled function.
  48681. for (i = 0; i < m; ++i) {
  48682. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  48683. var domain_2i = domain[i][0];
  48684. var domain_2i_1 = domain[i][1];
  48685. var xi = Math.min(Math.max(src[srcOffset + i], domain_2i), domain_2i_1);
  48686. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  48687. // Encode_2i, Encode_2i+1)
  48688. var e = interpolate(xi, domain_2i, domain_2i_1, encode[i][0], encode[i][1]);
  48689. // e_i' = min(max(e_i, 0), Size_i - 1)
  48690. var size_i = size[i];
  48691. e = Math.min(Math.max(e, 0), size_i - 1);
  48692. // Adjusting the cube: N and vertex sample index
  48693. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1;
  48694. // e1 = e0 + 1;
  48695. var n0 = e0 + 1 - e;
  48696. // (e1 - e) / (e1 - e0);
  48697. var n1 = e - e0;
  48698. // (e - e0) / (e1 - e0);
  48699. var offset0 = e0 * k;
  48700. var offset1 = offset0 + k;
  48701. // e1 * k
  48702. for (j = 0; j < cubeVertices; j++) {
  48703. if (j & pos) {
  48704. cubeN[j] *= n1;
  48705. cubeVertex[j] += offset1;
  48706. } else {
  48707. cubeN[j] *= n0;
  48708. cubeVertex[j] += offset0;
  48709. }
  48710. }
  48711. k *= size_i;
  48712. pos <<= 1;
  48713. }
  48714. for (j = 0; j < n; ++j) {
  48715. // Sum all cube vertices' samples portions
  48716. var rj = 0;
  48717. for (i = 0; i < cubeVertices; i++) {
  48718. rj += samples[cubeVertex[i] + j] * cubeN[i];
  48719. }
  48720. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  48721. // Decode_2j, Decode_2j+1)
  48722. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  48723. // y_j = min(max(r_j, range_2j), range_2j+1)
  48724. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]), range[j][1]);
  48725. }
  48726. };
  48727. },
  48728. constructInterpolated: function PDFFunction_constructInterpolated(str, dict) {
  48729. var c0 = dict.getArray('C0') || [0];
  48730. var c1 = dict.getArray('C1') || [1];
  48731. var n = dict.get('N');
  48732. if (!isArray(c0) || !isArray(c1)) {
  48733. error('Illegal dictionary for interpolated function');
  48734. }
  48735. var length = c0.length;
  48736. var diff = [];
  48737. for (var i = 0; i < length; ++i) {
  48738. diff.push(c1[i] - c0[i]);
  48739. }
  48740. return [
  48741. CONSTRUCT_INTERPOLATED,
  48742. c0,
  48743. diff,
  48744. n
  48745. ];
  48746. },
  48747. constructInterpolatedFromIR: function PDFFunction_constructInterpolatedFromIR(IR) {
  48748. var c0 = IR[1];
  48749. var diff = IR[2];
  48750. var n = IR[3];
  48751. var length = diff.length;
  48752. return function constructInterpolatedFromIRResult(src, srcOffset, dest, destOffset) {
  48753. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  48754. for (var j = 0; j < length; ++j) {
  48755. dest[destOffset + j] = c0[j] + x * diff[j];
  48756. }
  48757. };
  48758. },
  48759. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  48760. var domain = dict.getArray('Domain');
  48761. if (!domain) {
  48762. error('No domain');
  48763. }
  48764. var inputSize = domain.length / 2;
  48765. if (inputSize !== 1) {
  48766. error('Bad domain for stiched function');
  48767. }
  48768. var fnRefs = dict.get('Functions');
  48769. var fns = [];
  48770. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  48771. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  48772. }
  48773. var bounds = dict.getArray('Bounds');
  48774. var encode = dict.getArray('Encode');
  48775. return [
  48776. CONSTRUCT_STICHED,
  48777. domain,
  48778. bounds,
  48779. encode,
  48780. fns
  48781. ];
  48782. },
  48783. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  48784. var domain = IR[1];
  48785. var bounds = IR[2];
  48786. var encode = IR[3];
  48787. var fnsIR = IR[4];
  48788. var fns = [];
  48789. var tmpBuf = new Float32Array(1);
  48790. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  48791. fns.push(PDFFunction.fromIR(fnsIR[i]));
  48792. }
  48793. return function constructStichedFromIRResult(src, srcOffset, dest, destOffset) {
  48794. var clip = function constructStichedFromIRClip(v, min, max) {
  48795. if (v > max) {
  48796. v = max;
  48797. } else if (v < min) {
  48798. v = min;
  48799. }
  48800. return v;
  48801. };
  48802. // clip to domain
  48803. var v = clip(src[srcOffset], domain[0], domain[1]);
  48804. // calculate which bound the value is in
  48805. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  48806. if (v < bounds[i]) {
  48807. break;
  48808. }
  48809. }
  48810. // encode value into domain of function
  48811. var dmin = domain[0];
  48812. if (i > 0) {
  48813. dmin = bounds[i - 1];
  48814. }
  48815. var dmax = domain[1];
  48816. if (i < bounds.length) {
  48817. dmax = bounds[i];
  48818. }
  48819. var rmin = encode[2 * i];
  48820. var rmax = encode[2 * i + 1];
  48821. // Prevent the value from becoming NaN as a result
  48822. // of division by zero (fixes issue6113.pdf).
  48823. tmpBuf[0] = dmin === dmax ? rmin : rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  48824. // call the appropriate function
  48825. fns[i](tmpBuf, 0, dest, destOffset);
  48826. };
  48827. },
  48828. constructPostScript: function PDFFunction_constructPostScript(fn, dict, xref) {
  48829. var domain = dict.getArray('Domain');
  48830. var range = dict.getArray('Range');
  48831. if (!domain) {
  48832. error('No domain.');
  48833. }
  48834. if (!range) {
  48835. error('No range.');
  48836. }
  48837. var lexer = new PostScriptLexer(fn);
  48838. var parser = new PostScriptParser(lexer);
  48839. var code = parser.parse();
  48840. return [
  48841. CONSTRUCT_POSTSCRIPT,
  48842. domain,
  48843. range,
  48844. code
  48845. ];
  48846. },
  48847. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(IR) {
  48848. var domain = IR[1];
  48849. var range = IR[2];
  48850. var code = IR[3];
  48851. var compiled = new PostScriptCompiler().compile(code, domain, range);
  48852. if (compiled) {
  48853. // Compiled function consists of simple expressions such as addition,
  48854. // subtraction, Math.max, and also contains 'var' and 'return'
  48855. // statements. See the generation in the PostScriptCompiler below.
  48856. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  48857. }
  48858. info('Unable to compile PS function');
  48859. var numOutputs = range.length >> 1;
  48860. var numInputs = domain.length >> 1;
  48861. var evaluator = new PostScriptEvaluator(code);
  48862. // Cache the values for a big speed up, the cache size is limited though
  48863. // since the number of possible values can be huge from a PS function.
  48864. var cache = Object.create(null);
  48865. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  48866. // seen in our tests.
  48867. var MAX_CACHE_SIZE = 2048 * 4;
  48868. var cache_available = MAX_CACHE_SIZE;
  48869. var tmpBuf = new Float32Array(numInputs);
  48870. return function constructPostScriptFromIRResult(src, srcOffset, dest, destOffset) {
  48871. var i, value;
  48872. var key = '';
  48873. var input = tmpBuf;
  48874. for (i = 0; i < numInputs; i++) {
  48875. value = src[srcOffset + i];
  48876. input[i] = value;
  48877. key += value + '_';
  48878. }
  48879. var cachedValue = cache[key];
  48880. if (cachedValue !== undefined) {
  48881. dest.set(cachedValue, destOffset);
  48882. return;
  48883. }
  48884. var output = new Float32Array(numOutputs);
  48885. var stack = evaluator.execute(input);
  48886. var stackIndex = stack.length - numOutputs;
  48887. for (i = 0; i < numOutputs; i++) {
  48888. value = stack[stackIndex + i];
  48889. var bound = range[i * 2];
  48890. if (value < bound) {
  48891. value = bound;
  48892. } else {
  48893. bound = range[i * 2 + 1];
  48894. if (value > bound) {
  48895. value = bound;
  48896. }
  48897. }
  48898. output[i] = value;
  48899. }
  48900. if (cache_available > 0) {
  48901. cache_available--;
  48902. cache[key] = output;
  48903. }
  48904. dest.set(output, destOffset);
  48905. };
  48906. }
  48907. };
  48908. }();
  48909. function isPDFFunction(v) {
  48910. var fnDict;
  48911. if (typeof v !== 'object') {
  48912. return false;
  48913. } else if (isDict(v)) {
  48914. fnDict = v;
  48915. } else if (isStream(v)) {
  48916. fnDict = v.dict;
  48917. } else {
  48918. return false;
  48919. }
  48920. return fnDict.has('FunctionType');
  48921. }
  48922. var PostScriptStack = function PostScriptStackClosure() {
  48923. var MAX_STACK_SIZE = 100;
  48924. function PostScriptStack(initialStack) {
  48925. this.stack = !initialStack ? [] : Array.prototype.slice.call(initialStack, 0);
  48926. }
  48927. PostScriptStack.prototype = {
  48928. push: function PostScriptStack_push(value) {
  48929. if (this.stack.length >= MAX_STACK_SIZE) {
  48930. error('PostScript function stack overflow.');
  48931. }
  48932. this.stack.push(value);
  48933. },
  48934. pop: function PostScriptStack_pop() {
  48935. if (this.stack.length <= 0) {
  48936. error('PostScript function stack underflow.');
  48937. }
  48938. return this.stack.pop();
  48939. },
  48940. copy: function PostScriptStack_copy(n) {
  48941. if (this.stack.length + n >= MAX_STACK_SIZE) {
  48942. error('PostScript function stack overflow.');
  48943. }
  48944. var stack = this.stack;
  48945. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  48946. stack.push(stack[i]);
  48947. }
  48948. },
  48949. index: function PostScriptStack_index(n) {
  48950. this.push(this.stack[this.stack.length - n - 1]);
  48951. },
  48952. // rotate the last n stack elements p times
  48953. roll: function PostScriptStack_roll(n, p) {
  48954. var stack = this.stack;
  48955. var l = stack.length - n;
  48956. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  48957. for (i = l, j = r; i < j; i++, j--) {
  48958. t = stack[i];
  48959. stack[i] = stack[j];
  48960. stack[j] = t;
  48961. }
  48962. for (i = l, j = c - 1; i < j; i++, j--) {
  48963. t = stack[i];
  48964. stack[i] = stack[j];
  48965. stack[j] = t;
  48966. }
  48967. for (i = c, j = r; i < j; i++, j--) {
  48968. t = stack[i];
  48969. stack[i] = stack[j];
  48970. stack[j] = t;
  48971. }
  48972. }
  48973. };
  48974. return PostScriptStack;
  48975. }();
  48976. var PostScriptEvaluator = function PostScriptEvaluatorClosure() {
  48977. function PostScriptEvaluator(operators) {
  48978. this.operators = operators;
  48979. }
  48980. PostScriptEvaluator.prototype = {
  48981. execute: function PostScriptEvaluator_execute(initialStack) {
  48982. var stack = new PostScriptStack(initialStack);
  48983. var counter = 0;
  48984. var operators = this.operators;
  48985. var length = operators.length;
  48986. var operator, a, b;
  48987. while (counter < length) {
  48988. operator = operators[counter++];
  48989. if (typeof operator === 'number') {
  48990. // Operator is really an operand and should be pushed to the stack.
  48991. stack.push(operator);
  48992. continue;
  48993. }
  48994. switch (operator) {
  48995. // non standard ps operators
  48996. case 'jz':
  48997. // jump if false
  48998. b = stack.pop();
  48999. a = stack.pop();
  49000. if (!a) {
  49001. counter = b;
  49002. }
  49003. break;
  49004. case 'j':
  49005. // jump
  49006. a = stack.pop();
  49007. counter = a;
  49008. break;
  49009. // all ps operators in alphabetical order (excluding if/ifelse)
  49010. case 'abs':
  49011. a = stack.pop();
  49012. stack.push(Math.abs(a));
  49013. break;
  49014. case 'add':
  49015. b = stack.pop();
  49016. a = stack.pop();
  49017. stack.push(a + b);
  49018. break;
  49019. case 'and':
  49020. b = stack.pop();
  49021. a = stack.pop();
  49022. if (isBool(a) && isBool(b)) {
  49023. stack.push(a && b);
  49024. } else {
  49025. stack.push(a & b);
  49026. }
  49027. break;
  49028. case 'atan':
  49029. a = stack.pop();
  49030. stack.push(Math.atan(a));
  49031. break;
  49032. case 'bitshift':
  49033. b = stack.pop();
  49034. a = stack.pop();
  49035. if (a > 0) {
  49036. stack.push(a << b);
  49037. } else {
  49038. stack.push(a >> b);
  49039. }
  49040. break;
  49041. case 'ceiling':
  49042. a = stack.pop();
  49043. stack.push(Math.ceil(a));
  49044. break;
  49045. case 'copy':
  49046. a = stack.pop();
  49047. stack.copy(a);
  49048. break;
  49049. case 'cos':
  49050. a = stack.pop();
  49051. stack.push(Math.cos(a));
  49052. break;
  49053. case 'cvi':
  49054. a = stack.pop() | 0;
  49055. stack.push(a);
  49056. break;
  49057. case 'cvr':
  49058. // noop
  49059. break;
  49060. case 'div':
  49061. b = stack.pop();
  49062. a = stack.pop();
  49063. stack.push(a / b);
  49064. break;
  49065. case 'dup':
  49066. stack.copy(1);
  49067. break;
  49068. case 'eq':
  49069. b = stack.pop();
  49070. a = stack.pop();
  49071. stack.push(a === b);
  49072. break;
  49073. case 'exch':
  49074. stack.roll(2, 1);
  49075. break;
  49076. case 'exp':
  49077. b = stack.pop();
  49078. a = stack.pop();
  49079. stack.push(Math.pow(a, b));
  49080. break;
  49081. case 'false':
  49082. stack.push(false);
  49083. break;
  49084. case 'floor':
  49085. a = stack.pop();
  49086. stack.push(Math.floor(a));
  49087. break;
  49088. case 'ge':
  49089. b = stack.pop();
  49090. a = stack.pop();
  49091. stack.push(a >= b);
  49092. break;
  49093. case 'gt':
  49094. b = stack.pop();
  49095. a = stack.pop();
  49096. stack.push(a > b);
  49097. break;
  49098. case 'idiv':
  49099. b = stack.pop();
  49100. a = stack.pop();
  49101. stack.push(a / b | 0);
  49102. break;
  49103. case 'index':
  49104. a = stack.pop();
  49105. stack.index(a);
  49106. break;
  49107. case 'le':
  49108. b = stack.pop();
  49109. a = stack.pop();
  49110. stack.push(a <= b);
  49111. break;
  49112. case 'ln':
  49113. a = stack.pop();
  49114. stack.push(Math.log(a));
  49115. break;
  49116. case 'log':
  49117. a = stack.pop();
  49118. stack.push(Math.log(a) / Math.LN10);
  49119. break;
  49120. case 'lt':
  49121. b = stack.pop();
  49122. a = stack.pop();
  49123. stack.push(a < b);
  49124. break;
  49125. case 'mod':
  49126. b = stack.pop();
  49127. a = stack.pop();
  49128. stack.push(a % b);
  49129. break;
  49130. case 'mul':
  49131. b = stack.pop();
  49132. a = stack.pop();
  49133. stack.push(a * b);
  49134. break;
  49135. case 'ne':
  49136. b = stack.pop();
  49137. a = stack.pop();
  49138. stack.push(a !== b);
  49139. break;
  49140. case 'neg':
  49141. a = stack.pop();
  49142. stack.push(-a);
  49143. break;
  49144. case 'not':
  49145. a = stack.pop();
  49146. if (isBool(a)) {
  49147. stack.push(!a);
  49148. } else {
  49149. stack.push(~a);
  49150. }
  49151. break;
  49152. case 'or':
  49153. b = stack.pop();
  49154. a = stack.pop();
  49155. if (isBool(a) && isBool(b)) {
  49156. stack.push(a || b);
  49157. } else {
  49158. stack.push(a | b);
  49159. }
  49160. break;
  49161. case 'pop':
  49162. stack.pop();
  49163. break;
  49164. case 'roll':
  49165. b = stack.pop();
  49166. a = stack.pop();
  49167. stack.roll(a, b);
  49168. break;
  49169. case 'round':
  49170. a = stack.pop();
  49171. stack.push(Math.round(a));
  49172. break;
  49173. case 'sin':
  49174. a = stack.pop();
  49175. stack.push(Math.sin(a));
  49176. break;
  49177. case 'sqrt':
  49178. a = stack.pop();
  49179. stack.push(Math.sqrt(a));
  49180. break;
  49181. case 'sub':
  49182. b = stack.pop();
  49183. a = stack.pop();
  49184. stack.push(a - b);
  49185. break;
  49186. case 'true':
  49187. stack.push(true);
  49188. break;
  49189. case 'truncate':
  49190. a = stack.pop();
  49191. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  49192. stack.push(a);
  49193. break;
  49194. case 'xor':
  49195. b = stack.pop();
  49196. a = stack.pop();
  49197. if (isBool(a) && isBool(b)) {
  49198. stack.push(a !== b);
  49199. } else {
  49200. stack.push(a ^ b);
  49201. }
  49202. break;
  49203. default:
  49204. error('Unknown operator ' + operator);
  49205. break;
  49206. }
  49207. }
  49208. return stack.stack;
  49209. }
  49210. };
  49211. return PostScriptEvaluator;
  49212. }();
  49213. // Most of the PDFs functions consist of simple operations such as:
  49214. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  49215. //
  49216. // We can compile most of such programs, and at the same moment, we can
  49217. // optimize some expressions using basic math properties. Keeping track of
  49218. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  49219. var PostScriptCompiler = function PostScriptCompilerClosure() {
  49220. function AstNode(type) {
  49221. this.type = type;
  49222. }
  49223. AstNode.prototype.visit = function (visitor) {
  49224. throw new Error('abstract method');
  49225. };
  49226. function AstArgument(index, min, max) {
  49227. AstNode.call(this, 'args');
  49228. this.index = index;
  49229. this.min = min;
  49230. this.max = max;
  49231. }
  49232. AstArgument.prototype = Object.create(AstNode.prototype);
  49233. AstArgument.prototype.visit = function (visitor) {
  49234. visitor.visitArgument(this);
  49235. };
  49236. function AstLiteral(number) {
  49237. AstNode.call(this, 'literal');
  49238. this.number = number;
  49239. this.min = number;
  49240. this.max = number;
  49241. }
  49242. AstLiteral.prototype = Object.create(AstNode.prototype);
  49243. AstLiteral.prototype.visit = function (visitor) {
  49244. visitor.visitLiteral(this);
  49245. };
  49246. function AstBinaryOperation(op, arg1, arg2, min, max) {
  49247. AstNode.call(this, 'binary');
  49248. this.op = op;
  49249. this.arg1 = arg1;
  49250. this.arg2 = arg2;
  49251. this.min = min;
  49252. this.max = max;
  49253. }
  49254. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  49255. AstBinaryOperation.prototype.visit = function (visitor) {
  49256. visitor.visitBinaryOperation(this);
  49257. };
  49258. function AstMin(arg, max) {
  49259. AstNode.call(this, 'max');
  49260. this.arg = arg;
  49261. this.min = arg.min;
  49262. this.max = max;
  49263. }
  49264. AstMin.prototype = Object.create(AstNode.prototype);
  49265. AstMin.prototype.visit = function (visitor) {
  49266. visitor.visitMin(this);
  49267. };
  49268. function AstVariable(index, min, max) {
  49269. AstNode.call(this, 'var');
  49270. this.index = index;
  49271. this.min = min;
  49272. this.max = max;
  49273. }
  49274. AstVariable.prototype = Object.create(AstNode.prototype);
  49275. AstVariable.prototype.visit = function (visitor) {
  49276. visitor.visitVariable(this);
  49277. };
  49278. function AstVariableDefinition(variable, arg) {
  49279. AstNode.call(this, 'definition');
  49280. this.variable = variable;
  49281. this.arg = arg;
  49282. }
  49283. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  49284. AstVariableDefinition.prototype.visit = function (visitor) {
  49285. visitor.visitVariableDefinition(this);
  49286. };
  49287. function ExpressionBuilderVisitor() {
  49288. this.parts = [];
  49289. }
  49290. ExpressionBuilderVisitor.prototype = {
  49291. visitArgument: function (arg) {
  49292. this.parts.push('Math.max(', arg.min, ', Math.min(', arg.max, ', src[srcOffset + ', arg.index, ']))');
  49293. },
  49294. visitVariable: function (variable) {
  49295. this.parts.push('v', variable.index);
  49296. },
  49297. visitLiteral: function (literal) {
  49298. this.parts.push(literal.number);
  49299. },
  49300. visitBinaryOperation: function (operation) {
  49301. this.parts.push('(');
  49302. operation.arg1.visit(this);
  49303. this.parts.push(' ', operation.op, ' ');
  49304. operation.arg2.visit(this);
  49305. this.parts.push(')');
  49306. },
  49307. visitVariableDefinition: function (definition) {
  49308. this.parts.push('var ');
  49309. definition.variable.visit(this);
  49310. this.parts.push(' = ');
  49311. definition.arg.visit(this);
  49312. this.parts.push(';');
  49313. },
  49314. visitMin: function (max) {
  49315. this.parts.push('Math.min(');
  49316. max.arg.visit(this);
  49317. this.parts.push(', ', max.max, ')');
  49318. },
  49319. toString: function () {
  49320. return this.parts.join('');
  49321. }
  49322. };
  49323. function buildAddOperation(num1, num2) {
  49324. if (num2.type === 'literal' && num2.number === 0) {
  49325. // optimization: second operand is 0
  49326. return num1;
  49327. }
  49328. if (num1.type === 'literal' && num1.number === 0) {
  49329. // optimization: first operand is 0
  49330. return num2;
  49331. }
  49332. if (num2.type === 'literal' && num1.type === 'literal') {
  49333. // optimization: operands operand are literals
  49334. return new AstLiteral(num1.number + num2.number);
  49335. }
  49336. return new AstBinaryOperation('+', num1, num2, num1.min + num2.min, num1.max + num2.max);
  49337. }
  49338. function buildMulOperation(num1, num2) {
  49339. if (num2.type === 'literal') {
  49340. // optimization: second operands is a literal...
  49341. if (num2.number === 0) {
  49342. return new AstLiteral(0);
  49343. } else // and it's 0
  49344. if (num2.number === 1) {
  49345. return num1;
  49346. } else // and it's 1
  49347. if (num1.type === 'literal') {
  49348. // ... and first operands is a literal too
  49349. return new AstLiteral(num1.number * num2.number);
  49350. }
  49351. }
  49352. if (num1.type === 'literal') {
  49353. // optimization: first operands is a literal...
  49354. if (num1.number === 0) {
  49355. return new AstLiteral(0);
  49356. } else // and it's 0
  49357. if (num1.number === 1) {
  49358. return num2;
  49359. }
  49360. }
  49361. // and it's 1
  49362. var min = Math.min(num1.min * num2.min, num1.min * num2.max, num1.max * num2.min, num1.max * num2.max);
  49363. var max = Math.max(num1.min * num2.min, num1.min * num2.max, num1.max * num2.min, num1.max * num2.max);
  49364. return new AstBinaryOperation('*', num1, num2, min, max);
  49365. }
  49366. function buildSubOperation(num1, num2) {
  49367. if (num2.type === 'literal') {
  49368. // optimization: second operands is a literal...
  49369. if (num2.number === 0) {
  49370. return num1;
  49371. } else // ... and it's 0
  49372. if (num1.type === 'literal') {
  49373. // ... and first operands is a literal too
  49374. return new AstLiteral(num1.number - num2.number);
  49375. }
  49376. }
  49377. if (num2.type === 'binary' && num2.op === '-' && num1.type === 'literal' && num1.number === 1 && num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  49378. // optimization for case: 1 - (1 - x)
  49379. return num2.arg2;
  49380. }
  49381. return new AstBinaryOperation('-', num1, num2, num1.min - num2.max, num1.max - num2.min);
  49382. }
  49383. function buildMinOperation(num1, max) {
  49384. if (num1.min >= max) {
  49385. // optimization: num1 min value is not less than required max
  49386. return new AstLiteral(max);
  49387. } else // just returning max
  49388. if (num1.max <= max) {
  49389. // optimization: num1 max value is not greater than required max
  49390. return num1;
  49391. }
  49392. // just returning an argument
  49393. return new AstMin(num1, max);
  49394. }
  49395. function PostScriptCompiler() {
  49396. }
  49397. PostScriptCompiler.prototype = {
  49398. compile: function PostScriptCompiler_compile(code, domain, range) {
  49399. var stack = [];
  49400. var i, ii;
  49401. var instructions = [];
  49402. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  49403. var lastRegister = 0;
  49404. var n, j;
  49405. var num1, num2, ast1, ast2, tmpVar, item;
  49406. for (i = 0; i < inputSize; i++) {
  49407. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  49408. }
  49409. for (i = 0, ii = code.length; i < ii; i++) {
  49410. item = code[i];
  49411. if (typeof item === 'number') {
  49412. stack.push(new AstLiteral(item));
  49413. continue;
  49414. }
  49415. switch (item) {
  49416. case 'add':
  49417. if (stack.length < 2) {
  49418. return null;
  49419. }
  49420. num2 = stack.pop();
  49421. num1 = stack.pop();
  49422. stack.push(buildAddOperation(num1, num2));
  49423. break;
  49424. case 'cvr':
  49425. if (stack.length < 1) {
  49426. return null;
  49427. }
  49428. break;
  49429. case 'mul':
  49430. if (stack.length < 2) {
  49431. return null;
  49432. }
  49433. num2 = stack.pop();
  49434. num1 = stack.pop();
  49435. stack.push(buildMulOperation(num1, num2));
  49436. break;
  49437. case 'sub':
  49438. if (stack.length < 2) {
  49439. return null;
  49440. }
  49441. num2 = stack.pop();
  49442. num1 = stack.pop();
  49443. stack.push(buildSubOperation(num1, num2));
  49444. break;
  49445. case 'exch':
  49446. if (stack.length < 2) {
  49447. return null;
  49448. }
  49449. ast1 = stack.pop();
  49450. ast2 = stack.pop();
  49451. stack.push(ast1, ast2);
  49452. break;
  49453. case 'pop':
  49454. if (stack.length < 1) {
  49455. return null;
  49456. }
  49457. stack.pop();
  49458. break;
  49459. case 'index':
  49460. if (stack.length < 1) {
  49461. return null;
  49462. }
  49463. num1 = stack.pop();
  49464. if (num1.type !== 'literal') {
  49465. return null;
  49466. }
  49467. n = num1.number;
  49468. if (n < 0 || (n | 0) !== n || stack.length < n) {
  49469. return null;
  49470. }
  49471. ast1 = stack[stack.length - n - 1];
  49472. if (ast1.type === 'literal' || ast1.type === 'var') {
  49473. stack.push(ast1);
  49474. break;
  49475. }
  49476. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  49477. stack[stack.length - n - 1] = tmpVar;
  49478. stack.push(tmpVar);
  49479. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  49480. break;
  49481. case 'dup':
  49482. if (stack.length < 1) {
  49483. return null;
  49484. }
  49485. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' && code[i + 3] === i + 7 && code[i + 4] === 'jz' && code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  49486. // special case of the commands sequence for the min operation
  49487. num1 = stack.pop();
  49488. stack.push(buildMinOperation(num1, code[i + 1]));
  49489. i += 6;
  49490. break;
  49491. }
  49492. ast1 = stack[stack.length - 1];
  49493. if (ast1.type === 'literal' || ast1.type === 'var') {
  49494. // we don't have to save into intermediate variable a literal or
  49495. // variable.
  49496. stack.push(ast1);
  49497. break;
  49498. }
  49499. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  49500. stack[stack.length - 1] = tmpVar;
  49501. stack.push(tmpVar);
  49502. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  49503. break;
  49504. case 'roll':
  49505. if (stack.length < 2) {
  49506. return null;
  49507. }
  49508. num2 = stack.pop();
  49509. num1 = stack.pop();
  49510. if (num2.type !== 'literal' || num1.type !== 'literal') {
  49511. // both roll operands must be numbers
  49512. return null;
  49513. }
  49514. j = num2.number;
  49515. n = num1.number;
  49516. if (n <= 0 || (n | 0) !== n || (j | 0) !== j || stack.length < n) {
  49517. // ... and integers
  49518. return null;
  49519. }
  49520. j = (j % n + n) % n;
  49521. if (j === 0) {
  49522. break;
  49523. }
  49524. // just skipping -- there are nothing to rotate
  49525. Array.prototype.push.apply(stack, stack.splice(stack.length - n, n - j));
  49526. break;
  49527. default:
  49528. return null;
  49529. }
  49530. }
  49531. // unsupported operator
  49532. if (stack.length !== outputSize) {
  49533. return null;
  49534. }
  49535. var result = [];
  49536. instructions.forEach(function (instruction) {
  49537. var statementBuilder = new ExpressionBuilderVisitor();
  49538. instruction.visit(statementBuilder);
  49539. result.push(statementBuilder.toString());
  49540. });
  49541. stack.forEach(function (expr, i) {
  49542. var statementBuilder = new ExpressionBuilderVisitor();
  49543. expr.visit(statementBuilder);
  49544. var min = range[i * 2], max = range[i * 2 + 1];
  49545. var out = [statementBuilder.toString()];
  49546. if (min > expr.min) {
  49547. out.unshift('Math.max(', min, ', ');
  49548. out.push(')');
  49549. }
  49550. if (max < expr.max) {
  49551. out.unshift('Math.min(', max, ', ');
  49552. out.push(')');
  49553. }
  49554. out.unshift('dest[destOffset + ', i, '] = ');
  49555. out.push(';');
  49556. result.push(out.join(''));
  49557. });
  49558. return result.join('\n');
  49559. }
  49560. };
  49561. return PostScriptCompiler;
  49562. }();
  49563. exports.isPDFFunction = isPDFFunction;
  49564. exports.PDFFunction = PDFFunction;
  49565. exports.PostScriptEvaluator = PostScriptEvaluator;
  49566. exports.PostScriptCompiler = PostScriptCompiler;
  49567. }));
  49568. (function (root, factory) {
  49569. factory(root.pdfjsDisplayAPI = {}, root.pdfjsSharedUtil, root.pdfjsDisplayFontLoader, root.pdfjsDisplayCanvas, root.pdfjsDisplayMetadata, root.pdfjsDisplayDOMUtils);
  49570. }(this, function (exports, sharedUtil, displayFontLoader, displayCanvas, displayMetadata, displayDOMUtils, amdRequire) {
  49571. var InvalidPDFException = sharedUtil.InvalidPDFException;
  49572. var MessageHandler = sharedUtil.MessageHandler;
  49573. var MissingPDFException = sharedUtil.MissingPDFException;
  49574. var PageViewport = sharedUtil.PageViewport;
  49575. var PasswordResponses = sharedUtil.PasswordResponses;
  49576. var PasswordException = sharedUtil.PasswordException;
  49577. var StatTimer = sharedUtil.StatTimer;
  49578. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  49579. var UnknownErrorException = sharedUtil.UnknownErrorException;
  49580. var Util = sharedUtil.Util;
  49581. var createPromiseCapability = sharedUtil.createPromiseCapability;
  49582. var error = sharedUtil.error;
  49583. var deprecated = sharedUtil.deprecated;
  49584. var getVerbosityLevel = sharedUtil.getVerbosityLevel;
  49585. var info = sharedUtil.info;
  49586. var isInt = sharedUtil.isInt;
  49587. var isArray = sharedUtil.isArray;
  49588. var isArrayBuffer = sharedUtil.isArrayBuffer;
  49589. var isSameOrigin = sharedUtil.isSameOrigin;
  49590. var loadJpegStream = sharedUtil.loadJpegStream;
  49591. var stringToBytes = sharedUtil.stringToBytes;
  49592. var globalScope = sharedUtil.globalScope;
  49593. var warn = sharedUtil.warn;
  49594. var FontFaceObject = displayFontLoader.FontFaceObject;
  49595. var FontLoader = displayFontLoader.FontLoader;
  49596. var CanvasGraphics = displayCanvas.CanvasGraphics;
  49597. var createScratchCanvas = displayCanvas.createScratchCanvas;
  49598. var Metadata = displayMetadata.Metadata;
  49599. var getDefaultSetting = displayDOMUtils.getDefaultSetting;
  49600. var DEFAULT_RANGE_CHUNK_SIZE = 65536;
  49601. // 2^16 = 65536
  49602. var isWorkerDisabled = false;
  49603. var workerSrc;
  49604. var isPostMessageTransfersDisabled = false;
  49605. var fakeWorkerFilesLoader = null;
  49606. var useRequireEnsure = false;
  49607. /**
  49608. * Document initialization / loading parameters object.
  49609. *
  49610. * @typedef {Object} DocumentInitParameters
  49611. * @property {string} url - The URL of the PDF.
  49612. * @property {TypedArray|Array|string} data - Binary PDF data. Use typed arrays
  49613. * (Uint8Array) to improve the memory usage. If PDF data is BASE64-encoded,
  49614. * use atob() to convert it to a binary string first.
  49615. * @property {Object} httpHeaders - Basic authentication headers.
  49616. * @property {boolean} withCredentials - Indicates whether or not cross-site
  49617. * Access-Control requests should be made using credentials such as cookies
  49618. * or authorization headers. The default is false.
  49619. * @property {string} password - For decrypting password-protected PDFs.
  49620. * @property {TypedArray} initialData - A typed array with the first portion or
  49621. * all of the pdf data. Used by the extension since some data is already
  49622. * loaded before the switch to range requests.
  49623. * @property {number} length - The PDF file length. It's used for progress
  49624. * reports and range requests operations.
  49625. * @property {PDFDataRangeTransport} range
  49626. * @property {number} rangeChunkSize - Optional parameter to specify
  49627. * maximum number of bytes fetched per range request. The default value is
  49628. * 2^16 = 65536.
  49629. * @property {PDFWorker} worker - The worker that will be used for the loading
  49630. * and parsing of the PDF data.
  49631. */
  49632. /**
  49633. * @typedef {Object} PDFDocumentStats
  49634. * @property {Array} streamTypes - Used stream types in the document (an item
  49635. * is set to true if specific stream ID was used in the document).
  49636. * @property {Array} fontTypes - Used font type in the document (an item is set
  49637. * to true if specific font ID was used in the document).
  49638. */
  49639. /**
  49640. * This is the main entry point for loading a PDF and interacting with it.
  49641. * NOTE: If a URL is used to fetch the PDF data a standard XMLHttpRequest(XHR)
  49642. * is used, which means it must follow the same origin rules that any XHR does
  49643. * e.g. No cross domain requests without CORS.
  49644. *
  49645. * @param {string|TypedArray|DocumentInitParameters|PDFDataRangeTransport} src
  49646. * Can be a url to where a PDF is located, a typed array (Uint8Array)
  49647. * already populated with data or parameter object.
  49648. *
  49649. * @param {PDFDataRangeTransport} pdfDataRangeTransport (deprecated) It is used
  49650. * if you want to manually serve range requests for data in the PDF.
  49651. *
  49652. * @param {function} passwordCallback (deprecated) It is used to request a
  49653. * password if wrong or no password was provided. The callback receives two
  49654. * parameters: function that needs to be called with new password and reason
  49655. * (see {PasswordResponses}).
  49656. *
  49657. * @param {function} progressCallback (deprecated) It is used to be able to
  49658. * monitor the loading progress of the PDF file (necessary to implement e.g.
  49659. * a loading bar). The callback receives an {Object} with the properties:
  49660. * {number} loaded and {number} total.
  49661. *
  49662. * @return {PDFDocumentLoadingTask}
  49663. */
  49664. function getDocument(src, pdfDataRangeTransport, passwordCallback, progressCallback) {
  49665. var task = new PDFDocumentLoadingTask();
  49666. // Support of the obsolete arguments (for compatibility with API v1.0)
  49667. if (arguments.length > 1) {
  49668. deprecated('getDocument is called with pdfDataRangeTransport, ' + 'passwordCallback or progressCallback argument');
  49669. }
  49670. if (pdfDataRangeTransport) {
  49671. if (!(pdfDataRangeTransport instanceof PDFDataRangeTransport)) {
  49672. // Not a PDFDataRangeTransport instance, trying to add missing properties.
  49673. pdfDataRangeTransport = Object.create(pdfDataRangeTransport);
  49674. pdfDataRangeTransport.length = src.length;
  49675. pdfDataRangeTransport.initialData = src.initialData;
  49676. if (!pdfDataRangeTransport.abort) {
  49677. pdfDataRangeTransport.abort = function () {
  49678. };
  49679. }
  49680. }
  49681. src = Object.create(src);
  49682. src.range = pdfDataRangeTransport;
  49683. }
  49684. task.onPassword = passwordCallback || null;
  49685. task.onProgress = progressCallback || null;
  49686. var source;
  49687. if (typeof src === 'string') {
  49688. source = { url: src };
  49689. } else if (isArrayBuffer(src)) {
  49690. source = { data: src };
  49691. } else if (src instanceof PDFDataRangeTransport) {
  49692. source = { range: src };
  49693. } else {
  49694. if (typeof src !== 'object') {
  49695. error('Invalid parameter in getDocument, need either Uint8Array, ' + 'string or a parameter object');
  49696. }
  49697. if (!src.url && !src.data && !src.range) {
  49698. error('Invalid parameter object: need either .data, .range or .url');
  49699. }
  49700. source = src;
  49701. }
  49702. var params = {};
  49703. var rangeTransport = null;
  49704. var worker = null;
  49705. for (var key in source) {
  49706. if (key === 'url' && typeof window !== 'undefined') {
  49707. // The full path is required in the 'url' field.
  49708. params[key] = new URL(source[key], window.location).href;
  49709. continue;
  49710. } else if (key === 'range') {
  49711. rangeTransport = source[key];
  49712. continue;
  49713. } else if (key === 'worker') {
  49714. worker = source[key];
  49715. continue;
  49716. } else if (key === 'data' && !(source[key] instanceof Uint8Array)) {
  49717. // Converting string or array-like data to Uint8Array.
  49718. var pdfBytes = source[key];
  49719. if (typeof pdfBytes === 'string') {
  49720. params[key] = stringToBytes(pdfBytes);
  49721. } else if (typeof pdfBytes === 'object' && pdfBytes !== null && !isNaN(pdfBytes.length)) {
  49722. params[key] = new Uint8Array(pdfBytes);
  49723. } else if (isArrayBuffer(pdfBytes)) {
  49724. params[key] = new Uint8Array(pdfBytes);
  49725. } else {
  49726. error('Invalid PDF binary data: either typed array, string or ' + 'array-like object is expected in the data property.');
  49727. }
  49728. continue;
  49729. }
  49730. params[key] = source[key];
  49731. }
  49732. params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE;
  49733. if (!worker) {
  49734. // Worker was not provided -- creating and owning our own.
  49735. worker = new PDFWorker();
  49736. task._worker = worker;
  49737. }
  49738. var docId = task.docId;
  49739. worker.promise.then(function () {
  49740. if (task.destroyed) {
  49741. throw new Error('Loading aborted');
  49742. }
  49743. return _fetchDocument(worker, params, rangeTransport, docId).then(function (workerId) {
  49744. if (task.destroyed) {
  49745. throw new Error('Loading aborted');
  49746. }
  49747. var messageHandler = new MessageHandler(docId, workerId, worker.port);
  49748. var transport = new WorkerTransport(messageHandler, task, rangeTransport);
  49749. task._transport = transport;
  49750. messageHandler.send('Ready', null);
  49751. });
  49752. }).catch(task._capability.reject);
  49753. return task;
  49754. }
  49755. /**
  49756. * Starts fetching of specified PDF document/data.
  49757. * @param {PDFWorker} worker
  49758. * @param {Object} source
  49759. * @param {PDFDataRangeTransport} pdfDataRangeTransport
  49760. * @param {string} docId Unique document id, used as MessageHandler id.
  49761. * @returns {Promise} The promise, which is resolved when worker id of
  49762. * MessageHandler is known.
  49763. * @private
  49764. */
  49765. function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
  49766. if (worker.destroyed) {
  49767. return Promise.reject(new Error('Worker was destroyed'));
  49768. }
  49769. source.disableAutoFetch = getDefaultSetting('disableAutoFetch');
  49770. source.disableStream = getDefaultSetting('disableStream');
  49771. source.chunkedViewerLoading = !!pdfDataRangeTransport;
  49772. if (pdfDataRangeTransport) {
  49773. source.length = pdfDataRangeTransport.length;
  49774. source.initialData = pdfDataRangeTransport.initialData;
  49775. }
  49776. return worker.messageHandler.sendWithPromise('GetDocRequest', {
  49777. docId: docId,
  49778. source: source,
  49779. disableRange: getDefaultSetting('disableRange'),
  49780. maxImageSize: getDefaultSetting('maxImageSize'),
  49781. cMapUrl: getDefaultSetting('cMapUrl'),
  49782. cMapPacked: getDefaultSetting('cMapPacked'),
  49783. disableFontFace: getDefaultSetting('disableFontFace'),
  49784. disableCreateObjectURL: getDefaultSetting('disableCreateObjectURL'),
  49785. postMessageTransfers: getDefaultSetting('postMessageTransfers') && !isPostMessageTransfersDisabled
  49786. }).then(function (workerId) {
  49787. if (worker.destroyed) {
  49788. throw new Error('Worker was destroyed');
  49789. }
  49790. return workerId;
  49791. });
  49792. }
  49793. /**
  49794. * PDF document loading operation.
  49795. * @class
  49796. * @alias PDFDocumentLoadingTask
  49797. */
  49798. var PDFDocumentLoadingTask = function PDFDocumentLoadingTaskClosure() {
  49799. var nextDocumentId = 0;
  49800. /** @constructs PDFDocumentLoadingTask */
  49801. function PDFDocumentLoadingTask() {
  49802. this._capability = createPromiseCapability();
  49803. this._transport = null;
  49804. this._worker = null;
  49805. /**
  49806. * Unique document loading task id -- used in MessageHandlers.
  49807. * @type {string}
  49808. */
  49809. this.docId = 'd' + nextDocumentId++;
  49810. /**
  49811. * Shows if loading task is destroyed.
  49812. * @type {boolean}
  49813. */
  49814. this.destroyed = false;
  49815. /**
  49816. * Callback to request a password if wrong or no password was provided.
  49817. * The callback receives two parameters: function that needs to be called
  49818. * with new password and reason (see {PasswordResponses}).
  49819. */
  49820. this.onPassword = null;
  49821. /**
  49822. * Callback to be able to monitor the loading progress of the PDF file
  49823. * (necessary to implement e.g. a loading bar). The callback receives
  49824. * an {Object} with the properties: {number} loaded and {number} total.
  49825. */
  49826. this.onProgress = null;
  49827. /**
  49828. * Callback to when unsupported feature is used. The callback receives
  49829. * an {UNSUPPORTED_FEATURES} argument.
  49830. */
  49831. this.onUnsupportedFeature = null;
  49832. }
  49833. PDFDocumentLoadingTask.prototype = /** @lends PDFDocumentLoadingTask.prototype */
  49834. {
  49835. /**
  49836. * @return {Promise}
  49837. */
  49838. get promise() {
  49839. return this._capability.promise;
  49840. },
  49841. /**
  49842. * Aborts all network requests and destroys worker.
  49843. * @return {Promise} A promise that is resolved after destruction activity
  49844. * is completed.
  49845. */
  49846. destroy: function () {
  49847. this.destroyed = true;
  49848. var transportDestroyed = !this._transport ? Promise.resolve() : this._transport.destroy();
  49849. return transportDestroyed.then(function () {
  49850. this._transport = null;
  49851. if (this._worker) {
  49852. this._worker.destroy();
  49853. this._worker = null;
  49854. }
  49855. }.bind(this));
  49856. },
  49857. /**
  49858. * Registers callbacks to indicate the document loading completion.
  49859. *
  49860. * @param {function} onFulfilled The callback for the loading completion.
  49861. * @param {function} onRejected The callback for the loading failure.
  49862. * @return {Promise} A promise that is resolved after the onFulfilled or
  49863. * onRejected callback.
  49864. */
  49865. then: function PDFDocumentLoadingTask_then(onFulfilled, onRejected) {
  49866. return this.promise.then.apply(this.promise, arguments);
  49867. }
  49868. };
  49869. return PDFDocumentLoadingTask;
  49870. }();
  49871. /**
  49872. * Abstract class to support range requests file loading.
  49873. * @class
  49874. * @alias PDFDataRangeTransport
  49875. * @param {number} length
  49876. * @param {Uint8Array} initialData
  49877. */
  49878. var PDFDataRangeTransport = function pdfDataRangeTransportClosure() {
  49879. function PDFDataRangeTransport(length, initialData) {
  49880. this.length = length;
  49881. this.initialData = initialData;
  49882. this._rangeListeners = [];
  49883. this._progressListeners = [];
  49884. this._progressiveReadListeners = [];
  49885. this._readyCapability = createPromiseCapability();
  49886. }
  49887. PDFDataRangeTransport.prototype = /** @lends PDFDataRangeTransport.prototype */
  49888. {
  49889. addRangeListener: function PDFDataRangeTransport_addRangeListener(listener) {
  49890. this._rangeListeners.push(listener);
  49891. },
  49892. addProgressListener: function PDFDataRangeTransport_addProgressListener(listener) {
  49893. this._progressListeners.push(listener);
  49894. },
  49895. addProgressiveReadListener: function PDFDataRangeTransport_addProgressiveReadListener(listener) {
  49896. this._progressiveReadListeners.push(listener);
  49897. },
  49898. onDataRange: function PDFDataRangeTransport_onDataRange(begin, chunk) {
  49899. var listeners = this._rangeListeners;
  49900. for (var i = 0, n = listeners.length; i < n; ++i) {
  49901. listeners[i](begin, chunk);
  49902. }
  49903. },
  49904. onDataProgress: function PDFDataRangeTransport_onDataProgress(loaded) {
  49905. this._readyCapability.promise.then(function () {
  49906. var listeners = this._progressListeners;
  49907. for (var i = 0, n = listeners.length; i < n; ++i) {
  49908. listeners[i](loaded);
  49909. }
  49910. }.bind(this));
  49911. },
  49912. onDataProgressiveRead: function PDFDataRangeTransport_onDataProgress(chunk) {
  49913. this._readyCapability.promise.then(function () {
  49914. var listeners = this._progressiveReadListeners;
  49915. for (var i = 0, n = listeners.length; i < n; ++i) {
  49916. listeners[i](chunk);
  49917. }
  49918. }.bind(this));
  49919. },
  49920. transportReady: function PDFDataRangeTransport_transportReady() {
  49921. this._readyCapability.resolve();
  49922. },
  49923. requestDataRange: function PDFDataRangeTransport_requestDataRange(begin, end) {
  49924. throw new Error('Abstract method PDFDataRangeTransport.requestDataRange');
  49925. },
  49926. abort: function PDFDataRangeTransport_abort() {
  49927. }
  49928. };
  49929. return PDFDataRangeTransport;
  49930. }();
  49931. /**
  49932. * Proxy to a PDFDocument in the worker thread. Also, contains commonly used
  49933. * properties that can be read synchronously.
  49934. * @class
  49935. * @alias PDFDocumentProxy
  49936. */
  49937. var PDFDocumentProxy = function PDFDocumentProxyClosure() {
  49938. function PDFDocumentProxy(pdfInfo, transport, loadingTask) {
  49939. this.pdfInfo = pdfInfo;
  49940. this.transport = transport;
  49941. this.loadingTask = loadingTask;
  49942. }
  49943. PDFDocumentProxy.prototype = /** @lends PDFDocumentProxy.prototype */
  49944. {
  49945. /**
  49946. * @return {number} Total number of pages the PDF contains.
  49947. */
  49948. get numPages() {
  49949. return this.pdfInfo.numPages;
  49950. },
  49951. /**
  49952. * @return {string} A unique ID to identify a PDF. Not guaranteed to be
  49953. * unique.
  49954. */
  49955. get fingerprint() {
  49956. return this.pdfInfo.fingerprint;
  49957. },
  49958. /**
  49959. * @param {number} pageNumber The page number to get. The first page is 1.
  49960. * @return {Promise} A promise that is resolved with a {@link PDFPageProxy}
  49961. * object.
  49962. */
  49963. getPage: function PDFDocumentProxy_getPage(pageNumber) {
  49964. return this.transport.getPage(pageNumber);
  49965. },
  49966. /**
  49967. * @param {{num: number, gen: number}} ref The page reference. Must have
  49968. * the 'num' and 'gen' properties.
  49969. * @return {Promise} A promise that is resolved with the page index that is
  49970. * associated with the reference.
  49971. */
  49972. getPageIndex: function PDFDocumentProxy_getPageIndex(ref) {
  49973. return this.transport.getPageIndex(ref);
  49974. },
  49975. /**
  49976. * @return {Promise} A promise that is resolved with a lookup table for
  49977. * mapping named destinations to reference numbers.
  49978. *
  49979. * This can be slow for large documents: use getDestination instead
  49980. */
  49981. getDestinations: function PDFDocumentProxy_getDestinations() {
  49982. return this.transport.getDestinations();
  49983. },
  49984. /**
  49985. * @param {string} id The named destination to get.
  49986. * @return {Promise} A promise that is resolved with all information
  49987. * of the given named destination.
  49988. */
  49989. getDestination: function PDFDocumentProxy_getDestination(id) {
  49990. return this.transport.getDestination(id);
  49991. },
  49992. /**
  49993. * @return {Promise} A promise that is resolved with:
  49994. * an Array containing the pageLabels that correspond to the pageIndexes,
  49995. * or `null` when no pageLabels are present in the PDF file.
  49996. */
  49997. getPageLabels: function PDFDocumentProxy_getPageLabels() {
  49998. return this.transport.getPageLabels();
  49999. },
  50000. /**
  50001. * @return {Promise} A promise that is resolved with a lookup table for
  50002. * mapping named attachments to their content.
  50003. */
  50004. getAttachments: function PDFDocumentProxy_getAttachments() {
  50005. return this.transport.getAttachments();
  50006. },
  50007. /**
  50008. * @return {Promise} A promise that is resolved with an array of all the
  50009. * JavaScript strings in the name tree.
  50010. */
  50011. getJavaScript: function PDFDocumentProxy_getJavaScript() {
  50012. return this.transport.getJavaScript();
  50013. },
  50014. /**
  50015. * @return {Promise} A promise that is resolved with an {Array} that is a
  50016. * tree outline (if it has one) of the PDF. The tree is in the format of:
  50017. * [
  50018. * {
  50019. * title: string,
  50020. * bold: boolean,
  50021. * italic: boolean,
  50022. * color: rgb Uint8Array,
  50023. * dest: dest obj,
  50024. * url: string,
  50025. * items: array of more items like this
  50026. * },
  50027. * ...
  50028. * ].
  50029. */
  50030. getOutline: function PDFDocumentProxy_getOutline() {
  50031. return this.transport.getOutline();
  50032. },
  50033. /**
  50034. * @return {Promise} A promise that is resolved with an {Object} that has
  50035. * info and metadata properties. Info is an {Object} filled with anything
  50036. * available in the information dictionary and similarly metadata is a
  50037. * {Metadata} object with information from the metadata section of the PDF.
  50038. */
  50039. getMetadata: function PDFDocumentProxy_getMetadata() {
  50040. return this.transport.getMetadata();
  50041. },
  50042. /**
  50043. * @return {Promise} A promise that is resolved with a TypedArray that has
  50044. * the raw data from the PDF.
  50045. */
  50046. getData: function PDFDocumentProxy_getData() {
  50047. return this.transport.getData();
  50048. },
  50049. /**
  50050. * @return {Promise} A promise that is resolved when the document's data
  50051. * is loaded. It is resolved with an {Object} that contains the length
  50052. * property that indicates size of the PDF data in bytes.
  50053. */
  50054. getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() {
  50055. return this.transport.downloadInfoCapability.promise;
  50056. },
  50057. /**
  50058. * @return {Promise} A promise this is resolved with current stats about
  50059. * document structures (see {@link PDFDocumentStats}).
  50060. */
  50061. getStats: function PDFDocumentProxy_getStats() {
  50062. return this.transport.getStats();
  50063. },
  50064. /**
  50065. * Cleans up resources allocated by the document, e.g. created @font-face.
  50066. */
  50067. cleanup: function PDFDocumentProxy_cleanup() {
  50068. this.transport.startCleanup();
  50069. },
  50070. /**
  50071. * Destroys current document instance and terminates worker.
  50072. */
  50073. destroy: function PDFDocumentProxy_destroy() {
  50074. return this.loadingTask.destroy();
  50075. }
  50076. };
  50077. return PDFDocumentProxy;
  50078. }();
  50079. /**
  50080. * Page getTextContent parameters.
  50081. *
  50082. * @typedef {Object} getTextContentParameters
  50083. * @property {boolean} normalizeWhitespace - replaces all occurrences of
  50084. * whitespace with standard spaces (0x20). The default value is `false`.
  50085. * @property {boolean} disableCombineTextItems - do not attempt to combine
  50086. * same line {@link TextItem}'s. The default value is `false`.
  50087. */
  50088. /**
  50089. * Page text content.
  50090. *
  50091. * @typedef {Object} TextContent
  50092. * @property {array} items - array of {@link TextItem}
  50093. * @property {Object} styles - {@link TextStyles} objects, indexed by font name.
  50094. */
  50095. /**
  50096. * Page text content part.
  50097. *
  50098. * @typedef {Object} TextItem
  50099. * @property {string} str - text content.
  50100. * @property {string} dir - text direction: 'ttb', 'ltr' or 'rtl'.
  50101. * @property {array} transform - transformation matrix.
  50102. * @property {number} width - width in device space.
  50103. * @property {number} height - height in device space.
  50104. * @property {string} fontName - font name used by pdf.js for converted font.
  50105. */
  50106. /**
  50107. * Text style.
  50108. *
  50109. * @typedef {Object} TextStyle
  50110. * @property {number} ascent - font ascent.
  50111. * @property {number} descent - font descent.
  50112. * @property {boolean} vertical - text is in vertical mode.
  50113. * @property {string} fontFamily - possible font family
  50114. */
  50115. /**
  50116. * Page annotation parameters.
  50117. *
  50118. * @typedef {Object} GetAnnotationsParameters
  50119. * @property {string} intent - Determines the annotations that will be fetched,
  50120. * can be either 'display' (viewable annotations) or 'print'
  50121. * (printable annotations).
  50122. * If the parameter is omitted, all annotations are fetched.
  50123. */
  50124. /**
  50125. * Page render parameters.
  50126. *
  50127. * @typedef {Object} RenderParameters
  50128. * @property {Object} canvasContext - A 2D context of a DOM Canvas object.
  50129. * @property {PageViewport} viewport - Rendering viewport obtained by
  50130. * calling of PDFPage.getViewport method.
  50131. * @property {string} intent - Rendering intent, can be 'display' or 'print'
  50132. * (default value is 'display').
  50133. * @property {boolean} renderInteractiveForms - (optional) Whether or not
  50134. * interactive form elements are rendered in the display
  50135. * layer. If so, we do not render them on canvas as well.
  50136. * @property {Array} transform - (optional) Additional transform, applied
  50137. * just before viewport transform.
  50138. * @property {Object} imageLayer - (optional) An object that has beginLayout,
  50139. * endLayout and appendImage functions.
  50140. * @property {function} continueCallback - (deprecated) A function that will be
  50141. * called each time the rendering is paused. To continue
  50142. * rendering call the function that is the first argument
  50143. * to the callback.
  50144. */
  50145. /**
  50146. * PDF page operator list.
  50147. *
  50148. * @typedef {Object} PDFOperatorList
  50149. * @property {Array} fnArray - Array containing the operator functions.
  50150. * @property {Array} argsArray - Array containing the arguments of the
  50151. * functions.
  50152. */
  50153. /**
  50154. * Proxy to a PDFPage in the worker thread.
  50155. * @class
  50156. * @alias PDFPageProxy
  50157. */
  50158. var PDFPageProxy = function PDFPageProxyClosure() {
  50159. function PDFPageProxy(pageIndex, pageInfo, transport) {
  50160. this.pageIndex = pageIndex;
  50161. this.pageInfo = pageInfo;
  50162. this.transport = transport;
  50163. this.stats = new StatTimer();
  50164. this.stats.enabled = getDefaultSetting('enableStats');
  50165. this.commonObjs = transport.commonObjs;
  50166. this.objs = new PDFObjects();
  50167. this.cleanupAfterRender = false;
  50168. this.pendingCleanup = false;
  50169. this.intentStates = Object.create(null);
  50170. this.destroyed = false;
  50171. }
  50172. PDFPageProxy.prototype = /** @lends PDFPageProxy.prototype */
  50173. {
  50174. /**
  50175. * @return {number} Page number of the page. First page is 1.
  50176. */
  50177. get pageNumber() {
  50178. return this.pageIndex + 1;
  50179. },
  50180. /**
  50181. * @return {number} The number of degrees the page is rotated clockwise.
  50182. */
  50183. get rotate() {
  50184. return this.pageInfo.rotate;
  50185. },
  50186. /**
  50187. * @return {Object} The reference that points to this page. It has 'num' and
  50188. * 'gen' properties.
  50189. */
  50190. get ref() {
  50191. return this.pageInfo.ref;
  50192. },
  50193. /**
  50194. * @return {Array} An array of the visible portion of the PDF page in the
  50195. * user space units - [x1, y1, x2, y2].
  50196. */
  50197. get view() {
  50198. return this.pageInfo.view;
  50199. },
  50200. /**
  50201. * @param {number} scale The desired scale of the viewport.
  50202. * @param {number} rotate Degrees to rotate the viewport. If omitted this
  50203. * defaults to the page rotation.
  50204. * @return {PageViewport} Contains 'width' and 'height' properties
  50205. * along with transforms required for rendering.
  50206. */
  50207. getViewport: function PDFPageProxy_getViewport(scale, rotate) {
  50208. if (arguments.length < 2) {
  50209. rotate = this.rotate;
  50210. }
  50211. return new PageViewport(this.view, scale, rotate, 0, 0);
  50212. },
  50213. /**
  50214. * @param {GetAnnotationsParameters} params - Annotation parameters.
  50215. * @return {Promise} A promise that is resolved with an {Array} of the
  50216. * annotation objects.
  50217. */
  50218. getAnnotations: function PDFPageProxy_getAnnotations(params) {
  50219. var intent = params && params.intent || null;
  50220. if (!this.annotationsPromise || this.annotationsIntent !== intent) {
  50221. this.annotationsPromise = this.transport.getAnnotations(this.pageIndex, intent);
  50222. this.annotationsIntent = intent;
  50223. }
  50224. return this.annotationsPromise;
  50225. },
  50226. /**
  50227. * Begins the process of rendering a page to the desired context.
  50228. * @param {RenderParameters} params Page render parameters.
  50229. * @return {RenderTask} An object that contains the promise, which
  50230. * is resolved when the page finishes rendering.
  50231. */
  50232. render: function PDFPageProxy_render(params) {
  50233. var stats = this.stats;
  50234. stats.time('Overall');
  50235. // If there was a pending destroy cancel it so no cleanup happens during
  50236. // this call to render.
  50237. this.pendingCleanup = false;
  50238. var renderingIntent = params.intent === 'print' ? 'print' : 'display';
  50239. var renderInteractiveForms = params.renderInteractiveForms === true ? true : /* Default */
  50240. false;
  50241. if (!this.intentStates[renderingIntent]) {
  50242. this.intentStates[renderingIntent] = Object.create(null);
  50243. }
  50244. var intentState = this.intentStates[renderingIntent];
  50245. // If there's no displayReadyCapability yet, then the operatorList
  50246. // was never requested before. Make the request and create the promise.
  50247. if (!intentState.displayReadyCapability) {
  50248. intentState.receivingOperatorList = true;
  50249. intentState.displayReadyCapability = createPromiseCapability();
  50250. intentState.operatorList = {
  50251. fnArray: [],
  50252. argsArray: [],
  50253. lastChunk: false
  50254. };
  50255. this.stats.time('Page Request');
  50256. this.transport.messageHandler.send('RenderPageRequest', {
  50257. pageIndex: this.pageNumber - 1,
  50258. intent: renderingIntent,
  50259. renderInteractiveForms: renderInteractiveForms
  50260. });
  50261. }
  50262. var internalRenderTask = new InternalRenderTask(complete, params, this.objs, this.commonObjs, intentState.operatorList, this.pageNumber);
  50263. internalRenderTask.useRequestAnimationFrame = renderingIntent !== 'print';
  50264. if (!intentState.renderTasks) {
  50265. intentState.renderTasks = [];
  50266. }
  50267. intentState.renderTasks.push(internalRenderTask);
  50268. var renderTask = internalRenderTask.task;
  50269. // Obsolete parameter support
  50270. if (params.continueCallback) {
  50271. deprecated('render is used with continueCallback parameter');
  50272. renderTask.onContinue = params.continueCallback;
  50273. }
  50274. var self = this;
  50275. intentState.displayReadyCapability.promise.then(function pageDisplayReadyPromise(transparency) {
  50276. if (self.pendingCleanup) {
  50277. complete();
  50278. return;
  50279. }
  50280. stats.time('Rendering');
  50281. internalRenderTask.initializeGraphics(transparency);
  50282. internalRenderTask.operatorListChanged();
  50283. }, function pageDisplayReadPromiseError(reason) {
  50284. complete(reason);
  50285. });
  50286. function complete(error) {
  50287. var i = intentState.renderTasks.indexOf(internalRenderTask);
  50288. if (i >= 0) {
  50289. intentState.renderTasks.splice(i, 1);
  50290. }
  50291. if (self.cleanupAfterRender) {
  50292. self.pendingCleanup = true;
  50293. }
  50294. self._tryCleanup();
  50295. if (error) {
  50296. internalRenderTask.capability.reject(error);
  50297. } else {
  50298. internalRenderTask.capability.resolve();
  50299. }
  50300. stats.timeEnd('Rendering');
  50301. stats.timeEnd('Overall');
  50302. }
  50303. return renderTask;
  50304. },
  50305. /**
  50306. * @return {Promise} A promise resolved with an {@link PDFOperatorList}
  50307. * object that represents page's operator list.
  50308. */
  50309. getOperatorList: function PDFPageProxy_getOperatorList() {
  50310. function operatorListChanged() {
  50311. if (intentState.operatorList.lastChunk) {
  50312. intentState.opListReadCapability.resolve(intentState.operatorList);
  50313. var i = intentState.renderTasks.indexOf(opListTask);
  50314. if (i >= 0) {
  50315. intentState.renderTasks.splice(i, 1);
  50316. }
  50317. }
  50318. }
  50319. var renderingIntent = 'oplist';
  50320. if (!this.intentStates[renderingIntent]) {
  50321. this.intentStates[renderingIntent] = Object.create(null);
  50322. }
  50323. var intentState = this.intentStates[renderingIntent];
  50324. var opListTask;
  50325. if (!intentState.opListReadCapability) {
  50326. opListTask = {};
  50327. opListTask.operatorListChanged = operatorListChanged;
  50328. intentState.receivingOperatorList = true;
  50329. intentState.opListReadCapability = createPromiseCapability();
  50330. intentState.renderTasks = [];
  50331. intentState.renderTasks.push(opListTask);
  50332. intentState.operatorList = {
  50333. fnArray: [],
  50334. argsArray: [],
  50335. lastChunk: false
  50336. };
  50337. this.transport.messageHandler.send('RenderPageRequest', {
  50338. pageIndex: this.pageIndex,
  50339. intent: renderingIntent
  50340. });
  50341. }
  50342. return intentState.opListReadCapability.promise;
  50343. },
  50344. /**
  50345. * @param {getTextContentParameters} params - getTextContent parameters.
  50346. * @return {Promise} That is resolved a {@link TextContent}
  50347. * object that represent the page text content.
  50348. */
  50349. getTextContent: function PDFPageProxy_getTextContent(params) {
  50350. return this.transport.messageHandler.sendWithPromise('GetTextContent', {
  50351. pageIndex: this.pageNumber - 1,
  50352. normalizeWhitespace: params && params.normalizeWhitespace === true ? true : /* Default */
  50353. false,
  50354. combineTextItems: params && params.disableCombineTextItems === true ? false : /* Default */
  50355. true
  50356. });
  50357. },
  50358. /**
  50359. * Destroys page object.
  50360. */
  50361. _destroy: function PDFPageProxy_destroy() {
  50362. this.destroyed = true;
  50363. this.transport.pageCache[this.pageIndex] = null;
  50364. var waitOn = [];
  50365. Object.keys(this.intentStates).forEach(function (intent) {
  50366. if (intent === 'oplist') {
  50367. // Avoid errors below, since the renderTasks are just stubs.
  50368. return;
  50369. }
  50370. var intentState = this.intentStates[intent];
  50371. intentState.renderTasks.forEach(function (renderTask) {
  50372. var renderCompleted = renderTask.capability.promise.catch(function () {
  50373. });
  50374. // ignoring failures
  50375. waitOn.push(renderCompleted);
  50376. renderTask.cancel();
  50377. });
  50378. }, this);
  50379. this.objs.clear();
  50380. this.annotationsPromise = null;
  50381. this.pendingCleanup = false;
  50382. return Promise.all(waitOn);
  50383. },
  50384. /**
  50385. * Cleans up resources allocated by the page. (deprecated)
  50386. */
  50387. destroy: function () {
  50388. deprecated('page destroy method, use cleanup() instead');
  50389. this.cleanup();
  50390. },
  50391. /**
  50392. * Cleans up resources allocated by the page.
  50393. */
  50394. cleanup: function PDFPageProxy_cleanup() {
  50395. this.pendingCleanup = true;
  50396. this._tryCleanup();
  50397. },
  50398. /**
  50399. * For internal use only. Attempts to clean up if rendering is in a state
  50400. * where that's possible.
  50401. * @ignore
  50402. */
  50403. _tryCleanup: function PDFPageProxy_tryCleanup() {
  50404. if (!this.pendingCleanup || Object.keys(this.intentStates).some(function (intent) {
  50405. var intentState = this.intentStates[intent];
  50406. return intentState.renderTasks.length !== 0 || intentState.receivingOperatorList;
  50407. }, this)) {
  50408. return;
  50409. }
  50410. Object.keys(this.intentStates).forEach(function (intent) {
  50411. delete this.intentStates[intent];
  50412. }, this);
  50413. this.objs.clear();
  50414. this.annotationsPromise = null;
  50415. this.pendingCleanup = false;
  50416. },
  50417. /**
  50418. * For internal use only.
  50419. * @ignore
  50420. */
  50421. _startRenderPage: function PDFPageProxy_startRenderPage(transparency, intent) {
  50422. var intentState = this.intentStates[intent];
  50423. // TODO Refactor RenderPageRequest to separate rendering
  50424. // and operator list logic
  50425. if (intentState.displayReadyCapability) {
  50426. intentState.displayReadyCapability.resolve(transparency);
  50427. }
  50428. },
  50429. /**
  50430. * For internal use only.
  50431. * @ignore
  50432. */
  50433. _renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk, intent) {
  50434. var intentState = this.intentStates[intent];
  50435. var i, ii;
  50436. // Add the new chunk to the current operator list.
  50437. for (i = 0, ii = operatorListChunk.length; i < ii; i++) {
  50438. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  50439. intentState.operatorList.argsArray.push(operatorListChunk.argsArray[i]);
  50440. }
  50441. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  50442. // Notify all the rendering tasks there are more operators to be consumed.
  50443. for (i = 0; i < intentState.renderTasks.length; i++) {
  50444. intentState.renderTasks[i].operatorListChanged();
  50445. }
  50446. if (operatorListChunk.lastChunk) {
  50447. intentState.receivingOperatorList = false;
  50448. this._tryCleanup();
  50449. }
  50450. }
  50451. };
  50452. return PDFPageProxy;
  50453. }();
  50454. /**
  50455. * PDF.js web worker abstraction, it controls instantiation of PDF documents and
  50456. * WorkerTransport for them. If creation of a web worker is not possible,
  50457. * a "fake" worker will be used instead.
  50458. * @class
  50459. */
  50460. var PDFWorker = function PDFWorkerClosure() {
  50461. var nextFakeWorkerId = 0;
  50462. function getWorkerSrc() {
  50463. if (typeof workerSrc !== 'undefined') {
  50464. return workerSrc;
  50465. }
  50466. if (getDefaultSetting('workerSrc')) {
  50467. return getDefaultSetting('workerSrc');
  50468. }
  50469. if (pdfjsFilePath) {
  50470. return pdfjsFilePath.replace(/\.js$/i, '.worker.js');
  50471. }
  50472. error('No PDFJS.workerSrc specified');
  50473. }
  50474. var fakeWorkerFilesLoadedCapability;
  50475. // Loads worker code into main thread.
  50476. function setupFakeWorkerGlobal() {
  50477. var WorkerMessageHandler;
  50478. if (fakeWorkerFilesLoadedCapability) {
  50479. return fakeWorkerFilesLoadedCapability.promise;
  50480. }
  50481. fakeWorkerFilesLoadedCapability = createPromiseCapability();
  50482. WorkerMessageHandler = pdfjsLibs.pdfjsCoreWorker.WorkerMessageHandler;
  50483. fakeWorkerFilesLoadedCapability.resolve(WorkerMessageHandler);
  50484. return fakeWorkerFilesLoadedCapability.promise;
  50485. }
  50486. function FakeWorkerPort(defer) {
  50487. this._listeners = [];
  50488. this._defer = defer;
  50489. this._deferred = Promise.resolve(undefined);
  50490. }
  50491. FakeWorkerPort.prototype = {
  50492. postMessage: function (obj, transfers) {
  50493. function cloneValue(value) {
  50494. // Trying to perform a structured clone close to the spec, including
  50495. // transfers.
  50496. if (typeof value !== 'object' || value === null) {
  50497. return value;
  50498. }
  50499. if (cloned.has(value)) {
  50500. // already cloned the object
  50501. return cloned.get(value);
  50502. }
  50503. var result;
  50504. var buffer;
  50505. if ((buffer = value.buffer) && isArrayBuffer(buffer)) {
  50506. // We found object with ArrayBuffer (typed array).
  50507. var transferable = transfers && transfers.indexOf(buffer) >= 0;
  50508. if (value === buffer) {
  50509. // Special case when we are faking typed arrays in compatibility.js.
  50510. result = value;
  50511. } else if (transferable) {
  50512. result = new value.constructor(buffer, value.byteOffset, value.byteLength);
  50513. } else {
  50514. result = new value.constructor(value);
  50515. }
  50516. cloned.set(value, result);
  50517. return result;
  50518. }
  50519. result = isArray(value) ? [] : {};
  50520. cloned.set(value, result);
  50521. // adding to cache now for cyclic references
  50522. // Cloning all value and object properties, however ignoring properties
  50523. // defined via getter.
  50524. for (var i in value) {
  50525. var desc, p = value;
  50526. while (!(desc = Object.getOwnPropertyDescriptor(p, i))) {
  50527. p = Object.getPrototypeOf(p);
  50528. }
  50529. if (typeof desc.value === 'undefined' || typeof desc.value === 'function') {
  50530. continue;
  50531. }
  50532. result[i] = cloneValue(desc.value);
  50533. }
  50534. return result;
  50535. }
  50536. if (!this._defer) {
  50537. this._listeners.forEach(function (listener) {
  50538. listener.call(this, { data: obj });
  50539. }, this);
  50540. return;
  50541. }
  50542. var cloned = new WeakMap();
  50543. var e = { data: cloneValue(obj) };
  50544. this._deferred.then(function () {
  50545. this._listeners.forEach(function (listener) {
  50546. listener.call(this, e);
  50547. }, this);
  50548. }.bind(this));
  50549. },
  50550. addEventListener: function (name, listener) {
  50551. this._listeners.push(listener);
  50552. },
  50553. removeEventListener: function (name, listener) {
  50554. var i = this._listeners.indexOf(listener);
  50555. this._listeners.splice(i, 1);
  50556. },
  50557. terminate: function () {
  50558. this._listeners = [];
  50559. }
  50560. };
  50561. function createCDNWrapper(url) {
  50562. // We will rely on blob URL's property to specify origin.
  50563. // We want this function to fail in case if createObjectURL or Blob do not
  50564. // exist or fail for some reason -- our Worker creation will fail anyway.
  50565. var wrapper = 'importScripts(\'' + url + '\');';
  50566. return URL.createObjectURL(new Blob([wrapper]));
  50567. }
  50568. function PDFWorker(name) {
  50569. this.name = name;
  50570. this.destroyed = false;
  50571. this._readyCapability = createPromiseCapability();
  50572. this._port = null;
  50573. this._webWorker = null;
  50574. this._messageHandler = null;
  50575. this._initialize();
  50576. }
  50577. PDFWorker.prototype = /** @lends PDFWorker.prototype */
  50578. {
  50579. get promise() {
  50580. return this._readyCapability.promise;
  50581. },
  50582. get port() {
  50583. return this._port;
  50584. },
  50585. get messageHandler() {
  50586. return this._messageHandler;
  50587. },
  50588. _initialize: function PDFWorker_initialize() {
  50589. // Either workers are disabled, not supported or have thrown an exception.
  50590. // Thus, we fallback to a faked worker.
  50591. this._setupFakeWorker();
  50592. },
  50593. _setupFakeWorker: function PDFWorker_setupFakeWorker() {
  50594. if (!isWorkerDisabled && !getDefaultSetting('disableWorker')) {
  50595. warn('Setting up fake worker.');
  50596. isWorkerDisabled = true;
  50597. }
  50598. setupFakeWorkerGlobal().then(function (WorkerMessageHandler) {
  50599. if (this.destroyed) {
  50600. this._readyCapability.reject(new Error('Worker was destroyed'));
  50601. return;
  50602. }
  50603. // We cannot turn on proper fake port simulation (this includes
  50604. // structured cloning) when typed arrays are not supported. Relying
  50605. // on a chance that messages will be sent in proper order.
  50606. var isTypedArraysPresent = Uint8Array !== Float32Array;
  50607. var port = new FakeWorkerPort(isTypedArraysPresent);
  50608. this._port = port;
  50609. // All fake workers use the same port, making id unique.
  50610. var id = 'fake' + nextFakeWorkerId++;
  50611. // If the main thread is our worker, setup the handling for the
  50612. // messages -- the main thread sends to it self.
  50613. var workerHandler = new MessageHandler(id + '_worker', id, port);
  50614. WorkerMessageHandler.setup(workerHandler, port);
  50615. var messageHandler = new MessageHandler(id, id + '_worker', port);
  50616. this._messageHandler = messageHandler;
  50617. this._readyCapability.resolve();
  50618. }.bind(this));
  50619. },
  50620. /**
  50621. * Destroys the worker instance.
  50622. */
  50623. destroy: function PDFWorker_destroy() {
  50624. this.destroyed = true;
  50625. if (this._webWorker) {
  50626. // We need to terminate only web worker created resource.
  50627. this._webWorker.terminate();
  50628. this._webWorker = null;
  50629. }
  50630. this._port = null;
  50631. if (this._messageHandler) {
  50632. this._messageHandler.destroy();
  50633. this._messageHandler = null;
  50634. }
  50635. }
  50636. };
  50637. return PDFWorker;
  50638. }();
  50639. /**
  50640. * For internal use only.
  50641. * @ignore
  50642. */
  50643. var WorkerTransport = function WorkerTransportClosure() {
  50644. function WorkerTransport(messageHandler, loadingTask, pdfDataRangeTransport) {
  50645. this.messageHandler = messageHandler;
  50646. this.loadingTask = loadingTask;
  50647. this.pdfDataRangeTransport = pdfDataRangeTransport;
  50648. this.commonObjs = new PDFObjects();
  50649. this.fontLoader = new FontLoader(loadingTask.docId);
  50650. this.destroyed = false;
  50651. this.destroyCapability = null;
  50652. this.pageCache = [];
  50653. this.pagePromises = [];
  50654. this.downloadInfoCapability = createPromiseCapability();
  50655. this.setupMessageHandler();
  50656. }
  50657. WorkerTransport.prototype = {
  50658. destroy: function WorkerTransport_destroy() {
  50659. if (this.destroyCapability) {
  50660. return this.destroyCapability.promise;
  50661. }
  50662. this.destroyed = true;
  50663. this.destroyCapability = createPromiseCapability();
  50664. var waitOn = [];
  50665. // We need to wait for all renderings to be completed, e.g.
  50666. // timeout/rAF can take a long time.
  50667. this.pageCache.forEach(function (page) {
  50668. if (page) {
  50669. waitOn.push(page._destroy());
  50670. }
  50671. });
  50672. this.pageCache = [];
  50673. this.pagePromises = [];
  50674. var self = this;
  50675. // We also need to wait for the worker to finish its long running tasks.
  50676. var terminated = this.messageHandler.sendWithPromise('Terminate', null);
  50677. waitOn.push(terminated);
  50678. Promise.all(waitOn).then(function () {
  50679. self.fontLoader.clear();
  50680. if (self.pdfDataRangeTransport) {
  50681. self.pdfDataRangeTransport.abort();
  50682. self.pdfDataRangeTransport = null;
  50683. }
  50684. if (self.messageHandler) {
  50685. self.messageHandler.destroy();
  50686. self.messageHandler = null;
  50687. }
  50688. self.destroyCapability.resolve();
  50689. }, this.destroyCapability.reject);
  50690. return this.destroyCapability.promise;
  50691. },
  50692. setupMessageHandler: function WorkerTransport_setupMessageHandler() {
  50693. var messageHandler = this.messageHandler;
  50694. function updatePassword(password) {
  50695. messageHandler.send('UpdatePassword', password);
  50696. }
  50697. var pdfDataRangeTransport = this.pdfDataRangeTransport;
  50698. if (pdfDataRangeTransport) {
  50699. pdfDataRangeTransport.addRangeListener(function (begin, chunk) {
  50700. messageHandler.send('OnDataRange', {
  50701. begin: begin,
  50702. chunk: chunk
  50703. });
  50704. });
  50705. pdfDataRangeTransport.addProgressListener(function (loaded) {
  50706. messageHandler.send('OnDataProgress', { loaded: loaded });
  50707. });
  50708. pdfDataRangeTransport.addProgressiveReadListener(function (chunk) {
  50709. messageHandler.send('OnDataRange', { chunk: chunk });
  50710. });
  50711. messageHandler.on('RequestDataRange', function transportDataRange(data) {
  50712. pdfDataRangeTransport.requestDataRange(data.begin, data.end);
  50713. }, this);
  50714. }
  50715. messageHandler.on('GetDoc', function transportDoc(data) {
  50716. var pdfInfo = data.pdfInfo;
  50717. this.numPages = data.pdfInfo.numPages;
  50718. var loadingTask = this.loadingTask;
  50719. var pdfDocument = new PDFDocumentProxy(pdfInfo, this, loadingTask);
  50720. this.pdfDocument = pdfDocument;
  50721. loadingTask._capability.resolve(pdfDocument);
  50722. }, this);
  50723. messageHandler.on('NeedPassword', function transportNeedPassword(exception) {
  50724. var loadingTask = this.loadingTask;
  50725. if (loadingTask.onPassword) {
  50726. return loadingTask.onPassword(updatePassword, PasswordResponses.NEED_PASSWORD);
  50727. }
  50728. loadingTask._capability.reject(new PasswordException(exception.message, exception.code));
  50729. }, this);
  50730. messageHandler.on('IncorrectPassword', function transportIncorrectPassword(exception) {
  50731. var loadingTask = this.loadingTask;
  50732. if (loadingTask.onPassword) {
  50733. return loadingTask.onPassword(updatePassword, PasswordResponses.INCORRECT_PASSWORD);
  50734. }
  50735. loadingTask._capability.reject(new PasswordException(exception.message, exception.code));
  50736. }, this);
  50737. messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) {
  50738. this.loadingTask._capability.reject(new InvalidPDFException(exception.message));
  50739. }, this);
  50740. messageHandler.on('MissingPDF', function transportMissingPDF(exception) {
  50741. this.loadingTask._capability.reject(new MissingPDFException(exception.message));
  50742. }, this);
  50743. messageHandler.on('UnexpectedResponse', function transportUnexpectedResponse(exception) {
  50744. this.loadingTask._capability.reject(new UnexpectedResponseException(exception.message, exception.status));
  50745. }, this);
  50746. messageHandler.on('UnknownError', function transportUnknownError(exception) {
  50747. this.loadingTask._capability.reject(new UnknownErrorException(exception.message, exception.details));
  50748. }, this);
  50749. messageHandler.on('DataLoaded', function transportPage(data) {
  50750. this.downloadInfoCapability.resolve(data);
  50751. }, this);
  50752. messageHandler.on('PDFManagerReady', function transportPage(data) {
  50753. if (this.pdfDataRangeTransport) {
  50754. this.pdfDataRangeTransport.transportReady();
  50755. }
  50756. }, this);
  50757. messageHandler.on('StartRenderPage', function transportRender(data) {
  50758. if (this.destroyed) {
  50759. return;
  50760. }
  50761. // Ignore any pending requests if the worker was terminated.
  50762. var page = this.pageCache[data.pageIndex];
  50763. page.stats.timeEnd('Page Request');
  50764. page._startRenderPage(data.transparency, data.intent);
  50765. }, this);
  50766. messageHandler.on('RenderPageChunk', function transportRender(data) {
  50767. if (this.destroyed) {
  50768. return;
  50769. }
  50770. // Ignore any pending requests if the worker was terminated.
  50771. var page = this.pageCache[data.pageIndex];
  50772. page._renderPageChunk(data.operatorList, data.intent);
  50773. }, this);
  50774. messageHandler.on('commonobj', function transportObj(data) {
  50775. if (this.destroyed) {
  50776. return;
  50777. }
  50778. // Ignore any pending requests if the worker was terminated.
  50779. var id = data[0];
  50780. var type = data[1];
  50781. if (this.commonObjs.hasData(id)) {
  50782. return;
  50783. }
  50784. switch (type) {
  50785. case 'Font':
  50786. var exportedData = data[2];
  50787. if ('error' in exportedData) {
  50788. var exportedError = exportedData.error;
  50789. warn('Error during font loading: ' + exportedError);
  50790. this.commonObjs.resolve(id, exportedError);
  50791. break;
  50792. }
  50793. var fontRegistry = null;
  50794. if (getDefaultSetting('pdfBug') && globalScope.FontInspector && globalScope['FontInspector'].enabled) {
  50795. fontRegistry = {
  50796. registerFont: function (font, url) {
  50797. globalScope['FontInspector'].fontAdded(font, url);
  50798. }
  50799. };
  50800. }
  50801. var font = new FontFaceObject(exportedData, {
  50802. isEvalSuported: getDefaultSetting('isEvalSupported'),
  50803. disableFontFace: getDefaultSetting('disableFontFace'),
  50804. fontRegistry: fontRegistry
  50805. });
  50806. this.fontLoader.bind([font], function fontReady(fontObjs) {
  50807. this.commonObjs.resolve(id, font);
  50808. }.bind(this));
  50809. break;
  50810. case 'FontPath':
  50811. this.commonObjs.resolve(id, data[2]);
  50812. break;
  50813. default:
  50814. error('Got unknown common object type ' + type);
  50815. }
  50816. }, this);
  50817. messageHandler.on('obj', function transportObj(data) {
  50818. if (this.destroyed) {
  50819. return;
  50820. }
  50821. // Ignore any pending requests if the worker was terminated.
  50822. var id = data[0];
  50823. var pageIndex = data[1];
  50824. var type = data[2];
  50825. var pageProxy = this.pageCache[pageIndex];
  50826. var imageData;
  50827. if (pageProxy.objs.hasData(id)) {
  50828. return;
  50829. }
  50830. switch (type) {
  50831. case 'JpegStream':
  50832. imageData = data[3];
  50833. loadJpegStream(id, imageData, pageProxy.objs);
  50834. break;
  50835. case 'Image':
  50836. imageData = data[3];
  50837. pageProxy.objs.resolve(id, imageData);
  50838. // heuristics that will allow not to store large data
  50839. var MAX_IMAGE_SIZE_TO_STORE = 8000000;
  50840. if (imageData && 'data' in imageData && imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
  50841. pageProxy.cleanupAfterRender = true;
  50842. }
  50843. break;
  50844. default:
  50845. error('Got unknown object type ' + type);
  50846. }
  50847. }, this);
  50848. messageHandler.on('DocProgress', function transportDocProgress(data) {
  50849. if (this.destroyed) {
  50850. return;
  50851. }
  50852. // Ignore any pending requests if the worker was terminated.
  50853. var loadingTask = this.loadingTask;
  50854. if (loadingTask.onProgress) {
  50855. loadingTask.onProgress({
  50856. loaded: data.loaded,
  50857. total: data.total
  50858. });
  50859. }
  50860. }, this);
  50861. messageHandler.on('PageError', function transportError(data) {
  50862. if (this.destroyed) {
  50863. return;
  50864. }
  50865. // Ignore any pending requests if the worker was terminated.
  50866. var page = this.pageCache[data.pageNum - 1];
  50867. var intentState = page.intentStates[data.intent];
  50868. if (intentState.displayReadyCapability) {
  50869. intentState.displayReadyCapability.reject(data.error);
  50870. } else {
  50871. error(data.error);
  50872. }
  50873. if (intentState.operatorList) {
  50874. // Mark operator list as complete.
  50875. intentState.operatorList.lastChunk = true;
  50876. for (var i = 0; i < intentState.renderTasks.length; i++) {
  50877. intentState.renderTasks[i].operatorListChanged();
  50878. }
  50879. }
  50880. }, this);
  50881. messageHandler.on('UnsupportedFeature', function transportUnsupportedFeature(data) {
  50882. if (this.destroyed) {
  50883. return;
  50884. }
  50885. // Ignore any pending requests if the worker was terminated.
  50886. var featureId = data.featureId;
  50887. var loadingTask = this.loadingTask;
  50888. if (loadingTask.onUnsupportedFeature) {
  50889. loadingTask.onUnsupportedFeature(featureId);
  50890. }
  50891. _UnsupportedManager.notify(featureId);
  50892. }, this);
  50893. messageHandler.on('JpegDecode', function (data) {
  50894. if (this.destroyed) {
  50895. return Promise.reject(new Error('Worker was destroyed'));
  50896. }
  50897. var imageUrl = data[0];
  50898. var components = data[1];
  50899. if (components !== 3 && components !== 1) {
  50900. return Promise.reject(new Error('Only 3 components or 1 component can be returned'));
  50901. }
  50902. return new Promise(function (resolve, reject) {
  50903. var img = new Image();
  50904. img.onload = function () {
  50905. var width = img.width;
  50906. var height = img.height;
  50907. var size = width * height;
  50908. var rgbaLength = size * 4;
  50909. var buf = new Uint8Array(size * components);
  50910. var tmpCanvas = createScratchCanvas(width, height);
  50911. var tmpCtx = tmpCanvas.getContext('2d');
  50912. tmpCtx.drawImage(img, 0, 0);
  50913. var data = tmpCtx.getImageData(0, 0, width, height).data;
  50914. var i, j;
  50915. if (components === 3) {
  50916. for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
  50917. buf[j] = data[i];
  50918. buf[j + 1] = data[i + 1];
  50919. buf[j + 2] = data[i + 2];
  50920. }
  50921. } else if (components === 1) {
  50922. for (i = 0, j = 0; i < rgbaLength; i += 4, j++) {
  50923. buf[j] = data[i];
  50924. }
  50925. }
  50926. resolve({
  50927. data: buf,
  50928. width: width,
  50929. height: height
  50930. });
  50931. };
  50932. img.onerror = function () {
  50933. reject(new Error('JpegDecode failed to load image'));
  50934. };
  50935. img.src = imageUrl;
  50936. });
  50937. }, this);
  50938. },
  50939. getData: function WorkerTransport_getData() {
  50940. return this.messageHandler.sendWithPromise('GetData', null);
  50941. },
  50942. getPage: function WorkerTransport_getPage(pageNumber, capability) {
  50943. if (!isInt(pageNumber) || pageNumber <= 0 || pageNumber > this.numPages) {
  50944. return Promise.reject(new Error('Invalid page request'));
  50945. }
  50946. var pageIndex = pageNumber - 1;
  50947. if (pageIndex in this.pagePromises) {
  50948. return this.pagePromises[pageIndex];
  50949. }
  50950. var promise = this.messageHandler.sendWithPromise('GetPage', { pageIndex: pageIndex }).then(function (pageInfo) {
  50951. if (this.destroyed) {
  50952. throw new Error('Transport destroyed');
  50953. }
  50954. var page = new PDFPageProxy(pageIndex, pageInfo, this);
  50955. this.pageCache[pageIndex] = page;
  50956. return page;
  50957. }.bind(this));
  50958. this.pagePromises[pageIndex] = promise;
  50959. return promise;
  50960. },
  50961. getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
  50962. return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref }).catch(function (reason) {
  50963. return Promise.reject(new Error(reason));
  50964. });
  50965. },
  50966. getAnnotations: function WorkerTransport_getAnnotations(pageIndex, intent) {
  50967. return this.messageHandler.sendWithPromise('GetAnnotations', {
  50968. pageIndex: pageIndex,
  50969. intent: intent
  50970. });
  50971. },
  50972. getDestinations: function WorkerTransport_getDestinations() {
  50973. return this.messageHandler.sendWithPromise('GetDestinations', null);
  50974. },
  50975. getDestination: function WorkerTransport_getDestination(id) {
  50976. return this.messageHandler.sendWithPromise('GetDestination', { id: id });
  50977. },
  50978. getPageLabels: function WorkerTransport_getPageLabels() {
  50979. return this.messageHandler.sendWithPromise('GetPageLabels', null);
  50980. },
  50981. getAttachments: function WorkerTransport_getAttachments() {
  50982. return this.messageHandler.sendWithPromise('GetAttachments', null);
  50983. },
  50984. getJavaScript: function WorkerTransport_getJavaScript() {
  50985. return this.messageHandler.sendWithPromise('GetJavaScript', null);
  50986. },
  50987. getOutline: function WorkerTransport_getOutline() {
  50988. return this.messageHandler.sendWithPromise('GetOutline', null);
  50989. },
  50990. getMetadata: function WorkerTransport_getMetadata() {
  50991. return this.messageHandler.sendWithPromise('GetMetadata', null).then(function transportMetadata(results) {
  50992. return {
  50993. info: results[0],
  50994. metadata: results[1] ? new Metadata(results[1]) : null
  50995. };
  50996. });
  50997. },
  50998. getStats: function WorkerTransport_getStats() {
  50999. return this.messageHandler.sendWithPromise('GetStats', null);
  51000. },
  51001. startCleanup: function WorkerTransport_startCleanup() {
  51002. this.messageHandler.sendWithPromise('Cleanup', null).then(function endCleanup() {
  51003. for (var i = 0, ii = this.pageCache.length; i < ii; i++) {
  51004. var page = this.pageCache[i];
  51005. if (page) {
  51006. page.cleanup();
  51007. }
  51008. }
  51009. this.commonObjs.clear();
  51010. this.fontLoader.clear();
  51011. }.bind(this));
  51012. }
  51013. };
  51014. return WorkerTransport;
  51015. }();
  51016. /**
  51017. * A PDF document and page is built of many objects. E.g. there are objects
  51018. * for fonts, images, rendering code and such. These objects might get processed
  51019. * inside of a worker. The `PDFObjects` implements some basic functions to
  51020. * manage these objects.
  51021. * @ignore
  51022. */
  51023. var PDFObjects = function PDFObjectsClosure() {
  51024. function PDFObjects() {
  51025. this.objs = Object.create(null);
  51026. }
  51027. PDFObjects.prototype = {
  51028. /**
  51029. * Internal function.
  51030. * Ensures there is an object defined for `objId`.
  51031. */
  51032. ensureObj: function PDFObjects_ensureObj(objId) {
  51033. if (this.objs[objId]) {
  51034. return this.objs[objId];
  51035. }
  51036. var obj = {
  51037. capability: createPromiseCapability(),
  51038. data: null,
  51039. resolved: false
  51040. };
  51041. this.objs[objId] = obj;
  51042. return obj;
  51043. },
  51044. /**
  51045. * If called *without* callback, this returns the data of `objId` but the
  51046. * object needs to be resolved. If it isn't, this function throws.
  51047. *
  51048. * If called *with* a callback, the callback is called with the data of the
  51049. * object once the object is resolved. That means, if you call this
  51050. * function and the object is already resolved, the callback gets called
  51051. * right away.
  51052. */
  51053. get: function PDFObjects_get(objId, callback) {
  51054. // If there is a callback, then the get can be async and the object is
  51055. // not required to be resolved right now
  51056. if (callback) {
  51057. this.ensureObj(objId).capability.promise.then(callback);
  51058. return null;
  51059. }
  51060. // If there isn't a callback, the user expects to get the resolved data
  51061. // directly.
  51062. var obj = this.objs[objId];
  51063. // If there isn't an object yet or the object isn't resolved, then the
  51064. // data isn't ready yet!
  51065. if (!obj || !obj.resolved) {
  51066. error('Requesting object that isn\'t resolved yet ' + objId);
  51067. }
  51068. return obj.data;
  51069. },
  51070. /**
  51071. * Resolves the object `objId` with optional `data`.
  51072. */
  51073. resolve: function PDFObjects_resolve(objId, data) {
  51074. var obj = this.ensureObj(objId);
  51075. obj.resolved = true;
  51076. obj.data = data;
  51077. obj.capability.resolve(data);
  51078. },
  51079. isResolved: function PDFObjects_isResolved(objId) {
  51080. var objs = this.objs;
  51081. if (!objs[objId]) {
  51082. return false;
  51083. } else {
  51084. return objs[objId].resolved;
  51085. }
  51086. },
  51087. hasData: function PDFObjects_hasData(objId) {
  51088. return this.isResolved(objId);
  51089. },
  51090. /**
  51091. * Returns the data of `objId` if object exists, null otherwise.
  51092. */
  51093. getData: function PDFObjects_getData(objId) {
  51094. var objs = this.objs;
  51095. if (!objs[objId] || !objs[objId].resolved) {
  51096. return null;
  51097. } else {
  51098. return objs[objId].data;
  51099. }
  51100. },
  51101. clear: function PDFObjects_clear() {
  51102. this.objs = Object.create(null);
  51103. }
  51104. };
  51105. return PDFObjects;
  51106. }();
  51107. /**
  51108. * Allows controlling of the rendering tasks.
  51109. * @class
  51110. * @alias RenderTask
  51111. */
  51112. var RenderTask = function RenderTaskClosure() {
  51113. function RenderTask(internalRenderTask) {
  51114. this._internalRenderTask = internalRenderTask;
  51115. /**
  51116. * Callback for incremental rendering -- a function that will be called
  51117. * each time the rendering is paused. To continue rendering call the
  51118. * function that is the first argument to the callback.
  51119. * @type {function}
  51120. */
  51121. this.onContinue = null;
  51122. }
  51123. RenderTask.prototype = /** @lends RenderTask.prototype */
  51124. {
  51125. /**
  51126. * Promise for rendering task completion.
  51127. * @return {Promise}
  51128. */
  51129. get promise() {
  51130. return this._internalRenderTask.capability.promise;
  51131. },
  51132. /**
  51133. * Cancels the rendering task. If the task is currently rendering it will
  51134. * not be cancelled until graphics pauses with a timeout. The promise that
  51135. * this object extends will resolved when cancelled.
  51136. */
  51137. cancel: function RenderTask_cancel() {
  51138. this._internalRenderTask.cancel();
  51139. },
  51140. /**
  51141. * Registers callbacks to indicate the rendering task completion.
  51142. *
  51143. * @param {function} onFulfilled The callback for the rendering completion.
  51144. * @param {function} onRejected The callback for the rendering failure.
  51145. * @return {Promise} A promise that is resolved after the onFulfilled or
  51146. * onRejected callback.
  51147. */
  51148. then: function RenderTask_then(onFulfilled, onRejected) {
  51149. return this.promise.then.apply(this.promise, arguments);
  51150. }
  51151. };
  51152. return RenderTask;
  51153. }();
  51154. /**
  51155. * For internal use only.
  51156. * @ignore
  51157. */
  51158. var InternalRenderTask = function InternalRenderTaskClosure() {
  51159. function InternalRenderTask(callback, params, objs, commonObjs, operatorList, pageNumber) {
  51160. this.callback = callback;
  51161. this.params = params;
  51162. this.objs = objs;
  51163. this.commonObjs = commonObjs;
  51164. this.operatorListIdx = null;
  51165. this.operatorList = operatorList;
  51166. this.pageNumber = pageNumber;
  51167. this.running = false;
  51168. this.graphicsReadyCallback = null;
  51169. this.graphicsReady = false;
  51170. this.useRequestAnimationFrame = false;
  51171. this.cancelled = false;
  51172. this.capability = createPromiseCapability();
  51173. this.task = new RenderTask(this);
  51174. // caching this-bound methods
  51175. this._continueBound = this._continue.bind(this);
  51176. this._scheduleNextBound = this._scheduleNext.bind(this);
  51177. this._nextBound = this._next.bind(this);
  51178. }
  51179. InternalRenderTask.prototype = {
  51180. initializeGraphics: function InternalRenderTask_initializeGraphics(transparency) {
  51181. if (this.cancelled) {
  51182. return;
  51183. }
  51184. if (getDefaultSetting('pdfBug') && globalScope.StepperManager && globalScope.StepperManager.enabled) {
  51185. this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
  51186. this.stepper.init(this.operatorList);
  51187. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  51188. }
  51189. var params = this.params;
  51190. this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs, this.objs, params.imageLayer);
  51191. this.gfx.beginDrawing(params.transform, params.viewport, transparency);
  51192. this.operatorListIdx = 0;
  51193. this.graphicsReady = true;
  51194. if (this.graphicsReadyCallback) {
  51195. this.graphicsReadyCallback();
  51196. }
  51197. },
  51198. cancel: function InternalRenderTask_cancel() {
  51199. this.running = false;
  51200. this.cancelled = true;
  51201. this.callback('cancelled');
  51202. },
  51203. operatorListChanged: function InternalRenderTask_operatorListChanged() {
  51204. if (!this.graphicsReady) {
  51205. if (!this.graphicsReadyCallback) {
  51206. this.graphicsReadyCallback = this._continueBound;
  51207. }
  51208. return;
  51209. }
  51210. if (this.stepper) {
  51211. this.stepper.updateOperatorList(this.operatorList);
  51212. }
  51213. if (this.running) {
  51214. return;
  51215. }
  51216. this._continue();
  51217. },
  51218. _continue: function InternalRenderTask__continue() {
  51219. this.running = true;
  51220. if (this.cancelled) {
  51221. return;
  51222. }
  51223. if (this.task.onContinue) {
  51224. this.task.onContinue.call(this.task, this._scheduleNextBound);
  51225. } else {
  51226. this._scheduleNext();
  51227. }
  51228. },
  51229. _scheduleNext: function InternalRenderTask__scheduleNext() {
  51230. if (this.useRequestAnimationFrame && typeof window !== 'undefined') {
  51231. window.requestAnimationFrame(this._nextBound);
  51232. } else {
  51233. Promise.resolve(undefined).then(this._nextBound);
  51234. }
  51235. },
  51236. _next: function InternalRenderTask__next() {
  51237. if (this.cancelled) {
  51238. return;
  51239. }
  51240. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList, this.operatorListIdx, this._continueBound, this.stepper);
  51241. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  51242. this.running = false;
  51243. if (this.operatorList.lastChunk) {
  51244. this.gfx.endDrawing();
  51245. this.callback();
  51246. }
  51247. }
  51248. }
  51249. };
  51250. return InternalRenderTask;
  51251. }();
  51252. /**
  51253. * (Deprecated) Global observer of unsupported feature usages. Use
  51254. * onUnsupportedFeature callback of the {PDFDocumentLoadingTask} instance.
  51255. */
  51256. var _UnsupportedManager = function UnsupportedManagerClosure() {
  51257. var listeners = [];
  51258. return {
  51259. listen: function (cb) {
  51260. deprecated('Global UnsupportedManager.listen is used: ' + ' use PDFDocumentLoadingTask.onUnsupportedFeature instead');
  51261. listeners.push(cb);
  51262. },
  51263. notify: function (featureId) {
  51264. for (var i = 0, ii = listeners.length; i < ii; i++) {
  51265. listeners[i](featureId);
  51266. }
  51267. }
  51268. };
  51269. }();
  51270. if (typeof pdfjsVersion !== 'undefined') {
  51271. exports.version = pdfjsVersion;
  51272. }
  51273. if (typeof pdfjsBuild !== 'undefined') {
  51274. exports.build = pdfjsBuild;
  51275. }
  51276. exports.getDocument = getDocument;
  51277. exports.PDFDataRangeTransport = PDFDataRangeTransport;
  51278. exports.PDFWorker = PDFWorker;
  51279. exports.PDFDocumentProxy = PDFDocumentProxy;
  51280. exports.PDFPageProxy = PDFPageProxy;
  51281. exports._UnsupportedManager = _UnsupportedManager;
  51282. }));
  51283. (function (root, factory) {
  51284. factory(root.pdfjsCoreColorSpace = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreFunction);
  51285. }(this, function (exports, sharedUtil, corePrimitives, coreFunction) {
  51286. var error = sharedUtil.error;
  51287. var info = sharedUtil.info;
  51288. var isArray = sharedUtil.isArray;
  51289. var isString = sharedUtil.isString;
  51290. var shadow = sharedUtil.shadow;
  51291. var warn = sharedUtil.warn;
  51292. var isDict = corePrimitives.isDict;
  51293. var isName = corePrimitives.isName;
  51294. var isStream = corePrimitives.isStream;
  51295. var PDFFunction = coreFunction.PDFFunction;
  51296. var ColorSpace = function ColorSpaceClosure() {
  51297. /**
  51298. * Resizes an RGB image with 3 components.
  51299. * @param {TypedArray} src - The source buffer.
  51300. * @param {Number} bpc - Number of bits per component.
  51301. * @param {Number} w1 - Original width.
  51302. * @param {Number} h1 - Original height.
  51303. * @param {Number} w2 - New width.
  51304. * @param {Number} h2 - New height.
  51305. * @param {Number} alpha01 - Size reserved for the alpha channel.
  51306. * @param {TypedArray} dest - The destination buffer.
  51307. */
  51308. function resizeRgbImage(src, bpc, w1, h1, w2, h2, alpha01, dest) {
  51309. var COMPONENTS = 3;
  51310. alpha01 = alpha01 !== 1 ? 0 : alpha01;
  51311. var xRatio = w1 / w2;
  51312. var yRatio = h1 / h2;
  51313. var i, j, py, newIndex = 0, oldIndex;
  51314. var xScaled = new Uint16Array(w2);
  51315. var w1Scanline = w1 * COMPONENTS;
  51316. for (i = 0; i < w2; i++) {
  51317. xScaled[i] = Math.floor(i * xRatio) * COMPONENTS;
  51318. }
  51319. for (i = 0; i < h2; i++) {
  51320. py = Math.floor(i * yRatio) * w1Scanline;
  51321. for (j = 0; j < w2; j++) {
  51322. oldIndex = py + xScaled[j];
  51323. dest[newIndex++] = src[oldIndex++];
  51324. dest[newIndex++] = src[oldIndex++];
  51325. dest[newIndex++] = src[oldIndex++];
  51326. newIndex += alpha01;
  51327. }
  51328. }
  51329. }
  51330. // Constructor should define this.numComps, this.defaultColor, this.name
  51331. function ColorSpace() {
  51332. error('should not call ColorSpace constructor');
  51333. }
  51334. ColorSpace.prototype = {
  51335. /**
  51336. * Converts the color value to the RGB color. The color components are
  51337. * located in the src array starting from the srcOffset. Returns the array
  51338. * of the rgb components, each value ranging from [0,255].
  51339. */
  51340. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  51341. var rgb = new Uint8Array(3);
  51342. this.getRgbItem(src, srcOffset, rgb, 0);
  51343. return rgb;
  51344. },
  51345. /**
  51346. * Converts the color value to the RGB color, similar to the getRgb method.
  51347. * The result placed into the dest array starting from the destOffset.
  51348. */
  51349. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset, dest, destOffset) {
  51350. error('Should not call ColorSpace.getRgbItem');
  51351. },
  51352. /**
  51353. * Converts the specified number of the color values to the RGB colors.
  51354. * The colors are located in the src array starting from the srcOffset.
  51355. * The result is placed into the dest array starting from the destOffset.
  51356. * The src array items shall be in [0,2^bits) range, the dest array items
  51357. * will be in [0,255] range. alpha01 indicates how many alpha components
  51358. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  51359. * array).
  51360. */
  51361. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  51362. error('Should not call ColorSpace.getRgbBuffer');
  51363. },
  51364. /**
  51365. * Determines the number of bytes required to store the result of the
  51366. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  51367. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  51368. */
  51369. getOutputLength: function ColorSpace_getOutputLength(inputLength, alpha01) {
  51370. error('Should not call ColorSpace.getOutputLength');
  51371. },
  51372. /**
  51373. * Returns true if source data will be equal the result/output data.
  51374. */
  51375. isPassthrough: function ColorSpace_isPassthrough(bits) {
  51376. return false;
  51377. },
  51378. /**
  51379. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  51380. * how many alpha components there are in the dest array; it will be either
  51381. * 0 (RGB array) or 1 (RGBA array).
  51382. */
  51383. fillRgb: function ColorSpace_fillRgb(dest, originalWidth, originalHeight, width, height, actualHeight, bpc, comps, alpha01) {
  51384. var count = originalWidth * originalHeight;
  51385. var rgbBuf = null;
  51386. var numComponentColors = 1 << bpc;
  51387. var needsResizing = originalHeight !== height || originalWidth !== width;
  51388. var i, ii;
  51389. if (this.isPassthrough(bpc)) {
  51390. rgbBuf = comps;
  51391. } else if (this.numComps === 1 && count > numComponentColors && this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  51392. // Optimization: create a color map when there is just one component and
  51393. // we are converting more colors than the size of the color map. We
  51394. // don't build the map if the colorspace is gray or rgb since those
  51395. // methods are faster than building a map. This mainly offers big speed
  51396. // ups for indexed and alternate colorspaces.
  51397. //
  51398. // TODO it may be worth while to cache the color map. While running
  51399. // testing I never hit a cache so I will leave that out for now (perhaps
  51400. // we are reparsing colorspaces too much?).
  51401. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) : new Uint16Array(numComponentColors);
  51402. var key;
  51403. for (i = 0; i < numComponentColors; i++) {
  51404. allColors[i] = i;
  51405. }
  51406. var colorMap = new Uint8Array(numComponentColors * 3);
  51407. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc, /* alpha01 = */
  51408. 0);
  51409. var destPos, rgbPos;
  51410. if (!needsResizing) {
  51411. // Fill in the RGB values directly into |dest|.
  51412. destPos = 0;
  51413. for (i = 0; i < count; ++i) {
  51414. key = comps[i] * 3;
  51415. dest[destPos++] = colorMap[key];
  51416. dest[destPos++] = colorMap[key + 1];
  51417. dest[destPos++] = colorMap[key + 2];
  51418. destPos += alpha01;
  51419. }
  51420. } else {
  51421. rgbBuf = new Uint8Array(count * 3);
  51422. rgbPos = 0;
  51423. for (i = 0; i < count; ++i) {
  51424. key = comps[i] * 3;
  51425. rgbBuf[rgbPos++] = colorMap[key];
  51426. rgbBuf[rgbPos++] = colorMap[key + 1];
  51427. rgbBuf[rgbPos++] = colorMap[key + 2];
  51428. }
  51429. }
  51430. } else {
  51431. if (!needsResizing) {
  51432. // Fill in the RGB values directly into |dest|.
  51433. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc, alpha01);
  51434. } else {
  51435. rgbBuf = new Uint8Array(count * 3);
  51436. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc, /* alpha01 = */
  51437. 0);
  51438. }
  51439. }
  51440. if (rgbBuf) {
  51441. if (needsResizing) {
  51442. resizeRgbImage(rgbBuf, bpc, originalWidth, originalHeight, width, height, alpha01, dest);
  51443. } else {
  51444. rgbPos = 0;
  51445. destPos = 0;
  51446. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  51447. dest[destPos++] = rgbBuf[rgbPos++];
  51448. dest[destPos++] = rgbBuf[rgbPos++];
  51449. dest[destPos++] = rgbBuf[rgbPos++];
  51450. destPos += alpha01;
  51451. }
  51452. }
  51453. }
  51454. },
  51455. /**
  51456. * True if the colorspace has components in the default range of [0, 1].
  51457. * This should be true for all colorspaces except for lab color spaces
  51458. * which are [0,100], [-128, 127], [-128, 127].
  51459. */
  51460. usesZeroToOneRange: true
  51461. };
  51462. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  51463. var IR = ColorSpace.parseToIR(cs, xref, res);
  51464. if (IR instanceof AlternateCS) {
  51465. return IR;
  51466. }
  51467. return ColorSpace.fromIR(IR);
  51468. };
  51469. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  51470. var name = isArray(IR) ? IR[0] : IR;
  51471. var whitePoint, blackPoint, gamma;
  51472. switch (name) {
  51473. case 'DeviceGrayCS':
  51474. return this.singletons.gray;
  51475. case 'DeviceRgbCS':
  51476. return this.singletons.rgb;
  51477. case 'DeviceCmykCS':
  51478. return this.singletons.cmyk;
  51479. case 'CalGrayCS':
  51480. whitePoint = IR[1];
  51481. blackPoint = IR[2];
  51482. gamma = IR[3];
  51483. return new CalGrayCS(whitePoint, blackPoint, gamma);
  51484. case 'CalRGBCS':
  51485. whitePoint = IR[1];
  51486. blackPoint = IR[2];
  51487. gamma = IR[3];
  51488. var matrix = IR[4];
  51489. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  51490. case 'PatternCS':
  51491. var basePatternCS = IR[1];
  51492. if (basePatternCS) {
  51493. basePatternCS = ColorSpace.fromIR(basePatternCS);
  51494. }
  51495. return new PatternCS(basePatternCS);
  51496. case 'IndexedCS':
  51497. var baseIndexedCS = IR[1];
  51498. var hiVal = IR[2];
  51499. var lookup = IR[3];
  51500. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  51501. case 'AlternateCS':
  51502. var numComps = IR[1];
  51503. var alt = IR[2];
  51504. var tintFnIR = IR[3];
  51505. return new AlternateCS(numComps, ColorSpace.fromIR(alt), PDFFunction.fromIR(tintFnIR));
  51506. case 'LabCS':
  51507. whitePoint = IR[1];
  51508. blackPoint = IR[2];
  51509. var range = IR[3];
  51510. return new LabCS(whitePoint, blackPoint, range);
  51511. default:
  51512. error('Unknown name ' + name);
  51513. }
  51514. return null;
  51515. };
  51516. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  51517. if (isName(cs)) {
  51518. var colorSpaces = res.get('ColorSpace');
  51519. if (isDict(colorSpaces)) {
  51520. var refcs = colorSpaces.get(cs.name);
  51521. if (refcs) {
  51522. cs = refcs;
  51523. }
  51524. }
  51525. }
  51526. cs = xref.fetchIfRef(cs);
  51527. var mode;
  51528. if (isName(cs)) {
  51529. mode = cs.name;
  51530. this.mode = mode;
  51531. switch (mode) {
  51532. case 'DeviceGray':
  51533. case 'G':
  51534. return 'DeviceGrayCS';
  51535. case 'DeviceRGB':
  51536. case 'RGB':
  51537. return 'DeviceRgbCS';
  51538. case 'DeviceCMYK':
  51539. case 'CMYK':
  51540. return 'DeviceCmykCS';
  51541. case 'Pattern':
  51542. return [
  51543. 'PatternCS',
  51544. null
  51545. ];
  51546. default:
  51547. error('unrecognized colorspace ' + mode);
  51548. }
  51549. } else if (isArray(cs)) {
  51550. mode = xref.fetchIfRef(cs[0]).name;
  51551. this.mode = mode;
  51552. var numComps, params, alt, whitePoint, blackPoint, gamma;
  51553. switch (mode) {
  51554. case 'DeviceGray':
  51555. case 'G':
  51556. return 'DeviceGrayCS';
  51557. case 'DeviceRGB':
  51558. case 'RGB':
  51559. return 'DeviceRgbCS';
  51560. case 'DeviceCMYK':
  51561. case 'CMYK':
  51562. return 'DeviceCmykCS';
  51563. case 'CalGray':
  51564. params = xref.fetchIfRef(cs[1]);
  51565. whitePoint = params.getArray('WhitePoint');
  51566. blackPoint = params.getArray('BlackPoint');
  51567. gamma = params.get('Gamma');
  51568. return [
  51569. 'CalGrayCS',
  51570. whitePoint,
  51571. blackPoint,
  51572. gamma
  51573. ];
  51574. case 'CalRGB':
  51575. params = xref.fetchIfRef(cs[1]);
  51576. whitePoint = params.getArray('WhitePoint');
  51577. blackPoint = params.getArray('BlackPoint');
  51578. gamma = params.getArray('Gamma');
  51579. var matrix = params.getArray('Matrix');
  51580. return [
  51581. 'CalRGBCS',
  51582. whitePoint,
  51583. blackPoint,
  51584. gamma,
  51585. matrix
  51586. ];
  51587. case 'ICCBased':
  51588. var stream = xref.fetchIfRef(cs[1]);
  51589. var dict = stream.dict;
  51590. numComps = dict.get('N');
  51591. alt = dict.get('Alternate');
  51592. if (alt) {
  51593. var altIR = ColorSpace.parseToIR(alt, xref, res);
  51594. // Parse the /Alternate CS to ensure that the number of components
  51595. // are correct, and also (indirectly) that it is not a PatternCS.
  51596. var altCS = ColorSpace.fromIR(altIR);
  51597. if (altCS.numComps === numComps) {
  51598. return altIR;
  51599. }
  51600. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  51601. }
  51602. if (numComps === 1) {
  51603. return 'DeviceGrayCS';
  51604. } else if (numComps === 3) {
  51605. return 'DeviceRgbCS';
  51606. } else if (numComps === 4) {
  51607. return 'DeviceCmykCS';
  51608. }
  51609. break;
  51610. case 'Pattern':
  51611. var basePatternCS = cs[1] || null;
  51612. if (basePatternCS) {
  51613. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  51614. }
  51615. return [
  51616. 'PatternCS',
  51617. basePatternCS
  51618. ];
  51619. case 'Indexed':
  51620. case 'I':
  51621. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  51622. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  51623. var lookup = xref.fetchIfRef(cs[3]);
  51624. if (isStream(lookup)) {
  51625. lookup = lookup.getBytes();
  51626. }
  51627. return [
  51628. 'IndexedCS',
  51629. baseIndexedCS,
  51630. hiVal,
  51631. lookup
  51632. ];
  51633. case 'Separation':
  51634. case 'DeviceN':
  51635. var name = xref.fetchIfRef(cs[1]);
  51636. numComps = 1;
  51637. if (isName(name)) {
  51638. numComps = 1;
  51639. } else if (isArray(name)) {
  51640. numComps = name.length;
  51641. }
  51642. alt = ColorSpace.parseToIR(cs[2], xref, res);
  51643. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  51644. return [
  51645. 'AlternateCS',
  51646. numComps,
  51647. alt,
  51648. tintFnIR
  51649. ];
  51650. case 'Lab':
  51651. params = xref.fetchIfRef(cs[1]);
  51652. whitePoint = params.getArray('WhitePoint');
  51653. blackPoint = params.getArray('BlackPoint');
  51654. var range = params.getArray('Range');
  51655. return [
  51656. 'LabCS',
  51657. whitePoint,
  51658. blackPoint,
  51659. range
  51660. ];
  51661. default:
  51662. error('unimplemented color space object "' + mode + '"');
  51663. }
  51664. } else {
  51665. error('unrecognized color space object: "' + cs + '"');
  51666. }
  51667. return null;
  51668. };
  51669. /**
  51670. * Checks if a decode map matches the default decode map for a color space.
  51671. * This handles the general decode maps where there are two values per
  51672. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  51673. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  51674. * slightly different.
  51675. * @param {Array} decode Decode map (usually from an image).
  51676. * @param {Number} n Number of components the color space has.
  51677. */
  51678. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  51679. if (!isArray(decode)) {
  51680. return true;
  51681. }
  51682. if (n * 2 !== decode.length) {
  51683. warn('The decode map is not the correct length');
  51684. return true;
  51685. }
  51686. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  51687. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  51688. return false;
  51689. }
  51690. }
  51691. return true;
  51692. };
  51693. ColorSpace.singletons = {
  51694. get gray() {
  51695. return shadow(this, 'gray', new DeviceGrayCS());
  51696. },
  51697. get rgb() {
  51698. return shadow(this, 'rgb', new DeviceRgbCS());
  51699. },
  51700. get cmyk() {
  51701. return shadow(this, 'cmyk', new DeviceCmykCS());
  51702. }
  51703. };
  51704. return ColorSpace;
  51705. }();
  51706. /**
  51707. * Alternate color space handles both Separation and DeviceN color spaces. A
  51708. * Separation color space is actually just a DeviceN with one color component.
  51709. * Both color spaces use a tinting function to convert colors to a base color
  51710. * space.
  51711. */
  51712. var AlternateCS = function AlternateCSClosure() {
  51713. function AlternateCS(numComps, base, tintFn) {
  51714. this.name = 'Alternate';
  51715. this.numComps = numComps;
  51716. this.defaultColor = new Float32Array(numComps);
  51717. for (var i = 0; i < numComps; ++i) {
  51718. this.defaultColor[i] = 1;
  51719. }
  51720. this.base = base;
  51721. this.tintFn = tintFn;
  51722. this.tmpBuf = new Float32Array(base.numComps);
  51723. }
  51724. AlternateCS.prototype = {
  51725. getRgb: ColorSpace.prototype.getRgb,
  51726. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset, dest, destOffset) {
  51727. var tmpBuf = this.tmpBuf;
  51728. this.tintFn(src, srcOffset, tmpBuf, 0);
  51729. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  51730. },
  51731. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  51732. var tintFn = this.tintFn;
  51733. var base = this.base;
  51734. var scale = 1 / ((1 << bits) - 1);
  51735. var baseNumComps = base.numComps;
  51736. var usesZeroToOneRange = base.usesZeroToOneRange;
  51737. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) && alpha01 === 0;
  51738. var pos = isPassthrough ? destOffset : 0;
  51739. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  51740. var numComps = this.numComps;
  51741. var scaled = new Float32Array(numComps);
  51742. var tinted = new Float32Array(baseNumComps);
  51743. var i, j;
  51744. if (usesZeroToOneRange) {
  51745. for (i = 0; i < count; i++) {
  51746. for (j = 0; j < numComps; j++) {
  51747. scaled[j] = src[srcOffset++] * scale;
  51748. }
  51749. tintFn(scaled, 0, tinted, 0);
  51750. for (j = 0; j < baseNumComps; j++) {
  51751. baseBuf[pos++] = tinted[j] * 255;
  51752. }
  51753. }
  51754. } else {
  51755. for (i = 0; i < count; i++) {
  51756. for (j = 0; j < numComps; j++) {
  51757. scaled[j] = src[srcOffset++] * scale;
  51758. }
  51759. tintFn(scaled, 0, tinted, 0);
  51760. base.getRgbItem(tinted, 0, baseBuf, pos);
  51761. pos += baseNumComps;
  51762. }
  51763. }
  51764. if (!isPassthrough) {
  51765. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  51766. }
  51767. },
  51768. getOutputLength: function AlternateCS_getOutputLength(inputLength, alpha01) {
  51769. return this.base.getOutputLength(inputLength * this.base.numComps / this.numComps, alpha01);
  51770. },
  51771. isPassthrough: ColorSpace.prototype.isPassthrough,
  51772. fillRgb: ColorSpace.prototype.fillRgb,
  51773. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  51774. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  51775. },
  51776. usesZeroToOneRange: true
  51777. };
  51778. return AlternateCS;
  51779. }();
  51780. var PatternCS = function PatternCSClosure() {
  51781. function PatternCS(baseCS) {
  51782. this.name = 'Pattern';
  51783. this.base = baseCS;
  51784. }
  51785. PatternCS.prototype = {};
  51786. return PatternCS;
  51787. }();
  51788. var IndexedCS = function IndexedCSClosure() {
  51789. function IndexedCS(base, highVal, lookup) {
  51790. this.name = 'Indexed';
  51791. this.numComps = 1;
  51792. this.defaultColor = new Uint8Array([0]);
  51793. this.base = base;
  51794. this.highVal = highVal;
  51795. var baseNumComps = base.numComps;
  51796. var length = baseNumComps * highVal;
  51797. var lookupArray;
  51798. if (isStream(lookup)) {
  51799. lookupArray = new Uint8Array(length);
  51800. var bytes = lookup.getBytes(length);
  51801. lookupArray.set(bytes);
  51802. } else if (isString(lookup)) {
  51803. lookupArray = new Uint8Array(length);
  51804. for (var i = 0; i < length; ++i) {
  51805. lookupArray[i] = lookup.charCodeAt(i);
  51806. }
  51807. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  51808. lookupArray = lookup;
  51809. } else {
  51810. error('Unrecognized lookup table: ' + lookup);
  51811. }
  51812. this.lookup = lookupArray;
  51813. }
  51814. IndexedCS.prototype = {
  51815. getRgb: ColorSpace.prototype.getRgb,
  51816. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset, dest, destOffset) {
  51817. var numComps = this.base.numComps;
  51818. var start = src[srcOffset] * numComps;
  51819. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  51820. },
  51821. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  51822. var base = this.base;
  51823. var numComps = base.numComps;
  51824. var outputDelta = base.getOutputLength(numComps, alpha01);
  51825. var lookup = this.lookup;
  51826. for (var i = 0; i < count; ++i) {
  51827. var lookupPos = src[srcOffset++] * numComps;
  51828. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  51829. destOffset += outputDelta;
  51830. }
  51831. },
  51832. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  51833. return this.base.getOutputLength(inputLength * this.base.numComps, alpha01);
  51834. },
  51835. isPassthrough: ColorSpace.prototype.isPassthrough,
  51836. fillRgb: ColorSpace.prototype.fillRgb,
  51837. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  51838. // indexed color maps shouldn't be changed
  51839. return true;
  51840. },
  51841. usesZeroToOneRange: true
  51842. };
  51843. return IndexedCS;
  51844. }();
  51845. var DeviceGrayCS = function DeviceGrayCSClosure() {
  51846. function DeviceGrayCS() {
  51847. this.name = 'DeviceGray';
  51848. this.numComps = 1;
  51849. this.defaultColor = new Float32Array([0]);
  51850. }
  51851. DeviceGrayCS.prototype = {
  51852. getRgb: ColorSpace.prototype.getRgb,
  51853. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset, dest, destOffset) {
  51854. var c = src[srcOffset] * 255 | 0;
  51855. c = c < 0 ? 0 : c > 255 ? 255 : c;
  51856. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  51857. },
  51858. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  51859. var scale = 255 / ((1 << bits) - 1);
  51860. var j = srcOffset, q = destOffset;
  51861. for (var i = 0; i < count; ++i) {
  51862. var c = scale * src[j++] | 0;
  51863. dest[q++] = c;
  51864. dest[q++] = c;
  51865. dest[q++] = c;
  51866. q += alpha01;
  51867. }
  51868. },
  51869. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength, alpha01) {
  51870. return inputLength * (3 + alpha01);
  51871. },
  51872. isPassthrough: ColorSpace.prototype.isPassthrough,
  51873. fillRgb: ColorSpace.prototype.fillRgb,
  51874. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  51875. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  51876. },
  51877. usesZeroToOneRange: true
  51878. };
  51879. return DeviceGrayCS;
  51880. }();
  51881. var DeviceRgbCS = function DeviceRgbCSClosure() {
  51882. function DeviceRgbCS() {
  51883. this.name = 'DeviceRGB';
  51884. this.numComps = 3;
  51885. this.defaultColor = new Float32Array([
  51886. 0,
  51887. 0,
  51888. 0
  51889. ]);
  51890. }
  51891. DeviceRgbCS.prototype = {
  51892. getRgb: ColorSpace.prototype.getRgb,
  51893. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset, dest, destOffset) {
  51894. var r = src[srcOffset] * 255 | 0;
  51895. var g = src[srcOffset + 1] * 255 | 0;
  51896. var b = src[srcOffset + 2] * 255 | 0;
  51897. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  51898. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  51899. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  51900. },
  51901. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  51902. if (bits === 8 && alpha01 === 0) {
  51903. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  51904. return;
  51905. }
  51906. var scale = 255 / ((1 << bits) - 1);
  51907. var j = srcOffset, q = destOffset;
  51908. for (var i = 0; i < count; ++i) {
  51909. dest[q++] = scale * src[j++] | 0;
  51910. dest[q++] = scale * src[j++] | 0;
  51911. dest[q++] = scale * src[j++] | 0;
  51912. q += alpha01;
  51913. }
  51914. },
  51915. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength, alpha01) {
  51916. return inputLength * (3 + alpha01) / 3 | 0;
  51917. },
  51918. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  51919. return bits === 8;
  51920. },
  51921. fillRgb: ColorSpace.prototype.fillRgb,
  51922. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  51923. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  51924. },
  51925. usesZeroToOneRange: true
  51926. };
  51927. return DeviceRgbCS;
  51928. }();
  51929. var DeviceCmykCS = function DeviceCmykCSClosure() {
  51930. // The coefficients below was found using numerical analysis: the method of
  51931. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  51932. // where color_value is the tabular value from the table of sampled RGB colors
  51933. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  51934. // CMYK color conversion using the estimation below:
  51935. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  51936. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  51937. var c = src[srcOffset + 0] * srcScale;
  51938. var m = src[srcOffset + 1] * srcScale;
  51939. var y = src[srcOffset + 2] * srcScale;
  51940. var k = src[srcOffset + 3] * srcScale;
  51941. var r = c * (-4.387332384609988 * c + 54.48615194189176 * m + 18.82290502165302 * y + 212.25662451639585 * k + -285.2331026137004) + m * (1.7149763477362134 * m - 5.6096736904047315 * y + -17.873870861415444 * k - 5.497006427196366) + y * (-2.5217340131683033 * y - 21.248923337353073 * k + 17.5119270841813) + k * (-21.86122147463605 * k - 189.48180835922747) + 255 | 0;
  51942. var g = c * (8.841041422036149 * c + 60.118027045597366 * m + 6.871425592049007 * y + 31.159100130055922 * k + -79.2970844816548) + m * (-15.310361306967817 * m + 17.575251261109482 * y + 131.35250912493976 * k - 190.9453302588951) + y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) + k * (-20.737325471181034 * k - 187.80453709719578) + 255 | 0;
  51943. var b = c * (0.8842522430003296 * c + 8.078677503112928 * m + 30.89978309703729 * y - 0.23883238689178934 * k + -14.183576799673286) + m * (10.49593273432072 * m + 63.02378494754052 * y + 50.606957656360734 * k - 112.23884253719248) + y * (0.03296041114873217 * y + 115.60384449646641 * k + -193.58209356861505) + k * (-22.33816807309886 * k - 180.12613974708367) + 255 | 0;
  51944. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  51945. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  51946. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  51947. }
  51948. function DeviceCmykCS() {
  51949. this.name = 'DeviceCMYK';
  51950. this.numComps = 4;
  51951. this.defaultColor = new Float32Array([
  51952. 0,
  51953. 0,
  51954. 0,
  51955. 1
  51956. ]);
  51957. }
  51958. DeviceCmykCS.prototype = {
  51959. getRgb: ColorSpace.prototype.getRgb,
  51960. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset, dest, destOffset) {
  51961. convertToRgb(src, srcOffset, 1, dest, destOffset);
  51962. },
  51963. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  51964. var scale = 1 / ((1 << bits) - 1);
  51965. for (var i = 0; i < count; i++) {
  51966. convertToRgb(src, srcOffset, scale, dest, destOffset);
  51967. srcOffset += 4;
  51968. destOffset += 3 + alpha01;
  51969. }
  51970. },
  51971. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength, alpha01) {
  51972. return inputLength / 4 * (3 + alpha01) | 0;
  51973. },
  51974. isPassthrough: ColorSpace.prototype.isPassthrough,
  51975. fillRgb: ColorSpace.prototype.fillRgb,
  51976. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  51977. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  51978. },
  51979. usesZeroToOneRange: true
  51980. };
  51981. return DeviceCmykCS;
  51982. }();
  51983. //
  51984. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  51985. //
  51986. var CalGrayCS = function CalGrayCSClosure() {
  51987. function CalGrayCS(whitePoint, blackPoint, gamma) {
  51988. this.name = 'CalGray';
  51989. this.numComps = 1;
  51990. this.defaultColor = new Float32Array([0]);
  51991. if (!whitePoint) {
  51992. error('WhitePoint missing - required for color space CalGray');
  51993. }
  51994. blackPoint = blackPoint || [
  51995. 0,
  51996. 0,
  51997. 0
  51998. ];
  51999. gamma = gamma || 1;
  52000. // Translate arguments to spec variables.
  52001. this.XW = whitePoint[0];
  52002. this.YW = whitePoint[1];
  52003. this.ZW = whitePoint[2];
  52004. this.XB = blackPoint[0];
  52005. this.YB = blackPoint[1];
  52006. this.ZB = blackPoint[2];
  52007. this.G = gamma;
  52008. // Validate variables as per spec.
  52009. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  52010. error('Invalid WhitePoint components for ' + this.name + ', no fallback available');
  52011. }
  52012. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  52013. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  52014. this.XB = this.YB = this.ZB = 0;
  52015. }
  52016. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  52017. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB + ', ZB: ' + this.ZB + ', only default values are supported.');
  52018. }
  52019. if (this.G < 1) {
  52020. info('Invalid Gamma: ' + this.G + ' for ' + this.name + ', falling back to default');
  52021. this.G = 1;
  52022. }
  52023. }
  52024. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  52025. // A represents a gray component of a calibrated gray space.
  52026. // A <---> AG in the spec
  52027. var A = src[srcOffset] * scale;
  52028. var AG = Math.pow(A, cs.G);
  52029. // Computes L as per spec. ( = cs.YW * AG )
  52030. // Except if other than default BlackPoint values are used.
  52031. var L = cs.YW * AG;
  52032. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  52033. // Convert values to rgb range [0, 255].
  52034. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  52035. dest[destOffset] = val;
  52036. dest[destOffset + 1] = val;
  52037. dest[destOffset + 2] = val;
  52038. }
  52039. CalGrayCS.prototype = {
  52040. getRgb: ColorSpace.prototype.getRgb,
  52041. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset, dest, destOffset) {
  52042. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  52043. },
  52044. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  52045. var scale = 1 / ((1 << bits) - 1);
  52046. for (var i = 0; i < count; ++i) {
  52047. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  52048. srcOffset += 1;
  52049. destOffset += 3 + alpha01;
  52050. }
  52051. },
  52052. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  52053. return inputLength * (3 + alpha01);
  52054. },
  52055. isPassthrough: ColorSpace.prototype.isPassthrough,
  52056. fillRgb: ColorSpace.prototype.fillRgb,
  52057. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  52058. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  52059. },
  52060. usesZeroToOneRange: true
  52061. };
  52062. return CalGrayCS;
  52063. }();
  52064. //
  52065. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  52066. //
  52067. var CalRGBCS = function CalRGBCSClosure() {
  52068. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  52069. // matrices.
  52070. var BRADFORD_SCALE_MATRIX = new Float32Array([
  52071. 0.8951,
  52072. 0.2664,
  52073. -0.1614,
  52074. -0.7502,
  52075. 1.7135,
  52076. 0.0367,
  52077. 0.0389,
  52078. -0.0685,
  52079. 1.0296
  52080. ]);
  52081. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  52082. 0.9869929,
  52083. -0.1470543,
  52084. 0.1599627,
  52085. 0.4323053,
  52086. 0.5183603,
  52087. 0.0492912,
  52088. -0.0085287,
  52089. 0.0400428,
  52090. 0.9684867
  52091. ]);
  52092. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  52093. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  52094. 3.2404542,
  52095. -1.5371385,
  52096. -0.4985314,
  52097. -0.9692660,
  52098. 1.8760108,
  52099. 0.0415560,
  52100. 0.0556434,
  52101. -0.2040259,
  52102. 1.0572252
  52103. ]);
  52104. var FLAT_WHITEPOINT_MATRIX = new Float32Array([
  52105. 1,
  52106. 1,
  52107. 1
  52108. ]);
  52109. var tempNormalizeMatrix = new Float32Array(3);
  52110. var tempConvertMatrix1 = new Float32Array(3);
  52111. var tempConvertMatrix2 = new Float32Array(3);
  52112. var DECODE_L_CONSTANT = Math.pow((8 + 16) / 116, 3) / 8.0;
  52113. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  52114. this.name = 'CalRGB';
  52115. this.numComps = 3;
  52116. this.defaultColor = new Float32Array(3);
  52117. if (!whitePoint) {
  52118. error('WhitePoint missing - required for color space CalRGB');
  52119. }
  52120. blackPoint = blackPoint || new Float32Array(3);
  52121. gamma = gamma || new Float32Array([
  52122. 1,
  52123. 1,
  52124. 1
  52125. ]);
  52126. matrix = matrix || new Float32Array([
  52127. 1,
  52128. 0,
  52129. 0,
  52130. 0,
  52131. 1,
  52132. 0,
  52133. 0,
  52134. 0,
  52135. 1
  52136. ]);
  52137. // Translate arguments to spec variables.
  52138. var XW = whitePoint[0];
  52139. var YW = whitePoint[1];
  52140. var ZW = whitePoint[2];
  52141. this.whitePoint = whitePoint;
  52142. var XB = blackPoint[0];
  52143. var YB = blackPoint[1];
  52144. var ZB = blackPoint[2];
  52145. this.blackPoint = blackPoint;
  52146. this.GR = gamma[0];
  52147. this.GG = gamma[1];
  52148. this.GB = gamma[2];
  52149. this.MXA = matrix[0];
  52150. this.MYA = matrix[1];
  52151. this.MZA = matrix[2];
  52152. this.MXB = matrix[3];
  52153. this.MYB = matrix[4];
  52154. this.MZB = matrix[5];
  52155. this.MXC = matrix[6];
  52156. this.MYC = matrix[7];
  52157. this.MZC = matrix[8];
  52158. // Validate variables as per spec.
  52159. if (XW < 0 || ZW < 0 || YW !== 1) {
  52160. error('Invalid WhitePoint components for ' + this.name + ', no fallback available');
  52161. }
  52162. if (XB < 0 || YB < 0 || ZB < 0) {
  52163. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB + ', ' + ZB + '], falling back to default');
  52164. this.blackPoint = new Float32Array(3);
  52165. }
  52166. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  52167. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB + '] for ' + this.name + ', falling back to default');
  52168. this.GR = this.GG = this.GB = 1;
  52169. }
  52170. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 || this.MXB < 0 || this.MYB < 0 || this.MZB < 0 || this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  52171. info('Invalid Matrix for ' + this.name + ' [' + this.MXA + ', ' + this.MYA + ', ' + this.MZA + this.MXB + ', ' + this.MYB + ', ' + this.MZB + this.MXC + ', ' + this.MYC + ', ' + this.MZC + '], falling back to default');
  52172. this.MXA = this.MYB = this.MZC = 1;
  52173. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  52174. }
  52175. }
  52176. function matrixProduct(a, b, result) {
  52177. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  52178. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  52179. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  52180. }
  52181. function convertToFlat(sourceWhitePoint, LMS, result) {
  52182. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  52183. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  52184. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  52185. }
  52186. function convertToD65(sourceWhitePoint, LMS, result) {
  52187. var D65X = 0.95047;
  52188. var D65Y = 1;
  52189. var D65Z = 1.08883;
  52190. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  52191. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  52192. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  52193. }
  52194. function sRGBTransferFunction(color) {
  52195. // See http://en.wikipedia.org/wiki/SRGB.
  52196. if (color <= 0.0031308) {
  52197. return adjustToRange(0, 1, 12.92 * color);
  52198. }
  52199. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  52200. }
  52201. function adjustToRange(min, max, value) {
  52202. return Math.max(min, Math.min(max, value));
  52203. }
  52204. function decodeL(L) {
  52205. if (L < 0) {
  52206. return -decodeL(-L);
  52207. }
  52208. if (L > 8.0) {
  52209. return Math.pow((L + 16) / 116, 3);
  52210. }
  52211. return L * DECODE_L_CONSTANT;
  52212. }
  52213. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  52214. // In case the blackPoint is already the default blackPoint then there is
  52215. // no need to do compensation.
  52216. if (sourceBlackPoint[0] === 0 && sourceBlackPoint[1] === 0 && sourceBlackPoint[2] === 0) {
  52217. result[0] = XYZ_Flat[0];
  52218. result[1] = XYZ_Flat[1];
  52219. result[2] = XYZ_Flat[2];
  52220. return;
  52221. }
  52222. // For the blackPoint calculation details, please see
  52223. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  52224. // AdobeBPC.pdf.
  52225. // The destination blackPoint is the default blackPoint [0, 0, 0].
  52226. var zeroDecodeL = decodeL(0);
  52227. var X_DST = zeroDecodeL;
  52228. var X_SRC = decodeL(sourceBlackPoint[0]);
  52229. var Y_DST = zeroDecodeL;
  52230. var Y_SRC = decodeL(sourceBlackPoint[1]);
  52231. var Z_DST = zeroDecodeL;
  52232. var Z_SRC = decodeL(sourceBlackPoint[2]);
  52233. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  52234. var X_Offset = 1 - X_Scale;
  52235. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  52236. var Y_Offset = 1 - Y_Scale;
  52237. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  52238. var Z_Offset = 1 - Z_Scale;
  52239. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  52240. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  52241. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  52242. }
  52243. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  52244. // In case the whitePoint is already flat then there is no need to do
  52245. // normalization.
  52246. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  52247. result[0] = XYZ_In[0];
  52248. result[1] = XYZ_In[1];
  52249. result[2] = XYZ_In[2];
  52250. return;
  52251. }
  52252. var LMS = result;
  52253. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  52254. var LMS_Flat = tempNormalizeMatrix;
  52255. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  52256. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  52257. }
  52258. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  52259. var LMS = result;
  52260. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  52261. var LMS_D65 = tempNormalizeMatrix;
  52262. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  52263. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  52264. }
  52265. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  52266. // A, B and C represent a red, green and blue components of a calibrated
  52267. // rgb space.
  52268. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  52269. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  52270. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  52271. // A <---> AGR in the spec
  52272. // B <---> BGG in the spec
  52273. // C <---> CGB in the spec
  52274. var AGR = Math.pow(A, cs.GR);
  52275. var BGG = Math.pow(B, cs.GG);
  52276. var CGB = Math.pow(C, cs.GB);
  52277. // Computes intermediate variables L, M, N as per spec.
  52278. // To decode X, Y, Z values map L, M, N directly to them.
  52279. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  52280. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  52281. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  52282. // The following calculations are based on this document:
  52283. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  52284. // AdobeBPC.pdf.
  52285. var XYZ = tempConvertMatrix1;
  52286. XYZ[0] = X;
  52287. XYZ[1] = Y;
  52288. XYZ[2] = Z;
  52289. var XYZ_Flat = tempConvertMatrix2;
  52290. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  52291. var XYZ_Black = tempConvertMatrix1;
  52292. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  52293. var XYZ_D65 = tempConvertMatrix2;
  52294. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  52295. var SRGB = tempConvertMatrix1;
  52296. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  52297. var sR = sRGBTransferFunction(SRGB[0]);
  52298. var sG = sRGBTransferFunction(SRGB[1]);
  52299. var sB = sRGBTransferFunction(SRGB[2]);
  52300. // Convert the values to rgb range [0, 255].
  52301. dest[destOffset] = Math.round(sR * 255);
  52302. dest[destOffset + 1] = Math.round(sG * 255);
  52303. dest[destOffset + 2] = Math.round(sB * 255);
  52304. }
  52305. CalRGBCS.prototype = {
  52306. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  52307. var rgb = new Uint8Array(3);
  52308. this.getRgbItem(src, srcOffset, rgb, 0);
  52309. return rgb;
  52310. },
  52311. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset, dest, destOffset) {
  52312. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  52313. },
  52314. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  52315. var scale = 1 / ((1 << bits) - 1);
  52316. for (var i = 0; i < count; ++i) {
  52317. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  52318. srcOffset += 3;
  52319. destOffset += 3 + alpha01;
  52320. }
  52321. },
  52322. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  52323. return inputLength * (3 + alpha01) / 3 | 0;
  52324. },
  52325. isPassthrough: ColorSpace.prototype.isPassthrough,
  52326. fillRgb: ColorSpace.prototype.fillRgb,
  52327. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  52328. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  52329. },
  52330. usesZeroToOneRange: true
  52331. };
  52332. return CalRGBCS;
  52333. }();
  52334. //
  52335. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  52336. //
  52337. var LabCS = function LabCSClosure() {
  52338. function LabCS(whitePoint, blackPoint, range) {
  52339. this.name = 'Lab';
  52340. this.numComps = 3;
  52341. this.defaultColor = new Float32Array([
  52342. 0,
  52343. 0,
  52344. 0
  52345. ]);
  52346. if (!whitePoint) {
  52347. error('WhitePoint missing - required for color space Lab');
  52348. }
  52349. blackPoint = blackPoint || [
  52350. 0,
  52351. 0,
  52352. 0
  52353. ];
  52354. range = range || [
  52355. -100,
  52356. 100,
  52357. -100,
  52358. 100
  52359. ];
  52360. // Translate args to spec variables
  52361. this.XW = whitePoint[0];
  52362. this.YW = whitePoint[1];
  52363. this.ZW = whitePoint[2];
  52364. this.amin = range[0];
  52365. this.amax = range[1];
  52366. this.bmin = range[2];
  52367. this.bmax = range[3];
  52368. // These are here just for completeness - the spec doesn't offer any
  52369. // formulas that use BlackPoint in Lab
  52370. this.XB = blackPoint[0];
  52371. this.YB = blackPoint[1];
  52372. this.ZB = blackPoint[2];
  52373. // Validate vars as per spec
  52374. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  52375. error('Invalid WhitePoint components, no fallback available');
  52376. }
  52377. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  52378. info('Invalid BlackPoint, falling back to default');
  52379. this.XB = this.YB = this.ZB = 0;
  52380. }
  52381. if (this.amin > this.amax || this.bmin > this.bmax) {
  52382. info('Invalid Range, falling back to defaults');
  52383. this.amin = -100;
  52384. this.amax = 100;
  52385. this.bmin = -100;
  52386. this.bmax = 100;
  52387. }
  52388. }
  52389. // Function g(x) from spec
  52390. function fn_g(x) {
  52391. if (x >= 6 / 29) {
  52392. return x * x * x;
  52393. } else {
  52394. return 108 / 841 * (x - 4 / 29);
  52395. }
  52396. }
  52397. function decode(value, high1, low2, high2) {
  52398. return low2 + value * (high2 - low2) / high1;
  52399. }
  52400. // If decoding is needed maxVal should be 2^bits per component - 1.
  52401. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  52402. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  52403. // not the usual [0, 1]. If a command like setFillColor is used the src
  52404. // values will already be within the correct range. However, if we are
  52405. // converting an image we have to map the values to the correct range given
  52406. // above.
  52407. // Ls,as,bs <---> L*,a*,b* in the spec
  52408. var Ls = src[srcOffset];
  52409. var as = src[srcOffset + 1];
  52410. var bs = src[srcOffset + 2];
  52411. if (maxVal !== false) {
  52412. Ls = decode(Ls, maxVal, 0, 100);
  52413. as = decode(as, maxVal, cs.amin, cs.amax);
  52414. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  52415. }
  52416. // Adjust limits of 'as' and 'bs'
  52417. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  52418. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  52419. // Computes intermediate variables X,Y,Z as per spec
  52420. var M = (Ls + 16) / 116;
  52421. var L = M + as / 500;
  52422. var N = M - bs / 200;
  52423. var X = cs.XW * fn_g(L);
  52424. var Y = cs.YW * fn_g(M);
  52425. var Z = cs.ZW * fn_g(N);
  52426. var r, g, b;
  52427. // Using different conversions for D50 and D65 white points,
  52428. // per http://www.color.org/srgb.pdf
  52429. if (cs.ZW < 1) {
  52430. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  52431. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  52432. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  52433. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  52434. } else {
  52435. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  52436. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  52437. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  52438. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  52439. }
  52440. // clamp color values to [0,1] range then convert to [0,255] range.
  52441. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  52442. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  52443. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  52444. }
  52445. LabCS.prototype = {
  52446. getRgb: ColorSpace.prototype.getRgb,
  52447. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  52448. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  52449. },
  52450. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  52451. var maxVal = (1 << bits) - 1;
  52452. for (var i = 0; i < count; i++) {
  52453. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  52454. srcOffset += 3;
  52455. destOffset += 3 + alpha01;
  52456. }
  52457. },
  52458. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  52459. return inputLength * (3 + alpha01) / 3 | 0;
  52460. },
  52461. isPassthrough: ColorSpace.prototype.isPassthrough,
  52462. fillRgb: ColorSpace.prototype.fillRgb,
  52463. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  52464. // XXX: Decoding is handled with the lab conversion because of the strange
  52465. // ranges that are used.
  52466. return true;
  52467. },
  52468. usesZeroToOneRange: false
  52469. };
  52470. return LabCS;
  52471. }();
  52472. exports.ColorSpace = ColorSpace;
  52473. }));
  52474. (function (root, factory) {
  52475. factory(root.pdfjsDisplayGlobal = {}, root.pdfjsSharedUtil, root.pdfjsDisplayDOMUtils, root.pdfjsDisplayAPI, root.pdfjsDisplayAnnotationLayer, root.pdfjsDisplayTextLayer, root.pdfjsDisplayMetadata, root.pdfjsDisplaySVG);
  52476. }(this, function (exports, sharedUtil, displayDOMUtils, displayAPI, displayAnnotationLayer, displayTextLayer, displayMetadata, displaySVG) {
  52477. var globalScope = sharedUtil.globalScope;
  52478. var deprecated = sharedUtil.deprecated;
  52479. var warn = sharedUtil.warn;
  52480. var LinkTarget = displayDOMUtils.LinkTarget;
  52481. var isWorker = typeof window === 'undefined';
  52482. // The global PDFJS object is now deprecated and will not be supported in
  52483. // the future. The members below are maintained for backward compatibility
  52484. // and shall not be extended or modified. If the global.js is included as
  52485. // a module, we will create a global PDFJS object instance or use existing.
  52486. if (!globalScope.PDFJS) {
  52487. globalScope.PDFJS = {};
  52488. }
  52489. var PDFJS = globalScope.PDFJS;
  52490. if (typeof pdfjsVersion !== 'undefined') {
  52491. PDFJS.version = pdfjsVersion;
  52492. }
  52493. if (typeof pdfjsBuild !== 'undefined') {
  52494. PDFJS.build = pdfjsBuild;
  52495. }
  52496. PDFJS.pdfBug = false;
  52497. if (PDFJS.verbosity !== undefined) {
  52498. sharedUtil.setVerbosityLevel(PDFJS.verbosity);
  52499. }
  52500. delete PDFJS.verbosity;
  52501. Object.defineProperty(PDFJS, 'verbosity', {
  52502. get: function () {
  52503. return sharedUtil.getVerbosityLevel();
  52504. },
  52505. set: function (level) {
  52506. sharedUtil.setVerbosityLevel(level);
  52507. },
  52508. enumerable: true,
  52509. configurable: true
  52510. });
  52511. PDFJS.VERBOSITY_LEVELS = sharedUtil.VERBOSITY_LEVELS;
  52512. PDFJS.OPS = sharedUtil.OPS;
  52513. PDFJS.UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  52514. PDFJS.isValidUrl = sharedUtil.isValidUrl;
  52515. PDFJS.shadow = sharedUtil.shadow;
  52516. PDFJS.createBlob = sharedUtil.createBlob;
  52517. PDFJS.createObjectURL = function PDFJS_createObjectURL(data, contentType) {
  52518. return sharedUtil.createObjectURL(data, contentType, PDFJS.disableCreateObjectURL);
  52519. };
  52520. Object.defineProperty(PDFJS, 'isLittleEndian', {
  52521. configurable: true,
  52522. get: function PDFJS_isLittleEndian() {
  52523. var value = sharedUtil.isLittleEndian();
  52524. return sharedUtil.shadow(PDFJS, 'isLittleEndian', value);
  52525. }
  52526. });
  52527. PDFJS.removeNullCharacters = sharedUtil.removeNullCharacters;
  52528. PDFJS.PasswordResponses = sharedUtil.PasswordResponses;
  52529. PDFJS.PasswordException = sharedUtil.PasswordException;
  52530. PDFJS.UnknownErrorException = sharedUtil.UnknownErrorException;
  52531. PDFJS.InvalidPDFException = sharedUtil.InvalidPDFException;
  52532. PDFJS.MissingPDFException = sharedUtil.MissingPDFException;
  52533. PDFJS.UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  52534. PDFJS.Util = sharedUtil.Util;
  52535. PDFJS.PageViewport = sharedUtil.PageViewport;
  52536. PDFJS.createPromiseCapability = sharedUtil.createPromiseCapability;
  52537. /**
  52538. * The maximum allowed image size in total pixels e.g. width * height. Images
  52539. * above this value will not be drawn. Use -1 for no limit.
  52540. * @var {number}
  52541. */
  52542. PDFJS.maxImageSize = PDFJS.maxImageSize === undefined ? -1 : PDFJS.maxImageSize;
  52543. /**
  52544. * The url of where the predefined Adobe CMaps are located. Include trailing
  52545. * slash.
  52546. * @var {string}
  52547. */
  52548. PDFJS.cMapUrl = PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl;
  52549. /**
  52550. * Specifies if CMaps are binary packed.
  52551. * @var {boolean}
  52552. */
  52553. PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked;
  52554. /**
  52555. * By default fonts are converted to OpenType fonts and loaded via font face
  52556. * rules. If disabled, the font will be rendered using a built in font
  52557. * renderer that constructs the glyphs with primitive path commands.
  52558. * @var {boolean}
  52559. */
  52560. PDFJS.disableFontFace = PDFJS.disableFontFace === undefined ? false : PDFJS.disableFontFace;
  52561. /**
  52562. * Path for image resources, mainly for annotation icons. Include trailing
  52563. * slash.
  52564. * @var {string}
  52565. */
  52566. PDFJS.imageResourcesPath = PDFJS.imageResourcesPath === undefined ? '' : PDFJS.imageResourcesPath;
  52567. /**
  52568. * Disable the web worker and run all code on the main thread. This will
  52569. * happen automatically if the browser doesn't support workers or sending
  52570. * typed arrays to workers.
  52571. * @var {boolean}
  52572. */
  52573. PDFJS.disableWorker = PDFJS.disableWorker === undefined ? false : PDFJS.disableWorker;
  52574. /**
  52575. * Path and filename of the worker file. Required when the worker is enabled
  52576. * in development mode. If unspecified in the production build, the worker
  52577. * will be loaded based on the location of the pdf.js file. It is recommended
  52578. * that the workerSrc is set in a custom application to prevent issues caused
  52579. * by third-party frameworks and libraries.
  52580. * @var {string}
  52581. */
  52582. PDFJS.workerSrc = PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc;
  52583. /**
  52584. * Disable range request loading of PDF files. When enabled and if the server
  52585. * supports partial content requests then the PDF will be fetched in chunks.
  52586. * Enabled (false) by default.
  52587. * @var {boolean}
  52588. */
  52589. PDFJS.disableRange = PDFJS.disableRange === undefined ? false : PDFJS.disableRange;
  52590. /**
  52591. * Disable streaming of PDF file data. By default PDF.js attempts to load PDF
  52592. * in chunks. This default behavior can be disabled.
  52593. * @var {boolean}
  52594. */
  52595. PDFJS.disableStream = PDFJS.disableStream === undefined ? false : PDFJS.disableStream;
  52596. /**
  52597. * Disable pre-fetching of PDF file data. When range requests are enabled
  52598. * PDF.js will automatically keep fetching more data even if it isn't needed
  52599. * to display the current page. This default behavior can be disabled.
  52600. *
  52601. * NOTE: It is also necessary to disable streaming, see above,
  52602. * in order for disabling of pre-fetching to work correctly.
  52603. * @var {boolean}
  52604. */
  52605. PDFJS.disableAutoFetch = PDFJS.disableAutoFetch === undefined ? false : PDFJS.disableAutoFetch;
  52606. /**
  52607. * Enables special hooks for debugging PDF.js.
  52608. * @var {boolean}
  52609. */
  52610. PDFJS.pdfBug = PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug;
  52611. /**
  52612. * Enables transfer usage in postMessage for ArrayBuffers.
  52613. * @var {boolean}
  52614. */
  52615. PDFJS.postMessageTransfers = PDFJS.postMessageTransfers === undefined ? true : PDFJS.postMessageTransfers;
  52616. /**
  52617. * Disables URL.createObjectURL usage.
  52618. * @var {boolean}
  52619. */
  52620. PDFJS.disableCreateObjectURL = PDFJS.disableCreateObjectURL === undefined ? false : PDFJS.disableCreateObjectURL;
  52621. /**
  52622. * Disables WebGL usage.
  52623. * @var {boolean}
  52624. */
  52625. PDFJS.disableWebGL = PDFJS.disableWebGL === undefined ? true : PDFJS.disableWebGL;
  52626. /**
  52627. * Specifies the |target| attribute for external links.
  52628. * The constants from PDFJS.LinkTarget should be used:
  52629. * - NONE [default]
  52630. * - SELF
  52631. * - BLANK
  52632. * - PARENT
  52633. * - TOP
  52634. * @var {number}
  52635. */
  52636. PDFJS.externalLinkTarget = PDFJS.externalLinkTarget === undefined ? LinkTarget.NONE : PDFJS.externalLinkTarget;
  52637. /**
  52638. * Specifies the |rel| attribute for external links. Defaults to stripping
  52639. * the referrer.
  52640. * @var {string}
  52641. */
  52642. PDFJS.externalLinkRel = PDFJS.externalLinkRel === undefined ? 'noreferrer' : PDFJS.externalLinkRel;
  52643. /**
  52644. * Determines if we can eval strings as JS. Primarily used to improve
  52645. * performance for font rendering.
  52646. * @var {boolean}
  52647. */
  52648. PDFJS.isEvalSupported = PDFJS.isEvalSupported === undefined ? true : PDFJS.isEvalSupported;
  52649. var savedOpenExternalLinksInNewWindow = PDFJS.openExternalLinksInNewWindow;
  52650. delete PDFJS.openExternalLinksInNewWindow;
  52651. Object.defineProperty(PDFJS, 'openExternalLinksInNewWindow', {
  52652. get: function () {
  52653. return PDFJS.externalLinkTarget === LinkTarget.BLANK;
  52654. },
  52655. set: function (value) {
  52656. if (value) {
  52657. deprecated('PDFJS.openExternalLinksInNewWindow, please use ' + '"PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK" instead.');
  52658. }
  52659. if (PDFJS.externalLinkTarget !== LinkTarget.NONE) {
  52660. warn('PDFJS.externalLinkTarget is already initialized');
  52661. return;
  52662. }
  52663. PDFJS.externalLinkTarget = value ? LinkTarget.BLANK : LinkTarget.NONE;
  52664. },
  52665. enumerable: true,
  52666. configurable: true
  52667. });
  52668. if (savedOpenExternalLinksInNewWindow) {
  52669. /**
  52670. * (Deprecated) Opens external links in a new window if enabled.
  52671. * The default behavior opens external links in the PDF.js window.
  52672. *
  52673. * NOTE: This property has been deprecated, please use
  52674. * `PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK` instead.
  52675. * @var {boolean}
  52676. */
  52677. PDFJS.openExternalLinksInNewWindow = savedOpenExternalLinksInNewWindow;
  52678. }
  52679. PDFJS.getDocument = displayAPI.getDocument;
  52680. PDFJS.PDFDataRangeTransport = displayAPI.PDFDataRangeTransport;
  52681. PDFJS.PDFWorker = displayAPI.PDFWorker;
  52682. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  52683. configurable: true,
  52684. get: function PDFJS_hasCanvasTypedArrays() {
  52685. var value = displayDOMUtils.hasCanvasTypedArrays();
  52686. return sharedUtil.shadow(PDFJS, 'hasCanvasTypedArrays', value);
  52687. }
  52688. });
  52689. PDFJS.CustomStyle = displayDOMUtils.CustomStyle;
  52690. PDFJS.LinkTarget = LinkTarget;
  52691. PDFJS.addLinkAttributes = displayDOMUtils.addLinkAttributes;
  52692. PDFJS.getFilenameFromUrl = displayDOMUtils.getFilenameFromUrl;
  52693. PDFJS.isExternalLinkTargetSet = displayDOMUtils.isExternalLinkTargetSet;
  52694. PDFJS.AnnotationLayer = displayAnnotationLayer.AnnotationLayer;
  52695. PDFJS.renderTextLayer = displayTextLayer.renderTextLayer;
  52696. PDFJS.Metadata = displayMetadata.Metadata;
  52697. PDFJS.SVGGraphics = displaySVG.SVGGraphics;
  52698. PDFJS.UnsupportedManager = displayAPI._UnsupportedManager;
  52699. exports.globalScope = globalScope;
  52700. exports.isWorker = isWorker;
  52701. exports.PDFJS = globalScope.PDFJS;
  52702. }));
  52703. (function (root, factory) {
  52704. factory(root.pdfjsCoreImage = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreColorSpace, root.pdfjsCoreStream, root.pdfjsCoreJpx);
  52705. }(this, function (exports, sharedUtil, corePrimitives, coreColorSpace, coreStream, coreJpx) {
  52706. var ImageKind = sharedUtil.ImageKind;
  52707. var assert = sharedUtil.assert;
  52708. var error = sharedUtil.error;
  52709. var info = sharedUtil.info;
  52710. var isArray = sharedUtil.isArray;
  52711. var warn = sharedUtil.warn;
  52712. var Name = corePrimitives.Name;
  52713. var isStream = corePrimitives.isStream;
  52714. var ColorSpace = coreColorSpace.ColorSpace;
  52715. var DecodeStream = coreStream.DecodeStream;
  52716. var JpegStream = coreStream.JpegStream;
  52717. var JpxImage = coreJpx.JpxImage;
  52718. var PDFImage = function PDFImageClosure() {
  52719. /**
  52720. * Decodes the image using native decoder if possible. Resolves the promise
  52721. * when the image data is ready.
  52722. */
  52723. function handleImageData(image, nativeDecoder) {
  52724. if (nativeDecoder && nativeDecoder.canDecode(image)) {
  52725. return nativeDecoder.decode(image);
  52726. } else {
  52727. return Promise.resolve(image);
  52728. }
  52729. }
  52730. /**
  52731. * Decode and clamp a value. The formula is different from the spec because we
  52732. * don't decode to float range [0,1], we decode it in the [0,max] range.
  52733. */
  52734. function decodeAndClamp(value, addend, coefficient, max) {
  52735. value = addend + value * coefficient;
  52736. // Clamp the value to the range
  52737. return value < 0 ? 0 : value > max ? max : value;
  52738. }
  52739. /**
  52740. * Resizes an image mask with 1 component.
  52741. * @param {TypedArray} src - The source buffer.
  52742. * @param {Number} bpc - Number of bits per component.
  52743. * @param {Number} w1 - Original width.
  52744. * @param {Number} h1 - Original height.
  52745. * @param {Number} w2 - New width.
  52746. * @param {Number} h2 - New height.
  52747. * @returns {TypedArray} The resized image mask buffer.
  52748. */
  52749. function resizeImageMask(src, bpc, w1, h1, w2, h2) {
  52750. var length = w2 * h2;
  52751. var dest = bpc <= 8 ? new Uint8Array(length) : bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length);
  52752. var xRatio = w1 / w2;
  52753. var yRatio = h1 / h2;
  52754. var i, j, py, newIndex = 0, oldIndex;
  52755. var xScaled = new Uint16Array(w2);
  52756. var w1Scanline = w1;
  52757. for (i = 0; i < w2; i++) {
  52758. xScaled[i] = Math.floor(i * xRatio);
  52759. }
  52760. for (i = 0; i < h2; i++) {
  52761. py = Math.floor(i * yRatio) * w1Scanline;
  52762. for (j = 0; j < w2; j++) {
  52763. oldIndex = py + xScaled[j];
  52764. dest[newIndex++] = src[oldIndex];
  52765. }
  52766. }
  52767. return dest;
  52768. }
  52769. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  52770. this.image = image;
  52771. var dict = image.dict;
  52772. if (dict.has('Filter')) {
  52773. var filter = dict.get('Filter').name;
  52774. if (filter === 'JPXDecode') {
  52775. var jpxImage = new JpxImage();
  52776. jpxImage.parseImageProperties(image.stream);
  52777. image.stream.reset();
  52778. image.bitsPerComponent = jpxImage.bitsPerComponent;
  52779. image.numComps = jpxImage.componentsCount;
  52780. } else if (filter === 'JBIG2Decode') {
  52781. image.bitsPerComponent = 1;
  52782. image.numComps = 1;
  52783. }
  52784. }
  52785. // TODO cache rendered images?
  52786. this.width = dict.get('Width', 'W');
  52787. this.height = dict.get('Height', 'H');
  52788. if (this.width < 1 || this.height < 1) {
  52789. error('Invalid image width: ' + this.width + ' or height: ' + this.height);
  52790. }
  52791. this.interpolate = dict.get('Interpolate', 'I') || false;
  52792. this.imageMask = dict.get('ImageMask', 'IM') || false;
  52793. this.matte = dict.get('Matte') || false;
  52794. var bitsPerComponent = image.bitsPerComponent;
  52795. if (!bitsPerComponent) {
  52796. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  52797. if (!bitsPerComponent) {
  52798. if (this.imageMask) {
  52799. bitsPerComponent = 1;
  52800. } else {
  52801. error('Bits per component missing in image: ' + this.imageMask);
  52802. }
  52803. }
  52804. }
  52805. this.bpc = bitsPerComponent;
  52806. if (!this.imageMask) {
  52807. var colorSpace = dict.get('ColorSpace', 'CS');
  52808. if (!colorSpace) {
  52809. info('JPX images (which do not require color spaces)');
  52810. switch (image.numComps) {
  52811. case 1:
  52812. colorSpace = Name.get('DeviceGray');
  52813. break;
  52814. case 3:
  52815. colorSpace = Name.get('DeviceRGB');
  52816. break;
  52817. case 4:
  52818. colorSpace = Name.get('DeviceCMYK');
  52819. break;
  52820. default:
  52821. error('JPX images with ' + this.numComps + ' color components not supported.');
  52822. }
  52823. }
  52824. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  52825. this.numComps = this.colorSpace.numComps;
  52826. }
  52827. this.decode = dict.getArray('Decode', 'D');
  52828. this.needsDecode = false;
  52829. if (this.decode && (this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode) || isMask && !ColorSpace.isDefaultDecode(this.decode, 1))) {
  52830. this.needsDecode = true;
  52831. // Do some preprocessing to avoid more math.
  52832. var max = (1 << bitsPerComponent) - 1;
  52833. this.decodeCoefficients = [];
  52834. this.decodeAddends = [];
  52835. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  52836. var dmin = this.decode[i];
  52837. var dmax = this.decode[i + 1];
  52838. this.decodeCoefficients[j] = dmax - dmin;
  52839. this.decodeAddends[j] = max * dmin;
  52840. }
  52841. }
  52842. if (smask) {
  52843. this.smask = new PDFImage(xref, res, smask, false);
  52844. } else if (mask) {
  52845. if (isStream(mask)) {
  52846. var maskDict = mask.dict, imageMask = maskDict.get('ImageMask', 'IM');
  52847. if (!imageMask) {
  52848. warn('Ignoring /Mask in image without /ImageMask.');
  52849. } else {
  52850. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  52851. }
  52852. } else {
  52853. // Color key mask (just an array).
  52854. this.mask = mask;
  52855. }
  52856. }
  52857. }
  52858. /**
  52859. * Handles processing of image data and returns the Promise that is resolved
  52860. * with a PDFImage when the image is ready to be used.
  52861. */
  52862. PDFImage.buildImage = function PDFImage_buildImage(handler, xref, res, image, inline, nativeDecoder) {
  52863. var imagePromise = handleImageData(image, nativeDecoder);
  52864. var smaskPromise;
  52865. var maskPromise;
  52866. var smask = image.dict.get('SMask');
  52867. var mask = image.dict.get('Mask');
  52868. if (smask) {
  52869. smaskPromise = handleImageData(smask, nativeDecoder);
  52870. maskPromise = Promise.resolve(null);
  52871. } else {
  52872. smaskPromise = Promise.resolve(null);
  52873. if (mask) {
  52874. if (isStream(mask)) {
  52875. maskPromise = handleImageData(mask, nativeDecoder);
  52876. } else if (isArray(mask)) {
  52877. maskPromise = Promise.resolve(mask);
  52878. } else {
  52879. warn('Unsupported mask format.');
  52880. maskPromise = Promise.resolve(null);
  52881. }
  52882. } else {
  52883. maskPromise = Promise.resolve(null);
  52884. }
  52885. }
  52886. return Promise.all([
  52887. imagePromise,
  52888. smaskPromise,
  52889. maskPromise
  52890. ]).then(function (results) {
  52891. var imageData = results[0];
  52892. var smaskData = results[1];
  52893. var maskData = results[2];
  52894. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  52895. });
  52896. };
  52897. PDFImage.createMask = function PDFImage_createMask(imgArray, width, height, imageIsFromDecodeStream, inverseDecode) {
  52898. // |imgArray| might not contain full data for every pixel of the mask, so
  52899. // we need to distinguish between |computedLength| and |actualLength|.
  52900. // In particular, if inverseDecode is true, then the array we return must
  52901. // have a length of |computedLength|.
  52902. var computedLength = (width + 7 >> 3) * height;
  52903. var actualLength = imgArray.byteLength;
  52904. var haveFullData = computedLength === actualLength;
  52905. var data, i;
  52906. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  52907. // imgArray came from a DecodeStream and its data is in an appropriate
  52908. // form, so we can just transfer it.
  52909. data = imgArray;
  52910. } else if (!inverseDecode) {
  52911. data = new Uint8Array(actualLength);
  52912. data.set(imgArray);
  52913. } else {
  52914. data = new Uint8Array(computedLength);
  52915. data.set(imgArray);
  52916. for (i = actualLength; i < computedLength; i++) {
  52917. data[i] = 0xff;
  52918. }
  52919. }
  52920. // If necessary, invert the original mask data (but not any extra we might
  52921. // have added above). It's safe to modify the array -- whether it's the
  52922. // original or a copy, we're about to transfer it anyway, so nothing else
  52923. // in this thread can be relying on its contents.
  52924. if (inverseDecode) {
  52925. for (i = 0; i < actualLength; i++) {
  52926. data[i] = ~data[i];
  52927. }
  52928. }
  52929. return {
  52930. data: data,
  52931. width: width,
  52932. height: height
  52933. };
  52934. };
  52935. PDFImage.prototype = {
  52936. get drawWidth() {
  52937. return Math.max(this.width, this.smask && this.smask.width || 0, this.mask && this.mask.width || 0);
  52938. },
  52939. get drawHeight() {
  52940. return Math.max(this.height, this.smask && this.smask.height || 0, this.mask && this.mask.height || 0);
  52941. },
  52942. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  52943. var bpc = this.bpc;
  52944. var numComps = this.numComps;
  52945. var decodeAddends = this.decodeAddends;
  52946. var decodeCoefficients = this.decodeCoefficients;
  52947. var max = (1 << bpc) - 1;
  52948. var i, ii;
  52949. if (bpc === 1) {
  52950. // If the buffer needed decode that means it just needs to be inverted.
  52951. for (i = 0, ii = buffer.length; i < ii; i++) {
  52952. buffer[i] = +!buffer[i];
  52953. }
  52954. return;
  52955. }
  52956. var index = 0;
  52957. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  52958. for (var j = 0; j < numComps; j++) {
  52959. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j], decodeCoefficients[j], max);
  52960. index++;
  52961. }
  52962. }
  52963. },
  52964. getComponents: function PDFImage_getComponents(buffer) {
  52965. var bpc = this.bpc;
  52966. // This image doesn't require any extra work.
  52967. if (bpc === 8) {
  52968. return buffer;
  52969. }
  52970. var width = this.width;
  52971. var height = this.height;
  52972. var numComps = this.numComps;
  52973. var length = width * height * numComps;
  52974. var bufferPos = 0;
  52975. var output = bpc <= 8 ? new Uint8Array(length) : bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length);
  52976. var rowComps = width * numComps;
  52977. var max = (1 << bpc) - 1;
  52978. var i = 0, ii, buf;
  52979. if (bpc === 1) {
  52980. // Optimization for reading 1 bpc images.
  52981. var mask, loop1End, loop2End;
  52982. for (var j = 0; j < height; j++) {
  52983. loop1End = i + (rowComps & ~7);
  52984. loop2End = i + rowComps;
  52985. // unroll loop for all full bytes
  52986. while (i < loop1End) {
  52987. buf = buffer[bufferPos++];
  52988. output[i] = buf >> 7 & 1;
  52989. output[i + 1] = buf >> 6 & 1;
  52990. output[i + 2] = buf >> 5 & 1;
  52991. output[i + 3] = buf >> 4 & 1;
  52992. output[i + 4] = buf >> 3 & 1;
  52993. output[i + 5] = buf >> 2 & 1;
  52994. output[i + 6] = buf >> 1 & 1;
  52995. output[i + 7] = buf & 1;
  52996. i += 8;
  52997. }
  52998. // handle remaining bits
  52999. if (i < loop2End) {
  53000. buf = buffer[bufferPos++];
  53001. mask = 128;
  53002. while (i < loop2End) {
  53003. output[i++] = +!!(buf & mask);
  53004. mask >>= 1;
  53005. }
  53006. }
  53007. }
  53008. } else {
  53009. // The general case that handles all other bpc values.
  53010. var bits = 0;
  53011. buf = 0;
  53012. for (i = 0, ii = length; i < ii; ++i) {
  53013. if (i % rowComps === 0) {
  53014. buf = 0;
  53015. bits = 0;
  53016. }
  53017. while (bits < bpc) {
  53018. buf = buf << 8 | buffer[bufferPos++];
  53019. bits += 8;
  53020. }
  53021. var remainingBits = bits - bpc;
  53022. var value = buf >> remainingBits;
  53023. output[i] = value < 0 ? 0 : value > max ? max : value;
  53024. buf = buf & (1 << remainingBits) - 1;
  53025. bits = remainingBits;
  53026. }
  53027. }
  53028. return output;
  53029. },
  53030. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height, actualHeight, image) {
  53031. var smask = this.smask;
  53032. var mask = this.mask;
  53033. var alphaBuf, sw, sh, i, ii, j;
  53034. if (smask) {
  53035. sw = smask.width;
  53036. sh = smask.height;
  53037. alphaBuf = new Uint8Array(sw * sh);
  53038. smask.fillGrayBuffer(alphaBuf);
  53039. if (sw !== width || sh !== height) {
  53040. alphaBuf = resizeImageMask(alphaBuf, smask.bpc, sw, sh, width, height);
  53041. }
  53042. } else if (mask) {
  53043. if (mask instanceof PDFImage) {
  53044. sw = mask.width;
  53045. sh = mask.height;
  53046. alphaBuf = new Uint8Array(sw * sh);
  53047. mask.numComps = 1;
  53048. mask.fillGrayBuffer(alphaBuf);
  53049. // Need to invert values in rgbaBuf
  53050. for (i = 0, ii = sw * sh; i < ii; ++i) {
  53051. alphaBuf[i] = 255 - alphaBuf[i];
  53052. }
  53053. if (sw !== width || sh !== height) {
  53054. alphaBuf = resizeImageMask(alphaBuf, mask.bpc, sw, sh, width, height);
  53055. }
  53056. } else if (isArray(mask)) {
  53057. // Color key mask: if any of the components are outside the range
  53058. // then they should be painted.
  53059. alphaBuf = new Uint8Array(width * height);
  53060. var numComps = this.numComps;
  53061. for (i = 0, ii = width * height; i < ii; ++i) {
  53062. var opacity = 0;
  53063. var imageOffset = i * numComps;
  53064. for (j = 0; j < numComps; ++j) {
  53065. var color = image[imageOffset + j];
  53066. var maskOffset = j * 2;
  53067. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  53068. opacity = 255;
  53069. break;
  53070. }
  53071. }
  53072. alphaBuf[i] = opacity;
  53073. }
  53074. } else {
  53075. error('Unknown mask format.');
  53076. }
  53077. }
  53078. if (alphaBuf) {
  53079. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  53080. rgbaBuf[j] = alphaBuf[i];
  53081. }
  53082. } else {
  53083. // No mask.
  53084. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  53085. rgbaBuf[j] = 255;
  53086. }
  53087. }
  53088. },
  53089. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  53090. var matte = this.smask && this.smask.matte;
  53091. if (!matte) {
  53092. return;
  53093. }
  53094. var matteRgb = this.colorSpace.getRgb(matte, 0);
  53095. var matteR = matteRgb[0];
  53096. var matteG = matteRgb[1];
  53097. var matteB = matteRgb[2];
  53098. var length = width * height * 4;
  53099. var r, g, b;
  53100. for (var i = 0; i < length; i += 4) {
  53101. var alpha = buffer[i + 3];
  53102. if (alpha === 0) {
  53103. // according formula we have to get Infinity in all components
  53104. // making it white (typical paper color) should be okay
  53105. buffer[i] = 255;
  53106. buffer[i + 1] = 255;
  53107. buffer[i + 2] = 255;
  53108. continue;
  53109. }
  53110. var k = 255 / alpha;
  53111. r = (buffer[i] - matteR) * k + matteR;
  53112. g = (buffer[i + 1] - matteG) * k + matteG;
  53113. b = (buffer[i + 2] - matteB) * k + matteB;
  53114. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  53115. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  53116. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  53117. }
  53118. },
  53119. createImageData: function PDFImage_createImageData(forceRGBA) {
  53120. var drawWidth = this.drawWidth;
  53121. var drawHeight = this.drawHeight;
  53122. var imgData = {
  53123. // other fields are filled in below
  53124. width: drawWidth,
  53125. height: drawHeight
  53126. };
  53127. var numComps = this.numComps;
  53128. var originalWidth = this.width;
  53129. var originalHeight = this.height;
  53130. var bpc = this.bpc;
  53131. // Rows start at byte boundary.
  53132. var rowBytes = originalWidth * numComps * bpc + 7 >> 3;
  53133. var imgArray;
  53134. if (!forceRGBA) {
  53135. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  53136. // without any complications, we pass a same-sized copy to the main
  53137. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  53138. // of memory for many scanned documents. It's also much faster.
  53139. //
  53140. // Similarly, if it is a 24-bit-per pixel RGB image without any
  53141. // complications, we avoid expanding by 1.333x to RGBA form.
  53142. var kind;
  53143. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  53144. kind = ImageKind.GRAYSCALE_1BPP;
  53145. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 && !this.needsDecode) {
  53146. kind = ImageKind.RGB_24BPP;
  53147. }
  53148. if (kind && !this.smask && !this.mask && drawWidth === originalWidth && drawHeight === originalHeight) {
  53149. imgData.kind = kind;
  53150. imgArray = this.getImageBytes(originalHeight * rowBytes);
  53151. // If imgArray came from a DecodeStream, we're safe to transfer it
  53152. // (and thus detach its underlying buffer) because it will constitute
  53153. // the entire DecodeStream's data. But if it came from a Stream, we
  53154. // need to copy it because it'll only be a portion of the Stream's
  53155. // data, and the rest will be read later on.
  53156. if (this.image instanceof DecodeStream) {
  53157. imgData.data = imgArray;
  53158. } else {
  53159. var newArray = new Uint8Array(imgArray.length);
  53160. newArray.set(imgArray);
  53161. imgData.data = newArray;
  53162. }
  53163. if (this.needsDecode) {
  53164. // Invert the buffer (which must be grayscale if we reached here).
  53165. assert(kind === ImageKind.GRAYSCALE_1BPP);
  53166. var buffer = imgData.data;
  53167. for (var i = 0, ii = buffer.length; i < ii; i++) {
  53168. buffer[i] ^= 0xff;
  53169. }
  53170. }
  53171. return imgData;
  53172. }
  53173. if (this.image instanceof JpegStream && !this.smask && !this.mask && (this.colorSpace.name === 'DeviceGray' || this.colorSpace.name === 'DeviceRGB' || this.colorSpace.name === 'DeviceCMYK')) {
  53174. imgData.kind = ImageKind.RGB_24BPP;
  53175. imgData.data = this.getImageBytes(originalHeight * rowBytes, drawWidth, drawHeight, true);
  53176. return imgData;
  53177. }
  53178. }
  53179. imgArray = this.getImageBytes(originalHeight * rowBytes);
  53180. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  53181. var actualHeight = 0 | imgArray.length / rowBytes * drawHeight / originalHeight;
  53182. var comps = this.getComponents(imgArray);
  53183. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  53184. // more compact RGB_24BPP form if allowable.
  53185. var alpha01, maybeUndoPreblend;
  53186. if (!forceRGBA && !this.smask && !this.mask) {
  53187. imgData.kind = ImageKind.RGB_24BPP;
  53188. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  53189. alpha01 = 0;
  53190. maybeUndoPreblend = false;
  53191. } else {
  53192. imgData.kind = ImageKind.RGBA_32BPP;
  53193. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  53194. alpha01 = 1;
  53195. maybeUndoPreblend = true;
  53196. // Color key masking (opacity) must be performed before decoding.
  53197. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight, comps);
  53198. }
  53199. if (this.needsDecode) {
  53200. this.decodeBuffer(comps);
  53201. }
  53202. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight, drawWidth, drawHeight, actualHeight, bpc, comps, alpha01);
  53203. if (maybeUndoPreblend) {
  53204. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  53205. }
  53206. return imgData;
  53207. },
  53208. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  53209. var numComps = this.numComps;
  53210. if (numComps !== 1) {
  53211. error('Reading gray scale from a color image: ' + numComps);
  53212. }
  53213. var width = this.width;
  53214. var height = this.height;
  53215. var bpc = this.bpc;
  53216. // rows start at byte boundary
  53217. var rowBytes = width * numComps * bpc + 7 >> 3;
  53218. var imgArray = this.getImageBytes(height * rowBytes);
  53219. var comps = this.getComponents(imgArray);
  53220. var i, length;
  53221. if (bpc === 1) {
  53222. // inline decoding (= inversion) for 1 bpc images
  53223. length = width * height;
  53224. if (this.needsDecode) {
  53225. // invert and scale to {0, 255}
  53226. for (i = 0; i < length; ++i) {
  53227. buffer[i] = comps[i] - 1 & 255;
  53228. }
  53229. } else {
  53230. // scale to {0, 255}
  53231. for (i = 0; i < length; ++i) {
  53232. buffer[i] = -comps[i] & 255;
  53233. }
  53234. }
  53235. return;
  53236. }
  53237. if (this.needsDecode) {
  53238. this.decodeBuffer(comps);
  53239. }
  53240. length = width * height;
  53241. // we aren't using a colorspace so we need to scale the value
  53242. var scale = 255 / ((1 << bpc) - 1);
  53243. for (i = 0; i < length; ++i) {
  53244. buffer[i] = scale * comps[i] | 0;
  53245. }
  53246. },
  53247. getImageBytes: function PDFImage_getImageBytes(length, drawWidth, drawHeight, forceRGB) {
  53248. this.image.reset();
  53249. this.image.drawWidth = drawWidth || this.width;
  53250. this.image.drawHeight = drawHeight || this.height;
  53251. this.image.forceRGB = !!forceRGB;
  53252. return this.image.getBytes(length);
  53253. }
  53254. };
  53255. return PDFImage;
  53256. }();
  53257. exports.PDFImage = PDFImage;
  53258. }));
  53259. (function (root, factory) {
  53260. factory(root.pdfjsCoreObj = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreCrypto, root.pdfjsCoreParser, root.pdfjsCoreChunkedStream, root.pdfjsCoreColorSpace);
  53261. }(this, function (exports, sharedUtil, corePrimitives, coreCrypto, coreParser, coreChunkedStream, coreColorSpace) {
  53262. var InvalidPDFException = sharedUtil.InvalidPDFException;
  53263. var MissingDataException = sharedUtil.MissingDataException;
  53264. var XRefParseException = sharedUtil.XRefParseException;
  53265. var assert = sharedUtil.assert;
  53266. var bytesToString = sharedUtil.bytesToString;
  53267. var createPromiseCapability = sharedUtil.createPromiseCapability;
  53268. var error = sharedUtil.error;
  53269. var info = sharedUtil.info;
  53270. var isArray = sharedUtil.isArray;
  53271. var isInt = sharedUtil.isInt;
  53272. var isString = sharedUtil.isString;
  53273. var shadow = sharedUtil.shadow;
  53274. var stringToPDFString = sharedUtil.stringToPDFString;
  53275. var stringToUTF8String = sharedUtil.stringToUTF8String;
  53276. var warn = sharedUtil.warn;
  53277. var isValidUrl = sharedUtil.isValidUrl;
  53278. var Util = sharedUtil.Util;
  53279. var Ref = corePrimitives.Ref;
  53280. var RefSet = corePrimitives.RefSet;
  53281. var RefSetCache = corePrimitives.RefSetCache;
  53282. var isName = corePrimitives.isName;
  53283. var isCmd = corePrimitives.isCmd;
  53284. var isDict = corePrimitives.isDict;
  53285. var isRef = corePrimitives.isRef;
  53286. var isRefsEqual = corePrimitives.isRefsEqual;
  53287. var isStream = corePrimitives.isStream;
  53288. var CipherTransformFactory = coreCrypto.CipherTransformFactory;
  53289. var Lexer = coreParser.Lexer;
  53290. var Parser = coreParser.Parser;
  53291. var ChunkedStream = coreChunkedStream.ChunkedStream;
  53292. var ColorSpace = coreColorSpace.ColorSpace;
  53293. var Catalog = function CatalogClosure() {
  53294. function Catalog(pdfManager, xref, pageFactory) {
  53295. this.pdfManager = pdfManager;
  53296. this.xref = xref;
  53297. this.catDict = xref.getCatalogObj();
  53298. this.fontCache = new RefSetCache();
  53299. assert(isDict(this.catDict), 'catalog object is not a dictionary');
  53300. // TODO refactor to move getPage() to the PDFDocument.
  53301. this.pageFactory = pageFactory;
  53302. this.pagePromises = [];
  53303. }
  53304. Catalog.prototype = {
  53305. get metadata() {
  53306. var streamRef = this.catDict.getRaw('Metadata');
  53307. if (!isRef(streamRef)) {
  53308. return shadow(this, 'metadata', null);
  53309. }
  53310. var encryptMetadata = !this.xref.encrypt ? false : this.xref.encrypt.encryptMetadata;
  53311. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  53312. var metadata;
  53313. if (stream && isDict(stream.dict)) {
  53314. var type = stream.dict.get('Type');
  53315. var subtype = stream.dict.get('Subtype');
  53316. if (isName(type, 'Metadata') && isName(subtype, 'XML')) {
  53317. // XXX: This should examine the charset the XML document defines,
  53318. // however since there are currently no real means to decode
  53319. // arbitrary charsets, let's just hope that the author of the PDF
  53320. // was reasonable enough to stick with the XML default charset,
  53321. // which is UTF-8.
  53322. try {
  53323. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  53324. } catch (e) {
  53325. info('Skipping invalid metadata.');
  53326. }
  53327. }
  53328. }
  53329. return shadow(this, 'metadata', metadata);
  53330. },
  53331. get toplevelPagesDict() {
  53332. var pagesObj = this.catDict.get('Pages');
  53333. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  53334. // shadow the prototype getter
  53335. return shadow(this, 'toplevelPagesDict', pagesObj);
  53336. },
  53337. get documentOutline() {
  53338. var obj = null;
  53339. try {
  53340. obj = this.readDocumentOutline();
  53341. } catch (ex) {
  53342. if (ex instanceof MissingDataException) {
  53343. throw ex;
  53344. }
  53345. warn('Unable to read document outline');
  53346. }
  53347. return shadow(this, 'documentOutline', obj);
  53348. },
  53349. readDocumentOutline: function Catalog_readDocumentOutline() {
  53350. var obj = this.catDict.get('Outlines');
  53351. if (!isDict(obj)) {
  53352. return null;
  53353. }
  53354. obj = obj.getRaw('First');
  53355. if (!isRef(obj)) {
  53356. return null;
  53357. }
  53358. var root = { items: [] };
  53359. var queue = [{
  53360. obj: obj,
  53361. parent: root
  53362. }];
  53363. // To avoid recursion, keep track of the already processed items.
  53364. var processed = new RefSet();
  53365. processed.put(obj);
  53366. var xref = this.xref, blackColor = new Uint8Array(3);
  53367. while (queue.length > 0) {
  53368. var i = queue.shift();
  53369. var outlineDict = xref.fetchIfRef(i.obj);
  53370. if (outlineDict === null) {
  53371. continue;
  53372. }
  53373. assert(outlineDict.has('Title'), 'Invalid outline item');
  53374. var actionDict = outlineDict.get('A'), dest = null, url = null;
  53375. if (actionDict) {
  53376. var destEntry = actionDict.get('D');
  53377. if (destEntry) {
  53378. dest = destEntry;
  53379. } else {
  53380. var uriEntry = actionDict.get('URI');
  53381. if (isString(uriEntry) && isValidUrl(uriEntry, false)) {
  53382. url = uriEntry;
  53383. }
  53384. }
  53385. } else if (outlineDict.has('Dest')) {
  53386. dest = outlineDict.getRaw('Dest');
  53387. if (isName(dest)) {
  53388. dest = dest.name;
  53389. }
  53390. }
  53391. var title = outlineDict.get('Title');
  53392. var flags = outlineDict.get('F') || 0;
  53393. var color = outlineDict.getArray('C'), rgbColor = blackColor;
  53394. // We only need to parse the color when it's valid, and non-default.
  53395. if (isArray(color) && color.length === 3 && (color[0] !== 0 || color[1] !== 0 || color[2] !== 0)) {
  53396. rgbColor = ColorSpace.singletons.rgb.getRgb(color, 0);
  53397. }
  53398. var outlineItem = {
  53399. dest: dest,
  53400. url: url,
  53401. title: stringToPDFString(title),
  53402. color: rgbColor,
  53403. count: outlineDict.get('Count'),
  53404. bold: !!(flags & 2),
  53405. italic: !!(flags & 1),
  53406. items: []
  53407. };
  53408. i.parent.items.push(outlineItem);
  53409. obj = outlineDict.getRaw('First');
  53410. if (isRef(obj) && !processed.has(obj)) {
  53411. queue.push({
  53412. obj: obj,
  53413. parent: outlineItem
  53414. });
  53415. processed.put(obj);
  53416. }
  53417. obj = outlineDict.getRaw('Next');
  53418. if (isRef(obj) && !processed.has(obj)) {
  53419. queue.push({
  53420. obj: obj,
  53421. parent: i.parent
  53422. });
  53423. processed.put(obj);
  53424. }
  53425. }
  53426. return root.items.length > 0 ? root.items : null;
  53427. },
  53428. get numPages() {
  53429. var obj = this.toplevelPagesDict.get('Count');
  53430. assert(isInt(obj), 'page count in top level pages object is not an integer');
  53431. // shadow the prototype getter
  53432. return shadow(this, 'num', obj);
  53433. },
  53434. get destinations() {
  53435. function fetchDestination(dest) {
  53436. return isDict(dest) ? dest.get('D') : dest;
  53437. }
  53438. var xref = this.xref;
  53439. var dests = {}, nameTreeRef, nameDictionaryRef;
  53440. var obj = this.catDict.get('Names');
  53441. if (obj && obj.has('Dests')) {
  53442. nameTreeRef = obj.getRaw('Dests');
  53443. } else if (this.catDict.has('Dests')) {
  53444. nameDictionaryRef = this.catDict.get('Dests');
  53445. }
  53446. if (nameDictionaryRef) {
  53447. // reading simple destination dictionary
  53448. obj = nameDictionaryRef;
  53449. obj.forEach(function catalogForEach(key, value) {
  53450. if (!value) {
  53451. return;
  53452. }
  53453. dests[key] = fetchDestination(value);
  53454. });
  53455. }
  53456. if (nameTreeRef) {
  53457. var nameTree = new NameTree(nameTreeRef, xref);
  53458. var names = nameTree.getAll();
  53459. for (var name in names) {
  53460. dests[name] = fetchDestination(names[name]);
  53461. }
  53462. }
  53463. return shadow(this, 'destinations', dests);
  53464. },
  53465. getDestination: function Catalog_getDestination(destinationId) {
  53466. function fetchDestination(dest) {
  53467. return isDict(dest) ? dest.get('D') : dest;
  53468. }
  53469. var xref = this.xref;
  53470. var dest = null, nameTreeRef, nameDictionaryRef;
  53471. var obj = this.catDict.get('Names');
  53472. if (obj && obj.has('Dests')) {
  53473. nameTreeRef = obj.getRaw('Dests');
  53474. } else if (this.catDict.has('Dests')) {
  53475. nameDictionaryRef = this.catDict.get('Dests');
  53476. }
  53477. if (nameDictionaryRef) {
  53478. // Simple destination dictionary.
  53479. var value = nameDictionaryRef.get(destinationId);
  53480. if (value) {
  53481. dest = fetchDestination(value);
  53482. }
  53483. }
  53484. if (nameTreeRef) {
  53485. var nameTree = new NameTree(nameTreeRef, xref);
  53486. dest = fetchDestination(nameTree.get(destinationId));
  53487. }
  53488. return dest;
  53489. },
  53490. get pageLabels() {
  53491. var obj = null;
  53492. try {
  53493. obj = this.readPageLabels();
  53494. } catch (ex) {
  53495. if (ex instanceof MissingDataException) {
  53496. throw ex;
  53497. }
  53498. warn('Unable to read page labels.');
  53499. }
  53500. return shadow(this, 'pageLabels', obj);
  53501. },
  53502. readPageLabels: function Catalog_readPageLabels() {
  53503. var obj = this.catDict.getRaw('PageLabels');
  53504. if (!obj) {
  53505. return null;
  53506. }
  53507. var pageLabels = new Array(this.numPages);
  53508. var style = null;
  53509. var prefix = '';
  53510. var start = 1;
  53511. var numberTree = new NumberTree(obj, this.xref);
  53512. var nums = numberTree.getAll();
  53513. var currentLabel = '', currentIndex = 1;
  53514. for (var i = 0, ii = this.numPages; i < ii; i++) {
  53515. if (i in nums) {
  53516. var labelDict = nums[i];
  53517. assert(isDict(labelDict), 'The PageLabel is not a dictionary.');
  53518. var type = labelDict.get('Type');
  53519. assert(!type || isName(type, 'PageLabel'), 'Invalid type in PageLabel dictionary.');
  53520. var s = labelDict.get('S');
  53521. assert(!s || isName(s), 'Invalid style in PageLabel dictionary.');
  53522. style = s ? s.name : null;
  53523. prefix = labelDict.get('P') || '';
  53524. assert(isString(prefix), 'Invalid prefix in PageLabel dictionary.');
  53525. start = labelDict.get('St') || 1;
  53526. assert(isInt(start), 'Invalid start in PageLabel dictionary.');
  53527. currentIndex = start;
  53528. }
  53529. switch (style) {
  53530. case 'D':
  53531. currentLabel = currentIndex;
  53532. break;
  53533. case 'R':
  53534. case 'r':
  53535. currentLabel = Util.toRoman(currentIndex, style === 'r');
  53536. break;
  53537. case 'A':
  53538. case 'a':
  53539. var LIMIT = 26;
  53540. // Use only the characters A--Z, or a--z.
  53541. var A_UPPER_CASE = 0x41, A_LOWER_CASE = 0x61;
  53542. var baseCharCode = style === 'a' ? A_LOWER_CASE : A_UPPER_CASE;
  53543. var letterIndex = currentIndex - 1;
  53544. var character = String.fromCharCode(baseCharCode + letterIndex % LIMIT);
  53545. var charBuf = [];
  53546. for (var j = 0, jj = letterIndex / LIMIT | 0; j <= jj; j++) {
  53547. charBuf.push(character);
  53548. }
  53549. currentLabel = charBuf.join('');
  53550. break;
  53551. default:
  53552. assert(!style, 'Invalid style "' + style + '" in PageLabel dictionary.');
  53553. }
  53554. pageLabels[i] = prefix + currentLabel;
  53555. currentLabel = '';
  53556. currentIndex++;
  53557. }
  53558. return pageLabels;
  53559. },
  53560. get attachments() {
  53561. var xref = this.xref;
  53562. var attachments = null, nameTreeRef;
  53563. var obj = this.catDict.get('Names');
  53564. if (obj) {
  53565. nameTreeRef = obj.getRaw('EmbeddedFiles');
  53566. }
  53567. if (nameTreeRef) {
  53568. var nameTree = new NameTree(nameTreeRef, xref);
  53569. var names = nameTree.getAll();
  53570. for (var name in names) {
  53571. var fs = new FileSpec(names[name], xref);
  53572. if (!attachments) {
  53573. attachments = Object.create(null);
  53574. }
  53575. attachments[stringToPDFString(name)] = fs.serializable;
  53576. }
  53577. }
  53578. return shadow(this, 'attachments', attachments);
  53579. },
  53580. get javaScript() {
  53581. var xref = this.xref;
  53582. var obj = this.catDict.get('Names');
  53583. var javaScript = [];
  53584. function appendIfJavaScriptDict(jsDict) {
  53585. var type = jsDict.get('S');
  53586. if (!isName(type, 'JavaScript')) {
  53587. return;
  53588. }
  53589. var js = jsDict.get('JS');
  53590. if (isStream(js)) {
  53591. js = bytesToString(js.getBytes());
  53592. } else if (!isString(js)) {
  53593. return;
  53594. }
  53595. javaScript.push(stringToPDFString(js));
  53596. }
  53597. if (obj && obj.has('JavaScript')) {
  53598. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  53599. var names = nameTree.getAll();
  53600. for (var name in names) {
  53601. // We don't really use the JavaScript right now. This code is
  53602. // defensive so we don't cause errors on document load.
  53603. var jsDict = names[name];
  53604. if (isDict(jsDict)) {
  53605. appendIfJavaScriptDict(jsDict);
  53606. }
  53607. }
  53608. }
  53609. // Append OpenAction actions to javaScript array
  53610. var openactionDict = this.catDict.get('OpenAction');
  53611. if (isDict(openactionDict, 'Action')) {
  53612. var actionType = openactionDict.get('S');
  53613. if (isName(actionType, 'Named')) {
  53614. // The named Print action is not a part of the PDF 1.7 specification,
  53615. // but is supported by many PDF readers/writers (including Adobe's).
  53616. var action = openactionDict.get('N');
  53617. if (isName(action, 'Print')) {
  53618. javaScript.push('print({});');
  53619. }
  53620. } else {
  53621. appendIfJavaScriptDict(openactionDict);
  53622. }
  53623. }
  53624. return shadow(this, 'javaScript', javaScript);
  53625. },
  53626. cleanup: function Catalog_cleanup() {
  53627. var promises = [];
  53628. this.fontCache.forEach(function (promise) {
  53629. promises.push(promise);
  53630. });
  53631. return Promise.all(promises).then(function (translatedFonts) {
  53632. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  53633. var font = translatedFonts[i].dict;
  53634. delete font.translated;
  53635. }
  53636. this.fontCache.clear();
  53637. }.bind(this));
  53638. },
  53639. getPage: function Catalog_getPage(pageIndex) {
  53640. if (!(pageIndex in this.pagePromises)) {
  53641. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(function (a) {
  53642. var dict = a[0];
  53643. var ref = a[1];
  53644. return this.pageFactory.createPage(pageIndex, dict, ref, this.fontCache);
  53645. }.bind(this));
  53646. }
  53647. return this.pagePromises[pageIndex];
  53648. },
  53649. getPageDict: function Catalog_getPageDict(pageIndex) {
  53650. var capability = createPromiseCapability();
  53651. var nodesToVisit = [this.catDict.getRaw('Pages')];
  53652. var currentPageIndex = 0;
  53653. var xref = this.xref;
  53654. var checkAllKids = false;
  53655. function next() {
  53656. while (nodesToVisit.length) {
  53657. var currentNode = nodesToVisit.pop();
  53658. if (isRef(currentNode)) {
  53659. xref.fetchAsync(currentNode).then(function (obj) {
  53660. if (isDict(obj, 'Page') || isDict(obj) && !obj.has('Kids')) {
  53661. if (pageIndex === currentPageIndex) {
  53662. capability.resolve([
  53663. obj,
  53664. currentNode
  53665. ]);
  53666. } else {
  53667. currentPageIndex++;
  53668. next();
  53669. }
  53670. return;
  53671. }
  53672. nodesToVisit.push(obj);
  53673. next();
  53674. }, capability.reject);
  53675. return;
  53676. }
  53677. // Must be a child page dictionary.
  53678. assert(isDict(currentNode), 'page dictionary kid reference points to wrong type of object');
  53679. var count = currentNode.get('Count');
  53680. // If the current node doesn't have any children, avoid getting stuck
  53681. // in an empty node further down in the tree (see issue5644.pdf).
  53682. if (count === 0) {
  53683. checkAllKids = true;
  53684. }
  53685. // Skip nodes where the page can't be.
  53686. if (currentPageIndex + count <= pageIndex) {
  53687. currentPageIndex += count;
  53688. continue;
  53689. }
  53690. var kids = currentNode.get('Kids');
  53691. assert(isArray(kids), 'page dictionary kids object is not an array');
  53692. if (!checkAllKids && count === kids.length) {
  53693. // Nodes that don't have the page have been skipped and this is the
  53694. // bottom of the tree which means the page requested must be a
  53695. // descendant of this pages node. Ideally we would just resolve the
  53696. // promise with the page ref here, but there is the case where more
  53697. // pages nodes could link to single a page (see issue 3666 pdf). To
  53698. // handle this push it back on the queue so if it is a pages node it
  53699. // will be descended into.
  53700. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  53701. currentPageIndex = pageIndex;
  53702. continue;
  53703. } else {
  53704. for (var last = kids.length - 1; last >= 0; last--) {
  53705. nodesToVisit.push(kids[last]);
  53706. }
  53707. }
  53708. }
  53709. capability.reject('Page index ' + pageIndex + ' not found.');
  53710. }
  53711. next();
  53712. return capability.promise;
  53713. },
  53714. getPageIndex: function Catalog_getPageIndex(pageRef) {
  53715. // The page tree nodes have the count of all the leaves below them. To get
  53716. // how many pages are before we just have to walk up the tree and keep
  53717. // adding the count of siblings to the left of the node.
  53718. var xref = this.xref;
  53719. function pagesBeforeRef(kidRef) {
  53720. var total = 0;
  53721. var parentRef;
  53722. return xref.fetchAsync(kidRef).then(function (node) {
  53723. if (isRefsEqual(kidRef, pageRef) && !isDict(node, 'Page') && !(isDict(node) && !node.has('Type') && node.has('Contents'))) {
  53724. throw new Error('The reference does not point to a /Page Dict.');
  53725. }
  53726. if (!node) {
  53727. return null;
  53728. }
  53729. assert(isDict(node), 'node must be a Dict.');
  53730. parentRef = node.getRaw('Parent');
  53731. return node.getAsync('Parent');
  53732. }).then(function (parent) {
  53733. if (!parent) {
  53734. return null;
  53735. }
  53736. assert(isDict(parent), 'parent must be a Dict.');
  53737. return parent.getAsync('Kids');
  53738. }).then(function (kids) {
  53739. if (!kids) {
  53740. return null;
  53741. }
  53742. var kidPromises = [];
  53743. var found = false;
  53744. for (var i = 0; i < kids.length; i++) {
  53745. var kid = kids[i];
  53746. assert(isRef(kid), 'kid must be a Ref.');
  53747. if (kid.num === kidRef.num) {
  53748. found = true;
  53749. break;
  53750. }
  53751. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  53752. if (kid.has('Count')) {
  53753. var count = kid.get('Count');
  53754. total += count;
  53755. } else {
  53756. // page leaf node
  53757. total++;
  53758. }
  53759. }));
  53760. }
  53761. if (!found) {
  53762. error('kid ref not found in parents kids');
  53763. }
  53764. return Promise.all(kidPromises).then(function () {
  53765. return [
  53766. total,
  53767. parentRef
  53768. ];
  53769. });
  53770. });
  53771. }
  53772. var total = 0;
  53773. function next(ref) {
  53774. return pagesBeforeRef(ref).then(function (args) {
  53775. if (!args) {
  53776. return total;
  53777. }
  53778. var count = args[0];
  53779. var parentRef = args[1];
  53780. total += count;
  53781. return next(parentRef);
  53782. });
  53783. }
  53784. return next(pageRef);
  53785. }
  53786. };
  53787. return Catalog;
  53788. }();
  53789. var XRef = function XRefClosure() {
  53790. function XRef(stream, password) {
  53791. this.stream = stream;
  53792. this.entries = [];
  53793. this.xrefstms = Object.create(null);
  53794. // prepare the XRef cache
  53795. this.cache = [];
  53796. this.password = password;
  53797. this.stats = {
  53798. streamTypes: [],
  53799. fontTypes: []
  53800. };
  53801. }
  53802. XRef.prototype = {
  53803. setStartXRef: function XRef_setStartXRef(startXRef) {
  53804. // Store the starting positions of xref tables as we process them
  53805. // so we can recover from missing data errors
  53806. this.startXRefQueue = [startXRef];
  53807. },
  53808. parse: function XRef_parse(recoveryMode) {
  53809. var trailerDict;
  53810. if (!recoveryMode) {
  53811. trailerDict = this.readXRef();
  53812. } else {
  53813. warn('Indexing all PDF objects');
  53814. trailerDict = this.indexObjects();
  53815. }
  53816. trailerDict.assignXref(this);
  53817. this.trailer = trailerDict;
  53818. var encrypt = trailerDict.get('Encrypt');
  53819. if (encrypt) {
  53820. var ids = trailerDict.get('ID');
  53821. var fileId = ids && ids.length ? ids[0] : '';
  53822. // The 'Encrypt' dictionary itself should not be encrypted, and by
  53823. // setting `suppressEncryption` we can prevent an infinite loop inside
  53824. // of `XRef_fetchUncompressed` if the dictionary contains indirect
  53825. // objects (fixes issue7665.pdf).
  53826. encrypt.suppressEncryption = true;
  53827. this.encrypt = new CipherTransformFactory(encrypt, fileId, this.password);
  53828. }
  53829. // get the root dictionary (catalog) object
  53830. if (!(this.root = trailerDict.get('Root'))) {
  53831. error('Invalid root reference');
  53832. }
  53833. },
  53834. processXRefTable: function XRef_processXRefTable(parser) {
  53835. if (!('tableState' in this)) {
  53836. // Stores state of the table as we process it so we can resume
  53837. // from middle of table in case of missing data error
  53838. this.tableState = {
  53839. entryNum: 0,
  53840. streamPos: parser.lexer.stream.pos,
  53841. parserBuf1: parser.buf1,
  53842. parserBuf2: parser.buf2
  53843. };
  53844. }
  53845. var obj = this.readXRefTable(parser);
  53846. // Sanity check
  53847. if (!isCmd(obj, 'trailer')) {
  53848. error('Invalid XRef table: could not find trailer dictionary');
  53849. }
  53850. // Read trailer dictionary, e.g.
  53851. // trailer
  53852. // << /Size 22
  53853. // /Root 20R
  53854. // /Info 10R
  53855. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  53856. // >>
  53857. // The parser goes through the entire stream << ... >> and provides
  53858. // a getter interface for the key-value table
  53859. var dict = parser.getObj();
  53860. // The pdflib PDF generator can generate a nested trailer dictionary
  53861. if (!isDict(dict) && dict.dict) {
  53862. dict = dict.dict;
  53863. }
  53864. if (!isDict(dict)) {
  53865. error('Invalid XRef table: could not parse trailer dictionary');
  53866. }
  53867. delete this.tableState;
  53868. return dict;
  53869. },
  53870. readXRefTable: function XRef_readXRefTable(parser) {
  53871. // Example of cross-reference table:
  53872. // xref
  53873. // 0 1 <-- subsection header (first obj #, obj count)
  53874. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  53875. // 23 2 <-- subsection header ... and so on ...
  53876. // 0000025518 00002 n
  53877. // 0000025635 00000 n
  53878. // trailer
  53879. // ...
  53880. var stream = parser.lexer.stream;
  53881. var tableState = this.tableState;
  53882. stream.pos = tableState.streamPos;
  53883. parser.buf1 = tableState.parserBuf1;
  53884. parser.buf2 = tableState.parserBuf2;
  53885. // Outer loop is over subsection headers
  53886. var obj;
  53887. while (true) {
  53888. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  53889. if (isCmd(obj = parser.getObj(), 'trailer')) {
  53890. break;
  53891. }
  53892. tableState.firstEntryNum = obj;
  53893. tableState.entryCount = parser.getObj();
  53894. }
  53895. var first = tableState.firstEntryNum;
  53896. var count = tableState.entryCount;
  53897. if (!isInt(first) || !isInt(count)) {
  53898. error('Invalid XRef table: wrong types in subsection header');
  53899. }
  53900. // Inner loop is over objects themselves
  53901. for (var i = tableState.entryNum; i < count; i++) {
  53902. tableState.streamPos = stream.pos;
  53903. tableState.entryNum = i;
  53904. tableState.parserBuf1 = parser.buf1;
  53905. tableState.parserBuf2 = parser.buf2;
  53906. var entry = {};
  53907. entry.offset = parser.getObj();
  53908. entry.gen = parser.getObj();
  53909. var type = parser.getObj();
  53910. if (isCmd(type, 'f')) {
  53911. entry.free = true;
  53912. } else if (isCmd(type, 'n')) {
  53913. entry.uncompressed = true;
  53914. }
  53915. // Validate entry obj
  53916. if (!isInt(entry.offset) || !isInt(entry.gen) || !(entry.free || entry.uncompressed)) {
  53917. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  53918. }
  53919. // The first xref table entry, i.e. obj 0, should be free. Attempting
  53920. // to adjust an incorrect first obj # (fixes issue 3248 and 7229).
  53921. if (i === 0 && entry.free && first === 1) {
  53922. first = 0;
  53923. }
  53924. if (!this.entries[i + first]) {
  53925. this.entries[i + first] = entry;
  53926. }
  53927. }
  53928. tableState.entryNum = 0;
  53929. tableState.streamPos = stream.pos;
  53930. tableState.parserBuf1 = parser.buf1;
  53931. tableState.parserBuf2 = parser.buf2;
  53932. delete tableState.firstEntryNum;
  53933. delete tableState.entryCount;
  53934. }
  53935. // Sanity check: as per spec, first object must be free
  53936. if (this.entries[0] && !this.entries[0].free) {
  53937. error('Invalid XRef table: unexpected first object');
  53938. }
  53939. return obj;
  53940. },
  53941. processXRefStream: function XRef_processXRefStream(stream) {
  53942. if (!('streamState' in this)) {
  53943. // Stores state of the stream as we process it so we can resume
  53944. // from middle of stream in case of missing data error
  53945. var streamParameters = stream.dict;
  53946. var byteWidths = streamParameters.get('W');
  53947. var range = streamParameters.get('Index');
  53948. if (!range) {
  53949. range = [
  53950. 0,
  53951. streamParameters.get('Size')
  53952. ];
  53953. }
  53954. this.streamState = {
  53955. entryRanges: range,
  53956. byteWidths: byteWidths,
  53957. entryNum: 0,
  53958. streamPos: stream.pos
  53959. };
  53960. }
  53961. this.readXRefStream(stream);
  53962. delete this.streamState;
  53963. return stream.dict;
  53964. },
  53965. readXRefStream: function XRef_readXRefStream(stream) {
  53966. var i, j;
  53967. var streamState = this.streamState;
  53968. stream.pos = streamState.streamPos;
  53969. var byteWidths = streamState.byteWidths;
  53970. var typeFieldWidth = byteWidths[0];
  53971. var offsetFieldWidth = byteWidths[1];
  53972. var generationFieldWidth = byteWidths[2];
  53973. var entryRanges = streamState.entryRanges;
  53974. while (entryRanges.length > 0) {
  53975. var first = entryRanges[0];
  53976. var n = entryRanges[1];
  53977. if (!isInt(first) || !isInt(n)) {
  53978. error('Invalid XRef range fields: ' + first + ', ' + n);
  53979. }
  53980. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) || !isInt(generationFieldWidth)) {
  53981. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  53982. }
  53983. for (i = streamState.entryNum; i < n; ++i) {
  53984. streamState.entryNum = i;
  53985. streamState.streamPos = stream.pos;
  53986. var type = 0, offset = 0, generation = 0;
  53987. for (j = 0; j < typeFieldWidth; ++j) {
  53988. type = type << 8 | stream.getByte();
  53989. }
  53990. // if type field is absent, its default value is 1
  53991. if (typeFieldWidth === 0) {
  53992. type = 1;
  53993. }
  53994. for (j = 0; j < offsetFieldWidth; ++j) {
  53995. offset = offset << 8 | stream.getByte();
  53996. }
  53997. for (j = 0; j < generationFieldWidth; ++j) {
  53998. generation = generation << 8 | stream.getByte();
  53999. }
  54000. var entry = {};
  54001. entry.offset = offset;
  54002. entry.gen = generation;
  54003. switch (type) {
  54004. case 0:
  54005. entry.free = true;
  54006. break;
  54007. case 1:
  54008. entry.uncompressed = true;
  54009. break;
  54010. case 2:
  54011. break;
  54012. default:
  54013. error('Invalid XRef entry type: ' + type);
  54014. }
  54015. if (!this.entries[first + i]) {
  54016. this.entries[first + i] = entry;
  54017. }
  54018. }
  54019. streamState.entryNum = 0;
  54020. streamState.streamPos = stream.pos;
  54021. entryRanges.splice(0, 2);
  54022. }
  54023. },
  54024. indexObjects: function XRef_indexObjects() {
  54025. // Simple scan through the PDF content to find objects,
  54026. // trailers and XRef streams.
  54027. var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
  54028. var PERCENT = 0x25, LT = 0x3C;
  54029. function readToken(data, offset) {
  54030. var token = '', ch = data[offset];
  54031. while (ch !== LF && ch !== CR && ch !== LT) {
  54032. if (++offset >= data.length) {
  54033. break;
  54034. }
  54035. token += String.fromCharCode(ch);
  54036. ch = data[offset];
  54037. }
  54038. return token;
  54039. }
  54040. function skipUntil(data, offset, what) {
  54041. var length = what.length, dataLength = data.length;
  54042. var skipped = 0;
  54043. // finding byte sequence
  54044. while (offset < dataLength) {
  54045. var i = 0;
  54046. while (i < length && data[offset + i] === what[i]) {
  54047. ++i;
  54048. }
  54049. if (i >= length) {
  54050. break;
  54051. }
  54052. // sequence found
  54053. offset++;
  54054. skipped++;
  54055. }
  54056. return skipped;
  54057. }
  54058. var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  54059. var trailerBytes = new Uint8Array([
  54060. 116,
  54061. 114,
  54062. 97,
  54063. 105,
  54064. 108,
  54065. 101,
  54066. 114
  54067. ]);
  54068. var startxrefBytes = new Uint8Array([
  54069. 115,
  54070. 116,
  54071. 97,
  54072. 114,
  54073. 116,
  54074. 120,
  54075. 114,
  54076. 101,
  54077. 102
  54078. ]);
  54079. var endobjBytes = new Uint8Array([
  54080. 101,
  54081. 110,
  54082. 100,
  54083. 111,
  54084. 98,
  54085. 106
  54086. ]);
  54087. var xrefBytes = new Uint8Array([
  54088. 47,
  54089. 88,
  54090. 82,
  54091. 101,
  54092. 102
  54093. ]);
  54094. // Clear out any existing entries, since they may be bogus.
  54095. this.entries.length = 0;
  54096. var stream = this.stream;
  54097. stream.pos = 0;
  54098. var buffer = stream.getBytes();
  54099. var position = stream.start, length = buffer.length;
  54100. var trailers = [], xrefStms = [];
  54101. while (position < length) {
  54102. var ch = buffer[position];
  54103. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  54104. ++position;
  54105. continue;
  54106. }
  54107. if (ch === PERCENT) {
  54108. // %-comment
  54109. do {
  54110. ++position;
  54111. if (position >= length) {
  54112. break;
  54113. }
  54114. ch = buffer[position];
  54115. } while (ch !== LF && ch !== CR);
  54116. continue;
  54117. }
  54118. var token = readToken(buffer, position);
  54119. var m;
  54120. if (token.indexOf('xref') === 0 && (token.length === 4 || /\s/.test(token[4]))) {
  54121. position += skipUntil(buffer, position, trailerBytes);
  54122. trailers.push(position);
  54123. position += skipUntil(buffer, position, startxrefBytes);
  54124. } else if (m = objRegExp.exec(token)) {
  54125. if (typeof this.entries[m[1]] === 'undefined') {
  54126. this.entries[m[1]] = {
  54127. offset: position - stream.start,
  54128. gen: m[2] | 0,
  54129. uncompressed: true
  54130. };
  54131. }
  54132. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  54133. var content = buffer.subarray(position, position + contentLength);
  54134. // checking XRef stream suspect
  54135. // (it shall have '/XRef' and next char is not a letter)
  54136. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  54137. if (xrefTagOffset < contentLength && content[xrefTagOffset + 5] < 64) {
  54138. xrefStms.push(position - stream.start);
  54139. this.xrefstms[position - stream.start] = 1;
  54140. }
  54141. // Avoid recursion
  54142. position += contentLength;
  54143. } else if (token.indexOf('trailer') === 0 && (token.length === 7 || /\s/.test(token[7]))) {
  54144. trailers.push(position);
  54145. position += skipUntil(buffer, position, startxrefBytes);
  54146. } else {
  54147. position += token.length + 1;
  54148. }
  54149. }
  54150. // reading XRef streams
  54151. var i, ii;
  54152. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  54153. this.startXRefQueue.push(xrefStms[i]);
  54154. this.readXRef(/* recoveryMode */
  54155. true);
  54156. }
  54157. // finding main trailer
  54158. var dict;
  54159. for (i = 0, ii = trailers.length; i < ii; ++i) {
  54160. stream.pos = trailers[i];
  54161. var parser = new Parser(new Lexer(stream), /* allowStreams = */
  54162. true, /* xref = */
  54163. this, /* recoveryMode = */
  54164. true);
  54165. var obj = parser.getObj();
  54166. if (!isCmd(obj, 'trailer')) {
  54167. continue;
  54168. }
  54169. // read the trailer dictionary
  54170. dict = parser.getObj();
  54171. if (!isDict(dict)) {
  54172. continue;
  54173. }
  54174. // taking the first one with 'ID'
  54175. if (dict.has('ID')) {
  54176. return dict;
  54177. }
  54178. }
  54179. // no tailer with 'ID', taking last one (if exists)
  54180. if (dict) {
  54181. return dict;
  54182. }
  54183. // nothing helps
  54184. // calling error() would reject worker with an UnknownErrorException.
  54185. throw new InvalidPDFException('Invalid PDF structure');
  54186. },
  54187. readXRef: function XRef_readXRef(recoveryMode) {
  54188. var stream = this.stream;
  54189. try {
  54190. while (this.startXRefQueue.length) {
  54191. var startXRef = this.startXRefQueue[0];
  54192. stream.pos = startXRef + stream.start;
  54193. var parser = new Parser(new Lexer(stream), true, this);
  54194. var obj = parser.getObj();
  54195. var dict;
  54196. // Get dictionary
  54197. if (isCmd(obj, 'xref')) {
  54198. // Parse end-of-file XRef
  54199. dict = this.processXRefTable(parser);
  54200. if (!this.topDict) {
  54201. this.topDict = dict;
  54202. }
  54203. // Recursively get other XRefs 'XRefStm', if any
  54204. obj = dict.get('XRefStm');
  54205. if (isInt(obj)) {
  54206. var pos = obj;
  54207. // ignore previously loaded xref streams
  54208. // (possible infinite recursion)
  54209. if (!(pos in this.xrefstms)) {
  54210. this.xrefstms[pos] = 1;
  54211. this.startXRefQueue.push(pos);
  54212. }
  54213. }
  54214. } else if (isInt(obj)) {
  54215. // Parse in-stream XRef
  54216. if (!isInt(parser.getObj()) || !isCmd(parser.getObj(), 'obj') || !isStream(obj = parser.getObj())) {
  54217. error('Invalid XRef stream');
  54218. }
  54219. dict = this.processXRefStream(obj);
  54220. if (!this.topDict) {
  54221. this.topDict = dict;
  54222. }
  54223. if (!dict) {
  54224. error('Failed to read XRef stream');
  54225. }
  54226. } else {
  54227. error('Invalid XRef stream header');
  54228. }
  54229. // Recursively get previous dictionary, if any
  54230. obj = dict.get('Prev');
  54231. if (isInt(obj)) {
  54232. this.startXRefQueue.push(obj);
  54233. } else if (isRef(obj)) {
  54234. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  54235. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  54236. this.startXRefQueue.push(obj.num);
  54237. }
  54238. this.startXRefQueue.shift();
  54239. }
  54240. return this.topDict;
  54241. } catch (e) {
  54242. if (e instanceof MissingDataException) {
  54243. throw e;
  54244. }
  54245. info('(while reading XRef): ' + e);
  54246. }
  54247. if (recoveryMode) {
  54248. return;
  54249. }
  54250. throw new XRefParseException();
  54251. },
  54252. getEntry: function XRef_getEntry(i) {
  54253. var xrefEntry = this.entries[i];
  54254. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  54255. return xrefEntry;
  54256. }
  54257. return null;
  54258. },
  54259. fetchIfRef: function XRef_fetchIfRef(obj, suppressEncryption) {
  54260. if (!isRef(obj)) {
  54261. return obj;
  54262. }
  54263. return this.fetch(obj, suppressEncryption);
  54264. },
  54265. fetch: function XRef_fetch(ref, suppressEncryption) {
  54266. assert(isRef(ref), 'ref object is not a reference');
  54267. var num = ref.num;
  54268. if (num in this.cache) {
  54269. var cacheEntry = this.cache[num];
  54270. return cacheEntry;
  54271. }
  54272. var xrefEntry = this.getEntry(num);
  54273. // the referenced entry can be free
  54274. if (xrefEntry === null) {
  54275. return this.cache[num] = null;
  54276. }
  54277. if (xrefEntry.uncompressed) {
  54278. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  54279. } else {
  54280. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  54281. }
  54282. if (isDict(xrefEntry)) {
  54283. xrefEntry.objId = ref.toString();
  54284. } else if (isStream(xrefEntry)) {
  54285. xrefEntry.dict.objId = ref.toString();
  54286. }
  54287. return xrefEntry;
  54288. },
  54289. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry, suppressEncryption) {
  54290. var gen = ref.gen;
  54291. var num = ref.num;
  54292. if (xrefEntry.gen !== gen) {
  54293. error('inconsistent generation in XRef');
  54294. }
  54295. var stream = this.stream.makeSubStream(xrefEntry.offset + this.stream.start);
  54296. var parser = new Parser(new Lexer(stream), true, this);
  54297. var obj1 = parser.getObj();
  54298. var obj2 = parser.getObj();
  54299. var obj3 = parser.getObj();
  54300. if (!isInt(obj1) || parseInt(obj1, 10) !== num || !isInt(obj2) || parseInt(obj2, 10) !== gen || !isCmd(obj3)) {
  54301. error('bad XRef entry');
  54302. }
  54303. if (!isCmd(obj3, 'obj')) {
  54304. // some bad PDFs use "obj1234" and really mean 1234
  54305. if (obj3.cmd.indexOf('obj') === 0) {
  54306. num = parseInt(obj3.cmd.substring(3), 10);
  54307. if (!isNaN(num)) {
  54308. return num;
  54309. }
  54310. }
  54311. error('bad XRef entry');
  54312. }
  54313. if (this.encrypt && !suppressEncryption) {
  54314. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  54315. } else {
  54316. xrefEntry = parser.getObj();
  54317. }
  54318. if (!isStream(xrefEntry)) {
  54319. this.cache[num] = xrefEntry;
  54320. }
  54321. return xrefEntry;
  54322. },
  54323. fetchCompressed: function XRef_fetchCompressed(xrefEntry, suppressEncryption) {
  54324. var tableOffset = xrefEntry.offset;
  54325. var stream = this.fetch(new Ref(tableOffset, 0));
  54326. if (!isStream(stream)) {
  54327. error('bad ObjStm stream');
  54328. }
  54329. var first = stream.dict.get('First');
  54330. var n = stream.dict.get('N');
  54331. if (!isInt(first) || !isInt(n)) {
  54332. error('invalid first and n parameters for ObjStm stream');
  54333. }
  54334. var parser = new Parser(new Lexer(stream), false, this);
  54335. parser.allowStreams = true;
  54336. var i, entries = [], num, nums = [];
  54337. // read the object numbers to populate cache
  54338. for (i = 0; i < n; ++i) {
  54339. num = parser.getObj();
  54340. if (!isInt(num)) {
  54341. error('invalid object number in the ObjStm stream: ' + num);
  54342. }
  54343. nums.push(num);
  54344. var offset = parser.getObj();
  54345. if (!isInt(offset)) {
  54346. error('invalid object offset in the ObjStm stream: ' + offset);
  54347. }
  54348. }
  54349. // read stream objects for cache
  54350. for (i = 0; i < n; ++i) {
  54351. entries.push(parser.getObj());
  54352. // The ObjStm should not contain 'endobj'. If it's present, skip over it
  54353. // to support corrupt PDFs (fixes issue 5241, bug 898610, bug 1037816).
  54354. if (isCmd(parser.buf1, 'endobj')) {
  54355. parser.shift();
  54356. }
  54357. num = nums[i];
  54358. var entry = this.entries[num];
  54359. if (entry && entry.offset === tableOffset && entry.gen === i) {
  54360. this.cache[num] = entries[i];
  54361. }
  54362. }
  54363. xrefEntry = entries[xrefEntry.gen];
  54364. if (xrefEntry === undefined) {
  54365. error('bad XRef entry for compressed object');
  54366. }
  54367. return xrefEntry;
  54368. },
  54369. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj, suppressEncryption) {
  54370. if (!isRef(obj)) {
  54371. return Promise.resolve(obj);
  54372. }
  54373. return this.fetchAsync(obj, suppressEncryption);
  54374. },
  54375. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  54376. var streamManager = this.stream.manager;
  54377. var xref = this;
  54378. return new Promise(function tryFetch(resolve, reject) {
  54379. try {
  54380. resolve(xref.fetch(ref, suppressEncryption));
  54381. } catch (e) {
  54382. if (e instanceof MissingDataException) {
  54383. streamManager.requestRange(e.begin, e.end).then(function () {
  54384. tryFetch(resolve, reject);
  54385. }, reject);
  54386. return;
  54387. }
  54388. reject(e);
  54389. }
  54390. });
  54391. },
  54392. getCatalogObj: function XRef_getCatalogObj() {
  54393. return this.root;
  54394. }
  54395. };
  54396. return XRef;
  54397. }();
  54398. /**
  54399. * A NameTree/NumberTree is like a Dict but has some advantageous properties,
  54400. * see the specification (7.9.6 and 7.9.7) for additional details.
  54401. * TODO: implement all the Dict functions and make this more efficient.
  54402. */
  54403. var NameOrNumberTree = function NameOrNumberTreeClosure() {
  54404. function NameOrNumberTree(root, xref) {
  54405. throw new Error('Cannot initialize NameOrNumberTree.');
  54406. }
  54407. NameOrNumberTree.prototype = {
  54408. getAll: function NameOrNumberTree_getAll() {
  54409. var dict = Object.create(null);
  54410. if (!this.root) {
  54411. return dict;
  54412. }
  54413. var xref = this.xref;
  54414. // Reading Name/Number tree.
  54415. var processed = new RefSet();
  54416. processed.put(this.root);
  54417. var queue = [this.root];
  54418. while (queue.length > 0) {
  54419. var i, n;
  54420. var obj = xref.fetchIfRef(queue.shift());
  54421. if (!isDict(obj)) {
  54422. continue;
  54423. }
  54424. if (obj.has('Kids')) {
  54425. var kids = obj.get('Kids');
  54426. for (i = 0, n = kids.length; i < n; i++) {
  54427. var kid = kids[i];
  54428. assert(!processed.has(kid), 'Duplicate entry in "' + this._type + '" tree.');
  54429. queue.push(kid);
  54430. processed.put(kid);
  54431. }
  54432. continue;
  54433. }
  54434. var entries = obj.get(this._type);
  54435. if (isArray(entries)) {
  54436. for (i = 0, n = entries.length; i < n; i += 2) {
  54437. dict[xref.fetchIfRef(entries[i])] = xref.fetchIfRef(entries[i + 1]);
  54438. }
  54439. }
  54440. }
  54441. return dict;
  54442. },
  54443. get: function NameOrNumberTree_get(key) {
  54444. if (!this.root) {
  54445. return null;
  54446. }
  54447. var xref = this.xref;
  54448. var kidsOrEntries = xref.fetchIfRef(this.root);
  54449. var loopCount = 0;
  54450. var MAX_LEVELS = 10;
  54451. var l, r, m;
  54452. // Perform a binary search to quickly find the entry that
  54453. // contains the key we are looking for.
  54454. while (kidsOrEntries.has('Kids')) {
  54455. if (++loopCount > MAX_LEVELS) {
  54456. warn('Search depth limit reached for "' + this._type + '" tree.');
  54457. return null;
  54458. }
  54459. var kids = kidsOrEntries.get('Kids');
  54460. if (!isArray(kids)) {
  54461. return null;
  54462. }
  54463. l = 0;
  54464. r = kids.length - 1;
  54465. while (l <= r) {
  54466. m = l + r >> 1;
  54467. var kid = xref.fetchIfRef(kids[m]);
  54468. var limits = kid.get('Limits');
  54469. if (key < xref.fetchIfRef(limits[0])) {
  54470. r = m - 1;
  54471. } else if (key > xref.fetchIfRef(limits[1])) {
  54472. l = m + 1;
  54473. } else {
  54474. kidsOrEntries = xref.fetchIfRef(kids[m]);
  54475. break;
  54476. }
  54477. }
  54478. if (l > r) {
  54479. return null;
  54480. }
  54481. }
  54482. // If we get here, then we have found the right entry. Now go through the
  54483. // entries in the dictionary until we find the key we're looking for.
  54484. var entries = kidsOrEntries.get(this._type);
  54485. if (isArray(entries)) {
  54486. // Perform a binary search to reduce the lookup time.
  54487. l = 0;
  54488. r = entries.length - 2;
  54489. while (l <= r) {
  54490. // Check only even indices (0, 2, 4, ...) because the
  54491. // odd indices contain the actual data.
  54492. m = l + r & ~1;
  54493. var currentKey = xref.fetchIfRef(entries[m]);
  54494. if (key < currentKey) {
  54495. r = m - 2;
  54496. } else if (key > currentKey) {
  54497. l = m + 2;
  54498. } else {
  54499. return xref.fetchIfRef(entries[m + 1]);
  54500. }
  54501. }
  54502. }
  54503. return null;
  54504. }
  54505. };
  54506. return NameOrNumberTree;
  54507. }();
  54508. var NameTree = function NameTreeClosure() {
  54509. function NameTree(root, xref) {
  54510. this.root = root;
  54511. this.xref = xref;
  54512. this._type = 'Names';
  54513. }
  54514. Util.inherit(NameTree, NameOrNumberTree, {});
  54515. return NameTree;
  54516. }();
  54517. var NumberTree = function NumberTreeClosure() {
  54518. function NumberTree(root, xref) {
  54519. this.root = root;
  54520. this.xref = xref;
  54521. this._type = 'Nums';
  54522. }
  54523. Util.inherit(NumberTree, NameOrNumberTree, {});
  54524. return NumberTree;
  54525. }();
  54526. /**
  54527. * "A PDF file can refer to the contents of another file by using a File
  54528. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  54529. * NOTE: Only embedded files are supported (as part of the attachments support)
  54530. * TODO: support the 'URL' file system (with caching if !/V), portable
  54531. * collections attributes and related files (/RF)
  54532. */
  54533. var FileSpec = function FileSpecClosure() {
  54534. function FileSpec(root, xref) {
  54535. if (!root || !isDict(root)) {
  54536. return;
  54537. }
  54538. this.xref = xref;
  54539. this.root = root;
  54540. if (root.has('FS')) {
  54541. this.fs = root.get('FS');
  54542. }
  54543. this.description = root.has('Desc') ? stringToPDFString(root.get('Desc')) : '';
  54544. if (root.has('RF')) {
  54545. warn('Related file specifications are not supported');
  54546. }
  54547. this.contentAvailable = true;
  54548. if (!root.has('EF')) {
  54549. this.contentAvailable = false;
  54550. warn('Non-embedded file specifications are not supported');
  54551. }
  54552. }
  54553. function pickPlatformItem(dict) {
  54554. // Look for the filename in this order:
  54555. // UF, F, Unix, Mac, DOS
  54556. if (dict.has('UF')) {
  54557. return dict.get('UF');
  54558. } else if (dict.has('F')) {
  54559. return dict.get('F');
  54560. } else if (dict.has('Unix')) {
  54561. return dict.get('Unix');
  54562. } else if (dict.has('Mac')) {
  54563. return dict.get('Mac');
  54564. } else if (dict.has('DOS')) {
  54565. return dict.get('DOS');
  54566. } else {
  54567. return null;
  54568. }
  54569. }
  54570. FileSpec.prototype = {
  54571. get filename() {
  54572. if (!this._filename && this.root) {
  54573. var filename = pickPlatformItem(this.root) || 'unnamed';
  54574. this._filename = stringToPDFString(filename).replace(/\\\\/g, '\\').replace(/\\\//g, '/').replace(/\\/g, '/');
  54575. }
  54576. return this._filename;
  54577. },
  54578. get content() {
  54579. if (!this.contentAvailable) {
  54580. return null;
  54581. }
  54582. if (!this.contentRef && this.root) {
  54583. this.contentRef = pickPlatformItem(this.root.get('EF'));
  54584. }
  54585. var content = null;
  54586. if (this.contentRef) {
  54587. var xref = this.xref;
  54588. var fileObj = xref.fetchIfRef(this.contentRef);
  54589. if (fileObj && isStream(fileObj)) {
  54590. content = fileObj.getBytes();
  54591. } else {
  54592. warn('Embedded file specification points to non-existing/invalid ' + 'content');
  54593. }
  54594. } else {
  54595. warn('Embedded file specification does not have a content');
  54596. }
  54597. return content;
  54598. },
  54599. get serializable() {
  54600. return {
  54601. filename: this.filename,
  54602. content: this.content
  54603. };
  54604. }
  54605. };
  54606. return FileSpec;
  54607. }();
  54608. /**
  54609. * A helper for loading missing data in object graphs. It traverses the graph
  54610. * depth first and queues up any objects that have missing data. Once it has
  54611. * has traversed as many objects that are available it attempts to bundle the
  54612. * missing data requests and then resume from the nodes that weren't ready.
  54613. *
  54614. * NOTE: It provides protection from circular references by keeping track of
  54615. * of loaded references. However, you must be careful not to load any graphs
  54616. * that have references to the catalog or other pages since that will cause the
  54617. * entire PDF document object graph to be traversed.
  54618. */
  54619. var ObjectLoader = function () {
  54620. function mayHaveChildren(value) {
  54621. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  54622. }
  54623. function addChildren(node, nodesToVisit) {
  54624. var value;
  54625. if (isDict(node) || isStream(node)) {
  54626. var map;
  54627. if (isDict(node)) {
  54628. map = node.map;
  54629. } else {
  54630. map = node.dict.map;
  54631. }
  54632. for (var key in map) {
  54633. value = map[key];
  54634. if (mayHaveChildren(value)) {
  54635. nodesToVisit.push(value);
  54636. }
  54637. }
  54638. } else if (isArray(node)) {
  54639. for (var i = 0, ii = node.length; i < ii; i++) {
  54640. value = node[i];
  54641. if (mayHaveChildren(value)) {
  54642. nodesToVisit.push(value);
  54643. }
  54644. }
  54645. }
  54646. }
  54647. function ObjectLoader(obj, keys, xref) {
  54648. this.obj = obj;
  54649. this.keys = keys;
  54650. this.xref = xref;
  54651. this.refSet = null;
  54652. this.capability = null;
  54653. }
  54654. ObjectLoader.prototype = {
  54655. load: function ObjectLoader_load() {
  54656. var keys = this.keys;
  54657. this.capability = createPromiseCapability();
  54658. // Don't walk the graph if all the data is already loaded.
  54659. if (!(this.xref.stream instanceof ChunkedStream) || this.xref.stream.getMissingChunks().length === 0) {
  54660. this.capability.resolve();
  54661. return this.capability.promise;
  54662. }
  54663. this.refSet = new RefSet();
  54664. // Setup the initial nodes to visit.
  54665. var nodesToVisit = [];
  54666. for (var i = 0; i < keys.length; i++) {
  54667. nodesToVisit.push(this.obj[keys[i]]);
  54668. }
  54669. this._walk(nodesToVisit);
  54670. return this.capability.promise;
  54671. },
  54672. _walk: function ObjectLoader_walk(nodesToVisit) {
  54673. var nodesToRevisit = [];
  54674. var pendingRequests = [];
  54675. // DFS walk of the object graph.
  54676. while (nodesToVisit.length) {
  54677. var currentNode = nodesToVisit.pop();
  54678. // Only references or chunked streams can cause missing data exceptions.
  54679. if (isRef(currentNode)) {
  54680. // Skip nodes that have already been visited.
  54681. if (this.refSet.has(currentNode)) {
  54682. continue;
  54683. }
  54684. try {
  54685. var ref = currentNode;
  54686. this.refSet.put(ref);
  54687. currentNode = this.xref.fetch(currentNode);
  54688. } catch (e) {
  54689. if (!(e instanceof MissingDataException)) {
  54690. throw e;
  54691. }
  54692. nodesToRevisit.push(currentNode);
  54693. pendingRequests.push({
  54694. begin: e.begin,
  54695. end: e.end
  54696. });
  54697. }
  54698. }
  54699. if (currentNode && currentNode.getBaseStreams) {
  54700. var baseStreams = currentNode.getBaseStreams();
  54701. var foundMissingData = false;
  54702. for (var i = 0; i < baseStreams.length; i++) {
  54703. var stream = baseStreams[i];
  54704. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  54705. foundMissingData = true;
  54706. pendingRequests.push({
  54707. begin: stream.start,
  54708. end: stream.end
  54709. });
  54710. }
  54711. }
  54712. if (foundMissingData) {
  54713. nodesToRevisit.push(currentNode);
  54714. }
  54715. }
  54716. addChildren(currentNode, nodesToVisit);
  54717. }
  54718. if (pendingRequests.length) {
  54719. this.xref.stream.manager.requestRanges(pendingRequests).then(function pendingRequestCallback() {
  54720. nodesToVisit = nodesToRevisit;
  54721. for (var i = 0; i < nodesToRevisit.length; i++) {
  54722. var node = nodesToRevisit[i];
  54723. // Remove any reference nodes from the currrent refset so they
  54724. // aren't skipped when we revist them.
  54725. if (isRef(node)) {
  54726. this.refSet.remove(node);
  54727. }
  54728. }
  54729. this._walk(nodesToVisit);
  54730. }.bind(this), this.capability.reject);
  54731. return;
  54732. }
  54733. // Everything is loaded.
  54734. this.refSet = null;
  54735. this.capability.resolve();
  54736. }
  54737. };
  54738. return ObjectLoader;
  54739. }();
  54740. exports.Catalog = Catalog;
  54741. exports.ObjectLoader = ObjectLoader;
  54742. exports.XRef = XRef;
  54743. exports.FileSpec = FileSpec;
  54744. }));
  54745. (function (root, factory) {
  54746. factory(root.pdfjsCorePattern = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreFunction, root.pdfjsCoreColorSpace);
  54747. }(this, function (exports, sharedUtil, corePrimitives, coreFunction, coreColorSpace) {
  54748. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  54749. var MissingDataException = sharedUtil.MissingDataException;
  54750. var Util = sharedUtil.Util;
  54751. var assert = sharedUtil.assert;
  54752. var error = sharedUtil.error;
  54753. var info = sharedUtil.info;
  54754. var warn = sharedUtil.warn;
  54755. var isStream = corePrimitives.isStream;
  54756. var PDFFunction = coreFunction.PDFFunction;
  54757. var ColorSpace = coreColorSpace.ColorSpace;
  54758. var ShadingType = {
  54759. FUNCTION_BASED: 1,
  54760. AXIAL: 2,
  54761. RADIAL: 3,
  54762. FREE_FORM_MESH: 4,
  54763. LATTICE_FORM_MESH: 5,
  54764. COONS_PATCH_MESH: 6,
  54765. TENSOR_PATCH_MESH: 7
  54766. };
  54767. var Pattern = function PatternClosure() {
  54768. // Constructor should define this.getPattern
  54769. function Pattern() {
  54770. error('should not call Pattern constructor');
  54771. }
  54772. Pattern.prototype = {
  54773. // Input: current Canvas context
  54774. // Output: the appropriate fillStyle or strokeStyle
  54775. getPattern: function Pattern_getPattern(ctx) {
  54776. error('Should not call Pattern.getStyle: ' + ctx);
  54777. }
  54778. };
  54779. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref, res, handler) {
  54780. var dict = isStream(shading) ? shading.dict : shading;
  54781. var type = dict.get('ShadingType');
  54782. try {
  54783. switch (type) {
  54784. case ShadingType.AXIAL:
  54785. case ShadingType.RADIAL:
  54786. // Both radial and axial shadings are handled by RadialAxial shading.
  54787. return new Shadings.RadialAxial(dict, matrix, xref, res);
  54788. case ShadingType.FREE_FORM_MESH:
  54789. case ShadingType.LATTICE_FORM_MESH:
  54790. case ShadingType.COONS_PATCH_MESH:
  54791. case ShadingType.TENSOR_PATCH_MESH:
  54792. return new Shadings.Mesh(shading, matrix, xref, res);
  54793. default:
  54794. throw new Error('Unsupported ShadingType: ' + type);
  54795. }
  54796. } catch (ex) {
  54797. if (ex instanceof MissingDataException) {
  54798. throw ex;
  54799. }
  54800. handler.send('UnsupportedFeature', { featureId: UNSUPPORTED_FEATURES.shadingPattern });
  54801. warn(ex);
  54802. return new Shadings.Dummy();
  54803. }
  54804. };
  54805. return Pattern;
  54806. }();
  54807. var Shadings = {};
  54808. // A small number to offset the first/last color stops so we can insert ones to
  54809. // support extend. Number.MIN_VALUE is too small and breaks the extend.
  54810. Shadings.SMALL_NUMBER = 1e-6;
  54811. // Radial and axial shading have very similar implementations
  54812. // If needed, the implementations can be broken into two classes
  54813. Shadings.RadialAxial = function RadialAxialClosure() {
  54814. function RadialAxial(dict, matrix, xref, res) {
  54815. this.matrix = matrix;
  54816. this.coordsArr = dict.getArray('Coords');
  54817. this.shadingType = dict.get('ShadingType');
  54818. this.type = 'Pattern';
  54819. var cs = dict.get('ColorSpace', 'CS');
  54820. cs = ColorSpace.parse(cs, xref, res);
  54821. this.cs = cs;
  54822. var t0 = 0.0, t1 = 1.0;
  54823. if (dict.has('Domain')) {
  54824. var domainArr = dict.getArray('Domain');
  54825. t0 = domainArr[0];
  54826. t1 = domainArr[1];
  54827. }
  54828. var extendStart = false, extendEnd = false;
  54829. if (dict.has('Extend')) {
  54830. var extendArr = dict.getArray('Extend');
  54831. extendStart = extendArr[0];
  54832. extendEnd = extendArr[1];
  54833. }
  54834. if (this.shadingType === ShadingType.RADIAL && (!extendStart || !extendEnd)) {
  54835. // Radial gradient only currently works if either circle is fully within
  54836. // the other circle.
  54837. var x1 = this.coordsArr[0];
  54838. var y1 = this.coordsArr[1];
  54839. var r1 = this.coordsArr[2];
  54840. var x2 = this.coordsArr[3];
  54841. var y2 = this.coordsArr[4];
  54842. var r2 = this.coordsArr[5];
  54843. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  54844. if (r1 <= r2 + distance && r2 <= r1 + distance) {
  54845. warn('Unsupported radial gradient.');
  54846. }
  54847. }
  54848. this.extendStart = extendStart;
  54849. this.extendEnd = extendEnd;
  54850. var fnObj = dict.get('Function');
  54851. var fn = PDFFunction.parseArray(xref, fnObj);
  54852. // 10 samples seems good enough for now, but probably won't work
  54853. // if there are sharp color changes. Ideally, we would implement
  54854. // the spec faithfully and add lossless optimizations.
  54855. var diff = t1 - t0;
  54856. var step = diff / 10;
  54857. var colorStops = this.colorStops = [];
  54858. // Protect against bad domains so we don't end up in an infinte loop below.
  54859. if (t0 >= t1 || step <= 0) {
  54860. // Acrobat doesn't seem to handle these cases so we'll ignore for
  54861. // now.
  54862. info('Bad shading domain.');
  54863. return;
  54864. }
  54865. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  54866. var rgbColor;
  54867. for (var i = t0; i <= t1; i += step) {
  54868. ratio[0] = i;
  54869. fn(ratio, 0, color, 0);
  54870. rgbColor = cs.getRgb(color, 0);
  54871. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  54872. colorStops.push([
  54873. (i - t0) / diff,
  54874. cssColor
  54875. ]);
  54876. }
  54877. var background = 'transparent';
  54878. if (dict.has('Background')) {
  54879. rgbColor = cs.getRgb(dict.get('Background'), 0);
  54880. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  54881. }
  54882. if (!extendStart) {
  54883. // Insert a color stop at the front and offset the first real color stop
  54884. // so it doesn't conflict with the one we insert.
  54885. colorStops.unshift([
  54886. 0,
  54887. background
  54888. ]);
  54889. colorStops[1][0] += Shadings.SMALL_NUMBER;
  54890. }
  54891. if (!extendEnd) {
  54892. // Same idea as above in extendStart but for the end.
  54893. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  54894. colorStops.push([
  54895. 1,
  54896. background
  54897. ]);
  54898. }
  54899. this.colorStops = colorStops;
  54900. }
  54901. RadialAxial.prototype = {
  54902. getIR: function RadialAxial_getIR() {
  54903. var coordsArr = this.coordsArr;
  54904. var shadingType = this.shadingType;
  54905. var type, p0, p1, r0, r1;
  54906. if (shadingType === ShadingType.AXIAL) {
  54907. p0 = [
  54908. coordsArr[0],
  54909. coordsArr[1]
  54910. ];
  54911. p1 = [
  54912. coordsArr[2],
  54913. coordsArr[3]
  54914. ];
  54915. r0 = null;
  54916. r1 = null;
  54917. type = 'axial';
  54918. } else if (shadingType === ShadingType.RADIAL) {
  54919. p0 = [
  54920. coordsArr[0],
  54921. coordsArr[1]
  54922. ];
  54923. p1 = [
  54924. coordsArr[3],
  54925. coordsArr[4]
  54926. ];
  54927. r0 = coordsArr[2];
  54928. r1 = coordsArr[5];
  54929. type = 'radial';
  54930. } else {
  54931. error('getPattern type unknown: ' + shadingType);
  54932. }
  54933. var matrix = this.matrix;
  54934. if (matrix) {
  54935. p0 = Util.applyTransform(p0, matrix);
  54936. p1 = Util.applyTransform(p1, matrix);
  54937. if (shadingType === ShadingType.RADIAL) {
  54938. var scale = Util.singularValueDecompose2dScale(matrix);
  54939. r0 *= scale[0];
  54940. r1 *= scale[1];
  54941. }
  54942. }
  54943. return [
  54944. 'RadialAxial',
  54945. type,
  54946. this.colorStops,
  54947. p0,
  54948. p1,
  54949. r0,
  54950. r1
  54951. ];
  54952. }
  54953. };
  54954. return RadialAxial;
  54955. }();
  54956. // All mesh shading. For now, they will be presented as set of the triangles
  54957. // to be drawn on the canvas and rgb color for each vertex.
  54958. Shadings.Mesh = function MeshClosure() {
  54959. function MeshStreamReader(stream, context) {
  54960. this.stream = stream;
  54961. this.context = context;
  54962. this.buffer = 0;
  54963. this.bufferLength = 0;
  54964. var numComps = context.numComps;
  54965. this.tmpCompsBuf = new Float32Array(numComps);
  54966. var csNumComps = context.colorSpace.numComps;
  54967. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) : this.tmpCompsBuf;
  54968. }
  54969. MeshStreamReader.prototype = {
  54970. get hasData() {
  54971. if (this.stream.end) {
  54972. return this.stream.pos < this.stream.end;
  54973. }
  54974. if (this.bufferLength > 0) {
  54975. return true;
  54976. }
  54977. var nextByte = this.stream.getByte();
  54978. if (nextByte < 0) {
  54979. return false;
  54980. }
  54981. this.buffer = nextByte;
  54982. this.bufferLength = 8;
  54983. return true;
  54984. },
  54985. readBits: function MeshStreamReader_readBits(n) {
  54986. var buffer = this.buffer;
  54987. var bufferLength = this.bufferLength;
  54988. if (n === 32) {
  54989. if (bufferLength === 0) {
  54990. return (this.stream.getByte() << 24 | this.stream.getByte() << 16 | this.stream.getByte() << 8 | this.stream.getByte()) >>> 0;
  54991. }
  54992. buffer = buffer << 24 | this.stream.getByte() << 16 | this.stream.getByte() << 8 | this.stream.getByte();
  54993. var nextByte = this.stream.getByte();
  54994. this.buffer = nextByte & (1 << bufferLength) - 1;
  54995. return (buffer << 8 - bufferLength | (nextByte & 0xFF) >> bufferLength) >>> 0;
  54996. }
  54997. if (n === 8 && bufferLength === 0) {
  54998. return this.stream.getByte();
  54999. }
  55000. while (bufferLength < n) {
  55001. buffer = buffer << 8 | this.stream.getByte();
  55002. bufferLength += 8;
  55003. }
  55004. bufferLength -= n;
  55005. this.bufferLength = bufferLength;
  55006. this.buffer = buffer & (1 << bufferLength) - 1;
  55007. return buffer >> bufferLength;
  55008. },
  55009. align: function MeshStreamReader_align() {
  55010. this.buffer = 0;
  55011. this.bufferLength = 0;
  55012. },
  55013. readFlag: function MeshStreamReader_readFlag() {
  55014. return this.readBits(this.context.bitsPerFlag);
  55015. },
  55016. readCoordinate: function MeshStreamReader_readCoordinate() {
  55017. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  55018. var xi = this.readBits(bitsPerCoordinate);
  55019. var yi = this.readBits(bitsPerCoordinate);
  55020. var decode = this.context.decode;
  55021. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) : 2.3283064365386963e-10;
  55022. // 2 ^ -32
  55023. return [
  55024. xi * scale * (decode[1] - decode[0]) + decode[0],
  55025. yi * scale * (decode[3] - decode[2]) + decode[2]
  55026. ];
  55027. },
  55028. readComponents: function MeshStreamReader_readComponents() {
  55029. var numComps = this.context.numComps;
  55030. var bitsPerComponent = this.context.bitsPerComponent;
  55031. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) : 2.3283064365386963e-10;
  55032. // 2 ^ -32
  55033. var decode = this.context.decode;
  55034. var components = this.tmpCompsBuf;
  55035. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  55036. var ci = this.readBits(bitsPerComponent);
  55037. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  55038. }
  55039. var color = this.tmpCsCompsBuf;
  55040. if (this.context.colorFn) {
  55041. this.context.colorFn(components, 0, color, 0);
  55042. }
  55043. return this.context.colorSpace.getRgb(color, 0);
  55044. }
  55045. };
  55046. function decodeType4Shading(mesh, reader) {
  55047. var coords = mesh.coords;
  55048. var colors = mesh.colors;
  55049. var operators = [];
  55050. var ps = [];
  55051. // not maintaining cs since that will match ps
  55052. var verticesLeft = 0;
  55053. // assuming we have all data to start a new triangle
  55054. while (reader.hasData) {
  55055. var f = reader.readFlag();
  55056. var coord = reader.readCoordinate();
  55057. var color = reader.readComponents();
  55058. if (verticesLeft === 0) {
  55059. // ignoring flags if we started a triangle
  55060. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  55061. switch (f) {
  55062. case 0:
  55063. verticesLeft = 3;
  55064. break;
  55065. case 1:
  55066. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  55067. verticesLeft = 1;
  55068. break;
  55069. case 2:
  55070. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  55071. verticesLeft = 1;
  55072. break;
  55073. }
  55074. operators.push(f);
  55075. }
  55076. ps.push(coords.length);
  55077. coords.push(coord);
  55078. colors.push(color);
  55079. verticesLeft--;
  55080. reader.align();
  55081. }
  55082. mesh.figures.push({
  55083. type: 'triangles',
  55084. coords: new Int32Array(ps),
  55085. colors: new Int32Array(ps)
  55086. });
  55087. }
  55088. function decodeType5Shading(mesh, reader, verticesPerRow) {
  55089. var coords = mesh.coords;
  55090. var colors = mesh.colors;
  55091. var ps = [];
  55092. // not maintaining cs since that will match ps
  55093. while (reader.hasData) {
  55094. var coord = reader.readCoordinate();
  55095. var color = reader.readComponents();
  55096. ps.push(coords.length);
  55097. coords.push(coord);
  55098. colors.push(color);
  55099. }
  55100. mesh.figures.push({
  55101. type: 'lattice',
  55102. coords: new Int32Array(ps),
  55103. colors: new Int32Array(ps),
  55104. verticesPerRow: verticesPerRow
  55105. });
  55106. }
  55107. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  55108. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  55109. var TRIANGLE_DENSITY = 20;
  55110. // count of triangles per entire mesh bounds
  55111. var getB = function getBClosure() {
  55112. function buildB(count) {
  55113. var lut = [];
  55114. for (var i = 0; i <= count; i++) {
  55115. var t = i / count, t_ = 1 - t;
  55116. lut.push(new Float32Array([
  55117. t_ * t_ * t_,
  55118. 3 * t * t_ * t_,
  55119. 3 * t * t * t_,
  55120. t * t * t
  55121. ]));
  55122. }
  55123. return lut;
  55124. }
  55125. var cache = [];
  55126. return function getB(count) {
  55127. if (!cache[count]) {
  55128. cache[count] = buildB(count);
  55129. }
  55130. return cache[count];
  55131. };
  55132. }();
  55133. function buildFigureFromPatch(mesh, index) {
  55134. var figure = mesh.figures[index];
  55135. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  55136. var coords = mesh.coords, colors = mesh.colors;
  55137. var pi = figure.coords;
  55138. var ci = figure.colors;
  55139. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0], coords[pi[12]][0], coords[pi[15]][0]);
  55140. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1], coords[pi[12]][1], coords[pi[15]][1]);
  55141. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0], coords[pi[12]][0], coords[pi[15]][0]);
  55142. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1], coords[pi[12]][1], coords[pi[15]][1]);
  55143. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY / (mesh.bounds[2] - mesh.bounds[0]));
  55144. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT, Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  55145. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY / (mesh.bounds[3] - mesh.bounds[1]));
  55146. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT, Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  55147. var verticesPerRow = splitXBy + 1;
  55148. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  55149. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  55150. var k = 0;
  55151. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  55152. var c0 = colors[ci[0]], c1 = colors[ci[1]], c2 = colors[ci[2]], c3 = colors[ci[3]];
  55153. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  55154. for (var row = 0; row <= splitYBy; row++) {
  55155. cl[0] = (c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy | 0;
  55156. cl[1] = (c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy | 0;
  55157. cl[2] = (c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy | 0;
  55158. cr[0] = (c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy | 0;
  55159. cr[1] = (c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy | 0;
  55160. cr[2] = (c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy | 0;
  55161. for (var col = 0; col <= splitXBy; col++, k++) {
  55162. if ((row === 0 || row === splitYBy) && (col === 0 || col === splitXBy)) {
  55163. continue;
  55164. }
  55165. var x = 0, y = 0;
  55166. var q = 0;
  55167. for (var i = 0; i <= 3; i++) {
  55168. for (var j = 0; j <= 3; j++, q++) {
  55169. var m = bRow[row][i] * bCol[col][j];
  55170. x += coords[pi[q]][0] * m;
  55171. y += coords[pi[q]][1] * m;
  55172. }
  55173. }
  55174. figureCoords[k] = coords.length;
  55175. coords.push([
  55176. x,
  55177. y
  55178. ]);
  55179. figureColors[k] = colors.length;
  55180. var newColor = new Uint8Array(3);
  55181. newColor[0] = (cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy | 0;
  55182. newColor[1] = (cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy | 0;
  55183. newColor[2] = (cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy | 0;
  55184. colors.push(newColor);
  55185. }
  55186. }
  55187. figureCoords[0] = pi[0];
  55188. figureColors[0] = ci[0];
  55189. figureCoords[splitXBy] = pi[3];
  55190. figureColors[splitXBy] = ci[1];
  55191. figureCoords[verticesPerRow * splitYBy] = pi[12];
  55192. figureColors[verticesPerRow * splitYBy] = ci[2];
  55193. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  55194. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  55195. mesh.figures[index] = {
  55196. type: 'lattice',
  55197. coords: figureCoords,
  55198. colors: figureColors,
  55199. verticesPerRow: verticesPerRow
  55200. };
  55201. }
  55202. function decodeType6Shading(mesh, reader) {
  55203. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  55204. var coords = mesh.coords;
  55205. var colors = mesh.colors;
  55206. var ps = new Int32Array(16);
  55207. // p00, p10, ..., p30, p01, ..., p33
  55208. var cs = new Int32Array(4);
  55209. // c00, c30, c03, c33
  55210. while (reader.hasData) {
  55211. var f = reader.readFlag();
  55212. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  55213. var i, ii;
  55214. var pi = coords.length;
  55215. for (i = 0, ii = f !== 0 ? 8 : 12; i < ii; i++) {
  55216. coords.push(reader.readCoordinate());
  55217. }
  55218. var ci = colors.length;
  55219. for (i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
  55220. colors.push(reader.readComponents());
  55221. }
  55222. var tmp1, tmp2, tmp3, tmp4;
  55223. switch (f) {
  55224. case 0:
  55225. ps[12] = pi + 3;
  55226. ps[13] = pi + 4;
  55227. ps[14] = pi + 5;
  55228. ps[15] = pi + 6;
  55229. ps[8] = pi + 2;
  55230. /* values for 5, 6, 9, 10 are */
  55231. ps[11] = pi + 7;
  55232. ps[4] = pi + 1;
  55233. /* calculated below */
  55234. ps[7] = pi + 8;
  55235. ps[0] = pi;
  55236. ps[1] = pi + 11;
  55237. ps[2] = pi + 10;
  55238. ps[3] = pi + 9;
  55239. cs[2] = ci + 1;
  55240. cs[3] = ci + 2;
  55241. cs[0] = ci;
  55242. cs[1] = ci + 3;
  55243. break;
  55244. case 1:
  55245. tmp1 = ps[12];
  55246. tmp2 = ps[13];
  55247. tmp3 = ps[14];
  55248. tmp4 = ps[15];
  55249. ps[12] = tmp4;
  55250. ps[13] = pi + 0;
  55251. ps[14] = pi + 1;
  55252. ps[15] = pi + 2;
  55253. ps[8] = tmp3;
  55254. /* values for 5, 6, 9, 10 are */
  55255. ps[11] = pi + 3;
  55256. ps[4] = tmp2;
  55257. /* calculated below */
  55258. ps[7] = pi + 4;
  55259. ps[0] = tmp1;
  55260. ps[1] = pi + 7;
  55261. ps[2] = pi + 6;
  55262. ps[3] = pi + 5;
  55263. tmp1 = cs[2];
  55264. tmp2 = cs[3];
  55265. cs[2] = tmp2;
  55266. cs[3] = ci;
  55267. cs[0] = tmp1;
  55268. cs[1] = ci + 1;
  55269. break;
  55270. case 2:
  55271. tmp1 = ps[15];
  55272. tmp2 = ps[11];
  55273. ps[12] = ps[3];
  55274. ps[13] = pi + 0;
  55275. ps[14] = pi + 1;
  55276. ps[15] = pi + 2;
  55277. ps[8] = ps[7];
  55278. /* values for 5, 6, 9, 10 are */
  55279. ps[11] = pi + 3;
  55280. ps[4] = tmp2;
  55281. /* calculated below */
  55282. ps[7] = pi + 4;
  55283. ps[0] = tmp1;
  55284. ps[1] = pi + 7;
  55285. ps[2] = pi + 6;
  55286. ps[3] = pi + 5;
  55287. tmp1 = cs[3];
  55288. cs[2] = cs[1];
  55289. cs[3] = ci;
  55290. cs[0] = tmp1;
  55291. cs[1] = ci + 1;
  55292. break;
  55293. case 3:
  55294. ps[12] = ps[0];
  55295. ps[13] = pi + 0;
  55296. ps[14] = pi + 1;
  55297. ps[15] = pi + 2;
  55298. ps[8] = ps[1];
  55299. /* values for 5, 6, 9, 10 are */
  55300. ps[11] = pi + 3;
  55301. ps[4] = ps[2];
  55302. /* calculated below */
  55303. ps[7] = pi + 4;
  55304. ps[0] = ps[3];
  55305. ps[1] = pi + 7;
  55306. ps[2] = pi + 6;
  55307. ps[3] = pi + 5;
  55308. cs[2] = cs[0];
  55309. cs[3] = ci;
  55310. cs[0] = cs[1];
  55311. cs[1] = ci + 1;
  55312. break;
  55313. }
  55314. // set p11, p12, p21, p22
  55315. ps[5] = coords.length;
  55316. coords.push([
  55317. (-4 * coords[ps[0]][0] - coords[ps[15]][0] + 6 * (coords[ps[4]][0] + coords[ps[1]][0]) - 2 * (coords[ps[12]][0] + coords[ps[3]][0]) + 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  55318. (-4 * coords[ps[0]][1] - coords[ps[15]][1] + 6 * (coords[ps[4]][1] + coords[ps[1]][1]) - 2 * (coords[ps[12]][1] + coords[ps[3]][1]) + 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  55319. ]);
  55320. ps[6] = coords.length;
  55321. coords.push([
  55322. (-4 * coords[ps[3]][0] - coords[ps[12]][0] + 6 * (coords[ps[2]][0] + coords[ps[7]][0]) - 2 * (coords[ps[0]][0] + coords[ps[15]][0]) + 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  55323. (-4 * coords[ps[3]][1] - coords[ps[12]][1] + 6 * (coords[ps[2]][1] + coords[ps[7]][1]) - 2 * (coords[ps[0]][1] + coords[ps[15]][1]) + 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  55324. ]);
  55325. ps[9] = coords.length;
  55326. coords.push([
  55327. (-4 * coords[ps[12]][0] - coords[ps[3]][0] + 6 * (coords[ps[8]][0] + coords[ps[13]][0]) - 2 * (coords[ps[0]][0] + coords[ps[15]][0]) + 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  55328. (-4 * coords[ps[12]][1] - coords[ps[3]][1] + 6 * (coords[ps[8]][1] + coords[ps[13]][1]) - 2 * (coords[ps[0]][1] + coords[ps[15]][1]) + 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  55329. ]);
  55330. ps[10] = coords.length;
  55331. coords.push([
  55332. (-4 * coords[ps[15]][0] - coords[ps[0]][0] + 6 * (coords[ps[11]][0] + coords[ps[14]][0]) - 2 * (coords[ps[12]][0] + coords[ps[3]][0]) + 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  55333. (-4 * coords[ps[15]][1] - coords[ps[0]][1] + 6 * (coords[ps[11]][1] + coords[ps[14]][1]) - 2 * (coords[ps[12]][1] + coords[ps[3]][1]) + 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  55334. ]);
  55335. mesh.figures.push({
  55336. type: 'patch',
  55337. coords: new Int32Array(ps),
  55338. // making copies of ps and cs
  55339. colors: new Int32Array(cs)
  55340. });
  55341. }
  55342. }
  55343. function decodeType7Shading(mesh, reader) {
  55344. var coords = mesh.coords;
  55345. var colors = mesh.colors;
  55346. var ps = new Int32Array(16);
  55347. // p00, p10, ..., p30, p01, ..., p33
  55348. var cs = new Int32Array(4);
  55349. // c00, c30, c03, c33
  55350. while (reader.hasData) {
  55351. var f = reader.readFlag();
  55352. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  55353. var i, ii;
  55354. var pi = coords.length;
  55355. for (i = 0, ii = f !== 0 ? 12 : 16; i < ii; i++) {
  55356. coords.push(reader.readCoordinate());
  55357. }
  55358. var ci = colors.length;
  55359. for (i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
  55360. colors.push(reader.readComponents());
  55361. }
  55362. var tmp1, tmp2, tmp3, tmp4;
  55363. switch (f) {
  55364. case 0:
  55365. ps[12] = pi + 3;
  55366. ps[13] = pi + 4;
  55367. ps[14] = pi + 5;
  55368. ps[15] = pi + 6;
  55369. ps[8] = pi + 2;
  55370. ps[9] = pi + 13;
  55371. ps[10] = pi + 14;
  55372. ps[11] = pi + 7;
  55373. ps[4] = pi + 1;
  55374. ps[5] = pi + 12;
  55375. ps[6] = pi + 15;
  55376. ps[7] = pi + 8;
  55377. ps[0] = pi;
  55378. ps[1] = pi + 11;
  55379. ps[2] = pi + 10;
  55380. ps[3] = pi + 9;
  55381. cs[2] = ci + 1;
  55382. cs[3] = ci + 2;
  55383. cs[0] = ci;
  55384. cs[1] = ci + 3;
  55385. break;
  55386. case 1:
  55387. tmp1 = ps[12];
  55388. tmp2 = ps[13];
  55389. tmp3 = ps[14];
  55390. tmp4 = ps[15];
  55391. ps[12] = tmp4;
  55392. ps[13] = pi + 0;
  55393. ps[14] = pi + 1;
  55394. ps[15] = pi + 2;
  55395. ps[8] = tmp3;
  55396. ps[9] = pi + 9;
  55397. ps[10] = pi + 10;
  55398. ps[11] = pi + 3;
  55399. ps[4] = tmp2;
  55400. ps[5] = pi + 8;
  55401. ps[6] = pi + 11;
  55402. ps[7] = pi + 4;
  55403. ps[0] = tmp1;
  55404. ps[1] = pi + 7;
  55405. ps[2] = pi + 6;
  55406. ps[3] = pi + 5;
  55407. tmp1 = cs[2];
  55408. tmp2 = cs[3];
  55409. cs[2] = tmp2;
  55410. cs[3] = ci;
  55411. cs[0] = tmp1;
  55412. cs[1] = ci + 1;
  55413. break;
  55414. case 2:
  55415. tmp1 = ps[15];
  55416. tmp2 = ps[11];
  55417. ps[12] = ps[3];
  55418. ps[13] = pi + 0;
  55419. ps[14] = pi + 1;
  55420. ps[15] = pi + 2;
  55421. ps[8] = ps[7];
  55422. ps[9] = pi + 9;
  55423. ps[10] = pi + 10;
  55424. ps[11] = pi + 3;
  55425. ps[4] = tmp2;
  55426. ps[5] = pi + 8;
  55427. ps[6] = pi + 11;
  55428. ps[7] = pi + 4;
  55429. ps[0] = tmp1;
  55430. ps[1] = pi + 7;
  55431. ps[2] = pi + 6;
  55432. ps[3] = pi + 5;
  55433. tmp1 = cs[3];
  55434. cs[2] = cs[1];
  55435. cs[3] = ci;
  55436. cs[0] = tmp1;
  55437. cs[1] = ci + 1;
  55438. break;
  55439. case 3:
  55440. ps[12] = ps[0];
  55441. ps[13] = pi + 0;
  55442. ps[14] = pi + 1;
  55443. ps[15] = pi + 2;
  55444. ps[8] = ps[1];
  55445. ps[9] = pi + 9;
  55446. ps[10] = pi + 10;
  55447. ps[11] = pi + 3;
  55448. ps[4] = ps[2];
  55449. ps[5] = pi + 8;
  55450. ps[6] = pi + 11;
  55451. ps[7] = pi + 4;
  55452. ps[0] = ps[3];
  55453. ps[1] = pi + 7;
  55454. ps[2] = pi + 6;
  55455. ps[3] = pi + 5;
  55456. cs[2] = cs[0];
  55457. cs[3] = ci;
  55458. cs[0] = cs[1];
  55459. cs[1] = ci + 1;
  55460. break;
  55461. }
  55462. mesh.figures.push({
  55463. type: 'patch',
  55464. coords: new Int32Array(ps),
  55465. // making copies of ps and cs
  55466. colors: new Int32Array(cs)
  55467. });
  55468. }
  55469. }
  55470. function updateBounds(mesh) {
  55471. var minX = mesh.coords[0][0], minY = mesh.coords[0][1], maxX = minX, maxY = minY;
  55472. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  55473. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  55474. minX = minX > x ? x : minX;
  55475. minY = minY > y ? y : minY;
  55476. maxX = maxX < x ? x : maxX;
  55477. maxY = maxY < y ? y : maxY;
  55478. }
  55479. mesh.bounds = [
  55480. minX,
  55481. minY,
  55482. maxX,
  55483. maxY
  55484. ];
  55485. }
  55486. function packData(mesh) {
  55487. var i, ii, j, jj;
  55488. var coords = mesh.coords;
  55489. var coordsPacked = new Float32Array(coords.length * 2);
  55490. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  55491. var xy = coords[i];
  55492. coordsPacked[j++] = xy[0];
  55493. coordsPacked[j++] = xy[1];
  55494. }
  55495. mesh.coords = coordsPacked;
  55496. var colors = mesh.colors;
  55497. var colorsPacked = new Uint8Array(colors.length * 3);
  55498. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  55499. var c = colors[i];
  55500. colorsPacked[j++] = c[0];
  55501. colorsPacked[j++] = c[1];
  55502. colorsPacked[j++] = c[2];
  55503. }
  55504. mesh.colors = colorsPacked;
  55505. var figures = mesh.figures;
  55506. for (i = 0, ii = figures.length; i < ii; i++) {
  55507. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  55508. for (j = 0, jj = ps.length; j < jj; j++) {
  55509. ps[j] *= 2;
  55510. cs[j] *= 3;
  55511. }
  55512. }
  55513. }
  55514. function Mesh(stream, matrix, xref, res) {
  55515. assert(isStream(stream), 'Mesh data is not a stream');
  55516. var dict = stream.dict;
  55517. this.matrix = matrix;
  55518. this.shadingType = dict.get('ShadingType');
  55519. this.type = 'Pattern';
  55520. this.bbox = dict.getArray('BBox');
  55521. var cs = dict.get('ColorSpace', 'CS');
  55522. cs = ColorSpace.parse(cs, xref, res);
  55523. this.cs = cs;
  55524. this.background = dict.has('Background') ? cs.getRgb(dict.get('Background'), 0) : null;
  55525. var fnObj = dict.get('Function');
  55526. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  55527. this.coords = [];
  55528. this.colors = [];
  55529. this.figures = [];
  55530. var decodeContext = {
  55531. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  55532. bitsPerComponent: dict.get('BitsPerComponent'),
  55533. bitsPerFlag: dict.get('BitsPerFlag'),
  55534. decode: dict.getArray('Decode'),
  55535. colorFn: fn,
  55536. colorSpace: cs,
  55537. numComps: fn ? 1 : cs.numComps
  55538. };
  55539. var reader = new MeshStreamReader(stream, decodeContext);
  55540. var patchMesh = false;
  55541. switch (this.shadingType) {
  55542. case ShadingType.FREE_FORM_MESH:
  55543. decodeType4Shading(this, reader);
  55544. break;
  55545. case ShadingType.LATTICE_FORM_MESH:
  55546. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  55547. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  55548. decodeType5Shading(this, reader, verticesPerRow);
  55549. break;
  55550. case ShadingType.COONS_PATCH_MESH:
  55551. decodeType6Shading(this, reader);
  55552. patchMesh = true;
  55553. break;
  55554. case ShadingType.TENSOR_PATCH_MESH:
  55555. decodeType7Shading(this, reader);
  55556. patchMesh = true;
  55557. break;
  55558. default:
  55559. error('Unsupported mesh type.');
  55560. break;
  55561. }
  55562. if (patchMesh) {
  55563. // dirty bounds calculation for determining, how dense shall be triangles
  55564. updateBounds(this);
  55565. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  55566. buildFigureFromPatch(this, i);
  55567. }
  55568. }
  55569. // calculate bounds
  55570. updateBounds(this);
  55571. packData(this);
  55572. }
  55573. Mesh.prototype = {
  55574. getIR: function Mesh_getIR() {
  55575. return [
  55576. 'Mesh',
  55577. this.shadingType,
  55578. this.coords,
  55579. this.colors,
  55580. this.figures,
  55581. this.bounds,
  55582. this.matrix,
  55583. this.bbox,
  55584. this.background
  55585. ];
  55586. }
  55587. };
  55588. return Mesh;
  55589. }();
  55590. Shadings.Dummy = function DummyClosure() {
  55591. function Dummy() {
  55592. this.type = 'Pattern';
  55593. }
  55594. Dummy.prototype = {
  55595. getIR: function Dummy_getIR() {
  55596. return ['Dummy'];
  55597. }
  55598. };
  55599. return Dummy;
  55600. }();
  55601. function getTilingPatternIR(operatorList, dict, args) {
  55602. var matrix = dict.getArray('Matrix');
  55603. var bbox = dict.getArray('BBox');
  55604. var xstep = dict.get('XStep');
  55605. var ystep = dict.get('YStep');
  55606. var paintType = dict.get('PaintType');
  55607. var tilingType = dict.get('TilingType');
  55608. return [
  55609. 'TilingPattern',
  55610. args,
  55611. operatorList,
  55612. matrix,
  55613. bbox,
  55614. xstep,
  55615. ystep,
  55616. paintType,
  55617. tilingType
  55618. ];
  55619. }
  55620. exports.Pattern = Pattern;
  55621. exports.getTilingPatternIR = getTilingPatternIR;
  55622. }));
  55623. (function (root, factory) {
  55624. factory(root.pdfjsCoreEvaluator = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser, root.pdfjsCoreImage, root.pdfjsCoreColorSpace, root.pdfjsCoreMurmurHash3, root.pdfjsCoreFonts, root.pdfjsCoreFunction, root.pdfjsCorePattern, root.pdfjsCoreCMap, root.pdfjsCoreMetrics, root.pdfjsCoreBidi, root.pdfjsCoreEncodings, root.pdfjsCoreStandardFonts, root.pdfjsCoreUnicode, root.pdfjsCoreGlyphList);
  55625. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser, coreImage, coreColorSpace, coreMurmurHash3, coreFonts, coreFunction, corePattern, coreCMap, coreMetrics, coreBidi, coreEncodings, coreStandardFonts, coreUnicode, coreGlyphList) {
  55626. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  55627. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  55628. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  55629. var ImageKind = sharedUtil.ImageKind;
  55630. var OPS = sharedUtil.OPS;
  55631. var TextRenderingMode = sharedUtil.TextRenderingMode;
  55632. var Util = sharedUtil.Util;
  55633. var assert = sharedUtil.assert;
  55634. var createPromiseCapability = sharedUtil.createPromiseCapability;
  55635. var error = sharedUtil.error;
  55636. var info = sharedUtil.info;
  55637. var isArray = sharedUtil.isArray;
  55638. var isNum = sharedUtil.isNum;
  55639. var isString = sharedUtil.isString;
  55640. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  55641. var warn = sharedUtil.warn;
  55642. var Dict = corePrimitives.Dict;
  55643. var Name = corePrimitives.Name;
  55644. var isCmd = corePrimitives.isCmd;
  55645. var isDict = corePrimitives.isDict;
  55646. var isName = corePrimitives.isName;
  55647. var isRef = corePrimitives.isRef;
  55648. var isStream = corePrimitives.isStream;
  55649. var DecodeStream = coreStream.DecodeStream;
  55650. var JpegStream = coreStream.JpegStream;
  55651. var Stream = coreStream.Stream;
  55652. var Lexer = coreParser.Lexer;
  55653. var Parser = coreParser.Parser;
  55654. var isEOF = coreParser.isEOF;
  55655. var PDFImage = coreImage.PDFImage;
  55656. var ColorSpace = coreColorSpace.ColorSpace;
  55657. var MurmurHash3_64 = coreMurmurHash3.MurmurHash3_64;
  55658. var ErrorFont = coreFonts.ErrorFont;
  55659. var FontFlags = coreFonts.FontFlags;
  55660. var Font = coreFonts.Font;
  55661. var IdentityToUnicodeMap = coreFonts.IdentityToUnicodeMap;
  55662. var ToUnicodeMap = coreFonts.ToUnicodeMap;
  55663. var getFontType = coreFonts.getFontType;
  55664. var isPDFFunction = coreFunction.isPDFFunction;
  55665. var PDFFunction = coreFunction.PDFFunction;
  55666. var Pattern = corePattern.Pattern;
  55667. var getTilingPatternIR = corePattern.getTilingPatternIR;
  55668. var CMapFactory = coreCMap.CMapFactory;
  55669. var IdentityCMap = coreCMap.IdentityCMap;
  55670. var getMetrics = coreMetrics.getMetrics;
  55671. var bidi = coreBidi.bidi;
  55672. var WinAnsiEncoding = coreEncodings.WinAnsiEncoding;
  55673. var StandardEncoding = coreEncodings.StandardEncoding;
  55674. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  55675. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  55676. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  55677. var getEncoding = coreEncodings.getEncoding;
  55678. var getStdFontMap = coreStandardFonts.getStdFontMap;
  55679. var getSerifFonts = coreStandardFonts.getSerifFonts;
  55680. var getSymbolsFonts = coreStandardFonts.getSymbolsFonts;
  55681. var getNormalizedUnicodes = coreUnicode.getNormalizedUnicodes;
  55682. var reverseIfRtl = coreUnicode.reverseIfRtl;
  55683. var getUnicodeForGlyph = coreUnicode.getUnicodeForGlyph;
  55684. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  55685. var PartialEvaluator = function PartialEvaluatorClosure() {
  55686. var DefaultPartialEvaluatorOptions = {
  55687. forceDataSchema: false,
  55688. maxImageSize: -1,
  55689. disableFontFace: false,
  55690. cMapOptions: {
  55691. url: null,
  55692. packed: false
  55693. }
  55694. };
  55695. function NativeImageDecoder(xref, resources, handler, forceDataSchema) {
  55696. this.xref = xref;
  55697. this.resources = resources;
  55698. this.handler = handler;
  55699. this.forceDataSchema = forceDataSchema;
  55700. }
  55701. NativeImageDecoder.prototype = {
  55702. canDecode: function (image) {
  55703. return image instanceof JpegStream && NativeImageDecoder.isDecodable(image, this.xref, this.resources);
  55704. },
  55705. decode: function (image) {
  55706. // For natively supported JPEGs send them to the main thread for decoding.
  55707. var dict = image.dict;
  55708. var colorSpace = dict.get('ColorSpace', 'CS');
  55709. colorSpace = ColorSpace.parse(colorSpace, this.xref, this.resources);
  55710. var numComps = colorSpace.numComps;
  55711. var decodePromise = this.handler.sendWithPromise('JpegDecode', [
  55712. image.getIR(this.forceDataSchema),
  55713. numComps
  55714. ]);
  55715. return decodePromise.then(function (message) {
  55716. var data = message.data;
  55717. return new Stream(data, 0, data.length, image.dict);
  55718. });
  55719. }
  55720. };
  55721. /**
  55722. * Checks if the image can be decoded and displayed by the browser without any
  55723. * further processing such as color space conversions.
  55724. */
  55725. NativeImageDecoder.isSupported = function NativeImageDecoder_isSupported(image, xref, res) {
  55726. var dict = image.dict;
  55727. if (dict.has('DecodeParms') || dict.has('DP')) {
  55728. return false;
  55729. }
  55730. var cs = ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res);
  55731. return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') && cs.isDefaultDecode(dict.getArray('Decode', 'D'));
  55732. };
  55733. /**
  55734. * Checks if the image can be decoded by the browser.
  55735. */
  55736. NativeImageDecoder.isDecodable = function NativeImageDecoder_isDecodable(image, xref, res) {
  55737. var dict = image.dict;
  55738. if (dict.has('DecodeParms') || dict.has('DP')) {
  55739. return false;
  55740. }
  55741. var cs = ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res);
  55742. return (cs.numComps === 1 || cs.numComps === 3) && cs.isDefaultDecode(dict.getArray('Decode', 'D'));
  55743. };
  55744. function PartialEvaluator(pdfManager, xref, handler, pageIndex, uniquePrefix, idCounters, fontCache, options) {
  55745. this.pdfManager = pdfManager;
  55746. this.xref = xref;
  55747. this.handler = handler;
  55748. this.pageIndex = pageIndex;
  55749. this.uniquePrefix = uniquePrefix;
  55750. this.idCounters = idCounters;
  55751. this.fontCache = fontCache;
  55752. this.options = options || DefaultPartialEvaluatorOptions;
  55753. }
  55754. // Trying to minimize Date.now() usage and check every 100 time
  55755. var TIME_SLOT_DURATION_MS = 20;
  55756. var CHECK_TIME_EVERY = 100;
  55757. function TimeSlotManager() {
  55758. this.reset();
  55759. }
  55760. TimeSlotManager.prototype = {
  55761. check: function TimeSlotManager_check() {
  55762. if (++this.checked < CHECK_TIME_EVERY) {
  55763. return false;
  55764. }
  55765. this.checked = 0;
  55766. return this.endTime <= Date.now();
  55767. },
  55768. reset: function TimeSlotManager_reset() {
  55769. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  55770. this.checked = 0;
  55771. }
  55772. };
  55773. var deferred = Promise.resolve();
  55774. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  55775. PartialEvaluator.prototype = {
  55776. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  55777. if (!isDict(resources)) {
  55778. return false;
  55779. }
  55780. var processed = Object.create(null);
  55781. if (resources.objId) {
  55782. processed[resources.objId] = true;
  55783. }
  55784. var nodes = [resources], xref = this.xref;
  55785. while (nodes.length) {
  55786. var key, i, ii;
  55787. var node = nodes.shift();
  55788. // First check the current resources for blend modes.
  55789. var graphicStates = node.get('ExtGState');
  55790. if (isDict(graphicStates)) {
  55791. var graphicStatesKeys = graphicStates.getKeys();
  55792. for (i = 0, ii = graphicStatesKeys.length; i < ii; i++) {
  55793. key = graphicStatesKeys[i];
  55794. var graphicState = graphicStates.get(key);
  55795. var bm = graphicState.get('BM');
  55796. if (isName(bm) && bm.name !== 'Normal') {
  55797. return true;
  55798. }
  55799. }
  55800. }
  55801. // Descend into the XObjects to look for more resources and blend modes.
  55802. var xObjects = node.get('XObject');
  55803. if (!isDict(xObjects)) {
  55804. continue;
  55805. }
  55806. var xObjectsKeys = xObjects.getKeys();
  55807. for (i = 0, ii = xObjectsKeys.length; i < ii; i++) {
  55808. key = xObjectsKeys[i];
  55809. var xObject = xObjects.getRaw(key);
  55810. if (isRef(xObject)) {
  55811. if (processed[xObject.toString()]) {
  55812. // The XObject has already been processed, and by avoiding a
  55813. // redundant `xref.fetch` we can *significantly* reduce the load
  55814. // time for badly generated PDF files (fixes issue6961.pdf).
  55815. continue;
  55816. }
  55817. xObject = xref.fetch(xObject);
  55818. }
  55819. if (!isStream(xObject)) {
  55820. continue;
  55821. }
  55822. if (xObject.dict.objId) {
  55823. if (processed[xObject.dict.objId]) {
  55824. // stream has objId and is processed already
  55825. continue;
  55826. }
  55827. processed[xObject.dict.objId] = true;
  55828. }
  55829. var xResources = xObject.dict.get('Resources');
  55830. // Checking objId to detect an infinite loop.
  55831. if (isDict(xResources) && (!xResources.objId || !processed[xResources.objId])) {
  55832. nodes.push(xResources);
  55833. if (xResources.objId) {
  55834. processed[xResources.objId] = true;
  55835. }
  55836. }
  55837. }
  55838. }
  55839. return false;
  55840. },
  55841. buildFormXObject: function PartialEvaluator_buildFormXObject(resources, xobj, smask, operatorList, task, initialState) {
  55842. var matrix = xobj.dict.getArray('Matrix');
  55843. var bbox = xobj.dict.getArray('BBox');
  55844. var group = xobj.dict.get('Group');
  55845. if (group) {
  55846. var groupOptions = {
  55847. matrix: matrix,
  55848. bbox: bbox,
  55849. smask: smask,
  55850. isolated: false,
  55851. knockout: false
  55852. };
  55853. var groupSubtype = group.get('S');
  55854. var colorSpace;
  55855. if (isName(groupSubtype, 'Transparency')) {
  55856. groupOptions.isolated = group.get('I') || false;
  55857. groupOptions.knockout = group.get('K') || false;
  55858. colorSpace = group.has('CS') ? ColorSpace.parse(group.get('CS'), this.xref, resources) : null;
  55859. }
  55860. if (smask && smask.backdrop) {
  55861. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  55862. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  55863. }
  55864. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  55865. }
  55866. operatorList.addOp(OPS.paintFormXObjectBegin, [
  55867. matrix,
  55868. bbox
  55869. ]);
  55870. return this.getOperatorList(xobj, task, xobj.dict.get('Resources') || resources, operatorList, initialState).then(function () {
  55871. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  55872. if (group) {
  55873. operatorList.addOp(OPS.endGroup, [groupOptions]);
  55874. }
  55875. });
  55876. },
  55877. buildPaintImageXObject: function PartialEvaluator_buildPaintImageXObject(resources, image, inline, operatorList, cacheKey, imageCache) {
  55878. var self = this;
  55879. var dict = image.dict;
  55880. var w = dict.get('Width', 'W');
  55881. var h = dict.get('Height', 'H');
  55882. if (!(w && isNum(w)) || !(h && isNum(h))) {
  55883. warn('Image dimensions are missing, or not numbers.');
  55884. return;
  55885. }
  55886. var maxImageSize = this.options.maxImageSize;
  55887. if (maxImageSize !== -1 && w * h > maxImageSize) {
  55888. warn('Image exceeded maximum allowed size and was removed.');
  55889. return;
  55890. }
  55891. var imageMask = dict.get('ImageMask', 'IM') || false;
  55892. var imgData, args;
  55893. if (imageMask) {
  55894. // This depends on a tmpCanvas being filled with the
  55895. // current fillStyle, such that processing the pixel
  55896. // data can't be done here. Instead of creating a
  55897. // complete PDFImage, only read the information needed
  55898. // for later.
  55899. var width = dict.get('Width', 'W');
  55900. var height = dict.get('Height', 'H');
  55901. var bitStrideLength = width + 7 >> 3;
  55902. var imgArray = image.getBytes(bitStrideLength * height);
  55903. var decode = dict.getArray('Decode', 'D');
  55904. var inverseDecode = !!decode && decode[0] > 0;
  55905. imgData = PDFImage.createMask(imgArray, width, height, image instanceof DecodeStream, inverseDecode);
  55906. imgData.cached = true;
  55907. args = [imgData];
  55908. operatorList.addOp(OPS.paintImageMaskXObject, args);
  55909. if (cacheKey) {
  55910. imageCache[cacheKey] = {
  55911. fn: OPS.paintImageMaskXObject,
  55912. args: args
  55913. };
  55914. }
  55915. return;
  55916. }
  55917. var softMask = dict.get('SMask', 'SM') || false;
  55918. var mask = dict.get('Mask') || false;
  55919. var SMALL_IMAGE_DIMENSIONS = 200;
  55920. // Inlining small images into the queue as RGB data
  55921. if (inline && !softMask && !mask && !(image instanceof JpegStream) && w + h < SMALL_IMAGE_DIMENSIONS) {
  55922. var imageObj = new PDFImage(this.xref, resources, image, inline, null, null);
  55923. // We force the use of RGBA_32BPP images here, because we can't handle
  55924. // any other kind.
  55925. imgData = imageObj.createImageData(/* forceRGBA = */
  55926. true);
  55927. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  55928. return;
  55929. }
  55930. // If there is no imageMask, create the PDFImage and a lot
  55931. // of image processing can be done here.
  55932. var uniquePrefix = this.uniquePrefix || '';
  55933. var objId = 'img_' + uniquePrefix + ++this.idCounters.obj;
  55934. operatorList.addDependency(objId);
  55935. args = [
  55936. objId,
  55937. w,
  55938. h
  55939. ];
  55940. if (!softMask && !mask && image instanceof JpegStream && NativeImageDecoder.isSupported(image, this.xref, resources)) {
  55941. // These JPEGs don't need any more processing so we can just send it.
  55942. operatorList.addOp(OPS.paintJpegXObject, args);
  55943. this.handler.send('obj', [
  55944. objId,
  55945. this.pageIndex,
  55946. 'JpegStream',
  55947. image.getIR(this.options.forceDataSchema)
  55948. ]);
  55949. return;
  55950. }
  55951. // Creates native image decoder only if a JPEG image or mask is present.
  55952. var nativeImageDecoder = null;
  55953. if (image instanceof JpegStream || mask instanceof JpegStream || softMask instanceof JpegStream) {
  55954. nativeImageDecoder = new NativeImageDecoder(self.xref, resources, self.handler, self.options.forceDataSchema);
  55955. }
  55956. PDFImage.buildImage(self.handler, self.xref, resources, image, inline, nativeImageDecoder).then(function (imageObj) {
  55957. var imgData = imageObj.createImageData(/* forceRGBA = */
  55958. false);
  55959. self.handler.send('obj', [
  55960. objId,
  55961. self.pageIndex,
  55962. 'Image',
  55963. imgData
  55964. ], [imgData.data.buffer]);
  55965. }).then(undefined, function (reason) {
  55966. warn('Unable to decode image: ' + reason);
  55967. self.handler.send('obj', [
  55968. objId,
  55969. self.pageIndex,
  55970. 'Image',
  55971. null
  55972. ]);
  55973. });
  55974. operatorList.addOp(OPS.paintImageXObject, args);
  55975. if (cacheKey) {
  55976. imageCache[cacheKey] = {
  55977. fn: OPS.paintImageXObject,
  55978. args: args
  55979. };
  55980. }
  55981. },
  55982. handleSMask: function PartialEvaluator_handleSmask(smask, resources, operatorList, task, stateManager) {
  55983. var smaskContent = smask.get('G');
  55984. var smaskOptions = {
  55985. subtype: smask.get('S').name,
  55986. backdrop: smask.get('BC')
  55987. };
  55988. // The SMask might have a alpha/luminosity value transfer function --
  55989. // we will build a map of integer values in range 0..255 to be fast.
  55990. var transferObj = smask.get('TR');
  55991. if (isPDFFunction(transferObj)) {
  55992. var transferFn = PDFFunction.parse(this.xref, transferObj);
  55993. var transferMap = new Uint8Array(256);
  55994. var tmp = new Float32Array(1);
  55995. for (var i = 0; i < 256; i++) {
  55996. tmp[0] = i / 255;
  55997. transferFn(tmp, 0, tmp, 0);
  55998. transferMap[i] = tmp[0] * 255 | 0;
  55999. }
  56000. smaskOptions.transferMap = transferMap;
  56001. }
  56002. return this.buildFormXObject(resources, smaskContent, smaskOptions, operatorList, task, stateManager.state.clone());
  56003. },
  56004. handleTilingType: function PartialEvaluator_handleTilingType(fn, args, resources, pattern, patternDict, operatorList, task) {
  56005. // Create an IR of the pattern code.
  56006. var tilingOpList = new OperatorList();
  56007. // Merge the available resources, to prevent issues when the patternDict
  56008. // is missing some /Resources entries (fixes issue6541.pdf).
  56009. var resourcesArray = [
  56010. patternDict.get('Resources'),
  56011. resources
  56012. ];
  56013. var patternResources = Dict.merge(this.xref, resourcesArray);
  56014. return this.getOperatorList(pattern, task, patternResources, tilingOpList).then(function () {
  56015. // Add the dependencies to the parent operator list so they are
  56016. // resolved before sub operator list is executed synchronously.
  56017. operatorList.addDependencies(tilingOpList.dependencies);
  56018. operatorList.addOp(fn, getTilingPatternIR({
  56019. fnArray: tilingOpList.fnArray,
  56020. argsArray: tilingOpList.argsArray
  56021. }, patternDict, args));
  56022. });
  56023. },
  56024. handleSetFont: function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef, operatorList, task, state) {
  56025. // TODO(mack): Not needed?
  56026. var fontName;
  56027. if (fontArgs) {
  56028. fontArgs = fontArgs.slice();
  56029. fontName = fontArgs[0].name;
  56030. }
  56031. var self = this;
  56032. return this.loadFont(fontName, fontRef, this.xref, resources).then(function (translated) {
  56033. if (!translated.font.isType3Font) {
  56034. return translated;
  56035. }
  56036. return translated.loadType3Data(self, resources, operatorList, task).then(function () {
  56037. return translated;
  56038. }, function (reason) {
  56039. // Error in the font data -- sending unsupported feature notification.
  56040. self.handler.send('UnsupportedFeature', { featureId: UNSUPPORTED_FEATURES.font });
  56041. return new TranslatedFont('g_font_error', new ErrorFont('Type3 font load error: ' + reason), translated.font);
  56042. });
  56043. }).then(function (translated) {
  56044. state.font = translated.font;
  56045. translated.send(self.handler);
  56046. return translated.loadedName;
  56047. });
  56048. },
  56049. handleText: function PartialEvaluator_handleText(chars, state) {
  56050. var font = state.font;
  56051. var glyphs = font.charsToGlyphs(chars);
  56052. var isAddToPathSet = !!(state.textRenderingMode & TextRenderingMode.ADD_TO_PATH_FLAG);
  56053. if (font.data && (isAddToPathSet || this.options.disableFontFace)) {
  56054. var buildPath = function (fontChar) {
  56055. if (!font.renderer.hasBuiltPath(fontChar)) {
  56056. var path = font.renderer.getPathJs(fontChar);
  56057. this.handler.send('commonobj', [
  56058. font.loadedName + '_path_' + fontChar,
  56059. 'FontPath',
  56060. path
  56061. ]);
  56062. }
  56063. }.bind(this);
  56064. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  56065. var glyph = glyphs[i];
  56066. buildPath(glyph.fontChar);
  56067. // If the glyph has an accent we need to build a path for its
  56068. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  56069. var accent = glyph.accent;
  56070. if (accent && accent.fontChar) {
  56071. buildPath(accent.fontChar);
  56072. }
  56073. }
  56074. }
  56075. return glyphs;
  56076. },
  56077. setGState: function PartialEvaluator_setGState(resources, gState, operatorList, task, xref, stateManager) {
  56078. // This array holds the converted/processed state data.
  56079. var gStateObj = [];
  56080. var gStateKeys = gState.getKeys();
  56081. var self = this;
  56082. var promise = Promise.resolve();
  56083. for (var i = 0, ii = gStateKeys.length; i < ii; i++) {
  56084. var key = gStateKeys[i];
  56085. var value = gState.get(key);
  56086. switch (key) {
  56087. case 'Type':
  56088. break;
  56089. case 'LW':
  56090. case 'LC':
  56091. case 'LJ':
  56092. case 'ML':
  56093. case 'D':
  56094. case 'RI':
  56095. case 'FL':
  56096. case 'CA':
  56097. case 'ca':
  56098. gStateObj.push([
  56099. key,
  56100. value
  56101. ]);
  56102. break;
  56103. case 'Font':
  56104. promise = promise.then(function () {
  56105. return self.handleSetFont(resources, null, value[0], operatorList, task, stateManager.state).then(function (loadedName) {
  56106. operatorList.addDependency(loadedName);
  56107. gStateObj.push([
  56108. key,
  56109. [
  56110. loadedName,
  56111. value[1]
  56112. ]
  56113. ]);
  56114. });
  56115. });
  56116. break;
  56117. case 'BM':
  56118. gStateObj.push([
  56119. key,
  56120. value
  56121. ]);
  56122. break;
  56123. case 'SMask':
  56124. if (isName(value, 'None')) {
  56125. gStateObj.push([
  56126. key,
  56127. false
  56128. ]);
  56129. break;
  56130. }
  56131. if (isDict(value)) {
  56132. promise = promise.then(function (dict) {
  56133. return self.handleSMask(dict, resources, operatorList, task, stateManager);
  56134. }.bind(this, value));
  56135. gStateObj.push([
  56136. key,
  56137. true
  56138. ]);
  56139. } else {
  56140. warn('Unsupported SMask type');
  56141. }
  56142. break;
  56143. // Only generate info log messages for the following since
  56144. // they are unlikely to have a big impact on the rendering.
  56145. case 'OP':
  56146. case 'op':
  56147. case 'OPM':
  56148. case 'BG':
  56149. case 'BG2':
  56150. case 'UCR':
  56151. case 'UCR2':
  56152. case 'TR':
  56153. case 'TR2':
  56154. case 'HT':
  56155. case 'SM':
  56156. case 'SA':
  56157. case 'AIS':
  56158. case 'TK':
  56159. // TODO implement these operators.
  56160. info('graphic state operator ' + key);
  56161. break;
  56162. default:
  56163. info('Unknown graphic state operator ' + key);
  56164. break;
  56165. }
  56166. }
  56167. return promise.then(function () {
  56168. if (gStateObj.length > 0) {
  56169. operatorList.addOp(OPS.setGState, [gStateObj]);
  56170. }
  56171. });
  56172. },
  56173. loadFont: function PartialEvaluator_loadFont(fontName, font, xref, resources) {
  56174. function errorFont() {
  56175. return Promise.resolve(new TranslatedFont('g_font_error', new ErrorFont('Font ' + fontName + ' is not available'), font));
  56176. }
  56177. var fontRef;
  56178. if (font) {
  56179. // Loading by ref.
  56180. assert(isRef(font));
  56181. fontRef = font;
  56182. } else {
  56183. // Loading by name.
  56184. var fontRes = resources.get('Font');
  56185. if (fontRes) {
  56186. fontRef = fontRes.getRaw(fontName);
  56187. } else {
  56188. warn('fontRes not available');
  56189. return errorFont();
  56190. }
  56191. }
  56192. if (!fontRef) {
  56193. warn('fontRef not available');
  56194. return errorFont();
  56195. }
  56196. if (this.fontCache.has(fontRef)) {
  56197. return this.fontCache.get(fontRef);
  56198. }
  56199. font = xref.fetchIfRef(fontRef);
  56200. if (!isDict(font)) {
  56201. return errorFont();
  56202. }
  56203. // We are holding `font.translated` references just for `fontRef`s that
  56204. // are not actually `Ref`s, but rather `Dict`s. See explanation below.
  56205. if (font.translated) {
  56206. return font.translated;
  56207. }
  56208. var fontCapability = createPromiseCapability();
  56209. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  56210. var descriptor = preEvaluatedFont.descriptor;
  56211. var fontRefIsRef = isRef(fontRef), fontID;
  56212. if (fontRefIsRef) {
  56213. fontID = fontRef.toString();
  56214. }
  56215. if (isDict(descriptor)) {
  56216. if (!descriptor.fontAliases) {
  56217. descriptor.fontAliases = Object.create(null);
  56218. }
  56219. var fontAliases = descriptor.fontAliases;
  56220. var hash = preEvaluatedFont.hash;
  56221. if (fontAliases[hash]) {
  56222. var aliasFontRef = fontAliases[hash].aliasRef;
  56223. if (fontRefIsRef && aliasFontRef && this.fontCache.has(aliasFontRef)) {
  56224. this.fontCache.putAlias(fontRef, aliasFontRef);
  56225. return this.fontCache.get(fontRef);
  56226. }
  56227. } else {
  56228. fontAliases[hash] = { fontID: Font.getFontID() };
  56229. }
  56230. if (fontRefIsRef) {
  56231. fontAliases[hash].aliasRef = fontRef;
  56232. }
  56233. fontID = fontAliases[hash].fontID;
  56234. }
  56235. // Workaround for bad PDF generators that reference fonts incorrectly,
  56236. // where `fontRef` is a `Dict` rather than a `Ref` (fixes bug946506.pdf).
  56237. // In this case we should not put the font into `this.fontCache` (which is
  56238. // a `RefSetCache`), since it's not meaningful to use a `Dict` as a key.
  56239. //
  56240. // However, if we don't cache the font it's not possible to remove it
  56241. // when `cleanup` is triggered from the API, which causes issues on
  56242. // subsequent rendering operations (see issue7403.pdf).
  56243. // A simple workaround would be to just not hold `font.translated`
  56244. // references in this case, but this would force us to unnecessarily load
  56245. // the same fonts over and over.
  56246. //
  56247. // Instead, we cheat a bit by attempting to use a modified `fontID` as a
  56248. // key in `this.fontCache`, to allow the font to be cached.
  56249. // NOTE: This works because `RefSetCache` calls `toString()` on provided
  56250. // keys. Also, since `fontRef` is used when getting cached fonts,
  56251. // we'll not accidentally match fonts cached with the `fontID`.
  56252. if (fontRefIsRef) {
  56253. this.fontCache.put(fontRef, fontCapability.promise);
  56254. } else {
  56255. if (!fontID) {
  56256. fontID = (this.uniquePrefix || 'F_') + ++this.idCounters.obj;
  56257. }
  56258. this.fontCache.put('id_' + fontID, fontCapability.promise);
  56259. }
  56260. assert(fontID, 'The "fontID" must be defined.');
  56261. // Keep track of each font we translated so the caller can
  56262. // load them asynchronously before calling display on a page.
  56263. font.loadedName = 'g_' + this.pdfManager.docId + '_f' + fontID;
  56264. font.translated = fontCapability.promise;
  56265. // TODO move promises into translate font
  56266. var translatedPromise;
  56267. try {
  56268. translatedPromise = this.translateFont(preEvaluatedFont, xref);
  56269. } catch (e) {
  56270. translatedPromise = Promise.reject(e);
  56271. }
  56272. var self = this;
  56273. translatedPromise.then(function (translatedFont) {
  56274. if (translatedFont.fontType !== undefined) {
  56275. var xrefFontStats = xref.stats.fontTypes;
  56276. xrefFontStats[translatedFont.fontType] = true;
  56277. }
  56278. fontCapability.resolve(new TranslatedFont(font.loadedName, translatedFont, font));
  56279. }, function (reason) {
  56280. // TODO fontCapability.reject?
  56281. // Error in the font data -- sending unsupported feature notification.
  56282. self.handler.send('UnsupportedFeature', { featureId: UNSUPPORTED_FEATURES.font });
  56283. try {
  56284. // error, but it's still nice to have font type reported
  56285. var descriptor = preEvaluatedFont.descriptor;
  56286. var fontFile3 = descriptor && descriptor.get('FontFile3');
  56287. var subtype = fontFile3 && fontFile3.get('Subtype');
  56288. var fontType = getFontType(preEvaluatedFont.type, subtype && subtype.name);
  56289. var xrefFontStats = xref.stats.fontTypes;
  56290. xrefFontStats[fontType] = true;
  56291. } catch (ex) {
  56292. }
  56293. fontCapability.resolve(new TranslatedFont(font.loadedName, new ErrorFont(reason instanceof Error ? reason.message : reason), font));
  56294. });
  56295. return fontCapability.promise;
  56296. },
  56297. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  56298. var lastIndex = operatorList.length - 1;
  56299. if (!args) {
  56300. args = [];
  56301. }
  56302. if (lastIndex < 0 || operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  56303. operatorList.addOp(OPS.constructPath, [
  56304. [fn],
  56305. args
  56306. ]);
  56307. } else {
  56308. var opArgs = operatorList.argsArray[lastIndex];
  56309. opArgs[0].push(fn);
  56310. Array.prototype.push.apply(opArgs[1], args);
  56311. }
  56312. },
  56313. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args, cs, patterns, resources, task, xref) {
  56314. // compile tiling patterns
  56315. var patternName = args[args.length - 1];
  56316. // SCN/scn applies patterns along with normal colors
  56317. var pattern;
  56318. if (isName(patternName) && (pattern = patterns.get(patternName.name))) {
  56319. var dict = isStream(pattern) ? pattern.dict : pattern;
  56320. var typeNum = dict.get('PatternType');
  56321. if (typeNum === TILING_PATTERN) {
  56322. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  56323. return this.handleTilingType(fn, color, resources, pattern, dict, operatorList, task);
  56324. } else if (typeNum === SHADING_PATTERN) {
  56325. var shading = dict.get('Shading');
  56326. var matrix = dict.getArray('Matrix');
  56327. pattern = Pattern.parseShading(shading, matrix, xref, resources, this.handler);
  56328. operatorList.addOp(fn, pattern.getIR());
  56329. return Promise.resolve();
  56330. } else {
  56331. return Promise.reject('Unknown PatternType: ' + typeNum);
  56332. }
  56333. }
  56334. // TODO shall we fail here?
  56335. operatorList.addOp(fn, args);
  56336. return Promise.resolve();
  56337. },
  56338. getOperatorList: function PartialEvaluator_getOperatorList(stream, task, resources, operatorList, initialState) {
  56339. var self = this;
  56340. var xref = this.xref;
  56341. var imageCache = Object.create(null);
  56342. assert(operatorList);
  56343. resources = resources || Dict.empty;
  56344. var xobjs = resources.get('XObject') || Dict.empty;
  56345. var patterns = resources.get('Pattern') || Dict.empty;
  56346. var stateManager = new StateManager(initialState || new EvalState());
  56347. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  56348. var timeSlotManager = new TimeSlotManager();
  56349. return new Promise(function promiseBody(resolve, reject) {
  56350. var next = function (promise) {
  56351. promise.then(function () {
  56352. try {
  56353. promiseBody(resolve, reject);
  56354. } catch (ex) {
  56355. reject(ex);
  56356. }
  56357. }, reject);
  56358. };
  56359. task.ensureNotTerminated();
  56360. timeSlotManager.reset();
  56361. var stop, operation = {}, i, ii, cs;
  56362. while (!(stop = timeSlotManager.check())) {
  56363. // The arguments parsed by read() are used beyond this loop, so we
  56364. // cannot reuse the same array on each iteration. Therefore we pass
  56365. // in |null| as the initial value (see the comment on
  56366. // EvaluatorPreprocessor_read() for why).
  56367. operation.args = null;
  56368. if (!preprocessor.read(operation)) {
  56369. break;
  56370. }
  56371. var args = operation.args;
  56372. var fn = operation.fn;
  56373. switch (fn | 0) {
  56374. case OPS.paintXObject:
  56375. if (args[0].code) {
  56376. break;
  56377. }
  56378. // eagerly compile XForm objects
  56379. var name = args[0].name;
  56380. if (!name) {
  56381. warn('XObject must be referred to by name.');
  56382. continue;
  56383. }
  56384. if (imageCache[name] !== undefined) {
  56385. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  56386. args = null;
  56387. continue;
  56388. }
  56389. var xobj = xobjs.get(name);
  56390. if (xobj) {
  56391. assert(isStream(xobj), 'XObject should be a stream');
  56392. var type = xobj.dict.get('Subtype');
  56393. assert(isName(type), 'XObject should have a Name subtype');
  56394. if (type.name === 'Form') {
  56395. stateManager.save();
  56396. next(self.buildFormXObject(resources, xobj, null, operatorList, task, stateManager.state.clone()).then(function () {
  56397. stateManager.restore();
  56398. }));
  56399. return;
  56400. } else if (type.name === 'Image') {
  56401. self.buildPaintImageXObject(resources, xobj, false, operatorList, name, imageCache);
  56402. args = null;
  56403. continue;
  56404. } else if (type.name === 'PS') {
  56405. // PostScript XObjects are unused when viewing documents.
  56406. // See section 4.7.1 of Adobe's PDF reference.
  56407. info('Ignored XObject subtype PS');
  56408. continue;
  56409. } else {
  56410. error('Unhandled XObject subtype ' + type.name);
  56411. }
  56412. }
  56413. break;
  56414. case OPS.setFont:
  56415. var fontSize = args[1];
  56416. // eagerly collect all fonts
  56417. next(self.handleSetFont(resources, args, null, operatorList, task, stateManager.state).then(function (loadedName) {
  56418. operatorList.addDependency(loadedName);
  56419. operatorList.addOp(OPS.setFont, [
  56420. loadedName,
  56421. fontSize
  56422. ]);
  56423. }));
  56424. return;
  56425. case OPS.endInlineImage:
  56426. var cacheKey = args[0].cacheKey;
  56427. if (cacheKey) {
  56428. var cacheEntry = imageCache[cacheKey];
  56429. if (cacheEntry !== undefined) {
  56430. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  56431. args = null;
  56432. continue;
  56433. }
  56434. }
  56435. self.buildPaintImageXObject(resources, args[0], true, operatorList, cacheKey, imageCache);
  56436. args = null;
  56437. continue;
  56438. case OPS.showText:
  56439. args[0] = self.handleText(args[0], stateManager.state);
  56440. break;
  56441. case OPS.showSpacedText:
  56442. var arr = args[0];
  56443. var combinedGlyphs = [];
  56444. var arrLength = arr.length;
  56445. var state = stateManager.state;
  56446. for (i = 0; i < arrLength; ++i) {
  56447. var arrItem = arr[i];
  56448. if (isString(arrItem)) {
  56449. Array.prototype.push.apply(combinedGlyphs, self.handleText(arrItem, state));
  56450. } else if (isNum(arrItem)) {
  56451. combinedGlyphs.push(arrItem);
  56452. }
  56453. }
  56454. args[0] = combinedGlyphs;
  56455. fn = OPS.showText;
  56456. break;
  56457. case OPS.nextLineShowText:
  56458. operatorList.addOp(OPS.nextLine);
  56459. args[0] = self.handleText(args[0], stateManager.state);
  56460. fn = OPS.showText;
  56461. break;
  56462. case OPS.nextLineSetSpacingShowText:
  56463. operatorList.addOp(OPS.nextLine);
  56464. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  56465. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  56466. args[0] = self.handleText(args[0], stateManager.state);
  56467. fn = OPS.showText;
  56468. break;
  56469. case OPS.setTextRenderingMode:
  56470. stateManager.state.textRenderingMode = args[0];
  56471. break;
  56472. case OPS.setFillColorSpace:
  56473. stateManager.state.fillColorSpace = ColorSpace.parse(args[0], xref, resources);
  56474. continue;
  56475. case OPS.setStrokeColorSpace:
  56476. stateManager.state.strokeColorSpace = ColorSpace.parse(args[0], xref, resources);
  56477. continue;
  56478. case OPS.setFillColor:
  56479. cs = stateManager.state.fillColorSpace;
  56480. args = cs.getRgb(args, 0);
  56481. fn = OPS.setFillRGBColor;
  56482. break;
  56483. case OPS.setStrokeColor:
  56484. cs = stateManager.state.strokeColorSpace;
  56485. args = cs.getRgb(args, 0);
  56486. fn = OPS.setStrokeRGBColor;
  56487. break;
  56488. case OPS.setFillGray:
  56489. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  56490. args = ColorSpace.singletons.gray.getRgb(args, 0);
  56491. fn = OPS.setFillRGBColor;
  56492. break;
  56493. case OPS.setStrokeGray:
  56494. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  56495. args = ColorSpace.singletons.gray.getRgb(args, 0);
  56496. fn = OPS.setStrokeRGBColor;
  56497. break;
  56498. case OPS.setFillCMYKColor:
  56499. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  56500. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  56501. fn = OPS.setFillRGBColor;
  56502. break;
  56503. case OPS.setStrokeCMYKColor:
  56504. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  56505. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  56506. fn = OPS.setStrokeRGBColor;
  56507. break;
  56508. case OPS.setFillRGBColor:
  56509. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  56510. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  56511. break;
  56512. case OPS.setStrokeRGBColor:
  56513. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  56514. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  56515. break;
  56516. case OPS.setFillColorN:
  56517. cs = stateManager.state.fillColorSpace;
  56518. if (cs.name === 'Pattern') {
  56519. next(self.handleColorN(operatorList, OPS.setFillColorN, args, cs, patterns, resources, task, xref));
  56520. return;
  56521. }
  56522. args = cs.getRgb(args, 0);
  56523. fn = OPS.setFillRGBColor;
  56524. break;
  56525. case OPS.setStrokeColorN:
  56526. cs = stateManager.state.strokeColorSpace;
  56527. if (cs.name === 'Pattern') {
  56528. next(self.handleColorN(operatorList, OPS.setStrokeColorN, args, cs, patterns, resources, task, xref));
  56529. return;
  56530. }
  56531. args = cs.getRgb(args, 0);
  56532. fn = OPS.setStrokeRGBColor;
  56533. break;
  56534. case OPS.shadingFill:
  56535. var shadingRes = resources.get('Shading');
  56536. if (!shadingRes) {
  56537. error('No shading resource found');
  56538. }
  56539. var shading = shadingRes.get(args[0].name);
  56540. if (!shading) {
  56541. error('No shading object found');
  56542. }
  56543. var shadingFill = Pattern.parseShading(shading, null, xref, resources, self.handler);
  56544. var patternIR = shadingFill.getIR();
  56545. args = [patternIR];
  56546. fn = OPS.shadingFill;
  56547. break;
  56548. case OPS.setGState:
  56549. var dictName = args[0];
  56550. var extGState = resources.get('ExtGState');
  56551. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  56552. break;
  56553. }
  56554. var gState = extGState.get(dictName.name);
  56555. next(self.setGState(resources, gState, operatorList, task, xref, stateManager));
  56556. return;
  56557. case OPS.moveTo:
  56558. case OPS.lineTo:
  56559. case OPS.curveTo:
  56560. case OPS.curveTo2:
  56561. case OPS.curveTo3:
  56562. case OPS.closePath:
  56563. self.buildPath(operatorList, fn, args);
  56564. continue;
  56565. case OPS.rectangle:
  56566. self.buildPath(operatorList, fn, args);
  56567. continue;
  56568. case OPS.markPoint:
  56569. case OPS.markPointProps:
  56570. case OPS.beginMarkedContent:
  56571. case OPS.beginMarkedContentProps:
  56572. case OPS.endMarkedContent:
  56573. case OPS.beginCompat:
  56574. case OPS.endCompat:
  56575. // Ignore operators where the corresponding handlers are known to
  56576. // be no-op in CanvasGraphics (display/canvas.js). This prevents
  56577. // serialization errors and is also a bit more efficient.
  56578. // We could also try to serialize all objects in a general way,
  56579. // e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
  56580. // but doing so is meaningless without knowing the semantics.
  56581. continue;
  56582. default:
  56583. // Note: Ignore the operator if it has `Dict` arguments, since
  56584. // those are non-serializable, otherwise postMessage will throw
  56585. // "An object could not be cloned.".
  56586. if (args !== null) {
  56587. for (i = 0, ii = args.length; i < ii; i++) {
  56588. if (args[i] instanceof Dict) {
  56589. break;
  56590. }
  56591. }
  56592. if (i < ii) {
  56593. warn('getOperatorList - ignoring operator: ' + fn);
  56594. continue;
  56595. }
  56596. }
  56597. }
  56598. operatorList.addOp(fn, args);
  56599. }
  56600. if (stop) {
  56601. next(deferred);
  56602. return;
  56603. }
  56604. // Some PDFs don't close all restores inside object/form.
  56605. // Closing those for them.
  56606. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  56607. operatorList.addOp(OPS.restore, []);
  56608. }
  56609. resolve();
  56610. });
  56611. },
  56612. getTextContent: function PartialEvaluator_getTextContent(stream, task, resources, stateManager, normalizeWhitespace, combineTextItems) {
  56613. stateManager = stateManager || new StateManager(new TextState());
  56614. var WhitespaceRegexp = /\s/g;
  56615. var textContent = {
  56616. items: [],
  56617. styles: Object.create(null)
  56618. };
  56619. var textContentItem = {
  56620. initialized: false,
  56621. str: [],
  56622. width: 0,
  56623. height: 0,
  56624. vertical: false,
  56625. lastAdvanceWidth: 0,
  56626. lastAdvanceHeight: 0,
  56627. textAdvanceScale: 0,
  56628. spaceWidth: 0,
  56629. fakeSpaceMin: Infinity,
  56630. fakeMultiSpaceMin: Infinity,
  56631. fakeMultiSpaceMax: -0,
  56632. textRunBreakAllowed: false,
  56633. transform: null,
  56634. fontName: null
  56635. };
  56636. var SPACE_FACTOR = 0.3;
  56637. var MULTI_SPACE_FACTOR = 1.5;
  56638. var MULTI_SPACE_FACTOR_MAX = 4;
  56639. var self = this;
  56640. var xref = this.xref;
  56641. resources = xref.fetchIfRef(resources) || Dict.empty;
  56642. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  56643. var xobjs = null;
  56644. var xobjsCache = Object.create(null);
  56645. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  56646. var textState;
  56647. function ensureTextContentItem() {
  56648. if (textContentItem.initialized) {
  56649. return textContentItem;
  56650. }
  56651. var font = textState.font;
  56652. if (!(font.loadedName in textContent.styles)) {
  56653. textContent.styles[font.loadedName] = {
  56654. fontFamily: font.fallbackName,
  56655. ascent: font.ascent,
  56656. descent: font.descent,
  56657. vertical: font.vertical
  56658. };
  56659. }
  56660. textContentItem.fontName = font.loadedName;
  56661. // 9.4.4 Text Space Details
  56662. var tsm = [
  56663. textState.fontSize * textState.textHScale,
  56664. 0,
  56665. 0,
  56666. textState.fontSize,
  56667. 0,
  56668. textState.textRise
  56669. ];
  56670. if (font.isType3Font && textState.fontMatrix !== FONT_IDENTITY_MATRIX && textState.fontSize === 1) {
  56671. var glyphHeight = font.bbox[3] - font.bbox[1];
  56672. if (glyphHeight > 0) {
  56673. glyphHeight = glyphHeight * textState.fontMatrix[3];
  56674. tsm[3] *= glyphHeight;
  56675. }
  56676. }
  56677. var trm = Util.transform(textState.ctm, Util.transform(textState.textMatrix, tsm));
  56678. textContentItem.transform = trm;
  56679. if (!font.vertical) {
  56680. textContentItem.width = 0;
  56681. textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  56682. textContentItem.vertical = false;
  56683. } else {
  56684. textContentItem.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  56685. textContentItem.height = 0;
  56686. textContentItem.vertical = true;
  56687. }
  56688. var a = textState.textLineMatrix[0];
  56689. var b = textState.textLineMatrix[1];
  56690. var scaleLineX = Math.sqrt(a * a + b * b);
  56691. a = textState.ctm[0];
  56692. b = textState.ctm[1];
  56693. var scaleCtmX = Math.sqrt(a * a + b * b);
  56694. textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
  56695. textContentItem.lastAdvanceWidth = 0;
  56696. textContentItem.lastAdvanceHeight = 0;
  56697. var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
  56698. if (spaceWidth) {
  56699. textContentItem.spaceWidth = spaceWidth;
  56700. textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
  56701. textContentItem.fakeMultiSpaceMin = spaceWidth * MULTI_SPACE_FACTOR;
  56702. textContentItem.fakeMultiSpaceMax = spaceWidth * MULTI_SPACE_FACTOR_MAX;
  56703. // It's okay for monospace fonts to fake as much space as needed.
  56704. textContentItem.textRunBreakAllowed = !font.isMonospace;
  56705. } else {
  56706. textContentItem.spaceWidth = 0;
  56707. textContentItem.fakeSpaceMin = Infinity;
  56708. textContentItem.fakeMultiSpaceMin = Infinity;
  56709. textContentItem.fakeMultiSpaceMax = 0;
  56710. textContentItem.textRunBreakAllowed = false;
  56711. }
  56712. textContentItem.initialized = true;
  56713. return textContentItem;
  56714. }
  56715. function replaceWhitespace(str) {
  56716. // Replaces all whitespaces with standard spaces (0x20), to avoid
  56717. // alignment issues between the textLayer and the canvas if the text
  56718. // contains e.g. tabs (fixes issue6612.pdf).
  56719. var i = 0, ii = str.length, code;
  56720. while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7F) {
  56721. i++;
  56722. }
  56723. return i < ii ? str.replace(WhitespaceRegexp, ' ') : str;
  56724. }
  56725. function runBidiTransform(textChunk) {
  56726. var str = textChunk.str.join('');
  56727. var bidiResult = bidi(str, -1, textChunk.vertical);
  56728. return {
  56729. str: normalizeWhitespace ? replaceWhitespace(bidiResult.str) : bidiResult.str,
  56730. dir: bidiResult.dir,
  56731. width: textChunk.width,
  56732. height: textChunk.height,
  56733. transform: textChunk.transform,
  56734. fontName: textChunk.fontName
  56735. };
  56736. }
  56737. function handleSetFont(fontName, fontRef) {
  56738. return self.loadFont(fontName, fontRef, xref, resources).then(function (translated) {
  56739. textState.font = translated.font;
  56740. textState.fontMatrix = translated.font.fontMatrix || FONT_IDENTITY_MATRIX;
  56741. });
  56742. }
  56743. function buildTextContentItem(chars) {
  56744. var font = textState.font;
  56745. var textChunk = ensureTextContentItem();
  56746. var width = 0;
  56747. var height = 0;
  56748. var glyphs = font.charsToGlyphs(chars);
  56749. var defaultVMetrics = font.defaultVMetrics;
  56750. for (var i = 0; i < glyphs.length; i++) {
  56751. var glyph = glyphs[i];
  56752. var vMetricX = null;
  56753. var vMetricY = null;
  56754. var glyphWidth = null;
  56755. if (font.vertical) {
  56756. if (glyph.vmetric) {
  56757. glyphWidth = glyph.vmetric[0];
  56758. vMetricX = glyph.vmetric[1];
  56759. vMetricY = glyph.vmetric[2];
  56760. } else {
  56761. glyphWidth = glyph.width;
  56762. vMetricX = glyph.width * 0.5;
  56763. vMetricY = defaultVMetrics[2];
  56764. }
  56765. } else {
  56766. glyphWidth = glyph.width;
  56767. }
  56768. var glyphUnicode = glyph.unicode;
  56769. var NormalizedUnicodes = getNormalizedUnicodes();
  56770. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  56771. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  56772. }
  56773. glyphUnicode = reverseIfRtl(glyphUnicode);
  56774. // The following will calculate the x and y of the individual glyphs.
  56775. // if (font.vertical) {
  56776. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  56777. // textState.fontMatrix[0];
  56778. // tsm[5] -= vMetricY * textState.fontSize *
  56779. // textState.fontMatrix[0];
  56780. // }
  56781. // var trm = Util.transform(textState.textMatrix, tsm);
  56782. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  56783. // var x = pt[0];
  56784. // var y = pt[1];
  56785. var charSpacing = textState.charSpacing;
  56786. if (glyph.isSpace) {
  56787. var wordSpacing = textState.wordSpacing;
  56788. charSpacing += wordSpacing;
  56789. if (wordSpacing > 0) {
  56790. addFakeSpaces(wordSpacing, textChunk.str);
  56791. }
  56792. }
  56793. var tx = 0;
  56794. var ty = 0;
  56795. if (!font.vertical) {
  56796. var w0 = glyphWidth * textState.fontMatrix[0];
  56797. tx = (w0 * textState.fontSize + charSpacing) * textState.textHScale;
  56798. width += tx;
  56799. } else {
  56800. var w1 = glyphWidth * textState.fontMatrix[0];
  56801. ty = w1 * textState.fontSize + charSpacing;
  56802. height += ty;
  56803. }
  56804. textState.translateTextMatrix(tx, ty);
  56805. textChunk.str.push(glyphUnicode);
  56806. }
  56807. if (!font.vertical) {
  56808. textChunk.lastAdvanceWidth = width;
  56809. textChunk.width += width * textChunk.textAdvanceScale;
  56810. } else {
  56811. textChunk.lastAdvanceHeight = height;
  56812. textChunk.height += Math.abs(height * textChunk.textAdvanceScale);
  56813. }
  56814. return textChunk;
  56815. }
  56816. function addFakeSpaces(width, strBuf) {
  56817. if (width < textContentItem.fakeSpaceMin) {
  56818. return;
  56819. }
  56820. if (width < textContentItem.fakeMultiSpaceMin) {
  56821. strBuf.push(' ');
  56822. return;
  56823. }
  56824. var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
  56825. while (fakeSpaces-- > 0) {
  56826. strBuf.push(' ');
  56827. }
  56828. }
  56829. function flushTextContentItem() {
  56830. if (!textContentItem.initialized) {
  56831. return;
  56832. }
  56833. textContent.items.push(runBidiTransform(textContentItem));
  56834. textContentItem.initialized = false;
  56835. textContentItem.str.length = 0;
  56836. }
  56837. var timeSlotManager = new TimeSlotManager();
  56838. return new Promise(function promiseBody(resolve, reject) {
  56839. var next = function (promise) {
  56840. promise.then(function () {
  56841. try {
  56842. promiseBody(resolve, reject);
  56843. } catch (ex) {
  56844. reject(ex);
  56845. }
  56846. }, reject);
  56847. };
  56848. task.ensureNotTerminated();
  56849. timeSlotManager.reset();
  56850. var stop, operation = {}, args = [];
  56851. while (!(stop = timeSlotManager.check())) {
  56852. // The arguments parsed by read() are not used beyond this loop, so
  56853. // we can reuse the same array on every iteration, thus avoiding
  56854. // unnecessary allocations.
  56855. args.length = 0;
  56856. operation.args = args;
  56857. if (!preprocessor.read(operation)) {
  56858. break;
  56859. }
  56860. textState = stateManager.state;
  56861. var fn = operation.fn;
  56862. args = operation.args;
  56863. var advance, diff;
  56864. switch (fn | 0) {
  56865. case OPS.setFont:
  56866. // Optimization to ignore multiple identical Tf commands.
  56867. var fontNameArg = args[0].name, fontSizeArg = args[1];
  56868. if (textState.font && fontNameArg === textState.fontName && fontSizeArg === textState.fontSize) {
  56869. break;
  56870. }
  56871. flushTextContentItem();
  56872. textState.fontName = fontNameArg;
  56873. textState.fontSize = fontSizeArg;
  56874. next(handleSetFont(fontNameArg, null));
  56875. return;
  56876. case OPS.setTextRise:
  56877. flushTextContentItem();
  56878. textState.textRise = args[0];
  56879. break;
  56880. case OPS.setHScale:
  56881. flushTextContentItem();
  56882. textState.textHScale = args[0] / 100;
  56883. break;
  56884. case OPS.setLeading:
  56885. flushTextContentItem();
  56886. textState.leading = args[0];
  56887. break;
  56888. case OPS.moveText:
  56889. // Optimization to treat same line movement as advance
  56890. var isSameTextLine = !textState.font ? false : (textState.font.vertical ? args[0] : args[1]) === 0;
  56891. advance = args[0] - args[1];
  56892. if (combineTextItems && isSameTextLine && textContentItem.initialized && advance > 0 && advance <= textContentItem.fakeMultiSpaceMax) {
  56893. textState.translateTextLineMatrix(args[0], args[1]);
  56894. textContentItem.width += args[0] - textContentItem.lastAdvanceWidth;
  56895. textContentItem.height += args[1] - textContentItem.lastAdvanceHeight;
  56896. diff = args[0] - textContentItem.lastAdvanceWidth - (args[1] - textContentItem.lastAdvanceHeight);
  56897. addFakeSpaces(diff, textContentItem.str);
  56898. break;
  56899. }
  56900. flushTextContentItem();
  56901. textState.translateTextLineMatrix(args[0], args[1]);
  56902. textState.textMatrix = textState.textLineMatrix.slice();
  56903. break;
  56904. case OPS.setLeadingMoveText:
  56905. flushTextContentItem();
  56906. textState.leading = -args[1];
  56907. textState.translateTextLineMatrix(args[0], args[1]);
  56908. textState.textMatrix = textState.textLineMatrix.slice();
  56909. break;
  56910. case OPS.nextLine:
  56911. flushTextContentItem();
  56912. textState.carriageReturn();
  56913. break;
  56914. case OPS.setTextMatrix:
  56915. // Optimization to treat same line movement as advance.
  56916. advance = textState.calcTextLineMatrixAdvance(args[0], args[1], args[2], args[3], args[4], args[5]);
  56917. if (combineTextItems && advance !== null && textContentItem.initialized && advance.value > 0 && advance.value <= textContentItem.fakeMultiSpaceMax) {
  56918. textState.translateTextLineMatrix(advance.width, advance.height);
  56919. textContentItem.width += advance.width - textContentItem.lastAdvanceWidth;
  56920. textContentItem.height += advance.height - textContentItem.lastAdvanceHeight;
  56921. diff = advance.width - textContentItem.lastAdvanceWidth - (advance.height - textContentItem.lastAdvanceHeight);
  56922. addFakeSpaces(diff, textContentItem.str);
  56923. break;
  56924. }
  56925. flushTextContentItem();
  56926. textState.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
  56927. textState.setTextLineMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
  56928. break;
  56929. case OPS.setCharSpacing:
  56930. textState.charSpacing = args[0];
  56931. break;
  56932. case OPS.setWordSpacing:
  56933. textState.wordSpacing = args[0];
  56934. break;
  56935. case OPS.beginText:
  56936. flushTextContentItem();
  56937. textState.textMatrix = IDENTITY_MATRIX.slice();
  56938. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  56939. break;
  56940. case OPS.showSpacedText:
  56941. var items = args[0];
  56942. var offset;
  56943. for (var j = 0, jj = items.length; j < jj; j++) {
  56944. if (typeof items[j] === 'string') {
  56945. buildTextContentItem(items[j]);
  56946. } else if (isNum(items[j])) {
  56947. ensureTextContentItem();
  56948. // PDF Specification 5.3.2 states:
  56949. // The number is expressed in thousandths of a unit of text
  56950. // space.
  56951. // This amount is subtracted from the current horizontal or
  56952. // vertical coordinate, depending on the writing mode.
  56953. // In the default coordinate system, a positive adjustment
  56954. // has the effect of moving the next glyph painted either to
  56955. // the left or down by the given amount.
  56956. advance = items[j] * textState.fontSize / 1000;
  56957. var breakTextRun = false;
  56958. if (textState.font.vertical) {
  56959. offset = advance * (textState.textHScale * textState.textMatrix[2] + textState.textMatrix[3]);
  56960. textState.translateTextMatrix(0, advance);
  56961. breakTextRun = textContentItem.textRunBreakAllowed && advance > textContentItem.fakeMultiSpaceMax;
  56962. if (!breakTextRun) {
  56963. // Value needs to be added to height to paint down.
  56964. textContentItem.height += offset;
  56965. }
  56966. } else {
  56967. advance = -advance;
  56968. offset = advance * (textState.textHScale * textState.textMatrix[0] + textState.textMatrix[1]);
  56969. textState.translateTextMatrix(advance, 0);
  56970. breakTextRun = textContentItem.textRunBreakAllowed && advance > textContentItem.fakeMultiSpaceMax;
  56971. if (!breakTextRun) {
  56972. // Value needs to be subtracted from width to paint left.
  56973. textContentItem.width += offset;
  56974. }
  56975. }
  56976. if (breakTextRun) {
  56977. flushTextContentItem();
  56978. } else if (advance > 0) {
  56979. addFakeSpaces(advance, textContentItem.str);
  56980. }
  56981. }
  56982. }
  56983. break;
  56984. case OPS.showText:
  56985. buildTextContentItem(args[0]);
  56986. break;
  56987. case OPS.nextLineShowText:
  56988. flushTextContentItem();
  56989. textState.carriageReturn();
  56990. buildTextContentItem(args[0]);
  56991. break;
  56992. case OPS.nextLineSetSpacingShowText:
  56993. flushTextContentItem();
  56994. textState.wordSpacing = args[0];
  56995. textState.charSpacing = args[1];
  56996. textState.carriageReturn();
  56997. buildTextContentItem(args[2]);
  56998. break;
  56999. case OPS.paintXObject:
  57000. flushTextContentItem();
  57001. if (args[0].code) {
  57002. break;
  57003. }
  57004. if (!xobjs) {
  57005. xobjs = resources.get('XObject') || Dict.empty;
  57006. }
  57007. var name = args[0].name;
  57008. if (xobjsCache.key === name) {
  57009. if (xobjsCache.texts) {
  57010. Util.appendToArray(textContent.items, xobjsCache.texts.items);
  57011. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  57012. }
  57013. break;
  57014. }
  57015. var xobj = xobjs.get(name);
  57016. if (!xobj) {
  57017. break;
  57018. }
  57019. assert(isStream(xobj), 'XObject should be a stream');
  57020. var type = xobj.dict.get('Subtype');
  57021. assert(isName(type), 'XObject should have a Name subtype');
  57022. if ('Form' !== type.name) {
  57023. xobjsCache.key = name;
  57024. xobjsCache.texts = null;
  57025. break;
  57026. }
  57027. stateManager.save();
  57028. var matrix = xobj.dict.getArray('Matrix');
  57029. if (isArray(matrix) && matrix.length === 6) {
  57030. stateManager.transform(matrix);
  57031. }
  57032. next(self.getTextContent(xobj, task, xobj.dict.get('Resources') || resources, stateManager, normalizeWhitespace, combineTextItems).then(function (formTextContent) {
  57033. Util.appendToArray(textContent.items, formTextContent.items);
  57034. Util.extendObj(textContent.styles, formTextContent.styles);
  57035. stateManager.restore();
  57036. xobjsCache.key = name;
  57037. xobjsCache.texts = formTextContent;
  57038. }));
  57039. return;
  57040. case OPS.setGState:
  57041. flushTextContentItem();
  57042. var dictName = args[0];
  57043. var extGState = resources.get('ExtGState');
  57044. if (!isDict(extGState) || !isName(dictName)) {
  57045. break;
  57046. }
  57047. var gState = extGState.get(dictName.name);
  57048. if (!isDict(gState)) {
  57049. break;
  57050. }
  57051. var gStateFont = gState.get('Font');
  57052. if (gStateFont) {
  57053. textState.fontName = null;
  57054. textState.fontSize = gStateFont[1];
  57055. next(handleSetFont(null, gStateFont[0]));
  57056. return;
  57057. }
  57058. break;
  57059. }
  57060. }
  57061. // switch
  57062. // while
  57063. if (stop) {
  57064. next(deferred);
  57065. return;
  57066. }
  57067. flushTextContentItem();
  57068. resolve(textContent);
  57069. });
  57070. },
  57071. extractDataStructures: function PartialEvaluator_extractDataStructures(dict, baseDict, xref, properties) {
  57072. // 9.10.2
  57073. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  57074. var toUnicodePromise = toUnicode ? this.readToUnicode(toUnicode) : Promise.resolve(undefined);
  57075. if (properties.composite) {
  57076. // CIDSystemInfo helps to match CID to glyphs
  57077. var cidSystemInfo = dict.get('CIDSystemInfo');
  57078. if (isDict(cidSystemInfo)) {
  57079. properties.cidSystemInfo = {
  57080. registry: cidSystemInfo.get('Registry'),
  57081. ordering: cidSystemInfo.get('Ordering'),
  57082. supplement: cidSystemInfo.get('Supplement')
  57083. };
  57084. }
  57085. var cidToGidMap = dict.get('CIDToGIDMap');
  57086. if (isStream(cidToGidMap)) {
  57087. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  57088. }
  57089. }
  57090. // Based on 9.6.6 of the spec the encoding can come from multiple places
  57091. // and depends on the font type. The base encoding and differences are
  57092. // read here, but the encoding that is actually used is chosen during
  57093. // glyph mapping in the font.
  57094. // TODO: Loading the built in encoding in the font would allow the
  57095. // differences to be merged in here not require us to hold on to it.
  57096. var differences = [];
  57097. var baseEncodingName = null;
  57098. var encoding;
  57099. if (dict.has('Encoding')) {
  57100. encoding = dict.get('Encoding');
  57101. if (isDict(encoding)) {
  57102. baseEncodingName = encoding.get('BaseEncoding');
  57103. baseEncodingName = isName(baseEncodingName) ? baseEncodingName.name : null;
  57104. // Load the differences between the base and original
  57105. if (encoding.has('Differences')) {
  57106. var diffEncoding = encoding.get('Differences');
  57107. var index = 0;
  57108. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  57109. var data = xref.fetchIfRef(diffEncoding[j]);
  57110. if (isNum(data)) {
  57111. index = data;
  57112. } else if (isName(data)) {
  57113. differences[index++] = data.name;
  57114. } else {
  57115. error('Invalid entry in \'Differences\' array: ' + data);
  57116. }
  57117. }
  57118. }
  57119. } else if (isName(encoding)) {
  57120. baseEncodingName = encoding.name;
  57121. } else {
  57122. error('Encoding is not a Name nor a Dict');
  57123. }
  57124. // According to table 114 if the encoding is a named encoding it must be
  57125. // one of these predefined encodings.
  57126. if (baseEncodingName !== 'MacRomanEncoding' && baseEncodingName !== 'MacExpertEncoding' && baseEncodingName !== 'WinAnsiEncoding') {
  57127. baseEncodingName = null;
  57128. }
  57129. }
  57130. if (baseEncodingName) {
  57131. properties.defaultEncoding = getEncoding(baseEncodingName).slice();
  57132. } else {
  57133. encoding = properties.type === 'TrueType' ? WinAnsiEncoding : StandardEncoding;
  57134. // The Symbolic attribute can be misused for regular fonts
  57135. // Heuristic: we have to check if the font is a standard one also
  57136. if (!!(properties.flags & FontFlags.Symbolic)) {
  57137. encoding = MacRomanEncoding;
  57138. if (!properties.file) {
  57139. if (/Symbol/i.test(properties.name)) {
  57140. encoding = SymbolSetEncoding;
  57141. } else if (/Dingbats/i.test(properties.name)) {
  57142. encoding = ZapfDingbatsEncoding;
  57143. }
  57144. }
  57145. }
  57146. properties.defaultEncoding = encoding;
  57147. }
  57148. properties.differences = differences;
  57149. properties.baseEncodingName = baseEncodingName;
  57150. properties.hasEncoding = !!baseEncodingName || differences.length > 0;
  57151. properties.dict = dict;
  57152. return toUnicodePromise.then(function (toUnicode) {
  57153. properties.toUnicode = toUnicode;
  57154. return this.buildToUnicode(properties);
  57155. }.bind(this)).then(function (toUnicode) {
  57156. properties.toUnicode = toUnicode;
  57157. return properties;
  57158. });
  57159. },
  57160. /**
  57161. * Builds a char code to unicode map based on section 9.10 of the spec.
  57162. * @param {Object} properties Font properties object.
  57163. * @return {Promise} A Promise that is resolved with a
  57164. * {ToUnicodeMap|IdentityToUnicodeMap} object.
  57165. */
  57166. buildToUnicode: function PartialEvaluator_buildToUnicode(properties) {
  57167. properties.hasIncludedToUnicodeMap = !!properties.toUnicode && properties.toUnicode.length > 0;
  57168. // Section 9.10.2 Mapping Character Codes to Unicode Values
  57169. if (properties.hasIncludedToUnicodeMap) {
  57170. return Promise.resolve(properties.toUnicode);
  57171. }
  57172. // According to the spec if the font is a simple font we should only map
  57173. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  57174. // the differences array only contains adobe standard or symbol set names,
  57175. // in pratice it seems better to always try to create a toUnicode
  57176. // map based of the default encoding.
  57177. var toUnicode, charcode, glyphName;
  57178. if (!properties.composite)
  57179. /* is simple font */
  57180. {
  57181. toUnicode = [];
  57182. var encoding = properties.defaultEncoding.slice();
  57183. var baseEncodingName = properties.baseEncodingName;
  57184. // Merge in the differences array.
  57185. var differences = properties.differences;
  57186. for (charcode in differences) {
  57187. glyphName = differences[charcode];
  57188. if (glyphName === '.notdef') {
  57189. // Skip .notdef to prevent rendering errors, e.g. boxes appearing
  57190. // where there should be spaces (fixes issue5256.pdf).
  57191. continue;
  57192. }
  57193. encoding[charcode] = glyphName;
  57194. }
  57195. var glyphsUnicodeMap = getGlyphsUnicode();
  57196. for (charcode in encoding) {
  57197. // a) Map the character code to a character name.
  57198. glyphName = encoding[charcode];
  57199. // b) Look up the character name in the Adobe Glyph List (see the
  57200. // Bibliography) to obtain the corresponding Unicode value.
  57201. if (glyphName === '') {
  57202. continue;
  57203. } else if (glyphsUnicodeMap[glyphName] === undefined) {
  57204. // (undocumented) c) Few heuristics to recognize unknown glyphs
  57205. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  57206. var code = 0;
  57207. switch (glyphName[0]) {
  57208. case 'G':
  57209. // Gxx glyph
  57210. if (glyphName.length === 3) {
  57211. code = parseInt(glyphName.substr(1), 16);
  57212. }
  57213. break;
  57214. case 'g':
  57215. // g00xx glyph
  57216. if (glyphName.length === 5) {
  57217. code = parseInt(glyphName.substr(1), 16);
  57218. }
  57219. break;
  57220. case 'C':
  57221. // Cddd glyph
  57222. case 'c':
  57223. // cddd glyph
  57224. if (glyphName.length >= 3) {
  57225. code = +glyphName.substr(1);
  57226. }
  57227. break;
  57228. default:
  57229. // 'uniXXXX'/'uXXXX{XX}' glyphs
  57230. var unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  57231. if (unicode !== -1) {
  57232. code = unicode;
  57233. }
  57234. }
  57235. if (code) {
  57236. // If |baseEncodingName| is one the predefined encodings,
  57237. // and |code| equals |charcode|, using the glyph defined in the
  57238. // baseEncoding seems to yield a better |toUnicode| mapping
  57239. // (fixes issue 5070).
  57240. if (baseEncodingName && code === +charcode) {
  57241. var baseEncoding = getEncoding(baseEncodingName);
  57242. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  57243. toUnicode[charcode] = String.fromCharCode(glyphsUnicodeMap[glyphName]);
  57244. continue;
  57245. }
  57246. }
  57247. toUnicode[charcode] = String.fromCharCode(code);
  57248. }
  57249. continue;
  57250. }
  57251. toUnicode[charcode] = String.fromCharCode(glyphsUnicodeMap[glyphName]);
  57252. }
  57253. return Promise.resolve(new ToUnicodeMap(toUnicode));
  57254. }
  57255. // If the font is a composite font that uses one of the predefined CMaps
  57256. // listed in Table 118 (except Identity–H and Identity–V) or whose
  57257. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  57258. // Adobe-Korea1 character collection:
  57259. if (properties.composite && (properties.cMap.builtInCMap && !(properties.cMap instanceof IdentityCMap) || properties.cidSystemInfo.registry === 'Adobe' && (properties.cidSystemInfo.ordering === 'GB1' || properties.cidSystemInfo.ordering === 'CNS1' || properties.cidSystemInfo.ordering === 'Japan1' || properties.cidSystemInfo.ordering === 'Korea1'))) {
  57260. // Then:
  57261. // a) Map the character code to a character identifier (CID) according
  57262. // to the font’s CMap.
  57263. // b) Obtain the registry and ordering of the character collection used
  57264. // by the font’s CMap (for example, Adobe and Japan1) from its
  57265. // CIDSystemInfo dictionary.
  57266. var registry = properties.cidSystemInfo.registry;
  57267. var ordering = properties.cidSystemInfo.ordering;
  57268. // c) Construct a second CMap name by concatenating the registry and
  57269. // ordering obtained in step (b) in the format registry–ordering–UCS2
  57270. // (for example, Adobe–Japan1–UCS2).
  57271. var ucs2CMapName = Name.get(registry + '-' + ordering + '-UCS2');
  57272. // d) Obtain the CMap with the name constructed in step (c) (available
  57273. // from the ASN Web site; see the Bibliography).
  57274. return CMapFactory.create(ucs2CMapName, this.options.cMapOptions, null).then(function (ucs2CMap) {
  57275. var cMap = properties.cMap;
  57276. toUnicode = [];
  57277. cMap.forEach(function (charcode, cid) {
  57278. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  57279. // e) Map the CID obtained in step (a) according to the CMap
  57280. // obtained in step (d), producing a Unicode value.
  57281. var ucs2 = ucs2CMap.lookup(cid);
  57282. if (ucs2) {
  57283. toUnicode[charcode] = String.fromCharCode((ucs2.charCodeAt(0) << 8) + ucs2.charCodeAt(1));
  57284. }
  57285. });
  57286. return new ToUnicodeMap(toUnicode);
  57287. });
  57288. }
  57289. // The viewer's choice, just use an identity map.
  57290. return Promise.resolve(new IdentityToUnicodeMap(properties.firstChar, properties.lastChar));
  57291. },
  57292. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  57293. var cmapObj = toUnicode;
  57294. if (isName(cmapObj)) {
  57295. return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(function (cmap) {
  57296. if (cmap instanceof IdentityCMap) {
  57297. return new IdentityToUnicodeMap(0, 0xFFFF);
  57298. }
  57299. return new ToUnicodeMap(cmap.getMap());
  57300. });
  57301. } else if (isStream(cmapObj)) {
  57302. return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(function (cmap) {
  57303. if (cmap instanceof IdentityCMap) {
  57304. return new IdentityToUnicodeMap(0, 0xFFFF);
  57305. }
  57306. var map = new Array(cmap.length);
  57307. // Convert UTF-16BE
  57308. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  57309. // to iterate over all keys.
  57310. cmap.forEach(function (charCode, token) {
  57311. var str = [];
  57312. for (var k = 0; k < token.length; k += 2) {
  57313. var w1 = token.charCodeAt(k) << 8 | token.charCodeAt(k + 1);
  57314. if ((w1 & 0xF800) !== 0xD800) {
  57315. // w1 < 0xD800 || w1 > 0xDFFF
  57316. str.push(w1);
  57317. continue;
  57318. }
  57319. k += 2;
  57320. var w2 = token.charCodeAt(k) << 8 | token.charCodeAt(k + 1);
  57321. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  57322. }
  57323. map[charCode] = String.fromCharCode.apply(String, str);
  57324. });
  57325. return new ToUnicodeMap(map);
  57326. });
  57327. }
  57328. return Promise.resolve(null);
  57329. },
  57330. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  57331. // Extract the encoding from the CIDToGIDMap
  57332. var glyphsData = cidToGidStream.getBytes();
  57333. // Set encoding 0 to later verify the font has an encoding
  57334. var result = [];
  57335. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  57336. var glyphID = glyphsData[j++] << 8 | glyphsData[j];
  57337. if (glyphID === 0) {
  57338. continue;
  57339. }
  57340. var code = j >> 1;
  57341. result[code] = glyphID;
  57342. }
  57343. return result;
  57344. },
  57345. extractWidths: function PartialEvaluator_extractWidths(dict, xref, descriptor, properties) {
  57346. var glyphsWidths = [];
  57347. var defaultWidth = 0;
  57348. var glyphsVMetrics = [];
  57349. var defaultVMetrics;
  57350. var i, ii, j, jj, start, code, widths;
  57351. if (properties.composite) {
  57352. defaultWidth = dict.get('DW') || 1000;
  57353. widths = dict.get('W');
  57354. if (widths) {
  57355. for (i = 0, ii = widths.length; i < ii; i++) {
  57356. start = widths[i++];
  57357. code = xref.fetchIfRef(widths[i]);
  57358. if (isArray(code)) {
  57359. for (j = 0, jj = code.length; j < jj; j++) {
  57360. glyphsWidths[start++] = code[j];
  57361. }
  57362. } else {
  57363. var width = widths[++i];
  57364. for (j = start; j <= code; j++) {
  57365. glyphsWidths[j] = width;
  57366. }
  57367. }
  57368. }
  57369. }
  57370. if (properties.vertical) {
  57371. var vmetrics = dict.get('DW2') || [
  57372. 880,
  57373. -1000
  57374. ];
  57375. defaultVMetrics = [
  57376. vmetrics[1],
  57377. defaultWidth * 0.5,
  57378. vmetrics[0]
  57379. ];
  57380. vmetrics = dict.get('W2');
  57381. if (vmetrics) {
  57382. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  57383. start = vmetrics[i++];
  57384. code = xref.fetchIfRef(vmetrics[i]);
  57385. if (isArray(code)) {
  57386. for (j = 0, jj = code.length; j < jj; j++) {
  57387. glyphsVMetrics[start++] = [
  57388. code[j++],
  57389. code[j++],
  57390. code[j]
  57391. ];
  57392. }
  57393. } else {
  57394. var vmetric = [
  57395. vmetrics[++i],
  57396. vmetrics[++i],
  57397. vmetrics[++i]
  57398. ];
  57399. for (j = start; j <= code; j++) {
  57400. glyphsVMetrics[j] = vmetric;
  57401. }
  57402. }
  57403. }
  57404. }
  57405. }
  57406. } else {
  57407. var firstChar = properties.firstChar;
  57408. widths = dict.get('Widths');
  57409. if (widths) {
  57410. j = firstChar;
  57411. for (i = 0, ii = widths.length; i < ii; i++) {
  57412. glyphsWidths[j++] = widths[i];
  57413. }
  57414. defaultWidth = parseFloat(descriptor.get('MissingWidth')) || 0;
  57415. } else {
  57416. // Trying get the BaseFont metrics (see comment above).
  57417. var baseFontName = dict.get('BaseFont');
  57418. if (isName(baseFontName)) {
  57419. var metrics = this.getBaseFontMetrics(baseFontName.name);
  57420. glyphsWidths = this.buildCharCodeToWidth(metrics.widths, properties);
  57421. defaultWidth = metrics.defaultWidth;
  57422. }
  57423. }
  57424. }
  57425. // Heuristic: detection of monospace font by checking all non-zero widths
  57426. var isMonospace = true;
  57427. var firstWidth = defaultWidth;
  57428. for (var glyph in glyphsWidths) {
  57429. var glyphWidth = glyphsWidths[glyph];
  57430. if (!glyphWidth) {
  57431. continue;
  57432. }
  57433. if (!firstWidth) {
  57434. firstWidth = glyphWidth;
  57435. continue;
  57436. }
  57437. if (firstWidth !== glyphWidth) {
  57438. isMonospace = false;
  57439. break;
  57440. }
  57441. }
  57442. if (isMonospace) {
  57443. properties.flags |= FontFlags.FixedPitch;
  57444. }
  57445. properties.defaultWidth = defaultWidth;
  57446. properties.widths = glyphsWidths;
  57447. properties.defaultVMetrics = defaultVMetrics;
  57448. properties.vmetrics = glyphsVMetrics;
  57449. },
  57450. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  57451. // Simulating descriptor flags attribute
  57452. var fontNameWoStyle = baseFontName.split('-')[0];
  57453. return fontNameWoStyle in getSerifFonts() || fontNameWoStyle.search(/serif/gi) !== -1;
  57454. },
  57455. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  57456. var defaultWidth = 0;
  57457. var widths = [];
  57458. var monospace = false;
  57459. var stdFontMap = getStdFontMap();
  57460. var lookupName = stdFontMap[name] || name;
  57461. var Metrics = getMetrics();
  57462. if (!(lookupName in Metrics)) {
  57463. // Use default fonts for looking up font metrics if the passed
  57464. // font is not a base font
  57465. if (this.isSerifFont(name)) {
  57466. lookupName = 'Times-Roman';
  57467. } else {
  57468. lookupName = 'Helvetica';
  57469. }
  57470. }
  57471. var glyphWidths = Metrics[lookupName];
  57472. if (isNum(glyphWidths)) {
  57473. defaultWidth = glyphWidths;
  57474. monospace = true;
  57475. } else {
  57476. widths = glyphWidths();
  57477. }
  57478. // expand lazy widths array
  57479. return {
  57480. defaultWidth: defaultWidth,
  57481. monospace: monospace,
  57482. widths: widths
  57483. };
  57484. },
  57485. buildCharCodeToWidth: function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName, properties) {
  57486. var widths = Object.create(null);
  57487. var differences = properties.differences;
  57488. var encoding = properties.defaultEncoding;
  57489. for (var charCode = 0; charCode < 256; charCode++) {
  57490. if (charCode in differences && widthsByGlyphName[differences[charCode]]) {
  57491. widths[charCode] = widthsByGlyphName[differences[charCode]];
  57492. continue;
  57493. }
  57494. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  57495. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  57496. continue;
  57497. }
  57498. }
  57499. return widths;
  57500. },
  57501. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  57502. var baseDict = dict;
  57503. var type = dict.get('Subtype');
  57504. assert(isName(type), 'invalid font Subtype');
  57505. var composite = false;
  57506. var uint8array;
  57507. if (type.name === 'Type0') {
  57508. // If font is a composite
  57509. // - get the descendant font
  57510. // - set the type according to the descendant font
  57511. // - get the FontDescriptor from the descendant font
  57512. var df = dict.get('DescendantFonts');
  57513. if (!df) {
  57514. error('Descendant fonts are not specified');
  57515. }
  57516. dict = isArray(df) ? xref.fetchIfRef(df[0]) : df;
  57517. type = dict.get('Subtype');
  57518. assert(isName(type), 'invalid font Subtype');
  57519. composite = true;
  57520. }
  57521. var descriptor = dict.get('FontDescriptor');
  57522. if (descriptor) {
  57523. var hash = new MurmurHash3_64();
  57524. var encoding = baseDict.getRaw('Encoding');
  57525. if (isName(encoding)) {
  57526. hash.update(encoding.name);
  57527. } else if (isRef(encoding)) {
  57528. hash.update(encoding.toString());
  57529. } else if (isDict(encoding)) {
  57530. var keys = encoding.getKeys();
  57531. for (var i = 0, ii = keys.length; i < ii; i++) {
  57532. var entry = encoding.getRaw(keys[i]);
  57533. if (isName(entry)) {
  57534. hash.update(entry.name);
  57535. } else if (isRef(entry)) {
  57536. hash.update(entry.toString());
  57537. } else if (isArray(entry)) {
  57538. // 'Differences' entry.
  57539. // Ideally we should check the contents of the array, but to avoid
  57540. // parsing it here and then again in |extractDataStructures|,
  57541. // we only use the array length for now (fixes bug1157493.pdf).
  57542. hash.update(entry.length.toString());
  57543. }
  57544. }
  57545. }
  57546. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  57547. if (isStream(toUnicode)) {
  57548. var stream = toUnicode.str || toUnicode;
  57549. uint8array = stream.buffer ? new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) : new Uint8Array(stream.bytes.buffer, stream.start, stream.end - stream.start);
  57550. hash.update(uint8array);
  57551. } else if (isName(toUnicode)) {
  57552. hash.update(toUnicode.name);
  57553. }
  57554. var widths = dict.get('Widths') || baseDict.get('Widths');
  57555. if (widths) {
  57556. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  57557. hash.update(uint8array);
  57558. }
  57559. }
  57560. return {
  57561. descriptor: descriptor,
  57562. dict: dict,
  57563. baseDict: baseDict,
  57564. composite: composite,
  57565. type: type.name,
  57566. hash: hash ? hash.hexdigest() : ''
  57567. };
  57568. },
  57569. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont, xref) {
  57570. var baseDict = preEvaluatedFont.baseDict;
  57571. var dict = preEvaluatedFont.dict;
  57572. var composite = preEvaluatedFont.composite;
  57573. var descriptor = preEvaluatedFont.descriptor;
  57574. var type = preEvaluatedFont.type;
  57575. var maxCharIndex = composite ? 0xFFFF : 0xFF;
  57576. var cMapOptions = this.options.cMapOptions;
  57577. var properties;
  57578. if (!descriptor) {
  57579. if (type === 'Type3') {
  57580. // FontDescriptor is only required for Type3 fonts when the document
  57581. // is a tagged pdf. Create a barbebones one to get by.
  57582. descriptor = new Dict(null);
  57583. descriptor.set('FontName', Name.get(type));
  57584. descriptor.set('FontBBox', dict.getArray('FontBBox'));
  57585. } else {
  57586. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  57587. // FontDescriptor was not required.
  57588. // This case is here for compatibility.
  57589. var baseFontName = dict.get('BaseFont');
  57590. if (!isName(baseFontName)) {
  57591. error('Base font is not specified');
  57592. }
  57593. // Using base font name as a font name.
  57594. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  57595. var metrics = this.getBaseFontMetrics(baseFontName);
  57596. // Simulating descriptor flags attribute
  57597. var fontNameWoStyle = baseFontName.split('-')[0];
  57598. var flags = (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) | (metrics.monospace ? FontFlags.FixedPitch : 0) | (getSymbolsFonts()[fontNameWoStyle] ? FontFlags.Symbolic : FontFlags.Nonsymbolic);
  57599. properties = {
  57600. type: type,
  57601. name: baseFontName,
  57602. widths: metrics.widths,
  57603. defaultWidth: metrics.defaultWidth,
  57604. flags: flags,
  57605. firstChar: 0,
  57606. lastChar: maxCharIndex
  57607. };
  57608. return this.extractDataStructures(dict, dict, xref, properties).then(function (properties) {
  57609. properties.widths = this.buildCharCodeToWidth(metrics.widths, properties);
  57610. return new Font(baseFontName, null, properties);
  57611. }.bind(this));
  57612. }
  57613. }
  57614. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  57615. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  57616. // to ignore this rule when a variant of a standard font is used.
  57617. // TODO Fill the width array depending on which of the base font this is
  57618. // a variant.
  57619. var firstChar = dict.get('FirstChar') || 0;
  57620. var lastChar = dict.get('LastChar') || maxCharIndex;
  57621. var fontName = descriptor.get('FontName');
  57622. var baseFont = dict.get('BaseFont');
  57623. // Some bad PDFs have a string as the font name.
  57624. if (isString(fontName)) {
  57625. fontName = Name.get(fontName);
  57626. }
  57627. if (isString(baseFont)) {
  57628. baseFont = Name.get(baseFont);
  57629. }
  57630. if (type !== 'Type3') {
  57631. var fontNameStr = fontName && fontName.name;
  57632. var baseFontStr = baseFont && baseFont.name;
  57633. if (fontNameStr !== baseFontStr) {
  57634. info('The FontDescriptor\'s FontName is "' + fontNameStr + '" but should be the same as the Font\'s BaseFont "' + baseFontStr + '"');
  57635. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  57636. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  57637. if (fontNameStr && baseFontStr && baseFontStr.indexOf(fontNameStr) === 0) {
  57638. fontName = baseFont;
  57639. }
  57640. }
  57641. }
  57642. fontName = fontName || baseFont;
  57643. assert(isName(fontName), 'invalid font name');
  57644. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  57645. if (fontFile) {
  57646. if (fontFile.dict) {
  57647. var subtype = fontFile.dict.get('Subtype');
  57648. if (subtype) {
  57649. subtype = subtype.name;
  57650. }
  57651. var length1 = fontFile.dict.get('Length1');
  57652. var length2 = fontFile.dict.get('Length2');
  57653. var length3 = fontFile.dict.get('Length3');
  57654. }
  57655. }
  57656. properties = {
  57657. type: type,
  57658. name: fontName.name,
  57659. subtype: subtype,
  57660. file: fontFile,
  57661. length1: length1,
  57662. length2: length2,
  57663. length3: length3,
  57664. loadedName: baseDict.loadedName,
  57665. composite: composite,
  57666. wideChars: composite,
  57667. fixedPitch: false,
  57668. fontMatrix: dict.getArray('FontMatrix') || FONT_IDENTITY_MATRIX,
  57669. firstChar: firstChar || 0,
  57670. lastChar: lastChar || maxCharIndex,
  57671. bbox: descriptor.getArray('FontBBox'),
  57672. ascent: descriptor.get('Ascent'),
  57673. descent: descriptor.get('Descent'),
  57674. xHeight: descriptor.get('XHeight'),
  57675. capHeight: descriptor.get('CapHeight'),
  57676. flags: descriptor.get('Flags'),
  57677. italicAngle: descriptor.get('ItalicAngle'),
  57678. coded: false
  57679. };
  57680. var cMapPromise;
  57681. if (composite) {
  57682. var cidEncoding = baseDict.get('Encoding');
  57683. if (isName(cidEncoding)) {
  57684. properties.cidEncoding = cidEncoding.name;
  57685. }
  57686. cMapPromise = CMapFactory.create(cidEncoding, cMapOptions, null).then(function (cMap) {
  57687. properties.cMap = cMap;
  57688. properties.vertical = properties.cMap.vertical;
  57689. });
  57690. } else {
  57691. cMapPromise = Promise.resolve(undefined);
  57692. }
  57693. return cMapPromise.then(function () {
  57694. return this.extractDataStructures(dict, baseDict, xref, properties);
  57695. }.bind(this)).then(function (properties) {
  57696. this.extractWidths(dict, xref, descriptor, properties);
  57697. if (type === 'Type3') {
  57698. properties.isType3Font = true;
  57699. }
  57700. return new Font(fontName.name, fontFile, properties);
  57701. }.bind(this));
  57702. }
  57703. };
  57704. return PartialEvaluator;
  57705. }();
  57706. var TranslatedFont = function TranslatedFontClosure() {
  57707. function TranslatedFont(loadedName, font, dict) {
  57708. this.loadedName = loadedName;
  57709. this.font = font;
  57710. this.dict = dict;
  57711. this.type3Loaded = null;
  57712. this.sent = false;
  57713. }
  57714. TranslatedFont.prototype = {
  57715. send: function (handler) {
  57716. if (this.sent) {
  57717. return;
  57718. }
  57719. var fontData = this.font.exportData();
  57720. handler.send('commonobj', [
  57721. this.loadedName,
  57722. 'Font',
  57723. fontData
  57724. ]);
  57725. this.sent = true;
  57726. },
  57727. loadType3Data: function (evaluator, resources, parentOperatorList, task) {
  57728. assert(this.font.isType3Font);
  57729. if (this.type3Loaded) {
  57730. return this.type3Loaded;
  57731. }
  57732. var translatedFont = this.font;
  57733. var loadCharProcsPromise = Promise.resolve();
  57734. var charProcs = this.dict.get('CharProcs');
  57735. var fontResources = this.dict.get('Resources') || resources;
  57736. var charProcKeys = charProcs.getKeys();
  57737. var charProcOperatorList = Object.create(null);
  57738. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  57739. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  57740. var glyphStream = charProcs.get(key);
  57741. var operatorList = new OperatorList();
  57742. return evaluator.getOperatorList(glyphStream, task, fontResources, operatorList).then(function () {
  57743. charProcOperatorList[key] = operatorList.getIR();
  57744. // Add the dependencies to the parent operator list so they are
  57745. // resolved before sub operator list is executed synchronously.
  57746. parentOperatorList.addDependencies(operatorList.dependencies);
  57747. }, function (reason) {
  57748. warn('Type3 font resource \"' + key + '\" is not available');
  57749. var operatorList = new OperatorList();
  57750. charProcOperatorList[key] = operatorList.getIR();
  57751. });
  57752. }.bind(this, charProcKeys[i]));
  57753. }
  57754. this.type3Loaded = loadCharProcsPromise.then(function () {
  57755. translatedFont.charProcOperatorList = charProcOperatorList;
  57756. });
  57757. return this.type3Loaded;
  57758. }
  57759. };
  57760. return TranslatedFont;
  57761. }();
  57762. var OperatorList = function OperatorListClosure() {
  57763. var CHUNK_SIZE = 1000;
  57764. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5;
  57765. // close to chunk size
  57766. function getTransfers(queue) {
  57767. var transfers = [];
  57768. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  57769. for (var i = 0, ii = queue.length; i < ii; i++) {
  57770. switch (fnArray[i]) {
  57771. case OPS.paintInlineImageXObject:
  57772. case OPS.paintInlineImageXObjectGroup:
  57773. case OPS.paintImageMaskXObject:
  57774. var arg = argsArray[i][0];
  57775. // first param in imgData
  57776. if (!arg.cached) {
  57777. transfers.push(arg.data.buffer);
  57778. }
  57779. break;
  57780. }
  57781. }
  57782. return transfers;
  57783. }
  57784. function OperatorList(intent, messageHandler, pageIndex) {
  57785. this.messageHandler = messageHandler;
  57786. this.fnArray = [];
  57787. this.argsArray = [];
  57788. this.dependencies = Object.create(null);
  57789. this._totalLength = 0;
  57790. this.pageIndex = pageIndex;
  57791. this.intent = intent;
  57792. }
  57793. OperatorList.prototype = {
  57794. get length() {
  57795. return this.argsArray.length;
  57796. },
  57797. /**
  57798. * @returns {number} The total length of the entire operator list,
  57799. * since `this.length === 0` after flushing.
  57800. */
  57801. get totalLength() {
  57802. return this._totalLength + this.length;
  57803. },
  57804. addOp: function (fn, args) {
  57805. this.fnArray.push(fn);
  57806. this.argsArray.push(args);
  57807. if (this.messageHandler) {
  57808. if (this.fnArray.length >= CHUNK_SIZE) {
  57809. this.flush();
  57810. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT && (fn === OPS.restore || fn === OPS.endText)) {
  57811. // heuristic to flush on boundary of restore or endText
  57812. this.flush();
  57813. }
  57814. }
  57815. },
  57816. addDependency: function (dependency) {
  57817. if (dependency in this.dependencies) {
  57818. return;
  57819. }
  57820. this.dependencies[dependency] = true;
  57821. this.addOp(OPS.dependency, [dependency]);
  57822. },
  57823. addDependencies: function (dependencies) {
  57824. for (var key in dependencies) {
  57825. this.addDependency(key);
  57826. }
  57827. },
  57828. addOpList: function (opList) {
  57829. Util.extendObj(this.dependencies, opList.dependencies);
  57830. for (var i = 0, ii = opList.length; i < ii; i++) {
  57831. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  57832. }
  57833. },
  57834. getIR: function () {
  57835. return {
  57836. fnArray: this.fnArray,
  57837. argsArray: this.argsArray,
  57838. length: this.length
  57839. };
  57840. },
  57841. flush: function (lastChunk) {
  57842. if (this.intent !== 'oplist') {
  57843. new QueueOptimizer().optimize(this);
  57844. }
  57845. var transfers = getTransfers(this);
  57846. var length = this.length;
  57847. this._totalLength += length;
  57848. this.messageHandler.send('RenderPageChunk', {
  57849. operatorList: {
  57850. fnArray: this.fnArray,
  57851. argsArray: this.argsArray,
  57852. lastChunk: lastChunk,
  57853. length: length
  57854. },
  57855. pageIndex: this.pageIndex,
  57856. intent: this.intent
  57857. }, transfers);
  57858. this.dependencies = Object.create(null);
  57859. this.fnArray.length = 0;
  57860. this.argsArray.length = 0;
  57861. }
  57862. };
  57863. return OperatorList;
  57864. }();
  57865. var StateManager = function StateManagerClosure() {
  57866. function StateManager(initialState) {
  57867. this.state = initialState;
  57868. this.stateStack = [];
  57869. }
  57870. StateManager.prototype = {
  57871. save: function () {
  57872. var old = this.state;
  57873. this.stateStack.push(this.state);
  57874. this.state = old.clone();
  57875. },
  57876. restore: function () {
  57877. var prev = this.stateStack.pop();
  57878. if (prev) {
  57879. this.state = prev;
  57880. }
  57881. },
  57882. transform: function (args) {
  57883. this.state.ctm = Util.transform(this.state.ctm, args);
  57884. }
  57885. };
  57886. return StateManager;
  57887. }();
  57888. var TextState = function TextStateClosure() {
  57889. function TextState() {
  57890. this.ctm = new Float32Array(IDENTITY_MATRIX);
  57891. this.fontName = null;
  57892. this.fontSize = 0;
  57893. this.font = null;
  57894. this.fontMatrix = FONT_IDENTITY_MATRIX;
  57895. this.textMatrix = IDENTITY_MATRIX.slice();
  57896. this.textLineMatrix = IDENTITY_MATRIX.slice();
  57897. this.charSpacing = 0;
  57898. this.wordSpacing = 0;
  57899. this.leading = 0;
  57900. this.textHScale = 1;
  57901. this.textRise = 0;
  57902. }
  57903. TextState.prototype = {
  57904. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  57905. var m = this.textMatrix;
  57906. m[0] = a;
  57907. m[1] = b;
  57908. m[2] = c;
  57909. m[3] = d;
  57910. m[4] = e;
  57911. m[5] = f;
  57912. },
  57913. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  57914. var m = this.textLineMatrix;
  57915. m[0] = a;
  57916. m[1] = b;
  57917. m[2] = c;
  57918. m[3] = d;
  57919. m[4] = e;
  57920. m[5] = f;
  57921. },
  57922. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  57923. var m = this.textMatrix;
  57924. m[4] = m[0] * x + m[2] * y + m[4];
  57925. m[5] = m[1] * x + m[3] * y + m[5];
  57926. },
  57927. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  57928. var m = this.textLineMatrix;
  57929. m[4] = m[0] * x + m[2] * y + m[4];
  57930. m[5] = m[1] * x + m[3] * y + m[5];
  57931. },
  57932. calcTextLineMatrixAdvance: function TextState_calcTextLineMatrixAdvance(a, b, c, d, e, f) {
  57933. var font = this.font;
  57934. if (!font) {
  57935. return null;
  57936. }
  57937. var m = this.textLineMatrix;
  57938. if (!(a === m[0] && b === m[1] && c === m[2] && d === m[3])) {
  57939. return null;
  57940. }
  57941. var txDiff = e - m[4], tyDiff = f - m[5];
  57942. if (font.vertical && txDiff !== 0 || !font.vertical && tyDiff !== 0) {
  57943. return null;
  57944. }
  57945. var tx, ty, denominator = a * d - b * c;
  57946. if (font.vertical) {
  57947. tx = -tyDiff * c / denominator;
  57948. ty = tyDiff * a / denominator;
  57949. } else {
  57950. tx = txDiff * d / denominator;
  57951. ty = -txDiff * b / denominator;
  57952. }
  57953. return {
  57954. width: tx,
  57955. height: ty,
  57956. value: font.vertical ? ty : tx
  57957. };
  57958. },
  57959. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  57960. // 9.4.4 Text Space Details
  57961. var tsm = [
  57962. this.fontSize * this.textHScale,
  57963. 0,
  57964. 0,
  57965. this.fontSize,
  57966. 0,
  57967. this.textRise
  57968. ];
  57969. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  57970. },
  57971. carriageReturn: function TextState_carriageReturn() {
  57972. this.translateTextLineMatrix(0, -this.leading);
  57973. this.textMatrix = this.textLineMatrix.slice();
  57974. },
  57975. clone: function TextState_clone() {
  57976. var clone = Object.create(this);
  57977. clone.textMatrix = this.textMatrix.slice();
  57978. clone.textLineMatrix = this.textLineMatrix.slice();
  57979. clone.fontMatrix = this.fontMatrix.slice();
  57980. return clone;
  57981. }
  57982. };
  57983. return TextState;
  57984. }();
  57985. var EvalState = function EvalStateClosure() {
  57986. function EvalState() {
  57987. this.ctm = new Float32Array(IDENTITY_MATRIX);
  57988. this.font = null;
  57989. this.textRenderingMode = TextRenderingMode.FILL;
  57990. this.fillColorSpace = ColorSpace.singletons.gray;
  57991. this.strokeColorSpace = ColorSpace.singletons.gray;
  57992. }
  57993. EvalState.prototype = {
  57994. clone: function CanvasExtraState_clone() {
  57995. return Object.create(this);
  57996. }
  57997. };
  57998. return EvalState;
  57999. }();
  58000. var EvaluatorPreprocessor = function EvaluatorPreprocessorClosure() {
  58001. // Specifies properties for each command
  58002. //
  58003. // If variableArgs === true: [0, `numArgs`] expected
  58004. // If variableArgs === false: exactly `numArgs` expected
  58005. var getOPMap = getLookupTableFactory(function (t) {
  58006. // Graphic state
  58007. t['w'] = {
  58008. id: OPS.setLineWidth,
  58009. numArgs: 1,
  58010. variableArgs: false
  58011. };
  58012. t['J'] = {
  58013. id: OPS.setLineCap,
  58014. numArgs: 1,
  58015. variableArgs: false
  58016. };
  58017. t['j'] = {
  58018. id: OPS.setLineJoin,
  58019. numArgs: 1,
  58020. variableArgs: false
  58021. };
  58022. t['M'] = {
  58023. id: OPS.setMiterLimit,
  58024. numArgs: 1,
  58025. variableArgs: false
  58026. };
  58027. t['d'] = {
  58028. id: OPS.setDash,
  58029. numArgs: 2,
  58030. variableArgs: false
  58031. };
  58032. t['ri'] = {
  58033. id: OPS.setRenderingIntent,
  58034. numArgs: 1,
  58035. variableArgs: false
  58036. };
  58037. t['i'] = {
  58038. id: OPS.setFlatness,
  58039. numArgs: 1,
  58040. variableArgs: false
  58041. };
  58042. t['gs'] = {
  58043. id: OPS.setGState,
  58044. numArgs: 1,
  58045. variableArgs: false
  58046. };
  58047. t['q'] = {
  58048. id: OPS.save,
  58049. numArgs: 0,
  58050. variableArgs: false
  58051. };
  58052. t['Q'] = {
  58053. id: OPS.restore,
  58054. numArgs: 0,
  58055. variableArgs: false
  58056. };
  58057. t['cm'] = {
  58058. id: OPS.transform,
  58059. numArgs: 6,
  58060. variableArgs: false
  58061. };
  58062. // Path
  58063. t['m'] = {
  58064. id: OPS.moveTo,
  58065. numArgs: 2,
  58066. variableArgs: false
  58067. };
  58068. t['l'] = {
  58069. id: OPS.lineTo,
  58070. numArgs: 2,
  58071. variableArgs: false
  58072. };
  58073. t['c'] = {
  58074. id: OPS.curveTo,
  58075. numArgs: 6,
  58076. variableArgs: false
  58077. };
  58078. t['v'] = {
  58079. id: OPS.curveTo2,
  58080. numArgs: 4,
  58081. variableArgs: false
  58082. };
  58083. t['y'] = {
  58084. id: OPS.curveTo3,
  58085. numArgs: 4,
  58086. variableArgs: false
  58087. };
  58088. t['h'] = {
  58089. id: OPS.closePath,
  58090. numArgs: 0,
  58091. variableArgs: false
  58092. };
  58093. t['re'] = {
  58094. id: OPS.rectangle,
  58095. numArgs: 4,
  58096. variableArgs: false
  58097. };
  58098. t['S'] = {
  58099. id: OPS.stroke,
  58100. numArgs: 0,
  58101. variableArgs: false
  58102. };
  58103. t['s'] = {
  58104. id: OPS.closeStroke,
  58105. numArgs: 0,
  58106. variableArgs: false
  58107. };
  58108. t['f'] = {
  58109. id: OPS.fill,
  58110. numArgs: 0,
  58111. variableArgs: false
  58112. };
  58113. t['F'] = {
  58114. id: OPS.fill,
  58115. numArgs: 0,
  58116. variableArgs: false
  58117. };
  58118. t['f*'] = {
  58119. id: OPS.eoFill,
  58120. numArgs: 0,
  58121. variableArgs: false
  58122. };
  58123. t['B'] = {
  58124. id: OPS.fillStroke,
  58125. numArgs: 0,
  58126. variableArgs: false
  58127. };
  58128. t['B*'] = {
  58129. id: OPS.eoFillStroke,
  58130. numArgs: 0,
  58131. variableArgs: false
  58132. };
  58133. t['b'] = {
  58134. id: OPS.closeFillStroke,
  58135. numArgs: 0,
  58136. variableArgs: false
  58137. };
  58138. t['b*'] = {
  58139. id: OPS.closeEOFillStroke,
  58140. numArgs: 0,
  58141. variableArgs: false
  58142. };
  58143. t['n'] = {
  58144. id: OPS.endPath,
  58145. numArgs: 0,
  58146. variableArgs: false
  58147. };
  58148. // Clipping
  58149. t['W'] = {
  58150. id: OPS.clip,
  58151. numArgs: 0,
  58152. variableArgs: false
  58153. };
  58154. t['W*'] = {
  58155. id: OPS.eoClip,
  58156. numArgs: 0,
  58157. variableArgs: false
  58158. };
  58159. // Text
  58160. t['BT'] = {
  58161. id: OPS.beginText,
  58162. numArgs: 0,
  58163. variableArgs: false
  58164. };
  58165. t['ET'] = {
  58166. id: OPS.endText,
  58167. numArgs: 0,
  58168. variableArgs: false
  58169. };
  58170. t['Tc'] = {
  58171. id: OPS.setCharSpacing,
  58172. numArgs: 1,
  58173. variableArgs: false
  58174. };
  58175. t['Tw'] = {
  58176. id: OPS.setWordSpacing,
  58177. numArgs: 1,
  58178. variableArgs: false
  58179. };
  58180. t['Tz'] = {
  58181. id: OPS.setHScale,
  58182. numArgs: 1,
  58183. variableArgs: false
  58184. };
  58185. t['TL'] = {
  58186. id: OPS.setLeading,
  58187. numArgs: 1,
  58188. variableArgs: false
  58189. };
  58190. t['Tf'] = {
  58191. id: OPS.setFont,
  58192. numArgs: 2,
  58193. variableArgs: false
  58194. };
  58195. t['Tr'] = {
  58196. id: OPS.setTextRenderingMode,
  58197. numArgs: 1,
  58198. variableArgs: false
  58199. };
  58200. t['Ts'] = {
  58201. id: OPS.setTextRise,
  58202. numArgs: 1,
  58203. variableArgs: false
  58204. };
  58205. t['Td'] = {
  58206. id: OPS.moveText,
  58207. numArgs: 2,
  58208. variableArgs: false
  58209. };
  58210. t['TD'] = {
  58211. id: OPS.setLeadingMoveText,
  58212. numArgs: 2,
  58213. variableArgs: false
  58214. };
  58215. t['Tm'] = {
  58216. id: OPS.setTextMatrix,
  58217. numArgs: 6,
  58218. variableArgs: false
  58219. };
  58220. t['T*'] = {
  58221. id: OPS.nextLine,
  58222. numArgs: 0,
  58223. variableArgs: false
  58224. };
  58225. t['Tj'] = {
  58226. id: OPS.showText,
  58227. numArgs: 1,
  58228. variableArgs: false
  58229. };
  58230. t['TJ'] = {
  58231. id: OPS.showSpacedText,
  58232. numArgs: 1,
  58233. variableArgs: false
  58234. };
  58235. t['\''] = {
  58236. id: OPS.nextLineShowText,
  58237. numArgs: 1,
  58238. variableArgs: false
  58239. };
  58240. t['"'] = {
  58241. id: OPS.nextLineSetSpacingShowText,
  58242. numArgs: 3,
  58243. variableArgs: false
  58244. };
  58245. // Type3 fonts
  58246. t['d0'] = {
  58247. id: OPS.setCharWidth,
  58248. numArgs: 2,
  58249. variableArgs: false
  58250. };
  58251. t['d1'] = {
  58252. id: OPS.setCharWidthAndBounds,
  58253. numArgs: 6,
  58254. variableArgs: false
  58255. };
  58256. // Color
  58257. t['CS'] = {
  58258. id: OPS.setStrokeColorSpace,
  58259. numArgs: 1,
  58260. variableArgs: false
  58261. };
  58262. t['cs'] = {
  58263. id: OPS.setFillColorSpace,
  58264. numArgs: 1,
  58265. variableArgs: false
  58266. };
  58267. t['SC'] = {
  58268. id: OPS.setStrokeColor,
  58269. numArgs: 4,
  58270. variableArgs: true
  58271. };
  58272. t['SCN'] = {
  58273. id: OPS.setStrokeColorN,
  58274. numArgs: 33,
  58275. variableArgs: true
  58276. };
  58277. t['sc'] = {
  58278. id: OPS.setFillColor,
  58279. numArgs: 4,
  58280. variableArgs: true
  58281. };
  58282. t['scn'] = {
  58283. id: OPS.setFillColorN,
  58284. numArgs: 33,
  58285. variableArgs: true
  58286. };
  58287. t['G'] = {
  58288. id: OPS.setStrokeGray,
  58289. numArgs: 1,
  58290. variableArgs: false
  58291. };
  58292. t['g'] = {
  58293. id: OPS.setFillGray,
  58294. numArgs: 1,
  58295. variableArgs: false
  58296. };
  58297. t['RG'] = {
  58298. id: OPS.setStrokeRGBColor,
  58299. numArgs: 3,
  58300. variableArgs: false
  58301. };
  58302. t['rg'] = {
  58303. id: OPS.setFillRGBColor,
  58304. numArgs: 3,
  58305. variableArgs: false
  58306. };
  58307. t['K'] = {
  58308. id: OPS.setStrokeCMYKColor,
  58309. numArgs: 4,
  58310. variableArgs: false
  58311. };
  58312. t['k'] = {
  58313. id: OPS.setFillCMYKColor,
  58314. numArgs: 4,
  58315. variableArgs: false
  58316. };
  58317. // Shading
  58318. t['sh'] = {
  58319. id: OPS.shadingFill,
  58320. numArgs: 1,
  58321. variableArgs: false
  58322. };
  58323. // Images
  58324. t['BI'] = {
  58325. id: OPS.beginInlineImage,
  58326. numArgs: 0,
  58327. variableArgs: false
  58328. };
  58329. t['ID'] = {
  58330. id: OPS.beginImageData,
  58331. numArgs: 0,
  58332. variableArgs: false
  58333. };
  58334. t['EI'] = {
  58335. id: OPS.endInlineImage,
  58336. numArgs: 1,
  58337. variableArgs: false
  58338. };
  58339. // XObjects
  58340. t['Do'] = {
  58341. id: OPS.paintXObject,
  58342. numArgs: 1,
  58343. variableArgs: false
  58344. };
  58345. t['MP'] = {
  58346. id: OPS.markPoint,
  58347. numArgs: 1,
  58348. variableArgs: false
  58349. };
  58350. t['DP'] = {
  58351. id: OPS.markPointProps,
  58352. numArgs: 2,
  58353. variableArgs: false
  58354. };
  58355. t['BMC'] = {
  58356. id: OPS.beginMarkedContent,
  58357. numArgs: 1,
  58358. variableArgs: false
  58359. };
  58360. t['BDC'] = {
  58361. id: OPS.beginMarkedContentProps,
  58362. numArgs: 2,
  58363. variableArgs: false
  58364. };
  58365. t['EMC'] = {
  58366. id: OPS.endMarkedContent,
  58367. numArgs: 0,
  58368. variableArgs: false
  58369. };
  58370. // Compatibility
  58371. t['BX'] = {
  58372. id: OPS.beginCompat,
  58373. numArgs: 0,
  58374. variableArgs: false
  58375. };
  58376. t['EX'] = {
  58377. id: OPS.endCompat,
  58378. numArgs: 0,
  58379. variableArgs: false
  58380. };
  58381. // (reserved partial commands for the lexer)
  58382. t['BM'] = null;
  58383. t['BD'] = null;
  58384. t['true'] = null;
  58385. t['fa'] = null;
  58386. t['fal'] = null;
  58387. t['fals'] = null;
  58388. t['false'] = null;
  58389. t['nu'] = null;
  58390. t['nul'] = null;
  58391. t['null'] = null;
  58392. });
  58393. function EvaluatorPreprocessor(stream, xref, stateManager) {
  58394. this.opMap = getOPMap();
  58395. // TODO(mduan): pass array of knownCommands rather than this.opMap
  58396. // dictionary
  58397. this.parser = new Parser(new Lexer(stream, this.opMap), false, xref);
  58398. this.stateManager = stateManager;
  58399. this.nonProcessedArgs = [];
  58400. }
  58401. EvaluatorPreprocessor.prototype = {
  58402. get savedStatesDepth() {
  58403. return this.stateManager.stateStack.length;
  58404. },
  58405. // |operation| is an object with two fields:
  58406. //
  58407. // - |fn| is an out param.
  58408. //
  58409. // - |args| is an inout param. On entry, it should have one of two values.
  58410. //
  58411. // - An empty array. This indicates that the caller is providing the
  58412. // array in which the args will be stored in. The caller should use
  58413. // this value if it can reuse a single array for each call to read().
  58414. //
  58415. // - |null|. This indicates that the caller needs this function to create
  58416. // the array in which any args are stored in. If there are zero args,
  58417. // this function will leave |operation.args| as |null| (thus avoiding
  58418. // allocations that would occur if we used an empty array to represent
  58419. // zero arguments). Otherwise, it will replace |null| with a new array
  58420. // containing the arguments. The caller should use this value if it
  58421. // cannot reuse an array for each call to read().
  58422. //
  58423. // These two modes are present because this function is very hot and so
  58424. // avoiding allocations where possible is worthwhile.
  58425. //
  58426. read: function EvaluatorPreprocessor_read(operation) {
  58427. var args = operation.args;
  58428. while (true) {
  58429. var obj = this.parser.getObj();
  58430. if (isCmd(obj)) {
  58431. var cmd = obj.cmd;
  58432. // Check that the command is valid
  58433. var opSpec = this.opMap[cmd];
  58434. if (!opSpec) {
  58435. warn('Unknown command "' + cmd + '"');
  58436. continue;
  58437. }
  58438. var fn = opSpec.id;
  58439. var numArgs = opSpec.numArgs;
  58440. var argsLength = args !== null ? args.length : 0;
  58441. if (!opSpec.variableArgs) {
  58442. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  58443. if (argsLength !== numArgs) {
  58444. var nonProcessedArgs = this.nonProcessedArgs;
  58445. while (argsLength > numArgs) {
  58446. nonProcessedArgs.push(args.shift());
  58447. argsLength--;
  58448. }
  58449. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  58450. if (!args) {
  58451. args = [];
  58452. }
  58453. args.unshift(nonProcessedArgs.pop());
  58454. argsLength++;
  58455. }
  58456. }
  58457. if (argsLength < numArgs) {
  58458. // If we receive too few args, it's not possible to possible
  58459. // to execute the command, so skip the command
  58460. info('Command ' + fn + ': because expected ' + numArgs + ' args, but received ' + argsLength + ' args; skipping');
  58461. args = null;
  58462. continue;
  58463. }
  58464. } else if (argsLength > numArgs) {
  58465. info('Command ' + fn + ': expected [0,' + numArgs + '] args, but received ' + argsLength + ' args');
  58466. }
  58467. // TODO figure out how to type-check vararg functions
  58468. this.preprocessCommand(fn, args);
  58469. operation.fn = fn;
  58470. operation.args = args;
  58471. return true;
  58472. } else {
  58473. if (isEOF(obj)) {
  58474. return false;
  58475. }
  58476. // no more commands
  58477. // argument
  58478. if (obj !== null) {
  58479. if (!args) {
  58480. args = [];
  58481. }
  58482. args.push(obj);
  58483. assert(args.length <= 33, 'Too many arguments');
  58484. }
  58485. }
  58486. }
  58487. },
  58488. preprocessCommand: function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  58489. switch (fn | 0) {
  58490. case OPS.save:
  58491. this.stateManager.save();
  58492. break;
  58493. case OPS.restore:
  58494. this.stateManager.restore();
  58495. break;
  58496. case OPS.transform:
  58497. this.stateManager.transform(args);
  58498. break;
  58499. }
  58500. }
  58501. };
  58502. return EvaluatorPreprocessor;
  58503. }();
  58504. var QueueOptimizer = function QueueOptimizerClosure() {
  58505. function addState(parentState, pattern, fn) {
  58506. var state = parentState;
  58507. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  58508. var item = pattern[i];
  58509. state = state[item] || (state[item] = []);
  58510. }
  58511. state[pattern[pattern.length - 1]] = fn;
  58512. }
  58513. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray, argsArray) {
  58514. // Handles special case of mainly LaTeX documents which use image masks to
  58515. // draw lines with the current fill style.
  58516. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  58517. // have been found at iFirstSave.
  58518. var iFirstPIMXO = iFirstSave + 2;
  58519. for (var i = 0; i < count; i++) {
  58520. var arg = argsArray[iFirstPIMXO + 4 * i];
  58521. var imageMask = arg.length === 1 && arg[0];
  58522. if (imageMask && imageMask.width === 1 && imageMask.height === 1 && (!imageMask.data.length || imageMask.data.length === 1 && imageMask.data[0] === 0)) {
  58523. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  58524. continue;
  58525. }
  58526. break;
  58527. }
  58528. return count - i;
  58529. }
  58530. var InitialState = [];
  58531. // This replaces (save, transform, paintInlineImageXObject, restore)+
  58532. // sequences with one |paintInlineImageXObjectGroup| operation.
  58533. addState(InitialState, [
  58534. OPS.save,
  58535. OPS.transform,
  58536. OPS.paintInlineImageXObject,
  58537. OPS.restore
  58538. ], function foundInlineImageGroup(context) {
  58539. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  58540. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  58541. var MAX_WIDTH = 1000;
  58542. var IMAGE_PADDING = 1;
  58543. var fnArray = context.fnArray, argsArray = context.argsArray;
  58544. var curr = context.iCurr;
  58545. var iFirstSave = curr - 3;
  58546. var iFirstTransform = curr - 2;
  58547. var iFirstPIIXO = curr - 1;
  58548. // Look for the quartets.
  58549. var i = iFirstSave + 4;
  58550. var ii = fnArray.length;
  58551. while (i + 3 < ii) {
  58552. if (fnArray[i] !== OPS.save || fnArray[i + 1] !== OPS.transform || fnArray[i + 2] !== OPS.paintInlineImageXObject || fnArray[i + 3] !== OPS.restore) {
  58553. break;
  58554. }
  58555. // ops don't match
  58556. i += 4;
  58557. }
  58558. // At this point, i is the index of the first op past the last valid
  58559. // quartet.
  58560. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  58561. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  58562. return i;
  58563. }
  58564. // assuming that heights of those image is too small (~1 pixel)
  58565. // packing as much as possible by lines
  58566. var maxX = 0;
  58567. var map = [], maxLineHeight = 0;
  58568. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  58569. var q;
  58570. for (q = 0; q < count; q++) {
  58571. var transform = argsArray[iFirstTransform + (q << 2)];
  58572. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  58573. if (currentX + img.width > MAX_WIDTH) {
  58574. // starting new line
  58575. maxX = Math.max(maxX, currentX);
  58576. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  58577. currentX = 0;
  58578. maxLineHeight = 0;
  58579. }
  58580. map.push({
  58581. transform: transform,
  58582. x: currentX,
  58583. y: currentY,
  58584. w: img.width,
  58585. h: img.height
  58586. });
  58587. currentX += img.width + 2 * IMAGE_PADDING;
  58588. maxLineHeight = Math.max(maxLineHeight, img.height);
  58589. }
  58590. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  58591. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  58592. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  58593. var imgRowSize = imgWidth << 2;
  58594. for (q = 0; q < count; q++) {
  58595. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  58596. // Copy image by lines and extends pixels into padding.
  58597. var rowSize = map[q].w << 2;
  58598. var dataOffset = 0;
  58599. var offset = map[q].x + map[q].y * imgWidth << 2;
  58600. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  58601. for (var k = 0, kk = map[q].h; k < kk; k++) {
  58602. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  58603. dataOffset += rowSize;
  58604. offset += imgRowSize;
  58605. }
  58606. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  58607. while (offset >= 0) {
  58608. data[offset - 4] = data[offset];
  58609. data[offset - 3] = data[offset + 1];
  58610. data[offset - 2] = data[offset + 2];
  58611. data[offset - 1] = data[offset + 3];
  58612. data[offset + rowSize] = data[offset + rowSize - 4];
  58613. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  58614. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  58615. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  58616. offset -= imgRowSize;
  58617. }
  58618. }
  58619. // Replace queue items.
  58620. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  58621. argsArray.splice(iFirstSave, count * 4, [
  58622. {
  58623. width: imgWidth,
  58624. height: imgHeight,
  58625. kind: ImageKind.RGBA_32BPP,
  58626. data: imgData
  58627. },
  58628. map
  58629. ]);
  58630. return iFirstSave + 1;
  58631. });
  58632. // This replaces (save, transform, paintImageMaskXObject, restore)+
  58633. // sequences with one |paintImageMaskXObjectGroup| or one
  58634. // |paintImageMaskXObjectRepeat| operation.
  58635. addState(InitialState, [
  58636. OPS.save,
  58637. OPS.transform,
  58638. OPS.paintImageMaskXObject,
  58639. OPS.restore
  58640. ], function foundImageMaskGroup(context) {
  58641. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  58642. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  58643. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  58644. var fnArray = context.fnArray, argsArray = context.argsArray;
  58645. var curr = context.iCurr;
  58646. var iFirstSave = curr - 3;
  58647. var iFirstTransform = curr - 2;
  58648. var iFirstPIMXO = curr - 1;
  58649. // Look for the quartets.
  58650. var i = iFirstSave + 4;
  58651. var ii = fnArray.length;
  58652. while (i + 3 < ii) {
  58653. if (fnArray[i] !== OPS.save || fnArray[i + 1] !== OPS.transform || fnArray[i + 2] !== OPS.paintImageMaskXObject || fnArray[i + 3] !== OPS.restore) {
  58654. break;
  58655. }
  58656. // ops don't match
  58657. i += 4;
  58658. }
  58659. // At this point, i is the index of the first op past the last valid
  58660. // quartet.
  58661. var count = (i - iFirstSave) / 4;
  58662. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray, argsArray);
  58663. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  58664. return i;
  58665. }
  58666. var q;
  58667. var isSameImage = false;
  58668. var iTransform, transformArgs;
  58669. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  58670. if (argsArray[iFirstTransform][1] === 0 && argsArray[iFirstTransform][2] === 0) {
  58671. isSameImage = true;
  58672. var firstTransformArg0 = argsArray[iFirstTransform][0];
  58673. var firstTransformArg3 = argsArray[iFirstTransform][3];
  58674. iTransform = iFirstTransform + 4;
  58675. var iPIMXO = iFirstPIMXO + 4;
  58676. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  58677. transformArgs = argsArray[iTransform];
  58678. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 || transformArgs[0] !== firstTransformArg0 || transformArgs[1] !== 0 || transformArgs[2] !== 0 || transformArgs[3] !== firstTransformArg3) {
  58679. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  58680. isSameImage = false;
  58681. } else {
  58682. count = q;
  58683. }
  58684. break;
  58685. }
  58686. }
  58687. }
  58688. // different image or transform
  58689. if (isSameImage) {
  58690. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  58691. var positions = new Float32Array(count * 2);
  58692. iTransform = iFirstTransform;
  58693. for (q = 0; q < count; q++, iTransform += 4) {
  58694. transformArgs = argsArray[iTransform];
  58695. positions[q << 1] = transformArgs[4];
  58696. positions[(q << 1) + 1] = transformArgs[5];
  58697. }
  58698. // Replace queue items.
  58699. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  58700. argsArray.splice(iFirstSave, count * 4, [
  58701. firstPIMXOArg0,
  58702. firstTransformArg0,
  58703. firstTransformArg3,
  58704. positions
  58705. ]);
  58706. } else {
  58707. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  58708. var images = [];
  58709. for (q = 0; q < count; q++) {
  58710. transformArgs = argsArray[iFirstTransform + (q << 2)];
  58711. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  58712. images.push({
  58713. data: maskParams.data,
  58714. width: maskParams.width,
  58715. height: maskParams.height,
  58716. transform: transformArgs
  58717. });
  58718. }
  58719. // Replace queue items.
  58720. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  58721. argsArray.splice(iFirstSave, count * 4, [images]);
  58722. }
  58723. return iFirstSave + 1;
  58724. });
  58725. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  58726. // with one paintImageXObjectRepeat operation, if the |transform| and
  58727. // |paintImageXObjectRepeat| ops are appropriate.
  58728. addState(InitialState, [
  58729. OPS.save,
  58730. OPS.transform,
  58731. OPS.paintImageXObject,
  58732. OPS.restore
  58733. ], function (context) {
  58734. var MIN_IMAGES_IN_BLOCK = 3;
  58735. var MAX_IMAGES_IN_BLOCK = 1000;
  58736. var fnArray = context.fnArray, argsArray = context.argsArray;
  58737. var curr = context.iCurr;
  58738. var iFirstSave = curr - 3;
  58739. var iFirstTransform = curr - 2;
  58740. var iFirstPIXO = curr - 1;
  58741. var iFirstRestore = curr;
  58742. if (argsArray[iFirstTransform][1] !== 0 || argsArray[iFirstTransform][2] !== 0) {
  58743. return iFirstRestore + 1;
  58744. }
  58745. // transform has the wrong form
  58746. // Look for the quartets.
  58747. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  58748. var firstTransformArg0 = argsArray[iFirstTransform][0];
  58749. var firstTransformArg3 = argsArray[iFirstTransform][3];
  58750. var i = iFirstSave + 4;
  58751. var ii = fnArray.length;
  58752. while (i + 3 < ii) {
  58753. if (fnArray[i] !== OPS.save || fnArray[i + 1] !== OPS.transform || fnArray[i + 2] !== OPS.paintImageXObject || fnArray[i + 3] !== OPS.restore) {
  58754. break;
  58755. }
  58756. // ops don't match
  58757. if (argsArray[i + 1][0] !== firstTransformArg0 || argsArray[i + 1][1] !== 0 || argsArray[i + 1][2] !== 0 || argsArray[i + 1][3] !== firstTransformArg3) {
  58758. break;
  58759. }
  58760. // transforms don't match
  58761. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  58762. break;
  58763. }
  58764. // images don't match
  58765. i += 4;
  58766. }
  58767. // At this point, i is the index of the first op past the last valid
  58768. // quartet.
  58769. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  58770. if (count < MIN_IMAGES_IN_BLOCK) {
  58771. return i;
  58772. }
  58773. // Extract the (x,y) positions from all of the matching transforms.
  58774. var positions = new Float32Array(count * 2);
  58775. var iTransform = iFirstTransform;
  58776. for (var q = 0; q < count; q++, iTransform += 4) {
  58777. var transformArgs = argsArray[iTransform];
  58778. positions[q << 1] = transformArgs[4];
  58779. positions[(q << 1) + 1] = transformArgs[5];
  58780. }
  58781. // Replace queue items.
  58782. var args = [
  58783. firstPIXOArg0,
  58784. firstTransformArg0,
  58785. firstTransformArg3,
  58786. positions
  58787. ];
  58788. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  58789. argsArray.splice(iFirstSave, count * 4, args);
  58790. return iFirstSave + 1;
  58791. });
  58792. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  58793. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  58794. // sequences, if the font for each one is the same.
  58795. addState(InitialState, [
  58796. OPS.beginText,
  58797. OPS.setFont,
  58798. OPS.setTextMatrix,
  58799. OPS.showText,
  58800. OPS.endText
  58801. ], function (context) {
  58802. var MIN_CHARS_IN_BLOCK = 3;
  58803. var MAX_CHARS_IN_BLOCK = 1000;
  58804. var fnArray = context.fnArray, argsArray = context.argsArray;
  58805. var curr = context.iCurr;
  58806. var iFirstBeginText = curr - 4;
  58807. var iFirstSetFont = curr - 3;
  58808. var iFirstSetTextMatrix = curr - 2;
  58809. var iFirstShowText = curr - 1;
  58810. var iFirstEndText = curr;
  58811. // Look for the quintets.
  58812. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  58813. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  58814. var i = iFirstBeginText + 5;
  58815. var ii = fnArray.length;
  58816. while (i + 4 < ii) {
  58817. if (fnArray[i] !== OPS.beginText || fnArray[i + 1] !== OPS.setFont || fnArray[i + 2] !== OPS.setTextMatrix || fnArray[i + 3] !== OPS.showText || fnArray[i + 4] !== OPS.endText) {
  58818. break;
  58819. }
  58820. // ops don't match
  58821. if (argsArray[i + 1][0] !== firstSetFontArg0 || argsArray[i + 1][1] !== firstSetFontArg1) {
  58822. break;
  58823. }
  58824. // fonts don't match
  58825. i += 5;
  58826. }
  58827. // At this point, i is the index of the first op past the last valid
  58828. // quintet.
  58829. var count = Math.min((i - iFirstBeginText) / 5, MAX_CHARS_IN_BLOCK);
  58830. if (count < MIN_CHARS_IN_BLOCK) {
  58831. return i;
  58832. }
  58833. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  58834. // showText, endText), include that as well. (E.g. <something> might be
  58835. // |dependency|.)
  58836. var iFirst = iFirstBeginText;
  58837. if (iFirstBeginText >= 4 && fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] && fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] && fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] && fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] && argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 && argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  58838. count++;
  58839. iFirst -= 5;
  58840. }
  58841. // Remove (endText, beginText, setFont) trios.
  58842. var iEndText = iFirst + 4;
  58843. for (var q = 1; q < count; q++) {
  58844. fnArray.splice(iEndText, 3);
  58845. argsArray.splice(iEndText, 3);
  58846. iEndText += 2;
  58847. }
  58848. return iEndText + 1;
  58849. });
  58850. function QueueOptimizer() {
  58851. }
  58852. QueueOptimizer.prototype = {
  58853. optimize: function QueueOptimizer_optimize(queue) {
  58854. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  58855. var context = {
  58856. iCurr: 0,
  58857. fnArray: fnArray,
  58858. argsArray: argsArray
  58859. };
  58860. var state;
  58861. var i = 0, ii = fnArray.length;
  58862. while (i < ii) {
  58863. state = (state || InitialState)[fnArray[i]];
  58864. if (typeof state === 'function') {
  58865. // we found some handler
  58866. context.iCurr = i;
  58867. // state() returns the index of the first non-matching op (if we
  58868. // didn't match) or the first op past the modified ops (if we did
  58869. // match and replace).
  58870. i = state(context);
  58871. state = undefined;
  58872. // reset the state machine
  58873. ii = context.fnArray.length;
  58874. } else {
  58875. i++;
  58876. }
  58877. }
  58878. }
  58879. };
  58880. return QueueOptimizer;
  58881. }();
  58882. exports.OperatorList = OperatorList;
  58883. exports.PartialEvaluator = PartialEvaluator;
  58884. }));
  58885. (function (root, factory) {
  58886. factory(root.pdfjsCoreAnnotation = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreColorSpace, root.pdfjsCoreObj, root.pdfjsCoreEvaluator);
  58887. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreColorSpace, coreObj, coreEvaluator) {
  58888. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  58889. var AnnotationFieldFlag = sharedUtil.AnnotationFieldFlag;
  58890. var AnnotationFlag = sharedUtil.AnnotationFlag;
  58891. var AnnotationType = sharedUtil.AnnotationType;
  58892. var OPS = sharedUtil.OPS;
  58893. var Util = sharedUtil.Util;
  58894. var isBool = sharedUtil.isBool;
  58895. var isString = sharedUtil.isString;
  58896. var isArray = sharedUtil.isArray;
  58897. var isInt = sharedUtil.isInt;
  58898. var isValidUrl = sharedUtil.isValidUrl;
  58899. var stringToBytes = sharedUtil.stringToBytes;
  58900. var stringToPDFString = sharedUtil.stringToPDFString;
  58901. var stringToUTF8String = sharedUtil.stringToUTF8String;
  58902. var warn = sharedUtil.warn;
  58903. var Dict = corePrimitives.Dict;
  58904. var isDict = corePrimitives.isDict;
  58905. var isName = corePrimitives.isName;
  58906. var isRef = corePrimitives.isRef;
  58907. var Stream = coreStream.Stream;
  58908. var ColorSpace = coreColorSpace.ColorSpace;
  58909. var ObjectLoader = coreObj.ObjectLoader;
  58910. var FileSpec = coreObj.FileSpec;
  58911. var OperatorList = coreEvaluator.OperatorList;
  58912. /**
  58913. * @class
  58914. * @alias AnnotationFactory
  58915. */
  58916. function AnnotationFactory() {
  58917. }
  58918. AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */
  58919. {
  58920. /**
  58921. * @param {XRef} xref
  58922. * @param {Object} ref
  58923. * @param {string} uniquePrefix
  58924. * @param {Object} idCounters
  58925. * @returns {Annotation}
  58926. */
  58927. create: function AnnotationFactory_create(xref, ref, uniquePrefix, idCounters) {
  58928. var dict = xref.fetchIfRef(ref);
  58929. if (!isDict(dict)) {
  58930. return;
  58931. }
  58932. var id = isRef(ref) ? ref.toString() : 'annot_' + (uniquePrefix || '') + ++idCounters.obj;
  58933. // Determine the annotation's subtype.
  58934. var subtype = dict.get('Subtype');
  58935. subtype = isName(subtype) ? subtype.name : null;
  58936. // Return the right annotation object based on the subtype and field type.
  58937. var parameters = {
  58938. xref: xref,
  58939. dict: dict,
  58940. ref: isRef(ref) ? ref : null,
  58941. subtype: subtype,
  58942. id: id
  58943. };
  58944. switch (subtype) {
  58945. case 'Link':
  58946. return new LinkAnnotation(parameters);
  58947. case 'Text':
  58948. return new TextAnnotation(parameters);
  58949. case 'Widget':
  58950. var fieldType = Util.getInheritableProperty(dict, 'FT');
  58951. fieldType = isName(fieldType) ? fieldType.name : null;
  58952. switch (fieldType) {
  58953. case 'Tx':
  58954. return new TextWidgetAnnotation(parameters);
  58955. case 'Ch':
  58956. return new ChoiceWidgetAnnotation(parameters);
  58957. }
  58958. warn('Unimplemented widget field type "' + fieldType + '", ' + 'falling back to base field type.');
  58959. return new WidgetAnnotation(parameters);
  58960. case 'Popup':
  58961. return new PopupAnnotation(parameters);
  58962. case 'Highlight':
  58963. return new HighlightAnnotation(parameters);
  58964. case 'Underline':
  58965. return new UnderlineAnnotation(parameters);
  58966. case 'Squiggly':
  58967. return new SquigglyAnnotation(parameters);
  58968. case 'StrikeOut':
  58969. return new StrikeOutAnnotation(parameters);
  58970. case 'FileAttachment':
  58971. return new FileAttachmentAnnotation(parameters);
  58972. default:
  58973. if (!subtype) {
  58974. warn('Annotation is missing the required /Subtype.');
  58975. } else {
  58976. warn('Unimplemented annotation type "' + subtype + '", ' + 'falling back to base annotation.');
  58977. }
  58978. return new Annotation(parameters);
  58979. }
  58980. }
  58981. };
  58982. var Annotation = function AnnotationClosure() {
  58983. // 12.5.5: Algorithm: Appearance streams
  58984. function getTransformMatrix(rect, bbox, matrix) {
  58985. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  58986. var minX = bounds[0];
  58987. var minY = bounds[1];
  58988. var maxX = bounds[2];
  58989. var maxY = bounds[3];
  58990. if (minX === maxX || minY === maxY) {
  58991. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  58992. // just apply the transform for rect
  58993. return [
  58994. 1,
  58995. 0,
  58996. 0,
  58997. 1,
  58998. rect[0],
  58999. rect[1]
  59000. ];
  59001. }
  59002. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  59003. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  59004. return [
  59005. xRatio,
  59006. 0,
  59007. 0,
  59008. yRatio,
  59009. rect[0] - minX * xRatio,
  59010. rect[1] - minY * yRatio
  59011. ];
  59012. }
  59013. function getDefaultAppearance(dict) {
  59014. var appearanceState = dict.get('AP');
  59015. if (!isDict(appearanceState)) {
  59016. return;
  59017. }
  59018. var appearance;
  59019. var appearances = appearanceState.get('N');
  59020. if (isDict(appearances)) {
  59021. var as = dict.get('AS');
  59022. if (as && appearances.has(as.name)) {
  59023. appearance = appearances.get(as.name);
  59024. }
  59025. } else {
  59026. appearance = appearances;
  59027. }
  59028. return appearance;
  59029. }
  59030. function Annotation(params) {
  59031. var dict = params.dict;
  59032. this.setFlags(dict.get('F'));
  59033. this.setRectangle(dict.getArray('Rect'));
  59034. this.setColor(dict.getArray('C'));
  59035. this.setBorderStyle(dict);
  59036. this.appearance = getDefaultAppearance(dict);
  59037. // Expose public properties using a data object.
  59038. this.data = {};
  59039. this.data.id = params.id;
  59040. this.data.subtype = params.subtype;
  59041. this.data.annotationFlags = this.flags;
  59042. this.data.rect = this.rectangle;
  59043. this.data.color = this.color;
  59044. this.data.borderStyle = this.borderStyle;
  59045. this.data.hasAppearance = !!this.appearance;
  59046. }
  59047. Annotation.prototype = {
  59048. /**
  59049. * @private
  59050. */
  59051. _hasFlag: function Annotation_hasFlag(flags, flag) {
  59052. return !!(flags & flag);
  59053. },
  59054. /**
  59055. * @private
  59056. */
  59057. _isViewable: function Annotation_isViewable(flags) {
  59058. return !this._hasFlag(flags, AnnotationFlag.INVISIBLE) && !this._hasFlag(flags, AnnotationFlag.HIDDEN) && !this._hasFlag(flags, AnnotationFlag.NOVIEW);
  59059. },
  59060. /**
  59061. * @private
  59062. */
  59063. _isPrintable: function AnnotationFlag_isPrintable(flags) {
  59064. return this._hasFlag(flags, AnnotationFlag.PRINT) && !this._hasFlag(flags, AnnotationFlag.INVISIBLE) && !this._hasFlag(flags, AnnotationFlag.HIDDEN);
  59065. },
  59066. /**
  59067. * @return {boolean}
  59068. */
  59069. get viewable() {
  59070. if (this.flags === 0) {
  59071. return true;
  59072. }
  59073. return this._isViewable(this.flags);
  59074. },
  59075. /**
  59076. * @return {boolean}
  59077. */
  59078. get printable() {
  59079. if (this.flags === 0) {
  59080. return false;
  59081. }
  59082. return this._isPrintable(this.flags);
  59083. },
  59084. /**
  59085. * Set the flags.
  59086. *
  59087. * @public
  59088. * @memberof Annotation
  59089. * @param {number} flags - Unsigned 32-bit integer specifying annotation
  59090. * characteristics
  59091. * @see {@link shared/util.js}
  59092. */
  59093. setFlags: function Annotation_setFlags(flags) {
  59094. this.flags = isInt(flags) && flags > 0 ? flags : 0;
  59095. },
  59096. /**
  59097. * Check if a provided flag is set.
  59098. *
  59099. * @public
  59100. * @memberof Annotation
  59101. * @param {number} flag - Hexadecimal representation for an annotation
  59102. * characteristic
  59103. * @return {boolean}
  59104. * @see {@link shared/util.js}
  59105. */
  59106. hasFlag: function Annotation_hasFlag(flag) {
  59107. return this._hasFlag(this.flags, flag);
  59108. },
  59109. /**
  59110. * Set the rectangle.
  59111. *
  59112. * @public
  59113. * @memberof Annotation
  59114. * @param {Array} rectangle - The rectangle array with exactly four entries
  59115. */
  59116. setRectangle: function Annotation_setRectangle(rectangle) {
  59117. if (isArray(rectangle) && rectangle.length === 4) {
  59118. this.rectangle = Util.normalizeRect(rectangle);
  59119. } else {
  59120. this.rectangle = [
  59121. 0,
  59122. 0,
  59123. 0,
  59124. 0
  59125. ];
  59126. }
  59127. },
  59128. /**
  59129. * Set the color and take care of color space conversion.
  59130. *
  59131. * @public
  59132. * @memberof Annotation
  59133. * @param {Array} color - The color array containing either 0
  59134. * (transparent), 1 (grayscale), 3 (RGB) or
  59135. * 4 (CMYK) elements
  59136. */
  59137. setColor: function Annotation_setColor(color) {
  59138. var rgbColor = new Uint8Array(3);
  59139. // Black in RGB color space (default)
  59140. if (!isArray(color)) {
  59141. this.color = rgbColor;
  59142. return;
  59143. }
  59144. switch (color.length) {
  59145. case 0:
  59146. // Transparent, which we indicate with a null value
  59147. this.color = null;
  59148. break;
  59149. case 1:
  59150. // Convert grayscale to RGB
  59151. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  59152. this.color = rgbColor;
  59153. break;
  59154. case 3:
  59155. // Convert RGB percentages to RGB
  59156. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  59157. this.color = rgbColor;
  59158. break;
  59159. case 4:
  59160. // Convert CMYK to RGB
  59161. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  59162. this.color = rgbColor;
  59163. break;
  59164. default:
  59165. this.color = rgbColor;
  59166. break;
  59167. }
  59168. },
  59169. /**
  59170. * Set the border style (as AnnotationBorderStyle object).
  59171. *
  59172. * @public
  59173. * @memberof Annotation
  59174. * @param {Dict} borderStyle - The border style dictionary
  59175. */
  59176. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  59177. this.borderStyle = new AnnotationBorderStyle();
  59178. if (!isDict(borderStyle)) {
  59179. return;
  59180. }
  59181. if (borderStyle.has('BS')) {
  59182. var dict = borderStyle.get('BS');
  59183. var dictType = dict.get('Type');
  59184. if (!dictType || isName(dictType, 'Border')) {
  59185. this.borderStyle.setWidth(dict.get('W'));
  59186. this.borderStyle.setStyle(dict.get('S'));
  59187. this.borderStyle.setDashArray(dict.getArray('D'));
  59188. }
  59189. } else if (borderStyle.has('Border')) {
  59190. var array = borderStyle.getArray('Border');
  59191. if (isArray(array) && array.length >= 3) {
  59192. this.borderStyle.setHorizontalCornerRadius(array[0]);
  59193. this.borderStyle.setVerticalCornerRadius(array[1]);
  59194. this.borderStyle.setWidth(array[2]);
  59195. if (array.length === 4) {
  59196. // Dash array available
  59197. this.borderStyle.setDashArray(array[3]);
  59198. }
  59199. }
  59200. } else {
  59201. // There are no border entries in the dictionary. According to the
  59202. // specification, we should draw a solid border of width 1 in that
  59203. // case, but Adobe Reader did not implement that part of the
  59204. // specification and instead draws no border at all, so we do the same.
  59205. // See also https://github.com/mozilla/pdf.js/issues/6179.
  59206. this.borderStyle.setWidth(0);
  59207. }
  59208. },
  59209. /**
  59210. * Prepare the annotation for working with a popup in the display layer.
  59211. *
  59212. * @private
  59213. * @memberof Annotation
  59214. * @param {Dict} dict - The annotation's data dictionary
  59215. */
  59216. _preparePopup: function Annotation_preparePopup(dict) {
  59217. if (!dict.has('C')) {
  59218. // Fall back to the default background color.
  59219. this.data.color = null;
  59220. }
  59221. this.data.hasPopup = dict.has('Popup');
  59222. this.data.title = stringToPDFString(dict.get('T') || '');
  59223. this.data.contents = stringToPDFString(dict.get('Contents') || '');
  59224. },
  59225. loadResources: function Annotation_loadResources(keys) {
  59226. return new Promise(function (resolve, reject) {
  59227. this.appearance.dict.getAsync('Resources').then(function (resources) {
  59228. if (!resources) {
  59229. resolve();
  59230. return;
  59231. }
  59232. var objectLoader = new ObjectLoader(resources.map, keys, resources.xref);
  59233. objectLoader.load().then(function () {
  59234. resolve(resources);
  59235. }, reject);
  59236. }, reject);
  59237. }.bind(this));
  59238. },
  59239. getOperatorList: function Annotation_getOperatorList(evaluator, task, renderForms) {
  59240. if (!this.appearance) {
  59241. return Promise.resolve(new OperatorList());
  59242. }
  59243. var data = this.data;
  59244. var appearanceDict = this.appearance.dict;
  59245. var resourcesPromise = this.loadResources([
  59246. 'ExtGState',
  59247. 'ColorSpace',
  59248. 'Pattern',
  59249. 'Shading',
  59250. 'XObject',
  59251. 'Font'
  59252. ]);
  59253. // ProcSet
  59254. // Properties
  59255. var bbox = appearanceDict.getArray('BBox') || [
  59256. 0,
  59257. 0,
  59258. 1,
  59259. 1
  59260. ];
  59261. var matrix = appearanceDict.getArray('Matrix') || [
  59262. 1,
  59263. 0,
  59264. 0,
  59265. 1,
  59266. 0,
  59267. 0
  59268. ];
  59269. var transform = getTransformMatrix(data.rect, bbox, matrix);
  59270. var self = this;
  59271. return resourcesPromise.then(function (resources) {
  59272. var opList = new OperatorList();
  59273. opList.addOp(OPS.beginAnnotation, [
  59274. data.rect,
  59275. transform,
  59276. matrix
  59277. ]);
  59278. return evaluator.getOperatorList(self.appearance, task, resources, opList).then(function () {
  59279. opList.addOp(OPS.endAnnotation, []);
  59280. self.appearance.reset();
  59281. return opList;
  59282. });
  59283. });
  59284. }
  59285. };
  59286. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(annotations, opList, partialEvaluator, task, intent, renderForms) {
  59287. var annotationPromises = [];
  59288. for (var i = 0, n = annotations.length; i < n; ++i) {
  59289. if (intent === 'display' && annotations[i].viewable || intent === 'print' && annotations[i].printable) {
  59290. annotationPromises.push(annotations[i].getOperatorList(partialEvaluator, task, renderForms));
  59291. }
  59292. }
  59293. return Promise.all(annotationPromises).then(function (operatorLists) {
  59294. opList.addOp(OPS.beginAnnotations, []);
  59295. for (var i = 0, n = operatorLists.length; i < n; ++i) {
  59296. opList.addOpList(operatorLists[i]);
  59297. }
  59298. opList.addOp(OPS.endAnnotations, []);
  59299. });
  59300. };
  59301. return Annotation;
  59302. }();
  59303. /**
  59304. * Contains all data regarding an annotation's border style.
  59305. *
  59306. * @class
  59307. */
  59308. var AnnotationBorderStyle = function AnnotationBorderStyleClosure() {
  59309. /**
  59310. * @constructor
  59311. * @private
  59312. */
  59313. function AnnotationBorderStyle() {
  59314. this.width = 1;
  59315. this.style = AnnotationBorderStyleType.SOLID;
  59316. this.dashArray = [3];
  59317. this.horizontalCornerRadius = 0;
  59318. this.verticalCornerRadius = 0;
  59319. }
  59320. AnnotationBorderStyle.prototype = {
  59321. /**
  59322. * Set the width.
  59323. *
  59324. * @public
  59325. * @memberof AnnotationBorderStyle
  59326. * @param {integer} width - The width
  59327. */
  59328. setWidth: function AnnotationBorderStyle_setWidth(width) {
  59329. if (width === (width | 0)) {
  59330. this.width = width;
  59331. }
  59332. },
  59333. /**
  59334. * Set the style.
  59335. *
  59336. * @public
  59337. * @memberof AnnotationBorderStyle
  59338. * @param {Object} style - The style object
  59339. * @see {@link shared/util.js}
  59340. */
  59341. setStyle: function AnnotationBorderStyle_setStyle(style) {
  59342. if (!style) {
  59343. return;
  59344. }
  59345. switch (style.name) {
  59346. case 'S':
  59347. this.style = AnnotationBorderStyleType.SOLID;
  59348. break;
  59349. case 'D':
  59350. this.style = AnnotationBorderStyleType.DASHED;
  59351. break;
  59352. case 'B':
  59353. this.style = AnnotationBorderStyleType.BEVELED;
  59354. break;
  59355. case 'I':
  59356. this.style = AnnotationBorderStyleType.INSET;
  59357. break;
  59358. case 'U':
  59359. this.style = AnnotationBorderStyleType.UNDERLINE;
  59360. break;
  59361. default:
  59362. break;
  59363. }
  59364. },
  59365. /**
  59366. * Set the dash array.
  59367. *
  59368. * @public
  59369. * @memberof AnnotationBorderStyle
  59370. * @param {Array} dashArray - The dash array with at least one element
  59371. */
  59372. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  59373. // We validate the dash array, but we do not use it because CSS does not
  59374. // allow us to change spacing of dashes. For more information, visit
  59375. // http://www.w3.org/TR/css3-background/#the-border-style.
  59376. if (isArray(dashArray) && dashArray.length > 0) {
  59377. // According to the PDF specification: the elements in a dashArray
  59378. // shall be numbers that are nonnegative and not all equal to zero.
  59379. var isValid = true;
  59380. var allZeros = true;
  59381. for (var i = 0, len = dashArray.length; i < len; i++) {
  59382. var element = dashArray[i];
  59383. var validNumber = +element >= 0;
  59384. if (!validNumber) {
  59385. isValid = false;
  59386. break;
  59387. } else if (element > 0) {
  59388. allZeros = false;
  59389. }
  59390. }
  59391. if (isValid && !allZeros) {
  59392. this.dashArray = dashArray;
  59393. } else {
  59394. this.width = 0;
  59395. }
  59396. } else // Adobe behavior when the array is invalid.
  59397. if (dashArray) {
  59398. this.width = 0;
  59399. }
  59400. },
  59401. // Adobe behavior when the array is invalid.
  59402. /**
  59403. * Set the horizontal corner radius (from a Border dictionary).
  59404. *
  59405. * @public
  59406. * @memberof AnnotationBorderStyle
  59407. * @param {integer} radius - The horizontal corner radius
  59408. */
  59409. setHorizontalCornerRadius: function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  59410. if (radius === (radius | 0)) {
  59411. this.horizontalCornerRadius = radius;
  59412. }
  59413. },
  59414. /**
  59415. * Set the vertical corner radius (from a Border dictionary).
  59416. *
  59417. * @public
  59418. * @memberof AnnotationBorderStyle
  59419. * @param {integer} radius - The vertical corner radius
  59420. */
  59421. setVerticalCornerRadius: function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  59422. if (radius === (radius | 0)) {
  59423. this.verticalCornerRadius = radius;
  59424. }
  59425. }
  59426. };
  59427. return AnnotationBorderStyle;
  59428. }();
  59429. var WidgetAnnotation = function WidgetAnnotationClosure() {
  59430. function WidgetAnnotation(params) {
  59431. Annotation.call(this, params);
  59432. var dict = params.dict;
  59433. var data = this.data;
  59434. data.annotationType = AnnotationType.WIDGET;
  59435. data.fieldValue = Util.getInheritableProperty(dict, 'V', /* getArray = */
  59436. true);
  59437. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  59438. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  59439. var fieldType = Util.getInheritableProperty(dict, 'FT');
  59440. data.fieldType = isName(fieldType) ? fieldType.name : null;
  59441. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  59442. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff');
  59443. if (!isInt(data.fieldFlags) || data.fieldFlags < 0) {
  59444. data.fieldFlags = 0;
  59445. }
  59446. data.readOnly = this.hasFieldFlag(AnnotationFieldFlag.READONLY);
  59447. // Hide signatures because we cannot validate them.
  59448. if (data.fieldType === 'Sig') {
  59449. this.setFlags(AnnotationFlag.HIDDEN);
  59450. }
  59451. // Building the full field name by collecting the field and
  59452. // its ancestors 'T' data and joining them using '.'.
  59453. var fieldName = [];
  59454. var namedItem = dict;
  59455. var ref = params.ref;
  59456. while (namedItem) {
  59457. var parent = namedItem.get('Parent');
  59458. var parentRef = namedItem.getRaw('Parent');
  59459. var name = namedItem.get('T');
  59460. if (name) {
  59461. fieldName.unshift(stringToPDFString(name));
  59462. } else if (parent && ref) {
  59463. // The field name is absent, that means more than one field
  59464. // with the same name may exist. Replacing the empty name
  59465. // with the '`' plus index in the parent's 'Kids' array.
  59466. // This is not in the PDF spec but necessary to id the
  59467. // the input controls.
  59468. var kids = parent.get('Kids');
  59469. var j, jj;
  59470. for (j = 0, jj = kids.length; j < jj; j++) {
  59471. var kidRef = kids[j];
  59472. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  59473. break;
  59474. }
  59475. }
  59476. fieldName.unshift('`' + j);
  59477. }
  59478. namedItem = parent;
  59479. ref = parentRef;
  59480. }
  59481. data.fullName = fieldName.join('.');
  59482. }
  59483. Util.inherit(WidgetAnnotation, Annotation, {
  59484. /**
  59485. * Check if a provided field flag is set.
  59486. *
  59487. * @public
  59488. * @memberof WidgetAnnotation
  59489. * @param {number} flag - Hexadecimal representation for an annotation
  59490. * field characteristic
  59491. * @return {boolean}
  59492. * @see {@link shared/util.js}
  59493. */
  59494. hasFieldFlag: function WidgetAnnotation_hasFieldFlag(flag) {
  59495. return !!(this.data.fieldFlags & flag);
  59496. }
  59497. });
  59498. return WidgetAnnotation;
  59499. }();
  59500. var TextWidgetAnnotation = function TextWidgetAnnotationClosure() {
  59501. function TextWidgetAnnotation(params) {
  59502. WidgetAnnotation.call(this, params);
  59503. // The field value is always a string.
  59504. this.data.fieldValue = stringToPDFString(this.data.fieldValue || '');
  59505. // Determine the alignment of text in the field.
  59506. var alignment = Util.getInheritableProperty(params.dict, 'Q');
  59507. if (!isInt(alignment) || alignment < 0 || alignment > 2) {
  59508. alignment = null;
  59509. }
  59510. this.data.textAlignment = alignment;
  59511. // Determine the maximum length of text in the field.
  59512. var maximumLength = Util.getInheritableProperty(params.dict, 'MaxLen');
  59513. if (!isInt(maximumLength) || maximumLength < 0) {
  59514. maximumLength = null;
  59515. }
  59516. this.data.maxLen = maximumLength;
  59517. // Process field flags for the display layer.
  59518. this.data.multiLine = this.hasFieldFlag(AnnotationFieldFlag.MULTILINE);
  59519. this.data.comb = this.hasFieldFlag(AnnotationFieldFlag.COMB) && !this.hasFieldFlag(AnnotationFieldFlag.MULTILINE) && !this.hasFieldFlag(AnnotationFieldFlag.PASSWORD) && !this.hasFieldFlag(AnnotationFieldFlag.FILESELECT) && this.data.maxLen !== null;
  59520. }
  59521. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  59522. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator, task, renderForms) {
  59523. var operatorList = new OperatorList();
  59524. // Do not render form elements on the canvas when interactive forms are
  59525. // enabled. The display layer is responsible for rendering them instead.
  59526. if (renderForms) {
  59527. return Promise.resolve(operatorList);
  59528. }
  59529. if (this.appearance) {
  59530. return Annotation.prototype.getOperatorList.call(this, evaluator, task, renderForms);
  59531. }
  59532. // Even if there is an appearance stream, ignore it. This is the
  59533. // behaviour used by Adobe Reader.
  59534. if (!this.data.defaultAppearance) {
  59535. return Promise.resolve(operatorList);
  59536. }
  59537. var stream = new Stream(stringToBytes(this.data.defaultAppearance));
  59538. return evaluator.getOperatorList(stream, task, this.fieldResources, operatorList).then(function () {
  59539. return operatorList;
  59540. });
  59541. }
  59542. });
  59543. return TextWidgetAnnotation;
  59544. }();
  59545. var ChoiceWidgetAnnotation = function ChoiceWidgetAnnotationClosure() {
  59546. function ChoiceWidgetAnnotation(params) {
  59547. WidgetAnnotation.call(this, params);
  59548. // Determine the options. The options array may consist of strings or
  59549. // arrays. If the array consists of arrays, then the first element of
  59550. // each array is the export value and the second element of each array is
  59551. // the display value. If the array consists of strings, then these
  59552. // represent both the export and display value. In this case, we convert
  59553. // it to an array of arrays as well for convenience in the display layer.
  59554. this.data.options = [];
  59555. var options = params.dict.getArray('Opt');
  59556. if (isArray(options)) {
  59557. for (var i = 0, ii = options.length; i < ii; i++) {
  59558. var option = options[i];
  59559. this.data.options[i] = {
  59560. exportValue: isArray(option) ? option[0] : option,
  59561. displayValue: isArray(option) ? option[1] : option
  59562. };
  59563. }
  59564. }
  59565. // Determine the field value. In this case, it may be a string or an
  59566. // array of strings. For convenience in the display layer, convert the
  59567. // string to an array of one string as well.
  59568. if (!isArray(this.data.fieldValue)) {
  59569. this.data.fieldValue = [this.data.fieldValue];
  59570. }
  59571. // Process field flags for the display layer.
  59572. this.data.combo = this.hasFieldFlag(AnnotationFieldFlag.COMBO);
  59573. this.data.multiSelect = this.hasFieldFlag(AnnotationFieldFlag.MULTISELECT);
  59574. }
  59575. Util.inherit(ChoiceWidgetAnnotation, WidgetAnnotation, {
  59576. getOperatorList: function ChoiceWidgetAnnotation_getOperatorList(evaluator, task, renderForms) {
  59577. var operatorList = new OperatorList();
  59578. // Do not render form elements on the canvas when interactive forms are
  59579. // enabled. The display layer is responsible for rendering them instead.
  59580. if (renderForms) {
  59581. return Promise.resolve(operatorList);
  59582. }
  59583. return Annotation.prototype.getOperatorList.call(this, evaluator, task, renderForms);
  59584. }
  59585. });
  59586. return ChoiceWidgetAnnotation;
  59587. }();
  59588. var TextAnnotation = function TextAnnotationClosure() {
  59589. var DEFAULT_ICON_SIZE = 22;
  59590. // px
  59591. function TextAnnotation(parameters) {
  59592. Annotation.call(this, parameters);
  59593. this.data.annotationType = AnnotationType.TEXT;
  59594. if (this.data.hasAppearance) {
  59595. this.data.name = 'NoIcon';
  59596. } else {
  59597. this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE;
  59598. this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE;
  59599. this.data.name = parameters.dict.has('Name') ? parameters.dict.get('Name').name : 'Note';
  59600. }
  59601. this._preparePopup(parameters.dict);
  59602. }
  59603. Util.inherit(TextAnnotation, Annotation, {});
  59604. return TextAnnotation;
  59605. }();
  59606. var LinkAnnotation = function LinkAnnotationClosure() {
  59607. function LinkAnnotation(params) {
  59608. Annotation.call(this, params);
  59609. var dict = params.dict;
  59610. var data = this.data;
  59611. data.annotationType = AnnotationType.LINK;
  59612. var action = dict.get('A'), url, dest;
  59613. if (action && isDict(action)) {
  59614. var linkType = action.get('S').name;
  59615. switch (linkType) {
  59616. case 'URI':
  59617. url = action.get('URI');
  59618. if (isName(url)) {
  59619. // Some bad PDFs do not put parentheses around relative URLs.
  59620. url = '/' + url.name;
  59621. } else if (url) {
  59622. url = addDefaultProtocolToUrl(url);
  59623. }
  59624. // TODO: pdf spec mentions urls can be relative to a Base
  59625. // entry in the dictionary.
  59626. break;
  59627. case 'GoTo':
  59628. dest = action.get('D');
  59629. break;
  59630. case 'GoToR':
  59631. var urlDict = action.get('F');
  59632. if (isDict(urlDict)) {
  59633. // We assume that we found a FileSpec dictionary
  59634. // and fetch the URL without checking any further.
  59635. url = urlDict.get('F') || null;
  59636. } else if (isString(urlDict)) {
  59637. url = urlDict;
  59638. }
  59639. // NOTE: the destination is relative to the *remote* document.
  59640. var remoteDest = action.get('D');
  59641. if (remoteDest) {
  59642. if (isName(remoteDest)) {
  59643. remoteDest = remoteDest.name;
  59644. }
  59645. if (isString(url)) {
  59646. var baseUrl = url.split('#')[0];
  59647. if (isString(remoteDest)) {
  59648. // In practice, a named destination may contain only a number.
  59649. // If that happens, use the '#nameddest=' form to avoid the link
  59650. // redirecting to a page, instead of the correct destination.
  59651. url = baseUrl + '#' + (/^\d+$/.test(remoteDest) ? 'nameddest=' : '') + remoteDest;
  59652. } else if (isArray(remoteDest)) {
  59653. url = baseUrl + '#' + JSON.stringify(remoteDest);
  59654. }
  59655. }
  59656. }
  59657. // The 'NewWindow' property, equal to `LinkTarget.BLANK`.
  59658. var newWindow = action.get('NewWindow');
  59659. if (isBool(newWindow)) {
  59660. data.newWindow = newWindow;
  59661. }
  59662. break;
  59663. case 'Named':
  59664. data.action = action.get('N').name;
  59665. break;
  59666. default:
  59667. warn('unrecognized link type: ' + linkType);
  59668. }
  59669. } else if (dict.has('Dest')) {
  59670. // Simple destination link.
  59671. dest = dict.get('Dest');
  59672. }
  59673. if (url) {
  59674. if (isValidUrl(url, /* allowRelative = */
  59675. false)) {
  59676. data.url = tryConvertUrlEncoding(url);
  59677. }
  59678. }
  59679. if (dest) {
  59680. data.dest = isName(dest) ? dest.name : dest;
  59681. }
  59682. }
  59683. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  59684. function addDefaultProtocolToUrl(url) {
  59685. if (isString(url) && url.indexOf('www.') === 0) {
  59686. return 'http://' + url;
  59687. }
  59688. return url;
  59689. }
  59690. function tryConvertUrlEncoding(url) {
  59691. // According to ISO 32000-1:2008, section 12.6.4.7, URIs should be encoded
  59692. // in 7-bit ASCII. Some bad PDFs use UTF-8 encoding, see Bugzilla 1122280.
  59693. try {
  59694. return stringToUTF8String(url);
  59695. } catch (e) {
  59696. return url;
  59697. }
  59698. }
  59699. Util.inherit(LinkAnnotation, Annotation, {});
  59700. return LinkAnnotation;
  59701. }();
  59702. var PopupAnnotation = function PopupAnnotationClosure() {
  59703. function PopupAnnotation(parameters) {
  59704. Annotation.call(this, parameters);
  59705. this.data.annotationType = AnnotationType.POPUP;
  59706. var dict = parameters.dict;
  59707. var parentItem = dict.get('Parent');
  59708. if (!parentItem) {
  59709. warn('Popup annotation has a missing or invalid parent annotation.');
  59710. return;
  59711. }
  59712. this.data.parentId = dict.getRaw('Parent').toString();
  59713. this.data.title = stringToPDFString(parentItem.get('T') || '');
  59714. this.data.contents = stringToPDFString(parentItem.get('Contents') || '');
  59715. if (!parentItem.has('C')) {
  59716. // Fall back to the default background color.
  59717. this.data.color = null;
  59718. } else {
  59719. this.setColor(parentItem.getArray('C'));
  59720. this.data.color = this.color;
  59721. }
  59722. // If the Popup annotation is not viewable, but the parent annotation is,
  59723. // that is most likely a bug. Fallback to inherit the flags from the parent
  59724. // annotation (this is consistent with the behaviour in Adobe Reader).
  59725. if (!this.viewable) {
  59726. var parentFlags = parentItem.get('F');
  59727. if (this._isViewable(parentFlags)) {
  59728. this.setFlags(parentFlags);
  59729. }
  59730. }
  59731. }
  59732. Util.inherit(PopupAnnotation, Annotation, {});
  59733. return PopupAnnotation;
  59734. }();
  59735. var HighlightAnnotation = function HighlightAnnotationClosure() {
  59736. function HighlightAnnotation(parameters) {
  59737. Annotation.call(this, parameters);
  59738. this.data.annotationType = AnnotationType.HIGHLIGHT;
  59739. this._preparePopup(parameters.dict);
  59740. // PDF viewers completely ignore any border styles.
  59741. this.data.borderStyle.setWidth(0);
  59742. }
  59743. Util.inherit(HighlightAnnotation, Annotation, {});
  59744. return HighlightAnnotation;
  59745. }();
  59746. var UnderlineAnnotation = function UnderlineAnnotationClosure() {
  59747. function UnderlineAnnotation(parameters) {
  59748. Annotation.call(this, parameters);
  59749. this.data.annotationType = AnnotationType.UNDERLINE;
  59750. this._preparePopup(parameters.dict);
  59751. // PDF viewers completely ignore any border styles.
  59752. this.data.borderStyle.setWidth(0);
  59753. }
  59754. Util.inherit(UnderlineAnnotation, Annotation, {});
  59755. return UnderlineAnnotation;
  59756. }();
  59757. var SquigglyAnnotation = function SquigglyAnnotationClosure() {
  59758. function SquigglyAnnotation(parameters) {
  59759. Annotation.call(this, parameters);
  59760. this.data.annotationType = AnnotationType.SQUIGGLY;
  59761. this._preparePopup(parameters.dict);
  59762. // PDF viewers completely ignore any border styles.
  59763. this.data.borderStyle.setWidth(0);
  59764. }
  59765. Util.inherit(SquigglyAnnotation, Annotation, {});
  59766. return SquigglyAnnotation;
  59767. }();
  59768. var StrikeOutAnnotation = function StrikeOutAnnotationClosure() {
  59769. function StrikeOutAnnotation(parameters) {
  59770. Annotation.call(this, parameters);
  59771. this.data.annotationType = AnnotationType.STRIKEOUT;
  59772. this._preparePopup(parameters.dict);
  59773. // PDF viewers completely ignore any border styles.
  59774. this.data.borderStyle.setWidth(0);
  59775. }
  59776. Util.inherit(StrikeOutAnnotation, Annotation, {});
  59777. return StrikeOutAnnotation;
  59778. }();
  59779. var FileAttachmentAnnotation = function FileAttachmentAnnotationClosure() {
  59780. function FileAttachmentAnnotation(parameters) {
  59781. Annotation.call(this, parameters);
  59782. var file = new FileSpec(parameters.dict.get('FS'), parameters.xref);
  59783. this.data.annotationType = AnnotationType.FILEATTACHMENT;
  59784. this.data.file = file.serializable;
  59785. this._preparePopup(parameters.dict);
  59786. }
  59787. Util.inherit(FileAttachmentAnnotation, Annotation, {});
  59788. return FileAttachmentAnnotation;
  59789. }();
  59790. exports.Annotation = Annotation;
  59791. exports.AnnotationBorderStyle = AnnotationBorderStyle;
  59792. exports.AnnotationFactory = AnnotationFactory;
  59793. }));
  59794. (function (root, factory) {
  59795. factory(root.pdfjsCoreDocument = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreObj, root.pdfjsCoreParser, root.pdfjsCoreCrypto, root.pdfjsCoreEvaluator, root.pdfjsCoreAnnotation);
  59796. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreObj, coreParser, coreCrypto, coreEvaluator, coreAnnotation) {
  59797. var MissingDataException = sharedUtil.MissingDataException;
  59798. var Util = sharedUtil.Util;
  59799. var assert = sharedUtil.assert;
  59800. var error = sharedUtil.error;
  59801. var info = sharedUtil.info;
  59802. var isArray = sharedUtil.isArray;
  59803. var isArrayBuffer = sharedUtil.isArrayBuffer;
  59804. var isString = sharedUtil.isString;
  59805. var shadow = sharedUtil.shadow;
  59806. var stringToBytes = sharedUtil.stringToBytes;
  59807. var stringToPDFString = sharedUtil.stringToPDFString;
  59808. var warn = sharedUtil.warn;
  59809. var isSpace = sharedUtil.isSpace;
  59810. var Dict = corePrimitives.Dict;
  59811. var isDict = corePrimitives.isDict;
  59812. var isName = corePrimitives.isName;
  59813. var isStream = corePrimitives.isStream;
  59814. var NullStream = coreStream.NullStream;
  59815. var Stream = coreStream.Stream;
  59816. var StreamsSequenceStream = coreStream.StreamsSequenceStream;
  59817. var Catalog = coreObj.Catalog;
  59818. var ObjectLoader = coreObj.ObjectLoader;
  59819. var XRef = coreObj.XRef;
  59820. var Linearization = coreParser.Linearization;
  59821. var calculateMD5 = coreCrypto.calculateMD5;
  59822. var OperatorList = coreEvaluator.OperatorList;
  59823. var PartialEvaluator = coreEvaluator.PartialEvaluator;
  59824. var Annotation = coreAnnotation.Annotation;
  59825. var AnnotationFactory = coreAnnotation.AnnotationFactory;
  59826. var Page = function PageClosure() {
  59827. var LETTER_SIZE_MEDIABOX = [
  59828. 0,
  59829. 0,
  59830. 612,
  59831. 792
  59832. ];
  59833. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  59834. this.pdfManager = pdfManager;
  59835. this.pageIndex = pageIndex;
  59836. this.pageDict = pageDict;
  59837. this.xref = xref;
  59838. this.ref = ref;
  59839. this.fontCache = fontCache;
  59840. this.uniquePrefix = 'p' + this.pageIndex + '_';
  59841. this.idCounters = { obj: 0 };
  59842. this.evaluatorOptions = pdfManager.evaluatorOptions;
  59843. this.resourcesPromise = null;
  59844. }
  59845. Page.prototype = {
  59846. getPageProp: function Page_getPageProp(key) {
  59847. return this.pageDict.get(key);
  59848. },
  59849. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  59850. var dict = this.pageDict, valueArray = null, loopCount = 0;
  59851. var MAX_LOOP_COUNT = 100;
  59852. // Always walk up the entire parent chain, to be able to find
  59853. // e.g. \Resources placed on multiple levels of the tree.
  59854. while (dict) {
  59855. var value = dict.get(key);
  59856. if (value) {
  59857. if (!valueArray) {
  59858. valueArray = [];
  59859. }
  59860. valueArray.push(value);
  59861. }
  59862. if (++loopCount > MAX_LOOP_COUNT) {
  59863. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  59864. break;
  59865. }
  59866. dict = dict.get('Parent');
  59867. }
  59868. if (!valueArray) {
  59869. return Dict.empty;
  59870. }
  59871. if (valueArray.length === 1 || !isDict(valueArray[0]) || loopCount > MAX_LOOP_COUNT) {
  59872. return valueArray[0];
  59873. }
  59874. return Dict.merge(this.xref, valueArray);
  59875. },
  59876. get content() {
  59877. return this.getPageProp('Contents');
  59878. },
  59879. get resources() {
  59880. // For robustness: The spec states that a \Resources entry has to be
  59881. // present, but can be empty. Some document omit it still, in this case
  59882. // we return an empty dictionary.
  59883. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  59884. },
  59885. get mediaBox() {
  59886. var obj = this.getInheritedPageProp('MediaBox');
  59887. // Reset invalid media box to letter size.
  59888. if (!isArray(obj) || obj.length !== 4) {
  59889. obj = LETTER_SIZE_MEDIABOX;
  59890. }
  59891. return shadow(this, 'mediaBox', obj);
  59892. },
  59893. get view() {
  59894. var mediaBox = this.mediaBox;
  59895. var cropBox = this.getInheritedPageProp('CropBox');
  59896. if (!isArray(cropBox) || cropBox.length !== 4) {
  59897. return shadow(this, 'view', mediaBox);
  59898. }
  59899. // From the spec, 6th ed., p.963:
  59900. // "The crop, bleed, trim, and art boxes should not ordinarily
  59901. // extend beyond the boundaries of the media box. If they do, they are
  59902. // effectively reduced to their intersection with the media box."
  59903. cropBox = Util.intersect(cropBox, mediaBox);
  59904. if (!cropBox) {
  59905. return shadow(this, 'view', mediaBox);
  59906. }
  59907. return shadow(this, 'view', cropBox);
  59908. },
  59909. get rotate() {
  59910. var rotate = this.getInheritedPageProp('Rotate') || 0;
  59911. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  59912. if (rotate % 90 !== 0) {
  59913. rotate = 0;
  59914. } else if (rotate >= 360) {
  59915. rotate = rotate % 360;
  59916. } else if (rotate < 0) {
  59917. // The spec doesn't cover negatives, assume its counterclockwise
  59918. // rotation. The following is the other implementation of modulo.
  59919. rotate = (rotate % 360 + 360) % 360;
  59920. }
  59921. return shadow(this, 'rotate', rotate);
  59922. },
  59923. getContentStream: function Page_getContentStream() {
  59924. var content = this.content;
  59925. var stream;
  59926. if (isArray(content)) {
  59927. // fetching items
  59928. var xref = this.xref;
  59929. var i, n = content.length;
  59930. var streams = [];
  59931. for (i = 0; i < n; ++i) {
  59932. streams.push(xref.fetchIfRef(content[i]));
  59933. }
  59934. stream = new StreamsSequenceStream(streams);
  59935. } else if (isStream(content)) {
  59936. stream = content;
  59937. } else {
  59938. // replacing non-existent page content with empty one
  59939. stream = new NullStream();
  59940. }
  59941. return stream;
  59942. },
  59943. loadResources: function Page_loadResources(keys) {
  59944. if (!this.resourcesPromise) {
  59945. // TODO: add async getInheritedPageProp and remove this.
  59946. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  59947. }
  59948. return this.resourcesPromise.then(function resourceSuccess() {
  59949. var objectLoader = new ObjectLoader(this.resources.map, keys, this.xref);
  59950. return objectLoader.load();
  59951. }.bind(this));
  59952. },
  59953. getOperatorList: function Page_getOperatorList(handler, task, intent, renderInteractiveForms) {
  59954. var self = this;
  59955. var pdfManager = this.pdfManager;
  59956. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream', []);
  59957. var resourcesPromise = this.loadResources([
  59958. 'ExtGState',
  59959. 'ColorSpace',
  59960. 'Pattern',
  59961. 'Shading',
  59962. 'XObject',
  59963. 'Font'
  59964. ]);
  59965. // ProcSet
  59966. // Properties
  59967. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref, handler, this.pageIndex, this.uniquePrefix, this.idCounters, this.fontCache, this.evaluatorOptions);
  59968. var dataPromises = Promise.all([
  59969. contentStreamPromise,
  59970. resourcesPromise
  59971. ]);
  59972. var pageListPromise = dataPromises.then(function (data) {
  59973. var contentStream = data[0];
  59974. var opList = new OperatorList(intent, handler, self.pageIndex);
  59975. handler.send('StartRenderPage', {
  59976. transparency: partialEvaluator.hasBlendModes(self.resources),
  59977. pageIndex: self.pageIndex,
  59978. intent: intent
  59979. });
  59980. return partialEvaluator.getOperatorList(contentStream, task, self.resources, opList).then(function () {
  59981. return opList;
  59982. });
  59983. });
  59984. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  59985. return Promise.all([
  59986. pageListPromise,
  59987. annotationsPromise
  59988. ]).then(function (datas) {
  59989. var pageOpList = datas[0];
  59990. var annotations = datas[1];
  59991. if (annotations.length === 0) {
  59992. pageOpList.flush(true);
  59993. return pageOpList;
  59994. }
  59995. var annotationsReadyPromise = Annotation.appendToOperatorList(annotations, pageOpList, partialEvaluator, task, intent, renderInteractiveForms);
  59996. return annotationsReadyPromise.then(function () {
  59997. pageOpList.flush(true);
  59998. return pageOpList;
  59999. });
  60000. });
  60001. },
  60002. extractTextContent: function Page_extractTextContent(task, normalizeWhitespace, combineTextItems) {
  60003. var handler = {
  60004. on: function nullHandlerOn() {
  60005. },
  60006. send: function nullHandlerSend() {
  60007. }
  60008. };
  60009. var self = this;
  60010. var pdfManager = this.pdfManager;
  60011. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream', []);
  60012. var resourcesPromise = this.loadResources([
  60013. 'ExtGState',
  60014. 'XObject',
  60015. 'Font'
  60016. ]);
  60017. var dataPromises = Promise.all([
  60018. contentStreamPromise,
  60019. resourcesPromise
  60020. ]);
  60021. return dataPromises.then(function (data) {
  60022. var contentStream = data[0];
  60023. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref, handler, self.pageIndex, self.uniquePrefix, self.idCounters, self.fontCache, self.evaluatorOptions);
  60024. return partialEvaluator.getTextContent(contentStream, task, self.resources, /* stateManager = */
  60025. null, normalizeWhitespace, combineTextItems);
  60026. });
  60027. },
  60028. getAnnotationsData: function Page_getAnnotationsData(intent) {
  60029. var annotations = this.annotations;
  60030. var annotationsData = [];
  60031. for (var i = 0, n = annotations.length; i < n; ++i) {
  60032. if (intent) {
  60033. if (!(intent === 'display' && annotations[i].viewable) && !(intent === 'print' && annotations[i].printable)) {
  60034. continue;
  60035. }
  60036. }
  60037. annotationsData.push(annotations[i].data);
  60038. }
  60039. return annotationsData;
  60040. },
  60041. get annotations() {
  60042. var annotations = [];
  60043. var annotationRefs = this.getInheritedPageProp('Annots') || [];
  60044. var annotationFactory = new AnnotationFactory();
  60045. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  60046. var annotationRef = annotationRefs[i];
  60047. var annotation = annotationFactory.create(this.xref, annotationRef, this.uniquePrefix, this.idCounters);
  60048. if (annotation) {
  60049. annotations.push(annotation);
  60050. }
  60051. }
  60052. return shadow(this, 'annotations', annotations);
  60053. }
  60054. };
  60055. return Page;
  60056. }();
  60057. /**
  60058. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  60059. * `PDFDoc`, this one doesn't have any job management code.
  60060. * Right now there exists one PDFDocument on the main thread + one object
  60061. * for each worker. If there is no worker support enabled, there are two
  60062. * `PDFDocument` objects on the main thread created.
  60063. */
  60064. var PDFDocument = function PDFDocumentClosure() {
  60065. var FINGERPRINT_FIRST_BYTES = 1024;
  60066. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' + '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  60067. function PDFDocument(pdfManager, arg, password) {
  60068. if (isStream(arg)) {
  60069. init.call(this, pdfManager, arg, password);
  60070. } else if (isArrayBuffer(arg)) {
  60071. init.call(this, pdfManager, new Stream(arg), password);
  60072. } else {
  60073. error('PDFDocument: Unknown argument type');
  60074. }
  60075. }
  60076. function init(pdfManager, stream, password) {
  60077. assert(stream.length > 0, 'stream must have data');
  60078. this.pdfManager = pdfManager;
  60079. this.stream = stream;
  60080. var xref = new XRef(this.stream, password, pdfManager);
  60081. this.xref = xref;
  60082. }
  60083. function find(stream, needle, limit, backwards) {
  60084. var pos = stream.pos;
  60085. var end = stream.end;
  60086. var strBuf = [];
  60087. if (pos + limit > end) {
  60088. limit = end - pos;
  60089. }
  60090. for (var n = 0; n < limit; ++n) {
  60091. strBuf.push(String.fromCharCode(stream.getByte()));
  60092. }
  60093. var str = strBuf.join('');
  60094. stream.pos = pos;
  60095. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  60096. if (index === -1) {
  60097. return false;
  60098. }
  60099. /* not found */
  60100. stream.pos += index;
  60101. return true;
  60102. }
  60103. /* found */
  60104. var DocumentInfoValidators = {
  60105. get entries() {
  60106. // Lazily build this since all the validation functions below are not
  60107. // defined until after this file loads.
  60108. return shadow(this, 'entries', {
  60109. Title: isString,
  60110. Author: isString,
  60111. Subject: isString,
  60112. Keywords: isString,
  60113. Creator: isString,
  60114. Producer: isString,
  60115. CreationDate: isString,
  60116. ModDate: isString,
  60117. Trapped: isName
  60118. });
  60119. }
  60120. };
  60121. PDFDocument.prototype = {
  60122. parse: function PDFDocument_parse(recoveryMode) {
  60123. this.setup(recoveryMode);
  60124. var version = this.catalog.catDict.get('Version');
  60125. if (isName(version)) {
  60126. this.pdfFormatVersion = version.name;
  60127. }
  60128. try {
  60129. // checking if AcroForm is present
  60130. this.acroForm = this.catalog.catDict.get('AcroForm');
  60131. if (this.acroForm) {
  60132. this.xfa = this.acroForm.get('XFA');
  60133. var fields = this.acroForm.get('Fields');
  60134. if ((!fields || !isArray(fields) || fields.length === 0) && !this.xfa) {
  60135. // no fields and no XFA -- not a form (?)
  60136. this.acroForm = null;
  60137. }
  60138. }
  60139. } catch (ex) {
  60140. info('Something wrong with AcroForm entry');
  60141. this.acroForm = null;
  60142. }
  60143. },
  60144. get linearization() {
  60145. var linearization = null;
  60146. if (this.stream.length) {
  60147. try {
  60148. linearization = Linearization.create(this.stream);
  60149. } catch (err) {
  60150. if (err instanceof MissingDataException) {
  60151. throw err;
  60152. }
  60153. info(err);
  60154. }
  60155. }
  60156. // shadow the prototype getter with a data property
  60157. return shadow(this, 'linearization', linearization);
  60158. },
  60159. get startXRef() {
  60160. var stream = this.stream;
  60161. var startXRef = 0;
  60162. var linearization = this.linearization;
  60163. if (linearization) {
  60164. // Find end of first obj.
  60165. stream.reset();
  60166. if (find(stream, 'endobj', 1024)) {
  60167. startXRef = stream.pos + 6;
  60168. }
  60169. } else {
  60170. // Find startxref by jumping backward from the end of the file.
  60171. var step = 1024;
  60172. var found = false, pos = stream.end;
  60173. while (!found && pos > 0) {
  60174. pos -= step - 'startxref'.length;
  60175. if (pos < 0) {
  60176. pos = 0;
  60177. }
  60178. stream.pos = pos;
  60179. found = find(stream, 'startxref', step, true);
  60180. }
  60181. if (found) {
  60182. stream.skip(9);
  60183. var ch;
  60184. do {
  60185. ch = stream.getByte();
  60186. } while (isSpace(ch));
  60187. var str = '';
  60188. while (ch >= 0x20 && ch <= 0x39) {
  60189. // < '9'
  60190. str += String.fromCharCode(ch);
  60191. ch = stream.getByte();
  60192. }
  60193. startXRef = parseInt(str, 10);
  60194. if (isNaN(startXRef)) {
  60195. startXRef = 0;
  60196. }
  60197. }
  60198. }
  60199. // shadow the prototype getter with a data property
  60200. return shadow(this, 'startXRef', startXRef);
  60201. },
  60202. get mainXRefEntriesOffset() {
  60203. var mainXRefEntriesOffset = 0;
  60204. var linearization = this.linearization;
  60205. if (linearization) {
  60206. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  60207. }
  60208. // shadow the prototype getter with a data property
  60209. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  60210. },
  60211. // Find the header, remove leading garbage and setup the stream
  60212. // starting from the header.
  60213. checkHeader: function PDFDocument_checkHeader() {
  60214. var stream = this.stream;
  60215. stream.reset();
  60216. if (find(stream, '%PDF-', 1024)) {
  60217. // Found the header, trim off any garbage before it.
  60218. stream.moveStart();
  60219. // Reading file format version
  60220. var MAX_VERSION_LENGTH = 12;
  60221. var version = '', ch;
  60222. while ((ch = stream.getByte()) > 0x20) {
  60223. // SPACE
  60224. if (version.length >= MAX_VERSION_LENGTH) {
  60225. break;
  60226. }
  60227. version += String.fromCharCode(ch);
  60228. }
  60229. if (!this.pdfFormatVersion) {
  60230. // removing "%PDF-"-prefix
  60231. this.pdfFormatVersion = version.substring(5);
  60232. }
  60233. return;
  60234. }
  60235. },
  60236. // May not be a PDF file, continue anyway.
  60237. parseStartXRef: function PDFDocument_parseStartXRef() {
  60238. var startXRef = this.startXRef;
  60239. this.xref.setStartXRef(startXRef);
  60240. },
  60241. setup: function PDFDocument_setup(recoveryMode) {
  60242. this.xref.parse(recoveryMode);
  60243. var self = this;
  60244. var pageFactory = {
  60245. createPage: function (pageIndex, dict, ref, fontCache) {
  60246. return new Page(self.pdfManager, self.xref, pageIndex, dict, ref, fontCache);
  60247. }
  60248. };
  60249. this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);
  60250. },
  60251. get numPages() {
  60252. var linearization = this.linearization;
  60253. var num = linearization ? linearization.numPages : this.catalog.numPages;
  60254. // shadow the prototype getter
  60255. return shadow(this, 'numPages', num);
  60256. },
  60257. get documentInfo() {
  60258. var docInfo = {
  60259. PDFFormatVersion: this.pdfFormatVersion,
  60260. IsAcroFormPresent: !!this.acroForm,
  60261. IsXFAPresent: !!this.xfa
  60262. };
  60263. var infoDict;
  60264. try {
  60265. infoDict = this.xref.trailer.get('Info');
  60266. } catch (err) {
  60267. info('The document information dictionary is invalid.');
  60268. }
  60269. if (infoDict) {
  60270. var validEntries = DocumentInfoValidators.entries;
  60271. // Only fill the document info with valid entries from the spec.
  60272. for (var key in validEntries) {
  60273. if (infoDict.has(key)) {
  60274. var value = infoDict.get(key);
  60275. // Make sure the value conforms to the spec.
  60276. if (validEntries[key](value)) {
  60277. docInfo[key] = typeof value !== 'string' ? value : stringToPDFString(value);
  60278. } else {
  60279. info('Bad value in document info for "' + key + '"');
  60280. }
  60281. }
  60282. }
  60283. }
  60284. return shadow(this, 'documentInfo', docInfo);
  60285. },
  60286. get fingerprint() {
  60287. var xref = this.xref, hash, fileID = '';
  60288. var idArray = xref.trailer.get('ID');
  60289. if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) && idArray[0] !== EMPTY_FINGERPRINT) {
  60290. hash = stringToBytes(idArray[0]);
  60291. } else {
  60292. if (this.stream.ensureRange) {
  60293. this.stream.ensureRange(0, Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  60294. }
  60295. hash = calculateMD5(this.stream.bytes.subarray(0, FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  60296. }
  60297. for (var i = 0, n = hash.length; i < n; i++) {
  60298. var hex = hash[i].toString(16);
  60299. fileID += hex.length === 1 ? '0' + hex : hex;
  60300. }
  60301. return shadow(this, 'fingerprint', fileID);
  60302. },
  60303. getPage: function PDFDocument_getPage(pageIndex) {
  60304. return this.catalog.getPage(pageIndex);
  60305. },
  60306. cleanup: function PDFDocument_cleanup() {
  60307. return this.catalog.cleanup();
  60308. }
  60309. };
  60310. return PDFDocument;
  60311. }();
  60312. exports.Page = Page;
  60313. exports.PDFDocument = PDFDocument;
  60314. }));
  60315. (function (root, factory) {
  60316. factory(root.pdfjsCorePdfManager = {}, root.pdfjsSharedUtil, root.pdfjsCoreStream, root.pdfjsCoreChunkedStream, root.pdfjsCoreDocument);
  60317. }(this, function (exports, sharedUtil, coreStream, coreChunkedStream, coreDocument) {
  60318. var NotImplementedException = sharedUtil.NotImplementedException;
  60319. var MissingDataException = sharedUtil.MissingDataException;
  60320. var createPromiseCapability = sharedUtil.createPromiseCapability;
  60321. var Util = sharedUtil.Util;
  60322. var Stream = coreStream.Stream;
  60323. var ChunkedStreamManager = coreChunkedStream.ChunkedStreamManager;
  60324. var PDFDocument = coreDocument.PDFDocument;
  60325. var BasePdfManager = function BasePdfManagerClosure() {
  60326. function BasePdfManager() {
  60327. throw new Error('Cannot initialize BaseManagerManager');
  60328. }
  60329. BasePdfManager.prototype = {
  60330. get docId() {
  60331. return this._docId;
  60332. },
  60333. onLoadedStream: function BasePdfManager_onLoadedStream() {
  60334. throw new NotImplementedException();
  60335. },
  60336. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  60337. return this.ensure(this.pdfDocument, prop, args);
  60338. },
  60339. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  60340. return this.ensure(this.pdfDocument.xref, prop, args);
  60341. },
  60342. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  60343. return this.ensure(this.pdfDocument.catalog, prop, args);
  60344. },
  60345. getPage: function BasePdfManager_getPage(pageIndex) {
  60346. return this.pdfDocument.getPage(pageIndex);
  60347. },
  60348. cleanup: function BasePdfManager_cleanup() {
  60349. return this.pdfDocument.cleanup();
  60350. },
  60351. ensure: function BasePdfManager_ensure(obj, prop, args) {
  60352. return new NotImplementedException();
  60353. },
  60354. requestRange: function BasePdfManager_requestRange(begin, end) {
  60355. return new NotImplementedException();
  60356. },
  60357. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  60358. return new NotImplementedException();
  60359. },
  60360. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  60361. return new NotImplementedException();
  60362. },
  60363. updatePassword: function BasePdfManager_updatePassword(password) {
  60364. this.pdfDocument.xref.password = this.password = password;
  60365. if (this._passwordChangedCapability) {
  60366. this._passwordChangedCapability.resolve();
  60367. }
  60368. },
  60369. passwordChanged: function BasePdfManager_passwordChanged() {
  60370. this._passwordChangedCapability = createPromiseCapability();
  60371. return this._passwordChangedCapability.promise;
  60372. },
  60373. terminate: function BasePdfManager_terminate() {
  60374. return new NotImplementedException();
  60375. }
  60376. };
  60377. return BasePdfManager;
  60378. }();
  60379. var LocalPdfManager = function LocalPdfManagerClosure() {
  60380. function LocalPdfManager(docId, data, password, evaluatorOptions) {
  60381. this._docId = docId;
  60382. this.evaluatorOptions = evaluatorOptions;
  60383. var stream = new Stream(data);
  60384. this.pdfDocument = new PDFDocument(this, stream, password);
  60385. this._loadedStreamCapability = createPromiseCapability();
  60386. this._loadedStreamCapability.resolve(stream);
  60387. }
  60388. Util.inherit(LocalPdfManager, BasePdfManager, {
  60389. ensure: function LocalPdfManager_ensure(obj, prop, args) {
  60390. return new Promise(function (resolve, reject) {
  60391. try {
  60392. var value = obj[prop];
  60393. var result;
  60394. if (typeof value === 'function') {
  60395. result = value.apply(obj, args);
  60396. } else {
  60397. result = value;
  60398. }
  60399. resolve(result);
  60400. } catch (e) {
  60401. reject(e);
  60402. }
  60403. });
  60404. },
  60405. requestRange: function LocalPdfManager_requestRange(begin, end) {
  60406. return Promise.resolve();
  60407. },
  60408. requestLoadedStream: function LocalPdfManager_requestLoadedStream() {
  60409. return;
  60410. },
  60411. onLoadedStream: function LocalPdfManager_onLoadedStream() {
  60412. return this._loadedStreamCapability.promise;
  60413. },
  60414. terminate: function LocalPdfManager_terminate() {
  60415. return;
  60416. }
  60417. });
  60418. return LocalPdfManager;
  60419. }();
  60420. var NetworkPdfManager = function NetworkPdfManagerClosure() {
  60421. function NetworkPdfManager(docId, pdfNetworkStream, args, evaluatorOptions) {
  60422. this._docId = docId;
  60423. this.msgHandler = args.msgHandler;
  60424. this.evaluatorOptions = evaluatorOptions;
  60425. var params = {
  60426. msgHandler: args.msgHandler,
  60427. url: args.url,
  60428. length: args.length,
  60429. disableAutoFetch: args.disableAutoFetch,
  60430. rangeChunkSize: args.rangeChunkSize
  60431. };
  60432. this.streamManager = new ChunkedStreamManager(pdfNetworkStream, params);
  60433. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(), args.password);
  60434. }
  60435. Util.inherit(NetworkPdfManager, BasePdfManager, {
  60436. ensure: function NetworkPdfManager_ensure(obj, prop, args) {
  60437. var pdfManager = this;
  60438. return new Promise(function (resolve, reject) {
  60439. function ensureHelper() {
  60440. try {
  60441. var result;
  60442. var value = obj[prop];
  60443. if (typeof value === 'function') {
  60444. result = value.apply(obj, args);
  60445. } else {
  60446. result = value;
  60447. }
  60448. resolve(result);
  60449. } catch (e) {
  60450. if (!(e instanceof MissingDataException)) {
  60451. reject(e);
  60452. return;
  60453. }
  60454. pdfManager.streamManager.requestRange(e.begin, e.end).then(ensureHelper, reject);
  60455. }
  60456. }
  60457. ensureHelper();
  60458. });
  60459. },
  60460. requestRange: function NetworkPdfManager_requestRange(begin, end) {
  60461. return this.streamManager.requestRange(begin, end);
  60462. },
  60463. requestLoadedStream: function NetworkPdfManager_requestLoadedStream() {
  60464. this.streamManager.requestAllChunks();
  60465. },
  60466. sendProgressiveData: function NetworkPdfManager_sendProgressiveData(chunk) {
  60467. this.streamManager.onReceiveData({ chunk: chunk });
  60468. },
  60469. onLoadedStream: function NetworkPdfManager_onLoadedStream() {
  60470. return this.streamManager.onLoadedStream();
  60471. },
  60472. terminate: function NetworkPdfManager_terminate() {
  60473. this.streamManager.abort();
  60474. }
  60475. });
  60476. return NetworkPdfManager;
  60477. }();
  60478. exports.LocalPdfManager = LocalPdfManager;
  60479. exports.NetworkPdfManager = NetworkPdfManager;
  60480. }));
  60481. (function (root, factory) {
  60482. factory(root.pdfjsCoreWorker = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCorePdfManager);
  60483. }(this, function (exports, sharedUtil, corePrimitives, corePdfManager) {
  60484. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  60485. var InvalidPDFException = sharedUtil.InvalidPDFException;
  60486. var MessageHandler = sharedUtil.MessageHandler;
  60487. var MissingPDFException = sharedUtil.MissingPDFException;
  60488. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  60489. var PasswordException = sharedUtil.PasswordException;
  60490. var PasswordResponses = sharedUtil.PasswordResponses;
  60491. var UnknownErrorException = sharedUtil.UnknownErrorException;
  60492. var XRefParseException = sharedUtil.XRefParseException;
  60493. var arrayByteLength = sharedUtil.arrayByteLength;
  60494. var arraysToBytes = sharedUtil.arraysToBytes;
  60495. var assert = sharedUtil.assert;
  60496. var createPromiseCapability = sharedUtil.createPromiseCapability;
  60497. var error = sharedUtil.error;
  60498. var info = sharedUtil.info;
  60499. var warn = sharedUtil.warn;
  60500. var setVerbosityLevel = sharedUtil.setVerbosityLevel;
  60501. var Ref = corePrimitives.Ref;
  60502. var LocalPdfManager = corePdfManager.LocalPdfManager;
  60503. var NetworkPdfManager = corePdfManager.NetworkPdfManager;
  60504. var globalScope = sharedUtil.globalScope;
  60505. var WorkerTask = function WorkerTaskClosure() {
  60506. function WorkerTask(name) {
  60507. this.name = name;
  60508. this.terminated = false;
  60509. this._capability = createPromiseCapability();
  60510. }
  60511. WorkerTask.prototype = {
  60512. get finished() {
  60513. return this._capability.promise;
  60514. },
  60515. finish: function () {
  60516. this._capability.resolve();
  60517. },
  60518. terminate: function () {
  60519. this.terminated = true;
  60520. },
  60521. ensureNotTerminated: function () {
  60522. if (this.terminated) {
  60523. throw new Error('Worker task was terminated');
  60524. }
  60525. }
  60526. };
  60527. return WorkerTask;
  60528. }();
  60529. /** @implements {IPDFStream} */
  60530. var PDFWorkerStream = function PDFWorkerStreamClosure() {
  60531. function PDFWorkerStream(params, msgHandler) {
  60532. this._queuedChunks = [];
  60533. var initialData = params.initialData;
  60534. if (initialData && initialData.length > 0) {
  60535. this._queuedChunks.push(initialData);
  60536. }
  60537. this._msgHandler = msgHandler;
  60538. this._isRangeSupported = !params.disableRange;
  60539. this._isStreamingSupported = !params.disableStream;
  60540. this._contentLength = params.length;
  60541. this._fullRequestReader = null;
  60542. this._rangeReaders = [];
  60543. msgHandler.on('OnDataRange', this._onReceiveData.bind(this));
  60544. msgHandler.on('OnDataProgress', this._onProgress.bind(this));
  60545. }
  60546. PDFWorkerStream.prototype = {
  60547. _onReceiveData: function PDFWorkerStream_onReceiveData(args) {
  60548. if (args.begin === undefined) {
  60549. if (this._fullRequestReader) {
  60550. this._fullRequestReader._enqueue(args.chunk);
  60551. } else {
  60552. this._queuedChunks.push(args.chunk);
  60553. }
  60554. } else {
  60555. var found = this._rangeReaders.some(function (rangeReader) {
  60556. if (rangeReader._begin !== args.begin) {
  60557. return false;
  60558. }
  60559. rangeReader._enqueue(args.chunk);
  60560. return true;
  60561. });
  60562. assert(found);
  60563. }
  60564. },
  60565. _onProgress: function PDFWorkerStream_onProgress(evt) {
  60566. if (this._rangeReaders.length > 0) {
  60567. // Reporting to first range reader.
  60568. var firstReader = this._rangeReaders[0];
  60569. if (firstReader.onProgress) {
  60570. firstReader.onProgress({ loaded: evt.loaded });
  60571. }
  60572. }
  60573. },
  60574. _removeRangeReader: function PDFWorkerStream_removeRangeReader(reader) {
  60575. var i = this._rangeReaders.indexOf(reader);
  60576. if (i >= 0) {
  60577. this._rangeReaders.splice(i, 1);
  60578. }
  60579. },
  60580. getFullReader: function PDFWorkerStream_getFullReader() {
  60581. assert(!this._fullRequestReader);
  60582. var queuedChunks = this._queuedChunks;
  60583. this._queuedChunks = null;
  60584. return new PDFWorkerStreamReader(this, queuedChunks);
  60585. },
  60586. getRangeReader: function PDFWorkerStream_getRangeReader(begin, end) {
  60587. var reader = new PDFWorkerStreamRangeReader(this, begin, end);
  60588. this._msgHandler.send('RequestDataRange', {
  60589. begin: begin,
  60590. end: end
  60591. });
  60592. this._rangeReaders.push(reader);
  60593. return reader;
  60594. },
  60595. cancelAllRequests: function PDFWorkerStream_cancelAllRequests(reason) {
  60596. if (this._fullRequestReader) {
  60597. this._fullRequestReader.cancel(reason);
  60598. }
  60599. var readers = this._rangeReaders.slice(0);
  60600. readers.forEach(function (rangeReader) {
  60601. rangeReader.cancel(reason);
  60602. });
  60603. }
  60604. };
  60605. /** @implements {IPDFStreamReader} */
  60606. function PDFWorkerStreamReader(stream, queuedChunks) {
  60607. this._stream = stream;
  60608. this._done = false;
  60609. this._queuedChunks = queuedChunks || [];
  60610. this._requests = [];
  60611. this._headersReady = Promise.resolve();
  60612. stream._fullRequestReader = this;
  60613. this.onProgress = null;
  60614. }
  60615. // not used
  60616. PDFWorkerStreamReader.prototype = {
  60617. _enqueue: function PDFWorkerStreamReader_enqueue(chunk) {
  60618. if (this._done) {
  60619. return;
  60620. }
  60621. // ignore new data
  60622. if (this._requests.length > 0) {
  60623. var requestCapability = this._requests.shift();
  60624. requestCapability.resolve({
  60625. value: chunk,
  60626. done: false
  60627. });
  60628. return;
  60629. }
  60630. this._queuedChunks.push(chunk);
  60631. },
  60632. get headersReady() {
  60633. return this._headersReady;
  60634. },
  60635. get isRangeSupported() {
  60636. return this._stream._isRangeSupported;
  60637. },
  60638. get isStreamingSupported() {
  60639. return this._stream._isStreamingSupported;
  60640. },
  60641. get contentLength() {
  60642. return this._stream._contentLength;
  60643. },
  60644. read: function PDFWorkerStreamReader_read() {
  60645. if (this._queuedChunks.length > 0) {
  60646. var chunk = this._queuedChunks.shift();
  60647. return Promise.resolve({
  60648. value: chunk,
  60649. done: false
  60650. });
  60651. }
  60652. if (this._done) {
  60653. return Promise.resolve({
  60654. value: undefined,
  60655. done: true
  60656. });
  60657. }
  60658. var requestCapability = createPromiseCapability();
  60659. this._requests.push(requestCapability);
  60660. return requestCapability.promise;
  60661. },
  60662. cancel: function PDFWorkerStreamReader_cancel(reason) {
  60663. this._done = true;
  60664. this._requests.forEach(function (requestCapability) {
  60665. requestCapability.resolve({
  60666. value: undefined,
  60667. done: true
  60668. });
  60669. });
  60670. this._requests = [];
  60671. }
  60672. };
  60673. /** @implements {IPDFStreamRangeReader} */
  60674. function PDFWorkerStreamRangeReader(stream, begin, end) {
  60675. this._stream = stream;
  60676. this._begin = begin;
  60677. this._end = end;
  60678. this._queuedChunk = null;
  60679. this._requests = [];
  60680. this._done = false;
  60681. this.onProgress = null;
  60682. }
  60683. PDFWorkerStreamRangeReader.prototype = {
  60684. _enqueue: function PDFWorkerStreamRangeReader_enqueue(chunk) {
  60685. if (this._done) {
  60686. return;
  60687. }
  60688. // ignore new data
  60689. if (this._requests.length === 0) {
  60690. this._queuedChunk = chunk;
  60691. } else {
  60692. var requestsCapability = this._requests.shift();
  60693. requestsCapability.resolve({
  60694. value: chunk,
  60695. done: false
  60696. });
  60697. this._requests.forEach(function (requestCapability) {
  60698. requestCapability.resolve({
  60699. value: undefined,
  60700. done: true
  60701. });
  60702. });
  60703. this._requests = [];
  60704. }
  60705. this._done = true;
  60706. this._stream._removeRangeReader(this);
  60707. },
  60708. get isStreamingSupported() {
  60709. return false;
  60710. },
  60711. read: function PDFWorkerStreamRangeReader_read() {
  60712. if (this._queuedChunk) {
  60713. return Promise.resolve({
  60714. value: this._queuedChunk,
  60715. done: false
  60716. });
  60717. }
  60718. if (this._done) {
  60719. return Promise.resolve({
  60720. value: undefined,
  60721. done: true
  60722. });
  60723. }
  60724. var requestCapability = createPromiseCapability();
  60725. this._requests.push(requestCapability);
  60726. return requestCapability.promise;
  60727. },
  60728. cancel: function PDFWorkerStreamRangeReader_cancel(reason) {
  60729. this._done = true;
  60730. this._requests.forEach(function (requestCapability) {
  60731. requestCapability.resolve({
  60732. value: undefined,
  60733. done: true
  60734. });
  60735. });
  60736. this._requests = [];
  60737. this._stream._removeRangeReader(this);
  60738. }
  60739. };
  60740. return PDFWorkerStream;
  60741. }();
  60742. /** @type IPDFStream */
  60743. var PDFNetworkStream;
  60744. /**
  60745. * Sets PDFNetworkStream class to be used as alternative PDF data transport.
  60746. * @param {IPDFStream} cls - the PDF data transport.
  60747. */
  60748. function setPDFNetworkStreamClass(cls) {
  60749. PDFNetworkStream = cls;
  60750. }
  60751. var WorkerMessageHandler = {
  60752. setup: function wphSetup(handler, port) {
  60753. var testMessageProcessed = false;
  60754. handler.on('test', function wphSetupTest(data) {
  60755. if (testMessageProcessed) {
  60756. return;
  60757. }
  60758. // we already processed 'test' message once
  60759. testMessageProcessed = true;
  60760. // check if Uint8Array can be sent to worker
  60761. if (!(data instanceof Uint8Array)) {
  60762. handler.send('test', 'main', false);
  60763. return;
  60764. }
  60765. // making sure postMessage transfers are working
  60766. var supportTransfers = data[0] === 255;
  60767. handler.postMessageTransfers = supportTransfers;
  60768. // check if the response property is supported by xhr
  60769. var xhr = new XMLHttpRequest();
  60770. var responseExists = 'response' in xhr;
  60771. // check if the property is actually implemented
  60772. try {
  60773. var dummy = xhr.responseType;
  60774. } catch (e) {
  60775. responseExists = false;
  60776. }
  60777. if (!responseExists) {
  60778. handler.send('test', false);
  60779. return;
  60780. }
  60781. handler.send('test', {
  60782. supportTypedArray: true,
  60783. supportTransfers: supportTransfers
  60784. });
  60785. });
  60786. handler.on('configure', function wphConfigure(data) {
  60787. setVerbosityLevel(data.verbosity);
  60788. });
  60789. handler.on('GetDocRequest', function wphSetupDoc(data) {
  60790. return WorkerMessageHandler.createDocumentHandler(data, port);
  60791. });
  60792. },
  60793. createDocumentHandler: function wphCreateDocumentHandler(docParams, port) {
  60794. // This context is actually holds references on pdfManager and handler,
  60795. // until the latter is destroyed.
  60796. var pdfManager;
  60797. var terminated = false;
  60798. var cancelXHRs = null;
  60799. var WorkerTasks = [];
  60800. var docId = docParams.docId;
  60801. var workerHandlerName = docParams.docId + '_worker';
  60802. var handler = new MessageHandler(workerHandlerName, docId, port);
  60803. // Ensure that postMessage transfers are correctly enabled/disabled,
  60804. // to prevent "DataCloneError" in older versions of IE (see issue 6957).
  60805. handler.postMessageTransfers = docParams.postMessageTransfers;
  60806. function ensureNotTerminated() {
  60807. if (terminated) {
  60808. throw new Error('Worker was terminated');
  60809. }
  60810. }
  60811. function startWorkerTask(task) {
  60812. WorkerTasks.push(task);
  60813. }
  60814. function finishWorkerTask(task) {
  60815. task.finish();
  60816. var i = WorkerTasks.indexOf(task);
  60817. WorkerTasks.splice(i, 1);
  60818. }
  60819. function loadDocument(recoveryMode) {
  60820. var loadDocumentCapability = createPromiseCapability();
  60821. var parseSuccess = function parseSuccess() {
  60822. var numPagesPromise = pdfManager.ensureDoc('numPages');
  60823. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  60824. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  60825. Promise.all([
  60826. numPagesPromise,
  60827. fingerprintPromise,
  60828. encryptedPromise
  60829. ]).then(function onDocReady(results) {
  60830. var doc = {
  60831. numPages: results[0],
  60832. fingerprint: results[1],
  60833. encrypted: !!results[2]
  60834. };
  60835. loadDocumentCapability.resolve(doc);
  60836. }, parseFailure);
  60837. };
  60838. var parseFailure = function parseFailure(e) {
  60839. loadDocumentCapability.reject(e);
  60840. };
  60841. pdfManager.ensureDoc('checkHeader', []).then(function () {
  60842. pdfManager.ensureDoc('parseStartXRef', []).then(function () {
  60843. pdfManager.ensureDoc('parse', [recoveryMode]).then(parseSuccess, parseFailure);
  60844. }, parseFailure);
  60845. }, parseFailure);
  60846. return loadDocumentCapability.promise;
  60847. }
  60848. function getPdfManager(data, evaluatorOptions) {
  60849. var pdfManagerCapability = createPromiseCapability();
  60850. var pdfManager;
  60851. var source = data.source;
  60852. if (source.data) {
  60853. try {
  60854. pdfManager = new LocalPdfManager(docId, source.data, source.password, evaluatorOptions);
  60855. pdfManagerCapability.resolve(pdfManager);
  60856. } catch (ex) {
  60857. pdfManagerCapability.reject(ex);
  60858. }
  60859. return pdfManagerCapability.promise;
  60860. }
  60861. var pdfStream;
  60862. try {
  60863. if (source.chunkedViewerLoading) {
  60864. pdfStream = new PDFWorkerStream(source, handler);
  60865. } else {
  60866. assert(PDFNetworkStream, 'pdfjs/core/network module is not loaded');
  60867. pdfStream = new PDFNetworkStream(data);
  60868. }
  60869. } catch (ex) {
  60870. pdfManagerCapability.reject(ex);
  60871. return pdfManagerCapability.promise;
  60872. }
  60873. var fullRequest = pdfStream.getFullReader();
  60874. fullRequest.headersReady.then(function () {
  60875. if (!fullRequest.isStreamingSupported || !fullRequest.isRangeSupported) {
  60876. // If stream or range are disabled, it's our only way to report
  60877. // loading progress.
  60878. fullRequest.onProgress = function (evt) {
  60879. handler.send('DocProgress', {
  60880. loaded: evt.loaded,
  60881. total: evt.total
  60882. });
  60883. };
  60884. }
  60885. if (!fullRequest.isRangeSupported) {
  60886. return;
  60887. }
  60888. // We don't need auto-fetch when streaming is enabled.
  60889. var disableAutoFetch = source.disableAutoFetch || fullRequest.isStreamingSupported;
  60890. pdfManager = new NetworkPdfManager(docId, pdfStream, {
  60891. msgHandler: handler,
  60892. url: source.url,
  60893. password: source.password,
  60894. length: fullRequest.contentLength,
  60895. disableAutoFetch: disableAutoFetch,
  60896. rangeChunkSize: source.rangeChunkSize
  60897. }, evaluatorOptions);
  60898. pdfManagerCapability.resolve(pdfManager);
  60899. cancelXHRs = null;
  60900. }).catch(function (reason) {
  60901. pdfManagerCapability.reject(reason);
  60902. cancelXHRs = null;
  60903. });
  60904. var cachedChunks = [], loaded = 0;
  60905. var flushChunks = function () {
  60906. var pdfFile = arraysToBytes(cachedChunks);
  60907. if (source.length && pdfFile.length !== source.length) {
  60908. warn('reported HTTP length is different from actual');
  60909. }
  60910. // the data is array, instantiating directly from it
  60911. try {
  60912. pdfManager = new LocalPdfManager(docId, pdfFile, source.password, evaluatorOptions);
  60913. pdfManagerCapability.resolve(pdfManager);
  60914. } catch (ex) {
  60915. pdfManagerCapability.reject(ex);
  60916. }
  60917. cachedChunks = [];
  60918. };
  60919. var readPromise = new Promise(function (resolve, reject) {
  60920. var readChunk = function (chunk) {
  60921. try {
  60922. ensureNotTerminated();
  60923. if (chunk.done) {
  60924. if (!pdfManager) {
  60925. flushChunks();
  60926. }
  60927. cancelXHRs = null;
  60928. return;
  60929. }
  60930. var data = chunk.value;
  60931. loaded += arrayByteLength(data);
  60932. if (!fullRequest.isStreamingSupported) {
  60933. handler.send('DocProgress', {
  60934. loaded: loaded,
  60935. total: Math.max(loaded, fullRequest.contentLength || 0)
  60936. });
  60937. }
  60938. if (pdfManager) {
  60939. pdfManager.sendProgressiveData(data);
  60940. } else {
  60941. cachedChunks.push(data);
  60942. }
  60943. fullRequest.read().then(readChunk, reject);
  60944. } catch (e) {
  60945. reject(e);
  60946. }
  60947. };
  60948. fullRequest.read().then(readChunk, reject);
  60949. });
  60950. readPromise.catch(function (e) {
  60951. pdfManagerCapability.reject(e);
  60952. cancelXHRs = null;
  60953. });
  60954. cancelXHRs = function () {
  60955. pdfStream.cancelAllRequests('abort');
  60956. };
  60957. return pdfManagerCapability.promise;
  60958. }
  60959. var setupDoc = function (data) {
  60960. var onSuccess = function (doc) {
  60961. ensureNotTerminated();
  60962. handler.send('GetDoc', { pdfInfo: doc });
  60963. };
  60964. var onFailure = function (e) {
  60965. if (e instanceof PasswordException) {
  60966. if (e.code === PasswordResponses.NEED_PASSWORD) {
  60967. handler.send('NeedPassword', e);
  60968. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  60969. handler.send('IncorrectPassword', e);
  60970. }
  60971. } else if (e instanceof InvalidPDFException) {
  60972. handler.send('InvalidPDF', e);
  60973. } else if (e instanceof MissingPDFException) {
  60974. handler.send('MissingPDF', e);
  60975. } else if (e instanceof UnexpectedResponseException) {
  60976. handler.send('UnexpectedResponse', e);
  60977. } else {
  60978. handler.send('UnknownError', new UnknownErrorException(e.message, e.toString()));
  60979. }
  60980. };
  60981. ensureNotTerminated();
  60982. var cMapOptions = {
  60983. url: data.cMapUrl === undefined ? null : data.cMapUrl,
  60984. packed: data.cMapPacked === true
  60985. };
  60986. var evaluatorOptions = {
  60987. forceDataSchema: data.disableCreateObjectURL,
  60988. maxImageSize: data.maxImageSize === undefined ? -1 : data.maxImageSize,
  60989. disableFontFace: data.disableFontFace,
  60990. cMapOptions: cMapOptions
  60991. };
  60992. getPdfManager(data, evaluatorOptions).then(function (newPdfManager) {
  60993. if (terminated) {
  60994. // We were in a process of setting up the manager, but it got
  60995. // terminated in the middle.
  60996. newPdfManager.terminate();
  60997. throw new Error('Worker was terminated');
  60998. }
  60999. pdfManager = newPdfManager;
  61000. handler.send('PDFManagerReady', null);
  61001. pdfManager.onLoadedStream().then(function (stream) {
  61002. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  61003. });
  61004. }).then(function pdfManagerReady() {
  61005. ensureNotTerminated();
  61006. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  61007. ensureNotTerminated();
  61008. // Try again with recoveryMode == true
  61009. if (!(ex instanceof XRefParseException)) {
  61010. if (ex instanceof PasswordException) {
  61011. // after password exception prepare to receive a new password
  61012. // to repeat loading
  61013. pdfManager.passwordChanged().then(pdfManagerReady);
  61014. }
  61015. onFailure(ex);
  61016. return;
  61017. }
  61018. pdfManager.requestLoadedStream();
  61019. pdfManager.onLoadedStream().then(function () {
  61020. ensureNotTerminated();
  61021. loadDocument(true).then(onSuccess, onFailure);
  61022. });
  61023. }, onFailure);
  61024. }, onFailure);
  61025. };
  61026. handler.on('GetPage', function wphSetupGetPage(data) {
  61027. return pdfManager.getPage(data.pageIndex).then(function (page) {
  61028. var rotatePromise = pdfManager.ensure(page, 'rotate');
  61029. var refPromise = pdfManager.ensure(page, 'ref');
  61030. var viewPromise = pdfManager.ensure(page, 'view');
  61031. return Promise.all([
  61032. rotatePromise,
  61033. refPromise,
  61034. viewPromise
  61035. ]).then(function (results) {
  61036. return {
  61037. rotate: results[0],
  61038. ref: results[1],
  61039. view: results[2]
  61040. };
  61041. });
  61042. });
  61043. });
  61044. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  61045. var ref = new Ref(data.ref.num, data.ref.gen);
  61046. var catalog = pdfManager.pdfDocument.catalog;
  61047. return catalog.getPageIndex(ref);
  61048. });
  61049. handler.on('GetDestinations', function wphSetupGetDestinations(data) {
  61050. return pdfManager.ensureCatalog('destinations');
  61051. });
  61052. handler.on('GetDestination', function wphSetupGetDestination(data) {
  61053. return pdfManager.ensureCatalog('getDestination', [data.id]);
  61054. });
  61055. handler.on('GetPageLabels', function wphSetupGetPageLabels(data) {
  61056. return pdfManager.ensureCatalog('pageLabels');
  61057. });
  61058. handler.on('GetAttachments', function wphSetupGetAttachments(data) {
  61059. return pdfManager.ensureCatalog('attachments');
  61060. });
  61061. handler.on('GetJavaScript', function wphSetupGetJavaScript(data) {
  61062. return pdfManager.ensureCatalog('javaScript');
  61063. });
  61064. handler.on('GetOutline', function wphSetupGetOutline(data) {
  61065. return pdfManager.ensureCatalog('documentOutline');
  61066. });
  61067. handler.on('GetMetadata', function wphSetupGetMetadata(data) {
  61068. return Promise.all([
  61069. pdfManager.ensureDoc('documentInfo'),
  61070. pdfManager.ensureCatalog('metadata')
  61071. ]);
  61072. });
  61073. handler.on('GetData', function wphSetupGetData(data) {
  61074. pdfManager.requestLoadedStream();
  61075. return pdfManager.onLoadedStream().then(function (stream) {
  61076. return stream.bytes;
  61077. });
  61078. });
  61079. handler.on('GetStats', function wphSetupGetStats(data) {
  61080. return pdfManager.pdfDocument.xref.stats;
  61081. });
  61082. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  61083. pdfManager.updatePassword(data);
  61084. });
  61085. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  61086. return pdfManager.getPage(data.pageIndex).then(function (page) {
  61087. return pdfManager.ensure(page, 'getAnnotationsData', [data.intent]);
  61088. });
  61089. });
  61090. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  61091. var pageIndex = data.pageIndex;
  61092. pdfManager.getPage(pageIndex).then(function (page) {
  61093. var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
  61094. startWorkerTask(task);
  61095. var pageNum = pageIndex + 1;
  61096. var start = Date.now();
  61097. // Pre compile the pdf page and fetch the fonts/images.
  61098. page.getOperatorList(handler, task, data.intent, data.renderInteractiveForms).then(function (operatorList) {
  61099. finishWorkerTask(task);
  61100. info('page=' + pageNum + ' - getOperatorList: time=' + (Date.now() - start) + 'ms, len=' + operatorList.totalLength);
  61101. }, function (e) {
  61102. finishWorkerTask(task);
  61103. if (task.terminated) {
  61104. return;
  61105. }
  61106. // ignoring errors from the terminated thread
  61107. // For compatibility with older behavior, generating unknown
  61108. // unsupported feature notification on errors.
  61109. handler.send('UnsupportedFeature', { featureId: UNSUPPORTED_FEATURES.unknown });
  61110. var minimumStackMessage = 'worker.js: while trying to getPage() and getOperatorList()';
  61111. var wrappedException;
  61112. // Turn the error into an obj that can be serialized
  61113. if (typeof e === 'string') {
  61114. wrappedException = {
  61115. message: e,
  61116. stack: minimumStackMessage
  61117. };
  61118. } else if (typeof e === 'object') {
  61119. wrappedException = {
  61120. message: e.message || e.toString(),
  61121. stack: e.stack || minimumStackMessage
  61122. };
  61123. } else {
  61124. wrappedException = {
  61125. message: 'Unknown exception type: ' + typeof e,
  61126. stack: minimumStackMessage
  61127. };
  61128. }
  61129. handler.send('PageError', {
  61130. pageNum: pageNum,
  61131. error: wrappedException,
  61132. intent: data.intent
  61133. });
  61134. });
  61135. });
  61136. }, this);
  61137. handler.on('GetTextContent', function wphExtractText(data) {
  61138. var pageIndex = data.pageIndex;
  61139. var normalizeWhitespace = data.normalizeWhitespace;
  61140. var combineTextItems = data.combineTextItems;
  61141. return pdfManager.getPage(pageIndex).then(function (page) {
  61142. var task = new WorkerTask('GetTextContent: page ' + pageIndex);
  61143. startWorkerTask(task);
  61144. var pageNum = pageIndex + 1;
  61145. var start = Date.now();
  61146. return page.extractTextContent(task, normalizeWhitespace, combineTextItems).then(function (textContent) {
  61147. finishWorkerTask(task);
  61148. info('text indexing: page=' + pageNum + ' - time=' + (Date.now() - start) + 'ms');
  61149. return textContent;
  61150. }, function (reason) {
  61151. finishWorkerTask(task);
  61152. if (task.terminated) {
  61153. return;
  61154. }
  61155. // ignoring errors from the terminated thread
  61156. throw reason;
  61157. });
  61158. });
  61159. });
  61160. handler.on('Cleanup', function wphCleanup(data) {
  61161. return pdfManager.cleanup();
  61162. });
  61163. handler.on('Terminate', function wphTerminate(data) {
  61164. terminated = true;
  61165. if (pdfManager) {
  61166. pdfManager.terminate();
  61167. pdfManager = null;
  61168. }
  61169. if (cancelXHRs) {
  61170. cancelXHRs();
  61171. }
  61172. var waitOn = [];
  61173. WorkerTasks.forEach(function (task) {
  61174. waitOn.push(task.finished);
  61175. task.terminate();
  61176. });
  61177. return Promise.all(waitOn).then(function () {
  61178. // Notice that even if we destroying handler, resolved response promise
  61179. // must be sent back.
  61180. handler.destroy();
  61181. handler = null;
  61182. });
  61183. });
  61184. handler.on('Ready', function wphReady(data) {
  61185. setupDoc(docParams);
  61186. docParams = null;
  61187. });
  61188. // we don't need docParams anymore -- saving memory.
  61189. return workerHandlerName;
  61190. }
  61191. };
  61192. function initializeWorker() {
  61193. if (!('console' in globalScope)) {
  61194. var consoleTimer = {};
  61195. var workerConsole = {
  61196. log: function log() {
  61197. var args = Array.prototype.slice.call(arguments);
  61198. globalScope.postMessage({
  61199. targetName: 'main',
  61200. action: 'console_log',
  61201. data: args
  61202. });
  61203. },
  61204. error: function error() {
  61205. var args = Array.prototype.slice.call(arguments);
  61206. globalScope.postMessage({
  61207. targetName: 'main',
  61208. action: 'console_error',
  61209. data: args
  61210. });
  61211. throw 'pdf.js execution error';
  61212. },
  61213. time: function time(name) {
  61214. consoleTimer[name] = Date.now();
  61215. },
  61216. timeEnd: function timeEnd(name) {
  61217. var time = consoleTimer[name];
  61218. if (!time) {
  61219. error('Unknown timer name ' + name);
  61220. }
  61221. this.log('Timer:', name, Date.now() - time);
  61222. }
  61223. };
  61224. globalScope.console = workerConsole;
  61225. }
  61226. var handler = new MessageHandler('worker', 'main', self);
  61227. WorkerMessageHandler.setup(handler, self);
  61228. handler.send('ready', null);
  61229. }
  61230. // Worker thread (and not node.js)?
  61231. if (typeof window === 'undefined' && !(typeof module !== 'undefined' && module.require)) {
  61232. initializeWorker();
  61233. }
  61234. exports.setPDFNetworkStreamClass = setPDFNetworkStreamClass;
  61235. exports.WorkerTask = WorkerTask;
  61236. exports.WorkerMessageHandler = WorkerMessageHandler;
  61237. }));
  61238. (function (root, factory) {
  61239. factory(root.pdfjsCoreNetwork = {}, root.pdfjsSharedUtil, root.pdfjsCoreWorker);
  61240. }(this, function (exports, sharedUtil, coreWorker) {
  61241. var OK_RESPONSE = 200;
  61242. var PARTIAL_CONTENT_RESPONSE = 206;
  61243. function NetworkManager(url, args) {
  61244. this.url = url;
  61245. args = args || {};
  61246. this.isHttp = /^https?:/i.test(url);
  61247. this.httpHeaders = this.isHttp && args.httpHeaders || {};
  61248. this.withCredentials = args.withCredentials || false;
  61249. this.getXhr = args.getXhr || function NetworkManager_getXhr() {
  61250. return new XMLHttpRequest();
  61251. };
  61252. this.currXhrId = 0;
  61253. this.pendingRequests = Object.create(null);
  61254. this.loadedRequests = Object.create(null);
  61255. }
  61256. function getArrayBuffer(xhr) {
  61257. var data = xhr.response;
  61258. if (typeof data !== 'string') {
  61259. return data;
  61260. }
  61261. var length = data.length;
  61262. var array = new Uint8Array(length);
  61263. for (var i = 0; i < length; i++) {
  61264. array[i] = data.charCodeAt(i) & 0xFF;
  61265. }
  61266. return array.buffer;
  61267. }
  61268. var supportsMozChunked = function supportsMozChunkedClosure() {
  61269. try {
  61270. var x = new XMLHttpRequest();
  61271. // Firefox 37- required .open() to be called before setting responseType.
  61272. // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
  61273. // Even though the URL is not visited, .open() could fail if the URL is
  61274. // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
  61275. // When this error occurs, this feature detection method will mistakenly
  61276. // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
  61277. x.open('GET', 'https://example.com');
  61278. x.responseType = 'moz-chunked-arraybuffer';
  61279. return x.responseType === 'moz-chunked-arraybuffer';
  61280. } catch (e) {
  61281. return false;
  61282. }
  61283. }();
  61284. NetworkManager.prototype = {
  61285. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  61286. var args = {
  61287. begin: begin,
  61288. end: end
  61289. };
  61290. for (var prop in listeners) {
  61291. args[prop] = listeners[prop];
  61292. }
  61293. return this.request(args);
  61294. },
  61295. requestFull: function NetworkManager_requestFull(listeners) {
  61296. return this.request(listeners);
  61297. },
  61298. request: function NetworkManager_request(args) {
  61299. var xhr = this.getXhr();
  61300. var xhrId = this.currXhrId++;
  61301. var pendingRequest = this.pendingRequests[xhrId] = { xhr: xhr };
  61302. xhr.open('GET', this.url);
  61303. xhr.withCredentials = this.withCredentials;
  61304. for (var property in this.httpHeaders) {
  61305. var value = this.httpHeaders[property];
  61306. if (typeof value === 'undefined') {
  61307. continue;
  61308. }
  61309. xhr.setRequestHeader(property, value);
  61310. }
  61311. if (this.isHttp && 'begin' in args && 'end' in args) {
  61312. var rangeStr = args.begin + '-' + (args.end - 1);
  61313. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  61314. pendingRequest.expectedStatus = 206;
  61315. } else {
  61316. pendingRequest.expectedStatus = 200;
  61317. }
  61318. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  61319. if (useMozChunkedLoading) {
  61320. xhr.responseType = 'moz-chunked-arraybuffer';
  61321. pendingRequest.onProgressiveData = args.onProgressiveData;
  61322. pendingRequest.mozChunked = true;
  61323. } else {
  61324. xhr.responseType = 'arraybuffer';
  61325. }
  61326. if (args.onError) {
  61327. xhr.onerror = function (evt) {
  61328. args.onError(xhr.status);
  61329. };
  61330. }
  61331. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  61332. xhr.onprogress = this.onProgress.bind(this, xhrId);
  61333. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  61334. pendingRequest.onDone = args.onDone;
  61335. pendingRequest.onError = args.onError;
  61336. pendingRequest.onProgress = args.onProgress;
  61337. xhr.send(null);
  61338. return xhrId;
  61339. },
  61340. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  61341. var pendingRequest = this.pendingRequests[xhrId];
  61342. if (!pendingRequest) {
  61343. // Maybe abortRequest was called...
  61344. return;
  61345. }
  61346. if (pendingRequest.mozChunked) {
  61347. var chunk = getArrayBuffer(pendingRequest.xhr);
  61348. pendingRequest.onProgressiveData(chunk);
  61349. }
  61350. var onProgress = pendingRequest.onProgress;
  61351. if (onProgress) {
  61352. onProgress(evt);
  61353. }
  61354. },
  61355. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  61356. var pendingRequest = this.pendingRequests[xhrId];
  61357. if (!pendingRequest) {
  61358. // Maybe abortRequest was called...
  61359. return;
  61360. }
  61361. var xhr = pendingRequest.xhr;
  61362. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  61363. pendingRequest.onHeadersReceived();
  61364. delete pendingRequest.onHeadersReceived;
  61365. }
  61366. if (xhr.readyState !== 4) {
  61367. return;
  61368. }
  61369. if (!(xhrId in this.pendingRequests)) {
  61370. // The XHR request might have been aborted in onHeadersReceived()
  61371. // callback, in which case we should abort request
  61372. return;
  61373. }
  61374. delete this.pendingRequests[xhrId];
  61375. // success status == 0 can be on ftp, file and other protocols
  61376. if (xhr.status === 0 && this.isHttp) {
  61377. if (pendingRequest.onError) {
  61378. pendingRequest.onError(xhr.status);
  61379. }
  61380. return;
  61381. }
  61382. var xhrStatus = xhr.status || OK_RESPONSE;
  61383. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  61384. // "A server MAY ignore the Range header". This means it's possible to
  61385. // get a 200 rather than a 206 response from a range request.
  61386. var ok_response_on_range_request = xhrStatus === OK_RESPONSE && pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  61387. if (!ok_response_on_range_request && xhrStatus !== pendingRequest.expectedStatus) {
  61388. if (pendingRequest.onError) {
  61389. pendingRequest.onError(xhr.status);
  61390. }
  61391. return;
  61392. }
  61393. this.loadedRequests[xhrId] = true;
  61394. var chunk = getArrayBuffer(xhr);
  61395. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  61396. var rangeHeader = xhr.getResponseHeader('Content-Range');
  61397. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  61398. var begin = parseInt(matches[1], 10);
  61399. pendingRequest.onDone({
  61400. begin: begin,
  61401. chunk: chunk
  61402. });
  61403. } else if (pendingRequest.onProgressiveData) {
  61404. pendingRequest.onDone(null);
  61405. } else if (chunk) {
  61406. pendingRequest.onDone({
  61407. begin: 0,
  61408. chunk: chunk
  61409. });
  61410. } else if (pendingRequest.onError) {
  61411. pendingRequest.onError(xhr.status);
  61412. }
  61413. },
  61414. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  61415. for (var xhrId in this.pendingRequests) {
  61416. return true;
  61417. }
  61418. return false;
  61419. },
  61420. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  61421. return this.pendingRequests[xhrId].xhr;
  61422. },
  61423. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  61424. return !!this.pendingRequests[xhrId].onProgressiveData;
  61425. },
  61426. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  61427. return xhrId in this.pendingRequests;
  61428. },
  61429. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  61430. return xhrId in this.loadedRequests;
  61431. },
  61432. abortAllRequests: function NetworkManager_abortAllRequests() {
  61433. for (var xhrId in this.pendingRequests) {
  61434. this.abortRequest(xhrId | 0);
  61435. }
  61436. },
  61437. abortRequest: function NetworkManager_abortRequest(xhrId) {
  61438. var xhr = this.pendingRequests[xhrId].xhr;
  61439. delete this.pendingRequests[xhrId];
  61440. xhr.abort();
  61441. }
  61442. };
  61443. var assert = sharedUtil.assert;
  61444. var createPromiseCapability = sharedUtil.createPromiseCapability;
  61445. var isInt = sharedUtil.isInt;
  61446. var MissingPDFException = sharedUtil.MissingPDFException;
  61447. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  61448. /** @implements {IPDFStream} */
  61449. function PDFNetworkStream(options) {
  61450. this._options = options;
  61451. var source = options.source;
  61452. this._manager = new NetworkManager(source.url, {
  61453. httpHeaders: source.httpHeaders,
  61454. withCredentials: source.withCredentials
  61455. });
  61456. this._rangeChunkSize = source.rangeChunkSize;
  61457. this._fullRequestReader = null;
  61458. this._rangeRequestReaders = [];
  61459. }
  61460. PDFNetworkStream.prototype = {
  61461. _onRangeRequestReaderClosed: function PDFNetworkStream_onRangeRequestReaderClosed(reader) {
  61462. var i = this._rangeRequestReaders.indexOf(reader);
  61463. if (i >= 0) {
  61464. this._rangeRequestReaders.splice(i, 1);
  61465. }
  61466. },
  61467. getFullReader: function PDFNetworkStream_getFullReader() {
  61468. assert(!this._fullRequestReader);
  61469. this._fullRequestReader = new PDFNetworkStreamFullRequestReader(this._manager, this._options);
  61470. return this._fullRequestReader;
  61471. },
  61472. getRangeReader: function PDFNetworkStream_getRangeReader(begin, end) {
  61473. var reader = new PDFNetworkStreamRangeRequestReader(this._manager, begin, end);
  61474. reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
  61475. this._rangeRequestReaders.push(reader);
  61476. return reader;
  61477. },
  61478. cancelAllRequests: function PDFNetworkStream_cancelAllRequests(reason) {
  61479. if (this._fullRequestReader) {
  61480. this._fullRequestReader.cancel(reason);
  61481. }
  61482. var readers = this._rangeRequestReaders.slice(0);
  61483. readers.forEach(function (reader) {
  61484. reader.cancel(reason);
  61485. });
  61486. }
  61487. };
  61488. /** @implements {IPDFStreamReader} */
  61489. function PDFNetworkStreamFullRequestReader(manager, options) {
  61490. this._manager = manager;
  61491. var source = options.source;
  61492. var args = {
  61493. onHeadersReceived: this._onHeadersReceived.bind(this),
  61494. onProgressiveData: source.disableStream ? null : this._onProgressiveData.bind(this),
  61495. onDone: this._onDone.bind(this),
  61496. onError: this._onError.bind(this),
  61497. onProgress: this._onProgress.bind(this)
  61498. };
  61499. this._url = source.url;
  61500. this._fullRequestId = manager.requestFull(args);
  61501. this._headersReceivedCapability = createPromiseCapability();
  61502. this._disableRange = options.disableRange || false;
  61503. this._contentLength = source.length;
  61504. // optional
  61505. this._rangeChunkSize = source.rangeChunkSize;
  61506. if (!this._rangeChunkSize && !this._disableRange) {
  61507. this._disableRange = true;
  61508. }
  61509. this._isStreamingSupported = false;
  61510. this._isRangeSupported = false;
  61511. this._cachedChunks = [];
  61512. this._requests = [];
  61513. this._done = false;
  61514. this._storedError = undefined;
  61515. this.onProgress = null;
  61516. }
  61517. PDFNetworkStreamFullRequestReader.prototype = {
  61518. _validateRangeRequestCapabilities: function PDFNetworkStreamFullRequestReader_validateRangeRequestCapabilities() {
  61519. if (this._disableRange) {
  61520. return false;
  61521. }
  61522. var networkManager = this._manager;
  61523. var fullRequestXhrId = this._fullRequestId;
  61524. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  61525. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  61526. return false;
  61527. }
  61528. var contentEncoding = fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  61529. if (contentEncoding !== 'identity') {
  61530. return false;
  61531. }
  61532. var length = fullRequestXhr.getResponseHeader('Content-Length');
  61533. length = parseInt(length, 10);
  61534. if (!isInt(length)) {
  61535. return false;
  61536. }
  61537. this._contentLength = length;
  61538. // setting right content length
  61539. if (length <= 2 * this._rangeChunkSize) {
  61540. // The file size is smaller than the size of two chunks, so it does
  61541. // not make any sense to abort the request and retry with a range
  61542. // request.
  61543. return false;
  61544. }
  61545. return true;
  61546. },
  61547. _onHeadersReceived: function PDFNetworkStreamFullRequestReader_onHeadersReceived() {
  61548. if (this._validateRangeRequestCapabilities()) {
  61549. this._isRangeSupported = true;
  61550. }
  61551. var networkManager = this._manager;
  61552. var fullRequestXhrId = this._fullRequestId;
  61553. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  61554. // We can continue fetching when progressive loading is enabled,
  61555. // and we don't need the autoFetch feature.
  61556. this._isStreamingSupported = true;
  61557. } else if (this._isRangeSupported) {
  61558. // NOTE: by cancelling the full request, and then issuing range
  61559. // requests, there will be an issue for sites where you can only
  61560. // request the pdf once. However, if this is the case, then the
  61561. // server should not be returning that it can support range
  61562. // requests.
  61563. networkManager.abortRequest(fullRequestXhrId);
  61564. }
  61565. this._headersReceivedCapability.resolve();
  61566. },
  61567. _onProgressiveData: function PDFNetworkStreamFullRequestReader_onProgressiveData(chunk) {
  61568. if (this._requests.length > 0) {
  61569. var requestCapability = this._requests.shift();
  61570. requestCapability.resolve({
  61571. value: chunk,
  61572. done: false
  61573. });
  61574. } else {
  61575. this._cachedChunks.push(chunk);
  61576. }
  61577. },
  61578. _onDone: function PDFNetworkStreamFullRequestReader_onDone(args) {
  61579. if (args) {
  61580. this._onProgressiveData(args.chunk);
  61581. }
  61582. this._done = true;
  61583. if (this._cachedChunks.length > 0) {
  61584. return;
  61585. }
  61586. this._requests.forEach(function (requestCapability) {
  61587. requestCapability.resolve({
  61588. value: undefined,
  61589. done: true
  61590. });
  61591. });
  61592. this._requests = [];
  61593. },
  61594. _onError: function PDFNetworkStreamFullRequestReader_onError(status) {
  61595. var url = this._url;
  61596. var exception;
  61597. if (status === 404 || status === 0 && /^file:/.test(url)) {
  61598. exception = new MissingPDFException('Missing PDF "' + url + '".');
  61599. } else {
  61600. exception = new UnexpectedResponseException('Unexpected server response (' + status + ') while retrieving PDF "' + url + '".', status);
  61601. }
  61602. this._storedError = exception;
  61603. this._headersReceivedCapability.reject(exception);
  61604. this._requests.forEach(function (requestCapability) {
  61605. requestCapability.reject(exception);
  61606. });
  61607. this._requests = [];
  61608. this._cachedChunks = [];
  61609. },
  61610. _onProgress: function PDFNetworkStreamFullRequestReader_onProgress(data) {
  61611. if (this.onProgress) {
  61612. this.onProgress({
  61613. loaded: data.loaded,
  61614. total: data.lengthComputable ? data.total : this._contentLength
  61615. });
  61616. }
  61617. },
  61618. get isRangeSupported() {
  61619. return this._isRangeSupported;
  61620. },
  61621. get isStreamingSupported() {
  61622. return this._isStreamingSupported;
  61623. },
  61624. get contentLength() {
  61625. return this._contentLength;
  61626. },
  61627. get headersReady() {
  61628. return this._headersReceivedCapability.promise;
  61629. },
  61630. read: function PDFNetworkStreamFullRequestReader_read() {
  61631. if (this._storedError) {
  61632. return Promise.reject(this._storedError);
  61633. }
  61634. if (this._cachedChunks.length > 0) {
  61635. var chunk = this._cachedChunks.shift();
  61636. return Promise.resolve(chunk);
  61637. }
  61638. if (this._done) {
  61639. return Promise.resolve({
  61640. value: undefined,
  61641. done: true
  61642. });
  61643. }
  61644. var requestCapability = createPromiseCapability();
  61645. this._requests.push(requestCapability);
  61646. return requestCapability.promise;
  61647. },
  61648. cancel: function PDFNetworkStreamFullRequestReader_cancel(reason) {
  61649. this._done = true;
  61650. this._headersReceivedCapability.reject(reason);
  61651. this._requests.forEach(function (requestCapability) {
  61652. requestCapability.resolve({
  61653. value: undefined,
  61654. done: true
  61655. });
  61656. });
  61657. this._requests = [];
  61658. if (this._manager.isPendingRequest(this._fullRequestId)) {
  61659. this._manager.abortRequest(this._fullRequestId);
  61660. }
  61661. this._fullRequestReader = null;
  61662. }
  61663. };
  61664. /** @implements {IPDFStreamRangeReader} */
  61665. function PDFNetworkStreamRangeRequestReader(manager, begin, end) {
  61666. this._manager = manager;
  61667. var args = {
  61668. onDone: this._onDone.bind(this),
  61669. onProgress: this._onProgress.bind(this)
  61670. };
  61671. this._requestId = manager.requestRange(begin, end, args);
  61672. this._requests = [];
  61673. this._queuedChunk = null;
  61674. this._done = false;
  61675. this.onProgress = null;
  61676. this.onClosed = null;
  61677. }
  61678. PDFNetworkStreamRangeRequestReader.prototype = {
  61679. _close: function PDFNetworkStreamRangeRequestReader_close() {
  61680. if (this.onClosed) {
  61681. this.onClosed(this);
  61682. }
  61683. },
  61684. _onDone: function PDFNetworkStreamRangeRequestReader_onDone(data) {
  61685. var chunk = data.chunk;
  61686. if (this._requests.length > 0) {
  61687. var requestCapability = this._requests.shift();
  61688. requestCapability.resolve({
  61689. value: chunk,
  61690. done: false
  61691. });
  61692. } else {
  61693. this._queuedChunk = chunk;
  61694. }
  61695. this._done = true;
  61696. this._requests.forEach(function (requestCapability) {
  61697. requestCapability.resolve({
  61698. value: undefined,
  61699. done: true
  61700. });
  61701. });
  61702. this._requests = [];
  61703. this._close();
  61704. },
  61705. _onProgress: function PDFNetworkStreamRangeRequestReader_onProgress(evt) {
  61706. if (!this.isStreamingSupported && this.onProgress) {
  61707. this.onProgress({ loaded: evt.loaded });
  61708. }
  61709. },
  61710. get isStreamingSupported() {
  61711. return false;
  61712. },
  61713. // TODO allow progressive range bytes loading
  61714. read: function PDFNetworkStreamRangeRequestReader_read() {
  61715. if (this._queuedChunk !== null) {
  61716. var chunk = this._queuedChunk;
  61717. this._queuedChunk = null;
  61718. return Promise.resolve({
  61719. value: chunk,
  61720. done: false
  61721. });
  61722. }
  61723. if (this._done) {
  61724. return Promise.resolve({
  61725. value: undefined,
  61726. done: true
  61727. });
  61728. }
  61729. var requestCapability = createPromiseCapability();
  61730. this._requests.push(requestCapability);
  61731. return requestCapability.promise;
  61732. },
  61733. cancel: function PDFNetworkStreamRangeRequestReader_cancel(reason) {
  61734. this._done = true;
  61735. this._requests.forEach(function (requestCapability) {
  61736. requestCapability.resolve({
  61737. value: undefined,
  61738. done: true
  61739. });
  61740. });
  61741. this._requests = [];
  61742. if (this._manager.isPendingRequest(this._requestId)) {
  61743. this._manager.abortRequest(this._requestId);
  61744. }
  61745. this._close();
  61746. }
  61747. };
  61748. coreWorker.setPDFNetworkStreamClass(PDFNetworkStream);
  61749. exports.PDFNetworkStream = PDFNetworkStream;
  61750. exports.NetworkManager = NetworkManager;
  61751. }));
  61752. }.call(pdfjsLibs));
  61753. exports.PDFJS = pdfjsLibs.pdfjsDisplayGlobal.PDFJS;
  61754. exports.build = pdfjsLibs.pdfjsDisplayAPI.build;
  61755. exports.version = pdfjsLibs.pdfjsDisplayAPI.version;
  61756. exports.getDocument = pdfjsLibs.pdfjsDisplayAPI.getDocument;
  61757. exports.PDFDataRangeTransport = pdfjsLibs.pdfjsDisplayAPI.PDFDataRangeTransport;
  61758. exports.PDFWorker = pdfjsLibs.pdfjsDisplayAPI.PDFWorker;
  61759. exports.renderTextLayer = pdfjsLibs.pdfjsDisplayTextLayer.renderTextLayer;
  61760. exports.AnnotationLayer = pdfjsLibs.pdfjsDisplayAnnotationLayer.AnnotationLayer;
  61761. exports.CustomStyle = pdfjsLibs.pdfjsDisplayDOMUtils.CustomStyle;
  61762. exports.PasswordResponses = pdfjsLibs.pdfjsSharedUtil.PasswordResponses;
  61763. exports.InvalidPDFException = pdfjsLibs.pdfjsSharedUtil.InvalidPDFException;
  61764. exports.MissingPDFException = pdfjsLibs.pdfjsSharedUtil.MissingPDFException;
  61765. exports.SVGGraphics = pdfjsLibs.pdfjsDisplaySVG.SVGGraphics;
  61766. exports.UnexpectedResponseException = pdfjsLibs.pdfjsSharedUtil.UnexpectedResponseException;
  61767. exports.OPS = pdfjsLibs.pdfjsSharedUtil.OPS;
  61768. exports.UNSUPPORTED_FEATURES = pdfjsLibs.pdfjsSharedUtil.UNSUPPORTED_FEATURES;
  61769. exports.isValidUrl = pdfjsLibs.pdfjsSharedUtil.isValidUrl;
  61770. exports.createObjectURL = pdfjsLibs.pdfjsSharedUtil.createObjectURL;
  61771. exports.removeNullCharacters = pdfjsLibs.pdfjsSharedUtil.removeNullCharacters;
  61772. exports.shadow = pdfjsLibs.pdfjsSharedUtil.shadow;
  61773. exports.createBlob = pdfjsLibs.pdfjsSharedUtil.createBlob;
  61774. exports.getFilenameFromUrl = pdfjsLibs.pdfjsDisplayDOMUtils.getFilenameFromUrl;
  61775. exports.addLinkAttributes = pdfjsLibs.pdfjsDisplayDOMUtils.addLinkAttributes;
  61776. }));