pdf.combined.js 2.0 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998489994900049001490024900349004490054900649007490084900949010490114901249013490144901549016490174901849019490204902149022490234902449025490264902749028490294903049031490324903349034490354903649037490384903949040490414904249043490444904549046490474904849049490504905149052490534905449055490564905749058490594906049061490624906349064490654906649067490684906949070490714907249073490744907549076490774907849079490804908149082490834908449085490864908749088490894909049091490924909349094490954909649097490984909949100491014910249103491044910549106491074910849109491104911149112491134911449115491164911749118491194912049121491224912349124491254912649127491284912949130491314913249133491344913549136491374913849139491404914149142491434914449145491464914749148491494915049151491524915349154491554915649157491584915949160491614916249163491644916549166491674916849169491704917149172491734917449175491764917749178491794918049181491824918349184491854918649187491884918949190491914919249193491944919549196491974919849199492004920149202492034920449205492064920749208492094921049211492124921349214492154921649217492184921949220492214922249223492244922549226492274922849229492304923149232492334923449235492364923749238492394924049241492424924349244492454924649247492484924949250492514925249253492544925549256492574925849259492604926149262492634926449265492664926749268492694927049271492724927349274492754927649277492784927949280492814928249283492844928549286492874928849289492904929149292492934929449295492964929749298492994930049301493024930349304493054930649307493084930949310493114931249313493144931549316493174931849319493204932149322493234932449325493264932749328493294933049331493324933349334493354933649337493384933949340493414934249343493444934549346493474934849349493504935149352493534935449355493564935749358493594936049361493624936349364493654936649367493684936949370493714937249373493744937549376493774937849379493804938149382493834938449385493864938749388493894939049391493924939349394493954939649397493984939949400494014940249403494044940549406494074940849409494104941149412494134941449415494164941749418494194942049421494224942349424494254942649427494284942949430494314943249433494344943549436494374943849439494404944149442494434944449445494464944749448494494945049451494524945349454494554945649457494584945949460494614946249463494644946549466494674946849469494704947149472494734947449475494764947749478494794948049481494824948349484494854948649487494884948949490494914949249493494944949549496494974949849499495004950149502495034950449505495064950749508495094951049511495124951349514495154951649517495184951949520495214952249523495244952549526495274952849529495304953149532495334953449535495364953749538495394954049541495424954349544495454954649547495484954949550495514955249553495544955549556495574955849559495604956149562495634956449565495664956749568495694957049571495724957349574495754957649577495784957949580495814958249583495844958549586495874958849589495904959149592495934959449595495964959749598495994960049601496024960349604496054960649607496084960949610496114961249613496144961549616496174961849619496204962149622496234962449625496264962749628496294963049631496324963349634496354963649637496384963949640496414964249643496444964549646496474964849649496504965149652496534965449655496564965749658496594966049661496624966349664496654966649667496684966949670496714967249673496744967549676496774967849679496804968149682496834968449685496864968749688496894969049691496924969349694496954969649697496984969949700497014970249703497044970549706497074970849709497104971149712497134971449715497164971749718497194972049721497224972349724497254972649727497284972949730497314973249733497344973549736497374973849739497404974149742497434974449745497464974749748497494975049751497524975349754497554975649757497584975949760497614976249763497644976549766497674976849769497704977149772497734977449775497764977749778497794978049781497824978349784497854978649787497884978949790497914979249793497944979549796497974979849799498004980149802498034980449805498064980749808498094981049811498124981349814498154981649817498184981949820498214982249823498244982549826498274982849829498304983149832498334983449835498364983749838498394984049841498424984349844498454984649847498484984949850498514985249853498544985549856498574985849859498604986149862498634986449865498664986749868498694987049871498724987349874498754987649877498784987949880498814988249883498844988549886498874988849889498904989149892498934989449895498964989749898498994990049901499024990349904499054990649907499084990949910499114991249913499144991549916499174991849919499204992149922499234992449925499264992749928499294993049931499324993349934499354993649937499384993949940499414994249943499444994549946499474994849949499504995149952499534995449955499564995749958499594996049961499624996349964499654996649967499684996949970499714997249973499744997549976499774997849979499804998149982499834998449985499864998749988499894999049991499924999349994499954999649997499984999950000500015000250003500045000550006500075000850009500105001150012500135001450015500165001750018500195002050021500225002350024500255002650027500285002950030500315003250033500345003550036500375003850039500405004150042500435004450045500465004750048500495005050051500525005350054500555005650057500585005950060500615006250063500645006550066500675006850069500705007150072500735007450075500765007750078500795008050081500825008350084500855008650087500885008950090500915009250093500945009550096500975009850099501005010150102501035010450105501065010750108501095011050111501125011350114501155011650117501185011950120501215012250123501245012550126501275012850129501305013150132501335013450135501365013750138501395014050141501425014350144501455014650147501485014950150501515015250153501545015550156501575015850159501605016150162501635016450165501665016750168501695017050171501725017350174501755017650177501785017950180501815018250183501845018550186501875018850189501905019150192501935019450195501965019750198501995020050201502025020350204502055020650207502085020950210502115021250213502145021550216502175021850219502205022150222502235022450225502265022750228502295023050231502325023350234502355023650237502385023950240502415024250243502445024550246502475024850249502505025150252502535025450255502565025750258502595026050261502625026350264502655026650267502685026950270502715027250273502745027550276502775027850279502805028150282502835028450285502865028750288502895029050291502925029350294502955029650297502985029950300503015030250303503045030550306503075030850309503105031150312503135031450315503165031750318503195032050321503225032350324503255032650327503285032950330503315033250333503345033550336503375033850339503405034150342503435034450345503465034750348503495035050351503525035350354503555035650357503585035950360503615036250363503645036550366503675036850369503705037150372503735037450375503765037750378503795038050381503825038350384503855038650387503885038950390503915039250393503945039550396503975039850399504005040150402504035040450405504065040750408504095041050411504125041350414504155041650417504185041950420504215042250423504245042550426504275042850429504305043150432504335043450435504365043750438504395044050441504425044350444504455044650447504485044950450504515045250453504545045550456504575045850459504605046150462504635046450465504665046750468504695047050471504725047350474504755047650477504785047950480504815048250483504845048550486504875048850489504905049150492504935049450495504965049750498504995050050501505025050350504505055050650507505085050950510505115051250513505145051550516505175051850519505205052150522505235052450525505265052750528505295053050531505325053350534505355053650537505385053950540505415054250543505445054550546505475054850549505505055150552505535055450555505565055750558505595056050561505625056350564505655056650567505685056950570505715057250573505745057550576505775057850579505805058150582505835058450585505865058750588505895059050591505925059350594505955059650597505985059950600506015060250603506045060550606506075060850609506105061150612506135061450615506165061750618506195062050621506225062350624506255062650627506285062950630506315063250633506345063550636506375063850639506405064150642506435064450645506465064750648506495065050651506525065350654506555065650657506585065950660506615066250663506645066550666506675066850669506705067150672506735067450675506765067750678506795068050681506825068350684506855068650687506885068950690506915069250693506945069550696506975069850699507005070150702507035070450705507065070750708507095071050711507125071350714507155071650717507185071950720507215072250723507245072550726507275072850729507305073150732507335073450735507365073750738507395074050741507425074350744507455074650747507485074950750507515075250753507545075550756507575075850759507605076150762507635076450765507665076750768507695077050771507725077350774507755077650777507785077950780507815078250783507845078550786507875078850789507905079150792507935079450795507965079750798507995080050801508025080350804508055080650807508085080950810508115081250813508145081550816508175081850819508205082150822508235082450825508265082750828508295083050831508325083350834508355083650837508385083950840508415084250843508445084550846508475084850849508505085150852508535085450855508565085750858508595086050861508625086350864508655086650867508685086950870508715087250873508745087550876508775087850879508805088150882508835088450885508865088750888508895089050891508925089350894508955089650897508985089950900509015090250903509045090550906509075090850909509105091150912509135091450915509165091750918509195092050921509225092350924509255092650927509285092950930509315093250933509345093550936509375093850939509405094150942509435094450945509465094750948509495095050951509525095350954509555095650957509585095950960509615096250963509645096550966509675096850969509705097150972509735097450975509765097750978509795098050981509825098350984509855098650987509885098950990509915099250993509945099550996509975099850999510005100151002510035100451005510065100751008510095101051011510125101351014510155101651017510185101951020510215102251023510245102551026510275102851029510305103151032510335103451035510365103751038510395104051041510425104351044510455104651047510485104951050510515105251053510545105551056510575105851059510605106151062510635106451065510665106751068510695107051071510725107351074510755107651077510785107951080510815108251083510845108551086510875108851089510905109151092510935109451095510965109751098510995110051101511025110351104511055110651107511085110951110511115111251113511145111551116511175111851119511205112151122511235112451125511265112751128511295113051131511325113351134511355113651137511385113951140511415114251143511445114551146511475114851149511505115151152511535115451155511565115751158511595116051161511625116351164511655116651167511685116951170511715117251173511745117551176511775117851179511805118151182511835118451185511865118751188511895119051191511925119351194511955119651197511985119951200512015120251203512045120551206512075120851209512105121151212512135121451215512165121751218512195122051221512225122351224512255122651227512285122951230512315123251233512345123551236512375123851239512405124151242512435124451245512465124751248512495125051251512525125351254512555125651257512585125951260512615126251263512645126551266512675126851269512705127151272512735127451275512765127751278512795128051281512825128351284512855128651287512885128951290512915129251293512945129551296512975129851299513005130151302513035130451305513065130751308513095131051311513125131351314513155131651317513185131951320513215132251323513245132551326513275132851329513305133151332513335133451335513365133751338513395134051341513425134351344513455134651347513485134951350513515135251353513545135551356513575135851359513605136151362513635136451365513665136751368513695137051371513725137351374513755137651377513785137951380513815138251383513845138551386513875138851389513905139151392513935139451395513965139751398513995140051401514025140351404514055140651407514085140951410514115141251413514145141551416514175141851419514205142151422514235142451425514265142751428514295143051431514325143351434514355143651437514385143951440514415144251443514445144551446514475144851449514505145151452514535145451455514565145751458514595146051461514625146351464514655146651467514685146951470514715147251473514745147551476514775147851479514805148151482514835148451485514865148751488514895149051491514925149351494514955149651497514985149951500515015150251503515045150551506515075150851509515105151151512515135151451515515165151751518515195152051521515225152351524515255152651527515285152951530515315153251533515345153551536515375153851539515405154151542515435154451545515465154751548515495155051551515525155351554515555155651557515585155951560515615156251563515645156551566515675156851569515705157151572515735157451575515765157751578515795158051581515825158351584515855158651587515885158951590515915159251593515945159551596515975159851599516005160151602516035160451605516065160751608516095161051611516125161351614516155161651617516185161951620516215162251623516245162551626516275162851629516305163151632516335163451635516365163751638516395164051641516425164351644516455164651647516485164951650516515165251653516545165551656516575165851659516605166151662516635166451665516665166751668516695167051671516725167351674516755167651677516785167951680516815168251683516845168551686516875168851689516905169151692516935169451695516965169751698516995170051701517025170351704517055170651707517085170951710517115171251713517145171551716517175171851719517205172151722517235172451725517265172751728517295173051731517325173351734517355173651737517385173951740517415174251743517445174551746517475174851749517505175151752517535175451755517565175751758517595176051761517625176351764517655176651767517685176951770517715177251773517745177551776517775177851779517805178151782517835178451785517865178751788517895179051791517925179351794517955179651797517985179951800518015180251803518045180551806518075180851809518105181151812518135181451815518165181751818518195182051821518225182351824518255182651827518285182951830518315183251833518345183551836518375183851839518405184151842518435184451845518465184751848518495185051851518525185351854518555185651857518585185951860518615186251863518645186551866518675186851869518705187151872518735187451875518765187751878518795188051881518825188351884518855188651887518885188951890518915189251893518945189551896518975189851899519005190151902519035190451905519065190751908519095191051911519125191351914519155191651917519185191951920519215192251923519245192551926519275192851929519305193151932519335193451935519365193751938519395194051941519425194351944519455194651947519485194951950519515195251953519545195551956519575195851959519605196151962519635196451965519665196751968519695197051971519725197351974519755197651977519785197951980519815198251983519845198551986519875198851989519905199151992519935199451995519965199751998519995200052001520025200352004520055200652007520085200952010520115201252013520145201552016520175201852019520205202152022520235202452025520265202752028520295203052031520325203352034520355203652037520385203952040520415204252043520445204552046520475204852049520505205152052520535205452055520565205752058520595206052061520625206352064520655206652067520685206952070520715207252073520745207552076520775207852079520805208152082520835208452085520865208752088520895209052091520925209352094520955209652097520985209952100521015210252103521045210552106521075210852109521105211152112521135211452115521165211752118521195212052121521225212352124521255212652127521285212952130521315213252133521345213552136521375213852139521405214152142521435214452145521465214752148521495215052151521525215352154521555215652157521585215952160521615216252163521645216552166521675216852169521705217152172521735217452175521765217752178521795218052181521825218352184521855218652187521885218952190521915219252193521945219552196521975219852199522005220152202522035220452205522065220752208522095221052211522125221352214522155221652217522185221952220522215222252223522245222552226522275222852229522305223152232522335223452235522365223752238522395224052241522425224352244522455224652247522485224952250522515225252253522545225552256522575225852259522605226152262522635226452265522665226752268522695227052271522725227352274522755227652277522785227952280522815228252283522845228552286522875228852289522905229152292522935229452295522965229752298522995230052301523025230352304523055230652307523085230952310523115231252313523145231552316523175231852319523205232152322523235232452325523265232752328523295233052331523325233352334523355233652337523385233952340523415234252343523445234552346523475234852349523505235152352523535235452355523565235752358523595236052361523625236352364523655236652367523685236952370523715237252373523745237552376523775237852379523805238152382523835238452385523865238752388523895239052391523925239352394523955239652397523985239952400524015240252403524045240552406524075240852409524105241152412524135241452415524165241752418524195242052421524225242352424524255242652427524285242952430524315243252433524345243552436524375243852439524405244152442524435244452445524465244752448524495245052451524525245352454524555245652457524585245952460524615246252463524645246552466524675246852469524705247152472524735247452475524765247752478524795248052481524825248352484524855248652487524885248952490524915249252493524945249552496524975249852499525005250152502525035250452505525065250752508525095251052511525125251352514525155251652517525185251952520525215252252523525245252552526525275252852529525305253152532525335253452535525365253752538525395254052541525425254352544525455254652547525485254952550525515255252553525545255552556525575255852559525605256152562525635256452565525665256752568525695257052571525725257352574525755257652577525785257952580525815258252583525845258552586525875258852589525905259152592525935259452595525965259752598525995260052601526025260352604526055260652607526085260952610526115261252613526145261552616526175261852619526205262152622526235262452625526265262752628526295263052631526325263352634526355263652637526385263952640526415264252643526445264552646526475264852649526505265152652526535265452655526565265752658526595266052661526625266352664526655266652667526685266952670526715267252673526745267552676526775267852679526805268152682526835268452685526865268752688526895269052691526925269352694526955269652697526985269952700527015270252703527045270552706527075270852709527105271152712527135271452715527165271752718527195272052721527225272352724527255272652727527285272952730527315273252733527345273552736527375273852739527405274152742527435274452745527465274752748527495275052751527525275352754527555275652757527585275952760527615276252763527645276552766527675276852769527705277152772527735277452775527765277752778527795278052781527825278352784527855278652787527885278952790527915279252793527945279552796527975279852799528005280152802528035280452805528065280752808528095281052811528125281352814528155281652817528185281952820528215282252823528245282552826528275282852829528305283152832528335283452835528365283752838528395284052841528425284352844528455284652847528485284952850528515285252853528545285552856528575285852859528605286152862528635286452865528665286752868528695287052871528725287352874528755287652877528785287952880528815288252883528845288552886528875288852889528905289152892528935289452895528965289752898528995290052901529025290352904529055290652907529085290952910529115291252913529145291552916529175291852919529205292152922529235292452925529265292752928529295293052931529325293352934529355293652937529385293952940529415294252943529445294552946529475294852949529505295152952529535295452955529565295752958529595296052961529625296352964529655296652967529685296952970529715297252973529745297552976529775297852979529805298152982529835298452985529865298752988529895299052991529925299352994529955299652997529985299953000530015300253003530045300553006530075300853009530105301153012530135301453015530165301753018530195302053021530225302353024530255302653027530285302953030530315303253033530345303553036530375303853039530405304153042530435304453045530465304753048530495305053051530525305353054530555305653057530585305953060530615306253063530645306553066530675306853069530705307153072530735307453075530765307753078530795308053081530825308353084530855308653087530885308953090530915309253093530945309553096530975309853099531005310153102531035310453105531065310753108531095311053111531125311353114531155311653117531185311953120531215312253123531245312553126531275312853129531305313153132531335313453135531365313753138531395314053141531425314353144531455314653147531485314953150531515315253153531545315553156531575315853159531605316153162531635316453165531665316753168531695317053171531725317353174531755317653177531785317953180531815318253183531845318553186531875318853189531905319153192531935319453195531965319753198531995320053201532025320353204532055320653207532085320953210532115321253213532145321553216532175321853219532205322153222532235322453225532265322753228532295323053231532325323353234532355323653237532385323953240532415324253243532445324553246532475324853249532505325153252532535325453255532565325753258532595326053261532625326353264532655326653267532685326953270532715327253273532745327553276532775327853279532805328153282532835328453285532865328753288532895329053291532925329353294532955329653297532985329953300533015330253303533045330553306533075330853309533105331153312533135331453315533165331753318533195332053321533225332353324533255332653327533285332953330533315333253333533345333553336533375333853339533405334153342533435334453345533465334753348533495335053351533525335353354533555335653357533585335953360533615336253363533645336553366533675336853369533705337153372533735337453375533765337753378533795338053381533825338353384533855338653387533885338953390533915339253393533945339553396533975339853399534005340153402534035340453405534065340753408534095341053411534125341353414534155341653417534185341953420534215342253423534245342553426534275342853429534305343153432534335343453435534365343753438534395344053441534425344353444534455344653447534485344953450534515345253453534545345553456534575345853459534605346153462534635346453465534665346753468534695347053471534725347353474534755347653477534785347953480534815348253483534845348553486534875348853489534905349153492534935349453495534965349753498534995350053501535025350353504535055350653507535085350953510535115351253513535145351553516535175351853519535205352153522535235352453525535265352753528535295353053531535325353353534535355353653537535385353953540535415354253543535445354553546535475354853549535505355153552535535355453555535565355753558535595356053561535625356353564535655356653567535685356953570535715357253573535745357553576535775357853579535805358153582535835358453585535865358753588535895359053591535925359353594535955359653597535985359953600536015360253603536045360553606536075360853609536105361153612536135361453615536165361753618536195362053621536225362353624536255362653627536285362953630536315363253633536345363553636536375363853639536405364153642536435364453645536465364753648536495365053651536525365353654536555365653657536585365953660536615366253663536645366553666536675366853669536705367153672536735367453675536765367753678536795368053681536825368353684536855368653687536885368953690536915369253693536945369553696536975369853699537005370153702537035370453705537065370753708537095371053711537125371353714537155371653717537185371953720537215372253723537245372553726537275372853729537305373153732537335373453735537365373753738537395374053741537425374353744537455374653747537485374953750537515375253753537545375553756537575375853759537605376153762537635376453765537665376753768537695377053771537725377353774537755377653777537785377953780537815378253783537845378553786537875378853789537905379153792537935379453795537965379753798537995380053801538025380353804538055380653807538085380953810538115381253813538145381553816538175381853819538205382153822538235382453825538265382753828538295383053831538325383353834538355383653837538385383953840538415384253843538445384553846538475384853849538505385153852538535385453855538565385753858538595386053861538625386353864538655386653867538685386953870538715387253873538745387553876538775387853879538805388153882538835388453885538865388753888538895389053891538925389353894538955389653897538985389953900539015390253903539045390553906539075390853909539105391153912539135391453915539165391753918539195392053921539225392353924539255392653927539285392953930539315393253933539345393553936539375393853939539405394153942539435394453945539465394753948539495395053951539525395353954539555395653957539585395953960539615396253963539645396553966539675396853969539705397153972539735397453975539765397753978539795398053981539825398353984539855398653987539885398953990539915399253993539945399553996539975399853999540005400154002540035400454005540065400754008540095401054011540125401354014540155401654017540185401954020540215402254023540245402554026540275402854029540305403154032540335403454035540365403754038540395404054041540425404354044540455404654047540485404954050540515405254053540545405554056540575405854059540605406154062540635406454065540665406754068540695407054071540725407354074540755407654077540785407954080540815408254083540845408554086540875408854089540905409154092540935409454095540965409754098540995410054101541025410354104541055410654107541085410954110541115411254113541145411554116541175411854119541205412154122541235412454125541265412754128541295413054131541325413354134541355413654137541385413954140541415414254143541445414554146541475414854149541505415154152541535415454155541565415754158541595416054161541625416354164541655416654167541685416954170541715417254173541745417554176541775417854179541805418154182541835418454185541865418754188541895419054191541925419354194541955419654197541985419954200542015420254203542045420554206542075420854209542105421154212542135421454215542165421754218542195422054221542225422354224542255422654227542285422954230542315423254233542345423554236542375423854239542405424154242542435424454245542465424754248542495425054251542525425354254542555425654257542585425954260542615426254263542645426554266542675426854269542705427154272542735427454275542765427754278542795428054281542825428354284542855428654287542885428954290542915429254293542945429554296542975429854299543005430154302543035430454305543065430754308543095431054311543125431354314543155431654317543185431954320543215432254323543245432554326543275432854329543305433154332543335433454335543365433754338543395434054341543425434354344543455434654347543485434954350543515435254353543545435554356543575435854359543605436154362543635436454365543665436754368543695437054371543725437354374543755437654377543785437954380543815438254383543845438554386543875438854389543905439154392543935439454395543965439754398543995440054401544025440354404544055440654407544085440954410544115441254413544145441554416544175441854419544205442154422544235442454425544265442754428544295443054431544325443354434544355443654437544385443954440544415444254443544445444554446544475444854449544505445154452544535445454455544565445754458544595446054461544625446354464544655446654467544685446954470544715447254473544745447554476544775447854479544805448154482544835448454485544865448754488544895449054491544925449354494544955449654497544985449954500545015450254503545045450554506545075450854509545105451154512545135451454515545165451754518545195452054521545225452354524545255452654527545285452954530545315453254533545345453554536545375453854539545405454154542545435454454545545465454754548545495455054551545525455354554545555455654557545585455954560545615456254563545645456554566545675456854569545705457154572545735457454575545765457754578545795458054581545825458354584545855458654587545885458954590545915459254593545945459554596545975459854599546005460154602546035460454605546065460754608546095461054611546125461354614546155461654617546185461954620546215462254623546245462554626546275462854629546305463154632546335463454635546365463754638546395464054641546425464354644546455464654647546485464954650546515465254653546545465554656546575465854659546605466154662546635466454665546665466754668546695467054671546725467354674546755467654677546785467954680546815468254683546845468554686546875468854689546905469154692546935469454695546965469754698546995470054701547025470354704547055470654707547085470954710547115471254713547145471554716547175471854719547205472154722547235472454725547265472754728547295473054731547325473354734547355473654737547385473954740547415474254743547445474554746547475474854749547505475154752547535475454755547565475754758547595476054761547625476354764547655476654767547685476954770547715477254773547745477554776547775477854779547805478154782547835478454785547865478754788547895479054791547925479354794547955479654797547985479954800548015480254803548045480554806548075480854809548105481154812548135481454815548165481754818548195482054821548225482354824548255482654827548285482954830548315483254833548345483554836548375483854839548405484154842548435484454845548465484754848548495485054851548525485354854548555485654857548585485954860548615486254863548645486554866548675486854869548705487154872548735487454875548765487754878548795488054881548825488354884548855488654887548885488954890548915489254893548945489554896548975489854899549005490154902549035490454905549065490754908549095491054911549125491354914549155491654917549185491954920549215492254923549245492554926549275492854929549305493154932549335493454935549365493754938549395494054941549425494354944549455494654947549485494954950549515495254953549545495554956549575495854959549605496154962549635496454965549665496754968549695497054971549725497354974549755497654977549785497954980549815498254983549845498554986549875498854989549905499154992549935499454995549965499754998549995500055001550025500355004550055500655007550085500955010550115501255013550145501555016550175501855019550205502155022550235502455025550265502755028550295503055031550325503355034550355503655037550385503955040550415504255043550445504555046550475504855049550505505155052550535505455055550565505755058550595506055061550625506355064550655506655067550685506955070550715507255073550745507555076550775507855079550805508155082550835508455085550865508755088550895509055091550925509355094550955509655097550985509955100551015510255103551045510555106551075510855109551105511155112551135511455115551165511755118551195512055121551225512355124551255512655127551285512955130551315513255133551345513555136551375513855139551405514155142551435514455145551465514755148551495515055151551525515355154551555515655157551585515955160551615516255163551645516555166551675516855169551705517155172551735517455175551765517755178551795518055181551825518355184551855518655187551885518955190551915519255193551945519555196551975519855199552005520155202552035520455205552065520755208552095521055211552125521355214552155521655217552185521955220552215522255223552245522555226552275522855229552305523155232552335523455235552365523755238552395524055241552425524355244552455524655247552485524955250552515525255253552545525555256552575525855259552605526155262552635526455265552665526755268552695527055271552725527355274552755527655277552785527955280552815528255283552845528555286552875528855289552905529155292552935529455295552965529755298552995530055301553025530355304553055530655307553085530955310553115531255313553145531555316553175531855319553205532155322553235532455325553265532755328553295533055331553325533355334553355533655337553385533955340553415534255343553445534555346553475534855349553505535155352553535535455355553565535755358553595536055361553625536355364553655536655367553685536955370553715537255373553745537555376553775537855379553805538155382553835538455385553865538755388553895539055391553925539355394553955539655397553985539955400554015540255403554045540555406554075540855409554105541155412554135541455415554165541755418554195542055421554225542355424554255542655427554285542955430554315543255433554345543555436554375543855439554405544155442554435544455445554465544755448554495545055451554525545355454554555545655457554585545955460554615546255463554645546555466554675546855469554705547155472554735547455475554765547755478554795548055481554825548355484554855548655487554885548955490554915549255493554945549555496554975549855499555005550155502555035550455505555065550755508555095551055511555125551355514555155551655517555185551955520555215552255523555245552555526555275552855529555305553155532555335553455535555365553755538555395554055541555425554355544555455554655547555485554955550555515555255553555545555555556555575555855559555605556155562555635556455565555665556755568555695557055571555725557355574555755557655577555785557955580555815558255583555845558555586555875558855589555905559155592555935559455595555965559755598555995560055601556025560355604556055560655607556085560955610556115561255613556145561555616556175561855619556205562155622556235562455625556265562755628556295563055631556325563355634556355563655637556385563955640556415564255643556445564555646556475564855649556505565155652556535565455655556565565755658556595566055661556625566355664556655566655667556685566955670556715567255673556745567555676556775567855679556805568155682556835568455685556865568755688556895569055691556925569355694556955569655697556985569955700557015570255703557045570555706557075570855709557105571155712557135571455715557165571755718557195572055721557225572355724557255572655727557285572955730557315573255733557345573555736557375573855739557405574155742557435574455745557465574755748557495575055751557525575355754557555575655757557585575955760557615576255763557645576555766557675576855769557705577155772557735577455775557765577755778557795578055781557825578355784557855578655787557885578955790557915579255793557945579555796557975579855799558005580155802558035580455805558065580755808558095581055811558125581355814558155581655817558185581955820558215582255823558245582555826558275582855829558305583155832558335583455835558365583755838558395584055841558425584355844558455584655847558485584955850558515585255853558545585555856558575585855859558605586155862558635586455865558665586755868558695587055871558725587355874558755587655877558785587955880558815588255883558845588555886558875588855889558905589155892558935589455895558965589755898558995590055901559025590355904559055590655907559085590955910559115591255913559145591555916559175591855919559205592155922559235592455925559265592755928559295593055931559325593355934559355593655937559385593955940559415594255943559445594555946559475594855949559505595155952559535595455955559565595755958559595596055961559625596355964559655596655967559685596955970559715597255973559745597555976559775597855979559805598155982559835598455985559865598755988559895599055991559925599355994559955599655997559985599956000560015600256003560045600556006560075600856009560105601156012560135601456015560165601756018560195602056021560225602356024560255602656027560285602956030560315603256033560345603556036560375603856039560405604156042560435604456045560465604756048560495605056051560525605356054560555605656057560585605956060560615606256063560645606556066560675606856069560705607156072560735607456075560765607756078560795608056081560825608356084560855608656087560885608956090560915609256093560945609556096560975609856099561005610156102561035610456105561065610756108561095611056111561125611356114561155611656117561185611956120561215612256123561245612556126561275612856129561305613156132561335613456135561365613756138561395614056141561425614356144561455614656147561485614956150561515615256153561545615556156561575615856159561605616156162561635616456165561665616756168561695617056171561725617356174561755617656177561785617956180561815618256183561845618556186561875618856189561905619156192561935619456195561965619756198561995620056201562025620356204562055620656207562085620956210562115621256213562145621556216562175621856219562205622156222562235622456225562265622756228562295623056231562325623356234562355623656237562385623956240562415624256243562445624556246562475624856249562505625156252562535625456255562565625756258562595626056261562625626356264562655626656267562685626956270562715627256273562745627556276562775627856279562805628156282562835628456285562865628756288562895629056291562925629356294562955629656297562985629956300563015630256303563045630556306563075630856309563105631156312563135631456315563165631756318563195632056321563225632356324563255632656327563285632956330563315633256333563345633556336563375633856339563405634156342563435634456345563465634756348563495635056351563525635356354563555635656357563585635956360563615636256363563645636556366563675636856369563705637156372563735637456375563765637756378563795638056381563825638356384563855638656387563885638956390563915639256393563945639556396563975639856399564005640156402564035640456405564065640756408564095641056411564125641356414564155641656417564185641956420564215642256423564245642556426564275642856429564305643156432564335643456435564365643756438564395644056441564425644356444564455644656447564485644956450564515645256453564545645556456564575645856459564605646156462564635646456465564665646756468564695647056471564725647356474564755647656477564785647956480564815648256483564845648556486564875648856489564905649156492564935649456495564965649756498564995650056501565025650356504565055650656507565085650956510565115651256513565145651556516565175651856519565205652156522565235652456525565265652756528565295653056531565325653356534565355653656537565385653956540565415654256543565445654556546565475654856549565505655156552565535655456555565565655756558565595656056561565625656356564565655656656567565685656956570565715657256573565745657556576565775657856579565805658156582565835658456585565865658756588565895659056591565925659356594565955659656597565985659956600566015660256603566045660556606566075660856609566105661156612566135661456615566165661756618566195662056621566225662356624566255662656627566285662956630566315663256633566345663556636566375663856639566405664156642566435664456645566465664756648566495665056651566525665356654566555665656657566585665956660566615666256663566645666556666566675666856669566705667156672566735667456675566765667756678566795668056681566825668356684566855668656687566885668956690566915669256693566945669556696566975669856699567005670156702567035670456705567065670756708567095671056711567125671356714567155671656717567185671956720567215672256723567245672556726567275672856729567305673156732567335673456735567365673756738567395674056741567425674356744567455674656747567485674956750567515675256753567545675556756567575675856759567605676156762567635676456765567665676756768567695677056771567725677356774567755677656777567785677956780567815678256783567845678556786567875678856789567905679156792567935679456795567965679756798567995680056801568025680356804568055680656807568085680956810568115681256813568145681556816568175681856819568205682156822568235682456825568265682756828568295683056831568325683356834568355683656837568385683956840568415684256843568445684556846568475684856849568505685156852568535685456855568565685756858568595686056861568625686356864568655686656867568685686956870568715687256873568745687556876568775687856879568805688156882568835688456885568865688756888568895689056891568925689356894568955689656897568985689956900569015690256903569045690556906569075690856909569105691156912569135691456915569165691756918569195692056921569225692356924569255692656927569285692956930569315693256933569345693556936569375693856939569405694156942569435694456945569465694756948569495695056951569525695356954569555695656957569585695956960569615696256963569645696556966569675696856969569705697156972569735697456975569765697756978569795698056981569825698356984569855698656987569885698956990569915699256993569945699556996569975699856999570005700157002570035700457005570065700757008570095701057011570125701357014570155701657017570185701957020570215702257023570245702557026570275702857029570305703157032570335703457035570365703757038570395704057041570425704357044570455704657047570485704957050570515705257053570545705557056570575705857059570605706157062570635706457065570665706757068570695707057071570725707357074570755707657077570785707957080570815708257083570845708557086570875708857089570905709157092570935709457095570965709757098570995710057101571025710357104571055710657107571085710957110571115711257113571145711557116571175711857119571205712157122571235712457125571265712757128571295713057131571325713357134571355713657137571385713957140571415714257143571445714557146571475714857149571505715157152571535715457155571565715757158571595716057161571625716357164571655716657167571685716957170571715717257173571745717557176571775717857179571805718157182571835718457185571865718757188571895719057191571925719357194571955719657197571985719957200572015720257203572045720557206572075720857209572105721157212572135721457215572165721757218572195722057221572225722357224572255722657227572285722957230572315723257233572345723557236572375723857239572405724157242572435724457245572465724757248572495725057251572525725357254572555725657257572585725957260572615726257263572645726557266572675726857269572705727157272572735727457275572765727757278572795728057281572825728357284572855728657287572885728957290572915729257293572945729557296572975729857299573005730157302573035730457305573065730757308573095731057311573125731357314573155731657317573185731957320573215732257323573245732557326573275732857329573305733157332573335733457335573365733757338573395734057341573425734357344573455734657347573485734957350573515735257353573545735557356573575735857359573605736157362573635736457365573665736757368573695737057371573725737357374573755737657377573785737957380573815738257383573845738557386573875738857389573905739157392573935739457395573965739757398573995740057401574025740357404574055740657407574085740957410574115741257413574145741557416574175741857419574205742157422574235742457425574265742757428574295743057431574325743357434574355743657437574385743957440574415744257443574445744557446574475744857449574505745157452574535745457455574565745757458574595746057461574625746357464574655746657467574685746957470574715747257473574745747557476574775747857479574805748157482574835748457485574865748757488574895749057491574925749357494574955749657497574985749957500575015750257503575045750557506575075750857509575105751157512575135751457515575165751757518575195752057521575225752357524575255752657527575285752957530575315753257533575345753557536575375753857539575405754157542575435754457545575465754757548575495755057551575525755357554575555755657557575585755957560575615756257563575645756557566575675756857569575705757157572575735757457575575765757757578575795758057581575825758357584575855758657587575885758957590575915759257593575945759557596575975759857599576005760157602576035760457605576065760757608576095761057611576125761357614576155761657617576185761957620576215762257623576245762557626576275762857629576305763157632576335763457635576365763757638576395764057641576425764357644576455764657647576485764957650576515765257653576545765557656576575765857659576605766157662576635766457665576665766757668576695767057671576725767357674576755767657677576785767957680576815768257683576845768557686576875768857689576905769157692576935769457695576965769757698576995770057701577025770357704577055770657707577085770957710577115771257713577145771557716577175771857719577205772157722577235772457725577265772757728577295773057731577325773357734577355773657737577385773957740577415774257743577445774557746577475774857749577505775157752577535775457755577565775757758577595776057761577625776357764577655776657767577685776957770577715777257773577745777557776577775777857779577805778157782577835778457785577865778757788577895779057791577925779357794577955779657797577985779957800578015780257803578045780557806578075780857809578105781157812578135781457815578165781757818578195782057821578225782357824578255782657827578285782957830578315783257833578345783557836578375783857839578405784157842578435784457845578465784757848578495785057851578525785357854578555785657857578585785957860578615786257863578645786557866578675786857869578705787157872578735787457875578765787757878578795788057881578825788357884578855788657887578885788957890578915789257893578945789557896578975789857899579005790157902579035790457905579065790757908579095791057911579125791357914579155791657917579185791957920579215792257923579245792557926579275792857929579305793157932579335793457935579365793757938579395794057941579425794357944579455794657947579485794957950579515795257953579545795557956579575795857959579605796157962579635796457965579665796757968579695797057971579725797357974579755797657977579785797957980579815798257983579845798557986579875798857989579905799157992579935799457995579965799757998579995800058001580025800358004580055800658007580085800958010580115801258013580145801558016580175801858019580205802158022580235802458025580265802758028580295803058031580325803358034580355803658037580385803958040580415804258043580445804558046580475804858049580505805158052580535805458055580565805758058580595806058061580625806358064580655806658067580685806958070580715807258073580745807558076580775807858079580805808158082580835808458085580865808758088580895809058091580925809358094580955809658097580985809958100581015810258103581045810558106581075810858109581105811158112581135811458115581165811758118581195812058121581225812358124581255812658127581285812958130581315813258133581345813558136581375813858139581405814158142581435814458145581465814758148581495815058151581525815358154581555815658157581585815958160581615816258163581645816558166581675816858169581705817158172581735817458175581765817758178581795818058181581825818358184581855818658187581885818958190581915819258193581945819558196581975819858199582005820158202582035820458205582065820758208582095821058211582125821358214582155821658217582185821958220582215822258223582245822558226582275822858229582305823158232582335823458235582365823758238582395824058241582425824358244582455824658247582485824958250582515825258253582545825558256582575825858259582605826158262582635826458265582665826758268582695827058271582725827358274582755827658277582785827958280582815828258283582845828558286582875828858289582905829158292582935829458295582965829758298582995830058301583025830358304583055830658307583085830958310583115831258313583145831558316583175831858319583205832158322583235832458325583265832758328583295833058331583325833358334583355833658337583385833958340583415834258343583445834558346583475834858349583505835158352583535835458355583565835758358583595836058361583625836358364583655836658367583685836958370583715837258373583745837558376583775837858379583805838158382583835838458385583865838758388583895839058391583925839358394583955839658397583985839958400584015840258403584045840558406584075840858409584105841158412584135841458415584165841758418584195842058421584225842358424584255842658427584285842958430584315843258433584345843558436584375843858439584405844158442584435844458445584465844758448584495845058451584525845358454584555845658457584585845958460584615846258463584645846558466584675846858469584705847158472584735847458475584765847758478584795848058481584825848358484584855848658487584885848958490584915849258493584945849558496584975849858499585005850158502585035850458505585065850758508585095851058511585125851358514585155851658517585185851958520585215852258523585245852558526585275852858529585305853158532585335853458535585365853758538585395854058541585425854358544585455854658547585485854958550585515855258553585545855558556585575855858559585605856158562585635856458565585665856758568585695857058571585725857358574585755857658577585785857958580585815858258583585845858558586585875858858589585905859158592585935859458595585965859758598585995860058601586025860358604586055860658607586085860958610586115861258613586145861558616586175861858619586205862158622586235862458625586265862758628586295863058631586325863358634586355863658637586385863958640586415864258643586445864558646586475864858649586505865158652586535865458655586565865758658586595866058661586625866358664586655866658667586685866958670586715867258673586745867558676586775867858679586805868158682586835868458685586865868758688586895869058691586925869358694586955869658697586985869958700587015870258703587045870558706587075870858709587105871158712587135871458715587165871758718587195872058721587225872358724587255872658727587285872958730587315873258733587345873558736587375873858739587405874158742587435874458745587465874758748587495875058751587525875358754587555875658757587585875958760587615876258763587645876558766587675876858769587705877158772587735877458775587765877758778587795878058781587825878358784587855878658787587885878958790587915879258793587945879558796587975879858799588005880158802588035880458805588065880758808588095881058811588125881358814588155881658817588185881958820588215882258823588245882558826588275882858829588305883158832588335883458835588365883758838588395884058841588425884358844588455884658847588485884958850588515885258853588545885558856588575885858859588605886158862588635886458865588665886758868588695887058871588725887358874588755887658877588785887958880588815888258883588845888558886588875888858889588905889158892588935889458895588965889758898588995890058901589025890358904589055890658907589085890958910589115891258913589145891558916589175891858919589205892158922589235892458925589265892758928589295893058931589325893358934589355893658937589385893958940589415894258943589445894558946589475894858949589505895158952589535895458955589565895758958589595896058961589625896358964589655896658967589685896958970589715897258973589745897558976589775897858979589805898158982589835898458985589865898758988589895899058991589925899358994589955899658997589985899959000590015900259003590045900559006590075900859009590105901159012590135901459015590165901759018590195902059021590225902359024590255902659027590285902959030590315903259033590345903559036590375903859039590405904159042590435904459045590465904759048590495905059051590525905359054590555905659057590585905959060590615906259063590645906559066590675906859069590705907159072590735907459075590765907759078590795908059081590825908359084590855908659087590885908959090590915909259093590945909559096590975909859099591005910159102591035910459105591065910759108591095911059111591125911359114591155911659117591185911959120591215912259123591245912559126591275912859129591305913159132591335913459135591365913759138591395914059141591425914359144591455914659147591485914959150591515915259153591545915559156591575915859159591605916159162591635916459165591665916759168591695917059171591725917359174591755917659177591785917959180591815918259183591845918559186591875918859189591905919159192591935919459195591965919759198591995920059201592025920359204592055920659207592085920959210592115921259213592145921559216592175921859219592205922159222592235922459225592265922759228592295923059231592325923359234592355923659237592385923959240592415924259243592445924559246592475924859249592505925159252592535925459255592565925759258592595926059261592625926359264592655926659267592685926959270592715927259273592745927559276592775927859279592805928159282592835928459285592865928759288592895929059291592925929359294592955929659297592985929959300593015930259303593045930559306593075930859309593105931159312593135931459315593165931759318593195932059321593225932359324593255932659327593285932959330593315933259333593345933559336593375933859339593405934159342593435934459345593465934759348593495935059351593525935359354593555935659357593585935959360593615936259363593645936559366593675936859369593705937159372593735937459375593765937759378593795938059381593825938359384593855938659387593885938959390593915939259393593945939559396593975939859399594005940159402594035940459405594065940759408594095941059411594125941359414594155941659417594185941959420594215942259423594245942559426594275942859429594305943159432594335943459435594365943759438594395944059441594425944359444594455944659447594485944959450594515945259453594545945559456594575945859459594605946159462594635946459465594665946759468594695947059471594725947359474594755947659477594785947959480594815948259483594845948559486594875948859489594905949159492594935949459495594965949759498594995950059501595025950359504595055950659507595085950959510595115951259513595145951559516595175951859519595205952159522595235952459525595265952759528595295953059531595325953359534595355953659537595385953959540595415954259543595445954559546595475954859549595505955159552595535955459555595565955759558595595956059561595625956359564595655956659567595685956959570595715957259573595745957559576595775957859579595805958159582595835958459585595865958759588595895959059591595925959359594595955959659597595985959959600596015960259603596045960559606596075960859609596105961159612596135961459615596165961759618596195962059621596225962359624596255962659627596285962959630596315963259633596345963559636596375963859639596405964159642596435964459645596465964759648596495965059651596525965359654596555965659657596585965959660596615966259663596645966559666596675966859669596705967159672596735967459675596765967759678596795968059681596825968359684596855968659687596885968959690596915969259693596945969559696596975969859699597005970159702597035970459705597065970759708597095971059711597125971359714597155971659717597185971959720597215972259723597245972559726597275972859729597305973159732597335973459735597365973759738597395974059741597425974359744597455974659747597485974959750597515975259753597545975559756597575975859759597605976159762597635976459765597665976759768597695977059771597725977359774597755977659777597785977959780597815978259783597845978559786597875978859789597905979159792597935979459795597965979759798597995980059801598025980359804598055980659807598085980959810598115981259813598145981559816598175981859819598205982159822598235982459825598265982759828598295983059831598325983359834598355983659837598385983959840598415984259843598445984559846598475984859849598505985159852598535985459855598565985759858598595986059861598625986359864598655986659867598685986959870598715987259873598745987559876598775987859879598805988159882598835988459885598865988759888598895989059891598925989359894598955989659897598985989959900599015990259903599045990559906599075990859909599105991159912599135991459915599165991759918599195992059921599225992359924599255992659927599285992959930599315993259933599345993559936599375993859939599405994159942599435994459945599465994759948599495995059951599525995359954599555995659957599585995959960599615996259963599645996559966599675996859969599705997159972599735997459975599765997759978599795998059981599825998359984599855998659987599885998959990599915999259993599945999559996599975999859999600006000160002600036000460005600066000760008600096001060011600126001360014600156001660017600186001960020600216002260023600246002560026600276002860029600306003160032600336003460035600366003760038600396004060041600426004360044600456004660047600486004960050600516005260053600546005560056600576005860059600606006160062600636006460065600666006760068600696007060071600726007360074600756007660077600786007960080600816008260083600846008560086600876008860089600906009160092600936009460095600966009760098600996010060101601026010360104601056010660107601086010960110601116011260113601146011560116601176011860119601206012160122601236012460125601266012760128601296013060131601326013360134601356013660137601386013960140601416014260143601446014560146601476014860149601506015160152601536015460155601566015760158601596016060161601626016360164601656016660167601686016960170601716017260173601746017560176601776017860179601806018160182601836018460185601866018760188601896019060191601926019360194601956019660197601986019960200602016020260203602046020560206602076020860209602106021160212602136021460215602166021760218602196022060221602226022360224602256022660227602286022960230602316023260233602346023560236602376023860239602406024160242602436024460245602466024760248602496025060251602526025360254602556025660257602586025960260602616026260263602646026560266602676026860269602706027160272602736027460275602766027760278602796028060281602826028360284602856028660287602886028960290602916029260293602946029560296602976029860299603006030160302603036030460305603066030760308603096031060311603126031360314603156031660317603186031960320603216032260323603246032560326603276032860329603306033160332603336033460335603366033760338603396034060341603426034360344603456034660347603486034960350603516035260353603546035560356603576035860359603606036160362603636036460365603666036760368603696037060371603726037360374603756037660377603786037960380603816038260383603846038560386603876038860389603906039160392603936039460395603966039760398603996040060401604026040360404604056040660407604086040960410604116041260413604146041560416604176041860419604206042160422604236042460425604266042760428604296043060431604326043360434604356043660437604386043960440604416044260443604446044560446604476044860449604506045160452604536045460455604566045760458604596046060461604626046360464604656046660467604686046960470604716047260473604746047560476604776047860479604806048160482604836048460485604866048760488604896049060491604926049360494604956049660497604986049960500605016050260503605046050560506605076050860509605106051160512605136051460515605166051760518605196052060521605226052360524605256052660527605286052960530605316053260533605346053560536605376053860539605406054160542605436054460545605466054760548605496055060551605526055360554605556055660557605586055960560605616056260563605646056560566605676056860569605706057160572605736057460575605766057760578605796058060581605826058360584605856058660587605886058960590605916059260593605946059560596605976059860599606006060160602606036060460605606066060760608606096061060611606126061360614606156061660617606186061960620606216062260623606246062560626606276062860629606306063160632606336063460635606366063760638606396064060641606426064360644606456064660647606486064960650606516065260653606546065560656606576065860659606606066160662606636066460665606666066760668606696067060671606726067360674606756067660677606786067960680606816068260683606846068560686606876068860689606906069160692606936069460695606966069760698606996070060701607026070360704607056070660707607086070960710607116071260713607146071560716607176071860719607206072160722607236072460725607266072760728607296073060731607326073360734607356073660737607386073960740607416074260743607446074560746607476074860749607506075160752607536075460755607566075760758607596076060761607626076360764607656076660767607686076960770607716077260773607746077560776607776077860779607806078160782607836078460785607866078760788607896079060791607926079360794607956079660797607986079960800608016080260803608046080560806608076080860809608106081160812608136081460815608166081760818608196082060821608226082360824608256082660827608286082960830608316083260833608346083560836608376083860839608406084160842608436084460845608466084760848608496085060851608526085360854608556085660857608586085960860608616086260863608646086560866608676086860869608706087160872608736087460875608766087760878608796088060881608826088360884608856088660887608886088960890608916089260893608946089560896608976089860899609006090160902609036090460905609066090760908609096091060911609126091360914609156091660917609186091960920609216092260923609246092560926609276092860929609306093160932609336093460935609366093760938609396094060941609426094360944609456094660947609486094960950609516095260953609546095560956609576095860959609606096160962609636096460965609666096760968609696097060971609726097360974609756097660977609786097960980609816098260983609846098560986609876098860989609906099160992609936099460995609966099760998609996100061001610026100361004610056100661007610086100961010610116101261013610146101561016610176101861019610206102161022610236102461025610266102761028610296103061031610326103361034610356103661037610386103961040610416104261043610446104561046610476104861049610506105161052610536105461055610566105761058610596106061061610626106361064610656106661067610686106961070610716107261073610746107561076610776107861079610806108161082610836108461085610866108761088610896109061091610926109361094610956109661097610986109961100611016110261103611046110561106611076110861109611106111161112611136111461115611166111761118611196112061121611226112361124611256112661127611286112961130611316113261133611346113561136611376113861139611406114161142611436114461145611466114761148611496115061151611526115361154611556115661157611586115961160611616116261163611646116561166611676116861169611706117161172611736117461175611766117761178611796118061181611826118361184611856118661187611886118961190611916119261193611946119561196611976119861199612006120161202612036120461205612066120761208612096121061211612126121361214612156121661217612186121961220612216122261223612246122561226612276122861229612306123161232612336123461235612366123761238612396124061241612426124361244612456124661247612486124961250612516125261253612546125561256612576125861259612606126161262612636126461265612666126761268612696127061271612726127361274612756127661277612786127961280612816128261283612846128561286612876128861289612906129161292612936129461295612966129761298612996130061301613026130361304613056130661307613086130961310613116131261313613146131561316613176131861319613206132161322613236132461325613266132761328613296133061331613326133361334613356133661337613386133961340613416134261343613446134561346613476134861349613506135161352613536135461355613566135761358613596136061361613626136361364613656136661367613686136961370613716137261373613746137561376613776137861379613806138161382613836138461385613866138761388613896139061391613926139361394613956139661397613986139961400614016140261403614046140561406614076140861409614106141161412614136141461415614166141761418614196142061421614226142361424614256142661427614286142961430614316143261433614346143561436614376143861439614406144161442614436144461445614466144761448614496145061451614526145361454614556145661457614586145961460614616146261463614646146561466614676146861469614706147161472614736147461475614766147761478614796148061481614826148361484614856148661487614886148961490614916149261493614946149561496614976149861499615006150161502615036150461505615066150761508615096151061511615126151361514615156151661517615186151961520615216152261523615246152561526615276152861529615306153161532615336153461535615366153761538615396154061541615426154361544615456154661547615486154961550615516155261553615546155561556615576155861559615606156161562615636156461565615666156761568615696157061571615726157361574615756157661577615786157961580615816158261583615846158561586615876158861589615906159161592615936159461595615966159761598615996160061601616026160361604616056160661607616086160961610616116161261613616146161561616616176161861619616206162161622616236162461625616266162761628616296163061631616326163361634616356163661637616386163961640616416164261643616446164561646616476164861649616506165161652616536165461655616566165761658616596166061661616626166361664616656166661667616686166961670616716167261673616746167561676616776167861679616806168161682616836168461685616866168761688616896169061691616926169361694616956169661697616986169961700617016170261703617046170561706617076170861709617106171161712617136171461715617166171761718617196172061721617226172361724617256172661727617286172961730617316173261733617346173561736617376173861739617406174161742617436174461745617466174761748617496175061751617526175361754617556175661757617586175961760617616176261763617646176561766617676176861769617706177161772617736177461775617766177761778617796178061781617826178361784617856178661787617886178961790617916179261793617946179561796617976179861799618006180161802618036180461805618066180761808618096181061811618126181361814618156181661817618186181961820618216182261823618246182561826618276182861829618306183161832618336183461835618366183761838618396184061841618426184361844618456184661847618486184961850
  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.304';
  28. var pdfjsBuild = 'b4100ba';
  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. // Checks if URLs use one of the whitelisted protocols, e.g. to avoid XSS.
  3880. function isValidProtocol(url) {
  3881. if (!url) {
  3882. return false;
  3883. }
  3884. switch (url.protocol) {
  3885. case 'http:':
  3886. case 'https:':
  3887. case 'ftp:':
  3888. case 'mailto:':
  3889. case 'tel:':
  3890. return true;
  3891. default:
  3892. return false;
  3893. }
  3894. }
  3895. /**
  3896. * Attempts to create a valid absolute URL (utilizing `isValidProtocol`).
  3897. * @param {URL|string} url - An absolute, or relative, URL.
  3898. * @param {URL|string} baseUrl - An absolute URL.
  3899. * @returns Either a valid {URL}, or `null` otherwise.
  3900. */
  3901. function createValidAbsoluteUrl(url, baseUrl) {
  3902. if (!url) {
  3903. return null;
  3904. }
  3905. try {
  3906. var absoluteUrl = baseUrl ? new URL(url, baseUrl) : new URL(url);
  3907. if (isValidProtocol(absoluteUrl)) {
  3908. return absoluteUrl;
  3909. }
  3910. } catch (ex) {
  3911. }
  3912. return null;
  3913. }
  3914. function shadow(obj, prop, value) {
  3915. Object.defineProperty(obj, prop, {
  3916. value: value,
  3917. enumerable: true,
  3918. configurable: true,
  3919. writable: false
  3920. });
  3921. return value;
  3922. }
  3923. function getLookupTableFactory(initializer) {
  3924. var lookup;
  3925. return function () {
  3926. if (initializer) {
  3927. lookup = Object.create(null);
  3928. initializer(lookup);
  3929. initializer = null;
  3930. }
  3931. return lookup;
  3932. };
  3933. }
  3934. var PasswordResponses = {
  3935. NEED_PASSWORD: 1,
  3936. INCORRECT_PASSWORD: 2
  3937. };
  3938. var PasswordException = function PasswordExceptionClosure() {
  3939. function PasswordException(msg, code) {
  3940. this.name = 'PasswordException';
  3941. this.message = msg;
  3942. this.code = code;
  3943. }
  3944. PasswordException.prototype = new Error();
  3945. PasswordException.constructor = PasswordException;
  3946. return PasswordException;
  3947. }();
  3948. var UnknownErrorException = function UnknownErrorExceptionClosure() {
  3949. function UnknownErrorException(msg, details) {
  3950. this.name = 'UnknownErrorException';
  3951. this.message = msg;
  3952. this.details = details;
  3953. }
  3954. UnknownErrorException.prototype = new Error();
  3955. UnknownErrorException.constructor = UnknownErrorException;
  3956. return UnknownErrorException;
  3957. }();
  3958. var InvalidPDFException = function InvalidPDFExceptionClosure() {
  3959. function InvalidPDFException(msg) {
  3960. this.name = 'InvalidPDFException';
  3961. this.message = msg;
  3962. }
  3963. InvalidPDFException.prototype = new Error();
  3964. InvalidPDFException.constructor = InvalidPDFException;
  3965. return InvalidPDFException;
  3966. }();
  3967. var MissingPDFException = function MissingPDFExceptionClosure() {
  3968. function MissingPDFException(msg) {
  3969. this.name = 'MissingPDFException';
  3970. this.message = msg;
  3971. }
  3972. MissingPDFException.prototype = new Error();
  3973. MissingPDFException.constructor = MissingPDFException;
  3974. return MissingPDFException;
  3975. }();
  3976. var UnexpectedResponseException = function UnexpectedResponseExceptionClosure() {
  3977. function UnexpectedResponseException(msg, status) {
  3978. this.name = 'UnexpectedResponseException';
  3979. this.message = msg;
  3980. this.status = status;
  3981. }
  3982. UnexpectedResponseException.prototype = new Error();
  3983. UnexpectedResponseException.constructor = UnexpectedResponseException;
  3984. return UnexpectedResponseException;
  3985. }();
  3986. var NotImplementedException = function NotImplementedExceptionClosure() {
  3987. function NotImplementedException(msg) {
  3988. this.message = msg;
  3989. }
  3990. NotImplementedException.prototype = new Error();
  3991. NotImplementedException.prototype.name = 'NotImplementedException';
  3992. NotImplementedException.constructor = NotImplementedException;
  3993. return NotImplementedException;
  3994. }();
  3995. var MissingDataException = function MissingDataExceptionClosure() {
  3996. function MissingDataException(begin, end) {
  3997. this.begin = begin;
  3998. this.end = end;
  3999. this.message = 'Missing data [' + begin + ', ' + end + ')';
  4000. }
  4001. MissingDataException.prototype = new Error();
  4002. MissingDataException.prototype.name = 'MissingDataException';
  4003. MissingDataException.constructor = MissingDataException;
  4004. return MissingDataException;
  4005. }();
  4006. var XRefParseException = function XRefParseExceptionClosure() {
  4007. function XRefParseException(msg) {
  4008. this.message = msg;
  4009. }
  4010. XRefParseException.prototype = new Error();
  4011. XRefParseException.prototype.name = 'XRefParseException';
  4012. XRefParseException.constructor = XRefParseException;
  4013. return XRefParseException;
  4014. }();
  4015. var NullCharactersRegExp = /\x00/g;
  4016. function removeNullCharacters(str) {
  4017. if (typeof str !== 'string') {
  4018. warn('The argument for removeNullCharacters must be a string.');
  4019. return str;
  4020. }
  4021. return str.replace(NullCharactersRegExp, '');
  4022. }
  4023. function bytesToString(bytes) {
  4024. assert(bytes !== null && typeof bytes === 'object' && bytes.length !== undefined, 'Invalid argument for bytesToString');
  4025. var length = bytes.length;
  4026. var MAX_ARGUMENT_COUNT = 8192;
  4027. if (length < MAX_ARGUMENT_COUNT) {
  4028. return String.fromCharCode.apply(null, bytes);
  4029. }
  4030. var strBuf = [];
  4031. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  4032. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  4033. var chunk = bytes.subarray(i, chunkEnd);
  4034. strBuf.push(String.fromCharCode.apply(null, chunk));
  4035. }
  4036. return strBuf.join('');
  4037. }
  4038. function stringToBytes(str) {
  4039. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  4040. var length = str.length;
  4041. var bytes = new Uint8Array(length);
  4042. for (var i = 0; i < length; ++i) {
  4043. bytes[i] = str.charCodeAt(i) & 0xFF;
  4044. }
  4045. return bytes;
  4046. }
  4047. /**
  4048. * Gets length of the array (Array, Uint8Array, or string) in bytes.
  4049. * @param {Array|Uint8Array|string} arr
  4050. * @returns {number}
  4051. */
  4052. function arrayByteLength(arr) {
  4053. if (arr.length !== undefined) {
  4054. return arr.length;
  4055. }
  4056. assert(arr.byteLength !== undefined);
  4057. return arr.byteLength;
  4058. }
  4059. /**
  4060. * Combines array items (arrays) into single Uint8Array object.
  4061. * @param {Array} arr - the array of the arrays (Array, Uint8Array, or string).
  4062. * @returns {Uint8Array}
  4063. */
  4064. function arraysToBytes(arr) {
  4065. // Shortcut: if first and only item is Uint8Array, return it.
  4066. if (arr.length === 1 && arr[0] instanceof Uint8Array) {
  4067. return arr[0];
  4068. }
  4069. var resultLength = 0;
  4070. var i, ii = arr.length;
  4071. var item, itemLength;
  4072. for (i = 0; i < ii; i++) {
  4073. item = arr[i];
  4074. itemLength = arrayByteLength(item);
  4075. resultLength += itemLength;
  4076. }
  4077. var pos = 0;
  4078. var data = new Uint8Array(resultLength);
  4079. for (i = 0; i < ii; i++) {
  4080. item = arr[i];
  4081. if (!(item instanceof Uint8Array)) {
  4082. if (typeof item === 'string') {
  4083. item = stringToBytes(item);
  4084. } else {
  4085. item = new Uint8Array(item);
  4086. }
  4087. }
  4088. itemLength = item.byteLength;
  4089. data.set(item, pos);
  4090. pos += itemLength;
  4091. }
  4092. return data;
  4093. }
  4094. function string32(value) {
  4095. return String.fromCharCode(value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff);
  4096. }
  4097. function log2(x) {
  4098. var n = 1, i = 0;
  4099. while (x > n) {
  4100. n <<= 1;
  4101. i++;
  4102. }
  4103. return i;
  4104. }
  4105. function readInt8(data, start) {
  4106. return data[start] << 24 >> 24;
  4107. }
  4108. function readUint16(data, offset) {
  4109. return data[offset] << 8 | data[offset + 1];
  4110. }
  4111. function readUint32(data, offset) {
  4112. return (data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3]) >>> 0;
  4113. }
  4114. // Lazy test the endianness of the platform
  4115. // NOTE: This will be 'true' for simulated TypedArrays
  4116. function isLittleEndian() {
  4117. var buffer8 = new Uint8Array(2);
  4118. buffer8[0] = 1;
  4119. var buffer16 = new Uint16Array(buffer8.buffer);
  4120. return buffer16[0] === 1;
  4121. }
  4122. // Checks if it's possible to eval JS expressions.
  4123. function isEvalSupported() {
  4124. try {
  4125. new Function('');
  4126. return true;
  4127. } catch (e) {
  4128. return false;
  4129. }
  4130. }
  4131. var Uint32ArrayView = function Uint32ArrayViewClosure() {
  4132. function Uint32ArrayView(buffer, length) {
  4133. this.buffer = buffer;
  4134. this.byteLength = buffer.length;
  4135. this.length = length === undefined ? this.byteLength >> 2 : length;
  4136. ensureUint32ArrayViewProps(this.length);
  4137. }
  4138. Uint32ArrayView.prototype = Object.create(null);
  4139. var uint32ArrayViewSetters = 0;
  4140. function createUint32ArrayProp(index) {
  4141. return {
  4142. get: function () {
  4143. var buffer = this.buffer, offset = index << 2;
  4144. return (buffer[offset] | buffer[offset + 1] << 8 | buffer[offset + 2] << 16 | buffer[offset + 3] << 24) >>> 0;
  4145. },
  4146. set: function (value) {
  4147. var buffer = this.buffer, offset = index << 2;
  4148. buffer[offset] = value & 255;
  4149. buffer[offset + 1] = value >> 8 & 255;
  4150. buffer[offset + 2] = value >> 16 & 255;
  4151. buffer[offset + 3] = value >>> 24 & 255;
  4152. }
  4153. };
  4154. }
  4155. function ensureUint32ArrayViewProps(length) {
  4156. while (uint32ArrayViewSetters < length) {
  4157. Object.defineProperty(Uint32ArrayView.prototype, uint32ArrayViewSetters, createUint32ArrayProp(uint32ArrayViewSetters));
  4158. uint32ArrayViewSetters++;
  4159. }
  4160. }
  4161. return Uint32ArrayView;
  4162. }();
  4163. exports.Uint32ArrayView = Uint32ArrayView;
  4164. var IDENTITY_MATRIX = [
  4165. 1,
  4166. 0,
  4167. 0,
  4168. 1,
  4169. 0,
  4170. 0
  4171. ];
  4172. var Util = function UtilClosure() {
  4173. function Util() {
  4174. }
  4175. var rgbBuf = [
  4176. 'rgb(',
  4177. 0,
  4178. ',',
  4179. 0,
  4180. ',',
  4181. 0,
  4182. ')'
  4183. ];
  4184. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  4185. // creating many intermediate strings.
  4186. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  4187. rgbBuf[1] = r;
  4188. rgbBuf[3] = g;
  4189. rgbBuf[5] = b;
  4190. return rgbBuf.join('');
  4191. };
  4192. // Concatenates two transformation matrices together and returns the result.
  4193. Util.transform = function Util_transform(m1, m2) {
  4194. return [
  4195. m1[0] * m2[0] + m1[2] * m2[1],
  4196. m1[1] * m2[0] + m1[3] * m2[1],
  4197. m1[0] * m2[2] + m1[2] * m2[3],
  4198. m1[1] * m2[2] + m1[3] * m2[3],
  4199. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  4200. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  4201. ];
  4202. };
  4203. // For 2d affine transforms
  4204. Util.applyTransform = function Util_applyTransform(p, m) {
  4205. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  4206. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  4207. return [
  4208. xt,
  4209. yt
  4210. ];
  4211. };
  4212. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  4213. var d = m[0] * m[3] - m[1] * m[2];
  4214. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  4215. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  4216. return [
  4217. xt,
  4218. yt
  4219. ];
  4220. };
  4221. // Applies the transform to the rectangle and finds the minimum axially
  4222. // aligned bounding box.
  4223. Util.getAxialAlignedBoundingBox = function Util_getAxialAlignedBoundingBox(r, m) {
  4224. var p1 = Util.applyTransform(r, m);
  4225. var p2 = Util.applyTransform(r.slice(2, 4), m);
  4226. var p3 = Util.applyTransform([
  4227. r[0],
  4228. r[3]
  4229. ], m);
  4230. var p4 = Util.applyTransform([
  4231. r[2],
  4232. r[1]
  4233. ], m);
  4234. return [
  4235. Math.min(p1[0], p2[0], p3[0], p4[0]),
  4236. Math.min(p1[1], p2[1], p3[1], p4[1]),
  4237. Math.max(p1[0], p2[0], p3[0], p4[0]),
  4238. Math.max(p1[1], p2[1], p3[1], p4[1])
  4239. ];
  4240. };
  4241. Util.inverseTransform = function Util_inverseTransform(m) {
  4242. var d = m[0] * m[3] - m[1] * m[2];
  4243. return [
  4244. m[3] / d,
  4245. -m[1] / d,
  4246. -m[2] / d,
  4247. m[0] / d,
  4248. (m[2] * m[5] - m[4] * m[3]) / d,
  4249. (m[4] * m[1] - m[5] * m[0]) / d
  4250. ];
  4251. };
  4252. // Apply a generic 3d matrix M on a 3-vector v:
  4253. // | a b c | | X |
  4254. // | d e f | x | Y |
  4255. // | g h i | | Z |
  4256. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  4257. // with v as [X,Y,Z]
  4258. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  4259. return [
  4260. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  4261. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  4262. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  4263. ];
  4264. };
  4265. // This calculation uses Singular Value Decomposition.
  4266. // The SVD can be represented with formula A = USV. We are interested in the
  4267. // matrix S here because it represents the scale values.
  4268. Util.singularValueDecompose2dScale = function Util_singularValueDecompose2dScale(m) {
  4269. var transpose = [
  4270. m[0],
  4271. m[2],
  4272. m[1],
  4273. m[3]
  4274. ];
  4275. // Multiply matrix m with its transpose.
  4276. var a = m[0] * transpose[0] + m[1] * transpose[2];
  4277. var b = m[0] * transpose[1] + m[1] * transpose[3];
  4278. var c = m[2] * transpose[0] + m[3] * transpose[2];
  4279. var d = m[2] * transpose[1] + m[3] * transpose[3];
  4280. // Solve the second degree polynomial to get roots.
  4281. var first = (a + d) / 2;
  4282. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  4283. var sx = first + second || 1;
  4284. var sy = first - second || 1;
  4285. // Scale values are the square roots of the eigenvalues.
  4286. return [
  4287. Math.sqrt(sx),
  4288. Math.sqrt(sy)
  4289. ];
  4290. };
  4291. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  4292. // For coordinate systems whose origin lies in the bottom-left, this
  4293. // means normalization to (BL,TR) ordering. For systems with origin in the
  4294. // top-left, this means (TL,BR) ordering.
  4295. Util.normalizeRect = function Util_normalizeRect(rect) {
  4296. var r = rect.slice(0);
  4297. // clone rect
  4298. if (rect[0] > rect[2]) {
  4299. r[0] = rect[2];
  4300. r[2] = rect[0];
  4301. }
  4302. if (rect[1] > rect[3]) {
  4303. r[1] = rect[3];
  4304. r[3] = rect[1];
  4305. }
  4306. return r;
  4307. };
  4308. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  4309. // intersection of rect1 and rect2. If no intersection, returns 'false'
  4310. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  4311. Util.intersect = function Util_intersect(rect1, rect2) {
  4312. function compare(a, b) {
  4313. return a - b;
  4314. }
  4315. // Order points along the axes
  4316. var orderedX = [
  4317. rect1[0],
  4318. rect1[2],
  4319. rect2[0],
  4320. rect2[2]
  4321. ].sort(compare), orderedY = [
  4322. rect1[1],
  4323. rect1[3],
  4324. rect2[1],
  4325. rect2[3]
  4326. ].sort(compare), result = [];
  4327. rect1 = Util.normalizeRect(rect1);
  4328. rect2 = Util.normalizeRect(rect2);
  4329. // X: first and second points belong to different rectangles?
  4330. if (orderedX[0] === rect1[0] && orderedX[1] === rect2[0] || orderedX[0] === rect2[0] && orderedX[1] === rect1[0]) {
  4331. // Intersection must be between second and third points
  4332. result[0] = orderedX[1];
  4333. result[2] = orderedX[2];
  4334. } else {
  4335. return false;
  4336. }
  4337. // Y: first and second points belong to different rectangles?
  4338. if (orderedY[0] === rect1[1] && orderedY[1] === rect2[1] || orderedY[0] === rect2[1] && orderedY[1] === rect1[1]) {
  4339. // Intersection must be between second and third points
  4340. result[1] = orderedY[1];
  4341. result[3] = orderedY[2];
  4342. } else {
  4343. return false;
  4344. }
  4345. return result;
  4346. };
  4347. Util.sign = function Util_sign(num) {
  4348. return num < 0 ? -1 : 1;
  4349. };
  4350. var ROMAN_NUMBER_MAP = [
  4351. '',
  4352. 'C',
  4353. 'CC',
  4354. 'CCC',
  4355. 'CD',
  4356. 'D',
  4357. 'DC',
  4358. 'DCC',
  4359. 'DCCC',
  4360. 'CM',
  4361. '',
  4362. 'X',
  4363. 'XX',
  4364. 'XXX',
  4365. 'XL',
  4366. 'L',
  4367. 'LX',
  4368. 'LXX',
  4369. 'LXXX',
  4370. 'XC',
  4371. '',
  4372. 'I',
  4373. 'II',
  4374. 'III',
  4375. 'IV',
  4376. 'V',
  4377. 'VI',
  4378. 'VII',
  4379. 'VIII',
  4380. 'IX'
  4381. ];
  4382. /**
  4383. * Converts positive integers to (upper case) Roman numerals.
  4384. * @param {integer} number - The number that should be converted.
  4385. * @param {boolean} lowerCase - Indicates if the result should be converted
  4386. * to lower case letters. The default is false.
  4387. * @return {string} The resulting Roman number.
  4388. */
  4389. Util.toRoman = function Util_toRoman(number, lowerCase) {
  4390. assert(isInt(number) && number > 0, 'The number should be a positive integer.');
  4391. var pos, romanBuf = [];
  4392. // Thousands
  4393. while (number >= 1000) {
  4394. number -= 1000;
  4395. romanBuf.push('M');
  4396. }
  4397. // Hundreds
  4398. pos = number / 100 | 0;
  4399. number %= 100;
  4400. romanBuf.push(ROMAN_NUMBER_MAP[pos]);
  4401. // Tens
  4402. pos = number / 10 | 0;
  4403. number %= 10;
  4404. romanBuf.push(ROMAN_NUMBER_MAP[10 + pos]);
  4405. // Ones
  4406. romanBuf.push(ROMAN_NUMBER_MAP[20 + number]);
  4407. var romanStr = romanBuf.join('');
  4408. return lowerCase ? romanStr.toLowerCase() : romanStr;
  4409. };
  4410. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  4411. Array.prototype.push.apply(arr1, arr2);
  4412. };
  4413. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  4414. Array.prototype.unshift.apply(arr1, arr2);
  4415. };
  4416. Util.extendObj = function extendObj(obj1, obj2) {
  4417. for (var key in obj2) {
  4418. obj1[key] = obj2[key];
  4419. }
  4420. };
  4421. Util.getInheritableProperty = function Util_getInheritableProperty(dict, name, getArray) {
  4422. while (dict && !dict.has(name)) {
  4423. dict = dict.get('Parent');
  4424. }
  4425. if (!dict) {
  4426. return null;
  4427. }
  4428. return getArray ? dict.getArray(name) : dict.get(name);
  4429. };
  4430. Util.inherit = function Util_inherit(sub, base, prototype) {
  4431. sub.prototype = Object.create(base.prototype);
  4432. sub.prototype.constructor = sub;
  4433. for (var prop in prototype) {
  4434. sub.prototype[prop] = prototype[prop];
  4435. }
  4436. };
  4437. Util.loadScript = function Util_loadScript(src, callback) {
  4438. var script = document.createElement('script');
  4439. var loaded = false;
  4440. script.setAttribute('src', src);
  4441. if (callback) {
  4442. script.onload = function () {
  4443. if (!loaded) {
  4444. callback();
  4445. }
  4446. loaded = true;
  4447. };
  4448. }
  4449. document.getElementsByTagName('head')[0].appendChild(script);
  4450. };
  4451. return Util;
  4452. }();
  4453. /**
  4454. * PDF page viewport created based on scale, rotation and offset.
  4455. * @class
  4456. * @alias PageViewport
  4457. */
  4458. var PageViewport = function PageViewportClosure() {
  4459. /**
  4460. * @constructor
  4461. * @private
  4462. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  4463. * @param scale {number} scale of the viewport.
  4464. * @param rotation {number} rotations of the viewport in degrees.
  4465. * @param offsetX {number} offset X
  4466. * @param offsetY {number} offset Y
  4467. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  4468. */
  4469. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  4470. this.viewBox = viewBox;
  4471. this.scale = scale;
  4472. this.rotation = rotation;
  4473. this.offsetX = offsetX;
  4474. this.offsetY = offsetY;
  4475. // creating transform to convert pdf coordinate system to the normal
  4476. // canvas like coordinates taking in account scale and rotation
  4477. var centerX = (viewBox[2] + viewBox[0]) / 2;
  4478. var centerY = (viewBox[3] + viewBox[1]) / 2;
  4479. var rotateA, rotateB, rotateC, rotateD;
  4480. rotation = rotation % 360;
  4481. rotation = rotation < 0 ? rotation + 360 : rotation;
  4482. switch (rotation) {
  4483. case 180:
  4484. rotateA = -1;
  4485. rotateB = 0;
  4486. rotateC = 0;
  4487. rotateD = 1;
  4488. break;
  4489. case 90:
  4490. rotateA = 0;
  4491. rotateB = 1;
  4492. rotateC = 1;
  4493. rotateD = 0;
  4494. break;
  4495. case 270:
  4496. rotateA = 0;
  4497. rotateB = -1;
  4498. rotateC = -1;
  4499. rotateD = 0;
  4500. break;
  4501. //case 0:
  4502. default:
  4503. rotateA = 1;
  4504. rotateB = 0;
  4505. rotateC = 0;
  4506. rotateD = -1;
  4507. break;
  4508. }
  4509. if (dontFlip) {
  4510. rotateC = -rotateC;
  4511. rotateD = -rotateD;
  4512. }
  4513. var offsetCanvasX, offsetCanvasY;
  4514. var width, height;
  4515. if (rotateA === 0) {
  4516. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  4517. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  4518. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  4519. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  4520. } else {
  4521. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  4522. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  4523. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  4524. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  4525. }
  4526. // creating transform for the following operations:
  4527. // translate(-centerX, -centerY), rotate and flip vertically,
  4528. // scale, and translate(offsetCanvasX, offsetCanvasY)
  4529. this.transform = [
  4530. rotateA * scale,
  4531. rotateB * scale,
  4532. rotateC * scale,
  4533. rotateD * scale,
  4534. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  4535. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  4536. ];
  4537. this.width = width;
  4538. this.height = height;
  4539. this.fontScale = scale;
  4540. }
  4541. PageViewport.prototype = /** @lends PageViewport.prototype */
  4542. {
  4543. /**
  4544. * Clones viewport with additional properties.
  4545. * @param args {Object} (optional) If specified, may contain the 'scale' or
  4546. * 'rotation' properties to override the corresponding properties in
  4547. * the cloned viewport.
  4548. * @returns {PageViewport} Cloned viewport.
  4549. */
  4550. clone: function PageViewPort_clone(args) {
  4551. args = args || {};
  4552. var scale = 'scale' in args ? args.scale : this.scale;
  4553. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  4554. return new PageViewport(this.viewBox.slice(), scale, rotation, this.offsetX, this.offsetY, args.dontFlip);
  4555. },
  4556. /**
  4557. * Converts PDF point to the viewport coordinates. For examples, useful for
  4558. * converting PDF location into canvas pixel coordinates.
  4559. * @param x {number} X coordinate.
  4560. * @param y {number} Y coordinate.
  4561. * @returns {Object} Object that contains 'x' and 'y' properties of the
  4562. * point in the viewport coordinate space.
  4563. * @see {@link convertToPdfPoint}
  4564. * @see {@link convertToViewportRectangle}
  4565. */
  4566. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  4567. return Util.applyTransform([
  4568. x,
  4569. y
  4570. ], this.transform);
  4571. },
  4572. /**
  4573. * Converts PDF rectangle to the viewport coordinates.
  4574. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  4575. * @returns {Array} Contains corresponding coordinates of the rectangle
  4576. * in the viewport coordinate space.
  4577. * @see {@link convertToViewportPoint}
  4578. */
  4579. convertToViewportRectangle: function PageViewport_convertToViewportRectangle(rect) {
  4580. var tl = Util.applyTransform([
  4581. rect[0],
  4582. rect[1]
  4583. ], this.transform);
  4584. var br = Util.applyTransform([
  4585. rect[2],
  4586. rect[3]
  4587. ], this.transform);
  4588. return [
  4589. tl[0],
  4590. tl[1],
  4591. br[0],
  4592. br[1]
  4593. ];
  4594. },
  4595. /**
  4596. * Converts viewport coordinates to the PDF location. For examples, useful
  4597. * for converting canvas pixel location into PDF one.
  4598. * @param x {number} X coordinate.
  4599. * @param y {number} Y coordinate.
  4600. * @returns {Object} Object that contains 'x' and 'y' properties of the
  4601. * point in the PDF coordinate space.
  4602. * @see {@link convertToViewportPoint}
  4603. */
  4604. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  4605. return Util.applyInverseTransform([
  4606. x,
  4607. y
  4608. ], this.transform);
  4609. }
  4610. };
  4611. return PageViewport;
  4612. }();
  4613. var PDFStringTranslateTable = [
  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. 0,
  4627. 0,
  4628. 0,
  4629. 0,
  4630. 0,
  4631. 0,
  4632. 0,
  4633. 0,
  4634. 0,
  4635. 0,
  4636. 0,
  4637. 0,
  4638. 0x2D8,
  4639. 0x2C7,
  4640. 0x2C6,
  4641. 0x2D9,
  4642. 0x2DD,
  4643. 0x2DB,
  4644. 0x2DA,
  4645. 0x2DC,
  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. 0,
  4731. 0,
  4732. 0,
  4733. 0,
  4734. 0,
  4735. 0,
  4736. 0,
  4737. 0,
  4738. 0,
  4739. 0,
  4740. 0,
  4741. 0,
  4742. 0x2022,
  4743. 0x2020,
  4744. 0x2021,
  4745. 0x2026,
  4746. 0x2014,
  4747. 0x2013,
  4748. 0x192,
  4749. 0x2044,
  4750. 0x2039,
  4751. 0x203A,
  4752. 0x2212,
  4753. 0x2030,
  4754. 0x201E,
  4755. 0x201C,
  4756. 0x201D,
  4757. 0x2018,
  4758. 0x2019,
  4759. 0x201A,
  4760. 0x2122,
  4761. 0xFB01,
  4762. 0xFB02,
  4763. 0x141,
  4764. 0x152,
  4765. 0x160,
  4766. 0x178,
  4767. 0x17D,
  4768. 0x131,
  4769. 0x142,
  4770. 0x153,
  4771. 0x161,
  4772. 0x17E,
  4773. 0,
  4774. 0x20AC
  4775. ];
  4776. function stringToPDFString(str) {
  4777. var i, n = str.length, strBuf = [];
  4778. if (str[0] === '\xFE' && str[1] === '\xFF') {
  4779. // UTF16BE BOM
  4780. for (i = 2; i < n; i += 2) {
  4781. strBuf.push(String.fromCharCode(str.charCodeAt(i) << 8 | str.charCodeAt(i + 1)));
  4782. }
  4783. } else {
  4784. for (i = 0; i < n; ++i) {
  4785. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  4786. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  4787. }
  4788. }
  4789. return strBuf.join('');
  4790. }
  4791. function stringToUTF8String(str) {
  4792. return decodeURIComponent(escape(str));
  4793. }
  4794. function utf8StringToString(str) {
  4795. return unescape(encodeURIComponent(str));
  4796. }
  4797. function isEmptyObj(obj) {
  4798. for (var key in obj) {
  4799. return false;
  4800. }
  4801. return true;
  4802. }
  4803. function isBool(v) {
  4804. return typeof v === 'boolean';
  4805. }
  4806. function isInt(v) {
  4807. return typeof v === 'number' && (v | 0) === v;
  4808. }
  4809. function isNum(v) {
  4810. return typeof v === 'number';
  4811. }
  4812. function isString(v) {
  4813. return typeof v === 'string';
  4814. }
  4815. function isArray(v) {
  4816. return v instanceof Array;
  4817. }
  4818. function isArrayBuffer(v) {
  4819. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  4820. }
  4821. // Checks if ch is one of the following characters: SPACE, TAB, CR or LF.
  4822. function isSpace(ch) {
  4823. return ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A;
  4824. }
  4825. /**
  4826. * Promise Capability object.
  4827. *
  4828. * @typedef {Object} PromiseCapability
  4829. * @property {Promise} promise - A promise object.
  4830. * @property {function} resolve - Fulfills the promise.
  4831. * @property {function} reject - Rejects the promise.
  4832. */
  4833. /**
  4834. * Creates a promise capability object.
  4835. * @alias createPromiseCapability
  4836. *
  4837. * @return {PromiseCapability} A capability object contains:
  4838. * - a Promise, resolve and reject methods.
  4839. */
  4840. function createPromiseCapability() {
  4841. var capability = {};
  4842. capability.promise = new Promise(function (resolve, reject) {
  4843. capability.resolve = resolve;
  4844. capability.reject = reject;
  4845. });
  4846. return capability;
  4847. }
  4848. /**
  4849. * Polyfill for Promises:
  4850. * The following promise implementation tries to generally implement the
  4851. * Promise/A+ spec. Some notable differences from other promise libraries are:
  4852. * - There currently isn't a separate deferred and promise object.
  4853. * - Unhandled rejections eventually show an error if they aren't handled.
  4854. *
  4855. * Based off of the work in:
  4856. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  4857. */
  4858. (function PromiseClosure() {
  4859. if (globalScope.Promise) {
  4860. // Promises existing in the DOM/Worker, checking presence of all/resolve
  4861. if (typeof globalScope.Promise.all !== 'function') {
  4862. globalScope.Promise.all = function (iterable) {
  4863. var count = 0, results = [], resolve, reject;
  4864. var promise = new globalScope.Promise(function (resolve_, reject_) {
  4865. resolve = resolve_;
  4866. reject = reject_;
  4867. });
  4868. iterable.forEach(function (p, i) {
  4869. count++;
  4870. p.then(function (result) {
  4871. results[i] = result;
  4872. count--;
  4873. if (count === 0) {
  4874. resolve(results);
  4875. }
  4876. }, reject);
  4877. });
  4878. if (count === 0) {
  4879. resolve(results);
  4880. }
  4881. return promise;
  4882. };
  4883. }
  4884. if (typeof globalScope.Promise.resolve !== 'function') {
  4885. globalScope.Promise.resolve = function (value) {
  4886. return new globalScope.Promise(function (resolve) {
  4887. resolve(value);
  4888. });
  4889. };
  4890. }
  4891. if (typeof globalScope.Promise.reject !== 'function') {
  4892. globalScope.Promise.reject = function (reason) {
  4893. return new globalScope.Promise(function (resolve, reject) {
  4894. reject(reason);
  4895. });
  4896. };
  4897. }
  4898. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  4899. globalScope.Promise.prototype.catch = function (onReject) {
  4900. return globalScope.Promise.prototype.then(undefined, onReject);
  4901. };
  4902. }
  4903. return;
  4904. }
  4905. var STATUS_PENDING = 0;
  4906. var STATUS_RESOLVED = 1;
  4907. var STATUS_REJECTED = 2;
  4908. // In an attempt to avoid silent exceptions, unhandled rejections are
  4909. // tracked and if they aren't handled in a certain amount of time an
  4910. // error is logged.
  4911. var REJECTION_TIMEOUT = 500;
  4912. var HandlerManager = {
  4913. handlers: [],
  4914. running: false,
  4915. unhandledRejections: [],
  4916. pendingRejectionCheck: false,
  4917. scheduleHandlers: function scheduleHandlers(promise) {
  4918. if (promise._status === STATUS_PENDING) {
  4919. return;
  4920. }
  4921. this.handlers = this.handlers.concat(promise._handlers);
  4922. promise._handlers = [];
  4923. if (this.running) {
  4924. return;
  4925. }
  4926. this.running = true;
  4927. setTimeout(this.runHandlers.bind(this), 0);
  4928. },
  4929. runHandlers: function runHandlers() {
  4930. var RUN_TIMEOUT = 1;
  4931. // ms
  4932. var timeoutAt = Date.now() + RUN_TIMEOUT;
  4933. while (this.handlers.length > 0) {
  4934. var handler = this.handlers.shift();
  4935. var nextStatus = handler.thisPromise._status;
  4936. var nextValue = handler.thisPromise._value;
  4937. try {
  4938. if (nextStatus === STATUS_RESOLVED) {
  4939. if (typeof handler.onResolve === 'function') {
  4940. nextValue = handler.onResolve(nextValue);
  4941. }
  4942. } else if (typeof handler.onReject === 'function') {
  4943. nextValue = handler.onReject(nextValue);
  4944. nextStatus = STATUS_RESOLVED;
  4945. if (handler.thisPromise._unhandledRejection) {
  4946. this.removeUnhandeledRejection(handler.thisPromise);
  4947. }
  4948. }
  4949. } catch (ex) {
  4950. nextStatus = STATUS_REJECTED;
  4951. nextValue = ex;
  4952. }
  4953. handler.nextPromise._updateStatus(nextStatus, nextValue);
  4954. if (Date.now() >= timeoutAt) {
  4955. break;
  4956. }
  4957. }
  4958. if (this.handlers.length > 0) {
  4959. setTimeout(this.runHandlers.bind(this), 0);
  4960. return;
  4961. }
  4962. this.running = false;
  4963. },
  4964. addUnhandledRejection: function addUnhandledRejection(promise) {
  4965. this.unhandledRejections.push({
  4966. promise: promise,
  4967. time: Date.now()
  4968. });
  4969. this.scheduleRejectionCheck();
  4970. },
  4971. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  4972. promise._unhandledRejection = false;
  4973. for (var i = 0; i < this.unhandledRejections.length; i++) {
  4974. if (this.unhandledRejections[i].promise === promise) {
  4975. this.unhandledRejections.splice(i);
  4976. i--;
  4977. }
  4978. }
  4979. },
  4980. scheduleRejectionCheck: function scheduleRejectionCheck() {
  4981. if (this.pendingRejectionCheck) {
  4982. return;
  4983. }
  4984. this.pendingRejectionCheck = true;
  4985. setTimeout(function rejectionCheck() {
  4986. this.pendingRejectionCheck = false;
  4987. var now = Date.now();
  4988. for (var i = 0; i < this.unhandledRejections.length; i++) {
  4989. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  4990. var unhandled = this.unhandledRejections[i].promise._value;
  4991. var msg = 'Unhandled rejection: ' + unhandled;
  4992. if (unhandled.stack) {
  4993. msg += '\n' + unhandled.stack;
  4994. }
  4995. warn(msg);
  4996. this.unhandledRejections.splice(i);
  4997. i--;
  4998. }
  4999. }
  5000. if (this.unhandledRejections.length) {
  5001. this.scheduleRejectionCheck();
  5002. }
  5003. }.bind(this), REJECTION_TIMEOUT);
  5004. }
  5005. };
  5006. var Promise = function Promise(resolver) {
  5007. this._status = STATUS_PENDING;
  5008. this._handlers = [];
  5009. try {
  5010. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  5011. } catch (e) {
  5012. this._reject(e);
  5013. }
  5014. };
  5015. /**
  5016. * Builds a promise that is resolved when all the passed in promises are
  5017. * resolved.
  5018. * @param {array} promises array of data and/or promises to wait for.
  5019. * @return {Promise} New dependent promise.
  5020. */
  5021. Promise.all = function Promise_all(promises) {
  5022. var resolveAll, rejectAll;
  5023. var deferred = new Promise(function (resolve, reject) {
  5024. resolveAll = resolve;
  5025. rejectAll = reject;
  5026. });
  5027. var unresolved = promises.length;
  5028. var results = [];
  5029. if (unresolved === 0) {
  5030. resolveAll(results);
  5031. return deferred;
  5032. }
  5033. function reject(reason) {
  5034. if (deferred._status === STATUS_REJECTED) {
  5035. return;
  5036. }
  5037. results = [];
  5038. rejectAll(reason);
  5039. }
  5040. for (var i = 0, ii = promises.length; i < ii; ++i) {
  5041. var promise = promises[i];
  5042. var resolve = function (i) {
  5043. return function (value) {
  5044. if (deferred._status === STATUS_REJECTED) {
  5045. return;
  5046. }
  5047. results[i] = value;
  5048. unresolved--;
  5049. if (unresolved === 0) {
  5050. resolveAll(results);
  5051. }
  5052. };
  5053. }(i);
  5054. if (Promise.isPromise(promise)) {
  5055. promise.then(resolve, reject);
  5056. } else {
  5057. resolve(promise);
  5058. }
  5059. }
  5060. return deferred;
  5061. };
  5062. /**
  5063. * Checks if the value is likely a promise (has a 'then' function).
  5064. * @return {boolean} true if value is thenable
  5065. */
  5066. Promise.isPromise = function Promise_isPromise(value) {
  5067. return value && typeof value.then === 'function';
  5068. };
  5069. /**
  5070. * Creates resolved promise
  5071. * @param value resolve value
  5072. * @returns {Promise}
  5073. */
  5074. Promise.resolve = function Promise_resolve(value) {
  5075. return new Promise(function (resolve) {
  5076. resolve(value);
  5077. });
  5078. };
  5079. /**
  5080. * Creates rejected promise
  5081. * @param reason rejection value
  5082. * @returns {Promise}
  5083. */
  5084. Promise.reject = function Promise_reject(reason) {
  5085. return new Promise(function (resolve, reject) {
  5086. reject(reason);
  5087. });
  5088. };
  5089. Promise.prototype = {
  5090. _status: null,
  5091. _value: null,
  5092. _handlers: null,
  5093. _unhandledRejection: null,
  5094. _updateStatus: function Promise__updateStatus(status, value) {
  5095. if (this._status === STATUS_RESOLVED || this._status === STATUS_REJECTED) {
  5096. return;
  5097. }
  5098. if (status === STATUS_RESOLVED && Promise.isPromise(value)) {
  5099. value.then(this._updateStatus.bind(this, STATUS_RESOLVED), this._updateStatus.bind(this, STATUS_REJECTED));
  5100. return;
  5101. }
  5102. this._status = status;
  5103. this._value = value;
  5104. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  5105. this._unhandledRejection = true;
  5106. HandlerManager.addUnhandledRejection(this);
  5107. }
  5108. HandlerManager.scheduleHandlers(this);
  5109. },
  5110. _resolve: function Promise_resolve(value) {
  5111. this._updateStatus(STATUS_RESOLVED, value);
  5112. },
  5113. _reject: function Promise_reject(reason) {
  5114. this._updateStatus(STATUS_REJECTED, reason);
  5115. },
  5116. then: function Promise_then(onResolve, onReject) {
  5117. var nextPromise = new Promise(function (resolve, reject) {
  5118. this.resolve = resolve;
  5119. this.reject = reject;
  5120. });
  5121. this._handlers.push({
  5122. thisPromise: this,
  5123. onResolve: onResolve,
  5124. onReject: onReject,
  5125. nextPromise: nextPromise
  5126. });
  5127. HandlerManager.scheduleHandlers(this);
  5128. return nextPromise;
  5129. },
  5130. catch: function Promise_catch(onReject) {
  5131. return this.then(undefined, onReject);
  5132. }
  5133. };
  5134. globalScope.Promise = Promise;
  5135. }());
  5136. (function WeakMapClosure() {
  5137. if (globalScope.WeakMap) {
  5138. return;
  5139. }
  5140. var id = 0;
  5141. function WeakMap() {
  5142. this.id = '$weakmap' + id++;
  5143. }
  5144. WeakMap.prototype = {
  5145. has: function (obj) {
  5146. return !!Object.getOwnPropertyDescriptor(obj, this.id);
  5147. },
  5148. get: function (obj, defaultValue) {
  5149. return this.has(obj) ? obj[this.id] : defaultValue;
  5150. },
  5151. set: function (obj, value) {
  5152. Object.defineProperty(obj, this.id, {
  5153. value: value,
  5154. enumerable: false,
  5155. configurable: true
  5156. });
  5157. },
  5158. delete: function (obj) {
  5159. delete obj[this.id];
  5160. }
  5161. };
  5162. globalScope.WeakMap = WeakMap;
  5163. }());
  5164. var StatTimer = function StatTimerClosure() {
  5165. function rpad(str, pad, length) {
  5166. while (str.length < length) {
  5167. str += pad;
  5168. }
  5169. return str;
  5170. }
  5171. function StatTimer() {
  5172. this.started = Object.create(null);
  5173. this.times = [];
  5174. this.enabled = true;
  5175. }
  5176. StatTimer.prototype = {
  5177. time: function StatTimer_time(name) {
  5178. if (!this.enabled) {
  5179. return;
  5180. }
  5181. if (name in this.started) {
  5182. warn('Timer is already running for ' + name);
  5183. }
  5184. this.started[name] = Date.now();
  5185. },
  5186. timeEnd: function StatTimer_timeEnd(name) {
  5187. if (!this.enabled) {
  5188. return;
  5189. }
  5190. if (!(name in this.started)) {
  5191. warn('Timer has not been started for ' + name);
  5192. }
  5193. this.times.push({
  5194. 'name': name,
  5195. 'start': this.started[name],
  5196. 'end': Date.now()
  5197. });
  5198. // Remove timer from started so it can be called again.
  5199. delete this.started[name];
  5200. },
  5201. toString: function StatTimer_toString() {
  5202. var i, ii;
  5203. var times = this.times;
  5204. var out = '';
  5205. // Find the longest name for padding purposes.
  5206. var longest = 0;
  5207. for (i = 0, ii = times.length; i < ii; ++i) {
  5208. var name = times[i]['name'];
  5209. if (name.length > longest) {
  5210. longest = name.length;
  5211. }
  5212. }
  5213. for (i = 0, ii = times.length; i < ii; ++i) {
  5214. var span = times[i];
  5215. var duration = span.end - span.start;
  5216. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  5217. }
  5218. return out;
  5219. }
  5220. };
  5221. return StatTimer;
  5222. }();
  5223. var createBlob = function createBlob(data, contentType) {
  5224. if (typeof Blob !== 'undefined') {
  5225. return new Blob([data], { type: contentType });
  5226. }
  5227. warn('The "Blob" constructor is not supported.');
  5228. };
  5229. var createObjectURL = function createObjectURLClosure() {
  5230. // Blob/createObjectURL is not available, falling back to data schema.
  5231. var digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  5232. return function createObjectURL(data, contentType, forceDataSchema) {
  5233. if (!forceDataSchema && typeof URL !== 'undefined' && URL.createObjectURL) {
  5234. var blob = createBlob(data, contentType);
  5235. return URL.createObjectURL(blob);
  5236. }
  5237. var buffer = 'data:' + contentType + ';base64,';
  5238. for (var i = 0, ii = data.length; i < ii; i += 3) {
  5239. var b1 = data[i] & 0xFF;
  5240. var b2 = data[i + 1] & 0xFF;
  5241. var b3 = data[i + 2] & 0xFF;
  5242. var d1 = b1 >> 2, d2 = (b1 & 3) << 4 | b2 >> 4;
  5243. var d3 = i + 1 < ii ? (b2 & 0xF) << 2 | b3 >> 6 : 64;
  5244. var d4 = i + 2 < ii ? b3 & 0x3F : 64;
  5245. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  5246. }
  5247. return buffer;
  5248. };
  5249. }();
  5250. function MessageHandler(sourceName, targetName, comObj) {
  5251. this.sourceName = sourceName;
  5252. this.targetName = targetName;
  5253. this.comObj = comObj;
  5254. this.callbackIndex = 1;
  5255. this.postMessageTransfers = true;
  5256. var callbacksCapabilities = this.callbacksCapabilities = Object.create(null);
  5257. var ah = this.actionHandler = Object.create(null);
  5258. this._onComObjOnMessage = function messageHandlerComObjOnMessage(event) {
  5259. var data = event.data;
  5260. if (data.targetName !== this.sourceName) {
  5261. return;
  5262. }
  5263. if (data.isReply) {
  5264. var callbackId = data.callbackId;
  5265. if (data.callbackId in callbacksCapabilities) {
  5266. var callback = callbacksCapabilities[callbackId];
  5267. delete callbacksCapabilities[callbackId];
  5268. if ('error' in data) {
  5269. callback.reject(data.error);
  5270. } else {
  5271. callback.resolve(data.data);
  5272. }
  5273. } else {
  5274. error('Cannot resolve callback ' + callbackId);
  5275. }
  5276. } else if (data.action in ah) {
  5277. var action = ah[data.action];
  5278. if (data.callbackId) {
  5279. var sourceName = this.sourceName;
  5280. var targetName = data.sourceName;
  5281. Promise.resolve().then(function () {
  5282. return action[0].call(action[1], data.data);
  5283. }).then(function (result) {
  5284. comObj.postMessage({
  5285. sourceName: sourceName,
  5286. targetName: targetName,
  5287. isReply: true,
  5288. callbackId: data.callbackId,
  5289. data: result
  5290. });
  5291. }, function (reason) {
  5292. if (reason instanceof Error) {
  5293. // Serialize error to avoid "DataCloneError"
  5294. reason = reason + '';
  5295. }
  5296. comObj.postMessage({
  5297. sourceName: sourceName,
  5298. targetName: targetName,
  5299. isReply: true,
  5300. callbackId: data.callbackId,
  5301. error: reason
  5302. });
  5303. });
  5304. } else {
  5305. action[0].call(action[1], data.data);
  5306. }
  5307. } else {
  5308. error('Unknown action from worker: ' + data.action);
  5309. }
  5310. }.bind(this);
  5311. comObj.addEventListener('message', this._onComObjOnMessage);
  5312. }
  5313. MessageHandler.prototype = {
  5314. on: function messageHandlerOn(actionName, handler, scope) {
  5315. var ah = this.actionHandler;
  5316. if (ah[actionName]) {
  5317. error('There is already an actionName called "' + actionName + '"');
  5318. }
  5319. ah[actionName] = [
  5320. handler,
  5321. scope
  5322. ];
  5323. },
  5324. /**
  5325. * Sends a message to the comObj to invoke the action with the supplied data.
  5326. * @param {String} actionName Action to call.
  5327. * @param {JSON} data JSON data to send.
  5328. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  5329. */
  5330. send: function messageHandlerSend(actionName, data, transfers) {
  5331. var message = {
  5332. sourceName: this.sourceName,
  5333. targetName: this.targetName,
  5334. action: actionName,
  5335. data: data
  5336. };
  5337. this.postMessage(message, transfers);
  5338. },
  5339. /**
  5340. * Sends a message to the comObj to invoke the action with the supplied data.
  5341. * Expects that other side will callback with the response.
  5342. * @param {String} actionName Action to call.
  5343. * @param {JSON} data JSON data to send.
  5344. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  5345. * @returns {Promise} Promise to be resolved with response data.
  5346. */
  5347. sendWithPromise: function messageHandlerSendWithPromise(actionName, data, transfers) {
  5348. var callbackId = this.callbackIndex++;
  5349. var message = {
  5350. sourceName: this.sourceName,
  5351. targetName: this.targetName,
  5352. action: actionName,
  5353. data: data,
  5354. callbackId: callbackId
  5355. };
  5356. var capability = createPromiseCapability();
  5357. this.callbacksCapabilities[callbackId] = capability;
  5358. try {
  5359. this.postMessage(message, transfers);
  5360. } catch (e) {
  5361. capability.reject(e);
  5362. }
  5363. return capability.promise;
  5364. },
  5365. /**
  5366. * Sends raw message to the comObj.
  5367. * @private
  5368. * @param message {Object} Raw message.
  5369. * @param transfers List of transfers/ArrayBuffers, or undefined.
  5370. */
  5371. postMessage: function (message, transfers) {
  5372. if (transfers && this.postMessageTransfers) {
  5373. this.comObj.postMessage(message, transfers);
  5374. } else {
  5375. this.comObj.postMessage(message);
  5376. }
  5377. },
  5378. destroy: function () {
  5379. this.comObj.removeEventListener('message', this._onComObjOnMessage);
  5380. }
  5381. };
  5382. function loadJpegStream(id, imageUrl, objs) {
  5383. var img = new Image();
  5384. img.onload = function loadJpegStream_onloadClosure() {
  5385. objs.resolve(id, img);
  5386. };
  5387. img.onerror = function loadJpegStream_onerrorClosure() {
  5388. objs.resolve(id, null);
  5389. warn('Error during JPEG image loading');
  5390. };
  5391. img.src = imageUrl;
  5392. }
  5393. // Polyfill from https://github.com/Polymer/URL
  5394. /* Any copyright is dedicated to the Public Domain.
  5395. * http://creativecommons.org/publicdomain/zero/1.0/ */
  5396. (function checkURLConstructor(scope) {
  5397. // feature detect for URL constructor
  5398. var hasWorkingUrl = false;
  5399. try {
  5400. if (typeof URL === 'function' && typeof URL.prototype === 'object' && 'origin' in URL.prototype) {
  5401. var u = new URL('b', 'http://a');
  5402. u.pathname = 'c%20d';
  5403. hasWorkingUrl = u.href === 'http://a/c%20d';
  5404. }
  5405. } catch (e) {
  5406. }
  5407. if (hasWorkingUrl) {
  5408. return;
  5409. }
  5410. var relative = Object.create(null);
  5411. relative['ftp'] = 21;
  5412. relative['file'] = 0;
  5413. relative['gopher'] = 70;
  5414. relative['http'] = 80;
  5415. relative['https'] = 443;
  5416. relative['ws'] = 80;
  5417. relative['wss'] = 443;
  5418. var relativePathDotMapping = Object.create(null);
  5419. relativePathDotMapping['%2e'] = '.';
  5420. relativePathDotMapping['.%2e'] = '..';
  5421. relativePathDotMapping['%2e.'] = '..';
  5422. relativePathDotMapping['%2e%2e'] = '..';
  5423. function isRelativeScheme(scheme) {
  5424. return relative[scheme] !== undefined;
  5425. }
  5426. function invalid() {
  5427. clear.call(this);
  5428. this._isInvalid = true;
  5429. }
  5430. function IDNAToASCII(h) {
  5431. if ('' === h) {
  5432. invalid.call(this);
  5433. }
  5434. // XXX
  5435. return h.toLowerCase();
  5436. }
  5437. function percentEscape(c) {
  5438. var unicode = c.charCodeAt(0);
  5439. if (unicode > 0x20 && unicode < 0x7F && // " # < > ? `
  5440. [
  5441. 0x22,
  5442. 0x23,
  5443. 0x3C,
  5444. 0x3E,
  5445. 0x3F,
  5446. 0x60
  5447. ].indexOf(unicode) === -1) {
  5448. return c;
  5449. }
  5450. return encodeURIComponent(c);
  5451. }
  5452. function percentEscapeQuery(c) {
  5453. // XXX This actually needs to encode c using encoding and then
  5454. // convert the bytes one-by-one.
  5455. var unicode = c.charCodeAt(0);
  5456. if (unicode > 0x20 && unicode < 0x7F && // " # < > ` (do not escape '?')
  5457. [
  5458. 0x22,
  5459. 0x23,
  5460. 0x3C,
  5461. 0x3E,
  5462. 0x60
  5463. ].indexOf(unicode) === -1) {
  5464. return c;
  5465. }
  5466. return encodeURIComponent(c);
  5467. }
  5468. var EOF, ALPHA = /[a-zA-Z]/, ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/;
  5469. function parse(input, stateOverride, base) {
  5470. function err(message) {
  5471. errors.push(message);
  5472. }
  5473. var state = stateOverride || 'scheme start', cursor = 0, buffer = '', seenAt = false, seenBracket = false, errors = [];
  5474. loop:
  5475. while ((input[cursor - 1] !== EOF || cursor === 0) && !this._isInvalid) {
  5476. var c = input[cursor];
  5477. switch (state) {
  5478. case 'scheme start':
  5479. if (c && ALPHA.test(c)) {
  5480. buffer += c.toLowerCase();
  5481. // ASCII-safe
  5482. state = 'scheme';
  5483. } else if (!stateOverride) {
  5484. buffer = '';
  5485. state = 'no scheme';
  5486. continue;
  5487. } else {
  5488. err('Invalid scheme.');
  5489. break loop;
  5490. }
  5491. break;
  5492. case 'scheme':
  5493. if (c && ALPHANUMERIC.test(c)) {
  5494. buffer += c.toLowerCase();
  5495. } else // ASCII-safe
  5496. if (':' === c) {
  5497. this._scheme = buffer;
  5498. buffer = '';
  5499. if (stateOverride) {
  5500. break loop;
  5501. }
  5502. if (isRelativeScheme(this._scheme)) {
  5503. this._isRelative = true;
  5504. }
  5505. if ('file' === this._scheme) {
  5506. state = 'relative';
  5507. } else if (this._isRelative && base && base._scheme === this._scheme) {
  5508. state = 'relative or authority';
  5509. } else if (this._isRelative) {
  5510. state = 'authority first slash';
  5511. } else {
  5512. state = 'scheme data';
  5513. }
  5514. } else if (!stateOverride) {
  5515. buffer = '';
  5516. cursor = 0;
  5517. state = 'no scheme';
  5518. continue;
  5519. } else if (EOF === c) {
  5520. break loop;
  5521. } else {
  5522. err('Code point not allowed in scheme: ' + c);
  5523. break loop;
  5524. }
  5525. break;
  5526. case 'scheme data':
  5527. if ('?' === c) {
  5528. this._query = '?';
  5529. state = 'query';
  5530. } else if ('#' === c) {
  5531. this._fragment = '#';
  5532. state = 'fragment';
  5533. } else {
  5534. // XXX error handling
  5535. if (EOF !== c && '\t' !== c && '\n' !== c && '\r' !== c) {
  5536. this._schemeData += percentEscape(c);
  5537. }
  5538. }
  5539. break;
  5540. case 'no scheme':
  5541. if (!base || !isRelativeScheme(base._scheme)) {
  5542. err('Missing scheme.');
  5543. invalid.call(this);
  5544. } else {
  5545. state = 'relative';
  5546. continue;
  5547. }
  5548. break;
  5549. case 'relative or authority':
  5550. if ('/' === c && '/' === input[cursor + 1]) {
  5551. state = 'authority ignore slashes';
  5552. } else {
  5553. err('Expected /, got: ' + c);
  5554. state = 'relative';
  5555. continue;
  5556. }
  5557. break;
  5558. case 'relative':
  5559. this._isRelative = true;
  5560. if ('file' !== this._scheme) {
  5561. this._scheme = base._scheme;
  5562. }
  5563. if (EOF === c) {
  5564. this._host = base._host;
  5565. this._port = base._port;
  5566. this._path = base._path.slice();
  5567. this._query = base._query;
  5568. this._username = base._username;
  5569. this._password = base._password;
  5570. break loop;
  5571. } else if ('/' === c || '\\' === c) {
  5572. if ('\\' === c) {
  5573. err('\\ is an invalid code point.');
  5574. }
  5575. state = 'relative slash';
  5576. } else if ('?' === c) {
  5577. this._host = base._host;
  5578. this._port = base._port;
  5579. this._path = base._path.slice();
  5580. this._query = '?';
  5581. this._username = base._username;
  5582. this._password = base._password;
  5583. state = 'query';
  5584. } else if ('#' === c) {
  5585. this._host = base._host;
  5586. this._port = base._port;
  5587. this._path = base._path.slice();
  5588. this._query = base._query;
  5589. this._fragment = '#';
  5590. this._username = base._username;
  5591. this._password = base._password;
  5592. state = 'fragment';
  5593. } else {
  5594. var nextC = input[cursor + 1];
  5595. var nextNextC = input[cursor + 2];
  5596. if ('file' !== this._scheme || !ALPHA.test(c) || nextC !== ':' && nextC !== '|' || EOF !== nextNextC && '/' !== nextNextC && '\\' !== nextNextC && '?' !== nextNextC && '#' !== nextNextC) {
  5597. this._host = base._host;
  5598. this._port = base._port;
  5599. this._username = base._username;
  5600. this._password = base._password;
  5601. this._path = base._path.slice();
  5602. this._path.pop();
  5603. }
  5604. state = 'relative path';
  5605. continue;
  5606. }
  5607. break;
  5608. case 'relative slash':
  5609. if ('/' === c || '\\' === c) {
  5610. if ('\\' === c) {
  5611. err('\\ is an invalid code point.');
  5612. }
  5613. if ('file' === this._scheme) {
  5614. state = 'file host';
  5615. } else {
  5616. state = 'authority ignore slashes';
  5617. }
  5618. } else {
  5619. if ('file' !== this._scheme) {
  5620. this._host = base._host;
  5621. this._port = base._port;
  5622. this._username = base._username;
  5623. this._password = base._password;
  5624. }
  5625. state = 'relative path';
  5626. continue;
  5627. }
  5628. break;
  5629. case 'authority first slash':
  5630. if ('/' === c) {
  5631. state = 'authority second slash';
  5632. } else {
  5633. err('Expected \'/\', got: ' + c);
  5634. state = 'authority ignore slashes';
  5635. continue;
  5636. }
  5637. break;
  5638. case 'authority second slash':
  5639. state = 'authority ignore slashes';
  5640. if ('/' !== c) {
  5641. err('Expected \'/\', got: ' + c);
  5642. continue;
  5643. }
  5644. break;
  5645. case 'authority ignore slashes':
  5646. if ('/' !== c && '\\' !== c) {
  5647. state = 'authority';
  5648. continue;
  5649. } else {
  5650. err('Expected authority, got: ' + c);
  5651. }
  5652. break;
  5653. case 'authority':
  5654. if ('@' === c) {
  5655. if (seenAt) {
  5656. err('@ already seen.');
  5657. buffer += '%40';
  5658. }
  5659. seenAt = true;
  5660. for (var i = 0; i < buffer.length; i++) {
  5661. var cp = buffer[i];
  5662. if ('\t' === cp || '\n' === cp || '\r' === cp) {
  5663. err('Invalid whitespace in authority.');
  5664. continue;
  5665. }
  5666. // XXX check URL code points
  5667. if (':' === cp && null === this._password) {
  5668. this._password = '';
  5669. continue;
  5670. }
  5671. var tempC = percentEscape(cp);
  5672. if (null !== this._password) {
  5673. this._password += tempC;
  5674. } else {
  5675. this._username += tempC;
  5676. }
  5677. }
  5678. buffer = '';
  5679. } else if (EOF === c || '/' === c || '\\' === c || '?' === c || '#' === c) {
  5680. cursor -= buffer.length;
  5681. buffer = '';
  5682. state = 'host';
  5683. continue;
  5684. } else {
  5685. buffer += c;
  5686. }
  5687. break;
  5688. case 'file host':
  5689. if (EOF === c || '/' === c || '\\' === c || '?' === c || '#' === c) {
  5690. if (buffer.length === 2 && ALPHA.test(buffer[0]) && (buffer[1] === ':' || buffer[1] === '|')) {
  5691. state = 'relative path';
  5692. } else if (buffer.length === 0) {
  5693. state = 'relative path start';
  5694. } else {
  5695. this._host = IDNAToASCII.call(this, buffer);
  5696. buffer = '';
  5697. state = 'relative path start';
  5698. }
  5699. continue;
  5700. } else if ('\t' === c || '\n' === c || '\r' === c) {
  5701. err('Invalid whitespace in file host.');
  5702. } else {
  5703. buffer += c;
  5704. }
  5705. break;
  5706. case 'host':
  5707. case 'hostname':
  5708. if (':' === c && !seenBracket) {
  5709. // XXX host parsing
  5710. this._host = IDNAToASCII.call(this, buffer);
  5711. buffer = '';
  5712. state = 'port';
  5713. if ('hostname' === stateOverride) {
  5714. break loop;
  5715. }
  5716. } else if (EOF === c || '/' === c || '\\' === c || '?' === c || '#' === c) {
  5717. this._host = IDNAToASCII.call(this, buffer);
  5718. buffer = '';
  5719. state = 'relative path start';
  5720. if (stateOverride) {
  5721. break loop;
  5722. }
  5723. continue;
  5724. } else if ('\t' !== c && '\n' !== c && '\r' !== c) {
  5725. if ('[' === c) {
  5726. seenBracket = true;
  5727. } else if (']' === c) {
  5728. seenBracket = false;
  5729. }
  5730. buffer += c;
  5731. } else {
  5732. err('Invalid code point in host/hostname: ' + c);
  5733. }
  5734. break;
  5735. case 'port':
  5736. if (/[0-9]/.test(c)) {
  5737. buffer += c;
  5738. } else if (EOF === c || '/' === c || '\\' === c || '?' === c || '#' === c || stateOverride) {
  5739. if ('' !== buffer) {
  5740. var temp = parseInt(buffer, 10);
  5741. if (temp !== relative[this._scheme]) {
  5742. this._port = temp + '';
  5743. }
  5744. buffer = '';
  5745. }
  5746. if (stateOverride) {
  5747. break loop;
  5748. }
  5749. state = 'relative path start';
  5750. continue;
  5751. } else if ('\t' === c || '\n' === c || '\r' === c) {
  5752. err('Invalid code point in port: ' + c);
  5753. } else {
  5754. invalid.call(this);
  5755. }
  5756. break;
  5757. case 'relative path start':
  5758. if ('\\' === c) {
  5759. err('\'\\\' not allowed in path.');
  5760. }
  5761. state = 'relative path';
  5762. if ('/' !== c && '\\' !== c) {
  5763. continue;
  5764. }
  5765. break;
  5766. case 'relative path':
  5767. if (EOF === c || '/' === c || '\\' === c || !stateOverride && ('?' === c || '#' === c)) {
  5768. if ('\\' === c) {
  5769. err('\\ not allowed in relative path.');
  5770. }
  5771. var tmp;
  5772. if (tmp = relativePathDotMapping[buffer.toLowerCase()]) {
  5773. buffer = tmp;
  5774. }
  5775. if ('..' === buffer) {
  5776. this._path.pop();
  5777. if ('/' !== c && '\\' !== c) {
  5778. this._path.push('');
  5779. }
  5780. } else if ('.' === buffer && '/' !== c && '\\' !== c) {
  5781. this._path.push('');
  5782. } else if ('.' !== buffer) {
  5783. if ('file' === this._scheme && this._path.length === 0 && buffer.length === 2 && ALPHA.test(buffer[0]) && buffer[1] === '|') {
  5784. buffer = buffer[0] + ':';
  5785. }
  5786. this._path.push(buffer);
  5787. }
  5788. buffer = '';
  5789. if ('?' === c) {
  5790. this._query = '?';
  5791. state = 'query';
  5792. } else if ('#' === c) {
  5793. this._fragment = '#';
  5794. state = 'fragment';
  5795. }
  5796. } else if ('\t' !== c && '\n' !== c && '\r' !== c) {
  5797. buffer += percentEscape(c);
  5798. }
  5799. break;
  5800. case 'query':
  5801. if (!stateOverride && '#' === c) {
  5802. this._fragment = '#';
  5803. state = 'fragment';
  5804. } else if (EOF !== c && '\t' !== c && '\n' !== c && '\r' !== c) {
  5805. this._query += percentEscapeQuery(c);
  5806. }
  5807. break;
  5808. case 'fragment':
  5809. if (EOF !== c && '\t' !== c && '\n' !== c && '\r' !== c) {
  5810. this._fragment += c;
  5811. }
  5812. break;
  5813. }
  5814. cursor++;
  5815. }
  5816. }
  5817. function clear() {
  5818. this._scheme = '';
  5819. this._schemeData = '';
  5820. this._username = '';
  5821. this._password = null;
  5822. this._host = '';
  5823. this._port = '';
  5824. this._path = [];
  5825. this._query = '';
  5826. this._fragment = '';
  5827. this._isInvalid = false;
  5828. this._isRelative = false;
  5829. }
  5830. // Does not process domain names or IP addresses.
  5831. // Does not handle encoding for the query parameter.
  5832. function JURL(url, base)
  5833. /* , encoding */
  5834. {
  5835. if (base !== undefined && !(base instanceof JURL)) {
  5836. base = new JURL(String(base));
  5837. }
  5838. this._url = url;
  5839. clear.call(this);
  5840. var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, '');
  5841. // encoding = encoding || 'utf-8'
  5842. parse.call(this, input, null, base);
  5843. }
  5844. JURL.prototype = {
  5845. toString: function () {
  5846. return this.href;
  5847. },
  5848. get href() {
  5849. if (this._isInvalid) {
  5850. return this._url;
  5851. }
  5852. var authority = '';
  5853. if ('' !== this._username || null !== this._password) {
  5854. authority = this._username + (null !== this._password ? ':' + this._password : '') + '@';
  5855. }
  5856. return this.protocol + (this._isRelative ? '//' + authority + this.host : '') + this.pathname + this._query + this._fragment;
  5857. },
  5858. set href(href) {
  5859. clear.call(this);
  5860. parse.call(this, href);
  5861. },
  5862. get protocol() {
  5863. return this._scheme + ':';
  5864. },
  5865. set protocol(protocol) {
  5866. if (this._isInvalid) {
  5867. return;
  5868. }
  5869. parse.call(this, protocol + ':', 'scheme start');
  5870. },
  5871. get host() {
  5872. return this._isInvalid ? '' : this._port ? this._host + ':' + this._port : this._host;
  5873. },
  5874. set host(host) {
  5875. if (this._isInvalid || !this._isRelative) {
  5876. return;
  5877. }
  5878. parse.call(this, host, 'host');
  5879. },
  5880. get hostname() {
  5881. return this._host;
  5882. },
  5883. set hostname(hostname) {
  5884. if (this._isInvalid || !this._isRelative) {
  5885. return;
  5886. }
  5887. parse.call(this, hostname, 'hostname');
  5888. },
  5889. get port() {
  5890. return this._port;
  5891. },
  5892. set port(port) {
  5893. if (this._isInvalid || !this._isRelative) {
  5894. return;
  5895. }
  5896. parse.call(this, port, 'port');
  5897. },
  5898. get pathname() {
  5899. return this._isInvalid ? '' : this._isRelative ? '/' + this._path.join('/') : this._schemeData;
  5900. },
  5901. set pathname(pathname) {
  5902. if (this._isInvalid || !this._isRelative) {
  5903. return;
  5904. }
  5905. this._path = [];
  5906. parse.call(this, pathname, 'relative path start');
  5907. },
  5908. get search() {
  5909. return this._isInvalid || !this._query || '?' === this._query ? '' : this._query;
  5910. },
  5911. set search(search) {
  5912. if (this._isInvalid || !this._isRelative) {
  5913. return;
  5914. }
  5915. this._query = '?';
  5916. if ('?' === search[0]) {
  5917. search = search.slice(1);
  5918. }
  5919. parse.call(this, search, 'query');
  5920. },
  5921. get hash() {
  5922. return this._isInvalid || !this._fragment || '#' === this._fragment ? '' : this._fragment;
  5923. },
  5924. set hash(hash) {
  5925. if (this._isInvalid) {
  5926. return;
  5927. }
  5928. this._fragment = '#';
  5929. if ('#' === hash[0]) {
  5930. hash = hash.slice(1);
  5931. }
  5932. parse.call(this, hash, 'fragment');
  5933. },
  5934. get origin() {
  5935. var host;
  5936. if (this._isInvalid || !this._scheme) {
  5937. return '';
  5938. }
  5939. // javascript: Gecko returns String(""), WebKit/Blink String("null")
  5940. // Gecko throws error for "data://"
  5941. // data: Gecko returns "", Blink returns "data://", WebKit returns "null"
  5942. // Gecko returns String("") for file: mailto:
  5943. // WebKit/Blink returns String("SCHEME://") for file: mailto:
  5944. switch (this._scheme) {
  5945. case 'data':
  5946. case 'file':
  5947. case 'javascript':
  5948. case 'mailto':
  5949. return 'null';
  5950. }
  5951. host = this.host;
  5952. if (!host) {
  5953. return '';
  5954. }
  5955. return this._scheme + '://' + host;
  5956. }
  5957. };
  5958. // Copy over the static methods
  5959. var OriginalURL = scope.URL;
  5960. if (OriginalURL) {
  5961. JURL.createObjectURL = function (blob) {
  5962. // IE extension allows a second optional options argument.
  5963. // http://msdn.microsoft.com/en-us/library/ie/hh772302(v=vs.85).aspx
  5964. return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
  5965. };
  5966. JURL.revokeObjectURL = function (url) {
  5967. OriginalURL.revokeObjectURL(url);
  5968. };
  5969. }
  5970. scope.URL = JURL;
  5971. }(globalScope));
  5972. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  5973. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  5974. exports.OPS = OPS;
  5975. exports.VERBOSITY_LEVELS = VERBOSITY_LEVELS;
  5976. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  5977. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  5978. exports.AnnotationFieldFlag = AnnotationFieldFlag;
  5979. exports.AnnotationFlag = AnnotationFlag;
  5980. exports.AnnotationType = AnnotationType;
  5981. exports.FontType = FontType;
  5982. exports.ImageKind = ImageKind;
  5983. exports.InvalidPDFException = InvalidPDFException;
  5984. exports.MessageHandler = MessageHandler;
  5985. exports.MissingDataException = MissingDataException;
  5986. exports.MissingPDFException = MissingPDFException;
  5987. exports.NotImplementedException = NotImplementedException;
  5988. exports.PageViewport = PageViewport;
  5989. exports.PasswordException = PasswordException;
  5990. exports.PasswordResponses = PasswordResponses;
  5991. exports.StatTimer = StatTimer;
  5992. exports.StreamType = StreamType;
  5993. exports.TextRenderingMode = TextRenderingMode;
  5994. exports.UnexpectedResponseException = UnexpectedResponseException;
  5995. exports.UnknownErrorException = UnknownErrorException;
  5996. exports.Util = Util;
  5997. exports.XRefParseException = XRefParseException;
  5998. exports.arrayByteLength = arrayByteLength;
  5999. exports.arraysToBytes = arraysToBytes;
  6000. exports.assert = assert;
  6001. exports.bytesToString = bytesToString;
  6002. exports.createBlob = createBlob;
  6003. exports.createPromiseCapability = createPromiseCapability;
  6004. exports.createObjectURL = createObjectURL;
  6005. exports.deprecated = deprecated;
  6006. exports.error = error;
  6007. exports.getLookupTableFactory = getLookupTableFactory;
  6008. exports.getVerbosityLevel = getVerbosityLevel;
  6009. exports.globalScope = globalScope;
  6010. exports.info = info;
  6011. exports.isArray = isArray;
  6012. exports.isArrayBuffer = isArrayBuffer;
  6013. exports.isBool = isBool;
  6014. exports.isEmptyObj = isEmptyObj;
  6015. exports.isInt = isInt;
  6016. exports.isNum = isNum;
  6017. exports.isString = isString;
  6018. exports.isSpace = isSpace;
  6019. exports.isSameOrigin = isSameOrigin;
  6020. exports.createValidAbsoluteUrl = createValidAbsoluteUrl;
  6021. exports.isLittleEndian = isLittleEndian;
  6022. exports.isEvalSupported = isEvalSupported;
  6023. exports.loadJpegStream = loadJpegStream;
  6024. exports.log2 = log2;
  6025. exports.readInt8 = readInt8;
  6026. exports.readUint16 = readUint16;
  6027. exports.readUint32 = readUint32;
  6028. exports.removeNullCharacters = removeNullCharacters;
  6029. exports.setVerbosityLevel = setVerbosityLevel;
  6030. exports.shadow = shadow;
  6031. exports.string32 = string32;
  6032. exports.stringToBytes = stringToBytes;
  6033. exports.stringToPDFString = stringToPDFString;
  6034. exports.stringToUTF8String = stringToUTF8String;
  6035. exports.utf8StringToString = utf8StringToString;
  6036. exports.warn = warn;
  6037. }));
  6038. (function (root, factory) {
  6039. factory(root.pdfjsCoreCFFParser = {}, root.pdfjsSharedUtil, root.pdfjsCoreCharsets, root.pdfjsCoreEncodings);
  6040. }(this, function (exports, sharedUtil, coreCharsets, coreEncodings) {
  6041. var error = sharedUtil.error;
  6042. var info = sharedUtil.info;
  6043. var bytesToString = sharedUtil.bytesToString;
  6044. var warn = sharedUtil.warn;
  6045. var isArray = sharedUtil.isArray;
  6046. var Util = sharedUtil.Util;
  6047. var stringToBytes = sharedUtil.stringToBytes;
  6048. var assert = sharedUtil.assert;
  6049. var ISOAdobeCharset = coreCharsets.ISOAdobeCharset;
  6050. var ExpertCharset = coreCharsets.ExpertCharset;
  6051. var ExpertSubsetCharset = coreCharsets.ExpertSubsetCharset;
  6052. var StandardEncoding = coreEncodings.StandardEncoding;
  6053. var ExpertEncoding = coreEncodings.ExpertEncoding;
  6054. // Maximum subroutine call depth of type 2 chartrings. Matches OTS.
  6055. var MAX_SUBR_NESTING = 10;
  6056. /**
  6057. * The CFF class takes a Type1 file and wrap it into a
  6058. * 'Compact Font Format' which itself embed Type2 charstrings.
  6059. */
  6060. var CFFStandardStrings = [
  6061. '.notdef',
  6062. 'space',
  6063. 'exclam',
  6064. 'quotedbl',
  6065. 'numbersign',
  6066. 'dollar',
  6067. 'percent',
  6068. 'ampersand',
  6069. 'quoteright',
  6070. 'parenleft',
  6071. 'parenright',
  6072. 'asterisk',
  6073. 'plus',
  6074. 'comma',
  6075. 'hyphen',
  6076. 'period',
  6077. 'slash',
  6078. 'zero',
  6079. 'one',
  6080. 'two',
  6081. 'three',
  6082. 'four',
  6083. 'five',
  6084. 'six',
  6085. 'seven',
  6086. 'eight',
  6087. 'nine',
  6088. 'colon',
  6089. 'semicolon',
  6090. 'less',
  6091. 'equal',
  6092. 'greater',
  6093. 'question',
  6094. 'at',
  6095. 'A',
  6096. 'B',
  6097. 'C',
  6098. 'D',
  6099. 'E',
  6100. 'F',
  6101. 'G',
  6102. 'H',
  6103. 'I',
  6104. 'J',
  6105. 'K',
  6106. 'L',
  6107. 'M',
  6108. 'N',
  6109. 'O',
  6110. 'P',
  6111. 'Q',
  6112. 'R',
  6113. 'S',
  6114. 'T',
  6115. 'U',
  6116. 'V',
  6117. 'W',
  6118. 'X',
  6119. 'Y',
  6120. 'Z',
  6121. 'bracketleft',
  6122. 'backslash',
  6123. 'bracketright',
  6124. 'asciicircum',
  6125. 'underscore',
  6126. 'quoteleft',
  6127. 'a',
  6128. 'b',
  6129. 'c',
  6130. 'd',
  6131. 'e',
  6132. 'f',
  6133. 'g',
  6134. 'h',
  6135. 'i',
  6136. 'j',
  6137. 'k',
  6138. 'l',
  6139. 'm',
  6140. 'n',
  6141. 'o',
  6142. 'p',
  6143. 'q',
  6144. 'r',
  6145. 's',
  6146. 't',
  6147. 'u',
  6148. 'v',
  6149. 'w',
  6150. 'x',
  6151. 'y',
  6152. 'z',
  6153. 'braceleft',
  6154. 'bar',
  6155. 'braceright',
  6156. 'asciitilde',
  6157. 'exclamdown',
  6158. 'cent',
  6159. 'sterling',
  6160. 'fraction',
  6161. 'yen',
  6162. 'florin',
  6163. 'section',
  6164. 'currency',
  6165. 'quotesingle',
  6166. 'quotedblleft',
  6167. 'guillemotleft',
  6168. 'guilsinglleft',
  6169. 'guilsinglright',
  6170. 'fi',
  6171. 'fl',
  6172. 'endash',
  6173. 'dagger',
  6174. 'daggerdbl',
  6175. 'periodcentered',
  6176. 'paragraph',
  6177. 'bullet',
  6178. 'quotesinglbase',
  6179. 'quotedblbase',
  6180. 'quotedblright',
  6181. 'guillemotright',
  6182. 'ellipsis',
  6183. 'perthousand',
  6184. 'questiondown',
  6185. 'grave',
  6186. 'acute',
  6187. 'circumflex',
  6188. 'tilde',
  6189. 'macron',
  6190. 'breve',
  6191. 'dotaccent',
  6192. 'dieresis',
  6193. 'ring',
  6194. 'cedilla',
  6195. 'hungarumlaut',
  6196. 'ogonek',
  6197. 'caron',
  6198. 'emdash',
  6199. 'AE',
  6200. 'ordfeminine',
  6201. 'Lslash',
  6202. 'Oslash',
  6203. 'OE',
  6204. 'ordmasculine',
  6205. 'ae',
  6206. 'dotlessi',
  6207. 'lslash',
  6208. 'oslash',
  6209. 'oe',
  6210. 'germandbls',
  6211. 'onesuperior',
  6212. 'logicalnot',
  6213. 'mu',
  6214. 'trademark',
  6215. 'Eth',
  6216. 'onehalf',
  6217. 'plusminus',
  6218. 'Thorn',
  6219. 'onequarter',
  6220. 'divide',
  6221. 'brokenbar',
  6222. 'degree',
  6223. 'thorn',
  6224. 'threequarters',
  6225. 'twosuperior',
  6226. 'registered',
  6227. 'minus',
  6228. 'eth',
  6229. 'multiply',
  6230. 'threesuperior',
  6231. 'copyright',
  6232. 'Aacute',
  6233. 'Acircumflex',
  6234. 'Adieresis',
  6235. 'Agrave',
  6236. 'Aring',
  6237. 'Atilde',
  6238. 'Ccedilla',
  6239. 'Eacute',
  6240. 'Ecircumflex',
  6241. 'Edieresis',
  6242. 'Egrave',
  6243. 'Iacute',
  6244. 'Icircumflex',
  6245. 'Idieresis',
  6246. 'Igrave',
  6247. 'Ntilde',
  6248. 'Oacute',
  6249. 'Ocircumflex',
  6250. 'Odieresis',
  6251. 'Ograve',
  6252. 'Otilde',
  6253. 'Scaron',
  6254. 'Uacute',
  6255. 'Ucircumflex',
  6256. 'Udieresis',
  6257. 'Ugrave',
  6258. 'Yacute',
  6259. 'Ydieresis',
  6260. 'Zcaron',
  6261. 'aacute',
  6262. 'acircumflex',
  6263. 'adieresis',
  6264. 'agrave',
  6265. 'aring',
  6266. 'atilde',
  6267. 'ccedilla',
  6268. 'eacute',
  6269. 'ecircumflex',
  6270. 'edieresis',
  6271. 'egrave',
  6272. 'iacute',
  6273. 'icircumflex',
  6274. 'idieresis',
  6275. 'igrave',
  6276. 'ntilde',
  6277. 'oacute',
  6278. 'ocircumflex',
  6279. 'odieresis',
  6280. 'ograve',
  6281. 'otilde',
  6282. 'scaron',
  6283. 'uacute',
  6284. 'ucircumflex',
  6285. 'udieresis',
  6286. 'ugrave',
  6287. 'yacute',
  6288. 'ydieresis',
  6289. 'zcaron',
  6290. 'exclamsmall',
  6291. 'Hungarumlautsmall',
  6292. 'dollaroldstyle',
  6293. 'dollarsuperior',
  6294. 'ampersandsmall',
  6295. 'Acutesmall',
  6296. 'parenleftsuperior',
  6297. 'parenrightsuperior',
  6298. 'twodotenleader',
  6299. 'onedotenleader',
  6300. 'zerooldstyle',
  6301. 'oneoldstyle',
  6302. 'twooldstyle',
  6303. 'threeoldstyle',
  6304. 'fouroldstyle',
  6305. 'fiveoldstyle',
  6306. 'sixoldstyle',
  6307. 'sevenoldstyle',
  6308. 'eightoldstyle',
  6309. 'nineoldstyle',
  6310. 'commasuperior',
  6311. 'threequartersemdash',
  6312. 'periodsuperior',
  6313. 'questionsmall',
  6314. 'asuperior',
  6315. 'bsuperior',
  6316. 'centsuperior',
  6317. 'dsuperior',
  6318. 'esuperior',
  6319. 'isuperior',
  6320. 'lsuperior',
  6321. 'msuperior',
  6322. 'nsuperior',
  6323. 'osuperior',
  6324. 'rsuperior',
  6325. 'ssuperior',
  6326. 'tsuperior',
  6327. 'ff',
  6328. 'ffi',
  6329. 'ffl',
  6330. 'parenleftinferior',
  6331. 'parenrightinferior',
  6332. 'Circumflexsmall',
  6333. 'hyphensuperior',
  6334. 'Gravesmall',
  6335. 'Asmall',
  6336. 'Bsmall',
  6337. 'Csmall',
  6338. 'Dsmall',
  6339. 'Esmall',
  6340. 'Fsmall',
  6341. 'Gsmall',
  6342. 'Hsmall',
  6343. 'Ismall',
  6344. 'Jsmall',
  6345. 'Ksmall',
  6346. 'Lsmall',
  6347. 'Msmall',
  6348. 'Nsmall',
  6349. 'Osmall',
  6350. 'Psmall',
  6351. 'Qsmall',
  6352. 'Rsmall',
  6353. 'Ssmall',
  6354. 'Tsmall',
  6355. 'Usmall',
  6356. 'Vsmall',
  6357. 'Wsmall',
  6358. 'Xsmall',
  6359. 'Ysmall',
  6360. 'Zsmall',
  6361. 'colonmonetary',
  6362. 'onefitted',
  6363. 'rupiah',
  6364. 'Tildesmall',
  6365. 'exclamdownsmall',
  6366. 'centoldstyle',
  6367. 'Lslashsmall',
  6368. 'Scaronsmall',
  6369. 'Zcaronsmall',
  6370. 'Dieresissmall',
  6371. 'Brevesmall',
  6372. 'Caronsmall',
  6373. 'Dotaccentsmall',
  6374. 'Macronsmall',
  6375. 'figuredash',
  6376. 'hypheninferior',
  6377. 'Ogoneksmall',
  6378. 'Ringsmall',
  6379. 'Cedillasmall',
  6380. 'questiondownsmall',
  6381. 'oneeighth',
  6382. 'threeeighths',
  6383. 'fiveeighths',
  6384. 'seveneighths',
  6385. 'onethird',
  6386. 'twothirds',
  6387. 'zerosuperior',
  6388. 'foursuperior',
  6389. 'fivesuperior',
  6390. 'sixsuperior',
  6391. 'sevensuperior',
  6392. 'eightsuperior',
  6393. 'ninesuperior',
  6394. 'zeroinferior',
  6395. 'oneinferior',
  6396. 'twoinferior',
  6397. 'threeinferior',
  6398. 'fourinferior',
  6399. 'fiveinferior',
  6400. 'sixinferior',
  6401. 'seveninferior',
  6402. 'eightinferior',
  6403. 'nineinferior',
  6404. 'centinferior',
  6405. 'dollarinferior',
  6406. 'periodinferior',
  6407. 'commainferior',
  6408. 'Agravesmall',
  6409. 'Aacutesmall',
  6410. 'Acircumflexsmall',
  6411. 'Atildesmall',
  6412. 'Adieresissmall',
  6413. 'Aringsmall',
  6414. 'AEsmall',
  6415. 'Ccedillasmall',
  6416. 'Egravesmall',
  6417. 'Eacutesmall',
  6418. 'Ecircumflexsmall',
  6419. 'Edieresissmall',
  6420. 'Igravesmall',
  6421. 'Iacutesmall',
  6422. 'Icircumflexsmall',
  6423. 'Idieresissmall',
  6424. 'Ethsmall',
  6425. 'Ntildesmall',
  6426. 'Ogravesmall',
  6427. 'Oacutesmall',
  6428. 'Ocircumflexsmall',
  6429. 'Otildesmall',
  6430. 'Odieresissmall',
  6431. 'OEsmall',
  6432. 'Oslashsmall',
  6433. 'Ugravesmall',
  6434. 'Uacutesmall',
  6435. 'Ucircumflexsmall',
  6436. 'Udieresissmall',
  6437. 'Yacutesmall',
  6438. 'Thornsmall',
  6439. 'Ydieresissmall',
  6440. '001.000',
  6441. '001.001',
  6442. '001.002',
  6443. '001.003',
  6444. 'Black',
  6445. 'Bold',
  6446. 'Book',
  6447. 'Light',
  6448. 'Medium',
  6449. 'Regular',
  6450. 'Roman',
  6451. 'Semibold'
  6452. ];
  6453. var CFFParser = function CFFParserClosure() {
  6454. var CharstringValidationData = [
  6455. null,
  6456. {
  6457. id: 'hstem',
  6458. min: 2,
  6459. stackClearing: true,
  6460. stem: true
  6461. },
  6462. null,
  6463. {
  6464. id: 'vstem',
  6465. min: 2,
  6466. stackClearing: true,
  6467. stem: true
  6468. },
  6469. {
  6470. id: 'vmoveto',
  6471. min: 1,
  6472. stackClearing: true
  6473. },
  6474. {
  6475. id: 'rlineto',
  6476. min: 2,
  6477. resetStack: true
  6478. },
  6479. {
  6480. id: 'hlineto',
  6481. min: 1,
  6482. resetStack: true
  6483. },
  6484. {
  6485. id: 'vlineto',
  6486. min: 1,
  6487. resetStack: true
  6488. },
  6489. {
  6490. id: 'rrcurveto',
  6491. min: 6,
  6492. resetStack: true
  6493. },
  6494. null,
  6495. {
  6496. id: 'callsubr',
  6497. min: 1,
  6498. undefStack: true
  6499. },
  6500. {
  6501. id: 'return',
  6502. min: 0,
  6503. undefStack: true
  6504. },
  6505. null,
  6506. // 12
  6507. null,
  6508. {
  6509. id: 'endchar',
  6510. min: 0,
  6511. stackClearing: true
  6512. },
  6513. null,
  6514. null,
  6515. null,
  6516. {
  6517. id: 'hstemhm',
  6518. min: 2,
  6519. stackClearing: true,
  6520. stem: true
  6521. },
  6522. {
  6523. id: 'hintmask',
  6524. min: 0,
  6525. stackClearing: true
  6526. },
  6527. {
  6528. id: 'cntrmask',
  6529. min: 0,
  6530. stackClearing: true
  6531. },
  6532. {
  6533. id: 'rmoveto',
  6534. min: 2,
  6535. stackClearing: true
  6536. },
  6537. {
  6538. id: 'hmoveto',
  6539. min: 1,
  6540. stackClearing: true
  6541. },
  6542. {
  6543. id: 'vstemhm',
  6544. min: 2,
  6545. stackClearing: true,
  6546. stem: true
  6547. },
  6548. {
  6549. id: 'rcurveline',
  6550. min: 8,
  6551. resetStack: true
  6552. },
  6553. {
  6554. id: 'rlinecurve',
  6555. min: 8,
  6556. resetStack: true
  6557. },
  6558. {
  6559. id: 'vvcurveto',
  6560. min: 4,
  6561. resetStack: true
  6562. },
  6563. {
  6564. id: 'hhcurveto',
  6565. min: 4,
  6566. resetStack: true
  6567. },
  6568. null,
  6569. // shortint
  6570. {
  6571. id: 'callgsubr',
  6572. min: 1,
  6573. undefStack: true
  6574. },
  6575. {
  6576. id: 'vhcurveto',
  6577. min: 4,
  6578. resetStack: true
  6579. },
  6580. {
  6581. id: 'hvcurveto',
  6582. min: 4,
  6583. resetStack: true
  6584. }
  6585. ];
  6586. var CharstringValidationData12 = [
  6587. null,
  6588. null,
  6589. null,
  6590. {
  6591. id: 'and',
  6592. min: 2,
  6593. stackDelta: -1
  6594. },
  6595. {
  6596. id: 'or',
  6597. min: 2,
  6598. stackDelta: -1
  6599. },
  6600. {
  6601. id: 'not',
  6602. min: 1,
  6603. stackDelta: 0
  6604. },
  6605. null,
  6606. null,
  6607. null,
  6608. {
  6609. id: 'abs',
  6610. min: 1,
  6611. stackDelta: 0
  6612. },
  6613. {
  6614. id: 'add',
  6615. min: 2,
  6616. stackDelta: -1,
  6617. stackFn: function stack_div(stack, index) {
  6618. stack[index - 2] = stack[index - 2] + stack[index - 1];
  6619. }
  6620. },
  6621. {
  6622. id: 'sub',
  6623. min: 2,
  6624. stackDelta: -1,
  6625. stackFn: function stack_div(stack, index) {
  6626. stack[index - 2] = stack[index - 2] - stack[index - 1];
  6627. }
  6628. },
  6629. {
  6630. id: 'div',
  6631. min: 2,
  6632. stackDelta: -1,
  6633. stackFn: function stack_div(stack, index) {
  6634. stack[index - 2] = stack[index - 2] / stack[index - 1];
  6635. }
  6636. },
  6637. null,
  6638. {
  6639. id: 'neg',
  6640. min: 1,
  6641. stackDelta: 0,
  6642. stackFn: function stack_div(stack, index) {
  6643. stack[index - 1] = -stack[index - 1];
  6644. }
  6645. },
  6646. {
  6647. id: 'eq',
  6648. min: 2,
  6649. stackDelta: -1
  6650. },
  6651. null,
  6652. null,
  6653. {
  6654. id: 'drop',
  6655. min: 1,
  6656. stackDelta: -1
  6657. },
  6658. null,
  6659. {
  6660. id: 'put',
  6661. min: 2,
  6662. stackDelta: -2
  6663. },
  6664. {
  6665. id: 'get',
  6666. min: 1,
  6667. stackDelta: 0
  6668. },
  6669. {
  6670. id: 'ifelse',
  6671. min: 4,
  6672. stackDelta: -3
  6673. },
  6674. {
  6675. id: 'random',
  6676. min: 0,
  6677. stackDelta: 1
  6678. },
  6679. {
  6680. id: 'mul',
  6681. min: 2,
  6682. stackDelta: -1,
  6683. stackFn: function stack_div(stack, index) {
  6684. stack[index - 2] = stack[index - 2] * stack[index - 1];
  6685. }
  6686. },
  6687. null,
  6688. {
  6689. id: 'sqrt',
  6690. min: 1,
  6691. stackDelta: 0
  6692. },
  6693. {
  6694. id: 'dup',
  6695. min: 1,
  6696. stackDelta: 1
  6697. },
  6698. {
  6699. id: 'exch',
  6700. min: 2,
  6701. stackDelta: 0
  6702. },
  6703. {
  6704. id: 'index',
  6705. min: 2,
  6706. stackDelta: 0
  6707. },
  6708. {
  6709. id: 'roll',
  6710. min: 3,
  6711. stackDelta: -2
  6712. },
  6713. null,
  6714. null,
  6715. null,
  6716. {
  6717. id: 'hflex',
  6718. min: 7,
  6719. resetStack: true
  6720. },
  6721. {
  6722. id: 'flex',
  6723. min: 13,
  6724. resetStack: true
  6725. },
  6726. {
  6727. id: 'hflex1',
  6728. min: 9,
  6729. resetStack: true
  6730. },
  6731. {
  6732. id: 'flex1',
  6733. min: 11,
  6734. resetStack: true
  6735. }
  6736. ];
  6737. function CFFParser(file, properties, seacAnalysisEnabled) {
  6738. this.bytes = file.getBytes();
  6739. this.properties = properties;
  6740. this.seacAnalysisEnabled = !!seacAnalysisEnabled;
  6741. }
  6742. CFFParser.prototype = {
  6743. parse: function CFFParser_parse() {
  6744. var properties = this.properties;
  6745. var cff = new CFF();
  6746. this.cff = cff;
  6747. // The first five sections must be in order, all the others are reached
  6748. // via offsets contained in one of the below.
  6749. var header = this.parseHeader();
  6750. var nameIndex = this.parseIndex(header.endPos);
  6751. var topDictIndex = this.parseIndex(nameIndex.endPos);
  6752. var stringIndex = this.parseIndex(topDictIndex.endPos);
  6753. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  6754. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  6755. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  6756. cff.header = header.obj;
  6757. cff.names = this.parseNameIndex(nameIndex.obj);
  6758. cff.strings = this.parseStringIndex(stringIndex.obj);
  6759. cff.topDict = topDict;
  6760. cff.globalSubrIndex = globalSubrIndex.obj;
  6761. this.parsePrivateDict(cff.topDict);
  6762. cff.isCIDFont = topDict.hasName('ROS');
  6763. var charStringOffset = topDict.getByName('CharStrings');
  6764. var charStringIndex = this.parseIndex(charStringOffset).obj;
  6765. var fontMatrix = topDict.getByName('FontMatrix');
  6766. if (fontMatrix) {
  6767. properties.fontMatrix = fontMatrix;
  6768. }
  6769. var fontBBox = topDict.getByName('FontBBox');
  6770. if (fontBBox) {
  6771. // adjusting ascent/descent
  6772. properties.ascent = fontBBox[3];
  6773. properties.descent = fontBBox[1];
  6774. properties.ascentScaled = true;
  6775. }
  6776. var charset, encoding;
  6777. if (cff.isCIDFont) {
  6778. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  6779. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  6780. var dictRaw = fdArrayIndex.get(i);
  6781. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw), cff.strings);
  6782. this.parsePrivateDict(fontDict);
  6783. cff.fdArray.push(fontDict);
  6784. }
  6785. // cid fonts don't have an encoding
  6786. encoding = null;
  6787. charset = this.parseCharsets(topDict.getByName('charset'), charStringIndex.count, cff.strings, true);
  6788. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'), charStringIndex.count);
  6789. } else {
  6790. charset = this.parseCharsets(topDict.getByName('charset'), charStringIndex.count, cff.strings, false);
  6791. encoding = this.parseEncoding(topDict.getByName('Encoding'), properties, cff.strings, charset.charset);
  6792. }
  6793. cff.charset = charset;
  6794. cff.encoding = encoding;
  6795. var charStringsAndSeacs = this.parseCharStrings(charStringIndex, topDict.privateDict.subrsIndex, globalSubrIndex.obj, cff.fdSelect, cff.fdArray);
  6796. cff.charStrings = charStringsAndSeacs.charStrings;
  6797. cff.seacs = charStringsAndSeacs.seacs;
  6798. cff.widths = charStringsAndSeacs.widths;
  6799. return cff;
  6800. },
  6801. parseHeader: function CFFParser_parseHeader() {
  6802. var bytes = this.bytes;
  6803. var bytesLength = bytes.length;
  6804. var offset = 0;
  6805. // Prevent an infinite loop, by checking that the offset is within the
  6806. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  6807. while (offset < bytesLength && bytes[offset] !== 1) {
  6808. ++offset;
  6809. }
  6810. if (offset >= bytesLength) {
  6811. error('Invalid CFF header');
  6812. } else if (offset !== 0) {
  6813. info('cff data is shifted');
  6814. bytes = bytes.subarray(offset);
  6815. this.bytes = bytes;
  6816. }
  6817. var major = bytes[0];
  6818. var minor = bytes[1];
  6819. var hdrSize = bytes[2];
  6820. var offSize = bytes[3];
  6821. var header = new CFFHeader(major, minor, hdrSize, offSize);
  6822. return {
  6823. obj: header,
  6824. endPos: hdrSize
  6825. };
  6826. },
  6827. parseDict: function CFFParser_parseDict(dict) {
  6828. var pos = 0;
  6829. function parseOperand() {
  6830. var value = dict[pos++];
  6831. if (value === 30) {
  6832. return parseFloatOperand();
  6833. } else if (value === 28) {
  6834. value = dict[pos++];
  6835. value = (value << 24 | dict[pos++] << 16) >> 16;
  6836. return value;
  6837. } else if (value === 29) {
  6838. value = dict[pos++];
  6839. value = value << 8 | dict[pos++];
  6840. value = value << 8 | dict[pos++];
  6841. value = value << 8 | dict[pos++];
  6842. return value;
  6843. } else if (value >= 32 && value <= 246) {
  6844. return value - 139;
  6845. } else if (value >= 247 && value <= 250) {
  6846. return (value - 247) * 256 + dict[pos++] + 108;
  6847. } else if (value >= 251 && value <= 254) {
  6848. return -((value - 251) * 256) - dict[pos++] - 108;
  6849. } else {
  6850. warn('CFFParser_parseDict: "' + value + '" is a reserved command.');
  6851. return NaN;
  6852. }
  6853. }
  6854. function parseFloatOperand() {
  6855. var str = '';
  6856. var eof = 15;
  6857. var lookup = [
  6858. '0',
  6859. '1',
  6860. '2',
  6861. '3',
  6862. '4',
  6863. '5',
  6864. '6',
  6865. '7',
  6866. '8',
  6867. '9',
  6868. '.',
  6869. 'E',
  6870. 'E-',
  6871. null,
  6872. '-'
  6873. ];
  6874. var length = dict.length;
  6875. while (pos < length) {
  6876. var b = dict[pos++];
  6877. var b1 = b >> 4;
  6878. var b2 = b & 15;
  6879. if (b1 === eof) {
  6880. break;
  6881. }
  6882. str += lookup[b1];
  6883. if (b2 === eof) {
  6884. break;
  6885. }
  6886. str += lookup[b2];
  6887. }
  6888. return parseFloat(str);
  6889. }
  6890. var operands = [];
  6891. var entries = [];
  6892. pos = 0;
  6893. var end = dict.length;
  6894. while (pos < end) {
  6895. var b = dict[pos];
  6896. if (b <= 21) {
  6897. if (b === 12) {
  6898. b = b << 8 | dict[++pos];
  6899. }
  6900. entries.push([
  6901. b,
  6902. operands
  6903. ]);
  6904. operands = [];
  6905. ++pos;
  6906. } else {
  6907. operands.push(parseOperand());
  6908. }
  6909. }
  6910. return entries;
  6911. },
  6912. parseIndex: function CFFParser_parseIndex(pos) {
  6913. var cffIndex = new CFFIndex();
  6914. var bytes = this.bytes;
  6915. var count = bytes[pos++] << 8 | bytes[pos++];
  6916. var offsets = [];
  6917. var end = pos;
  6918. var i, ii;
  6919. if (count !== 0) {
  6920. var offsetSize = bytes[pos++];
  6921. // add 1 for offset to determine size of last object
  6922. var startPos = pos + (count + 1) * offsetSize - 1;
  6923. for (i = 0, ii = count + 1; i < ii; ++i) {
  6924. var offset = 0;
  6925. for (var j = 0; j < offsetSize; ++j) {
  6926. offset <<= 8;
  6927. offset += bytes[pos++];
  6928. }
  6929. offsets.push(startPos + offset);
  6930. }
  6931. end = offsets[count];
  6932. }
  6933. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  6934. var offsetStart = offsets[i];
  6935. var offsetEnd = offsets[i + 1];
  6936. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  6937. }
  6938. return {
  6939. obj: cffIndex,
  6940. endPos: end
  6941. };
  6942. },
  6943. parseNameIndex: function CFFParser_parseNameIndex(index) {
  6944. var names = [];
  6945. for (var i = 0, ii = index.count; i < ii; ++i) {
  6946. var name = index.get(i);
  6947. // OTS doesn't allow names to be over 127 characters.
  6948. var length = Math.min(name.length, 127);
  6949. var data = [];
  6950. // OTS also only permits certain characters in the name.
  6951. for (var j = 0; j < length; ++j) {
  6952. var c = name[j];
  6953. if (j === 0 && c === 0) {
  6954. data[j] = c;
  6955. continue;
  6956. }
  6957. if (c < 33 || c > 126 || c === 91 || /* [ */
  6958. c === 93 || /* ] */
  6959. c === 40 || /* ( */
  6960. c === 41 || /* ) */
  6961. c === 123 || /* { */
  6962. c === 125 || /* } */
  6963. c === 60 || /* < */
  6964. c === 62 || /* > */
  6965. c === 47 || /* / */
  6966. c === 37 || /* % */
  6967. c === 35)
  6968. /* # */
  6969. {
  6970. data[j] = 95;
  6971. continue;
  6972. }
  6973. data[j] = c;
  6974. }
  6975. names.push(bytesToString(data));
  6976. }
  6977. return names;
  6978. },
  6979. parseStringIndex: function CFFParser_parseStringIndex(index) {
  6980. var strings = new CFFStrings();
  6981. for (var i = 0, ii = index.count; i < ii; ++i) {
  6982. var data = index.get(i);
  6983. strings.add(bytesToString(data));
  6984. }
  6985. return strings;
  6986. },
  6987. createDict: function CFFParser_createDict(Type, dict, strings) {
  6988. var cffDict = new Type(strings);
  6989. for (var i = 0, ii = dict.length; i < ii; ++i) {
  6990. var pair = dict[i];
  6991. var key = pair[0];
  6992. var value = pair[1];
  6993. cffDict.setByKey(key, value);
  6994. }
  6995. return cffDict;
  6996. },
  6997. parseCharString: function CFFParser_parseCharString(state, data, localSubrIndex, globalSubrIndex) {
  6998. if (state.callDepth > MAX_SUBR_NESTING) {
  6999. return false;
  7000. }
  7001. var stackSize = state.stackSize;
  7002. var stack = state.stack;
  7003. var length = data.length;
  7004. for (var j = 0; j < length;) {
  7005. var value = data[j++];
  7006. var validationCommand = null;
  7007. if (value === 12) {
  7008. var q = data[j++];
  7009. if (q === 0) {
  7010. // The CFF specification state that the 'dotsection' command
  7011. // (12, 0) is deprecated and treated as a no-op, but all Type2
  7012. // charstrings processors should support them. Unfortunately
  7013. // the font sanitizer don't. As a workaround the sequence (12, 0)
  7014. // is replaced by a useless (0, hmoveto).
  7015. data[j - 2] = 139;
  7016. data[j - 1] = 22;
  7017. stackSize = 0;
  7018. } else {
  7019. validationCommand = CharstringValidationData12[q];
  7020. }
  7021. } else if (value === 28) {
  7022. // number (16 bit)
  7023. stack[stackSize] = (data[j] << 24 | data[j + 1] << 16) >> 16;
  7024. j += 2;
  7025. stackSize++;
  7026. } else if (value === 14) {
  7027. if (stackSize >= 4) {
  7028. stackSize -= 4;
  7029. if (this.seacAnalysisEnabled) {
  7030. state.seac = stack.slice(stackSize, stackSize + 4);
  7031. return false;
  7032. }
  7033. }
  7034. validationCommand = CharstringValidationData[value];
  7035. } else if (value >= 32 && value <= 246) {
  7036. // number
  7037. stack[stackSize] = value - 139;
  7038. stackSize++;
  7039. } else if (value >= 247 && value <= 254) {
  7040. // number (+1 bytes)
  7041. stack[stackSize] = value < 251 ? (value - 247 << 8) + data[j] + 108 : -(value - 251 << 8) - data[j] - 108;
  7042. j++;
  7043. stackSize++;
  7044. } else if (value === 255) {
  7045. // number (32 bit)
  7046. stack[stackSize] = (data[j] << 24 | data[j + 1] << 16 | data[j + 2] << 8 | data[j + 3]) / 65536;
  7047. j += 4;
  7048. stackSize++;
  7049. } else if (value === 19 || value === 20) {
  7050. state.hints += stackSize >> 1;
  7051. // skipping right amount of hints flag data
  7052. j += state.hints + 7 >> 3;
  7053. stackSize %= 2;
  7054. validationCommand = CharstringValidationData[value];
  7055. } else if (value === 10 || value === 29) {
  7056. var subrsIndex;
  7057. if (value === 10) {
  7058. subrsIndex = localSubrIndex;
  7059. } else {
  7060. subrsIndex = globalSubrIndex;
  7061. }
  7062. if (!subrsIndex) {
  7063. validationCommand = CharstringValidationData[value];
  7064. warn('Missing subrsIndex for ' + validationCommand.id);
  7065. return false;
  7066. }
  7067. var bias = 32768;
  7068. if (subrsIndex.count < 1240) {
  7069. bias = 107;
  7070. } else if (subrsIndex.count < 33900) {
  7071. bias = 1131;
  7072. }
  7073. var subrNumber = stack[--stackSize] + bias;
  7074. if (subrNumber < 0 || subrNumber >= subrsIndex.count) {
  7075. validationCommand = CharstringValidationData[value];
  7076. warn('Out of bounds subrIndex for ' + validationCommand.id);
  7077. return false;
  7078. }
  7079. state.stackSize = stackSize;
  7080. state.callDepth++;
  7081. var valid = this.parseCharString(state, subrsIndex.get(subrNumber), localSubrIndex, globalSubrIndex);
  7082. if (!valid) {
  7083. return false;
  7084. }
  7085. state.callDepth--;
  7086. stackSize = state.stackSize;
  7087. continue;
  7088. } else if (value === 11) {
  7089. state.stackSize = stackSize;
  7090. return true;
  7091. } else {
  7092. validationCommand = CharstringValidationData[value];
  7093. }
  7094. if (validationCommand) {
  7095. if (validationCommand.stem) {
  7096. state.hints += stackSize >> 1;
  7097. }
  7098. if ('min' in validationCommand) {
  7099. if (!state.undefStack && stackSize < validationCommand.min) {
  7100. warn('Not enough parameters for ' + validationCommand.id + '; actual: ' + stackSize + ', expected: ' + validationCommand.min);
  7101. return false;
  7102. }
  7103. }
  7104. if (state.firstStackClearing && validationCommand.stackClearing) {
  7105. state.firstStackClearing = false;
  7106. // the optional character width can be found before the first
  7107. // stack-clearing command arguments
  7108. stackSize -= validationCommand.min;
  7109. if (stackSize >= 2 && validationCommand.stem) {
  7110. // there are even amount of arguments for stem commands
  7111. stackSize %= 2;
  7112. } else if (stackSize > 1) {
  7113. warn('Found too many parameters for stack-clearing command');
  7114. }
  7115. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  7116. state.width = stack[stackSize - 1];
  7117. }
  7118. }
  7119. if ('stackDelta' in validationCommand) {
  7120. if ('stackFn' in validationCommand) {
  7121. validationCommand.stackFn(stack, stackSize);
  7122. }
  7123. stackSize += validationCommand.stackDelta;
  7124. } else if (validationCommand.stackClearing) {
  7125. stackSize = 0;
  7126. } else if (validationCommand.resetStack) {
  7127. stackSize = 0;
  7128. state.undefStack = false;
  7129. } else if (validationCommand.undefStack) {
  7130. stackSize = 0;
  7131. state.undefStack = true;
  7132. state.firstStackClearing = false;
  7133. }
  7134. }
  7135. }
  7136. state.stackSize = stackSize;
  7137. return true;
  7138. },
  7139. parseCharStrings: function CFFParser_parseCharStrings(charStrings, localSubrIndex, globalSubrIndex, fdSelect, fdArray) {
  7140. var seacs = [];
  7141. var widths = [];
  7142. var count = charStrings.count;
  7143. for (var i = 0; i < count; i++) {
  7144. var charstring = charStrings.get(i);
  7145. var state = {
  7146. callDepth: 0,
  7147. stackSize: 0,
  7148. stack: [],
  7149. undefStack: true,
  7150. hints: 0,
  7151. firstStackClearing: true,
  7152. seac: null,
  7153. width: null
  7154. };
  7155. var valid = true;
  7156. var localSubrToUse = null;
  7157. if (fdSelect && fdArray.length) {
  7158. var fdIndex = fdSelect.getFDIndex(i);
  7159. if (fdIndex === -1) {
  7160. warn('Glyph index is not in fd select.');
  7161. valid = false;
  7162. }
  7163. if (fdIndex >= fdArray.length) {
  7164. warn('Invalid fd index for glyph index.');
  7165. valid = false;
  7166. }
  7167. if (valid) {
  7168. localSubrToUse = fdArray[fdIndex].privateDict.subrsIndex;
  7169. }
  7170. } else if (localSubrIndex) {
  7171. localSubrToUse = localSubrIndex;
  7172. }
  7173. if (valid) {
  7174. valid = this.parseCharString(state, charstring, localSubrToUse, globalSubrIndex);
  7175. }
  7176. if (state.width !== null) {
  7177. widths[i] = state.width;
  7178. }
  7179. if (state.seac !== null) {
  7180. seacs[i] = state.seac;
  7181. }
  7182. if (!valid) {
  7183. // resetting invalid charstring to single 'endchar'
  7184. charStrings.set(i, new Uint8Array([14]));
  7185. }
  7186. }
  7187. return {
  7188. charStrings: charStrings,
  7189. seacs: seacs,
  7190. widths: widths
  7191. };
  7192. },
  7193. emptyPrivateDictionary: function CFFParser_emptyPrivateDictionary(parentDict) {
  7194. var privateDict = this.createDict(CFFPrivateDict, [], parentDict.strings);
  7195. parentDict.setByKey(18, [
  7196. 0,
  7197. 0
  7198. ]);
  7199. parentDict.privateDict = privateDict;
  7200. },
  7201. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  7202. // no private dict, do nothing
  7203. if (!parentDict.hasName('Private')) {
  7204. this.emptyPrivateDictionary(parentDict);
  7205. return;
  7206. }
  7207. var privateOffset = parentDict.getByName('Private');
  7208. // make sure the params are formatted correctly
  7209. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  7210. parentDict.removeByName('Private');
  7211. return;
  7212. }
  7213. var size = privateOffset[0];
  7214. var offset = privateOffset[1];
  7215. // remove empty dicts or ones that refer to invalid location
  7216. if (size === 0 || offset >= this.bytes.length) {
  7217. this.emptyPrivateDictionary(parentDict);
  7218. return;
  7219. }
  7220. var privateDictEnd = offset + size;
  7221. var dictData = this.bytes.subarray(offset, privateDictEnd);
  7222. var dict = this.parseDict(dictData);
  7223. var privateDict = this.createDict(CFFPrivateDict, dict, parentDict.strings);
  7224. parentDict.privateDict = privateDict;
  7225. // Parse the Subrs index also since it's relative to the private dict.
  7226. if (!privateDict.getByName('Subrs')) {
  7227. return;
  7228. }
  7229. var subrsOffset = privateDict.getByName('Subrs');
  7230. var relativeOffset = offset + subrsOffset;
  7231. // Validate the offset.
  7232. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  7233. this.emptyPrivateDictionary(parentDict);
  7234. return;
  7235. }
  7236. var subrsIndex = this.parseIndex(relativeOffset);
  7237. privateDict.subrsIndex = subrsIndex.obj;
  7238. },
  7239. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  7240. if (pos === 0) {
  7241. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE, ISOAdobeCharset);
  7242. } else if (pos === 1) {
  7243. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT, ExpertCharset);
  7244. } else if (pos === 2) {
  7245. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET, ExpertSubsetCharset);
  7246. }
  7247. var bytes = this.bytes;
  7248. var start = pos;
  7249. var format = bytes[pos++];
  7250. var charset = ['.notdef'];
  7251. var id, count, i;
  7252. // subtract 1 for the .notdef glyph
  7253. length -= 1;
  7254. switch (format) {
  7255. case 0:
  7256. for (i = 0; i < length; i++) {
  7257. id = bytes[pos++] << 8 | bytes[pos++];
  7258. charset.push(cid ? id : strings.get(id));
  7259. }
  7260. break;
  7261. case 1:
  7262. while (charset.length <= length) {
  7263. id = bytes[pos++] << 8 | bytes[pos++];
  7264. count = bytes[pos++];
  7265. for (i = 0; i <= count; i++) {
  7266. charset.push(cid ? id++ : strings.get(id++));
  7267. }
  7268. }
  7269. break;
  7270. case 2:
  7271. while (charset.length <= length) {
  7272. id = bytes[pos++] << 8 | bytes[pos++];
  7273. count = bytes[pos++] << 8 | bytes[pos++];
  7274. for (i = 0; i <= count; i++) {
  7275. charset.push(cid ? id++ : strings.get(id++));
  7276. }
  7277. }
  7278. break;
  7279. default:
  7280. error('Unknown charset format');
  7281. }
  7282. // Raw won't be needed if we actually compile the charset.
  7283. var end = pos;
  7284. var raw = bytes.subarray(start, end);
  7285. return new CFFCharset(false, format, charset, raw);
  7286. },
  7287. parseEncoding: function CFFParser_parseEncoding(pos, properties, strings, charset) {
  7288. var encoding = Object.create(null);
  7289. var bytes = this.bytes;
  7290. var predefined = false;
  7291. var hasSupplement = false;
  7292. var format, i, ii;
  7293. var raw = null;
  7294. function readSupplement() {
  7295. var supplementsCount = bytes[pos++];
  7296. for (i = 0; i < supplementsCount; i++) {
  7297. var code = bytes[pos++];
  7298. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  7299. encoding[code] = charset.indexOf(strings.get(sid));
  7300. }
  7301. }
  7302. if (pos === 0 || pos === 1) {
  7303. predefined = true;
  7304. format = pos;
  7305. var baseEncoding = pos ? ExpertEncoding : StandardEncoding;
  7306. for (i = 0, ii = charset.length; i < ii; i++) {
  7307. var index = baseEncoding.indexOf(charset[i]);
  7308. if (index !== -1) {
  7309. encoding[index] = i;
  7310. }
  7311. }
  7312. } else {
  7313. var dataStart = pos;
  7314. format = bytes[pos++];
  7315. switch (format & 0x7f) {
  7316. case 0:
  7317. var glyphsCount = bytes[pos++];
  7318. for (i = 1; i <= glyphsCount; i++) {
  7319. encoding[bytes[pos++]] = i;
  7320. }
  7321. break;
  7322. case 1:
  7323. var rangesCount = bytes[pos++];
  7324. var gid = 1;
  7325. for (i = 0; i < rangesCount; i++) {
  7326. var start = bytes[pos++];
  7327. var left = bytes[pos++];
  7328. for (var j = start; j <= start + left; j++) {
  7329. encoding[j] = gid++;
  7330. }
  7331. }
  7332. break;
  7333. default:
  7334. error('Unknown encoding format: ' + format + ' in CFF');
  7335. break;
  7336. }
  7337. var dataEnd = pos;
  7338. if (format & 0x80) {
  7339. // The font sanitizer does not support CFF encoding with a
  7340. // supplement, since the encoding is not really used to map
  7341. // between gid to glyph, let's overwrite what is declared in
  7342. // the top dictionary to let the sanitizer think the font use
  7343. // StandardEncoding, that's a lie but that's ok.
  7344. bytes[dataStart] &= 0x7f;
  7345. readSupplement();
  7346. hasSupplement = true;
  7347. }
  7348. raw = bytes.subarray(dataStart, dataEnd);
  7349. }
  7350. format = format & 0x7f;
  7351. return new CFFEncoding(predefined, format, encoding, raw);
  7352. },
  7353. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  7354. var start = pos;
  7355. var bytes = this.bytes;
  7356. var format = bytes[pos++];
  7357. var fdSelect = [], rawBytes;
  7358. var i, invalidFirstGID = false;
  7359. switch (format) {
  7360. case 0:
  7361. for (i = 0; i < length; ++i) {
  7362. var id = bytes[pos++];
  7363. fdSelect.push(id);
  7364. }
  7365. rawBytes = bytes.subarray(start, pos);
  7366. break;
  7367. case 3:
  7368. var rangesCount = bytes[pos++] << 8 | bytes[pos++];
  7369. for (i = 0; i < rangesCount; ++i) {
  7370. var first = bytes[pos++] << 8 | bytes[pos++];
  7371. if (i === 0 && first !== 0) {
  7372. warn('parseFDSelect: The first range must have a first GID of 0' + ' -- trying to recover.');
  7373. invalidFirstGID = true;
  7374. first = 0;
  7375. }
  7376. var fdIndex = bytes[pos++];
  7377. var next = bytes[pos] << 8 | bytes[pos + 1];
  7378. for (var j = first; j < next; ++j) {
  7379. fdSelect.push(fdIndex);
  7380. }
  7381. }
  7382. // Advance past the sentinel(next).
  7383. pos += 2;
  7384. rawBytes = bytes.subarray(start, pos);
  7385. if (invalidFirstGID) {
  7386. rawBytes[3] = rawBytes[4] = 0;
  7387. }
  7388. // Adjust the first range, first GID.
  7389. break;
  7390. default:
  7391. error('parseFDSelect: Unknown format "' + format + '".');
  7392. break;
  7393. }
  7394. assert(fdSelect.length === length, 'parseFDSelect: Invalid font data.');
  7395. return new CFFFDSelect(fdSelect, rawBytes);
  7396. }
  7397. };
  7398. return CFFParser;
  7399. }();
  7400. // Compact Font Format
  7401. var CFF = function CFFClosure() {
  7402. function CFF() {
  7403. this.header = null;
  7404. this.names = [];
  7405. this.topDict = null;
  7406. this.strings = new CFFStrings();
  7407. this.globalSubrIndex = null;
  7408. // The following could really be per font, but since we only have one font
  7409. // store them here.
  7410. this.encoding = null;
  7411. this.charset = null;
  7412. this.charStrings = null;
  7413. this.fdArray = [];
  7414. this.fdSelect = null;
  7415. this.isCIDFont = false;
  7416. }
  7417. return CFF;
  7418. }();
  7419. var CFFHeader = function CFFHeaderClosure() {
  7420. function CFFHeader(major, minor, hdrSize, offSize) {
  7421. this.major = major;
  7422. this.minor = minor;
  7423. this.hdrSize = hdrSize;
  7424. this.offSize = offSize;
  7425. }
  7426. return CFFHeader;
  7427. }();
  7428. var CFFStrings = function CFFStringsClosure() {
  7429. function CFFStrings() {
  7430. this.strings = [];
  7431. }
  7432. CFFStrings.prototype = {
  7433. get: function CFFStrings_get(index) {
  7434. if (index >= 0 && index <= 390) {
  7435. return CFFStandardStrings[index];
  7436. }
  7437. if (index - 391 <= this.strings.length) {
  7438. return this.strings[index - 391];
  7439. }
  7440. return CFFStandardStrings[0];
  7441. },
  7442. add: function CFFStrings_add(value) {
  7443. this.strings.push(value);
  7444. },
  7445. get count() {
  7446. return this.strings.length;
  7447. }
  7448. };
  7449. return CFFStrings;
  7450. }();
  7451. var CFFIndex = function CFFIndexClosure() {
  7452. function CFFIndex() {
  7453. this.objects = [];
  7454. this.length = 0;
  7455. }
  7456. CFFIndex.prototype = {
  7457. add: function CFFIndex_add(data) {
  7458. this.length += data.length;
  7459. this.objects.push(data);
  7460. },
  7461. set: function CFFIndex_set(index, data) {
  7462. this.length += data.length - this.objects[index].length;
  7463. this.objects[index] = data;
  7464. },
  7465. get: function CFFIndex_get(index) {
  7466. return this.objects[index];
  7467. },
  7468. get count() {
  7469. return this.objects.length;
  7470. }
  7471. };
  7472. return CFFIndex;
  7473. }();
  7474. var CFFDict = function CFFDictClosure() {
  7475. function CFFDict(tables, strings) {
  7476. this.keyToNameMap = tables.keyToNameMap;
  7477. this.nameToKeyMap = tables.nameToKeyMap;
  7478. this.defaults = tables.defaults;
  7479. this.types = tables.types;
  7480. this.opcodes = tables.opcodes;
  7481. this.order = tables.order;
  7482. this.strings = strings;
  7483. this.values = Object.create(null);
  7484. }
  7485. CFFDict.prototype = {
  7486. // value should always be an array
  7487. setByKey: function CFFDict_setByKey(key, value) {
  7488. if (!(key in this.keyToNameMap)) {
  7489. return false;
  7490. }
  7491. var valueLength = value.length;
  7492. // ignore empty values
  7493. if (valueLength === 0) {
  7494. return true;
  7495. }
  7496. // Ignore invalid values (fixes bug1068432.pdf and bug1308536.pdf).
  7497. for (var i = 0; i < valueLength; i++) {
  7498. if (isNaN(value[i])) {
  7499. warn('Invalid CFFDict value: "' + value + '" for key "' + key + '".');
  7500. return true;
  7501. }
  7502. }
  7503. var type = this.types[key];
  7504. // remove the array wrapping these types of values
  7505. if (type === 'num' || type === 'sid' || type === 'offset') {
  7506. value = value[0];
  7507. }
  7508. this.values[key] = value;
  7509. return true;
  7510. },
  7511. setByName: function CFFDict_setByName(name, value) {
  7512. if (!(name in this.nameToKeyMap)) {
  7513. error('Invalid dictionary name "' + name + '"');
  7514. }
  7515. this.values[this.nameToKeyMap[name]] = value;
  7516. },
  7517. hasName: function CFFDict_hasName(name) {
  7518. return this.nameToKeyMap[name] in this.values;
  7519. },
  7520. getByName: function CFFDict_getByName(name) {
  7521. if (!(name in this.nameToKeyMap)) {
  7522. error('Invalid dictionary name "' + name + '"');
  7523. }
  7524. var key = this.nameToKeyMap[name];
  7525. if (!(key in this.values)) {
  7526. return this.defaults[key];
  7527. }
  7528. return this.values[key];
  7529. },
  7530. removeByName: function CFFDict_removeByName(name) {
  7531. delete this.values[this.nameToKeyMap[name]];
  7532. }
  7533. };
  7534. CFFDict.createTables = function CFFDict_createTables(layout) {
  7535. var tables = {
  7536. keyToNameMap: {},
  7537. nameToKeyMap: {},
  7538. defaults: {},
  7539. types: {},
  7540. opcodes: {},
  7541. order: []
  7542. };
  7543. for (var i = 0, ii = layout.length; i < ii; ++i) {
  7544. var entry = layout[i];
  7545. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  7546. tables.keyToNameMap[key] = entry[1];
  7547. tables.nameToKeyMap[entry[1]] = key;
  7548. tables.types[key] = entry[2];
  7549. tables.defaults[key] = entry[3];
  7550. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  7551. tables.order.push(key);
  7552. }
  7553. return tables;
  7554. };
  7555. return CFFDict;
  7556. }();
  7557. var CFFTopDict = function CFFTopDictClosure() {
  7558. var layout = [
  7559. [
  7560. [
  7561. 12,
  7562. 30
  7563. ],
  7564. 'ROS',
  7565. [
  7566. 'sid',
  7567. 'sid',
  7568. 'num'
  7569. ],
  7570. null
  7571. ],
  7572. [
  7573. [
  7574. 12,
  7575. 20
  7576. ],
  7577. 'SyntheticBase',
  7578. 'num',
  7579. null
  7580. ],
  7581. [
  7582. 0,
  7583. 'version',
  7584. 'sid',
  7585. null
  7586. ],
  7587. [
  7588. 1,
  7589. 'Notice',
  7590. 'sid',
  7591. null
  7592. ],
  7593. [
  7594. [
  7595. 12,
  7596. 0
  7597. ],
  7598. 'Copyright',
  7599. 'sid',
  7600. null
  7601. ],
  7602. [
  7603. 2,
  7604. 'FullName',
  7605. 'sid',
  7606. null
  7607. ],
  7608. [
  7609. 3,
  7610. 'FamilyName',
  7611. 'sid',
  7612. null
  7613. ],
  7614. [
  7615. 4,
  7616. 'Weight',
  7617. 'sid',
  7618. null
  7619. ],
  7620. [
  7621. [
  7622. 12,
  7623. 1
  7624. ],
  7625. 'isFixedPitch',
  7626. 'num',
  7627. 0
  7628. ],
  7629. [
  7630. [
  7631. 12,
  7632. 2
  7633. ],
  7634. 'ItalicAngle',
  7635. 'num',
  7636. 0
  7637. ],
  7638. [
  7639. [
  7640. 12,
  7641. 3
  7642. ],
  7643. 'UnderlinePosition',
  7644. 'num',
  7645. -100
  7646. ],
  7647. [
  7648. [
  7649. 12,
  7650. 4
  7651. ],
  7652. 'UnderlineThickness',
  7653. 'num',
  7654. 50
  7655. ],
  7656. [
  7657. [
  7658. 12,
  7659. 5
  7660. ],
  7661. 'PaintType',
  7662. 'num',
  7663. 0
  7664. ],
  7665. [
  7666. [
  7667. 12,
  7668. 6
  7669. ],
  7670. 'CharstringType',
  7671. 'num',
  7672. 2
  7673. ],
  7674. [
  7675. [
  7676. 12,
  7677. 7
  7678. ],
  7679. 'FontMatrix',
  7680. [
  7681. 'num',
  7682. 'num',
  7683. 'num',
  7684. 'num',
  7685. 'num',
  7686. 'num'
  7687. ],
  7688. [
  7689. 0.001,
  7690. 0,
  7691. 0,
  7692. 0.001,
  7693. 0,
  7694. 0
  7695. ]
  7696. ],
  7697. [
  7698. 13,
  7699. 'UniqueID',
  7700. 'num',
  7701. null
  7702. ],
  7703. [
  7704. 5,
  7705. 'FontBBox',
  7706. [
  7707. 'num',
  7708. 'num',
  7709. 'num',
  7710. 'num'
  7711. ],
  7712. [
  7713. 0,
  7714. 0,
  7715. 0,
  7716. 0
  7717. ]
  7718. ],
  7719. [
  7720. [
  7721. 12,
  7722. 8
  7723. ],
  7724. 'StrokeWidth',
  7725. 'num',
  7726. 0
  7727. ],
  7728. [
  7729. 14,
  7730. 'XUID',
  7731. 'array',
  7732. null
  7733. ],
  7734. [
  7735. 15,
  7736. 'charset',
  7737. 'offset',
  7738. 0
  7739. ],
  7740. [
  7741. 16,
  7742. 'Encoding',
  7743. 'offset',
  7744. 0
  7745. ],
  7746. [
  7747. 17,
  7748. 'CharStrings',
  7749. 'offset',
  7750. 0
  7751. ],
  7752. [
  7753. 18,
  7754. 'Private',
  7755. [
  7756. 'offset',
  7757. 'offset'
  7758. ],
  7759. null
  7760. ],
  7761. [
  7762. [
  7763. 12,
  7764. 21
  7765. ],
  7766. 'PostScript',
  7767. 'sid',
  7768. null
  7769. ],
  7770. [
  7771. [
  7772. 12,
  7773. 22
  7774. ],
  7775. 'BaseFontName',
  7776. 'sid',
  7777. null
  7778. ],
  7779. [
  7780. [
  7781. 12,
  7782. 23
  7783. ],
  7784. 'BaseFontBlend',
  7785. 'delta',
  7786. null
  7787. ],
  7788. [
  7789. [
  7790. 12,
  7791. 31
  7792. ],
  7793. 'CIDFontVersion',
  7794. 'num',
  7795. 0
  7796. ],
  7797. [
  7798. [
  7799. 12,
  7800. 32
  7801. ],
  7802. 'CIDFontRevision',
  7803. 'num',
  7804. 0
  7805. ],
  7806. [
  7807. [
  7808. 12,
  7809. 33
  7810. ],
  7811. 'CIDFontType',
  7812. 'num',
  7813. 0
  7814. ],
  7815. [
  7816. [
  7817. 12,
  7818. 34
  7819. ],
  7820. 'CIDCount',
  7821. 'num',
  7822. 8720
  7823. ],
  7824. [
  7825. [
  7826. 12,
  7827. 35
  7828. ],
  7829. 'UIDBase',
  7830. 'num',
  7831. null
  7832. ],
  7833. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  7834. // before FDArray.
  7835. [
  7836. [
  7837. 12,
  7838. 37
  7839. ],
  7840. 'FDSelect',
  7841. 'offset',
  7842. null
  7843. ],
  7844. [
  7845. [
  7846. 12,
  7847. 36
  7848. ],
  7849. 'FDArray',
  7850. 'offset',
  7851. null
  7852. ],
  7853. [
  7854. [
  7855. 12,
  7856. 38
  7857. ],
  7858. 'FontName',
  7859. 'sid',
  7860. null
  7861. ]
  7862. ];
  7863. var tables = null;
  7864. function CFFTopDict(strings) {
  7865. if (tables === null) {
  7866. tables = CFFDict.createTables(layout);
  7867. }
  7868. CFFDict.call(this, tables, strings);
  7869. this.privateDict = null;
  7870. }
  7871. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  7872. return CFFTopDict;
  7873. }();
  7874. var CFFPrivateDict = function CFFPrivateDictClosure() {
  7875. var layout = [
  7876. [
  7877. 6,
  7878. 'BlueValues',
  7879. 'delta',
  7880. null
  7881. ],
  7882. [
  7883. 7,
  7884. 'OtherBlues',
  7885. 'delta',
  7886. null
  7887. ],
  7888. [
  7889. 8,
  7890. 'FamilyBlues',
  7891. 'delta',
  7892. null
  7893. ],
  7894. [
  7895. 9,
  7896. 'FamilyOtherBlues',
  7897. 'delta',
  7898. null
  7899. ],
  7900. [
  7901. [
  7902. 12,
  7903. 9
  7904. ],
  7905. 'BlueScale',
  7906. 'num',
  7907. 0.039625
  7908. ],
  7909. [
  7910. [
  7911. 12,
  7912. 10
  7913. ],
  7914. 'BlueShift',
  7915. 'num',
  7916. 7
  7917. ],
  7918. [
  7919. [
  7920. 12,
  7921. 11
  7922. ],
  7923. 'BlueFuzz',
  7924. 'num',
  7925. 1
  7926. ],
  7927. [
  7928. 10,
  7929. 'StdHW',
  7930. 'num',
  7931. null
  7932. ],
  7933. [
  7934. 11,
  7935. 'StdVW',
  7936. 'num',
  7937. null
  7938. ],
  7939. [
  7940. [
  7941. 12,
  7942. 12
  7943. ],
  7944. 'StemSnapH',
  7945. 'delta',
  7946. null
  7947. ],
  7948. [
  7949. [
  7950. 12,
  7951. 13
  7952. ],
  7953. 'StemSnapV',
  7954. 'delta',
  7955. null
  7956. ],
  7957. [
  7958. [
  7959. 12,
  7960. 14
  7961. ],
  7962. 'ForceBold',
  7963. 'num',
  7964. 0
  7965. ],
  7966. [
  7967. [
  7968. 12,
  7969. 17
  7970. ],
  7971. 'LanguageGroup',
  7972. 'num',
  7973. 0
  7974. ],
  7975. [
  7976. [
  7977. 12,
  7978. 18
  7979. ],
  7980. 'ExpansionFactor',
  7981. 'num',
  7982. 0.06
  7983. ],
  7984. [
  7985. [
  7986. 12,
  7987. 19
  7988. ],
  7989. 'initialRandomSeed',
  7990. 'num',
  7991. 0
  7992. ],
  7993. [
  7994. 20,
  7995. 'defaultWidthX',
  7996. 'num',
  7997. 0
  7998. ],
  7999. [
  8000. 21,
  8001. 'nominalWidthX',
  8002. 'num',
  8003. 0
  8004. ],
  8005. [
  8006. 19,
  8007. 'Subrs',
  8008. 'offset',
  8009. null
  8010. ]
  8011. ];
  8012. var tables = null;
  8013. function CFFPrivateDict(strings) {
  8014. if (tables === null) {
  8015. tables = CFFDict.createTables(layout);
  8016. }
  8017. CFFDict.call(this, tables, strings);
  8018. this.subrsIndex = null;
  8019. }
  8020. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  8021. return CFFPrivateDict;
  8022. }();
  8023. var CFFCharsetPredefinedTypes = {
  8024. ISO_ADOBE: 0,
  8025. EXPERT: 1,
  8026. EXPERT_SUBSET: 2
  8027. };
  8028. var CFFCharset = function CFFCharsetClosure() {
  8029. function CFFCharset(predefined, format, charset, raw) {
  8030. this.predefined = predefined;
  8031. this.format = format;
  8032. this.charset = charset;
  8033. this.raw = raw;
  8034. }
  8035. return CFFCharset;
  8036. }();
  8037. var CFFEncoding = function CFFEncodingClosure() {
  8038. function CFFEncoding(predefined, format, encoding, raw) {
  8039. this.predefined = predefined;
  8040. this.format = format;
  8041. this.encoding = encoding;
  8042. this.raw = raw;
  8043. }
  8044. return CFFEncoding;
  8045. }();
  8046. var CFFFDSelect = function CFFFDSelectClosure() {
  8047. function CFFFDSelect(fdSelect, raw) {
  8048. this.fdSelect = fdSelect;
  8049. this.raw = raw;
  8050. }
  8051. CFFFDSelect.prototype = {
  8052. getFDIndex: function CFFFDSelect_get(glyphIndex) {
  8053. if (glyphIndex < 0 || glyphIndex >= this.fdSelect.length) {
  8054. return -1;
  8055. }
  8056. return this.fdSelect[glyphIndex];
  8057. }
  8058. };
  8059. return CFFFDSelect;
  8060. }();
  8061. // Helper class to keep track of where an offset is within the data and helps
  8062. // filling in that offset once it's known.
  8063. var CFFOffsetTracker = function CFFOffsetTrackerClosure() {
  8064. function CFFOffsetTracker() {
  8065. this.offsets = Object.create(null);
  8066. }
  8067. CFFOffsetTracker.prototype = {
  8068. isTracking: function CFFOffsetTracker_isTracking(key) {
  8069. return key in this.offsets;
  8070. },
  8071. track: function CFFOffsetTracker_track(key, location) {
  8072. if (key in this.offsets) {
  8073. error('Already tracking location of ' + key);
  8074. }
  8075. this.offsets[key] = location;
  8076. },
  8077. offset: function CFFOffsetTracker_offset(value) {
  8078. for (var key in this.offsets) {
  8079. this.offsets[key] += value;
  8080. }
  8081. },
  8082. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key, values, output) {
  8083. if (!(key in this.offsets)) {
  8084. error('Not tracking location of ' + key);
  8085. }
  8086. var data = output.data;
  8087. var dataOffset = this.offsets[key];
  8088. var size = 5;
  8089. for (var i = 0, ii = values.length; i < ii; ++i) {
  8090. var offset0 = i * size + dataOffset;
  8091. var offset1 = offset0 + 1;
  8092. var offset2 = offset0 + 2;
  8093. var offset3 = offset0 + 3;
  8094. var offset4 = offset0 + 4;
  8095. // It's easy to screw up offsets so perform this sanity check.
  8096. if (data[offset0] !== 0x1d || data[offset1] !== 0 || data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  8097. error('writing to an offset that is not empty');
  8098. }
  8099. var value = values[i];
  8100. data[offset0] = 0x1d;
  8101. data[offset1] = value >> 24 & 0xFF;
  8102. data[offset2] = value >> 16 & 0xFF;
  8103. data[offset3] = value >> 8 & 0xFF;
  8104. data[offset4] = value & 0xFF;
  8105. }
  8106. }
  8107. };
  8108. return CFFOffsetTracker;
  8109. }();
  8110. // Takes a CFF and converts it to the binary representation.
  8111. var CFFCompiler = function CFFCompilerClosure() {
  8112. function CFFCompiler(cff) {
  8113. this.cff = cff;
  8114. }
  8115. CFFCompiler.prototype = {
  8116. compile: function CFFCompiler_compile() {
  8117. var cff = this.cff;
  8118. var output = {
  8119. data: [],
  8120. length: 0,
  8121. add: function CFFCompiler_add(data) {
  8122. this.data = this.data.concat(data);
  8123. this.length = this.data.length;
  8124. }
  8125. };
  8126. // Compile the five entries that must be in order.
  8127. var header = this.compileHeader(cff.header);
  8128. output.add(header);
  8129. var nameIndex = this.compileNameIndex(cff.names);
  8130. output.add(nameIndex);
  8131. if (cff.isCIDFont) {
  8132. // The spec is unclear on how font matrices should relate to each other
  8133. // when there is one in the main top dict and the sub top dicts.
  8134. // Windows handles this differently than linux and osx so we have to
  8135. // normalize to work on all.
  8136. // Rules based off of some mailing list discussions:
  8137. // - If main font has a matrix and subfont doesn't, use the main matrix.
  8138. // - If no main font matrix and there is a subfont matrix, use the
  8139. // subfont matrix.
  8140. // - If both have matrices, concat together.
  8141. // - If neither have matrices, use default.
  8142. // To make this work on all platforms we move the top matrix into each
  8143. // sub top dict and concat if necessary.
  8144. if (cff.topDict.hasName('FontMatrix')) {
  8145. var base = cff.topDict.getByName('FontMatrix');
  8146. cff.topDict.removeByName('FontMatrix');
  8147. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  8148. var subDict = cff.fdArray[i];
  8149. var matrix = base.slice(0);
  8150. if (subDict.hasName('FontMatrix')) {
  8151. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  8152. }
  8153. subDict.setByName('FontMatrix', matrix);
  8154. }
  8155. }
  8156. }
  8157. var compiled = this.compileTopDicts([cff.topDict], output.length, cff.isCIDFont);
  8158. output.add(compiled.output);
  8159. var topDictTracker = compiled.trackers[0];
  8160. var stringIndex = this.compileStringIndex(cff.strings.strings);
  8161. output.add(stringIndex);
  8162. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  8163. output.add(globalSubrIndex);
  8164. // Now start on the other entries that have no specific order.
  8165. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  8166. if (cff.encoding.predefined) {
  8167. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format], output);
  8168. } else {
  8169. var encoding = this.compileEncoding(cff.encoding);
  8170. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  8171. output.add(encoding);
  8172. }
  8173. }
  8174. if (cff.charset && cff.topDict.hasName('charset')) {
  8175. if (cff.charset.predefined) {
  8176. topDictTracker.setEntryLocation('charset', [cff.charset.format], output);
  8177. } else {
  8178. var charset = this.compileCharset(cff.charset);
  8179. topDictTracker.setEntryLocation('charset', [output.length], output);
  8180. output.add(charset);
  8181. }
  8182. }
  8183. var charStrings = this.compileCharStrings(cff.charStrings);
  8184. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  8185. output.add(charStrings);
  8186. if (cff.isCIDFont) {
  8187. // For some reason FDSelect must be in front of FDArray on windows. OSX
  8188. // and linux don't seem to care.
  8189. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  8190. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  8191. output.add(fdSelect);
  8192. // It is unclear if the sub font dictionary can have CID related
  8193. // dictionary keys, but the sanitizer doesn't like them so remove them.
  8194. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  8195. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  8196. output.add(compiled.output);
  8197. var fontDictTrackers = compiled.trackers;
  8198. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  8199. }
  8200. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  8201. // If the font data ends with INDEX whose object data is zero-length,
  8202. // the sanitizer will bail out. Add a dummy byte to avoid that.
  8203. output.add([0]);
  8204. return output.data;
  8205. },
  8206. encodeNumber: function CFFCompiler_encodeNumber(value) {
  8207. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) {
  8208. // isInt
  8209. return this.encodeInteger(value);
  8210. } else {
  8211. return this.encodeFloat(value);
  8212. }
  8213. },
  8214. encodeFloat: function CFFCompiler_encodeFloat(num) {
  8215. var value = num.toString();
  8216. // rounding inaccurate doubles
  8217. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  8218. if (m) {
  8219. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  8220. value = (Math.round(num * epsilon) / epsilon).toString();
  8221. }
  8222. var nibbles = '';
  8223. var i, ii;
  8224. for (i = 0, ii = value.length; i < ii; ++i) {
  8225. var a = value[i];
  8226. if (a === 'e') {
  8227. nibbles += value[++i] === '-' ? 'c' : 'b';
  8228. } else if (a === '.') {
  8229. nibbles += 'a';
  8230. } else if (a === '-') {
  8231. nibbles += 'e';
  8232. } else {
  8233. nibbles += a;
  8234. }
  8235. }
  8236. nibbles += nibbles.length & 1 ? 'f' : 'ff';
  8237. var out = [30];
  8238. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  8239. out.push(parseInt(nibbles.substr(i, 2), 16));
  8240. }
  8241. return out;
  8242. },
  8243. encodeInteger: function CFFCompiler_encodeInteger(value) {
  8244. var code;
  8245. if (value >= -107 && value <= 107) {
  8246. code = [value + 139];
  8247. } else if (value >= 108 && value <= 1131) {
  8248. value = value - 108;
  8249. code = [
  8250. (value >> 8) + 247,
  8251. value & 0xFF
  8252. ];
  8253. } else if (value >= -1131 && value <= -108) {
  8254. value = -value - 108;
  8255. code = [
  8256. (value >> 8) + 251,
  8257. value & 0xFF
  8258. ];
  8259. } else if (value >= -32768 && value <= 32767) {
  8260. code = [
  8261. 0x1c,
  8262. value >> 8 & 0xFF,
  8263. value & 0xFF
  8264. ];
  8265. } else {
  8266. code = [
  8267. 0x1d,
  8268. value >> 24 & 0xFF,
  8269. value >> 16 & 0xFF,
  8270. value >> 8 & 0xFF,
  8271. value & 0xFF
  8272. ];
  8273. }
  8274. return code;
  8275. },
  8276. compileHeader: function CFFCompiler_compileHeader(header) {
  8277. return [
  8278. header.major,
  8279. header.minor,
  8280. header.hdrSize,
  8281. header.offSize
  8282. ];
  8283. },
  8284. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  8285. var nameIndex = new CFFIndex();
  8286. for (var i = 0, ii = names.length; i < ii; ++i) {
  8287. nameIndex.add(stringToBytes(names[i]));
  8288. }
  8289. return this.compileIndex(nameIndex);
  8290. },
  8291. compileTopDicts: function CFFCompiler_compileTopDicts(dicts, length, removeCidKeys) {
  8292. var fontDictTrackers = [];
  8293. var fdArrayIndex = new CFFIndex();
  8294. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  8295. var fontDict = dicts[i];
  8296. if (removeCidKeys) {
  8297. fontDict.removeByName('CIDFontVersion');
  8298. fontDict.removeByName('CIDFontRevision');
  8299. fontDict.removeByName('CIDFontType');
  8300. fontDict.removeByName('CIDCount');
  8301. fontDict.removeByName('UIDBase');
  8302. }
  8303. var fontDictTracker = new CFFOffsetTracker();
  8304. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  8305. fontDictTrackers.push(fontDictTracker);
  8306. fdArrayIndex.add(fontDictData);
  8307. fontDictTracker.offset(length);
  8308. }
  8309. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  8310. return {
  8311. trackers: fontDictTrackers,
  8312. output: fdArrayIndex
  8313. };
  8314. },
  8315. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts, trackers, output) {
  8316. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  8317. var fontDict = dicts[i];
  8318. assert(fontDict.privateDict && fontDict.hasName('Private'), 'There must be an private dictionary.');
  8319. var privateDict = fontDict.privateDict;
  8320. var privateDictTracker = new CFFOffsetTracker();
  8321. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  8322. var outputLength = output.length;
  8323. privateDictTracker.offset(outputLength);
  8324. if (!privateDictData.length) {
  8325. // The private dictionary was empty, set the output length to zero to
  8326. // ensure the offset length isn't out of bounds in the eyes of the
  8327. // sanitizer.
  8328. outputLength = 0;
  8329. }
  8330. trackers[i].setEntryLocation('Private', [
  8331. privateDictData.length,
  8332. outputLength
  8333. ], output);
  8334. output.add(privateDictData);
  8335. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  8336. var subrs = this.compileIndex(privateDict.subrsIndex);
  8337. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length], output);
  8338. output.add(subrs);
  8339. }
  8340. }
  8341. },
  8342. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  8343. var out = [];
  8344. // The dictionary keys must be in a certain order.
  8345. var order = dict.order;
  8346. for (var i = 0; i < order.length; ++i) {
  8347. var key = order[i];
  8348. if (!(key in dict.values)) {
  8349. continue;
  8350. }
  8351. var values = dict.values[key];
  8352. var types = dict.types[key];
  8353. if (!isArray(types)) {
  8354. types = [types];
  8355. }
  8356. if (!isArray(values)) {
  8357. values = [values];
  8358. }
  8359. // Remove any empty dict values.
  8360. if (values.length === 0) {
  8361. continue;
  8362. }
  8363. for (var j = 0, jj = types.length; j < jj; ++j) {
  8364. var type = types[j];
  8365. var value = values[j];
  8366. switch (type) {
  8367. case 'num':
  8368. case 'sid':
  8369. out = out.concat(this.encodeNumber(value));
  8370. break;
  8371. case 'offset':
  8372. // For offsets we just insert a 32bit integer so we don't have to
  8373. // deal with figuring out the length of the offset when it gets
  8374. // replaced later on by the compiler.
  8375. var name = dict.keyToNameMap[key];
  8376. // Some offsets have the offset and the length, so just record the
  8377. // position of the first one.
  8378. if (!offsetTracker.isTracking(name)) {
  8379. offsetTracker.track(name, out.length);
  8380. }
  8381. out = out.concat([
  8382. 0x1d,
  8383. 0,
  8384. 0,
  8385. 0,
  8386. 0
  8387. ]);
  8388. break;
  8389. case 'array':
  8390. case 'delta':
  8391. out = out.concat(this.encodeNumber(value));
  8392. for (var k = 1, kk = values.length; k < kk; ++k) {
  8393. out = out.concat(this.encodeNumber(values[k]));
  8394. }
  8395. break;
  8396. default:
  8397. error('Unknown data type of ' + type);
  8398. break;
  8399. }
  8400. }
  8401. out = out.concat(dict.opcodes[key]);
  8402. }
  8403. return out;
  8404. },
  8405. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  8406. var stringIndex = new CFFIndex();
  8407. for (var i = 0, ii = strings.length; i < ii; ++i) {
  8408. stringIndex.add(stringToBytes(strings[i]));
  8409. }
  8410. return this.compileIndex(stringIndex);
  8411. },
  8412. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  8413. var globalSubrIndex = this.cff.globalSubrIndex;
  8414. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  8415. },
  8416. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  8417. return this.compileIndex(charStrings);
  8418. },
  8419. compileCharset: function CFFCompiler_compileCharset(charset) {
  8420. return this.compileTypedArray(charset.raw);
  8421. },
  8422. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  8423. return this.compileTypedArray(encoding.raw);
  8424. },
  8425. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  8426. return this.compileTypedArray(fdSelect);
  8427. },
  8428. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  8429. var out = [];
  8430. for (var i = 0, ii = data.length; i < ii; ++i) {
  8431. out[i] = data[i];
  8432. }
  8433. return out;
  8434. },
  8435. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  8436. trackers = trackers || [];
  8437. var objects = index.objects;
  8438. // First 2 bytes contains the number of objects contained into this index
  8439. var count = objects.length;
  8440. // If there is no object, just create an index. This technically
  8441. // should just be [0, 0] but OTS has an issue with that.
  8442. if (count === 0) {
  8443. return [
  8444. 0,
  8445. 0,
  8446. 0
  8447. ];
  8448. }
  8449. var data = [
  8450. count >> 8 & 0xFF,
  8451. count & 0xff
  8452. ];
  8453. var lastOffset = 1, i;
  8454. for (i = 0; i < count; ++i) {
  8455. lastOffset += objects[i].length;
  8456. }
  8457. var offsetSize;
  8458. if (lastOffset < 0x100) {
  8459. offsetSize = 1;
  8460. } else if (lastOffset < 0x10000) {
  8461. offsetSize = 2;
  8462. } else if (lastOffset < 0x1000000) {
  8463. offsetSize = 3;
  8464. } else {
  8465. offsetSize = 4;
  8466. }
  8467. // Next byte contains the offset size use to reference object in the file
  8468. data.push(offsetSize);
  8469. // Add another offset after this one because we need a new offset
  8470. var relativeOffset = 1;
  8471. for (i = 0; i < count + 1; i++) {
  8472. if (offsetSize === 1) {
  8473. data.push(relativeOffset & 0xFF);
  8474. } else if (offsetSize === 2) {
  8475. data.push(relativeOffset >> 8 & 0xFF, relativeOffset & 0xFF);
  8476. } else if (offsetSize === 3) {
  8477. data.push(relativeOffset >> 16 & 0xFF, relativeOffset >> 8 & 0xFF, relativeOffset & 0xFF);
  8478. } else {
  8479. data.push(relativeOffset >>> 24 & 0xFF, relativeOffset >> 16 & 0xFF, relativeOffset >> 8 & 0xFF, relativeOffset & 0xFF);
  8480. }
  8481. if (objects[i]) {
  8482. relativeOffset += objects[i].length;
  8483. }
  8484. }
  8485. for (i = 0; i < count; i++) {
  8486. // Notify the tracker where the object will be offset in the data.
  8487. if (trackers[i]) {
  8488. trackers[i].offset(data.length);
  8489. }
  8490. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  8491. data.push(objects[i][j]);
  8492. }
  8493. }
  8494. return data;
  8495. }
  8496. };
  8497. return CFFCompiler;
  8498. }();
  8499. exports.CFFStandardStrings = CFFStandardStrings;
  8500. exports.CFFParser = CFFParser;
  8501. exports.CFF = CFF;
  8502. exports.CFFHeader = CFFHeader;
  8503. exports.CFFStrings = CFFStrings;
  8504. exports.CFFIndex = CFFIndex;
  8505. exports.CFFCharset = CFFCharset;
  8506. exports.CFFTopDict = CFFTopDict;
  8507. exports.CFFPrivateDict = CFFPrivateDict;
  8508. exports.CFFCompiler = CFFCompiler;
  8509. }));
  8510. (function (root, factory) {
  8511. factory(root.pdfjsCoreChunkedStream = {}, root.pdfjsSharedUtil);
  8512. }(this, function (exports, sharedUtil) {
  8513. var MissingDataException = sharedUtil.MissingDataException;
  8514. var arrayByteLength = sharedUtil.arrayByteLength;
  8515. var arraysToBytes = sharedUtil.arraysToBytes;
  8516. var assert = sharedUtil.assert;
  8517. var createPromiseCapability = sharedUtil.createPromiseCapability;
  8518. var isInt = sharedUtil.isInt;
  8519. var isEmptyObj = sharedUtil.isEmptyObj;
  8520. var ChunkedStream = function ChunkedStreamClosure() {
  8521. function ChunkedStream(length, chunkSize, manager) {
  8522. this.bytes = new Uint8Array(length);
  8523. this.start = 0;
  8524. this.pos = 0;
  8525. this.end = length;
  8526. this.chunkSize = chunkSize;
  8527. this.loadedChunks = [];
  8528. this.numChunksLoaded = 0;
  8529. this.numChunks = Math.ceil(length / chunkSize);
  8530. this.manager = manager;
  8531. this.progressiveDataLength = 0;
  8532. this.lastSuccessfulEnsureByteChunk = -1;
  8533. }
  8534. // a single-entry cache
  8535. // required methods for a stream. if a particular stream does not
  8536. // implement these, an error should be thrown
  8537. ChunkedStream.prototype = {
  8538. getMissingChunks: function ChunkedStream_getMissingChunks() {
  8539. var chunks = [];
  8540. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  8541. if (!this.loadedChunks[chunk]) {
  8542. chunks.push(chunk);
  8543. }
  8544. }
  8545. return chunks;
  8546. },
  8547. getBaseStreams: function ChunkedStream_getBaseStreams() {
  8548. return [this];
  8549. },
  8550. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  8551. return this.numChunksLoaded === this.numChunks;
  8552. },
  8553. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  8554. var end = begin + chunk.byteLength;
  8555. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  8556. // Using this.length is inaccurate here since this.start can be moved
  8557. // See ChunkedStream.moveStart()
  8558. var length = this.bytes.length;
  8559. assert(end % this.chunkSize === 0 || end === length, 'Bad end offset: ' + end);
  8560. this.bytes.set(new Uint8Array(chunk), begin);
  8561. var chunkSize = this.chunkSize;
  8562. var beginChunk = Math.floor(begin / chunkSize);
  8563. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  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. onReceiveProgressiveData: function ChunkedStream_onReceiveProgressiveData(data) {
  8573. var position = this.progressiveDataLength;
  8574. var beginChunk = Math.floor(position / this.chunkSize);
  8575. this.bytes.set(new Uint8Array(data), position);
  8576. position += data.byteLength;
  8577. this.progressiveDataLength = position;
  8578. var endChunk = position >= this.end ? this.numChunks : Math.floor(position / this.chunkSize);
  8579. var curChunk;
  8580. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  8581. if (!this.loadedChunks[curChunk]) {
  8582. this.loadedChunks[curChunk] = true;
  8583. ++this.numChunksLoaded;
  8584. }
  8585. }
  8586. },
  8587. ensureByte: function ChunkedStream_ensureByte(pos) {
  8588. var chunk = Math.floor(pos / this.chunkSize);
  8589. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  8590. return;
  8591. }
  8592. if (!this.loadedChunks[chunk]) {
  8593. throw new MissingDataException(pos, pos + 1);
  8594. }
  8595. this.lastSuccessfulEnsureByteChunk = chunk;
  8596. },
  8597. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  8598. if (begin >= end) {
  8599. return;
  8600. }
  8601. if (end <= this.progressiveDataLength) {
  8602. return;
  8603. }
  8604. var chunkSize = this.chunkSize;
  8605. var beginChunk = Math.floor(begin / chunkSize);
  8606. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  8607. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  8608. if (!this.loadedChunks[chunk]) {
  8609. throw new MissingDataException(begin, end);
  8610. }
  8611. }
  8612. },
  8613. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  8614. var chunk, numChunks = this.numChunks;
  8615. for (var i = 0; i < numChunks; ++i) {
  8616. chunk = (beginChunk + i) % numChunks;
  8617. // Wrap around to beginning
  8618. if (!this.loadedChunks[chunk]) {
  8619. return chunk;
  8620. }
  8621. }
  8622. return null;
  8623. },
  8624. hasChunk: function ChunkedStream_hasChunk(chunk) {
  8625. return !!this.loadedChunks[chunk];
  8626. },
  8627. get length() {
  8628. return this.end - this.start;
  8629. },
  8630. get isEmpty() {
  8631. return this.length === 0;
  8632. },
  8633. getByte: function ChunkedStream_getByte() {
  8634. var pos = this.pos;
  8635. if (pos >= this.end) {
  8636. return -1;
  8637. }
  8638. this.ensureByte(pos);
  8639. return this.bytes[this.pos++];
  8640. },
  8641. getUint16: function ChunkedStream_getUint16() {
  8642. var b0 = this.getByte();
  8643. var b1 = this.getByte();
  8644. if (b0 === -1 || b1 === -1) {
  8645. return -1;
  8646. }
  8647. return (b0 << 8) + b1;
  8648. },
  8649. getInt32: function ChunkedStream_getInt32() {
  8650. var b0 = this.getByte();
  8651. var b1 = this.getByte();
  8652. var b2 = this.getByte();
  8653. var b3 = this.getByte();
  8654. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  8655. },
  8656. // returns subarray of original buffer
  8657. // should only be read
  8658. getBytes: function ChunkedStream_getBytes(length) {
  8659. var bytes = this.bytes;
  8660. var pos = this.pos;
  8661. var strEnd = this.end;
  8662. if (!length) {
  8663. this.ensureRange(pos, strEnd);
  8664. return bytes.subarray(pos, strEnd);
  8665. }
  8666. var end = pos + length;
  8667. if (end > strEnd) {
  8668. end = strEnd;
  8669. }
  8670. this.ensureRange(pos, end);
  8671. this.pos = end;
  8672. return bytes.subarray(pos, end);
  8673. },
  8674. peekByte: function ChunkedStream_peekByte() {
  8675. var peekedByte = this.getByte();
  8676. this.pos--;
  8677. return peekedByte;
  8678. },
  8679. peekBytes: function ChunkedStream_peekBytes(length) {
  8680. var bytes = this.getBytes(length);
  8681. this.pos -= bytes.length;
  8682. return bytes;
  8683. },
  8684. getByteRange: function ChunkedStream_getBytes(begin, end) {
  8685. this.ensureRange(begin, end);
  8686. return this.bytes.subarray(begin, end);
  8687. },
  8688. skip: function ChunkedStream_skip(n) {
  8689. if (!n) {
  8690. n = 1;
  8691. }
  8692. this.pos += n;
  8693. },
  8694. reset: function ChunkedStream_reset() {
  8695. this.pos = this.start;
  8696. },
  8697. moveStart: function ChunkedStream_moveStart() {
  8698. this.start = this.pos;
  8699. },
  8700. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  8701. this.ensureRange(start, start + length);
  8702. function ChunkedStreamSubstream() {
  8703. }
  8704. ChunkedStreamSubstream.prototype = Object.create(this);
  8705. ChunkedStreamSubstream.prototype.getMissingChunks = function () {
  8706. var chunkSize = this.chunkSize;
  8707. var beginChunk = Math.floor(this.start / chunkSize);
  8708. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  8709. var missingChunks = [];
  8710. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  8711. if (!this.loadedChunks[chunk]) {
  8712. missingChunks.push(chunk);
  8713. }
  8714. }
  8715. return missingChunks;
  8716. };
  8717. var subStream = new ChunkedStreamSubstream();
  8718. subStream.pos = subStream.start = start;
  8719. subStream.end = start + length || this.end;
  8720. subStream.dict = dict;
  8721. return subStream;
  8722. },
  8723. isStream: true
  8724. };
  8725. return ChunkedStream;
  8726. }();
  8727. var ChunkedStreamManager = function ChunkedStreamManagerClosure() {
  8728. function ChunkedStreamManager(pdfNetworkStream, args) {
  8729. var chunkSize = args.rangeChunkSize;
  8730. var length = args.length;
  8731. this.stream = new ChunkedStream(length, chunkSize, this);
  8732. this.length = length;
  8733. this.chunkSize = chunkSize;
  8734. this.pdfNetworkStream = pdfNetworkStream;
  8735. this.url = args.url;
  8736. this.disableAutoFetch = args.disableAutoFetch;
  8737. this.msgHandler = args.msgHandler;
  8738. this.currRequestId = 0;
  8739. this.chunksNeededByRequest = Object.create(null);
  8740. this.requestsByChunk = Object.create(null);
  8741. this.promisesByRequest = Object.create(null);
  8742. this.progressiveDataLength = 0;
  8743. this.aborted = false;
  8744. this._loadedStreamCapability = createPromiseCapability();
  8745. }
  8746. ChunkedStreamManager.prototype = {
  8747. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  8748. return this._loadedStreamCapability.promise;
  8749. },
  8750. sendRequest: function ChunkedStreamManager_sendRequest(begin, end) {
  8751. var rangeReader = this.pdfNetworkStream.getRangeReader(begin, end);
  8752. if (!rangeReader.isStreamingSupported) {
  8753. rangeReader.onProgress = this.onProgress.bind(this);
  8754. }
  8755. var chunks = [], loaded = 0;
  8756. var manager = this;
  8757. var promise = new Promise(function (resolve, reject) {
  8758. var readChunk = function (chunk) {
  8759. try {
  8760. if (!chunk.done) {
  8761. var data = chunk.value;
  8762. chunks.push(data);
  8763. loaded += arrayByteLength(data);
  8764. if (rangeReader.isStreamingSupported) {
  8765. manager.onProgress({ loaded: loaded });
  8766. }
  8767. rangeReader.read().then(readChunk, reject);
  8768. return;
  8769. }
  8770. var chunkData = arraysToBytes(chunks);
  8771. chunks = null;
  8772. resolve(chunkData);
  8773. } catch (e) {
  8774. reject(e);
  8775. }
  8776. };
  8777. rangeReader.read().then(readChunk, reject);
  8778. });
  8779. promise.then(function (data) {
  8780. if (this.aborted) {
  8781. return;
  8782. }
  8783. // ignoring any data after abort
  8784. this.onReceiveData({
  8785. chunk: data,
  8786. begin: begin
  8787. });
  8788. }.bind(this));
  8789. },
  8790. // TODO check errors
  8791. // Get all the chunks that are not yet loaded and groups them into
  8792. // contiguous ranges to load in as few requests as possible
  8793. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  8794. var missingChunks = this.stream.getMissingChunks();
  8795. this._requestChunks(missingChunks);
  8796. return this._loadedStreamCapability.promise;
  8797. },
  8798. _requestChunks: function ChunkedStreamManager_requestChunks(chunks) {
  8799. var requestId = this.currRequestId++;
  8800. var i, ii;
  8801. var chunksNeeded = Object.create(null);
  8802. this.chunksNeededByRequest[requestId] = chunksNeeded;
  8803. for (i = 0, ii = chunks.length; i < ii; i++) {
  8804. if (!this.stream.hasChunk(chunks[i])) {
  8805. chunksNeeded[chunks[i]] = true;
  8806. }
  8807. }
  8808. if (isEmptyObj(chunksNeeded)) {
  8809. return Promise.resolve();
  8810. }
  8811. var capability = createPromiseCapability();
  8812. this.promisesByRequest[requestId] = capability;
  8813. var chunksToRequest = [];
  8814. for (var chunk in chunksNeeded) {
  8815. chunk = chunk | 0;
  8816. if (!(chunk in this.requestsByChunk)) {
  8817. this.requestsByChunk[chunk] = [];
  8818. chunksToRequest.push(chunk);
  8819. }
  8820. this.requestsByChunk[chunk].push(requestId);
  8821. }
  8822. if (!chunksToRequest.length) {
  8823. return capability.promise;
  8824. }
  8825. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  8826. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  8827. var groupedChunk = groupedChunksToRequest[i];
  8828. var begin = groupedChunk.beginChunk * this.chunkSize;
  8829. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  8830. this.sendRequest(begin, end);
  8831. }
  8832. return capability.promise;
  8833. },
  8834. getStream: function ChunkedStreamManager_getStream() {
  8835. return this.stream;
  8836. },
  8837. // Loads any chunks in the requested range that are not yet loaded
  8838. requestRange: function ChunkedStreamManager_requestRange(begin, end) {
  8839. end = Math.min(end, this.length);
  8840. var beginChunk = this.getBeginChunk(begin);
  8841. var endChunk = this.getEndChunk(end);
  8842. var chunks = [];
  8843. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  8844. chunks.push(chunk);
  8845. }
  8846. return this._requestChunks(chunks);
  8847. },
  8848. requestRanges: function ChunkedStreamManager_requestRanges(ranges) {
  8849. ranges = ranges || [];
  8850. var chunksToRequest = [];
  8851. for (var i = 0; i < ranges.length; i++) {
  8852. var beginChunk = this.getBeginChunk(ranges[i].begin);
  8853. var endChunk = this.getEndChunk(ranges[i].end);
  8854. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  8855. if (chunksToRequest.indexOf(chunk) < 0) {
  8856. chunksToRequest.push(chunk);
  8857. }
  8858. }
  8859. }
  8860. chunksToRequest.sort(function (a, b) {
  8861. return a - b;
  8862. });
  8863. return this._requestChunks(chunksToRequest);
  8864. },
  8865. // Groups a sorted array of chunks into as few contiguous larger
  8866. // chunks as possible
  8867. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  8868. var groupedChunks = [];
  8869. var beginChunk = -1;
  8870. var prevChunk = -1;
  8871. for (var i = 0; i < chunks.length; ++i) {
  8872. var chunk = chunks[i];
  8873. if (beginChunk < 0) {
  8874. beginChunk = chunk;
  8875. }
  8876. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  8877. groupedChunks.push({
  8878. beginChunk: beginChunk,
  8879. endChunk: prevChunk + 1
  8880. });
  8881. beginChunk = chunk;
  8882. }
  8883. if (i + 1 === chunks.length) {
  8884. groupedChunks.push({
  8885. beginChunk: beginChunk,
  8886. endChunk: chunk + 1
  8887. });
  8888. }
  8889. prevChunk = chunk;
  8890. }
  8891. return groupedChunks;
  8892. },
  8893. onProgress: function ChunkedStreamManager_onProgress(args) {
  8894. var bytesLoaded = this.stream.numChunksLoaded * this.chunkSize + args.loaded;
  8895. this.msgHandler.send('DocProgress', {
  8896. loaded: bytesLoaded,
  8897. total: this.length
  8898. });
  8899. },
  8900. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  8901. var chunk = args.chunk;
  8902. var isProgressive = args.begin === undefined;
  8903. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  8904. var end = begin + chunk.byteLength;
  8905. var beginChunk = Math.floor(begin / this.chunkSize);
  8906. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) : Math.ceil(end / this.chunkSize);
  8907. if (isProgressive) {
  8908. this.stream.onReceiveProgressiveData(chunk);
  8909. this.progressiveDataLength = end;
  8910. } else {
  8911. this.stream.onReceiveData(begin, chunk);
  8912. }
  8913. if (this.stream.allChunksLoaded()) {
  8914. this._loadedStreamCapability.resolve(this.stream);
  8915. }
  8916. var loadedRequests = [];
  8917. var i, requestId;
  8918. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  8919. // The server might return more chunks than requested
  8920. var requestIds = this.requestsByChunk[chunk] || [];
  8921. delete this.requestsByChunk[chunk];
  8922. for (i = 0; i < requestIds.length; ++i) {
  8923. requestId = requestIds[i];
  8924. var chunksNeeded = this.chunksNeededByRequest[requestId];
  8925. if (chunk in chunksNeeded) {
  8926. delete chunksNeeded[chunk];
  8927. }
  8928. if (!isEmptyObj(chunksNeeded)) {
  8929. continue;
  8930. }
  8931. loadedRequests.push(requestId);
  8932. }
  8933. }
  8934. // If there are no pending requests, automatically fetch the next
  8935. // unfetched chunk of the PDF
  8936. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  8937. var nextEmptyChunk;
  8938. if (this.stream.numChunksLoaded === 1) {
  8939. // This is a special optimization so that after fetching the first
  8940. // chunk, rather than fetching the second chunk, we fetch the last
  8941. // chunk.
  8942. var lastChunk = this.stream.numChunks - 1;
  8943. if (!this.stream.hasChunk(lastChunk)) {
  8944. nextEmptyChunk = lastChunk;
  8945. }
  8946. } else {
  8947. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  8948. }
  8949. if (isInt(nextEmptyChunk)) {
  8950. this._requestChunks([nextEmptyChunk]);
  8951. }
  8952. }
  8953. for (i = 0; i < loadedRequests.length; ++i) {
  8954. requestId = loadedRequests[i];
  8955. var capability = this.promisesByRequest[requestId];
  8956. delete this.promisesByRequest[requestId];
  8957. capability.resolve();
  8958. }
  8959. this.msgHandler.send('DocProgress', {
  8960. loaded: this.stream.numChunksLoaded * this.chunkSize,
  8961. total: this.length
  8962. });
  8963. },
  8964. onError: function ChunkedStreamManager_onError(err) {
  8965. this._loadedStreamCapability.reject(err);
  8966. },
  8967. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  8968. var chunk = Math.floor(begin / this.chunkSize);
  8969. return chunk;
  8970. },
  8971. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  8972. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  8973. return chunk;
  8974. },
  8975. abort: function ChunkedStreamManager_abort() {
  8976. this.aborted = true;
  8977. if (this.pdfNetworkStream) {
  8978. this.pdfNetworkStream.cancelAllRequests('abort');
  8979. }
  8980. for (var requestId in this.promisesByRequest) {
  8981. var capability = this.promisesByRequest[requestId];
  8982. capability.reject(new Error('Request was aborted'));
  8983. }
  8984. }
  8985. };
  8986. return ChunkedStreamManager;
  8987. }();
  8988. exports.ChunkedStream = ChunkedStream;
  8989. exports.ChunkedStreamManager = ChunkedStreamManager;
  8990. }));
  8991. (function (root, factory) {
  8992. factory(root.pdfjsCoreGlyphList = {}, root.pdfjsSharedUtil);
  8993. }(this, function (exports, sharedUtil) {
  8994. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  8995. var getGlyphsUnicode = getLookupTableFactory(function (t) {
  8996. t['A'] = 0x0041;
  8997. t['AE'] = 0x00C6;
  8998. t['AEacute'] = 0x01FC;
  8999. t['AEmacron'] = 0x01E2;
  9000. t['AEsmall'] = 0xF7E6;
  9001. t['Aacute'] = 0x00C1;
  9002. t['Aacutesmall'] = 0xF7E1;
  9003. t['Abreve'] = 0x0102;
  9004. t['Abreveacute'] = 0x1EAE;
  9005. t['Abrevecyrillic'] = 0x04D0;
  9006. t['Abrevedotbelow'] = 0x1EB6;
  9007. t['Abrevegrave'] = 0x1EB0;
  9008. t['Abrevehookabove'] = 0x1EB2;
  9009. t['Abrevetilde'] = 0x1EB4;
  9010. t['Acaron'] = 0x01CD;
  9011. t['Acircle'] = 0x24B6;
  9012. t['Acircumflex'] = 0x00C2;
  9013. t['Acircumflexacute'] = 0x1EA4;
  9014. t['Acircumflexdotbelow'] = 0x1EAC;
  9015. t['Acircumflexgrave'] = 0x1EA6;
  9016. t['Acircumflexhookabove'] = 0x1EA8;
  9017. t['Acircumflexsmall'] = 0xF7E2;
  9018. t['Acircumflextilde'] = 0x1EAA;
  9019. t['Acute'] = 0xF6C9;
  9020. t['Acutesmall'] = 0xF7B4;
  9021. t['Acyrillic'] = 0x0410;
  9022. t['Adblgrave'] = 0x0200;
  9023. t['Adieresis'] = 0x00C4;
  9024. t['Adieresiscyrillic'] = 0x04D2;
  9025. t['Adieresismacron'] = 0x01DE;
  9026. t['Adieresissmall'] = 0xF7E4;
  9027. t['Adotbelow'] = 0x1EA0;
  9028. t['Adotmacron'] = 0x01E0;
  9029. t['Agrave'] = 0x00C0;
  9030. t['Agravesmall'] = 0xF7E0;
  9031. t['Ahookabove'] = 0x1EA2;
  9032. t['Aiecyrillic'] = 0x04D4;
  9033. t['Ainvertedbreve'] = 0x0202;
  9034. t['Alpha'] = 0x0391;
  9035. t['Alphatonos'] = 0x0386;
  9036. t['Amacron'] = 0x0100;
  9037. t['Amonospace'] = 0xFF21;
  9038. t['Aogonek'] = 0x0104;
  9039. t['Aring'] = 0x00C5;
  9040. t['Aringacute'] = 0x01FA;
  9041. t['Aringbelow'] = 0x1E00;
  9042. t['Aringsmall'] = 0xF7E5;
  9043. t['Asmall'] = 0xF761;
  9044. t['Atilde'] = 0x00C3;
  9045. t['Atildesmall'] = 0xF7E3;
  9046. t['Aybarmenian'] = 0x0531;
  9047. t['B'] = 0x0042;
  9048. t['Bcircle'] = 0x24B7;
  9049. t['Bdotaccent'] = 0x1E02;
  9050. t['Bdotbelow'] = 0x1E04;
  9051. t['Becyrillic'] = 0x0411;
  9052. t['Benarmenian'] = 0x0532;
  9053. t['Beta'] = 0x0392;
  9054. t['Bhook'] = 0x0181;
  9055. t['Blinebelow'] = 0x1E06;
  9056. t['Bmonospace'] = 0xFF22;
  9057. t['Brevesmall'] = 0xF6F4;
  9058. t['Bsmall'] = 0xF762;
  9059. t['Btopbar'] = 0x0182;
  9060. t['C'] = 0x0043;
  9061. t['Caarmenian'] = 0x053E;
  9062. t['Cacute'] = 0x0106;
  9063. t['Caron'] = 0xF6CA;
  9064. t['Caronsmall'] = 0xF6F5;
  9065. t['Ccaron'] = 0x010C;
  9066. t['Ccedilla'] = 0x00C7;
  9067. t['Ccedillaacute'] = 0x1E08;
  9068. t['Ccedillasmall'] = 0xF7E7;
  9069. t['Ccircle'] = 0x24B8;
  9070. t['Ccircumflex'] = 0x0108;
  9071. t['Cdot'] = 0x010A;
  9072. t['Cdotaccent'] = 0x010A;
  9073. t['Cedillasmall'] = 0xF7B8;
  9074. t['Chaarmenian'] = 0x0549;
  9075. t['Cheabkhasiancyrillic'] = 0x04BC;
  9076. t['Checyrillic'] = 0x0427;
  9077. t['Chedescenderabkhasiancyrillic'] = 0x04BE;
  9078. t['Chedescendercyrillic'] = 0x04B6;
  9079. t['Chedieresiscyrillic'] = 0x04F4;
  9080. t['Cheharmenian'] = 0x0543;
  9081. t['Chekhakassiancyrillic'] = 0x04CB;
  9082. t['Cheverticalstrokecyrillic'] = 0x04B8;
  9083. t['Chi'] = 0x03A7;
  9084. t['Chook'] = 0x0187;
  9085. t['Circumflexsmall'] = 0xF6F6;
  9086. t['Cmonospace'] = 0xFF23;
  9087. t['Coarmenian'] = 0x0551;
  9088. t['Csmall'] = 0xF763;
  9089. t['D'] = 0x0044;
  9090. t['DZ'] = 0x01F1;
  9091. t['DZcaron'] = 0x01C4;
  9092. t['Daarmenian'] = 0x0534;
  9093. t['Dafrican'] = 0x0189;
  9094. t['Dcaron'] = 0x010E;
  9095. t['Dcedilla'] = 0x1E10;
  9096. t['Dcircle'] = 0x24B9;
  9097. t['Dcircumflexbelow'] = 0x1E12;
  9098. t['Dcroat'] = 0x0110;
  9099. t['Ddotaccent'] = 0x1E0A;
  9100. t['Ddotbelow'] = 0x1E0C;
  9101. t['Decyrillic'] = 0x0414;
  9102. t['Deicoptic'] = 0x03EE;
  9103. t['Delta'] = 0x2206;
  9104. t['Deltagreek'] = 0x0394;
  9105. t['Dhook'] = 0x018A;
  9106. t['Dieresis'] = 0xF6CB;
  9107. t['DieresisAcute'] = 0xF6CC;
  9108. t['DieresisGrave'] = 0xF6CD;
  9109. t['Dieresissmall'] = 0xF7A8;
  9110. t['Digammagreek'] = 0x03DC;
  9111. t['Djecyrillic'] = 0x0402;
  9112. t['Dlinebelow'] = 0x1E0E;
  9113. t['Dmonospace'] = 0xFF24;
  9114. t['Dotaccentsmall'] = 0xF6F7;
  9115. t['Dslash'] = 0x0110;
  9116. t['Dsmall'] = 0xF764;
  9117. t['Dtopbar'] = 0x018B;
  9118. t['Dz'] = 0x01F2;
  9119. t['Dzcaron'] = 0x01C5;
  9120. t['Dzeabkhasiancyrillic'] = 0x04E0;
  9121. t['Dzecyrillic'] = 0x0405;
  9122. t['Dzhecyrillic'] = 0x040F;
  9123. t['E'] = 0x0045;
  9124. t['Eacute'] = 0x00C9;
  9125. t['Eacutesmall'] = 0xF7E9;
  9126. t['Ebreve'] = 0x0114;
  9127. t['Ecaron'] = 0x011A;
  9128. t['Ecedillabreve'] = 0x1E1C;
  9129. t['Echarmenian'] = 0x0535;
  9130. t['Ecircle'] = 0x24BA;
  9131. t['Ecircumflex'] = 0x00CA;
  9132. t['Ecircumflexacute'] = 0x1EBE;
  9133. t['Ecircumflexbelow'] = 0x1E18;
  9134. t['Ecircumflexdotbelow'] = 0x1EC6;
  9135. t['Ecircumflexgrave'] = 0x1EC0;
  9136. t['Ecircumflexhookabove'] = 0x1EC2;
  9137. t['Ecircumflexsmall'] = 0xF7EA;
  9138. t['Ecircumflextilde'] = 0x1EC4;
  9139. t['Ecyrillic'] = 0x0404;
  9140. t['Edblgrave'] = 0x0204;
  9141. t['Edieresis'] = 0x00CB;
  9142. t['Edieresissmall'] = 0xF7EB;
  9143. t['Edot'] = 0x0116;
  9144. t['Edotaccent'] = 0x0116;
  9145. t['Edotbelow'] = 0x1EB8;
  9146. t['Efcyrillic'] = 0x0424;
  9147. t['Egrave'] = 0x00C8;
  9148. t['Egravesmall'] = 0xF7E8;
  9149. t['Eharmenian'] = 0x0537;
  9150. t['Ehookabove'] = 0x1EBA;
  9151. t['Eightroman'] = 0x2167;
  9152. t['Einvertedbreve'] = 0x0206;
  9153. t['Eiotifiedcyrillic'] = 0x0464;
  9154. t['Elcyrillic'] = 0x041B;
  9155. t['Elevenroman'] = 0x216A;
  9156. t['Emacron'] = 0x0112;
  9157. t['Emacronacute'] = 0x1E16;
  9158. t['Emacrongrave'] = 0x1E14;
  9159. t['Emcyrillic'] = 0x041C;
  9160. t['Emonospace'] = 0xFF25;
  9161. t['Encyrillic'] = 0x041D;
  9162. t['Endescendercyrillic'] = 0x04A2;
  9163. t['Eng'] = 0x014A;
  9164. t['Enghecyrillic'] = 0x04A4;
  9165. t['Enhookcyrillic'] = 0x04C7;
  9166. t['Eogonek'] = 0x0118;
  9167. t['Eopen'] = 0x0190;
  9168. t['Epsilon'] = 0x0395;
  9169. t['Epsilontonos'] = 0x0388;
  9170. t['Ercyrillic'] = 0x0420;
  9171. t['Ereversed'] = 0x018E;
  9172. t['Ereversedcyrillic'] = 0x042D;
  9173. t['Escyrillic'] = 0x0421;
  9174. t['Esdescendercyrillic'] = 0x04AA;
  9175. t['Esh'] = 0x01A9;
  9176. t['Esmall'] = 0xF765;
  9177. t['Eta'] = 0x0397;
  9178. t['Etarmenian'] = 0x0538;
  9179. t['Etatonos'] = 0x0389;
  9180. t['Eth'] = 0x00D0;
  9181. t['Ethsmall'] = 0xF7F0;
  9182. t['Etilde'] = 0x1EBC;
  9183. t['Etildebelow'] = 0x1E1A;
  9184. t['Euro'] = 0x20AC;
  9185. t['Ezh'] = 0x01B7;
  9186. t['Ezhcaron'] = 0x01EE;
  9187. t['Ezhreversed'] = 0x01B8;
  9188. t['F'] = 0x0046;
  9189. t['Fcircle'] = 0x24BB;
  9190. t['Fdotaccent'] = 0x1E1E;
  9191. t['Feharmenian'] = 0x0556;
  9192. t['Feicoptic'] = 0x03E4;
  9193. t['Fhook'] = 0x0191;
  9194. t['Fitacyrillic'] = 0x0472;
  9195. t['Fiveroman'] = 0x2164;
  9196. t['Fmonospace'] = 0xFF26;
  9197. t['Fourroman'] = 0x2163;
  9198. t['Fsmall'] = 0xF766;
  9199. t['G'] = 0x0047;
  9200. t['GBsquare'] = 0x3387;
  9201. t['Gacute'] = 0x01F4;
  9202. t['Gamma'] = 0x0393;
  9203. t['Gammaafrican'] = 0x0194;
  9204. t['Gangiacoptic'] = 0x03EA;
  9205. t['Gbreve'] = 0x011E;
  9206. t['Gcaron'] = 0x01E6;
  9207. t['Gcedilla'] = 0x0122;
  9208. t['Gcircle'] = 0x24BC;
  9209. t['Gcircumflex'] = 0x011C;
  9210. t['Gcommaaccent'] = 0x0122;
  9211. t['Gdot'] = 0x0120;
  9212. t['Gdotaccent'] = 0x0120;
  9213. t['Gecyrillic'] = 0x0413;
  9214. t['Ghadarmenian'] = 0x0542;
  9215. t['Ghemiddlehookcyrillic'] = 0x0494;
  9216. t['Ghestrokecyrillic'] = 0x0492;
  9217. t['Gheupturncyrillic'] = 0x0490;
  9218. t['Ghook'] = 0x0193;
  9219. t['Gimarmenian'] = 0x0533;
  9220. t['Gjecyrillic'] = 0x0403;
  9221. t['Gmacron'] = 0x1E20;
  9222. t['Gmonospace'] = 0xFF27;
  9223. t['Grave'] = 0xF6CE;
  9224. t['Gravesmall'] = 0xF760;
  9225. t['Gsmall'] = 0xF767;
  9226. t['Gsmallhook'] = 0x029B;
  9227. t['Gstroke'] = 0x01E4;
  9228. t['H'] = 0x0048;
  9229. t['H18533'] = 0x25CF;
  9230. t['H18543'] = 0x25AA;
  9231. t['H18551'] = 0x25AB;
  9232. t['H22073'] = 0x25A1;
  9233. t['HPsquare'] = 0x33CB;
  9234. t['Haabkhasiancyrillic'] = 0x04A8;
  9235. t['Hadescendercyrillic'] = 0x04B2;
  9236. t['Hardsigncyrillic'] = 0x042A;
  9237. t['Hbar'] = 0x0126;
  9238. t['Hbrevebelow'] = 0x1E2A;
  9239. t['Hcedilla'] = 0x1E28;
  9240. t['Hcircle'] = 0x24BD;
  9241. t['Hcircumflex'] = 0x0124;
  9242. t['Hdieresis'] = 0x1E26;
  9243. t['Hdotaccent'] = 0x1E22;
  9244. t['Hdotbelow'] = 0x1E24;
  9245. t['Hmonospace'] = 0xFF28;
  9246. t['Hoarmenian'] = 0x0540;
  9247. t['Horicoptic'] = 0x03E8;
  9248. t['Hsmall'] = 0xF768;
  9249. t['Hungarumlaut'] = 0xF6CF;
  9250. t['Hungarumlautsmall'] = 0xF6F8;
  9251. t['Hzsquare'] = 0x3390;
  9252. t['I'] = 0x0049;
  9253. t['IAcyrillic'] = 0x042F;
  9254. t['IJ'] = 0x0132;
  9255. t['IUcyrillic'] = 0x042E;
  9256. t['Iacute'] = 0x00CD;
  9257. t['Iacutesmall'] = 0xF7ED;
  9258. t['Ibreve'] = 0x012C;
  9259. t['Icaron'] = 0x01CF;
  9260. t['Icircle'] = 0x24BE;
  9261. t['Icircumflex'] = 0x00CE;
  9262. t['Icircumflexsmall'] = 0xF7EE;
  9263. t['Icyrillic'] = 0x0406;
  9264. t['Idblgrave'] = 0x0208;
  9265. t['Idieresis'] = 0x00CF;
  9266. t['Idieresisacute'] = 0x1E2E;
  9267. t['Idieresiscyrillic'] = 0x04E4;
  9268. t['Idieresissmall'] = 0xF7EF;
  9269. t['Idot'] = 0x0130;
  9270. t['Idotaccent'] = 0x0130;
  9271. t['Idotbelow'] = 0x1ECA;
  9272. t['Iebrevecyrillic'] = 0x04D6;
  9273. t['Iecyrillic'] = 0x0415;
  9274. t['Ifraktur'] = 0x2111;
  9275. t['Igrave'] = 0x00CC;
  9276. t['Igravesmall'] = 0xF7EC;
  9277. t['Ihookabove'] = 0x1EC8;
  9278. t['Iicyrillic'] = 0x0418;
  9279. t['Iinvertedbreve'] = 0x020A;
  9280. t['Iishortcyrillic'] = 0x0419;
  9281. t['Imacron'] = 0x012A;
  9282. t['Imacroncyrillic'] = 0x04E2;
  9283. t['Imonospace'] = 0xFF29;
  9284. t['Iniarmenian'] = 0x053B;
  9285. t['Iocyrillic'] = 0x0401;
  9286. t['Iogonek'] = 0x012E;
  9287. t['Iota'] = 0x0399;
  9288. t['Iotaafrican'] = 0x0196;
  9289. t['Iotadieresis'] = 0x03AA;
  9290. t['Iotatonos'] = 0x038A;
  9291. t['Ismall'] = 0xF769;
  9292. t['Istroke'] = 0x0197;
  9293. t['Itilde'] = 0x0128;
  9294. t['Itildebelow'] = 0x1E2C;
  9295. t['Izhitsacyrillic'] = 0x0474;
  9296. t['Izhitsadblgravecyrillic'] = 0x0476;
  9297. t['J'] = 0x004A;
  9298. t['Jaarmenian'] = 0x0541;
  9299. t['Jcircle'] = 0x24BF;
  9300. t['Jcircumflex'] = 0x0134;
  9301. t['Jecyrillic'] = 0x0408;
  9302. t['Jheharmenian'] = 0x054B;
  9303. t['Jmonospace'] = 0xFF2A;
  9304. t['Jsmall'] = 0xF76A;
  9305. t['K'] = 0x004B;
  9306. t['KBsquare'] = 0x3385;
  9307. t['KKsquare'] = 0x33CD;
  9308. t['Kabashkircyrillic'] = 0x04A0;
  9309. t['Kacute'] = 0x1E30;
  9310. t['Kacyrillic'] = 0x041A;
  9311. t['Kadescendercyrillic'] = 0x049A;
  9312. t['Kahookcyrillic'] = 0x04C3;
  9313. t['Kappa'] = 0x039A;
  9314. t['Kastrokecyrillic'] = 0x049E;
  9315. t['Kaverticalstrokecyrillic'] = 0x049C;
  9316. t['Kcaron'] = 0x01E8;
  9317. t['Kcedilla'] = 0x0136;
  9318. t['Kcircle'] = 0x24C0;
  9319. t['Kcommaaccent'] = 0x0136;
  9320. t['Kdotbelow'] = 0x1E32;
  9321. t['Keharmenian'] = 0x0554;
  9322. t['Kenarmenian'] = 0x053F;
  9323. t['Khacyrillic'] = 0x0425;
  9324. t['Kheicoptic'] = 0x03E6;
  9325. t['Khook'] = 0x0198;
  9326. t['Kjecyrillic'] = 0x040C;
  9327. t['Klinebelow'] = 0x1E34;
  9328. t['Kmonospace'] = 0xFF2B;
  9329. t['Koppacyrillic'] = 0x0480;
  9330. t['Koppagreek'] = 0x03DE;
  9331. t['Ksicyrillic'] = 0x046E;
  9332. t['Ksmall'] = 0xF76B;
  9333. t['L'] = 0x004C;
  9334. t['LJ'] = 0x01C7;
  9335. t['LL'] = 0xF6BF;
  9336. t['Lacute'] = 0x0139;
  9337. t['Lambda'] = 0x039B;
  9338. t['Lcaron'] = 0x013D;
  9339. t['Lcedilla'] = 0x013B;
  9340. t['Lcircle'] = 0x24C1;
  9341. t['Lcircumflexbelow'] = 0x1E3C;
  9342. t['Lcommaaccent'] = 0x013B;
  9343. t['Ldot'] = 0x013F;
  9344. t['Ldotaccent'] = 0x013F;
  9345. t['Ldotbelow'] = 0x1E36;
  9346. t['Ldotbelowmacron'] = 0x1E38;
  9347. t['Liwnarmenian'] = 0x053C;
  9348. t['Lj'] = 0x01C8;
  9349. t['Ljecyrillic'] = 0x0409;
  9350. t['Llinebelow'] = 0x1E3A;
  9351. t['Lmonospace'] = 0xFF2C;
  9352. t['Lslash'] = 0x0141;
  9353. t['Lslashsmall'] = 0xF6F9;
  9354. t['Lsmall'] = 0xF76C;
  9355. t['M'] = 0x004D;
  9356. t['MBsquare'] = 0x3386;
  9357. t['Macron'] = 0xF6D0;
  9358. t['Macronsmall'] = 0xF7AF;
  9359. t['Macute'] = 0x1E3E;
  9360. t['Mcircle'] = 0x24C2;
  9361. t['Mdotaccent'] = 0x1E40;
  9362. t['Mdotbelow'] = 0x1E42;
  9363. t['Menarmenian'] = 0x0544;
  9364. t['Mmonospace'] = 0xFF2D;
  9365. t['Msmall'] = 0xF76D;
  9366. t['Mturned'] = 0x019C;
  9367. t['Mu'] = 0x039C;
  9368. t['N'] = 0x004E;
  9369. t['NJ'] = 0x01CA;
  9370. t['Nacute'] = 0x0143;
  9371. t['Ncaron'] = 0x0147;
  9372. t['Ncedilla'] = 0x0145;
  9373. t['Ncircle'] = 0x24C3;
  9374. t['Ncircumflexbelow'] = 0x1E4A;
  9375. t['Ncommaaccent'] = 0x0145;
  9376. t['Ndotaccent'] = 0x1E44;
  9377. t['Ndotbelow'] = 0x1E46;
  9378. t['Nhookleft'] = 0x019D;
  9379. t['Nineroman'] = 0x2168;
  9380. t['Nj'] = 0x01CB;
  9381. t['Njecyrillic'] = 0x040A;
  9382. t['Nlinebelow'] = 0x1E48;
  9383. t['Nmonospace'] = 0xFF2E;
  9384. t['Nowarmenian'] = 0x0546;
  9385. t['Nsmall'] = 0xF76E;
  9386. t['Ntilde'] = 0x00D1;
  9387. t['Ntildesmall'] = 0xF7F1;
  9388. t['Nu'] = 0x039D;
  9389. t['O'] = 0x004F;
  9390. t['OE'] = 0x0152;
  9391. t['OEsmall'] = 0xF6FA;
  9392. t['Oacute'] = 0x00D3;
  9393. t['Oacutesmall'] = 0xF7F3;
  9394. t['Obarredcyrillic'] = 0x04E8;
  9395. t['Obarreddieresiscyrillic'] = 0x04EA;
  9396. t['Obreve'] = 0x014E;
  9397. t['Ocaron'] = 0x01D1;
  9398. t['Ocenteredtilde'] = 0x019F;
  9399. t['Ocircle'] = 0x24C4;
  9400. t['Ocircumflex'] = 0x00D4;
  9401. t['Ocircumflexacute'] = 0x1ED0;
  9402. t['Ocircumflexdotbelow'] = 0x1ED8;
  9403. t['Ocircumflexgrave'] = 0x1ED2;
  9404. t['Ocircumflexhookabove'] = 0x1ED4;
  9405. t['Ocircumflexsmall'] = 0xF7F4;
  9406. t['Ocircumflextilde'] = 0x1ED6;
  9407. t['Ocyrillic'] = 0x041E;
  9408. t['Odblacute'] = 0x0150;
  9409. t['Odblgrave'] = 0x020C;
  9410. t['Odieresis'] = 0x00D6;
  9411. t['Odieresiscyrillic'] = 0x04E6;
  9412. t['Odieresissmall'] = 0xF7F6;
  9413. t['Odotbelow'] = 0x1ECC;
  9414. t['Ogoneksmall'] = 0xF6FB;
  9415. t['Ograve'] = 0x00D2;
  9416. t['Ogravesmall'] = 0xF7F2;
  9417. t['Oharmenian'] = 0x0555;
  9418. t['Ohm'] = 0x2126;
  9419. t['Ohookabove'] = 0x1ECE;
  9420. t['Ohorn'] = 0x01A0;
  9421. t['Ohornacute'] = 0x1EDA;
  9422. t['Ohorndotbelow'] = 0x1EE2;
  9423. t['Ohorngrave'] = 0x1EDC;
  9424. t['Ohornhookabove'] = 0x1EDE;
  9425. t['Ohorntilde'] = 0x1EE0;
  9426. t['Ohungarumlaut'] = 0x0150;
  9427. t['Oi'] = 0x01A2;
  9428. t['Oinvertedbreve'] = 0x020E;
  9429. t['Omacron'] = 0x014C;
  9430. t['Omacronacute'] = 0x1E52;
  9431. t['Omacrongrave'] = 0x1E50;
  9432. t['Omega'] = 0x2126;
  9433. t['Omegacyrillic'] = 0x0460;
  9434. t['Omegagreek'] = 0x03A9;
  9435. t['Omegaroundcyrillic'] = 0x047A;
  9436. t['Omegatitlocyrillic'] = 0x047C;
  9437. t['Omegatonos'] = 0x038F;
  9438. t['Omicron'] = 0x039F;
  9439. t['Omicrontonos'] = 0x038C;
  9440. t['Omonospace'] = 0xFF2F;
  9441. t['Oneroman'] = 0x2160;
  9442. t['Oogonek'] = 0x01EA;
  9443. t['Oogonekmacron'] = 0x01EC;
  9444. t['Oopen'] = 0x0186;
  9445. t['Oslash'] = 0x00D8;
  9446. t['Oslashacute'] = 0x01FE;
  9447. t['Oslashsmall'] = 0xF7F8;
  9448. t['Osmall'] = 0xF76F;
  9449. t['Ostrokeacute'] = 0x01FE;
  9450. t['Otcyrillic'] = 0x047E;
  9451. t['Otilde'] = 0x00D5;
  9452. t['Otildeacute'] = 0x1E4C;
  9453. t['Otildedieresis'] = 0x1E4E;
  9454. t['Otildesmall'] = 0xF7F5;
  9455. t['P'] = 0x0050;
  9456. t['Pacute'] = 0x1E54;
  9457. t['Pcircle'] = 0x24C5;
  9458. t['Pdotaccent'] = 0x1E56;
  9459. t['Pecyrillic'] = 0x041F;
  9460. t['Peharmenian'] = 0x054A;
  9461. t['Pemiddlehookcyrillic'] = 0x04A6;
  9462. t['Phi'] = 0x03A6;
  9463. t['Phook'] = 0x01A4;
  9464. t['Pi'] = 0x03A0;
  9465. t['Piwrarmenian'] = 0x0553;
  9466. t['Pmonospace'] = 0xFF30;
  9467. t['Psi'] = 0x03A8;
  9468. t['Psicyrillic'] = 0x0470;
  9469. t['Psmall'] = 0xF770;
  9470. t['Q'] = 0x0051;
  9471. t['Qcircle'] = 0x24C6;
  9472. t['Qmonospace'] = 0xFF31;
  9473. t['Qsmall'] = 0xF771;
  9474. t['R'] = 0x0052;
  9475. t['Raarmenian'] = 0x054C;
  9476. t['Racute'] = 0x0154;
  9477. t['Rcaron'] = 0x0158;
  9478. t['Rcedilla'] = 0x0156;
  9479. t['Rcircle'] = 0x24C7;
  9480. t['Rcommaaccent'] = 0x0156;
  9481. t['Rdblgrave'] = 0x0210;
  9482. t['Rdotaccent'] = 0x1E58;
  9483. t['Rdotbelow'] = 0x1E5A;
  9484. t['Rdotbelowmacron'] = 0x1E5C;
  9485. t['Reharmenian'] = 0x0550;
  9486. t['Rfraktur'] = 0x211C;
  9487. t['Rho'] = 0x03A1;
  9488. t['Ringsmall'] = 0xF6FC;
  9489. t['Rinvertedbreve'] = 0x0212;
  9490. t['Rlinebelow'] = 0x1E5E;
  9491. t['Rmonospace'] = 0xFF32;
  9492. t['Rsmall'] = 0xF772;
  9493. t['Rsmallinverted'] = 0x0281;
  9494. t['Rsmallinvertedsuperior'] = 0x02B6;
  9495. t['S'] = 0x0053;
  9496. t['SF010000'] = 0x250C;
  9497. t['SF020000'] = 0x2514;
  9498. t['SF030000'] = 0x2510;
  9499. t['SF040000'] = 0x2518;
  9500. t['SF050000'] = 0x253C;
  9501. t['SF060000'] = 0x252C;
  9502. t['SF070000'] = 0x2534;
  9503. t['SF080000'] = 0x251C;
  9504. t['SF090000'] = 0x2524;
  9505. t['SF100000'] = 0x2500;
  9506. t['SF110000'] = 0x2502;
  9507. t['SF190000'] = 0x2561;
  9508. t['SF200000'] = 0x2562;
  9509. t['SF210000'] = 0x2556;
  9510. t['SF220000'] = 0x2555;
  9511. t['SF230000'] = 0x2563;
  9512. t['SF240000'] = 0x2551;
  9513. t['SF250000'] = 0x2557;
  9514. t['SF260000'] = 0x255D;
  9515. t['SF270000'] = 0x255C;
  9516. t['SF280000'] = 0x255B;
  9517. t['SF360000'] = 0x255E;
  9518. t['SF370000'] = 0x255F;
  9519. t['SF380000'] = 0x255A;
  9520. t['SF390000'] = 0x2554;
  9521. t['SF400000'] = 0x2569;
  9522. t['SF410000'] = 0x2566;
  9523. t['SF420000'] = 0x2560;
  9524. t['SF430000'] = 0x2550;
  9525. t['SF440000'] = 0x256C;
  9526. t['SF450000'] = 0x2567;
  9527. t['SF460000'] = 0x2568;
  9528. t['SF470000'] = 0x2564;
  9529. t['SF480000'] = 0x2565;
  9530. t['SF490000'] = 0x2559;
  9531. t['SF500000'] = 0x2558;
  9532. t['SF510000'] = 0x2552;
  9533. t['SF520000'] = 0x2553;
  9534. t['SF530000'] = 0x256B;
  9535. t['SF540000'] = 0x256A;
  9536. t['Sacute'] = 0x015A;
  9537. t['Sacutedotaccent'] = 0x1E64;
  9538. t['Sampigreek'] = 0x03E0;
  9539. t['Scaron'] = 0x0160;
  9540. t['Scarondotaccent'] = 0x1E66;
  9541. t['Scaronsmall'] = 0xF6FD;
  9542. t['Scedilla'] = 0x015E;
  9543. t['Schwa'] = 0x018F;
  9544. t['Schwacyrillic'] = 0x04D8;
  9545. t['Schwadieresiscyrillic'] = 0x04DA;
  9546. t['Scircle'] = 0x24C8;
  9547. t['Scircumflex'] = 0x015C;
  9548. t['Scommaaccent'] = 0x0218;
  9549. t['Sdotaccent'] = 0x1E60;
  9550. t['Sdotbelow'] = 0x1E62;
  9551. t['Sdotbelowdotaccent'] = 0x1E68;
  9552. t['Seharmenian'] = 0x054D;
  9553. t['Sevenroman'] = 0x2166;
  9554. t['Shaarmenian'] = 0x0547;
  9555. t['Shacyrillic'] = 0x0428;
  9556. t['Shchacyrillic'] = 0x0429;
  9557. t['Sheicoptic'] = 0x03E2;
  9558. t['Shhacyrillic'] = 0x04BA;
  9559. t['Shimacoptic'] = 0x03EC;
  9560. t['Sigma'] = 0x03A3;
  9561. t['Sixroman'] = 0x2165;
  9562. t['Smonospace'] = 0xFF33;
  9563. t['Softsigncyrillic'] = 0x042C;
  9564. t['Ssmall'] = 0xF773;
  9565. t['Stigmagreek'] = 0x03DA;
  9566. t['T'] = 0x0054;
  9567. t['Tau'] = 0x03A4;
  9568. t['Tbar'] = 0x0166;
  9569. t['Tcaron'] = 0x0164;
  9570. t['Tcedilla'] = 0x0162;
  9571. t['Tcircle'] = 0x24C9;
  9572. t['Tcircumflexbelow'] = 0x1E70;
  9573. t['Tcommaaccent'] = 0x0162;
  9574. t['Tdotaccent'] = 0x1E6A;
  9575. t['Tdotbelow'] = 0x1E6C;
  9576. t['Tecyrillic'] = 0x0422;
  9577. t['Tedescendercyrillic'] = 0x04AC;
  9578. t['Tenroman'] = 0x2169;
  9579. t['Tetsecyrillic'] = 0x04B4;
  9580. t['Theta'] = 0x0398;
  9581. t['Thook'] = 0x01AC;
  9582. t['Thorn'] = 0x00DE;
  9583. t['Thornsmall'] = 0xF7FE;
  9584. t['Threeroman'] = 0x2162;
  9585. t['Tildesmall'] = 0xF6FE;
  9586. t['Tiwnarmenian'] = 0x054F;
  9587. t['Tlinebelow'] = 0x1E6E;
  9588. t['Tmonospace'] = 0xFF34;
  9589. t['Toarmenian'] = 0x0539;
  9590. t['Tonefive'] = 0x01BC;
  9591. t['Tonesix'] = 0x0184;
  9592. t['Tonetwo'] = 0x01A7;
  9593. t['Tretroflexhook'] = 0x01AE;
  9594. t['Tsecyrillic'] = 0x0426;
  9595. t['Tshecyrillic'] = 0x040B;
  9596. t['Tsmall'] = 0xF774;
  9597. t['Twelveroman'] = 0x216B;
  9598. t['Tworoman'] = 0x2161;
  9599. t['U'] = 0x0055;
  9600. t['Uacute'] = 0x00DA;
  9601. t['Uacutesmall'] = 0xF7FA;
  9602. t['Ubreve'] = 0x016C;
  9603. t['Ucaron'] = 0x01D3;
  9604. t['Ucircle'] = 0x24CA;
  9605. t['Ucircumflex'] = 0x00DB;
  9606. t['Ucircumflexbelow'] = 0x1E76;
  9607. t['Ucircumflexsmall'] = 0xF7FB;
  9608. t['Ucyrillic'] = 0x0423;
  9609. t['Udblacute'] = 0x0170;
  9610. t['Udblgrave'] = 0x0214;
  9611. t['Udieresis'] = 0x00DC;
  9612. t['Udieresisacute'] = 0x01D7;
  9613. t['Udieresisbelow'] = 0x1E72;
  9614. t['Udieresiscaron'] = 0x01D9;
  9615. t['Udieresiscyrillic'] = 0x04F0;
  9616. t['Udieresisgrave'] = 0x01DB;
  9617. t['Udieresismacron'] = 0x01D5;
  9618. t['Udieresissmall'] = 0xF7FC;
  9619. t['Udotbelow'] = 0x1EE4;
  9620. t['Ugrave'] = 0x00D9;
  9621. t['Ugravesmall'] = 0xF7F9;
  9622. t['Uhookabove'] = 0x1EE6;
  9623. t['Uhorn'] = 0x01AF;
  9624. t['Uhornacute'] = 0x1EE8;
  9625. t['Uhorndotbelow'] = 0x1EF0;
  9626. t['Uhorngrave'] = 0x1EEA;
  9627. t['Uhornhookabove'] = 0x1EEC;
  9628. t['Uhorntilde'] = 0x1EEE;
  9629. t['Uhungarumlaut'] = 0x0170;
  9630. t['Uhungarumlautcyrillic'] = 0x04F2;
  9631. t['Uinvertedbreve'] = 0x0216;
  9632. t['Ukcyrillic'] = 0x0478;
  9633. t['Umacron'] = 0x016A;
  9634. t['Umacroncyrillic'] = 0x04EE;
  9635. t['Umacrondieresis'] = 0x1E7A;
  9636. t['Umonospace'] = 0xFF35;
  9637. t['Uogonek'] = 0x0172;
  9638. t['Upsilon'] = 0x03A5;
  9639. t['Upsilon1'] = 0x03D2;
  9640. t['Upsilonacutehooksymbolgreek'] = 0x03D3;
  9641. t['Upsilonafrican'] = 0x01B1;
  9642. t['Upsilondieresis'] = 0x03AB;
  9643. t['Upsilondieresishooksymbolgreek'] = 0x03D4;
  9644. t['Upsilonhooksymbol'] = 0x03D2;
  9645. t['Upsilontonos'] = 0x038E;
  9646. t['Uring'] = 0x016E;
  9647. t['Ushortcyrillic'] = 0x040E;
  9648. t['Usmall'] = 0xF775;
  9649. t['Ustraightcyrillic'] = 0x04AE;
  9650. t['Ustraightstrokecyrillic'] = 0x04B0;
  9651. t['Utilde'] = 0x0168;
  9652. t['Utildeacute'] = 0x1E78;
  9653. t['Utildebelow'] = 0x1E74;
  9654. t['V'] = 0x0056;
  9655. t['Vcircle'] = 0x24CB;
  9656. t['Vdotbelow'] = 0x1E7E;
  9657. t['Vecyrillic'] = 0x0412;
  9658. t['Vewarmenian'] = 0x054E;
  9659. t['Vhook'] = 0x01B2;
  9660. t['Vmonospace'] = 0xFF36;
  9661. t['Voarmenian'] = 0x0548;
  9662. t['Vsmall'] = 0xF776;
  9663. t['Vtilde'] = 0x1E7C;
  9664. t['W'] = 0x0057;
  9665. t['Wacute'] = 0x1E82;
  9666. t['Wcircle'] = 0x24CC;
  9667. t['Wcircumflex'] = 0x0174;
  9668. t['Wdieresis'] = 0x1E84;
  9669. t['Wdotaccent'] = 0x1E86;
  9670. t['Wdotbelow'] = 0x1E88;
  9671. t['Wgrave'] = 0x1E80;
  9672. t['Wmonospace'] = 0xFF37;
  9673. t['Wsmall'] = 0xF777;
  9674. t['X'] = 0x0058;
  9675. t['Xcircle'] = 0x24CD;
  9676. t['Xdieresis'] = 0x1E8C;
  9677. t['Xdotaccent'] = 0x1E8A;
  9678. t['Xeharmenian'] = 0x053D;
  9679. t['Xi'] = 0x039E;
  9680. t['Xmonospace'] = 0xFF38;
  9681. t['Xsmall'] = 0xF778;
  9682. t['Y'] = 0x0059;
  9683. t['Yacute'] = 0x00DD;
  9684. t['Yacutesmall'] = 0xF7FD;
  9685. t['Yatcyrillic'] = 0x0462;
  9686. t['Ycircle'] = 0x24CE;
  9687. t['Ycircumflex'] = 0x0176;
  9688. t['Ydieresis'] = 0x0178;
  9689. t['Ydieresissmall'] = 0xF7FF;
  9690. t['Ydotaccent'] = 0x1E8E;
  9691. t['Ydotbelow'] = 0x1EF4;
  9692. t['Yericyrillic'] = 0x042B;
  9693. t['Yerudieresiscyrillic'] = 0x04F8;
  9694. t['Ygrave'] = 0x1EF2;
  9695. t['Yhook'] = 0x01B3;
  9696. t['Yhookabove'] = 0x1EF6;
  9697. t['Yiarmenian'] = 0x0545;
  9698. t['Yicyrillic'] = 0x0407;
  9699. t['Yiwnarmenian'] = 0x0552;
  9700. t['Ymonospace'] = 0xFF39;
  9701. t['Ysmall'] = 0xF779;
  9702. t['Ytilde'] = 0x1EF8;
  9703. t['Yusbigcyrillic'] = 0x046A;
  9704. t['Yusbigiotifiedcyrillic'] = 0x046C;
  9705. t['Yuslittlecyrillic'] = 0x0466;
  9706. t['Yuslittleiotifiedcyrillic'] = 0x0468;
  9707. t['Z'] = 0x005A;
  9708. t['Zaarmenian'] = 0x0536;
  9709. t['Zacute'] = 0x0179;
  9710. t['Zcaron'] = 0x017D;
  9711. t['Zcaronsmall'] = 0xF6FF;
  9712. t['Zcircle'] = 0x24CF;
  9713. t['Zcircumflex'] = 0x1E90;
  9714. t['Zdot'] = 0x017B;
  9715. t['Zdotaccent'] = 0x017B;
  9716. t['Zdotbelow'] = 0x1E92;
  9717. t['Zecyrillic'] = 0x0417;
  9718. t['Zedescendercyrillic'] = 0x0498;
  9719. t['Zedieresiscyrillic'] = 0x04DE;
  9720. t['Zeta'] = 0x0396;
  9721. t['Zhearmenian'] = 0x053A;
  9722. t['Zhebrevecyrillic'] = 0x04C1;
  9723. t['Zhecyrillic'] = 0x0416;
  9724. t['Zhedescendercyrillic'] = 0x0496;
  9725. t['Zhedieresiscyrillic'] = 0x04DC;
  9726. t['Zlinebelow'] = 0x1E94;
  9727. t['Zmonospace'] = 0xFF3A;
  9728. t['Zsmall'] = 0xF77A;
  9729. t['Zstroke'] = 0x01B5;
  9730. t['a'] = 0x0061;
  9731. t['aabengali'] = 0x0986;
  9732. t['aacute'] = 0x00E1;
  9733. t['aadeva'] = 0x0906;
  9734. t['aagujarati'] = 0x0A86;
  9735. t['aagurmukhi'] = 0x0A06;
  9736. t['aamatragurmukhi'] = 0x0A3E;
  9737. t['aarusquare'] = 0x3303;
  9738. t['aavowelsignbengali'] = 0x09BE;
  9739. t['aavowelsigndeva'] = 0x093E;
  9740. t['aavowelsigngujarati'] = 0x0ABE;
  9741. t['abbreviationmarkarmenian'] = 0x055F;
  9742. t['abbreviationsigndeva'] = 0x0970;
  9743. t['abengali'] = 0x0985;
  9744. t['abopomofo'] = 0x311A;
  9745. t['abreve'] = 0x0103;
  9746. t['abreveacute'] = 0x1EAF;
  9747. t['abrevecyrillic'] = 0x04D1;
  9748. t['abrevedotbelow'] = 0x1EB7;
  9749. t['abrevegrave'] = 0x1EB1;
  9750. t['abrevehookabove'] = 0x1EB3;
  9751. t['abrevetilde'] = 0x1EB5;
  9752. t['acaron'] = 0x01CE;
  9753. t['acircle'] = 0x24D0;
  9754. t['acircumflex'] = 0x00E2;
  9755. t['acircumflexacute'] = 0x1EA5;
  9756. t['acircumflexdotbelow'] = 0x1EAD;
  9757. t['acircumflexgrave'] = 0x1EA7;
  9758. t['acircumflexhookabove'] = 0x1EA9;
  9759. t['acircumflextilde'] = 0x1EAB;
  9760. t['acute'] = 0x00B4;
  9761. t['acutebelowcmb'] = 0x0317;
  9762. t['acutecmb'] = 0x0301;
  9763. t['acutecomb'] = 0x0301;
  9764. t['acutedeva'] = 0x0954;
  9765. t['acutelowmod'] = 0x02CF;
  9766. t['acutetonecmb'] = 0x0341;
  9767. t['acyrillic'] = 0x0430;
  9768. t['adblgrave'] = 0x0201;
  9769. t['addakgurmukhi'] = 0x0A71;
  9770. t['adeva'] = 0x0905;
  9771. t['adieresis'] = 0x00E4;
  9772. t['adieresiscyrillic'] = 0x04D3;
  9773. t['adieresismacron'] = 0x01DF;
  9774. t['adotbelow'] = 0x1EA1;
  9775. t['adotmacron'] = 0x01E1;
  9776. t['ae'] = 0x00E6;
  9777. t['aeacute'] = 0x01FD;
  9778. t['aekorean'] = 0x3150;
  9779. t['aemacron'] = 0x01E3;
  9780. t['afii00208'] = 0x2015;
  9781. t['afii08941'] = 0x20A4;
  9782. t['afii10017'] = 0x0410;
  9783. t['afii10018'] = 0x0411;
  9784. t['afii10019'] = 0x0412;
  9785. t['afii10020'] = 0x0413;
  9786. t['afii10021'] = 0x0414;
  9787. t['afii10022'] = 0x0415;
  9788. t['afii10023'] = 0x0401;
  9789. t['afii10024'] = 0x0416;
  9790. t['afii10025'] = 0x0417;
  9791. t['afii10026'] = 0x0418;
  9792. t['afii10027'] = 0x0419;
  9793. t['afii10028'] = 0x041A;
  9794. t['afii10029'] = 0x041B;
  9795. t['afii10030'] = 0x041C;
  9796. t['afii10031'] = 0x041D;
  9797. t['afii10032'] = 0x041E;
  9798. t['afii10033'] = 0x041F;
  9799. t['afii10034'] = 0x0420;
  9800. t['afii10035'] = 0x0421;
  9801. t['afii10036'] = 0x0422;
  9802. t['afii10037'] = 0x0423;
  9803. t['afii10038'] = 0x0424;
  9804. t['afii10039'] = 0x0425;
  9805. t['afii10040'] = 0x0426;
  9806. t['afii10041'] = 0x0427;
  9807. t['afii10042'] = 0x0428;
  9808. t['afii10043'] = 0x0429;
  9809. t['afii10044'] = 0x042A;
  9810. t['afii10045'] = 0x042B;
  9811. t['afii10046'] = 0x042C;
  9812. t['afii10047'] = 0x042D;
  9813. t['afii10048'] = 0x042E;
  9814. t['afii10049'] = 0x042F;
  9815. t['afii10050'] = 0x0490;
  9816. t['afii10051'] = 0x0402;
  9817. t['afii10052'] = 0x0403;
  9818. t['afii10053'] = 0x0404;
  9819. t['afii10054'] = 0x0405;
  9820. t['afii10055'] = 0x0406;
  9821. t['afii10056'] = 0x0407;
  9822. t['afii10057'] = 0x0408;
  9823. t['afii10058'] = 0x0409;
  9824. t['afii10059'] = 0x040A;
  9825. t['afii10060'] = 0x040B;
  9826. t['afii10061'] = 0x040C;
  9827. t['afii10062'] = 0x040E;
  9828. t['afii10063'] = 0xF6C4;
  9829. t['afii10064'] = 0xF6C5;
  9830. t['afii10065'] = 0x0430;
  9831. t['afii10066'] = 0x0431;
  9832. t['afii10067'] = 0x0432;
  9833. t['afii10068'] = 0x0433;
  9834. t['afii10069'] = 0x0434;
  9835. t['afii10070'] = 0x0435;
  9836. t['afii10071'] = 0x0451;
  9837. t['afii10072'] = 0x0436;
  9838. t['afii10073'] = 0x0437;
  9839. t['afii10074'] = 0x0438;
  9840. t['afii10075'] = 0x0439;
  9841. t['afii10076'] = 0x043A;
  9842. t['afii10077'] = 0x043B;
  9843. t['afii10078'] = 0x043C;
  9844. t['afii10079'] = 0x043D;
  9845. t['afii10080'] = 0x043E;
  9846. t['afii10081'] = 0x043F;
  9847. t['afii10082'] = 0x0440;
  9848. t['afii10083'] = 0x0441;
  9849. t['afii10084'] = 0x0442;
  9850. t['afii10085'] = 0x0443;
  9851. t['afii10086'] = 0x0444;
  9852. t['afii10087'] = 0x0445;
  9853. t['afii10088'] = 0x0446;
  9854. t['afii10089'] = 0x0447;
  9855. t['afii10090'] = 0x0448;
  9856. t['afii10091'] = 0x0449;
  9857. t['afii10092'] = 0x044A;
  9858. t['afii10093'] = 0x044B;
  9859. t['afii10094'] = 0x044C;
  9860. t['afii10095'] = 0x044D;
  9861. t['afii10096'] = 0x044E;
  9862. t['afii10097'] = 0x044F;
  9863. t['afii10098'] = 0x0491;
  9864. t['afii10099'] = 0x0452;
  9865. t['afii10100'] = 0x0453;
  9866. t['afii10101'] = 0x0454;
  9867. t['afii10102'] = 0x0455;
  9868. t['afii10103'] = 0x0456;
  9869. t['afii10104'] = 0x0457;
  9870. t['afii10105'] = 0x0458;
  9871. t['afii10106'] = 0x0459;
  9872. t['afii10107'] = 0x045A;
  9873. t['afii10108'] = 0x045B;
  9874. t['afii10109'] = 0x045C;
  9875. t['afii10110'] = 0x045E;
  9876. t['afii10145'] = 0x040F;
  9877. t['afii10146'] = 0x0462;
  9878. t['afii10147'] = 0x0472;
  9879. t['afii10148'] = 0x0474;
  9880. t['afii10192'] = 0xF6C6;
  9881. t['afii10193'] = 0x045F;
  9882. t['afii10194'] = 0x0463;
  9883. t['afii10195'] = 0x0473;
  9884. t['afii10196'] = 0x0475;
  9885. t['afii10831'] = 0xF6C7;
  9886. t['afii10832'] = 0xF6C8;
  9887. t['afii10846'] = 0x04D9;
  9888. t['afii299'] = 0x200E;
  9889. t['afii300'] = 0x200F;
  9890. t['afii301'] = 0x200D;
  9891. t['afii57381'] = 0x066A;
  9892. t['afii57388'] = 0x060C;
  9893. t['afii57392'] = 0x0660;
  9894. t['afii57393'] = 0x0661;
  9895. t['afii57394'] = 0x0662;
  9896. t['afii57395'] = 0x0663;
  9897. t['afii57396'] = 0x0664;
  9898. t['afii57397'] = 0x0665;
  9899. t['afii57398'] = 0x0666;
  9900. t['afii57399'] = 0x0667;
  9901. t['afii57400'] = 0x0668;
  9902. t['afii57401'] = 0x0669;
  9903. t['afii57403'] = 0x061B;
  9904. t['afii57407'] = 0x061F;
  9905. t['afii57409'] = 0x0621;
  9906. t['afii57410'] = 0x0622;
  9907. t['afii57411'] = 0x0623;
  9908. t['afii57412'] = 0x0624;
  9909. t['afii57413'] = 0x0625;
  9910. t['afii57414'] = 0x0626;
  9911. t['afii57415'] = 0x0627;
  9912. t['afii57416'] = 0x0628;
  9913. t['afii57417'] = 0x0629;
  9914. t['afii57418'] = 0x062A;
  9915. t['afii57419'] = 0x062B;
  9916. t['afii57420'] = 0x062C;
  9917. t['afii57421'] = 0x062D;
  9918. t['afii57422'] = 0x062E;
  9919. t['afii57423'] = 0x062F;
  9920. t['afii57424'] = 0x0630;
  9921. t['afii57425'] = 0x0631;
  9922. t['afii57426'] = 0x0632;
  9923. t['afii57427'] = 0x0633;
  9924. t['afii57428'] = 0x0634;
  9925. t['afii57429'] = 0x0635;
  9926. t['afii57430'] = 0x0636;
  9927. t['afii57431'] = 0x0637;
  9928. t['afii57432'] = 0x0638;
  9929. t['afii57433'] = 0x0639;
  9930. t['afii57434'] = 0x063A;
  9931. t['afii57440'] = 0x0640;
  9932. t['afii57441'] = 0x0641;
  9933. t['afii57442'] = 0x0642;
  9934. t['afii57443'] = 0x0643;
  9935. t['afii57444'] = 0x0644;
  9936. t['afii57445'] = 0x0645;
  9937. t['afii57446'] = 0x0646;
  9938. t['afii57448'] = 0x0648;
  9939. t['afii57449'] = 0x0649;
  9940. t['afii57450'] = 0x064A;
  9941. t['afii57451'] = 0x064B;
  9942. t['afii57452'] = 0x064C;
  9943. t['afii57453'] = 0x064D;
  9944. t['afii57454'] = 0x064E;
  9945. t['afii57455'] = 0x064F;
  9946. t['afii57456'] = 0x0650;
  9947. t['afii57457'] = 0x0651;
  9948. t['afii57458'] = 0x0652;
  9949. t['afii57470'] = 0x0647;
  9950. t['afii57505'] = 0x06A4;
  9951. t['afii57506'] = 0x067E;
  9952. t['afii57507'] = 0x0686;
  9953. t['afii57508'] = 0x0698;
  9954. t['afii57509'] = 0x06AF;
  9955. t['afii57511'] = 0x0679;
  9956. t['afii57512'] = 0x0688;
  9957. t['afii57513'] = 0x0691;
  9958. t['afii57514'] = 0x06BA;
  9959. t['afii57519'] = 0x06D2;
  9960. t['afii57534'] = 0x06D5;
  9961. t['afii57636'] = 0x20AA;
  9962. t['afii57645'] = 0x05BE;
  9963. t['afii57658'] = 0x05C3;
  9964. t['afii57664'] = 0x05D0;
  9965. t['afii57665'] = 0x05D1;
  9966. t['afii57666'] = 0x05D2;
  9967. t['afii57667'] = 0x05D3;
  9968. t['afii57668'] = 0x05D4;
  9969. t['afii57669'] = 0x05D5;
  9970. t['afii57670'] = 0x05D6;
  9971. t['afii57671'] = 0x05D7;
  9972. t['afii57672'] = 0x05D8;
  9973. t['afii57673'] = 0x05D9;
  9974. t['afii57674'] = 0x05DA;
  9975. t['afii57675'] = 0x05DB;
  9976. t['afii57676'] = 0x05DC;
  9977. t['afii57677'] = 0x05DD;
  9978. t['afii57678'] = 0x05DE;
  9979. t['afii57679'] = 0x05DF;
  9980. t['afii57680'] = 0x05E0;
  9981. t['afii57681'] = 0x05E1;
  9982. t['afii57682'] = 0x05E2;
  9983. t['afii57683'] = 0x05E3;
  9984. t['afii57684'] = 0x05E4;
  9985. t['afii57685'] = 0x05E5;
  9986. t['afii57686'] = 0x05E6;
  9987. t['afii57687'] = 0x05E7;
  9988. t['afii57688'] = 0x05E8;
  9989. t['afii57689'] = 0x05E9;
  9990. t['afii57690'] = 0x05EA;
  9991. t['afii57694'] = 0xFB2A;
  9992. t['afii57695'] = 0xFB2B;
  9993. t['afii57700'] = 0xFB4B;
  9994. t['afii57705'] = 0xFB1F;
  9995. t['afii57716'] = 0x05F0;
  9996. t['afii57717'] = 0x05F1;
  9997. t['afii57718'] = 0x05F2;
  9998. t['afii57723'] = 0xFB35;
  9999. t['afii57793'] = 0x05B4;
  10000. t['afii57794'] = 0x05B5;
  10001. t['afii57795'] = 0x05B6;
  10002. t['afii57796'] = 0x05BB;
  10003. t['afii57797'] = 0x05B8;
  10004. t['afii57798'] = 0x05B7;
  10005. t['afii57799'] = 0x05B0;
  10006. t['afii57800'] = 0x05B2;
  10007. t['afii57801'] = 0x05B1;
  10008. t['afii57802'] = 0x05B3;
  10009. t['afii57803'] = 0x05C2;
  10010. t['afii57804'] = 0x05C1;
  10011. t['afii57806'] = 0x05B9;
  10012. t['afii57807'] = 0x05BC;
  10013. t['afii57839'] = 0x05BD;
  10014. t['afii57841'] = 0x05BF;
  10015. t['afii57842'] = 0x05C0;
  10016. t['afii57929'] = 0x02BC;
  10017. t['afii61248'] = 0x2105;
  10018. t['afii61289'] = 0x2113;
  10019. t['afii61352'] = 0x2116;
  10020. t['afii61573'] = 0x202C;
  10021. t['afii61574'] = 0x202D;
  10022. t['afii61575'] = 0x202E;
  10023. t['afii61664'] = 0x200C;
  10024. t['afii63167'] = 0x066D;
  10025. t['afii64937'] = 0x02BD;
  10026. t['agrave'] = 0x00E0;
  10027. t['agujarati'] = 0x0A85;
  10028. t['agurmukhi'] = 0x0A05;
  10029. t['ahiragana'] = 0x3042;
  10030. t['ahookabove'] = 0x1EA3;
  10031. t['aibengali'] = 0x0990;
  10032. t['aibopomofo'] = 0x311E;
  10033. t['aideva'] = 0x0910;
  10034. t['aiecyrillic'] = 0x04D5;
  10035. t['aigujarati'] = 0x0A90;
  10036. t['aigurmukhi'] = 0x0A10;
  10037. t['aimatragurmukhi'] = 0x0A48;
  10038. t['ainarabic'] = 0x0639;
  10039. t['ainfinalarabic'] = 0xFECA;
  10040. t['aininitialarabic'] = 0xFECB;
  10041. t['ainmedialarabic'] = 0xFECC;
  10042. t['ainvertedbreve'] = 0x0203;
  10043. t['aivowelsignbengali'] = 0x09C8;
  10044. t['aivowelsigndeva'] = 0x0948;
  10045. t['aivowelsigngujarati'] = 0x0AC8;
  10046. t['akatakana'] = 0x30A2;
  10047. t['akatakanahalfwidth'] = 0xFF71;
  10048. t['akorean'] = 0x314F;
  10049. t['alef'] = 0x05D0;
  10050. t['alefarabic'] = 0x0627;
  10051. t['alefdageshhebrew'] = 0xFB30;
  10052. t['aleffinalarabic'] = 0xFE8E;
  10053. t['alefhamzaabovearabic'] = 0x0623;
  10054. t['alefhamzaabovefinalarabic'] = 0xFE84;
  10055. t['alefhamzabelowarabic'] = 0x0625;
  10056. t['alefhamzabelowfinalarabic'] = 0xFE88;
  10057. t['alefhebrew'] = 0x05D0;
  10058. t['aleflamedhebrew'] = 0xFB4F;
  10059. t['alefmaddaabovearabic'] = 0x0622;
  10060. t['alefmaddaabovefinalarabic'] = 0xFE82;
  10061. t['alefmaksuraarabic'] = 0x0649;
  10062. t['alefmaksurafinalarabic'] = 0xFEF0;
  10063. t['alefmaksurainitialarabic'] = 0xFEF3;
  10064. t['alefmaksuramedialarabic'] = 0xFEF4;
  10065. t['alefpatahhebrew'] = 0xFB2E;
  10066. t['alefqamatshebrew'] = 0xFB2F;
  10067. t['aleph'] = 0x2135;
  10068. t['allequal'] = 0x224C;
  10069. t['alpha'] = 0x03B1;
  10070. t['alphatonos'] = 0x03AC;
  10071. t['amacron'] = 0x0101;
  10072. t['amonospace'] = 0xFF41;
  10073. t['ampersand'] = 0x0026;
  10074. t['ampersandmonospace'] = 0xFF06;
  10075. t['ampersandsmall'] = 0xF726;
  10076. t['amsquare'] = 0x33C2;
  10077. t['anbopomofo'] = 0x3122;
  10078. t['angbopomofo'] = 0x3124;
  10079. t['angbracketleft'] = 0x3008;
  10080. // Glyph is missing from Adobe's original list.
  10081. t['angbracketright'] = 0x3009;
  10082. // Glyph is missing from Adobe's original list.
  10083. t['angkhankhuthai'] = 0x0E5A;
  10084. t['angle'] = 0x2220;
  10085. t['anglebracketleft'] = 0x3008;
  10086. t['anglebracketleftvertical'] = 0xFE3F;
  10087. t['anglebracketright'] = 0x3009;
  10088. t['anglebracketrightvertical'] = 0xFE40;
  10089. t['angleleft'] = 0x2329;
  10090. t['angleright'] = 0x232A;
  10091. t['angstrom'] = 0x212B;
  10092. t['anoteleia'] = 0x0387;
  10093. t['anudattadeva'] = 0x0952;
  10094. t['anusvarabengali'] = 0x0982;
  10095. t['anusvaradeva'] = 0x0902;
  10096. t['anusvaragujarati'] = 0x0A82;
  10097. t['aogonek'] = 0x0105;
  10098. t['apaatosquare'] = 0x3300;
  10099. t['aparen'] = 0x249C;
  10100. t['apostrophearmenian'] = 0x055A;
  10101. t['apostrophemod'] = 0x02BC;
  10102. t['apple'] = 0xF8FF;
  10103. t['approaches'] = 0x2250;
  10104. t['approxequal'] = 0x2248;
  10105. t['approxequalorimage'] = 0x2252;
  10106. t['approximatelyequal'] = 0x2245;
  10107. t['araeaekorean'] = 0x318E;
  10108. t['araeakorean'] = 0x318D;
  10109. t['arc'] = 0x2312;
  10110. t['arighthalfring'] = 0x1E9A;
  10111. t['aring'] = 0x00E5;
  10112. t['aringacute'] = 0x01FB;
  10113. t['aringbelow'] = 0x1E01;
  10114. t['arrowboth'] = 0x2194;
  10115. t['arrowdashdown'] = 0x21E3;
  10116. t['arrowdashleft'] = 0x21E0;
  10117. t['arrowdashright'] = 0x21E2;
  10118. t['arrowdashup'] = 0x21E1;
  10119. t['arrowdblboth'] = 0x21D4;
  10120. t['arrowdbldown'] = 0x21D3;
  10121. t['arrowdblleft'] = 0x21D0;
  10122. t['arrowdblright'] = 0x21D2;
  10123. t['arrowdblup'] = 0x21D1;
  10124. t['arrowdown'] = 0x2193;
  10125. t['arrowdownleft'] = 0x2199;
  10126. t['arrowdownright'] = 0x2198;
  10127. t['arrowdownwhite'] = 0x21E9;
  10128. t['arrowheaddownmod'] = 0x02C5;
  10129. t['arrowheadleftmod'] = 0x02C2;
  10130. t['arrowheadrightmod'] = 0x02C3;
  10131. t['arrowheadupmod'] = 0x02C4;
  10132. t['arrowhorizex'] = 0xF8E7;
  10133. t['arrowleft'] = 0x2190;
  10134. t['arrowleftdbl'] = 0x21D0;
  10135. t['arrowleftdblstroke'] = 0x21CD;
  10136. t['arrowleftoverright'] = 0x21C6;
  10137. t['arrowleftwhite'] = 0x21E6;
  10138. t['arrowright'] = 0x2192;
  10139. t['arrowrightdblstroke'] = 0x21CF;
  10140. t['arrowrightheavy'] = 0x279E;
  10141. t['arrowrightoverleft'] = 0x21C4;
  10142. t['arrowrightwhite'] = 0x21E8;
  10143. t['arrowtableft'] = 0x21E4;
  10144. t['arrowtabright'] = 0x21E5;
  10145. t['arrowup'] = 0x2191;
  10146. t['arrowupdn'] = 0x2195;
  10147. t['arrowupdnbse'] = 0x21A8;
  10148. t['arrowupdownbase'] = 0x21A8;
  10149. t['arrowupleft'] = 0x2196;
  10150. t['arrowupleftofdown'] = 0x21C5;
  10151. t['arrowupright'] = 0x2197;
  10152. t['arrowupwhite'] = 0x21E7;
  10153. t['arrowvertex'] = 0xF8E6;
  10154. t['asciicircum'] = 0x005E;
  10155. t['asciicircummonospace'] = 0xFF3E;
  10156. t['asciitilde'] = 0x007E;
  10157. t['asciitildemonospace'] = 0xFF5E;
  10158. t['ascript'] = 0x0251;
  10159. t['ascriptturned'] = 0x0252;
  10160. t['asmallhiragana'] = 0x3041;
  10161. t['asmallkatakana'] = 0x30A1;
  10162. t['asmallkatakanahalfwidth'] = 0xFF67;
  10163. t['asterisk'] = 0x002A;
  10164. t['asteriskaltonearabic'] = 0x066D;
  10165. t['asteriskarabic'] = 0x066D;
  10166. t['asteriskmath'] = 0x2217;
  10167. t['asteriskmonospace'] = 0xFF0A;
  10168. t['asterisksmall'] = 0xFE61;
  10169. t['asterism'] = 0x2042;
  10170. t['asuperior'] = 0xF6E9;
  10171. t['asymptoticallyequal'] = 0x2243;
  10172. t['at'] = 0x0040;
  10173. t['atilde'] = 0x00E3;
  10174. t['atmonospace'] = 0xFF20;
  10175. t['atsmall'] = 0xFE6B;
  10176. t['aturned'] = 0x0250;
  10177. t['aubengali'] = 0x0994;
  10178. t['aubopomofo'] = 0x3120;
  10179. t['audeva'] = 0x0914;
  10180. t['augujarati'] = 0x0A94;
  10181. t['augurmukhi'] = 0x0A14;
  10182. t['aulengthmarkbengali'] = 0x09D7;
  10183. t['aumatragurmukhi'] = 0x0A4C;
  10184. t['auvowelsignbengali'] = 0x09CC;
  10185. t['auvowelsigndeva'] = 0x094C;
  10186. t['auvowelsigngujarati'] = 0x0ACC;
  10187. t['avagrahadeva'] = 0x093D;
  10188. t['aybarmenian'] = 0x0561;
  10189. t['ayin'] = 0x05E2;
  10190. t['ayinaltonehebrew'] = 0xFB20;
  10191. t['ayinhebrew'] = 0x05E2;
  10192. t['b'] = 0x0062;
  10193. t['babengali'] = 0x09AC;
  10194. t['backslash'] = 0x005C;
  10195. t['backslashmonospace'] = 0xFF3C;
  10196. t['badeva'] = 0x092C;
  10197. t['bagujarati'] = 0x0AAC;
  10198. t['bagurmukhi'] = 0x0A2C;
  10199. t['bahiragana'] = 0x3070;
  10200. t['bahtthai'] = 0x0E3F;
  10201. t['bakatakana'] = 0x30D0;
  10202. t['bar'] = 0x007C;
  10203. t['barmonospace'] = 0xFF5C;
  10204. t['bbopomofo'] = 0x3105;
  10205. t['bcircle'] = 0x24D1;
  10206. t['bdotaccent'] = 0x1E03;
  10207. t['bdotbelow'] = 0x1E05;
  10208. t['beamedsixteenthnotes'] = 0x266C;
  10209. t['because'] = 0x2235;
  10210. t['becyrillic'] = 0x0431;
  10211. t['beharabic'] = 0x0628;
  10212. t['behfinalarabic'] = 0xFE90;
  10213. t['behinitialarabic'] = 0xFE91;
  10214. t['behiragana'] = 0x3079;
  10215. t['behmedialarabic'] = 0xFE92;
  10216. t['behmeeminitialarabic'] = 0xFC9F;
  10217. t['behmeemisolatedarabic'] = 0xFC08;
  10218. t['behnoonfinalarabic'] = 0xFC6D;
  10219. t['bekatakana'] = 0x30D9;
  10220. t['benarmenian'] = 0x0562;
  10221. t['bet'] = 0x05D1;
  10222. t['beta'] = 0x03B2;
  10223. t['betasymbolgreek'] = 0x03D0;
  10224. t['betdagesh'] = 0xFB31;
  10225. t['betdageshhebrew'] = 0xFB31;
  10226. t['bethebrew'] = 0x05D1;
  10227. t['betrafehebrew'] = 0xFB4C;
  10228. t['bhabengali'] = 0x09AD;
  10229. t['bhadeva'] = 0x092D;
  10230. t['bhagujarati'] = 0x0AAD;
  10231. t['bhagurmukhi'] = 0x0A2D;
  10232. t['bhook'] = 0x0253;
  10233. t['bihiragana'] = 0x3073;
  10234. t['bikatakana'] = 0x30D3;
  10235. t['bilabialclick'] = 0x0298;
  10236. t['bindigurmukhi'] = 0x0A02;
  10237. t['birusquare'] = 0x3331;
  10238. t['blackcircle'] = 0x25CF;
  10239. t['blackdiamond'] = 0x25C6;
  10240. t['blackdownpointingtriangle'] = 0x25BC;
  10241. t['blackleftpointingpointer'] = 0x25C4;
  10242. t['blackleftpointingtriangle'] = 0x25C0;
  10243. t['blacklenticularbracketleft'] = 0x3010;
  10244. t['blacklenticularbracketleftvertical'] = 0xFE3B;
  10245. t['blacklenticularbracketright'] = 0x3011;
  10246. t['blacklenticularbracketrightvertical'] = 0xFE3C;
  10247. t['blacklowerlefttriangle'] = 0x25E3;
  10248. t['blacklowerrighttriangle'] = 0x25E2;
  10249. t['blackrectangle'] = 0x25AC;
  10250. t['blackrightpointingpointer'] = 0x25BA;
  10251. t['blackrightpointingtriangle'] = 0x25B6;
  10252. t['blacksmallsquare'] = 0x25AA;
  10253. t['blacksmilingface'] = 0x263B;
  10254. t['blacksquare'] = 0x25A0;
  10255. t['blackstar'] = 0x2605;
  10256. t['blackupperlefttriangle'] = 0x25E4;
  10257. t['blackupperrighttriangle'] = 0x25E5;
  10258. t['blackuppointingsmalltriangle'] = 0x25B4;
  10259. t['blackuppointingtriangle'] = 0x25B2;
  10260. t['blank'] = 0x2423;
  10261. t['blinebelow'] = 0x1E07;
  10262. t['block'] = 0x2588;
  10263. t['bmonospace'] = 0xFF42;
  10264. t['bobaimaithai'] = 0x0E1A;
  10265. t['bohiragana'] = 0x307C;
  10266. t['bokatakana'] = 0x30DC;
  10267. t['bparen'] = 0x249D;
  10268. t['bqsquare'] = 0x33C3;
  10269. t['braceex'] = 0xF8F4;
  10270. t['braceleft'] = 0x007B;
  10271. t['braceleftbt'] = 0xF8F3;
  10272. t['braceleftmid'] = 0xF8F2;
  10273. t['braceleftmonospace'] = 0xFF5B;
  10274. t['braceleftsmall'] = 0xFE5B;
  10275. t['bracelefttp'] = 0xF8F1;
  10276. t['braceleftvertical'] = 0xFE37;
  10277. t['braceright'] = 0x007D;
  10278. t['bracerightbt'] = 0xF8FE;
  10279. t['bracerightmid'] = 0xF8FD;
  10280. t['bracerightmonospace'] = 0xFF5D;
  10281. t['bracerightsmall'] = 0xFE5C;
  10282. t['bracerighttp'] = 0xF8FC;
  10283. t['bracerightvertical'] = 0xFE38;
  10284. t['bracketleft'] = 0x005B;
  10285. t['bracketleftbt'] = 0xF8F0;
  10286. t['bracketleftex'] = 0xF8EF;
  10287. t['bracketleftmonospace'] = 0xFF3B;
  10288. t['bracketlefttp'] = 0xF8EE;
  10289. t['bracketright'] = 0x005D;
  10290. t['bracketrightbt'] = 0xF8FB;
  10291. t['bracketrightex'] = 0xF8FA;
  10292. t['bracketrightmonospace'] = 0xFF3D;
  10293. t['bracketrighttp'] = 0xF8F9;
  10294. t['breve'] = 0x02D8;
  10295. t['brevebelowcmb'] = 0x032E;
  10296. t['brevecmb'] = 0x0306;
  10297. t['breveinvertedbelowcmb'] = 0x032F;
  10298. t['breveinvertedcmb'] = 0x0311;
  10299. t['breveinverteddoublecmb'] = 0x0361;
  10300. t['bridgebelowcmb'] = 0x032A;
  10301. t['bridgeinvertedbelowcmb'] = 0x033A;
  10302. t['brokenbar'] = 0x00A6;
  10303. t['bstroke'] = 0x0180;
  10304. t['bsuperior'] = 0xF6EA;
  10305. t['btopbar'] = 0x0183;
  10306. t['buhiragana'] = 0x3076;
  10307. t['bukatakana'] = 0x30D6;
  10308. t['bullet'] = 0x2022;
  10309. t['bulletinverse'] = 0x25D8;
  10310. t['bulletoperator'] = 0x2219;
  10311. t['bullseye'] = 0x25CE;
  10312. t['c'] = 0x0063;
  10313. t['caarmenian'] = 0x056E;
  10314. t['cabengali'] = 0x099A;
  10315. t['cacute'] = 0x0107;
  10316. t['cadeva'] = 0x091A;
  10317. t['cagujarati'] = 0x0A9A;
  10318. t['cagurmukhi'] = 0x0A1A;
  10319. t['calsquare'] = 0x3388;
  10320. t['candrabindubengali'] = 0x0981;
  10321. t['candrabinducmb'] = 0x0310;
  10322. t['candrabindudeva'] = 0x0901;
  10323. t['candrabindugujarati'] = 0x0A81;
  10324. t['capslock'] = 0x21EA;
  10325. t['careof'] = 0x2105;
  10326. t['caron'] = 0x02C7;
  10327. t['caronbelowcmb'] = 0x032C;
  10328. t['caroncmb'] = 0x030C;
  10329. t['carriagereturn'] = 0x21B5;
  10330. t['cbopomofo'] = 0x3118;
  10331. t['ccaron'] = 0x010D;
  10332. t['ccedilla'] = 0x00E7;
  10333. t['ccedillaacute'] = 0x1E09;
  10334. t['ccircle'] = 0x24D2;
  10335. t['ccircumflex'] = 0x0109;
  10336. t['ccurl'] = 0x0255;
  10337. t['cdot'] = 0x010B;
  10338. t['cdotaccent'] = 0x010B;
  10339. t['cdsquare'] = 0x33C5;
  10340. t['cedilla'] = 0x00B8;
  10341. t['cedillacmb'] = 0x0327;
  10342. t['cent'] = 0x00A2;
  10343. t['centigrade'] = 0x2103;
  10344. t['centinferior'] = 0xF6DF;
  10345. t['centmonospace'] = 0xFFE0;
  10346. t['centoldstyle'] = 0xF7A2;
  10347. t['centsuperior'] = 0xF6E0;
  10348. t['chaarmenian'] = 0x0579;
  10349. t['chabengali'] = 0x099B;
  10350. t['chadeva'] = 0x091B;
  10351. t['chagujarati'] = 0x0A9B;
  10352. t['chagurmukhi'] = 0x0A1B;
  10353. t['chbopomofo'] = 0x3114;
  10354. t['cheabkhasiancyrillic'] = 0x04BD;
  10355. t['checkmark'] = 0x2713;
  10356. t['checyrillic'] = 0x0447;
  10357. t['chedescenderabkhasiancyrillic'] = 0x04BF;
  10358. t['chedescendercyrillic'] = 0x04B7;
  10359. t['chedieresiscyrillic'] = 0x04F5;
  10360. t['cheharmenian'] = 0x0573;
  10361. t['chekhakassiancyrillic'] = 0x04CC;
  10362. t['cheverticalstrokecyrillic'] = 0x04B9;
  10363. t['chi'] = 0x03C7;
  10364. t['chieuchacirclekorean'] = 0x3277;
  10365. t['chieuchaparenkorean'] = 0x3217;
  10366. t['chieuchcirclekorean'] = 0x3269;
  10367. t['chieuchkorean'] = 0x314A;
  10368. t['chieuchparenkorean'] = 0x3209;
  10369. t['chochangthai'] = 0x0E0A;
  10370. t['chochanthai'] = 0x0E08;
  10371. t['chochingthai'] = 0x0E09;
  10372. t['chochoethai'] = 0x0E0C;
  10373. t['chook'] = 0x0188;
  10374. t['cieucacirclekorean'] = 0x3276;
  10375. t['cieucaparenkorean'] = 0x3216;
  10376. t['cieuccirclekorean'] = 0x3268;
  10377. t['cieuckorean'] = 0x3148;
  10378. t['cieucparenkorean'] = 0x3208;
  10379. t['cieucuparenkorean'] = 0x321C;
  10380. t['circle'] = 0x25CB;
  10381. t['circlecopyrt'] = 0x00A9;
  10382. // Glyph is missing from Adobe's original list.
  10383. t['circlemultiply'] = 0x2297;
  10384. t['circleot'] = 0x2299;
  10385. t['circleplus'] = 0x2295;
  10386. t['circlepostalmark'] = 0x3036;
  10387. t['circlewithlefthalfblack'] = 0x25D0;
  10388. t['circlewithrighthalfblack'] = 0x25D1;
  10389. t['circumflex'] = 0x02C6;
  10390. t['circumflexbelowcmb'] = 0x032D;
  10391. t['circumflexcmb'] = 0x0302;
  10392. t['clear'] = 0x2327;
  10393. t['clickalveolar'] = 0x01C2;
  10394. t['clickdental'] = 0x01C0;
  10395. t['clicklateral'] = 0x01C1;
  10396. t['clickretroflex'] = 0x01C3;
  10397. t['club'] = 0x2663;
  10398. t['clubsuitblack'] = 0x2663;
  10399. t['clubsuitwhite'] = 0x2667;
  10400. t['cmcubedsquare'] = 0x33A4;
  10401. t['cmonospace'] = 0xFF43;
  10402. t['cmsquaredsquare'] = 0x33A0;
  10403. t['coarmenian'] = 0x0581;
  10404. t['colon'] = 0x003A;
  10405. t['colonmonetary'] = 0x20A1;
  10406. t['colonmonospace'] = 0xFF1A;
  10407. t['colonsign'] = 0x20A1;
  10408. t['colonsmall'] = 0xFE55;
  10409. t['colontriangularhalfmod'] = 0x02D1;
  10410. t['colontriangularmod'] = 0x02D0;
  10411. t['comma'] = 0x002C;
  10412. t['commaabovecmb'] = 0x0313;
  10413. t['commaaboverightcmb'] = 0x0315;
  10414. t['commaaccent'] = 0xF6C3;
  10415. t['commaarabic'] = 0x060C;
  10416. t['commaarmenian'] = 0x055D;
  10417. t['commainferior'] = 0xF6E1;
  10418. t['commamonospace'] = 0xFF0C;
  10419. t['commareversedabovecmb'] = 0x0314;
  10420. t['commareversedmod'] = 0x02BD;
  10421. t['commasmall'] = 0xFE50;
  10422. t['commasuperior'] = 0xF6E2;
  10423. t['commaturnedabovecmb'] = 0x0312;
  10424. t['commaturnedmod'] = 0x02BB;
  10425. t['compass'] = 0x263C;
  10426. t['congruent'] = 0x2245;
  10427. t['contourintegral'] = 0x222E;
  10428. t['control'] = 0x2303;
  10429. t['controlACK'] = 0x0006;
  10430. t['controlBEL'] = 0x0007;
  10431. t['controlBS'] = 0x0008;
  10432. t['controlCAN'] = 0x0018;
  10433. t['controlCR'] = 0x000D;
  10434. t['controlDC1'] = 0x0011;
  10435. t['controlDC2'] = 0x0012;
  10436. t['controlDC3'] = 0x0013;
  10437. t['controlDC4'] = 0x0014;
  10438. t['controlDEL'] = 0x007F;
  10439. t['controlDLE'] = 0x0010;
  10440. t['controlEM'] = 0x0019;
  10441. t['controlENQ'] = 0x0005;
  10442. t['controlEOT'] = 0x0004;
  10443. t['controlESC'] = 0x001B;
  10444. t['controlETB'] = 0x0017;
  10445. t['controlETX'] = 0x0003;
  10446. t['controlFF'] = 0x000C;
  10447. t['controlFS'] = 0x001C;
  10448. t['controlGS'] = 0x001D;
  10449. t['controlHT'] = 0x0009;
  10450. t['controlLF'] = 0x000A;
  10451. t['controlNAK'] = 0x0015;
  10452. t['controlRS'] = 0x001E;
  10453. t['controlSI'] = 0x000F;
  10454. t['controlSO'] = 0x000E;
  10455. t['controlSOT'] = 0x0002;
  10456. t['controlSTX'] = 0x0001;
  10457. t['controlSUB'] = 0x001A;
  10458. t['controlSYN'] = 0x0016;
  10459. t['controlUS'] = 0x001F;
  10460. t['controlVT'] = 0x000B;
  10461. t['copyright'] = 0x00A9;
  10462. t['copyrightsans'] = 0xF8E9;
  10463. t['copyrightserif'] = 0xF6D9;
  10464. t['cornerbracketleft'] = 0x300C;
  10465. t['cornerbracketlefthalfwidth'] = 0xFF62;
  10466. t['cornerbracketleftvertical'] = 0xFE41;
  10467. t['cornerbracketright'] = 0x300D;
  10468. t['cornerbracketrighthalfwidth'] = 0xFF63;
  10469. t['cornerbracketrightvertical'] = 0xFE42;
  10470. t['corporationsquare'] = 0x337F;
  10471. t['cosquare'] = 0x33C7;
  10472. t['coverkgsquare'] = 0x33C6;
  10473. t['cparen'] = 0x249E;
  10474. t['cruzeiro'] = 0x20A2;
  10475. t['cstretched'] = 0x0297;
  10476. t['curlyand'] = 0x22CF;
  10477. t['curlyor'] = 0x22CE;
  10478. t['currency'] = 0x00A4;
  10479. t['cyrBreve'] = 0xF6D1;
  10480. t['cyrFlex'] = 0xF6D2;
  10481. t['cyrbreve'] = 0xF6D4;
  10482. t['cyrflex'] = 0xF6D5;
  10483. t['d'] = 0x0064;
  10484. t['daarmenian'] = 0x0564;
  10485. t['dabengali'] = 0x09A6;
  10486. t['dadarabic'] = 0x0636;
  10487. t['dadeva'] = 0x0926;
  10488. t['dadfinalarabic'] = 0xFEBE;
  10489. t['dadinitialarabic'] = 0xFEBF;
  10490. t['dadmedialarabic'] = 0xFEC0;
  10491. t['dagesh'] = 0x05BC;
  10492. t['dageshhebrew'] = 0x05BC;
  10493. t['dagger'] = 0x2020;
  10494. t['daggerdbl'] = 0x2021;
  10495. t['dagujarati'] = 0x0AA6;
  10496. t['dagurmukhi'] = 0x0A26;
  10497. t['dahiragana'] = 0x3060;
  10498. t['dakatakana'] = 0x30C0;
  10499. t['dalarabic'] = 0x062F;
  10500. t['dalet'] = 0x05D3;
  10501. t['daletdagesh'] = 0xFB33;
  10502. t['daletdageshhebrew'] = 0xFB33;
  10503. t['dalethebrew'] = 0x05D3;
  10504. t['dalfinalarabic'] = 0xFEAA;
  10505. t['dammaarabic'] = 0x064F;
  10506. t['dammalowarabic'] = 0x064F;
  10507. t['dammatanaltonearabic'] = 0x064C;
  10508. t['dammatanarabic'] = 0x064C;
  10509. t['danda'] = 0x0964;
  10510. t['dargahebrew'] = 0x05A7;
  10511. t['dargalefthebrew'] = 0x05A7;
  10512. t['dasiapneumatacyrilliccmb'] = 0x0485;
  10513. t['dblGrave'] = 0xF6D3;
  10514. t['dblanglebracketleft'] = 0x300A;
  10515. t['dblanglebracketleftvertical'] = 0xFE3D;
  10516. t['dblanglebracketright'] = 0x300B;
  10517. t['dblanglebracketrightvertical'] = 0xFE3E;
  10518. t['dblarchinvertedbelowcmb'] = 0x032B;
  10519. t['dblarrowleft'] = 0x21D4;
  10520. t['dblarrowright'] = 0x21D2;
  10521. t['dbldanda'] = 0x0965;
  10522. t['dblgrave'] = 0xF6D6;
  10523. t['dblgravecmb'] = 0x030F;
  10524. t['dblintegral'] = 0x222C;
  10525. t['dbllowline'] = 0x2017;
  10526. t['dbllowlinecmb'] = 0x0333;
  10527. t['dbloverlinecmb'] = 0x033F;
  10528. t['dblprimemod'] = 0x02BA;
  10529. t['dblverticalbar'] = 0x2016;
  10530. t['dblverticallineabovecmb'] = 0x030E;
  10531. t['dbopomofo'] = 0x3109;
  10532. t['dbsquare'] = 0x33C8;
  10533. t['dcaron'] = 0x010F;
  10534. t['dcedilla'] = 0x1E11;
  10535. t['dcircle'] = 0x24D3;
  10536. t['dcircumflexbelow'] = 0x1E13;
  10537. t['dcroat'] = 0x0111;
  10538. t['ddabengali'] = 0x09A1;
  10539. t['ddadeva'] = 0x0921;
  10540. t['ddagujarati'] = 0x0AA1;
  10541. t['ddagurmukhi'] = 0x0A21;
  10542. t['ddalarabic'] = 0x0688;
  10543. t['ddalfinalarabic'] = 0xFB89;
  10544. t['dddhadeva'] = 0x095C;
  10545. t['ddhabengali'] = 0x09A2;
  10546. t['ddhadeva'] = 0x0922;
  10547. t['ddhagujarati'] = 0x0AA2;
  10548. t['ddhagurmukhi'] = 0x0A22;
  10549. t['ddotaccent'] = 0x1E0B;
  10550. t['ddotbelow'] = 0x1E0D;
  10551. t['decimalseparatorarabic'] = 0x066B;
  10552. t['decimalseparatorpersian'] = 0x066B;
  10553. t['decyrillic'] = 0x0434;
  10554. t['degree'] = 0x00B0;
  10555. t['dehihebrew'] = 0x05AD;
  10556. t['dehiragana'] = 0x3067;
  10557. t['deicoptic'] = 0x03EF;
  10558. t['dekatakana'] = 0x30C7;
  10559. t['deleteleft'] = 0x232B;
  10560. t['deleteright'] = 0x2326;
  10561. t['delta'] = 0x03B4;
  10562. t['deltaturned'] = 0x018D;
  10563. t['denominatorminusonenumeratorbengali'] = 0x09F8;
  10564. t['dezh'] = 0x02A4;
  10565. t['dhabengali'] = 0x09A7;
  10566. t['dhadeva'] = 0x0927;
  10567. t['dhagujarati'] = 0x0AA7;
  10568. t['dhagurmukhi'] = 0x0A27;
  10569. t['dhook'] = 0x0257;
  10570. t['dialytikatonos'] = 0x0385;
  10571. t['dialytikatonoscmb'] = 0x0344;
  10572. t['diamond'] = 0x2666;
  10573. t['diamondsuitwhite'] = 0x2662;
  10574. t['dieresis'] = 0x00A8;
  10575. t['dieresisacute'] = 0xF6D7;
  10576. t['dieresisbelowcmb'] = 0x0324;
  10577. t['dieresiscmb'] = 0x0308;
  10578. t['dieresisgrave'] = 0xF6D8;
  10579. t['dieresistonos'] = 0x0385;
  10580. t['dihiragana'] = 0x3062;
  10581. t['dikatakana'] = 0x30C2;
  10582. t['dittomark'] = 0x3003;
  10583. t['divide'] = 0x00F7;
  10584. t['divides'] = 0x2223;
  10585. t['divisionslash'] = 0x2215;
  10586. t['djecyrillic'] = 0x0452;
  10587. t['dkshade'] = 0x2593;
  10588. t['dlinebelow'] = 0x1E0F;
  10589. t['dlsquare'] = 0x3397;
  10590. t['dmacron'] = 0x0111;
  10591. t['dmonospace'] = 0xFF44;
  10592. t['dnblock'] = 0x2584;
  10593. t['dochadathai'] = 0x0E0E;
  10594. t['dodekthai'] = 0x0E14;
  10595. t['dohiragana'] = 0x3069;
  10596. t['dokatakana'] = 0x30C9;
  10597. t['dollar'] = 0x0024;
  10598. t['dollarinferior'] = 0xF6E3;
  10599. t['dollarmonospace'] = 0xFF04;
  10600. t['dollaroldstyle'] = 0xF724;
  10601. t['dollarsmall'] = 0xFE69;
  10602. t['dollarsuperior'] = 0xF6E4;
  10603. t['dong'] = 0x20AB;
  10604. t['dorusquare'] = 0x3326;
  10605. t['dotaccent'] = 0x02D9;
  10606. t['dotaccentcmb'] = 0x0307;
  10607. t['dotbelowcmb'] = 0x0323;
  10608. t['dotbelowcomb'] = 0x0323;
  10609. t['dotkatakana'] = 0x30FB;
  10610. t['dotlessi'] = 0x0131;
  10611. t['dotlessj'] = 0xF6BE;
  10612. t['dotlessjstrokehook'] = 0x0284;
  10613. t['dotmath'] = 0x22C5;
  10614. t['dottedcircle'] = 0x25CC;
  10615. t['doubleyodpatah'] = 0xFB1F;
  10616. t['doubleyodpatahhebrew'] = 0xFB1F;
  10617. t['downtackbelowcmb'] = 0x031E;
  10618. t['downtackmod'] = 0x02D5;
  10619. t['dparen'] = 0x249F;
  10620. t['dsuperior'] = 0xF6EB;
  10621. t['dtail'] = 0x0256;
  10622. t['dtopbar'] = 0x018C;
  10623. t['duhiragana'] = 0x3065;
  10624. t['dukatakana'] = 0x30C5;
  10625. t['dz'] = 0x01F3;
  10626. t['dzaltone'] = 0x02A3;
  10627. t['dzcaron'] = 0x01C6;
  10628. t['dzcurl'] = 0x02A5;
  10629. t['dzeabkhasiancyrillic'] = 0x04E1;
  10630. t['dzecyrillic'] = 0x0455;
  10631. t['dzhecyrillic'] = 0x045F;
  10632. t['e'] = 0x0065;
  10633. t['eacute'] = 0x00E9;
  10634. t['earth'] = 0x2641;
  10635. t['ebengali'] = 0x098F;
  10636. t['ebopomofo'] = 0x311C;
  10637. t['ebreve'] = 0x0115;
  10638. t['ecandradeva'] = 0x090D;
  10639. t['ecandragujarati'] = 0x0A8D;
  10640. t['ecandravowelsigndeva'] = 0x0945;
  10641. t['ecandravowelsigngujarati'] = 0x0AC5;
  10642. t['ecaron'] = 0x011B;
  10643. t['ecedillabreve'] = 0x1E1D;
  10644. t['echarmenian'] = 0x0565;
  10645. t['echyiwnarmenian'] = 0x0587;
  10646. t['ecircle'] = 0x24D4;
  10647. t['ecircumflex'] = 0x00EA;
  10648. t['ecircumflexacute'] = 0x1EBF;
  10649. t['ecircumflexbelow'] = 0x1E19;
  10650. t['ecircumflexdotbelow'] = 0x1EC7;
  10651. t['ecircumflexgrave'] = 0x1EC1;
  10652. t['ecircumflexhookabove'] = 0x1EC3;
  10653. t['ecircumflextilde'] = 0x1EC5;
  10654. t['ecyrillic'] = 0x0454;
  10655. t['edblgrave'] = 0x0205;
  10656. t['edeva'] = 0x090F;
  10657. t['edieresis'] = 0x00EB;
  10658. t['edot'] = 0x0117;
  10659. t['edotaccent'] = 0x0117;
  10660. t['edotbelow'] = 0x1EB9;
  10661. t['eegurmukhi'] = 0x0A0F;
  10662. t['eematragurmukhi'] = 0x0A47;
  10663. t['efcyrillic'] = 0x0444;
  10664. t['egrave'] = 0x00E8;
  10665. t['egujarati'] = 0x0A8F;
  10666. t['eharmenian'] = 0x0567;
  10667. t['ehbopomofo'] = 0x311D;
  10668. t['ehiragana'] = 0x3048;
  10669. t['ehookabove'] = 0x1EBB;
  10670. t['eibopomofo'] = 0x311F;
  10671. t['eight'] = 0x0038;
  10672. t['eightarabic'] = 0x0668;
  10673. t['eightbengali'] = 0x09EE;
  10674. t['eightcircle'] = 0x2467;
  10675. t['eightcircleinversesansserif'] = 0x2791;
  10676. t['eightdeva'] = 0x096E;
  10677. t['eighteencircle'] = 0x2471;
  10678. t['eighteenparen'] = 0x2485;
  10679. t['eighteenperiod'] = 0x2499;
  10680. t['eightgujarati'] = 0x0AEE;
  10681. t['eightgurmukhi'] = 0x0A6E;
  10682. t['eighthackarabic'] = 0x0668;
  10683. t['eighthangzhou'] = 0x3028;
  10684. t['eighthnotebeamed'] = 0x266B;
  10685. t['eightideographicparen'] = 0x3227;
  10686. t['eightinferior'] = 0x2088;
  10687. t['eightmonospace'] = 0xFF18;
  10688. t['eightoldstyle'] = 0xF738;
  10689. t['eightparen'] = 0x247B;
  10690. t['eightperiod'] = 0x248F;
  10691. t['eightpersian'] = 0x06F8;
  10692. t['eightroman'] = 0x2177;
  10693. t['eightsuperior'] = 0x2078;
  10694. t['eightthai'] = 0x0E58;
  10695. t['einvertedbreve'] = 0x0207;
  10696. t['eiotifiedcyrillic'] = 0x0465;
  10697. t['ekatakana'] = 0x30A8;
  10698. t['ekatakanahalfwidth'] = 0xFF74;
  10699. t['ekonkargurmukhi'] = 0x0A74;
  10700. t['ekorean'] = 0x3154;
  10701. t['elcyrillic'] = 0x043B;
  10702. t['element'] = 0x2208;
  10703. t['elevencircle'] = 0x246A;
  10704. t['elevenparen'] = 0x247E;
  10705. t['elevenperiod'] = 0x2492;
  10706. t['elevenroman'] = 0x217A;
  10707. t['ellipsis'] = 0x2026;
  10708. t['ellipsisvertical'] = 0x22EE;
  10709. t['emacron'] = 0x0113;
  10710. t['emacronacute'] = 0x1E17;
  10711. t['emacrongrave'] = 0x1E15;
  10712. t['emcyrillic'] = 0x043C;
  10713. t['emdash'] = 0x2014;
  10714. t['emdashvertical'] = 0xFE31;
  10715. t['emonospace'] = 0xFF45;
  10716. t['emphasismarkarmenian'] = 0x055B;
  10717. t['emptyset'] = 0x2205;
  10718. t['enbopomofo'] = 0x3123;
  10719. t['encyrillic'] = 0x043D;
  10720. t['endash'] = 0x2013;
  10721. t['endashvertical'] = 0xFE32;
  10722. t['endescendercyrillic'] = 0x04A3;
  10723. t['eng'] = 0x014B;
  10724. t['engbopomofo'] = 0x3125;
  10725. t['enghecyrillic'] = 0x04A5;
  10726. t['enhookcyrillic'] = 0x04C8;
  10727. t['enspace'] = 0x2002;
  10728. t['eogonek'] = 0x0119;
  10729. t['eokorean'] = 0x3153;
  10730. t['eopen'] = 0x025B;
  10731. t['eopenclosed'] = 0x029A;
  10732. t['eopenreversed'] = 0x025C;
  10733. t['eopenreversedclosed'] = 0x025E;
  10734. t['eopenreversedhook'] = 0x025D;
  10735. t['eparen'] = 0x24A0;
  10736. t['epsilon'] = 0x03B5;
  10737. t['epsilontonos'] = 0x03AD;
  10738. t['equal'] = 0x003D;
  10739. t['equalmonospace'] = 0xFF1D;
  10740. t['equalsmall'] = 0xFE66;
  10741. t['equalsuperior'] = 0x207C;
  10742. t['equivalence'] = 0x2261;
  10743. t['erbopomofo'] = 0x3126;
  10744. t['ercyrillic'] = 0x0440;
  10745. t['ereversed'] = 0x0258;
  10746. t['ereversedcyrillic'] = 0x044D;
  10747. t['escyrillic'] = 0x0441;
  10748. t['esdescendercyrillic'] = 0x04AB;
  10749. t['esh'] = 0x0283;
  10750. t['eshcurl'] = 0x0286;
  10751. t['eshortdeva'] = 0x090E;
  10752. t['eshortvowelsigndeva'] = 0x0946;
  10753. t['eshreversedloop'] = 0x01AA;
  10754. t['eshsquatreversed'] = 0x0285;
  10755. t['esmallhiragana'] = 0x3047;
  10756. t['esmallkatakana'] = 0x30A7;
  10757. t['esmallkatakanahalfwidth'] = 0xFF6A;
  10758. t['estimated'] = 0x212E;
  10759. t['esuperior'] = 0xF6EC;
  10760. t['eta'] = 0x03B7;
  10761. t['etarmenian'] = 0x0568;
  10762. t['etatonos'] = 0x03AE;
  10763. t['eth'] = 0x00F0;
  10764. t['etilde'] = 0x1EBD;
  10765. t['etildebelow'] = 0x1E1B;
  10766. t['etnahtafoukhhebrew'] = 0x0591;
  10767. t['etnahtafoukhlefthebrew'] = 0x0591;
  10768. t['etnahtahebrew'] = 0x0591;
  10769. t['etnahtalefthebrew'] = 0x0591;
  10770. t['eturned'] = 0x01DD;
  10771. t['eukorean'] = 0x3161;
  10772. t['euro'] = 0x20AC;
  10773. t['evowelsignbengali'] = 0x09C7;
  10774. t['evowelsigndeva'] = 0x0947;
  10775. t['evowelsigngujarati'] = 0x0AC7;
  10776. t['exclam'] = 0x0021;
  10777. t['exclamarmenian'] = 0x055C;
  10778. t['exclamdbl'] = 0x203C;
  10779. t['exclamdown'] = 0x00A1;
  10780. t['exclamdownsmall'] = 0xF7A1;
  10781. t['exclammonospace'] = 0xFF01;
  10782. t['exclamsmall'] = 0xF721;
  10783. t['existential'] = 0x2203;
  10784. t['ezh'] = 0x0292;
  10785. t['ezhcaron'] = 0x01EF;
  10786. t['ezhcurl'] = 0x0293;
  10787. t['ezhreversed'] = 0x01B9;
  10788. t['ezhtail'] = 0x01BA;
  10789. t['f'] = 0x0066;
  10790. t['fadeva'] = 0x095E;
  10791. t['fagurmukhi'] = 0x0A5E;
  10792. t['fahrenheit'] = 0x2109;
  10793. t['fathaarabic'] = 0x064E;
  10794. t['fathalowarabic'] = 0x064E;
  10795. t['fathatanarabic'] = 0x064B;
  10796. t['fbopomofo'] = 0x3108;
  10797. t['fcircle'] = 0x24D5;
  10798. t['fdotaccent'] = 0x1E1F;
  10799. t['feharabic'] = 0x0641;
  10800. t['feharmenian'] = 0x0586;
  10801. t['fehfinalarabic'] = 0xFED2;
  10802. t['fehinitialarabic'] = 0xFED3;
  10803. t['fehmedialarabic'] = 0xFED4;
  10804. t['feicoptic'] = 0x03E5;
  10805. t['female'] = 0x2640;
  10806. t['ff'] = 0xFB00;
  10807. t['ffi'] = 0xFB03;
  10808. t['ffl'] = 0xFB04;
  10809. t['fi'] = 0xFB01;
  10810. t['fifteencircle'] = 0x246E;
  10811. t['fifteenparen'] = 0x2482;
  10812. t['fifteenperiod'] = 0x2496;
  10813. t['figuredash'] = 0x2012;
  10814. t['filledbox'] = 0x25A0;
  10815. t['filledrect'] = 0x25AC;
  10816. t['finalkaf'] = 0x05DA;
  10817. t['finalkafdagesh'] = 0xFB3A;
  10818. t['finalkafdageshhebrew'] = 0xFB3A;
  10819. t['finalkafhebrew'] = 0x05DA;
  10820. t['finalmem'] = 0x05DD;
  10821. t['finalmemhebrew'] = 0x05DD;
  10822. t['finalnun'] = 0x05DF;
  10823. t['finalnunhebrew'] = 0x05DF;
  10824. t['finalpe'] = 0x05E3;
  10825. t['finalpehebrew'] = 0x05E3;
  10826. t['finaltsadi'] = 0x05E5;
  10827. t['finaltsadihebrew'] = 0x05E5;
  10828. t['firsttonechinese'] = 0x02C9;
  10829. t['fisheye'] = 0x25C9;
  10830. t['fitacyrillic'] = 0x0473;
  10831. t['five'] = 0x0035;
  10832. t['fivearabic'] = 0x0665;
  10833. t['fivebengali'] = 0x09EB;
  10834. t['fivecircle'] = 0x2464;
  10835. t['fivecircleinversesansserif'] = 0x278E;
  10836. t['fivedeva'] = 0x096B;
  10837. t['fiveeighths'] = 0x215D;
  10838. t['fivegujarati'] = 0x0AEB;
  10839. t['fivegurmukhi'] = 0x0A6B;
  10840. t['fivehackarabic'] = 0x0665;
  10841. t['fivehangzhou'] = 0x3025;
  10842. t['fiveideographicparen'] = 0x3224;
  10843. t['fiveinferior'] = 0x2085;
  10844. t['fivemonospace'] = 0xFF15;
  10845. t['fiveoldstyle'] = 0xF735;
  10846. t['fiveparen'] = 0x2478;
  10847. t['fiveperiod'] = 0x248C;
  10848. t['fivepersian'] = 0x06F5;
  10849. t['fiveroman'] = 0x2174;
  10850. t['fivesuperior'] = 0x2075;
  10851. t['fivethai'] = 0x0E55;
  10852. t['fl'] = 0xFB02;
  10853. t['florin'] = 0x0192;
  10854. t['fmonospace'] = 0xFF46;
  10855. t['fmsquare'] = 0x3399;
  10856. t['fofanthai'] = 0x0E1F;
  10857. t['fofathai'] = 0x0E1D;
  10858. t['fongmanthai'] = 0x0E4F;
  10859. t['forall'] = 0x2200;
  10860. t['four'] = 0x0034;
  10861. t['fourarabic'] = 0x0664;
  10862. t['fourbengali'] = 0x09EA;
  10863. t['fourcircle'] = 0x2463;
  10864. t['fourcircleinversesansserif'] = 0x278D;
  10865. t['fourdeva'] = 0x096A;
  10866. t['fourgujarati'] = 0x0AEA;
  10867. t['fourgurmukhi'] = 0x0A6A;
  10868. t['fourhackarabic'] = 0x0664;
  10869. t['fourhangzhou'] = 0x3024;
  10870. t['fourideographicparen'] = 0x3223;
  10871. t['fourinferior'] = 0x2084;
  10872. t['fourmonospace'] = 0xFF14;
  10873. t['fournumeratorbengali'] = 0x09F7;
  10874. t['fouroldstyle'] = 0xF734;
  10875. t['fourparen'] = 0x2477;
  10876. t['fourperiod'] = 0x248B;
  10877. t['fourpersian'] = 0x06F4;
  10878. t['fourroman'] = 0x2173;
  10879. t['foursuperior'] = 0x2074;
  10880. t['fourteencircle'] = 0x246D;
  10881. t['fourteenparen'] = 0x2481;
  10882. t['fourteenperiod'] = 0x2495;
  10883. t['fourthai'] = 0x0E54;
  10884. t['fourthtonechinese'] = 0x02CB;
  10885. t['fparen'] = 0x24A1;
  10886. t['fraction'] = 0x2044;
  10887. t['franc'] = 0x20A3;
  10888. t['g'] = 0x0067;
  10889. t['gabengali'] = 0x0997;
  10890. t['gacute'] = 0x01F5;
  10891. t['gadeva'] = 0x0917;
  10892. t['gafarabic'] = 0x06AF;
  10893. t['gaffinalarabic'] = 0xFB93;
  10894. t['gafinitialarabic'] = 0xFB94;
  10895. t['gafmedialarabic'] = 0xFB95;
  10896. t['gagujarati'] = 0x0A97;
  10897. t['gagurmukhi'] = 0x0A17;
  10898. t['gahiragana'] = 0x304C;
  10899. t['gakatakana'] = 0x30AC;
  10900. t['gamma'] = 0x03B3;
  10901. t['gammalatinsmall'] = 0x0263;
  10902. t['gammasuperior'] = 0x02E0;
  10903. t['gangiacoptic'] = 0x03EB;
  10904. t['gbopomofo'] = 0x310D;
  10905. t['gbreve'] = 0x011F;
  10906. t['gcaron'] = 0x01E7;
  10907. t['gcedilla'] = 0x0123;
  10908. t['gcircle'] = 0x24D6;
  10909. t['gcircumflex'] = 0x011D;
  10910. t['gcommaaccent'] = 0x0123;
  10911. t['gdot'] = 0x0121;
  10912. t['gdotaccent'] = 0x0121;
  10913. t['gecyrillic'] = 0x0433;
  10914. t['gehiragana'] = 0x3052;
  10915. t['gekatakana'] = 0x30B2;
  10916. t['geometricallyequal'] = 0x2251;
  10917. t['gereshaccenthebrew'] = 0x059C;
  10918. t['gereshhebrew'] = 0x05F3;
  10919. t['gereshmuqdamhebrew'] = 0x059D;
  10920. t['germandbls'] = 0x00DF;
  10921. t['gershayimaccenthebrew'] = 0x059E;
  10922. t['gershayimhebrew'] = 0x05F4;
  10923. t['getamark'] = 0x3013;
  10924. t['ghabengali'] = 0x0998;
  10925. t['ghadarmenian'] = 0x0572;
  10926. t['ghadeva'] = 0x0918;
  10927. t['ghagujarati'] = 0x0A98;
  10928. t['ghagurmukhi'] = 0x0A18;
  10929. t['ghainarabic'] = 0x063A;
  10930. t['ghainfinalarabic'] = 0xFECE;
  10931. t['ghaininitialarabic'] = 0xFECF;
  10932. t['ghainmedialarabic'] = 0xFED0;
  10933. t['ghemiddlehookcyrillic'] = 0x0495;
  10934. t['ghestrokecyrillic'] = 0x0493;
  10935. t['gheupturncyrillic'] = 0x0491;
  10936. t['ghhadeva'] = 0x095A;
  10937. t['ghhagurmukhi'] = 0x0A5A;
  10938. t['ghook'] = 0x0260;
  10939. t['ghzsquare'] = 0x3393;
  10940. t['gihiragana'] = 0x304E;
  10941. t['gikatakana'] = 0x30AE;
  10942. t['gimarmenian'] = 0x0563;
  10943. t['gimel'] = 0x05D2;
  10944. t['gimeldagesh'] = 0xFB32;
  10945. t['gimeldageshhebrew'] = 0xFB32;
  10946. t['gimelhebrew'] = 0x05D2;
  10947. t['gjecyrillic'] = 0x0453;
  10948. t['glottalinvertedstroke'] = 0x01BE;
  10949. t['glottalstop'] = 0x0294;
  10950. t['glottalstopinverted'] = 0x0296;
  10951. t['glottalstopmod'] = 0x02C0;
  10952. t['glottalstopreversed'] = 0x0295;
  10953. t['glottalstopreversedmod'] = 0x02C1;
  10954. t['glottalstopreversedsuperior'] = 0x02E4;
  10955. t['glottalstopstroke'] = 0x02A1;
  10956. t['glottalstopstrokereversed'] = 0x02A2;
  10957. t['gmacron'] = 0x1E21;
  10958. t['gmonospace'] = 0xFF47;
  10959. t['gohiragana'] = 0x3054;
  10960. t['gokatakana'] = 0x30B4;
  10961. t['gparen'] = 0x24A2;
  10962. t['gpasquare'] = 0x33AC;
  10963. t['gradient'] = 0x2207;
  10964. t['grave'] = 0x0060;
  10965. t['gravebelowcmb'] = 0x0316;
  10966. t['gravecmb'] = 0x0300;
  10967. t['gravecomb'] = 0x0300;
  10968. t['gravedeva'] = 0x0953;
  10969. t['gravelowmod'] = 0x02CE;
  10970. t['gravemonospace'] = 0xFF40;
  10971. t['gravetonecmb'] = 0x0340;
  10972. t['greater'] = 0x003E;
  10973. t['greaterequal'] = 0x2265;
  10974. t['greaterequalorless'] = 0x22DB;
  10975. t['greatermonospace'] = 0xFF1E;
  10976. t['greaterorequivalent'] = 0x2273;
  10977. t['greaterorless'] = 0x2277;
  10978. t['greateroverequal'] = 0x2267;
  10979. t['greatersmall'] = 0xFE65;
  10980. t['gscript'] = 0x0261;
  10981. t['gstroke'] = 0x01E5;
  10982. t['guhiragana'] = 0x3050;
  10983. t['guillemotleft'] = 0x00AB;
  10984. t['guillemotright'] = 0x00BB;
  10985. t['guilsinglleft'] = 0x2039;
  10986. t['guilsinglright'] = 0x203A;
  10987. t['gukatakana'] = 0x30B0;
  10988. t['guramusquare'] = 0x3318;
  10989. t['gysquare'] = 0x33C9;
  10990. t['h'] = 0x0068;
  10991. t['haabkhasiancyrillic'] = 0x04A9;
  10992. t['haaltonearabic'] = 0x06C1;
  10993. t['habengali'] = 0x09B9;
  10994. t['hadescendercyrillic'] = 0x04B3;
  10995. t['hadeva'] = 0x0939;
  10996. t['hagujarati'] = 0x0AB9;
  10997. t['hagurmukhi'] = 0x0A39;
  10998. t['haharabic'] = 0x062D;
  10999. t['hahfinalarabic'] = 0xFEA2;
  11000. t['hahinitialarabic'] = 0xFEA3;
  11001. t['hahiragana'] = 0x306F;
  11002. t['hahmedialarabic'] = 0xFEA4;
  11003. t['haitusquare'] = 0x332A;
  11004. t['hakatakana'] = 0x30CF;
  11005. t['hakatakanahalfwidth'] = 0xFF8A;
  11006. t['halantgurmukhi'] = 0x0A4D;
  11007. t['hamzaarabic'] = 0x0621;
  11008. t['hamzalowarabic'] = 0x0621;
  11009. t['hangulfiller'] = 0x3164;
  11010. t['hardsigncyrillic'] = 0x044A;
  11011. t['harpoonleftbarbup'] = 0x21BC;
  11012. t['harpoonrightbarbup'] = 0x21C0;
  11013. t['hasquare'] = 0x33CA;
  11014. t['hatafpatah'] = 0x05B2;
  11015. t['hatafpatah16'] = 0x05B2;
  11016. t['hatafpatah23'] = 0x05B2;
  11017. t['hatafpatah2f'] = 0x05B2;
  11018. t['hatafpatahhebrew'] = 0x05B2;
  11019. t['hatafpatahnarrowhebrew'] = 0x05B2;
  11020. t['hatafpatahquarterhebrew'] = 0x05B2;
  11021. t['hatafpatahwidehebrew'] = 0x05B2;
  11022. t['hatafqamats'] = 0x05B3;
  11023. t['hatafqamats1b'] = 0x05B3;
  11024. t['hatafqamats28'] = 0x05B3;
  11025. t['hatafqamats34'] = 0x05B3;
  11026. t['hatafqamatshebrew'] = 0x05B3;
  11027. t['hatafqamatsnarrowhebrew'] = 0x05B3;
  11028. t['hatafqamatsquarterhebrew'] = 0x05B3;
  11029. t['hatafqamatswidehebrew'] = 0x05B3;
  11030. t['hatafsegol'] = 0x05B1;
  11031. t['hatafsegol17'] = 0x05B1;
  11032. t['hatafsegol24'] = 0x05B1;
  11033. t['hatafsegol30'] = 0x05B1;
  11034. t['hatafsegolhebrew'] = 0x05B1;
  11035. t['hatafsegolnarrowhebrew'] = 0x05B1;
  11036. t['hatafsegolquarterhebrew'] = 0x05B1;
  11037. t['hatafsegolwidehebrew'] = 0x05B1;
  11038. t['hbar'] = 0x0127;
  11039. t['hbopomofo'] = 0x310F;
  11040. t['hbrevebelow'] = 0x1E2B;
  11041. t['hcedilla'] = 0x1E29;
  11042. t['hcircle'] = 0x24D7;
  11043. t['hcircumflex'] = 0x0125;
  11044. t['hdieresis'] = 0x1E27;
  11045. t['hdotaccent'] = 0x1E23;
  11046. t['hdotbelow'] = 0x1E25;
  11047. t['he'] = 0x05D4;
  11048. t['heart'] = 0x2665;
  11049. t['heartsuitblack'] = 0x2665;
  11050. t['heartsuitwhite'] = 0x2661;
  11051. t['hedagesh'] = 0xFB34;
  11052. t['hedageshhebrew'] = 0xFB34;
  11053. t['hehaltonearabic'] = 0x06C1;
  11054. t['heharabic'] = 0x0647;
  11055. t['hehebrew'] = 0x05D4;
  11056. t['hehfinalaltonearabic'] = 0xFBA7;
  11057. t['hehfinalalttwoarabic'] = 0xFEEA;
  11058. t['hehfinalarabic'] = 0xFEEA;
  11059. t['hehhamzaabovefinalarabic'] = 0xFBA5;
  11060. t['hehhamzaaboveisolatedarabic'] = 0xFBA4;
  11061. t['hehinitialaltonearabic'] = 0xFBA8;
  11062. t['hehinitialarabic'] = 0xFEEB;
  11063. t['hehiragana'] = 0x3078;
  11064. t['hehmedialaltonearabic'] = 0xFBA9;
  11065. t['hehmedialarabic'] = 0xFEEC;
  11066. t['heiseierasquare'] = 0x337B;
  11067. t['hekatakana'] = 0x30D8;
  11068. t['hekatakanahalfwidth'] = 0xFF8D;
  11069. t['hekutaarusquare'] = 0x3336;
  11070. t['henghook'] = 0x0267;
  11071. t['herutusquare'] = 0x3339;
  11072. t['het'] = 0x05D7;
  11073. t['hethebrew'] = 0x05D7;
  11074. t['hhook'] = 0x0266;
  11075. t['hhooksuperior'] = 0x02B1;
  11076. t['hieuhacirclekorean'] = 0x327B;
  11077. t['hieuhaparenkorean'] = 0x321B;
  11078. t['hieuhcirclekorean'] = 0x326D;
  11079. t['hieuhkorean'] = 0x314E;
  11080. t['hieuhparenkorean'] = 0x320D;
  11081. t['hihiragana'] = 0x3072;
  11082. t['hikatakana'] = 0x30D2;
  11083. t['hikatakanahalfwidth'] = 0xFF8B;
  11084. t['hiriq'] = 0x05B4;
  11085. t['hiriq14'] = 0x05B4;
  11086. t['hiriq21'] = 0x05B4;
  11087. t['hiriq2d'] = 0x05B4;
  11088. t['hiriqhebrew'] = 0x05B4;
  11089. t['hiriqnarrowhebrew'] = 0x05B4;
  11090. t['hiriqquarterhebrew'] = 0x05B4;
  11091. t['hiriqwidehebrew'] = 0x05B4;
  11092. t['hlinebelow'] = 0x1E96;
  11093. t['hmonospace'] = 0xFF48;
  11094. t['hoarmenian'] = 0x0570;
  11095. t['hohipthai'] = 0x0E2B;
  11096. t['hohiragana'] = 0x307B;
  11097. t['hokatakana'] = 0x30DB;
  11098. t['hokatakanahalfwidth'] = 0xFF8E;
  11099. t['holam'] = 0x05B9;
  11100. t['holam19'] = 0x05B9;
  11101. t['holam26'] = 0x05B9;
  11102. t['holam32'] = 0x05B9;
  11103. t['holamhebrew'] = 0x05B9;
  11104. t['holamnarrowhebrew'] = 0x05B9;
  11105. t['holamquarterhebrew'] = 0x05B9;
  11106. t['holamwidehebrew'] = 0x05B9;
  11107. t['honokhukthai'] = 0x0E2E;
  11108. t['hookabovecomb'] = 0x0309;
  11109. t['hookcmb'] = 0x0309;
  11110. t['hookpalatalizedbelowcmb'] = 0x0321;
  11111. t['hookretroflexbelowcmb'] = 0x0322;
  11112. t['hoonsquare'] = 0x3342;
  11113. t['horicoptic'] = 0x03E9;
  11114. t['horizontalbar'] = 0x2015;
  11115. t['horncmb'] = 0x031B;
  11116. t['hotsprings'] = 0x2668;
  11117. t['house'] = 0x2302;
  11118. t['hparen'] = 0x24A3;
  11119. t['hsuperior'] = 0x02B0;
  11120. t['hturned'] = 0x0265;
  11121. t['huhiragana'] = 0x3075;
  11122. t['huiitosquare'] = 0x3333;
  11123. t['hukatakana'] = 0x30D5;
  11124. t['hukatakanahalfwidth'] = 0xFF8C;
  11125. t['hungarumlaut'] = 0x02DD;
  11126. t['hungarumlautcmb'] = 0x030B;
  11127. t['hv'] = 0x0195;
  11128. t['hyphen'] = 0x002D;
  11129. t['hypheninferior'] = 0xF6E5;
  11130. t['hyphenmonospace'] = 0xFF0D;
  11131. t['hyphensmall'] = 0xFE63;
  11132. t['hyphensuperior'] = 0xF6E6;
  11133. t['hyphentwo'] = 0x2010;
  11134. t['i'] = 0x0069;
  11135. t['iacute'] = 0x00ED;
  11136. t['iacyrillic'] = 0x044F;
  11137. t['ibengali'] = 0x0987;
  11138. t['ibopomofo'] = 0x3127;
  11139. t['ibreve'] = 0x012D;
  11140. t['icaron'] = 0x01D0;
  11141. t['icircle'] = 0x24D8;
  11142. t['icircumflex'] = 0x00EE;
  11143. t['icyrillic'] = 0x0456;
  11144. t['idblgrave'] = 0x0209;
  11145. t['ideographearthcircle'] = 0x328F;
  11146. t['ideographfirecircle'] = 0x328B;
  11147. t['ideographicallianceparen'] = 0x323F;
  11148. t['ideographiccallparen'] = 0x323A;
  11149. t['ideographiccentrecircle'] = 0x32A5;
  11150. t['ideographicclose'] = 0x3006;
  11151. t['ideographiccomma'] = 0x3001;
  11152. t['ideographiccommaleft'] = 0xFF64;
  11153. t['ideographiccongratulationparen'] = 0x3237;
  11154. t['ideographiccorrectcircle'] = 0x32A3;
  11155. t['ideographicearthparen'] = 0x322F;
  11156. t['ideographicenterpriseparen'] = 0x323D;
  11157. t['ideographicexcellentcircle'] = 0x329D;
  11158. t['ideographicfestivalparen'] = 0x3240;
  11159. t['ideographicfinancialcircle'] = 0x3296;
  11160. t['ideographicfinancialparen'] = 0x3236;
  11161. t['ideographicfireparen'] = 0x322B;
  11162. t['ideographichaveparen'] = 0x3232;
  11163. t['ideographichighcircle'] = 0x32A4;
  11164. t['ideographiciterationmark'] = 0x3005;
  11165. t['ideographiclaborcircle'] = 0x3298;
  11166. t['ideographiclaborparen'] = 0x3238;
  11167. t['ideographicleftcircle'] = 0x32A7;
  11168. t['ideographiclowcircle'] = 0x32A6;
  11169. t['ideographicmedicinecircle'] = 0x32A9;
  11170. t['ideographicmetalparen'] = 0x322E;
  11171. t['ideographicmoonparen'] = 0x322A;
  11172. t['ideographicnameparen'] = 0x3234;
  11173. t['ideographicperiod'] = 0x3002;
  11174. t['ideographicprintcircle'] = 0x329E;
  11175. t['ideographicreachparen'] = 0x3243;
  11176. t['ideographicrepresentparen'] = 0x3239;
  11177. t['ideographicresourceparen'] = 0x323E;
  11178. t['ideographicrightcircle'] = 0x32A8;
  11179. t['ideographicsecretcircle'] = 0x3299;
  11180. t['ideographicselfparen'] = 0x3242;
  11181. t['ideographicsocietyparen'] = 0x3233;
  11182. t['ideographicspace'] = 0x3000;
  11183. t['ideographicspecialparen'] = 0x3235;
  11184. t['ideographicstockparen'] = 0x3231;
  11185. t['ideographicstudyparen'] = 0x323B;
  11186. t['ideographicsunparen'] = 0x3230;
  11187. t['ideographicsuperviseparen'] = 0x323C;
  11188. t['ideographicwaterparen'] = 0x322C;
  11189. t['ideographicwoodparen'] = 0x322D;
  11190. t['ideographiczero'] = 0x3007;
  11191. t['ideographmetalcircle'] = 0x328E;
  11192. t['ideographmooncircle'] = 0x328A;
  11193. t['ideographnamecircle'] = 0x3294;
  11194. t['ideographsuncircle'] = 0x3290;
  11195. t['ideographwatercircle'] = 0x328C;
  11196. t['ideographwoodcircle'] = 0x328D;
  11197. t['ideva'] = 0x0907;
  11198. t['idieresis'] = 0x00EF;
  11199. t['idieresisacute'] = 0x1E2F;
  11200. t['idieresiscyrillic'] = 0x04E5;
  11201. t['idotbelow'] = 0x1ECB;
  11202. t['iebrevecyrillic'] = 0x04D7;
  11203. t['iecyrillic'] = 0x0435;
  11204. t['ieungacirclekorean'] = 0x3275;
  11205. t['ieungaparenkorean'] = 0x3215;
  11206. t['ieungcirclekorean'] = 0x3267;
  11207. t['ieungkorean'] = 0x3147;
  11208. t['ieungparenkorean'] = 0x3207;
  11209. t['igrave'] = 0x00EC;
  11210. t['igujarati'] = 0x0A87;
  11211. t['igurmukhi'] = 0x0A07;
  11212. t['ihiragana'] = 0x3044;
  11213. t['ihookabove'] = 0x1EC9;
  11214. t['iibengali'] = 0x0988;
  11215. t['iicyrillic'] = 0x0438;
  11216. t['iideva'] = 0x0908;
  11217. t['iigujarati'] = 0x0A88;
  11218. t['iigurmukhi'] = 0x0A08;
  11219. t['iimatragurmukhi'] = 0x0A40;
  11220. t['iinvertedbreve'] = 0x020B;
  11221. t['iishortcyrillic'] = 0x0439;
  11222. t['iivowelsignbengali'] = 0x09C0;
  11223. t['iivowelsigndeva'] = 0x0940;
  11224. t['iivowelsigngujarati'] = 0x0AC0;
  11225. t['ij'] = 0x0133;
  11226. t['ikatakana'] = 0x30A4;
  11227. t['ikatakanahalfwidth'] = 0xFF72;
  11228. t['ikorean'] = 0x3163;
  11229. t['ilde'] = 0x02DC;
  11230. t['iluyhebrew'] = 0x05AC;
  11231. t['imacron'] = 0x012B;
  11232. t['imacroncyrillic'] = 0x04E3;
  11233. t['imageorapproximatelyequal'] = 0x2253;
  11234. t['imatragurmukhi'] = 0x0A3F;
  11235. t['imonospace'] = 0xFF49;
  11236. t['increment'] = 0x2206;
  11237. t['infinity'] = 0x221E;
  11238. t['iniarmenian'] = 0x056B;
  11239. t['integral'] = 0x222B;
  11240. t['integralbottom'] = 0x2321;
  11241. t['integralbt'] = 0x2321;
  11242. t['integralex'] = 0xF8F5;
  11243. t['integraltop'] = 0x2320;
  11244. t['integraltp'] = 0x2320;
  11245. t['intersection'] = 0x2229;
  11246. t['intisquare'] = 0x3305;
  11247. t['invbullet'] = 0x25D8;
  11248. t['invcircle'] = 0x25D9;
  11249. t['invsmileface'] = 0x263B;
  11250. t['iocyrillic'] = 0x0451;
  11251. t['iogonek'] = 0x012F;
  11252. t['iota'] = 0x03B9;
  11253. t['iotadieresis'] = 0x03CA;
  11254. t['iotadieresistonos'] = 0x0390;
  11255. t['iotalatin'] = 0x0269;
  11256. t['iotatonos'] = 0x03AF;
  11257. t['iparen'] = 0x24A4;
  11258. t['irigurmukhi'] = 0x0A72;
  11259. t['ismallhiragana'] = 0x3043;
  11260. t['ismallkatakana'] = 0x30A3;
  11261. t['ismallkatakanahalfwidth'] = 0xFF68;
  11262. t['issharbengali'] = 0x09FA;
  11263. t['istroke'] = 0x0268;
  11264. t['isuperior'] = 0xF6ED;
  11265. t['iterationhiragana'] = 0x309D;
  11266. t['iterationkatakana'] = 0x30FD;
  11267. t['itilde'] = 0x0129;
  11268. t['itildebelow'] = 0x1E2D;
  11269. t['iubopomofo'] = 0x3129;
  11270. t['iucyrillic'] = 0x044E;
  11271. t['ivowelsignbengali'] = 0x09BF;
  11272. t['ivowelsigndeva'] = 0x093F;
  11273. t['ivowelsigngujarati'] = 0x0ABF;
  11274. t['izhitsacyrillic'] = 0x0475;
  11275. t['izhitsadblgravecyrillic'] = 0x0477;
  11276. t['j'] = 0x006A;
  11277. t['jaarmenian'] = 0x0571;
  11278. t['jabengali'] = 0x099C;
  11279. t['jadeva'] = 0x091C;
  11280. t['jagujarati'] = 0x0A9C;
  11281. t['jagurmukhi'] = 0x0A1C;
  11282. t['jbopomofo'] = 0x3110;
  11283. t['jcaron'] = 0x01F0;
  11284. t['jcircle'] = 0x24D9;
  11285. t['jcircumflex'] = 0x0135;
  11286. t['jcrossedtail'] = 0x029D;
  11287. t['jdotlessstroke'] = 0x025F;
  11288. t['jecyrillic'] = 0x0458;
  11289. t['jeemarabic'] = 0x062C;
  11290. t['jeemfinalarabic'] = 0xFE9E;
  11291. t['jeeminitialarabic'] = 0xFE9F;
  11292. t['jeemmedialarabic'] = 0xFEA0;
  11293. t['jeharabic'] = 0x0698;
  11294. t['jehfinalarabic'] = 0xFB8B;
  11295. t['jhabengali'] = 0x099D;
  11296. t['jhadeva'] = 0x091D;
  11297. t['jhagujarati'] = 0x0A9D;
  11298. t['jhagurmukhi'] = 0x0A1D;
  11299. t['jheharmenian'] = 0x057B;
  11300. t['jis'] = 0x3004;
  11301. t['jmonospace'] = 0xFF4A;
  11302. t['jparen'] = 0x24A5;
  11303. t['jsuperior'] = 0x02B2;
  11304. t['k'] = 0x006B;
  11305. t['kabashkircyrillic'] = 0x04A1;
  11306. t['kabengali'] = 0x0995;
  11307. t['kacute'] = 0x1E31;
  11308. t['kacyrillic'] = 0x043A;
  11309. t['kadescendercyrillic'] = 0x049B;
  11310. t['kadeva'] = 0x0915;
  11311. t['kaf'] = 0x05DB;
  11312. t['kafarabic'] = 0x0643;
  11313. t['kafdagesh'] = 0xFB3B;
  11314. t['kafdageshhebrew'] = 0xFB3B;
  11315. t['kaffinalarabic'] = 0xFEDA;
  11316. t['kafhebrew'] = 0x05DB;
  11317. t['kafinitialarabic'] = 0xFEDB;
  11318. t['kafmedialarabic'] = 0xFEDC;
  11319. t['kafrafehebrew'] = 0xFB4D;
  11320. t['kagujarati'] = 0x0A95;
  11321. t['kagurmukhi'] = 0x0A15;
  11322. t['kahiragana'] = 0x304B;
  11323. t['kahookcyrillic'] = 0x04C4;
  11324. t['kakatakana'] = 0x30AB;
  11325. t['kakatakanahalfwidth'] = 0xFF76;
  11326. t['kappa'] = 0x03BA;
  11327. t['kappasymbolgreek'] = 0x03F0;
  11328. t['kapyeounmieumkorean'] = 0x3171;
  11329. t['kapyeounphieuphkorean'] = 0x3184;
  11330. t['kapyeounpieupkorean'] = 0x3178;
  11331. t['kapyeounssangpieupkorean'] = 0x3179;
  11332. t['karoriisquare'] = 0x330D;
  11333. t['kashidaautoarabic'] = 0x0640;
  11334. t['kashidaautonosidebearingarabic'] = 0x0640;
  11335. t['kasmallkatakana'] = 0x30F5;
  11336. t['kasquare'] = 0x3384;
  11337. t['kasraarabic'] = 0x0650;
  11338. t['kasratanarabic'] = 0x064D;
  11339. t['kastrokecyrillic'] = 0x049F;
  11340. t['katahiraprolongmarkhalfwidth'] = 0xFF70;
  11341. t['kaverticalstrokecyrillic'] = 0x049D;
  11342. t['kbopomofo'] = 0x310E;
  11343. t['kcalsquare'] = 0x3389;
  11344. t['kcaron'] = 0x01E9;
  11345. t['kcedilla'] = 0x0137;
  11346. t['kcircle'] = 0x24DA;
  11347. t['kcommaaccent'] = 0x0137;
  11348. t['kdotbelow'] = 0x1E33;
  11349. t['keharmenian'] = 0x0584;
  11350. t['kehiragana'] = 0x3051;
  11351. t['kekatakana'] = 0x30B1;
  11352. t['kekatakanahalfwidth'] = 0xFF79;
  11353. t['kenarmenian'] = 0x056F;
  11354. t['kesmallkatakana'] = 0x30F6;
  11355. t['kgreenlandic'] = 0x0138;
  11356. t['khabengali'] = 0x0996;
  11357. t['khacyrillic'] = 0x0445;
  11358. t['khadeva'] = 0x0916;
  11359. t['khagujarati'] = 0x0A96;
  11360. t['khagurmukhi'] = 0x0A16;
  11361. t['khaharabic'] = 0x062E;
  11362. t['khahfinalarabic'] = 0xFEA6;
  11363. t['khahinitialarabic'] = 0xFEA7;
  11364. t['khahmedialarabic'] = 0xFEA8;
  11365. t['kheicoptic'] = 0x03E7;
  11366. t['khhadeva'] = 0x0959;
  11367. t['khhagurmukhi'] = 0x0A59;
  11368. t['khieukhacirclekorean'] = 0x3278;
  11369. t['khieukhaparenkorean'] = 0x3218;
  11370. t['khieukhcirclekorean'] = 0x326A;
  11371. t['khieukhkorean'] = 0x314B;
  11372. t['khieukhparenkorean'] = 0x320A;
  11373. t['khokhaithai'] = 0x0E02;
  11374. t['khokhonthai'] = 0x0E05;
  11375. t['khokhuatthai'] = 0x0E03;
  11376. t['khokhwaithai'] = 0x0E04;
  11377. t['khomutthai'] = 0x0E5B;
  11378. t['khook'] = 0x0199;
  11379. t['khorakhangthai'] = 0x0E06;
  11380. t['khzsquare'] = 0x3391;
  11381. t['kihiragana'] = 0x304D;
  11382. t['kikatakana'] = 0x30AD;
  11383. t['kikatakanahalfwidth'] = 0xFF77;
  11384. t['kiroguramusquare'] = 0x3315;
  11385. t['kiromeetorusquare'] = 0x3316;
  11386. t['kirosquare'] = 0x3314;
  11387. t['kiyeokacirclekorean'] = 0x326E;
  11388. t['kiyeokaparenkorean'] = 0x320E;
  11389. t['kiyeokcirclekorean'] = 0x3260;
  11390. t['kiyeokkorean'] = 0x3131;
  11391. t['kiyeokparenkorean'] = 0x3200;
  11392. t['kiyeoksioskorean'] = 0x3133;
  11393. t['kjecyrillic'] = 0x045C;
  11394. t['klinebelow'] = 0x1E35;
  11395. t['klsquare'] = 0x3398;
  11396. t['kmcubedsquare'] = 0x33A6;
  11397. t['kmonospace'] = 0xFF4B;
  11398. t['kmsquaredsquare'] = 0x33A2;
  11399. t['kohiragana'] = 0x3053;
  11400. t['kohmsquare'] = 0x33C0;
  11401. t['kokaithai'] = 0x0E01;
  11402. t['kokatakana'] = 0x30B3;
  11403. t['kokatakanahalfwidth'] = 0xFF7A;
  11404. t['kooposquare'] = 0x331E;
  11405. t['koppacyrillic'] = 0x0481;
  11406. t['koreanstandardsymbol'] = 0x327F;
  11407. t['koroniscmb'] = 0x0343;
  11408. t['kparen'] = 0x24A6;
  11409. t['kpasquare'] = 0x33AA;
  11410. t['ksicyrillic'] = 0x046F;
  11411. t['ktsquare'] = 0x33CF;
  11412. t['kturned'] = 0x029E;
  11413. t['kuhiragana'] = 0x304F;
  11414. t['kukatakana'] = 0x30AF;
  11415. t['kukatakanahalfwidth'] = 0xFF78;
  11416. t['kvsquare'] = 0x33B8;
  11417. t['kwsquare'] = 0x33BE;
  11418. t['l'] = 0x006C;
  11419. t['labengali'] = 0x09B2;
  11420. t['lacute'] = 0x013A;
  11421. t['ladeva'] = 0x0932;
  11422. t['lagujarati'] = 0x0AB2;
  11423. t['lagurmukhi'] = 0x0A32;
  11424. t['lakkhangyaothai'] = 0x0E45;
  11425. t['lamaleffinalarabic'] = 0xFEFC;
  11426. t['lamalefhamzaabovefinalarabic'] = 0xFEF8;
  11427. t['lamalefhamzaaboveisolatedarabic'] = 0xFEF7;
  11428. t['lamalefhamzabelowfinalarabic'] = 0xFEFA;
  11429. t['lamalefhamzabelowisolatedarabic'] = 0xFEF9;
  11430. t['lamalefisolatedarabic'] = 0xFEFB;
  11431. t['lamalefmaddaabovefinalarabic'] = 0xFEF6;
  11432. t['lamalefmaddaaboveisolatedarabic'] = 0xFEF5;
  11433. t['lamarabic'] = 0x0644;
  11434. t['lambda'] = 0x03BB;
  11435. t['lambdastroke'] = 0x019B;
  11436. t['lamed'] = 0x05DC;
  11437. t['lameddagesh'] = 0xFB3C;
  11438. t['lameddageshhebrew'] = 0xFB3C;
  11439. t['lamedhebrew'] = 0x05DC;
  11440. t['lamfinalarabic'] = 0xFEDE;
  11441. t['lamhahinitialarabic'] = 0xFCCA;
  11442. t['laminitialarabic'] = 0xFEDF;
  11443. t['lamjeeminitialarabic'] = 0xFCC9;
  11444. t['lamkhahinitialarabic'] = 0xFCCB;
  11445. t['lamlamhehisolatedarabic'] = 0xFDF2;
  11446. t['lammedialarabic'] = 0xFEE0;
  11447. t['lammeemhahinitialarabic'] = 0xFD88;
  11448. t['lammeeminitialarabic'] = 0xFCCC;
  11449. t['largecircle'] = 0x25EF;
  11450. t['lbar'] = 0x019A;
  11451. t['lbelt'] = 0x026C;
  11452. t['lbopomofo'] = 0x310C;
  11453. t['lcaron'] = 0x013E;
  11454. t['lcedilla'] = 0x013C;
  11455. t['lcircle'] = 0x24DB;
  11456. t['lcircumflexbelow'] = 0x1E3D;
  11457. t['lcommaaccent'] = 0x013C;
  11458. t['ldot'] = 0x0140;
  11459. t['ldotaccent'] = 0x0140;
  11460. t['ldotbelow'] = 0x1E37;
  11461. t['ldotbelowmacron'] = 0x1E39;
  11462. t['leftangleabovecmb'] = 0x031A;
  11463. t['lefttackbelowcmb'] = 0x0318;
  11464. t['less'] = 0x003C;
  11465. t['lessequal'] = 0x2264;
  11466. t['lessequalorgreater'] = 0x22DA;
  11467. t['lessmonospace'] = 0xFF1C;
  11468. t['lessorequivalent'] = 0x2272;
  11469. t['lessorgreater'] = 0x2276;
  11470. t['lessoverequal'] = 0x2266;
  11471. t['lesssmall'] = 0xFE64;
  11472. t['lezh'] = 0x026E;
  11473. t['lfblock'] = 0x258C;
  11474. t['lhookretroflex'] = 0x026D;
  11475. t['lira'] = 0x20A4;
  11476. t['liwnarmenian'] = 0x056C;
  11477. t['lj'] = 0x01C9;
  11478. t['ljecyrillic'] = 0x0459;
  11479. t['ll'] = 0xF6C0;
  11480. t['lladeva'] = 0x0933;
  11481. t['llagujarati'] = 0x0AB3;
  11482. t['llinebelow'] = 0x1E3B;
  11483. t['llladeva'] = 0x0934;
  11484. t['llvocalicbengali'] = 0x09E1;
  11485. t['llvocalicdeva'] = 0x0961;
  11486. t['llvocalicvowelsignbengali'] = 0x09E3;
  11487. t['llvocalicvowelsigndeva'] = 0x0963;
  11488. t['lmiddletilde'] = 0x026B;
  11489. t['lmonospace'] = 0xFF4C;
  11490. t['lmsquare'] = 0x33D0;
  11491. t['lochulathai'] = 0x0E2C;
  11492. t['logicaland'] = 0x2227;
  11493. t['logicalnot'] = 0x00AC;
  11494. t['logicalnotreversed'] = 0x2310;
  11495. t['logicalor'] = 0x2228;
  11496. t['lolingthai'] = 0x0E25;
  11497. t['longs'] = 0x017F;
  11498. t['lowlinecenterline'] = 0xFE4E;
  11499. t['lowlinecmb'] = 0x0332;
  11500. t['lowlinedashed'] = 0xFE4D;
  11501. t['lozenge'] = 0x25CA;
  11502. t['lparen'] = 0x24A7;
  11503. t['lslash'] = 0x0142;
  11504. t['lsquare'] = 0x2113;
  11505. t['lsuperior'] = 0xF6EE;
  11506. t['ltshade'] = 0x2591;
  11507. t['luthai'] = 0x0E26;
  11508. t['lvocalicbengali'] = 0x098C;
  11509. t['lvocalicdeva'] = 0x090C;
  11510. t['lvocalicvowelsignbengali'] = 0x09E2;
  11511. t['lvocalicvowelsigndeva'] = 0x0962;
  11512. t['lxsquare'] = 0x33D3;
  11513. t['m'] = 0x006D;
  11514. t['mabengali'] = 0x09AE;
  11515. t['macron'] = 0x00AF;
  11516. t['macronbelowcmb'] = 0x0331;
  11517. t['macroncmb'] = 0x0304;
  11518. t['macronlowmod'] = 0x02CD;
  11519. t['macronmonospace'] = 0xFFE3;
  11520. t['macute'] = 0x1E3F;
  11521. t['madeva'] = 0x092E;
  11522. t['magujarati'] = 0x0AAE;
  11523. t['magurmukhi'] = 0x0A2E;
  11524. t['mahapakhhebrew'] = 0x05A4;
  11525. t['mahapakhlefthebrew'] = 0x05A4;
  11526. t['mahiragana'] = 0x307E;
  11527. t['maichattawalowleftthai'] = 0xF895;
  11528. t['maichattawalowrightthai'] = 0xF894;
  11529. t['maichattawathai'] = 0x0E4B;
  11530. t['maichattawaupperleftthai'] = 0xF893;
  11531. t['maieklowleftthai'] = 0xF88C;
  11532. t['maieklowrightthai'] = 0xF88B;
  11533. t['maiekthai'] = 0x0E48;
  11534. t['maiekupperleftthai'] = 0xF88A;
  11535. t['maihanakatleftthai'] = 0xF884;
  11536. t['maihanakatthai'] = 0x0E31;
  11537. t['maitaikhuleftthai'] = 0xF889;
  11538. t['maitaikhuthai'] = 0x0E47;
  11539. t['maitholowleftthai'] = 0xF88F;
  11540. t['maitholowrightthai'] = 0xF88E;
  11541. t['maithothai'] = 0x0E49;
  11542. t['maithoupperleftthai'] = 0xF88D;
  11543. t['maitrilowleftthai'] = 0xF892;
  11544. t['maitrilowrightthai'] = 0xF891;
  11545. t['maitrithai'] = 0x0E4A;
  11546. t['maitriupperleftthai'] = 0xF890;
  11547. t['maiyamokthai'] = 0x0E46;
  11548. t['makatakana'] = 0x30DE;
  11549. t['makatakanahalfwidth'] = 0xFF8F;
  11550. t['male'] = 0x2642;
  11551. t['mansyonsquare'] = 0x3347;
  11552. t['maqafhebrew'] = 0x05BE;
  11553. t['mars'] = 0x2642;
  11554. t['masoracirclehebrew'] = 0x05AF;
  11555. t['masquare'] = 0x3383;
  11556. t['mbopomofo'] = 0x3107;
  11557. t['mbsquare'] = 0x33D4;
  11558. t['mcircle'] = 0x24DC;
  11559. t['mcubedsquare'] = 0x33A5;
  11560. t['mdotaccent'] = 0x1E41;
  11561. t['mdotbelow'] = 0x1E43;
  11562. t['meemarabic'] = 0x0645;
  11563. t['meemfinalarabic'] = 0xFEE2;
  11564. t['meeminitialarabic'] = 0xFEE3;
  11565. t['meemmedialarabic'] = 0xFEE4;
  11566. t['meemmeeminitialarabic'] = 0xFCD1;
  11567. t['meemmeemisolatedarabic'] = 0xFC48;
  11568. t['meetorusquare'] = 0x334D;
  11569. t['mehiragana'] = 0x3081;
  11570. t['meizierasquare'] = 0x337E;
  11571. t['mekatakana'] = 0x30E1;
  11572. t['mekatakanahalfwidth'] = 0xFF92;
  11573. t['mem'] = 0x05DE;
  11574. t['memdagesh'] = 0xFB3E;
  11575. t['memdageshhebrew'] = 0xFB3E;
  11576. t['memhebrew'] = 0x05DE;
  11577. t['menarmenian'] = 0x0574;
  11578. t['merkhahebrew'] = 0x05A5;
  11579. t['merkhakefulahebrew'] = 0x05A6;
  11580. t['merkhakefulalefthebrew'] = 0x05A6;
  11581. t['merkhalefthebrew'] = 0x05A5;
  11582. t['mhook'] = 0x0271;
  11583. t['mhzsquare'] = 0x3392;
  11584. t['middledotkatakanahalfwidth'] = 0xFF65;
  11585. t['middot'] = 0x00B7;
  11586. t['mieumacirclekorean'] = 0x3272;
  11587. t['mieumaparenkorean'] = 0x3212;
  11588. t['mieumcirclekorean'] = 0x3264;
  11589. t['mieumkorean'] = 0x3141;
  11590. t['mieumpansioskorean'] = 0x3170;
  11591. t['mieumparenkorean'] = 0x3204;
  11592. t['mieumpieupkorean'] = 0x316E;
  11593. t['mieumsioskorean'] = 0x316F;
  11594. t['mihiragana'] = 0x307F;
  11595. t['mikatakana'] = 0x30DF;
  11596. t['mikatakanahalfwidth'] = 0xFF90;
  11597. t['minus'] = 0x2212;
  11598. t['minusbelowcmb'] = 0x0320;
  11599. t['minuscircle'] = 0x2296;
  11600. t['minusmod'] = 0x02D7;
  11601. t['minusplus'] = 0x2213;
  11602. t['minute'] = 0x2032;
  11603. t['miribaarusquare'] = 0x334A;
  11604. t['mirisquare'] = 0x3349;
  11605. t['mlonglegturned'] = 0x0270;
  11606. t['mlsquare'] = 0x3396;
  11607. t['mmcubedsquare'] = 0x33A3;
  11608. t['mmonospace'] = 0xFF4D;
  11609. t['mmsquaredsquare'] = 0x339F;
  11610. t['mohiragana'] = 0x3082;
  11611. t['mohmsquare'] = 0x33C1;
  11612. t['mokatakana'] = 0x30E2;
  11613. t['mokatakanahalfwidth'] = 0xFF93;
  11614. t['molsquare'] = 0x33D6;
  11615. t['momathai'] = 0x0E21;
  11616. t['moverssquare'] = 0x33A7;
  11617. t['moverssquaredsquare'] = 0x33A8;
  11618. t['mparen'] = 0x24A8;
  11619. t['mpasquare'] = 0x33AB;
  11620. t['mssquare'] = 0x33B3;
  11621. t['msuperior'] = 0xF6EF;
  11622. t['mturned'] = 0x026F;
  11623. t['mu'] = 0x00B5;
  11624. t['mu1'] = 0x00B5;
  11625. t['muasquare'] = 0x3382;
  11626. t['muchgreater'] = 0x226B;
  11627. t['muchless'] = 0x226A;
  11628. t['mufsquare'] = 0x338C;
  11629. t['mugreek'] = 0x03BC;
  11630. t['mugsquare'] = 0x338D;
  11631. t['muhiragana'] = 0x3080;
  11632. t['mukatakana'] = 0x30E0;
  11633. t['mukatakanahalfwidth'] = 0xFF91;
  11634. t['mulsquare'] = 0x3395;
  11635. t['multiply'] = 0x00D7;
  11636. t['mumsquare'] = 0x339B;
  11637. t['munahhebrew'] = 0x05A3;
  11638. t['munahlefthebrew'] = 0x05A3;
  11639. t['musicalnote'] = 0x266A;
  11640. t['musicalnotedbl'] = 0x266B;
  11641. t['musicflatsign'] = 0x266D;
  11642. t['musicsharpsign'] = 0x266F;
  11643. t['mussquare'] = 0x33B2;
  11644. t['muvsquare'] = 0x33B6;
  11645. t['muwsquare'] = 0x33BC;
  11646. t['mvmegasquare'] = 0x33B9;
  11647. t['mvsquare'] = 0x33B7;
  11648. t['mwmegasquare'] = 0x33BF;
  11649. t['mwsquare'] = 0x33BD;
  11650. t['n'] = 0x006E;
  11651. t['nabengali'] = 0x09A8;
  11652. t['nabla'] = 0x2207;
  11653. t['nacute'] = 0x0144;
  11654. t['nadeva'] = 0x0928;
  11655. t['nagujarati'] = 0x0AA8;
  11656. t['nagurmukhi'] = 0x0A28;
  11657. t['nahiragana'] = 0x306A;
  11658. t['nakatakana'] = 0x30CA;
  11659. t['nakatakanahalfwidth'] = 0xFF85;
  11660. t['napostrophe'] = 0x0149;
  11661. t['nasquare'] = 0x3381;
  11662. t['nbopomofo'] = 0x310B;
  11663. t['nbspace'] = 0x00A0;
  11664. t['ncaron'] = 0x0148;
  11665. t['ncedilla'] = 0x0146;
  11666. t['ncircle'] = 0x24DD;
  11667. t['ncircumflexbelow'] = 0x1E4B;
  11668. t['ncommaaccent'] = 0x0146;
  11669. t['ndotaccent'] = 0x1E45;
  11670. t['ndotbelow'] = 0x1E47;
  11671. t['nehiragana'] = 0x306D;
  11672. t['nekatakana'] = 0x30CD;
  11673. t['nekatakanahalfwidth'] = 0xFF88;
  11674. t['newsheqelsign'] = 0x20AA;
  11675. t['nfsquare'] = 0x338B;
  11676. t['ngabengali'] = 0x0999;
  11677. t['ngadeva'] = 0x0919;
  11678. t['ngagujarati'] = 0x0A99;
  11679. t['ngagurmukhi'] = 0x0A19;
  11680. t['ngonguthai'] = 0x0E07;
  11681. t['nhiragana'] = 0x3093;
  11682. t['nhookleft'] = 0x0272;
  11683. t['nhookretroflex'] = 0x0273;
  11684. t['nieunacirclekorean'] = 0x326F;
  11685. t['nieunaparenkorean'] = 0x320F;
  11686. t['nieuncieuckorean'] = 0x3135;
  11687. t['nieuncirclekorean'] = 0x3261;
  11688. t['nieunhieuhkorean'] = 0x3136;
  11689. t['nieunkorean'] = 0x3134;
  11690. t['nieunpansioskorean'] = 0x3168;
  11691. t['nieunparenkorean'] = 0x3201;
  11692. t['nieunsioskorean'] = 0x3167;
  11693. t['nieuntikeutkorean'] = 0x3166;
  11694. t['nihiragana'] = 0x306B;
  11695. t['nikatakana'] = 0x30CB;
  11696. t['nikatakanahalfwidth'] = 0xFF86;
  11697. t['nikhahitleftthai'] = 0xF899;
  11698. t['nikhahitthai'] = 0x0E4D;
  11699. t['nine'] = 0x0039;
  11700. t['ninearabic'] = 0x0669;
  11701. t['ninebengali'] = 0x09EF;
  11702. t['ninecircle'] = 0x2468;
  11703. t['ninecircleinversesansserif'] = 0x2792;
  11704. t['ninedeva'] = 0x096F;
  11705. t['ninegujarati'] = 0x0AEF;
  11706. t['ninegurmukhi'] = 0x0A6F;
  11707. t['ninehackarabic'] = 0x0669;
  11708. t['ninehangzhou'] = 0x3029;
  11709. t['nineideographicparen'] = 0x3228;
  11710. t['nineinferior'] = 0x2089;
  11711. t['ninemonospace'] = 0xFF19;
  11712. t['nineoldstyle'] = 0xF739;
  11713. t['nineparen'] = 0x247C;
  11714. t['nineperiod'] = 0x2490;
  11715. t['ninepersian'] = 0x06F9;
  11716. t['nineroman'] = 0x2178;
  11717. t['ninesuperior'] = 0x2079;
  11718. t['nineteencircle'] = 0x2472;
  11719. t['nineteenparen'] = 0x2486;
  11720. t['nineteenperiod'] = 0x249A;
  11721. t['ninethai'] = 0x0E59;
  11722. t['nj'] = 0x01CC;
  11723. t['njecyrillic'] = 0x045A;
  11724. t['nkatakana'] = 0x30F3;
  11725. t['nkatakanahalfwidth'] = 0xFF9D;
  11726. t['nlegrightlong'] = 0x019E;
  11727. t['nlinebelow'] = 0x1E49;
  11728. t['nmonospace'] = 0xFF4E;
  11729. t['nmsquare'] = 0x339A;
  11730. t['nnabengali'] = 0x09A3;
  11731. t['nnadeva'] = 0x0923;
  11732. t['nnagujarati'] = 0x0AA3;
  11733. t['nnagurmukhi'] = 0x0A23;
  11734. t['nnnadeva'] = 0x0929;
  11735. t['nohiragana'] = 0x306E;
  11736. t['nokatakana'] = 0x30CE;
  11737. t['nokatakanahalfwidth'] = 0xFF89;
  11738. t['nonbreakingspace'] = 0x00A0;
  11739. t['nonenthai'] = 0x0E13;
  11740. t['nonuthai'] = 0x0E19;
  11741. t['noonarabic'] = 0x0646;
  11742. t['noonfinalarabic'] = 0xFEE6;
  11743. t['noonghunnaarabic'] = 0x06BA;
  11744. t['noonghunnafinalarabic'] = 0xFB9F;
  11745. t['nooninitialarabic'] = 0xFEE7;
  11746. t['noonjeeminitialarabic'] = 0xFCD2;
  11747. t['noonjeemisolatedarabic'] = 0xFC4B;
  11748. t['noonmedialarabic'] = 0xFEE8;
  11749. t['noonmeeminitialarabic'] = 0xFCD5;
  11750. t['noonmeemisolatedarabic'] = 0xFC4E;
  11751. t['noonnoonfinalarabic'] = 0xFC8D;
  11752. t['notcontains'] = 0x220C;
  11753. t['notelement'] = 0x2209;
  11754. t['notelementof'] = 0x2209;
  11755. t['notequal'] = 0x2260;
  11756. t['notgreater'] = 0x226F;
  11757. t['notgreaternorequal'] = 0x2271;
  11758. t['notgreaternorless'] = 0x2279;
  11759. t['notidentical'] = 0x2262;
  11760. t['notless'] = 0x226E;
  11761. t['notlessnorequal'] = 0x2270;
  11762. t['notparallel'] = 0x2226;
  11763. t['notprecedes'] = 0x2280;
  11764. t['notsubset'] = 0x2284;
  11765. t['notsucceeds'] = 0x2281;
  11766. t['notsuperset'] = 0x2285;
  11767. t['nowarmenian'] = 0x0576;
  11768. t['nparen'] = 0x24A9;
  11769. t['nssquare'] = 0x33B1;
  11770. t['nsuperior'] = 0x207F;
  11771. t['ntilde'] = 0x00F1;
  11772. t['nu'] = 0x03BD;
  11773. t['nuhiragana'] = 0x306C;
  11774. t['nukatakana'] = 0x30CC;
  11775. t['nukatakanahalfwidth'] = 0xFF87;
  11776. t['nuktabengali'] = 0x09BC;
  11777. t['nuktadeva'] = 0x093C;
  11778. t['nuktagujarati'] = 0x0ABC;
  11779. t['nuktagurmukhi'] = 0x0A3C;
  11780. t['numbersign'] = 0x0023;
  11781. t['numbersignmonospace'] = 0xFF03;
  11782. t['numbersignsmall'] = 0xFE5F;
  11783. t['numeralsigngreek'] = 0x0374;
  11784. t['numeralsignlowergreek'] = 0x0375;
  11785. t['numero'] = 0x2116;
  11786. t['nun'] = 0x05E0;
  11787. t['nundagesh'] = 0xFB40;
  11788. t['nundageshhebrew'] = 0xFB40;
  11789. t['nunhebrew'] = 0x05E0;
  11790. t['nvsquare'] = 0x33B5;
  11791. t['nwsquare'] = 0x33BB;
  11792. t['nyabengali'] = 0x099E;
  11793. t['nyadeva'] = 0x091E;
  11794. t['nyagujarati'] = 0x0A9E;
  11795. t['nyagurmukhi'] = 0x0A1E;
  11796. t['o'] = 0x006F;
  11797. t['oacute'] = 0x00F3;
  11798. t['oangthai'] = 0x0E2D;
  11799. t['obarred'] = 0x0275;
  11800. t['obarredcyrillic'] = 0x04E9;
  11801. t['obarreddieresiscyrillic'] = 0x04EB;
  11802. t['obengali'] = 0x0993;
  11803. t['obopomofo'] = 0x311B;
  11804. t['obreve'] = 0x014F;
  11805. t['ocandradeva'] = 0x0911;
  11806. t['ocandragujarati'] = 0x0A91;
  11807. t['ocandravowelsigndeva'] = 0x0949;
  11808. t['ocandravowelsigngujarati'] = 0x0AC9;
  11809. t['ocaron'] = 0x01D2;
  11810. t['ocircle'] = 0x24DE;
  11811. t['ocircumflex'] = 0x00F4;
  11812. t['ocircumflexacute'] = 0x1ED1;
  11813. t['ocircumflexdotbelow'] = 0x1ED9;
  11814. t['ocircumflexgrave'] = 0x1ED3;
  11815. t['ocircumflexhookabove'] = 0x1ED5;
  11816. t['ocircumflextilde'] = 0x1ED7;
  11817. t['ocyrillic'] = 0x043E;
  11818. t['odblacute'] = 0x0151;
  11819. t['odblgrave'] = 0x020D;
  11820. t['odeva'] = 0x0913;
  11821. t['odieresis'] = 0x00F6;
  11822. t['odieresiscyrillic'] = 0x04E7;
  11823. t['odotbelow'] = 0x1ECD;
  11824. t['oe'] = 0x0153;
  11825. t['oekorean'] = 0x315A;
  11826. t['ogonek'] = 0x02DB;
  11827. t['ogonekcmb'] = 0x0328;
  11828. t['ograve'] = 0x00F2;
  11829. t['ogujarati'] = 0x0A93;
  11830. t['oharmenian'] = 0x0585;
  11831. t['ohiragana'] = 0x304A;
  11832. t['ohookabove'] = 0x1ECF;
  11833. t['ohorn'] = 0x01A1;
  11834. t['ohornacute'] = 0x1EDB;
  11835. t['ohorndotbelow'] = 0x1EE3;
  11836. t['ohorngrave'] = 0x1EDD;
  11837. t['ohornhookabove'] = 0x1EDF;
  11838. t['ohorntilde'] = 0x1EE1;
  11839. t['ohungarumlaut'] = 0x0151;
  11840. t['oi'] = 0x01A3;
  11841. t['oinvertedbreve'] = 0x020F;
  11842. t['okatakana'] = 0x30AA;
  11843. t['okatakanahalfwidth'] = 0xFF75;
  11844. t['okorean'] = 0x3157;
  11845. t['olehebrew'] = 0x05AB;
  11846. t['omacron'] = 0x014D;
  11847. t['omacronacute'] = 0x1E53;
  11848. t['omacrongrave'] = 0x1E51;
  11849. t['omdeva'] = 0x0950;
  11850. t['omega'] = 0x03C9;
  11851. t['omega1'] = 0x03D6;
  11852. t['omegacyrillic'] = 0x0461;
  11853. t['omegalatinclosed'] = 0x0277;
  11854. t['omegaroundcyrillic'] = 0x047B;
  11855. t['omegatitlocyrillic'] = 0x047D;
  11856. t['omegatonos'] = 0x03CE;
  11857. t['omgujarati'] = 0x0AD0;
  11858. t['omicron'] = 0x03BF;
  11859. t['omicrontonos'] = 0x03CC;
  11860. t['omonospace'] = 0xFF4F;
  11861. t['one'] = 0x0031;
  11862. t['onearabic'] = 0x0661;
  11863. t['onebengali'] = 0x09E7;
  11864. t['onecircle'] = 0x2460;
  11865. t['onecircleinversesansserif'] = 0x278A;
  11866. t['onedeva'] = 0x0967;
  11867. t['onedotenleader'] = 0x2024;
  11868. t['oneeighth'] = 0x215B;
  11869. t['onefitted'] = 0xF6DC;
  11870. t['onegujarati'] = 0x0AE7;
  11871. t['onegurmukhi'] = 0x0A67;
  11872. t['onehackarabic'] = 0x0661;
  11873. t['onehalf'] = 0x00BD;
  11874. t['onehangzhou'] = 0x3021;
  11875. t['oneideographicparen'] = 0x3220;
  11876. t['oneinferior'] = 0x2081;
  11877. t['onemonospace'] = 0xFF11;
  11878. t['onenumeratorbengali'] = 0x09F4;
  11879. t['oneoldstyle'] = 0xF731;
  11880. t['oneparen'] = 0x2474;
  11881. t['oneperiod'] = 0x2488;
  11882. t['onepersian'] = 0x06F1;
  11883. t['onequarter'] = 0x00BC;
  11884. t['oneroman'] = 0x2170;
  11885. t['onesuperior'] = 0x00B9;
  11886. t['onethai'] = 0x0E51;
  11887. t['onethird'] = 0x2153;
  11888. t['oogonek'] = 0x01EB;
  11889. t['oogonekmacron'] = 0x01ED;
  11890. t['oogurmukhi'] = 0x0A13;
  11891. t['oomatragurmukhi'] = 0x0A4B;
  11892. t['oopen'] = 0x0254;
  11893. t['oparen'] = 0x24AA;
  11894. t['openbullet'] = 0x25E6;
  11895. t['option'] = 0x2325;
  11896. t['ordfeminine'] = 0x00AA;
  11897. t['ordmasculine'] = 0x00BA;
  11898. t['orthogonal'] = 0x221F;
  11899. t['oshortdeva'] = 0x0912;
  11900. t['oshortvowelsigndeva'] = 0x094A;
  11901. t['oslash'] = 0x00F8;
  11902. t['oslashacute'] = 0x01FF;
  11903. t['osmallhiragana'] = 0x3049;
  11904. t['osmallkatakana'] = 0x30A9;
  11905. t['osmallkatakanahalfwidth'] = 0xFF6B;
  11906. t['ostrokeacute'] = 0x01FF;
  11907. t['osuperior'] = 0xF6F0;
  11908. t['otcyrillic'] = 0x047F;
  11909. t['otilde'] = 0x00F5;
  11910. t['otildeacute'] = 0x1E4D;
  11911. t['otildedieresis'] = 0x1E4F;
  11912. t['oubopomofo'] = 0x3121;
  11913. t['overline'] = 0x203E;
  11914. t['overlinecenterline'] = 0xFE4A;
  11915. t['overlinecmb'] = 0x0305;
  11916. t['overlinedashed'] = 0xFE49;
  11917. t['overlinedblwavy'] = 0xFE4C;
  11918. t['overlinewavy'] = 0xFE4B;
  11919. t['overscore'] = 0x00AF;
  11920. t['ovowelsignbengali'] = 0x09CB;
  11921. t['ovowelsigndeva'] = 0x094B;
  11922. t['ovowelsigngujarati'] = 0x0ACB;
  11923. t['p'] = 0x0070;
  11924. t['paampssquare'] = 0x3380;
  11925. t['paasentosquare'] = 0x332B;
  11926. t['pabengali'] = 0x09AA;
  11927. t['pacute'] = 0x1E55;
  11928. t['padeva'] = 0x092A;
  11929. t['pagedown'] = 0x21DF;
  11930. t['pageup'] = 0x21DE;
  11931. t['pagujarati'] = 0x0AAA;
  11932. t['pagurmukhi'] = 0x0A2A;
  11933. t['pahiragana'] = 0x3071;
  11934. t['paiyannoithai'] = 0x0E2F;
  11935. t['pakatakana'] = 0x30D1;
  11936. t['palatalizationcyrilliccmb'] = 0x0484;
  11937. t['palochkacyrillic'] = 0x04C0;
  11938. t['pansioskorean'] = 0x317F;
  11939. t['paragraph'] = 0x00B6;
  11940. t['parallel'] = 0x2225;
  11941. t['parenleft'] = 0x0028;
  11942. t['parenleftaltonearabic'] = 0xFD3E;
  11943. t['parenleftbt'] = 0xF8ED;
  11944. t['parenleftex'] = 0xF8EC;
  11945. t['parenleftinferior'] = 0x208D;
  11946. t['parenleftmonospace'] = 0xFF08;
  11947. t['parenleftsmall'] = 0xFE59;
  11948. t['parenleftsuperior'] = 0x207D;
  11949. t['parenlefttp'] = 0xF8EB;
  11950. t['parenleftvertical'] = 0xFE35;
  11951. t['parenright'] = 0x0029;
  11952. t['parenrightaltonearabic'] = 0xFD3F;
  11953. t['parenrightbt'] = 0xF8F8;
  11954. t['parenrightex'] = 0xF8F7;
  11955. t['parenrightinferior'] = 0x208E;
  11956. t['parenrightmonospace'] = 0xFF09;
  11957. t['parenrightsmall'] = 0xFE5A;
  11958. t['parenrightsuperior'] = 0x207E;
  11959. t['parenrighttp'] = 0xF8F6;
  11960. t['parenrightvertical'] = 0xFE36;
  11961. t['partialdiff'] = 0x2202;
  11962. t['paseqhebrew'] = 0x05C0;
  11963. t['pashtahebrew'] = 0x0599;
  11964. t['pasquare'] = 0x33A9;
  11965. t['patah'] = 0x05B7;
  11966. t['patah11'] = 0x05B7;
  11967. t['patah1d'] = 0x05B7;
  11968. t['patah2a'] = 0x05B7;
  11969. t['patahhebrew'] = 0x05B7;
  11970. t['patahnarrowhebrew'] = 0x05B7;
  11971. t['patahquarterhebrew'] = 0x05B7;
  11972. t['patahwidehebrew'] = 0x05B7;
  11973. t['pazerhebrew'] = 0x05A1;
  11974. t['pbopomofo'] = 0x3106;
  11975. t['pcircle'] = 0x24DF;
  11976. t['pdotaccent'] = 0x1E57;
  11977. t['pe'] = 0x05E4;
  11978. t['pecyrillic'] = 0x043F;
  11979. t['pedagesh'] = 0xFB44;
  11980. t['pedageshhebrew'] = 0xFB44;
  11981. t['peezisquare'] = 0x333B;
  11982. t['pefinaldageshhebrew'] = 0xFB43;
  11983. t['peharabic'] = 0x067E;
  11984. t['peharmenian'] = 0x057A;
  11985. t['pehebrew'] = 0x05E4;
  11986. t['pehfinalarabic'] = 0xFB57;
  11987. t['pehinitialarabic'] = 0xFB58;
  11988. t['pehiragana'] = 0x307A;
  11989. t['pehmedialarabic'] = 0xFB59;
  11990. t['pekatakana'] = 0x30DA;
  11991. t['pemiddlehookcyrillic'] = 0x04A7;
  11992. t['perafehebrew'] = 0xFB4E;
  11993. t['percent'] = 0x0025;
  11994. t['percentarabic'] = 0x066A;
  11995. t['percentmonospace'] = 0xFF05;
  11996. t['percentsmall'] = 0xFE6A;
  11997. t['period'] = 0x002E;
  11998. t['periodarmenian'] = 0x0589;
  11999. t['periodcentered'] = 0x00B7;
  12000. t['periodhalfwidth'] = 0xFF61;
  12001. t['periodinferior'] = 0xF6E7;
  12002. t['periodmonospace'] = 0xFF0E;
  12003. t['periodsmall'] = 0xFE52;
  12004. t['periodsuperior'] = 0xF6E8;
  12005. t['perispomenigreekcmb'] = 0x0342;
  12006. t['perpendicular'] = 0x22A5;
  12007. t['perthousand'] = 0x2030;
  12008. t['peseta'] = 0x20A7;
  12009. t['pfsquare'] = 0x338A;
  12010. t['phabengali'] = 0x09AB;
  12011. t['phadeva'] = 0x092B;
  12012. t['phagujarati'] = 0x0AAB;
  12013. t['phagurmukhi'] = 0x0A2B;
  12014. t['phi'] = 0x03C6;
  12015. t['phi1'] = 0x03D5;
  12016. t['phieuphacirclekorean'] = 0x327A;
  12017. t['phieuphaparenkorean'] = 0x321A;
  12018. t['phieuphcirclekorean'] = 0x326C;
  12019. t['phieuphkorean'] = 0x314D;
  12020. t['phieuphparenkorean'] = 0x320C;
  12021. t['philatin'] = 0x0278;
  12022. t['phinthuthai'] = 0x0E3A;
  12023. t['phisymbolgreek'] = 0x03D5;
  12024. t['phook'] = 0x01A5;
  12025. t['phophanthai'] = 0x0E1E;
  12026. t['phophungthai'] = 0x0E1C;
  12027. t['phosamphaothai'] = 0x0E20;
  12028. t['pi'] = 0x03C0;
  12029. t['pieupacirclekorean'] = 0x3273;
  12030. t['pieupaparenkorean'] = 0x3213;
  12031. t['pieupcieuckorean'] = 0x3176;
  12032. t['pieupcirclekorean'] = 0x3265;
  12033. t['pieupkiyeokkorean'] = 0x3172;
  12034. t['pieupkorean'] = 0x3142;
  12035. t['pieupparenkorean'] = 0x3205;
  12036. t['pieupsioskiyeokkorean'] = 0x3174;
  12037. t['pieupsioskorean'] = 0x3144;
  12038. t['pieupsiostikeutkorean'] = 0x3175;
  12039. t['pieupthieuthkorean'] = 0x3177;
  12040. t['pieuptikeutkorean'] = 0x3173;
  12041. t['pihiragana'] = 0x3074;
  12042. t['pikatakana'] = 0x30D4;
  12043. t['pisymbolgreek'] = 0x03D6;
  12044. t['piwrarmenian'] = 0x0583;
  12045. t['plus'] = 0x002B;
  12046. t['plusbelowcmb'] = 0x031F;
  12047. t['pluscircle'] = 0x2295;
  12048. t['plusminus'] = 0x00B1;
  12049. t['plusmod'] = 0x02D6;
  12050. t['plusmonospace'] = 0xFF0B;
  12051. t['plussmall'] = 0xFE62;
  12052. t['plussuperior'] = 0x207A;
  12053. t['pmonospace'] = 0xFF50;
  12054. t['pmsquare'] = 0x33D8;
  12055. t['pohiragana'] = 0x307D;
  12056. t['pointingindexdownwhite'] = 0x261F;
  12057. t['pointingindexleftwhite'] = 0x261C;
  12058. t['pointingindexrightwhite'] = 0x261E;
  12059. t['pointingindexupwhite'] = 0x261D;
  12060. t['pokatakana'] = 0x30DD;
  12061. t['poplathai'] = 0x0E1B;
  12062. t['postalmark'] = 0x3012;
  12063. t['postalmarkface'] = 0x3020;
  12064. t['pparen'] = 0x24AB;
  12065. t['precedes'] = 0x227A;
  12066. t['prescription'] = 0x211E;
  12067. t['primemod'] = 0x02B9;
  12068. t['primereversed'] = 0x2035;
  12069. t['product'] = 0x220F;
  12070. t['projective'] = 0x2305;
  12071. t['prolongedkana'] = 0x30FC;
  12072. t['propellor'] = 0x2318;
  12073. t['propersubset'] = 0x2282;
  12074. t['propersuperset'] = 0x2283;
  12075. t['proportion'] = 0x2237;
  12076. t['proportional'] = 0x221D;
  12077. t['psi'] = 0x03C8;
  12078. t['psicyrillic'] = 0x0471;
  12079. t['psilipneumatacyrilliccmb'] = 0x0486;
  12080. t['pssquare'] = 0x33B0;
  12081. t['puhiragana'] = 0x3077;
  12082. t['pukatakana'] = 0x30D7;
  12083. t['pvsquare'] = 0x33B4;
  12084. t['pwsquare'] = 0x33BA;
  12085. t['q'] = 0x0071;
  12086. t['qadeva'] = 0x0958;
  12087. t['qadmahebrew'] = 0x05A8;
  12088. t['qafarabic'] = 0x0642;
  12089. t['qaffinalarabic'] = 0xFED6;
  12090. t['qafinitialarabic'] = 0xFED7;
  12091. t['qafmedialarabic'] = 0xFED8;
  12092. t['qamats'] = 0x05B8;
  12093. t['qamats10'] = 0x05B8;
  12094. t['qamats1a'] = 0x05B8;
  12095. t['qamats1c'] = 0x05B8;
  12096. t['qamats27'] = 0x05B8;
  12097. t['qamats29'] = 0x05B8;
  12098. t['qamats33'] = 0x05B8;
  12099. t['qamatsde'] = 0x05B8;
  12100. t['qamatshebrew'] = 0x05B8;
  12101. t['qamatsnarrowhebrew'] = 0x05B8;
  12102. t['qamatsqatanhebrew'] = 0x05B8;
  12103. t['qamatsqatannarrowhebrew'] = 0x05B8;
  12104. t['qamatsqatanquarterhebrew'] = 0x05B8;
  12105. t['qamatsqatanwidehebrew'] = 0x05B8;
  12106. t['qamatsquarterhebrew'] = 0x05B8;
  12107. t['qamatswidehebrew'] = 0x05B8;
  12108. t['qarneyparahebrew'] = 0x059F;
  12109. t['qbopomofo'] = 0x3111;
  12110. t['qcircle'] = 0x24E0;
  12111. t['qhook'] = 0x02A0;
  12112. t['qmonospace'] = 0xFF51;
  12113. t['qof'] = 0x05E7;
  12114. t['qofdagesh'] = 0xFB47;
  12115. t['qofdageshhebrew'] = 0xFB47;
  12116. t['qofhebrew'] = 0x05E7;
  12117. t['qparen'] = 0x24AC;
  12118. t['quarternote'] = 0x2669;
  12119. t['qubuts'] = 0x05BB;
  12120. t['qubuts18'] = 0x05BB;
  12121. t['qubuts25'] = 0x05BB;
  12122. t['qubuts31'] = 0x05BB;
  12123. t['qubutshebrew'] = 0x05BB;
  12124. t['qubutsnarrowhebrew'] = 0x05BB;
  12125. t['qubutsquarterhebrew'] = 0x05BB;
  12126. t['qubutswidehebrew'] = 0x05BB;
  12127. t['question'] = 0x003F;
  12128. t['questionarabic'] = 0x061F;
  12129. t['questionarmenian'] = 0x055E;
  12130. t['questiondown'] = 0x00BF;
  12131. t['questiondownsmall'] = 0xF7BF;
  12132. t['questiongreek'] = 0x037E;
  12133. t['questionmonospace'] = 0xFF1F;
  12134. t['questionsmall'] = 0xF73F;
  12135. t['quotedbl'] = 0x0022;
  12136. t['quotedblbase'] = 0x201E;
  12137. t['quotedblleft'] = 0x201C;
  12138. t['quotedblmonospace'] = 0xFF02;
  12139. t['quotedblprime'] = 0x301E;
  12140. t['quotedblprimereversed'] = 0x301D;
  12141. t['quotedblright'] = 0x201D;
  12142. t['quoteleft'] = 0x2018;
  12143. t['quoteleftreversed'] = 0x201B;
  12144. t['quotereversed'] = 0x201B;
  12145. t['quoteright'] = 0x2019;
  12146. t['quoterightn'] = 0x0149;
  12147. t['quotesinglbase'] = 0x201A;
  12148. t['quotesingle'] = 0x0027;
  12149. t['quotesinglemonospace'] = 0xFF07;
  12150. t['r'] = 0x0072;
  12151. t['raarmenian'] = 0x057C;
  12152. t['rabengali'] = 0x09B0;
  12153. t['racute'] = 0x0155;
  12154. t['radeva'] = 0x0930;
  12155. t['radical'] = 0x221A;
  12156. t['radicalex'] = 0xF8E5;
  12157. t['radoverssquare'] = 0x33AE;
  12158. t['radoverssquaredsquare'] = 0x33AF;
  12159. t['radsquare'] = 0x33AD;
  12160. t['rafe'] = 0x05BF;
  12161. t['rafehebrew'] = 0x05BF;
  12162. t['ragujarati'] = 0x0AB0;
  12163. t['ragurmukhi'] = 0x0A30;
  12164. t['rahiragana'] = 0x3089;
  12165. t['rakatakana'] = 0x30E9;
  12166. t['rakatakanahalfwidth'] = 0xFF97;
  12167. t['ralowerdiagonalbengali'] = 0x09F1;
  12168. t['ramiddlediagonalbengali'] = 0x09F0;
  12169. t['ramshorn'] = 0x0264;
  12170. t['ratio'] = 0x2236;
  12171. t['rbopomofo'] = 0x3116;
  12172. t['rcaron'] = 0x0159;
  12173. t['rcedilla'] = 0x0157;
  12174. t['rcircle'] = 0x24E1;
  12175. t['rcommaaccent'] = 0x0157;
  12176. t['rdblgrave'] = 0x0211;
  12177. t['rdotaccent'] = 0x1E59;
  12178. t['rdotbelow'] = 0x1E5B;
  12179. t['rdotbelowmacron'] = 0x1E5D;
  12180. t['referencemark'] = 0x203B;
  12181. t['reflexsubset'] = 0x2286;
  12182. t['reflexsuperset'] = 0x2287;
  12183. t['registered'] = 0x00AE;
  12184. t['registersans'] = 0xF8E8;
  12185. t['registerserif'] = 0xF6DA;
  12186. t['reharabic'] = 0x0631;
  12187. t['reharmenian'] = 0x0580;
  12188. t['rehfinalarabic'] = 0xFEAE;
  12189. t['rehiragana'] = 0x308C;
  12190. t['rekatakana'] = 0x30EC;
  12191. t['rekatakanahalfwidth'] = 0xFF9A;
  12192. t['resh'] = 0x05E8;
  12193. t['reshdageshhebrew'] = 0xFB48;
  12194. t['reshhebrew'] = 0x05E8;
  12195. t['reversedtilde'] = 0x223D;
  12196. t['reviahebrew'] = 0x0597;
  12197. t['reviamugrashhebrew'] = 0x0597;
  12198. t['revlogicalnot'] = 0x2310;
  12199. t['rfishhook'] = 0x027E;
  12200. t['rfishhookreversed'] = 0x027F;
  12201. t['rhabengali'] = 0x09DD;
  12202. t['rhadeva'] = 0x095D;
  12203. t['rho'] = 0x03C1;
  12204. t['rhook'] = 0x027D;
  12205. t['rhookturned'] = 0x027B;
  12206. t['rhookturnedsuperior'] = 0x02B5;
  12207. t['rhosymbolgreek'] = 0x03F1;
  12208. t['rhotichookmod'] = 0x02DE;
  12209. t['rieulacirclekorean'] = 0x3271;
  12210. t['rieulaparenkorean'] = 0x3211;
  12211. t['rieulcirclekorean'] = 0x3263;
  12212. t['rieulhieuhkorean'] = 0x3140;
  12213. t['rieulkiyeokkorean'] = 0x313A;
  12214. t['rieulkiyeoksioskorean'] = 0x3169;
  12215. t['rieulkorean'] = 0x3139;
  12216. t['rieulmieumkorean'] = 0x313B;
  12217. t['rieulpansioskorean'] = 0x316C;
  12218. t['rieulparenkorean'] = 0x3203;
  12219. t['rieulphieuphkorean'] = 0x313F;
  12220. t['rieulpieupkorean'] = 0x313C;
  12221. t['rieulpieupsioskorean'] = 0x316B;
  12222. t['rieulsioskorean'] = 0x313D;
  12223. t['rieulthieuthkorean'] = 0x313E;
  12224. t['rieultikeutkorean'] = 0x316A;
  12225. t['rieulyeorinhieuhkorean'] = 0x316D;
  12226. t['rightangle'] = 0x221F;
  12227. t['righttackbelowcmb'] = 0x0319;
  12228. t['righttriangle'] = 0x22BF;
  12229. t['rihiragana'] = 0x308A;
  12230. t['rikatakana'] = 0x30EA;
  12231. t['rikatakanahalfwidth'] = 0xFF98;
  12232. t['ring'] = 0x02DA;
  12233. t['ringbelowcmb'] = 0x0325;
  12234. t['ringcmb'] = 0x030A;
  12235. t['ringhalfleft'] = 0x02BF;
  12236. t['ringhalfleftarmenian'] = 0x0559;
  12237. t['ringhalfleftbelowcmb'] = 0x031C;
  12238. t['ringhalfleftcentered'] = 0x02D3;
  12239. t['ringhalfright'] = 0x02BE;
  12240. t['ringhalfrightbelowcmb'] = 0x0339;
  12241. t['ringhalfrightcentered'] = 0x02D2;
  12242. t['rinvertedbreve'] = 0x0213;
  12243. t['rittorusquare'] = 0x3351;
  12244. t['rlinebelow'] = 0x1E5F;
  12245. t['rlongleg'] = 0x027C;
  12246. t['rlonglegturned'] = 0x027A;
  12247. t['rmonospace'] = 0xFF52;
  12248. t['rohiragana'] = 0x308D;
  12249. t['rokatakana'] = 0x30ED;
  12250. t['rokatakanahalfwidth'] = 0xFF9B;
  12251. t['roruathai'] = 0x0E23;
  12252. t['rparen'] = 0x24AD;
  12253. t['rrabengali'] = 0x09DC;
  12254. t['rradeva'] = 0x0931;
  12255. t['rragurmukhi'] = 0x0A5C;
  12256. t['rreharabic'] = 0x0691;
  12257. t['rrehfinalarabic'] = 0xFB8D;
  12258. t['rrvocalicbengali'] = 0x09E0;
  12259. t['rrvocalicdeva'] = 0x0960;
  12260. t['rrvocalicgujarati'] = 0x0AE0;
  12261. t['rrvocalicvowelsignbengali'] = 0x09C4;
  12262. t['rrvocalicvowelsigndeva'] = 0x0944;
  12263. t['rrvocalicvowelsigngujarati'] = 0x0AC4;
  12264. t['rsuperior'] = 0xF6F1;
  12265. t['rtblock'] = 0x2590;
  12266. t['rturned'] = 0x0279;
  12267. t['rturnedsuperior'] = 0x02B4;
  12268. t['ruhiragana'] = 0x308B;
  12269. t['rukatakana'] = 0x30EB;
  12270. t['rukatakanahalfwidth'] = 0xFF99;
  12271. t['rupeemarkbengali'] = 0x09F2;
  12272. t['rupeesignbengali'] = 0x09F3;
  12273. t['rupiah'] = 0xF6DD;
  12274. t['ruthai'] = 0x0E24;
  12275. t['rvocalicbengali'] = 0x098B;
  12276. t['rvocalicdeva'] = 0x090B;
  12277. t['rvocalicgujarati'] = 0x0A8B;
  12278. t['rvocalicvowelsignbengali'] = 0x09C3;
  12279. t['rvocalicvowelsigndeva'] = 0x0943;
  12280. t['rvocalicvowelsigngujarati'] = 0x0AC3;
  12281. t['s'] = 0x0073;
  12282. t['sabengali'] = 0x09B8;
  12283. t['sacute'] = 0x015B;
  12284. t['sacutedotaccent'] = 0x1E65;
  12285. t['sadarabic'] = 0x0635;
  12286. t['sadeva'] = 0x0938;
  12287. t['sadfinalarabic'] = 0xFEBA;
  12288. t['sadinitialarabic'] = 0xFEBB;
  12289. t['sadmedialarabic'] = 0xFEBC;
  12290. t['sagujarati'] = 0x0AB8;
  12291. t['sagurmukhi'] = 0x0A38;
  12292. t['sahiragana'] = 0x3055;
  12293. t['sakatakana'] = 0x30B5;
  12294. t['sakatakanahalfwidth'] = 0xFF7B;
  12295. t['sallallahoualayhewasallamarabic'] = 0xFDFA;
  12296. t['samekh'] = 0x05E1;
  12297. t['samekhdagesh'] = 0xFB41;
  12298. t['samekhdageshhebrew'] = 0xFB41;
  12299. t['samekhhebrew'] = 0x05E1;
  12300. t['saraaathai'] = 0x0E32;
  12301. t['saraaethai'] = 0x0E41;
  12302. t['saraaimaimalaithai'] = 0x0E44;
  12303. t['saraaimaimuanthai'] = 0x0E43;
  12304. t['saraamthai'] = 0x0E33;
  12305. t['saraathai'] = 0x0E30;
  12306. t['saraethai'] = 0x0E40;
  12307. t['saraiileftthai'] = 0xF886;
  12308. t['saraiithai'] = 0x0E35;
  12309. t['saraileftthai'] = 0xF885;
  12310. t['saraithai'] = 0x0E34;
  12311. t['saraothai'] = 0x0E42;
  12312. t['saraueeleftthai'] = 0xF888;
  12313. t['saraueethai'] = 0x0E37;
  12314. t['saraueleftthai'] = 0xF887;
  12315. t['sarauethai'] = 0x0E36;
  12316. t['sarauthai'] = 0x0E38;
  12317. t['sarauuthai'] = 0x0E39;
  12318. t['sbopomofo'] = 0x3119;
  12319. t['scaron'] = 0x0161;
  12320. t['scarondotaccent'] = 0x1E67;
  12321. t['scedilla'] = 0x015F;
  12322. t['schwa'] = 0x0259;
  12323. t['schwacyrillic'] = 0x04D9;
  12324. t['schwadieresiscyrillic'] = 0x04DB;
  12325. t['schwahook'] = 0x025A;
  12326. t['scircle'] = 0x24E2;
  12327. t['scircumflex'] = 0x015D;
  12328. t['scommaaccent'] = 0x0219;
  12329. t['sdotaccent'] = 0x1E61;
  12330. t['sdotbelow'] = 0x1E63;
  12331. t['sdotbelowdotaccent'] = 0x1E69;
  12332. t['seagullbelowcmb'] = 0x033C;
  12333. t['second'] = 0x2033;
  12334. t['secondtonechinese'] = 0x02CA;
  12335. t['section'] = 0x00A7;
  12336. t['seenarabic'] = 0x0633;
  12337. t['seenfinalarabic'] = 0xFEB2;
  12338. t['seeninitialarabic'] = 0xFEB3;
  12339. t['seenmedialarabic'] = 0xFEB4;
  12340. t['segol'] = 0x05B6;
  12341. t['segol13'] = 0x05B6;
  12342. t['segol1f'] = 0x05B6;
  12343. t['segol2c'] = 0x05B6;
  12344. t['segolhebrew'] = 0x05B6;
  12345. t['segolnarrowhebrew'] = 0x05B6;
  12346. t['segolquarterhebrew'] = 0x05B6;
  12347. t['segoltahebrew'] = 0x0592;
  12348. t['segolwidehebrew'] = 0x05B6;
  12349. t['seharmenian'] = 0x057D;
  12350. t['sehiragana'] = 0x305B;
  12351. t['sekatakana'] = 0x30BB;
  12352. t['sekatakanahalfwidth'] = 0xFF7E;
  12353. t['semicolon'] = 0x003B;
  12354. t['semicolonarabic'] = 0x061B;
  12355. t['semicolonmonospace'] = 0xFF1B;
  12356. t['semicolonsmall'] = 0xFE54;
  12357. t['semivoicedmarkkana'] = 0x309C;
  12358. t['semivoicedmarkkanahalfwidth'] = 0xFF9F;
  12359. t['sentisquare'] = 0x3322;
  12360. t['sentosquare'] = 0x3323;
  12361. t['seven'] = 0x0037;
  12362. t['sevenarabic'] = 0x0667;
  12363. t['sevenbengali'] = 0x09ED;
  12364. t['sevencircle'] = 0x2466;
  12365. t['sevencircleinversesansserif'] = 0x2790;
  12366. t['sevendeva'] = 0x096D;
  12367. t['seveneighths'] = 0x215E;
  12368. t['sevengujarati'] = 0x0AED;
  12369. t['sevengurmukhi'] = 0x0A6D;
  12370. t['sevenhackarabic'] = 0x0667;
  12371. t['sevenhangzhou'] = 0x3027;
  12372. t['sevenideographicparen'] = 0x3226;
  12373. t['seveninferior'] = 0x2087;
  12374. t['sevenmonospace'] = 0xFF17;
  12375. t['sevenoldstyle'] = 0xF737;
  12376. t['sevenparen'] = 0x247A;
  12377. t['sevenperiod'] = 0x248E;
  12378. t['sevenpersian'] = 0x06F7;
  12379. t['sevenroman'] = 0x2176;
  12380. t['sevensuperior'] = 0x2077;
  12381. t['seventeencircle'] = 0x2470;
  12382. t['seventeenparen'] = 0x2484;
  12383. t['seventeenperiod'] = 0x2498;
  12384. t['seventhai'] = 0x0E57;
  12385. t['sfthyphen'] = 0x00AD;
  12386. t['shaarmenian'] = 0x0577;
  12387. t['shabengali'] = 0x09B6;
  12388. t['shacyrillic'] = 0x0448;
  12389. t['shaddaarabic'] = 0x0651;
  12390. t['shaddadammaarabic'] = 0xFC61;
  12391. t['shaddadammatanarabic'] = 0xFC5E;
  12392. t['shaddafathaarabic'] = 0xFC60;
  12393. t['shaddakasraarabic'] = 0xFC62;
  12394. t['shaddakasratanarabic'] = 0xFC5F;
  12395. t['shade'] = 0x2592;
  12396. t['shadedark'] = 0x2593;
  12397. t['shadelight'] = 0x2591;
  12398. t['shademedium'] = 0x2592;
  12399. t['shadeva'] = 0x0936;
  12400. t['shagujarati'] = 0x0AB6;
  12401. t['shagurmukhi'] = 0x0A36;
  12402. t['shalshelethebrew'] = 0x0593;
  12403. t['shbopomofo'] = 0x3115;
  12404. t['shchacyrillic'] = 0x0449;
  12405. t['sheenarabic'] = 0x0634;
  12406. t['sheenfinalarabic'] = 0xFEB6;
  12407. t['sheeninitialarabic'] = 0xFEB7;
  12408. t['sheenmedialarabic'] = 0xFEB8;
  12409. t['sheicoptic'] = 0x03E3;
  12410. t['sheqel'] = 0x20AA;
  12411. t['sheqelhebrew'] = 0x20AA;
  12412. t['sheva'] = 0x05B0;
  12413. t['sheva115'] = 0x05B0;
  12414. t['sheva15'] = 0x05B0;
  12415. t['sheva22'] = 0x05B0;
  12416. t['sheva2e'] = 0x05B0;
  12417. t['shevahebrew'] = 0x05B0;
  12418. t['shevanarrowhebrew'] = 0x05B0;
  12419. t['shevaquarterhebrew'] = 0x05B0;
  12420. t['shevawidehebrew'] = 0x05B0;
  12421. t['shhacyrillic'] = 0x04BB;
  12422. t['shimacoptic'] = 0x03ED;
  12423. t['shin'] = 0x05E9;
  12424. t['shindagesh'] = 0xFB49;
  12425. t['shindageshhebrew'] = 0xFB49;
  12426. t['shindageshshindot'] = 0xFB2C;
  12427. t['shindageshshindothebrew'] = 0xFB2C;
  12428. t['shindageshsindot'] = 0xFB2D;
  12429. t['shindageshsindothebrew'] = 0xFB2D;
  12430. t['shindothebrew'] = 0x05C1;
  12431. t['shinhebrew'] = 0x05E9;
  12432. t['shinshindot'] = 0xFB2A;
  12433. t['shinshindothebrew'] = 0xFB2A;
  12434. t['shinsindot'] = 0xFB2B;
  12435. t['shinsindothebrew'] = 0xFB2B;
  12436. t['shook'] = 0x0282;
  12437. t['sigma'] = 0x03C3;
  12438. t['sigma1'] = 0x03C2;
  12439. t['sigmafinal'] = 0x03C2;
  12440. t['sigmalunatesymbolgreek'] = 0x03F2;
  12441. t['sihiragana'] = 0x3057;
  12442. t['sikatakana'] = 0x30B7;
  12443. t['sikatakanahalfwidth'] = 0xFF7C;
  12444. t['siluqhebrew'] = 0x05BD;
  12445. t['siluqlefthebrew'] = 0x05BD;
  12446. t['similar'] = 0x223C;
  12447. t['sindothebrew'] = 0x05C2;
  12448. t['siosacirclekorean'] = 0x3274;
  12449. t['siosaparenkorean'] = 0x3214;
  12450. t['sioscieuckorean'] = 0x317E;
  12451. t['sioscirclekorean'] = 0x3266;
  12452. t['sioskiyeokkorean'] = 0x317A;
  12453. t['sioskorean'] = 0x3145;
  12454. t['siosnieunkorean'] = 0x317B;
  12455. t['siosparenkorean'] = 0x3206;
  12456. t['siospieupkorean'] = 0x317D;
  12457. t['siostikeutkorean'] = 0x317C;
  12458. t['six'] = 0x0036;
  12459. t['sixarabic'] = 0x0666;
  12460. t['sixbengali'] = 0x09EC;
  12461. t['sixcircle'] = 0x2465;
  12462. t['sixcircleinversesansserif'] = 0x278F;
  12463. t['sixdeva'] = 0x096C;
  12464. t['sixgujarati'] = 0x0AEC;
  12465. t['sixgurmukhi'] = 0x0A6C;
  12466. t['sixhackarabic'] = 0x0666;
  12467. t['sixhangzhou'] = 0x3026;
  12468. t['sixideographicparen'] = 0x3225;
  12469. t['sixinferior'] = 0x2086;
  12470. t['sixmonospace'] = 0xFF16;
  12471. t['sixoldstyle'] = 0xF736;
  12472. t['sixparen'] = 0x2479;
  12473. t['sixperiod'] = 0x248D;
  12474. t['sixpersian'] = 0x06F6;
  12475. t['sixroman'] = 0x2175;
  12476. t['sixsuperior'] = 0x2076;
  12477. t['sixteencircle'] = 0x246F;
  12478. t['sixteencurrencydenominatorbengali'] = 0x09F9;
  12479. t['sixteenparen'] = 0x2483;
  12480. t['sixteenperiod'] = 0x2497;
  12481. t['sixthai'] = 0x0E56;
  12482. t['slash'] = 0x002F;
  12483. t['slashmonospace'] = 0xFF0F;
  12484. t['slong'] = 0x017F;
  12485. t['slongdotaccent'] = 0x1E9B;
  12486. t['smileface'] = 0x263A;
  12487. t['smonospace'] = 0xFF53;
  12488. t['sofpasuqhebrew'] = 0x05C3;
  12489. t['softhyphen'] = 0x00AD;
  12490. t['softsigncyrillic'] = 0x044C;
  12491. t['sohiragana'] = 0x305D;
  12492. t['sokatakana'] = 0x30BD;
  12493. t['sokatakanahalfwidth'] = 0xFF7F;
  12494. t['soliduslongoverlaycmb'] = 0x0338;
  12495. t['solidusshortoverlaycmb'] = 0x0337;
  12496. t['sorusithai'] = 0x0E29;
  12497. t['sosalathai'] = 0x0E28;
  12498. t['sosothai'] = 0x0E0B;
  12499. t['sosuathai'] = 0x0E2A;
  12500. t['space'] = 0x0020;
  12501. t['spacehackarabic'] = 0x0020;
  12502. t['spade'] = 0x2660;
  12503. t['spadesuitblack'] = 0x2660;
  12504. t['spadesuitwhite'] = 0x2664;
  12505. t['sparen'] = 0x24AE;
  12506. t['squarebelowcmb'] = 0x033B;
  12507. t['squarecc'] = 0x33C4;
  12508. t['squarecm'] = 0x339D;
  12509. t['squarediagonalcrosshatchfill'] = 0x25A9;
  12510. t['squarehorizontalfill'] = 0x25A4;
  12511. t['squarekg'] = 0x338F;
  12512. t['squarekm'] = 0x339E;
  12513. t['squarekmcapital'] = 0x33CE;
  12514. t['squareln'] = 0x33D1;
  12515. t['squarelog'] = 0x33D2;
  12516. t['squaremg'] = 0x338E;
  12517. t['squaremil'] = 0x33D5;
  12518. t['squaremm'] = 0x339C;
  12519. t['squaremsquared'] = 0x33A1;
  12520. t['squareorthogonalcrosshatchfill'] = 0x25A6;
  12521. t['squareupperlefttolowerrightfill'] = 0x25A7;
  12522. t['squareupperrighttolowerleftfill'] = 0x25A8;
  12523. t['squareverticalfill'] = 0x25A5;
  12524. t['squarewhitewithsmallblack'] = 0x25A3;
  12525. t['srsquare'] = 0x33DB;
  12526. t['ssabengali'] = 0x09B7;
  12527. t['ssadeva'] = 0x0937;
  12528. t['ssagujarati'] = 0x0AB7;
  12529. t['ssangcieuckorean'] = 0x3149;
  12530. t['ssanghieuhkorean'] = 0x3185;
  12531. t['ssangieungkorean'] = 0x3180;
  12532. t['ssangkiyeokkorean'] = 0x3132;
  12533. t['ssangnieunkorean'] = 0x3165;
  12534. t['ssangpieupkorean'] = 0x3143;
  12535. t['ssangsioskorean'] = 0x3146;
  12536. t['ssangtikeutkorean'] = 0x3138;
  12537. t['ssuperior'] = 0xF6F2;
  12538. t['sterling'] = 0x00A3;
  12539. t['sterlingmonospace'] = 0xFFE1;
  12540. t['strokelongoverlaycmb'] = 0x0336;
  12541. t['strokeshortoverlaycmb'] = 0x0335;
  12542. t['subset'] = 0x2282;
  12543. t['subsetnotequal'] = 0x228A;
  12544. t['subsetorequal'] = 0x2286;
  12545. t['succeeds'] = 0x227B;
  12546. t['suchthat'] = 0x220B;
  12547. t['suhiragana'] = 0x3059;
  12548. t['sukatakana'] = 0x30B9;
  12549. t['sukatakanahalfwidth'] = 0xFF7D;
  12550. t['sukunarabic'] = 0x0652;
  12551. t['summation'] = 0x2211;
  12552. t['sun'] = 0x263C;
  12553. t['superset'] = 0x2283;
  12554. t['supersetnotequal'] = 0x228B;
  12555. t['supersetorequal'] = 0x2287;
  12556. t['svsquare'] = 0x33DC;
  12557. t['syouwaerasquare'] = 0x337C;
  12558. t['t'] = 0x0074;
  12559. t['tabengali'] = 0x09A4;
  12560. t['tackdown'] = 0x22A4;
  12561. t['tackleft'] = 0x22A3;
  12562. t['tadeva'] = 0x0924;
  12563. t['tagujarati'] = 0x0AA4;
  12564. t['tagurmukhi'] = 0x0A24;
  12565. t['taharabic'] = 0x0637;
  12566. t['tahfinalarabic'] = 0xFEC2;
  12567. t['tahinitialarabic'] = 0xFEC3;
  12568. t['tahiragana'] = 0x305F;
  12569. t['tahmedialarabic'] = 0xFEC4;
  12570. t['taisyouerasquare'] = 0x337D;
  12571. t['takatakana'] = 0x30BF;
  12572. t['takatakanahalfwidth'] = 0xFF80;
  12573. t['tatweelarabic'] = 0x0640;
  12574. t['tau'] = 0x03C4;
  12575. t['tav'] = 0x05EA;
  12576. t['tavdages'] = 0xFB4A;
  12577. t['tavdagesh'] = 0xFB4A;
  12578. t['tavdageshhebrew'] = 0xFB4A;
  12579. t['tavhebrew'] = 0x05EA;
  12580. t['tbar'] = 0x0167;
  12581. t['tbopomofo'] = 0x310A;
  12582. t['tcaron'] = 0x0165;
  12583. t['tccurl'] = 0x02A8;
  12584. t['tcedilla'] = 0x0163;
  12585. t['tcheharabic'] = 0x0686;
  12586. t['tchehfinalarabic'] = 0xFB7B;
  12587. t['tchehinitialarabic'] = 0xFB7C;
  12588. t['tchehmedialarabic'] = 0xFB7D;
  12589. t['tcircle'] = 0x24E3;
  12590. t['tcircumflexbelow'] = 0x1E71;
  12591. t['tcommaaccent'] = 0x0163;
  12592. t['tdieresis'] = 0x1E97;
  12593. t['tdotaccent'] = 0x1E6B;
  12594. t['tdotbelow'] = 0x1E6D;
  12595. t['tecyrillic'] = 0x0442;
  12596. t['tedescendercyrillic'] = 0x04AD;
  12597. t['teharabic'] = 0x062A;
  12598. t['tehfinalarabic'] = 0xFE96;
  12599. t['tehhahinitialarabic'] = 0xFCA2;
  12600. t['tehhahisolatedarabic'] = 0xFC0C;
  12601. t['tehinitialarabic'] = 0xFE97;
  12602. t['tehiragana'] = 0x3066;
  12603. t['tehjeeminitialarabic'] = 0xFCA1;
  12604. t['tehjeemisolatedarabic'] = 0xFC0B;
  12605. t['tehmarbutaarabic'] = 0x0629;
  12606. t['tehmarbutafinalarabic'] = 0xFE94;
  12607. t['tehmedialarabic'] = 0xFE98;
  12608. t['tehmeeminitialarabic'] = 0xFCA4;
  12609. t['tehmeemisolatedarabic'] = 0xFC0E;
  12610. t['tehnoonfinalarabic'] = 0xFC73;
  12611. t['tekatakana'] = 0x30C6;
  12612. t['tekatakanahalfwidth'] = 0xFF83;
  12613. t['telephone'] = 0x2121;
  12614. t['telephoneblack'] = 0x260E;
  12615. t['telishagedolahebrew'] = 0x05A0;
  12616. t['telishaqetanahebrew'] = 0x05A9;
  12617. t['tencircle'] = 0x2469;
  12618. t['tenideographicparen'] = 0x3229;
  12619. t['tenparen'] = 0x247D;
  12620. t['tenperiod'] = 0x2491;
  12621. t['tenroman'] = 0x2179;
  12622. t['tesh'] = 0x02A7;
  12623. t['tet'] = 0x05D8;
  12624. t['tetdagesh'] = 0xFB38;
  12625. t['tetdageshhebrew'] = 0xFB38;
  12626. t['tethebrew'] = 0x05D8;
  12627. t['tetsecyrillic'] = 0x04B5;
  12628. t['tevirhebrew'] = 0x059B;
  12629. t['tevirlefthebrew'] = 0x059B;
  12630. t['thabengali'] = 0x09A5;
  12631. t['thadeva'] = 0x0925;
  12632. t['thagujarati'] = 0x0AA5;
  12633. t['thagurmukhi'] = 0x0A25;
  12634. t['thalarabic'] = 0x0630;
  12635. t['thalfinalarabic'] = 0xFEAC;
  12636. t['thanthakhatlowleftthai'] = 0xF898;
  12637. t['thanthakhatlowrightthai'] = 0xF897;
  12638. t['thanthakhatthai'] = 0x0E4C;
  12639. t['thanthakhatupperleftthai'] = 0xF896;
  12640. t['theharabic'] = 0x062B;
  12641. t['thehfinalarabic'] = 0xFE9A;
  12642. t['thehinitialarabic'] = 0xFE9B;
  12643. t['thehmedialarabic'] = 0xFE9C;
  12644. t['thereexists'] = 0x2203;
  12645. t['therefore'] = 0x2234;
  12646. t['theta'] = 0x03B8;
  12647. t['theta1'] = 0x03D1;
  12648. t['thetasymbolgreek'] = 0x03D1;
  12649. t['thieuthacirclekorean'] = 0x3279;
  12650. t['thieuthaparenkorean'] = 0x3219;
  12651. t['thieuthcirclekorean'] = 0x326B;
  12652. t['thieuthkorean'] = 0x314C;
  12653. t['thieuthparenkorean'] = 0x320B;
  12654. t['thirteencircle'] = 0x246C;
  12655. t['thirteenparen'] = 0x2480;
  12656. t['thirteenperiod'] = 0x2494;
  12657. t['thonangmonthothai'] = 0x0E11;
  12658. t['thook'] = 0x01AD;
  12659. t['thophuthaothai'] = 0x0E12;
  12660. t['thorn'] = 0x00FE;
  12661. t['thothahanthai'] = 0x0E17;
  12662. t['thothanthai'] = 0x0E10;
  12663. t['thothongthai'] = 0x0E18;
  12664. t['thothungthai'] = 0x0E16;
  12665. t['thousandcyrillic'] = 0x0482;
  12666. t['thousandsseparatorarabic'] = 0x066C;
  12667. t['thousandsseparatorpersian'] = 0x066C;
  12668. t['three'] = 0x0033;
  12669. t['threearabic'] = 0x0663;
  12670. t['threebengali'] = 0x09E9;
  12671. t['threecircle'] = 0x2462;
  12672. t['threecircleinversesansserif'] = 0x278C;
  12673. t['threedeva'] = 0x0969;
  12674. t['threeeighths'] = 0x215C;
  12675. t['threegujarati'] = 0x0AE9;
  12676. t['threegurmukhi'] = 0x0A69;
  12677. t['threehackarabic'] = 0x0663;
  12678. t['threehangzhou'] = 0x3023;
  12679. t['threeideographicparen'] = 0x3222;
  12680. t['threeinferior'] = 0x2083;
  12681. t['threemonospace'] = 0xFF13;
  12682. t['threenumeratorbengali'] = 0x09F6;
  12683. t['threeoldstyle'] = 0xF733;
  12684. t['threeparen'] = 0x2476;
  12685. t['threeperiod'] = 0x248A;
  12686. t['threepersian'] = 0x06F3;
  12687. t['threequarters'] = 0x00BE;
  12688. t['threequartersemdash'] = 0xF6DE;
  12689. t['threeroman'] = 0x2172;
  12690. t['threesuperior'] = 0x00B3;
  12691. t['threethai'] = 0x0E53;
  12692. t['thzsquare'] = 0x3394;
  12693. t['tihiragana'] = 0x3061;
  12694. t['tikatakana'] = 0x30C1;
  12695. t['tikatakanahalfwidth'] = 0xFF81;
  12696. t['tikeutacirclekorean'] = 0x3270;
  12697. t['tikeutaparenkorean'] = 0x3210;
  12698. t['tikeutcirclekorean'] = 0x3262;
  12699. t['tikeutkorean'] = 0x3137;
  12700. t['tikeutparenkorean'] = 0x3202;
  12701. t['tilde'] = 0x02DC;
  12702. t['tildebelowcmb'] = 0x0330;
  12703. t['tildecmb'] = 0x0303;
  12704. t['tildecomb'] = 0x0303;
  12705. t['tildedoublecmb'] = 0x0360;
  12706. t['tildeoperator'] = 0x223C;
  12707. t['tildeoverlaycmb'] = 0x0334;
  12708. t['tildeverticalcmb'] = 0x033E;
  12709. t['timescircle'] = 0x2297;
  12710. t['tipehahebrew'] = 0x0596;
  12711. t['tipehalefthebrew'] = 0x0596;
  12712. t['tippigurmukhi'] = 0x0A70;
  12713. t['titlocyrilliccmb'] = 0x0483;
  12714. t['tiwnarmenian'] = 0x057F;
  12715. t['tlinebelow'] = 0x1E6F;
  12716. t['tmonospace'] = 0xFF54;
  12717. t['toarmenian'] = 0x0569;
  12718. t['tohiragana'] = 0x3068;
  12719. t['tokatakana'] = 0x30C8;
  12720. t['tokatakanahalfwidth'] = 0xFF84;
  12721. t['tonebarextrahighmod'] = 0x02E5;
  12722. t['tonebarextralowmod'] = 0x02E9;
  12723. t['tonebarhighmod'] = 0x02E6;
  12724. t['tonebarlowmod'] = 0x02E8;
  12725. t['tonebarmidmod'] = 0x02E7;
  12726. t['tonefive'] = 0x01BD;
  12727. t['tonesix'] = 0x0185;
  12728. t['tonetwo'] = 0x01A8;
  12729. t['tonos'] = 0x0384;
  12730. t['tonsquare'] = 0x3327;
  12731. t['topatakthai'] = 0x0E0F;
  12732. t['tortoiseshellbracketleft'] = 0x3014;
  12733. t['tortoiseshellbracketleftsmall'] = 0xFE5D;
  12734. t['tortoiseshellbracketleftvertical'] = 0xFE39;
  12735. t['tortoiseshellbracketright'] = 0x3015;
  12736. t['tortoiseshellbracketrightsmall'] = 0xFE5E;
  12737. t['tortoiseshellbracketrightvertical'] = 0xFE3A;
  12738. t['totaothai'] = 0x0E15;
  12739. t['tpalatalhook'] = 0x01AB;
  12740. t['tparen'] = 0x24AF;
  12741. t['trademark'] = 0x2122;
  12742. t['trademarksans'] = 0xF8EA;
  12743. t['trademarkserif'] = 0xF6DB;
  12744. t['tretroflexhook'] = 0x0288;
  12745. t['triagdn'] = 0x25BC;
  12746. t['triaglf'] = 0x25C4;
  12747. t['triagrt'] = 0x25BA;
  12748. t['triagup'] = 0x25B2;
  12749. t['ts'] = 0x02A6;
  12750. t['tsadi'] = 0x05E6;
  12751. t['tsadidagesh'] = 0xFB46;
  12752. t['tsadidageshhebrew'] = 0xFB46;
  12753. t['tsadihebrew'] = 0x05E6;
  12754. t['tsecyrillic'] = 0x0446;
  12755. t['tsere'] = 0x05B5;
  12756. t['tsere12'] = 0x05B5;
  12757. t['tsere1e'] = 0x05B5;
  12758. t['tsere2b'] = 0x05B5;
  12759. t['tserehebrew'] = 0x05B5;
  12760. t['tserenarrowhebrew'] = 0x05B5;
  12761. t['tserequarterhebrew'] = 0x05B5;
  12762. t['tserewidehebrew'] = 0x05B5;
  12763. t['tshecyrillic'] = 0x045B;
  12764. t['tsuperior'] = 0xF6F3;
  12765. t['ttabengali'] = 0x099F;
  12766. t['ttadeva'] = 0x091F;
  12767. t['ttagujarati'] = 0x0A9F;
  12768. t['ttagurmukhi'] = 0x0A1F;
  12769. t['tteharabic'] = 0x0679;
  12770. t['ttehfinalarabic'] = 0xFB67;
  12771. t['ttehinitialarabic'] = 0xFB68;
  12772. t['ttehmedialarabic'] = 0xFB69;
  12773. t['tthabengali'] = 0x09A0;
  12774. t['tthadeva'] = 0x0920;
  12775. t['tthagujarati'] = 0x0AA0;
  12776. t['tthagurmukhi'] = 0x0A20;
  12777. t['tturned'] = 0x0287;
  12778. t['tuhiragana'] = 0x3064;
  12779. t['tukatakana'] = 0x30C4;
  12780. t['tukatakanahalfwidth'] = 0xFF82;
  12781. t['tusmallhiragana'] = 0x3063;
  12782. t['tusmallkatakana'] = 0x30C3;
  12783. t['tusmallkatakanahalfwidth'] = 0xFF6F;
  12784. t['twelvecircle'] = 0x246B;
  12785. t['twelveparen'] = 0x247F;
  12786. t['twelveperiod'] = 0x2493;
  12787. t['twelveroman'] = 0x217B;
  12788. t['twentycircle'] = 0x2473;
  12789. t['twentyhangzhou'] = 0x5344;
  12790. t['twentyparen'] = 0x2487;
  12791. t['twentyperiod'] = 0x249B;
  12792. t['two'] = 0x0032;
  12793. t['twoarabic'] = 0x0662;
  12794. t['twobengali'] = 0x09E8;
  12795. t['twocircle'] = 0x2461;
  12796. t['twocircleinversesansserif'] = 0x278B;
  12797. t['twodeva'] = 0x0968;
  12798. t['twodotenleader'] = 0x2025;
  12799. t['twodotleader'] = 0x2025;
  12800. t['twodotleadervertical'] = 0xFE30;
  12801. t['twogujarati'] = 0x0AE8;
  12802. t['twogurmukhi'] = 0x0A68;
  12803. t['twohackarabic'] = 0x0662;
  12804. t['twohangzhou'] = 0x3022;
  12805. t['twoideographicparen'] = 0x3221;
  12806. t['twoinferior'] = 0x2082;
  12807. t['twomonospace'] = 0xFF12;
  12808. t['twonumeratorbengali'] = 0x09F5;
  12809. t['twooldstyle'] = 0xF732;
  12810. t['twoparen'] = 0x2475;
  12811. t['twoperiod'] = 0x2489;
  12812. t['twopersian'] = 0x06F2;
  12813. t['tworoman'] = 0x2171;
  12814. t['twostroke'] = 0x01BB;
  12815. t['twosuperior'] = 0x00B2;
  12816. t['twothai'] = 0x0E52;
  12817. t['twothirds'] = 0x2154;
  12818. t['u'] = 0x0075;
  12819. t['uacute'] = 0x00FA;
  12820. t['ubar'] = 0x0289;
  12821. t['ubengali'] = 0x0989;
  12822. t['ubopomofo'] = 0x3128;
  12823. t['ubreve'] = 0x016D;
  12824. t['ucaron'] = 0x01D4;
  12825. t['ucircle'] = 0x24E4;
  12826. t['ucircumflex'] = 0x00FB;
  12827. t['ucircumflexbelow'] = 0x1E77;
  12828. t['ucyrillic'] = 0x0443;
  12829. t['udattadeva'] = 0x0951;
  12830. t['udblacute'] = 0x0171;
  12831. t['udblgrave'] = 0x0215;
  12832. t['udeva'] = 0x0909;
  12833. t['udieresis'] = 0x00FC;
  12834. t['udieresisacute'] = 0x01D8;
  12835. t['udieresisbelow'] = 0x1E73;
  12836. t['udieresiscaron'] = 0x01DA;
  12837. t['udieresiscyrillic'] = 0x04F1;
  12838. t['udieresisgrave'] = 0x01DC;
  12839. t['udieresismacron'] = 0x01D6;
  12840. t['udotbelow'] = 0x1EE5;
  12841. t['ugrave'] = 0x00F9;
  12842. t['ugujarati'] = 0x0A89;
  12843. t['ugurmukhi'] = 0x0A09;
  12844. t['uhiragana'] = 0x3046;
  12845. t['uhookabove'] = 0x1EE7;
  12846. t['uhorn'] = 0x01B0;
  12847. t['uhornacute'] = 0x1EE9;
  12848. t['uhorndotbelow'] = 0x1EF1;
  12849. t['uhorngrave'] = 0x1EEB;
  12850. t['uhornhookabove'] = 0x1EED;
  12851. t['uhorntilde'] = 0x1EEF;
  12852. t['uhungarumlaut'] = 0x0171;
  12853. t['uhungarumlautcyrillic'] = 0x04F3;
  12854. t['uinvertedbreve'] = 0x0217;
  12855. t['ukatakana'] = 0x30A6;
  12856. t['ukatakanahalfwidth'] = 0xFF73;
  12857. t['ukcyrillic'] = 0x0479;
  12858. t['ukorean'] = 0x315C;
  12859. t['umacron'] = 0x016B;
  12860. t['umacroncyrillic'] = 0x04EF;
  12861. t['umacrondieresis'] = 0x1E7B;
  12862. t['umatragurmukhi'] = 0x0A41;
  12863. t['umonospace'] = 0xFF55;
  12864. t['underscore'] = 0x005F;
  12865. t['underscoredbl'] = 0x2017;
  12866. t['underscoremonospace'] = 0xFF3F;
  12867. t['underscorevertical'] = 0xFE33;
  12868. t['underscorewavy'] = 0xFE4F;
  12869. t['union'] = 0x222A;
  12870. t['universal'] = 0x2200;
  12871. t['uogonek'] = 0x0173;
  12872. t['uparen'] = 0x24B0;
  12873. t['upblock'] = 0x2580;
  12874. t['upperdothebrew'] = 0x05C4;
  12875. t['upsilon'] = 0x03C5;
  12876. t['upsilondieresis'] = 0x03CB;
  12877. t['upsilondieresistonos'] = 0x03B0;
  12878. t['upsilonlatin'] = 0x028A;
  12879. t['upsilontonos'] = 0x03CD;
  12880. t['uptackbelowcmb'] = 0x031D;
  12881. t['uptackmod'] = 0x02D4;
  12882. t['uragurmukhi'] = 0x0A73;
  12883. t['uring'] = 0x016F;
  12884. t['ushortcyrillic'] = 0x045E;
  12885. t['usmallhiragana'] = 0x3045;
  12886. t['usmallkatakana'] = 0x30A5;
  12887. t['usmallkatakanahalfwidth'] = 0xFF69;
  12888. t['ustraightcyrillic'] = 0x04AF;
  12889. t['ustraightstrokecyrillic'] = 0x04B1;
  12890. t['utilde'] = 0x0169;
  12891. t['utildeacute'] = 0x1E79;
  12892. t['utildebelow'] = 0x1E75;
  12893. t['uubengali'] = 0x098A;
  12894. t['uudeva'] = 0x090A;
  12895. t['uugujarati'] = 0x0A8A;
  12896. t['uugurmukhi'] = 0x0A0A;
  12897. t['uumatragurmukhi'] = 0x0A42;
  12898. t['uuvowelsignbengali'] = 0x09C2;
  12899. t['uuvowelsigndeva'] = 0x0942;
  12900. t['uuvowelsigngujarati'] = 0x0AC2;
  12901. t['uvowelsignbengali'] = 0x09C1;
  12902. t['uvowelsigndeva'] = 0x0941;
  12903. t['uvowelsigngujarati'] = 0x0AC1;
  12904. t['v'] = 0x0076;
  12905. t['vadeva'] = 0x0935;
  12906. t['vagujarati'] = 0x0AB5;
  12907. t['vagurmukhi'] = 0x0A35;
  12908. t['vakatakana'] = 0x30F7;
  12909. t['vav'] = 0x05D5;
  12910. t['vavdagesh'] = 0xFB35;
  12911. t['vavdagesh65'] = 0xFB35;
  12912. t['vavdageshhebrew'] = 0xFB35;
  12913. t['vavhebrew'] = 0x05D5;
  12914. t['vavholam'] = 0xFB4B;
  12915. t['vavholamhebrew'] = 0xFB4B;
  12916. t['vavvavhebrew'] = 0x05F0;
  12917. t['vavyodhebrew'] = 0x05F1;
  12918. t['vcircle'] = 0x24E5;
  12919. t['vdotbelow'] = 0x1E7F;
  12920. t['vecyrillic'] = 0x0432;
  12921. t['veharabic'] = 0x06A4;
  12922. t['vehfinalarabic'] = 0xFB6B;
  12923. t['vehinitialarabic'] = 0xFB6C;
  12924. t['vehmedialarabic'] = 0xFB6D;
  12925. t['vekatakana'] = 0x30F9;
  12926. t['venus'] = 0x2640;
  12927. t['verticalbar'] = 0x007C;
  12928. t['verticallineabovecmb'] = 0x030D;
  12929. t['verticallinebelowcmb'] = 0x0329;
  12930. t['verticallinelowmod'] = 0x02CC;
  12931. t['verticallinemod'] = 0x02C8;
  12932. t['vewarmenian'] = 0x057E;
  12933. t['vhook'] = 0x028B;
  12934. t['vikatakana'] = 0x30F8;
  12935. t['viramabengali'] = 0x09CD;
  12936. t['viramadeva'] = 0x094D;
  12937. t['viramagujarati'] = 0x0ACD;
  12938. t['visargabengali'] = 0x0983;
  12939. t['visargadeva'] = 0x0903;
  12940. t['visargagujarati'] = 0x0A83;
  12941. t['vmonospace'] = 0xFF56;
  12942. t['voarmenian'] = 0x0578;
  12943. t['voicediterationhiragana'] = 0x309E;
  12944. t['voicediterationkatakana'] = 0x30FE;
  12945. t['voicedmarkkana'] = 0x309B;
  12946. t['voicedmarkkanahalfwidth'] = 0xFF9E;
  12947. t['vokatakana'] = 0x30FA;
  12948. t['vparen'] = 0x24B1;
  12949. t['vtilde'] = 0x1E7D;
  12950. t['vturned'] = 0x028C;
  12951. t['vuhiragana'] = 0x3094;
  12952. t['vukatakana'] = 0x30F4;
  12953. t['w'] = 0x0077;
  12954. t['wacute'] = 0x1E83;
  12955. t['waekorean'] = 0x3159;
  12956. t['wahiragana'] = 0x308F;
  12957. t['wakatakana'] = 0x30EF;
  12958. t['wakatakanahalfwidth'] = 0xFF9C;
  12959. t['wakorean'] = 0x3158;
  12960. t['wasmallhiragana'] = 0x308E;
  12961. t['wasmallkatakana'] = 0x30EE;
  12962. t['wattosquare'] = 0x3357;
  12963. t['wavedash'] = 0x301C;
  12964. t['wavyunderscorevertical'] = 0xFE34;
  12965. t['wawarabic'] = 0x0648;
  12966. t['wawfinalarabic'] = 0xFEEE;
  12967. t['wawhamzaabovearabic'] = 0x0624;
  12968. t['wawhamzaabovefinalarabic'] = 0xFE86;
  12969. t['wbsquare'] = 0x33DD;
  12970. t['wcircle'] = 0x24E6;
  12971. t['wcircumflex'] = 0x0175;
  12972. t['wdieresis'] = 0x1E85;
  12973. t['wdotaccent'] = 0x1E87;
  12974. t['wdotbelow'] = 0x1E89;
  12975. t['wehiragana'] = 0x3091;
  12976. t['weierstrass'] = 0x2118;
  12977. t['wekatakana'] = 0x30F1;
  12978. t['wekorean'] = 0x315E;
  12979. t['weokorean'] = 0x315D;
  12980. t['wgrave'] = 0x1E81;
  12981. t['whitebullet'] = 0x25E6;
  12982. t['whitecircle'] = 0x25CB;
  12983. t['whitecircleinverse'] = 0x25D9;
  12984. t['whitecornerbracketleft'] = 0x300E;
  12985. t['whitecornerbracketleftvertical'] = 0xFE43;
  12986. t['whitecornerbracketright'] = 0x300F;
  12987. t['whitecornerbracketrightvertical'] = 0xFE44;
  12988. t['whitediamond'] = 0x25C7;
  12989. t['whitediamondcontainingblacksmalldiamond'] = 0x25C8;
  12990. t['whitedownpointingsmalltriangle'] = 0x25BF;
  12991. t['whitedownpointingtriangle'] = 0x25BD;
  12992. t['whiteleftpointingsmalltriangle'] = 0x25C3;
  12993. t['whiteleftpointingtriangle'] = 0x25C1;
  12994. t['whitelenticularbracketleft'] = 0x3016;
  12995. t['whitelenticularbracketright'] = 0x3017;
  12996. t['whiterightpointingsmalltriangle'] = 0x25B9;
  12997. t['whiterightpointingtriangle'] = 0x25B7;
  12998. t['whitesmallsquare'] = 0x25AB;
  12999. t['whitesmilingface'] = 0x263A;
  13000. t['whitesquare'] = 0x25A1;
  13001. t['whitestar'] = 0x2606;
  13002. t['whitetelephone'] = 0x260F;
  13003. t['whitetortoiseshellbracketleft'] = 0x3018;
  13004. t['whitetortoiseshellbracketright'] = 0x3019;
  13005. t['whiteuppointingsmalltriangle'] = 0x25B5;
  13006. t['whiteuppointingtriangle'] = 0x25B3;
  13007. t['wihiragana'] = 0x3090;
  13008. t['wikatakana'] = 0x30F0;
  13009. t['wikorean'] = 0x315F;
  13010. t['wmonospace'] = 0xFF57;
  13011. t['wohiragana'] = 0x3092;
  13012. t['wokatakana'] = 0x30F2;
  13013. t['wokatakanahalfwidth'] = 0xFF66;
  13014. t['won'] = 0x20A9;
  13015. t['wonmonospace'] = 0xFFE6;
  13016. t['wowaenthai'] = 0x0E27;
  13017. t['wparen'] = 0x24B2;
  13018. t['wring'] = 0x1E98;
  13019. t['wsuperior'] = 0x02B7;
  13020. t['wturned'] = 0x028D;
  13021. t['wynn'] = 0x01BF;
  13022. t['x'] = 0x0078;
  13023. t['xabovecmb'] = 0x033D;
  13024. t['xbopomofo'] = 0x3112;
  13025. t['xcircle'] = 0x24E7;
  13026. t['xdieresis'] = 0x1E8D;
  13027. t['xdotaccent'] = 0x1E8B;
  13028. t['xeharmenian'] = 0x056D;
  13029. t['xi'] = 0x03BE;
  13030. t['xmonospace'] = 0xFF58;
  13031. t['xparen'] = 0x24B3;
  13032. t['xsuperior'] = 0x02E3;
  13033. t['y'] = 0x0079;
  13034. t['yaadosquare'] = 0x334E;
  13035. t['yabengali'] = 0x09AF;
  13036. t['yacute'] = 0x00FD;
  13037. t['yadeva'] = 0x092F;
  13038. t['yaekorean'] = 0x3152;
  13039. t['yagujarati'] = 0x0AAF;
  13040. t['yagurmukhi'] = 0x0A2F;
  13041. t['yahiragana'] = 0x3084;
  13042. t['yakatakana'] = 0x30E4;
  13043. t['yakatakanahalfwidth'] = 0xFF94;
  13044. t['yakorean'] = 0x3151;
  13045. t['yamakkanthai'] = 0x0E4E;
  13046. t['yasmallhiragana'] = 0x3083;
  13047. t['yasmallkatakana'] = 0x30E3;
  13048. t['yasmallkatakanahalfwidth'] = 0xFF6C;
  13049. t['yatcyrillic'] = 0x0463;
  13050. t['ycircle'] = 0x24E8;
  13051. t['ycircumflex'] = 0x0177;
  13052. t['ydieresis'] = 0x00FF;
  13053. t['ydotaccent'] = 0x1E8F;
  13054. t['ydotbelow'] = 0x1EF5;
  13055. t['yeharabic'] = 0x064A;
  13056. t['yehbarreearabic'] = 0x06D2;
  13057. t['yehbarreefinalarabic'] = 0xFBAF;
  13058. t['yehfinalarabic'] = 0xFEF2;
  13059. t['yehhamzaabovearabic'] = 0x0626;
  13060. t['yehhamzaabovefinalarabic'] = 0xFE8A;
  13061. t['yehhamzaaboveinitialarabic'] = 0xFE8B;
  13062. t['yehhamzaabovemedialarabic'] = 0xFE8C;
  13063. t['yehinitialarabic'] = 0xFEF3;
  13064. t['yehmedialarabic'] = 0xFEF4;
  13065. t['yehmeeminitialarabic'] = 0xFCDD;
  13066. t['yehmeemisolatedarabic'] = 0xFC58;
  13067. t['yehnoonfinalarabic'] = 0xFC94;
  13068. t['yehthreedotsbelowarabic'] = 0x06D1;
  13069. t['yekorean'] = 0x3156;
  13070. t['yen'] = 0x00A5;
  13071. t['yenmonospace'] = 0xFFE5;
  13072. t['yeokorean'] = 0x3155;
  13073. t['yeorinhieuhkorean'] = 0x3186;
  13074. t['yerahbenyomohebrew'] = 0x05AA;
  13075. t['yerahbenyomolefthebrew'] = 0x05AA;
  13076. t['yericyrillic'] = 0x044B;
  13077. t['yerudieresiscyrillic'] = 0x04F9;
  13078. t['yesieungkorean'] = 0x3181;
  13079. t['yesieungpansioskorean'] = 0x3183;
  13080. t['yesieungsioskorean'] = 0x3182;
  13081. t['yetivhebrew'] = 0x059A;
  13082. t['ygrave'] = 0x1EF3;
  13083. t['yhook'] = 0x01B4;
  13084. t['yhookabove'] = 0x1EF7;
  13085. t['yiarmenian'] = 0x0575;
  13086. t['yicyrillic'] = 0x0457;
  13087. t['yikorean'] = 0x3162;
  13088. t['yinyang'] = 0x262F;
  13089. t['yiwnarmenian'] = 0x0582;
  13090. t['ymonospace'] = 0xFF59;
  13091. t['yod'] = 0x05D9;
  13092. t['yoddagesh'] = 0xFB39;
  13093. t['yoddageshhebrew'] = 0xFB39;
  13094. t['yodhebrew'] = 0x05D9;
  13095. t['yodyodhebrew'] = 0x05F2;
  13096. t['yodyodpatahhebrew'] = 0xFB1F;
  13097. t['yohiragana'] = 0x3088;
  13098. t['yoikorean'] = 0x3189;
  13099. t['yokatakana'] = 0x30E8;
  13100. t['yokatakanahalfwidth'] = 0xFF96;
  13101. t['yokorean'] = 0x315B;
  13102. t['yosmallhiragana'] = 0x3087;
  13103. t['yosmallkatakana'] = 0x30E7;
  13104. t['yosmallkatakanahalfwidth'] = 0xFF6E;
  13105. t['yotgreek'] = 0x03F3;
  13106. t['yoyaekorean'] = 0x3188;
  13107. t['yoyakorean'] = 0x3187;
  13108. t['yoyakthai'] = 0x0E22;
  13109. t['yoyingthai'] = 0x0E0D;
  13110. t['yparen'] = 0x24B4;
  13111. t['ypogegrammeni'] = 0x037A;
  13112. t['ypogegrammenigreekcmb'] = 0x0345;
  13113. t['yr'] = 0x01A6;
  13114. t['yring'] = 0x1E99;
  13115. t['ysuperior'] = 0x02B8;
  13116. t['ytilde'] = 0x1EF9;
  13117. t['yturned'] = 0x028E;
  13118. t['yuhiragana'] = 0x3086;
  13119. t['yuikorean'] = 0x318C;
  13120. t['yukatakana'] = 0x30E6;
  13121. t['yukatakanahalfwidth'] = 0xFF95;
  13122. t['yukorean'] = 0x3160;
  13123. t['yusbigcyrillic'] = 0x046B;
  13124. t['yusbigiotifiedcyrillic'] = 0x046D;
  13125. t['yuslittlecyrillic'] = 0x0467;
  13126. t['yuslittleiotifiedcyrillic'] = 0x0469;
  13127. t['yusmallhiragana'] = 0x3085;
  13128. t['yusmallkatakana'] = 0x30E5;
  13129. t['yusmallkatakanahalfwidth'] = 0xFF6D;
  13130. t['yuyekorean'] = 0x318B;
  13131. t['yuyeokorean'] = 0x318A;
  13132. t['yyabengali'] = 0x09DF;
  13133. t['yyadeva'] = 0x095F;
  13134. t['z'] = 0x007A;
  13135. t['zaarmenian'] = 0x0566;
  13136. t['zacute'] = 0x017A;
  13137. t['zadeva'] = 0x095B;
  13138. t['zagurmukhi'] = 0x0A5B;
  13139. t['zaharabic'] = 0x0638;
  13140. t['zahfinalarabic'] = 0xFEC6;
  13141. t['zahinitialarabic'] = 0xFEC7;
  13142. t['zahiragana'] = 0x3056;
  13143. t['zahmedialarabic'] = 0xFEC8;
  13144. t['zainarabic'] = 0x0632;
  13145. t['zainfinalarabic'] = 0xFEB0;
  13146. t['zakatakana'] = 0x30B6;
  13147. t['zaqefgadolhebrew'] = 0x0595;
  13148. t['zaqefqatanhebrew'] = 0x0594;
  13149. t['zarqahebrew'] = 0x0598;
  13150. t['zayin'] = 0x05D6;
  13151. t['zayindagesh'] = 0xFB36;
  13152. t['zayindageshhebrew'] = 0xFB36;
  13153. t['zayinhebrew'] = 0x05D6;
  13154. t['zbopomofo'] = 0x3117;
  13155. t['zcaron'] = 0x017E;
  13156. t['zcircle'] = 0x24E9;
  13157. t['zcircumflex'] = 0x1E91;
  13158. t['zcurl'] = 0x0291;
  13159. t['zdot'] = 0x017C;
  13160. t['zdotaccent'] = 0x017C;
  13161. t['zdotbelow'] = 0x1E93;
  13162. t['zecyrillic'] = 0x0437;
  13163. t['zedescendercyrillic'] = 0x0499;
  13164. t['zedieresiscyrillic'] = 0x04DF;
  13165. t['zehiragana'] = 0x305C;
  13166. t['zekatakana'] = 0x30BC;
  13167. t['zero'] = 0x0030;
  13168. t['zeroarabic'] = 0x0660;
  13169. t['zerobengali'] = 0x09E6;
  13170. t['zerodeva'] = 0x0966;
  13171. t['zerogujarati'] = 0x0AE6;
  13172. t['zerogurmukhi'] = 0x0A66;
  13173. t['zerohackarabic'] = 0x0660;
  13174. t['zeroinferior'] = 0x2080;
  13175. t['zeromonospace'] = 0xFF10;
  13176. t['zerooldstyle'] = 0xF730;
  13177. t['zeropersian'] = 0x06F0;
  13178. t['zerosuperior'] = 0x2070;
  13179. t['zerothai'] = 0x0E50;
  13180. t['zerowidthjoiner'] = 0xFEFF;
  13181. t['zerowidthnonjoiner'] = 0x200C;
  13182. t['zerowidthspace'] = 0x200B;
  13183. t['zeta'] = 0x03B6;
  13184. t['zhbopomofo'] = 0x3113;
  13185. t['zhearmenian'] = 0x056A;
  13186. t['zhebrevecyrillic'] = 0x04C2;
  13187. t['zhecyrillic'] = 0x0436;
  13188. t['zhedescendercyrillic'] = 0x0497;
  13189. t['zhedieresiscyrillic'] = 0x04DD;
  13190. t['zihiragana'] = 0x3058;
  13191. t['zikatakana'] = 0x30B8;
  13192. t['zinorhebrew'] = 0x05AE;
  13193. t['zlinebelow'] = 0x1E95;
  13194. t['zmonospace'] = 0xFF5A;
  13195. t['zohiragana'] = 0x305E;
  13196. t['zokatakana'] = 0x30BE;
  13197. t['zparen'] = 0x24B5;
  13198. t['zretroflexhook'] = 0x0290;
  13199. t['zstroke'] = 0x01B6;
  13200. t['zuhiragana'] = 0x305A;
  13201. t['zukatakana'] = 0x30BA;
  13202. t['.notdef'] = 0x0000;
  13203. });
  13204. var getDingbatsGlyphsUnicode = getLookupTableFactory(function (t) {
  13205. t['space'] = 0x0020;
  13206. t['a1'] = 0x2701;
  13207. t['a2'] = 0x2702;
  13208. t['a202'] = 0x2703;
  13209. t['a3'] = 0x2704;
  13210. t['a4'] = 0x260E;
  13211. t['a5'] = 0x2706;
  13212. t['a119'] = 0x2707;
  13213. t['a118'] = 0x2708;
  13214. t['a117'] = 0x2709;
  13215. t['a11'] = 0x261B;
  13216. t['a12'] = 0x261E;
  13217. t['a13'] = 0x270C;
  13218. t['a14'] = 0x270D;
  13219. t['a15'] = 0x270E;
  13220. t['a16'] = 0x270F;
  13221. t['a105'] = 0x2710;
  13222. t['a17'] = 0x2711;
  13223. t['a18'] = 0x2712;
  13224. t['a19'] = 0x2713;
  13225. t['a20'] = 0x2714;
  13226. t['a21'] = 0x2715;
  13227. t['a22'] = 0x2716;
  13228. t['a23'] = 0x2717;
  13229. t['a24'] = 0x2718;
  13230. t['a25'] = 0x2719;
  13231. t['a26'] = 0x271A;
  13232. t['a27'] = 0x271B;
  13233. t['a28'] = 0x271C;
  13234. t['a6'] = 0x271D;
  13235. t['a7'] = 0x271E;
  13236. t['a8'] = 0x271F;
  13237. t['a9'] = 0x2720;
  13238. t['a10'] = 0x2721;
  13239. t['a29'] = 0x2722;
  13240. t['a30'] = 0x2723;
  13241. t['a31'] = 0x2724;
  13242. t['a32'] = 0x2725;
  13243. t['a33'] = 0x2726;
  13244. t['a34'] = 0x2727;
  13245. t['a35'] = 0x2605;
  13246. t['a36'] = 0x2729;
  13247. t['a37'] = 0x272A;
  13248. t['a38'] = 0x272B;
  13249. t['a39'] = 0x272C;
  13250. t['a40'] = 0x272D;
  13251. t['a41'] = 0x272E;
  13252. t['a42'] = 0x272F;
  13253. t['a43'] = 0x2730;
  13254. t['a44'] = 0x2731;
  13255. t['a45'] = 0x2732;
  13256. t['a46'] = 0x2733;
  13257. t['a47'] = 0x2734;
  13258. t['a48'] = 0x2735;
  13259. t['a49'] = 0x2736;
  13260. t['a50'] = 0x2737;
  13261. t['a51'] = 0x2738;
  13262. t['a52'] = 0x2739;
  13263. t['a53'] = 0x273A;
  13264. t['a54'] = 0x273B;
  13265. t['a55'] = 0x273C;
  13266. t['a56'] = 0x273D;
  13267. t['a57'] = 0x273E;
  13268. t['a58'] = 0x273F;
  13269. t['a59'] = 0x2740;
  13270. t['a60'] = 0x2741;
  13271. t['a61'] = 0x2742;
  13272. t['a62'] = 0x2743;
  13273. t['a63'] = 0x2744;
  13274. t['a64'] = 0x2745;
  13275. t['a65'] = 0x2746;
  13276. t['a66'] = 0x2747;
  13277. t['a67'] = 0x2748;
  13278. t['a68'] = 0x2749;
  13279. t['a69'] = 0x274A;
  13280. t['a70'] = 0x274B;
  13281. t['a71'] = 0x25CF;
  13282. t['a72'] = 0x274D;
  13283. t['a73'] = 0x25A0;
  13284. t['a74'] = 0x274F;
  13285. t['a203'] = 0x2750;
  13286. t['a75'] = 0x2751;
  13287. t['a204'] = 0x2752;
  13288. t['a76'] = 0x25B2;
  13289. t['a77'] = 0x25BC;
  13290. t['a78'] = 0x25C6;
  13291. t['a79'] = 0x2756;
  13292. t['a81'] = 0x25D7;
  13293. t['a82'] = 0x2758;
  13294. t['a83'] = 0x2759;
  13295. t['a84'] = 0x275A;
  13296. t['a97'] = 0x275B;
  13297. t['a98'] = 0x275C;
  13298. t['a99'] = 0x275D;
  13299. t['a100'] = 0x275E;
  13300. t['a101'] = 0x2761;
  13301. t['a102'] = 0x2762;
  13302. t['a103'] = 0x2763;
  13303. t['a104'] = 0x2764;
  13304. t['a106'] = 0x2765;
  13305. t['a107'] = 0x2766;
  13306. t['a108'] = 0x2767;
  13307. t['a112'] = 0x2663;
  13308. t['a111'] = 0x2666;
  13309. t['a110'] = 0x2665;
  13310. t['a109'] = 0x2660;
  13311. t['a120'] = 0x2460;
  13312. t['a121'] = 0x2461;
  13313. t['a122'] = 0x2462;
  13314. t['a123'] = 0x2463;
  13315. t['a124'] = 0x2464;
  13316. t['a125'] = 0x2465;
  13317. t['a126'] = 0x2466;
  13318. t['a127'] = 0x2467;
  13319. t['a128'] = 0x2468;
  13320. t['a129'] = 0x2469;
  13321. t['a130'] = 0x2776;
  13322. t['a131'] = 0x2777;
  13323. t['a132'] = 0x2778;
  13324. t['a133'] = 0x2779;
  13325. t['a134'] = 0x277A;
  13326. t['a135'] = 0x277B;
  13327. t['a136'] = 0x277C;
  13328. t['a137'] = 0x277D;
  13329. t['a138'] = 0x277E;
  13330. t['a139'] = 0x277F;
  13331. t['a140'] = 0x2780;
  13332. t['a141'] = 0x2781;
  13333. t['a142'] = 0x2782;
  13334. t['a143'] = 0x2783;
  13335. t['a144'] = 0x2784;
  13336. t['a145'] = 0x2785;
  13337. t['a146'] = 0x2786;
  13338. t['a147'] = 0x2787;
  13339. t['a148'] = 0x2788;
  13340. t['a149'] = 0x2789;
  13341. t['a150'] = 0x278A;
  13342. t['a151'] = 0x278B;
  13343. t['a152'] = 0x278C;
  13344. t['a153'] = 0x278D;
  13345. t['a154'] = 0x278E;
  13346. t['a155'] = 0x278F;
  13347. t['a156'] = 0x2790;
  13348. t['a157'] = 0x2791;
  13349. t['a158'] = 0x2792;
  13350. t['a159'] = 0x2793;
  13351. t['a160'] = 0x2794;
  13352. t['a161'] = 0x2192;
  13353. t['a163'] = 0x2194;
  13354. t['a164'] = 0x2195;
  13355. t['a196'] = 0x2798;
  13356. t['a165'] = 0x2799;
  13357. t['a192'] = 0x279A;
  13358. t['a166'] = 0x279B;
  13359. t['a167'] = 0x279C;
  13360. t['a168'] = 0x279D;
  13361. t['a169'] = 0x279E;
  13362. t['a170'] = 0x279F;
  13363. t['a171'] = 0x27A0;
  13364. t['a172'] = 0x27A1;
  13365. t['a173'] = 0x27A2;
  13366. t['a162'] = 0x27A3;
  13367. t['a174'] = 0x27A4;
  13368. t['a175'] = 0x27A5;
  13369. t['a176'] = 0x27A6;
  13370. t['a177'] = 0x27A7;
  13371. t['a178'] = 0x27A8;
  13372. t['a179'] = 0x27A9;
  13373. t['a193'] = 0x27AA;
  13374. t['a180'] = 0x27AB;
  13375. t['a199'] = 0x27AC;
  13376. t['a181'] = 0x27AD;
  13377. t['a200'] = 0x27AE;
  13378. t['a182'] = 0x27AF;
  13379. t['a201'] = 0x27B1;
  13380. t['a183'] = 0x27B2;
  13381. t['a184'] = 0x27B3;
  13382. t['a197'] = 0x27B4;
  13383. t['a185'] = 0x27B5;
  13384. t['a194'] = 0x27B6;
  13385. t['a198'] = 0x27B7;
  13386. t['a186'] = 0x27B8;
  13387. t['a195'] = 0x27B9;
  13388. t['a187'] = 0x27BA;
  13389. t['a188'] = 0x27BB;
  13390. t['a189'] = 0x27BC;
  13391. t['a190'] = 0x27BD;
  13392. t['a191'] = 0x27BE;
  13393. t['a89'] = 0x2768;
  13394. // 0xF8D7
  13395. t['a90'] = 0x2769;
  13396. // 0xF8D8
  13397. t['a93'] = 0x276A;
  13398. // 0xF8D9
  13399. t['a94'] = 0x276B;
  13400. // 0xF8DA
  13401. t['a91'] = 0x276C;
  13402. // 0xF8DB
  13403. t['a92'] = 0x276D;
  13404. // 0xF8DC
  13405. t['a205'] = 0x276E;
  13406. // 0xF8DD
  13407. t['a85'] = 0x276F;
  13408. // 0xF8DE
  13409. t['a206'] = 0x2770;
  13410. // 0xF8DF
  13411. t['a86'] = 0x2771;
  13412. // 0xF8E0
  13413. t['a87'] = 0x2772;
  13414. // 0xF8E1
  13415. t['a88'] = 0x2773;
  13416. // 0xF8E2
  13417. t['a95'] = 0x2774;
  13418. // 0xF8E3
  13419. t['a96'] = 0x2775;
  13420. // 0xF8E4
  13421. t['.notdef'] = 0x0000;
  13422. });
  13423. exports.getGlyphsUnicode = getGlyphsUnicode;
  13424. exports.getDingbatsGlyphsUnicode = getDingbatsGlyphsUnicode;
  13425. }));
  13426. (function (root, factory) {
  13427. factory(root.pdfjsCoreJbig2 = {}, root.pdfjsSharedUtil, root.pdfjsCoreArithmeticDecoder);
  13428. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  13429. var error = sharedUtil.error;
  13430. var log2 = sharedUtil.log2;
  13431. var readInt8 = sharedUtil.readInt8;
  13432. var readUint16 = sharedUtil.readUint16;
  13433. var readUint32 = sharedUtil.readUint32;
  13434. var shadow = sharedUtil.shadow;
  13435. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  13436. var Jbig2Image = function Jbig2ImageClosure() {
  13437. // Utility data structures
  13438. function ContextCache() {
  13439. }
  13440. ContextCache.prototype = {
  13441. getContexts: function (id) {
  13442. if (id in this) {
  13443. return this[id];
  13444. }
  13445. return this[id] = new Int8Array(1 << 16);
  13446. }
  13447. };
  13448. function DecodingContext(data, start, end) {
  13449. this.data = data;
  13450. this.start = start;
  13451. this.end = end;
  13452. }
  13453. DecodingContext.prototype = {
  13454. get decoder() {
  13455. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  13456. return shadow(this, 'decoder', decoder);
  13457. },
  13458. get contextCache() {
  13459. var cache = new ContextCache();
  13460. return shadow(this, 'contextCache', cache);
  13461. }
  13462. };
  13463. // Annex A. Arithmetic Integer Decoding Procedure
  13464. // A.2 Procedure for decoding values
  13465. function decodeInteger(contextCache, procedure, decoder) {
  13466. var contexts = contextCache.getContexts(procedure);
  13467. var prev = 1;
  13468. function readBits(length) {
  13469. var v = 0;
  13470. for (var i = 0; i < length; i++) {
  13471. var bit = decoder.readBit(contexts, prev);
  13472. prev = prev < 256 ? prev << 1 | bit : (prev << 1 | bit) & 511 | 256;
  13473. v = v << 1 | bit;
  13474. }
  13475. return v >>> 0;
  13476. }
  13477. var sign = readBits(1);
  13478. 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);
  13479. return sign === 0 ? value : value > 0 ? -value : null;
  13480. }
  13481. // A.3 The IAID decoding procedure
  13482. function decodeIAID(contextCache, decoder, codeLength) {
  13483. var contexts = contextCache.getContexts('IAID');
  13484. var prev = 1;
  13485. for (var i = 0; i < codeLength; i++) {
  13486. var bit = decoder.readBit(contexts, prev);
  13487. prev = prev << 1 | bit;
  13488. }
  13489. if (codeLength < 31) {
  13490. return prev & (1 << codeLength) - 1;
  13491. }
  13492. return prev & 0x7FFFFFFF;
  13493. }
  13494. // 7.3 Segment types
  13495. var SegmentTypes = [
  13496. 'SymbolDictionary',
  13497. null,
  13498. null,
  13499. null,
  13500. 'IntermediateTextRegion',
  13501. null,
  13502. 'ImmediateTextRegion',
  13503. 'ImmediateLosslessTextRegion',
  13504. null,
  13505. null,
  13506. null,
  13507. null,
  13508. null,
  13509. null,
  13510. null,
  13511. null,
  13512. 'patternDictionary',
  13513. null,
  13514. null,
  13515. null,
  13516. 'IntermediateHalftoneRegion',
  13517. null,
  13518. 'ImmediateHalftoneRegion',
  13519. 'ImmediateLosslessHalftoneRegion',
  13520. null,
  13521. null,
  13522. null,
  13523. null,
  13524. null,
  13525. null,
  13526. null,
  13527. null,
  13528. null,
  13529. null,
  13530. null,
  13531. null,
  13532. 'IntermediateGenericRegion',
  13533. null,
  13534. 'ImmediateGenericRegion',
  13535. 'ImmediateLosslessGenericRegion',
  13536. 'IntermediateGenericRefinementRegion',
  13537. null,
  13538. 'ImmediateGenericRefinementRegion',
  13539. 'ImmediateLosslessGenericRefinementRegion',
  13540. null,
  13541. null,
  13542. null,
  13543. null,
  13544. 'PageInformation',
  13545. 'EndOfPage',
  13546. 'EndOfStripe',
  13547. 'EndOfFile',
  13548. 'Profiles',
  13549. 'Tables',
  13550. null,
  13551. null,
  13552. null,
  13553. null,
  13554. null,
  13555. null,
  13556. null,
  13557. null,
  13558. 'Extension'
  13559. ];
  13560. var CodingTemplates = [
  13561. [
  13562. {
  13563. x: -1,
  13564. y: -2
  13565. },
  13566. {
  13567. x: 0,
  13568. y: -2
  13569. },
  13570. {
  13571. x: 1,
  13572. y: -2
  13573. },
  13574. {
  13575. x: -2,
  13576. y: -1
  13577. },
  13578. {
  13579. x: -1,
  13580. y: -1
  13581. },
  13582. {
  13583. x: 0,
  13584. y: -1
  13585. },
  13586. {
  13587. x: 1,
  13588. y: -1
  13589. },
  13590. {
  13591. x: 2,
  13592. y: -1
  13593. },
  13594. {
  13595. x: -4,
  13596. y: 0
  13597. },
  13598. {
  13599. x: -3,
  13600. y: 0
  13601. },
  13602. {
  13603. x: -2,
  13604. y: 0
  13605. },
  13606. {
  13607. x: -1,
  13608. y: 0
  13609. }
  13610. ],
  13611. [
  13612. {
  13613. x: -1,
  13614. y: -2
  13615. },
  13616. {
  13617. x: 0,
  13618. y: -2
  13619. },
  13620. {
  13621. x: 1,
  13622. y: -2
  13623. },
  13624. {
  13625. x: 2,
  13626. y: -2
  13627. },
  13628. {
  13629. x: -2,
  13630. y: -1
  13631. },
  13632. {
  13633. x: -1,
  13634. y: -1
  13635. },
  13636. {
  13637. x: 0,
  13638. y: -1
  13639. },
  13640. {
  13641. x: 1,
  13642. y: -1
  13643. },
  13644. {
  13645. x: 2,
  13646. y: -1
  13647. },
  13648. {
  13649. x: -3,
  13650. y: 0
  13651. },
  13652. {
  13653. x: -2,
  13654. y: 0
  13655. },
  13656. {
  13657. x: -1,
  13658. y: 0
  13659. }
  13660. ],
  13661. [
  13662. {
  13663. x: -1,
  13664. y: -2
  13665. },
  13666. {
  13667. x: 0,
  13668. y: -2
  13669. },
  13670. {
  13671. x: 1,
  13672. y: -2
  13673. },
  13674. {
  13675. x: -2,
  13676. y: -1
  13677. },
  13678. {
  13679. x: -1,
  13680. y: -1
  13681. },
  13682. {
  13683. x: 0,
  13684. y: -1
  13685. },
  13686. {
  13687. x: 1,
  13688. y: -1
  13689. },
  13690. {
  13691. x: -2,
  13692. y: 0
  13693. },
  13694. {
  13695. x: -1,
  13696. y: 0
  13697. }
  13698. ],
  13699. [
  13700. {
  13701. x: -3,
  13702. y: -1
  13703. },
  13704. {
  13705. x: -2,
  13706. y: -1
  13707. },
  13708. {
  13709. x: -1,
  13710. y: -1
  13711. },
  13712. {
  13713. x: 0,
  13714. y: -1
  13715. },
  13716. {
  13717. x: 1,
  13718. y: -1
  13719. },
  13720. {
  13721. x: -4,
  13722. y: 0
  13723. },
  13724. {
  13725. x: -3,
  13726. y: 0
  13727. },
  13728. {
  13729. x: -2,
  13730. y: 0
  13731. },
  13732. {
  13733. x: -1,
  13734. y: 0
  13735. }
  13736. ]
  13737. ];
  13738. var RefinementTemplates = [
  13739. {
  13740. coding: [
  13741. {
  13742. x: 0,
  13743. y: -1
  13744. },
  13745. {
  13746. x: 1,
  13747. y: -1
  13748. },
  13749. {
  13750. x: -1,
  13751. y: 0
  13752. }
  13753. ],
  13754. reference: [
  13755. {
  13756. x: 0,
  13757. y: -1
  13758. },
  13759. {
  13760. x: 1,
  13761. y: -1
  13762. },
  13763. {
  13764. x: -1,
  13765. y: 0
  13766. },
  13767. {
  13768. x: 0,
  13769. y: 0
  13770. },
  13771. {
  13772. x: 1,
  13773. y: 0
  13774. },
  13775. {
  13776. x: -1,
  13777. y: 1
  13778. },
  13779. {
  13780. x: 0,
  13781. y: 1
  13782. },
  13783. {
  13784. x: 1,
  13785. y: 1
  13786. }
  13787. ]
  13788. },
  13789. {
  13790. coding: [
  13791. {
  13792. x: -1,
  13793. y: -1
  13794. },
  13795. {
  13796. x: 0,
  13797. y: -1
  13798. },
  13799. {
  13800. x: 1,
  13801. y: -1
  13802. },
  13803. {
  13804. x: -1,
  13805. y: 0
  13806. }
  13807. ],
  13808. reference: [
  13809. {
  13810. x: 0,
  13811. y: -1
  13812. },
  13813. {
  13814. x: -1,
  13815. y: 0
  13816. },
  13817. {
  13818. x: 0,
  13819. y: 0
  13820. },
  13821. {
  13822. x: 1,
  13823. y: 0
  13824. },
  13825. {
  13826. x: 0,
  13827. y: 1
  13828. },
  13829. {
  13830. x: 1,
  13831. y: 1
  13832. }
  13833. ]
  13834. }
  13835. ];
  13836. // See 6.2.5.7 Decoding the bitmap.
  13837. var ReusedContexts = [
  13838. 0x9B25,
  13839. // 10011 0110010 0101
  13840. 0x0795,
  13841. // 0011 110010 101
  13842. 0x00E5,
  13843. // 001 11001 01
  13844. 0x0195
  13845. ];
  13846. // 011001 0101
  13847. var RefinementReusedContexts = [
  13848. 0x0020,
  13849. // '000' + '0' (coding) + '00010000' + '0' (reference)
  13850. 0x0008
  13851. ];
  13852. // '0000' + '001000'
  13853. function decodeBitmapTemplate0(width, height, decodingContext) {
  13854. var decoder = decodingContext.decoder;
  13855. var contexts = decodingContext.contextCache.getContexts('GB');
  13856. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  13857. // ...ooooo....
  13858. // ..ooooooo... Context template for current pixel (X)
  13859. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  13860. var OLD_PIXEL_MASK = 0x7BF7;
  13861. // 01111 0111111 0111
  13862. for (i = 0; i < height; i++) {
  13863. row = bitmap[i] = new Uint8Array(width);
  13864. row1 = i < 1 ? row : bitmap[i - 1];
  13865. row2 = i < 2 ? row : bitmap[i - 2];
  13866. // At the beginning of each row:
  13867. // Fill contextLabel with pixels that are above/right of (X)
  13868. contextLabel = row2[0] << 13 | row2[1] << 12 | row2[2] << 11 | row1[0] << 7 | row1[1] << 6 | row1[2] << 5 | row1[3] << 4;
  13869. for (j = 0; j < width; j++) {
  13870. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  13871. // At each pixel: Clear contextLabel pixels that are shifted
  13872. // out of the context, then add new ones.
  13873. contextLabel = (contextLabel & OLD_PIXEL_MASK) << 1 | (j + 3 < width ? row2[j + 3] << 11 : 0) | (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  13874. }
  13875. }
  13876. return bitmap;
  13877. }
  13878. // 6.2 Generic Region Decoding Procedure
  13879. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at, decodingContext) {
  13880. if (mmr) {
  13881. error('JBIG2 error: MMR encoding is not supported');
  13882. }
  13883. // Use optimized version for the most common case
  13884. 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) {
  13885. return decodeBitmapTemplate0(width, height, decodingContext);
  13886. }
  13887. var useskip = !!skip;
  13888. var template = CodingTemplates[templateIndex].concat(at);
  13889. // Sorting is non-standard, and it is not required. But sorting increases
  13890. // the number of template bits that can be reused from the previous
  13891. // contextLabel in the main loop.
  13892. template.sort(function (a, b) {
  13893. return a.y - b.y || a.x - b.x;
  13894. });
  13895. var templateLength = template.length;
  13896. var templateX = new Int8Array(templateLength);
  13897. var templateY = new Int8Array(templateLength);
  13898. var changingTemplateEntries = [];
  13899. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  13900. var c, k;
  13901. for (k = 0; k < templateLength; k++) {
  13902. templateX[k] = template[k].x;
  13903. templateY[k] = template[k].y;
  13904. minX = Math.min(minX, template[k].x);
  13905. maxX = Math.max(maxX, template[k].x);
  13906. minY = Math.min(minY, template[k].y);
  13907. // Check if the template pixel appears in two consecutive context labels,
  13908. // so it can be reused. Otherwise, we add it to the list of changing
  13909. // template entries.
  13910. if (k < templateLength - 1 && template[k].y === template[k + 1].y && template[k].x === template[k + 1].x - 1) {
  13911. reuseMask |= 1 << templateLength - 1 - k;
  13912. } else {
  13913. changingTemplateEntries.push(k);
  13914. }
  13915. }
  13916. var changingEntriesLength = changingTemplateEntries.length;
  13917. var changingTemplateX = new Int8Array(changingEntriesLength);
  13918. var changingTemplateY = new Int8Array(changingEntriesLength);
  13919. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  13920. for (c = 0; c < changingEntriesLength; c++) {
  13921. k = changingTemplateEntries[c];
  13922. changingTemplateX[c] = template[k].x;
  13923. changingTemplateY[c] = template[k].y;
  13924. changingTemplateBit[c] = 1 << templateLength - 1 - k;
  13925. }
  13926. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  13927. var sbb_left = -minX;
  13928. var sbb_top = -minY;
  13929. var sbb_right = width - maxX;
  13930. var pseudoPixelContext = ReusedContexts[templateIndex];
  13931. var row = new Uint8Array(width);
  13932. var bitmap = [];
  13933. var decoder = decodingContext.decoder;
  13934. var contexts = decodingContext.contextCache.getContexts('GB');
  13935. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  13936. for (var i = 0; i < height; i++) {
  13937. if (prediction) {
  13938. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  13939. ltp ^= sltp;
  13940. if (ltp) {
  13941. bitmap.push(row);
  13942. // duplicate previous row
  13943. continue;
  13944. }
  13945. }
  13946. row = new Uint8Array(row);
  13947. bitmap.push(row);
  13948. for (j = 0; j < width; j++) {
  13949. if (useskip && skip[i][j]) {
  13950. row[j] = 0;
  13951. continue;
  13952. }
  13953. // Are we in the middle of a scanline, so we can reuse contextLabel
  13954. // bits?
  13955. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  13956. // If yes, we can just shift the bits that are reusable and only
  13957. // fetch the remaining ones.
  13958. contextLabel = contextLabel << 1 & reuseMask;
  13959. for (k = 0; k < changingEntriesLength; k++) {
  13960. i0 = i + changingTemplateY[k];
  13961. j0 = j + changingTemplateX[k];
  13962. bit = bitmap[i0][j0];
  13963. if (bit) {
  13964. bit = changingTemplateBit[k];
  13965. contextLabel |= bit;
  13966. }
  13967. }
  13968. } else {
  13969. // compute the contextLabel from scratch
  13970. contextLabel = 0;
  13971. shift = templateLength - 1;
  13972. for (k = 0; k < templateLength; k++, shift--) {
  13973. j0 = j + templateX[k];
  13974. if (j0 >= 0 && j0 < width) {
  13975. i0 = i + templateY[k];
  13976. if (i0 >= 0) {
  13977. bit = bitmap[i0][j0];
  13978. if (bit) {
  13979. contextLabel |= bit << shift;
  13980. }
  13981. }
  13982. }
  13983. }
  13984. }
  13985. var pixel = decoder.readBit(contexts, contextLabel);
  13986. row[j] = pixel;
  13987. }
  13988. }
  13989. return bitmap;
  13990. }
  13991. // 6.3.2 Generic Refinement Region Decoding Procedure
  13992. function decodeRefinement(width, height, templateIndex, referenceBitmap, offsetX, offsetY, prediction, at, decodingContext) {
  13993. var codingTemplate = RefinementTemplates[templateIndex].coding;
  13994. if (templateIndex === 0) {
  13995. codingTemplate = codingTemplate.concat([at[0]]);
  13996. }
  13997. var codingTemplateLength = codingTemplate.length;
  13998. var codingTemplateX = new Int32Array(codingTemplateLength);
  13999. var codingTemplateY = new Int32Array(codingTemplateLength);
  14000. var k;
  14001. for (k = 0; k < codingTemplateLength; k++) {
  14002. codingTemplateX[k] = codingTemplate[k].x;
  14003. codingTemplateY[k] = codingTemplate[k].y;
  14004. }
  14005. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  14006. if (templateIndex === 0) {
  14007. referenceTemplate = referenceTemplate.concat([at[1]]);
  14008. }
  14009. var referenceTemplateLength = referenceTemplate.length;
  14010. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  14011. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  14012. for (k = 0; k < referenceTemplateLength; k++) {
  14013. referenceTemplateX[k] = referenceTemplate[k].x;
  14014. referenceTemplateY[k] = referenceTemplate[k].y;
  14015. }
  14016. var referenceWidth = referenceBitmap[0].length;
  14017. var referenceHeight = referenceBitmap.length;
  14018. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  14019. var bitmap = [];
  14020. var decoder = decodingContext.decoder;
  14021. var contexts = decodingContext.contextCache.getContexts('GR');
  14022. var ltp = 0;
  14023. for (var i = 0; i < height; i++) {
  14024. if (prediction) {
  14025. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  14026. ltp ^= sltp;
  14027. if (ltp) {
  14028. error('JBIG2 error: prediction is not supported');
  14029. }
  14030. }
  14031. var row = new Uint8Array(width);
  14032. bitmap.push(row);
  14033. for (var j = 0; j < width; j++) {
  14034. var i0, j0;
  14035. var contextLabel = 0;
  14036. for (k = 0; k < codingTemplateLength; k++) {
  14037. i0 = i + codingTemplateY[k];
  14038. j0 = j + codingTemplateX[k];
  14039. if (i0 < 0 || j0 < 0 || j0 >= width) {
  14040. contextLabel <<= 1;
  14041. } else
  14042. // out of bound pixel
  14043. {
  14044. contextLabel = contextLabel << 1 | bitmap[i0][j0];
  14045. }
  14046. }
  14047. for (k = 0; k < referenceTemplateLength; k++) {
  14048. i0 = i + referenceTemplateY[k] + offsetY;
  14049. j0 = j + referenceTemplateX[k] + offsetX;
  14050. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 || j0 >= referenceWidth) {
  14051. contextLabel <<= 1;
  14052. } else
  14053. // out of bound pixel
  14054. {
  14055. contextLabel = contextLabel << 1 | referenceBitmap[i0][j0];
  14056. }
  14057. }
  14058. var pixel = decoder.readBit(contexts, contextLabel);
  14059. row[j] = pixel;
  14060. }
  14061. }
  14062. return bitmap;
  14063. }
  14064. // 6.5.5 Decoding the symbol dictionary
  14065. function decodeSymbolDictionary(huffman, refinement, symbols, numberOfNewSymbols, numberOfExportedSymbols, huffmanTables, templateIndex, at, refinementTemplateIndex, refinementAt, decodingContext) {
  14066. if (huffman) {
  14067. error('JBIG2 error: huffman is not supported');
  14068. }
  14069. var newSymbols = [];
  14070. var currentHeight = 0;
  14071. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  14072. var decoder = decodingContext.decoder;
  14073. var contextCache = decodingContext.contextCache;
  14074. while (newSymbols.length < numberOfNewSymbols) {
  14075. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder);
  14076. // 6.5.6
  14077. currentHeight += deltaHeight;
  14078. var currentWidth = 0;
  14079. var totalWidth = 0;
  14080. while (true) {
  14081. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder);
  14082. // 6.5.7
  14083. if (deltaWidth === null) {
  14084. break;
  14085. }
  14086. // OOB
  14087. currentWidth += deltaWidth;
  14088. totalWidth += currentWidth;
  14089. var bitmap;
  14090. if (refinement) {
  14091. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  14092. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  14093. if (numberOfInstances > 1) {
  14094. bitmap = decodeTextRegion(huffman, refinement, currentWidth, currentHeight, 0, numberOfInstances, 1, //strip size
  14095. symbols.concat(newSymbols), symbolCodeLength, 0, //transposed
  14096. 0, //ds offset
  14097. 1, //top left 7.4.3.1.1
  14098. 0, //OR operator
  14099. huffmanTables, refinementTemplateIndex, refinementAt, decodingContext);
  14100. } else {
  14101. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  14102. var rdx = decodeInteger(contextCache, 'IARDX', decoder);
  14103. // 6.4.11.3
  14104. var rdy = decodeInteger(contextCache, 'IARDY', decoder);
  14105. // 6.4.11.4
  14106. var symbol = symbolId < symbols.length ? symbols[symbolId] : newSymbols[symbolId - symbols.length];
  14107. bitmap = decodeRefinement(currentWidth, currentHeight, refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt, decodingContext);
  14108. }
  14109. } else {
  14110. // 6.5.8.1 Direct-coded symbol bitmap
  14111. bitmap = decodeBitmap(false, currentWidth, currentHeight, templateIndex, false, null, at, decodingContext);
  14112. }
  14113. newSymbols.push(bitmap);
  14114. }
  14115. }
  14116. // 6.5.10 Exported symbols
  14117. var exportedSymbols = [];
  14118. var flags = [], currentFlag = false;
  14119. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  14120. while (flags.length < totalSymbolsLength) {
  14121. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  14122. while (runLength--) {
  14123. flags.push(currentFlag);
  14124. }
  14125. currentFlag = !currentFlag;
  14126. }
  14127. for (var i = 0, ii = symbols.length; i < ii; i++) {
  14128. if (flags[i]) {
  14129. exportedSymbols.push(symbols[i]);
  14130. }
  14131. }
  14132. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  14133. if (flags[i]) {
  14134. exportedSymbols.push(newSymbols[j]);
  14135. }
  14136. }
  14137. return exportedSymbols;
  14138. }
  14139. function decodeTextRegion(huffman, refinement, width, height, defaultPixelValue, numberOfSymbolInstances, stripSize, inputSymbols, symbolCodeLength, transposed, dsOffset, referenceCorner, combinationOperator, huffmanTables, refinementTemplateIndex, refinementAt, decodingContext) {
  14140. if (huffman) {
  14141. error('JBIG2 error: huffman is not supported');
  14142. }
  14143. // Prepare bitmap
  14144. var bitmap = [];
  14145. var i, row;
  14146. for (i = 0; i < height; i++) {
  14147. row = new Uint8Array(width);
  14148. if (defaultPixelValue) {
  14149. for (var j = 0; j < width; j++) {
  14150. row[j] = defaultPixelValue;
  14151. }
  14152. }
  14153. bitmap.push(row);
  14154. }
  14155. var decoder = decodingContext.decoder;
  14156. var contextCache = decodingContext.contextCache;
  14157. var stripT = -decodeInteger(contextCache, 'IADT', decoder);
  14158. // 6.4.6
  14159. var firstS = 0;
  14160. i = 0;
  14161. while (i < numberOfSymbolInstances) {
  14162. var deltaT = decodeInteger(contextCache, 'IADT', decoder);
  14163. // 6.4.6
  14164. stripT += deltaT;
  14165. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder);
  14166. // 6.4.7
  14167. firstS += deltaFirstS;
  14168. var currentS = firstS;
  14169. do {
  14170. var currentT = stripSize === 1 ? 0 : decodeInteger(contextCache, 'IAIT', decoder);
  14171. // 6.4.9
  14172. var t = stripSize * stripT + currentT;
  14173. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  14174. var applyRefinement = refinement && decodeInteger(contextCache, 'IARI', decoder);
  14175. var symbolBitmap = inputSymbols[symbolId];
  14176. var symbolWidth = symbolBitmap[0].length;
  14177. var symbolHeight = symbolBitmap.length;
  14178. if (applyRefinement) {
  14179. var rdw = decodeInteger(contextCache, 'IARDW', decoder);
  14180. // 6.4.11.1
  14181. var rdh = decodeInteger(contextCache, 'IARDH', decoder);
  14182. // 6.4.11.2
  14183. var rdx = decodeInteger(contextCache, 'IARDX', decoder);
  14184. // 6.4.11.3
  14185. var rdy = decodeInteger(contextCache, 'IARDY', decoder);
  14186. // 6.4.11.4
  14187. symbolWidth += rdw;
  14188. symbolHeight += rdh;
  14189. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight, refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx, (rdh >> 1) + rdy, false, refinementAt, decodingContext);
  14190. }
  14191. var offsetT = t - (referenceCorner & 1 ? 0 : symbolHeight);
  14192. var offsetS = currentS - (referenceCorner & 2 ? symbolWidth : 0);
  14193. var s2, t2, symbolRow;
  14194. if (transposed) {
  14195. // Place Symbol Bitmap from T1,S1
  14196. for (s2 = 0; s2 < symbolHeight; s2++) {
  14197. row = bitmap[offsetS + s2];
  14198. if (!row) {
  14199. continue;
  14200. }
  14201. symbolRow = symbolBitmap[s2];
  14202. // To ignore Parts of Symbol bitmap which goes
  14203. // outside bitmap region
  14204. var maxWidth = Math.min(width - offsetT, symbolWidth);
  14205. switch (combinationOperator) {
  14206. case 0:
  14207. // OR
  14208. for (t2 = 0; t2 < maxWidth; t2++) {
  14209. row[offsetT + t2] |= symbolRow[t2];
  14210. }
  14211. break;
  14212. case 2:
  14213. // XOR
  14214. for (t2 = 0; t2 < maxWidth; t2++) {
  14215. row[offsetT + t2] ^= symbolRow[t2];
  14216. }
  14217. break;
  14218. default:
  14219. error('JBIG2 error: operator ' + combinationOperator + ' is not supported');
  14220. }
  14221. }
  14222. currentS += symbolHeight - 1;
  14223. } else {
  14224. for (t2 = 0; t2 < symbolHeight; t2++) {
  14225. row = bitmap[offsetT + t2];
  14226. if (!row) {
  14227. continue;
  14228. }
  14229. symbolRow = symbolBitmap[t2];
  14230. switch (combinationOperator) {
  14231. case 0:
  14232. // OR
  14233. for (s2 = 0; s2 < symbolWidth; s2++) {
  14234. row[offsetS + s2] |= symbolRow[s2];
  14235. }
  14236. break;
  14237. case 2:
  14238. // XOR
  14239. for (s2 = 0; s2 < symbolWidth; s2++) {
  14240. row[offsetS + s2] ^= symbolRow[s2];
  14241. }
  14242. break;
  14243. default:
  14244. error('JBIG2 error: operator ' + combinationOperator + ' is not supported');
  14245. }
  14246. }
  14247. currentS += symbolWidth - 1;
  14248. }
  14249. i++;
  14250. var deltaS = decodeInteger(contextCache, 'IADS', decoder);
  14251. // 6.4.8
  14252. if (deltaS === null) {
  14253. break;
  14254. }
  14255. // OOB
  14256. currentS += deltaS + dsOffset;
  14257. } while (true);
  14258. }
  14259. return bitmap;
  14260. }
  14261. function readSegmentHeader(data, start) {
  14262. var segmentHeader = {};
  14263. segmentHeader.number = readUint32(data, start);
  14264. var flags = data[start + 4];
  14265. var segmentType = flags & 0x3F;
  14266. if (!SegmentTypes[segmentType]) {
  14267. error('JBIG2 error: invalid segment type: ' + segmentType);
  14268. }
  14269. segmentHeader.type = segmentType;
  14270. segmentHeader.typeName = SegmentTypes[segmentType];
  14271. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  14272. var pageAssociationFieldSize = !!(flags & 0x40);
  14273. var referredFlags = data[start + 5];
  14274. var referredToCount = referredFlags >> 5 & 7;
  14275. var retainBits = [referredFlags & 31];
  14276. var position = start + 6;
  14277. if (referredFlags === 7) {
  14278. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  14279. position += 3;
  14280. var bytes = referredToCount + 7 >> 3;
  14281. retainBits[0] = data[position++];
  14282. while (--bytes > 0) {
  14283. retainBits.push(data[position++]);
  14284. }
  14285. } else if (referredFlags === 5 || referredFlags === 6) {
  14286. error('JBIG2 error: invalid referred-to flags');
  14287. }
  14288. segmentHeader.retainBits = retainBits;
  14289. var referredToSegmentNumberSize = segmentHeader.number <= 256 ? 1 : segmentHeader.number <= 65536 ? 2 : 4;
  14290. var referredTo = [];
  14291. var i, ii;
  14292. for (i = 0; i < referredToCount; i++) {
  14293. var number = referredToSegmentNumberSize === 1 ? data[position] : referredToSegmentNumberSize === 2 ? readUint16(data, position) : readUint32(data, position);
  14294. referredTo.push(number);
  14295. position += referredToSegmentNumberSize;
  14296. }
  14297. segmentHeader.referredTo = referredTo;
  14298. if (!pageAssociationFieldSize) {
  14299. segmentHeader.pageAssociation = data[position++];
  14300. } else {
  14301. segmentHeader.pageAssociation = readUint32(data, position);
  14302. position += 4;
  14303. }
  14304. segmentHeader.length = readUint32(data, position);
  14305. position += 4;
  14306. if (segmentHeader.length === 0xFFFFFFFF) {
  14307. // 7.2.7 Segment data length, unknown segment length
  14308. if (segmentType === 38) {
  14309. // ImmediateGenericRegion
  14310. var genericRegionInfo = readRegionSegmentInformation(data, position);
  14311. var genericRegionSegmentFlags = data[position + RegionSegmentInformationFieldLength];
  14312. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  14313. // searching for the segment end
  14314. var searchPatternLength = 6;
  14315. var searchPattern = new Uint8Array(searchPatternLength);
  14316. if (!genericRegionMmr) {
  14317. searchPattern[0] = 0xFF;
  14318. searchPattern[1] = 0xAC;
  14319. }
  14320. searchPattern[2] = genericRegionInfo.height >>> 24 & 0xFF;
  14321. searchPattern[3] = genericRegionInfo.height >> 16 & 0xFF;
  14322. searchPattern[4] = genericRegionInfo.height >> 8 & 0xFF;
  14323. searchPattern[5] = genericRegionInfo.height & 0xFF;
  14324. for (i = position, ii = data.length; i < ii; i++) {
  14325. var j = 0;
  14326. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  14327. j++;
  14328. }
  14329. if (j === searchPatternLength) {
  14330. segmentHeader.length = i + searchPatternLength;
  14331. break;
  14332. }
  14333. }
  14334. if (segmentHeader.length === 0xFFFFFFFF) {
  14335. error('JBIG2 error: segment end was not found');
  14336. }
  14337. } else {
  14338. error('JBIG2 error: invalid unknown segment length');
  14339. }
  14340. }
  14341. segmentHeader.headerEnd = position;
  14342. return segmentHeader;
  14343. }
  14344. function readSegments(header, data, start, end) {
  14345. var segments = [];
  14346. var position = start;
  14347. while (position < end) {
  14348. var segmentHeader = readSegmentHeader(data, position);
  14349. position = segmentHeader.headerEnd;
  14350. var segment = {
  14351. header: segmentHeader,
  14352. data: data
  14353. };
  14354. if (!header.randomAccess) {
  14355. segment.start = position;
  14356. position += segmentHeader.length;
  14357. segment.end = position;
  14358. }
  14359. segments.push(segment);
  14360. if (segmentHeader.type === 51) {
  14361. break;
  14362. }
  14363. }
  14364. // end of file is found
  14365. if (header.randomAccess) {
  14366. for (var i = 0, ii = segments.length; i < ii; i++) {
  14367. segments[i].start = position;
  14368. position += segments[i].header.length;
  14369. segments[i].end = position;
  14370. }
  14371. }
  14372. return segments;
  14373. }
  14374. // 7.4.1 Region segment information field
  14375. function readRegionSegmentInformation(data, start) {
  14376. return {
  14377. width: readUint32(data, start),
  14378. height: readUint32(data, start + 4),
  14379. x: readUint32(data, start + 8),
  14380. y: readUint32(data, start + 12),
  14381. combinationOperator: data[start + 16] & 7
  14382. };
  14383. }
  14384. var RegionSegmentInformationFieldLength = 17;
  14385. function processSegment(segment, visitor) {
  14386. var header = segment.header;
  14387. var data = segment.data, position = segment.start, end = segment.end;
  14388. var args, at, i, atLength;
  14389. switch (header.type) {
  14390. case 0:
  14391. // SymbolDictionary
  14392. // 7.4.2 Symbol dictionary segment syntax
  14393. var dictionary = {};
  14394. var dictionaryFlags = readUint16(data, position);
  14395. // 7.4.2.1.1
  14396. dictionary.huffman = !!(dictionaryFlags & 1);
  14397. dictionary.refinement = !!(dictionaryFlags & 2);
  14398. dictionary.huffmanDHSelector = dictionaryFlags >> 2 & 3;
  14399. dictionary.huffmanDWSelector = dictionaryFlags >> 4 & 3;
  14400. dictionary.bitmapSizeSelector = dictionaryFlags >> 6 & 1;
  14401. dictionary.aggregationInstancesSelector = dictionaryFlags >> 7 & 1;
  14402. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  14403. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  14404. dictionary.template = dictionaryFlags >> 10 & 3;
  14405. dictionary.refinementTemplate = dictionaryFlags >> 12 & 1;
  14406. position += 2;
  14407. if (!dictionary.huffman) {
  14408. atLength = dictionary.template === 0 ? 4 : 1;
  14409. at = [];
  14410. for (i = 0; i < atLength; i++) {
  14411. at.push({
  14412. x: readInt8(data, position),
  14413. y: readInt8(data, position + 1)
  14414. });
  14415. position += 2;
  14416. }
  14417. dictionary.at = at;
  14418. }
  14419. if (dictionary.refinement && !dictionary.refinementTemplate) {
  14420. at = [];
  14421. for (i = 0; i < 2; i++) {
  14422. at.push({
  14423. x: readInt8(data, position),
  14424. y: readInt8(data, position + 1)
  14425. });
  14426. position += 2;
  14427. }
  14428. dictionary.refinementAt = at;
  14429. }
  14430. dictionary.numberOfExportedSymbols = readUint32(data, position);
  14431. position += 4;
  14432. dictionary.numberOfNewSymbols = readUint32(data, position);
  14433. position += 4;
  14434. args = [
  14435. dictionary,
  14436. header.number,
  14437. header.referredTo,
  14438. data,
  14439. position,
  14440. end
  14441. ];
  14442. break;
  14443. case 6:
  14444. // ImmediateTextRegion
  14445. case 7:
  14446. // ImmediateLosslessTextRegion
  14447. var textRegion = {};
  14448. textRegion.info = readRegionSegmentInformation(data, position);
  14449. position += RegionSegmentInformationFieldLength;
  14450. var textRegionSegmentFlags = readUint16(data, position);
  14451. position += 2;
  14452. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  14453. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  14454. textRegion.stripSize = 1 << (textRegionSegmentFlags >> 2 & 3);
  14455. textRegion.referenceCorner = textRegionSegmentFlags >> 4 & 3;
  14456. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  14457. textRegion.combinationOperator = textRegionSegmentFlags >> 7 & 3;
  14458. textRegion.defaultPixelValue = textRegionSegmentFlags >> 9 & 1;
  14459. textRegion.dsOffset = textRegionSegmentFlags << 17 >> 27;
  14460. textRegion.refinementTemplate = textRegionSegmentFlags >> 15 & 1;
  14461. if (textRegion.huffman) {
  14462. var textRegionHuffmanFlags = readUint16(data, position);
  14463. position += 2;
  14464. textRegion.huffmanFS = textRegionHuffmanFlags & 3;
  14465. textRegion.huffmanDS = textRegionHuffmanFlags >> 2 & 3;
  14466. textRegion.huffmanDT = textRegionHuffmanFlags >> 4 & 3;
  14467. textRegion.huffmanRefinementDW = textRegionHuffmanFlags >> 6 & 3;
  14468. textRegion.huffmanRefinementDH = textRegionHuffmanFlags >> 8 & 3;
  14469. textRegion.huffmanRefinementDX = textRegionHuffmanFlags >> 10 & 3;
  14470. textRegion.huffmanRefinementDY = textRegionHuffmanFlags >> 12 & 3;
  14471. textRegion.huffmanRefinementSizeSelector = !!(textRegionHuffmanFlags & 14);
  14472. }
  14473. if (textRegion.refinement && !textRegion.refinementTemplate) {
  14474. at = [];
  14475. for (i = 0; i < 2; i++) {
  14476. at.push({
  14477. x: readInt8(data, position),
  14478. y: readInt8(data, position + 1)
  14479. });
  14480. position += 2;
  14481. }
  14482. textRegion.refinementAt = at;
  14483. }
  14484. textRegion.numberOfSymbolInstances = readUint32(data, position);
  14485. position += 4;
  14486. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  14487. if (textRegion.huffman) {
  14488. error('JBIG2 error: huffman is not supported');
  14489. }
  14490. args = [
  14491. textRegion,
  14492. header.referredTo,
  14493. data,
  14494. position,
  14495. end
  14496. ];
  14497. break;
  14498. case 38:
  14499. // ImmediateGenericRegion
  14500. case 39:
  14501. // ImmediateLosslessGenericRegion
  14502. var genericRegion = {};
  14503. genericRegion.info = readRegionSegmentInformation(data, position);
  14504. position += RegionSegmentInformationFieldLength;
  14505. var genericRegionSegmentFlags = data[position++];
  14506. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  14507. genericRegion.template = genericRegionSegmentFlags >> 1 & 3;
  14508. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  14509. if (!genericRegion.mmr) {
  14510. atLength = genericRegion.template === 0 ? 4 : 1;
  14511. at = [];
  14512. for (i = 0; i < atLength; i++) {
  14513. at.push({
  14514. x: readInt8(data, position),
  14515. y: readInt8(data, position + 1)
  14516. });
  14517. position += 2;
  14518. }
  14519. genericRegion.at = at;
  14520. }
  14521. args = [
  14522. genericRegion,
  14523. data,
  14524. position,
  14525. end
  14526. ];
  14527. break;
  14528. case 48:
  14529. // PageInformation
  14530. var pageInfo = {
  14531. width: readUint32(data, position),
  14532. height: readUint32(data, position + 4),
  14533. resolutionX: readUint32(data, position + 8),
  14534. resolutionY: readUint32(data, position + 12)
  14535. };
  14536. if (pageInfo.height === 0xFFFFFFFF) {
  14537. delete pageInfo.height;
  14538. }
  14539. var pageSegmentFlags = data[position + 16];
  14540. var pageStripingInformation = readUint16(data, position + 17);
  14541. pageInfo.lossless = !!(pageSegmentFlags & 1);
  14542. pageInfo.refinement = !!(pageSegmentFlags & 2);
  14543. pageInfo.defaultPixelValue = pageSegmentFlags >> 2 & 1;
  14544. pageInfo.combinationOperator = pageSegmentFlags >> 3 & 3;
  14545. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  14546. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  14547. args = [pageInfo];
  14548. break;
  14549. case 49:
  14550. // EndOfPage
  14551. break;
  14552. case 50:
  14553. // EndOfStripe
  14554. break;
  14555. case 51:
  14556. // EndOfFile
  14557. break;
  14558. case 62:
  14559. // 7.4.15 defines 2 extension types which
  14560. // are comments and can be ignored.
  14561. break;
  14562. default:
  14563. error('JBIG2 error: segment type ' + header.typeName + '(' + header.type + ') is not implemented');
  14564. }
  14565. var callbackName = 'on' + header.typeName;
  14566. if (callbackName in visitor) {
  14567. visitor[callbackName].apply(visitor, args);
  14568. }
  14569. }
  14570. function processSegments(segments, visitor) {
  14571. for (var i = 0, ii = segments.length; i < ii; i++) {
  14572. processSegment(segments[i], visitor);
  14573. }
  14574. }
  14575. function parseJbig2(data, start, end) {
  14576. var position = start;
  14577. 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) {
  14578. error('JBIG2 error: invalid header');
  14579. }
  14580. var header = {};
  14581. position += 8;
  14582. var flags = data[position++];
  14583. header.randomAccess = !(flags & 1);
  14584. if (!(flags & 2)) {
  14585. header.numberOfPages = readUint32(data, position);
  14586. position += 4;
  14587. }
  14588. var segments = readSegments(header, data, position, end);
  14589. error('Not implemented');
  14590. }
  14591. // processSegments(segments, new SimpleSegmentVisitor());
  14592. function parseJbig2Chunks(chunks) {
  14593. var visitor = new SimpleSegmentVisitor();
  14594. for (var i = 0, ii = chunks.length; i < ii; i++) {
  14595. var chunk = chunks[i];
  14596. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  14597. processSegments(segments, visitor);
  14598. }
  14599. return visitor.buffer;
  14600. }
  14601. function SimpleSegmentVisitor() {
  14602. }
  14603. SimpleSegmentVisitor.prototype = {
  14604. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  14605. this.currentPageInfo = info;
  14606. var rowSize = info.width + 7 >> 3;
  14607. var buffer = new Uint8Array(rowSize * info.height);
  14608. // The contents of ArrayBuffers are initialized to 0.
  14609. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  14610. if (info.defaultPixelValue) {
  14611. for (var i = 0, ii = buffer.length; i < ii; i++) {
  14612. buffer[i] = 0xFF;
  14613. }
  14614. }
  14615. this.buffer = buffer;
  14616. },
  14617. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  14618. var pageInfo = this.currentPageInfo;
  14619. var width = regionInfo.width, height = regionInfo.height;
  14620. var rowSize = pageInfo.width + 7 >> 3;
  14621. var combinationOperator = pageInfo.combinationOperatorOverride ? regionInfo.combinationOperator : pageInfo.combinationOperator;
  14622. var buffer = this.buffer;
  14623. var mask0 = 128 >> (regionInfo.x & 7);
  14624. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  14625. var i, j, mask, offset;
  14626. switch (combinationOperator) {
  14627. case 0:
  14628. // OR
  14629. for (i = 0; i < height; i++) {
  14630. mask = mask0;
  14631. offset = offset0;
  14632. for (j = 0; j < width; j++) {
  14633. if (bitmap[i][j]) {
  14634. buffer[offset] |= mask;
  14635. }
  14636. mask >>= 1;
  14637. if (!mask) {
  14638. mask = 128;
  14639. offset++;
  14640. }
  14641. }
  14642. offset0 += rowSize;
  14643. }
  14644. break;
  14645. case 2:
  14646. // XOR
  14647. for (i = 0; i < height; i++) {
  14648. mask = mask0;
  14649. offset = offset0;
  14650. for (j = 0; j < width; j++) {
  14651. if (bitmap[i][j]) {
  14652. buffer[offset] ^= mask;
  14653. }
  14654. mask >>= 1;
  14655. if (!mask) {
  14656. mask = 128;
  14657. offset++;
  14658. }
  14659. }
  14660. offset0 += rowSize;
  14661. }
  14662. break;
  14663. default:
  14664. error('JBIG2 error: operator ' + combinationOperator + ' is not supported');
  14665. }
  14666. },
  14667. onImmediateGenericRegion: function SimpleSegmentVisitor_onImmediateGenericRegion(region, data, start, end) {
  14668. var regionInfo = region.info;
  14669. var decodingContext = new DecodingContext(data, start, end);
  14670. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height, region.template, region.prediction, null, region.at, decodingContext);
  14671. this.drawBitmap(regionInfo, bitmap);
  14672. },
  14673. onImmediateLosslessGenericRegion: function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  14674. this.onImmediateGenericRegion.apply(this, arguments);
  14675. },
  14676. onSymbolDictionary: function SimpleSegmentVisitor_onSymbolDictionary(dictionary, currentSegment, referredSegments, data, start, end) {
  14677. var huffmanTables;
  14678. if (dictionary.huffman) {
  14679. error('JBIG2 error: huffman is not supported');
  14680. }
  14681. // Combines exported symbols from all referred segments
  14682. var symbols = this.symbols;
  14683. if (!symbols) {
  14684. this.symbols = symbols = {};
  14685. }
  14686. var inputSymbols = [];
  14687. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  14688. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  14689. }
  14690. var decodingContext = new DecodingContext(data, start, end);
  14691. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman, dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols, dictionary.numberOfExportedSymbols, huffmanTables, dictionary.template, dictionary.at, dictionary.refinementTemplate, dictionary.refinementAt, decodingContext);
  14692. },
  14693. onImmediateTextRegion: function SimpleSegmentVisitor_onImmediateTextRegion(region, referredSegments, data, start, end) {
  14694. var regionInfo = region.info;
  14695. var huffmanTables;
  14696. // Combines exported symbols from all referred segments
  14697. var symbols = this.symbols;
  14698. var inputSymbols = [];
  14699. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  14700. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  14701. }
  14702. var symbolCodeLength = log2(inputSymbols.length);
  14703. var decodingContext = new DecodingContext(data, start, end);
  14704. 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);
  14705. this.drawBitmap(regionInfo, bitmap);
  14706. },
  14707. onImmediateLosslessTextRegion: function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  14708. this.onImmediateTextRegion.apply(this, arguments);
  14709. }
  14710. };
  14711. function Jbig2Image() {
  14712. }
  14713. Jbig2Image.prototype = {
  14714. parseChunks: function Jbig2Image_parseChunks(chunks) {
  14715. return parseJbig2Chunks(chunks);
  14716. }
  14717. };
  14718. return Jbig2Image;
  14719. }();
  14720. exports.Jbig2Image = Jbig2Image;
  14721. }));
  14722. (function (root, factory) {
  14723. factory(root.pdfjsCoreJpg = {}, root.pdfjsSharedUtil);
  14724. }(this, function (exports, sharedUtil) {
  14725. var error = sharedUtil.error;
  14726. /**
  14727. * This code was forked from https://github.com/notmasteryet/jpgjs.
  14728. * The original version was created by GitHub user notmasteryet.
  14729. *
  14730. * - The JPEG specification can be found in the ITU CCITT Recommendation T.81
  14731. * (www.w3.org/Graphics/JPEG/itu-t81.pdf)
  14732. * - The JFIF specification can be found in the JPEG File Interchange Format
  14733. * (www.w3.org/Graphics/JPEG/jfif3.pdf)
  14734. * - The Adobe Application-Specific JPEG markers in the
  14735. * Supporting the DCT Filters in PostScript Level 2, Technical Note #5116
  14736. * (partners.adobe.com/public/developer/en/ps/sdk/5116.DCT_Filter.pdf)
  14737. */
  14738. var JpegImage = function JpegImageClosure() {
  14739. var dctZigZag = new Uint8Array([
  14740. 0,
  14741. 1,
  14742. 8,
  14743. 16,
  14744. 9,
  14745. 2,
  14746. 3,
  14747. 10,
  14748. 17,
  14749. 24,
  14750. 32,
  14751. 25,
  14752. 18,
  14753. 11,
  14754. 4,
  14755. 5,
  14756. 12,
  14757. 19,
  14758. 26,
  14759. 33,
  14760. 40,
  14761. 48,
  14762. 41,
  14763. 34,
  14764. 27,
  14765. 20,
  14766. 13,
  14767. 6,
  14768. 7,
  14769. 14,
  14770. 21,
  14771. 28,
  14772. 35,
  14773. 42,
  14774. 49,
  14775. 56,
  14776. 57,
  14777. 50,
  14778. 43,
  14779. 36,
  14780. 29,
  14781. 22,
  14782. 15,
  14783. 23,
  14784. 30,
  14785. 37,
  14786. 44,
  14787. 51,
  14788. 58,
  14789. 59,
  14790. 52,
  14791. 45,
  14792. 38,
  14793. 31,
  14794. 39,
  14795. 46,
  14796. 53,
  14797. 60,
  14798. 61,
  14799. 54,
  14800. 47,
  14801. 55,
  14802. 62,
  14803. 63
  14804. ]);
  14805. var dctCos1 = 4017;
  14806. // cos(pi/16)
  14807. var dctSin1 = 799;
  14808. // sin(pi/16)
  14809. var dctCos3 = 3406;
  14810. // cos(3*pi/16)
  14811. var dctSin3 = 2276;
  14812. // sin(3*pi/16)
  14813. var dctCos6 = 1567;
  14814. // cos(6*pi/16)
  14815. var dctSin6 = 3784;
  14816. // sin(6*pi/16)
  14817. var dctSqrt2 = 5793;
  14818. // sqrt(2)
  14819. var dctSqrt1d2 = 2896;
  14820. // sqrt(2) / 2
  14821. function JpegImage() {
  14822. this.decodeTransform = null;
  14823. this.colorTransform = -1;
  14824. }
  14825. function buildHuffmanTable(codeLengths, values) {
  14826. var k = 0, code = [], i, j, length = 16;
  14827. while (length > 0 && !codeLengths[length - 1]) {
  14828. length--;
  14829. }
  14830. code.push({
  14831. children: [],
  14832. index: 0
  14833. });
  14834. var p = code[0], q;
  14835. for (i = 0; i < length; i++) {
  14836. for (j = 0; j < codeLengths[i]; j++) {
  14837. p = code.pop();
  14838. p.children[p.index] = values[k];
  14839. while (p.index > 0) {
  14840. p = code.pop();
  14841. }
  14842. p.index++;
  14843. code.push(p);
  14844. while (code.length <= i) {
  14845. code.push(q = {
  14846. children: [],
  14847. index: 0
  14848. });
  14849. p.children[p.index] = q.children;
  14850. p = q;
  14851. }
  14852. k++;
  14853. }
  14854. if (i + 1 < length) {
  14855. // p here points to last code
  14856. code.push(q = {
  14857. children: [],
  14858. index: 0
  14859. });
  14860. p.children[p.index] = q.children;
  14861. p = q;
  14862. }
  14863. }
  14864. return code[0].children;
  14865. }
  14866. function getBlockBufferOffset(component, row, col) {
  14867. return 64 * ((component.blocksPerLine + 1) * row + col);
  14868. }
  14869. function decodeScan(data, offset, frame, components, resetInterval, spectralStart, spectralEnd, successivePrev, successive) {
  14870. var mcusPerLine = frame.mcusPerLine;
  14871. var progressive = frame.progressive;
  14872. var startOffset = offset, bitsData = 0, bitsCount = 0;
  14873. function readBit() {
  14874. if (bitsCount > 0) {
  14875. bitsCount--;
  14876. return bitsData >> bitsCount & 1;
  14877. }
  14878. bitsData = data[offset++];
  14879. if (bitsData === 0xFF) {
  14880. var nextByte = data[offset++];
  14881. if (nextByte) {
  14882. error('JPEG error: unexpected marker ' + (bitsData << 8 | nextByte).toString(16));
  14883. }
  14884. }
  14885. // unstuff 0
  14886. bitsCount = 7;
  14887. return bitsData >>> 7;
  14888. }
  14889. function decodeHuffman(tree) {
  14890. var node = tree;
  14891. while (true) {
  14892. node = node[readBit()];
  14893. if (typeof node === 'number') {
  14894. return node;
  14895. }
  14896. if (typeof node !== 'object') {
  14897. error('JPEG error: invalid huffman sequence');
  14898. }
  14899. }
  14900. }
  14901. function receive(length) {
  14902. var n = 0;
  14903. while (length > 0) {
  14904. n = n << 1 | readBit();
  14905. length--;
  14906. }
  14907. return n;
  14908. }
  14909. function receiveAndExtend(length) {
  14910. if (length === 1) {
  14911. return readBit() === 1 ? 1 : -1;
  14912. }
  14913. var n = receive(length);
  14914. if (n >= 1 << length - 1) {
  14915. return n;
  14916. }
  14917. return n + (-1 << length) + 1;
  14918. }
  14919. function decodeBaseline(component, offset) {
  14920. var t = decodeHuffman(component.huffmanTableDC);
  14921. var diff = t === 0 ? 0 : receiveAndExtend(t);
  14922. component.blockData[offset] = component.pred += diff;
  14923. var k = 1;
  14924. while (k < 64) {
  14925. var rs = decodeHuffman(component.huffmanTableAC);
  14926. var s = rs & 15, r = rs >> 4;
  14927. if (s === 0) {
  14928. if (r < 15) {
  14929. break;
  14930. }
  14931. k += 16;
  14932. continue;
  14933. }
  14934. k += r;
  14935. var z = dctZigZag[k];
  14936. component.blockData[offset + z] = receiveAndExtend(s);
  14937. k++;
  14938. }
  14939. }
  14940. function decodeDCFirst(component, offset) {
  14941. var t = decodeHuffman(component.huffmanTableDC);
  14942. var diff = t === 0 ? 0 : receiveAndExtend(t) << successive;
  14943. component.blockData[offset] = component.pred += diff;
  14944. }
  14945. function decodeDCSuccessive(component, offset) {
  14946. component.blockData[offset] |= readBit() << successive;
  14947. }
  14948. var eobrun = 0;
  14949. function decodeACFirst(component, offset) {
  14950. if (eobrun > 0) {
  14951. eobrun--;
  14952. return;
  14953. }
  14954. var k = spectralStart, e = spectralEnd;
  14955. while (k <= e) {
  14956. var rs = decodeHuffman(component.huffmanTableAC);
  14957. var s = rs & 15, r = rs >> 4;
  14958. if (s === 0) {
  14959. if (r < 15) {
  14960. eobrun = receive(r) + (1 << r) - 1;
  14961. break;
  14962. }
  14963. k += 16;
  14964. continue;
  14965. }
  14966. k += r;
  14967. var z = dctZigZag[k];
  14968. component.blockData[offset + z] = receiveAndExtend(s) * (1 << successive);
  14969. k++;
  14970. }
  14971. }
  14972. var successiveACState = 0, successiveACNextValue;
  14973. function decodeACSuccessive(component, offset) {
  14974. var k = spectralStart;
  14975. var e = spectralEnd;
  14976. var r = 0;
  14977. var s;
  14978. var rs;
  14979. while (k <= e) {
  14980. var z = dctZigZag[k];
  14981. switch (successiveACState) {
  14982. case 0:
  14983. // initial state
  14984. rs = decodeHuffman(component.huffmanTableAC);
  14985. s = rs & 15;
  14986. r = rs >> 4;
  14987. if (s === 0) {
  14988. if (r < 15) {
  14989. eobrun = receive(r) + (1 << r);
  14990. successiveACState = 4;
  14991. } else {
  14992. r = 16;
  14993. successiveACState = 1;
  14994. }
  14995. } else {
  14996. if (s !== 1) {
  14997. error('JPEG error: invalid ACn encoding');
  14998. }
  14999. successiveACNextValue = receiveAndExtend(s);
  15000. successiveACState = r ? 2 : 3;
  15001. }
  15002. continue;
  15003. case 1:
  15004. // skipping r zero items
  15005. case 2:
  15006. if (component.blockData[offset + z]) {
  15007. component.blockData[offset + z] += readBit() << successive;
  15008. } else {
  15009. r--;
  15010. if (r === 0) {
  15011. successiveACState = successiveACState === 2 ? 3 : 0;
  15012. }
  15013. }
  15014. break;
  15015. case 3:
  15016. // set value for a zero item
  15017. if (component.blockData[offset + z]) {
  15018. component.blockData[offset + z] += readBit() << successive;
  15019. } else {
  15020. component.blockData[offset + z] = successiveACNextValue << successive;
  15021. successiveACState = 0;
  15022. }
  15023. break;
  15024. case 4:
  15025. // eob
  15026. if (component.blockData[offset + z]) {
  15027. component.blockData[offset + z] += readBit() << successive;
  15028. }
  15029. break;
  15030. }
  15031. k++;
  15032. }
  15033. if (successiveACState === 4) {
  15034. eobrun--;
  15035. if (eobrun === 0) {
  15036. successiveACState = 0;
  15037. }
  15038. }
  15039. }
  15040. function decodeMcu(component, decode, mcu, row, col) {
  15041. var mcuRow = mcu / mcusPerLine | 0;
  15042. var mcuCol = mcu % mcusPerLine;
  15043. var blockRow = mcuRow * component.v + row;
  15044. var blockCol = mcuCol * component.h + col;
  15045. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  15046. decode(component, offset);
  15047. }
  15048. function decodeBlock(component, decode, mcu) {
  15049. var blockRow = mcu / component.blocksPerLine | 0;
  15050. var blockCol = mcu % component.blocksPerLine;
  15051. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  15052. decode(component, offset);
  15053. }
  15054. var componentsLength = components.length;
  15055. var component, i, j, k, n;
  15056. var decodeFn;
  15057. if (progressive) {
  15058. if (spectralStart === 0) {
  15059. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  15060. } else {
  15061. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  15062. }
  15063. } else {
  15064. decodeFn = decodeBaseline;
  15065. }
  15066. var mcu = 0, marker;
  15067. var mcuExpected;
  15068. if (componentsLength === 1) {
  15069. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  15070. } else {
  15071. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  15072. }
  15073. if (!resetInterval) {
  15074. resetInterval = mcuExpected;
  15075. }
  15076. var h, v;
  15077. while (mcu < mcuExpected) {
  15078. // reset interval stuff
  15079. for (i = 0; i < componentsLength; i++) {
  15080. components[i].pred = 0;
  15081. }
  15082. eobrun = 0;
  15083. if (componentsLength === 1) {
  15084. component = components[0];
  15085. for (n = 0; n < resetInterval; n++) {
  15086. decodeBlock(component, decodeFn, mcu);
  15087. mcu++;
  15088. }
  15089. } else {
  15090. for (n = 0; n < resetInterval; n++) {
  15091. for (i = 0; i < componentsLength; i++) {
  15092. component = components[i];
  15093. h = component.h;
  15094. v = component.v;
  15095. for (j = 0; j < v; j++) {
  15096. for (k = 0; k < h; k++) {
  15097. decodeMcu(component, decodeFn, mcu, j, k);
  15098. }
  15099. }
  15100. }
  15101. mcu++;
  15102. }
  15103. }
  15104. // find marker
  15105. bitsCount = 0;
  15106. marker = data[offset] << 8 | data[offset + 1];
  15107. // Some bad images seem to pad Scan blocks with zero bytes, skip past
  15108. // those to attempt to find a valid marker (fixes issue4090.pdf).
  15109. while (data[offset] === 0x00 && offset < data.length - 1) {
  15110. offset++;
  15111. marker = data[offset] << 8 | data[offset + 1];
  15112. }
  15113. if (marker <= 0xFF00) {
  15114. error('JPEG error: marker was not found');
  15115. }
  15116. if (marker >= 0xFFD0 && marker <= 0xFFD7) {
  15117. // RSTx
  15118. offset += 2;
  15119. } else {
  15120. break;
  15121. }
  15122. }
  15123. return offset - startOffset;
  15124. }
  15125. // A port of poppler's IDCT method which in turn is taken from:
  15126. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  15127. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  15128. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  15129. // 988-991.
  15130. function quantizeAndInverse(component, blockBufferOffset, p) {
  15131. var qt = component.quantizationTable, blockData = component.blockData;
  15132. var v0, v1, v2, v3, v4, v5, v6, v7;
  15133. var p0, p1, p2, p3, p4, p5, p6, p7;
  15134. var t;
  15135. if (!qt) {
  15136. error('JPEG error: missing required Quantization Table.');
  15137. }
  15138. // inverse DCT on rows
  15139. for (var row = 0; row < 64; row += 8) {
  15140. // gather block data
  15141. p0 = blockData[blockBufferOffset + row];
  15142. p1 = blockData[blockBufferOffset + row + 1];
  15143. p2 = blockData[blockBufferOffset + row + 2];
  15144. p3 = blockData[blockBufferOffset + row + 3];
  15145. p4 = blockData[blockBufferOffset + row + 4];
  15146. p5 = blockData[blockBufferOffset + row + 5];
  15147. p6 = blockData[blockBufferOffset + row + 6];
  15148. p7 = blockData[blockBufferOffset + row + 7];
  15149. // dequant p0
  15150. p0 *= qt[row];
  15151. // check for all-zero AC coefficients
  15152. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  15153. t = dctSqrt2 * p0 + 512 >> 10;
  15154. p[row] = t;
  15155. p[row + 1] = t;
  15156. p[row + 2] = t;
  15157. p[row + 3] = t;
  15158. p[row + 4] = t;
  15159. p[row + 5] = t;
  15160. p[row + 6] = t;
  15161. p[row + 7] = t;
  15162. continue;
  15163. }
  15164. // dequant p1 ... p7
  15165. p1 *= qt[row + 1];
  15166. p2 *= qt[row + 2];
  15167. p3 *= qt[row + 3];
  15168. p4 *= qt[row + 4];
  15169. p5 *= qt[row + 5];
  15170. p6 *= qt[row + 6];
  15171. p7 *= qt[row + 7];
  15172. // stage 4
  15173. v0 = dctSqrt2 * p0 + 128 >> 8;
  15174. v1 = dctSqrt2 * p4 + 128 >> 8;
  15175. v2 = p2;
  15176. v3 = p6;
  15177. v4 = dctSqrt1d2 * (p1 - p7) + 128 >> 8;
  15178. v7 = dctSqrt1d2 * (p1 + p7) + 128 >> 8;
  15179. v5 = p3 << 4;
  15180. v6 = p5 << 4;
  15181. // stage 3
  15182. v0 = v0 + v1 + 1 >> 1;
  15183. v1 = v0 - v1;
  15184. t = v2 * dctSin6 + v3 * dctCos6 + 128 >> 8;
  15185. v2 = v2 * dctCos6 - v3 * dctSin6 + 128 >> 8;
  15186. v3 = t;
  15187. v4 = v4 + v6 + 1 >> 1;
  15188. v6 = v4 - v6;
  15189. v7 = v7 + v5 + 1 >> 1;
  15190. v5 = v7 - v5;
  15191. // stage 2
  15192. v0 = v0 + v3 + 1 >> 1;
  15193. v3 = v0 - v3;
  15194. v1 = v1 + v2 + 1 >> 1;
  15195. v2 = v1 - v2;
  15196. t = v4 * dctSin3 + v7 * dctCos3 + 2048 >> 12;
  15197. v4 = v4 * dctCos3 - v7 * dctSin3 + 2048 >> 12;
  15198. v7 = t;
  15199. t = v5 * dctSin1 + v6 * dctCos1 + 2048 >> 12;
  15200. v5 = v5 * dctCos1 - v6 * dctSin1 + 2048 >> 12;
  15201. v6 = t;
  15202. // stage 1
  15203. p[row] = v0 + v7;
  15204. p[row + 7] = v0 - v7;
  15205. p[row + 1] = v1 + v6;
  15206. p[row + 6] = v1 - v6;
  15207. p[row + 2] = v2 + v5;
  15208. p[row + 5] = v2 - v5;
  15209. p[row + 3] = v3 + v4;
  15210. p[row + 4] = v3 - v4;
  15211. }
  15212. // inverse DCT on columns
  15213. for (var col = 0; col < 8; ++col) {
  15214. p0 = p[col];
  15215. p1 = p[col + 8];
  15216. p2 = p[col + 16];
  15217. p3 = p[col + 24];
  15218. p4 = p[col + 32];
  15219. p5 = p[col + 40];
  15220. p6 = p[col + 48];
  15221. p7 = p[col + 56];
  15222. // check for all-zero AC coefficients
  15223. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  15224. t = dctSqrt2 * p0 + 8192 >> 14;
  15225. // convert to 8 bit
  15226. t = t < -2040 ? 0 : t >= 2024 ? 255 : t + 2056 >> 4;
  15227. blockData[blockBufferOffset + col] = t;
  15228. blockData[blockBufferOffset + col + 8] = t;
  15229. blockData[blockBufferOffset + col + 16] = t;
  15230. blockData[blockBufferOffset + col + 24] = t;
  15231. blockData[blockBufferOffset + col + 32] = t;
  15232. blockData[blockBufferOffset + col + 40] = t;
  15233. blockData[blockBufferOffset + col + 48] = t;
  15234. blockData[blockBufferOffset + col + 56] = t;
  15235. continue;
  15236. }
  15237. // stage 4
  15238. v0 = dctSqrt2 * p0 + 2048 >> 12;
  15239. v1 = dctSqrt2 * p4 + 2048 >> 12;
  15240. v2 = p2;
  15241. v3 = p6;
  15242. v4 = dctSqrt1d2 * (p1 - p7) + 2048 >> 12;
  15243. v7 = dctSqrt1d2 * (p1 + p7) + 2048 >> 12;
  15244. v5 = p3;
  15245. v6 = p5;
  15246. // stage 3
  15247. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  15248. // converting to UInt8 range later.
  15249. v0 = (v0 + v1 + 1 >> 1) + 4112;
  15250. v1 = v0 - v1;
  15251. t = v2 * dctSin6 + v3 * dctCos6 + 2048 >> 12;
  15252. v2 = v2 * dctCos6 - v3 * dctSin6 + 2048 >> 12;
  15253. v3 = t;
  15254. v4 = v4 + v6 + 1 >> 1;
  15255. v6 = v4 - v6;
  15256. v7 = v7 + v5 + 1 >> 1;
  15257. v5 = v7 - v5;
  15258. // stage 2
  15259. v0 = v0 + v3 + 1 >> 1;
  15260. v3 = v0 - v3;
  15261. v1 = v1 + v2 + 1 >> 1;
  15262. v2 = v1 - v2;
  15263. t = v4 * dctSin3 + v7 * dctCos3 + 2048 >> 12;
  15264. v4 = v4 * dctCos3 - v7 * dctSin3 + 2048 >> 12;
  15265. v7 = t;
  15266. t = v5 * dctSin1 + v6 * dctCos1 + 2048 >> 12;
  15267. v5 = v5 * dctCos1 - v6 * dctSin1 + 2048 >> 12;
  15268. v6 = t;
  15269. // stage 1
  15270. p0 = v0 + v7;
  15271. p7 = v0 - v7;
  15272. p1 = v1 + v6;
  15273. p6 = v1 - v6;
  15274. p2 = v2 + v5;
  15275. p5 = v2 - v5;
  15276. p3 = v3 + v4;
  15277. p4 = v3 - v4;
  15278. // convert to 8-bit integers
  15279. p0 = p0 < 16 ? 0 : p0 >= 4080 ? 255 : p0 >> 4;
  15280. p1 = p1 < 16 ? 0 : p1 >= 4080 ? 255 : p1 >> 4;
  15281. p2 = p2 < 16 ? 0 : p2 >= 4080 ? 255 : p2 >> 4;
  15282. p3 = p3 < 16 ? 0 : p3 >= 4080 ? 255 : p3 >> 4;
  15283. p4 = p4 < 16 ? 0 : p4 >= 4080 ? 255 : p4 >> 4;
  15284. p5 = p5 < 16 ? 0 : p5 >= 4080 ? 255 : p5 >> 4;
  15285. p6 = p6 < 16 ? 0 : p6 >= 4080 ? 255 : p6 >> 4;
  15286. p7 = p7 < 16 ? 0 : p7 >= 4080 ? 255 : p7 >> 4;
  15287. // store block data
  15288. blockData[blockBufferOffset + col] = p0;
  15289. blockData[blockBufferOffset + col + 8] = p1;
  15290. blockData[blockBufferOffset + col + 16] = p2;
  15291. blockData[blockBufferOffset + col + 24] = p3;
  15292. blockData[blockBufferOffset + col + 32] = p4;
  15293. blockData[blockBufferOffset + col + 40] = p5;
  15294. blockData[blockBufferOffset + col + 48] = p6;
  15295. blockData[blockBufferOffset + col + 56] = p7;
  15296. }
  15297. }
  15298. function buildComponentData(frame, component) {
  15299. var blocksPerLine = component.blocksPerLine;
  15300. var blocksPerColumn = component.blocksPerColumn;
  15301. var computationBuffer = new Int16Array(64);
  15302. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  15303. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  15304. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  15305. quantizeAndInverse(component, offset, computationBuffer);
  15306. }
  15307. }
  15308. return component.blockData;
  15309. }
  15310. function clamp0to255(a) {
  15311. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  15312. }
  15313. JpegImage.prototype = {
  15314. parse: function parse(data) {
  15315. function readUint16() {
  15316. var value = data[offset] << 8 | data[offset + 1];
  15317. offset += 2;
  15318. return value;
  15319. }
  15320. function readDataBlock() {
  15321. var length = readUint16();
  15322. var array = data.subarray(offset, offset + length - 2);
  15323. offset += array.length;
  15324. return array;
  15325. }
  15326. function prepareComponents(frame) {
  15327. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  15328. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  15329. for (var i = 0; i < frame.components.length; i++) {
  15330. component = frame.components[i];
  15331. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) * component.h / frame.maxH);
  15332. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) * component.v / frame.maxV);
  15333. var blocksPerLineForMcu = mcusPerLine * component.h;
  15334. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  15335. var blocksBufferSize = 64 * blocksPerColumnForMcu * (blocksPerLineForMcu + 1);
  15336. component.blockData = new Int16Array(blocksBufferSize);
  15337. component.blocksPerLine = blocksPerLine;
  15338. component.blocksPerColumn = blocksPerColumn;
  15339. }
  15340. frame.mcusPerLine = mcusPerLine;
  15341. frame.mcusPerColumn = mcusPerColumn;
  15342. }
  15343. var offset = 0;
  15344. var jfif = null;
  15345. var adobe = null;
  15346. var frame, resetInterval;
  15347. var quantizationTables = [];
  15348. var huffmanTablesAC = [], huffmanTablesDC = [];
  15349. var fileMarker = readUint16();
  15350. if (fileMarker !== 0xFFD8) {
  15351. // SOI (Start of Image)
  15352. error('JPEG error: SOI not found');
  15353. }
  15354. fileMarker = readUint16();
  15355. while (fileMarker !== 0xFFD9) {
  15356. // EOI (End of image)
  15357. var i, j, l;
  15358. switch (fileMarker) {
  15359. case 0xFFE0:
  15360. // APP0 (Application Specific)
  15361. case 0xFFE1:
  15362. // APP1
  15363. case 0xFFE2:
  15364. // APP2
  15365. case 0xFFE3:
  15366. // APP3
  15367. case 0xFFE4:
  15368. // APP4
  15369. case 0xFFE5:
  15370. // APP5
  15371. case 0xFFE6:
  15372. // APP6
  15373. case 0xFFE7:
  15374. // APP7
  15375. case 0xFFE8:
  15376. // APP8
  15377. case 0xFFE9:
  15378. // APP9
  15379. case 0xFFEA:
  15380. // APP10
  15381. case 0xFFEB:
  15382. // APP11
  15383. case 0xFFEC:
  15384. // APP12
  15385. case 0xFFED:
  15386. // APP13
  15387. case 0xFFEE:
  15388. // APP14
  15389. case 0xFFEF:
  15390. // APP15
  15391. case 0xFFFE:
  15392. // COM (Comment)
  15393. var appData = readDataBlock();
  15394. if (fileMarker === 0xFFE0) {
  15395. if (appData[0] === 0x4A && appData[1] === 0x46 && appData[2] === 0x49 && appData[3] === 0x46 && appData[4] === 0) {
  15396. // 'JFIF\x00'
  15397. jfif = {
  15398. version: {
  15399. major: appData[5],
  15400. minor: appData[6]
  15401. },
  15402. densityUnits: appData[7],
  15403. xDensity: appData[8] << 8 | appData[9],
  15404. yDensity: appData[10] << 8 | appData[11],
  15405. thumbWidth: appData[12],
  15406. thumbHeight: appData[13],
  15407. thumbData: appData.subarray(14, 14 + 3 * appData[12] * appData[13])
  15408. };
  15409. }
  15410. }
  15411. // TODO APP1 - Exif
  15412. if (fileMarker === 0xFFEE) {
  15413. if (appData[0] === 0x41 && appData[1] === 0x64 && appData[2] === 0x6F && appData[3] === 0x62 && appData[4] === 0x65) {
  15414. // 'Adobe'
  15415. adobe = {
  15416. version: appData[5] << 8 | appData[6],
  15417. flags0: appData[7] << 8 | appData[8],
  15418. flags1: appData[9] << 8 | appData[10],
  15419. transformCode: appData[11]
  15420. };
  15421. }
  15422. }
  15423. break;
  15424. case 0xFFDB:
  15425. // DQT (Define Quantization Tables)
  15426. var quantizationTablesLength = readUint16();
  15427. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  15428. var z;
  15429. while (offset < quantizationTablesEnd) {
  15430. var quantizationTableSpec = data[offset++];
  15431. var tableData = new Uint16Array(64);
  15432. if (quantizationTableSpec >> 4 === 0) {
  15433. // 8 bit values
  15434. for (j = 0; j < 64; j++) {
  15435. z = dctZigZag[j];
  15436. tableData[z] = data[offset++];
  15437. }
  15438. } else if (quantizationTableSpec >> 4 === 1) {
  15439. //16 bit
  15440. for (j = 0; j < 64; j++) {
  15441. z = dctZigZag[j];
  15442. tableData[z] = readUint16();
  15443. }
  15444. } else {
  15445. error('JPEG error: DQT - invalid table spec');
  15446. }
  15447. quantizationTables[quantizationTableSpec & 15] = tableData;
  15448. }
  15449. break;
  15450. case 0xFFC0:
  15451. // SOF0 (Start of Frame, Baseline DCT)
  15452. case 0xFFC1:
  15453. // SOF1 (Start of Frame, Extended DCT)
  15454. case 0xFFC2:
  15455. // SOF2 (Start of Frame, Progressive DCT)
  15456. if (frame) {
  15457. error('JPEG error: Only single frame JPEGs supported');
  15458. }
  15459. readUint16();
  15460. // skip data length
  15461. frame = {};
  15462. frame.extended = fileMarker === 0xFFC1;
  15463. frame.progressive = fileMarker === 0xFFC2;
  15464. frame.precision = data[offset++];
  15465. frame.scanLines = readUint16();
  15466. frame.samplesPerLine = readUint16();
  15467. frame.components = [];
  15468. frame.componentIds = {};
  15469. var componentsCount = data[offset++], componentId;
  15470. var maxH = 0, maxV = 0;
  15471. for (i = 0; i < componentsCount; i++) {
  15472. componentId = data[offset];
  15473. var h = data[offset + 1] >> 4;
  15474. var v = data[offset + 1] & 15;
  15475. if (maxH < h) {
  15476. maxH = h;
  15477. }
  15478. if (maxV < v) {
  15479. maxV = v;
  15480. }
  15481. var qId = data[offset + 2];
  15482. l = frame.components.push({
  15483. h: h,
  15484. v: v,
  15485. quantizationId: qId,
  15486. quantizationTable: null
  15487. });
  15488. // See comment below.
  15489. frame.componentIds[componentId] = l - 1;
  15490. offset += 3;
  15491. }
  15492. frame.maxH = maxH;
  15493. frame.maxV = maxV;
  15494. prepareComponents(frame);
  15495. break;
  15496. case 0xFFC4:
  15497. // DHT (Define Huffman Tables)
  15498. var huffmanLength = readUint16();
  15499. for (i = 2; i < huffmanLength;) {
  15500. var huffmanTableSpec = data[offset++];
  15501. var codeLengths = new Uint8Array(16);
  15502. var codeLengthSum = 0;
  15503. for (j = 0; j < 16; j++, offset++) {
  15504. codeLengthSum += codeLengths[j] = data[offset];
  15505. }
  15506. var huffmanValues = new Uint8Array(codeLengthSum);
  15507. for (j = 0; j < codeLengthSum; j++, offset++) {
  15508. huffmanValues[j] = data[offset];
  15509. }
  15510. i += 17 + codeLengthSum;
  15511. (huffmanTableSpec >> 4 === 0 ? huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] = buildHuffmanTable(codeLengths, huffmanValues);
  15512. }
  15513. break;
  15514. case 0xFFDD:
  15515. // DRI (Define Restart Interval)
  15516. readUint16();
  15517. // skip data length
  15518. resetInterval = readUint16();
  15519. break;
  15520. case 0xFFDA:
  15521. // SOS (Start of Scan)
  15522. var scanLength = readUint16();
  15523. var selectorsCount = data[offset++];
  15524. var components = [], component;
  15525. for (i = 0; i < selectorsCount; i++) {
  15526. var componentIndex = frame.componentIds[data[offset++]];
  15527. component = frame.components[componentIndex];
  15528. var tableSpec = data[offset++];
  15529. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  15530. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  15531. components.push(component);
  15532. }
  15533. var spectralStart = data[offset++];
  15534. var spectralEnd = data[offset++];
  15535. var successiveApproximation = data[offset++];
  15536. var processed = decodeScan(data, offset, frame, components, resetInterval, spectralStart, spectralEnd, successiveApproximation >> 4, successiveApproximation & 15);
  15537. offset += processed;
  15538. break;
  15539. case 0xFFFF:
  15540. // Fill bytes
  15541. if (data[offset] !== 0xFF) {
  15542. // Avoid skipping a valid marker.
  15543. offset--;
  15544. }
  15545. break;
  15546. default:
  15547. if (data[offset - 3] === 0xFF && data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  15548. // could be incorrect encoding -- last 0xFF byte of the previous
  15549. // block was eaten by the encoder
  15550. offset -= 3;
  15551. break;
  15552. }
  15553. error('JPEG error: unknown marker ' + fileMarker.toString(16));
  15554. }
  15555. fileMarker = readUint16();
  15556. }
  15557. this.width = frame.samplesPerLine;
  15558. this.height = frame.scanLines;
  15559. this.jfif = jfif;
  15560. this.adobe = adobe;
  15561. this.components = [];
  15562. for (i = 0; i < frame.components.length; i++) {
  15563. component = frame.components[i];
  15564. // Prevent errors when DQT markers are placed after SOF{n} markers,
  15565. // by assigning the `quantizationTable` entry after the entire image
  15566. // has been parsed (fixes issue7406.pdf).
  15567. var quantizationTable = quantizationTables[component.quantizationId];
  15568. if (quantizationTable) {
  15569. component.quantizationTable = quantizationTable;
  15570. }
  15571. this.components.push({
  15572. output: buildComponentData(frame, component),
  15573. scaleX: component.h / frame.maxH,
  15574. scaleY: component.v / frame.maxV,
  15575. blocksPerLine: component.blocksPerLine,
  15576. blocksPerColumn: component.blocksPerColumn
  15577. });
  15578. }
  15579. this.numComponents = this.components.length;
  15580. },
  15581. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  15582. var scaleX = this.width / width, scaleY = this.height / height;
  15583. var component, componentScaleX, componentScaleY, blocksPerScanline;
  15584. var x, y, i, j, k;
  15585. var index;
  15586. var offset = 0;
  15587. var output;
  15588. var numComponents = this.components.length;
  15589. var dataLength = width * height * numComponents;
  15590. var data = new Uint8Array(dataLength);
  15591. var xScaleBlockOffset = new Uint32Array(width);
  15592. var mask3LSB = 0xfffffff8;
  15593. // used to clear the 3 LSBs
  15594. for (i = 0; i < numComponents; i++) {
  15595. component = this.components[i];
  15596. componentScaleX = component.scaleX * scaleX;
  15597. componentScaleY = component.scaleY * scaleY;
  15598. offset = i;
  15599. output = component.output;
  15600. blocksPerScanline = component.blocksPerLine + 1 << 3;
  15601. // precalculate the xScaleBlockOffset
  15602. for (x = 0; x < width; x++) {
  15603. j = 0 | x * componentScaleX;
  15604. xScaleBlockOffset[x] = (j & mask3LSB) << 3 | j & 7;
  15605. }
  15606. // linearize the blocks of the component
  15607. for (y = 0; y < height; y++) {
  15608. j = 0 | y * componentScaleY;
  15609. index = blocksPerScanline * (j & mask3LSB) | (j & 7) << 3;
  15610. for (x = 0; x < width; x++) {
  15611. data[offset] = output[index + xScaleBlockOffset[x]];
  15612. offset += numComponents;
  15613. }
  15614. }
  15615. }
  15616. // decodeTransform contains pairs of multiplier (-256..256) and additive
  15617. var transform = this.decodeTransform;
  15618. if (transform) {
  15619. for (i = 0; i < dataLength;) {
  15620. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  15621. data[i] = (data[i] * transform[k] >> 8) + transform[k + 1];
  15622. }
  15623. }
  15624. }
  15625. return data;
  15626. },
  15627. _isColorConversionNeeded: function isColorConversionNeeded() {
  15628. if (this.adobe && this.adobe.transformCode) {
  15629. // The adobe transform marker overrides any previous setting
  15630. return true;
  15631. } else if (this.numComponents === 3) {
  15632. if (!this.adobe && this.colorTransform === 0) {
  15633. // If the Adobe transform marker is not present and the image
  15634. // dictionary has a 'ColorTransform' entry, explicitly set to `0`,
  15635. // then the colours should *not* be transformed.
  15636. return false;
  15637. }
  15638. return true;
  15639. } else {
  15640. // `this.numComponents !== 3`
  15641. if (!this.adobe && this.colorTransform === 1) {
  15642. // If the Adobe transform marker is not present and the image
  15643. // dictionary has a 'ColorTransform' entry, explicitly set to `1`,
  15644. // then the colours should be transformed.
  15645. return true;
  15646. }
  15647. return false;
  15648. }
  15649. },
  15650. _convertYccToRgb: function convertYccToRgb(data) {
  15651. var Y, Cb, Cr;
  15652. for (var i = 0, length = data.length; i < length; i += 3) {
  15653. Y = data[i];
  15654. Cb = data[i + 1];
  15655. Cr = data[i + 2];
  15656. data[i] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  15657. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  15658. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  15659. }
  15660. return data;
  15661. },
  15662. _convertYcckToRgb: function convertYcckToRgb(data) {
  15663. var Y, Cb, Cr, k;
  15664. var offset = 0;
  15665. for (var i = 0, length = data.length; i < length; i += 4) {
  15666. Y = data[i];
  15667. Cb = data[i + 1];
  15668. Cr = data[i + 2];
  15669. k = data[i + 3];
  15670. 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);
  15671. 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);
  15672. 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);
  15673. data[offset++] = clamp0to255(r);
  15674. data[offset++] = clamp0to255(g);
  15675. data[offset++] = clamp0to255(b);
  15676. }
  15677. return data;
  15678. },
  15679. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  15680. var Y, Cb, Cr;
  15681. for (var i = 0, length = data.length; i < length; i += 4) {
  15682. Y = data[i];
  15683. Cb = data[i + 1];
  15684. Cr = data[i + 2];
  15685. data[i] = clamp0to255(434.456 - Y - 1.402 * Cr);
  15686. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  15687. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  15688. }
  15689. // K in data[i + 3] is unchanged
  15690. return data;
  15691. },
  15692. _convertCmykToRgb: function convertCmykToRgb(data) {
  15693. var c, m, y, k;
  15694. var offset = 0;
  15695. var min = -255 * 255 * 255;
  15696. var scale = 1 / 255 / 255;
  15697. for (var i = 0, length = data.length; i < length; i += 4) {
  15698. c = data[i];
  15699. m = data[i + 1];
  15700. y = data[i + 2];
  15701. k = data[i + 3];
  15702. 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);
  15703. 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);
  15704. 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);
  15705. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  15706. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  15707. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  15708. }
  15709. return data;
  15710. },
  15711. getData: function getData(width, height, forceRGBoutput) {
  15712. if (this.numComponents > 4) {
  15713. error('JPEG error: Unsupported color mode');
  15714. }
  15715. // type of data: Uint8Array(width * height * numComponents)
  15716. var data = this._getLinearizedBlockData(width, height);
  15717. if (this.numComponents === 1 && forceRGBoutput) {
  15718. var dataLength = data.length;
  15719. var rgbData = new Uint8Array(dataLength * 3);
  15720. var offset = 0;
  15721. for (var i = 0; i < dataLength; i++) {
  15722. var grayColor = data[i];
  15723. rgbData[offset++] = grayColor;
  15724. rgbData[offset++] = grayColor;
  15725. rgbData[offset++] = grayColor;
  15726. }
  15727. return rgbData;
  15728. } else if (this.numComponents === 3 && this._isColorConversionNeeded()) {
  15729. return this._convertYccToRgb(data);
  15730. } else if (this.numComponents === 4) {
  15731. if (this._isColorConversionNeeded()) {
  15732. if (forceRGBoutput) {
  15733. return this._convertYcckToRgb(data);
  15734. } else {
  15735. return this._convertYcckToCmyk(data);
  15736. }
  15737. } else if (forceRGBoutput) {
  15738. return this._convertCmykToRgb(data);
  15739. }
  15740. }
  15741. return data;
  15742. }
  15743. };
  15744. return JpegImage;
  15745. }();
  15746. exports.JpegImage = JpegImage;
  15747. }));
  15748. (function (root, factory) {
  15749. factory(root.pdfjsCoreJpx = {}, root.pdfjsSharedUtil, root.pdfjsCoreArithmeticDecoder);
  15750. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  15751. var info = sharedUtil.info;
  15752. var warn = sharedUtil.warn;
  15753. var error = sharedUtil.error;
  15754. var log2 = sharedUtil.log2;
  15755. var readUint16 = sharedUtil.readUint16;
  15756. var readUint32 = sharedUtil.readUint32;
  15757. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  15758. var JpxImage = function JpxImageClosure() {
  15759. // Table E.1
  15760. var SubbandsGainLog2 = {
  15761. 'LL': 0,
  15762. 'LH': 1,
  15763. 'HL': 1,
  15764. 'HH': 2
  15765. };
  15766. function JpxImage() {
  15767. this.failOnCorruptedImage = false;
  15768. }
  15769. JpxImage.prototype = {
  15770. parse: function JpxImage_parse(data) {
  15771. var head = readUint16(data, 0);
  15772. // No box header, immediate start of codestream (SOC)
  15773. if (head === 0xFF4F) {
  15774. this.parseCodestream(data, 0, data.length);
  15775. return;
  15776. }
  15777. var position = 0, length = data.length;
  15778. while (position < length) {
  15779. var headerSize = 8;
  15780. var lbox = readUint32(data, position);
  15781. var tbox = readUint32(data, position + 4);
  15782. position += headerSize;
  15783. if (lbox === 1) {
  15784. // XLBox: read UInt64 according to spec.
  15785. // JavaScript's int precision of 53 bit should be sufficient here.
  15786. lbox = readUint32(data, position) * 4294967296 + readUint32(data, position + 4);
  15787. position += 8;
  15788. headerSize += 8;
  15789. }
  15790. if (lbox === 0) {
  15791. lbox = length - position + headerSize;
  15792. }
  15793. if (lbox < headerSize) {
  15794. error('JPX Error: Invalid box field size');
  15795. }
  15796. var dataLength = lbox - headerSize;
  15797. var jumpDataLength = true;
  15798. switch (tbox) {
  15799. case 0x6A703268:
  15800. // 'jp2h'
  15801. jumpDataLength = false;
  15802. // parsing child boxes
  15803. break;
  15804. case 0x636F6C72:
  15805. // 'colr'
  15806. // Colorspaces are not used, the CS from the PDF is used.
  15807. var method = data[position];
  15808. if (method === 1) {
  15809. // enumerated colorspace
  15810. var colorspace = readUint32(data, position + 3);
  15811. switch (colorspace) {
  15812. case 16:
  15813. // this indicates a sRGB colorspace
  15814. case 17:
  15815. // this indicates a grayscale colorspace
  15816. case 18:
  15817. // this indicates a YUV colorspace
  15818. break;
  15819. default:
  15820. warn('Unknown colorspace ' + colorspace);
  15821. break;
  15822. }
  15823. } else if (method === 2) {
  15824. info('ICC profile not supported');
  15825. }
  15826. break;
  15827. case 0x6A703263:
  15828. // 'jp2c'
  15829. this.parseCodestream(data, position, position + dataLength);
  15830. break;
  15831. case 0x6A502020:
  15832. // 'jP\024\024'
  15833. if (0x0d0a870a !== readUint32(data, position)) {
  15834. warn('Invalid JP2 signature');
  15835. }
  15836. break;
  15837. // The following header types are valid but currently not used:
  15838. case 0x6A501A1A:
  15839. // 'jP\032\032'
  15840. case 0x66747970:
  15841. // 'ftyp'
  15842. case 0x72726571:
  15843. // 'rreq'
  15844. case 0x72657320:
  15845. // 'res '
  15846. case 0x69686472:
  15847. // 'ihdr'
  15848. break;
  15849. default:
  15850. var headerType = String.fromCharCode(tbox >> 24 & 0xFF, tbox >> 16 & 0xFF, tbox >> 8 & 0xFF, tbox & 0xFF);
  15851. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  15852. break;
  15853. }
  15854. if (jumpDataLength) {
  15855. position += dataLength;
  15856. }
  15857. }
  15858. },
  15859. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  15860. var newByte = stream.getByte();
  15861. while (newByte >= 0) {
  15862. var oldByte = newByte;
  15863. newByte = stream.getByte();
  15864. var code = oldByte << 8 | newByte;
  15865. // Image and tile size (SIZ)
  15866. if (code === 0xFF51) {
  15867. stream.skip(4);
  15868. var Xsiz = stream.getInt32() >>> 0;
  15869. // Byte 4
  15870. var Ysiz = stream.getInt32() >>> 0;
  15871. // Byte 8
  15872. var XOsiz = stream.getInt32() >>> 0;
  15873. // Byte 12
  15874. var YOsiz = stream.getInt32() >>> 0;
  15875. // Byte 16
  15876. stream.skip(16);
  15877. var Csiz = stream.getUint16();
  15878. // Byte 36
  15879. this.width = Xsiz - XOsiz;
  15880. this.height = Ysiz - YOsiz;
  15881. this.componentsCount = Csiz;
  15882. // Results are always returned as Uint8Arrays
  15883. this.bitsPerComponent = 8;
  15884. return;
  15885. }
  15886. }
  15887. error('JPX Error: No size marker found in JPX stream');
  15888. },
  15889. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  15890. var context = {};
  15891. var doNotRecover = false;
  15892. try {
  15893. var position = start;
  15894. while (position + 1 < end) {
  15895. var code = readUint16(data, position);
  15896. position += 2;
  15897. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  15898. switch (code) {
  15899. case 0xFF4F:
  15900. // Start of codestream (SOC)
  15901. context.mainHeader = true;
  15902. break;
  15903. case 0xFFD9:
  15904. // End of codestream (EOC)
  15905. break;
  15906. case 0xFF51:
  15907. // Image and tile size (SIZ)
  15908. length = readUint16(data, position);
  15909. var siz = {};
  15910. siz.Xsiz = readUint32(data, position + 4);
  15911. siz.Ysiz = readUint32(data, position + 8);
  15912. siz.XOsiz = readUint32(data, position + 12);
  15913. siz.YOsiz = readUint32(data, position + 16);
  15914. siz.XTsiz = readUint32(data, position + 20);
  15915. siz.YTsiz = readUint32(data, position + 24);
  15916. siz.XTOsiz = readUint32(data, position + 28);
  15917. siz.YTOsiz = readUint32(data, position + 32);
  15918. var componentsCount = readUint16(data, position + 36);
  15919. siz.Csiz = componentsCount;
  15920. var components = [];
  15921. j = position + 38;
  15922. for (var i = 0; i < componentsCount; i++) {
  15923. var component = {
  15924. precision: (data[j] & 0x7F) + 1,
  15925. isSigned: !!(data[j] & 0x80),
  15926. XRsiz: data[j + 1],
  15927. YRsiz: data[j + 1]
  15928. };
  15929. calculateComponentDimensions(component, siz);
  15930. components.push(component);
  15931. }
  15932. context.SIZ = siz;
  15933. context.components = components;
  15934. calculateTileGrids(context, components);
  15935. context.QCC = [];
  15936. context.COC = [];
  15937. break;
  15938. case 0xFF5C:
  15939. // Quantization default (QCD)
  15940. length = readUint16(data, position);
  15941. var qcd = {};
  15942. j = position + 2;
  15943. sqcd = data[j++];
  15944. switch (sqcd & 0x1F) {
  15945. case 0:
  15946. spqcdSize = 8;
  15947. scalarExpounded = true;
  15948. break;
  15949. case 1:
  15950. spqcdSize = 16;
  15951. scalarExpounded = false;
  15952. break;
  15953. case 2:
  15954. spqcdSize = 16;
  15955. scalarExpounded = true;
  15956. break;
  15957. default:
  15958. throw new Error('Invalid SQcd value ' + sqcd);
  15959. }
  15960. qcd.noQuantization = spqcdSize === 8;
  15961. qcd.scalarExpounded = scalarExpounded;
  15962. qcd.guardBits = sqcd >> 5;
  15963. spqcds = [];
  15964. while (j < length + position) {
  15965. var spqcd = {};
  15966. if (spqcdSize === 8) {
  15967. spqcd.epsilon = data[j++] >> 3;
  15968. spqcd.mu = 0;
  15969. } else {
  15970. spqcd.epsilon = data[j] >> 3;
  15971. spqcd.mu = (data[j] & 0x7) << 8 | data[j + 1];
  15972. j += 2;
  15973. }
  15974. spqcds.push(spqcd);
  15975. }
  15976. qcd.SPqcds = spqcds;
  15977. if (context.mainHeader) {
  15978. context.QCD = qcd;
  15979. } else {
  15980. context.currentTile.QCD = qcd;
  15981. context.currentTile.QCC = [];
  15982. }
  15983. break;
  15984. case 0xFF5D:
  15985. // Quantization component (QCC)
  15986. length = readUint16(data, position);
  15987. var qcc = {};
  15988. j = position + 2;
  15989. var cqcc;
  15990. if (context.SIZ.Csiz < 257) {
  15991. cqcc = data[j++];
  15992. } else {
  15993. cqcc = readUint16(data, j);
  15994. j += 2;
  15995. }
  15996. sqcd = data[j++];
  15997. switch (sqcd & 0x1F) {
  15998. case 0:
  15999. spqcdSize = 8;
  16000. scalarExpounded = true;
  16001. break;
  16002. case 1:
  16003. spqcdSize = 16;
  16004. scalarExpounded = false;
  16005. break;
  16006. case 2:
  16007. spqcdSize = 16;
  16008. scalarExpounded = true;
  16009. break;
  16010. default:
  16011. throw new Error('Invalid SQcd value ' + sqcd);
  16012. }
  16013. qcc.noQuantization = spqcdSize === 8;
  16014. qcc.scalarExpounded = scalarExpounded;
  16015. qcc.guardBits = sqcd >> 5;
  16016. spqcds = [];
  16017. while (j < length + position) {
  16018. spqcd = {};
  16019. if (spqcdSize === 8) {
  16020. spqcd.epsilon = data[j++] >> 3;
  16021. spqcd.mu = 0;
  16022. } else {
  16023. spqcd.epsilon = data[j] >> 3;
  16024. spqcd.mu = (data[j] & 0x7) << 8 | data[j + 1];
  16025. j += 2;
  16026. }
  16027. spqcds.push(spqcd);
  16028. }
  16029. qcc.SPqcds = spqcds;
  16030. if (context.mainHeader) {
  16031. context.QCC[cqcc] = qcc;
  16032. } else {
  16033. context.currentTile.QCC[cqcc] = qcc;
  16034. }
  16035. break;
  16036. case 0xFF52:
  16037. // Coding style default (COD)
  16038. length = readUint16(data, position);
  16039. var cod = {};
  16040. j = position + 2;
  16041. var scod = data[j++];
  16042. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  16043. cod.sopMarkerUsed = !!(scod & 2);
  16044. cod.ephMarkerUsed = !!(scod & 4);
  16045. cod.progressionOrder = data[j++];
  16046. cod.layersCount = readUint16(data, j);
  16047. j += 2;
  16048. cod.multipleComponentTransform = data[j++];
  16049. cod.decompositionLevelsCount = data[j++];
  16050. cod.xcb = (data[j++] & 0xF) + 2;
  16051. cod.ycb = (data[j++] & 0xF) + 2;
  16052. var blockStyle = data[j++];
  16053. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  16054. cod.resetContextProbabilities = !!(blockStyle & 2);
  16055. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  16056. cod.verticalyStripe = !!(blockStyle & 8);
  16057. cod.predictableTermination = !!(blockStyle & 16);
  16058. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  16059. cod.reversibleTransformation = data[j++];
  16060. if (cod.entropyCoderWithCustomPrecincts) {
  16061. var precinctsSizes = [];
  16062. while (j < length + position) {
  16063. var precinctsSize = data[j++];
  16064. precinctsSizes.push({
  16065. PPx: precinctsSize & 0xF,
  16066. PPy: precinctsSize >> 4
  16067. });
  16068. }
  16069. cod.precinctsSizes = precinctsSizes;
  16070. }
  16071. var unsupported = [];
  16072. if (cod.selectiveArithmeticCodingBypass) {
  16073. unsupported.push('selectiveArithmeticCodingBypass');
  16074. }
  16075. if (cod.resetContextProbabilities) {
  16076. unsupported.push('resetContextProbabilities');
  16077. }
  16078. if (cod.terminationOnEachCodingPass) {
  16079. unsupported.push('terminationOnEachCodingPass');
  16080. }
  16081. if (cod.verticalyStripe) {
  16082. unsupported.push('verticalyStripe');
  16083. }
  16084. if (cod.predictableTermination) {
  16085. unsupported.push('predictableTermination');
  16086. }
  16087. if (unsupported.length > 0) {
  16088. doNotRecover = true;
  16089. throw new Error('Unsupported COD options (' + unsupported.join(', ') + ')');
  16090. }
  16091. if (context.mainHeader) {
  16092. context.COD = cod;
  16093. } else {
  16094. context.currentTile.COD = cod;
  16095. context.currentTile.COC = [];
  16096. }
  16097. break;
  16098. case 0xFF90:
  16099. // Start of tile-part (SOT)
  16100. length = readUint16(data, position);
  16101. tile = {};
  16102. tile.index = readUint16(data, position + 2);
  16103. tile.length = readUint32(data, position + 4);
  16104. tile.dataEnd = tile.length + position - 2;
  16105. tile.partIndex = data[position + 8];
  16106. tile.partsCount = data[position + 9];
  16107. context.mainHeader = false;
  16108. if (tile.partIndex === 0) {
  16109. // reset component specific settings
  16110. tile.COD = context.COD;
  16111. tile.COC = context.COC.slice(0);
  16112. // clone of the global COC
  16113. tile.QCD = context.QCD;
  16114. tile.QCC = context.QCC.slice(0);
  16115. }
  16116. // clone of the global COC
  16117. context.currentTile = tile;
  16118. break;
  16119. case 0xFF93:
  16120. // Start of data (SOD)
  16121. tile = context.currentTile;
  16122. if (tile.partIndex === 0) {
  16123. initializeTile(context, tile.index);
  16124. buildPackets(context);
  16125. }
  16126. // moving to the end of the data
  16127. length = tile.dataEnd - position;
  16128. parseTilePackets(context, data, position, length);
  16129. break;
  16130. case 0xFF55:
  16131. // Tile-part lengths, main header (TLM)
  16132. case 0xFF57:
  16133. // Packet length, main header (PLM)
  16134. case 0xFF58:
  16135. // Packet length, tile-part header (PLT)
  16136. case 0xFF64:
  16137. // Comment (COM)
  16138. length = readUint16(data, position);
  16139. // skipping content
  16140. break;
  16141. case 0xFF53:
  16142. // Coding style component (COC)
  16143. throw new Error('Codestream code 0xFF53 (COC) is ' + 'not implemented');
  16144. default:
  16145. throw new Error('Unknown codestream code: ' + code.toString(16));
  16146. }
  16147. position += length;
  16148. }
  16149. } catch (e) {
  16150. if (doNotRecover || this.failOnCorruptedImage) {
  16151. error('JPX Error: ' + e.message);
  16152. } else {
  16153. warn('JPX: Trying to recover from: ' + e.message);
  16154. }
  16155. }
  16156. this.tiles = transformComponents(context);
  16157. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  16158. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  16159. this.componentsCount = context.SIZ.Csiz;
  16160. }
  16161. };
  16162. function calculateComponentDimensions(component, siz) {
  16163. // Section B.2 Component mapping
  16164. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  16165. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  16166. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  16167. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  16168. component.width = component.x1 - component.x0;
  16169. component.height = component.y1 - component.y0;
  16170. }
  16171. function calculateTileGrids(context, components) {
  16172. var siz = context.SIZ;
  16173. // Section B.3 Division into tile and tile-components
  16174. var tile, tiles = [];
  16175. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  16176. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  16177. for (var q = 0; q < numYtiles; q++) {
  16178. for (var p = 0; p < numXtiles; p++) {
  16179. tile = {};
  16180. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  16181. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  16182. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  16183. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  16184. tile.width = tile.tx1 - tile.tx0;
  16185. tile.height = tile.ty1 - tile.ty0;
  16186. tile.components = [];
  16187. tiles.push(tile);
  16188. }
  16189. }
  16190. context.tiles = tiles;
  16191. var componentsCount = siz.Csiz;
  16192. for (var i = 0, ii = componentsCount; i < ii; i++) {
  16193. var component = components[i];
  16194. for (var j = 0, jj = tiles.length; j < jj; j++) {
  16195. var tileComponent = {};
  16196. tile = tiles[j];
  16197. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  16198. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  16199. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  16200. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  16201. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  16202. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  16203. tile.components[i] = tileComponent;
  16204. }
  16205. }
  16206. }
  16207. function getBlocksDimensions(context, component, r) {
  16208. var codOrCoc = component.codingStyleParameters;
  16209. var result = {};
  16210. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  16211. result.PPx = 15;
  16212. result.PPy = 15;
  16213. } else {
  16214. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  16215. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  16216. }
  16217. // calculate codeblock size as described in section B.7
  16218. result.xcb_ = r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) : Math.min(codOrCoc.xcb, result.PPx);
  16219. result.ycb_ = r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) : Math.min(codOrCoc.ycb, result.PPy);
  16220. return result;
  16221. }
  16222. function buildPrecincts(context, resolution, dimensions) {
  16223. // Section B.6 Division resolution to precincts
  16224. var precinctWidth = 1 << dimensions.PPx;
  16225. var precinctHeight = 1 << dimensions.PPy;
  16226. // Jasper introduces codeblock groups for mapping each subband codeblocks
  16227. // to precincts. Precinct partition divides a resolution according to width
  16228. // and height parameters. The subband that belongs to the resolution level
  16229. // has a different size than the level, unless it is the zero resolution.
  16230. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  16231. // The precinct partitioning for a particular subband is derived from a
  16232. // partitioning of its parent LL band (i.e., the LL band at the next higher
  16233. // resolution level)... The LL band associated with each resolution level is
  16234. // divided into precincts... Each of the resulting precinct regions is then
  16235. // mapped into its child subbands (if any) at the next lower resolution
  16236. // level. This is accomplished by using the coordinate transformation
  16237. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  16238. // coordinates of a point in the LL band and child subband, respectively.
  16239. var isZeroRes = resolution.resLevel === 0;
  16240. var precinctWidthInSubband = 1 << dimensions.PPx + (isZeroRes ? 0 : -1);
  16241. var precinctHeightInSubband = 1 << dimensions.PPy + (isZeroRes ? 0 : -1);
  16242. var numprecinctswide = resolution.trx1 > resolution.trx0 ? Math.ceil(resolution.trx1 / precinctWidth) - Math.floor(resolution.trx0 / precinctWidth) : 0;
  16243. var numprecinctshigh = resolution.try1 > resolution.try0 ? Math.ceil(resolution.try1 / precinctHeight) - Math.floor(resolution.try0 / precinctHeight) : 0;
  16244. var numprecincts = numprecinctswide * numprecinctshigh;
  16245. resolution.precinctParameters = {
  16246. precinctWidth: precinctWidth,
  16247. precinctHeight: precinctHeight,
  16248. numprecinctswide: numprecinctswide,
  16249. numprecinctshigh: numprecinctshigh,
  16250. numprecincts: numprecincts,
  16251. precinctWidthInSubband: precinctWidthInSubband,
  16252. precinctHeightInSubband: precinctHeightInSubband
  16253. };
  16254. }
  16255. function buildCodeblocks(context, subband, dimensions) {
  16256. // Section B.7 Division sub-band into code-blocks
  16257. var xcb_ = dimensions.xcb_;
  16258. var ycb_ = dimensions.ycb_;
  16259. var codeblockWidth = 1 << xcb_;
  16260. var codeblockHeight = 1 << ycb_;
  16261. var cbx0 = subband.tbx0 >> xcb_;
  16262. var cby0 = subband.tby0 >> ycb_;
  16263. var cbx1 = subband.tbx1 + codeblockWidth - 1 >> xcb_;
  16264. var cby1 = subband.tby1 + codeblockHeight - 1 >> ycb_;
  16265. var precinctParameters = subband.resolution.precinctParameters;
  16266. var codeblocks = [];
  16267. var precincts = [];
  16268. var i, j, codeblock, precinctNumber;
  16269. for (j = cby0; j < cby1; j++) {
  16270. for (i = cbx0; i < cbx1; i++) {
  16271. codeblock = {
  16272. cbx: i,
  16273. cby: j,
  16274. tbx0: codeblockWidth * i,
  16275. tby0: codeblockHeight * j,
  16276. tbx1: codeblockWidth * (i + 1),
  16277. tby1: codeblockHeight * (j + 1)
  16278. };
  16279. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  16280. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  16281. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  16282. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  16283. // Calculate precinct number for this codeblock, codeblock position
  16284. // should be relative to its subband, use actual dimension and position
  16285. // See comment about codeblock group width and height
  16286. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) / precinctParameters.precinctWidthInSubband);
  16287. var pj = Math.floor((codeblock.tby0_ - subband.tby0) / precinctParameters.precinctHeightInSubband);
  16288. precinctNumber = pi + pj * precinctParameters.numprecinctswide;
  16289. codeblock.precinctNumber = precinctNumber;
  16290. codeblock.subbandType = subband.type;
  16291. codeblock.Lblock = 3;
  16292. if (codeblock.tbx1_ <= codeblock.tbx0_ || codeblock.tby1_ <= codeblock.tby0_) {
  16293. continue;
  16294. }
  16295. codeblocks.push(codeblock);
  16296. // building precinct for the sub-band
  16297. var precinct = precincts[precinctNumber];
  16298. if (precinct !== undefined) {
  16299. if (i < precinct.cbxMin) {
  16300. precinct.cbxMin = i;
  16301. } else if (i > precinct.cbxMax) {
  16302. precinct.cbxMax = i;
  16303. }
  16304. if (j < precinct.cbyMin) {
  16305. precinct.cbxMin = j;
  16306. } else if (j > precinct.cbyMax) {
  16307. precinct.cbyMax = j;
  16308. }
  16309. } else {
  16310. precincts[precinctNumber] = precinct = {
  16311. cbxMin: i,
  16312. cbyMin: j,
  16313. cbxMax: i,
  16314. cbyMax: j
  16315. };
  16316. }
  16317. codeblock.precinct = precinct;
  16318. }
  16319. }
  16320. subband.codeblockParameters = {
  16321. codeblockWidth: xcb_,
  16322. codeblockHeight: ycb_,
  16323. numcodeblockwide: cbx1 - cbx0 + 1,
  16324. numcodeblockhigh: cby1 - cby0 + 1
  16325. };
  16326. subband.codeblocks = codeblocks;
  16327. subband.precincts = precincts;
  16328. }
  16329. function createPacket(resolution, precinctNumber, layerNumber) {
  16330. var precinctCodeblocks = [];
  16331. // Section B.10.8 Order of info in packet
  16332. var subbands = resolution.subbands;
  16333. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  16334. for (var i = 0, ii = subbands.length; i < ii; i++) {
  16335. var subband = subbands[i];
  16336. var codeblocks = subband.codeblocks;
  16337. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  16338. var codeblock = codeblocks[j];
  16339. if (codeblock.precinctNumber !== precinctNumber) {
  16340. continue;
  16341. }
  16342. precinctCodeblocks.push(codeblock);
  16343. }
  16344. }
  16345. return {
  16346. layerNumber: layerNumber,
  16347. codeblocks: precinctCodeblocks
  16348. };
  16349. }
  16350. function LayerResolutionComponentPositionIterator(context) {
  16351. var siz = context.SIZ;
  16352. var tileIndex = context.currentTile.index;
  16353. var tile = context.tiles[tileIndex];
  16354. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  16355. var componentsCount = siz.Csiz;
  16356. var maxDecompositionLevelsCount = 0;
  16357. for (var q = 0; q < componentsCount; q++) {
  16358. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, tile.components[q].codingStyleParameters.decompositionLevelsCount);
  16359. }
  16360. var l = 0, r = 0, i = 0, k = 0;
  16361. this.nextPacket = function JpxImage_nextPacket() {
  16362. // Section B.12.1.1 Layer-resolution-component-position
  16363. for (; l < layersCount; l++) {
  16364. for (; r <= maxDecompositionLevelsCount; r++) {
  16365. for (; i < componentsCount; i++) {
  16366. var component = tile.components[i];
  16367. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  16368. continue;
  16369. }
  16370. var resolution = component.resolutions[r];
  16371. var numprecincts = resolution.precinctParameters.numprecincts;
  16372. for (; k < numprecincts;) {
  16373. var packet = createPacket(resolution, k, l);
  16374. k++;
  16375. return packet;
  16376. }
  16377. k = 0;
  16378. }
  16379. i = 0;
  16380. }
  16381. r = 0;
  16382. }
  16383. error('JPX Error: Out of packets');
  16384. };
  16385. }
  16386. function ResolutionLayerComponentPositionIterator(context) {
  16387. var siz = context.SIZ;
  16388. var tileIndex = context.currentTile.index;
  16389. var tile = context.tiles[tileIndex];
  16390. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  16391. var componentsCount = siz.Csiz;
  16392. var maxDecompositionLevelsCount = 0;
  16393. for (var q = 0; q < componentsCount; q++) {
  16394. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, tile.components[q].codingStyleParameters.decompositionLevelsCount);
  16395. }
  16396. var r = 0, l = 0, i = 0, k = 0;
  16397. this.nextPacket = function JpxImage_nextPacket() {
  16398. // Section B.12.1.2 Resolution-layer-component-position
  16399. for (; r <= maxDecompositionLevelsCount; r++) {
  16400. for (; l < layersCount; l++) {
  16401. for (; i < componentsCount; i++) {
  16402. var component = tile.components[i];
  16403. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  16404. continue;
  16405. }
  16406. var resolution = component.resolutions[r];
  16407. var numprecincts = resolution.precinctParameters.numprecincts;
  16408. for (; k < numprecincts;) {
  16409. var packet = createPacket(resolution, k, l);
  16410. k++;
  16411. return packet;
  16412. }
  16413. k = 0;
  16414. }
  16415. i = 0;
  16416. }
  16417. l = 0;
  16418. }
  16419. error('JPX Error: Out of packets');
  16420. };
  16421. }
  16422. function ResolutionPositionComponentLayerIterator(context) {
  16423. var siz = context.SIZ;
  16424. var tileIndex = context.currentTile.index;
  16425. var tile = context.tiles[tileIndex];
  16426. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  16427. var componentsCount = siz.Csiz;
  16428. var l, r, c, p;
  16429. var maxDecompositionLevelsCount = 0;
  16430. for (c = 0; c < componentsCount; c++) {
  16431. var component = tile.components[c];
  16432. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, component.codingStyleParameters.decompositionLevelsCount);
  16433. }
  16434. var maxNumPrecinctsInLevel = new Int32Array(maxDecompositionLevelsCount + 1);
  16435. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  16436. var maxNumPrecincts = 0;
  16437. for (c = 0; c < componentsCount; ++c) {
  16438. var resolutions = tile.components[c].resolutions;
  16439. if (r < resolutions.length) {
  16440. maxNumPrecincts = Math.max(maxNumPrecincts, resolutions[r].precinctParameters.numprecincts);
  16441. }
  16442. }
  16443. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  16444. }
  16445. l = 0;
  16446. r = 0;
  16447. c = 0;
  16448. p = 0;
  16449. this.nextPacket = function JpxImage_nextPacket() {
  16450. // Section B.12.1.3 Resolution-position-component-layer
  16451. for (; r <= maxDecompositionLevelsCount; r++) {
  16452. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  16453. for (; c < componentsCount; c++) {
  16454. var component = tile.components[c];
  16455. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  16456. continue;
  16457. }
  16458. var resolution = component.resolutions[r];
  16459. var numprecincts = resolution.precinctParameters.numprecincts;
  16460. if (p >= numprecincts) {
  16461. continue;
  16462. }
  16463. for (; l < layersCount;) {
  16464. var packet = createPacket(resolution, p, l);
  16465. l++;
  16466. return packet;
  16467. }
  16468. l = 0;
  16469. }
  16470. c = 0;
  16471. }
  16472. p = 0;
  16473. }
  16474. error('JPX Error: Out of packets');
  16475. };
  16476. }
  16477. function PositionComponentResolutionLayerIterator(context) {
  16478. var siz = context.SIZ;
  16479. var tileIndex = context.currentTile.index;
  16480. var tile = context.tiles[tileIndex];
  16481. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  16482. var componentsCount = siz.Csiz;
  16483. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  16484. var precinctsIterationSizes = precinctsSizes;
  16485. var l = 0, r = 0, c = 0, px = 0, py = 0;
  16486. this.nextPacket = function JpxImage_nextPacket() {
  16487. // Section B.12.1.4 Position-component-resolution-layer
  16488. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  16489. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  16490. for (; c < componentsCount; c++) {
  16491. var component = tile.components[c];
  16492. var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
  16493. for (; r <= decompositionLevelsCount; r++) {
  16494. var resolution = component.resolutions[r];
  16495. var sizeInImageScale = precinctsSizes.components[c].resolutions[r];
  16496. var k = getPrecinctIndexIfExist(px, py, sizeInImageScale, precinctsIterationSizes, resolution);
  16497. if (k === null) {
  16498. continue;
  16499. }
  16500. for (; l < layersCount;) {
  16501. var packet = createPacket(resolution, k, l);
  16502. l++;
  16503. return packet;
  16504. }
  16505. l = 0;
  16506. }
  16507. r = 0;
  16508. }
  16509. c = 0;
  16510. }
  16511. px = 0;
  16512. }
  16513. error('JPX Error: Out of packets');
  16514. };
  16515. }
  16516. function ComponentPositionResolutionLayerIterator(context) {
  16517. var siz = context.SIZ;
  16518. var tileIndex = context.currentTile.index;
  16519. var tile = context.tiles[tileIndex];
  16520. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  16521. var componentsCount = siz.Csiz;
  16522. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  16523. var l = 0, r = 0, c = 0, px = 0, py = 0;
  16524. this.nextPacket = function JpxImage_nextPacket() {
  16525. // Section B.12.1.5 Component-position-resolution-layer
  16526. for (; c < componentsCount; ++c) {
  16527. var component = tile.components[c];
  16528. var precinctsIterationSizes = precinctsSizes.components[c];
  16529. var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
  16530. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  16531. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  16532. for (; r <= decompositionLevelsCount; r++) {
  16533. var resolution = component.resolutions[r];
  16534. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  16535. var k = getPrecinctIndexIfExist(px, py, sizeInImageScale, precinctsIterationSizes, resolution);
  16536. if (k === null) {
  16537. continue;
  16538. }
  16539. for (; l < layersCount;) {
  16540. var packet = createPacket(resolution, k, l);
  16541. l++;
  16542. return packet;
  16543. }
  16544. l = 0;
  16545. }
  16546. r = 0;
  16547. }
  16548. px = 0;
  16549. }
  16550. py = 0;
  16551. }
  16552. error('JPX Error: Out of packets');
  16553. };
  16554. }
  16555. function getPrecinctIndexIfExist(pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  16556. var posX = pxIndex * precinctIterationSizes.minWidth;
  16557. var posY = pyIndex * precinctIterationSizes.minHeight;
  16558. if (posX % sizeInImageScale.width !== 0 || posY % sizeInImageScale.height !== 0) {
  16559. return null;
  16560. }
  16561. var startPrecinctRowIndex = posY / sizeInImageScale.width * resolution.precinctParameters.numprecinctswide;
  16562. return posX / sizeInImageScale.height + startPrecinctRowIndex;
  16563. }
  16564. function getPrecinctSizesInImageScale(tile) {
  16565. var componentsCount = tile.components.length;
  16566. var minWidth = Number.MAX_VALUE;
  16567. var minHeight = Number.MAX_VALUE;
  16568. var maxNumWide = 0;
  16569. var maxNumHigh = 0;
  16570. var sizePerComponent = new Array(componentsCount);
  16571. for (var c = 0; c < componentsCount; c++) {
  16572. var component = tile.components[c];
  16573. var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
  16574. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  16575. var minWidthCurrentComponent = Number.MAX_VALUE;
  16576. var minHeightCurrentComponent = Number.MAX_VALUE;
  16577. var maxNumWideCurrentComponent = 0;
  16578. var maxNumHighCurrentComponent = 0;
  16579. var scale = 1;
  16580. for (var r = decompositionLevelsCount; r >= 0; --r) {
  16581. var resolution = component.resolutions[r];
  16582. var widthCurrentResolution = scale * resolution.precinctParameters.precinctWidth;
  16583. var heightCurrentResolution = scale * resolution.precinctParameters.precinctHeight;
  16584. minWidthCurrentComponent = Math.min(minWidthCurrentComponent, widthCurrentResolution);
  16585. minHeightCurrentComponent = Math.min(minHeightCurrentComponent, heightCurrentResolution);
  16586. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent, resolution.precinctParameters.numprecinctswide);
  16587. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent, resolution.precinctParameters.numprecinctshigh);
  16588. sizePerResolution[r] = {
  16589. width: widthCurrentResolution,
  16590. height: heightCurrentResolution
  16591. };
  16592. scale <<= 1;
  16593. }
  16594. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  16595. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  16596. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  16597. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  16598. sizePerComponent[c] = {
  16599. resolutions: sizePerResolution,
  16600. minWidth: minWidthCurrentComponent,
  16601. minHeight: minHeightCurrentComponent,
  16602. maxNumWide: maxNumWideCurrentComponent,
  16603. maxNumHigh: maxNumHighCurrentComponent
  16604. };
  16605. }
  16606. return {
  16607. components: sizePerComponent,
  16608. minWidth: minWidth,
  16609. minHeight: minHeight,
  16610. maxNumWide: maxNumWide,
  16611. maxNumHigh: maxNumHigh
  16612. };
  16613. }
  16614. function buildPackets(context) {
  16615. var siz = context.SIZ;
  16616. var tileIndex = context.currentTile.index;
  16617. var tile = context.tiles[tileIndex];
  16618. var componentsCount = siz.Csiz;
  16619. // Creating resolutions and sub-bands for each component
  16620. for (var c = 0; c < componentsCount; c++) {
  16621. var component = tile.components[c];
  16622. var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
  16623. // Section B.5 Resolution levels and sub-bands
  16624. var resolutions = [];
  16625. var subbands = [];
  16626. for (var r = 0; r <= decompositionLevelsCount; r++) {
  16627. var blocksDimensions = getBlocksDimensions(context, component, r);
  16628. var resolution = {};
  16629. var scale = 1 << decompositionLevelsCount - r;
  16630. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  16631. resolution.try0 = Math.ceil(component.tcy0 / scale);
  16632. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  16633. resolution.try1 = Math.ceil(component.tcy1 / scale);
  16634. resolution.resLevel = r;
  16635. buildPrecincts(context, resolution, blocksDimensions);
  16636. resolutions.push(resolution);
  16637. var subband;
  16638. if (r === 0) {
  16639. // one sub-band (LL) with last decomposition
  16640. subband = {};
  16641. subband.type = 'LL';
  16642. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  16643. subband.tby0 = Math.ceil(component.tcy0 / scale);
  16644. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  16645. subband.tby1 = Math.ceil(component.tcy1 / scale);
  16646. subband.resolution = resolution;
  16647. buildCodeblocks(context, subband, blocksDimensions);
  16648. subbands.push(subband);
  16649. resolution.subbands = [subband];
  16650. } else {
  16651. var bscale = 1 << decompositionLevelsCount - r + 1;
  16652. var resolutionSubbands = [];
  16653. // three sub-bands (HL, LH and HH) with rest of decompositions
  16654. subband = {};
  16655. subband.type = 'HL';
  16656. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  16657. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  16658. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  16659. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  16660. subband.resolution = resolution;
  16661. buildCodeblocks(context, subband, blocksDimensions);
  16662. subbands.push(subband);
  16663. resolutionSubbands.push(subband);
  16664. subband = {};
  16665. subband.type = 'LH';
  16666. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  16667. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  16668. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  16669. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  16670. subband.resolution = resolution;
  16671. buildCodeblocks(context, subband, blocksDimensions);
  16672. subbands.push(subband);
  16673. resolutionSubbands.push(subband);
  16674. subband = {};
  16675. subband.type = 'HH';
  16676. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  16677. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  16678. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  16679. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  16680. subband.resolution = resolution;
  16681. buildCodeblocks(context, subband, blocksDimensions);
  16682. subbands.push(subband);
  16683. resolutionSubbands.push(subband);
  16684. resolution.subbands = resolutionSubbands;
  16685. }
  16686. }
  16687. component.resolutions = resolutions;
  16688. component.subbands = subbands;
  16689. }
  16690. // Generate the packets sequence
  16691. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  16692. switch (progressionOrder) {
  16693. case 0:
  16694. tile.packetsIterator = new LayerResolutionComponentPositionIterator(context);
  16695. break;
  16696. case 1:
  16697. tile.packetsIterator = new ResolutionLayerComponentPositionIterator(context);
  16698. break;
  16699. case 2:
  16700. tile.packetsIterator = new ResolutionPositionComponentLayerIterator(context);
  16701. break;
  16702. case 3:
  16703. tile.packetsIterator = new PositionComponentResolutionLayerIterator(context);
  16704. break;
  16705. case 4:
  16706. tile.packetsIterator = new ComponentPositionResolutionLayerIterator(context);
  16707. break;
  16708. default:
  16709. error('JPX Error: Unsupported progression order ' + progressionOrder);
  16710. }
  16711. }
  16712. function parseTilePackets(context, data, offset, dataLength) {
  16713. var position = 0;
  16714. var buffer, bufferSize = 0, skipNextBit = false;
  16715. function readBits(count) {
  16716. while (bufferSize < count) {
  16717. var b = data[offset + position];
  16718. position++;
  16719. if (skipNextBit) {
  16720. buffer = buffer << 7 | b;
  16721. bufferSize += 7;
  16722. skipNextBit = false;
  16723. } else {
  16724. buffer = buffer << 8 | b;
  16725. bufferSize += 8;
  16726. }
  16727. if (b === 0xFF) {
  16728. skipNextBit = true;
  16729. }
  16730. }
  16731. bufferSize -= count;
  16732. return buffer >>> bufferSize & (1 << count) - 1;
  16733. }
  16734. function skipMarkerIfEqual(value) {
  16735. if (data[offset + position - 1] === 0xFF && data[offset + position] === value) {
  16736. skipBytes(1);
  16737. return true;
  16738. } else if (data[offset + position] === 0xFF && data[offset + position + 1] === value) {
  16739. skipBytes(2);
  16740. return true;
  16741. }
  16742. return false;
  16743. }
  16744. function skipBytes(count) {
  16745. position += count;
  16746. }
  16747. function alignToByte() {
  16748. bufferSize = 0;
  16749. if (skipNextBit) {
  16750. position++;
  16751. skipNextBit = false;
  16752. }
  16753. }
  16754. function readCodingpasses() {
  16755. if (readBits(1) === 0) {
  16756. return 1;
  16757. }
  16758. if (readBits(1) === 0) {
  16759. return 2;
  16760. }
  16761. var value = readBits(2);
  16762. if (value < 3) {
  16763. return value + 3;
  16764. }
  16765. value = readBits(5);
  16766. if (value < 31) {
  16767. return value + 6;
  16768. }
  16769. value = readBits(7);
  16770. return value + 37;
  16771. }
  16772. var tileIndex = context.currentTile.index;
  16773. var tile = context.tiles[tileIndex];
  16774. var sopMarkerUsed = context.COD.sopMarkerUsed;
  16775. var ephMarkerUsed = context.COD.ephMarkerUsed;
  16776. var packetsIterator = tile.packetsIterator;
  16777. while (position < dataLength) {
  16778. alignToByte();
  16779. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  16780. // Skip also marker segment length and packet sequence ID
  16781. skipBytes(4);
  16782. }
  16783. var packet = packetsIterator.nextPacket();
  16784. if (!readBits(1)) {
  16785. continue;
  16786. }
  16787. var layerNumber = packet.layerNumber;
  16788. var queue = [], codeblock;
  16789. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  16790. codeblock = packet.codeblocks[i];
  16791. var precinct = codeblock.precinct;
  16792. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  16793. var codeblockRow = codeblock.cby - precinct.cbyMin;
  16794. var codeblockIncluded = false;
  16795. var firstTimeInclusion = false;
  16796. var valueReady;
  16797. if (codeblock['included'] !== undefined) {
  16798. codeblockIncluded = !!readBits(1);
  16799. } else {
  16800. // reading inclusion tree
  16801. precinct = codeblock.precinct;
  16802. var inclusionTree, zeroBitPlanesTree;
  16803. if (precinct['inclusionTree'] !== undefined) {
  16804. inclusionTree = precinct.inclusionTree;
  16805. } else {
  16806. // building inclusion and zero bit-planes trees
  16807. var width = precinct.cbxMax - precinct.cbxMin + 1;
  16808. var height = precinct.cbyMax - precinct.cbyMin + 1;
  16809. inclusionTree = new InclusionTree(width, height, layerNumber);
  16810. zeroBitPlanesTree = new TagTree(width, height);
  16811. precinct.inclusionTree = inclusionTree;
  16812. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  16813. }
  16814. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  16815. while (true) {
  16816. if (readBits(1)) {
  16817. valueReady = !inclusionTree.nextLevel();
  16818. if (valueReady) {
  16819. codeblock.included = true;
  16820. codeblockIncluded = firstTimeInclusion = true;
  16821. break;
  16822. }
  16823. } else {
  16824. inclusionTree.incrementValue(layerNumber);
  16825. break;
  16826. }
  16827. }
  16828. }
  16829. }
  16830. if (!codeblockIncluded) {
  16831. continue;
  16832. }
  16833. if (firstTimeInclusion) {
  16834. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  16835. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  16836. while (true) {
  16837. if (readBits(1)) {
  16838. valueReady = !zeroBitPlanesTree.nextLevel();
  16839. if (valueReady) {
  16840. break;
  16841. }
  16842. } else {
  16843. zeroBitPlanesTree.incrementValue();
  16844. }
  16845. }
  16846. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  16847. }
  16848. var codingpasses = readCodingpasses();
  16849. while (readBits(1)) {
  16850. codeblock.Lblock++;
  16851. }
  16852. var codingpassesLog2 = log2(codingpasses);
  16853. // rounding down log2
  16854. var bits = (codingpasses < 1 << codingpassesLog2 ? codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  16855. var codedDataLength = readBits(bits);
  16856. queue.push({
  16857. codeblock: codeblock,
  16858. codingpasses: codingpasses,
  16859. dataLength: codedDataLength
  16860. });
  16861. }
  16862. alignToByte();
  16863. if (ephMarkerUsed) {
  16864. skipMarkerIfEqual(0x92);
  16865. }
  16866. while (queue.length > 0) {
  16867. var packetItem = queue.shift();
  16868. codeblock = packetItem.codeblock;
  16869. if (codeblock['data'] === undefined) {
  16870. codeblock.data = [];
  16871. }
  16872. codeblock.data.push({
  16873. data: data,
  16874. start: offset + position,
  16875. end: offset + position + packetItem.dataLength,
  16876. codingpasses: packetItem.codingpasses
  16877. });
  16878. position += packetItem.dataLength;
  16879. }
  16880. }
  16881. return position;
  16882. }
  16883. function copyCoefficients(coefficients, levelWidth, levelHeight, subband, delta, mb, reversible, segmentationSymbolUsed) {
  16884. var x0 = subband.tbx0;
  16885. var y0 = subband.tby0;
  16886. var width = subband.tbx1 - subband.tbx0;
  16887. var codeblocks = subband.codeblocks;
  16888. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  16889. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  16890. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  16891. var codeblock = codeblocks[i];
  16892. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  16893. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  16894. if (blockWidth === 0 || blockHeight === 0) {
  16895. continue;
  16896. }
  16897. if (codeblock['data'] === undefined) {
  16898. continue;
  16899. }
  16900. var bitModel, currentCodingpassType;
  16901. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType, codeblock.zeroBitPlanes, mb);
  16902. currentCodingpassType = 2;
  16903. // first bit plane starts from cleanup
  16904. // collect data
  16905. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  16906. var j, jj, dataItem;
  16907. for (j = 0, jj = data.length; j < jj; j++) {
  16908. dataItem = data[j];
  16909. totalLength += dataItem.end - dataItem.start;
  16910. codingpasses += dataItem.codingpasses;
  16911. }
  16912. var encodedData = new Uint8Array(totalLength);
  16913. var position = 0;
  16914. for (j = 0, jj = data.length; j < jj; j++) {
  16915. dataItem = data[j];
  16916. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  16917. encodedData.set(chunk, position);
  16918. position += chunk.length;
  16919. }
  16920. // decoding the item
  16921. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  16922. bitModel.setDecoder(decoder);
  16923. for (j = 0; j < codingpasses; j++) {
  16924. switch (currentCodingpassType) {
  16925. case 0:
  16926. bitModel.runSignificancePropagationPass();
  16927. break;
  16928. case 1:
  16929. bitModel.runMagnitudeRefinementPass();
  16930. break;
  16931. case 2:
  16932. bitModel.runCleanupPass();
  16933. if (segmentationSymbolUsed) {
  16934. bitModel.checkSegmentationSymbol();
  16935. }
  16936. break;
  16937. }
  16938. currentCodingpassType = (currentCodingpassType + 1) % 3;
  16939. }
  16940. var offset = codeblock.tbx0_ - x0 + (codeblock.tby0_ - y0) * width;
  16941. var sign = bitModel.coefficentsSign;
  16942. var magnitude = bitModel.coefficentsMagnitude;
  16943. var bitsDecoded = bitModel.bitsDecoded;
  16944. var magnitudeCorrection = reversible ? 0 : 0.5;
  16945. var k, n, nb;
  16946. position = 0;
  16947. // Do the interleaving of Section F.3.3 here, so we do not need
  16948. // to copy later. LL level is not interleaved, just copied.
  16949. var interleave = subband.type !== 'LL';
  16950. for (j = 0; j < blockHeight; j++) {
  16951. var row = offset / width | 0;
  16952. // row in the non-interleaved subband
  16953. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  16954. for (k = 0; k < blockWidth; k++) {
  16955. n = magnitude[position];
  16956. if (n !== 0) {
  16957. n = (n + magnitudeCorrection) * delta;
  16958. if (sign[position] !== 0) {
  16959. n = -n;
  16960. }
  16961. nb = bitsDecoded[position];
  16962. var pos = interleave ? levelOffset + (offset << 1) : offset;
  16963. if (reversible && nb >= mb) {
  16964. coefficients[pos] = n;
  16965. } else {
  16966. coefficients[pos] = n * (1 << mb - nb);
  16967. }
  16968. }
  16969. offset++;
  16970. position++;
  16971. }
  16972. offset += width - blockWidth;
  16973. }
  16974. }
  16975. }
  16976. function transformTile(context, tile, c) {
  16977. var component = tile.components[c];
  16978. var codingStyleParameters = component.codingStyleParameters;
  16979. var quantizationParameters = component.quantizationParameters;
  16980. var decompositionLevelsCount = codingStyleParameters.decompositionLevelsCount;
  16981. var spqcds = quantizationParameters.SPqcds;
  16982. var scalarExpounded = quantizationParameters.scalarExpounded;
  16983. var guardBits = quantizationParameters.guardBits;
  16984. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  16985. var precision = context.components[c].precision;
  16986. var reversible = codingStyleParameters.reversibleTransformation;
  16987. var transform = reversible ? new ReversibleTransform() : new IrreversibleTransform();
  16988. var subbandCoefficients = [];
  16989. var b = 0;
  16990. for (var i = 0; i <= decompositionLevelsCount; i++) {
  16991. var resolution = component.resolutions[i];
  16992. var width = resolution.trx1 - resolution.trx0;
  16993. var height = resolution.try1 - resolution.try0;
  16994. // Allocate space for the whole sublevel.
  16995. var coefficients = new Float32Array(width * height);
  16996. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  16997. var mu, epsilon;
  16998. if (!scalarExpounded) {
  16999. // formula E-5
  17000. mu = spqcds[0].mu;
  17001. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  17002. } else {
  17003. mu = spqcds[b].mu;
  17004. epsilon = spqcds[b].epsilon;
  17005. b++;
  17006. }
  17007. var subband = resolution.subbands[j];
  17008. var gainLog2 = SubbandsGainLog2[subband.type];
  17009. // calculate quantization coefficient (Section E.1.1.1)
  17010. var delta = reversible ? 1 : Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048);
  17011. var mb = guardBits + epsilon - 1;
  17012. // In the first resolution level, copyCoefficients will fill the
  17013. // whole array with coefficients. In the succeeding passes,
  17014. // copyCoefficients will consecutively fill in the values that belong
  17015. // to the interleaved positions of the HL, LH, and HH coefficients.
  17016. // The LL coefficients will then be interleaved in Transform.iterate().
  17017. copyCoefficients(coefficients, width, height, subband, delta, mb, reversible, segmentationSymbolUsed);
  17018. }
  17019. subbandCoefficients.push({
  17020. width: width,
  17021. height: height,
  17022. items: coefficients
  17023. });
  17024. }
  17025. var result = transform.calculate(subbandCoefficients, component.tcx0, component.tcy0);
  17026. return {
  17027. left: component.tcx0,
  17028. top: component.tcy0,
  17029. width: result.width,
  17030. height: result.height,
  17031. items: result.items
  17032. };
  17033. }
  17034. function transformComponents(context) {
  17035. var siz = context.SIZ;
  17036. var components = context.components;
  17037. var componentsCount = siz.Csiz;
  17038. var resultImages = [];
  17039. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  17040. var tile = context.tiles[i];
  17041. var transformedTiles = [];
  17042. var c;
  17043. for (c = 0; c < componentsCount; c++) {
  17044. transformedTiles[c] = transformTile(context, tile, c);
  17045. }
  17046. var tile0 = transformedTiles[0];
  17047. var out = new Uint8Array(tile0.items.length * componentsCount);
  17048. var result = {
  17049. left: tile0.left,
  17050. top: tile0.top,
  17051. width: tile0.width,
  17052. height: tile0.height,
  17053. items: out
  17054. };
  17055. // Section G.2.2 Inverse multi component transform
  17056. var shift, offset, max, min, maxK;
  17057. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  17058. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  17059. var fourComponents = componentsCount === 4;
  17060. var y0items = transformedTiles[0].items;
  17061. var y1items = transformedTiles[1].items;
  17062. var y2items = transformedTiles[2].items;
  17063. var y3items = fourComponents ? transformedTiles[3].items : null;
  17064. // HACK: The multiple component transform formulas below assume that
  17065. // all components have the same precision. With this in mind, we
  17066. // compute shift and offset only once.
  17067. shift = components[0].precision - 8;
  17068. offset = (128 << shift) + 0.5;
  17069. max = 255 * (1 << shift);
  17070. maxK = max * 0.5;
  17071. min = -maxK;
  17072. var component0 = tile.components[0];
  17073. var alpha01 = componentsCount - 3;
  17074. jj = y0items.length;
  17075. if (!component0.codingStyleParameters.reversibleTransformation) {
  17076. // inverse irreversible multiple component transform
  17077. for (j = 0; j < jj; j++, pos += alpha01) {
  17078. y0 = y0items[j] + offset;
  17079. y1 = y1items[j];
  17080. y2 = y2items[j];
  17081. r = y0 + 1.402 * y2;
  17082. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  17083. b = y0 + 1.772 * y1;
  17084. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  17085. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  17086. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  17087. }
  17088. } else {
  17089. // inverse reversible multiple component transform
  17090. for (j = 0; j < jj; j++, pos += alpha01) {
  17091. y0 = y0items[j] + offset;
  17092. y1 = y1items[j];
  17093. y2 = y2items[j];
  17094. g = y0 - (y2 + y1 >> 2);
  17095. r = g + y2;
  17096. b = g + y1;
  17097. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  17098. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  17099. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  17100. }
  17101. }
  17102. if (fourComponents) {
  17103. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  17104. k = y3items[j];
  17105. out[pos] = k <= min ? 0 : k >= maxK ? 255 : k + offset >> shift;
  17106. }
  17107. }
  17108. } else {
  17109. // no multi-component transform
  17110. for (c = 0; c < componentsCount; c++) {
  17111. var items = transformedTiles[c].items;
  17112. shift = components[c].precision - 8;
  17113. offset = (128 << shift) + 0.5;
  17114. max = 127.5 * (1 << shift);
  17115. min = -max;
  17116. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  17117. val = items[j];
  17118. out[pos] = val <= min ? 0 : val >= max ? 255 : val + offset >> shift;
  17119. pos += componentsCount;
  17120. }
  17121. }
  17122. }
  17123. resultImages.push(result);
  17124. }
  17125. return resultImages;
  17126. }
  17127. function initializeTile(context, tileIndex) {
  17128. var siz = context.SIZ;
  17129. var componentsCount = siz.Csiz;
  17130. var tile = context.tiles[tileIndex];
  17131. for (var c = 0; c < componentsCount; c++) {
  17132. var component = tile.components[c];
  17133. var qcdOrQcc = context.currentTile.QCC[c] !== undefined ? context.currentTile.QCC[c] : context.currentTile.QCD;
  17134. component.quantizationParameters = qcdOrQcc;
  17135. var codOrCoc = context.currentTile.COC[c] !== undefined ? context.currentTile.COC[c] : context.currentTile.COD;
  17136. component.codingStyleParameters = codOrCoc;
  17137. }
  17138. tile.codingStyleDefaultParameters = context.currentTile.COD;
  17139. }
  17140. // Section B.10.2 Tag trees
  17141. var TagTree = function TagTreeClosure() {
  17142. function TagTree(width, height) {
  17143. var levelsLength = log2(Math.max(width, height)) + 1;
  17144. this.levels = [];
  17145. for (var i = 0; i < levelsLength; i++) {
  17146. var level = {
  17147. width: width,
  17148. height: height,
  17149. items: []
  17150. };
  17151. this.levels.push(level);
  17152. width = Math.ceil(width / 2);
  17153. height = Math.ceil(height / 2);
  17154. }
  17155. }
  17156. TagTree.prototype = {
  17157. reset: function TagTree_reset(i, j) {
  17158. var currentLevel = 0, value = 0, level;
  17159. while (currentLevel < this.levels.length) {
  17160. level = this.levels[currentLevel];
  17161. var index = i + j * level.width;
  17162. if (level.items[index] !== undefined) {
  17163. value = level.items[index];
  17164. break;
  17165. }
  17166. level.index = index;
  17167. i >>= 1;
  17168. j >>= 1;
  17169. currentLevel++;
  17170. }
  17171. currentLevel--;
  17172. level = this.levels[currentLevel];
  17173. level.items[level.index] = value;
  17174. this.currentLevel = currentLevel;
  17175. delete this.value;
  17176. },
  17177. incrementValue: function TagTree_incrementValue() {
  17178. var level = this.levels[this.currentLevel];
  17179. level.items[level.index]++;
  17180. },
  17181. nextLevel: function TagTree_nextLevel() {
  17182. var currentLevel = this.currentLevel;
  17183. var level = this.levels[currentLevel];
  17184. var value = level.items[level.index];
  17185. currentLevel--;
  17186. if (currentLevel < 0) {
  17187. this.value = value;
  17188. return false;
  17189. }
  17190. this.currentLevel = currentLevel;
  17191. level = this.levels[currentLevel];
  17192. level.items[level.index] = value;
  17193. return true;
  17194. }
  17195. };
  17196. return TagTree;
  17197. }();
  17198. var InclusionTree = function InclusionTreeClosure() {
  17199. function InclusionTree(width, height, defaultValue) {
  17200. var levelsLength = log2(Math.max(width, height)) + 1;
  17201. this.levels = [];
  17202. for (var i = 0; i < levelsLength; i++) {
  17203. var items = new Uint8Array(width * height);
  17204. for (var j = 0, jj = items.length; j < jj; j++) {
  17205. items[j] = defaultValue;
  17206. }
  17207. var level = {
  17208. width: width,
  17209. height: height,
  17210. items: items
  17211. };
  17212. this.levels.push(level);
  17213. width = Math.ceil(width / 2);
  17214. height = Math.ceil(height / 2);
  17215. }
  17216. }
  17217. InclusionTree.prototype = {
  17218. reset: function InclusionTree_reset(i, j, stopValue) {
  17219. var currentLevel = 0;
  17220. while (currentLevel < this.levels.length) {
  17221. var level = this.levels[currentLevel];
  17222. var index = i + j * level.width;
  17223. level.index = index;
  17224. var value = level.items[index];
  17225. if (value === 0xFF) {
  17226. break;
  17227. }
  17228. if (value > stopValue) {
  17229. this.currentLevel = currentLevel;
  17230. // already know about this one, propagating the value to top levels
  17231. this.propagateValues();
  17232. return false;
  17233. }
  17234. i >>= 1;
  17235. j >>= 1;
  17236. currentLevel++;
  17237. }
  17238. this.currentLevel = currentLevel - 1;
  17239. return true;
  17240. },
  17241. incrementValue: function InclusionTree_incrementValue(stopValue) {
  17242. var level = this.levels[this.currentLevel];
  17243. level.items[level.index] = stopValue + 1;
  17244. this.propagateValues();
  17245. },
  17246. propagateValues: function InclusionTree_propagateValues() {
  17247. var levelIndex = this.currentLevel;
  17248. var level = this.levels[levelIndex];
  17249. var currentValue = level.items[level.index];
  17250. while (--levelIndex >= 0) {
  17251. level = this.levels[levelIndex];
  17252. level.items[level.index] = currentValue;
  17253. }
  17254. },
  17255. nextLevel: function InclusionTree_nextLevel() {
  17256. var currentLevel = this.currentLevel;
  17257. var level = this.levels[currentLevel];
  17258. var value = level.items[level.index];
  17259. level.items[level.index] = 0xFF;
  17260. currentLevel--;
  17261. if (currentLevel < 0) {
  17262. return false;
  17263. }
  17264. this.currentLevel = currentLevel;
  17265. level = this.levels[currentLevel];
  17266. level.items[level.index] = value;
  17267. return true;
  17268. }
  17269. };
  17270. return InclusionTree;
  17271. }();
  17272. // Section D. Coefficient bit modeling
  17273. var BitModel = function BitModelClosure() {
  17274. var UNIFORM_CONTEXT = 17;
  17275. var RUNLENGTH_CONTEXT = 18;
  17276. // Table D-1
  17277. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  17278. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  17279. var LLAndLHContextsLabel = new Uint8Array([
  17280. 0,
  17281. 5,
  17282. 8,
  17283. 0,
  17284. 3,
  17285. 7,
  17286. 8,
  17287. 0,
  17288. 4,
  17289. 7,
  17290. 8,
  17291. 0,
  17292. 0,
  17293. 0,
  17294. 0,
  17295. 0,
  17296. 1,
  17297. 6,
  17298. 8,
  17299. 0,
  17300. 3,
  17301. 7,
  17302. 8,
  17303. 0,
  17304. 4,
  17305. 7,
  17306. 8,
  17307. 0,
  17308. 0,
  17309. 0,
  17310. 0,
  17311. 0,
  17312. 2,
  17313. 6,
  17314. 8,
  17315. 0,
  17316. 3,
  17317. 7,
  17318. 8,
  17319. 0,
  17320. 4,
  17321. 7,
  17322. 8,
  17323. 0,
  17324. 0,
  17325. 0,
  17326. 0,
  17327. 0,
  17328. 2,
  17329. 6,
  17330. 8,
  17331. 0,
  17332. 3,
  17333. 7,
  17334. 8,
  17335. 0,
  17336. 4,
  17337. 7,
  17338. 8,
  17339. 0,
  17340. 0,
  17341. 0,
  17342. 0,
  17343. 0,
  17344. 2,
  17345. 6,
  17346. 8,
  17347. 0,
  17348. 3,
  17349. 7,
  17350. 8,
  17351. 0,
  17352. 4,
  17353. 7,
  17354. 8
  17355. ]);
  17356. var HLContextLabel = new Uint8Array([
  17357. 0,
  17358. 3,
  17359. 4,
  17360. 0,
  17361. 5,
  17362. 7,
  17363. 7,
  17364. 0,
  17365. 8,
  17366. 8,
  17367. 8,
  17368. 0,
  17369. 0,
  17370. 0,
  17371. 0,
  17372. 0,
  17373. 1,
  17374. 3,
  17375. 4,
  17376. 0,
  17377. 6,
  17378. 7,
  17379. 7,
  17380. 0,
  17381. 8,
  17382. 8,
  17383. 8,
  17384. 0,
  17385. 0,
  17386. 0,
  17387. 0,
  17388. 0,
  17389. 2,
  17390. 3,
  17391. 4,
  17392. 0,
  17393. 6,
  17394. 7,
  17395. 7,
  17396. 0,
  17397. 8,
  17398. 8,
  17399. 8,
  17400. 0,
  17401. 0,
  17402. 0,
  17403. 0,
  17404. 0,
  17405. 2,
  17406. 3,
  17407. 4,
  17408. 0,
  17409. 6,
  17410. 7,
  17411. 7,
  17412. 0,
  17413. 8,
  17414. 8,
  17415. 8,
  17416. 0,
  17417. 0,
  17418. 0,
  17419. 0,
  17420. 0,
  17421. 2,
  17422. 3,
  17423. 4,
  17424. 0,
  17425. 6,
  17426. 7,
  17427. 7,
  17428. 0,
  17429. 8,
  17430. 8,
  17431. 8
  17432. ]);
  17433. var HHContextLabel = new Uint8Array([
  17434. 0,
  17435. 1,
  17436. 2,
  17437. 0,
  17438. 1,
  17439. 2,
  17440. 2,
  17441. 0,
  17442. 2,
  17443. 2,
  17444. 2,
  17445. 0,
  17446. 0,
  17447. 0,
  17448. 0,
  17449. 0,
  17450. 3,
  17451. 4,
  17452. 5,
  17453. 0,
  17454. 4,
  17455. 5,
  17456. 5,
  17457. 0,
  17458. 5,
  17459. 5,
  17460. 5,
  17461. 0,
  17462. 0,
  17463. 0,
  17464. 0,
  17465. 0,
  17466. 6,
  17467. 7,
  17468. 7,
  17469. 0,
  17470. 7,
  17471. 7,
  17472. 7,
  17473. 0,
  17474. 7,
  17475. 7,
  17476. 7,
  17477. 0,
  17478. 0,
  17479. 0,
  17480. 0,
  17481. 0,
  17482. 8,
  17483. 8,
  17484. 8,
  17485. 0,
  17486. 8,
  17487. 8,
  17488. 8,
  17489. 0,
  17490. 8,
  17491. 8,
  17492. 8,
  17493. 0,
  17494. 0,
  17495. 0,
  17496. 0,
  17497. 0,
  17498. 8,
  17499. 8,
  17500. 8,
  17501. 0,
  17502. 8,
  17503. 8,
  17504. 8,
  17505. 0,
  17506. 8,
  17507. 8,
  17508. 8
  17509. ]);
  17510. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  17511. this.width = width;
  17512. this.height = height;
  17513. this.contextLabelTable = subband === 'HH' ? HHContextLabel : subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel;
  17514. var coefficientCount = width * height;
  17515. // coefficients outside the encoding region treated as insignificant
  17516. // add border state cells for significanceState
  17517. this.neighborsSignificance = new Uint8Array(coefficientCount);
  17518. this.coefficentsSign = new Uint8Array(coefficientCount);
  17519. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) : mb > 6 ? new Uint16Array(coefficientCount) : new Uint8Array(coefficientCount);
  17520. this.processingFlags = new Uint8Array(coefficientCount);
  17521. var bitsDecoded = new Uint8Array(coefficientCount);
  17522. if (zeroBitPlanes !== 0) {
  17523. for (var i = 0; i < coefficientCount; i++) {
  17524. bitsDecoded[i] = zeroBitPlanes;
  17525. }
  17526. }
  17527. this.bitsDecoded = bitsDecoded;
  17528. this.reset();
  17529. }
  17530. BitModel.prototype = {
  17531. setDecoder: function BitModel_setDecoder(decoder) {
  17532. this.decoder = decoder;
  17533. },
  17534. reset: function BitModel_reset() {
  17535. // We have 17 contexts that are accessed via context labels,
  17536. // plus the uniform and runlength context.
  17537. this.contexts = new Int8Array(19);
  17538. // Contexts are packed into 1 byte:
  17539. // highest 7 bits carry the index, lowest bit carries mps
  17540. this.contexts[0] = 4 << 1 | 0;
  17541. this.contexts[UNIFORM_CONTEXT] = 46 << 1 | 0;
  17542. this.contexts[RUNLENGTH_CONTEXT] = 3 << 1 | 0;
  17543. },
  17544. setNeighborsSignificance: function BitModel_setNeighborsSignificance(row, column, index) {
  17545. var neighborsSignificance = this.neighborsSignificance;
  17546. var width = this.width, height = this.height;
  17547. var left = column > 0;
  17548. var right = column + 1 < width;
  17549. var i;
  17550. if (row > 0) {
  17551. i = index - width;
  17552. if (left) {
  17553. neighborsSignificance[i - 1] += 0x10;
  17554. }
  17555. if (right) {
  17556. neighborsSignificance[i + 1] += 0x10;
  17557. }
  17558. neighborsSignificance[i] += 0x04;
  17559. }
  17560. if (row + 1 < height) {
  17561. i = index + width;
  17562. if (left) {
  17563. neighborsSignificance[i - 1] += 0x10;
  17564. }
  17565. if (right) {
  17566. neighborsSignificance[i + 1] += 0x10;
  17567. }
  17568. neighborsSignificance[i] += 0x04;
  17569. }
  17570. if (left) {
  17571. neighborsSignificance[index - 1] += 0x01;
  17572. }
  17573. if (right) {
  17574. neighborsSignificance[index + 1] += 0x01;
  17575. }
  17576. neighborsSignificance[index] |= 0x80;
  17577. },
  17578. runSignificancePropagationPass: function BitModel_runSignificancePropagationPass() {
  17579. var decoder = this.decoder;
  17580. var width = this.width, height = this.height;
  17581. var coefficentsMagnitude = this.coefficentsMagnitude;
  17582. var coefficentsSign = this.coefficentsSign;
  17583. var neighborsSignificance = this.neighborsSignificance;
  17584. var processingFlags = this.processingFlags;
  17585. var contexts = this.contexts;
  17586. var labels = this.contextLabelTable;
  17587. var bitsDecoded = this.bitsDecoded;
  17588. var processedInverseMask = ~1;
  17589. var processedMask = 1;
  17590. var firstMagnitudeBitMask = 2;
  17591. for (var i0 = 0; i0 < height; i0 += 4) {
  17592. for (var j = 0; j < width; j++) {
  17593. var index = i0 * width + j;
  17594. for (var i1 = 0; i1 < 4; i1++, index += width) {
  17595. var i = i0 + i1;
  17596. if (i >= height) {
  17597. break;
  17598. }
  17599. // clear processed flag first
  17600. processingFlags[index] &= processedInverseMask;
  17601. if (coefficentsMagnitude[index] || !neighborsSignificance[index]) {
  17602. continue;
  17603. }
  17604. var contextLabel = labels[neighborsSignificance[index]];
  17605. var decision = decoder.readBit(contexts, contextLabel);
  17606. if (decision) {
  17607. var sign = this.decodeSignBit(i, j, index);
  17608. coefficentsSign[index] = sign;
  17609. coefficentsMagnitude[index] = 1;
  17610. this.setNeighborsSignificance(i, j, index);
  17611. processingFlags[index] |= firstMagnitudeBitMask;
  17612. }
  17613. bitsDecoded[index]++;
  17614. processingFlags[index] |= processedMask;
  17615. }
  17616. }
  17617. }
  17618. },
  17619. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  17620. var width = this.width, height = this.height;
  17621. var coefficentsMagnitude = this.coefficentsMagnitude;
  17622. var coefficentsSign = this.coefficentsSign;
  17623. var contribution, sign0, sign1, significance1;
  17624. var contextLabel, decoded;
  17625. // calculate horizontal contribution
  17626. significance1 = column > 0 && coefficentsMagnitude[index - 1] !== 0;
  17627. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  17628. sign1 = coefficentsSign[index + 1];
  17629. if (significance1) {
  17630. sign0 = coefficentsSign[index - 1];
  17631. contribution = 1 - sign1 - sign0;
  17632. } else {
  17633. contribution = 1 - sign1 - sign1;
  17634. }
  17635. } else if (significance1) {
  17636. sign0 = coefficentsSign[index - 1];
  17637. contribution = 1 - sign0 - sign0;
  17638. } else {
  17639. contribution = 0;
  17640. }
  17641. var horizontalContribution = 3 * contribution;
  17642. // calculate vertical contribution and combine with the horizontal
  17643. significance1 = row > 0 && coefficentsMagnitude[index - width] !== 0;
  17644. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  17645. sign1 = coefficentsSign[index + width];
  17646. if (significance1) {
  17647. sign0 = coefficentsSign[index - width];
  17648. contribution = 1 - sign1 - sign0 + horizontalContribution;
  17649. } else {
  17650. contribution = 1 - sign1 - sign1 + horizontalContribution;
  17651. }
  17652. } else if (significance1) {
  17653. sign0 = coefficentsSign[index - width];
  17654. contribution = 1 - sign0 - sign0 + horizontalContribution;
  17655. } else {
  17656. contribution = horizontalContribution;
  17657. }
  17658. if (contribution >= 0) {
  17659. contextLabel = 9 + contribution;
  17660. decoded = this.decoder.readBit(this.contexts, contextLabel);
  17661. } else {
  17662. contextLabel = 9 - contribution;
  17663. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  17664. }
  17665. return decoded;
  17666. },
  17667. runMagnitudeRefinementPass: function BitModel_runMagnitudeRefinementPass() {
  17668. var decoder = this.decoder;
  17669. var width = this.width, height = this.height;
  17670. var coefficentsMagnitude = this.coefficentsMagnitude;
  17671. var neighborsSignificance = this.neighborsSignificance;
  17672. var contexts = this.contexts;
  17673. var bitsDecoded = this.bitsDecoded;
  17674. var processingFlags = this.processingFlags;
  17675. var processedMask = 1;
  17676. var firstMagnitudeBitMask = 2;
  17677. var length = width * height;
  17678. var width4 = width * 4;
  17679. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  17680. indexNext = Math.min(length, index0 + width4);
  17681. for (var j = 0; j < width; j++) {
  17682. for (var index = index0 + j; index < indexNext; index += width) {
  17683. // significant but not those that have just become
  17684. if (!coefficentsMagnitude[index] || (processingFlags[index] & processedMask) !== 0) {
  17685. continue;
  17686. }
  17687. var contextLabel = 16;
  17688. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  17689. processingFlags[index] ^= firstMagnitudeBitMask;
  17690. // first refinement
  17691. var significance = neighborsSignificance[index] & 127;
  17692. contextLabel = significance === 0 ? 15 : 14;
  17693. }
  17694. var bit = decoder.readBit(contexts, contextLabel);
  17695. coefficentsMagnitude[index] = coefficentsMagnitude[index] << 1 | bit;
  17696. bitsDecoded[index]++;
  17697. processingFlags[index] |= processedMask;
  17698. }
  17699. }
  17700. }
  17701. },
  17702. runCleanupPass: function BitModel_runCleanupPass() {
  17703. var decoder = this.decoder;
  17704. var width = this.width, height = this.height;
  17705. var neighborsSignificance = this.neighborsSignificance;
  17706. var coefficentsMagnitude = this.coefficentsMagnitude;
  17707. var coefficentsSign = this.coefficentsSign;
  17708. var contexts = this.contexts;
  17709. var labels = this.contextLabelTable;
  17710. var bitsDecoded = this.bitsDecoded;
  17711. var processingFlags = this.processingFlags;
  17712. var processedMask = 1;
  17713. var firstMagnitudeBitMask = 2;
  17714. var oneRowDown = width;
  17715. var twoRowsDown = width * 2;
  17716. var threeRowsDown = width * 3;
  17717. var iNext;
  17718. for (var i0 = 0; i0 < height; i0 = iNext) {
  17719. iNext = Math.min(i0 + 4, height);
  17720. var indexBase = i0 * width;
  17721. var checkAllEmpty = i0 + 3 < height;
  17722. for (var j = 0; j < width; j++) {
  17723. var index0 = indexBase + j;
  17724. // using the property: labels[neighborsSignificance[index]] === 0
  17725. // when neighborsSignificance[index] === 0
  17726. 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;
  17727. var i1 = 0, index = index0;
  17728. var i = i0, sign;
  17729. if (allEmpty) {
  17730. var hasSignificantCoefficent = decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  17731. if (!hasSignificantCoefficent) {
  17732. bitsDecoded[index0]++;
  17733. bitsDecoded[index0 + oneRowDown]++;
  17734. bitsDecoded[index0 + twoRowsDown]++;
  17735. bitsDecoded[index0 + threeRowsDown]++;
  17736. continue;
  17737. }
  17738. // next column
  17739. i1 = decoder.readBit(contexts, UNIFORM_CONTEXT) << 1 | decoder.readBit(contexts, UNIFORM_CONTEXT);
  17740. if (i1 !== 0) {
  17741. i = i0 + i1;
  17742. index += i1 * width;
  17743. }
  17744. sign = this.decodeSignBit(i, j, index);
  17745. coefficentsSign[index] = sign;
  17746. coefficentsMagnitude[index] = 1;
  17747. this.setNeighborsSignificance(i, j, index);
  17748. processingFlags[index] |= firstMagnitudeBitMask;
  17749. index = index0;
  17750. for (var i2 = i0; i2 <= i; i2++, index += width) {
  17751. bitsDecoded[index]++;
  17752. }
  17753. i1++;
  17754. }
  17755. for (i = i0 + i1; i < iNext; i++, index += width) {
  17756. if (coefficentsMagnitude[index] || (processingFlags[index] & processedMask) !== 0) {
  17757. continue;
  17758. }
  17759. var contextLabel = labels[neighborsSignificance[index]];
  17760. var decision = decoder.readBit(contexts, contextLabel);
  17761. if (decision === 1) {
  17762. sign = this.decodeSignBit(i, j, index);
  17763. coefficentsSign[index] = sign;
  17764. coefficentsMagnitude[index] = 1;
  17765. this.setNeighborsSignificance(i, j, index);
  17766. processingFlags[index] |= firstMagnitudeBitMask;
  17767. }
  17768. bitsDecoded[index]++;
  17769. }
  17770. }
  17771. }
  17772. },
  17773. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  17774. var decoder = this.decoder;
  17775. var contexts = this.contexts;
  17776. 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);
  17777. if (symbol !== 0xA) {
  17778. error('JPX Error: Invalid segmentation symbol');
  17779. }
  17780. }
  17781. };
  17782. return BitModel;
  17783. }();
  17784. // Section F, Discrete wavelet transformation
  17785. var Transform = function TransformClosure() {
  17786. function Transform() {
  17787. }
  17788. Transform.prototype.calculate = function transformCalculate(subbands, u0, v0) {
  17789. var ll = subbands[0];
  17790. for (var i = 1, ii = subbands.length; i < ii; i++) {
  17791. ll = this.iterate(ll, subbands[i], u0, v0);
  17792. }
  17793. return ll;
  17794. };
  17795. Transform.prototype.extend = function extend(buffer, offset, size) {
  17796. // Section F.3.7 extending... using max extension of 4
  17797. var i1 = offset - 1, j1 = offset + 1;
  17798. var i2 = offset + size - 2, j2 = offset + size;
  17799. buffer[i1--] = buffer[j1++];
  17800. buffer[j2++] = buffer[i2--];
  17801. buffer[i1--] = buffer[j1++];
  17802. buffer[j2++] = buffer[i2--];
  17803. buffer[i1--] = buffer[j1++];
  17804. buffer[j2++] = buffer[i2--];
  17805. buffer[i1] = buffer[j1];
  17806. buffer[j2] = buffer[i2];
  17807. };
  17808. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh, u0, v0) {
  17809. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  17810. var width = hl_lh_hh.width;
  17811. var height = hl_lh_hh.height;
  17812. var items = hl_lh_hh.items;
  17813. var i, j, k, l, u, v;
  17814. // Interleave LL according to Section F.3.3
  17815. for (k = 0, i = 0; i < llHeight; i++) {
  17816. l = i * 2 * width;
  17817. for (j = 0; j < llWidth; j++, k++, l += 2) {
  17818. items[l] = llItems[k];
  17819. }
  17820. }
  17821. // The LL band is not needed anymore.
  17822. llItems = ll.items = null;
  17823. var bufferPadding = 4;
  17824. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  17825. // Section F.3.4 HOR_SR
  17826. if (width === 1) {
  17827. // if width = 1, when u0 even keep items as is, when odd divide by 2
  17828. if ((u0 & 1) !== 0) {
  17829. for (v = 0, k = 0; v < height; v++, k += width) {
  17830. items[k] *= 0.5;
  17831. }
  17832. }
  17833. } else {
  17834. for (v = 0, k = 0; v < height; v++, k += width) {
  17835. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  17836. this.extend(rowBuffer, bufferPadding, width);
  17837. this.filter(rowBuffer, bufferPadding, width);
  17838. items.set(rowBuffer.subarray(bufferPadding, bufferPadding + width), k);
  17839. }
  17840. }
  17841. // Accesses to the items array can take long, because it may not fit into
  17842. // CPU cache and has to be fetched from main memory. Since subsequent
  17843. // accesses to the items array are not local when reading columns, we
  17844. // have a cache miss every time. To reduce cache misses, get up to
  17845. // 'numBuffers' items at a time and store them into the individual
  17846. // buffers. The colBuffers should be small enough to fit into CPU cache.
  17847. var numBuffers = 16;
  17848. var colBuffers = [];
  17849. for (i = 0; i < numBuffers; i++) {
  17850. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  17851. }
  17852. var b, currentBuffer = 0;
  17853. ll = bufferPadding + height;
  17854. // Section F.3.5 VER_SR
  17855. if (height === 1) {
  17856. // if height = 1, when v0 even keep items as is, when odd divide by 2
  17857. if ((v0 & 1) !== 0) {
  17858. for (u = 0; u < width; u++) {
  17859. items[u] *= 0.5;
  17860. }
  17861. }
  17862. } else {
  17863. for (u = 0; u < width; u++) {
  17864. // if we ran out of buffers, copy several image columns at once
  17865. if (currentBuffer === 0) {
  17866. numBuffers = Math.min(width - u, numBuffers);
  17867. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  17868. for (b = 0; b < numBuffers; b++) {
  17869. colBuffers[b][l] = items[k + b];
  17870. }
  17871. }
  17872. currentBuffer = numBuffers;
  17873. }
  17874. currentBuffer--;
  17875. var buffer = colBuffers[currentBuffer];
  17876. this.extend(buffer, bufferPadding, height);
  17877. this.filter(buffer, bufferPadding, height);
  17878. // If this is last buffer in this group of buffers, flush all buffers.
  17879. if (currentBuffer === 0) {
  17880. k = u - numBuffers + 1;
  17881. for (l = bufferPadding; l < ll; k += width, l++) {
  17882. for (b = 0; b < numBuffers; b++) {
  17883. items[k + b] = colBuffers[b][l];
  17884. }
  17885. }
  17886. }
  17887. }
  17888. }
  17889. return {
  17890. width: width,
  17891. height: height,
  17892. items: items
  17893. };
  17894. };
  17895. return Transform;
  17896. }();
  17897. // Section 3.8.2 Irreversible 9-7 filter
  17898. var IrreversibleTransform = function IrreversibleTransformClosure() {
  17899. function IrreversibleTransform() {
  17900. Transform.call(this);
  17901. }
  17902. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  17903. IrreversibleTransform.prototype.filter = function irreversibleTransformFilter(x, offset, length) {
  17904. var len = length >> 1;
  17905. offset = offset | 0;
  17906. var j, n, current, next;
  17907. var alpha = -1.586134342059924;
  17908. var beta = -0.052980118572961;
  17909. var gamma = 0.882911075530934;
  17910. var delta = 0.443506852043971;
  17911. var K = 1.230174104914001;
  17912. var K_ = 1 / K;
  17913. // step 1 is combined with step 3
  17914. // step 2
  17915. j = offset - 3;
  17916. for (n = len + 4; n--; j += 2) {
  17917. x[j] *= K_;
  17918. }
  17919. // step 1 & 3
  17920. j = offset - 2;
  17921. current = delta * x[j - 1];
  17922. for (n = len + 3; n--; j += 2) {
  17923. next = delta * x[j + 1];
  17924. x[j] = K * x[j] - current - next;
  17925. if (n--) {
  17926. j += 2;
  17927. current = delta * x[j + 1];
  17928. x[j] = K * x[j] - current - next;
  17929. } else {
  17930. break;
  17931. }
  17932. }
  17933. // step 4
  17934. j = offset - 1;
  17935. current = gamma * x[j - 1];
  17936. for (n = len + 2; n--; j += 2) {
  17937. next = gamma * x[j + 1];
  17938. x[j] -= current + next;
  17939. if (n--) {
  17940. j += 2;
  17941. current = gamma * x[j + 1];
  17942. x[j] -= current + next;
  17943. } else {
  17944. break;
  17945. }
  17946. }
  17947. // step 5
  17948. j = offset;
  17949. current = beta * x[j - 1];
  17950. for (n = len + 1; n--; j += 2) {
  17951. next = beta * x[j + 1];
  17952. x[j] -= current + next;
  17953. if (n--) {
  17954. j += 2;
  17955. current = beta * x[j + 1];
  17956. x[j] -= current + next;
  17957. } else {
  17958. break;
  17959. }
  17960. }
  17961. // step 6
  17962. if (len !== 0) {
  17963. j = offset + 1;
  17964. current = alpha * x[j - 1];
  17965. for (n = len; n--; j += 2) {
  17966. next = alpha * x[j + 1];
  17967. x[j] -= current + next;
  17968. if (n--) {
  17969. j += 2;
  17970. current = alpha * x[j + 1];
  17971. x[j] -= current + next;
  17972. } else {
  17973. break;
  17974. }
  17975. }
  17976. }
  17977. };
  17978. return IrreversibleTransform;
  17979. }();
  17980. // Section 3.8.1 Reversible 5-3 filter
  17981. var ReversibleTransform = function ReversibleTransformClosure() {
  17982. function ReversibleTransform() {
  17983. Transform.call(this);
  17984. }
  17985. ReversibleTransform.prototype = Object.create(Transform.prototype);
  17986. ReversibleTransform.prototype.filter = function reversibleTransformFilter(x, offset, length) {
  17987. var len = length >> 1;
  17988. offset = offset | 0;
  17989. var j, n;
  17990. for (j = offset, n = len + 1; n--; j += 2) {
  17991. x[j] -= x[j - 1] + x[j + 1] + 2 >> 2;
  17992. }
  17993. for (j = offset + 1, n = len; n--; j += 2) {
  17994. x[j] += x[j - 1] + x[j + 1] >> 1;
  17995. }
  17996. };
  17997. return ReversibleTransform;
  17998. }();
  17999. return JpxImage;
  18000. }();
  18001. exports.JpxImage = JpxImage;
  18002. }));
  18003. (function (root, factory) {
  18004. factory(root.pdfjsCoreMetrics = {}, root.pdfjsSharedUtil);
  18005. }(this, function (exports, sharedUtil) {
  18006. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  18007. // The Metrics object contains glyph widths (in glyph space units).
  18008. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  18009. // space unit corresponds to 1/1000th of text space unit.
  18010. var getMetrics = getLookupTableFactory(function (t) {
  18011. t['Courier'] = 600;
  18012. t['Courier-Bold'] = 600;
  18013. t['Courier-BoldOblique'] = 600;
  18014. t['Courier-Oblique'] = 600;
  18015. t['Helvetica'] = getLookupTableFactory(function (t) {
  18016. t['space'] = 278;
  18017. t['exclam'] = 278;
  18018. t['quotedbl'] = 355;
  18019. t['numbersign'] = 556;
  18020. t['dollar'] = 556;
  18021. t['percent'] = 889;
  18022. t['ampersand'] = 667;
  18023. t['quoteright'] = 222;
  18024. t['parenleft'] = 333;
  18025. t['parenright'] = 333;
  18026. t['asterisk'] = 389;
  18027. t['plus'] = 584;
  18028. t['comma'] = 278;
  18029. t['hyphen'] = 333;
  18030. t['period'] = 278;
  18031. t['slash'] = 278;
  18032. t['zero'] = 556;
  18033. t['one'] = 556;
  18034. t['two'] = 556;
  18035. t['three'] = 556;
  18036. t['four'] = 556;
  18037. t['five'] = 556;
  18038. t['six'] = 556;
  18039. t['seven'] = 556;
  18040. t['eight'] = 556;
  18041. t['nine'] = 556;
  18042. t['colon'] = 278;
  18043. t['semicolon'] = 278;
  18044. t['less'] = 584;
  18045. t['equal'] = 584;
  18046. t['greater'] = 584;
  18047. t['question'] = 556;
  18048. t['at'] = 1015;
  18049. t['A'] = 667;
  18050. t['B'] = 667;
  18051. t['C'] = 722;
  18052. t['D'] = 722;
  18053. t['E'] = 667;
  18054. t['F'] = 611;
  18055. t['G'] = 778;
  18056. t['H'] = 722;
  18057. t['I'] = 278;
  18058. t['J'] = 500;
  18059. t['K'] = 667;
  18060. t['L'] = 556;
  18061. t['M'] = 833;
  18062. t['N'] = 722;
  18063. t['O'] = 778;
  18064. t['P'] = 667;
  18065. t['Q'] = 778;
  18066. t['R'] = 722;
  18067. t['S'] = 667;
  18068. t['T'] = 611;
  18069. t['U'] = 722;
  18070. t['V'] = 667;
  18071. t['W'] = 944;
  18072. t['X'] = 667;
  18073. t['Y'] = 667;
  18074. t['Z'] = 611;
  18075. t['bracketleft'] = 278;
  18076. t['backslash'] = 278;
  18077. t['bracketright'] = 278;
  18078. t['asciicircum'] = 469;
  18079. t['underscore'] = 556;
  18080. t['quoteleft'] = 222;
  18081. t['a'] = 556;
  18082. t['b'] = 556;
  18083. t['c'] = 500;
  18084. t['d'] = 556;
  18085. t['e'] = 556;
  18086. t['f'] = 278;
  18087. t['g'] = 556;
  18088. t['h'] = 556;
  18089. t['i'] = 222;
  18090. t['j'] = 222;
  18091. t['k'] = 500;
  18092. t['l'] = 222;
  18093. t['m'] = 833;
  18094. t['n'] = 556;
  18095. t['o'] = 556;
  18096. t['p'] = 556;
  18097. t['q'] = 556;
  18098. t['r'] = 333;
  18099. t['s'] = 500;
  18100. t['t'] = 278;
  18101. t['u'] = 556;
  18102. t['v'] = 500;
  18103. t['w'] = 722;
  18104. t['x'] = 500;
  18105. t['y'] = 500;
  18106. t['z'] = 500;
  18107. t['braceleft'] = 334;
  18108. t['bar'] = 260;
  18109. t['braceright'] = 334;
  18110. t['asciitilde'] = 584;
  18111. t['exclamdown'] = 333;
  18112. t['cent'] = 556;
  18113. t['sterling'] = 556;
  18114. t['fraction'] = 167;
  18115. t['yen'] = 556;
  18116. t['florin'] = 556;
  18117. t['section'] = 556;
  18118. t['currency'] = 556;
  18119. t['quotesingle'] = 191;
  18120. t['quotedblleft'] = 333;
  18121. t['guillemotleft'] = 556;
  18122. t['guilsinglleft'] = 333;
  18123. t['guilsinglright'] = 333;
  18124. t['fi'] = 500;
  18125. t['fl'] = 500;
  18126. t['endash'] = 556;
  18127. t['dagger'] = 556;
  18128. t['daggerdbl'] = 556;
  18129. t['periodcentered'] = 278;
  18130. t['paragraph'] = 537;
  18131. t['bullet'] = 350;
  18132. t['quotesinglbase'] = 222;
  18133. t['quotedblbase'] = 333;
  18134. t['quotedblright'] = 333;
  18135. t['guillemotright'] = 556;
  18136. t['ellipsis'] = 1000;
  18137. t['perthousand'] = 1000;
  18138. t['questiondown'] = 611;
  18139. t['grave'] = 333;
  18140. t['acute'] = 333;
  18141. t['circumflex'] = 333;
  18142. t['tilde'] = 333;
  18143. t['macron'] = 333;
  18144. t['breve'] = 333;
  18145. t['dotaccent'] = 333;
  18146. t['dieresis'] = 333;
  18147. t['ring'] = 333;
  18148. t['cedilla'] = 333;
  18149. t['hungarumlaut'] = 333;
  18150. t['ogonek'] = 333;
  18151. t['caron'] = 333;
  18152. t['emdash'] = 1000;
  18153. t['AE'] = 1000;
  18154. t['ordfeminine'] = 370;
  18155. t['Lslash'] = 556;
  18156. t['Oslash'] = 778;
  18157. t['OE'] = 1000;
  18158. t['ordmasculine'] = 365;
  18159. t['ae'] = 889;
  18160. t['dotlessi'] = 278;
  18161. t['lslash'] = 222;
  18162. t['oslash'] = 611;
  18163. t['oe'] = 944;
  18164. t['germandbls'] = 611;
  18165. t['Idieresis'] = 278;
  18166. t['eacute'] = 556;
  18167. t['abreve'] = 556;
  18168. t['uhungarumlaut'] = 556;
  18169. t['ecaron'] = 556;
  18170. t['Ydieresis'] = 667;
  18171. t['divide'] = 584;
  18172. t['Yacute'] = 667;
  18173. t['Acircumflex'] = 667;
  18174. t['aacute'] = 556;
  18175. t['Ucircumflex'] = 722;
  18176. t['yacute'] = 500;
  18177. t['scommaaccent'] = 500;
  18178. t['ecircumflex'] = 556;
  18179. t['Uring'] = 722;
  18180. t['Udieresis'] = 722;
  18181. t['aogonek'] = 556;
  18182. t['Uacute'] = 722;
  18183. t['uogonek'] = 556;
  18184. t['Edieresis'] = 667;
  18185. t['Dcroat'] = 722;
  18186. t['commaaccent'] = 250;
  18187. t['copyright'] = 737;
  18188. t['Emacron'] = 667;
  18189. t['ccaron'] = 500;
  18190. t['aring'] = 556;
  18191. t['Ncommaaccent'] = 722;
  18192. t['lacute'] = 222;
  18193. t['agrave'] = 556;
  18194. t['Tcommaaccent'] = 611;
  18195. t['Cacute'] = 722;
  18196. t['atilde'] = 556;
  18197. t['Edotaccent'] = 667;
  18198. t['scaron'] = 500;
  18199. t['scedilla'] = 500;
  18200. t['iacute'] = 278;
  18201. t['lozenge'] = 471;
  18202. t['Rcaron'] = 722;
  18203. t['Gcommaaccent'] = 778;
  18204. t['ucircumflex'] = 556;
  18205. t['acircumflex'] = 556;
  18206. t['Amacron'] = 667;
  18207. t['rcaron'] = 333;
  18208. t['ccedilla'] = 500;
  18209. t['Zdotaccent'] = 611;
  18210. t['Thorn'] = 667;
  18211. t['Omacron'] = 778;
  18212. t['Racute'] = 722;
  18213. t['Sacute'] = 667;
  18214. t['dcaron'] = 643;
  18215. t['Umacron'] = 722;
  18216. t['uring'] = 556;
  18217. t['threesuperior'] = 333;
  18218. t['Ograve'] = 778;
  18219. t['Agrave'] = 667;
  18220. t['Abreve'] = 667;
  18221. t['multiply'] = 584;
  18222. t['uacute'] = 556;
  18223. t['Tcaron'] = 611;
  18224. t['partialdiff'] = 476;
  18225. t['ydieresis'] = 500;
  18226. t['Nacute'] = 722;
  18227. t['icircumflex'] = 278;
  18228. t['Ecircumflex'] = 667;
  18229. t['adieresis'] = 556;
  18230. t['edieresis'] = 556;
  18231. t['cacute'] = 500;
  18232. t['nacute'] = 556;
  18233. t['umacron'] = 556;
  18234. t['Ncaron'] = 722;
  18235. t['Iacute'] = 278;
  18236. t['plusminus'] = 584;
  18237. t['brokenbar'] = 260;
  18238. t['registered'] = 737;
  18239. t['Gbreve'] = 778;
  18240. t['Idotaccent'] = 278;
  18241. t['summation'] = 600;
  18242. t['Egrave'] = 667;
  18243. t['racute'] = 333;
  18244. t['omacron'] = 556;
  18245. t['Zacute'] = 611;
  18246. t['Zcaron'] = 611;
  18247. t['greaterequal'] = 549;
  18248. t['Eth'] = 722;
  18249. t['Ccedilla'] = 722;
  18250. t['lcommaaccent'] = 222;
  18251. t['tcaron'] = 317;
  18252. t['eogonek'] = 556;
  18253. t['Uogonek'] = 722;
  18254. t['Aacute'] = 667;
  18255. t['Adieresis'] = 667;
  18256. t['egrave'] = 556;
  18257. t['zacute'] = 500;
  18258. t['iogonek'] = 222;
  18259. t['Oacute'] = 778;
  18260. t['oacute'] = 556;
  18261. t['amacron'] = 556;
  18262. t['sacute'] = 500;
  18263. t['idieresis'] = 278;
  18264. t['Ocircumflex'] = 778;
  18265. t['Ugrave'] = 722;
  18266. t['Delta'] = 612;
  18267. t['thorn'] = 556;
  18268. t['twosuperior'] = 333;
  18269. t['Odieresis'] = 778;
  18270. t['mu'] = 556;
  18271. t['igrave'] = 278;
  18272. t['ohungarumlaut'] = 556;
  18273. t['Eogonek'] = 667;
  18274. t['dcroat'] = 556;
  18275. t['threequarters'] = 834;
  18276. t['Scedilla'] = 667;
  18277. t['lcaron'] = 299;
  18278. t['Kcommaaccent'] = 667;
  18279. t['Lacute'] = 556;
  18280. t['trademark'] = 1000;
  18281. t['edotaccent'] = 556;
  18282. t['Igrave'] = 278;
  18283. t['Imacron'] = 278;
  18284. t['Lcaron'] = 556;
  18285. t['onehalf'] = 834;
  18286. t['lessequal'] = 549;
  18287. t['ocircumflex'] = 556;
  18288. t['ntilde'] = 556;
  18289. t['Uhungarumlaut'] = 722;
  18290. t['Eacute'] = 667;
  18291. t['emacron'] = 556;
  18292. t['gbreve'] = 556;
  18293. t['onequarter'] = 834;
  18294. t['Scaron'] = 667;
  18295. t['Scommaaccent'] = 667;
  18296. t['Ohungarumlaut'] = 778;
  18297. t['degree'] = 400;
  18298. t['ograve'] = 556;
  18299. t['Ccaron'] = 722;
  18300. t['ugrave'] = 556;
  18301. t['radical'] = 453;
  18302. t['Dcaron'] = 722;
  18303. t['rcommaaccent'] = 333;
  18304. t['Ntilde'] = 722;
  18305. t['otilde'] = 556;
  18306. t['Rcommaaccent'] = 722;
  18307. t['Lcommaaccent'] = 556;
  18308. t['Atilde'] = 667;
  18309. t['Aogonek'] = 667;
  18310. t['Aring'] = 667;
  18311. t['Otilde'] = 778;
  18312. t['zdotaccent'] = 500;
  18313. t['Ecaron'] = 667;
  18314. t['Iogonek'] = 278;
  18315. t['kcommaaccent'] = 500;
  18316. t['minus'] = 584;
  18317. t['Icircumflex'] = 278;
  18318. t['ncaron'] = 556;
  18319. t['tcommaaccent'] = 278;
  18320. t['logicalnot'] = 584;
  18321. t['odieresis'] = 556;
  18322. t['udieresis'] = 556;
  18323. t['notequal'] = 549;
  18324. t['gcommaaccent'] = 556;
  18325. t['eth'] = 556;
  18326. t['zcaron'] = 500;
  18327. t['ncommaaccent'] = 556;
  18328. t['onesuperior'] = 333;
  18329. t['imacron'] = 278;
  18330. t['Euro'] = 556;
  18331. });
  18332. t['Helvetica-Bold'] = getLookupTableFactory(function (t) {
  18333. t['space'] = 278;
  18334. t['exclam'] = 333;
  18335. t['quotedbl'] = 474;
  18336. t['numbersign'] = 556;
  18337. t['dollar'] = 556;
  18338. t['percent'] = 889;
  18339. t['ampersand'] = 722;
  18340. t['quoteright'] = 278;
  18341. t['parenleft'] = 333;
  18342. t['parenright'] = 333;
  18343. t['asterisk'] = 389;
  18344. t['plus'] = 584;
  18345. t['comma'] = 278;
  18346. t['hyphen'] = 333;
  18347. t['period'] = 278;
  18348. t['slash'] = 278;
  18349. t['zero'] = 556;
  18350. t['one'] = 556;
  18351. t['two'] = 556;
  18352. t['three'] = 556;
  18353. t['four'] = 556;
  18354. t['five'] = 556;
  18355. t['six'] = 556;
  18356. t['seven'] = 556;
  18357. t['eight'] = 556;
  18358. t['nine'] = 556;
  18359. t['colon'] = 333;
  18360. t['semicolon'] = 333;
  18361. t['less'] = 584;
  18362. t['equal'] = 584;
  18363. t['greater'] = 584;
  18364. t['question'] = 611;
  18365. t['at'] = 975;
  18366. t['A'] = 722;
  18367. t['B'] = 722;
  18368. t['C'] = 722;
  18369. t['D'] = 722;
  18370. t['E'] = 667;
  18371. t['F'] = 611;
  18372. t['G'] = 778;
  18373. t['H'] = 722;
  18374. t['I'] = 278;
  18375. t['J'] = 556;
  18376. t['K'] = 722;
  18377. t['L'] = 611;
  18378. t['M'] = 833;
  18379. t['N'] = 722;
  18380. t['O'] = 778;
  18381. t['P'] = 667;
  18382. t['Q'] = 778;
  18383. t['R'] = 722;
  18384. t['S'] = 667;
  18385. t['T'] = 611;
  18386. t['U'] = 722;
  18387. t['V'] = 667;
  18388. t['W'] = 944;
  18389. t['X'] = 667;
  18390. t['Y'] = 667;
  18391. t['Z'] = 611;
  18392. t['bracketleft'] = 333;
  18393. t['backslash'] = 278;
  18394. t['bracketright'] = 333;
  18395. t['asciicircum'] = 584;
  18396. t['underscore'] = 556;
  18397. t['quoteleft'] = 278;
  18398. t['a'] = 556;
  18399. t['b'] = 611;
  18400. t['c'] = 556;
  18401. t['d'] = 611;
  18402. t['e'] = 556;
  18403. t['f'] = 333;
  18404. t['g'] = 611;
  18405. t['h'] = 611;
  18406. t['i'] = 278;
  18407. t['j'] = 278;
  18408. t['k'] = 556;
  18409. t['l'] = 278;
  18410. t['m'] = 889;
  18411. t['n'] = 611;
  18412. t['o'] = 611;
  18413. t['p'] = 611;
  18414. t['q'] = 611;
  18415. t['r'] = 389;
  18416. t['s'] = 556;
  18417. t['t'] = 333;
  18418. t['u'] = 611;
  18419. t['v'] = 556;
  18420. t['w'] = 778;
  18421. t['x'] = 556;
  18422. t['y'] = 556;
  18423. t['z'] = 500;
  18424. t['braceleft'] = 389;
  18425. t['bar'] = 280;
  18426. t['braceright'] = 389;
  18427. t['asciitilde'] = 584;
  18428. t['exclamdown'] = 333;
  18429. t['cent'] = 556;
  18430. t['sterling'] = 556;
  18431. t['fraction'] = 167;
  18432. t['yen'] = 556;
  18433. t['florin'] = 556;
  18434. t['section'] = 556;
  18435. t['currency'] = 556;
  18436. t['quotesingle'] = 238;
  18437. t['quotedblleft'] = 500;
  18438. t['guillemotleft'] = 556;
  18439. t['guilsinglleft'] = 333;
  18440. t['guilsinglright'] = 333;
  18441. t['fi'] = 611;
  18442. t['fl'] = 611;
  18443. t['endash'] = 556;
  18444. t['dagger'] = 556;
  18445. t['daggerdbl'] = 556;
  18446. t['periodcentered'] = 278;
  18447. t['paragraph'] = 556;
  18448. t['bullet'] = 350;
  18449. t['quotesinglbase'] = 278;
  18450. t['quotedblbase'] = 500;
  18451. t['quotedblright'] = 500;
  18452. t['guillemotright'] = 556;
  18453. t['ellipsis'] = 1000;
  18454. t['perthousand'] = 1000;
  18455. t['questiondown'] = 611;
  18456. t['grave'] = 333;
  18457. t['acute'] = 333;
  18458. t['circumflex'] = 333;
  18459. t['tilde'] = 333;
  18460. t['macron'] = 333;
  18461. t['breve'] = 333;
  18462. t['dotaccent'] = 333;
  18463. t['dieresis'] = 333;
  18464. t['ring'] = 333;
  18465. t['cedilla'] = 333;
  18466. t['hungarumlaut'] = 333;
  18467. t['ogonek'] = 333;
  18468. t['caron'] = 333;
  18469. t['emdash'] = 1000;
  18470. t['AE'] = 1000;
  18471. t['ordfeminine'] = 370;
  18472. t['Lslash'] = 611;
  18473. t['Oslash'] = 778;
  18474. t['OE'] = 1000;
  18475. t['ordmasculine'] = 365;
  18476. t['ae'] = 889;
  18477. t['dotlessi'] = 278;
  18478. t['lslash'] = 278;
  18479. t['oslash'] = 611;
  18480. t['oe'] = 944;
  18481. t['germandbls'] = 611;
  18482. t['Idieresis'] = 278;
  18483. t['eacute'] = 556;
  18484. t['abreve'] = 556;
  18485. t['uhungarumlaut'] = 611;
  18486. t['ecaron'] = 556;
  18487. t['Ydieresis'] = 667;
  18488. t['divide'] = 584;
  18489. t['Yacute'] = 667;
  18490. t['Acircumflex'] = 722;
  18491. t['aacute'] = 556;
  18492. t['Ucircumflex'] = 722;
  18493. t['yacute'] = 556;
  18494. t['scommaaccent'] = 556;
  18495. t['ecircumflex'] = 556;
  18496. t['Uring'] = 722;
  18497. t['Udieresis'] = 722;
  18498. t['aogonek'] = 556;
  18499. t['Uacute'] = 722;
  18500. t['uogonek'] = 611;
  18501. t['Edieresis'] = 667;
  18502. t['Dcroat'] = 722;
  18503. t['commaaccent'] = 250;
  18504. t['copyright'] = 737;
  18505. t['Emacron'] = 667;
  18506. t['ccaron'] = 556;
  18507. t['aring'] = 556;
  18508. t['Ncommaaccent'] = 722;
  18509. t['lacute'] = 278;
  18510. t['agrave'] = 556;
  18511. t['Tcommaaccent'] = 611;
  18512. t['Cacute'] = 722;
  18513. t['atilde'] = 556;
  18514. t['Edotaccent'] = 667;
  18515. t['scaron'] = 556;
  18516. t['scedilla'] = 556;
  18517. t['iacute'] = 278;
  18518. t['lozenge'] = 494;
  18519. t['Rcaron'] = 722;
  18520. t['Gcommaaccent'] = 778;
  18521. t['ucircumflex'] = 611;
  18522. t['acircumflex'] = 556;
  18523. t['Amacron'] = 722;
  18524. t['rcaron'] = 389;
  18525. t['ccedilla'] = 556;
  18526. t['Zdotaccent'] = 611;
  18527. t['Thorn'] = 667;
  18528. t['Omacron'] = 778;
  18529. t['Racute'] = 722;
  18530. t['Sacute'] = 667;
  18531. t['dcaron'] = 743;
  18532. t['Umacron'] = 722;
  18533. t['uring'] = 611;
  18534. t['threesuperior'] = 333;
  18535. t['Ograve'] = 778;
  18536. t['Agrave'] = 722;
  18537. t['Abreve'] = 722;
  18538. t['multiply'] = 584;
  18539. t['uacute'] = 611;
  18540. t['Tcaron'] = 611;
  18541. t['partialdiff'] = 494;
  18542. t['ydieresis'] = 556;
  18543. t['Nacute'] = 722;
  18544. t['icircumflex'] = 278;
  18545. t['Ecircumflex'] = 667;
  18546. t['adieresis'] = 556;
  18547. t['edieresis'] = 556;
  18548. t['cacute'] = 556;
  18549. t['nacute'] = 611;
  18550. t['umacron'] = 611;
  18551. t['Ncaron'] = 722;
  18552. t['Iacute'] = 278;
  18553. t['plusminus'] = 584;
  18554. t['brokenbar'] = 280;
  18555. t['registered'] = 737;
  18556. t['Gbreve'] = 778;
  18557. t['Idotaccent'] = 278;
  18558. t['summation'] = 600;
  18559. t['Egrave'] = 667;
  18560. t['racute'] = 389;
  18561. t['omacron'] = 611;
  18562. t['Zacute'] = 611;
  18563. t['Zcaron'] = 611;
  18564. t['greaterequal'] = 549;
  18565. t['Eth'] = 722;
  18566. t['Ccedilla'] = 722;
  18567. t['lcommaaccent'] = 278;
  18568. t['tcaron'] = 389;
  18569. t['eogonek'] = 556;
  18570. t['Uogonek'] = 722;
  18571. t['Aacute'] = 722;
  18572. t['Adieresis'] = 722;
  18573. t['egrave'] = 556;
  18574. t['zacute'] = 500;
  18575. t['iogonek'] = 278;
  18576. t['Oacute'] = 778;
  18577. t['oacute'] = 611;
  18578. t['amacron'] = 556;
  18579. t['sacute'] = 556;
  18580. t['idieresis'] = 278;
  18581. t['Ocircumflex'] = 778;
  18582. t['Ugrave'] = 722;
  18583. t['Delta'] = 612;
  18584. t['thorn'] = 611;
  18585. t['twosuperior'] = 333;
  18586. t['Odieresis'] = 778;
  18587. t['mu'] = 611;
  18588. t['igrave'] = 278;
  18589. t['ohungarumlaut'] = 611;
  18590. t['Eogonek'] = 667;
  18591. t['dcroat'] = 611;
  18592. t['threequarters'] = 834;
  18593. t['Scedilla'] = 667;
  18594. t['lcaron'] = 400;
  18595. t['Kcommaaccent'] = 722;
  18596. t['Lacute'] = 611;
  18597. t['trademark'] = 1000;
  18598. t['edotaccent'] = 556;
  18599. t['Igrave'] = 278;
  18600. t['Imacron'] = 278;
  18601. t['Lcaron'] = 611;
  18602. t['onehalf'] = 834;
  18603. t['lessequal'] = 549;
  18604. t['ocircumflex'] = 611;
  18605. t['ntilde'] = 611;
  18606. t['Uhungarumlaut'] = 722;
  18607. t['Eacute'] = 667;
  18608. t['emacron'] = 556;
  18609. t['gbreve'] = 611;
  18610. t['onequarter'] = 834;
  18611. t['Scaron'] = 667;
  18612. t['Scommaaccent'] = 667;
  18613. t['Ohungarumlaut'] = 778;
  18614. t['degree'] = 400;
  18615. t['ograve'] = 611;
  18616. t['Ccaron'] = 722;
  18617. t['ugrave'] = 611;
  18618. t['radical'] = 549;
  18619. t['Dcaron'] = 722;
  18620. t['rcommaaccent'] = 389;
  18621. t['Ntilde'] = 722;
  18622. t['otilde'] = 611;
  18623. t['Rcommaaccent'] = 722;
  18624. t['Lcommaaccent'] = 611;
  18625. t['Atilde'] = 722;
  18626. t['Aogonek'] = 722;
  18627. t['Aring'] = 722;
  18628. t['Otilde'] = 778;
  18629. t['zdotaccent'] = 500;
  18630. t['Ecaron'] = 667;
  18631. t['Iogonek'] = 278;
  18632. t['kcommaaccent'] = 556;
  18633. t['minus'] = 584;
  18634. t['Icircumflex'] = 278;
  18635. t['ncaron'] = 611;
  18636. t['tcommaaccent'] = 333;
  18637. t['logicalnot'] = 584;
  18638. t['odieresis'] = 611;
  18639. t['udieresis'] = 611;
  18640. t['notequal'] = 549;
  18641. t['gcommaaccent'] = 611;
  18642. t['eth'] = 611;
  18643. t['zcaron'] = 500;
  18644. t['ncommaaccent'] = 611;
  18645. t['onesuperior'] = 333;
  18646. t['imacron'] = 278;
  18647. t['Euro'] = 556;
  18648. });
  18649. t['Helvetica-BoldOblique'] = getLookupTableFactory(function (t) {
  18650. t['space'] = 278;
  18651. t['exclam'] = 333;
  18652. t['quotedbl'] = 474;
  18653. t['numbersign'] = 556;
  18654. t['dollar'] = 556;
  18655. t['percent'] = 889;
  18656. t['ampersand'] = 722;
  18657. t['quoteright'] = 278;
  18658. t['parenleft'] = 333;
  18659. t['parenright'] = 333;
  18660. t['asterisk'] = 389;
  18661. t['plus'] = 584;
  18662. t['comma'] = 278;
  18663. t['hyphen'] = 333;
  18664. t['period'] = 278;
  18665. t['slash'] = 278;
  18666. t['zero'] = 556;
  18667. t['one'] = 556;
  18668. t['two'] = 556;
  18669. t['three'] = 556;
  18670. t['four'] = 556;
  18671. t['five'] = 556;
  18672. t['six'] = 556;
  18673. t['seven'] = 556;
  18674. t['eight'] = 556;
  18675. t['nine'] = 556;
  18676. t['colon'] = 333;
  18677. t['semicolon'] = 333;
  18678. t['less'] = 584;
  18679. t['equal'] = 584;
  18680. t['greater'] = 584;
  18681. t['question'] = 611;
  18682. t['at'] = 975;
  18683. t['A'] = 722;
  18684. t['B'] = 722;
  18685. t['C'] = 722;
  18686. t['D'] = 722;
  18687. t['E'] = 667;
  18688. t['F'] = 611;
  18689. t['G'] = 778;
  18690. t['H'] = 722;
  18691. t['I'] = 278;
  18692. t['J'] = 556;
  18693. t['K'] = 722;
  18694. t['L'] = 611;
  18695. t['M'] = 833;
  18696. t['N'] = 722;
  18697. t['O'] = 778;
  18698. t['P'] = 667;
  18699. t['Q'] = 778;
  18700. t['R'] = 722;
  18701. t['S'] = 667;
  18702. t['T'] = 611;
  18703. t['U'] = 722;
  18704. t['V'] = 667;
  18705. t['W'] = 944;
  18706. t['X'] = 667;
  18707. t['Y'] = 667;
  18708. t['Z'] = 611;
  18709. t['bracketleft'] = 333;
  18710. t['backslash'] = 278;
  18711. t['bracketright'] = 333;
  18712. t['asciicircum'] = 584;
  18713. t['underscore'] = 556;
  18714. t['quoteleft'] = 278;
  18715. t['a'] = 556;
  18716. t['b'] = 611;
  18717. t['c'] = 556;
  18718. t['d'] = 611;
  18719. t['e'] = 556;
  18720. t['f'] = 333;
  18721. t['g'] = 611;
  18722. t['h'] = 611;
  18723. t['i'] = 278;
  18724. t['j'] = 278;
  18725. t['k'] = 556;
  18726. t['l'] = 278;
  18727. t['m'] = 889;
  18728. t['n'] = 611;
  18729. t['o'] = 611;
  18730. t['p'] = 611;
  18731. t['q'] = 611;
  18732. t['r'] = 389;
  18733. t['s'] = 556;
  18734. t['t'] = 333;
  18735. t['u'] = 611;
  18736. t['v'] = 556;
  18737. t['w'] = 778;
  18738. t['x'] = 556;
  18739. t['y'] = 556;
  18740. t['z'] = 500;
  18741. t['braceleft'] = 389;
  18742. t['bar'] = 280;
  18743. t['braceright'] = 389;
  18744. t['asciitilde'] = 584;
  18745. t['exclamdown'] = 333;
  18746. t['cent'] = 556;
  18747. t['sterling'] = 556;
  18748. t['fraction'] = 167;
  18749. t['yen'] = 556;
  18750. t['florin'] = 556;
  18751. t['section'] = 556;
  18752. t['currency'] = 556;
  18753. t['quotesingle'] = 238;
  18754. t['quotedblleft'] = 500;
  18755. t['guillemotleft'] = 556;
  18756. t['guilsinglleft'] = 333;
  18757. t['guilsinglright'] = 333;
  18758. t['fi'] = 611;
  18759. t['fl'] = 611;
  18760. t['endash'] = 556;
  18761. t['dagger'] = 556;
  18762. t['daggerdbl'] = 556;
  18763. t['periodcentered'] = 278;
  18764. t['paragraph'] = 556;
  18765. t['bullet'] = 350;
  18766. t['quotesinglbase'] = 278;
  18767. t['quotedblbase'] = 500;
  18768. t['quotedblright'] = 500;
  18769. t['guillemotright'] = 556;
  18770. t['ellipsis'] = 1000;
  18771. t['perthousand'] = 1000;
  18772. t['questiondown'] = 611;
  18773. t['grave'] = 333;
  18774. t['acute'] = 333;
  18775. t['circumflex'] = 333;
  18776. t['tilde'] = 333;
  18777. t['macron'] = 333;
  18778. t['breve'] = 333;
  18779. t['dotaccent'] = 333;
  18780. t['dieresis'] = 333;
  18781. t['ring'] = 333;
  18782. t['cedilla'] = 333;
  18783. t['hungarumlaut'] = 333;
  18784. t['ogonek'] = 333;
  18785. t['caron'] = 333;
  18786. t['emdash'] = 1000;
  18787. t['AE'] = 1000;
  18788. t['ordfeminine'] = 370;
  18789. t['Lslash'] = 611;
  18790. t['Oslash'] = 778;
  18791. t['OE'] = 1000;
  18792. t['ordmasculine'] = 365;
  18793. t['ae'] = 889;
  18794. t['dotlessi'] = 278;
  18795. t['lslash'] = 278;
  18796. t['oslash'] = 611;
  18797. t['oe'] = 944;
  18798. t['germandbls'] = 611;
  18799. t['Idieresis'] = 278;
  18800. t['eacute'] = 556;
  18801. t['abreve'] = 556;
  18802. t['uhungarumlaut'] = 611;
  18803. t['ecaron'] = 556;
  18804. t['Ydieresis'] = 667;
  18805. t['divide'] = 584;
  18806. t['Yacute'] = 667;
  18807. t['Acircumflex'] = 722;
  18808. t['aacute'] = 556;
  18809. t['Ucircumflex'] = 722;
  18810. t['yacute'] = 556;
  18811. t['scommaaccent'] = 556;
  18812. t['ecircumflex'] = 556;
  18813. t['Uring'] = 722;
  18814. t['Udieresis'] = 722;
  18815. t['aogonek'] = 556;
  18816. t['Uacute'] = 722;
  18817. t['uogonek'] = 611;
  18818. t['Edieresis'] = 667;
  18819. t['Dcroat'] = 722;
  18820. t['commaaccent'] = 250;
  18821. t['copyright'] = 737;
  18822. t['Emacron'] = 667;
  18823. t['ccaron'] = 556;
  18824. t['aring'] = 556;
  18825. t['Ncommaaccent'] = 722;
  18826. t['lacute'] = 278;
  18827. t['agrave'] = 556;
  18828. t['Tcommaaccent'] = 611;
  18829. t['Cacute'] = 722;
  18830. t['atilde'] = 556;
  18831. t['Edotaccent'] = 667;
  18832. t['scaron'] = 556;
  18833. t['scedilla'] = 556;
  18834. t['iacute'] = 278;
  18835. t['lozenge'] = 494;
  18836. t['Rcaron'] = 722;
  18837. t['Gcommaaccent'] = 778;
  18838. t['ucircumflex'] = 611;
  18839. t['acircumflex'] = 556;
  18840. t['Amacron'] = 722;
  18841. t['rcaron'] = 389;
  18842. t['ccedilla'] = 556;
  18843. t['Zdotaccent'] = 611;
  18844. t['Thorn'] = 667;
  18845. t['Omacron'] = 778;
  18846. t['Racute'] = 722;
  18847. t['Sacute'] = 667;
  18848. t['dcaron'] = 743;
  18849. t['Umacron'] = 722;
  18850. t['uring'] = 611;
  18851. t['threesuperior'] = 333;
  18852. t['Ograve'] = 778;
  18853. t['Agrave'] = 722;
  18854. t['Abreve'] = 722;
  18855. t['multiply'] = 584;
  18856. t['uacute'] = 611;
  18857. t['Tcaron'] = 611;
  18858. t['partialdiff'] = 494;
  18859. t['ydieresis'] = 556;
  18860. t['Nacute'] = 722;
  18861. t['icircumflex'] = 278;
  18862. t['Ecircumflex'] = 667;
  18863. t['adieresis'] = 556;
  18864. t['edieresis'] = 556;
  18865. t['cacute'] = 556;
  18866. t['nacute'] = 611;
  18867. t['umacron'] = 611;
  18868. t['Ncaron'] = 722;
  18869. t['Iacute'] = 278;
  18870. t['plusminus'] = 584;
  18871. t['brokenbar'] = 280;
  18872. t['registered'] = 737;
  18873. t['Gbreve'] = 778;
  18874. t['Idotaccent'] = 278;
  18875. t['summation'] = 600;
  18876. t['Egrave'] = 667;
  18877. t['racute'] = 389;
  18878. t['omacron'] = 611;
  18879. t['Zacute'] = 611;
  18880. t['Zcaron'] = 611;
  18881. t['greaterequal'] = 549;
  18882. t['Eth'] = 722;
  18883. t['Ccedilla'] = 722;
  18884. t['lcommaaccent'] = 278;
  18885. t['tcaron'] = 389;
  18886. t['eogonek'] = 556;
  18887. t['Uogonek'] = 722;
  18888. t['Aacute'] = 722;
  18889. t['Adieresis'] = 722;
  18890. t['egrave'] = 556;
  18891. t['zacute'] = 500;
  18892. t['iogonek'] = 278;
  18893. t['Oacute'] = 778;
  18894. t['oacute'] = 611;
  18895. t['amacron'] = 556;
  18896. t['sacute'] = 556;
  18897. t['idieresis'] = 278;
  18898. t['Ocircumflex'] = 778;
  18899. t['Ugrave'] = 722;
  18900. t['Delta'] = 612;
  18901. t['thorn'] = 611;
  18902. t['twosuperior'] = 333;
  18903. t['Odieresis'] = 778;
  18904. t['mu'] = 611;
  18905. t['igrave'] = 278;
  18906. t['ohungarumlaut'] = 611;
  18907. t['Eogonek'] = 667;
  18908. t['dcroat'] = 611;
  18909. t['threequarters'] = 834;
  18910. t['Scedilla'] = 667;
  18911. t['lcaron'] = 400;
  18912. t['Kcommaaccent'] = 722;
  18913. t['Lacute'] = 611;
  18914. t['trademark'] = 1000;
  18915. t['edotaccent'] = 556;
  18916. t['Igrave'] = 278;
  18917. t['Imacron'] = 278;
  18918. t['Lcaron'] = 611;
  18919. t['onehalf'] = 834;
  18920. t['lessequal'] = 549;
  18921. t['ocircumflex'] = 611;
  18922. t['ntilde'] = 611;
  18923. t['Uhungarumlaut'] = 722;
  18924. t['Eacute'] = 667;
  18925. t['emacron'] = 556;
  18926. t['gbreve'] = 611;
  18927. t['onequarter'] = 834;
  18928. t['Scaron'] = 667;
  18929. t['Scommaaccent'] = 667;
  18930. t['Ohungarumlaut'] = 778;
  18931. t['degree'] = 400;
  18932. t['ograve'] = 611;
  18933. t['Ccaron'] = 722;
  18934. t['ugrave'] = 611;
  18935. t['radical'] = 549;
  18936. t['Dcaron'] = 722;
  18937. t['rcommaaccent'] = 389;
  18938. t['Ntilde'] = 722;
  18939. t['otilde'] = 611;
  18940. t['Rcommaaccent'] = 722;
  18941. t['Lcommaaccent'] = 611;
  18942. t['Atilde'] = 722;
  18943. t['Aogonek'] = 722;
  18944. t['Aring'] = 722;
  18945. t['Otilde'] = 778;
  18946. t['zdotaccent'] = 500;
  18947. t['Ecaron'] = 667;
  18948. t['Iogonek'] = 278;
  18949. t['kcommaaccent'] = 556;
  18950. t['minus'] = 584;
  18951. t['Icircumflex'] = 278;
  18952. t['ncaron'] = 611;
  18953. t['tcommaaccent'] = 333;
  18954. t['logicalnot'] = 584;
  18955. t['odieresis'] = 611;
  18956. t['udieresis'] = 611;
  18957. t['notequal'] = 549;
  18958. t['gcommaaccent'] = 611;
  18959. t['eth'] = 611;
  18960. t['zcaron'] = 500;
  18961. t['ncommaaccent'] = 611;
  18962. t['onesuperior'] = 333;
  18963. t['imacron'] = 278;
  18964. t['Euro'] = 556;
  18965. });
  18966. t['Helvetica-Oblique'] = getLookupTableFactory(function (t) {
  18967. t['space'] = 278;
  18968. t['exclam'] = 278;
  18969. t['quotedbl'] = 355;
  18970. t['numbersign'] = 556;
  18971. t['dollar'] = 556;
  18972. t['percent'] = 889;
  18973. t['ampersand'] = 667;
  18974. t['quoteright'] = 222;
  18975. t['parenleft'] = 333;
  18976. t['parenright'] = 333;
  18977. t['asterisk'] = 389;
  18978. t['plus'] = 584;
  18979. t['comma'] = 278;
  18980. t['hyphen'] = 333;
  18981. t['period'] = 278;
  18982. t['slash'] = 278;
  18983. t['zero'] = 556;
  18984. t['one'] = 556;
  18985. t['two'] = 556;
  18986. t['three'] = 556;
  18987. t['four'] = 556;
  18988. t['five'] = 556;
  18989. t['six'] = 556;
  18990. t['seven'] = 556;
  18991. t['eight'] = 556;
  18992. t['nine'] = 556;
  18993. t['colon'] = 278;
  18994. t['semicolon'] = 278;
  18995. t['less'] = 584;
  18996. t['equal'] = 584;
  18997. t['greater'] = 584;
  18998. t['question'] = 556;
  18999. t['at'] = 1015;
  19000. t['A'] = 667;
  19001. t['B'] = 667;
  19002. t['C'] = 722;
  19003. t['D'] = 722;
  19004. t['E'] = 667;
  19005. t['F'] = 611;
  19006. t['G'] = 778;
  19007. t['H'] = 722;
  19008. t['I'] = 278;
  19009. t['J'] = 500;
  19010. t['K'] = 667;
  19011. t['L'] = 556;
  19012. t['M'] = 833;
  19013. t['N'] = 722;
  19014. t['O'] = 778;
  19015. t['P'] = 667;
  19016. t['Q'] = 778;
  19017. t['R'] = 722;
  19018. t['S'] = 667;
  19019. t['T'] = 611;
  19020. t['U'] = 722;
  19021. t['V'] = 667;
  19022. t['W'] = 944;
  19023. t['X'] = 667;
  19024. t['Y'] = 667;
  19025. t['Z'] = 611;
  19026. t['bracketleft'] = 278;
  19027. t['backslash'] = 278;
  19028. t['bracketright'] = 278;
  19029. t['asciicircum'] = 469;
  19030. t['underscore'] = 556;
  19031. t['quoteleft'] = 222;
  19032. t['a'] = 556;
  19033. t['b'] = 556;
  19034. t['c'] = 500;
  19035. t['d'] = 556;
  19036. t['e'] = 556;
  19037. t['f'] = 278;
  19038. t['g'] = 556;
  19039. t['h'] = 556;
  19040. t['i'] = 222;
  19041. t['j'] = 222;
  19042. t['k'] = 500;
  19043. t['l'] = 222;
  19044. t['m'] = 833;
  19045. t['n'] = 556;
  19046. t['o'] = 556;
  19047. t['p'] = 556;
  19048. t['q'] = 556;
  19049. t['r'] = 333;
  19050. t['s'] = 500;
  19051. t['t'] = 278;
  19052. t['u'] = 556;
  19053. t['v'] = 500;
  19054. t['w'] = 722;
  19055. t['x'] = 500;
  19056. t['y'] = 500;
  19057. t['z'] = 500;
  19058. t['braceleft'] = 334;
  19059. t['bar'] = 260;
  19060. t['braceright'] = 334;
  19061. t['asciitilde'] = 584;
  19062. t['exclamdown'] = 333;
  19063. t['cent'] = 556;
  19064. t['sterling'] = 556;
  19065. t['fraction'] = 167;
  19066. t['yen'] = 556;
  19067. t['florin'] = 556;
  19068. t['section'] = 556;
  19069. t['currency'] = 556;
  19070. t['quotesingle'] = 191;
  19071. t['quotedblleft'] = 333;
  19072. t['guillemotleft'] = 556;
  19073. t['guilsinglleft'] = 333;
  19074. t['guilsinglright'] = 333;
  19075. t['fi'] = 500;
  19076. t['fl'] = 500;
  19077. t['endash'] = 556;
  19078. t['dagger'] = 556;
  19079. t['daggerdbl'] = 556;
  19080. t['periodcentered'] = 278;
  19081. t['paragraph'] = 537;
  19082. t['bullet'] = 350;
  19083. t['quotesinglbase'] = 222;
  19084. t['quotedblbase'] = 333;
  19085. t['quotedblright'] = 333;
  19086. t['guillemotright'] = 556;
  19087. t['ellipsis'] = 1000;
  19088. t['perthousand'] = 1000;
  19089. t['questiondown'] = 611;
  19090. t['grave'] = 333;
  19091. t['acute'] = 333;
  19092. t['circumflex'] = 333;
  19093. t['tilde'] = 333;
  19094. t['macron'] = 333;
  19095. t['breve'] = 333;
  19096. t['dotaccent'] = 333;
  19097. t['dieresis'] = 333;
  19098. t['ring'] = 333;
  19099. t['cedilla'] = 333;
  19100. t['hungarumlaut'] = 333;
  19101. t['ogonek'] = 333;
  19102. t['caron'] = 333;
  19103. t['emdash'] = 1000;
  19104. t['AE'] = 1000;
  19105. t['ordfeminine'] = 370;
  19106. t['Lslash'] = 556;
  19107. t['Oslash'] = 778;
  19108. t['OE'] = 1000;
  19109. t['ordmasculine'] = 365;
  19110. t['ae'] = 889;
  19111. t['dotlessi'] = 278;
  19112. t['lslash'] = 222;
  19113. t['oslash'] = 611;
  19114. t['oe'] = 944;
  19115. t['germandbls'] = 611;
  19116. t['Idieresis'] = 278;
  19117. t['eacute'] = 556;
  19118. t['abreve'] = 556;
  19119. t['uhungarumlaut'] = 556;
  19120. t['ecaron'] = 556;
  19121. t['Ydieresis'] = 667;
  19122. t['divide'] = 584;
  19123. t['Yacute'] = 667;
  19124. t['Acircumflex'] = 667;
  19125. t['aacute'] = 556;
  19126. t['Ucircumflex'] = 722;
  19127. t['yacute'] = 500;
  19128. t['scommaaccent'] = 500;
  19129. t['ecircumflex'] = 556;
  19130. t['Uring'] = 722;
  19131. t['Udieresis'] = 722;
  19132. t['aogonek'] = 556;
  19133. t['Uacute'] = 722;
  19134. t['uogonek'] = 556;
  19135. t['Edieresis'] = 667;
  19136. t['Dcroat'] = 722;
  19137. t['commaaccent'] = 250;
  19138. t['copyright'] = 737;
  19139. t['Emacron'] = 667;
  19140. t['ccaron'] = 500;
  19141. t['aring'] = 556;
  19142. t['Ncommaaccent'] = 722;
  19143. t['lacute'] = 222;
  19144. t['agrave'] = 556;
  19145. t['Tcommaaccent'] = 611;
  19146. t['Cacute'] = 722;
  19147. t['atilde'] = 556;
  19148. t['Edotaccent'] = 667;
  19149. t['scaron'] = 500;
  19150. t['scedilla'] = 500;
  19151. t['iacute'] = 278;
  19152. t['lozenge'] = 471;
  19153. t['Rcaron'] = 722;
  19154. t['Gcommaaccent'] = 778;
  19155. t['ucircumflex'] = 556;
  19156. t['acircumflex'] = 556;
  19157. t['Amacron'] = 667;
  19158. t['rcaron'] = 333;
  19159. t['ccedilla'] = 500;
  19160. t['Zdotaccent'] = 611;
  19161. t['Thorn'] = 667;
  19162. t['Omacron'] = 778;
  19163. t['Racute'] = 722;
  19164. t['Sacute'] = 667;
  19165. t['dcaron'] = 643;
  19166. t['Umacron'] = 722;
  19167. t['uring'] = 556;
  19168. t['threesuperior'] = 333;
  19169. t['Ograve'] = 778;
  19170. t['Agrave'] = 667;
  19171. t['Abreve'] = 667;
  19172. t['multiply'] = 584;
  19173. t['uacute'] = 556;
  19174. t['Tcaron'] = 611;
  19175. t['partialdiff'] = 476;
  19176. t['ydieresis'] = 500;
  19177. t['Nacute'] = 722;
  19178. t['icircumflex'] = 278;
  19179. t['Ecircumflex'] = 667;
  19180. t['adieresis'] = 556;
  19181. t['edieresis'] = 556;
  19182. t['cacute'] = 500;
  19183. t['nacute'] = 556;
  19184. t['umacron'] = 556;
  19185. t['Ncaron'] = 722;
  19186. t['Iacute'] = 278;
  19187. t['plusminus'] = 584;
  19188. t['brokenbar'] = 260;
  19189. t['registered'] = 737;
  19190. t['Gbreve'] = 778;
  19191. t['Idotaccent'] = 278;
  19192. t['summation'] = 600;
  19193. t['Egrave'] = 667;
  19194. t['racute'] = 333;
  19195. t['omacron'] = 556;
  19196. t['Zacute'] = 611;
  19197. t['Zcaron'] = 611;
  19198. t['greaterequal'] = 549;
  19199. t['Eth'] = 722;
  19200. t['Ccedilla'] = 722;
  19201. t['lcommaaccent'] = 222;
  19202. t['tcaron'] = 317;
  19203. t['eogonek'] = 556;
  19204. t['Uogonek'] = 722;
  19205. t['Aacute'] = 667;
  19206. t['Adieresis'] = 667;
  19207. t['egrave'] = 556;
  19208. t['zacute'] = 500;
  19209. t['iogonek'] = 222;
  19210. t['Oacute'] = 778;
  19211. t['oacute'] = 556;
  19212. t['amacron'] = 556;
  19213. t['sacute'] = 500;
  19214. t['idieresis'] = 278;
  19215. t['Ocircumflex'] = 778;
  19216. t['Ugrave'] = 722;
  19217. t['Delta'] = 612;
  19218. t['thorn'] = 556;
  19219. t['twosuperior'] = 333;
  19220. t['Odieresis'] = 778;
  19221. t['mu'] = 556;
  19222. t['igrave'] = 278;
  19223. t['ohungarumlaut'] = 556;
  19224. t['Eogonek'] = 667;
  19225. t['dcroat'] = 556;
  19226. t['threequarters'] = 834;
  19227. t['Scedilla'] = 667;
  19228. t['lcaron'] = 299;
  19229. t['Kcommaaccent'] = 667;
  19230. t['Lacute'] = 556;
  19231. t['trademark'] = 1000;
  19232. t['edotaccent'] = 556;
  19233. t['Igrave'] = 278;
  19234. t['Imacron'] = 278;
  19235. t['Lcaron'] = 556;
  19236. t['onehalf'] = 834;
  19237. t['lessequal'] = 549;
  19238. t['ocircumflex'] = 556;
  19239. t['ntilde'] = 556;
  19240. t['Uhungarumlaut'] = 722;
  19241. t['Eacute'] = 667;
  19242. t['emacron'] = 556;
  19243. t['gbreve'] = 556;
  19244. t['onequarter'] = 834;
  19245. t['Scaron'] = 667;
  19246. t['Scommaaccent'] = 667;
  19247. t['Ohungarumlaut'] = 778;
  19248. t['degree'] = 400;
  19249. t['ograve'] = 556;
  19250. t['Ccaron'] = 722;
  19251. t['ugrave'] = 556;
  19252. t['radical'] = 453;
  19253. t['Dcaron'] = 722;
  19254. t['rcommaaccent'] = 333;
  19255. t['Ntilde'] = 722;
  19256. t['otilde'] = 556;
  19257. t['Rcommaaccent'] = 722;
  19258. t['Lcommaaccent'] = 556;
  19259. t['Atilde'] = 667;
  19260. t['Aogonek'] = 667;
  19261. t['Aring'] = 667;
  19262. t['Otilde'] = 778;
  19263. t['zdotaccent'] = 500;
  19264. t['Ecaron'] = 667;
  19265. t['Iogonek'] = 278;
  19266. t['kcommaaccent'] = 500;
  19267. t['minus'] = 584;
  19268. t['Icircumflex'] = 278;
  19269. t['ncaron'] = 556;
  19270. t['tcommaaccent'] = 278;
  19271. t['logicalnot'] = 584;
  19272. t['odieresis'] = 556;
  19273. t['udieresis'] = 556;
  19274. t['notequal'] = 549;
  19275. t['gcommaaccent'] = 556;
  19276. t['eth'] = 556;
  19277. t['zcaron'] = 500;
  19278. t['ncommaaccent'] = 556;
  19279. t['onesuperior'] = 333;
  19280. t['imacron'] = 278;
  19281. t['Euro'] = 556;
  19282. });
  19283. t['Symbol'] = getLookupTableFactory(function (t) {
  19284. t['space'] = 250;
  19285. t['exclam'] = 333;
  19286. t['universal'] = 713;
  19287. t['numbersign'] = 500;
  19288. t['existential'] = 549;
  19289. t['percent'] = 833;
  19290. t['ampersand'] = 778;
  19291. t['suchthat'] = 439;
  19292. t['parenleft'] = 333;
  19293. t['parenright'] = 333;
  19294. t['asteriskmath'] = 500;
  19295. t['plus'] = 549;
  19296. t['comma'] = 250;
  19297. t['minus'] = 549;
  19298. t['period'] = 250;
  19299. t['slash'] = 278;
  19300. t['zero'] = 500;
  19301. t['one'] = 500;
  19302. t['two'] = 500;
  19303. t['three'] = 500;
  19304. t['four'] = 500;
  19305. t['five'] = 500;
  19306. t['six'] = 500;
  19307. t['seven'] = 500;
  19308. t['eight'] = 500;
  19309. t['nine'] = 500;
  19310. t['colon'] = 278;
  19311. t['semicolon'] = 278;
  19312. t['less'] = 549;
  19313. t['equal'] = 549;
  19314. t['greater'] = 549;
  19315. t['question'] = 444;
  19316. t['congruent'] = 549;
  19317. t['Alpha'] = 722;
  19318. t['Beta'] = 667;
  19319. t['Chi'] = 722;
  19320. t['Delta'] = 612;
  19321. t['Epsilon'] = 611;
  19322. t['Phi'] = 763;
  19323. t['Gamma'] = 603;
  19324. t['Eta'] = 722;
  19325. t['Iota'] = 333;
  19326. t['theta1'] = 631;
  19327. t['Kappa'] = 722;
  19328. t['Lambda'] = 686;
  19329. t['Mu'] = 889;
  19330. t['Nu'] = 722;
  19331. t['Omicron'] = 722;
  19332. t['Pi'] = 768;
  19333. t['Theta'] = 741;
  19334. t['Rho'] = 556;
  19335. t['Sigma'] = 592;
  19336. t['Tau'] = 611;
  19337. t['Upsilon'] = 690;
  19338. t['sigma1'] = 439;
  19339. t['Omega'] = 768;
  19340. t['Xi'] = 645;
  19341. t['Psi'] = 795;
  19342. t['Zeta'] = 611;
  19343. t['bracketleft'] = 333;
  19344. t['therefore'] = 863;
  19345. t['bracketright'] = 333;
  19346. t['perpendicular'] = 658;
  19347. t['underscore'] = 500;
  19348. t['radicalex'] = 500;
  19349. t['alpha'] = 631;
  19350. t['beta'] = 549;
  19351. t['chi'] = 549;
  19352. t['delta'] = 494;
  19353. t['epsilon'] = 439;
  19354. t['phi'] = 521;
  19355. t['gamma'] = 411;
  19356. t['eta'] = 603;
  19357. t['iota'] = 329;
  19358. t['phi1'] = 603;
  19359. t['kappa'] = 549;
  19360. t['lambda'] = 549;
  19361. t['mu'] = 576;
  19362. t['nu'] = 521;
  19363. t['omicron'] = 549;
  19364. t['pi'] = 549;
  19365. t['theta'] = 521;
  19366. t['rho'] = 549;
  19367. t['sigma'] = 603;
  19368. t['tau'] = 439;
  19369. t['upsilon'] = 576;
  19370. t['omega1'] = 713;
  19371. t['omega'] = 686;
  19372. t['xi'] = 493;
  19373. t['psi'] = 686;
  19374. t['zeta'] = 494;
  19375. t['braceleft'] = 480;
  19376. t['bar'] = 200;
  19377. t['braceright'] = 480;
  19378. t['similar'] = 549;
  19379. t['Euro'] = 750;
  19380. t['Upsilon1'] = 620;
  19381. t['minute'] = 247;
  19382. t['lessequal'] = 549;
  19383. t['fraction'] = 167;
  19384. t['infinity'] = 713;
  19385. t['florin'] = 500;
  19386. t['club'] = 753;
  19387. t['diamond'] = 753;
  19388. t['heart'] = 753;
  19389. t['spade'] = 753;
  19390. t['arrowboth'] = 1042;
  19391. t['arrowleft'] = 987;
  19392. t['arrowup'] = 603;
  19393. t['arrowright'] = 987;
  19394. t['arrowdown'] = 603;
  19395. t['degree'] = 400;
  19396. t['plusminus'] = 549;
  19397. t['second'] = 411;
  19398. t['greaterequal'] = 549;
  19399. t['multiply'] = 549;
  19400. t['proportional'] = 713;
  19401. t['partialdiff'] = 494;
  19402. t['bullet'] = 460;
  19403. t['divide'] = 549;
  19404. t['notequal'] = 549;
  19405. t['equivalence'] = 549;
  19406. t['approxequal'] = 549;
  19407. t['ellipsis'] = 1000;
  19408. t['arrowvertex'] = 603;
  19409. t['arrowhorizex'] = 1000;
  19410. t['carriagereturn'] = 658;
  19411. t['aleph'] = 823;
  19412. t['Ifraktur'] = 686;
  19413. t['Rfraktur'] = 795;
  19414. t['weierstrass'] = 987;
  19415. t['circlemultiply'] = 768;
  19416. t['circleplus'] = 768;
  19417. t['emptyset'] = 823;
  19418. t['intersection'] = 768;
  19419. t['union'] = 768;
  19420. t['propersuperset'] = 713;
  19421. t['reflexsuperset'] = 713;
  19422. t['notsubset'] = 713;
  19423. t['propersubset'] = 713;
  19424. t['reflexsubset'] = 713;
  19425. t['element'] = 713;
  19426. t['notelement'] = 713;
  19427. t['angle'] = 768;
  19428. t['gradient'] = 713;
  19429. t['registerserif'] = 790;
  19430. t['copyrightserif'] = 790;
  19431. t['trademarkserif'] = 890;
  19432. t['product'] = 823;
  19433. t['radical'] = 549;
  19434. t['dotmath'] = 250;
  19435. t['logicalnot'] = 713;
  19436. t['logicaland'] = 603;
  19437. t['logicalor'] = 603;
  19438. t['arrowdblboth'] = 1042;
  19439. t['arrowdblleft'] = 987;
  19440. t['arrowdblup'] = 603;
  19441. t['arrowdblright'] = 987;
  19442. t['arrowdbldown'] = 603;
  19443. t['lozenge'] = 494;
  19444. t['angleleft'] = 329;
  19445. t['registersans'] = 790;
  19446. t['copyrightsans'] = 790;
  19447. t['trademarksans'] = 786;
  19448. t['summation'] = 713;
  19449. t['parenlefttp'] = 384;
  19450. t['parenleftex'] = 384;
  19451. t['parenleftbt'] = 384;
  19452. t['bracketlefttp'] = 384;
  19453. t['bracketleftex'] = 384;
  19454. t['bracketleftbt'] = 384;
  19455. t['bracelefttp'] = 494;
  19456. t['braceleftmid'] = 494;
  19457. t['braceleftbt'] = 494;
  19458. t['braceex'] = 494;
  19459. t['angleright'] = 329;
  19460. t['integral'] = 274;
  19461. t['integraltp'] = 686;
  19462. t['integralex'] = 686;
  19463. t['integralbt'] = 686;
  19464. t['parenrighttp'] = 384;
  19465. t['parenrightex'] = 384;
  19466. t['parenrightbt'] = 384;
  19467. t['bracketrighttp'] = 384;
  19468. t['bracketrightex'] = 384;
  19469. t['bracketrightbt'] = 384;
  19470. t['bracerighttp'] = 494;
  19471. t['bracerightmid'] = 494;
  19472. t['bracerightbt'] = 494;
  19473. t['apple'] = 790;
  19474. });
  19475. t['Times-Roman'] = getLookupTableFactory(function (t) {
  19476. t['space'] = 250;
  19477. t['exclam'] = 333;
  19478. t['quotedbl'] = 408;
  19479. t['numbersign'] = 500;
  19480. t['dollar'] = 500;
  19481. t['percent'] = 833;
  19482. t['ampersand'] = 778;
  19483. t['quoteright'] = 333;
  19484. t['parenleft'] = 333;
  19485. t['parenright'] = 333;
  19486. t['asterisk'] = 500;
  19487. t['plus'] = 564;
  19488. t['comma'] = 250;
  19489. t['hyphen'] = 333;
  19490. t['period'] = 250;
  19491. t['slash'] = 278;
  19492. t['zero'] = 500;
  19493. t['one'] = 500;
  19494. t['two'] = 500;
  19495. t['three'] = 500;
  19496. t['four'] = 500;
  19497. t['five'] = 500;
  19498. t['six'] = 500;
  19499. t['seven'] = 500;
  19500. t['eight'] = 500;
  19501. t['nine'] = 500;
  19502. t['colon'] = 278;
  19503. t['semicolon'] = 278;
  19504. t['less'] = 564;
  19505. t['equal'] = 564;
  19506. t['greater'] = 564;
  19507. t['question'] = 444;
  19508. t['at'] = 921;
  19509. t['A'] = 722;
  19510. t['B'] = 667;
  19511. t['C'] = 667;
  19512. t['D'] = 722;
  19513. t['E'] = 611;
  19514. t['F'] = 556;
  19515. t['G'] = 722;
  19516. t['H'] = 722;
  19517. t['I'] = 333;
  19518. t['J'] = 389;
  19519. t['K'] = 722;
  19520. t['L'] = 611;
  19521. t['M'] = 889;
  19522. t['N'] = 722;
  19523. t['O'] = 722;
  19524. t['P'] = 556;
  19525. t['Q'] = 722;
  19526. t['R'] = 667;
  19527. t['S'] = 556;
  19528. t['T'] = 611;
  19529. t['U'] = 722;
  19530. t['V'] = 722;
  19531. t['W'] = 944;
  19532. t['X'] = 722;
  19533. t['Y'] = 722;
  19534. t['Z'] = 611;
  19535. t['bracketleft'] = 333;
  19536. t['backslash'] = 278;
  19537. t['bracketright'] = 333;
  19538. t['asciicircum'] = 469;
  19539. t['underscore'] = 500;
  19540. t['quoteleft'] = 333;
  19541. t['a'] = 444;
  19542. t['b'] = 500;
  19543. t['c'] = 444;
  19544. t['d'] = 500;
  19545. t['e'] = 444;
  19546. t['f'] = 333;
  19547. t['g'] = 500;
  19548. t['h'] = 500;
  19549. t['i'] = 278;
  19550. t['j'] = 278;
  19551. t['k'] = 500;
  19552. t['l'] = 278;
  19553. t['m'] = 778;
  19554. t['n'] = 500;
  19555. t['o'] = 500;
  19556. t['p'] = 500;
  19557. t['q'] = 500;
  19558. t['r'] = 333;
  19559. t['s'] = 389;
  19560. t['t'] = 278;
  19561. t['u'] = 500;
  19562. t['v'] = 500;
  19563. t['w'] = 722;
  19564. t['x'] = 500;
  19565. t['y'] = 500;
  19566. t['z'] = 444;
  19567. t['braceleft'] = 480;
  19568. t['bar'] = 200;
  19569. t['braceright'] = 480;
  19570. t['asciitilde'] = 541;
  19571. t['exclamdown'] = 333;
  19572. t['cent'] = 500;
  19573. t['sterling'] = 500;
  19574. t['fraction'] = 167;
  19575. t['yen'] = 500;
  19576. t['florin'] = 500;
  19577. t['section'] = 500;
  19578. t['currency'] = 500;
  19579. t['quotesingle'] = 180;
  19580. t['quotedblleft'] = 444;
  19581. t['guillemotleft'] = 500;
  19582. t['guilsinglleft'] = 333;
  19583. t['guilsinglright'] = 333;
  19584. t['fi'] = 556;
  19585. t['fl'] = 556;
  19586. t['endash'] = 500;
  19587. t['dagger'] = 500;
  19588. t['daggerdbl'] = 500;
  19589. t['periodcentered'] = 250;
  19590. t['paragraph'] = 453;
  19591. t['bullet'] = 350;
  19592. t['quotesinglbase'] = 333;
  19593. t['quotedblbase'] = 444;
  19594. t['quotedblright'] = 444;
  19595. t['guillemotright'] = 500;
  19596. t['ellipsis'] = 1000;
  19597. t['perthousand'] = 1000;
  19598. t['questiondown'] = 444;
  19599. t['grave'] = 333;
  19600. t['acute'] = 333;
  19601. t['circumflex'] = 333;
  19602. t['tilde'] = 333;
  19603. t['macron'] = 333;
  19604. t['breve'] = 333;
  19605. t['dotaccent'] = 333;
  19606. t['dieresis'] = 333;
  19607. t['ring'] = 333;
  19608. t['cedilla'] = 333;
  19609. t['hungarumlaut'] = 333;
  19610. t['ogonek'] = 333;
  19611. t['caron'] = 333;
  19612. t['emdash'] = 1000;
  19613. t['AE'] = 889;
  19614. t['ordfeminine'] = 276;
  19615. t['Lslash'] = 611;
  19616. t['Oslash'] = 722;
  19617. t['OE'] = 889;
  19618. t['ordmasculine'] = 310;
  19619. t['ae'] = 667;
  19620. t['dotlessi'] = 278;
  19621. t['lslash'] = 278;
  19622. t['oslash'] = 500;
  19623. t['oe'] = 722;
  19624. t['germandbls'] = 500;
  19625. t['Idieresis'] = 333;
  19626. t['eacute'] = 444;
  19627. t['abreve'] = 444;
  19628. t['uhungarumlaut'] = 500;
  19629. t['ecaron'] = 444;
  19630. t['Ydieresis'] = 722;
  19631. t['divide'] = 564;
  19632. t['Yacute'] = 722;
  19633. t['Acircumflex'] = 722;
  19634. t['aacute'] = 444;
  19635. t['Ucircumflex'] = 722;
  19636. t['yacute'] = 500;
  19637. t['scommaaccent'] = 389;
  19638. t['ecircumflex'] = 444;
  19639. t['Uring'] = 722;
  19640. t['Udieresis'] = 722;
  19641. t['aogonek'] = 444;
  19642. t['Uacute'] = 722;
  19643. t['uogonek'] = 500;
  19644. t['Edieresis'] = 611;
  19645. t['Dcroat'] = 722;
  19646. t['commaaccent'] = 250;
  19647. t['copyright'] = 760;
  19648. t['Emacron'] = 611;
  19649. t['ccaron'] = 444;
  19650. t['aring'] = 444;
  19651. t['Ncommaaccent'] = 722;
  19652. t['lacute'] = 278;
  19653. t['agrave'] = 444;
  19654. t['Tcommaaccent'] = 611;
  19655. t['Cacute'] = 667;
  19656. t['atilde'] = 444;
  19657. t['Edotaccent'] = 611;
  19658. t['scaron'] = 389;
  19659. t['scedilla'] = 389;
  19660. t['iacute'] = 278;
  19661. t['lozenge'] = 471;
  19662. t['Rcaron'] = 667;
  19663. t['Gcommaaccent'] = 722;
  19664. t['ucircumflex'] = 500;
  19665. t['acircumflex'] = 444;
  19666. t['Amacron'] = 722;
  19667. t['rcaron'] = 333;
  19668. t['ccedilla'] = 444;
  19669. t['Zdotaccent'] = 611;
  19670. t['Thorn'] = 556;
  19671. t['Omacron'] = 722;
  19672. t['Racute'] = 667;
  19673. t['Sacute'] = 556;
  19674. t['dcaron'] = 588;
  19675. t['Umacron'] = 722;
  19676. t['uring'] = 500;
  19677. t['threesuperior'] = 300;
  19678. t['Ograve'] = 722;
  19679. t['Agrave'] = 722;
  19680. t['Abreve'] = 722;
  19681. t['multiply'] = 564;
  19682. t['uacute'] = 500;
  19683. t['Tcaron'] = 611;
  19684. t['partialdiff'] = 476;
  19685. t['ydieresis'] = 500;
  19686. t['Nacute'] = 722;
  19687. t['icircumflex'] = 278;
  19688. t['Ecircumflex'] = 611;
  19689. t['adieresis'] = 444;
  19690. t['edieresis'] = 444;
  19691. t['cacute'] = 444;
  19692. t['nacute'] = 500;
  19693. t['umacron'] = 500;
  19694. t['Ncaron'] = 722;
  19695. t['Iacute'] = 333;
  19696. t['plusminus'] = 564;
  19697. t['brokenbar'] = 200;
  19698. t['registered'] = 760;
  19699. t['Gbreve'] = 722;
  19700. t['Idotaccent'] = 333;
  19701. t['summation'] = 600;
  19702. t['Egrave'] = 611;
  19703. t['racute'] = 333;
  19704. t['omacron'] = 500;
  19705. t['Zacute'] = 611;
  19706. t['Zcaron'] = 611;
  19707. t['greaterequal'] = 549;
  19708. t['Eth'] = 722;
  19709. t['Ccedilla'] = 667;
  19710. t['lcommaaccent'] = 278;
  19711. t['tcaron'] = 326;
  19712. t['eogonek'] = 444;
  19713. t['Uogonek'] = 722;
  19714. t['Aacute'] = 722;
  19715. t['Adieresis'] = 722;
  19716. t['egrave'] = 444;
  19717. t['zacute'] = 444;
  19718. t['iogonek'] = 278;
  19719. t['Oacute'] = 722;
  19720. t['oacute'] = 500;
  19721. t['amacron'] = 444;
  19722. t['sacute'] = 389;
  19723. t['idieresis'] = 278;
  19724. t['Ocircumflex'] = 722;
  19725. t['Ugrave'] = 722;
  19726. t['Delta'] = 612;
  19727. t['thorn'] = 500;
  19728. t['twosuperior'] = 300;
  19729. t['Odieresis'] = 722;
  19730. t['mu'] = 500;
  19731. t['igrave'] = 278;
  19732. t['ohungarumlaut'] = 500;
  19733. t['Eogonek'] = 611;
  19734. t['dcroat'] = 500;
  19735. t['threequarters'] = 750;
  19736. t['Scedilla'] = 556;
  19737. t['lcaron'] = 344;
  19738. t['Kcommaaccent'] = 722;
  19739. t['Lacute'] = 611;
  19740. t['trademark'] = 980;
  19741. t['edotaccent'] = 444;
  19742. t['Igrave'] = 333;
  19743. t['Imacron'] = 333;
  19744. t['Lcaron'] = 611;
  19745. t['onehalf'] = 750;
  19746. t['lessequal'] = 549;
  19747. t['ocircumflex'] = 500;
  19748. t['ntilde'] = 500;
  19749. t['Uhungarumlaut'] = 722;
  19750. t['Eacute'] = 611;
  19751. t['emacron'] = 444;
  19752. t['gbreve'] = 500;
  19753. t['onequarter'] = 750;
  19754. t['Scaron'] = 556;
  19755. t['Scommaaccent'] = 556;
  19756. t['Ohungarumlaut'] = 722;
  19757. t['degree'] = 400;
  19758. t['ograve'] = 500;
  19759. t['Ccaron'] = 667;
  19760. t['ugrave'] = 500;
  19761. t['radical'] = 453;
  19762. t['Dcaron'] = 722;
  19763. t['rcommaaccent'] = 333;
  19764. t['Ntilde'] = 722;
  19765. t['otilde'] = 500;
  19766. t['Rcommaaccent'] = 667;
  19767. t['Lcommaaccent'] = 611;
  19768. t['Atilde'] = 722;
  19769. t['Aogonek'] = 722;
  19770. t['Aring'] = 722;
  19771. t['Otilde'] = 722;
  19772. t['zdotaccent'] = 444;
  19773. t['Ecaron'] = 611;
  19774. t['Iogonek'] = 333;
  19775. t['kcommaaccent'] = 500;
  19776. t['minus'] = 564;
  19777. t['Icircumflex'] = 333;
  19778. t['ncaron'] = 500;
  19779. t['tcommaaccent'] = 278;
  19780. t['logicalnot'] = 564;
  19781. t['odieresis'] = 500;
  19782. t['udieresis'] = 500;
  19783. t['notequal'] = 549;
  19784. t['gcommaaccent'] = 500;
  19785. t['eth'] = 500;
  19786. t['zcaron'] = 444;
  19787. t['ncommaaccent'] = 500;
  19788. t['onesuperior'] = 300;
  19789. t['imacron'] = 278;
  19790. t['Euro'] = 500;
  19791. });
  19792. t['Times-Bold'] = getLookupTableFactory(function (t) {
  19793. t['space'] = 250;
  19794. t['exclam'] = 333;
  19795. t['quotedbl'] = 555;
  19796. t['numbersign'] = 500;
  19797. t['dollar'] = 500;
  19798. t['percent'] = 1000;
  19799. t['ampersand'] = 833;
  19800. t['quoteright'] = 333;
  19801. t['parenleft'] = 333;
  19802. t['parenright'] = 333;
  19803. t['asterisk'] = 500;
  19804. t['plus'] = 570;
  19805. t['comma'] = 250;
  19806. t['hyphen'] = 333;
  19807. t['period'] = 250;
  19808. t['slash'] = 278;
  19809. t['zero'] = 500;
  19810. t['one'] = 500;
  19811. t['two'] = 500;
  19812. t['three'] = 500;
  19813. t['four'] = 500;
  19814. t['five'] = 500;
  19815. t['six'] = 500;
  19816. t['seven'] = 500;
  19817. t['eight'] = 500;
  19818. t['nine'] = 500;
  19819. t['colon'] = 333;
  19820. t['semicolon'] = 333;
  19821. t['less'] = 570;
  19822. t['equal'] = 570;
  19823. t['greater'] = 570;
  19824. t['question'] = 500;
  19825. t['at'] = 930;
  19826. t['A'] = 722;
  19827. t['B'] = 667;
  19828. t['C'] = 722;
  19829. t['D'] = 722;
  19830. t['E'] = 667;
  19831. t['F'] = 611;
  19832. t['G'] = 778;
  19833. t['H'] = 778;
  19834. t['I'] = 389;
  19835. t['J'] = 500;
  19836. t['K'] = 778;
  19837. t['L'] = 667;
  19838. t['M'] = 944;
  19839. t['N'] = 722;
  19840. t['O'] = 778;
  19841. t['P'] = 611;
  19842. t['Q'] = 778;
  19843. t['R'] = 722;
  19844. t['S'] = 556;
  19845. t['T'] = 667;
  19846. t['U'] = 722;
  19847. t['V'] = 722;
  19848. t['W'] = 1000;
  19849. t['X'] = 722;
  19850. t['Y'] = 722;
  19851. t['Z'] = 667;
  19852. t['bracketleft'] = 333;
  19853. t['backslash'] = 278;
  19854. t['bracketright'] = 333;
  19855. t['asciicircum'] = 581;
  19856. t['underscore'] = 500;
  19857. t['quoteleft'] = 333;
  19858. t['a'] = 500;
  19859. t['b'] = 556;
  19860. t['c'] = 444;
  19861. t['d'] = 556;
  19862. t['e'] = 444;
  19863. t['f'] = 333;
  19864. t['g'] = 500;
  19865. t['h'] = 556;
  19866. t['i'] = 278;
  19867. t['j'] = 333;
  19868. t['k'] = 556;
  19869. t['l'] = 278;
  19870. t['m'] = 833;
  19871. t['n'] = 556;
  19872. t['o'] = 500;
  19873. t['p'] = 556;
  19874. t['q'] = 556;
  19875. t['r'] = 444;
  19876. t['s'] = 389;
  19877. t['t'] = 333;
  19878. t['u'] = 556;
  19879. t['v'] = 500;
  19880. t['w'] = 722;
  19881. t['x'] = 500;
  19882. t['y'] = 500;
  19883. t['z'] = 444;
  19884. t['braceleft'] = 394;
  19885. t['bar'] = 220;
  19886. t['braceright'] = 394;
  19887. t['asciitilde'] = 520;
  19888. t['exclamdown'] = 333;
  19889. t['cent'] = 500;
  19890. t['sterling'] = 500;
  19891. t['fraction'] = 167;
  19892. t['yen'] = 500;
  19893. t['florin'] = 500;
  19894. t['section'] = 500;
  19895. t['currency'] = 500;
  19896. t['quotesingle'] = 278;
  19897. t['quotedblleft'] = 500;
  19898. t['guillemotleft'] = 500;
  19899. t['guilsinglleft'] = 333;
  19900. t['guilsinglright'] = 333;
  19901. t['fi'] = 556;
  19902. t['fl'] = 556;
  19903. t['endash'] = 500;
  19904. t['dagger'] = 500;
  19905. t['daggerdbl'] = 500;
  19906. t['periodcentered'] = 250;
  19907. t['paragraph'] = 540;
  19908. t['bullet'] = 350;
  19909. t['quotesinglbase'] = 333;
  19910. t['quotedblbase'] = 500;
  19911. t['quotedblright'] = 500;
  19912. t['guillemotright'] = 500;
  19913. t['ellipsis'] = 1000;
  19914. t['perthousand'] = 1000;
  19915. t['questiondown'] = 500;
  19916. t['grave'] = 333;
  19917. t['acute'] = 333;
  19918. t['circumflex'] = 333;
  19919. t['tilde'] = 333;
  19920. t['macron'] = 333;
  19921. t['breve'] = 333;
  19922. t['dotaccent'] = 333;
  19923. t['dieresis'] = 333;
  19924. t['ring'] = 333;
  19925. t['cedilla'] = 333;
  19926. t['hungarumlaut'] = 333;
  19927. t['ogonek'] = 333;
  19928. t['caron'] = 333;
  19929. t['emdash'] = 1000;
  19930. t['AE'] = 1000;
  19931. t['ordfeminine'] = 300;
  19932. t['Lslash'] = 667;
  19933. t['Oslash'] = 778;
  19934. t['OE'] = 1000;
  19935. t['ordmasculine'] = 330;
  19936. t['ae'] = 722;
  19937. t['dotlessi'] = 278;
  19938. t['lslash'] = 278;
  19939. t['oslash'] = 500;
  19940. t['oe'] = 722;
  19941. t['germandbls'] = 556;
  19942. t['Idieresis'] = 389;
  19943. t['eacute'] = 444;
  19944. t['abreve'] = 500;
  19945. t['uhungarumlaut'] = 556;
  19946. t['ecaron'] = 444;
  19947. t['Ydieresis'] = 722;
  19948. t['divide'] = 570;
  19949. t['Yacute'] = 722;
  19950. t['Acircumflex'] = 722;
  19951. t['aacute'] = 500;
  19952. t['Ucircumflex'] = 722;
  19953. t['yacute'] = 500;
  19954. t['scommaaccent'] = 389;
  19955. t['ecircumflex'] = 444;
  19956. t['Uring'] = 722;
  19957. t['Udieresis'] = 722;
  19958. t['aogonek'] = 500;
  19959. t['Uacute'] = 722;
  19960. t['uogonek'] = 556;
  19961. t['Edieresis'] = 667;
  19962. t['Dcroat'] = 722;
  19963. t['commaaccent'] = 250;
  19964. t['copyright'] = 747;
  19965. t['Emacron'] = 667;
  19966. t['ccaron'] = 444;
  19967. t['aring'] = 500;
  19968. t['Ncommaaccent'] = 722;
  19969. t['lacute'] = 278;
  19970. t['agrave'] = 500;
  19971. t['Tcommaaccent'] = 667;
  19972. t['Cacute'] = 722;
  19973. t['atilde'] = 500;
  19974. t['Edotaccent'] = 667;
  19975. t['scaron'] = 389;
  19976. t['scedilla'] = 389;
  19977. t['iacute'] = 278;
  19978. t['lozenge'] = 494;
  19979. t['Rcaron'] = 722;
  19980. t['Gcommaaccent'] = 778;
  19981. t['ucircumflex'] = 556;
  19982. t['acircumflex'] = 500;
  19983. t['Amacron'] = 722;
  19984. t['rcaron'] = 444;
  19985. t['ccedilla'] = 444;
  19986. t['Zdotaccent'] = 667;
  19987. t['Thorn'] = 611;
  19988. t['Omacron'] = 778;
  19989. t['Racute'] = 722;
  19990. t['Sacute'] = 556;
  19991. t['dcaron'] = 672;
  19992. t['Umacron'] = 722;
  19993. t['uring'] = 556;
  19994. t['threesuperior'] = 300;
  19995. t['Ograve'] = 778;
  19996. t['Agrave'] = 722;
  19997. t['Abreve'] = 722;
  19998. t['multiply'] = 570;
  19999. t['uacute'] = 556;
  20000. t['Tcaron'] = 667;
  20001. t['partialdiff'] = 494;
  20002. t['ydieresis'] = 500;
  20003. t['Nacute'] = 722;
  20004. t['icircumflex'] = 278;
  20005. t['Ecircumflex'] = 667;
  20006. t['adieresis'] = 500;
  20007. t['edieresis'] = 444;
  20008. t['cacute'] = 444;
  20009. t['nacute'] = 556;
  20010. t['umacron'] = 556;
  20011. t['Ncaron'] = 722;
  20012. t['Iacute'] = 389;
  20013. t['plusminus'] = 570;
  20014. t['brokenbar'] = 220;
  20015. t['registered'] = 747;
  20016. t['Gbreve'] = 778;
  20017. t['Idotaccent'] = 389;
  20018. t['summation'] = 600;
  20019. t['Egrave'] = 667;
  20020. t['racute'] = 444;
  20021. t['omacron'] = 500;
  20022. t['Zacute'] = 667;
  20023. t['Zcaron'] = 667;
  20024. t['greaterequal'] = 549;
  20025. t['Eth'] = 722;
  20026. t['Ccedilla'] = 722;
  20027. t['lcommaaccent'] = 278;
  20028. t['tcaron'] = 416;
  20029. t['eogonek'] = 444;
  20030. t['Uogonek'] = 722;
  20031. t['Aacute'] = 722;
  20032. t['Adieresis'] = 722;
  20033. t['egrave'] = 444;
  20034. t['zacute'] = 444;
  20035. t['iogonek'] = 278;
  20036. t['Oacute'] = 778;
  20037. t['oacute'] = 500;
  20038. t['amacron'] = 500;
  20039. t['sacute'] = 389;
  20040. t['idieresis'] = 278;
  20041. t['Ocircumflex'] = 778;
  20042. t['Ugrave'] = 722;
  20043. t['Delta'] = 612;
  20044. t['thorn'] = 556;
  20045. t['twosuperior'] = 300;
  20046. t['Odieresis'] = 778;
  20047. t['mu'] = 556;
  20048. t['igrave'] = 278;
  20049. t['ohungarumlaut'] = 500;
  20050. t['Eogonek'] = 667;
  20051. t['dcroat'] = 556;
  20052. t['threequarters'] = 750;
  20053. t['Scedilla'] = 556;
  20054. t['lcaron'] = 394;
  20055. t['Kcommaaccent'] = 778;
  20056. t['Lacute'] = 667;
  20057. t['trademark'] = 1000;
  20058. t['edotaccent'] = 444;
  20059. t['Igrave'] = 389;
  20060. t['Imacron'] = 389;
  20061. t['Lcaron'] = 667;
  20062. t['onehalf'] = 750;
  20063. t['lessequal'] = 549;
  20064. t['ocircumflex'] = 500;
  20065. t['ntilde'] = 556;
  20066. t['Uhungarumlaut'] = 722;
  20067. t['Eacute'] = 667;
  20068. t['emacron'] = 444;
  20069. t['gbreve'] = 500;
  20070. t['onequarter'] = 750;
  20071. t['Scaron'] = 556;
  20072. t['Scommaaccent'] = 556;
  20073. t['Ohungarumlaut'] = 778;
  20074. t['degree'] = 400;
  20075. t['ograve'] = 500;
  20076. t['Ccaron'] = 722;
  20077. t['ugrave'] = 556;
  20078. t['radical'] = 549;
  20079. t['Dcaron'] = 722;
  20080. t['rcommaaccent'] = 444;
  20081. t['Ntilde'] = 722;
  20082. t['otilde'] = 500;
  20083. t['Rcommaaccent'] = 722;
  20084. t['Lcommaaccent'] = 667;
  20085. t['Atilde'] = 722;
  20086. t['Aogonek'] = 722;
  20087. t['Aring'] = 722;
  20088. t['Otilde'] = 778;
  20089. t['zdotaccent'] = 444;
  20090. t['Ecaron'] = 667;
  20091. t['Iogonek'] = 389;
  20092. t['kcommaaccent'] = 556;
  20093. t['minus'] = 570;
  20094. t['Icircumflex'] = 389;
  20095. t['ncaron'] = 556;
  20096. t['tcommaaccent'] = 333;
  20097. t['logicalnot'] = 570;
  20098. t['odieresis'] = 500;
  20099. t['udieresis'] = 556;
  20100. t['notequal'] = 549;
  20101. t['gcommaaccent'] = 500;
  20102. t['eth'] = 500;
  20103. t['zcaron'] = 444;
  20104. t['ncommaaccent'] = 556;
  20105. t['onesuperior'] = 300;
  20106. t['imacron'] = 278;
  20107. t['Euro'] = 500;
  20108. });
  20109. t['Times-BoldItalic'] = getLookupTableFactory(function (t) {
  20110. t['space'] = 250;
  20111. t['exclam'] = 389;
  20112. t['quotedbl'] = 555;
  20113. t['numbersign'] = 500;
  20114. t['dollar'] = 500;
  20115. t['percent'] = 833;
  20116. t['ampersand'] = 778;
  20117. t['quoteright'] = 333;
  20118. t['parenleft'] = 333;
  20119. t['parenright'] = 333;
  20120. t['asterisk'] = 500;
  20121. t['plus'] = 570;
  20122. t['comma'] = 250;
  20123. t['hyphen'] = 333;
  20124. t['period'] = 250;
  20125. t['slash'] = 278;
  20126. t['zero'] = 500;
  20127. t['one'] = 500;
  20128. t['two'] = 500;
  20129. t['three'] = 500;
  20130. t['four'] = 500;
  20131. t['five'] = 500;
  20132. t['six'] = 500;
  20133. t['seven'] = 500;
  20134. t['eight'] = 500;
  20135. t['nine'] = 500;
  20136. t['colon'] = 333;
  20137. t['semicolon'] = 333;
  20138. t['less'] = 570;
  20139. t['equal'] = 570;
  20140. t['greater'] = 570;
  20141. t['question'] = 500;
  20142. t['at'] = 832;
  20143. t['A'] = 667;
  20144. t['B'] = 667;
  20145. t['C'] = 667;
  20146. t['D'] = 722;
  20147. t['E'] = 667;
  20148. t['F'] = 667;
  20149. t['G'] = 722;
  20150. t['H'] = 778;
  20151. t['I'] = 389;
  20152. t['J'] = 500;
  20153. t['K'] = 667;
  20154. t['L'] = 611;
  20155. t['M'] = 889;
  20156. t['N'] = 722;
  20157. t['O'] = 722;
  20158. t['P'] = 611;
  20159. t['Q'] = 722;
  20160. t['R'] = 667;
  20161. t['S'] = 556;
  20162. t['T'] = 611;
  20163. t['U'] = 722;
  20164. t['V'] = 667;
  20165. t['W'] = 889;
  20166. t['X'] = 667;
  20167. t['Y'] = 611;
  20168. t['Z'] = 611;
  20169. t['bracketleft'] = 333;
  20170. t['backslash'] = 278;
  20171. t['bracketright'] = 333;
  20172. t['asciicircum'] = 570;
  20173. t['underscore'] = 500;
  20174. t['quoteleft'] = 333;
  20175. t['a'] = 500;
  20176. t['b'] = 500;
  20177. t['c'] = 444;
  20178. t['d'] = 500;
  20179. t['e'] = 444;
  20180. t['f'] = 333;
  20181. t['g'] = 500;
  20182. t['h'] = 556;
  20183. t['i'] = 278;
  20184. t['j'] = 278;
  20185. t['k'] = 500;
  20186. t['l'] = 278;
  20187. t['m'] = 778;
  20188. t['n'] = 556;
  20189. t['o'] = 500;
  20190. t['p'] = 500;
  20191. t['q'] = 500;
  20192. t['r'] = 389;
  20193. t['s'] = 389;
  20194. t['t'] = 278;
  20195. t['u'] = 556;
  20196. t['v'] = 444;
  20197. t['w'] = 667;
  20198. t['x'] = 500;
  20199. t['y'] = 444;
  20200. t['z'] = 389;
  20201. t['braceleft'] = 348;
  20202. t['bar'] = 220;
  20203. t['braceright'] = 348;
  20204. t['asciitilde'] = 570;
  20205. t['exclamdown'] = 389;
  20206. t['cent'] = 500;
  20207. t['sterling'] = 500;
  20208. t['fraction'] = 167;
  20209. t['yen'] = 500;
  20210. t['florin'] = 500;
  20211. t['section'] = 500;
  20212. t['currency'] = 500;
  20213. t['quotesingle'] = 278;
  20214. t['quotedblleft'] = 500;
  20215. t['guillemotleft'] = 500;
  20216. t['guilsinglleft'] = 333;
  20217. t['guilsinglright'] = 333;
  20218. t['fi'] = 556;
  20219. t['fl'] = 556;
  20220. t['endash'] = 500;
  20221. t['dagger'] = 500;
  20222. t['daggerdbl'] = 500;
  20223. t['periodcentered'] = 250;
  20224. t['paragraph'] = 500;
  20225. t['bullet'] = 350;
  20226. t['quotesinglbase'] = 333;
  20227. t['quotedblbase'] = 500;
  20228. t['quotedblright'] = 500;
  20229. t['guillemotright'] = 500;
  20230. t['ellipsis'] = 1000;
  20231. t['perthousand'] = 1000;
  20232. t['questiondown'] = 500;
  20233. t['grave'] = 333;
  20234. t['acute'] = 333;
  20235. t['circumflex'] = 333;
  20236. t['tilde'] = 333;
  20237. t['macron'] = 333;
  20238. t['breve'] = 333;
  20239. t['dotaccent'] = 333;
  20240. t['dieresis'] = 333;
  20241. t['ring'] = 333;
  20242. t['cedilla'] = 333;
  20243. t['hungarumlaut'] = 333;
  20244. t['ogonek'] = 333;
  20245. t['caron'] = 333;
  20246. t['emdash'] = 1000;
  20247. t['AE'] = 944;
  20248. t['ordfeminine'] = 266;
  20249. t['Lslash'] = 611;
  20250. t['Oslash'] = 722;
  20251. t['OE'] = 944;
  20252. t['ordmasculine'] = 300;
  20253. t['ae'] = 722;
  20254. t['dotlessi'] = 278;
  20255. t['lslash'] = 278;
  20256. t['oslash'] = 500;
  20257. t['oe'] = 722;
  20258. t['germandbls'] = 500;
  20259. t['Idieresis'] = 389;
  20260. t['eacute'] = 444;
  20261. t['abreve'] = 500;
  20262. t['uhungarumlaut'] = 556;
  20263. t['ecaron'] = 444;
  20264. t['Ydieresis'] = 611;
  20265. t['divide'] = 570;
  20266. t['Yacute'] = 611;
  20267. t['Acircumflex'] = 667;
  20268. t['aacute'] = 500;
  20269. t['Ucircumflex'] = 722;
  20270. t['yacute'] = 444;
  20271. t['scommaaccent'] = 389;
  20272. t['ecircumflex'] = 444;
  20273. t['Uring'] = 722;
  20274. t['Udieresis'] = 722;
  20275. t['aogonek'] = 500;
  20276. t['Uacute'] = 722;
  20277. t['uogonek'] = 556;
  20278. t['Edieresis'] = 667;
  20279. t['Dcroat'] = 722;
  20280. t['commaaccent'] = 250;
  20281. t['copyright'] = 747;
  20282. t['Emacron'] = 667;
  20283. t['ccaron'] = 444;
  20284. t['aring'] = 500;
  20285. t['Ncommaaccent'] = 722;
  20286. t['lacute'] = 278;
  20287. t['agrave'] = 500;
  20288. t['Tcommaaccent'] = 611;
  20289. t['Cacute'] = 667;
  20290. t['atilde'] = 500;
  20291. t['Edotaccent'] = 667;
  20292. t['scaron'] = 389;
  20293. t['scedilla'] = 389;
  20294. t['iacute'] = 278;
  20295. t['lozenge'] = 494;
  20296. t['Rcaron'] = 667;
  20297. t['Gcommaaccent'] = 722;
  20298. t['ucircumflex'] = 556;
  20299. t['acircumflex'] = 500;
  20300. t['Amacron'] = 667;
  20301. t['rcaron'] = 389;
  20302. t['ccedilla'] = 444;
  20303. t['Zdotaccent'] = 611;
  20304. t['Thorn'] = 611;
  20305. t['Omacron'] = 722;
  20306. t['Racute'] = 667;
  20307. t['Sacute'] = 556;
  20308. t['dcaron'] = 608;
  20309. t['Umacron'] = 722;
  20310. t['uring'] = 556;
  20311. t['threesuperior'] = 300;
  20312. t['Ograve'] = 722;
  20313. t['Agrave'] = 667;
  20314. t['Abreve'] = 667;
  20315. t['multiply'] = 570;
  20316. t['uacute'] = 556;
  20317. t['Tcaron'] = 611;
  20318. t['partialdiff'] = 494;
  20319. t['ydieresis'] = 444;
  20320. t['Nacute'] = 722;
  20321. t['icircumflex'] = 278;
  20322. t['Ecircumflex'] = 667;
  20323. t['adieresis'] = 500;
  20324. t['edieresis'] = 444;
  20325. t['cacute'] = 444;
  20326. t['nacute'] = 556;
  20327. t['umacron'] = 556;
  20328. t['Ncaron'] = 722;
  20329. t['Iacute'] = 389;
  20330. t['plusminus'] = 570;
  20331. t['brokenbar'] = 220;
  20332. t['registered'] = 747;
  20333. t['Gbreve'] = 722;
  20334. t['Idotaccent'] = 389;
  20335. t['summation'] = 600;
  20336. t['Egrave'] = 667;
  20337. t['racute'] = 389;
  20338. t['omacron'] = 500;
  20339. t['Zacute'] = 611;
  20340. t['Zcaron'] = 611;
  20341. t['greaterequal'] = 549;
  20342. t['Eth'] = 722;
  20343. t['Ccedilla'] = 667;
  20344. t['lcommaaccent'] = 278;
  20345. t['tcaron'] = 366;
  20346. t['eogonek'] = 444;
  20347. t['Uogonek'] = 722;
  20348. t['Aacute'] = 667;
  20349. t['Adieresis'] = 667;
  20350. t['egrave'] = 444;
  20351. t['zacute'] = 389;
  20352. t['iogonek'] = 278;
  20353. t['Oacute'] = 722;
  20354. t['oacute'] = 500;
  20355. t['amacron'] = 500;
  20356. t['sacute'] = 389;
  20357. t['idieresis'] = 278;
  20358. t['Ocircumflex'] = 722;
  20359. t['Ugrave'] = 722;
  20360. t['Delta'] = 612;
  20361. t['thorn'] = 500;
  20362. t['twosuperior'] = 300;
  20363. t['Odieresis'] = 722;
  20364. t['mu'] = 576;
  20365. t['igrave'] = 278;
  20366. t['ohungarumlaut'] = 500;
  20367. t['Eogonek'] = 667;
  20368. t['dcroat'] = 500;
  20369. t['threequarters'] = 750;
  20370. t['Scedilla'] = 556;
  20371. t['lcaron'] = 382;
  20372. t['Kcommaaccent'] = 667;
  20373. t['Lacute'] = 611;
  20374. t['trademark'] = 1000;
  20375. t['edotaccent'] = 444;
  20376. t['Igrave'] = 389;
  20377. t['Imacron'] = 389;
  20378. t['Lcaron'] = 611;
  20379. t['onehalf'] = 750;
  20380. t['lessequal'] = 549;
  20381. t['ocircumflex'] = 500;
  20382. t['ntilde'] = 556;
  20383. t['Uhungarumlaut'] = 722;
  20384. t['Eacute'] = 667;
  20385. t['emacron'] = 444;
  20386. t['gbreve'] = 500;
  20387. t['onequarter'] = 750;
  20388. t['Scaron'] = 556;
  20389. t['Scommaaccent'] = 556;
  20390. t['Ohungarumlaut'] = 722;
  20391. t['degree'] = 400;
  20392. t['ograve'] = 500;
  20393. t['Ccaron'] = 667;
  20394. t['ugrave'] = 556;
  20395. t['radical'] = 549;
  20396. t['Dcaron'] = 722;
  20397. t['rcommaaccent'] = 389;
  20398. t['Ntilde'] = 722;
  20399. t['otilde'] = 500;
  20400. t['Rcommaaccent'] = 667;
  20401. t['Lcommaaccent'] = 611;
  20402. t['Atilde'] = 667;
  20403. t['Aogonek'] = 667;
  20404. t['Aring'] = 667;
  20405. t['Otilde'] = 722;
  20406. t['zdotaccent'] = 389;
  20407. t['Ecaron'] = 667;
  20408. t['Iogonek'] = 389;
  20409. t['kcommaaccent'] = 500;
  20410. t['minus'] = 606;
  20411. t['Icircumflex'] = 389;
  20412. t['ncaron'] = 556;
  20413. t['tcommaaccent'] = 278;
  20414. t['logicalnot'] = 606;
  20415. t['odieresis'] = 500;
  20416. t['udieresis'] = 556;
  20417. t['notequal'] = 549;
  20418. t['gcommaaccent'] = 500;
  20419. t['eth'] = 500;
  20420. t['zcaron'] = 389;
  20421. t['ncommaaccent'] = 556;
  20422. t['onesuperior'] = 300;
  20423. t['imacron'] = 278;
  20424. t['Euro'] = 500;
  20425. });
  20426. t['Times-Italic'] = getLookupTableFactory(function (t) {
  20427. t['space'] = 250;
  20428. t['exclam'] = 333;
  20429. t['quotedbl'] = 420;
  20430. t['numbersign'] = 500;
  20431. t['dollar'] = 500;
  20432. t['percent'] = 833;
  20433. t['ampersand'] = 778;
  20434. t['quoteright'] = 333;
  20435. t['parenleft'] = 333;
  20436. t['parenright'] = 333;
  20437. t['asterisk'] = 500;
  20438. t['plus'] = 675;
  20439. t['comma'] = 250;
  20440. t['hyphen'] = 333;
  20441. t['period'] = 250;
  20442. t['slash'] = 278;
  20443. t['zero'] = 500;
  20444. t['one'] = 500;
  20445. t['two'] = 500;
  20446. t['three'] = 500;
  20447. t['four'] = 500;
  20448. t['five'] = 500;
  20449. t['six'] = 500;
  20450. t['seven'] = 500;
  20451. t['eight'] = 500;
  20452. t['nine'] = 500;
  20453. t['colon'] = 333;
  20454. t['semicolon'] = 333;
  20455. t['less'] = 675;
  20456. t['equal'] = 675;
  20457. t['greater'] = 675;
  20458. t['question'] = 500;
  20459. t['at'] = 920;
  20460. t['A'] = 611;
  20461. t['B'] = 611;
  20462. t['C'] = 667;
  20463. t['D'] = 722;
  20464. t['E'] = 611;
  20465. t['F'] = 611;
  20466. t['G'] = 722;
  20467. t['H'] = 722;
  20468. t['I'] = 333;
  20469. t['J'] = 444;
  20470. t['K'] = 667;
  20471. t['L'] = 556;
  20472. t['M'] = 833;
  20473. t['N'] = 667;
  20474. t['O'] = 722;
  20475. t['P'] = 611;
  20476. t['Q'] = 722;
  20477. t['R'] = 611;
  20478. t['S'] = 500;
  20479. t['T'] = 556;
  20480. t['U'] = 722;
  20481. t['V'] = 611;
  20482. t['W'] = 833;
  20483. t['X'] = 611;
  20484. t['Y'] = 556;
  20485. t['Z'] = 556;
  20486. t['bracketleft'] = 389;
  20487. t['backslash'] = 278;
  20488. t['bracketright'] = 389;
  20489. t['asciicircum'] = 422;
  20490. t['underscore'] = 500;
  20491. t['quoteleft'] = 333;
  20492. t['a'] = 500;
  20493. t['b'] = 500;
  20494. t['c'] = 444;
  20495. t['d'] = 500;
  20496. t['e'] = 444;
  20497. t['f'] = 278;
  20498. t['g'] = 500;
  20499. t['h'] = 500;
  20500. t['i'] = 278;
  20501. t['j'] = 278;
  20502. t['k'] = 444;
  20503. t['l'] = 278;
  20504. t['m'] = 722;
  20505. t['n'] = 500;
  20506. t['o'] = 500;
  20507. t['p'] = 500;
  20508. t['q'] = 500;
  20509. t['r'] = 389;
  20510. t['s'] = 389;
  20511. t['t'] = 278;
  20512. t['u'] = 500;
  20513. t['v'] = 444;
  20514. t['w'] = 667;
  20515. t['x'] = 444;
  20516. t['y'] = 444;
  20517. t['z'] = 389;
  20518. t['braceleft'] = 400;
  20519. t['bar'] = 275;
  20520. t['braceright'] = 400;
  20521. t['asciitilde'] = 541;
  20522. t['exclamdown'] = 389;
  20523. t['cent'] = 500;
  20524. t['sterling'] = 500;
  20525. t['fraction'] = 167;
  20526. t['yen'] = 500;
  20527. t['florin'] = 500;
  20528. t['section'] = 500;
  20529. t['currency'] = 500;
  20530. t['quotesingle'] = 214;
  20531. t['quotedblleft'] = 556;
  20532. t['guillemotleft'] = 500;
  20533. t['guilsinglleft'] = 333;
  20534. t['guilsinglright'] = 333;
  20535. t['fi'] = 500;
  20536. t['fl'] = 500;
  20537. t['endash'] = 500;
  20538. t['dagger'] = 500;
  20539. t['daggerdbl'] = 500;
  20540. t['periodcentered'] = 250;
  20541. t['paragraph'] = 523;
  20542. t['bullet'] = 350;
  20543. t['quotesinglbase'] = 333;
  20544. t['quotedblbase'] = 556;
  20545. t['quotedblright'] = 556;
  20546. t['guillemotright'] = 500;
  20547. t['ellipsis'] = 889;
  20548. t['perthousand'] = 1000;
  20549. t['questiondown'] = 500;
  20550. t['grave'] = 333;
  20551. t['acute'] = 333;
  20552. t['circumflex'] = 333;
  20553. t['tilde'] = 333;
  20554. t['macron'] = 333;
  20555. t['breve'] = 333;
  20556. t['dotaccent'] = 333;
  20557. t['dieresis'] = 333;
  20558. t['ring'] = 333;
  20559. t['cedilla'] = 333;
  20560. t['hungarumlaut'] = 333;
  20561. t['ogonek'] = 333;
  20562. t['caron'] = 333;
  20563. t['emdash'] = 889;
  20564. t['AE'] = 889;
  20565. t['ordfeminine'] = 276;
  20566. t['Lslash'] = 556;
  20567. t['Oslash'] = 722;
  20568. t['OE'] = 944;
  20569. t['ordmasculine'] = 310;
  20570. t['ae'] = 667;
  20571. t['dotlessi'] = 278;
  20572. t['lslash'] = 278;
  20573. t['oslash'] = 500;
  20574. t['oe'] = 667;
  20575. t['germandbls'] = 500;
  20576. t['Idieresis'] = 333;
  20577. t['eacute'] = 444;
  20578. t['abreve'] = 500;
  20579. t['uhungarumlaut'] = 500;
  20580. t['ecaron'] = 444;
  20581. t['Ydieresis'] = 556;
  20582. t['divide'] = 675;
  20583. t['Yacute'] = 556;
  20584. t['Acircumflex'] = 611;
  20585. t['aacute'] = 500;
  20586. t['Ucircumflex'] = 722;
  20587. t['yacute'] = 444;
  20588. t['scommaaccent'] = 389;
  20589. t['ecircumflex'] = 444;
  20590. t['Uring'] = 722;
  20591. t['Udieresis'] = 722;
  20592. t['aogonek'] = 500;
  20593. t['Uacute'] = 722;
  20594. t['uogonek'] = 500;
  20595. t['Edieresis'] = 611;
  20596. t['Dcroat'] = 722;
  20597. t['commaaccent'] = 250;
  20598. t['copyright'] = 760;
  20599. t['Emacron'] = 611;
  20600. t['ccaron'] = 444;
  20601. t['aring'] = 500;
  20602. t['Ncommaaccent'] = 667;
  20603. t['lacute'] = 278;
  20604. t['agrave'] = 500;
  20605. t['Tcommaaccent'] = 556;
  20606. t['Cacute'] = 667;
  20607. t['atilde'] = 500;
  20608. t['Edotaccent'] = 611;
  20609. t['scaron'] = 389;
  20610. t['scedilla'] = 389;
  20611. t['iacute'] = 278;
  20612. t['lozenge'] = 471;
  20613. t['Rcaron'] = 611;
  20614. t['Gcommaaccent'] = 722;
  20615. t['ucircumflex'] = 500;
  20616. t['acircumflex'] = 500;
  20617. t['Amacron'] = 611;
  20618. t['rcaron'] = 389;
  20619. t['ccedilla'] = 444;
  20620. t['Zdotaccent'] = 556;
  20621. t['Thorn'] = 611;
  20622. t['Omacron'] = 722;
  20623. t['Racute'] = 611;
  20624. t['Sacute'] = 500;
  20625. t['dcaron'] = 544;
  20626. t['Umacron'] = 722;
  20627. t['uring'] = 500;
  20628. t['threesuperior'] = 300;
  20629. t['Ograve'] = 722;
  20630. t['Agrave'] = 611;
  20631. t['Abreve'] = 611;
  20632. t['multiply'] = 675;
  20633. t['uacute'] = 500;
  20634. t['Tcaron'] = 556;
  20635. t['partialdiff'] = 476;
  20636. t['ydieresis'] = 444;
  20637. t['Nacute'] = 667;
  20638. t['icircumflex'] = 278;
  20639. t['Ecircumflex'] = 611;
  20640. t['adieresis'] = 500;
  20641. t['edieresis'] = 444;
  20642. t['cacute'] = 444;
  20643. t['nacute'] = 500;
  20644. t['umacron'] = 500;
  20645. t['Ncaron'] = 667;
  20646. t['Iacute'] = 333;
  20647. t['plusminus'] = 675;
  20648. t['brokenbar'] = 275;
  20649. t['registered'] = 760;
  20650. t['Gbreve'] = 722;
  20651. t['Idotaccent'] = 333;
  20652. t['summation'] = 600;
  20653. t['Egrave'] = 611;
  20654. t['racute'] = 389;
  20655. t['omacron'] = 500;
  20656. t['Zacute'] = 556;
  20657. t['Zcaron'] = 556;
  20658. t['greaterequal'] = 549;
  20659. t['Eth'] = 722;
  20660. t['Ccedilla'] = 667;
  20661. t['lcommaaccent'] = 278;
  20662. t['tcaron'] = 300;
  20663. t['eogonek'] = 444;
  20664. t['Uogonek'] = 722;
  20665. t['Aacute'] = 611;
  20666. t['Adieresis'] = 611;
  20667. t['egrave'] = 444;
  20668. t['zacute'] = 389;
  20669. t['iogonek'] = 278;
  20670. t['Oacute'] = 722;
  20671. t['oacute'] = 500;
  20672. t['amacron'] = 500;
  20673. t['sacute'] = 389;
  20674. t['idieresis'] = 278;
  20675. t['Ocircumflex'] = 722;
  20676. t['Ugrave'] = 722;
  20677. t['Delta'] = 612;
  20678. t['thorn'] = 500;
  20679. t['twosuperior'] = 300;
  20680. t['Odieresis'] = 722;
  20681. t['mu'] = 500;
  20682. t['igrave'] = 278;
  20683. t['ohungarumlaut'] = 500;
  20684. t['Eogonek'] = 611;
  20685. t['dcroat'] = 500;
  20686. t['threequarters'] = 750;
  20687. t['Scedilla'] = 500;
  20688. t['lcaron'] = 300;
  20689. t['Kcommaaccent'] = 667;
  20690. t['Lacute'] = 556;
  20691. t['trademark'] = 980;
  20692. t['edotaccent'] = 444;
  20693. t['Igrave'] = 333;
  20694. t['Imacron'] = 333;
  20695. t['Lcaron'] = 611;
  20696. t['onehalf'] = 750;
  20697. t['lessequal'] = 549;
  20698. t['ocircumflex'] = 500;
  20699. t['ntilde'] = 500;
  20700. t['Uhungarumlaut'] = 722;
  20701. t['Eacute'] = 611;
  20702. t['emacron'] = 444;
  20703. t['gbreve'] = 500;
  20704. t['onequarter'] = 750;
  20705. t['Scaron'] = 500;
  20706. t['Scommaaccent'] = 500;
  20707. t['Ohungarumlaut'] = 722;
  20708. t['degree'] = 400;
  20709. t['ograve'] = 500;
  20710. t['Ccaron'] = 667;
  20711. t['ugrave'] = 500;
  20712. t['radical'] = 453;
  20713. t['Dcaron'] = 722;
  20714. t['rcommaaccent'] = 389;
  20715. t['Ntilde'] = 667;
  20716. t['otilde'] = 500;
  20717. t['Rcommaaccent'] = 611;
  20718. t['Lcommaaccent'] = 556;
  20719. t['Atilde'] = 611;
  20720. t['Aogonek'] = 611;
  20721. t['Aring'] = 611;
  20722. t['Otilde'] = 722;
  20723. t['zdotaccent'] = 389;
  20724. t['Ecaron'] = 611;
  20725. t['Iogonek'] = 333;
  20726. t['kcommaaccent'] = 444;
  20727. t['minus'] = 675;
  20728. t['Icircumflex'] = 333;
  20729. t['ncaron'] = 500;
  20730. t['tcommaaccent'] = 278;
  20731. t['logicalnot'] = 675;
  20732. t['odieresis'] = 500;
  20733. t['udieresis'] = 500;
  20734. t['notequal'] = 549;
  20735. t['gcommaaccent'] = 500;
  20736. t['eth'] = 500;
  20737. t['zcaron'] = 389;
  20738. t['ncommaaccent'] = 500;
  20739. t['onesuperior'] = 300;
  20740. t['imacron'] = 278;
  20741. t['Euro'] = 500;
  20742. });
  20743. t['ZapfDingbats'] = getLookupTableFactory(function (t) {
  20744. t['space'] = 278;
  20745. t['a1'] = 974;
  20746. t['a2'] = 961;
  20747. t['a202'] = 974;
  20748. t['a3'] = 980;
  20749. t['a4'] = 719;
  20750. t['a5'] = 789;
  20751. t['a119'] = 790;
  20752. t['a118'] = 791;
  20753. t['a117'] = 690;
  20754. t['a11'] = 960;
  20755. t['a12'] = 939;
  20756. t['a13'] = 549;
  20757. t['a14'] = 855;
  20758. t['a15'] = 911;
  20759. t['a16'] = 933;
  20760. t['a105'] = 911;
  20761. t['a17'] = 945;
  20762. t['a18'] = 974;
  20763. t['a19'] = 755;
  20764. t['a20'] = 846;
  20765. t['a21'] = 762;
  20766. t['a22'] = 761;
  20767. t['a23'] = 571;
  20768. t['a24'] = 677;
  20769. t['a25'] = 763;
  20770. t['a26'] = 760;
  20771. t['a27'] = 759;
  20772. t['a28'] = 754;
  20773. t['a6'] = 494;
  20774. t['a7'] = 552;
  20775. t['a8'] = 537;
  20776. t['a9'] = 577;
  20777. t['a10'] = 692;
  20778. t['a29'] = 786;
  20779. t['a30'] = 788;
  20780. t['a31'] = 788;
  20781. t['a32'] = 790;
  20782. t['a33'] = 793;
  20783. t['a34'] = 794;
  20784. t['a35'] = 816;
  20785. t['a36'] = 823;
  20786. t['a37'] = 789;
  20787. t['a38'] = 841;
  20788. t['a39'] = 823;
  20789. t['a40'] = 833;
  20790. t['a41'] = 816;
  20791. t['a42'] = 831;
  20792. t['a43'] = 923;
  20793. t['a44'] = 744;
  20794. t['a45'] = 723;
  20795. t['a46'] = 749;
  20796. t['a47'] = 790;
  20797. t['a48'] = 792;
  20798. t['a49'] = 695;
  20799. t['a50'] = 776;
  20800. t['a51'] = 768;
  20801. t['a52'] = 792;
  20802. t['a53'] = 759;
  20803. t['a54'] = 707;
  20804. t['a55'] = 708;
  20805. t['a56'] = 682;
  20806. t['a57'] = 701;
  20807. t['a58'] = 826;
  20808. t['a59'] = 815;
  20809. t['a60'] = 789;
  20810. t['a61'] = 789;
  20811. t['a62'] = 707;
  20812. t['a63'] = 687;
  20813. t['a64'] = 696;
  20814. t['a65'] = 689;
  20815. t['a66'] = 786;
  20816. t['a67'] = 787;
  20817. t['a68'] = 713;
  20818. t['a69'] = 791;
  20819. t['a70'] = 785;
  20820. t['a71'] = 791;
  20821. t['a72'] = 873;
  20822. t['a73'] = 761;
  20823. t['a74'] = 762;
  20824. t['a203'] = 762;
  20825. t['a75'] = 759;
  20826. t['a204'] = 759;
  20827. t['a76'] = 892;
  20828. t['a77'] = 892;
  20829. t['a78'] = 788;
  20830. t['a79'] = 784;
  20831. t['a81'] = 438;
  20832. t['a82'] = 138;
  20833. t['a83'] = 277;
  20834. t['a84'] = 415;
  20835. t['a97'] = 392;
  20836. t['a98'] = 392;
  20837. t['a99'] = 668;
  20838. t['a100'] = 668;
  20839. t['a89'] = 390;
  20840. t['a90'] = 390;
  20841. t['a93'] = 317;
  20842. t['a94'] = 317;
  20843. t['a91'] = 276;
  20844. t['a92'] = 276;
  20845. t['a205'] = 509;
  20846. t['a85'] = 509;
  20847. t['a206'] = 410;
  20848. t['a86'] = 410;
  20849. t['a87'] = 234;
  20850. t['a88'] = 234;
  20851. t['a95'] = 334;
  20852. t['a96'] = 334;
  20853. t['a101'] = 732;
  20854. t['a102'] = 544;
  20855. t['a103'] = 544;
  20856. t['a104'] = 910;
  20857. t['a106'] = 667;
  20858. t['a107'] = 760;
  20859. t['a108'] = 760;
  20860. t['a112'] = 776;
  20861. t['a111'] = 595;
  20862. t['a110'] = 694;
  20863. t['a109'] = 626;
  20864. t['a120'] = 788;
  20865. t['a121'] = 788;
  20866. t['a122'] = 788;
  20867. t['a123'] = 788;
  20868. t['a124'] = 788;
  20869. t['a125'] = 788;
  20870. t['a126'] = 788;
  20871. t['a127'] = 788;
  20872. t['a128'] = 788;
  20873. t['a129'] = 788;
  20874. t['a130'] = 788;
  20875. t['a131'] = 788;
  20876. t['a132'] = 788;
  20877. t['a133'] = 788;
  20878. t['a134'] = 788;
  20879. t['a135'] = 788;
  20880. t['a136'] = 788;
  20881. t['a137'] = 788;
  20882. t['a138'] = 788;
  20883. t['a139'] = 788;
  20884. t['a140'] = 788;
  20885. t['a141'] = 788;
  20886. t['a142'] = 788;
  20887. t['a143'] = 788;
  20888. t['a144'] = 788;
  20889. t['a145'] = 788;
  20890. t['a146'] = 788;
  20891. t['a147'] = 788;
  20892. t['a148'] = 788;
  20893. t['a149'] = 788;
  20894. t['a150'] = 788;
  20895. t['a151'] = 788;
  20896. t['a152'] = 788;
  20897. t['a153'] = 788;
  20898. t['a154'] = 788;
  20899. t['a155'] = 788;
  20900. t['a156'] = 788;
  20901. t['a157'] = 788;
  20902. t['a158'] = 788;
  20903. t['a159'] = 788;
  20904. t['a160'] = 894;
  20905. t['a161'] = 838;
  20906. t['a163'] = 1016;
  20907. t['a164'] = 458;
  20908. t['a196'] = 748;
  20909. t['a165'] = 924;
  20910. t['a192'] = 748;
  20911. t['a166'] = 918;
  20912. t['a167'] = 927;
  20913. t['a168'] = 928;
  20914. t['a169'] = 928;
  20915. t['a170'] = 834;
  20916. t['a171'] = 873;
  20917. t['a172'] = 828;
  20918. t['a173'] = 924;
  20919. t['a162'] = 924;
  20920. t['a174'] = 917;
  20921. t['a175'] = 930;
  20922. t['a176'] = 931;
  20923. t['a177'] = 463;
  20924. t['a178'] = 883;
  20925. t['a179'] = 836;
  20926. t['a193'] = 836;
  20927. t['a180'] = 867;
  20928. t['a199'] = 867;
  20929. t['a181'] = 696;
  20930. t['a200'] = 696;
  20931. t['a182'] = 874;
  20932. t['a201'] = 874;
  20933. t['a183'] = 760;
  20934. t['a184'] = 946;
  20935. t['a197'] = 771;
  20936. t['a185'] = 865;
  20937. t['a194'] = 771;
  20938. t['a198'] = 888;
  20939. t['a186'] = 967;
  20940. t['a195'] = 888;
  20941. t['a187'] = 831;
  20942. t['a188'] = 873;
  20943. t['a189'] = 927;
  20944. t['a190'] = 970;
  20945. t['a191'] = 918;
  20946. });
  20947. });
  20948. exports.getMetrics = getMetrics;
  20949. }));
  20950. (function (root, factory) {
  20951. factory(root.pdfjsCoreMurmurHash3 = {}, root.pdfjsSharedUtil);
  20952. }(this, function (exports, sharedUtil) {
  20953. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  20954. var MurmurHash3_64 = function MurmurHash3_64Closure(seed) {
  20955. // Workaround for missing math precision in JS.
  20956. var MASK_HIGH = 0xffff0000;
  20957. var MASK_LOW = 0xffff;
  20958. function MurmurHash3_64(seed) {
  20959. var SEED = 0xc3d2e1f0;
  20960. this.h1 = seed ? seed & 0xffffffff : SEED;
  20961. this.h2 = seed ? seed & 0xffffffff : SEED;
  20962. }
  20963. var alwaysUseUint32ArrayView = false;
  20964. // old webkits have issues with non-aligned arrays
  20965. try {
  20966. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  20967. } catch (e) {
  20968. alwaysUseUint32ArrayView = true;
  20969. }
  20970. MurmurHash3_64.prototype = {
  20971. update: function MurmurHash3_64_update(input) {
  20972. var useUint32ArrayView = alwaysUseUint32ArrayView;
  20973. var i;
  20974. if (typeof input === 'string') {
  20975. var data = new Uint8Array(input.length * 2);
  20976. var length = 0;
  20977. for (i = 0; i < input.length; i++) {
  20978. var code = input.charCodeAt(i);
  20979. if (code <= 0xff) {
  20980. data[length++] = code;
  20981. } else {
  20982. data[length++] = code >>> 8;
  20983. data[length++] = code & 0xff;
  20984. }
  20985. }
  20986. } else if (input instanceof Uint8Array) {
  20987. data = input;
  20988. length = data.length;
  20989. } else if (typeof input === 'object' && 'length' in input) {
  20990. // processing regular arrays as well, e.g. for IE9
  20991. data = input;
  20992. length = data.length;
  20993. useUint32ArrayView = true;
  20994. } else {
  20995. throw new Error('Wrong data format in MurmurHash3_64_update. ' + 'Input must be a string or array.');
  20996. }
  20997. var blockCounts = length >> 2;
  20998. var tailLength = length - blockCounts * 4;
  20999. // we don't care about endianness here
  21000. var dataUint32 = useUint32ArrayView ? new Uint32ArrayView(data, blockCounts) : new Uint32Array(data.buffer, 0, blockCounts);
  21001. var k1 = 0;
  21002. var k2 = 0;
  21003. var h1 = this.h1;
  21004. var h2 = this.h2;
  21005. var C1 = 0xcc9e2d51;
  21006. var C2 = 0x1b873593;
  21007. var C1_LOW = C1 & MASK_LOW;
  21008. var C2_LOW = C2 & MASK_LOW;
  21009. for (i = 0; i < blockCounts; i++) {
  21010. if (i & 1) {
  21011. k1 = dataUint32[i];
  21012. k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
  21013. k1 = k1 << 15 | k1 >>> 17;
  21014. k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
  21015. h1 ^= k1;
  21016. h1 = h1 << 13 | h1 >>> 19;
  21017. h1 = h1 * 5 + 0xe6546b64;
  21018. } else {
  21019. k2 = dataUint32[i];
  21020. k2 = k2 * C1 & MASK_HIGH | k2 * C1_LOW & MASK_LOW;
  21021. k2 = k2 << 15 | k2 >>> 17;
  21022. k2 = k2 * C2 & MASK_HIGH | k2 * C2_LOW & MASK_LOW;
  21023. h2 ^= k2;
  21024. h2 = h2 << 13 | h2 >>> 19;
  21025. h2 = h2 * 5 + 0xe6546b64;
  21026. }
  21027. }
  21028. k1 = 0;
  21029. switch (tailLength) {
  21030. case 3:
  21031. k1 ^= data[blockCounts * 4 + 2] << 16;
  21032. case 2:
  21033. k1 ^= data[blockCounts * 4 + 1] << 8;
  21034. case 1:
  21035. k1 ^= data[blockCounts * 4];
  21036. k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
  21037. k1 = k1 << 15 | k1 >>> 17;
  21038. k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
  21039. if (blockCounts & 1) {
  21040. h1 ^= k1;
  21041. } else {
  21042. h2 ^= k1;
  21043. }
  21044. }
  21045. this.h1 = h1;
  21046. this.h2 = h2;
  21047. return this;
  21048. },
  21049. hexdigest: function MurmurHash3_64_hexdigest() {
  21050. var h1 = this.h1;
  21051. var h2 = this.h2;
  21052. h1 ^= h2 >>> 1;
  21053. h1 = h1 * 0xed558ccd & MASK_HIGH | h1 * 0x8ccd & MASK_LOW;
  21054. h2 = h2 * 0xff51afd7 & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16;
  21055. h1 ^= h2 >>> 1;
  21056. h1 = h1 * 0x1a85ec53 & MASK_HIGH | h1 * 0xec53 & MASK_LOW;
  21057. h2 = h2 * 0xc4ceb9fe & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16;
  21058. h1 ^= h2 >>> 1;
  21059. for (var i = 0, arr = [
  21060. h1,
  21061. h2
  21062. ], str = ''; i < arr.length; i++) {
  21063. var hex = (arr[i] >>> 0).toString(16);
  21064. while (hex.length < 8) {
  21065. hex = '0' + hex;
  21066. }
  21067. str += hex;
  21068. }
  21069. return str;
  21070. }
  21071. };
  21072. return MurmurHash3_64;
  21073. }();
  21074. exports.MurmurHash3_64 = MurmurHash3_64;
  21075. }));
  21076. (function (root, factory) {
  21077. factory(root.pdfjsCorePrimitives = {}, root.pdfjsSharedUtil);
  21078. }(this, function (exports, sharedUtil) {
  21079. var isArray = sharedUtil.isArray;
  21080. var Name = function NameClosure() {
  21081. function Name(name) {
  21082. this.name = name;
  21083. }
  21084. Name.prototype = {};
  21085. var nameCache = Object.create(null);
  21086. Name.get = function Name_get(name) {
  21087. var nameValue = nameCache[name];
  21088. return nameValue ? nameValue : nameCache[name] = new Name(name);
  21089. };
  21090. return Name;
  21091. }();
  21092. var Cmd = function CmdClosure() {
  21093. function Cmd(cmd) {
  21094. this.cmd = cmd;
  21095. }
  21096. Cmd.prototype = {};
  21097. var cmdCache = Object.create(null);
  21098. Cmd.get = function Cmd_get(cmd) {
  21099. var cmdValue = cmdCache[cmd];
  21100. return cmdValue ? cmdValue : cmdCache[cmd] = new Cmd(cmd);
  21101. };
  21102. return Cmd;
  21103. }();
  21104. var Dict = function DictClosure() {
  21105. var nonSerializable = function nonSerializableClosure() {
  21106. return nonSerializable;
  21107. };
  21108. // creating closure on some variable
  21109. // xref is optional
  21110. function Dict(xref) {
  21111. // Map should only be used internally, use functions below to access.
  21112. this.map = Object.create(null);
  21113. this.xref = xref;
  21114. this.objId = null;
  21115. this.suppressEncryption = false;
  21116. this.__nonSerializable__ = nonSerializable;
  21117. }
  21118. // disable cloning of the Dict
  21119. Dict.prototype = {
  21120. assignXref: function Dict_assignXref(newXref) {
  21121. this.xref = newXref;
  21122. },
  21123. // automatically dereferences Ref objects
  21124. get: function Dict_get(key1, key2, key3) {
  21125. var value;
  21126. var xref = this.xref, suppressEncryption = this.suppressEncryption;
  21127. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map || typeof key2 === 'undefined') {
  21128. return xref ? xref.fetchIfRef(value, suppressEncryption) : value;
  21129. }
  21130. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map || typeof key3 === 'undefined') {
  21131. return xref ? xref.fetchIfRef(value, suppressEncryption) : value;
  21132. }
  21133. value = this.map[key3] || null;
  21134. return xref ? xref.fetchIfRef(value, suppressEncryption) : value;
  21135. },
  21136. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  21137. getAsync: function Dict_getAsync(key1, key2, key3) {
  21138. var value;
  21139. var xref = this.xref, suppressEncryption = this.suppressEncryption;
  21140. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map || typeof key2 === 'undefined') {
  21141. if (xref) {
  21142. return xref.fetchIfRefAsync(value, suppressEncryption);
  21143. }
  21144. return Promise.resolve(value);
  21145. }
  21146. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map || typeof key3 === 'undefined') {
  21147. if (xref) {
  21148. return xref.fetchIfRefAsync(value, suppressEncryption);
  21149. }
  21150. return Promise.resolve(value);
  21151. }
  21152. value = this.map[key3] || null;
  21153. if (xref) {
  21154. return xref.fetchIfRefAsync(value, suppressEncryption);
  21155. }
  21156. return Promise.resolve(value);
  21157. },
  21158. // Same as get(), but dereferences all elements if the result is an Array.
  21159. getArray: function Dict_getArray(key1, key2, key3) {
  21160. var value = this.get(key1, key2, key3);
  21161. var xref = this.xref, suppressEncryption = this.suppressEncryption;
  21162. if (!isArray(value) || !xref) {
  21163. return value;
  21164. }
  21165. value = value.slice();
  21166. // Ensure that we don't modify the Dict data.
  21167. for (var i = 0, ii = value.length; i < ii; i++) {
  21168. if (!isRef(value[i])) {
  21169. continue;
  21170. }
  21171. value[i] = xref.fetch(value[i], suppressEncryption);
  21172. }
  21173. return value;
  21174. },
  21175. // no dereferencing
  21176. getRaw: function Dict_getRaw(key) {
  21177. return this.map[key];
  21178. },
  21179. getKeys: function Dict_getKeys() {
  21180. return Object.keys(this.map);
  21181. },
  21182. set: function Dict_set(key, value) {
  21183. this.map[key] = value;
  21184. },
  21185. has: function Dict_has(key) {
  21186. return key in this.map;
  21187. },
  21188. forEach: function Dict_forEach(callback) {
  21189. for (var key in this.map) {
  21190. callback(key, this.get(key));
  21191. }
  21192. }
  21193. };
  21194. Dict.empty = new Dict(null);
  21195. Dict.merge = function Dict_merge(xref, dictArray) {
  21196. var mergedDict = new Dict(xref);
  21197. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  21198. var dict = dictArray[i];
  21199. if (!isDict(dict)) {
  21200. continue;
  21201. }
  21202. for (var keyName in dict.map) {
  21203. if (mergedDict.map[keyName]) {
  21204. continue;
  21205. }
  21206. mergedDict.map[keyName] = dict.map[keyName];
  21207. }
  21208. }
  21209. return mergedDict;
  21210. };
  21211. return Dict;
  21212. }();
  21213. var Ref = function RefClosure() {
  21214. function Ref(num, gen) {
  21215. this.num = num;
  21216. this.gen = gen;
  21217. }
  21218. Ref.prototype = {
  21219. toString: function Ref_toString() {
  21220. // This function is hot, so we make the string as compact as possible.
  21221. // |this.gen| is almost always zero, so we treat that case specially.
  21222. var str = this.num + 'R';
  21223. if (this.gen !== 0) {
  21224. str += this.gen;
  21225. }
  21226. return str;
  21227. }
  21228. };
  21229. return Ref;
  21230. }();
  21231. // The reference is identified by number and generation.
  21232. // This structure stores only one instance of the reference.
  21233. var RefSet = function RefSetClosure() {
  21234. function RefSet() {
  21235. this.dict = Object.create(null);
  21236. }
  21237. RefSet.prototype = {
  21238. has: function RefSet_has(ref) {
  21239. return ref.toString() in this.dict;
  21240. },
  21241. put: function RefSet_put(ref) {
  21242. this.dict[ref.toString()] = true;
  21243. },
  21244. remove: function RefSet_remove(ref) {
  21245. delete this.dict[ref.toString()];
  21246. }
  21247. };
  21248. return RefSet;
  21249. }();
  21250. var RefSetCache = function RefSetCacheClosure() {
  21251. function RefSetCache() {
  21252. this.dict = Object.create(null);
  21253. }
  21254. RefSetCache.prototype = {
  21255. get: function RefSetCache_get(ref) {
  21256. return this.dict[ref.toString()];
  21257. },
  21258. has: function RefSetCache_has(ref) {
  21259. return ref.toString() in this.dict;
  21260. },
  21261. put: function RefSetCache_put(ref, obj) {
  21262. this.dict[ref.toString()] = obj;
  21263. },
  21264. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  21265. this.dict[ref.toString()] = this.get(aliasRef);
  21266. },
  21267. forEach: function RefSetCache_forEach(fn, thisArg) {
  21268. for (var i in this.dict) {
  21269. fn.call(thisArg, this.dict[i]);
  21270. }
  21271. },
  21272. clear: function RefSetCache_clear() {
  21273. this.dict = Object.create(null);
  21274. }
  21275. };
  21276. return RefSetCache;
  21277. }();
  21278. function isName(v, name) {
  21279. return v instanceof Name && (name === undefined || v.name === name);
  21280. }
  21281. function isCmd(v, cmd) {
  21282. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  21283. }
  21284. function isDict(v, type) {
  21285. return v instanceof Dict && (type === undefined || isName(v.get('Type'), type));
  21286. }
  21287. function isRef(v) {
  21288. return v instanceof Ref;
  21289. }
  21290. function isRefsEqual(v1, v2) {
  21291. return v1.num === v2.num && v1.gen === v2.gen;
  21292. }
  21293. function isStream(v) {
  21294. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  21295. }
  21296. exports.Cmd = Cmd;
  21297. exports.Dict = Dict;
  21298. exports.Name = Name;
  21299. exports.Ref = Ref;
  21300. exports.RefSet = RefSet;
  21301. exports.RefSetCache = RefSetCache;
  21302. exports.isCmd = isCmd;
  21303. exports.isDict = isDict;
  21304. exports.isName = isName;
  21305. exports.isRef = isRef;
  21306. exports.isRefsEqual = isRefsEqual;
  21307. exports.isStream = isStream;
  21308. }));
  21309. (function (root, factory) {
  21310. factory(root.pdfjsCoreStandardFonts = {}, root.pdfjsSharedUtil);
  21311. }(this, function (exports, sharedUtil) {
  21312. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  21313. /**
  21314. * Hold a map of decoded fonts and of the standard fourteen Type1
  21315. * fonts and their acronyms.
  21316. */
  21317. var getStdFontMap = getLookupTableFactory(function (t) {
  21318. t['ArialNarrow'] = 'Helvetica';
  21319. t['ArialNarrow-Bold'] = 'Helvetica-Bold';
  21320. t['ArialNarrow-BoldItalic'] = 'Helvetica-BoldOblique';
  21321. t['ArialNarrow-Italic'] = 'Helvetica-Oblique';
  21322. t['ArialBlack'] = 'Helvetica';
  21323. t['ArialBlack-Bold'] = 'Helvetica-Bold';
  21324. t['ArialBlack-BoldItalic'] = 'Helvetica-BoldOblique';
  21325. t['ArialBlack-Italic'] = 'Helvetica-Oblique';
  21326. t['Arial'] = 'Helvetica';
  21327. t['Arial-Bold'] = 'Helvetica-Bold';
  21328. t['Arial-BoldItalic'] = 'Helvetica-BoldOblique';
  21329. t['Arial-Italic'] = 'Helvetica-Oblique';
  21330. t['Arial-BoldItalicMT'] = 'Helvetica-BoldOblique';
  21331. t['Arial-BoldMT'] = 'Helvetica-Bold';
  21332. t['Arial-ItalicMT'] = 'Helvetica-Oblique';
  21333. t['ArialMT'] = 'Helvetica';
  21334. t['Courier-Bold'] = 'Courier-Bold';
  21335. t['Courier-BoldItalic'] = 'Courier-BoldOblique';
  21336. t['Courier-Italic'] = 'Courier-Oblique';
  21337. t['CourierNew'] = 'Courier';
  21338. t['CourierNew-Bold'] = 'Courier-Bold';
  21339. t['CourierNew-BoldItalic'] = 'Courier-BoldOblique';
  21340. t['CourierNew-Italic'] = 'Courier-Oblique';
  21341. t['CourierNewPS-BoldItalicMT'] = 'Courier-BoldOblique';
  21342. t['CourierNewPS-BoldMT'] = 'Courier-Bold';
  21343. t['CourierNewPS-ItalicMT'] = 'Courier-Oblique';
  21344. t['CourierNewPSMT'] = 'Courier';
  21345. t['Helvetica'] = 'Helvetica';
  21346. t['Helvetica-Bold'] = 'Helvetica-Bold';
  21347. t['Helvetica-BoldItalic'] = 'Helvetica-BoldOblique';
  21348. t['Helvetica-BoldOblique'] = 'Helvetica-BoldOblique';
  21349. t['Helvetica-Italic'] = 'Helvetica-Oblique';
  21350. t['Helvetica-Oblique'] = 'Helvetica-Oblique';
  21351. t['Symbol-Bold'] = 'Symbol';
  21352. t['Symbol-BoldItalic'] = 'Symbol';
  21353. t['Symbol-Italic'] = 'Symbol';
  21354. t['TimesNewRoman'] = 'Times-Roman';
  21355. t['TimesNewRoman-Bold'] = 'Times-Bold';
  21356. t['TimesNewRoman-BoldItalic'] = 'Times-BoldItalic';
  21357. t['TimesNewRoman-Italic'] = 'Times-Italic';
  21358. t['TimesNewRomanPS'] = 'Times-Roman';
  21359. t['TimesNewRomanPS-Bold'] = 'Times-Bold';
  21360. t['TimesNewRomanPS-BoldItalic'] = 'Times-BoldItalic';
  21361. t['TimesNewRomanPS-BoldItalicMT'] = 'Times-BoldItalic';
  21362. t['TimesNewRomanPS-BoldMT'] = 'Times-Bold';
  21363. t['TimesNewRomanPS-Italic'] = 'Times-Italic';
  21364. t['TimesNewRomanPS-ItalicMT'] = 'Times-Italic';
  21365. t['TimesNewRomanPSMT'] = 'Times-Roman';
  21366. t['TimesNewRomanPSMT-Bold'] = 'Times-Bold';
  21367. t['TimesNewRomanPSMT-BoldItalic'] = 'Times-BoldItalic';
  21368. t['TimesNewRomanPSMT-Italic'] = 'Times-Italic';
  21369. });
  21370. /**
  21371. * Holds the map of the non-standard fonts that might be included as
  21372. * a standard fonts without glyph data.
  21373. */
  21374. var getNonStdFontMap = getLookupTableFactory(function (t) {
  21375. t['CenturyGothic'] = 'Helvetica';
  21376. t['CenturyGothic-Bold'] = 'Helvetica-Bold';
  21377. t['CenturyGothic-BoldItalic'] = 'Helvetica-BoldOblique';
  21378. t['CenturyGothic-Italic'] = 'Helvetica-Oblique';
  21379. t['ComicSansMS'] = 'Comic Sans MS';
  21380. t['ComicSansMS-Bold'] = 'Comic Sans MS-Bold';
  21381. t['ComicSansMS-BoldItalic'] = 'Comic Sans MS-BoldItalic';
  21382. t['ComicSansMS-Italic'] = 'Comic Sans MS-Italic';
  21383. t['LucidaConsole'] = 'Courier';
  21384. t['LucidaConsole-Bold'] = 'Courier-Bold';
  21385. t['LucidaConsole-BoldItalic'] = 'Courier-BoldOblique';
  21386. t['LucidaConsole-Italic'] = 'Courier-Oblique';
  21387. t['MS-Gothic'] = 'MS Gothic';
  21388. t['MS-Gothic-Bold'] = 'MS Gothic-Bold';
  21389. t['MS-Gothic-BoldItalic'] = 'MS Gothic-BoldItalic';
  21390. t['MS-Gothic-Italic'] = 'MS Gothic-Italic';
  21391. t['MS-Mincho'] = 'MS Mincho';
  21392. t['MS-Mincho-Bold'] = 'MS Mincho-Bold';
  21393. t['MS-Mincho-BoldItalic'] = 'MS Mincho-BoldItalic';
  21394. t['MS-Mincho-Italic'] = 'MS Mincho-Italic';
  21395. t['MS-PGothic'] = 'MS PGothic';
  21396. t['MS-PGothic-Bold'] = 'MS PGothic-Bold';
  21397. t['MS-PGothic-BoldItalic'] = 'MS PGothic-BoldItalic';
  21398. t['MS-PGothic-Italic'] = 'MS PGothic-Italic';
  21399. t['MS-PMincho'] = 'MS PMincho';
  21400. t['MS-PMincho-Bold'] = 'MS PMincho-Bold';
  21401. t['MS-PMincho-BoldItalic'] = 'MS PMincho-BoldItalic';
  21402. t['MS-PMincho-Italic'] = 'MS PMincho-Italic';
  21403. t['Wingdings'] = 'ZapfDingbats';
  21404. });
  21405. var getSerifFonts = getLookupTableFactory(function (t) {
  21406. t['Adobe Jenson'] = true;
  21407. t['Adobe Text'] = true;
  21408. t['Albertus'] = true;
  21409. t['Aldus'] = true;
  21410. t['Alexandria'] = true;
  21411. t['Algerian'] = true;
  21412. t['American Typewriter'] = true;
  21413. t['Antiqua'] = true;
  21414. t['Apex'] = true;
  21415. t['Arno'] = true;
  21416. t['Aster'] = true;
  21417. t['Aurora'] = true;
  21418. t['Baskerville'] = true;
  21419. t['Bell'] = true;
  21420. t['Bembo'] = true;
  21421. t['Bembo Schoolbook'] = true;
  21422. t['Benguiat'] = true;
  21423. t['Berkeley Old Style'] = true;
  21424. t['Bernhard Modern'] = true;
  21425. t['Berthold City'] = true;
  21426. t['Bodoni'] = true;
  21427. t['Bauer Bodoni'] = true;
  21428. t['Book Antiqua'] = true;
  21429. t['Bookman'] = true;
  21430. t['Bordeaux Roman'] = true;
  21431. t['Californian FB'] = true;
  21432. t['Calisto'] = true;
  21433. t['Calvert'] = true;
  21434. t['Capitals'] = true;
  21435. t['Cambria'] = true;
  21436. t['Cartier'] = true;
  21437. t['Caslon'] = true;
  21438. t['Catull'] = true;
  21439. t['Centaur'] = true;
  21440. t['Century Old Style'] = true;
  21441. t['Century Schoolbook'] = true;
  21442. t['Chaparral'] = true;
  21443. t['Charis SIL'] = true;
  21444. t['Cheltenham'] = true;
  21445. t['Cholla Slab'] = true;
  21446. t['Clarendon'] = true;
  21447. t['Clearface'] = true;
  21448. t['Cochin'] = true;
  21449. t['Colonna'] = true;
  21450. t['Computer Modern'] = true;
  21451. t['Concrete Roman'] = true;
  21452. t['Constantia'] = true;
  21453. t['Cooper Black'] = true;
  21454. t['Corona'] = true;
  21455. t['Ecotype'] = true;
  21456. t['Egyptienne'] = true;
  21457. t['Elephant'] = true;
  21458. t['Excelsior'] = true;
  21459. t['Fairfield'] = true;
  21460. t['FF Scala'] = true;
  21461. t['Folkard'] = true;
  21462. t['Footlight'] = true;
  21463. t['FreeSerif'] = true;
  21464. t['Friz Quadrata'] = true;
  21465. t['Garamond'] = true;
  21466. t['Gentium'] = true;
  21467. t['Georgia'] = true;
  21468. t['Gloucester'] = true;
  21469. t['Goudy Old Style'] = true;
  21470. t['Goudy Schoolbook'] = true;
  21471. t['Goudy Pro Font'] = true;
  21472. t['Granjon'] = true;
  21473. t['Guardian Egyptian'] = true;
  21474. t['Heather'] = true;
  21475. t['Hercules'] = true;
  21476. t['High Tower Text'] = true;
  21477. t['Hiroshige'] = true;
  21478. t['Hoefler Text'] = true;
  21479. t['Humana Serif'] = true;
  21480. t['Imprint'] = true;
  21481. t['Ionic No. 5'] = true;
  21482. t['Janson'] = true;
  21483. t['Joanna'] = true;
  21484. t['Korinna'] = true;
  21485. t['Lexicon'] = true;
  21486. t['Liberation Serif'] = true;
  21487. t['Linux Libertine'] = true;
  21488. t['Literaturnaya'] = true;
  21489. t['Lucida'] = true;
  21490. t['Lucida Bright'] = true;
  21491. t['Melior'] = true;
  21492. t['Memphis'] = true;
  21493. t['Miller'] = true;
  21494. t['Minion'] = true;
  21495. t['Modern'] = true;
  21496. t['Mona Lisa'] = true;
  21497. t['Mrs Eaves'] = true;
  21498. t['MS Serif'] = true;
  21499. t['Museo Slab'] = true;
  21500. t['New York'] = true;
  21501. t['Nimbus Roman'] = true;
  21502. t['NPS Rawlinson Roadway'] = true;
  21503. t['Palatino'] = true;
  21504. t['Perpetua'] = true;
  21505. t['Plantin'] = true;
  21506. t['Plantin Schoolbook'] = true;
  21507. t['Playbill'] = true;
  21508. t['Poor Richard'] = true;
  21509. t['Rawlinson Roadway'] = true;
  21510. t['Renault'] = true;
  21511. t['Requiem'] = true;
  21512. t['Rockwell'] = true;
  21513. t['Roman'] = true;
  21514. t['Rotis Serif'] = true;
  21515. t['Sabon'] = true;
  21516. t['Scala'] = true;
  21517. t['Seagull'] = true;
  21518. t['Sistina'] = true;
  21519. t['Souvenir'] = true;
  21520. t['STIX'] = true;
  21521. t['Stone Informal'] = true;
  21522. t['Stone Serif'] = true;
  21523. t['Sylfaen'] = true;
  21524. t['Times'] = true;
  21525. t['Trajan'] = true;
  21526. t['Trinité'] = true;
  21527. t['Trump Mediaeval'] = true;
  21528. t['Utopia'] = true;
  21529. t['Vale Type'] = true;
  21530. t['Bitstream Vera'] = true;
  21531. t['Vera Serif'] = true;
  21532. t['Versailles'] = true;
  21533. t['Wanted'] = true;
  21534. t['Weiss'] = true;
  21535. t['Wide Latin'] = true;
  21536. t['Windsor'] = true;
  21537. t['XITS'] = true;
  21538. });
  21539. var getSymbolsFonts = getLookupTableFactory(function (t) {
  21540. t['Dingbats'] = true;
  21541. t['Symbol'] = true;
  21542. t['ZapfDingbats'] = true;
  21543. });
  21544. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID
  21545. // fonts, but does not embed the CID to GID mapping. The mapping is incomplete
  21546. // for all glyphs, but common for some set of the standard fonts.
  21547. var getGlyphMapForStandardFonts = getLookupTableFactory(function (t) {
  21548. t[2] = 10;
  21549. t[3] = 32;
  21550. t[4] = 33;
  21551. t[5] = 34;
  21552. t[6] = 35;
  21553. t[7] = 36;
  21554. t[8] = 37;
  21555. t[9] = 38;
  21556. t[10] = 39;
  21557. t[11] = 40;
  21558. t[12] = 41;
  21559. t[13] = 42;
  21560. t[14] = 43;
  21561. t[15] = 44;
  21562. t[16] = 45;
  21563. t[17] = 46;
  21564. t[18] = 47;
  21565. t[19] = 48;
  21566. t[20] = 49;
  21567. t[21] = 50;
  21568. t[22] = 51;
  21569. t[23] = 52;
  21570. t[24] = 53;
  21571. t[25] = 54;
  21572. t[26] = 55;
  21573. t[27] = 56;
  21574. t[28] = 57;
  21575. t[29] = 58;
  21576. t[30] = 894;
  21577. t[31] = 60;
  21578. t[32] = 61;
  21579. t[33] = 62;
  21580. t[34] = 63;
  21581. t[35] = 64;
  21582. t[36] = 65;
  21583. t[37] = 66;
  21584. t[38] = 67;
  21585. t[39] = 68;
  21586. t[40] = 69;
  21587. t[41] = 70;
  21588. t[42] = 71;
  21589. t[43] = 72;
  21590. t[44] = 73;
  21591. t[45] = 74;
  21592. t[46] = 75;
  21593. t[47] = 76;
  21594. t[48] = 77;
  21595. t[49] = 78;
  21596. t[50] = 79;
  21597. t[51] = 80;
  21598. t[52] = 81;
  21599. t[53] = 82;
  21600. t[54] = 83;
  21601. t[55] = 84;
  21602. t[56] = 85;
  21603. t[57] = 86;
  21604. t[58] = 87;
  21605. t[59] = 88;
  21606. t[60] = 89;
  21607. t[61] = 90;
  21608. t[62] = 91;
  21609. t[63] = 92;
  21610. t[64] = 93;
  21611. t[65] = 94;
  21612. t[66] = 95;
  21613. t[67] = 96;
  21614. t[68] = 97;
  21615. t[69] = 98;
  21616. t[70] = 99;
  21617. t[71] = 100;
  21618. t[72] = 101;
  21619. t[73] = 102;
  21620. t[74] = 103;
  21621. t[75] = 104;
  21622. t[76] = 105;
  21623. t[77] = 106;
  21624. t[78] = 107;
  21625. t[79] = 108;
  21626. t[80] = 109;
  21627. t[81] = 110;
  21628. t[82] = 111;
  21629. t[83] = 112;
  21630. t[84] = 113;
  21631. t[85] = 114;
  21632. t[86] = 115;
  21633. t[87] = 116;
  21634. t[88] = 117;
  21635. t[89] = 118;
  21636. t[90] = 119;
  21637. t[91] = 120;
  21638. t[92] = 121;
  21639. t[93] = 122;
  21640. t[94] = 123;
  21641. t[95] = 124;
  21642. t[96] = 125;
  21643. t[97] = 126;
  21644. t[98] = 196;
  21645. t[99] = 197;
  21646. t[100] = 199;
  21647. t[101] = 201;
  21648. t[102] = 209;
  21649. t[103] = 214;
  21650. t[104] = 220;
  21651. t[105] = 225;
  21652. t[106] = 224;
  21653. t[107] = 226;
  21654. t[108] = 228;
  21655. t[109] = 227;
  21656. t[110] = 229;
  21657. t[111] = 231;
  21658. t[112] = 233;
  21659. t[113] = 232;
  21660. t[114] = 234;
  21661. t[115] = 235;
  21662. t[116] = 237;
  21663. t[117] = 236;
  21664. t[118] = 238;
  21665. t[119] = 239;
  21666. t[120] = 241;
  21667. t[121] = 243;
  21668. t[122] = 242;
  21669. t[123] = 244;
  21670. t[124] = 246;
  21671. t[125] = 245;
  21672. t[126] = 250;
  21673. t[127] = 249;
  21674. t[128] = 251;
  21675. t[129] = 252;
  21676. t[130] = 8224;
  21677. t[131] = 176;
  21678. t[132] = 162;
  21679. t[133] = 163;
  21680. t[134] = 167;
  21681. t[135] = 8226;
  21682. t[136] = 182;
  21683. t[137] = 223;
  21684. t[138] = 174;
  21685. t[139] = 169;
  21686. t[140] = 8482;
  21687. t[141] = 180;
  21688. t[142] = 168;
  21689. t[143] = 8800;
  21690. t[144] = 198;
  21691. t[145] = 216;
  21692. t[146] = 8734;
  21693. t[147] = 177;
  21694. t[148] = 8804;
  21695. t[149] = 8805;
  21696. t[150] = 165;
  21697. t[151] = 181;
  21698. t[152] = 8706;
  21699. t[153] = 8721;
  21700. t[154] = 8719;
  21701. t[156] = 8747;
  21702. t[157] = 170;
  21703. t[158] = 186;
  21704. t[159] = 8486;
  21705. t[160] = 230;
  21706. t[161] = 248;
  21707. t[162] = 191;
  21708. t[163] = 161;
  21709. t[164] = 172;
  21710. t[165] = 8730;
  21711. t[166] = 402;
  21712. t[167] = 8776;
  21713. t[168] = 8710;
  21714. t[169] = 171;
  21715. t[170] = 187;
  21716. t[171] = 8230;
  21717. t[210] = 218;
  21718. t[223] = 711;
  21719. t[224] = 321;
  21720. t[225] = 322;
  21721. t[227] = 353;
  21722. t[229] = 382;
  21723. t[234] = 253;
  21724. t[252] = 263;
  21725. t[253] = 268;
  21726. t[254] = 269;
  21727. t[258] = 258;
  21728. t[260] = 260;
  21729. t[261] = 261;
  21730. t[265] = 280;
  21731. t[266] = 281;
  21732. t[268] = 283;
  21733. t[269] = 313;
  21734. t[275] = 323;
  21735. t[276] = 324;
  21736. t[278] = 328;
  21737. t[284] = 345;
  21738. t[285] = 346;
  21739. t[286] = 347;
  21740. t[292] = 367;
  21741. t[295] = 377;
  21742. t[296] = 378;
  21743. t[298] = 380;
  21744. t[305] = 963;
  21745. t[306] = 964;
  21746. t[307] = 966;
  21747. t[308] = 8215;
  21748. t[309] = 8252;
  21749. t[310] = 8319;
  21750. t[311] = 8359;
  21751. t[312] = 8592;
  21752. t[313] = 8593;
  21753. t[337] = 9552;
  21754. t[493] = 1039;
  21755. t[494] = 1040;
  21756. t[705] = 1524;
  21757. t[706] = 8362;
  21758. t[710] = 64288;
  21759. t[711] = 64298;
  21760. t[759] = 1617;
  21761. t[761] = 1776;
  21762. t[763] = 1778;
  21763. t[775] = 1652;
  21764. t[777] = 1764;
  21765. t[778] = 1780;
  21766. t[779] = 1781;
  21767. t[780] = 1782;
  21768. t[782] = 771;
  21769. t[783] = 64726;
  21770. t[786] = 8363;
  21771. t[788] = 8532;
  21772. t[790] = 768;
  21773. t[791] = 769;
  21774. t[792] = 768;
  21775. t[795] = 803;
  21776. t[797] = 64336;
  21777. t[798] = 64337;
  21778. t[799] = 64342;
  21779. t[800] = 64343;
  21780. t[801] = 64344;
  21781. t[802] = 64345;
  21782. t[803] = 64362;
  21783. t[804] = 64363;
  21784. t[805] = 64364;
  21785. t[2424] = 7821;
  21786. t[2425] = 7822;
  21787. t[2426] = 7823;
  21788. t[2427] = 7824;
  21789. t[2428] = 7825;
  21790. t[2429] = 7826;
  21791. t[2430] = 7827;
  21792. t[2433] = 7682;
  21793. t[2678] = 8045;
  21794. t[2679] = 8046;
  21795. t[2830] = 1552;
  21796. t[2838] = 686;
  21797. t[2840] = 751;
  21798. t[2842] = 753;
  21799. t[2843] = 754;
  21800. t[2844] = 755;
  21801. t[2846] = 757;
  21802. t[2856] = 767;
  21803. t[2857] = 848;
  21804. t[2858] = 849;
  21805. t[2862] = 853;
  21806. t[2863] = 854;
  21807. t[2864] = 855;
  21808. t[2865] = 861;
  21809. t[2866] = 862;
  21810. t[2906] = 7460;
  21811. t[2908] = 7462;
  21812. t[2909] = 7463;
  21813. t[2910] = 7464;
  21814. t[2912] = 7466;
  21815. t[2913] = 7467;
  21816. t[2914] = 7468;
  21817. t[2916] = 7470;
  21818. t[2917] = 7471;
  21819. t[2918] = 7472;
  21820. t[2920] = 7474;
  21821. t[2921] = 7475;
  21822. t[2922] = 7476;
  21823. t[2924] = 7478;
  21824. t[2925] = 7479;
  21825. t[2926] = 7480;
  21826. t[2928] = 7482;
  21827. t[2929] = 7483;
  21828. t[2930] = 7484;
  21829. t[2932] = 7486;
  21830. t[2933] = 7487;
  21831. t[2934] = 7488;
  21832. t[2936] = 7490;
  21833. t[2937] = 7491;
  21834. t[2938] = 7492;
  21835. t[2940] = 7494;
  21836. t[2941] = 7495;
  21837. t[2942] = 7496;
  21838. t[2944] = 7498;
  21839. t[2946] = 7500;
  21840. t[2948] = 7502;
  21841. t[2950] = 7504;
  21842. t[2951] = 7505;
  21843. t[2952] = 7506;
  21844. t[2954] = 7508;
  21845. t[2955] = 7509;
  21846. t[2956] = 7510;
  21847. t[2958] = 7512;
  21848. t[2959] = 7513;
  21849. t[2960] = 7514;
  21850. t[2962] = 7516;
  21851. t[2963] = 7517;
  21852. t[2964] = 7518;
  21853. t[2966] = 7520;
  21854. t[2967] = 7521;
  21855. t[2968] = 7522;
  21856. t[2970] = 7524;
  21857. t[2971] = 7525;
  21858. t[2972] = 7526;
  21859. t[2974] = 7528;
  21860. t[2975] = 7529;
  21861. t[2976] = 7530;
  21862. t[2978] = 1537;
  21863. t[2979] = 1538;
  21864. t[2980] = 1539;
  21865. t[2982] = 1549;
  21866. t[2983] = 1551;
  21867. t[2984] = 1552;
  21868. t[2986] = 1554;
  21869. t[2987] = 1555;
  21870. t[2988] = 1556;
  21871. t[2990] = 1623;
  21872. t[2991] = 1624;
  21873. t[2995] = 1775;
  21874. t[2999] = 1791;
  21875. t[3002] = 64290;
  21876. t[3003] = 64291;
  21877. t[3004] = 64292;
  21878. t[3006] = 64294;
  21879. t[3007] = 64295;
  21880. t[3008] = 64296;
  21881. t[3011] = 1900;
  21882. t[3014] = 8223;
  21883. t[3015] = 8244;
  21884. t[3017] = 7532;
  21885. t[3018] = 7533;
  21886. t[3019] = 7534;
  21887. t[3075] = 7590;
  21888. t[3076] = 7591;
  21889. t[3079] = 7594;
  21890. t[3080] = 7595;
  21891. t[3083] = 7598;
  21892. t[3084] = 7599;
  21893. t[3087] = 7602;
  21894. t[3088] = 7603;
  21895. t[3091] = 7606;
  21896. t[3092] = 7607;
  21897. t[3095] = 7610;
  21898. t[3096] = 7611;
  21899. t[3099] = 7614;
  21900. t[3100] = 7615;
  21901. t[3103] = 7618;
  21902. t[3104] = 7619;
  21903. t[3107] = 8337;
  21904. t[3108] = 8338;
  21905. t[3116] = 1884;
  21906. t[3119] = 1885;
  21907. t[3120] = 1885;
  21908. t[3123] = 1886;
  21909. t[3124] = 1886;
  21910. t[3127] = 1887;
  21911. t[3128] = 1887;
  21912. t[3131] = 1888;
  21913. t[3132] = 1888;
  21914. t[3135] = 1889;
  21915. t[3136] = 1889;
  21916. t[3139] = 1890;
  21917. t[3140] = 1890;
  21918. t[3143] = 1891;
  21919. t[3144] = 1891;
  21920. t[3147] = 1892;
  21921. t[3148] = 1892;
  21922. t[3153] = 580;
  21923. t[3154] = 581;
  21924. t[3157] = 584;
  21925. t[3158] = 585;
  21926. t[3161] = 588;
  21927. t[3162] = 589;
  21928. t[3165] = 891;
  21929. t[3166] = 892;
  21930. t[3169] = 1274;
  21931. t[3170] = 1275;
  21932. t[3173] = 1278;
  21933. t[3174] = 1279;
  21934. t[3181] = 7622;
  21935. t[3182] = 7623;
  21936. t[3282] = 11799;
  21937. t[3316] = 578;
  21938. t[3379] = 42785;
  21939. t[3393] = 1159;
  21940. t[3416] = 8377;
  21941. });
  21942. // The glyph map for ArialBlack differs slightly from the glyph map used for
  21943. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  21944. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  21945. var getSupplementalGlyphMapForArialBlack = getLookupTableFactory(function (t) {
  21946. t[227] = 322;
  21947. t[264] = 261;
  21948. t[291] = 346;
  21949. });
  21950. exports.getStdFontMap = getStdFontMap;
  21951. exports.getNonStdFontMap = getNonStdFontMap;
  21952. exports.getSerifFonts = getSerifFonts;
  21953. exports.getSymbolsFonts = getSymbolsFonts;
  21954. exports.getGlyphMapForStandardFonts = getGlyphMapForStandardFonts;
  21955. exports.getSupplementalGlyphMapForArialBlack = getSupplementalGlyphMapForArialBlack;
  21956. }));
  21957. (function (root, factory) {
  21958. factory(root.pdfjsCoreUnicode = {}, root.pdfjsSharedUtil);
  21959. }(this, function (exports, sharedUtil) {
  21960. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  21961. // Some characters, e.g. copyrightserif, are mapped to the private use area
  21962. // and might not be displayed using standard fonts. Mapping/hacking well-known
  21963. // chars to the similar equivalents in the normal characters range.
  21964. var getSpecialPUASymbols = getLookupTableFactory(function (t) {
  21965. t[63721] = 0x00A9;
  21966. // copyrightsans (0xF8E9) => copyright
  21967. t[63193] = 0x00A9;
  21968. // copyrightserif (0xF6D9) => copyright
  21969. t[63720] = 0x00AE;
  21970. // registersans (0xF8E8) => registered
  21971. t[63194] = 0x00AE;
  21972. // registerserif (0xF6DA) => registered
  21973. t[63722] = 0x2122;
  21974. // trademarksans (0xF8EA) => trademark
  21975. t[63195] = 0x2122;
  21976. // trademarkserif (0xF6DB) => trademark
  21977. t[63729] = 0x23A7;
  21978. // bracelefttp (0xF8F1)
  21979. t[63730] = 0x23A8;
  21980. // braceleftmid (0xF8F2)
  21981. t[63731] = 0x23A9;
  21982. // braceleftbt (0xF8F3)
  21983. t[63740] = 0x23AB;
  21984. // bracerighttp (0xF8FC)
  21985. t[63741] = 0x23AC;
  21986. // bracerightmid (0xF8FD)
  21987. t[63742] = 0x23AD;
  21988. // bracerightbt (0xF8FE)
  21989. t[63726] = 0x23A1;
  21990. // bracketlefttp (0xF8EE)
  21991. t[63727] = 0x23A2;
  21992. // bracketleftex (0xF8EF)
  21993. t[63728] = 0x23A3;
  21994. // bracketleftbt (0xF8F0)
  21995. t[63737] = 0x23A4;
  21996. // bracketrighttp (0xF8F9)
  21997. t[63738] = 0x23A5;
  21998. // bracketrightex (0xF8FA)
  21999. t[63739] = 0x23A6;
  22000. // bracketrightbt (0xF8FB)
  22001. t[63723] = 0x239B;
  22002. // parenlefttp (0xF8EB)
  22003. t[63724] = 0x239C;
  22004. // parenleftex (0xF8EC)
  22005. t[63725] = 0x239D;
  22006. // parenleftbt (0xF8ED)
  22007. t[63734] = 0x239E;
  22008. // parenrighttp (0xF8F6)
  22009. t[63735] = 0x239F;
  22010. // parenrightex (0xF8F7)
  22011. t[63736] = 0x23A0;
  22012. });
  22013. // parenrightbt (0xF8F8)
  22014. function mapSpecialUnicodeValues(code) {
  22015. if (code >= 0xFFF0 && code <= 0xFFFF) {
  22016. // Specials unicode block.
  22017. return 0;
  22018. } else if (code >= 0xF600 && code <= 0xF8FF) {
  22019. return getSpecialPUASymbols()[code] || code;
  22020. }
  22021. return code;
  22022. }
  22023. function getUnicodeForGlyph(name, glyphsUnicodeMap) {
  22024. var unicode = glyphsUnicodeMap[name];
  22025. if (unicode !== undefined) {
  22026. return unicode;
  22027. }
  22028. if (!name) {
  22029. return -1;
  22030. }
  22031. // Try to recover valid Unicode values from 'uniXXXX'/'uXXXX{XX}' glyphs.
  22032. if (name[0] === 'u') {
  22033. var nameLen = name.length, hexStr;
  22034. if (nameLen === 7 && name[1] === 'n' && name[2] === 'i') {
  22035. // 'uniXXXX'
  22036. hexStr = name.substr(3);
  22037. } else if (nameLen >= 5 && nameLen <= 7) {
  22038. // 'uXXXX{XX}'
  22039. hexStr = name.substr(1);
  22040. } else {
  22041. return -1;
  22042. }
  22043. // Check for upper-case hexadecimal characters, to avoid false positives.
  22044. if (hexStr === hexStr.toUpperCase()) {
  22045. unicode = parseInt(hexStr, 16);
  22046. if (unicode >= 0) {
  22047. return unicode;
  22048. }
  22049. }
  22050. }
  22051. return -1;
  22052. }
  22053. var UnicodeRanges = [
  22054. {
  22055. 'begin': 0x0000,
  22056. 'end': 0x007F
  22057. },
  22058. // Basic Latin
  22059. {
  22060. 'begin': 0x0080,
  22061. 'end': 0x00FF
  22062. },
  22063. // Latin-1 Supplement
  22064. {
  22065. 'begin': 0x0100,
  22066. 'end': 0x017F
  22067. },
  22068. // Latin Extended-A
  22069. {
  22070. 'begin': 0x0180,
  22071. 'end': 0x024F
  22072. },
  22073. // Latin Extended-B
  22074. {
  22075. 'begin': 0x0250,
  22076. 'end': 0x02AF
  22077. },
  22078. // IPA Extensions
  22079. {
  22080. 'begin': 0x02B0,
  22081. 'end': 0x02FF
  22082. },
  22083. // Spacing Modifier Letters
  22084. {
  22085. 'begin': 0x0300,
  22086. 'end': 0x036F
  22087. },
  22088. // Combining Diacritical Marks
  22089. {
  22090. 'begin': 0x0370,
  22091. 'end': 0x03FF
  22092. },
  22093. // Greek and Coptic
  22094. {
  22095. 'begin': 0x2C80,
  22096. 'end': 0x2CFF
  22097. },
  22098. // Coptic
  22099. {
  22100. 'begin': 0x0400,
  22101. 'end': 0x04FF
  22102. },
  22103. // Cyrillic
  22104. {
  22105. 'begin': 0x0530,
  22106. 'end': 0x058F
  22107. },
  22108. // Armenian
  22109. {
  22110. 'begin': 0x0590,
  22111. 'end': 0x05FF
  22112. },
  22113. // Hebrew
  22114. {
  22115. 'begin': 0xA500,
  22116. 'end': 0xA63F
  22117. },
  22118. // Vai
  22119. {
  22120. 'begin': 0x0600,
  22121. 'end': 0x06FF
  22122. },
  22123. // Arabic
  22124. {
  22125. 'begin': 0x07C0,
  22126. 'end': 0x07FF
  22127. },
  22128. // NKo
  22129. {
  22130. 'begin': 0x0900,
  22131. 'end': 0x097F
  22132. },
  22133. // Devanagari
  22134. {
  22135. 'begin': 0x0980,
  22136. 'end': 0x09FF
  22137. },
  22138. // Bengali
  22139. {
  22140. 'begin': 0x0A00,
  22141. 'end': 0x0A7F
  22142. },
  22143. // Gurmukhi
  22144. {
  22145. 'begin': 0x0A80,
  22146. 'end': 0x0AFF
  22147. },
  22148. // Gujarati
  22149. {
  22150. 'begin': 0x0B00,
  22151. 'end': 0x0B7F
  22152. },
  22153. // Oriya
  22154. {
  22155. 'begin': 0x0B80,
  22156. 'end': 0x0BFF
  22157. },
  22158. // Tamil
  22159. {
  22160. 'begin': 0x0C00,
  22161. 'end': 0x0C7F
  22162. },
  22163. // Telugu
  22164. {
  22165. 'begin': 0x0C80,
  22166. 'end': 0x0CFF
  22167. },
  22168. // Kannada
  22169. {
  22170. 'begin': 0x0D00,
  22171. 'end': 0x0D7F
  22172. },
  22173. // Malayalam
  22174. {
  22175. 'begin': 0x0E00,
  22176. 'end': 0x0E7F
  22177. },
  22178. // Thai
  22179. {
  22180. 'begin': 0x0E80,
  22181. 'end': 0x0EFF
  22182. },
  22183. // Lao
  22184. {
  22185. 'begin': 0x10A0,
  22186. 'end': 0x10FF
  22187. },
  22188. // Georgian
  22189. {
  22190. 'begin': 0x1B00,
  22191. 'end': 0x1B7F
  22192. },
  22193. // Balinese
  22194. {
  22195. 'begin': 0x1100,
  22196. 'end': 0x11FF
  22197. },
  22198. // Hangul Jamo
  22199. {
  22200. 'begin': 0x1E00,
  22201. 'end': 0x1EFF
  22202. },
  22203. // Latin Extended Additional
  22204. {
  22205. 'begin': 0x1F00,
  22206. 'end': 0x1FFF
  22207. },
  22208. // Greek Extended
  22209. {
  22210. 'begin': 0x2000,
  22211. 'end': 0x206F
  22212. },
  22213. // General Punctuation
  22214. {
  22215. 'begin': 0x2070,
  22216. 'end': 0x209F
  22217. },
  22218. // Superscripts And Subscripts
  22219. {
  22220. 'begin': 0x20A0,
  22221. 'end': 0x20CF
  22222. },
  22223. // Currency Symbol
  22224. {
  22225. 'begin': 0x20D0,
  22226. 'end': 0x20FF
  22227. },
  22228. // Combining Diacritical Marks
  22229. {
  22230. 'begin': 0x2100,
  22231. 'end': 0x214F
  22232. },
  22233. // Letterlike Symbols
  22234. {
  22235. 'begin': 0x2150,
  22236. 'end': 0x218F
  22237. },
  22238. // Number Forms
  22239. {
  22240. 'begin': 0x2190,
  22241. 'end': 0x21FF
  22242. },
  22243. // Arrows
  22244. {
  22245. 'begin': 0x2200,
  22246. 'end': 0x22FF
  22247. },
  22248. // Mathematical Operators
  22249. {
  22250. 'begin': 0x2300,
  22251. 'end': 0x23FF
  22252. },
  22253. // Miscellaneous Technical
  22254. {
  22255. 'begin': 0x2400,
  22256. 'end': 0x243F
  22257. },
  22258. // Control Pictures
  22259. {
  22260. 'begin': 0x2440,
  22261. 'end': 0x245F
  22262. },
  22263. // Optical Character Recognition
  22264. {
  22265. 'begin': 0x2460,
  22266. 'end': 0x24FF
  22267. },
  22268. // Enclosed Alphanumerics
  22269. {
  22270. 'begin': 0x2500,
  22271. 'end': 0x257F
  22272. },
  22273. // Box Drawing
  22274. {
  22275. 'begin': 0x2580,
  22276. 'end': 0x259F
  22277. },
  22278. // Block Elements
  22279. {
  22280. 'begin': 0x25A0,
  22281. 'end': 0x25FF
  22282. },
  22283. // Geometric Shapes
  22284. {
  22285. 'begin': 0x2600,
  22286. 'end': 0x26FF
  22287. },
  22288. // Miscellaneous Symbols
  22289. {
  22290. 'begin': 0x2700,
  22291. 'end': 0x27BF
  22292. },
  22293. // Dingbats
  22294. {
  22295. 'begin': 0x3000,
  22296. 'end': 0x303F
  22297. },
  22298. // CJK Symbols And Punctuation
  22299. {
  22300. 'begin': 0x3040,
  22301. 'end': 0x309F
  22302. },
  22303. // Hiragana
  22304. {
  22305. 'begin': 0x30A0,
  22306. 'end': 0x30FF
  22307. },
  22308. // Katakana
  22309. {
  22310. 'begin': 0x3100,
  22311. 'end': 0x312F
  22312. },
  22313. // Bopomofo
  22314. {
  22315. 'begin': 0x3130,
  22316. 'end': 0x318F
  22317. },
  22318. // Hangul Compatibility Jamo
  22319. {
  22320. 'begin': 0xA840,
  22321. 'end': 0xA87F
  22322. },
  22323. // Phags-pa
  22324. {
  22325. 'begin': 0x3200,
  22326. 'end': 0x32FF
  22327. },
  22328. // Enclosed CJK Letters And Months
  22329. {
  22330. 'begin': 0x3300,
  22331. 'end': 0x33FF
  22332. },
  22333. // CJK Compatibility
  22334. {
  22335. 'begin': 0xAC00,
  22336. 'end': 0xD7AF
  22337. },
  22338. // Hangul Syllables
  22339. {
  22340. 'begin': 0xD800,
  22341. 'end': 0xDFFF
  22342. },
  22343. // Non-Plane 0 *
  22344. {
  22345. 'begin': 0x10900,
  22346. 'end': 0x1091F
  22347. },
  22348. // Phoenicia
  22349. {
  22350. 'begin': 0x4E00,
  22351. 'end': 0x9FFF
  22352. },
  22353. // CJK Unified Ideographs
  22354. {
  22355. 'begin': 0xE000,
  22356. 'end': 0xF8FF
  22357. },
  22358. // Private Use Area (plane 0)
  22359. {
  22360. 'begin': 0x31C0,
  22361. 'end': 0x31EF
  22362. },
  22363. // CJK Strokes
  22364. {
  22365. 'begin': 0xFB00,
  22366. 'end': 0xFB4F
  22367. },
  22368. // Alphabetic Presentation Forms
  22369. {
  22370. 'begin': 0xFB50,
  22371. 'end': 0xFDFF
  22372. },
  22373. // Arabic Presentation Forms-A
  22374. {
  22375. 'begin': 0xFE20,
  22376. 'end': 0xFE2F
  22377. },
  22378. // Combining Half Marks
  22379. {
  22380. 'begin': 0xFE10,
  22381. 'end': 0xFE1F
  22382. },
  22383. // Vertical Forms
  22384. {
  22385. 'begin': 0xFE50,
  22386. 'end': 0xFE6F
  22387. },
  22388. // Small Form Variants
  22389. {
  22390. 'begin': 0xFE70,
  22391. 'end': 0xFEFF
  22392. },
  22393. // Arabic Presentation Forms-B
  22394. {
  22395. 'begin': 0xFF00,
  22396. 'end': 0xFFEF
  22397. },
  22398. // Halfwidth And Fullwidth Forms
  22399. {
  22400. 'begin': 0xFFF0,
  22401. 'end': 0xFFFF
  22402. },
  22403. // Specials
  22404. {
  22405. 'begin': 0x0F00,
  22406. 'end': 0x0FFF
  22407. },
  22408. // Tibetan
  22409. {
  22410. 'begin': 0x0700,
  22411. 'end': 0x074F
  22412. },
  22413. // Syriac
  22414. {
  22415. 'begin': 0x0780,
  22416. 'end': 0x07BF
  22417. },
  22418. // Thaana
  22419. {
  22420. 'begin': 0x0D80,
  22421. 'end': 0x0DFF
  22422. },
  22423. // Sinhala
  22424. {
  22425. 'begin': 0x1000,
  22426. 'end': 0x109F
  22427. },
  22428. // Myanmar
  22429. {
  22430. 'begin': 0x1200,
  22431. 'end': 0x137F
  22432. },
  22433. // Ethiopic
  22434. {
  22435. 'begin': 0x13A0,
  22436. 'end': 0x13FF
  22437. },
  22438. // Cherokee
  22439. {
  22440. 'begin': 0x1400,
  22441. 'end': 0x167F
  22442. },
  22443. // Unified Canadian Aboriginal Syllabics
  22444. {
  22445. 'begin': 0x1680,
  22446. 'end': 0x169F
  22447. },
  22448. // Ogham
  22449. {
  22450. 'begin': 0x16A0,
  22451. 'end': 0x16FF
  22452. },
  22453. // Runic
  22454. {
  22455. 'begin': 0x1780,
  22456. 'end': 0x17FF
  22457. },
  22458. // Khmer
  22459. {
  22460. 'begin': 0x1800,
  22461. 'end': 0x18AF
  22462. },
  22463. // Mongolian
  22464. {
  22465. 'begin': 0x2800,
  22466. 'end': 0x28FF
  22467. },
  22468. // Braille Patterns
  22469. {
  22470. 'begin': 0xA000,
  22471. 'end': 0xA48F
  22472. },
  22473. // Yi Syllables
  22474. {
  22475. 'begin': 0x1700,
  22476. 'end': 0x171F
  22477. },
  22478. // Tagalog
  22479. {
  22480. 'begin': 0x10300,
  22481. 'end': 0x1032F
  22482. },
  22483. // Old Italic
  22484. {
  22485. 'begin': 0x10330,
  22486. 'end': 0x1034F
  22487. },
  22488. // Gothic
  22489. {
  22490. 'begin': 0x10400,
  22491. 'end': 0x1044F
  22492. },
  22493. // Deseret
  22494. {
  22495. 'begin': 0x1D000,
  22496. 'end': 0x1D0FF
  22497. },
  22498. // Byzantine Musical Symbols
  22499. {
  22500. 'begin': 0x1D400,
  22501. 'end': 0x1D7FF
  22502. },
  22503. // Mathematical Alphanumeric Symbols
  22504. {
  22505. 'begin': 0xFF000,
  22506. 'end': 0xFFFFD
  22507. },
  22508. // Private Use (plane 15)
  22509. {
  22510. 'begin': 0xFE00,
  22511. 'end': 0xFE0F
  22512. },
  22513. // Variation Selectors
  22514. {
  22515. 'begin': 0xE0000,
  22516. 'end': 0xE007F
  22517. },
  22518. // Tags
  22519. {
  22520. 'begin': 0x1900,
  22521. 'end': 0x194F
  22522. },
  22523. // Limbu
  22524. {
  22525. 'begin': 0x1950,
  22526. 'end': 0x197F
  22527. },
  22528. // Tai Le
  22529. {
  22530. 'begin': 0x1980,
  22531. 'end': 0x19DF
  22532. },
  22533. // New Tai Lue
  22534. {
  22535. 'begin': 0x1A00,
  22536. 'end': 0x1A1F
  22537. },
  22538. // Buginese
  22539. {
  22540. 'begin': 0x2C00,
  22541. 'end': 0x2C5F
  22542. },
  22543. // Glagolitic
  22544. {
  22545. 'begin': 0x2D30,
  22546. 'end': 0x2D7F
  22547. },
  22548. // Tifinagh
  22549. {
  22550. 'begin': 0x4DC0,
  22551. 'end': 0x4DFF
  22552. },
  22553. // Yijing Hexagram Symbols
  22554. {
  22555. 'begin': 0xA800,
  22556. 'end': 0xA82F
  22557. },
  22558. // Syloti Nagri
  22559. {
  22560. 'begin': 0x10000,
  22561. 'end': 0x1007F
  22562. },
  22563. // Linear B Syllabary
  22564. {
  22565. 'begin': 0x10140,
  22566. 'end': 0x1018F
  22567. },
  22568. // Ancient Greek Numbers
  22569. {
  22570. 'begin': 0x10380,
  22571. 'end': 0x1039F
  22572. },
  22573. // Ugaritic
  22574. {
  22575. 'begin': 0x103A0,
  22576. 'end': 0x103DF
  22577. },
  22578. // Old Persian
  22579. {
  22580. 'begin': 0x10450,
  22581. 'end': 0x1047F
  22582. },
  22583. // Shavian
  22584. {
  22585. 'begin': 0x10480,
  22586. 'end': 0x104AF
  22587. },
  22588. // Osmanya
  22589. {
  22590. 'begin': 0x10800,
  22591. 'end': 0x1083F
  22592. },
  22593. // Cypriot Syllabary
  22594. {
  22595. 'begin': 0x10A00,
  22596. 'end': 0x10A5F
  22597. },
  22598. // Kharoshthi
  22599. {
  22600. 'begin': 0x1D300,
  22601. 'end': 0x1D35F
  22602. },
  22603. // Tai Xuan Jing Symbols
  22604. {
  22605. 'begin': 0x12000,
  22606. 'end': 0x123FF
  22607. },
  22608. // Cuneiform
  22609. {
  22610. 'begin': 0x1D360,
  22611. 'end': 0x1D37F
  22612. },
  22613. // Counting Rod Numerals
  22614. {
  22615. 'begin': 0x1B80,
  22616. 'end': 0x1BBF
  22617. },
  22618. // Sundanese
  22619. {
  22620. 'begin': 0x1C00,
  22621. 'end': 0x1C4F
  22622. },
  22623. // Lepcha
  22624. {
  22625. 'begin': 0x1C50,
  22626. 'end': 0x1C7F
  22627. },
  22628. // Ol Chiki
  22629. {
  22630. 'begin': 0xA880,
  22631. 'end': 0xA8DF
  22632. },
  22633. // Saurashtra
  22634. {
  22635. 'begin': 0xA900,
  22636. 'end': 0xA92F
  22637. },
  22638. // Kayah Li
  22639. {
  22640. 'begin': 0xA930,
  22641. 'end': 0xA95F
  22642. },
  22643. // Rejang
  22644. {
  22645. 'begin': 0xAA00,
  22646. 'end': 0xAA5F
  22647. },
  22648. // Cham
  22649. {
  22650. 'begin': 0x10190,
  22651. 'end': 0x101CF
  22652. },
  22653. // Ancient Symbols
  22654. {
  22655. 'begin': 0x101D0,
  22656. 'end': 0x101FF
  22657. },
  22658. // Phaistos Disc
  22659. {
  22660. 'begin': 0x102A0,
  22661. 'end': 0x102DF
  22662. },
  22663. // Carian
  22664. {
  22665. 'begin': 0x1F030,
  22666. 'end': 0x1F09F
  22667. }
  22668. ];
  22669. // Domino Tiles
  22670. function getUnicodeRangeFor(value) {
  22671. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  22672. var range = UnicodeRanges[i];
  22673. if (value >= range.begin && value < range.end) {
  22674. return i;
  22675. }
  22676. }
  22677. return -1;
  22678. }
  22679. function isRTLRangeFor(value) {
  22680. var range = UnicodeRanges[13];
  22681. if (value >= range.begin && value < range.end) {
  22682. return true;
  22683. }
  22684. range = UnicodeRanges[11];
  22685. if (value >= range.begin && value < range.end) {
  22686. return true;
  22687. }
  22688. return false;
  22689. }
  22690. // The normalization table is obtained by filtering the Unicode characters
  22691. // database with <compat> entries.
  22692. var getNormalizedUnicodes = getLookupTableFactory(function (t) {
  22693. t['\u00A8'] = '\u0020\u0308';
  22694. t['\u00AF'] = '\u0020\u0304';
  22695. t['\u00B4'] = '\u0020\u0301';
  22696. t['\u00B5'] = '\u03BC';
  22697. t['\u00B8'] = '\u0020\u0327';
  22698. t['\u0132'] = '\u0049\u004A';
  22699. t['\u0133'] = '\u0069\u006A';
  22700. t['\u013F'] = '\u004C\u00B7';
  22701. t['\u0140'] = '\u006C\u00B7';
  22702. t['\u0149'] = '\u02BC\u006E';
  22703. t['\u017F'] = '\u0073';
  22704. t['\u01C4'] = '\u0044\u017D';
  22705. t['\u01C5'] = '\u0044\u017E';
  22706. t['\u01C6'] = '\u0064\u017E';
  22707. t['\u01C7'] = '\u004C\u004A';
  22708. t['\u01C8'] = '\u004C\u006A';
  22709. t['\u01C9'] = '\u006C\u006A';
  22710. t['\u01CA'] = '\u004E\u004A';
  22711. t['\u01CB'] = '\u004E\u006A';
  22712. t['\u01CC'] = '\u006E\u006A';
  22713. t['\u01F1'] = '\u0044\u005A';
  22714. t['\u01F2'] = '\u0044\u007A';
  22715. t['\u01F3'] = '\u0064\u007A';
  22716. t['\u02D8'] = '\u0020\u0306';
  22717. t['\u02D9'] = '\u0020\u0307';
  22718. t['\u02DA'] = '\u0020\u030A';
  22719. t['\u02DB'] = '\u0020\u0328';
  22720. t['\u02DC'] = '\u0020\u0303';
  22721. t['\u02DD'] = '\u0020\u030B';
  22722. t['\u037A'] = '\u0020\u0345';
  22723. t['\u0384'] = '\u0020\u0301';
  22724. t['\u03D0'] = '\u03B2';
  22725. t['\u03D1'] = '\u03B8';
  22726. t['\u03D2'] = '\u03A5';
  22727. t['\u03D5'] = '\u03C6';
  22728. t['\u03D6'] = '\u03C0';
  22729. t['\u03F0'] = '\u03BA';
  22730. t['\u03F1'] = '\u03C1';
  22731. t['\u03F2'] = '\u03C2';
  22732. t['\u03F4'] = '\u0398';
  22733. t['\u03F5'] = '\u03B5';
  22734. t['\u03F9'] = '\u03A3';
  22735. t['\u0587'] = '\u0565\u0582';
  22736. t['\u0675'] = '\u0627\u0674';
  22737. t['\u0676'] = '\u0648\u0674';
  22738. t['\u0677'] = '\u06C7\u0674';
  22739. t['\u0678'] = '\u064A\u0674';
  22740. t['\u0E33'] = '\u0E4D\u0E32';
  22741. t['\u0EB3'] = '\u0ECD\u0EB2';
  22742. t['\u0EDC'] = '\u0EAB\u0E99';
  22743. t['\u0EDD'] = '\u0EAB\u0EA1';
  22744. t['\u0F77'] = '\u0FB2\u0F81';
  22745. t['\u0F79'] = '\u0FB3\u0F81';
  22746. t['\u1E9A'] = '\u0061\u02BE';
  22747. t['\u1FBD'] = '\u0020\u0313';
  22748. t['\u1FBF'] = '\u0020\u0313';
  22749. t['\u1FC0'] = '\u0020\u0342';
  22750. t['\u1FFE'] = '\u0020\u0314';
  22751. t['\u2002'] = '\u0020';
  22752. t['\u2003'] = '\u0020';
  22753. t['\u2004'] = '\u0020';
  22754. t['\u2005'] = '\u0020';
  22755. t['\u2006'] = '\u0020';
  22756. t['\u2008'] = '\u0020';
  22757. t['\u2009'] = '\u0020';
  22758. t['\u200A'] = '\u0020';
  22759. t['\u2017'] = '\u0020\u0333';
  22760. t['\u2024'] = '\u002E';
  22761. t['\u2025'] = '\u002E\u002E';
  22762. t['\u2026'] = '\u002E\u002E\u002E';
  22763. t['\u2033'] = '\u2032\u2032';
  22764. t['\u2034'] = '\u2032\u2032\u2032';
  22765. t['\u2036'] = '\u2035\u2035';
  22766. t['\u2037'] = '\u2035\u2035\u2035';
  22767. t['\u203C'] = '\u0021\u0021';
  22768. t['\u203E'] = '\u0020\u0305';
  22769. t['\u2047'] = '\u003F\u003F';
  22770. t['\u2048'] = '\u003F\u0021';
  22771. t['\u2049'] = '\u0021\u003F';
  22772. t['\u2057'] = '\u2032\u2032\u2032\u2032';
  22773. t['\u205F'] = '\u0020';
  22774. t['\u20A8'] = '\u0052\u0073';
  22775. t['\u2100'] = '\u0061\u002F\u0063';
  22776. t['\u2101'] = '\u0061\u002F\u0073';
  22777. t['\u2103'] = '\u00B0\u0043';
  22778. t['\u2105'] = '\u0063\u002F\u006F';
  22779. t['\u2106'] = '\u0063\u002F\u0075';
  22780. t['\u2107'] = '\u0190';
  22781. t['\u2109'] = '\u00B0\u0046';
  22782. t['\u2116'] = '\u004E\u006F';
  22783. t['\u2121'] = '\u0054\u0045\u004C';
  22784. t['\u2135'] = '\u05D0';
  22785. t['\u2136'] = '\u05D1';
  22786. t['\u2137'] = '\u05D2';
  22787. t['\u2138'] = '\u05D3';
  22788. t['\u213B'] = '\u0046\u0041\u0058';
  22789. t['\u2160'] = '\u0049';
  22790. t['\u2161'] = '\u0049\u0049';
  22791. t['\u2162'] = '\u0049\u0049\u0049';
  22792. t['\u2163'] = '\u0049\u0056';
  22793. t['\u2164'] = '\u0056';
  22794. t['\u2165'] = '\u0056\u0049';
  22795. t['\u2166'] = '\u0056\u0049\u0049';
  22796. t['\u2167'] = '\u0056\u0049\u0049\u0049';
  22797. t['\u2168'] = '\u0049\u0058';
  22798. t['\u2169'] = '\u0058';
  22799. t['\u216A'] = '\u0058\u0049';
  22800. t['\u216B'] = '\u0058\u0049\u0049';
  22801. t['\u216C'] = '\u004C';
  22802. t['\u216D'] = '\u0043';
  22803. t['\u216E'] = '\u0044';
  22804. t['\u216F'] = '\u004D';
  22805. t['\u2170'] = '\u0069';
  22806. t['\u2171'] = '\u0069\u0069';
  22807. t['\u2172'] = '\u0069\u0069\u0069';
  22808. t['\u2173'] = '\u0069\u0076';
  22809. t['\u2174'] = '\u0076';
  22810. t['\u2175'] = '\u0076\u0069';
  22811. t['\u2176'] = '\u0076\u0069\u0069';
  22812. t['\u2177'] = '\u0076\u0069\u0069\u0069';
  22813. t['\u2178'] = '\u0069\u0078';
  22814. t['\u2179'] = '\u0078';
  22815. t['\u217A'] = '\u0078\u0069';
  22816. t['\u217B'] = '\u0078\u0069\u0069';
  22817. t['\u217C'] = '\u006C';
  22818. t['\u217D'] = '\u0063';
  22819. t['\u217E'] = '\u0064';
  22820. t['\u217F'] = '\u006D';
  22821. t['\u222C'] = '\u222B\u222B';
  22822. t['\u222D'] = '\u222B\u222B\u222B';
  22823. t['\u222F'] = '\u222E\u222E';
  22824. t['\u2230'] = '\u222E\u222E\u222E';
  22825. t['\u2474'] = '\u0028\u0031\u0029';
  22826. t['\u2475'] = '\u0028\u0032\u0029';
  22827. t['\u2476'] = '\u0028\u0033\u0029';
  22828. t['\u2477'] = '\u0028\u0034\u0029';
  22829. t['\u2478'] = '\u0028\u0035\u0029';
  22830. t['\u2479'] = '\u0028\u0036\u0029';
  22831. t['\u247A'] = '\u0028\u0037\u0029';
  22832. t['\u247B'] = '\u0028\u0038\u0029';
  22833. t['\u247C'] = '\u0028\u0039\u0029';
  22834. t['\u247D'] = '\u0028\u0031\u0030\u0029';
  22835. t['\u247E'] = '\u0028\u0031\u0031\u0029';
  22836. t['\u247F'] = '\u0028\u0031\u0032\u0029';
  22837. t['\u2480'] = '\u0028\u0031\u0033\u0029';
  22838. t['\u2481'] = '\u0028\u0031\u0034\u0029';
  22839. t['\u2482'] = '\u0028\u0031\u0035\u0029';
  22840. t['\u2483'] = '\u0028\u0031\u0036\u0029';
  22841. t['\u2484'] = '\u0028\u0031\u0037\u0029';
  22842. t['\u2485'] = '\u0028\u0031\u0038\u0029';
  22843. t['\u2486'] = '\u0028\u0031\u0039\u0029';
  22844. t['\u2487'] = '\u0028\u0032\u0030\u0029';
  22845. t['\u2488'] = '\u0031\u002E';
  22846. t['\u2489'] = '\u0032\u002E';
  22847. t['\u248A'] = '\u0033\u002E';
  22848. t['\u248B'] = '\u0034\u002E';
  22849. t['\u248C'] = '\u0035\u002E';
  22850. t['\u248D'] = '\u0036\u002E';
  22851. t['\u248E'] = '\u0037\u002E';
  22852. t['\u248F'] = '\u0038\u002E';
  22853. t['\u2490'] = '\u0039\u002E';
  22854. t['\u2491'] = '\u0031\u0030\u002E';
  22855. t['\u2492'] = '\u0031\u0031\u002E';
  22856. t['\u2493'] = '\u0031\u0032\u002E';
  22857. t['\u2494'] = '\u0031\u0033\u002E';
  22858. t['\u2495'] = '\u0031\u0034\u002E';
  22859. t['\u2496'] = '\u0031\u0035\u002E';
  22860. t['\u2497'] = '\u0031\u0036\u002E';
  22861. t['\u2498'] = '\u0031\u0037\u002E';
  22862. t['\u2499'] = '\u0031\u0038\u002E';
  22863. t['\u249A'] = '\u0031\u0039\u002E';
  22864. t['\u249B'] = '\u0032\u0030\u002E';
  22865. t['\u249C'] = '\u0028\u0061\u0029';
  22866. t['\u249D'] = '\u0028\u0062\u0029';
  22867. t['\u249E'] = '\u0028\u0063\u0029';
  22868. t['\u249F'] = '\u0028\u0064\u0029';
  22869. t['\u24A0'] = '\u0028\u0065\u0029';
  22870. t['\u24A1'] = '\u0028\u0066\u0029';
  22871. t['\u24A2'] = '\u0028\u0067\u0029';
  22872. t['\u24A3'] = '\u0028\u0068\u0029';
  22873. t['\u24A4'] = '\u0028\u0069\u0029';
  22874. t['\u24A5'] = '\u0028\u006A\u0029';
  22875. t['\u24A6'] = '\u0028\u006B\u0029';
  22876. t['\u24A7'] = '\u0028\u006C\u0029';
  22877. t['\u24A8'] = '\u0028\u006D\u0029';
  22878. t['\u24A9'] = '\u0028\u006E\u0029';
  22879. t['\u24AA'] = '\u0028\u006F\u0029';
  22880. t['\u24AB'] = '\u0028\u0070\u0029';
  22881. t['\u24AC'] = '\u0028\u0071\u0029';
  22882. t['\u24AD'] = '\u0028\u0072\u0029';
  22883. t['\u24AE'] = '\u0028\u0073\u0029';
  22884. t['\u24AF'] = '\u0028\u0074\u0029';
  22885. t['\u24B0'] = '\u0028\u0075\u0029';
  22886. t['\u24B1'] = '\u0028\u0076\u0029';
  22887. t['\u24B2'] = '\u0028\u0077\u0029';
  22888. t['\u24B3'] = '\u0028\u0078\u0029';
  22889. t['\u24B4'] = '\u0028\u0079\u0029';
  22890. t['\u24B5'] = '\u0028\u007A\u0029';
  22891. t['\u2A0C'] = '\u222B\u222B\u222B\u222B';
  22892. t['\u2A74'] = '\u003A\u003A\u003D';
  22893. t['\u2A75'] = '\u003D\u003D';
  22894. t['\u2A76'] = '\u003D\u003D\u003D';
  22895. t['\u2E9F'] = '\u6BCD';
  22896. t['\u2EF3'] = '\u9F9F';
  22897. t['\u2F00'] = '\u4E00';
  22898. t['\u2F01'] = '\u4E28';
  22899. t['\u2F02'] = '\u4E36';
  22900. t['\u2F03'] = '\u4E3F';
  22901. t['\u2F04'] = '\u4E59';
  22902. t['\u2F05'] = '\u4E85';
  22903. t['\u2F06'] = '\u4E8C';
  22904. t['\u2F07'] = '\u4EA0';
  22905. t['\u2F08'] = '\u4EBA';
  22906. t['\u2F09'] = '\u513F';
  22907. t['\u2F0A'] = '\u5165';
  22908. t['\u2F0B'] = '\u516B';
  22909. t['\u2F0C'] = '\u5182';
  22910. t['\u2F0D'] = '\u5196';
  22911. t['\u2F0E'] = '\u51AB';
  22912. t['\u2F0F'] = '\u51E0';
  22913. t['\u2F10'] = '\u51F5';
  22914. t['\u2F11'] = '\u5200';
  22915. t['\u2F12'] = '\u529B';
  22916. t['\u2F13'] = '\u52F9';
  22917. t['\u2F14'] = '\u5315';
  22918. t['\u2F15'] = '\u531A';
  22919. t['\u2F16'] = '\u5338';
  22920. t['\u2F17'] = '\u5341';
  22921. t['\u2F18'] = '\u535C';
  22922. t['\u2F19'] = '\u5369';
  22923. t['\u2F1A'] = '\u5382';
  22924. t['\u2F1B'] = '\u53B6';
  22925. t['\u2F1C'] = '\u53C8';
  22926. t['\u2F1D'] = '\u53E3';
  22927. t['\u2F1E'] = '\u56D7';
  22928. t['\u2F1F'] = '\u571F';
  22929. t['\u2F20'] = '\u58EB';
  22930. t['\u2F21'] = '\u5902';
  22931. t['\u2F22'] = '\u590A';
  22932. t['\u2F23'] = '\u5915';
  22933. t['\u2F24'] = '\u5927';
  22934. t['\u2F25'] = '\u5973';
  22935. t['\u2F26'] = '\u5B50';
  22936. t['\u2F27'] = '\u5B80';
  22937. t['\u2F28'] = '\u5BF8';
  22938. t['\u2F29'] = '\u5C0F';
  22939. t['\u2F2A'] = '\u5C22';
  22940. t['\u2F2B'] = '\u5C38';
  22941. t['\u2F2C'] = '\u5C6E';
  22942. t['\u2F2D'] = '\u5C71';
  22943. t['\u2F2E'] = '\u5DDB';
  22944. t['\u2F2F'] = '\u5DE5';
  22945. t['\u2F30'] = '\u5DF1';
  22946. t['\u2F31'] = '\u5DFE';
  22947. t['\u2F32'] = '\u5E72';
  22948. t['\u2F33'] = '\u5E7A';
  22949. t['\u2F34'] = '\u5E7F';
  22950. t['\u2F35'] = '\u5EF4';
  22951. t['\u2F36'] = '\u5EFE';
  22952. t['\u2F37'] = '\u5F0B';
  22953. t['\u2F38'] = '\u5F13';
  22954. t['\u2F39'] = '\u5F50';
  22955. t['\u2F3A'] = '\u5F61';
  22956. t['\u2F3B'] = '\u5F73';
  22957. t['\u2F3C'] = '\u5FC3';
  22958. t['\u2F3D'] = '\u6208';
  22959. t['\u2F3E'] = '\u6236';
  22960. t['\u2F3F'] = '\u624B';
  22961. t['\u2F40'] = '\u652F';
  22962. t['\u2F41'] = '\u6534';
  22963. t['\u2F42'] = '\u6587';
  22964. t['\u2F43'] = '\u6597';
  22965. t['\u2F44'] = '\u65A4';
  22966. t['\u2F45'] = '\u65B9';
  22967. t['\u2F46'] = '\u65E0';
  22968. t['\u2F47'] = '\u65E5';
  22969. t['\u2F48'] = '\u66F0';
  22970. t['\u2F49'] = '\u6708';
  22971. t['\u2F4A'] = '\u6728';
  22972. t['\u2F4B'] = '\u6B20';
  22973. t['\u2F4C'] = '\u6B62';
  22974. t['\u2F4D'] = '\u6B79';
  22975. t['\u2F4E'] = '\u6BB3';
  22976. t['\u2F4F'] = '\u6BCB';
  22977. t['\u2F50'] = '\u6BD4';
  22978. t['\u2F51'] = '\u6BDB';
  22979. t['\u2F52'] = '\u6C0F';
  22980. t['\u2F53'] = '\u6C14';
  22981. t['\u2F54'] = '\u6C34';
  22982. t['\u2F55'] = '\u706B';
  22983. t['\u2F56'] = '\u722A';
  22984. t['\u2F57'] = '\u7236';
  22985. t['\u2F58'] = '\u723B';
  22986. t['\u2F59'] = '\u723F';
  22987. t['\u2F5A'] = '\u7247';
  22988. t['\u2F5B'] = '\u7259';
  22989. t['\u2F5C'] = '\u725B';
  22990. t['\u2F5D'] = '\u72AC';
  22991. t['\u2F5E'] = '\u7384';
  22992. t['\u2F5F'] = '\u7389';
  22993. t['\u2F60'] = '\u74DC';
  22994. t['\u2F61'] = '\u74E6';
  22995. t['\u2F62'] = '\u7518';
  22996. t['\u2F63'] = '\u751F';
  22997. t['\u2F64'] = '\u7528';
  22998. t['\u2F65'] = '\u7530';
  22999. t['\u2F66'] = '\u758B';
  23000. t['\u2F67'] = '\u7592';
  23001. t['\u2F68'] = '\u7676';
  23002. t['\u2F69'] = '\u767D';
  23003. t['\u2F6A'] = '\u76AE';
  23004. t['\u2F6B'] = '\u76BF';
  23005. t['\u2F6C'] = '\u76EE';
  23006. t['\u2F6D'] = '\u77DB';
  23007. t['\u2F6E'] = '\u77E2';
  23008. t['\u2F6F'] = '\u77F3';
  23009. t['\u2F70'] = '\u793A';
  23010. t['\u2F71'] = '\u79B8';
  23011. t['\u2F72'] = '\u79BE';
  23012. t['\u2F73'] = '\u7A74';
  23013. t['\u2F74'] = '\u7ACB';
  23014. t['\u2F75'] = '\u7AF9';
  23015. t['\u2F76'] = '\u7C73';
  23016. t['\u2F77'] = '\u7CF8';
  23017. t['\u2F78'] = '\u7F36';
  23018. t['\u2F79'] = '\u7F51';
  23019. t['\u2F7A'] = '\u7F8A';
  23020. t['\u2F7B'] = '\u7FBD';
  23021. t['\u2F7C'] = '\u8001';
  23022. t['\u2F7D'] = '\u800C';
  23023. t['\u2F7E'] = '\u8012';
  23024. t['\u2F7F'] = '\u8033';
  23025. t['\u2F80'] = '\u807F';
  23026. t['\u2F81'] = '\u8089';
  23027. t['\u2F82'] = '\u81E3';
  23028. t['\u2F83'] = '\u81EA';
  23029. t['\u2F84'] = '\u81F3';
  23030. t['\u2F85'] = '\u81FC';
  23031. t['\u2F86'] = '\u820C';
  23032. t['\u2F87'] = '\u821B';
  23033. t['\u2F88'] = '\u821F';
  23034. t['\u2F89'] = '\u826E';
  23035. t['\u2F8A'] = '\u8272';
  23036. t['\u2F8B'] = '\u8278';
  23037. t['\u2F8C'] = '\u864D';
  23038. t['\u2F8D'] = '\u866B';
  23039. t['\u2F8E'] = '\u8840';
  23040. t['\u2F8F'] = '\u884C';
  23041. t['\u2F90'] = '\u8863';
  23042. t['\u2F91'] = '\u897E';
  23043. t['\u2F92'] = '\u898B';
  23044. t['\u2F93'] = '\u89D2';
  23045. t['\u2F94'] = '\u8A00';
  23046. t['\u2F95'] = '\u8C37';
  23047. t['\u2F96'] = '\u8C46';
  23048. t['\u2F97'] = '\u8C55';
  23049. t['\u2F98'] = '\u8C78';
  23050. t['\u2F99'] = '\u8C9D';
  23051. t['\u2F9A'] = '\u8D64';
  23052. t['\u2F9B'] = '\u8D70';
  23053. t['\u2F9C'] = '\u8DB3';
  23054. t['\u2F9D'] = '\u8EAB';
  23055. t['\u2F9E'] = '\u8ECA';
  23056. t['\u2F9F'] = '\u8F9B';
  23057. t['\u2FA0'] = '\u8FB0';
  23058. t['\u2FA1'] = '\u8FB5';
  23059. t['\u2FA2'] = '\u9091';
  23060. t['\u2FA3'] = '\u9149';
  23061. t['\u2FA4'] = '\u91C6';
  23062. t['\u2FA5'] = '\u91CC';
  23063. t['\u2FA6'] = '\u91D1';
  23064. t['\u2FA7'] = '\u9577';
  23065. t['\u2FA8'] = '\u9580';
  23066. t['\u2FA9'] = '\u961C';
  23067. t['\u2FAA'] = '\u96B6';
  23068. t['\u2FAB'] = '\u96B9';
  23069. t['\u2FAC'] = '\u96E8';
  23070. t['\u2FAD'] = '\u9751';
  23071. t['\u2FAE'] = '\u975E';
  23072. t['\u2FAF'] = '\u9762';
  23073. t['\u2FB0'] = '\u9769';
  23074. t['\u2FB1'] = '\u97CB';
  23075. t['\u2FB2'] = '\u97ED';
  23076. t['\u2FB3'] = '\u97F3';
  23077. t['\u2FB4'] = '\u9801';
  23078. t['\u2FB5'] = '\u98A8';
  23079. t['\u2FB6'] = '\u98DB';
  23080. t['\u2FB7'] = '\u98DF';
  23081. t['\u2FB8'] = '\u9996';
  23082. t['\u2FB9'] = '\u9999';
  23083. t['\u2FBA'] = '\u99AC';
  23084. t['\u2FBB'] = '\u9AA8';
  23085. t['\u2FBC'] = '\u9AD8';
  23086. t['\u2FBD'] = '\u9ADF';
  23087. t['\u2FBE'] = '\u9B25';
  23088. t['\u2FBF'] = '\u9B2F';
  23089. t['\u2FC0'] = '\u9B32';
  23090. t['\u2FC1'] = '\u9B3C';
  23091. t['\u2FC2'] = '\u9B5A';
  23092. t['\u2FC3'] = '\u9CE5';
  23093. t['\u2FC4'] = '\u9E75';
  23094. t['\u2FC5'] = '\u9E7F';
  23095. t['\u2FC6'] = '\u9EA5';
  23096. t['\u2FC7'] = '\u9EBB';
  23097. t['\u2FC8'] = '\u9EC3';
  23098. t['\u2FC9'] = '\u9ECD';
  23099. t['\u2FCA'] = '\u9ED1';
  23100. t['\u2FCB'] = '\u9EF9';
  23101. t['\u2FCC'] = '\u9EFD';
  23102. t['\u2FCD'] = '\u9F0E';
  23103. t['\u2FCE'] = '\u9F13';
  23104. t['\u2FCF'] = '\u9F20';
  23105. t['\u2FD0'] = '\u9F3B';
  23106. t['\u2FD1'] = '\u9F4A';
  23107. t['\u2FD2'] = '\u9F52';
  23108. t['\u2FD3'] = '\u9F8D';
  23109. t['\u2FD4'] = '\u9F9C';
  23110. t['\u2FD5'] = '\u9FA0';
  23111. t['\u3036'] = '\u3012';
  23112. t['\u3038'] = '\u5341';
  23113. t['\u3039'] = '\u5344';
  23114. t['\u303A'] = '\u5345';
  23115. t['\u309B'] = '\u0020\u3099';
  23116. t['\u309C'] = '\u0020\u309A';
  23117. t['\u3131'] = '\u1100';
  23118. t['\u3132'] = '\u1101';
  23119. t['\u3133'] = '\u11AA';
  23120. t['\u3134'] = '\u1102';
  23121. t['\u3135'] = '\u11AC';
  23122. t['\u3136'] = '\u11AD';
  23123. t['\u3137'] = '\u1103';
  23124. t['\u3138'] = '\u1104';
  23125. t['\u3139'] = '\u1105';
  23126. t['\u313A'] = '\u11B0';
  23127. t['\u313B'] = '\u11B1';
  23128. t['\u313C'] = '\u11B2';
  23129. t['\u313D'] = '\u11B3';
  23130. t['\u313E'] = '\u11B4';
  23131. t['\u313F'] = '\u11B5';
  23132. t['\u3140'] = '\u111A';
  23133. t['\u3141'] = '\u1106';
  23134. t['\u3142'] = '\u1107';
  23135. t['\u3143'] = '\u1108';
  23136. t['\u3144'] = '\u1121';
  23137. t['\u3145'] = '\u1109';
  23138. t['\u3146'] = '\u110A';
  23139. t['\u3147'] = '\u110B';
  23140. t['\u3148'] = '\u110C';
  23141. t['\u3149'] = '\u110D';
  23142. t['\u314A'] = '\u110E';
  23143. t['\u314B'] = '\u110F';
  23144. t['\u314C'] = '\u1110';
  23145. t['\u314D'] = '\u1111';
  23146. t['\u314E'] = '\u1112';
  23147. t['\u314F'] = '\u1161';
  23148. t['\u3150'] = '\u1162';
  23149. t['\u3151'] = '\u1163';
  23150. t['\u3152'] = '\u1164';
  23151. t['\u3153'] = '\u1165';
  23152. t['\u3154'] = '\u1166';
  23153. t['\u3155'] = '\u1167';
  23154. t['\u3156'] = '\u1168';
  23155. t['\u3157'] = '\u1169';
  23156. t['\u3158'] = '\u116A';
  23157. t['\u3159'] = '\u116B';
  23158. t['\u315A'] = '\u116C';
  23159. t['\u315B'] = '\u116D';
  23160. t['\u315C'] = '\u116E';
  23161. t['\u315D'] = '\u116F';
  23162. t['\u315E'] = '\u1170';
  23163. t['\u315F'] = '\u1171';
  23164. t['\u3160'] = '\u1172';
  23165. t['\u3161'] = '\u1173';
  23166. t['\u3162'] = '\u1174';
  23167. t['\u3163'] = '\u1175';
  23168. t['\u3164'] = '\u1160';
  23169. t['\u3165'] = '\u1114';
  23170. t['\u3166'] = '\u1115';
  23171. t['\u3167'] = '\u11C7';
  23172. t['\u3168'] = '\u11C8';
  23173. t['\u3169'] = '\u11CC';
  23174. t['\u316A'] = '\u11CE';
  23175. t['\u316B'] = '\u11D3';
  23176. t['\u316C'] = '\u11D7';
  23177. t['\u316D'] = '\u11D9';
  23178. t['\u316E'] = '\u111C';
  23179. t['\u316F'] = '\u11DD';
  23180. t['\u3170'] = '\u11DF';
  23181. t['\u3171'] = '\u111D';
  23182. t['\u3172'] = '\u111E';
  23183. t['\u3173'] = '\u1120';
  23184. t['\u3174'] = '\u1122';
  23185. t['\u3175'] = '\u1123';
  23186. t['\u3176'] = '\u1127';
  23187. t['\u3177'] = '\u1129';
  23188. t['\u3178'] = '\u112B';
  23189. t['\u3179'] = '\u112C';
  23190. t['\u317A'] = '\u112D';
  23191. t['\u317B'] = '\u112E';
  23192. t['\u317C'] = '\u112F';
  23193. t['\u317D'] = '\u1132';
  23194. t['\u317E'] = '\u1136';
  23195. t['\u317F'] = '\u1140';
  23196. t['\u3180'] = '\u1147';
  23197. t['\u3181'] = '\u114C';
  23198. t['\u3182'] = '\u11F1';
  23199. t['\u3183'] = '\u11F2';
  23200. t['\u3184'] = '\u1157';
  23201. t['\u3185'] = '\u1158';
  23202. t['\u3186'] = '\u1159';
  23203. t['\u3187'] = '\u1184';
  23204. t['\u3188'] = '\u1185';
  23205. t['\u3189'] = '\u1188';
  23206. t['\u318A'] = '\u1191';
  23207. t['\u318B'] = '\u1192';
  23208. t['\u318C'] = '\u1194';
  23209. t['\u318D'] = '\u119E';
  23210. t['\u318E'] = '\u11A1';
  23211. t['\u3200'] = '\u0028\u1100\u0029';
  23212. t['\u3201'] = '\u0028\u1102\u0029';
  23213. t['\u3202'] = '\u0028\u1103\u0029';
  23214. t['\u3203'] = '\u0028\u1105\u0029';
  23215. t['\u3204'] = '\u0028\u1106\u0029';
  23216. t['\u3205'] = '\u0028\u1107\u0029';
  23217. t['\u3206'] = '\u0028\u1109\u0029';
  23218. t['\u3207'] = '\u0028\u110B\u0029';
  23219. t['\u3208'] = '\u0028\u110C\u0029';
  23220. t['\u3209'] = '\u0028\u110E\u0029';
  23221. t['\u320A'] = '\u0028\u110F\u0029';
  23222. t['\u320B'] = '\u0028\u1110\u0029';
  23223. t['\u320C'] = '\u0028\u1111\u0029';
  23224. t['\u320D'] = '\u0028\u1112\u0029';
  23225. t['\u320E'] = '\u0028\u1100\u1161\u0029';
  23226. t['\u320F'] = '\u0028\u1102\u1161\u0029';
  23227. t['\u3210'] = '\u0028\u1103\u1161\u0029';
  23228. t['\u3211'] = '\u0028\u1105\u1161\u0029';
  23229. t['\u3212'] = '\u0028\u1106\u1161\u0029';
  23230. t['\u3213'] = '\u0028\u1107\u1161\u0029';
  23231. t['\u3214'] = '\u0028\u1109\u1161\u0029';
  23232. t['\u3215'] = '\u0028\u110B\u1161\u0029';
  23233. t['\u3216'] = '\u0028\u110C\u1161\u0029';
  23234. t['\u3217'] = '\u0028\u110E\u1161\u0029';
  23235. t['\u3218'] = '\u0028\u110F\u1161\u0029';
  23236. t['\u3219'] = '\u0028\u1110\u1161\u0029';
  23237. t['\u321A'] = '\u0028\u1111\u1161\u0029';
  23238. t['\u321B'] = '\u0028\u1112\u1161\u0029';
  23239. t['\u321C'] = '\u0028\u110C\u116E\u0029';
  23240. t['\u321D'] = '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029';
  23241. t['\u321E'] = '\u0028\u110B\u1169\u1112\u116E\u0029';
  23242. t['\u3220'] = '\u0028\u4E00\u0029';
  23243. t['\u3221'] = '\u0028\u4E8C\u0029';
  23244. t['\u3222'] = '\u0028\u4E09\u0029';
  23245. t['\u3223'] = '\u0028\u56DB\u0029';
  23246. t['\u3224'] = '\u0028\u4E94\u0029';
  23247. t['\u3225'] = '\u0028\u516D\u0029';
  23248. t['\u3226'] = '\u0028\u4E03\u0029';
  23249. t['\u3227'] = '\u0028\u516B\u0029';
  23250. t['\u3228'] = '\u0028\u4E5D\u0029';
  23251. t['\u3229'] = '\u0028\u5341\u0029';
  23252. t['\u322A'] = '\u0028\u6708\u0029';
  23253. t['\u322B'] = '\u0028\u706B\u0029';
  23254. t['\u322C'] = '\u0028\u6C34\u0029';
  23255. t['\u322D'] = '\u0028\u6728\u0029';
  23256. t['\u322E'] = '\u0028\u91D1\u0029';
  23257. t['\u322F'] = '\u0028\u571F\u0029';
  23258. t['\u3230'] = '\u0028\u65E5\u0029';
  23259. t['\u3231'] = '\u0028\u682A\u0029';
  23260. t['\u3232'] = '\u0028\u6709\u0029';
  23261. t['\u3233'] = '\u0028\u793E\u0029';
  23262. t['\u3234'] = '\u0028\u540D\u0029';
  23263. t['\u3235'] = '\u0028\u7279\u0029';
  23264. t['\u3236'] = '\u0028\u8CA1\u0029';
  23265. t['\u3237'] = '\u0028\u795D\u0029';
  23266. t['\u3238'] = '\u0028\u52B4\u0029';
  23267. t['\u3239'] = '\u0028\u4EE3\u0029';
  23268. t['\u323A'] = '\u0028\u547C\u0029';
  23269. t['\u323B'] = '\u0028\u5B66\u0029';
  23270. t['\u323C'] = '\u0028\u76E3\u0029';
  23271. t['\u323D'] = '\u0028\u4F01\u0029';
  23272. t['\u323E'] = '\u0028\u8CC7\u0029';
  23273. t['\u323F'] = '\u0028\u5354\u0029';
  23274. t['\u3240'] = '\u0028\u796D\u0029';
  23275. t['\u3241'] = '\u0028\u4F11\u0029';
  23276. t['\u3242'] = '\u0028\u81EA\u0029';
  23277. t['\u3243'] = '\u0028\u81F3\u0029';
  23278. t['\u32C0'] = '\u0031\u6708';
  23279. t['\u32C1'] = '\u0032\u6708';
  23280. t['\u32C2'] = '\u0033\u6708';
  23281. t['\u32C3'] = '\u0034\u6708';
  23282. t['\u32C4'] = '\u0035\u6708';
  23283. t['\u32C5'] = '\u0036\u6708';
  23284. t['\u32C6'] = '\u0037\u6708';
  23285. t['\u32C7'] = '\u0038\u6708';
  23286. t['\u32C8'] = '\u0039\u6708';
  23287. t['\u32C9'] = '\u0031\u0030\u6708';
  23288. t['\u32CA'] = '\u0031\u0031\u6708';
  23289. t['\u32CB'] = '\u0031\u0032\u6708';
  23290. t['\u3358'] = '\u0030\u70B9';
  23291. t['\u3359'] = '\u0031\u70B9';
  23292. t['\u335A'] = '\u0032\u70B9';
  23293. t['\u335B'] = '\u0033\u70B9';
  23294. t['\u335C'] = '\u0034\u70B9';
  23295. t['\u335D'] = '\u0035\u70B9';
  23296. t['\u335E'] = '\u0036\u70B9';
  23297. t['\u335F'] = '\u0037\u70B9';
  23298. t['\u3360'] = '\u0038\u70B9';
  23299. t['\u3361'] = '\u0039\u70B9';
  23300. t['\u3362'] = '\u0031\u0030\u70B9';
  23301. t['\u3363'] = '\u0031\u0031\u70B9';
  23302. t['\u3364'] = '\u0031\u0032\u70B9';
  23303. t['\u3365'] = '\u0031\u0033\u70B9';
  23304. t['\u3366'] = '\u0031\u0034\u70B9';
  23305. t['\u3367'] = '\u0031\u0035\u70B9';
  23306. t['\u3368'] = '\u0031\u0036\u70B9';
  23307. t['\u3369'] = '\u0031\u0037\u70B9';
  23308. t['\u336A'] = '\u0031\u0038\u70B9';
  23309. t['\u336B'] = '\u0031\u0039\u70B9';
  23310. t['\u336C'] = '\u0032\u0030\u70B9';
  23311. t['\u336D'] = '\u0032\u0031\u70B9';
  23312. t['\u336E'] = '\u0032\u0032\u70B9';
  23313. t['\u336F'] = '\u0032\u0033\u70B9';
  23314. t['\u3370'] = '\u0032\u0034\u70B9';
  23315. t['\u33E0'] = '\u0031\u65E5';
  23316. t['\u33E1'] = '\u0032\u65E5';
  23317. t['\u33E2'] = '\u0033\u65E5';
  23318. t['\u33E3'] = '\u0034\u65E5';
  23319. t['\u33E4'] = '\u0035\u65E5';
  23320. t['\u33E5'] = '\u0036\u65E5';
  23321. t['\u33E6'] = '\u0037\u65E5';
  23322. t['\u33E7'] = '\u0038\u65E5';
  23323. t['\u33E8'] = '\u0039\u65E5';
  23324. t['\u33E9'] = '\u0031\u0030\u65E5';
  23325. t['\u33EA'] = '\u0031\u0031\u65E5';
  23326. t['\u33EB'] = '\u0031\u0032\u65E5';
  23327. t['\u33EC'] = '\u0031\u0033\u65E5';
  23328. t['\u33ED'] = '\u0031\u0034\u65E5';
  23329. t['\u33EE'] = '\u0031\u0035\u65E5';
  23330. t['\u33EF'] = '\u0031\u0036\u65E5';
  23331. t['\u33F0'] = '\u0031\u0037\u65E5';
  23332. t['\u33F1'] = '\u0031\u0038\u65E5';
  23333. t['\u33F2'] = '\u0031\u0039\u65E5';
  23334. t['\u33F3'] = '\u0032\u0030\u65E5';
  23335. t['\u33F4'] = '\u0032\u0031\u65E5';
  23336. t['\u33F5'] = '\u0032\u0032\u65E5';
  23337. t['\u33F6'] = '\u0032\u0033\u65E5';
  23338. t['\u33F7'] = '\u0032\u0034\u65E5';
  23339. t['\u33F8'] = '\u0032\u0035\u65E5';
  23340. t['\u33F9'] = '\u0032\u0036\u65E5';
  23341. t['\u33FA'] = '\u0032\u0037\u65E5';
  23342. t['\u33FB'] = '\u0032\u0038\u65E5';
  23343. t['\u33FC'] = '\u0032\u0039\u65E5';
  23344. t['\u33FD'] = '\u0033\u0030\u65E5';
  23345. t['\u33FE'] = '\u0033\u0031\u65E5';
  23346. t['\uFB00'] = '\u0066\u0066';
  23347. t['\uFB01'] = '\u0066\u0069';
  23348. t['\uFB02'] = '\u0066\u006C';
  23349. t['\uFB03'] = '\u0066\u0066\u0069';
  23350. t['\uFB04'] = '\u0066\u0066\u006C';
  23351. t['\uFB05'] = '\u017F\u0074';
  23352. t['\uFB06'] = '\u0073\u0074';
  23353. t['\uFB13'] = '\u0574\u0576';
  23354. t['\uFB14'] = '\u0574\u0565';
  23355. t['\uFB15'] = '\u0574\u056B';
  23356. t['\uFB16'] = '\u057E\u0576';
  23357. t['\uFB17'] = '\u0574\u056D';
  23358. t['\uFB4F'] = '\u05D0\u05DC';
  23359. t['\uFB50'] = '\u0671';
  23360. t['\uFB51'] = '\u0671';
  23361. t['\uFB52'] = '\u067B';
  23362. t['\uFB53'] = '\u067B';
  23363. t['\uFB54'] = '\u067B';
  23364. t['\uFB55'] = '\u067B';
  23365. t['\uFB56'] = '\u067E';
  23366. t['\uFB57'] = '\u067E';
  23367. t['\uFB58'] = '\u067E';
  23368. t['\uFB59'] = '\u067E';
  23369. t['\uFB5A'] = '\u0680';
  23370. t['\uFB5B'] = '\u0680';
  23371. t['\uFB5C'] = '\u0680';
  23372. t['\uFB5D'] = '\u0680';
  23373. t['\uFB5E'] = '\u067A';
  23374. t['\uFB5F'] = '\u067A';
  23375. t['\uFB60'] = '\u067A';
  23376. t['\uFB61'] = '\u067A';
  23377. t['\uFB62'] = '\u067F';
  23378. t['\uFB63'] = '\u067F';
  23379. t['\uFB64'] = '\u067F';
  23380. t['\uFB65'] = '\u067F';
  23381. t['\uFB66'] = '\u0679';
  23382. t['\uFB67'] = '\u0679';
  23383. t['\uFB68'] = '\u0679';
  23384. t['\uFB69'] = '\u0679';
  23385. t['\uFB6A'] = '\u06A4';
  23386. t['\uFB6B'] = '\u06A4';
  23387. t['\uFB6C'] = '\u06A4';
  23388. t['\uFB6D'] = '\u06A4';
  23389. t['\uFB6E'] = '\u06A6';
  23390. t['\uFB6F'] = '\u06A6';
  23391. t['\uFB70'] = '\u06A6';
  23392. t['\uFB71'] = '\u06A6';
  23393. t['\uFB72'] = '\u0684';
  23394. t['\uFB73'] = '\u0684';
  23395. t['\uFB74'] = '\u0684';
  23396. t['\uFB75'] = '\u0684';
  23397. t['\uFB76'] = '\u0683';
  23398. t['\uFB77'] = '\u0683';
  23399. t['\uFB78'] = '\u0683';
  23400. t['\uFB79'] = '\u0683';
  23401. t['\uFB7A'] = '\u0686';
  23402. t['\uFB7B'] = '\u0686';
  23403. t['\uFB7C'] = '\u0686';
  23404. t['\uFB7D'] = '\u0686';
  23405. t['\uFB7E'] = '\u0687';
  23406. t['\uFB7F'] = '\u0687';
  23407. t['\uFB80'] = '\u0687';
  23408. t['\uFB81'] = '\u0687';
  23409. t['\uFB82'] = '\u068D';
  23410. t['\uFB83'] = '\u068D';
  23411. t['\uFB84'] = '\u068C';
  23412. t['\uFB85'] = '\u068C';
  23413. t['\uFB86'] = '\u068E';
  23414. t['\uFB87'] = '\u068E';
  23415. t['\uFB88'] = '\u0688';
  23416. t['\uFB89'] = '\u0688';
  23417. t['\uFB8A'] = '\u0698';
  23418. t['\uFB8B'] = '\u0698';
  23419. t['\uFB8C'] = '\u0691';
  23420. t['\uFB8D'] = '\u0691';
  23421. t['\uFB8E'] = '\u06A9';
  23422. t['\uFB8F'] = '\u06A9';
  23423. t['\uFB90'] = '\u06A9';
  23424. t['\uFB91'] = '\u06A9';
  23425. t['\uFB92'] = '\u06AF';
  23426. t['\uFB93'] = '\u06AF';
  23427. t['\uFB94'] = '\u06AF';
  23428. t['\uFB95'] = '\u06AF';
  23429. t['\uFB96'] = '\u06B3';
  23430. t['\uFB97'] = '\u06B3';
  23431. t['\uFB98'] = '\u06B3';
  23432. t['\uFB99'] = '\u06B3';
  23433. t['\uFB9A'] = '\u06B1';
  23434. t['\uFB9B'] = '\u06B1';
  23435. t['\uFB9C'] = '\u06B1';
  23436. t['\uFB9D'] = '\u06B1';
  23437. t['\uFB9E'] = '\u06BA';
  23438. t['\uFB9F'] = '\u06BA';
  23439. t['\uFBA0'] = '\u06BB';
  23440. t['\uFBA1'] = '\u06BB';
  23441. t['\uFBA2'] = '\u06BB';
  23442. t['\uFBA3'] = '\u06BB';
  23443. t['\uFBA4'] = '\u06C0';
  23444. t['\uFBA5'] = '\u06C0';
  23445. t['\uFBA6'] = '\u06C1';
  23446. t['\uFBA7'] = '\u06C1';
  23447. t['\uFBA8'] = '\u06C1';
  23448. t['\uFBA9'] = '\u06C1';
  23449. t['\uFBAA'] = '\u06BE';
  23450. t['\uFBAB'] = '\u06BE';
  23451. t['\uFBAC'] = '\u06BE';
  23452. t['\uFBAD'] = '\u06BE';
  23453. t['\uFBAE'] = '\u06D2';
  23454. t['\uFBAF'] = '\u06D2';
  23455. t['\uFBB0'] = '\u06D3';
  23456. t['\uFBB1'] = '\u06D3';
  23457. t['\uFBD3'] = '\u06AD';
  23458. t['\uFBD4'] = '\u06AD';
  23459. t['\uFBD5'] = '\u06AD';
  23460. t['\uFBD6'] = '\u06AD';
  23461. t['\uFBD7'] = '\u06C7';
  23462. t['\uFBD8'] = '\u06C7';
  23463. t['\uFBD9'] = '\u06C6';
  23464. t['\uFBDA'] = '\u06C6';
  23465. t['\uFBDB'] = '\u06C8';
  23466. t['\uFBDC'] = '\u06C8';
  23467. t['\uFBDD'] = '\u0677';
  23468. t['\uFBDE'] = '\u06CB';
  23469. t['\uFBDF'] = '\u06CB';
  23470. t['\uFBE0'] = '\u06C5';
  23471. t['\uFBE1'] = '\u06C5';
  23472. t['\uFBE2'] = '\u06C9';
  23473. t['\uFBE3'] = '\u06C9';
  23474. t['\uFBE4'] = '\u06D0';
  23475. t['\uFBE5'] = '\u06D0';
  23476. t['\uFBE6'] = '\u06D0';
  23477. t['\uFBE7'] = '\u06D0';
  23478. t['\uFBE8'] = '\u0649';
  23479. t['\uFBE9'] = '\u0649';
  23480. t['\uFBEA'] = '\u0626\u0627';
  23481. t['\uFBEB'] = '\u0626\u0627';
  23482. t['\uFBEC'] = '\u0626\u06D5';
  23483. t['\uFBED'] = '\u0626\u06D5';
  23484. t['\uFBEE'] = '\u0626\u0648';
  23485. t['\uFBEF'] = '\u0626\u0648';
  23486. t['\uFBF0'] = '\u0626\u06C7';
  23487. t['\uFBF1'] = '\u0626\u06C7';
  23488. t['\uFBF2'] = '\u0626\u06C6';
  23489. t['\uFBF3'] = '\u0626\u06C6';
  23490. t['\uFBF4'] = '\u0626\u06C8';
  23491. t['\uFBF5'] = '\u0626\u06C8';
  23492. t['\uFBF6'] = '\u0626\u06D0';
  23493. t['\uFBF7'] = '\u0626\u06D0';
  23494. t['\uFBF8'] = '\u0626\u06D0';
  23495. t['\uFBF9'] = '\u0626\u0649';
  23496. t['\uFBFA'] = '\u0626\u0649';
  23497. t['\uFBFB'] = '\u0626\u0649';
  23498. t['\uFBFC'] = '\u06CC';
  23499. t['\uFBFD'] = '\u06CC';
  23500. t['\uFBFE'] = '\u06CC';
  23501. t['\uFBFF'] = '\u06CC';
  23502. t['\uFC00'] = '\u0626\u062C';
  23503. t['\uFC01'] = '\u0626\u062D';
  23504. t['\uFC02'] = '\u0626\u0645';
  23505. t['\uFC03'] = '\u0626\u0649';
  23506. t['\uFC04'] = '\u0626\u064A';
  23507. t['\uFC05'] = '\u0628\u062C';
  23508. t['\uFC06'] = '\u0628\u062D';
  23509. t['\uFC07'] = '\u0628\u062E';
  23510. t['\uFC08'] = '\u0628\u0645';
  23511. t['\uFC09'] = '\u0628\u0649';
  23512. t['\uFC0A'] = '\u0628\u064A';
  23513. t['\uFC0B'] = '\u062A\u062C';
  23514. t['\uFC0C'] = '\u062A\u062D';
  23515. t['\uFC0D'] = '\u062A\u062E';
  23516. t['\uFC0E'] = '\u062A\u0645';
  23517. t['\uFC0F'] = '\u062A\u0649';
  23518. t['\uFC10'] = '\u062A\u064A';
  23519. t['\uFC11'] = '\u062B\u062C';
  23520. t['\uFC12'] = '\u062B\u0645';
  23521. t['\uFC13'] = '\u062B\u0649';
  23522. t['\uFC14'] = '\u062B\u064A';
  23523. t['\uFC15'] = '\u062C\u062D';
  23524. t['\uFC16'] = '\u062C\u0645';
  23525. t['\uFC17'] = '\u062D\u062C';
  23526. t['\uFC18'] = '\u062D\u0645';
  23527. t['\uFC19'] = '\u062E\u062C';
  23528. t['\uFC1A'] = '\u062E\u062D';
  23529. t['\uFC1B'] = '\u062E\u0645';
  23530. t['\uFC1C'] = '\u0633\u062C';
  23531. t['\uFC1D'] = '\u0633\u062D';
  23532. t['\uFC1E'] = '\u0633\u062E';
  23533. t['\uFC1F'] = '\u0633\u0645';
  23534. t['\uFC20'] = '\u0635\u062D';
  23535. t['\uFC21'] = '\u0635\u0645';
  23536. t['\uFC22'] = '\u0636\u062C';
  23537. t['\uFC23'] = '\u0636\u062D';
  23538. t['\uFC24'] = '\u0636\u062E';
  23539. t['\uFC25'] = '\u0636\u0645';
  23540. t['\uFC26'] = '\u0637\u062D';
  23541. t['\uFC27'] = '\u0637\u0645';
  23542. t['\uFC28'] = '\u0638\u0645';
  23543. t['\uFC29'] = '\u0639\u062C';
  23544. t['\uFC2A'] = '\u0639\u0645';
  23545. t['\uFC2B'] = '\u063A\u062C';
  23546. t['\uFC2C'] = '\u063A\u0645';
  23547. t['\uFC2D'] = '\u0641\u062C';
  23548. t['\uFC2E'] = '\u0641\u062D';
  23549. t['\uFC2F'] = '\u0641\u062E';
  23550. t['\uFC30'] = '\u0641\u0645';
  23551. t['\uFC31'] = '\u0641\u0649';
  23552. t['\uFC32'] = '\u0641\u064A';
  23553. t['\uFC33'] = '\u0642\u062D';
  23554. t['\uFC34'] = '\u0642\u0645';
  23555. t['\uFC35'] = '\u0642\u0649';
  23556. t['\uFC36'] = '\u0642\u064A';
  23557. t['\uFC37'] = '\u0643\u0627';
  23558. t['\uFC38'] = '\u0643\u062C';
  23559. t['\uFC39'] = '\u0643\u062D';
  23560. t['\uFC3A'] = '\u0643\u062E';
  23561. t['\uFC3B'] = '\u0643\u0644';
  23562. t['\uFC3C'] = '\u0643\u0645';
  23563. t['\uFC3D'] = '\u0643\u0649';
  23564. t['\uFC3E'] = '\u0643\u064A';
  23565. t['\uFC3F'] = '\u0644\u062C';
  23566. t['\uFC40'] = '\u0644\u062D';
  23567. t['\uFC41'] = '\u0644\u062E';
  23568. t['\uFC42'] = '\u0644\u0645';
  23569. t['\uFC43'] = '\u0644\u0649';
  23570. t['\uFC44'] = '\u0644\u064A';
  23571. t['\uFC45'] = '\u0645\u062C';
  23572. t['\uFC46'] = '\u0645\u062D';
  23573. t['\uFC47'] = '\u0645\u062E';
  23574. t['\uFC48'] = '\u0645\u0645';
  23575. t['\uFC49'] = '\u0645\u0649';
  23576. t['\uFC4A'] = '\u0645\u064A';
  23577. t['\uFC4B'] = '\u0646\u062C';
  23578. t['\uFC4C'] = '\u0646\u062D';
  23579. t['\uFC4D'] = '\u0646\u062E';
  23580. t['\uFC4E'] = '\u0646\u0645';
  23581. t['\uFC4F'] = '\u0646\u0649';
  23582. t['\uFC50'] = '\u0646\u064A';
  23583. t['\uFC51'] = '\u0647\u062C';
  23584. t['\uFC52'] = '\u0647\u0645';
  23585. t['\uFC53'] = '\u0647\u0649';
  23586. t['\uFC54'] = '\u0647\u064A';
  23587. t['\uFC55'] = '\u064A\u062C';
  23588. t['\uFC56'] = '\u064A\u062D';
  23589. t['\uFC57'] = '\u064A\u062E';
  23590. t['\uFC58'] = '\u064A\u0645';
  23591. t['\uFC59'] = '\u064A\u0649';
  23592. t['\uFC5A'] = '\u064A\u064A';
  23593. t['\uFC5B'] = '\u0630\u0670';
  23594. t['\uFC5C'] = '\u0631\u0670';
  23595. t['\uFC5D'] = '\u0649\u0670';
  23596. t['\uFC5E'] = '\u0020\u064C\u0651';
  23597. t['\uFC5F'] = '\u0020\u064D\u0651';
  23598. t['\uFC60'] = '\u0020\u064E\u0651';
  23599. t['\uFC61'] = '\u0020\u064F\u0651';
  23600. t['\uFC62'] = '\u0020\u0650\u0651';
  23601. t['\uFC63'] = '\u0020\u0651\u0670';
  23602. t['\uFC64'] = '\u0626\u0631';
  23603. t['\uFC65'] = '\u0626\u0632';
  23604. t['\uFC66'] = '\u0626\u0645';
  23605. t['\uFC67'] = '\u0626\u0646';
  23606. t['\uFC68'] = '\u0626\u0649';
  23607. t['\uFC69'] = '\u0626\u064A';
  23608. t['\uFC6A'] = '\u0628\u0631';
  23609. t['\uFC6B'] = '\u0628\u0632';
  23610. t['\uFC6C'] = '\u0628\u0645';
  23611. t['\uFC6D'] = '\u0628\u0646';
  23612. t['\uFC6E'] = '\u0628\u0649';
  23613. t['\uFC6F'] = '\u0628\u064A';
  23614. t['\uFC70'] = '\u062A\u0631';
  23615. t['\uFC71'] = '\u062A\u0632';
  23616. t['\uFC72'] = '\u062A\u0645';
  23617. t['\uFC73'] = '\u062A\u0646';
  23618. t['\uFC74'] = '\u062A\u0649';
  23619. t['\uFC75'] = '\u062A\u064A';
  23620. t['\uFC76'] = '\u062B\u0631';
  23621. t['\uFC77'] = '\u062B\u0632';
  23622. t['\uFC78'] = '\u062B\u0645';
  23623. t['\uFC79'] = '\u062B\u0646';
  23624. t['\uFC7A'] = '\u062B\u0649';
  23625. t['\uFC7B'] = '\u062B\u064A';
  23626. t['\uFC7C'] = '\u0641\u0649';
  23627. t['\uFC7D'] = '\u0641\u064A';
  23628. t['\uFC7E'] = '\u0642\u0649';
  23629. t['\uFC7F'] = '\u0642\u064A';
  23630. t['\uFC80'] = '\u0643\u0627';
  23631. t['\uFC81'] = '\u0643\u0644';
  23632. t['\uFC82'] = '\u0643\u0645';
  23633. t['\uFC83'] = '\u0643\u0649';
  23634. t['\uFC84'] = '\u0643\u064A';
  23635. t['\uFC85'] = '\u0644\u0645';
  23636. t['\uFC86'] = '\u0644\u0649';
  23637. t['\uFC87'] = '\u0644\u064A';
  23638. t['\uFC88'] = '\u0645\u0627';
  23639. t['\uFC89'] = '\u0645\u0645';
  23640. t['\uFC8A'] = '\u0646\u0631';
  23641. t['\uFC8B'] = '\u0646\u0632';
  23642. t['\uFC8C'] = '\u0646\u0645';
  23643. t['\uFC8D'] = '\u0646\u0646';
  23644. t['\uFC8E'] = '\u0646\u0649';
  23645. t['\uFC8F'] = '\u0646\u064A';
  23646. t['\uFC90'] = '\u0649\u0670';
  23647. t['\uFC91'] = '\u064A\u0631';
  23648. t['\uFC92'] = '\u064A\u0632';
  23649. t['\uFC93'] = '\u064A\u0645';
  23650. t['\uFC94'] = '\u064A\u0646';
  23651. t['\uFC95'] = '\u064A\u0649';
  23652. t['\uFC96'] = '\u064A\u064A';
  23653. t['\uFC97'] = '\u0626\u062C';
  23654. t['\uFC98'] = '\u0626\u062D';
  23655. t['\uFC99'] = '\u0626\u062E';
  23656. t['\uFC9A'] = '\u0626\u0645';
  23657. t['\uFC9B'] = '\u0626\u0647';
  23658. t['\uFC9C'] = '\u0628\u062C';
  23659. t['\uFC9D'] = '\u0628\u062D';
  23660. t['\uFC9E'] = '\u0628\u062E';
  23661. t['\uFC9F'] = '\u0628\u0645';
  23662. t['\uFCA0'] = '\u0628\u0647';
  23663. t['\uFCA1'] = '\u062A\u062C';
  23664. t['\uFCA2'] = '\u062A\u062D';
  23665. t['\uFCA3'] = '\u062A\u062E';
  23666. t['\uFCA4'] = '\u062A\u0645';
  23667. t['\uFCA5'] = '\u062A\u0647';
  23668. t['\uFCA6'] = '\u062B\u0645';
  23669. t['\uFCA7'] = '\u062C\u062D';
  23670. t['\uFCA8'] = '\u062C\u0645';
  23671. t['\uFCA9'] = '\u062D\u062C';
  23672. t['\uFCAA'] = '\u062D\u0645';
  23673. t['\uFCAB'] = '\u062E\u062C';
  23674. t['\uFCAC'] = '\u062E\u0645';
  23675. t['\uFCAD'] = '\u0633\u062C';
  23676. t['\uFCAE'] = '\u0633\u062D';
  23677. t['\uFCAF'] = '\u0633\u062E';
  23678. t['\uFCB0'] = '\u0633\u0645';
  23679. t['\uFCB1'] = '\u0635\u062D';
  23680. t['\uFCB2'] = '\u0635\u062E';
  23681. t['\uFCB3'] = '\u0635\u0645';
  23682. t['\uFCB4'] = '\u0636\u062C';
  23683. t['\uFCB5'] = '\u0636\u062D';
  23684. t['\uFCB6'] = '\u0636\u062E';
  23685. t['\uFCB7'] = '\u0636\u0645';
  23686. t['\uFCB8'] = '\u0637\u062D';
  23687. t['\uFCB9'] = '\u0638\u0645';
  23688. t['\uFCBA'] = '\u0639\u062C';
  23689. t['\uFCBB'] = '\u0639\u0645';
  23690. t['\uFCBC'] = '\u063A\u062C';
  23691. t['\uFCBD'] = '\u063A\u0645';
  23692. t['\uFCBE'] = '\u0641\u062C';
  23693. t['\uFCBF'] = '\u0641\u062D';
  23694. t['\uFCC0'] = '\u0641\u062E';
  23695. t['\uFCC1'] = '\u0641\u0645';
  23696. t['\uFCC2'] = '\u0642\u062D';
  23697. t['\uFCC3'] = '\u0642\u0645';
  23698. t['\uFCC4'] = '\u0643\u062C';
  23699. t['\uFCC5'] = '\u0643\u062D';
  23700. t['\uFCC6'] = '\u0643\u062E';
  23701. t['\uFCC7'] = '\u0643\u0644';
  23702. t['\uFCC8'] = '\u0643\u0645';
  23703. t['\uFCC9'] = '\u0644\u062C';
  23704. t['\uFCCA'] = '\u0644\u062D';
  23705. t['\uFCCB'] = '\u0644\u062E';
  23706. t['\uFCCC'] = '\u0644\u0645';
  23707. t['\uFCCD'] = '\u0644\u0647';
  23708. t['\uFCCE'] = '\u0645\u062C';
  23709. t['\uFCCF'] = '\u0645\u062D';
  23710. t['\uFCD0'] = '\u0645\u062E';
  23711. t['\uFCD1'] = '\u0645\u0645';
  23712. t['\uFCD2'] = '\u0646\u062C';
  23713. t['\uFCD3'] = '\u0646\u062D';
  23714. t['\uFCD4'] = '\u0646\u062E';
  23715. t['\uFCD5'] = '\u0646\u0645';
  23716. t['\uFCD6'] = '\u0646\u0647';
  23717. t['\uFCD7'] = '\u0647\u062C';
  23718. t['\uFCD8'] = '\u0647\u0645';
  23719. t['\uFCD9'] = '\u0647\u0670';
  23720. t['\uFCDA'] = '\u064A\u062C';
  23721. t['\uFCDB'] = '\u064A\u062D';
  23722. t['\uFCDC'] = '\u064A\u062E';
  23723. t['\uFCDD'] = '\u064A\u0645';
  23724. t['\uFCDE'] = '\u064A\u0647';
  23725. t['\uFCDF'] = '\u0626\u0645';
  23726. t['\uFCE0'] = '\u0626\u0647';
  23727. t['\uFCE1'] = '\u0628\u0645';
  23728. t['\uFCE2'] = '\u0628\u0647';
  23729. t['\uFCE3'] = '\u062A\u0645';
  23730. t['\uFCE4'] = '\u062A\u0647';
  23731. t['\uFCE5'] = '\u062B\u0645';
  23732. t['\uFCE6'] = '\u062B\u0647';
  23733. t['\uFCE7'] = '\u0633\u0645';
  23734. t['\uFCE8'] = '\u0633\u0647';
  23735. t['\uFCE9'] = '\u0634\u0645';
  23736. t['\uFCEA'] = '\u0634\u0647';
  23737. t['\uFCEB'] = '\u0643\u0644';
  23738. t['\uFCEC'] = '\u0643\u0645';
  23739. t['\uFCED'] = '\u0644\u0645';
  23740. t['\uFCEE'] = '\u0646\u0645';
  23741. t['\uFCEF'] = '\u0646\u0647';
  23742. t['\uFCF0'] = '\u064A\u0645';
  23743. t['\uFCF1'] = '\u064A\u0647';
  23744. t['\uFCF2'] = '\u0640\u064E\u0651';
  23745. t['\uFCF3'] = '\u0640\u064F\u0651';
  23746. t['\uFCF4'] = '\u0640\u0650\u0651';
  23747. t['\uFCF5'] = '\u0637\u0649';
  23748. t['\uFCF6'] = '\u0637\u064A';
  23749. t['\uFCF7'] = '\u0639\u0649';
  23750. t['\uFCF8'] = '\u0639\u064A';
  23751. t['\uFCF9'] = '\u063A\u0649';
  23752. t['\uFCFA'] = '\u063A\u064A';
  23753. t['\uFCFB'] = '\u0633\u0649';
  23754. t['\uFCFC'] = '\u0633\u064A';
  23755. t['\uFCFD'] = '\u0634\u0649';
  23756. t['\uFCFE'] = '\u0634\u064A';
  23757. t['\uFCFF'] = '\u062D\u0649';
  23758. t['\uFD00'] = '\u062D\u064A';
  23759. t['\uFD01'] = '\u062C\u0649';
  23760. t['\uFD02'] = '\u062C\u064A';
  23761. t['\uFD03'] = '\u062E\u0649';
  23762. t['\uFD04'] = '\u062E\u064A';
  23763. t['\uFD05'] = '\u0635\u0649';
  23764. t['\uFD06'] = '\u0635\u064A';
  23765. t['\uFD07'] = '\u0636\u0649';
  23766. t['\uFD08'] = '\u0636\u064A';
  23767. t['\uFD09'] = '\u0634\u062C';
  23768. t['\uFD0A'] = '\u0634\u062D';
  23769. t['\uFD0B'] = '\u0634\u062E';
  23770. t['\uFD0C'] = '\u0634\u0645';
  23771. t['\uFD0D'] = '\u0634\u0631';
  23772. t['\uFD0E'] = '\u0633\u0631';
  23773. t['\uFD0F'] = '\u0635\u0631';
  23774. t['\uFD10'] = '\u0636\u0631';
  23775. t['\uFD11'] = '\u0637\u0649';
  23776. t['\uFD12'] = '\u0637\u064A';
  23777. t['\uFD13'] = '\u0639\u0649';
  23778. t['\uFD14'] = '\u0639\u064A';
  23779. t['\uFD15'] = '\u063A\u0649';
  23780. t['\uFD16'] = '\u063A\u064A';
  23781. t['\uFD17'] = '\u0633\u0649';
  23782. t['\uFD18'] = '\u0633\u064A';
  23783. t['\uFD19'] = '\u0634\u0649';
  23784. t['\uFD1A'] = '\u0634\u064A';
  23785. t['\uFD1B'] = '\u062D\u0649';
  23786. t['\uFD1C'] = '\u062D\u064A';
  23787. t['\uFD1D'] = '\u062C\u0649';
  23788. t['\uFD1E'] = '\u062C\u064A';
  23789. t['\uFD1F'] = '\u062E\u0649';
  23790. t['\uFD20'] = '\u062E\u064A';
  23791. t['\uFD21'] = '\u0635\u0649';
  23792. t['\uFD22'] = '\u0635\u064A';
  23793. t['\uFD23'] = '\u0636\u0649';
  23794. t['\uFD24'] = '\u0636\u064A';
  23795. t['\uFD25'] = '\u0634\u062C';
  23796. t['\uFD26'] = '\u0634\u062D';
  23797. t['\uFD27'] = '\u0634\u062E';
  23798. t['\uFD28'] = '\u0634\u0645';
  23799. t['\uFD29'] = '\u0634\u0631';
  23800. t['\uFD2A'] = '\u0633\u0631';
  23801. t['\uFD2B'] = '\u0635\u0631';
  23802. t['\uFD2C'] = '\u0636\u0631';
  23803. t['\uFD2D'] = '\u0634\u062C';
  23804. t['\uFD2E'] = '\u0634\u062D';
  23805. t['\uFD2F'] = '\u0634\u062E';
  23806. t['\uFD30'] = '\u0634\u0645';
  23807. t['\uFD31'] = '\u0633\u0647';
  23808. t['\uFD32'] = '\u0634\u0647';
  23809. t['\uFD33'] = '\u0637\u0645';
  23810. t['\uFD34'] = '\u0633\u062C';
  23811. t['\uFD35'] = '\u0633\u062D';
  23812. t['\uFD36'] = '\u0633\u062E';
  23813. t['\uFD37'] = '\u0634\u062C';
  23814. t['\uFD38'] = '\u0634\u062D';
  23815. t['\uFD39'] = '\u0634\u062E';
  23816. t['\uFD3A'] = '\u0637\u0645';
  23817. t['\uFD3B'] = '\u0638\u0645';
  23818. t['\uFD3C'] = '\u0627\u064B';
  23819. t['\uFD3D'] = '\u0627\u064B';
  23820. t['\uFD50'] = '\u062A\u062C\u0645';
  23821. t['\uFD51'] = '\u062A\u062D\u062C';
  23822. t['\uFD52'] = '\u062A\u062D\u062C';
  23823. t['\uFD53'] = '\u062A\u062D\u0645';
  23824. t['\uFD54'] = '\u062A\u062E\u0645';
  23825. t['\uFD55'] = '\u062A\u0645\u062C';
  23826. t['\uFD56'] = '\u062A\u0645\u062D';
  23827. t['\uFD57'] = '\u062A\u0645\u062E';
  23828. t['\uFD58'] = '\u062C\u0645\u062D';
  23829. t['\uFD59'] = '\u062C\u0645\u062D';
  23830. t['\uFD5A'] = '\u062D\u0645\u064A';
  23831. t['\uFD5B'] = '\u062D\u0645\u0649';
  23832. t['\uFD5C'] = '\u0633\u062D\u062C';
  23833. t['\uFD5D'] = '\u0633\u062C\u062D';
  23834. t['\uFD5E'] = '\u0633\u062C\u0649';
  23835. t['\uFD5F'] = '\u0633\u0645\u062D';
  23836. t['\uFD60'] = '\u0633\u0645\u062D';
  23837. t['\uFD61'] = '\u0633\u0645\u062C';
  23838. t['\uFD62'] = '\u0633\u0645\u0645';
  23839. t['\uFD63'] = '\u0633\u0645\u0645';
  23840. t['\uFD64'] = '\u0635\u062D\u062D';
  23841. t['\uFD65'] = '\u0635\u062D\u062D';
  23842. t['\uFD66'] = '\u0635\u0645\u0645';
  23843. t['\uFD67'] = '\u0634\u062D\u0645';
  23844. t['\uFD68'] = '\u0634\u062D\u0645';
  23845. t['\uFD69'] = '\u0634\u062C\u064A';
  23846. t['\uFD6A'] = '\u0634\u0645\u062E';
  23847. t['\uFD6B'] = '\u0634\u0645\u062E';
  23848. t['\uFD6C'] = '\u0634\u0645\u0645';
  23849. t['\uFD6D'] = '\u0634\u0645\u0645';
  23850. t['\uFD6E'] = '\u0636\u062D\u0649';
  23851. t['\uFD6F'] = '\u0636\u062E\u0645';
  23852. t['\uFD70'] = '\u0636\u062E\u0645';
  23853. t['\uFD71'] = '\u0637\u0645\u062D';
  23854. t['\uFD72'] = '\u0637\u0645\u062D';
  23855. t['\uFD73'] = '\u0637\u0645\u0645';
  23856. t['\uFD74'] = '\u0637\u0645\u064A';
  23857. t['\uFD75'] = '\u0639\u062C\u0645';
  23858. t['\uFD76'] = '\u0639\u0645\u0645';
  23859. t['\uFD77'] = '\u0639\u0645\u0645';
  23860. t['\uFD78'] = '\u0639\u0645\u0649';
  23861. t['\uFD79'] = '\u063A\u0645\u0645';
  23862. t['\uFD7A'] = '\u063A\u0645\u064A';
  23863. t['\uFD7B'] = '\u063A\u0645\u0649';
  23864. t['\uFD7C'] = '\u0641\u062E\u0645';
  23865. t['\uFD7D'] = '\u0641\u062E\u0645';
  23866. t['\uFD7E'] = '\u0642\u0645\u062D';
  23867. t['\uFD7F'] = '\u0642\u0645\u0645';
  23868. t['\uFD80'] = '\u0644\u062D\u0645';
  23869. t['\uFD81'] = '\u0644\u062D\u064A';
  23870. t['\uFD82'] = '\u0644\u062D\u0649';
  23871. t['\uFD83'] = '\u0644\u062C\u062C';
  23872. t['\uFD84'] = '\u0644\u062C\u062C';
  23873. t['\uFD85'] = '\u0644\u062E\u0645';
  23874. t['\uFD86'] = '\u0644\u062E\u0645';
  23875. t['\uFD87'] = '\u0644\u0645\u062D';
  23876. t['\uFD88'] = '\u0644\u0645\u062D';
  23877. t['\uFD89'] = '\u0645\u062D\u062C';
  23878. t['\uFD8A'] = '\u0645\u062D\u0645';
  23879. t['\uFD8B'] = '\u0645\u062D\u064A';
  23880. t['\uFD8C'] = '\u0645\u062C\u062D';
  23881. t['\uFD8D'] = '\u0645\u062C\u0645';
  23882. t['\uFD8E'] = '\u0645\u062E\u062C';
  23883. t['\uFD8F'] = '\u0645\u062E\u0645';
  23884. t['\uFD92'] = '\u0645\u062C\u062E';
  23885. t['\uFD93'] = '\u0647\u0645\u062C';
  23886. t['\uFD94'] = '\u0647\u0645\u0645';
  23887. t['\uFD95'] = '\u0646\u062D\u0645';
  23888. t['\uFD96'] = '\u0646\u062D\u0649';
  23889. t['\uFD97'] = '\u0646\u062C\u0645';
  23890. t['\uFD98'] = '\u0646\u062C\u0645';
  23891. t['\uFD99'] = '\u0646\u062C\u0649';
  23892. t['\uFD9A'] = '\u0646\u0645\u064A';
  23893. t['\uFD9B'] = '\u0646\u0645\u0649';
  23894. t['\uFD9C'] = '\u064A\u0645\u0645';
  23895. t['\uFD9D'] = '\u064A\u0645\u0645';
  23896. t['\uFD9E'] = '\u0628\u062E\u064A';
  23897. t['\uFD9F'] = '\u062A\u062C\u064A';
  23898. t['\uFDA0'] = '\u062A\u062C\u0649';
  23899. t['\uFDA1'] = '\u062A\u062E\u064A';
  23900. t['\uFDA2'] = '\u062A\u062E\u0649';
  23901. t['\uFDA3'] = '\u062A\u0645\u064A';
  23902. t['\uFDA4'] = '\u062A\u0645\u0649';
  23903. t['\uFDA5'] = '\u062C\u0645\u064A';
  23904. t['\uFDA6'] = '\u062C\u062D\u0649';
  23905. t['\uFDA7'] = '\u062C\u0645\u0649';
  23906. t['\uFDA8'] = '\u0633\u062E\u0649';
  23907. t['\uFDA9'] = '\u0635\u062D\u064A';
  23908. t['\uFDAA'] = '\u0634\u062D\u064A';
  23909. t['\uFDAB'] = '\u0636\u062D\u064A';
  23910. t['\uFDAC'] = '\u0644\u062C\u064A';
  23911. t['\uFDAD'] = '\u0644\u0645\u064A';
  23912. t['\uFDAE'] = '\u064A\u062D\u064A';
  23913. t['\uFDAF'] = '\u064A\u062C\u064A';
  23914. t['\uFDB0'] = '\u064A\u0645\u064A';
  23915. t['\uFDB1'] = '\u0645\u0645\u064A';
  23916. t['\uFDB2'] = '\u0642\u0645\u064A';
  23917. t['\uFDB3'] = '\u0646\u062D\u064A';
  23918. t['\uFDB4'] = '\u0642\u0645\u062D';
  23919. t['\uFDB5'] = '\u0644\u062D\u0645';
  23920. t['\uFDB6'] = '\u0639\u0645\u064A';
  23921. t['\uFDB7'] = '\u0643\u0645\u064A';
  23922. t['\uFDB8'] = '\u0646\u062C\u062D';
  23923. t['\uFDB9'] = '\u0645\u062E\u064A';
  23924. t['\uFDBA'] = '\u0644\u062C\u0645';
  23925. t['\uFDBB'] = '\u0643\u0645\u0645';
  23926. t['\uFDBC'] = '\u0644\u062C\u0645';
  23927. t['\uFDBD'] = '\u0646\u062C\u062D';
  23928. t['\uFDBE'] = '\u062C\u062D\u064A';
  23929. t['\uFDBF'] = '\u062D\u062C\u064A';
  23930. t['\uFDC0'] = '\u0645\u062C\u064A';
  23931. t['\uFDC1'] = '\u0641\u0645\u064A';
  23932. t['\uFDC2'] = '\u0628\u062D\u064A';
  23933. t['\uFDC3'] = '\u0643\u0645\u0645';
  23934. t['\uFDC4'] = '\u0639\u062C\u0645';
  23935. t['\uFDC5'] = '\u0635\u0645\u0645';
  23936. t['\uFDC6'] = '\u0633\u062E\u064A';
  23937. t['\uFDC7'] = '\u0646\u062C\u064A';
  23938. t['\uFE49'] = '\u203E';
  23939. t['\uFE4A'] = '\u203E';
  23940. t['\uFE4B'] = '\u203E';
  23941. t['\uFE4C'] = '\u203E';
  23942. t['\uFE4D'] = '\u005F';
  23943. t['\uFE4E'] = '\u005F';
  23944. t['\uFE4F'] = '\u005F';
  23945. t['\uFE80'] = '\u0621';
  23946. t['\uFE81'] = '\u0622';
  23947. t['\uFE82'] = '\u0622';
  23948. t['\uFE83'] = '\u0623';
  23949. t['\uFE84'] = '\u0623';
  23950. t['\uFE85'] = '\u0624';
  23951. t['\uFE86'] = '\u0624';
  23952. t['\uFE87'] = '\u0625';
  23953. t['\uFE88'] = '\u0625';
  23954. t['\uFE89'] = '\u0626';
  23955. t['\uFE8A'] = '\u0626';
  23956. t['\uFE8B'] = '\u0626';
  23957. t['\uFE8C'] = '\u0626';
  23958. t['\uFE8D'] = '\u0627';
  23959. t['\uFE8E'] = '\u0627';
  23960. t['\uFE8F'] = '\u0628';
  23961. t['\uFE90'] = '\u0628';
  23962. t['\uFE91'] = '\u0628';
  23963. t['\uFE92'] = '\u0628';
  23964. t['\uFE93'] = '\u0629';
  23965. t['\uFE94'] = '\u0629';
  23966. t['\uFE95'] = '\u062A';
  23967. t['\uFE96'] = '\u062A';
  23968. t['\uFE97'] = '\u062A';
  23969. t['\uFE98'] = '\u062A';
  23970. t['\uFE99'] = '\u062B';
  23971. t['\uFE9A'] = '\u062B';
  23972. t['\uFE9B'] = '\u062B';
  23973. t['\uFE9C'] = '\u062B';
  23974. t['\uFE9D'] = '\u062C';
  23975. t['\uFE9E'] = '\u062C';
  23976. t['\uFE9F'] = '\u062C';
  23977. t['\uFEA0'] = '\u062C';
  23978. t['\uFEA1'] = '\u062D';
  23979. t['\uFEA2'] = '\u062D';
  23980. t['\uFEA3'] = '\u062D';
  23981. t['\uFEA4'] = '\u062D';
  23982. t['\uFEA5'] = '\u062E';
  23983. t['\uFEA6'] = '\u062E';
  23984. t['\uFEA7'] = '\u062E';
  23985. t['\uFEA8'] = '\u062E';
  23986. t['\uFEA9'] = '\u062F';
  23987. t['\uFEAA'] = '\u062F';
  23988. t['\uFEAB'] = '\u0630';
  23989. t['\uFEAC'] = '\u0630';
  23990. t['\uFEAD'] = '\u0631';
  23991. t['\uFEAE'] = '\u0631';
  23992. t['\uFEAF'] = '\u0632';
  23993. t['\uFEB0'] = '\u0632';
  23994. t['\uFEB1'] = '\u0633';
  23995. t['\uFEB2'] = '\u0633';
  23996. t['\uFEB3'] = '\u0633';
  23997. t['\uFEB4'] = '\u0633';
  23998. t['\uFEB5'] = '\u0634';
  23999. t['\uFEB6'] = '\u0634';
  24000. t['\uFEB7'] = '\u0634';
  24001. t['\uFEB8'] = '\u0634';
  24002. t['\uFEB9'] = '\u0635';
  24003. t['\uFEBA'] = '\u0635';
  24004. t['\uFEBB'] = '\u0635';
  24005. t['\uFEBC'] = '\u0635';
  24006. t['\uFEBD'] = '\u0636';
  24007. t['\uFEBE'] = '\u0636';
  24008. t['\uFEBF'] = '\u0636';
  24009. t['\uFEC0'] = '\u0636';
  24010. t['\uFEC1'] = '\u0637';
  24011. t['\uFEC2'] = '\u0637';
  24012. t['\uFEC3'] = '\u0637';
  24013. t['\uFEC4'] = '\u0637';
  24014. t['\uFEC5'] = '\u0638';
  24015. t['\uFEC6'] = '\u0638';
  24016. t['\uFEC7'] = '\u0638';
  24017. t['\uFEC8'] = '\u0638';
  24018. t['\uFEC9'] = '\u0639';
  24019. t['\uFECA'] = '\u0639';
  24020. t['\uFECB'] = '\u0639';
  24021. t['\uFECC'] = '\u0639';
  24022. t['\uFECD'] = '\u063A';
  24023. t['\uFECE'] = '\u063A';
  24024. t['\uFECF'] = '\u063A';
  24025. t['\uFED0'] = '\u063A';
  24026. t['\uFED1'] = '\u0641';
  24027. t['\uFED2'] = '\u0641';
  24028. t['\uFED3'] = '\u0641';
  24029. t['\uFED4'] = '\u0641';
  24030. t['\uFED5'] = '\u0642';
  24031. t['\uFED6'] = '\u0642';
  24032. t['\uFED7'] = '\u0642';
  24033. t['\uFED8'] = '\u0642';
  24034. t['\uFED9'] = '\u0643';
  24035. t['\uFEDA'] = '\u0643';
  24036. t['\uFEDB'] = '\u0643';
  24037. t['\uFEDC'] = '\u0643';
  24038. t['\uFEDD'] = '\u0644';
  24039. t['\uFEDE'] = '\u0644';
  24040. t['\uFEDF'] = '\u0644';
  24041. t['\uFEE0'] = '\u0644';
  24042. t['\uFEE1'] = '\u0645';
  24043. t['\uFEE2'] = '\u0645';
  24044. t['\uFEE3'] = '\u0645';
  24045. t['\uFEE4'] = '\u0645';
  24046. t['\uFEE5'] = '\u0646';
  24047. t['\uFEE6'] = '\u0646';
  24048. t['\uFEE7'] = '\u0646';
  24049. t['\uFEE8'] = '\u0646';
  24050. t['\uFEE9'] = '\u0647';
  24051. t['\uFEEA'] = '\u0647';
  24052. t['\uFEEB'] = '\u0647';
  24053. t['\uFEEC'] = '\u0647';
  24054. t['\uFEED'] = '\u0648';
  24055. t['\uFEEE'] = '\u0648';
  24056. t['\uFEEF'] = '\u0649';
  24057. t['\uFEF0'] = '\u0649';
  24058. t['\uFEF1'] = '\u064A';
  24059. t['\uFEF2'] = '\u064A';
  24060. t['\uFEF3'] = '\u064A';
  24061. t['\uFEF4'] = '\u064A';
  24062. t['\uFEF5'] = '\u0644\u0622';
  24063. t['\uFEF6'] = '\u0644\u0622';
  24064. t['\uFEF7'] = '\u0644\u0623';
  24065. t['\uFEF8'] = '\u0644\u0623';
  24066. t['\uFEF9'] = '\u0644\u0625';
  24067. t['\uFEFA'] = '\u0644\u0625';
  24068. t['\uFEFB'] = '\u0644\u0627';
  24069. t['\uFEFC'] = '\u0644\u0627';
  24070. });
  24071. function reverseIfRtl(chars) {
  24072. var charsLength = chars.length;
  24073. //reverse an arabic ligature
  24074. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  24075. return chars;
  24076. }
  24077. var s = '';
  24078. for (var ii = charsLength - 1; ii >= 0; ii--) {
  24079. s += chars[ii];
  24080. }
  24081. return s;
  24082. }
  24083. exports.mapSpecialUnicodeValues = mapSpecialUnicodeValues;
  24084. exports.reverseIfRtl = reverseIfRtl;
  24085. exports.getUnicodeRangeFor = getUnicodeRangeFor;
  24086. exports.getNormalizedUnicodes = getNormalizedUnicodes;
  24087. exports.getUnicodeForGlyph = getUnicodeForGlyph;
  24088. }));
  24089. (function (root, factory) {
  24090. factory(root.pdfjsDisplayDOMUtils = {}, root.pdfjsSharedUtil);
  24091. }(this, function (exports, sharedUtil) {
  24092. var removeNullCharacters = sharedUtil.removeNullCharacters;
  24093. var warn = sharedUtil.warn;
  24094. var deprecated = sharedUtil.deprecated;
  24095. var createValidAbsoluteUrl = sharedUtil.createValidAbsoluteUrl;
  24096. /**
  24097. * Optimised CSS custom property getter/setter.
  24098. * @class
  24099. */
  24100. var CustomStyle = function CustomStyleClosure() {
  24101. // As noted on: http://www.zachstronaut.com/posts/2009/02/17/
  24102. // animate-css-transforms-firefox-webkit.html
  24103. // in some versions of IE9 it is critical that ms appear in this list
  24104. // before Moz
  24105. var prefixes = [
  24106. 'ms',
  24107. 'Moz',
  24108. 'Webkit',
  24109. 'O'
  24110. ];
  24111. var _cache = Object.create(null);
  24112. function CustomStyle() {
  24113. }
  24114. CustomStyle.getProp = function get(propName, element) {
  24115. // check cache only when no element is given
  24116. if (arguments.length === 1 && typeof _cache[propName] === 'string') {
  24117. return _cache[propName];
  24118. }
  24119. element = element || document.documentElement;
  24120. var style = element.style, prefixed, uPropName;
  24121. // test standard property first
  24122. if (typeof style[propName] === 'string') {
  24123. return _cache[propName] = propName;
  24124. }
  24125. // capitalize
  24126. uPropName = propName.charAt(0).toUpperCase() + propName.slice(1);
  24127. // test vendor specific properties
  24128. for (var i = 0, l = prefixes.length; i < l; i++) {
  24129. prefixed = prefixes[i] + uPropName;
  24130. if (typeof style[prefixed] === 'string') {
  24131. return _cache[propName] = prefixed;
  24132. }
  24133. }
  24134. //if all fails then set to undefined
  24135. return _cache[propName] = 'undefined';
  24136. };
  24137. CustomStyle.setProp = function set(propName, element, str) {
  24138. var prop = this.getProp(propName);
  24139. if (prop !== 'undefined') {
  24140. element.style[prop] = str;
  24141. }
  24142. };
  24143. return CustomStyle;
  24144. }();
  24145. var hasCanvasTypedArrays;
  24146. hasCanvasTypedArrays = function hasCanvasTypedArrays() {
  24147. var canvas = document.createElement('canvas');
  24148. canvas.width = canvas.height = 1;
  24149. var ctx = canvas.getContext('2d');
  24150. var imageData = ctx.createImageData(1, 1);
  24151. return typeof imageData.data.buffer !== 'undefined';
  24152. };
  24153. var LinkTarget = {
  24154. NONE: 0,
  24155. // Default value.
  24156. SELF: 1,
  24157. BLANK: 2,
  24158. PARENT: 3,
  24159. TOP: 4
  24160. };
  24161. var LinkTargetStringMap = [
  24162. '',
  24163. '_self',
  24164. '_blank',
  24165. '_parent',
  24166. '_top'
  24167. ];
  24168. /**
  24169. * @typedef ExternalLinkParameters
  24170. * @typedef {Object} ExternalLinkParameters
  24171. * @property {string} url - An absolute URL.
  24172. * @property {LinkTarget} target - The link target.
  24173. * @property {string} rel - The link relationship.
  24174. */
  24175. /**
  24176. * Adds various attributes (href, title, target, rel) to hyperlinks.
  24177. * @param {HTMLLinkElement} link - The link element.
  24178. * @param {ExternalLinkParameters} params
  24179. */
  24180. function addLinkAttributes(link, params) {
  24181. var url = params && params.url;
  24182. link.href = link.title = url ? removeNullCharacters(url) : '';
  24183. if (url) {
  24184. var target = params.target;
  24185. if (typeof target === 'undefined') {
  24186. target = getDefaultSetting('externalLinkTarget');
  24187. }
  24188. link.target = LinkTargetStringMap[target];
  24189. var rel = params.rel;
  24190. if (typeof rel === 'undefined') {
  24191. rel = getDefaultSetting('externalLinkRel');
  24192. }
  24193. link.rel = rel;
  24194. }
  24195. }
  24196. // Gets the file name from a given URL.
  24197. function getFilenameFromUrl(url) {
  24198. var anchor = url.indexOf('#');
  24199. var query = url.indexOf('?');
  24200. var end = Math.min(anchor > 0 ? anchor : url.length, query > 0 ? query : url.length);
  24201. return url.substring(url.lastIndexOf('/', end) + 1, end);
  24202. }
  24203. function getDefaultSetting(id) {
  24204. // The list of the settings and their default is maintained for backward
  24205. // compatibility and shall not be extended or modified. See also global.js.
  24206. var globalSettings = sharedUtil.globalScope.PDFJS;
  24207. switch (id) {
  24208. case 'pdfBug':
  24209. return globalSettings ? globalSettings.pdfBug : false;
  24210. case 'disableAutoFetch':
  24211. return globalSettings ? globalSettings.disableAutoFetch : false;
  24212. case 'disableStream':
  24213. return globalSettings ? globalSettings.disableStream : false;
  24214. case 'disableRange':
  24215. return globalSettings ? globalSettings.disableRange : false;
  24216. case 'disableFontFace':
  24217. return globalSettings ? globalSettings.disableFontFace : false;
  24218. case 'disableCreateObjectURL':
  24219. return globalSettings ? globalSettings.disableCreateObjectURL : false;
  24220. case 'disableWebGL':
  24221. return globalSettings ? globalSettings.disableWebGL : true;
  24222. case 'cMapUrl':
  24223. return globalSettings ? globalSettings.cMapUrl : null;
  24224. case 'cMapPacked':
  24225. return globalSettings ? globalSettings.cMapPacked : false;
  24226. case 'postMessageTransfers':
  24227. return globalSettings ? globalSettings.postMessageTransfers : true;
  24228. case 'workerSrc':
  24229. return globalSettings ? globalSettings.workerSrc : null;
  24230. case 'disableWorker':
  24231. return globalSettings ? globalSettings.disableWorker : false;
  24232. case 'maxImageSize':
  24233. return globalSettings ? globalSettings.maxImageSize : -1;
  24234. case 'imageResourcesPath':
  24235. return globalSettings ? globalSettings.imageResourcesPath : '';
  24236. case 'isEvalSupported':
  24237. return globalSettings ? globalSettings.isEvalSupported : true;
  24238. case 'externalLinkTarget':
  24239. if (!globalSettings) {
  24240. return LinkTarget.NONE;
  24241. }
  24242. switch (globalSettings.externalLinkTarget) {
  24243. case LinkTarget.NONE:
  24244. case LinkTarget.SELF:
  24245. case LinkTarget.BLANK:
  24246. case LinkTarget.PARENT:
  24247. case LinkTarget.TOP:
  24248. return globalSettings.externalLinkTarget;
  24249. }
  24250. warn('PDFJS.externalLinkTarget is invalid: ' + globalSettings.externalLinkTarget);
  24251. // Reset the external link target, to suppress further warnings.
  24252. globalSettings.externalLinkTarget = LinkTarget.NONE;
  24253. return LinkTarget.NONE;
  24254. case 'externalLinkRel':
  24255. return globalSettings ? globalSettings.externalLinkRel : 'noreferrer';
  24256. case 'enableStats':
  24257. return !!(globalSettings && globalSettings.enableStats);
  24258. default:
  24259. throw new Error('Unknown default setting: ' + id);
  24260. }
  24261. }
  24262. function isExternalLinkTargetSet() {
  24263. var externalLinkTarget = getDefaultSetting('externalLinkTarget');
  24264. switch (externalLinkTarget) {
  24265. case LinkTarget.NONE:
  24266. return false;
  24267. case LinkTarget.SELF:
  24268. case LinkTarget.BLANK:
  24269. case LinkTarget.PARENT:
  24270. case LinkTarget.TOP:
  24271. return true;
  24272. }
  24273. }
  24274. function isValidUrl(url, allowRelative) {
  24275. deprecated('isValidUrl(), please use createValidAbsoluteUrl() instead.');
  24276. var baseUrl = allowRelative ? 'http://example.com' : null;
  24277. return createValidAbsoluteUrl(url, baseUrl) !== null;
  24278. }
  24279. exports.CustomStyle = CustomStyle;
  24280. exports.addLinkAttributes = addLinkAttributes;
  24281. exports.isExternalLinkTargetSet = isExternalLinkTargetSet;
  24282. exports.isValidUrl = isValidUrl;
  24283. exports.getFilenameFromUrl = getFilenameFromUrl;
  24284. exports.LinkTarget = LinkTarget;
  24285. exports.hasCanvasTypedArrays = hasCanvasTypedArrays;
  24286. exports.getDefaultSetting = getDefaultSetting;
  24287. }));
  24288. (function (root, factory) {
  24289. factory(root.pdfjsDisplayFontLoader = {}, root.pdfjsSharedUtil);
  24290. }(this, function (exports, sharedUtil) {
  24291. var assert = sharedUtil.assert;
  24292. var bytesToString = sharedUtil.bytesToString;
  24293. var string32 = sharedUtil.string32;
  24294. var shadow = sharedUtil.shadow;
  24295. var warn = sharedUtil.warn;
  24296. function FontLoader(docId) {
  24297. this.docId = docId;
  24298. this.styleElement = null;
  24299. this.nativeFontFaces = [];
  24300. this.loadTestFontId = 0;
  24301. this.loadingContext = {
  24302. requests: [],
  24303. nextRequestId: 0
  24304. };
  24305. }
  24306. FontLoader.prototype = {
  24307. insertRule: function fontLoaderInsertRule(rule) {
  24308. var styleElement = this.styleElement;
  24309. if (!styleElement) {
  24310. styleElement = this.styleElement = document.createElement('style');
  24311. styleElement.id = 'PDFJS_FONT_STYLE_TAG_' + this.docId;
  24312. document.documentElement.getElementsByTagName('head')[0].appendChild(styleElement);
  24313. }
  24314. var styleSheet = styleElement.sheet;
  24315. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  24316. },
  24317. clear: function fontLoaderClear() {
  24318. var styleElement = this.styleElement;
  24319. if (styleElement) {
  24320. styleElement.parentNode.removeChild(styleElement);
  24321. styleElement = this.styleElement = null;
  24322. }
  24323. this.nativeFontFaces.forEach(function (nativeFontFace) {
  24324. document.fonts.delete(nativeFontFace);
  24325. });
  24326. this.nativeFontFaces.length = 0;
  24327. }
  24328. };
  24329. var getLoadTestFont = function () {
  24330. // This is a CFF font with 1 glyph for '.' that fills its entire width and
  24331. // height.
  24332. 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==');
  24333. };
  24334. Object.defineProperty(FontLoader.prototype, 'loadTestFont', {
  24335. get: function () {
  24336. return shadow(this, 'loadTestFont', getLoadTestFont());
  24337. },
  24338. configurable: true
  24339. });
  24340. FontLoader.prototype.addNativeFontFace = function fontLoader_addNativeFontFace(nativeFontFace) {
  24341. this.nativeFontFaces.push(nativeFontFace);
  24342. document.fonts.add(nativeFontFace);
  24343. };
  24344. FontLoader.prototype.bind = function fontLoaderBind(fonts, callback) {
  24345. var rules = [];
  24346. var fontsToLoad = [];
  24347. var fontLoadPromises = [];
  24348. var getNativeFontPromise = function (nativeFontFace) {
  24349. // Return a promise that is always fulfilled, even when the font fails to
  24350. // load.
  24351. return nativeFontFace.loaded.catch(function (e) {
  24352. warn('Failed to load font "' + nativeFontFace.family + '": ' + e);
  24353. });
  24354. };
  24355. // Firefox Font Loading API does not work with mozPrintCallback --
  24356. // disabling it in this case.
  24357. var isFontLoadingAPISupported = FontLoader.isFontLoadingAPISupported && !FontLoader.isSyncFontLoadingSupported;
  24358. for (var i = 0, ii = fonts.length; i < ii; i++) {
  24359. var font = fonts[i];
  24360. // Add the font to the DOM only once or skip if the font
  24361. // is already loaded.
  24362. if (font.attached || font.loading === false) {
  24363. continue;
  24364. }
  24365. font.attached = true;
  24366. if (isFontLoadingAPISupported) {
  24367. var nativeFontFace = font.createNativeFontFace();
  24368. if (nativeFontFace) {
  24369. this.addNativeFontFace(nativeFontFace);
  24370. fontLoadPromises.push(getNativeFontPromise(nativeFontFace));
  24371. }
  24372. } else {
  24373. var rule = font.createFontFaceRule();
  24374. if (rule) {
  24375. this.insertRule(rule);
  24376. rules.push(rule);
  24377. fontsToLoad.push(font);
  24378. }
  24379. }
  24380. }
  24381. var request = this.queueLoadingCallback(callback);
  24382. if (isFontLoadingAPISupported) {
  24383. Promise.all(fontLoadPromises).then(function () {
  24384. request.complete();
  24385. });
  24386. } else if (rules.length > 0 && !FontLoader.isSyncFontLoadingSupported) {
  24387. this.prepareFontLoadEvent(rules, fontsToLoad, request);
  24388. } else {
  24389. request.complete();
  24390. }
  24391. };
  24392. FontLoader.prototype.queueLoadingCallback = function FontLoader_queueLoadingCallback(callback) {
  24393. function LoadLoader_completeRequest() {
  24394. assert(!request.end, 'completeRequest() cannot be called twice');
  24395. request.end = Date.now();
  24396. // sending all completed requests in order how they were queued
  24397. while (context.requests.length > 0 && context.requests[0].end) {
  24398. var otherRequest = context.requests.shift();
  24399. setTimeout(otherRequest.callback, 0);
  24400. }
  24401. }
  24402. var context = this.loadingContext;
  24403. var requestId = 'pdfjs-font-loading-' + context.nextRequestId++;
  24404. var request = {
  24405. id: requestId,
  24406. complete: LoadLoader_completeRequest,
  24407. callback: callback,
  24408. started: Date.now()
  24409. };
  24410. context.requests.push(request);
  24411. return request;
  24412. };
  24413. FontLoader.prototype.prepareFontLoadEvent = function fontLoaderPrepareFontLoadEvent(rules, fonts, request) {
  24414. /** Hack begin */
  24415. // There's currently no event when a font has finished downloading so the
  24416. // following code is a dirty hack to 'guess' when a font is
  24417. // ready. It's assumed fonts are loaded in order, so add a known test
  24418. // font after the desired fonts and then test for the loading of that
  24419. // test font.
  24420. function int32(data, offset) {
  24421. return data.charCodeAt(offset) << 24 | data.charCodeAt(offset + 1) << 16 | data.charCodeAt(offset + 2) << 8 | data.charCodeAt(offset + 3) & 0xff;
  24422. }
  24423. function spliceString(s, offset, remove, insert) {
  24424. var chunk1 = s.substr(0, offset);
  24425. var chunk2 = s.substr(offset + remove);
  24426. return chunk1 + insert + chunk2;
  24427. }
  24428. var i, ii;
  24429. var canvas = document.createElement('canvas');
  24430. canvas.width = 1;
  24431. canvas.height = 1;
  24432. var ctx = canvas.getContext('2d');
  24433. var called = 0;
  24434. function isFontReady(name, callback) {
  24435. called++;
  24436. // With setTimeout clamping this gives the font ~100ms to load.
  24437. if (called > 30) {
  24438. warn('Load test font never loaded.');
  24439. callback();
  24440. return;
  24441. }
  24442. ctx.font = '30px ' + name;
  24443. ctx.fillText('.', 0, 20);
  24444. var imageData = ctx.getImageData(0, 0, 1, 1);
  24445. if (imageData.data[3] > 0) {
  24446. callback();
  24447. return;
  24448. }
  24449. setTimeout(isFontReady.bind(null, name, callback));
  24450. }
  24451. var loadTestFontId = 'lt' + Date.now() + this.loadTestFontId++;
  24452. // Chromium seems to cache fonts based on a hash of the actual font data,
  24453. // so the font must be modified for each load test else it will appear to
  24454. // be loaded already.
  24455. // TODO: This could maybe be made faster by avoiding the btoa of the full
  24456. // font by splitting it in chunks before hand and padding the font id.
  24457. var data = this.loadTestFont;
  24458. var COMMENT_OFFSET = 976;
  24459. // has to be on 4 byte boundary (for checksum)
  24460. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length, loadTestFontId);
  24461. // CFF checksum is important for IE, adjusting it
  24462. var CFF_CHECKSUM_OFFSET = 16;
  24463. var XXXX_VALUE = 0x58585858;
  24464. // the "comment" filled with 'X'
  24465. var checksum = int32(data, CFF_CHECKSUM_OFFSET);
  24466. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  24467. checksum = checksum - XXXX_VALUE + int32(loadTestFontId, i) | 0;
  24468. }
  24469. if (i < loadTestFontId.length) {
  24470. // align to 4 bytes boundary
  24471. checksum = checksum - XXXX_VALUE + int32(loadTestFontId + 'XXX', i) | 0;
  24472. }
  24473. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, string32(checksum));
  24474. var url = 'url(data:font/opentype;base64,' + btoa(data) + ');';
  24475. var rule = '@font-face { font-family:"' + loadTestFontId + '";src:' + url + '}';
  24476. this.insertRule(rule);
  24477. var names = [];
  24478. for (i = 0, ii = fonts.length; i < ii; i++) {
  24479. names.push(fonts[i].loadedName);
  24480. }
  24481. names.push(loadTestFontId);
  24482. var div = document.createElement('div');
  24483. div.setAttribute('style', 'visibility: hidden;' + 'width: 10px; height: 10px;' + 'position: absolute; top: 0px; left: 0px;');
  24484. for (i = 0, ii = names.length; i < ii; ++i) {
  24485. var span = document.createElement('span');
  24486. span.textContent = 'Hi';
  24487. span.style.fontFamily = names[i];
  24488. div.appendChild(span);
  24489. }
  24490. document.body.appendChild(div);
  24491. isFontReady(loadTestFontId, function () {
  24492. document.body.removeChild(div);
  24493. request.complete();
  24494. });
  24495. };
  24496. FontLoader.isFontLoadingAPISupported = typeof document !== 'undefined' && !!document.fonts;
  24497. var isSyncFontLoadingSupported = function isSyncFontLoadingSupported() {
  24498. if (typeof navigator === 'undefined') {
  24499. // node.js - we can pretend sync font loading is supported.
  24500. return true;
  24501. }
  24502. var supported = false;
  24503. // User agent string sniffing is bad, but there is no reliable way to tell
  24504. // if font is fully loaded and ready to be used with canvas.
  24505. var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(navigator.userAgent);
  24506. if (m && m[1] >= 14) {
  24507. supported = true;
  24508. }
  24509. // TODO other browsers
  24510. return supported;
  24511. };
  24512. Object.defineProperty(FontLoader, 'isSyncFontLoadingSupported', {
  24513. get: function () {
  24514. return shadow(FontLoader, 'isSyncFontLoadingSupported', isSyncFontLoadingSupported());
  24515. },
  24516. enumerable: true,
  24517. configurable: true
  24518. });
  24519. var IsEvalSupportedCached = {
  24520. get value() {
  24521. return shadow(this, 'value', sharedUtil.isEvalSupported());
  24522. }
  24523. };
  24524. var FontFaceObject = function FontFaceObjectClosure() {
  24525. function FontFaceObject(translatedData, options) {
  24526. this.compiledGlyphs = Object.create(null);
  24527. // importing translated data
  24528. for (var i in translatedData) {
  24529. this[i] = translatedData[i];
  24530. }
  24531. this.options = options;
  24532. }
  24533. FontFaceObject.prototype = {
  24534. createNativeFontFace: function FontFaceObject_createNativeFontFace() {
  24535. if (!this.data) {
  24536. return null;
  24537. }
  24538. if (this.options.disableFontFace) {
  24539. this.disableFontFace = true;
  24540. return null;
  24541. }
  24542. var nativeFontFace = new FontFace(this.loadedName, this.data, {});
  24543. if (this.options.fontRegistry) {
  24544. this.options.fontRegistry.registerFont(this);
  24545. }
  24546. return nativeFontFace;
  24547. },
  24548. createFontFaceRule: function FontFaceObject_createFontFaceRule() {
  24549. if (!this.data) {
  24550. return null;
  24551. }
  24552. if (this.options.disableFontFace) {
  24553. this.disableFontFace = true;
  24554. return null;
  24555. }
  24556. var data = bytesToString(new Uint8Array(this.data));
  24557. var fontName = this.loadedName;
  24558. // Add the font-face rule to the document
  24559. var url = 'url(data:' + this.mimetype + ';base64,' + btoa(data) + ');';
  24560. var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
  24561. if (this.options.fontRegistry) {
  24562. this.options.fontRegistry.registerFont(this, url);
  24563. }
  24564. return rule;
  24565. },
  24566. getPathGenerator: function FontFaceObject_getPathGenerator(objs, character) {
  24567. if (!(character in this.compiledGlyphs)) {
  24568. var cmds = objs.get(this.loadedName + '_path_' + character);
  24569. var current, i, len;
  24570. // If we can, compile cmds into JS for MAXIMUM SPEED
  24571. if (this.options.isEvalSupported && IsEvalSupportedCached.value) {
  24572. var args, js = '';
  24573. for (i = 0, len = cmds.length; i < len; i++) {
  24574. current = cmds[i];
  24575. if (current.args !== undefined) {
  24576. args = current.args.join(',');
  24577. } else {
  24578. args = '';
  24579. }
  24580. js += 'c.' + current.cmd + '(' + args + ');\n';
  24581. }
  24582. this.compiledGlyphs[character] = new Function('c', 'size', js);
  24583. } else {
  24584. // But fall back on using Function.prototype.apply() if we're
  24585. // blocked from using eval() for whatever reason (like CSP policies)
  24586. this.compiledGlyphs[character] = function (c, size) {
  24587. for (i = 0, len = cmds.length; i < len; i++) {
  24588. current = cmds[i];
  24589. if (current.cmd === 'scale') {
  24590. current.args = [
  24591. size,
  24592. -size
  24593. ];
  24594. }
  24595. c[current.cmd].apply(c, current.args);
  24596. }
  24597. };
  24598. }
  24599. }
  24600. return this.compiledGlyphs[character];
  24601. }
  24602. };
  24603. return FontFaceObject;
  24604. }();
  24605. exports.FontFaceObject = FontFaceObject;
  24606. exports.FontLoader = FontLoader;
  24607. }));
  24608. (function (root, factory) {
  24609. factory(root.pdfjsDisplayMetadata = {}, root.pdfjsSharedUtil);
  24610. }(this, function (exports, sharedUtil) {
  24611. var error = sharedUtil.error;
  24612. function fixMetadata(meta) {
  24613. return meta.replace(/>\\376\\377([^<]+)/g, function (all, codes) {
  24614. var bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g, function (code, d1, d2, d3) {
  24615. return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
  24616. });
  24617. var chars = '';
  24618. for (var i = 0; i < bytes.length; i += 2) {
  24619. var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
  24620. chars += code >= 32 && code < 127 && code !== 60 && code !== 62 && code !== 38 && false ? String.fromCharCode(code) : '&#x' + (0x10000 + code).toString(16).substring(1) + ';';
  24621. }
  24622. return '>' + chars;
  24623. });
  24624. }
  24625. function Metadata(meta) {
  24626. if (typeof meta === 'string') {
  24627. // Ghostscript produces invalid metadata
  24628. meta = fixMetadata(meta);
  24629. var parser = new DOMParser();
  24630. meta = parser.parseFromString(meta, 'application/xml');
  24631. } else if (!(meta instanceof Document)) {
  24632. error('Metadata: Invalid metadata object');
  24633. }
  24634. this.metaDocument = meta;
  24635. this.metadata = Object.create(null);
  24636. this.parse();
  24637. }
  24638. Metadata.prototype = {
  24639. parse: function Metadata_parse() {
  24640. var doc = this.metaDocument;
  24641. var rdf = doc.documentElement;
  24642. if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  24643. // Wrapped in <xmpmeta>
  24644. rdf = rdf.firstChild;
  24645. while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  24646. rdf = rdf.nextSibling;
  24647. }
  24648. }
  24649. var nodeName = rdf ? rdf.nodeName.toLowerCase() : null;
  24650. if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) {
  24651. return;
  24652. }
  24653. var children = rdf.childNodes, desc, entry, name, i, ii, length, iLength;
  24654. for (i = 0, length = children.length; i < length; i++) {
  24655. desc = children[i];
  24656. if (desc.nodeName.toLowerCase() !== 'rdf:description') {
  24657. continue;
  24658. }
  24659. for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
  24660. if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') {
  24661. entry = desc.childNodes[ii];
  24662. name = entry.nodeName.toLowerCase();
  24663. this.metadata[name] = entry.textContent.trim();
  24664. }
  24665. }
  24666. }
  24667. },
  24668. get: function Metadata_get(name) {
  24669. return this.metadata[name] || null;
  24670. },
  24671. has: function Metadata_has(name) {
  24672. return typeof this.metadata[name] !== 'undefined';
  24673. }
  24674. };
  24675. exports.Metadata = Metadata;
  24676. }));
  24677. (function (root, factory) {
  24678. factory(root.pdfjsDisplaySVG = {}, root.pdfjsSharedUtil);
  24679. }(this, function (exports, sharedUtil) {
  24680. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  24681. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  24682. var ImageKind = sharedUtil.ImageKind;
  24683. var OPS = sharedUtil.OPS;
  24684. var Util = sharedUtil.Util;
  24685. var isNum = sharedUtil.isNum;
  24686. var isArray = sharedUtil.isArray;
  24687. var warn = sharedUtil.warn;
  24688. var createObjectURL = sharedUtil.createObjectURL;
  24689. var SVG_DEFAULTS = {
  24690. fontStyle: 'normal',
  24691. fontWeight: 'normal',
  24692. fillColor: '#000000'
  24693. };
  24694. var convertImgDataToPng = function convertImgDataToPngClosure() {
  24695. var PNG_HEADER = new Uint8Array([
  24696. 0x89,
  24697. 0x50,
  24698. 0x4e,
  24699. 0x47,
  24700. 0x0d,
  24701. 0x0a,
  24702. 0x1a,
  24703. 0x0a
  24704. ]);
  24705. var CHUNK_WRAPPER_SIZE = 12;
  24706. var crcTable = new Int32Array(256);
  24707. for (var i = 0; i < 256; i++) {
  24708. var c = i;
  24709. for (var h = 0; h < 8; h++) {
  24710. if (c & 1) {
  24711. c = 0xedB88320 ^ c >> 1 & 0x7fffffff;
  24712. } else {
  24713. c = c >> 1 & 0x7fffffff;
  24714. }
  24715. }
  24716. crcTable[i] = c;
  24717. }
  24718. function crc32(data, start, end) {
  24719. var crc = -1;
  24720. for (var i = start; i < end; i++) {
  24721. var a = (crc ^ data[i]) & 0xff;
  24722. var b = crcTable[a];
  24723. crc = crc >>> 8 ^ b;
  24724. }
  24725. return crc ^ -1;
  24726. }
  24727. function writePngChunk(type, body, data, offset) {
  24728. var p = offset;
  24729. var len = body.length;
  24730. data[p] = len >> 24 & 0xff;
  24731. data[p + 1] = len >> 16 & 0xff;
  24732. data[p + 2] = len >> 8 & 0xff;
  24733. data[p + 3] = len & 0xff;
  24734. p += 4;
  24735. data[p] = type.charCodeAt(0) & 0xff;
  24736. data[p + 1] = type.charCodeAt(1) & 0xff;
  24737. data[p + 2] = type.charCodeAt(2) & 0xff;
  24738. data[p + 3] = type.charCodeAt(3) & 0xff;
  24739. p += 4;
  24740. data.set(body, p);
  24741. p += body.length;
  24742. var crc = crc32(data, offset + 4, p);
  24743. data[p] = crc >> 24 & 0xff;
  24744. data[p + 1] = crc >> 16 & 0xff;
  24745. data[p + 2] = crc >> 8 & 0xff;
  24746. data[p + 3] = crc & 0xff;
  24747. }
  24748. function adler32(data, start, end) {
  24749. var a = 1;
  24750. var b = 0;
  24751. for (var i = start; i < end; ++i) {
  24752. a = (a + (data[i] & 0xff)) % 65521;
  24753. b = (b + a) % 65521;
  24754. }
  24755. return b << 16 | a;
  24756. }
  24757. function encode(imgData, kind, forceDataSchema) {
  24758. var width = imgData.width;
  24759. var height = imgData.height;
  24760. var bitDepth, colorType, lineSize;
  24761. var bytes = imgData.data;
  24762. switch (kind) {
  24763. case ImageKind.GRAYSCALE_1BPP:
  24764. colorType = 0;
  24765. bitDepth = 1;
  24766. lineSize = width + 7 >> 3;
  24767. break;
  24768. case ImageKind.RGB_24BPP:
  24769. colorType = 2;
  24770. bitDepth = 8;
  24771. lineSize = width * 3;
  24772. break;
  24773. case ImageKind.RGBA_32BPP:
  24774. colorType = 6;
  24775. bitDepth = 8;
  24776. lineSize = width * 4;
  24777. break;
  24778. default:
  24779. throw new Error('invalid format');
  24780. }
  24781. // prefix every row with predictor 0
  24782. var literals = new Uint8Array((1 + lineSize) * height);
  24783. var offsetLiterals = 0, offsetBytes = 0;
  24784. var y, i;
  24785. for (y = 0; y < height; ++y) {
  24786. literals[offsetLiterals++] = 0;
  24787. // no prediction
  24788. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize), offsetLiterals);
  24789. offsetBytes += lineSize;
  24790. offsetLiterals += lineSize;
  24791. }
  24792. if (kind === ImageKind.GRAYSCALE_1BPP) {
  24793. // inverting for B/W
  24794. offsetLiterals = 0;
  24795. for (y = 0; y < height; y++) {
  24796. offsetLiterals++;
  24797. // skipping predictor
  24798. for (i = 0; i < lineSize; i++) {
  24799. literals[offsetLiterals++] ^= 0xFF;
  24800. }
  24801. }
  24802. }
  24803. var ihdr = new Uint8Array([
  24804. width >> 24 & 0xff,
  24805. width >> 16 & 0xff,
  24806. width >> 8 & 0xff,
  24807. width & 0xff,
  24808. height >> 24 & 0xff,
  24809. height >> 16 & 0xff,
  24810. height >> 8 & 0xff,
  24811. height & 0xff,
  24812. bitDepth,
  24813. // bit depth
  24814. colorType,
  24815. // color type
  24816. 0x00,
  24817. // compression method
  24818. 0x00,
  24819. // filter method
  24820. 0x00
  24821. ]);
  24822. // interlace method
  24823. var len = literals.length;
  24824. var maxBlockLength = 0xFFFF;
  24825. var deflateBlocks = Math.ceil(len / maxBlockLength);
  24826. var idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  24827. var pi = 0;
  24828. idat[pi++] = 0x78;
  24829. // compression method and flags
  24830. idat[pi++] = 0x9c;
  24831. // flags
  24832. var pos = 0;
  24833. while (len > maxBlockLength) {
  24834. // writing non-final DEFLATE blocks type 0 and length of 65535
  24835. idat[pi++] = 0x00;
  24836. idat[pi++] = 0xff;
  24837. idat[pi++] = 0xff;
  24838. idat[pi++] = 0x00;
  24839. idat[pi++] = 0x00;
  24840. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  24841. pi += maxBlockLength;
  24842. pos += maxBlockLength;
  24843. len -= maxBlockLength;
  24844. }
  24845. // writing non-final DEFLATE blocks type 0
  24846. idat[pi++] = 0x01;
  24847. idat[pi++] = len & 0xff;
  24848. idat[pi++] = len >> 8 & 0xff;
  24849. idat[pi++] = ~len & 0xffff & 0xff;
  24850. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  24851. idat.set(literals.subarray(pos), pi);
  24852. pi += literals.length - pos;
  24853. var adler = adler32(literals, 0, literals.length);
  24854. // checksum
  24855. idat[pi++] = adler >> 24 & 0xff;
  24856. idat[pi++] = adler >> 16 & 0xff;
  24857. idat[pi++] = adler >> 8 & 0xff;
  24858. idat[pi++] = adler & 0xff;
  24859. // PNG will consists: header, IHDR+data, IDAT+data, and IEND.
  24860. var pngLength = PNG_HEADER.length + CHUNK_WRAPPER_SIZE * 3 + ihdr.length + idat.length;
  24861. var data = new Uint8Array(pngLength);
  24862. var offset = 0;
  24863. data.set(PNG_HEADER, offset);
  24864. offset += PNG_HEADER.length;
  24865. writePngChunk('IHDR', ihdr, data, offset);
  24866. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  24867. writePngChunk('IDATA', idat, data, offset);
  24868. offset += CHUNK_WRAPPER_SIZE + idat.length;
  24869. writePngChunk('IEND', new Uint8Array(0), data, offset);
  24870. return createObjectURL(data, 'image/png', forceDataSchema);
  24871. }
  24872. return function convertImgDataToPng(imgData, forceDataSchema) {
  24873. var kind = imgData.kind === undefined ? ImageKind.GRAYSCALE_1BPP : imgData.kind;
  24874. return encode(imgData, kind, forceDataSchema);
  24875. };
  24876. }();
  24877. var SVGExtraState = function SVGExtraStateClosure() {
  24878. function SVGExtraState() {
  24879. this.fontSizeScale = 1;
  24880. this.fontWeight = SVG_DEFAULTS.fontWeight;
  24881. this.fontSize = 0;
  24882. this.textMatrix = IDENTITY_MATRIX;
  24883. this.fontMatrix = FONT_IDENTITY_MATRIX;
  24884. this.leading = 0;
  24885. // Current point (in user coordinates)
  24886. this.x = 0;
  24887. this.y = 0;
  24888. // Start of text line (in text coordinates)
  24889. this.lineX = 0;
  24890. this.lineY = 0;
  24891. // Character and word spacing
  24892. this.charSpacing = 0;
  24893. this.wordSpacing = 0;
  24894. this.textHScale = 1;
  24895. this.textRise = 0;
  24896. // Default foreground and background colors
  24897. this.fillColor = SVG_DEFAULTS.fillColor;
  24898. this.strokeColor = '#000000';
  24899. this.fillAlpha = 1;
  24900. this.strokeAlpha = 1;
  24901. this.lineWidth = 1;
  24902. this.lineJoin = '';
  24903. this.lineCap = '';
  24904. this.miterLimit = 0;
  24905. this.dashArray = [];
  24906. this.dashPhase = 0;
  24907. this.dependencies = [];
  24908. // Clipping
  24909. this.activeClipUrl = null;
  24910. this.clipGroup = null;
  24911. this.maskId = '';
  24912. }
  24913. SVGExtraState.prototype = {
  24914. clone: function SVGExtraState_clone() {
  24915. return Object.create(this);
  24916. },
  24917. setCurrentPoint: function SVGExtraState_setCurrentPoint(x, y) {
  24918. this.x = x;
  24919. this.y = y;
  24920. }
  24921. };
  24922. return SVGExtraState;
  24923. }();
  24924. var SVGGraphics = function SVGGraphicsClosure() {
  24925. function opListToTree(opList) {
  24926. var opTree = [];
  24927. var tmp = [];
  24928. var opListLen = opList.length;
  24929. for (var x = 0; x < opListLen; x++) {
  24930. if (opList[x].fn === 'save') {
  24931. opTree.push({
  24932. 'fnId': 92,
  24933. 'fn': 'group',
  24934. 'items': []
  24935. });
  24936. tmp.push(opTree);
  24937. opTree = opTree[opTree.length - 1].items;
  24938. continue;
  24939. }
  24940. if (opList[x].fn === 'restore') {
  24941. opTree = tmp.pop();
  24942. } else {
  24943. opTree.push(opList[x]);
  24944. }
  24945. }
  24946. return opTree;
  24947. }
  24948. /**
  24949. * Formats float number.
  24950. * @param value {number} number to format.
  24951. * @returns {string}
  24952. */
  24953. function pf(value) {
  24954. if (value === (value | 0)) {
  24955. // integer number
  24956. return value.toString();
  24957. }
  24958. var s = value.toFixed(10);
  24959. var i = s.length - 1;
  24960. if (s[i] !== '0') {
  24961. return s;
  24962. }
  24963. // removing trailing zeros
  24964. do {
  24965. i--;
  24966. } while (s[i] === '0');
  24967. return s.substr(0, s[i] === '.' ? i : i + 1);
  24968. }
  24969. /**
  24970. * Formats transform matrix. The standard rotation, scale and translate
  24971. * matrices are replaced by their shorter forms, and for identity matrix
  24972. * returns empty string to save the memory.
  24973. * @param m {Array} matrix to format.
  24974. * @returns {string}
  24975. */
  24976. function pm(m) {
  24977. if (m[4] === 0 && m[5] === 0) {
  24978. if (m[1] === 0 && m[2] === 0) {
  24979. if (m[0] === 1 && m[3] === 1) {
  24980. return '';
  24981. }
  24982. return 'scale(' + pf(m[0]) + ' ' + pf(m[3]) + ')';
  24983. }
  24984. if (m[0] === m[3] && m[1] === -m[2]) {
  24985. var a = Math.acos(m[0]) * 180 / Math.PI;
  24986. return 'rotate(' + pf(a) + ')';
  24987. }
  24988. } else {
  24989. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  24990. return 'translate(' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  24991. }
  24992. }
  24993. return 'matrix(' + pf(m[0]) + ' ' + pf(m[1]) + ' ' + pf(m[2]) + ' ' + pf(m[3]) + ' ' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  24994. }
  24995. function SVGGraphics(commonObjs, objs, forceDataSchema) {
  24996. this.current = new SVGExtraState();
  24997. this.transformMatrix = IDENTITY_MATRIX;
  24998. // Graphics state matrix
  24999. this.transformStack = [];
  25000. this.extraStack = [];
  25001. this.commonObjs = commonObjs;
  25002. this.objs = objs;
  25003. this.pendingEOFill = false;
  25004. this.embedFonts = false;
  25005. this.embeddedFonts = Object.create(null);
  25006. this.cssStyle = null;
  25007. this.forceDataSchema = !!forceDataSchema;
  25008. }
  25009. var NS = 'http://www.w3.org/2000/svg';
  25010. var XML_NS = 'http://www.w3.org/XML/1998/namespace';
  25011. var XLINK_NS = 'http://www.w3.org/1999/xlink';
  25012. var LINE_CAP_STYLES = [
  25013. 'butt',
  25014. 'round',
  25015. 'square'
  25016. ];
  25017. var LINE_JOIN_STYLES = [
  25018. 'miter',
  25019. 'round',
  25020. 'bevel'
  25021. ];
  25022. var clipCount = 0;
  25023. var maskCount = 0;
  25024. SVGGraphics.prototype = {
  25025. save: function SVGGraphics_save() {
  25026. this.transformStack.push(this.transformMatrix);
  25027. var old = this.current;
  25028. this.extraStack.push(old);
  25029. this.current = old.clone();
  25030. },
  25031. restore: function SVGGraphics_restore() {
  25032. this.transformMatrix = this.transformStack.pop();
  25033. this.current = this.extraStack.pop();
  25034. this.tgrp = null;
  25035. },
  25036. group: function SVGGraphics_group(items) {
  25037. this.save();
  25038. this.executeOpTree(items);
  25039. this.restore();
  25040. },
  25041. loadDependencies: function SVGGraphics_loadDependencies(operatorList) {
  25042. var fnArray = operatorList.fnArray;
  25043. var fnArrayLen = fnArray.length;
  25044. var argsArray = operatorList.argsArray;
  25045. var self = this;
  25046. for (var i = 0; i < fnArrayLen; i++) {
  25047. if (OPS.dependency === fnArray[i]) {
  25048. var deps = argsArray[i];
  25049. for (var n = 0, nn = deps.length; n < nn; n++) {
  25050. var obj = deps[n];
  25051. var common = obj.substring(0, 2) === 'g_';
  25052. var promise;
  25053. if (common) {
  25054. promise = new Promise(function (resolve) {
  25055. self.commonObjs.get(obj, resolve);
  25056. });
  25057. } else {
  25058. promise = new Promise(function (resolve) {
  25059. self.objs.get(obj, resolve);
  25060. });
  25061. }
  25062. this.current.dependencies.push(promise);
  25063. }
  25064. }
  25065. }
  25066. return Promise.all(this.current.dependencies);
  25067. },
  25068. transform: function SVGGraphics_transform(a, b, c, d, e, f) {
  25069. var transformMatrix = [
  25070. a,
  25071. b,
  25072. c,
  25073. d,
  25074. e,
  25075. f
  25076. ];
  25077. this.transformMatrix = Util.transform(this.transformMatrix, transformMatrix);
  25078. this.tgrp = null;
  25079. },
  25080. getSVG: function SVGGraphics_getSVG(operatorList, viewport) {
  25081. this.viewport = viewport;
  25082. var svgElement = this._initialize(viewport);
  25083. return this.loadDependencies(operatorList).then(function () {
  25084. this.transformMatrix = IDENTITY_MATRIX;
  25085. var opTree = this.convertOpList(operatorList);
  25086. this.executeOpTree(opTree);
  25087. return svgElement;
  25088. }.bind(this));
  25089. },
  25090. convertOpList: function SVGGraphics_convertOpList(operatorList) {
  25091. var argsArray = operatorList.argsArray;
  25092. var fnArray = operatorList.fnArray;
  25093. var fnArrayLen = fnArray.length;
  25094. var REVOPS = [];
  25095. var opList = [];
  25096. for (var op in OPS) {
  25097. REVOPS[OPS[op]] = op;
  25098. }
  25099. for (var x = 0; x < fnArrayLen; x++) {
  25100. var fnId = fnArray[x];
  25101. opList.push({
  25102. 'fnId': fnId,
  25103. 'fn': REVOPS[fnId],
  25104. 'args': argsArray[x]
  25105. });
  25106. }
  25107. return opListToTree(opList);
  25108. },
  25109. executeOpTree: function SVGGraphics_executeOpTree(opTree) {
  25110. var opTreeLen = opTree.length;
  25111. for (var x = 0; x < opTreeLen; x++) {
  25112. var fn = opTree[x].fn;
  25113. var fnId = opTree[x].fnId;
  25114. var args = opTree[x].args;
  25115. switch (fnId | 0) {
  25116. case OPS.beginText:
  25117. this.beginText();
  25118. break;
  25119. case OPS.setLeading:
  25120. this.setLeading(args);
  25121. break;
  25122. case OPS.setLeadingMoveText:
  25123. this.setLeadingMoveText(args[0], args[1]);
  25124. break;
  25125. case OPS.setFont:
  25126. this.setFont(args);
  25127. break;
  25128. case OPS.showText:
  25129. this.showText(args[0]);
  25130. break;
  25131. case OPS.showSpacedText:
  25132. this.showText(args[0]);
  25133. break;
  25134. case OPS.endText:
  25135. this.endText();
  25136. break;
  25137. case OPS.moveText:
  25138. this.moveText(args[0], args[1]);
  25139. break;
  25140. case OPS.setCharSpacing:
  25141. this.setCharSpacing(args[0]);
  25142. break;
  25143. case OPS.setWordSpacing:
  25144. this.setWordSpacing(args[0]);
  25145. break;
  25146. case OPS.setHScale:
  25147. this.setHScale(args[0]);
  25148. break;
  25149. case OPS.setTextMatrix:
  25150. this.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
  25151. break;
  25152. case OPS.setLineWidth:
  25153. this.setLineWidth(args[0]);
  25154. break;
  25155. case OPS.setLineJoin:
  25156. this.setLineJoin(args[0]);
  25157. break;
  25158. case OPS.setLineCap:
  25159. this.setLineCap(args[0]);
  25160. break;
  25161. case OPS.setMiterLimit:
  25162. this.setMiterLimit(args[0]);
  25163. break;
  25164. case OPS.setFillRGBColor:
  25165. this.setFillRGBColor(args[0], args[1], args[2]);
  25166. break;
  25167. case OPS.setStrokeRGBColor:
  25168. this.setStrokeRGBColor(args[0], args[1], args[2]);
  25169. break;
  25170. case OPS.setDash:
  25171. this.setDash(args[0], args[1]);
  25172. break;
  25173. case OPS.setGState:
  25174. this.setGState(args[0]);
  25175. break;
  25176. case OPS.fill:
  25177. this.fill();
  25178. break;
  25179. case OPS.eoFill:
  25180. this.eoFill();
  25181. break;
  25182. case OPS.stroke:
  25183. this.stroke();
  25184. break;
  25185. case OPS.fillStroke:
  25186. this.fillStroke();
  25187. break;
  25188. case OPS.eoFillStroke:
  25189. this.eoFillStroke();
  25190. break;
  25191. case OPS.clip:
  25192. this.clip('nonzero');
  25193. break;
  25194. case OPS.eoClip:
  25195. this.clip('evenodd');
  25196. break;
  25197. case OPS.paintSolidColorImageMask:
  25198. this.paintSolidColorImageMask();
  25199. break;
  25200. case OPS.paintJpegXObject:
  25201. this.paintJpegXObject(args[0], args[1], args[2]);
  25202. break;
  25203. case OPS.paintImageXObject:
  25204. this.paintImageXObject(args[0]);
  25205. break;
  25206. case OPS.paintInlineImageXObject:
  25207. this.paintInlineImageXObject(args[0]);
  25208. break;
  25209. case OPS.paintImageMaskXObject:
  25210. this.paintImageMaskXObject(args[0]);
  25211. break;
  25212. case OPS.paintFormXObjectBegin:
  25213. this.paintFormXObjectBegin(args[0], args[1]);
  25214. break;
  25215. case OPS.paintFormXObjectEnd:
  25216. this.paintFormXObjectEnd();
  25217. break;
  25218. case OPS.closePath:
  25219. this.closePath();
  25220. break;
  25221. case OPS.closeStroke:
  25222. this.closeStroke();
  25223. break;
  25224. case OPS.closeFillStroke:
  25225. this.closeFillStroke();
  25226. break;
  25227. case OPS.nextLine:
  25228. this.nextLine();
  25229. break;
  25230. case OPS.transform:
  25231. this.transform(args[0], args[1], args[2], args[3], args[4], args[5]);
  25232. break;
  25233. case OPS.constructPath:
  25234. this.constructPath(args[0], args[1]);
  25235. break;
  25236. case OPS.endPath:
  25237. this.endPath();
  25238. break;
  25239. case 92:
  25240. this.group(opTree[x].items);
  25241. break;
  25242. default:
  25243. warn('Unimplemented operator ' + fn);
  25244. break;
  25245. }
  25246. }
  25247. },
  25248. setWordSpacing: function SVGGraphics_setWordSpacing(wordSpacing) {
  25249. this.current.wordSpacing = wordSpacing;
  25250. },
  25251. setCharSpacing: function SVGGraphics_setCharSpacing(charSpacing) {
  25252. this.current.charSpacing = charSpacing;
  25253. },
  25254. nextLine: function SVGGraphics_nextLine() {
  25255. this.moveText(0, this.current.leading);
  25256. },
  25257. setTextMatrix: function SVGGraphics_setTextMatrix(a, b, c, d, e, f) {
  25258. var current = this.current;
  25259. this.current.textMatrix = this.current.lineMatrix = [
  25260. a,
  25261. b,
  25262. c,
  25263. d,
  25264. e,
  25265. f
  25266. ];
  25267. this.current.x = this.current.lineX = 0;
  25268. this.current.y = this.current.lineY = 0;
  25269. current.xcoords = [];
  25270. current.tspan = document.createElementNS(NS, 'svg:tspan');
  25271. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  25272. current.tspan.setAttributeNS(null, 'font-size', pf(current.fontSize) + 'px');
  25273. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  25274. current.txtElement = document.createElementNS(NS, 'svg:text');
  25275. current.txtElement.appendChild(current.tspan);
  25276. },
  25277. beginText: function SVGGraphics_beginText() {
  25278. this.current.x = this.current.lineX = 0;
  25279. this.current.y = this.current.lineY = 0;
  25280. this.current.textMatrix = IDENTITY_MATRIX;
  25281. this.current.lineMatrix = IDENTITY_MATRIX;
  25282. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  25283. this.current.txtElement = document.createElementNS(NS, 'svg:text');
  25284. this.current.txtgrp = document.createElementNS(NS, 'svg:g');
  25285. this.current.xcoords = [];
  25286. },
  25287. moveText: function SVGGraphics_moveText(x, y) {
  25288. var current = this.current;
  25289. this.current.x = this.current.lineX += x;
  25290. this.current.y = this.current.lineY += y;
  25291. current.xcoords = [];
  25292. current.tspan = document.createElementNS(NS, 'svg:tspan');
  25293. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  25294. current.tspan.setAttributeNS(null, 'font-size', pf(current.fontSize) + 'px');
  25295. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  25296. },
  25297. showText: function SVGGraphics_showText(glyphs) {
  25298. var current = this.current;
  25299. var font = current.font;
  25300. var fontSize = current.fontSize;
  25301. if (fontSize === 0) {
  25302. return;
  25303. }
  25304. var charSpacing = current.charSpacing;
  25305. var wordSpacing = current.wordSpacing;
  25306. var fontDirection = current.fontDirection;
  25307. var textHScale = current.textHScale * fontDirection;
  25308. var glyphsLength = glyphs.length;
  25309. var vertical = font.vertical;
  25310. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  25311. var x = 0, i;
  25312. for (i = 0; i < glyphsLength; ++i) {
  25313. var glyph = glyphs[i];
  25314. if (glyph === null) {
  25315. // word break
  25316. x += fontDirection * wordSpacing;
  25317. continue;
  25318. } else if (isNum(glyph)) {
  25319. x += -glyph * fontSize * 0.001;
  25320. continue;
  25321. }
  25322. current.xcoords.push(current.x + x * textHScale);
  25323. var width = glyph.width;
  25324. var character = glyph.fontChar;
  25325. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  25326. x += charWidth;
  25327. current.tspan.textContent += character;
  25328. }
  25329. if (vertical) {
  25330. current.y -= x * textHScale;
  25331. } else {
  25332. current.x += x * textHScale;
  25333. }
  25334. current.tspan.setAttributeNS(null, 'x', current.xcoords.map(pf).join(' '));
  25335. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  25336. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  25337. current.tspan.setAttributeNS(null, 'font-size', pf(current.fontSize) + 'px');
  25338. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  25339. current.tspan.setAttributeNS(null, 'font-style', current.fontStyle);
  25340. }
  25341. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  25342. current.tspan.setAttributeNS(null, 'font-weight', current.fontWeight);
  25343. }
  25344. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  25345. current.tspan.setAttributeNS(null, 'fill', current.fillColor);
  25346. }
  25347. current.txtElement.setAttributeNS(null, 'transform', pm(current.textMatrix) + ' scale(1, -1)');
  25348. current.txtElement.setAttributeNS(XML_NS, 'xml:space', 'preserve');
  25349. current.txtElement.appendChild(current.tspan);
  25350. current.txtgrp.appendChild(current.txtElement);
  25351. this._ensureTransformGroup().appendChild(current.txtElement);
  25352. },
  25353. setLeadingMoveText: function SVGGraphics_setLeadingMoveText(x, y) {
  25354. this.setLeading(-y);
  25355. this.moveText(x, y);
  25356. },
  25357. addFontStyle: function SVGGraphics_addFontStyle(fontObj) {
  25358. if (!this.cssStyle) {
  25359. this.cssStyle = document.createElementNS(NS, 'svg:style');
  25360. this.cssStyle.setAttributeNS(null, 'type', 'text/css');
  25361. this.defs.appendChild(this.cssStyle);
  25362. }
  25363. var url = createObjectURL(fontObj.data, fontObj.mimetype, this.forceDataSchema);
  25364. this.cssStyle.textContent += '@font-face { font-family: "' + fontObj.loadedName + '";' + ' src: url(' + url + '); }\n';
  25365. },
  25366. setFont: function SVGGraphics_setFont(details) {
  25367. var current = this.current;
  25368. var fontObj = this.commonObjs.get(details[0]);
  25369. var size = details[1];
  25370. this.current.font = fontObj;
  25371. if (this.embedFonts && fontObj.data && !this.embeddedFonts[fontObj.loadedName]) {
  25372. this.addFontStyle(fontObj);
  25373. this.embeddedFonts[fontObj.loadedName] = fontObj;
  25374. }
  25375. current.fontMatrix = fontObj.fontMatrix ? fontObj.fontMatrix : FONT_IDENTITY_MATRIX;
  25376. var bold = fontObj.black ? fontObj.bold ? 'bolder' : 'bold' : fontObj.bold ? 'bold' : 'normal';
  25377. var italic = fontObj.italic ? 'italic' : 'normal';
  25378. if (size < 0) {
  25379. size = -size;
  25380. current.fontDirection = -1;
  25381. } else {
  25382. current.fontDirection = 1;
  25383. }
  25384. current.fontSize = size;
  25385. current.fontFamily = fontObj.loadedName;
  25386. current.fontWeight = bold;
  25387. current.fontStyle = italic;
  25388. current.tspan = document.createElementNS(NS, 'svg:tspan');
  25389. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  25390. current.xcoords = [];
  25391. },
  25392. endText: function SVGGraphics_endText() {
  25393. },
  25394. // Path properties
  25395. setLineWidth: function SVGGraphics_setLineWidth(width) {
  25396. this.current.lineWidth = width;
  25397. },
  25398. setLineCap: function SVGGraphics_setLineCap(style) {
  25399. this.current.lineCap = LINE_CAP_STYLES[style];
  25400. },
  25401. setLineJoin: function SVGGraphics_setLineJoin(style) {
  25402. this.current.lineJoin = LINE_JOIN_STYLES[style];
  25403. },
  25404. setMiterLimit: function SVGGraphics_setMiterLimit(limit) {
  25405. this.current.miterLimit = limit;
  25406. },
  25407. setStrokeRGBColor: function SVGGraphics_setStrokeRGBColor(r, g, b) {
  25408. var color = Util.makeCssRgb(r, g, b);
  25409. this.current.strokeColor = color;
  25410. },
  25411. setFillRGBColor: function SVGGraphics_setFillRGBColor(r, g, b) {
  25412. var color = Util.makeCssRgb(r, g, b);
  25413. this.current.fillColor = color;
  25414. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  25415. this.current.xcoords = [];
  25416. },
  25417. setDash: function SVGGraphics_setDash(dashArray, dashPhase) {
  25418. this.current.dashArray = dashArray;
  25419. this.current.dashPhase = dashPhase;
  25420. },
  25421. constructPath: function SVGGraphics_constructPath(ops, args) {
  25422. var current = this.current;
  25423. var x = current.x, y = current.y;
  25424. current.path = document.createElementNS(NS, 'svg:path');
  25425. var d = [];
  25426. var opLength = ops.length;
  25427. for (var i = 0, j = 0; i < opLength; i++) {
  25428. switch (ops[i] | 0) {
  25429. case OPS.rectangle:
  25430. x = args[j++];
  25431. y = args[j++];
  25432. var width = args[j++];
  25433. var height = args[j++];
  25434. var xw = x + width;
  25435. var yh = y + height;
  25436. d.push('M', pf(x), pf(y), 'L', pf(xw), pf(y), 'L', pf(xw), pf(yh), 'L', pf(x), pf(yh), 'Z');
  25437. break;
  25438. case OPS.moveTo:
  25439. x = args[j++];
  25440. y = args[j++];
  25441. d.push('M', pf(x), pf(y));
  25442. break;
  25443. case OPS.lineTo:
  25444. x = args[j++];
  25445. y = args[j++];
  25446. d.push('L', pf(x), pf(y));
  25447. break;
  25448. case OPS.curveTo:
  25449. x = args[j + 4];
  25450. y = args[j + 5];
  25451. d.push('C', pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]), pf(x), pf(y));
  25452. j += 6;
  25453. break;
  25454. case OPS.curveTo2:
  25455. x = args[j + 2];
  25456. y = args[j + 3];
  25457. d.push('C', pf(x), pf(y), pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]));
  25458. j += 4;
  25459. break;
  25460. case OPS.curveTo3:
  25461. x = args[j + 2];
  25462. y = args[j + 3];
  25463. d.push('C', pf(args[j]), pf(args[j + 1]), pf(x), pf(y), pf(x), pf(y));
  25464. j += 4;
  25465. break;
  25466. case OPS.closePath:
  25467. d.push('Z');
  25468. break;
  25469. }
  25470. }
  25471. current.path.setAttributeNS(null, 'd', d.join(' '));
  25472. current.path.setAttributeNS(null, 'stroke-miterlimit', pf(current.miterLimit));
  25473. current.path.setAttributeNS(null, 'stroke-linecap', current.lineCap);
  25474. current.path.setAttributeNS(null, 'stroke-linejoin', current.lineJoin);
  25475. current.path.setAttributeNS(null, 'stroke-width', pf(current.lineWidth) + 'px');
  25476. current.path.setAttributeNS(null, 'stroke-dasharray', current.dashArray.map(pf).join(' '));
  25477. current.path.setAttributeNS(null, 'stroke-dashoffset', pf(current.dashPhase) + 'px');
  25478. current.path.setAttributeNS(null, 'fill', 'none');
  25479. this._ensureTransformGroup().appendChild(current.path);
  25480. // Saving a reference in current.element so that it can be addressed
  25481. // in 'fill' and 'stroke'
  25482. current.element = current.path;
  25483. current.setCurrentPoint(x, y);
  25484. },
  25485. endPath: function SVGGraphics_endPath() {
  25486. },
  25487. clip: function SVGGraphics_clip(type) {
  25488. var current = this.current;
  25489. // Add current path to clipping path
  25490. var clipId = 'clippath' + clipCount;
  25491. clipCount++;
  25492. var clipPath = document.createElementNS(NS, 'svg:clipPath');
  25493. clipPath.setAttributeNS(null, 'id', clipId);
  25494. clipPath.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  25495. var clipElement = current.element.cloneNode();
  25496. if (type === 'evenodd') {
  25497. clipElement.setAttributeNS(null, 'clip-rule', 'evenodd');
  25498. } else {
  25499. clipElement.setAttributeNS(null, 'clip-rule', 'nonzero');
  25500. }
  25501. clipPath.appendChild(clipElement);
  25502. this.defs.appendChild(clipPath);
  25503. if (current.activeClipUrl) {
  25504. // The previous clipping group content can go out of order -- resetting
  25505. // cached clipGroup's.
  25506. current.clipGroup = null;
  25507. this.extraStack.forEach(function (prev) {
  25508. prev.clipGroup = null;
  25509. });
  25510. }
  25511. current.activeClipUrl = 'url(#' + clipId + ')';
  25512. this.tgrp = null;
  25513. },
  25514. closePath: function SVGGraphics_closePath() {
  25515. var current = this.current;
  25516. var d = current.path.getAttributeNS(null, 'd');
  25517. d += 'Z';
  25518. current.path.setAttributeNS(null, 'd', d);
  25519. },
  25520. setLeading: function SVGGraphics_setLeading(leading) {
  25521. this.current.leading = -leading;
  25522. },
  25523. setTextRise: function SVGGraphics_setTextRise(textRise) {
  25524. this.current.textRise = textRise;
  25525. },
  25526. setHScale: function SVGGraphics_setHScale(scale) {
  25527. this.current.textHScale = scale / 100;
  25528. },
  25529. setGState: function SVGGraphics_setGState(states) {
  25530. for (var i = 0, ii = states.length; i < ii; i++) {
  25531. var state = states[i];
  25532. var key = state[0];
  25533. var value = state[1];
  25534. switch (key) {
  25535. case 'LW':
  25536. this.setLineWidth(value);
  25537. break;
  25538. case 'LC':
  25539. this.setLineCap(value);
  25540. break;
  25541. case 'LJ':
  25542. this.setLineJoin(value);
  25543. break;
  25544. case 'ML':
  25545. this.setMiterLimit(value);
  25546. break;
  25547. case 'D':
  25548. this.setDash(value[0], value[1]);
  25549. break;
  25550. case 'Font':
  25551. this.setFont(value);
  25552. break;
  25553. default:
  25554. warn('Unimplemented graphic state ' + key);
  25555. break;
  25556. }
  25557. }
  25558. },
  25559. fill: function SVGGraphics_fill() {
  25560. var current = this.current;
  25561. current.element.setAttributeNS(null, 'fill', current.fillColor);
  25562. },
  25563. stroke: function SVGGraphics_stroke() {
  25564. var current = this.current;
  25565. current.element.setAttributeNS(null, 'stroke', current.strokeColor);
  25566. current.element.setAttributeNS(null, 'fill', 'none');
  25567. },
  25568. eoFill: function SVGGraphics_eoFill() {
  25569. var current = this.current;
  25570. current.element.setAttributeNS(null, 'fill', current.fillColor);
  25571. current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  25572. },
  25573. fillStroke: function SVGGraphics_fillStroke() {
  25574. // Order is important since stroke wants fill to be none.
  25575. // First stroke, then if fill needed, it will be overwritten.
  25576. this.stroke();
  25577. this.fill();
  25578. },
  25579. eoFillStroke: function SVGGraphics_eoFillStroke() {
  25580. this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  25581. this.fillStroke();
  25582. },
  25583. closeStroke: function SVGGraphics_closeStroke() {
  25584. this.closePath();
  25585. this.stroke();
  25586. },
  25587. closeFillStroke: function SVGGraphics_closeFillStroke() {
  25588. this.closePath();
  25589. this.fillStroke();
  25590. },
  25591. paintSolidColorImageMask: function SVGGraphics_paintSolidColorImageMask() {
  25592. var current = this.current;
  25593. var rect = document.createElementNS(NS, 'svg:rect');
  25594. rect.setAttributeNS(null, 'x', '0');
  25595. rect.setAttributeNS(null, 'y', '0');
  25596. rect.setAttributeNS(null, 'width', '1px');
  25597. rect.setAttributeNS(null, 'height', '1px');
  25598. rect.setAttributeNS(null, 'fill', current.fillColor);
  25599. this._ensureTransformGroup().appendChild(rect);
  25600. },
  25601. paintJpegXObject: function SVGGraphics_paintJpegXObject(objId, w, h) {
  25602. var imgObj = this.objs.get(objId);
  25603. var imgEl = document.createElementNS(NS, 'svg:image');
  25604. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgObj.src);
  25605. imgEl.setAttributeNS(null, 'width', imgObj.width + 'px');
  25606. imgEl.setAttributeNS(null, 'height', imgObj.height + 'px');
  25607. imgEl.setAttributeNS(null, 'x', '0');
  25608. imgEl.setAttributeNS(null, 'y', pf(-h));
  25609. imgEl.setAttributeNS(null, 'transform', 'scale(' + pf(1 / w) + ' ' + pf(-1 / h) + ')');
  25610. this._ensureTransformGroup().appendChild(imgEl);
  25611. },
  25612. paintImageXObject: function SVGGraphics_paintImageXObject(objId) {
  25613. var imgData = this.objs.get(objId);
  25614. if (!imgData) {
  25615. warn('Dependent image isn\'t ready yet');
  25616. return;
  25617. }
  25618. this.paintInlineImageXObject(imgData);
  25619. },
  25620. paintInlineImageXObject: function SVGGraphics_paintInlineImageXObject(imgData, mask) {
  25621. var width = imgData.width;
  25622. var height = imgData.height;
  25623. var imgSrc = convertImgDataToPng(imgData, this.forceDataSchema);
  25624. var cliprect = document.createElementNS(NS, 'svg:rect');
  25625. cliprect.setAttributeNS(null, 'x', '0');
  25626. cliprect.setAttributeNS(null, 'y', '0');
  25627. cliprect.setAttributeNS(null, 'width', pf(width));
  25628. cliprect.setAttributeNS(null, 'height', pf(height));
  25629. this.current.element = cliprect;
  25630. this.clip('nonzero');
  25631. var imgEl = document.createElementNS(NS, 'svg:image');
  25632. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgSrc);
  25633. imgEl.setAttributeNS(null, 'x', '0');
  25634. imgEl.setAttributeNS(null, 'y', pf(-height));
  25635. imgEl.setAttributeNS(null, 'width', pf(width) + 'px');
  25636. imgEl.setAttributeNS(null, 'height', pf(height) + 'px');
  25637. imgEl.setAttributeNS(null, 'transform', 'scale(' + pf(1 / width) + ' ' + pf(-1 / height) + ')');
  25638. if (mask) {
  25639. mask.appendChild(imgEl);
  25640. } else {
  25641. this._ensureTransformGroup().appendChild(imgEl);
  25642. }
  25643. },
  25644. paintImageMaskXObject: function SVGGraphics_paintImageMaskXObject(imgData) {
  25645. var current = this.current;
  25646. var width = imgData.width;
  25647. var height = imgData.height;
  25648. var fillColor = current.fillColor;
  25649. current.maskId = 'mask' + maskCount++;
  25650. var mask = document.createElementNS(NS, 'svg:mask');
  25651. mask.setAttributeNS(null, 'id', current.maskId);
  25652. var rect = document.createElementNS(NS, 'svg:rect');
  25653. rect.setAttributeNS(null, 'x', '0');
  25654. rect.setAttributeNS(null, 'y', '0');
  25655. rect.setAttributeNS(null, 'width', pf(width));
  25656. rect.setAttributeNS(null, 'height', pf(height));
  25657. rect.setAttributeNS(null, 'fill', fillColor);
  25658. rect.setAttributeNS(null, 'mask', 'url(#' + current.maskId + ')');
  25659. this.defs.appendChild(mask);
  25660. this._ensureTransformGroup().appendChild(rect);
  25661. this.paintInlineImageXObject(imgData, mask);
  25662. },
  25663. paintFormXObjectBegin: function SVGGraphics_paintFormXObjectBegin(matrix, bbox) {
  25664. if (isArray(matrix) && matrix.length === 6) {
  25665. this.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
  25666. }
  25667. if (isArray(bbox) && bbox.length === 4) {
  25668. var width = bbox[2] - bbox[0];
  25669. var height = bbox[3] - bbox[1];
  25670. var cliprect = document.createElementNS(NS, 'svg:rect');
  25671. cliprect.setAttributeNS(null, 'x', bbox[0]);
  25672. cliprect.setAttributeNS(null, 'y', bbox[1]);
  25673. cliprect.setAttributeNS(null, 'width', pf(width));
  25674. cliprect.setAttributeNS(null, 'height', pf(height));
  25675. this.current.element = cliprect;
  25676. this.clip('nonzero');
  25677. this.endPath();
  25678. }
  25679. },
  25680. paintFormXObjectEnd: function SVGGraphics_paintFormXObjectEnd() {
  25681. },
  25682. /**
  25683. * @private
  25684. */
  25685. _initialize: function SVGGraphics_initialize(viewport) {
  25686. // Create the SVG element.
  25687. var svg = document.createElementNS(NS, 'svg:svg');
  25688. svg.setAttributeNS(null, 'version', '1.1');
  25689. svg.setAttributeNS(null, 'width', viewport.width + 'px');
  25690. svg.setAttributeNS(null, 'height', viewport.height + 'px');
  25691. svg.setAttributeNS(null, 'viewBox', '0 0 ' + viewport.width + ' ' + viewport.height);
  25692. // Create the definitions element.
  25693. var definitions = document.createElementNS(NS, 'svg:defs');
  25694. svg.appendChild(definitions);
  25695. this.defs = definitions;
  25696. // Create the root group element, which acts a container for all other
  25697. // groups and applies the viewport transform.
  25698. var rootGroup = document.createElementNS(NS, 'svg:g');
  25699. rootGroup.setAttributeNS(null, 'transform', pm(viewport.transform));
  25700. svg.appendChild(rootGroup);
  25701. // For the construction of the SVG image we are only interested in the
  25702. // root group, so we expose it as the entry point of the SVG image for
  25703. // the other code in this class.
  25704. this.svg = rootGroup;
  25705. return svg;
  25706. },
  25707. /**
  25708. * @private
  25709. */
  25710. _ensureClipGroup: function SVGGraphics_ensureClipGroup() {
  25711. if (!this.current.clipGroup) {
  25712. var clipGroup = document.createElementNS(NS, 'svg:g');
  25713. clipGroup.setAttributeNS(null, 'clip-path', this.current.activeClipUrl);
  25714. this.svg.appendChild(clipGroup);
  25715. this.current.clipGroup = clipGroup;
  25716. }
  25717. return this.current.clipGroup;
  25718. },
  25719. /**
  25720. * @private
  25721. */
  25722. _ensureTransformGroup: function SVGGraphics_ensureTransformGroup() {
  25723. if (!this.tgrp) {
  25724. this.tgrp = document.createElementNS(NS, 'svg:g');
  25725. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  25726. if (this.current.activeClipUrl) {
  25727. this._ensureClipGroup().appendChild(this.tgrp);
  25728. } else {
  25729. this.svg.appendChild(this.tgrp);
  25730. }
  25731. }
  25732. return this.tgrp;
  25733. }
  25734. };
  25735. return SVGGraphics;
  25736. }();
  25737. exports.SVGGraphics = SVGGraphics;
  25738. }));
  25739. (function (root, factory) {
  25740. factory(root.pdfjsCoreStream = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreJbig2, root.pdfjsCoreJpg, root.pdfjsCoreJpx);
  25741. }(this, function (exports, sharedUtil, corePrimitives, coreJbig2, coreJpg, coreJpx) {
  25742. var Util = sharedUtil.Util;
  25743. var error = sharedUtil.error;
  25744. var info = sharedUtil.info;
  25745. var isInt = sharedUtil.isInt;
  25746. var isArray = sharedUtil.isArray;
  25747. var createObjectURL = sharedUtil.createObjectURL;
  25748. var shadow = sharedUtil.shadow;
  25749. var warn = sharedUtil.warn;
  25750. var isSpace = sharedUtil.isSpace;
  25751. var Dict = corePrimitives.Dict;
  25752. var isDict = corePrimitives.isDict;
  25753. var isStream = corePrimitives.isStream;
  25754. var Jbig2Image = coreJbig2.Jbig2Image;
  25755. var JpegImage = coreJpg.JpegImage;
  25756. var JpxImage = coreJpx.JpxImage;
  25757. var Stream = function StreamClosure() {
  25758. function Stream(arrayBuffer, start, length, dict) {
  25759. this.bytes = arrayBuffer instanceof Uint8Array ? arrayBuffer : new Uint8Array(arrayBuffer);
  25760. this.start = start || 0;
  25761. this.pos = this.start;
  25762. this.end = start + length || this.bytes.length;
  25763. this.dict = dict;
  25764. }
  25765. // required methods for a stream. if a particular stream does not
  25766. // implement these, an error should be thrown
  25767. Stream.prototype = {
  25768. get length() {
  25769. return this.end - this.start;
  25770. },
  25771. get isEmpty() {
  25772. return this.length === 0;
  25773. },
  25774. getByte: function Stream_getByte() {
  25775. if (this.pos >= this.end) {
  25776. return -1;
  25777. }
  25778. return this.bytes[this.pos++];
  25779. },
  25780. getUint16: function Stream_getUint16() {
  25781. var b0 = this.getByte();
  25782. var b1 = this.getByte();
  25783. if (b0 === -1 || b1 === -1) {
  25784. return -1;
  25785. }
  25786. return (b0 << 8) + b1;
  25787. },
  25788. getInt32: function Stream_getInt32() {
  25789. var b0 = this.getByte();
  25790. var b1 = this.getByte();
  25791. var b2 = this.getByte();
  25792. var b3 = this.getByte();
  25793. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  25794. },
  25795. // returns subarray of original buffer
  25796. // should only be read
  25797. getBytes: function Stream_getBytes(length) {
  25798. var bytes = this.bytes;
  25799. var pos = this.pos;
  25800. var strEnd = this.end;
  25801. if (!length) {
  25802. return bytes.subarray(pos, strEnd);
  25803. }
  25804. var end = pos + length;
  25805. if (end > strEnd) {
  25806. end = strEnd;
  25807. }
  25808. this.pos = end;
  25809. return bytes.subarray(pos, end);
  25810. },
  25811. peekByte: function Stream_peekByte() {
  25812. var peekedByte = this.getByte();
  25813. this.pos--;
  25814. return peekedByte;
  25815. },
  25816. peekBytes: function Stream_peekBytes(length) {
  25817. var bytes = this.getBytes(length);
  25818. this.pos -= bytes.length;
  25819. return bytes;
  25820. },
  25821. skip: function Stream_skip(n) {
  25822. if (!n) {
  25823. n = 1;
  25824. }
  25825. this.pos += n;
  25826. },
  25827. reset: function Stream_reset() {
  25828. this.pos = this.start;
  25829. },
  25830. moveStart: function Stream_moveStart() {
  25831. this.start = this.pos;
  25832. },
  25833. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  25834. return new Stream(this.bytes.buffer, start, length, dict);
  25835. },
  25836. isStream: true
  25837. };
  25838. return Stream;
  25839. }();
  25840. var StringStream = function StringStreamClosure() {
  25841. function StringStream(str) {
  25842. var length = str.length;
  25843. var bytes = new Uint8Array(length);
  25844. for (var n = 0; n < length; ++n) {
  25845. bytes[n] = str.charCodeAt(n);
  25846. }
  25847. Stream.call(this, bytes);
  25848. }
  25849. StringStream.prototype = Stream.prototype;
  25850. return StringStream;
  25851. }();
  25852. // super class for the decoding streams
  25853. var DecodeStream = function DecodeStreamClosure() {
  25854. // Lots of DecodeStreams are created whose buffers are never used. For these
  25855. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  25856. // having special cases that would be required if we used |null| for an empty
  25857. // buffer.
  25858. var emptyBuffer = new Uint8Array(0);
  25859. function DecodeStream(maybeMinBufferLength) {
  25860. this.pos = 0;
  25861. this.bufferLength = 0;
  25862. this.eof = false;
  25863. this.buffer = emptyBuffer;
  25864. this.minBufferLength = 512;
  25865. if (maybeMinBufferLength) {
  25866. // Compute the first power of two that is as big as maybeMinBufferLength.
  25867. while (this.minBufferLength < maybeMinBufferLength) {
  25868. this.minBufferLength *= 2;
  25869. }
  25870. }
  25871. }
  25872. DecodeStream.prototype = {
  25873. get isEmpty() {
  25874. while (!this.eof && this.bufferLength === 0) {
  25875. this.readBlock();
  25876. }
  25877. return this.bufferLength === 0;
  25878. },
  25879. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  25880. var buffer = this.buffer;
  25881. if (requested <= buffer.byteLength) {
  25882. return buffer;
  25883. }
  25884. var size = this.minBufferLength;
  25885. while (size < requested) {
  25886. size *= 2;
  25887. }
  25888. var buffer2 = new Uint8Array(size);
  25889. buffer2.set(buffer);
  25890. return this.buffer = buffer2;
  25891. },
  25892. getByte: function DecodeStream_getByte() {
  25893. var pos = this.pos;
  25894. while (this.bufferLength <= pos) {
  25895. if (this.eof) {
  25896. return -1;
  25897. }
  25898. this.readBlock();
  25899. }
  25900. return this.buffer[this.pos++];
  25901. },
  25902. getUint16: function DecodeStream_getUint16() {
  25903. var b0 = this.getByte();
  25904. var b1 = this.getByte();
  25905. if (b0 === -1 || b1 === -1) {
  25906. return -1;
  25907. }
  25908. return (b0 << 8) + b1;
  25909. },
  25910. getInt32: function DecodeStream_getInt32() {
  25911. var b0 = this.getByte();
  25912. var b1 = this.getByte();
  25913. var b2 = this.getByte();
  25914. var b3 = this.getByte();
  25915. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  25916. },
  25917. getBytes: function DecodeStream_getBytes(length) {
  25918. var end, pos = this.pos;
  25919. if (length) {
  25920. this.ensureBuffer(pos + length);
  25921. end = pos + length;
  25922. while (!this.eof && this.bufferLength < end) {
  25923. this.readBlock();
  25924. }
  25925. var bufEnd = this.bufferLength;
  25926. if (end > bufEnd) {
  25927. end = bufEnd;
  25928. }
  25929. } else {
  25930. while (!this.eof) {
  25931. this.readBlock();
  25932. }
  25933. end = this.bufferLength;
  25934. }
  25935. this.pos = end;
  25936. return this.buffer.subarray(pos, end);
  25937. },
  25938. peekByte: function DecodeStream_peekByte() {
  25939. var peekedByte = this.getByte();
  25940. this.pos--;
  25941. return peekedByte;
  25942. },
  25943. peekBytes: function DecodeStream_peekBytes(length) {
  25944. var bytes = this.getBytes(length);
  25945. this.pos -= bytes.length;
  25946. return bytes;
  25947. },
  25948. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  25949. var end = start + length;
  25950. while (this.bufferLength <= end && !this.eof) {
  25951. this.readBlock();
  25952. }
  25953. return new Stream(this.buffer, start, length, dict);
  25954. },
  25955. skip: function DecodeStream_skip(n) {
  25956. if (!n) {
  25957. n = 1;
  25958. }
  25959. this.pos += n;
  25960. },
  25961. reset: function DecodeStream_reset() {
  25962. this.pos = 0;
  25963. },
  25964. getBaseStreams: function DecodeStream_getBaseStreams() {
  25965. if (this.str && this.str.getBaseStreams) {
  25966. return this.str.getBaseStreams();
  25967. }
  25968. return [];
  25969. }
  25970. };
  25971. return DecodeStream;
  25972. }();
  25973. var StreamsSequenceStream = function StreamsSequenceStreamClosure() {
  25974. function StreamsSequenceStream(streams) {
  25975. this.streams = streams;
  25976. DecodeStream.call(this, /* maybeLength = */
  25977. null);
  25978. }
  25979. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  25980. StreamsSequenceStream.prototype.readBlock = function streamSequenceStreamReadBlock() {
  25981. var streams = this.streams;
  25982. if (streams.length === 0) {
  25983. this.eof = true;
  25984. return;
  25985. }
  25986. var stream = streams.shift();
  25987. var chunk = stream.getBytes();
  25988. var bufferLength = this.bufferLength;
  25989. var newLength = bufferLength + chunk.length;
  25990. var buffer = this.ensureBuffer(newLength);
  25991. buffer.set(chunk, bufferLength);
  25992. this.bufferLength = newLength;
  25993. };
  25994. StreamsSequenceStream.prototype.getBaseStreams = function StreamsSequenceStream_getBaseStreams() {
  25995. var baseStreams = [];
  25996. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  25997. var stream = this.streams[i];
  25998. if (stream.getBaseStreams) {
  25999. Util.appendToArray(baseStreams, stream.getBaseStreams());
  26000. }
  26001. }
  26002. return baseStreams;
  26003. };
  26004. return StreamsSequenceStream;
  26005. }();
  26006. var FlateStream = function FlateStreamClosure() {
  26007. var codeLenCodeMap = new Int32Array([
  26008. 16,
  26009. 17,
  26010. 18,
  26011. 0,
  26012. 8,
  26013. 7,
  26014. 9,
  26015. 6,
  26016. 10,
  26017. 5,
  26018. 11,
  26019. 4,
  26020. 12,
  26021. 3,
  26022. 13,
  26023. 2,
  26024. 14,
  26025. 1,
  26026. 15
  26027. ]);
  26028. var lengthDecode = new Int32Array([
  26029. 0x00003,
  26030. 0x00004,
  26031. 0x00005,
  26032. 0x00006,
  26033. 0x00007,
  26034. 0x00008,
  26035. 0x00009,
  26036. 0x0000a,
  26037. 0x1000b,
  26038. 0x1000d,
  26039. 0x1000f,
  26040. 0x10011,
  26041. 0x20013,
  26042. 0x20017,
  26043. 0x2001b,
  26044. 0x2001f,
  26045. 0x30023,
  26046. 0x3002b,
  26047. 0x30033,
  26048. 0x3003b,
  26049. 0x40043,
  26050. 0x40053,
  26051. 0x40063,
  26052. 0x40073,
  26053. 0x50083,
  26054. 0x500a3,
  26055. 0x500c3,
  26056. 0x500e3,
  26057. 0x00102,
  26058. 0x00102,
  26059. 0x00102
  26060. ]);
  26061. var distDecode = new Int32Array([
  26062. 0x00001,
  26063. 0x00002,
  26064. 0x00003,
  26065. 0x00004,
  26066. 0x10005,
  26067. 0x10007,
  26068. 0x20009,
  26069. 0x2000d,
  26070. 0x30011,
  26071. 0x30019,
  26072. 0x40021,
  26073. 0x40031,
  26074. 0x50041,
  26075. 0x50061,
  26076. 0x60081,
  26077. 0x600c1,
  26078. 0x70101,
  26079. 0x70181,
  26080. 0x80201,
  26081. 0x80301,
  26082. 0x90401,
  26083. 0x90601,
  26084. 0xa0801,
  26085. 0xa0c01,
  26086. 0xb1001,
  26087. 0xb1801,
  26088. 0xc2001,
  26089. 0xc3001,
  26090. 0xd4001,
  26091. 0xd6001
  26092. ]);
  26093. var fixedLitCodeTab = [
  26094. new Int32Array([
  26095. 0x70100,
  26096. 0x80050,
  26097. 0x80010,
  26098. 0x80118,
  26099. 0x70110,
  26100. 0x80070,
  26101. 0x80030,
  26102. 0x900c0,
  26103. 0x70108,
  26104. 0x80060,
  26105. 0x80020,
  26106. 0x900a0,
  26107. 0x80000,
  26108. 0x80080,
  26109. 0x80040,
  26110. 0x900e0,
  26111. 0x70104,
  26112. 0x80058,
  26113. 0x80018,
  26114. 0x90090,
  26115. 0x70114,
  26116. 0x80078,
  26117. 0x80038,
  26118. 0x900d0,
  26119. 0x7010c,
  26120. 0x80068,
  26121. 0x80028,
  26122. 0x900b0,
  26123. 0x80008,
  26124. 0x80088,
  26125. 0x80048,
  26126. 0x900f0,
  26127. 0x70102,
  26128. 0x80054,
  26129. 0x80014,
  26130. 0x8011c,
  26131. 0x70112,
  26132. 0x80074,
  26133. 0x80034,
  26134. 0x900c8,
  26135. 0x7010a,
  26136. 0x80064,
  26137. 0x80024,
  26138. 0x900a8,
  26139. 0x80004,
  26140. 0x80084,
  26141. 0x80044,
  26142. 0x900e8,
  26143. 0x70106,
  26144. 0x8005c,
  26145. 0x8001c,
  26146. 0x90098,
  26147. 0x70116,
  26148. 0x8007c,
  26149. 0x8003c,
  26150. 0x900d8,
  26151. 0x7010e,
  26152. 0x8006c,
  26153. 0x8002c,
  26154. 0x900b8,
  26155. 0x8000c,
  26156. 0x8008c,
  26157. 0x8004c,
  26158. 0x900f8,
  26159. 0x70101,
  26160. 0x80052,
  26161. 0x80012,
  26162. 0x8011a,
  26163. 0x70111,
  26164. 0x80072,
  26165. 0x80032,
  26166. 0x900c4,
  26167. 0x70109,
  26168. 0x80062,
  26169. 0x80022,
  26170. 0x900a4,
  26171. 0x80002,
  26172. 0x80082,
  26173. 0x80042,
  26174. 0x900e4,
  26175. 0x70105,
  26176. 0x8005a,
  26177. 0x8001a,
  26178. 0x90094,
  26179. 0x70115,
  26180. 0x8007a,
  26181. 0x8003a,
  26182. 0x900d4,
  26183. 0x7010d,
  26184. 0x8006a,
  26185. 0x8002a,
  26186. 0x900b4,
  26187. 0x8000a,
  26188. 0x8008a,
  26189. 0x8004a,
  26190. 0x900f4,
  26191. 0x70103,
  26192. 0x80056,
  26193. 0x80016,
  26194. 0x8011e,
  26195. 0x70113,
  26196. 0x80076,
  26197. 0x80036,
  26198. 0x900cc,
  26199. 0x7010b,
  26200. 0x80066,
  26201. 0x80026,
  26202. 0x900ac,
  26203. 0x80006,
  26204. 0x80086,
  26205. 0x80046,
  26206. 0x900ec,
  26207. 0x70107,
  26208. 0x8005e,
  26209. 0x8001e,
  26210. 0x9009c,
  26211. 0x70117,
  26212. 0x8007e,
  26213. 0x8003e,
  26214. 0x900dc,
  26215. 0x7010f,
  26216. 0x8006e,
  26217. 0x8002e,
  26218. 0x900bc,
  26219. 0x8000e,
  26220. 0x8008e,
  26221. 0x8004e,
  26222. 0x900fc,
  26223. 0x70100,
  26224. 0x80051,
  26225. 0x80011,
  26226. 0x80119,
  26227. 0x70110,
  26228. 0x80071,
  26229. 0x80031,
  26230. 0x900c2,
  26231. 0x70108,
  26232. 0x80061,
  26233. 0x80021,
  26234. 0x900a2,
  26235. 0x80001,
  26236. 0x80081,
  26237. 0x80041,
  26238. 0x900e2,
  26239. 0x70104,
  26240. 0x80059,
  26241. 0x80019,
  26242. 0x90092,
  26243. 0x70114,
  26244. 0x80079,
  26245. 0x80039,
  26246. 0x900d2,
  26247. 0x7010c,
  26248. 0x80069,
  26249. 0x80029,
  26250. 0x900b2,
  26251. 0x80009,
  26252. 0x80089,
  26253. 0x80049,
  26254. 0x900f2,
  26255. 0x70102,
  26256. 0x80055,
  26257. 0x80015,
  26258. 0x8011d,
  26259. 0x70112,
  26260. 0x80075,
  26261. 0x80035,
  26262. 0x900ca,
  26263. 0x7010a,
  26264. 0x80065,
  26265. 0x80025,
  26266. 0x900aa,
  26267. 0x80005,
  26268. 0x80085,
  26269. 0x80045,
  26270. 0x900ea,
  26271. 0x70106,
  26272. 0x8005d,
  26273. 0x8001d,
  26274. 0x9009a,
  26275. 0x70116,
  26276. 0x8007d,
  26277. 0x8003d,
  26278. 0x900da,
  26279. 0x7010e,
  26280. 0x8006d,
  26281. 0x8002d,
  26282. 0x900ba,
  26283. 0x8000d,
  26284. 0x8008d,
  26285. 0x8004d,
  26286. 0x900fa,
  26287. 0x70101,
  26288. 0x80053,
  26289. 0x80013,
  26290. 0x8011b,
  26291. 0x70111,
  26292. 0x80073,
  26293. 0x80033,
  26294. 0x900c6,
  26295. 0x70109,
  26296. 0x80063,
  26297. 0x80023,
  26298. 0x900a6,
  26299. 0x80003,
  26300. 0x80083,
  26301. 0x80043,
  26302. 0x900e6,
  26303. 0x70105,
  26304. 0x8005b,
  26305. 0x8001b,
  26306. 0x90096,
  26307. 0x70115,
  26308. 0x8007b,
  26309. 0x8003b,
  26310. 0x900d6,
  26311. 0x7010d,
  26312. 0x8006b,
  26313. 0x8002b,
  26314. 0x900b6,
  26315. 0x8000b,
  26316. 0x8008b,
  26317. 0x8004b,
  26318. 0x900f6,
  26319. 0x70103,
  26320. 0x80057,
  26321. 0x80017,
  26322. 0x8011f,
  26323. 0x70113,
  26324. 0x80077,
  26325. 0x80037,
  26326. 0x900ce,
  26327. 0x7010b,
  26328. 0x80067,
  26329. 0x80027,
  26330. 0x900ae,
  26331. 0x80007,
  26332. 0x80087,
  26333. 0x80047,
  26334. 0x900ee,
  26335. 0x70107,
  26336. 0x8005f,
  26337. 0x8001f,
  26338. 0x9009e,
  26339. 0x70117,
  26340. 0x8007f,
  26341. 0x8003f,
  26342. 0x900de,
  26343. 0x7010f,
  26344. 0x8006f,
  26345. 0x8002f,
  26346. 0x900be,
  26347. 0x8000f,
  26348. 0x8008f,
  26349. 0x8004f,
  26350. 0x900fe,
  26351. 0x70100,
  26352. 0x80050,
  26353. 0x80010,
  26354. 0x80118,
  26355. 0x70110,
  26356. 0x80070,
  26357. 0x80030,
  26358. 0x900c1,
  26359. 0x70108,
  26360. 0x80060,
  26361. 0x80020,
  26362. 0x900a1,
  26363. 0x80000,
  26364. 0x80080,
  26365. 0x80040,
  26366. 0x900e1,
  26367. 0x70104,
  26368. 0x80058,
  26369. 0x80018,
  26370. 0x90091,
  26371. 0x70114,
  26372. 0x80078,
  26373. 0x80038,
  26374. 0x900d1,
  26375. 0x7010c,
  26376. 0x80068,
  26377. 0x80028,
  26378. 0x900b1,
  26379. 0x80008,
  26380. 0x80088,
  26381. 0x80048,
  26382. 0x900f1,
  26383. 0x70102,
  26384. 0x80054,
  26385. 0x80014,
  26386. 0x8011c,
  26387. 0x70112,
  26388. 0x80074,
  26389. 0x80034,
  26390. 0x900c9,
  26391. 0x7010a,
  26392. 0x80064,
  26393. 0x80024,
  26394. 0x900a9,
  26395. 0x80004,
  26396. 0x80084,
  26397. 0x80044,
  26398. 0x900e9,
  26399. 0x70106,
  26400. 0x8005c,
  26401. 0x8001c,
  26402. 0x90099,
  26403. 0x70116,
  26404. 0x8007c,
  26405. 0x8003c,
  26406. 0x900d9,
  26407. 0x7010e,
  26408. 0x8006c,
  26409. 0x8002c,
  26410. 0x900b9,
  26411. 0x8000c,
  26412. 0x8008c,
  26413. 0x8004c,
  26414. 0x900f9,
  26415. 0x70101,
  26416. 0x80052,
  26417. 0x80012,
  26418. 0x8011a,
  26419. 0x70111,
  26420. 0x80072,
  26421. 0x80032,
  26422. 0x900c5,
  26423. 0x70109,
  26424. 0x80062,
  26425. 0x80022,
  26426. 0x900a5,
  26427. 0x80002,
  26428. 0x80082,
  26429. 0x80042,
  26430. 0x900e5,
  26431. 0x70105,
  26432. 0x8005a,
  26433. 0x8001a,
  26434. 0x90095,
  26435. 0x70115,
  26436. 0x8007a,
  26437. 0x8003a,
  26438. 0x900d5,
  26439. 0x7010d,
  26440. 0x8006a,
  26441. 0x8002a,
  26442. 0x900b5,
  26443. 0x8000a,
  26444. 0x8008a,
  26445. 0x8004a,
  26446. 0x900f5,
  26447. 0x70103,
  26448. 0x80056,
  26449. 0x80016,
  26450. 0x8011e,
  26451. 0x70113,
  26452. 0x80076,
  26453. 0x80036,
  26454. 0x900cd,
  26455. 0x7010b,
  26456. 0x80066,
  26457. 0x80026,
  26458. 0x900ad,
  26459. 0x80006,
  26460. 0x80086,
  26461. 0x80046,
  26462. 0x900ed,
  26463. 0x70107,
  26464. 0x8005e,
  26465. 0x8001e,
  26466. 0x9009d,
  26467. 0x70117,
  26468. 0x8007e,
  26469. 0x8003e,
  26470. 0x900dd,
  26471. 0x7010f,
  26472. 0x8006e,
  26473. 0x8002e,
  26474. 0x900bd,
  26475. 0x8000e,
  26476. 0x8008e,
  26477. 0x8004e,
  26478. 0x900fd,
  26479. 0x70100,
  26480. 0x80051,
  26481. 0x80011,
  26482. 0x80119,
  26483. 0x70110,
  26484. 0x80071,
  26485. 0x80031,
  26486. 0x900c3,
  26487. 0x70108,
  26488. 0x80061,
  26489. 0x80021,
  26490. 0x900a3,
  26491. 0x80001,
  26492. 0x80081,
  26493. 0x80041,
  26494. 0x900e3,
  26495. 0x70104,
  26496. 0x80059,
  26497. 0x80019,
  26498. 0x90093,
  26499. 0x70114,
  26500. 0x80079,
  26501. 0x80039,
  26502. 0x900d3,
  26503. 0x7010c,
  26504. 0x80069,
  26505. 0x80029,
  26506. 0x900b3,
  26507. 0x80009,
  26508. 0x80089,
  26509. 0x80049,
  26510. 0x900f3,
  26511. 0x70102,
  26512. 0x80055,
  26513. 0x80015,
  26514. 0x8011d,
  26515. 0x70112,
  26516. 0x80075,
  26517. 0x80035,
  26518. 0x900cb,
  26519. 0x7010a,
  26520. 0x80065,
  26521. 0x80025,
  26522. 0x900ab,
  26523. 0x80005,
  26524. 0x80085,
  26525. 0x80045,
  26526. 0x900eb,
  26527. 0x70106,
  26528. 0x8005d,
  26529. 0x8001d,
  26530. 0x9009b,
  26531. 0x70116,
  26532. 0x8007d,
  26533. 0x8003d,
  26534. 0x900db,
  26535. 0x7010e,
  26536. 0x8006d,
  26537. 0x8002d,
  26538. 0x900bb,
  26539. 0x8000d,
  26540. 0x8008d,
  26541. 0x8004d,
  26542. 0x900fb,
  26543. 0x70101,
  26544. 0x80053,
  26545. 0x80013,
  26546. 0x8011b,
  26547. 0x70111,
  26548. 0x80073,
  26549. 0x80033,
  26550. 0x900c7,
  26551. 0x70109,
  26552. 0x80063,
  26553. 0x80023,
  26554. 0x900a7,
  26555. 0x80003,
  26556. 0x80083,
  26557. 0x80043,
  26558. 0x900e7,
  26559. 0x70105,
  26560. 0x8005b,
  26561. 0x8001b,
  26562. 0x90097,
  26563. 0x70115,
  26564. 0x8007b,
  26565. 0x8003b,
  26566. 0x900d7,
  26567. 0x7010d,
  26568. 0x8006b,
  26569. 0x8002b,
  26570. 0x900b7,
  26571. 0x8000b,
  26572. 0x8008b,
  26573. 0x8004b,
  26574. 0x900f7,
  26575. 0x70103,
  26576. 0x80057,
  26577. 0x80017,
  26578. 0x8011f,
  26579. 0x70113,
  26580. 0x80077,
  26581. 0x80037,
  26582. 0x900cf,
  26583. 0x7010b,
  26584. 0x80067,
  26585. 0x80027,
  26586. 0x900af,
  26587. 0x80007,
  26588. 0x80087,
  26589. 0x80047,
  26590. 0x900ef,
  26591. 0x70107,
  26592. 0x8005f,
  26593. 0x8001f,
  26594. 0x9009f,
  26595. 0x70117,
  26596. 0x8007f,
  26597. 0x8003f,
  26598. 0x900df,
  26599. 0x7010f,
  26600. 0x8006f,
  26601. 0x8002f,
  26602. 0x900bf,
  26603. 0x8000f,
  26604. 0x8008f,
  26605. 0x8004f,
  26606. 0x900ff
  26607. ]),
  26608. 9
  26609. ];
  26610. var fixedDistCodeTab = [
  26611. new Int32Array([
  26612. 0x50000,
  26613. 0x50010,
  26614. 0x50008,
  26615. 0x50018,
  26616. 0x50004,
  26617. 0x50014,
  26618. 0x5000c,
  26619. 0x5001c,
  26620. 0x50002,
  26621. 0x50012,
  26622. 0x5000a,
  26623. 0x5001a,
  26624. 0x50006,
  26625. 0x50016,
  26626. 0x5000e,
  26627. 0x00000,
  26628. 0x50001,
  26629. 0x50011,
  26630. 0x50009,
  26631. 0x50019,
  26632. 0x50005,
  26633. 0x50015,
  26634. 0x5000d,
  26635. 0x5001d,
  26636. 0x50003,
  26637. 0x50013,
  26638. 0x5000b,
  26639. 0x5001b,
  26640. 0x50007,
  26641. 0x50017,
  26642. 0x5000f,
  26643. 0x00000
  26644. ]),
  26645. 5
  26646. ];
  26647. function FlateStream(str, maybeLength) {
  26648. this.str = str;
  26649. this.dict = str.dict;
  26650. var cmf = str.getByte();
  26651. var flg = str.getByte();
  26652. if (cmf === -1 || flg === -1) {
  26653. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  26654. }
  26655. if ((cmf & 0x0f) !== 0x08) {
  26656. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  26657. }
  26658. if (((cmf << 8) + flg) % 31 !== 0) {
  26659. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  26660. }
  26661. if (flg & 0x20) {
  26662. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  26663. }
  26664. this.codeSize = 0;
  26665. this.codeBuf = 0;
  26666. DecodeStream.call(this, maybeLength);
  26667. }
  26668. FlateStream.prototype = Object.create(DecodeStream.prototype);
  26669. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  26670. var str = this.str;
  26671. var codeSize = this.codeSize;
  26672. var codeBuf = this.codeBuf;
  26673. var b;
  26674. while (codeSize < bits) {
  26675. if ((b = str.getByte()) === -1) {
  26676. error('Bad encoding in flate stream');
  26677. }
  26678. codeBuf |= b << codeSize;
  26679. codeSize += 8;
  26680. }
  26681. b = codeBuf & (1 << bits) - 1;
  26682. this.codeBuf = codeBuf >> bits;
  26683. this.codeSize = codeSize -= bits;
  26684. return b;
  26685. };
  26686. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  26687. var str = this.str;
  26688. var codes = table[0];
  26689. var maxLen = table[1];
  26690. var codeSize = this.codeSize;
  26691. var codeBuf = this.codeBuf;
  26692. var b;
  26693. while (codeSize < maxLen) {
  26694. if ((b = str.getByte()) === -1) {
  26695. // premature end of stream. code might however still be valid.
  26696. // codeSize < codeLen check below guards against incomplete codeVal.
  26697. break;
  26698. }
  26699. codeBuf |= b << codeSize;
  26700. codeSize += 8;
  26701. }
  26702. var code = codes[codeBuf & (1 << maxLen) - 1];
  26703. var codeLen = code >> 16;
  26704. var codeVal = code & 0xffff;
  26705. if (codeLen < 1 || codeSize < codeLen) {
  26706. error('Bad encoding in flate stream');
  26707. }
  26708. this.codeBuf = codeBuf >> codeLen;
  26709. this.codeSize = codeSize - codeLen;
  26710. return codeVal;
  26711. };
  26712. FlateStream.prototype.generateHuffmanTable = function flateStreamGenerateHuffmanTable(lengths) {
  26713. var n = lengths.length;
  26714. // find max code length
  26715. var maxLen = 0;
  26716. var i;
  26717. for (i = 0; i < n; ++i) {
  26718. if (lengths[i] > maxLen) {
  26719. maxLen = lengths[i];
  26720. }
  26721. }
  26722. // build the table
  26723. var size = 1 << maxLen;
  26724. var codes = new Int32Array(size);
  26725. for (var len = 1, code = 0, skip = 2; len <= maxLen; ++len, code <<= 1, skip <<= 1) {
  26726. for (var val = 0; val < n; ++val) {
  26727. if (lengths[val] === len) {
  26728. // bit-reverse the code
  26729. var code2 = 0;
  26730. var t = code;
  26731. for (i = 0; i < len; ++i) {
  26732. code2 = code2 << 1 | t & 1;
  26733. t >>= 1;
  26734. }
  26735. // fill the table entries
  26736. for (i = code2; i < size; i += skip) {
  26737. codes[i] = len << 16 | val;
  26738. }
  26739. ++code;
  26740. }
  26741. }
  26742. }
  26743. return [
  26744. codes,
  26745. maxLen
  26746. ];
  26747. };
  26748. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  26749. var buffer, len;
  26750. var str = this.str;
  26751. // read block header
  26752. var hdr = this.getBits(3);
  26753. if (hdr & 1) {
  26754. this.eof = true;
  26755. }
  26756. hdr >>= 1;
  26757. if (hdr === 0) {
  26758. // uncompressed block
  26759. var b;
  26760. if ((b = str.getByte()) === -1) {
  26761. error('Bad block header in flate stream');
  26762. }
  26763. var blockLen = b;
  26764. if ((b = str.getByte()) === -1) {
  26765. error('Bad block header in flate stream');
  26766. }
  26767. blockLen |= b << 8;
  26768. if ((b = str.getByte()) === -1) {
  26769. error('Bad block header in flate stream');
  26770. }
  26771. var check = b;
  26772. if ((b = str.getByte()) === -1) {
  26773. error('Bad block header in flate stream');
  26774. }
  26775. check |= b << 8;
  26776. if (check !== (~blockLen & 0xffff) && (blockLen !== 0 || check !== 0)) {
  26777. // Ignoring error for bad "empty" block (see issue 1277)
  26778. error('Bad uncompressed block length in flate stream');
  26779. }
  26780. this.codeBuf = 0;
  26781. this.codeSize = 0;
  26782. var bufferLength = this.bufferLength;
  26783. buffer = this.ensureBuffer(bufferLength + blockLen);
  26784. var end = bufferLength + blockLen;
  26785. this.bufferLength = end;
  26786. if (blockLen === 0) {
  26787. if (str.peekByte() === -1) {
  26788. this.eof = true;
  26789. }
  26790. } else {
  26791. for (var n = bufferLength; n < end; ++n) {
  26792. if ((b = str.getByte()) === -1) {
  26793. this.eof = true;
  26794. break;
  26795. }
  26796. buffer[n] = b;
  26797. }
  26798. }
  26799. return;
  26800. }
  26801. var litCodeTable;
  26802. var distCodeTable;
  26803. if (hdr === 1) {
  26804. // compressed block, fixed codes
  26805. litCodeTable = fixedLitCodeTab;
  26806. distCodeTable = fixedDistCodeTab;
  26807. } else if (hdr === 2) {
  26808. // compressed block, dynamic codes
  26809. var numLitCodes = this.getBits(5) + 257;
  26810. var numDistCodes = this.getBits(5) + 1;
  26811. var numCodeLenCodes = this.getBits(4) + 4;
  26812. // build the code lengths code table
  26813. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  26814. var i;
  26815. for (i = 0; i < numCodeLenCodes; ++i) {
  26816. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  26817. }
  26818. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  26819. // build the literal and distance code tables
  26820. len = 0;
  26821. i = 0;
  26822. var codes = numLitCodes + numDistCodes;
  26823. var codeLengths = new Uint8Array(codes);
  26824. var bitsLength, bitsOffset, what;
  26825. while (i < codes) {
  26826. var code = this.getCode(codeLenCodeTab);
  26827. if (code === 16) {
  26828. bitsLength = 2;
  26829. bitsOffset = 3;
  26830. what = len;
  26831. } else if (code === 17) {
  26832. bitsLength = 3;
  26833. bitsOffset = 3;
  26834. what = len = 0;
  26835. } else if (code === 18) {
  26836. bitsLength = 7;
  26837. bitsOffset = 11;
  26838. what = len = 0;
  26839. } else {
  26840. codeLengths[i++] = len = code;
  26841. continue;
  26842. }
  26843. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  26844. while (repeatLength-- > 0) {
  26845. codeLengths[i++] = what;
  26846. }
  26847. }
  26848. litCodeTable = this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  26849. distCodeTable = this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  26850. } else {
  26851. error('Unknown block type in flate stream');
  26852. }
  26853. buffer = this.buffer;
  26854. var limit = buffer ? buffer.length : 0;
  26855. var pos = this.bufferLength;
  26856. while (true) {
  26857. var code1 = this.getCode(litCodeTable);
  26858. if (code1 < 256) {
  26859. if (pos + 1 >= limit) {
  26860. buffer = this.ensureBuffer(pos + 1);
  26861. limit = buffer.length;
  26862. }
  26863. buffer[pos++] = code1;
  26864. continue;
  26865. }
  26866. if (code1 === 256) {
  26867. this.bufferLength = pos;
  26868. return;
  26869. }
  26870. code1 -= 257;
  26871. code1 = lengthDecode[code1];
  26872. var code2 = code1 >> 16;
  26873. if (code2 > 0) {
  26874. code2 = this.getBits(code2);
  26875. }
  26876. len = (code1 & 0xffff) + code2;
  26877. code1 = this.getCode(distCodeTable);
  26878. code1 = distDecode[code1];
  26879. code2 = code1 >> 16;
  26880. if (code2 > 0) {
  26881. code2 = this.getBits(code2);
  26882. }
  26883. var dist = (code1 & 0xffff) + code2;
  26884. if (pos + len >= limit) {
  26885. buffer = this.ensureBuffer(pos + len);
  26886. limit = buffer.length;
  26887. }
  26888. for (var k = 0; k < len; ++k, ++pos) {
  26889. buffer[pos] = buffer[pos - dist];
  26890. }
  26891. }
  26892. };
  26893. return FlateStream;
  26894. }();
  26895. var PredictorStream = function PredictorStreamClosure() {
  26896. function PredictorStream(str, maybeLength, params) {
  26897. if (!isDict(params)) {
  26898. return str;
  26899. }
  26900. // no prediction
  26901. var predictor = this.predictor = params.get('Predictor') || 1;
  26902. if (predictor <= 1) {
  26903. return str;
  26904. }
  26905. // no prediction
  26906. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  26907. error('Unsupported predictor: ' + predictor);
  26908. }
  26909. if (predictor === 2) {
  26910. this.readBlock = this.readBlockTiff;
  26911. } else {
  26912. this.readBlock = this.readBlockPng;
  26913. }
  26914. this.str = str;
  26915. this.dict = str.dict;
  26916. var colors = this.colors = params.get('Colors') || 1;
  26917. var bits = this.bits = params.get('BitsPerComponent') || 8;
  26918. var columns = this.columns = params.get('Columns') || 1;
  26919. this.pixBytes = colors * bits + 7 >> 3;
  26920. this.rowBytes = columns * colors * bits + 7 >> 3;
  26921. DecodeStream.call(this, maybeLength);
  26922. return this;
  26923. }
  26924. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  26925. PredictorStream.prototype.readBlockTiff = function predictorStreamReadBlockTiff() {
  26926. var rowBytes = this.rowBytes;
  26927. var bufferLength = this.bufferLength;
  26928. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  26929. var bits = this.bits;
  26930. var colors = this.colors;
  26931. var rawBytes = this.str.getBytes(rowBytes);
  26932. this.eof = !rawBytes.length;
  26933. if (this.eof) {
  26934. return;
  26935. }
  26936. var inbuf = 0, outbuf = 0;
  26937. var inbits = 0, outbits = 0;
  26938. var pos = bufferLength;
  26939. var i;
  26940. if (bits === 1) {
  26941. for (i = 0; i < rowBytes; ++i) {
  26942. var c = rawBytes[i];
  26943. inbuf = inbuf << 8 | c;
  26944. // bitwise addition is exclusive or
  26945. // first shift inbuf and then add
  26946. buffer[pos++] = (c ^ inbuf >> colors) & 0xFF;
  26947. // truncate inbuf (assumes colors < 16)
  26948. inbuf &= 0xFFFF;
  26949. }
  26950. } else if (bits === 8) {
  26951. for (i = 0; i < colors; ++i) {
  26952. buffer[pos++] = rawBytes[i];
  26953. }
  26954. for (; i < rowBytes; ++i) {
  26955. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  26956. pos++;
  26957. }
  26958. } else {
  26959. var compArray = new Uint8Array(colors + 1);
  26960. var bitMask = (1 << bits) - 1;
  26961. var j = 0, k = bufferLength;
  26962. var columns = this.columns;
  26963. for (i = 0; i < columns; ++i) {
  26964. for (var kk = 0; kk < colors; ++kk) {
  26965. if (inbits < bits) {
  26966. inbuf = inbuf << 8 | rawBytes[j++] & 0xFF;
  26967. inbits += 8;
  26968. }
  26969. compArray[kk] = compArray[kk] + (inbuf >> inbits - bits) & bitMask;
  26970. inbits -= bits;
  26971. outbuf = outbuf << bits | compArray[kk];
  26972. outbits += bits;
  26973. if (outbits >= 8) {
  26974. buffer[k++] = outbuf >> outbits - 8 & 0xFF;
  26975. outbits -= 8;
  26976. }
  26977. }
  26978. }
  26979. if (outbits > 0) {
  26980. buffer[k++] = (outbuf << 8 - outbits) + (inbuf & (1 << 8 - outbits) - 1);
  26981. }
  26982. }
  26983. this.bufferLength += rowBytes;
  26984. };
  26985. PredictorStream.prototype.readBlockPng = function predictorStreamReadBlockPng() {
  26986. var rowBytes = this.rowBytes;
  26987. var pixBytes = this.pixBytes;
  26988. var predictor = this.str.getByte();
  26989. var rawBytes = this.str.getBytes(rowBytes);
  26990. this.eof = !rawBytes.length;
  26991. if (this.eof) {
  26992. return;
  26993. }
  26994. var bufferLength = this.bufferLength;
  26995. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  26996. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  26997. if (prevRow.length === 0) {
  26998. prevRow = new Uint8Array(rowBytes);
  26999. }
  27000. var i, j = bufferLength, up, c;
  27001. switch (predictor) {
  27002. case 0:
  27003. for (i = 0; i < rowBytes; ++i) {
  27004. buffer[j++] = rawBytes[i];
  27005. }
  27006. break;
  27007. case 1:
  27008. for (i = 0; i < pixBytes; ++i) {
  27009. buffer[j++] = rawBytes[i];
  27010. }
  27011. for (; i < rowBytes; ++i) {
  27012. buffer[j] = buffer[j - pixBytes] + rawBytes[i] & 0xFF;
  27013. j++;
  27014. }
  27015. break;
  27016. case 2:
  27017. for (i = 0; i < rowBytes; ++i) {
  27018. buffer[j++] = prevRow[i] + rawBytes[i] & 0xFF;
  27019. }
  27020. break;
  27021. case 3:
  27022. for (i = 0; i < pixBytes; ++i) {
  27023. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  27024. }
  27025. for (; i < rowBytes; ++i) {
  27026. buffer[j] = (prevRow[i] + buffer[j - pixBytes] >> 1) + rawBytes[i] & 0xFF;
  27027. j++;
  27028. }
  27029. break;
  27030. case 4:
  27031. // we need to save the up left pixels values. the simplest way
  27032. // is to create a new buffer
  27033. for (i = 0; i < pixBytes; ++i) {
  27034. up = prevRow[i];
  27035. c = rawBytes[i];
  27036. buffer[j++] = up + c;
  27037. }
  27038. for (; i < rowBytes; ++i) {
  27039. up = prevRow[i];
  27040. var upLeft = prevRow[i - pixBytes];
  27041. var left = buffer[j - pixBytes];
  27042. var p = left + up - upLeft;
  27043. var pa = p - left;
  27044. if (pa < 0) {
  27045. pa = -pa;
  27046. }
  27047. var pb = p - up;
  27048. if (pb < 0) {
  27049. pb = -pb;
  27050. }
  27051. var pc = p - upLeft;
  27052. if (pc < 0) {
  27053. pc = -pc;
  27054. }
  27055. c = rawBytes[i];
  27056. if (pa <= pb && pa <= pc) {
  27057. buffer[j++] = left + c;
  27058. } else if (pb <= pc) {
  27059. buffer[j++] = up + c;
  27060. } else {
  27061. buffer[j++] = upLeft + c;
  27062. }
  27063. }
  27064. break;
  27065. default:
  27066. error('Unsupported predictor: ' + predictor);
  27067. }
  27068. this.bufferLength += rowBytes;
  27069. };
  27070. return PredictorStream;
  27071. }();
  27072. /**
  27073. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  27074. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  27075. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  27076. * a library to decode these images and the stream behaves like all the other
  27077. * DecodeStreams.
  27078. */
  27079. var JpegStream = function JpegStreamClosure() {
  27080. function JpegStream(stream, maybeLength, dict, params) {
  27081. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  27082. // Note: this seems to mainly affect inline images.
  27083. var ch;
  27084. while ((ch = stream.getByte()) !== -1) {
  27085. if (ch === 0xFF) {
  27086. // Find the first byte of the SOI marker (0xFFD8).
  27087. stream.skip(-1);
  27088. // Reset the stream position to the SOI.
  27089. break;
  27090. }
  27091. }
  27092. this.stream = stream;
  27093. this.maybeLength = maybeLength;
  27094. this.dict = dict;
  27095. this.params = params;
  27096. DecodeStream.call(this, maybeLength);
  27097. }
  27098. JpegStream.prototype = Object.create(DecodeStream.prototype);
  27099. Object.defineProperty(JpegStream.prototype, 'bytes', {
  27100. get: function JpegStream_bytes() {
  27101. // If this.maybeLength is null, we'll get the entire stream.
  27102. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  27103. },
  27104. configurable: true
  27105. });
  27106. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  27107. if (this.bufferLength) {
  27108. return;
  27109. }
  27110. var jpegImage = new JpegImage();
  27111. // Checking if values need to be transformed before conversion.
  27112. var decodeArr = this.dict.getArray('Decode', 'D');
  27113. if (this.forceRGB && isArray(decodeArr)) {
  27114. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  27115. var decodeArrLength = decodeArr.length;
  27116. var transform = new Int32Array(decodeArrLength);
  27117. var transformNeeded = false;
  27118. var maxValue = (1 << bitsPerComponent) - 1;
  27119. for (var i = 0; i < decodeArrLength; i += 2) {
  27120. transform[i] = (decodeArr[i + 1] - decodeArr[i]) * 256 | 0;
  27121. transform[i + 1] = decodeArr[i] * maxValue | 0;
  27122. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  27123. transformNeeded = true;
  27124. }
  27125. }
  27126. if (transformNeeded) {
  27127. jpegImage.decodeTransform = transform;
  27128. }
  27129. }
  27130. // Fetching the 'ColorTransform' entry, if it exists.
  27131. if (isDict(this.params)) {
  27132. var colorTransform = this.params.get('ColorTransform');
  27133. if (isInt(colorTransform)) {
  27134. jpegImage.colorTransform = colorTransform;
  27135. }
  27136. }
  27137. jpegImage.parse(this.bytes);
  27138. var data = jpegImage.getData(this.drawWidth, this.drawHeight, this.forceRGB);
  27139. this.buffer = data;
  27140. this.bufferLength = data.length;
  27141. this.eof = true;
  27142. };
  27143. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  27144. this.ensureBuffer();
  27145. return this.buffer;
  27146. };
  27147. JpegStream.prototype.getIR = function JpegStream_getIR(forceDataSchema) {
  27148. return createObjectURL(this.bytes, 'image/jpeg', forceDataSchema);
  27149. };
  27150. return JpegStream;
  27151. }();
  27152. /**
  27153. * For JPEG 2000's we use a library to decode these images and
  27154. * the stream behaves like all the other DecodeStreams.
  27155. */
  27156. var JpxStream = function JpxStreamClosure() {
  27157. function JpxStream(stream, maybeLength, dict, params) {
  27158. this.stream = stream;
  27159. this.maybeLength = maybeLength;
  27160. this.dict = dict;
  27161. this.params = params;
  27162. DecodeStream.call(this, maybeLength);
  27163. }
  27164. JpxStream.prototype = Object.create(DecodeStream.prototype);
  27165. Object.defineProperty(JpxStream.prototype, 'bytes', {
  27166. get: function JpxStream_bytes() {
  27167. // If this.maybeLength is null, we'll get the entire stream.
  27168. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  27169. },
  27170. configurable: true
  27171. });
  27172. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  27173. if (this.bufferLength) {
  27174. return;
  27175. }
  27176. var jpxImage = new JpxImage();
  27177. jpxImage.parse(this.bytes);
  27178. var width = jpxImage.width;
  27179. var height = jpxImage.height;
  27180. var componentsCount = jpxImage.componentsCount;
  27181. var tileCount = jpxImage.tiles.length;
  27182. if (tileCount === 1) {
  27183. this.buffer = jpxImage.tiles[0].items;
  27184. } else {
  27185. var data = new Uint8Array(width * height * componentsCount);
  27186. for (var k = 0; k < tileCount; k++) {
  27187. var tileComponents = jpxImage.tiles[k];
  27188. var tileWidth = tileComponents.width;
  27189. var tileHeight = tileComponents.height;
  27190. var tileLeft = tileComponents.left;
  27191. var tileTop = tileComponents.top;
  27192. var src = tileComponents.items;
  27193. var srcPosition = 0;
  27194. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  27195. var imgRowSize = width * componentsCount;
  27196. var tileRowSize = tileWidth * componentsCount;
  27197. for (var j = 0; j < tileHeight; j++) {
  27198. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  27199. data.set(rowBytes, dataPosition);
  27200. srcPosition += tileRowSize;
  27201. dataPosition += imgRowSize;
  27202. }
  27203. }
  27204. this.buffer = data;
  27205. }
  27206. this.bufferLength = this.buffer.length;
  27207. this.eof = true;
  27208. };
  27209. return JpxStream;
  27210. }();
  27211. /**
  27212. * For JBIG2's we use a library to decode these images and
  27213. * the stream behaves like all the other DecodeStreams.
  27214. */
  27215. var Jbig2Stream = function Jbig2StreamClosure() {
  27216. function Jbig2Stream(stream, maybeLength, dict, params) {
  27217. this.stream = stream;
  27218. this.maybeLength = maybeLength;
  27219. this.dict = dict;
  27220. this.params = params;
  27221. DecodeStream.call(this, maybeLength);
  27222. }
  27223. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  27224. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  27225. get: function Jbig2Stream_bytes() {
  27226. // If this.maybeLength is null, we'll get the entire stream.
  27227. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  27228. },
  27229. configurable: true
  27230. });
  27231. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  27232. if (this.bufferLength) {
  27233. return;
  27234. }
  27235. var jbig2Image = new Jbig2Image();
  27236. var chunks = [];
  27237. if (isDict(this.params)) {
  27238. var globalsStream = this.params.get('JBIG2Globals');
  27239. if (isStream(globalsStream)) {
  27240. var globals = globalsStream.getBytes();
  27241. chunks.push({
  27242. data: globals,
  27243. start: 0,
  27244. end: globals.length
  27245. });
  27246. }
  27247. }
  27248. chunks.push({
  27249. data: this.bytes,
  27250. start: 0,
  27251. end: this.bytes.length
  27252. });
  27253. var data = jbig2Image.parseChunks(chunks);
  27254. var dataLength = data.length;
  27255. // JBIG2 had black as 1 and white as 0, inverting the colors
  27256. for (var i = 0; i < dataLength; i++) {
  27257. data[i] ^= 0xFF;
  27258. }
  27259. this.buffer = data;
  27260. this.bufferLength = dataLength;
  27261. this.eof = true;
  27262. };
  27263. return Jbig2Stream;
  27264. }();
  27265. var DecryptStream = function DecryptStreamClosure() {
  27266. function DecryptStream(str, maybeLength, decrypt) {
  27267. this.str = str;
  27268. this.dict = str.dict;
  27269. this.decrypt = decrypt;
  27270. this.nextChunk = null;
  27271. this.initialized = false;
  27272. DecodeStream.call(this, maybeLength);
  27273. }
  27274. var chunkSize = 512;
  27275. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  27276. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  27277. var chunk;
  27278. if (this.initialized) {
  27279. chunk = this.nextChunk;
  27280. } else {
  27281. chunk = this.str.getBytes(chunkSize);
  27282. this.initialized = true;
  27283. }
  27284. if (!chunk || chunk.length === 0) {
  27285. this.eof = true;
  27286. return;
  27287. }
  27288. this.nextChunk = this.str.getBytes(chunkSize);
  27289. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  27290. var decrypt = this.decrypt;
  27291. chunk = decrypt(chunk, !hasMoreData);
  27292. var bufferLength = this.bufferLength;
  27293. var i, n = chunk.length;
  27294. var buffer = this.ensureBuffer(bufferLength + n);
  27295. for (i = 0; i < n; i++) {
  27296. buffer[bufferLength++] = chunk[i];
  27297. }
  27298. this.bufferLength = bufferLength;
  27299. };
  27300. return DecryptStream;
  27301. }();
  27302. var Ascii85Stream = function Ascii85StreamClosure() {
  27303. function Ascii85Stream(str, maybeLength) {
  27304. this.str = str;
  27305. this.dict = str.dict;
  27306. this.input = new Uint8Array(5);
  27307. // Most streams increase in size when decoded, but Ascii85 streams
  27308. // typically shrink by ~20%.
  27309. if (maybeLength) {
  27310. maybeLength = 0.8 * maybeLength;
  27311. }
  27312. DecodeStream.call(this, maybeLength);
  27313. }
  27314. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  27315. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  27316. var TILDA_CHAR = 0x7E;
  27317. // '~'
  27318. var Z_LOWER_CHAR = 0x7A;
  27319. // 'z'
  27320. var EOF = -1;
  27321. var str = this.str;
  27322. var c = str.getByte();
  27323. while (isSpace(c)) {
  27324. c = str.getByte();
  27325. }
  27326. if (c === EOF || c === TILDA_CHAR) {
  27327. this.eof = true;
  27328. return;
  27329. }
  27330. var bufferLength = this.bufferLength, buffer;
  27331. var i;
  27332. // special code for z
  27333. if (c === Z_LOWER_CHAR) {
  27334. buffer = this.ensureBuffer(bufferLength + 4);
  27335. for (i = 0; i < 4; ++i) {
  27336. buffer[bufferLength + i] = 0;
  27337. }
  27338. this.bufferLength += 4;
  27339. } else {
  27340. var input = this.input;
  27341. input[0] = c;
  27342. for (i = 1; i < 5; ++i) {
  27343. c = str.getByte();
  27344. while (isSpace(c)) {
  27345. c = str.getByte();
  27346. }
  27347. input[i] = c;
  27348. if (c === EOF || c === TILDA_CHAR) {
  27349. break;
  27350. }
  27351. }
  27352. buffer = this.ensureBuffer(bufferLength + i - 1);
  27353. this.bufferLength += i - 1;
  27354. // partial ending;
  27355. if (i < 5) {
  27356. for (; i < 5; ++i) {
  27357. input[i] = 0x21 + 84;
  27358. }
  27359. this.eof = true;
  27360. }
  27361. var t = 0;
  27362. for (i = 0; i < 5; ++i) {
  27363. t = t * 85 + (input[i] - 0x21);
  27364. }
  27365. for (i = 3; i >= 0; --i) {
  27366. buffer[bufferLength + i] = t & 0xFF;
  27367. t >>= 8;
  27368. }
  27369. }
  27370. };
  27371. return Ascii85Stream;
  27372. }();
  27373. var AsciiHexStream = function AsciiHexStreamClosure() {
  27374. function AsciiHexStream(str, maybeLength) {
  27375. this.str = str;
  27376. this.dict = str.dict;
  27377. this.firstDigit = -1;
  27378. // Most streams increase in size when decoded, but AsciiHex streams shrink
  27379. // by 50%.
  27380. if (maybeLength) {
  27381. maybeLength = 0.5 * maybeLength;
  27382. }
  27383. DecodeStream.call(this, maybeLength);
  27384. }
  27385. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  27386. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  27387. var UPSTREAM_BLOCK_SIZE = 8000;
  27388. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  27389. if (!bytes.length) {
  27390. this.eof = true;
  27391. return;
  27392. }
  27393. var maxDecodeLength = bytes.length + 1 >> 1;
  27394. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  27395. var bufferLength = this.bufferLength;
  27396. var firstDigit = this.firstDigit;
  27397. for (var i = 0, ii = bytes.length; i < ii; i++) {
  27398. var ch = bytes[i], digit;
  27399. if (ch >= 0x30 && ch <= 0x39) {
  27400. // '0'-'9'
  27401. digit = ch & 0x0F;
  27402. } else if (ch >= 0x41 && ch <= 0x46 || ch >= 0x61 && ch <= 0x66) {
  27403. // 'A'-'Z', 'a'-'z'
  27404. digit = (ch & 0x0F) + 9;
  27405. } else if (ch === 0x3E) {
  27406. // '>'
  27407. this.eof = true;
  27408. break;
  27409. } else {
  27410. // probably whitespace
  27411. continue;
  27412. }
  27413. // ignoring
  27414. if (firstDigit < 0) {
  27415. firstDigit = digit;
  27416. } else {
  27417. buffer[bufferLength++] = firstDigit << 4 | digit;
  27418. firstDigit = -1;
  27419. }
  27420. }
  27421. if (firstDigit >= 0 && this.eof) {
  27422. // incomplete byte
  27423. buffer[bufferLength++] = firstDigit << 4;
  27424. firstDigit = -1;
  27425. }
  27426. this.firstDigit = firstDigit;
  27427. this.bufferLength = bufferLength;
  27428. };
  27429. return AsciiHexStream;
  27430. }();
  27431. var RunLengthStream = function RunLengthStreamClosure() {
  27432. function RunLengthStream(str, maybeLength) {
  27433. this.str = str;
  27434. this.dict = str.dict;
  27435. DecodeStream.call(this, maybeLength);
  27436. }
  27437. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  27438. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  27439. // The repeatHeader has following format. The first byte defines type of run
  27440. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  27441. // (in addition to the second byte from the header), n = 129 through 255 -
  27442. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  27443. var repeatHeader = this.str.getBytes(2);
  27444. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  27445. this.eof = true;
  27446. return;
  27447. }
  27448. var buffer;
  27449. var bufferLength = this.bufferLength;
  27450. var n = repeatHeader[0];
  27451. if (n < 128) {
  27452. // copy n bytes
  27453. buffer = this.ensureBuffer(bufferLength + n + 1);
  27454. buffer[bufferLength++] = repeatHeader[1];
  27455. if (n > 0) {
  27456. var source = this.str.getBytes(n);
  27457. buffer.set(source, bufferLength);
  27458. bufferLength += n;
  27459. }
  27460. } else {
  27461. n = 257 - n;
  27462. var b = repeatHeader[1];
  27463. buffer = this.ensureBuffer(bufferLength + n + 1);
  27464. for (var i = 0; i < n; i++) {
  27465. buffer[bufferLength++] = b;
  27466. }
  27467. }
  27468. this.bufferLength = bufferLength;
  27469. };
  27470. return RunLengthStream;
  27471. }();
  27472. var CCITTFaxStream = function CCITTFaxStreamClosure() {
  27473. var ccittEOL = -2;
  27474. var ccittEOF = -1;
  27475. var twoDimPass = 0;
  27476. var twoDimHoriz = 1;
  27477. var twoDimVert0 = 2;
  27478. var twoDimVertR1 = 3;
  27479. var twoDimVertL1 = 4;
  27480. var twoDimVertR2 = 5;
  27481. var twoDimVertL2 = 6;
  27482. var twoDimVertR3 = 7;
  27483. var twoDimVertL3 = 8;
  27484. var twoDimTable = [
  27485. [
  27486. -1,
  27487. -1
  27488. ],
  27489. [
  27490. -1,
  27491. -1
  27492. ],
  27493. // 000000x
  27494. [
  27495. 7,
  27496. twoDimVertL3
  27497. ],
  27498. // 0000010
  27499. [
  27500. 7,
  27501. twoDimVertR3
  27502. ],
  27503. // 0000011
  27504. [
  27505. 6,
  27506. twoDimVertL2
  27507. ],
  27508. [
  27509. 6,
  27510. twoDimVertL2
  27511. ],
  27512. // 000010x
  27513. [
  27514. 6,
  27515. twoDimVertR2
  27516. ],
  27517. [
  27518. 6,
  27519. twoDimVertR2
  27520. ],
  27521. // 000011x
  27522. [
  27523. 4,
  27524. twoDimPass
  27525. ],
  27526. [
  27527. 4,
  27528. twoDimPass
  27529. ],
  27530. // 0001xxx
  27531. [
  27532. 4,
  27533. twoDimPass
  27534. ],
  27535. [
  27536. 4,
  27537. twoDimPass
  27538. ],
  27539. [
  27540. 4,
  27541. twoDimPass
  27542. ],
  27543. [
  27544. 4,
  27545. twoDimPass
  27546. ],
  27547. [
  27548. 4,
  27549. twoDimPass
  27550. ],
  27551. [
  27552. 4,
  27553. twoDimPass
  27554. ],
  27555. [
  27556. 3,
  27557. twoDimHoriz
  27558. ],
  27559. [
  27560. 3,
  27561. twoDimHoriz
  27562. ],
  27563. // 001xxxx
  27564. [
  27565. 3,
  27566. twoDimHoriz
  27567. ],
  27568. [
  27569. 3,
  27570. twoDimHoriz
  27571. ],
  27572. [
  27573. 3,
  27574. twoDimHoriz
  27575. ],
  27576. [
  27577. 3,
  27578. twoDimHoriz
  27579. ],
  27580. [
  27581. 3,
  27582. twoDimHoriz
  27583. ],
  27584. [
  27585. 3,
  27586. twoDimHoriz
  27587. ],
  27588. [
  27589. 3,
  27590. twoDimHoriz
  27591. ],
  27592. [
  27593. 3,
  27594. twoDimHoriz
  27595. ],
  27596. [
  27597. 3,
  27598. twoDimHoriz
  27599. ],
  27600. [
  27601. 3,
  27602. twoDimHoriz
  27603. ],
  27604. [
  27605. 3,
  27606. twoDimHoriz
  27607. ],
  27608. [
  27609. 3,
  27610. twoDimHoriz
  27611. ],
  27612. [
  27613. 3,
  27614. twoDimHoriz
  27615. ],
  27616. [
  27617. 3,
  27618. twoDimHoriz
  27619. ],
  27620. [
  27621. 3,
  27622. twoDimVertL1
  27623. ],
  27624. [
  27625. 3,
  27626. twoDimVertL1
  27627. ],
  27628. // 010xxxx
  27629. [
  27630. 3,
  27631. twoDimVertL1
  27632. ],
  27633. [
  27634. 3,
  27635. twoDimVertL1
  27636. ],
  27637. [
  27638. 3,
  27639. twoDimVertL1
  27640. ],
  27641. [
  27642. 3,
  27643. twoDimVertL1
  27644. ],
  27645. [
  27646. 3,
  27647. twoDimVertL1
  27648. ],
  27649. [
  27650. 3,
  27651. twoDimVertL1
  27652. ],
  27653. [
  27654. 3,
  27655. twoDimVertL1
  27656. ],
  27657. [
  27658. 3,
  27659. twoDimVertL1
  27660. ],
  27661. [
  27662. 3,
  27663. twoDimVertL1
  27664. ],
  27665. [
  27666. 3,
  27667. twoDimVertL1
  27668. ],
  27669. [
  27670. 3,
  27671. twoDimVertL1
  27672. ],
  27673. [
  27674. 3,
  27675. twoDimVertL1
  27676. ],
  27677. [
  27678. 3,
  27679. twoDimVertL1
  27680. ],
  27681. [
  27682. 3,
  27683. twoDimVertL1
  27684. ],
  27685. [
  27686. 3,
  27687. twoDimVertR1
  27688. ],
  27689. [
  27690. 3,
  27691. twoDimVertR1
  27692. ],
  27693. // 011xxxx
  27694. [
  27695. 3,
  27696. twoDimVertR1
  27697. ],
  27698. [
  27699. 3,
  27700. twoDimVertR1
  27701. ],
  27702. [
  27703. 3,
  27704. twoDimVertR1
  27705. ],
  27706. [
  27707. 3,
  27708. twoDimVertR1
  27709. ],
  27710. [
  27711. 3,
  27712. twoDimVertR1
  27713. ],
  27714. [
  27715. 3,
  27716. twoDimVertR1
  27717. ],
  27718. [
  27719. 3,
  27720. twoDimVertR1
  27721. ],
  27722. [
  27723. 3,
  27724. twoDimVertR1
  27725. ],
  27726. [
  27727. 3,
  27728. twoDimVertR1
  27729. ],
  27730. [
  27731. 3,
  27732. twoDimVertR1
  27733. ],
  27734. [
  27735. 3,
  27736. twoDimVertR1
  27737. ],
  27738. [
  27739. 3,
  27740. twoDimVertR1
  27741. ],
  27742. [
  27743. 3,
  27744. twoDimVertR1
  27745. ],
  27746. [
  27747. 3,
  27748. twoDimVertR1
  27749. ],
  27750. [
  27751. 1,
  27752. twoDimVert0
  27753. ],
  27754. [
  27755. 1,
  27756. twoDimVert0
  27757. ],
  27758. // 1xxxxxx
  27759. [
  27760. 1,
  27761. twoDimVert0
  27762. ],
  27763. [
  27764. 1,
  27765. twoDimVert0
  27766. ],
  27767. [
  27768. 1,
  27769. twoDimVert0
  27770. ],
  27771. [
  27772. 1,
  27773. twoDimVert0
  27774. ],
  27775. [
  27776. 1,
  27777. twoDimVert0
  27778. ],
  27779. [
  27780. 1,
  27781. twoDimVert0
  27782. ],
  27783. [
  27784. 1,
  27785. twoDimVert0
  27786. ],
  27787. [
  27788. 1,
  27789. twoDimVert0
  27790. ],
  27791. [
  27792. 1,
  27793. twoDimVert0
  27794. ],
  27795. [
  27796. 1,
  27797. twoDimVert0
  27798. ],
  27799. [
  27800. 1,
  27801. twoDimVert0
  27802. ],
  27803. [
  27804. 1,
  27805. twoDimVert0
  27806. ],
  27807. [
  27808. 1,
  27809. twoDimVert0
  27810. ],
  27811. [
  27812. 1,
  27813. twoDimVert0
  27814. ],
  27815. [
  27816. 1,
  27817. twoDimVert0
  27818. ],
  27819. [
  27820. 1,
  27821. twoDimVert0
  27822. ],
  27823. [
  27824. 1,
  27825. twoDimVert0
  27826. ],
  27827. [
  27828. 1,
  27829. twoDimVert0
  27830. ],
  27831. [
  27832. 1,
  27833. twoDimVert0
  27834. ],
  27835. [
  27836. 1,
  27837. twoDimVert0
  27838. ],
  27839. [
  27840. 1,
  27841. twoDimVert0
  27842. ],
  27843. [
  27844. 1,
  27845. twoDimVert0
  27846. ],
  27847. [
  27848. 1,
  27849. twoDimVert0
  27850. ],
  27851. [
  27852. 1,
  27853. twoDimVert0
  27854. ],
  27855. [
  27856. 1,
  27857. twoDimVert0
  27858. ],
  27859. [
  27860. 1,
  27861. twoDimVert0
  27862. ],
  27863. [
  27864. 1,
  27865. twoDimVert0
  27866. ],
  27867. [
  27868. 1,
  27869. twoDimVert0
  27870. ],
  27871. [
  27872. 1,
  27873. twoDimVert0
  27874. ],
  27875. [
  27876. 1,
  27877. twoDimVert0
  27878. ],
  27879. [
  27880. 1,
  27881. twoDimVert0
  27882. ],
  27883. [
  27884. 1,
  27885. twoDimVert0
  27886. ],
  27887. [
  27888. 1,
  27889. twoDimVert0
  27890. ],
  27891. [
  27892. 1,
  27893. twoDimVert0
  27894. ],
  27895. [
  27896. 1,
  27897. twoDimVert0
  27898. ],
  27899. [
  27900. 1,
  27901. twoDimVert0
  27902. ],
  27903. [
  27904. 1,
  27905. twoDimVert0
  27906. ],
  27907. [
  27908. 1,
  27909. twoDimVert0
  27910. ],
  27911. [
  27912. 1,
  27913. twoDimVert0
  27914. ],
  27915. [
  27916. 1,
  27917. twoDimVert0
  27918. ],
  27919. [
  27920. 1,
  27921. twoDimVert0
  27922. ],
  27923. [
  27924. 1,
  27925. twoDimVert0
  27926. ],
  27927. [
  27928. 1,
  27929. twoDimVert0
  27930. ],
  27931. [
  27932. 1,
  27933. twoDimVert0
  27934. ],
  27935. [
  27936. 1,
  27937. twoDimVert0
  27938. ],
  27939. [
  27940. 1,
  27941. twoDimVert0
  27942. ],
  27943. [
  27944. 1,
  27945. twoDimVert0
  27946. ],
  27947. [
  27948. 1,
  27949. twoDimVert0
  27950. ],
  27951. [
  27952. 1,
  27953. twoDimVert0
  27954. ],
  27955. [
  27956. 1,
  27957. twoDimVert0
  27958. ],
  27959. [
  27960. 1,
  27961. twoDimVert0
  27962. ],
  27963. [
  27964. 1,
  27965. twoDimVert0
  27966. ],
  27967. [
  27968. 1,
  27969. twoDimVert0
  27970. ],
  27971. [
  27972. 1,
  27973. twoDimVert0
  27974. ],
  27975. [
  27976. 1,
  27977. twoDimVert0
  27978. ],
  27979. [
  27980. 1,
  27981. twoDimVert0
  27982. ],
  27983. [
  27984. 1,
  27985. twoDimVert0
  27986. ],
  27987. [
  27988. 1,
  27989. twoDimVert0
  27990. ],
  27991. [
  27992. 1,
  27993. twoDimVert0
  27994. ],
  27995. [
  27996. 1,
  27997. twoDimVert0
  27998. ],
  27999. [
  28000. 1,
  28001. twoDimVert0
  28002. ],
  28003. [
  28004. 1,
  28005. twoDimVert0
  28006. ]
  28007. ];
  28008. var whiteTable1 = [
  28009. [
  28010. -1,
  28011. -1
  28012. ],
  28013. // 00000
  28014. [
  28015. 12,
  28016. ccittEOL
  28017. ],
  28018. // 00001
  28019. [
  28020. -1,
  28021. -1
  28022. ],
  28023. [
  28024. -1,
  28025. -1
  28026. ],
  28027. // 0001x
  28028. [
  28029. -1,
  28030. -1
  28031. ],
  28032. [
  28033. -1,
  28034. -1
  28035. ],
  28036. [
  28037. -1,
  28038. -1
  28039. ],
  28040. [
  28041. -1,
  28042. -1
  28043. ],
  28044. // 001xx
  28045. [
  28046. -1,
  28047. -1
  28048. ],
  28049. [
  28050. -1,
  28051. -1
  28052. ],
  28053. [
  28054. -1,
  28055. -1
  28056. ],
  28057. [
  28058. -1,
  28059. -1
  28060. ],
  28061. // 010xx
  28062. [
  28063. -1,
  28064. -1
  28065. ],
  28066. [
  28067. -1,
  28068. -1
  28069. ],
  28070. [
  28071. -1,
  28072. -1
  28073. ],
  28074. [
  28075. -1,
  28076. -1
  28077. ],
  28078. // 011xx
  28079. [
  28080. 11,
  28081. 1792
  28082. ],
  28083. [
  28084. 11,
  28085. 1792
  28086. ],
  28087. // 1000x
  28088. [
  28089. 12,
  28090. 1984
  28091. ],
  28092. // 10010
  28093. [
  28094. 12,
  28095. 2048
  28096. ],
  28097. // 10011
  28098. [
  28099. 12,
  28100. 2112
  28101. ],
  28102. // 10100
  28103. [
  28104. 12,
  28105. 2176
  28106. ],
  28107. // 10101
  28108. [
  28109. 12,
  28110. 2240
  28111. ],
  28112. // 10110
  28113. [
  28114. 12,
  28115. 2304
  28116. ],
  28117. // 10111
  28118. [
  28119. 11,
  28120. 1856
  28121. ],
  28122. [
  28123. 11,
  28124. 1856
  28125. ],
  28126. // 1100x
  28127. [
  28128. 11,
  28129. 1920
  28130. ],
  28131. [
  28132. 11,
  28133. 1920
  28134. ],
  28135. // 1101x
  28136. [
  28137. 12,
  28138. 2368
  28139. ],
  28140. // 11100
  28141. [
  28142. 12,
  28143. 2432
  28144. ],
  28145. // 11101
  28146. [
  28147. 12,
  28148. 2496
  28149. ],
  28150. // 11110
  28151. [
  28152. 12,
  28153. 2560
  28154. ]
  28155. ];
  28156. // 11111
  28157. var whiteTable2 = [
  28158. [
  28159. -1,
  28160. -1
  28161. ],
  28162. [
  28163. -1,
  28164. -1
  28165. ],
  28166. [
  28167. -1,
  28168. -1
  28169. ],
  28170. [
  28171. -1,
  28172. -1
  28173. ],
  28174. // 0000000xx
  28175. [
  28176. 8,
  28177. 29
  28178. ],
  28179. [
  28180. 8,
  28181. 29
  28182. ],
  28183. // 00000010x
  28184. [
  28185. 8,
  28186. 30
  28187. ],
  28188. [
  28189. 8,
  28190. 30
  28191. ],
  28192. // 00000011x
  28193. [
  28194. 8,
  28195. 45
  28196. ],
  28197. [
  28198. 8,
  28199. 45
  28200. ],
  28201. // 00000100x
  28202. [
  28203. 8,
  28204. 46
  28205. ],
  28206. [
  28207. 8,
  28208. 46
  28209. ],
  28210. // 00000101x
  28211. [
  28212. 7,
  28213. 22
  28214. ],
  28215. [
  28216. 7,
  28217. 22
  28218. ],
  28219. [
  28220. 7,
  28221. 22
  28222. ],
  28223. [
  28224. 7,
  28225. 22
  28226. ],
  28227. // 0000011xx
  28228. [
  28229. 7,
  28230. 23
  28231. ],
  28232. [
  28233. 7,
  28234. 23
  28235. ],
  28236. [
  28237. 7,
  28238. 23
  28239. ],
  28240. [
  28241. 7,
  28242. 23
  28243. ],
  28244. // 0000100xx
  28245. [
  28246. 8,
  28247. 47
  28248. ],
  28249. [
  28250. 8,
  28251. 47
  28252. ],
  28253. // 00001010x
  28254. [
  28255. 8,
  28256. 48
  28257. ],
  28258. [
  28259. 8,
  28260. 48
  28261. ],
  28262. // 00001011x
  28263. [
  28264. 6,
  28265. 13
  28266. ],
  28267. [
  28268. 6,
  28269. 13
  28270. ],
  28271. [
  28272. 6,
  28273. 13
  28274. ],
  28275. [
  28276. 6,
  28277. 13
  28278. ],
  28279. // 000011xxx
  28280. [
  28281. 6,
  28282. 13
  28283. ],
  28284. [
  28285. 6,
  28286. 13
  28287. ],
  28288. [
  28289. 6,
  28290. 13
  28291. ],
  28292. [
  28293. 6,
  28294. 13
  28295. ],
  28296. [
  28297. 7,
  28298. 20
  28299. ],
  28300. [
  28301. 7,
  28302. 20
  28303. ],
  28304. [
  28305. 7,
  28306. 20
  28307. ],
  28308. [
  28309. 7,
  28310. 20
  28311. ],
  28312. // 0001000xx
  28313. [
  28314. 8,
  28315. 33
  28316. ],
  28317. [
  28318. 8,
  28319. 33
  28320. ],
  28321. // 00010010x
  28322. [
  28323. 8,
  28324. 34
  28325. ],
  28326. [
  28327. 8,
  28328. 34
  28329. ],
  28330. // 00010011x
  28331. [
  28332. 8,
  28333. 35
  28334. ],
  28335. [
  28336. 8,
  28337. 35
  28338. ],
  28339. // 00010100x
  28340. [
  28341. 8,
  28342. 36
  28343. ],
  28344. [
  28345. 8,
  28346. 36
  28347. ],
  28348. // 00010101x
  28349. [
  28350. 8,
  28351. 37
  28352. ],
  28353. [
  28354. 8,
  28355. 37
  28356. ],
  28357. // 00010110x
  28358. [
  28359. 8,
  28360. 38
  28361. ],
  28362. [
  28363. 8,
  28364. 38
  28365. ],
  28366. // 00010111x
  28367. [
  28368. 7,
  28369. 19
  28370. ],
  28371. [
  28372. 7,
  28373. 19
  28374. ],
  28375. [
  28376. 7,
  28377. 19
  28378. ],
  28379. [
  28380. 7,
  28381. 19
  28382. ],
  28383. // 0001100xx
  28384. [
  28385. 8,
  28386. 31
  28387. ],
  28388. [
  28389. 8,
  28390. 31
  28391. ],
  28392. // 00011010x
  28393. [
  28394. 8,
  28395. 32
  28396. ],
  28397. [
  28398. 8,
  28399. 32
  28400. ],
  28401. // 00011011x
  28402. [
  28403. 6,
  28404. 1
  28405. ],
  28406. [
  28407. 6,
  28408. 1
  28409. ],
  28410. [
  28411. 6,
  28412. 1
  28413. ],
  28414. [
  28415. 6,
  28416. 1
  28417. ],
  28418. // 000111xxx
  28419. [
  28420. 6,
  28421. 1
  28422. ],
  28423. [
  28424. 6,
  28425. 1
  28426. ],
  28427. [
  28428. 6,
  28429. 1
  28430. ],
  28431. [
  28432. 6,
  28433. 1
  28434. ],
  28435. [
  28436. 6,
  28437. 12
  28438. ],
  28439. [
  28440. 6,
  28441. 12
  28442. ],
  28443. [
  28444. 6,
  28445. 12
  28446. ],
  28447. [
  28448. 6,
  28449. 12
  28450. ],
  28451. // 001000xxx
  28452. [
  28453. 6,
  28454. 12
  28455. ],
  28456. [
  28457. 6,
  28458. 12
  28459. ],
  28460. [
  28461. 6,
  28462. 12
  28463. ],
  28464. [
  28465. 6,
  28466. 12
  28467. ],
  28468. [
  28469. 8,
  28470. 53
  28471. ],
  28472. [
  28473. 8,
  28474. 53
  28475. ],
  28476. // 00100100x
  28477. [
  28478. 8,
  28479. 54
  28480. ],
  28481. [
  28482. 8,
  28483. 54
  28484. ],
  28485. // 00100101x
  28486. [
  28487. 7,
  28488. 26
  28489. ],
  28490. [
  28491. 7,
  28492. 26
  28493. ],
  28494. [
  28495. 7,
  28496. 26
  28497. ],
  28498. [
  28499. 7,
  28500. 26
  28501. ],
  28502. // 0010011xx
  28503. [
  28504. 8,
  28505. 39
  28506. ],
  28507. [
  28508. 8,
  28509. 39
  28510. ],
  28511. // 00101000x
  28512. [
  28513. 8,
  28514. 40
  28515. ],
  28516. [
  28517. 8,
  28518. 40
  28519. ],
  28520. // 00101001x
  28521. [
  28522. 8,
  28523. 41
  28524. ],
  28525. [
  28526. 8,
  28527. 41
  28528. ],
  28529. // 00101010x
  28530. [
  28531. 8,
  28532. 42
  28533. ],
  28534. [
  28535. 8,
  28536. 42
  28537. ],
  28538. // 00101011x
  28539. [
  28540. 8,
  28541. 43
  28542. ],
  28543. [
  28544. 8,
  28545. 43
  28546. ],
  28547. // 00101100x
  28548. [
  28549. 8,
  28550. 44
  28551. ],
  28552. [
  28553. 8,
  28554. 44
  28555. ],
  28556. // 00101101x
  28557. [
  28558. 7,
  28559. 21
  28560. ],
  28561. [
  28562. 7,
  28563. 21
  28564. ],
  28565. [
  28566. 7,
  28567. 21
  28568. ],
  28569. [
  28570. 7,
  28571. 21
  28572. ],
  28573. // 0010111xx
  28574. [
  28575. 7,
  28576. 28
  28577. ],
  28578. [
  28579. 7,
  28580. 28
  28581. ],
  28582. [
  28583. 7,
  28584. 28
  28585. ],
  28586. [
  28587. 7,
  28588. 28
  28589. ],
  28590. // 0011000xx
  28591. [
  28592. 8,
  28593. 61
  28594. ],
  28595. [
  28596. 8,
  28597. 61
  28598. ],
  28599. // 00110010x
  28600. [
  28601. 8,
  28602. 62
  28603. ],
  28604. [
  28605. 8,
  28606. 62
  28607. ],
  28608. // 00110011x
  28609. [
  28610. 8,
  28611. 63
  28612. ],
  28613. [
  28614. 8,
  28615. 63
  28616. ],
  28617. // 00110100x
  28618. [
  28619. 8,
  28620. 0
  28621. ],
  28622. [
  28623. 8,
  28624. 0
  28625. ],
  28626. // 00110101x
  28627. [
  28628. 8,
  28629. 320
  28630. ],
  28631. [
  28632. 8,
  28633. 320
  28634. ],
  28635. // 00110110x
  28636. [
  28637. 8,
  28638. 384
  28639. ],
  28640. [
  28641. 8,
  28642. 384
  28643. ],
  28644. // 00110111x
  28645. [
  28646. 5,
  28647. 10
  28648. ],
  28649. [
  28650. 5,
  28651. 10
  28652. ],
  28653. [
  28654. 5,
  28655. 10
  28656. ],
  28657. [
  28658. 5,
  28659. 10
  28660. ],
  28661. // 00111xxxx
  28662. [
  28663. 5,
  28664. 10
  28665. ],
  28666. [
  28667. 5,
  28668. 10
  28669. ],
  28670. [
  28671. 5,
  28672. 10
  28673. ],
  28674. [
  28675. 5,
  28676. 10
  28677. ],
  28678. [
  28679. 5,
  28680. 10
  28681. ],
  28682. [
  28683. 5,
  28684. 10
  28685. ],
  28686. [
  28687. 5,
  28688. 10
  28689. ],
  28690. [
  28691. 5,
  28692. 10
  28693. ],
  28694. [
  28695. 5,
  28696. 10
  28697. ],
  28698. [
  28699. 5,
  28700. 10
  28701. ],
  28702. [
  28703. 5,
  28704. 10
  28705. ],
  28706. [
  28707. 5,
  28708. 10
  28709. ],
  28710. [
  28711. 5,
  28712. 11
  28713. ],
  28714. [
  28715. 5,
  28716. 11
  28717. ],
  28718. [
  28719. 5,
  28720. 11
  28721. ],
  28722. [
  28723. 5,
  28724. 11
  28725. ],
  28726. // 01000xxxx
  28727. [
  28728. 5,
  28729. 11
  28730. ],
  28731. [
  28732. 5,
  28733. 11
  28734. ],
  28735. [
  28736. 5,
  28737. 11
  28738. ],
  28739. [
  28740. 5,
  28741. 11
  28742. ],
  28743. [
  28744. 5,
  28745. 11
  28746. ],
  28747. [
  28748. 5,
  28749. 11
  28750. ],
  28751. [
  28752. 5,
  28753. 11
  28754. ],
  28755. [
  28756. 5,
  28757. 11
  28758. ],
  28759. [
  28760. 5,
  28761. 11
  28762. ],
  28763. [
  28764. 5,
  28765. 11
  28766. ],
  28767. [
  28768. 5,
  28769. 11
  28770. ],
  28771. [
  28772. 5,
  28773. 11
  28774. ],
  28775. [
  28776. 7,
  28777. 27
  28778. ],
  28779. [
  28780. 7,
  28781. 27
  28782. ],
  28783. [
  28784. 7,
  28785. 27
  28786. ],
  28787. [
  28788. 7,
  28789. 27
  28790. ],
  28791. // 0100100xx
  28792. [
  28793. 8,
  28794. 59
  28795. ],
  28796. [
  28797. 8,
  28798. 59
  28799. ],
  28800. // 01001010x
  28801. [
  28802. 8,
  28803. 60
  28804. ],
  28805. [
  28806. 8,
  28807. 60
  28808. ],
  28809. // 01001011x
  28810. [
  28811. 9,
  28812. 1472
  28813. ],
  28814. // 010011000
  28815. [
  28816. 9,
  28817. 1536
  28818. ],
  28819. // 010011001
  28820. [
  28821. 9,
  28822. 1600
  28823. ],
  28824. // 010011010
  28825. [
  28826. 9,
  28827. 1728
  28828. ],
  28829. // 010011011
  28830. [
  28831. 7,
  28832. 18
  28833. ],
  28834. [
  28835. 7,
  28836. 18
  28837. ],
  28838. [
  28839. 7,
  28840. 18
  28841. ],
  28842. [
  28843. 7,
  28844. 18
  28845. ],
  28846. // 0100111xx
  28847. [
  28848. 7,
  28849. 24
  28850. ],
  28851. [
  28852. 7,
  28853. 24
  28854. ],
  28855. [
  28856. 7,
  28857. 24
  28858. ],
  28859. [
  28860. 7,
  28861. 24
  28862. ],
  28863. // 0101000xx
  28864. [
  28865. 8,
  28866. 49
  28867. ],
  28868. [
  28869. 8,
  28870. 49
  28871. ],
  28872. // 01010010x
  28873. [
  28874. 8,
  28875. 50
  28876. ],
  28877. [
  28878. 8,
  28879. 50
  28880. ],
  28881. // 01010011x
  28882. [
  28883. 8,
  28884. 51
  28885. ],
  28886. [
  28887. 8,
  28888. 51
  28889. ],
  28890. // 01010100x
  28891. [
  28892. 8,
  28893. 52
  28894. ],
  28895. [
  28896. 8,
  28897. 52
  28898. ],
  28899. // 01010101x
  28900. [
  28901. 7,
  28902. 25
  28903. ],
  28904. [
  28905. 7,
  28906. 25
  28907. ],
  28908. [
  28909. 7,
  28910. 25
  28911. ],
  28912. [
  28913. 7,
  28914. 25
  28915. ],
  28916. // 0101011xx
  28917. [
  28918. 8,
  28919. 55
  28920. ],
  28921. [
  28922. 8,
  28923. 55
  28924. ],
  28925. // 01011000x
  28926. [
  28927. 8,
  28928. 56
  28929. ],
  28930. [
  28931. 8,
  28932. 56
  28933. ],
  28934. // 01011001x
  28935. [
  28936. 8,
  28937. 57
  28938. ],
  28939. [
  28940. 8,
  28941. 57
  28942. ],
  28943. // 01011010x
  28944. [
  28945. 8,
  28946. 58
  28947. ],
  28948. [
  28949. 8,
  28950. 58
  28951. ],
  28952. // 01011011x
  28953. [
  28954. 6,
  28955. 192
  28956. ],
  28957. [
  28958. 6,
  28959. 192
  28960. ],
  28961. [
  28962. 6,
  28963. 192
  28964. ],
  28965. [
  28966. 6,
  28967. 192
  28968. ],
  28969. // 010111xxx
  28970. [
  28971. 6,
  28972. 192
  28973. ],
  28974. [
  28975. 6,
  28976. 192
  28977. ],
  28978. [
  28979. 6,
  28980. 192
  28981. ],
  28982. [
  28983. 6,
  28984. 192
  28985. ],
  28986. [
  28987. 6,
  28988. 1664
  28989. ],
  28990. [
  28991. 6,
  28992. 1664
  28993. ],
  28994. [
  28995. 6,
  28996. 1664
  28997. ],
  28998. [
  28999. 6,
  29000. 1664
  29001. ],
  29002. // 011000xxx
  29003. [
  29004. 6,
  29005. 1664
  29006. ],
  29007. [
  29008. 6,
  29009. 1664
  29010. ],
  29011. [
  29012. 6,
  29013. 1664
  29014. ],
  29015. [
  29016. 6,
  29017. 1664
  29018. ],
  29019. [
  29020. 8,
  29021. 448
  29022. ],
  29023. [
  29024. 8,
  29025. 448
  29026. ],
  29027. // 01100100x
  29028. [
  29029. 8,
  29030. 512
  29031. ],
  29032. [
  29033. 8,
  29034. 512
  29035. ],
  29036. // 01100101x
  29037. [
  29038. 9,
  29039. 704
  29040. ],
  29041. // 011001100
  29042. [
  29043. 9,
  29044. 768
  29045. ],
  29046. // 011001101
  29047. [
  29048. 8,
  29049. 640
  29050. ],
  29051. [
  29052. 8,
  29053. 640
  29054. ],
  29055. // 01100111x
  29056. [
  29057. 8,
  29058. 576
  29059. ],
  29060. [
  29061. 8,
  29062. 576
  29063. ],
  29064. // 01101000x
  29065. [
  29066. 9,
  29067. 832
  29068. ],
  29069. // 011010010
  29070. [
  29071. 9,
  29072. 896
  29073. ],
  29074. // 011010011
  29075. [
  29076. 9,
  29077. 960
  29078. ],
  29079. // 011010100
  29080. [
  29081. 9,
  29082. 1024
  29083. ],
  29084. // 011010101
  29085. [
  29086. 9,
  29087. 1088
  29088. ],
  29089. // 011010110
  29090. [
  29091. 9,
  29092. 1152
  29093. ],
  29094. // 011010111
  29095. [
  29096. 9,
  29097. 1216
  29098. ],
  29099. // 011011000
  29100. [
  29101. 9,
  29102. 1280
  29103. ],
  29104. // 011011001
  29105. [
  29106. 9,
  29107. 1344
  29108. ],
  29109. // 011011010
  29110. [
  29111. 9,
  29112. 1408
  29113. ],
  29114. // 011011011
  29115. [
  29116. 7,
  29117. 256
  29118. ],
  29119. [
  29120. 7,
  29121. 256
  29122. ],
  29123. [
  29124. 7,
  29125. 256
  29126. ],
  29127. [
  29128. 7,
  29129. 256
  29130. ],
  29131. // 0110111xx
  29132. [
  29133. 4,
  29134. 2
  29135. ],
  29136. [
  29137. 4,
  29138. 2
  29139. ],
  29140. [
  29141. 4,
  29142. 2
  29143. ],
  29144. [
  29145. 4,
  29146. 2
  29147. ],
  29148. // 0111xxxxx
  29149. [
  29150. 4,
  29151. 2
  29152. ],
  29153. [
  29154. 4,
  29155. 2
  29156. ],
  29157. [
  29158. 4,
  29159. 2
  29160. ],
  29161. [
  29162. 4,
  29163. 2
  29164. ],
  29165. [
  29166. 4,
  29167. 2
  29168. ],
  29169. [
  29170. 4,
  29171. 2
  29172. ],
  29173. [
  29174. 4,
  29175. 2
  29176. ],
  29177. [
  29178. 4,
  29179. 2
  29180. ],
  29181. [
  29182. 4,
  29183. 2
  29184. ],
  29185. [
  29186. 4,
  29187. 2
  29188. ],
  29189. [
  29190. 4,
  29191. 2
  29192. ],
  29193. [
  29194. 4,
  29195. 2
  29196. ],
  29197. [
  29198. 4,
  29199. 2
  29200. ],
  29201. [
  29202. 4,
  29203. 2
  29204. ],
  29205. [
  29206. 4,
  29207. 2
  29208. ],
  29209. [
  29210. 4,
  29211. 2
  29212. ],
  29213. [
  29214. 4,
  29215. 2
  29216. ],
  29217. [
  29218. 4,
  29219. 2
  29220. ],
  29221. [
  29222. 4,
  29223. 2
  29224. ],
  29225. [
  29226. 4,
  29227. 2
  29228. ],
  29229. [
  29230. 4,
  29231. 2
  29232. ],
  29233. [
  29234. 4,
  29235. 2
  29236. ],
  29237. [
  29238. 4,
  29239. 2
  29240. ],
  29241. [
  29242. 4,
  29243. 2
  29244. ],
  29245. [
  29246. 4,
  29247. 2
  29248. ],
  29249. [
  29250. 4,
  29251. 2
  29252. ],
  29253. [
  29254. 4,
  29255. 2
  29256. ],
  29257. [
  29258. 4,
  29259. 2
  29260. ],
  29261. [
  29262. 4,
  29263. 3
  29264. ],
  29265. [
  29266. 4,
  29267. 3
  29268. ],
  29269. [
  29270. 4,
  29271. 3
  29272. ],
  29273. [
  29274. 4,
  29275. 3
  29276. ],
  29277. // 1000xxxxx
  29278. [
  29279. 4,
  29280. 3
  29281. ],
  29282. [
  29283. 4,
  29284. 3
  29285. ],
  29286. [
  29287. 4,
  29288. 3
  29289. ],
  29290. [
  29291. 4,
  29292. 3
  29293. ],
  29294. [
  29295. 4,
  29296. 3
  29297. ],
  29298. [
  29299. 4,
  29300. 3
  29301. ],
  29302. [
  29303. 4,
  29304. 3
  29305. ],
  29306. [
  29307. 4,
  29308. 3
  29309. ],
  29310. [
  29311. 4,
  29312. 3
  29313. ],
  29314. [
  29315. 4,
  29316. 3
  29317. ],
  29318. [
  29319. 4,
  29320. 3
  29321. ],
  29322. [
  29323. 4,
  29324. 3
  29325. ],
  29326. [
  29327. 4,
  29328. 3
  29329. ],
  29330. [
  29331. 4,
  29332. 3
  29333. ],
  29334. [
  29335. 4,
  29336. 3
  29337. ],
  29338. [
  29339. 4,
  29340. 3
  29341. ],
  29342. [
  29343. 4,
  29344. 3
  29345. ],
  29346. [
  29347. 4,
  29348. 3
  29349. ],
  29350. [
  29351. 4,
  29352. 3
  29353. ],
  29354. [
  29355. 4,
  29356. 3
  29357. ],
  29358. [
  29359. 4,
  29360. 3
  29361. ],
  29362. [
  29363. 4,
  29364. 3
  29365. ],
  29366. [
  29367. 4,
  29368. 3
  29369. ],
  29370. [
  29371. 4,
  29372. 3
  29373. ],
  29374. [
  29375. 4,
  29376. 3
  29377. ],
  29378. [
  29379. 4,
  29380. 3
  29381. ],
  29382. [
  29383. 4,
  29384. 3
  29385. ],
  29386. [
  29387. 4,
  29388. 3
  29389. ],
  29390. [
  29391. 5,
  29392. 128
  29393. ],
  29394. [
  29395. 5,
  29396. 128
  29397. ],
  29398. [
  29399. 5,
  29400. 128
  29401. ],
  29402. [
  29403. 5,
  29404. 128
  29405. ],
  29406. // 10010xxxx
  29407. [
  29408. 5,
  29409. 128
  29410. ],
  29411. [
  29412. 5,
  29413. 128
  29414. ],
  29415. [
  29416. 5,
  29417. 128
  29418. ],
  29419. [
  29420. 5,
  29421. 128
  29422. ],
  29423. [
  29424. 5,
  29425. 128
  29426. ],
  29427. [
  29428. 5,
  29429. 128
  29430. ],
  29431. [
  29432. 5,
  29433. 128
  29434. ],
  29435. [
  29436. 5,
  29437. 128
  29438. ],
  29439. [
  29440. 5,
  29441. 128
  29442. ],
  29443. [
  29444. 5,
  29445. 128
  29446. ],
  29447. [
  29448. 5,
  29449. 128
  29450. ],
  29451. [
  29452. 5,
  29453. 128
  29454. ],
  29455. [
  29456. 5,
  29457. 8
  29458. ],
  29459. [
  29460. 5,
  29461. 8
  29462. ],
  29463. [
  29464. 5,
  29465. 8
  29466. ],
  29467. [
  29468. 5,
  29469. 8
  29470. ],
  29471. // 10011xxxx
  29472. [
  29473. 5,
  29474. 8
  29475. ],
  29476. [
  29477. 5,
  29478. 8
  29479. ],
  29480. [
  29481. 5,
  29482. 8
  29483. ],
  29484. [
  29485. 5,
  29486. 8
  29487. ],
  29488. [
  29489. 5,
  29490. 8
  29491. ],
  29492. [
  29493. 5,
  29494. 8
  29495. ],
  29496. [
  29497. 5,
  29498. 8
  29499. ],
  29500. [
  29501. 5,
  29502. 8
  29503. ],
  29504. [
  29505. 5,
  29506. 8
  29507. ],
  29508. [
  29509. 5,
  29510. 8
  29511. ],
  29512. [
  29513. 5,
  29514. 8
  29515. ],
  29516. [
  29517. 5,
  29518. 8
  29519. ],
  29520. [
  29521. 5,
  29522. 9
  29523. ],
  29524. [
  29525. 5,
  29526. 9
  29527. ],
  29528. [
  29529. 5,
  29530. 9
  29531. ],
  29532. [
  29533. 5,
  29534. 9
  29535. ],
  29536. // 10100xxxx
  29537. [
  29538. 5,
  29539. 9
  29540. ],
  29541. [
  29542. 5,
  29543. 9
  29544. ],
  29545. [
  29546. 5,
  29547. 9
  29548. ],
  29549. [
  29550. 5,
  29551. 9
  29552. ],
  29553. [
  29554. 5,
  29555. 9
  29556. ],
  29557. [
  29558. 5,
  29559. 9
  29560. ],
  29561. [
  29562. 5,
  29563. 9
  29564. ],
  29565. [
  29566. 5,
  29567. 9
  29568. ],
  29569. [
  29570. 5,
  29571. 9
  29572. ],
  29573. [
  29574. 5,
  29575. 9
  29576. ],
  29577. [
  29578. 5,
  29579. 9
  29580. ],
  29581. [
  29582. 5,
  29583. 9
  29584. ],
  29585. [
  29586. 6,
  29587. 16
  29588. ],
  29589. [
  29590. 6,
  29591. 16
  29592. ],
  29593. [
  29594. 6,
  29595. 16
  29596. ],
  29597. [
  29598. 6,
  29599. 16
  29600. ],
  29601. // 101010xxx
  29602. [
  29603. 6,
  29604. 16
  29605. ],
  29606. [
  29607. 6,
  29608. 16
  29609. ],
  29610. [
  29611. 6,
  29612. 16
  29613. ],
  29614. [
  29615. 6,
  29616. 16
  29617. ],
  29618. [
  29619. 6,
  29620. 17
  29621. ],
  29622. [
  29623. 6,
  29624. 17
  29625. ],
  29626. [
  29627. 6,
  29628. 17
  29629. ],
  29630. [
  29631. 6,
  29632. 17
  29633. ],
  29634. // 101011xxx
  29635. [
  29636. 6,
  29637. 17
  29638. ],
  29639. [
  29640. 6,
  29641. 17
  29642. ],
  29643. [
  29644. 6,
  29645. 17
  29646. ],
  29647. [
  29648. 6,
  29649. 17
  29650. ],
  29651. [
  29652. 4,
  29653. 4
  29654. ],
  29655. [
  29656. 4,
  29657. 4
  29658. ],
  29659. [
  29660. 4,
  29661. 4
  29662. ],
  29663. [
  29664. 4,
  29665. 4
  29666. ],
  29667. // 1011xxxxx
  29668. [
  29669. 4,
  29670. 4
  29671. ],
  29672. [
  29673. 4,
  29674. 4
  29675. ],
  29676. [
  29677. 4,
  29678. 4
  29679. ],
  29680. [
  29681. 4,
  29682. 4
  29683. ],
  29684. [
  29685. 4,
  29686. 4
  29687. ],
  29688. [
  29689. 4,
  29690. 4
  29691. ],
  29692. [
  29693. 4,
  29694. 4
  29695. ],
  29696. [
  29697. 4,
  29698. 4
  29699. ],
  29700. [
  29701. 4,
  29702. 4
  29703. ],
  29704. [
  29705. 4,
  29706. 4
  29707. ],
  29708. [
  29709. 4,
  29710. 4
  29711. ],
  29712. [
  29713. 4,
  29714. 4
  29715. ],
  29716. [
  29717. 4,
  29718. 4
  29719. ],
  29720. [
  29721. 4,
  29722. 4
  29723. ],
  29724. [
  29725. 4,
  29726. 4
  29727. ],
  29728. [
  29729. 4,
  29730. 4
  29731. ],
  29732. [
  29733. 4,
  29734. 4
  29735. ],
  29736. [
  29737. 4,
  29738. 4
  29739. ],
  29740. [
  29741. 4,
  29742. 4
  29743. ],
  29744. [
  29745. 4,
  29746. 4
  29747. ],
  29748. [
  29749. 4,
  29750. 4
  29751. ],
  29752. [
  29753. 4,
  29754. 4
  29755. ],
  29756. [
  29757. 4,
  29758. 4
  29759. ],
  29760. [
  29761. 4,
  29762. 4
  29763. ],
  29764. [
  29765. 4,
  29766. 4
  29767. ],
  29768. [
  29769. 4,
  29770. 4
  29771. ],
  29772. [
  29773. 4,
  29774. 4
  29775. ],
  29776. [
  29777. 4,
  29778. 4
  29779. ],
  29780. [
  29781. 4,
  29782. 5
  29783. ],
  29784. [
  29785. 4,
  29786. 5
  29787. ],
  29788. [
  29789. 4,
  29790. 5
  29791. ],
  29792. [
  29793. 4,
  29794. 5
  29795. ],
  29796. // 1100xxxxx
  29797. [
  29798. 4,
  29799. 5
  29800. ],
  29801. [
  29802. 4,
  29803. 5
  29804. ],
  29805. [
  29806. 4,
  29807. 5
  29808. ],
  29809. [
  29810. 4,
  29811. 5
  29812. ],
  29813. [
  29814. 4,
  29815. 5
  29816. ],
  29817. [
  29818. 4,
  29819. 5
  29820. ],
  29821. [
  29822. 4,
  29823. 5
  29824. ],
  29825. [
  29826. 4,
  29827. 5
  29828. ],
  29829. [
  29830. 4,
  29831. 5
  29832. ],
  29833. [
  29834. 4,
  29835. 5
  29836. ],
  29837. [
  29838. 4,
  29839. 5
  29840. ],
  29841. [
  29842. 4,
  29843. 5
  29844. ],
  29845. [
  29846. 4,
  29847. 5
  29848. ],
  29849. [
  29850. 4,
  29851. 5
  29852. ],
  29853. [
  29854. 4,
  29855. 5
  29856. ],
  29857. [
  29858. 4,
  29859. 5
  29860. ],
  29861. [
  29862. 4,
  29863. 5
  29864. ],
  29865. [
  29866. 4,
  29867. 5
  29868. ],
  29869. [
  29870. 4,
  29871. 5
  29872. ],
  29873. [
  29874. 4,
  29875. 5
  29876. ],
  29877. [
  29878. 4,
  29879. 5
  29880. ],
  29881. [
  29882. 4,
  29883. 5
  29884. ],
  29885. [
  29886. 4,
  29887. 5
  29888. ],
  29889. [
  29890. 4,
  29891. 5
  29892. ],
  29893. [
  29894. 4,
  29895. 5
  29896. ],
  29897. [
  29898. 4,
  29899. 5
  29900. ],
  29901. [
  29902. 4,
  29903. 5
  29904. ],
  29905. [
  29906. 4,
  29907. 5
  29908. ],
  29909. [
  29910. 6,
  29911. 14
  29912. ],
  29913. [
  29914. 6,
  29915. 14
  29916. ],
  29917. [
  29918. 6,
  29919. 14
  29920. ],
  29921. [
  29922. 6,
  29923. 14
  29924. ],
  29925. // 110100xxx
  29926. [
  29927. 6,
  29928. 14
  29929. ],
  29930. [
  29931. 6,
  29932. 14
  29933. ],
  29934. [
  29935. 6,
  29936. 14
  29937. ],
  29938. [
  29939. 6,
  29940. 14
  29941. ],
  29942. [
  29943. 6,
  29944. 15
  29945. ],
  29946. [
  29947. 6,
  29948. 15
  29949. ],
  29950. [
  29951. 6,
  29952. 15
  29953. ],
  29954. [
  29955. 6,
  29956. 15
  29957. ],
  29958. // 110101xxx
  29959. [
  29960. 6,
  29961. 15
  29962. ],
  29963. [
  29964. 6,
  29965. 15
  29966. ],
  29967. [
  29968. 6,
  29969. 15
  29970. ],
  29971. [
  29972. 6,
  29973. 15
  29974. ],
  29975. [
  29976. 5,
  29977. 64
  29978. ],
  29979. [
  29980. 5,
  29981. 64
  29982. ],
  29983. [
  29984. 5,
  29985. 64
  29986. ],
  29987. [
  29988. 5,
  29989. 64
  29990. ],
  29991. // 11011xxxx
  29992. [
  29993. 5,
  29994. 64
  29995. ],
  29996. [
  29997. 5,
  29998. 64
  29999. ],
  30000. [
  30001. 5,
  30002. 64
  30003. ],
  30004. [
  30005. 5,
  30006. 64
  30007. ],
  30008. [
  30009. 5,
  30010. 64
  30011. ],
  30012. [
  30013. 5,
  30014. 64
  30015. ],
  30016. [
  30017. 5,
  30018. 64
  30019. ],
  30020. [
  30021. 5,
  30022. 64
  30023. ],
  30024. [
  30025. 5,
  30026. 64
  30027. ],
  30028. [
  30029. 5,
  30030. 64
  30031. ],
  30032. [
  30033. 5,
  30034. 64
  30035. ],
  30036. [
  30037. 5,
  30038. 64
  30039. ],
  30040. [
  30041. 4,
  30042. 6
  30043. ],
  30044. [
  30045. 4,
  30046. 6
  30047. ],
  30048. [
  30049. 4,
  30050. 6
  30051. ],
  30052. [
  30053. 4,
  30054. 6
  30055. ],
  30056. // 1110xxxxx
  30057. [
  30058. 4,
  30059. 6
  30060. ],
  30061. [
  30062. 4,
  30063. 6
  30064. ],
  30065. [
  30066. 4,
  30067. 6
  30068. ],
  30069. [
  30070. 4,
  30071. 6
  30072. ],
  30073. [
  30074. 4,
  30075. 6
  30076. ],
  30077. [
  30078. 4,
  30079. 6
  30080. ],
  30081. [
  30082. 4,
  30083. 6
  30084. ],
  30085. [
  30086. 4,
  30087. 6
  30088. ],
  30089. [
  30090. 4,
  30091. 6
  30092. ],
  30093. [
  30094. 4,
  30095. 6
  30096. ],
  30097. [
  30098. 4,
  30099. 6
  30100. ],
  30101. [
  30102. 4,
  30103. 6
  30104. ],
  30105. [
  30106. 4,
  30107. 6
  30108. ],
  30109. [
  30110. 4,
  30111. 6
  30112. ],
  30113. [
  30114. 4,
  30115. 6
  30116. ],
  30117. [
  30118. 4,
  30119. 6
  30120. ],
  30121. [
  30122. 4,
  30123. 6
  30124. ],
  30125. [
  30126. 4,
  30127. 6
  30128. ],
  30129. [
  30130. 4,
  30131. 6
  30132. ],
  30133. [
  30134. 4,
  30135. 6
  30136. ],
  30137. [
  30138. 4,
  30139. 6
  30140. ],
  30141. [
  30142. 4,
  30143. 6
  30144. ],
  30145. [
  30146. 4,
  30147. 6
  30148. ],
  30149. [
  30150. 4,
  30151. 6
  30152. ],
  30153. [
  30154. 4,
  30155. 6
  30156. ],
  30157. [
  30158. 4,
  30159. 6
  30160. ],
  30161. [
  30162. 4,
  30163. 6
  30164. ],
  30165. [
  30166. 4,
  30167. 6
  30168. ],
  30169. [
  30170. 4,
  30171. 7
  30172. ],
  30173. [
  30174. 4,
  30175. 7
  30176. ],
  30177. [
  30178. 4,
  30179. 7
  30180. ],
  30181. [
  30182. 4,
  30183. 7
  30184. ],
  30185. // 1111xxxxx
  30186. [
  30187. 4,
  30188. 7
  30189. ],
  30190. [
  30191. 4,
  30192. 7
  30193. ],
  30194. [
  30195. 4,
  30196. 7
  30197. ],
  30198. [
  30199. 4,
  30200. 7
  30201. ],
  30202. [
  30203. 4,
  30204. 7
  30205. ],
  30206. [
  30207. 4,
  30208. 7
  30209. ],
  30210. [
  30211. 4,
  30212. 7
  30213. ],
  30214. [
  30215. 4,
  30216. 7
  30217. ],
  30218. [
  30219. 4,
  30220. 7
  30221. ],
  30222. [
  30223. 4,
  30224. 7
  30225. ],
  30226. [
  30227. 4,
  30228. 7
  30229. ],
  30230. [
  30231. 4,
  30232. 7
  30233. ],
  30234. [
  30235. 4,
  30236. 7
  30237. ],
  30238. [
  30239. 4,
  30240. 7
  30241. ],
  30242. [
  30243. 4,
  30244. 7
  30245. ],
  30246. [
  30247. 4,
  30248. 7
  30249. ],
  30250. [
  30251. 4,
  30252. 7
  30253. ],
  30254. [
  30255. 4,
  30256. 7
  30257. ],
  30258. [
  30259. 4,
  30260. 7
  30261. ],
  30262. [
  30263. 4,
  30264. 7
  30265. ],
  30266. [
  30267. 4,
  30268. 7
  30269. ],
  30270. [
  30271. 4,
  30272. 7
  30273. ],
  30274. [
  30275. 4,
  30276. 7
  30277. ],
  30278. [
  30279. 4,
  30280. 7
  30281. ],
  30282. [
  30283. 4,
  30284. 7
  30285. ],
  30286. [
  30287. 4,
  30288. 7
  30289. ],
  30290. [
  30291. 4,
  30292. 7
  30293. ],
  30294. [
  30295. 4,
  30296. 7
  30297. ]
  30298. ];
  30299. var blackTable1 = [
  30300. [
  30301. -1,
  30302. -1
  30303. ],
  30304. [
  30305. -1,
  30306. -1
  30307. ],
  30308. // 000000000000x
  30309. [
  30310. 12,
  30311. ccittEOL
  30312. ],
  30313. [
  30314. 12,
  30315. ccittEOL
  30316. ],
  30317. // 000000000001x
  30318. [
  30319. -1,
  30320. -1
  30321. ],
  30322. [
  30323. -1,
  30324. -1
  30325. ],
  30326. [
  30327. -1,
  30328. -1
  30329. ],
  30330. [
  30331. -1,
  30332. -1
  30333. ],
  30334. // 00000000001xx
  30335. [
  30336. -1,
  30337. -1
  30338. ],
  30339. [
  30340. -1,
  30341. -1
  30342. ],
  30343. [
  30344. -1,
  30345. -1
  30346. ],
  30347. [
  30348. -1,
  30349. -1
  30350. ],
  30351. // 00000000010xx
  30352. [
  30353. -1,
  30354. -1
  30355. ],
  30356. [
  30357. -1,
  30358. -1
  30359. ],
  30360. [
  30361. -1,
  30362. -1
  30363. ],
  30364. [
  30365. -1,
  30366. -1
  30367. ],
  30368. // 00000000011xx
  30369. [
  30370. -1,
  30371. -1
  30372. ],
  30373. [
  30374. -1,
  30375. -1
  30376. ],
  30377. [
  30378. -1,
  30379. -1
  30380. ],
  30381. [
  30382. -1,
  30383. -1
  30384. ],
  30385. // 00000000100xx
  30386. [
  30387. -1,
  30388. -1
  30389. ],
  30390. [
  30391. -1,
  30392. -1
  30393. ],
  30394. [
  30395. -1,
  30396. -1
  30397. ],
  30398. [
  30399. -1,
  30400. -1
  30401. ],
  30402. // 00000000101xx
  30403. [
  30404. -1,
  30405. -1
  30406. ],
  30407. [
  30408. -1,
  30409. -1
  30410. ],
  30411. [
  30412. -1,
  30413. -1
  30414. ],
  30415. [
  30416. -1,
  30417. -1
  30418. ],
  30419. // 00000000110xx
  30420. [
  30421. -1,
  30422. -1
  30423. ],
  30424. [
  30425. -1,
  30426. -1
  30427. ],
  30428. [
  30429. -1,
  30430. -1
  30431. ],
  30432. [
  30433. -1,
  30434. -1
  30435. ],
  30436. // 00000000111xx
  30437. [
  30438. 11,
  30439. 1792
  30440. ],
  30441. [
  30442. 11,
  30443. 1792
  30444. ],
  30445. [
  30446. 11,
  30447. 1792
  30448. ],
  30449. [
  30450. 11,
  30451. 1792
  30452. ],
  30453. // 00000001000xx
  30454. [
  30455. 12,
  30456. 1984
  30457. ],
  30458. [
  30459. 12,
  30460. 1984
  30461. ],
  30462. // 000000010010x
  30463. [
  30464. 12,
  30465. 2048
  30466. ],
  30467. [
  30468. 12,
  30469. 2048
  30470. ],
  30471. // 000000010011x
  30472. [
  30473. 12,
  30474. 2112
  30475. ],
  30476. [
  30477. 12,
  30478. 2112
  30479. ],
  30480. // 000000010100x
  30481. [
  30482. 12,
  30483. 2176
  30484. ],
  30485. [
  30486. 12,
  30487. 2176
  30488. ],
  30489. // 000000010101x
  30490. [
  30491. 12,
  30492. 2240
  30493. ],
  30494. [
  30495. 12,
  30496. 2240
  30497. ],
  30498. // 000000010110x
  30499. [
  30500. 12,
  30501. 2304
  30502. ],
  30503. [
  30504. 12,
  30505. 2304
  30506. ],
  30507. // 000000010111x
  30508. [
  30509. 11,
  30510. 1856
  30511. ],
  30512. [
  30513. 11,
  30514. 1856
  30515. ],
  30516. [
  30517. 11,
  30518. 1856
  30519. ],
  30520. [
  30521. 11,
  30522. 1856
  30523. ],
  30524. // 00000001100xx
  30525. [
  30526. 11,
  30527. 1920
  30528. ],
  30529. [
  30530. 11,
  30531. 1920
  30532. ],
  30533. [
  30534. 11,
  30535. 1920
  30536. ],
  30537. [
  30538. 11,
  30539. 1920
  30540. ],
  30541. // 00000001101xx
  30542. [
  30543. 12,
  30544. 2368
  30545. ],
  30546. [
  30547. 12,
  30548. 2368
  30549. ],
  30550. // 000000011100x
  30551. [
  30552. 12,
  30553. 2432
  30554. ],
  30555. [
  30556. 12,
  30557. 2432
  30558. ],
  30559. // 000000011101x
  30560. [
  30561. 12,
  30562. 2496
  30563. ],
  30564. [
  30565. 12,
  30566. 2496
  30567. ],
  30568. // 000000011110x
  30569. [
  30570. 12,
  30571. 2560
  30572. ],
  30573. [
  30574. 12,
  30575. 2560
  30576. ],
  30577. // 000000011111x
  30578. [
  30579. 10,
  30580. 18
  30581. ],
  30582. [
  30583. 10,
  30584. 18
  30585. ],
  30586. [
  30587. 10,
  30588. 18
  30589. ],
  30590. [
  30591. 10,
  30592. 18
  30593. ],
  30594. // 0000001000xxx
  30595. [
  30596. 10,
  30597. 18
  30598. ],
  30599. [
  30600. 10,
  30601. 18
  30602. ],
  30603. [
  30604. 10,
  30605. 18
  30606. ],
  30607. [
  30608. 10,
  30609. 18
  30610. ],
  30611. [
  30612. 12,
  30613. 52
  30614. ],
  30615. [
  30616. 12,
  30617. 52
  30618. ],
  30619. // 000000100100x
  30620. [
  30621. 13,
  30622. 640
  30623. ],
  30624. // 0000001001010
  30625. [
  30626. 13,
  30627. 704
  30628. ],
  30629. // 0000001001011
  30630. [
  30631. 13,
  30632. 768
  30633. ],
  30634. // 0000001001100
  30635. [
  30636. 13,
  30637. 832
  30638. ],
  30639. // 0000001001101
  30640. [
  30641. 12,
  30642. 55
  30643. ],
  30644. [
  30645. 12,
  30646. 55
  30647. ],
  30648. // 000000100111x
  30649. [
  30650. 12,
  30651. 56
  30652. ],
  30653. [
  30654. 12,
  30655. 56
  30656. ],
  30657. // 000000101000x
  30658. [
  30659. 13,
  30660. 1280
  30661. ],
  30662. // 0000001010010
  30663. [
  30664. 13,
  30665. 1344
  30666. ],
  30667. // 0000001010011
  30668. [
  30669. 13,
  30670. 1408
  30671. ],
  30672. // 0000001010100
  30673. [
  30674. 13,
  30675. 1472
  30676. ],
  30677. // 0000001010101
  30678. [
  30679. 12,
  30680. 59
  30681. ],
  30682. [
  30683. 12,
  30684. 59
  30685. ],
  30686. // 000000101011x
  30687. [
  30688. 12,
  30689. 60
  30690. ],
  30691. [
  30692. 12,
  30693. 60
  30694. ],
  30695. // 000000101100x
  30696. [
  30697. 13,
  30698. 1536
  30699. ],
  30700. // 0000001011010
  30701. [
  30702. 13,
  30703. 1600
  30704. ],
  30705. // 0000001011011
  30706. [
  30707. 11,
  30708. 24
  30709. ],
  30710. [
  30711. 11,
  30712. 24
  30713. ],
  30714. [
  30715. 11,
  30716. 24
  30717. ],
  30718. [
  30719. 11,
  30720. 24
  30721. ],
  30722. // 00000010111xx
  30723. [
  30724. 11,
  30725. 25
  30726. ],
  30727. [
  30728. 11,
  30729. 25
  30730. ],
  30731. [
  30732. 11,
  30733. 25
  30734. ],
  30735. [
  30736. 11,
  30737. 25
  30738. ],
  30739. // 00000011000xx
  30740. [
  30741. 13,
  30742. 1664
  30743. ],
  30744. // 0000001100100
  30745. [
  30746. 13,
  30747. 1728
  30748. ],
  30749. // 0000001100101
  30750. [
  30751. 12,
  30752. 320
  30753. ],
  30754. [
  30755. 12,
  30756. 320
  30757. ],
  30758. // 000000110011x
  30759. [
  30760. 12,
  30761. 384
  30762. ],
  30763. [
  30764. 12,
  30765. 384
  30766. ],
  30767. // 000000110100x
  30768. [
  30769. 12,
  30770. 448
  30771. ],
  30772. [
  30773. 12,
  30774. 448
  30775. ],
  30776. // 000000110101x
  30777. [
  30778. 13,
  30779. 512
  30780. ],
  30781. // 0000001101100
  30782. [
  30783. 13,
  30784. 576
  30785. ],
  30786. // 0000001101101
  30787. [
  30788. 12,
  30789. 53
  30790. ],
  30791. [
  30792. 12,
  30793. 53
  30794. ],
  30795. // 000000110111x
  30796. [
  30797. 12,
  30798. 54
  30799. ],
  30800. [
  30801. 12,
  30802. 54
  30803. ],
  30804. // 000000111000x
  30805. [
  30806. 13,
  30807. 896
  30808. ],
  30809. // 0000001110010
  30810. [
  30811. 13,
  30812. 960
  30813. ],
  30814. // 0000001110011
  30815. [
  30816. 13,
  30817. 1024
  30818. ],
  30819. // 0000001110100
  30820. [
  30821. 13,
  30822. 1088
  30823. ],
  30824. // 0000001110101
  30825. [
  30826. 13,
  30827. 1152
  30828. ],
  30829. // 0000001110110
  30830. [
  30831. 13,
  30832. 1216
  30833. ],
  30834. // 0000001110111
  30835. [
  30836. 10,
  30837. 64
  30838. ],
  30839. [
  30840. 10,
  30841. 64
  30842. ],
  30843. [
  30844. 10,
  30845. 64
  30846. ],
  30847. [
  30848. 10,
  30849. 64
  30850. ],
  30851. // 0000001111xxx
  30852. [
  30853. 10,
  30854. 64
  30855. ],
  30856. [
  30857. 10,
  30858. 64
  30859. ],
  30860. [
  30861. 10,
  30862. 64
  30863. ],
  30864. [
  30865. 10,
  30866. 64
  30867. ]
  30868. ];
  30869. var blackTable2 = [
  30870. [
  30871. 8,
  30872. 13
  30873. ],
  30874. [
  30875. 8,
  30876. 13
  30877. ],
  30878. [
  30879. 8,
  30880. 13
  30881. ],
  30882. [
  30883. 8,
  30884. 13
  30885. ],
  30886. // 00000100xxxx
  30887. [
  30888. 8,
  30889. 13
  30890. ],
  30891. [
  30892. 8,
  30893. 13
  30894. ],
  30895. [
  30896. 8,
  30897. 13
  30898. ],
  30899. [
  30900. 8,
  30901. 13
  30902. ],
  30903. [
  30904. 8,
  30905. 13
  30906. ],
  30907. [
  30908. 8,
  30909. 13
  30910. ],
  30911. [
  30912. 8,
  30913. 13
  30914. ],
  30915. [
  30916. 8,
  30917. 13
  30918. ],
  30919. [
  30920. 8,
  30921. 13
  30922. ],
  30923. [
  30924. 8,
  30925. 13
  30926. ],
  30927. [
  30928. 8,
  30929. 13
  30930. ],
  30931. [
  30932. 8,
  30933. 13
  30934. ],
  30935. [
  30936. 11,
  30937. 23
  30938. ],
  30939. [
  30940. 11,
  30941. 23
  30942. ],
  30943. // 00000101000x
  30944. [
  30945. 12,
  30946. 50
  30947. ],
  30948. // 000001010010
  30949. [
  30950. 12,
  30951. 51
  30952. ],
  30953. // 000001010011
  30954. [
  30955. 12,
  30956. 44
  30957. ],
  30958. // 000001010100
  30959. [
  30960. 12,
  30961. 45
  30962. ],
  30963. // 000001010101
  30964. [
  30965. 12,
  30966. 46
  30967. ],
  30968. // 000001010110
  30969. [
  30970. 12,
  30971. 47
  30972. ],
  30973. // 000001010111
  30974. [
  30975. 12,
  30976. 57
  30977. ],
  30978. // 000001011000
  30979. [
  30980. 12,
  30981. 58
  30982. ],
  30983. // 000001011001
  30984. [
  30985. 12,
  30986. 61
  30987. ],
  30988. // 000001011010
  30989. [
  30990. 12,
  30991. 256
  30992. ],
  30993. // 000001011011
  30994. [
  30995. 10,
  30996. 16
  30997. ],
  30998. [
  30999. 10,
  31000. 16
  31001. ],
  31002. [
  31003. 10,
  31004. 16
  31005. ],
  31006. [
  31007. 10,
  31008. 16
  31009. ],
  31010. // 0000010111xx
  31011. [
  31012. 10,
  31013. 17
  31014. ],
  31015. [
  31016. 10,
  31017. 17
  31018. ],
  31019. [
  31020. 10,
  31021. 17
  31022. ],
  31023. [
  31024. 10,
  31025. 17
  31026. ],
  31027. // 0000011000xx
  31028. [
  31029. 12,
  31030. 48
  31031. ],
  31032. // 000001100100
  31033. [
  31034. 12,
  31035. 49
  31036. ],
  31037. // 000001100101
  31038. [
  31039. 12,
  31040. 62
  31041. ],
  31042. // 000001100110
  31043. [
  31044. 12,
  31045. 63
  31046. ],
  31047. // 000001100111
  31048. [
  31049. 12,
  31050. 30
  31051. ],
  31052. // 000001101000
  31053. [
  31054. 12,
  31055. 31
  31056. ],
  31057. // 000001101001
  31058. [
  31059. 12,
  31060. 32
  31061. ],
  31062. // 000001101010
  31063. [
  31064. 12,
  31065. 33
  31066. ],
  31067. // 000001101011
  31068. [
  31069. 12,
  31070. 40
  31071. ],
  31072. // 000001101100
  31073. [
  31074. 12,
  31075. 41
  31076. ],
  31077. // 000001101101
  31078. [
  31079. 11,
  31080. 22
  31081. ],
  31082. [
  31083. 11,
  31084. 22
  31085. ],
  31086. // 00000110111x
  31087. [
  31088. 8,
  31089. 14
  31090. ],
  31091. [
  31092. 8,
  31093. 14
  31094. ],
  31095. [
  31096. 8,
  31097. 14
  31098. ],
  31099. [
  31100. 8,
  31101. 14
  31102. ],
  31103. // 00000111xxxx
  31104. [
  31105. 8,
  31106. 14
  31107. ],
  31108. [
  31109. 8,
  31110. 14
  31111. ],
  31112. [
  31113. 8,
  31114. 14
  31115. ],
  31116. [
  31117. 8,
  31118. 14
  31119. ],
  31120. [
  31121. 8,
  31122. 14
  31123. ],
  31124. [
  31125. 8,
  31126. 14
  31127. ],
  31128. [
  31129. 8,
  31130. 14
  31131. ],
  31132. [
  31133. 8,
  31134. 14
  31135. ],
  31136. [
  31137. 8,
  31138. 14
  31139. ],
  31140. [
  31141. 8,
  31142. 14
  31143. ],
  31144. [
  31145. 8,
  31146. 14
  31147. ],
  31148. [
  31149. 8,
  31150. 14
  31151. ],
  31152. [
  31153. 7,
  31154. 10
  31155. ],
  31156. [
  31157. 7,
  31158. 10
  31159. ],
  31160. [
  31161. 7,
  31162. 10
  31163. ],
  31164. [
  31165. 7,
  31166. 10
  31167. ],
  31168. // 0000100xxxxx
  31169. [
  31170. 7,
  31171. 10
  31172. ],
  31173. [
  31174. 7,
  31175. 10
  31176. ],
  31177. [
  31178. 7,
  31179. 10
  31180. ],
  31181. [
  31182. 7,
  31183. 10
  31184. ],
  31185. [
  31186. 7,
  31187. 10
  31188. ],
  31189. [
  31190. 7,
  31191. 10
  31192. ],
  31193. [
  31194. 7,
  31195. 10
  31196. ],
  31197. [
  31198. 7,
  31199. 10
  31200. ],
  31201. [
  31202. 7,
  31203. 10
  31204. ],
  31205. [
  31206. 7,
  31207. 10
  31208. ],
  31209. [
  31210. 7,
  31211. 10
  31212. ],
  31213. [
  31214. 7,
  31215. 10
  31216. ],
  31217. [
  31218. 7,
  31219. 10
  31220. ],
  31221. [
  31222. 7,
  31223. 10
  31224. ],
  31225. [
  31226. 7,
  31227. 10
  31228. ],
  31229. [
  31230. 7,
  31231. 10
  31232. ],
  31233. [
  31234. 7,
  31235. 10
  31236. ],
  31237. [
  31238. 7,
  31239. 10
  31240. ],
  31241. [
  31242. 7,
  31243. 10
  31244. ],
  31245. [
  31246. 7,
  31247. 10
  31248. ],
  31249. [
  31250. 7,
  31251. 10
  31252. ],
  31253. [
  31254. 7,
  31255. 10
  31256. ],
  31257. [
  31258. 7,
  31259. 10
  31260. ],
  31261. [
  31262. 7,
  31263. 10
  31264. ],
  31265. [
  31266. 7,
  31267. 10
  31268. ],
  31269. [
  31270. 7,
  31271. 10
  31272. ],
  31273. [
  31274. 7,
  31275. 10
  31276. ],
  31277. [
  31278. 7,
  31279. 10
  31280. ],
  31281. [
  31282. 7,
  31283. 11
  31284. ],
  31285. [
  31286. 7,
  31287. 11
  31288. ],
  31289. [
  31290. 7,
  31291. 11
  31292. ],
  31293. [
  31294. 7,
  31295. 11
  31296. ],
  31297. // 0000101xxxxx
  31298. [
  31299. 7,
  31300. 11
  31301. ],
  31302. [
  31303. 7,
  31304. 11
  31305. ],
  31306. [
  31307. 7,
  31308. 11
  31309. ],
  31310. [
  31311. 7,
  31312. 11
  31313. ],
  31314. [
  31315. 7,
  31316. 11
  31317. ],
  31318. [
  31319. 7,
  31320. 11
  31321. ],
  31322. [
  31323. 7,
  31324. 11
  31325. ],
  31326. [
  31327. 7,
  31328. 11
  31329. ],
  31330. [
  31331. 7,
  31332. 11
  31333. ],
  31334. [
  31335. 7,
  31336. 11
  31337. ],
  31338. [
  31339. 7,
  31340. 11
  31341. ],
  31342. [
  31343. 7,
  31344. 11
  31345. ],
  31346. [
  31347. 7,
  31348. 11
  31349. ],
  31350. [
  31351. 7,
  31352. 11
  31353. ],
  31354. [
  31355. 7,
  31356. 11
  31357. ],
  31358. [
  31359. 7,
  31360. 11
  31361. ],
  31362. [
  31363. 7,
  31364. 11
  31365. ],
  31366. [
  31367. 7,
  31368. 11
  31369. ],
  31370. [
  31371. 7,
  31372. 11
  31373. ],
  31374. [
  31375. 7,
  31376. 11
  31377. ],
  31378. [
  31379. 7,
  31380. 11
  31381. ],
  31382. [
  31383. 7,
  31384. 11
  31385. ],
  31386. [
  31387. 7,
  31388. 11
  31389. ],
  31390. [
  31391. 7,
  31392. 11
  31393. ],
  31394. [
  31395. 7,
  31396. 11
  31397. ],
  31398. [
  31399. 7,
  31400. 11
  31401. ],
  31402. [
  31403. 7,
  31404. 11
  31405. ],
  31406. [
  31407. 7,
  31408. 11
  31409. ],
  31410. [
  31411. 9,
  31412. 15
  31413. ],
  31414. [
  31415. 9,
  31416. 15
  31417. ],
  31418. [
  31419. 9,
  31420. 15
  31421. ],
  31422. [
  31423. 9,
  31424. 15
  31425. ],
  31426. // 000011000xxx
  31427. [
  31428. 9,
  31429. 15
  31430. ],
  31431. [
  31432. 9,
  31433. 15
  31434. ],
  31435. [
  31436. 9,
  31437. 15
  31438. ],
  31439. [
  31440. 9,
  31441. 15
  31442. ],
  31443. [
  31444. 12,
  31445. 128
  31446. ],
  31447. // 000011001000
  31448. [
  31449. 12,
  31450. 192
  31451. ],
  31452. // 000011001001
  31453. [
  31454. 12,
  31455. 26
  31456. ],
  31457. // 000011001010
  31458. [
  31459. 12,
  31460. 27
  31461. ],
  31462. // 000011001011
  31463. [
  31464. 12,
  31465. 28
  31466. ],
  31467. // 000011001100
  31468. [
  31469. 12,
  31470. 29
  31471. ],
  31472. // 000011001101
  31473. [
  31474. 11,
  31475. 19
  31476. ],
  31477. [
  31478. 11,
  31479. 19
  31480. ],
  31481. // 00001100111x
  31482. [
  31483. 11,
  31484. 20
  31485. ],
  31486. [
  31487. 11,
  31488. 20
  31489. ],
  31490. // 00001101000x
  31491. [
  31492. 12,
  31493. 34
  31494. ],
  31495. // 000011010010
  31496. [
  31497. 12,
  31498. 35
  31499. ],
  31500. // 000011010011
  31501. [
  31502. 12,
  31503. 36
  31504. ],
  31505. // 000011010100
  31506. [
  31507. 12,
  31508. 37
  31509. ],
  31510. // 000011010101
  31511. [
  31512. 12,
  31513. 38
  31514. ],
  31515. // 000011010110
  31516. [
  31517. 12,
  31518. 39
  31519. ],
  31520. // 000011010111
  31521. [
  31522. 11,
  31523. 21
  31524. ],
  31525. [
  31526. 11,
  31527. 21
  31528. ],
  31529. // 00001101100x
  31530. [
  31531. 12,
  31532. 42
  31533. ],
  31534. // 000011011010
  31535. [
  31536. 12,
  31537. 43
  31538. ],
  31539. // 000011011011
  31540. [
  31541. 10,
  31542. 0
  31543. ],
  31544. [
  31545. 10,
  31546. 0
  31547. ],
  31548. [
  31549. 10,
  31550. 0
  31551. ],
  31552. [
  31553. 10,
  31554. 0
  31555. ],
  31556. // 0000110111xx
  31557. [
  31558. 7,
  31559. 12
  31560. ],
  31561. [
  31562. 7,
  31563. 12
  31564. ],
  31565. [
  31566. 7,
  31567. 12
  31568. ],
  31569. [
  31570. 7,
  31571. 12
  31572. ],
  31573. // 0000111xxxxx
  31574. [
  31575. 7,
  31576. 12
  31577. ],
  31578. [
  31579. 7,
  31580. 12
  31581. ],
  31582. [
  31583. 7,
  31584. 12
  31585. ],
  31586. [
  31587. 7,
  31588. 12
  31589. ],
  31590. [
  31591. 7,
  31592. 12
  31593. ],
  31594. [
  31595. 7,
  31596. 12
  31597. ],
  31598. [
  31599. 7,
  31600. 12
  31601. ],
  31602. [
  31603. 7,
  31604. 12
  31605. ],
  31606. [
  31607. 7,
  31608. 12
  31609. ],
  31610. [
  31611. 7,
  31612. 12
  31613. ],
  31614. [
  31615. 7,
  31616. 12
  31617. ],
  31618. [
  31619. 7,
  31620. 12
  31621. ],
  31622. [
  31623. 7,
  31624. 12
  31625. ],
  31626. [
  31627. 7,
  31628. 12
  31629. ],
  31630. [
  31631. 7,
  31632. 12
  31633. ],
  31634. [
  31635. 7,
  31636. 12
  31637. ],
  31638. [
  31639. 7,
  31640. 12
  31641. ],
  31642. [
  31643. 7,
  31644. 12
  31645. ],
  31646. [
  31647. 7,
  31648. 12
  31649. ],
  31650. [
  31651. 7,
  31652. 12
  31653. ],
  31654. [
  31655. 7,
  31656. 12
  31657. ],
  31658. [
  31659. 7,
  31660. 12
  31661. ],
  31662. [
  31663. 7,
  31664. 12
  31665. ],
  31666. [
  31667. 7,
  31668. 12
  31669. ],
  31670. [
  31671. 7,
  31672. 12
  31673. ],
  31674. [
  31675. 7,
  31676. 12
  31677. ],
  31678. [
  31679. 7,
  31680. 12
  31681. ],
  31682. [
  31683. 7,
  31684. 12
  31685. ]
  31686. ];
  31687. var blackTable3 = [
  31688. [
  31689. -1,
  31690. -1
  31691. ],
  31692. [
  31693. -1,
  31694. -1
  31695. ],
  31696. [
  31697. -1,
  31698. -1
  31699. ],
  31700. [
  31701. -1,
  31702. -1
  31703. ],
  31704. // 0000xx
  31705. [
  31706. 6,
  31707. 9
  31708. ],
  31709. // 000100
  31710. [
  31711. 6,
  31712. 8
  31713. ],
  31714. // 000101
  31715. [
  31716. 5,
  31717. 7
  31718. ],
  31719. [
  31720. 5,
  31721. 7
  31722. ],
  31723. // 00011x
  31724. [
  31725. 4,
  31726. 6
  31727. ],
  31728. [
  31729. 4,
  31730. 6
  31731. ],
  31732. [
  31733. 4,
  31734. 6
  31735. ],
  31736. [
  31737. 4,
  31738. 6
  31739. ],
  31740. // 0010xx
  31741. [
  31742. 4,
  31743. 5
  31744. ],
  31745. [
  31746. 4,
  31747. 5
  31748. ],
  31749. [
  31750. 4,
  31751. 5
  31752. ],
  31753. [
  31754. 4,
  31755. 5
  31756. ],
  31757. // 0011xx
  31758. [
  31759. 3,
  31760. 1
  31761. ],
  31762. [
  31763. 3,
  31764. 1
  31765. ],
  31766. [
  31767. 3,
  31768. 1
  31769. ],
  31770. [
  31771. 3,
  31772. 1
  31773. ],
  31774. // 010xxx
  31775. [
  31776. 3,
  31777. 1
  31778. ],
  31779. [
  31780. 3,
  31781. 1
  31782. ],
  31783. [
  31784. 3,
  31785. 1
  31786. ],
  31787. [
  31788. 3,
  31789. 1
  31790. ],
  31791. [
  31792. 3,
  31793. 4
  31794. ],
  31795. [
  31796. 3,
  31797. 4
  31798. ],
  31799. [
  31800. 3,
  31801. 4
  31802. ],
  31803. [
  31804. 3,
  31805. 4
  31806. ],
  31807. // 011xxx
  31808. [
  31809. 3,
  31810. 4
  31811. ],
  31812. [
  31813. 3,
  31814. 4
  31815. ],
  31816. [
  31817. 3,
  31818. 4
  31819. ],
  31820. [
  31821. 3,
  31822. 4
  31823. ],
  31824. [
  31825. 2,
  31826. 3
  31827. ],
  31828. [
  31829. 2,
  31830. 3
  31831. ],
  31832. [
  31833. 2,
  31834. 3
  31835. ],
  31836. [
  31837. 2,
  31838. 3
  31839. ],
  31840. // 10xxxx
  31841. [
  31842. 2,
  31843. 3
  31844. ],
  31845. [
  31846. 2,
  31847. 3
  31848. ],
  31849. [
  31850. 2,
  31851. 3
  31852. ],
  31853. [
  31854. 2,
  31855. 3
  31856. ],
  31857. [
  31858. 2,
  31859. 3
  31860. ],
  31861. [
  31862. 2,
  31863. 3
  31864. ],
  31865. [
  31866. 2,
  31867. 3
  31868. ],
  31869. [
  31870. 2,
  31871. 3
  31872. ],
  31873. [
  31874. 2,
  31875. 3
  31876. ],
  31877. [
  31878. 2,
  31879. 3
  31880. ],
  31881. [
  31882. 2,
  31883. 3
  31884. ],
  31885. [
  31886. 2,
  31887. 3
  31888. ],
  31889. [
  31890. 2,
  31891. 2
  31892. ],
  31893. [
  31894. 2,
  31895. 2
  31896. ],
  31897. [
  31898. 2,
  31899. 2
  31900. ],
  31901. [
  31902. 2,
  31903. 2
  31904. ],
  31905. // 11xxxx
  31906. [
  31907. 2,
  31908. 2
  31909. ],
  31910. [
  31911. 2,
  31912. 2
  31913. ],
  31914. [
  31915. 2,
  31916. 2
  31917. ],
  31918. [
  31919. 2,
  31920. 2
  31921. ],
  31922. [
  31923. 2,
  31924. 2
  31925. ],
  31926. [
  31927. 2,
  31928. 2
  31929. ],
  31930. [
  31931. 2,
  31932. 2
  31933. ],
  31934. [
  31935. 2,
  31936. 2
  31937. ],
  31938. [
  31939. 2,
  31940. 2
  31941. ],
  31942. [
  31943. 2,
  31944. 2
  31945. ],
  31946. [
  31947. 2,
  31948. 2
  31949. ],
  31950. [
  31951. 2,
  31952. 2
  31953. ]
  31954. ];
  31955. function CCITTFaxStream(str, maybeLength, params) {
  31956. this.str = str;
  31957. this.dict = str.dict;
  31958. params = params || Dict.empty;
  31959. this.encoding = params.get('K') || 0;
  31960. this.eoline = params.get('EndOfLine') || false;
  31961. this.byteAlign = params.get('EncodedByteAlign') || false;
  31962. this.columns = params.get('Columns') || 1728;
  31963. this.rows = params.get('Rows') || 0;
  31964. var eoblock = params.get('EndOfBlock');
  31965. if (eoblock === null || eoblock === undefined) {
  31966. eoblock = true;
  31967. }
  31968. this.eoblock = eoblock;
  31969. this.black = params.get('BlackIs1') || false;
  31970. this.codingLine = new Uint32Array(this.columns + 1);
  31971. this.refLine = new Uint32Array(this.columns + 2);
  31972. this.codingLine[0] = this.columns;
  31973. this.codingPos = 0;
  31974. this.row = 0;
  31975. this.nextLine2D = this.encoding < 0;
  31976. this.inputBits = 0;
  31977. this.inputBuf = 0;
  31978. this.outputBits = 0;
  31979. var code1;
  31980. while ((code1 = this.lookBits(12)) === 0) {
  31981. this.eatBits(1);
  31982. }
  31983. if (code1 === 1) {
  31984. this.eatBits(12);
  31985. }
  31986. if (this.encoding > 0) {
  31987. this.nextLine2D = !this.lookBits(1);
  31988. this.eatBits(1);
  31989. }
  31990. DecodeStream.call(this, maybeLength);
  31991. }
  31992. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  31993. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  31994. while (!this.eof) {
  31995. var c = this.lookChar();
  31996. this.ensureBuffer(this.bufferLength + 1);
  31997. this.buffer[this.bufferLength++] = c;
  31998. }
  31999. };
  32000. CCITTFaxStream.prototype.addPixels = function ccittFaxStreamAddPixels(a1, blackPixels) {
  32001. var codingLine = this.codingLine;
  32002. var codingPos = this.codingPos;
  32003. if (a1 > codingLine[codingPos]) {
  32004. if (a1 > this.columns) {
  32005. info('row is wrong length');
  32006. this.err = true;
  32007. a1 = this.columns;
  32008. }
  32009. if (codingPos & 1 ^ blackPixels) {
  32010. ++codingPos;
  32011. }
  32012. codingLine[codingPos] = a1;
  32013. }
  32014. this.codingPos = codingPos;
  32015. };
  32016. CCITTFaxStream.prototype.addPixelsNeg = function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  32017. var codingLine = this.codingLine;
  32018. var codingPos = this.codingPos;
  32019. if (a1 > codingLine[codingPos]) {
  32020. if (a1 > this.columns) {
  32021. info('row is wrong length');
  32022. this.err = true;
  32023. a1 = this.columns;
  32024. }
  32025. if (codingPos & 1 ^ blackPixels) {
  32026. ++codingPos;
  32027. }
  32028. codingLine[codingPos] = a1;
  32029. } else if (a1 < codingLine[codingPos]) {
  32030. if (a1 < 0) {
  32031. info('invalid code');
  32032. this.err = true;
  32033. a1 = 0;
  32034. }
  32035. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  32036. --codingPos;
  32037. }
  32038. codingLine[codingPos] = a1;
  32039. }
  32040. this.codingPos = codingPos;
  32041. };
  32042. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  32043. var refLine = this.refLine;
  32044. var codingLine = this.codingLine;
  32045. var columns = this.columns;
  32046. var refPos, blackPixels, bits, i;
  32047. if (this.outputBits === 0) {
  32048. if (this.eof) {
  32049. return null;
  32050. }
  32051. this.err = false;
  32052. var code1, code2, code3;
  32053. if (this.nextLine2D) {
  32054. for (i = 0; codingLine[i] < columns; ++i) {
  32055. refLine[i] = codingLine[i];
  32056. }
  32057. refLine[i++] = columns;
  32058. refLine[i] = columns;
  32059. codingLine[0] = 0;
  32060. this.codingPos = 0;
  32061. refPos = 0;
  32062. blackPixels = 0;
  32063. while (codingLine[this.codingPos] < columns) {
  32064. code1 = this.getTwoDimCode();
  32065. switch (code1) {
  32066. case twoDimPass:
  32067. this.addPixels(refLine[refPos + 1], blackPixels);
  32068. if (refLine[refPos + 1] < columns) {
  32069. refPos += 2;
  32070. }
  32071. break;
  32072. case twoDimHoriz:
  32073. code1 = code2 = 0;
  32074. if (blackPixels) {
  32075. do {
  32076. code1 += code3 = this.getBlackCode();
  32077. } while (code3 >= 64);
  32078. do {
  32079. code2 += code3 = this.getWhiteCode();
  32080. } while (code3 >= 64);
  32081. } else {
  32082. do {
  32083. code1 += code3 = this.getWhiteCode();
  32084. } while (code3 >= 64);
  32085. do {
  32086. code2 += code3 = this.getBlackCode();
  32087. } while (code3 >= 64);
  32088. }
  32089. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  32090. if (codingLine[this.codingPos] < columns) {
  32091. this.addPixels(codingLine[this.codingPos] + code2, blackPixels ^ 1);
  32092. }
  32093. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  32094. refPos += 2;
  32095. }
  32096. break;
  32097. case twoDimVertR3:
  32098. this.addPixels(refLine[refPos] + 3, 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 twoDimVertR2:
  32108. this.addPixels(refLine[refPos] + 2, 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 twoDimVertR1:
  32118. this.addPixels(refLine[refPos] + 1, 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 twoDimVert0:
  32128. this.addPixels(refLine[refPos], blackPixels);
  32129. blackPixels ^= 1;
  32130. if (codingLine[this.codingPos] < columns) {
  32131. ++refPos;
  32132. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  32133. refPos += 2;
  32134. }
  32135. }
  32136. break;
  32137. case twoDimVertL3:
  32138. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  32139. blackPixels ^= 1;
  32140. if (codingLine[this.codingPos] < columns) {
  32141. if (refPos > 0) {
  32142. --refPos;
  32143. } else {
  32144. ++refPos;
  32145. }
  32146. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  32147. refPos += 2;
  32148. }
  32149. }
  32150. break;
  32151. case twoDimVertL2:
  32152. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  32153. blackPixels ^= 1;
  32154. if (codingLine[this.codingPos] < columns) {
  32155. if (refPos > 0) {
  32156. --refPos;
  32157. } else {
  32158. ++refPos;
  32159. }
  32160. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  32161. refPos += 2;
  32162. }
  32163. }
  32164. break;
  32165. case twoDimVertL1:
  32166. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  32167. blackPixels ^= 1;
  32168. if (codingLine[this.codingPos] < columns) {
  32169. if (refPos > 0) {
  32170. --refPos;
  32171. } else {
  32172. ++refPos;
  32173. }
  32174. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  32175. refPos += 2;
  32176. }
  32177. }
  32178. break;
  32179. case ccittEOF:
  32180. this.addPixels(columns, 0);
  32181. this.eof = true;
  32182. break;
  32183. default:
  32184. info('bad 2d code');
  32185. this.addPixels(columns, 0);
  32186. this.err = true;
  32187. }
  32188. }
  32189. } else {
  32190. codingLine[0] = 0;
  32191. this.codingPos = 0;
  32192. blackPixels = 0;
  32193. while (codingLine[this.codingPos] < columns) {
  32194. code1 = 0;
  32195. if (blackPixels) {
  32196. do {
  32197. code1 += code3 = this.getBlackCode();
  32198. } while (code3 >= 64);
  32199. } else {
  32200. do {
  32201. code1 += code3 = this.getWhiteCode();
  32202. } while (code3 >= 64);
  32203. }
  32204. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  32205. blackPixels ^= 1;
  32206. }
  32207. }
  32208. var gotEOL = false;
  32209. if (this.byteAlign) {
  32210. this.inputBits &= ~7;
  32211. }
  32212. if (!this.eoblock && this.row === this.rows - 1) {
  32213. this.eof = true;
  32214. } else {
  32215. code1 = this.lookBits(12);
  32216. if (this.eoline) {
  32217. while (code1 !== ccittEOF && code1 !== 1) {
  32218. this.eatBits(1);
  32219. code1 = this.lookBits(12);
  32220. }
  32221. } else {
  32222. while (code1 === 0) {
  32223. this.eatBits(1);
  32224. code1 = this.lookBits(12);
  32225. }
  32226. }
  32227. if (code1 === 1) {
  32228. this.eatBits(12);
  32229. gotEOL = true;
  32230. } else if (code1 === ccittEOF) {
  32231. this.eof = true;
  32232. }
  32233. }
  32234. if (!this.eof && this.encoding > 0) {
  32235. this.nextLine2D = !this.lookBits(1);
  32236. this.eatBits(1);
  32237. }
  32238. if (this.eoblock && gotEOL && this.byteAlign) {
  32239. code1 = this.lookBits(12);
  32240. if (code1 === 1) {
  32241. this.eatBits(12);
  32242. if (this.encoding > 0) {
  32243. this.lookBits(1);
  32244. this.eatBits(1);
  32245. }
  32246. if (this.encoding >= 0) {
  32247. for (i = 0; i < 4; ++i) {
  32248. code1 = this.lookBits(12);
  32249. if (code1 !== 1) {
  32250. info('bad rtc code: ' + code1);
  32251. }
  32252. this.eatBits(12);
  32253. if (this.encoding > 0) {
  32254. this.lookBits(1);
  32255. this.eatBits(1);
  32256. }
  32257. }
  32258. }
  32259. this.eof = true;
  32260. }
  32261. } else if (this.err && this.eoline) {
  32262. while (true) {
  32263. code1 = this.lookBits(13);
  32264. if (code1 === ccittEOF) {
  32265. this.eof = true;
  32266. return null;
  32267. }
  32268. if (code1 >> 1 === 1) {
  32269. break;
  32270. }
  32271. this.eatBits(1);
  32272. }
  32273. this.eatBits(12);
  32274. if (this.encoding > 0) {
  32275. this.eatBits(1);
  32276. this.nextLine2D = !(code1 & 1);
  32277. }
  32278. }
  32279. if (codingLine[0] > 0) {
  32280. this.outputBits = codingLine[this.codingPos = 0];
  32281. } else {
  32282. this.outputBits = codingLine[this.codingPos = 1];
  32283. }
  32284. this.row++;
  32285. }
  32286. var c;
  32287. if (this.outputBits >= 8) {
  32288. c = this.codingPos & 1 ? 0 : 0xFF;
  32289. this.outputBits -= 8;
  32290. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  32291. this.codingPos++;
  32292. this.outputBits = codingLine[this.codingPos] - codingLine[this.codingPos - 1];
  32293. }
  32294. } else {
  32295. bits = 8;
  32296. c = 0;
  32297. do {
  32298. if (this.outputBits > bits) {
  32299. c <<= bits;
  32300. if (!(this.codingPos & 1)) {
  32301. c |= 0xFF >> 8 - bits;
  32302. }
  32303. this.outputBits -= bits;
  32304. bits = 0;
  32305. } else {
  32306. c <<= this.outputBits;
  32307. if (!(this.codingPos & 1)) {
  32308. c |= 0xFF >> 8 - this.outputBits;
  32309. }
  32310. bits -= this.outputBits;
  32311. this.outputBits = 0;
  32312. if (codingLine[this.codingPos] < columns) {
  32313. this.codingPos++;
  32314. this.outputBits = codingLine[this.codingPos] - codingLine[this.codingPos - 1];
  32315. } else if (bits > 0) {
  32316. c <<= bits;
  32317. bits = 0;
  32318. }
  32319. }
  32320. } while (bits);
  32321. }
  32322. if (this.black) {
  32323. c ^= 0xFF;
  32324. }
  32325. return c;
  32326. };
  32327. // This functions returns the code found from the table.
  32328. // The start and end parameters set the boundaries for searching the table.
  32329. // The limit parameter is optional. Function returns an array with three
  32330. // values. The first array element indicates whether a valid code is being
  32331. // returned. The second array element is the actual code. The third array
  32332. // element indicates whether EOF was reached.
  32333. CCITTFaxStream.prototype.findTableCode = function ccittFaxStreamFindTableCode(start, end, table, limit) {
  32334. var limitValue = limit || 0;
  32335. for (var i = start; i <= end; ++i) {
  32336. var code = this.lookBits(i);
  32337. if (code === ccittEOF) {
  32338. return [
  32339. true,
  32340. 1,
  32341. false
  32342. ];
  32343. }
  32344. if (i < end) {
  32345. code <<= end - i;
  32346. }
  32347. if (!limitValue || code >= limitValue) {
  32348. var p = table[code - limitValue];
  32349. if (p[0] === i) {
  32350. this.eatBits(i);
  32351. return [
  32352. true,
  32353. p[1],
  32354. true
  32355. ];
  32356. }
  32357. }
  32358. }
  32359. return [
  32360. false,
  32361. 0,
  32362. false
  32363. ];
  32364. };
  32365. CCITTFaxStream.prototype.getTwoDimCode = function ccittFaxStreamGetTwoDimCode() {
  32366. var code = 0;
  32367. var p;
  32368. if (this.eoblock) {
  32369. code = this.lookBits(7);
  32370. p = twoDimTable[code];
  32371. if (p && p[0] > 0) {
  32372. this.eatBits(p[0]);
  32373. return p[1];
  32374. }
  32375. } else {
  32376. var result = this.findTableCode(1, 7, twoDimTable);
  32377. if (result[0] && result[2]) {
  32378. return result[1];
  32379. }
  32380. }
  32381. info('Bad two dim code');
  32382. return ccittEOF;
  32383. };
  32384. CCITTFaxStream.prototype.getWhiteCode = function ccittFaxStreamGetWhiteCode() {
  32385. var code = 0;
  32386. var p;
  32387. if (this.eoblock) {
  32388. code = this.lookBits(12);
  32389. if (code === ccittEOF) {
  32390. return 1;
  32391. }
  32392. if (code >> 5 === 0) {
  32393. p = whiteTable1[code];
  32394. } else {
  32395. p = whiteTable2[code >> 3];
  32396. }
  32397. if (p[0] > 0) {
  32398. this.eatBits(p[0]);
  32399. return p[1];
  32400. }
  32401. } else {
  32402. var result = this.findTableCode(1, 9, whiteTable2);
  32403. if (result[0]) {
  32404. return result[1];
  32405. }
  32406. result = this.findTableCode(11, 12, whiteTable1);
  32407. if (result[0]) {
  32408. return result[1];
  32409. }
  32410. }
  32411. info('bad white code');
  32412. this.eatBits(1);
  32413. return 1;
  32414. };
  32415. CCITTFaxStream.prototype.getBlackCode = function ccittFaxStreamGetBlackCode() {
  32416. var code, p;
  32417. if (this.eoblock) {
  32418. code = this.lookBits(13);
  32419. if (code === ccittEOF) {
  32420. return 1;
  32421. }
  32422. if (code >> 7 === 0) {
  32423. p = blackTable1[code];
  32424. } else if (code >> 9 === 0 && code >> 7 !== 0) {
  32425. p = blackTable2[(code >> 1) - 64];
  32426. } else {
  32427. p = blackTable3[code >> 7];
  32428. }
  32429. if (p[0] > 0) {
  32430. this.eatBits(p[0]);
  32431. return p[1];
  32432. }
  32433. } else {
  32434. var result = this.findTableCode(2, 6, blackTable3);
  32435. if (result[0]) {
  32436. return result[1];
  32437. }
  32438. result = this.findTableCode(7, 12, blackTable2, 64);
  32439. if (result[0]) {
  32440. return result[1];
  32441. }
  32442. result = this.findTableCode(10, 13, blackTable1);
  32443. if (result[0]) {
  32444. return result[1];
  32445. }
  32446. }
  32447. info('bad black code');
  32448. this.eatBits(1);
  32449. return 1;
  32450. };
  32451. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  32452. var c;
  32453. while (this.inputBits < n) {
  32454. if ((c = this.str.getByte()) === -1) {
  32455. if (this.inputBits === 0) {
  32456. return ccittEOF;
  32457. }
  32458. return this.inputBuf << n - this.inputBits & 0xFFFF >> 16 - n;
  32459. }
  32460. this.inputBuf = this.inputBuf << 8 | c;
  32461. this.inputBits += 8;
  32462. }
  32463. return this.inputBuf >> this.inputBits - n & 0xFFFF >> 16 - n;
  32464. };
  32465. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  32466. if ((this.inputBits -= n) < 0) {
  32467. this.inputBits = 0;
  32468. }
  32469. };
  32470. return CCITTFaxStream;
  32471. }();
  32472. var LZWStream = function LZWStreamClosure() {
  32473. function LZWStream(str, maybeLength, earlyChange) {
  32474. this.str = str;
  32475. this.dict = str.dict;
  32476. this.cachedData = 0;
  32477. this.bitsCached = 0;
  32478. var maxLzwDictionarySize = 4096;
  32479. var lzwState = {
  32480. earlyChange: earlyChange,
  32481. codeLength: 9,
  32482. nextCode: 258,
  32483. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  32484. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  32485. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  32486. currentSequence: new Uint8Array(maxLzwDictionarySize),
  32487. currentSequenceLength: 0
  32488. };
  32489. for (var i = 0; i < 256; ++i) {
  32490. lzwState.dictionaryValues[i] = i;
  32491. lzwState.dictionaryLengths[i] = 1;
  32492. }
  32493. this.lzwState = lzwState;
  32494. DecodeStream.call(this, maybeLength);
  32495. }
  32496. LZWStream.prototype = Object.create(DecodeStream.prototype);
  32497. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  32498. var bitsCached = this.bitsCached;
  32499. var cachedData = this.cachedData;
  32500. while (bitsCached < n) {
  32501. var c = this.str.getByte();
  32502. if (c === -1) {
  32503. this.eof = true;
  32504. return null;
  32505. }
  32506. cachedData = cachedData << 8 | c;
  32507. bitsCached += 8;
  32508. }
  32509. this.bitsCached = bitsCached -= n;
  32510. this.cachedData = cachedData;
  32511. this.lastCode = null;
  32512. return cachedData >>> bitsCached & (1 << n) - 1;
  32513. };
  32514. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  32515. var blockSize = 512;
  32516. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  32517. var i, j, q;
  32518. var lzwState = this.lzwState;
  32519. if (!lzwState) {
  32520. return;
  32521. }
  32522. // eof was found
  32523. var earlyChange = lzwState.earlyChange;
  32524. var nextCode = lzwState.nextCode;
  32525. var dictionaryValues = lzwState.dictionaryValues;
  32526. var dictionaryLengths = lzwState.dictionaryLengths;
  32527. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  32528. var codeLength = lzwState.codeLength;
  32529. var prevCode = lzwState.prevCode;
  32530. var currentSequence = lzwState.currentSequence;
  32531. var currentSequenceLength = lzwState.currentSequenceLength;
  32532. var decodedLength = 0;
  32533. var currentBufferLength = this.bufferLength;
  32534. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  32535. for (i = 0; i < blockSize; i++) {
  32536. var code = this.readBits(codeLength);
  32537. var hasPrev = currentSequenceLength > 0;
  32538. if (code < 256) {
  32539. currentSequence[0] = code;
  32540. currentSequenceLength = 1;
  32541. } else if (code >= 258) {
  32542. if (code < nextCode) {
  32543. currentSequenceLength = dictionaryLengths[code];
  32544. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  32545. currentSequence[j] = dictionaryValues[q];
  32546. q = dictionaryPrevCodes[q];
  32547. }
  32548. } else {
  32549. currentSequence[currentSequenceLength++] = currentSequence[0];
  32550. }
  32551. } else if (code === 256) {
  32552. codeLength = 9;
  32553. nextCode = 258;
  32554. currentSequenceLength = 0;
  32555. continue;
  32556. } else {
  32557. this.eof = true;
  32558. delete this.lzwState;
  32559. break;
  32560. }
  32561. if (hasPrev) {
  32562. dictionaryPrevCodes[nextCode] = prevCode;
  32563. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  32564. dictionaryValues[nextCode] = currentSequence[0];
  32565. nextCode++;
  32566. codeLength = nextCode + earlyChange & nextCode + earlyChange - 1 ? codeLength : Math.min(Math.log(nextCode + earlyChange) / 0.6931471805599453 + 1, 12) | 0;
  32567. }
  32568. prevCode = code;
  32569. decodedLength += currentSequenceLength;
  32570. if (estimatedDecodedSize < decodedLength) {
  32571. do {
  32572. estimatedDecodedSize += decodedSizeDelta;
  32573. } while (estimatedDecodedSize < decodedLength);
  32574. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  32575. }
  32576. for (j = 0; j < currentSequenceLength; j++) {
  32577. buffer[currentBufferLength++] = currentSequence[j];
  32578. }
  32579. }
  32580. lzwState.nextCode = nextCode;
  32581. lzwState.codeLength = codeLength;
  32582. lzwState.prevCode = prevCode;
  32583. lzwState.currentSequenceLength = currentSequenceLength;
  32584. this.bufferLength = currentBufferLength;
  32585. };
  32586. return LZWStream;
  32587. }();
  32588. var NullStream = function NullStreamClosure() {
  32589. function NullStream() {
  32590. Stream.call(this, new Uint8Array(0));
  32591. }
  32592. NullStream.prototype = Stream.prototype;
  32593. return NullStream;
  32594. }();
  32595. exports.Ascii85Stream = Ascii85Stream;
  32596. exports.AsciiHexStream = AsciiHexStream;
  32597. exports.CCITTFaxStream = CCITTFaxStream;
  32598. exports.DecryptStream = DecryptStream;
  32599. exports.DecodeStream = DecodeStream;
  32600. exports.FlateStream = FlateStream;
  32601. exports.Jbig2Stream = Jbig2Stream;
  32602. exports.JpegStream = JpegStream;
  32603. exports.JpxStream = JpxStream;
  32604. exports.NullStream = NullStream;
  32605. exports.PredictorStream = PredictorStream;
  32606. exports.RunLengthStream = RunLengthStream;
  32607. exports.Stream = Stream;
  32608. exports.StreamsSequenceStream = StreamsSequenceStream;
  32609. exports.StringStream = StringStream;
  32610. exports.LZWStream = LZWStream;
  32611. }));
  32612. (function (root, factory) {
  32613. factory(root.pdfjsDisplayAnnotationLayer = {}, root.pdfjsSharedUtil, root.pdfjsDisplayDOMUtils);
  32614. }(this, function (exports, sharedUtil, displayDOMUtils) {
  32615. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  32616. var AnnotationType = sharedUtil.AnnotationType;
  32617. var Util = sharedUtil.Util;
  32618. var addLinkAttributes = displayDOMUtils.addLinkAttributes;
  32619. var LinkTarget = displayDOMUtils.LinkTarget;
  32620. var getFilenameFromUrl = displayDOMUtils.getFilenameFromUrl;
  32621. var warn = sharedUtil.warn;
  32622. var CustomStyle = displayDOMUtils.CustomStyle;
  32623. var getDefaultSetting = displayDOMUtils.getDefaultSetting;
  32624. /**
  32625. * @typedef {Object} AnnotationElementParameters
  32626. * @property {Object} data
  32627. * @property {HTMLDivElement} layer
  32628. * @property {PDFPage} page
  32629. * @property {PageViewport} viewport
  32630. * @property {IPDFLinkService} linkService
  32631. * @property {DownloadManager} downloadManager
  32632. * @property {string} imageResourcesPath
  32633. * @property {boolean} renderInteractiveForms
  32634. */
  32635. /**
  32636. * @class
  32637. * @alias AnnotationElementFactory
  32638. */
  32639. function AnnotationElementFactory() {
  32640. }
  32641. AnnotationElementFactory.prototype = /** @lends AnnotationElementFactory.prototype */
  32642. {
  32643. /**
  32644. * @param {AnnotationElementParameters} parameters
  32645. * @returns {AnnotationElement}
  32646. */
  32647. create: function AnnotationElementFactory_create(parameters) {
  32648. var subtype = parameters.data.annotationType;
  32649. switch (subtype) {
  32650. case AnnotationType.LINK:
  32651. return new LinkAnnotationElement(parameters);
  32652. case AnnotationType.TEXT:
  32653. return new TextAnnotationElement(parameters);
  32654. case AnnotationType.WIDGET:
  32655. var fieldType = parameters.data.fieldType;
  32656. switch (fieldType) {
  32657. case 'Tx':
  32658. return new TextWidgetAnnotationElement(parameters);
  32659. case 'Ch':
  32660. return new ChoiceWidgetAnnotationElement(parameters);
  32661. }
  32662. return new WidgetAnnotationElement(parameters);
  32663. case AnnotationType.POPUP:
  32664. return new PopupAnnotationElement(parameters);
  32665. case AnnotationType.HIGHLIGHT:
  32666. return new HighlightAnnotationElement(parameters);
  32667. case AnnotationType.UNDERLINE:
  32668. return new UnderlineAnnotationElement(parameters);
  32669. case AnnotationType.SQUIGGLY:
  32670. return new SquigglyAnnotationElement(parameters);
  32671. case AnnotationType.STRIKEOUT:
  32672. return new StrikeOutAnnotationElement(parameters);
  32673. case AnnotationType.FILEATTACHMENT:
  32674. return new FileAttachmentAnnotationElement(parameters);
  32675. default:
  32676. return new AnnotationElement(parameters);
  32677. }
  32678. }
  32679. };
  32680. /**
  32681. * @class
  32682. * @alias AnnotationElement
  32683. */
  32684. var AnnotationElement = function AnnotationElementClosure() {
  32685. function AnnotationElement(parameters, isRenderable) {
  32686. this.isRenderable = isRenderable || false;
  32687. this.data = parameters.data;
  32688. this.layer = parameters.layer;
  32689. this.page = parameters.page;
  32690. this.viewport = parameters.viewport;
  32691. this.linkService = parameters.linkService;
  32692. this.downloadManager = parameters.downloadManager;
  32693. this.imageResourcesPath = parameters.imageResourcesPath;
  32694. this.renderInteractiveForms = parameters.renderInteractiveForms;
  32695. if (isRenderable) {
  32696. this.container = this._createContainer();
  32697. }
  32698. }
  32699. AnnotationElement.prototype = /** @lends AnnotationElement.prototype */
  32700. {
  32701. /**
  32702. * Create an empty container for the annotation's HTML element.
  32703. *
  32704. * @private
  32705. * @memberof AnnotationElement
  32706. * @returns {HTMLSectionElement}
  32707. */
  32708. _createContainer: function AnnotationElement_createContainer() {
  32709. var data = this.data, page = this.page, viewport = this.viewport;
  32710. var container = document.createElement('section');
  32711. var width = data.rect[2] - data.rect[0];
  32712. var height = data.rect[3] - data.rect[1];
  32713. container.setAttribute('data-annotation-id', data.id);
  32714. // Do *not* modify `data.rect`, since that will corrupt the annotation
  32715. // position on subsequent calls to `_createContainer` (see issue 6804).
  32716. var rect = Util.normalizeRect([
  32717. data.rect[0],
  32718. page.view[3] - data.rect[1] + page.view[1],
  32719. data.rect[2],
  32720. page.view[3] - data.rect[3] + page.view[1]
  32721. ]);
  32722. CustomStyle.setProp('transform', container, 'matrix(' + viewport.transform.join(',') + ')');
  32723. CustomStyle.setProp('transformOrigin', container, -rect[0] + 'px ' + -rect[1] + 'px');
  32724. if (data.borderStyle.width > 0) {
  32725. container.style.borderWidth = data.borderStyle.width + 'px';
  32726. if (data.borderStyle.style !== AnnotationBorderStyleType.UNDERLINE) {
  32727. // Underline styles only have a bottom border, so we do not need
  32728. // to adjust for all borders. This yields a similar result as
  32729. // Adobe Acrobat/Reader.
  32730. width = width - 2 * data.borderStyle.width;
  32731. height = height - 2 * data.borderStyle.width;
  32732. }
  32733. var horizontalRadius = data.borderStyle.horizontalCornerRadius;
  32734. var verticalRadius = data.borderStyle.verticalCornerRadius;
  32735. if (horizontalRadius > 0 || verticalRadius > 0) {
  32736. var radius = horizontalRadius + 'px / ' + verticalRadius + 'px';
  32737. CustomStyle.setProp('borderRadius', container, radius);
  32738. }
  32739. switch (data.borderStyle.style) {
  32740. case AnnotationBorderStyleType.SOLID:
  32741. container.style.borderStyle = 'solid';
  32742. break;
  32743. case AnnotationBorderStyleType.DASHED:
  32744. container.style.borderStyle = 'dashed';
  32745. break;
  32746. case AnnotationBorderStyleType.BEVELED:
  32747. warn('Unimplemented border style: beveled');
  32748. break;
  32749. case AnnotationBorderStyleType.INSET:
  32750. warn('Unimplemented border style: inset');
  32751. break;
  32752. case AnnotationBorderStyleType.UNDERLINE:
  32753. container.style.borderBottomStyle = 'solid';
  32754. break;
  32755. default:
  32756. break;
  32757. }
  32758. if (data.color) {
  32759. container.style.borderColor = Util.makeCssRgb(data.color[0] | 0, data.color[1] | 0, data.color[2] | 0);
  32760. } else {
  32761. // Transparent (invisible) border, so do not draw it at all.
  32762. container.style.borderWidth = 0;
  32763. }
  32764. }
  32765. container.style.left = rect[0] + 'px';
  32766. container.style.top = rect[1] + 'px';
  32767. container.style.width = width + 'px';
  32768. container.style.height = height + 'px';
  32769. return container;
  32770. },
  32771. /**
  32772. * Create a popup for the annotation's HTML element. This is used for
  32773. * annotations that do not have a Popup entry in the dictionary, but
  32774. * are of a type that works with popups (such as Highlight annotations).
  32775. *
  32776. * @private
  32777. * @param {HTMLSectionElement} container
  32778. * @param {HTMLDivElement|HTMLImageElement|null} trigger
  32779. * @param {Object} data
  32780. * @memberof AnnotationElement
  32781. */
  32782. _createPopup: function AnnotationElement_createPopup(container, trigger, data) {
  32783. // If no trigger element is specified, create it.
  32784. if (!trigger) {
  32785. trigger = document.createElement('div');
  32786. trigger.style.height = container.style.height;
  32787. trigger.style.width = container.style.width;
  32788. container.appendChild(trigger);
  32789. }
  32790. var popupElement = new PopupElement({
  32791. container: container,
  32792. trigger: trigger,
  32793. color: data.color,
  32794. title: data.title,
  32795. contents: data.contents,
  32796. hideWrapper: true
  32797. });
  32798. var popup = popupElement.render();
  32799. // Position the popup next to the annotation's container.
  32800. popup.style.left = container.style.width;
  32801. container.appendChild(popup);
  32802. },
  32803. /**
  32804. * Render the annotation's HTML element in the empty container.
  32805. *
  32806. * @public
  32807. * @memberof AnnotationElement
  32808. */
  32809. render: function AnnotationElement_render() {
  32810. throw new Error('Abstract method AnnotationElement.render called');
  32811. }
  32812. };
  32813. return AnnotationElement;
  32814. }();
  32815. /**
  32816. * @class
  32817. * @alias LinkAnnotationElement
  32818. */
  32819. var LinkAnnotationElement = function LinkAnnotationElementClosure() {
  32820. function LinkAnnotationElement(parameters) {
  32821. AnnotationElement.call(this, parameters, true);
  32822. }
  32823. Util.inherit(LinkAnnotationElement, AnnotationElement, {
  32824. /**
  32825. * Render the link annotation's HTML element in the empty container.
  32826. *
  32827. * @public
  32828. * @memberof LinkAnnotationElement
  32829. * @returns {HTMLSectionElement}
  32830. */
  32831. render: function LinkAnnotationElement_render() {
  32832. this.container.className = 'linkAnnotation';
  32833. var link = document.createElement('a');
  32834. addLinkAttributes(link, {
  32835. url: this.data.url,
  32836. target: this.data.newWindow ? LinkTarget.BLANK : undefined
  32837. });
  32838. if (!this.data.url) {
  32839. if (this.data.action) {
  32840. this._bindNamedAction(link, this.data.action);
  32841. } else {
  32842. this._bindLink(link, this.data.dest);
  32843. }
  32844. }
  32845. this.container.appendChild(link);
  32846. return this.container;
  32847. },
  32848. /**
  32849. * Bind internal links to the link element.
  32850. *
  32851. * @private
  32852. * @param {Object} link
  32853. * @param {Object} destination
  32854. * @memberof LinkAnnotationElement
  32855. */
  32856. _bindLink: function LinkAnnotationElement_bindLink(link, destination) {
  32857. var self = this;
  32858. link.href = this.linkService.getDestinationHash(destination);
  32859. link.onclick = function () {
  32860. if (destination) {
  32861. self.linkService.navigateTo(destination);
  32862. }
  32863. return false;
  32864. };
  32865. if (destination) {
  32866. link.className = 'internalLink';
  32867. }
  32868. },
  32869. /**
  32870. * Bind named actions to the link element.
  32871. *
  32872. * @private
  32873. * @param {Object} link
  32874. * @param {Object} action
  32875. * @memberof LinkAnnotationElement
  32876. */
  32877. _bindNamedAction: function LinkAnnotationElement_bindNamedAction(link, action) {
  32878. var self = this;
  32879. link.href = this.linkService.getAnchorUrl('');
  32880. link.onclick = function () {
  32881. self.linkService.executeNamedAction(action);
  32882. return false;
  32883. };
  32884. link.className = 'internalLink';
  32885. }
  32886. });
  32887. return LinkAnnotationElement;
  32888. }();
  32889. /**
  32890. * @class
  32891. * @alias TextAnnotationElement
  32892. */
  32893. var TextAnnotationElement = function TextAnnotationElementClosure() {
  32894. function TextAnnotationElement(parameters) {
  32895. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  32896. AnnotationElement.call(this, parameters, isRenderable);
  32897. }
  32898. Util.inherit(TextAnnotationElement, AnnotationElement, {
  32899. /**
  32900. * Render the text annotation's HTML element in the empty container.
  32901. *
  32902. * @public
  32903. * @memberof TextAnnotationElement
  32904. * @returns {HTMLSectionElement}
  32905. */
  32906. render: function TextAnnotationElement_render() {
  32907. this.container.className = 'textAnnotation';
  32908. var image = document.createElement('img');
  32909. image.style.height = this.container.style.height;
  32910. image.style.width = this.container.style.width;
  32911. image.src = this.imageResourcesPath + 'annotation-' + this.data.name.toLowerCase() + '.svg';
  32912. image.alt = '[{{type}} Annotation]';
  32913. image.dataset.l10nId = 'text_annotation_type';
  32914. image.dataset.l10nArgs = JSON.stringify({ type: this.data.name });
  32915. if (!this.data.hasPopup) {
  32916. this._createPopup(this.container, image, this.data);
  32917. }
  32918. this.container.appendChild(image);
  32919. return this.container;
  32920. }
  32921. });
  32922. return TextAnnotationElement;
  32923. }();
  32924. /**
  32925. * @class
  32926. * @alias WidgetAnnotationElement
  32927. */
  32928. var WidgetAnnotationElement = function WidgetAnnotationElementClosure() {
  32929. function WidgetAnnotationElement(parameters, isRenderable) {
  32930. AnnotationElement.call(this, parameters, isRenderable);
  32931. }
  32932. Util.inherit(WidgetAnnotationElement, AnnotationElement, {
  32933. /**
  32934. * Render the widget annotation's HTML element in the empty container.
  32935. *
  32936. * @public
  32937. * @memberof WidgetAnnotationElement
  32938. * @returns {HTMLSectionElement}
  32939. */
  32940. render: function WidgetAnnotationElement_render() {
  32941. // Show only the container for unsupported field types.
  32942. return this.container;
  32943. }
  32944. });
  32945. return WidgetAnnotationElement;
  32946. }();
  32947. /**
  32948. * @class
  32949. * @alias TextWidgetAnnotationElement
  32950. */
  32951. var TextWidgetAnnotationElement = function TextWidgetAnnotationElementClosure() {
  32952. var TEXT_ALIGNMENT = [
  32953. 'left',
  32954. 'center',
  32955. 'right'
  32956. ];
  32957. function TextWidgetAnnotationElement(parameters) {
  32958. var isRenderable = parameters.renderInteractiveForms || !parameters.data.hasAppearance && !!parameters.data.fieldValue;
  32959. WidgetAnnotationElement.call(this, parameters, isRenderable);
  32960. }
  32961. Util.inherit(TextWidgetAnnotationElement, WidgetAnnotationElement, {
  32962. /**
  32963. * Render the text widget annotation's HTML element in the empty container.
  32964. *
  32965. * @public
  32966. * @memberof TextWidgetAnnotationElement
  32967. * @returns {HTMLSectionElement}
  32968. */
  32969. render: function TextWidgetAnnotationElement_render() {
  32970. this.container.className = 'textWidgetAnnotation';
  32971. var element = null;
  32972. if (this.renderInteractiveForms) {
  32973. // NOTE: We cannot set the values using `element.value` below, since it
  32974. // prevents the AnnotationLayer rasterizer in `test/driver.js`
  32975. // from parsing the elements correctly for the reference tests.
  32976. if (this.data.multiLine) {
  32977. element = document.createElement('textarea');
  32978. element.textContent = this.data.fieldValue;
  32979. } else {
  32980. element = document.createElement('input');
  32981. element.type = 'text';
  32982. element.setAttribute('value', this.data.fieldValue);
  32983. }
  32984. element.disabled = this.data.readOnly;
  32985. if (this.data.maxLen !== null) {
  32986. element.maxLength = this.data.maxLen;
  32987. }
  32988. if (this.data.comb) {
  32989. var fieldWidth = this.data.rect[2] - this.data.rect[0];
  32990. var combWidth = fieldWidth / this.data.maxLen;
  32991. element.classList.add('comb');
  32992. element.style.letterSpacing = 'calc(' + combWidth + 'px - 1ch)';
  32993. }
  32994. } else {
  32995. element = document.createElement('div');
  32996. element.textContent = this.data.fieldValue;
  32997. element.style.verticalAlign = 'middle';
  32998. element.style.display = 'table-cell';
  32999. var font = null;
  33000. if (this.data.fontRefName) {
  33001. font = this.page.commonObjs.getData(this.data.fontRefName);
  33002. }
  33003. this._setTextStyle(element, font);
  33004. }
  33005. if (this.data.textAlignment !== null) {
  33006. element.style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];
  33007. }
  33008. this.container.appendChild(element);
  33009. return this.container;
  33010. },
  33011. /**
  33012. * Apply text styles to the text in the element.
  33013. *
  33014. * @private
  33015. * @param {HTMLDivElement} element
  33016. * @param {Object} font
  33017. * @memberof TextWidgetAnnotationElement
  33018. */
  33019. _setTextStyle: function TextWidgetAnnotationElement_setTextStyle(element, font) {
  33020. // TODO: This duplicates some of the logic in CanvasGraphics.setFont().
  33021. var style = element.style;
  33022. style.fontSize = this.data.fontSize + 'px';
  33023. style.direction = this.data.fontDirection < 0 ? 'rtl' : 'ltr';
  33024. if (!font) {
  33025. return;
  33026. }
  33027. style.fontWeight = font.black ? font.bold ? '900' : 'bold' : font.bold ? 'bold' : 'normal';
  33028. style.fontStyle = font.italic ? 'italic' : 'normal';
  33029. // Use a reasonable default font if the font doesn't specify a fallback.
  33030. var fontFamily = font.loadedName ? '"' + font.loadedName + '", ' : '';
  33031. var fallbackName = font.fallbackName || 'Helvetica, sans-serif';
  33032. style.fontFamily = fontFamily + fallbackName;
  33033. }
  33034. });
  33035. return TextWidgetAnnotationElement;
  33036. }();
  33037. /**
  33038. * @class
  33039. * @alias ChoiceWidgetAnnotationElement
  33040. */
  33041. var ChoiceWidgetAnnotationElement = function ChoiceWidgetAnnotationElementClosure() {
  33042. function ChoiceWidgetAnnotationElement(parameters) {
  33043. WidgetAnnotationElement.call(this, parameters, parameters.renderInteractiveForms);
  33044. }
  33045. Util.inherit(ChoiceWidgetAnnotationElement, WidgetAnnotationElement, {
  33046. /**
  33047. * Render the choice widget annotation's HTML element in the empty
  33048. * container.
  33049. *
  33050. * @public
  33051. * @memberof ChoiceWidgetAnnotationElement
  33052. * @returns {HTMLSectionElement}
  33053. */
  33054. render: function ChoiceWidgetAnnotationElement_render() {
  33055. this.container.className = 'choiceWidgetAnnotation';
  33056. var selectElement = document.createElement('select');
  33057. selectElement.disabled = this.data.readOnly;
  33058. if (!this.data.combo) {
  33059. // List boxes have a size and (optionally) multiple selection.
  33060. selectElement.size = this.data.options.length;
  33061. if (this.data.multiSelect) {
  33062. selectElement.multiple = true;
  33063. }
  33064. }
  33065. // Insert the options into the choice field.
  33066. for (var i = 0, ii = this.data.options.length; i < ii; i++) {
  33067. var option = this.data.options[i];
  33068. var optionElement = document.createElement('option');
  33069. optionElement.textContent = option.displayValue;
  33070. optionElement.value = option.exportValue;
  33071. if (this.data.fieldValue.indexOf(option.displayValue) >= 0) {
  33072. optionElement.setAttribute('selected', true);
  33073. }
  33074. selectElement.appendChild(optionElement);
  33075. }
  33076. this.container.appendChild(selectElement);
  33077. return this.container;
  33078. }
  33079. });
  33080. return ChoiceWidgetAnnotationElement;
  33081. }();
  33082. /**
  33083. * @class
  33084. * @alias PopupAnnotationElement
  33085. */
  33086. var PopupAnnotationElement = function PopupAnnotationElementClosure() {
  33087. function PopupAnnotationElement(parameters) {
  33088. var isRenderable = !!(parameters.data.title || parameters.data.contents);
  33089. AnnotationElement.call(this, parameters, isRenderable);
  33090. }
  33091. Util.inherit(PopupAnnotationElement, AnnotationElement, {
  33092. /**
  33093. * Render the popup annotation's HTML element in the empty container.
  33094. *
  33095. * @public
  33096. * @memberof PopupAnnotationElement
  33097. * @returns {HTMLSectionElement}
  33098. */
  33099. render: function PopupAnnotationElement_render() {
  33100. this.container.className = 'popupAnnotation';
  33101. var selector = '[data-annotation-id="' + this.data.parentId + '"]';
  33102. var parentElement = this.layer.querySelector(selector);
  33103. if (!parentElement) {
  33104. return this.container;
  33105. }
  33106. var popup = new PopupElement({
  33107. container: this.container,
  33108. trigger: parentElement,
  33109. color: this.data.color,
  33110. title: this.data.title,
  33111. contents: this.data.contents
  33112. });
  33113. // Position the popup next to the parent annotation's container.
  33114. // PDF viewers ignore a popup annotation's rectangle.
  33115. var parentLeft = parseFloat(parentElement.style.left);
  33116. var parentWidth = parseFloat(parentElement.style.width);
  33117. CustomStyle.setProp('transformOrigin', this.container, -(parentLeft + parentWidth) + 'px -' + parentElement.style.top);
  33118. this.container.style.left = parentLeft + parentWidth + 'px';
  33119. this.container.appendChild(popup.render());
  33120. return this.container;
  33121. }
  33122. });
  33123. return PopupAnnotationElement;
  33124. }();
  33125. /**
  33126. * @class
  33127. * @alias PopupElement
  33128. */
  33129. var PopupElement = function PopupElementClosure() {
  33130. var BACKGROUND_ENLIGHT = 0.7;
  33131. function PopupElement(parameters) {
  33132. this.container = parameters.container;
  33133. this.trigger = parameters.trigger;
  33134. this.color = parameters.color;
  33135. this.title = parameters.title;
  33136. this.contents = parameters.contents;
  33137. this.hideWrapper = parameters.hideWrapper || false;
  33138. this.pinned = false;
  33139. }
  33140. PopupElement.prototype = /** @lends PopupElement.prototype */
  33141. {
  33142. /**
  33143. * Render the popup's HTML element.
  33144. *
  33145. * @public
  33146. * @memberof PopupElement
  33147. * @returns {HTMLSectionElement}
  33148. */
  33149. render: function PopupElement_render() {
  33150. var wrapper = document.createElement('div');
  33151. wrapper.className = 'popupWrapper';
  33152. // For Popup annotations we hide the entire section because it contains
  33153. // only the popup. However, for Text annotations without a separate Popup
  33154. // annotation, we cannot hide the entire container as the image would
  33155. // disappear too. In that special case, hiding the wrapper suffices.
  33156. this.hideElement = this.hideWrapper ? wrapper : this.container;
  33157. this.hideElement.setAttribute('hidden', true);
  33158. var popup = document.createElement('div');
  33159. popup.className = 'popup';
  33160. var color = this.color;
  33161. if (color) {
  33162. // Enlighten the color.
  33163. var r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
  33164. var g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
  33165. var b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
  33166. popup.style.backgroundColor = Util.makeCssRgb(r | 0, g | 0, b | 0);
  33167. }
  33168. var contents = this._formatContents(this.contents);
  33169. var title = document.createElement('h1');
  33170. title.textContent = this.title;
  33171. // Attach the event listeners to the trigger element.
  33172. this.trigger.addEventListener('click', this._toggle.bind(this));
  33173. this.trigger.addEventListener('mouseover', this._show.bind(this, false));
  33174. this.trigger.addEventListener('mouseout', this._hide.bind(this, false));
  33175. popup.addEventListener('click', this._hide.bind(this, true));
  33176. popup.appendChild(title);
  33177. popup.appendChild(contents);
  33178. wrapper.appendChild(popup);
  33179. return wrapper;
  33180. },
  33181. /**
  33182. * Format the contents of the popup by adding newlines where necessary.
  33183. *
  33184. * @private
  33185. * @param {string} contents
  33186. * @memberof PopupElement
  33187. * @returns {HTMLParagraphElement}
  33188. */
  33189. _formatContents: function PopupElement_formatContents(contents) {
  33190. var p = document.createElement('p');
  33191. var lines = contents.split(/(?:\r\n?|\n)/);
  33192. for (var i = 0, ii = lines.length; i < ii; ++i) {
  33193. var line = lines[i];
  33194. p.appendChild(document.createTextNode(line));
  33195. if (i < ii - 1) {
  33196. p.appendChild(document.createElement('br'));
  33197. }
  33198. }
  33199. return p;
  33200. },
  33201. /**
  33202. * Toggle the visibility of the popup.
  33203. *
  33204. * @private
  33205. * @memberof PopupElement
  33206. */
  33207. _toggle: function PopupElement_toggle() {
  33208. if (this.pinned) {
  33209. this._hide(true);
  33210. } else {
  33211. this._show(true);
  33212. }
  33213. },
  33214. /**
  33215. * Show the popup.
  33216. *
  33217. * @private
  33218. * @param {boolean} pin
  33219. * @memberof PopupElement
  33220. */
  33221. _show: function PopupElement_show(pin) {
  33222. if (pin) {
  33223. this.pinned = true;
  33224. }
  33225. if (this.hideElement.hasAttribute('hidden')) {
  33226. this.hideElement.removeAttribute('hidden');
  33227. this.container.style.zIndex += 1;
  33228. }
  33229. },
  33230. /**
  33231. * Hide the popup.
  33232. *
  33233. * @private
  33234. * @param {boolean} unpin
  33235. * @memberof PopupElement
  33236. */
  33237. _hide: function PopupElement_hide(unpin) {
  33238. if (unpin) {
  33239. this.pinned = false;
  33240. }
  33241. if (!this.hideElement.hasAttribute('hidden') && !this.pinned) {
  33242. this.hideElement.setAttribute('hidden', true);
  33243. this.container.style.zIndex -= 1;
  33244. }
  33245. }
  33246. };
  33247. return PopupElement;
  33248. }();
  33249. /**
  33250. * @class
  33251. * @alias HighlightAnnotationElement
  33252. */
  33253. var HighlightAnnotationElement = function HighlightAnnotationElementClosure() {
  33254. function HighlightAnnotationElement(parameters) {
  33255. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  33256. AnnotationElement.call(this, parameters, isRenderable);
  33257. }
  33258. Util.inherit(HighlightAnnotationElement, AnnotationElement, {
  33259. /**
  33260. * Render the highlight annotation's HTML element in the empty container.
  33261. *
  33262. * @public
  33263. * @memberof HighlightAnnotationElement
  33264. * @returns {HTMLSectionElement}
  33265. */
  33266. render: function HighlightAnnotationElement_render() {
  33267. this.container.className = 'highlightAnnotation';
  33268. if (!this.data.hasPopup) {
  33269. this._createPopup(this.container, null, this.data);
  33270. }
  33271. return this.container;
  33272. }
  33273. });
  33274. return HighlightAnnotationElement;
  33275. }();
  33276. /**
  33277. * @class
  33278. * @alias UnderlineAnnotationElement
  33279. */
  33280. var UnderlineAnnotationElement = function UnderlineAnnotationElementClosure() {
  33281. function UnderlineAnnotationElement(parameters) {
  33282. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  33283. AnnotationElement.call(this, parameters, isRenderable);
  33284. }
  33285. Util.inherit(UnderlineAnnotationElement, AnnotationElement, {
  33286. /**
  33287. * Render the underline annotation's HTML element in the empty container.
  33288. *
  33289. * @public
  33290. * @memberof UnderlineAnnotationElement
  33291. * @returns {HTMLSectionElement}
  33292. */
  33293. render: function UnderlineAnnotationElement_render() {
  33294. this.container.className = 'underlineAnnotation';
  33295. if (!this.data.hasPopup) {
  33296. this._createPopup(this.container, null, this.data);
  33297. }
  33298. return this.container;
  33299. }
  33300. });
  33301. return UnderlineAnnotationElement;
  33302. }();
  33303. /**
  33304. * @class
  33305. * @alias SquigglyAnnotationElement
  33306. */
  33307. var SquigglyAnnotationElement = function SquigglyAnnotationElementClosure() {
  33308. function SquigglyAnnotationElement(parameters) {
  33309. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  33310. AnnotationElement.call(this, parameters, isRenderable);
  33311. }
  33312. Util.inherit(SquigglyAnnotationElement, AnnotationElement, {
  33313. /**
  33314. * Render the squiggly annotation's HTML element in the empty container.
  33315. *
  33316. * @public
  33317. * @memberof SquigglyAnnotationElement
  33318. * @returns {HTMLSectionElement}
  33319. */
  33320. render: function SquigglyAnnotationElement_render() {
  33321. this.container.className = 'squigglyAnnotation';
  33322. if (!this.data.hasPopup) {
  33323. this._createPopup(this.container, null, this.data);
  33324. }
  33325. return this.container;
  33326. }
  33327. });
  33328. return SquigglyAnnotationElement;
  33329. }();
  33330. /**
  33331. * @class
  33332. * @alias StrikeOutAnnotationElement
  33333. */
  33334. var StrikeOutAnnotationElement = function StrikeOutAnnotationElementClosure() {
  33335. function StrikeOutAnnotationElement(parameters) {
  33336. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  33337. AnnotationElement.call(this, parameters, isRenderable);
  33338. }
  33339. Util.inherit(StrikeOutAnnotationElement, AnnotationElement, {
  33340. /**
  33341. * Render the strikeout annotation's HTML element in the empty container.
  33342. *
  33343. * @public
  33344. * @memberof StrikeOutAnnotationElement
  33345. * @returns {HTMLSectionElement}
  33346. */
  33347. render: function StrikeOutAnnotationElement_render() {
  33348. this.container.className = 'strikeoutAnnotation';
  33349. if (!this.data.hasPopup) {
  33350. this._createPopup(this.container, null, this.data);
  33351. }
  33352. return this.container;
  33353. }
  33354. });
  33355. return StrikeOutAnnotationElement;
  33356. }();
  33357. /**
  33358. * @class
  33359. * @alias FileAttachmentAnnotationElement
  33360. */
  33361. var FileAttachmentAnnotationElement = function FileAttachmentAnnotationElementClosure() {
  33362. function FileAttachmentAnnotationElement(parameters) {
  33363. AnnotationElement.call(this, parameters, true);
  33364. this.filename = getFilenameFromUrl(parameters.data.file.filename);
  33365. this.content = parameters.data.file.content;
  33366. }
  33367. Util.inherit(FileAttachmentAnnotationElement, AnnotationElement, {
  33368. /**
  33369. * Render the file attachment annotation's HTML element in the empty
  33370. * container.
  33371. *
  33372. * @public
  33373. * @memberof FileAttachmentAnnotationElement
  33374. * @returns {HTMLSectionElement}
  33375. */
  33376. render: function FileAttachmentAnnotationElement_render() {
  33377. this.container.className = 'fileAttachmentAnnotation';
  33378. var trigger = document.createElement('div');
  33379. trigger.style.height = this.container.style.height;
  33380. trigger.style.width = this.container.style.width;
  33381. trigger.addEventListener('dblclick', this._download.bind(this));
  33382. if (!this.data.hasPopup && (this.data.title || this.data.contents)) {
  33383. this._createPopup(this.container, trigger, this.data);
  33384. }
  33385. this.container.appendChild(trigger);
  33386. return this.container;
  33387. },
  33388. /**
  33389. * Download the file attachment associated with this annotation.
  33390. *
  33391. * @private
  33392. * @memberof FileAttachmentAnnotationElement
  33393. */
  33394. _download: function FileAttachmentAnnotationElement_download() {
  33395. if (!this.downloadManager) {
  33396. warn('Download cannot be started due to unavailable download manager');
  33397. return;
  33398. }
  33399. this.downloadManager.downloadData(this.content, this.filename, '');
  33400. }
  33401. });
  33402. return FileAttachmentAnnotationElement;
  33403. }();
  33404. /**
  33405. * @typedef {Object} AnnotationLayerParameters
  33406. * @property {PageViewport} viewport
  33407. * @property {HTMLDivElement} div
  33408. * @property {Array} annotations
  33409. * @property {PDFPage} page
  33410. * @property {IPDFLinkService} linkService
  33411. * @property {string} imageResourcesPath
  33412. * @property {boolean} renderInteractiveForms
  33413. */
  33414. /**
  33415. * @class
  33416. * @alias AnnotationLayer
  33417. */
  33418. var AnnotationLayer = function AnnotationLayerClosure() {
  33419. return {
  33420. /**
  33421. * Render a new annotation layer with all annotation elements.
  33422. *
  33423. * @public
  33424. * @param {AnnotationLayerParameters} parameters
  33425. * @memberof AnnotationLayer
  33426. */
  33427. render: function AnnotationLayer_render(parameters) {
  33428. var annotationElementFactory = new AnnotationElementFactory();
  33429. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  33430. var data = parameters.annotations[i];
  33431. if (!data) {
  33432. continue;
  33433. }
  33434. var properties = {
  33435. data: data,
  33436. layer: parameters.div,
  33437. page: parameters.page,
  33438. viewport: parameters.viewport,
  33439. linkService: parameters.linkService,
  33440. downloadManager: parameters.downloadManager,
  33441. imageResourcesPath: parameters.imageResourcesPath || getDefaultSetting('imageResourcesPath'),
  33442. renderInteractiveForms: parameters.renderInteractiveForms || false
  33443. };
  33444. var element = annotationElementFactory.create(properties);
  33445. if (element.isRenderable) {
  33446. parameters.div.appendChild(element.render());
  33447. }
  33448. }
  33449. },
  33450. /**
  33451. * Update the annotation elements on existing annotation layer.
  33452. *
  33453. * @public
  33454. * @param {AnnotationLayerParameters} parameters
  33455. * @memberof AnnotationLayer
  33456. */
  33457. update: function AnnotationLayer_update(parameters) {
  33458. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  33459. var data = parameters.annotations[i];
  33460. var element = parameters.div.querySelector('[data-annotation-id="' + data.id + '"]');
  33461. if (element) {
  33462. CustomStyle.setProp('transform', element, 'matrix(' + parameters.viewport.transform.join(',') + ')');
  33463. }
  33464. }
  33465. parameters.div.removeAttribute('hidden');
  33466. }
  33467. };
  33468. }();
  33469. exports.AnnotationLayer = AnnotationLayer;
  33470. }));
  33471. (function (root, factory) {
  33472. factory(root.pdfjsDisplayTextLayer = {}, root.pdfjsSharedUtil, root.pdfjsDisplayDOMUtils);
  33473. }(this, function (exports, sharedUtil, displayDOMUtils) {
  33474. var Util = sharedUtil.Util;
  33475. var createPromiseCapability = sharedUtil.createPromiseCapability;
  33476. var CustomStyle = displayDOMUtils.CustomStyle;
  33477. var getDefaultSetting = displayDOMUtils.getDefaultSetting;
  33478. /**
  33479. * Text layer render parameters.
  33480. *
  33481. * @typedef {Object} TextLayerRenderParameters
  33482. * @property {TextContent} textContent - Text content to render (the object is
  33483. * returned by the page's getTextContent() method).
  33484. * @property {HTMLElement} container - HTML element that will contain text runs.
  33485. * @property {PageViewport} viewport - The target viewport to properly
  33486. * layout the text runs.
  33487. * @property {Array} textDivs - (optional) HTML elements that are correspond
  33488. * the text items of the textContent input. This is output and shall be
  33489. * initially be set to empty array.
  33490. * @property {number} timeout - (optional) Delay in milliseconds before
  33491. * rendering of the text runs occurs.
  33492. * @property {boolean} enhanceTextSelection - (optional) Whether to turn on the
  33493. * text selection enhancement.
  33494. */
  33495. var renderTextLayer = function renderTextLayerClosure() {
  33496. var MAX_TEXT_DIVS_TO_RENDER = 100000;
  33497. var NonWhitespaceRegexp = /\S/;
  33498. function isAllWhitespace(str) {
  33499. return !NonWhitespaceRegexp.test(str);
  33500. }
  33501. // Text layers may contain many thousand div's, and using `styleBuf` avoids
  33502. // creating many intermediate strings when building their 'style' properties.
  33503. var styleBuf = [
  33504. 'left: ',
  33505. 0,
  33506. 'px; top: ',
  33507. 0,
  33508. 'px; font-size: ',
  33509. 0,
  33510. 'px; font-family: ',
  33511. '',
  33512. ';'
  33513. ];
  33514. function appendText(task, geom, styles) {
  33515. // Initialize all used properties to keep the caches monomorphic.
  33516. var textDiv = document.createElement('div');
  33517. var textDivProperties = {
  33518. style: null,
  33519. angle: 0,
  33520. canvasWidth: 0,
  33521. isWhitespace: false,
  33522. originalTransform: null,
  33523. paddingBottom: 0,
  33524. paddingLeft: 0,
  33525. paddingRight: 0,
  33526. paddingTop: 0,
  33527. scale: 1
  33528. };
  33529. task._textDivs.push(textDiv);
  33530. if (isAllWhitespace(geom.str)) {
  33531. textDivProperties.isWhitespace = true;
  33532. task._textDivProperties.set(textDiv, textDivProperties);
  33533. return;
  33534. }
  33535. var tx = Util.transform(task._viewport.transform, geom.transform);
  33536. var angle = Math.atan2(tx[1], tx[0]);
  33537. var style = styles[geom.fontName];
  33538. if (style.vertical) {
  33539. angle += Math.PI / 2;
  33540. }
  33541. var fontHeight = Math.sqrt(tx[2] * tx[2] + tx[3] * tx[3]);
  33542. var fontAscent = fontHeight;
  33543. if (style.ascent) {
  33544. fontAscent = style.ascent * fontAscent;
  33545. } else if (style.descent) {
  33546. fontAscent = (1 + style.descent) * fontAscent;
  33547. }
  33548. var left;
  33549. var top;
  33550. if (angle === 0) {
  33551. left = tx[4];
  33552. top = tx[5] - fontAscent;
  33553. } else {
  33554. left = tx[4] + fontAscent * Math.sin(angle);
  33555. top = tx[5] - fontAscent * Math.cos(angle);
  33556. }
  33557. styleBuf[1] = left;
  33558. styleBuf[3] = top;
  33559. styleBuf[5] = fontHeight;
  33560. styleBuf[7] = style.fontFamily;
  33561. textDivProperties.style = styleBuf.join('');
  33562. textDiv.setAttribute('style', textDivProperties.style);
  33563. textDiv.textContent = geom.str;
  33564. // |fontName| is only used by the Font Inspector. This test will succeed
  33565. // when e.g. the Font Inspector is off but the Stepper is on, but it's
  33566. // not worth the effort to do a more accurate test. We only use `dataset`
  33567. // here to make the font name available for the debugger.
  33568. if (getDefaultSetting('pdfBug')) {
  33569. textDiv.dataset.fontName = geom.fontName;
  33570. }
  33571. if (angle !== 0) {
  33572. textDivProperties.angle = angle * (180 / Math.PI);
  33573. }
  33574. // We don't bother scaling single-char text divs, because it has very
  33575. // little effect on text highlighting. This makes scrolling on docs with
  33576. // lots of such divs a lot faster.
  33577. if (geom.str.length > 1) {
  33578. if (style.vertical) {
  33579. textDivProperties.canvasWidth = geom.height * task._viewport.scale;
  33580. } else {
  33581. textDivProperties.canvasWidth = geom.width * task._viewport.scale;
  33582. }
  33583. }
  33584. task._textDivProperties.set(textDiv, textDivProperties);
  33585. if (task._enhanceTextSelection) {
  33586. var angleCos = 1, angleSin = 0;
  33587. if (angle !== 0) {
  33588. angleCos = Math.cos(angle);
  33589. angleSin = Math.sin(angle);
  33590. }
  33591. var divWidth = (style.vertical ? geom.height : geom.width) * task._viewport.scale;
  33592. var divHeight = fontHeight;
  33593. var m, b;
  33594. if (angle !== 0) {
  33595. m = [
  33596. angleCos,
  33597. angleSin,
  33598. -angleSin,
  33599. angleCos,
  33600. left,
  33601. top
  33602. ];
  33603. b = Util.getAxialAlignedBoundingBox([
  33604. 0,
  33605. 0,
  33606. divWidth,
  33607. divHeight
  33608. ], m);
  33609. } else {
  33610. b = [
  33611. left,
  33612. top,
  33613. left + divWidth,
  33614. top + divHeight
  33615. ];
  33616. }
  33617. task._bounds.push({
  33618. left: b[0],
  33619. top: b[1],
  33620. right: b[2],
  33621. bottom: b[3],
  33622. div: textDiv,
  33623. size: [
  33624. divWidth,
  33625. divHeight
  33626. ],
  33627. m: m
  33628. });
  33629. }
  33630. }
  33631. function render(task) {
  33632. if (task._canceled) {
  33633. return;
  33634. }
  33635. var textLayerFrag = task._container;
  33636. var textDivs = task._textDivs;
  33637. var capability = task._capability;
  33638. var textDivsLength = textDivs.length;
  33639. // No point in rendering many divs as it would make the browser
  33640. // unusable even after the divs are rendered.
  33641. if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
  33642. task._renderingDone = true;
  33643. capability.resolve();
  33644. return;
  33645. }
  33646. var canvas = document.createElement('canvas');
  33647. var ctx = canvas.getContext('2d', { alpha: false });
  33648. var lastFontSize;
  33649. var lastFontFamily;
  33650. for (var i = 0; i < textDivsLength; i++) {
  33651. var textDiv = textDivs[i];
  33652. var textDivProperties = task._textDivProperties.get(textDiv);
  33653. if (textDivProperties.isWhitespace) {
  33654. continue;
  33655. }
  33656. var fontSize = textDiv.style.fontSize;
  33657. var fontFamily = textDiv.style.fontFamily;
  33658. // Only build font string and set to context if different from last.
  33659. if (fontSize !== lastFontSize || fontFamily !== lastFontFamily) {
  33660. ctx.font = fontSize + ' ' + fontFamily;
  33661. lastFontSize = fontSize;
  33662. lastFontFamily = fontFamily;
  33663. }
  33664. var width = ctx.measureText(textDiv.textContent).width;
  33665. textLayerFrag.appendChild(textDiv);
  33666. var transform = '';
  33667. if (textDivProperties.canvasWidth !== 0 && width > 0) {
  33668. textDivProperties.scale = textDivProperties.canvasWidth / width;
  33669. transform = 'scaleX(' + textDivProperties.scale + ')';
  33670. }
  33671. if (textDivProperties.angle !== 0) {
  33672. transform = 'rotate(' + textDivProperties.angle + 'deg) ' + transform;
  33673. }
  33674. if (transform !== '') {
  33675. textDivProperties.originalTransform = transform;
  33676. CustomStyle.setProp('transform', textDiv, transform);
  33677. }
  33678. task._textDivProperties.set(textDiv, textDivProperties);
  33679. }
  33680. task._renderingDone = true;
  33681. capability.resolve();
  33682. }
  33683. function expand(task) {
  33684. var bounds = task._bounds;
  33685. var viewport = task._viewport;
  33686. var expanded = expandBounds(viewport.width, viewport.height, bounds);
  33687. for (var i = 0; i < expanded.length; i++) {
  33688. var div = bounds[i].div;
  33689. var divProperties = task._textDivProperties.get(div);
  33690. if (divProperties.angle === 0) {
  33691. divProperties.paddingLeft = bounds[i].left - expanded[i].left;
  33692. divProperties.paddingTop = bounds[i].top - expanded[i].top;
  33693. divProperties.paddingRight = expanded[i].right - bounds[i].right;
  33694. divProperties.paddingBottom = expanded[i].bottom - bounds[i].bottom;
  33695. task._textDivProperties.set(div, divProperties);
  33696. continue;
  33697. }
  33698. // Box is rotated -- trying to find padding so rotated div will not
  33699. // exceed its expanded bounds.
  33700. var e = expanded[i], b = bounds[i];
  33701. var m = b.m, c = m[0], s = m[1];
  33702. // Finding intersections with expanded box.
  33703. var points = [
  33704. [
  33705. 0,
  33706. 0
  33707. ],
  33708. [
  33709. 0,
  33710. b.size[1]
  33711. ],
  33712. [
  33713. b.size[0],
  33714. 0
  33715. ],
  33716. b.size
  33717. ];
  33718. var ts = new Float64Array(64);
  33719. points.forEach(function (p, i) {
  33720. var t = Util.applyTransform(p, m);
  33721. ts[i + 0] = c && (e.left - t[0]) / c;
  33722. ts[i + 4] = s && (e.top - t[1]) / s;
  33723. ts[i + 8] = c && (e.right - t[0]) / c;
  33724. ts[i + 12] = s && (e.bottom - t[1]) / s;
  33725. ts[i + 16] = s && (e.left - t[0]) / -s;
  33726. ts[i + 20] = c && (e.top - t[1]) / c;
  33727. ts[i + 24] = s && (e.right - t[0]) / -s;
  33728. ts[i + 28] = c && (e.bottom - t[1]) / c;
  33729. ts[i + 32] = c && (e.left - t[0]) / -c;
  33730. ts[i + 36] = s && (e.top - t[1]) / -s;
  33731. ts[i + 40] = c && (e.right - t[0]) / -c;
  33732. ts[i + 44] = s && (e.bottom - t[1]) / -s;
  33733. ts[i + 48] = s && (e.left - t[0]) / s;
  33734. ts[i + 52] = c && (e.top - t[1]) / -c;
  33735. ts[i + 56] = s && (e.right - t[0]) / s;
  33736. ts[i + 60] = c && (e.bottom - t[1]) / -c;
  33737. });
  33738. var findPositiveMin = function (ts, offset, count) {
  33739. var result = 0;
  33740. for (var i = 0; i < count; i++) {
  33741. var t = ts[offset++];
  33742. if (t > 0) {
  33743. result = result ? Math.min(t, result) : t;
  33744. }
  33745. }
  33746. return result;
  33747. };
  33748. // Not based on math, but to simplify calculations, using cos and sin
  33749. // absolute values to not exceed the box (it can but insignificantly).
  33750. var boxScale = 1 + Math.min(Math.abs(c), Math.abs(s));
  33751. divProperties.paddingLeft = findPositiveMin(ts, 32, 16) / boxScale;
  33752. divProperties.paddingTop = findPositiveMin(ts, 48, 16) / boxScale;
  33753. divProperties.paddingRight = findPositiveMin(ts, 0, 16) / boxScale;
  33754. divProperties.paddingBottom = findPositiveMin(ts, 16, 16) / boxScale;
  33755. task._textDivProperties.set(div, divProperties);
  33756. }
  33757. }
  33758. function expandBounds(width, height, boxes) {
  33759. var bounds = boxes.map(function (box, i) {
  33760. return {
  33761. x1: box.left,
  33762. y1: box.top,
  33763. x2: box.right,
  33764. y2: box.bottom,
  33765. index: i,
  33766. x1New: undefined,
  33767. x2New: undefined
  33768. };
  33769. });
  33770. expandBoundsLTR(width, bounds);
  33771. var expanded = new Array(boxes.length);
  33772. bounds.forEach(function (b) {
  33773. var i = b.index;
  33774. expanded[i] = {
  33775. left: b.x1New,
  33776. top: 0,
  33777. right: b.x2New,
  33778. bottom: 0
  33779. };
  33780. });
  33781. // Rotating on 90 degrees and extending extended boxes. Reusing the bounds
  33782. // array and objects.
  33783. boxes.map(function (box, i) {
  33784. var e = expanded[i], b = bounds[i];
  33785. b.x1 = box.top;
  33786. b.y1 = width - e.right;
  33787. b.x2 = box.bottom;
  33788. b.y2 = width - e.left;
  33789. b.index = i;
  33790. b.x1New = undefined;
  33791. b.x2New = undefined;
  33792. });
  33793. expandBoundsLTR(height, bounds);
  33794. bounds.forEach(function (b) {
  33795. var i = b.index;
  33796. expanded[i].top = b.x1New;
  33797. expanded[i].bottom = b.x2New;
  33798. });
  33799. return expanded;
  33800. }
  33801. function expandBoundsLTR(width, bounds) {
  33802. // Sorting by x1 coordinate and walk by the bounds in the same order.
  33803. bounds.sort(function (a, b) {
  33804. return a.x1 - b.x1 || a.index - b.index;
  33805. });
  33806. // First we see on the horizon is a fake boundary.
  33807. var fakeBoundary = {
  33808. x1: -Infinity,
  33809. y1: -Infinity,
  33810. x2: 0,
  33811. y2: Infinity,
  33812. index: -1,
  33813. x1New: 0,
  33814. x2New: 0
  33815. };
  33816. var horizon = [{
  33817. start: -Infinity,
  33818. end: Infinity,
  33819. boundary: fakeBoundary
  33820. }];
  33821. bounds.forEach(function (boundary) {
  33822. // Searching for the affected part of horizon.
  33823. // TODO red-black tree or simple binary search
  33824. var i = 0;
  33825. while (i < horizon.length && horizon[i].end <= boundary.y1) {
  33826. i++;
  33827. }
  33828. var j = horizon.length - 1;
  33829. while (j >= 0 && horizon[j].start >= boundary.y2) {
  33830. j--;
  33831. }
  33832. var horizonPart, affectedBoundary;
  33833. var q, k, maxXNew = -Infinity;
  33834. for (q = i; q <= j; q++) {
  33835. horizonPart = horizon[q];
  33836. affectedBoundary = horizonPart.boundary;
  33837. var xNew;
  33838. if (affectedBoundary.x2 > boundary.x1) {
  33839. // In the middle of the previous element, new x shall be at the
  33840. // boundary start. Extending if further if the affected bondary
  33841. // placed on top of the current one.
  33842. xNew = affectedBoundary.index > boundary.index ? affectedBoundary.x1New : boundary.x1;
  33843. } else if (affectedBoundary.x2New === undefined) {
  33844. // We have some space in between, new x in middle will be a fair
  33845. // choice.
  33846. xNew = (affectedBoundary.x2 + boundary.x1) / 2;
  33847. } else {
  33848. // Affected boundary has x2new set, using it as new x.
  33849. xNew = affectedBoundary.x2New;
  33850. }
  33851. if (xNew > maxXNew) {
  33852. maxXNew = xNew;
  33853. }
  33854. }
  33855. // Set new x1 for current boundary.
  33856. boundary.x1New = maxXNew;
  33857. // Adjusts new x2 for the affected boundaries.
  33858. for (q = i; q <= j; q++) {
  33859. horizonPart = horizon[q];
  33860. affectedBoundary = horizonPart.boundary;
  33861. if (affectedBoundary.x2New === undefined) {
  33862. // Was not set yet, choosing new x if possible.
  33863. if (affectedBoundary.x2 > boundary.x1) {
  33864. // Current and affected boundaries intersect. If affected boundary
  33865. // is placed on top of the current, shrinking the affected.
  33866. if (affectedBoundary.index > boundary.index) {
  33867. affectedBoundary.x2New = affectedBoundary.x2;
  33868. }
  33869. } else {
  33870. affectedBoundary.x2New = maxXNew;
  33871. }
  33872. } else if (affectedBoundary.x2New > maxXNew) {
  33873. // Affected boundary is touching new x, pushing it back.
  33874. affectedBoundary.x2New = Math.max(maxXNew, affectedBoundary.x2);
  33875. }
  33876. }
  33877. // Fixing the horizon.
  33878. var changedHorizon = [], lastBoundary = null;
  33879. for (q = i; q <= j; q++) {
  33880. horizonPart = horizon[q];
  33881. affectedBoundary = horizonPart.boundary;
  33882. // Checking which boundary will be visible.
  33883. var useBoundary = affectedBoundary.x2 > boundary.x2 ? affectedBoundary : boundary;
  33884. if (lastBoundary === useBoundary) {
  33885. // Merging with previous.
  33886. changedHorizon[changedHorizon.length - 1].end = horizonPart.end;
  33887. } else {
  33888. changedHorizon.push({
  33889. start: horizonPart.start,
  33890. end: horizonPart.end,
  33891. boundary: useBoundary
  33892. });
  33893. lastBoundary = useBoundary;
  33894. }
  33895. }
  33896. if (horizon[i].start < boundary.y1) {
  33897. changedHorizon[0].start = boundary.y1;
  33898. changedHorizon.unshift({
  33899. start: horizon[i].start,
  33900. end: boundary.y1,
  33901. boundary: horizon[i].boundary
  33902. });
  33903. }
  33904. if (boundary.y2 < horizon[j].end) {
  33905. changedHorizon[changedHorizon.length - 1].end = boundary.y2;
  33906. changedHorizon.push({
  33907. start: boundary.y2,
  33908. end: horizon[j].end,
  33909. boundary: horizon[j].boundary
  33910. });
  33911. }
  33912. // Set x2 new of boundary that is no longer visible (see overlapping case
  33913. // above).
  33914. // TODO more efficient, e.g. via reference counting.
  33915. for (q = i; q <= j; q++) {
  33916. horizonPart = horizon[q];
  33917. affectedBoundary = horizonPart.boundary;
  33918. if (affectedBoundary.x2New !== undefined) {
  33919. continue;
  33920. }
  33921. var used = false;
  33922. for (k = i - 1; !used && k >= 0 && horizon[k].start >= affectedBoundary.y1; k--) {
  33923. used = horizon[k].boundary === affectedBoundary;
  33924. }
  33925. for (k = j + 1; !used && k < horizon.length && horizon[k].end <= affectedBoundary.y2; k++) {
  33926. used = horizon[k].boundary === affectedBoundary;
  33927. }
  33928. for (k = 0; !used && k < changedHorizon.length; k++) {
  33929. used = changedHorizon[k].boundary === affectedBoundary;
  33930. }
  33931. if (!used) {
  33932. affectedBoundary.x2New = maxXNew;
  33933. }
  33934. }
  33935. Array.prototype.splice.apply(horizon, [
  33936. i,
  33937. j - i + 1
  33938. ].concat(changedHorizon));
  33939. });
  33940. // Set new x2 for all unset boundaries.
  33941. horizon.forEach(function (horizonPart) {
  33942. var affectedBoundary = horizonPart.boundary;
  33943. if (affectedBoundary.x2New === undefined) {
  33944. affectedBoundary.x2New = Math.max(width, affectedBoundary.x2);
  33945. }
  33946. });
  33947. }
  33948. /**
  33949. * Text layer rendering task.
  33950. *
  33951. * @param {TextContent} textContent
  33952. * @param {HTMLElement} container
  33953. * @param {PageViewport} viewport
  33954. * @param {Array} textDivs
  33955. * @param {boolean} enhanceTextSelection
  33956. * @private
  33957. */
  33958. function TextLayerRenderTask(textContent, container, viewport, textDivs, enhanceTextSelection) {
  33959. this._textContent = textContent;
  33960. this._container = container;
  33961. this._viewport = viewport;
  33962. this._textDivs = textDivs || [];
  33963. this._textDivProperties = new WeakMap();
  33964. this._renderingDone = false;
  33965. this._canceled = false;
  33966. this._capability = createPromiseCapability();
  33967. this._renderTimer = null;
  33968. this._bounds = [];
  33969. this._enhanceTextSelection = !!enhanceTextSelection;
  33970. }
  33971. TextLayerRenderTask.prototype = {
  33972. get promise() {
  33973. return this._capability.promise;
  33974. },
  33975. cancel: function TextLayer_cancel() {
  33976. this._canceled = true;
  33977. if (this._renderTimer !== null) {
  33978. clearTimeout(this._renderTimer);
  33979. this._renderTimer = null;
  33980. }
  33981. this._capability.reject('canceled');
  33982. },
  33983. _render: function TextLayer_render(timeout) {
  33984. var textItems = this._textContent.items;
  33985. var textStyles = this._textContent.styles;
  33986. for (var i = 0, len = textItems.length; i < len; i++) {
  33987. appendText(this, textItems[i], textStyles);
  33988. }
  33989. if (!timeout) {
  33990. // Render right away
  33991. render(this);
  33992. } else {
  33993. // Schedule
  33994. var self = this;
  33995. this._renderTimer = setTimeout(function () {
  33996. render(self);
  33997. self._renderTimer = null;
  33998. }, timeout);
  33999. }
  34000. },
  34001. expandTextDivs: function TextLayer_expandTextDivs(expandDivs) {
  34002. if (!this._enhanceTextSelection || !this._renderingDone) {
  34003. return;
  34004. }
  34005. if (this._bounds !== null) {
  34006. expand(this);
  34007. this._bounds = null;
  34008. }
  34009. for (var i = 0, ii = this._textDivs.length; i < ii; i++) {
  34010. var div = this._textDivs[i];
  34011. var divProperties = this._textDivProperties.get(div);
  34012. if (divProperties.isWhitespace) {
  34013. continue;
  34014. }
  34015. if (expandDivs) {
  34016. var transform = '', padding = '';
  34017. if (divProperties.scale !== 1) {
  34018. transform = 'scaleX(' + divProperties.scale + ')';
  34019. }
  34020. if (divProperties.angle !== 0) {
  34021. transform = 'rotate(' + divProperties.angle + 'deg) ' + transform;
  34022. }
  34023. if (divProperties.paddingLeft !== 0) {
  34024. padding += ' padding-left: ' + divProperties.paddingLeft / divProperties.scale + 'px;';
  34025. transform += ' translateX(' + -divProperties.paddingLeft / divProperties.scale + 'px)';
  34026. }
  34027. if (divProperties.paddingTop !== 0) {
  34028. padding += ' padding-top: ' + divProperties.paddingTop + 'px;';
  34029. transform += ' translateY(' + -divProperties.paddingTop + 'px)';
  34030. }
  34031. if (divProperties.paddingRight !== 0) {
  34032. padding += ' padding-right: ' + divProperties.paddingRight / divProperties.scale + 'px;';
  34033. }
  34034. if (divProperties.paddingBottom !== 0) {
  34035. padding += ' padding-bottom: ' + divProperties.paddingBottom + 'px;';
  34036. }
  34037. if (padding !== '') {
  34038. div.setAttribute('style', divProperties.style + padding);
  34039. }
  34040. if (transform !== '') {
  34041. CustomStyle.setProp('transform', div, transform);
  34042. }
  34043. } else {
  34044. div.style.padding = 0;
  34045. CustomStyle.setProp('transform', div, divProperties.originalTransform || '');
  34046. }
  34047. }
  34048. }
  34049. };
  34050. /**
  34051. * Starts rendering of the text layer.
  34052. *
  34053. * @param {TextLayerRenderParameters} renderParameters
  34054. * @returns {TextLayerRenderTask}
  34055. */
  34056. function renderTextLayer(renderParameters) {
  34057. var task = new TextLayerRenderTask(renderParameters.textContent, renderParameters.container, renderParameters.viewport, renderParameters.textDivs, renderParameters.enhanceTextSelection);
  34058. task._render(renderParameters.timeout);
  34059. return task;
  34060. }
  34061. return renderTextLayer;
  34062. }();
  34063. exports.renderTextLayer = renderTextLayer;
  34064. }));
  34065. (function (root, factory) {
  34066. factory(root.pdfjsDisplayWebGL = {}, root.pdfjsSharedUtil, root.pdfjsDisplayDOMUtils);
  34067. }(this, function (exports, sharedUtil, displayDOMUtils) {
  34068. var shadow = sharedUtil.shadow;
  34069. var getDefaultSetting = displayDOMUtils.getDefaultSetting;
  34070. var WebGLUtils = function WebGLUtilsClosure() {
  34071. function loadShader(gl, code, shaderType) {
  34072. var shader = gl.createShader(shaderType);
  34073. gl.shaderSource(shader, code);
  34074. gl.compileShader(shader);
  34075. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  34076. if (!compiled) {
  34077. var errorMsg = gl.getShaderInfoLog(shader);
  34078. throw new Error('Error during shader compilation: ' + errorMsg);
  34079. }
  34080. return shader;
  34081. }
  34082. function createVertexShader(gl, code) {
  34083. return loadShader(gl, code, gl.VERTEX_SHADER);
  34084. }
  34085. function createFragmentShader(gl, code) {
  34086. return loadShader(gl, code, gl.FRAGMENT_SHADER);
  34087. }
  34088. function createProgram(gl, shaders) {
  34089. var program = gl.createProgram();
  34090. for (var i = 0, ii = shaders.length; i < ii; ++i) {
  34091. gl.attachShader(program, shaders[i]);
  34092. }
  34093. gl.linkProgram(program);
  34094. var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  34095. if (!linked) {
  34096. var errorMsg = gl.getProgramInfoLog(program);
  34097. throw new Error('Error during program linking: ' + errorMsg);
  34098. }
  34099. return program;
  34100. }
  34101. function createTexture(gl, image, textureId) {
  34102. gl.activeTexture(textureId);
  34103. var texture = gl.createTexture();
  34104. gl.bindTexture(gl.TEXTURE_2D, texture);
  34105. // Set the parameters so we can render any size image.
  34106. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  34107. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  34108. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  34109. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  34110. // Upload the image into the texture.
  34111. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  34112. return texture;
  34113. }
  34114. var currentGL, currentCanvas;
  34115. function generateGL() {
  34116. if (currentGL) {
  34117. return;
  34118. }
  34119. currentCanvas = document.createElement('canvas');
  34120. currentGL = currentCanvas.getContext('webgl', { premultipliedalpha: false });
  34121. }
  34122. var smaskVertexShaderCode = '\
  34123. attribute vec2 a_position; \
  34124. attribute vec2 a_texCoord; \
  34125. \
  34126. uniform vec2 u_resolution; \
  34127. \
  34128. varying vec2 v_texCoord; \
  34129. \
  34130. void main() { \
  34131. vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
  34132. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  34133. \
  34134. v_texCoord = a_texCoord; \
  34135. } ';
  34136. var smaskFragmentShaderCode = '\
  34137. precision mediump float; \
  34138. \
  34139. uniform vec4 u_backdrop; \
  34140. uniform int u_subtype; \
  34141. uniform sampler2D u_image; \
  34142. uniform sampler2D u_mask; \
  34143. \
  34144. varying vec2 v_texCoord; \
  34145. \
  34146. void main() { \
  34147. vec4 imageColor = texture2D(u_image, v_texCoord); \
  34148. vec4 maskColor = texture2D(u_mask, v_texCoord); \
  34149. if (u_backdrop.a > 0.0) { \
  34150. maskColor.rgb = maskColor.rgb * maskColor.a + \
  34151. u_backdrop.rgb * (1.0 - maskColor.a); \
  34152. } \
  34153. float lum; \
  34154. if (u_subtype == 0) { \
  34155. lum = maskColor.a; \
  34156. } else { \
  34157. lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
  34158. maskColor.b * 0.11; \
  34159. } \
  34160. imageColor.a *= lum; \
  34161. imageColor.rgb *= imageColor.a; \
  34162. gl_FragColor = imageColor; \
  34163. } ';
  34164. var smaskCache = null;
  34165. function initSmaskGL() {
  34166. var canvas, gl;
  34167. generateGL();
  34168. canvas = currentCanvas;
  34169. currentCanvas = null;
  34170. gl = currentGL;
  34171. currentGL = null;
  34172. // setup a GLSL program
  34173. var vertexShader = createVertexShader(gl, smaskVertexShaderCode);
  34174. var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
  34175. var program = createProgram(gl, [
  34176. vertexShader,
  34177. fragmentShader
  34178. ]);
  34179. gl.useProgram(program);
  34180. var cache = {};
  34181. cache.gl = gl;
  34182. cache.canvas = canvas;
  34183. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  34184. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  34185. cache.backdropLocation = gl.getUniformLocation(program, 'u_backdrop');
  34186. cache.subtypeLocation = gl.getUniformLocation(program, 'u_subtype');
  34187. var texCoordLocation = gl.getAttribLocation(program, 'a_texCoord');
  34188. var texLayerLocation = gl.getUniformLocation(program, 'u_image');
  34189. var texMaskLocation = gl.getUniformLocation(program, 'u_mask');
  34190. // provide texture coordinates for the rectangle.
  34191. var texCoordBuffer = gl.createBuffer();
  34192. gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
  34193. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  34194. 0.0,
  34195. 0.0,
  34196. 1.0,
  34197. 0.0,
  34198. 0.0,
  34199. 1.0,
  34200. 0.0,
  34201. 1.0,
  34202. 1.0,
  34203. 0.0,
  34204. 1.0,
  34205. 1.0
  34206. ]), gl.STATIC_DRAW);
  34207. gl.enableVertexAttribArray(texCoordLocation);
  34208. gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
  34209. gl.uniform1i(texLayerLocation, 0);
  34210. gl.uniform1i(texMaskLocation, 1);
  34211. smaskCache = cache;
  34212. }
  34213. function composeSMask(layer, mask, properties) {
  34214. var width = layer.width, height = layer.height;
  34215. if (!smaskCache) {
  34216. initSmaskGL();
  34217. }
  34218. var cache = smaskCache, canvas = cache.canvas, gl = cache.gl;
  34219. canvas.width = width;
  34220. canvas.height = height;
  34221. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  34222. gl.uniform2f(cache.resolutionLocation, width, height);
  34223. if (properties.backdrop) {
  34224. gl.uniform4f(cache.resolutionLocation, properties.backdrop[0], properties.backdrop[1], properties.backdrop[2], 1);
  34225. } else {
  34226. gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
  34227. }
  34228. gl.uniform1i(cache.subtypeLocation, properties.subtype === 'Luminosity' ? 1 : 0);
  34229. // Create a textures
  34230. var texture = createTexture(gl, layer, gl.TEXTURE0);
  34231. var maskTexture = createTexture(gl, mask, gl.TEXTURE1);
  34232. // Create a buffer and put a single clipspace rectangle in
  34233. // it (2 triangles)
  34234. var buffer = gl.createBuffer();
  34235. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  34236. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  34237. 0,
  34238. 0,
  34239. width,
  34240. 0,
  34241. 0,
  34242. height,
  34243. 0,
  34244. height,
  34245. width,
  34246. 0,
  34247. width,
  34248. height
  34249. ]), gl.STATIC_DRAW);
  34250. gl.enableVertexAttribArray(cache.positionLocation);
  34251. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  34252. // draw
  34253. gl.clearColor(0, 0, 0, 0);
  34254. gl.enable(gl.BLEND);
  34255. gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  34256. gl.clear(gl.COLOR_BUFFER_BIT);
  34257. gl.drawArrays(gl.TRIANGLES, 0, 6);
  34258. gl.flush();
  34259. gl.deleteTexture(texture);
  34260. gl.deleteTexture(maskTexture);
  34261. gl.deleteBuffer(buffer);
  34262. return canvas;
  34263. }
  34264. var figuresVertexShaderCode = '\
  34265. attribute vec2 a_position; \
  34266. attribute vec3 a_color; \
  34267. \
  34268. uniform vec2 u_resolution; \
  34269. uniform vec2 u_scale; \
  34270. uniform vec2 u_offset; \
  34271. \
  34272. varying vec4 v_color; \
  34273. \
  34274. void main() { \
  34275. vec2 position = (a_position + u_offset) * u_scale; \
  34276. vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
  34277. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  34278. \
  34279. v_color = vec4(a_color / 255.0, 1.0); \
  34280. } ';
  34281. var figuresFragmentShaderCode = '\
  34282. precision mediump float; \
  34283. \
  34284. varying vec4 v_color; \
  34285. \
  34286. void main() { \
  34287. gl_FragColor = v_color; \
  34288. } ';
  34289. var figuresCache = null;
  34290. function initFiguresGL() {
  34291. var canvas, gl;
  34292. generateGL();
  34293. canvas = currentCanvas;
  34294. currentCanvas = null;
  34295. gl = currentGL;
  34296. currentGL = null;
  34297. // setup a GLSL program
  34298. var vertexShader = createVertexShader(gl, figuresVertexShaderCode);
  34299. var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
  34300. var program = createProgram(gl, [
  34301. vertexShader,
  34302. fragmentShader
  34303. ]);
  34304. gl.useProgram(program);
  34305. var cache = {};
  34306. cache.gl = gl;
  34307. cache.canvas = canvas;
  34308. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  34309. cache.scaleLocation = gl.getUniformLocation(program, 'u_scale');
  34310. cache.offsetLocation = gl.getUniformLocation(program, 'u_offset');
  34311. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  34312. cache.colorLocation = gl.getAttribLocation(program, 'a_color');
  34313. figuresCache = cache;
  34314. }
  34315. function drawFigures(width, height, backgroundColor, figures, context) {
  34316. if (!figuresCache) {
  34317. initFiguresGL();
  34318. }
  34319. var cache = figuresCache, canvas = cache.canvas, gl = cache.gl;
  34320. canvas.width = width;
  34321. canvas.height = height;
  34322. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  34323. gl.uniform2f(cache.resolutionLocation, width, height);
  34324. // count triangle points
  34325. var count = 0;
  34326. var i, ii, rows;
  34327. for (i = 0, ii = figures.length; i < ii; i++) {
  34328. switch (figures[i].type) {
  34329. case 'lattice':
  34330. rows = figures[i].coords.length / figures[i].verticesPerRow | 0;
  34331. count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
  34332. break;
  34333. case 'triangles':
  34334. count += figures[i].coords.length;
  34335. break;
  34336. }
  34337. }
  34338. // transfer data
  34339. var coords = new Float32Array(count * 2);
  34340. var colors = new Uint8Array(count * 3);
  34341. var coordsMap = context.coords, colorsMap = context.colors;
  34342. var pIndex = 0, cIndex = 0;
  34343. for (i = 0, ii = figures.length; i < ii; i++) {
  34344. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  34345. switch (figure.type) {
  34346. case 'lattice':
  34347. var cols = figure.verticesPerRow;
  34348. rows = ps.length / cols | 0;
  34349. for (var row = 1; row < rows; row++) {
  34350. var offset = row * cols + 1;
  34351. for (var col = 1; col < cols; col++, offset++) {
  34352. coords[pIndex] = coordsMap[ps[offset - cols - 1]];
  34353. coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
  34354. coords[pIndex + 2] = coordsMap[ps[offset - cols]];
  34355. coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
  34356. coords[pIndex + 4] = coordsMap[ps[offset - 1]];
  34357. coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
  34358. colors[cIndex] = colorsMap[cs[offset - cols - 1]];
  34359. colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
  34360. colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
  34361. colors[cIndex + 3] = colorsMap[cs[offset - cols]];
  34362. colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
  34363. colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
  34364. colors[cIndex + 6] = colorsMap[cs[offset - 1]];
  34365. colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
  34366. colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
  34367. coords[pIndex + 6] = coords[pIndex + 2];
  34368. coords[pIndex + 7] = coords[pIndex + 3];
  34369. coords[pIndex + 8] = coords[pIndex + 4];
  34370. coords[pIndex + 9] = coords[pIndex + 5];
  34371. coords[pIndex + 10] = coordsMap[ps[offset]];
  34372. coords[pIndex + 11] = coordsMap[ps[offset] + 1];
  34373. colors[cIndex + 9] = colors[cIndex + 3];
  34374. colors[cIndex + 10] = colors[cIndex + 4];
  34375. colors[cIndex + 11] = colors[cIndex + 5];
  34376. colors[cIndex + 12] = colors[cIndex + 6];
  34377. colors[cIndex + 13] = colors[cIndex + 7];
  34378. colors[cIndex + 14] = colors[cIndex + 8];
  34379. colors[cIndex + 15] = colorsMap[cs[offset]];
  34380. colors[cIndex + 16] = colorsMap[cs[offset] + 1];
  34381. colors[cIndex + 17] = colorsMap[cs[offset] + 2];
  34382. pIndex += 12;
  34383. cIndex += 18;
  34384. }
  34385. }
  34386. break;
  34387. case 'triangles':
  34388. for (var j = 0, jj = ps.length; j < jj; j++) {
  34389. coords[pIndex] = coordsMap[ps[j]];
  34390. coords[pIndex + 1] = coordsMap[ps[j] + 1];
  34391. colors[cIndex] = colorsMap[cs[j]];
  34392. colors[cIndex + 1] = colorsMap[cs[j] + 1];
  34393. colors[cIndex + 2] = colorsMap[cs[j] + 2];
  34394. pIndex += 2;
  34395. cIndex += 3;
  34396. }
  34397. break;
  34398. }
  34399. }
  34400. // draw
  34401. if (backgroundColor) {
  34402. gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255, backgroundColor[2] / 255, 1.0);
  34403. } else {
  34404. gl.clearColor(0, 0, 0, 0);
  34405. }
  34406. gl.clear(gl.COLOR_BUFFER_BIT);
  34407. var coordsBuffer = gl.createBuffer();
  34408. gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
  34409. gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
  34410. gl.enableVertexAttribArray(cache.positionLocation);
  34411. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  34412. var colorsBuffer = gl.createBuffer();
  34413. gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
  34414. gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
  34415. gl.enableVertexAttribArray(cache.colorLocation);
  34416. gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false, 0, 0);
  34417. gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
  34418. gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
  34419. gl.drawArrays(gl.TRIANGLES, 0, count);
  34420. gl.flush();
  34421. gl.deleteBuffer(coordsBuffer);
  34422. gl.deleteBuffer(colorsBuffer);
  34423. return canvas;
  34424. }
  34425. function cleanup() {
  34426. if (smaskCache && smaskCache.canvas) {
  34427. smaskCache.canvas.width = 0;
  34428. smaskCache.canvas.height = 0;
  34429. }
  34430. if (figuresCache && figuresCache.canvas) {
  34431. figuresCache.canvas.width = 0;
  34432. figuresCache.canvas.height = 0;
  34433. }
  34434. smaskCache = null;
  34435. figuresCache = null;
  34436. }
  34437. return {
  34438. get isEnabled() {
  34439. if (getDefaultSetting('disableWebGL')) {
  34440. return false;
  34441. }
  34442. var enabled = false;
  34443. try {
  34444. generateGL();
  34445. enabled = !!currentGL;
  34446. } catch (e) {
  34447. }
  34448. return shadow(this, 'isEnabled', enabled);
  34449. },
  34450. composeSMask: composeSMask,
  34451. drawFigures: drawFigures,
  34452. clear: cleanup
  34453. };
  34454. }();
  34455. exports.WebGLUtils = WebGLUtils;
  34456. }));
  34457. (function (root, factory) {
  34458. factory(root.pdfjsCoreCrypto = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  34459. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  34460. var PasswordException = sharedUtil.PasswordException;
  34461. var PasswordResponses = sharedUtil.PasswordResponses;
  34462. var bytesToString = sharedUtil.bytesToString;
  34463. var warn = sharedUtil.warn;
  34464. var error = sharedUtil.error;
  34465. var assert = sharedUtil.assert;
  34466. var isInt = sharedUtil.isInt;
  34467. var stringToBytes = sharedUtil.stringToBytes;
  34468. var utf8StringToString = sharedUtil.utf8StringToString;
  34469. var Name = corePrimitives.Name;
  34470. var isName = corePrimitives.isName;
  34471. var isDict = corePrimitives.isDict;
  34472. var DecryptStream = coreStream.DecryptStream;
  34473. var ARCFourCipher = function ARCFourCipherClosure() {
  34474. function ARCFourCipher(key) {
  34475. this.a = 0;
  34476. this.b = 0;
  34477. var s = new Uint8Array(256);
  34478. var i, j = 0, tmp, keyLength = key.length;
  34479. for (i = 0; i < 256; ++i) {
  34480. s[i] = i;
  34481. }
  34482. for (i = 0; i < 256; ++i) {
  34483. tmp = s[i];
  34484. j = j + tmp + key[i % keyLength] & 0xFF;
  34485. s[i] = s[j];
  34486. s[j] = tmp;
  34487. }
  34488. this.s = s;
  34489. }
  34490. ARCFourCipher.prototype = {
  34491. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  34492. var i, n = data.length, tmp, tmp2;
  34493. var a = this.a, b = this.b, s = this.s;
  34494. var output = new Uint8Array(n);
  34495. for (i = 0; i < n; ++i) {
  34496. a = a + 1 & 0xFF;
  34497. tmp = s[a];
  34498. b = b + tmp & 0xFF;
  34499. tmp2 = s[b];
  34500. s[a] = tmp2;
  34501. s[b] = tmp;
  34502. output[i] = data[i] ^ s[tmp + tmp2 & 0xFF];
  34503. }
  34504. this.a = a;
  34505. this.b = b;
  34506. return output;
  34507. }
  34508. };
  34509. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  34510. return ARCFourCipher;
  34511. }();
  34512. var calculateMD5 = function calculateMD5Closure() {
  34513. var r = new Uint8Array([
  34514. 7,
  34515. 12,
  34516. 17,
  34517. 22,
  34518. 7,
  34519. 12,
  34520. 17,
  34521. 22,
  34522. 7,
  34523. 12,
  34524. 17,
  34525. 22,
  34526. 7,
  34527. 12,
  34528. 17,
  34529. 22,
  34530. 5,
  34531. 9,
  34532. 14,
  34533. 20,
  34534. 5,
  34535. 9,
  34536. 14,
  34537. 20,
  34538. 5,
  34539. 9,
  34540. 14,
  34541. 20,
  34542. 5,
  34543. 9,
  34544. 14,
  34545. 20,
  34546. 4,
  34547. 11,
  34548. 16,
  34549. 23,
  34550. 4,
  34551. 11,
  34552. 16,
  34553. 23,
  34554. 4,
  34555. 11,
  34556. 16,
  34557. 23,
  34558. 4,
  34559. 11,
  34560. 16,
  34561. 23,
  34562. 6,
  34563. 10,
  34564. 15,
  34565. 21,
  34566. 6,
  34567. 10,
  34568. 15,
  34569. 21,
  34570. 6,
  34571. 10,
  34572. 15,
  34573. 21,
  34574. 6,
  34575. 10,
  34576. 15,
  34577. 21
  34578. ]);
  34579. var k = new Int32Array([
  34580. -680876936,
  34581. -389564586,
  34582. 606105819,
  34583. -1044525330,
  34584. -176418897,
  34585. 1200080426,
  34586. -1473231341,
  34587. -45705983,
  34588. 1770035416,
  34589. -1958414417,
  34590. -42063,
  34591. -1990404162,
  34592. 1804603682,
  34593. -40341101,
  34594. -1502002290,
  34595. 1236535329,
  34596. -165796510,
  34597. -1069501632,
  34598. 643717713,
  34599. -373897302,
  34600. -701558691,
  34601. 38016083,
  34602. -660478335,
  34603. -405537848,
  34604. 568446438,
  34605. -1019803690,
  34606. -187363961,
  34607. 1163531501,
  34608. -1444681467,
  34609. -51403784,
  34610. 1735328473,
  34611. -1926607734,
  34612. -378558,
  34613. -2022574463,
  34614. 1839030562,
  34615. -35309556,
  34616. -1530992060,
  34617. 1272893353,
  34618. -155497632,
  34619. -1094730640,
  34620. 681279174,
  34621. -358537222,
  34622. -722521979,
  34623. 76029189,
  34624. -640364487,
  34625. -421815835,
  34626. 530742520,
  34627. -995338651,
  34628. -198630844,
  34629. 1126891415,
  34630. -1416354905,
  34631. -57434055,
  34632. 1700485571,
  34633. -1894986606,
  34634. -1051523,
  34635. -2054922799,
  34636. 1873313359,
  34637. -30611744,
  34638. -1560198380,
  34639. 1309151649,
  34640. -145523070,
  34641. -1120210379,
  34642. 718787259,
  34643. -343485551
  34644. ]);
  34645. function hash(data, offset, length) {
  34646. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  34647. // pre-processing
  34648. var paddedLength = length + 72 & ~63;
  34649. // data + 9 extra bytes
  34650. var padded = new Uint8Array(paddedLength);
  34651. var i, j, n;
  34652. for (i = 0; i < length; ++i) {
  34653. padded[i] = data[offset++];
  34654. }
  34655. padded[i++] = 0x80;
  34656. n = paddedLength - 8;
  34657. while (i < n) {
  34658. padded[i++] = 0;
  34659. }
  34660. padded[i++] = length << 3 & 0xFF;
  34661. padded[i++] = length >> 5 & 0xFF;
  34662. padded[i++] = length >> 13 & 0xFF;
  34663. padded[i++] = length >> 21 & 0xFF;
  34664. padded[i++] = length >>> 29 & 0xFF;
  34665. padded[i++] = 0;
  34666. padded[i++] = 0;
  34667. padded[i++] = 0;
  34668. var w = new Int32Array(16);
  34669. for (i = 0; i < paddedLength;) {
  34670. for (j = 0; j < 16; ++j, i += 4) {
  34671. w[j] = padded[i] | padded[i + 1] << 8 | padded[i + 2] << 16 | padded[i + 3] << 24;
  34672. }
  34673. var a = h0, b = h1, c = h2, d = h3, f, g;
  34674. for (j = 0; j < 64; ++j) {
  34675. if (j < 16) {
  34676. f = b & c | ~b & d;
  34677. g = j;
  34678. } else if (j < 32) {
  34679. f = d & b | ~d & c;
  34680. g = 5 * j + 1 & 15;
  34681. } else if (j < 48) {
  34682. f = b ^ c ^ d;
  34683. g = 3 * j + 5 & 15;
  34684. } else {
  34685. f = c ^ (b | ~d);
  34686. g = 7 * j & 15;
  34687. }
  34688. var tmp = d, rotateArg = a + f + k[j] + w[g] | 0, rotate = r[j];
  34689. d = c;
  34690. c = b;
  34691. b = b + (rotateArg << rotate | rotateArg >>> 32 - rotate) | 0;
  34692. a = tmp;
  34693. }
  34694. h0 = h0 + a | 0;
  34695. h1 = h1 + b | 0;
  34696. h2 = h2 + c | 0;
  34697. h3 = h3 + d | 0;
  34698. }
  34699. return new Uint8Array([
  34700. h0 & 0xFF,
  34701. h0 >> 8 & 0xFF,
  34702. h0 >> 16 & 0xFF,
  34703. h0 >>> 24 & 0xFF,
  34704. h1 & 0xFF,
  34705. h1 >> 8 & 0xFF,
  34706. h1 >> 16 & 0xFF,
  34707. h1 >>> 24 & 0xFF,
  34708. h2 & 0xFF,
  34709. h2 >> 8 & 0xFF,
  34710. h2 >> 16 & 0xFF,
  34711. h2 >>> 24 & 0xFF,
  34712. h3 & 0xFF,
  34713. h3 >> 8 & 0xFF,
  34714. h3 >> 16 & 0xFF,
  34715. h3 >>> 24 & 0xFF
  34716. ]);
  34717. }
  34718. return hash;
  34719. }();
  34720. var Word64 = function Word64Closure() {
  34721. function Word64(highInteger, lowInteger) {
  34722. this.high = highInteger | 0;
  34723. this.low = lowInteger | 0;
  34724. }
  34725. Word64.prototype = {
  34726. and: function Word64_and(word) {
  34727. this.high &= word.high;
  34728. this.low &= word.low;
  34729. },
  34730. xor: function Word64_xor(word) {
  34731. this.high ^= word.high;
  34732. this.low ^= word.low;
  34733. },
  34734. or: function Word64_or(word) {
  34735. this.high |= word.high;
  34736. this.low |= word.low;
  34737. },
  34738. shiftRight: function Word64_shiftRight(places) {
  34739. if (places >= 32) {
  34740. this.low = this.high >>> places - 32 | 0;
  34741. this.high = 0;
  34742. } else {
  34743. this.low = this.low >>> places | this.high << 32 - places;
  34744. this.high = this.high >>> places | 0;
  34745. }
  34746. },
  34747. shiftLeft: function Word64_shiftLeft(places) {
  34748. if (places >= 32) {
  34749. this.high = this.low << places - 32;
  34750. this.low = 0;
  34751. } else {
  34752. this.high = this.high << places | this.low >>> 32 - places;
  34753. this.low = this.low << places;
  34754. }
  34755. },
  34756. rotateRight: function Word64_rotateRight(places) {
  34757. var low, high;
  34758. if (places & 32) {
  34759. high = this.low;
  34760. low = this.high;
  34761. } else {
  34762. low = this.low;
  34763. high = this.high;
  34764. }
  34765. places &= 31;
  34766. this.low = low >>> places | high << 32 - places;
  34767. this.high = high >>> places | low << 32 - places;
  34768. },
  34769. not: function Word64_not() {
  34770. this.high = ~this.high;
  34771. this.low = ~this.low;
  34772. },
  34773. add: function Word64_add(word) {
  34774. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  34775. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  34776. if (lowAdd > 0xFFFFFFFF) {
  34777. highAdd += 1;
  34778. }
  34779. this.low = lowAdd | 0;
  34780. this.high = highAdd | 0;
  34781. },
  34782. copyTo: function Word64_copyTo(bytes, offset) {
  34783. bytes[offset] = this.high >>> 24 & 0xFF;
  34784. bytes[offset + 1] = this.high >> 16 & 0xFF;
  34785. bytes[offset + 2] = this.high >> 8 & 0xFF;
  34786. bytes[offset + 3] = this.high & 0xFF;
  34787. bytes[offset + 4] = this.low >>> 24 & 0xFF;
  34788. bytes[offset + 5] = this.low >> 16 & 0xFF;
  34789. bytes[offset + 6] = this.low >> 8 & 0xFF;
  34790. bytes[offset + 7] = this.low & 0xFF;
  34791. },
  34792. assign: function Word64_assign(word) {
  34793. this.high = word.high;
  34794. this.low = word.low;
  34795. }
  34796. };
  34797. return Word64;
  34798. }();
  34799. var calculateSHA256 = function calculateSHA256Closure() {
  34800. function rotr(x, n) {
  34801. return x >>> n | x << 32 - n;
  34802. }
  34803. function ch(x, y, z) {
  34804. return x & y ^ ~x & z;
  34805. }
  34806. function maj(x, y, z) {
  34807. return x & y ^ x & z ^ y & z;
  34808. }
  34809. function sigma(x) {
  34810. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  34811. }
  34812. function sigmaPrime(x) {
  34813. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  34814. }
  34815. function littleSigma(x) {
  34816. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  34817. }
  34818. function littleSigmaPrime(x) {
  34819. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  34820. }
  34821. var k = [
  34822. 0x428a2f98,
  34823. 0x71374491,
  34824. 0xb5c0fbcf,
  34825. 0xe9b5dba5,
  34826. 0x3956c25b,
  34827. 0x59f111f1,
  34828. 0x923f82a4,
  34829. 0xab1c5ed5,
  34830. 0xd807aa98,
  34831. 0x12835b01,
  34832. 0x243185be,
  34833. 0x550c7dc3,
  34834. 0x72be5d74,
  34835. 0x80deb1fe,
  34836. 0x9bdc06a7,
  34837. 0xc19bf174,
  34838. 0xe49b69c1,
  34839. 0xefbe4786,
  34840. 0x0fc19dc6,
  34841. 0x240ca1cc,
  34842. 0x2de92c6f,
  34843. 0x4a7484aa,
  34844. 0x5cb0a9dc,
  34845. 0x76f988da,
  34846. 0x983e5152,
  34847. 0xa831c66d,
  34848. 0xb00327c8,
  34849. 0xbf597fc7,
  34850. 0xc6e00bf3,
  34851. 0xd5a79147,
  34852. 0x06ca6351,
  34853. 0x14292967,
  34854. 0x27b70a85,
  34855. 0x2e1b2138,
  34856. 0x4d2c6dfc,
  34857. 0x53380d13,
  34858. 0x650a7354,
  34859. 0x766a0abb,
  34860. 0x81c2c92e,
  34861. 0x92722c85,
  34862. 0xa2bfe8a1,
  34863. 0xa81a664b,
  34864. 0xc24b8b70,
  34865. 0xc76c51a3,
  34866. 0xd192e819,
  34867. 0xd6990624,
  34868. 0xf40e3585,
  34869. 0x106aa070,
  34870. 0x19a4c116,
  34871. 0x1e376c08,
  34872. 0x2748774c,
  34873. 0x34b0bcb5,
  34874. 0x391c0cb3,
  34875. 0x4ed8aa4a,
  34876. 0x5b9cca4f,
  34877. 0x682e6ff3,
  34878. 0x748f82ee,
  34879. 0x78a5636f,
  34880. 0x84c87814,
  34881. 0x8cc70208,
  34882. 0x90befffa,
  34883. 0xa4506ceb,
  34884. 0xbef9a3f7,
  34885. 0xc67178f2
  34886. ];
  34887. function hash(data, offset, length) {
  34888. // initial hash values
  34889. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372, h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c, h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  34890. // pre-processing
  34891. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  34892. var padded = new Uint8Array(paddedLength);
  34893. var i, j, n;
  34894. for (i = 0; i < length; ++i) {
  34895. padded[i] = data[offset++];
  34896. }
  34897. padded[i++] = 0x80;
  34898. n = paddedLength - 8;
  34899. while (i < n) {
  34900. padded[i++] = 0;
  34901. }
  34902. padded[i++] = 0;
  34903. padded[i++] = 0;
  34904. padded[i++] = 0;
  34905. padded[i++] = length >>> 29 & 0xFF;
  34906. padded[i++] = length >> 21 & 0xFF;
  34907. padded[i++] = length >> 13 & 0xFF;
  34908. padded[i++] = length >> 5 & 0xFF;
  34909. padded[i++] = length << 3 & 0xFF;
  34910. var w = new Uint32Array(64);
  34911. // for each 512 bit block
  34912. for (i = 0; i < paddedLength;) {
  34913. for (j = 0; j < 16; ++j) {
  34914. w[j] = padded[i] << 24 | padded[i + 1] << 16 | padded[i + 2] << 8 | padded[i + 3];
  34915. i += 4;
  34916. }
  34917. for (j = 16; j < 64; ++j) {
  34918. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] + littleSigma(w[j - 15]) + w[j - 16] | 0;
  34919. }
  34920. var a = h0, b = h1, c = h2, d = h3, e = h4, f = h5, g = h6, h = h7, t1, t2;
  34921. for (j = 0; j < 64; ++j) {
  34922. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  34923. t2 = sigma(a) + maj(a, b, c);
  34924. h = g;
  34925. g = f;
  34926. f = e;
  34927. e = d + t1 | 0;
  34928. d = c;
  34929. c = b;
  34930. b = a;
  34931. a = t1 + t2 | 0;
  34932. }
  34933. h0 = h0 + a | 0;
  34934. h1 = h1 + b | 0;
  34935. h2 = h2 + c | 0;
  34936. h3 = h3 + d | 0;
  34937. h4 = h4 + e | 0;
  34938. h5 = h5 + f | 0;
  34939. h6 = h6 + g | 0;
  34940. h7 = h7 + h | 0;
  34941. }
  34942. return new Uint8Array([
  34943. h0 >> 24 & 0xFF,
  34944. h0 >> 16 & 0xFF,
  34945. h0 >> 8 & 0xFF,
  34946. h0 & 0xFF,
  34947. h1 >> 24 & 0xFF,
  34948. h1 >> 16 & 0xFF,
  34949. h1 >> 8 & 0xFF,
  34950. h1 & 0xFF,
  34951. h2 >> 24 & 0xFF,
  34952. h2 >> 16 & 0xFF,
  34953. h2 >> 8 & 0xFF,
  34954. h2 & 0xFF,
  34955. h3 >> 24 & 0xFF,
  34956. h3 >> 16 & 0xFF,
  34957. h3 >> 8 & 0xFF,
  34958. h3 & 0xFF,
  34959. h4 >> 24 & 0xFF,
  34960. h4 >> 16 & 0xFF,
  34961. h4 >> 8 & 0xFF,
  34962. h4 & 0xFF,
  34963. h5 >> 24 & 0xFF,
  34964. h5 >> 16 & 0xFF,
  34965. h5 >> 8 & 0xFF,
  34966. h5 & 0xFF,
  34967. h6 >> 24 & 0xFF,
  34968. h6 >> 16 & 0xFF,
  34969. h6 >> 8 & 0xFF,
  34970. h6 & 0xFF,
  34971. h7 >> 24 & 0xFF,
  34972. h7 >> 16 & 0xFF,
  34973. h7 >> 8 & 0xFF,
  34974. h7 & 0xFF
  34975. ]);
  34976. }
  34977. return hash;
  34978. }();
  34979. var calculateSHA512 = function calculateSHA512Closure() {
  34980. function ch(result, x, y, z, tmp) {
  34981. result.assign(x);
  34982. result.and(y);
  34983. tmp.assign(x);
  34984. tmp.not();
  34985. tmp.and(z);
  34986. result.xor(tmp);
  34987. }
  34988. function maj(result, x, y, z, tmp) {
  34989. result.assign(x);
  34990. result.and(y);
  34991. tmp.assign(x);
  34992. tmp.and(z);
  34993. result.xor(tmp);
  34994. tmp.assign(y);
  34995. tmp.and(z);
  34996. result.xor(tmp);
  34997. }
  34998. function sigma(result, x, tmp) {
  34999. result.assign(x);
  35000. result.rotateRight(28);
  35001. tmp.assign(x);
  35002. tmp.rotateRight(34);
  35003. result.xor(tmp);
  35004. tmp.assign(x);
  35005. tmp.rotateRight(39);
  35006. result.xor(tmp);
  35007. }
  35008. function sigmaPrime(result, x, tmp) {
  35009. result.assign(x);
  35010. result.rotateRight(14);
  35011. tmp.assign(x);
  35012. tmp.rotateRight(18);
  35013. result.xor(tmp);
  35014. tmp.assign(x);
  35015. tmp.rotateRight(41);
  35016. result.xor(tmp);
  35017. }
  35018. function littleSigma(result, x, tmp) {
  35019. result.assign(x);
  35020. result.rotateRight(1);
  35021. tmp.assign(x);
  35022. tmp.rotateRight(8);
  35023. result.xor(tmp);
  35024. tmp.assign(x);
  35025. tmp.shiftRight(7);
  35026. result.xor(tmp);
  35027. }
  35028. function littleSigmaPrime(result, x, tmp) {
  35029. result.assign(x);
  35030. result.rotateRight(19);
  35031. tmp.assign(x);
  35032. tmp.rotateRight(61);
  35033. result.xor(tmp);
  35034. tmp.assign(x);
  35035. tmp.shiftRight(6);
  35036. result.xor(tmp);
  35037. }
  35038. var k = [
  35039. new Word64(0x428a2f98, 0xd728ae22),
  35040. new Word64(0x71374491, 0x23ef65cd),
  35041. new Word64(0xb5c0fbcf, 0xec4d3b2f),
  35042. new Word64(0xe9b5dba5, 0x8189dbbc),
  35043. new Word64(0x3956c25b, 0xf348b538),
  35044. new Word64(0x59f111f1, 0xb605d019),
  35045. new Word64(0x923f82a4, 0xaf194f9b),
  35046. new Word64(0xab1c5ed5, 0xda6d8118),
  35047. new Word64(0xd807aa98, 0xa3030242),
  35048. new Word64(0x12835b01, 0x45706fbe),
  35049. new Word64(0x243185be, 0x4ee4b28c),
  35050. new Word64(0x550c7dc3, 0xd5ffb4e2),
  35051. new Word64(0x72be5d74, 0xf27b896f),
  35052. new Word64(0x80deb1fe, 0x3b1696b1),
  35053. new Word64(0x9bdc06a7, 0x25c71235),
  35054. new Word64(0xc19bf174, 0xcf692694),
  35055. new Word64(0xe49b69c1, 0x9ef14ad2),
  35056. new Word64(0xefbe4786, 0x384f25e3),
  35057. new Word64(0x0fc19dc6, 0x8b8cd5b5),
  35058. new Word64(0x240ca1cc, 0x77ac9c65),
  35059. new Word64(0x2de92c6f, 0x592b0275),
  35060. new Word64(0x4a7484aa, 0x6ea6e483),
  35061. new Word64(0x5cb0a9dc, 0xbd41fbd4),
  35062. new Word64(0x76f988da, 0x831153b5),
  35063. new Word64(0x983e5152, 0xee66dfab),
  35064. new Word64(0xa831c66d, 0x2db43210),
  35065. new Word64(0xb00327c8, 0x98fb213f),
  35066. new Word64(0xbf597fc7, 0xbeef0ee4),
  35067. new Word64(0xc6e00bf3, 0x3da88fc2),
  35068. new Word64(0xd5a79147, 0x930aa725),
  35069. new Word64(0x06ca6351, 0xe003826f),
  35070. new Word64(0x14292967, 0x0a0e6e70),
  35071. new Word64(0x27b70a85, 0x46d22ffc),
  35072. new Word64(0x2e1b2138, 0x5c26c926),
  35073. new Word64(0x4d2c6dfc, 0x5ac42aed),
  35074. new Word64(0x53380d13, 0x9d95b3df),
  35075. new Word64(0x650a7354, 0x8baf63de),
  35076. new Word64(0x766a0abb, 0x3c77b2a8),
  35077. new Word64(0x81c2c92e, 0x47edaee6),
  35078. new Word64(0x92722c85, 0x1482353b),
  35079. new Word64(0xa2bfe8a1, 0x4cf10364),
  35080. new Word64(0xa81a664b, 0xbc423001),
  35081. new Word64(0xc24b8b70, 0xd0f89791),
  35082. new Word64(0xc76c51a3, 0x0654be30),
  35083. new Word64(0xd192e819, 0xd6ef5218),
  35084. new Word64(0xd6990624, 0x5565a910),
  35085. new Word64(0xf40e3585, 0x5771202a),
  35086. new Word64(0x106aa070, 0x32bbd1b8),
  35087. new Word64(0x19a4c116, 0xb8d2d0c8),
  35088. new Word64(0x1e376c08, 0x5141ab53),
  35089. new Word64(0x2748774c, 0xdf8eeb99),
  35090. new Word64(0x34b0bcb5, 0xe19b48a8),
  35091. new Word64(0x391c0cb3, 0xc5c95a63),
  35092. new Word64(0x4ed8aa4a, 0xe3418acb),
  35093. new Word64(0x5b9cca4f, 0x7763e373),
  35094. new Word64(0x682e6ff3, 0xd6b2b8a3),
  35095. new Word64(0x748f82ee, 0x5defb2fc),
  35096. new Word64(0x78a5636f, 0x43172f60),
  35097. new Word64(0x84c87814, 0xa1f0ab72),
  35098. new Word64(0x8cc70208, 0x1a6439ec),
  35099. new Word64(0x90befffa, 0x23631e28),
  35100. new Word64(0xa4506ceb, 0xde82bde9),
  35101. new Word64(0xbef9a3f7, 0xb2c67915),
  35102. new Word64(0xc67178f2, 0xe372532b),
  35103. new Word64(0xca273ece, 0xea26619c),
  35104. new Word64(0xd186b8c7, 0x21c0c207),
  35105. new Word64(0xeada7dd6, 0xcde0eb1e),
  35106. new Word64(0xf57d4f7f, 0xee6ed178),
  35107. new Word64(0x06f067aa, 0x72176fba),
  35108. new Word64(0x0a637dc5, 0xa2c898a6),
  35109. new Word64(0x113f9804, 0xbef90dae),
  35110. new Word64(0x1b710b35, 0x131c471b),
  35111. new Word64(0x28db77f5, 0x23047d84),
  35112. new Word64(0x32caab7b, 0x40c72493),
  35113. new Word64(0x3c9ebe0a, 0x15c9bebc),
  35114. new Word64(0x431d67c4, 0x9c100d4c),
  35115. new Word64(0x4cc5d4be, 0xcb3e42b6),
  35116. new Word64(0x597f299c, 0xfc657e2a),
  35117. new Word64(0x5fcb6fab, 0x3ad6faec),
  35118. new Word64(0x6c44198c, 0x4a475817)
  35119. ];
  35120. function hash(data, offset, length, mode384) {
  35121. mode384 = !!mode384;
  35122. // initial hash values
  35123. var h0, h1, h2, h3, h4, h5, h6, h7;
  35124. if (!mode384) {
  35125. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  35126. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  35127. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  35128. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  35129. h4 = new Word64(0x510e527f, 0xade682d1);
  35130. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  35131. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  35132. h7 = new Word64(0x5be0cd19, 0x137e2179);
  35133. } else {
  35134. // SHA384 is exactly the same
  35135. // except with different starting values and a trimmed result
  35136. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  35137. h1 = new Word64(0x629a292a, 0x367cd507);
  35138. h2 = new Word64(0x9159015a, 0x3070dd17);
  35139. h3 = new Word64(0x152fecd8, 0xf70e5939);
  35140. h4 = new Word64(0x67332667, 0xffc00b31);
  35141. h5 = new Word64(0x8eb44a87, 0x68581511);
  35142. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  35143. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  35144. }
  35145. // pre-processing
  35146. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  35147. var padded = new Uint8Array(paddedLength);
  35148. var i, j, n;
  35149. for (i = 0; i < length; ++i) {
  35150. padded[i] = data[offset++];
  35151. }
  35152. padded[i++] = 0x80;
  35153. n = paddedLength - 16;
  35154. while (i < n) {
  35155. padded[i++] = 0;
  35156. }
  35157. padded[i++] = 0;
  35158. padded[i++] = 0;
  35159. padded[i++] = 0;
  35160. padded[i++] = 0;
  35161. padded[i++] = 0;
  35162. padded[i++] = 0;
  35163. padded[i++] = 0;
  35164. padded[i++] = 0;
  35165. padded[i++] = 0;
  35166. padded[i++] = 0;
  35167. padded[i++] = 0;
  35168. padded[i++] = length >>> 29 & 0xFF;
  35169. padded[i++] = length >> 21 & 0xFF;
  35170. padded[i++] = length >> 13 & 0xFF;
  35171. padded[i++] = length >> 5 & 0xFF;
  35172. padded[i++] = length << 3 & 0xFF;
  35173. var w = new Array(80);
  35174. for (i = 0; i < 80; i++) {
  35175. w[i] = new Word64(0, 0);
  35176. }
  35177. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  35178. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  35179. var g = new Word64(0, 0), h = new Word64(0, 0);
  35180. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  35181. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  35182. // for each 1024 bit block
  35183. for (i = 0; i < paddedLength;) {
  35184. for (j = 0; j < 16; ++j) {
  35185. w[j].high = padded[i] << 24 | padded[i + 1] << 16 | padded[i + 2] << 8 | padded[i + 3];
  35186. w[j].low = padded[i + 4] << 24 | padded[i + 5] << 16 | padded[i + 6] << 8 | padded[i + 7];
  35187. i += 8;
  35188. }
  35189. for (j = 16; j < 80; ++j) {
  35190. tmp3 = w[j];
  35191. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  35192. tmp3.add(w[j - 7]);
  35193. littleSigma(tmp1, w[j - 15], tmp2);
  35194. tmp3.add(tmp1);
  35195. tmp3.add(w[j - 16]);
  35196. }
  35197. a.assign(h0);
  35198. b.assign(h1);
  35199. c.assign(h2);
  35200. d.assign(h3);
  35201. e.assign(h4);
  35202. f.assign(h5);
  35203. g.assign(h6);
  35204. h.assign(h7);
  35205. for (j = 0; j < 80; ++j) {
  35206. t1.assign(h);
  35207. sigmaPrime(tmp1, e, tmp2);
  35208. t1.add(tmp1);
  35209. ch(tmp1, e, f, g, tmp2);
  35210. t1.add(tmp1);
  35211. t1.add(k[j]);
  35212. t1.add(w[j]);
  35213. sigma(t2, a, tmp2);
  35214. maj(tmp1, a, b, c, tmp2);
  35215. t2.add(tmp1);
  35216. tmp3 = h;
  35217. h = g;
  35218. g = f;
  35219. f = e;
  35220. d.add(t1);
  35221. e = d;
  35222. d = c;
  35223. c = b;
  35224. b = a;
  35225. tmp3.assign(t1);
  35226. tmp3.add(t2);
  35227. a = tmp3;
  35228. }
  35229. h0.add(a);
  35230. h1.add(b);
  35231. h2.add(c);
  35232. h3.add(d);
  35233. h4.add(e);
  35234. h5.add(f);
  35235. h6.add(g);
  35236. h7.add(h);
  35237. }
  35238. var result;
  35239. if (!mode384) {
  35240. result = new Uint8Array(64);
  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. h6.copyTo(result, 48);
  35248. h7.copyTo(result, 56);
  35249. } else {
  35250. result = new Uint8Array(48);
  35251. h0.copyTo(result, 0);
  35252. h1.copyTo(result, 8);
  35253. h2.copyTo(result, 16);
  35254. h3.copyTo(result, 24);
  35255. h4.copyTo(result, 32);
  35256. h5.copyTo(result, 40);
  35257. }
  35258. return result;
  35259. }
  35260. return hash;
  35261. }();
  35262. var calculateSHA384 = function calculateSHA384Closure() {
  35263. function hash(data, offset, length) {
  35264. return calculateSHA512(data, offset, length, true);
  35265. }
  35266. return hash;
  35267. }();
  35268. var NullCipher = function NullCipherClosure() {
  35269. function NullCipher() {
  35270. }
  35271. NullCipher.prototype = {
  35272. decryptBlock: function NullCipher_decryptBlock(data) {
  35273. return data;
  35274. }
  35275. };
  35276. return NullCipher;
  35277. }();
  35278. var AES128Cipher = function AES128CipherClosure() {
  35279. var rcon = new Uint8Array([
  35280. 0x8d,
  35281. 0x01,
  35282. 0x02,
  35283. 0x04,
  35284. 0x08,
  35285. 0x10,
  35286. 0x20,
  35287. 0x40,
  35288. 0x80,
  35289. 0x1b,
  35290. 0x36,
  35291. 0x6c,
  35292. 0xd8,
  35293. 0xab,
  35294. 0x4d,
  35295. 0x9a,
  35296. 0x2f,
  35297. 0x5e,
  35298. 0xbc,
  35299. 0x63,
  35300. 0xc6,
  35301. 0x97,
  35302. 0x35,
  35303. 0x6a,
  35304. 0xd4,
  35305. 0xb3,
  35306. 0x7d,
  35307. 0xfa,
  35308. 0xef,
  35309. 0xc5,
  35310. 0x91,
  35311. 0x39,
  35312. 0x72,
  35313. 0xe4,
  35314. 0xd3,
  35315. 0xbd,
  35316. 0x61,
  35317. 0xc2,
  35318. 0x9f,
  35319. 0x25,
  35320. 0x4a,
  35321. 0x94,
  35322. 0x33,
  35323. 0x66,
  35324. 0xcc,
  35325. 0x83,
  35326. 0x1d,
  35327. 0x3a,
  35328. 0x74,
  35329. 0xe8,
  35330. 0xcb,
  35331. 0x8d,
  35332. 0x01,
  35333. 0x02,
  35334. 0x04,
  35335. 0x08,
  35336. 0x10,
  35337. 0x20,
  35338. 0x40,
  35339. 0x80,
  35340. 0x1b,
  35341. 0x36,
  35342. 0x6c,
  35343. 0xd8,
  35344. 0xab,
  35345. 0x4d,
  35346. 0x9a,
  35347. 0x2f,
  35348. 0x5e,
  35349. 0xbc,
  35350. 0x63,
  35351. 0xc6,
  35352. 0x97,
  35353. 0x35,
  35354. 0x6a,
  35355. 0xd4,
  35356. 0xb3,
  35357. 0x7d,
  35358. 0xfa,
  35359. 0xef,
  35360. 0xc5,
  35361. 0x91,
  35362. 0x39,
  35363. 0x72,
  35364. 0xe4,
  35365. 0xd3,
  35366. 0xbd,
  35367. 0x61,
  35368. 0xc2,
  35369. 0x9f,
  35370. 0x25,
  35371. 0x4a,
  35372. 0x94,
  35373. 0x33,
  35374. 0x66,
  35375. 0xcc,
  35376. 0x83,
  35377. 0x1d,
  35378. 0x3a,
  35379. 0x74,
  35380. 0xe8,
  35381. 0xcb,
  35382. 0x8d,
  35383. 0x01,
  35384. 0x02,
  35385. 0x04,
  35386. 0x08,
  35387. 0x10,
  35388. 0x20,
  35389. 0x40,
  35390. 0x80,
  35391. 0x1b,
  35392. 0x36,
  35393. 0x6c,
  35394. 0xd8,
  35395. 0xab,
  35396. 0x4d,
  35397. 0x9a,
  35398. 0x2f,
  35399. 0x5e,
  35400. 0xbc,
  35401. 0x63,
  35402. 0xc6,
  35403. 0x97,
  35404. 0x35,
  35405. 0x6a,
  35406. 0xd4,
  35407. 0xb3,
  35408. 0x7d,
  35409. 0xfa,
  35410. 0xef,
  35411. 0xc5,
  35412. 0x91,
  35413. 0x39,
  35414. 0x72,
  35415. 0xe4,
  35416. 0xd3,
  35417. 0xbd,
  35418. 0x61,
  35419. 0xc2,
  35420. 0x9f,
  35421. 0x25,
  35422. 0x4a,
  35423. 0x94,
  35424. 0x33,
  35425. 0x66,
  35426. 0xcc,
  35427. 0x83,
  35428. 0x1d,
  35429. 0x3a,
  35430. 0x74,
  35431. 0xe8,
  35432. 0xcb,
  35433. 0x8d,
  35434. 0x01,
  35435. 0x02,
  35436. 0x04,
  35437. 0x08,
  35438. 0x10,
  35439. 0x20,
  35440. 0x40,
  35441. 0x80,
  35442. 0x1b,
  35443. 0x36,
  35444. 0x6c,
  35445. 0xd8,
  35446. 0xab,
  35447. 0x4d,
  35448. 0x9a,
  35449. 0x2f,
  35450. 0x5e,
  35451. 0xbc,
  35452. 0x63,
  35453. 0xc6,
  35454. 0x97,
  35455. 0x35,
  35456. 0x6a,
  35457. 0xd4,
  35458. 0xb3,
  35459. 0x7d,
  35460. 0xfa,
  35461. 0xef,
  35462. 0xc5,
  35463. 0x91,
  35464. 0x39,
  35465. 0x72,
  35466. 0xe4,
  35467. 0xd3,
  35468. 0xbd,
  35469. 0x61,
  35470. 0xc2,
  35471. 0x9f,
  35472. 0x25,
  35473. 0x4a,
  35474. 0x94,
  35475. 0x33,
  35476. 0x66,
  35477. 0xcc,
  35478. 0x83,
  35479. 0x1d,
  35480. 0x3a,
  35481. 0x74,
  35482. 0xe8,
  35483. 0xcb,
  35484. 0x8d,
  35485. 0x01,
  35486. 0x02,
  35487. 0x04,
  35488. 0x08,
  35489. 0x10,
  35490. 0x20,
  35491. 0x40,
  35492. 0x80,
  35493. 0x1b,
  35494. 0x36,
  35495. 0x6c,
  35496. 0xd8,
  35497. 0xab,
  35498. 0x4d,
  35499. 0x9a,
  35500. 0x2f,
  35501. 0x5e,
  35502. 0xbc,
  35503. 0x63,
  35504. 0xc6,
  35505. 0x97,
  35506. 0x35,
  35507. 0x6a,
  35508. 0xd4,
  35509. 0xb3,
  35510. 0x7d,
  35511. 0xfa,
  35512. 0xef,
  35513. 0xc5,
  35514. 0x91,
  35515. 0x39,
  35516. 0x72,
  35517. 0xe4,
  35518. 0xd3,
  35519. 0xbd,
  35520. 0x61,
  35521. 0xc2,
  35522. 0x9f,
  35523. 0x25,
  35524. 0x4a,
  35525. 0x94,
  35526. 0x33,
  35527. 0x66,
  35528. 0xcc,
  35529. 0x83,
  35530. 0x1d,
  35531. 0x3a,
  35532. 0x74,
  35533. 0xe8,
  35534. 0xcb,
  35535. 0x8d
  35536. ]);
  35537. var s = new Uint8Array([
  35538. 0x63,
  35539. 0x7c,
  35540. 0x77,
  35541. 0x7b,
  35542. 0xf2,
  35543. 0x6b,
  35544. 0x6f,
  35545. 0xc5,
  35546. 0x30,
  35547. 0x01,
  35548. 0x67,
  35549. 0x2b,
  35550. 0xfe,
  35551. 0xd7,
  35552. 0xab,
  35553. 0x76,
  35554. 0xca,
  35555. 0x82,
  35556. 0xc9,
  35557. 0x7d,
  35558. 0xfa,
  35559. 0x59,
  35560. 0x47,
  35561. 0xf0,
  35562. 0xad,
  35563. 0xd4,
  35564. 0xa2,
  35565. 0xaf,
  35566. 0x9c,
  35567. 0xa4,
  35568. 0x72,
  35569. 0xc0,
  35570. 0xb7,
  35571. 0xfd,
  35572. 0x93,
  35573. 0x26,
  35574. 0x36,
  35575. 0x3f,
  35576. 0xf7,
  35577. 0xcc,
  35578. 0x34,
  35579. 0xa5,
  35580. 0xe5,
  35581. 0xf1,
  35582. 0x71,
  35583. 0xd8,
  35584. 0x31,
  35585. 0x15,
  35586. 0x04,
  35587. 0xc7,
  35588. 0x23,
  35589. 0xc3,
  35590. 0x18,
  35591. 0x96,
  35592. 0x05,
  35593. 0x9a,
  35594. 0x07,
  35595. 0x12,
  35596. 0x80,
  35597. 0xe2,
  35598. 0xeb,
  35599. 0x27,
  35600. 0xb2,
  35601. 0x75,
  35602. 0x09,
  35603. 0x83,
  35604. 0x2c,
  35605. 0x1a,
  35606. 0x1b,
  35607. 0x6e,
  35608. 0x5a,
  35609. 0xa0,
  35610. 0x52,
  35611. 0x3b,
  35612. 0xd6,
  35613. 0xb3,
  35614. 0x29,
  35615. 0xe3,
  35616. 0x2f,
  35617. 0x84,
  35618. 0x53,
  35619. 0xd1,
  35620. 0x00,
  35621. 0xed,
  35622. 0x20,
  35623. 0xfc,
  35624. 0xb1,
  35625. 0x5b,
  35626. 0x6a,
  35627. 0xcb,
  35628. 0xbe,
  35629. 0x39,
  35630. 0x4a,
  35631. 0x4c,
  35632. 0x58,
  35633. 0xcf,
  35634. 0xd0,
  35635. 0xef,
  35636. 0xaa,
  35637. 0xfb,
  35638. 0x43,
  35639. 0x4d,
  35640. 0x33,
  35641. 0x85,
  35642. 0x45,
  35643. 0xf9,
  35644. 0x02,
  35645. 0x7f,
  35646. 0x50,
  35647. 0x3c,
  35648. 0x9f,
  35649. 0xa8,
  35650. 0x51,
  35651. 0xa3,
  35652. 0x40,
  35653. 0x8f,
  35654. 0x92,
  35655. 0x9d,
  35656. 0x38,
  35657. 0xf5,
  35658. 0xbc,
  35659. 0xb6,
  35660. 0xda,
  35661. 0x21,
  35662. 0x10,
  35663. 0xff,
  35664. 0xf3,
  35665. 0xd2,
  35666. 0xcd,
  35667. 0x0c,
  35668. 0x13,
  35669. 0xec,
  35670. 0x5f,
  35671. 0x97,
  35672. 0x44,
  35673. 0x17,
  35674. 0xc4,
  35675. 0xa7,
  35676. 0x7e,
  35677. 0x3d,
  35678. 0x64,
  35679. 0x5d,
  35680. 0x19,
  35681. 0x73,
  35682. 0x60,
  35683. 0x81,
  35684. 0x4f,
  35685. 0xdc,
  35686. 0x22,
  35687. 0x2a,
  35688. 0x90,
  35689. 0x88,
  35690. 0x46,
  35691. 0xee,
  35692. 0xb8,
  35693. 0x14,
  35694. 0xde,
  35695. 0x5e,
  35696. 0x0b,
  35697. 0xdb,
  35698. 0xe0,
  35699. 0x32,
  35700. 0x3a,
  35701. 0x0a,
  35702. 0x49,
  35703. 0x06,
  35704. 0x24,
  35705. 0x5c,
  35706. 0xc2,
  35707. 0xd3,
  35708. 0xac,
  35709. 0x62,
  35710. 0x91,
  35711. 0x95,
  35712. 0xe4,
  35713. 0x79,
  35714. 0xe7,
  35715. 0xc8,
  35716. 0x37,
  35717. 0x6d,
  35718. 0x8d,
  35719. 0xd5,
  35720. 0x4e,
  35721. 0xa9,
  35722. 0x6c,
  35723. 0x56,
  35724. 0xf4,
  35725. 0xea,
  35726. 0x65,
  35727. 0x7a,
  35728. 0xae,
  35729. 0x08,
  35730. 0xba,
  35731. 0x78,
  35732. 0x25,
  35733. 0x2e,
  35734. 0x1c,
  35735. 0xa6,
  35736. 0xb4,
  35737. 0xc6,
  35738. 0xe8,
  35739. 0xdd,
  35740. 0x74,
  35741. 0x1f,
  35742. 0x4b,
  35743. 0xbd,
  35744. 0x8b,
  35745. 0x8a,
  35746. 0x70,
  35747. 0x3e,
  35748. 0xb5,
  35749. 0x66,
  35750. 0x48,
  35751. 0x03,
  35752. 0xf6,
  35753. 0x0e,
  35754. 0x61,
  35755. 0x35,
  35756. 0x57,
  35757. 0xb9,
  35758. 0x86,
  35759. 0xc1,
  35760. 0x1d,
  35761. 0x9e,
  35762. 0xe1,
  35763. 0xf8,
  35764. 0x98,
  35765. 0x11,
  35766. 0x69,
  35767. 0xd9,
  35768. 0x8e,
  35769. 0x94,
  35770. 0x9b,
  35771. 0x1e,
  35772. 0x87,
  35773. 0xe9,
  35774. 0xce,
  35775. 0x55,
  35776. 0x28,
  35777. 0xdf,
  35778. 0x8c,
  35779. 0xa1,
  35780. 0x89,
  35781. 0x0d,
  35782. 0xbf,
  35783. 0xe6,
  35784. 0x42,
  35785. 0x68,
  35786. 0x41,
  35787. 0x99,
  35788. 0x2d,
  35789. 0x0f,
  35790. 0xb0,
  35791. 0x54,
  35792. 0xbb,
  35793. 0x16
  35794. ]);
  35795. var inv_s = new Uint8Array([
  35796. 0x52,
  35797. 0x09,
  35798. 0x6a,
  35799. 0xd5,
  35800. 0x30,
  35801. 0x36,
  35802. 0xa5,
  35803. 0x38,
  35804. 0xbf,
  35805. 0x40,
  35806. 0xa3,
  35807. 0x9e,
  35808. 0x81,
  35809. 0xf3,
  35810. 0xd7,
  35811. 0xfb,
  35812. 0x7c,
  35813. 0xe3,
  35814. 0x39,
  35815. 0x82,
  35816. 0x9b,
  35817. 0x2f,
  35818. 0xff,
  35819. 0x87,
  35820. 0x34,
  35821. 0x8e,
  35822. 0x43,
  35823. 0x44,
  35824. 0xc4,
  35825. 0xde,
  35826. 0xe9,
  35827. 0xcb,
  35828. 0x54,
  35829. 0x7b,
  35830. 0x94,
  35831. 0x32,
  35832. 0xa6,
  35833. 0xc2,
  35834. 0x23,
  35835. 0x3d,
  35836. 0xee,
  35837. 0x4c,
  35838. 0x95,
  35839. 0x0b,
  35840. 0x42,
  35841. 0xfa,
  35842. 0xc3,
  35843. 0x4e,
  35844. 0x08,
  35845. 0x2e,
  35846. 0xa1,
  35847. 0x66,
  35848. 0x28,
  35849. 0xd9,
  35850. 0x24,
  35851. 0xb2,
  35852. 0x76,
  35853. 0x5b,
  35854. 0xa2,
  35855. 0x49,
  35856. 0x6d,
  35857. 0x8b,
  35858. 0xd1,
  35859. 0x25,
  35860. 0x72,
  35861. 0xf8,
  35862. 0xf6,
  35863. 0x64,
  35864. 0x86,
  35865. 0x68,
  35866. 0x98,
  35867. 0x16,
  35868. 0xd4,
  35869. 0xa4,
  35870. 0x5c,
  35871. 0xcc,
  35872. 0x5d,
  35873. 0x65,
  35874. 0xb6,
  35875. 0x92,
  35876. 0x6c,
  35877. 0x70,
  35878. 0x48,
  35879. 0x50,
  35880. 0xfd,
  35881. 0xed,
  35882. 0xb9,
  35883. 0xda,
  35884. 0x5e,
  35885. 0x15,
  35886. 0x46,
  35887. 0x57,
  35888. 0xa7,
  35889. 0x8d,
  35890. 0x9d,
  35891. 0x84,
  35892. 0x90,
  35893. 0xd8,
  35894. 0xab,
  35895. 0x00,
  35896. 0x8c,
  35897. 0xbc,
  35898. 0xd3,
  35899. 0x0a,
  35900. 0xf7,
  35901. 0xe4,
  35902. 0x58,
  35903. 0x05,
  35904. 0xb8,
  35905. 0xb3,
  35906. 0x45,
  35907. 0x06,
  35908. 0xd0,
  35909. 0x2c,
  35910. 0x1e,
  35911. 0x8f,
  35912. 0xca,
  35913. 0x3f,
  35914. 0x0f,
  35915. 0x02,
  35916. 0xc1,
  35917. 0xaf,
  35918. 0xbd,
  35919. 0x03,
  35920. 0x01,
  35921. 0x13,
  35922. 0x8a,
  35923. 0x6b,
  35924. 0x3a,
  35925. 0x91,
  35926. 0x11,
  35927. 0x41,
  35928. 0x4f,
  35929. 0x67,
  35930. 0xdc,
  35931. 0xea,
  35932. 0x97,
  35933. 0xf2,
  35934. 0xcf,
  35935. 0xce,
  35936. 0xf0,
  35937. 0xb4,
  35938. 0xe6,
  35939. 0x73,
  35940. 0x96,
  35941. 0xac,
  35942. 0x74,
  35943. 0x22,
  35944. 0xe7,
  35945. 0xad,
  35946. 0x35,
  35947. 0x85,
  35948. 0xe2,
  35949. 0xf9,
  35950. 0x37,
  35951. 0xe8,
  35952. 0x1c,
  35953. 0x75,
  35954. 0xdf,
  35955. 0x6e,
  35956. 0x47,
  35957. 0xf1,
  35958. 0x1a,
  35959. 0x71,
  35960. 0x1d,
  35961. 0x29,
  35962. 0xc5,
  35963. 0x89,
  35964. 0x6f,
  35965. 0xb7,
  35966. 0x62,
  35967. 0x0e,
  35968. 0xaa,
  35969. 0x18,
  35970. 0xbe,
  35971. 0x1b,
  35972. 0xfc,
  35973. 0x56,
  35974. 0x3e,
  35975. 0x4b,
  35976. 0xc6,
  35977. 0xd2,
  35978. 0x79,
  35979. 0x20,
  35980. 0x9a,
  35981. 0xdb,
  35982. 0xc0,
  35983. 0xfe,
  35984. 0x78,
  35985. 0xcd,
  35986. 0x5a,
  35987. 0xf4,
  35988. 0x1f,
  35989. 0xdd,
  35990. 0xa8,
  35991. 0x33,
  35992. 0x88,
  35993. 0x07,
  35994. 0xc7,
  35995. 0x31,
  35996. 0xb1,
  35997. 0x12,
  35998. 0x10,
  35999. 0x59,
  36000. 0x27,
  36001. 0x80,
  36002. 0xec,
  36003. 0x5f,
  36004. 0x60,
  36005. 0x51,
  36006. 0x7f,
  36007. 0xa9,
  36008. 0x19,
  36009. 0xb5,
  36010. 0x4a,
  36011. 0x0d,
  36012. 0x2d,
  36013. 0xe5,
  36014. 0x7a,
  36015. 0x9f,
  36016. 0x93,
  36017. 0xc9,
  36018. 0x9c,
  36019. 0xef,
  36020. 0xa0,
  36021. 0xe0,
  36022. 0x3b,
  36023. 0x4d,
  36024. 0xae,
  36025. 0x2a,
  36026. 0xf5,
  36027. 0xb0,
  36028. 0xc8,
  36029. 0xeb,
  36030. 0xbb,
  36031. 0x3c,
  36032. 0x83,
  36033. 0x53,
  36034. 0x99,
  36035. 0x61,
  36036. 0x17,
  36037. 0x2b,
  36038. 0x04,
  36039. 0x7e,
  36040. 0xba,
  36041. 0x77,
  36042. 0xd6,
  36043. 0x26,
  36044. 0xe1,
  36045. 0x69,
  36046. 0x14,
  36047. 0x63,
  36048. 0x55,
  36049. 0x21,
  36050. 0x0c,
  36051. 0x7d
  36052. ]);
  36053. var mixCol = new Uint8Array(256);
  36054. for (var i = 0; i < 256; i++) {
  36055. if (i < 128) {
  36056. mixCol[i] = i << 1;
  36057. } else {
  36058. mixCol[i] = i << 1 ^ 0x1b;
  36059. }
  36060. }
  36061. var mix = new Uint32Array([
  36062. 0x00000000,
  36063. 0x0e090d0b,
  36064. 0x1c121a16,
  36065. 0x121b171d,
  36066. 0x3824342c,
  36067. 0x362d3927,
  36068. 0x24362e3a,
  36069. 0x2a3f2331,
  36070. 0x70486858,
  36071. 0x7e416553,
  36072. 0x6c5a724e,
  36073. 0x62537f45,
  36074. 0x486c5c74,
  36075. 0x4665517f,
  36076. 0x547e4662,
  36077. 0x5a774b69,
  36078. 0xe090d0b0,
  36079. 0xee99ddbb,
  36080. 0xfc82caa6,
  36081. 0xf28bc7ad,
  36082. 0xd8b4e49c,
  36083. 0xd6bde997,
  36084. 0xc4a6fe8a,
  36085. 0xcaaff381,
  36086. 0x90d8b8e8,
  36087. 0x9ed1b5e3,
  36088. 0x8ccaa2fe,
  36089. 0x82c3aff5,
  36090. 0xa8fc8cc4,
  36091. 0xa6f581cf,
  36092. 0xb4ee96d2,
  36093. 0xbae79bd9,
  36094. 0xdb3bbb7b,
  36095. 0xd532b670,
  36096. 0xc729a16d,
  36097. 0xc920ac66,
  36098. 0xe31f8f57,
  36099. 0xed16825c,
  36100. 0xff0d9541,
  36101. 0xf104984a,
  36102. 0xab73d323,
  36103. 0xa57ade28,
  36104. 0xb761c935,
  36105. 0xb968c43e,
  36106. 0x9357e70f,
  36107. 0x9d5eea04,
  36108. 0x8f45fd19,
  36109. 0x814cf012,
  36110. 0x3bab6bcb,
  36111. 0x35a266c0,
  36112. 0x27b971dd,
  36113. 0x29b07cd6,
  36114. 0x038f5fe7,
  36115. 0x0d8652ec,
  36116. 0x1f9d45f1,
  36117. 0x119448fa,
  36118. 0x4be30393,
  36119. 0x45ea0e98,
  36120. 0x57f11985,
  36121. 0x59f8148e,
  36122. 0x73c737bf,
  36123. 0x7dce3ab4,
  36124. 0x6fd52da9,
  36125. 0x61dc20a2,
  36126. 0xad766df6,
  36127. 0xa37f60fd,
  36128. 0xb16477e0,
  36129. 0xbf6d7aeb,
  36130. 0x955259da,
  36131. 0x9b5b54d1,
  36132. 0x894043cc,
  36133. 0x87494ec7,
  36134. 0xdd3e05ae,
  36135. 0xd33708a5,
  36136. 0xc12c1fb8,
  36137. 0xcf2512b3,
  36138. 0xe51a3182,
  36139. 0xeb133c89,
  36140. 0xf9082b94,
  36141. 0xf701269f,
  36142. 0x4de6bd46,
  36143. 0x43efb04d,
  36144. 0x51f4a750,
  36145. 0x5ffdaa5b,
  36146. 0x75c2896a,
  36147. 0x7bcb8461,
  36148. 0x69d0937c,
  36149. 0x67d99e77,
  36150. 0x3daed51e,
  36151. 0x33a7d815,
  36152. 0x21bccf08,
  36153. 0x2fb5c203,
  36154. 0x058ae132,
  36155. 0x0b83ec39,
  36156. 0x1998fb24,
  36157. 0x1791f62f,
  36158. 0x764dd68d,
  36159. 0x7844db86,
  36160. 0x6a5fcc9b,
  36161. 0x6456c190,
  36162. 0x4e69e2a1,
  36163. 0x4060efaa,
  36164. 0x527bf8b7,
  36165. 0x5c72f5bc,
  36166. 0x0605bed5,
  36167. 0x080cb3de,
  36168. 0x1a17a4c3,
  36169. 0x141ea9c8,
  36170. 0x3e218af9,
  36171. 0x302887f2,
  36172. 0x223390ef,
  36173. 0x2c3a9de4,
  36174. 0x96dd063d,
  36175. 0x98d40b36,
  36176. 0x8acf1c2b,
  36177. 0x84c61120,
  36178. 0xaef93211,
  36179. 0xa0f03f1a,
  36180. 0xb2eb2807,
  36181. 0xbce2250c,
  36182. 0xe6956e65,
  36183. 0xe89c636e,
  36184. 0xfa877473,
  36185. 0xf48e7978,
  36186. 0xdeb15a49,
  36187. 0xd0b85742,
  36188. 0xc2a3405f,
  36189. 0xccaa4d54,
  36190. 0x41ecdaf7,
  36191. 0x4fe5d7fc,
  36192. 0x5dfec0e1,
  36193. 0x53f7cdea,
  36194. 0x79c8eedb,
  36195. 0x77c1e3d0,
  36196. 0x65daf4cd,
  36197. 0x6bd3f9c6,
  36198. 0x31a4b2af,
  36199. 0x3fadbfa4,
  36200. 0x2db6a8b9,
  36201. 0x23bfa5b2,
  36202. 0x09808683,
  36203. 0x07898b88,
  36204. 0x15929c95,
  36205. 0x1b9b919e,
  36206. 0xa17c0a47,
  36207. 0xaf75074c,
  36208. 0xbd6e1051,
  36209. 0xb3671d5a,
  36210. 0x99583e6b,
  36211. 0x97513360,
  36212. 0x854a247d,
  36213. 0x8b432976,
  36214. 0xd134621f,
  36215. 0xdf3d6f14,
  36216. 0xcd267809,
  36217. 0xc32f7502,
  36218. 0xe9105633,
  36219. 0xe7195b38,
  36220. 0xf5024c25,
  36221. 0xfb0b412e,
  36222. 0x9ad7618c,
  36223. 0x94de6c87,
  36224. 0x86c57b9a,
  36225. 0x88cc7691,
  36226. 0xa2f355a0,
  36227. 0xacfa58ab,
  36228. 0xbee14fb6,
  36229. 0xb0e842bd,
  36230. 0xea9f09d4,
  36231. 0xe49604df,
  36232. 0xf68d13c2,
  36233. 0xf8841ec9,
  36234. 0xd2bb3df8,
  36235. 0xdcb230f3,
  36236. 0xcea927ee,
  36237. 0xc0a02ae5,
  36238. 0x7a47b13c,
  36239. 0x744ebc37,
  36240. 0x6655ab2a,
  36241. 0x685ca621,
  36242. 0x42638510,
  36243. 0x4c6a881b,
  36244. 0x5e719f06,
  36245. 0x5078920d,
  36246. 0x0a0fd964,
  36247. 0x0406d46f,
  36248. 0x161dc372,
  36249. 0x1814ce79,
  36250. 0x322bed48,
  36251. 0x3c22e043,
  36252. 0x2e39f75e,
  36253. 0x2030fa55,
  36254. 0xec9ab701,
  36255. 0xe293ba0a,
  36256. 0xf088ad17,
  36257. 0xfe81a01c,
  36258. 0xd4be832d,
  36259. 0xdab78e26,
  36260. 0xc8ac993b,
  36261. 0xc6a59430,
  36262. 0x9cd2df59,
  36263. 0x92dbd252,
  36264. 0x80c0c54f,
  36265. 0x8ec9c844,
  36266. 0xa4f6eb75,
  36267. 0xaaffe67e,
  36268. 0xb8e4f163,
  36269. 0xb6edfc68,
  36270. 0x0c0a67b1,
  36271. 0x02036aba,
  36272. 0x10187da7,
  36273. 0x1e1170ac,
  36274. 0x342e539d,
  36275. 0x3a275e96,
  36276. 0x283c498b,
  36277. 0x26354480,
  36278. 0x7c420fe9,
  36279. 0x724b02e2,
  36280. 0x605015ff,
  36281. 0x6e5918f4,
  36282. 0x44663bc5,
  36283. 0x4a6f36ce,
  36284. 0x587421d3,
  36285. 0x567d2cd8,
  36286. 0x37a10c7a,
  36287. 0x39a80171,
  36288. 0x2bb3166c,
  36289. 0x25ba1b67,
  36290. 0x0f853856,
  36291. 0x018c355d,
  36292. 0x13972240,
  36293. 0x1d9e2f4b,
  36294. 0x47e96422,
  36295. 0x49e06929,
  36296. 0x5bfb7e34,
  36297. 0x55f2733f,
  36298. 0x7fcd500e,
  36299. 0x71c45d05,
  36300. 0x63df4a18,
  36301. 0x6dd64713,
  36302. 0xd731dcca,
  36303. 0xd938d1c1,
  36304. 0xcb23c6dc,
  36305. 0xc52acbd7,
  36306. 0xef15e8e6,
  36307. 0xe11ce5ed,
  36308. 0xf307f2f0,
  36309. 0xfd0efffb,
  36310. 0xa779b492,
  36311. 0xa970b999,
  36312. 0xbb6bae84,
  36313. 0xb562a38f,
  36314. 0x9f5d80be,
  36315. 0x91548db5,
  36316. 0x834f9aa8,
  36317. 0x8d4697a3
  36318. ]);
  36319. function expandKey128(cipherKey) {
  36320. var b = 176, result = new Uint8Array(b);
  36321. result.set(cipherKey);
  36322. for (var j = 16, i = 1; j < b; ++i) {
  36323. // RotWord
  36324. var t1 = result[j - 3], t2 = result[j - 2], t3 = result[j - 1], t4 = result[j - 4];
  36325. // SubWord
  36326. t1 = s[t1];
  36327. t2 = s[t2];
  36328. t3 = s[t3];
  36329. t4 = s[t4];
  36330. // Rcon
  36331. t1 = t1 ^ rcon[i];
  36332. for (var n = 0; n < 4; ++n) {
  36333. result[j] = t1 ^= result[j - 16];
  36334. j++;
  36335. result[j] = t2 ^= result[j - 16];
  36336. j++;
  36337. result[j] = t3 ^= result[j - 16];
  36338. j++;
  36339. result[j] = t4 ^= result[j - 16];
  36340. j++;
  36341. }
  36342. }
  36343. return result;
  36344. }
  36345. function decrypt128(input, key) {
  36346. var state = new Uint8Array(16);
  36347. state.set(input);
  36348. var i, j, k;
  36349. var t, u, v;
  36350. // AddRoundKey
  36351. for (j = 0, k = 160; j < 16; ++j, ++k) {
  36352. state[j] ^= key[k];
  36353. }
  36354. for (i = 9; i >= 1; --i) {
  36355. // InvShiftRows
  36356. t = state[13];
  36357. state[13] = state[9];
  36358. state[9] = state[5];
  36359. state[5] = state[1];
  36360. state[1] = t;
  36361. t = state[14];
  36362. u = state[10];
  36363. state[14] = state[6];
  36364. state[10] = state[2];
  36365. state[6] = t;
  36366. state[2] = u;
  36367. t = state[15];
  36368. u = state[11];
  36369. v = state[7];
  36370. state[15] = state[3];
  36371. state[11] = t;
  36372. state[7] = u;
  36373. state[3] = v;
  36374. // InvSubBytes
  36375. for (j = 0; j < 16; ++j) {
  36376. state[j] = inv_s[state[j]];
  36377. }
  36378. // AddRoundKey
  36379. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  36380. state[j] ^= key[k];
  36381. }
  36382. // InvMixColumns
  36383. for (j = 0; j < 16; j += 4) {
  36384. var s0 = mix[state[j]], s1 = mix[state[j + 1]], s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  36385. t = s0 ^ s1 >>> 8 ^ s1 << 24 ^ s2 >>> 16 ^ s2 << 16 ^ s3 >>> 24 ^ s3 << 8;
  36386. state[j] = t >>> 24 & 0xFF;
  36387. state[j + 1] = t >> 16 & 0xFF;
  36388. state[j + 2] = t >> 8 & 0xFF;
  36389. state[j + 3] = t & 0xFF;
  36390. }
  36391. }
  36392. // InvShiftRows
  36393. t = state[13];
  36394. state[13] = state[9];
  36395. state[9] = state[5];
  36396. state[5] = state[1];
  36397. state[1] = t;
  36398. t = state[14];
  36399. u = state[10];
  36400. state[14] = state[6];
  36401. state[10] = state[2];
  36402. state[6] = t;
  36403. state[2] = u;
  36404. t = state[15];
  36405. u = state[11];
  36406. v = state[7];
  36407. state[15] = state[3];
  36408. state[11] = t;
  36409. state[7] = u;
  36410. state[3] = v;
  36411. for (j = 0; j < 16; ++j) {
  36412. // InvSubBytes
  36413. state[j] = inv_s[state[j]];
  36414. // AddRoundKey
  36415. state[j] ^= key[j];
  36416. }
  36417. return state;
  36418. }
  36419. function encrypt128(input, key) {
  36420. var t, u, v, k;
  36421. var state = new Uint8Array(16);
  36422. state.set(input);
  36423. for (j = 0; j < 16; ++j) {
  36424. // AddRoundKey
  36425. state[j] ^= key[j];
  36426. }
  36427. for (i = 1; i < 10; i++) {
  36428. //SubBytes
  36429. for (j = 0; j < 16; ++j) {
  36430. state[j] = s[state[j]];
  36431. }
  36432. //ShiftRows
  36433. v = state[1];
  36434. state[1] = state[5];
  36435. state[5] = state[9];
  36436. state[9] = state[13];
  36437. state[13] = v;
  36438. v = state[2];
  36439. u = state[6];
  36440. state[2] = state[10];
  36441. state[6] = state[14];
  36442. state[10] = v;
  36443. state[14] = u;
  36444. v = state[3];
  36445. u = state[7];
  36446. t = state[11];
  36447. state[3] = state[15];
  36448. state[7] = v;
  36449. state[11] = u;
  36450. state[15] = t;
  36451. //MixColumns
  36452. for (var j = 0; j < 16; j += 4) {
  36453. var s0 = state[j + 0], s1 = state[j + 1];
  36454. var s2 = state[j + 2], s3 = state[j + 3];
  36455. t = s0 ^ s1 ^ s2 ^ s3;
  36456. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  36457. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  36458. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  36459. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  36460. }
  36461. //AddRoundKey
  36462. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  36463. state[j] ^= key[k];
  36464. }
  36465. }
  36466. //SubBytes
  36467. for (j = 0; j < 16; ++j) {
  36468. state[j] = s[state[j]];
  36469. }
  36470. //ShiftRows
  36471. v = state[1];
  36472. state[1] = state[5];
  36473. state[5] = state[9];
  36474. state[9] = state[13];
  36475. state[13] = v;
  36476. v = state[2];
  36477. u = state[6];
  36478. state[2] = state[10];
  36479. state[6] = state[14];
  36480. state[10] = v;
  36481. state[14] = u;
  36482. v = state[3];
  36483. u = state[7];
  36484. t = state[11];
  36485. state[3] = state[15];
  36486. state[7] = v;
  36487. state[11] = u;
  36488. state[15] = t;
  36489. //AddRoundKey
  36490. for (j = 0, k = 160; j < 16; ++j, ++k) {
  36491. state[j] ^= key[k];
  36492. }
  36493. return state;
  36494. }
  36495. function AES128Cipher(key) {
  36496. this.key = expandKey128(key);
  36497. this.buffer = new Uint8Array(16);
  36498. this.bufferPosition = 0;
  36499. }
  36500. function decryptBlock2(data, finalize) {
  36501. var i, j, ii, sourceLength = data.length, buffer = this.buffer, bufferLength = this.bufferPosition, result = [], iv = this.iv;
  36502. for (i = 0; i < sourceLength; ++i) {
  36503. buffer[bufferLength] = data[i];
  36504. ++bufferLength;
  36505. if (bufferLength < 16) {
  36506. continue;
  36507. }
  36508. // buffer is full, decrypting
  36509. var plain = decrypt128(buffer, this.key);
  36510. // xor-ing the IV vector to get plain text
  36511. for (j = 0; j < 16; ++j) {
  36512. plain[j] ^= iv[j];
  36513. }
  36514. iv = buffer;
  36515. result.push(plain);
  36516. buffer = new Uint8Array(16);
  36517. bufferLength = 0;
  36518. }
  36519. // saving incomplete buffer
  36520. this.buffer = buffer;
  36521. this.bufferLength = bufferLength;
  36522. this.iv = iv;
  36523. if (result.length === 0) {
  36524. return new Uint8Array([]);
  36525. }
  36526. // combining plain text blocks into one
  36527. var outputLength = 16 * result.length;
  36528. if (finalize) {
  36529. // undo a padding that is described in RFC 2898
  36530. var lastBlock = result[result.length - 1];
  36531. var psLen = lastBlock[15];
  36532. if (psLen <= 16) {
  36533. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  36534. if (lastBlock[i] !== psLen) {
  36535. // Invalid padding, assume that the block has no padding.
  36536. psLen = 0;
  36537. break;
  36538. }
  36539. }
  36540. outputLength -= psLen;
  36541. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  36542. }
  36543. }
  36544. var output = new Uint8Array(outputLength);
  36545. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  36546. output.set(result[i], j);
  36547. }
  36548. return output;
  36549. }
  36550. AES128Cipher.prototype = {
  36551. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  36552. var i, sourceLength = data.length;
  36553. var buffer = this.buffer, bufferLength = this.bufferPosition;
  36554. // waiting for IV values -- they are at the start of the stream
  36555. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  36556. buffer[bufferLength] = data[i];
  36557. }
  36558. if (bufferLength < 16) {
  36559. // need more data
  36560. this.bufferLength = bufferLength;
  36561. return new Uint8Array([]);
  36562. }
  36563. this.iv = buffer;
  36564. this.buffer = new Uint8Array(16);
  36565. this.bufferLength = 0;
  36566. // starting decryption
  36567. this.decryptBlock = decryptBlock2;
  36568. return this.decryptBlock(data.subarray(16), finalize);
  36569. },
  36570. encrypt: function AES128Cipher_encrypt(data, iv) {
  36571. var i, j, ii, sourceLength = data.length, buffer = this.buffer, bufferLength = this.bufferPosition, result = [];
  36572. if (!iv) {
  36573. iv = new Uint8Array(16);
  36574. }
  36575. for (i = 0; i < sourceLength; ++i) {
  36576. buffer[bufferLength] = data[i];
  36577. ++bufferLength;
  36578. if (bufferLength < 16) {
  36579. continue;
  36580. }
  36581. for (j = 0; j < 16; ++j) {
  36582. buffer[j] ^= iv[j];
  36583. }
  36584. // buffer is full, encrypting
  36585. var cipher = encrypt128(buffer, this.key);
  36586. iv = cipher;
  36587. result.push(cipher);
  36588. buffer = new Uint8Array(16);
  36589. bufferLength = 0;
  36590. }
  36591. // saving incomplete buffer
  36592. this.buffer = buffer;
  36593. this.bufferLength = bufferLength;
  36594. this.iv = iv;
  36595. if (result.length === 0) {
  36596. return new Uint8Array([]);
  36597. }
  36598. // combining plain text blocks into one
  36599. var outputLength = 16 * result.length;
  36600. var output = new Uint8Array(outputLength);
  36601. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  36602. output.set(result[i], j);
  36603. }
  36604. return output;
  36605. }
  36606. };
  36607. return AES128Cipher;
  36608. }();
  36609. var AES256Cipher = function AES256CipherClosure() {
  36610. var rcon = new Uint8Array([
  36611. 0x8d,
  36612. 0x01,
  36613. 0x02,
  36614. 0x04,
  36615. 0x08,
  36616. 0x10,
  36617. 0x20,
  36618. 0x40,
  36619. 0x80,
  36620. 0x1b,
  36621. 0x36,
  36622. 0x6c,
  36623. 0xd8,
  36624. 0xab,
  36625. 0x4d,
  36626. 0x9a,
  36627. 0x2f,
  36628. 0x5e,
  36629. 0xbc,
  36630. 0x63,
  36631. 0xc6,
  36632. 0x97,
  36633. 0x35,
  36634. 0x6a,
  36635. 0xd4,
  36636. 0xb3,
  36637. 0x7d,
  36638. 0xfa,
  36639. 0xef,
  36640. 0xc5,
  36641. 0x91,
  36642. 0x39,
  36643. 0x72,
  36644. 0xe4,
  36645. 0xd3,
  36646. 0xbd,
  36647. 0x61,
  36648. 0xc2,
  36649. 0x9f,
  36650. 0x25,
  36651. 0x4a,
  36652. 0x94,
  36653. 0x33,
  36654. 0x66,
  36655. 0xcc,
  36656. 0x83,
  36657. 0x1d,
  36658. 0x3a,
  36659. 0x74,
  36660. 0xe8,
  36661. 0xcb,
  36662. 0x8d,
  36663. 0x01,
  36664. 0x02,
  36665. 0x04,
  36666. 0x08,
  36667. 0x10,
  36668. 0x20,
  36669. 0x40,
  36670. 0x80,
  36671. 0x1b,
  36672. 0x36,
  36673. 0x6c,
  36674. 0xd8,
  36675. 0xab,
  36676. 0x4d,
  36677. 0x9a,
  36678. 0x2f,
  36679. 0x5e,
  36680. 0xbc,
  36681. 0x63,
  36682. 0xc6,
  36683. 0x97,
  36684. 0x35,
  36685. 0x6a,
  36686. 0xd4,
  36687. 0xb3,
  36688. 0x7d,
  36689. 0xfa,
  36690. 0xef,
  36691. 0xc5,
  36692. 0x91,
  36693. 0x39,
  36694. 0x72,
  36695. 0xe4,
  36696. 0xd3,
  36697. 0xbd,
  36698. 0x61,
  36699. 0xc2,
  36700. 0x9f,
  36701. 0x25,
  36702. 0x4a,
  36703. 0x94,
  36704. 0x33,
  36705. 0x66,
  36706. 0xcc,
  36707. 0x83,
  36708. 0x1d,
  36709. 0x3a,
  36710. 0x74,
  36711. 0xe8,
  36712. 0xcb,
  36713. 0x8d,
  36714. 0x01,
  36715. 0x02,
  36716. 0x04,
  36717. 0x08,
  36718. 0x10,
  36719. 0x20,
  36720. 0x40,
  36721. 0x80,
  36722. 0x1b,
  36723. 0x36,
  36724. 0x6c,
  36725. 0xd8,
  36726. 0xab,
  36727. 0x4d,
  36728. 0x9a,
  36729. 0x2f,
  36730. 0x5e,
  36731. 0xbc,
  36732. 0x63,
  36733. 0xc6,
  36734. 0x97,
  36735. 0x35,
  36736. 0x6a,
  36737. 0xd4,
  36738. 0xb3,
  36739. 0x7d,
  36740. 0xfa,
  36741. 0xef,
  36742. 0xc5,
  36743. 0x91,
  36744. 0x39,
  36745. 0x72,
  36746. 0xe4,
  36747. 0xd3,
  36748. 0xbd,
  36749. 0x61,
  36750. 0xc2,
  36751. 0x9f,
  36752. 0x25,
  36753. 0x4a,
  36754. 0x94,
  36755. 0x33,
  36756. 0x66,
  36757. 0xcc,
  36758. 0x83,
  36759. 0x1d,
  36760. 0x3a,
  36761. 0x74,
  36762. 0xe8,
  36763. 0xcb,
  36764. 0x8d,
  36765. 0x01,
  36766. 0x02,
  36767. 0x04,
  36768. 0x08,
  36769. 0x10,
  36770. 0x20,
  36771. 0x40,
  36772. 0x80,
  36773. 0x1b,
  36774. 0x36,
  36775. 0x6c,
  36776. 0xd8,
  36777. 0xab,
  36778. 0x4d,
  36779. 0x9a,
  36780. 0x2f,
  36781. 0x5e,
  36782. 0xbc,
  36783. 0x63,
  36784. 0xc6,
  36785. 0x97,
  36786. 0x35,
  36787. 0x6a,
  36788. 0xd4,
  36789. 0xb3,
  36790. 0x7d,
  36791. 0xfa,
  36792. 0xef,
  36793. 0xc5,
  36794. 0x91,
  36795. 0x39,
  36796. 0x72,
  36797. 0xe4,
  36798. 0xd3,
  36799. 0xbd,
  36800. 0x61,
  36801. 0xc2,
  36802. 0x9f,
  36803. 0x25,
  36804. 0x4a,
  36805. 0x94,
  36806. 0x33,
  36807. 0x66,
  36808. 0xcc,
  36809. 0x83,
  36810. 0x1d,
  36811. 0x3a,
  36812. 0x74,
  36813. 0xe8,
  36814. 0xcb,
  36815. 0x8d,
  36816. 0x01,
  36817. 0x02,
  36818. 0x04,
  36819. 0x08,
  36820. 0x10,
  36821. 0x20,
  36822. 0x40,
  36823. 0x80,
  36824. 0x1b,
  36825. 0x36,
  36826. 0x6c,
  36827. 0xd8,
  36828. 0xab,
  36829. 0x4d,
  36830. 0x9a,
  36831. 0x2f,
  36832. 0x5e,
  36833. 0xbc,
  36834. 0x63,
  36835. 0xc6,
  36836. 0x97,
  36837. 0x35,
  36838. 0x6a,
  36839. 0xd4,
  36840. 0xb3,
  36841. 0x7d,
  36842. 0xfa,
  36843. 0xef,
  36844. 0xc5,
  36845. 0x91,
  36846. 0x39,
  36847. 0x72,
  36848. 0xe4,
  36849. 0xd3,
  36850. 0xbd,
  36851. 0x61,
  36852. 0xc2,
  36853. 0x9f,
  36854. 0x25,
  36855. 0x4a,
  36856. 0x94,
  36857. 0x33,
  36858. 0x66,
  36859. 0xcc,
  36860. 0x83,
  36861. 0x1d,
  36862. 0x3a,
  36863. 0x74,
  36864. 0xe8,
  36865. 0xcb,
  36866. 0x8d
  36867. ]);
  36868. var s = new Uint8Array([
  36869. 0x63,
  36870. 0x7c,
  36871. 0x77,
  36872. 0x7b,
  36873. 0xf2,
  36874. 0x6b,
  36875. 0x6f,
  36876. 0xc5,
  36877. 0x30,
  36878. 0x01,
  36879. 0x67,
  36880. 0x2b,
  36881. 0xfe,
  36882. 0xd7,
  36883. 0xab,
  36884. 0x76,
  36885. 0xca,
  36886. 0x82,
  36887. 0xc9,
  36888. 0x7d,
  36889. 0xfa,
  36890. 0x59,
  36891. 0x47,
  36892. 0xf0,
  36893. 0xad,
  36894. 0xd4,
  36895. 0xa2,
  36896. 0xaf,
  36897. 0x9c,
  36898. 0xa4,
  36899. 0x72,
  36900. 0xc0,
  36901. 0xb7,
  36902. 0xfd,
  36903. 0x93,
  36904. 0x26,
  36905. 0x36,
  36906. 0x3f,
  36907. 0xf7,
  36908. 0xcc,
  36909. 0x34,
  36910. 0xa5,
  36911. 0xe5,
  36912. 0xf1,
  36913. 0x71,
  36914. 0xd8,
  36915. 0x31,
  36916. 0x15,
  36917. 0x04,
  36918. 0xc7,
  36919. 0x23,
  36920. 0xc3,
  36921. 0x18,
  36922. 0x96,
  36923. 0x05,
  36924. 0x9a,
  36925. 0x07,
  36926. 0x12,
  36927. 0x80,
  36928. 0xe2,
  36929. 0xeb,
  36930. 0x27,
  36931. 0xb2,
  36932. 0x75,
  36933. 0x09,
  36934. 0x83,
  36935. 0x2c,
  36936. 0x1a,
  36937. 0x1b,
  36938. 0x6e,
  36939. 0x5a,
  36940. 0xa0,
  36941. 0x52,
  36942. 0x3b,
  36943. 0xd6,
  36944. 0xb3,
  36945. 0x29,
  36946. 0xe3,
  36947. 0x2f,
  36948. 0x84,
  36949. 0x53,
  36950. 0xd1,
  36951. 0x00,
  36952. 0xed,
  36953. 0x20,
  36954. 0xfc,
  36955. 0xb1,
  36956. 0x5b,
  36957. 0x6a,
  36958. 0xcb,
  36959. 0xbe,
  36960. 0x39,
  36961. 0x4a,
  36962. 0x4c,
  36963. 0x58,
  36964. 0xcf,
  36965. 0xd0,
  36966. 0xef,
  36967. 0xaa,
  36968. 0xfb,
  36969. 0x43,
  36970. 0x4d,
  36971. 0x33,
  36972. 0x85,
  36973. 0x45,
  36974. 0xf9,
  36975. 0x02,
  36976. 0x7f,
  36977. 0x50,
  36978. 0x3c,
  36979. 0x9f,
  36980. 0xa8,
  36981. 0x51,
  36982. 0xa3,
  36983. 0x40,
  36984. 0x8f,
  36985. 0x92,
  36986. 0x9d,
  36987. 0x38,
  36988. 0xf5,
  36989. 0xbc,
  36990. 0xb6,
  36991. 0xda,
  36992. 0x21,
  36993. 0x10,
  36994. 0xff,
  36995. 0xf3,
  36996. 0xd2,
  36997. 0xcd,
  36998. 0x0c,
  36999. 0x13,
  37000. 0xec,
  37001. 0x5f,
  37002. 0x97,
  37003. 0x44,
  37004. 0x17,
  37005. 0xc4,
  37006. 0xa7,
  37007. 0x7e,
  37008. 0x3d,
  37009. 0x64,
  37010. 0x5d,
  37011. 0x19,
  37012. 0x73,
  37013. 0x60,
  37014. 0x81,
  37015. 0x4f,
  37016. 0xdc,
  37017. 0x22,
  37018. 0x2a,
  37019. 0x90,
  37020. 0x88,
  37021. 0x46,
  37022. 0xee,
  37023. 0xb8,
  37024. 0x14,
  37025. 0xde,
  37026. 0x5e,
  37027. 0x0b,
  37028. 0xdb,
  37029. 0xe0,
  37030. 0x32,
  37031. 0x3a,
  37032. 0x0a,
  37033. 0x49,
  37034. 0x06,
  37035. 0x24,
  37036. 0x5c,
  37037. 0xc2,
  37038. 0xd3,
  37039. 0xac,
  37040. 0x62,
  37041. 0x91,
  37042. 0x95,
  37043. 0xe4,
  37044. 0x79,
  37045. 0xe7,
  37046. 0xc8,
  37047. 0x37,
  37048. 0x6d,
  37049. 0x8d,
  37050. 0xd5,
  37051. 0x4e,
  37052. 0xa9,
  37053. 0x6c,
  37054. 0x56,
  37055. 0xf4,
  37056. 0xea,
  37057. 0x65,
  37058. 0x7a,
  37059. 0xae,
  37060. 0x08,
  37061. 0xba,
  37062. 0x78,
  37063. 0x25,
  37064. 0x2e,
  37065. 0x1c,
  37066. 0xa6,
  37067. 0xb4,
  37068. 0xc6,
  37069. 0xe8,
  37070. 0xdd,
  37071. 0x74,
  37072. 0x1f,
  37073. 0x4b,
  37074. 0xbd,
  37075. 0x8b,
  37076. 0x8a,
  37077. 0x70,
  37078. 0x3e,
  37079. 0xb5,
  37080. 0x66,
  37081. 0x48,
  37082. 0x03,
  37083. 0xf6,
  37084. 0x0e,
  37085. 0x61,
  37086. 0x35,
  37087. 0x57,
  37088. 0xb9,
  37089. 0x86,
  37090. 0xc1,
  37091. 0x1d,
  37092. 0x9e,
  37093. 0xe1,
  37094. 0xf8,
  37095. 0x98,
  37096. 0x11,
  37097. 0x69,
  37098. 0xd9,
  37099. 0x8e,
  37100. 0x94,
  37101. 0x9b,
  37102. 0x1e,
  37103. 0x87,
  37104. 0xe9,
  37105. 0xce,
  37106. 0x55,
  37107. 0x28,
  37108. 0xdf,
  37109. 0x8c,
  37110. 0xa1,
  37111. 0x89,
  37112. 0x0d,
  37113. 0xbf,
  37114. 0xe6,
  37115. 0x42,
  37116. 0x68,
  37117. 0x41,
  37118. 0x99,
  37119. 0x2d,
  37120. 0x0f,
  37121. 0xb0,
  37122. 0x54,
  37123. 0xbb,
  37124. 0x16
  37125. ]);
  37126. var inv_s = new Uint8Array([
  37127. 0x52,
  37128. 0x09,
  37129. 0x6a,
  37130. 0xd5,
  37131. 0x30,
  37132. 0x36,
  37133. 0xa5,
  37134. 0x38,
  37135. 0xbf,
  37136. 0x40,
  37137. 0xa3,
  37138. 0x9e,
  37139. 0x81,
  37140. 0xf3,
  37141. 0xd7,
  37142. 0xfb,
  37143. 0x7c,
  37144. 0xe3,
  37145. 0x39,
  37146. 0x82,
  37147. 0x9b,
  37148. 0x2f,
  37149. 0xff,
  37150. 0x87,
  37151. 0x34,
  37152. 0x8e,
  37153. 0x43,
  37154. 0x44,
  37155. 0xc4,
  37156. 0xde,
  37157. 0xe9,
  37158. 0xcb,
  37159. 0x54,
  37160. 0x7b,
  37161. 0x94,
  37162. 0x32,
  37163. 0xa6,
  37164. 0xc2,
  37165. 0x23,
  37166. 0x3d,
  37167. 0xee,
  37168. 0x4c,
  37169. 0x95,
  37170. 0x0b,
  37171. 0x42,
  37172. 0xfa,
  37173. 0xc3,
  37174. 0x4e,
  37175. 0x08,
  37176. 0x2e,
  37177. 0xa1,
  37178. 0x66,
  37179. 0x28,
  37180. 0xd9,
  37181. 0x24,
  37182. 0xb2,
  37183. 0x76,
  37184. 0x5b,
  37185. 0xa2,
  37186. 0x49,
  37187. 0x6d,
  37188. 0x8b,
  37189. 0xd1,
  37190. 0x25,
  37191. 0x72,
  37192. 0xf8,
  37193. 0xf6,
  37194. 0x64,
  37195. 0x86,
  37196. 0x68,
  37197. 0x98,
  37198. 0x16,
  37199. 0xd4,
  37200. 0xa4,
  37201. 0x5c,
  37202. 0xcc,
  37203. 0x5d,
  37204. 0x65,
  37205. 0xb6,
  37206. 0x92,
  37207. 0x6c,
  37208. 0x70,
  37209. 0x48,
  37210. 0x50,
  37211. 0xfd,
  37212. 0xed,
  37213. 0xb9,
  37214. 0xda,
  37215. 0x5e,
  37216. 0x15,
  37217. 0x46,
  37218. 0x57,
  37219. 0xa7,
  37220. 0x8d,
  37221. 0x9d,
  37222. 0x84,
  37223. 0x90,
  37224. 0xd8,
  37225. 0xab,
  37226. 0x00,
  37227. 0x8c,
  37228. 0xbc,
  37229. 0xd3,
  37230. 0x0a,
  37231. 0xf7,
  37232. 0xe4,
  37233. 0x58,
  37234. 0x05,
  37235. 0xb8,
  37236. 0xb3,
  37237. 0x45,
  37238. 0x06,
  37239. 0xd0,
  37240. 0x2c,
  37241. 0x1e,
  37242. 0x8f,
  37243. 0xca,
  37244. 0x3f,
  37245. 0x0f,
  37246. 0x02,
  37247. 0xc1,
  37248. 0xaf,
  37249. 0xbd,
  37250. 0x03,
  37251. 0x01,
  37252. 0x13,
  37253. 0x8a,
  37254. 0x6b,
  37255. 0x3a,
  37256. 0x91,
  37257. 0x11,
  37258. 0x41,
  37259. 0x4f,
  37260. 0x67,
  37261. 0xdc,
  37262. 0xea,
  37263. 0x97,
  37264. 0xf2,
  37265. 0xcf,
  37266. 0xce,
  37267. 0xf0,
  37268. 0xb4,
  37269. 0xe6,
  37270. 0x73,
  37271. 0x96,
  37272. 0xac,
  37273. 0x74,
  37274. 0x22,
  37275. 0xe7,
  37276. 0xad,
  37277. 0x35,
  37278. 0x85,
  37279. 0xe2,
  37280. 0xf9,
  37281. 0x37,
  37282. 0xe8,
  37283. 0x1c,
  37284. 0x75,
  37285. 0xdf,
  37286. 0x6e,
  37287. 0x47,
  37288. 0xf1,
  37289. 0x1a,
  37290. 0x71,
  37291. 0x1d,
  37292. 0x29,
  37293. 0xc5,
  37294. 0x89,
  37295. 0x6f,
  37296. 0xb7,
  37297. 0x62,
  37298. 0x0e,
  37299. 0xaa,
  37300. 0x18,
  37301. 0xbe,
  37302. 0x1b,
  37303. 0xfc,
  37304. 0x56,
  37305. 0x3e,
  37306. 0x4b,
  37307. 0xc6,
  37308. 0xd2,
  37309. 0x79,
  37310. 0x20,
  37311. 0x9a,
  37312. 0xdb,
  37313. 0xc0,
  37314. 0xfe,
  37315. 0x78,
  37316. 0xcd,
  37317. 0x5a,
  37318. 0xf4,
  37319. 0x1f,
  37320. 0xdd,
  37321. 0xa8,
  37322. 0x33,
  37323. 0x88,
  37324. 0x07,
  37325. 0xc7,
  37326. 0x31,
  37327. 0xb1,
  37328. 0x12,
  37329. 0x10,
  37330. 0x59,
  37331. 0x27,
  37332. 0x80,
  37333. 0xec,
  37334. 0x5f,
  37335. 0x60,
  37336. 0x51,
  37337. 0x7f,
  37338. 0xa9,
  37339. 0x19,
  37340. 0xb5,
  37341. 0x4a,
  37342. 0x0d,
  37343. 0x2d,
  37344. 0xe5,
  37345. 0x7a,
  37346. 0x9f,
  37347. 0x93,
  37348. 0xc9,
  37349. 0x9c,
  37350. 0xef,
  37351. 0xa0,
  37352. 0xe0,
  37353. 0x3b,
  37354. 0x4d,
  37355. 0xae,
  37356. 0x2a,
  37357. 0xf5,
  37358. 0xb0,
  37359. 0xc8,
  37360. 0xeb,
  37361. 0xbb,
  37362. 0x3c,
  37363. 0x83,
  37364. 0x53,
  37365. 0x99,
  37366. 0x61,
  37367. 0x17,
  37368. 0x2b,
  37369. 0x04,
  37370. 0x7e,
  37371. 0xba,
  37372. 0x77,
  37373. 0xd6,
  37374. 0x26,
  37375. 0xe1,
  37376. 0x69,
  37377. 0x14,
  37378. 0x63,
  37379. 0x55,
  37380. 0x21,
  37381. 0x0c,
  37382. 0x7d
  37383. ]);
  37384. var mixCol = new Uint8Array(256);
  37385. for (var i = 0; i < 256; i++) {
  37386. if (i < 128) {
  37387. mixCol[i] = i << 1;
  37388. } else {
  37389. mixCol[i] = i << 1 ^ 0x1b;
  37390. }
  37391. }
  37392. var mix = new Uint32Array([
  37393. 0x00000000,
  37394. 0x0e090d0b,
  37395. 0x1c121a16,
  37396. 0x121b171d,
  37397. 0x3824342c,
  37398. 0x362d3927,
  37399. 0x24362e3a,
  37400. 0x2a3f2331,
  37401. 0x70486858,
  37402. 0x7e416553,
  37403. 0x6c5a724e,
  37404. 0x62537f45,
  37405. 0x486c5c74,
  37406. 0x4665517f,
  37407. 0x547e4662,
  37408. 0x5a774b69,
  37409. 0xe090d0b0,
  37410. 0xee99ddbb,
  37411. 0xfc82caa6,
  37412. 0xf28bc7ad,
  37413. 0xd8b4e49c,
  37414. 0xd6bde997,
  37415. 0xc4a6fe8a,
  37416. 0xcaaff381,
  37417. 0x90d8b8e8,
  37418. 0x9ed1b5e3,
  37419. 0x8ccaa2fe,
  37420. 0x82c3aff5,
  37421. 0xa8fc8cc4,
  37422. 0xa6f581cf,
  37423. 0xb4ee96d2,
  37424. 0xbae79bd9,
  37425. 0xdb3bbb7b,
  37426. 0xd532b670,
  37427. 0xc729a16d,
  37428. 0xc920ac66,
  37429. 0xe31f8f57,
  37430. 0xed16825c,
  37431. 0xff0d9541,
  37432. 0xf104984a,
  37433. 0xab73d323,
  37434. 0xa57ade28,
  37435. 0xb761c935,
  37436. 0xb968c43e,
  37437. 0x9357e70f,
  37438. 0x9d5eea04,
  37439. 0x8f45fd19,
  37440. 0x814cf012,
  37441. 0x3bab6bcb,
  37442. 0x35a266c0,
  37443. 0x27b971dd,
  37444. 0x29b07cd6,
  37445. 0x038f5fe7,
  37446. 0x0d8652ec,
  37447. 0x1f9d45f1,
  37448. 0x119448fa,
  37449. 0x4be30393,
  37450. 0x45ea0e98,
  37451. 0x57f11985,
  37452. 0x59f8148e,
  37453. 0x73c737bf,
  37454. 0x7dce3ab4,
  37455. 0x6fd52da9,
  37456. 0x61dc20a2,
  37457. 0xad766df6,
  37458. 0xa37f60fd,
  37459. 0xb16477e0,
  37460. 0xbf6d7aeb,
  37461. 0x955259da,
  37462. 0x9b5b54d1,
  37463. 0x894043cc,
  37464. 0x87494ec7,
  37465. 0xdd3e05ae,
  37466. 0xd33708a5,
  37467. 0xc12c1fb8,
  37468. 0xcf2512b3,
  37469. 0xe51a3182,
  37470. 0xeb133c89,
  37471. 0xf9082b94,
  37472. 0xf701269f,
  37473. 0x4de6bd46,
  37474. 0x43efb04d,
  37475. 0x51f4a750,
  37476. 0x5ffdaa5b,
  37477. 0x75c2896a,
  37478. 0x7bcb8461,
  37479. 0x69d0937c,
  37480. 0x67d99e77,
  37481. 0x3daed51e,
  37482. 0x33a7d815,
  37483. 0x21bccf08,
  37484. 0x2fb5c203,
  37485. 0x058ae132,
  37486. 0x0b83ec39,
  37487. 0x1998fb24,
  37488. 0x1791f62f,
  37489. 0x764dd68d,
  37490. 0x7844db86,
  37491. 0x6a5fcc9b,
  37492. 0x6456c190,
  37493. 0x4e69e2a1,
  37494. 0x4060efaa,
  37495. 0x527bf8b7,
  37496. 0x5c72f5bc,
  37497. 0x0605bed5,
  37498. 0x080cb3de,
  37499. 0x1a17a4c3,
  37500. 0x141ea9c8,
  37501. 0x3e218af9,
  37502. 0x302887f2,
  37503. 0x223390ef,
  37504. 0x2c3a9de4,
  37505. 0x96dd063d,
  37506. 0x98d40b36,
  37507. 0x8acf1c2b,
  37508. 0x84c61120,
  37509. 0xaef93211,
  37510. 0xa0f03f1a,
  37511. 0xb2eb2807,
  37512. 0xbce2250c,
  37513. 0xe6956e65,
  37514. 0xe89c636e,
  37515. 0xfa877473,
  37516. 0xf48e7978,
  37517. 0xdeb15a49,
  37518. 0xd0b85742,
  37519. 0xc2a3405f,
  37520. 0xccaa4d54,
  37521. 0x41ecdaf7,
  37522. 0x4fe5d7fc,
  37523. 0x5dfec0e1,
  37524. 0x53f7cdea,
  37525. 0x79c8eedb,
  37526. 0x77c1e3d0,
  37527. 0x65daf4cd,
  37528. 0x6bd3f9c6,
  37529. 0x31a4b2af,
  37530. 0x3fadbfa4,
  37531. 0x2db6a8b9,
  37532. 0x23bfa5b2,
  37533. 0x09808683,
  37534. 0x07898b88,
  37535. 0x15929c95,
  37536. 0x1b9b919e,
  37537. 0xa17c0a47,
  37538. 0xaf75074c,
  37539. 0xbd6e1051,
  37540. 0xb3671d5a,
  37541. 0x99583e6b,
  37542. 0x97513360,
  37543. 0x854a247d,
  37544. 0x8b432976,
  37545. 0xd134621f,
  37546. 0xdf3d6f14,
  37547. 0xcd267809,
  37548. 0xc32f7502,
  37549. 0xe9105633,
  37550. 0xe7195b38,
  37551. 0xf5024c25,
  37552. 0xfb0b412e,
  37553. 0x9ad7618c,
  37554. 0x94de6c87,
  37555. 0x86c57b9a,
  37556. 0x88cc7691,
  37557. 0xa2f355a0,
  37558. 0xacfa58ab,
  37559. 0xbee14fb6,
  37560. 0xb0e842bd,
  37561. 0xea9f09d4,
  37562. 0xe49604df,
  37563. 0xf68d13c2,
  37564. 0xf8841ec9,
  37565. 0xd2bb3df8,
  37566. 0xdcb230f3,
  37567. 0xcea927ee,
  37568. 0xc0a02ae5,
  37569. 0x7a47b13c,
  37570. 0x744ebc37,
  37571. 0x6655ab2a,
  37572. 0x685ca621,
  37573. 0x42638510,
  37574. 0x4c6a881b,
  37575. 0x5e719f06,
  37576. 0x5078920d,
  37577. 0x0a0fd964,
  37578. 0x0406d46f,
  37579. 0x161dc372,
  37580. 0x1814ce79,
  37581. 0x322bed48,
  37582. 0x3c22e043,
  37583. 0x2e39f75e,
  37584. 0x2030fa55,
  37585. 0xec9ab701,
  37586. 0xe293ba0a,
  37587. 0xf088ad17,
  37588. 0xfe81a01c,
  37589. 0xd4be832d,
  37590. 0xdab78e26,
  37591. 0xc8ac993b,
  37592. 0xc6a59430,
  37593. 0x9cd2df59,
  37594. 0x92dbd252,
  37595. 0x80c0c54f,
  37596. 0x8ec9c844,
  37597. 0xa4f6eb75,
  37598. 0xaaffe67e,
  37599. 0xb8e4f163,
  37600. 0xb6edfc68,
  37601. 0x0c0a67b1,
  37602. 0x02036aba,
  37603. 0x10187da7,
  37604. 0x1e1170ac,
  37605. 0x342e539d,
  37606. 0x3a275e96,
  37607. 0x283c498b,
  37608. 0x26354480,
  37609. 0x7c420fe9,
  37610. 0x724b02e2,
  37611. 0x605015ff,
  37612. 0x6e5918f4,
  37613. 0x44663bc5,
  37614. 0x4a6f36ce,
  37615. 0x587421d3,
  37616. 0x567d2cd8,
  37617. 0x37a10c7a,
  37618. 0x39a80171,
  37619. 0x2bb3166c,
  37620. 0x25ba1b67,
  37621. 0x0f853856,
  37622. 0x018c355d,
  37623. 0x13972240,
  37624. 0x1d9e2f4b,
  37625. 0x47e96422,
  37626. 0x49e06929,
  37627. 0x5bfb7e34,
  37628. 0x55f2733f,
  37629. 0x7fcd500e,
  37630. 0x71c45d05,
  37631. 0x63df4a18,
  37632. 0x6dd64713,
  37633. 0xd731dcca,
  37634. 0xd938d1c1,
  37635. 0xcb23c6dc,
  37636. 0xc52acbd7,
  37637. 0xef15e8e6,
  37638. 0xe11ce5ed,
  37639. 0xf307f2f0,
  37640. 0xfd0efffb,
  37641. 0xa779b492,
  37642. 0xa970b999,
  37643. 0xbb6bae84,
  37644. 0xb562a38f,
  37645. 0x9f5d80be,
  37646. 0x91548db5,
  37647. 0x834f9aa8,
  37648. 0x8d4697a3
  37649. ]);
  37650. function expandKey256(cipherKey) {
  37651. var b = 240, result = new Uint8Array(b);
  37652. var r = 1;
  37653. result.set(cipherKey);
  37654. for (var j = 32, i = 1; j < b; ++i) {
  37655. if (j % 32 === 16) {
  37656. t1 = s[t1];
  37657. t2 = s[t2];
  37658. t3 = s[t3];
  37659. t4 = s[t4];
  37660. } else if (j % 32 === 0) {
  37661. // RotWord
  37662. var t1 = result[j - 3], t2 = result[j - 2], t3 = result[j - 1], t4 = result[j - 4];
  37663. // SubWord
  37664. t1 = s[t1];
  37665. t2 = s[t2];
  37666. t3 = s[t3];
  37667. t4 = s[t4];
  37668. // Rcon
  37669. t1 = t1 ^ r;
  37670. if ((r <<= 1) >= 256) {
  37671. r = (r ^ 0x1b) & 0xFF;
  37672. }
  37673. }
  37674. for (var n = 0; n < 4; ++n) {
  37675. result[j] = t1 ^= result[j - 32];
  37676. j++;
  37677. result[j] = t2 ^= result[j - 32];
  37678. j++;
  37679. result[j] = t3 ^= result[j - 32];
  37680. j++;
  37681. result[j] = t4 ^= result[j - 32];
  37682. j++;
  37683. }
  37684. }
  37685. return result;
  37686. }
  37687. function decrypt256(input, key) {
  37688. var state = new Uint8Array(16);
  37689. state.set(input);
  37690. var i, j, k;
  37691. var t, u, v;
  37692. // AddRoundKey
  37693. for (j = 0, k = 224; j < 16; ++j, ++k) {
  37694. state[j] ^= key[k];
  37695. }
  37696. for (i = 13; i >= 1; --i) {
  37697. // InvShiftRows
  37698. t = state[13];
  37699. state[13] = state[9];
  37700. state[9] = state[5];
  37701. state[5] = state[1];
  37702. state[1] = t;
  37703. t = state[14];
  37704. u = state[10];
  37705. state[14] = state[6];
  37706. state[10] = state[2];
  37707. state[6] = t;
  37708. state[2] = u;
  37709. t = state[15];
  37710. u = state[11];
  37711. v = state[7];
  37712. state[15] = state[3];
  37713. state[11] = t;
  37714. state[7] = u;
  37715. state[3] = v;
  37716. // InvSubBytes
  37717. for (j = 0; j < 16; ++j) {
  37718. state[j] = inv_s[state[j]];
  37719. }
  37720. // AddRoundKey
  37721. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  37722. state[j] ^= key[k];
  37723. }
  37724. // InvMixColumns
  37725. for (j = 0; j < 16; j += 4) {
  37726. var s0 = mix[state[j]], s1 = mix[state[j + 1]], s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  37727. t = s0 ^ s1 >>> 8 ^ s1 << 24 ^ s2 >>> 16 ^ s2 << 16 ^ s3 >>> 24 ^ s3 << 8;
  37728. state[j] = t >>> 24 & 0xFF;
  37729. state[j + 1] = t >> 16 & 0xFF;
  37730. state[j + 2] = t >> 8 & 0xFF;
  37731. state[j + 3] = t & 0xFF;
  37732. }
  37733. }
  37734. // InvShiftRows
  37735. t = state[13];
  37736. state[13] = state[9];
  37737. state[9] = state[5];
  37738. state[5] = state[1];
  37739. state[1] = t;
  37740. t = state[14];
  37741. u = state[10];
  37742. state[14] = state[6];
  37743. state[10] = state[2];
  37744. state[6] = t;
  37745. state[2] = u;
  37746. t = state[15];
  37747. u = state[11];
  37748. v = state[7];
  37749. state[15] = state[3];
  37750. state[11] = t;
  37751. state[7] = u;
  37752. state[3] = v;
  37753. for (j = 0; j < 16; ++j) {
  37754. // InvSubBytes
  37755. state[j] = inv_s[state[j]];
  37756. // AddRoundKey
  37757. state[j] ^= key[j];
  37758. }
  37759. return state;
  37760. }
  37761. function encrypt256(input, key) {
  37762. var t, u, v, k;
  37763. var state = new Uint8Array(16);
  37764. state.set(input);
  37765. for (j = 0; j < 16; ++j) {
  37766. // AddRoundKey
  37767. state[j] ^= key[j];
  37768. }
  37769. for (i = 1; i < 14; i++) {
  37770. //SubBytes
  37771. for (j = 0; j < 16; ++j) {
  37772. state[j] = s[state[j]];
  37773. }
  37774. //ShiftRows
  37775. v = state[1];
  37776. state[1] = state[5];
  37777. state[5] = state[9];
  37778. state[9] = state[13];
  37779. state[13] = v;
  37780. v = state[2];
  37781. u = state[6];
  37782. state[2] = state[10];
  37783. state[6] = state[14];
  37784. state[10] = v;
  37785. state[14] = u;
  37786. v = state[3];
  37787. u = state[7];
  37788. t = state[11];
  37789. state[3] = state[15];
  37790. state[7] = v;
  37791. state[11] = u;
  37792. state[15] = t;
  37793. //MixColumns
  37794. for (var j = 0; j < 16; j += 4) {
  37795. var s0 = state[j + 0], s1 = state[j + 1];
  37796. var s2 = state[j + 2], s3 = state[j + 3];
  37797. t = s0 ^ s1 ^ s2 ^ s3;
  37798. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  37799. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  37800. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  37801. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  37802. }
  37803. //AddRoundKey
  37804. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  37805. state[j] ^= key[k];
  37806. }
  37807. }
  37808. //SubBytes
  37809. for (j = 0; j < 16; ++j) {
  37810. state[j] = s[state[j]];
  37811. }
  37812. //ShiftRows
  37813. v = state[1];
  37814. state[1] = state[5];
  37815. state[5] = state[9];
  37816. state[9] = state[13];
  37817. state[13] = v;
  37818. v = state[2];
  37819. u = state[6];
  37820. state[2] = state[10];
  37821. state[6] = state[14];
  37822. state[10] = v;
  37823. state[14] = u;
  37824. v = state[3];
  37825. u = state[7];
  37826. t = state[11];
  37827. state[3] = state[15];
  37828. state[7] = v;
  37829. state[11] = u;
  37830. state[15] = t;
  37831. //AddRoundKey
  37832. for (j = 0, k = 224; j < 16; ++j, ++k) {
  37833. state[j] ^= key[k];
  37834. }
  37835. return state;
  37836. }
  37837. function AES256Cipher(key) {
  37838. this.key = expandKey256(key);
  37839. this.buffer = new Uint8Array(16);
  37840. this.bufferPosition = 0;
  37841. }
  37842. function decryptBlock2(data, finalize) {
  37843. var i, j, ii, sourceLength = data.length, buffer = this.buffer, bufferLength = this.bufferPosition, result = [], iv = this.iv;
  37844. for (i = 0; i < sourceLength; ++i) {
  37845. buffer[bufferLength] = data[i];
  37846. ++bufferLength;
  37847. if (bufferLength < 16) {
  37848. continue;
  37849. }
  37850. // buffer is full, decrypting
  37851. var plain = decrypt256(buffer, this.key);
  37852. // xor-ing the IV vector to get plain text
  37853. for (j = 0; j < 16; ++j) {
  37854. plain[j] ^= iv[j];
  37855. }
  37856. iv = buffer;
  37857. result.push(plain);
  37858. buffer = new Uint8Array(16);
  37859. bufferLength = 0;
  37860. }
  37861. // saving incomplete buffer
  37862. this.buffer = buffer;
  37863. this.bufferLength = bufferLength;
  37864. this.iv = iv;
  37865. if (result.length === 0) {
  37866. return new Uint8Array([]);
  37867. }
  37868. // combining plain text blocks into one
  37869. var outputLength = 16 * result.length;
  37870. if (finalize) {
  37871. // undo a padding that is described in RFC 2898
  37872. var lastBlock = result[result.length - 1];
  37873. var psLen = lastBlock[15];
  37874. if (psLen <= 16) {
  37875. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  37876. if (lastBlock[i] !== psLen) {
  37877. // Invalid padding, assume that the block has no padding.
  37878. psLen = 0;
  37879. break;
  37880. }
  37881. }
  37882. outputLength -= psLen;
  37883. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  37884. }
  37885. }
  37886. var output = new Uint8Array(outputLength);
  37887. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  37888. output.set(result[i], j);
  37889. }
  37890. return output;
  37891. }
  37892. AES256Cipher.prototype = {
  37893. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  37894. var i, sourceLength = data.length;
  37895. var buffer = this.buffer, bufferLength = this.bufferPosition;
  37896. // if not supplied an IV wait for IV values
  37897. // they are at the start of the stream
  37898. if (iv) {
  37899. this.iv = iv;
  37900. } else {
  37901. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  37902. buffer[bufferLength] = data[i];
  37903. }
  37904. if (bufferLength < 16) {
  37905. //need more data
  37906. this.bufferLength = bufferLength;
  37907. return new Uint8Array([]);
  37908. }
  37909. this.iv = buffer;
  37910. data = data.subarray(16);
  37911. }
  37912. this.buffer = new Uint8Array(16);
  37913. this.bufferLength = 0;
  37914. // starting decryption
  37915. this.decryptBlock = decryptBlock2;
  37916. return this.decryptBlock(data, finalize);
  37917. },
  37918. encrypt: function AES256Cipher_encrypt(data, iv) {
  37919. var i, j, ii, sourceLength = data.length, buffer = this.buffer, bufferLength = this.bufferPosition, result = [];
  37920. if (!iv) {
  37921. iv = new Uint8Array(16);
  37922. }
  37923. for (i = 0; i < sourceLength; ++i) {
  37924. buffer[bufferLength] = data[i];
  37925. ++bufferLength;
  37926. if (bufferLength < 16) {
  37927. continue;
  37928. }
  37929. for (j = 0; j < 16; ++j) {
  37930. buffer[j] ^= iv[j];
  37931. }
  37932. // buffer is full, encrypting
  37933. var cipher = encrypt256(buffer, this.key);
  37934. this.iv = cipher;
  37935. result.push(cipher);
  37936. buffer = new Uint8Array(16);
  37937. bufferLength = 0;
  37938. }
  37939. // saving incomplete buffer
  37940. this.buffer = buffer;
  37941. this.bufferLength = bufferLength;
  37942. this.iv = iv;
  37943. if (result.length === 0) {
  37944. return new Uint8Array([]);
  37945. }
  37946. // combining plain text blocks into one
  37947. var outputLength = 16 * result.length;
  37948. var output = new Uint8Array(outputLength);
  37949. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  37950. output.set(result[i], j);
  37951. }
  37952. return output;
  37953. }
  37954. };
  37955. return AES256Cipher;
  37956. }();
  37957. var PDF17 = function PDF17Closure() {
  37958. function compareByteArrays(array1, array2) {
  37959. if (array1.length !== array2.length) {
  37960. return false;
  37961. }
  37962. for (var i = 0; i < array1.length; i++) {
  37963. if (array1[i] !== array2[i]) {
  37964. return false;
  37965. }
  37966. }
  37967. return true;
  37968. }
  37969. function PDF17() {
  37970. }
  37971. PDF17.prototype = {
  37972. checkOwnerPassword: function PDF17_checkOwnerPassword(password, ownerValidationSalt, userBytes, ownerPassword) {
  37973. var hashData = new Uint8Array(password.length + 56);
  37974. hashData.set(password, 0);
  37975. hashData.set(ownerValidationSalt, password.length);
  37976. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  37977. var result = calculateSHA256(hashData, 0, hashData.length);
  37978. return compareByteArrays(result, ownerPassword);
  37979. },
  37980. checkUserPassword: function PDF17_checkUserPassword(password, userValidationSalt, userPassword) {
  37981. var hashData = new Uint8Array(password.length + 8);
  37982. hashData.set(password, 0);
  37983. hashData.set(userValidationSalt, password.length);
  37984. var result = calculateSHA256(hashData, 0, hashData.length);
  37985. return compareByteArrays(result, userPassword);
  37986. },
  37987. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes, ownerEncryption) {
  37988. var hashData = new Uint8Array(password.length + 56);
  37989. hashData.set(password, 0);
  37990. hashData.set(ownerKeySalt, password.length);
  37991. hashData.set(userBytes, password.length + ownerKeySalt.length);
  37992. var key = calculateSHA256(hashData, 0, hashData.length);
  37993. var cipher = new AES256Cipher(key);
  37994. return cipher.decryptBlock(ownerEncryption, false, new Uint8Array(16));
  37995. },
  37996. getUserKey: function PDF17_getUserKey(password, userKeySalt, userEncryption) {
  37997. var hashData = new Uint8Array(password.length + 8);
  37998. hashData.set(password, 0);
  37999. hashData.set(userKeySalt, password.length);
  38000. //key is the decryption key for the UE string
  38001. var key = calculateSHA256(hashData, 0, hashData.length);
  38002. var cipher = new AES256Cipher(key);
  38003. return cipher.decryptBlock(userEncryption, false, new Uint8Array(16));
  38004. }
  38005. };
  38006. return PDF17;
  38007. }();
  38008. var PDF20 = function PDF20Closure() {
  38009. function concatArrays(array1, array2) {
  38010. var t = new Uint8Array(array1.length + array2.length);
  38011. t.set(array1, 0);
  38012. t.set(array2, array1.length);
  38013. return t;
  38014. }
  38015. function calculatePDF20Hash(password, input, userBytes) {
  38016. //This refers to Algorithm 2.B as defined in ISO 32000-2
  38017. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  38018. var e = [0];
  38019. var i = 0;
  38020. while (i < 64 || e[e.length - 1] > i - 32) {
  38021. var arrayLength = password.length + k.length + userBytes.length;
  38022. var k1 = new Uint8Array(arrayLength * 64);
  38023. var array = concatArrays(password, k);
  38024. array = concatArrays(array, userBytes);
  38025. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  38026. k1.set(array, pos);
  38027. }
  38028. //AES128 CBC NO PADDING with
  38029. //first 16 bytes of k as the key and the second 16 as the iv.
  38030. var cipher = new AES128Cipher(k.subarray(0, 16));
  38031. e = cipher.encrypt(k1, k.subarray(16, 32));
  38032. //Now we have to take the first 16 bytes of an unsigned
  38033. //big endian integer... and compute the remainder
  38034. //modulo 3.... That is a fairly large number and
  38035. //JavaScript isn't going to handle that well...
  38036. //So we're using a trick that allows us to perform
  38037. //modulo math byte by byte
  38038. var remainder = 0;
  38039. for (var z = 0; z < 16; z++) {
  38040. remainder *= 256 % 3;
  38041. remainder %= 3;
  38042. remainder += (e[z] >>> 0) % 3;
  38043. remainder %= 3;
  38044. }
  38045. if (remainder === 0) {
  38046. k = calculateSHA256(e, 0, e.length);
  38047. } else if (remainder === 1) {
  38048. k = calculateSHA384(e, 0, e.length);
  38049. } else if (remainder === 2) {
  38050. k = calculateSHA512(e, 0, e.length);
  38051. }
  38052. i++;
  38053. }
  38054. return k.subarray(0, 32);
  38055. }
  38056. function PDF20() {
  38057. }
  38058. function compareByteArrays(array1, array2) {
  38059. if (array1.length !== array2.length) {
  38060. return false;
  38061. }
  38062. for (var i = 0; i < array1.length; i++) {
  38063. if (array1[i] !== array2[i]) {
  38064. return false;
  38065. }
  38066. }
  38067. return true;
  38068. }
  38069. PDF20.prototype = {
  38070. hash: function PDF20_hash(password, concatBytes, userBytes) {
  38071. return calculatePDF20Hash(password, concatBytes, userBytes);
  38072. },
  38073. checkOwnerPassword: function PDF20_checkOwnerPassword(password, ownerValidationSalt, userBytes, ownerPassword) {
  38074. var hashData = new Uint8Array(password.length + 56);
  38075. hashData.set(password, 0);
  38076. hashData.set(ownerValidationSalt, password.length);
  38077. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  38078. var result = calculatePDF20Hash(password, hashData, userBytes);
  38079. return compareByteArrays(result, ownerPassword);
  38080. },
  38081. checkUserPassword: function PDF20_checkUserPassword(password, userValidationSalt, userPassword) {
  38082. var hashData = new Uint8Array(password.length + 8);
  38083. hashData.set(password, 0);
  38084. hashData.set(userValidationSalt, password.length);
  38085. var result = calculatePDF20Hash(password, hashData, []);
  38086. return compareByteArrays(result, userPassword);
  38087. },
  38088. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes, ownerEncryption) {
  38089. var hashData = new Uint8Array(password.length + 56);
  38090. hashData.set(password, 0);
  38091. hashData.set(ownerKeySalt, password.length);
  38092. hashData.set(userBytes, password.length + ownerKeySalt.length);
  38093. var key = calculatePDF20Hash(password, hashData, userBytes);
  38094. var cipher = new AES256Cipher(key);
  38095. return cipher.decryptBlock(ownerEncryption, false, new Uint8Array(16));
  38096. },
  38097. getUserKey: function PDF20_getUserKey(password, userKeySalt, userEncryption) {
  38098. var hashData = new Uint8Array(password.length + 8);
  38099. hashData.set(password, 0);
  38100. hashData.set(userKeySalt, password.length);
  38101. //key is the decryption key for the UE string
  38102. var key = calculatePDF20Hash(password, hashData, []);
  38103. var cipher = new AES256Cipher(key);
  38104. return cipher.decryptBlock(userEncryption, false, new Uint8Array(16));
  38105. }
  38106. };
  38107. return PDF20;
  38108. }();
  38109. var CipherTransform = function CipherTransformClosure() {
  38110. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  38111. this.stringCipherConstructor = stringCipherConstructor;
  38112. this.streamCipherConstructor = streamCipherConstructor;
  38113. }
  38114. CipherTransform.prototype = {
  38115. createStream: function CipherTransform_createStream(stream, length) {
  38116. var cipher = new this.streamCipherConstructor();
  38117. return new DecryptStream(stream, length, function cipherTransformDecryptStream(data, finalize) {
  38118. return cipher.decryptBlock(data, finalize);
  38119. });
  38120. },
  38121. decryptString: function CipherTransform_decryptString(s) {
  38122. var cipher = new this.stringCipherConstructor();
  38123. var data = stringToBytes(s);
  38124. data = cipher.decryptBlock(data, true);
  38125. return bytesToString(data);
  38126. }
  38127. };
  38128. return CipherTransform;
  38129. }();
  38130. var CipherTransformFactory = function CipherTransformFactoryClosure() {
  38131. var defaultPasswordBytes = new Uint8Array([
  38132. 0x28,
  38133. 0xBF,
  38134. 0x4E,
  38135. 0x5E,
  38136. 0x4E,
  38137. 0x75,
  38138. 0x8A,
  38139. 0x41,
  38140. 0x64,
  38141. 0x00,
  38142. 0x4E,
  38143. 0x56,
  38144. 0xFF,
  38145. 0xFA,
  38146. 0x01,
  38147. 0x08,
  38148. 0x2E,
  38149. 0x2E,
  38150. 0x00,
  38151. 0xB6,
  38152. 0xD0,
  38153. 0x68,
  38154. 0x3E,
  38155. 0x80,
  38156. 0x2F,
  38157. 0x0C,
  38158. 0xA9,
  38159. 0xFE,
  38160. 0x64,
  38161. 0x53,
  38162. 0x69,
  38163. 0x7A
  38164. ]);
  38165. function createEncryptionKey20(revision, password, ownerPassword, ownerValidationSalt, ownerKeySalt, uBytes, userPassword, userValidationSalt, userKeySalt, ownerEncryption, userEncryption, perms) {
  38166. if (password) {
  38167. var passwordLength = Math.min(127, password.length);
  38168. password = password.subarray(0, passwordLength);
  38169. } else {
  38170. password = [];
  38171. }
  38172. var pdfAlgorithm;
  38173. if (revision === 6) {
  38174. pdfAlgorithm = new PDF20();
  38175. } else {
  38176. pdfAlgorithm = new PDF17();
  38177. }
  38178. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt, userPassword)) {
  38179. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  38180. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt, uBytes, ownerPassword)) {
  38181. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes, ownerEncryption);
  38182. }
  38183. return null;
  38184. }
  38185. function prepareKeyData(fileId, password, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata) {
  38186. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  38187. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  38188. if (password) {
  38189. n = Math.min(32, password.length);
  38190. for (; i < n; ++i) {
  38191. hashData[i] = password[i];
  38192. }
  38193. }
  38194. j = 0;
  38195. while (i < 32) {
  38196. hashData[i++] = defaultPasswordBytes[j++];
  38197. }
  38198. // as now the padded password in the hashData[0..i]
  38199. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  38200. hashData[i++] = ownerPassword[j];
  38201. }
  38202. hashData[i++] = flags & 0xFF;
  38203. hashData[i++] = flags >> 8 & 0xFF;
  38204. hashData[i++] = flags >> 16 & 0xFF;
  38205. hashData[i++] = flags >>> 24 & 0xFF;
  38206. for (j = 0, n = fileId.length; j < n; ++j) {
  38207. hashData[i++] = fileId[j];
  38208. }
  38209. if (revision >= 4 && !encryptMetadata) {
  38210. hashData[i++] = 0xFF;
  38211. hashData[i++] = 0xFF;
  38212. hashData[i++] = 0xFF;
  38213. hashData[i++] = 0xFF;
  38214. }
  38215. var hash = calculateMD5(hashData, 0, i);
  38216. var keyLengthInBytes = keyLength >> 3;
  38217. if (revision >= 3) {
  38218. for (j = 0; j < 50; ++j) {
  38219. hash = calculateMD5(hash, 0, keyLengthInBytes);
  38220. }
  38221. }
  38222. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  38223. var cipher, checkData;
  38224. if (revision >= 3) {
  38225. for (i = 0; i < 32; ++i) {
  38226. hashData[i] = defaultPasswordBytes[i];
  38227. }
  38228. for (j = 0, n = fileId.length; j < n; ++j) {
  38229. hashData[i++] = fileId[j];
  38230. }
  38231. cipher = new ARCFourCipher(encryptionKey);
  38232. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  38233. n = encryptionKey.length;
  38234. var derivedKey = new Uint8Array(n), k;
  38235. for (j = 1; j <= 19; ++j) {
  38236. for (k = 0; k < n; ++k) {
  38237. derivedKey[k] = encryptionKey[k] ^ j;
  38238. }
  38239. cipher = new ARCFourCipher(derivedKey);
  38240. checkData = cipher.encryptBlock(checkData);
  38241. }
  38242. for (j = 0, n = checkData.length; j < n; ++j) {
  38243. if (userPassword[j] !== checkData[j]) {
  38244. return null;
  38245. }
  38246. }
  38247. } else {
  38248. cipher = new ARCFourCipher(encryptionKey);
  38249. checkData = cipher.encryptBlock(defaultPasswordBytes);
  38250. for (j = 0, n = checkData.length; j < n; ++j) {
  38251. if (userPassword[j] !== checkData[j]) {
  38252. return null;
  38253. }
  38254. }
  38255. }
  38256. return encryptionKey;
  38257. }
  38258. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  38259. var hashData = new Uint8Array(32), i = 0, j, n;
  38260. n = Math.min(32, password.length);
  38261. for (; i < n; ++i) {
  38262. hashData[i] = password[i];
  38263. }
  38264. j = 0;
  38265. while (i < 32) {
  38266. hashData[i++] = defaultPasswordBytes[j++];
  38267. }
  38268. var hash = calculateMD5(hashData, 0, i);
  38269. var keyLengthInBytes = keyLength >> 3;
  38270. if (revision >= 3) {
  38271. for (j = 0; j < 50; ++j) {
  38272. hash = calculateMD5(hash, 0, hash.length);
  38273. }
  38274. }
  38275. var cipher, userPassword;
  38276. if (revision >= 3) {
  38277. userPassword = ownerPassword;
  38278. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  38279. for (j = 19; j >= 0; j--) {
  38280. for (k = 0; k < keyLengthInBytes; ++k) {
  38281. derivedKey[k] = hash[k] ^ j;
  38282. }
  38283. cipher = new ARCFourCipher(derivedKey);
  38284. userPassword = cipher.encryptBlock(userPassword);
  38285. }
  38286. } else {
  38287. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  38288. userPassword = cipher.encryptBlock(ownerPassword);
  38289. }
  38290. return userPassword;
  38291. }
  38292. var identityName = Name.get('Identity');
  38293. function CipherTransformFactory(dict, fileId, password) {
  38294. var filter = dict.get('Filter');
  38295. if (!isName(filter, 'Standard')) {
  38296. error('unknown encryption method');
  38297. }
  38298. this.dict = dict;
  38299. var algorithm = dict.get('V');
  38300. if (!isInt(algorithm) || algorithm !== 1 && algorithm !== 2 && algorithm !== 4 && algorithm !== 5) {
  38301. error('unsupported encryption algorithm');
  38302. }
  38303. this.algorithm = algorithm;
  38304. var keyLength = dict.get('Length');
  38305. if (!keyLength) {
  38306. // Spec asks to rely on encryption dictionary's Length entry, however
  38307. // some PDFs don't have it. Trying to recover.
  38308. if (algorithm <= 3) {
  38309. // For 1 and 2 it's fixed to 40-bit, for 3 40-bit is a minimal value.
  38310. keyLength = 40;
  38311. } else {
  38312. // Trying to find default handler -- it usually has Length.
  38313. var cfDict = dict.get('CF');
  38314. var streamCryptoName = dict.get('StmF');
  38315. if (isDict(cfDict) && isName(streamCryptoName)) {
  38316. cfDict.suppressEncryption = true;
  38317. // See comment below.
  38318. var handlerDict = cfDict.get(streamCryptoName.name);
  38319. keyLength = handlerDict && handlerDict.get('Length') || 128;
  38320. if (keyLength < 40) {
  38321. // Sometimes it's incorrect value of bits, generators specify bytes.
  38322. keyLength <<= 3;
  38323. }
  38324. }
  38325. }
  38326. }
  38327. if (!isInt(keyLength) || keyLength < 40 || keyLength % 8 !== 0) {
  38328. error('invalid key length');
  38329. }
  38330. // prepare keys
  38331. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  38332. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  38333. var flags = dict.get('P');
  38334. var revision = dict.get('R');
  38335. // meaningful when V is 4 or 5
  38336. var encryptMetadata = (algorithm === 4 || algorithm === 5) && dict.get('EncryptMetadata') !== false;
  38337. this.encryptMetadata = encryptMetadata;
  38338. var fileIdBytes = stringToBytes(fileId);
  38339. var passwordBytes;
  38340. if (password) {
  38341. if (revision === 6) {
  38342. try {
  38343. password = utf8StringToString(password);
  38344. } catch (ex) {
  38345. warn('CipherTransformFactory: ' + 'Unable to convert UTF8 encoded password.');
  38346. }
  38347. }
  38348. passwordBytes = stringToBytes(password);
  38349. }
  38350. var encryptionKey;
  38351. if (algorithm !== 5) {
  38352. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata);
  38353. } else {
  38354. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  38355. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  38356. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  38357. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  38358. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  38359. var ownerEncryption = stringToBytes(dict.get('OE'));
  38360. var userEncryption = stringToBytes(dict.get('UE'));
  38361. var perms = stringToBytes(dict.get('Perms'));
  38362. encryptionKey = createEncryptionKey20(revision, passwordBytes, ownerPassword, ownerValidationSalt, ownerKeySalt, uBytes, userPassword, userValidationSalt, userKeySalt, ownerEncryption, userEncryption, perms);
  38363. }
  38364. if (!encryptionKey && !password) {
  38365. throw new PasswordException('No password given', PasswordResponses.NEED_PASSWORD);
  38366. } else if (!encryptionKey && password) {
  38367. // Attempting use the password as an owner password
  38368. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword, revision, keyLength);
  38369. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata);
  38370. }
  38371. if (!encryptionKey) {
  38372. throw new PasswordException('Incorrect Password', PasswordResponses.INCORRECT_PASSWORD);
  38373. }
  38374. this.encryptionKey = encryptionKey;
  38375. if (algorithm >= 4) {
  38376. var cf = dict.get('CF');
  38377. if (isDict(cf)) {
  38378. // The 'CF' dictionary itself should not be encrypted, and by setting
  38379. // `suppressEncryption` we can prevent an infinite loop inside of
  38380. // `XRef_fetchUncompressed` if the dictionary contains indirect objects
  38381. // (fixes issue7665.pdf).
  38382. cf.suppressEncryption = true;
  38383. }
  38384. this.cf = cf;
  38385. this.stmf = dict.get('StmF') || identityName;
  38386. this.strf = dict.get('StrF') || identityName;
  38387. this.eff = dict.get('EFF') || this.stmf;
  38388. }
  38389. }
  38390. function buildObjectKey(num, gen, encryptionKey, isAes) {
  38391. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  38392. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  38393. key[i] = encryptionKey[i];
  38394. }
  38395. key[i++] = num & 0xFF;
  38396. key[i++] = num >> 8 & 0xFF;
  38397. key[i++] = num >> 16 & 0xFF;
  38398. key[i++] = gen & 0xFF;
  38399. key[i++] = gen >> 8 & 0xFF;
  38400. if (isAes) {
  38401. key[i++] = 0x73;
  38402. key[i++] = 0x41;
  38403. key[i++] = 0x6C;
  38404. key[i++] = 0x54;
  38405. }
  38406. var hash = calculateMD5(key, 0, i);
  38407. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  38408. }
  38409. function buildCipherConstructor(cf, name, num, gen, key) {
  38410. assert(isName(name), 'Invalid crypt filter name.');
  38411. var cryptFilter = cf.get(name.name);
  38412. var cfm;
  38413. if (cryptFilter !== null && cryptFilter !== undefined) {
  38414. cfm = cryptFilter.get('CFM');
  38415. }
  38416. if (!cfm || cfm.name === 'None') {
  38417. return function cipherTransformFactoryBuildCipherConstructorNone() {
  38418. return new NullCipher();
  38419. };
  38420. }
  38421. if ('V2' === cfm.name) {
  38422. return function cipherTransformFactoryBuildCipherConstructorV2() {
  38423. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  38424. };
  38425. }
  38426. if ('AESV2' === cfm.name) {
  38427. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  38428. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  38429. };
  38430. }
  38431. if ('AESV3' === cfm.name) {
  38432. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  38433. return new AES256Cipher(key);
  38434. };
  38435. }
  38436. error('Unknown crypto method');
  38437. }
  38438. CipherTransformFactory.prototype = {
  38439. createCipherTransform: function CipherTransformFactory_createCipherTransform(num, gen) {
  38440. if (this.algorithm === 4 || this.algorithm === 5) {
  38441. return new CipherTransform(buildCipherConstructor(this.cf, this.stmf, num, gen, this.encryptionKey), buildCipherConstructor(this.cf, this.strf, num, gen, this.encryptionKey));
  38442. }
  38443. // algorithms 1 and 2
  38444. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  38445. var cipherConstructor = function buildCipherCipherConstructor() {
  38446. return new ARCFourCipher(key);
  38447. };
  38448. return new CipherTransform(cipherConstructor, cipherConstructor);
  38449. }
  38450. };
  38451. return CipherTransformFactory;
  38452. }();
  38453. exports.AES128Cipher = AES128Cipher;
  38454. exports.AES256Cipher = AES256Cipher;
  38455. exports.ARCFourCipher = ARCFourCipher;
  38456. exports.CipherTransformFactory = CipherTransformFactory;
  38457. exports.PDF17 = PDF17;
  38458. exports.PDF20 = PDF20;
  38459. exports.calculateMD5 = calculateMD5;
  38460. exports.calculateSHA256 = calculateSHA256;
  38461. exports.calculateSHA384 = calculateSHA384;
  38462. exports.calculateSHA512 = calculateSHA512;
  38463. }));
  38464. (function (root, factory) {
  38465. factory(root.pdfjsCoreFontRenderer = {}, root.pdfjsSharedUtil, root.pdfjsCoreStream, root.pdfjsCoreGlyphList, root.pdfjsCoreEncodings, root.pdfjsCoreCFFParser);
  38466. }(this, function (exports, sharedUtil, coreStream, coreGlyphList, coreEncodings, coreCFFParser) {
  38467. var Util = sharedUtil.Util;
  38468. var bytesToString = sharedUtil.bytesToString;
  38469. var error = sharedUtil.error;
  38470. var Stream = coreStream.Stream;
  38471. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  38472. var StandardEncoding = coreEncodings.StandardEncoding;
  38473. var CFFParser = coreCFFParser.CFFParser;
  38474. var FontRendererFactory = function FontRendererFactoryClosure() {
  38475. function getLong(data, offset) {
  38476. return data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3];
  38477. }
  38478. function getUshort(data, offset) {
  38479. return data[offset] << 8 | data[offset + 1];
  38480. }
  38481. function parseCmap(data, start, end) {
  38482. var offset = getUshort(data, start + 2) === 1 ? getLong(data, start + 8) : getLong(data, start + 16);
  38483. var format = getUshort(data, start + offset);
  38484. var length, ranges, p, i;
  38485. if (format === 4) {
  38486. length = getUshort(data, start + offset + 2);
  38487. var segCount = getUshort(data, start + offset + 6) >> 1;
  38488. p = start + offset + 14;
  38489. ranges = [];
  38490. for (i = 0; i < segCount; i++, p += 2) {
  38491. ranges[i] = { end: getUshort(data, p) };
  38492. }
  38493. p += 2;
  38494. for (i = 0; i < segCount; i++, p += 2) {
  38495. ranges[i].start = getUshort(data, p);
  38496. }
  38497. for (i = 0; i < segCount; i++, p += 2) {
  38498. ranges[i].idDelta = getUshort(data, p);
  38499. }
  38500. for (i = 0; i < segCount; i++, p += 2) {
  38501. var idOffset = getUshort(data, p);
  38502. if (idOffset === 0) {
  38503. continue;
  38504. }
  38505. ranges[i].ids = [];
  38506. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  38507. ranges[i].ids[j] = getUshort(data, p + idOffset);
  38508. idOffset += 2;
  38509. }
  38510. }
  38511. return ranges;
  38512. } else if (format === 12) {
  38513. length = getLong(data, start + offset + 4);
  38514. var groups = getLong(data, start + offset + 12);
  38515. p = start + offset + 16;
  38516. ranges = [];
  38517. for (i = 0; i < groups; i++) {
  38518. ranges.push({
  38519. start: getLong(data, p),
  38520. end: getLong(data, p + 4),
  38521. idDelta: getLong(data, p + 8) - getLong(data, p)
  38522. });
  38523. p += 12;
  38524. }
  38525. return ranges;
  38526. }
  38527. error('not supported cmap: ' + format);
  38528. }
  38529. function parseCff(data, start, end, seacAnalysisEnabled) {
  38530. var properties = {};
  38531. var parser = new CFFParser(new Stream(data, start, end - start), properties, seacAnalysisEnabled);
  38532. var cff = parser.parse();
  38533. return {
  38534. glyphs: cff.charStrings.objects,
  38535. subrs: cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex && cff.topDict.privateDict.subrsIndex.objects,
  38536. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  38537. };
  38538. }
  38539. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  38540. var itemSize, itemDecode;
  38541. if (isGlyphLocationsLong) {
  38542. itemSize = 4;
  38543. itemDecode = function fontItemDecodeLong(data, offset) {
  38544. return data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3];
  38545. };
  38546. } else {
  38547. itemSize = 2;
  38548. itemDecode = function fontItemDecode(data, offset) {
  38549. return data[offset] << 9 | data[offset + 1] << 1;
  38550. };
  38551. }
  38552. var glyphs = [];
  38553. var startOffset = itemDecode(loca, 0);
  38554. for (var j = itemSize; j < loca.length; j += itemSize) {
  38555. var endOffset = itemDecode(loca, j);
  38556. glyphs.push(glyf.subarray(startOffset, endOffset));
  38557. startOffset = endOffset;
  38558. }
  38559. return glyphs;
  38560. }
  38561. function lookupCmap(ranges, unicode) {
  38562. var code = unicode.charCodeAt(0), gid = 0;
  38563. var l = 0, r = ranges.length - 1;
  38564. while (l < r) {
  38565. var c = l + r + 1 >> 1;
  38566. if (code < ranges[c].start) {
  38567. r = c - 1;
  38568. } else {
  38569. l = c;
  38570. }
  38571. }
  38572. if (ranges[l].start <= code && code <= ranges[l].end) {
  38573. gid = ranges[l].idDelta + (ranges[l].ids ? ranges[l].ids[code - ranges[l].start] : code) & 0xFFFF;
  38574. }
  38575. return {
  38576. charCode: code,
  38577. glyphId: gid
  38578. };
  38579. }
  38580. function compileGlyf(code, cmds, font) {
  38581. function moveTo(x, y) {
  38582. cmds.push({
  38583. cmd: 'moveTo',
  38584. args: [
  38585. x,
  38586. y
  38587. ]
  38588. });
  38589. }
  38590. function lineTo(x, y) {
  38591. cmds.push({
  38592. cmd: 'lineTo',
  38593. args: [
  38594. x,
  38595. y
  38596. ]
  38597. });
  38598. }
  38599. function quadraticCurveTo(xa, ya, x, y) {
  38600. cmds.push({
  38601. cmd: 'quadraticCurveTo',
  38602. args: [
  38603. xa,
  38604. ya,
  38605. x,
  38606. y
  38607. ]
  38608. });
  38609. }
  38610. var i = 0;
  38611. var numberOfContours = (code[i] << 24 | code[i + 1] << 16) >> 16;
  38612. var flags;
  38613. var x = 0, y = 0;
  38614. i += 10;
  38615. if (numberOfContours < 0) {
  38616. // composite glyph
  38617. do {
  38618. flags = code[i] << 8 | code[i + 1];
  38619. var glyphIndex = code[i + 2] << 8 | code[i + 3];
  38620. i += 4;
  38621. var arg1, arg2;
  38622. if (flags & 0x01) {
  38623. arg1 = (code[i] << 24 | code[i + 1] << 16) >> 16;
  38624. arg2 = (code[i + 2] << 24 | code[i + 3] << 16) >> 16;
  38625. i += 4;
  38626. } else {
  38627. arg1 = code[i++];
  38628. arg2 = code[i++];
  38629. }
  38630. if (flags & 0x02) {
  38631. x = arg1;
  38632. y = arg2;
  38633. } else {
  38634. x = 0;
  38635. y = 0;
  38636. }
  38637. // TODO "they are points" ?
  38638. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  38639. if (flags & 0x08) {
  38640. scaleX = scaleY = (code[i] << 24 | code[i + 1] << 16) / 1073741824;
  38641. i += 2;
  38642. } else if (flags & 0x40) {
  38643. scaleX = (code[i] << 24 | code[i + 1] << 16) / 1073741824;
  38644. scaleY = (code[i + 2] << 24 | code[i + 3] << 16) / 1073741824;
  38645. i += 4;
  38646. } else if (flags & 0x80) {
  38647. scaleX = (code[i] << 24 | code[i + 1] << 16) / 1073741824;
  38648. scale01 = (code[i + 2] << 24 | code[i + 3] << 16) / 1073741824;
  38649. scale10 = (code[i + 4] << 24 | code[i + 5] << 16) / 1073741824;
  38650. scaleY = (code[i + 6] << 24 | code[i + 7] << 16) / 1073741824;
  38651. i += 8;
  38652. }
  38653. var subglyph = font.glyphs[glyphIndex];
  38654. if (subglyph) {
  38655. cmds.push({ cmd: 'save' });
  38656. cmds.push({
  38657. cmd: 'transform',
  38658. args: [
  38659. scaleX,
  38660. scale01,
  38661. scale10,
  38662. scaleY,
  38663. x,
  38664. y
  38665. ]
  38666. });
  38667. compileGlyf(subglyph, cmds, font);
  38668. cmds.push({ cmd: 'restore' });
  38669. }
  38670. } while (flags & 0x20);
  38671. } else {
  38672. // simple glyph
  38673. var endPtsOfContours = [];
  38674. var j, jj;
  38675. for (j = 0; j < numberOfContours; j++) {
  38676. endPtsOfContours.push(code[i] << 8 | code[i + 1]);
  38677. i += 2;
  38678. }
  38679. var instructionLength = code[i] << 8 | code[i + 1];
  38680. i += 2 + instructionLength;
  38681. // skipping the instructions
  38682. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  38683. var points = [];
  38684. while (points.length < numberOfPoints) {
  38685. flags = code[i++];
  38686. var repeat = 1;
  38687. if (flags & 0x08) {
  38688. repeat += code[i++];
  38689. }
  38690. while (repeat-- > 0) {
  38691. points.push({ flags: flags });
  38692. }
  38693. }
  38694. for (j = 0; j < numberOfPoints; j++) {
  38695. switch (points[j].flags & 0x12) {
  38696. case 0x00:
  38697. x += (code[i] << 24 | code[i + 1] << 16) >> 16;
  38698. i += 2;
  38699. break;
  38700. case 0x02:
  38701. x -= code[i++];
  38702. break;
  38703. case 0x12:
  38704. x += code[i++];
  38705. break;
  38706. }
  38707. points[j].x = x;
  38708. }
  38709. for (j = 0; j < numberOfPoints; j++) {
  38710. switch (points[j].flags & 0x24) {
  38711. case 0x00:
  38712. y += (code[i] << 24 | code[i + 1] << 16) >> 16;
  38713. i += 2;
  38714. break;
  38715. case 0x04:
  38716. y -= code[i++];
  38717. break;
  38718. case 0x24:
  38719. y += code[i++];
  38720. break;
  38721. }
  38722. points[j].y = y;
  38723. }
  38724. var startPoint = 0;
  38725. for (i = 0; i < numberOfContours; i++) {
  38726. var endPoint = endPtsOfContours[i];
  38727. // contours might have implicit points, which is located in the middle
  38728. // between two neighboring off-curve points
  38729. var contour = points.slice(startPoint, endPoint + 1);
  38730. if (contour[0].flags & 1) {
  38731. contour.push(contour[0]);
  38732. } else // using start point at the contour end
  38733. if (contour[contour.length - 1].flags & 1) {
  38734. // first is off-curve point, trying to use one from the end
  38735. contour.unshift(contour[contour.length - 1]);
  38736. } else {
  38737. // start and end are off-curve points, creating implicit one
  38738. var p = {
  38739. flags: 1,
  38740. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  38741. y: (contour[0].y + contour[contour.length - 1].y) / 2
  38742. };
  38743. contour.unshift(p);
  38744. contour.push(p);
  38745. }
  38746. moveTo(contour[0].x, contour[0].y);
  38747. for (j = 1, jj = contour.length; j < jj; j++) {
  38748. if (contour[j].flags & 1) {
  38749. lineTo(contour[j].x, contour[j].y);
  38750. } else if (contour[j + 1].flags & 1) {
  38751. quadraticCurveTo(contour[j].x, contour[j].y, contour[j + 1].x, contour[j + 1].y);
  38752. j++;
  38753. } else {
  38754. quadraticCurveTo(contour[j].x, contour[j].y, (contour[j].x + contour[j + 1].x) / 2, (contour[j].y + contour[j + 1].y) / 2);
  38755. }
  38756. }
  38757. startPoint = endPoint + 1;
  38758. }
  38759. }
  38760. }
  38761. function compileCharString(code, cmds, font) {
  38762. var stack = [];
  38763. var x = 0, y = 0;
  38764. var stems = 0;
  38765. function moveTo(x, y) {
  38766. cmds.push({
  38767. cmd: 'moveTo',
  38768. args: [
  38769. x,
  38770. y
  38771. ]
  38772. });
  38773. }
  38774. function lineTo(x, y) {
  38775. cmds.push({
  38776. cmd: 'lineTo',
  38777. args: [
  38778. x,
  38779. y
  38780. ]
  38781. });
  38782. }
  38783. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  38784. cmds.push({
  38785. cmd: 'bezierCurveTo',
  38786. args: [
  38787. x1,
  38788. y1,
  38789. x2,
  38790. y2,
  38791. x,
  38792. y
  38793. ]
  38794. });
  38795. }
  38796. function parse(code) {
  38797. var i = 0;
  38798. while (i < code.length) {
  38799. var stackClean = false;
  38800. var v = code[i++];
  38801. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  38802. switch (v) {
  38803. case 1:
  38804. // hstem
  38805. stems += stack.length >> 1;
  38806. stackClean = true;
  38807. break;
  38808. case 3:
  38809. // vstem
  38810. stems += stack.length >> 1;
  38811. stackClean = true;
  38812. break;
  38813. case 4:
  38814. // vmoveto
  38815. y += stack.pop();
  38816. moveTo(x, y);
  38817. stackClean = true;
  38818. break;
  38819. case 5:
  38820. // rlineto
  38821. while (stack.length > 0) {
  38822. x += stack.shift();
  38823. y += stack.shift();
  38824. lineTo(x, y);
  38825. }
  38826. break;
  38827. case 6:
  38828. // hlineto
  38829. while (stack.length > 0) {
  38830. x += stack.shift();
  38831. lineTo(x, y);
  38832. if (stack.length === 0) {
  38833. break;
  38834. }
  38835. y += stack.shift();
  38836. lineTo(x, y);
  38837. }
  38838. break;
  38839. case 7:
  38840. // vlineto
  38841. while (stack.length > 0) {
  38842. y += stack.shift();
  38843. lineTo(x, y);
  38844. if (stack.length === 0) {
  38845. break;
  38846. }
  38847. x += stack.shift();
  38848. lineTo(x, y);
  38849. }
  38850. break;
  38851. case 8:
  38852. // rrcurveto
  38853. while (stack.length > 0) {
  38854. xa = x + stack.shift();
  38855. ya = y + stack.shift();
  38856. xb = xa + stack.shift();
  38857. yb = ya + stack.shift();
  38858. x = xb + stack.shift();
  38859. y = yb + stack.shift();
  38860. bezierCurveTo(xa, ya, xb, yb, x, y);
  38861. }
  38862. break;
  38863. case 10:
  38864. // callsubr
  38865. n = stack.pop() + font.subrsBias;
  38866. subrCode = font.subrs[n];
  38867. if (subrCode) {
  38868. parse(subrCode);
  38869. }
  38870. break;
  38871. case 11:
  38872. // return
  38873. return;
  38874. case 12:
  38875. v = code[i++];
  38876. switch (v) {
  38877. case 34:
  38878. // flex
  38879. xa = x + stack.shift();
  38880. xb = xa + stack.shift();
  38881. y1 = y + stack.shift();
  38882. x = xb + stack.shift();
  38883. bezierCurveTo(xa, y, xb, y1, x, y1);
  38884. xa = x + stack.shift();
  38885. xb = xa + stack.shift();
  38886. x = xb + stack.shift();
  38887. bezierCurveTo(xa, y1, xb, y, x, y);
  38888. break;
  38889. case 35:
  38890. // flex
  38891. xa = x + stack.shift();
  38892. ya = y + stack.shift();
  38893. xb = xa + stack.shift();
  38894. yb = ya + stack.shift();
  38895. x = xb + stack.shift();
  38896. y = yb + stack.shift();
  38897. bezierCurveTo(xa, ya, xb, yb, x, y);
  38898. xa = x + stack.shift();
  38899. ya = y + stack.shift();
  38900. xb = xa + stack.shift();
  38901. yb = ya + stack.shift();
  38902. x = xb + stack.shift();
  38903. y = yb + stack.shift();
  38904. bezierCurveTo(xa, ya, xb, yb, x, y);
  38905. stack.pop();
  38906. // fd
  38907. break;
  38908. case 36:
  38909. // hflex1
  38910. xa = x + stack.shift();
  38911. y1 = y + stack.shift();
  38912. xb = xa + stack.shift();
  38913. y2 = y1 + stack.shift();
  38914. x = xb + stack.shift();
  38915. bezierCurveTo(xa, y1, xb, y2, x, y2);
  38916. xa = x + stack.shift();
  38917. xb = xa + stack.shift();
  38918. y3 = y2 + stack.shift();
  38919. x = xb + stack.shift();
  38920. bezierCurveTo(xa, y2, xb, y3, x, y);
  38921. break;
  38922. case 37:
  38923. // flex1
  38924. var x0 = x, y0 = y;
  38925. xa = x + stack.shift();
  38926. ya = y + stack.shift();
  38927. xb = xa + stack.shift();
  38928. yb = ya + stack.shift();
  38929. x = xb + stack.shift();
  38930. y = yb + stack.shift();
  38931. bezierCurveTo(xa, ya, xb, yb, x, y);
  38932. xa = x + stack.shift();
  38933. ya = y + stack.shift();
  38934. xb = xa + stack.shift();
  38935. yb = ya + stack.shift();
  38936. x = xb;
  38937. y = yb;
  38938. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  38939. x += stack.shift();
  38940. } else {
  38941. y += stack.shift();
  38942. }
  38943. bezierCurveTo(xa, ya, xb, yb, x, y);
  38944. break;
  38945. default:
  38946. error('unknown operator: 12 ' + v);
  38947. }
  38948. break;
  38949. case 14:
  38950. // endchar
  38951. if (stack.length >= 4) {
  38952. var achar = stack.pop();
  38953. var bchar = stack.pop();
  38954. y = stack.pop();
  38955. x = stack.pop();
  38956. cmds.push({ cmd: 'save' });
  38957. cmds.push({
  38958. cmd: 'translate',
  38959. args: [
  38960. x,
  38961. y
  38962. ]
  38963. });
  38964. var cmap = lookupCmap(font.cmap, String.fromCharCode(font.glyphNameMap[StandardEncoding[achar]]));
  38965. compileCharString(font.glyphs[cmap.glyphId], cmds, font);
  38966. cmds.push({ cmd: 'restore' });
  38967. cmap = lookupCmap(font.cmap, String.fromCharCode(font.glyphNameMap[StandardEncoding[bchar]]));
  38968. compileCharString(font.glyphs[cmap.glyphId], cmds, font);
  38969. }
  38970. return;
  38971. case 18:
  38972. // hstemhm
  38973. stems += stack.length >> 1;
  38974. stackClean = true;
  38975. break;
  38976. case 19:
  38977. // hintmask
  38978. stems += stack.length >> 1;
  38979. i += stems + 7 >> 3;
  38980. stackClean = true;
  38981. break;
  38982. case 20:
  38983. // cntrmask
  38984. stems += stack.length >> 1;
  38985. i += stems + 7 >> 3;
  38986. stackClean = true;
  38987. break;
  38988. case 21:
  38989. // rmoveto
  38990. y += stack.pop();
  38991. x += stack.pop();
  38992. moveTo(x, y);
  38993. stackClean = true;
  38994. break;
  38995. case 22:
  38996. // hmoveto
  38997. x += stack.pop();
  38998. moveTo(x, y);
  38999. stackClean = true;
  39000. break;
  39001. case 23:
  39002. // vstemhm
  39003. stems += stack.length >> 1;
  39004. stackClean = true;
  39005. break;
  39006. case 24:
  39007. // rcurveline
  39008. while (stack.length > 2) {
  39009. xa = x + stack.shift();
  39010. ya = y + stack.shift();
  39011. xb = xa + stack.shift();
  39012. yb = ya + stack.shift();
  39013. x = xb + stack.shift();
  39014. y = yb + stack.shift();
  39015. bezierCurveTo(xa, ya, xb, yb, x, y);
  39016. }
  39017. x += stack.shift();
  39018. y += stack.shift();
  39019. lineTo(x, y);
  39020. break;
  39021. case 25:
  39022. // rlinecurve
  39023. while (stack.length > 6) {
  39024. x += stack.shift();
  39025. y += stack.shift();
  39026. lineTo(x, y);
  39027. }
  39028. xa = x + stack.shift();
  39029. ya = y + stack.shift();
  39030. xb = xa + stack.shift();
  39031. yb = ya + stack.shift();
  39032. x = xb + stack.shift();
  39033. y = yb + stack.shift();
  39034. bezierCurveTo(xa, ya, xb, yb, x, y);
  39035. break;
  39036. case 26:
  39037. // vvcurveto
  39038. if (stack.length % 2) {
  39039. x += stack.shift();
  39040. }
  39041. while (stack.length > 0) {
  39042. xa = x;
  39043. ya = y + stack.shift();
  39044. xb = xa + stack.shift();
  39045. yb = ya + stack.shift();
  39046. x = xb;
  39047. y = yb + stack.shift();
  39048. bezierCurveTo(xa, ya, xb, yb, x, y);
  39049. }
  39050. break;
  39051. case 27:
  39052. // hhcurveto
  39053. if (stack.length % 2) {
  39054. y += stack.shift();
  39055. }
  39056. while (stack.length > 0) {
  39057. xa = x + stack.shift();
  39058. ya = y;
  39059. xb = xa + stack.shift();
  39060. yb = ya + stack.shift();
  39061. x = xb + stack.shift();
  39062. y = yb;
  39063. bezierCurveTo(xa, ya, xb, yb, x, y);
  39064. }
  39065. break;
  39066. case 28:
  39067. stack.push((code[i] << 24 | code[i + 1] << 16) >> 16);
  39068. i += 2;
  39069. break;
  39070. case 29:
  39071. // callgsubr
  39072. n = stack.pop() + font.gsubrsBias;
  39073. subrCode = font.gsubrs[n];
  39074. if (subrCode) {
  39075. parse(subrCode);
  39076. }
  39077. break;
  39078. case 30:
  39079. // vhcurveto
  39080. while (stack.length > 0) {
  39081. xa = x;
  39082. ya = y + stack.shift();
  39083. xb = xa + stack.shift();
  39084. yb = ya + stack.shift();
  39085. x = xb + stack.shift();
  39086. y = yb + (stack.length === 1 ? stack.shift() : 0);
  39087. bezierCurveTo(xa, ya, xb, yb, x, y);
  39088. if (stack.length === 0) {
  39089. break;
  39090. }
  39091. xa = x + stack.shift();
  39092. ya = y;
  39093. xb = xa + stack.shift();
  39094. yb = ya + stack.shift();
  39095. y = yb + stack.shift();
  39096. x = xb + (stack.length === 1 ? stack.shift() : 0);
  39097. bezierCurveTo(xa, ya, xb, yb, x, y);
  39098. }
  39099. break;
  39100. case 31:
  39101. // hvcurveto
  39102. while (stack.length > 0) {
  39103. xa = x + stack.shift();
  39104. ya = y;
  39105. xb = xa + stack.shift();
  39106. yb = ya + stack.shift();
  39107. y = yb + stack.shift();
  39108. x = xb + (stack.length === 1 ? stack.shift() : 0);
  39109. bezierCurveTo(xa, ya, xb, yb, x, y);
  39110. if (stack.length === 0) {
  39111. break;
  39112. }
  39113. xa = x;
  39114. ya = y + stack.shift();
  39115. xb = xa + stack.shift();
  39116. yb = ya + stack.shift();
  39117. x = xb + stack.shift();
  39118. y = yb + (stack.length === 1 ? stack.shift() : 0);
  39119. bezierCurveTo(xa, ya, xb, yb, x, y);
  39120. }
  39121. break;
  39122. default:
  39123. if (v < 32) {
  39124. error('unknown operator: ' + v);
  39125. }
  39126. if (v < 247) {
  39127. stack.push(v - 139);
  39128. } else if (v < 251) {
  39129. stack.push((v - 247) * 256 + code[i++] + 108);
  39130. } else if (v < 255) {
  39131. stack.push(-(v - 251) * 256 - code[i++] - 108);
  39132. } else {
  39133. stack.push((code[i] << 24 | code[i + 1] << 16 | code[i + 2] << 8 | code[i + 3]) / 65536);
  39134. i += 4;
  39135. }
  39136. break;
  39137. }
  39138. if (stackClean) {
  39139. stack.length = 0;
  39140. }
  39141. }
  39142. }
  39143. parse(code);
  39144. }
  39145. var noop = '';
  39146. function CompiledFont(fontMatrix) {
  39147. this.compiledGlyphs = Object.create(null);
  39148. this.compiledCharCodeToGlyphId = Object.create(null);
  39149. this.fontMatrix = fontMatrix;
  39150. }
  39151. CompiledFont.prototype = {
  39152. getPathJs: function (unicode) {
  39153. var cmap = lookupCmap(this.cmap, unicode);
  39154. var fn = this.compiledGlyphs[cmap.glyphId];
  39155. if (!fn) {
  39156. fn = this.compileGlyph(this.glyphs[cmap.glyphId]);
  39157. this.compiledGlyphs[cmap.glyphId] = fn;
  39158. }
  39159. if (this.compiledCharCodeToGlyphId[cmap.charCode] === undefined) {
  39160. this.compiledCharCodeToGlyphId[cmap.charCode] = cmap.glyphId;
  39161. }
  39162. return fn;
  39163. },
  39164. compileGlyph: function (code) {
  39165. if (!code || code.length === 0 || code[0] === 14) {
  39166. return noop;
  39167. }
  39168. var cmds = [];
  39169. cmds.push({ cmd: 'save' });
  39170. cmds.push({
  39171. cmd: 'transform',
  39172. args: this.fontMatrix.slice()
  39173. });
  39174. cmds.push({
  39175. cmd: 'scale',
  39176. args: [
  39177. 'size',
  39178. '-size'
  39179. ]
  39180. });
  39181. this.compileGlyphImpl(code, cmds);
  39182. cmds.push({ cmd: 'restore' });
  39183. return cmds;
  39184. },
  39185. compileGlyphImpl: function () {
  39186. error('Children classes should implement this.');
  39187. },
  39188. hasBuiltPath: function (unicode) {
  39189. var cmap = lookupCmap(this.cmap, unicode);
  39190. return this.compiledGlyphs[cmap.glyphId] !== undefined && this.compiledCharCodeToGlyphId[cmap.charCode] !== undefined;
  39191. }
  39192. };
  39193. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  39194. fontMatrix = fontMatrix || [
  39195. 0.000488,
  39196. 0,
  39197. 0,
  39198. 0.000488,
  39199. 0,
  39200. 0
  39201. ];
  39202. CompiledFont.call(this, fontMatrix);
  39203. this.glyphs = glyphs;
  39204. this.cmap = cmap;
  39205. }
  39206. Util.inherit(TrueTypeCompiled, CompiledFont, {
  39207. compileGlyphImpl: function (code, cmds) {
  39208. compileGlyf(code, cmds, this);
  39209. }
  39210. });
  39211. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  39212. fontMatrix = fontMatrix || [
  39213. 0.001,
  39214. 0,
  39215. 0,
  39216. 0.001,
  39217. 0,
  39218. 0
  39219. ];
  39220. CompiledFont.call(this, fontMatrix);
  39221. this.glyphs = cffInfo.glyphs;
  39222. this.gsubrs = cffInfo.gsubrs || [];
  39223. this.subrs = cffInfo.subrs || [];
  39224. this.cmap = cmap;
  39225. this.glyphNameMap = glyphNameMap || getGlyphsUnicode();
  39226. this.gsubrsBias = this.gsubrs.length < 1240 ? 107 : this.gsubrs.length < 33900 ? 1131 : 32768;
  39227. this.subrsBias = this.subrs.length < 1240 ? 107 : this.subrs.length < 33900 ? 1131 : 32768;
  39228. }
  39229. Util.inherit(Type2Compiled, CompiledFont, {
  39230. compileGlyphImpl: function (code, cmds) {
  39231. compileCharString(code, cmds, this);
  39232. }
  39233. });
  39234. return {
  39235. create: function FontRendererFactory_create(font, seacAnalysisEnabled) {
  39236. var data = new Uint8Array(font.data);
  39237. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  39238. var numTables = getUshort(data, 4);
  39239. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  39240. var tag = bytesToString(data.subarray(p, p + 4));
  39241. var offset = getLong(data, p + 8);
  39242. var length = getLong(data, p + 12);
  39243. switch (tag) {
  39244. case 'cmap':
  39245. cmap = parseCmap(data, offset, offset + length);
  39246. break;
  39247. case 'glyf':
  39248. glyf = data.subarray(offset, offset + length);
  39249. break;
  39250. case 'loca':
  39251. loca = data.subarray(offset, offset + length);
  39252. break;
  39253. case 'head':
  39254. unitsPerEm = getUshort(data, offset + 18);
  39255. indexToLocFormat = getUshort(data, offset + 50);
  39256. break;
  39257. case 'CFF ':
  39258. cff = parseCff(data, offset, offset + length, seacAnalysisEnabled);
  39259. break;
  39260. }
  39261. }
  39262. if (glyf) {
  39263. var fontMatrix = !unitsPerEm ? font.fontMatrix : [
  39264. 1 / unitsPerEm,
  39265. 0,
  39266. 0,
  39267. 1 / unitsPerEm,
  39268. 0,
  39269. 0
  39270. ];
  39271. return new TrueTypeCompiled(parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  39272. } else {
  39273. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  39274. }
  39275. }
  39276. };
  39277. }();
  39278. exports.FontRendererFactory = FontRendererFactory;
  39279. }));
  39280. (function (root, factory) {
  39281. factory(root.pdfjsCoreParser = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  39282. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  39283. var MissingDataException = sharedUtil.MissingDataException;
  39284. var StreamType = sharedUtil.StreamType;
  39285. var assert = sharedUtil.assert;
  39286. var error = sharedUtil.error;
  39287. var info = sharedUtil.info;
  39288. var isArray = sharedUtil.isArray;
  39289. var isInt = sharedUtil.isInt;
  39290. var isNum = sharedUtil.isNum;
  39291. var isString = sharedUtil.isString;
  39292. var warn = sharedUtil.warn;
  39293. var Cmd = corePrimitives.Cmd;
  39294. var Dict = corePrimitives.Dict;
  39295. var Name = corePrimitives.Name;
  39296. var Ref = corePrimitives.Ref;
  39297. var isCmd = corePrimitives.isCmd;
  39298. var isDict = corePrimitives.isDict;
  39299. var isName = corePrimitives.isName;
  39300. var Ascii85Stream = coreStream.Ascii85Stream;
  39301. var AsciiHexStream = coreStream.AsciiHexStream;
  39302. var CCITTFaxStream = coreStream.CCITTFaxStream;
  39303. var FlateStream = coreStream.FlateStream;
  39304. var Jbig2Stream = coreStream.Jbig2Stream;
  39305. var JpegStream = coreStream.JpegStream;
  39306. var JpxStream = coreStream.JpxStream;
  39307. var LZWStream = coreStream.LZWStream;
  39308. var NullStream = coreStream.NullStream;
  39309. var PredictorStream = coreStream.PredictorStream;
  39310. var RunLengthStream = coreStream.RunLengthStream;
  39311. var EOF = {};
  39312. function isEOF(v) {
  39313. return v === EOF;
  39314. }
  39315. var MAX_LENGTH_TO_CACHE = 1000;
  39316. var Parser = function ParserClosure() {
  39317. function Parser(lexer, allowStreams, xref, recoveryMode) {
  39318. this.lexer = lexer;
  39319. this.allowStreams = allowStreams;
  39320. this.xref = xref;
  39321. this.recoveryMode = recoveryMode || false;
  39322. this.imageCache = Object.create(null);
  39323. this.refill();
  39324. }
  39325. Parser.prototype = {
  39326. refill: function Parser_refill() {
  39327. this.buf1 = this.lexer.getObj();
  39328. this.buf2 = this.lexer.getObj();
  39329. },
  39330. shift: function Parser_shift() {
  39331. if (isCmd(this.buf2, 'ID')) {
  39332. this.buf1 = this.buf2;
  39333. this.buf2 = null;
  39334. } else {
  39335. this.buf1 = this.buf2;
  39336. this.buf2 = this.lexer.getObj();
  39337. }
  39338. },
  39339. tryShift: function Parser_tryShift() {
  39340. try {
  39341. this.shift();
  39342. return true;
  39343. } catch (e) {
  39344. if (e instanceof MissingDataException) {
  39345. throw e;
  39346. }
  39347. // Upon failure, the caller should reset this.lexer.pos to a known good
  39348. // state and call this.shift() twice to reset the buffers.
  39349. return false;
  39350. }
  39351. },
  39352. getObj: function Parser_getObj(cipherTransform) {
  39353. var buf1 = this.buf1;
  39354. this.shift();
  39355. if (buf1 instanceof Cmd) {
  39356. switch (buf1.cmd) {
  39357. case 'BI':
  39358. // inline image
  39359. return this.makeInlineImage(cipherTransform);
  39360. case '[':
  39361. // array
  39362. var array = [];
  39363. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  39364. array.push(this.getObj(cipherTransform));
  39365. }
  39366. if (isEOF(this.buf1)) {
  39367. if (!this.recoveryMode) {
  39368. error('End of file inside array');
  39369. }
  39370. return array;
  39371. }
  39372. this.shift();
  39373. return array;
  39374. case '<<':
  39375. // dictionary or stream
  39376. var dict = new Dict(this.xref);
  39377. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  39378. if (!isName(this.buf1)) {
  39379. info('Malformed dictionary: key must be a name object');
  39380. this.shift();
  39381. continue;
  39382. }
  39383. var key = this.buf1.name;
  39384. this.shift();
  39385. if (isEOF(this.buf1)) {
  39386. break;
  39387. }
  39388. dict.set(key, this.getObj(cipherTransform));
  39389. }
  39390. if (isEOF(this.buf1)) {
  39391. if (!this.recoveryMode) {
  39392. error('End of file inside dictionary');
  39393. }
  39394. return dict;
  39395. }
  39396. // Stream objects are not allowed inside content streams or
  39397. // object streams.
  39398. if (isCmd(this.buf2, 'stream')) {
  39399. return this.allowStreams ? this.makeStream(dict, cipherTransform) : dict;
  39400. }
  39401. this.shift();
  39402. return dict;
  39403. default:
  39404. // simple object
  39405. return buf1;
  39406. }
  39407. }
  39408. if (isInt(buf1)) {
  39409. // indirect reference or integer
  39410. var num = buf1;
  39411. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  39412. var ref = new Ref(num, this.buf1);
  39413. this.shift();
  39414. this.shift();
  39415. return ref;
  39416. }
  39417. return num;
  39418. }
  39419. if (isString(buf1)) {
  39420. // string
  39421. var str = buf1;
  39422. if (cipherTransform) {
  39423. str = cipherTransform.decryptString(str);
  39424. }
  39425. return str;
  39426. }
  39427. // simple object
  39428. return buf1;
  39429. },
  39430. /**
  39431. * Find the end of the stream by searching for the /EI\s/.
  39432. * @returns {number} The inline stream length.
  39433. */
  39434. findDefaultInlineStreamEnd: function Parser_findDefaultInlineStreamEnd(stream) {
  39435. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  39436. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  39437. while ((ch = stream.getByte()) !== -1) {
  39438. if (state === 0) {
  39439. state = ch === E ? 1 : 0;
  39440. } else if (state === 1) {
  39441. state = ch === I ? 2 : 0;
  39442. } else {
  39443. assert(state === 2);
  39444. if (ch === SPACE || ch === LF || ch === CR) {
  39445. // Let's check the next five bytes are ASCII... just be sure.
  39446. n = 5;
  39447. followingBytes = stream.peekBytes(n);
  39448. for (i = 0; i < n; i++) {
  39449. ch = followingBytes[i];
  39450. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  39451. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  39452. // it's binary stuff. Resetting the state.
  39453. state = 0;
  39454. break;
  39455. }
  39456. }
  39457. if (state === 2) {
  39458. break;
  39459. }
  39460. } else
  39461. // Finished!
  39462. {
  39463. state = 0;
  39464. }
  39465. }
  39466. }
  39467. return stream.pos - 4 - startPos;
  39468. },
  39469. /**
  39470. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  39471. * @returns {number} The inline stream length.
  39472. */
  39473. findDCTDecodeInlineStreamEnd: function Parser_findDCTDecodeInlineStreamEnd(stream) {
  39474. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  39475. while ((b = stream.getByte()) !== -1) {
  39476. if (b !== 0xFF) {
  39477. // Not a valid marker.
  39478. continue;
  39479. }
  39480. switch (stream.getByte()) {
  39481. case 0x00:
  39482. // Byte stuffing.
  39483. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  39484. break;
  39485. case 0xFF:
  39486. // Fill byte.
  39487. // Avoid skipping a valid marker, resetting the stream position.
  39488. stream.skip(-1);
  39489. break;
  39490. case 0xD9:
  39491. // EOI
  39492. foundEOI = true;
  39493. break;
  39494. case 0xC0:
  39495. // SOF0
  39496. case 0xC1:
  39497. // SOF1
  39498. case 0xC2:
  39499. // SOF2
  39500. case 0xC3:
  39501. // SOF3
  39502. case 0xC5:
  39503. // SOF5
  39504. case 0xC6:
  39505. // SOF6
  39506. case 0xC7:
  39507. // SOF7
  39508. case 0xC9:
  39509. // SOF9
  39510. case 0xCA:
  39511. // SOF10
  39512. case 0xCB:
  39513. // SOF11
  39514. case 0xCD:
  39515. // SOF13
  39516. case 0xCE:
  39517. // SOF14
  39518. case 0xCF:
  39519. // SOF15
  39520. case 0xC4:
  39521. // DHT
  39522. case 0xCC:
  39523. // DAC
  39524. case 0xDA:
  39525. // SOS
  39526. case 0xDB:
  39527. // DQT
  39528. case 0xDC:
  39529. // DNL
  39530. case 0xDD:
  39531. // DRI
  39532. case 0xDE:
  39533. // DHP
  39534. case 0xDF:
  39535. // EXP
  39536. case 0xE0:
  39537. // APP0
  39538. case 0xE1:
  39539. // APP1
  39540. case 0xE2:
  39541. // APP2
  39542. case 0xE3:
  39543. // APP3
  39544. case 0xE4:
  39545. // APP4
  39546. case 0xE5:
  39547. // APP5
  39548. case 0xE6:
  39549. // APP6
  39550. case 0xE7:
  39551. // APP7
  39552. case 0xE8:
  39553. // APP8
  39554. case 0xE9:
  39555. // APP9
  39556. case 0xEA:
  39557. // APP10
  39558. case 0xEB:
  39559. // APP11
  39560. case 0xEC:
  39561. // APP12
  39562. case 0xED:
  39563. // APP13
  39564. case 0xEE:
  39565. // APP14
  39566. case 0xEF:
  39567. // APP15
  39568. case 0xFE:
  39569. // COM
  39570. // The marker should be followed by the length of the segment.
  39571. markerLength = stream.getUint16();
  39572. if (markerLength > 2) {
  39573. // |markerLength| contains the byte length of the marker segment,
  39574. // including its own length (2 bytes) and excluding the marker.
  39575. stream.skip(markerLength - 2);
  39576. } else
  39577. // Jump to the next marker.
  39578. {
  39579. // The marker length is invalid, resetting the stream position.
  39580. stream.skip(-2);
  39581. }
  39582. break;
  39583. }
  39584. if (foundEOI) {
  39585. break;
  39586. }
  39587. }
  39588. length = stream.pos - startPos;
  39589. if (b === -1) {
  39590. warn('Inline DCTDecode image stream: ' + 'EOI marker not found, searching for /EI/ instead.');
  39591. stream.skip(-length);
  39592. // Reset the stream position.
  39593. return this.findDefaultInlineStreamEnd(stream);
  39594. }
  39595. this.inlineStreamSkipEI(stream);
  39596. return length;
  39597. },
  39598. /**
  39599. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  39600. * @returns {number} The inline stream length.
  39601. */
  39602. findASCII85DecodeInlineStreamEnd: function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  39603. var TILDE = 0x7E, GT = 0x3E;
  39604. var startPos = stream.pos, ch, length;
  39605. while ((ch = stream.getByte()) !== -1) {
  39606. if (ch === TILDE && stream.peekByte() === GT) {
  39607. stream.skip();
  39608. break;
  39609. }
  39610. }
  39611. length = stream.pos - startPos;
  39612. if (ch === -1) {
  39613. warn('Inline ASCII85Decode image stream: ' + 'EOD marker not found, searching for /EI/ instead.');
  39614. stream.skip(-length);
  39615. // Reset the stream position.
  39616. return this.findDefaultInlineStreamEnd(stream);
  39617. }
  39618. this.inlineStreamSkipEI(stream);
  39619. return length;
  39620. },
  39621. /**
  39622. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  39623. * @returns {number} The inline stream length.
  39624. */
  39625. findASCIIHexDecodeInlineStreamEnd: function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  39626. var GT = 0x3E;
  39627. var startPos = stream.pos, ch, length;
  39628. while ((ch = stream.getByte()) !== -1) {
  39629. if (ch === GT) {
  39630. break;
  39631. }
  39632. }
  39633. length = stream.pos - startPos;
  39634. if (ch === -1) {
  39635. warn('Inline ASCIIHexDecode image stream: ' + 'EOD marker not found, searching for /EI/ instead.');
  39636. stream.skip(-length);
  39637. // Reset the stream position.
  39638. return this.findDefaultInlineStreamEnd(stream);
  39639. }
  39640. this.inlineStreamSkipEI(stream);
  39641. return length;
  39642. },
  39643. /**
  39644. * Skip over the /EI/ for streams where we search for an EOD marker.
  39645. */
  39646. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  39647. var E = 0x45, I = 0x49;
  39648. var state = 0, ch;
  39649. while ((ch = stream.getByte()) !== -1) {
  39650. if (state === 0) {
  39651. state = ch === E ? 1 : 0;
  39652. } else if (state === 1) {
  39653. state = ch === I ? 2 : 0;
  39654. } else if (state === 2) {
  39655. break;
  39656. }
  39657. }
  39658. },
  39659. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  39660. var lexer = this.lexer;
  39661. var stream = lexer.stream;
  39662. // Parse dictionary.
  39663. var dict = new Dict(this.xref);
  39664. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  39665. if (!isName(this.buf1)) {
  39666. error('Dictionary key must be a name object');
  39667. }
  39668. var key = this.buf1.name;
  39669. this.shift();
  39670. if (isEOF(this.buf1)) {
  39671. break;
  39672. }
  39673. dict.set(key, this.getObj(cipherTransform));
  39674. }
  39675. // Extract the name of the first (i.e. the current) image filter.
  39676. var filter = dict.get('Filter', 'F'), filterName;
  39677. if (isName(filter)) {
  39678. filterName = filter.name;
  39679. } else if (isArray(filter) && isName(filter[0])) {
  39680. filterName = filter[0].name;
  39681. }
  39682. // Parse image stream.
  39683. var startPos = stream.pos, length, i, ii;
  39684. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  39685. length = this.findDCTDecodeInlineStreamEnd(stream);
  39686. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  39687. length = this.findASCII85DecodeInlineStreamEnd(stream);
  39688. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  39689. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  39690. } else {
  39691. length = this.findDefaultInlineStreamEnd(stream);
  39692. }
  39693. var imageStream = stream.makeSubStream(startPos, length, dict);
  39694. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  39695. // adler32 checksum.
  39696. var adler32;
  39697. if (length < MAX_LENGTH_TO_CACHE) {
  39698. var imageBytes = imageStream.getBytes();
  39699. imageStream.reset();
  39700. var a = 1;
  39701. var b = 0;
  39702. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  39703. // No modulo required in the loop if imageBytes.length < 5552.
  39704. a += imageBytes[i] & 0xff;
  39705. b += a;
  39706. }
  39707. adler32 = b % 65521 << 16 | a % 65521;
  39708. if (this.imageCache.adler32 === adler32) {
  39709. this.buf2 = Cmd.get('EI');
  39710. this.shift();
  39711. this.imageCache[adler32].reset();
  39712. return this.imageCache[adler32];
  39713. }
  39714. }
  39715. if (cipherTransform) {
  39716. imageStream = cipherTransform.createStream(imageStream, length);
  39717. }
  39718. imageStream = this.filter(imageStream, dict, length);
  39719. imageStream.dict = dict;
  39720. if (adler32 !== undefined) {
  39721. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  39722. this.imageCache[adler32] = imageStream;
  39723. }
  39724. this.buf2 = Cmd.get('EI');
  39725. this.shift();
  39726. return imageStream;
  39727. },
  39728. makeStream: function Parser_makeStream(dict, cipherTransform) {
  39729. var lexer = this.lexer;
  39730. var stream = lexer.stream;
  39731. // get stream start position
  39732. lexer.skipToNextLine();
  39733. var pos = stream.pos - 1;
  39734. // get length
  39735. var length = dict.get('Length');
  39736. if (!isInt(length)) {
  39737. info('Bad ' + length + ' attribute in stream');
  39738. length = 0;
  39739. }
  39740. // skip over the stream data
  39741. stream.pos = pos + length;
  39742. lexer.nextChar();
  39743. // Shift '>>' and check whether the new object marks the end of the stream
  39744. if (this.tryShift() && isCmd(this.buf2, 'endstream')) {
  39745. this.shift();
  39746. } else
  39747. // 'stream'
  39748. {
  39749. // bad stream length, scanning for endstream
  39750. stream.pos = pos;
  39751. var SCAN_BLOCK_SIZE = 2048;
  39752. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  39753. var ENDSTREAM_SIGNATURE = [
  39754. 0x65,
  39755. 0x6E,
  39756. 0x64,
  39757. 0x73,
  39758. 0x74,
  39759. 0x72,
  39760. 0x65,
  39761. 0x61,
  39762. 0x6D
  39763. ];
  39764. var skipped = 0, found = false, i, j;
  39765. while (stream.pos < stream.end) {
  39766. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  39767. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  39768. if (scanLength <= 0) {
  39769. break;
  39770. }
  39771. found = false;
  39772. i = 0;
  39773. while (i < scanLength) {
  39774. j = 0;
  39775. while (j < ENDSTREAM_SIGNATURE_LENGTH && scanBytes[i + j] === ENDSTREAM_SIGNATURE[j]) {
  39776. j++;
  39777. }
  39778. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  39779. found = true;
  39780. break;
  39781. }
  39782. i++;
  39783. }
  39784. if (found) {
  39785. skipped += i;
  39786. stream.pos += i;
  39787. break;
  39788. }
  39789. skipped += scanLength;
  39790. stream.pos += scanLength;
  39791. }
  39792. if (!found) {
  39793. error('Missing endstream');
  39794. }
  39795. length = skipped;
  39796. lexer.nextChar();
  39797. this.shift();
  39798. this.shift();
  39799. }
  39800. this.shift();
  39801. // 'endstream'
  39802. stream = stream.makeSubStream(pos, length, dict);
  39803. if (cipherTransform) {
  39804. stream = cipherTransform.createStream(stream, length);
  39805. }
  39806. stream = this.filter(stream, dict, length);
  39807. stream.dict = dict;
  39808. return stream;
  39809. },
  39810. filter: function Parser_filter(stream, dict, length) {
  39811. var filter = dict.get('Filter', 'F');
  39812. var params = dict.get('DecodeParms', 'DP');
  39813. if (isName(filter)) {
  39814. if (isArray(params)) {
  39815. params = params[0];
  39816. }
  39817. return this.makeFilter(stream, filter.name, length, params);
  39818. }
  39819. var maybeLength = length;
  39820. if (isArray(filter)) {
  39821. var filterArray = filter;
  39822. var paramsArray = params;
  39823. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  39824. filter = filterArray[i];
  39825. if (!isName(filter)) {
  39826. error('Bad filter name: ' + filter);
  39827. }
  39828. params = null;
  39829. if (isArray(paramsArray) && i in paramsArray) {
  39830. params = paramsArray[i];
  39831. }
  39832. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  39833. // after the first stream the length variable is invalid
  39834. maybeLength = null;
  39835. }
  39836. }
  39837. return stream;
  39838. },
  39839. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  39840. // Since the 'Length' entry in the stream dictionary can be completely
  39841. // wrong, e.g. zero for non-empty streams, only skip parsing the stream
  39842. // when we can be absolutely certain that it actually is empty.
  39843. if (maybeLength === 0) {
  39844. warn('Empty "' + name + '" stream.');
  39845. return new NullStream(stream);
  39846. }
  39847. try {
  39848. if (params && this.xref) {
  39849. params = this.xref.fetchIfRef(params);
  39850. }
  39851. var xrefStreamStats = this.xref.stats.streamTypes;
  39852. if (name === 'FlateDecode' || name === 'Fl') {
  39853. xrefStreamStats[StreamType.FLATE] = true;
  39854. if (params) {
  39855. return new PredictorStream(new FlateStream(stream, maybeLength), maybeLength, params);
  39856. }
  39857. return new FlateStream(stream, maybeLength);
  39858. }
  39859. if (name === 'LZWDecode' || name === 'LZW') {
  39860. xrefStreamStats[StreamType.LZW] = true;
  39861. var earlyChange = 1;
  39862. if (params) {
  39863. if (params.has('EarlyChange')) {
  39864. earlyChange = params.get('EarlyChange');
  39865. }
  39866. return new PredictorStream(new LZWStream(stream, maybeLength, earlyChange), maybeLength, params);
  39867. }
  39868. return new LZWStream(stream, maybeLength, earlyChange);
  39869. }
  39870. if (name === 'DCTDecode' || name === 'DCT') {
  39871. xrefStreamStats[StreamType.DCT] = true;
  39872. return new JpegStream(stream, maybeLength, stream.dict, params);
  39873. }
  39874. if (name === 'JPXDecode' || name === 'JPX') {
  39875. xrefStreamStats[StreamType.JPX] = true;
  39876. return new JpxStream(stream, maybeLength, stream.dict, params);
  39877. }
  39878. if (name === 'ASCII85Decode' || name === 'A85') {
  39879. xrefStreamStats[StreamType.A85] = true;
  39880. return new Ascii85Stream(stream, maybeLength);
  39881. }
  39882. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  39883. xrefStreamStats[StreamType.AHX] = true;
  39884. return new AsciiHexStream(stream, maybeLength);
  39885. }
  39886. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  39887. xrefStreamStats[StreamType.CCF] = true;
  39888. return new CCITTFaxStream(stream, maybeLength, params);
  39889. }
  39890. if (name === 'RunLengthDecode' || name === 'RL') {
  39891. xrefStreamStats[StreamType.RL] = true;
  39892. return new RunLengthStream(stream, maybeLength);
  39893. }
  39894. if (name === 'JBIG2Decode') {
  39895. xrefStreamStats[StreamType.JBIG] = true;
  39896. return new Jbig2Stream(stream, maybeLength, stream.dict, params);
  39897. }
  39898. warn('filter "' + name + '" not supported yet');
  39899. return stream;
  39900. } catch (ex) {
  39901. if (ex instanceof MissingDataException) {
  39902. throw ex;
  39903. }
  39904. warn('Invalid stream: \"' + ex + '\"');
  39905. return new NullStream(stream);
  39906. }
  39907. }
  39908. };
  39909. return Parser;
  39910. }();
  39911. var Lexer = function LexerClosure() {
  39912. function Lexer(stream, knownCommands) {
  39913. this.stream = stream;
  39914. this.nextChar();
  39915. // While lexing, we build up many strings one char at a time. Using += for
  39916. // this can result in lots of garbage strings. It's better to build an
  39917. // array of single-char strings and then join() them together at the end.
  39918. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  39919. // purpose uses less memory than using a new array for each string.
  39920. this.strBuf = [];
  39921. // The PDFs might have "glued" commands with other commands, operands or
  39922. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  39923. // commands and their prefixes. The prefixes are built the following way:
  39924. // if there a command that is a prefix of the other valid command or
  39925. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  39926. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  39927. // other commands or literals as a prefix. The knowCommands is optional.
  39928. this.knownCommands = knownCommands;
  39929. }
  39930. // A '1' in this array means the character is white space. A '1' or
  39931. // '2' means the character ends a name or command.
  39932. var specialChars = [
  39933. 1,
  39934. 0,
  39935. 0,
  39936. 0,
  39937. 0,
  39938. 0,
  39939. 0,
  39940. 0,
  39941. 0,
  39942. 1,
  39943. 1,
  39944. 0,
  39945. 1,
  39946. 1,
  39947. 0,
  39948. 0,
  39949. // 0x
  39950. 0,
  39951. 0,
  39952. 0,
  39953. 0,
  39954. 0,
  39955. 0,
  39956. 0,
  39957. 0,
  39958. 0,
  39959. 0,
  39960. 0,
  39961. 0,
  39962. 0,
  39963. 0,
  39964. 0,
  39965. 0,
  39966. // 1x
  39967. 1,
  39968. 0,
  39969. 0,
  39970. 0,
  39971. 0,
  39972. 2,
  39973. 0,
  39974. 0,
  39975. 2,
  39976. 2,
  39977. 0,
  39978. 0,
  39979. 0,
  39980. 0,
  39981. 0,
  39982. 2,
  39983. // 2x
  39984. 0,
  39985. 0,
  39986. 0,
  39987. 0,
  39988. 0,
  39989. 0,
  39990. 0,
  39991. 0,
  39992. 0,
  39993. 0,
  39994. 0,
  39995. 0,
  39996. 2,
  39997. 0,
  39998. 2,
  39999. 0,
  40000. // 3x
  40001. 0,
  40002. 0,
  40003. 0,
  40004. 0,
  40005. 0,
  40006. 0,
  40007. 0,
  40008. 0,
  40009. 0,
  40010. 0,
  40011. 0,
  40012. 0,
  40013. 0,
  40014. 0,
  40015. 0,
  40016. 0,
  40017. // 4x
  40018. 0,
  40019. 0,
  40020. 0,
  40021. 0,
  40022. 0,
  40023. 0,
  40024. 0,
  40025. 0,
  40026. 0,
  40027. 0,
  40028. 0,
  40029. 2,
  40030. 0,
  40031. 2,
  40032. 0,
  40033. 0,
  40034. // 5x
  40035. 0,
  40036. 0,
  40037. 0,
  40038. 0,
  40039. 0,
  40040. 0,
  40041. 0,
  40042. 0,
  40043. 0,
  40044. 0,
  40045. 0,
  40046. 0,
  40047. 0,
  40048. 0,
  40049. 0,
  40050. 0,
  40051. // 6x
  40052. 0,
  40053. 0,
  40054. 0,
  40055. 0,
  40056. 0,
  40057. 0,
  40058. 0,
  40059. 0,
  40060. 0,
  40061. 0,
  40062. 0,
  40063. 2,
  40064. 0,
  40065. 2,
  40066. 0,
  40067. 0,
  40068. // 7x
  40069. 0,
  40070. 0,
  40071. 0,
  40072. 0,
  40073. 0,
  40074. 0,
  40075. 0,
  40076. 0,
  40077. 0,
  40078. 0,
  40079. 0,
  40080. 0,
  40081. 0,
  40082. 0,
  40083. 0,
  40084. 0,
  40085. // 8x
  40086. 0,
  40087. 0,
  40088. 0,
  40089. 0,
  40090. 0,
  40091. 0,
  40092. 0,
  40093. 0,
  40094. 0,
  40095. 0,
  40096. 0,
  40097. 0,
  40098. 0,
  40099. 0,
  40100. 0,
  40101. 0,
  40102. // 9x
  40103. 0,
  40104. 0,
  40105. 0,
  40106. 0,
  40107. 0,
  40108. 0,
  40109. 0,
  40110. 0,
  40111. 0,
  40112. 0,
  40113. 0,
  40114. 0,
  40115. 0,
  40116. 0,
  40117. 0,
  40118. 0,
  40119. // ax
  40120. 0,
  40121. 0,
  40122. 0,
  40123. 0,
  40124. 0,
  40125. 0,
  40126. 0,
  40127. 0,
  40128. 0,
  40129. 0,
  40130. 0,
  40131. 0,
  40132. 0,
  40133. 0,
  40134. 0,
  40135. 0,
  40136. // bx
  40137. 0,
  40138. 0,
  40139. 0,
  40140. 0,
  40141. 0,
  40142. 0,
  40143. 0,
  40144. 0,
  40145. 0,
  40146. 0,
  40147. 0,
  40148. 0,
  40149. 0,
  40150. 0,
  40151. 0,
  40152. 0,
  40153. // cx
  40154. 0,
  40155. 0,
  40156. 0,
  40157. 0,
  40158. 0,
  40159. 0,
  40160. 0,
  40161. 0,
  40162. 0,
  40163. 0,
  40164. 0,
  40165. 0,
  40166. 0,
  40167. 0,
  40168. 0,
  40169. 0,
  40170. // dx
  40171. 0,
  40172. 0,
  40173. 0,
  40174. 0,
  40175. 0,
  40176. 0,
  40177. 0,
  40178. 0,
  40179. 0,
  40180. 0,
  40181. 0,
  40182. 0,
  40183. 0,
  40184. 0,
  40185. 0,
  40186. 0,
  40187. // ex
  40188. 0,
  40189. 0,
  40190. 0,
  40191. 0,
  40192. 0,
  40193. 0,
  40194. 0,
  40195. 0,
  40196. 0,
  40197. 0,
  40198. 0,
  40199. 0,
  40200. 0,
  40201. 0,
  40202. 0,
  40203. 0
  40204. ];
  40205. // fx
  40206. function toHexDigit(ch) {
  40207. if (ch >= 0x30 && ch <= 0x39) {
  40208. // '0'-'9'
  40209. return ch & 0x0F;
  40210. }
  40211. if (ch >= 0x41 && ch <= 0x46 || ch >= 0x61 && ch <= 0x66) {
  40212. // 'A'-'F', 'a'-'f'
  40213. return (ch & 0x0F) + 9;
  40214. }
  40215. return -1;
  40216. }
  40217. Lexer.prototype = {
  40218. nextChar: function Lexer_nextChar() {
  40219. return this.currentChar = this.stream.getByte();
  40220. },
  40221. peekChar: function Lexer_peekChar() {
  40222. return this.stream.peekByte();
  40223. },
  40224. getNumber: function Lexer_getNumber() {
  40225. var ch = this.currentChar;
  40226. var eNotation = false;
  40227. var divideBy = 0;
  40228. // different from 0 if it's a floating point value
  40229. var sign = 1;
  40230. if (ch === 0x2D) {
  40231. // '-'
  40232. sign = -1;
  40233. ch = this.nextChar();
  40234. if (ch === 0x2D) {
  40235. // '-'
  40236. // Ignore double negative (this is consistent with Adobe Reader).
  40237. ch = this.nextChar();
  40238. }
  40239. } else if (ch === 0x2B) {
  40240. // '+'
  40241. ch = this.nextChar();
  40242. }
  40243. if (ch === 0x2E) {
  40244. // '.'
  40245. divideBy = 10;
  40246. ch = this.nextChar();
  40247. }
  40248. if (ch < 0x30 || ch > 0x39) {
  40249. // '0' - '9'
  40250. error('Invalid number: ' + String.fromCharCode(ch));
  40251. return 0;
  40252. }
  40253. var baseValue = ch - 0x30;
  40254. // '0'
  40255. var powerValue = 0;
  40256. var powerValueSign = 1;
  40257. while ((ch = this.nextChar()) >= 0) {
  40258. if (0x30 <= ch && ch <= 0x39) {
  40259. // '0' - '9'
  40260. var currentDigit = ch - 0x30;
  40261. // '0'
  40262. if (eNotation) {
  40263. // We are after an 'e' or 'E'
  40264. powerValue = powerValue * 10 + currentDigit;
  40265. } else {
  40266. if (divideBy !== 0) {
  40267. // We are after a point
  40268. divideBy *= 10;
  40269. }
  40270. baseValue = baseValue * 10 + currentDigit;
  40271. }
  40272. } else if (ch === 0x2E) {
  40273. // '.'
  40274. if (divideBy === 0) {
  40275. divideBy = 1;
  40276. } else {
  40277. // A number can have only one '.'
  40278. break;
  40279. }
  40280. } else if (ch === 0x2D) {
  40281. // '-'
  40282. // ignore minus signs in the middle of numbers to match
  40283. // Adobe's behavior
  40284. warn('Badly formatted number');
  40285. } else if (ch === 0x45 || ch === 0x65) {
  40286. // 'E', 'e'
  40287. // 'E' can be either a scientific notation or the beginning of a new
  40288. // operator
  40289. ch = this.peekChar();
  40290. if (ch === 0x2B || ch === 0x2D) {
  40291. // '+', '-'
  40292. powerValueSign = ch === 0x2D ? -1 : 1;
  40293. this.nextChar();
  40294. } else // Consume the sign character
  40295. if (ch < 0x30 || ch > 0x39) {
  40296. // '0' - '9'
  40297. // The 'E' must be the beginning of a new operator
  40298. break;
  40299. }
  40300. eNotation = true;
  40301. } else {
  40302. // the last character doesn't belong to us
  40303. break;
  40304. }
  40305. }
  40306. if (divideBy !== 0) {
  40307. baseValue /= divideBy;
  40308. }
  40309. if (eNotation) {
  40310. baseValue *= Math.pow(10, powerValueSign * powerValue);
  40311. }
  40312. return sign * baseValue;
  40313. },
  40314. getString: function Lexer_getString() {
  40315. var numParen = 1;
  40316. var done = false;
  40317. var strBuf = this.strBuf;
  40318. strBuf.length = 0;
  40319. var ch = this.nextChar();
  40320. while (true) {
  40321. var charBuffered = false;
  40322. switch (ch | 0) {
  40323. case -1:
  40324. warn('Unterminated string');
  40325. done = true;
  40326. break;
  40327. case 0x28:
  40328. // '('
  40329. ++numParen;
  40330. strBuf.push('(');
  40331. break;
  40332. case 0x29:
  40333. // ')'
  40334. if (--numParen === 0) {
  40335. this.nextChar();
  40336. // consume strings ')'
  40337. done = true;
  40338. } else {
  40339. strBuf.push(')');
  40340. }
  40341. break;
  40342. case 0x5C:
  40343. // '\\'
  40344. ch = this.nextChar();
  40345. switch (ch) {
  40346. case -1:
  40347. warn('Unterminated string');
  40348. done = true;
  40349. break;
  40350. case 0x6E:
  40351. // 'n'
  40352. strBuf.push('\n');
  40353. break;
  40354. case 0x72:
  40355. // 'r'
  40356. strBuf.push('\r');
  40357. break;
  40358. case 0x74:
  40359. // 't'
  40360. strBuf.push('\t');
  40361. break;
  40362. case 0x62:
  40363. // 'b'
  40364. strBuf.push('\b');
  40365. break;
  40366. case 0x66:
  40367. // 'f'
  40368. strBuf.push('\f');
  40369. break;
  40370. case 0x5C:
  40371. // '\'
  40372. case 0x28:
  40373. // '('
  40374. case 0x29:
  40375. // ')'
  40376. strBuf.push(String.fromCharCode(ch));
  40377. break;
  40378. case 0x30:
  40379. case 0x31:
  40380. case 0x32:
  40381. case 0x33:
  40382. // '0'-'3'
  40383. case 0x34:
  40384. case 0x35:
  40385. case 0x36:
  40386. case 0x37:
  40387. // '4'-'7'
  40388. var x = ch & 0x0F;
  40389. ch = this.nextChar();
  40390. charBuffered = true;
  40391. if (ch >= 0x30 && ch <= 0x37) {
  40392. // '0'-'7'
  40393. x = (x << 3) + (ch & 0x0F);
  40394. ch = this.nextChar();
  40395. if (ch >= 0x30 && ch <= 0x37) {
  40396. // '0'-'7'
  40397. charBuffered = false;
  40398. x = (x << 3) + (ch & 0x0F);
  40399. }
  40400. }
  40401. strBuf.push(String.fromCharCode(x));
  40402. break;
  40403. case 0x0D:
  40404. // CR
  40405. if (this.peekChar() === 0x0A) {
  40406. // LF
  40407. this.nextChar();
  40408. }
  40409. break;
  40410. case 0x0A:
  40411. // LF
  40412. break;
  40413. default:
  40414. strBuf.push(String.fromCharCode(ch));
  40415. break;
  40416. }
  40417. break;
  40418. default:
  40419. strBuf.push(String.fromCharCode(ch));
  40420. break;
  40421. }
  40422. if (done) {
  40423. break;
  40424. }
  40425. if (!charBuffered) {
  40426. ch = this.nextChar();
  40427. }
  40428. }
  40429. return strBuf.join('');
  40430. },
  40431. getName: function Lexer_getName() {
  40432. var ch, previousCh;
  40433. var strBuf = this.strBuf;
  40434. strBuf.length = 0;
  40435. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  40436. if (ch === 0x23) {
  40437. // '#'
  40438. ch = this.nextChar();
  40439. if (specialChars[ch]) {
  40440. warn('Lexer_getName: ' + 'NUMBER SIGN (#) should be followed by a hexadecimal number.');
  40441. strBuf.push('#');
  40442. break;
  40443. }
  40444. var x = toHexDigit(ch);
  40445. if (x !== -1) {
  40446. previousCh = ch;
  40447. ch = this.nextChar();
  40448. var x2 = toHexDigit(ch);
  40449. if (x2 === -1) {
  40450. warn('Lexer_getName: Illegal digit (' + String.fromCharCode(ch) + ') in hexadecimal number.');
  40451. strBuf.push('#', String.fromCharCode(previousCh));
  40452. if (specialChars[ch]) {
  40453. break;
  40454. }
  40455. strBuf.push(String.fromCharCode(ch));
  40456. continue;
  40457. }
  40458. strBuf.push(String.fromCharCode(x << 4 | x2));
  40459. } else {
  40460. strBuf.push('#', String.fromCharCode(ch));
  40461. }
  40462. } else {
  40463. strBuf.push(String.fromCharCode(ch));
  40464. }
  40465. }
  40466. if (strBuf.length > 127) {
  40467. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  40468. }
  40469. return Name.get(strBuf.join(''));
  40470. },
  40471. getHexString: function Lexer_getHexString() {
  40472. var strBuf = this.strBuf;
  40473. strBuf.length = 0;
  40474. var ch = this.currentChar;
  40475. var isFirstHex = true;
  40476. var firstDigit;
  40477. var secondDigit;
  40478. while (true) {
  40479. if (ch < 0) {
  40480. warn('Unterminated hex string');
  40481. break;
  40482. } else if (ch === 0x3E) {
  40483. // '>'
  40484. this.nextChar();
  40485. break;
  40486. } else if (specialChars[ch] === 1) {
  40487. ch = this.nextChar();
  40488. continue;
  40489. } else {
  40490. if (isFirstHex) {
  40491. firstDigit = toHexDigit(ch);
  40492. if (firstDigit === -1) {
  40493. warn('Ignoring invalid character "' + ch + '" in hex string');
  40494. ch = this.nextChar();
  40495. continue;
  40496. }
  40497. } else {
  40498. secondDigit = toHexDigit(ch);
  40499. if (secondDigit === -1) {
  40500. warn('Ignoring invalid character "' + ch + '" in hex string');
  40501. ch = this.nextChar();
  40502. continue;
  40503. }
  40504. strBuf.push(String.fromCharCode(firstDigit << 4 | secondDigit));
  40505. }
  40506. isFirstHex = !isFirstHex;
  40507. ch = this.nextChar();
  40508. }
  40509. }
  40510. return strBuf.join('');
  40511. },
  40512. getObj: function Lexer_getObj() {
  40513. // skip whitespace and comments
  40514. var comment = false;
  40515. var ch = this.currentChar;
  40516. while (true) {
  40517. if (ch < 0) {
  40518. return EOF;
  40519. }
  40520. if (comment) {
  40521. if (ch === 0x0A || ch === 0x0D) {
  40522. // LF, CR
  40523. comment = false;
  40524. }
  40525. } else if (ch === 0x25) {
  40526. // '%'
  40527. comment = true;
  40528. } else if (specialChars[ch] !== 1) {
  40529. break;
  40530. }
  40531. ch = this.nextChar();
  40532. }
  40533. // start reading token
  40534. switch (ch | 0) {
  40535. case 0x30:
  40536. case 0x31:
  40537. case 0x32:
  40538. case 0x33:
  40539. case 0x34:
  40540. // '0'-'4'
  40541. case 0x35:
  40542. case 0x36:
  40543. case 0x37:
  40544. case 0x38:
  40545. case 0x39:
  40546. // '5'-'9'
  40547. case 0x2B:
  40548. case 0x2D:
  40549. case 0x2E:
  40550. // '+', '-', '.'
  40551. return this.getNumber();
  40552. case 0x28:
  40553. // '('
  40554. return this.getString();
  40555. case 0x2F:
  40556. // '/'
  40557. return this.getName();
  40558. // array punctuation
  40559. case 0x5B:
  40560. // '['
  40561. this.nextChar();
  40562. return Cmd.get('[');
  40563. case 0x5D:
  40564. // ']'
  40565. this.nextChar();
  40566. return Cmd.get(']');
  40567. // hex string or dict punctuation
  40568. case 0x3C:
  40569. // '<'
  40570. ch = this.nextChar();
  40571. if (ch === 0x3C) {
  40572. // dict punctuation
  40573. this.nextChar();
  40574. return Cmd.get('<<');
  40575. }
  40576. return this.getHexString();
  40577. // dict punctuation
  40578. case 0x3E:
  40579. // '>'
  40580. ch = this.nextChar();
  40581. if (ch === 0x3E) {
  40582. this.nextChar();
  40583. return Cmd.get('>>');
  40584. }
  40585. return Cmd.get('>');
  40586. case 0x7B:
  40587. // '{'
  40588. this.nextChar();
  40589. return Cmd.get('{');
  40590. case 0x7D:
  40591. // '}'
  40592. this.nextChar();
  40593. return Cmd.get('}');
  40594. case 0x29:
  40595. // ')'
  40596. error('Illegal character: ' + ch);
  40597. break;
  40598. }
  40599. // command
  40600. var str = String.fromCharCode(ch);
  40601. var knownCommands = this.knownCommands;
  40602. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  40603. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  40604. // stop if known command is found and next character does not make
  40605. // the str a command
  40606. var possibleCommand = str + String.fromCharCode(ch);
  40607. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  40608. break;
  40609. }
  40610. if (str.length === 128) {
  40611. error('Command token too long: ' + str.length);
  40612. }
  40613. str = possibleCommand;
  40614. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  40615. }
  40616. if (str === 'true') {
  40617. return true;
  40618. }
  40619. if (str === 'false') {
  40620. return false;
  40621. }
  40622. if (str === 'null') {
  40623. return null;
  40624. }
  40625. return Cmd.get(str);
  40626. },
  40627. skipToNextLine: function Lexer_skipToNextLine() {
  40628. var ch = this.currentChar;
  40629. while (ch >= 0) {
  40630. if (ch === 0x0D) {
  40631. // CR
  40632. ch = this.nextChar();
  40633. if (ch === 0x0A) {
  40634. // LF
  40635. this.nextChar();
  40636. }
  40637. break;
  40638. } else if (ch === 0x0A) {
  40639. // LF
  40640. this.nextChar();
  40641. break;
  40642. }
  40643. ch = this.nextChar();
  40644. }
  40645. }
  40646. };
  40647. return Lexer;
  40648. }();
  40649. var Linearization = {
  40650. create: function LinearizationCreate(stream) {
  40651. function getInt(name, allowZeroValue) {
  40652. var obj = linDict.get(name);
  40653. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  40654. return obj;
  40655. }
  40656. throw new Error('The "' + name + '" parameter in the linearization ' + 'dictionary is invalid.');
  40657. }
  40658. function getHints() {
  40659. var hints = linDict.get('H'), hintsLength, item;
  40660. if (isArray(hints) && ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  40661. for (var index = 0; index < hintsLength; index++) {
  40662. if (!(isInt(item = hints[index]) && item > 0)) {
  40663. throw new Error('Hint (' + index + ') in the linearization dictionary is invalid.');
  40664. }
  40665. }
  40666. return hints;
  40667. }
  40668. throw new Error('Hint array in the linearization dictionary is invalid.');
  40669. }
  40670. var parser = new Parser(new Lexer(stream), false, null);
  40671. var obj1 = parser.getObj();
  40672. var obj2 = parser.getObj();
  40673. var obj3 = parser.getObj();
  40674. var linDict = parser.getObj();
  40675. var obj, length;
  40676. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) && isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  40677. return null;
  40678. } else // No valid linearization dictionary found.
  40679. if ((length = getInt('L')) !== stream.length) {
  40680. throw new Error('The "L" parameter in the linearization dictionary ' + 'does not equal the stream length.');
  40681. }
  40682. return {
  40683. length: length,
  40684. hints: getHints(),
  40685. objectNumberFirst: getInt('O'),
  40686. endFirst: getInt('E'),
  40687. numPages: getInt('N'),
  40688. mainXRefEntriesOffset: getInt('T'),
  40689. pageFirst: linDict.has('P') ? getInt('P', true) : 0
  40690. };
  40691. }
  40692. };
  40693. exports.EOF = EOF;
  40694. exports.Lexer = Lexer;
  40695. exports.Linearization = Linearization;
  40696. exports.Parser = Parser;
  40697. exports.isEOF = isEOF;
  40698. }));
  40699. (function (root, factory) {
  40700. factory(root.pdfjsCoreType1Parser = {}, root.pdfjsSharedUtil, root.pdfjsCoreStream, root.pdfjsCoreEncodings);
  40701. }(this, function (exports, sharedUtil, coreStream, coreEncodings) {
  40702. var warn = sharedUtil.warn;
  40703. var isSpace = sharedUtil.isSpace;
  40704. var Stream = coreStream.Stream;
  40705. var getEncoding = coreEncodings.getEncoding;
  40706. // Hinting is currently disabled due to unknown problems on windows
  40707. // in tracemonkey and various other pdfs with type1 fonts.
  40708. var HINTING_ENABLED = false;
  40709. /*
  40710. * CharStrings are encoded following the the CharString Encoding sequence
  40711. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  40712. * The value in a byte indicates a command, a number, or subsequent bytes
  40713. * that are to be interpreted in a special way.
  40714. *
  40715. * CharString Number Encoding:
  40716. * A CharString byte containing the values from 32 through 255 inclusive
  40717. * indicate an integer. These values are decoded in four ranges.
  40718. *
  40719. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  40720. * indicate the integer v - 139. Thus, the integer values from -107 through
  40721. * 107 inclusive may be encoded in single byte.
  40722. *
  40723. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  40724. * indicates an integer involving the next byte, w, according to the formula:
  40725. * [(v - 247) x 256] + w + 108
  40726. *
  40727. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  40728. * indicates an integer involving the next byte, w, according to the formula:
  40729. * -[(v - 251) * 256] - w - 108
  40730. *
  40731. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  40732. * are a two complement signed integer. The first of these bytes contains the
  40733. * highest order bits, the second byte contains the next higher order bits
  40734. * and the fourth byte contain the lowest order bits.
  40735. *
  40736. *
  40737. * CharString Command Encoding:
  40738. * CharStrings commands are encoded in 1 or 2 bytes.
  40739. *
  40740. * Single byte commands are encoded in 1 byte that contains a value between
  40741. * 0 and 31 inclusive.
  40742. * If a command byte contains the value 12, then the value in the next byte
  40743. * indicates a command. This "escape" mechanism allows many extra commands
  40744. * to be encoded and this encoding technique helps to minimize the length of
  40745. * the charStrings.
  40746. */
  40747. var Type1CharString = function Type1CharStringClosure() {
  40748. var COMMAND_MAP = {
  40749. 'hstem': [1],
  40750. 'vstem': [3],
  40751. 'vmoveto': [4],
  40752. 'rlineto': [5],
  40753. 'hlineto': [6],
  40754. 'vlineto': [7],
  40755. 'rrcurveto': [8],
  40756. 'callsubr': [10],
  40757. 'flex': [
  40758. 12,
  40759. 35
  40760. ],
  40761. 'drop': [
  40762. 12,
  40763. 18
  40764. ],
  40765. 'endchar': [14],
  40766. 'rmoveto': [21],
  40767. 'hmoveto': [22],
  40768. 'vhcurveto': [30],
  40769. 'hvcurveto': [31]
  40770. };
  40771. function Type1CharString() {
  40772. this.width = 0;
  40773. this.lsb = 0;
  40774. this.flexing = false;
  40775. this.output = [];
  40776. this.stack = [];
  40777. }
  40778. Type1CharString.prototype = {
  40779. convert: function Type1CharString_convert(encoded, subrs, seacAnalysisEnabled) {
  40780. var count = encoded.length;
  40781. var error = false;
  40782. var wx, sbx, subrNumber;
  40783. for (var i = 0; i < count; i++) {
  40784. var value = encoded[i];
  40785. if (value < 32) {
  40786. if (value === 12) {
  40787. value = (value << 8) + encoded[++i];
  40788. }
  40789. switch (value) {
  40790. case 1:
  40791. // hstem
  40792. if (!HINTING_ENABLED) {
  40793. this.stack = [];
  40794. break;
  40795. }
  40796. error = this.executeCommand(2, COMMAND_MAP.hstem);
  40797. break;
  40798. case 3:
  40799. // vstem
  40800. if (!HINTING_ENABLED) {
  40801. this.stack = [];
  40802. break;
  40803. }
  40804. error = this.executeCommand(2, COMMAND_MAP.vstem);
  40805. break;
  40806. case 4:
  40807. // vmoveto
  40808. if (this.flexing) {
  40809. if (this.stack.length < 1) {
  40810. error = true;
  40811. break;
  40812. }
  40813. // Add the dx for flex and but also swap the values so they are
  40814. // the right order.
  40815. var dy = this.stack.pop();
  40816. this.stack.push(0, dy);
  40817. break;
  40818. }
  40819. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  40820. break;
  40821. case 5:
  40822. // rlineto
  40823. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  40824. break;
  40825. case 6:
  40826. // hlineto
  40827. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  40828. break;
  40829. case 7:
  40830. // vlineto
  40831. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  40832. break;
  40833. case 8:
  40834. // rrcurveto
  40835. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  40836. break;
  40837. case 9:
  40838. // closepath
  40839. // closepath is a Type1 command that does not take argument and is
  40840. // useless in Type2 and it can simply be ignored.
  40841. this.stack = [];
  40842. break;
  40843. case 10:
  40844. // callsubr
  40845. if (this.stack.length < 1) {
  40846. error = true;
  40847. break;
  40848. }
  40849. subrNumber = this.stack.pop();
  40850. error = this.convert(subrs[subrNumber], subrs, seacAnalysisEnabled);
  40851. break;
  40852. case 11:
  40853. // return
  40854. return error;
  40855. case 13:
  40856. // hsbw
  40857. if (this.stack.length < 2) {
  40858. error = true;
  40859. break;
  40860. }
  40861. // To convert to type2 we have to move the width value to the
  40862. // first part of the charstring and then use hmoveto with lsb.
  40863. wx = this.stack.pop();
  40864. sbx = this.stack.pop();
  40865. this.lsb = sbx;
  40866. this.width = wx;
  40867. this.stack.push(wx, sbx);
  40868. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  40869. break;
  40870. case 14:
  40871. // endchar
  40872. this.output.push(COMMAND_MAP.endchar[0]);
  40873. break;
  40874. case 21:
  40875. // rmoveto
  40876. if (this.flexing) {
  40877. break;
  40878. }
  40879. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  40880. break;
  40881. case 22:
  40882. // hmoveto
  40883. if (this.flexing) {
  40884. // Add the dy for flex.
  40885. this.stack.push(0);
  40886. break;
  40887. }
  40888. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  40889. break;
  40890. case 30:
  40891. // vhcurveto
  40892. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  40893. break;
  40894. case 31:
  40895. // hvcurveto
  40896. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  40897. break;
  40898. case (12 << 8) + 0:
  40899. // dotsection
  40900. // dotsection is a Type1 command to specify some hinting feature
  40901. // for dots that do not take a parameter and it can safely be
  40902. // ignored for Type2.
  40903. this.stack = [];
  40904. break;
  40905. case (12 << 8) + 1:
  40906. // vstem3
  40907. if (!HINTING_ENABLED) {
  40908. this.stack = [];
  40909. break;
  40910. }
  40911. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  40912. // multiple parameters, so instead of returning [vh]stem3 take a
  40913. // shortcut and return [vhstem] instead.
  40914. error = this.executeCommand(2, COMMAND_MAP.vstem);
  40915. break;
  40916. case (12 << 8) + 2:
  40917. // hstem3
  40918. if (!HINTING_ENABLED) {
  40919. this.stack = [];
  40920. break;
  40921. }
  40922. // See vstem3.
  40923. error = this.executeCommand(2, COMMAND_MAP.hstem);
  40924. break;
  40925. case (12 << 8) + 6:
  40926. // seac
  40927. // seac is like type 2's special endchar but it doesn't use the
  40928. // first argument asb, so remove it.
  40929. if (seacAnalysisEnabled) {
  40930. this.seac = this.stack.splice(-4, 4);
  40931. error = this.executeCommand(0, COMMAND_MAP.endchar);
  40932. } else {
  40933. error = this.executeCommand(4, COMMAND_MAP.endchar);
  40934. }
  40935. break;
  40936. case (12 << 8) + 7:
  40937. // sbw
  40938. if (this.stack.length < 4) {
  40939. error = true;
  40940. break;
  40941. }
  40942. // To convert to type2 we have to move the width value to the
  40943. // first part of the charstring and then use rmoveto with
  40944. // (dx, dy). The height argument will not be used for vmtx and
  40945. // vhea tables reconstruction -- ignoring it.
  40946. var wy = this.stack.pop();
  40947. wx = this.stack.pop();
  40948. var sby = this.stack.pop();
  40949. sbx = this.stack.pop();
  40950. this.lsb = sbx;
  40951. this.width = wx;
  40952. this.stack.push(wx, sbx, sby);
  40953. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  40954. break;
  40955. case (12 << 8) + 12:
  40956. // div
  40957. if (this.stack.length < 2) {
  40958. error = true;
  40959. break;
  40960. }
  40961. var num2 = this.stack.pop();
  40962. var num1 = this.stack.pop();
  40963. this.stack.push(num1 / num2);
  40964. break;
  40965. case (12 << 8) + 16:
  40966. // callothersubr
  40967. if (this.stack.length < 2) {
  40968. error = true;
  40969. break;
  40970. }
  40971. subrNumber = this.stack.pop();
  40972. var numArgs = this.stack.pop();
  40973. if (subrNumber === 0 && numArgs === 3) {
  40974. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  40975. this.stack.push(flexArgs[2] + flexArgs[0], // bcp1x + rpx
  40976. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  40977. flexArgs[4], // bcp2x
  40978. flexArgs[5], // bcp2y
  40979. flexArgs[6], // p2x
  40980. flexArgs[7], // p2y
  40981. flexArgs[8], // bcp3x
  40982. flexArgs[9], // bcp3y
  40983. flexArgs[10], // bcp4x
  40984. flexArgs[11], // bcp4y
  40985. flexArgs[12], // p3x
  40986. flexArgs[13], // p3y
  40987. flexArgs[14]);
  40988. // flexDepth
  40989. // 15 = finalx unused by flex
  40990. // 16 = finaly unused by flex
  40991. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  40992. this.flexing = false;
  40993. this.stack.push(flexArgs[15], flexArgs[16]);
  40994. } else if (subrNumber === 1 && numArgs === 0) {
  40995. this.flexing = true;
  40996. }
  40997. break;
  40998. case (12 << 8) + 17:
  40999. // pop
  41000. // Ignore this since it is only used with othersubr.
  41001. break;
  41002. case (12 << 8) + 33:
  41003. // setcurrentpoint
  41004. // Ignore for now.
  41005. this.stack = [];
  41006. break;
  41007. default:
  41008. warn('Unknown type 1 charstring command of "' + value + '"');
  41009. break;
  41010. }
  41011. if (error) {
  41012. break;
  41013. }
  41014. continue;
  41015. } else if (value <= 246) {
  41016. value = value - 139;
  41017. } else if (value <= 250) {
  41018. value = (value - 247) * 256 + encoded[++i] + 108;
  41019. } else if (value <= 254) {
  41020. value = -((value - 251) * 256) - encoded[++i] - 108;
  41021. } else {
  41022. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 | (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  41023. }
  41024. this.stack.push(value);
  41025. }
  41026. return error;
  41027. },
  41028. executeCommand: function (howManyArgs, command, keepStack) {
  41029. var stackLength = this.stack.length;
  41030. if (howManyArgs > stackLength) {
  41031. return true;
  41032. }
  41033. var start = stackLength - howManyArgs;
  41034. for (var i = start; i < stackLength; i++) {
  41035. var value = this.stack[i];
  41036. if (value === (value | 0)) {
  41037. // int
  41038. this.output.push(28, value >> 8 & 0xff, value & 0xff);
  41039. } else {
  41040. // fixed point
  41041. value = 65536 * value | 0;
  41042. this.output.push(255, value >> 24 & 0xFF, value >> 16 & 0xFF, value >> 8 & 0xFF, value & 0xFF);
  41043. }
  41044. }
  41045. this.output.push.apply(this.output, command);
  41046. if (keepStack) {
  41047. this.stack.splice(start, howManyArgs);
  41048. } else {
  41049. this.stack.length = 0;
  41050. }
  41051. return false;
  41052. }
  41053. };
  41054. return Type1CharString;
  41055. }();
  41056. /*
  41057. * Type1Parser encapsulate the needed code for parsing a Type1 font
  41058. * program. Some of its logic depends on the Type2 charstrings
  41059. * structure.
  41060. * Note: this doesn't really parse the font since that would require evaluation
  41061. * of PostScript, but it is possible in most cases to extract what we need
  41062. * without a full parse.
  41063. */
  41064. var Type1Parser = function Type1ParserClosure() {
  41065. /*
  41066. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  41067. * of Plaintext Bytes. The function took a key as a parameter which can be
  41068. * for decrypting the eexec block of for decoding charStrings.
  41069. */
  41070. var EEXEC_ENCRYPT_KEY = 55665;
  41071. var CHAR_STRS_ENCRYPT_KEY = 4330;
  41072. function isHexDigit(code) {
  41073. return code >= 48 && code <= 57 || // '0'-'9'
  41074. code >= 65 && code <= 70 || // 'A'-'F'
  41075. code >= 97 && code <= 102;
  41076. }
  41077. // 'a'-'f'
  41078. function decrypt(data, key, discardNumber) {
  41079. if (discardNumber >= data.length) {
  41080. return new Uint8Array(0);
  41081. }
  41082. var r = key | 0, c1 = 52845, c2 = 22719, i, j;
  41083. for (i = 0; i < discardNumber; i++) {
  41084. r = (data[i] + r) * c1 + c2 & (1 << 16) - 1;
  41085. }
  41086. var count = data.length - discardNumber;
  41087. var decrypted = new Uint8Array(count);
  41088. for (i = discardNumber, j = 0; j < count; i++, j++) {
  41089. var value = data[i];
  41090. decrypted[j] = value ^ r >> 8;
  41091. r = (value + r) * c1 + c2 & (1 << 16) - 1;
  41092. }
  41093. return decrypted;
  41094. }
  41095. function decryptAscii(data, key, discardNumber) {
  41096. var r = key | 0, c1 = 52845, c2 = 22719;
  41097. var count = data.length, maybeLength = count >>> 1;
  41098. var decrypted = new Uint8Array(maybeLength);
  41099. var i, j;
  41100. for (i = 0, j = 0; i < count; i++) {
  41101. var digit1 = data[i];
  41102. if (!isHexDigit(digit1)) {
  41103. continue;
  41104. }
  41105. i++;
  41106. var digit2;
  41107. while (i < count && !isHexDigit(digit2 = data[i])) {
  41108. i++;
  41109. }
  41110. if (i < count) {
  41111. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  41112. decrypted[j++] = value ^ r >> 8;
  41113. r = (value + r) * c1 + c2 & (1 << 16) - 1;
  41114. }
  41115. }
  41116. return Array.prototype.slice.call(decrypted, discardNumber, j);
  41117. }
  41118. function isSpecial(c) {
  41119. return c === 0x2F || // '/'
  41120. c === 0x5B || c === 0x5D || // '[', ']'
  41121. c === 0x7B || c === 0x7D || // '{', '}'
  41122. c === 0x28 || c === 0x29;
  41123. }
  41124. // '(', ')'
  41125. function Type1Parser(stream, encrypted, seacAnalysisEnabled) {
  41126. if (encrypted) {
  41127. var data = stream.getBytes();
  41128. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) && isHexDigit(data[2]) && isHexDigit(data[3]));
  41129. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) : decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  41130. }
  41131. this.seacAnalysisEnabled = !!seacAnalysisEnabled;
  41132. this.stream = stream;
  41133. this.nextChar();
  41134. }
  41135. Type1Parser.prototype = {
  41136. readNumberArray: function Type1Parser_readNumberArray() {
  41137. this.getToken();
  41138. // read '[' or '{' (arrays can start with either)
  41139. var array = [];
  41140. while (true) {
  41141. var token = this.getToken();
  41142. if (token === null || token === ']' || token === '}') {
  41143. break;
  41144. }
  41145. array.push(parseFloat(token || 0));
  41146. }
  41147. return array;
  41148. },
  41149. readNumber: function Type1Parser_readNumber() {
  41150. var token = this.getToken();
  41151. return parseFloat(token || 0);
  41152. },
  41153. readInt: function Type1Parser_readInt() {
  41154. // Use '| 0' to prevent setting a double into length such as the double
  41155. // does not flow into the loop variable.
  41156. var token = this.getToken();
  41157. return parseInt(token || 0, 10) | 0;
  41158. },
  41159. readBoolean: function Type1Parser_readBoolean() {
  41160. var token = this.getToken();
  41161. // Use 1 and 0 since that's what type2 charstrings use.
  41162. return token === 'true' ? 1 : 0;
  41163. },
  41164. nextChar: function Type1_nextChar() {
  41165. return this.currentChar = this.stream.getByte();
  41166. },
  41167. getToken: function Type1Parser_getToken() {
  41168. // Eat whitespace and comments.
  41169. var comment = false;
  41170. var ch = this.currentChar;
  41171. while (true) {
  41172. if (ch === -1) {
  41173. return null;
  41174. }
  41175. if (comment) {
  41176. if (ch === 0x0A || ch === 0x0D) {
  41177. comment = false;
  41178. }
  41179. } else if (ch === 0x25) {
  41180. // '%'
  41181. comment = true;
  41182. } else if (!isSpace(ch)) {
  41183. break;
  41184. }
  41185. ch = this.nextChar();
  41186. }
  41187. if (isSpecial(ch)) {
  41188. this.nextChar();
  41189. return String.fromCharCode(ch);
  41190. }
  41191. var token = '';
  41192. do {
  41193. token += String.fromCharCode(ch);
  41194. ch = this.nextChar();
  41195. } while (ch >= 0 && !isSpace(ch) && !isSpecial(ch));
  41196. return token;
  41197. },
  41198. /*
  41199. * Returns an object containing a Subrs array and a CharStrings
  41200. * array extracted from and eexec encrypted block of data
  41201. */
  41202. extractFontProgram: function Type1Parser_extractFontProgram() {
  41203. var stream = this.stream;
  41204. var subrs = [], charstrings = [];
  41205. var privateData = Object.create(null);
  41206. privateData['lenIV'] = 4;
  41207. var program = {
  41208. subrs: [],
  41209. charstrings: [],
  41210. properties: { 'privateData': privateData }
  41211. };
  41212. var token, length, data, lenIV, encoded;
  41213. while ((token = this.getToken()) !== null) {
  41214. if (token !== '/') {
  41215. continue;
  41216. }
  41217. token = this.getToken();
  41218. switch (token) {
  41219. case 'CharStrings':
  41220. // The number immediately following CharStrings must be greater or
  41221. // equal to the number of CharStrings.
  41222. this.getToken();
  41223. this.getToken();
  41224. // read in 'dict'
  41225. this.getToken();
  41226. // read in 'dup'
  41227. this.getToken();
  41228. // read in 'begin'
  41229. while (true) {
  41230. token = this.getToken();
  41231. if (token === null || token === 'end') {
  41232. break;
  41233. }
  41234. if (token !== '/') {
  41235. continue;
  41236. }
  41237. var glyph = this.getToken();
  41238. length = this.readInt();
  41239. this.getToken();
  41240. // read in 'RD' or '-|'
  41241. data = stream.makeSubStream(stream.pos, length);
  41242. lenIV = program.properties.privateData['lenIV'];
  41243. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  41244. // Skip past the required space and binary data.
  41245. stream.skip(length);
  41246. this.nextChar();
  41247. token = this.getToken();
  41248. // read in 'ND' or '|-'
  41249. if (token === 'noaccess') {
  41250. this.getToken();
  41251. }
  41252. // read in 'def'
  41253. charstrings.push({
  41254. glyph: glyph,
  41255. encoded: encoded
  41256. });
  41257. }
  41258. break;
  41259. case 'Subrs':
  41260. var num = this.readInt();
  41261. this.getToken();
  41262. // read in 'array'
  41263. while ((token = this.getToken()) === 'dup') {
  41264. var index = this.readInt();
  41265. length = this.readInt();
  41266. this.getToken();
  41267. // read in 'RD' or '-|'
  41268. data = stream.makeSubStream(stream.pos, length);
  41269. lenIV = program.properties.privateData['lenIV'];
  41270. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  41271. // Skip past the required space and binary data.
  41272. stream.skip(length);
  41273. this.nextChar();
  41274. token = this.getToken();
  41275. // read in 'NP' or '|'
  41276. if (token === 'noaccess') {
  41277. this.getToken();
  41278. }
  41279. // read in 'put'
  41280. subrs[index] = encoded;
  41281. }
  41282. break;
  41283. case 'BlueValues':
  41284. case 'OtherBlues':
  41285. case 'FamilyBlues':
  41286. case 'FamilyOtherBlues':
  41287. var blueArray = this.readNumberArray();
  41288. // *Blue* values may contain invalid data: disables reading of
  41289. // those values when hinting is disabled.
  41290. if (blueArray.length > 0 && blueArray.length % 2 === 0 && HINTING_ENABLED) {
  41291. program.properties.privateData[token] = blueArray;
  41292. }
  41293. break;
  41294. case 'StemSnapH':
  41295. case 'StemSnapV':
  41296. program.properties.privateData[token] = this.readNumberArray();
  41297. break;
  41298. case 'StdHW':
  41299. case 'StdVW':
  41300. program.properties.privateData[token] = this.readNumberArray()[0];
  41301. break;
  41302. case 'BlueShift':
  41303. case 'lenIV':
  41304. case 'BlueFuzz':
  41305. case 'BlueScale':
  41306. case 'LanguageGroup':
  41307. case 'ExpansionFactor':
  41308. program.properties.privateData[token] = this.readNumber();
  41309. break;
  41310. case 'ForceBold':
  41311. program.properties.privateData[token] = this.readBoolean();
  41312. break;
  41313. }
  41314. }
  41315. for (var i = 0; i < charstrings.length; i++) {
  41316. glyph = charstrings[i].glyph;
  41317. encoded = charstrings[i].encoded;
  41318. var charString = new Type1CharString();
  41319. var error = charString.convert(encoded, subrs, this.seacAnalysisEnabled);
  41320. var output = charString.output;
  41321. if (error) {
  41322. // It seems when FreeType encounters an error while evaluating a glyph
  41323. // that it completely ignores the glyph so we'll mimic that behaviour
  41324. // here and put an endchar to make the validator happy.
  41325. output = [14];
  41326. }
  41327. program.charstrings.push({
  41328. glyphName: glyph,
  41329. charstring: output,
  41330. width: charString.width,
  41331. lsb: charString.lsb,
  41332. seac: charString.seac
  41333. });
  41334. }
  41335. return program;
  41336. },
  41337. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  41338. var token;
  41339. while ((token = this.getToken()) !== null) {
  41340. if (token !== '/') {
  41341. continue;
  41342. }
  41343. token = this.getToken();
  41344. switch (token) {
  41345. case 'FontMatrix':
  41346. var matrix = this.readNumberArray();
  41347. properties.fontMatrix = matrix;
  41348. break;
  41349. case 'Encoding':
  41350. var encodingArg = this.getToken();
  41351. var encoding;
  41352. if (!/^\d+$/.test(encodingArg)) {
  41353. // encoding name is specified
  41354. encoding = getEncoding(encodingArg);
  41355. } else {
  41356. encoding = [];
  41357. var size = parseInt(encodingArg, 10) | 0;
  41358. this.getToken();
  41359. // read in 'array'
  41360. for (var j = 0; j < size; j++) {
  41361. token = this.getToken();
  41362. // skipping till first dup or def (e.g. ignoring for statement)
  41363. while (token !== 'dup' && token !== 'def') {
  41364. token = this.getToken();
  41365. if (token === null) {
  41366. return;
  41367. }
  41368. }
  41369. // invalid header
  41370. if (token === 'def') {
  41371. break;
  41372. }
  41373. // read all array data
  41374. var index = this.readInt();
  41375. this.getToken();
  41376. // read in '/'
  41377. var glyph = this.getToken();
  41378. encoding[index] = glyph;
  41379. this.getToken();
  41380. }
  41381. }
  41382. // read the in 'put'
  41383. properties.builtInEncoding = encoding;
  41384. break;
  41385. case 'FontBBox':
  41386. var fontBBox = this.readNumberArray();
  41387. // adjusting ascent/descent
  41388. properties.ascent = fontBBox[3];
  41389. properties.descent = fontBBox[1];
  41390. properties.ascentScaled = true;
  41391. break;
  41392. }
  41393. }
  41394. }
  41395. };
  41396. return Type1Parser;
  41397. }();
  41398. exports.Type1Parser = Type1Parser;
  41399. }));
  41400. (function (root, factory) {
  41401. factory(root.pdfjsDisplayPatternHelper = {}, root.pdfjsSharedUtil, root.pdfjsDisplayWebGL);
  41402. }(this, function (exports, sharedUtil, displayWebGL) {
  41403. var Util = sharedUtil.Util;
  41404. var info = sharedUtil.info;
  41405. var isArray = sharedUtil.isArray;
  41406. var error = sharedUtil.error;
  41407. var WebGLUtils = displayWebGL.WebGLUtils;
  41408. var ShadingIRs = {};
  41409. ShadingIRs.RadialAxial = {
  41410. fromIR: function RadialAxial_fromIR(raw) {
  41411. var type = raw[1];
  41412. var colorStops = raw[2];
  41413. var p0 = raw[3];
  41414. var p1 = raw[4];
  41415. var r0 = raw[5];
  41416. var r1 = raw[6];
  41417. return {
  41418. type: 'Pattern',
  41419. getPattern: function RadialAxial_getPattern(ctx) {
  41420. var grad;
  41421. if (type === 'axial') {
  41422. grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
  41423. } else if (type === 'radial') {
  41424. grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
  41425. }
  41426. for (var i = 0, ii = colorStops.length; i < ii; ++i) {
  41427. var c = colorStops[i];
  41428. grad.addColorStop(c[0], c[1]);
  41429. }
  41430. return grad;
  41431. }
  41432. };
  41433. }
  41434. };
  41435. var createMeshCanvas = function createMeshCanvasClosure() {
  41436. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  41437. // Very basic Gouraud-shaded triangle rasterization algorithm.
  41438. var coords = context.coords, colors = context.colors;
  41439. var bytes = data.data, rowSize = data.width * 4;
  41440. var tmp;
  41441. if (coords[p1 + 1] > coords[p2 + 1]) {
  41442. tmp = p1;
  41443. p1 = p2;
  41444. p2 = tmp;
  41445. tmp = c1;
  41446. c1 = c2;
  41447. c2 = tmp;
  41448. }
  41449. if (coords[p2 + 1] > coords[p3 + 1]) {
  41450. tmp = p2;
  41451. p2 = p3;
  41452. p3 = tmp;
  41453. tmp = c2;
  41454. c2 = c3;
  41455. c3 = tmp;
  41456. }
  41457. if (coords[p1 + 1] > coords[p2 + 1]) {
  41458. tmp = p1;
  41459. p1 = p2;
  41460. p2 = tmp;
  41461. tmp = c1;
  41462. c1 = c2;
  41463. c2 = tmp;
  41464. }
  41465. var x1 = (coords[p1] + context.offsetX) * context.scaleX;
  41466. var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  41467. var x2 = (coords[p2] + context.offsetX) * context.scaleX;
  41468. var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  41469. var x3 = (coords[p3] + context.offsetX) * context.scaleX;
  41470. var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  41471. if (y1 >= y3) {
  41472. return;
  41473. }
  41474. var c1r = colors[c1], c1g = colors[c1 + 1], c1b = colors[c1 + 2];
  41475. var c2r = colors[c2], c2g = colors[c2 + 1], c2b = colors[c2 + 2];
  41476. var c3r = colors[c3], c3g = colors[c3 + 1], c3b = colors[c3 + 2];
  41477. var minY = Math.round(y1), maxY = Math.round(y3);
  41478. var xa, car, cag, cab;
  41479. var xb, cbr, cbg, cbb;
  41480. var k;
  41481. for (var y = minY; y <= maxY; y++) {
  41482. if (y < y2) {
  41483. k = y < y1 ? 0 : y1 === y2 ? 1 : (y1 - y) / (y1 - y2);
  41484. xa = x1 - (x1 - x2) * k;
  41485. car = c1r - (c1r - c2r) * k;
  41486. cag = c1g - (c1g - c2g) * k;
  41487. cab = c1b - (c1b - c2b) * k;
  41488. } else {
  41489. k = y > y3 ? 1 : y2 === y3 ? 0 : (y2 - y) / (y2 - y3);
  41490. xa = x2 - (x2 - x3) * k;
  41491. car = c2r - (c2r - c3r) * k;
  41492. cag = c2g - (c2g - c3g) * k;
  41493. cab = c2b - (c2b - c3b) * k;
  41494. }
  41495. k = y < y1 ? 0 : y > y3 ? 1 : (y1 - y) / (y1 - y3);
  41496. xb = x1 - (x1 - x3) * k;
  41497. cbr = c1r - (c1r - c3r) * k;
  41498. cbg = c1g - (c1g - c3g) * k;
  41499. cbb = c1b - (c1b - c3b) * k;
  41500. var x1_ = Math.round(Math.min(xa, xb));
  41501. var x2_ = Math.round(Math.max(xa, xb));
  41502. var j = rowSize * y + x1_ * 4;
  41503. for (var x = x1_; x <= x2_; x++) {
  41504. k = (xa - x) / (xa - xb);
  41505. k = k < 0 ? 0 : k > 1 ? 1 : k;
  41506. bytes[j++] = car - (car - cbr) * k | 0;
  41507. bytes[j++] = cag - (cag - cbg) * k | 0;
  41508. bytes[j++] = cab - (cab - cbb) * k | 0;
  41509. bytes[j++] = 255;
  41510. }
  41511. }
  41512. }
  41513. function drawFigure(data, figure, context) {
  41514. var ps = figure.coords;
  41515. var cs = figure.colors;
  41516. var i, ii;
  41517. switch (figure.type) {
  41518. case 'lattice':
  41519. var verticesPerRow = figure.verticesPerRow;
  41520. var rows = Math.floor(ps.length / verticesPerRow) - 1;
  41521. var cols = verticesPerRow - 1;
  41522. for (i = 0; i < rows; i++) {
  41523. var q = i * verticesPerRow;
  41524. for (var j = 0; j < cols; j++, q++) {
  41525. drawTriangle(data, context, ps[q], ps[q + 1], ps[q + verticesPerRow], cs[q], cs[q + 1], cs[q + verticesPerRow]);
  41526. drawTriangle(data, context, ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow], cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  41527. }
  41528. }
  41529. break;
  41530. case 'triangles':
  41531. for (i = 0, ii = ps.length; i < ii; i += 3) {
  41532. drawTriangle(data, context, ps[i], ps[i + 1], ps[i + 2], cs[i], cs[i + 1], cs[i + 2]);
  41533. }
  41534. break;
  41535. default:
  41536. error('illigal figure');
  41537. break;
  41538. }
  41539. }
  41540. function createMeshCanvas(bounds, combinesScale, coords, colors, figures, backgroundColor, cachedCanvases) {
  41541. // we will increase scale on some weird factor to let antialiasing take
  41542. // care of "rough" edges
  41543. var EXPECTED_SCALE = 1.1;
  41544. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  41545. var MAX_PATTERN_SIZE = 3000;
  41546. // 10in @ 300dpi shall be enough
  41547. // We need to keep transparent border around our pattern for fill():
  41548. // createPattern with 'no-repeat' will bleed edges across entire area.
  41549. var BORDER_SIZE = 2;
  41550. var offsetX = Math.floor(bounds[0]);
  41551. var offsetY = Math.floor(bounds[1]);
  41552. var boundsWidth = Math.ceil(bounds[2]) - offsetX;
  41553. var boundsHeight = Math.ceil(bounds[3]) - offsetY;
  41554. var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  41555. var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] * EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  41556. var scaleX = boundsWidth / width;
  41557. var scaleY = boundsHeight / height;
  41558. var context = {
  41559. coords: coords,
  41560. colors: colors,
  41561. offsetX: -offsetX,
  41562. offsetY: -offsetY,
  41563. scaleX: 1 / scaleX,
  41564. scaleY: 1 / scaleY
  41565. };
  41566. var paddedWidth = width + BORDER_SIZE * 2;
  41567. var paddedHeight = height + BORDER_SIZE * 2;
  41568. var canvas, tmpCanvas, i, ii;
  41569. if (WebGLUtils.isEnabled) {
  41570. canvas = WebGLUtils.drawFigures(width, height, backgroundColor, figures, context);
  41571. // https://bugzilla.mozilla.org/show_bug.cgi?id=972126
  41572. tmpCanvas = cachedCanvases.getCanvas('mesh', paddedWidth, paddedHeight, false);
  41573. tmpCanvas.context.drawImage(canvas, BORDER_SIZE, BORDER_SIZE);
  41574. canvas = tmpCanvas.canvas;
  41575. } else {
  41576. tmpCanvas = cachedCanvases.getCanvas('mesh', paddedWidth, paddedHeight, false);
  41577. var tmpCtx = tmpCanvas.context;
  41578. var data = tmpCtx.createImageData(width, height);
  41579. if (backgroundColor) {
  41580. var bytes = data.data;
  41581. for (i = 0, ii = bytes.length; i < ii; i += 4) {
  41582. bytes[i] = backgroundColor[0];
  41583. bytes[i + 1] = backgroundColor[1];
  41584. bytes[i + 2] = backgroundColor[2];
  41585. bytes[i + 3] = 255;
  41586. }
  41587. }
  41588. for (i = 0; i < figures.length; i++) {
  41589. drawFigure(data, figures[i], context);
  41590. }
  41591. tmpCtx.putImageData(data, BORDER_SIZE, BORDER_SIZE);
  41592. canvas = tmpCanvas.canvas;
  41593. }
  41594. return {
  41595. canvas: canvas,
  41596. offsetX: offsetX - BORDER_SIZE * scaleX,
  41597. offsetY: offsetY - BORDER_SIZE * scaleY,
  41598. scaleX: scaleX,
  41599. scaleY: scaleY
  41600. };
  41601. }
  41602. return createMeshCanvas;
  41603. }();
  41604. ShadingIRs.Mesh = {
  41605. fromIR: function Mesh_fromIR(raw) {
  41606. //var type = raw[1];
  41607. var coords = raw[2];
  41608. var colors = raw[3];
  41609. var figures = raw[4];
  41610. var bounds = raw[5];
  41611. var matrix = raw[6];
  41612. //var bbox = raw[7];
  41613. var background = raw[8];
  41614. return {
  41615. type: 'Pattern',
  41616. getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
  41617. var scale;
  41618. if (shadingFill) {
  41619. scale = Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  41620. } else {
  41621. // Obtain scale from matrix and current transformation matrix.
  41622. scale = Util.singularValueDecompose2dScale(owner.baseTransform);
  41623. if (matrix) {
  41624. var matrixScale = Util.singularValueDecompose2dScale(matrix);
  41625. scale = [
  41626. scale[0] * matrixScale[0],
  41627. scale[1] * matrixScale[1]
  41628. ];
  41629. }
  41630. }
  41631. // Rasterizing on the main thread since sending/queue large canvases
  41632. // might cause OOM.
  41633. var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords, colors, figures, shadingFill ? null : background, owner.cachedCanvases);
  41634. if (!shadingFill) {
  41635. ctx.setTransform.apply(ctx, owner.baseTransform);
  41636. if (matrix) {
  41637. ctx.transform.apply(ctx, matrix);
  41638. }
  41639. }
  41640. ctx.translate(temporaryPatternCanvas.offsetX, temporaryPatternCanvas.offsetY);
  41641. ctx.scale(temporaryPatternCanvas.scaleX, temporaryPatternCanvas.scaleY);
  41642. return ctx.createPattern(temporaryPatternCanvas.canvas, 'no-repeat');
  41643. }
  41644. };
  41645. }
  41646. };
  41647. ShadingIRs.Dummy = {
  41648. fromIR: function Dummy_fromIR() {
  41649. return {
  41650. type: 'Pattern',
  41651. getPattern: function Dummy_fromIR_getPattern() {
  41652. return 'hotpink';
  41653. }
  41654. };
  41655. }
  41656. };
  41657. function getShadingPatternFromIR(raw) {
  41658. var shadingIR = ShadingIRs[raw[0]];
  41659. if (!shadingIR) {
  41660. error('Unknown IR type: ' + raw[0]);
  41661. }
  41662. return shadingIR.fromIR(raw);
  41663. }
  41664. var TilingPattern = function TilingPatternClosure() {
  41665. var PaintType = {
  41666. COLORED: 1,
  41667. UNCOLORED: 2
  41668. };
  41669. var MAX_PATTERN_SIZE = 3000;
  41670. // 10in @ 300dpi shall be enough
  41671. function TilingPattern(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
  41672. this.operatorList = IR[2];
  41673. this.matrix = IR[3] || [
  41674. 1,
  41675. 0,
  41676. 0,
  41677. 1,
  41678. 0,
  41679. 0
  41680. ];
  41681. this.bbox = IR[4];
  41682. this.xstep = IR[5];
  41683. this.ystep = IR[6];
  41684. this.paintType = IR[7];
  41685. this.tilingType = IR[8];
  41686. this.color = color;
  41687. this.canvasGraphicsFactory = canvasGraphicsFactory;
  41688. this.baseTransform = baseTransform;
  41689. this.type = 'Pattern';
  41690. this.ctx = ctx;
  41691. }
  41692. TilingPattern.prototype = {
  41693. createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
  41694. var operatorList = this.operatorList;
  41695. var bbox = this.bbox;
  41696. var xstep = this.xstep;
  41697. var ystep = this.ystep;
  41698. var paintType = this.paintType;
  41699. var tilingType = this.tilingType;
  41700. var color = this.color;
  41701. var canvasGraphicsFactory = this.canvasGraphicsFactory;
  41702. info('TilingType: ' + tilingType);
  41703. var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
  41704. var topLeft = [
  41705. x0,
  41706. y0
  41707. ];
  41708. // we want the canvas to be as large as the step size
  41709. var botRight = [
  41710. x0 + xstep,
  41711. y0 + ystep
  41712. ];
  41713. var width = botRight[0] - topLeft[0];
  41714. var height = botRight[1] - topLeft[1];
  41715. // Obtain scale from matrix and current transformation matrix.
  41716. var matrixScale = Util.singularValueDecompose2dScale(this.matrix);
  41717. var curMatrixScale = Util.singularValueDecompose2dScale(this.baseTransform);
  41718. var combinedScale = [
  41719. matrixScale[0] * curMatrixScale[0],
  41720. matrixScale[1] * curMatrixScale[1]
  41721. ];
  41722. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  41723. // Use width and height values that are as close as possible to the end
  41724. // result when the pattern is used. Too low value makes the pattern look
  41725. // blurry. Too large value makes it look too crispy.
  41726. width = Math.min(Math.ceil(Math.abs(width * combinedScale[0])), MAX_PATTERN_SIZE);
  41727. height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])), MAX_PATTERN_SIZE);
  41728. var tmpCanvas = owner.cachedCanvases.getCanvas('pattern', width, height, true);
  41729. var tmpCtx = tmpCanvas.context;
  41730. var graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
  41731. graphics.groupLevel = owner.groupLevel;
  41732. this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color);
  41733. this.setScale(width, height, xstep, ystep);
  41734. this.transformToScale(graphics);
  41735. // transform coordinates to pattern space
  41736. var tmpTranslate = [
  41737. 1,
  41738. 0,
  41739. 0,
  41740. 1,
  41741. -topLeft[0],
  41742. -topLeft[1]
  41743. ];
  41744. graphics.transform.apply(graphics, tmpTranslate);
  41745. this.clipBbox(graphics, bbox, x0, y0, x1, y1);
  41746. graphics.executeOperatorList(operatorList);
  41747. return tmpCanvas.canvas;
  41748. },
  41749. setScale: function TilingPattern_setScale(width, height, xstep, ystep) {
  41750. this.scale = [
  41751. width / xstep,
  41752. height / ystep
  41753. ];
  41754. },
  41755. transformToScale: function TilingPattern_transformToScale(graphics) {
  41756. var scale = this.scale;
  41757. var tmpScale = [
  41758. scale[0],
  41759. 0,
  41760. 0,
  41761. scale[1],
  41762. 0,
  41763. 0
  41764. ];
  41765. graphics.transform.apply(graphics, tmpScale);
  41766. },
  41767. scaleToContext: function TilingPattern_scaleToContext() {
  41768. var scale = this.scale;
  41769. this.ctx.scale(1 / scale[0], 1 / scale[1]);
  41770. },
  41771. clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
  41772. if (bbox && isArray(bbox) && bbox.length === 4) {
  41773. var bboxWidth = x1 - x0;
  41774. var bboxHeight = y1 - y0;
  41775. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  41776. graphics.clip();
  41777. graphics.endPath();
  41778. }
  41779. },
  41780. setFillAndStrokeStyleToContext: function setFillAndStrokeStyleToContext(context, paintType, color) {
  41781. switch (paintType) {
  41782. case PaintType.COLORED:
  41783. var ctx = this.ctx;
  41784. context.fillStyle = ctx.fillStyle;
  41785. context.strokeStyle = ctx.strokeStyle;
  41786. break;
  41787. case PaintType.UNCOLORED:
  41788. var cssColor = Util.makeCssRgb(color[0], color[1], color[2]);
  41789. context.fillStyle = cssColor;
  41790. context.strokeStyle = cssColor;
  41791. break;
  41792. default:
  41793. error('Unsupported paint type: ' + paintType);
  41794. }
  41795. },
  41796. getPattern: function TilingPattern_getPattern(ctx, owner) {
  41797. var temporaryPatternCanvas = this.createPatternCanvas(owner);
  41798. ctx = this.ctx;
  41799. ctx.setTransform.apply(ctx, this.baseTransform);
  41800. ctx.transform.apply(ctx, this.matrix);
  41801. this.scaleToContext();
  41802. return ctx.createPattern(temporaryPatternCanvas, 'repeat');
  41803. }
  41804. };
  41805. return TilingPattern;
  41806. }();
  41807. exports.getShadingPatternFromIR = getShadingPatternFromIR;
  41808. exports.TilingPattern = TilingPattern;
  41809. }));
  41810. (function (root, factory) {
  41811. factory(root.pdfjsCoreCMap = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser);
  41812. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser) {
  41813. var Util = sharedUtil.Util;
  41814. var assert = sharedUtil.assert;
  41815. var warn = sharedUtil.warn;
  41816. var error = sharedUtil.error;
  41817. var isInt = sharedUtil.isInt;
  41818. var isString = sharedUtil.isString;
  41819. var MissingDataException = sharedUtil.MissingDataException;
  41820. var isName = corePrimitives.isName;
  41821. var isCmd = corePrimitives.isCmd;
  41822. var isStream = corePrimitives.isStream;
  41823. var StringStream = coreStream.StringStream;
  41824. var Lexer = coreParser.Lexer;
  41825. var isEOF = coreParser.isEOF;
  41826. var BUILT_IN_CMAPS = [
  41827. // << Start unicode maps.
  41828. 'Adobe-GB1-UCS2',
  41829. 'Adobe-CNS1-UCS2',
  41830. 'Adobe-Japan1-UCS2',
  41831. 'Adobe-Korea1-UCS2',
  41832. // >> End unicode maps.
  41833. '78-EUC-H',
  41834. '78-EUC-V',
  41835. '78-H',
  41836. '78-RKSJ-H',
  41837. '78-RKSJ-V',
  41838. '78-V',
  41839. '78ms-RKSJ-H',
  41840. '78ms-RKSJ-V',
  41841. '83pv-RKSJ-H',
  41842. '90ms-RKSJ-H',
  41843. '90ms-RKSJ-V',
  41844. '90msp-RKSJ-H',
  41845. '90msp-RKSJ-V',
  41846. '90pv-RKSJ-H',
  41847. '90pv-RKSJ-V',
  41848. 'Add-H',
  41849. 'Add-RKSJ-H',
  41850. 'Add-RKSJ-V',
  41851. 'Add-V',
  41852. 'Adobe-CNS1-0',
  41853. 'Adobe-CNS1-1',
  41854. 'Adobe-CNS1-2',
  41855. 'Adobe-CNS1-3',
  41856. 'Adobe-CNS1-4',
  41857. 'Adobe-CNS1-5',
  41858. 'Adobe-CNS1-6',
  41859. 'Adobe-GB1-0',
  41860. 'Adobe-GB1-1',
  41861. 'Adobe-GB1-2',
  41862. 'Adobe-GB1-3',
  41863. 'Adobe-GB1-4',
  41864. 'Adobe-GB1-5',
  41865. 'Adobe-Japan1-0',
  41866. 'Adobe-Japan1-1',
  41867. 'Adobe-Japan1-2',
  41868. 'Adobe-Japan1-3',
  41869. 'Adobe-Japan1-4',
  41870. 'Adobe-Japan1-5',
  41871. 'Adobe-Japan1-6',
  41872. 'Adobe-Korea1-0',
  41873. 'Adobe-Korea1-1',
  41874. 'Adobe-Korea1-2',
  41875. 'B5-H',
  41876. 'B5-V',
  41877. 'B5pc-H',
  41878. 'B5pc-V',
  41879. 'CNS-EUC-H',
  41880. 'CNS-EUC-V',
  41881. 'CNS1-H',
  41882. 'CNS1-V',
  41883. 'CNS2-H',
  41884. 'CNS2-V',
  41885. 'ETHK-B5-H',
  41886. 'ETHK-B5-V',
  41887. 'ETen-B5-H',
  41888. 'ETen-B5-V',
  41889. 'ETenms-B5-H',
  41890. 'ETenms-B5-V',
  41891. 'EUC-H',
  41892. 'EUC-V',
  41893. 'Ext-H',
  41894. 'Ext-RKSJ-H',
  41895. 'Ext-RKSJ-V',
  41896. 'Ext-V',
  41897. 'GB-EUC-H',
  41898. 'GB-EUC-V',
  41899. 'GB-H',
  41900. 'GB-V',
  41901. 'GBK-EUC-H',
  41902. 'GBK-EUC-V',
  41903. 'GBK2K-H',
  41904. 'GBK2K-V',
  41905. 'GBKp-EUC-H',
  41906. 'GBKp-EUC-V',
  41907. 'GBT-EUC-H',
  41908. 'GBT-EUC-V',
  41909. 'GBT-H',
  41910. 'GBT-V',
  41911. 'GBTpc-EUC-H',
  41912. 'GBTpc-EUC-V',
  41913. 'GBpc-EUC-H',
  41914. 'GBpc-EUC-V',
  41915. 'H',
  41916. 'HKdla-B5-H',
  41917. 'HKdla-B5-V',
  41918. 'HKdlb-B5-H',
  41919. 'HKdlb-B5-V',
  41920. 'HKgccs-B5-H',
  41921. 'HKgccs-B5-V',
  41922. 'HKm314-B5-H',
  41923. 'HKm314-B5-V',
  41924. 'HKm471-B5-H',
  41925. 'HKm471-B5-V',
  41926. 'HKscs-B5-H',
  41927. 'HKscs-B5-V',
  41928. 'Hankaku',
  41929. 'Hiragana',
  41930. 'KSC-EUC-H',
  41931. 'KSC-EUC-V',
  41932. 'KSC-H',
  41933. 'KSC-Johab-H',
  41934. 'KSC-Johab-V',
  41935. 'KSC-V',
  41936. 'KSCms-UHC-H',
  41937. 'KSCms-UHC-HW-H',
  41938. 'KSCms-UHC-HW-V',
  41939. 'KSCms-UHC-V',
  41940. 'KSCpc-EUC-H',
  41941. 'KSCpc-EUC-V',
  41942. 'Katakana',
  41943. 'NWP-H',
  41944. 'NWP-V',
  41945. 'RKSJ-H',
  41946. 'RKSJ-V',
  41947. 'Roman',
  41948. 'UniCNS-UCS2-H',
  41949. 'UniCNS-UCS2-V',
  41950. 'UniCNS-UTF16-H',
  41951. 'UniCNS-UTF16-V',
  41952. 'UniCNS-UTF32-H',
  41953. 'UniCNS-UTF32-V',
  41954. 'UniCNS-UTF8-H',
  41955. 'UniCNS-UTF8-V',
  41956. 'UniGB-UCS2-H',
  41957. 'UniGB-UCS2-V',
  41958. 'UniGB-UTF16-H',
  41959. 'UniGB-UTF16-V',
  41960. 'UniGB-UTF32-H',
  41961. 'UniGB-UTF32-V',
  41962. 'UniGB-UTF8-H',
  41963. 'UniGB-UTF8-V',
  41964. 'UniJIS-UCS2-H',
  41965. 'UniJIS-UCS2-HW-H',
  41966. 'UniJIS-UCS2-HW-V',
  41967. 'UniJIS-UCS2-V',
  41968. 'UniJIS-UTF16-H',
  41969. 'UniJIS-UTF16-V',
  41970. 'UniJIS-UTF32-H',
  41971. 'UniJIS-UTF32-V',
  41972. 'UniJIS-UTF8-H',
  41973. 'UniJIS-UTF8-V',
  41974. 'UniJIS2004-UTF16-H',
  41975. 'UniJIS2004-UTF16-V',
  41976. 'UniJIS2004-UTF32-H',
  41977. 'UniJIS2004-UTF32-V',
  41978. 'UniJIS2004-UTF8-H',
  41979. 'UniJIS2004-UTF8-V',
  41980. 'UniJISPro-UCS2-HW-V',
  41981. 'UniJISPro-UCS2-V',
  41982. 'UniJISPro-UTF8-V',
  41983. 'UniJISX0213-UTF32-H',
  41984. 'UniJISX0213-UTF32-V',
  41985. 'UniJISX02132004-UTF32-H',
  41986. 'UniJISX02132004-UTF32-V',
  41987. 'UniKS-UCS2-H',
  41988. 'UniKS-UCS2-V',
  41989. 'UniKS-UTF16-H',
  41990. 'UniKS-UTF16-V',
  41991. 'UniKS-UTF32-H',
  41992. 'UniKS-UTF32-V',
  41993. 'UniKS-UTF8-H',
  41994. 'UniKS-UTF8-V',
  41995. 'V',
  41996. 'WP-Symbol'
  41997. ];
  41998. // CMap, not to be confused with TrueType's cmap.
  41999. var CMap = function CMapClosure() {
  42000. function CMap(builtInCMap) {
  42001. // Codespace ranges are stored as follows:
  42002. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  42003. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  42004. this.codespaceRanges = [
  42005. [],
  42006. [],
  42007. [],
  42008. []
  42009. ];
  42010. this.numCodespaceRanges = 0;
  42011. // Map entries have one of two forms.
  42012. // - cid chars are 16-bit unsigned integers, stored as integers.
  42013. // - bf chars are variable-length byte sequences, stored as strings, with
  42014. // one byte per character.
  42015. this._map = [];
  42016. this.name = '';
  42017. this.vertical = false;
  42018. this.useCMap = null;
  42019. this.builtInCMap = builtInCMap;
  42020. }
  42021. CMap.prototype = {
  42022. addCodespaceRange: function (n, low, high) {
  42023. this.codespaceRanges[n - 1].push(low, high);
  42024. this.numCodespaceRanges++;
  42025. },
  42026. mapCidRange: function (low, high, dstLow) {
  42027. while (low <= high) {
  42028. this._map[low++] = dstLow++;
  42029. }
  42030. },
  42031. mapBfRange: function (low, high, dstLow) {
  42032. var lastByte = dstLow.length - 1;
  42033. while (low <= high) {
  42034. this._map[low++] = dstLow;
  42035. // Only the last byte has to be incremented.
  42036. dstLow = dstLow.substr(0, lastByte) + String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  42037. }
  42038. },
  42039. mapBfRangeToArray: function (low, high, array) {
  42040. var i = 0, ii = array.length;
  42041. while (low <= high && i < ii) {
  42042. this._map[low] = array[i++];
  42043. ++low;
  42044. }
  42045. },
  42046. // This is used for both bf and cid chars.
  42047. mapOne: function (src, dst) {
  42048. this._map[src] = dst;
  42049. },
  42050. lookup: function (code) {
  42051. return this._map[code];
  42052. },
  42053. contains: function (code) {
  42054. return this._map[code] !== undefined;
  42055. },
  42056. forEach: function (callback) {
  42057. // Most maps have fewer than 65536 entries, and for those we use normal
  42058. // array iteration. But really sparse tables are possible -- e.g. with
  42059. // indices in the *billions*. For such tables we use for..in, which isn't
  42060. // ideal because it stringifies the indices for all present elements, but
  42061. // it does avoid iterating over every undefined entry.
  42062. var map = this._map;
  42063. var length = map.length;
  42064. var i;
  42065. if (length <= 0x10000) {
  42066. for (i = 0; i < length; i++) {
  42067. if (map[i] !== undefined) {
  42068. callback(i, map[i]);
  42069. }
  42070. }
  42071. } else {
  42072. for (i in this._map) {
  42073. callback(i, map[i]);
  42074. }
  42075. }
  42076. },
  42077. charCodeOf: function (value) {
  42078. return this._map.indexOf(value);
  42079. },
  42080. getMap: function () {
  42081. return this._map;
  42082. },
  42083. readCharCode: function (str, offset, out) {
  42084. var c = 0;
  42085. var codespaceRanges = this.codespaceRanges;
  42086. var codespaceRangesLen = this.codespaceRanges.length;
  42087. // 9.7.6.2 CMap Mapping
  42088. // The code length is at most 4.
  42089. for (var n = 0; n < codespaceRangesLen; n++) {
  42090. c = (c << 8 | str.charCodeAt(offset + n)) >>> 0;
  42091. // Check each codespace range to see if it falls within.
  42092. var codespaceRange = codespaceRanges[n];
  42093. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  42094. var low = codespaceRange[k++];
  42095. var high = codespaceRange[k++];
  42096. if (c >= low && c <= high) {
  42097. out.charcode = c;
  42098. out.length = n + 1;
  42099. return;
  42100. }
  42101. }
  42102. }
  42103. out.charcode = 0;
  42104. out.length = 1;
  42105. },
  42106. get length() {
  42107. return this._map.length;
  42108. },
  42109. get isIdentityCMap() {
  42110. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  42111. return false;
  42112. }
  42113. if (this._map.length !== 0x10000) {
  42114. return false;
  42115. }
  42116. for (var i = 0; i < 0x10000; i++) {
  42117. if (this._map[i] !== i) {
  42118. return false;
  42119. }
  42120. }
  42121. return true;
  42122. }
  42123. };
  42124. return CMap;
  42125. }();
  42126. // A special case of CMap, where the _map array implicitly has a length of
  42127. // 65536 and each element is equal to its index.
  42128. var IdentityCMap = function IdentityCMapClosure() {
  42129. function IdentityCMap(vertical, n) {
  42130. CMap.call(this);
  42131. this.vertical = vertical;
  42132. this.addCodespaceRange(n, 0, 0xffff);
  42133. }
  42134. Util.inherit(IdentityCMap, CMap, {});
  42135. IdentityCMap.prototype = {
  42136. addCodespaceRange: CMap.prototype.addCodespaceRange,
  42137. mapCidRange: function (low, high, dstLow) {
  42138. error('should not call mapCidRange');
  42139. },
  42140. mapBfRange: function (low, high, dstLow) {
  42141. error('should not call mapBfRange');
  42142. },
  42143. mapBfRangeToArray: function (low, high, array) {
  42144. error('should not call mapBfRangeToArray');
  42145. },
  42146. mapOne: function (src, dst) {
  42147. error('should not call mapCidOne');
  42148. },
  42149. lookup: function (code) {
  42150. return isInt(code) && code <= 0xffff ? code : undefined;
  42151. },
  42152. contains: function (code) {
  42153. return isInt(code) && code <= 0xffff;
  42154. },
  42155. forEach: function (callback) {
  42156. for (var i = 0; i <= 0xffff; i++) {
  42157. callback(i, i);
  42158. }
  42159. },
  42160. charCodeOf: function (value) {
  42161. return isInt(value) && value <= 0xffff ? value : -1;
  42162. },
  42163. getMap: function () {
  42164. // Sometimes identity maps must be instantiated, but it's rare.
  42165. var map = new Array(0x10000);
  42166. for (var i = 0; i <= 0xffff; i++) {
  42167. map[i] = i;
  42168. }
  42169. return map;
  42170. },
  42171. readCharCode: CMap.prototype.readCharCode,
  42172. get length() {
  42173. return 0x10000;
  42174. },
  42175. get isIdentityCMap() {
  42176. error('should not access .isIdentityCMap');
  42177. }
  42178. };
  42179. return IdentityCMap;
  42180. }();
  42181. var BinaryCMapReader = function BinaryCMapReaderClosure() {
  42182. function fetchBinaryData(url) {
  42183. return new Promise(function (resolve, reject) {
  42184. var request = new XMLHttpRequest();
  42185. request.open('GET', url, true);
  42186. request.responseType = 'arraybuffer';
  42187. request.onreadystatechange = function () {
  42188. if (request.readyState === XMLHttpRequest.DONE) {
  42189. if (!request.response || request.status !== 200 && request.status !== 0) {
  42190. reject(new Error('Unable to get binary cMap at: ' + url));
  42191. } else {
  42192. resolve(new Uint8Array(request.response));
  42193. }
  42194. }
  42195. };
  42196. request.send(null);
  42197. });
  42198. }
  42199. function hexToInt(a, size) {
  42200. var n = 0;
  42201. for (var i = 0; i <= size; i++) {
  42202. n = n << 8 | a[i];
  42203. }
  42204. return n >>> 0;
  42205. }
  42206. function hexToStr(a, size) {
  42207. // This code is hot. Special-case some common values to avoid creating an
  42208. // object with subarray().
  42209. if (size === 1) {
  42210. return String.fromCharCode(a[0], a[1]);
  42211. }
  42212. if (size === 3) {
  42213. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  42214. }
  42215. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  42216. }
  42217. function addHex(a, b, size) {
  42218. var c = 0;
  42219. for (var i = size; i >= 0; i--) {
  42220. c += a[i] + b[i];
  42221. a[i] = c & 255;
  42222. c >>= 8;
  42223. }
  42224. }
  42225. function incHex(a, size) {
  42226. var c = 1;
  42227. for (var i = size; i >= 0 && c > 0; i--) {
  42228. c += a[i];
  42229. a[i] = c & 255;
  42230. c >>= 8;
  42231. }
  42232. }
  42233. var MAX_NUM_SIZE = 16;
  42234. var MAX_ENCODED_NUM_SIZE = 19;
  42235. // ceil(MAX_NUM_SIZE * 7 / 8)
  42236. function BinaryCMapStream(data) {
  42237. this.buffer = data;
  42238. this.pos = 0;
  42239. this.end = data.length;
  42240. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  42241. }
  42242. BinaryCMapStream.prototype = {
  42243. readByte: function () {
  42244. if (this.pos >= this.end) {
  42245. return -1;
  42246. }
  42247. return this.buffer[this.pos++];
  42248. },
  42249. readNumber: function () {
  42250. var n = 0;
  42251. var last;
  42252. do {
  42253. var b = this.readByte();
  42254. if (b < 0) {
  42255. error('unexpected EOF in bcmap');
  42256. }
  42257. last = !(b & 0x80);
  42258. n = n << 7 | b & 0x7F;
  42259. } while (!last);
  42260. return n;
  42261. },
  42262. readSigned: function () {
  42263. var n = this.readNumber();
  42264. return n & 1 ? ~(n >>> 1) : n >>> 1;
  42265. },
  42266. readHex: function (num, size) {
  42267. num.set(this.buffer.subarray(this.pos, this.pos + size + 1));
  42268. this.pos += size + 1;
  42269. },
  42270. readHexNumber: function (num, size) {
  42271. var last;
  42272. var stack = this.tmpBuf, sp = 0;
  42273. do {
  42274. var b = this.readByte();
  42275. if (b < 0) {
  42276. error('unexpected EOF in bcmap');
  42277. }
  42278. last = !(b & 0x80);
  42279. stack[sp++] = b & 0x7F;
  42280. } while (!last);
  42281. var i = size, buffer = 0, bufferSize = 0;
  42282. while (i >= 0) {
  42283. while (bufferSize < 8 && stack.length > 0) {
  42284. buffer = stack[--sp] << bufferSize | buffer;
  42285. bufferSize += 7;
  42286. }
  42287. num[i] = buffer & 255;
  42288. i--;
  42289. buffer >>= 8;
  42290. bufferSize -= 8;
  42291. }
  42292. },
  42293. readHexSigned: function (num, size) {
  42294. this.readHexNumber(num, size);
  42295. var sign = num[size] & 1 ? 255 : 0;
  42296. var c = 0;
  42297. for (var i = 0; i <= size; i++) {
  42298. c = (c & 1) << 8 | num[i];
  42299. num[i] = c >> 1 ^ sign;
  42300. }
  42301. },
  42302. readString: function () {
  42303. var len = this.readNumber();
  42304. var s = '';
  42305. for (var i = 0; i < len; i++) {
  42306. s += String.fromCharCode(this.readNumber());
  42307. }
  42308. return s;
  42309. }
  42310. };
  42311. function processBinaryCMap(url, cMap, extend) {
  42312. return fetchBinaryData(url).then(function (data) {
  42313. var stream = new BinaryCMapStream(data);
  42314. var header = stream.readByte();
  42315. cMap.vertical = !!(header & 1);
  42316. var useCMap = null;
  42317. var start = new Uint8Array(MAX_NUM_SIZE);
  42318. var end = new Uint8Array(MAX_NUM_SIZE);
  42319. var char = new Uint8Array(MAX_NUM_SIZE);
  42320. var charCode = new Uint8Array(MAX_NUM_SIZE);
  42321. var tmp = new Uint8Array(MAX_NUM_SIZE);
  42322. var code;
  42323. var b;
  42324. while ((b = stream.readByte()) >= 0) {
  42325. var type = b >> 5;
  42326. if (type === 7) {
  42327. // metadata, e.g. comment or usecmap
  42328. switch (b & 0x1F) {
  42329. case 0:
  42330. stream.readString();
  42331. // skipping comment
  42332. break;
  42333. case 1:
  42334. useCMap = stream.readString();
  42335. break;
  42336. }
  42337. continue;
  42338. }
  42339. var sequence = !!(b & 0x10);
  42340. var dataSize = b & 15;
  42341. assert(dataSize + 1 <= MAX_NUM_SIZE);
  42342. var ucs2DataSize = 1;
  42343. var subitemsCount = stream.readNumber();
  42344. var i;
  42345. switch (type) {
  42346. case 0:
  42347. // codespacerange
  42348. stream.readHex(start, dataSize);
  42349. stream.readHexNumber(end, dataSize);
  42350. addHex(end, start, dataSize);
  42351. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize), hexToInt(end, dataSize));
  42352. for (i = 1; i < subitemsCount; i++) {
  42353. incHex(end, dataSize);
  42354. stream.readHexNumber(start, dataSize);
  42355. addHex(start, end, dataSize);
  42356. stream.readHexNumber(end, dataSize);
  42357. addHex(end, start, dataSize);
  42358. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize), hexToInt(end, dataSize));
  42359. }
  42360. break;
  42361. case 1:
  42362. // notdefrange
  42363. stream.readHex(start, dataSize);
  42364. stream.readHexNumber(end, dataSize);
  42365. addHex(end, start, dataSize);
  42366. code = stream.readNumber();
  42367. // undefined range, skipping
  42368. for (i = 1; i < subitemsCount; i++) {
  42369. incHex(end, dataSize);
  42370. stream.readHexNumber(start, dataSize);
  42371. addHex(start, end, dataSize);
  42372. stream.readHexNumber(end, dataSize);
  42373. addHex(end, start, dataSize);
  42374. code = stream.readNumber();
  42375. }
  42376. // nop
  42377. break;
  42378. case 2:
  42379. // cidchar
  42380. stream.readHex(char, dataSize);
  42381. code = stream.readNumber();
  42382. cMap.mapOne(hexToInt(char, dataSize), code);
  42383. for (i = 1; i < subitemsCount; i++) {
  42384. incHex(char, dataSize);
  42385. if (!sequence) {
  42386. stream.readHexNumber(tmp, dataSize);
  42387. addHex(char, tmp, dataSize);
  42388. }
  42389. code = stream.readSigned() + (code + 1);
  42390. cMap.mapOne(hexToInt(char, dataSize), code);
  42391. }
  42392. break;
  42393. case 3:
  42394. // cidrange
  42395. stream.readHex(start, dataSize);
  42396. stream.readHexNumber(end, dataSize);
  42397. addHex(end, start, dataSize);
  42398. code = stream.readNumber();
  42399. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize), code);
  42400. for (i = 1; i < subitemsCount; i++) {
  42401. incHex(end, dataSize);
  42402. if (!sequence) {
  42403. stream.readHexNumber(start, dataSize);
  42404. addHex(start, end, dataSize);
  42405. } else {
  42406. start.set(end);
  42407. }
  42408. stream.readHexNumber(end, dataSize);
  42409. addHex(end, start, dataSize);
  42410. code = stream.readNumber();
  42411. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize), code);
  42412. }
  42413. break;
  42414. case 4:
  42415. // bfchar
  42416. stream.readHex(char, ucs2DataSize);
  42417. stream.readHex(charCode, dataSize);
  42418. cMap.mapOne(hexToInt(char, ucs2DataSize), hexToStr(charCode, dataSize));
  42419. for (i = 1; i < subitemsCount; i++) {
  42420. incHex(char, ucs2DataSize);
  42421. if (!sequence) {
  42422. stream.readHexNumber(tmp, ucs2DataSize);
  42423. addHex(char, tmp, ucs2DataSize);
  42424. }
  42425. incHex(charCode, dataSize);
  42426. stream.readHexSigned(tmp, dataSize);
  42427. addHex(charCode, tmp, dataSize);
  42428. cMap.mapOne(hexToInt(char, ucs2DataSize), hexToStr(charCode, dataSize));
  42429. }
  42430. break;
  42431. case 5:
  42432. // bfrange
  42433. stream.readHex(start, ucs2DataSize);
  42434. stream.readHexNumber(end, ucs2DataSize);
  42435. addHex(end, start, ucs2DataSize);
  42436. stream.readHex(charCode, dataSize);
  42437. cMap.mapBfRange(hexToInt(start, ucs2DataSize), hexToInt(end, ucs2DataSize), hexToStr(charCode, dataSize));
  42438. for (i = 1; i < subitemsCount; i++) {
  42439. incHex(end, ucs2DataSize);
  42440. if (!sequence) {
  42441. stream.readHexNumber(start, ucs2DataSize);
  42442. addHex(start, end, ucs2DataSize);
  42443. } else {
  42444. start.set(end);
  42445. }
  42446. stream.readHexNumber(end, ucs2DataSize);
  42447. addHex(end, start, ucs2DataSize);
  42448. stream.readHex(charCode, dataSize);
  42449. cMap.mapBfRange(hexToInt(start, ucs2DataSize), hexToInt(end, ucs2DataSize), hexToStr(charCode, dataSize));
  42450. }
  42451. break;
  42452. default:
  42453. error('Unknown type: ' + type);
  42454. break;
  42455. }
  42456. }
  42457. if (useCMap) {
  42458. return extend(useCMap);
  42459. }
  42460. return cMap;
  42461. });
  42462. }
  42463. function BinaryCMapReader() {
  42464. }
  42465. BinaryCMapReader.prototype = { read: processBinaryCMap };
  42466. return BinaryCMapReader;
  42467. }();
  42468. var CMapFactory = function CMapFactoryClosure() {
  42469. function strToInt(str) {
  42470. var a = 0;
  42471. for (var i = 0; i < str.length; i++) {
  42472. a = a << 8 | str.charCodeAt(i);
  42473. }
  42474. return a >>> 0;
  42475. }
  42476. function expectString(obj) {
  42477. if (!isString(obj)) {
  42478. error('Malformed CMap: expected string.');
  42479. }
  42480. }
  42481. function expectInt(obj) {
  42482. if (!isInt(obj)) {
  42483. error('Malformed CMap: expected int.');
  42484. }
  42485. }
  42486. function parseBfChar(cMap, lexer) {
  42487. while (true) {
  42488. var obj = lexer.getObj();
  42489. if (isEOF(obj)) {
  42490. break;
  42491. }
  42492. if (isCmd(obj, 'endbfchar')) {
  42493. return;
  42494. }
  42495. expectString(obj);
  42496. var src = strToInt(obj);
  42497. obj = lexer.getObj();
  42498. // TODO are /dstName used?
  42499. expectString(obj);
  42500. var dst = obj;
  42501. cMap.mapOne(src, dst);
  42502. }
  42503. }
  42504. function parseBfRange(cMap, lexer) {
  42505. while (true) {
  42506. var obj = lexer.getObj();
  42507. if (isEOF(obj)) {
  42508. break;
  42509. }
  42510. if (isCmd(obj, 'endbfrange')) {
  42511. return;
  42512. }
  42513. expectString(obj);
  42514. var low = strToInt(obj);
  42515. obj = lexer.getObj();
  42516. expectString(obj);
  42517. var high = strToInt(obj);
  42518. obj = lexer.getObj();
  42519. if (isInt(obj) || isString(obj)) {
  42520. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  42521. cMap.mapBfRange(low, high, dstLow);
  42522. } else if (isCmd(obj, '[')) {
  42523. obj = lexer.getObj();
  42524. var array = [];
  42525. while (!isCmd(obj, ']') && !isEOF(obj)) {
  42526. array.push(obj);
  42527. obj = lexer.getObj();
  42528. }
  42529. cMap.mapBfRangeToArray(low, high, array);
  42530. } else {
  42531. break;
  42532. }
  42533. }
  42534. error('Invalid bf range.');
  42535. }
  42536. function parseCidChar(cMap, lexer) {
  42537. while (true) {
  42538. var obj = lexer.getObj();
  42539. if (isEOF(obj)) {
  42540. break;
  42541. }
  42542. if (isCmd(obj, 'endcidchar')) {
  42543. return;
  42544. }
  42545. expectString(obj);
  42546. var src = strToInt(obj);
  42547. obj = lexer.getObj();
  42548. expectInt(obj);
  42549. var dst = obj;
  42550. cMap.mapOne(src, dst);
  42551. }
  42552. }
  42553. function parseCidRange(cMap, lexer) {
  42554. while (true) {
  42555. var obj = lexer.getObj();
  42556. if (isEOF(obj)) {
  42557. break;
  42558. }
  42559. if (isCmd(obj, 'endcidrange')) {
  42560. return;
  42561. }
  42562. expectString(obj);
  42563. var low = strToInt(obj);
  42564. obj = lexer.getObj();
  42565. expectString(obj);
  42566. var high = strToInt(obj);
  42567. obj = lexer.getObj();
  42568. expectInt(obj);
  42569. var dstLow = obj;
  42570. cMap.mapCidRange(low, high, dstLow);
  42571. }
  42572. }
  42573. function parseCodespaceRange(cMap, lexer) {
  42574. while (true) {
  42575. var obj = lexer.getObj();
  42576. if (isEOF(obj)) {
  42577. break;
  42578. }
  42579. if (isCmd(obj, 'endcodespacerange')) {
  42580. return;
  42581. }
  42582. if (!isString(obj)) {
  42583. break;
  42584. }
  42585. var low = strToInt(obj);
  42586. obj = lexer.getObj();
  42587. if (!isString(obj)) {
  42588. break;
  42589. }
  42590. var high = strToInt(obj);
  42591. cMap.addCodespaceRange(obj.length, low, high);
  42592. }
  42593. error('Invalid codespace range.');
  42594. }
  42595. function parseWMode(cMap, lexer) {
  42596. var obj = lexer.getObj();
  42597. if (isInt(obj)) {
  42598. cMap.vertical = !!obj;
  42599. }
  42600. }
  42601. function parseCMapName(cMap, lexer) {
  42602. var obj = lexer.getObj();
  42603. if (isName(obj) && isString(obj.name)) {
  42604. cMap.name = obj.name;
  42605. }
  42606. }
  42607. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  42608. var previous;
  42609. var embededUseCMap;
  42610. objLoop:
  42611. while (true) {
  42612. try {
  42613. var obj = lexer.getObj();
  42614. if (isEOF(obj)) {
  42615. break;
  42616. } else if (isName(obj)) {
  42617. if (obj.name === 'WMode') {
  42618. parseWMode(cMap, lexer);
  42619. } else if (obj.name === 'CMapName') {
  42620. parseCMapName(cMap, lexer);
  42621. }
  42622. previous = obj;
  42623. } else if (isCmd(obj)) {
  42624. switch (obj.cmd) {
  42625. case 'endcmap':
  42626. break objLoop;
  42627. case 'usecmap':
  42628. if (isName(previous)) {
  42629. embededUseCMap = previous.name;
  42630. }
  42631. break;
  42632. case 'begincodespacerange':
  42633. parseCodespaceRange(cMap, lexer);
  42634. break;
  42635. case 'beginbfchar':
  42636. parseBfChar(cMap, lexer);
  42637. break;
  42638. case 'begincidchar':
  42639. parseCidChar(cMap, lexer);
  42640. break;
  42641. case 'beginbfrange':
  42642. parseBfRange(cMap, lexer);
  42643. break;
  42644. case 'begincidrange':
  42645. parseCidRange(cMap, lexer);
  42646. break;
  42647. }
  42648. }
  42649. } catch (ex) {
  42650. if (ex instanceof MissingDataException) {
  42651. throw ex;
  42652. }
  42653. warn('Invalid cMap data: ' + ex);
  42654. continue;
  42655. }
  42656. }
  42657. if (!useCMap && embededUseCMap) {
  42658. // Load the usecmap definition from the file only if there wasn't one
  42659. // specified.
  42660. useCMap = embededUseCMap;
  42661. }
  42662. if (useCMap) {
  42663. return extendCMap(cMap, builtInCMapParams, useCMap);
  42664. }
  42665. return Promise.resolve(cMap);
  42666. }
  42667. function extendCMap(cMap, builtInCMapParams, useCMap) {
  42668. return createBuiltInCMap(useCMap, builtInCMapParams).then(function (newCMap) {
  42669. cMap.useCMap = newCMap;
  42670. // If there aren't any code space ranges defined clone all the parent ones
  42671. // into this cMap.
  42672. if (cMap.numCodespaceRanges === 0) {
  42673. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  42674. for (var i = 0; i < useCodespaceRanges.length; i++) {
  42675. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  42676. }
  42677. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  42678. }
  42679. // Merge the map into the current one, making sure not to override
  42680. // any previously defined entries.
  42681. cMap.useCMap.forEach(function (key, value) {
  42682. if (!cMap.contains(key)) {
  42683. cMap.mapOne(key, cMap.useCMap.lookup(key));
  42684. }
  42685. });
  42686. return cMap;
  42687. });
  42688. }
  42689. function parseBinaryCMap(name, builtInCMapParams) {
  42690. var url = builtInCMapParams.url + name + '.bcmap';
  42691. var cMap = new CMap(true);
  42692. return new BinaryCMapReader().read(url, cMap, function (useCMap) {
  42693. return extendCMap(cMap, builtInCMapParams, useCMap);
  42694. });
  42695. }
  42696. function createBuiltInCMap(name, builtInCMapParams) {
  42697. if (name === 'Identity-H') {
  42698. return Promise.resolve(new IdentityCMap(false, 2));
  42699. } else if (name === 'Identity-V') {
  42700. return Promise.resolve(new IdentityCMap(true, 2));
  42701. }
  42702. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  42703. return Promise.reject(new Error('Unknown cMap name: ' + name));
  42704. }
  42705. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  42706. if (builtInCMapParams.packed) {
  42707. return parseBinaryCMap(name, builtInCMapParams);
  42708. }
  42709. return new Promise(function (resolve, reject) {
  42710. var url = builtInCMapParams.url + name;
  42711. var request = new XMLHttpRequest();
  42712. request.onreadystatechange = function () {
  42713. if (request.readyState === XMLHttpRequest.DONE) {
  42714. if (request.status === 200 || request.status === 0) {
  42715. var cMap = new CMap(true);
  42716. var lexer = new Lexer(new StringStream(request.responseText));
  42717. parseCMap(cMap, lexer, builtInCMapParams, null).then(function (parsedCMap) {
  42718. resolve(parsedCMap);
  42719. });
  42720. } else {
  42721. reject(new Error('Unable to get cMap at: ' + url));
  42722. }
  42723. }
  42724. };
  42725. request.open('GET', url, true);
  42726. request.send(null);
  42727. });
  42728. }
  42729. return {
  42730. create: function (encoding, builtInCMapParams, useCMap) {
  42731. if (isName(encoding)) {
  42732. return createBuiltInCMap(encoding.name, builtInCMapParams);
  42733. } else if (isStream(encoding)) {
  42734. var cMap = new CMap();
  42735. var lexer = new Lexer(encoding);
  42736. return parseCMap(cMap, lexer, builtInCMapParams, useCMap).then(function (parsedCMap) {
  42737. if (parsedCMap.isIdentityCMap) {
  42738. return createBuiltInCMap(parsedCMap.name, builtInCMapParams);
  42739. }
  42740. return parsedCMap;
  42741. });
  42742. }
  42743. return Promise.reject(new Error('Encoding required.'));
  42744. }
  42745. };
  42746. }();
  42747. exports.CMap = CMap;
  42748. exports.CMapFactory = CMapFactory;
  42749. exports.IdentityCMap = IdentityCMap;
  42750. }));
  42751. (function (root, factory) {
  42752. factory(root.pdfjsCoreFonts = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreGlyphList, root.pdfjsCoreFontRenderer, root.pdfjsCoreEncodings, root.pdfjsCoreStandardFonts, root.pdfjsCoreUnicode, root.pdfjsCoreType1Parser, root.pdfjsCoreCFFParser);
  42753. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreGlyphList, coreFontRenderer, coreEncodings, coreStandardFonts, coreUnicode, coreType1Parser, coreCFFParser) {
  42754. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  42755. var FontType = sharedUtil.FontType;
  42756. var assert = sharedUtil.assert;
  42757. var bytesToString = sharedUtil.bytesToString;
  42758. var error = sharedUtil.error;
  42759. var info = sharedUtil.info;
  42760. var isArray = sharedUtil.isArray;
  42761. var isInt = sharedUtil.isInt;
  42762. var isNum = sharedUtil.isNum;
  42763. var readUint32 = sharedUtil.readUint32;
  42764. var shadow = sharedUtil.shadow;
  42765. var string32 = sharedUtil.string32;
  42766. var warn = sharedUtil.warn;
  42767. var MissingDataException = sharedUtil.MissingDataException;
  42768. var isSpace = sharedUtil.isSpace;
  42769. var Stream = coreStream.Stream;
  42770. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  42771. var getDingbatsGlyphsUnicode = coreGlyphList.getDingbatsGlyphsUnicode;
  42772. var FontRendererFactory = coreFontRenderer.FontRendererFactory;
  42773. var StandardEncoding = coreEncodings.StandardEncoding;
  42774. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  42775. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  42776. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  42777. var getEncoding = coreEncodings.getEncoding;
  42778. var getStdFontMap = coreStandardFonts.getStdFontMap;
  42779. var getNonStdFontMap = coreStandardFonts.getNonStdFontMap;
  42780. var getGlyphMapForStandardFonts = coreStandardFonts.getGlyphMapForStandardFonts;
  42781. var getSupplementalGlyphMapForArialBlack = coreStandardFonts.getSupplementalGlyphMapForArialBlack;
  42782. var getUnicodeRangeFor = coreUnicode.getUnicodeRangeFor;
  42783. var mapSpecialUnicodeValues = coreUnicode.mapSpecialUnicodeValues;
  42784. var getUnicodeForGlyph = coreUnicode.getUnicodeForGlyph;
  42785. var Type1Parser = coreType1Parser.Type1Parser;
  42786. var CFFStandardStrings = coreCFFParser.CFFStandardStrings;
  42787. var CFFParser = coreCFFParser.CFFParser;
  42788. var CFFCompiler = coreCFFParser.CFFCompiler;
  42789. var CFF = coreCFFParser.CFF;
  42790. var CFFHeader = coreCFFParser.CFFHeader;
  42791. var CFFTopDict = coreCFFParser.CFFTopDict;
  42792. var CFFPrivateDict = coreCFFParser.CFFPrivateDict;
  42793. var CFFStrings = coreCFFParser.CFFStrings;
  42794. var CFFIndex = coreCFFParser.CFFIndex;
  42795. var CFFCharset = coreCFFParser.CFFCharset;
  42796. // Unicode Private Use Area
  42797. var PRIVATE_USE_OFFSET_START = 0xE000;
  42798. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  42799. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  42800. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  42801. // except for Type 3 fonts
  42802. var PDF_GLYPH_SPACE_UNITS = 1000;
  42803. // Accented charactars are not displayed properly on Windows, using this flag
  42804. // to control analysis of seac charstrings.
  42805. var SEAC_ANALYSIS_ENABLED = false;
  42806. var FontFlags = {
  42807. FixedPitch: 1,
  42808. Serif: 2,
  42809. Symbolic: 4,
  42810. Script: 8,
  42811. Nonsymbolic: 32,
  42812. Italic: 64,
  42813. AllCap: 65536,
  42814. SmallCap: 131072,
  42815. ForceBold: 262144
  42816. };
  42817. var MacStandardGlyphOrdering = [
  42818. '.notdef',
  42819. '.null',
  42820. 'nonmarkingreturn',
  42821. 'space',
  42822. 'exclam',
  42823. 'quotedbl',
  42824. 'numbersign',
  42825. 'dollar',
  42826. 'percent',
  42827. 'ampersand',
  42828. 'quotesingle',
  42829. 'parenleft',
  42830. 'parenright',
  42831. 'asterisk',
  42832. 'plus',
  42833. 'comma',
  42834. 'hyphen',
  42835. 'period',
  42836. 'slash',
  42837. 'zero',
  42838. 'one',
  42839. 'two',
  42840. 'three',
  42841. 'four',
  42842. 'five',
  42843. 'six',
  42844. 'seven',
  42845. 'eight',
  42846. 'nine',
  42847. 'colon',
  42848. 'semicolon',
  42849. 'less',
  42850. 'equal',
  42851. 'greater',
  42852. 'question',
  42853. 'at',
  42854. 'A',
  42855. 'B',
  42856. 'C',
  42857. 'D',
  42858. 'E',
  42859. 'F',
  42860. 'G',
  42861. 'H',
  42862. 'I',
  42863. 'J',
  42864. 'K',
  42865. 'L',
  42866. 'M',
  42867. 'N',
  42868. 'O',
  42869. 'P',
  42870. 'Q',
  42871. 'R',
  42872. 'S',
  42873. 'T',
  42874. 'U',
  42875. 'V',
  42876. 'W',
  42877. 'X',
  42878. 'Y',
  42879. 'Z',
  42880. 'bracketleft',
  42881. 'backslash',
  42882. 'bracketright',
  42883. 'asciicircum',
  42884. 'underscore',
  42885. 'grave',
  42886. 'a',
  42887. 'b',
  42888. 'c',
  42889. 'd',
  42890. 'e',
  42891. 'f',
  42892. 'g',
  42893. 'h',
  42894. 'i',
  42895. 'j',
  42896. 'k',
  42897. 'l',
  42898. 'm',
  42899. 'n',
  42900. 'o',
  42901. 'p',
  42902. 'q',
  42903. 'r',
  42904. 's',
  42905. 't',
  42906. 'u',
  42907. 'v',
  42908. 'w',
  42909. 'x',
  42910. 'y',
  42911. 'z',
  42912. 'braceleft',
  42913. 'bar',
  42914. 'braceright',
  42915. 'asciitilde',
  42916. 'Adieresis',
  42917. 'Aring',
  42918. 'Ccedilla',
  42919. 'Eacute',
  42920. 'Ntilde',
  42921. 'Odieresis',
  42922. 'Udieresis',
  42923. 'aacute',
  42924. 'agrave',
  42925. 'acircumflex',
  42926. 'adieresis',
  42927. 'atilde',
  42928. 'aring',
  42929. 'ccedilla',
  42930. 'eacute',
  42931. 'egrave',
  42932. 'ecircumflex',
  42933. 'edieresis',
  42934. 'iacute',
  42935. 'igrave',
  42936. 'icircumflex',
  42937. 'idieresis',
  42938. 'ntilde',
  42939. 'oacute',
  42940. 'ograve',
  42941. 'ocircumflex',
  42942. 'odieresis',
  42943. 'otilde',
  42944. 'uacute',
  42945. 'ugrave',
  42946. 'ucircumflex',
  42947. 'udieresis',
  42948. 'dagger',
  42949. 'degree',
  42950. 'cent',
  42951. 'sterling',
  42952. 'section',
  42953. 'bullet',
  42954. 'paragraph',
  42955. 'germandbls',
  42956. 'registered',
  42957. 'copyright',
  42958. 'trademark',
  42959. 'acute',
  42960. 'dieresis',
  42961. 'notequal',
  42962. 'AE',
  42963. 'Oslash',
  42964. 'infinity',
  42965. 'plusminus',
  42966. 'lessequal',
  42967. 'greaterequal',
  42968. 'yen',
  42969. 'mu',
  42970. 'partialdiff',
  42971. 'summation',
  42972. 'product',
  42973. 'pi',
  42974. 'integral',
  42975. 'ordfeminine',
  42976. 'ordmasculine',
  42977. 'Omega',
  42978. 'ae',
  42979. 'oslash',
  42980. 'questiondown',
  42981. 'exclamdown',
  42982. 'logicalnot',
  42983. 'radical',
  42984. 'florin',
  42985. 'approxequal',
  42986. 'Delta',
  42987. 'guillemotleft',
  42988. 'guillemotright',
  42989. 'ellipsis',
  42990. 'nonbreakingspace',
  42991. 'Agrave',
  42992. 'Atilde',
  42993. 'Otilde',
  42994. 'OE',
  42995. 'oe',
  42996. 'endash',
  42997. 'emdash',
  42998. 'quotedblleft',
  42999. 'quotedblright',
  43000. 'quoteleft',
  43001. 'quoteright',
  43002. 'divide',
  43003. 'lozenge',
  43004. 'ydieresis',
  43005. 'Ydieresis',
  43006. 'fraction',
  43007. 'currency',
  43008. 'guilsinglleft',
  43009. 'guilsinglright',
  43010. 'fi',
  43011. 'fl',
  43012. 'daggerdbl',
  43013. 'periodcentered',
  43014. 'quotesinglbase',
  43015. 'quotedblbase',
  43016. 'perthousand',
  43017. 'Acircumflex',
  43018. 'Ecircumflex',
  43019. 'Aacute',
  43020. 'Edieresis',
  43021. 'Egrave',
  43022. 'Iacute',
  43023. 'Icircumflex',
  43024. 'Idieresis',
  43025. 'Igrave',
  43026. 'Oacute',
  43027. 'Ocircumflex',
  43028. 'apple',
  43029. 'Ograve',
  43030. 'Uacute',
  43031. 'Ucircumflex',
  43032. 'Ugrave',
  43033. 'dotlessi',
  43034. 'circumflex',
  43035. 'tilde',
  43036. 'macron',
  43037. 'breve',
  43038. 'dotaccent',
  43039. 'ring',
  43040. 'cedilla',
  43041. 'hungarumlaut',
  43042. 'ogonek',
  43043. 'caron',
  43044. 'Lslash',
  43045. 'lslash',
  43046. 'Scaron',
  43047. 'scaron',
  43048. 'Zcaron',
  43049. 'zcaron',
  43050. 'brokenbar',
  43051. 'Eth',
  43052. 'eth',
  43053. 'Yacute',
  43054. 'yacute',
  43055. 'Thorn',
  43056. 'thorn',
  43057. 'minus',
  43058. 'multiply',
  43059. 'onesuperior',
  43060. 'twosuperior',
  43061. 'threesuperior',
  43062. 'onehalf',
  43063. 'onequarter',
  43064. 'threequarters',
  43065. 'franc',
  43066. 'Gbreve',
  43067. 'gbreve',
  43068. 'Idotaccent',
  43069. 'Scedilla',
  43070. 'scedilla',
  43071. 'Cacute',
  43072. 'cacute',
  43073. 'Ccaron',
  43074. 'ccaron',
  43075. 'dcroat'
  43076. ];
  43077. function adjustWidths(properties) {
  43078. if (!properties.fontMatrix) {
  43079. return;
  43080. }
  43081. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  43082. return;
  43083. }
  43084. // adjusting width to fontMatrix scale
  43085. var scale = 0.001 / properties.fontMatrix[0];
  43086. var glyphsWidths = properties.widths;
  43087. for (var glyph in glyphsWidths) {
  43088. glyphsWidths[glyph] *= scale;
  43089. }
  43090. properties.defaultWidth *= scale;
  43091. }
  43092. function adjustToUnicode(properties, builtInEncoding) {
  43093. if (properties.hasIncludedToUnicodeMap) {
  43094. return;
  43095. }
  43096. // The font dictionary has a `ToUnicode` entry.
  43097. if (properties.hasEncoding) {
  43098. return;
  43099. }
  43100. // The font dictionary has an `Encoding` entry.
  43101. if (builtInEncoding === properties.defaultEncoding) {
  43102. return;
  43103. }
  43104. // No point in trying to adjust `toUnicode` if the encodings match.
  43105. if (properties.toUnicode instanceof IdentityToUnicodeMap) {
  43106. return;
  43107. }
  43108. var toUnicode = [], glyphsUnicodeMap = getGlyphsUnicode();
  43109. for (var charCode in builtInEncoding) {
  43110. var glyphName = builtInEncoding[charCode];
  43111. var unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  43112. if (unicode !== -1) {
  43113. toUnicode[charCode] = String.fromCharCode(unicode);
  43114. }
  43115. }
  43116. properties.toUnicode.amend(toUnicode);
  43117. }
  43118. function getFontType(type, subtype) {
  43119. switch (type) {
  43120. case 'Type1':
  43121. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  43122. case 'CIDFontType0':
  43123. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C : FontType.CIDFONTTYPE0;
  43124. case 'OpenType':
  43125. return FontType.OPENTYPE;
  43126. case 'TrueType':
  43127. return FontType.TRUETYPE;
  43128. case 'CIDFontType2':
  43129. return FontType.CIDFONTTYPE2;
  43130. case 'MMType1':
  43131. return FontType.MMTYPE1;
  43132. case 'Type0':
  43133. return FontType.TYPE0;
  43134. default:
  43135. return FontType.UNKNOWN;
  43136. }
  43137. }
  43138. // Some bad PDF generators, e.g. Scribus PDF, include glyph names
  43139. // in a 'uniXXXX' format -- attempting to recover proper ones.
  43140. function recoverGlyphName(name, glyphsUnicodeMap) {
  43141. if (glyphsUnicodeMap[name] !== undefined) {
  43142. return name;
  43143. }
  43144. // The glyph name is non-standard, trying to recover.
  43145. var unicode = getUnicodeForGlyph(name, glyphsUnicodeMap);
  43146. if (unicode !== -1) {
  43147. for (var key in glyphsUnicodeMap) {
  43148. if (glyphsUnicodeMap[key] === unicode) {
  43149. return key;
  43150. }
  43151. }
  43152. }
  43153. info('Unable to recover a standard glyph name for: ' + name);
  43154. return name;
  43155. }
  43156. var Glyph = function GlyphClosure() {
  43157. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont) {
  43158. this.fontChar = fontChar;
  43159. this.unicode = unicode;
  43160. this.accent = accent;
  43161. this.width = width;
  43162. this.vmetric = vmetric;
  43163. this.operatorListId = operatorListId;
  43164. this.isSpace = isSpace;
  43165. this.isInFont = isInFont;
  43166. }
  43167. Glyph.prototype.matchesForCache = function (fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont) {
  43168. 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;
  43169. };
  43170. return Glyph;
  43171. }();
  43172. var ToUnicodeMap = function ToUnicodeMapClosure() {
  43173. function ToUnicodeMap(cmap) {
  43174. // The elements of this._map can be integers or strings, depending on how
  43175. // |cmap| was created.
  43176. this._map = cmap;
  43177. }
  43178. ToUnicodeMap.prototype = {
  43179. get length() {
  43180. return this._map.length;
  43181. },
  43182. forEach: function (callback) {
  43183. for (var charCode in this._map) {
  43184. callback(charCode, this._map[charCode].charCodeAt(0));
  43185. }
  43186. },
  43187. has: function (i) {
  43188. return this._map[i] !== undefined;
  43189. },
  43190. get: function (i) {
  43191. return this._map[i];
  43192. },
  43193. charCodeOf: function (v) {
  43194. return this._map.indexOf(v);
  43195. },
  43196. amend: function (map) {
  43197. for (var charCode in map) {
  43198. this._map[charCode] = map[charCode];
  43199. }
  43200. }
  43201. };
  43202. return ToUnicodeMap;
  43203. }();
  43204. var IdentityToUnicodeMap = function IdentityToUnicodeMapClosure() {
  43205. function IdentityToUnicodeMap(firstChar, lastChar) {
  43206. this.firstChar = firstChar;
  43207. this.lastChar = lastChar;
  43208. }
  43209. IdentityToUnicodeMap.prototype = {
  43210. get length() {
  43211. return this.lastChar + 1 - this.firstChar;
  43212. },
  43213. forEach: function (callback) {
  43214. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  43215. callback(i, i);
  43216. }
  43217. },
  43218. has: function (i) {
  43219. return this.firstChar <= i && i <= this.lastChar;
  43220. },
  43221. get: function (i) {
  43222. if (this.firstChar <= i && i <= this.lastChar) {
  43223. return String.fromCharCode(i);
  43224. }
  43225. return undefined;
  43226. },
  43227. charCodeOf: function (v) {
  43228. return isInt(v) && v >= this.firstChar && v <= this.lastChar ? v : -1;
  43229. },
  43230. amend: function (map) {
  43231. error('Should not call amend()');
  43232. }
  43233. };
  43234. return IdentityToUnicodeMap;
  43235. }();
  43236. var OpenTypeFileBuilder = function OpenTypeFileBuilderClosure() {
  43237. function writeInt16(dest, offset, num) {
  43238. dest[offset] = num >> 8 & 0xFF;
  43239. dest[offset + 1] = num & 0xFF;
  43240. }
  43241. function writeInt32(dest, offset, num) {
  43242. dest[offset] = num >> 24 & 0xFF;
  43243. dest[offset + 1] = num >> 16 & 0xFF;
  43244. dest[offset + 2] = num >> 8 & 0xFF;
  43245. dest[offset + 3] = num & 0xFF;
  43246. }
  43247. function writeData(dest, offset, data) {
  43248. var i, ii;
  43249. if (data instanceof Uint8Array) {
  43250. dest.set(data, offset);
  43251. } else if (typeof data === 'string') {
  43252. for (i = 0, ii = data.length; i < ii; i++) {
  43253. dest[offset++] = data.charCodeAt(i) & 0xFF;
  43254. }
  43255. } else {
  43256. // treating everything else as array
  43257. for (i = 0, ii = data.length; i < ii; i++) {
  43258. dest[offset++] = data[i] & 0xFF;
  43259. }
  43260. }
  43261. }
  43262. function OpenTypeFileBuilder(sfnt) {
  43263. this.sfnt = sfnt;
  43264. this.tables = Object.create(null);
  43265. }
  43266. OpenTypeFileBuilder.getSearchParams = function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  43267. var maxPower2 = 1, log2 = 0;
  43268. while ((maxPower2 ^ entriesCount) > maxPower2) {
  43269. maxPower2 <<= 1;
  43270. log2++;
  43271. }
  43272. var searchRange = maxPower2 * entrySize;
  43273. return {
  43274. range: searchRange,
  43275. entry: log2,
  43276. rangeShift: entrySize * entriesCount - searchRange
  43277. };
  43278. };
  43279. var OTF_HEADER_SIZE = 12;
  43280. var OTF_TABLE_ENTRY_SIZE = 16;
  43281. OpenTypeFileBuilder.prototype = {
  43282. toArray: function OpenTypeFileBuilder_toArray() {
  43283. var sfnt = this.sfnt;
  43284. // Tables needs to be written by ascendant alphabetic order
  43285. var tables = this.tables;
  43286. var tablesNames = Object.keys(tables);
  43287. tablesNames.sort();
  43288. var numTables = tablesNames.length;
  43289. var i, j, jj, table, tableName;
  43290. // layout the tables data
  43291. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  43292. var tableOffsets = [offset];
  43293. for (i = 0; i < numTables; i++) {
  43294. table = tables[tablesNames[i]];
  43295. var paddedLength = (table.length + 3 & ~3) >>> 0;
  43296. offset += paddedLength;
  43297. tableOffsets.push(offset);
  43298. }
  43299. var file = new Uint8Array(offset);
  43300. // write the table data first (mostly for checksum)
  43301. for (i = 0; i < numTables; i++) {
  43302. table = tables[tablesNames[i]];
  43303. writeData(file, tableOffsets[i], table);
  43304. }
  43305. // sfnt version (4 bytes)
  43306. if (sfnt === 'true') {
  43307. // Windows hates the Mac TrueType sfnt version number
  43308. sfnt = string32(0x00010000);
  43309. }
  43310. file[0] = sfnt.charCodeAt(0) & 0xFF;
  43311. file[1] = sfnt.charCodeAt(1) & 0xFF;
  43312. file[2] = sfnt.charCodeAt(2) & 0xFF;
  43313. file[3] = sfnt.charCodeAt(3) & 0xFF;
  43314. // numTables (2 bytes)
  43315. writeInt16(file, 4, numTables);
  43316. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  43317. // searchRange (2 bytes)
  43318. writeInt16(file, 6, searchParams.range);
  43319. // entrySelector (2 bytes)
  43320. writeInt16(file, 8, searchParams.entry);
  43321. // rangeShift (2 bytes)
  43322. writeInt16(file, 10, searchParams.rangeShift);
  43323. offset = OTF_HEADER_SIZE;
  43324. // writing table entries
  43325. for (i = 0; i < numTables; i++) {
  43326. tableName = tablesNames[i];
  43327. file[offset] = tableName.charCodeAt(0) & 0xFF;
  43328. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  43329. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  43330. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  43331. // checksum
  43332. var checksum = 0;
  43333. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  43334. var quad = readUint32(file, j);
  43335. checksum = checksum + quad >>> 0;
  43336. }
  43337. writeInt32(file, offset + 4, checksum);
  43338. // offset
  43339. writeInt32(file, offset + 8, tableOffsets[i]);
  43340. // length
  43341. writeInt32(file, offset + 12, tables[tableName].length);
  43342. offset += OTF_TABLE_ENTRY_SIZE;
  43343. }
  43344. return file;
  43345. },
  43346. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  43347. if (tag in this.tables) {
  43348. throw new Error('Table ' + tag + ' already exists');
  43349. }
  43350. this.tables[tag] = data;
  43351. }
  43352. };
  43353. return OpenTypeFileBuilder;
  43354. }();
  43355. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  43356. // issues when they are painted on the canvas, e.g. complex-script shaping or
  43357. // control/whitespace characters. The ranges are listed in pairs: the first item
  43358. // is a code of the first problematic code, the second one is the next
  43359. // non-problematic code. The ranges must be in sorted order.
  43360. var ProblematicCharRanges = new Int32Array([
  43361. // Control characters.
  43362. 0x0000,
  43363. 0x0020,
  43364. 0x007F,
  43365. 0x00A1,
  43366. 0x00AD,
  43367. 0x00AE,
  43368. // Chars that is used in complex-script shaping.
  43369. 0x0600,
  43370. 0x0780,
  43371. 0x08A0,
  43372. 0x10A0,
  43373. 0x1780,
  43374. 0x1800,
  43375. 0x1C00,
  43376. 0x1C50,
  43377. // General punctuation chars.
  43378. 0x2000,
  43379. 0x2010,
  43380. 0x2011,
  43381. 0x2012,
  43382. 0x2028,
  43383. 0x2030,
  43384. 0x205F,
  43385. 0x2070,
  43386. 0x25CC,
  43387. 0x25CD,
  43388. 0x3000,
  43389. 0x3001,
  43390. // Chars that is used in complex-script shaping.
  43391. 0xAA60,
  43392. 0xAA80,
  43393. // Specials Unicode block.
  43394. 0xFFF0,
  43395. 0x10000
  43396. ]);
  43397. /**
  43398. * 'Font' is the class the outside world should use, it encapsulate all the font
  43399. * decoding logics whatever type it is (assuming the font type is supported).
  43400. *
  43401. * For example to read a Type1 font and to attach it to the document:
  43402. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  43403. * type1Font.bind();
  43404. */
  43405. var Font = function FontClosure() {
  43406. function Font(name, file, properties) {
  43407. var charCode, glyphName, unicode;
  43408. this.name = name;
  43409. this.loadedName = properties.loadedName;
  43410. this.isType3Font = properties.isType3Font;
  43411. this.sizes = [];
  43412. this.missingFile = false;
  43413. this.glyphCache = Object.create(null);
  43414. var names = name.split('+');
  43415. names = names.length > 1 ? names[1] : names[0];
  43416. names = names.split(/[-,_]/g)[0];
  43417. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  43418. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  43419. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  43420. var type = properties.type;
  43421. var subtype = properties.subtype;
  43422. this.type = type;
  43423. this.fallbackName = this.isMonospace ? 'monospace' : this.isSerifFont ? 'serif' : 'sans-serif';
  43424. this.differences = properties.differences;
  43425. this.widths = properties.widths;
  43426. this.defaultWidth = properties.defaultWidth;
  43427. this.composite = properties.composite;
  43428. this.wideChars = properties.wideChars;
  43429. this.cMap = properties.cMap;
  43430. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  43431. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  43432. this.fontMatrix = properties.fontMatrix;
  43433. this.bbox = properties.bbox;
  43434. this.toUnicode = properties.toUnicode;
  43435. this.toFontChar = [];
  43436. if (properties.type === 'Type3') {
  43437. for (charCode = 0; charCode < 256; charCode++) {
  43438. this.toFontChar[charCode] = this.differences[charCode] || properties.defaultEncoding[charCode];
  43439. }
  43440. this.fontType = FontType.TYPE3;
  43441. return;
  43442. }
  43443. this.cidEncoding = properties.cidEncoding;
  43444. this.vertical = properties.vertical;
  43445. if (this.vertical) {
  43446. this.vmetrics = properties.vmetrics;
  43447. this.defaultVMetrics = properties.defaultVMetrics;
  43448. }
  43449. var glyphsUnicodeMap;
  43450. if (!file || file.isEmpty) {
  43451. if (file) {
  43452. // Some bad PDF generators will include empty font files,
  43453. // attempting to recover by assuming that no file exists.
  43454. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  43455. }
  43456. this.missingFile = true;
  43457. // The file data is not specified. Trying to fix the font name
  43458. // to be used with the canvas.font.
  43459. var fontName = name.replace(/[,_]/g, '-');
  43460. var stdFontMap = getStdFontMap(), nonStdFontMap = getNonStdFontMap();
  43461. var isStandardFont = !!stdFontMap[fontName] || !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  43462. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  43463. this.bold = fontName.search(/bold/gi) !== -1;
  43464. this.italic = fontName.search(/oblique/gi) !== -1 || fontName.search(/italic/gi) !== -1;
  43465. // Use 'name' instead of 'fontName' here because the original
  43466. // name ArialBlack for example will be replaced by Helvetica.
  43467. this.black = name.search(/Black/g) !== -1;
  43468. // if at least one width is present, remeasure all chars when exists
  43469. this.remeasure = Object.keys(this.widths).length > 0;
  43470. if (isStandardFont && type === 'CIDFontType2' && properties.cidEncoding.indexOf('Identity-') === 0) {
  43471. var GlyphMapForStandardFonts = getGlyphMapForStandardFonts();
  43472. // Standard fonts might be embedded as CID font without glyph mapping.
  43473. // Building one based on GlyphMapForStandardFonts.
  43474. var map = [];
  43475. for (charCode in GlyphMapForStandardFonts) {
  43476. map[+charCode] = GlyphMapForStandardFonts[charCode];
  43477. }
  43478. if (/ArialBlack/i.test(name)) {
  43479. var SupplementalGlyphMapForArialBlack = getSupplementalGlyphMapForArialBlack();
  43480. for (charCode in SupplementalGlyphMapForArialBlack) {
  43481. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  43482. }
  43483. }
  43484. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  43485. if (!isIdentityUnicode) {
  43486. this.toUnicode.forEach(function (charCode, unicodeCharCode) {
  43487. map[+charCode] = unicodeCharCode;
  43488. });
  43489. }
  43490. this.toFontChar = map;
  43491. this.toUnicode = new ToUnicodeMap(map);
  43492. } else if (/Symbol/i.test(fontName)) {
  43493. this.toFontChar = buildToFontChar(SymbolSetEncoding, getGlyphsUnicode(), properties.differences);
  43494. } else if (/Dingbats/i.test(fontName)) {
  43495. if (/Wingdings/i.test(name)) {
  43496. warn('Non-embedded Wingdings font, falling back to ZapfDingbats.');
  43497. }
  43498. this.toFontChar = buildToFontChar(ZapfDingbatsEncoding, getDingbatsGlyphsUnicode(), properties.differences);
  43499. } else if (isStandardFont) {
  43500. this.toFontChar = buildToFontChar(properties.defaultEncoding, getGlyphsUnicode(), properties.differences);
  43501. } else {
  43502. glyphsUnicodeMap = getGlyphsUnicode();
  43503. this.toUnicode.forEach(function (charCode, unicodeCharCode) {
  43504. if (!this.composite) {
  43505. glyphName = properties.differences[charCode] || properties.defaultEncoding[charCode];
  43506. unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  43507. if (unicode !== -1) {
  43508. unicodeCharCode = unicode;
  43509. }
  43510. }
  43511. this.toFontChar[charCode] = unicodeCharCode;
  43512. }.bind(this));
  43513. }
  43514. this.loadedName = fontName.split('-')[0];
  43515. this.loading = false;
  43516. this.fontType = getFontType(type, subtype);
  43517. return;
  43518. }
  43519. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  43520. if (subtype === 'Type1C') {
  43521. if (type !== 'Type1' && type !== 'MMType1') {
  43522. // Some TrueType fonts by mistake claim Type1C
  43523. if (isTrueTypeFile(file)) {
  43524. subtype = 'TrueType';
  43525. } else {
  43526. type = 'Type1';
  43527. }
  43528. } else if (isOpenTypeFile(file)) {
  43529. // Sometimes the type/subtype can be a complete lie (see issue7598.pdf).
  43530. type = subtype = 'OpenType';
  43531. }
  43532. }
  43533. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  43534. type = 'CIDFontType0';
  43535. }
  43536. if (subtype === 'OpenType') {
  43537. type = 'OpenType';
  43538. }
  43539. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  43540. if (type === 'CIDFontType0') {
  43541. if (isType1File(file)) {
  43542. subtype = 'CIDFontType0';
  43543. } else if (isOpenTypeFile(file)) {
  43544. // Sometimes the type/subtype can be a complete lie (see issue6782.pdf).
  43545. type = subtype = 'OpenType';
  43546. } else {
  43547. subtype = 'CIDFontType0C';
  43548. }
  43549. }
  43550. var data;
  43551. switch (type) {
  43552. case 'MMType1':
  43553. info('MMType1 font (' + name + '), falling back to Type1.');
  43554. case 'Type1':
  43555. case 'CIDFontType0':
  43556. this.mimetype = 'font/opentype';
  43557. var cff = subtype === 'Type1C' || subtype === 'CIDFontType0C' ? new CFFFont(file, properties) : new Type1Font(name, file, properties);
  43558. adjustWidths(properties);
  43559. // Wrap the CFF data inside an OTF font file
  43560. data = this.convert(name, cff, properties);
  43561. break;
  43562. case 'OpenType':
  43563. case 'TrueType':
  43564. case 'CIDFontType2':
  43565. this.mimetype = 'font/opentype';
  43566. // Repair the TrueType file. It is can be damaged in the point of
  43567. // view of the sanitizer
  43568. data = this.checkAndRepair(name, file, properties);
  43569. if (this.isOpenType) {
  43570. adjustWidths(properties);
  43571. type = 'OpenType';
  43572. }
  43573. break;
  43574. default:
  43575. error('Font ' + type + ' is not supported');
  43576. break;
  43577. }
  43578. this.data = data;
  43579. this.fontType = getFontType(type, subtype);
  43580. // Transfer some properties again that could change during font conversion
  43581. this.fontMatrix = properties.fontMatrix;
  43582. this.widths = properties.widths;
  43583. this.defaultWidth = properties.defaultWidth;
  43584. this.toUnicode = properties.toUnicode;
  43585. this.encoding = properties.baseEncoding;
  43586. this.seacMap = properties.seacMap;
  43587. this.loading = true;
  43588. }
  43589. Font.getFontID = function () {
  43590. var ID = 1;
  43591. return function Font_getFontID() {
  43592. return String(ID++);
  43593. };
  43594. }();
  43595. function int16(b0, b1) {
  43596. return (b0 << 8) + b1;
  43597. }
  43598. function signedInt16(b0, b1) {
  43599. var value = (b0 << 8) + b1;
  43600. return value & 1 << 15 ? value - 0x10000 : value;
  43601. }
  43602. function int32(b0, b1, b2, b3) {
  43603. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  43604. }
  43605. function string16(value) {
  43606. return String.fromCharCode(value >> 8 & 0xff, value & 0xff);
  43607. }
  43608. function safeString16(value) {
  43609. // clamp value to the 16-bit int range
  43610. value = value > 0x7FFF ? 0x7FFF : value < -0x8000 ? -0x8000 : value;
  43611. return String.fromCharCode(value >> 8 & 0xff, value & 0xff);
  43612. }
  43613. function isTrueTypeFile(file) {
  43614. var header = file.peekBytes(4);
  43615. return readUint32(header, 0) === 0x00010000;
  43616. }
  43617. function isOpenTypeFile(file) {
  43618. var header = file.peekBytes(4);
  43619. return bytesToString(header) === 'OTTO';
  43620. }
  43621. function isType1File(file) {
  43622. var header = file.peekBytes(2);
  43623. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  43624. if (header[0] === 0x25 && header[1] === 0x21) {
  43625. return true;
  43626. }
  43627. // ... obviously some fonts violate that part of the specification,
  43628. // please refer to the comment in |Type1Font| below.
  43629. if (header[0] === 0x80 && header[1] === 0x01) {
  43630. // pfb file header.
  43631. return true;
  43632. }
  43633. return false;
  43634. }
  43635. function buildToFontChar(encoding, glyphsUnicodeMap, differences) {
  43636. var toFontChar = [], unicode;
  43637. for (var i = 0, ii = encoding.length; i < ii; i++) {
  43638. unicode = getUnicodeForGlyph(encoding[i], glyphsUnicodeMap);
  43639. if (unicode !== -1) {
  43640. toFontChar[i] = unicode;
  43641. }
  43642. }
  43643. for (var charCode in differences) {
  43644. unicode = getUnicodeForGlyph(differences[charCode], glyphsUnicodeMap);
  43645. if (unicode !== -1) {
  43646. toFontChar[+charCode] = unicode;
  43647. }
  43648. }
  43649. return toFontChar;
  43650. }
  43651. /**
  43652. * Helper function for |adjustMapping|.
  43653. * @return {boolean}
  43654. */
  43655. function isProblematicUnicodeLocation(code) {
  43656. // Using binary search to find a range start.
  43657. var i = 0, j = ProblematicCharRanges.length - 1;
  43658. while (i < j) {
  43659. var c = i + j + 1 >> 1;
  43660. if (code < ProblematicCharRanges[c]) {
  43661. j = c - 1;
  43662. } else {
  43663. i = c;
  43664. }
  43665. }
  43666. // Even index means code in problematic range.
  43667. return !(i & 1);
  43668. }
  43669. /**
  43670. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  43671. * with their unicode value. It also moves char codes that are in known
  43672. * problematic locations.
  43673. * @return {Object} Two properties:
  43674. * 'toFontChar' - maps original char codes(the value that will be read
  43675. * from commands such as show text) to the char codes that will be used in the
  43676. * font that we build
  43677. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  43678. */
  43679. function adjustMapping(charCodeToGlyphId, properties) {
  43680. var toUnicode = properties.toUnicode;
  43681. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  43682. var isIdentityUnicode = properties.toUnicode instanceof IdentityToUnicodeMap;
  43683. var newMap = Object.create(null);
  43684. var toFontChar = [];
  43685. var usedFontCharCodes = [];
  43686. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  43687. for (var originalCharCode in charCodeToGlyphId) {
  43688. originalCharCode |= 0;
  43689. var glyphId = charCodeToGlyphId[originalCharCode];
  43690. var fontCharCode = originalCharCode;
  43691. // First try to map the value to a unicode position if a non identity map
  43692. // was created.
  43693. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  43694. var unicode = toUnicode.get(fontCharCode);
  43695. // TODO: Try to map ligatures to the correct spot.
  43696. if (unicode.length === 1) {
  43697. fontCharCode = unicode.charCodeAt(0);
  43698. }
  43699. }
  43700. // Try to move control characters, special characters and already mapped
  43701. // characters to the private use area since they will not be drawn by
  43702. // canvas if left in their current position. Also, move characters if the
  43703. // font was symbolic and there is only an identity unicode map since the
  43704. // characters probably aren't in the correct position (fixes an issue
  43705. // with firefox and thuluthfont).
  43706. if ((usedFontCharCodes[fontCharCode] !== undefined || isProblematicUnicodeLocation(fontCharCode) || isSymbolic && isIdentityUnicode) && nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) {
  43707. // Room left.
  43708. // Loop to try and find a free spot in the private use area.
  43709. do {
  43710. fontCharCode = nextAvailableFontCharCode++;
  43711. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  43712. fontCharCode = 0xF020;
  43713. nextAvailableFontCharCode = fontCharCode + 1;
  43714. }
  43715. } while (usedFontCharCodes[fontCharCode] !== undefined && nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  43716. }
  43717. newMap[fontCharCode] = glyphId;
  43718. toFontChar[originalCharCode] = fontCharCode;
  43719. usedFontCharCodes[fontCharCode] = true;
  43720. }
  43721. return {
  43722. toFontChar: toFontChar,
  43723. charCodeToGlyphId: newMap,
  43724. nextAvailableFontCharCode: nextAvailableFontCharCode
  43725. };
  43726. }
  43727. function getRanges(glyphs, numGlyphs) {
  43728. // Array.sort() sorts by characters, not numerically, so convert to an
  43729. // array of characters.
  43730. var codes = [];
  43731. for (var charCode in glyphs) {
  43732. // Remove an invalid glyph ID mappings to make OTS happy.
  43733. if (glyphs[charCode] >= numGlyphs) {
  43734. continue;
  43735. }
  43736. codes.push({
  43737. fontCharCode: charCode | 0,
  43738. glyphId: glyphs[charCode]
  43739. });
  43740. }
  43741. codes.sort(function fontGetRangesSort(a, b) {
  43742. return a.fontCharCode - b.fontCharCode;
  43743. });
  43744. // Split the sorted codes into ranges.
  43745. var ranges = [];
  43746. var length = codes.length;
  43747. for (var n = 0; n < length;) {
  43748. var start = codes[n].fontCharCode;
  43749. var codeIndices = [codes[n].glyphId];
  43750. ++n;
  43751. var end = start;
  43752. while (n < length && end + 1 === codes[n].fontCharCode) {
  43753. codeIndices.push(codes[n].glyphId);
  43754. ++end;
  43755. ++n;
  43756. if (end === 0xFFFF) {
  43757. break;
  43758. }
  43759. }
  43760. ranges.push([
  43761. start,
  43762. end,
  43763. codeIndices
  43764. ]);
  43765. }
  43766. return ranges;
  43767. }
  43768. function createCmapTable(glyphs, numGlyphs) {
  43769. var ranges = getRanges(glyphs, numGlyphs);
  43770. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  43771. var cmap = '\x00\x00' + // version
  43772. string16(numTables) + // numTables
  43773. '\x00\x03' + // platformID
  43774. '\x00\x01' + // encodingID
  43775. string32(4 + numTables * 8);
  43776. // start of the table record
  43777. var i, ii, j, jj;
  43778. for (i = ranges.length - 1; i >= 0; --i) {
  43779. if (ranges[i][0] <= 0xFFFF) {
  43780. break;
  43781. }
  43782. }
  43783. var bmpLength = i + 1;
  43784. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  43785. ranges[i][1] = 0xFFFE;
  43786. }
  43787. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  43788. var segCount = bmpLength + trailingRangesCount;
  43789. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  43790. // Fill up the 4 parallel arrays describing the segments.
  43791. var startCount = '';
  43792. var endCount = '';
  43793. var idDeltas = '';
  43794. var idRangeOffsets = '';
  43795. var glyphsIds = '';
  43796. var bias = 0;
  43797. var range, start, end, codes;
  43798. for (i = 0, ii = bmpLength; i < ii; i++) {
  43799. range = ranges[i];
  43800. start = range[0];
  43801. end = range[1];
  43802. startCount += string16(start);
  43803. endCount += string16(end);
  43804. codes = range[2];
  43805. var contiguous = true;
  43806. for (j = 1, jj = codes.length; j < jj; ++j) {
  43807. if (codes[j] !== codes[j - 1] + 1) {
  43808. contiguous = false;
  43809. break;
  43810. }
  43811. }
  43812. if (!contiguous) {
  43813. var offset = (segCount - i) * 2 + bias * 2;
  43814. bias += end - start + 1;
  43815. idDeltas += string16(0);
  43816. idRangeOffsets += string16(offset);
  43817. for (j = 0, jj = codes.length; j < jj; ++j) {
  43818. glyphsIds += string16(codes[j]);
  43819. }
  43820. } else {
  43821. var startCode = codes[0];
  43822. idDeltas += string16(startCode - start & 0xFFFF);
  43823. idRangeOffsets += string16(0);
  43824. }
  43825. }
  43826. if (trailingRangesCount > 0) {
  43827. endCount += '\xFF\xFF';
  43828. startCount += '\xFF\xFF';
  43829. idDeltas += '\x00\x01';
  43830. idRangeOffsets += '\x00\x00';
  43831. }
  43832. var format314 = '\x00\x00' + // language
  43833. string16(2 * segCount) + string16(searchParams.range) + string16(searchParams.entry) + string16(searchParams.rangeShift) + endCount + '\x00\x00' + startCount + idDeltas + idRangeOffsets + glyphsIds;
  43834. var format31012 = '';
  43835. var header31012 = '';
  43836. if (numTables > 1) {
  43837. cmap += '\x00\x03' + // platformID
  43838. '\x00\x0A' + // encodingID
  43839. string32(4 + numTables * 8 + 4 + format314.length);
  43840. // start of the table record
  43841. format31012 = '';
  43842. for (i = 0, ii = ranges.length; i < ii; i++) {
  43843. range = ranges[i];
  43844. start = range[0];
  43845. codes = range[2];
  43846. var code = codes[0];
  43847. for (j = 1, jj = codes.length; j < jj; ++j) {
  43848. if (codes[j] !== codes[j - 1] + 1) {
  43849. end = range[0] + j - 1;
  43850. format31012 += string32(start) + // startCharCode
  43851. string32(end) + // endCharCode
  43852. string32(code);
  43853. // startGlyphID
  43854. start = end + 1;
  43855. code = codes[j];
  43856. }
  43857. }
  43858. format31012 += string32(start) + // startCharCode
  43859. string32(range[1]) + // endCharCode
  43860. string32(code);
  43861. }
  43862. // startGlyphID
  43863. header31012 = '\x00\x0C' + // format
  43864. '\x00\x00' + // reserved
  43865. string32(format31012.length + 16) + // length
  43866. '\x00\x00\x00\x00' + // language
  43867. string32(format31012.length / 12);
  43868. }
  43869. // nGroups
  43870. return cmap + '\x00\x04' + // format
  43871. string16(format314.length + 4) + // length
  43872. format314 + header31012 + format31012;
  43873. }
  43874. function validateOS2Table(os2) {
  43875. var stream = new Stream(os2.data);
  43876. var version = stream.getUint16();
  43877. // TODO verify all OS/2 tables fields, but currently we validate only those
  43878. // that give us issues
  43879. stream.getBytes(60);
  43880. // skipping type, misc sizes, panose, unicode ranges
  43881. var selection = stream.getUint16();
  43882. if (version < 4 && selection & 0x0300) {
  43883. return false;
  43884. }
  43885. var firstChar = stream.getUint16();
  43886. var lastChar = stream.getUint16();
  43887. if (firstChar > lastChar) {
  43888. return false;
  43889. }
  43890. stream.getBytes(6);
  43891. // skipping sTypoAscender/Descender/LineGap
  43892. var usWinAscent = stream.getUint16();
  43893. if (usWinAscent === 0) {
  43894. // makes font unreadable by windows
  43895. return false;
  43896. }
  43897. // OS/2 appears to be valid, resetting some fields
  43898. os2.data[8] = os2.data[9] = 0;
  43899. // IE rejects fonts if fsType != 0
  43900. return true;
  43901. }
  43902. function createOS2Table(properties, charstrings, override) {
  43903. override = override || {
  43904. unitsPerEm: 0,
  43905. yMax: 0,
  43906. yMin: 0,
  43907. ascent: 0,
  43908. descent: 0
  43909. };
  43910. var ulUnicodeRange1 = 0;
  43911. var ulUnicodeRange2 = 0;
  43912. var ulUnicodeRange3 = 0;
  43913. var ulUnicodeRange4 = 0;
  43914. var firstCharIndex = null;
  43915. var lastCharIndex = 0;
  43916. if (charstrings) {
  43917. for (var code in charstrings) {
  43918. code |= 0;
  43919. if (firstCharIndex > code || !firstCharIndex) {
  43920. firstCharIndex = code;
  43921. }
  43922. if (lastCharIndex < code) {
  43923. lastCharIndex = code;
  43924. }
  43925. var position = getUnicodeRangeFor(code);
  43926. if (position < 32) {
  43927. ulUnicodeRange1 |= 1 << position;
  43928. } else if (position < 64) {
  43929. ulUnicodeRange2 |= 1 << position - 32;
  43930. } else if (position < 96) {
  43931. ulUnicodeRange3 |= 1 << position - 64;
  43932. } else if (position < 123) {
  43933. ulUnicodeRange4 |= 1 << position - 96;
  43934. } else {
  43935. error('Unicode ranges Bits > 123 are reserved for internal usage');
  43936. }
  43937. }
  43938. } else {
  43939. // TODO
  43940. firstCharIndex = 0;
  43941. lastCharIndex = 255;
  43942. }
  43943. var bbox = properties.bbox || [
  43944. 0,
  43945. 0,
  43946. 0,
  43947. 0
  43948. ];
  43949. var unitsPerEm = override.unitsPerEm || 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  43950. // if the font units differ to the PDF glyph space units
  43951. // then scale up the values
  43952. var scale = properties.ascentScaled ? 1.0 : unitsPerEm / PDF_GLYPH_SPACE_UNITS;
  43953. var typoAscent = override.ascent || Math.round(scale * (properties.ascent || bbox[3]));
  43954. var typoDescent = override.descent || Math.round(scale * (properties.descent || bbox[1]));
  43955. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  43956. typoDescent = -typoDescent;
  43957. }
  43958. // fixing incorrect descent
  43959. var winAscent = override.yMax || typoAscent;
  43960. var winDescent = -override.yMin || -typoDescent;
  43961. return '\x00\x03' + // version
  43962. '\x02\x24' + // xAvgCharWidth
  43963. '\x01\xF4' + // usWeightClass
  43964. '\x00\x05' + // usWidthClass
  43965. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  43966. '\x02\x8A' + // ySubscriptXSize
  43967. '\x02\xBB' + // ySubscriptYSize
  43968. '\x00\x00' + // ySubscriptXOffset
  43969. '\x00\x8C' + // ySubscriptYOffset
  43970. '\x02\x8A' + // ySuperScriptXSize
  43971. '\x02\xBB' + // ySuperScriptYSize
  43972. '\x00\x00' + // ySuperScriptXOffset
  43973. '\x01\xDF' + // ySuperScriptYOffset
  43974. '\x00\x31' + // yStrikeOutSize
  43975. '\x01\x02' + // yStrikeOutPosition
  43976. '\x00\x00' + // sFamilyClass
  43977. '\x00\x00\x06' + String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) + '\x00\x00\x00\x00\x00\x00' + // Panose
  43978. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  43979. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  43980. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  43981. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  43982. '\x2A\x32\x31\x2A' + // achVendID
  43983. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  43984. string16(firstCharIndex || properties.firstChar) + // usFirstCharIndex
  43985. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  43986. string16(typoAscent) + // sTypoAscender
  43987. string16(typoDescent) + // sTypoDescender
  43988. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  43989. string16(winAscent) + // usWinAscent
  43990. string16(winDescent) + // usWinDescent
  43991. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  43992. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  43993. string16(properties.xHeight) + // sxHeight
  43994. string16(properties.capHeight) + // sCapHeight
  43995. string16(0) + // usDefaultChar
  43996. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  43997. '\x00\x03';
  43998. }
  43999. // usMaxContext
  44000. function createPostTable(properties) {
  44001. var angle = Math.floor(properties.italicAngle * Math.pow(2, 16));
  44002. return '\x00\x03\x00\x00' + // Version number
  44003. string32(angle) + // italicAngle
  44004. '\x00\x00' + // underlinePosition
  44005. '\x00\x00' + // underlineThickness
  44006. string32(properties.fixedPitch) + // isFixedPitch
  44007. '\x00\x00\x00\x00' + // minMemType42
  44008. '\x00\x00\x00\x00' + // maxMemType42
  44009. '\x00\x00\x00\x00' + // minMemType1
  44010. '\x00\x00\x00\x00';
  44011. }
  44012. // maxMemType1
  44013. function createNameTable(name, proto) {
  44014. if (!proto) {
  44015. proto = [
  44016. [],
  44017. []
  44018. ];
  44019. }
  44020. // no strings and unicode strings
  44021. var strings = [
  44022. proto[0][0] || 'Original licence',
  44023. // 0.Copyright
  44024. proto[0][1] || name,
  44025. // 1.Font family
  44026. proto[0][2] || 'Unknown',
  44027. // 2.Font subfamily (font weight)
  44028. proto[0][3] || 'uniqueID',
  44029. // 3.Unique ID
  44030. proto[0][4] || name,
  44031. // 4.Full font name
  44032. proto[0][5] || 'Version 0.11',
  44033. // 5.Version
  44034. proto[0][6] || '',
  44035. // 6.Postscript name
  44036. proto[0][7] || 'Unknown',
  44037. // 7.Trademark
  44038. proto[0][8] || 'Unknown',
  44039. // 8.Manufacturer
  44040. proto[0][9] || 'Unknown'
  44041. ];
  44042. // 9.Designer
  44043. // Mac want 1-byte per character strings while Windows want
  44044. // 2-bytes per character, so duplicate the names table
  44045. var stringsUnicode = [];
  44046. var i, ii, j, jj, str;
  44047. for (i = 0, ii = strings.length; i < ii; i++) {
  44048. str = proto[1][i] || strings[i];
  44049. var strBufUnicode = [];
  44050. for (j = 0, jj = str.length; j < jj; j++) {
  44051. strBufUnicode.push(string16(str.charCodeAt(j)));
  44052. }
  44053. stringsUnicode.push(strBufUnicode.join(''));
  44054. }
  44055. var names = [
  44056. strings,
  44057. stringsUnicode
  44058. ];
  44059. var platforms = [
  44060. '\x00\x01',
  44061. '\x00\x03'
  44062. ];
  44063. var encodings = [
  44064. '\x00\x00',
  44065. '\x00\x01'
  44066. ];
  44067. var languages = [
  44068. '\x00\x00',
  44069. '\x04\x09'
  44070. ];
  44071. var namesRecordCount = strings.length * platforms.length;
  44072. var nameTable = '\x00\x00' + // format
  44073. string16(namesRecordCount) + // Number of names Record
  44074. string16(namesRecordCount * 12 + 6);
  44075. // Storage
  44076. // Build the name records field
  44077. var strOffset = 0;
  44078. for (i = 0, ii = platforms.length; i < ii; i++) {
  44079. var strs = names[i];
  44080. for (j = 0, jj = strs.length; j < jj; j++) {
  44081. str = strs[j];
  44082. var nameRecord = platforms[i] + // platform ID
  44083. encodings[i] + // encoding ID
  44084. languages[i] + // language ID
  44085. string16(j) + // name ID
  44086. string16(str.length) + string16(strOffset);
  44087. nameTable += nameRecord;
  44088. strOffset += str.length;
  44089. }
  44090. }
  44091. nameTable += strings.join('') + stringsUnicode.join('');
  44092. return nameTable;
  44093. }
  44094. Font.prototype = {
  44095. name: null,
  44096. font: null,
  44097. mimetype: null,
  44098. encoding: null,
  44099. get renderer() {
  44100. var renderer = FontRendererFactory.create(this, SEAC_ANALYSIS_ENABLED);
  44101. return shadow(this, 'renderer', renderer);
  44102. },
  44103. exportData: function Font_exportData() {
  44104. // TODO remove enumerating of the properties, e.g. hardcode exact names.
  44105. var data = {};
  44106. for (var i in this) {
  44107. if (this.hasOwnProperty(i)) {
  44108. data[i] = this[i];
  44109. }
  44110. }
  44111. return data;
  44112. },
  44113. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  44114. function readTableEntry(file) {
  44115. var tag = bytesToString(file.getBytes(4));
  44116. var checksum = file.getInt32() >>> 0;
  44117. var offset = file.getInt32() >>> 0;
  44118. var length = file.getInt32() >>> 0;
  44119. // Read the table associated data
  44120. var previousPosition = file.pos;
  44121. file.pos = file.start ? file.start : 0;
  44122. file.skip(offset);
  44123. var data = file.getBytes(length);
  44124. file.pos = previousPosition;
  44125. if (tag === 'head') {
  44126. // clearing checksum adjustment
  44127. data[8] = data[9] = data[10] = data[11] = 0;
  44128. data[17] |= 0x20;
  44129. }
  44130. //Set font optimized for cleartype flag
  44131. return {
  44132. tag: tag,
  44133. checksum: checksum,
  44134. length: length,
  44135. offset: offset,
  44136. data: data
  44137. };
  44138. }
  44139. function readOpenTypeHeader(ttf) {
  44140. return {
  44141. version: bytesToString(ttf.getBytes(4)),
  44142. numTables: ttf.getUint16(),
  44143. searchRange: ttf.getUint16(),
  44144. entrySelector: ttf.getUint16(),
  44145. rangeShift: ttf.getUint16()
  44146. };
  44147. }
  44148. /**
  44149. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  44150. * PDF spec
  44151. */
  44152. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  44153. if (!cmap) {
  44154. warn('No cmap table available.');
  44155. return {
  44156. platformId: -1,
  44157. encodingId: -1,
  44158. mappings: [],
  44159. hasShortCmap: false
  44160. };
  44161. }
  44162. var segment;
  44163. var start = (font.start ? font.start : 0) + cmap.offset;
  44164. font.pos = start;
  44165. var version = font.getUint16();
  44166. var numTables = font.getUint16();
  44167. var potentialTable;
  44168. var canBreak = false;
  44169. // There's an order of preference in terms of which cmap subtable to
  44170. // use:
  44171. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  44172. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  44173. // The following takes advantage of the fact that the tables are sorted
  44174. // to work.
  44175. for (var i = 0; i < numTables; i++) {
  44176. var platformId = font.getUint16();
  44177. var encodingId = font.getUint16();
  44178. var offset = font.getInt32() >>> 0;
  44179. var useTable = false;
  44180. if (platformId === 0 && encodingId === 0) {
  44181. useTable = true;
  44182. } else // Continue the loop since there still may be a higher priority
  44183. // table.
  44184. if (platformId === 1 && encodingId === 0) {
  44185. useTable = true;
  44186. } else // Continue the loop since there still may be a higher priority
  44187. // table.
  44188. if (platformId === 3 && encodingId === 1 && (!isSymbolicFont && hasEncoding || !potentialTable)) {
  44189. useTable = true;
  44190. if (!isSymbolicFont) {
  44191. canBreak = true;
  44192. }
  44193. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  44194. useTable = true;
  44195. canBreak = true;
  44196. }
  44197. if (useTable) {
  44198. potentialTable = {
  44199. platformId: platformId,
  44200. encodingId: encodingId,
  44201. offset: offset
  44202. };
  44203. }
  44204. if (canBreak) {
  44205. break;
  44206. }
  44207. }
  44208. if (potentialTable) {
  44209. font.pos = start + potentialTable.offset;
  44210. }
  44211. if (!potentialTable || font.peekByte() === -1) {
  44212. warn('Could not find a preferred cmap table.');
  44213. return {
  44214. platformId: -1,
  44215. encodingId: -1,
  44216. mappings: [],
  44217. hasShortCmap: false
  44218. };
  44219. }
  44220. var format = font.getUint16();
  44221. var length = font.getUint16();
  44222. var language = font.getUint16();
  44223. var hasShortCmap = false;
  44224. var mappings = [];
  44225. var j, glyphId;
  44226. // TODO(mack): refactor this cmap subtable reading logic out
  44227. if (format === 0) {
  44228. for (j = 0; j < 256; j++) {
  44229. var index = font.getByte();
  44230. if (!index) {
  44231. continue;
  44232. }
  44233. mappings.push({
  44234. charCode: j,
  44235. glyphId: index
  44236. });
  44237. }
  44238. hasShortCmap = true;
  44239. } else if (format === 4) {
  44240. // re-creating the table in format 4 since the encoding
  44241. // might be changed
  44242. var segCount = font.getUint16() >> 1;
  44243. font.getBytes(6);
  44244. // skipping range fields
  44245. var segIndex, segments = [];
  44246. for (segIndex = 0; segIndex < segCount; segIndex++) {
  44247. segments.push({ end: font.getUint16() });
  44248. }
  44249. font.getUint16();
  44250. for (segIndex = 0; segIndex < segCount; segIndex++) {
  44251. segments[segIndex].start = font.getUint16();
  44252. }
  44253. for (segIndex = 0; segIndex < segCount; segIndex++) {
  44254. segments[segIndex].delta = font.getUint16();
  44255. }
  44256. var offsetsCount = 0;
  44257. for (segIndex = 0; segIndex < segCount; segIndex++) {
  44258. segment = segments[segIndex];
  44259. var rangeOffset = font.getUint16();
  44260. if (!rangeOffset) {
  44261. segment.offsetIndex = -1;
  44262. continue;
  44263. }
  44264. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  44265. segment.offsetIndex = offsetIndex;
  44266. offsetsCount = Math.max(offsetsCount, offsetIndex + segment.end - segment.start + 1);
  44267. }
  44268. var offsets = [];
  44269. for (j = 0; j < offsetsCount; j++) {
  44270. offsets.push(font.getUint16());
  44271. }
  44272. for (segIndex = 0; segIndex < segCount; segIndex++) {
  44273. segment = segments[segIndex];
  44274. start = segment.start;
  44275. var end = segment.end;
  44276. var delta = segment.delta;
  44277. offsetIndex = segment.offsetIndex;
  44278. for (j = start; j <= end; j++) {
  44279. if (j === 0xFFFF) {
  44280. continue;
  44281. }
  44282. glyphId = offsetIndex < 0 ? j : offsets[offsetIndex + j - start];
  44283. glyphId = glyphId + delta & 0xFFFF;
  44284. if (glyphId === 0) {
  44285. continue;
  44286. }
  44287. mappings.push({
  44288. charCode: j,
  44289. glyphId: glyphId
  44290. });
  44291. }
  44292. }
  44293. } else if (format === 6) {
  44294. // Format 6 is a 2-bytes dense mapping, which means the font data
  44295. // lives glue together even if they are pretty far in the unicode
  44296. // table. (This looks weird, so I can have missed something), this
  44297. // works on Linux but seems to fails on Mac so let's rewrite the
  44298. // cmap table to a 3-1-4 style
  44299. var firstCode = font.getUint16();
  44300. var entryCount = font.getUint16();
  44301. for (j = 0; j < entryCount; j++) {
  44302. glyphId = font.getUint16();
  44303. var charCode = firstCode + j;
  44304. mappings.push({
  44305. charCode: charCode,
  44306. glyphId: glyphId
  44307. });
  44308. }
  44309. } else {
  44310. warn('cmap table has unsupported format: ' + format);
  44311. return {
  44312. platformId: -1,
  44313. encodingId: -1,
  44314. mappings: [],
  44315. hasShortCmap: false
  44316. };
  44317. }
  44318. // removing duplicate entries
  44319. mappings.sort(function (a, b) {
  44320. return a.charCode - b.charCode;
  44321. });
  44322. for (i = 1; i < mappings.length; i++) {
  44323. if (mappings[i - 1].charCode === mappings[i].charCode) {
  44324. mappings.splice(i, 1);
  44325. i--;
  44326. }
  44327. }
  44328. return {
  44329. platformId: potentialTable.platformId,
  44330. encodingId: potentialTable.encodingId,
  44331. mappings: mappings,
  44332. hasShortCmap: hasShortCmap
  44333. };
  44334. }
  44335. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  44336. if (!header) {
  44337. if (metrics) {
  44338. metrics.data = null;
  44339. }
  44340. return;
  44341. }
  44342. font.pos = (font.start ? font.start : 0) + header.offset;
  44343. font.pos += header.length - 2;
  44344. var numOfMetrics = font.getUint16();
  44345. if (numOfMetrics > numGlyphs) {
  44346. info('The numOfMetrics (' + numOfMetrics + ') should not be ' + 'greater than the numGlyphs (' + numGlyphs + ')');
  44347. // Reduce numOfMetrics if it is greater than numGlyphs
  44348. numOfMetrics = numGlyphs;
  44349. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  44350. header.data[35] = numOfMetrics & 0x00ff;
  44351. }
  44352. var numOfSidebearings = numGlyphs - numOfMetrics;
  44353. var numMissing = numOfSidebearings - (metrics.length - numOfMetrics * 4 >> 1);
  44354. if (numMissing > 0) {
  44355. // For each missing glyph, we set both the width and lsb to 0 (zero).
  44356. // Since we need to add two properties for each glyph, this explains
  44357. // the use of |numMissing * 2| when initializing the typed array.
  44358. var entries = new Uint8Array(metrics.length + numMissing * 2);
  44359. entries.set(metrics.data);
  44360. metrics.data = entries;
  44361. }
  44362. }
  44363. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart, hintsValid) {
  44364. if (sourceEnd - sourceStart <= 12) {
  44365. // glyph with data less than 12 is invalid one
  44366. return 0;
  44367. }
  44368. var glyf = source.subarray(sourceStart, sourceEnd);
  44369. var contoursCount = glyf[0] << 8 | glyf[1];
  44370. if (contoursCount & 0x8000) {
  44371. // complex glyph, writing as is
  44372. dest.set(glyf, destStart);
  44373. return glyf.length;
  44374. }
  44375. var i, j = 10, flagsCount = 0;
  44376. for (i = 0; i < contoursCount; i++) {
  44377. var endPoint = glyf[j] << 8 | glyf[j + 1];
  44378. flagsCount = endPoint + 1;
  44379. j += 2;
  44380. }
  44381. // skipping instructions
  44382. var instructionsStart = j;
  44383. var instructionsLength = glyf[j] << 8 | glyf[j + 1];
  44384. j += 2 + instructionsLength;
  44385. var instructionsEnd = j;
  44386. // validating flags
  44387. var coordinatesLength = 0;
  44388. for (i = 0; i < flagsCount; i++) {
  44389. var flag = glyf[j++];
  44390. if (flag & 0xC0) {
  44391. // reserved flags must be zero, cleaning up
  44392. glyf[j - 1] = flag & 0x3F;
  44393. }
  44394. var xyLength = (flag & 2 ? 1 : flag & 16 ? 0 : 2) + (flag & 4 ? 1 : flag & 32 ? 0 : 2);
  44395. coordinatesLength += xyLength;
  44396. if (flag & 8) {
  44397. var repeat = glyf[j++];
  44398. i += repeat;
  44399. coordinatesLength += repeat * xyLength;
  44400. }
  44401. }
  44402. // glyph without coordinates will be rejected
  44403. if (coordinatesLength === 0) {
  44404. return 0;
  44405. }
  44406. var glyphDataLength = j + coordinatesLength;
  44407. if (glyphDataLength > glyf.length) {
  44408. // not enough data for coordinates
  44409. return 0;
  44410. }
  44411. if (!hintsValid && instructionsLength > 0) {
  44412. dest.set(glyf.subarray(0, instructionsStart), destStart);
  44413. dest.set([
  44414. 0,
  44415. 0
  44416. ], destStart + instructionsStart);
  44417. dest.set(glyf.subarray(instructionsEnd, glyphDataLength), destStart + instructionsStart + 2);
  44418. glyphDataLength -= instructionsLength;
  44419. if (glyf.length - glyphDataLength > 3) {
  44420. glyphDataLength = glyphDataLength + 3 & ~3;
  44421. }
  44422. return glyphDataLength;
  44423. }
  44424. if (glyf.length - glyphDataLength > 3) {
  44425. // truncating and aligning to 4 bytes the long glyph data
  44426. glyphDataLength = glyphDataLength + 3 & ~3;
  44427. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  44428. return glyphDataLength;
  44429. }
  44430. // glyph data is fine
  44431. dest.set(glyf, destStart);
  44432. return glyf.length;
  44433. }
  44434. function sanitizeHead(head, numGlyphs, locaLength) {
  44435. var data = head.data;
  44436. // Validate version:
  44437. // Should always be 0x00010000
  44438. var version = int32(data[0], data[1], data[2], data[3]);
  44439. if (version >> 16 !== 1) {
  44440. info('Attempting to fix invalid version in head table: ' + version);
  44441. data[0] = 0;
  44442. data[1] = 1;
  44443. data[2] = 0;
  44444. data[3] = 0;
  44445. }
  44446. var indexToLocFormat = int16(data[50], data[51]);
  44447. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  44448. info('Attempting to fix invalid indexToLocFormat in head table: ' + indexToLocFormat);
  44449. // The value of indexToLocFormat should be 0 if the loca table
  44450. // consists of short offsets, and should be 1 if the loca table
  44451. // consists of long offsets.
  44452. //
  44453. // The number of entries in the loca table should be numGlyphs + 1.
  44454. //
  44455. // Using this information, we can work backwards to deduce if the
  44456. // size of each offset in the loca table, and thus figure out the
  44457. // appropriate value for indexToLocFormat.
  44458. var numGlyphsPlusOne = numGlyphs + 1;
  44459. if (locaLength === numGlyphsPlusOne << 1) {
  44460. // 0x0000 indicates the loca table consists of short offsets
  44461. data[50] = 0;
  44462. data[51] = 0;
  44463. } else if (locaLength === numGlyphsPlusOne << 2) {
  44464. // 0x0001 indicates the loca table consists of long offsets
  44465. data[50] = 0;
  44466. data[51] = 1;
  44467. } else {
  44468. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  44469. }
  44470. }
  44471. }
  44472. function sanitizeGlyphLocations(loca, glyf, numGlyphs, isGlyphLocationsLong, hintsValid, dupFirstEntry) {
  44473. var itemSize, itemDecode, itemEncode;
  44474. if (isGlyphLocationsLong) {
  44475. itemSize = 4;
  44476. itemDecode = function fontItemDecodeLong(data, offset) {
  44477. return data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3];
  44478. };
  44479. itemEncode = function fontItemEncodeLong(data, offset, value) {
  44480. data[offset] = value >>> 24 & 0xFF;
  44481. data[offset + 1] = value >> 16 & 0xFF;
  44482. data[offset + 2] = value >> 8 & 0xFF;
  44483. data[offset + 3] = value & 0xFF;
  44484. };
  44485. } else {
  44486. itemSize = 2;
  44487. itemDecode = function fontItemDecode(data, offset) {
  44488. return data[offset] << 9 | data[offset + 1] << 1;
  44489. };
  44490. itemEncode = function fontItemEncode(data, offset, value) {
  44491. data[offset] = value >> 9 & 0xFF;
  44492. data[offset + 1] = value >> 1 & 0xFF;
  44493. };
  44494. }
  44495. var locaData = loca.data;
  44496. var locaDataSize = itemSize * (1 + numGlyphs);
  44497. // is loca.data too short or long?
  44498. if (locaData.length !== locaDataSize) {
  44499. locaData = new Uint8Array(locaDataSize);
  44500. locaData.set(loca.data.subarray(0, locaDataSize));
  44501. loca.data = locaData;
  44502. }
  44503. // removing the invalid glyphs
  44504. var oldGlyfData = glyf.data;
  44505. var oldGlyfDataLength = oldGlyfData.length;
  44506. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  44507. var startOffset = itemDecode(locaData, 0);
  44508. var writeOffset = 0;
  44509. var missingGlyphData = Object.create(null);
  44510. itemEncode(locaData, 0, writeOffset);
  44511. var i, j;
  44512. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  44513. var endOffset = itemDecode(locaData, j);
  44514. if (endOffset > oldGlyfDataLength && (oldGlyfDataLength + 3 & ~3) === endOffset) {
  44515. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  44516. // the glyf table size, which makes last glyph out of range.
  44517. endOffset = oldGlyfDataLength;
  44518. }
  44519. if (endOffset > oldGlyfDataLength) {
  44520. // glyph end offset points outside glyf data, rejecting the glyph
  44521. itemEncode(locaData, j, writeOffset);
  44522. startOffset = endOffset;
  44523. continue;
  44524. }
  44525. if (startOffset === endOffset) {
  44526. missingGlyphData[i] = true;
  44527. }
  44528. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset, newGlyfData, writeOffset, hintsValid);
  44529. writeOffset += newLength;
  44530. itemEncode(locaData, j, writeOffset);
  44531. startOffset = endOffset;
  44532. }
  44533. if (writeOffset === 0) {
  44534. // glyf table cannot be empty -- redoing the glyf and loca tables
  44535. // to have single glyph with one point
  44536. var simpleGlyph = new Uint8Array([
  44537. 0,
  44538. 1,
  44539. 0,
  44540. 0,
  44541. 0,
  44542. 0,
  44543. 0,
  44544. 0,
  44545. 0,
  44546. 0,
  44547. 0,
  44548. 0,
  44549. 0,
  44550. 0,
  44551. 49,
  44552. 0
  44553. ]);
  44554. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  44555. itemEncode(locaData, j, simpleGlyph.length);
  44556. }
  44557. glyf.data = simpleGlyph;
  44558. return missingGlyphData;
  44559. }
  44560. if (dupFirstEntry) {
  44561. var firstEntryLength = itemDecode(locaData, itemSize);
  44562. if (newGlyfData.length > firstEntryLength + writeOffset) {
  44563. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  44564. } else {
  44565. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  44566. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  44567. }
  44568. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  44569. itemEncode(loca.data, locaData.length - itemSize, writeOffset + firstEntryLength);
  44570. } else {
  44571. glyf.data = newGlyfData.subarray(0, writeOffset);
  44572. }
  44573. return missingGlyphData;
  44574. }
  44575. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  44576. var start = (font.start ? font.start : 0) + post.offset;
  44577. font.pos = start;
  44578. var length = post.length, end = start + length;
  44579. var version = font.getInt32();
  44580. // skip rest to the tables
  44581. font.getBytes(28);
  44582. var glyphNames;
  44583. var valid = true;
  44584. var i;
  44585. switch (version) {
  44586. case 0x00010000:
  44587. glyphNames = MacStandardGlyphOrdering;
  44588. break;
  44589. case 0x00020000:
  44590. var numGlyphs = font.getUint16();
  44591. if (numGlyphs !== maxpNumGlyphs) {
  44592. valid = false;
  44593. break;
  44594. }
  44595. var glyphNameIndexes = [];
  44596. for (i = 0; i < numGlyphs; ++i) {
  44597. var index = font.getUint16();
  44598. if (index >= 32768) {
  44599. valid = false;
  44600. break;
  44601. }
  44602. glyphNameIndexes.push(index);
  44603. }
  44604. if (!valid) {
  44605. break;
  44606. }
  44607. var customNames = [];
  44608. var strBuf = [];
  44609. while (font.pos < end) {
  44610. var stringLength = font.getByte();
  44611. strBuf.length = stringLength;
  44612. for (i = 0; i < stringLength; ++i) {
  44613. strBuf[i] = String.fromCharCode(font.getByte());
  44614. }
  44615. customNames.push(strBuf.join(''));
  44616. }
  44617. glyphNames = [];
  44618. for (i = 0; i < numGlyphs; ++i) {
  44619. var j = glyphNameIndexes[i];
  44620. if (j < 258) {
  44621. glyphNames.push(MacStandardGlyphOrdering[j]);
  44622. continue;
  44623. }
  44624. glyphNames.push(customNames[j - 258]);
  44625. }
  44626. break;
  44627. case 0x00030000:
  44628. break;
  44629. default:
  44630. warn('Unknown/unsupported post table version ' + version);
  44631. valid = false;
  44632. if (properties.defaultEncoding) {
  44633. glyphNames = properties.defaultEncoding;
  44634. }
  44635. break;
  44636. }
  44637. properties.glyphNames = glyphNames;
  44638. return valid;
  44639. }
  44640. function readNameTable(nameTable) {
  44641. var start = (font.start ? font.start : 0) + nameTable.offset;
  44642. font.pos = start;
  44643. var names = [
  44644. [],
  44645. []
  44646. ];
  44647. var length = nameTable.length, end = start + length;
  44648. var format = font.getUint16();
  44649. var FORMAT_0_HEADER_LENGTH = 6;
  44650. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  44651. // unsupported name table format or table "too" small
  44652. return names;
  44653. }
  44654. var numRecords = font.getUint16();
  44655. var stringsStart = font.getUint16();
  44656. var records = [];
  44657. var NAME_RECORD_LENGTH = 12;
  44658. var i, ii;
  44659. for (i = 0; i < numRecords && font.pos + NAME_RECORD_LENGTH <= end; i++) {
  44660. var r = {
  44661. platform: font.getUint16(),
  44662. encoding: font.getUint16(),
  44663. language: font.getUint16(),
  44664. name: font.getUint16(),
  44665. length: font.getUint16(),
  44666. offset: font.getUint16()
  44667. };
  44668. // using only Macintosh and Windows platform/encoding names
  44669. if (r.platform === 1 && r.encoding === 0 && r.language === 0 || r.platform === 3 && r.encoding === 1 && r.language === 0x409) {
  44670. records.push(r);
  44671. }
  44672. }
  44673. for (i = 0, ii = records.length; i < ii; i++) {
  44674. var record = records[i];
  44675. if (record.length <= 0) {
  44676. continue;
  44677. }
  44678. // Nothing to process, ignoring.
  44679. var pos = start + stringsStart + record.offset;
  44680. if (pos + record.length > end) {
  44681. continue;
  44682. }
  44683. // outside of name table, ignoring
  44684. font.pos = pos;
  44685. var nameIndex = record.name;
  44686. if (record.encoding) {
  44687. // unicode
  44688. var str = '';
  44689. for (var j = 0, jj = record.length; j < jj; j += 2) {
  44690. str += String.fromCharCode(font.getUint16());
  44691. }
  44692. names[1][nameIndex] = str;
  44693. } else {
  44694. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  44695. }
  44696. }
  44697. return names;
  44698. }
  44699. var TTOpsStackDeltas = [
  44700. 0,
  44701. 0,
  44702. 0,
  44703. 0,
  44704. 0,
  44705. 0,
  44706. 0,
  44707. 0,
  44708. -2,
  44709. -2,
  44710. -2,
  44711. -2,
  44712. 0,
  44713. 0,
  44714. -2,
  44715. -5,
  44716. -1,
  44717. -1,
  44718. -1,
  44719. -1,
  44720. -1,
  44721. -1,
  44722. -1,
  44723. -1,
  44724. 0,
  44725. 0,
  44726. -1,
  44727. 0,
  44728. -1,
  44729. -1,
  44730. -1,
  44731. -1,
  44732. 1,
  44733. -1,
  44734. -999,
  44735. 0,
  44736. 1,
  44737. 0,
  44738. -1,
  44739. -2,
  44740. 0,
  44741. -1,
  44742. -2,
  44743. -1,
  44744. -1,
  44745. 0,
  44746. -1,
  44747. -1,
  44748. 0,
  44749. 0,
  44750. -999,
  44751. -999,
  44752. -1,
  44753. -1,
  44754. -1,
  44755. -1,
  44756. -2,
  44757. -999,
  44758. -2,
  44759. -2,
  44760. -999,
  44761. 0,
  44762. -2,
  44763. -2,
  44764. 0,
  44765. 0,
  44766. -2,
  44767. 0,
  44768. -2,
  44769. 0,
  44770. 0,
  44771. 0,
  44772. -2,
  44773. -1,
  44774. -1,
  44775. 1,
  44776. 1,
  44777. 0,
  44778. 0,
  44779. -1,
  44780. -1,
  44781. -1,
  44782. -1,
  44783. -1,
  44784. -1,
  44785. -1,
  44786. 0,
  44787. 0,
  44788. -1,
  44789. 0,
  44790. -1,
  44791. -1,
  44792. 0,
  44793. -999,
  44794. -1,
  44795. -1,
  44796. -1,
  44797. -1,
  44798. -1,
  44799. -1,
  44800. 0,
  44801. 0,
  44802. 0,
  44803. 0,
  44804. 0,
  44805. 0,
  44806. 0,
  44807. 0,
  44808. 0,
  44809. 0,
  44810. 0,
  44811. 0,
  44812. -2,
  44813. -999,
  44814. -999,
  44815. -999,
  44816. -999,
  44817. -999,
  44818. -1,
  44819. -1,
  44820. -2,
  44821. -2,
  44822. 0,
  44823. 0,
  44824. 0,
  44825. 0,
  44826. -1,
  44827. -1,
  44828. -999,
  44829. -2,
  44830. -2,
  44831. 0,
  44832. 0,
  44833. -1,
  44834. -2,
  44835. -2,
  44836. 0,
  44837. 0,
  44838. 0,
  44839. -1,
  44840. -1,
  44841. -1,
  44842. -2
  44843. ];
  44844. // 0xC0-DF == -1 and 0xE0-FF == -2
  44845. function sanitizeTTProgram(table, ttContext) {
  44846. var data = table.data;
  44847. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  44848. var stack = [];
  44849. var callstack = [];
  44850. var functionsCalled = [];
  44851. var tooComplexToFollowFunctions = ttContext.tooComplexToFollowFunctions;
  44852. var inFDEF = false, ifLevel = 0, inELSE = 0;
  44853. for (var ii = data.length; i < ii;) {
  44854. var op = data[i++];
  44855. // The TrueType instruction set docs can be found at
  44856. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  44857. if (op === 0x40) {
  44858. // NPUSHB - pushes n bytes
  44859. n = data[i++];
  44860. if (inFDEF || inELSE) {
  44861. i += n;
  44862. } else {
  44863. for (j = 0; j < n; j++) {
  44864. stack.push(data[i++]);
  44865. }
  44866. }
  44867. } else if (op === 0x41) {
  44868. // NPUSHW - pushes n words
  44869. n = data[i++];
  44870. if (inFDEF || inELSE) {
  44871. i += n * 2;
  44872. } else {
  44873. for (j = 0; j < n; j++) {
  44874. b = data[i++];
  44875. stack.push(b << 8 | data[i++]);
  44876. }
  44877. }
  44878. } else if ((op & 0xF8) === 0xB0) {
  44879. // PUSHB - pushes bytes
  44880. n = op - 0xB0 + 1;
  44881. if (inFDEF || inELSE) {
  44882. i += n;
  44883. } else {
  44884. for (j = 0; j < n; j++) {
  44885. stack.push(data[i++]);
  44886. }
  44887. }
  44888. } else if ((op & 0xF8) === 0xB8) {
  44889. // PUSHW - pushes words
  44890. n = op - 0xB8 + 1;
  44891. if (inFDEF || inELSE) {
  44892. i += n * 2;
  44893. } else {
  44894. for (j = 0; j < n; j++) {
  44895. b = data[i++];
  44896. stack.push(b << 8 | data[i++]);
  44897. }
  44898. }
  44899. } else if (op === 0x2B && !tooComplexToFollowFunctions) {
  44900. // CALL
  44901. if (!inFDEF && !inELSE) {
  44902. // collecting inforamtion about which functions are used
  44903. funcId = stack[stack.length - 1];
  44904. ttContext.functionsUsed[funcId] = true;
  44905. if (funcId in ttContext.functionsStackDeltas) {
  44906. stack.length += ttContext.functionsStackDeltas[funcId];
  44907. } else if (funcId in ttContext.functionsDefined && functionsCalled.indexOf(funcId) < 0) {
  44908. callstack.push({
  44909. data: data,
  44910. i: i,
  44911. stackTop: stack.length - 1
  44912. });
  44913. functionsCalled.push(funcId);
  44914. pc = ttContext.functionsDefined[funcId];
  44915. if (!pc) {
  44916. warn('TT: CALL non-existent function');
  44917. ttContext.hintsValid = false;
  44918. return;
  44919. }
  44920. data = pc.data;
  44921. i = pc.i;
  44922. }
  44923. }
  44924. } else if (op === 0x2C && !tooComplexToFollowFunctions) {
  44925. // FDEF
  44926. if (inFDEF || inELSE) {
  44927. warn('TT: nested FDEFs not allowed');
  44928. tooComplexToFollowFunctions = true;
  44929. }
  44930. inFDEF = true;
  44931. // collecting inforamtion about which functions are defined
  44932. lastDeff = i;
  44933. funcId = stack.pop();
  44934. ttContext.functionsDefined[funcId] = {
  44935. data: data,
  44936. i: i
  44937. };
  44938. } else if (op === 0x2D) {
  44939. // ENDF - end of function
  44940. if (inFDEF) {
  44941. inFDEF = false;
  44942. lastEndf = i;
  44943. } else {
  44944. pc = callstack.pop();
  44945. if (!pc) {
  44946. warn('TT: ENDF bad stack');
  44947. ttContext.hintsValid = false;
  44948. return;
  44949. }
  44950. funcId = functionsCalled.pop();
  44951. data = pc.data;
  44952. i = pc.i;
  44953. ttContext.functionsStackDeltas[funcId] = stack.length - pc.stackTop;
  44954. }
  44955. } else if (op === 0x89) {
  44956. // IDEF - instruction definition
  44957. if (inFDEF || inELSE) {
  44958. warn('TT: nested IDEFs not allowed');
  44959. tooComplexToFollowFunctions = true;
  44960. }
  44961. inFDEF = true;
  44962. // recording it as a function to track ENDF
  44963. lastDeff = i;
  44964. } else if (op === 0x58) {
  44965. // IF
  44966. ++ifLevel;
  44967. } else if (op === 0x1B) {
  44968. // ELSE
  44969. inELSE = ifLevel;
  44970. } else if (op === 0x59) {
  44971. // EIF
  44972. if (inELSE === ifLevel) {
  44973. inELSE = 0;
  44974. }
  44975. --ifLevel;
  44976. } else if (op === 0x1C) {
  44977. // JMPR
  44978. if (!inFDEF && !inELSE) {
  44979. var offset = stack[stack.length - 1];
  44980. // only jumping forward to prevent infinite loop
  44981. if (offset > 0) {
  44982. i += offset - 1;
  44983. }
  44984. }
  44985. }
  44986. // Adjusting stack not extactly, but just enough to get function id
  44987. if (!inFDEF && !inELSE) {
  44988. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] : op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  44989. if (op >= 0x71 && op <= 0x75) {
  44990. n = stack.pop();
  44991. if (n === n) {
  44992. stackDelta = -n * 2;
  44993. }
  44994. }
  44995. while (stackDelta < 0 && stack.length > 0) {
  44996. stack.pop();
  44997. stackDelta++;
  44998. }
  44999. while (stackDelta > 0) {
  45000. stack.push(NaN);
  45001. // pushing any number into stack
  45002. stackDelta--;
  45003. }
  45004. }
  45005. }
  45006. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  45007. var content = [data];
  45008. if (i > data.length) {
  45009. content.push(new Uint8Array(i - data.length));
  45010. }
  45011. if (lastDeff > lastEndf) {
  45012. warn('TT: complementing a missing function tail');
  45013. // new function definition started, but not finished
  45014. // complete function by [CLEAR, ENDF]
  45015. content.push(new Uint8Array([
  45016. 0x22,
  45017. 0x2D
  45018. ]));
  45019. }
  45020. foldTTTable(table, content);
  45021. }
  45022. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  45023. if (ttContext.tooComplexToFollowFunctions) {
  45024. return;
  45025. }
  45026. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  45027. warn('TT: more functions defined than expected');
  45028. ttContext.hintsValid = false;
  45029. return;
  45030. }
  45031. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  45032. if (j > maxFunctionDefs) {
  45033. warn('TT: invalid function id: ' + j);
  45034. ttContext.hintsValid = false;
  45035. return;
  45036. }
  45037. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  45038. warn('TT: undefined function: ' + j);
  45039. ttContext.hintsValid = false;
  45040. return;
  45041. }
  45042. }
  45043. }
  45044. function foldTTTable(table, content) {
  45045. if (content.length > 1) {
  45046. // concatenating the content items
  45047. var newLength = 0;
  45048. var j, jj;
  45049. for (j = 0, jj = content.length; j < jj; j++) {
  45050. newLength += content[j].length;
  45051. }
  45052. newLength = newLength + 3 & ~3;
  45053. var result = new Uint8Array(newLength);
  45054. var pos = 0;
  45055. for (j = 0, jj = content.length; j < jj; j++) {
  45056. result.set(content[j], pos);
  45057. pos += content[j].length;
  45058. }
  45059. table.data = result;
  45060. table.length = newLength;
  45061. }
  45062. }
  45063. function sanitizeTTPrograms(fpgm, prep, cvt, maxFunctionDefs) {
  45064. var ttContext = {
  45065. functionsDefined: [],
  45066. functionsUsed: [],
  45067. functionsStackDeltas: [],
  45068. tooComplexToFollowFunctions: false,
  45069. hintsValid: true
  45070. };
  45071. if (fpgm) {
  45072. sanitizeTTProgram(fpgm, ttContext);
  45073. }
  45074. if (prep) {
  45075. sanitizeTTProgram(prep, ttContext);
  45076. }
  45077. if (fpgm) {
  45078. checkInvalidFunctions(ttContext, maxFunctionDefs);
  45079. }
  45080. if (cvt && cvt.length & 1) {
  45081. var cvtData = new Uint8Array(cvt.length + 1);
  45082. cvtData.set(cvt.data);
  45083. cvt.data = cvtData;
  45084. }
  45085. return ttContext.hintsValid;
  45086. }
  45087. // The following steps modify the original font data, making copy
  45088. font = new Stream(new Uint8Array(font.getBytes()));
  45089. var VALID_TABLES = [
  45090. 'OS/2',
  45091. 'cmap',
  45092. 'head',
  45093. 'hhea',
  45094. 'hmtx',
  45095. 'maxp',
  45096. 'name',
  45097. 'post',
  45098. 'loca',
  45099. 'glyf',
  45100. 'fpgm',
  45101. 'prep',
  45102. 'cvt ',
  45103. 'CFF '
  45104. ];
  45105. var header = readOpenTypeHeader(font);
  45106. var numTables = header.numTables;
  45107. var cff, cffFile;
  45108. var tables = Object.create(null);
  45109. tables['OS/2'] = null;
  45110. tables['cmap'] = null;
  45111. tables['head'] = null;
  45112. tables['hhea'] = null;
  45113. tables['hmtx'] = null;
  45114. tables['maxp'] = null;
  45115. tables['name'] = null;
  45116. tables['post'] = null;
  45117. var table;
  45118. for (var i = 0; i < numTables; i++) {
  45119. table = readTableEntry(font);
  45120. if (VALID_TABLES.indexOf(table.tag) < 0) {
  45121. continue;
  45122. }
  45123. // skipping table if it's not a required or optional table
  45124. if (table.length === 0) {
  45125. continue;
  45126. }
  45127. // skipping empty tables
  45128. tables[table.tag] = table;
  45129. }
  45130. var isTrueType = !tables['CFF '];
  45131. if (!isTrueType) {
  45132. // OpenType font
  45133. if (header.version === 'OTTO' && properties.type !== 'CIDFontType2' || !tables['head'] || !tables['hhea'] || !tables['maxp'] || !tables['post']) {
  45134. // no major tables: throwing everything at CFFFont
  45135. cffFile = new Stream(tables['CFF '].data);
  45136. cff = new CFFFont(cffFile, properties);
  45137. adjustWidths(properties);
  45138. return this.convert(name, cff, properties);
  45139. }
  45140. delete tables['glyf'];
  45141. delete tables['loca'];
  45142. delete tables['fpgm'];
  45143. delete tables['prep'];
  45144. delete tables['cvt '];
  45145. this.isOpenType = true;
  45146. } else {
  45147. if (!tables['loca']) {
  45148. error('Required "loca" table is not found');
  45149. }
  45150. if (!tables['glyf']) {
  45151. warn('Required "glyf" table is not found -- trying to recover.');
  45152. // Note: We use `sanitizeGlyphLocations` to add dummy glyf data below.
  45153. tables['glyf'] = {
  45154. tag: 'glyf',
  45155. data: new Uint8Array(0)
  45156. };
  45157. }
  45158. this.isOpenType = false;
  45159. }
  45160. if (!tables['maxp']) {
  45161. error('Required "maxp" table is not found');
  45162. }
  45163. font.pos = (font.start || 0) + tables['maxp'].offset;
  45164. var version = font.getInt32();
  45165. var numGlyphs = font.getUint16();
  45166. var maxFunctionDefs = 0;
  45167. if (version >= 0x00010000 && tables['maxp'].length >= 22) {
  45168. // maxZones can be invalid
  45169. font.pos += 8;
  45170. var maxZones = font.getUint16();
  45171. if (maxZones > 2) {
  45172. // reset to 2 if font has invalid maxZones
  45173. tables['maxp'].data[14] = 0;
  45174. tables['maxp'].data[15] = 2;
  45175. }
  45176. font.pos += 4;
  45177. maxFunctionDefs = font.getUint16();
  45178. }
  45179. var dupFirstEntry = false;
  45180. if (properties.type === 'CIDFontType2' && properties.toUnicode && properties.toUnicode.get(0) > '\u0000') {
  45181. // oracle's defect (see 3427), duplicating first entry
  45182. dupFirstEntry = true;
  45183. numGlyphs++;
  45184. tables['maxp'].data[4] = numGlyphs >> 8;
  45185. tables['maxp'].data[5] = numGlyphs & 255;
  45186. }
  45187. var hintsValid = sanitizeTTPrograms(tables['fpgm'], tables['prep'], tables['cvt '], maxFunctionDefs);
  45188. if (!hintsValid) {
  45189. delete tables['fpgm'];
  45190. delete tables['prep'];
  45191. delete tables['cvt '];
  45192. }
  45193. // Ensure the hmtx table contains the advance width and
  45194. // sidebearings information for numGlyphs in the maxp table
  45195. sanitizeMetrics(font, tables['hhea'], tables['hmtx'], numGlyphs);
  45196. if (!tables['head']) {
  45197. error('Required "head" table is not found');
  45198. }
  45199. sanitizeHead(tables['head'], numGlyphs, isTrueType ? tables['loca'].length : 0);
  45200. var missingGlyphs = Object.create(null);
  45201. if (isTrueType) {
  45202. var isGlyphLocationsLong = int16(tables['head'].data[50], tables['head'].data[51]);
  45203. missingGlyphs = sanitizeGlyphLocations(tables['loca'], tables['glyf'], numGlyphs, isGlyphLocationsLong, hintsValid, dupFirstEntry);
  45204. }
  45205. if (!tables['hhea']) {
  45206. error('Required "hhea" table is not found');
  45207. }
  45208. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  45209. // Sometimes it's 0. That needs to be fixed
  45210. if (tables['hhea'].data[10] === 0 && tables['hhea'].data[11] === 0) {
  45211. tables['hhea'].data[10] = 0xFF;
  45212. tables['hhea'].data[11] = 0xFF;
  45213. }
  45214. // Extract some more font properties from the OpenType head and
  45215. // hhea tables; yMin and descent value are always negative.
  45216. var metricsOverride = {
  45217. unitsPerEm: int16(tables['head'].data[18], tables['head'].data[19]),
  45218. yMax: int16(tables['head'].data[42], tables['head'].data[43]),
  45219. yMin: signedInt16(tables['head'].data[38], tables['head'].data[39]),
  45220. ascent: int16(tables['hhea'].data[4], tables['hhea'].data[5]),
  45221. descent: signedInt16(tables['hhea'].data[6], tables['hhea'].data[7])
  45222. };
  45223. // PDF FontDescriptor metrics lie -- using data from actual font.
  45224. this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
  45225. this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
  45226. // The 'post' table has glyphs names.
  45227. if (tables['post']) {
  45228. var valid = readPostScriptTable(tables['post'], properties, numGlyphs);
  45229. if (!valid) {
  45230. tables['post'] = null;
  45231. }
  45232. }
  45233. var charCodeToGlyphId = [], charCode;
  45234. var toUnicode = properties.toUnicode, widths = properties.widths;
  45235. var skipToUnicode = toUnicode instanceof IdentityToUnicodeMap || toUnicode.length === 0x10000;
  45236. // Helper function to try to skip mapping of empty glyphs.
  45237. // Note: In some cases, just relying on the glyph data doesn't work,
  45238. // hence we also use a few heuristics to fix various PDF files.
  45239. function hasGlyph(glyphId, charCode, widthCode) {
  45240. if (!missingGlyphs[glyphId]) {
  45241. return true;
  45242. }
  45243. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  45244. return true;
  45245. }
  45246. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  45247. return true;
  45248. }
  45249. return false;
  45250. }
  45251. if (properties.type === 'CIDFontType2') {
  45252. var cidToGidMap = properties.cidToGidMap || [];
  45253. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  45254. properties.cMap.forEach(function (charCode, cid) {
  45255. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  45256. var glyphId = -1;
  45257. if (isCidToGidMapEmpty) {
  45258. glyphId = cid;
  45259. } else if (cidToGidMap[cid] !== undefined) {
  45260. glyphId = cidToGidMap[cid];
  45261. }
  45262. if (glyphId >= 0 && glyphId < numGlyphs && hasGlyph(glyphId, charCode, cid)) {
  45263. charCodeToGlyphId[charCode] = glyphId;
  45264. }
  45265. });
  45266. if (dupFirstEntry && (isCidToGidMapEmpty || !charCodeToGlyphId[0])) {
  45267. // We don't duplicate the first entry in the `charCodeToGlyphId` map
  45268. // if the font has a `CIDToGIDMap` which has already mapped the first
  45269. // entry to a non-zero `glyphId` (fixes issue7544.pdf).
  45270. charCodeToGlyphId[0] = numGlyphs - 1;
  45271. }
  45272. } else {
  45273. // Most of the following logic in this code branch is based on the
  45274. // 9.6.6.4 of the PDF spec.
  45275. var cmapTable = readCmapTable(tables['cmap'], font, this.isSymbolicFont, properties.hasEncoding);
  45276. var cmapPlatformId = cmapTable.platformId;
  45277. var cmapEncodingId = cmapTable.encodingId;
  45278. var cmapMappings = cmapTable.mappings;
  45279. var cmapMappingsLength = cmapMappings.length;
  45280. // The spec seems to imply that if the font is symbolic the encoding
  45281. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  45282. // where the the font is symbolic and it has an encoding.
  45283. if (properties.hasEncoding && (cmapPlatformId === 3 && cmapEncodingId === 1 || cmapPlatformId === 1 && cmapEncodingId === 0) || cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  45284. !!getEncoding(properties.baseEncodingName)) {
  45285. // Temporary hack
  45286. // When no preferred cmap table was found and |baseEncodingName| is
  45287. // one of the predefined encodings, we seem to obtain a better
  45288. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  45289. // TODO: Note that this is a hack which should be removed as soon as
  45290. // we have proper support for more exotic cmap tables.
  45291. var baseEncoding = [];
  45292. if (properties.baseEncodingName === 'MacRomanEncoding' || properties.baseEncodingName === 'WinAnsiEncoding') {
  45293. baseEncoding = getEncoding(properties.baseEncodingName);
  45294. }
  45295. var glyphsUnicodeMap = getGlyphsUnicode();
  45296. for (charCode = 0; charCode < 256; charCode++) {
  45297. var glyphName, standardGlyphName;
  45298. if (this.differences && charCode in this.differences) {
  45299. glyphName = this.differences[charCode];
  45300. } else if (charCode in baseEncoding && baseEncoding[charCode] !== '') {
  45301. glyphName = baseEncoding[charCode];
  45302. } else {
  45303. glyphName = StandardEncoding[charCode];
  45304. }
  45305. if (!glyphName) {
  45306. continue;
  45307. }
  45308. // Ensure that non-standard glyph names are resolved to valid ones.
  45309. standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
  45310. var unicodeOrCharCode, isUnicode = false;
  45311. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  45312. unicodeOrCharCode = glyphsUnicodeMap[standardGlyphName];
  45313. isUnicode = true;
  45314. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  45315. // TODO: the encoding needs to be updated with mac os table.
  45316. unicodeOrCharCode = MacRomanEncoding.indexOf(standardGlyphName);
  45317. }
  45318. var found = false;
  45319. for (i = 0; i < cmapMappingsLength; ++i) {
  45320. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  45321. continue;
  45322. }
  45323. var code = isUnicode ? charCode : unicodeOrCharCode;
  45324. if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
  45325. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  45326. found = true;
  45327. break;
  45328. }
  45329. }
  45330. if (!found && properties.glyphNames) {
  45331. // Try to map using the post table.
  45332. var glyphId = properties.glyphNames.indexOf(glyphName);
  45333. // The post table ought to use the same kind of glyph names as the
  45334. // `differences` array, but check the standard ones as a fallback.
  45335. if (glyphId === -1 && standardGlyphName !== glyphName) {
  45336. glyphId = properties.glyphNames.indexOf(standardGlyphName);
  45337. }
  45338. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  45339. charCodeToGlyphId[charCode] = glyphId;
  45340. found = true;
  45341. }
  45342. }
  45343. if (!found) {
  45344. charCodeToGlyphId[charCode] = 0;
  45345. }
  45346. }
  45347. } else // notdef
  45348. if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  45349. // Default Unicode semantics, use the charcodes as is.
  45350. for (i = 0; i < cmapMappingsLength; ++i) {
  45351. charCodeToGlyphId[cmapMappings[i].charCode] = cmapMappings[i].glyphId;
  45352. }
  45353. } else {
  45354. // For (3, 0) cmap tables:
  45355. // The charcode key being stored in charCodeToGlyphId is the lower
  45356. // byte of the two-byte charcodes of the cmap table since according to
  45357. // the spec: 'each byte from the string shall be prepended with the
  45358. // high byte of the range [of charcodes in the cmap table], to form
  45359. // a two-byte character, which shall be used to select the
  45360. // associated glyph description from the subtable'.
  45361. //
  45362. // For (1, 0) cmap tables:
  45363. // 'single bytes from the string shall be used to look up the
  45364. // associated glyph descriptions from the subtable'. This means
  45365. // charcodes in the cmap will be single bytes, so no-op since
  45366. // glyph.charCode & 0xFF === glyph.charCode
  45367. for (i = 0; i < cmapMappingsLength; ++i) {
  45368. charCode = cmapMappings[i].charCode & 0xFF;
  45369. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  45370. }
  45371. }
  45372. }
  45373. if (charCodeToGlyphId.length === 0) {
  45374. // defines at least one glyph
  45375. charCodeToGlyphId[0] = 0;
  45376. }
  45377. // Converting glyphs and ids into font's cmap table
  45378. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  45379. this.toFontChar = newMapping.toFontChar;
  45380. tables['cmap'] = {
  45381. tag: 'cmap',
  45382. data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphs)
  45383. };
  45384. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  45385. tables['OS/2'] = {
  45386. tag: 'OS/2',
  45387. data: createOS2Table(properties, newMapping.charCodeToGlyphId, metricsOverride)
  45388. };
  45389. }
  45390. // Rewrite the 'post' table if needed
  45391. if (!tables['post']) {
  45392. tables['post'] = {
  45393. tag: 'post',
  45394. data: createPostTable(properties)
  45395. };
  45396. }
  45397. if (!isTrueType) {
  45398. try {
  45399. // Trying to repair CFF file
  45400. cffFile = new Stream(tables['CFF '].data);
  45401. var parser = new CFFParser(cffFile, properties, SEAC_ANALYSIS_ENABLED);
  45402. cff = parser.parse();
  45403. var compiler = new CFFCompiler(cff);
  45404. tables['CFF '].data = compiler.compile();
  45405. } catch (e) {
  45406. warn('Failed to compile font ' + properties.loadedName);
  45407. }
  45408. }
  45409. // Re-creating 'name' table
  45410. if (!tables['name']) {
  45411. tables['name'] = {
  45412. tag: 'name',
  45413. data: createNameTable(this.name)
  45414. };
  45415. } else {
  45416. // ... using existing 'name' table as prototype
  45417. var namePrototype = readNameTable(tables['name']);
  45418. tables['name'].data = createNameTable(name, namePrototype);
  45419. }
  45420. var builder = new OpenTypeFileBuilder(header.version);
  45421. for (var tableTag in tables) {
  45422. builder.addTable(tableTag, tables[tableTag].data);
  45423. }
  45424. return builder.toArray();
  45425. },
  45426. convert: function Font_convert(fontName, font, properties) {
  45427. // TODO: Check the charstring widths to determine this.
  45428. properties.fixedPitch = false;
  45429. if (properties.builtInEncoding) {
  45430. // For Type1 fonts that do not include either `ToUnicode` or `Encoding`
  45431. // data, attempt to use the `builtInEncoding` to improve text selection.
  45432. adjustToUnicode(properties, properties.builtInEncoding);
  45433. }
  45434. var mapping = font.getGlyphMapping(properties);
  45435. var newMapping = adjustMapping(mapping, properties);
  45436. this.toFontChar = newMapping.toFontChar;
  45437. var numGlyphs = font.numGlyphs;
  45438. function getCharCodes(charCodeToGlyphId, glyphId) {
  45439. var charCodes = null;
  45440. for (var charCode in charCodeToGlyphId) {
  45441. if (glyphId === charCodeToGlyphId[charCode]) {
  45442. if (!charCodes) {
  45443. charCodes = [];
  45444. }
  45445. charCodes.push(charCode | 0);
  45446. }
  45447. }
  45448. return charCodes;
  45449. }
  45450. function createCharCode(charCodeToGlyphId, glyphId) {
  45451. for (var charCode in charCodeToGlyphId) {
  45452. if (glyphId === charCodeToGlyphId[charCode]) {
  45453. return charCode | 0;
  45454. }
  45455. }
  45456. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] = glyphId;
  45457. return newMapping.nextAvailableFontCharCode++;
  45458. }
  45459. var seacs = font.seacs;
  45460. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  45461. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  45462. var charset = font.getCharset();
  45463. var seacMap = Object.create(null);
  45464. for (var glyphId in seacs) {
  45465. glyphId |= 0;
  45466. var seac = seacs[glyphId];
  45467. var baseGlyphName = StandardEncoding[seac[2]];
  45468. var accentGlyphName = StandardEncoding[seac[3]];
  45469. var baseGlyphId = charset.indexOf(baseGlyphName);
  45470. var accentGlyphId = charset.indexOf(accentGlyphName);
  45471. if (baseGlyphId < 0 || accentGlyphId < 0) {
  45472. continue;
  45473. }
  45474. var accentOffset = {
  45475. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  45476. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  45477. };
  45478. var charCodes = getCharCodes(mapping, glyphId);
  45479. if (!charCodes) {
  45480. // There's no point in mapping it if the char code was never mapped
  45481. // to begin with.
  45482. continue;
  45483. }
  45484. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  45485. var charCode = charCodes[i];
  45486. // Find a fontCharCode that maps to the base and accent glyphs.
  45487. // If one doesn't exists, create it.
  45488. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  45489. var baseFontCharCode = createCharCode(charCodeToGlyphId, baseGlyphId);
  45490. var accentFontCharCode = createCharCode(charCodeToGlyphId, accentGlyphId);
  45491. seacMap[charCode] = {
  45492. baseFontCharCode: baseFontCharCode,
  45493. accentFontCharCode: accentFontCharCode,
  45494. accentOffset: accentOffset
  45495. };
  45496. }
  45497. }
  45498. properties.seacMap = seacMap;
  45499. }
  45500. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  45501. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  45502. // PostScript Font Program
  45503. builder.addTable('CFF ', font.data);
  45504. // OS/2 and Windows Specific metrics
  45505. builder.addTable('OS/2', createOS2Table(properties, newMapping.charCodeToGlyphId));
  45506. // Character to glyphs mapping
  45507. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId, numGlyphs));
  45508. // Font header
  45509. builder.addTable('head', '\x00\x01\x00\x00' + // Version number
  45510. '\x00\x00\x10\x00' + // fontRevision
  45511. '\x00\x00\x00\x00' + // checksumAdjustement
  45512. '\x5F\x0F\x3C\xF5' + // magicNumber
  45513. '\x00\x00' + // Flags
  45514. safeString16(unitsPerEm) + // unitsPerEM
  45515. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  45516. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  45517. '\x00\x00' + // xMin
  45518. safeString16(properties.descent) + // yMin
  45519. '\x0F\xFF' + // xMax
  45520. safeString16(properties.ascent) + // yMax
  45521. string16(properties.italicAngle ? 2 : 0) + // macStyle
  45522. '\x00\x11' + // lowestRecPPEM
  45523. '\x00\x00' + // fontDirectionHint
  45524. '\x00\x00' + // indexToLocFormat
  45525. '\x00\x00');
  45526. // glyphDataFormat
  45527. // Horizontal header
  45528. builder.addTable('hhea', '\x00\x01\x00\x00' + // Version number
  45529. safeString16(properties.ascent) + // Typographic Ascent
  45530. safeString16(properties.descent) + // Typographic Descent
  45531. '\x00\x00' + // Line Gap
  45532. '\xFF\xFF' + // advanceWidthMax
  45533. '\x00\x00' + // minLeftSidebearing
  45534. '\x00\x00' + // minRightSidebearing
  45535. '\x00\x00' + // xMaxExtent
  45536. safeString16(properties.capHeight) + // caretSlopeRise
  45537. safeString16(Math.tan(properties.italicAngle) * properties.xHeight) + // caretSlopeRun
  45538. '\x00\x00' + // caretOffset
  45539. '\x00\x00' + // -reserved-
  45540. '\x00\x00' + // -reserved-
  45541. '\x00\x00' + // -reserved-
  45542. '\x00\x00' + // -reserved-
  45543. '\x00\x00' + // metricDataFormat
  45544. string16(numGlyphs));
  45545. // Number of HMetrics
  45546. // Horizontal metrics
  45547. builder.addTable('hmtx', function fontFieldsHmtx() {
  45548. var charstrings = font.charstrings;
  45549. var cffWidths = font.cff ? font.cff.widths : null;
  45550. var hmtx = '\x00\x00\x00\x00';
  45551. // Fake .notdef
  45552. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  45553. var width = 0;
  45554. if (charstrings) {
  45555. var charstring = charstrings[i - 1];
  45556. width = 'width' in charstring ? charstring.width : 0;
  45557. } else if (cffWidths) {
  45558. width = Math.ceil(cffWidths[i] || 0);
  45559. }
  45560. hmtx += string16(width) + string16(0);
  45561. }
  45562. return hmtx;
  45563. }());
  45564. // Maximum profile
  45565. builder.addTable('maxp', '\x00\x00\x50\x00' + // Version number
  45566. string16(numGlyphs));
  45567. // Num of glyphs
  45568. // Naming tables
  45569. builder.addTable('name', createNameTable(fontName));
  45570. // PostScript information
  45571. builder.addTable('post', createPostTable(properties));
  45572. return builder.toArray();
  45573. },
  45574. get spaceWidth() {
  45575. if ('_shadowWidth' in this) {
  45576. return this._shadowWidth;
  45577. }
  45578. // trying to estimate space character width
  45579. var possibleSpaceReplacements = [
  45580. 'space',
  45581. 'minus',
  45582. 'one',
  45583. 'i',
  45584. 'I'
  45585. ];
  45586. var width;
  45587. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  45588. var glyphName = possibleSpaceReplacements[i];
  45589. // if possible, getting width by glyph name
  45590. if (glyphName in this.widths) {
  45591. width = this.widths[glyphName];
  45592. break;
  45593. }
  45594. var glyphsUnicodeMap = getGlyphsUnicode();
  45595. var glyphUnicode = glyphsUnicodeMap[glyphName];
  45596. // finding the charcode via unicodeToCID map
  45597. var charcode = 0;
  45598. if (this.composite) {
  45599. if (this.cMap.contains(glyphUnicode)) {
  45600. charcode = this.cMap.lookup(glyphUnicode);
  45601. }
  45602. }
  45603. // ... via toUnicode map
  45604. if (!charcode && this.toUnicode) {
  45605. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  45606. }
  45607. // setting it to unicode if negative or undefined
  45608. if (charcode <= 0) {
  45609. charcode = glyphUnicode;
  45610. }
  45611. // trying to get width via charcode
  45612. width = this.widths[charcode];
  45613. if (width) {
  45614. break;
  45615. }
  45616. }
  45617. // the non-zero width found
  45618. width = width || this.defaultWidth;
  45619. // Do not shadow the property here. See discussion:
  45620. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  45621. this._shadowWidth = width;
  45622. return width;
  45623. },
  45624. charToGlyph: function Font_charToGlyph(charcode, isSpace) {
  45625. var fontCharCode, width, operatorListId;
  45626. var widthCode = charcode;
  45627. if (this.cMap && this.cMap.contains(charcode)) {
  45628. widthCode = this.cMap.lookup(charcode);
  45629. }
  45630. width = this.widths[widthCode];
  45631. width = isNum(width) ? width : this.defaultWidth;
  45632. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  45633. var unicode = this.toUnicode.get(charcode) || charcode;
  45634. if (typeof unicode === 'number') {
  45635. unicode = String.fromCharCode(unicode);
  45636. }
  45637. var isInFont = charcode in this.toFontChar;
  45638. // First try the toFontChar map, if it's not there then try falling
  45639. // back to the char code.
  45640. fontCharCode = this.toFontChar[charcode] || charcode;
  45641. if (this.missingFile) {
  45642. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  45643. }
  45644. if (this.isType3Font) {
  45645. // Font char code in this case is actually a glyph name.
  45646. operatorListId = fontCharCode;
  45647. }
  45648. var accent = null;
  45649. if (this.seacMap && this.seacMap[charcode]) {
  45650. isInFont = true;
  45651. var seac = this.seacMap[charcode];
  45652. fontCharCode = seac.baseFontCharCode;
  45653. accent = {
  45654. fontChar: String.fromCharCode(seac.accentFontCharCode),
  45655. offset: seac.accentOffset
  45656. };
  45657. }
  45658. var fontChar = String.fromCharCode(fontCharCode);
  45659. var glyph = this.glyphCache[charcode];
  45660. if (!glyph || !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont)) {
  45661. glyph = new Glyph(fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont);
  45662. this.glyphCache[charcode] = glyph;
  45663. }
  45664. return glyph;
  45665. },
  45666. charsToGlyphs: function Font_charsToGlyphs(chars) {
  45667. var charsCache = this.charsCache;
  45668. var glyphs, glyph, charcode;
  45669. // if we translated this string before, just grab it from the cache
  45670. if (charsCache) {
  45671. glyphs = charsCache[chars];
  45672. if (glyphs) {
  45673. return glyphs;
  45674. }
  45675. }
  45676. // lazily create the translation cache
  45677. if (!charsCache) {
  45678. charsCache = this.charsCache = Object.create(null);
  45679. }
  45680. glyphs = [];
  45681. var charsCacheKey = chars;
  45682. var i = 0, ii;
  45683. if (this.cMap) {
  45684. // composite fonts have multi-byte strings convert the string from
  45685. // single-byte to multi-byte
  45686. var c = Object.create(null);
  45687. while (i < chars.length) {
  45688. this.cMap.readCharCode(chars, i, c);
  45689. charcode = c.charcode;
  45690. var length = c.length;
  45691. i += length;
  45692. // Space is char with code 0x20 and length 1 in multiple-byte codes.
  45693. var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
  45694. glyph = this.charToGlyph(charcode, isSpace);
  45695. glyphs.push(glyph);
  45696. }
  45697. } else {
  45698. for (i = 0, ii = chars.length; i < ii; ++i) {
  45699. charcode = chars.charCodeAt(i);
  45700. glyph = this.charToGlyph(charcode, charcode === 0x20);
  45701. glyphs.push(glyph);
  45702. }
  45703. }
  45704. // Enter the translated string into the cache
  45705. return charsCache[charsCacheKey] = glyphs;
  45706. }
  45707. };
  45708. return Font;
  45709. }();
  45710. var ErrorFont = function ErrorFontClosure() {
  45711. function ErrorFont(error) {
  45712. this.error = error;
  45713. this.loadedName = 'g_font_error';
  45714. this.loading = false;
  45715. }
  45716. ErrorFont.prototype = {
  45717. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  45718. return [];
  45719. },
  45720. exportData: function ErrorFont_exportData() {
  45721. return { error: this.error };
  45722. }
  45723. };
  45724. return ErrorFont;
  45725. }();
  45726. /**
  45727. * Shared logic for building a char code to glyph id mapping for Type1 and
  45728. * simple CFF fonts. See section 9.6.6.2 of the spec.
  45729. * @param {Object} properties Font properties object.
  45730. * @param {Object} builtInEncoding The encoding contained within the actual font
  45731. * data.
  45732. * @param {Array} glyphNames Array of glyph names where the index is the
  45733. * glyph ID.
  45734. * @returns {Object} A char code to glyph ID map.
  45735. */
  45736. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  45737. var charCodeToGlyphId = Object.create(null);
  45738. var glyphId, charCode, baseEncoding;
  45739. if (properties.baseEncodingName) {
  45740. // If a valid base encoding name was used, the mapping is initialized with
  45741. // that.
  45742. baseEncoding = getEncoding(properties.baseEncodingName);
  45743. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  45744. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  45745. if (glyphId >= 0) {
  45746. charCodeToGlyphId[charCode] = glyphId;
  45747. } else {
  45748. charCodeToGlyphId[charCode] = 0;
  45749. }
  45750. }
  45751. } else // notdef
  45752. if (!!(properties.flags & FontFlags.Symbolic)) {
  45753. // For a symbolic font the encoding should be the fonts built-in
  45754. // encoding.
  45755. for (charCode in builtInEncoding) {
  45756. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  45757. }
  45758. } else {
  45759. // For non-symbolic fonts that don't have a base encoding the standard
  45760. // encoding should be used.
  45761. baseEncoding = StandardEncoding;
  45762. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  45763. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  45764. if (glyphId >= 0) {
  45765. charCodeToGlyphId[charCode] = glyphId;
  45766. } else {
  45767. charCodeToGlyphId[charCode] = 0;
  45768. }
  45769. }
  45770. }
  45771. // notdef
  45772. // Lastly, merge in the differences.
  45773. var differences = properties.differences, glyphsUnicodeMap;
  45774. if (differences) {
  45775. for (charCode in differences) {
  45776. var glyphName = differences[charCode];
  45777. glyphId = glyphNames.indexOf(glyphName);
  45778. if (glyphId === -1) {
  45779. if (!glyphsUnicodeMap) {
  45780. glyphsUnicodeMap = getGlyphsUnicode();
  45781. }
  45782. var standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
  45783. if (standardGlyphName !== glyphName) {
  45784. glyphId = glyphNames.indexOf(standardGlyphName);
  45785. }
  45786. }
  45787. if (glyphId >= 0) {
  45788. charCodeToGlyphId[charCode] = glyphId;
  45789. } else {
  45790. charCodeToGlyphId[charCode] = 0;
  45791. }
  45792. }
  45793. }
  45794. // notdef
  45795. return charCodeToGlyphId;
  45796. }
  45797. // Type1Font is also a CIDFontType0.
  45798. var Type1Font = function Type1FontClosure() {
  45799. function findBlock(streamBytes, signature, startIndex) {
  45800. var streamBytesLength = streamBytes.length;
  45801. var signatureLength = signature.length;
  45802. var scanLength = streamBytesLength - signatureLength;
  45803. var i = startIndex, j, found = false;
  45804. while (i < scanLength) {
  45805. j = 0;
  45806. while (j < signatureLength && streamBytes[i + j] === signature[j]) {
  45807. j++;
  45808. }
  45809. if (j >= signatureLength) {
  45810. // `signature` found, skip over whitespace.
  45811. i += j;
  45812. while (i < streamBytesLength && isSpace(streamBytes[i])) {
  45813. i++;
  45814. }
  45815. found = true;
  45816. break;
  45817. }
  45818. i++;
  45819. }
  45820. return {
  45821. found: found,
  45822. length: i
  45823. };
  45824. }
  45825. function getHeaderBlock(stream, suggestedLength) {
  45826. var EEXEC_SIGNATURE = [
  45827. 0x65,
  45828. 0x65,
  45829. 0x78,
  45830. 0x65,
  45831. 0x63
  45832. ];
  45833. var streamStartPos = stream.pos;
  45834. // Save the initial stream position.
  45835. var headerBytes, headerBytesLength, block;
  45836. try {
  45837. headerBytes = stream.getBytes(suggestedLength);
  45838. headerBytesLength = headerBytes.length;
  45839. } catch (ex) {
  45840. if (ex instanceof MissingDataException) {
  45841. throw ex;
  45842. }
  45843. }
  45844. // Ignore errors if the `suggestedLength` is huge enough that a Uint8Array
  45845. // cannot hold the result of `getBytes`, and fallback to simply checking
  45846. // the entire stream (fixes issue3928.pdf).
  45847. if (headerBytesLength === suggestedLength) {
  45848. // Most of the time `suggestedLength` is correct, so to speed things up we
  45849. // initially only check the last few bytes to see if the header was found.
  45850. // Otherwise we (potentially) check the entire stream to prevent errors in
  45851. // `Type1Parser` (fixes issue5686.pdf).
  45852. block = findBlock(headerBytes, EEXEC_SIGNATURE, suggestedLength - 2 * EEXEC_SIGNATURE.length);
  45853. if (block.found && block.length === suggestedLength) {
  45854. return {
  45855. stream: new Stream(headerBytes),
  45856. length: suggestedLength
  45857. };
  45858. }
  45859. }
  45860. warn('Invalid "Length1" property in Type1 font -- trying to recover.');
  45861. stream.pos = streamStartPos;
  45862. // Reset the stream position.
  45863. var SCAN_BLOCK_LENGTH = 2048;
  45864. var actualLength;
  45865. while (true) {
  45866. var scanBytes = stream.peekBytes(SCAN_BLOCK_LENGTH);
  45867. block = findBlock(scanBytes, EEXEC_SIGNATURE, 0);
  45868. if (block.length === 0) {
  45869. break;
  45870. }
  45871. stream.pos += block.length;
  45872. // Update the stream position.
  45873. if (block.found) {
  45874. actualLength = stream.pos - streamStartPos;
  45875. break;
  45876. }
  45877. }
  45878. stream.pos = streamStartPos;
  45879. // Reset the stream position.
  45880. if (actualLength) {
  45881. return {
  45882. stream: new Stream(stream.getBytes(actualLength)),
  45883. length: actualLength
  45884. };
  45885. }
  45886. warn('Unable to recover "Length1" property in Type1 font -- using as is.');
  45887. return {
  45888. stream: new Stream(stream.getBytes(suggestedLength)),
  45889. length: suggestedLength
  45890. };
  45891. }
  45892. function getEexecBlock(stream, suggestedLength) {
  45893. // We should ideally parse the eexec block to ensure that `suggestedLength`
  45894. // is correct, so we don't truncate the block data if it's too small.
  45895. // However, this would also require checking if the fixed-content portion
  45896. // exists (using the 'Length3' property), and ensuring that it's valid.
  45897. //
  45898. // Given that `suggestedLength` almost always is correct, all the validation
  45899. // would require a great deal of unnecessary parsing for most fonts.
  45900. // To save time, we always fetch the entire stream instead, which also avoid
  45901. // issues if `suggestedLength` is huge (see comment in `getHeaderBlock`).
  45902. //
  45903. // NOTE: This means that the function can include the fixed-content portion
  45904. // in the returned eexec block. In practice this does *not* seem to matter,
  45905. // since `Type1Parser_extractFontProgram` will skip over any non-commands.
  45906. var eexecBytes = stream.getBytes();
  45907. return {
  45908. stream: new Stream(eexecBytes),
  45909. length: eexecBytes.length
  45910. };
  45911. }
  45912. function Type1Font(name, file, properties) {
  45913. // Some bad generators embed pfb file as is, we have to strip 6-byte header.
  45914. // Also, length1 and length2 might be off by 6 bytes as well.
  45915. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  45916. var PFB_HEADER_SIZE = 6;
  45917. var headerBlockLength = properties.length1;
  45918. var eexecBlockLength = properties.length2;
  45919. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  45920. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  45921. if (pfbHeaderPresent) {
  45922. file.skip(PFB_HEADER_SIZE);
  45923. headerBlockLength = pfbHeader[5] << 24 | pfbHeader[4] << 16 | pfbHeader[3] << 8 | pfbHeader[2];
  45924. }
  45925. // Get the data block containing glyphs and subrs information
  45926. var headerBlock = getHeaderBlock(file, headerBlockLength);
  45927. headerBlockLength = headerBlock.length;
  45928. var headerBlockParser = new Type1Parser(headerBlock.stream, false, SEAC_ANALYSIS_ENABLED);
  45929. headerBlockParser.extractFontHeader(properties);
  45930. if (pfbHeaderPresent) {
  45931. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  45932. eexecBlockLength = pfbHeader[5] << 24 | pfbHeader[4] << 16 | pfbHeader[3] << 8 | pfbHeader[2];
  45933. }
  45934. // Decrypt the data blocks and retrieve it's content
  45935. var eexecBlock = getEexecBlock(file, eexecBlockLength);
  45936. eexecBlockLength = eexecBlock.length;
  45937. var eexecBlockParser = new Type1Parser(eexecBlock.stream, true, SEAC_ANALYSIS_ENABLED);
  45938. var data = eexecBlockParser.extractFontProgram();
  45939. for (var info in data.properties) {
  45940. properties[info] = data.properties[info];
  45941. }
  45942. var charstrings = data.charstrings;
  45943. var type2Charstrings = this.getType2Charstrings(charstrings);
  45944. var subrs = this.getType2Subrs(data.subrs);
  45945. this.charstrings = charstrings;
  45946. this.data = this.wrap(name, type2Charstrings, this.charstrings, subrs, properties);
  45947. this.seacs = this.getSeacs(data.charstrings);
  45948. }
  45949. Type1Font.prototype = {
  45950. get numGlyphs() {
  45951. return this.charstrings.length + 1;
  45952. },
  45953. getCharset: function Type1Font_getCharset() {
  45954. var charset = ['.notdef'];
  45955. var charstrings = this.charstrings;
  45956. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  45957. charset.push(charstrings[glyphId].glyphName);
  45958. }
  45959. return charset;
  45960. },
  45961. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  45962. var charstrings = this.charstrings;
  45963. var glyphNames = ['.notdef'], glyphId;
  45964. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  45965. glyphNames.push(charstrings[glyphId].glyphName);
  45966. }
  45967. var encoding = properties.builtInEncoding;
  45968. if (encoding) {
  45969. var builtInEncoding = Object.create(null);
  45970. for (var charCode in encoding) {
  45971. glyphId = glyphNames.indexOf(encoding[charCode]);
  45972. if (glyphId >= 0) {
  45973. builtInEncoding[charCode] = glyphId;
  45974. }
  45975. }
  45976. }
  45977. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  45978. },
  45979. getSeacs: function Type1Font_getSeacs(charstrings) {
  45980. var i, ii;
  45981. var seacMap = [];
  45982. for (i = 0, ii = charstrings.length; i < ii; i++) {
  45983. var charstring = charstrings[i];
  45984. if (charstring.seac) {
  45985. // Offset by 1 for .notdef
  45986. seacMap[i + 1] = charstring.seac;
  45987. }
  45988. }
  45989. return seacMap;
  45990. },
  45991. getType2Charstrings: function Type1Font_getType2Charstrings(type1Charstrings) {
  45992. var type2Charstrings = [];
  45993. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  45994. type2Charstrings.push(type1Charstrings[i].charstring);
  45995. }
  45996. return type2Charstrings;
  45997. },
  45998. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  45999. var bias = 0;
  46000. var count = type1Subrs.length;
  46001. if (count < 1133) {
  46002. bias = 107;
  46003. } else if (count < 33769) {
  46004. bias = 1131;
  46005. } else {
  46006. bias = 32768;
  46007. }
  46008. // Add a bunch of empty subrs to deal with the Type2 bias
  46009. var type2Subrs = [];
  46010. var i;
  46011. for (i = 0; i < bias; i++) {
  46012. type2Subrs.push([0x0B]);
  46013. }
  46014. for (i = 0; i < count; i++) {
  46015. type2Subrs.push(type1Subrs[i]);
  46016. }
  46017. return type2Subrs;
  46018. },
  46019. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  46020. var cff = new CFF();
  46021. cff.header = new CFFHeader(1, 0, 4, 4);
  46022. cff.names = [name];
  46023. var topDict = new CFFTopDict();
  46024. // CFF strings IDs 0...390 are predefined names, so refering
  46025. // to entries in our own String INDEX starts at SID 391.
  46026. topDict.setByName('version', 391);
  46027. topDict.setByName('Notice', 392);
  46028. topDict.setByName('FullName', 393);
  46029. topDict.setByName('FamilyName', 394);
  46030. topDict.setByName('Weight', 395);
  46031. topDict.setByName('Encoding', null);
  46032. // placeholder
  46033. topDict.setByName('FontMatrix', properties.fontMatrix);
  46034. topDict.setByName('FontBBox', properties.bbox);
  46035. topDict.setByName('charset', null);
  46036. // placeholder
  46037. topDict.setByName('CharStrings', null);
  46038. // placeholder
  46039. topDict.setByName('Private', null);
  46040. // placeholder
  46041. cff.topDict = topDict;
  46042. var strings = new CFFStrings();
  46043. strings.add('Version 0.11');
  46044. // Version
  46045. strings.add('See original notice');
  46046. // Notice
  46047. strings.add(name);
  46048. // FullName
  46049. strings.add(name);
  46050. // FamilyName
  46051. strings.add('Medium');
  46052. // Weight
  46053. cff.strings = strings;
  46054. cff.globalSubrIndex = new CFFIndex();
  46055. var count = glyphs.length;
  46056. var charsetArray = [0];
  46057. var i, ii;
  46058. for (i = 0; i < count; i++) {
  46059. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  46060. // TODO: Insert the string and correctly map it. Previously it was
  46061. // thought mapping names that aren't in the standard strings to .notdef
  46062. // was fine, however in issue818 when mapping them all to .notdef the
  46063. // adieresis glyph no longer worked.
  46064. if (index === -1) {
  46065. index = 0;
  46066. }
  46067. charsetArray.push(index >> 8 & 0xff, index & 0xff);
  46068. }
  46069. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  46070. var charStringsIndex = new CFFIndex();
  46071. charStringsIndex.add([
  46072. 0x8B,
  46073. 0x0E
  46074. ]);
  46075. // .notdef
  46076. for (i = 0; i < count; i++) {
  46077. var glyph = glyphs[i];
  46078. // If the CharString outline is empty, replace it with .notdef to
  46079. // prevent OTS from rejecting the font (fixes bug1252420.pdf).
  46080. if (glyph.length === 0) {
  46081. charStringsIndex.add([
  46082. 0x8B,
  46083. 0x0E
  46084. ]);
  46085. // .notdef
  46086. continue;
  46087. }
  46088. charStringsIndex.add(glyph);
  46089. }
  46090. cff.charStrings = charStringsIndex;
  46091. var privateDict = new CFFPrivateDict();
  46092. privateDict.setByName('Subrs', null);
  46093. // placeholder
  46094. var fields = [
  46095. 'BlueValues',
  46096. 'OtherBlues',
  46097. 'FamilyBlues',
  46098. 'FamilyOtherBlues',
  46099. 'StemSnapH',
  46100. 'StemSnapV',
  46101. 'BlueShift',
  46102. 'BlueFuzz',
  46103. 'BlueScale',
  46104. 'LanguageGroup',
  46105. 'ExpansionFactor',
  46106. 'ForceBold',
  46107. 'StdHW',
  46108. 'StdVW'
  46109. ];
  46110. for (i = 0, ii = fields.length; i < ii; i++) {
  46111. var field = fields[i];
  46112. if (!(field in properties.privateData)) {
  46113. continue;
  46114. }
  46115. var value = properties.privateData[field];
  46116. if (isArray(value)) {
  46117. // All of the private dictionary array data in CFF must be stored as
  46118. // "delta-encoded" numbers.
  46119. for (var j = value.length - 1; j > 0; j--) {
  46120. value[j] -= value[j - 1];
  46121. }
  46122. }
  46123. // ... difference from previous value
  46124. privateDict.setByName(field, value);
  46125. }
  46126. cff.topDict.privateDict = privateDict;
  46127. var subrIndex = new CFFIndex();
  46128. for (i = 0, ii = subrs.length; i < ii; i++) {
  46129. subrIndex.add(subrs[i]);
  46130. }
  46131. privateDict.subrsIndex = subrIndex;
  46132. var compiler = new CFFCompiler(cff);
  46133. return compiler.compile();
  46134. }
  46135. };
  46136. return Type1Font;
  46137. }();
  46138. var CFFFont = function CFFFontClosure() {
  46139. function CFFFont(file, properties) {
  46140. this.properties = properties;
  46141. var parser = new CFFParser(file, properties, SEAC_ANALYSIS_ENABLED);
  46142. this.cff = parser.parse();
  46143. var compiler = new CFFCompiler(this.cff);
  46144. this.seacs = this.cff.seacs;
  46145. try {
  46146. this.data = compiler.compile();
  46147. } catch (e) {
  46148. warn('Failed to compile font ' + properties.loadedName);
  46149. // There may have just been an issue with the compiler, set the data
  46150. // anyway and hope the font loaded.
  46151. this.data = file;
  46152. }
  46153. }
  46154. CFFFont.prototype = {
  46155. get numGlyphs() {
  46156. return this.cff.charStrings.count;
  46157. },
  46158. getCharset: function CFFFont_getCharset() {
  46159. return this.cff.charset.charset;
  46160. },
  46161. getGlyphMapping: function CFFFont_getGlyphMapping() {
  46162. var cff = this.cff;
  46163. var properties = this.properties;
  46164. var charsets = cff.charset.charset;
  46165. var charCodeToGlyphId;
  46166. var glyphId;
  46167. if (properties.composite) {
  46168. charCodeToGlyphId = Object.create(null);
  46169. if (cff.isCIDFont) {
  46170. // If the font is actually a CID font then we should use the charset
  46171. // to map CIDs to GIDs.
  46172. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  46173. var cid = charsets[glyphId];
  46174. var charCode = properties.cMap.charCodeOf(cid);
  46175. charCodeToGlyphId[charCode] = glyphId;
  46176. }
  46177. } else {
  46178. // If it is NOT actually a CID font then CIDs should be mapped
  46179. // directly to GIDs.
  46180. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  46181. charCodeToGlyphId[glyphId] = glyphId;
  46182. }
  46183. }
  46184. return charCodeToGlyphId;
  46185. }
  46186. var encoding = cff.encoding ? cff.encoding.encoding : null;
  46187. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  46188. return charCodeToGlyphId;
  46189. }
  46190. };
  46191. return CFFFont;
  46192. }();
  46193. // Workaround for seac on Windows.
  46194. (function checkSeacSupport() {
  46195. if (typeof navigator !== 'undefined' && /Windows/.test(navigator.userAgent)) {
  46196. SEAC_ANALYSIS_ENABLED = true;
  46197. }
  46198. }());
  46199. // Workaround for Private Use Area characters in Chrome on Windows
  46200. // http://code.google.com/p/chromium/issues/detail?id=122465
  46201. // https://github.com/mozilla/pdf.js/issues/1689
  46202. (function checkChromeWindows() {
  46203. if (typeof navigator !== 'undefined' && /Windows.*Chrome/.test(navigator.userAgent)) {
  46204. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  46205. }
  46206. }());
  46207. exports.ErrorFont = ErrorFont;
  46208. exports.Font = Font;
  46209. exports.FontFlags = FontFlags;
  46210. exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
  46211. exports.ToUnicodeMap = ToUnicodeMap;
  46212. exports.getFontType = getFontType;
  46213. }));
  46214. (function (root, factory) {
  46215. factory(root.pdfjsCorePsParser = {}, root.pdfjsSharedUtil, root.pdfjsCoreParser);
  46216. }(this, function (exports, sharedUtil, coreParser) {
  46217. var error = sharedUtil.error;
  46218. var isSpace = sharedUtil.isSpace;
  46219. var EOF = coreParser.EOF;
  46220. var PostScriptParser = function PostScriptParserClosure() {
  46221. function PostScriptParser(lexer) {
  46222. this.lexer = lexer;
  46223. this.operators = [];
  46224. this.token = null;
  46225. this.prev = null;
  46226. }
  46227. PostScriptParser.prototype = {
  46228. nextToken: function PostScriptParser_nextToken() {
  46229. this.prev = this.token;
  46230. this.token = this.lexer.getToken();
  46231. },
  46232. accept: function PostScriptParser_accept(type) {
  46233. if (this.token.type === type) {
  46234. this.nextToken();
  46235. return true;
  46236. }
  46237. return false;
  46238. },
  46239. expect: function PostScriptParser_expect(type) {
  46240. if (this.accept(type)) {
  46241. return true;
  46242. }
  46243. error('Unexpected symbol: found ' + this.token.type + ' expected ' + type + '.');
  46244. },
  46245. parse: function PostScriptParser_parse() {
  46246. this.nextToken();
  46247. this.expect(PostScriptTokenTypes.LBRACE);
  46248. this.parseBlock();
  46249. this.expect(PostScriptTokenTypes.RBRACE);
  46250. return this.operators;
  46251. },
  46252. parseBlock: function PostScriptParser_parseBlock() {
  46253. while (true) {
  46254. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  46255. this.operators.push(this.prev.value);
  46256. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  46257. this.operators.push(this.prev.value);
  46258. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  46259. this.parseCondition();
  46260. } else {
  46261. return;
  46262. }
  46263. }
  46264. },
  46265. parseCondition: function PostScriptParser_parseCondition() {
  46266. // Add two place holders that will be updated later
  46267. var conditionLocation = this.operators.length;
  46268. this.operators.push(null, null);
  46269. this.parseBlock();
  46270. this.expect(PostScriptTokenTypes.RBRACE);
  46271. if (this.accept(PostScriptTokenTypes.IF)) {
  46272. // The true block is right after the 'if' so it just falls through on
  46273. // true else it jumps and skips the true block.
  46274. this.operators[conditionLocation] = this.operators.length;
  46275. this.operators[conditionLocation + 1] = 'jz';
  46276. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  46277. var jumpLocation = this.operators.length;
  46278. this.operators.push(null, null);
  46279. var endOfTrue = this.operators.length;
  46280. this.parseBlock();
  46281. this.expect(PostScriptTokenTypes.RBRACE);
  46282. this.expect(PostScriptTokenTypes.IFELSE);
  46283. // The jump is added at the end of the true block to skip the false
  46284. // block.
  46285. this.operators[jumpLocation] = this.operators.length;
  46286. this.operators[jumpLocation + 1] = 'j';
  46287. this.operators[conditionLocation] = endOfTrue;
  46288. this.operators[conditionLocation + 1] = 'jz';
  46289. } else {
  46290. error('PS Function: error parsing conditional.');
  46291. }
  46292. }
  46293. };
  46294. return PostScriptParser;
  46295. }();
  46296. var PostScriptTokenTypes = {
  46297. LBRACE: 0,
  46298. RBRACE: 1,
  46299. NUMBER: 2,
  46300. OPERATOR: 3,
  46301. IF: 4,
  46302. IFELSE: 5
  46303. };
  46304. var PostScriptToken = function PostScriptTokenClosure() {
  46305. function PostScriptToken(type, value) {
  46306. this.type = type;
  46307. this.value = value;
  46308. }
  46309. var opCache = Object.create(null);
  46310. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  46311. var opValue = opCache[op];
  46312. if (opValue) {
  46313. return opValue;
  46314. }
  46315. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  46316. };
  46317. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE, '{');
  46318. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE, '}');
  46319. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  46320. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE, 'IFELSE');
  46321. return PostScriptToken;
  46322. }();
  46323. var PostScriptLexer = function PostScriptLexerClosure() {
  46324. function PostScriptLexer(stream) {
  46325. this.stream = stream;
  46326. this.nextChar();
  46327. this.strBuf = [];
  46328. }
  46329. PostScriptLexer.prototype = {
  46330. nextChar: function PostScriptLexer_nextChar() {
  46331. return this.currentChar = this.stream.getByte();
  46332. },
  46333. getToken: function PostScriptLexer_getToken() {
  46334. var comment = false;
  46335. var ch = this.currentChar;
  46336. // skip comments
  46337. while (true) {
  46338. if (ch < 0) {
  46339. return EOF;
  46340. }
  46341. if (comment) {
  46342. if (ch === 0x0A || ch === 0x0D) {
  46343. comment = false;
  46344. }
  46345. } else if (ch === 0x25) {
  46346. // '%'
  46347. comment = true;
  46348. } else if (!isSpace(ch)) {
  46349. break;
  46350. }
  46351. ch = this.nextChar();
  46352. }
  46353. switch (ch | 0) {
  46354. case 0x30:
  46355. case 0x31:
  46356. case 0x32:
  46357. case 0x33:
  46358. case 0x34:
  46359. // '0'-'4'
  46360. case 0x35:
  46361. case 0x36:
  46362. case 0x37:
  46363. case 0x38:
  46364. case 0x39:
  46365. // '5'-'9'
  46366. case 0x2B:
  46367. case 0x2D:
  46368. case 0x2E:
  46369. // '+', '-', '.'
  46370. return new PostScriptToken(PostScriptTokenTypes.NUMBER, this.getNumber());
  46371. case 0x7B:
  46372. // '{'
  46373. this.nextChar();
  46374. return PostScriptToken.LBRACE;
  46375. case 0x7D:
  46376. // '}'
  46377. this.nextChar();
  46378. return PostScriptToken.RBRACE;
  46379. }
  46380. // operator
  46381. var strBuf = this.strBuf;
  46382. strBuf.length = 0;
  46383. strBuf[0] = String.fromCharCode(ch);
  46384. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  46385. (ch >= 0x41 && ch <= 0x5A || ch >= 0x61 && ch <= 0x7A)) {
  46386. strBuf.push(String.fromCharCode(ch));
  46387. }
  46388. var str = strBuf.join('');
  46389. switch (str.toLowerCase()) {
  46390. case 'if':
  46391. return PostScriptToken.IF;
  46392. case 'ifelse':
  46393. return PostScriptToken.IFELSE;
  46394. default:
  46395. return PostScriptToken.getOperator(str);
  46396. }
  46397. },
  46398. getNumber: function PostScriptLexer_getNumber() {
  46399. var ch = this.currentChar;
  46400. var strBuf = this.strBuf;
  46401. strBuf.length = 0;
  46402. strBuf[0] = String.fromCharCode(ch);
  46403. while ((ch = this.nextChar()) >= 0) {
  46404. if (ch >= 0x30 && ch <= 0x39 || // '0'-'9'
  46405. ch === 0x2D || ch === 0x2E) {
  46406. // '-', '.'
  46407. strBuf.push(String.fromCharCode(ch));
  46408. } else {
  46409. break;
  46410. }
  46411. }
  46412. var value = parseFloat(strBuf.join(''));
  46413. if (isNaN(value)) {
  46414. error('Invalid floating point number: ' + value);
  46415. }
  46416. return value;
  46417. }
  46418. };
  46419. return PostScriptLexer;
  46420. }();
  46421. exports.PostScriptLexer = PostScriptLexer;
  46422. exports.PostScriptParser = PostScriptParser;
  46423. }));
  46424. (function (root, factory) {
  46425. factory(root.pdfjsDisplayCanvas = {}, root.pdfjsSharedUtil, root.pdfjsDisplayDOMUtils, root.pdfjsDisplayPatternHelper, root.pdfjsDisplayWebGL);
  46426. }(this, function (exports, sharedUtil, displayDOMUtils, displayPatternHelper, displayWebGL) {
  46427. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  46428. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  46429. var ImageKind = sharedUtil.ImageKind;
  46430. var OPS = sharedUtil.OPS;
  46431. var TextRenderingMode = sharedUtil.TextRenderingMode;
  46432. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  46433. var Util = sharedUtil.Util;
  46434. var assert = sharedUtil.assert;
  46435. var info = sharedUtil.info;
  46436. var isNum = sharedUtil.isNum;
  46437. var isArray = sharedUtil.isArray;
  46438. var isLittleEndian = sharedUtil.isLittleEndian;
  46439. var error = sharedUtil.error;
  46440. var shadow = sharedUtil.shadow;
  46441. var warn = sharedUtil.warn;
  46442. var TilingPattern = displayPatternHelper.TilingPattern;
  46443. var getShadingPatternFromIR = displayPatternHelper.getShadingPatternFromIR;
  46444. var WebGLUtils = displayWebGL.WebGLUtils;
  46445. var hasCanvasTypedArrays = displayDOMUtils.hasCanvasTypedArrays;
  46446. // <canvas> contexts store most of the state we need natively.
  46447. // However, PDF needs a bit more state, which we store here.
  46448. // Minimal font size that would be used during canvas fillText operations.
  46449. var MIN_FONT_SIZE = 16;
  46450. // Maximum font size that would be used during canvas fillText operations.
  46451. var MAX_FONT_SIZE = 100;
  46452. var MAX_GROUP_SIZE = 4096;
  46453. // Heuristic value used when enforcing minimum line widths.
  46454. var MIN_WIDTH_FACTOR = 0.65;
  46455. var COMPILE_TYPE3_GLYPHS = true;
  46456. var MAX_SIZE_TO_COMPILE = 1000;
  46457. var FULL_CHUNK_HEIGHT = 16;
  46458. var HasCanvasTypedArraysCached = {
  46459. get value() {
  46460. return shadow(HasCanvasTypedArraysCached, 'value', hasCanvasTypedArrays());
  46461. }
  46462. };
  46463. var IsLittleEndianCached = {
  46464. get value() {
  46465. return shadow(IsLittleEndianCached, 'value', isLittleEndian());
  46466. }
  46467. };
  46468. function createScratchCanvas(width, height) {
  46469. var canvas = document.createElement('canvas');
  46470. canvas.width = width;
  46471. canvas.height = height;
  46472. return canvas;
  46473. }
  46474. function addContextCurrentTransform(ctx) {
  46475. // If the context doesn't expose a `mozCurrentTransform`, add a JS based one.
  46476. if (!ctx.mozCurrentTransform) {
  46477. ctx._originalSave = ctx.save;
  46478. ctx._originalRestore = ctx.restore;
  46479. ctx._originalRotate = ctx.rotate;
  46480. ctx._originalScale = ctx.scale;
  46481. ctx._originalTranslate = ctx.translate;
  46482. ctx._originalTransform = ctx.transform;
  46483. ctx._originalSetTransform = ctx.setTransform;
  46484. ctx._transformMatrix = ctx._transformMatrix || [
  46485. 1,
  46486. 0,
  46487. 0,
  46488. 1,
  46489. 0,
  46490. 0
  46491. ];
  46492. ctx._transformStack = [];
  46493. Object.defineProperty(ctx, 'mozCurrentTransform', {
  46494. get: function getCurrentTransform() {
  46495. return this._transformMatrix;
  46496. }
  46497. });
  46498. Object.defineProperty(ctx, 'mozCurrentTransformInverse', {
  46499. get: function getCurrentTransformInverse() {
  46500. // Calculation done using WolframAlpha:
  46501. // http://www.wolframalpha.com/input/?
  46502. // i=Inverse+{{a%2C+c%2C+e}%2C+{b%2C+d%2C+f}%2C+{0%2C+0%2C+1}}
  46503. var m = this._transformMatrix;
  46504. var a = m[0], b = m[1], c = m[2], d = m[3], e = m[4], f = m[5];
  46505. var ad_bc = a * d - b * c;
  46506. var bc_ad = b * c - a * d;
  46507. return [
  46508. d / ad_bc,
  46509. b / bc_ad,
  46510. c / bc_ad,
  46511. a / ad_bc,
  46512. (d * e - c * f) / bc_ad,
  46513. (b * e - a * f) / ad_bc
  46514. ];
  46515. }
  46516. });
  46517. ctx.save = function ctxSave() {
  46518. var old = this._transformMatrix;
  46519. this._transformStack.push(old);
  46520. this._transformMatrix = old.slice(0, 6);
  46521. this._originalSave();
  46522. };
  46523. ctx.restore = function ctxRestore() {
  46524. var prev = this._transformStack.pop();
  46525. if (prev) {
  46526. this._transformMatrix = prev;
  46527. this._originalRestore();
  46528. }
  46529. };
  46530. ctx.translate = function ctxTranslate(x, y) {
  46531. var m = this._transformMatrix;
  46532. m[4] = m[0] * x + m[2] * y + m[4];
  46533. m[5] = m[1] * x + m[3] * y + m[5];
  46534. this._originalTranslate(x, y);
  46535. };
  46536. ctx.scale = function ctxScale(x, y) {
  46537. var m = this._transformMatrix;
  46538. m[0] = m[0] * x;
  46539. m[1] = m[1] * x;
  46540. m[2] = m[2] * y;
  46541. m[3] = m[3] * y;
  46542. this._originalScale(x, y);
  46543. };
  46544. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  46545. var m = this._transformMatrix;
  46546. this._transformMatrix = [
  46547. m[0] * a + m[2] * b,
  46548. m[1] * a + m[3] * b,
  46549. m[0] * c + m[2] * d,
  46550. m[1] * c + m[3] * d,
  46551. m[0] * e + m[2] * f + m[4],
  46552. m[1] * e + m[3] * f + m[5]
  46553. ];
  46554. ctx._originalTransform(a, b, c, d, e, f);
  46555. };
  46556. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  46557. this._transformMatrix = [
  46558. a,
  46559. b,
  46560. c,
  46561. d,
  46562. e,
  46563. f
  46564. ];
  46565. ctx._originalSetTransform(a, b, c, d, e, f);
  46566. };
  46567. ctx.rotate = function ctxRotate(angle) {
  46568. var cosValue = Math.cos(angle);
  46569. var sinValue = Math.sin(angle);
  46570. var m = this._transformMatrix;
  46571. this._transformMatrix = [
  46572. m[0] * cosValue + m[2] * sinValue,
  46573. m[1] * cosValue + m[3] * sinValue,
  46574. m[0] * -sinValue + m[2] * cosValue,
  46575. m[1] * -sinValue + m[3] * cosValue,
  46576. m[4],
  46577. m[5]
  46578. ];
  46579. this._originalRotate(angle);
  46580. };
  46581. }
  46582. }
  46583. var CachedCanvases = function CachedCanvasesClosure() {
  46584. function CachedCanvases() {
  46585. this.cache = Object.create(null);
  46586. }
  46587. CachedCanvases.prototype = {
  46588. getCanvas: function CachedCanvases_getCanvas(id, width, height, trackTransform) {
  46589. var canvasEntry;
  46590. if (this.cache[id] !== undefined) {
  46591. canvasEntry = this.cache[id];
  46592. canvasEntry.canvas.width = width;
  46593. canvasEntry.canvas.height = height;
  46594. // reset canvas transform for emulated mozCurrentTransform, if needed
  46595. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  46596. } else {
  46597. var canvas = createScratchCanvas(width, height);
  46598. var ctx = canvas.getContext('2d');
  46599. if (trackTransform) {
  46600. addContextCurrentTransform(ctx);
  46601. }
  46602. this.cache[id] = canvasEntry = {
  46603. canvas: canvas,
  46604. context: ctx
  46605. };
  46606. }
  46607. return canvasEntry;
  46608. },
  46609. clear: function () {
  46610. for (var id in this.cache) {
  46611. var canvasEntry = this.cache[id];
  46612. // Zeroing the width and height causes Firefox to release graphics
  46613. // resources immediately, which can greatly reduce memory consumption.
  46614. canvasEntry.canvas.width = 0;
  46615. canvasEntry.canvas.height = 0;
  46616. delete this.cache[id];
  46617. }
  46618. }
  46619. };
  46620. return CachedCanvases;
  46621. }();
  46622. function compileType3Glyph(imgData) {
  46623. var POINT_TO_PROCESS_LIMIT = 1000;
  46624. var width = imgData.width, height = imgData.height;
  46625. var i, j, j0, width1 = width + 1;
  46626. var points = new Uint8Array(width1 * (height + 1));
  46627. var POINT_TYPES = new Uint8Array([
  46628. 0,
  46629. 2,
  46630. 4,
  46631. 0,
  46632. 1,
  46633. 0,
  46634. 5,
  46635. 4,
  46636. 8,
  46637. 10,
  46638. 0,
  46639. 8,
  46640. 0,
  46641. 2,
  46642. 1,
  46643. 0
  46644. ]);
  46645. // decodes bit-packed mask data
  46646. var lineSize = width + 7 & ~7, data0 = imgData.data;
  46647. var data = new Uint8Array(lineSize * height), pos = 0, ii;
  46648. for (i = 0, ii = data0.length; i < ii; i++) {
  46649. var mask = 128, elem = data0[i];
  46650. while (mask > 0) {
  46651. data[pos++] = elem & mask ? 0 : 255;
  46652. mask >>= 1;
  46653. }
  46654. }
  46655. // finding iteresting points: every point is located between mask pixels,
  46656. // so there will be points of the (width + 1)x(height + 1) grid. Every point
  46657. // will have flags assigned based on neighboring mask pixels:
  46658. // 4 | 8
  46659. // --P--
  46660. // 2 | 1
  46661. // We are interested only in points with the flags:
  46662. // - outside corners: 1, 2, 4, 8;
  46663. // - inside corners: 7, 11, 13, 14;
  46664. // - and, intersections: 5, 10.
  46665. var count = 0;
  46666. pos = 0;
  46667. if (data[pos] !== 0) {
  46668. points[0] = 1;
  46669. ++count;
  46670. }
  46671. for (j = 1; j < width; j++) {
  46672. if (data[pos] !== data[pos + 1]) {
  46673. points[j] = data[pos] ? 2 : 1;
  46674. ++count;
  46675. }
  46676. pos++;
  46677. }
  46678. if (data[pos] !== 0) {
  46679. points[j] = 2;
  46680. ++count;
  46681. }
  46682. for (i = 1; i < height; i++) {
  46683. pos = i * lineSize;
  46684. j0 = i * width1;
  46685. if (data[pos - lineSize] !== data[pos]) {
  46686. points[j0] = data[pos] ? 1 : 8;
  46687. ++count;
  46688. }
  46689. // 'sum' is the position of the current pixel configuration in the 'TYPES'
  46690. // array (in order 8-1-2-4, so we can use '>>2' to shift the column).
  46691. var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  46692. for (j = 1; j < width; j++) {
  46693. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) + (data[pos - lineSize + 1] ? 8 : 0);
  46694. if (POINT_TYPES[sum]) {
  46695. points[j0 + j] = POINT_TYPES[sum];
  46696. ++count;
  46697. }
  46698. pos++;
  46699. }
  46700. if (data[pos - lineSize] !== data[pos]) {
  46701. points[j0 + j] = data[pos] ? 2 : 4;
  46702. ++count;
  46703. }
  46704. if (count > POINT_TO_PROCESS_LIMIT) {
  46705. return null;
  46706. }
  46707. }
  46708. pos = lineSize * (height - 1);
  46709. j0 = i * width1;
  46710. if (data[pos] !== 0) {
  46711. points[j0] = 8;
  46712. ++count;
  46713. }
  46714. for (j = 1; j < width; j++) {
  46715. if (data[pos] !== data[pos + 1]) {
  46716. points[j0 + j] = data[pos] ? 4 : 8;
  46717. ++count;
  46718. }
  46719. pos++;
  46720. }
  46721. if (data[pos] !== 0) {
  46722. points[j0 + j] = 4;
  46723. ++count;
  46724. }
  46725. if (count > POINT_TO_PROCESS_LIMIT) {
  46726. return null;
  46727. }
  46728. // building outlines
  46729. var steps = new Int32Array([
  46730. 0,
  46731. width1,
  46732. -1,
  46733. 0,
  46734. -width1,
  46735. 0,
  46736. 0,
  46737. 0,
  46738. 1
  46739. ]);
  46740. var outlines = [];
  46741. for (i = 0; count && i <= height; i++) {
  46742. var p = i * width1;
  46743. var end = p + width;
  46744. while (p < end && !points[p]) {
  46745. p++;
  46746. }
  46747. if (p === end) {
  46748. continue;
  46749. }
  46750. var coords = [
  46751. p % width1,
  46752. i
  46753. ];
  46754. var type = points[p], p0 = p, pp;
  46755. do {
  46756. var step = steps[type];
  46757. do {
  46758. p += step;
  46759. } while (!points[p]);
  46760. pp = points[p];
  46761. if (pp !== 5 && pp !== 10) {
  46762. // set new direction
  46763. type = pp;
  46764. // delete mark
  46765. points[p] = 0;
  46766. } else {
  46767. // type is 5 or 10, ie, a crossing
  46768. // set new direction
  46769. type = pp & 0x33 * type >> 4;
  46770. // set new type for "future hit"
  46771. points[p] &= type >> 2 | type << 2;
  46772. }
  46773. coords.push(p % width1);
  46774. coords.push(p / width1 | 0);
  46775. --count;
  46776. } while (p0 !== p);
  46777. outlines.push(coords);
  46778. --i;
  46779. }
  46780. var drawOutline = function (c) {
  46781. c.save();
  46782. // the path shall be painted in [0..1]x[0..1] space
  46783. c.scale(1 / width, -1 / height);
  46784. c.translate(0, -height);
  46785. c.beginPath();
  46786. for (var i = 0, ii = outlines.length; i < ii; i++) {
  46787. var o = outlines[i];
  46788. c.moveTo(o[0], o[1]);
  46789. for (var j = 2, jj = o.length; j < jj; j += 2) {
  46790. c.lineTo(o[j], o[j + 1]);
  46791. }
  46792. }
  46793. c.fill();
  46794. c.beginPath();
  46795. c.restore();
  46796. };
  46797. return drawOutline;
  46798. }
  46799. var CanvasExtraState = function CanvasExtraStateClosure() {
  46800. function CanvasExtraState(old) {
  46801. // Are soft masks and alpha values shapes or opacities?
  46802. this.alphaIsShape = false;
  46803. this.fontSize = 0;
  46804. this.fontSizeScale = 1;
  46805. this.textMatrix = IDENTITY_MATRIX;
  46806. this.textMatrixScale = 1;
  46807. this.fontMatrix = FONT_IDENTITY_MATRIX;
  46808. this.leading = 0;
  46809. // Current point (in user coordinates)
  46810. this.x = 0;
  46811. this.y = 0;
  46812. // Start of text line (in text coordinates)
  46813. this.lineX = 0;
  46814. this.lineY = 0;
  46815. // Character and word spacing
  46816. this.charSpacing = 0;
  46817. this.wordSpacing = 0;
  46818. this.textHScale = 1;
  46819. this.textRenderingMode = TextRenderingMode.FILL;
  46820. this.textRise = 0;
  46821. // Default fore and background colors
  46822. this.fillColor = '#000000';
  46823. this.strokeColor = '#000000';
  46824. this.patternFill = false;
  46825. // Note: fill alpha applies to all non-stroking operations
  46826. this.fillAlpha = 1;
  46827. this.strokeAlpha = 1;
  46828. this.lineWidth = 1;
  46829. this.activeSMask = null;
  46830. this.resumeSMaskCtx = null;
  46831. // nonclonable field (see the save method below)
  46832. this.old = old;
  46833. }
  46834. CanvasExtraState.prototype = {
  46835. clone: function CanvasExtraState_clone() {
  46836. return Object.create(this);
  46837. },
  46838. setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
  46839. this.x = x;
  46840. this.y = y;
  46841. }
  46842. };
  46843. return CanvasExtraState;
  46844. }();
  46845. var CanvasGraphics = function CanvasGraphicsClosure() {
  46846. // Defines the time the executeOperatorList is going to be executing
  46847. // before it stops and shedules a continue of execution.
  46848. var EXECUTION_TIME = 15;
  46849. // Defines the number of steps before checking the execution time
  46850. var EXECUTION_STEPS = 10;
  46851. function CanvasGraphics(canvasCtx, commonObjs, objs, imageLayer) {
  46852. this.ctx = canvasCtx;
  46853. this.current = new CanvasExtraState();
  46854. this.stateStack = [];
  46855. this.pendingClip = null;
  46856. this.pendingEOFill = false;
  46857. this.res = null;
  46858. this.xobjs = null;
  46859. this.commonObjs = commonObjs;
  46860. this.objs = objs;
  46861. this.imageLayer = imageLayer;
  46862. this.groupStack = [];
  46863. this.processingType3 = null;
  46864. // Patterns are painted relative to the initial page/form transform, see pdf
  46865. // spec 8.7.2 NOTE 1.
  46866. this.baseTransform = null;
  46867. this.baseTransformStack = [];
  46868. this.groupLevel = 0;
  46869. this.smaskStack = [];
  46870. this.smaskCounter = 0;
  46871. this.tempSMask = null;
  46872. this.cachedCanvases = new CachedCanvases();
  46873. if (canvasCtx) {
  46874. // NOTE: if mozCurrentTransform is polyfilled, then the current state of
  46875. // the transformation must already be set in canvasCtx._transformMatrix.
  46876. addContextCurrentTransform(canvasCtx);
  46877. }
  46878. this.cachedGetSinglePixelWidth = null;
  46879. }
  46880. function putBinaryImageData(ctx, imgData) {
  46881. if (typeof ImageData !== 'undefined' && imgData instanceof ImageData) {
  46882. ctx.putImageData(imgData, 0, 0);
  46883. return;
  46884. }
  46885. // Put the image data to the canvas in chunks, rather than putting the
  46886. // whole image at once. This saves JS memory, because the ImageData object
  46887. // is smaller. It also possibly saves C++ memory within the implementation
  46888. // of putImageData(). (E.g. in Firefox we make two short-lived copies of
  46889. // the data passed to putImageData()). |n| shouldn't be too small, however,
  46890. // because too many putImageData() calls will slow things down.
  46891. //
  46892. // Note: as written, if the last chunk is partial, the putImageData() call
  46893. // will (conceptually) put pixels past the bounds of the canvas. But
  46894. // that's ok; any such pixels are ignored.
  46895. var height = imgData.height, width = imgData.width;
  46896. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  46897. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  46898. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  46899. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  46900. var srcPos = 0, destPos;
  46901. var src = imgData.data;
  46902. var dest = chunkImgData.data;
  46903. var i, j, thisChunkHeight, elemsInThisChunk;
  46904. // There are multiple forms in which the pixel data can be passed, and
  46905. // imgData.kind tells us which one this is.
  46906. if (imgData.kind === ImageKind.GRAYSCALE_1BPP) {
  46907. // Grayscale, 1 bit per pixel (i.e. black-and-white).
  46908. var srcLength = src.byteLength;
  46909. var dest32 = HasCanvasTypedArraysCached.value ? new Uint32Array(dest.buffer) : new Uint32ArrayView(dest);
  46910. var dest32DataLength = dest32.length;
  46911. var fullSrcDiff = width + 7 >> 3;
  46912. var white = 0xFFFFFFFF;
  46913. var black = IsLittleEndianCached.value || !HasCanvasTypedArraysCached.value ? 0xFF000000 : 0x000000FF;
  46914. for (i = 0; i < totalChunks; i++) {
  46915. thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  46916. destPos = 0;
  46917. for (j = 0; j < thisChunkHeight; j++) {
  46918. var srcDiff = srcLength - srcPos;
  46919. var k = 0;
  46920. var kEnd = srcDiff > fullSrcDiff ? width : srcDiff * 8 - 7;
  46921. var kEndUnrolled = kEnd & ~7;
  46922. var mask = 0;
  46923. var srcByte = 0;
  46924. for (; k < kEndUnrolled; k += 8) {
  46925. srcByte = src[srcPos++];
  46926. dest32[destPos++] = srcByte & 128 ? white : black;
  46927. dest32[destPos++] = srcByte & 64 ? white : black;
  46928. dest32[destPos++] = srcByte & 32 ? white : black;
  46929. dest32[destPos++] = srcByte & 16 ? white : black;
  46930. dest32[destPos++] = srcByte & 8 ? white : black;
  46931. dest32[destPos++] = srcByte & 4 ? white : black;
  46932. dest32[destPos++] = srcByte & 2 ? white : black;
  46933. dest32[destPos++] = srcByte & 1 ? white : black;
  46934. }
  46935. for (; k < kEnd; k++) {
  46936. if (mask === 0) {
  46937. srcByte = src[srcPos++];
  46938. mask = 128;
  46939. }
  46940. dest32[destPos++] = srcByte & mask ? white : black;
  46941. mask >>= 1;
  46942. }
  46943. }
  46944. // We ran out of input. Make all remaining pixels transparent.
  46945. while (destPos < dest32DataLength) {
  46946. dest32[destPos++] = 0;
  46947. }
  46948. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  46949. }
  46950. } else if (imgData.kind === ImageKind.RGBA_32BPP) {
  46951. // RGBA, 32-bits per pixel.
  46952. j = 0;
  46953. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  46954. for (i = 0; i < fullChunks; i++) {
  46955. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  46956. srcPos += elemsInThisChunk;
  46957. ctx.putImageData(chunkImgData, 0, j);
  46958. j += FULL_CHUNK_HEIGHT;
  46959. }
  46960. if (i < totalChunks) {
  46961. elemsInThisChunk = width * partialChunkHeight * 4;
  46962. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  46963. ctx.putImageData(chunkImgData, 0, j);
  46964. }
  46965. } else if (imgData.kind === ImageKind.RGB_24BPP) {
  46966. // RGB, 24-bits per pixel.
  46967. thisChunkHeight = FULL_CHUNK_HEIGHT;
  46968. elemsInThisChunk = width * thisChunkHeight;
  46969. for (i = 0; i < totalChunks; i++) {
  46970. if (i >= fullChunks) {
  46971. thisChunkHeight = partialChunkHeight;
  46972. elemsInThisChunk = width * thisChunkHeight;
  46973. }
  46974. destPos = 0;
  46975. for (j = elemsInThisChunk; j--;) {
  46976. dest[destPos++] = src[srcPos++];
  46977. dest[destPos++] = src[srcPos++];
  46978. dest[destPos++] = src[srcPos++];
  46979. dest[destPos++] = 255;
  46980. }
  46981. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  46982. }
  46983. } else {
  46984. error('bad image kind: ' + imgData.kind);
  46985. }
  46986. }
  46987. function putBinaryImageMask(ctx, imgData) {
  46988. var height = imgData.height, width = imgData.width;
  46989. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  46990. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  46991. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  46992. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  46993. var srcPos = 0;
  46994. var src = imgData.data;
  46995. var dest = chunkImgData.data;
  46996. for (var i = 0; i < totalChunks; i++) {
  46997. var thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  46998. // Expand the mask so it can be used by the canvas. Any required
  46999. // inversion has already been handled.
  47000. var destPos = 3;
  47001. // alpha component offset
  47002. for (var j = 0; j < thisChunkHeight; j++) {
  47003. var mask = 0;
  47004. for (var k = 0; k < width; k++) {
  47005. if (!mask) {
  47006. var elem = src[srcPos++];
  47007. mask = 128;
  47008. }
  47009. dest[destPos] = elem & mask ? 0 : 255;
  47010. destPos += 4;
  47011. mask >>= 1;
  47012. }
  47013. }
  47014. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  47015. }
  47016. }
  47017. function copyCtxState(sourceCtx, destCtx) {
  47018. var properties = [
  47019. 'strokeStyle',
  47020. 'fillStyle',
  47021. 'fillRule',
  47022. 'globalAlpha',
  47023. 'lineWidth',
  47024. 'lineCap',
  47025. 'lineJoin',
  47026. 'miterLimit',
  47027. 'globalCompositeOperation',
  47028. 'font'
  47029. ];
  47030. for (var i = 0, ii = properties.length; i < ii; i++) {
  47031. var property = properties[i];
  47032. if (sourceCtx[property] !== undefined) {
  47033. destCtx[property] = sourceCtx[property];
  47034. }
  47035. }
  47036. if (sourceCtx.setLineDash !== undefined) {
  47037. destCtx.setLineDash(sourceCtx.getLineDash());
  47038. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  47039. }
  47040. }
  47041. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  47042. var length = bytes.length;
  47043. for (var i = 3; i < length; i += 4) {
  47044. var alpha = bytes[i];
  47045. if (alpha === 0) {
  47046. bytes[i - 3] = r0;
  47047. bytes[i - 2] = g0;
  47048. bytes[i - 1] = b0;
  47049. } else if (alpha < 255) {
  47050. var alpha_ = 255 - alpha;
  47051. bytes[i - 3] = bytes[i - 3] * alpha + r0 * alpha_ >> 8;
  47052. bytes[i - 2] = bytes[i - 2] * alpha + g0 * alpha_ >> 8;
  47053. bytes[i - 1] = bytes[i - 1] * alpha + b0 * alpha_ >> 8;
  47054. }
  47055. }
  47056. }
  47057. function composeSMaskAlpha(maskData, layerData, transferMap) {
  47058. var length = maskData.length;
  47059. var scale = 1 / 255;
  47060. for (var i = 3; i < length; i += 4) {
  47061. var alpha = transferMap ? transferMap[maskData[i]] : maskData[i];
  47062. layerData[i] = layerData[i] * alpha * scale | 0;
  47063. }
  47064. }
  47065. function composeSMaskLuminosity(maskData, layerData, transferMap) {
  47066. var length = maskData.length;
  47067. for (var i = 3; i < length; i += 4) {
  47068. var y = maskData[i - 3] * 77 + // * 0.3 / 255 * 0x10000
  47069. maskData[i - 2] * 152 + // * 0.59 ....
  47070. maskData[i - 1] * 28;
  47071. // * 0.11 ....
  47072. layerData[i] = transferMap ? layerData[i] * transferMap[y >> 8] >> 8 : layerData[i] * y >> 16;
  47073. }
  47074. }
  47075. function genericComposeSMask(maskCtx, layerCtx, width, height, subtype, backdrop, transferMap) {
  47076. var hasBackdrop = !!backdrop;
  47077. var r0 = hasBackdrop ? backdrop[0] : 0;
  47078. var g0 = hasBackdrop ? backdrop[1] : 0;
  47079. var b0 = hasBackdrop ? backdrop[2] : 0;
  47080. var composeFn;
  47081. if (subtype === 'Luminosity') {
  47082. composeFn = composeSMaskLuminosity;
  47083. } else {
  47084. composeFn = composeSMaskAlpha;
  47085. }
  47086. // processing image in chunks to save memory
  47087. var PIXELS_TO_PROCESS = 1048576;
  47088. var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  47089. for (var row = 0; row < height; row += chunkSize) {
  47090. var chunkHeight = Math.min(chunkSize, height - row);
  47091. var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
  47092. var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
  47093. if (hasBackdrop) {
  47094. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  47095. }
  47096. composeFn(maskData.data, layerData.data, transferMap);
  47097. maskCtx.putImageData(layerData, 0, row);
  47098. }
  47099. }
  47100. function composeSMask(ctx, smask, layerCtx) {
  47101. var mask = smask.canvas;
  47102. var maskCtx = smask.context;
  47103. ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY, smask.offsetX, smask.offsetY);
  47104. var backdrop = smask.backdrop || null;
  47105. if (!smask.transferMap && WebGLUtils.isEnabled) {
  47106. var composed = WebGLUtils.composeSMask(layerCtx.canvas, mask, {
  47107. subtype: smask.subtype,
  47108. backdrop: backdrop
  47109. });
  47110. ctx.setTransform(1, 0, 0, 1, 0, 0);
  47111. ctx.drawImage(composed, smask.offsetX, smask.offsetY);
  47112. return;
  47113. }
  47114. genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height, smask.subtype, backdrop, smask.transferMap);
  47115. ctx.drawImage(mask, 0, 0);
  47116. }
  47117. var LINE_CAP_STYLES = [
  47118. 'butt',
  47119. 'round',
  47120. 'square'
  47121. ];
  47122. var LINE_JOIN_STYLES = [
  47123. 'miter',
  47124. 'round',
  47125. 'bevel'
  47126. ];
  47127. var NORMAL_CLIP = {};
  47128. var EO_CLIP = {};
  47129. CanvasGraphics.prototype = {
  47130. beginDrawing: function CanvasGraphics_beginDrawing(transform, viewport, transparency) {
  47131. // For pdfs that use blend modes we have to clear the canvas else certain
  47132. // blend modes can look wrong since we'd be blending with a white
  47133. // backdrop. The problem with a transparent backdrop though is we then
  47134. // don't get sub pixel anti aliasing on text, creating temporary
  47135. // transparent canvas when we have blend modes.
  47136. var width = this.ctx.canvas.width;
  47137. var height = this.ctx.canvas.height;
  47138. this.ctx.save();
  47139. this.ctx.fillStyle = 'rgb(255, 255, 255)';
  47140. this.ctx.fillRect(0, 0, width, height);
  47141. this.ctx.restore();
  47142. if (transparency) {
  47143. var transparentCanvas = this.cachedCanvases.getCanvas('transparent', width, height, true);
  47144. this.compositeCtx = this.ctx;
  47145. this.transparentCanvas = transparentCanvas.canvas;
  47146. this.ctx = transparentCanvas.context;
  47147. this.ctx.save();
  47148. // The transform can be applied before rendering, transferring it to
  47149. // the new canvas.
  47150. this.ctx.transform.apply(this.ctx, this.compositeCtx.mozCurrentTransform);
  47151. }
  47152. this.ctx.save();
  47153. if (transform) {
  47154. this.ctx.transform.apply(this.ctx, transform);
  47155. }
  47156. this.ctx.transform.apply(this.ctx, viewport.transform);
  47157. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  47158. if (this.imageLayer) {
  47159. this.imageLayer.beginLayout();
  47160. }
  47161. },
  47162. executeOperatorList: function CanvasGraphics_executeOperatorList(operatorList, executionStartIdx, continueCallback, stepper) {
  47163. var argsArray = operatorList.argsArray;
  47164. var fnArray = operatorList.fnArray;
  47165. var i = executionStartIdx || 0;
  47166. var argsArrayLen = argsArray.length;
  47167. // Sometimes the OperatorList to execute is empty.
  47168. if (argsArrayLen === i) {
  47169. return i;
  47170. }
  47171. var chunkOperations = argsArrayLen - i > EXECUTION_STEPS && typeof continueCallback === 'function';
  47172. var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  47173. var steps = 0;
  47174. var commonObjs = this.commonObjs;
  47175. var objs = this.objs;
  47176. var fnId;
  47177. while (true) {
  47178. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  47179. stepper.breakIt(i, continueCallback);
  47180. return i;
  47181. }
  47182. fnId = fnArray[i];
  47183. if (fnId !== OPS.dependency) {
  47184. this[fnId].apply(this, argsArray[i]);
  47185. } else {
  47186. var deps = argsArray[i];
  47187. for (var n = 0, nn = deps.length; n < nn; n++) {
  47188. var depObjId = deps[n];
  47189. var common = depObjId[0] === 'g' && depObjId[1] === '_';
  47190. var objsPool = common ? commonObjs : objs;
  47191. // If the promise isn't resolved yet, add the continueCallback
  47192. // to the promise and bail out.
  47193. if (!objsPool.isResolved(depObjId)) {
  47194. objsPool.get(depObjId, continueCallback);
  47195. return i;
  47196. }
  47197. }
  47198. }
  47199. i++;
  47200. // If the entire operatorList was executed, stop as were done.
  47201. if (i === argsArrayLen) {
  47202. return i;
  47203. }
  47204. // If the execution took longer then a certain amount of time and
  47205. // `continueCallback` is specified, interrupt the execution.
  47206. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  47207. if (Date.now() > endTime) {
  47208. continueCallback();
  47209. return i;
  47210. }
  47211. steps = 0;
  47212. }
  47213. }
  47214. },
  47215. // If the operatorList isn't executed completely yet OR the execution
  47216. // time was short enough, do another execution round.
  47217. endDrawing: function CanvasGraphics_endDrawing() {
  47218. // Finishing all opened operations such as SMask group painting.
  47219. if (this.current.activeSMask !== null) {
  47220. this.endSMaskGroup();
  47221. }
  47222. this.ctx.restore();
  47223. if (this.transparentCanvas) {
  47224. this.ctx = this.compositeCtx;
  47225. this.ctx.save();
  47226. this.ctx.setTransform(1, 0, 0, 1, 0, 0);
  47227. // Avoid apply transform twice
  47228. this.ctx.drawImage(this.transparentCanvas, 0, 0);
  47229. this.ctx.restore();
  47230. this.transparentCanvas = null;
  47231. }
  47232. this.cachedCanvases.clear();
  47233. WebGLUtils.clear();
  47234. if (this.imageLayer) {
  47235. this.imageLayer.endLayout();
  47236. }
  47237. },
  47238. // Graphics state
  47239. setLineWidth: function CanvasGraphics_setLineWidth(width) {
  47240. this.current.lineWidth = width;
  47241. this.ctx.lineWidth = width;
  47242. },
  47243. setLineCap: function CanvasGraphics_setLineCap(style) {
  47244. this.ctx.lineCap = LINE_CAP_STYLES[style];
  47245. },
  47246. setLineJoin: function CanvasGraphics_setLineJoin(style) {
  47247. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  47248. },
  47249. setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
  47250. this.ctx.miterLimit = limit;
  47251. },
  47252. setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
  47253. var ctx = this.ctx;
  47254. if (ctx.setLineDash !== undefined) {
  47255. ctx.setLineDash(dashArray);
  47256. ctx.lineDashOffset = dashPhase;
  47257. }
  47258. },
  47259. setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {
  47260. },
  47261. setFlatness: function CanvasGraphics_setFlatness(flatness) {
  47262. },
  47263. setGState: function CanvasGraphics_setGState(states) {
  47264. for (var i = 0, ii = states.length; i < ii; i++) {
  47265. var state = states[i];
  47266. var key = state[0];
  47267. var value = state[1];
  47268. switch (key) {
  47269. case 'LW':
  47270. this.setLineWidth(value);
  47271. break;
  47272. case 'LC':
  47273. this.setLineCap(value);
  47274. break;
  47275. case 'LJ':
  47276. this.setLineJoin(value);
  47277. break;
  47278. case 'ML':
  47279. this.setMiterLimit(value);
  47280. break;
  47281. case 'D':
  47282. this.setDash(value[0], value[1]);
  47283. break;
  47284. case 'RI':
  47285. this.setRenderingIntent(value);
  47286. break;
  47287. case 'FL':
  47288. this.setFlatness(value);
  47289. break;
  47290. case 'Font':
  47291. this.setFont(value[0], value[1]);
  47292. break;
  47293. case 'CA':
  47294. this.current.strokeAlpha = state[1];
  47295. break;
  47296. case 'ca':
  47297. this.current.fillAlpha = state[1];
  47298. this.ctx.globalAlpha = state[1];
  47299. break;
  47300. case 'BM':
  47301. if (value && value.name && value.name !== 'Normal') {
  47302. var mode = value.name.replace(/([A-Z])/g, function (c) {
  47303. return '-' + c.toLowerCase();
  47304. }).substring(1);
  47305. this.ctx.globalCompositeOperation = mode;
  47306. if (this.ctx.globalCompositeOperation !== mode) {
  47307. warn('globalCompositeOperation "' + mode + '" is not supported');
  47308. }
  47309. } else {
  47310. this.ctx.globalCompositeOperation = 'source-over';
  47311. }
  47312. break;
  47313. case 'SMask':
  47314. if (this.current.activeSMask) {
  47315. // If SMask is currrenly used, it needs to be suspended or
  47316. // finished. Suspend only makes sense when at least one save()
  47317. // was performed and state needs to be reverted on restore().
  47318. if (this.stateStack.length > 0 && this.stateStack[this.stateStack.length - 1].activeSMask === this.current.activeSMask) {
  47319. this.suspendSMaskGroup();
  47320. } else {
  47321. this.endSMaskGroup();
  47322. }
  47323. }
  47324. this.current.activeSMask = value ? this.tempSMask : null;
  47325. if (this.current.activeSMask) {
  47326. this.beginSMaskGroup();
  47327. }
  47328. this.tempSMask = null;
  47329. break;
  47330. }
  47331. }
  47332. },
  47333. beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
  47334. var activeSMask = this.current.activeSMask;
  47335. var drawnWidth = activeSMask.canvas.width;
  47336. var drawnHeight = activeSMask.canvas.height;
  47337. var cacheId = 'smaskGroupAt' + this.groupLevel;
  47338. var scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight, true);
  47339. var currentCtx = this.ctx;
  47340. var currentTransform = currentCtx.mozCurrentTransform;
  47341. this.ctx.save();
  47342. var groupCtx = scratchCanvas.context;
  47343. groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
  47344. groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
  47345. groupCtx.transform.apply(groupCtx, currentTransform);
  47346. activeSMask.startTransformInverse = groupCtx.mozCurrentTransformInverse;
  47347. copyCtxState(currentCtx, groupCtx);
  47348. this.ctx = groupCtx;
  47349. this.setGState([
  47350. [
  47351. 'BM',
  47352. 'Normal'
  47353. ],
  47354. [
  47355. 'ca',
  47356. 1
  47357. ],
  47358. [
  47359. 'CA',
  47360. 1
  47361. ]
  47362. ]);
  47363. this.groupStack.push(currentCtx);
  47364. this.groupLevel++;
  47365. },
  47366. suspendSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  47367. // Similar to endSMaskGroup, the intermediate canvas has to be composed
  47368. // and future ctx state restored.
  47369. var groupCtx = this.ctx;
  47370. this.groupLevel--;
  47371. this.ctx = this.groupStack.pop();
  47372. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  47373. this.ctx.restore();
  47374. this.ctx.save();
  47375. // save is needed since SMask will be resumed.
  47376. copyCtxState(groupCtx, this.ctx);
  47377. // Saving state for resuming.
  47378. this.current.resumeSMaskCtx = groupCtx;
  47379. // Transform was changed in the SMask canvas, reflecting this change on
  47380. // this.ctx.
  47381. var deltaTransform = Util.transform(this.current.activeSMask.startTransformInverse, groupCtx.mozCurrentTransform);
  47382. this.ctx.transform.apply(this.ctx, deltaTransform);
  47383. // SMask was composed, the results at the groupCtx can be cleared.
  47384. groupCtx.save();
  47385. groupCtx.setTransform(1, 0, 0, 1, 0, 0);
  47386. groupCtx.clearRect(0, 0, groupCtx.canvas.width, groupCtx.canvas.height);
  47387. groupCtx.restore();
  47388. },
  47389. resumeSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  47390. // Resuming state saved by suspendSMaskGroup. We don't need to restore
  47391. // any groupCtx state since restore() command (the only caller) will do
  47392. // that for us. See also beginSMaskGroup.
  47393. var groupCtx = this.current.resumeSMaskCtx;
  47394. var currentCtx = this.ctx;
  47395. this.ctx = groupCtx;
  47396. this.groupStack.push(currentCtx);
  47397. this.groupLevel++;
  47398. },
  47399. endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  47400. var groupCtx = this.ctx;
  47401. this.groupLevel--;
  47402. this.ctx = this.groupStack.pop();
  47403. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  47404. this.ctx.restore();
  47405. copyCtxState(groupCtx, this.ctx);
  47406. // Transform was changed in the SMask canvas, reflecting this change on
  47407. // this.ctx.
  47408. var deltaTransform = Util.transform(this.current.activeSMask.startTransformInverse, groupCtx.mozCurrentTransform);
  47409. this.ctx.transform.apply(this.ctx, deltaTransform);
  47410. },
  47411. save: function CanvasGraphics_save() {
  47412. this.ctx.save();
  47413. var old = this.current;
  47414. this.stateStack.push(old);
  47415. this.current = old.clone();
  47416. this.current.resumeSMaskCtx = null;
  47417. },
  47418. restore: function CanvasGraphics_restore() {
  47419. // SMask was suspended, we just need to resume it.
  47420. if (this.current.resumeSMaskCtx) {
  47421. this.resumeSMaskGroup();
  47422. }
  47423. // SMask has to be finished once there is no states that are using the
  47424. // same SMask.
  47425. if (this.current.activeSMask !== null && (this.stateStack.length === 0 || this.stateStack[this.stateStack.length - 1].activeSMask !== this.current.activeSMask)) {
  47426. this.endSMaskGroup();
  47427. }
  47428. if (this.stateStack.length !== 0) {
  47429. this.current = this.stateStack.pop();
  47430. this.ctx.restore();
  47431. // Ensure that the clipping path is reset (fixes issue6413.pdf).
  47432. this.pendingClip = null;
  47433. this.cachedGetSinglePixelWidth = null;
  47434. }
  47435. },
  47436. transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
  47437. this.ctx.transform(a, b, c, d, e, f);
  47438. this.cachedGetSinglePixelWidth = null;
  47439. },
  47440. // Path
  47441. constructPath: function CanvasGraphics_constructPath(ops, args) {
  47442. var ctx = this.ctx;
  47443. var current = this.current;
  47444. var x = current.x, y = current.y;
  47445. for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
  47446. switch (ops[i] | 0) {
  47447. case OPS.rectangle:
  47448. x = args[j++];
  47449. y = args[j++];
  47450. var width = args[j++];
  47451. var height = args[j++];
  47452. if (width === 0) {
  47453. width = this.getSinglePixelWidth();
  47454. }
  47455. if (height === 0) {
  47456. height = this.getSinglePixelWidth();
  47457. }
  47458. var xw = x + width;
  47459. var yh = y + height;
  47460. this.ctx.moveTo(x, y);
  47461. this.ctx.lineTo(xw, y);
  47462. this.ctx.lineTo(xw, yh);
  47463. this.ctx.lineTo(x, yh);
  47464. this.ctx.lineTo(x, y);
  47465. this.ctx.closePath();
  47466. break;
  47467. case OPS.moveTo:
  47468. x = args[j++];
  47469. y = args[j++];
  47470. ctx.moveTo(x, y);
  47471. break;
  47472. case OPS.lineTo:
  47473. x = args[j++];
  47474. y = args[j++];
  47475. ctx.lineTo(x, y);
  47476. break;
  47477. case OPS.curveTo:
  47478. x = args[j + 4];
  47479. y = args[j + 5];
  47480. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3], x, y);
  47481. j += 6;
  47482. break;
  47483. case OPS.curveTo2:
  47484. ctx.bezierCurveTo(x, y, args[j], args[j + 1], args[j + 2], args[j + 3]);
  47485. x = args[j + 2];
  47486. y = args[j + 3];
  47487. j += 4;
  47488. break;
  47489. case OPS.curveTo3:
  47490. x = args[j + 2];
  47491. y = args[j + 3];
  47492. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  47493. j += 4;
  47494. break;
  47495. case OPS.closePath:
  47496. ctx.closePath();
  47497. break;
  47498. }
  47499. }
  47500. current.setCurrentPoint(x, y);
  47501. },
  47502. closePath: function CanvasGraphics_closePath() {
  47503. this.ctx.closePath();
  47504. },
  47505. stroke: function CanvasGraphics_stroke(consumePath) {
  47506. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  47507. var ctx = this.ctx;
  47508. var strokeColor = this.current.strokeColor;
  47509. // Prevent drawing too thin lines by enforcing a minimum line width.
  47510. ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR, this.current.lineWidth);
  47511. // For stroke we want to temporarily change the global alpha to the
  47512. // stroking alpha.
  47513. ctx.globalAlpha = this.current.strokeAlpha;
  47514. if (strokeColor && strokeColor.hasOwnProperty('type') && strokeColor.type === 'Pattern') {
  47515. // for patterns, we transform to pattern space, calculate
  47516. // the pattern, call stroke, and restore to user space
  47517. ctx.save();
  47518. ctx.strokeStyle = strokeColor.getPattern(ctx, this);
  47519. ctx.stroke();
  47520. ctx.restore();
  47521. } else {
  47522. ctx.stroke();
  47523. }
  47524. if (consumePath) {
  47525. this.consumePath();
  47526. }
  47527. // Restore the global alpha to the fill alpha
  47528. ctx.globalAlpha = this.current.fillAlpha;
  47529. },
  47530. closeStroke: function CanvasGraphics_closeStroke() {
  47531. this.closePath();
  47532. this.stroke();
  47533. },
  47534. fill: function CanvasGraphics_fill(consumePath) {
  47535. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  47536. var ctx = this.ctx;
  47537. var fillColor = this.current.fillColor;
  47538. var isPatternFill = this.current.patternFill;
  47539. var needRestore = false;
  47540. if (isPatternFill) {
  47541. ctx.save();
  47542. if (this.baseTransform) {
  47543. ctx.setTransform.apply(ctx, this.baseTransform);
  47544. }
  47545. ctx.fillStyle = fillColor.getPattern(ctx, this);
  47546. needRestore = true;
  47547. }
  47548. if (this.pendingEOFill) {
  47549. if (ctx.mozFillRule !== undefined) {
  47550. ctx.mozFillRule = 'evenodd';
  47551. ctx.fill();
  47552. ctx.mozFillRule = 'nonzero';
  47553. } else {
  47554. ctx.fill('evenodd');
  47555. }
  47556. this.pendingEOFill = false;
  47557. } else {
  47558. ctx.fill();
  47559. }
  47560. if (needRestore) {
  47561. ctx.restore();
  47562. }
  47563. if (consumePath) {
  47564. this.consumePath();
  47565. }
  47566. },
  47567. eoFill: function CanvasGraphics_eoFill() {
  47568. this.pendingEOFill = true;
  47569. this.fill();
  47570. },
  47571. fillStroke: function CanvasGraphics_fillStroke() {
  47572. this.fill(false);
  47573. this.stroke(false);
  47574. this.consumePath();
  47575. },
  47576. eoFillStroke: function CanvasGraphics_eoFillStroke() {
  47577. this.pendingEOFill = true;
  47578. this.fillStroke();
  47579. },
  47580. closeFillStroke: function CanvasGraphics_closeFillStroke() {
  47581. this.closePath();
  47582. this.fillStroke();
  47583. },
  47584. closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
  47585. this.pendingEOFill = true;
  47586. this.closePath();
  47587. this.fillStroke();
  47588. },
  47589. endPath: function CanvasGraphics_endPath() {
  47590. this.consumePath();
  47591. },
  47592. // Clipping
  47593. clip: function CanvasGraphics_clip() {
  47594. this.pendingClip = NORMAL_CLIP;
  47595. },
  47596. eoClip: function CanvasGraphics_eoClip() {
  47597. this.pendingClip = EO_CLIP;
  47598. },
  47599. // Text
  47600. beginText: function CanvasGraphics_beginText() {
  47601. this.current.textMatrix = IDENTITY_MATRIX;
  47602. this.current.textMatrixScale = 1;
  47603. this.current.x = this.current.lineX = 0;
  47604. this.current.y = this.current.lineY = 0;
  47605. },
  47606. endText: function CanvasGraphics_endText() {
  47607. var paths = this.pendingTextPaths;
  47608. var ctx = this.ctx;
  47609. if (paths === undefined) {
  47610. ctx.beginPath();
  47611. return;
  47612. }
  47613. ctx.save();
  47614. ctx.beginPath();
  47615. for (var i = 0; i < paths.length; i++) {
  47616. var path = paths[i];
  47617. ctx.setTransform.apply(ctx, path.transform);
  47618. ctx.translate(path.x, path.y);
  47619. path.addToPath(ctx, path.fontSize);
  47620. }
  47621. ctx.restore();
  47622. ctx.clip();
  47623. ctx.beginPath();
  47624. delete this.pendingTextPaths;
  47625. },
  47626. setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
  47627. this.current.charSpacing = spacing;
  47628. },
  47629. setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
  47630. this.current.wordSpacing = spacing;
  47631. },
  47632. setHScale: function CanvasGraphics_setHScale(scale) {
  47633. this.current.textHScale = scale / 100;
  47634. },
  47635. setLeading: function CanvasGraphics_setLeading(leading) {
  47636. this.current.leading = -leading;
  47637. },
  47638. setFont: function CanvasGraphics_setFont(fontRefName, size) {
  47639. var fontObj = this.commonObjs.get(fontRefName);
  47640. var current = this.current;
  47641. if (!fontObj) {
  47642. error('Can\'t find font for ' + fontRefName);
  47643. }
  47644. current.fontMatrix = fontObj.fontMatrix ? fontObj.fontMatrix : FONT_IDENTITY_MATRIX;
  47645. // A valid matrix needs all main diagonal elements to be non-zero
  47646. // This also ensures we bypass FF bugzilla bug #719844.
  47647. if (current.fontMatrix[0] === 0 || current.fontMatrix[3] === 0) {
  47648. warn('Invalid font matrix for font ' + fontRefName);
  47649. }
  47650. // The spec for Tf (setFont) says that 'size' specifies the font 'scale',
  47651. // and in some docs this can be negative (inverted x-y axes).
  47652. if (size < 0) {
  47653. size = -size;
  47654. current.fontDirection = -1;
  47655. } else {
  47656. current.fontDirection = 1;
  47657. }
  47658. this.current.font = fontObj;
  47659. this.current.fontSize = size;
  47660. if (fontObj.isType3Font) {
  47661. return;
  47662. }
  47663. // we don't need ctx.font for Type3 fonts
  47664. var name = fontObj.loadedName || 'sans-serif';
  47665. var bold = fontObj.black ? fontObj.bold ? '900' : 'bold' : fontObj.bold ? 'bold' : 'normal';
  47666. var italic = fontObj.italic ? 'italic' : 'normal';
  47667. var typeface = '"' + name + '", ' + fontObj.fallbackName;
  47668. // Some font backends cannot handle fonts below certain size.
  47669. // Keeping the font at minimal size and using the fontSizeScale to change
  47670. // the current transformation matrix before the fillText/strokeText.
  47671. // See https://bugzilla.mozilla.org/show_bug.cgi?id=726227
  47672. var browserFontSize = size < MIN_FONT_SIZE ? MIN_FONT_SIZE : size > MAX_FONT_SIZE ? MAX_FONT_SIZE : size;
  47673. this.current.fontSizeScale = size / browserFontSize;
  47674. var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
  47675. this.ctx.font = rule;
  47676. },
  47677. setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
  47678. this.current.textRenderingMode = mode;
  47679. },
  47680. setTextRise: function CanvasGraphics_setTextRise(rise) {
  47681. this.current.textRise = rise;
  47682. },
  47683. moveText: function CanvasGraphics_moveText(x, y) {
  47684. this.current.x = this.current.lineX += x;
  47685. this.current.y = this.current.lineY += y;
  47686. },
  47687. setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
  47688. this.setLeading(-y);
  47689. this.moveText(x, y);
  47690. },
  47691. setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
  47692. this.current.textMatrix = [
  47693. a,
  47694. b,
  47695. c,
  47696. d,
  47697. e,
  47698. f
  47699. ];
  47700. this.current.textMatrixScale = Math.sqrt(a * a + b * b);
  47701. this.current.x = this.current.lineX = 0;
  47702. this.current.y = this.current.lineY = 0;
  47703. },
  47704. nextLine: function CanvasGraphics_nextLine() {
  47705. this.moveText(0, this.current.leading);
  47706. },
  47707. paintChar: function CanvasGraphics_paintChar(character, x, y) {
  47708. var ctx = this.ctx;
  47709. var current = this.current;
  47710. var font = current.font;
  47711. var textRenderingMode = current.textRenderingMode;
  47712. var fontSize = current.fontSize / current.fontSizeScale;
  47713. var fillStrokeMode = textRenderingMode & TextRenderingMode.FILL_STROKE_MASK;
  47714. var isAddToPathSet = !!(textRenderingMode & TextRenderingMode.ADD_TO_PATH_FLAG);
  47715. var addToPath;
  47716. if (font.disableFontFace || isAddToPathSet) {
  47717. addToPath = font.getPathGenerator(this.commonObjs, character);
  47718. }
  47719. if (font.disableFontFace) {
  47720. ctx.save();
  47721. ctx.translate(x, y);
  47722. ctx.beginPath();
  47723. addToPath(ctx, fontSize);
  47724. if (fillStrokeMode === TextRenderingMode.FILL || fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  47725. ctx.fill();
  47726. }
  47727. if (fillStrokeMode === TextRenderingMode.STROKE || fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  47728. ctx.stroke();
  47729. }
  47730. ctx.restore();
  47731. } else {
  47732. if (fillStrokeMode === TextRenderingMode.FILL || fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  47733. ctx.fillText(character, x, y);
  47734. }
  47735. if (fillStrokeMode === TextRenderingMode.STROKE || fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  47736. ctx.strokeText(character, x, y);
  47737. }
  47738. }
  47739. if (isAddToPathSet) {
  47740. var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  47741. paths.push({
  47742. transform: ctx.mozCurrentTransform,
  47743. x: x,
  47744. y: y,
  47745. fontSize: fontSize,
  47746. addToPath: addToPath
  47747. });
  47748. }
  47749. },
  47750. get isFontSubpixelAAEnabled() {
  47751. // Checks if anti-aliasing is enabled when scaled text is painted.
  47752. // On Windows GDI scaled fonts looks bad.
  47753. var ctx = document.createElement('canvas').getContext('2d');
  47754. ctx.scale(1.5, 1);
  47755. ctx.fillText('I', 0, 10);
  47756. var data = ctx.getImageData(0, 0, 10, 10).data;
  47757. var enabled = false;
  47758. for (var i = 3; i < data.length; i += 4) {
  47759. if (data[i] > 0 && data[i] < 255) {
  47760. enabled = true;
  47761. break;
  47762. }
  47763. }
  47764. return shadow(this, 'isFontSubpixelAAEnabled', enabled);
  47765. },
  47766. showText: function CanvasGraphics_showText(glyphs) {
  47767. var current = this.current;
  47768. var font = current.font;
  47769. if (font.isType3Font) {
  47770. return this.showType3Text(glyphs);
  47771. }
  47772. var fontSize = current.fontSize;
  47773. if (fontSize === 0) {
  47774. return;
  47775. }
  47776. var ctx = this.ctx;
  47777. var fontSizeScale = current.fontSizeScale;
  47778. var charSpacing = current.charSpacing;
  47779. var wordSpacing = current.wordSpacing;
  47780. var fontDirection = current.fontDirection;
  47781. var textHScale = current.textHScale * fontDirection;
  47782. var glyphsLength = glyphs.length;
  47783. var vertical = font.vertical;
  47784. var spacingDir = vertical ? 1 : -1;
  47785. var defaultVMetrics = font.defaultVMetrics;
  47786. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  47787. var simpleFillText = current.textRenderingMode === TextRenderingMode.FILL && !font.disableFontFace;
  47788. ctx.save();
  47789. ctx.transform.apply(ctx, current.textMatrix);
  47790. ctx.translate(current.x, current.y + current.textRise);
  47791. if (current.patternFill) {
  47792. // TODO: Some shading patterns are not applied correctly to text,
  47793. // e.g. issues 3988 and 5432, and ShowText-ShadingPattern.pdf.
  47794. ctx.fillStyle = current.fillColor.getPattern(ctx, this);
  47795. }
  47796. if (fontDirection > 0) {
  47797. ctx.scale(textHScale, -1);
  47798. } else {
  47799. ctx.scale(textHScale, 1);
  47800. }
  47801. var lineWidth = current.lineWidth;
  47802. var scale = current.textMatrixScale;
  47803. if (scale === 0 || lineWidth === 0) {
  47804. var fillStrokeMode = current.textRenderingMode & TextRenderingMode.FILL_STROKE_MASK;
  47805. if (fillStrokeMode === TextRenderingMode.STROKE || fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  47806. this.cachedGetSinglePixelWidth = null;
  47807. lineWidth = this.getSinglePixelWidth() * MIN_WIDTH_FACTOR;
  47808. }
  47809. } else {
  47810. lineWidth /= scale;
  47811. }
  47812. if (fontSizeScale !== 1.0) {
  47813. ctx.scale(fontSizeScale, fontSizeScale);
  47814. lineWidth /= fontSizeScale;
  47815. }
  47816. ctx.lineWidth = lineWidth;
  47817. var x = 0, i;
  47818. for (i = 0; i < glyphsLength; ++i) {
  47819. var glyph = glyphs[i];
  47820. if (isNum(glyph)) {
  47821. x += spacingDir * glyph * fontSize / 1000;
  47822. continue;
  47823. }
  47824. var restoreNeeded = false;
  47825. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  47826. var character = glyph.fontChar;
  47827. var accent = glyph.accent;
  47828. var scaledX, scaledY, scaledAccentX, scaledAccentY;
  47829. var width = glyph.width;
  47830. if (vertical) {
  47831. var vmetric, vx, vy;
  47832. vmetric = glyph.vmetric || defaultVMetrics;
  47833. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  47834. vx = -vx * widthAdvanceScale;
  47835. vy = vmetric[2] * widthAdvanceScale;
  47836. width = vmetric ? -vmetric[0] : width;
  47837. scaledX = vx / fontSizeScale;
  47838. scaledY = (x + vy) / fontSizeScale;
  47839. } else {
  47840. scaledX = x / fontSizeScale;
  47841. scaledY = 0;
  47842. }
  47843. if (font.remeasure && width > 0) {
  47844. // Some standard fonts may not have the exact width: rescale per
  47845. // character if measured width is greater than expected glyph width
  47846. // and subpixel-aa is enabled, otherwise just center the glyph.
  47847. var measuredWidth = ctx.measureText(character).width * 1000 / fontSize * fontSizeScale;
  47848. if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
  47849. var characterScaleX = width / measuredWidth;
  47850. restoreNeeded = true;
  47851. ctx.save();
  47852. ctx.scale(characterScaleX, 1);
  47853. scaledX /= characterScaleX;
  47854. } else if (width !== measuredWidth) {
  47855. scaledX += (width - measuredWidth) / 2000 * fontSize / fontSizeScale;
  47856. }
  47857. }
  47858. // Only attempt to draw the glyph if it is actually in the embedded font
  47859. // file or if there isn't a font file so the fallback font is shown.
  47860. if (glyph.isInFont || font.missingFile) {
  47861. if (simpleFillText && !accent) {
  47862. // common case
  47863. ctx.fillText(character, scaledX, scaledY);
  47864. } else {
  47865. this.paintChar(character, scaledX, scaledY);
  47866. if (accent) {
  47867. scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
  47868. scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
  47869. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
  47870. }
  47871. }
  47872. }
  47873. var charWidth = width * widthAdvanceScale + spacing * fontDirection;
  47874. x += charWidth;
  47875. if (restoreNeeded) {
  47876. ctx.restore();
  47877. }
  47878. }
  47879. if (vertical) {
  47880. current.y -= x * textHScale;
  47881. } else {
  47882. current.x += x * textHScale;
  47883. }
  47884. ctx.restore();
  47885. },
  47886. showType3Text: function CanvasGraphics_showType3Text(glyphs) {
  47887. // Type3 fonts - each glyph is a "mini-PDF"
  47888. var ctx = this.ctx;
  47889. var current = this.current;
  47890. var font = current.font;
  47891. var fontSize = current.fontSize;
  47892. var fontDirection = current.fontDirection;
  47893. var spacingDir = font.vertical ? 1 : -1;
  47894. var charSpacing = current.charSpacing;
  47895. var wordSpacing = current.wordSpacing;
  47896. var textHScale = current.textHScale * fontDirection;
  47897. var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX;
  47898. var glyphsLength = glyphs.length;
  47899. var isTextInvisible = current.textRenderingMode === TextRenderingMode.INVISIBLE;
  47900. var i, glyph, width, spacingLength;
  47901. if (isTextInvisible || fontSize === 0) {
  47902. return;
  47903. }
  47904. this.cachedGetSinglePixelWidth = null;
  47905. ctx.save();
  47906. ctx.transform.apply(ctx, current.textMatrix);
  47907. ctx.translate(current.x, current.y);
  47908. ctx.scale(textHScale, fontDirection);
  47909. for (i = 0; i < glyphsLength; ++i) {
  47910. glyph = glyphs[i];
  47911. if (isNum(glyph)) {
  47912. spacingLength = spacingDir * glyph * fontSize / 1000;
  47913. this.ctx.translate(spacingLength, 0);
  47914. current.x += spacingLength * textHScale;
  47915. continue;
  47916. }
  47917. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  47918. var operatorList = font.charProcOperatorList[glyph.operatorListId];
  47919. if (!operatorList) {
  47920. warn('Type3 character \"' + glyph.operatorListId + '\" is not available');
  47921. continue;
  47922. }
  47923. this.processingType3 = glyph;
  47924. this.save();
  47925. ctx.scale(fontSize, fontSize);
  47926. ctx.transform.apply(ctx, fontMatrix);
  47927. this.executeOperatorList(operatorList);
  47928. this.restore();
  47929. var transformed = Util.applyTransform([
  47930. glyph.width,
  47931. 0
  47932. ], fontMatrix);
  47933. width = transformed[0] * fontSize + spacing;
  47934. ctx.translate(width, 0);
  47935. current.x += width * textHScale;
  47936. }
  47937. ctx.restore();
  47938. this.processingType3 = null;
  47939. },
  47940. // Type3 fonts
  47941. setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {
  47942. },
  47943. setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth, yWidth, llx, lly, urx, ury) {
  47944. // TODO According to the spec we're also suppose to ignore any operators
  47945. // that set color or include images while processing this type3 font.
  47946. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  47947. this.clip();
  47948. this.endPath();
  47949. },
  47950. // Color
  47951. getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
  47952. var pattern;
  47953. if (IR[0] === 'TilingPattern') {
  47954. var color = IR[1];
  47955. var baseTransform = this.baseTransform || this.ctx.mozCurrentTransform.slice();
  47956. var self = this;
  47957. var canvasGraphicsFactory = {
  47958. createCanvasGraphics: function (ctx) {
  47959. return new CanvasGraphics(ctx, self.commonObjs, self.objs);
  47960. }
  47961. };
  47962. pattern = new TilingPattern(IR, color, this.ctx, canvasGraphicsFactory, baseTransform);
  47963. } else {
  47964. pattern = getShadingPatternFromIR(IR);
  47965. }
  47966. return pattern;
  47967. },
  47968. setStrokeColorN: function CanvasGraphics_setStrokeColorN()
  47969. /*...*/
  47970. {
  47971. this.current.strokeColor = this.getColorN_Pattern(arguments);
  47972. },
  47973. setFillColorN: function CanvasGraphics_setFillColorN()
  47974. /*...*/
  47975. {
  47976. this.current.fillColor = this.getColorN_Pattern(arguments);
  47977. this.current.patternFill = true;
  47978. },
  47979. setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
  47980. var color = Util.makeCssRgb(r, g, b);
  47981. this.ctx.strokeStyle = color;
  47982. this.current.strokeColor = color;
  47983. },
  47984. setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
  47985. var color = Util.makeCssRgb(r, g, b);
  47986. this.ctx.fillStyle = color;
  47987. this.current.fillColor = color;
  47988. this.current.patternFill = false;
  47989. },
  47990. shadingFill: function CanvasGraphics_shadingFill(patternIR) {
  47991. var ctx = this.ctx;
  47992. this.save();
  47993. var pattern = getShadingPatternFromIR(patternIR);
  47994. ctx.fillStyle = pattern.getPattern(ctx, this, true);
  47995. var inv = ctx.mozCurrentTransformInverse;
  47996. if (inv) {
  47997. var canvas = ctx.canvas;
  47998. var width = canvas.width;
  47999. var height = canvas.height;
  48000. var bl = Util.applyTransform([
  48001. 0,
  48002. 0
  48003. ], inv);
  48004. var br = Util.applyTransform([
  48005. 0,
  48006. height
  48007. ], inv);
  48008. var ul = Util.applyTransform([
  48009. width,
  48010. 0
  48011. ], inv);
  48012. var ur = Util.applyTransform([
  48013. width,
  48014. height
  48015. ], inv);
  48016. var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  48017. var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  48018. var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  48019. var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  48020. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  48021. } else {
  48022. // HACK to draw the gradient onto an infinite rectangle.
  48023. // PDF gradients are drawn across the entire image while
  48024. // Canvas only allows gradients to be drawn in a rectangle
  48025. // The following bug should allow us to remove this.
  48026. // https://bugzilla.mozilla.org/show_bug.cgi?id=664884
  48027. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  48028. }
  48029. this.restore();
  48030. },
  48031. // Images
  48032. beginInlineImage: function CanvasGraphics_beginInlineImage() {
  48033. error('Should not call beginInlineImage');
  48034. },
  48035. beginImageData: function CanvasGraphics_beginImageData() {
  48036. error('Should not call beginImageData');
  48037. },
  48038. paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix, bbox) {
  48039. this.save();
  48040. this.baseTransformStack.push(this.baseTransform);
  48041. if (isArray(matrix) && 6 === matrix.length) {
  48042. this.transform.apply(this, matrix);
  48043. }
  48044. this.baseTransform = this.ctx.mozCurrentTransform;
  48045. if (isArray(bbox) && 4 === bbox.length) {
  48046. var width = bbox[2] - bbox[0];
  48047. var height = bbox[3] - bbox[1];
  48048. this.ctx.rect(bbox[0], bbox[1], width, height);
  48049. this.clip();
  48050. this.endPath();
  48051. }
  48052. },
  48053. paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
  48054. this.restore();
  48055. this.baseTransform = this.baseTransformStack.pop();
  48056. },
  48057. beginGroup: function CanvasGraphics_beginGroup(group) {
  48058. this.save();
  48059. var currentCtx = this.ctx;
  48060. // TODO non-isolated groups - according to Rik at adobe non-isolated
  48061. // group results aren't usually that different and they even have tools
  48062. // that ignore this setting. Notes from Rik on implementing:
  48063. // - When you encounter an transparency group, create a new canvas with
  48064. // the dimensions of the bbox
  48065. // - copy the content from the previous canvas to the new canvas
  48066. // - draw as usual
  48067. // - remove the backdrop alpha:
  48068. // alphaNew = 1 - (1 - alpha)/(1 - alphaBackdrop) with 'alpha' the alpha
  48069. // value of your transparency group and 'alphaBackdrop' the alpha of the
  48070. // backdrop
  48071. // - remove background color:
  48072. // colorNew = color - alphaNew *colorBackdrop /(1 - alphaNew)
  48073. if (!group.isolated) {
  48074. info('TODO: Support non-isolated groups.');
  48075. }
  48076. // TODO knockout - supposedly possible with the clever use of compositing
  48077. // modes.
  48078. if (group.knockout) {
  48079. warn('Knockout groups not supported.');
  48080. }
  48081. var currentTransform = currentCtx.mozCurrentTransform;
  48082. if (group.matrix) {
  48083. currentCtx.transform.apply(currentCtx, group.matrix);
  48084. }
  48085. assert(group.bbox, 'Bounding box is required.');
  48086. // Based on the current transform figure out how big the bounding box
  48087. // will actually be.
  48088. var bounds = Util.getAxialAlignedBoundingBox(group.bbox, currentCtx.mozCurrentTransform);
  48089. // Clip the bounding box to the current canvas.
  48090. var canvasBounds = [
  48091. 0,
  48092. 0,
  48093. currentCtx.canvas.width,
  48094. currentCtx.canvas.height
  48095. ];
  48096. bounds = Util.intersect(bounds, canvasBounds) || [
  48097. 0,
  48098. 0,
  48099. 0,
  48100. 0
  48101. ];
  48102. // Use ceil in case we're between sizes so we don't create canvas that is
  48103. // too small and make the canvas at least 1x1 pixels.
  48104. var offsetX = Math.floor(bounds[0]);
  48105. var offsetY = Math.floor(bounds[1]);
  48106. var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  48107. var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  48108. var scaleX = 1, scaleY = 1;
  48109. if (drawnWidth > MAX_GROUP_SIZE) {
  48110. scaleX = drawnWidth / MAX_GROUP_SIZE;
  48111. drawnWidth = MAX_GROUP_SIZE;
  48112. }
  48113. if (drawnHeight > MAX_GROUP_SIZE) {
  48114. scaleY = drawnHeight / MAX_GROUP_SIZE;
  48115. drawnHeight = MAX_GROUP_SIZE;
  48116. }
  48117. var cacheId = 'groupAt' + this.groupLevel;
  48118. if (group.smask) {
  48119. // Using two cache entries is case if masks are used one after another.
  48120. cacheId += '_smask_' + this.smaskCounter++ % 2;
  48121. }
  48122. var scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight, true);
  48123. var groupCtx = scratchCanvas.context;
  48124. // Since we created a new canvas that is just the size of the bounding box
  48125. // we have to translate the group ctx.
  48126. groupCtx.scale(1 / scaleX, 1 / scaleY);
  48127. groupCtx.translate(-offsetX, -offsetY);
  48128. groupCtx.transform.apply(groupCtx, currentTransform);
  48129. if (group.smask) {
  48130. // Saving state and cached mask to be used in setGState.
  48131. this.smaskStack.push({
  48132. canvas: scratchCanvas.canvas,
  48133. context: groupCtx,
  48134. offsetX: offsetX,
  48135. offsetY: offsetY,
  48136. scaleX: scaleX,
  48137. scaleY: scaleY,
  48138. subtype: group.smask.subtype,
  48139. backdrop: group.smask.backdrop,
  48140. transferMap: group.smask.transferMap || null,
  48141. startTransformInverse: null
  48142. });
  48143. } else
  48144. // used during suspend operation
  48145. {
  48146. // Setup the current ctx so when the group is popped we draw it at the
  48147. // right location.
  48148. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  48149. currentCtx.translate(offsetX, offsetY);
  48150. currentCtx.scale(scaleX, scaleY);
  48151. }
  48152. // The transparency group inherits all off the current graphics state
  48153. // except the blend mode, soft mask, and alpha constants.
  48154. copyCtxState(currentCtx, groupCtx);
  48155. this.ctx = groupCtx;
  48156. this.setGState([
  48157. [
  48158. 'BM',
  48159. 'Normal'
  48160. ],
  48161. [
  48162. 'ca',
  48163. 1
  48164. ],
  48165. [
  48166. 'CA',
  48167. 1
  48168. ]
  48169. ]);
  48170. this.groupStack.push(currentCtx);
  48171. this.groupLevel++;
  48172. // Reseting mask state, masks will be applied on restore of the group.
  48173. this.current.activeSMask = null;
  48174. },
  48175. endGroup: function CanvasGraphics_endGroup(group) {
  48176. this.groupLevel--;
  48177. var groupCtx = this.ctx;
  48178. this.ctx = this.groupStack.pop();
  48179. // Turn off image smoothing to avoid sub pixel interpolation which can
  48180. // look kind of blurry for some pdfs.
  48181. if (this.ctx.imageSmoothingEnabled !== undefined) {
  48182. this.ctx.imageSmoothingEnabled = false;
  48183. } else {
  48184. this.ctx.mozImageSmoothingEnabled = false;
  48185. }
  48186. if (group.smask) {
  48187. this.tempSMask = this.smaskStack.pop();
  48188. } else {
  48189. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  48190. }
  48191. this.restore();
  48192. },
  48193. beginAnnotations: function CanvasGraphics_beginAnnotations() {
  48194. this.save();
  48195. this.current = new CanvasExtraState();
  48196. if (this.baseTransform) {
  48197. this.ctx.setTransform.apply(this.ctx, this.baseTransform);
  48198. }
  48199. },
  48200. endAnnotations: function CanvasGraphics_endAnnotations() {
  48201. this.restore();
  48202. },
  48203. beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform, matrix) {
  48204. this.save();
  48205. if (isArray(rect) && 4 === rect.length) {
  48206. var width = rect[2] - rect[0];
  48207. var height = rect[3] - rect[1];
  48208. this.ctx.rect(rect[0], rect[1], width, height);
  48209. this.clip();
  48210. this.endPath();
  48211. }
  48212. this.transform.apply(this, transform);
  48213. this.transform.apply(this, matrix);
  48214. },
  48215. endAnnotation: function CanvasGraphics_endAnnotation() {
  48216. this.restore();
  48217. },
  48218. paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
  48219. var domImage = this.objs.get(objId);
  48220. if (!domImage) {
  48221. warn('Dependent image isn\'t ready yet');
  48222. return;
  48223. }
  48224. this.save();
  48225. var ctx = this.ctx;
  48226. // scale the image to the unit square
  48227. ctx.scale(1 / w, -1 / h);
  48228. ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height, 0, -h, w, h);
  48229. if (this.imageLayer) {
  48230. var currentTransform = ctx.mozCurrentTransformInverse;
  48231. var position = this.getCanvasPosition(0, 0);
  48232. this.imageLayer.appendImage({
  48233. objId: objId,
  48234. left: position[0],
  48235. top: position[1],
  48236. width: w / currentTransform[0],
  48237. height: h / currentTransform[3]
  48238. });
  48239. }
  48240. this.restore();
  48241. },
  48242. paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
  48243. var ctx = this.ctx;
  48244. var width = img.width, height = img.height;
  48245. var fillColor = this.current.fillColor;
  48246. var isPatternFill = this.current.patternFill;
  48247. var glyph = this.processingType3;
  48248. if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) {
  48249. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  48250. glyph.compiled = compileType3Glyph({
  48251. data: img.data,
  48252. width: width,
  48253. height: height
  48254. });
  48255. } else {
  48256. glyph.compiled = null;
  48257. }
  48258. }
  48259. if (glyph && glyph.compiled) {
  48260. glyph.compiled(ctx);
  48261. return;
  48262. }
  48263. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas', width, height);
  48264. var maskCtx = maskCanvas.context;
  48265. maskCtx.save();
  48266. putBinaryImageMask(maskCtx, img);
  48267. maskCtx.globalCompositeOperation = 'source-in';
  48268. maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor;
  48269. maskCtx.fillRect(0, 0, width, height);
  48270. maskCtx.restore();
  48271. this.paintInlineImageXObject(maskCanvas.canvas);
  48272. },
  48273. paintImageMaskXObjectRepeat: function CanvasGraphics_paintImageMaskXObjectRepeat(imgData, scaleX, scaleY, positions) {
  48274. var width = imgData.width;
  48275. var height = imgData.height;
  48276. var fillColor = this.current.fillColor;
  48277. var isPatternFill = this.current.patternFill;
  48278. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas', width, height);
  48279. var maskCtx = maskCanvas.context;
  48280. maskCtx.save();
  48281. putBinaryImageMask(maskCtx, imgData);
  48282. maskCtx.globalCompositeOperation = 'source-in';
  48283. maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor;
  48284. maskCtx.fillRect(0, 0, width, height);
  48285. maskCtx.restore();
  48286. var ctx = this.ctx;
  48287. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  48288. ctx.save();
  48289. ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]);
  48290. ctx.scale(1, -1);
  48291. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height, 0, -1, 1, 1);
  48292. ctx.restore();
  48293. }
  48294. },
  48295. paintImageMaskXObjectGroup: function CanvasGraphics_paintImageMaskXObjectGroup(images) {
  48296. var ctx = this.ctx;
  48297. var fillColor = this.current.fillColor;
  48298. var isPatternFill = this.current.patternFill;
  48299. for (var i = 0, ii = images.length; i < ii; i++) {
  48300. var image = images[i];
  48301. var width = image.width, height = image.height;
  48302. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas', width, height);
  48303. var maskCtx = maskCanvas.context;
  48304. maskCtx.save();
  48305. putBinaryImageMask(maskCtx, image);
  48306. maskCtx.globalCompositeOperation = 'source-in';
  48307. maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor;
  48308. maskCtx.fillRect(0, 0, width, height);
  48309. maskCtx.restore();
  48310. ctx.save();
  48311. ctx.transform.apply(ctx, image.transform);
  48312. ctx.scale(1, -1);
  48313. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height, 0, -1, 1, 1);
  48314. ctx.restore();
  48315. }
  48316. },
  48317. paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
  48318. var imgData = this.objs.get(objId);
  48319. if (!imgData) {
  48320. warn('Dependent image isn\'t ready yet');
  48321. return;
  48322. }
  48323. this.paintInlineImageXObject(imgData);
  48324. },
  48325. paintImageXObjectRepeat: function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY, positions) {
  48326. var imgData = this.objs.get(objId);
  48327. if (!imgData) {
  48328. warn('Dependent image isn\'t ready yet');
  48329. return;
  48330. }
  48331. var width = imgData.width;
  48332. var height = imgData.height;
  48333. var map = [];
  48334. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  48335. map.push({
  48336. transform: [
  48337. scaleX,
  48338. 0,
  48339. 0,
  48340. scaleY,
  48341. positions[i],
  48342. positions[i + 1]
  48343. ],
  48344. x: 0,
  48345. y: 0,
  48346. w: width,
  48347. h: height
  48348. });
  48349. }
  48350. this.paintInlineImageXObjectGroup(imgData, map);
  48351. },
  48352. paintInlineImageXObject: function CanvasGraphics_paintInlineImageXObject(imgData) {
  48353. var width = imgData.width;
  48354. var height = imgData.height;
  48355. var ctx = this.ctx;
  48356. this.save();
  48357. // scale the image to the unit square
  48358. ctx.scale(1 / width, -1 / height);
  48359. var currentTransform = ctx.mozCurrentTransformInverse;
  48360. var a = currentTransform[0], b = currentTransform[1];
  48361. var widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
  48362. var c = currentTransform[2], d = currentTransform[3];
  48363. var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
  48364. var imgToPaint, tmpCanvas;
  48365. // instanceof HTMLElement does not work in jsdom node.js module
  48366. if (imgData instanceof HTMLElement || !imgData.data) {
  48367. imgToPaint = imgData;
  48368. } else {
  48369. tmpCanvas = this.cachedCanvases.getCanvas('inlineImage', width, height);
  48370. var tmpCtx = tmpCanvas.context;
  48371. putBinaryImageData(tmpCtx, imgData);
  48372. imgToPaint = tmpCanvas.canvas;
  48373. }
  48374. var paintWidth = width, paintHeight = height;
  48375. var tmpCanvasId = 'prescale1';
  48376. // Vertial or horizontal scaling shall not be more than 2 to not loose the
  48377. // pixels during drawImage operation, painting on the temporary canvas(es)
  48378. // that are twice smaller in size
  48379. while (widthScale > 2 && paintWidth > 1 || heightScale > 2 && paintHeight > 1) {
  48380. var newWidth = paintWidth, newHeight = paintHeight;
  48381. if (widthScale > 2 && paintWidth > 1) {
  48382. newWidth = Math.ceil(paintWidth / 2);
  48383. widthScale /= paintWidth / newWidth;
  48384. }
  48385. if (heightScale > 2 && paintHeight > 1) {
  48386. newHeight = Math.ceil(paintHeight / 2);
  48387. heightScale /= paintHeight / newHeight;
  48388. }
  48389. tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight);
  48390. tmpCtx = tmpCanvas.context;
  48391. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  48392. tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight, 0, 0, newWidth, newHeight);
  48393. imgToPaint = tmpCanvas.canvas;
  48394. paintWidth = newWidth;
  48395. paintHeight = newHeight;
  48396. tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1';
  48397. }
  48398. ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight, 0, -height, width, height);
  48399. if (this.imageLayer) {
  48400. var position = this.getCanvasPosition(0, -height);
  48401. this.imageLayer.appendImage({
  48402. imgData: imgData,
  48403. left: position[0],
  48404. top: position[1],
  48405. width: width / currentTransform[0],
  48406. height: height / currentTransform[3]
  48407. });
  48408. }
  48409. this.restore();
  48410. },
  48411. paintInlineImageXObjectGroup: function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
  48412. var ctx = this.ctx;
  48413. var w = imgData.width;
  48414. var h = imgData.height;
  48415. var tmpCanvas = this.cachedCanvases.getCanvas('inlineImage', w, h);
  48416. var tmpCtx = tmpCanvas.context;
  48417. putBinaryImageData(tmpCtx, imgData);
  48418. for (var i = 0, ii = map.length; i < ii; i++) {
  48419. var entry = map[i];
  48420. ctx.save();
  48421. ctx.transform.apply(ctx, entry.transform);
  48422. ctx.scale(1, -1);
  48423. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h, 0, -1, 1, 1);
  48424. if (this.imageLayer) {
  48425. var position = this.getCanvasPosition(entry.x, entry.y);
  48426. this.imageLayer.appendImage({
  48427. imgData: imgData,
  48428. left: position[0],
  48429. top: position[1],
  48430. width: w,
  48431. height: h
  48432. });
  48433. }
  48434. ctx.restore();
  48435. }
  48436. },
  48437. paintSolidColorImageMask: function CanvasGraphics_paintSolidColorImageMask() {
  48438. this.ctx.fillRect(0, 0, 1, 1);
  48439. },
  48440. paintXObject: function CanvasGraphics_paintXObject() {
  48441. warn('Unsupported \'paintXObject\' command.');
  48442. },
  48443. // Marked content
  48444. markPoint: function CanvasGraphics_markPoint(tag) {
  48445. },
  48446. markPointProps: function CanvasGraphics_markPointProps(tag, properties) {
  48447. },
  48448. beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {
  48449. },
  48450. beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(tag, properties) {
  48451. },
  48452. endMarkedContent: function CanvasGraphics_endMarkedContent() {
  48453. },
  48454. // Compatibility
  48455. beginCompat: function CanvasGraphics_beginCompat() {
  48456. },
  48457. endCompat: function CanvasGraphics_endCompat() {
  48458. },
  48459. // Helper functions
  48460. consumePath: function CanvasGraphics_consumePath() {
  48461. var ctx = this.ctx;
  48462. if (this.pendingClip) {
  48463. if (this.pendingClip === EO_CLIP) {
  48464. if (ctx.mozFillRule !== undefined) {
  48465. ctx.mozFillRule = 'evenodd';
  48466. ctx.clip();
  48467. ctx.mozFillRule = 'nonzero';
  48468. } else {
  48469. ctx.clip('evenodd');
  48470. }
  48471. } else {
  48472. ctx.clip();
  48473. }
  48474. this.pendingClip = null;
  48475. }
  48476. ctx.beginPath();
  48477. },
  48478. getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
  48479. if (this.cachedGetSinglePixelWidth === null) {
  48480. // NOTE: The `save` and `restore` commands used below is a workaround
  48481. // that is necessary in order to prevent `mozCurrentTransformInverse`
  48482. // from intermittently returning incorrect values in Firefox, see:
  48483. // https://github.com/mozilla/pdf.js/issues/7188.
  48484. this.ctx.save();
  48485. var inverse = this.ctx.mozCurrentTransformInverse;
  48486. this.ctx.restore();
  48487. // max of the current horizontal and vertical scale
  48488. this.cachedGetSinglePixelWidth = Math.sqrt(Math.max(inverse[0] * inverse[0] + inverse[1] * inverse[1], inverse[2] * inverse[2] + inverse[3] * inverse[3]));
  48489. }
  48490. return this.cachedGetSinglePixelWidth;
  48491. },
  48492. getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
  48493. var transform = this.ctx.mozCurrentTransform;
  48494. return [
  48495. transform[0] * x + transform[2] * y + transform[4],
  48496. transform[1] * x + transform[3] * y + transform[5]
  48497. ];
  48498. }
  48499. };
  48500. for (var op in OPS) {
  48501. CanvasGraphics.prototype[OPS[op]] = CanvasGraphics.prototype[op];
  48502. }
  48503. return CanvasGraphics;
  48504. }();
  48505. exports.CanvasGraphics = CanvasGraphics;
  48506. exports.createScratchCanvas = createScratchCanvas;
  48507. }));
  48508. (function (root, factory) {
  48509. factory(root.pdfjsCoreFunction = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCorePsParser);
  48510. }(this, function (exports, sharedUtil, corePrimitives, corePsParser) {
  48511. var error = sharedUtil.error;
  48512. var info = sharedUtil.info;
  48513. var isArray = sharedUtil.isArray;
  48514. var isBool = sharedUtil.isBool;
  48515. var isDict = corePrimitives.isDict;
  48516. var isStream = corePrimitives.isStream;
  48517. var PostScriptLexer = corePsParser.PostScriptLexer;
  48518. var PostScriptParser = corePsParser.PostScriptParser;
  48519. var PDFFunction = function PDFFunctionClosure() {
  48520. var CONSTRUCT_SAMPLED = 0;
  48521. var CONSTRUCT_INTERPOLATED = 2;
  48522. var CONSTRUCT_STICHED = 3;
  48523. var CONSTRUCT_POSTSCRIPT = 4;
  48524. return {
  48525. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps, str) {
  48526. var i, ii;
  48527. var length = 1;
  48528. for (i = 0, ii = size.length; i < ii; i++) {
  48529. length *= size[i];
  48530. }
  48531. length *= outputSize;
  48532. var array = new Array(length);
  48533. var codeSize = 0;
  48534. var codeBuf = 0;
  48535. // 32 is a valid bps so shifting won't work
  48536. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  48537. var strBytes = str.getBytes((length * bps + 7) / 8);
  48538. var strIdx = 0;
  48539. for (i = 0; i < length; i++) {
  48540. while (codeSize < bps) {
  48541. codeBuf <<= 8;
  48542. codeBuf |= strBytes[strIdx++];
  48543. codeSize += 8;
  48544. }
  48545. codeSize -= bps;
  48546. array[i] = (codeBuf >> codeSize) * sampleMul;
  48547. codeBuf &= (1 << codeSize) - 1;
  48548. }
  48549. return array;
  48550. },
  48551. getIR: function PDFFunction_getIR(xref, fn) {
  48552. var dict = fn.dict;
  48553. if (!dict) {
  48554. dict = fn;
  48555. }
  48556. var types = [
  48557. this.constructSampled,
  48558. null,
  48559. this.constructInterpolated,
  48560. this.constructStiched,
  48561. this.constructPostScript
  48562. ];
  48563. var typeNum = dict.get('FunctionType');
  48564. var typeFn = types[typeNum];
  48565. if (!typeFn) {
  48566. error('Unknown type of function');
  48567. }
  48568. return typeFn.call(this, fn, dict, xref);
  48569. },
  48570. fromIR: function PDFFunction_fromIR(IR) {
  48571. var type = IR[0];
  48572. switch (type) {
  48573. case CONSTRUCT_SAMPLED:
  48574. return this.constructSampledFromIR(IR);
  48575. case CONSTRUCT_INTERPOLATED:
  48576. return this.constructInterpolatedFromIR(IR);
  48577. case CONSTRUCT_STICHED:
  48578. return this.constructStichedFromIR(IR);
  48579. //case CONSTRUCT_POSTSCRIPT:
  48580. default:
  48581. return this.constructPostScriptFromIR(IR);
  48582. }
  48583. },
  48584. parse: function PDFFunction_parse(xref, fn) {
  48585. var IR = this.getIR(xref, fn);
  48586. return this.fromIR(IR);
  48587. },
  48588. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  48589. if (!isArray(fnObj)) {
  48590. // not an array -- parsing as regular function
  48591. return this.parse(xref, fnObj);
  48592. }
  48593. var fnArray = [];
  48594. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  48595. var obj = xref.fetchIfRef(fnObj[j]);
  48596. fnArray.push(PDFFunction.parse(xref, obj));
  48597. }
  48598. return function (src, srcOffset, dest, destOffset) {
  48599. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  48600. fnArray[i](src, srcOffset, dest, destOffset + i);
  48601. }
  48602. };
  48603. },
  48604. constructSampled: function PDFFunction_constructSampled(str, dict) {
  48605. function toMultiArray(arr) {
  48606. var inputLength = arr.length;
  48607. var out = [];
  48608. var index = 0;
  48609. for (var i = 0; i < inputLength; i += 2) {
  48610. out[index] = [
  48611. arr[i],
  48612. arr[i + 1]
  48613. ];
  48614. ++index;
  48615. }
  48616. return out;
  48617. }
  48618. var domain = dict.getArray('Domain');
  48619. var range = dict.getArray('Range');
  48620. if (!domain || !range) {
  48621. error('No domain or range');
  48622. }
  48623. var inputSize = domain.length / 2;
  48624. var outputSize = range.length / 2;
  48625. domain = toMultiArray(domain);
  48626. range = toMultiArray(range);
  48627. var size = dict.get('Size');
  48628. var bps = dict.get('BitsPerSample');
  48629. var order = dict.get('Order') || 1;
  48630. if (order !== 1) {
  48631. // No description how cubic spline interpolation works in PDF32000:2008
  48632. // As in poppler, ignoring order, linear interpolation may work as good
  48633. info('No support for cubic spline interpolation: ' + order);
  48634. }
  48635. var encode = dict.getArray('Encode');
  48636. if (!encode) {
  48637. encode = [];
  48638. for (var i = 0; i < inputSize; ++i) {
  48639. encode.push(0);
  48640. encode.push(size[i] - 1);
  48641. }
  48642. }
  48643. encode = toMultiArray(encode);
  48644. var decode = dict.getArray('Decode');
  48645. if (!decode) {
  48646. decode = range;
  48647. } else {
  48648. decode = toMultiArray(decode);
  48649. }
  48650. var samples = this.getSampleArray(size, outputSize, bps, str);
  48651. return [
  48652. CONSTRUCT_SAMPLED,
  48653. inputSize,
  48654. domain,
  48655. encode,
  48656. decode,
  48657. samples,
  48658. size,
  48659. outputSize,
  48660. Math.pow(2, bps) - 1,
  48661. range
  48662. ];
  48663. },
  48664. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  48665. // See chapter 3, page 109 of the PDF reference
  48666. function interpolate(x, xmin, xmax, ymin, ymax) {
  48667. return ymin + (x - xmin) * ((ymax - ymin) / (xmax - xmin));
  48668. }
  48669. return function constructSampledFromIRResult(src, srcOffset, dest, destOffset) {
  48670. // See chapter 3, page 110 of the PDF reference.
  48671. var m = IR[1];
  48672. var domain = IR[2];
  48673. var encode = IR[3];
  48674. var decode = IR[4];
  48675. var samples = IR[5];
  48676. var size = IR[6];
  48677. var n = IR[7];
  48678. //var mask = IR[8];
  48679. var range = IR[9];
  48680. // Building the cube vertices: its part and sample index
  48681. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  48682. var cubeVertices = 1 << m;
  48683. var cubeN = new Float64Array(cubeVertices);
  48684. var cubeVertex = new Uint32Array(cubeVertices);
  48685. var i, j;
  48686. for (j = 0; j < cubeVertices; j++) {
  48687. cubeN[j] = 1;
  48688. }
  48689. var k = n, pos = 1;
  48690. // Map x_i to y_j for 0 <= i < m using the sampled function.
  48691. for (i = 0; i < m; ++i) {
  48692. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  48693. var domain_2i = domain[i][0];
  48694. var domain_2i_1 = domain[i][1];
  48695. var xi = Math.min(Math.max(src[srcOffset + i], domain_2i), domain_2i_1);
  48696. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  48697. // Encode_2i, Encode_2i+1)
  48698. var e = interpolate(xi, domain_2i, domain_2i_1, encode[i][0], encode[i][1]);
  48699. // e_i' = min(max(e_i, 0), Size_i - 1)
  48700. var size_i = size[i];
  48701. e = Math.min(Math.max(e, 0), size_i - 1);
  48702. // Adjusting the cube: N and vertex sample index
  48703. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1;
  48704. // e1 = e0 + 1;
  48705. var n0 = e0 + 1 - e;
  48706. // (e1 - e) / (e1 - e0);
  48707. var n1 = e - e0;
  48708. // (e - e0) / (e1 - e0);
  48709. var offset0 = e0 * k;
  48710. var offset1 = offset0 + k;
  48711. // e1 * k
  48712. for (j = 0; j < cubeVertices; j++) {
  48713. if (j & pos) {
  48714. cubeN[j] *= n1;
  48715. cubeVertex[j] += offset1;
  48716. } else {
  48717. cubeN[j] *= n0;
  48718. cubeVertex[j] += offset0;
  48719. }
  48720. }
  48721. k *= size_i;
  48722. pos <<= 1;
  48723. }
  48724. for (j = 0; j < n; ++j) {
  48725. // Sum all cube vertices' samples portions
  48726. var rj = 0;
  48727. for (i = 0; i < cubeVertices; i++) {
  48728. rj += samples[cubeVertex[i] + j] * cubeN[i];
  48729. }
  48730. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  48731. // Decode_2j, Decode_2j+1)
  48732. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  48733. // y_j = min(max(r_j, range_2j), range_2j+1)
  48734. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]), range[j][1]);
  48735. }
  48736. };
  48737. },
  48738. constructInterpolated: function PDFFunction_constructInterpolated(str, dict) {
  48739. var c0 = dict.getArray('C0') || [0];
  48740. var c1 = dict.getArray('C1') || [1];
  48741. var n = dict.get('N');
  48742. if (!isArray(c0) || !isArray(c1)) {
  48743. error('Illegal dictionary for interpolated function');
  48744. }
  48745. var length = c0.length;
  48746. var diff = [];
  48747. for (var i = 0; i < length; ++i) {
  48748. diff.push(c1[i] - c0[i]);
  48749. }
  48750. return [
  48751. CONSTRUCT_INTERPOLATED,
  48752. c0,
  48753. diff,
  48754. n
  48755. ];
  48756. },
  48757. constructInterpolatedFromIR: function PDFFunction_constructInterpolatedFromIR(IR) {
  48758. var c0 = IR[1];
  48759. var diff = IR[2];
  48760. var n = IR[3];
  48761. var length = diff.length;
  48762. return function constructInterpolatedFromIRResult(src, srcOffset, dest, destOffset) {
  48763. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  48764. for (var j = 0; j < length; ++j) {
  48765. dest[destOffset + j] = c0[j] + x * diff[j];
  48766. }
  48767. };
  48768. },
  48769. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  48770. var domain = dict.getArray('Domain');
  48771. if (!domain) {
  48772. error('No domain');
  48773. }
  48774. var inputSize = domain.length / 2;
  48775. if (inputSize !== 1) {
  48776. error('Bad domain for stiched function');
  48777. }
  48778. var fnRefs = dict.get('Functions');
  48779. var fns = [];
  48780. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  48781. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  48782. }
  48783. var bounds = dict.getArray('Bounds');
  48784. var encode = dict.getArray('Encode');
  48785. return [
  48786. CONSTRUCT_STICHED,
  48787. domain,
  48788. bounds,
  48789. encode,
  48790. fns
  48791. ];
  48792. },
  48793. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  48794. var domain = IR[1];
  48795. var bounds = IR[2];
  48796. var encode = IR[3];
  48797. var fnsIR = IR[4];
  48798. var fns = [];
  48799. var tmpBuf = new Float32Array(1);
  48800. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  48801. fns.push(PDFFunction.fromIR(fnsIR[i]));
  48802. }
  48803. return function constructStichedFromIRResult(src, srcOffset, dest, destOffset) {
  48804. var clip = function constructStichedFromIRClip(v, min, max) {
  48805. if (v > max) {
  48806. v = max;
  48807. } else if (v < min) {
  48808. v = min;
  48809. }
  48810. return v;
  48811. };
  48812. // clip to domain
  48813. var v = clip(src[srcOffset], domain[0], domain[1]);
  48814. // calculate which bound the value is in
  48815. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  48816. if (v < bounds[i]) {
  48817. break;
  48818. }
  48819. }
  48820. // encode value into domain of function
  48821. var dmin = domain[0];
  48822. if (i > 0) {
  48823. dmin = bounds[i - 1];
  48824. }
  48825. var dmax = domain[1];
  48826. if (i < bounds.length) {
  48827. dmax = bounds[i];
  48828. }
  48829. var rmin = encode[2 * i];
  48830. var rmax = encode[2 * i + 1];
  48831. // Prevent the value from becoming NaN as a result
  48832. // of division by zero (fixes issue6113.pdf).
  48833. tmpBuf[0] = dmin === dmax ? rmin : rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  48834. // call the appropriate function
  48835. fns[i](tmpBuf, 0, dest, destOffset);
  48836. };
  48837. },
  48838. constructPostScript: function PDFFunction_constructPostScript(fn, dict, xref) {
  48839. var domain = dict.getArray('Domain');
  48840. var range = dict.getArray('Range');
  48841. if (!domain) {
  48842. error('No domain.');
  48843. }
  48844. if (!range) {
  48845. error('No range.');
  48846. }
  48847. var lexer = new PostScriptLexer(fn);
  48848. var parser = new PostScriptParser(lexer);
  48849. var code = parser.parse();
  48850. return [
  48851. CONSTRUCT_POSTSCRIPT,
  48852. domain,
  48853. range,
  48854. code
  48855. ];
  48856. },
  48857. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(IR) {
  48858. var domain = IR[1];
  48859. var range = IR[2];
  48860. var code = IR[3];
  48861. var compiled = new PostScriptCompiler().compile(code, domain, range);
  48862. if (compiled) {
  48863. // Compiled function consists of simple expressions such as addition,
  48864. // subtraction, Math.max, and also contains 'var' and 'return'
  48865. // statements. See the generation in the PostScriptCompiler below.
  48866. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  48867. }
  48868. info('Unable to compile PS function');
  48869. var numOutputs = range.length >> 1;
  48870. var numInputs = domain.length >> 1;
  48871. var evaluator = new PostScriptEvaluator(code);
  48872. // Cache the values for a big speed up, the cache size is limited though
  48873. // since the number of possible values can be huge from a PS function.
  48874. var cache = Object.create(null);
  48875. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  48876. // seen in our tests.
  48877. var MAX_CACHE_SIZE = 2048 * 4;
  48878. var cache_available = MAX_CACHE_SIZE;
  48879. var tmpBuf = new Float32Array(numInputs);
  48880. return function constructPostScriptFromIRResult(src, srcOffset, dest, destOffset) {
  48881. var i, value;
  48882. var key = '';
  48883. var input = tmpBuf;
  48884. for (i = 0; i < numInputs; i++) {
  48885. value = src[srcOffset + i];
  48886. input[i] = value;
  48887. key += value + '_';
  48888. }
  48889. var cachedValue = cache[key];
  48890. if (cachedValue !== undefined) {
  48891. dest.set(cachedValue, destOffset);
  48892. return;
  48893. }
  48894. var output = new Float32Array(numOutputs);
  48895. var stack = evaluator.execute(input);
  48896. var stackIndex = stack.length - numOutputs;
  48897. for (i = 0; i < numOutputs; i++) {
  48898. value = stack[stackIndex + i];
  48899. var bound = range[i * 2];
  48900. if (value < bound) {
  48901. value = bound;
  48902. } else {
  48903. bound = range[i * 2 + 1];
  48904. if (value > bound) {
  48905. value = bound;
  48906. }
  48907. }
  48908. output[i] = value;
  48909. }
  48910. if (cache_available > 0) {
  48911. cache_available--;
  48912. cache[key] = output;
  48913. }
  48914. dest.set(output, destOffset);
  48915. };
  48916. }
  48917. };
  48918. }();
  48919. function isPDFFunction(v) {
  48920. var fnDict;
  48921. if (typeof v !== 'object') {
  48922. return false;
  48923. } else if (isDict(v)) {
  48924. fnDict = v;
  48925. } else if (isStream(v)) {
  48926. fnDict = v.dict;
  48927. } else {
  48928. return false;
  48929. }
  48930. return fnDict.has('FunctionType');
  48931. }
  48932. var PostScriptStack = function PostScriptStackClosure() {
  48933. var MAX_STACK_SIZE = 100;
  48934. function PostScriptStack(initialStack) {
  48935. this.stack = !initialStack ? [] : Array.prototype.slice.call(initialStack, 0);
  48936. }
  48937. PostScriptStack.prototype = {
  48938. push: function PostScriptStack_push(value) {
  48939. if (this.stack.length >= MAX_STACK_SIZE) {
  48940. error('PostScript function stack overflow.');
  48941. }
  48942. this.stack.push(value);
  48943. },
  48944. pop: function PostScriptStack_pop() {
  48945. if (this.stack.length <= 0) {
  48946. error('PostScript function stack underflow.');
  48947. }
  48948. return this.stack.pop();
  48949. },
  48950. copy: function PostScriptStack_copy(n) {
  48951. if (this.stack.length + n >= MAX_STACK_SIZE) {
  48952. error('PostScript function stack overflow.');
  48953. }
  48954. var stack = this.stack;
  48955. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  48956. stack.push(stack[i]);
  48957. }
  48958. },
  48959. index: function PostScriptStack_index(n) {
  48960. this.push(this.stack[this.stack.length - n - 1]);
  48961. },
  48962. // rotate the last n stack elements p times
  48963. roll: function PostScriptStack_roll(n, p) {
  48964. var stack = this.stack;
  48965. var l = stack.length - n;
  48966. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  48967. for (i = l, j = r; i < j; i++, j--) {
  48968. t = stack[i];
  48969. stack[i] = stack[j];
  48970. stack[j] = t;
  48971. }
  48972. for (i = l, j = c - 1; i < j; i++, j--) {
  48973. t = stack[i];
  48974. stack[i] = stack[j];
  48975. stack[j] = t;
  48976. }
  48977. for (i = c, j = r; i < j; i++, j--) {
  48978. t = stack[i];
  48979. stack[i] = stack[j];
  48980. stack[j] = t;
  48981. }
  48982. }
  48983. };
  48984. return PostScriptStack;
  48985. }();
  48986. var PostScriptEvaluator = function PostScriptEvaluatorClosure() {
  48987. function PostScriptEvaluator(operators) {
  48988. this.operators = operators;
  48989. }
  48990. PostScriptEvaluator.prototype = {
  48991. execute: function PostScriptEvaluator_execute(initialStack) {
  48992. var stack = new PostScriptStack(initialStack);
  48993. var counter = 0;
  48994. var operators = this.operators;
  48995. var length = operators.length;
  48996. var operator, a, b;
  48997. while (counter < length) {
  48998. operator = operators[counter++];
  48999. if (typeof operator === 'number') {
  49000. // Operator is really an operand and should be pushed to the stack.
  49001. stack.push(operator);
  49002. continue;
  49003. }
  49004. switch (operator) {
  49005. // non standard ps operators
  49006. case 'jz':
  49007. // jump if false
  49008. b = stack.pop();
  49009. a = stack.pop();
  49010. if (!a) {
  49011. counter = b;
  49012. }
  49013. break;
  49014. case 'j':
  49015. // jump
  49016. a = stack.pop();
  49017. counter = a;
  49018. break;
  49019. // all ps operators in alphabetical order (excluding if/ifelse)
  49020. case 'abs':
  49021. a = stack.pop();
  49022. stack.push(Math.abs(a));
  49023. break;
  49024. case 'add':
  49025. b = stack.pop();
  49026. a = stack.pop();
  49027. stack.push(a + b);
  49028. break;
  49029. case 'and':
  49030. b = stack.pop();
  49031. a = stack.pop();
  49032. if (isBool(a) && isBool(b)) {
  49033. stack.push(a && b);
  49034. } else {
  49035. stack.push(a & b);
  49036. }
  49037. break;
  49038. case 'atan':
  49039. a = stack.pop();
  49040. stack.push(Math.atan(a));
  49041. break;
  49042. case 'bitshift':
  49043. b = stack.pop();
  49044. a = stack.pop();
  49045. if (a > 0) {
  49046. stack.push(a << b);
  49047. } else {
  49048. stack.push(a >> b);
  49049. }
  49050. break;
  49051. case 'ceiling':
  49052. a = stack.pop();
  49053. stack.push(Math.ceil(a));
  49054. break;
  49055. case 'copy':
  49056. a = stack.pop();
  49057. stack.copy(a);
  49058. break;
  49059. case 'cos':
  49060. a = stack.pop();
  49061. stack.push(Math.cos(a));
  49062. break;
  49063. case 'cvi':
  49064. a = stack.pop() | 0;
  49065. stack.push(a);
  49066. break;
  49067. case 'cvr':
  49068. // noop
  49069. break;
  49070. case 'div':
  49071. b = stack.pop();
  49072. a = stack.pop();
  49073. stack.push(a / b);
  49074. break;
  49075. case 'dup':
  49076. stack.copy(1);
  49077. break;
  49078. case 'eq':
  49079. b = stack.pop();
  49080. a = stack.pop();
  49081. stack.push(a === b);
  49082. break;
  49083. case 'exch':
  49084. stack.roll(2, 1);
  49085. break;
  49086. case 'exp':
  49087. b = stack.pop();
  49088. a = stack.pop();
  49089. stack.push(Math.pow(a, b));
  49090. break;
  49091. case 'false':
  49092. stack.push(false);
  49093. break;
  49094. case 'floor':
  49095. a = stack.pop();
  49096. stack.push(Math.floor(a));
  49097. break;
  49098. case 'ge':
  49099. b = stack.pop();
  49100. a = stack.pop();
  49101. stack.push(a >= b);
  49102. break;
  49103. case 'gt':
  49104. b = stack.pop();
  49105. a = stack.pop();
  49106. stack.push(a > b);
  49107. break;
  49108. case 'idiv':
  49109. b = stack.pop();
  49110. a = stack.pop();
  49111. stack.push(a / b | 0);
  49112. break;
  49113. case 'index':
  49114. a = stack.pop();
  49115. stack.index(a);
  49116. break;
  49117. case 'le':
  49118. b = stack.pop();
  49119. a = stack.pop();
  49120. stack.push(a <= b);
  49121. break;
  49122. case 'ln':
  49123. a = stack.pop();
  49124. stack.push(Math.log(a));
  49125. break;
  49126. case 'log':
  49127. a = stack.pop();
  49128. stack.push(Math.log(a) / Math.LN10);
  49129. break;
  49130. case 'lt':
  49131. b = stack.pop();
  49132. a = stack.pop();
  49133. stack.push(a < b);
  49134. break;
  49135. case 'mod':
  49136. b = stack.pop();
  49137. a = stack.pop();
  49138. stack.push(a % b);
  49139. break;
  49140. case 'mul':
  49141. b = stack.pop();
  49142. a = stack.pop();
  49143. stack.push(a * b);
  49144. break;
  49145. case 'ne':
  49146. b = stack.pop();
  49147. a = stack.pop();
  49148. stack.push(a !== b);
  49149. break;
  49150. case 'neg':
  49151. a = stack.pop();
  49152. stack.push(-a);
  49153. break;
  49154. case 'not':
  49155. a = stack.pop();
  49156. if (isBool(a)) {
  49157. stack.push(!a);
  49158. } else {
  49159. stack.push(~a);
  49160. }
  49161. break;
  49162. case 'or':
  49163. b = stack.pop();
  49164. a = stack.pop();
  49165. if (isBool(a) && isBool(b)) {
  49166. stack.push(a || b);
  49167. } else {
  49168. stack.push(a | b);
  49169. }
  49170. break;
  49171. case 'pop':
  49172. stack.pop();
  49173. break;
  49174. case 'roll':
  49175. b = stack.pop();
  49176. a = stack.pop();
  49177. stack.roll(a, b);
  49178. break;
  49179. case 'round':
  49180. a = stack.pop();
  49181. stack.push(Math.round(a));
  49182. break;
  49183. case 'sin':
  49184. a = stack.pop();
  49185. stack.push(Math.sin(a));
  49186. break;
  49187. case 'sqrt':
  49188. a = stack.pop();
  49189. stack.push(Math.sqrt(a));
  49190. break;
  49191. case 'sub':
  49192. b = stack.pop();
  49193. a = stack.pop();
  49194. stack.push(a - b);
  49195. break;
  49196. case 'true':
  49197. stack.push(true);
  49198. break;
  49199. case 'truncate':
  49200. a = stack.pop();
  49201. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  49202. stack.push(a);
  49203. break;
  49204. case 'xor':
  49205. b = stack.pop();
  49206. a = stack.pop();
  49207. if (isBool(a) && isBool(b)) {
  49208. stack.push(a !== b);
  49209. } else {
  49210. stack.push(a ^ b);
  49211. }
  49212. break;
  49213. default:
  49214. error('Unknown operator ' + operator);
  49215. break;
  49216. }
  49217. }
  49218. return stack.stack;
  49219. }
  49220. };
  49221. return PostScriptEvaluator;
  49222. }();
  49223. // Most of the PDFs functions consist of simple operations such as:
  49224. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  49225. //
  49226. // We can compile most of such programs, and at the same moment, we can
  49227. // optimize some expressions using basic math properties. Keeping track of
  49228. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  49229. var PostScriptCompiler = function PostScriptCompilerClosure() {
  49230. function AstNode(type) {
  49231. this.type = type;
  49232. }
  49233. AstNode.prototype.visit = function (visitor) {
  49234. throw new Error('abstract method');
  49235. };
  49236. function AstArgument(index, min, max) {
  49237. AstNode.call(this, 'args');
  49238. this.index = index;
  49239. this.min = min;
  49240. this.max = max;
  49241. }
  49242. AstArgument.prototype = Object.create(AstNode.prototype);
  49243. AstArgument.prototype.visit = function (visitor) {
  49244. visitor.visitArgument(this);
  49245. };
  49246. function AstLiteral(number) {
  49247. AstNode.call(this, 'literal');
  49248. this.number = number;
  49249. this.min = number;
  49250. this.max = number;
  49251. }
  49252. AstLiteral.prototype = Object.create(AstNode.prototype);
  49253. AstLiteral.prototype.visit = function (visitor) {
  49254. visitor.visitLiteral(this);
  49255. };
  49256. function AstBinaryOperation(op, arg1, arg2, min, max) {
  49257. AstNode.call(this, 'binary');
  49258. this.op = op;
  49259. this.arg1 = arg1;
  49260. this.arg2 = arg2;
  49261. this.min = min;
  49262. this.max = max;
  49263. }
  49264. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  49265. AstBinaryOperation.prototype.visit = function (visitor) {
  49266. visitor.visitBinaryOperation(this);
  49267. };
  49268. function AstMin(arg, max) {
  49269. AstNode.call(this, 'max');
  49270. this.arg = arg;
  49271. this.min = arg.min;
  49272. this.max = max;
  49273. }
  49274. AstMin.prototype = Object.create(AstNode.prototype);
  49275. AstMin.prototype.visit = function (visitor) {
  49276. visitor.visitMin(this);
  49277. };
  49278. function AstVariable(index, min, max) {
  49279. AstNode.call(this, 'var');
  49280. this.index = index;
  49281. this.min = min;
  49282. this.max = max;
  49283. }
  49284. AstVariable.prototype = Object.create(AstNode.prototype);
  49285. AstVariable.prototype.visit = function (visitor) {
  49286. visitor.visitVariable(this);
  49287. };
  49288. function AstVariableDefinition(variable, arg) {
  49289. AstNode.call(this, 'definition');
  49290. this.variable = variable;
  49291. this.arg = arg;
  49292. }
  49293. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  49294. AstVariableDefinition.prototype.visit = function (visitor) {
  49295. visitor.visitVariableDefinition(this);
  49296. };
  49297. function ExpressionBuilderVisitor() {
  49298. this.parts = [];
  49299. }
  49300. ExpressionBuilderVisitor.prototype = {
  49301. visitArgument: function (arg) {
  49302. this.parts.push('Math.max(', arg.min, ', Math.min(', arg.max, ', src[srcOffset + ', arg.index, ']))');
  49303. },
  49304. visitVariable: function (variable) {
  49305. this.parts.push('v', variable.index);
  49306. },
  49307. visitLiteral: function (literal) {
  49308. this.parts.push(literal.number);
  49309. },
  49310. visitBinaryOperation: function (operation) {
  49311. this.parts.push('(');
  49312. operation.arg1.visit(this);
  49313. this.parts.push(' ', operation.op, ' ');
  49314. operation.arg2.visit(this);
  49315. this.parts.push(')');
  49316. },
  49317. visitVariableDefinition: function (definition) {
  49318. this.parts.push('var ');
  49319. definition.variable.visit(this);
  49320. this.parts.push(' = ');
  49321. definition.arg.visit(this);
  49322. this.parts.push(';');
  49323. },
  49324. visitMin: function (max) {
  49325. this.parts.push('Math.min(');
  49326. max.arg.visit(this);
  49327. this.parts.push(', ', max.max, ')');
  49328. },
  49329. toString: function () {
  49330. return this.parts.join('');
  49331. }
  49332. };
  49333. function buildAddOperation(num1, num2) {
  49334. if (num2.type === 'literal' && num2.number === 0) {
  49335. // optimization: second operand is 0
  49336. return num1;
  49337. }
  49338. if (num1.type === 'literal' && num1.number === 0) {
  49339. // optimization: first operand is 0
  49340. return num2;
  49341. }
  49342. if (num2.type === 'literal' && num1.type === 'literal') {
  49343. // optimization: operands operand are literals
  49344. return new AstLiteral(num1.number + num2.number);
  49345. }
  49346. return new AstBinaryOperation('+', num1, num2, num1.min + num2.min, num1.max + num2.max);
  49347. }
  49348. function buildMulOperation(num1, num2) {
  49349. if (num2.type === 'literal') {
  49350. // optimization: second operands is a literal...
  49351. if (num2.number === 0) {
  49352. return new AstLiteral(0);
  49353. } else // and it's 0
  49354. if (num2.number === 1) {
  49355. return num1;
  49356. } else // and it's 1
  49357. if (num1.type === 'literal') {
  49358. // ... and first operands is a literal too
  49359. return new AstLiteral(num1.number * num2.number);
  49360. }
  49361. }
  49362. if (num1.type === 'literal') {
  49363. // optimization: first operands is a literal...
  49364. if (num1.number === 0) {
  49365. return new AstLiteral(0);
  49366. } else // and it's 0
  49367. if (num1.number === 1) {
  49368. return num2;
  49369. }
  49370. }
  49371. // and it's 1
  49372. var min = Math.min(num1.min * num2.min, num1.min * num2.max, num1.max * num2.min, num1.max * num2.max);
  49373. var max = Math.max(num1.min * num2.min, num1.min * num2.max, num1.max * num2.min, num1.max * num2.max);
  49374. return new AstBinaryOperation('*', num1, num2, min, max);
  49375. }
  49376. function buildSubOperation(num1, num2) {
  49377. if (num2.type === 'literal') {
  49378. // optimization: second operands is a literal...
  49379. if (num2.number === 0) {
  49380. return num1;
  49381. } else // ... and it's 0
  49382. if (num1.type === 'literal') {
  49383. // ... and first operands is a literal too
  49384. return new AstLiteral(num1.number - num2.number);
  49385. }
  49386. }
  49387. if (num2.type === 'binary' && num2.op === '-' && num1.type === 'literal' && num1.number === 1 && num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  49388. // optimization for case: 1 - (1 - x)
  49389. return num2.arg2;
  49390. }
  49391. return new AstBinaryOperation('-', num1, num2, num1.min - num2.max, num1.max - num2.min);
  49392. }
  49393. function buildMinOperation(num1, max) {
  49394. if (num1.min >= max) {
  49395. // optimization: num1 min value is not less than required max
  49396. return new AstLiteral(max);
  49397. } else // just returning max
  49398. if (num1.max <= max) {
  49399. // optimization: num1 max value is not greater than required max
  49400. return num1;
  49401. }
  49402. // just returning an argument
  49403. return new AstMin(num1, max);
  49404. }
  49405. function PostScriptCompiler() {
  49406. }
  49407. PostScriptCompiler.prototype = {
  49408. compile: function PostScriptCompiler_compile(code, domain, range) {
  49409. var stack = [];
  49410. var i, ii;
  49411. var instructions = [];
  49412. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  49413. var lastRegister = 0;
  49414. var n, j;
  49415. var num1, num2, ast1, ast2, tmpVar, item;
  49416. for (i = 0; i < inputSize; i++) {
  49417. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  49418. }
  49419. for (i = 0, ii = code.length; i < ii; i++) {
  49420. item = code[i];
  49421. if (typeof item === 'number') {
  49422. stack.push(new AstLiteral(item));
  49423. continue;
  49424. }
  49425. switch (item) {
  49426. case 'add':
  49427. if (stack.length < 2) {
  49428. return null;
  49429. }
  49430. num2 = stack.pop();
  49431. num1 = stack.pop();
  49432. stack.push(buildAddOperation(num1, num2));
  49433. break;
  49434. case 'cvr':
  49435. if (stack.length < 1) {
  49436. return null;
  49437. }
  49438. break;
  49439. case 'mul':
  49440. if (stack.length < 2) {
  49441. return null;
  49442. }
  49443. num2 = stack.pop();
  49444. num1 = stack.pop();
  49445. stack.push(buildMulOperation(num1, num2));
  49446. break;
  49447. case 'sub':
  49448. if (stack.length < 2) {
  49449. return null;
  49450. }
  49451. num2 = stack.pop();
  49452. num1 = stack.pop();
  49453. stack.push(buildSubOperation(num1, num2));
  49454. break;
  49455. case 'exch':
  49456. if (stack.length < 2) {
  49457. return null;
  49458. }
  49459. ast1 = stack.pop();
  49460. ast2 = stack.pop();
  49461. stack.push(ast1, ast2);
  49462. break;
  49463. case 'pop':
  49464. if (stack.length < 1) {
  49465. return null;
  49466. }
  49467. stack.pop();
  49468. break;
  49469. case 'index':
  49470. if (stack.length < 1) {
  49471. return null;
  49472. }
  49473. num1 = stack.pop();
  49474. if (num1.type !== 'literal') {
  49475. return null;
  49476. }
  49477. n = num1.number;
  49478. if (n < 0 || (n | 0) !== n || stack.length < n) {
  49479. return null;
  49480. }
  49481. ast1 = stack[stack.length - n - 1];
  49482. if (ast1.type === 'literal' || ast1.type === 'var') {
  49483. stack.push(ast1);
  49484. break;
  49485. }
  49486. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  49487. stack[stack.length - n - 1] = tmpVar;
  49488. stack.push(tmpVar);
  49489. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  49490. break;
  49491. case 'dup':
  49492. if (stack.length < 1) {
  49493. return null;
  49494. }
  49495. 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]) {
  49496. // special case of the commands sequence for the min operation
  49497. num1 = stack.pop();
  49498. stack.push(buildMinOperation(num1, code[i + 1]));
  49499. i += 6;
  49500. break;
  49501. }
  49502. ast1 = stack[stack.length - 1];
  49503. if (ast1.type === 'literal' || ast1.type === 'var') {
  49504. // we don't have to save into intermediate variable a literal or
  49505. // variable.
  49506. stack.push(ast1);
  49507. break;
  49508. }
  49509. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  49510. stack[stack.length - 1] = tmpVar;
  49511. stack.push(tmpVar);
  49512. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  49513. break;
  49514. case 'roll':
  49515. if (stack.length < 2) {
  49516. return null;
  49517. }
  49518. num2 = stack.pop();
  49519. num1 = stack.pop();
  49520. if (num2.type !== 'literal' || num1.type !== 'literal') {
  49521. // both roll operands must be numbers
  49522. return null;
  49523. }
  49524. j = num2.number;
  49525. n = num1.number;
  49526. if (n <= 0 || (n | 0) !== n || (j | 0) !== j || stack.length < n) {
  49527. // ... and integers
  49528. return null;
  49529. }
  49530. j = (j % n + n) % n;
  49531. if (j === 0) {
  49532. break;
  49533. }
  49534. // just skipping -- there are nothing to rotate
  49535. Array.prototype.push.apply(stack, stack.splice(stack.length - n, n - j));
  49536. break;
  49537. default:
  49538. return null;
  49539. }
  49540. }
  49541. // unsupported operator
  49542. if (stack.length !== outputSize) {
  49543. return null;
  49544. }
  49545. var result = [];
  49546. instructions.forEach(function (instruction) {
  49547. var statementBuilder = new ExpressionBuilderVisitor();
  49548. instruction.visit(statementBuilder);
  49549. result.push(statementBuilder.toString());
  49550. });
  49551. stack.forEach(function (expr, i) {
  49552. var statementBuilder = new ExpressionBuilderVisitor();
  49553. expr.visit(statementBuilder);
  49554. var min = range[i * 2], max = range[i * 2 + 1];
  49555. var out = [statementBuilder.toString()];
  49556. if (min > expr.min) {
  49557. out.unshift('Math.max(', min, ', ');
  49558. out.push(')');
  49559. }
  49560. if (max < expr.max) {
  49561. out.unshift('Math.min(', max, ', ');
  49562. out.push(')');
  49563. }
  49564. out.unshift('dest[destOffset + ', i, '] = ');
  49565. out.push(';');
  49566. result.push(out.join(''));
  49567. });
  49568. return result.join('\n');
  49569. }
  49570. };
  49571. return PostScriptCompiler;
  49572. }();
  49573. exports.isPDFFunction = isPDFFunction;
  49574. exports.PDFFunction = PDFFunction;
  49575. exports.PostScriptEvaluator = PostScriptEvaluator;
  49576. exports.PostScriptCompiler = PostScriptCompiler;
  49577. }));
  49578. (function (root, factory) {
  49579. factory(root.pdfjsDisplayAPI = {}, root.pdfjsSharedUtil, root.pdfjsDisplayFontLoader, root.pdfjsDisplayCanvas, root.pdfjsDisplayMetadata, root.pdfjsDisplayDOMUtils);
  49580. }(this, function (exports, sharedUtil, displayFontLoader, displayCanvas, displayMetadata, displayDOMUtils, amdRequire) {
  49581. var InvalidPDFException = sharedUtil.InvalidPDFException;
  49582. var MessageHandler = sharedUtil.MessageHandler;
  49583. var MissingPDFException = sharedUtil.MissingPDFException;
  49584. var PageViewport = sharedUtil.PageViewport;
  49585. var PasswordResponses = sharedUtil.PasswordResponses;
  49586. var PasswordException = sharedUtil.PasswordException;
  49587. var StatTimer = sharedUtil.StatTimer;
  49588. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  49589. var UnknownErrorException = sharedUtil.UnknownErrorException;
  49590. var Util = sharedUtil.Util;
  49591. var createPromiseCapability = sharedUtil.createPromiseCapability;
  49592. var error = sharedUtil.error;
  49593. var deprecated = sharedUtil.deprecated;
  49594. var getVerbosityLevel = sharedUtil.getVerbosityLevel;
  49595. var info = sharedUtil.info;
  49596. var isInt = sharedUtil.isInt;
  49597. var isArray = sharedUtil.isArray;
  49598. var isArrayBuffer = sharedUtil.isArrayBuffer;
  49599. var isSameOrigin = sharedUtil.isSameOrigin;
  49600. var loadJpegStream = sharedUtil.loadJpegStream;
  49601. var stringToBytes = sharedUtil.stringToBytes;
  49602. var globalScope = sharedUtil.globalScope;
  49603. var warn = sharedUtil.warn;
  49604. var FontFaceObject = displayFontLoader.FontFaceObject;
  49605. var FontLoader = displayFontLoader.FontLoader;
  49606. var CanvasGraphics = displayCanvas.CanvasGraphics;
  49607. var createScratchCanvas = displayCanvas.createScratchCanvas;
  49608. var Metadata = displayMetadata.Metadata;
  49609. var getDefaultSetting = displayDOMUtils.getDefaultSetting;
  49610. var DEFAULT_RANGE_CHUNK_SIZE = 65536;
  49611. // 2^16 = 65536
  49612. var isWorkerDisabled = false;
  49613. var workerSrc;
  49614. var isPostMessageTransfersDisabled = false;
  49615. var fakeWorkerFilesLoader = null;
  49616. var useRequireEnsure = false;
  49617. /**
  49618. * Document initialization / loading parameters object.
  49619. *
  49620. * @typedef {Object} DocumentInitParameters
  49621. * @property {string} url - The URL of the PDF.
  49622. * @property {TypedArray|Array|string} data - Binary PDF data. Use typed arrays
  49623. * (Uint8Array) to improve the memory usage. If PDF data is BASE64-encoded,
  49624. * use atob() to convert it to a binary string first.
  49625. * @property {Object} httpHeaders - Basic authentication headers.
  49626. * @property {boolean} withCredentials - Indicates whether or not cross-site
  49627. * Access-Control requests should be made using credentials such as cookies
  49628. * or authorization headers. The default is false.
  49629. * @property {string} password - For decrypting password-protected PDFs.
  49630. * @property {TypedArray} initialData - A typed array with the first portion or
  49631. * all of the pdf data. Used by the extension since some data is already
  49632. * loaded before the switch to range requests.
  49633. * @property {number} length - The PDF file length. It's used for progress
  49634. * reports and range requests operations.
  49635. * @property {PDFDataRangeTransport} range
  49636. * @property {number} rangeChunkSize - Optional parameter to specify
  49637. * maximum number of bytes fetched per range request. The default value is
  49638. * 2^16 = 65536.
  49639. * @property {PDFWorker} worker - The worker that will be used for the loading
  49640. * and parsing of the PDF data.
  49641. * @property {string} docBaseUrl - (optional) The base URL of the document,
  49642. * used when attempting to recover valid absolute URLs for annotations, and
  49643. * outline items, that (incorrectly) only specify relative URLs.
  49644. */
  49645. /**
  49646. * @typedef {Object} PDFDocumentStats
  49647. * @property {Array} streamTypes - Used stream types in the document (an item
  49648. * is set to true if specific stream ID was used in the document).
  49649. * @property {Array} fontTypes - Used font type in the document (an item is set
  49650. * to true if specific font ID was used in the document).
  49651. */
  49652. /**
  49653. * This is the main entry point for loading a PDF and interacting with it.
  49654. * NOTE: If a URL is used to fetch the PDF data a standard XMLHttpRequest(XHR)
  49655. * is used, which means it must follow the same origin rules that any XHR does
  49656. * e.g. No cross domain requests without CORS.
  49657. *
  49658. * @param {string|TypedArray|DocumentInitParameters|PDFDataRangeTransport} src
  49659. * Can be a url to where a PDF is located, a typed array (Uint8Array)
  49660. * already populated with data or parameter object.
  49661. *
  49662. * @param {PDFDataRangeTransport} pdfDataRangeTransport (deprecated) It is used
  49663. * if you want to manually serve range requests for data in the PDF.
  49664. *
  49665. * @param {function} passwordCallback (deprecated) It is used to request a
  49666. * password if wrong or no password was provided. The callback receives two
  49667. * parameters: function that needs to be called with new password and reason
  49668. * (see {PasswordResponses}).
  49669. *
  49670. * @param {function} progressCallback (deprecated) It is used to be able to
  49671. * monitor the loading progress of the PDF file (necessary to implement e.g.
  49672. * a loading bar). The callback receives an {Object} with the properties:
  49673. * {number} loaded and {number} total.
  49674. *
  49675. * @return {PDFDocumentLoadingTask}
  49676. */
  49677. function getDocument(src, pdfDataRangeTransport, passwordCallback, progressCallback) {
  49678. var task = new PDFDocumentLoadingTask();
  49679. // Support of the obsolete arguments (for compatibility with API v1.0)
  49680. if (arguments.length > 1) {
  49681. deprecated('getDocument is called with pdfDataRangeTransport, ' + 'passwordCallback or progressCallback argument');
  49682. }
  49683. if (pdfDataRangeTransport) {
  49684. if (!(pdfDataRangeTransport instanceof PDFDataRangeTransport)) {
  49685. // Not a PDFDataRangeTransport instance, trying to add missing properties.
  49686. pdfDataRangeTransport = Object.create(pdfDataRangeTransport);
  49687. pdfDataRangeTransport.length = src.length;
  49688. pdfDataRangeTransport.initialData = src.initialData;
  49689. if (!pdfDataRangeTransport.abort) {
  49690. pdfDataRangeTransport.abort = function () {
  49691. };
  49692. }
  49693. }
  49694. src = Object.create(src);
  49695. src.range = pdfDataRangeTransport;
  49696. }
  49697. task.onPassword = passwordCallback || null;
  49698. task.onProgress = progressCallback || null;
  49699. var source;
  49700. if (typeof src === 'string') {
  49701. source = { url: src };
  49702. } else if (isArrayBuffer(src)) {
  49703. source = { data: src };
  49704. } else if (src instanceof PDFDataRangeTransport) {
  49705. source = { range: src };
  49706. } else {
  49707. if (typeof src !== 'object') {
  49708. error('Invalid parameter in getDocument, need either Uint8Array, ' + 'string or a parameter object');
  49709. }
  49710. if (!src.url && !src.data && !src.range) {
  49711. error('Invalid parameter object: need either .data, .range or .url');
  49712. }
  49713. source = src;
  49714. }
  49715. var params = {};
  49716. var rangeTransport = null;
  49717. var worker = null;
  49718. for (var key in source) {
  49719. if (key === 'url' && typeof window !== 'undefined') {
  49720. // The full path is required in the 'url' field.
  49721. params[key] = new URL(source[key], window.location).href;
  49722. continue;
  49723. } else if (key === 'range') {
  49724. rangeTransport = source[key];
  49725. continue;
  49726. } else if (key === 'worker') {
  49727. worker = source[key];
  49728. continue;
  49729. } else if (key === 'data' && !(source[key] instanceof Uint8Array)) {
  49730. // Converting string or array-like data to Uint8Array.
  49731. var pdfBytes = source[key];
  49732. if (typeof pdfBytes === 'string') {
  49733. params[key] = stringToBytes(pdfBytes);
  49734. } else if (typeof pdfBytes === 'object' && pdfBytes !== null && !isNaN(pdfBytes.length)) {
  49735. params[key] = new Uint8Array(pdfBytes);
  49736. } else if (isArrayBuffer(pdfBytes)) {
  49737. params[key] = new Uint8Array(pdfBytes);
  49738. } else {
  49739. error('Invalid PDF binary data: either typed array, string or ' + 'array-like object is expected in the data property.');
  49740. }
  49741. continue;
  49742. }
  49743. params[key] = source[key];
  49744. }
  49745. params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE;
  49746. if (!worker) {
  49747. // Worker was not provided -- creating and owning our own.
  49748. worker = new PDFWorker();
  49749. task._worker = worker;
  49750. }
  49751. var docId = task.docId;
  49752. worker.promise.then(function () {
  49753. if (task.destroyed) {
  49754. throw new Error('Loading aborted');
  49755. }
  49756. return _fetchDocument(worker, params, rangeTransport, docId).then(function (workerId) {
  49757. if (task.destroyed) {
  49758. throw new Error('Loading aborted');
  49759. }
  49760. var messageHandler = new MessageHandler(docId, workerId, worker.port);
  49761. var transport = new WorkerTransport(messageHandler, task, rangeTransport);
  49762. task._transport = transport;
  49763. messageHandler.send('Ready', null);
  49764. });
  49765. }).catch(task._capability.reject);
  49766. return task;
  49767. }
  49768. /**
  49769. * Starts fetching of specified PDF document/data.
  49770. * @param {PDFWorker} worker
  49771. * @param {Object} source
  49772. * @param {PDFDataRangeTransport} pdfDataRangeTransport
  49773. * @param {string} docId Unique document id, used as MessageHandler id.
  49774. * @returns {Promise} The promise, which is resolved when worker id of
  49775. * MessageHandler is known.
  49776. * @private
  49777. */
  49778. function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
  49779. if (worker.destroyed) {
  49780. return Promise.reject(new Error('Worker was destroyed'));
  49781. }
  49782. source.disableAutoFetch = getDefaultSetting('disableAutoFetch');
  49783. source.disableStream = getDefaultSetting('disableStream');
  49784. source.chunkedViewerLoading = !!pdfDataRangeTransport;
  49785. if (pdfDataRangeTransport) {
  49786. source.length = pdfDataRangeTransport.length;
  49787. source.initialData = pdfDataRangeTransport.initialData;
  49788. }
  49789. return worker.messageHandler.sendWithPromise('GetDocRequest', {
  49790. docId: docId,
  49791. source: source,
  49792. disableRange: getDefaultSetting('disableRange'),
  49793. maxImageSize: getDefaultSetting('maxImageSize'),
  49794. cMapUrl: getDefaultSetting('cMapUrl'),
  49795. cMapPacked: getDefaultSetting('cMapPacked'),
  49796. disableFontFace: getDefaultSetting('disableFontFace'),
  49797. disableCreateObjectURL: getDefaultSetting('disableCreateObjectURL'),
  49798. postMessageTransfers: getDefaultSetting('postMessageTransfers') && !isPostMessageTransfersDisabled,
  49799. docBaseUrl: source.docBaseUrl
  49800. }).then(function (workerId) {
  49801. if (worker.destroyed) {
  49802. throw new Error('Worker was destroyed');
  49803. }
  49804. return workerId;
  49805. });
  49806. }
  49807. /**
  49808. * PDF document loading operation.
  49809. * @class
  49810. * @alias PDFDocumentLoadingTask
  49811. */
  49812. var PDFDocumentLoadingTask = function PDFDocumentLoadingTaskClosure() {
  49813. var nextDocumentId = 0;
  49814. /** @constructs PDFDocumentLoadingTask */
  49815. function PDFDocumentLoadingTask() {
  49816. this._capability = createPromiseCapability();
  49817. this._transport = null;
  49818. this._worker = null;
  49819. /**
  49820. * Unique document loading task id -- used in MessageHandlers.
  49821. * @type {string}
  49822. */
  49823. this.docId = 'd' + nextDocumentId++;
  49824. /**
  49825. * Shows if loading task is destroyed.
  49826. * @type {boolean}
  49827. */
  49828. this.destroyed = false;
  49829. /**
  49830. * Callback to request a password if wrong or no password was provided.
  49831. * The callback receives two parameters: function that needs to be called
  49832. * with new password and reason (see {PasswordResponses}).
  49833. */
  49834. this.onPassword = null;
  49835. /**
  49836. * Callback to be able to monitor the loading progress of the PDF file
  49837. * (necessary to implement e.g. a loading bar). The callback receives
  49838. * an {Object} with the properties: {number} loaded and {number} total.
  49839. */
  49840. this.onProgress = null;
  49841. /**
  49842. * Callback to when unsupported feature is used. The callback receives
  49843. * an {UNSUPPORTED_FEATURES} argument.
  49844. */
  49845. this.onUnsupportedFeature = null;
  49846. }
  49847. PDFDocumentLoadingTask.prototype = /** @lends PDFDocumentLoadingTask.prototype */
  49848. {
  49849. /**
  49850. * @return {Promise}
  49851. */
  49852. get promise() {
  49853. return this._capability.promise;
  49854. },
  49855. /**
  49856. * Aborts all network requests and destroys worker.
  49857. * @return {Promise} A promise that is resolved after destruction activity
  49858. * is completed.
  49859. */
  49860. destroy: function () {
  49861. this.destroyed = true;
  49862. var transportDestroyed = !this._transport ? Promise.resolve() : this._transport.destroy();
  49863. return transportDestroyed.then(function () {
  49864. this._transport = null;
  49865. if (this._worker) {
  49866. this._worker.destroy();
  49867. this._worker = null;
  49868. }
  49869. }.bind(this));
  49870. },
  49871. /**
  49872. * Registers callbacks to indicate the document loading completion.
  49873. *
  49874. * @param {function} onFulfilled The callback for the loading completion.
  49875. * @param {function} onRejected The callback for the loading failure.
  49876. * @return {Promise} A promise that is resolved after the onFulfilled or
  49877. * onRejected callback.
  49878. */
  49879. then: function PDFDocumentLoadingTask_then(onFulfilled, onRejected) {
  49880. return this.promise.then.apply(this.promise, arguments);
  49881. }
  49882. };
  49883. return PDFDocumentLoadingTask;
  49884. }();
  49885. /**
  49886. * Abstract class to support range requests file loading.
  49887. * @class
  49888. * @alias PDFDataRangeTransport
  49889. * @param {number} length
  49890. * @param {Uint8Array} initialData
  49891. */
  49892. var PDFDataRangeTransport = function pdfDataRangeTransportClosure() {
  49893. function PDFDataRangeTransport(length, initialData) {
  49894. this.length = length;
  49895. this.initialData = initialData;
  49896. this._rangeListeners = [];
  49897. this._progressListeners = [];
  49898. this._progressiveReadListeners = [];
  49899. this._readyCapability = createPromiseCapability();
  49900. }
  49901. PDFDataRangeTransport.prototype = /** @lends PDFDataRangeTransport.prototype */
  49902. {
  49903. addRangeListener: function PDFDataRangeTransport_addRangeListener(listener) {
  49904. this._rangeListeners.push(listener);
  49905. },
  49906. addProgressListener: function PDFDataRangeTransport_addProgressListener(listener) {
  49907. this._progressListeners.push(listener);
  49908. },
  49909. addProgressiveReadListener: function PDFDataRangeTransport_addProgressiveReadListener(listener) {
  49910. this._progressiveReadListeners.push(listener);
  49911. },
  49912. onDataRange: function PDFDataRangeTransport_onDataRange(begin, chunk) {
  49913. var listeners = this._rangeListeners;
  49914. for (var i = 0, n = listeners.length; i < n; ++i) {
  49915. listeners[i](begin, chunk);
  49916. }
  49917. },
  49918. onDataProgress: function PDFDataRangeTransport_onDataProgress(loaded) {
  49919. this._readyCapability.promise.then(function () {
  49920. var listeners = this._progressListeners;
  49921. for (var i = 0, n = listeners.length; i < n; ++i) {
  49922. listeners[i](loaded);
  49923. }
  49924. }.bind(this));
  49925. },
  49926. onDataProgressiveRead: function PDFDataRangeTransport_onDataProgress(chunk) {
  49927. this._readyCapability.promise.then(function () {
  49928. var listeners = this._progressiveReadListeners;
  49929. for (var i = 0, n = listeners.length; i < n; ++i) {
  49930. listeners[i](chunk);
  49931. }
  49932. }.bind(this));
  49933. },
  49934. transportReady: function PDFDataRangeTransport_transportReady() {
  49935. this._readyCapability.resolve();
  49936. },
  49937. requestDataRange: function PDFDataRangeTransport_requestDataRange(begin, end) {
  49938. throw new Error('Abstract method PDFDataRangeTransport.requestDataRange');
  49939. },
  49940. abort: function PDFDataRangeTransport_abort() {
  49941. }
  49942. };
  49943. return PDFDataRangeTransport;
  49944. }();
  49945. /**
  49946. * Proxy to a PDFDocument in the worker thread. Also, contains commonly used
  49947. * properties that can be read synchronously.
  49948. * @class
  49949. * @alias PDFDocumentProxy
  49950. */
  49951. var PDFDocumentProxy = function PDFDocumentProxyClosure() {
  49952. function PDFDocumentProxy(pdfInfo, transport, loadingTask) {
  49953. this.pdfInfo = pdfInfo;
  49954. this.transport = transport;
  49955. this.loadingTask = loadingTask;
  49956. }
  49957. PDFDocumentProxy.prototype = /** @lends PDFDocumentProxy.prototype */
  49958. {
  49959. /**
  49960. * @return {number} Total number of pages the PDF contains.
  49961. */
  49962. get numPages() {
  49963. return this.pdfInfo.numPages;
  49964. },
  49965. /**
  49966. * @return {string} A unique ID to identify a PDF. Not guaranteed to be
  49967. * unique.
  49968. */
  49969. get fingerprint() {
  49970. return this.pdfInfo.fingerprint;
  49971. },
  49972. /**
  49973. * @param {number} pageNumber The page number to get. The first page is 1.
  49974. * @return {Promise} A promise that is resolved with a {@link PDFPageProxy}
  49975. * object.
  49976. */
  49977. getPage: function PDFDocumentProxy_getPage(pageNumber) {
  49978. return this.transport.getPage(pageNumber);
  49979. },
  49980. /**
  49981. * @param {{num: number, gen: number}} ref The page reference. Must have
  49982. * the 'num' and 'gen' properties.
  49983. * @return {Promise} A promise that is resolved with the page index that is
  49984. * associated with the reference.
  49985. */
  49986. getPageIndex: function PDFDocumentProxy_getPageIndex(ref) {
  49987. return this.transport.getPageIndex(ref);
  49988. },
  49989. /**
  49990. * @return {Promise} A promise that is resolved with a lookup table for
  49991. * mapping named destinations to reference numbers.
  49992. *
  49993. * This can be slow for large documents: use getDestination instead
  49994. */
  49995. getDestinations: function PDFDocumentProxy_getDestinations() {
  49996. return this.transport.getDestinations();
  49997. },
  49998. /**
  49999. * @param {string} id The named destination to get.
  50000. * @return {Promise} A promise that is resolved with all information
  50001. * of the given named destination.
  50002. */
  50003. getDestination: function PDFDocumentProxy_getDestination(id) {
  50004. return this.transport.getDestination(id);
  50005. },
  50006. /**
  50007. * @return {Promise} A promise that is resolved with:
  50008. * an Array containing the pageLabels that correspond to the pageIndexes,
  50009. * or `null` when no pageLabels are present in the PDF file.
  50010. */
  50011. getPageLabels: function PDFDocumentProxy_getPageLabels() {
  50012. return this.transport.getPageLabels();
  50013. },
  50014. /**
  50015. * @return {Promise} A promise that is resolved with a lookup table for
  50016. * mapping named attachments to their content.
  50017. */
  50018. getAttachments: function PDFDocumentProxy_getAttachments() {
  50019. return this.transport.getAttachments();
  50020. },
  50021. /**
  50022. * @return {Promise} A promise that is resolved with an array of all the
  50023. * JavaScript strings in the name tree.
  50024. */
  50025. getJavaScript: function PDFDocumentProxy_getJavaScript() {
  50026. return this.transport.getJavaScript();
  50027. },
  50028. /**
  50029. * @return {Promise} A promise that is resolved with an {Array} that is a
  50030. * tree outline (if it has one) of the PDF. The tree is in the format of:
  50031. * [
  50032. * {
  50033. * title: string,
  50034. * bold: boolean,
  50035. * italic: boolean,
  50036. * color: rgb Uint8Array,
  50037. * dest: dest obj,
  50038. * url: string,
  50039. * items: array of more items like this
  50040. * },
  50041. * ...
  50042. * ].
  50043. */
  50044. getOutline: function PDFDocumentProxy_getOutline() {
  50045. return this.transport.getOutline();
  50046. },
  50047. /**
  50048. * @return {Promise} A promise that is resolved with an {Object} that has
  50049. * info and metadata properties. Info is an {Object} filled with anything
  50050. * available in the information dictionary and similarly metadata is a
  50051. * {Metadata} object with information from the metadata section of the PDF.
  50052. */
  50053. getMetadata: function PDFDocumentProxy_getMetadata() {
  50054. return this.transport.getMetadata();
  50055. },
  50056. /**
  50057. * @return {Promise} A promise that is resolved with a TypedArray that has
  50058. * the raw data from the PDF.
  50059. */
  50060. getData: function PDFDocumentProxy_getData() {
  50061. return this.transport.getData();
  50062. },
  50063. /**
  50064. * @return {Promise} A promise that is resolved when the document's data
  50065. * is loaded. It is resolved with an {Object} that contains the length
  50066. * property that indicates size of the PDF data in bytes.
  50067. */
  50068. getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() {
  50069. return this.transport.downloadInfoCapability.promise;
  50070. },
  50071. /**
  50072. * @return {Promise} A promise this is resolved with current stats about
  50073. * document structures (see {@link PDFDocumentStats}).
  50074. */
  50075. getStats: function PDFDocumentProxy_getStats() {
  50076. return this.transport.getStats();
  50077. },
  50078. /**
  50079. * Cleans up resources allocated by the document, e.g. created @font-face.
  50080. */
  50081. cleanup: function PDFDocumentProxy_cleanup() {
  50082. this.transport.startCleanup();
  50083. },
  50084. /**
  50085. * Destroys current document instance and terminates worker.
  50086. */
  50087. destroy: function PDFDocumentProxy_destroy() {
  50088. return this.loadingTask.destroy();
  50089. }
  50090. };
  50091. return PDFDocumentProxy;
  50092. }();
  50093. /**
  50094. * Page getTextContent parameters.
  50095. *
  50096. * @typedef {Object} getTextContentParameters
  50097. * @property {boolean} normalizeWhitespace - replaces all occurrences of
  50098. * whitespace with standard spaces (0x20). The default value is `false`.
  50099. * @property {boolean} disableCombineTextItems - do not attempt to combine
  50100. * same line {@link TextItem}'s. The default value is `false`.
  50101. */
  50102. /**
  50103. * Page text content.
  50104. *
  50105. * @typedef {Object} TextContent
  50106. * @property {array} items - array of {@link TextItem}
  50107. * @property {Object} styles - {@link TextStyles} objects, indexed by font name.
  50108. */
  50109. /**
  50110. * Page text content part.
  50111. *
  50112. * @typedef {Object} TextItem
  50113. * @property {string} str - text content.
  50114. * @property {string} dir - text direction: 'ttb', 'ltr' or 'rtl'.
  50115. * @property {array} transform - transformation matrix.
  50116. * @property {number} width - width in device space.
  50117. * @property {number} height - height in device space.
  50118. * @property {string} fontName - font name used by pdf.js for converted font.
  50119. */
  50120. /**
  50121. * Text style.
  50122. *
  50123. * @typedef {Object} TextStyle
  50124. * @property {number} ascent - font ascent.
  50125. * @property {number} descent - font descent.
  50126. * @property {boolean} vertical - text is in vertical mode.
  50127. * @property {string} fontFamily - possible font family
  50128. */
  50129. /**
  50130. * Page annotation parameters.
  50131. *
  50132. * @typedef {Object} GetAnnotationsParameters
  50133. * @property {string} intent - Determines the annotations that will be fetched,
  50134. * can be either 'display' (viewable annotations) or 'print'
  50135. * (printable annotations).
  50136. * If the parameter is omitted, all annotations are fetched.
  50137. */
  50138. /**
  50139. * Page render parameters.
  50140. *
  50141. * @typedef {Object} RenderParameters
  50142. * @property {Object} canvasContext - A 2D context of a DOM Canvas object.
  50143. * @property {PageViewport} viewport - Rendering viewport obtained by
  50144. * calling of PDFPage.getViewport method.
  50145. * @property {string} intent - Rendering intent, can be 'display' or 'print'
  50146. * (default value is 'display').
  50147. * @property {boolean} renderInteractiveForms - (optional) Whether or not
  50148. * interactive form elements are rendered in the display
  50149. * layer. If so, we do not render them on canvas as well.
  50150. * @property {Array} transform - (optional) Additional transform, applied
  50151. * just before viewport transform.
  50152. * @property {Object} imageLayer - (optional) An object that has beginLayout,
  50153. * endLayout and appendImage functions.
  50154. * @property {function} continueCallback - (deprecated) A function that will be
  50155. * called each time the rendering is paused. To continue
  50156. * rendering call the function that is the first argument
  50157. * to the callback.
  50158. */
  50159. /**
  50160. * PDF page operator list.
  50161. *
  50162. * @typedef {Object} PDFOperatorList
  50163. * @property {Array} fnArray - Array containing the operator functions.
  50164. * @property {Array} argsArray - Array containing the arguments of the
  50165. * functions.
  50166. */
  50167. /**
  50168. * Proxy to a PDFPage in the worker thread.
  50169. * @class
  50170. * @alias PDFPageProxy
  50171. */
  50172. var PDFPageProxy = function PDFPageProxyClosure() {
  50173. function PDFPageProxy(pageIndex, pageInfo, transport) {
  50174. this.pageIndex = pageIndex;
  50175. this.pageInfo = pageInfo;
  50176. this.transport = transport;
  50177. this.stats = new StatTimer();
  50178. this.stats.enabled = getDefaultSetting('enableStats');
  50179. this.commonObjs = transport.commonObjs;
  50180. this.objs = new PDFObjects();
  50181. this.cleanupAfterRender = false;
  50182. this.pendingCleanup = false;
  50183. this.intentStates = Object.create(null);
  50184. this.destroyed = false;
  50185. }
  50186. PDFPageProxy.prototype = /** @lends PDFPageProxy.prototype */
  50187. {
  50188. /**
  50189. * @return {number} Page number of the page. First page is 1.
  50190. */
  50191. get pageNumber() {
  50192. return this.pageIndex + 1;
  50193. },
  50194. /**
  50195. * @return {number} The number of degrees the page is rotated clockwise.
  50196. */
  50197. get rotate() {
  50198. return this.pageInfo.rotate;
  50199. },
  50200. /**
  50201. * @return {Object} The reference that points to this page. It has 'num' and
  50202. * 'gen' properties.
  50203. */
  50204. get ref() {
  50205. return this.pageInfo.ref;
  50206. },
  50207. /**
  50208. * @return {Array} An array of the visible portion of the PDF page in the
  50209. * user space units - [x1, y1, x2, y2].
  50210. */
  50211. get view() {
  50212. return this.pageInfo.view;
  50213. },
  50214. /**
  50215. * @param {number} scale The desired scale of the viewport.
  50216. * @param {number} rotate Degrees to rotate the viewport. If omitted this
  50217. * defaults to the page rotation.
  50218. * @return {PageViewport} Contains 'width' and 'height' properties
  50219. * along with transforms required for rendering.
  50220. */
  50221. getViewport: function PDFPageProxy_getViewport(scale, rotate) {
  50222. if (arguments.length < 2) {
  50223. rotate = this.rotate;
  50224. }
  50225. return new PageViewport(this.view, scale, rotate, 0, 0);
  50226. },
  50227. /**
  50228. * @param {GetAnnotationsParameters} params - Annotation parameters.
  50229. * @return {Promise} A promise that is resolved with an {Array} of the
  50230. * annotation objects.
  50231. */
  50232. getAnnotations: function PDFPageProxy_getAnnotations(params) {
  50233. var intent = params && params.intent || null;
  50234. if (!this.annotationsPromise || this.annotationsIntent !== intent) {
  50235. this.annotationsPromise = this.transport.getAnnotations(this.pageIndex, intent);
  50236. this.annotationsIntent = intent;
  50237. }
  50238. return this.annotationsPromise;
  50239. },
  50240. /**
  50241. * Begins the process of rendering a page to the desired context.
  50242. * @param {RenderParameters} params Page render parameters.
  50243. * @return {RenderTask} An object that contains the promise, which
  50244. * is resolved when the page finishes rendering.
  50245. */
  50246. render: function PDFPageProxy_render(params) {
  50247. var stats = this.stats;
  50248. stats.time('Overall');
  50249. // If there was a pending destroy cancel it so no cleanup happens during
  50250. // this call to render.
  50251. this.pendingCleanup = false;
  50252. var renderingIntent = params.intent === 'print' ? 'print' : 'display';
  50253. var renderInteractiveForms = params.renderInteractiveForms === true ? true : /* Default */
  50254. false;
  50255. if (!this.intentStates[renderingIntent]) {
  50256. this.intentStates[renderingIntent] = Object.create(null);
  50257. }
  50258. var intentState = this.intentStates[renderingIntent];
  50259. // If there's no displayReadyCapability yet, then the operatorList
  50260. // was never requested before. Make the request and create the promise.
  50261. if (!intentState.displayReadyCapability) {
  50262. intentState.receivingOperatorList = true;
  50263. intentState.displayReadyCapability = createPromiseCapability();
  50264. intentState.operatorList = {
  50265. fnArray: [],
  50266. argsArray: [],
  50267. lastChunk: false
  50268. };
  50269. this.stats.time('Page Request');
  50270. this.transport.messageHandler.send('RenderPageRequest', {
  50271. pageIndex: this.pageNumber - 1,
  50272. intent: renderingIntent,
  50273. renderInteractiveForms: renderInteractiveForms
  50274. });
  50275. }
  50276. var internalRenderTask = new InternalRenderTask(complete, params, this.objs, this.commonObjs, intentState.operatorList, this.pageNumber);
  50277. internalRenderTask.useRequestAnimationFrame = renderingIntent !== 'print';
  50278. if (!intentState.renderTasks) {
  50279. intentState.renderTasks = [];
  50280. }
  50281. intentState.renderTasks.push(internalRenderTask);
  50282. var renderTask = internalRenderTask.task;
  50283. // Obsolete parameter support
  50284. if (params.continueCallback) {
  50285. deprecated('render is used with continueCallback parameter');
  50286. renderTask.onContinue = params.continueCallback;
  50287. }
  50288. var self = this;
  50289. intentState.displayReadyCapability.promise.then(function pageDisplayReadyPromise(transparency) {
  50290. if (self.pendingCleanup) {
  50291. complete();
  50292. return;
  50293. }
  50294. stats.time('Rendering');
  50295. internalRenderTask.initializeGraphics(transparency);
  50296. internalRenderTask.operatorListChanged();
  50297. }, function pageDisplayReadPromiseError(reason) {
  50298. complete(reason);
  50299. });
  50300. function complete(error) {
  50301. var i = intentState.renderTasks.indexOf(internalRenderTask);
  50302. if (i >= 0) {
  50303. intentState.renderTasks.splice(i, 1);
  50304. }
  50305. if (self.cleanupAfterRender) {
  50306. self.pendingCleanup = true;
  50307. }
  50308. self._tryCleanup();
  50309. if (error) {
  50310. internalRenderTask.capability.reject(error);
  50311. } else {
  50312. internalRenderTask.capability.resolve();
  50313. }
  50314. stats.timeEnd('Rendering');
  50315. stats.timeEnd('Overall');
  50316. }
  50317. return renderTask;
  50318. },
  50319. /**
  50320. * @return {Promise} A promise resolved with an {@link PDFOperatorList}
  50321. * object that represents page's operator list.
  50322. */
  50323. getOperatorList: function PDFPageProxy_getOperatorList() {
  50324. function operatorListChanged() {
  50325. if (intentState.operatorList.lastChunk) {
  50326. intentState.opListReadCapability.resolve(intentState.operatorList);
  50327. var i = intentState.renderTasks.indexOf(opListTask);
  50328. if (i >= 0) {
  50329. intentState.renderTasks.splice(i, 1);
  50330. }
  50331. }
  50332. }
  50333. var renderingIntent = 'oplist';
  50334. if (!this.intentStates[renderingIntent]) {
  50335. this.intentStates[renderingIntent] = Object.create(null);
  50336. }
  50337. var intentState = this.intentStates[renderingIntent];
  50338. var opListTask;
  50339. if (!intentState.opListReadCapability) {
  50340. opListTask = {};
  50341. opListTask.operatorListChanged = operatorListChanged;
  50342. intentState.receivingOperatorList = true;
  50343. intentState.opListReadCapability = createPromiseCapability();
  50344. intentState.renderTasks = [];
  50345. intentState.renderTasks.push(opListTask);
  50346. intentState.operatorList = {
  50347. fnArray: [],
  50348. argsArray: [],
  50349. lastChunk: false
  50350. };
  50351. this.transport.messageHandler.send('RenderPageRequest', {
  50352. pageIndex: this.pageIndex,
  50353. intent: renderingIntent
  50354. });
  50355. }
  50356. return intentState.opListReadCapability.promise;
  50357. },
  50358. /**
  50359. * @param {getTextContentParameters} params - getTextContent parameters.
  50360. * @return {Promise} That is resolved a {@link TextContent}
  50361. * object that represent the page text content.
  50362. */
  50363. getTextContent: function PDFPageProxy_getTextContent(params) {
  50364. return this.transport.messageHandler.sendWithPromise('GetTextContent', {
  50365. pageIndex: this.pageNumber - 1,
  50366. normalizeWhitespace: params && params.normalizeWhitespace === true ? true : /* Default */
  50367. false,
  50368. combineTextItems: params && params.disableCombineTextItems === true ? false : /* Default */
  50369. true
  50370. });
  50371. },
  50372. /**
  50373. * Destroys page object.
  50374. */
  50375. _destroy: function PDFPageProxy_destroy() {
  50376. this.destroyed = true;
  50377. this.transport.pageCache[this.pageIndex] = null;
  50378. var waitOn = [];
  50379. Object.keys(this.intentStates).forEach(function (intent) {
  50380. if (intent === 'oplist') {
  50381. // Avoid errors below, since the renderTasks are just stubs.
  50382. return;
  50383. }
  50384. var intentState = this.intentStates[intent];
  50385. intentState.renderTasks.forEach(function (renderTask) {
  50386. var renderCompleted = renderTask.capability.promise.catch(function () {
  50387. });
  50388. // ignoring failures
  50389. waitOn.push(renderCompleted);
  50390. renderTask.cancel();
  50391. });
  50392. }, this);
  50393. this.objs.clear();
  50394. this.annotationsPromise = null;
  50395. this.pendingCleanup = false;
  50396. return Promise.all(waitOn);
  50397. },
  50398. /**
  50399. * Cleans up resources allocated by the page. (deprecated)
  50400. */
  50401. destroy: function () {
  50402. deprecated('page destroy method, use cleanup() instead');
  50403. this.cleanup();
  50404. },
  50405. /**
  50406. * Cleans up resources allocated by the page.
  50407. */
  50408. cleanup: function PDFPageProxy_cleanup() {
  50409. this.pendingCleanup = true;
  50410. this._tryCleanup();
  50411. },
  50412. /**
  50413. * For internal use only. Attempts to clean up if rendering is in a state
  50414. * where that's possible.
  50415. * @ignore
  50416. */
  50417. _tryCleanup: function PDFPageProxy_tryCleanup() {
  50418. if (!this.pendingCleanup || Object.keys(this.intentStates).some(function (intent) {
  50419. var intentState = this.intentStates[intent];
  50420. return intentState.renderTasks.length !== 0 || intentState.receivingOperatorList;
  50421. }, this)) {
  50422. return;
  50423. }
  50424. Object.keys(this.intentStates).forEach(function (intent) {
  50425. delete this.intentStates[intent];
  50426. }, this);
  50427. this.objs.clear();
  50428. this.annotationsPromise = null;
  50429. this.pendingCleanup = false;
  50430. },
  50431. /**
  50432. * For internal use only.
  50433. * @ignore
  50434. */
  50435. _startRenderPage: function PDFPageProxy_startRenderPage(transparency, intent) {
  50436. var intentState = this.intentStates[intent];
  50437. // TODO Refactor RenderPageRequest to separate rendering
  50438. // and operator list logic
  50439. if (intentState.displayReadyCapability) {
  50440. intentState.displayReadyCapability.resolve(transparency);
  50441. }
  50442. },
  50443. /**
  50444. * For internal use only.
  50445. * @ignore
  50446. */
  50447. _renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk, intent) {
  50448. var intentState = this.intentStates[intent];
  50449. var i, ii;
  50450. // Add the new chunk to the current operator list.
  50451. for (i = 0, ii = operatorListChunk.length; i < ii; i++) {
  50452. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  50453. intentState.operatorList.argsArray.push(operatorListChunk.argsArray[i]);
  50454. }
  50455. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  50456. // Notify all the rendering tasks there are more operators to be consumed.
  50457. for (i = 0; i < intentState.renderTasks.length; i++) {
  50458. intentState.renderTasks[i].operatorListChanged();
  50459. }
  50460. if (operatorListChunk.lastChunk) {
  50461. intentState.receivingOperatorList = false;
  50462. this._tryCleanup();
  50463. }
  50464. }
  50465. };
  50466. return PDFPageProxy;
  50467. }();
  50468. /**
  50469. * PDF.js web worker abstraction, it controls instantiation of PDF documents and
  50470. * WorkerTransport for them. If creation of a web worker is not possible,
  50471. * a "fake" worker will be used instead.
  50472. * @class
  50473. */
  50474. var PDFWorker = function PDFWorkerClosure() {
  50475. var nextFakeWorkerId = 0;
  50476. function getWorkerSrc() {
  50477. if (typeof workerSrc !== 'undefined') {
  50478. return workerSrc;
  50479. }
  50480. if (getDefaultSetting('workerSrc')) {
  50481. return getDefaultSetting('workerSrc');
  50482. }
  50483. if (pdfjsFilePath) {
  50484. return pdfjsFilePath.replace(/\.js$/i, '.worker.js');
  50485. }
  50486. error('No PDFJS.workerSrc specified');
  50487. }
  50488. var fakeWorkerFilesLoadedCapability;
  50489. // Loads worker code into main thread.
  50490. function setupFakeWorkerGlobal() {
  50491. var WorkerMessageHandler;
  50492. if (fakeWorkerFilesLoadedCapability) {
  50493. return fakeWorkerFilesLoadedCapability.promise;
  50494. }
  50495. fakeWorkerFilesLoadedCapability = createPromiseCapability();
  50496. WorkerMessageHandler = pdfjsLibs.pdfjsCoreWorker.WorkerMessageHandler;
  50497. fakeWorkerFilesLoadedCapability.resolve(WorkerMessageHandler);
  50498. return fakeWorkerFilesLoadedCapability.promise;
  50499. }
  50500. function FakeWorkerPort(defer) {
  50501. this._listeners = [];
  50502. this._defer = defer;
  50503. this._deferred = Promise.resolve(undefined);
  50504. }
  50505. FakeWorkerPort.prototype = {
  50506. postMessage: function (obj, transfers) {
  50507. function cloneValue(value) {
  50508. // Trying to perform a structured clone close to the spec, including
  50509. // transfers.
  50510. if (typeof value !== 'object' || value === null) {
  50511. return value;
  50512. }
  50513. if (cloned.has(value)) {
  50514. // already cloned the object
  50515. return cloned.get(value);
  50516. }
  50517. var result;
  50518. var buffer;
  50519. if ((buffer = value.buffer) && isArrayBuffer(buffer)) {
  50520. // We found object with ArrayBuffer (typed array).
  50521. var transferable = transfers && transfers.indexOf(buffer) >= 0;
  50522. if (value === buffer) {
  50523. // Special case when we are faking typed arrays in compatibility.js.
  50524. result = value;
  50525. } else if (transferable) {
  50526. result = new value.constructor(buffer, value.byteOffset, value.byteLength);
  50527. } else {
  50528. result = new value.constructor(value);
  50529. }
  50530. cloned.set(value, result);
  50531. return result;
  50532. }
  50533. result = isArray(value) ? [] : {};
  50534. cloned.set(value, result);
  50535. // adding to cache now for cyclic references
  50536. // Cloning all value and object properties, however ignoring properties
  50537. // defined via getter.
  50538. for (var i in value) {
  50539. var desc, p = value;
  50540. while (!(desc = Object.getOwnPropertyDescriptor(p, i))) {
  50541. p = Object.getPrototypeOf(p);
  50542. }
  50543. if (typeof desc.value === 'undefined' || typeof desc.value === 'function') {
  50544. continue;
  50545. }
  50546. result[i] = cloneValue(desc.value);
  50547. }
  50548. return result;
  50549. }
  50550. if (!this._defer) {
  50551. this._listeners.forEach(function (listener) {
  50552. listener.call(this, { data: obj });
  50553. }, this);
  50554. return;
  50555. }
  50556. var cloned = new WeakMap();
  50557. var e = { data: cloneValue(obj) };
  50558. this._deferred.then(function () {
  50559. this._listeners.forEach(function (listener) {
  50560. listener.call(this, e);
  50561. }, this);
  50562. }.bind(this));
  50563. },
  50564. addEventListener: function (name, listener) {
  50565. this._listeners.push(listener);
  50566. },
  50567. removeEventListener: function (name, listener) {
  50568. var i = this._listeners.indexOf(listener);
  50569. this._listeners.splice(i, 1);
  50570. },
  50571. terminate: function () {
  50572. this._listeners = [];
  50573. }
  50574. };
  50575. function createCDNWrapper(url) {
  50576. // We will rely on blob URL's property to specify origin.
  50577. // We want this function to fail in case if createObjectURL or Blob do not
  50578. // exist or fail for some reason -- our Worker creation will fail anyway.
  50579. var wrapper = 'importScripts(\'' + url + '\');';
  50580. return URL.createObjectURL(new Blob([wrapper]));
  50581. }
  50582. function PDFWorker(name) {
  50583. this.name = name;
  50584. this.destroyed = false;
  50585. this._readyCapability = createPromiseCapability();
  50586. this._port = null;
  50587. this._webWorker = null;
  50588. this._messageHandler = null;
  50589. this._initialize();
  50590. }
  50591. PDFWorker.prototype = /** @lends PDFWorker.prototype */
  50592. {
  50593. get promise() {
  50594. return this._readyCapability.promise;
  50595. },
  50596. get port() {
  50597. return this._port;
  50598. },
  50599. get messageHandler() {
  50600. return this._messageHandler;
  50601. },
  50602. _initialize: function PDFWorker_initialize() {
  50603. // Either workers are disabled, not supported or have thrown an exception.
  50604. // Thus, we fallback to a faked worker.
  50605. this._setupFakeWorker();
  50606. },
  50607. _setupFakeWorker: function PDFWorker_setupFakeWorker() {
  50608. if (!isWorkerDisabled && !getDefaultSetting('disableWorker')) {
  50609. warn('Setting up fake worker.');
  50610. isWorkerDisabled = true;
  50611. }
  50612. setupFakeWorkerGlobal().then(function (WorkerMessageHandler) {
  50613. if (this.destroyed) {
  50614. this._readyCapability.reject(new Error('Worker was destroyed'));
  50615. return;
  50616. }
  50617. // We cannot turn on proper fake port simulation (this includes
  50618. // structured cloning) when typed arrays are not supported. Relying
  50619. // on a chance that messages will be sent in proper order.
  50620. var isTypedArraysPresent = Uint8Array !== Float32Array;
  50621. var port = new FakeWorkerPort(isTypedArraysPresent);
  50622. this._port = port;
  50623. // All fake workers use the same port, making id unique.
  50624. var id = 'fake' + nextFakeWorkerId++;
  50625. // If the main thread is our worker, setup the handling for the
  50626. // messages -- the main thread sends to it self.
  50627. var workerHandler = new MessageHandler(id + '_worker', id, port);
  50628. WorkerMessageHandler.setup(workerHandler, port);
  50629. var messageHandler = new MessageHandler(id, id + '_worker', port);
  50630. this._messageHandler = messageHandler;
  50631. this._readyCapability.resolve();
  50632. }.bind(this));
  50633. },
  50634. /**
  50635. * Destroys the worker instance.
  50636. */
  50637. destroy: function PDFWorker_destroy() {
  50638. this.destroyed = true;
  50639. if (this._webWorker) {
  50640. // We need to terminate only web worker created resource.
  50641. this._webWorker.terminate();
  50642. this._webWorker = null;
  50643. }
  50644. this._port = null;
  50645. if (this._messageHandler) {
  50646. this._messageHandler.destroy();
  50647. this._messageHandler = null;
  50648. }
  50649. }
  50650. };
  50651. return PDFWorker;
  50652. }();
  50653. /**
  50654. * For internal use only.
  50655. * @ignore
  50656. */
  50657. var WorkerTransport = function WorkerTransportClosure() {
  50658. function WorkerTransport(messageHandler, loadingTask, pdfDataRangeTransport) {
  50659. this.messageHandler = messageHandler;
  50660. this.loadingTask = loadingTask;
  50661. this.pdfDataRangeTransport = pdfDataRangeTransport;
  50662. this.commonObjs = new PDFObjects();
  50663. this.fontLoader = new FontLoader(loadingTask.docId);
  50664. this.destroyed = false;
  50665. this.destroyCapability = null;
  50666. this.pageCache = [];
  50667. this.pagePromises = [];
  50668. this.downloadInfoCapability = createPromiseCapability();
  50669. this.setupMessageHandler();
  50670. }
  50671. WorkerTransport.prototype = {
  50672. destroy: function WorkerTransport_destroy() {
  50673. if (this.destroyCapability) {
  50674. return this.destroyCapability.promise;
  50675. }
  50676. this.destroyed = true;
  50677. this.destroyCapability = createPromiseCapability();
  50678. var waitOn = [];
  50679. // We need to wait for all renderings to be completed, e.g.
  50680. // timeout/rAF can take a long time.
  50681. this.pageCache.forEach(function (page) {
  50682. if (page) {
  50683. waitOn.push(page._destroy());
  50684. }
  50685. });
  50686. this.pageCache = [];
  50687. this.pagePromises = [];
  50688. var self = this;
  50689. // We also need to wait for the worker to finish its long running tasks.
  50690. var terminated = this.messageHandler.sendWithPromise('Terminate', null);
  50691. waitOn.push(terminated);
  50692. Promise.all(waitOn).then(function () {
  50693. self.fontLoader.clear();
  50694. if (self.pdfDataRangeTransport) {
  50695. self.pdfDataRangeTransport.abort();
  50696. self.pdfDataRangeTransport = null;
  50697. }
  50698. if (self.messageHandler) {
  50699. self.messageHandler.destroy();
  50700. self.messageHandler = null;
  50701. }
  50702. self.destroyCapability.resolve();
  50703. }, this.destroyCapability.reject);
  50704. return this.destroyCapability.promise;
  50705. },
  50706. setupMessageHandler: function WorkerTransport_setupMessageHandler() {
  50707. var messageHandler = this.messageHandler;
  50708. function updatePassword(password) {
  50709. messageHandler.send('UpdatePassword', password);
  50710. }
  50711. var pdfDataRangeTransport = this.pdfDataRangeTransport;
  50712. if (pdfDataRangeTransport) {
  50713. pdfDataRangeTransport.addRangeListener(function (begin, chunk) {
  50714. messageHandler.send('OnDataRange', {
  50715. begin: begin,
  50716. chunk: chunk
  50717. });
  50718. });
  50719. pdfDataRangeTransport.addProgressListener(function (loaded) {
  50720. messageHandler.send('OnDataProgress', { loaded: loaded });
  50721. });
  50722. pdfDataRangeTransport.addProgressiveReadListener(function (chunk) {
  50723. messageHandler.send('OnDataRange', { chunk: chunk });
  50724. });
  50725. messageHandler.on('RequestDataRange', function transportDataRange(data) {
  50726. pdfDataRangeTransport.requestDataRange(data.begin, data.end);
  50727. }, this);
  50728. }
  50729. messageHandler.on('GetDoc', function transportDoc(data) {
  50730. var pdfInfo = data.pdfInfo;
  50731. this.numPages = data.pdfInfo.numPages;
  50732. var loadingTask = this.loadingTask;
  50733. var pdfDocument = new PDFDocumentProxy(pdfInfo, this, loadingTask);
  50734. this.pdfDocument = pdfDocument;
  50735. loadingTask._capability.resolve(pdfDocument);
  50736. }, this);
  50737. messageHandler.on('NeedPassword', function transportNeedPassword(exception) {
  50738. var loadingTask = this.loadingTask;
  50739. if (loadingTask.onPassword) {
  50740. return loadingTask.onPassword(updatePassword, PasswordResponses.NEED_PASSWORD);
  50741. }
  50742. loadingTask._capability.reject(new PasswordException(exception.message, exception.code));
  50743. }, this);
  50744. messageHandler.on('IncorrectPassword', function transportIncorrectPassword(exception) {
  50745. var loadingTask = this.loadingTask;
  50746. if (loadingTask.onPassword) {
  50747. return loadingTask.onPassword(updatePassword, PasswordResponses.INCORRECT_PASSWORD);
  50748. }
  50749. loadingTask._capability.reject(new PasswordException(exception.message, exception.code));
  50750. }, this);
  50751. messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) {
  50752. this.loadingTask._capability.reject(new InvalidPDFException(exception.message));
  50753. }, this);
  50754. messageHandler.on('MissingPDF', function transportMissingPDF(exception) {
  50755. this.loadingTask._capability.reject(new MissingPDFException(exception.message));
  50756. }, this);
  50757. messageHandler.on('UnexpectedResponse', function transportUnexpectedResponse(exception) {
  50758. this.loadingTask._capability.reject(new UnexpectedResponseException(exception.message, exception.status));
  50759. }, this);
  50760. messageHandler.on('UnknownError', function transportUnknownError(exception) {
  50761. this.loadingTask._capability.reject(new UnknownErrorException(exception.message, exception.details));
  50762. }, this);
  50763. messageHandler.on('DataLoaded', function transportPage(data) {
  50764. this.downloadInfoCapability.resolve(data);
  50765. }, this);
  50766. messageHandler.on('PDFManagerReady', function transportPage(data) {
  50767. if (this.pdfDataRangeTransport) {
  50768. this.pdfDataRangeTransport.transportReady();
  50769. }
  50770. }, this);
  50771. messageHandler.on('StartRenderPage', function transportRender(data) {
  50772. if (this.destroyed) {
  50773. return;
  50774. }
  50775. // Ignore any pending requests if the worker was terminated.
  50776. var page = this.pageCache[data.pageIndex];
  50777. page.stats.timeEnd('Page Request');
  50778. page._startRenderPage(data.transparency, data.intent);
  50779. }, this);
  50780. messageHandler.on('RenderPageChunk', function transportRender(data) {
  50781. if (this.destroyed) {
  50782. return;
  50783. }
  50784. // Ignore any pending requests if the worker was terminated.
  50785. var page = this.pageCache[data.pageIndex];
  50786. page._renderPageChunk(data.operatorList, data.intent);
  50787. }, this);
  50788. messageHandler.on('commonobj', function transportObj(data) {
  50789. if (this.destroyed) {
  50790. return;
  50791. }
  50792. // Ignore any pending requests if the worker was terminated.
  50793. var id = data[0];
  50794. var type = data[1];
  50795. if (this.commonObjs.hasData(id)) {
  50796. return;
  50797. }
  50798. switch (type) {
  50799. case 'Font':
  50800. var exportedData = data[2];
  50801. if ('error' in exportedData) {
  50802. var exportedError = exportedData.error;
  50803. warn('Error during font loading: ' + exportedError);
  50804. this.commonObjs.resolve(id, exportedError);
  50805. break;
  50806. }
  50807. var fontRegistry = null;
  50808. if (getDefaultSetting('pdfBug') && globalScope.FontInspector && globalScope['FontInspector'].enabled) {
  50809. fontRegistry = {
  50810. registerFont: function (font, url) {
  50811. globalScope['FontInspector'].fontAdded(font, url);
  50812. }
  50813. };
  50814. }
  50815. var font = new FontFaceObject(exportedData, {
  50816. isEvalSuported: getDefaultSetting('isEvalSupported'),
  50817. disableFontFace: getDefaultSetting('disableFontFace'),
  50818. fontRegistry: fontRegistry
  50819. });
  50820. this.fontLoader.bind([font], function fontReady(fontObjs) {
  50821. this.commonObjs.resolve(id, font);
  50822. }.bind(this));
  50823. break;
  50824. case 'FontPath':
  50825. this.commonObjs.resolve(id, data[2]);
  50826. break;
  50827. default:
  50828. error('Got unknown common object type ' + type);
  50829. }
  50830. }, this);
  50831. messageHandler.on('obj', function transportObj(data) {
  50832. if (this.destroyed) {
  50833. return;
  50834. }
  50835. // Ignore any pending requests if the worker was terminated.
  50836. var id = data[0];
  50837. var pageIndex = data[1];
  50838. var type = data[2];
  50839. var pageProxy = this.pageCache[pageIndex];
  50840. var imageData;
  50841. if (pageProxy.objs.hasData(id)) {
  50842. return;
  50843. }
  50844. switch (type) {
  50845. case 'JpegStream':
  50846. imageData = data[3];
  50847. loadJpegStream(id, imageData, pageProxy.objs);
  50848. break;
  50849. case 'Image':
  50850. imageData = data[3];
  50851. pageProxy.objs.resolve(id, imageData);
  50852. // heuristics that will allow not to store large data
  50853. var MAX_IMAGE_SIZE_TO_STORE = 8000000;
  50854. if (imageData && 'data' in imageData && imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
  50855. pageProxy.cleanupAfterRender = true;
  50856. }
  50857. break;
  50858. default:
  50859. error('Got unknown object type ' + type);
  50860. }
  50861. }, this);
  50862. messageHandler.on('DocProgress', function transportDocProgress(data) {
  50863. if (this.destroyed) {
  50864. return;
  50865. }
  50866. // Ignore any pending requests if the worker was terminated.
  50867. var loadingTask = this.loadingTask;
  50868. if (loadingTask.onProgress) {
  50869. loadingTask.onProgress({
  50870. loaded: data.loaded,
  50871. total: data.total
  50872. });
  50873. }
  50874. }, this);
  50875. messageHandler.on('PageError', function transportError(data) {
  50876. if (this.destroyed) {
  50877. return;
  50878. }
  50879. // Ignore any pending requests if the worker was terminated.
  50880. var page = this.pageCache[data.pageNum - 1];
  50881. var intentState = page.intentStates[data.intent];
  50882. if (intentState.displayReadyCapability) {
  50883. intentState.displayReadyCapability.reject(data.error);
  50884. } else {
  50885. error(data.error);
  50886. }
  50887. if (intentState.operatorList) {
  50888. // Mark operator list as complete.
  50889. intentState.operatorList.lastChunk = true;
  50890. for (var i = 0; i < intentState.renderTasks.length; i++) {
  50891. intentState.renderTasks[i].operatorListChanged();
  50892. }
  50893. }
  50894. }, this);
  50895. messageHandler.on('UnsupportedFeature', function transportUnsupportedFeature(data) {
  50896. if (this.destroyed) {
  50897. return;
  50898. }
  50899. // Ignore any pending requests if the worker was terminated.
  50900. var featureId = data.featureId;
  50901. var loadingTask = this.loadingTask;
  50902. if (loadingTask.onUnsupportedFeature) {
  50903. loadingTask.onUnsupportedFeature(featureId);
  50904. }
  50905. _UnsupportedManager.notify(featureId);
  50906. }, this);
  50907. messageHandler.on('JpegDecode', function (data) {
  50908. if (this.destroyed) {
  50909. return Promise.reject(new Error('Worker was destroyed'));
  50910. }
  50911. var imageUrl = data[0];
  50912. var components = data[1];
  50913. if (components !== 3 && components !== 1) {
  50914. return Promise.reject(new Error('Only 3 components or 1 component can be returned'));
  50915. }
  50916. return new Promise(function (resolve, reject) {
  50917. var img = new Image();
  50918. img.onload = function () {
  50919. var width = img.width;
  50920. var height = img.height;
  50921. var size = width * height;
  50922. var rgbaLength = size * 4;
  50923. var buf = new Uint8Array(size * components);
  50924. var tmpCanvas = createScratchCanvas(width, height);
  50925. var tmpCtx = tmpCanvas.getContext('2d');
  50926. tmpCtx.drawImage(img, 0, 0);
  50927. var data = tmpCtx.getImageData(0, 0, width, height).data;
  50928. var i, j;
  50929. if (components === 3) {
  50930. for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
  50931. buf[j] = data[i];
  50932. buf[j + 1] = data[i + 1];
  50933. buf[j + 2] = data[i + 2];
  50934. }
  50935. } else if (components === 1) {
  50936. for (i = 0, j = 0; i < rgbaLength; i += 4, j++) {
  50937. buf[j] = data[i];
  50938. }
  50939. }
  50940. resolve({
  50941. data: buf,
  50942. width: width,
  50943. height: height
  50944. });
  50945. };
  50946. img.onerror = function () {
  50947. reject(new Error('JpegDecode failed to load image'));
  50948. };
  50949. img.src = imageUrl;
  50950. });
  50951. }, this);
  50952. },
  50953. getData: function WorkerTransport_getData() {
  50954. return this.messageHandler.sendWithPromise('GetData', null);
  50955. },
  50956. getPage: function WorkerTransport_getPage(pageNumber, capability) {
  50957. if (!isInt(pageNumber) || pageNumber <= 0 || pageNumber > this.numPages) {
  50958. return Promise.reject(new Error('Invalid page request'));
  50959. }
  50960. var pageIndex = pageNumber - 1;
  50961. if (pageIndex in this.pagePromises) {
  50962. return this.pagePromises[pageIndex];
  50963. }
  50964. var promise = this.messageHandler.sendWithPromise('GetPage', { pageIndex: pageIndex }).then(function (pageInfo) {
  50965. if (this.destroyed) {
  50966. throw new Error('Transport destroyed');
  50967. }
  50968. var page = new PDFPageProxy(pageIndex, pageInfo, this);
  50969. this.pageCache[pageIndex] = page;
  50970. return page;
  50971. }.bind(this));
  50972. this.pagePromises[pageIndex] = promise;
  50973. return promise;
  50974. },
  50975. getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
  50976. return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref }).catch(function (reason) {
  50977. return Promise.reject(new Error(reason));
  50978. });
  50979. },
  50980. getAnnotations: function WorkerTransport_getAnnotations(pageIndex, intent) {
  50981. return this.messageHandler.sendWithPromise('GetAnnotations', {
  50982. pageIndex: pageIndex,
  50983. intent: intent
  50984. });
  50985. },
  50986. getDestinations: function WorkerTransport_getDestinations() {
  50987. return this.messageHandler.sendWithPromise('GetDestinations', null);
  50988. },
  50989. getDestination: function WorkerTransport_getDestination(id) {
  50990. return this.messageHandler.sendWithPromise('GetDestination', { id: id });
  50991. },
  50992. getPageLabels: function WorkerTransport_getPageLabels() {
  50993. return this.messageHandler.sendWithPromise('GetPageLabels', null);
  50994. },
  50995. getAttachments: function WorkerTransport_getAttachments() {
  50996. return this.messageHandler.sendWithPromise('GetAttachments', null);
  50997. },
  50998. getJavaScript: function WorkerTransport_getJavaScript() {
  50999. return this.messageHandler.sendWithPromise('GetJavaScript', null);
  51000. },
  51001. getOutline: function WorkerTransport_getOutline() {
  51002. return this.messageHandler.sendWithPromise('GetOutline', null);
  51003. },
  51004. getMetadata: function WorkerTransport_getMetadata() {
  51005. return this.messageHandler.sendWithPromise('GetMetadata', null).then(function transportMetadata(results) {
  51006. return {
  51007. info: results[0],
  51008. metadata: results[1] ? new Metadata(results[1]) : null
  51009. };
  51010. });
  51011. },
  51012. getStats: function WorkerTransport_getStats() {
  51013. return this.messageHandler.sendWithPromise('GetStats', null);
  51014. },
  51015. startCleanup: function WorkerTransport_startCleanup() {
  51016. this.messageHandler.sendWithPromise('Cleanup', null).then(function endCleanup() {
  51017. for (var i = 0, ii = this.pageCache.length; i < ii; i++) {
  51018. var page = this.pageCache[i];
  51019. if (page) {
  51020. page.cleanup();
  51021. }
  51022. }
  51023. this.commonObjs.clear();
  51024. this.fontLoader.clear();
  51025. }.bind(this));
  51026. }
  51027. };
  51028. return WorkerTransport;
  51029. }();
  51030. /**
  51031. * A PDF document and page is built of many objects. E.g. there are objects
  51032. * for fonts, images, rendering code and such. These objects might get processed
  51033. * inside of a worker. The `PDFObjects` implements some basic functions to
  51034. * manage these objects.
  51035. * @ignore
  51036. */
  51037. var PDFObjects = function PDFObjectsClosure() {
  51038. function PDFObjects() {
  51039. this.objs = Object.create(null);
  51040. }
  51041. PDFObjects.prototype = {
  51042. /**
  51043. * Internal function.
  51044. * Ensures there is an object defined for `objId`.
  51045. */
  51046. ensureObj: function PDFObjects_ensureObj(objId) {
  51047. if (this.objs[objId]) {
  51048. return this.objs[objId];
  51049. }
  51050. var obj = {
  51051. capability: createPromiseCapability(),
  51052. data: null,
  51053. resolved: false
  51054. };
  51055. this.objs[objId] = obj;
  51056. return obj;
  51057. },
  51058. /**
  51059. * If called *without* callback, this returns the data of `objId` but the
  51060. * object needs to be resolved. If it isn't, this function throws.
  51061. *
  51062. * If called *with* a callback, the callback is called with the data of the
  51063. * object once the object is resolved. That means, if you call this
  51064. * function and the object is already resolved, the callback gets called
  51065. * right away.
  51066. */
  51067. get: function PDFObjects_get(objId, callback) {
  51068. // If there is a callback, then the get can be async and the object is
  51069. // not required to be resolved right now
  51070. if (callback) {
  51071. this.ensureObj(objId).capability.promise.then(callback);
  51072. return null;
  51073. }
  51074. // If there isn't a callback, the user expects to get the resolved data
  51075. // directly.
  51076. var obj = this.objs[objId];
  51077. // If there isn't an object yet or the object isn't resolved, then the
  51078. // data isn't ready yet!
  51079. if (!obj || !obj.resolved) {
  51080. error('Requesting object that isn\'t resolved yet ' + objId);
  51081. }
  51082. return obj.data;
  51083. },
  51084. /**
  51085. * Resolves the object `objId` with optional `data`.
  51086. */
  51087. resolve: function PDFObjects_resolve(objId, data) {
  51088. var obj = this.ensureObj(objId);
  51089. obj.resolved = true;
  51090. obj.data = data;
  51091. obj.capability.resolve(data);
  51092. },
  51093. isResolved: function PDFObjects_isResolved(objId) {
  51094. var objs = this.objs;
  51095. if (!objs[objId]) {
  51096. return false;
  51097. } else {
  51098. return objs[objId].resolved;
  51099. }
  51100. },
  51101. hasData: function PDFObjects_hasData(objId) {
  51102. return this.isResolved(objId);
  51103. },
  51104. /**
  51105. * Returns the data of `objId` if object exists, null otherwise.
  51106. */
  51107. getData: function PDFObjects_getData(objId) {
  51108. var objs = this.objs;
  51109. if (!objs[objId] || !objs[objId].resolved) {
  51110. return null;
  51111. } else {
  51112. return objs[objId].data;
  51113. }
  51114. },
  51115. clear: function PDFObjects_clear() {
  51116. this.objs = Object.create(null);
  51117. }
  51118. };
  51119. return PDFObjects;
  51120. }();
  51121. /**
  51122. * Allows controlling of the rendering tasks.
  51123. * @class
  51124. * @alias RenderTask
  51125. */
  51126. var RenderTask = function RenderTaskClosure() {
  51127. function RenderTask(internalRenderTask) {
  51128. this._internalRenderTask = internalRenderTask;
  51129. /**
  51130. * Callback for incremental rendering -- a function that will be called
  51131. * each time the rendering is paused. To continue rendering call the
  51132. * function that is the first argument to the callback.
  51133. * @type {function}
  51134. */
  51135. this.onContinue = null;
  51136. }
  51137. RenderTask.prototype = /** @lends RenderTask.prototype */
  51138. {
  51139. /**
  51140. * Promise for rendering task completion.
  51141. * @return {Promise}
  51142. */
  51143. get promise() {
  51144. return this._internalRenderTask.capability.promise;
  51145. },
  51146. /**
  51147. * Cancels the rendering task. If the task is currently rendering it will
  51148. * not be cancelled until graphics pauses with a timeout. The promise that
  51149. * this object extends will resolved when cancelled.
  51150. */
  51151. cancel: function RenderTask_cancel() {
  51152. this._internalRenderTask.cancel();
  51153. },
  51154. /**
  51155. * Registers callbacks to indicate the rendering task completion.
  51156. *
  51157. * @param {function} onFulfilled The callback for the rendering completion.
  51158. * @param {function} onRejected The callback for the rendering failure.
  51159. * @return {Promise} A promise that is resolved after the onFulfilled or
  51160. * onRejected callback.
  51161. */
  51162. then: function RenderTask_then(onFulfilled, onRejected) {
  51163. return this.promise.then.apply(this.promise, arguments);
  51164. }
  51165. };
  51166. return RenderTask;
  51167. }();
  51168. /**
  51169. * For internal use only.
  51170. * @ignore
  51171. */
  51172. var InternalRenderTask = function InternalRenderTaskClosure() {
  51173. function InternalRenderTask(callback, params, objs, commonObjs, operatorList, pageNumber) {
  51174. this.callback = callback;
  51175. this.params = params;
  51176. this.objs = objs;
  51177. this.commonObjs = commonObjs;
  51178. this.operatorListIdx = null;
  51179. this.operatorList = operatorList;
  51180. this.pageNumber = pageNumber;
  51181. this.running = false;
  51182. this.graphicsReadyCallback = null;
  51183. this.graphicsReady = false;
  51184. this.useRequestAnimationFrame = false;
  51185. this.cancelled = false;
  51186. this.capability = createPromiseCapability();
  51187. this.task = new RenderTask(this);
  51188. // caching this-bound methods
  51189. this._continueBound = this._continue.bind(this);
  51190. this._scheduleNextBound = this._scheduleNext.bind(this);
  51191. this._nextBound = this._next.bind(this);
  51192. }
  51193. InternalRenderTask.prototype = {
  51194. initializeGraphics: function InternalRenderTask_initializeGraphics(transparency) {
  51195. if (this.cancelled) {
  51196. return;
  51197. }
  51198. if (getDefaultSetting('pdfBug') && globalScope.StepperManager && globalScope.StepperManager.enabled) {
  51199. this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
  51200. this.stepper.init(this.operatorList);
  51201. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  51202. }
  51203. var params = this.params;
  51204. this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs, this.objs, params.imageLayer);
  51205. this.gfx.beginDrawing(params.transform, params.viewport, transparency);
  51206. this.operatorListIdx = 0;
  51207. this.graphicsReady = true;
  51208. if (this.graphicsReadyCallback) {
  51209. this.graphicsReadyCallback();
  51210. }
  51211. },
  51212. cancel: function InternalRenderTask_cancel() {
  51213. this.running = false;
  51214. this.cancelled = true;
  51215. this.callback('cancelled');
  51216. },
  51217. operatorListChanged: function InternalRenderTask_operatorListChanged() {
  51218. if (!this.graphicsReady) {
  51219. if (!this.graphicsReadyCallback) {
  51220. this.graphicsReadyCallback = this._continueBound;
  51221. }
  51222. return;
  51223. }
  51224. if (this.stepper) {
  51225. this.stepper.updateOperatorList(this.operatorList);
  51226. }
  51227. if (this.running) {
  51228. return;
  51229. }
  51230. this._continue();
  51231. },
  51232. _continue: function InternalRenderTask__continue() {
  51233. this.running = true;
  51234. if (this.cancelled) {
  51235. return;
  51236. }
  51237. if (this.task.onContinue) {
  51238. this.task.onContinue.call(this.task, this._scheduleNextBound);
  51239. } else {
  51240. this._scheduleNext();
  51241. }
  51242. },
  51243. _scheduleNext: function InternalRenderTask__scheduleNext() {
  51244. if (this.useRequestAnimationFrame && typeof window !== 'undefined') {
  51245. window.requestAnimationFrame(this._nextBound);
  51246. } else {
  51247. Promise.resolve(undefined).then(this._nextBound);
  51248. }
  51249. },
  51250. _next: function InternalRenderTask__next() {
  51251. if (this.cancelled) {
  51252. return;
  51253. }
  51254. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList, this.operatorListIdx, this._continueBound, this.stepper);
  51255. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  51256. this.running = false;
  51257. if (this.operatorList.lastChunk) {
  51258. this.gfx.endDrawing();
  51259. this.callback();
  51260. }
  51261. }
  51262. }
  51263. };
  51264. return InternalRenderTask;
  51265. }();
  51266. /**
  51267. * (Deprecated) Global observer of unsupported feature usages. Use
  51268. * onUnsupportedFeature callback of the {PDFDocumentLoadingTask} instance.
  51269. */
  51270. var _UnsupportedManager = function UnsupportedManagerClosure() {
  51271. var listeners = [];
  51272. return {
  51273. listen: function (cb) {
  51274. deprecated('Global UnsupportedManager.listen is used: ' + ' use PDFDocumentLoadingTask.onUnsupportedFeature instead');
  51275. listeners.push(cb);
  51276. },
  51277. notify: function (featureId) {
  51278. for (var i = 0, ii = listeners.length; i < ii; i++) {
  51279. listeners[i](featureId);
  51280. }
  51281. }
  51282. };
  51283. }();
  51284. if (typeof pdfjsVersion !== 'undefined') {
  51285. exports.version = pdfjsVersion;
  51286. }
  51287. if (typeof pdfjsBuild !== 'undefined') {
  51288. exports.build = pdfjsBuild;
  51289. }
  51290. exports.getDocument = getDocument;
  51291. exports.PDFDataRangeTransport = PDFDataRangeTransport;
  51292. exports.PDFWorker = PDFWorker;
  51293. exports.PDFDocumentProxy = PDFDocumentProxy;
  51294. exports.PDFPageProxy = PDFPageProxy;
  51295. exports._UnsupportedManager = _UnsupportedManager;
  51296. }));
  51297. (function (root, factory) {
  51298. factory(root.pdfjsCoreColorSpace = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreFunction);
  51299. }(this, function (exports, sharedUtil, corePrimitives, coreFunction) {
  51300. var error = sharedUtil.error;
  51301. var info = sharedUtil.info;
  51302. var isArray = sharedUtil.isArray;
  51303. var isString = sharedUtil.isString;
  51304. var shadow = sharedUtil.shadow;
  51305. var warn = sharedUtil.warn;
  51306. var isDict = corePrimitives.isDict;
  51307. var isName = corePrimitives.isName;
  51308. var isStream = corePrimitives.isStream;
  51309. var PDFFunction = coreFunction.PDFFunction;
  51310. var ColorSpace = function ColorSpaceClosure() {
  51311. /**
  51312. * Resizes an RGB image with 3 components.
  51313. * @param {TypedArray} src - The source buffer.
  51314. * @param {Number} bpc - Number of bits per component.
  51315. * @param {Number} w1 - Original width.
  51316. * @param {Number} h1 - Original height.
  51317. * @param {Number} w2 - New width.
  51318. * @param {Number} h2 - New height.
  51319. * @param {Number} alpha01 - Size reserved for the alpha channel.
  51320. * @param {TypedArray} dest - The destination buffer.
  51321. */
  51322. function resizeRgbImage(src, bpc, w1, h1, w2, h2, alpha01, dest) {
  51323. var COMPONENTS = 3;
  51324. alpha01 = alpha01 !== 1 ? 0 : alpha01;
  51325. var xRatio = w1 / w2;
  51326. var yRatio = h1 / h2;
  51327. var i, j, py, newIndex = 0, oldIndex;
  51328. var xScaled = new Uint16Array(w2);
  51329. var w1Scanline = w1 * COMPONENTS;
  51330. for (i = 0; i < w2; i++) {
  51331. xScaled[i] = Math.floor(i * xRatio) * COMPONENTS;
  51332. }
  51333. for (i = 0; i < h2; i++) {
  51334. py = Math.floor(i * yRatio) * w1Scanline;
  51335. for (j = 0; j < w2; j++) {
  51336. oldIndex = py + xScaled[j];
  51337. dest[newIndex++] = src[oldIndex++];
  51338. dest[newIndex++] = src[oldIndex++];
  51339. dest[newIndex++] = src[oldIndex++];
  51340. newIndex += alpha01;
  51341. }
  51342. }
  51343. }
  51344. // Constructor should define this.numComps, this.defaultColor, this.name
  51345. function ColorSpace() {
  51346. error('should not call ColorSpace constructor');
  51347. }
  51348. ColorSpace.prototype = {
  51349. /**
  51350. * Converts the color value to the RGB color. The color components are
  51351. * located in the src array starting from the srcOffset. Returns the array
  51352. * of the rgb components, each value ranging from [0,255].
  51353. */
  51354. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  51355. var rgb = new Uint8Array(3);
  51356. this.getRgbItem(src, srcOffset, rgb, 0);
  51357. return rgb;
  51358. },
  51359. /**
  51360. * Converts the color value to the RGB color, similar to the getRgb method.
  51361. * The result placed into the dest array starting from the destOffset.
  51362. */
  51363. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset, dest, destOffset) {
  51364. error('Should not call ColorSpace.getRgbItem');
  51365. },
  51366. /**
  51367. * Converts the specified number of the color values to the RGB colors.
  51368. * The colors are located in the src array starting from the srcOffset.
  51369. * The result is placed into the dest array starting from the destOffset.
  51370. * The src array items shall be in [0,2^bits) range, the dest array items
  51371. * will be in [0,255] range. alpha01 indicates how many alpha components
  51372. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  51373. * array).
  51374. */
  51375. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  51376. error('Should not call ColorSpace.getRgbBuffer');
  51377. },
  51378. /**
  51379. * Determines the number of bytes required to store the result of the
  51380. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  51381. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  51382. */
  51383. getOutputLength: function ColorSpace_getOutputLength(inputLength, alpha01) {
  51384. error('Should not call ColorSpace.getOutputLength');
  51385. },
  51386. /**
  51387. * Returns true if source data will be equal the result/output data.
  51388. */
  51389. isPassthrough: function ColorSpace_isPassthrough(bits) {
  51390. return false;
  51391. },
  51392. /**
  51393. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  51394. * how many alpha components there are in the dest array; it will be either
  51395. * 0 (RGB array) or 1 (RGBA array).
  51396. */
  51397. fillRgb: function ColorSpace_fillRgb(dest, originalWidth, originalHeight, width, height, actualHeight, bpc, comps, alpha01) {
  51398. var count = originalWidth * originalHeight;
  51399. var rgbBuf = null;
  51400. var numComponentColors = 1 << bpc;
  51401. var needsResizing = originalHeight !== height || originalWidth !== width;
  51402. var i, ii;
  51403. if (this.isPassthrough(bpc)) {
  51404. rgbBuf = comps;
  51405. } else if (this.numComps === 1 && count > numComponentColors && this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  51406. // Optimization: create a color map when there is just one component and
  51407. // we are converting more colors than the size of the color map. We
  51408. // don't build the map if the colorspace is gray or rgb since those
  51409. // methods are faster than building a map. This mainly offers big speed
  51410. // ups for indexed and alternate colorspaces.
  51411. //
  51412. // TODO it may be worth while to cache the color map. While running
  51413. // testing I never hit a cache so I will leave that out for now (perhaps
  51414. // we are reparsing colorspaces too much?).
  51415. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) : new Uint16Array(numComponentColors);
  51416. var key;
  51417. for (i = 0; i < numComponentColors; i++) {
  51418. allColors[i] = i;
  51419. }
  51420. var colorMap = new Uint8Array(numComponentColors * 3);
  51421. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc, /* alpha01 = */
  51422. 0);
  51423. var destPos, rgbPos;
  51424. if (!needsResizing) {
  51425. // Fill in the RGB values directly into |dest|.
  51426. destPos = 0;
  51427. for (i = 0; i < count; ++i) {
  51428. key = comps[i] * 3;
  51429. dest[destPos++] = colorMap[key];
  51430. dest[destPos++] = colorMap[key + 1];
  51431. dest[destPos++] = colorMap[key + 2];
  51432. destPos += alpha01;
  51433. }
  51434. } else {
  51435. rgbBuf = new Uint8Array(count * 3);
  51436. rgbPos = 0;
  51437. for (i = 0; i < count; ++i) {
  51438. key = comps[i] * 3;
  51439. rgbBuf[rgbPos++] = colorMap[key];
  51440. rgbBuf[rgbPos++] = colorMap[key + 1];
  51441. rgbBuf[rgbPos++] = colorMap[key + 2];
  51442. }
  51443. }
  51444. } else {
  51445. if (!needsResizing) {
  51446. // Fill in the RGB values directly into |dest|.
  51447. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc, alpha01);
  51448. } else {
  51449. rgbBuf = new Uint8Array(count * 3);
  51450. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc, /* alpha01 = */
  51451. 0);
  51452. }
  51453. }
  51454. if (rgbBuf) {
  51455. if (needsResizing) {
  51456. resizeRgbImage(rgbBuf, bpc, originalWidth, originalHeight, width, height, alpha01, dest);
  51457. } else {
  51458. rgbPos = 0;
  51459. destPos = 0;
  51460. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  51461. dest[destPos++] = rgbBuf[rgbPos++];
  51462. dest[destPos++] = rgbBuf[rgbPos++];
  51463. dest[destPos++] = rgbBuf[rgbPos++];
  51464. destPos += alpha01;
  51465. }
  51466. }
  51467. }
  51468. },
  51469. /**
  51470. * True if the colorspace has components in the default range of [0, 1].
  51471. * This should be true for all colorspaces except for lab color spaces
  51472. * which are [0,100], [-128, 127], [-128, 127].
  51473. */
  51474. usesZeroToOneRange: true
  51475. };
  51476. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  51477. var IR = ColorSpace.parseToIR(cs, xref, res);
  51478. if (IR instanceof AlternateCS) {
  51479. return IR;
  51480. }
  51481. return ColorSpace.fromIR(IR);
  51482. };
  51483. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  51484. var name = isArray(IR) ? IR[0] : IR;
  51485. var whitePoint, blackPoint, gamma;
  51486. switch (name) {
  51487. case 'DeviceGrayCS':
  51488. return this.singletons.gray;
  51489. case 'DeviceRgbCS':
  51490. return this.singletons.rgb;
  51491. case 'DeviceCmykCS':
  51492. return this.singletons.cmyk;
  51493. case 'CalGrayCS':
  51494. whitePoint = IR[1];
  51495. blackPoint = IR[2];
  51496. gamma = IR[3];
  51497. return new CalGrayCS(whitePoint, blackPoint, gamma);
  51498. case 'CalRGBCS':
  51499. whitePoint = IR[1];
  51500. blackPoint = IR[2];
  51501. gamma = IR[3];
  51502. var matrix = IR[4];
  51503. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  51504. case 'PatternCS':
  51505. var basePatternCS = IR[1];
  51506. if (basePatternCS) {
  51507. basePatternCS = ColorSpace.fromIR(basePatternCS);
  51508. }
  51509. return new PatternCS(basePatternCS);
  51510. case 'IndexedCS':
  51511. var baseIndexedCS = IR[1];
  51512. var hiVal = IR[2];
  51513. var lookup = IR[3];
  51514. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  51515. case 'AlternateCS':
  51516. var numComps = IR[1];
  51517. var alt = IR[2];
  51518. var tintFnIR = IR[3];
  51519. return new AlternateCS(numComps, ColorSpace.fromIR(alt), PDFFunction.fromIR(tintFnIR));
  51520. case 'LabCS':
  51521. whitePoint = IR[1];
  51522. blackPoint = IR[2];
  51523. var range = IR[3];
  51524. return new LabCS(whitePoint, blackPoint, range);
  51525. default:
  51526. error('Unknown name ' + name);
  51527. }
  51528. return null;
  51529. };
  51530. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  51531. if (isName(cs)) {
  51532. var colorSpaces = res.get('ColorSpace');
  51533. if (isDict(colorSpaces)) {
  51534. var refcs = colorSpaces.get(cs.name);
  51535. if (refcs) {
  51536. cs = refcs;
  51537. }
  51538. }
  51539. }
  51540. cs = xref.fetchIfRef(cs);
  51541. var mode;
  51542. if (isName(cs)) {
  51543. mode = cs.name;
  51544. this.mode = mode;
  51545. switch (mode) {
  51546. case 'DeviceGray':
  51547. case 'G':
  51548. return 'DeviceGrayCS';
  51549. case 'DeviceRGB':
  51550. case 'RGB':
  51551. return 'DeviceRgbCS';
  51552. case 'DeviceCMYK':
  51553. case 'CMYK':
  51554. return 'DeviceCmykCS';
  51555. case 'Pattern':
  51556. return [
  51557. 'PatternCS',
  51558. null
  51559. ];
  51560. default:
  51561. error('unrecognized colorspace ' + mode);
  51562. }
  51563. } else if (isArray(cs)) {
  51564. mode = xref.fetchIfRef(cs[0]).name;
  51565. this.mode = mode;
  51566. var numComps, params, alt, whitePoint, blackPoint, gamma;
  51567. switch (mode) {
  51568. case 'DeviceGray':
  51569. case 'G':
  51570. return 'DeviceGrayCS';
  51571. case 'DeviceRGB':
  51572. case 'RGB':
  51573. return 'DeviceRgbCS';
  51574. case 'DeviceCMYK':
  51575. case 'CMYK':
  51576. return 'DeviceCmykCS';
  51577. case 'CalGray':
  51578. params = xref.fetchIfRef(cs[1]);
  51579. whitePoint = params.getArray('WhitePoint');
  51580. blackPoint = params.getArray('BlackPoint');
  51581. gamma = params.get('Gamma');
  51582. return [
  51583. 'CalGrayCS',
  51584. whitePoint,
  51585. blackPoint,
  51586. gamma
  51587. ];
  51588. case 'CalRGB':
  51589. params = xref.fetchIfRef(cs[1]);
  51590. whitePoint = params.getArray('WhitePoint');
  51591. blackPoint = params.getArray('BlackPoint');
  51592. gamma = params.getArray('Gamma');
  51593. var matrix = params.getArray('Matrix');
  51594. return [
  51595. 'CalRGBCS',
  51596. whitePoint,
  51597. blackPoint,
  51598. gamma,
  51599. matrix
  51600. ];
  51601. case 'ICCBased':
  51602. var stream = xref.fetchIfRef(cs[1]);
  51603. var dict = stream.dict;
  51604. numComps = dict.get('N');
  51605. alt = dict.get('Alternate');
  51606. if (alt) {
  51607. var altIR = ColorSpace.parseToIR(alt, xref, res);
  51608. // Parse the /Alternate CS to ensure that the number of components
  51609. // are correct, and also (indirectly) that it is not a PatternCS.
  51610. var altCS = ColorSpace.fromIR(altIR);
  51611. if (altCS.numComps === numComps) {
  51612. return altIR;
  51613. }
  51614. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  51615. }
  51616. if (numComps === 1) {
  51617. return 'DeviceGrayCS';
  51618. } else if (numComps === 3) {
  51619. return 'DeviceRgbCS';
  51620. } else if (numComps === 4) {
  51621. return 'DeviceCmykCS';
  51622. }
  51623. break;
  51624. case 'Pattern':
  51625. var basePatternCS = cs[1] || null;
  51626. if (basePatternCS) {
  51627. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  51628. }
  51629. return [
  51630. 'PatternCS',
  51631. basePatternCS
  51632. ];
  51633. case 'Indexed':
  51634. case 'I':
  51635. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  51636. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  51637. var lookup = xref.fetchIfRef(cs[3]);
  51638. if (isStream(lookup)) {
  51639. lookup = lookup.getBytes();
  51640. }
  51641. return [
  51642. 'IndexedCS',
  51643. baseIndexedCS,
  51644. hiVal,
  51645. lookup
  51646. ];
  51647. case 'Separation':
  51648. case 'DeviceN':
  51649. var name = xref.fetchIfRef(cs[1]);
  51650. numComps = 1;
  51651. if (isName(name)) {
  51652. numComps = 1;
  51653. } else if (isArray(name)) {
  51654. numComps = name.length;
  51655. }
  51656. alt = ColorSpace.parseToIR(cs[2], xref, res);
  51657. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  51658. return [
  51659. 'AlternateCS',
  51660. numComps,
  51661. alt,
  51662. tintFnIR
  51663. ];
  51664. case 'Lab':
  51665. params = xref.fetchIfRef(cs[1]);
  51666. whitePoint = params.getArray('WhitePoint');
  51667. blackPoint = params.getArray('BlackPoint');
  51668. var range = params.getArray('Range');
  51669. return [
  51670. 'LabCS',
  51671. whitePoint,
  51672. blackPoint,
  51673. range
  51674. ];
  51675. default:
  51676. error('unimplemented color space object "' + mode + '"');
  51677. }
  51678. } else {
  51679. error('unrecognized color space object: "' + cs + '"');
  51680. }
  51681. return null;
  51682. };
  51683. /**
  51684. * Checks if a decode map matches the default decode map for a color space.
  51685. * This handles the general decode maps where there are two values per
  51686. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  51687. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  51688. * slightly different.
  51689. * @param {Array} decode Decode map (usually from an image).
  51690. * @param {Number} n Number of components the color space has.
  51691. */
  51692. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  51693. if (!isArray(decode)) {
  51694. return true;
  51695. }
  51696. if (n * 2 !== decode.length) {
  51697. warn('The decode map is not the correct length');
  51698. return true;
  51699. }
  51700. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  51701. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  51702. return false;
  51703. }
  51704. }
  51705. return true;
  51706. };
  51707. ColorSpace.singletons = {
  51708. get gray() {
  51709. return shadow(this, 'gray', new DeviceGrayCS());
  51710. },
  51711. get rgb() {
  51712. return shadow(this, 'rgb', new DeviceRgbCS());
  51713. },
  51714. get cmyk() {
  51715. return shadow(this, 'cmyk', new DeviceCmykCS());
  51716. }
  51717. };
  51718. return ColorSpace;
  51719. }();
  51720. /**
  51721. * Alternate color space handles both Separation and DeviceN color spaces. A
  51722. * Separation color space is actually just a DeviceN with one color component.
  51723. * Both color spaces use a tinting function to convert colors to a base color
  51724. * space.
  51725. */
  51726. var AlternateCS = function AlternateCSClosure() {
  51727. function AlternateCS(numComps, base, tintFn) {
  51728. this.name = 'Alternate';
  51729. this.numComps = numComps;
  51730. this.defaultColor = new Float32Array(numComps);
  51731. for (var i = 0; i < numComps; ++i) {
  51732. this.defaultColor[i] = 1;
  51733. }
  51734. this.base = base;
  51735. this.tintFn = tintFn;
  51736. this.tmpBuf = new Float32Array(base.numComps);
  51737. }
  51738. AlternateCS.prototype = {
  51739. getRgb: ColorSpace.prototype.getRgb,
  51740. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset, dest, destOffset) {
  51741. var tmpBuf = this.tmpBuf;
  51742. this.tintFn(src, srcOffset, tmpBuf, 0);
  51743. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  51744. },
  51745. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  51746. var tintFn = this.tintFn;
  51747. var base = this.base;
  51748. var scale = 1 / ((1 << bits) - 1);
  51749. var baseNumComps = base.numComps;
  51750. var usesZeroToOneRange = base.usesZeroToOneRange;
  51751. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) && alpha01 === 0;
  51752. var pos = isPassthrough ? destOffset : 0;
  51753. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  51754. var numComps = this.numComps;
  51755. var scaled = new Float32Array(numComps);
  51756. var tinted = new Float32Array(baseNumComps);
  51757. var i, j;
  51758. if (usesZeroToOneRange) {
  51759. for (i = 0; i < count; i++) {
  51760. for (j = 0; j < numComps; j++) {
  51761. scaled[j] = src[srcOffset++] * scale;
  51762. }
  51763. tintFn(scaled, 0, tinted, 0);
  51764. for (j = 0; j < baseNumComps; j++) {
  51765. baseBuf[pos++] = tinted[j] * 255;
  51766. }
  51767. }
  51768. } else {
  51769. for (i = 0; i < count; i++) {
  51770. for (j = 0; j < numComps; j++) {
  51771. scaled[j] = src[srcOffset++] * scale;
  51772. }
  51773. tintFn(scaled, 0, tinted, 0);
  51774. base.getRgbItem(tinted, 0, baseBuf, pos);
  51775. pos += baseNumComps;
  51776. }
  51777. }
  51778. if (!isPassthrough) {
  51779. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  51780. }
  51781. },
  51782. getOutputLength: function AlternateCS_getOutputLength(inputLength, alpha01) {
  51783. return this.base.getOutputLength(inputLength * this.base.numComps / this.numComps, alpha01);
  51784. },
  51785. isPassthrough: ColorSpace.prototype.isPassthrough,
  51786. fillRgb: ColorSpace.prototype.fillRgb,
  51787. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  51788. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  51789. },
  51790. usesZeroToOneRange: true
  51791. };
  51792. return AlternateCS;
  51793. }();
  51794. var PatternCS = function PatternCSClosure() {
  51795. function PatternCS(baseCS) {
  51796. this.name = 'Pattern';
  51797. this.base = baseCS;
  51798. }
  51799. PatternCS.prototype = {};
  51800. return PatternCS;
  51801. }();
  51802. var IndexedCS = function IndexedCSClosure() {
  51803. function IndexedCS(base, highVal, lookup) {
  51804. this.name = 'Indexed';
  51805. this.numComps = 1;
  51806. this.defaultColor = new Uint8Array([0]);
  51807. this.base = base;
  51808. this.highVal = highVal;
  51809. var baseNumComps = base.numComps;
  51810. var length = baseNumComps * highVal;
  51811. var lookupArray;
  51812. if (isStream(lookup)) {
  51813. lookupArray = new Uint8Array(length);
  51814. var bytes = lookup.getBytes(length);
  51815. lookupArray.set(bytes);
  51816. } else if (isString(lookup)) {
  51817. lookupArray = new Uint8Array(length);
  51818. for (var i = 0; i < length; ++i) {
  51819. lookupArray[i] = lookup.charCodeAt(i);
  51820. }
  51821. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  51822. lookupArray = lookup;
  51823. } else {
  51824. error('Unrecognized lookup table: ' + lookup);
  51825. }
  51826. this.lookup = lookupArray;
  51827. }
  51828. IndexedCS.prototype = {
  51829. getRgb: ColorSpace.prototype.getRgb,
  51830. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset, dest, destOffset) {
  51831. var numComps = this.base.numComps;
  51832. var start = src[srcOffset] * numComps;
  51833. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  51834. },
  51835. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  51836. var base = this.base;
  51837. var numComps = base.numComps;
  51838. var outputDelta = base.getOutputLength(numComps, alpha01);
  51839. var lookup = this.lookup;
  51840. for (var i = 0; i < count; ++i) {
  51841. var lookupPos = src[srcOffset++] * numComps;
  51842. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  51843. destOffset += outputDelta;
  51844. }
  51845. },
  51846. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  51847. return this.base.getOutputLength(inputLength * this.base.numComps, alpha01);
  51848. },
  51849. isPassthrough: ColorSpace.prototype.isPassthrough,
  51850. fillRgb: ColorSpace.prototype.fillRgb,
  51851. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  51852. // indexed color maps shouldn't be changed
  51853. return true;
  51854. },
  51855. usesZeroToOneRange: true
  51856. };
  51857. return IndexedCS;
  51858. }();
  51859. var DeviceGrayCS = function DeviceGrayCSClosure() {
  51860. function DeviceGrayCS() {
  51861. this.name = 'DeviceGray';
  51862. this.numComps = 1;
  51863. this.defaultColor = new Float32Array([0]);
  51864. }
  51865. DeviceGrayCS.prototype = {
  51866. getRgb: ColorSpace.prototype.getRgb,
  51867. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset, dest, destOffset) {
  51868. var c = src[srcOffset] * 255 | 0;
  51869. c = c < 0 ? 0 : c > 255 ? 255 : c;
  51870. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  51871. },
  51872. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  51873. var scale = 255 / ((1 << bits) - 1);
  51874. var j = srcOffset, q = destOffset;
  51875. for (var i = 0; i < count; ++i) {
  51876. var c = scale * src[j++] | 0;
  51877. dest[q++] = c;
  51878. dest[q++] = c;
  51879. dest[q++] = c;
  51880. q += alpha01;
  51881. }
  51882. },
  51883. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength, alpha01) {
  51884. return inputLength * (3 + alpha01);
  51885. },
  51886. isPassthrough: ColorSpace.prototype.isPassthrough,
  51887. fillRgb: ColorSpace.prototype.fillRgb,
  51888. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  51889. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  51890. },
  51891. usesZeroToOneRange: true
  51892. };
  51893. return DeviceGrayCS;
  51894. }();
  51895. var DeviceRgbCS = function DeviceRgbCSClosure() {
  51896. function DeviceRgbCS() {
  51897. this.name = 'DeviceRGB';
  51898. this.numComps = 3;
  51899. this.defaultColor = new Float32Array([
  51900. 0,
  51901. 0,
  51902. 0
  51903. ]);
  51904. }
  51905. DeviceRgbCS.prototype = {
  51906. getRgb: ColorSpace.prototype.getRgb,
  51907. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset, dest, destOffset) {
  51908. var r = src[srcOffset] * 255 | 0;
  51909. var g = src[srcOffset + 1] * 255 | 0;
  51910. var b = src[srcOffset + 2] * 255 | 0;
  51911. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  51912. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  51913. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  51914. },
  51915. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  51916. if (bits === 8 && alpha01 === 0) {
  51917. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  51918. return;
  51919. }
  51920. var scale = 255 / ((1 << bits) - 1);
  51921. var j = srcOffset, q = destOffset;
  51922. for (var i = 0; i < count; ++i) {
  51923. dest[q++] = scale * src[j++] | 0;
  51924. dest[q++] = scale * src[j++] | 0;
  51925. dest[q++] = scale * src[j++] | 0;
  51926. q += alpha01;
  51927. }
  51928. },
  51929. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength, alpha01) {
  51930. return inputLength * (3 + alpha01) / 3 | 0;
  51931. },
  51932. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  51933. return bits === 8;
  51934. },
  51935. fillRgb: ColorSpace.prototype.fillRgb,
  51936. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  51937. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  51938. },
  51939. usesZeroToOneRange: true
  51940. };
  51941. return DeviceRgbCS;
  51942. }();
  51943. var DeviceCmykCS = function DeviceCmykCSClosure() {
  51944. // The coefficients below was found using numerical analysis: the method of
  51945. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  51946. // where color_value is the tabular value from the table of sampled RGB colors
  51947. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  51948. // CMYK color conversion using the estimation below:
  51949. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  51950. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  51951. var c = src[srcOffset + 0] * srcScale;
  51952. var m = src[srcOffset + 1] * srcScale;
  51953. var y = src[srcOffset + 2] * srcScale;
  51954. var k = src[srcOffset + 3] * srcScale;
  51955. 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;
  51956. 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;
  51957. 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;
  51958. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  51959. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  51960. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  51961. }
  51962. function DeviceCmykCS() {
  51963. this.name = 'DeviceCMYK';
  51964. this.numComps = 4;
  51965. this.defaultColor = new Float32Array([
  51966. 0,
  51967. 0,
  51968. 0,
  51969. 1
  51970. ]);
  51971. }
  51972. DeviceCmykCS.prototype = {
  51973. getRgb: ColorSpace.prototype.getRgb,
  51974. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset, dest, destOffset) {
  51975. convertToRgb(src, srcOffset, 1, dest, destOffset);
  51976. },
  51977. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  51978. var scale = 1 / ((1 << bits) - 1);
  51979. for (var i = 0; i < count; i++) {
  51980. convertToRgb(src, srcOffset, scale, dest, destOffset);
  51981. srcOffset += 4;
  51982. destOffset += 3 + alpha01;
  51983. }
  51984. },
  51985. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength, alpha01) {
  51986. return inputLength / 4 * (3 + alpha01) | 0;
  51987. },
  51988. isPassthrough: ColorSpace.prototype.isPassthrough,
  51989. fillRgb: ColorSpace.prototype.fillRgb,
  51990. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  51991. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  51992. },
  51993. usesZeroToOneRange: true
  51994. };
  51995. return DeviceCmykCS;
  51996. }();
  51997. //
  51998. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  51999. //
  52000. var CalGrayCS = function CalGrayCSClosure() {
  52001. function CalGrayCS(whitePoint, blackPoint, gamma) {
  52002. this.name = 'CalGray';
  52003. this.numComps = 1;
  52004. this.defaultColor = new Float32Array([0]);
  52005. if (!whitePoint) {
  52006. error('WhitePoint missing - required for color space CalGray');
  52007. }
  52008. blackPoint = blackPoint || [
  52009. 0,
  52010. 0,
  52011. 0
  52012. ];
  52013. gamma = gamma || 1;
  52014. // Translate arguments to spec variables.
  52015. this.XW = whitePoint[0];
  52016. this.YW = whitePoint[1];
  52017. this.ZW = whitePoint[2];
  52018. this.XB = blackPoint[0];
  52019. this.YB = blackPoint[1];
  52020. this.ZB = blackPoint[2];
  52021. this.G = gamma;
  52022. // Validate variables as per spec.
  52023. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  52024. error('Invalid WhitePoint components for ' + this.name + ', no fallback available');
  52025. }
  52026. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  52027. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  52028. this.XB = this.YB = this.ZB = 0;
  52029. }
  52030. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  52031. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB + ', ZB: ' + this.ZB + ', only default values are supported.');
  52032. }
  52033. if (this.G < 1) {
  52034. info('Invalid Gamma: ' + this.G + ' for ' + this.name + ', falling back to default');
  52035. this.G = 1;
  52036. }
  52037. }
  52038. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  52039. // A represents a gray component of a calibrated gray space.
  52040. // A <---> AG in the spec
  52041. var A = src[srcOffset] * scale;
  52042. var AG = Math.pow(A, cs.G);
  52043. // Computes L as per spec. ( = cs.YW * AG )
  52044. // Except if other than default BlackPoint values are used.
  52045. var L = cs.YW * AG;
  52046. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  52047. // Convert values to rgb range [0, 255].
  52048. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  52049. dest[destOffset] = val;
  52050. dest[destOffset + 1] = val;
  52051. dest[destOffset + 2] = val;
  52052. }
  52053. CalGrayCS.prototype = {
  52054. getRgb: ColorSpace.prototype.getRgb,
  52055. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset, dest, destOffset) {
  52056. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  52057. },
  52058. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  52059. var scale = 1 / ((1 << bits) - 1);
  52060. for (var i = 0; i < count; ++i) {
  52061. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  52062. srcOffset += 1;
  52063. destOffset += 3 + alpha01;
  52064. }
  52065. },
  52066. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  52067. return inputLength * (3 + alpha01);
  52068. },
  52069. isPassthrough: ColorSpace.prototype.isPassthrough,
  52070. fillRgb: ColorSpace.prototype.fillRgb,
  52071. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  52072. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  52073. },
  52074. usesZeroToOneRange: true
  52075. };
  52076. return CalGrayCS;
  52077. }();
  52078. //
  52079. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  52080. //
  52081. var CalRGBCS = function CalRGBCSClosure() {
  52082. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  52083. // matrices.
  52084. var BRADFORD_SCALE_MATRIX = new Float32Array([
  52085. 0.8951,
  52086. 0.2664,
  52087. -0.1614,
  52088. -0.7502,
  52089. 1.7135,
  52090. 0.0367,
  52091. 0.0389,
  52092. -0.0685,
  52093. 1.0296
  52094. ]);
  52095. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  52096. 0.9869929,
  52097. -0.1470543,
  52098. 0.1599627,
  52099. 0.4323053,
  52100. 0.5183603,
  52101. 0.0492912,
  52102. -0.0085287,
  52103. 0.0400428,
  52104. 0.9684867
  52105. ]);
  52106. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  52107. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  52108. 3.2404542,
  52109. -1.5371385,
  52110. -0.4985314,
  52111. -0.9692660,
  52112. 1.8760108,
  52113. 0.0415560,
  52114. 0.0556434,
  52115. -0.2040259,
  52116. 1.0572252
  52117. ]);
  52118. var FLAT_WHITEPOINT_MATRIX = new Float32Array([
  52119. 1,
  52120. 1,
  52121. 1
  52122. ]);
  52123. var tempNormalizeMatrix = new Float32Array(3);
  52124. var tempConvertMatrix1 = new Float32Array(3);
  52125. var tempConvertMatrix2 = new Float32Array(3);
  52126. var DECODE_L_CONSTANT = Math.pow((8 + 16) / 116, 3) / 8.0;
  52127. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  52128. this.name = 'CalRGB';
  52129. this.numComps = 3;
  52130. this.defaultColor = new Float32Array(3);
  52131. if (!whitePoint) {
  52132. error('WhitePoint missing - required for color space CalRGB');
  52133. }
  52134. blackPoint = blackPoint || new Float32Array(3);
  52135. gamma = gamma || new Float32Array([
  52136. 1,
  52137. 1,
  52138. 1
  52139. ]);
  52140. matrix = matrix || new Float32Array([
  52141. 1,
  52142. 0,
  52143. 0,
  52144. 0,
  52145. 1,
  52146. 0,
  52147. 0,
  52148. 0,
  52149. 1
  52150. ]);
  52151. // Translate arguments to spec variables.
  52152. var XW = whitePoint[0];
  52153. var YW = whitePoint[1];
  52154. var ZW = whitePoint[2];
  52155. this.whitePoint = whitePoint;
  52156. var XB = blackPoint[0];
  52157. var YB = blackPoint[1];
  52158. var ZB = blackPoint[2];
  52159. this.blackPoint = blackPoint;
  52160. this.GR = gamma[0];
  52161. this.GG = gamma[1];
  52162. this.GB = gamma[2];
  52163. this.MXA = matrix[0];
  52164. this.MYA = matrix[1];
  52165. this.MZA = matrix[2];
  52166. this.MXB = matrix[3];
  52167. this.MYB = matrix[4];
  52168. this.MZB = matrix[5];
  52169. this.MXC = matrix[6];
  52170. this.MYC = matrix[7];
  52171. this.MZC = matrix[8];
  52172. // Validate variables as per spec.
  52173. if (XW < 0 || ZW < 0 || YW !== 1) {
  52174. error('Invalid WhitePoint components for ' + this.name + ', no fallback available');
  52175. }
  52176. if (XB < 0 || YB < 0 || ZB < 0) {
  52177. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB + ', ' + ZB + '], falling back to default');
  52178. this.blackPoint = new Float32Array(3);
  52179. }
  52180. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  52181. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB + '] for ' + this.name + ', falling back to default');
  52182. this.GR = this.GG = this.GB = 1;
  52183. }
  52184. 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) {
  52185. 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');
  52186. this.MXA = this.MYB = this.MZC = 1;
  52187. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  52188. }
  52189. }
  52190. function matrixProduct(a, b, result) {
  52191. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  52192. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  52193. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  52194. }
  52195. function convertToFlat(sourceWhitePoint, LMS, result) {
  52196. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  52197. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  52198. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  52199. }
  52200. function convertToD65(sourceWhitePoint, LMS, result) {
  52201. var D65X = 0.95047;
  52202. var D65Y = 1;
  52203. var D65Z = 1.08883;
  52204. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  52205. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  52206. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  52207. }
  52208. function sRGBTransferFunction(color) {
  52209. // See http://en.wikipedia.org/wiki/SRGB.
  52210. if (color <= 0.0031308) {
  52211. return adjustToRange(0, 1, 12.92 * color);
  52212. }
  52213. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  52214. }
  52215. function adjustToRange(min, max, value) {
  52216. return Math.max(min, Math.min(max, value));
  52217. }
  52218. function decodeL(L) {
  52219. if (L < 0) {
  52220. return -decodeL(-L);
  52221. }
  52222. if (L > 8.0) {
  52223. return Math.pow((L + 16) / 116, 3);
  52224. }
  52225. return L * DECODE_L_CONSTANT;
  52226. }
  52227. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  52228. // In case the blackPoint is already the default blackPoint then there is
  52229. // no need to do compensation.
  52230. if (sourceBlackPoint[0] === 0 && sourceBlackPoint[1] === 0 && sourceBlackPoint[2] === 0) {
  52231. result[0] = XYZ_Flat[0];
  52232. result[1] = XYZ_Flat[1];
  52233. result[2] = XYZ_Flat[2];
  52234. return;
  52235. }
  52236. // For the blackPoint calculation details, please see
  52237. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  52238. // AdobeBPC.pdf.
  52239. // The destination blackPoint is the default blackPoint [0, 0, 0].
  52240. var zeroDecodeL = decodeL(0);
  52241. var X_DST = zeroDecodeL;
  52242. var X_SRC = decodeL(sourceBlackPoint[0]);
  52243. var Y_DST = zeroDecodeL;
  52244. var Y_SRC = decodeL(sourceBlackPoint[1]);
  52245. var Z_DST = zeroDecodeL;
  52246. var Z_SRC = decodeL(sourceBlackPoint[2]);
  52247. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  52248. var X_Offset = 1 - X_Scale;
  52249. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  52250. var Y_Offset = 1 - Y_Scale;
  52251. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  52252. var Z_Offset = 1 - Z_Scale;
  52253. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  52254. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  52255. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  52256. }
  52257. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  52258. // In case the whitePoint is already flat then there is no need to do
  52259. // normalization.
  52260. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  52261. result[0] = XYZ_In[0];
  52262. result[1] = XYZ_In[1];
  52263. result[2] = XYZ_In[2];
  52264. return;
  52265. }
  52266. var LMS = result;
  52267. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  52268. var LMS_Flat = tempNormalizeMatrix;
  52269. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  52270. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  52271. }
  52272. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  52273. var LMS = result;
  52274. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  52275. var LMS_D65 = tempNormalizeMatrix;
  52276. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  52277. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  52278. }
  52279. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  52280. // A, B and C represent a red, green and blue components of a calibrated
  52281. // rgb space.
  52282. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  52283. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  52284. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  52285. // A <---> AGR in the spec
  52286. // B <---> BGG in the spec
  52287. // C <---> CGB in the spec
  52288. var AGR = Math.pow(A, cs.GR);
  52289. var BGG = Math.pow(B, cs.GG);
  52290. var CGB = Math.pow(C, cs.GB);
  52291. // Computes intermediate variables L, M, N as per spec.
  52292. // To decode X, Y, Z values map L, M, N directly to them.
  52293. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  52294. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  52295. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  52296. // The following calculations are based on this document:
  52297. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  52298. // AdobeBPC.pdf.
  52299. var XYZ = tempConvertMatrix1;
  52300. XYZ[0] = X;
  52301. XYZ[1] = Y;
  52302. XYZ[2] = Z;
  52303. var XYZ_Flat = tempConvertMatrix2;
  52304. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  52305. var XYZ_Black = tempConvertMatrix1;
  52306. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  52307. var XYZ_D65 = tempConvertMatrix2;
  52308. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  52309. var SRGB = tempConvertMatrix1;
  52310. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  52311. var sR = sRGBTransferFunction(SRGB[0]);
  52312. var sG = sRGBTransferFunction(SRGB[1]);
  52313. var sB = sRGBTransferFunction(SRGB[2]);
  52314. // Convert the values to rgb range [0, 255].
  52315. dest[destOffset] = Math.round(sR * 255);
  52316. dest[destOffset + 1] = Math.round(sG * 255);
  52317. dest[destOffset + 2] = Math.round(sB * 255);
  52318. }
  52319. CalRGBCS.prototype = {
  52320. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  52321. var rgb = new Uint8Array(3);
  52322. this.getRgbItem(src, srcOffset, rgb, 0);
  52323. return rgb;
  52324. },
  52325. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset, dest, destOffset) {
  52326. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  52327. },
  52328. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  52329. var scale = 1 / ((1 << bits) - 1);
  52330. for (var i = 0; i < count; ++i) {
  52331. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  52332. srcOffset += 3;
  52333. destOffset += 3 + alpha01;
  52334. }
  52335. },
  52336. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  52337. return inputLength * (3 + alpha01) / 3 | 0;
  52338. },
  52339. isPassthrough: ColorSpace.prototype.isPassthrough,
  52340. fillRgb: ColorSpace.prototype.fillRgb,
  52341. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  52342. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  52343. },
  52344. usesZeroToOneRange: true
  52345. };
  52346. return CalRGBCS;
  52347. }();
  52348. //
  52349. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  52350. //
  52351. var LabCS = function LabCSClosure() {
  52352. function LabCS(whitePoint, blackPoint, range) {
  52353. this.name = 'Lab';
  52354. this.numComps = 3;
  52355. this.defaultColor = new Float32Array([
  52356. 0,
  52357. 0,
  52358. 0
  52359. ]);
  52360. if (!whitePoint) {
  52361. error('WhitePoint missing - required for color space Lab');
  52362. }
  52363. blackPoint = blackPoint || [
  52364. 0,
  52365. 0,
  52366. 0
  52367. ];
  52368. range = range || [
  52369. -100,
  52370. 100,
  52371. -100,
  52372. 100
  52373. ];
  52374. // Translate args to spec variables
  52375. this.XW = whitePoint[0];
  52376. this.YW = whitePoint[1];
  52377. this.ZW = whitePoint[2];
  52378. this.amin = range[0];
  52379. this.amax = range[1];
  52380. this.bmin = range[2];
  52381. this.bmax = range[3];
  52382. // These are here just for completeness - the spec doesn't offer any
  52383. // formulas that use BlackPoint in Lab
  52384. this.XB = blackPoint[0];
  52385. this.YB = blackPoint[1];
  52386. this.ZB = blackPoint[2];
  52387. // Validate vars as per spec
  52388. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  52389. error('Invalid WhitePoint components, no fallback available');
  52390. }
  52391. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  52392. info('Invalid BlackPoint, falling back to default');
  52393. this.XB = this.YB = this.ZB = 0;
  52394. }
  52395. if (this.amin > this.amax || this.bmin > this.bmax) {
  52396. info('Invalid Range, falling back to defaults');
  52397. this.amin = -100;
  52398. this.amax = 100;
  52399. this.bmin = -100;
  52400. this.bmax = 100;
  52401. }
  52402. }
  52403. // Function g(x) from spec
  52404. function fn_g(x) {
  52405. if (x >= 6 / 29) {
  52406. return x * x * x;
  52407. } else {
  52408. return 108 / 841 * (x - 4 / 29);
  52409. }
  52410. }
  52411. function decode(value, high1, low2, high2) {
  52412. return low2 + value * (high2 - low2) / high1;
  52413. }
  52414. // If decoding is needed maxVal should be 2^bits per component - 1.
  52415. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  52416. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  52417. // not the usual [0, 1]. If a command like setFillColor is used the src
  52418. // values will already be within the correct range. However, if we are
  52419. // converting an image we have to map the values to the correct range given
  52420. // above.
  52421. // Ls,as,bs <---> L*,a*,b* in the spec
  52422. var Ls = src[srcOffset];
  52423. var as = src[srcOffset + 1];
  52424. var bs = src[srcOffset + 2];
  52425. if (maxVal !== false) {
  52426. Ls = decode(Ls, maxVal, 0, 100);
  52427. as = decode(as, maxVal, cs.amin, cs.amax);
  52428. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  52429. }
  52430. // Adjust limits of 'as' and 'bs'
  52431. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  52432. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  52433. // Computes intermediate variables X,Y,Z as per spec
  52434. var M = (Ls + 16) / 116;
  52435. var L = M + as / 500;
  52436. var N = M - bs / 200;
  52437. var X = cs.XW * fn_g(L);
  52438. var Y = cs.YW * fn_g(M);
  52439. var Z = cs.ZW * fn_g(N);
  52440. var r, g, b;
  52441. // Using different conversions for D50 and D65 white points,
  52442. // per http://www.color.org/srgb.pdf
  52443. if (cs.ZW < 1) {
  52444. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  52445. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  52446. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  52447. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  52448. } else {
  52449. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  52450. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  52451. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  52452. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  52453. }
  52454. // clamp color values to [0,1] range then convert to [0,255] range.
  52455. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  52456. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  52457. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  52458. }
  52459. LabCS.prototype = {
  52460. getRgb: ColorSpace.prototype.getRgb,
  52461. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  52462. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  52463. },
  52464. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  52465. var maxVal = (1 << bits) - 1;
  52466. for (var i = 0; i < count; i++) {
  52467. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  52468. srcOffset += 3;
  52469. destOffset += 3 + alpha01;
  52470. }
  52471. },
  52472. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  52473. return inputLength * (3 + alpha01) / 3 | 0;
  52474. },
  52475. isPassthrough: ColorSpace.prototype.isPassthrough,
  52476. fillRgb: ColorSpace.prototype.fillRgb,
  52477. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  52478. // XXX: Decoding is handled with the lab conversion because of the strange
  52479. // ranges that are used.
  52480. return true;
  52481. },
  52482. usesZeroToOneRange: false
  52483. };
  52484. return LabCS;
  52485. }();
  52486. exports.ColorSpace = ColorSpace;
  52487. }));
  52488. (function (root, factory) {
  52489. factory(root.pdfjsDisplayGlobal = {}, root.pdfjsSharedUtil, root.pdfjsDisplayDOMUtils, root.pdfjsDisplayAPI, root.pdfjsDisplayAnnotationLayer, root.pdfjsDisplayTextLayer, root.pdfjsDisplayMetadata, root.pdfjsDisplaySVG);
  52490. }(this, function (exports, sharedUtil, displayDOMUtils, displayAPI, displayAnnotationLayer, displayTextLayer, displayMetadata, displaySVG) {
  52491. var globalScope = sharedUtil.globalScope;
  52492. var deprecated = sharedUtil.deprecated;
  52493. var warn = sharedUtil.warn;
  52494. var LinkTarget = displayDOMUtils.LinkTarget;
  52495. var isWorker = typeof window === 'undefined';
  52496. // The global PDFJS object is now deprecated and will not be supported in
  52497. // the future. The members below are maintained for backward compatibility
  52498. // and shall not be extended or modified. If the global.js is included as
  52499. // a module, we will create a global PDFJS object instance or use existing.
  52500. if (!globalScope.PDFJS) {
  52501. globalScope.PDFJS = {};
  52502. }
  52503. var PDFJS = globalScope.PDFJS;
  52504. if (typeof pdfjsVersion !== 'undefined') {
  52505. PDFJS.version = pdfjsVersion;
  52506. }
  52507. if (typeof pdfjsBuild !== 'undefined') {
  52508. PDFJS.build = pdfjsBuild;
  52509. }
  52510. PDFJS.pdfBug = false;
  52511. if (PDFJS.verbosity !== undefined) {
  52512. sharedUtil.setVerbosityLevel(PDFJS.verbosity);
  52513. }
  52514. delete PDFJS.verbosity;
  52515. Object.defineProperty(PDFJS, 'verbosity', {
  52516. get: function () {
  52517. return sharedUtil.getVerbosityLevel();
  52518. },
  52519. set: function (level) {
  52520. sharedUtil.setVerbosityLevel(level);
  52521. },
  52522. enumerable: true,
  52523. configurable: true
  52524. });
  52525. PDFJS.VERBOSITY_LEVELS = sharedUtil.VERBOSITY_LEVELS;
  52526. PDFJS.OPS = sharedUtil.OPS;
  52527. PDFJS.UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  52528. PDFJS.isValidUrl = displayDOMUtils.isValidUrl;
  52529. PDFJS.shadow = sharedUtil.shadow;
  52530. PDFJS.createBlob = sharedUtil.createBlob;
  52531. PDFJS.createObjectURL = function PDFJS_createObjectURL(data, contentType) {
  52532. return sharedUtil.createObjectURL(data, contentType, PDFJS.disableCreateObjectURL);
  52533. };
  52534. Object.defineProperty(PDFJS, 'isLittleEndian', {
  52535. configurable: true,
  52536. get: function PDFJS_isLittleEndian() {
  52537. var value = sharedUtil.isLittleEndian();
  52538. return sharedUtil.shadow(PDFJS, 'isLittleEndian', value);
  52539. }
  52540. });
  52541. PDFJS.removeNullCharacters = sharedUtil.removeNullCharacters;
  52542. PDFJS.PasswordResponses = sharedUtil.PasswordResponses;
  52543. PDFJS.PasswordException = sharedUtil.PasswordException;
  52544. PDFJS.UnknownErrorException = sharedUtil.UnknownErrorException;
  52545. PDFJS.InvalidPDFException = sharedUtil.InvalidPDFException;
  52546. PDFJS.MissingPDFException = sharedUtil.MissingPDFException;
  52547. PDFJS.UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  52548. PDFJS.Util = sharedUtil.Util;
  52549. PDFJS.PageViewport = sharedUtil.PageViewport;
  52550. PDFJS.createPromiseCapability = sharedUtil.createPromiseCapability;
  52551. /**
  52552. * The maximum allowed image size in total pixels e.g. width * height. Images
  52553. * above this value will not be drawn. Use -1 for no limit.
  52554. * @var {number}
  52555. */
  52556. PDFJS.maxImageSize = PDFJS.maxImageSize === undefined ? -1 : PDFJS.maxImageSize;
  52557. /**
  52558. * The url of where the predefined Adobe CMaps are located. Include trailing
  52559. * slash.
  52560. * @var {string}
  52561. */
  52562. PDFJS.cMapUrl = PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl;
  52563. /**
  52564. * Specifies if CMaps are binary packed.
  52565. * @var {boolean}
  52566. */
  52567. PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked;
  52568. /**
  52569. * By default fonts are converted to OpenType fonts and loaded via font face
  52570. * rules. If disabled, the font will be rendered using a built in font
  52571. * renderer that constructs the glyphs with primitive path commands.
  52572. * @var {boolean}
  52573. */
  52574. PDFJS.disableFontFace = PDFJS.disableFontFace === undefined ? false : PDFJS.disableFontFace;
  52575. /**
  52576. * Path for image resources, mainly for annotation icons. Include trailing
  52577. * slash.
  52578. * @var {string}
  52579. */
  52580. PDFJS.imageResourcesPath = PDFJS.imageResourcesPath === undefined ? '' : PDFJS.imageResourcesPath;
  52581. /**
  52582. * Disable the web worker and run all code on the main thread. This will
  52583. * happen automatically if the browser doesn't support workers or sending
  52584. * typed arrays to workers.
  52585. * @var {boolean}
  52586. */
  52587. PDFJS.disableWorker = PDFJS.disableWorker === undefined ? false : PDFJS.disableWorker;
  52588. /**
  52589. * Path and filename of the worker file. Required when the worker is enabled
  52590. * in development mode. If unspecified in the production build, the worker
  52591. * will be loaded based on the location of the pdf.js file. It is recommended
  52592. * that the workerSrc is set in a custom application to prevent issues caused
  52593. * by third-party frameworks and libraries.
  52594. * @var {string}
  52595. */
  52596. PDFJS.workerSrc = PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc;
  52597. /**
  52598. * Disable range request loading of PDF files. When enabled and if the server
  52599. * supports partial content requests then the PDF will be fetched in chunks.
  52600. * Enabled (false) by default.
  52601. * @var {boolean}
  52602. */
  52603. PDFJS.disableRange = PDFJS.disableRange === undefined ? false : PDFJS.disableRange;
  52604. /**
  52605. * Disable streaming of PDF file data. By default PDF.js attempts to load PDF
  52606. * in chunks. This default behavior can be disabled.
  52607. * @var {boolean}
  52608. */
  52609. PDFJS.disableStream = PDFJS.disableStream === undefined ? false : PDFJS.disableStream;
  52610. /**
  52611. * Disable pre-fetching of PDF file data. When range requests are enabled
  52612. * PDF.js will automatically keep fetching more data even if it isn't needed
  52613. * to display the current page. This default behavior can be disabled.
  52614. *
  52615. * NOTE: It is also necessary to disable streaming, see above,
  52616. * in order for disabling of pre-fetching to work correctly.
  52617. * @var {boolean}
  52618. */
  52619. PDFJS.disableAutoFetch = PDFJS.disableAutoFetch === undefined ? false : PDFJS.disableAutoFetch;
  52620. /**
  52621. * Enables special hooks for debugging PDF.js.
  52622. * @var {boolean}
  52623. */
  52624. PDFJS.pdfBug = PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug;
  52625. /**
  52626. * Enables transfer usage in postMessage for ArrayBuffers.
  52627. * @var {boolean}
  52628. */
  52629. PDFJS.postMessageTransfers = PDFJS.postMessageTransfers === undefined ? true : PDFJS.postMessageTransfers;
  52630. /**
  52631. * Disables URL.createObjectURL usage.
  52632. * @var {boolean}
  52633. */
  52634. PDFJS.disableCreateObjectURL = PDFJS.disableCreateObjectURL === undefined ? false : PDFJS.disableCreateObjectURL;
  52635. /**
  52636. * Disables WebGL usage.
  52637. * @var {boolean}
  52638. */
  52639. PDFJS.disableWebGL = PDFJS.disableWebGL === undefined ? true : PDFJS.disableWebGL;
  52640. /**
  52641. * Specifies the |target| attribute for external links.
  52642. * The constants from PDFJS.LinkTarget should be used:
  52643. * - NONE [default]
  52644. * - SELF
  52645. * - BLANK
  52646. * - PARENT
  52647. * - TOP
  52648. * @var {number}
  52649. */
  52650. PDFJS.externalLinkTarget = PDFJS.externalLinkTarget === undefined ? LinkTarget.NONE : PDFJS.externalLinkTarget;
  52651. /**
  52652. * Specifies the |rel| attribute for external links. Defaults to stripping
  52653. * the referrer.
  52654. * @var {string}
  52655. */
  52656. PDFJS.externalLinkRel = PDFJS.externalLinkRel === undefined ? 'noreferrer' : PDFJS.externalLinkRel;
  52657. /**
  52658. * Determines if we can eval strings as JS. Primarily used to improve
  52659. * performance for font rendering.
  52660. * @var {boolean}
  52661. */
  52662. PDFJS.isEvalSupported = PDFJS.isEvalSupported === undefined ? true : PDFJS.isEvalSupported;
  52663. var savedOpenExternalLinksInNewWindow = PDFJS.openExternalLinksInNewWindow;
  52664. delete PDFJS.openExternalLinksInNewWindow;
  52665. Object.defineProperty(PDFJS, 'openExternalLinksInNewWindow', {
  52666. get: function () {
  52667. return PDFJS.externalLinkTarget === LinkTarget.BLANK;
  52668. },
  52669. set: function (value) {
  52670. if (value) {
  52671. deprecated('PDFJS.openExternalLinksInNewWindow, please use ' + '"PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK" instead.');
  52672. }
  52673. if (PDFJS.externalLinkTarget !== LinkTarget.NONE) {
  52674. warn('PDFJS.externalLinkTarget is already initialized');
  52675. return;
  52676. }
  52677. PDFJS.externalLinkTarget = value ? LinkTarget.BLANK : LinkTarget.NONE;
  52678. },
  52679. enumerable: true,
  52680. configurable: true
  52681. });
  52682. if (savedOpenExternalLinksInNewWindow) {
  52683. /**
  52684. * (Deprecated) Opens external links in a new window if enabled.
  52685. * The default behavior opens external links in the PDF.js window.
  52686. *
  52687. * NOTE: This property has been deprecated, please use
  52688. * `PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK` instead.
  52689. * @var {boolean}
  52690. */
  52691. PDFJS.openExternalLinksInNewWindow = savedOpenExternalLinksInNewWindow;
  52692. }
  52693. PDFJS.getDocument = displayAPI.getDocument;
  52694. PDFJS.PDFDataRangeTransport = displayAPI.PDFDataRangeTransport;
  52695. PDFJS.PDFWorker = displayAPI.PDFWorker;
  52696. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  52697. configurable: true,
  52698. get: function PDFJS_hasCanvasTypedArrays() {
  52699. var value = displayDOMUtils.hasCanvasTypedArrays();
  52700. return sharedUtil.shadow(PDFJS, 'hasCanvasTypedArrays', value);
  52701. }
  52702. });
  52703. PDFJS.CustomStyle = displayDOMUtils.CustomStyle;
  52704. PDFJS.LinkTarget = LinkTarget;
  52705. PDFJS.addLinkAttributes = displayDOMUtils.addLinkAttributes;
  52706. PDFJS.getFilenameFromUrl = displayDOMUtils.getFilenameFromUrl;
  52707. PDFJS.isExternalLinkTargetSet = displayDOMUtils.isExternalLinkTargetSet;
  52708. PDFJS.AnnotationLayer = displayAnnotationLayer.AnnotationLayer;
  52709. PDFJS.renderTextLayer = displayTextLayer.renderTextLayer;
  52710. PDFJS.Metadata = displayMetadata.Metadata;
  52711. PDFJS.SVGGraphics = displaySVG.SVGGraphics;
  52712. PDFJS.UnsupportedManager = displayAPI._UnsupportedManager;
  52713. exports.globalScope = globalScope;
  52714. exports.isWorker = isWorker;
  52715. exports.PDFJS = globalScope.PDFJS;
  52716. }));
  52717. (function (root, factory) {
  52718. factory(root.pdfjsCoreImage = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreColorSpace, root.pdfjsCoreStream, root.pdfjsCoreJpx);
  52719. }(this, function (exports, sharedUtil, corePrimitives, coreColorSpace, coreStream, coreJpx) {
  52720. var ImageKind = sharedUtil.ImageKind;
  52721. var assert = sharedUtil.assert;
  52722. var error = sharedUtil.error;
  52723. var info = sharedUtil.info;
  52724. var isArray = sharedUtil.isArray;
  52725. var warn = sharedUtil.warn;
  52726. var Name = corePrimitives.Name;
  52727. var isStream = corePrimitives.isStream;
  52728. var ColorSpace = coreColorSpace.ColorSpace;
  52729. var DecodeStream = coreStream.DecodeStream;
  52730. var JpegStream = coreStream.JpegStream;
  52731. var JpxImage = coreJpx.JpxImage;
  52732. var PDFImage = function PDFImageClosure() {
  52733. /**
  52734. * Decodes the image using native decoder if possible. Resolves the promise
  52735. * when the image data is ready.
  52736. */
  52737. function handleImageData(image, nativeDecoder) {
  52738. if (nativeDecoder && nativeDecoder.canDecode(image)) {
  52739. return nativeDecoder.decode(image);
  52740. } else {
  52741. return Promise.resolve(image);
  52742. }
  52743. }
  52744. /**
  52745. * Decode and clamp a value. The formula is different from the spec because we
  52746. * don't decode to float range [0,1], we decode it in the [0,max] range.
  52747. */
  52748. function decodeAndClamp(value, addend, coefficient, max) {
  52749. value = addend + value * coefficient;
  52750. // Clamp the value to the range
  52751. return value < 0 ? 0 : value > max ? max : value;
  52752. }
  52753. /**
  52754. * Resizes an image mask with 1 component.
  52755. * @param {TypedArray} src - The source buffer.
  52756. * @param {Number} bpc - Number of bits per component.
  52757. * @param {Number} w1 - Original width.
  52758. * @param {Number} h1 - Original height.
  52759. * @param {Number} w2 - New width.
  52760. * @param {Number} h2 - New height.
  52761. * @returns {TypedArray} The resized image mask buffer.
  52762. */
  52763. function resizeImageMask(src, bpc, w1, h1, w2, h2) {
  52764. var length = w2 * h2;
  52765. var dest = bpc <= 8 ? new Uint8Array(length) : bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length);
  52766. var xRatio = w1 / w2;
  52767. var yRatio = h1 / h2;
  52768. var i, j, py, newIndex = 0, oldIndex;
  52769. var xScaled = new Uint16Array(w2);
  52770. var w1Scanline = w1;
  52771. for (i = 0; i < w2; i++) {
  52772. xScaled[i] = Math.floor(i * xRatio);
  52773. }
  52774. for (i = 0; i < h2; i++) {
  52775. py = Math.floor(i * yRatio) * w1Scanline;
  52776. for (j = 0; j < w2; j++) {
  52777. oldIndex = py + xScaled[j];
  52778. dest[newIndex++] = src[oldIndex];
  52779. }
  52780. }
  52781. return dest;
  52782. }
  52783. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  52784. this.image = image;
  52785. var dict = image.dict;
  52786. if (dict.has('Filter')) {
  52787. var filter = dict.get('Filter').name;
  52788. if (filter === 'JPXDecode') {
  52789. var jpxImage = new JpxImage();
  52790. jpxImage.parseImageProperties(image.stream);
  52791. image.stream.reset();
  52792. image.bitsPerComponent = jpxImage.bitsPerComponent;
  52793. image.numComps = jpxImage.componentsCount;
  52794. } else if (filter === 'JBIG2Decode') {
  52795. image.bitsPerComponent = 1;
  52796. image.numComps = 1;
  52797. }
  52798. }
  52799. // TODO cache rendered images?
  52800. this.width = dict.get('Width', 'W');
  52801. this.height = dict.get('Height', 'H');
  52802. if (this.width < 1 || this.height < 1) {
  52803. error('Invalid image width: ' + this.width + ' or height: ' + this.height);
  52804. }
  52805. this.interpolate = dict.get('Interpolate', 'I') || false;
  52806. this.imageMask = dict.get('ImageMask', 'IM') || false;
  52807. this.matte = dict.get('Matte') || false;
  52808. var bitsPerComponent = image.bitsPerComponent;
  52809. if (!bitsPerComponent) {
  52810. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  52811. if (!bitsPerComponent) {
  52812. if (this.imageMask) {
  52813. bitsPerComponent = 1;
  52814. } else {
  52815. error('Bits per component missing in image: ' + this.imageMask);
  52816. }
  52817. }
  52818. }
  52819. this.bpc = bitsPerComponent;
  52820. if (!this.imageMask) {
  52821. var colorSpace = dict.get('ColorSpace', 'CS');
  52822. if (!colorSpace) {
  52823. info('JPX images (which do not require color spaces)');
  52824. switch (image.numComps) {
  52825. case 1:
  52826. colorSpace = Name.get('DeviceGray');
  52827. break;
  52828. case 3:
  52829. colorSpace = Name.get('DeviceRGB');
  52830. break;
  52831. case 4:
  52832. colorSpace = Name.get('DeviceCMYK');
  52833. break;
  52834. default:
  52835. error('JPX images with ' + this.numComps + ' color components not supported.');
  52836. }
  52837. }
  52838. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  52839. this.numComps = this.colorSpace.numComps;
  52840. }
  52841. this.decode = dict.getArray('Decode', 'D');
  52842. this.needsDecode = false;
  52843. if (this.decode && (this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode) || isMask && !ColorSpace.isDefaultDecode(this.decode, 1))) {
  52844. this.needsDecode = true;
  52845. // Do some preprocessing to avoid more math.
  52846. var max = (1 << bitsPerComponent) - 1;
  52847. this.decodeCoefficients = [];
  52848. this.decodeAddends = [];
  52849. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  52850. var dmin = this.decode[i];
  52851. var dmax = this.decode[i + 1];
  52852. this.decodeCoefficients[j] = dmax - dmin;
  52853. this.decodeAddends[j] = max * dmin;
  52854. }
  52855. }
  52856. if (smask) {
  52857. this.smask = new PDFImage(xref, res, smask, false);
  52858. } else if (mask) {
  52859. if (isStream(mask)) {
  52860. var maskDict = mask.dict, imageMask = maskDict.get('ImageMask', 'IM');
  52861. if (!imageMask) {
  52862. warn('Ignoring /Mask in image without /ImageMask.');
  52863. } else {
  52864. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  52865. }
  52866. } else {
  52867. // Color key mask (just an array).
  52868. this.mask = mask;
  52869. }
  52870. }
  52871. }
  52872. /**
  52873. * Handles processing of image data and returns the Promise that is resolved
  52874. * with a PDFImage when the image is ready to be used.
  52875. */
  52876. PDFImage.buildImage = function PDFImage_buildImage(handler, xref, res, image, inline, nativeDecoder) {
  52877. var imagePromise = handleImageData(image, nativeDecoder);
  52878. var smaskPromise;
  52879. var maskPromise;
  52880. var smask = image.dict.get('SMask');
  52881. var mask = image.dict.get('Mask');
  52882. if (smask) {
  52883. smaskPromise = handleImageData(smask, nativeDecoder);
  52884. maskPromise = Promise.resolve(null);
  52885. } else {
  52886. smaskPromise = Promise.resolve(null);
  52887. if (mask) {
  52888. if (isStream(mask)) {
  52889. maskPromise = handleImageData(mask, nativeDecoder);
  52890. } else if (isArray(mask)) {
  52891. maskPromise = Promise.resolve(mask);
  52892. } else {
  52893. warn('Unsupported mask format.');
  52894. maskPromise = Promise.resolve(null);
  52895. }
  52896. } else {
  52897. maskPromise = Promise.resolve(null);
  52898. }
  52899. }
  52900. return Promise.all([
  52901. imagePromise,
  52902. smaskPromise,
  52903. maskPromise
  52904. ]).then(function (results) {
  52905. var imageData = results[0];
  52906. var smaskData = results[1];
  52907. var maskData = results[2];
  52908. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  52909. });
  52910. };
  52911. PDFImage.createMask = function PDFImage_createMask(imgArray, width, height, imageIsFromDecodeStream, inverseDecode) {
  52912. // |imgArray| might not contain full data for every pixel of the mask, so
  52913. // we need to distinguish between |computedLength| and |actualLength|.
  52914. // In particular, if inverseDecode is true, then the array we return must
  52915. // have a length of |computedLength|.
  52916. var computedLength = (width + 7 >> 3) * height;
  52917. var actualLength = imgArray.byteLength;
  52918. var haveFullData = computedLength === actualLength;
  52919. var data, i;
  52920. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  52921. // imgArray came from a DecodeStream and its data is in an appropriate
  52922. // form, so we can just transfer it.
  52923. data = imgArray;
  52924. } else if (!inverseDecode) {
  52925. data = new Uint8Array(actualLength);
  52926. data.set(imgArray);
  52927. } else {
  52928. data = new Uint8Array(computedLength);
  52929. data.set(imgArray);
  52930. for (i = actualLength; i < computedLength; i++) {
  52931. data[i] = 0xff;
  52932. }
  52933. }
  52934. // If necessary, invert the original mask data (but not any extra we might
  52935. // have added above). It's safe to modify the array -- whether it's the
  52936. // original or a copy, we're about to transfer it anyway, so nothing else
  52937. // in this thread can be relying on its contents.
  52938. if (inverseDecode) {
  52939. for (i = 0; i < actualLength; i++) {
  52940. data[i] = ~data[i];
  52941. }
  52942. }
  52943. return {
  52944. data: data,
  52945. width: width,
  52946. height: height
  52947. };
  52948. };
  52949. PDFImage.prototype = {
  52950. get drawWidth() {
  52951. return Math.max(this.width, this.smask && this.smask.width || 0, this.mask && this.mask.width || 0);
  52952. },
  52953. get drawHeight() {
  52954. return Math.max(this.height, this.smask && this.smask.height || 0, this.mask && this.mask.height || 0);
  52955. },
  52956. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  52957. var bpc = this.bpc;
  52958. var numComps = this.numComps;
  52959. var decodeAddends = this.decodeAddends;
  52960. var decodeCoefficients = this.decodeCoefficients;
  52961. var max = (1 << bpc) - 1;
  52962. var i, ii;
  52963. if (bpc === 1) {
  52964. // If the buffer needed decode that means it just needs to be inverted.
  52965. for (i = 0, ii = buffer.length; i < ii; i++) {
  52966. buffer[i] = +!buffer[i];
  52967. }
  52968. return;
  52969. }
  52970. var index = 0;
  52971. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  52972. for (var j = 0; j < numComps; j++) {
  52973. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j], decodeCoefficients[j], max);
  52974. index++;
  52975. }
  52976. }
  52977. },
  52978. getComponents: function PDFImage_getComponents(buffer) {
  52979. var bpc = this.bpc;
  52980. // This image doesn't require any extra work.
  52981. if (bpc === 8) {
  52982. return buffer;
  52983. }
  52984. var width = this.width;
  52985. var height = this.height;
  52986. var numComps = this.numComps;
  52987. var length = width * height * numComps;
  52988. var bufferPos = 0;
  52989. var output = bpc <= 8 ? new Uint8Array(length) : bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length);
  52990. var rowComps = width * numComps;
  52991. var max = (1 << bpc) - 1;
  52992. var i = 0, ii, buf;
  52993. if (bpc === 1) {
  52994. // Optimization for reading 1 bpc images.
  52995. var mask, loop1End, loop2End;
  52996. for (var j = 0; j < height; j++) {
  52997. loop1End = i + (rowComps & ~7);
  52998. loop2End = i + rowComps;
  52999. // unroll loop for all full bytes
  53000. while (i < loop1End) {
  53001. buf = buffer[bufferPos++];
  53002. output[i] = buf >> 7 & 1;
  53003. output[i + 1] = buf >> 6 & 1;
  53004. output[i + 2] = buf >> 5 & 1;
  53005. output[i + 3] = buf >> 4 & 1;
  53006. output[i + 4] = buf >> 3 & 1;
  53007. output[i + 5] = buf >> 2 & 1;
  53008. output[i + 6] = buf >> 1 & 1;
  53009. output[i + 7] = buf & 1;
  53010. i += 8;
  53011. }
  53012. // handle remaining bits
  53013. if (i < loop2End) {
  53014. buf = buffer[bufferPos++];
  53015. mask = 128;
  53016. while (i < loop2End) {
  53017. output[i++] = +!!(buf & mask);
  53018. mask >>= 1;
  53019. }
  53020. }
  53021. }
  53022. } else {
  53023. // The general case that handles all other bpc values.
  53024. var bits = 0;
  53025. buf = 0;
  53026. for (i = 0, ii = length; i < ii; ++i) {
  53027. if (i % rowComps === 0) {
  53028. buf = 0;
  53029. bits = 0;
  53030. }
  53031. while (bits < bpc) {
  53032. buf = buf << 8 | buffer[bufferPos++];
  53033. bits += 8;
  53034. }
  53035. var remainingBits = bits - bpc;
  53036. var value = buf >> remainingBits;
  53037. output[i] = value < 0 ? 0 : value > max ? max : value;
  53038. buf = buf & (1 << remainingBits) - 1;
  53039. bits = remainingBits;
  53040. }
  53041. }
  53042. return output;
  53043. },
  53044. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height, actualHeight, image) {
  53045. var smask = this.smask;
  53046. var mask = this.mask;
  53047. var alphaBuf, sw, sh, i, ii, j;
  53048. if (smask) {
  53049. sw = smask.width;
  53050. sh = smask.height;
  53051. alphaBuf = new Uint8Array(sw * sh);
  53052. smask.fillGrayBuffer(alphaBuf);
  53053. if (sw !== width || sh !== height) {
  53054. alphaBuf = resizeImageMask(alphaBuf, smask.bpc, sw, sh, width, height);
  53055. }
  53056. } else if (mask) {
  53057. if (mask instanceof PDFImage) {
  53058. sw = mask.width;
  53059. sh = mask.height;
  53060. alphaBuf = new Uint8Array(sw * sh);
  53061. mask.numComps = 1;
  53062. mask.fillGrayBuffer(alphaBuf);
  53063. // Need to invert values in rgbaBuf
  53064. for (i = 0, ii = sw * sh; i < ii; ++i) {
  53065. alphaBuf[i] = 255 - alphaBuf[i];
  53066. }
  53067. if (sw !== width || sh !== height) {
  53068. alphaBuf = resizeImageMask(alphaBuf, mask.bpc, sw, sh, width, height);
  53069. }
  53070. } else if (isArray(mask)) {
  53071. // Color key mask: if any of the components are outside the range
  53072. // then they should be painted.
  53073. alphaBuf = new Uint8Array(width * height);
  53074. var numComps = this.numComps;
  53075. for (i = 0, ii = width * height; i < ii; ++i) {
  53076. var opacity = 0;
  53077. var imageOffset = i * numComps;
  53078. for (j = 0; j < numComps; ++j) {
  53079. var color = image[imageOffset + j];
  53080. var maskOffset = j * 2;
  53081. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  53082. opacity = 255;
  53083. break;
  53084. }
  53085. }
  53086. alphaBuf[i] = opacity;
  53087. }
  53088. } else {
  53089. error('Unknown mask format.');
  53090. }
  53091. }
  53092. if (alphaBuf) {
  53093. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  53094. rgbaBuf[j] = alphaBuf[i];
  53095. }
  53096. } else {
  53097. // No mask.
  53098. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  53099. rgbaBuf[j] = 255;
  53100. }
  53101. }
  53102. },
  53103. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  53104. var matte = this.smask && this.smask.matte;
  53105. if (!matte) {
  53106. return;
  53107. }
  53108. var matteRgb = this.colorSpace.getRgb(matte, 0);
  53109. var matteR = matteRgb[0];
  53110. var matteG = matteRgb[1];
  53111. var matteB = matteRgb[2];
  53112. var length = width * height * 4;
  53113. var r, g, b;
  53114. for (var i = 0; i < length; i += 4) {
  53115. var alpha = buffer[i + 3];
  53116. if (alpha === 0) {
  53117. // according formula we have to get Infinity in all components
  53118. // making it white (typical paper color) should be okay
  53119. buffer[i] = 255;
  53120. buffer[i + 1] = 255;
  53121. buffer[i + 2] = 255;
  53122. continue;
  53123. }
  53124. var k = 255 / alpha;
  53125. r = (buffer[i] - matteR) * k + matteR;
  53126. g = (buffer[i + 1] - matteG) * k + matteG;
  53127. b = (buffer[i + 2] - matteB) * k + matteB;
  53128. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  53129. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  53130. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  53131. }
  53132. },
  53133. createImageData: function PDFImage_createImageData(forceRGBA) {
  53134. var drawWidth = this.drawWidth;
  53135. var drawHeight = this.drawHeight;
  53136. var imgData = {
  53137. // other fields are filled in below
  53138. width: drawWidth,
  53139. height: drawHeight
  53140. };
  53141. var numComps = this.numComps;
  53142. var originalWidth = this.width;
  53143. var originalHeight = this.height;
  53144. var bpc = this.bpc;
  53145. // Rows start at byte boundary.
  53146. var rowBytes = originalWidth * numComps * bpc + 7 >> 3;
  53147. var imgArray;
  53148. if (!forceRGBA) {
  53149. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  53150. // without any complications, we pass a same-sized copy to the main
  53151. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  53152. // of memory for many scanned documents. It's also much faster.
  53153. //
  53154. // Similarly, if it is a 24-bit-per pixel RGB image without any
  53155. // complications, we avoid expanding by 1.333x to RGBA form.
  53156. var kind;
  53157. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  53158. kind = ImageKind.GRAYSCALE_1BPP;
  53159. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 && !this.needsDecode) {
  53160. kind = ImageKind.RGB_24BPP;
  53161. }
  53162. if (kind && !this.smask && !this.mask && drawWidth === originalWidth && drawHeight === originalHeight) {
  53163. imgData.kind = kind;
  53164. imgArray = this.getImageBytes(originalHeight * rowBytes);
  53165. // If imgArray came from a DecodeStream, we're safe to transfer it
  53166. // (and thus detach its underlying buffer) because it will constitute
  53167. // the entire DecodeStream's data. But if it came from a Stream, we
  53168. // need to copy it because it'll only be a portion of the Stream's
  53169. // data, and the rest will be read later on.
  53170. if (this.image instanceof DecodeStream) {
  53171. imgData.data = imgArray;
  53172. } else {
  53173. var newArray = new Uint8Array(imgArray.length);
  53174. newArray.set(imgArray);
  53175. imgData.data = newArray;
  53176. }
  53177. if (this.needsDecode) {
  53178. // Invert the buffer (which must be grayscale if we reached here).
  53179. assert(kind === ImageKind.GRAYSCALE_1BPP);
  53180. var buffer = imgData.data;
  53181. for (var i = 0, ii = buffer.length; i < ii; i++) {
  53182. buffer[i] ^= 0xff;
  53183. }
  53184. }
  53185. return imgData;
  53186. }
  53187. if (this.image instanceof JpegStream && !this.smask && !this.mask && (this.colorSpace.name === 'DeviceGray' || this.colorSpace.name === 'DeviceRGB' || this.colorSpace.name === 'DeviceCMYK')) {
  53188. imgData.kind = ImageKind.RGB_24BPP;
  53189. imgData.data = this.getImageBytes(originalHeight * rowBytes, drawWidth, drawHeight, true);
  53190. return imgData;
  53191. }
  53192. }
  53193. imgArray = this.getImageBytes(originalHeight * rowBytes);
  53194. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  53195. var actualHeight = 0 | imgArray.length / rowBytes * drawHeight / originalHeight;
  53196. var comps = this.getComponents(imgArray);
  53197. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  53198. // more compact RGB_24BPP form if allowable.
  53199. var alpha01, maybeUndoPreblend;
  53200. if (!forceRGBA && !this.smask && !this.mask) {
  53201. imgData.kind = ImageKind.RGB_24BPP;
  53202. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  53203. alpha01 = 0;
  53204. maybeUndoPreblend = false;
  53205. } else {
  53206. imgData.kind = ImageKind.RGBA_32BPP;
  53207. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  53208. alpha01 = 1;
  53209. maybeUndoPreblend = true;
  53210. // Color key masking (opacity) must be performed before decoding.
  53211. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight, comps);
  53212. }
  53213. if (this.needsDecode) {
  53214. this.decodeBuffer(comps);
  53215. }
  53216. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight, drawWidth, drawHeight, actualHeight, bpc, comps, alpha01);
  53217. if (maybeUndoPreblend) {
  53218. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  53219. }
  53220. return imgData;
  53221. },
  53222. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  53223. var numComps = this.numComps;
  53224. if (numComps !== 1) {
  53225. error('Reading gray scale from a color image: ' + numComps);
  53226. }
  53227. var width = this.width;
  53228. var height = this.height;
  53229. var bpc = this.bpc;
  53230. // rows start at byte boundary
  53231. var rowBytes = width * numComps * bpc + 7 >> 3;
  53232. var imgArray = this.getImageBytes(height * rowBytes);
  53233. var comps = this.getComponents(imgArray);
  53234. var i, length;
  53235. if (bpc === 1) {
  53236. // inline decoding (= inversion) for 1 bpc images
  53237. length = width * height;
  53238. if (this.needsDecode) {
  53239. // invert and scale to {0, 255}
  53240. for (i = 0; i < length; ++i) {
  53241. buffer[i] = comps[i] - 1 & 255;
  53242. }
  53243. } else {
  53244. // scale to {0, 255}
  53245. for (i = 0; i < length; ++i) {
  53246. buffer[i] = -comps[i] & 255;
  53247. }
  53248. }
  53249. return;
  53250. }
  53251. if (this.needsDecode) {
  53252. this.decodeBuffer(comps);
  53253. }
  53254. length = width * height;
  53255. // we aren't using a colorspace so we need to scale the value
  53256. var scale = 255 / ((1 << bpc) - 1);
  53257. for (i = 0; i < length; ++i) {
  53258. buffer[i] = scale * comps[i] | 0;
  53259. }
  53260. },
  53261. getImageBytes: function PDFImage_getImageBytes(length, drawWidth, drawHeight, forceRGB) {
  53262. this.image.reset();
  53263. this.image.drawWidth = drawWidth || this.width;
  53264. this.image.drawHeight = drawHeight || this.height;
  53265. this.image.forceRGB = !!forceRGB;
  53266. return this.image.getBytes(length);
  53267. }
  53268. };
  53269. return PDFImage;
  53270. }();
  53271. exports.PDFImage = PDFImage;
  53272. }));
  53273. (function (root, factory) {
  53274. factory(root.pdfjsCoreObj = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreCrypto, root.pdfjsCoreParser, root.pdfjsCoreChunkedStream, root.pdfjsCoreColorSpace);
  53275. }(this, function (exports, sharedUtil, corePrimitives, coreCrypto, coreParser, coreChunkedStream, coreColorSpace) {
  53276. var InvalidPDFException = sharedUtil.InvalidPDFException;
  53277. var MissingDataException = sharedUtil.MissingDataException;
  53278. var XRefParseException = sharedUtil.XRefParseException;
  53279. var assert = sharedUtil.assert;
  53280. var bytesToString = sharedUtil.bytesToString;
  53281. var createPromiseCapability = sharedUtil.createPromiseCapability;
  53282. var error = sharedUtil.error;
  53283. var info = sharedUtil.info;
  53284. var isArray = sharedUtil.isArray;
  53285. var isBool = sharedUtil.isBool;
  53286. var isInt = sharedUtil.isInt;
  53287. var isString = sharedUtil.isString;
  53288. var shadow = sharedUtil.shadow;
  53289. var stringToPDFString = sharedUtil.stringToPDFString;
  53290. var stringToUTF8String = sharedUtil.stringToUTF8String;
  53291. var warn = sharedUtil.warn;
  53292. var createValidAbsoluteUrl = sharedUtil.createValidAbsoluteUrl;
  53293. var Util = sharedUtil.Util;
  53294. var Ref = corePrimitives.Ref;
  53295. var RefSet = corePrimitives.RefSet;
  53296. var RefSetCache = corePrimitives.RefSetCache;
  53297. var isName = corePrimitives.isName;
  53298. var isCmd = corePrimitives.isCmd;
  53299. var isDict = corePrimitives.isDict;
  53300. var isRef = corePrimitives.isRef;
  53301. var isRefsEqual = corePrimitives.isRefsEqual;
  53302. var isStream = corePrimitives.isStream;
  53303. var CipherTransformFactory = coreCrypto.CipherTransformFactory;
  53304. var Lexer = coreParser.Lexer;
  53305. var Parser = coreParser.Parser;
  53306. var ChunkedStream = coreChunkedStream.ChunkedStream;
  53307. var ColorSpace = coreColorSpace.ColorSpace;
  53308. var Catalog = function CatalogClosure() {
  53309. function Catalog(pdfManager, xref, pageFactory) {
  53310. this.pdfManager = pdfManager;
  53311. this.xref = xref;
  53312. this.catDict = xref.getCatalogObj();
  53313. this.fontCache = new RefSetCache();
  53314. assert(isDict(this.catDict), 'catalog object is not a dictionary');
  53315. // TODO refactor to move getPage() to the PDFDocument.
  53316. this.pageFactory = pageFactory;
  53317. this.pagePromises = [];
  53318. }
  53319. Catalog.prototype = {
  53320. get metadata() {
  53321. var streamRef = this.catDict.getRaw('Metadata');
  53322. if (!isRef(streamRef)) {
  53323. return shadow(this, 'metadata', null);
  53324. }
  53325. var encryptMetadata = !this.xref.encrypt ? false : this.xref.encrypt.encryptMetadata;
  53326. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  53327. var metadata;
  53328. if (stream && isDict(stream.dict)) {
  53329. var type = stream.dict.get('Type');
  53330. var subtype = stream.dict.get('Subtype');
  53331. if (isName(type, 'Metadata') && isName(subtype, 'XML')) {
  53332. // XXX: This should examine the charset the XML document defines,
  53333. // however since there are currently no real means to decode
  53334. // arbitrary charsets, let's just hope that the author of the PDF
  53335. // was reasonable enough to stick with the XML default charset,
  53336. // which is UTF-8.
  53337. try {
  53338. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  53339. } catch (e) {
  53340. info('Skipping invalid metadata.');
  53341. }
  53342. }
  53343. }
  53344. return shadow(this, 'metadata', metadata);
  53345. },
  53346. get toplevelPagesDict() {
  53347. var pagesObj = this.catDict.get('Pages');
  53348. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  53349. // shadow the prototype getter
  53350. return shadow(this, 'toplevelPagesDict', pagesObj);
  53351. },
  53352. get documentOutline() {
  53353. var obj = null;
  53354. try {
  53355. obj = this.readDocumentOutline();
  53356. } catch (ex) {
  53357. if (ex instanceof MissingDataException) {
  53358. throw ex;
  53359. }
  53360. warn('Unable to read document outline');
  53361. }
  53362. return shadow(this, 'documentOutline', obj);
  53363. },
  53364. readDocumentOutline: function Catalog_readDocumentOutline() {
  53365. var obj = this.catDict.get('Outlines');
  53366. if (!isDict(obj)) {
  53367. return null;
  53368. }
  53369. obj = obj.getRaw('First');
  53370. if (!isRef(obj)) {
  53371. return null;
  53372. }
  53373. var root = { items: [] };
  53374. var queue = [{
  53375. obj: obj,
  53376. parent: root
  53377. }];
  53378. // To avoid recursion, keep track of the already processed items.
  53379. var processed = new RefSet();
  53380. processed.put(obj);
  53381. var xref = this.xref, blackColor = new Uint8Array(3);
  53382. while (queue.length > 0) {
  53383. var i = queue.shift();
  53384. var outlineDict = xref.fetchIfRef(i.obj);
  53385. if (outlineDict === null) {
  53386. continue;
  53387. }
  53388. assert(outlineDict.has('Title'), 'Invalid outline item');
  53389. var data = {
  53390. url: null,
  53391. dest: null
  53392. };
  53393. Catalog.parseDestDictionary({
  53394. destDict: outlineDict,
  53395. resultObj: data,
  53396. docBaseUrl: this.pdfManager.docBaseUrl
  53397. });
  53398. var title = outlineDict.get('Title');
  53399. var flags = outlineDict.get('F') || 0;
  53400. var color = outlineDict.getArray('C'), rgbColor = blackColor;
  53401. // We only need to parse the color when it's valid, and non-default.
  53402. if (isArray(color) && color.length === 3 && (color[0] !== 0 || color[1] !== 0 || color[2] !== 0)) {
  53403. rgbColor = ColorSpace.singletons.rgb.getRgb(color, 0);
  53404. }
  53405. var outlineItem = {
  53406. dest: data.dest,
  53407. url: data.url,
  53408. unsafeUrl: data.unsafeUrl,
  53409. newWindow: data.newWindow,
  53410. title: stringToPDFString(title),
  53411. color: rgbColor,
  53412. count: outlineDict.get('Count'),
  53413. bold: !!(flags & 2),
  53414. italic: !!(flags & 1),
  53415. items: []
  53416. };
  53417. i.parent.items.push(outlineItem);
  53418. obj = outlineDict.getRaw('First');
  53419. if (isRef(obj) && !processed.has(obj)) {
  53420. queue.push({
  53421. obj: obj,
  53422. parent: outlineItem
  53423. });
  53424. processed.put(obj);
  53425. }
  53426. obj = outlineDict.getRaw('Next');
  53427. if (isRef(obj) && !processed.has(obj)) {
  53428. queue.push({
  53429. obj: obj,
  53430. parent: i.parent
  53431. });
  53432. processed.put(obj);
  53433. }
  53434. }
  53435. return root.items.length > 0 ? root.items : null;
  53436. },
  53437. get numPages() {
  53438. var obj = this.toplevelPagesDict.get('Count');
  53439. assert(isInt(obj), 'page count in top level pages object is not an integer');
  53440. // shadow the prototype getter
  53441. return shadow(this, 'num', obj);
  53442. },
  53443. get destinations() {
  53444. function fetchDestination(dest) {
  53445. return isDict(dest) ? dest.get('D') : dest;
  53446. }
  53447. var xref = this.xref;
  53448. var dests = {}, nameTreeRef, nameDictionaryRef;
  53449. var obj = this.catDict.get('Names');
  53450. if (obj && obj.has('Dests')) {
  53451. nameTreeRef = obj.getRaw('Dests');
  53452. } else if (this.catDict.has('Dests')) {
  53453. nameDictionaryRef = this.catDict.get('Dests');
  53454. }
  53455. if (nameDictionaryRef) {
  53456. // reading simple destination dictionary
  53457. obj = nameDictionaryRef;
  53458. obj.forEach(function catalogForEach(key, value) {
  53459. if (!value) {
  53460. return;
  53461. }
  53462. dests[key] = fetchDestination(value);
  53463. });
  53464. }
  53465. if (nameTreeRef) {
  53466. var nameTree = new NameTree(nameTreeRef, xref);
  53467. var names = nameTree.getAll();
  53468. for (var name in names) {
  53469. dests[name] = fetchDestination(names[name]);
  53470. }
  53471. }
  53472. return shadow(this, 'destinations', dests);
  53473. },
  53474. getDestination: function Catalog_getDestination(destinationId) {
  53475. function fetchDestination(dest) {
  53476. return isDict(dest) ? dest.get('D') : dest;
  53477. }
  53478. var xref = this.xref;
  53479. var dest = null, nameTreeRef, nameDictionaryRef;
  53480. var obj = this.catDict.get('Names');
  53481. if (obj && obj.has('Dests')) {
  53482. nameTreeRef = obj.getRaw('Dests');
  53483. } else if (this.catDict.has('Dests')) {
  53484. nameDictionaryRef = this.catDict.get('Dests');
  53485. }
  53486. if (nameDictionaryRef) {
  53487. // Simple destination dictionary.
  53488. var value = nameDictionaryRef.get(destinationId);
  53489. if (value) {
  53490. dest = fetchDestination(value);
  53491. }
  53492. }
  53493. if (nameTreeRef) {
  53494. var nameTree = new NameTree(nameTreeRef, xref);
  53495. dest = fetchDestination(nameTree.get(destinationId));
  53496. }
  53497. return dest;
  53498. },
  53499. get pageLabels() {
  53500. var obj = null;
  53501. try {
  53502. obj = this.readPageLabels();
  53503. } catch (ex) {
  53504. if (ex instanceof MissingDataException) {
  53505. throw ex;
  53506. }
  53507. warn('Unable to read page labels.');
  53508. }
  53509. return shadow(this, 'pageLabels', obj);
  53510. },
  53511. readPageLabels: function Catalog_readPageLabels() {
  53512. var obj = this.catDict.getRaw('PageLabels');
  53513. if (!obj) {
  53514. return null;
  53515. }
  53516. var pageLabels = new Array(this.numPages);
  53517. var style = null;
  53518. var prefix = '';
  53519. var numberTree = new NumberTree(obj, this.xref);
  53520. var nums = numberTree.getAll();
  53521. var currentLabel = '', currentIndex = 1;
  53522. for (var i = 0, ii = this.numPages; i < ii; i++) {
  53523. if (i in nums) {
  53524. var labelDict = nums[i];
  53525. assert(isDict(labelDict), 'The PageLabel is not a dictionary.');
  53526. var type = labelDict.get('Type');
  53527. assert(!type || isName(type, 'PageLabel'), 'Invalid type in PageLabel dictionary.');
  53528. var s = labelDict.get('S');
  53529. assert(!s || isName(s), 'Invalid style in PageLabel dictionary.');
  53530. style = s ? s.name : null;
  53531. var p = labelDict.get('P');
  53532. assert(!p || isString(p), 'Invalid prefix in PageLabel dictionary.');
  53533. prefix = p ? stringToPDFString(p) : '';
  53534. var st = labelDict.get('St');
  53535. assert(!st || isInt(st) && st >= 1, 'Invalid start in PageLabel dictionary.');
  53536. currentIndex = st || 1;
  53537. }
  53538. switch (style) {
  53539. case 'D':
  53540. currentLabel = currentIndex;
  53541. break;
  53542. case 'R':
  53543. case 'r':
  53544. currentLabel = Util.toRoman(currentIndex, style === 'r');
  53545. break;
  53546. case 'A':
  53547. case 'a':
  53548. var LIMIT = 26;
  53549. // Use only the characters A--Z, or a--z.
  53550. var A_UPPER_CASE = 0x41, A_LOWER_CASE = 0x61;
  53551. var baseCharCode = style === 'a' ? A_LOWER_CASE : A_UPPER_CASE;
  53552. var letterIndex = currentIndex - 1;
  53553. var character = String.fromCharCode(baseCharCode + letterIndex % LIMIT);
  53554. var charBuf = [];
  53555. for (var j = 0, jj = letterIndex / LIMIT | 0; j <= jj; j++) {
  53556. charBuf.push(character);
  53557. }
  53558. currentLabel = charBuf.join('');
  53559. break;
  53560. default:
  53561. assert(!style, 'Invalid style "' + style + '" in PageLabel dictionary.');
  53562. }
  53563. pageLabels[i] = prefix + currentLabel;
  53564. currentLabel = '';
  53565. currentIndex++;
  53566. }
  53567. return pageLabels;
  53568. },
  53569. get attachments() {
  53570. var xref = this.xref;
  53571. var attachments = null, nameTreeRef;
  53572. var obj = this.catDict.get('Names');
  53573. if (obj) {
  53574. nameTreeRef = obj.getRaw('EmbeddedFiles');
  53575. }
  53576. if (nameTreeRef) {
  53577. var nameTree = new NameTree(nameTreeRef, xref);
  53578. var names = nameTree.getAll();
  53579. for (var name in names) {
  53580. var fs = new FileSpec(names[name], xref);
  53581. if (!attachments) {
  53582. attachments = Object.create(null);
  53583. }
  53584. attachments[stringToPDFString(name)] = fs.serializable;
  53585. }
  53586. }
  53587. return shadow(this, 'attachments', attachments);
  53588. },
  53589. get javaScript() {
  53590. var xref = this.xref;
  53591. var obj = this.catDict.get('Names');
  53592. var javaScript = [];
  53593. function appendIfJavaScriptDict(jsDict) {
  53594. var type = jsDict.get('S');
  53595. if (!isName(type, 'JavaScript')) {
  53596. return;
  53597. }
  53598. var js = jsDict.get('JS');
  53599. if (isStream(js)) {
  53600. js = bytesToString(js.getBytes());
  53601. } else if (!isString(js)) {
  53602. return;
  53603. }
  53604. javaScript.push(stringToPDFString(js));
  53605. }
  53606. if (obj && obj.has('JavaScript')) {
  53607. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  53608. var names = nameTree.getAll();
  53609. for (var name in names) {
  53610. // We don't really use the JavaScript right now. This code is
  53611. // defensive so we don't cause errors on document load.
  53612. var jsDict = names[name];
  53613. if (isDict(jsDict)) {
  53614. appendIfJavaScriptDict(jsDict);
  53615. }
  53616. }
  53617. }
  53618. // Append OpenAction actions to javaScript array
  53619. var openactionDict = this.catDict.get('OpenAction');
  53620. if (isDict(openactionDict, 'Action')) {
  53621. var actionType = openactionDict.get('S');
  53622. if (isName(actionType, 'Named')) {
  53623. // The named Print action is not a part of the PDF 1.7 specification,
  53624. // but is supported by many PDF readers/writers (including Adobe's).
  53625. var action = openactionDict.get('N');
  53626. if (isName(action, 'Print')) {
  53627. javaScript.push('print({});');
  53628. }
  53629. } else {
  53630. appendIfJavaScriptDict(openactionDict);
  53631. }
  53632. }
  53633. return shadow(this, 'javaScript', javaScript);
  53634. },
  53635. cleanup: function Catalog_cleanup() {
  53636. var promises = [];
  53637. this.fontCache.forEach(function (promise) {
  53638. promises.push(promise);
  53639. });
  53640. return Promise.all(promises).then(function (translatedFonts) {
  53641. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  53642. var font = translatedFonts[i].dict;
  53643. delete font.translated;
  53644. }
  53645. this.fontCache.clear();
  53646. }.bind(this));
  53647. },
  53648. getPage: function Catalog_getPage(pageIndex) {
  53649. if (!(pageIndex in this.pagePromises)) {
  53650. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(function (a) {
  53651. var dict = a[0];
  53652. var ref = a[1];
  53653. return this.pageFactory.createPage(pageIndex, dict, ref, this.fontCache);
  53654. }.bind(this));
  53655. }
  53656. return this.pagePromises[pageIndex];
  53657. },
  53658. getPageDict: function Catalog_getPageDict(pageIndex) {
  53659. var capability = createPromiseCapability();
  53660. var nodesToVisit = [this.catDict.getRaw('Pages')];
  53661. var currentPageIndex = 0;
  53662. var xref = this.xref;
  53663. var checkAllKids = false;
  53664. function next() {
  53665. while (nodesToVisit.length) {
  53666. var currentNode = nodesToVisit.pop();
  53667. if (isRef(currentNode)) {
  53668. xref.fetchAsync(currentNode).then(function (obj) {
  53669. if (isDict(obj, 'Page') || isDict(obj) && !obj.has('Kids')) {
  53670. if (pageIndex === currentPageIndex) {
  53671. capability.resolve([
  53672. obj,
  53673. currentNode
  53674. ]);
  53675. } else {
  53676. currentPageIndex++;
  53677. next();
  53678. }
  53679. return;
  53680. }
  53681. nodesToVisit.push(obj);
  53682. next();
  53683. }, capability.reject);
  53684. return;
  53685. }
  53686. // Must be a child page dictionary.
  53687. assert(isDict(currentNode), 'page dictionary kid reference points to wrong type of object');
  53688. var count = currentNode.get('Count');
  53689. // If the current node doesn't have any children, avoid getting stuck
  53690. // in an empty node further down in the tree (see issue5644.pdf).
  53691. if (count === 0) {
  53692. checkAllKids = true;
  53693. }
  53694. // Skip nodes where the page can't be.
  53695. if (currentPageIndex + count <= pageIndex) {
  53696. currentPageIndex += count;
  53697. continue;
  53698. }
  53699. var kids = currentNode.get('Kids');
  53700. assert(isArray(kids), 'page dictionary kids object is not an array');
  53701. if (!checkAllKids && count === kids.length) {
  53702. // Nodes that don't have the page have been skipped and this is the
  53703. // bottom of the tree which means the page requested must be a
  53704. // descendant of this pages node. Ideally we would just resolve the
  53705. // promise with the page ref here, but there is the case where more
  53706. // pages nodes could link to single a page (see issue 3666 pdf). To
  53707. // handle this push it back on the queue so if it is a pages node it
  53708. // will be descended into.
  53709. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  53710. currentPageIndex = pageIndex;
  53711. continue;
  53712. } else {
  53713. for (var last = kids.length - 1; last >= 0; last--) {
  53714. nodesToVisit.push(kids[last]);
  53715. }
  53716. }
  53717. }
  53718. capability.reject('Page index ' + pageIndex + ' not found.');
  53719. }
  53720. next();
  53721. return capability.promise;
  53722. },
  53723. getPageIndex: function Catalog_getPageIndex(pageRef) {
  53724. // The page tree nodes have the count of all the leaves below them. To get
  53725. // how many pages are before we just have to walk up the tree and keep
  53726. // adding the count of siblings to the left of the node.
  53727. var xref = this.xref;
  53728. function pagesBeforeRef(kidRef) {
  53729. var total = 0;
  53730. var parentRef;
  53731. return xref.fetchAsync(kidRef).then(function (node) {
  53732. if (isRefsEqual(kidRef, pageRef) && !isDict(node, 'Page') && !(isDict(node) && !node.has('Type') && node.has('Contents'))) {
  53733. throw new Error('The reference does not point to a /Page Dict.');
  53734. }
  53735. if (!node) {
  53736. return null;
  53737. }
  53738. assert(isDict(node), 'node must be a Dict.');
  53739. parentRef = node.getRaw('Parent');
  53740. return node.getAsync('Parent');
  53741. }).then(function (parent) {
  53742. if (!parent) {
  53743. return null;
  53744. }
  53745. assert(isDict(parent), 'parent must be a Dict.');
  53746. return parent.getAsync('Kids');
  53747. }).then(function (kids) {
  53748. if (!kids) {
  53749. return null;
  53750. }
  53751. var kidPromises = [];
  53752. var found = false;
  53753. for (var i = 0; i < kids.length; i++) {
  53754. var kid = kids[i];
  53755. assert(isRef(kid), 'kid must be a Ref.');
  53756. if (kid.num === kidRef.num) {
  53757. found = true;
  53758. break;
  53759. }
  53760. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  53761. if (kid.has('Count')) {
  53762. var count = kid.get('Count');
  53763. total += count;
  53764. } else {
  53765. // page leaf node
  53766. total++;
  53767. }
  53768. }));
  53769. }
  53770. if (!found) {
  53771. error('kid ref not found in parents kids');
  53772. }
  53773. return Promise.all(kidPromises).then(function () {
  53774. return [
  53775. total,
  53776. parentRef
  53777. ];
  53778. });
  53779. });
  53780. }
  53781. var total = 0;
  53782. function next(ref) {
  53783. return pagesBeforeRef(ref).then(function (args) {
  53784. if (!args) {
  53785. return total;
  53786. }
  53787. var count = args[0];
  53788. var parentRef = args[1];
  53789. total += count;
  53790. return next(parentRef);
  53791. });
  53792. }
  53793. return next(pageRef);
  53794. }
  53795. };
  53796. /**
  53797. * Helper function used to parse the contents of destination dictionaries.
  53798. * @param {Dict} destDict - The dictionary containing the destination.
  53799. * @param {Object} resultObj - The object where the parsed destination
  53800. * properties will be placed.
  53801. * @param {string} docBaseUrl - (optional) The document base URL that is used
  53802. * when attempting to recover valid absolute URLs from relative ones.
  53803. */
  53804. Catalog.parseDestDictionary = function Catalog_parseDestDictionary(params) {
  53805. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  53806. function addDefaultProtocolToUrl(url) {
  53807. if (url.indexOf('www.') === 0) {
  53808. return 'http://' + url;
  53809. }
  53810. return url;
  53811. }
  53812. // According to ISO 32000-1:2008, section 12.6.4.7, URIs should be encoded
  53813. // in 7-bit ASCII. Some bad PDFs use UTF-8 encoding, see Bugzilla 1122280.
  53814. function tryConvertUrlEncoding(url) {
  53815. try {
  53816. return stringToUTF8String(url);
  53817. } catch (e) {
  53818. return url;
  53819. }
  53820. }
  53821. var destDict = params.destDict;
  53822. if (!isDict(destDict)) {
  53823. warn('Catalog_parseDestDictionary: "destDict" must be a dictionary.');
  53824. return;
  53825. }
  53826. var resultObj = params.resultObj;
  53827. if (typeof resultObj !== 'object') {
  53828. warn('Catalog_parseDestDictionary: "resultObj" must be an object.');
  53829. return;
  53830. }
  53831. var docBaseUrl = params.docBaseUrl || null;
  53832. var action = destDict.get('A'), url, dest;
  53833. if (isDict(action)) {
  53834. var linkType = action.get('S').name;
  53835. switch (linkType) {
  53836. case 'URI':
  53837. url = action.get('URI');
  53838. if (isName(url)) {
  53839. // Some bad PDFs do not put parentheses around relative URLs.
  53840. url = '/' + url.name;
  53841. } else if (isString(url)) {
  53842. url = addDefaultProtocolToUrl(url);
  53843. }
  53844. // TODO: pdf spec mentions urls can be relative to a Base
  53845. // entry in the dictionary.
  53846. break;
  53847. case 'GoTo':
  53848. dest = action.get('D');
  53849. break;
  53850. case 'Launch':
  53851. // We neither want, nor can, support arbitrary 'Launch' actions.
  53852. // However, in practice they are mostly used for linking to other PDF
  53853. // files, which we thus attempt to support (utilizing `docBaseUrl`).
  53854. case 'GoToR':
  53855. var urlDict = action.get('F');
  53856. if (isDict(urlDict)) {
  53857. // We assume that we found a FileSpec dictionary
  53858. // and fetch the URL without checking any further.
  53859. url = urlDict.get('F') || null;
  53860. } else if (isString(urlDict)) {
  53861. url = urlDict;
  53862. }
  53863. // NOTE: the destination is relative to the *remote* document.
  53864. var remoteDest = action.get('D');
  53865. if (remoteDest) {
  53866. if (isName(remoteDest)) {
  53867. remoteDest = remoteDest.name;
  53868. }
  53869. if (isString(url)) {
  53870. var baseUrl = url.split('#')[0];
  53871. if (isString(remoteDest)) {
  53872. // In practice, a named destination may contain only a number.
  53873. // If that happens, use the '#nameddest=' form to avoid the link
  53874. // redirecting to a page, instead of the correct destination.
  53875. url = baseUrl + '#' + (/^\d+$/.test(remoteDest) ? 'nameddest=' : '') + remoteDest;
  53876. } else if (isArray(remoteDest)) {
  53877. url = baseUrl + '#' + JSON.stringify(remoteDest);
  53878. }
  53879. }
  53880. }
  53881. // The 'NewWindow' property, equal to `LinkTarget.BLANK`.
  53882. var newWindow = action.get('NewWindow');
  53883. if (isBool(newWindow)) {
  53884. resultObj.newWindow = newWindow;
  53885. }
  53886. break;
  53887. case 'Named':
  53888. var namedAction = action.get('N');
  53889. if (isName(namedAction)) {
  53890. resultObj.action = namedAction.name;
  53891. }
  53892. break;
  53893. default:
  53894. warn('Catalog_parseDestDictionary: Unrecognized link type "' + linkType + '".');
  53895. break;
  53896. }
  53897. } else if (destDict.has('Dest')) {
  53898. // Simple destination link.
  53899. dest = destDict.get('Dest');
  53900. }
  53901. if (isString(url)) {
  53902. url = tryConvertUrlEncoding(url);
  53903. var absoluteUrl = createValidAbsoluteUrl(url, docBaseUrl);
  53904. if (absoluteUrl) {
  53905. resultObj.url = absoluteUrl.href;
  53906. }
  53907. resultObj.unsafeUrl = url;
  53908. }
  53909. if (dest) {
  53910. if (isName(dest)) {
  53911. dest = dest.name;
  53912. }
  53913. if (isString(dest) || isArray(dest)) {
  53914. resultObj.dest = dest;
  53915. }
  53916. }
  53917. };
  53918. return Catalog;
  53919. }();
  53920. var XRef = function XRefClosure() {
  53921. function XRef(stream, password) {
  53922. this.stream = stream;
  53923. this.entries = [];
  53924. this.xrefstms = Object.create(null);
  53925. // prepare the XRef cache
  53926. this.cache = [];
  53927. this.password = password;
  53928. this.stats = {
  53929. streamTypes: [],
  53930. fontTypes: []
  53931. };
  53932. }
  53933. XRef.prototype = {
  53934. setStartXRef: function XRef_setStartXRef(startXRef) {
  53935. // Store the starting positions of xref tables as we process them
  53936. // so we can recover from missing data errors
  53937. this.startXRefQueue = [startXRef];
  53938. },
  53939. parse: function XRef_parse(recoveryMode) {
  53940. var trailerDict;
  53941. if (!recoveryMode) {
  53942. trailerDict = this.readXRef();
  53943. } else {
  53944. warn('Indexing all PDF objects');
  53945. trailerDict = this.indexObjects();
  53946. }
  53947. trailerDict.assignXref(this);
  53948. this.trailer = trailerDict;
  53949. var encrypt = trailerDict.get('Encrypt');
  53950. if (encrypt) {
  53951. var ids = trailerDict.get('ID');
  53952. var fileId = ids && ids.length ? ids[0] : '';
  53953. // The 'Encrypt' dictionary itself should not be encrypted, and by
  53954. // setting `suppressEncryption` we can prevent an infinite loop inside
  53955. // of `XRef_fetchUncompressed` if the dictionary contains indirect
  53956. // objects (fixes issue7665.pdf).
  53957. encrypt.suppressEncryption = true;
  53958. this.encrypt = new CipherTransformFactory(encrypt, fileId, this.password);
  53959. }
  53960. // get the root dictionary (catalog) object
  53961. if (!(this.root = trailerDict.get('Root'))) {
  53962. error('Invalid root reference');
  53963. }
  53964. },
  53965. processXRefTable: function XRef_processXRefTable(parser) {
  53966. if (!('tableState' in this)) {
  53967. // Stores state of the table as we process it so we can resume
  53968. // from middle of table in case of missing data error
  53969. this.tableState = {
  53970. entryNum: 0,
  53971. streamPos: parser.lexer.stream.pos,
  53972. parserBuf1: parser.buf1,
  53973. parserBuf2: parser.buf2
  53974. };
  53975. }
  53976. var obj = this.readXRefTable(parser);
  53977. // Sanity check
  53978. if (!isCmd(obj, 'trailer')) {
  53979. error('Invalid XRef table: could not find trailer dictionary');
  53980. }
  53981. // Read trailer dictionary, e.g.
  53982. // trailer
  53983. // << /Size 22
  53984. // /Root 20R
  53985. // /Info 10R
  53986. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  53987. // >>
  53988. // The parser goes through the entire stream << ... >> and provides
  53989. // a getter interface for the key-value table
  53990. var dict = parser.getObj();
  53991. // The pdflib PDF generator can generate a nested trailer dictionary
  53992. if (!isDict(dict) && dict.dict) {
  53993. dict = dict.dict;
  53994. }
  53995. if (!isDict(dict)) {
  53996. error('Invalid XRef table: could not parse trailer dictionary');
  53997. }
  53998. delete this.tableState;
  53999. return dict;
  54000. },
  54001. readXRefTable: function XRef_readXRefTable(parser) {
  54002. // Example of cross-reference table:
  54003. // xref
  54004. // 0 1 <-- subsection header (first obj #, obj count)
  54005. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  54006. // 23 2 <-- subsection header ... and so on ...
  54007. // 0000025518 00002 n
  54008. // 0000025635 00000 n
  54009. // trailer
  54010. // ...
  54011. var stream = parser.lexer.stream;
  54012. var tableState = this.tableState;
  54013. stream.pos = tableState.streamPos;
  54014. parser.buf1 = tableState.parserBuf1;
  54015. parser.buf2 = tableState.parserBuf2;
  54016. // Outer loop is over subsection headers
  54017. var obj;
  54018. while (true) {
  54019. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  54020. if (isCmd(obj = parser.getObj(), 'trailer')) {
  54021. break;
  54022. }
  54023. tableState.firstEntryNum = obj;
  54024. tableState.entryCount = parser.getObj();
  54025. }
  54026. var first = tableState.firstEntryNum;
  54027. var count = tableState.entryCount;
  54028. if (!isInt(first) || !isInt(count)) {
  54029. error('Invalid XRef table: wrong types in subsection header');
  54030. }
  54031. // Inner loop is over objects themselves
  54032. for (var i = tableState.entryNum; i < count; i++) {
  54033. tableState.streamPos = stream.pos;
  54034. tableState.entryNum = i;
  54035. tableState.parserBuf1 = parser.buf1;
  54036. tableState.parserBuf2 = parser.buf2;
  54037. var entry = {};
  54038. entry.offset = parser.getObj();
  54039. entry.gen = parser.getObj();
  54040. var type = parser.getObj();
  54041. if (isCmd(type, 'f')) {
  54042. entry.free = true;
  54043. } else if (isCmd(type, 'n')) {
  54044. entry.uncompressed = true;
  54045. }
  54046. // Validate entry obj
  54047. if (!isInt(entry.offset) || !isInt(entry.gen) || !(entry.free || entry.uncompressed)) {
  54048. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  54049. }
  54050. // The first xref table entry, i.e. obj 0, should be free. Attempting
  54051. // to adjust an incorrect first obj # (fixes issue 3248 and 7229).
  54052. if (i === 0 && entry.free && first === 1) {
  54053. first = 0;
  54054. }
  54055. if (!this.entries[i + first]) {
  54056. this.entries[i + first] = entry;
  54057. }
  54058. }
  54059. tableState.entryNum = 0;
  54060. tableState.streamPos = stream.pos;
  54061. tableState.parserBuf1 = parser.buf1;
  54062. tableState.parserBuf2 = parser.buf2;
  54063. delete tableState.firstEntryNum;
  54064. delete tableState.entryCount;
  54065. }
  54066. // Sanity check: as per spec, first object must be free
  54067. if (this.entries[0] && !this.entries[0].free) {
  54068. error('Invalid XRef table: unexpected first object');
  54069. }
  54070. return obj;
  54071. },
  54072. processXRefStream: function XRef_processXRefStream(stream) {
  54073. if (!('streamState' in this)) {
  54074. // Stores state of the stream as we process it so we can resume
  54075. // from middle of stream in case of missing data error
  54076. var streamParameters = stream.dict;
  54077. var byteWidths = streamParameters.get('W');
  54078. var range = streamParameters.get('Index');
  54079. if (!range) {
  54080. range = [
  54081. 0,
  54082. streamParameters.get('Size')
  54083. ];
  54084. }
  54085. this.streamState = {
  54086. entryRanges: range,
  54087. byteWidths: byteWidths,
  54088. entryNum: 0,
  54089. streamPos: stream.pos
  54090. };
  54091. }
  54092. this.readXRefStream(stream);
  54093. delete this.streamState;
  54094. return stream.dict;
  54095. },
  54096. readXRefStream: function XRef_readXRefStream(stream) {
  54097. var i, j;
  54098. var streamState = this.streamState;
  54099. stream.pos = streamState.streamPos;
  54100. var byteWidths = streamState.byteWidths;
  54101. var typeFieldWidth = byteWidths[0];
  54102. var offsetFieldWidth = byteWidths[1];
  54103. var generationFieldWidth = byteWidths[2];
  54104. var entryRanges = streamState.entryRanges;
  54105. while (entryRanges.length > 0) {
  54106. var first = entryRanges[0];
  54107. var n = entryRanges[1];
  54108. if (!isInt(first) || !isInt(n)) {
  54109. error('Invalid XRef range fields: ' + first + ', ' + n);
  54110. }
  54111. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) || !isInt(generationFieldWidth)) {
  54112. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  54113. }
  54114. for (i = streamState.entryNum; i < n; ++i) {
  54115. streamState.entryNum = i;
  54116. streamState.streamPos = stream.pos;
  54117. var type = 0, offset = 0, generation = 0;
  54118. for (j = 0; j < typeFieldWidth; ++j) {
  54119. type = type << 8 | stream.getByte();
  54120. }
  54121. // if type field is absent, its default value is 1
  54122. if (typeFieldWidth === 0) {
  54123. type = 1;
  54124. }
  54125. for (j = 0; j < offsetFieldWidth; ++j) {
  54126. offset = offset << 8 | stream.getByte();
  54127. }
  54128. for (j = 0; j < generationFieldWidth; ++j) {
  54129. generation = generation << 8 | stream.getByte();
  54130. }
  54131. var entry = {};
  54132. entry.offset = offset;
  54133. entry.gen = generation;
  54134. switch (type) {
  54135. case 0:
  54136. entry.free = true;
  54137. break;
  54138. case 1:
  54139. entry.uncompressed = true;
  54140. break;
  54141. case 2:
  54142. break;
  54143. default:
  54144. error('Invalid XRef entry type: ' + type);
  54145. }
  54146. if (!this.entries[first + i]) {
  54147. this.entries[first + i] = entry;
  54148. }
  54149. }
  54150. streamState.entryNum = 0;
  54151. streamState.streamPos = stream.pos;
  54152. entryRanges.splice(0, 2);
  54153. }
  54154. },
  54155. indexObjects: function XRef_indexObjects() {
  54156. // Simple scan through the PDF content to find objects,
  54157. // trailers and XRef streams.
  54158. var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
  54159. var PERCENT = 0x25, LT = 0x3C;
  54160. function readToken(data, offset) {
  54161. var token = '', ch = data[offset];
  54162. while (ch !== LF && ch !== CR && ch !== LT) {
  54163. if (++offset >= data.length) {
  54164. break;
  54165. }
  54166. token += String.fromCharCode(ch);
  54167. ch = data[offset];
  54168. }
  54169. return token;
  54170. }
  54171. function skipUntil(data, offset, what) {
  54172. var length = what.length, dataLength = data.length;
  54173. var skipped = 0;
  54174. // finding byte sequence
  54175. while (offset < dataLength) {
  54176. var i = 0;
  54177. while (i < length && data[offset + i] === what[i]) {
  54178. ++i;
  54179. }
  54180. if (i >= length) {
  54181. break;
  54182. }
  54183. // sequence found
  54184. offset++;
  54185. skipped++;
  54186. }
  54187. return skipped;
  54188. }
  54189. var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  54190. var trailerBytes = new Uint8Array([
  54191. 116,
  54192. 114,
  54193. 97,
  54194. 105,
  54195. 108,
  54196. 101,
  54197. 114
  54198. ]);
  54199. var startxrefBytes = new Uint8Array([
  54200. 115,
  54201. 116,
  54202. 97,
  54203. 114,
  54204. 116,
  54205. 120,
  54206. 114,
  54207. 101,
  54208. 102
  54209. ]);
  54210. var endobjBytes = new Uint8Array([
  54211. 101,
  54212. 110,
  54213. 100,
  54214. 111,
  54215. 98,
  54216. 106
  54217. ]);
  54218. var xrefBytes = new Uint8Array([
  54219. 47,
  54220. 88,
  54221. 82,
  54222. 101,
  54223. 102
  54224. ]);
  54225. // Clear out any existing entries, since they may be bogus.
  54226. this.entries.length = 0;
  54227. var stream = this.stream;
  54228. stream.pos = 0;
  54229. var buffer = stream.getBytes();
  54230. var position = stream.start, length = buffer.length;
  54231. var trailers = [], xrefStms = [];
  54232. while (position < length) {
  54233. var ch = buffer[position];
  54234. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  54235. ++position;
  54236. continue;
  54237. }
  54238. if (ch === PERCENT) {
  54239. // %-comment
  54240. do {
  54241. ++position;
  54242. if (position >= length) {
  54243. break;
  54244. }
  54245. ch = buffer[position];
  54246. } while (ch !== LF && ch !== CR);
  54247. continue;
  54248. }
  54249. var token = readToken(buffer, position);
  54250. var m;
  54251. if (token.indexOf('xref') === 0 && (token.length === 4 || /\s/.test(token[4]))) {
  54252. position += skipUntil(buffer, position, trailerBytes);
  54253. trailers.push(position);
  54254. position += skipUntil(buffer, position, startxrefBytes);
  54255. } else if (m = objRegExp.exec(token)) {
  54256. if (typeof this.entries[m[1]] === 'undefined') {
  54257. this.entries[m[1]] = {
  54258. offset: position - stream.start,
  54259. gen: m[2] | 0,
  54260. uncompressed: true
  54261. };
  54262. }
  54263. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  54264. var content = buffer.subarray(position, position + contentLength);
  54265. // checking XRef stream suspect
  54266. // (it shall have '/XRef' and next char is not a letter)
  54267. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  54268. if (xrefTagOffset < contentLength && content[xrefTagOffset + 5] < 64) {
  54269. xrefStms.push(position - stream.start);
  54270. this.xrefstms[position - stream.start] = 1;
  54271. }
  54272. // Avoid recursion
  54273. position += contentLength;
  54274. } else if (token.indexOf('trailer') === 0 && (token.length === 7 || /\s/.test(token[7]))) {
  54275. trailers.push(position);
  54276. position += skipUntil(buffer, position, startxrefBytes);
  54277. } else {
  54278. position += token.length + 1;
  54279. }
  54280. }
  54281. // reading XRef streams
  54282. var i, ii;
  54283. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  54284. this.startXRefQueue.push(xrefStms[i]);
  54285. this.readXRef(/* recoveryMode */
  54286. true);
  54287. }
  54288. // finding main trailer
  54289. var dict;
  54290. for (i = 0, ii = trailers.length; i < ii; ++i) {
  54291. stream.pos = trailers[i];
  54292. var parser = new Parser(new Lexer(stream), /* allowStreams = */
  54293. true, /* xref = */
  54294. this, /* recoveryMode = */
  54295. true);
  54296. var obj = parser.getObj();
  54297. if (!isCmd(obj, 'trailer')) {
  54298. continue;
  54299. }
  54300. // read the trailer dictionary
  54301. dict = parser.getObj();
  54302. if (!isDict(dict)) {
  54303. continue;
  54304. }
  54305. // taking the first one with 'ID'
  54306. if (dict.has('ID')) {
  54307. return dict;
  54308. }
  54309. }
  54310. // no tailer with 'ID', taking last one (if exists)
  54311. if (dict) {
  54312. return dict;
  54313. }
  54314. // nothing helps
  54315. // calling error() would reject worker with an UnknownErrorException.
  54316. throw new InvalidPDFException('Invalid PDF structure');
  54317. },
  54318. readXRef: function XRef_readXRef(recoveryMode) {
  54319. var stream = this.stream;
  54320. try {
  54321. while (this.startXRefQueue.length) {
  54322. var startXRef = this.startXRefQueue[0];
  54323. stream.pos = startXRef + stream.start;
  54324. var parser = new Parser(new Lexer(stream), true, this);
  54325. var obj = parser.getObj();
  54326. var dict;
  54327. // Get dictionary
  54328. if (isCmd(obj, 'xref')) {
  54329. // Parse end-of-file XRef
  54330. dict = this.processXRefTable(parser);
  54331. if (!this.topDict) {
  54332. this.topDict = dict;
  54333. }
  54334. // Recursively get other XRefs 'XRefStm', if any
  54335. obj = dict.get('XRefStm');
  54336. if (isInt(obj)) {
  54337. var pos = obj;
  54338. // ignore previously loaded xref streams
  54339. // (possible infinite recursion)
  54340. if (!(pos in this.xrefstms)) {
  54341. this.xrefstms[pos] = 1;
  54342. this.startXRefQueue.push(pos);
  54343. }
  54344. }
  54345. } else if (isInt(obj)) {
  54346. // Parse in-stream XRef
  54347. if (!isInt(parser.getObj()) || !isCmd(parser.getObj(), 'obj') || !isStream(obj = parser.getObj())) {
  54348. error('Invalid XRef stream');
  54349. }
  54350. dict = this.processXRefStream(obj);
  54351. if (!this.topDict) {
  54352. this.topDict = dict;
  54353. }
  54354. if (!dict) {
  54355. error('Failed to read XRef stream');
  54356. }
  54357. } else {
  54358. error('Invalid XRef stream header');
  54359. }
  54360. // Recursively get previous dictionary, if any
  54361. obj = dict.get('Prev');
  54362. if (isInt(obj)) {
  54363. this.startXRefQueue.push(obj);
  54364. } else if (isRef(obj)) {
  54365. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  54366. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  54367. this.startXRefQueue.push(obj.num);
  54368. }
  54369. this.startXRefQueue.shift();
  54370. }
  54371. return this.topDict;
  54372. } catch (e) {
  54373. if (e instanceof MissingDataException) {
  54374. throw e;
  54375. }
  54376. info('(while reading XRef): ' + e);
  54377. }
  54378. if (recoveryMode) {
  54379. return;
  54380. }
  54381. throw new XRefParseException();
  54382. },
  54383. getEntry: function XRef_getEntry(i) {
  54384. var xrefEntry = this.entries[i];
  54385. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  54386. return xrefEntry;
  54387. }
  54388. return null;
  54389. },
  54390. fetchIfRef: function XRef_fetchIfRef(obj, suppressEncryption) {
  54391. if (!isRef(obj)) {
  54392. return obj;
  54393. }
  54394. return this.fetch(obj, suppressEncryption);
  54395. },
  54396. fetch: function XRef_fetch(ref, suppressEncryption) {
  54397. assert(isRef(ref), 'ref object is not a reference');
  54398. var num = ref.num;
  54399. if (num in this.cache) {
  54400. var cacheEntry = this.cache[num];
  54401. return cacheEntry;
  54402. }
  54403. var xrefEntry = this.getEntry(num);
  54404. // the referenced entry can be free
  54405. if (xrefEntry === null) {
  54406. return this.cache[num] = null;
  54407. }
  54408. if (xrefEntry.uncompressed) {
  54409. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  54410. } else {
  54411. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  54412. }
  54413. if (isDict(xrefEntry)) {
  54414. xrefEntry.objId = ref.toString();
  54415. } else if (isStream(xrefEntry)) {
  54416. xrefEntry.dict.objId = ref.toString();
  54417. }
  54418. return xrefEntry;
  54419. },
  54420. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry, suppressEncryption) {
  54421. var gen = ref.gen;
  54422. var num = ref.num;
  54423. if (xrefEntry.gen !== gen) {
  54424. error('inconsistent generation in XRef');
  54425. }
  54426. var stream = this.stream.makeSubStream(xrefEntry.offset + this.stream.start);
  54427. var parser = new Parser(new Lexer(stream), true, this);
  54428. var obj1 = parser.getObj();
  54429. var obj2 = parser.getObj();
  54430. var obj3 = parser.getObj();
  54431. if (!isInt(obj1) || parseInt(obj1, 10) !== num || !isInt(obj2) || parseInt(obj2, 10) !== gen || !isCmd(obj3)) {
  54432. error('bad XRef entry');
  54433. }
  54434. if (!isCmd(obj3, 'obj')) {
  54435. // some bad PDFs use "obj1234" and really mean 1234
  54436. if (obj3.cmd.indexOf('obj') === 0) {
  54437. num = parseInt(obj3.cmd.substring(3), 10);
  54438. if (!isNaN(num)) {
  54439. return num;
  54440. }
  54441. }
  54442. error('bad XRef entry');
  54443. }
  54444. if (this.encrypt && !suppressEncryption) {
  54445. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  54446. } else {
  54447. xrefEntry = parser.getObj();
  54448. }
  54449. if (!isStream(xrefEntry)) {
  54450. this.cache[num] = xrefEntry;
  54451. }
  54452. return xrefEntry;
  54453. },
  54454. fetchCompressed: function XRef_fetchCompressed(xrefEntry, suppressEncryption) {
  54455. var tableOffset = xrefEntry.offset;
  54456. var stream = this.fetch(new Ref(tableOffset, 0));
  54457. if (!isStream(stream)) {
  54458. error('bad ObjStm stream');
  54459. }
  54460. var first = stream.dict.get('First');
  54461. var n = stream.dict.get('N');
  54462. if (!isInt(first) || !isInt(n)) {
  54463. error('invalid first and n parameters for ObjStm stream');
  54464. }
  54465. var parser = new Parser(new Lexer(stream), false, this);
  54466. parser.allowStreams = true;
  54467. var i, entries = [], num, nums = [];
  54468. // read the object numbers to populate cache
  54469. for (i = 0; i < n; ++i) {
  54470. num = parser.getObj();
  54471. if (!isInt(num)) {
  54472. error('invalid object number in the ObjStm stream: ' + num);
  54473. }
  54474. nums.push(num);
  54475. var offset = parser.getObj();
  54476. if (!isInt(offset)) {
  54477. error('invalid object offset in the ObjStm stream: ' + offset);
  54478. }
  54479. }
  54480. // read stream objects for cache
  54481. for (i = 0; i < n; ++i) {
  54482. entries.push(parser.getObj());
  54483. // The ObjStm should not contain 'endobj'. If it's present, skip over it
  54484. // to support corrupt PDFs (fixes issue 5241, bug 898610, bug 1037816).
  54485. if (isCmd(parser.buf1, 'endobj')) {
  54486. parser.shift();
  54487. }
  54488. num = nums[i];
  54489. var entry = this.entries[num];
  54490. if (entry && entry.offset === tableOffset && entry.gen === i) {
  54491. this.cache[num] = entries[i];
  54492. }
  54493. }
  54494. xrefEntry = entries[xrefEntry.gen];
  54495. if (xrefEntry === undefined) {
  54496. error('bad XRef entry for compressed object');
  54497. }
  54498. return xrefEntry;
  54499. },
  54500. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj, suppressEncryption) {
  54501. if (!isRef(obj)) {
  54502. return Promise.resolve(obj);
  54503. }
  54504. return this.fetchAsync(obj, suppressEncryption);
  54505. },
  54506. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  54507. var streamManager = this.stream.manager;
  54508. var xref = this;
  54509. return new Promise(function tryFetch(resolve, reject) {
  54510. try {
  54511. resolve(xref.fetch(ref, suppressEncryption));
  54512. } catch (e) {
  54513. if (e instanceof MissingDataException) {
  54514. streamManager.requestRange(e.begin, e.end).then(function () {
  54515. tryFetch(resolve, reject);
  54516. }, reject);
  54517. return;
  54518. }
  54519. reject(e);
  54520. }
  54521. });
  54522. },
  54523. getCatalogObj: function XRef_getCatalogObj() {
  54524. return this.root;
  54525. }
  54526. };
  54527. return XRef;
  54528. }();
  54529. /**
  54530. * A NameTree/NumberTree is like a Dict but has some advantageous properties,
  54531. * see the specification (7.9.6 and 7.9.7) for additional details.
  54532. * TODO: implement all the Dict functions and make this more efficient.
  54533. */
  54534. var NameOrNumberTree = function NameOrNumberTreeClosure() {
  54535. function NameOrNumberTree(root, xref) {
  54536. throw new Error('Cannot initialize NameOrNumberTree.');
  54537. }
  54538. NameOrNumberTree.prototype = {
  54539. getAll: function NameOrNumberTree_getAll() {
  54540. var dict = Object.create(null);
  54541. if (!this.root) {
  54542. return dict;
  54543. }
  54544. var xref = this.xref;
  54545. // Reading Name/Number tree.
  54546. var processed = new RefSet();
  54547. processed.put(this.root);
  54548. var queue = [this.root];
  54549. while (queue.length > 0) {
  54550. var i, n;
  54551. var obj = xref.fetchIfRef(queue.shift());
  54552. if (!isDict(obj)) {
  54553. continue;
  54554. }
  54555. if (obj.has('Kids')) {
  54556. var kids = obj.get('Kids');
  54557. for (i = 0, n = kids.length; i < n; i++) {
  54558. var kid = kids[i];
  54559. assert(!processed.has(kid), 'Duplicate entry in "' + this._type + '" tree.');
  54560. queue.push(kid);
  54561. processed.put(kid);
  54562. }
  54563. continue;
  54564. }
  54565. var entries = obj.get(this._type);
  54566. if (isArray(entries)) {
  54567. for (i = 0, n = entries.length; i < n; i += 2) {
  54568. dict[xref.fetchIfRef(entries[i])] = xref.fetchIfRef(entries[i + 1]);
  54569. }
  54570. }
  54571. }
  54572. return dict;
  54573. },
  54574. get: function NameOrNumberTree_get(key) {
  54575. if (!this.root) {
  54576. return null;
  54577. }
  54578. var xref = this.xref;
  54579. var kidsOrEntries = xref.fetchIfRef(this.root);
  54580. var loopCount = 0;
  54581. var MAX_LEVELS = 10;
  54582. var l, r, m;
  54583. // Perform a binary search to quickly find the entry that
  54584. // contains the key we are looking for.
  54585. while (kidsOrEntries.has('Kids')) {
  54586. if (++loopCount > MAX_LEVELS) {
  54587. warn('Search depth limit reached for "' + this._type + '" tree.');
  54588. return null;
  54589. }
  54590. var kids = kidsOrEntries.get('Kids');
  54591. if (!isArray(kids)) {
  54592. return null;
  54593. }
  54594. l = 0;
  54595. r = kids.length - 1;
  54596. while (l <= r) {
  54597. m = l + r >> 1;
  54598. var kid = xref.fetchIfRef(kids[m]);
  54599. var limits = kid.get('Limits');
  54600. if (key < xref.fetchIfRef(limits[0])) {
  54601. r = m - 1;
  54602. } else if (key > xref.fetchIfRef(limits[1])) {
  54603. l = m + 1;
  54604. } else {
  54605. kidsOrEntries = xref.fetchIfRef(kids[m]);
  54606. break;
  54607. }
  54608. }
  54609. if (l > r) {
  54610. return null;
  54611. }
  54612. }
  54613. // If we get here, then we have found the right entry. Now go through the
  54614. // entries in the dictionary until we find the key we're looking for.
  54615. var entries = kidsOrEntries.get(this._type);
  54616. if (isArray(entries)) {
  54617. // Perform a binary search to reduce the lookup time.
  54618. l = 0;
  54619. r = entries.length - 2;
  54620. while (l <= r) {
  54621. // Check only even indices (0, 2, 4, ...) because the
  54622. // odd indices contain the actual data.
  54623. m = l + r & ~1;
  54624. var currentKey = xref.fetchIfRef(entries[m]);
  54625. if (key < currentKey) {
  54626. r = m - 2;
  54627. } else if (key > currentKey) {
  54628. l = m + 2;
  54629. } else {
  54630. return xref.fetchIfRef(entries[m + 1]);
  54631. }
  54632. }
  54633. }
  54634. return null;
  54635. }
  54636. };
  54637. return NameOrNumberTree;
  54638. }();
  54639. var NameTree = function NameTreeClosure() {
  54640. function NameTree(root, xref) {
  54641. this.root = root;
  54642. this.xref = xref;
  54643. this._type = 'Names';
  54644. }
  54645. Util.inherit(NameTree, NameOrNumberTree, {});
  54646. return NameTree;
  54647. }();
  54648. var NumberTree = function NumberTreeClosure() {
  54649. function NumberTree(root, xref) {
  54650. this.root = root;
  54651. this.xref = xref;
  54652. this._type = 'Nums';
  54653. }
  54654. Util.inherit(NumberTree, NameOrNumberTree, {});
  54655. return NumberTree;
  54656. }();
  54657. /**
  54658. * "A PDF file can refer to the contents of another file by using a File
  54659. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  54660. * NOTE: Only embedded files are supported (as part of the attachments support)
  54661. * TODO: support the 'URL' file system (with caching if !/V), portable
  54662. * collections attributes and related files (/RF)
  54663. */
  54664. var FileSpec = function FileSpecClosure() {
  54665. function FileSpec(root, xref) {
  54666. if (!root || !isDict(root)) {
  54667. return;
  54668. }
  54669. this.xref = xref;
  54670. this.root = root;
  54671. if (root.has('FS')) {
  54672. this.fs = root.get('FS');
  54673. }
  54674. this.description = root.has('Desc') ? stringToPDFString(root.get('Desc')) : '';
  54675. if (root.has('RF')) {
  54676. warn('Related file specifications are not supported');
  54677. }
  54678. this.contentAvailable = true;
  54679. if (!root.has('EF')) {
  54680. this.contentAvailable = false;
  54681. warn('Non-embedded file specifications are not supported');
  54682. }
  54683. }
  54684. function pickPlatformItem(dict) {
  54685. // Look for the filename in this order:
  54686. // UF, F, Unix, Mac, DOS
  54687. if (dict.has('UF')) {
  54688. return dict.get('UF');
  54689. } else if (dict.has('F')) {
  54690. return dict.get('F');
  54691. } else if (dict.has('Unix')) {
  54692. return dict.get('Unix');
  54693. } else if (dict.has('Mac')) {
  54694. return dict.get('Mac');
  54695. } else if (dict.has('DOS')) {
  54696. return dict.get('DOS');
  54697. } else {
  54698. return null;
  54699. }
  54700. }
  54701. FileSpec.prototype = {
  54702. get filename() {
  54703. if (!this._filename && this.root) {
  54704. var filename = pickPlatformItem(this.root) || 'unnamed';
  54705. this._filename = stringToPDFString(filename).replace(/\\\\/g, '\\').replace(/\\\//g, '/').replace(/\\/g, '/');
  54706. }
  54707. return this._filename;
  54708. },
  54709. get content() {
  54710. if (!this.contentAvailable) {
  54711. return null;
  54712. }
  54713. if (!this.contentRef && this.root) {
  54714. this.contentRef = pickPlatformItem(this.root.get('EF'));
  54715. }
  54716. var content = null;
  54717. if (this.contentRef) {
  54718. var xref = this.xref;
  54719. var fileObj = xref.fetchIfRef(this.contentRef);
  54720. if (fileObj && isStream(fileObj)) {
  54721. content = fileObj.getBytes();
  54722. } else {
  54723. warn('Embedded file specification points to non-existing/invalid ' + 'content');
  54724. }
  54725. } else {
  54726. warn('Embedded file specification does not have a content');
  54727. }
  54728. return content;
  54729. },
  54730. get serializable() {
  54731. return {
  54732. filename: this.filename,
  54733. content: this.content
  54734. };
  54735. }
  54736. };
  54737. return FileSpec;
  54738. }();
  54739. /**
  54740. * A helper for loading missing data in object graphs. It traverses the graph
  54741. * depth first and queues up any objects that have missing data. Once it has
  54742. * has traversed as many objects that are available it attempts to bundle the
  54743. * missing data requests and then resume from the nodes that weren't ready.
  54744. *
  54745. * NOTE: It provides protection from circular references by keeping track of
  54746. * of loaded references. However, you must be careful not to load any graphs
  54747. * that have references to the catalog or other pages since that will cause the
  54748. * entire PDF document object graph to be traversed.
  54749. */
  54750. var ObjectLoader = function () {
  54751. function mayHaveChildren(value) {
  54752. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  54753. }
  54754. function addChildren(node, nodesToVisit) {
  54755. var value;
  54756. if (isDict(node) || isStream(node)) {
  54757. var map;
  54758. if (isDict(node)) {
  54759. map = node.map;
  54760. } else {
  54761. map = node.dict.map;
  54762. }
  54763. for (var key in map) {
  54764. value = map[key];
  54765. if (mayHaveChildren(value)) {
  54766. nodesToVisit.push(value);
  54767. }
  54768. }
  54769. } else if (isArray(node)) {
  54770. for (var i = 0, ii = node.length; i < ii; i++) {
  54771. value = node[i];
  54772. if (mayHaveChildren(value)) {
  54773. nodesToVisit.push(value);
  54774. }
  54775. }
  54776. }
  54777. }
  54778. function ObjectLoader(obj, keys, xref) {
  54779. this.obj = obj;
  54780. this.keys = keys;
  54781. this.xref = xref;
  54782. this.refSet = null;
  54783. this.capability = null;
  54784. }
  54785. ObjectLoader.prototype = {
  54786. load: function ObjectLoader_load() {
  54787. var keys = this.keys;
  54788. this.capability = createPromiseCapability();
  54789. // Don't walk the graph if all the data is already loaded.
  54790. if (!(this.xref.stream instanceof ChunkedStream) || this.xref.stream.getMissingChunks().length === 0) {
  54791. this.capability.resolve();
  54792. return this.capability.promise;
  54793. }
  54794. this.refSet = new RefSet();
  54795. // Setup the initial nodes to visit.
  54796. var nodesToVisit = [];
  54797. for (var i = 0; i < keys.length; i++) {
  54798. nodesToVisit.push(this.obj[keys[i]]);
  54799. }
  54800. this._walk(nodesToVisit);
  54801. return this.capability.promise;
  54802. },
  54803. _walk: function ObjectLoader_walk(nodesToVisit) {
  54804. var nodesToRevisit = [];
  54805. var pendingRequests = [];
  54806. // DFS walk of the object graph.
  54807. while (nodesToVisit.length) {
  54808. var currentNode = nodesToVisit.pop();
  54809. // Only references or chunked streams can cause missing data exceptions.
  54810. if (isRef(currentNode)) {
  54811. // Skip nodes that have already been visited.
  54812. if (this.refSet.has(currentNode)) {
  54813. continue;
  54814. }
  54815. try {
  54816. var ref = currentNode;
  54817. this.refSet.put(ref);
  54818. currentNode = this.xref.fetch(currentNode);
  54819. } catch (e) {
  54820. if (!(e instanceof MissingDataException)) {
  54821. throw e;
  54822. }
  54823. nodesToRevisit.push(currentNode);
  54824. pendingRequests.push({
  54825. begin: e.begin,
  54826. end: e.end
  54827. });
  54828. }
  54829. }
  54830. if (currentNode && currentNode.getBaseStreams) {
  54831. var baseStreams = currentNode.getBaseStreams();
  54832. var foundMissingData = false;
  54833. for (var i = 0; i < baseStreams.length; i++) {
  54834. var stream = baseStreams[i];
  54835. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  54836. foundMissingData = true;
  54837. pendingRequests.push({
  54838. begin: stream.start,
  54839. end: stream.end
  54840. });
  54841. }
  54842. }
  54843. if (foundMissingData) {
  54844. nodesToRevisit.push(currentNode);
  54845. }
  54846. }
  54847. addChildren(currentNode, nodesToVisit);
  54848. }
  54849. if (pendingRequests.length) {
  54850. this.xref.stream.manager.requestRanges(pendingRequests).then(function pendingRequestCallback() {
  54851. nodesToVisit = nodesToRevisit;
  54852. for (var i = 0; i < nodesToRevisit.length; i++) {
  54853. var node = nodesToRevisit[i];
  54854. // Remove any reference nodes from the currrent refset so they
  54855. // aren't skipped when we revist them.
  54856. if (isRef(node)) {
  54857. this.refSet.remove(node);
  54858. }
  54859. }
  54860. this._walk(nodesToVisit);
  54861. }.bind(this), this.capability.reject);
  54862. return;
  54863. }
  54864. // Everything is loaded.
  54865. this.refSet = null;
  54866. this.capability.resolve();
  54867. }
  54868. };
  54869. return ObjectLoader;
  54870. }();
  54871. exports.Catalog = Catalog;
  54872. exports.ObjectLoader = ObjectLoader;
  54873. exports.XRef = XRef;
  54874. exports.FileSpec = FileSpec;
  54875. }));
  54876. (function (root, factory) {
  54877. factory(root.pdfjsCorePattern = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreFunction, root.pdfjsCoreColorSpace);
  54878. }(this, function (exports, sharedUtil, corePrimitives, coreFunction, coreColorSpace) {
  54879. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  54880. var MissingDataException = sharedUtil.MissingDataException;
  54881. var Util = sharedUtil.Util;
  54882. var assert = sharedUtil.assert;
  54883. var error = sharedUtil.error;
  54884. var info = sharedUtil.info;
  54885. var warn = sharedUtil.warn;
  54886. var isStream = corePrimitives.isStream;
  54887. var PDFFunction = coreFunction.PDFFunction;
  54888. var ColorSpace = coreColorSpace.ColorSpace;
  54889. var ShadingType = {
  54890. FUNCTION_BASED: 1,
  54891. AXIAL: 2,
  54892. RADIAL: 3,
  54893. FREE_FORM_MESH: 4,
  54894. LATTICE_FORM_MESH: 5,
  54895. COONS_PATCH_MESH: 6,
  54896. TENSOR_PATCH_MESH: 7
  54897. };
  54898. var Pattern = function PatternClosure() {
  54899. // Constructor should define this.getPattern
  54900. function Pattern() {
  54901. error('should not call Pattern constructor');
  54902. }
  54903. Pattern.prototype = {
  54904. // Input: current Canvas context
  54905. // Output: the appropriate fillStyle or strokeStyle
  54906. getPattern: function Pattern_getPattern(ctx) {
  54907. error('Should not call Pattern.getStyle: ' + ctx);
  54908. }
  54909. };
  54910. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref, res, handler) {
  54911. var dict = isStream(shading) ? shading.dict : shading;
  54912. var type = dict.get('ShadingType');
  54913. try {
  54914. switch (type) {
  54915. case ShadingType.AXIAL:
  54916. case ShadingType.RADIAL:
  54917. // Both radial and axial shadings are handled by RadialAxial shading.
  54918. return new Shadings.RadialAxial(dict, matrix, xref, res);
  54919. case ShadingType.FREE_FORM_MESH:
  54920. case ShadingType.LATTICE_FORM_MESH:
  54921. case ShadingType.COONS_PATCH_MESH:
  54922. case ShadingType.TENSOR_PATCH_MESH:
  54923. return new Shadings.Mesh(shading, matrix, xref, res);
  54924. default:
  54925. throw new Error('Unsupported ShadingType: ' + type);
  54926. }
  54927. } catch (ex) {
  54928. if (ex instanceof MissingDataException) {
  54929. throw ex;
  54930. }
  54931. handler.send('UnsupportedFeature', { featureId: UNSUPPORTED_FEATURES.shadingPattern });
  54932. warn(ex);
  54933. return new Shadings.Dummy();
  54934. }
  54935. };
  54936. return Pattern;
  54937. }();
  54938. var Shadings = {};
  54939. // A small number to offset the first/last color stops so we can insert ones to
  54940. // support extend. Number.MIN_VALUE is too small and breaks the extend.
  54941. Shadings.SMALL_NUMBER = 1e-6;
  54942. // Radial and axial shading have very similar implementations
  54943. // If needed, the implementations can be broken into two classes
  54944. Shadings.RadialAxial = function RadialAxialClosure() {
  54945. function RadialAxial(dict, matrix, xref, res) {
  54946. this.matrix = matrix;
  54947. this.coordsArr = dict.getArray('Coords');
  54948. this.shadingType = dict.get('ShadingType');
  54949. this.type = 'Pattern';
  54950. var cs = dict.get('ColorSpace', 'CS');
  54951. cs = ColorSpace.parse(cs, xref, res);
  54952. this.cs = cs;
  54953. var t0 = 0.0, t1 = 1.0;
  54954. if (dict.has('Domain')) {
  54955. var domainArr = dict.getArray('Domain');
  54956. t0 = domainArr[0];
  54957. t1 = domainArr[1];
  54958. }
  54959. var extendStart = false, extendEnd = false;
  54960. if (dict.has('Extend')) {
  54961. var extendArr = dict.getArray('Extend');
  54962. extendStart = extendArr[0];
  54963. extendEnd = extendArr[1];
  54964. }
  54965. if (this.shadingType === ShadingType.RADIAL && (!extendStart || !extendEnd)) {
  54966. // Radial gradient only currently works if either circle is fully within
  54967. // the other circle.
  54968. var x1 = this.coordsArr[0];
  54969. var y1 = this.coordsArr[1];
  54970. var r1 = this.coordsArr[2];
  54971. var x2 = this.coordsArr[3];
  54972. var y2 = this.coordsArr[4];
  54973. var r2 = this.coordsArr[5];
  54974. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  54975. if (r1 <= r2 + distance && r2 <= r1 + distance) {
  54976. warn('Unsupported radial gradient.');
  54977. }
  54978. }
  54979. this.extendStart = extendStart;
  54980. this.extendEnd = extendEnd;
  54981. var fnObj = dict.get('Function');
  54982. var fn = PDFFunction.parseArray(xref, fnObj);
  54983. // 10 samples seems good enough for now, but probably won't work
  54984. // if there are sharp color changes. Ideally, we would implement
  54985. // the spec faithfully and add lossless optimizations.
  54986. var diff = t1 - t0;
  54987. var step = diff / 10;
  54988. var colorStops = this.colorStops = [];
  54989. // Protect against bad domains so we don't end up in an infinte loop below.
  54990. if (t0 >= t1 || step <= 0) {
  54991. // Acrobat doesn't seem to handle these cases so we'll ignore for
  54992. // now.
  54993. info('Bad shading domain.');
  54994. return;
  54995. }
  54996. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  54997. var rgbColor;
  54998. for (var i = t0; i <= t1; i += step) {
  54999. ratio[0] = i;
  55000. fn(ratio, 0, color, 0);
  55001. rgbColor = cs.getRgb(color, 0);
  55002. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  55003. colorStops.push([
  55004. (i - t0) / diff,
  55005. cssColor
  55006. ]);
  55007. }
  55008. var background = 'transparent';
  55009. if (dict.has('Background')) {
  55010. rgbColor = cs.getRgb(dict.get('Background'), 0);
  55011. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  55012. }
  55013. if (!extendStart) {
  55014. // Insert a color stop at the front and offset the first real color stop
  55015. // so it doesn't conflict with the one we insert.
  55016. colorStops.unshift([
  55017. 0,
  55018. background
  55019. ]);
  55020. colorStops[1][0] += Shadings.SMALL_NUMBER;
  55021. }
  55022. if (!extendEnd) {
  55023. // Same idea as above in extendStart but for the end.
  55024. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  55025. colorStops.push([
  55026. 1,
  55027. background
  55028. ]);
  55029. }
  55030. this.colorStops = colorStops;
  55031. }
  55032. RadialAxial.prototype = {
  55033. getIR: function RadialAxial_getIR() {
  55034. var coordsArr = this.coordsArr;
  55035. var shadingType = this.shadingType;
  55036. var type, p0, p1, r0, r1;
  55037. if (shadingType === ShadingType.AXIAL) {
  55038. p0 = [
  55039. coordsArr[0],
  55040. coordsArr[1]
  55041. ];
  55042. p1 = [
  55043. coordsArr[2],
  55044. coordsArr[3]
  55045. ];
  55046. r0 = null;
  55047. r1 = null;
  55048. type = 'axial';
  55049. } else if (shadingType === ShadingType.RADIAL) {
  55050. p0 = [
  55051. coordsArr[0],
  55052. coordsArr[1]
  55053. ];
  55054. p1 = [
  55055. coordsArr[3],
  55056. coordsArr[4]
  55057. ];
  55058. r0 = coordsArr[2];
  55059. r1 = coordsArr[5];
  55060. type = 'radial';
  55061. } else {
  55062. error('getPattern type unknown: ' + shadingType);
  55063. }
  55064. var matrix = this.matrix;
  55065. if (matrix) {
  55066. p0 = Util.applyTransform(p0, matrix);
  55067. p1 = Util.applyTransform(p1, matrix);
  55068. if (shadingType === ShadingType.RADIAL) {
  55069. var scale = Util.singularValueDecompose2dScale(matrix);
  55070. r0 *= scale[0];
  55071. r1 *= scale[1];
  55072. }
  55073. }
  55074. return [
  55075. 'RadialAxial',
  55076. type,
  55077. this.colorStops,
  55078. p0,
  55079. p1,
  55080. r0,
  55081. r1
  55082. ];
  55083. }
  55084. };
  55085. return RadialAxial;
  55086. }();
  55087. // All mesh shading. For now, they will be presented as set of the triangles
  55088. // to be drawn on the canvas and rgb color for each vertex.
  55089. Shadings.Mesh = function MeshClosure() {
  55090. function MeshStreamReader(stream, context) {
  55091. this.stream = stream;
  55092. this.context = context;
  55093. this.buffer = 0;
  55094. this.bufferLength = 0;
  55095. var numComps = context.numComps;
  55096. this.tmpCompsBuf = new Float32Array(numComps);
  55097. var csNumComps = context.colorSpace.numComps;
  55098. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) : this.tmpCompsBuf;
  55099. }
  55100. MeshStreamReader.prototype = {
  55101. get hasData() {
  55102. if (this.stream.end) {
  55103. return this.stream.pos < this.stream.end;
  55104. }
  55105. if (this.bufferLength > 0) {
  55106. return true;
  55107. }
  55108. var nextByte = this.stream.getByte();
  55109. if (nextByte < 0) {
  55110. return false;
  55111. }
  55112. this.buffer = nextByte;
  55113. this.bufferLength = 8;
  55114. return true;
  55115. },
  55116. readBits: function MeshStreamReader_readBits(n) {
  55117. var buffer = this.buffer;
  55118. var bufferLength = this.bufferLength;
  55119. if (n === 32) {
  55120. if (bufferLength === 0) {
  55121. return (this.stream.getByte() << 24 | this.stream.getByte() << 16 | this.stream.getByte() << 8 | this.stream.getByte()) >>> 0;
  55122. }
  55123. buffer = buffer << 24 | this.stream.getByte() << 16 | this.stream.getByte() << 8 | this.stream.getByte();
  55124. var nextByte = this.stream.getByte();
  55125. this.buffer = nextByte & (1 << bufferLength) - 1;
  55126. return (buffer << 8 - bufferLength | (nextByte & 0xFF) >> bufferLength) >>> 0;
  55127. }
  55128. if (n === 8 && bufferLength === 0) {
  55129. return this.stream.getByte();
  55130. }
  55131. while (bufferLength < n) {
  55132. buffer = buffer << 8 | this.stream.getByte();
  55133. bufferLength += 8;
  55134. }
  55135. bufferLength -= n;
  55136. this.bufferLength = bufferLength;
  55137. this.buffer = buffer & (1 << bufferLength) - 1;
  55138. return buffer >> bufferLength;
  55139. },
  55140. align: function MeshStreamReader_align() {
  55141. this.buffer = 0;
  55142. this.bufferLength = 0;
  55143. },
  55144. readFlag: function MeshStreamReader_readFlag() {
  55145. return this.readBits(this.context.bitsPerFlag);
  55146. },
  55147. readCoordinate: function MeshStreamReader_readCoordinate() {
  55148. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  55149. var xi = this.readBits(bitsPerCoordinate);
  55150. var yi = this.readBits(bitsPerCoordinate);
  55151. var decode = this.context.decode;
  55152. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) : 2.3283064365386963e-10;
  55153. // 2 ^ -32
  55154. return [
  55155. xi * scale * (decode[1] - decode[0]) + decode[0],
  55156. yi * scale * (decode[3] - decode[2]) + decode[2]
  55157. ];
  55158. },
  55159. readComponents: function MeshStreamReader_readComponents() {
  55160. var numComps = this.context.numComps;
  55161. var bitsPerComponent = this.context.bitsPerComponent;
  55162. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) : 2.3283064365386963e-10;
  55163. // 2 ^ -32
  55164. var decode = this.context.decode;
  55165. var components = this.tmpCompsBuf;
  55166. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  55167. var ci = this.readBits(bitsPerComponent);
  55168. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  55169. }
  55170. var color = this.tmpCsCompsBuf;
  55171. if (this.context.colorFn) {
  55172. this.context.colorFn(components, 0, color, 0);
  55173. }
  55174. return this.context.colorSpace.getRgb(color, 0);
  55175. }
  55176. };
  55177. function decodeType4Shading(mesh, reader) {
  55178. var coords = mesh.coords;
  55179. var colors = mesh.colors;
  55180. var operators = [];
  55181. var ps = [];
  55182. // not maintaining cs since that will match ps
  55183. var verticesLeft = 0;
  55184. // assuming we have all data to start a new triangle
  55185. while (reader.hasData) {
  55186. var f = reader.readFlag();
  55187. var coord = reader.readCoordinate();
  55188. var color = reader.readComponents();
  55189. if (verticesLeft === 0) {
  55190. // ignoring flags if we started a triangle
  55191. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  55192. switch (f) {
  55193. case 0:
  55194. verticesLeft = 3;
  55195. break;
  55196. case 1:
  55197. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  55198. verticesLeft = 1;
  55199. break;
  55200. case 2:
  55201. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  55202. verticesLeft = 1;
  55203. break;
  55204. }
  55205. operators.push(f);
  55206. }
  55207. ps.push(coords.length);
  55208. coords.push(coord);
  55209. colors.push(color);
  55210. verticesLeft--;
  55211. reader.align();
  55212. }
  55213. mesh.figures.push({
  55214. type: 'triangles',
  55215. coords: new Int32Array(ps),
  55216. colors: new Int32Array(ps)
  55217. });
  55218. }
  55219. function decodeType5Shading(mesh, reader, verticesPerRow) {
  55220. var coords = mesh.coords;
  55221. var colors = mesh.colors;
  55222. var ps = [];
  55223. // not maintaining cs since that will match ps
  55224. while (reader.hasData) {
  55225. var coord = reader.readCoordinate();
  55226. var color = reader.readComponents();
  55227. ps.push(coords.length);
  55228. coords.push(coord);
  55229. colors.push(color);
  55230. }
  55231. mesh.figures.push({
  55232. type: 'lattice',
  55233. coords: new Int32Array(ps),
  55234. colors: new Int32Array(ps),
  55235. verticesPerRow: verticesPerRow
  55236. });
  55237. }
  55238. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  55239. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  55240. var TRIANGLE_DENSITY = 20;
  55241. // count of triangles per entire mesh bounds
  55242. var getB = function getBClosure() {
  55243. function buildB(count) {
  55244. var lut = [];
  55245. for (var i = 0; i <= count; i++) {
  55246. var t = i / count, t_ = 1 - t;
  55247. lut.push(new Float32Array([
  55248. t_ * t_ * t_,
  55249. 3 * t * t_ * t_,
  55250. 3 * t * t * t_,
  55251. t * t * t
  55252. ]));
  55253. }
  55254. return lut;
  55255. }
  55256. var cache = [];
  55257. return function getB(count) {
  55258. if (!cache[count]) {
  55259. cache[count] = buildB(count);
  55260. }
  55261. return cache[count];
  55262. };
  55263. }();
  55264. function buildFigureFromPatch(mesh, index) {
  55265. var figure = mesh.figures[index];
  55266. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  55267. var coords = mesh.coords, colors = mesh.colors;
  55268. var pi = figure.coords;
  55269. var ci = figure.colors;
  55270. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0], coords[pi[12]][0], coords[pi[15]][0]);
  55271. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1], coords[pi[12]][1], coords[pi[15]][1]);
  55272. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0], coords[pi[12]][0], coords[pi[15]][0]);
  55273. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1], coords[pi[12]][1], coords[pi[15]][1]);
  55274. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY / (mesh.bounds[2] - mesh.bounds[0]));
  55275. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT, Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  55276. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY / (mesh.bounds[3] - mesh.bounds[1]));
  55277. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT, Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  55278. var verticesPerRow = splitXBy + 1;
  55279. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  55280. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  55281. var k = 0;
  55282. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  55283. var c0 = colors[ci[0]], c1 = colors[ci[1]], c2 = colors[ci[2]], c3 = colors[ci[3]];
  55284. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  55285. for (var row = 0; row <= splitYBy; row++) {
  55286. cl[0] = (c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy | 0;
  55287. cl[1] = (c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy | 0;
  55288. cl[2] = (c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy | 0;
  55289. cr[0] = (c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy | 0;
  55290. cr[1] = (c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy | 0;
  55291. cr[2] = (c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy | 0;
  55292. for (var col = 0; col <= splitXBy; col++, k++) {
  55293. if ((row === 0 || row === splitYBy) && (col === 0 || col === splitXBy)) {
  55294. continue;
  55295. }
  55296. var x = 0, y = 0;
  55297. var q = 0;
  55298. for (var i = 0; i <= 3; i++) {
  55299. for (var j = 0; j <= 3; j++, q++) {
  55300. var m = bRow[row][i] * bCol[col][j];
  55301. x += coords[pi[q]][0] * m;
  55302. y += coords[pi[q]][1] * m;
  55303. }
  55304. }
  55305. figureCoords[k] = coords.length;
  55306. coords.push([
  55307. x,
  55308. y
  55309. ]);
  55310. figureColors[k] = colors.length;
  55311. var newColor = new Uint8Array(3);
  55312. newColor[0] = (cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy | 0;
  55313. newColor[1] = (cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy | 0;
  55314. newColor[2] = (cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy | 0;
  55315. colors.push(newColor);
  55316. }
  55317. }
  55318. figureCoords[0] = pi[0];
  55319. figureColors[0] = ci[0];
  55320. figureCoords[splitXBy] = pi[3];
  55321. figureColors[splitXBy] = ci[1];
  55322. figureCoords[verticesPerRow * splitYBy] = pi[12];
  55323. figureColors[verticesPerRow * splitYBy] = ci[2];
  55324. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  55325. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  55326. mesh.figures[index] = {
  55327. type: 'lattice',
  55328. coords: figureCoords,
  55329. colors: figureColors,
  55330. verticesPerRow: verticesPerRow
  55331. };
  55332. }
  55333. function decodeType6Shading(mesh, reader) {
  55334. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  55335. var coords = mesh.coords;
  55336. var colors = mesh.colors;
  55337. var ps = new Int32Array(16);
  55338. // p00, p10, ..., p30, p01, ..., p33
  55339. var cs = new Int32Array(4);
  55340. // c00, c30, c03, c33
  55341. while (reader.hasData) {
  55342. var f = reader.readFlag();
  55343. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  55344. var i, ii;
  55345. var pi = coords.length;
  55346. for (i = 0, ii = f !== 0 ? 8 : 12; i < ii; i++) {
  55347. coords.push(reader.readCoordinate());
  55348. }
  55349. var ci = colors.length;
  55350. for (i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
  55351. colors.push(reader.readComponents());
  55352. }
  55353. var tmp1, tmp2, tmp3, tmp4;
  55354. switch (f) {
  55355. case 0:
  55356. ps[12] = pi + 3;
  55357. ps[13] = pi + 4;
  55358. ps[14] = pi + 5;
  55359. ps[15] = pi + 6;
  55360. ps[8] = pi + 2;
  55361. /* values for 5, 6, 9, 10 are */
  55362. ps[11] = pi + 7;
  55363. ps[4] = pi + 1;
  55364. /* calculated below */
  55365. ps[7] = pi + 8;
  55366. ps[0] = pi;
  55367. ps[1] = pi + 11;
  55368. ps[2] = pi + 10;
  55369. ps[3] = pi + 9;
  55370. cs[2] = ci + 1;
  55371. cs[3] = ci + 2;
  55372. cs[0] = ci;
  55373. cs[1] = ci + 3;
  55374. break;
  55375. case 1:
  55376. tmp1 = ps[12];
  55377. tmp2 = ps[13];
  55378. tmp3 = ps[14];
  55379. tmp4 = ps[15];
  55380. ps[12] = tmp4;
  55381. ps[13] = pi + 0;
  55382. ps[14] = pi + 1;
  55383. ps[15] = pi + 2;
  55384. ps[8] = tmp3;
  55385. /* values for 5, 6, 9, 10 are */
  55386. ps[11] = pi + 3;
  55387. ps[4] = tmp2;
  55388. /* calculated below */
  55389. ps[7] = pi + 4;
  55390. ps[0] = tmp1;
  55391. ps[1] = pi + 7;
  55392. ps[2] = pi + 6;
  55393. ps[3] = pi + 5;
  55394. tmp1 = cs[2];
  55395. tmp2 = cs[3];
  55396. cs[2] = tmp2;
  55397. cs[3] = ci;
  55398. cs[0] = tmp1;
  55399. cs[1] = ci + 1;
  55400. break;
  55401. case 2:
  55402. tmp1 = ps[15];
  55403. tmp2 = ps[11];
  55404. ps[12] = ps[3];
  55405. ps[13] = pi + 0;
  55406. ps[14] = pi + 1;
  55407. ps[15] = pi + 2;
  55408. ps[8] = ps[7];
  55409. /* values for 5, 6, 9, 10 are */
  55410. ps[11] = pi + 3;
  55411. ps[4] = tmp2;
  55412. /* calculated below */
  55413. ps[7] = pi + 4;
  55414. ps[0] = tmp1;
  55415. ps[1] = pi + 7;
  55416. ps[2] = pi + 6;
  55417. ps[3] = pi + 5;
  55418. tmp1 = cs[3];
  55419. cs[2] = cs[1];
  55420. cs[3] = ci;
  55421. cs[0] = tmp1;
  55422. cs[1] = ci + 1;
  55423. break;
  55424. case 3:
  55425. ps[12] = ps[0];
  55426. ps[13] = pi + 0;
  55427. ps[14] = pi + 1;
  55428. ps[15] = pi + 2;
  55429. ps[8] = ps[1];
  55430. /* values for 5, 6, 9, 10 are */
  55431. ps[11] = pi + 3;
  55432. ps[4] = ps[2];
  55433. /* calculated below */
  55434. ps[7] = pi + 4;
  55435. ps[0] = ps[3];
  55436. ps[1] = pi + 7;
  55437. ps[2] = pi + 6;
  55438. ps[3] = pi + 5;
  55439. cs[2] = cs[0];
  55440. cs[3] = ci;
  55441. cs[0] = cs[1];
  55442. cs[1] = ci + 1;
  55443. break;
  55444. }
  55445. // set p11, p12, p21, p22
  55446. ps[5] = coords.length;
  55447. coords.push([
  55448. (-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,
  55449. (-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
  55450. ]);
  55451. ps[6] = coords.length;
  55452. coords.push([
  55453. (-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,
  55454. (-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
  55455. ]);
  55456. ps[9] = coords.length;
  55457. coords.push([
  55458. (-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,
  55459. (-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
  55460. ]);
  55461. ps[10] = coords.length;
  55462. coords.push([
  55463. (-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,
  55464. (-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
  55465. ]);
  55466. mesh.figures.push({
  55467. type: 'patch',
  55468. coords: new Int32Array(ps),
  55469. // making copies of ps and cs
  55470. colors: new Int32Array(cs)
  55471. });
  55472. }
  55473. }
  55474. function decodeType7Shading(mesh, reader) {
  55475. var coords = mesh.coords;
  55476. var colors = mesh.colors;
  55477. var ps = new Int32Array(16);
  55478. // p00, p10, ..., p30, p01, ..., p33
  55479. var cs = new Int32Array(4);
  55480. // c00, c30, c03, c33
  55481. while (reader.hasData) {
  55482. var f = reader.readFlag();
  55483. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  55484. var i, ii;
  55485. var pi = coords.length;
  55486. for (i = 0, ii = f !== 0 ? 12 : 16; i < ii; i++) {
  55487. coords.push(reader.readCoordinate());
  55488. }
  55489. var ci = colors.length;
  55490. for (i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
  55491. colors.push(reader.readComponents());
  55492. }
  55493. var tmp1, tmp2, tmp3, tmp4;
  55494. switch (f) {
  55495. case 0:
  55496. ps[12] = pi + 3;
  55497. ps[13] = pi + 4;
  55498. ps[14] = pi + 5;
  55499. ps[15] = pi + 6;
  55500. ps[8] = pi + 2;
  55501. ps[9] = pi + 13;
  55502. ps[10] = pi + 14;
  55503. ps[11] = pi + 7;
  55504. ps[4] = pi + 1;
  55505. ps[5] = pi + 12;
  55506. ps[6] = pi + 15;
  55507. ps[7] = pi + 8;
  55508. ps[0] = pi;
  55509. ps[1] = pi + 11;
  55510. ps[2] = pi + 10;
  55511. ps[3] = pi + 9;
  55512. cs[2] = ci + 1;
  55513. cs[3] = ci + 2;
  55514. cs[0] = ci;
  55515. cs[1] = ci + 3;
  55516. break;
  55517. case 1:
  55518. tmp1 = ps[12];
  55519. tmp2 = ps[13];
  55520. tmp3 = ps[14];
  55521. tmp4 = ps[15];
  55522. ps[12] = tmp4;
  55523. ps[13] = pi + 0;
  55524. ps[14] = pi + 1;
  55525. ps[15] = pi + 2;
  55526. ps[8] = tmp3;
  55527. ps[9] = pi + 9;
  55528. ps[10] = pi + 10;
  55529. ps[11] = pi + 3;
  55530. ps[4] = tmp2;
  55531. ps[5] = pi + 8;
  55532. ps[6] = pi + 11;
  55533. ps[7] = pi + 4;
  55534. ps[0] = tmp1;
  55535. ps[1] = pi + 7;
  55536. ps[2] = pi + 6;
  55537. ps[3] = pi + 5;
  55538. tmp1 = cs[2];
  55539. tmp2 = cs[3];
  55540. cs[2] = tmp2;
  55541. cs[3] = ci;
  55542. cs[0] = tmp1;
  55543. cs[1] = ci + 1;
  55544. break;
  55545. case 2:
  55546. tmp1 = ps[15];
  55547. tmp2 = ps[11];
  55548. ps[12] = ps[3];
  55549. ps[13] = pi + 0;
  55550. ps[14] = pi + 1;
  55551. ps[15] = pi + 2;
  55552. ps[8] = ps[7];
  55553. ps[9] = pi + 9;
  55554. ps[10] = pi + 10;
  55555. ps[11] = pi + 3;
  55556. ps[4] = tmp2;
  55557. ps[5] = pi + 8;
  55558. ps[6] = pi + 11;
  55559. ps[7] = pi + 4;
  55560. ps[0] = tmp1;
  55561. ps[1] = pi + 7;
  55562. ps[2] = pi + 6;
  55563. ps[3] = pi + 5;
  55564. tmp1 = cs[3];
  55565. cs[2] = cs[1];
  55566. cs[3] = ci;
  55567. cs[0] = tmp1;
  55568. cs[1] = ci + 1;
  55569. break;
  55570. case 3:
  55571. ps[12] = ps[0];
  55572. ps[13] = pi + 0;
  55573. ps[14] = pi + 1;
  55574. ps[15] = pi + 2;
  55575. ps[8] = ps[1];
  55576. ps[9] = pi + 9;
  55577. ps[10] = pi + 10;
  55578. ps[11] = pi + 3;
  55579. ps[4] = ps[2];
  55580. ps[5] = pi + 8;
  55581. ps[6] = pi + 11;
  55582. ps[7] = pi + 4;
  55583. ps[0] = ps[3];
  55584. ps[1] = pi + 7;
  55585. ps[2] = pi + 6;
  55586. ps[3] = pi + 5;
  55587. cs[2] = cs[0];
  55588. cs[3] = ci;
  55589. cs[0] = cs[1];
  55590. cs[1] = ci + 1;
  55591. break;
  55592. }
  55593. mesh.figures.push({
  55594. type: 'patch',
  55595. coords: new Int32Array(ps),
  55596. // making copies of ps and cs
  55597. colors: new Int32Array(cs)
  55598. });
  55599. }
  55600. }
  55601. function updateBounds(mesh) {
  55602. var minX = mesh.coords[0][0], minY = mesh.coords[0][1], maxX = minX, maxY = minY;
  55603. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  55604. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  55605. minX = minX > x ? x : minX;
  55606. minY = minY > y ? y : minY;
  55607. maxX = maxX < x ? x : maxX;
  55608. maxY = maxY < y ? y : maxY;
  55609. }
  55610. mesh.bounds = [
  55611. minX,
  55612. minY,
  55613. maxX,
  55614. maxY
  55615. ];
  55616. }
  55617. function packData(mesh) {
  55618. var i, ii, j, jj;
  55619. var coords = mesh.coords;
  55620. var coordsPacked = new Float32Array(coords.length * 2);
  55621. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  55622. var xy = coords[i];
  55623. coordsPacked[j++] = xy[0];
  55624. coordsPacked[j++] = xy[1];
  55625. }
  55626. mesh.coords = coordsPacked;
  55627. var colors = mesh.colors;
  55628. var colorsPacked = new Uint8Array(colors.length * 3);
  55629. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  55630. var c = colors[i];
  55631. colorsPacked[j++] = c[0];
  55632. colorsPacked[j++] = c[1];
  55633. colorsPacked[j++] = c[2];
  55634. }
  55635. mesh.colors = colorsPacked;
  55636. var figures = mesh.figures;
  55637. for (i = 0, ii = figures.length; i < ii; i++) {
  55638. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  55639. for (j = 0, jj = ps.length; j < jj; j++) {
  55640. ps[j] *= 2;
  55641. cs[j] *= 3;
  55642. }
  55643. }
  55644. }
  55645. function Mesh(stream, matrix, xref, res) {
  55646. assert(isStream(stream), 'Mesh data is not a stream');
  55647. var dict = stream.dict;
  55648. this.matrix = matrix;
  55649. this.shadingType = dict.get('ShadingType');
  55650. this.type = 'Pattern';
  55651. this.bbox = dict.getArray('BBox');
  55652. var cs = dict.get('ColorSpace', 'CS');
  55653. cs = ColorSpace.parse(cs, xref, res);
  55654. this.cs = cs;
  55655. this.background = dict.has('Background') ? cs.getRgb(dict.get('Background'), 0) : null;
  55656. var fnObj = dict.get('Function');
  55657. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  55658. this.coords = [];
  55659. this.colors = [];
  55660. this.figures = [];
  55661. var decodeContext = {
  55662. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  55663. bitsPerComponent: dict.get('BitsPerComponent'),
  55664. bitsPerFlag: dict.get('BitsPerFlag'),
  55665. decode: dict.getArray('Decode'),
  55666. colorFn: fn,
  55667. colorSpace: cs,
  55668. numComps: fn ? 1 : cs.numComps
  55669. };
  55670. var reader = new MeshStreamReader(stream, decodeContext);
  55671. var patchMesh = false;
  55672. switch (this.shadingType) {
  55673. case ShadingType.FREE_FORM_MESH:
  55674. decodeType4Shading(this, reader);
  55675. break;
  55676. case ShadingType.LATTICE_FORM_MESH:
  55677. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  55678. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  55679. decodeType5Shading(this, reader, verticesPerRow);
  55680. break;
  55681. case ShadingType.COONS_PATCH_MESH:
  55682. decodeType6Shading(this, reader);
  55683. patchMesh = true;
  55684. break;
  55685. case ShadingType.TENSOR_PATCH_MESH:
  55686. decodeType7Shading(this, reader);
  55687. patchMesh = true;
  55688. break;
  55689. default:
  55690. error('Unsupported mesh type.');
  55691. break;
  55692. }
  55693. if (patchMesh) {
  55694. // dirty bounds calculation for determining, how dense shall be triangles
  55695. updateBounds(this);
  55696. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  55697. buildFigureFromPatch(this, i);
  55698. }
  55699. }
  55700. // calculate bounds
  55701. updateBounds(this);
  55702. packData(this);
  55703. }
  55704. Mesh.prototype = {
  55705. getIR: function Mesh_getIR() {
  55706. return [
  55707. 'Mesh',
  55708. this.shadingType,
  55709. this.coords,
  55710. this.colors,
  55711. this.figures,
  55712. this.bounds,
  55713. this.matrix,
  55714. this.bbox,
  55715. this.background
  55716. ];
  55717. }
  55718. };
  55719. return Mesh;
  55720. }();
  55721. Shadings.Dummy = function DummyClosure() {
  55722. function Dummy() {
  55723. this.type = 'Pattern';
  55724. }
  55725. Dummy.prototype = {
  55726. getIR: function Dummy_getIR() {
  55727. return ['Dummy'];
  55728. }
  55729. };
  55730. return Dummy;
  55731. }();
  55732. function getTilingPatternIR(operatorList, dict, args) {
  55733. var matrix = dict.getArray('Matrix');
  55734. var bbox = dict.getArray('BBox');
  55735. var xstep = dict.get('XStep');
  55736. var ystep = dict.get('YStep');
  55737. var paintType = dict.get('PaintType');
  55738. var tilingType = dict.get('TilingType');
  55739. return [
  55740. 'TilingPattern',
  55741. args,
  55742. operatorList,
  55743. matrix,
  55744. bbox,
  55745. xstep,
  55746. ystep,
  55747. paintType,
  55748. tilingType
  55749. ];
  55750. }
  55751. exports.Pattern = Pattern;
  55752. exports.getTilingPatternIR = getTilingPatternIR;
  55753. }));
  55754. (function (root, factory) {
  55755. 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);
  55756. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser, coreImage, coreColorSpace, coreMurmurHash3, coreFonts, coreFunction, corePattern, coreCMap, coreMetrics, coreBidi, coreEncodings, coreStandardFonts, coreUnicode, coreGlyphList) {
  55757. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  55758. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  55759. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  55760. var ImageKind = sharedUtil.ImageKind;
  55761. var OPS = sharedUtil.OPS;
  55762. var TextRenderingMode = sharedUtil.TextRenderingMode;
  55763. var Util = sharedUtil.Util;
  55764. var assert = sharedUtil.assert;
  55765. var createPromiseCapability = sharedUtil.createPromiseCapability;
  55766. var error = sharedUtil.error;
  55767. var info = sharedUtil.info;
  55768. var isArray = sharedUtil.isArray;
  55769. var isNum = sharedUtil.isNum;
  55770. var isString = sharedUtil.isString;
  55771. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  55772. var warn = sharedUtil.warn;
  55773. var Dict = corePrimitives.Dict;
  55774. var Name = corePrimitives.Name;
  55775. var isCmd = corePrimitives.isCmd;
  55776. var isDict = corePrimitives.isDict;
  55777. var isName = corePrimitives.isName;
  55778. var isRef = corePrimitives.isRef;
  55779. var isStream = corePrimitives.isStream;
  55780. var DecodeStream = coreStream.DecodeStream;
  55781. var JpegStream = coreStream.JpegStream;
  55782. var Stream = coreStream.Stream;
  55783. var Lexer = coreParser.Lexer;
  55784. var Parser = coreParser.Parser;
  55785. var isEOF = coreParser.isEOF;
  55786. var PDFImage = coreImage.PDFImage;
  55787. var ColorSpace = coreColorSpace.ColorSpace;
  55788. var MurmurHash3_64 = coreMurmurHash3.MurmurHash3_64;
  55789. var ErrorFont = coreFonts.ErrorFont;
  55790. var FontFlags = coreFonts.FontFlags;
  55791. var Font = coreFonts.Font;
  55792. var IdentityToUnicodeMap = coreFonts.IdentityToUnicodeMap;
  55793. var ToUnicodeMap = coreFonts.ToUnicodeMap;
  55794. var getFontType = coreFonts.getFontType;
  55795. var isPDFFunction = coreFunction.isPDFFunction;
  55796. var PDFFunction = coreFunction.PDFFunction;
  55797. var Pattern = corePattern.Pattern;
  55798. var getTilingPatternIR = corePattern.getTilingPatternIR;
  55799. var CMapFactory = coreCMap.CMapFactory;
  55800. var IdentityCMap = coreCMap.IdentityCMap;
  55801. var getMetrics = coreMetrics.getMetrics;
  55802. var bidi = coreBidi.bidi;
  55803. var WinAnsiEncoding = coreEncodings.WinAnsiEncoding;
  55804. var StandardEncoding = coreEncodings.StandardEncoding;
  55805. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  55806. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  55807. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  55808. var getEncoding = coreEncodings.getEncoding;
  55809. var getStdFontMap = coreStandardFonts.getStdFontMap;
  55810. var getSerifFonts = coreStandardFonts.getSerifFonts;
  55811. var getSymbolsFonts = coreStandardFonts.getSymbolsFonts;
  55812. var getNormalizedUnicodes = coreUnicode.getNormalizedUnicodes;
  55813. var reverseIfRtl = coreUnicode.reverseIfRtl;
  55814. var getUnicodeForGlyph = coreUnicode.getUnicodeForGlyph;
  55815. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  55816. var PartialEvaluator = function PartialEvaluatorClosure() {
  55817. var DefaultPartialEvaluatorOptions = {
  55818. forceDataSchema: false,
  55819. maxImageSize: -1,
  55820. disableFontFace: false,
  55821. cMapOptions: {
  55822. url: null,
  55823. packed: false
  55824. }
  55825. };
  55826. function NativeImageDecoder(xref, resources, handler, forceDataSchema) {
  55827. this.xref = xref;
  55828. this.resources = resources;
  55829. this.handler = handler;
  55830. this.forceDataSchema = forceDataSchema;
  55831. }
  55832. NativeImageDecoder.prototype = {
  55833. canDecode: function (image) {
  55834. return image instanceof JpegStream && NativeImageDecoder.isDecodable(image, this.xref, this.resources);
  55835. },
  55836. decode: function (image) {
  55837. // For natively supported JPEGs send them to the main thread for decoding.
  55838. var dict = image.dict;
  55839. var colorSpace = dict.get('ColorSpace', 'CS');
  55840. colorSpace = ColorSpace.parse(colorSpace, this.xref, this.resources);
  55841. var numComps = colorSpace.numComps;
  55842. var decodePromise = this.handler.sendWithPromise('JpegDecode', [
  55843. image.getIR(this.forceDataSchema),
  55844. numComps
  55845. ]);
  55846. return decodePromise.then(function (message) {
  55847. var data = message.data;
  55848. return new Stream(data, 0, data.length, image.dict);
  55849. });
  55850. }
  55851. };
  55852. /**
  55853. * Checks if the image can be decoded and displayed by the browser without any
  55854. * further processing such as color space conversions.
  55855. */
  55856. NativeImageDecoder.isSupported = function NativeImageDecoder_isSupported(image, xref, res) {
  55857. var dict = image.dict;
  55858. if (dict.has('DecodeParms') || dict.has('DP')) {
  55859. return false;
  55860. }
  55861. var cs = ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res);
  55862. return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') && cs.isDefaultDecode(dict.getArray('Decode', 'D'));
  55863. };
  55864. /**
  55865. * Checks if the image can be decoded by the browser.
  55866. */
  55867. NativeImageDecoder.isDecodable = function NativeImageDecoder_isDecodable(image, xref, res) {
  55868. var dict = image.dict;
  55869. if (dict.has('DecodeParms') || dict.has('DP')) {
  55870. return false;
  55871. }
  55872. var cs = ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res);
  55873. return (cs.numComps === 1 || cs.numComps === 3) && cs.isDefaultDecode(dict.getArray('Decode', 'D'));
  55874. };
  55875. function PartialEvaluator(pdfManager, xref, handler, pageIndex, uniquePrefix, idCounters, fontCache, options) {
  55876. this.pdfManager = pdfManager;
  55877. this.xref = xref;
  55878. this.handler = handler;
  55879. this.pageIndex = pageIndex;
  55880. this.uniquePrefix = uniquePrefix;
  55881. this.idCounters = idCounters;
  55882. this.fontCache = fontCache;
  55883. this.options = options || DefaultPartialEvaluatorOptions;
  55884. }
  55885. // Trying to minimize Date.now() usage and check every 100 time
  55886. var TIME_SLOT_DURATION_MS = 20;
  55887. var CHECK_TIME_EVERY = 100;
  55888. function TimeSlotManager() {
  55889. this.reset();
  55890. }
  55891. TimeSlotManager.prototype = {
  55892. check: function TimeSlotManager_check() {
  55893. if (++this.checked < CHECK_TIME_EVERY) {
  55894. return false;
  55895. }
  55896. this.checked = 0;
  55897. return this.endTime <= Date.now();
  55898. },
  55899. reset: function TimeSlotManager_reset() {
  55900. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  55901. this.checked = 0;
  55902. }
  55903. };
  55904. var deferred = Promise.resolve();
  55905. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  55906. PartialEvaluator.prototype = {
  55907. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  55908. if (!isDict(resources)) {
  55909. return false;
  55910. }
  55911. var processed = Object.create(null);
  55912. if (resources.objId) {
  55913. processed[resources.objId] = true;
  55914. }
  55915. var nodes = [resources], xref = this.xref;
  55916. while (nodes.length) {
  55917. var key, i, ii;
  55918. var node = nodes.shift();
  55919. // First check the current resources for blend modes.
  55920. var graphicStates = node.get('ExtGState');
  55921. if (isDict(graphicStates)) {
  55922. var graphicStatesKeys = graphicStates.getKeys();
  55923. for (i = 0, ii = graphicStatesKeys.length; i < ii; i++) {
  55924. key = graphicStatesKeys[i];
  55925. var graphicState = graphicStates.get(key);
  55926. var bm = graphicState.get('BM');
  55927. if (isName(bm) && bm.name !== 'Normal') {
  55928. return true;
  55929. }
  55930. }
  55931. }
  55932. // Descend into the XObjects to look for more resources and blend modes.
  55933. var xObjects = node.get('XObject');
  55934. if (!isDict(xObjects)) {
  55935. continue;
  55936. }
  55937. var xObjectsKeys = xObjects.getKeys();
  55938. for (i = 0, ii = xObjectsKeys.length; i < ii; i++) {
  55939. key = xObjectsKeys[i];
  55940. var xObject = xObjects.getRaw(key);
  55941. if (isRef(xObject)) {
  55942. if (processed[xObject.toString()]) {
  55943. // The XObject has already been processed, and by avoiding a
  55944. // redundant `xref.fetch` we can *significantly* reduce the load
  55945. // time for badly generated PDF files (fixes issue6961.pdf).
  55946. continue;
  55947. }
  55948. xObject = xref.fetch(xObject);
  55949. }
  55950. if (!isStream(xObject)) {
  55951. continue;
  55952. }
  55953. if (xObject.dict.objId) {
  55954. if (processed[xObject.dict.objId]) {
  55955. // stream has objId and is processed already
  55956. continue;
  55957. }
  55958. processed[xObject.dict.objId] = true;
  55959. }
  55960. var xResources = xObject.dict.get('Resources');
  55961. // Checking objId to detect an infinite loop.
  55962. if (isDict(xResources) && (!xResources.objId || !processed[xResources.objId])) {
  55963. nodes.push(xResources);
  55964. if (xResources.objId) {
  55965. processed[xResources.objId] = true;
  55966. }
  55967. }
  55968. }
  55969. }
  55970. return false;
  55971. },
  55972. buildFormXObject: function PartialEvaluator_buildFormXObject(resources, xobj, smask, operatorList, task, initialState) {
  55973. var matrix = xobj.dict.getArray('Matrix');
  55974. var bbox = xobj.dict.getArray('BBox');
  55975. var group = xobj.dict.get('Group');
  55976. if (group) {
  55977. var groupOptions = {
  55978. matrix: matrix,
  55979. bbox: bbox,
  55980. smask: smask,
  55981. isolated: false,
  55982. knockout: false
  55983. };
  55984. var groupSubtype = group.get('S');
  55985. var colorSpace;
  55986. if (isName(groupSubtype, 'Transparency')) {
  55987. groupOptions.isolated = group.get('I') || false;
  55988. groupOptions.knockout = group.get('K') || false;
  55989. colorSpace = group.has('CS') ? ColorSpace.parse(group.get('CS'), this.xref, resources) : null;
  55990. }
  55991. if (smask && smask.backdrop) {
  55992. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  55993. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  55994. }
  55995. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  55996. }
  55997. operatorList.addOp(OPS.paintFormXObjectBegin, [
  55998. matrix,
  55999. bbox
  56000. ]);
  56001. return this.getOperatorList(xobj, task, xobj.dict.get('Resources') || resources, operatorList, initialState).then(function () {
  56002. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  56003. if (group) {
  56004. operatorList.addOp(OPS.endGroup, [groupOptions]);
  56005. }
  56006. });
  56007. },
  56008. buildPaintImageXObject: function PartialEvaluator_buildPaintImageXObject(resources, image, inline, operatorList, cacheKey, imageCache) {
  56009. var self = this;
  56010. var dict = image.dict;
  56011. var w = dict.get('Width', 'W');
  56012. var h = dict.get('Height', 'H');
  56013. if (!(w && isNum(w)) || !(h && isNum(h))) {
  56014. warn('Image dimensions are missing, or not numbers.');
  56015. return;
  56016. }
  56017. var maxImageSize = this.options.maxImageSize;
  56018. if (maxImageSize !== -1 && w * h > maxImageSize) {
  56019. warn('Image exceeded maximum allowed size and was removed.');
  56020. return;
  56021. }
  56022. var imageMask = dict.get('ImageMask', 'IM') || false;
  56023. var imgData, args;
  56024. if (imageMask) {
  56025. // This depends on a tmpCanvas being filled with the
  56026. // current fillStyle, such that processing the pixel
  56027. // data can't be done here. Instead of creating a
  56028. // complete PDFImage, only read the information needed
  56029. // for later.
  56030. var width = dict.get('Width', 'W');
  56031. var height = dict.get('Height', 'H');
  56032. var bitStrideLength = width + 7 >> 3;
  56033. var imgArray = image.getBytes(bitStrideLength * height);
  56034. var decode = dict.getArray('Decode', 'D');
  56035. var inverseDecode = !!decode && decode[0] > 0;
  56036. imgData = PDFImage.createMask(imgArray, width, height, image instanceof DecodeStream, inverseDecode);
  56037. imgData.cached = true;
  56038. args = [imgData];
  56039. operatorList.addOp(OPS.paintImageMaskXObject, args);
  56040. if (cacheKey) {
  56041. imageCache[cacheKey] = {
  56042. fn: OPS.paintImageMaskXObject,
  56043. args: args
  56044. };
  56045. }
  56046. return;
  56047. }
  56048. var softMask = dict.get('SMask', 'SM') || false;
  56049. var mask = dict.get('Mask') || false;
  56050. var SMALL_IMAGE_DIMENSIONS = 200;
  56051. // Inlining small images into the queue as RGB data
  56052. if (inline && !softMask && !mask && !(image instanceof JpegStream) && w + h < SMALL_IMAGE_DIMENSIONS) {
  56053. var imageObj = new PDFImage(this.xref, resources, image, inline, null, null);
  56054. // We force the use of RGBA_32BPP images here, because we can't handle
  56055. // any other kind.
  56056. imgData = imageObj.createImageData(/* forceRGBA = */
  56057. true);
  56058. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  56059. return;
  56060. }
  56061. // If there is no imageMask, create the PDFImage and a lot
  56062. // of image processing can be done here.
  56063. var uniquePrefix = this.uniquePrefix || '';
  56064. var objId = 'img_' + uniquePrefix + ++this.idCounters.obj;
  56065. operatorList.addDependency(objId);
  56066. args = [
  56067. objId,
  56068. w,
  56069. h
  56070. ];
  56071. if (!softMask && !mask && image instanceof JpegStream && NativeImageDecoder.isSupported(image, this.xref, resources)) {
  56072. // These JPEGs don't need any more processing so we can just send it.
  56073. operatorList.addOp(OPS.paintJpegXObject, args);
  56074. this.handler.send('obj', [
  56075. objId,
  56076. this.pageIndex,
  56077. 'JpegStream',
  56078. image.getIR(this.options.forceDataSchema)
  56079. ]);
  56080. return;
  56081. }
  56082. // Creates native image decoder only if a JPEG image or mask is present.
  56083. var nativeImageDecoder = null;
  56084. if (image instanceof JpegStream || mask instanceof JpegStream || softMask instanceof JpegStream) {
  56085. nativeImageDecoder = new NativeImageDecoder(self.xref, resources, self.handler, self.options.forceDataSchema);
  56086. }
  56087. PDFImage.buildImage(self.handler, self.xref, resources, image, inline, nativeImageDecoder).then(function (imageObj) {
  56088. var imgData = imageObj.createImageData(/* forceRGBA = */
  56089. false);
  56090. self.handler.send('obj', [
  56091. objId,
  56092. self.pageIndex,
  56093. 'Image',
  56094. imgData
  56095. ], [imgData.data.buffer]);
  56096. }).then(undefined, function (reason) {
  56097. warn('Unable to decode image: ' + reason);
  56098. self.handler.send('obj', [
  56099. objId,
  56100. self.pageIndex,
  56101. 'Image',
  56102. null
  56103. ]);
  56104. });
  56105. operatorList.addOp(OPS.paintImageXObject, args);
  56106. if (cacheKey) {
  56107. imageCache[cacheKey] = {
  56108. fn: OPS.paintImageXObject,
  56109. args: args
  56110. };
  56111. }
  56112. },
  56113. handleSMask: function PartialEvaluator_handleSmask(smask, resources, operatorList, task, stateManager) {
  56114. var smaskContent = smask.get('G');
  56115. var smaskOptions = {
  56116. subtype: smask.get('S').name,
  56117. backdrop: smask.get('BC')
  56118. };
  56119. // The SMask might have a alpha/luminosity value transfer function --
  56120. // we will build a map of integer values in range 0..255 to be fast.
  56121. var transferObj = smask.get('TR');
  56122. if (isPDFFunction(transferObj)) {
  56123. var transferFn = PDFFunction.parse(this.xref, transferObj);
  56124. var transferMap = new Uint8Array(256);
  56125. var tmp = new Float32Array(1);
  56126. for (var i = 0; i < 256; i++) {
  56127. tmp[0] = i / 255;
  56128. transferFn(tmp, 0, tmp, 0);
  56129. transferMap[i] = tmp[0] * 255 | 0;
  56130. }
  56131. smaskOptions.transferMap = transferMap;
  56132. }
  56133. return this.buildFormXObject(resources, smaskContent, smaskOptions, operatorList, task, stateManager.state.clone());
  56134. },
  56135. handleTilingType: function PartialEvaluator_handleTilingType(fn, args, resources, pattern, patternDict, operatorList, task) {
  56136. // Create an IR of the pattern code.
  56137. var tilingOpList = new OperatorList();
  56138. // Merge the available resources, to prevent issues when the patternDict
  56139. // is missing some /Resources entries (fixes issue6541.pdf).
  56140. var resourcesArray = [
  56141. patternDict.get('Resources'),
  56142. resources
  56143. ];
  56144. var patternResources = Dict.merge(this.xref, resourcesArray);
  56145. return this.getOperatorList(pattern, task, patternResources, tilingOpList).then(function () {
  56146. // Add the dependencies to the parent operator list so they are
  56147. // resolved before sub operator list is executed synchronously.
  56148. operatorList.addDependencies(tilingOpList.dependencies);
  56149. operatorList.addOp(fn, getTilingPatternIR({
  56150. fnArray: tilingOpList.fnArray,
  56151. argsArray: tilingOpList.argsArray
  56152. }, patternDict, args));
  56153. });
  56154. },
  56155. handleSetFont: function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef, operatorList, task, state) {
  56156. // TODO(mack): Not needed?
  56157. var fontName;
  56158. if (fontArgs) {
  56159. fontArgs = fontArgs.slice();
  56160. fontName = fontArgs[0].name;
  56161. }
  56162. var self = this;
  56163. return this.loadFont(fontName, fontRef, this.xref, resources).then(function (translated) {
  56164. if (!translated.font.isType3Font) {
  56165. return translated;
  56166. }
  56167. return translated.loadType3Data(self, resources, operatorList, task).then(function () {
  56168. return translated;
  56169. }, function (reason) {
  56170. // Error in the font data -- sending unsupported feature notification.
  56171. self.handler.send('UnsupportedFeature', { featureId: UNSUPPORTED_FEATURES.font });
  56172. return new TranslatedFont('g_font_error', new ErrorFont('Type3 font load error: ' + reason), translated.font);
  56173. });
  56174. }).then(function (translated) {
  56175. state.font = translated.font;
  56176. translated.send(self.handler);
  56177. return translated.loadedName;
  56178. });
  56179. },
  56180. handleText: function PartialEvaluator_handleText(chars, state) {
  56181. var font = state.font;
  56182. var glyphs = font.charsToGlyphs(chars);
  56183. var isAddToPathSet = !!(state.textRenderingMode & TextRenderingMode.ADD_TO_PATH_FLAG);
  56184. if (font.data && (isAddToPathSet || this.options.disableFontFace)) {
  56185. var buildPath = function (fontChar) {
  56186. if (!font.renderer.hasBuiltPath(fontChar)) {
  56187. var path = font.renderer.getPathJs(fontChar);
  56188. this.handler.send('commonobj', [
  56189. font.loadedName + '_path_' + fontChar,
  56190. 'FontPath',
  56191. path
  56192. ]);
  56193. }
  56194. }.bind(this);
  56195. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  56196. var glyph = glyphs[i];
  56197. buildPath(glyph.fontChar);
  56198. // If the glyph has an accent we need to build a path for its
  56199. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  56200. var accent = glyph.accent;
  56201. if (accent && accent.fontChar) {
  56202. buildPath(accent.fontChar);
  56203. }
  56204. }
  56205. }
  56206. return glyphs;
  56207. },
  56208. setGState: function PartialEvaluator_setGState(resources, gState, operatorList, task, xref, stateManager) {
  56209. // This array holds the converted/processed state data.
  56210. var gStateObj = [];
  56211. var gStateKeys = gState.getKeys();
  56212. var self = this;
  56213. var promise = Promise.resolve();
  56214. for (var i = 0, ii = gStateKeys.length; i < ii; i++) {
  56215. var key = gStateKeys[i];
  56216. var value = gState.get(key);
  56217. switch (key) {
  56218. case 'Type':
  56219. break;
  56220. case 'LW':
  56221. case 'LC':
  56222. case 'LJ':
  56223. case 'ML':
  56224. case 'D':
  56225. case 'RI':
  56226. case 'FL':
  56227. case 'CA':
  56228. case 'ca':
  56229. gStateObj.push([
  56230. key,
  56231. value
  56232. ]);
  56233. break;
  56234. case 'Font':
  56235. promise = promise.then(function () {
  56236. return self.handleSetFont(resources, null, value[0], operatorList, task, stateManager.state).then(function (loadedName) {
  56237. operatorList.addDependency(loadedName);
  56238. gStateObj.push([
  56239. key,
  56240. [
  56241. loadedName,
  56242. value[1]
  56243. ]
  56244. ]);
  56245. });
  56246. });
  56247. break;
  56248. case 'BM':
  56249. gStateObj.push([
  56250. key,
  56251. value
  56252. ]);
  56253. break;
  56254. case 'SMask':
  56255. if (isName(value, 'None')) {
  56256. gStateObj.push([
  56257. key,
  56258. false
  56259. ]);
  56260. break;
  56261. }
  56262. if (isDict(value)) {
  56263. promise = promise.then(function (dict) {
  56264. return self.handleSMask(dict, resources, operatorList, task, stateManager);
  56265. }.bind(this, value));
  56266. gStateObj.push([
  56267. key,
  56268. true
  56269. ]);
  56270. } else {
  56271. warn('Unsupported SMask type');
  56272. }
  56273. break;
  56274. // Only generate info log messages for the following since
  56275. // they are unlikely to have a big impact on the rendering.
  56276. case 'OP':
  56277. case 'op':
  56278. case 'OPM':
  56279. case 'BG':
  56280. case 'BG2':
  56281. case 'UCR':
  56282. case 'UCR2':
  56283. case 'TR':
  56284. case 'TR2':
  56285. case 'HT':
  56286. case 'SM':
  56287. case 'SA':
  56288. case 'AIS':
  56289. case 'TK':
  56290. // TODO implement these operators.
  56291. info('graphic state operator ' + key);
  56292. break;
  56293. default:
  56294. info('Unknown graphic state operator ' + key);
  56295. break;
  56296. }
  56297. }
  56298. return promise.then(function () {
  56299. if (gStateObj.length > 0) {
  56300. operatorList.addOp(OPS.setGState, [gStateObj]);
  56301. }
  56302. });
  56303. },
  56304. loadFont: function PartialEvaluator_loadFont(fontName, font, xref, resources) {
  56305. function errorFont() {
  56306. return Promise.resolve(new TranslatedFont('g_font_error', new ErrorFont('Font ' + fontName + ' is not available'), font));
  56307. }
  56308. var fontRef;
  56309. if (font) {
  56310. // Loading by ref.
  56311. assert(isRef(font));
  56312. fontRef = font;
  56313. } else {
  56314. // Loading by name.
  56315. var fontRes = resources.get('Font');
  56316. if (fontRes) {
  56317. fontRef = fontRes.getRaw(fontName);
  56318. } else {
  56319. warn('fontRes not available');
  56320. return errorFont();
  56321. }
  56322. }
  56323. if (!fontRef) {
  56324. warn('fontRef not available');
  56325. return errorFont();
  56326. }
  56327. if (this.fontCache.has(fontRef)) {
  56328. return this.fontCache.get(fontRef);
  56329. }
  56330. font = xref.fetchIfRef(fontRef);
  56331. if (!isDict(font)) {
  56332. return errorFont();
  56333. }
  56334. // We are holding `font.translated` references just for `fontRef`s that
  56335. // are not actually `Ref`s, but rather `Dict`s. See explanation below.
  56336. if (font.translated) {
  56337. return font.translated;
  56338. }
  56339. var fontCapability = createPromiseCapability();
  56340. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  56341. var descriptor = preEvaluatedFont.descriptor;
  56342. var fontRefIsRef = isRef(fontRef), fontID;
  56343. if (fontRefIsRef) {
  56344. fontID = fontRef.toString();
  56345. }
  56346. if (isDict(descriptor)) {
  56347. if (!descriptor.fontAliases) {
  56348. descriptor.fontAliases = Object.create(null);
  56349. }
  56350. var fontAliases = descriptor.fontAliases;
  56351. var hash = preEvaluatedFont.hash;
  56352. if (fontAliases[hash]) {
  56353. var aliasFontRef = fontAliases[hash].aliasRef;
  56354. if (fontRefIsRef && aliasFontRef && this.fontCache.has(aliasFontRef)) {
  56355. this.fontCache.putAlias(fontRef, aliasFontRef);
  56356. return this.fontCache.get(fontRef);
  56357. }
  56358. } else {
  56359. fontAliases[hash] = { fontID: Font.getFontID() };
  56360. }
  56361. if (fontRefIsRef) {
  56362. fontAliases[hash].aliasRef = fontRef;
  56363. }
  56364. fontID = fontAliases[hash].fontID;
  56365. }
  56366. // Workaround for bad PDF generators that reference fonts incorrectly,
  56367. // where `fontRef` is a `Dict` rather than a `Ref` (fixes bug946506.pdf).
  56368. // In this case we should not put the font into `this.fontCache` (which is
  56369. // a `RefSetCache`), since it's not meaningful to use a `Dict` as a key.
  56370. //
  56371. // However, if we don't cache the font it's not possible to remove it
  56372. // when `cleanup` is triggered from the API, which causes issues on
  56373. // subsequent rendering operations (see issue7403.pdf).
  56374. // A simple workaround would be to just not hold `font.translated`
  56375. // references in this case, but this would force us to unnecessarily load
  56376. // the same fonts over and over.
  56377. //
  56378. // Instead, we cheat a bit by attempting to use a modified `fontID` as a
  56379. // key in `this.fontCache`, to allow the font to be cached.
  56380. // NOTE: This works because `RefSetCache` calls `toString()` on provided
  56381. // keys. Also, since `fontRef` is used when getting cached fonts,
  56382. // we'll not accidentally match fonts cached with the `fontID`.
  56383. if (fontRefIsRef) {
  56384. this.fontCache.put(fontRef, fontCapability.promise);
  56385. } else {
  56386. if (!fontID) {
  56387. fontID = (this.uniquePrefix || 'F_') + ++this.idCounters.obj;
  56388. }
  56389. this.fontCache.put('id_' + fontID, fontCapability.promise);
  56390. }
  56391. assert(fontID, 'The "fontID" must be defined.');
  56392. // Keep track of each font we translated so the caller can
  56393. // load them asynchronously before calling display on a page.
  56394. font.loadedName = 'g_' + this.pdfManager.docId + '_f' + fontID;
  56395. font.translated = fontCapability.promise;
  56396. // TODO move promises into translate font
  56397. var translatedPromise;
  56398. try {
  56399. translatedPromise = this.translateFont(preEvaluatedFont, xref);
  56400. } catch (e) {
  56401. translatedPromise = Promise.reject(e);
  56402. }
  56403. var self = this;
  56404. translatedPromise.then(function (translatedFont) {
  56405. if (translatedFont.fontType !== undefined) {
  56406. var xrefFontStats = xref.stats.fontTypes;
  56407. xrefFontStats[translatedFont.fontType] = true;
  56408. }
  56409. fontCapability.resolve(new TranslatedFont(font.loadedName, translatedFont, font));
  56410. }, function (reason) {
  56411. // TODO fontCapability.reject?
  56412. // Error in the font data -- sending unsupported feature notification.
  56413. self.handler.send('UnsupportedFeature', { featureId: UNSUPPORTED_FEATURES.font });
  56414. try {
  56415. // error, but it's still nice to have font type reported
  56416. var descriptor = preEvaluatedFont.descriptor;
  56417. var fontFile3 = descriptor && descriptor.get('FontFile3');
  56418. var subtype = fontFile3 && fontFile3.get('Subtype');
  56419. var fontType = getFontType(preEvaluatedFont.type, subtype && subtype.name);
  56420. var xrefFontStats = xref.stats.fontTypes;
  56421. xrefFontStats[fontType] = true;
  56422. } catch (ex) {
  56423. }
  56424. fontCapability.resolve(new TranslatedFont(font.loadedName, new ErrorFont(reason instanceof Error ? reason.message : reason), font));
  56425. });
  56426. return fontCapability.promise;
  56427. },
  56428. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  56429. var lastIndex = operatorList.length - 1;
  56430. if (!args) {
  56431. args = [];
  56432. }
  56433. if (lastIndex < 0 || operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  56434. operatorList.addOp(OPS.constructPath, [
  56435. [fn],
  56436. args
  56437. ]);
  56438. } else {
  56439. var opArgs = operatorList.argsArray[lastIndex];
  56440. opArgs[0].push(fn);
  56441. Array.prototype.push.apply(opArgs[1], args);
  56442. }
  56443. },
  56444. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args, cs, patterns, resources, task, xref) {
  56445. // compile tiling patterns
  56446. var patternName = args[args.length - 1];
  56447. // SCN/scn applies patterns along with normal colors
  56448. var pattern;
  56449. if (isName(patternName) && (pattern = patterns.get(patternName.name))) {
  56450. var dict = isStream(pattern) ? pattern.dict : pattern;
  56451. var typeNum = dict.get('PatternType');
  56452. if (typeNum === TILING_PATTERN) {
  56453. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  56454. return this.handleTilingType(fn, color, resources, pattern, dict, operatorList, task);
  56455. } else if (typeNum === SHADING_PATTERN) {
  56456. var shading = dict.get('Shading');
  56457. var matrix = dict.getArray('Matrix');
  56458. pattern = Pattern.parseShading(shading, matrix, xref, resources, this.handler);
  56459. operatorList.addOp(fn, pattern.getIR());
  56460. return Promise.resolve();
  56461. } else {
  56462. return Promise.reject('Unknown PatternType: ' + typeNum);
  56463. }
  56464. }
  56465. // TODO shall we fail here?
  56466. operatorList.addOp(fn, args);
  56467. return Promise.resolve();
  56468. },
  56469. getOperatorList: function PartialEvaluator_getOperatorList(stream, task, resources, operatorList, initialState) {
  56470. var self = this;
  56471. var xref = this.xref;
  56472. var imageCache = Object.create(null);
  56473. assert(operatorList);
  56474. resources = resources || Dict.empty;
  56475. var xobjs = resources.get('XObject') || Dict.empty;
  56476. var patterns = resources.get('Pattern') || Dict.empty;
  56477. var stateManager = new StateManager(initialState || new EvalState());
  56478. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  56479. var timeSlotManager = new TimeSlotManager();
  56480. return new Promise(function promiseBody(resolve, reject) {
  56481. var next = function (promise) {
  56482. promise.then(function () {
  56483. try {
  56484. promiseBody(resolve, reject);
  56485. } catch (ex) {
  56486. reject(ex);
  56487. }
  56488. }, reject);
  56489. };
  56490. task.ensureNotTerminated();
  56491. timeSlotManager.reset();
  56492. var stop, operation = {}, i, ii, cs;
  56493. while (!(stop = timeSlotManager.check())) {
  56494. // The arguments parsed by read() are used beyond this loop, so we
  56495. // cannot reuse the same array on each iteration. Therefore we pass
  56496. // in |null| as the initial value (see the comment on
  56497. // EvaluatorPreprocessor_read() for why).
  56498. operation.args = null;
  56499. if (!preprocessor.read(operation)) {
  56500. break;
  56501. }
  56502. var args = operation.args;
  56503. var fn = operation.fn;
  56504. switch (fn | 0) {
  56505. case OPS.paintXObject:
  56506. if (args[0].code) {
  56507. break;
  56508. }
  56509. // eagerly compile XForm objects
  56510. var name = args[0].name;
  56511. if (!name) {
  56512. warn('XObject must be referred to by name.');
  56513. continue;
  56514. }
  56515. if (imageCache[name] !== undefined) {
  56516. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  56517. args = null;
  56518. continue;
  56519. }
  56520. var xobj = xobjs.get(name);
  56521. if (xobj) {
  56522. assert(isStream(xobj), 'XObject should be a stream');
  56523. var type = xobj.dict.get('Subtype');
  56524. assert(isName(type), 'XObject should have a Name subtype');
  56525. if (type.name === 'Form') {
  56526. stateManager.save();
  56527. next(self.buildFormXObject(resources, xobj, null, operatorList, task, stateManager.state.clone()).then(function () {
  56528. stateManager.restore();
  56529. }));
  56530. return;
  56531. } else if (type.name === 'Image') {
  56532. self.buildPaintImageXObject(resources, xobj, false, operatorList, name, imageCache);
  56533. args = null;
  56534. continue;
  56535. } else if (type.name === 'PS') {
  56536. // PostScript XObjects are unused when viewing documents.
  56537. // See section 4.7.1 of Adobe's PDF reference.
  56538. info('Ignored XObject subtype PS');
  56539. continue;
  56540. } else {
  56541. error('Unhandled XObject subtype ' + type.name);
  56542. }
  56543. }
  56544. break;
  56545. case OPS.setFont:
  56546. var fontSize = args[1];
  56547. // eagerly collect all fonts
  56548. next(self.handleSetFont(resources, args, null, operatorList, task, stateManager.state).then(function (loadedName) {
  56549. operatorList.addDependency(loadedName);
  56550. operatorList.addOp(OPS.setFont, [
  56551. loadedName,
  56552. fontSize
  56553. ]);
  56554. }));
  56555. return;
  56556. case OPS.endInlineImage:
  56557. var cacheKey = args[0].cacheKey;
  56558. if (cacheKey) {
  56559. var cacheEntry = imageCache[cacheKey];
  56560. if (cacheEntry !== undefined) {
  56561. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  56562. args = null;
  56563. continue;
  56564. }
  56565. }
  56566. self.buildPaintImageXObject(resources, args[0], true, operatorList, cacheKey, imageCache);
  56567. args = null;
  56568. continue;
  56569. case OPS.showText:
  56570. args[0] = self.handleText(args[0], stateManager.state);
  56571. break;
  56572. case OPS.showSpacedText:
  56573. var arr = args[0];
  56574. var combinedGlyphs = [];
  56575. var arrLength = arr.length;
  56576. var state = stateManager.state;
  56577. for (i = 0; i < arrLength; ++i) {
  56578. var arrItem = arr[i];
  56579. if (isString(arrItem)) {
  56580. Array.prototype.push.apply(combinedGlyphs, self.handleText(arrItem, state));
  56581. } else if (isNum(arrItem)) {
  56582. combinedGlyphs.push(arrItem);
  56583. }
  56584. }
  56585. args[0] = combinedGlyphs;
  56586. fn = OPS.showText;
  56587. break;
  56588. case OPS.nextLineShowText:
  56589. operatorList.addOp(OPS.nextLine);
  56590. args[0] = self.handleText(args[0], stateManager.state);
  56591. fn = OPS.showText;
  56592. break;
  56593. case OPS.nextLineSetSpacingShowText:
  56594. operatorList.addOp(OPS.nextLine);
  56595. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  56596. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  56597. args[0] = self.handleText(args[0], stateManager.state);
  56598. fn = OPS.showText;
  56599. break;
  56600. case OPS.setTextRenderingMode:
  56601. stateManager.state.textRenderingMode = args[0];
  56602. break;
  56603. case OPS.setFillColorSpace:
  56604. stateManager.state.fillColorSpace = ColorSpace.parse(args[0], xref, resources);
  56605. continue;
  56606. case OPS.setStrokeColorSpace:
  56607. stateManager.state.strokeColorSpace = ColorSpace.parse(args[0], xref, resources);
  56608. continue;
  56609. case OPS.setFillColor:
  56610. cs = stateManager.state.fillColorSpace;
  56611. args = cs.getRgb(args, 0);
  56612. fn = OPS.setFillRGBColor;
  56613. break;
  56614. case OPS.setStrokeColor:
  56615. cs = stateManager.state.strokeColorSpace;
  56616. args = cs.getRgb(args, 0);
  56617. fn = OPS.setStrokeRGBColor;
  56618. break;
  56619. case OPS.setFillGray:
  56620. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  56621. args = ColorSpace.singletons.gray.getRgb(args, 0);
  56622. fn = OPS.setFillRGBColor;
  56623. break;
  56624. case OPS.setStrokeGray:
  56625. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  56626. args = ColorSpace.singletons.gray.getRgb(args, 0);
  56627. fn = OPS.setStrokeRGBColor;
  56628. break;
  56629. case OPS.setFillCMYKColor:
  56630. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  56631. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  56632. fn = OPS.setFillRGBColor;
  56633. break;
  56634. case OPS.setStrokeCMYKColor:
  56635. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  56636. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  56637. fn = OPS.setStrokeRGBColor;
  56638. break;
  56639. case OPS.setFillRGBColor:
  56640. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  56641. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  56642. break;
  56643. case OPS.setStrokeRGBColor:
  56644. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  56645. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  56646. break;
  56647. case OPS.setFillColorN:
  56648. cs = stateManager.state.fillColorSpace;
  56649. if (cs.name === 'Pattern') {
  56650. next(self.handleColorN(operatorList, OPS.setFillColorN, args, cs, patterns, resources, task, xref));
  56651. return;
  56652. }
  56653. args = cs.getRgb(args, 0);
  56654. fn = OPS.setFillRGBColor;
  56655. break;
  56656. case OPS.setStrokeColorN:
  56657. cs = stateManager.state.strokeColorSpace;
  56658. if (cs.name === 'Pattern') {
  56659. next(self.handleColorN(operatorList, OPS.setStrokeColorN, args, cs, patterns, resources, task, xref));
  56660. return;
  56661. }
  56662. args = cs.getRgb(args, 0);
  56663. fn = OPS.setStrokeRGBColor;
  56664. break;
  56665. case OPS.shadingFill:
  56666. var shadingRes = resources.get('Shading');
  56667. if (!shadingRes) {
  56668. error('No shading resource found');
  56669. }
  56670. var shading = shadingRes.get(args[0].name);
  56671. if (!shading) {
  56672. error('No shading object found');
  56673. }
  56674. var shadingFill = Pattern.parseShading(shading, null, xref, resources, self.handler);
  56675. var patternIR = shadingFill.getIR();
  56676. args = [patternIR];
  56677. fn = OPS.shadingFill;
  56678. break;
  56679. case OPS.setGState:
  56680. var dictName = args[0];
  56681. var extGState = resources.get('ExtGState');
  56682. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  56683. break;
  56684. }
  56685. var gState = extGState.get(dictName.name);
  56686. next(self.setGState(resources, gState, operatorList, task, xref, stateManager));
  56687. return;
  56688. case OPS.moveTo:
  56689. case OPS.lineTo:
  56690. case OPS.curveTo:
  56691. case OPS.curveTo2:
  56692. case OPS.curveTo3:
  56693. case OPS.closePath:
  56694. self.buildPath(operatorList, fn, args);
  56695. continue;
  56696. case OPS.rectangle:
  56697. self.buildPath(operatorList, fn, args);
  56698. continue;
  56699. case OPS.markPoint:
  56700. case OPS.markPointProps:
  56701. case OPS.beginMarkedContent:
  56702. case OPS.beginMarkedContentProps:
  56703. case OPS.endMarkedContent:
  56704. case OPS.beginCompat:
  56705. case OPS.endCompat:
  56706. // Ignore operators where the corresponding handlers are known to
  56707. // be no-op in CanvasGraphics (display/canvas.js). This prevents
  56708. // serialization errors and is also a bit more efficient.
  56709. // We could also try to serialize all objects in a general way,
  56710. // e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
  56711. // but doing so is meaningless without knowing the semantics.
  56712. continue;
  56713. default:
  56714. // Note: Ignore the operator if it has `Dict` arguments, since
  56715. // those are non-serializable, otherwise postMessage will throw
  56716. // "An object could not be cloned.".
  56717. if (args !== null) {
  56718. for (i = 0, ii = args.length; i < ii; i++) {
  56719. if (args[i] instanceof Dict) {
  56720. break;
  56721. }
  56722. }
  56723. if (i < ii) {
  56724. warn('getOperatorList - ignoring operator: ' + fn);
  56725. continue;
  56726. }
  56727. }
  56728. }
  56729. operatorList.addOp(fn, args);
  56730. }
  56731. if (stop) {
  56732. next(deferred);
  56733. return;
  56734. }
  56735. // Some PDFs don't close all restores inside object/form.
  56736. // Closing those for them.
  56737. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  56738. operatorList.addOp(OPS.restore, []);
  56739. }
  56740. resolve();
  56741. });
  56742. },
  56743. getTextContent: function PartialEvaluator_getTextContent(stream, task, resources, stateManager, normalizeWhitespace, combineTextItems) {
  56744. stateManager = stateManager || new StateManager(new TextState());
  56745. var WhitespaceRegexp = /\s/g;
  56746. var textContent = {
  56747. items: [],
  56748. styles: Object.create(null)
  56749. };
  56750. var textContentItem = {
  56751. initialized: false,
  56752. str: [],
  56753. width: 0,
  56754. height: 0,
  56755. vertical: false,
  56756. lastAdvanceWidth: 0,
  56757. lastAdvanceHeight: 0,
  56758. textAdvanceScale: 0,
  56759. spaceWidth: 0,
  56760. fakeSpaceMin: Infinity,
  56761. fakeMultiSpaceMin: Infinity,
  56762. fakeMultiSpaceMax: -0,
  56763. textRunBreakAllowed: false,
  56764. transform: null,
  56765. fontName: null
  56766. };
  56767. var SPACE_FACTOR = 0.3;
  56768. var MULTI_SPACE_FACTOR = 1.5;
  56769. var MULTI_SPACE_FACTOR_MAX = 4;
  56770. var self = this;
  56771. var xref = this.xref;
  56772. resources = xref.fetchIfRef(resources) || Dict.empty;
  56773. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  56774. var xobjs = null;
  56775. var xobjsCache = Object.create(null);
  56776. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  56777. var textState;
  56778. function ensureTextContentItem() {
  56779. if (textContentItem.initialized) {
  56780. return textContentItem;
  56781. }
  56782. var font = textState.font;
  56783. if (!(font.loadedName in textContent.styles)) {
  56784. textContent.styles[font.loadedName] = {
  56785. fontFamily: font.fallbackName,
  56786. ascent: font.ascent,
  56787. descent: font.descent,
  56788. vertical: font.vertical
  56789. };
  56790. }
  56791. textContentItem.fontName = font.loadedName;
  56792. // 9.4.4 Text Space Details
  56793. var tsm = [
  56794. textState.fontSize * textState.textHScale,
  56795. 0,
  56796. 0,
  56797. textState.fontSize,
  56798. 0,
  56799. textState.textRise
  56800. ];
  56801. if (font.isType3Font && textState.fontMatrix !== FONT_IDENTITY_MATRIX && textState.fontSize === 1) {
  56802. var glyphHeight = font.bbox[3] - font.bbox[1];
  56803. if (glyphHeight > 0) {
  56804. glyphHeight = glyphHeight * textState.fontMatrix[3];
  56805. tsm[3] *= glyphHeight;
  56806. }
  56807. }
  56808. var trm = Util.transform(textState.ctm, Util.transform(textState.textMatrix, tsm));
  56809. textContentItem.transform = trm;
  56810. if (!font.vertical) {
  56811. textContentItem.width = 0;
  56812. textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  56813. textContentItem.vertical = false;
  56814. } else {
  56815. textContentItem.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  56816. textContentItem.height = 0;
  56817. textContentItem.vertical = true;
  56818. }
  56819. var a = textState.textLineMatrix[0];
  56820. var b = textState.textLineMatrix[1];
  56821. var scaleLineX = Math.sqrt(a * a + b * b);
  56822. a = textState.ctm[0];
  56823. b = textState.ctm[1];
  56824. var scaleCtmX = Math.sqrt(a * a + b * b);
  56825. textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
  56826. textContentItem.lastAdvanceWidth = 0;
  56827. textContentItem.lastAdvanceHeight = 0;
  56828. var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
  56829. if (spaceWidth) {
  56830. textContentItem.spaceWidth = spaceWidth;
  56831. textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
  56832. textContentItem.fakeMultiSpaceMin = spaceWidth * MULTI_SPACE_FACTOR;
  56833. textContentItem.fakeMultiSpaceMax = spaceWidth * MULTI_SPACE_FACTOR_MAX;
  56834. // It's okay for monospace fonts to fake as much space as needed.
  56835. textContentItem.textRunBreakAllowed = !font.isMonospace;
  56836. } else {
  56837. textContentItem.spaceWidth = 0;
  56838. textContentItem.fakeSpaceMin = Infinity;
  56839. textContentItem.fakeMultiSpaceMin = Infinity;
  56840. textContentItem.fakeMultiSpaceMax = 0;
  56841. textContentItem.textRunBreakAllowed = false;
  56842. }
  56843. textContentItem.initialized = true;
  56844. return textContentItem;
  56845. }
  56846. function replaceWhitespace(str) {
  56847. // Replaces all whitespaces with standard spaces (0x20), to avoid
  56848. // alignment issues between the textLayer and the canvas if the text
  56849. // contains e.g. tabs (fixes issue6612.pdf).
  56850. var i = 0, ii = str.length, code;
  56851. while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7F) {
  56852. i++;
  56853. }
  56854. return i < ii ? str.replace(WhitespaceRegexp, ' ') : str;
  56855. }
  56856. function runBidiTransform(textChunk) {
  56857. var str = textChunk.str.join('');
  56858. var bidiResult = bidi(str, -1, textChunk.vertical);
  56859. return {
  56860. str: normalizeWhitespace ? replaceWhitespace(bidiResult.str) : bidiResult.str,
  56861. dir: bidiResult.dir,
  56862. width: textChunk.width,
  56863. height: textChunk.height,
  56864. transform: textChunk.transform,
  56865. fontName: textChunk.fontName
  56866. };
  56867. }
  56868. function handleSetFont(fontName, fontRef) {
  56869. return self.loadFont(fontName, fontRef, xref, resources).then(function (translated) {
  56870. textState.font = translated.font;
  56871. textState.fontMatrix = translated.font.fontMatrix || FONT_IDENTITY_MATRIX;
  56872. });
  56873. }
  56874. function buildTextContentItem(chars) {
  56875. var font = textState.font;
  56876. var textChunk = ensureTextContentItem();
  56877. var width = 0;
  56878. var height = 0;
  56879. var glyphs = font.charsToGlyphs(chars);
  56880. var defaultVMetrics = font.defaultVMetrics;
  56881. for (var i = 0; i < glyphs.length; i++) {
  56882. var glyph = glyphs[i];
  56883. var vMetricX = null;
  56884. var vMetricY = null;
  56885. var glyphWidth = null;
  56886. if (font.vertical) {
  56887. if (glyph.vmetric) {
  56888. glyphWidth = glyph.vmetric[0];
  56889. vMetricX = glyph.vmetric[1];
  56890. vMetricY = glyph.vmetric[2];
  56891. } else {
  56892. glyphWidth = glyph.width;
  56893. vMetricX = glyph.width * 0.5;
  56894. vMetricY = defaultVMetrics[2];
  56895. }
  56896. } else {
  56897. glyphWidth = glyph.width;
  56898. }
  56899. var glyphUnicode = glyph.unicode;
  56900. var NormalizedUnicodes = getNormalizedUnicodes();
  56901. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  56902. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  56903. }
  56904. glyphUnicode = reverseIfRtl(glyphUnicode);
  56905. // The following will calculate the x and y of the individual glyphs.
  56906. // if (font.vertical) {
  56907. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  56908. // textState.fontMatrix[0];
  56909. // tsm[5] -= vMetricY * textState.fontSize *
  56910. // textState.fontMatrix[0];
  56911. // }
  56912. // var trm = Util.transform(textState.textMatrix, tsm);
  56913. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  56914. // var x = pt[0];
  56915. // var y = pt[1];
  56916. var charSpacing = textState.charSpacing;
  56917. if (glyph.isSpace) {
  56918. var wordSpacing = textState.wordSpacing;
  56919. charSpacing += wordSpacing;
  56920. if (wordSpacing > 0) {
  56921. addFakeSpaces(wordSpacing, textChunk.str);
  56922. }
  56923. }
  56924. var tx = 0;
  56925. var ty = 0;
  56926. if (!font.vertical) {
  56927. var w0 = glyphWidth * textState.fontMatrix[0];
  56928. tx = (w0 * textState.fontSize + charSpacing) * textState.textHScale;
  56929. width += tx;
  56930. } else {
  56931. var w1 = glyphWidth * textState.fontMatrix[0];
  56932. ty = w1 * textState.fontSize + charSpacing;
  56933. height += ty;
  56934. }
  56935. textState.translateTextMatrix(tx, ty);
  56936. textChunk.str.push(glyphUnicode);
  56937. }
  56938. if (!font.vertical) {
  56939. textChunk.lastAdvanceWidth = width;
  56940. textChunk.width += width * textChunk.textAdvanceScale;
  56941. } else {
  56942. textChunk.lastAdvanceHeight = height;
  56943. textChunk.height += Math.abs(height * textChunk.textAdvanceScale);
  56944. }
  56945. return textChunk;
  56946. }
  56947. function addFakeSpaces(width, strBuf) {
  56948. if (width < textContentItem.fakeSpaceMin) {
  56949. return;
  56950. }
  56951. if (width < textContentItem.fakeMultiSpaceMin) {
  56952. strBuf.push(' ');
  56953. return;
  56954. }
  56955. var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
  56956. while (fakeSpaces-- > 0) {
  56957. strBuf.push(' ');
  56958. }
  56959. }
  56960. function flushTextContentItem() {
  56961. if (!textContentItem.initialized) {
  56962. return;
  56963. }
  56964. textContent.items.push(runBidiTransform(textContentItem));
  56965. textContentItem.initialized = false;
  56966. textContentItem.str.length = 0;
  56967. }
  56968. var timeSlotManager = new TimeSlotManager();
  56969. return new Promise(function promiseBody(resolve, reject) {
  56970. var next = function (promise) {
  56971. promise.then(function () {
  56972. try {
  56973. promiseBody(resolve, reject);
  56974. } catch (ex) {
  56975. reject(ex);
  56976. }
  56977. }, reject);
  56978. };
  56979. task.ensureNotTerminated();
  56980. timeSlotManager.reset();
  56981. var stop, operation = {}, args = [];
  56982. while (!(stop = timeSlotManager.check())) {
  56983. // The arguments parsed by read() are not used beyond this loop, so
  56984. // we can reuse the same array on every iteration, thus avoiding
  56985. // unnecessary allocations.
  56986. args.length = 0;
  56987. operation.args = args;
  56988. if (!preprocessor.read(operation)) {
  56989. break;
  56990. }
  56991. textState = stateManager.state;
  56992. var fn = operation.fn;
  56993. args = operation.args;
  56994. var advance, diff;
  56995. switch (fn | 0) {
  56996. case OPS.setFont:
  56997. // Optimization to ignore multiple identical Tf commands.
  56998. var fontNameArg = args[0].name, fontSizeArg = args[1];
  56999. if (textState.font && fontNameArg === textState.fontName && fontSizeArg === textState.fontSize) {
  57000. break;
  57001. }
  57002. flushTextContentItem();
  57003. textState.fontName = fontNameArg;
  57004. textState.fontSize = fontSizeArg;
  57005. next(handleSetFont(fontNameArg, null));
  57006. return;
  57007. case OPS.setTextRise:
  57008. flushTextContentItem();
  57009. textState.textRise = args[0];
  57010. break;
  57011. case OPS.setHScale:
  57012. flushTextContentItem();
  57013. textState.textHScale = args[0] / 100;
  57014. break;
  57015. case OPS.setLeading:
  57016. flushTextContentItem();
  57017. textState.leading = args[0];
  57018. break;
  57019. case OPS.moveText:
  57020. // Optimization to treat same line movement as advance
  57021. var isSameTextLine = !textState.font ? false : (textState.font.vertical ? args[0] : args[1]) === 0;
  57022. advance = args[0] - args[1];
  57023. if (combineTextItems && isSameTextLine && textContentItem.initialized && advance > 0 && advance <= textContentItem.fakeMultiSpaceMax) {
  57024. textState.translateTextLineMatrix(args[0], args[1]);
  57025. textContentItem.width += args[0] - textContentItem.lastAdvanceWidth;
  57026. textContentItem.height += args[1] - textContentItem.lastAdvanceHeight;
  57027. diff = args[0] - textContentItem.lastAdvanceWidth - (args[1] - textContentItem.lastAdvanceHeight);
  57028. addFakeSpaces(diff, textContentItem.str);
  57029. break;
  57030. }
  57031. flushTextContentItem();
  57032. textState.translateTextLineMatrix(args[0], args[1]);
  57033. textState.textMatrix = textState.textLineMatrix.slice();
  57034. break;
  57035. case OPS.setLeadingMoveText:
  57036. flushTextContentItem();
  57037. textState.leading = -args[1];
  57038. textState.translateTextLineMatrix(args[0], args[1]);
  57039. textState.textMatrix = textState.textLineMatrix.slice();
  57040. break;
  57041. case OPS.nextLine:
  57042. flushTextContentItem();
  57043. textState.carriageReturn();
  57044. break;
  57045. case OPS.setTextMatrix:
  57046. // Optimization to treat same line movement as advance.
  57047. advance = textState.calcTextLineMatrixAdvance(args[0], args[1], args[2], args[3], args[4], args[5]);
  57048. if (combineTextItems && advance !== null && textContentItem.initialized && advance.value > 0 && advance.value <= textContentItem.fakeMultiSpaceMax) {
  57049. textState.translateTextLineMatrix(advance.width, advance.height);
  57050. textContentItem.width += advance.width - textContentItem.lastAdvanceWidth;
  57051. textContentItem.height += advance.height - textContentItem.lastAdvanceHeight;
  57052. diff = advance.width - textContentItem.lastAdvanceWidth - (advance.height - textContentItem.lastAdvanceHeight);
  57053. addFakeSpaces(diff, textContentItem.str);
  57054. break;
  57055. }
  57056. flushTextContentItem();
  57057. textState.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
  57058. textState.setTextLineMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
  57059. break;
  57060. case OPS.setCharSpacing:
  57061. textState.charSpacing = args[0];
  57062. break;
  57063. case OPS.setWordSpacing:
  57064. textState.wordSpacing = args[0];
  57065. break;
  57066. case OPS.beginText:
  57067. flushTextContentItem();
  57068. textState.textMatrix = IDENTITY_MATRIX.slice();
  57069. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  57070. break;
  57071. case OPS.showSpacedText:
  57072. var items = args[0];
  57073. var offset;
  57074. for (var j = 0, jj = items.length; j < jj; j++) {
  57075. if (typeof items[j] === 'string') {
  57076. buildTextContentItem(items[j]);
  57077. } else if (isNum(items[j])) {
  57078. ensureTextContentItem();
  57079. // PDF Specification 5.3.2 states:
  57080. // The number is expressed in thousandths of a unit of text
  57081. // space.
  57082. // This amount is subtracted from the current horizontal or
  57083. // vertical coordinate, depending on the writing mode.
  57084. // In the default coordinate system, a positive adjustment
  57085. // has the effect of moving the next glyph painted either to
  57086. // the left or down by the given amount.
  57087. advance = items[j] * textState.fontSize / 1000;
  57088. var breakTextRun = false;
  57089. if (textState.font.vertical) {
  57090. offset = advance * (textState.textHScale * textState.textMatrix[2] + textState.textMatrix[3]);
  57091. textState.translateTextMatrix(0, advance);
  57092. breakTextRun = textContentItem.textRunBreakAllowed && advance > textContentItem.fakeMultiSpaceMax;
  57093. if (!breakTextRun) {
  57094. // Value needs to be added to height to paint down.
  57095. textContentItem.height += offset;
  57096. }
  57097. } else {
  57098. advance = -advance;
  57099. offset = advance * (textState.textHScale * textState.textMatrix[0] + textState.textMatrix[1]);
  57100. textState.translateTextMatrix(advance, 0);
  57101. breakTextRun = textContentItem.textRunBreakAllowed && advance > textContentItem.fakeMultiSpaceMax;
  57102. if (!breakTextRun) {
  57103. // Value needs to be subtracted from width to paint left.
  57104. textContentItem.width += offset;
  57105. }
  57106. }
  57107. if (breakTextRun) {
  57108. flushTextContentItem();
  57109. } else if (advance > 0) {
  57110. addFakeSpaces(advance, textContentItem.str);
  57111. }
  57112. }
  57113. }
  57114. break;
  57115. case OPS.showText:
  57116. buildTextContentItem(args[0]);
  57117. break;
  57118. case OPS.nextLineShowText:
  57119. flushTextContentItem();
  57120. textState.carriageReturn();
  57121. buildTextContentItem(args[0]);
  57122. break;
  57123. case OPS.nextLineSetSpacingShowText:
  57124. flushTextContentItem();
  57125. textState.wordSpacing = args[0];
  57126. textState.charSpacing = args[1];
  57127. textState.carriageReturn();
  57128. buildTextContentItem(args[2]);
  57129. break;
  57130. case OPS.paintXObject:
  57131. flushTextContentItem();
  57132. if (args[0].code) {
  57133. break;
  57134. }
  57135. if (!xobjs) {
  57136. xobjs = resources.get('XObject') || Dict.empty;
  57137. }
  57138. var name = args[0].name;
  57139. if (xobjsCache.key === name) {
  57140. if (xobjsCache.texts) {
  57141. Util.appendToArray(textContent.items, xobjsCache.texts.items);
  57142. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  57143. }
  57144. break;
  57145. }
  57146. var xobj = xobjs.get(name);
  57147. if (!xobj) {
  57148. break;
  57149. }
  57150. assert(isStream(xobj), 'XObject should be a stream');
  57151. var type = xobj.dict.get('Subtype');
  57152. assert(isName(type), 'XObject should have a Name subtype');
  57153. if ('Form' !== type.name) {
  57154. xobjsCache.key = name;
  57155. xobjsCache.texts = null;
  57156. break;
  57157. }
  57158. stateManager.save();
  57159. var matrix = xobj.dict.getArray('Matrix');
  57160. if (isArray(matrix) && matrix.length === 6) {
  57161. stateManager.transform(matrix);
  57162. }
  57163. next(self.getTextContent(xobj, task, xobj.dict.get('Resources') || resources, stateManager, normalizeWhitespace, combineTextItems).then(function (formTextContent) {
  57164. Util.appendToArray(textContent.items, formTextContent.items);
  57165. Util.extendObj(textContent.styles, formTextContent.styles);
  57166. stateManager.restore();
  57167. xobjsCache.key = name;
  57168. xobjsCache.texts = formTextContent;
  57169. }));
  57170. return;
  57171. case OPS.setGState:
  57172. flushTextContentItem();
  57173. var dictName = args[0];
  57174. var extGState = resources.get('ExtGState');
  57175. if (!isDict(extGState) || !isName(dictName)) {
  57176. break;
  57177. }
  57178. var gState = extGState.get(dictName.name);
  57179. if (!isDict(gState)) {
  57180. break;
  57181. }
  57182. var gStateFont = gState.get('Font');
  57183. if (gStateFont) {
  57184. textState.fontName = null;
  57185. textState.fontSize = gStateFont[1];
  57186. next(handleSetFont(null, gStateFont[0]));
  57187. return;
  57188. }
  57189. break;
  57190. }
  57191. }
  57192. // switch
  57193. // while
  57194. if (stop) {
  57195. next(deferred);
  57196. return;
  57197. }
  57198. flushTextContentItem();
  57199. resolve(textContent);
  57200. });
  57201. },
  57202. extractDataStructures: function PartialEvaluator_extractDataStructures(dict, baseDict, xref, properties) {
  57203. // 9.10.2
  57204. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  57205. var toUnicodePromise = toUnicode ? this.readToUnicode(toUnicode) : Promise.resolve(undefined);
  57206. if (properties.composite) {
  57207. // CIDSystemInfo helps to match CID to glyphs
  57208. var cidSystemInfo = dict.get('CIDSystemInfo');
  57209. if (isDict(cidSystemInfo)) {
  57210. properties.cidSystemInfo = {
  57211. registry: cidSystemInfo.get('Registry'),
  57212. ordering: cidSystemInfo.get('Ordering'),
  57213. supplement: cidSystemInfo.get('Supplement')
  57214. };
  57215. }
  57216. var cidToGidMap = dict.get('CIDToGIDMap');
  57217. if (isStream(cidToGidMap)) {
  57218. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  57219. }
  57220. }
  57221. // Based on 9.6.6 of the spec the encoding can come from multiple places
  57222. // and depends on the font type. The base encoding and differences are
  57223. // read here, but the encoding that is actually used is chosen during
  57224. // glyph mapping in the font.
  57225. // TODO: Loading the built in encoding in the font would allow the
  57226. // differences to be merged in here not require us to hold on to it.
  57227. var differences = [];
  57228. var baseEncodingName = null;
  57229. var encoding;
  57230. if (dict.has('Encoding')) {
  57231. encoding = dict.get('Encoding');
  57232. if (isDict(encoding)) {
  57233. baseEncodingName = encoding.get('BaseEncoding');
  57234. baseEncodingName = isName(baseEncodingName) ? baseEncodingName.name : null;
  57235. // Load the differences between the base and original
  57236. if (encoding.has('Differences')) {
  57237. var diffEncoding = encoding.get('Differences');
  57238. var index = 0;
  57239. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  57240. var data = xref.fetchIfRef(diffEncoding[j]);
  57241. if (isNum(data)) {
  57242. index = data;
  57243. } else if (isName(data)) {
  57244. differences[index++] = data.name;
  57245. } else {
  57246. error('Invalid entry in \'Differences\' array: ' + data);
  57247. }
  57248. }
  57249. }
  57250. } else if (isName(encoding)) {
  57251. baseEncodingName = encoding.name;
  57252. } else {
  57253. error('Encoding is not a Name nor a Dict');
  57254. }
  57255. // According to table 114 if the encoding is a named encoding it must be
  57256. // one of these predefined encodings.
  57257. if (baseEncodingName !== 'MacRomanEncoding' && baseEncodingName !== 'MacExpertEncoding' && baseEncodingName !== 'WinAnsiEncoding') {
  57258. baseEncodingName = null;
  57259. }
  57260. }
  57261. if (baseEncodingName) {
  57262. properties.defaultEncoding = getEncoding(baseEncodingName).slice();
  57263. } else {
  57264. encoding = properties.type === 'TrueType' ? WinAnsiEncoding : StandardEncoding;
  57265. // The Symbolic attribute can be misused for regular fonts
  57266. // Heuristic: we have to check if the font is a standard one also
  57267. if (!!(properties.flags & FontFlags.Symbolic)) {
  57268. encoding = MacRomanEncoding;
  57269. if (!properties.file) {
  57270. if (/Symbol/i.test(properties.name)) {
  57271. encoding = SymbolSetEncoding;
  57272. } else if (/Dingbats/i.test(properties.name)) {
  57273. encoding = ZapfDingbatsEncoding;
  57274. }
  57275. }
  57276. }
  57277. properties.defaultEncoding = encoding;
  57278. }
  57279. properties.differences = differences;
  57280. properties.baseEncodingName = baseEncodingName;
  57281. properties.hasEncoding = !!baseEncodingName || differences.length > 0;
  57282. properties.dict = dict;
  57283. return toUnicodePromise.then(function (toUnicode) {
  57284. properties.toUnicode = toUnicode;
  57285. return this.buildToUnicode(properties);
  57286. }.bind(this)).then(function (toUnicode) {
  57287. properties.toUnicode = toUnicode;
  57288. return properties;
  57289. });
  57290. },
  57291. /**
  57292. * Builds a char code to unicode map based on section 9.10 of the spec.
  57293. * @param {Object} properties Font properties object.
  57294. * @return {Promise} A Promise that is resolved with a
  57295. * {ToUnicodeMap|IdentityToUnicodeMap} object.
  57296. */
  57297. buildToUnicode: function PartialEvaluator_buildToUnicode(properties) {
  57298. properties.hasIncludedToUnicodeMap = !!properties.toUnicode && properties.toUnicode.length > 0;
  57299. // Section 9.10.2 Mapping Character Codes to Unicode Values
  57300. if (properties.hasIncludedToUnicodeMap) {
  57301. return Promise.resolve(properties.toUnicode);
  57302. }
  57303. // According to the spec if the font is a simple font we should only map
  57304. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  57305. // the differences array only contains adobe standard or symbol set names,
  57306. // in pratice it seems better to always try to create a toUnicode
  57307. // map based of the default encoding.
  57308. var toUnicode, charcode, glyphName;
  57309. if (!properties.composite)
  57310. /* is simple font */
  57311. {
  57312. toUnicode = [];
  57313. var encoding = properties.defaultEncoding.slice();
  57314. var baseEncodingName = properties.baseEncodingName;
  57315. // Merge in the differences array.
  57316. var differences = properties.differences;
  57317. for (charcode in differences) {
  57318. glyphName = differences[charcode];
  57319. if (glyphName === '.notdef') {
  57320. // Skip .notdef to prevent rendering errors, e.g. boxes appearing
  57321. // where there should be spaces (fixes issue5256.pdf).
  57322. continue;
  57323. }
  57324. encoding[charcode] = glyphName;
  57325. }
  57326. var glyphsUnicodeMap = getGlyphsUnicode();
  57327. for (charcode in encoding) {
  57328. // a) Map the character code to a character name.
  57329. glyphName = encoding[charcode];
  57330. // b) Look up the character name in the Adobe Glyph List (see the
  57331. // Bibliography) to obtain the corresponding Unicode value.
  57332. if (glyphName === '') {
  57333. continue;
  57334. } else if (glyphsUnicodeMap[glyphName] === undefined) {
  57335. // (undocumented) c) Few heuristics to recognize unknown glyphs
  57336. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  57337. var code = 0;
  57338. switch (glyphName[0]) {
  57339. case 'G':
  57340. // Gxx glyph
  57341. if (glyphName.length === 3) {
  57342. code = parseInt(glyphName.substr(1), 16);
  57343. }
  57344. break;
  57345. case 'g':
  57346. // g00xx glyph
  57347. if (glyphName.length === 5) {
  57348. code = parseInt(glyphName.substr(1), 16);
  57349. }
  57350. break;
  57351. case 'C':
  57352. // Cddd glyph
  57353. case 'c':
  57354. // cddd glyph
  57355. if (glyphName.length >= 3) {
  57356. code = +glyphName.substr(1);
  57357. }
  57358. break;
  57359. default:
  57360. // 'uniXXXX'/'uXXXX{XX}' glyphs
  57361. var unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  57362. if (unicode !== -1) {
  57363. code = unicode;
  57364. }
  57365. }
  57366. if (code) {
  57367. // If |baseEncodingName| is one the predefined encodings,
  57368. // and |code| equals |charcode|, using the glyph defined in the
  57369. // baseEncoding seems to yield a better |toUnicode| mapping
  57370. // (fixes issue 5070).
  57371. if (baseEncodingName && code === +charcode) {
  57372. var baseEncoding = getEncoding(baseEncodingName);
  57373. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  57374. toUnicode[charcode] = String.fromCharCode(glyphsUnicodeMap[glyphName]);
  57375. continue;
  57376. }
  57377. }
  57378. toUnicode[charcode] = String.fromCharCode(code);
  57379. }
  57380. continue;
  57381. }
  57382. toUnicode[charcode] = String.fromCharCode(glyphsUnicodeMap[glyphName]);
  57383. }
  57384. return Promise.resolve(new ToUnicodeMap(toUnicode));
  57385. }
  57386. // If the font is a composite font that uses one of the predefined CMaps
  57387. // listed in Table 118 (except Identity–H and Identity–V) or whose
  57388. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  57389. // Adobe-Korea1 character collection:
  57390. 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'))) {
  57391. // Then:
  57392. // a) Map the character code to a character identifier (CID) according
  57393. // to the font’s CMap.
  57394. // b) Obtain the registry and ordering of the character collection used
  57395. // by the font’s CMap (for example, Adobe and Japan1) from its
  57396. // CIDSystemInfo dictionary.
  57397. var registry = properties.cidSystemInfo.registry;
  57398. var ordering = properties.cidSystemInfo.ordering;
  57399. // c) Construct a second CMap name by concatenating the registry and
  57400. // ordering obtained in step (b) in the format registry–ordering–UCS2
  57401. // (for example, Adobe–Japan1–UCS2).
  57402. var ucs2CMapName = Name.get(registry + '-' + ordering + '-UCS2');
  57403. // d) Obtain the CMap with the name constructed in step (c) (available
  57404. // from the ASN Web site; see the Bibliography).
  57405. return CMapFactory.create(ucs2CMapName, this.options.cMapOptions, null).then(function (ucs2CMap) {
  57406. var cMap = properties.cMap;
  57407. toUnicode = [];
  57408. cMap.forEach(function (charcode, cid) {
  57409. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  57410. // e) Map the CID obtained in step (a) according to the CMap
  57411. // obtained in step (d), producing a Unicode value.
  57412. var ucs2 = ucs2CMap.lookup(cid);
  57413. if (ucs2) {
  57414. toUnicode[charcode] = String.fromCharCode((ucs2.charCodeAt(0) << 8) + ucs2.charCodeAt(1));
  57415. }
  57416. });
  57417. return new ToUnicodeMap(toUnicode);
  57418. });
  57419. }
  57420. // The viewer's choice, just use an identity map.
  57421. return Promise.resolve(new IdentityToUnicodeMap(properties.firstChar, properties.lastChar));
  57422. },
  57423. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  57424. var cmapObj = toUnicode;
  57425. if (isName(cmapObj)) {
  57426. return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(function (cmap) {
  57427. if (cmap instanceof IdentityCMap) {
  57428. return new IdentityToUnicodeMap(0, 0xFFFF);
  57429. }
  57430. return new ToUnicodeMap(cmap.getMap());
  57431. });
  57432. } else if (isStream(cmapObj)) {
  57433. return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(function (cmap) {
  57434. if (cmap instanceof IdentityCMap) {
  57435. return new IdentityToUnicodeMap(0, 0xFFFF);
  57436. }
  57437. var map = new Array(cmap.length);
  57438. // Convert UTF-16BE
  57439. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  57440. // to iterate over all keys.
  57441. cmap.forEach(function (charCode, token) {
  57442. var str = [];
  57443. for (var k = 0; k < token.length; k += 2) {
  57444. var w1 = token.charCodeAt(k) << 8 | token.charCodeAt(k + 1);
  57445. if ((w1 & 0xF800) !== 0xD800) {
  57446. // w1 < 0xD800 || w1 > 0xDFFF
  57447. str.push(w1);
  57448. continue;
  57449. }
  57450. k += 2;
  57451. var w2 = token.charCodeAt(k) << 8 | token.charCodeAt(k + 1);
  57452. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  57453. }
  57454. map[charCode] = String.fromCharCode.apply(String, str);
  57455. });
  57456. return new ToUnicodeMap(map);
  57457. });
  57458. }
  57459. return Promise.resolve(null);
  57460. },
  57461. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  57462. // Extract the encoding from the CIDToGIDMap
  57463. var glyphsData = cidToGidStream.getBytes();
  57464. // Set encoding 0 to later verify the font has an encoding
  57465. var result = [];
  57466. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  57467. var glyphID = glyphsData[j++] << 8 | glyphsData[j];
  57468. if (glyphID === 0) {
  57469. continue;
  57470. }
  57471. var code = j >> 1;
  57472. result[code] = glyphID;
  57473. }
  57474. return result;
  57475. },
  57476. extractWidths: function PartialEvaluator_extractWidths(dict, xref, descriptor, properties) {
  57477. var glyphsWidths = [];
  57478. var defaultWidth = 0;
  57479. var glyphsVMetrics = [];
  57480. var defaultVMetrics;
  57481. var i, ii, j, jj, start, code, widths;
  57482. if (properties.composite) {
  57483. defaultWidth = dict.get('DW') || 1000;
  57484. widths = dict.get('W');
  57485. if (widths) {
  57486. for (i = 0, ii = widths.length; i < ii; i++) {
  57487. start = widths[i++];
  57488. code = xref.fetchIfRef(widths[i]);
  57489. if (isArray(code)) {
  57490. for (j = 0, jj = code.length; j < jj; j++) {
  57491. glyphsWidths[start++] = code[j];
  57492. }
  57493. } else {
  57494. var width = widths[++i];
  57495. for (j = start; j <= code; j++) {
  57496. glyphsWidths[j] = width;
  57497. }
  57498. }
  57499. }
  57500. }
  57501. if (properties.vertical) {
  57502. var vmetrics = dict.get('DW2') || [
  57503. 880,
  57504. -1000
  57505. ];
  57506. defaultVMetrics = [
  57507. vmetrics[1],
  57508. defaultWidth * 0.5,
  57509. vmetrics[0]
  57510. ];
  57511. vmetrics = dict.get('W2');
  57512. if (vmetrics) {
  57513. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  57514. start = vmetrics[i++];
  57515. code = xref.fetchIfRef(vmetrics[i]);
  57516. if (isArray(code)) {
  57517. for (j = 0, jj = code.length; j < jj; j++) {
  57518. glyphsVMetrics[start++] = [
  57519. code[j++],
  57520. code[j++],
  57521. code[j]
  57522. ];
  57523. }
  57524. } else {
  57525. var vmetric = [
  57526. vmetrics[++i],
  57527. vmetrics[++i],
  57528. vmetrics[++i]
  57529. ];
  57530. for (j = start; j <= code; j++) {
  57531. glyphsVMetrics[j] = vmetric;
  57532. }
  57533. }
  57534. }
  57535. }
  57536. }
  57537. } else {
  57538. var firstChar = properties.firstChar;
  57539. widths = dict.get('Widths');
  57540. if (widths) {
  57541. j = firstChar;
  57542. for (i = 0, ii = widths.length; i < ii; i++) {
  57543. glyphsWidths[j++] = widths[i];
  57544. }
  57545. defaultWidth = parseFloat(descriptor.get('MissingWidth')) || 0;
  57546. } else {
  57547. // Trying get the BaseFont metrics (see comment above).
  57548. var baseFontName = dict.get('BaseFont');
  57549. if (isName(baseFontName)) {
  57550. var metrics = this.getBaseFontMetrics(baseFontName.name);
  57551. glyphsWidths = this.buildCharCodeToWidth(metrics.widths, properties);
  57552. defaultWidth = metrics.defaultWidth;
  57553. }
  57554. }
  57555. }
  57556. // Heuristic: detection of monospace font by checking all non-zero widths
  57557. var isMonospace = true;
  57558. var firstWidth = defaultWidth;
  57559. for (var glyph in glyphsWidths) {
  57560. var glyphWidth = glyphsWidths[glyph];
  57561. if (!glyphWidth) {
  57562. continue;
  57563. }
  57564. if (!firstWidth) {
  57565. firstWidth = glyphWidth;
  57566. continue;
  57567. }
  57568. if (firstWidth !== glyphWidth) {
  57569. isMonospace = false;
  57570. break;
  57571. }
  57572. }
  57573. if (isMonospace) {
  57574. properties.flags |= FontFlags.FixedPitch;
  57575. }
  57576. properties.defaultWidth = defaultWidth;
  57577. properties.widths = glyphsWidths;
  57578. properties.defaultVMetrics = defaultVMetrics;
  57579. properties.vmetrics = glyphsVMetrics;
  57580. },
  57581. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  57582. // Simulating descriptor flags attribute
  57583. var fontNameWoStyle = baseFontName.split('-')[0];
  57584. return fontNameWoStyle in getSerifFonts() || fontNameWoStyle.search(/serif/gi) !== -1;
  57585. },
  57586. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  57587. var defaultWidth = 0;
  57588. var widths = [];
  57589. var monospace = false;
  57590. var stdFontMap = getStdFontMap();
  57591. var lookupName = stdFontMap[name] || name;
  57592. var Metrics = getMetrics();
  57593. if (!(lookupName in Metrics)) {
  57594. // Use default fonts for looking up font metrics if the passed
  57595. // font is not a base font
  57596. if (this.isSerifFont(name)) {
  57597. lookupName = 'Times-Roman';
  57598. } else {
  57599. lookupName = 'Helvetica';
  57600. }
  57601. }
  57602. var glyphWidths = Metrics[lookupName];
  57603. if (isNum(glyphWidths)) {
  57604. defaultWidth = glyphWidths;
  57605. monospace = true;
  57606. } else {
  57607. widths = glyphWidths();
  57608. }
  57609. // expand lazy widths array
  57610. return {
  57611. defaultWidth: defaultWidth,
  57612. monospace: monospace,
  57613. widths: widths
  57614. };
  57615. },
  57616. buildCharCodeToWidth: function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName, properties) {
  57617. var widths = Object.create(null);
  57618. var differences = properties.differences;
  57619. var encoding = properties.defaultEncoding;
  57620. for (var charCode = 0; charCode < 256; charCode++) {
  57621. if (charCode in differences && widthsByGlyphName[differences[charCode]]) {
  57622. widths[charCode] = widthsByGlyphName[differences[charCode]];
  57623. continue;
  57624. }
  57625. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  57626. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  57627. continue;
  57628. }
  57629. }
  57630. return widths;
  57631. },
  57632. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  57633. var baseDict = dict;
  57634. var type = dict.get('Subtype');
  57635. assert(isName(type), 'invalid font Subtype');
  57636. var composite = false;
  57637. var uint8array;
  57638. if (type.name === 'Type0') {
  57639. // If font is a composite
  57640. // - get the descendant font
  57641. // - set the type according to the descendant font
  57642. // - get the FontDescriptor from the descendant font
  57643. var df = dict.get('DescendantFonts');
  57644. if (!df) {
  57645. error('Descendant fonts are not specified');
  57646. }
  57647. dict = isArray(df) ? xref.fetchIfRef(df[0]) : df;
  57648. type = dict.get('Subtype');
  57649. assert(isName(type), 'invalid font Subtype');
  57650. composite = true;
  57651. }
  57652. var descriptor = dict.get('FontDescriptor');
  57653. if (descriptor) {
  57654. var hash = new MurmurHash3_64();
  57655. var encoding = baseDict.getRaw('Encoding');
  57656. if (isName(encoding)) {
  57657. hash.update(encoding.name);
  57658. } else if (isRef(encoding)) {
  57659. hash.update(encoding.toString());
  57660. } else if (isDict(encoding)) {
  57661. var keys = encoding.getKeys();
  57662. for (var i = 0, ii = keys.length; i < ii; i++) {
  57663. var entry = encoding.getRaw(keys[i]);
  57664. if (isName(entry)) {
  57665. hash.update(entry.name);
  57666. } else if (isRef(entry)) {
  57667. hash.update(entry.toString());
  57668. } else if (isArray(entry)) {
  57669. // 'Differences' entry.
  57670. // Ideally we should check the contents of the array, but to avoid
  57671. // parsing it here and then again in |extractDataStructures|,
  57672. // we only use the array length for now (fixes bug1157493.pdf).
  57673. hash.update(entry.length.toString());
  57674. }
  57675. }
  57676. }
  57677. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  57678. if (isStream(toUnicode)) {
  57679. var stream = toUnicode.str || toUnicode;
  57680. uint8array = stream.buffer ? new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) : new Uint8Array(stream.bytes.buffer, stream.start, stream.end - stream.start);
  57681. hash.update(uint8array);
  57682. } else if (isName(toUnicode)) {
  57683. hash.update(toUnicode.name);
  57684. }
  57685. var widths = dict.get('Widths') || baseDict.get('Widths');
  57686. if (widths) {
  57687. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  57688. hash.update(uint8array);
  57689. }
  57690. }
  57691. return {
  57692. descriptor: descriptor,
  57693. dict: dict,
  57694. baseDict: baseDict,
  57695. composite: composite,
  57696. type: type.name,
  57697. hash: hash ? hash.hexdigest() : ''
  57698. };
  57699. },
  57700. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont, xref) {
  57701. var baseDict = preEvaluatedFont.baseDict;
  57702. var dict = preEvaluatedFont.dict;
  57703. var composite = preEvaluatedFont.composite;
  57704. var descriptor = preEvaluatedFont.descriptor;
  57705. var type = preEvaluatedFont.type;
  57706. var maxCharIndex = composite ? 0xFFFF : 0xFF;
  57707. var cMapOptions = this.options.cMapOptions;
  57708. var properties;
  57709. if (!descriptor) {
  57710. if (type === 'Type3') {
  57711. // FontDescriptor is only required for Type3 fonts when the document
  57712. // is a tagged pdf. Create a barbebones one to get by.
  57713. descriptor = new Dict(null);
  57714. descriptor.set('FontName', Name.get(type));
  57715. descriptor.set('FontBBox', dict.getArray('FontBBox'));
  57716. } else {
  57717. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  57718. // FontDescriptor was not required.
  57719. // This case is here for compatibility.
  57720. var baseFontName = dict.get('BaseFont');
  57721. if (!isName(baseFontName)) {
  57722. error('Base font is not specified');
  57723. }
  57724. // Using base font name as a font name.
  57725. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  57726. var metrics = this.getBaseFontMetrics(baseFontName);
  57727. // Simulating descriptor flags attribute
  57728. var fontNameWoStyle = baseFontName.split('-')[0];
  57729. var flags = (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) | (metrics.monospace ? FontFlags.FixedPitch : 0) | (getSymbolsFonts()[fontNameWoStyle] ? FontFlags.Symbolic : FontFlags.Nonsymbolic);
  57730. properties = {
  57731. type: type,
  57732. name: baseFontName,
  57733. widths: metrics.widths,
  57734. defaultWidth: metrics.defaultWidth,
  57735. flags: flags,
  57736. firstChar: 0,
  57737. lastChar: maxCharIndex
  57738. };
  57739. return this.extractDataStructures(dict, dict, xref, properties).then(function (properties) {
  57740. properties.widths = this.buildCharCodeToWidth(metrics.widths, properties);
  57741. return new Font(baseFontName, null, properties);
  57742. }.bind(this));
  57743. }
  57744. }
  57745. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  57746. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  57747. // to ignore this rule when a variant of a standard font is used.
  57748. // TODO Fill the width array depending on which of the base font this is
  57749. // a variant.
  57750. var firstChar = dict.get('FirstChar') || 0;
  57751. var lastChar = dict.get('LastChar') || maxCharIndex;
  57752. var fontName = descriptor.get('FontName');
  57753. var baseFont = dict.get('BaseFont');
  57754. // Some bad PDFs have a string as the font name.
  57755. if (isString(fontName)) {
  57756. fontName = Name.get(fontName);
  57757. }
  57758. if (isString(baseFont)) {
  57759. baseFont = Name.get(baseFont);
  57760. }
  57761. if (type !== 'Type3') {
  57762. var fontNameStr = fontName && fontName.name;
  57763. var baseFontStr = baseFont && baseFont.name;
  57764. if (fontNameStr !== baseFontStr) {
  57765. info('The FontDescriptor\'s FontName is "' + fontNameStr + '" but should be the same as the Font\'s BaseFont "' + baseFontStr + '"');
  57766. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  57767. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  57768. if (fontNameStr && baseFontStr && baseFontStr.indexOf(fontNameStr) === 0) {
  57769. fontName = baseFont;
  57770. }
  57771. }
  57772. }
  57773. fontName = fontName || baseFont;
  57774. assert(isName(fontName), 'invalid font name');
  57775. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  57776. if (fontFile) {
  57777. if (fontFile.dict) {
  57778. var subtype = fontFile.dict.get('Subtype');
  57779. if (subtype) {
  57780. subtype = subtype.name;
  57781. }
  57782. var length1 = fontFile.dict.get('Length1');
  57783. var length2 = fontFile.dict.get('Length2');
  57784. var length3 = fontFile.dict.get('Length3');
  57785. }
  57786. }
  57787. properties = {
  57788. type: type,
  57789. name: fontName.name,
  57790. subtype: subtype,
  57791. file: fontFile,
  57792. length1: length1,
  57793. length2: length2,
  57794. length3: length3,
  57795. loadedName: baseDict.loadedName,
  57796. composite: composite,
  57797. wideChars: composite,
  57798. fixedPitch: false,
  57799. fontMatrix: dict.getArray('FontMatrix') || FONT_IDENTITY_MATRIX,
  57800. firstChar: firstChar || 0,
  57801. lastChar: lastChar || maxCharIndex,
  57802. bbox: descriptor.getArray('FontBBox'),
  57803. ascent: descriptor.get('Ascent'),
  57804. descent: descriptor.get('Descent'),
  57805. xHeight: descriptor.get('XHeight'),
  57806. capHeight: descriptor.get('CapHeight'),
  57807. flags: descriptor.get('Flags'),
  57808. italicAngle: descriptor.get('ItalicAngle'),
  57809. coded: false
  57810. };
  57811. var cMapPromise;
  57812. if (composite) {
  57813. var cidEncoding = baseDict.get('Encoding');
  57814. if (isName(cidEncoding)) {
  57815. properties.cidEncoding = cidEncoding.name;
  57816. }
  57817. cMapPromise = CMapFactory.create(cidEncoding, cMapOptions, null).then(function (cMap) {
  57818. properties.cMap = cMap;
  57819. properties.vertical = properties.cMap.vertical;
  57820. });
  57821. } else {
  57822. cMapPromise = Promise.resolve(undefined);
  57823. }
  57824. return cMapPromise.then(function () {
  57825. return this.extractDataStructures(dict, baseDict, xref, properties);
  57826. }.bind(this)).then(function (properties) {
  57827. this.extractWidths(dict, xref, descriptor, properties);
  57828. if (type === 'Type3') {
  57829. properties.isType3Font = true;
  57830. }
  57831. return new Font(fontName.name, fontFile, properties);
  57832. }.bind(this));
  57833. }
  57834. };
  57835. return PartialEvaluator;
  57836. }();
  57837. var TranslatedFont = function TranslatedFontClosure() {
  57838. function TranslatedFont(loadedName, font, dict) {
  57839. this.loadedName = loadedName;
  57840. this.font = font;
  57841. this.dict = dict;
  57842. this.type3Loaded = null;
  57843. this.sent = false;
  57844. }
  57845. TranslatedFont.prototype = {
  57846. send: function (handler) {
  57847. if (this.sent) {
  57848. return;
  57849. }
  57850. var fontData = this.font.exportData();
  57851. handler.send('commonobj', [
  57852. this.loadedName,
  57853. 'Font',
  57854. fontData
  57855. ]);
  57856. this.sent = true;
  57857. },
  57858. loadType3Data: function (evaluator, resources, parentOperatorList, task) {
  57859. assert(this.font.isType3Font);
  57860. if (this.type3Loaded) {
  57861. return this.type3Loaded;
  57862. }
  57863. var translatedFont = this.font;
  57864. var loadCharProcsPromise = Promise.resolve();
  57865. var charProcs = this.dict.get('CharProcs');
  57866. var fontResources = this.dict.get('Resources') || resources;
  57867. var charProcKeys = charProcs.getKeys();
  57868. var charProcOperatorList = Object.create(null);
  57869. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  57870. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  57871. var glyphStream = charProcs.get(key);
  57872. var operatorList = new OperatorList();
  57873. return evaluator.getOperatorList(glyphStream, task, fontResources, operatorList).then(function () {
  57874. charProcOperatorList[key] = operatorList.getIR();
  57875. // Add the dependencies to the parent operator list so they are
  57876. // resolved before sub operator list is executed synchronously.
  57877. parentOperatorList.addDependencies(operatorList.dependencies);
  57878. }, function (reason) {
  57879. warn('Type3 font resource \"' + key + '\" is not available');
  57880. var operatorList = new OperatorList();
  57881. charProcOperatorList[key] = operatorList.getIR();
  57882. });
  57883. }.bind(this, charProcKeys[i]));
  57884. }
  57885. this.type3Loaded = loadCharProcsPromise.then(function () {
  57886. translatedFont.charProcOperatorList = charProcOperatorList;
  57887. });
  57888. return this.type3Loaded;
  57889. }
  57890. };
  57891. return TranslatedFont;
  57892. }();
  57893. var OperatorList = function OperatorListClosure() {
  57894. var CHUNK_SIZE = 1000;
  57895. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5;
  57896. // close to chunk size
  57897. function getTransfers(queue) {
  57898. var transfers = [];
  57899. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  57900. for (var i = 0, ii = queue.length; i < ii; i++) {
  57901. switch (fnArray[i]) {
  57902. case OPS.paintInlineImageXObject:
  57903. case OPS.paintInlineImageXObjectGroup:
  57904. case OPS.paintImageMaskXObject:
  57905. var arg = argsArray[i][0];
  57906. // first param in imgData
  57907. if (!arg.cached) {
  57908. transfers.push(arg.data.buffer);
  57909. }
  57910. break;
  57911. }
  57912. }
  57913. return transfers;
  57914. }
  57915. function OperatorList(intent, messageHandler, pageIndex) {
  57916. this.messageHandler = messageHandler;
  57917. this.fnArray = [];
  57918. this.argsArray = [];
  57919. this.dependencies = Object.create(null);
  57920. this._totalLength = 0;
  57921. this.pageIndex = pageIndex;
  57922. this.intent = intent;
  57923. }
  57924. OperatorList.prototype = {
  57925. get length() {
  57926. return this.argsArray.length;
  57927. },
  57928. /**
  57929. * @returns {number} The total length of the entire operator list,
  57930. * since `this.length === 0` after flushing.
  57931. */
  57932. get totalLength() {
  57933. return this._totalLength + this.length;
  57934. },
  57935. addOp: function (fn, args) {
  57936. this.fnArray.push(fn);
  57937. this.argsArray.push(args);
  57938. if (this.messageHandler) {
  57939. if (this.fnArray.length >= CHUNK_SIZE) {
  57940. this.flush();
  57941. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT && (fn === OPS.restore || fn === OPS.endText)) {
  57942. // heuristic to flush on boundary of restore or endText
  57943. this.flush();
  57944. }
  57945. }
  57946. },
  57947. addDependency: function (dependency) {
  57948. if (dependency in this.dependencies) {
  57949. return;
  57950. }
  57951. this.dependencies[dependency] = true;
  57952. this.addOp(OPS.dependency, [dependency]);
  57953. },
  57954. addDependencies: function (dependencies) {
  57955. for (var key in dependencies) {
  57956. this.addDependency(key);
  57957. }
  57958. },
  57959. addOpList: function (opList) {
  57960. Util.extendObj(this.dependencies, opList.dependencies);
  57961. for (var i = 0, ii = opList.length; i < ii; i++) {
  57962. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  57963. }
  57964. },
  57965. getIR: function () {
  57966. return {
  57967. fnArray: this.fnArray,
  57968. argsArray: this.argsArray,
  57969. length: this.length
  57970. };
  57971. },
  57972. flush: function (lastChunk) {
  57973. if (this.intent !== 'oplist') {
  57974. new QueueOptimizer().optimize(this);
  57975. }
  57976. var transfers = getTransfers(this);
  57977. var length = this.length;
  57978. this._totalLength += length;
  57979. this.messageHandler.send('RenderPageChunk', {
  57980. operatorList: {
  57981. fnArray: this.fnArray,
  57982. argsArray: this.argsArray,
  57983. lastChunk: lastChunk,
  57984. length: length
  57985. },
  57986. pageIndex: this.pageIndex,
  57987. intent: this.intent
  57988. }, transfers);
  57989. this.dependencies = Object.create(null);
  57990. this.fnArray.length = 0;
  57991. this.argsArray.length = 0;
  57992. }
  57993. };
  57994. return OperatorList;
  57995. }();
  57996. var StateManager = function StateManagerClosure() {
  57997. function StateManager(initialState) {
  57998. this.state = initialState;
  57999. this.stateStack = [];
  58000. }
  58001. StateManager.prototype = {
  58002. save: function () {
  58003. var old = this.state;
  58004. this.stateStack.push(this.state);
  58005. this.state = old.clone();
  58006. },
  58007. restore: function () {
  58008. var prev = this.stateStack.pop();
  58009. if (prev) {
  58010. this.state = prev;
  58011. }
  58012. },
  58013. transform: function (args) {
  58014. this.state.ctm = Util.transform(this.state.ctm, args);
  58015. }
  58016. };
  58017. return StateManager;
  58018. }();
  58019. var TextState = function TextStateClosure() {
  58020. function TextState() {
  58021. this.ctm = new Float32Array(IDENTITY_MATRIX);
  58022. this.fontName = null;
  58023. this.fontSize = 0;
  58024. this.font = null;
  58025. this.fontMatrix = FONT_IDENTITY_MATRIX;
  58026. this.textMatrix = IDENTITY_MATRIX.slice();
  58027. this.textLineMatrix = IDENTITY_MATRIX.slice();
  58028. this.charSpacing = 0;
  58029. this.wordSpacing = 0;
  58030. this.leading = 0;
  58031. this.textHScale = 1;
  58032. this.textRise = 0;
  58033. }
  58034. TextState.prototype = {
  58035. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  58036. var m = this.textMatrix;
  58037. m[0] = a;
  58038. m[1] = b;
  58039. m[2] = c;
  58040. m[3] = d;
  58041. m[4] = e;
  58042. m[5] = f;
  58043. },
  58044. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  58045. var m = this.textLineMatrix;
  58046. m[0] = a;
  58047. m[1] = b;
  58048. m[2] = c;
  58049. m[3] = d;
  58050. m[4] = e;
  58051. m[5] = f;
  58052. },
  58053. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  58054. var m = this.textMatrix;
  58055. m[4] = m[0] * x + m[2] * y + m[4];
  58056. m[5] = m[1] * x + m[3] * y + m[5];
  58057. },
  58058. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  58059. var m = this.textLineMatrix;
  58060. m[4] = m[0] * x + m[2] * y + m[4];
  58061. m[5] = m[1] * x + m[3] * y + m[5];
  58062. },
  58063. calcTextLineMatrixAdvance: function TextState_calcTextLineMatrixAdvance(a, b, c, d, e, f) {
  58064. var font = this.font;
  58065. if (!font) {
  58066. return null;
  58067. }
  58068. var m = this.textLineMatrix;
  58069. if (!(a === m[0] && b === m[1] && c === m[2] && d === m[3])) {
  58070. return null;
  58071. }
  58072. var txDiff = e - m[4], tyDiff = f - m[5];
  58073. if (font.vertical && txDiff !== 0 || !font.vertical && tyDiff !== 0) {
  58074. return null;
  58075. }
  58076. var tx, ty, denominator = a * d - b * c;
  58077. if (font.vertical) {
  58078. tx = -tyDiff * c / denominator;
  58079. ty = tyDiff * a / denominator;
  58080. } else {
  58081. tx = txDiff * d / denominator;
  58082. ty = -txDiff * b / denominator;
  58083. }
  58084. return {
  58085. width: tx,
  58086. height: ty,
  58087. value: font.vertical ? ty : tx
  58088. };
  58089. },
  58090. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  58091. // 9.4.4 Text Space Details
  58092. var tsm = [
  58093. this.fontSize * this.textHScale,
  58094. 0,
  58095. 0,
  58096. this.fontSize,
  58097. 0,
  58098. this.textRise
  58099. ];
  58100. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  58101. },
  58102. carriageReturn: function TextState_carriageReturn() {
  58103. this.translateTextLineMatrix(0, -this.leading);
  58104. this.textMatrix = this.textLineMatrix.slice();
  58105. },
  58106. clone: function TextState_clone() {
  58107. var clone = Object.create(this);
  58108. clone.textMatrix = this.textMatrix.slice();
  58109. clone.textLineMatrix = this.textLineMatrix.slice();
  58110. clone.fontMatrix = this.fontMatrix.slice();
  58111. return clone;
  58112. }
  58113. };
  58114. return TextState;
  58115. }();
  58116. var EvalState = function EvalStateClosure() {
  58117. function EvalState() {
  58118. this.ctm = new Float32Array(IDENTITY_MATRIX);
  58119. this.font = null;
  58120. this.textRenderingMode = TextRenderingMode.FILL;
  58121. this.fillColorSpace = ColorSpace.singletons.gray;
  58122. this.strokeColorSpace = ColorSpace.singletons.gray;
  58123. }
  58124. EvalState.prototype = {
  58125. clone: function CanvasExtraState_clone() {
  58126. return Object.create(this);
  58127. }
  58128. };
  58129. return EvalState;
  58130. }();
  58131. var EvaluatorPreprocessor = function EvaluatorPreprocessorClosure() {
  58132. // Specifies properties for each command
  58133. //
  58134. // If variableArgs === true: [0, `numArgs`] expected
  58135. // If variableArgs === false: exactly `numArgs` expected
  58136. var getOPMap = getLookupTableFactory(function (t) {
  58137. // Graphic state
  58138. t['w'] = {
  58139. id: OPS.setLineWidth,
  58140. numArgs: 1,
  58141. variableArgs: false
  58142. };
  58143. t['J'] = {
  58144. id: OPS.setLineCap,
  58145. numArgs: 1,
  58146. variableArgs: false
  58147. };
  58148. t['j'] = {
  58149. id: OPS.setLineJoin,
  58150. numArgs: 1,
  58151. variableArgs: false
  58152. };
  58153. t['M'] = {
  58154. id: OPS.setMiterLimit,
  58155. numArgs: 1,
  58156. variableArgs: false
  58157. };
  58158. t['d'] = {
  58159. id: OPS.setDash,
  58160. numArgs: 2,
  58161. variableArgs: false
  58162. };
  58163. t['ri'] = {
  58164. id: OPS.setRenderingIntent,
  58165. numArgs: 1,
  58166. variableArgs: false
  58167. };
  58168. t['i'] = {
  58169. id: OPS.setFlatness,
  58170. numArgs: 1,
  58171. variableArgs: false
  58172. };
  58173. t['gs'] = {
  58174. id: OPS.setGState,
  58175. numArgs: 1,
  58176. variableArgs: false
  58177. };
  58178. t['q'] = {
  58179. id: OPS.save,
  58180. numArgs: 0,
  58181. variableArgs: false
  58182. };
  58183. t['Q'] = {
  58184. id: OPS.restore,
  58185. numArgs: 0,
  58186. variableArgs: false
  58187. };
  58188. t['cm'] = {
  58189. id: OPS.transform,
  58190. numArgs: 6,
  58191. variableArgs: false
  58192. };
  58193. // Path
  58194. t['m'] = {
  58195. id: OPS.moveTo,
  58196. numArgs: 2,
  58197. variableArgs: false
  58198. };
  58199. t['l'] = {
  58200. id: OPS.lineTo,
  58201. numArgs: 2,
  58202. variableArgs: false
  58203. };
  58204. t['c'] = {
  58205. id: OPS.curveTo,
  58206. numArgs: 6,
  58207. variableArgs: false
  58208. };
  58209. t['v'] = {
  58210. id: OPS.curveTo2,
  58211. numArgs: 4,
  58212. variableArgs: false
  58213. };
  58214. t['y'] = {
  58215. id: OPS.curveTo3,
  58216. numArgs: 4,
  58217. variableArgs: false
  58218. };
  58219. t['h'] = {
  58220. id: OPS.closePath,
  58221. numArgs: 0,
  58222. variableArgs: false
  58223. };
  58224. t['re'] = {
  58225. id: OPS.rectangle,
  58226. numArgs: 4,
  58227. variableArgs: false
  58228. };
  58229. t['S'] = {
  58230. id: OPS.stroke,
  58231. numArgs: 0,
  58232. variableArgs: false
  58233. };
  58234. t['s'] = {
  58235. id: OPS.closeStroke,
  58236. numArgs: 0,
  58237. variableArgs: false
  58238. };
  58239. t['f'] = {
  58240. id: OPS.fill,
  58241. numArgs: 0,
  58242. variableArgs: false
  58243. };
  58244. t['F'] = {
  58245. id: OPS.fill,
  58246. numArgs: 0,
  58247. variableArgs: false
  58248. };
  58249. t['f*'] = {
  58250. id: OPS.eoFill,
  58251. numArgs: 0,
  58252. variableArgs: false
  58253. };
  58254. t['B'] = {
  58255. id: OPS.fillStroke,
  58256. numArgs: 0,
  58257. variableArgs: false
  58258. };
  58259. t['B*'] = {
  58260. id: OPS.eoFillStroke,
  58261. numArgs: 0,
  58262. variableArgs: false
  58263. };
  58264. t['b'] = {
  58265. id: OPS.closeFillStroke,
  58266. numArgs: 0,
  58267. variableArgs: false
  58268. };
  58269. t['b*'] = {
  58270. id: OPS.closeEOFillStroke,
  58271. numArgs: 0,
  58272. variableArgs: false
  58273. };
  58274. t['n'] = {
  58275. id: OPS.endPath,
  58276. numArgs: 0,
  58277. variableArgs: false
  58278. };
  58279. // Clipping
  58280. t['W'] = {
  58281. id: OPS.clip,
  58282. numArgs: 0,
  58283. variableArgs: false
  58284. };
  58285. t['W*'] = {
  58286. id: OPS.eoClip,
  58287. numArgs: 0,
  58288. variableArgs: false
  58289. };
  58290. // Text
  58291. t['BT'] = {
  58292. id: OPS.beginText,
  58293. numArgs: 0,
  58294. variableArgs: false
  58295. };
  58296. t['ET'] = {
  58297. id: OPS.endText,
  58298. numArgs: 0,
  58299. variableArgs: false
  58300. };
  58301. t['Tc'] = {
  58302. id: OPS.setCharSpacing,
  58303. numArgs: 1,
  58304. variableArgs: false
  58305. };
  58306. t['Tw'] = {
  58307. id: OPS.setWordSpacing,
  58308. numArgs: 1,
  58309. variableArgs: false
  58310. };
  58311. t['Tz'] = {
  58312. id: OPS.setHScale,
  58313. numArgs: 1,
  58314. variableArgs: false
  58315. };
  58316. t['TL'] = {
  58317. id: OPS.setLeading,
  58318. numArgs: 1,
  58319. variableArgs: false
  58320. };
  58321. t['Tf'] = {
  58322. id: OPS.setFont,
  58323. numArgs: 2,
  58324. variableArgs: false
  58325. };
  58326. t['Tr'] = {
  58327. id: OPS.setTextRenderingMode,
  58328. numArgs: 1,
  58329. variableArgs: false
  58330. };
  58331. t['Ts'] = {
  58332. id: OPS.setTextRise,
  58333. numArgs: 1,
  58334. variableArgs: false
  58335. };
  58336. t['Td'] = {
  58337. id: OPS.moveText,
  58338. numArgs: 2,
  58339. variableArgs: false
  58340. };
  58341. t['TD'] = {
  58342. id: OPS.setLeadingMoveText,
  58343. numArgs: 2,
  58344. variableArgs: false
  58345. };
  58346. t['Tm'] = {
  58347. id: OPS.setTextMatrix,
  58348. numArgs: 6,
  58349. variableArgs: false
  58350. };
  58351. t['T*'] = {
  58352. id: OPS.nextLine,
  58353. numArgs: 0,
  58354. variableArgs: false
  58355. };
  58356. t['Tj'] = {
  58357. id: OPS.showText,
  58358. numArgs: 1,
  58359. variableArgs: false
  58360. };
  58361. t['TJ'] = {
  58362. id: OPS.showSpacedText,
  58363. numArgs: 1,
  58364. variableArgs: false
  58365. };
  58366. t['\''] = {
  58367. id: OPS.nextLineShowText,
  58368. numArgs: 1,
  58369. variableArgs: false
  58370. };
  58371. t['"'] = {
  58372. id: OPS.nextLineSetSpacingShowText,
  58373. numArgs: 3,
  58374. variableArgs: false
  58375. };
  58376. // Type3 fonts
  58377. t['d0'] = {
  58378. id: OPS.setCharWidth,
  58379. numArgs: 2,
  58380. variableArgs: false
  58381. };
  58382. t['d1'] = {
  58383. id: OPS.setCharWidthAndBounds,
  58384. numArgs: 6,
  58385. variableArgs: false
  58386. };
  58387. // Color
  58388. t['CS'] = {
  58389. id: OPS.setStrokeColorSpace,
  58390. numArgs: 1,
  58391. variableArgs: false
  58392. };
  58393. t['cs'] = {
  58394. id: OPS.setFillColorSpace,
  58395. numArgs: 1,
  58396. variableArgs: false
  58397. };
  58398. t['SC'] = {
  58399. id: OPS.setStrokeColor,
  58400. numArgs: 4,
  58401. variableArgs: true
  58402. };
  58403. t['SCN'] = {
  58404. id: OPS.setStrokeColorN,
  58405. numArgs: 33,
  58406. variableArgs: true
  58407. };
  58408. t['sc'] = {
  58409. id: OPS.setFillColor,
  58410. numArgs: 4,
  58411. variableArgs: true
  58412. };
  58413. t['scn'] = {
  58414. id: OPS.setFillColorN,
  58415. numArgs: 33,
  58416. variableArgs: true
  58417. };
  58418. t['G'] = {
  58419. id: OPS.setStrokeGray,
  58420. numArgs: 1,
  58421. variableArgs: false
  58422. };
  58423. t['g'] = {
  58424. id: OPS.setFillGray,
  58425. numArgs: 1,
  58426. variableArgs: false
  58427. };
  58428. t['RG'] = {
  58429. id: OPS.setStrokeRGBColor,
  58430. numArgs: 3,
  58431. variableArgs: false
  58432. };
  58433. t['rg'] = {
  58434. id: OPS.setFillRGBColor,
  58435. numArgs: 3,
  58436. variableArgs: false
  58437. };
  58438. t['K'] = {
  58439. id: OPS.setStrokeCMYKColor,
  58440. numArgs: 4,
  58441. variableArgs: false
  58442. };
  58443. t['k'] = {
  58444. id: OPS.setFillCMYKColor,
  58445. numArgs: 4,
  58446. variableArgs: false
  58447. };
  58448. // Shading
  58449. t['sh'] = {
  58450. id: OPS.shadingFill,
  58451. numArgs: 1,
  58452. variableArgs: false
  58453. };
  58454. // Images
  58455. t['BI'] = {
  58456. id: OPS.beginInlineImage,
  58457. numArgs: 0,
  58458. variableArgs: false
  58459. };
  58460. t['ID'] = {
  58461. id: OPS.beginImageData,
  58462. numArgs: 0,
  58463. variableArgs: false
  58464. };
  58465. t['EI'] = {
  58466. id: OPS.endInlineImage,
  58467. numArgs: 1,
  58468. variableArgs: false
  58469. };
  58470. // XObjects
  58471. t['Do'] = {
  58472. id: OPS.paintXObject,
  58473. numArgs: 1,
  58474. variableArgs: false
  58475. };
  58476. t['MP'] = {
  58477. id: OPS.markPoint,
  58478. numArgs: 1,
  58479. variableArgs: false
  58480. };
  58481. t['DP'] = {
  58482. id: OPS.markPointProps,
  58483. numArgs: 2,
  58484. variableArgs: false
  58485. };
  58486. t['BMC'] = {
  58487. id: OPS.beginMarkedContent,
  58488. numArgs: 1,
  58489. variableArgs: false
  58490. };
  58491. t['BDC'] = {
  58492. id: OPS.beginMarkedContentProps,
  58493. numArgs: 2,
  58494. variableArgs: false
  58495. };
  58496. t['EMC'] = {
  58497. id: OPS.endMarkedContent,
  58498. numArgs: 0,
  58499. variableArgs: false
  58500. };
  58501. // Compatibility
  58502. t['BX'] = {
  58503. id: OPS.beginCompat,
  58504. numArgs: 0,
  58505. variableArgs: false
  58506. };
  58507. t['EX'] = {
  58508. id: OPS.endCompat,
  58509. numArgs: 0,
  58510. variableArgs: false
  58511. };
  58512. // (reserved partial commands for the lexer)
  58513. t['BM'] = null;
  58514. t['BD'] = null;
  58515. t['true'] = null;
  58516. t['fa'] = null;
  58517. t['fal'] = null;
  58518. t['fals'] = null;
  58519. t['false'] = null;
  58520. t['nu'] = null;
  58521. t['nul'] = null;
  58522. t['null'] = null;
  58523. });
  58524. function EvaluatorPreprocessor(stream, xref, stateManager) {
  58525. this.opMap = getOPMap();
  58526. // TODO(mduan): pass array of knownCommands rather than this.opMap
  58527. // dictionary
  58528. this.parser = new Parser(new Lexer(stream, this.opMap), false, xref);
  58529. this.stateManager = stateManager;
  58530. this.nonProcessedArgs = [];
  58531. }
  58532. EvaluatorPreprocessor.prototype = {
  58533. get savedStatesDepth() {
  58534. return this.stateManager.stateStack.length;
  58535. },
  58536. // |operation| is an object with two fields:
  58537. //
  58538. // - |fn| is an out param.
  58539. //
  58540. // - |args| is an inout param. On entry, it should have one of two values.
  58541. //
  58542. // - An empty array. This indicates that the caller is providing the
  58543. // array in which the args will be stored in. The caller should use
  58544. // this value if it can reuse a single array for each call to read().
  58545. //
  58546. // - |null|. This indicates that the caller needs this function to create
  58547. // the array in which any args are stored in. If there are zero args,
  58548. // this function will leave |operation.args| as |null| (thus avoiding
  58549. // allocations that would occur if we used an empty array to represent
  58550. // zero arguments). Otherwise, it will replace |null| with a new array
  58551. // containing the arguments. The caller should use this value if it
  58552. // cannot reuse an array for each call to read().
  58553. //
  58554. // These two modes are present because this function is very hot and so
  58555. // avoiding allocations where possible is worthwhile.
  58556. //
  58557. read: function EvaluatorPreprocessor_read(operation) {
  58558. var args = operation.args;
  58559. while (true) {
  58560. var obj = this.parser.getObj();
  58561. if (isCmd(obj)) {
  58562. var cmd = obj.cmd;
  58563. // Check that the command is valid
  58564. var opSpec = this.opMap[cmd];
  58565. if (!opSpec) {
  58566. warn('Unknown command "' + cmd + '"');
  58567. continue;
  58568. }
  58569. var fn = opSpec.id;
  58570. var numArgs = opSpec.numArgs;
  58571. var argsLength = args !== null ? args.length : 0;
  58572. if (!opSpec.variableArgs) {
  58573. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  58574. if (argsLength !== numArgs) {
  58575. var nonProcessedArgs = this.nonProcessedArgs;
  58576. while (argsLength > numArgs) {
  58577. nonProcessedArgs.push(args.shift());
  58578. argsLength--;
  58579. }
  58580. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  58581. if (!args) {
  58582. args = [];
  58583. }
  58584. args.unshift(nonProcessedArgs.pop());
  58585. argsLength++;
  58586. }
  58587. }
  58588. if (argsLength < numArgs) {
  58589. // If we receive too few args, it's not possible to possible
  58590. // to execute the command, so skip the command
  58591. info('Command ' + fn + ': because expected ' + numArgs + ' args, but received ' + argsLength + ' args; skipping');
  58592. args = null;
  58593. continue;
  58594. }
  58595. } else if (argsLength > numArgs) {
  58596. info('Command ' + fn + ': expected [0,' + numArgs + '] args, but received ' + argsLength + ' args');
  58597. }
  58598. // TODO figure out how to type-check vararg functions
  58599. this.preprocessCommand(fn, args);
  58600. operation.fn = fn;
  58601. operation.args = args;
  58602. return true;
  58603. } else {
  58604. if (isEOF(obj)) {
  58605. return false;
  58606. }
  58607. // no more commands
  58608. // argument
  58609. if (obj !== null) {
  58610. if (!args) {
  58611. args = [];
  58612. }
  58613. args.push(obj);
  58614. assert(args.length <= 33, 'Too many arguments');
  58615. }
  58616. }
  58617. }
  58618. },
  58619. preprocessCommand: function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  58620. switch (fn | 0) {
  58621. case OPS.save:
  58622. this.stateManager.save();
  58623. break;
  58624. case OPS.restore:
  58625. this.stateManager.restore();
  58626. break;
  58627. case OPS.transform:
  58628. this.stateManager.transform(args);
  58629. break;
  58630. }
  58631. }
  58632. };
  58633. return EvaluatorPreprocessor;
  58634. }();
  58635. var QueueOptimizer = function QueueOptimizerClosure() {
  58636. function addState(parentState, pattern, fn) {
  58637. var state = parentState;
  58638. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  58639. var item = pattern[i];
  58640. state = state[item] || (state[item] = []);
  58641. }
  58642. state[pattern[pattern.length - 1]] = fn;
  58643. }
  58644. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray, argsArray) {
  58645. // Handles special case of mainly LaTeX documents which use image masks to
  58646. // draw lines with the current fill style.
  58647. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  58648. // have been found at iFirstSave.
  58649. var iFirstPIMXO = iFirstSave + 2;
  58650. for (var i = 0; i < count; i++) {
  58651. var arg = argsArray[iFirstPIMXO + 4 * i];
  58652. var imageMask = arg.length === 1 && arg[0];
  58653. if (imageMask && imageMask.width === 1 && imageMask.height === 1 && (!imageMask.data.length || imageMask.data.length === 1 && imageMask.data[0] === 0)) {
  58654. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  58655. continue;
  58656. }
  58657. break;
  58658. }
  58659. return count - i;
  58660. }
  58661. var InitialState = [];
  58662. // This replaces (save, transform, paintInlineImageXObject, restore)+
  58663. // sequences with one |paintInlineImageXObjectGroup| operation.
  58664. addState(InitialState, [
  58665. OPS.save,
  58666. OPS.transform,
  58667. OPS.paintInlineImageXObject,
  58668. OPS.restore
  58669. ], function foundInlineImageGroup(context) {
  58670. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  58671. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  58672. var MAX_WIDTH = 1000;
  58673. var IMAGE_PADDING = 1;
  58674. var fnArray = context.fnArray, argsArray = context.argsArray;
  58675. var curr = context.iCurr;
  58676. var iFirstSave = curr - 3;
  58677. var iFirstTransform = curr - 2;
  58678. var iFirstPIIXO = curr - 1;
  58679. // Look for the quartets.
  58680. var i = iFirstSave + 4;
  58681. var ii = fnArray.length;
  58682. while (i + 3 < ii) {
  58683. if (fnArray[i] !== OPS.save || fnArray[i + 1] !== OPS.transform || fnArray[i + 2] !== OPS.paintInlineImageXObject || fnArray[i + 3] !== OPS.restore) {
  58684. break;
  58685. }
  58686. // ops don't match
  58687. i += 4;
  58688. }
  58689. // At this point, i is the index of the first op past the last valid
  58690. // quartet.
  58691. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  58692. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  58693. return i;
  58694. }
  58695. // assuming that heights of those image is too small (~1 pixel)
  58696. // packing as much as possible by lines
  58697. var maxX = 0;
  58698. var map = [], maxLineHeight = 0;
  58699. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  58700. var q;
  58701. for (q = 0; q < count; q++) {
  58702. var transform = argsArray[iFirstTransform + (q << 2)];
  58703. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  58704. if (currentX + img.width > MAX_WIDTH) {
  58705. // starting new line
  58706. maxX = Math.max(maxX, currentX);
  58707. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  58708. currentX = 0;
  58709. maxLineHeight = 0;
  58710. }
  58711. map.push({
  58712. transform: transform,
  58713. x: currentX,
  58714. y: currentY,
  58715. w: img.width,
  58716. h: img.height
  58717. });
  58718. currentX += img.width + 2 * IMAGE_PADDING;
  58719. maxLineHeight = Math.max(maxLineHeight, img.height);
  58720. }
  58721. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  58722. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  58723. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  58724. var imgRowSize = imgWidth << 2;
  58725. for (q = 0; q < count; q++) {
  58726. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  58727. // Copy image by lines and extends pixels into padding.
  58728. var rowSize = map[q].w << 2;
  58729. var dataOffset = 0;
  58730. var offset = map[q].x + map[q].y * imgWidth << 2;
  58731. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  58732. for (var k = 0, kk = map[q].h; k < kk; k++) {
  58733. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  58734. dataOffset += rowSize;
  58735. offset += imgRowSize;
  58736. }
  58737. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  58738. while (offset >= 0) {
  58739. data[offset - 4] = data[offset];
  58740. data[offset - 3] = data[offset + 1];
  58741. data[offset - 2] = data[offset + 2];
  58742. data[offset - 1] = data[offset + 3];
  58743. data[offset + rowSize] = data[offset + rowSize - 4];
  58744. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  58745. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  58746. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  58747. offset -= imgRowSize;
  58748. }
  58749. }
  58750. // Replace queue items.
  58751. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  58752. argsArray.splice(iFirstSave, count * 4, [
  58753. {
  58754. width: imgWidth,
  58755. height: imgHeight,
  58756. kind: ImageKind.RGBA_32BPP,
  58757. data: imgData
  58758. },
  58759. map
  58760. ]);
  58761. return iFirstSave + 1;
  58762. });
  58763. // This replaces (save, transform, paintImageMaskXObject, restore)+
  58764. // sequences with one |paintImageMaskXObjectGroup| or one
  58765. // |paintImageMaskXObjectRepeat| operation.
  58766. addState(InitialState, [
  58767. OPS.save,
  58768. OPS.transform,
  58769. OPS.paintImageMaskXObject,
  58770. OPS.restore
  58771. ], function foundImageMaskGroup(context) {
  58772. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  58773. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  58774. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  58775. var fnArray = context.fnArray, argsArray = context.argsArray;
  58776. var curr = context.iCurr;
  58777. var iFirstSave = curr - 3;
  58778. var iFirstTransform = curr - 2;
  58779. var iFirstPIMXO = curr - 1;
  58780. // Look for the quartets.
  58781. var i = iFirstSave + 4;
  58782. var ii = fnArray.length;
  58783. while (i + 3 < ii) {
  58784. if (fnArray[i] !== OPS.save || fnArray[i + 1] !== OPS.transform || fnArray[i + 2] !== OPS.paintImageMaskXObject || fnArray[i + 3] !== OPS.restore) {
  58785. break;
  58786. }
  58787. // ops don't match
  58788. i += 4;
  58789. }
  58790. // At this point, i is the index of the first op past the last valid
  58791. // quartet.
  58792. var count = (i - iFirstSave) / 4;
  58793. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray, argsArray);
  58794. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  58795. return i;
  58796. }
  58797. var q;
  58798. var isSameImage = false;
  58799. var iTransform, transformArgs;
  58800. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  58801. if (argsArray[iFirstTransform][1] === 0 && argsArray[iFirstTransform][2] === 0) {
  58802. isSameImage = true;
  58803. var firstTransformArg0 = argsArray[iFirstTransform][0];
  58804. var firstTransformArg3 = argsArray[iFirstTransform][3];
  58805. iTransform = iFirstTransform + 4;
  58806. var iPIMXO = iFirstPIMXO + 4;
  58807. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  58808. transformArgs = argsArray[iTransform];
  58809. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 || transformArgs[0] !== firstTransformArg0 || transformArgs[1] !== 0 || transformArgs[2] !== 0 || transformArgs[3] !== firstTransformArg3) {
  58810. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  58811. isSameImage = false;
  58812. } else {
  58813. count = q;
  58814. }
  58815. break;
  58816. }
  58817. }
  58818. }
  58819. // different image or transform
  58820. if (isSameImage) {
  58821. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  58822. var positions = new Float32Array(count * 2);
  58823. iTransform = iFirstTransform;
  58824. for (q = 0; q < count; q++, iTransform += 4) {
  58825. transformArgs = argsArray[iTransform];
  58826. positions[q << 1] = transformArgs[4];
  58827. positions[(q << 1) + 1] = transformArgs[5];
  58828. }
  58829. // Replace queue items.
  58830. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  58831. argsArray.splice(iFirstSave, count * 4, [
  58832. firstPIMXOArg0,
  58833. firstTransformArg0,
  58834. firstTransformArg3,
  58835. positions
  58836. ]);
  58837. } else {
  58838. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  58839. var images = [];
  58840. for (q = 0; q < count; q++) {
  58841. transformArgs = argsArray[iFirstTransform + (q << 2)];
  58842. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  58843. images.push({
  58844. data: maskParams.data,
  58845. width: maskParams.width,
  58846. height: maskParams.height,
  58847. transform: transformArgs
  58848. });
  58849. }
  58850. // Replace queue items.
  58851. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  58852. argsArray.splice(iFirstSave, count * 4, [images]);
  58853. }
  58854. return iFirstSave + 1;
  58855. });
  58856. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  58857. // with one paintImageXObjectRepeat operation, if the |transform| and
  58858. // |paintImageXObjectRepeat| ops are appropriate.
  58859. addState(InitialState, [
  58860. OPS.save,
  58861. OPS.transform,
  58862. OPS.paintImageXObject,
  58863. OPS.restore
  58864. ], function (context) {
  58865. var MIN_IMAGES_IN_BLOCK = 3;
  58866. var MAX_IMAGES_IN_BLOCK = 1000;
  58867. var fnArray = context.fnArray, argsArray = context.argsArray;
  58868. var curr = context.iCurr;
  58869. var iFirstSave = curr - 3;
  58870. var iFirstTransform = curr - 2;
  58871. var iFirstPIXO = curr - 1;
  58872. var iFirstRestore = curr;
  58873. if (argsArray[iFirstTransform][1] !== 0 || argsArray[iFirstTransform][2] !== 0) {
  58874. return iFirstRestore + 1;
  58875. }
  58876. // transform has the wrong form
  58877. // Look for the quartets.
  58878. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  58879. var firstTransformArg0 = argsArray[iFirstTransform][0];
  58880. var firstTransformArg3 = argsArray[iFirstTransform][3];
  58881. var i = iFirstSave + 4;
  58882. var ii = fnArray.length;
  58883. while (i + 3 < ii) {
  58884. if (fnArray[i] !== OPS.save || fnArray[i + 1] !== OPS.transform || fnArray[i + 2] !== OPS.paintImageXObject || fnArray[i + 3] !== OPS.restore) {
  58885. break;
  58886. }
  58887. // ops don't match
  58888. if (argsArray[i + 1][0] !== firstTransformArg0 || argsArray[i + 1][1] !== 0 || argsArray[i + 1][2] !== 0 || argsArray[i + 1][3] !== firstTransformArg3) {
  58889. break;
  58890. }
  58891. // transforms don't match
  58892. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  58893. break;
  58894. }
  58895. // images don't match
  58896. i += 4;
  58897. }
  58898. // At this point, i is the index of the first op past the last valid
  58899. // quartet.
  58900. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  58901. if (count < MIN_IMAGES_IN_BLOCK) {
  58902. return i;
  58903. }
  58904. // Extract the (x,y) positions from all of the matching transforms.
  58905. var positions = new Float32Array(count * 2);
  58906. var iTransform = iFirstTransform;
  58907. for (var q = 0; q < count; q++, iTransform += 4) {
  58908. var transformArgs = argsArray[iTransform];
  58909. positions[q << 1] = transformArgs[4];
  58910. positions[(q << 1) + 1] = transformArgs[5];
  58911. }
  58912. // Replace queue items.
  58913. var args = [
  58914. firstPIXOArg0,
  58915. firstTransformArg0,
  58916. firstTransformArg3,
  58917. positions
  58918. ];
  58919. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  58920. argsArray.splice(iFirstSave, count * 4, args);
  58921. return iFirstSave + 1;
  58922. });
  58923. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  58924. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  58925. // sequences, if the font for each one is the same.
  58926. addState(InitialState, [
  58927. OPS.beginText,
  58928. OPS.setFont,
  58929. OPS.setTextMatrix,
  58930. OPS.showText,
  58931. OPS.endText
  58932. ], function (context) {
  58933. var MIN_CHARS_IN_BLOCK = 3;
  58934. var MAX_CHARS_IN_BLOCK = 1000;
  58935. var fnArray = context.fnArray, argsArray = context.argsArray;
  58936. var curr = context.iCurr;
  58937. var iFirstBeginText = curr - 4;
  58938. var iFirstSetFont = curr - 3;
  58939. var iFirstSetTextMatrix = curr - 2;
  58940. var iFirstShowText = curr - 1;
  58941. var iFirstEndText = curr;
  58942. // Look for the quintets.
  58943. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  58944. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  58945. var i = iFirstBeginText + 5;
  58946. var ii = fnArray.length;
  58947. while (i + 4 < ii) {
  58948. 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) {
  58949. break;
  58950. }
  58951. // ops don't match
  58952. if (argsArray[i + 1][0] !== firstSetFontArg0 || argsArray[i + 1][1] !== firstSetFontArg1) {
  58953. break;
  58954. }
  58955. // fonts don't match
  58956. i += 5;
  58957. }
  58958. // At this point, i is the index of the first op past the last valid
  58959. // quintet.
  58960. var count = Math.min((i - iFirstBeginText) / 5, MAX_CHARS_IN_BLOCK);
  58961. if (count < MIN_CHARS_IN_BLOCK) {
  58962. return i;
  58963. }
  58964. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  58965. // showText, endText), include that as well. (E.g. <something> might be
  58966. // |dependency|.)
  58967. var iFirst = iFirstBeginText;
  58968. 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) {
  58969. count++;
  58970. iFirst -= 5;
  58971. }
  58972. // Remove (endText, beginText, setFont) trios.
  58973. var iEndText = iFirst + 4;
  58974. for (var q = 1; q < count; q++) {
  58975. fnArray.splice(iEndText, 3);
  58976. argsArray.splice(iEndText, 3);
  58977. iEndText += 2;
  58978. }
  58979. return iEndText + 1;
  58980. });
  58981. function QueueOptimizer() {
  58982. }
  58983. QueueOptimizer.prototype = {
  58984. optimize: function QueueOptimizer_optimize(queue) {
  58985. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  58986. var context = {
  58987. iCurr: 0,
  58988. fnArray: fnArray,
  58989. argsArray: argsArray
  58990. };
  58991. var state;
  58992. var i = 0, ii = fnArray.length;
  58993. while (i < ii) {
  58994. state = (state || InitialState)[fnArray[i]];
  58995. if (typeof state === 'function') {
  58996. // we found some handler
  58997. context.iCurr = i;
  58998. // state() returns the index of the first non-matching op (if we
  58999. // didn't match) or the first op past the modified ops (if we did
  59000. // match and replace).
  59001. i = state(context);
  59002. state = undefined;
  59003. // reset the state machine
  59004. ii = context.fnArray.length;
  59005. } else {
  59006. i++;
  59007. }
  59008. }
  59009. }
  59010. };
  59011. return QueueOptimizer;
  59012. }();
  59013. exports.OperatorList = OperatorList;
  59014. exports.PartialEvaluator = PartialEvaluator;
  59015. }));
  59016. (function (root, factory) {
  59017. factory(root.pdfjsCoreAnnotation = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreColorSpace, root.pdfjsCoreObj, root.pdfjsCoreEvaluator);
  59018. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreColorSpace, coreObj, coreEvaluator) {
  59019. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  59020. var AnnotationFieldFlag = sharedUtil.AnnotationFieldFlag;
  59021. var AnnotationFlag = sharedUtil.AnnotationFlag;
  59022. var AnnotationType = sharedUtil.AnnotationType;
  59023. var OPS = sharedUtil.OPS;
  59024. var Util = sharedUtil.Util;
  59025. var isString = sharedUtil.isString;
  59026. var isArray = sharedUtil.isArray;
  59027. var isInt = sharedUtil.isInt;
  59028. var stringToBytes = sharedUtil.stringToBytes;
  59029. var stringToPDFString = sharedUtil.stringToPDFString;
  59030. var warn = sharedUtil.warn;
  59031. var Dict = corePrimitives.Dict;
  59032. var isDict = corePrimitives.isDict;
  59033. var isName = corePrimitives.isName;
  59034. var isRef = corePrimitives.isRef;
  59035. var Stream = coreStream.Stream;
  59036. var ColorSpace = coreColorSpace.ColorSpace;
  59037. var Catalog = coreObj.Catalog;
  59038. var ObjectLoader = coreObj.ObjectLoader;
  59039. var FileSpec = coreObj.FileSpec;
  59040. var OperatorList = coreEvaluator.OperatorList;
  59041. /**
  59042. * @class
  59043. * @alias AnnotationFactory
  59044. */
  59045. function AnnotationFactory() {
  59046. }
  59047. AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */
  59048. {
  59049. /**
  59050. * @param {XRef} xref
  59051. * @param {Object} ref
  59052. * @param {PDFManager} pdfManager
  59053. * @param {string} uniquePrefix
  59054. * @param {Object} idCounters
  59055. * @returns {Annotation}
  59056. */
  59057. create: function AnnotationFactory_create(xref, ref, pdfManager, uniquePrefix, idCounters) {
  59058. var dict = xref.fetchIfRef(ref);
  59059. if (!isDict(dict)) {
  59060. return;
  59061. }
  59062. var id = isRef(ref) ? ref.toString() : 'annot_' + (uniquePrefix || '') + ++idCounters.obj;
  59063. // Determine the annotation's subtype.
  59064. var subtype = dict.get('Subtype');
  59065. subtype = isName(subtype) ? subtype.name : null;
  59066. // Return the right annotation object based on the subtype and field type.
  59067. var parameters = {
  59068. xref: xref,
  59069. dict: dict,
  59070. ref: isRef(ref) ? ref : null,
  59071. subtype: subtype,
  59072. id: id,
  59073. pdfManager: pdfManager
  59074. };
  59075. switch (subtype) {
  59076. case 'Link':
  59077. return new LinkAnnotation(parameters);
  59078. case 'Text':
  59079. return new TextAnnotation(parameters);
  59080. case 'Widget':
  59081. var fieldType = Util.getInheritableProperty(dict, 'FT');
  59082. fieldType = isName(fieldType) ? fieldType.name : null;
  59083. switch (fieldType) {
  59084. case 'Tx':
  59085. return new TextWidgetAnnotation(parameters);
  59086. case 'Ch':
  59087. return new ChoiceWidgetAnnotation(parameters);
  59088. }
  59089. warn('Unimplemented widget field type "' + fieldType + '", ' + 'falling back to base field type.');
  59090. return new WidgetAnnotation(parameters);
  59091. case 'Popup':
  59092. return new PopupAnnotation(parameters);
  59093. case 'Highlight':
  59094. return new HighlightAnnotation(parameters);
  59095. case 'Underline':
  59096. return new UnderlineAnnotation(parameters);
  59097. case 'Squiggly':
  59098. return new SquigglyAnnotation(parameters);
  59099. case 'StrikeOut':
  59100. return new StrikeOutAnnotation(parameters);
  59101. case 'FileAttachment':
  59102. return new FileAttachmentAnnotation(parameters);
  59103. default:
  59104. if (!subtype) {
  59105. warn('Annotation is missing the required /Subtype.');
  59106. } else {
  59107. warn('Unimplemented annotation type "' + subtype + '", ' + 'falling back to base annotation.');
  59108. }
  59109. return new Annotation(parameters);
  59110. }
  59111. }
  59112. };
  59113. var Annotation = function AnnotationClosure() {
  59114. // 12.5.5: Algorithm: Appearance streams
  59115. function getTransformMatrix(rect, bbox, matrix) {
  59116. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  59117. var minX = bounds[0];
  59118. var minY = bounds[1];
  59119. var maxX = bounds[2];
  59120. var maxY = bounds[3];
  59121. if (minX === maxX || minY === maxY) {
  59122. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  59123. // just apply the transform for rect
  59124. return [
  59125. 1,
  59126. 0,
  59127. 0,
  59128. 1,
  59129. rect[0],
  59130. rect[1]
  59131. ];
  59132. }
  59133. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  59134. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  59135. return [
  59136. xRatio,
  59137. 0,
  59138. 0,
  59139. yRatio,
  59140. rect[0] - minX * xRatio,
  59141. rect[1] - minY * yRatio
  59142. ];
  59143. }
  59144. function getDefaultAppearance(dict) {
  59145. var appearanceState = dict.get('AP');
  59146. if (!isDict(appearanceState)) {
  59147. return;
  59148. }
  59149. var appearance;
  59150. var appearances = appearanceState.get('N');
  59151. if (isDict(appearances)) {
  59152. var as = dict.get('AS');
  59153. if (as && appearances.has(as.name)) {
  59154. appearance = appearances.get(as.name);
  59155. }
  59156. } else {
  59157. appearance = appearances;
  59158. }
  59159. return appearance;
  59160. }
  59161. function Annotation(params) {
  59162. var dict = params.dict;
  59163. this.setFlags(dict.get('F'));
  59164. this.setRectangle(dict.getArray('Rect'));
  59165. this.setColor(dict.getArray('C'));
  59166. this.setBorderStyle(dict);
  59167. this.appearance = getDefaultAppearance(dict);
  59168. // Expose public properties using a data object.
  59169. this.data = {};
  59170. this.data.id = params.id;
  59171. this.data.subtype = params.subtype;
  59172. this.data.annotationFlags = this.flags;
  59173. this.data.rect = this.rectangle;
  59174. this.data.color = this.color;
  59175. this.data.borderStyle = this.borderStyle;
  59176. this.data.hasAppearance = !!this.appearance;
  59177. }
  59178. Annotation.prototype = {
  59179. /**
  59180. * @private
  59181. */
  59182. _hasFlag: function Annotation_hasFlag(flags, flag) {
  59183. return !!(flags & flag);
  59184. },
  59185. /**
  59186. * @private
  59187. */
  59188. _isViewable: function Annotation_isViewable(flags) {
  59189. return !this._hasFlag(flags, AnnotationFlag.INVISIBLE) && !this._hasFlag(flags, AnnotationFlag.HIDDEN) && !this._hasFlag(flags, AnnotationFlag.NOVIEW);
  59190. },
  59191. /**
  59192. * @private
  59193. */
  59194. _isPrintable: function AnnotationFlag_isPrintable(flags) {
  59195. return this._hasFlag(flags, AnnotationFlag.PRINT) && !this._hasFlag(flags, AnnotationFlag.INVISIBLE) && !this._hasFlag(flags, AnnotationFlag.HIDDEN);
  59196. },
  59197. /**
  59198. * @return {boolean}
  59199. */
  59200. get viewable() {
  59201. if (this.flags === 0) {
  59202. return true;
  59203. }
  59204. return this._isViewable(this.flags);
  59205. },
  59206. /**
  59207. * @return {boolean}
  59208. */
  59209. get printable() {
  59210. if (this.flags === 0) {
  59211. return false;
  59212. }
  59213. return this._isPrintable(this.flags);
  59214. },
  59215. /**
  59216. * Set the flags.
  59217. *
  59218. * @public
  59219. * @memberof Annotation
  59220. * @param {number} flags - Unsigned 32-bit integer specifying annotation
  59221. * characteristics
  59222. * @see {@link shared/util.js}
  59223. */
  59224. setFlags: function Annotation_setFlags(flags) {
  59225. this.flags = isInt(flags) && flags > 0 ? flags : 0;
  59226. },
  59227. /**
  59228. * Check if a provided flag is set.
  59229. *
  59230. * @public
  59231. * @memberof Annotation
  59232. * @param {number} flag - Hexadecimal representation for an annotation
  59233. * characteristic
  59234. * @return {boolean}
  59235. * @see {@link shared/util.js}
  59236. */
  59237. hasFlag: function Annotation_hasFlag(flag) {
  59238. return this._hasFlag(this.flags, flag);
  59239. },
  59240. /**
  59241. * Set the rectangle.
  59242. *
  59243. * @public
  59244. * @memberof Annotation
  59245. * @param {Array} rectangle - The rectangle array with exactly four entries
  59246. */
  59247. setRectangle: function Annotation_setRectangle(rectangle) {
  59248. if (isArray(rectangle) && rectangle.length === 4) {
  59249. this.rectangle = Util.normalizeRect(rectangle);
  59250. } else {
  59251. this.rectangle = [
  59252. 0,
  59253. 0,
  59254. 0,
  59255. 0
  59256. ];
  59257. }
  59258. },
  59259. /**
  59260. * Set the color and take care of color space conversion.
  59261. *
  59262. * @public
  59263. * @memberof Annotation
  59264. * @param {Array} color - The color array containing either 0
  59265. * (transparent), 1 (grayscale), 3 (RGB) or
  59266. * 4 (CMYK) elements
  59267. */
  59268. setColor: function Annotation_setColor(color) {
  59269. var rgbColor = new Uint8Array(3);
  59270. // Black in RGB color space (default)
  59271. if (!isArray(color)) {
  59272. this.color = rgbColor;
  59273. return;
  59274. }
  59275. switch (color.length) {
  59276. case 0:
  59277. // Transparent, which we indicate with a null value
  59278. this.color = null;
  59279. break;
  59280. case 1:
  59281. // Convert grayscale to RGB
  59282. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  59283. this.color = rgbColor;
  59284. break;
  59285. case 3:
  59286. // Convert RGB percentages to RGB
  59287. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  59288. this.color = rgbColor;
  59289. break;
  59290. case 4:
  59291. // Convert CMYK to RGB
  59292. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  59293. this.color = rgbColor;
  59294. break;
  59295. default:
  59296. this.color = rgbColor;
  59297. break;
  59298. }
  59299. },
  59300. /**
  59301. * Set the border style (as AnnotationBorderStyle object).
  59302. *
  59303. * @public
  59304. * @memberof Annotation
  59305. * @param {Dict} borderStyle - The border style dictionary
  59306. */
  59307. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  59308. this.borderStyle = new AnnotationBorderStyle();
  59309. if (!isDict(borderStyle)) {
  59310. return;
  59311. }
  59312. if (borderStyle.has('BS')) {
  59313. var dict = borderStyle.get('BS');
  59314. var dictType = dict.get('Type');
  59315. if (!dictType || isName(dictType, 'Border')) {
  59316. this.borderStyle.setWidth(dict.get('W'));
  59317. this.borderStyle.setStyle(dict.get('S'));
  59318. this.borderStyle.setDashArray(dict.getArray('D'));
  59319. }
  59320. } else if (borderStyle.has('Border')) {
  59321. var array = borderStyle.getArray('Border');
  59322. if (isArray(array) && array.length >= 3) {
  59323. this.borderStyle.setHorizontalCornerRadius(array[0]);
  59324. this.borderStyle.setVerticalCornerRadius(array[1]);
  59325. this.borderStyle.setWidth(array[2]);
  59326. if (array.length === 4) {
  59327. // Dash array available
  59328. this.borderStyle.setDashArray(array[3]);
  59329. }
  59330. }
  59331. } else {
  59332. // There are no border entries in the dictionary. According to the
  59333. // specification, we should draw a solid border of width 1 in that
  59334. // case, but Adobe Reader did not implement that part of the
  59335. // specification and instead draws no border at all, so we do the same.
  59336. // See also https://github.com/mozilla/pdf.js/issues/6179.
  59337. this.borderStyle.setWidth(0);
  59338. }
  59339. },
  59340. /**
  59341. * Prepare the annotation for working with a popup in the display layer.
  59342. *
  59343. * @private
  59344. * @memberof Annotation
  59345. * @param {Dict} dict - The annotation's data dictionary
  59346. */
  59347. _preparePopup: function Annotation_preparePopup(dict) {
  59348. if (!dict.has('C')) {
  59349. // Fall back to the default background color.
  59350. this.data.color = null;
  59351. }
  59352. this.data.hasPopup = dict.has('Popup');
  59353. this.data.title = stringToPDFString(dict.get('T') || '');
  59354. this.data.contents = stringToPDFString(dict.get('Contents') || '');
  59355. },
  59356. loadResources: function Annotation_loadResources(keys) {
  59357. return new Promise(function (resolve, reject) {
  59358. this.appearance.dict.getAsync('Resources').then(function (resources) {
  59359. if (!resources) {
  59360. resolve();
  59361. return;
  59362. }
  59363. var objectLoader = new ObjectLoader(resources.map, keys, resources.xref);
  59364. objectLoader.load().then(function () {
  59365. resolve(resources);
  59366. }, reject);
  59367. }, reject);
  59368. }.bind(this));
  59369. },
  59370. getOperatorList: function Annotation_getOperatorList(evaluator, task, renderForms) {
  59371. if (!this.appearance) {
  59372. return Promise.resolve(new OperatorList());
  59373. }
  59374. var data = this.data;
  59375. var appearanceDict = this.appearance.dict;
  59376. var resourcesPromise = this.loadResources([
  59377. 'ExtGState',
  59378. 'ColorSpace',
  59379. 'Pattern',
  59380. 'Shading',
  59381. 'XObject',
  59382. 'Font'
  59383. ]);
  59384. // ProcSet
  59385. // Properties
  59386. var bbox = appearanceDict.getArray('BBox') || [
  59387. 0,
  59388. 0,
  59389. 1,
  59390. 1
  59391. ];
  59392. var matrix = appearanceDict.getArray('Matrix') || [
  59393. 1,
  59394. 0,
  59395. 0,
  59396. 1,
  59397. 0,
  59398. 0
  59399. ];
  59400. var transform = getTransformMatrix(data.rect, bbox, matrix);
  59401. var self = this;
  59402. return resourcesPromise.then(function (resources) {
  59403. var opList = new OperatorList();
  59404. opList.addOp(OPS.beginAnnotation, [
  59405. data.rect,
  59406. transform,
  59407. matrix
  59408. ]);
  59409. return evaluator.getOperatorList(self.appearance, task, resources, opList).then(function () {
  59410. opList.addOp(OPS.endAnnotation, []);
  59411. self.appearance.reset();
  59412. return opList;
  59413. });
  59414. });
  59415. }
  59416. };
  59417. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(annotations, opList, partialEvaluator, task, intent, renderForms) {
  59418. var annotationPromises = [];
  59419. for (var i = 0, n = annotations.length; i < n; ++i) {
  59420. if (intent === 'display' && annotations[i].viewable || intent === 'print' && annotations[i].printable) {
  59421. annotationPromises.push(annotations[i].getOperatorList(partialEvaluator, task, renderForms));
  59422. }
  59423. }
  59424. return Promise.all(annotationPromises).then(function (operatorLists) {
  59425. opList.addOp(OPS.beginAnnotations, []);
  59426. for (var i = 0, n = operatorLists.length; i < n; ++i) {
  59427. opList.addOpList(operatorLists[i]);
  59428. }
  59429. opList.addOp(OPS.endAnnotations, []);
  59430. });
  59431. };
  59432. return Annotation;
  59433. }();
  59434. /**
  59435. * Contains all data regarding an annotation's border style.
  59436. *
  59437. * @class
  59438. */
  59439. var AnnotationBorderStyle = function AnnotationBorderStyleClosure() {
  59440. /**
  59441. * @constructor
  59442. * @private
  59443. */
  59444. function AnnotationBorderStyle() {
  59445. this.width = 1;
  59446. this.style = AnnotationBorderStyleType.SOLID;
  59447. this.dashArray = [3];
  59448. this.horizontalCornerRadius = 0;
  59449. this.verticalCornerRadius = 0;
  59450. }
  59451. AnnotationBorderStyle.prototype = {
  59452. /**
  59453. * Set the width.
  59454. *
  59455. * @public
  59456. * @memberof AnnotationBorderStyle
  59457. * @param {integer} width - The width
  59458. */
  59459. setWidth: function AnnotationBorderStyle_setWidth(width) {
  59460. if (width === (width | 0)) {
  59461. this.width = width;
  59462. }
  59463. },
  59464. /**
  59465. * Set the style.
  59466. *
  59467. * @public
  59468. * @memberof AnnotationBorderStyle
  59469. * @param {Object} style - The style object
  59470. * @see {@link shared/util.js}
  59471. */
  59472. setStyle: function AnnotationBorderStyle_setStyle(style) {
  59473. if (!style) {
  59474. return;
  59475. }
  59476. switch (style.name) {
  59477. case 'S':
  59478. this.style = AnnotationBorderStyleType.SOLID;
  59479. break;
  59480. case 'D':
  59481. this.style = AnnotationBorderStyleType.DASHED;
  59482. break;
  59483. case 'B':
  59484. this.style = AnnotationBorderStyleType.BEVELED;
  59485. break;
  59486. case 'I':
  59487. this.style = AnnotationBorderStyleType.INSET;
  59488. break;
  59489. case 'U':
  59490. this.style = AnnotationBorderStyleType.UNDERLINE;
  59491. break;
  59492. default:
  59493. break;
  59494. }
  59495. },
  59496. /**
  59497. * Set the dash array.
  59498. *
  59499. * @public
  59500. * @memberof AnnotationBorderStyle
  59501. * @param {Array} dashArray - The dash array with at least one element
  59502. */
  59503. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  59504. // We validate the dash array, but we do not use it because CSS does not
  59505. // allow us to change spacing of dashes. For more information, visit
  59506. // http://www.w3.org/TR/css3-background/#the-border-style.
  59507. if (isArray(dashArray) && dashArray.length > 0) {
  59508. // According to the PDF specification: the elements in a dashArray
  59509. // shall be numbers that are nonnegative and not all equal to zero.
  59510. var isValid = true;
  59511. var allZeros = true;
  59512. for (var i = 0, len = dashArray.length; i < len; i++) {
  59513. var element = dashArray[i];
  59514. var validNumber = +element >= 0;
  59515. if (!validNumber) {
  59516. isValid = false;
  59517. break;
  59518. } else if (element > 0) {
  59519. allZeros = false;
  59520. }
  59521. }
  59522. if (isValid && !allZeros) {
  59523. this.dashArray = dashArray;
  59524. } else {
  59525. this.width = 0;
  59526. }
  59527. } else // Adobe behavior when the array is invalid.
  59528. if (dashArray) {
  59529. this.width = 0;
  59530. }
  59531. },
  59532. // Adobe behavior when the array is invalid.
  59533. /**
  59534. * Set the horizontal corner radius (from a Border dictionary).
  59535. *
  59536. * @public
  59537. * @memberof AnnotationBorderStyle
  59538. * @param {integer} radius - The horizontal corner radius
  59539. */
  59540. setHorizontalCornerRadius: function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  59541. if (radius === (radius | 0)) {
  59542. this.horizontalCornerRadius = radius;
  59543. }
  59544. },
  59545. /**
  59546. * Set the vertical corner radius (from a Border dictionary).
  59547. *
  59548. * @public
  59549. * @memberof AnnotationBorderStyle
  59550. * @param {integer} radius - The vertical corner radius
  59551. */
  59552. setVerticalCornerRadius: function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  59553. if (radius === (radius | 0)) {
  59554. this.verticalCornerRadius = radius;
  59555. }
  59556. }
  59557. };
  59558. return AnnotationBorderStyle;
  59559. }();
  59560. var WidgetAnnotation = function WidgetAnnotationClosure() {
  59561. function WidgetAnnotation(params) {
  59562. Annotation.call(this, params);
  59563. var dict = params.dict;
  59564. var data = this.data;
  59565. data.annotationType = AnnotationType.WIDGET;
  59566. data.fieldName = this._constructFieldName(dict);
  59567. data.fieldValue = Util.getInheritableProperty(dict, 'V', /* getArray = */
  59568. true);
  59569. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  59570. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  59571. var fieldType = Util.getInheritableProperty(dict, 'FT');
  59572. data.fieldType = isName(fieldType) ? fieldType.name : null;
  59573. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  59574. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff');
  59575. if (!isInt(data.fieldFlags) || data.fieldFlags < 0) {
  59576. data.fieldFlags = 0;
  59577. }
  59578. data.readOnly = this.hasFieldFlag(AnnotationFieldFlag.READONLY);
  59579. // Hide signatures because we cannot validate them.
  59580. if (data.fieldType === 'Sig') {
  59581. this.setFlags(AnnotationFlag.HIDDEN);
  59582. }
  59583. }
  59584. Util.inherit(WidgetAnnotation, Annotation, {
  59585. /**
  59586. * Construct the (fully qualified) field name from the (partial) field
  59587. * names of the field and its ancestors.
  59588. *
  59589. * @private
  59590. * @memberof WidgetAnnotation
  59591. * @param {Dict} dict - Complete widget annotation dictionary
  59592. * @return {string}
  59593. */
  59594. _constructFieldName: function WidgetAnnotation_constructFieldName(dict) {
  59595. // Both the `Parent` and `T` fields are optional. While at least one of
  59596. // them should be provided, bad PDF generators may fail to do so.
  59597. if (!dict.has('T') && !dict.has('Parent')) {
  59598. warn('Unknown field name, falling back to empty field name.');
  59599. return '';
  59600. }
  59601. // If no parent exists, the partial and fully qualified names are equal.
  59602. if (!dict.has('Parent')) {
  59603. return stringToPDFString(dict.get('T'));
  59604. }
  59605. // Form the fully qualified field name by appending the partial name to
  59606. // the parent's fully qualified name, separated by a period.
  59607. var fieldName = [];
  59608. if (dict.has('T')) {
  59609. fieldName.unshift(stringToPDFString(dict.get('T')));
  59610. }
  59611. var loopDict = dict;
  59612. while (loopDict.has('Parent')) {
  59613. loopDict = loopDict.get('Parent');
  59614. if (loopDict.has('T')) {
  59615. fieldName.unshift(stringToPDFString(loopDict.get('T')));
  59616. }
  59617. }
  59618. return fieldName.join('.');
  59619. },
  59620. /**
  59621. * Check if a provided field flag is set.
  59622. *
  59623. * @public
  59624. * @memberof WidgetAnnotation
  59625. * @param {number} flag - Hexadecimal representation for an annotation
  59626. * field characteristic
  59627. * @return {boolean}
  59628. * @see {@link shared/util.js}
  59629. */
  59630. hasFieldFlag: function WidgetAnnotation_hasFieldFlag(flag) {
  59631. return !!(this.data.fieldFlags & flag);
  59632. }
  59633. });
  59634. return WidgetAnnotation;
  59635. }();
  59636. var TextWidgetAnnotation = function TextWidgetAnnotationClosure() {
  59637. function TextWidgetAnnotation(params) {
  59638. WidgetAnnotation.call(this, params);
  59639. // The field value is always a string.
  59640. this.data.fieldValue = stringToPDFString(this.data.fieldValue || '');
  59641. // Determine the alignment of text in the field.
  59642. var alignment = Util.getInheritableProperty(params.dict, 'Q');
  59643. if (!isInt(alignment) || alignment < 0 || alignment > 2) {
  59644. alignment = null;
  59645. }
  59646. this.data.textAlignment = alignment;
  59647. // Determine the maximum length of text in the field.
  59648. var maximumLength = Util.getInheritableProperty(params.dict, 'MaxLen');
  59649. if (!isInt(maximumLength) || maximumLength < 0) {
  59650. maximumLength = null;
  59651. }
  59652. this.data.maxLen = maximumLength;
  59653. // Process field flags for the display layer.
  59654. this.data.multiLine = this.hasFieldFlag(AnnotationFieldFlag.MULTILINE);
  59655. this.data.comb = this.hasFieldFlag(AnnotationFieldFlag.COMB) && !this.hasFieldFlag(AnnotationFieldFlag.MULTILINE) && !this.hasFieldFlag(AnnotationFieldFlag.PASSWORD) && !this.hasFieldFlag(AnnotationFieldFlag.FILESELECT) && this.data.maxLen !== null;
  59656. }
  59657. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  59658. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator, task, renderForms) {
  59659. var operatorList = new OperatorList();
  59660. // Do not render form elements on the canvas when interactive forms are
  59661. // enabled. The display layer is responsible for rendering them instead.
  59662. if (renderForms) {
  59663. return Promise.resolve(operatorList);
  59664. }
  59665. if (this.appearance) {
  59666. return Annotation.prototype.getOperatorList.call(this, evaluator, task, renderForms);
  59667. }
  59668. // Even if there is an appearance stream, ignore it. This is the
  59669. // behaviour used by Adobe Reader.
  59670. if (!this.data.defaultAppearance) {
  59671. return Promise.resolve(operatorList);
  59672. }
  59673. var stream = new Stream(stringToBytes(this.data.defaultAppearance));
  59674. return evaluator.getOperatorList(stream, task, this.fieldResources, operatorList).then(function () {
  59675. return operatorList;
  59676. });
  59677. }
  59678. });
  59679. return TextWidgetAnnotation;
  59680. }();
  59681. var ChoiceWidgetAnnotation = function ChoiceWidgetAnnotationClosure() {
  59682. function ChoiceWidgetAnnotation(params) {
  59683. WidgetAnnotation.call(this, params);
  59684. // Determine the options. The options array may consist of strings or
  59685. // arrays. If the array consists of arrays, then the first element of
  59686. // each array is the export value and the second element of each array is
  59687. // the display value. If the array consists of strings, then these
  59688. // represent both the export and display value. In this case, we convert
  59689. // it to an array of arrays as well for convenience in the display layer.
  59690. this.data.options = [];
  59691. var options = params.dict.getArray('Opt');
  59692. if (isArray(options)) {
  59693. for (var i = 0, ii = options.length; i < ii; i++) {
  59694. var option = options[i];
  59695. this.data.options[i] = {
  59696. exportValue: isArray(option) ? option[0] : option,
  59697. displayValue: isArray(option) ? option[1] : option
  59698. };
  59699. }
  59700. }
  59701. // Determine the field value. In this case, it may be a string or an
  59702. // array of strings. For convenience in the display layer, convert the
  59703. // string to an array of one string as well.
  59704. if (!isArray(this.data.fieldValue)) {
  59705. this.data.fieldValue = [this.data.fieldValue];
  59706. }
  59707. // Process field flags for the display layer.
  59708. this.data.combo = this.hasFieldFlag(AnnotationFieldFlag.COMBO);
  59709. this.data.multiSelect = this.hasFieldFlag(AnnotationFieldFlag.MULTISELECT);
  59710. }
  59711. Util.inherit(ChoiceWidgetAnnotation, WidgetAnnotation, {
  59712. getOperatorList: function ChoiceWidgetAnnotation_getOperatorList(evaluator, task, renderForms) {
  59713. var operatorList = new OperatorList();
  59714. // Do not render form elements on the canvas when interactive forms are
  59715. // enabled. The display layer is responsible for rendering them instead.
  59716. if (renderForms) {
  59717. return Promise.resolve(operatorList);
  59718. }
  59719. return Annotation.prototype.getOperatorList.call(this, evaluator, task, renderForms);
  59720. }
  59721. });
  59722. return ChoiceWidgetAnnotation;
  59723. }();
  59724. var TextAnnotation = function TextAnnotationClosure() {
  59725. var DEFAULT_ICON_SIZE = 22;
  59726. // px
  59727. function TextAnnotation(parameters) {
  59728. Annotation.call(this, parameters);
  59729. this.data.annotationType = AnnotationType.TEXT;
  59730. if (this.data.hasAppearance) {
  59731. this.data.name = 'NoIcon';
  59732. } else {
  59733. this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE;
  59734. this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE;
  59735. this.data.name = parameters.dict.has('Name') ? parameters.dict.get('Name').name : 'Note';
  59736. }
  59737. this._preparePopup(parameters.dict);
  59738. }
  59739. Util.inherit(TextAnnotation, Annotation, {});
  59740. return TextAnnotation;
  59741. }();
  59742. var LinkAnnotation = function LinkAnnotationClosure() {
  59743. function LinkAnnotation(params) {
  59744. Annotation.call(this, params);
  59745. var data = this.data;
  59746. data.annotationType = AnnotationType.LINK;
  59747. Catalog.parseDestDictionary({
  59748. destDict: params.dict,
  59749. resultObj: data,
  59750. docBaseUrl: params.pdfManager.docBaseUrl
  59751. });
  59752. }
  59753. Util.inherit(LinkAnnotation, Annotation, {});
  59754. return LinkAnnotation;
  59755. }();
  59756. var PopupAnnotation = function PopupAnnotationClosure() {
  59757. function PopupAnnotation(parameters) {
  59758. Annotation.call(this, parameters);
  59759. this.data.annotationType = AnnotationType.POPUP;
  59760. var dict = parameters.dict;
  59761. var parentItem = dict.get('Parent');
  59762. if (!parentItem) {
  59763. warn('Popup annotation has a missing or invalid parent annotation.');
  59764. return;
  59765. }
  59766. this.data.parentId = dict.getRaw('Parent').toString();
  59767. this.data.title = stringToPDFString(parentItem.get('T') || '');
  59768. this.data.contents = stringToPDFString(parentItem.get('Contents') || '');
  59769. if (!parentItem.has('C')) {
  59770. // Fall back to the default background color.
  59771. this.data.color = null;
  59772. } else {
  59773. this.setColor(parentItem.getArray('C'));
  59774. this.data.color = this.color;
  59775. }
  59776. // If the Popup annotation is not viewable, but the parent annotation is,
  59777. // that is most likely a bug. Fallback to inherit the flags from the parent
  59778. // annotation (this is consistent with the behaviour in Adobe Reader).
  59779. if (!this.viewable) {
  59780. var parentFlags = parentItem.get('F');
  59781. if (this._isViewable(parentFlags)) {
  59782. this.setFlags(parentFlags);
  59783. }
  59784. }
  59785. }
  59786. Util.inherit(PopupAnnotation, Annotation, {});
  59787. return PopupAnnotation;
  59788. }();
  59789. var HighlightAnnotation = function HighlightAnnotationClosure() {
  59790. function HighlightAnnotation(parameters) {
  59791. Annotation.call(this, parameters);
  59792. this.data.annotationType = AnnotationType.HIGHLIGHT;
  59793. this._preparePopup(parameters.dict);
  59794. // PDF viewers completely ignore any border styles.
  59795. this.data.borderStyle.setWidth(0);
  59796. }
  59797. Util.inherit(HighlightAnnotation, Annotation, {});
  59798. return HighlightAnnotation;
  59799. }();
  59800. var UnderlineAnnotation = function UnderlineAnnotationClosure() {
  59801. function UnderlineAnnotation(parameters) {
  59802. Annotation.call(this, parameters);
  59803. this.data.annotationType = AnnotationType.UNDERLINE;
  59804. this._preparePopup(parameters.dict);
  59805. // PDF viewers completely ignore any border styles.
  59806. this.data.borderStyle.setWidth(0);
  59807. }
  59808. Util.inherit(UnderlineAnnotation, Annotation, {});
  59809. return UnderlineAnnotation;
  59810. }();
  59811. var SquigglyAnnotation = function SquigglyAnnotationClosure() {
  59812. function SquigglyAnnotation(parameters) {
  59813. Annotation.call(this, parameters);
  59814. this.data.annotationType = AnnotationType.SQUIGGLY;
  59815. this._preparePopup(parameters.dict);
  59816. // PDF viewers completely ignore any border styles.
  59817. this.data.borderStyle.setWidth(0);
  59818. }
  59819. Util.inherit(SquigglyAnnotation, Annotation, {});
  59820. return SquigglyAnnotation;
  59821. }();
  59822. var StrikeOutAnnotation = function StrikeOutAnnotationClosure() {
  59823. function StrikeOutAnnotation(parameters) {
  59824. Annotation.call(this, parameters);
  59825. this.data.annotationType = AnnotationType.STRIKEOUT;
  59826. this._preparePopup(parameters.dict);
  59827. // PDF viewers completely ignore any border styles.
  59828. this.data.borderStyle.setWidth(0);
  59829. }
  59830. Util.inherit(StrikeOutAnnotation, Annotation, {});
  59831. return StrikeOutAnnotation;
  59832. }();
  59833. var FileAttachmentAnnotation = function FileAttachmentAnnotationClosure() {
  59834. function FileAttachmentAnnotation(parameters) {
  59835. Annotation.call(this, parameters);
  59836. var file = new FileSpec(parameters.dict.get('FS'), parameters.xref);
  59837. this.data.annotationType = AnnotationType.FILEATTACHMENT;
  59838. this.data.file = file.serializable;
  59839. this._preparePopup(parameters.dict);
  59840. }
  59841. Util.inherit(FileAttachmentAnnotation, Annotation, {});
  59842. return FileAttachmentAnnotation;
  59843. }();
  59844. exports.Annotation = Annotation;
  59845. exports.AnnotationBorderStyle = AnnotationBorderStyle;
  59846. exports.AnnotationFactory = AnnotationFactory;
  59847. }));
  59848. (function (root, factory) {
  59849. factory(root.pdfjsCoreDocument = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreObj, root.pdfjsCoreParser, root.pdfjsCoreCrypto, root.pdfjsCoreEvaluator, root.pdfjsCoreAnnotation);
  59850. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreObj, coreParser, coreCrypto, coreEvaluator, coreAnnotation) {
  59851. var MissingDataException = sharedUtil.MissingDataException;
  59852. var Util = sharedUtil.Util;
  59853. var assert = sharedUtil.assert;
  59854. var error = sharedUtil.error;
  59855. var info = sharedUtil.info;
  59856. var isArray = sharedUtil.isArray;
  59857. var isArrayBuffer = sharedUtil.isArrayBuffer;
  59858. var isString = sharedUtil.isString;
  59859. var shadow = sharedUtil.shadow;
  59860. var stringToBytes = sharedUtil.stringToBytes;
  59861. var stringToPDFString = sharedUtil.stringToPDFString;
  59862. var warn = sharedUtil.warn;
  59863. var isSpace = sharedUtil.isSpace;
  59864. var Dict = corePrimitives.Dict;
  59865. var isDict = corePrimitives.isDict;
  59866. var isName = corePrimitives.isName;
  59867. var isStream = corePrimitives.isStream;
  59868. var NullStream = coreStream.NullStream;
  59869. var Stream = coreStream.Stream;
  59870. var StreamsSequenceStream = coreStream.StreamsSequenceStream;
  59871. var Catalog = coreObj.Catalog;
  59872. var ObjectLoader = coreObj.ObjectLoader;
  59873. var XRef = coreObj.XRef;
  59874. var Linearization = coreParser.Linearization;
  59875. var calculateMD5 = coreCrypto.calculateMD5;
  59876. var OperatorList = coreEvaluator.OperatorList;
  59877. var PartialEvaluator = coreEvaluator.PartialEvaluator;
  59878. var Annotation = coreAnnotation.Annotation;
  59879. var AnnotationFactory = coreAnnotation.AnnotationFactory;
  59880. var Page = function PageClosure() {
  59881. var LETTER_SIZE_MEDIABOX = [
  59882. 0,
  59883. 0,
  59884. 612,
  59885. 792
  59886. ];
  59887. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  59888. this.pdfManager = pdfManager;
  59889. this.pageIndex = pageIndex;
  59890. this.pageDict = pageDict;
  59891. this.xref = xref;
  59892. this.ref = ref;
  59893. this.fontCache = fontCache;
  59894. this.uniquePrefix = 'p' + this.pageIndex + '_';
  59895. this.idCounters = { obj: 0 };
  59896. this.evaluatorOptions = pdfManager.evaluatorOptions;
  59897. this.resourcesPromise = null;
  59898. }
  59899. Page.prototype = {
  59900. getPageProp: function Page_getPageProp(key) {
  59901. return this.pageDict.get(key);
  59902. },
  59903. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  59904. var dict = this.pageDict, valueArray = null, loopCount = 0;
  59905. var MAX_LOOP_COUNT = 100;
  59906. // Always walk up the entire parent chain, to be able to find
  59907. // e.g. \Resources placed on multiple levels of the tree.
  59908. while (dict) {
  59909. var value = dict.get(key);
  59910. if (value) {
  59911. if (!valueArray) {
  59912. valueArray = [];
  59913. }
  59914. valueArray.push(value);
  59915. }
  59916. if (++loopCount > MAX_LOOP_COUNT) {
  59917. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  59918. break;
  59919. }
  59920. dict = dict.get('Parent');
  59921. }
  59922. if (!valueArray) {
  59923. return Dict.empty;
  59924. }
  59925. if (valueArray.length === 1 || !isDict(valueArray[0]) || loopCount > MAX_LOOP_COUNT) {
  59926. return valueArray[0];
  59927. }
  59928. return Dict.merge(this.xref, valueArray);
  59929. },
  59930. get content() {
  59931. return this.getPageProp('Contents');
  59932. },
  59933. get resources() {
  59934. // For robustness: The spec states that a \Resources entry has to be
  59935. // present, but can be empty. Some document omit it still, in this case
  59936. // we return an empty dictionary.
  59937. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  59938. },
  59939. get mediaBox() {
  59940. var obj = this.getInheritedPageProp('MediaBox');
  59941. // Reset invalid media box to letter size.
  59942. if (!isArray(obj) || obj.length !== 4) {
  59943. obj = LETTER_SIZE_MEDIABOX;
  59944. }
  59945. return shadow(this, 'mediaBox', obj);
  59946. },
  59947. get view() {
  59948. var mediaBox = this.mediaBox;
  59949. var cropBox = this.getInheritedPageProp('CropBox');
  59950. if (!isArray(cropBox) || cropBox.length !== 4) {
  59951. return shadow(this, 'view', mediaBox);
  59952. }
  59953. // From the spec, 6th ed., p.963:
  59954. // "The crop, bleed, trim, and art boxes should not ordinarily
  59955. // extend beyond the boundaries of the media box. If they do, they are
  59956. // effectively reduced to their intersection with the media box."
  59957. cropBox = Util.intersect(cropBox, mediaBox);
  59958. if (!cropBox) {
  59959. return shadow(this, 'view', mediaBox);
  59960. }
  59961. return shadow(this, 'view', cropBox);
  59962. },
  59963. get rotate() {
  59964. var rotate = this.getInheritedPageProp('Rotate') || 0;
  59965. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  59966. if (rotate % 90 !== 0) {
  59967. rotate = 0;
  59968. } else if (rotate >= 360) {
  59969. rotate = rotate % 360;
  59970. } else if (rotate < 0) {
  59971. // The spec doesn't cover negatives, assume its counterclockwise
  59972. // rotation. The following is the other implementation of modulo.
  59973. rotate = (rotate % 360 + 360) % 360;
  59974. }
  59975. return shadow(this, 'rotate', rotate);
  59976. },
  59977. getContentStream: function Page_getContentStream() {
  59978. var content = this.content;
  59979. var stream;
  59980. if (isArray(content)) {
  59981. // fetching items
  59982. var xref = this.xref;
  59983. var i, n = content.length;
  59984. var streams = [];
  59985. for (i = 0; i < n; ++i) {
  59986. streams.push(xref.fetchIfRef(content[i]));
  59987. }
  59988. stream = new StreamsSequenceStream(streams);
  59989. } else if (isStream(content)) {
  59990. stream = content;
  59991. } else {
  59992. // replacing non-existent page content with empty one
  59993. stream = new NullStream();
  59994. }
  59995. return stream;
  59996. },
  59997. loadResources: function Page_loadResources(keys) {
  59998. if (!this.resourcesPromise) {
  59999. // TODO: add async getInheritedPageProp and remove this.
  60000. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  60001. }
  60002. return this.resourcesPromise.then(function resourceSuccess() {
  60003. var objectLoader = new ObjectLoader(this.resources.map, keys, this.xref);
  60004. return objectLoader.load();
  60005. }.bind(this));
  60006. },
  60007. getOperatorList: function Page_getOperatorList(handler, task, intent, renderInteractiveForms) {
  60008. var self = this;
  60009. var pdfManager = this.pdfManager;
  60010. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream', []);
  60011. var resourcesPromise = this.loadResources([
  60012. 'ExtGState',
  60013. 'ColorSpace',
  60014. 'Pattern',
  60015. 'Shading',
  60016. 'XObject',
  60017. 'Font'
  60018. ]);
  60019. // ProcSet
  60020. // Properties
  60021. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref, handler, this.pageIndex, this.uniquePrefix, this.idCounters, this.fontCache, this.evaluatorOptions);
  60022. var dataPromises = Promise.all([
  60023. contentStreamPromise,
  60024. resourcesPromise
  60025. ]);
  60026. var pageListPromise = dataPromises.then(function (data) {
  60027. var contentStream = data[0];
  60028. var opList = new OperatorList(intent, handler, self.pageIndex);
  60029. handler.send('StartRenderPage', {
  60030. transparency: partialEvaluator.hasBlendModes(self.resources),
  60031. pageIndex: self.pageIndex,
  60032. intent: intent
  60033. });
  60034. return partialEvaluator.getOperatorList(contentStream, task, self.resources, opList).then(function () {
  60035. return opList;
  60036. });
  60037. });
  60038. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  60039. return Promise.all([
  60040. pageListPromise,
  60041. annotationsPromise
  60042. ]).then(function (datas) {
  60043. var pageOpList = datas[0];
  60044. var annotations = datas[1];
  60045. if (annotations.length === 0) {
  60046. pageOpList.flush(true);
  60047. return pageOpList;
  60048. }
  60049. var annotationsReadyPromise = Annotation.appendToOperatorList(annotations, pageOpList, partialEvaluator, task, intent, renderInteractiveForms);
  60050. return annotationsReadyPromise.then(function () {
  60051. pageOpList.flush(true);
  60052. return pageOpList;
  60053. });
  60054. });
  60055. },
  60056. extractTextContent: function Page_extractTextContent(task, normalizeWhitespace, combineTextItems) {
  60057. var handler = {
  60058. on: function nullHandlerOn() {
  60059. },
  60060. send: function nullHandlerSend() {
  60061. }
  60062. };
  60063. var self = this;
  60064. var pdfManager = this.pdfManager;
  60065. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream', []);
  60066. var resourcesPromise = this.loadResources([
  60067. 'ExtGState',
  60068. 'XObject',
  60069. 'Font'
  60070. ]);
  60071. var dataPromises = Promise.all([
  60072. contentStreamPromise,
  60073. resourcesPromise
  60074. ]);
  60075. return dataPromises.then(function (data) {
  60076. var contentStream = data[0];
  60077. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref, handler, self.pageIndex, self.uniquePrefix, self.idCounters, self.fontCache, self.evaluatorOptions);
  60078. return partialEvaluator.getTextContent(contentStream, task, self.resources, /* stateManager = */
  60079. null, normalizeWhitespace, combineTextItems);
  60080. });
  60081. },
  60082. getAnnotationsData: function Page_getAnnotationsData(intent) {
  60083. var annotations = this.annotations;
  60084. var annotationsData = [];
  60085. for (var i = 0, n = annotations.length; i < n; ++i) {
  60086. if (intent) {
  60087. if (!(intent === 'display' && annotations[i].viewable) && !(intent === 'print' && annotations[i].printable)) {
  60088. continue;
  60089. }
  60090. }
  60091. annotationsData.push(annotations[i].data);
  60092. }
  60093. return annotationsData;
  60094. },
  60095. get annotations() {
  60096. var annotations = [];
  60097. var annotationRefs = this.getInheritedPageProp('Annots') || [];
  60098. var annotationFactory = new AnnotationFactory();
  60099. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  60100. var annotationRef = annotationRefs[i];
  60101. var annotation = annotationFactory.create(this.xref, annotationRef, this.pdfManager, this.uniquePrefix, this.idCounters);
  60102. if (annotation) {
  60103. annotations.push(annotation);
  60104. }
  60105. }
  60106. return shadow(this, 'annotations', annotations);
  60107. }
  60108. };
  60109. return Page;
  60110. }();
  60111. /**
  60112. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  60113. * `PDFDoc`, this one doesn't have any job management code.
  60114. * Right now there exists one PDFDocument on the main thread + one object
  60115. * for each worker. If there is no worker support enabled, there are two
  60116. * `PDFDocument` objects on the main thread created.
  60117. */
  60118. var PDFDocument = function PDFDocumentClosure() {
  60119. var FINGERPRINT_FIRST_BYTES = 1024;
  60120. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' + '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  60121. function PDFDocument(pdfManager, arg, password) {
  60122. if (isStream(arg)) {
  60123. init.call(this, pdfManager, arg, password);
  60124. } else if (isArrayBuffer(arg)) {
  60125. init.call(this, pdfManager, new Stream(arg), password);
  60126. } else {
  60127. error('PDFDocument: Unknown argument type');
  60128. }
  60129. }
  60130. function init(pdfManager, stream, password) {
  60131. assert(stream.length > 0, 'stream must have data');
  60132. this.pdfManager = pdfManager;
  60133. this.stream = stream;
  60134. var xref = new XRef(this.stream, password, pdfManager);
  60135. this.xref = xref;
  60136. }
  60137. function find(stream, needle, limit, backwards) {
  60138. var pos = stream.pos;
  60139. var end = stream.end;
  60140. var strBuf = [];
  60141. if (pos + limit > end) {
  60142. limit = end - pos;
  60143. }
  60144. for (var n = 0; n < limit; ++n) {
  60145. strBuf.push(String.fromCharCode(stream.getByte()));
  60146. }
  60147. var str = strBuf.join('');
  60148. stream.pos = pos;
  60149. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  60150. if (index === -1) {
  60151. return false;
  60152. }
  60153. /* not found */
  60154. stream.pos += index;
  60155. return true;
  60156. }
  60157. /* found */
  60158. var DocumentInfoValidators = {
  60159. get entries() {
  60160. // Lazily build this since all the validation functions below are not
  60161. // defined until after this file loads.
  60162. return shadow(this, 'entries', {
  60163. Title: isString,
  60164. Author: isString,
  60165. Subject: isString,
  60166. Keywords: isString,
  60167. Creator: isString,
  60168. Producer: isString,
  60169. CreationDate: isString,
  60170. ModDate: isString,
  60171. Trapped: isName
  60172. });
  60173. }
  60174. };
  60175. PDFDocument.prototype = {
  60176. parse: function PDFDocument_parse(recoveryMode) {
  60177. this.setup(recoveryMode);
  60178. var version = this.catalog.catDict.get('Version');
  60179. if (isName(version)) {
  60180. this.pdfFormatVersion = version.name;
  60181. }
  60182. try {
  60183. // checking if AcroForm is present
  60184. this.acroForm = this.catalog.catDict.get('AcroForm');
  60185. if (this.acroForm) {
  60186. this.xfa = this.acroForm.get('XFA');
  60187. var fields = this.acroForm.get('Fields');
  60188. if ((!fields || !isArray(fields) || fields.length === 0) && !this.xfa) {
  60189. // no fields and no XFA -- not a form (?)
  60190. this.acroForm = null;
  60191. }
  60192. }
  60193. } catch (ex) {
  60194. info('Something wrong with AcroForm entry');
  60195. this.acroForm = null;
  60196. }
  60197. },
  60198. get linearization() {
  60199. var linearization = null;
  60200. if (this.stream.length) {
  60201. try {
  60202. linearization = Linearization.create(this.stream);
  60203. } catch (err) {
  60204. if (err instanceof MissingDataException) {
  60205. throw err;
  60206. }
  60207. info(err);
  60208. }
  60209. }
  60210. // shadow the prototype getter with a data property
  60211. return shadow(this, 'linearization', linearization);
  60212. },
  60213. get startXRef() {
  60214. var stream = this.stream;
  60215. var startXRef = 0;
  60216. var linearization = this.linearization;
  60217. if (linearization) {
  60218. // Find end of first obj.
  60219. stream.reset();
  60220. if (find(stream, 'endobj', 1024)) {
  60221. startXRef = stream.pos + 6;
  60222. }
  60223. } else {
  60224. // Find startxref by jumping backward from the end of the file.
  60225. var step = 1024;
  60226. var found = false, pos = stream.end;
  60227. while (!found && pos > 0) {
  60228. pos -= step - 'startxref'.length;
  60229. if (pos < 0) {
  60230. pos = 0;
  60231. }
  60232. stream.pos = pos;
  60233. found = find(stream, 'startxref', step, true);
  60234. }
  60235. if (found) {
  60236. stream.skip(9);
  60237. var ch;
  60238. do {
  60239. ch = stream.getByte();
  60240. } while (isSpace(ch));
  60241. var str = '';
  60242. while (ch >= 0x20 && ch <= 0x39) {
  60243. // < '9'
  60244. str += String.fromCharCode(ch);
  60245. ch = stream.getByte();
  60246. }
  60247. startXRef = parseInt(str, 10);
  60248. if (isNaN(startXRef)) {
  60249. startXRef = 0;
  60250. }
  60251. }
  60252. }
  60253. // shadow the prototype getter with a data property
  60254. return shadow(this, 'startXRef', startXRef);
  60255. },
  60256. get mainXRefEntriesOffset() {
  60257. var mainXRefEntriesOffset = 0;
  60258. var linearization = this.linearization;
  60259. if (linearization) {
  60260. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  60261. }
  60262. // shadow the prototype getter with a data property
  60263. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  60264. },
  60265. // Find the header, remove leading garbage and setup the stream
  60266. // starting from the header.
  60267. checkHeader: function PDFDocument_checkHeader() {
  60268. var stream = this.stream;
  60269. stream.reset();
  60270. if (find(stream, '%PDF-', 1024)) {
  60271. // Found the header, trim off any garbage before it.
  60272. stream.moveStart();
  60273. // Reading file format version
  60274. var MAX_VERSION_LENGTH = 12;
  60275. var version = '', ch;
  60276. while ((ch = stream.getByte()) > 0x20) {
  60277. // SPACE
  60278. if (version.length >= MAX_VERSION_LENGTH) {
  60279. break;
  60280. }
  60281. version += String.fromCharCode(ch);
  60282. }
  60283. if (!this.pdfFormatVersion) {
  60284. // removing "%PDF-"-prefix
  60285. this.pdfFormatVersion = version.substring(5);
  60286. }
  60287. return;
  60288. }
  60289. },
  60290. // May not be a PDF file, continue anyway.
  60291. parseStartXRef: function PDFDocument_parseStartXRef() {
  60292. var startXRef = this.startXRef;
  60293. this.xref.setStartXRef(startXRef);
  60294. },
  60295. setup: function PDFDocument_setup(recoveryMode) {
  60296. this.xref.parse(recoveryMode);
  60297. var self = this;
  60298. var pageFactory = {
  60299. createPage: function (pageIndex, dict, ref, fontCache) {
  60300. return new Page(self.pdfManager, self.xref, pageIndex, dict, ref, fontCache);
  60301. }
  60302. };
  60303. this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);
  60304. },
  60305. get numPages() {
  60306. var linearization = this.linearization;
  60307. var num = linearization ? linearization.numPages : this.catalog.numPages;
  60308. // shadow the prototype getter
  60309. return shadow(this, 'numPages', num);
  60310. },
  60311. get documentInfo() {
  60312. var docInfo = {
  60313. PDFFormatVersion: this.pdfFormatVersion,
  60314. IsAcroFormPresent: !!this.acroForm,
  60315. IsXFAPresent: !!this.xfa
  60316. };
  60317. var infoDict;
  60318. try {
  60319. infoDict = this.xref.trailer.get('Info');
  60320. } catch (err) {
  60321. info('The document information dictionary is invalid.');
  60322. }
  60323. if (infoDict) {
  60324. var validEntries = DocumentInfoValidators.entries;
  60325. // Only fill the document info with valid entries from the spec.
  60326. for (var key in validEntries) {
  60327. if (infoDict.has(key)) {
  60328. var value = infoDict.get(key);
  60329. // Make sure the value conforms to the spec.
  60330. if (validEntries[key](value)) {
  60331. docInfo[key] = typeof value !== 'string' ? value : stringToPDFString(value);
  60332. } else {
  60333. info('Bad value in document info for "' + key + '"');
  60334. }
  60335. }
  60336. }
  60337. }
  60338. return shadow(this, 'documentInfo', docInfo);
  60339. },
  60340. get fingerprint() {
  60341. var xref = this.xref, hash, fileID = '';
  60342. var idArray = xref.trailer.get('ID');
  60343. if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) && idArray[0] !== EMPTY_FINGERPRINT) {
  60344. hash = stringToBytes(idArray[0]);
  60345. } else {
  60346. if (this.stream.ensureRange) {
  60347. this.stream.ensureRange(0, Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  60348. }
  60349. hash = calculateMD5(this.stream.bytes.subarray(0, FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  60350. }
  60351. for (var i = 0, n = hash.length; i < n; i++) {
  60352. var hex = hash[i].toString(16);
  60353. fileID += hex.length === 1 ? '0' + hex : hex;
  60354. }
  60355. return shadow(this, 'fingerprint', fileID);
  60356. },
  60357. getPage: function PDFDocument_getPage(pageIndex) {
  60358. return this.catalog.getPage(pageIndex);
  60359. },
  60360. cleanup: function PDFDocument_cleanup() {
  60361. return this.catalog.cleanup();
  60362. }
  60363. };
  60364. return PDFDocument;
  60365. }();
  60366. exports.Page = Page;
  60367. exports.PDFDocument = PDFDocument;
  60368. }));
  60369. (function (root, factory) {
  60370. factory(root.pdfjsCorePdfManager = {}, root.pdfjsSharedUtil, root.pdfjsCoreStream, root.pdfjsCoreChunkedStream, root.pdfjsCoreDocument);
  60371. }(this, function (exports, sharedUtil, coreStream, coreChunkedStream, coreDocument) {
  60372. var warn = sharedUtil.warn;
  60373. var createValidAbsoluteUrl = sharedUtil.createValidAbsoluteUrl;
  60374. var shadow = sharedUtil.shadow;
  60375. var NotImplementedException = sharedUtil.NotImplementedException;
  60376. var MissingDataException = sharedUtil.MissingDataException;
  60377. var createPromiseCapability = sharedUtil.createPromiseCapability;
  60378. var Util = sharedUtil.Util;
  60379. var Stream = coreStream.Stream;
  60380. var ChunkedStreamManager = coreChunkedStream.ChunkedStreamManager;
  60381. var PDFDocument = coreDocument.PDFDocument;
  60382. var BasePdfManager = function BasePdfManagerClosure() {
  60383. function BasePdfManager() {
  60384. throw new Error('Cannot initialize BaseManagerManager');
  60385. }
  60386. BasePdfManager.prototype = {
  60387. get docId() {
  60388. return this._docId;
  60389. },
  60390. get docBaseUrl() {
  60391. var docBaseUrl = null;
  60392. if (this._docBaseUrl) {
  60393. var absoluteUrl = createValidAbsoluteUrl(this._docBaseUrl);
  60394. if (absoluteUrl) {
  60395. docBaseUrl = absoluteUrl.href;
  60396. } else {
  60397. warn('Invalid absolute docBaseUrl: "' + this._docBaseUrl + '".');
  60398. }
  60399. }
  60400. return shadow(this, 'docBaseUrl', docBaseUrl);
  60401. },
  60402. onLoadedStream: function BasePdfManager_onLoadedStream() {
  60403. throw new NotImplementedException();
  60404. },
  60405. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  60406. return this.ensure(this.pdfDocument, prop, args);
  60407. },
  60408. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  60409. return this.ensure(this.pdfDocument.xref, prop, args);
  60410. },
  60411. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  60412. return this.ensure(this.pdfDocument.catalog, prop, args);
  60413. },
  60414. getPage: function BasePdfManager_getPage(pageIndex) {
  60415. return this.pdfDocument.getPage(pageIndex);
  60416. },
  60417. cleanup: function BasePdfManager_cleanup() {
  60418. return this.pdfDocument.cleanup();
  60419. },
  60420. ensure: function BasePdfManager_ensure(obj, prop, args) {
  60421. return new NotImplementedException();
  60422. },
  60423. requestRange: function BasePdfManager_requestRange(begin, end) {
  60424. return new NotImplementedException();
  60425. },
  60426. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  60427. return new NotImplementedException();
  60428. },
  60429. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  60430. return new NotImplementedException();
  60431. },
  60432. updatePassword: function BasePdfManager_updatePassword(password) {
  60433. this.pdfDocument.xref.password = this.password = password;
  60434. if (this._passwordChangedCapability) {
  60435. this._passwordChangedCapability.resolve();
  60436. }
  60437. },
  60438. passwordChanged: function BasePdfManager_passwordChanged() {
  60439. this._passwordChangedCapability = createPromiseCapability();
  60440. return this._passwordChangedCapability.promise;
  60441. },
  60442. terminate: function BasePdfManager_terminate() {
  60443. return new NotImplementedException();
  60444. }
  60445. };
  60446. return BasePdfManager;
  60447. }();
  60448. var LocalPdfManager = function LocalPdfManagerClosure() {
  60449. function LocalPdfManager(docId, data, password, evaluatorOptions, docBaseUrl) {
  60450. this._docId = docId;
  60451. this._docBaseUrl = docBaseUrl;
  60452. this.evaluatorOptions = evaluatorOptions;
  60453. var stream = new Stream(data);
  60454. this.pdfDocument = new PDFDocument(this, stream, password);
  60455. this._loadedStreamCapability = createPromiseCapability();
  60456. this._loadedStreamCapability.resolve(stream);
  60457. }
  60458. Util.inherit(LocalPdfManager, BasePdfManager, {
  60459. ensure: function LocalPdfManager_ensure(obj, prop, args) {
  60460. return new Promise(function (resolve, reject) {
  60461. try {
  60462. var value = obj[prop];
  60463. var result;
  60464. if (typeof value === 'function') {
  60465. result = value.apply(obj, args);
  60466. } else {
  60467. result = value;
  60468. }
  60469. resolve(result);
  60470. } catch (e) {
  60471. reject(e);
  60472. }
  60473. });
  60474. },
  60475. requestRange: function LocalPdfManager_requestRange(begin, end) {
  60476. return Promise.resolve();
  60477. },
  60478. requestLoadedStream: function LocalPdfManager_requestLoadedStream() {
  60479. return;
  60480. },
  60481. onLoadedStream: function LocalPdfManager_onLoadedStream() {
  60482. return this._loadedStreamCapability.promise;
  60483. },
  60484. terminate: function LocalPdfManager_terminate() {
  60485. return;
  60486. }
  60487. });
  60488. return LocalPdfManager;
  60489. }();
  60490. var NetworkPdfManager = function NetworkPdfManagerClosure() {
  60491. function NetworkPdfManager(docId, pdfNetworkStream, args, evaluatorOptions, docBaseUrl) {
  60492. this._docId = docId;
  60493. this._docBaseUrl = docBaseUrl;
  60494. this.msgHandler = args.msgHandler;
  60495. this.evaluatorOptions = evaluatorOptions;
  60496. var params = {
  60497. msgHandler: args.msgHandler,
  60498. url: args.url,
  60499. length: args.length,
  60500. disableAutoFetch: args.disableAutoFetch,
  60501. rangeChunkSize: args.rangeChunkSize
  60502. };
  60503. this.streamManager = new ChunkedStreamManager(pdfNetworkStream, params);
  60504. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(), args.password);
  60505. }
  60506. Util.inherit(NetworkPdfManager, BasePdfManager, {
  60507. ensure: function NetworkPdfManager_ensure(obj, prop, args) {
  60508. var pdfManager = this;
  60509. return new Promise(function (resolve, reject) {
  60510. function ensureHelper() {
  60511. try {
  60512. var result;
  60513. var value = obj[prop];
  60514. if (typeof value === 'function') {
  60515. result = value.apply(obj, args);
  60516. } else {
  60517. result = value;
  60518. }
  60519. resolve(result);
  60520. } catch (e) {
  60521. if (!(e instanceof MissingDataException)) {
  60522. reject(e);
  60523. return;
  60524. }
  60525. pdfManager.streamManager.requestRange(e.begin, e.end).then(ensureHelper, reject);
  60526. }
  60527. }
  60528. ensureHelper();
  60529. });
  60530. },
  60531. requestRange: function NetworkPdfManager_requestRange(begin, end) {
  60532. return this.streamManager.requestRange(begin, end);
  60533. },
  60534. requestLoadedStream: function NetworkPdfManager_requestLoadedStream() {
  60535. this.streamManager.requestAllChunks();
  60536. },
  60537. sendProgressiveData: function NetworkPdfManager_sendProgressiveData(chunk) {
  60538. this.streamManager.onReceiveData({ chunk: chunk });
  60539. },
  60540. onLoadedStream: function NetworkPdfManager_onLoadedStream() {
  60541. return this.streamManager.onLoadedStream();
  60542. },
  60543. terminate: function NetworkPdfManager_terminate() {
  60544. this.streamManager.abort();
  60545. }
  60546. });
  60547. return NetworkPdfManager;
  60548. }();
  60549. exports.LocalPdfManager = LocalPdfManager;
  60550. exports.NetworkPdfManager = NetworkPdfManager;
  60551. }));
  60552. (function (root, factory) {
  60553. factory(root.pdfjsCoreWorker = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCorePdfManager);
  60554. }(this, function (exports, sharedUtil, corePrimitives, corePdfManager) {
  60555. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  60556. var InvalidPDFException = sharedUtil.InvalidPDFException;
  60557. var MessageHandler = sharedUtil.MessageHandler;
  60558. var MissingPDFException = sharedUtil.MissingPDFException;
  60559. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  60560. var PasswordException = sharedUtil.PasswordException;
  60561. var PasswordResponses = sharedUtil.PasswordResponses;
  60562. var UnknownErrorException = sharedUtil.UnknownErrorException;
  60563. var XRefParseException = sharedUtil.XRefParseException;
  60564. var arrayByteLength = sharedUtil.arrayByteLength;
  60565. var arraysToBytes = sharedUtil.arraysToBytes;
  60566. var assert = sharedUtil.assert;
  60567. var createPromiseCapability = sharedUtil.createPromiseCapability;
  60568. var error = sharedUtil.error;
  60569. var info = sharedUtil.info;
  60570. var warn = sharedUtil.warn;
  60571. var setVerbosityLevel = sharedUtil.setVerbosityLevel;
  60572. var Ref = corePrimitives.Ref;
  60573. var LocalPdfManager = corePdfManager.LocalPdfManager;
  60574. var NetworkPdfManager = corePdfManager.NetworkPdfManager;
  60575. var globalScope = sharedUtil.globalScope;
  60576. var WorkerTask = function WorkerTaskClosure() {
  60577. function WorkerTask(name) {
  60578. this.name = name;
  60579. this.terminated = false;
  60580. this._capability = createPromiseCapability();
  60581. }
  60582. WorkerTask.prototype = {
  60583. get finished() {
  60584. return this._capability.promise;
  60585. },
  60586. finish: function () {
  60587. this._capability.resolve();
  60588. },
  60589. terminate: function () {
  60590. this.terminated = true;
  60591. },
  60592. ensureNotTerminated: function () {
  60593. if (this.terminated) {
  60594. throw new Error('Worker task was terminated');
  60595. }
  60596. }
  60597. };
  60598. return WorkerTask;
  60599. }();
  60600. /** @implements {IPDFStream} */
  60601. var PDFWorkerStream = function PDFWorkerStreamClosure() {
  60602. function PDFWorkerStream(params, msgHandler) {
  60603. this._queuedChunks = [];
  60604. var initialData = params.initialData;
  60605. if (initialData && initialData.length > 0) {
  60606. this._queuedChunks.push(initialData);
  60607. }
  60608. this._msgHandler = msgHandler;
  60609. this._isRangeSupported = !params.disableRange;
  60610. this._isStreamingSupported = !params.disableStream;
  60611. this._contentLength = params.length;
  60612. this._fullRequestReader = null;
  60613. this._rangeReaders = [];
  60614. msgHandler.on('OnDataRange', this._onReceiveData.bind(this));
  60615. msgHandler.on('OnDataProgress', this._onProgress.bind(this));
  60616. }
  60617. PDFWorkerStream.prototype = {
  60618. _onReceiveData: function PDFWorkerStream_onReceiveData(args) {
  60619. if (args.begin === undefined) {
  60620. if (this._fullRequestReader) {
  60621. this._fullRequestReader._enqueue(args.chunk);
  60622. } else {
  60623. this._queuedChunks.push(args.chunk);
  60624. }
  60625. } else {
  60626. var found = this._rangeReaders.some(function (rangeReader) {
  60627. if (rangeReader._begin !== args.begin) {
  60628. return false;
  60629. }
  60630. rangeReader._enqueue(args.chunk);
  60631. return true;
  60632. });
  60633. assert(found);
  60634. }
  60635. },
  60636. _onProgress: function PDFWorkerStream_onProgress(evt) {
  60637. if (this._rangeReaders.length > 0) {
  60638. // Reporting to first range reader.
  60639. var firstReader = this._rangeReaders[0];
  60640. if (firstReader.onProgress) {
  60641. firstReader.onProgress({ loaded: evt.loaded });
  60642. }
  60643. }
  60644. },
  60645. _removeRangeReader: function PDFWorkerStream_removeRangeReader(reader) {
  60646. var i = this._rangeReaders.indexOf(reader);
  60647. if (i >= 0) {
  60648. this._rangeReaders.splice(i, 1);
  60649. }
  60650. },
  60651. getFullReader: function PDFWorkerStream_getFullReader() {
  60652. assert(!this._fullRequestReader);
  60653. var queuedChunks = this._queuedChunks;
  60654. this._queuedChunks = null;
  60655. return new PDFWorkerStreamReader(this, queuedChunks);
  60656. },
  60657. getRangeReader: function PDFWorkerStream_getRangeReader(begin, end) {
  60658. var reader = new PDFWorkerStreamRangeReader(this, begin, end);
  60659. this._msgHandler.send('RequestDataRange', {
  60660. begin: begin,
  60661. end: end
  60662. });
  60663. this._rangeReaders.push(reader);
  60664. return reader;
  60665. },
  60666. cancelAllRequests: function PDFWorkerStream_cancelAllRequests(reason) {
  60667. if (this._fullRequestReader) {
  60668. this._fullRequestReader.cancel(reason);
  60669. }
  60670. var readers = this._rangeReaders.slice(0);
  60671. readers.forEach(function (rangeReader) {
  60672. rangeReader.cancel(reason);
  60673. });
  60674. }
  60675. };
  60676. /** @implements {IPDFStreamReader} */
  60677. function PDFWorkerStreamReader(stream, queuedChunks) {
  60678. this._stream = stream;
  60679. this._done = false;
  60680. this._queuedChunks = queuedChunks || [];
  60681. this._requests = [];
  60682. this._headersReady = Promise.resolve();
  60683. stream._fullRequestReader = this;
  60684. this.onProgress = null;
  60685. }
  60686. // not used
  60687. PDFWorkerStreamReader.prototype = {
  60688. _enqueue: function PDFWorkerStreamReader_enqueue(chunk) {
  60689. if (this._done) {
  60690. return;
  60691. }
  60692. // ignore new data
  60693. if (this._requests.length > 0) {
  60694. var requestCapability = this._requests.shift();
  60695. requestCapability.resolve({
  60696. value: chunk,
  60697. done: false
  60698. });
  60699. return;
  60700. }
  60701. this._queuedChunks.push(chunk);
  60702. },
  60703. get headersReady() {
  60704. return this._headersReady;
  60705. },
  60706. get isRangeSupported() {
  60707. return this._stream._isRangeSupported;
  60708. },
  60709. get isStreamingSupported() {
  60710. return this._stream._isStreamingSupported;
  60711. },
  60712. get contentLength() {
  60713. return this._stream._contentLength;
  60714. },
  60715. read: function PDFWorkerStreamReader_read() {
  60716. if (this._queuedChunks.length > 0) {
  60717. var chunk = this._queuedChunks.shift();
  60718. return Promise.resolve({
  60719. value: chunk,
  60720. done: false
  60721. });
  60722. }
  60723. if (this._done) {
  60724. return Promise.resolve({
  60725. value: undefined,
  60726. done: true
  60727. });
  60728. }
  60729. var requestCapability = createPromiseCapability();
  60730. this._requests.push(requestCapability);
  60731. return requestCapability.promise;
  60732. },
  60733. cancel: function PDFWorkerStreamReader_cancel(reason) {
  60734. this._done = true;
  60735. this._requests.forEach(function (requestCapability) {
  60736. requestCapability.resolve({
  60737. value: undefined,
  60738. done: true
  60739. });
  60740. });
  60741. this._requests = [];
  60742. }
  60743. };
  60744. /** @implements {IPDFStreamRangeReader} */
  60745. function PDFWorkerStreamRangeReader(stream, begin, end) {
  60746. this._stream = stream;
  60747. this._begin = begin;
  60748. this._end = end;
  60749. this._queuedChunk = null;
  60750. this._requests = [];
  60751. this._done = false;
  60752. this.onProgress = null;
  60753. }
  60754. PDFWorkerStreamRangeReader.prototype = {
  60755. _enqueue: function PDFWorkerStreamRangeReader_enqueue(chunk) {
  60756. if (this._done) {
  60757. return;
  60758. }
  60759. // ignore new data
  60760. if (this._requests.length === 0) {
  60761. this._queuedChunk = chunk;
  60762. } else {
  60763. var requestsCapability = this._requests.shift();
  60764. requestsCapability.resolve({
  60765. value: chunk,
  60766. done: false
  60767. });
  60768. this._requests.forEach(function (requestCapability) {
  60769. requestCapability.resolve({
  60770. value: undefined,
  60771. done: true
  60772. });
  60773. });
  60774. this._requests = [];
  60775. }
  60776. this._done = true;
  60777. this._stream._removeRangeReader(this);
  60778. },
  60779. get isStreamingSupported() {
  60780. return false;
  60781. },
  60782. read: function PDFWorkerStreamRangeReader_read() {
  60783. if (this._queuedChunk) {
  60784. return Promise.resolve({
  60785. value: this._queuedChunk,
  60786. done: false
  60787. });
  60788. }
  60789. if (this._done) {
  60790. return Promise.resolve({
  60791. value: undefined,
  60792. done: true
  60793. });
  60794. }
  60795. var requestCapability = createPromiseCapability();
  60796. this._requests.push(requestCapability);
  60797. return requestCapability.promise;
  60798. },
  60799. cancel: function PDFWorkerStreamRangeReader_cancel(reason) {
  60800. this._done = true;
  60801. this._requests.forEach(function (requestCapability) {
  60802. requestCapability.resolve({
  60803. value: undefined,
  60804. done: true
  60805. });
  60806. });
  60807. this._requests = [];
  60808. this._stream._removeRangeReader(this);
  60809. }
  60810. };
  60811. return PDFWorkerStream;
  60812. }();
  60813. /** @type IPDFStream */
  60814. var PDFNetworkStream;
  60815. /**
  60816. * Sets PDFNetworkStream class to be used as alternative PDF data transport.
  60817. * @param {IPDFStream} cls - the PDF data transport.
  60818. */
  60819. function setPDFNetworkStreamClass(cls) {
  60820. PDFNetworkStream = cls;
  60821. }
  60822. var WorkerMessageHandler = {
  60823. setup: function wphSetup(handler, port) {
  60824. var testMessageProcessed = false;
  60825. handler.on('test', function wphSetupTest(data) {
  60826. if (testMessageProcessed) {
  60827. return;
  60828. }
  60829. // we already processed 'test' message once
  60830. testMessageProcessed = true;
  60831. // check if Uint8Array can be sent to worker
  60832. if (!(data instanceof Uint8Array)) {
  60833. handler.send('test', 'main', false);
  60834. return;
  60835. }
  60836. // making sure postMessage transfers are working
  60837. var supportTransfers = data[0] === 255;
  60838. handler.postMessageTransfers = supportTransfers;
  60839. // check if the response property is supported by xhr
  60840. var xhr = new XMLHttpRequest();
  60841. var responseExists = 'response' in xhr;
  60842. // check if the property is actually implemented
  60843. try {
  60844. var dummy = xhr.responseType;
  60845. } catch (e) {
  60846. responseExists = false;
  60847. }
  60848. if (!responseExists) {
  60849. handler.send('test', false);
  60850. return;
  60851. }
  60852. handler.send('test', {
  60853. supportTypedArray: true,
  60854. supportTransfers: supportTransfers
  60855. });
  60856. });
  60857. handler.on('configure', function wphConfigure(data) {
  60858. setVerbosityLevel(data.verbosity);
  60859. });
  60860. handler.on('GetDocRequest', function wphSetupDoc(data) {
  60861. return WorkerMessageHandler.createDocumentHandler(data, port);
  60862. });
  60863. },
  60864. createDocumentHandler: function wphCreateDocumentHandler(docParams, port) {
  60865. // This context is actually holds references on pdfManager and handler,
  60866. // until the latter is destroyed.
  60867. var pdfManager;
  60868. var terminated = false;
  60869. var cancelXHRs = null;
  60870. var WorkerTasks = [];
  60871. var docId = docParams.docId;
  60872. var docBaseUrl = docParams.docBaseUrl;
  60873. var workerHandlerName = docParams.docId + '_worker';
  60874. var handler = new MessageHandler(workerHandlerName, docId, port);
  60875. // Ensure that postMessage transfers are correctly enabled/disabled,
  60876. // to prevent "DataCloneError" in older versions of IE (see issue 6957).
  60877. handler.postMessageTransfers = docParams.postMessageTransfers;
  60878. function ensureNotTerminated() {
  60879. if (terminated) {
  60880. throw new Error('Worker was terminated');
  60881. }
  60882. }
  60883. function startWorkerTask(task) {
  60884. WorkerTasks.push(task);
  60885. }
  60886. function finishWorkerTask(task) {
  60887. task.finish();
  60888. var i = WorkerTasks.indexOf(task);
  60889. WorkerTasks.splice(i, 1);
  60890. }
  60891. function loadDocument(recoveryMode) {
  60892. var loadDocumentCapability = createPromiseCapability();
  60893. var parseSuccess = function parseSuccess() {
  60894. var numPagesPromise = pdfManager.ensureDoc('numPages');
  60895. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  60896. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  60897. Promise.all([
  60898. numPagesPromise,
  60899. fingerprintPromise,
  60900. encryptedPromise
  60901. ]).then(function onDocReady(results) {
  60902. var doc = {
  60903. numPages: results[0],
  60904. fingerprint: results[1],
  60905. encrypted: !!results[2]
  60906. };
  60907. loadDocumentCapability.resolve(doc);
  60908. }, parseFailure);
  60909. };
  60910. var parseFailure = function parseFailure(e) {
  60911. loadDocumentCapability.reject(e);
  60912. };
  60913. pdfManager.ensureDoc('checkHeader', []).then(function () {
  60914. pdfManager.ensureDoc('parseStartXRef', []).then(function () {
  60915. pdfManager.ensureDoc('parse', [recoveryMode]).then(parseSuccess, parseFailure);
  60916. }, parseFailure);
  60917. }, parseFailure);
  60918. return loadDocumentCapability.promise;
  60919. }
  60920. function getPdfManager(data, evaluatorOptions) {
  60921. var pdfManagerCapability = createPromiseCapability();
  60922. var pdfManager;
  60923. var source = data.source;
  60924. if (source.data) {
  60925. try {
  60926. pdfManager = new LocalPdfManager(docId, source.data, source.password, evaluatorOptions, docBaseUrl);
  60927. pdfManagerCapability.resolve(pdfManager);
  60928. } catch (ex) {
  60929. pdfManagerCapability.reject(ex);
  60930. }
  60931. return pdfManagerCapability.promise;
  60932. }
  60933. var pdfStream;
  60934. try {
  60935. if (source.chunkedViewerLoading) {
  60936. pdfStream = new PDFWorkerStream(source, handler);
  60937. } else {
  60938. assert(PDFNetworkStream, 'pdfjs/core/network module is not loaded');
  60939. pdfStream = new PDFNetworkStream(data);
  60940. }
  60941. } catch (ex) {
  60942. pdfManagerCapability.reject(ex);
  60943. return pdfManagerCapability.promise;
  60944. }
  60945. var fullRequest = pdfStream.getFullReader();
  60946. fullRequest.headersReady.then(function () {
  60947. if (!fullRequest.isStreamingSupported || !fullRequest.isRangeSupported) {
  60948. // If stream or range are disabled, it's our only way to report
  60949. // loading progress.
  60950. fullRequest.onProgress = function (evt) {
  60951. handler.send('DocProgress', {
  60952. loaded: evt.loaded,
  60953. total: evt.total
  60954. });
  60955. };
  60956. }
  60957. if (!fullRequest.isRangeSupported) {
  60958. return;
  60959. }
  60960. // We don't need auto-fetch when streaming is enabled.
  60961. var disableAutoFetch = source.disableAutoFetch || fullRequest.isStreamingSupported;
  60962. pdfManager = new NetworkPdfManager(docId, pdfStream, {
  60963. msgHandler: handler,
  60964. url: source.url,
  60965. password: source.password,
  60966. length: fullRequest.contentLength,
  60967. disableAutoFetch: disableAutoFetch,
  60968. rangeChunkSize: source.rangeChunkSize
  60969. }, evaluatorOptions, docBaseUrl);
  60970. pdfManagerCapability.resolve(pdfManager);
  60971. cancelXHRs = null;
  60972. }).catch(function (reason) {
  60973. pdfManagerCapability.reject(reason);
  60974. cancelXHRs = null;
  60975. });
  60976. var cachedChunks = [], loaded = 0;
  60977. var flushChunks = function () {
  60978. var pdfFile = arraysToBytes(cachedChunks);
  60979. if (source.length && pdfFile.length !== source.length) {
  60980. warn('reported HTTP length is different from actual');
  60981. }
  60982. // the data is array, instantiating directly from it
  60983. try {
  60984. pdfManager = new LocalPdfManager(docId, pdfFile, source.password, evaluatorOptions, docBaseUrl);
  60985. pdfManagerCapability.resolve(pdfManager);
  60986. } catch (ex) {
  60987. pdfManagerCapability.reject(ex);
  60988. }
  60989. cachedChunks = [];
  60990. };
  60991. var readPromise = new Promise(function (resolve, reject) {
  60992. var readChunk = function (chunk) {
  60993. try {
  60994. ensureNotTerminated();
  60995. if (chunk.done) {
  60996. if (!pdfManager) {
  60997. flushChunks();
  60998. }
  60999. cancelXHRs = null;
  61000. return;
  61001. }
  61002. var data = chunk.value;
  61003. loaded += arrayByteLength(data);
  61004. if (!fullRequest.isStreamingSupported) {
  61005. handler.send('DocProgress', {
  61006. loaded: loaded,
  61007. total: Math.max(loaded, fullRequest.contentLength || 0)
  61008. });
  61009. }
  61010. if (pdfManager) {
  61011. pdfManager.sendProgressiveData(data);
  61012. } else {
  61013. cachedChunks.push(data);
  61014. }
  61015. fullRequest.read().then(readChunk, reject);
  61016. } catch (e) {
  61017. reject(e);
  61018. }
  61019. };
  61020. fullRequest.read().then(readChunk, reject);
  61021. });
  61022. readPromise.catch(function (e) {
  61023. pdfManagerCapability.reject(e);
  61024. cancelXHRs = null;
  61025. });
  61026. cancelXHRs = function () {
  61027. pdfStream.cancelAllRequests('abort');
  61028. };
  61029. return pdfManagerCapability.promise;
  61030. }
  61031. var setupDoc = function (data) {
  61032. var onSuccess = function (doc) {
  61033. ensureNotTerminated();
  61034. handler.send('GetDoc', { pdfInfo: doc });
  61035. };
  61036. var onFailure = function (e) {
  61037. if (e instanceof PasswordException) {
  61038. if (e.code === PasswordResponses.NEED_PASSWORD) {
  61039. handler.send('NeedPassword', e);
  61040. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  61041. handler.send('IncorrectPassword', e);
  61042. }
  61043. } else if (e instanceof InvalidPDFException) {
  61044. handler.send('InvalidPDF', e);
  61045. } else if (e instanceof MissingPDFException) {
  61046. handler.send('MissingPDF', e);
  61047. } else if (e instanceof UnexpectedResponseException) {
  61048. handler.send('UnexpectedResponse', e);
  61049. } else {
  61050. handler.send('UnknownError', new UnknownErrorException(e.message, e.toString()));
  61051. }
  61052. };
  61053. ensureNotTerminated();
  61054. var cMapOptions = {
  61055. url: data.cMapUrl === undefined ? null : data.cMapUrl,
  61056. packed: data.cMapPacked === true
  61057. };
  61058. var evaluatorOptions = {
  61059. forceDataSchema: data.disableCreateObjectURL,
  61060. maxImageSize: data.maxImageSize === undefined ? -1 : data.maxImageSize,
  61061. disableFontFace: data.disableFontFace,
  61062. cMapOptions: cMapOptions
  61063. };
  61064. getPdfManager(data, evaluatorOptions).then(function (newPdfManager) {
  61065. if (terminated) {
  61066. // We were in a process of setting up the manager, but it got
  61067. // terminated in the middle.
  61068. newPdfManager.terminate();
  61069. throw new Error('Worker was terminated');
  61070. }
  61071. pdfManager = newPdfManager;
  61072. handler.send('PDFManagerReady', null);
  61073. pdfManager.onLoadedStream().then(function (stream) {
  61074. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  61075. });
  61076. }).then(function pdfManagerReady() {
  61077. ensureNotTerminated();
  61078. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  61079. ensureNotTerminated();
  61080. // Try again with recoveryMode == true
  61081. if (!(ex instanceof XRefParseException)) {
  61082. if (ex instanceof PasswordException) {
  61083. // after password exception prepare to receive a new password
  61084. // to repeat loading
  61085. pdfManager.passwordChanged().then(pdfManagerReady);
  61086. }
  61087. onFailure(ex);
  61088. return;
  61089. }
  61090. pdfManager.requestLoadedStream();
  61091. pdfManager.onLoadedStream().then(function () {
  61092. ensureNotTerminated();
  61093. loadDocument(true).then(onSuccess, onFailure);
  61094. });
  61095. }, onFailure);
  61096. }, onFailure);
  61097. };
  61098. handler.on('GetPage', function wphSetupGetPage(data) {
  61099. return pdfManager.getPage(data.pageIndex).then(function (page) {
  61100. var rotatePromise = pdfManager.ensure(page, 'rotate');
  61101. var refPromise = pdfManager.ensure(page, 'ref');
  61102. var viewPromise = pdfManager.ensure(page, 'view');
  61103. return Promise.all([
  61104. rotatePromise,
  61105. refPromise,
  61106. viewPromise
  61107. ]).then(function (results) {
  61108. return {
  61109. rotate: results[0],
  61110. ref: results[1],
  61111. view: results[2]
  61112. };
  61113. });
  61114. });
  61115. });
  61116. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  61117. var ref = new Ref(data.ref.num, data.ref.gen);
  61118. var catalog = pdfManager.pdfDocument.catalog;
  61119. return catalog.getPageIndex(ref);
  61120. });
  61121. handler.on('GetDestinations', function wphSetupGetDestinations(data) {
  61122. return pdfManager.ensureCatalog('destinations');
  61123. });
  61124. handler.on('GetDestination', function wphSetupGetDestination(data) {
  61125. return pdfManager.ensureCatalog('getDestination', [data.id]);
  61126. });
  61127. handler.on('GetPageLabels', function wphSetupGetPageLabels(data) {
  61128. return pdfManager.ensureCatalog('pageLabels');
  61129. });
  61130. handler.on('GetAttachments', function wphSetupGetAttachments(data) {
  61131. return pdfManager.ensureCatalog('attachments');
  61132. });
  61133. handler.on('GetJavaScript', function wphSetupGetJavaScript(data) {
  61134. return pdfManager.ensureCatalog('javaScript');
  61135. });
  61136. handler.on('GetOutline', function wphSetupGetOutline(data) {
  61137. return pdfManager.ensureCatalog('documentOutline');
  61138. });
  61139. handler.on('GetMetadata', function wphSetupGetMetadata(data) {
  61140. return Promise.all([
  61141. pdfManager.ensureDoc('documentInfo'),
  61142. pdfManager.ensureCatalog('metadata')
  61143. ]);
  61144. });
  61145. handler.on('GetData', function wphSetupGetData(data) {
  61146. pdfManager.requestLoadedStream();
  61147. return pdfManager.onLoadedStream().then(function (stream) {
  61148. return stream.bytes;
  61149. });
  61150. });
  61151. handler.on('GetStats', function wphSetupGetStats(data) {
  61152. return pdfManager.pdfDocument.xref.stats;
  61153. });
  61154. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  61155. pdfManager.updatePassword(data);
  61156. });
  61157. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  61158. return pdfManager.getPage(data.pageIndex).then(function (page) {
  61159. return pdfManager.ensure(page, 'getAnnotationsData', [data.intent]);
  61160. });
  61161. });
  61162. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  61163. var pageIndex = data.pageIndex;
  61164. pdfManager.getPage(pageIndex).then(function (page) {
  61165. var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
  61166. startWorkerTask(task);
  61167. var pageNum = pageIndex + 1;
  61168. var start = Date.now();
  61169. // Pre compile the pdf page and fetch the fonts/images.
  61170. page.getOperatorList(handler, task, data.intent, data.renderInteractiveForms).then(function (operatorList) {
  61171. finishWorkerTask(task);
  61172. info('page=' + pageNum + ' - getOperatorList: time=' + (Date.now() - start) + 'ms, len=' + operatorList.totalLength);
  61173. }, function (e) {
  61174. finishWorkerTask(task);
  61175. if (task.terminated) {
  61176. return;
  61177. }
  61178. // ignoring errors from the terminated thread
  61179. // For compatibility with older behavior, generating unknown
  61180. // unsupported feature notification on errors.
  61181. handler.send('UnsupportedFeature', { featureId: UNSUPPORTED_FEATURES.unknown });
  61182. var minimumStackMessage = 'worker.js: while trying to getPage() and getOperatorList()';
  61183. var wrappedException;
  61184. // Turn the error into an obj that can be serialized
  61185. if (typeof e === 'string') {
  61186. wrappedException = {
  61187. message: e,
  61188. stack: minimumStackMessage
  61189. };
  61190. } else if (typeof e === 'object') {
  61191. wrappedException = {
  61192. message: e.message || e.toString(),
  61193. stack: e.stack || minimumStackMessage
  61194. };
  61195. } else {
  61196. wrappedException = {
  61197. message: 'Unknown exception type: ' + typeof e,
  61198. stack: minimumStackMessage
  61199. };
  61200. }
  61201. handler.send('PageError', {
  61202. pageNum: pageNum,
  61203. error: wrappedException,
  61204. intent: data.intent
  61205. });
  61206. });
  61207. });
  61208. }, this);
  61209. handler.on('GetTextContent', function wphExtractText(data) {
  61210. var pageIndex = data.pageIndex;
  61211. var normalizeWhitespace = data.normalizeWhitespace;
  61212. var combineTextItems = data.combineTextItems;
  61213. return pdfManager.getPage(pageIndex).then(function (page) {
  61214. var task = new WorkerTask('GetTextContent: page ' + pageIndex);
  61215. startWorkerTask(task);
  61216. var pageNum = pageIndex + 1;
  61217. var start = Date.now();
  61218. return page.extractTextContent(task, normalizeWhitespace, combineTextItems).then(function (textContent) {
  61219. finishWorkerTask(task);
  61220. info('text indexing: page=' + pageNum + ' - time=' + (Date.now() - start) + 'ms');
  61221. return textContent;
  61222. }, function (reason) {
  61223. finishWorkerTask(task);
  61224. if (task.terminated) {
  61225. return;
  61226. }
  61227. // ignoring errors from the terminated thread
  61228. throw reason;
  61229. });
  61230. });
  61231. });
  61232. handler.on('Cleanup', function wphCleanup(data) {
  61233. return pdfManager.cleanup();
  61234. });
  61235. handler.on('Terminate', function wphTerminate(data) {
  61236. terminated = true;
  61237. if (pdfManager) {
  61238. pdfManager.terminate();
  61239. pdfManager = null;
  61240. }
  61241. if (cancelXHRs) {
  61242. cancelXHRs();
  61243. }
  61244. var waitOn = [];
  61245. WorkerTasks.forEach(function (task) {
  61246. waitOn.push(task.finished);
  61247. task.terminate();
  61248. });
  61249. return Promise.all(waitOn).then(function () {
  61250. // Notice that even if we destroying handler, resolved response promise
  61251. // must be sent back.
  61252. handler.destroy();
  61253. handler = null;
  61254. });
  61255. });
  61256. handler.on('Ready', function wphReady(data) {
  61257. setupDoc(docParams);
  61258. docParams = null;
  61259. });
  61260. // we don't need docParams anymore -- saving memory.
  61261. return workerHandlerName;
  61262. }
  61263. };
  61264. function initializeWorker() {
  61265. if (!('console' in globalScope)) {
  61266. var consoleTimer = {};
  61267. var workerConsole = {
  61268. log: function log() {
  61269. var args = Array.prototype.slice.call(arguments);
  61270. globalScope.postMessage({
  61271. targetName: 'main',
  61272. action: 'console_log',
  61273. data: args
  61274. });
  61275. },
  61276. error: function error() {
  61277. var args = Array.prototype.slice.call(arguments);
  61278. globalScope.postMessage({
  61279. targetName: 'main',
  61280. action: 'console_error',
  61281. data: args
  61282. });
  61283. throw 'pdf.js execution error';
  61284. },
  61285. time: function time(name) {
  61286. consoleTimer[name] = Date.now();
  61287. },
  61288. timeEnd: function timeEnd(name) {
  61289. var time = consoleTimer[name];
  61290. if (!time) {
  61291. error('Unknown timer name ' + name);
  61292. }
  61293. this.log('Timer:', name, Date.now() - time);
  61294. }
  61295. };
  61296. globalScope.console = workerConsole;
  61297. }
  61298. var handler = new MessageHandler('worker', 'main', self);
  61299. WorkerMessageHandler.setup(handler, self);
  61300. handler.send('ready', null);
  61301. }
  61302. // Worker thread (and not node.js)?
  61303. if (typeof window === 'undefined' && !(typeof module !== 'undefined' && module.require)) {
  61304. initializeWorker();
  61305. }
  61306. exports.setPDFNetworkStreamClass = setPDFNetworkStreamClass;
  61307. exports.WorkerTask = WorkerTask;
  61308. exports.WorkerMessageHandler = WorkerMessageHandler;
  61309. }));
  61310. (function (root, factory) {
  61311. factory(root.pdfjsCoreNetwork = {}, root.pdfjsSharedUtil, root.pdfjsCoreWorker);
  61312. }(this, function (exports, sharedUtil, coreWorker) {
  61313. var OK_RESPONSE = 200;
  61314. var PARTIAL_CONTENT_RESPONSE = 206;
  61315. function NetworkManager(url, args) {
  61316. this.url = url;
  61317. args = args || {};
  61318. this.isHttp = /^https?:/i.test(url);
  61319. this.httpHeaders = this.isHttp && args.httpHeaders || {};
  61320. this.withCredentials = args.withCredentials || false;
  61321. this.getXhr = args.getXhr || function NetworkManager_getXhr() {
  61322. return new XMLHttpRequest();
  61323. };
  61324. this.currXhrId = 0;
  61325. this.pendingRequests = Object.create(null);
  61326. this.loadedRequests = Object.create(null);
  61327. }
  61328. function getArrayBuffer(xhr) {
  61329. var data = xhr.response;
  61330. if (typeof data !== 'string') {
  61331. return data;
  61332. }
  61333. var length = data.length;
  61334. var array = new Uint8Array(length);
  61335. for (var i = 0; i < length; i++) {
  61336. array[i] = data.charCodeAt(i) & 0xFF;
  61337. }
  61338. return array.buffer;
  61339. }
  61340. var supportsMozChunked = function supportsMozChunkedClosure() {
  61341. try {
  61342. var x = new XMLHttpRequest();
  61343. // Firefox 37- required .open() to be called before setting responseType.
  61344. // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
  61345. // Even though the URL is not visited, .open() could fail if the URL is
  61346. // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
  61347. // When this error occurs, this feature detection method will mistakenly
  61348. // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
  61349. x.open('GET', 'https://example.com');
  61350. x.responseType = 'moz-chunked-arraybuffer';
  61351. return x.responseType === 'moz-chunked-arraybuffer';
  61352. } catch (e) {
  61353. return false;
  61354. }
  61355. }();
  61356. NetworkManager.prototype = {
  61357. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  61358. var args = {
  61359. begin: begin,
  61360. end: end
  61361. };
  61362. for (var prop in listeners) {
  61363. args[prop] = listeners[prop];
  61364. }
  61365. return this.request(args);
  61366. },
  61367. requestFull: function NetworkManager_requestFull(listeners) {
  61368. return this.request(listeners);
  61369. },
  61370. request: function NetworkManager_request(args) {
  61371. var xhr = this.getXhr();
  61372. var xhrId = this.currXhrId++;
  61373. var pendingRequest = this.pendingRequests[xhrId] = { xhr: xhr };
  61374. xhr.open('GET', this.url);
  61375. xhr.withCredentials = this.withCredentials;
  61376. for (var property in this.httpHeaders) {
  61377. var value = this.httpHeaders[property];
  61378. if (typeof value === 'undefined') {
  61379. continue;
  61380. }
  61381. xhr.setRequestHeader(property, value);
  61382. }
  61383. if (this.isHttp && 'begin' in args && 'end' in args) {
  61384. var rangeStr = args.begin + '-' + (args.end - 1);
  61385. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  61386. pendingRequest.expectedStatus = 206;
  61387. } else {
  61388. pendingRequest.expectedStatus = 200;
  61389. }
  61390. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  61391. if (useMozChunkedLoading) {
  61392. xhr.responseType = 'moz-chunked-arraybuffer';
  61393. pendingRequest.onProgressiveData = args.onProgressiveData;
  61394. pendingRequest.mozChunked = true;
  61395. } else {
  61396. xhr.responseType = 'arraybuffer';
  61397. }
  61398. if (args.onError) {
  61399. xhr.onerror = function (evt) {
  61400. args.onError(xhr.status);
  61401. };
  61402. }
  61403. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  61404. xhr.onprogress = this.onProgress.bind(this, xhrId);
  61405. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  61406. pendingRequest.onDone = args.onDone;
  61407. pendingRequest.onError = args.onError;
  61408. pendingRequest.onProgress = args.onProgress;
  61409. xhr.send(null);
  61410. return xhrId;
  61411. },
  61412. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  61413. var pendingRequest = this.pendingRequests[xhrId];
  61414. if (!pendingRequest) {
  61415. // Maybe abortRequest was called...
  61416. return;
  61417. }
  61418. if (pendingRequest.mozChunked) {
  61419. var chunk = getArrayBuffer(pendingRequest.xhr);
  61420. pendingRequest.onProgressiveData(chunk);
  61421. }
  61422. var onProgress = pendingRequest.onProgress;
  61423. if (onProgress) {
  61424. onProgress(evt);
  61425. }
  61426. },
  61427. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  61428. var pendingRequest = this.pendingRequests[xhrId];
  61429. if (!pendingRequest) {
  61430. // Maybe abortRequest was called...
  61431. return;
  61432. }
  61433. var xhr = pendingRequest.xhr;
  61434. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  61435. pendingRequest.onHeadersReceived();
  61436. delete pendingRequest.onHeadersReceived;
  61437. }
  61438. if (xhr.readyState !== 4) {
  61439. return;
  61440. }
  61441. if (!(xhrId in this.pendingRequests)) {
  61442. // The XHR request might have been aborted in onHeadersReceived()
  61443. // callback, in which case we should abort request
  61444. return;
  61445. }
  61446. delete this.pendingRequests[xhrId];
  61447. // success status == 0 can be on ftp, file and other protocols
  61448. if (xhr.status === 0 && this.isHttp) {
  61449. if (pendingRequest.onError) {
  61450. pendingRequest.onError(xhr.status);
  61451. }
  61452. return;
  61453. }
  61454. var xhrStatus = xhr.status || OK_RESPONSE;
  61455. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  61456. // "A server MAY ignore the Range header". This means it's possible to
  61457. // get a 200 rather than a 206 response from a range request.
  61458. var ok_response_on_range_request = xhrStatus === OK_RESPONSE && pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  61459. if (!ok_response_on_range_request && xhrStatus !== pendingRequest.expectedStatus) {
  61460. if (pendingRequest.onError) {
  61461. pendingRequest.onError(xhr.status);
  61462. }
  61463. return;
  61464. }
  61465. this.loadedRequests[xhrId] = true;
  61466. var chunk = getArrayBuffer(xhr);
  61467. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  61468. var rangeHeader = xhr.getResponseHeader('Content-Range');
  61469. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  61470. var begin = parseInt(matches[1], 10);
  61471. pendingRequest.onDone({
  61472. begin: begin,
  61473. chunk: chunk
  61474. });
  61475. } else if (pendingRequest.onProgressiveData) {
  61476. pendingRequest.onDone(null);
  61477. } else if (chunk) {
  61478. pendingRequest.onDone({
  61479. begin: 0,
  61480. chunk: chunk
  61481. });
  61482. } else if (pendingRequest.onError) {
  61483. pendingRequest.onError(xhr.status);
  61484. }
  61485. },
  61486. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  61487. for (var xhrId in this.pendingRequests) {
  61488. return true;
  61489. }
  61490. return false;
  61491. },
  61492. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  61493. return this.pendingRequests[xhrId].xhr;
  61494. },
  61495. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  61496. return !!this.pendingRequests[xhrId].onProgressiveData;
  61497. },
  61498. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  61499. return xhrId in this.pendingRequests;
  61500. },
  61501. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  61502. return xhrId in this.loadedRequests;
  61503. },
  61504. abortAllRequests: function NetworkManager_abortAllRequests() {
  61505. for (var xhrId in this.pendingRequests) {
  61506. this.abortRequest(xhrId | 0);
  61507. }
  61508. },
  61509. abortRequest: function NetworkManager_abortRequest(xhrId) {
  61510. var xhr = this.pendingRequests[xhrId].xhr;
  61511. delete this.pendingRequests[xhrId];
  61512. xhr.abort();
  61513. }
  61514. };
  61515. var assert = sharedUtil.assert;
  61516. var createPromiseCapability = sharedUtil.createPromiseCapability;
  61517. var isInt = sharedUtil.isInt;
  61518. var MissingPDFException = sharedUtil.MissingPDFException;
  61519. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  61520. /** @implements {IPDFStream} */
  61521. function PDFNetworkStream(options) {
  61522. this._options = options;
  61523. var source = options.source;
  61524. this._manager = new NetworkManager(source.url, {
  61525. httpHeaders: source.httpHeaders,
  61526. withCredentials: source.withCredentials
  61527. });
  61528. this._rangeChunkSize = source.rangeChunkSize;
  61529. this._fullRequestReader = null;
  61530. this._rangeRequestReaders = [];
  61531. }
  61532. PDFNetworkStream.prototype = {
  61533. _onRangeRequestReaderClosed: function PDFNetworkStream_onRangeRequestReaderClosed(reader) {
  61534. var i = this._rangeRequestReaders.indexOf(reader);
  61535. if (i >= 0) {
  61536. this._rangeRequestReaders.splice(i, 1);
  61537. }
  61538. },
  61539. getFullReader: function PDFNetworkStream_getFullReader() {
  61540. assert(!this._fullRequestReader);
  61541. this._fullRequestReader = new PDFNetworkStreamFullRequestReader(this._manager, this._options);
  61542. return this._fullRequestReader;
  61543. },
  61544. getRangeReader: function PDFNetworkStream_getRangeReader(begin, end) {
  61545. var reader = new PDFNetworkStreamRangeRequestReader(this._manager, begin, end);
  61546. reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
  61547. this._rangeRequestReaders.push(reader);
  61548. return reader;
  61549. },
  61550. cancelAllRequests: function PDFNetworkStream_cancelAllRequests(reason) {
  61551. if (this._fullRequestReader) {
  61552. this._fullRequestReader.cancel(reason);
  61553. }
  61554. var readers = this._rangeRequestReaders.slice(0);
  61555. readers.forEach(function (reader) {
  61556. reader.cancel(reason);
  61557. });
  61558. }
  61559. };
  61560. /** @implements {IPDFStreamReader} */
  61561. function PDFNetworkStreamFullRequestReader(manager, options) {
  61562. this._manager = manager;
  61563. var source = options.source;
  61564. var args = {
  61565. onHeadersReceived: this._onHeadersReceived.bind(this),
  61566. onProgressiveData: source.disableStream ? null : this._onProgressiveData.bind(this),
  61567. onDone: this._onDone.bind(this),
  61568. onError: this._onError.bind(this),
  61569. onProgress: this._onProgress.bind(this)
  61570. };
  61571. this._url = source.url;
  61572. this._fullRequestId = manager.requestFull(args);
  61573. this._headersReceivedCapability = createPromiseCapability();
  61574. this._disableRange = options.disableRange || false;
  61575. this._contentLength = source.length;
  61576. // optional
  61577. this._rangeChunkSize = source.rangeChunkSize;
  61578. if (!this._rangeChunkSize && !this._disableRange) {
  61579. this._disableRange = true;
  61580. }
  61581. this._isStreamingSupported = false;
  61582. this._isRangeSupported = false;
  61583. this._cachedChunks = [];
  61584. this._requests = [];
  61585. this._done = false;
  61586. this._storedError = undefined;
  61587. this.onProgress = null;
  61588. }
  61589. PDFNetworkStreamFullRequestReader.prototype = {
  61590. _validateRangeRequestCapabilities: function PDFNetworkStreamFullRequestReader_validateRangeRequestCapabilities() {
  61591. if (this._disableRange) {
  61592. return false;
  61593. }
  61594. var networkManager = this._manager;
  61595. var fullRequestXhrId = this._fullRequestId;
  61596. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  61597. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  61598. return false;
  61599. }
  61600. var contentEncoding = fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  61601. if (contentEncoding !== 'identity') {
  61602. return false;
  61603. }
  61604. var length = fullRequestXhr.getResponseHeader('Content-Length');
  61605. length = parseInt(length, 10);
  61606. if (!isInt(length)) {
  61607. return false;
  61608. }
  61609. this._contentLength = length;
  61610. // setting right content length
  61611. if (length <= 2 * this._rangeChunkSize) {
  61612. // The file size is smaller than the size of two chunks, so it does
  61613. // not make any sense to abort the request and retry with a range
  61614. // request.
  61615. return false;
  61616. }
  61617. return true;
  61618. },
  61619. _onHeadersReceived: function PDFNetworkStreamFullRequestReader_onHeadersReceived() {
  61620. if (this._validateRangeRequestCapabilities()) {
  61621. this._isRangeSupported = true;
  61622. }
  61623. var networkManager = this._manager;
  61624. var fullRequestXhrId = this._fullRequestId;
  61625. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  61626. // We can continue fetching when progressive loading is enabled,
  61627. // and we don't need the autoFetch feature.
  61628. this._isStreamingSupported = true;
  61629. } else if (this._isRangeSupported) {
  61630. // NOTE: by cancelling the full request, and then issuing range
  61631. // requests, there will be an issue for sites where you can only
  61632. // request the pdf once. However, if this is the case, then the
  61633. // server should not be returning that it can support range
  61634. // requests.
  61635. networkManager.abortRequest(fullRequestXhrId);
  61636. }
  61637. this._headersReceivedCapability.resolve();
  61638. },
  61639. _onProgressiveData: function PDFNetworkStreamFullRequestReader_onProgressiveData(chunk) {
  61640. if (this._requests.length > 0) {
  61641. var requestCapability = this._requests.shift();
  61642. requestCapability.resolve({
  61643. value: chunk,
  61644. done: false
  61645. });
  61646. } else {
  61647. this._cachedChunks.push(chunk);
  61648. }
  61649. },
  61650. _onDone: function PDFNetworkStreamFullRequestReader_onDone(args) {
  61651. if (args) {
  61652. this._onProgressiveData(args.chunk);
  61653. }
  61654. this._done = true;
  61655. if (this._cachedChunks.length > 0) {
  61656. return;
  61657. }
  61658. this._requests.forEach(function (requestCapability) {
  61659. requestCapability.resolve({
  61660. value: undefined,
  61661. done: true
  61662. });
  61663. });
  61664. this._requests = [];
  61665. },
  61666. _onError: function PDFNetworkStreamFullRequestReader_onError(status) {
  61667. var url = this._url;
  61668. var exception;
  61669. if (status === 404 || status === 0 && /^file:/.test(url)) {
  61670. exception = new MissingPDFException('Missing PDF "' + url + '".');
  61671. } else {
  61672. exception = new UnexpectedResponseException('Unexpected server response (' + status + ') while retrieving PDF "' + url + '".', status);
  61673. }
  61674. this._storedError = exception;
  61675. this._headersReceivedCapability.reject(exception);
  61676. this._requests.forEach(function (requestCapability) {
  61677. requestCapability.reject(exception);
  61678. });
  61679. this._requests = [];
  61680. this._cachedChunks = [];
  61681. },
  61682. _onProgress: function PDFNetworkStreamFullRequestReader_onProgress(data) {
  61683. if (this.onProgress) {
  61684. this.onProgress({
  61685. loaded: data.loaded,
  61686. total: data.lengthComputable ? data.total : this._contentLength
  61687. });
  61688. }
  61689. },
  61690. get isRangeSupported() {
  61691. return this._isRangeSupported;
  61692. },
  61693. get isStreamingSupported() {
  61694. return this._isStreamingSupported;
  61695. },
  61696. get contentLength() {
  61697. return this._contentLength;
  61698. },
  61699. get headersReady() {
  61700. return this._headersReceivedCapability.promise;
  61701. },
  61702. read: function PDFNetworkStreamFullRequestReader_read() {
  61703. if (this._storedError) {
  61704. return Promise.reject(this._storedError);
  61705. }
  61706. if (this._cachedChunks.length > 0) {
  61707. var chunk = this._cachedChunks.shift();
  61708. return Promise.resolve(chunk);
  61709. }
  61710. if (this._done) {
  61711. return Promise.resolve({
  61712. value: undefined,
  61713. done: true
  61714. });
  61715. }
  61716. var requestCapability = createPromiseCapability();
  61717. this._requests.push(requestCapability);
  61718. return requestCapability.promise;
  61719. },
  61720. cancel: function PDFNetworkStreamFullRequestReader_cancel(reason) {
  61721. this._done = true;
  61722. this._headersReceivedCapability.reject(reason);
  61723. this._requests.forEach(function (requestCapability) {
  61724. requestCapability.resolve({
  61725. value: undefined,
  61726. done: true
  61727. });
  61728. });
  61729. this._requests = [];
  61730. if (this._manager.isPendingRequest(this._fullRequestId)) {
  61731. this._manager.abortRequest(this._fullRequestId);
  61732. }
  61733. this._fullRequestReader = null;
  61734. }
  61735. };
  61736. /** @implements {IPDFStreamRangeReader} */
  61737. function PDFNetworkStreamRangeRequestReader(manager, begin, end) {
  61738. this._manager = manager;
  61739. var args = {
  61740. onDone: this._onDone.bind(this),
  61741. onProgress: this._onProgress.bind(this)
  61742. };
  61743. this._requestId = manager.requestRange(begin, end, args);
  61744. this._requests = [];
  61745. this._queuedChunk = null;
  61746. this._done = false;
  61747. this.onProgress = null;
  61748. this.onClosed = null;
  61749. }
  61750. PDFNetworkStreamRangeRequestReader.prototype = {
  61751. _close: function PDFNetworkStreamRangeRequestReader_close() {
  61752. if (this.onClosed) {
  61753. this.onClosed(this);
  61754. }
  61755. },
  61756. _onDone: function PDFNetworkStreamRangeRequestReader_onDone(data) {
  61757. var chunk = data.chunk;
  61758. if (this._requests.length > 0) {
  61759. var requestCapability = this._requests.shift();
  61760. requestCapability.resolve({
  61761. value: chunk,
  61762. done: false
  61763. });
  61764. } else {
  61765. this._queuedChunk = chunk;
  61766. }
  61767. this._done = true;
  61768. this._requests.forEach(function (requestCapability) {
  61769. requestCapability.resolve({
  61770. value: undefined,
  61771. done: true
  61772. });
  61773. });
  61774. this._requests = [];
  61775. this._close();
  61776. },
  61777. _onProgress: function PDFNetworkStreamRangeRequestReader_onProgress(evt) {
  61778. if (!this.isStreamingSupported && this.onProgress) {
  61779. this.onProgress({ loaded: evt.loaded });
  61780. }
  61781. },
  61782. get isStreamingSupported() {
  61783. return false;
  61784. },
  61785. // TODO allow progressive range bytes loading
  61786. read: function PDFNetworkStreamRangeRequestReader_read() {
  61787. if (this._queuedChunk !== null) {
  61788. var chunk = this._queuedChunk;
  61789. this._queuedChunk = null;
  61790. return Promise.resolve({
  61791. value: chunk,
  61792. done: false
  61793. });
  61794. }
  61795. if (this._done) {
  61796. return Promise.resolve({
  61797. value: undefined,
  61798. done: true
  61799. });
  61800. }
  61801. var requestCapability = createPromiseCapability();
  61802. this._requests.push(requestCapability);
  61803. return requestCapability.promise;
  61804. },
  61805. cancel: function PDFNetworkStreamRangeRequestReader_cancel(reason) {
  61806. this._done = true;
  61807. this._requests.forEach(function (requestCapability) {
  61808. requestCapability.resolve({
  61809. value: undefined,
  61810. done: true
  61811. });
  61812. });
  61813. this._requests = [];
  61814. if (this._manager.isPendingRequest(this._requestId)) {
  61815. this._manager.abortRequest(this._requestId);
  61816. }
  61817. this._close();
  61818. }
  61819. };
  61820. coreWorker.setPDFNetworkStreamClass(PDFNetworkStream);
  61821. exports.PDFNetworkStream = PDFNetworkStream;
  61822. exports.NetworkManager = NetworkManager;
  61823. }));
  61824. }.call(pdfjsLibs));
  61825. exports.PDFJS = pdfjsLibs.pdfjsDisplayGlobal.PDFJS;
  61826. exports.build = pdfjsLibs.pdfjsDisplayAPI.build;
  61827. exports.version = pdfjsLibs.pdfjsDisplayAPI.version;
  61828. exports.getDocument = pdfjsLibs.pdfjsDisplayAPI.getDocument;
  61829. exports.PDFDataRangeTransport = pdfjsLibs.pdfjsDisplayAPI.PDFDataRangeTransport;
  61830. exports.PDFWorker = pdfjsLibs.pdfjsDisplayAPI.PDFWorker;
  61831. exports.renderTextLayer = pdfjsLibs.pdfjsDisplayTextLayer.renderTextLayer;
  61832. exports.AnnotationLayer = pdfjsLibs.pdfjsDisplayAnnotationLayer.AnnotationLayer;
  61833. exports.CustomStyle = pdfjsLibs.pdfjsDisplayDOMUtils.CustomStyle;
  61834. exports.PasswordResponses = pdfjsLibs.pdfjsSharedUtil.PasswordResponses;
  61835. exports.InvalidPDFException = pdfjsLibs.pdfjsSharedUtil.InvalidPDFException;
  61836. exports.MissingPDFException = pdfjsLibs.pdfjsSharedUtil.MissingPDFException;
  61837. exports.SVGGraphics = pdfjsLibs.pdfjsDisplaySVG.SVGGraphics;
  61838. exports.UnexpectedResponseException = pdfjsLibs.pdfjsSharedUtil.UnexpectedResponseException;
  61839. exports.OPS = pdfjsLibs.pdfjsSharedUtil.OPS;
  61840. exports.UNSUPPORTED_FEATURES = pdfjsLibs.pdfjsSharedUtil.UNSUPPORTED_FEATURES;
  61841. exports.isValidUrl = pdfjsLibs.pdfjsDisplayDOMUtils.isValidUrl;
  61842. exports.createValidAbsoluteUrl = pdfjsLibs.pdfjsSharedUtil.createValidAbsoluteUrl;
  61843. exports.createObjectURL = pdfjsLibs.pdfjsSharedUtil.createObjectURL;
  61844. exports.removeNullCharacters = pdfjsLibs.pdfjsSharedUtil.removeNullCharacters;
  61845. exports.shadow = pdfjsLibs.pdfjsSharedUtil.shadow;
  61846. exports.createBlob = pdfjsLibs.pdfjsSharedUtil.createBlob;
  61847. exports.getFilenameFromUrl = pdfjsLibs.pdfjsDisplayDOMUtils.getFilenameFromUrl;
  61848. exports.addLinkAttributes = pdfjsLibs.pdfjsDisplayDOMUtils.addLinkAttributes;
  61849. }));