2
0

pdf.worker.js 1.7 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593385943859538596385973859838599386003860138602386033860438605386063860738608386093861038611386123861338614386153861638617386183861938620386213862238623386243862538626386273862838629386303863138632386333863438635386363863738638386393864038641386423864338644386453864638647386483864938650386513865238653386543865538656386573865838659386603866138662386633866438665386663866738668386693867038671386723867338674386753867638677386783867938680386813868238683386843868538686386873868838689386903869138692386933869438695386963869738698386993870038701387023870338704387053870638707387083870938710387113871238713387143871538716387173871838719387203872138722387233872438725387263872738728387293873038731387323873338734387353873638737387383873938740387413874238743387443874538746387473874838749387503875138752387533875438755387563875738758387593876038761387623876338764387653876638767387683876938770387713877238773387743877538776387773877838779387803878138782387833878438785387863878738788387893879038791387923879338794387953879638797387983879938800388013880238803388043880538806388073880838809388103881138812388133881438815388163881738818388193882038821388223882338824388253882638827388283882938830388313883238833388343883538836388373883838839388403884138842388433884438845388463884738848388493885038851388523885338854388553885638857388583885938860388613886238863388643886538866388673886838869388703887138872388733887438875388763887738878388793888038881388823888338884388853888638887388883888938890388913889238893388943889538896388973889838899389003890138902389033890438905389063890738908389093891038911389123891338914389153891638917389183891938920389213892238923389243892538926389273892838929389303893138932389333893438935389363893738938389393894038941389423894338944389453894638947389483894938950389513895238953389543895538956389573895838959389603896138962389633896438965389663896738968389693897038971389723897338974389753897638977389783897938980389813898238983389843898538986389873898838989389903899138992389933899438995389963899738998389993900039001390023900339004390053900639007390083900939010390113901239013390143901539016390173901839019390203902139022390233902439025390263902739028390293903039031390323903339034390353903639037390383903939040390413904239043390443904539046390473904839049390503905139052390533905439055390563905739058390593906039061390623906339064390653906639067390683906939070390713907239073390743907539076390773907839079390803908139082390833908439085390863908739088390893909039091390923909339094390953909639097390983909939100391013910239103391043910539106391073910839109391103911139112391133911439115391163911739118391193912039121391223912339124391253912639127391283912939130391313913239133391343913539136391373913839139391403914139142391433914439145391463914739148391493915039151391523915339154391553915639157391583915939160391613916239163391643916539166391673916839169391703917139172391733917439175391763917739178391793918039181391823918339184391853918639187391883918939190391913919239193391943919539196391973919839199392003920139202392033920439205392063920739208392093921039211392123921339214392153921639217392183921939220392213922239223392243922539226392273922839229392303923139232392333923439235392363923739238392393924039241392423924339244392453924639247392483924939250392513925239253392543925539256392573925839259392603926139262392633926439265392663926739268392693927039271392723927339274392753927639277392783927939280392813928239283392843928539286392873928839289392903929139292392933929439295392963929739298392993930039301393023930339304393053930639307393083930939310393113931239313393143931539316393173931839319393203932139322393233932439325393263932739328393293933039331393323933339334393353933639337393383933939340393413934239343393443934539346393473934839349393503935139352393533935439355393563935739358393593936039361393623936339364393653936639367393683936939370393713937239373393743937539376393773937839379393803938139382393833938439385393863938739388393893939039391393923939339394393953939639397393983939939400394013940239403394043940539406394073940839409394103941139412394133941439415394163941739418394193942039421394223942339424394253942639427394283942939430394313943239433394343943539436394373943839439394403944139442394433944439445394463944739448394493945039451394523945339454394553945639457394583945939460394613946239463394643946539466394673946839469394703947139472394733947439475394763947739478394793948039481394823948339484394853948639487394883948939490394913949239493394943949539496394973949839499395003950139502395033950439505395063950739508395093951039511395123951339514395153951639517395183951939520395213952239523395243952539526395273952839529395303953139532395333953439535395363953739538395393954039541395423954339544395453954639547395483954939550395513955239553395543955539556395573955839559395603956139562395633956439565395663956739568395693957039571395723957339574395753957639577395783957939580395813958239583395843958539586395873958839589395903959139592395933959439595395963959739598395993960039601396023960339604396053960639607396083960939610396113961239613396143961539616396173961839619396203962139622396233962439625396263962739628396293963039631396323963339634396353963639637396383963939640396413964239643396443964539646396473964839649396503965139652396533965439655396563965739658396593966039661396623966339664396653966639667396683966939670396713967239673396743967539676396773967839679396803968139682396833968439685396863968739688396893969039691396923969339694396953969639697396983969939700397013970239703397043970539706397073970839709397103971139712397133971439715397163971739718397193972039721397223972339724397253972639727397283972939730397313973239733397343973539736397373973839739397403974139742397433974439745397463974739748397493975039751397523975339754397553975639757397583975939760397613976239763397643976539766397673976839769397703977139772397733977439775397763977739778397793978039781397823978339784397853978639787397883978939790397913979239793397943979539796397973979839799398003980139802398033980439805398063980739808398093981039811398123981339814398153981639817398183981939820398213982239823398243982539826398273982839829398303983139832398333983439835398363983739838398393984039841398423984339844398453984639847398483984939850398513985239853398543985539856398573985839859398603986139862398633986439865398663986739868398693987039871398723987339874398753987639877398783987939880398813988239883398843988539886398873988839889398903989139892398933989439895398963989739898398993990039901399023990339904399053990639907399083990939910399113991239913399143991539916399173991839919399203992139922399233992439925399263992739928399293993039931399323993339934399353993639937399383993939940399413994239943399443994539946399473994839949399503995139952399533995439955399563995739958399593996039961399623996339964399653996639967399683996939970399713997239973399743997539976399773997839979399803998139982399833998439985399863998739988399893999039991399923999339994399953999639997399983999940000400014000240003400044000540006400074000840009400104001140012400134001440015400164001740018400194002040021400224002340024400254002640027400284002940030400314003240033400344003540036400374003840039400404004140042400434004440045400464004740048400494005040051400524005340054400554005640057400584005940060400614006240063400644006540066400674006840069400704007140072400734007440075400764007740078400794008040081400824008340084400854008640087400884008940090400914009240093400944009540096400974009840099401004010140102401034010440105401064010740108401094011040111401124011340114401154011640117401184011940120401214012240123401244012540126401274012840129401304013140132401334013440135401364013740138401394014040141401424014340144401454014640147401484014940150401514015240153401544015540156401574015840159401604016140162401634016440165401664016740168401694017040171401724017340174401754017640177401784017940180401814018240183401844018540186401874018840189401904019140192401934019440195401964019740198401994020040201402024020340204402054020640207402084020940210402114021240213402144021540216402174021840219402204022140222402234022440225402264022740228402294023040231402324023340234402354023640237402384023940240402414024240243402444024540246402474024840249402504025140252402534025440255402564025740258402594026040261402624026340264402654026640267402684026940270402714027240273402744027540276402774027840279402804028140282402834028440285402864028740288402894029040291402924029340294402954029640297402984029940300403014030240303403044030540306403074030840309403104031140312403134031440315403164031740318403194032040321403224032340324403254032640327403284032940330403314033240333403344033540336403374033840339403404034140342403434034440345403464034740348403494035040351403524035340354403554035640357403584035940360403614036240363403644036540366403674036840369403704037140372403734037440375403764037740378403794038040381403824038340384403854038640387403884038940390403914039240393403944039540396403974039840399404004040140402404034040440405404064040740408404094041040411404124041340414404154041640417404184041940420404214042240423404244042540426404274042840429404304043140432404334043440435404364043740438404394044040441404424044340444404454044640447404484044940450404514045240453404544045540456404574045840459404604046140462404634046440465404664046740468404694047040471404724047340474404754047640477404784047940480404814048240483404844048540486404874048840489404904049140492404934049440495404964049740498404994050040501405024050340504405054050640507405084050940510405114051240513405144051540516405174051840519405204052140522405234052440525405264052740528405294053040531405324053340534405354053640537405384053940540405414054240543405444054540546405474054840549405504055140552405534055440555405564055740558405594056040561405624056340564405654056640567405684056940570405714057240573405744057540576405774057840579405804058140582405834058440585405864058740588405894059040591405924059340594405954059640597405984059940600406014060240603406044060540606406074060840609406104061140612406134061440615406164061740618406194062040621406224062340624406254062640627406284062940630406314063240633406344063540636406374063840639406404064140642406434064440645406464064740648406494065040651406524065340654406554065640657406584065940660406614066240663406644066540666406674066840669406704067140672406734067440675406764067740678406794068040681406824068340684406854068640687406884068940690406914069240693406944069540696406974069840699407004070140702407034070440705407064070740708407094071040711407124071340714407154071640717407184071940720407214072240723407244072540726407274072840729407304073140732407334073440735407364073740738407394074040741407424074340744407454074640747407484074940750407514075240753407544075540756407574075840759407604076140762407634076440765407664076740768407694077040771407724077340774407754077640777407784077940780407814078240783407844078540786407874078840789407904079140792407934079440795407964079740798407994080040801408024080340804408054080640807408084080940810408114081240813408144081540816408174081840819408204082140822408234082440825408264082740828408294083040831408324083340834408354083640837408384083940840408414084240843408444084540846408474084840849408504085140852408534085440855408564085740858408594086040861408624086340864408654086640867408684086940870408714087240873408744087540876408774087840879408804088140882408834088440885408864088740888408894089040891408924089340894408954089640897408984089940900409014090240903409044090540906409074090840909409104091140912409134091440915409164091740918409194092040921409224092340924409254092640927409284092940930409314093240933409344093540936409374093840939409404094140942409434094440945409464094740948409494095040951409524095340954409554095640957409584095940960409614096240963409644096540966409674096840969409704097140972409734097440975409764097740978409794098040981409824098340984409854098640987409884098940990409914099240993409944099540996409974099840999410004100141002410034100441005410064100741008410094101041011410124101341014410154101641017410184101941020410214102241023410244102541026410274102841029410304103141032410334103441035410364103741038410394104041041410424104341044410454104641047410484104941050410514105241053410544105541056410574105841059410604106141062410634106441065410664106741068410694107041071410724107341074410754107641077410784107941080410814108241083410844108541086410874108841089410904109141092410934109441095410964109741098410994110041101411024110341104411054110641107411084110941110411114111241113411144111541116411174111841119411204112141122411234112441125411264112741128411294113041131411324113341134411354113641137411384113941140411414114241143411444114541146411474114841149411504115141152411534115441155411564115741158411594116041161411624116341164411654116641167411684116941170411714117241173411744117541176411774117841179411804118141182411834118441185411864118741188411894119041191411924119341194411954119641197411984119941200412014120241203412044120541206412074120841209412104121141212412134121441215412164121741218412194122041221412224122341224412254122641227412284122941230412314123241233412344123541236412374123841239412404124141242412434124441245412464124741248412494125041251412524125341254412554125641257412584125941260412614126241263412644126541266412674126841269412704127141272412734127441275412764127741278412794128041281412824128341284412854128641287412884128941290412914129241293412944129541296412974129841299413004130141302413034130441305413064130741308413094131041311413124131341314413154131641317413184131941320413214132241323413244132541326413274132841329413304133141332413334133441335413364133741338413394134041341413424134341344413454134641347413484134941350413514135241353413544135541356413574135841359413604136141362413634136441365413664136741368413694137041371413724137341374413754137641377413784137941380413814138241383413844138541386413874138841389413904139141392413934139441395413964139741398413994140041401414024140341404414054140641407414084140941410414114141241413414144141541416414174141841419414204142141422414234142441425414264142741428414294143041431414324143341434414354143641437414384143941440414414144241443414444144541446414474144841449414504145141452414534145441455414564145741458414594146041461414624146341464414654146641467414684146941470414714147241473414744147541476414774147841479414804148141482414834148441485414864148741488414894149041491414924149341494414954149641497414984149941500415014150241503415044150541506415074150841509415104151141512415134151441515415164151741518415194152041521415224152341524415254152641527415284152941530415314153241533415344153541536415374153841539415404154141542415434154441545415464154741548415494155041551415524155341554415554155641557415584155941560415614156241563415644156541566415674156841569415704157141572415734157441575415764157741578415794158041581415824158341584415854158641587415884158941590415914159241593415944159541596415974159841599416004160141602416034160441605416064160741608416094161041611416124161341614416154161641617416184161941620416214162241623416244162541626416274162841629416304163141632416334163441635416364163741638416394164041641416424164341644416454164641647416484164941650416514165241653416544165541656416574165841659416604166141662416634166441665416664166741668416694167041671416724167341674416754167641677416784167941680416814168241683416844168541686416874168841689416904169141692416934169441695416964169741698416994170041701417024170341704417054170641707417084170941710417114171241713417144171541716417174171841719417204172141722417234172441725417264172741728417294173041731417324173341734417354173641737417384173941740417414174241743417444174541746417474174841749417504175141752417534175441755417564175741758417594176041761417624176341764417654176641767417684176941770417714177241773417744177541776417774177841779417804178141782417834178441785417864178741788417894179041791417924179341794417954179641797417984179941800418014180241803418044180541806418074180841809418104181141812418134181441815418164181741818418194182041821418224182341824418254182641827418284182941830418314183241833418344183541836418374183841839418404184141842418434184441845418464184741848418494185041851418524185341854418554185641857418584185941860418614186241863418644186541866418674186841869418704187141872418734187441875418764187741878418794188041881418824188341884418854188641887418884188941890418914189241893418944189541896418974189841899419004190141902419034190441905419064190741908419094191041911419124191341914419154191641917419184191941920419214192241923419244192541926419274192841929419304193141932419334193441935419364193741938419394194041941419424194341944419454194641947419484194941950419514195241953419544195541956419574195841959419604196141962419634196441965419664196741968419694197041971419724197341974419754197641977419784197941980419814198241983419844198541986419874198841989419904199141992419934199441995419964199741998419994200042001420024200342004420054200642007420084200942010420114201242013420144201542016420174201842019420204202142022420234202442025420264202742028420294203042031420324203342034420354203642037420384203942040420414204242043420444204542046420474204842049420504205142052420534205442055420564205742058420594206042061420624206342064420654206642067420684206942070420714207242073420744207542076420774207842079420804208142082420834208442085420864208742088420894209042091420924209342094420954209642097420984209942100421014210242103421044210542106421074210842109421104211142112421134211442115421164211742118421194212042121421224212342124421254212642127421284212942130421314213242133421344213542136421374213842139421404214142142421434214442145421464214742148421494215042151421524215342154421554215642157421584215942160421614216242163421644216542166421674216842169421704217142172421734217442175421764217742178421794218042181421824218342184421854218642187421884218942190421914219242193421944219542196421974219842199422004220142202422034220442205422064220742208422094221042211422124221342214422154221642217422184221942220422214222242223422244222542226422274222842229422304223142232422334223442235422364223742238422394224042241422424224342244422454224642247422484224942250422514225242253422544225542256422574225842259422604226142262422634226442265422664226742268422694227042271422724227342274422754227642277422784227942280422814228242283422844228542286422874228842289422904229142292422934229442295422964229742298422994230042301423024230342304423054230642307423084230942310423114231242313423144231542316423174231842319423204232142322423234232442325423264232742328423294233042331423324233342334423354233642337423384233942340423414234242343423444234542346423474234842349423504235142352423534235442355423564235742358423594236042361423624236342364423654236642367423684236942370423714237242373423744237542376423774237842379423804238142382423834238442385423864238742388423894239042391423924239342394423954239642397423984239942400424014240242403424044240542406424074240842409424104241142412424134241442415424164241742418424194242042421424224242342424424254242642427424284242942430424314243242433424344243542436424374243842439424404244142442424434244442445424464244742448424494245042451424524245342454424554245642457424584245942460424614246242463424644246542466424674246842469424704247142472424734247442475424764247742478424794248042481424824248342484424854248642487424884248942490424914249242493424944249542496424974249842499425004250142502425034250442505425064250742508425094251042511425124251342514425154251642517425184251942520425214252242523425244252542526425274252842529425304253142532425334253442535425364253742538425394254042541425424254342544425454254642547425484254942550425514255242553425544255542556425574255842559425604256142562425634256442565425664256742568425694257042571425724257342574425754257642577425784257942580425814258242583425844258542586425874258842589425904259142592425934259442595425964259742598425994260042601426024260342604426054260642607426084260942610426114261242613426144261542616426174261842619426204262142622426234262442625426264262742628426294263042631426324263342634426354263642637426384263942640426414264242643426444264542646426474264842649426504265142652426534265442655426564265742658426594266042661426624266342664426654266642667426684266942670426714267242673426744267542676426774267842679426804268142682426834268442685426864268742688426894269042691426924269342694426954269642697426984269942700427014270242703427044270542706427074270842709427104271142712427134271442715427164271742718427194272042721427224272342724427254272642727427284272942730427314273242733427344273542736427374273842739427404274142742427434274442745427464274742748427494275042751427524275342754427554275642757427584275942760427614276242763427644276542766427674276842769427704277142772427734277442775427764277742778427794278042781427824278342784427854278642787427884278942790427914279242793427944279542796427974279842799428004280142802428034280442805428064280742808428094281042811428124281342814428154281642817428184281942820428214282242823428244282542826428274282842829428304283142832428334283442835428364283742838428394284042841428424284342844428454284642847428484284942850428514285242853428544285542856428574285842859428604286142862428634286442865428664286742868428694287042871428724287342874428754287642877428784287942880428814288242883428844288542886428874288842889428904289142892428934289442895428964289742898428994290042901429024290342904429054290642907429084290942910429114291242913429144291542916429174291842919429204292142922429234292442925429264292742928429294293042931429324293342934429354293642937429384293942940429414294242943429444294542946429474294842949429504295142952429534295442955429564295742958429594296042961429624296342964429654296642967429684296942970429714297242973429744297542976429774297842979429804298142982429834298442985429864298742988429894299042991429924299342994429954299642997429984299943000430014300243003430044300543006430074300843009430104301143012430134301443015430164301743018430194302043021430224302343024430254302643027430284302943030430314303243033430344303543036430374303843039430404304143042430434304443045430464304743048430494305043051430524305343054430554305643057430584305943060430614306243063430644306543066430674306843069430704307143072430734307443075430764307743078430794308043081430824308343084430854308643087430884308943090430914309243093430944309543096430974309843099431004310143102431034310443105431064310743108431094311043111431124311343114431154311643117431184311943120431214312243123431244312543126431274312843129431304313143132431334313443135431364313743138431394314043141431424314343144431454314643147431484314943150431514315243153431544315543156431574315843159431604316143162431634316443165431664316743168431694317043171431724317343174431754317643177431784317943180431814318243183431844318543186431874318843189431904319143192431934319443195431964319743198431994320043201432024320343204432054320643207432084320943210432114321243213432144321543216432174321843219432204322143222432234322443225432264322743228432294323043231432324323343234432354323643237432384323943240432414324243243432444324543246432474324843249432504325143252432534325443255432564325743258432594326043261432624326343264432654326643267432684326943270432714327243273432744327543276432774327843279432804328143282432834328443285432864328743288432894329043291432924329343294432954329643297432984329943300433014330243303433044330543306433074330843309433104331143312433134331443315433164331743318433194332043321433224332343324433254332643327433284332943330433314333243333433344333543336433374333843339433404334143342433434334443345433464334743348433494335043351433524335343354433554335643357433584335943360433614336243363433644336543366433674336843369433704337143372433734337443375433764337743378433794338043381433824338343384433854338643387433884338943390433914339243393433944339543396433974339843399434004340143402434034340443405434064340743408434094341043411434124341343414434154341643417434184341943420434214342243423434244342543426434274342843429434304343143432434334343443435434364343743438434394344043441434424344343444434454344643447434484344943450434514345243453434544345543456434574345843459434604346143462434634346443465434664346743468434694347043471434724347343474434754347643477434784347943480434814348243483434844348543486434874348843489434904349143492434934349443495434964349743498434994350043501435024350343504435054350643507435084350943510435114351243513435144351543516435174351843519435204352143522435234352443525435264352743528435294353043531435324353343534435354353643537435384353943540435414354243543435444354543546435474354843549435504355143552435534355443555435564355743558435594356043561435624356343564435654356643567435684356943570435714357243573435744357543576435774357843579435804358143582435834358443585435864358743588435894359043591435924359343594435954359643597435984359943600436014360243603436044360543606436074360843609436104361143612436134361443615436164361743618436194362043621436224362343624436254362643627436284362943630436314363243633436344363543636436374363843639436404364143642436434364443645436464364743648436494365043651436524365343654436554365643657436584365943660436614366243663436644366543666436674366843669436704367143672436734367443675436764367743678436794368043681436824368343684436854368643687436884368943690436914369243693436944369543696436974369843699437004370143702437034370443705437064370743708437094371043711437124371343714437154371643717437184371943720437214372243723437244372543726437274372843729437304373143732437334373443735437364373743738437394374043741437424374343744437454374643747437484374943750437514375243753437544375543756437574375843759437604376143762437634376443765437664376743768437694377043771437724377343774437754377643777437784377943780437814378243783437844378543786437874378843789437904379143792437934379443795437964379743798437994380043801438024380343804438054380643807438084380943810438114381243813438144381543816438174381843819438204382143822438234382443825438264382743828438294383043831438324383343834438354383643837438384383943840438414384243843438444384543846438474384843849438504385143852438534385443855438564385743858438594386043861438624386343864438654386643867438684386943870438714387243873438744387543876438774387843879438804388143882438834388443885438864388743888438894389043891438924389343894438954389643897438984389943900439014390243903439044390543906439074390843909439104391143912439134391443915439164391743918439194392043921439224392343924439254392643927439284392943930439314393243933439344393543936439374393843939439404394143942439434394443945439464394743948439494395043951439524395343954439554395643957439584395943960439614396243963439644396543966439674396843969439704397143972439734397443975439764397743978439794398043981439824398343984439854398643987439884398943990439914399243993439944399543996439974399843999440004400144002440034400444005440064400744008440094401044011440124401344014440154401644017440184401944020440214402244023440244402544026440274402844029440304403144032440334403444035440364403744038440394404044041440424404344044440454404644047440484404944050440514405244053440544405544056440574405844059440604406144062440634406444065440664406744068440694407044071440724407344074440754407644077440784407944080440814408244083440844408544086440874408844089440904409144092440934409444095440964409744098440994410044101441024410344104441054410644107441084410944110441114411244113441144411544116441174411844119441204412144122441234412444125441264412744128441294413044131441324413344134441354413644137441384413944140441414414244143441444414544146441474414844149441504415144152441534415444155441564415744158441594416044161441624416344164441654416644167441684416944170441714417244173441744417544176441774417844179441804418144182441834418444185441864418744188441894419044191441924419344194441954419644197441984419944200442014420244203442044420544206442074420844209442104421144212442134421444215442164421744218442194422044221442224422344224442254422644227442284422944230442314423244233442344423544236442374423844239442404424144242442434424444245442464424744248442494425044251442524425344254442554425644257442584425944260442614426244263442644426544266442674426844269442704427144272442734427444275442764427744278442794428044281442824428344284442854428644287442884428944290442914429244293442944429544296442974429844299443004430144302443034430444305443064430744308443094431044311443124431344314443154431644317443184431944320443214432244323443244432544326443274432844329443304433144332443334433444335443364433744338443394434044341443424434344344443454434644347443484434944350443514435244353443544435544356443574435844359443604436144362443634436444365443664436744368443694437044371443724437344374443754437644377443784437944380443814438244383443844438544386443874438844389443904439144392443934439444395443964439744398443994440044401444024440344404444054440644407444084440944410444114441244413444144441544416444174441844419444204442144422444234442444425444264442744428444294443044431444324443344434444354443644437444384443944440444414444244443444444444544446444474444844449444504445144452444534445444455444564445744458444594446044461444624446344464444654446644467444684446944470444714447244473444744447544476444774447844479444804448144482444834448444485444864448744488444894449044491444924449344494444954449644497444984449944500445014450244503445044450544506445074450844509445104451144512445134451444515445164451744518445194452044521445224452344524445254452644527445284452944530445314453244533445344453544536445374453844539445404454144542445434454444545445464454744548445494455044551445524455344554445554455644557445584455944560445614456244563445644456544566445674456844569445704457144572445734457444575445764457744578445794458044581445824458344584445854458644587445884458944590445914459244593445944459544596445974459844599446004460144602446034460444605446064460744608446094461044611446124461344614446154461644617446184461944620446214462244623446244462544626446274462844629446304463144632446334463444635446364463744638446394464044641446424464344644446454464644647446484464944650446514465244653446544465544656446574465844659446604466144662446634466444665446664466744668446694467044671446724467344674446754467644677446784467944680446814468244683446844468544686446874468844689446904469144692446934469444695446964469744698446994470044701447024470344704447054470644707447084470944710447114471244713447144471544716447174471844719447204472144722447234472444725447264472744728447294473044731447324473344734447354473644737447384473944740447414474244743447444474544746447474474844749447504475144752447534475444755447564475744758447594476044761447624476344764447654476644767447684476944770447714477244773447744477544776447774477844779447804478144782447834478444785447864478744788447894479044791447924479344794447954479644797447984479944800448014480244803448044480544806448074480844809448104481144812448134481444815448164481744818448194482044821448224482344824448254482644827448284482944830448314483244833448344483544836448374483844839448404484144842448434484444845448464484744848448494485044851448524485344854448554485644857448584485944860448614486244863448644486544866448674486844869448704487144872448734487444875448764487744878448794488044881448824488344884448854488644887448884488944890448914489244893448944489544896448974489844899449004490144902449034490444905449064490744908449094491044911449124491344914449154491644917449184491944920449214492244923449244492544926449274492844929449304493144932449334493444935449364493744938449394494044941449424494344944449454494644947449484494944950449514495244953449544495544956449574495844959449604496144962449634496444965449664496744968449694497044971449724497344974449754497644977449784497944980449814498244983449844498544986449874498844989449904499144992449934499444995449964499744998449994500045001450024500345004450054500645007450084500945010450114501245013450144501545016450174501845019450204502145022450234502445025450264502745028450294503045031450324503345034450354503645037450384503945040450414504245043450444504545046450474504845049450504505145052450534505445055450564505745058450594506045061450624506345064450654506645067450684506945070450714507245073450744507545076450774507845079450804508145082450834508445085450864508745088450894509045091450924509345094450954509645097450984509945100451014510245103451044510545106451074510845109451104511145112451134511445115451164511745118451194512045121451224512345124451254512645127451284512945130451314513245133451344513545136451374513845139451404514145142451434514445145451464514745148451494515045151451524515345154451554515645157451584515945160451614516245163451644516545166451674516845169451704517145172451734517445175451764517745178451794518045181451824518345184451854518645187451884518945190451914519245193451944519545196451974519845199452004520145202452034520445205452064520745208452094521045211452124521345214452154521645217452184521945220452214522245223452244522545226452274522845229452304523145232452334523445235452364523745238452394524045241452424524345244452454524645247452484524945250452514525245253452544525545256452574525845259452604526145262452634526445265452664526745268452694527045271452724527345274452754527645277452784527945280452814528245283452844528545286452874528845289452904529145292452934529445295452964529745298452994530045301453024530345304453054530645307453084530945310453114531245313453144531545316453174531845319453204532145322453234532445325453264532745328453294533045331453324533345334453354533645337453384533945340453414534245343453444534545346453474534845349453504535145352453534535445355453564535745358453594536045361453624536345364453654536645367453684536945370453714537245373453744537545376453774537845379453804538145382453834538445385453864538745388453894539045391453924539345394453954539645397453984539945400454014540245403454044540545406454074540845409454104541145412454134541445415454164541745418454194542045421454224542345424454254542645427454284542945430454314543245433454344543545436454374543845439454404544145442454434544445445454464544745448454494545045451454524545345454454554545645457454584545945460454614546245463454644546545466454674546845469454704547145472454734547445475454764547745478454794548045481454824548345484454854548645487454884548945490454914549245493454944549545496454974549845499455004550145502455034550445505455064550745508455094551045511455124551345514455154551645517455184551945520455214552245523455244552545526455274552845529455304553145532455334553445535455364553745538455394554045541455424554345544455454554645547455484554945550455514555245553455544555545556455574555845559455604556145562455634556445565455664556745568455694557045571455724557345574455754557645577455784557945580455814558245583455844558545586455874558845589455904559145592455934559445595455964559745598455994560045601456024560345604456054560645607456084560945610456114561245613456144561545616456174561845619456204562145622456234562445625456264562745628456294563045631456324563345634456354563645637456384563945640456414564245643456444564545646456474564845649456504565145652456534565445655456564565745658456594566045661456624566345664456654566645667456684566945670456714567245673456744567545676456774567845679456804568145682456834568445685456864568745688456894569045691456924569345694456954569645697456984569945700457014570245703457044570545706457074570845709457104571145712457134571445715457164571745718457194572045721457224572345724457254572645727457284572945730457314573245733457344573545736457374573845739457404574145742457434574445745457464574745748457494575045751457524575345754457554575645757457584575945760457614576245763457644576545766457674576845769457704577145772457734577445775457764577745778457794578045781457824578345784457854578645787457884578945790457914579245793457944579545796457974579845799458004580145802458034580445805458064580745808458094581045811458124581345814458154581645817458184581945820458214582245823458244582545826458274582845829458304583145832458334583445835458364583745838458394584045841458424584345844458454584645847458484584945850458514585245853458544585545856458574585845859458604586145862458634586445865458664586745868458694587045871458724587345874458754587645877458784587945880458814588245883458844588545886458874588845889458904589145892458934589445895458964589745898458994590045901459024590345904459054590645907459084590945910459114591245913459144591545916459174591845919459204592145922459234592445925459264592745928459294593045931459324593345934459354593645937459384593945940459414594245943459444594545946459474594845949459504595145952459534595445955459564595745958459594596045961459624596345964459654596645967459684596945970459714597245973459744597545976459774597845979459804598145982459834598445985459864598745988459894599045991459924599345994459954599645997459984599946000460014600246003460044600546006460074600846009460104601146012460134601446015460164601746018460194602046021460224602346024460254602646027460284602946030460314603246033460344603546036460374603846039460404604146042460434604446045460464604746048460494605046051460524605346054460554605646057460584605946060460614606246063460644606546066460674606846069460704607146072460734607446075460764607746078460794608046081460824608346084460854608646087460884608946090460914609246093460944609546096460974609846099461004610146102461034610446105461064610746108461094611046111461124611346114461154611646117461184611946120461214612246123461244612546126461274612846129461304613146132461334613446135461364613746138461394614046141461424614346144461454614646147461484614946150461514615246153461544615546156461574615846159461604616146162461634616446165461664616746168461694617046171461724617346174461754617646177461784617946180461814618246183461844618546186461874618846189461904619146192461934619446195461964619746198461994620046201462024620346204462054620646207462084620946210462114621246213462144621546216462174621846219462204622146222462234622446225462264622746228462294623046231462324623346234462354623646237462384623946240462414624246243462444624546246462474624846249462504625146252462534625446255462564625746258462594626046261462624626346264462654626646267462684626946270462714627246273462744627546276462774627846279462804628146282462834628446285462864628746288462894629046291462924629346294462954629646297462984629946300463014630246303463044630546306463074630846309463104631146312463134631446315463164631746318463194632046321463224632346324463254632646327463284632946330463314633246333463344633546336463374633846339463404634146342463434634446345463464634746348463494635046351463524635346354463554635646357463584635946360463614636246363463644636546366463674636846369463704637146372463734637446375463764637746378463794638046381463824638346384463854638646387463884638946390463914639246393463944639546396463974639846399464004640146402464034640446405464064640746408464094641046411464124641346414464154641646417464184641946420464214642246423464244642546426464274642846429464304643146432464334643446435464364643746438464394644046441464424644346444464454644646447464484644946450464514645246453464544645546456464574645846459464604646146462464634646446465464664646746468464694647046471464724647346474464754647646477464784647946480464814648246483464844648546486464874648846489464904649146492464934649446495464964649746498464994650046501465024650346504465054650646507465084650946510465114651246513465144651546516465174651846519465204652146522465234652446525465264652746528465294653046531465324653346534465354653646537465384653946540465414654246543465444654546546465474654846549465504655146552465534655446555465564655746558465594656046561465624656346564465654656646567465684656946570465714657246573465744657546576465774657846579465804658146582465834658446585465864658746588465894659046591465924659346594465954659646597465984659946600466014660246603466044660546606466074660846609466104661146612466134661446615466164661746618466194662046621466224662346624466254662646627466284662946630466314663246633466344663546636466374663846639466404664146642466434664446645466464664746648466494665046651466524665346654466554665646657466584665946660466614666246663466644666546666466674666846669466704667146672466734667446675466764667746678466794668046681466824668346684466854668646687466884668946690466914669246693466944669546696466974669846699467004670146702467034670446705467064670746708467094671046711467124671346714467154671646717467184671946720467214672246723467244672546726467274672846729467304673146732467334673446735467364673746738467394674046741467424674346744467454674646747467484674946750467514675246753467544675546756467574675846759467604676146762467634676446765467664676746768467694677046771467724677346774467754677646777467784677946780467814678246783467844678546786467874678846789467904679146792467934679446795467964679746798467994680046801468024680346804468054680646807468084680946810468114681246813468144681546816468174681846819468204682146822468234682446825468264682746828468294683046831468324683346834468354683646837468384683946840468414684246843468444684546846468474684846849468504685146852468534685446855468564685746858468594686046861468624686346864468654686646867468684686946870468714687246873468744687546876468774687846879468804688146882468834688446885468864688746888468894689046891468924689346894468954689646897468984689946900469014690246903469044690546906469074690846909469104691146912469134691446915469164691746918469194692046921469224692346924469254692646927469284692946930469314693246933469344693546936469374693846939469404694146942469434694446945469464694746948469494695046951469524695346954469554695646957469584695946960469614696246963469644696546966469674696846969469704697146972469734697446975469764697746978469794698046981469824698346984469854698646987469884698946990469914699246993469944699546996469974699846999470004700147002470034700447005470064700747008470094701047011470124701347014470154701647017470184701947020470214702247023470244702547026470274702847029470304703147032470334703447035470364703747038470394704047041470424704347044470454704647047470484704947050470514705247053470544705547056470574705847059470604706147062470634706447065470664706747068470694707047071470724707347074470754707647077470784707947080470814708247083470844708547086470874708847089470904709147092470934709447095470964709747098470994710047101471024710347104471054710647107471084710947110471114711247113471144711547116471174711847119471204712147122471234712447125471264712747128471294713047131471324713347134471354713647137471384713947140471414714247143471444714547146471474714847149471504715147152471534715447155471564715747158471594716047161471624716347164471654716647167471684716947170471714717247173471744717547176471774717847179471804718147182471834718447185471864718747188471894719047191471924719347194471954719647197471984719947200472014720247203472044720547206472074720847209472104721147212472134721447215472164721747218472194722047221472224722347224472254722647227472284722947230472314723247233472344723547236472374723847239472404724147242472434724447245472464724747248472494725047251472524725347254472554725647257472584725947260472614726247263472644726547266472674726847269472704727147272472734727447275472764727747278472794728047281472824728347284472854728647287472884728947290472914729247293472944729547296472974729847299473004730147302473034730447305473064730747308473094731047311473124731347314473154731647317473184731947320473214732247323473244732547326473274732847329473304733147332473334733447335473364733747338473394734047341473424734347344473454734647347473484734947350473514735247353473544735547356473574735847359473604736147362473634736447365473664736747368473694737047371473724737347374473754737647377473784737947380473814738247383473844738547386473874738847389473904739147392473934739447395473964739747398473994740047401474024740347404474054740647407474084740947410474114741247413474144741547416474174741847419474204742147422474234742447425474264742747428474294743047431474324743347434474354743647437474384743947440474414744247443474444744547446474474744847449474504745147452474534745447455474564745747458474594746047461474624746347464474654746647467474684746947470474714747247473474744747547476474774747847479474804748147482474834748447485474864748747488474894749047491474924749347494474954749647497474984749947500475014750247503475044750547506475074750847509475104751147512475134751447515475164751747518475194752047521475224752347524475254752647527475284752947530475314753247533475344753547536475374753847539475404754147542475434754447545475464754747548475494755047551475524755347554475554755647557475584755947560475614756247563475644756547566475674756847569475704757147572475734757447575475764757747578475794758047581475824758347584475854758647587475884758947590475914759247593475944759547596475974759847599476004760147602476034760447605476064760747608476094761047611476124761347614476154761647617476184761947620476214762247623476244762547626476274762847629476304763147632476334763447635476364763747638476394764047641476424764347644476454764647647476484764947650476514765247653476544765547656476574765847659476604766147662476634766447665476664766747668476694767047671476724767347674476754767647677476784767947680476814768247683476844768547686476874768847689476904769147692476934769447695476964769747698476994770047701477024770347704477054770647707477084770947710477114771247713477144771547716477174771847719477204772147722477234772447725477264772747728477294773047731477324773347734477354773647737477384773947740477414774247743477444774547746477474774847749477504775147752477534775447755477564775747758477594776047761477624776347764477654776647767477684776947770477714777247773477744777547776477774777847779477804778147782477834778447785477864778747788477894779047791477924779347794477954779647797477984779947800478014780247803478044780547806478074780847809478104781147812478134781447815478164781747818478194782047821478224782347824478254782647827478284782947830478314783247833478344783547836478374783847839478404784147842478434784447845478464784747848478494785047851478524785347854478554785647857478584785947860478614786247863478644786547866478674786847869478704787147872478734787447875478764787747878478794788047881478824788347884478854788647887478884788947890478914789247893478944789547896478974789847899479004790147902479034790447905479064790747908479094791047911479124791347914479154791647917479184791947920479214792247923479244792547926479274792847929479304793147932479334793447935479364793747938479394794047941479424794347944479454794647947479484794947950479514795247953479544795547956479574795847959479604796147962479634796447965479664796747968479694797047971479724797347974479754797647977479784797947980479814798247983479844798547986479874798847989479904799147992479934799447995479964799747998479994800048001480024800348004480054800648007480084800948010480114801248013480144801548016480174801848019480204802148022480234802448025480264802748028480294803048031480324803348034480354803648037480384803948040480414804248043480444804548046480474804848049480504805148052480534805448055480564805748058480594806048061480624806348064480654806648067480684806948070480714807248073480744807548076480774807848079480804808148082480834808448085480864808748088480894809048091480924809348094480954809648097480984809948100481014810248103481044810548106481074810848109481104811148112481134811448115481164811748118481194812048121481224812348124481254812648127481284812948130481314813248133481344813548136481374813848139481404814148142481434814448145481464814748148481494815048151481524815348154481554815648157481584815948160481614816248163481644816548166481674816848169481704817148172481734817448175481764817748178481794818048181481824818348184481854818648187481884818948190481914819248193481944819548196481974819848199482004820148202482034820448205482064820748208482094821048211482124821348214482154821648217482184821948220482214822248223482244822548226482274822848229482304823148232482334823448235482364823748238482394824048241482424824348244482454824648247482484824948250482514825248253482544825548256482574825848259482604826148262482634826448265482664826748268482694827048271482724827348274482754827648277482784827948280482814828248283482844828548286482874828848289482904829148292482934829448295482964829748298482994830048301483024830348304483054830648307483084830948310483114831248313483144831548316483174831848319483204832148322483234832448325483264832748328483294833048331483324833348334483354833648337483384833948340483414834248343483444834548346483474834848349483504835148352483534835448355483564835748358483594836048361483624836348364483654836648367483684836948370483714837248373483744837548376483774837848379483804838148382483834838448385483864838748388483894839048391483924839348394483954839648397483984839948400484014840248403484044840548406484074840848409484104841148412484134841448415484164841748418484194842048421484224842348424484254842648427484284842948430484314843248433484344843548436484374843848439484404844148442484434844448445484464844748448484494845048451484524845348454484554845648457484584845948460484614846248463484644846548466484674846848469484704847148472484734847448475484764847748478484794848048481484824848348484484854848648487484884848948490484914849248493484944849548496484974849848499485004850148502485034850448505485064850748508485094851048511485124851348514485154851648517485184851948520485214852248523485244852548526485274852848529485304853148532485334853448535485364853748538485394854048541485424854348544485454854648547485484854948550485514855248553485544855548556485574855848559485604856148562485634856448565485664856748568485694857048571485724857348574485754857648577485784857948580485814858248583485844858548586485874858848589485904859148592485934859448595485964859748598485994860048601486024860348604486054860648607486084860948610486114861248613486144861548616486174861848619486204862148622486234862448625486264862748628486294863048631486324863348634486354863648637486384863948640486414864248643486444864548646486474864848649486504865148652486534865448655486564865748658486594866048661486624866348664486654866648667486684866948670486714867248673486744867548676486774867848679486804868148682486834868448685486864868748688486894869048691486924869348694486954869648697486984869948700487014870248703487044870548706487074870848709487104871148712487134871448715487164871748718487194872048721487224872348724487254872648727487284872948730487314873248733487344873548736487374873848739487404874148742487434874448745487464874748748487494875048751487524875348754487554875648757487584875948760487614876248763487644876548766487674876848769487704877148772487734877448775487764877748778487794878048781487824878348784487854878648787487884878948790487914879248793487944879548796487974879848799488004880148802488034880448805488064880748808488094881048811488124881348814488154881648817488184881948820488214882248823488244882548826488274882848829488304883148832488334883448835488364883748838488394884048841488424884348844488454884648847488484884948850488514885248853488544885548856488574885848859488604886148862488634886448865488664886748868488694887048871488724887348874488754887648877488784887948880488814888248883488844888548886488874888848889488904889148892488934889448895488964889748898488994890048901489024890348904489054890648907489084890948910489114891248913489144891548916489174891848919489204892148922489234892448925489264892748928489294893048931489324893348934489354893648937489384893948940489414894248943489444894548946489474894848949489504895148952489534895448955489564895748958489594896048961489624896348964489654896648967489684896948970489714897248973489744897548976489774897848979489804898148982489834898448985489864898748988489894899048991489924899348994489954899648997489984899949000490014900249003490044900549006490074900849009490104901149012490134901449015490164901749018490194902049021490224902349024490254902649027490284902949030490314903249033490344903549036490374903849039490404904149042490434904449045490464904749048490494905049051490524905349054490554905649057490584905949060490614906249063490644906549066490674906849069490704907149072490734907449075490764907749078490794908049081490824908349084490854908649087490884908949090490914909249093490944909549096490974909849099491004910149102491034910449105491064910749108491094911049111491124911349114491154911649117491184911949120491214912249123491244912549126491274912849129491304913149132491334913449135491364913749138491394914049141491424914349144491454914649147491484914949150491514915249153491544915549156491574915849159491604916149162491634916449165491664916749168491694917049171491724917349174491754917649177491784917949180491814918249183491844918549186491874918849189491904919149192491934919449195491964919749198491994920049201492024920349204492054920649207492084920949210492114921249213492144921549216492174921849219492204922149222492234922449225492264922749228492294923049231492324923349234492354923649237492384923949240492414924249243492444924549246492474924849249492504925149252492534925449255492564925749258492594926049261492624926349264492654926649267492684926949270492714927249273492744927549276492774927849279492804928149282492834928449285492864928749288492894929049291492924929349294492954929649297492984929949300493014930249303493044930549306493074930849309493104931149312493134931449315493164931749318493194932049321493224932349324493254932649327493284932949330493314933249333493344933549336493374933849339493404934149342493434934449345493464934749348493494935049351493524935349354493554935649357493584935949360493614936249363493644936549366493674936849369493704937149372493734937449375493764937749378493794938049381493824938349384493854938649387493884938949390493914939249393493944939549396493974939849399494004940149402494034940449405494064940749408494094941049411494124941349414494154941649417494184941949420494214942249423494244942549426494274942849429494304943149432494334943449435494364943749438494394944049441494424944349444494454944649447494484944949450494514945249453494544945549456494574945849459494604946149462494634946449465494664946749468494694947049471494724947349474494754947649477494784947949480494814948249483494844948549486494874948849489494904949149492494934949449495494964949749498494994950049501495024950349504495054950649507495084950949510495114951249513495144951549516495174951849519495204952149522495234952449525495264952749528495294953049531495324953349534495354953649537495384953949540495414954249543495444954549546495474954849549495504955149552495534955449555495564955749558495594956049561495624956349564495654956649567495684956949570495714957249573495744957549576495774957849579495804958149582495834958449585495864958749588495894959049591495924959349594495954959649597495984959949600496014960249603496044960549606496074960849609496104961149612496134961449615496164961749618496194962049621496224962349624496254962649627496284962949630496314963249633496344963549636496374963849639496404964149642496434964449645496464964749648496494965049651496524965349654496554965649657496584965949660496614966249663496644966549666496674966849669496704967149672496734967449675496764967749678496794968049681496824968349684496854968649687496884968949690496914969249693496944969549696496974969849699497004970149702497034970449705497064970749708497094971049711497124971349714497154971649717497184971949720497214972249723497244972549726497274972849729497304973149732497334973449735497364973749738497394974049741497424974349744497454974649747497484974949750497514975249753497544975549756497574975849759497604976149762497634976449765497664976749768497694977049771497724977349774497754977649777497784977949780497814978249783497844978549786497874978849789497904979149792497934979449795497964979749798497994980049801498024980349804498054980649807498084980949810498114981249813498144981549816498174981849819498204982149822498234982449825498264982749828498294983049831498324983349834498354983649837498384983949840498414984249843498444984549846498474984849849498504985149852498534985449855498564985749858498594986049861498624986349864498654986649867498684986949870498714987249873498744987549876498774987849879498804988149882498834988449885498864988749888498894989049891498924989349894498954989649897498984989949900499014990249903499044990549906499074990849909499104991149912499134991449915499164991749918499194992049921499224992349924499254992649927499284992949930499314993249933499344993549936499374993849939499404994149942499434994449945499464994749948499494995049951499524995349954499554995649957499584995949960499614996249963499644996549966499674996849969499704997149972499734997449975499764997749978499794998049981499824998349984499854998649987499884998949990499914999249993499944999549996499974999849999500005000150002500035000450005500065000750008500095001050011500125001350014500155001650017500185001950020500215002250023500245002550026500275002850029500305003150032500335003450035500365003750038500395004050041500425004350044500455004650047500485004950050500515005250053500545005550056500575005850059500605006150062500635006450065500665006750068500695007050071500725007350074500755007650077500785007950080500815008250083500845008550086500875008850089500905009150092500935009450095500965009750098500995010050101501025010350104501055010650107501085010950110501115011250113501145011550116501175011850119501205012150122501235012450125501265012750128501295013050131501325013350134501355013650137501385013950140501415014250143501445014550146501475014850149501505015150152501535015450155501565015750158501595016050161501625016350164501655016650167501685016950170501715017250173501745017550176501775017850179501805018150182501835018450185501865018750188501895019050191501925019350194501955019650197501985019950200502015020250203502045020550206502075020850209502105021150212502135021450215502165021750218502195022050221502225022350224502255022650227502285022950230502315023250233502345023550236502375023850239502405024150242502435024450245502465024750248502495025050251502525025350254502555025650257502585025950260502615026250263502645026550266502675026850269502705027150272502735027450275502765027750278502795028050281502825028350284502855028650287502885028950290502915029250293502945029550296502975029850299503005030150302503035030450305503065030750308503095031050311503125031350314503155031650317503185031950320503215032250323503245032550326503275032850329503305033150332503335033450335503365033750338503395034050341503425034350344503455034650347503485034950350503515035250353503545035550356503575035850359503605036150362503635036450365503665036750368503695037050371503725037350374503755037650377503785037950380503815038250383503845038550386503875038850389503905039150392503935039450395503965039750398503995040050401504025040350404504055040650407504085040950410504115041250413504145041550416504175041850419504205042150422504235042450425504265042750428504295043050431504325043350434504355043650437504385043950440504415044250443504445044550446504475044850449504505045150452504535045450455504565045750458504595046050461504625046350464504655046650467504685046950470504715047250473504745047550476504775047850479504805048150482504835048450485504865048750488504895049050491504925049350494504955049650497504985049950500505015050250503505045050550506505075050850509505105051150512505135051450515505165051750518505195052050521505225052350524505255052650527505285052950530505315053250533505345053550536505375053850539505405054150542505435054450545505465054750548505495055050551505525055350554505555055650557505585055950560505615056250563505645056550566505675056850569505705057150572505735057450575505765057750578505795058050581505825058350584505855058650587505885058950590505915059250593505945059550596505975059850599506005060150602506035060450605506065060750608506095061050611506125061350614506155061650617506185061950620506215062250623506245062550626506275062850629506305063150632506335063450635506365063750638506395064050641506425064350644506455064650647506485064950650506515065250653506545065550656506575065850659506605066150662506635066450665506665066750668506695067050671506725067350674506755067650677506785067950680506815068250683506845068550686506875068850689506905069150692506935069450695506965069750698506995070050701507025070350704507055070650707507085070950710507115071250713507145071550716507175071850719507205072150722507235072450725507265072750728507295073050731507325073350734507355073650737507385073950740507415074250743507445074550746507475074850749507505075150752507535075450755507565075750758507595076050761507625076350764507655076650767507685076950770507715077250773507745077550776507775077850779507805078150782507835078450785507865078750788507895079050791507925079350794507955079650797507985079950800508015080250803508045080550806508075080850809508105081150812508135081450815508165081750818508195082050821508225082350824508255082650827508285082950830508315083250833508345083550836508375083850839508405084150842508435084450845508465084750848508495085050851508525085350854508555085650857508585085950860508615086250863508645086550866508675086850869508705087150872508735087450875508765087750878508795088050881508825088350884508855088650887508885088950890508915089250893508945089550896508975089850899509005090150902509035090450905509065090750908509095091050911509125091350914509155091650917509185091950920509215092250923509245092550926509275092850929509305093150932509335093450935509365093750938509395094050941509425094350944509455094650947509485094950950509515095250953509545095550956509575095850959509605096150962509635096450965509665096750968509695097050971509725097350974509755097650977509785097950980509815098250983509845098550986509875098850989509905099150992509935099450995509965099750998509995100051001510025100351004510055100651007510085100951010510115101251013510145101551016510175101851019510205102151022510235102451025510265102751028510295103051031510325103351034510355103651037510385103951040510415104251043510445104551046510475104851049510505105151052510535105451055510565105751058510595106051061510625106351064510655106651067510685106951070510715107251073510745107551076510775107851079510805108151082510835108451085510865108751088510895109051091510925109351094510955109651097510985109951100511015110251103511045110551106511075110851109511105111151112511135111451115511165111751118511195112051121511225112351124511255112651127511285112951130511315113251133511345113551136511375113851139511405114151142511435114451145511465114751148511495115051151511525115351154511555115651157511585115951160511615116251163511645116551166511675116851169511705117151172511735117451175511765117751178511795118051181511825118351184511855118651187511885118951190511915119251193511945119551196511975119851199512005120151202512035120451205512065120751208512095121051211512125121351214512155121651217512185121951220512215122251223512245122551226512275122851229512305123151232512335123451235512365123751238512395124051241512425124351244512455124651247512485124951250512515125251253512545125551256512575125851259512605126151262512635126451265512665126751268512695127051271512725127351274512755127651277512785127951280512815128251283512845128551286512875128851289512905129151292512935129451295512965129751298512995130051301513025130351304513055130651307513085130951310513115131251313513145131551316513175131851319513205132151322513235132451325513265132751328513295133051331513325133351334513355133651337513385133951340513415134251343513445134551346513475134851349513505135151352513535135451355513565135751358513595136051361513625136351364513655136651367513685136951370513715137251373513745137551376513775137851379513805138151382513835138451385513865138751388513895139051391513925139351394513955139651397513985139951400514015140251403514045140551406514075140851409514105141151412514135141451415514165141751418514195142051421514225142351424514255142651427514285142951430514315143251433514345143551436514375143851439514405144151442514435144451445514465144751448514495145051451514525145351454514555145651457514585145951460514615146251463514645146551466514675146851469514705147151472514735147451475514765147751478514795148051481514825148351484514855148651487514885148951490514915149251493514945149551496514975149851499515005150151502515035150451505515065150751508515095151051511515125151351514515155151651517515185151951520515215152251523515245152551526515275152851529515305153151532515335153451535515365153751538515395154051541515425154351544515455154651547515485154951550515515155251553515545155551556515575155851559515605156151562515635156451565515665156751568515695157051571515725157351574515755157651577515785157951580515815158251583515845158551586515875158851589515905159151592515935159451595515965159751598515995160051601516025160351604516055160651607516085160951610516115161251613516145161551616516175161851619516205162151622516235162451625516265162751628516295163051631516325163351634516355163651637516385163951640516415164251643516445164551646516475164851649516505165151652516535165451655516565165751658516595166051661516625166351664516655166651667516685166951670516715167251673516745167551676516775167851679516805168151682516835168451685516865168751688516895169051691516925169351694516955169651697516985169951700517015170251703517045170551706517075170851709517105171151712517135171451715517165171751718517195172051721517225172351724517255172651727517285172951730517315173251733517345173551736517375173851739517405174151742517435174451745517465174751748517495175051751517525175351754517555175651757517585175951760517615176251763517645176551766517675176851769517705177151772517735177451775517765177751778517795178051781517825178351784517855178651787517885178951790517915179251793517945179551796517975179851799518005180151802518035180451805518065180751808518095181051811518125181351814518155181651817518185181951820518215182251823518245182551826518275182851829518305183151832518335183451835518365183751838518395184051841518425184351844518455184651847518485184951850518515185251853518545185551856518575185851859518605186151862518635186451865518665186751868518695187051871518725187351874518755187651877518785187951880518815188251883518845188551886518875188851889518905189151892518935189451895518965189751898518995190051901519025190351904519055190651907519085190951910519115191251913519145191551916519175191851919519205192151922519235192451925519265192751928519295193051931519325193351934519355193651937519385193951940519415194251943519445194551946519475194851949519505195151952519535195451955519565195751958519595196051961519625196351964519655196651967519685196951970519715197251973519745197551976519775197851979519805198151982519835198451985519865198751988519895199051991519925199351994519955199651997519985199952000520015200252003520045200552006520075200852009520105201152012520135201452015520165201752018520195202052021520225202352024520255202652027520285202952030520315203252033520345203552036520375203852039520405204152042520435204452045520465204752048520495205052051520525205352054520555205652057520585205952060520615206252063520645206552066520675206852069520705207152072520735207452075520765207752078520795208052081520825208352084520855208652087520885208952090520915209252093520945209552096520975209852099521005210152102521035210452105521065210752108521095211052111521125211352114521155211652117521185211952120521215212252123521245212552126521275212852129521305213152132521335213452135521365213752138521395214052141521425214352144521455214652147521485214952150521515215252153521545215552156521575215852159521605216152162521635216452165521665216752168521695217052171521725217352174521755217652177521785217952180521815218252183521845218552186521875218852189521905219152192521935219452195521965219752198521995220052201522025220352204522055220652207522085220952210522115221252213522145221552216522175221852219522205222152222522235222452225522265222752228522295223052231522325223352234522355223652237522385223952240522415224252243522445224552246522475224852249522505225152252522535225452255522565225752258522595226052261522625226352264522655226652267522685226952270522715227252273522745227552276522775227852279522805228152282522835228452285522865228752288522895229052291522925229352294522955229652297522985229952300523015230252303523045230552306523075230852309523105231152312523135231452315523165231752318523195232052321523225232352324523255232652327523285232952330523315233252333523345233552336523375233852339523405234152342523435234452345523465234752348523495235052351523525235352354523555235652357523585235952360523615236252363523645236552366523675236852369523705237152372523735237452375523765237752378523795238052381523825238352384523855238652387523885238952390523915239252393523945239552396523975239852399524005240152402524035240452405524065240752408524095241052411524125241352414524155241652417524185241952420524215242252423524245242552426524275242852429524305243152432524335243452435524365243752438524395244052441524425244352444524455244652447524485244952450524515245252453524545245552456524575245852459524605246152462524635246452465524665246752468524695247052471524725247352474524755247652477524785247952480524815248252483524845248552486524875248852489524905249152492524935249452495524965249752498524995250052501525025250352504525055250652507525085250952510525115251252513525145251552516525175251852519525205252152522525235252452525525265252752528525295253052531525325253352534525355253652537525385253952540525415254252543525445254552546525475254852549525505255152552525535255452555525565255752558525595256052561525625256352564525655256652567525685256952570525715257252573525745257552576525775257852579525805258152582525835258452585525865258752588525895259052591525925259352594525955259652597525985259952600526015260252603526045260552606526075260852609526105261152612526135261452615526165261752618526195262052621526225262352624526255262652627526285262952630526315263252633526345263552636526375263852639526405264152642526435264452645526465264752648526495265052651526525265352654526555265652657526585265952660526615266252663526645266552666526675266852669526705267152672526735267452675526765267752678526795268052681526825268352684526855268652687526885268952690526915269252693526945269552696526975269852699527005270152702527035270452705527065270752708527095271052711527125271352714527155271652717527185271952720527215272252723527245272552726527275272852729527305273152732527335273452735527365273752738527395274052741527425274352744527455274652747527485274952750527515275252753527545275552756527575275852759527605276152762527635276452765527665276752768527695277052771527725277352774527755277652777527785277952780527815278252783527845278552786527875278852789527905279152792527935279452795527965279752798527995280052801528025280352804528055280652807528085280952810528115281252813528145281552816528175281852819528205282152822528235282452825528265282752828528295283052831528325283352834528355283652837528385283952840528415284252843528445284552846528475284852849528505285152852528535285452855528565285752858528595286052861528625286352864528655286652867528685286952870528715287252873528745287552876528775287852879528805288152882528835288452885528865288752888528895289052891528925289352894528955289652897528985289952900529015290252903529045290552906529075290852909529105291152912529135291452915529165291752918529195292052921529225292352924529255292652927529285292952930529315293252933529345293552936529375293852939529405294152942529435294452945529465294752948529495295052951529525295352954529555295652957529585295952960529615296252963529645296552966529675296852969529705297152972529735297452975529765297752978529795298052981529825298352984529855298652987529885298952990529915299252993529945299552996529975299852999530005300153002530035300453005530065300753008530095301053011530125301353014530155301653017530185301953020530215302253023530245302553026530275302853029530305303153032530335303453035530365303753038530395304053041530425304353044530455304653047530485304953050530515305253053530545305553056530575305853059530605306153062530635306453065530665306753068530695307053071530725307353074530755307653077530785307953080530815308253083530845308553086530875308853089530905309153092530935309453095530965309753098530995310053101531025310353104531055310653107531085310953110531115311253113531145311553116531175311853119531205312153122531235312453125531265312753128531295313053131531325313353134531355313653137531385313953140531415314253143531445314553146531475314853149531505315153152531535315453155531565315753158531595316053161531625316353164531655316653167531685316953170531715317253173531745317553176531775317853179531805318153182531835318453185531865318753188531895319053191531925319353194531955319653197531985319953200532015320253203532045320553206532075320853209532105321153212532135321453215532165321753218532195322053221532225322353224532255322653227532285322953230532315323253233532345323553236532375323853239532405324153242532435324453245532465324753248532495325053251532525325353254532555325653257532585325953260532615326253263532645326553266532675326853269532705327153272532735327453275532765327753278532795328053281532825328353284532855328653287532885328953290532915329253293532945329553296532975329853299533005330153302533035330453305533065330753308533095331053311533125331353314533155331653317533185331953320533215332253323533245332553326533275332853329533305333153332533335333453335533365333753338533395334053341533425334353344533455334653347533485334953350533515335253353533545335553356533575335853359533605336153362533635336453365533665336753368533695337053371533725337353374533755337653377533785337953380533815338253383533845338553386533875338853389533905339153392533935339453395533965339753398533995340053401534025340353404534055340653407534085340953410534115341253413534145341553416534175341853419534205342153422534235342453425534265342753428534295343053431534325343353434534355343653437534385343953440534415344253443534445344553446534475344853449534505345153452534535345453455534565345753458534595346053461534625346353464534655346653467534685346953470534715347253473534745347553476534775347853479534805348153482534835348453485534865348753488534895349053491534925349353494534955349653497534985349953500535015350253503535045350553506535075350853509535105351153512535135351453515535165351753518535195352053521535225352353524535255352653527535285352953530535315353253533535345353553536535375353853539535405354153542535435354453545535465354753548535495355053551535525355353554535555355653557535585355953560535615356253563535645356553566535675356853569535705357153572535735357453575535765357753578535795358053581535825358353584535855358653587535885358953590535915359253593535945359553596535975359853599536005360153602536035360453605536065360753608536095361053611536125361353614536155361653617536185361953620536215362253623536245362553626536275362853629536305363153632536335363453635536365363753638536395364053641536425364353644536455364653647536485364953650536515365253653536545365553656536575365853659536605366153662536635366453665536665366753668536695367053671536725367353674536755367653677536785367953680536815368253683536845368553686536875368853689536905369153692536935369453695536965369753698536995370053701537025370353704537055370653707537085370953710537115371253713537145371553716537175371853719537205372153722537235372453725537265372753728537295373053731537325373353734537355373653737537385373953740537415374253743537445374553746537475374853749537505375153752537535375453755537565375753758537595376053761537625376353764537655376653767537685376953770537715377253773537745377553776537775377853779537805378153782537835378453785537865378753788537895379053791537925379353794537955379653797537985379953800
  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.worker', ['exports'], factory);
  19. } else if (typeof exports !== 'undefined') {
  20. factory(exports);
  21. } else {
  22. factory(root['pdfjsDistBuildPdfWorker'] = {});
  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.239';
  28. var pdfjsBuild = 'f209030';
  29. var pdfjsFilePath = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : null;
  30. var pdfjsLibs = {};
  31. (function pdfjsWrapper() {
  32. (function (root, factory) {
  33. factory(root.pdfjsCoreArithmeticDecoder = {});
  34. }(this, function (exports) {
  35. /* This class implements the QM Coder decoding as defined in
  36. * JPEG 2000 Part I Final Committee Draft Version 1.0
  37. * Annex C.3 Arithmetic decoding procedure
  38. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  39. *
  40. * The arithmetic decoder is used in conjunction with context models to decode
  41. * JPEG2000 and JBIG2 streams.
  42. */
  43. var ArithmeticDecoder = function ArithmeticDecoderClosure() {
  44. // Table C-2
  45. var QeTable = [
  46. {
  47. qe: 0x5601,
  48. nmps: 1,
  49. nlps: 1,
  50. switchFlag: 1
  51. },
  52. {
  53. qe: 0x3401,
  54. nmps: 2,
  55. nlps: 6,
  56. switchFlag: 0
  57. },
  58. {
  59. qe: 0x1801,
  60. nmps: 3,
  61. nlps: 9,
  62. switchFlag: 0
  63. },
  64. {
  65. qe: 0x0AC1,
  66. nmps: 4,
  67. nlps: 12,
  68. switchFlag: 0
  69. },
  70. {
  71. qe: 0x0521,
  72. nmps: 5,
  73. nlps: 29,
  74. switchFlag: 0
  75. },
  76. {
  77. qe: 0x0221,
  78. nmps: 38,
  79. nlps: 33,
  80. switchFlag: 0
  81. },
  82. {
  83. qe: 0x5601,
  84. nmps: 7,
  85. nlps: 6,
  86. switchFlag: 1
  87. },
  88. {
  89. qe: 0x5401,
  90. nmps: 8,
  91. nlps: 14,
  92. switchFlag: 0
  93. },
  94. {
  95. qe: 0x4801,
  96. nmps: 9,
  97. nlps: 14,
  98. switchFlag: 0
  99. },
  100. {
  101. qe: 0x3801,
  102. nmps: 10,
  103. nlps: 14,
  104. switchFlag: 0
  105. },
  106. {
  107. qe: 0x3001,
  108. nmps: 11,
  109. nlps: 17,
  110. switchFlag: 0
  111. },
  112. {
  113. qe: 0x2401,
  114. nmps: 12,
  115. nlps: 18,
  116. switchFlag: 0
  117. },
  118. {
  119. qe: 0x1C01,
  120. nmps: 13,
  121. nlps: 20,
  122. switchFlag: 0
  123. },
  124. {
  125. qe: 0x1601,
  126. nmps: 29,
  127. nlps: 21,
  128. switchFlag: 0
  129. },
  130. {
  131. qe: 0x5601,
  132. nmps: 15,
  133. nlps: 14,
  134. switchFlag: 1
  135. },
  136. {
  137. qe: 0x5401,
  138. nmps: 16,
  139. nlps: 14,
  140. switchFlag: 0
  141. },
  142. {
  143. qe: 0x5101,
  144. nmps: 17,
  145. nlps: 15,
  146. switchFlag: 0
  147. },
  148. {
  149. qe: 0x4801,
  150. nmps: 18,
  151. nlps: 16,
  152. switchFlag: 0
  153. },
  154. {
  155. qe: 0x3801,
  156. nmps: 19,
  157. nlps: 17,
  158. switchFlag: 0
  159. },
  160. {
  161. qe: 0x3401,
  162. nmps: 20,
  163. nlps: 18,
  164. switchFlag: 0
  165. },
  166. {
  167. qe: 0x3001,
  168. nmps: 21,
  169. nlps: 19,
  170. switchFlag: 0
  171. },
  172. {
  173. qe: 0x2801,
  174. nmps: 22,
  175. nlps: 19,
  176. switchFlag: 0
  177. },
  178. {
  179. qe: 0x2401,
  180. nmps: 23,
  181. nlps: 20,
  182. switchFlag: 0
  183. },
  184. {
  185. qe: 0x2201,
  186. nmps: 24,
  187. nlps: 21,
  188. switchFlag: 0
  189. },
  190. {
  191. qe: 0x1C01,
  192. nmps: 25,
  193. nlps: 22,
  194. switchFlag: 0
  195. },
  196. {
  197. qe: 0x1801,
  198. nmps: 26,
  199. nlps: 23,
  200. switchFlag: 0
  201. },
  202. {
  203. qe: 0x1601,
  204. nmps: 27,
  205. nlps: 24,
  206. switchFlag: 0
  207. },
  208. {
  209. qe: 0x1401,
  210. nmps: 28,
  211. nlps: 25,
  212. switchFlag: 0
  213. },
  214. {
  215. qe: 0x1201,
  216. nmps: 29,
  217. nlps: 26,
  218. switchFlag: 0
  219. },
  220. {
  221. qe: 0x1101,
  222. nmps: 30,
  223. nlps: 27,
  224. switchFlag: 0
  225. },
  226. {
  227. qe: 0x0AC1,
  228. nmps: 31,
  229. nlps: 28,
  230. switchFlag: 0
  231. },
  232. {
  233. qe: 0x09C1,
  234. nmps: 32,
  235. nlps: 29,
  236. switchFlag: 0
  237. },
  238. {
  239. qe: 0x08A1,
  240. nmps: 33,
  241. nlps: 30,
  242. switchFlag: 0
  243. },
  244. {
  245. qe: 0x0521,
  246. nmps: 34,
  247. nlps: 31,
  248. switchFlag: 0
  249. },
  250. {
  251. qe: 0x0441,
  252. nmps: 35,
  253. nlps: 32,
  254. switchFlag: 0
  255. },
  256. {
  257. qe: 0x02A1,
  258. nmps: 36,
  259. nlps: 33,
  260. switchFlag: 0
  261. },
  262. {
  263. qe: 0x0221,
  264. nmps: 37,
  265. nlps: 34,
  266. switchFlag: 0
  267. },
  268. {
  269. qe: 0x0141,
  270. nmps: 38,
  271. nlps: 35,
  272. switchFlag: 0
  273. },
  274. {
  275. qe: 0x0111,
  276. nmps: 39,
  277. nlps: 36,
  278. switchFlag: 0
  279. },
  280. {
  281. qe: 0x0085,
  282. nmps: 40,
  283. nlps: 37,
  284. switchFlag: 0
  285. },
  286. {
  287. qe: 0x0049,
  288. nmps: 41,
  289. nlps: 38,
  290. switchFlag: 0
  291. },
  292. {
  293. qe: 0x0025,
  294. nmps: 42,
  295. nlps: 39,
  296. switchFlag: 0
  297. },
  298. {
  299. qe: 0x0015,
  300. nmps: 43,
  301. nlps: 40,
  302. switchFlag: 0
  303. },
  304. {
  305. qe: 0x0009,
  306. nmps: 44,
  307. nlps: 41,
  308. switchFlag: 0
  309. },
  310. {
  311. qe: 0x0005,
  312. nmps: 45,
  313. nlps: 42,
  314. switchFlag: 0
  315. },
  316. {
  317. qe: 0x0001,
  318. nmps: 45,
  319. nlps: 43,
  320. switchFlag: 0
  321. },
  322. {
  323. qe: 0x5601,
  324. nmps: 46,
  325. nlps: 46,
  326. switchFlag: 0
  327. }
  328. ];
  329. // C.3.5 Initialisation of the decoder (INITDEC)
  330. function ArithmeticDecoder(data, start, end) {
  331. this.data = data;
  332. this.bp = start;
  333. this.dataEnd = end;
  334. this.chigh = data[start];
  335. this.clow = 0;
  336. this.byteIn();
  337. this.chigh = this.chigh << 7 & 0xFFFF | this.clow >> 9 & 0x7F;
  338. this.clow = this.clow << 7 & 0xFFFF;
  339. this.ct -= 7;
  340. this.a = 0x8000;
  341. }
  342. ArithmeticDecoder.prototype = {
  343. // C.3.4 Compressed data input (BYTEIN)
  344. byteIn: function ArithmeticDecoder_byteIn() {
  345. var data = this.data;
  346. var bp = this.bp;
  347. if (data[bp] === 0xFF) {
  348. var b1 = data[bp + 1];
  349. if (b1 > 0x8F) {
  350. this.clow += 0xFF00;
  351. this.ct = 8;
  352. } else {
  353. bp++;
  354. this.clow += data[bp] << 9;
  355. this.ct = 7;
  356. this.bp = bp;
  357. }
  358. } else {
  359. bp++;
  360. this.clow += bp < this.dataEnd ? data[bp] << 8 : 0xFF00;
  361. this.ct = 8;
  362. this.bp = bp;
  363. }
  364. if (this.clow > 0xFFFF) {
  365. this.chigh += this.clow >> 16;
  366. this.clow &= 0xFFFF;
  367. }
  368. },
  369. // C.3.2 Decoding a decision (DECODE)
  370. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  371. // contexts are packed into 1 byte:
  372. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  373. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  374. var qeTableIcx = QeTable[cx_index];
  375. var qeIcx = qeTableIcx.qe;
  376. var d;
  377. var a = this.a - qeIcx;
  378. if (this.chigh < qeIcx) {
  379. // exchangeLps
  380. if (a < qeIcx) {
  381. a = qeIcx;
  382. d = cx_mps;
  383. cx_index = qeTableIcx.nmps;
  384. } else {
  385. a = qeIcx;
  386. d = 1 ^ cx_mps;
  387. if (qeTableIcx.switchFlag === 1) {
  388. cx_mps = d;
  389. }
  390. cx_index = qeTableIcx.nlps;
  391. }
  392. } else {
  393. this.chigh -= qeIcx;
  394. if ((a & 0x8000) !== 0) {
  395. this.a = a;
  396. return cx_mps;
  397. }
  398. // exchangeMps
  399. if (a < qeIcx) {
  400. d = 1 ^ cx_mps;
  401. if (qeTableIcx.switchFlag === 1) {
  402. cx_mps = d;
  403. }
  404. cx_index = qeTableIcx.nlps;
  405. } else {
  406. d = cx_mps;
  407. cx_index = qeTableIcx.nmps;
  408. }
  409. }
  410. // C.3.3 renormD;
  411. do {
  412. if (this.ct === 0) {
  413. this.byteIn();
  414. }
  415. a <<= 1;
  416. this.chigh = this.chigh << 1 & 0xFFFF | this.clow >> 15 & 1;
  417. this.clow = this.clow << 1 & 0xFFFF;
  418. this.ct--;
  419. } while ((a & 0x8000) === 0);
  420. this.a = a;
  421. contexts[pos] = cx_index << 1 | cx_mps;
  422. return d;
  423. }
  424. };
  425. return ArithmeticDecoder;
  426. }();
  427. exports.ArithmeticDecoder = ArithmeticDecoder;
  428. }));
  429. (function (root, factory) {
  430. factory(root.pdfjsCoreBidi = {});
  431. }(this, function (exports) {
  432. // Character types for symbols from 0000 to 00FF.
  433. var baseTypes = [
  434. 'BN',
  435. 'BN',
  436. 'BN',
  437. 'BN',
  438. 'BN',
  439. 'BN',
  440. 'BN',
  441. 'BN',
  442. 'BN',
  443. 'S',
  444. 'B',
  445. 'S',
  446. 'WS',
  447. 'B',
  448. 'BN',
  449. 'BN',
  450. 'BN',
  451. 'BN',
  452. 'BN',
  453. 'BN',
  454. 'BN',
  455. 'BN',
  456. 'BN',
  457. 'BN',
  458. 'BN',
  459. 'BN',
  460. 'BN',
  461. 'BN',
  462. 'B',
  463. 'B',
  464. 'B',
  465. 'S',
  466. 'WS',
  467. 'ON',
  468. 'ON',
  469. 'ET',
  470. 'ET',
  471. 'ET',
  472. 'ON',
  473. 'ON',
  474. 'ON',
  475. 'ON',
  476. 'ON',
  477. 'ON',
  478. 'CS',
  479. 'ON',
  480. 'CS',
  481. 'ON',
  482. 'EN',
  483. 'EN',
  484. 'EN',
  485. 'EN',
  486. 'EN',
  487. 'EN',
  488. 'EN',
  489. 'EN',
  490. 'EN',
  491. 'EN',
  492. 'ON',
  493. 'ON',
  494. 'ON',
  495. 'ON',
  496. 'ON',
  497. 'ON',
  498. 'ON',
  499. 'L',
  500. 'L',
  501. 'L',
  502. 'L',
  503. 'L',
  504. 'L',
  505. 'L',
  506. 'L',
  507. 'L',
  508. 'L',
  509. 'L',
  510. 'L',
  511. 'L',
  512. 'L',
  513. 'L',
  514. 'L',
  515. 'L',
  516. 'L',
  517. 'L',
  518. 'L',
  519. 'L',
  520. 'L',
  521. 'L',
  522. 'L',
  523. 'L',
  524. 'L',
  525. 'ON',
  526. 'ON',
  527. 'ON',
  528. 'ON',
  529. 'ON',
  530. 'ON',
  531. 'L',
  532. 'L',
  533. 'L',
  534. 'L',
  535. 'L',
  536. 'L',
  537. 'L',
  538. 'L',
  539. 'L',
  540. 'L',
  541. 'L',
  542. 'L',
  543. 'L',
  544. 'L',
  545. 'L',
  546. 'L',
  547. 'L',
  548. 'L',
  549. 'L',
  550. 'L',
  551. 'L',
  552. 'L',
  553. 'L',
  554. 'L',
  555. 'L',
  556. 'L',
  557. 'ON',
  558. 'ON',
  559. 'ON',
  560. 'ON',
  561. 'BN',
  562. 'BN',
  563. 'BN',
  564. 'BN',
  565. 'BN',
  566. 'BN',
  567. 'B',
  568. 'BN',
  569. 'BN',
  570. 'BN',
  571. 'BN',
  572. 'BN',
  573. 'BN',
  574. 'BN',
  575. 'BN',
  576. 'BN',
  577. 'BN',
  578. 'BN',
  579. 'BN',
  580. 'BN',
  581. 'BN',
  582. 'BN',
  583. 'BN',
  584. 'BN',
  585. 'BN',
  586. 'BN',
  587. 'BN',
  588. 'BN',
  589. 'BN',
  590. 'BN',
  591. 'BN',
  592. 'BN',
  593. 'BN',
  594. 'CS',
  595. 'ON',
  596. 'ET',
  597. 'ET',
  598. 'ET',
  599. 'ET',
  600. 'ON',
  601. 'ON',
  602. 'ON',
  603. 'ON',
  604. 'L',
  605. 'ON',
  606. 'ON',
  607. 'ON',
  608. 'ON',
  609. 'ON',
  610. 'ET',
  611. 'ET',
  612. 'EN',
  613. 'EN',
  614. 'ON',
  615. 'L',
  616. 'ON',
  617. 'ON',
  618. 'ON',
  619. 'EN',
  620. 'L',
  621. 'ON',
  622. 'ON',
  623. 'ON',
  624. 'ON',
  625. 'ON',
  626. 'L',
  627. 'L',
  628. 'L',
  629. 'L',
  630. 'L',
  631. 'L',
  632. 'L',
  633. 'L',
  634. 'L',
  635. 'L',
  636. 'L',
  637. 'L',
  638. 'L',
  639. 'L',
  640. 'L',
  641. 'L',
  642. 'L',
  643. 'L',
  644. 'L',
  645. 'L',
  646. 'L',
  647. 'L',
  648. 'L',
  649. 'ON',
  650. 'L',
  651. 'L',
  652. 'L',
  653. 'L',
  654. 'L',
  655. 'L',
  656. 'L',
  657. 'L',
  658. 'L',
  659. 'L',
  660. 'L',
  661. 'L',
  662. 'L',
  663. 'L',
  664. 'L',
  665. 'L',
  666. 'L',
  667. 'L',
  668. 'L',
  669. 'L',
  670. 'L',
  671. 'L',
  672. 'L',
  673. 'L',
  674. 'L',
  675. 'L',
  676. 'L',
  677. 'L',
  678. 'L',
  679. 'L',
  680. 'L',
  681. 'ON',
  682. 'L',
  683. 'L',
  684. 'L',
  685. 'L',
  686. 'L',
  687. 'L',
  688. 'L',
  689. 'L'
  690. ];
  691. // Character types for symbols from 0600 to 06FF
  692. var arabicTypes = [
  693. 'AL',
  694. 'AL',
  695. 'AL',
  696. 'AL',
  697. 'AL',
  698. 'AL',
  699. 'AL',
  700. 'AL',
  701. 'AL',
  702. 'AL',
  703. 'AL',
  704. 'AL',
  705. 'CS',
  706. 'AL',
  707. 'ON',
  708. 'ON',
  709. 'NSM',
  710. 'NSM',
  711. 'NSM',
  712. 'NSM',
  713. 'NSM',
  714. 'NSM',
  715. 'AL',
  716. 'AL',
  717. 'AL',
  718. 'AL',
  719. 'AL',
  720. 'AL',
  721. 'AL',
  722. 'AL',
  723. 'AL',
  724. 'AL',
  725. 'AL',
  726. 'AL',
  727. 'AL',
  728. 'AL',
  729. 'AL',
  730. 'AL',
  731. 'AL',
  732. 'AL',
  733. 'AL',
  734. 'AL',
  735. 'AL',
  736. 'AL',
  737. 'AL',
  738. 'AL',
  739. 'AL',
  740. 'AL',
  741. 'AL',
  742. 'AL',
  743. 'AL',
  744. 'AL',
  745. 'AL',
  746. 'AL',
  747. 'AL',
  748. 'AL',
  749. 'AL',
  750. 'AL',
  751. 'AL',
  752. 'AL',
  753. 'AL',
  754. 'AL',
  755. 'AL',
  756. 'AL',
  757. 'AL',
  758. 'AL',
  759. 'AL',
  760. 'AL',
  761. 'AL',
  762. 'AL',
  763. 'AL',
  764. 'AL',
  765. 'AL',
  766. 'AL',
  767. 'AL',
  768. 'NSM',
  769. 'NSM',
  770. 'NSM',
  771. 'NSM',
  772. 'NSM',
  773. 'NSM',
  774. 'NSM',
  775. 'NSM',
  776. 'NSM',
  777. 'NSM',
  778. 'NSM',
  779. 'NSM',
  780. 'NSM',
  781. 'NSM',
  782. 'AL',
  783. 'AL',
  784. 'AL',
  785. 'AL',
  786. 'AL',
  787. 'AL',
  788. 'AL',
  789. 'AN',
  790. 'AN',
  791. 'AN',
  792. 'AN',
  793. 'AN',
  794. 'AN',
  795. 'AN',
  796. 'AN',
  797. 'AN',
  798. 'AN',
  799. 'ET',
  800. 'AN',
  801. 'AN',
  802. 'AL',
  803. 'AL',
  804. 'AL',
  805. 'NSM',
  806. 'AL',
  807. 'AL',
  808. 'AL',
  809. 'AL',
  810. 'AL',
  811. 'AL',
  812. 'AL',
  813. 'AL',
  814. 'AL',
  815. 'AL',
  816. 'AL',
  817. 'AL',
  818. 'AL',
  819. 'AL',
  820. 'AL',
  821. 'AL',
  822. 'AL',
  823. 'AL',
  824. 'AL',
  825. 'AL',
  826. 'AL',
  827. 'AL',
  828. 'AL',
  829. 'AL',
  830. 'AL',
  831. 'AL',
  832. 'AL',
  833. 'AL',
  834. 'AL',
  835. 'AL',
  836. 'AL',
  837. 'AL',
  838. 'AL',
  839. 'AL',
  840. 'AL',
  841. 'AL',
  842. 'AL',
  843. 'AL',
  844. 'AL',
  845. 'AL',
  846. 'AL',
  847. 'AL',
  848. 'AL',
  849. 'AL',
  850. 'AL',
  851. 'AL',
  852. 'AL',
  853. 'AL',
  854. 'AL',
  855. 'AL',
  856. 'AL',
  857. 'AL',
  858. 'AL',
  859. 'AL',
  860. 'AL',
  861. 'AL',
  862. 'AL',
  863. 'AL',
  864. 'AL',
  865. 'AL',
  866. 'AL',
  867. 'AL',
  868. 'AL',
  869. 'AL',
  870. 'AL',
  871. 'AL',
  872. 'AL',
  873. 'AL',
  874. 'AL',
  875. 'AL',
  876. 'AL',
  877. 'AL',
  878. 'AL',
  879. 'AL',
  880. 'AL',
  881. 'AL',
  882. 'AL',
  883. 'AL',
  884. 'AL',
  885. 'AL',
  886. 'AL',
  887. 'AL',
  888. 'AL',
  889. 'AL',
  890. 'AL',
  891. 'AL',
  892. 'AL',
  893. 'AL',
  894. 'AL',
  895. 'AL',
  896. 'AL',
  897. 'AL',
  898. 'AL',
  899. 'AL',
  900. 'AL',
  901. 'AL',
  902. 'AL',
  903. 'AL',
  904. 'AL',
  905. 'AL',
  906. 'AL',
  907. 'NSM',
  908. 'NSM',
  909. 'NSM',
  910. 'NSM',
  911. 'NSM',
  912. 'NSM',
  913. 'NSM',
  914. 'NSM',
  915. 'NSM',
  916. 'NSM',
  917. 'NSM',
  918. 'NSM',
  919. 'NSM',
  920. 'NSM',
  921. 'NSM',
  922. 'NSM',
  923. 'NSM',
  924. 'NSM',
  925. 'NSM',
  926. 'ON',
  927. 'NSM',
  928. 'NSM',
  929. 'NSM',
  930. 'NSM',
  931. 'AL',
  932. 'AL',
  933. 'AL',
  934. 'AL',
  935. 'AL',
  936. 'AL',
  937. 'AL',
  938. 'AL',
  939. 'AL',
  940. 'AL',
  941. 'AL',
  942. 'AL',
  943. 'AL',
  944. 'AL',
  945. 'AL',
  946. 'AL',
  947. 'AL',
  948. 'AL'
  949. ];
  950. function isOdd(i) {
  951. return (i & 1) !== 0;
  952. }
  953. function isEven(i) {
  954. return (i & 1) === 0;
  955. }
  956. function findUnequal(arr, start, value) {
  957. for (var j = start, jj = arr.length; j < jj; ++j) {
  958. if (arr[j] !== value) {
  959. return j;
  960. }
  961. }
  962. return j;
  963. }
  964. function setValues(arr, start, end, value) {
  965. for (var j = start; j < end; ++j) {
  966. arr[j] = value;
  967. }
  968. }
  969. function reverseValues(arr, start, end) {
  970. for (var i = start, j = end - 1; i < j; ++i, --j) {
  971. var temp = arr[i];
  972. arr[i] = arr[j];
  973. arr[j] = temp;
  974. }
  975. }
  976. function createBidiText(str, isLTR, vertical) {
  977. return {
  978. str: str,
  979. dir: vertical ? 'ttb' : isLTR ? 'ltr' : 'rtl'
  980. };
  981. }
  982. // These are used in bidi(), which is called frequently. We re-use them on
  983. // each call to avoid unnecessary allocations.
  984. var chars = [];
  985. var types = [];
  986. function bidi(str, startLevel, vertical) {
  987. var isLTR = true;
  988. var strLength = str.length;
  989. if (strLength === 0 || vertical) {
  990. return createBidiText(str, isLTR, vertical);
  991. }
  992. // Get types and fill arrays
  993. chars.length = strLength;
  994. types.length = strLength;
  995. var numBidi = 0;
  996. var i, ii;
  997. for (i = 0; i < strLength; ++i) {
  998. chars[i] = str.charAt(i);
  999. var charCode = str.charCodeAt(i);
  1000. var charType = 'L';
  1001. if (charCode <= 0x00ff) {
  1002. charType = baseTypes[charCode];
  1003. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  1004. charType = 'R';
  1005. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  1006. charType = arabicTypes[charCode & 0xff];
  1007. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  1008. charType = 'AL';
  1009. }
  1010. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  1011. numBidi++;
  1012. }
  1013. types[i] = charType;
  1014. }
  1015. // Detect the bidi method
  1016. // - If there are no rtl characters then no bidi needed
  1017. // - If less than 30% chars are rtl then string is primarily ltr
  1018. // - If more than 30% chars are rtl then string is primarily rtl
  1019. if (numBidi === 0) {
  1020. isLTR = true;
  1021. return createBidiText(str, isLTR);
  1022. }
  1023. if (startLevel === -1) {
  1024. if (strLength / numBidi < 0.3) {
  1025. isLTR = true;
  1026. startLevel = 0;
  1027. } else {
  1028. isLTR = false;
  1029. startLevel = 1;
  1030. }
  1031. }
  1032. var levels = [];
  1033. for (i = 0; i < strLength; ++i) {
  1034. levels[i] = startLevel;
  1035. }
  1036. /*
  1037. X1-X10: skip most of this, since we are NOT doing the embeddings.
  1038. */
  1039. var e = isOdd(startLevel) ? 'R' : 'L';
  1040. var sor = e;
  1041. var eor = sor;
  1042. /*
  1043. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  1044. type of the NSM to the type of the previous character. If the NSM is at the
  1045. start of the level run, it will get the type of sor.
  1046. */
  1047. var lastType = sor;
  1048. for (i = 0; i < strLength; ++i) {
  1049. if (types[i] === 'NSM') {
  1050. types[i] = lastType;
  1051. } else {
  1052. lastType = types[i];
  1053. }
  1054. }
  1055. /*
  1056. W2. Search backwards from each instance of a European number until the
  1057. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  1058. the type of the European number to Arabic number.
  1059. */
  1060. lastType = sor;
  1061. var t;
  1062. for (i = 0; i < strLength; ++i) {
  1063. t = types[i];
  1064. if (t === 'EN') {
  1065. types[i] = lastType === 'AL' ? 'AN' : 'EN';
  1066. } else if (t === 'R' || t === 'L' || t === 'AL') {
  1067. lastType = t;
  1068. }
  1069. }
  1070. /*
  1071. W3. Change all ALs to R.
  1072. */
  1073. for (i = 0; i < strLength; ++i) {
  1074. t = types[i];
  1075. if (t === 'AL') {
  1076. types[i] = 'R';
  1077. }
  1078. }
  1079. /*
  1080. W4. A single European separator between two European numbers changes to a
  1081. European number. A single common separator between two numbers of the same
  1082. type changes to that type:
  1083. */
  1084. for (i = 1; i < strLength - 1; ++i) {
  1085. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  1086. types[i] = 'EN';
  1087. }
  1088. if (types[i] === 'CS' && (types[i - 1] === 'EN' || types[i - 1] === 'AN') && types[i + 1] === types[i - 1]) {
  1089. types[i] = types[i - 1];
  1090. }
  1091. }
  1092. /*
  1093. W5. A sequence of European terminators adjacent to European numbers changes
  1094. to all European numbers:
  1095. */
  1096. for (i = 0; i < strLength; ++i) {
  1097. if (types[i] === 'EN') {
  1098. // do before
  1099. var j;
  1100. for (j = i - 1; j >= 0; --j) {
  1101. if (types[j] !== 'ET') {
  1102. break;
  1103. }
  1104. types[j] = 'EN';
  1105. }
  1106. // do after
  1107. for (j = i + 1; j < strLength; ++j) {
  1108. if (types[j] !== 'ET') {
  1109. break;
  1110. }
  1111. types[j] = 'EN';
  1112. }
  1113. }
  1114. }
  1115. /*
  1116. W6. Otherwise, separators and terminators change to Other Neutral:
  1117. */
  1118. for (i = 0; i < strLength; ++i) {
  1119. t = types[i];
  1120. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  1121. types[i] = 'ON';
  1122. }
  1123. }
  1124. /*
  1125. W7. Search backwards from each instance of a European number until the
  1126. first strong type (R, L, or sor) is found. If an L is found, then change
  1127. the type of the European number to L.
  1128. */
  1129. lastType = sor;
  1130. for (i = 0; i < strLength; ++i) {
  1131. t = types[i];
  1132. if (t === 'EN') {
  1133. types[i] = lastType === 'L' ? 'L' : 'EN';
  1134. } else if (t === 'R' || t === 'L') {
  1135. lastType = t;
  1136. }
  1137. }
  1138. /*
  1139. N1. A sequence of neutrals takes the direction of the surrounding strong
  1140. text if the text on both sides has the same direction. European and Arabic
  1141. numbers are treated as though they were R. Start-of-level-run (sor) and
  1142. end-of-level-run (eor) are used at level run boundaries.
  1143. */
  1144. for (i = 0; i < strLength; ++i) {
  1145. if (types[i] === 'ON') {
  1146. var end = findUnequal(types, i + 1, 'ON');
  1147. var before = sor;
  1148. if (i > 0) {
  1149. before = types[i - 1];
  1150. }
  1151. var after = eor;
  1152. if (end + 1 < strLength) {
  1153. after = types[end + 1];
  1154. }
  1155. if (before !== 'L') {
  1156. before = 'R';
  1157. }
  1158. if (after !== 'L') {
  1159. after = 'R';
  1160. }
  1161. if (before === after) {
  1162. setValues(types, i, end, before);
  1163. }
  1164. i = end - 1;
  1165. }
  1166. }
  1167. // reset to end (-1 so next iteration is ok)
  1168. /*
  1169. N2. Any remaining neutrals take the embedding direction.
  1170. */
  1171. for (i = 0; i < strLength; ++i) {
  1172. if (types[i] === 'ON') {
  1173. types[i] = e;
  1174. }
  1175. }
  1176. /*
  1177. I1. For all characters with an even (left-to-right) embedding direction,
  1178. those of type R go up one level and those of type AN or EN go up two
  1179. levels.
  1180. I2. For all characters with an odd (right-to-left) embedding direction,
  1181. those of type L, EN or AN go up one level.
  1182. */
  1183. for (i = 0; i < strLength; ++i) {
  1184. t = types[i];
  1185. if (isEven(levels[i])) {
  1186. if (t === 'R') {
  1187. levels[i] += 1;
  1188. } else if (t === 'AN' || t === 'EN') {
  1189. levels[i] += 2;
  1190. }
  1191. } else {
  1192. // isOdd
  1193. if (t === 'L' || t === 'AN' || t === 'EN') {
  1194. levels[i] += 1;
  1195. }
  1196. }
  1197. }
  1198. /*
  1199. L1. On each line, reset the embedding level of the following characters to
  1200. the paragraph embedding level:
  1201. segment separators,
  1202. paragraph separators,
  1203. any sequence of whitespace characters preceding a segment separator or
  1204. paragraph separator, and any sequence of white space characters at the end
  1205. of the line.
  1206. */
  1207. // don't bother as text is only single line
  1208. /*
  1209. L2. From the highest level found in the text to the lowest odd level on
  1210. each line, reverse any contiguous sequence of characters that are at that
  1211. level or higher.
  1212. */
  1213. // find highest level & lowest odd level
  1214. var highestLevel = -1;
  1215. var lowestOddLevel = 99;
  1216. var level;
  1217. for (i = 0, ii = levels.length; i < ii; ++i) {
  1218. level = levels[i];
  1219. if (highestLevel < level) {
  1220. highestLevel = level;
  1221. }
  1222. if (lowestOddLevel > level && isOdd(level)) {
  1223. lowestOddLevel = level;
  1224. }
  1225. }
  1226. // now reverse between those limits
  1227. for (level = highestLevel; level >= lowestOddLevel; --level) {
  1228. // find segments to reverse
  1229. var start = -1;
  1230. for (i = 0, ii = levels.length; i < ii; ++i) {
  1231. if (levels[i] < level) {
  1232. if (start >= 0) {
  1233. reverseValues(chars, start, i);
  1234. start = -1;
  1235. }
  1236. } else if (start < 0) {
  1237. start = i;
  1238. }
  1239. }
  1240. if (start >= 0) {
  1241. reverseValues(chars, start, levels.length);
  1242. }
  1243. }
  1244. /*
  1245. L3. Combining marks applied to a right-to-left base character will at this
  1246. point precede their base character. If the rendering engine expects them to
  1247. follow the base characters in the final display process, then the ordering
  1248. of the marks and the base character must be reversed.
  1249. */
  1250. // don't bother for now
  1251. /*
  1252. L4. A character that possesses the mirrored property as specified by
  1253. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  1254. directionality of that character is R.
  1255. */
  1256. // don't mirror as characters are already mirrored in the pdf
  1257. // Finally, return string
  1258. for (i = 0, ii = chars.length; i < ii; ++i) {
  1259. var ch = chars[i];
  1260. if (ch === '<' || ch === '>') {
  1261. chars[i] = '';
  1262. }
  1263. }
  1264. return createBidiText(chars.join(''), isLTR);
  1265. }
  1266. exports.bidi = bidi;
  1267. }));
  1268. (function (root, factory) {
  1269. factory(root.pdfjsCoreCharsets = {});
  1270. }(this, function (exports) {
  1271. var ISOAdobeCharset = [
  1272. '.notdef',
  1273. 'space',
  1274. 'exclam',
  1275. 'quotedbl',
  1276. 'numbersign',
  1277. 'dollar',
  1278. 'percent',
  1279. 'ampersand',
  1280. 'quoteright',
  1281. 'parenleft',
  1282. 'parenright',
  1283. 'asterisk',
  1284. 'plus',
  1285. 'comma',
  1286. 'hyphen',
  1287. 'period',
  1288. 'slash',
  1289. 'zero',
  1290. 'one',
  1291. 'two',
  1292. 'three',
  1293. 'four',
  1294. 'five',
  1295. 'six',
  1296. 'seven',
  1297. 'eight',
  1298. 'nine',
  1299. 'colon',
  1300. 'semicolon',
  1301. 'less',
  1302. 'equal',
  1303. 'greater',
  1304. 'question',
  1305. 'at',
  1306. 'A',
  1307. 'B',
  1308. 'C',
  1309. 'D',
  1310. 'E',
  1311. 'F',
  1312. 'G',
  1313. 'H',
  1314. 'I',
  1315. 'J',
  1316. 'K',
  1317. 'L',
  1318. 'M',
  1319. 'N',
  1320. 'O',
  1321. 'P',
  1322. 'Q',
  1323. 'R',
  1324. 'S',
  1325. 'T',
  1326. 'U',
  1327. 'V',
  1328. 'W',
  1329. 'X',
  1330. 'Y',
  1331. 'Z',
  1332. 'bracketleft',
  1333. 'backslash',
  1334. 'bracketright',
  1335. 'asciicircum',
  1336. 'underscore',
  1337. 'quoteleft',
  1338. 'a',
  1339. 'b',
  1340. 'c',
  1341. 'd',
  1342. 'e',
  1343. 'f',
  1344. 'g',
  1345. 'h',
  1346. 'i',
  1347. 'j',
  1348. 'k',
  1349. 'l',
  1350. 'm',
  1351. 'n',
  1352. 'o',
  1353. 'p',
  1354. 'q',
  1355. 'r',
  1356. 's',
  1357. 't',
  1358. 'u',
  1359. 'v',
  1360. 'w',
  1361. 'x',
  1362. 'y',
  1363. 'z',
  1364. 'braceleft',
  1365. 'bar',
  1366. 'braceright',
  1367. 'asciitilde',
  1368. 'exclamdown',
  1369. 'cent',
  1370. 'sterling',
  1371. 'fraction',
  1372. 'yen',
  1373. 'florin',
  1374. 'section',
  1375. 'currency',
  1376. 'quotesingle',
  1377. 'quotedblleft',
  1378. 'guillemotleft',
  1379. 'guilsinglleft',
  1380. 'guilsinglright',
  1381. 'fi',
  1382. 'fl',
  1383. 'endash',
  1384. 'dagger',
  1385. 'daggerdbl',
  1386. 'periodcentered',
  1387. 'paragraph',
  1388. 'bullet',
  1389. 'quotesinglbase',
  1390. 'quotedblbase',
  1391. 'quotedblright',
  1392. 'guillemotright',
  1393. 'ellipsis',
  1394. 'perthousand',
  1395. 'questiondown',
  1396. 'grave',
  1397. 'acute',
  1398. 'circumflex',
  1399. 'tilde',
  1400. 'macron',
  1401. 'breve',
  1402. 'dotaccent',
  1403. 'dieresis',
  1404. 'ring',
  1405. 'cedilla',
  1406. 'hungarumlaut',
  1407. 'ogonek',
  1408. 'caron',
  1409. 'emdash',
  1410. 'AE',
  1411. 'ordfeminine',
  1412. 'Lslash',
  1413. 'Oslash',
  1414. 'OE',
  1415. 'ordmasculine',
  1416. 'ae',
  1417. 'dotlessi',
  1418. 'lslash',
  1419. 'oslash',
  1420. 'oe',
  1421. 'germandbls',
  1422. 'onesuperior',
  1423. 'logicalnot',
  1424. 'mu',
  1425. 'trademark',
  1426. 'Eth',
  1427. 'onehalf',
  1428. 'plusminus',
  1429. 'Thorn',
  1430. 'onequarter',
  1431. 'divide',
  1432. 'brokenbar',
  1433. 'degree',
  1434. 'thorn',
  1435. 'threequarters',
  1436. 'twosuperior',
  1437. 'registered',
  1438. 'minus',
  1439. 'eth',
  1440. 'multiply',
  1441. 'threesuperior',
  1442. 'copyright',
  1443. 'Aacute',
  1444. 'Acircumflex',
  1445. 'Adieresis',
  1446. 'Agrave',
  1447. 'Aring',
  1448. 'Atilde',
  1449. 'Ccedilla',
  1450. 'Eacute',
  1451. 'Ecircumflex',
  1452. 'Edieresis',
  1453. 'Egrave',
  1454. 'Iacute',
  1455. 'Icircumflex',
  1456. 'Idieresis',
  1457. 'Igrave',
  1458. 'Ntilde',
  1459. 'Oacute',
  1460. 'Ocircumflex',
  1461. 'Odieresis',
  1462. 'Ograve',
  1463. 'Otilde',
  1464. 'Scaron',
  1465. 'Uacute',
  1466. 'Ucircumflex',
  1467. 'Udieresis',
  1468. 'Ugrave',
  1469. 'Yacute',
  1470. 'Ydieresis',
  1471. 'Zcaron',
  1472. 'aacute',
  1473. 'acircumflex',
  1474. 'adieresis',
  1475. 'agrave',
  1476. 'aring',
  1477. 'atilde',
  1478. 'ccedilla',
  1479. 'eacute',
  1480. 'ecircumflex',
  1481. 'edieresis',
  1482. 'egrave',
  1483. 'iacute',
  1484. 'icircumflex',
  1485. 'idieresis',
  1486. 'igrave',
  1487. 'ntilde',
  1488. 'oacute',
  1489. 'ocircumflex',
  1490. 'odieresis',
  1491. 'ograve',
  1492. 'otilde',
  1493. 'scaron',
  1494. 'uacute',
  1495. 'ucircumflex',
  1496. 'udieresis',
  1497. 'ugrave',
  1498. 'yacute',
  1499. 'ydieresis',
  1500. 'zcaron'
  1501. ];
  1502. var ExpertCharset = [
  1503. '.notdef',
  1504. 'space',
  1505. 'exclamsmall',
  1506. 'Hungarumlautsmall',
  1507. 'dollaroldstyle',
  1508. 'dollarsuperior',
  1509. 'ampersandsmall',
  1510. 'Acutesmall',
  1511. 'parenleftsuperior',
  1512. 'parenrightsuperior',
  1513. 'twodotenleader',
  1514. 'onedotenleader',
  1515. 'comma',
  1516. 'hyphen',
  1517. 'period',
  1518. 'fraction',
  1519. 'zerooldstyle',
  1520. 'oneoldstyle',
  1521. 'twooldstyle',
  1522. 'threeoldstyle',
  1523. 'fouroldstyle',
  1524. 'fiveoldstyle',
  1525. 'sixoldstyle',
  1526. 'sevenoldstyle',
  1527. 'eightoldstyle',
  1528. 'nineoldstyle',
  1529. 'colon',
  1530. 'semicolon',
  1531. 'commasuperior',
  1532. 'threequartersemdash',
  1533. 'periodsuperior',
  1534. 'questionsmall',
  1535. 'asuperior',
  1536. 'bsuperior',
  1537. 'centsuperior',
  1538. 'dsuperior',
  1539. 'esuperior',
  1540. 'isuperior',
  1541. 'lsuperior',
  1542. 'msuperior',
  1543. 'nsuperior',
  1544. 'osuperior',
  1545. 'rsuperior',
  1546. 'ssuperior',
  1547. 'tsuperior',
  1548. 'ff',
  1549. 'fi',
  1550. 'fl',
  1551. 'ffi',
  1552. 'ffl',
  1553. 'parenleftinferior',
  1554. 'parenrightinferior',
  1555. 'Circumflexsmall',
  1556. 'hyphensuperior',
  1557. 'Gravesmall',
  1558. 'Asmall',
  1559. 'Bsmall',
  1560. 'Csmall',
  1561. 'Dsmall',
  1562. 'Esmall',
  1563. 'Fsmall',
  1564. 'Gsmall',
  1565. 'Hsmall',
  1566. 'Ismall',
  1567. 'Jsmall',
  1568. 'Ksmall',
  1569. 'Lsmall',
  1570. 'Msmall',
  1571. 'Nsmall',
  1572. 'Osmall',
  1573. 'Psmall',
  1574. 'Qsmall',
  1575. 'Rsmall',
  1576. 'Ssmall',
  1577. 'Tsmall',
  1578. 'Usmall',
  1579. 'Vsmall',
  1580. 'Wsmall',
  1581. 'Xsmall',
  1582. 'Ysmall',
  1583. 'Zsmall',
  1584. 'colonmonetary',
  1585. 'onefitted',
  1586. 'rupiah',
  1587. 'Tildesmall',
  1588. 'exclamdownsmall',
  1589. 'centoldstyle',
  1590. 'Lslashsmall',
  1591. 'Scaronsmall',
  1592. 'Zcaronsmall',
  1593. 'Dieresissmall',
  1594. 'Brevesmall',
  1595. 'Caronsmall',
  1596. 'Dotaccentsmall',
  1597. 'Macronsmall',
  1598. 'figuredash',
  1599. 'hypheninferior',
  1600. 'Ogoneksmall',
  1601. 'Ringsmall',
  1602. 'Cedillasmall',
  1603. 'onequarter',
  1604. 'onehalf',
  1605. 'threequarters',
  1606. 'questiondownsmall',
  1607. 'oneeighth',
  1608. 'threeeighths',
  1609. 'fiveeighths',
  1610. 'seveneighths',
  1611. 'onethird',
  1612. 'twothirds',
  1613. 'zerosuperior',
  1614. 'onesuperior',
  1615. 'twosuperior',
  1616. 'threesuperior',
  1617. 'foursuperior',
  1618. 'fivesuperior',
  1619. 'sixsuperior',
  1620. 'sevensuperior',
  1621. 'eightsuperior',
  1622. 'ninesuperior',
  1623. 'zeroinferior',
  1624. 'oneinferior',
  1625. 'twoinferior',
  1626. 'threeinferior',
  1627. 'fourinferior',
  1628. 'fiveinferior',
  1629. 'sixinferior',
  1630. 'seveninferior',
  1631. 'eightinferior',
  1632. 'nineinferior',
  1633. 'centinferior',
  1634. 'dollarinferior',
  1635. 'periodinferior',
  1636. 'commainferior',
  1637. 'Agravesmall',
  1638. 'Aacutesmall',
  1639. 'Acircumflexsmall',
  1640. 'Atildesmall',
  1641. 'Adieresissmall',
  1642. 'Aringsmall',
  1643. 'AEsmall',
  1644. 'Ccedillasmall',
  1645. 'Egravesmall',
  1646. 'Eacutesmall',
  1647. 'Ecircumflexsmall',
  1648. 'Edieresissmall',
  1649. 'Igravesmall',
  1650. 'Iacutesmall',
  1651. 'Icircumflexsmall',
  1652. 'Idieresissmall',
  1653. 'Ethsmall',
  1654. 'Ntildesmall',
  1655. 'Ogravesmall',
  1656. 'Oacutesmall',
  1657. 'Ocircumflexsmall',
  1658. 'Otildesmall',
  1659. 'Odieresissmall',
  1660. 'OEsmall',
  1661. 'Oslashsmall',
  1662. 'Ugravesmall',
  1663. 'Uacutesmall',
  1664. 'Ucircumflexsmall',
  1665. 'Udieresissmall',
  1666. 'Yacutesmall',
  1667. 'Thornsmall',
  1668. 'Ydieresissmall'
  1669. ];
  1670. var ExpertSubsetCharset = [
  1671. '.notdef',
  1672. 'space',
  1673. 'dollaroldstyle',
  1674. 'dollarsuperior',
  1675. 'parenleftsuperior',
  1676. 'parenrightsuperior',
  1677. 'twodotenleader',
  1678. 'onedotenleader',
  1679. 'comma',
  1680. 'hyphen',
  1681. 'period',
  1682. 'fraction',
  1683. 'zerooldstyle',
  1684. 'oneoldstyle',
  1685. 'twooldstyle',
  1686. 'threeoldstyle',
  1687. 'fouroldstyle',
  1688. 'fiveoldstyle',
  1689. 'sixoldstyle',
  1690. 'sevenoldstyle',
  1691. 'eightoldstyle',
  1692. 'nineoldstyle',
  1693. 'colon',
  1694. 'semicolon',
  1695. 'commasuperior',
  1696. 'threequartersemdash',
  1697. 'periodsuperior',
  1698. 'asuperior',
  1699. 'bsuperior',
  1700. 'centsuperior',
  1701. 'dsuperior',
  1702. 'esuperior',
  1703. 'isuperior',
  1704. 'lsuperior',
  1705. 'msuperior',
  1706. 'nsuperior',
  1707. 'osuperior',
  1708. 'rsuperior',
  1709. 'ssuperior',
  1710. 'tsuperior',
  1711. 'ff',
  1712. 'fi',
  1713. 'fl',
  1714. 'ffi',
  1715. 'ffl',
  1716. 'parenleftinferior',
  1717. 'parenrightinferior',
  1718. 'hyphensuperior',
  1719. 'colonmonetary',
  1720. 'onefitted',
  1721. 'rupiah',
  1722. 'centoldstyle',
  1723. 'figuredash',
  1724. 'hypheninferior',
  1725. 'onequarter',
  1726. 'onehalf',
  1727. 'threequarters',
  1728. 'oneeighth',
  1729. 'threeeighths',
  1730. 'fiveeighths',
  1731. 'seveneighths',
  1732. 'onethird',
  1733. 'twothirds',
  1734. 'zerosuperior',
  1735. 'onesuperior',
  1736. 'twosuperior',
  1737. 'threesuperior',
  1738. 'foursuperior',
  1739. 'fivesuperior',
  1740. 'sixsuperior',
  1741. 'sevensuperior',
  1742. 'eightsuperior',
  1743. 'ninesuperior',
  1744. 'zeroinferior',
  1745. 'oneinferior',
  1746. 'twoinferior',
  1747. 'threeinferior',
  1748. 'fourinferior',
  1749. 'fiveinferior',
  1750. 'sixinferior',
  1751. 'seveninferior',
  1752. 'eightinferior',
  1753. 'nineinferior',
  1754. 'centinferior',
  1755. 'dollarinferior',
  1756. 'periodinferior',
  1757. 'commainferior'
  1758. ];
  1759. exports.ISOAdobeCharset = ISOAdobeCharset;
  1760. exports.ExpertCharset = ExpertCharset;
  1761. exports.ExpertSubsetCharset = ExpertSubsetCharset;
  1762. }));
  1763. (function (root, factory) {
  1764. factory(root.pdfjsCoreEncodings = {});
  1765. }(this, function (exports) {
  1766. var ExpertEncoding = [
  1767. '',
  1768. '',
  1769. '',
  1770. '',
  1771. '',
  1772. '',
  1773. '',
  1774. '',
  1775. '',
  1776. '',
  1777. '',
  1778. '',
  1779. '',
  1780. '',
  1781. '',
  1782. '',
  1783. '',
  1784. '',
  1785. '',
  1786. '',
  1787. '',
  1788. '',
  1789. '',
  1790. '',
  1791. '',
  1792. '',
  1793. '',
  1794. '',
  1795. '',
  1796. '',
  1797. '',
  1798. '',
  1799. 'space',
  1800. 'exclamsmall',
  1801. 'Hungarumlautsmall',
  1802. '',
  1803. 'dollaroldstyle',
  1804. 'dollarsuperior',
  1805. 'ampersandsmall',
  1806. 'Acutesmall',
  1807. 'parenleftsuperior',
  1808. 'parenrightsuperior',
  1809. 'twodotenleader',
  1810. 'onedotenleader',
  1811. 'comma',
  1812. 'hyphen',
  1813. 'period',
  1814. 'fraction',
  1815. 'zerooldstyle',
  1816. 'oneoldstyle',
  1817. 'twooldstyle',
  1818. 'threeoldstyle',
  1819. 'fouroldstyle',
  1820. 'fiveoldstyle',
  1821. 'sixoldstyle',
  1822. 'sevenoldstyle',
  1823. 'eightoldstyle',
  1824. 'nineoldstyle',
  1825. 'colon',
  1826. 'semicolon',
  1827. 'commasuperior',
  1828. 'threequartersemdash',
  1829. 'periodsuperior',
  1830. 'questionsmall',
  1831. '',
  1832. 'asuperior',
  1833. 'bsuperior',
  1834. 'centsuperior',
  1835. 'dsuperior',
  1836. 'esuperior',
  1837. '',
  1838. '',
  1839. 'isuperior',
  1840. '',
  1841. '',
  1842. 'lsuperior',
  1843. 'msuperior',
  1844. 'nsuperior',
  1845. 'osuperior',
  1846. '',
  1847. '',
  1848. 'rsuperior',
  1849. 'ssuperior',
  1850. 'tsuperior',
  1851. '',
  1852. 'ff',
  1853. 'fi',
  1854. 'fl',
  1855. 'ffi',
  1856. 'ffl',
  1857. 'parenleftinferior',
  1858. '',
  1859. 'parenrightinferior',
  1860. 'Circumflexsmall',
  1861. 'hyphensuperior',
  1862. 'Gravesmall',
  1863. 'Asmall',
  1864. 'Bsmall',
  1865. 'Csmall',
  1866. 'Dsmall',
  1867. 'Esmall',
  1868. 'Fsmall',
  1869. 'Gsmall',
  1870. 'Hsmall',
  1871. 'Ismall',
  1872. 'Jsmall',
  1873. 'Ksmall',
  1874. 'Lsmall',
  1875. 'Msmall',
  1876. 'Nsmall',
  1877. 'Osmall',
  1878. 'Psmall',
  1879. 'Qsmall',
  1880. 'Rsmall',
  1881. 'Ssmall',
  1882. 'Tsmall',
  1883. 'Usmall',
  1884. 'Vsmall',
  1885. 'Wsmall',
  1886. 'Xsmall',
  1887. 'Ysmall',
  1888. 'Zsmall',
  1889. 'colonmonetary',
  1890. 'onefitted',
  1891. 'rupiah',
  1892. 'Tildesmall',
  1893. '',
  1894. '',
  1895. '',
  1896. '',
  1897. '',
  1898. '',
  1899. '',
  1900. '',
  1901. '',
  1902. '',
  1903. '',
  1904. '',
  1905. '',
  1906. '',
  1907. '',
  1908. '',
  1909. '',
  1910. '',
  1911. '',
  1912. '',
  1913. '',
  1914. '',
  1915. '',
  1916. '',
  1917. '',
  1918. '',
  1919. '',
  1920. '',
  1921. '',
  1922. '',
  1923. '',
  1924. '',
  1925. '',
  1926. '',
  1927. 'exclamdownsmall',
  1928. 'centoldstyle',
  1929. 'Lslashsmall',
  1930. '',
  1931. '',
  1932. 'Scaronsmall',
  1933. 'Zcaronsmall',
  1934. 'Dieresissmall',
  1935. 'Brevesmall',
  1936. 'Caronsmall',
  1937. '',
  1938. 'Dotaccentsmall',
  1939. '',
  1940. '',
  1941. 'Macronsmall',
  1942. '',
  1943. '',
  1944. 'figuredash',
  1945. 'hypheninferior',
  1946. '',
  1947. '',
  1948. 'Ogoneksmall',
  1949. 'Ringsmall',
  1950. 'Cedillasmall',
  1951. '',
  1952. '',
  1953. '',
  1954. 'onequarter',
  1955. 'onehalf',
  1956. 'threequarters',
  1957. 'questiondownsmall',
  1958. 'oneeighth',
  1959. 'threeeighths',
  1960. 'fiveeighths',
  1961. 'seveneighths',
  1962. 'onethird',
  1963. 'twothirds',
  1964. '',
  1965. '',
  1966. 'zerosuperior',
  1967. 'onesuperior',
  1968. 'twosuperior',
  1969. 'threesuperior',
  1970. 'foursuperior',
  1971. 'fivesuperior',
  1972. 'sixsuperior',
  1973. 'sevensuperior',
  1974. 'eightsuperior',
  1975. 'ninesuperior',
  1976. 'zeroinferior',
  1977. 'oneinferior',
  1978. 'twoinferior',
  1979. 'threeinferior',
  1980. 'fourinferior',
  1981. 'fiveinferior',
  1982. 'sixinferior',
  1983. 'seveninferior',
  1984. 'eightinferior',
  1985. 'nineinferior',
  1986. 'centinferior',
  1987. 'dollarinferior',
  1988. 'periodinferior',
  1989. 'commainferior',
  1990. 'Agravesmall',
  1991. 'Aacutesmall',
  1992. 'Acircumflexsmall',
  1993. 'Atildesmall',
  1994. 'Adieresissmall',
  1995. 'Aringsmall',
  1996. 'AEsmall',
  1997. 'Ccedillasmall',
  1998. 'Egravesmall',
  1999. 'Eacutesmall',
  2000. 'Ecircumflexsmall',
  2001. 'Edieresissmall',
  2002. 'Igravesmall',
  2003. 'Iacutesmall',
  2004. 'Icircumflexsmall',
  2005. 'Idieresissmall',
  2006. 'Ethsmall',
  2007. 'Ntildesmall',
  2008. 'Ogravesmall',
  2009. 'Oacutesmall',
  2010. 'Ocircumflexsmall',
  2011. 'Otildesmall',
  2012. 'Odieresissmall',
  2013. 'OEsmall',
  2014. 'Oslashsmall',
  2015. 'Ugravesmall',
  2016. 'Uacutesmall',
  2017. 'Ucircumflexsmall',
  2018. 'Udieresissmall',
  2019. 'Yacutesmall',
  2020. 'Thornsmall',
  2021. 'Ydieresissmall'
  2022. ];
  2023. var MacExpertEncoding = [
  2024. '',
  2025. '',
  2026. '',
  2027. '',
  2028. '',
  2029. '',
  2030. '',
  2031. '',
  2032. '',
  2033. '',
  2034. '',
  2035. '',
  2036. '',
  2037. '',
  2038. '',
  2039. '',
  2040. '',
  2041. '',
  2042. '',
  2043. '',
  2044. '',
  2045. '',
  2046. '',
  2047. '',
  2048. '',
  2049. '',
  2050. '',
  2051. '',
  2052. '',
  2053. '',
  2054. '',
  2055. '',
  2056. 'space',
  2057. 'exclamsmall',
  2058. 'Hungarumlautsmall',
  2059. 'centoldstyle',
  2060. 'dollaroldstyle',
  2061. 'dollarsuperior',
  2062. 'ampersandsmall',
  2063. 'Acutesmall',
  2064. 'parenleftsuperior',
  2065. 'parenrightsuperior',
  2066. 'twodotenleader',
  2067. 'onedotenleader',
  2068. 'comma',
  2069. 'hyphen',
  2070. 'period',
  2071. 'fraction',
  2072. 'zerooldstyle',
  2073. 'oneoldstyle',
  2074. 'twooldstyle',
  2075. 'threeoldstyle',
  2076. 'fouroldstyle',
  2077. 'fiveoldstyle',
  2078. 'sixoldstyle',
  2079. 'sevenoldstyle',
  2080. 'eightoldstyle',
  2081. 'nineoldstyle',
  2082. 'colon',
  2083. 'semicolon',
  2084. '',
  2085. 'threequartersemdash',
  2086. '',
  2087. 'questionsmall',
  2088. '',
  2089. '',
  2090. '',
  2091. '',
  2092. 'Ethsmall',
  2093. '',
  2094. '',
  2095. 'onequarter',
  2096. 'onehalf',
  2097. 'threequarters',
  2098. 'oneeighth',
  2099. 'threeeighths',
  2100. 'fiveeighths',
  2101. 'seveneighths',
  2102. 'onethird',
  2103. 'twothirds',
  2104. '',
  2105. '',
  2106. '',
  2107. '',
  2108. '',
  2109. '',
  2110. 'ff',
  2111. 'fi',
  2112. 'fl',
  2113. 'ffi',
  2114. 'ffl',
  2115. 'parenleftinferior',
  2116. '',
  2117. 'parenrightinferior',
  2118. 'Circumflexsmall',
  2119. 'hypheninferior',
  2120. 'Gravesmall',
  2121. 'Asmall',
  2122. 'Bsmall',
  2123. 'Csmall',
  2124. 'Dsmall',
  2125. 'Esmall',
  2126. 'Fsmall',
  2127. 'Gsmall',
  2128. 'Hsmall',
  2129. 'Ismall',
  2130. 'Jsmall',
  2131. 'Ksmall',
  2132. 'Lsmall',
  2133. 'Msmall',
  2134. 'Nsmall',
  2135. 'Osmall',
  2136. 'Psmall',
  2137. 'Qsmall',
  2138. 'Rsmall',
  2139. 'Ssmall',
  2140. 'Tsmall',
  2141. 'Usmall',
  2142. 'Vsmall',
  2143. 'Wsmall',
  2144. 'Xsmall',
  2145. 'Ysmall',
  2146. 'Zsmall',
  2147. 'colonmonetary',
  2148. 'onefitted',
  2149. 'rupiah',
  2150. 'Tildesmall',
  2151. '',
  2152. '',
  2153. 'asuperior',
  2154. 'centsuperior',
  2155. '',
  2156. '',
  2157. '',
  2158. '',
  2159. 'Aacutesmall',
  2160. 'Agravesmall',
  2161. 'Acircumflexsmall',
  2162. 'Adieresissmall',
  2163. 'Atildesmall',
  2164. 'Aringsmall',
  2165. 'Ccedillasmall',
  2166. 'Eacutesmall',
  2167. 'Egravesmall',
  2168. 'Ecircumflexsmall',
  2169. 'Edieresissmall',
  2170. 'Iacutesmall',
  2171. 'Igravesmall',
  2172. 'Icircumflexsmall',
  2173. 'Idieresissmall',
  2174. 'Ntildesmall',
  2175. 'Oacutesmall',
  2176. 'Ogravesmall',
  2177. 'Ocircumflexsmall',
  2178. 'Odieresissmall',
  2179. 'Otildesmall',
  2180. 'Uacutesmall',
  2181. 'Ugravesmall',
  2182. 'Ucircumflexsmall',
  2183. 'Udieresissmall',
  2184. '',
  2185. 'eightsuperior',
  2186. 'fourinferior',
  2187. 'threeinferior',
  2188. 'sixinferior',
  2189. 'eightinferior',
  2190. 'seveninferior',
  2191. 'Scaronsmall',
  2192. '',
  2193. 'centinferior',
  2194. 'twoinferior',
  2195. '',
  2196. 'Dieresissmall',
  2197. '',
  2198. 'Caronsmall',
  2199. 'osuperior',
  2200. 'fiveinferior',
  2201. '',
  2202. 'commainferior',
  2203. 'periodinferior',
  2204. 'Yacutesmall',
  2205. '',
  2206. 'dollarinferior',
  2207. '',
  2208. 'Thornsmall',
  2209. '',
  2210. 'nineinferior',
  2211. 'zeroinferior',
  2212. 'Zcaronsmall',
  2213. 'AEsmall',
  2214. 'Oslashsmall',
  2215. 'questiondownsmall',
  2216. 'oneinferior',
  2217. 'Lslashsmall',
  2218. '',
  2219. '',
  2220. '',
  2221. '',
  2222. '',
  2223. '',
  2224. 'Cedillasmall',
  2225. '',
  2226. '',
  2227. '',
  2228. '',
  2229. '',
  2230. 'OEsmall',
  2231. 'figuredash',
  2232. 'hyphensuperior',
  2233. '',
  2234. '',
  2235. '',
  2236. '',
  2237. 'exclamdownsmall',
  2238. '',
  2239. 'Ydieresissmall',
  2240. '',
  2241. 'onesuperior',
  2242. 'twosuperior',
  2243. 'threesuperior',
  2244. 'foursuperior',
  2245. 'fivesuperior',
  2246. 'sixsuperior',
  2247. 'sevensuperior',
  2248. 'ninesuperior',
  2249. 'zerosuperior',
  2250. '',
  2251. 'esuperior',
  2252. 'rsuperior',
  2253. 'tsuperior',
  2254. '',
  2255. '',
  2256. 'isuperior',
  2257. 'ssuperior',
  2258. 'dsuperior',
  2259. '',
  2260. '',
  2261. '',
  2262. '',
  2263. '',
  2264. 'lsuperior',
  2265. 'Ogoneksmall',
  2266. 'Brevesmall',
  2267. 'Macronsmall',
  2268. 'bsuperior',
  2269. 'nsuperior',
  2270. 'msuperior',
  2271. 'commasuperior',
  2272. 'periodsuperior',
  2273. 'Dotaccentsmall',
  2274. 'Ringsmall'
  2275. ];
  2276. var MacRomanEncoding = [
  2277. '',
  2278. '',
  2279. '',
  2280. '',
  2281. '',
  2282. '',
  2283. '',
  2284. '',
  2285. '',
  2286. '',
  2287. '',
  2288. '',
  2289. '',
  2290. '',
  2291. '',
  2292. '',
  2293. '',
  2294. '',
  2295. '',
  2296. '',
  2297. '',
  2298. '',
  2299. '',
  2300. '',
  2301. '',
  2302. '',
  2303. '',
  2304. '',
  2305. '',
  2306. '',
  2307. '',
  2308. '',
  2309. 'space',
  2310. 'exclam',
  2311. 'quotedbl',
  2312. 'numbersign',
  2313. 'dollar',
  2314. 'percent',
  2315. 'ampersand',
  2316. 'quotesingle',
  2317. 'parenleft',
  2318. 'parenright',
  2319. 'asterisk',
  2320. 'plus',
  2321. 'comma',
  2322. 'hyphen',
  2323. 'period',
  2324. 'slash',
  2325. 'zero',
  2326. 'one',
  2327. 'two',
  2328. 'three',
  2329. 'four',
  2330. 'five',
  2331. 'six',
  2332. 'seven',
  2333. 'eight',
  2334. 'nine',
  2335. 'colon',
  2336. 'semicolon',
  2337. 'less',
  2338. 'equal',
  2339. 'greater',
  2340. 'question',
  2341. 'at',
  2342. 'A',
  2343. 'B',
  2344. 'C',
  2345. 'D',
  2346. 'E',
  2347. 'F',
  2348. 'G',
  2349. 'H',
  2350. 'I',
  2351. 'J',
  2352. 'K',
  2353. 'L',
  2354. 'M',
  2355. 'N',
  2356. 'O',
  2357. 'P',
  2358. 'Q',
  2359. 'R',
  2360. 'S',
  2361. 'T',
  2362. 'U',
  2363. 'V',
  2364. 'W',
  2365. 'X',
  2366. 'Y',
  2367. 'Z',
  2368. 'bracketleft',
  2369. 'backslash',
  2370. 'bracketright',
  2371. 'asciicircum',
  2372. 'underscore',
  2373. 'grave',
  2374. 'a',
  2375. 'b',
  2376. 'c',
  2377. 'd',
  2378. 'e',
  2379. 'f',
  2380. 'g',
  2381. 'h',
  2382. 'i',
  2383. 'j',
  2384. 'k',
  2385. 'l',
  2386. 'm',
  2387. 'n',
  2388. 'o',
  2389. 'p',
  2390. 'q',
  2391. 'r',
  2392. 's',
  2393. 't',
  2394. 'u',
  2395. 'v',
  2396. 'w',
  2397. 'x',
  2398. 'y',
  2399. 'z',
  2400. 'braceleft',
  2401. 'bar',
  2402. 'braceright',
  2403. 'asciitilde',
  2404. '',
  2405. 'Adieresis',
  2406. 'Aring',
  2407. 'Ccedilla',
  2408. 'Eacute',
  2409. 'Ntilde',
  2410. 'Odieresis',
  2411. 'Udieresis',
  2412. 'aacute',
  2413. 'agrave',
  2414. 'acircumflex',
  2415. 'adieresis',
  2416. 'atilde',
  2417. 'aring',
  2418. 'ccedilla',
  2419. 'eacute',
  2420. 'egrave',
  2421. 'ecircumflex',
  2422. 'edieresis',
  2423. 'iacute',
  2424. 'igrave',
  2425. 'icircumflex',
  2426. 'idieresis',
  2427. 'ntilde',
  2428. 'oacute',
  2429. 'ograve',
  2430. 'ocircumflex',
  2431. 'odieresis',
  2432. 'otilde',
  2433. 'uacute',
  2434. 'ugrave',
  2435. 'ucircumflex',
  2436. 'udieresis',
  2437. 'dagger',
  2438. 'degree',
  2439. 'cent',
  2440. 'sterling',
  2441. 'section',
  2442. 'bullet',
  2443. 'paragraph',
  2444. 'germandbls',
  2445. 'registered',
  2446. 'copyright',
  2447. 'trademark',
  2448. 'acute',
  2449. 'dieresis',
  2450. 'notequal',
  2451. 'AE',
  2452. 'Oslash',
  2453. 'infinity',
  2454. 'plusminus',
  2455. 'lessequal',
  2456. 'greaterequal',
  2457. 'yen',
  2458. 'mu',
  2459. 'partialdiff',
  2460. 'summation',
  2461. 'product',
  2462. 'pi',
  2463. 'integral',
  2464. 'ordfeminine',
  2465. 'ordmasculine',
  2466. 'Omega',
  2467. 'ae',
  2468. 'oslash',
  2469. 'questiondown',
  2470. 'exclamdown',
  2471. 'logicalnot',
  2472. 'radical',
  2473. 'florin',
  2474. 'approxequal',
  2475. 'Delta',
  2476. 'guillemotleft',
  2477. 'guillemotright',
  2478. 'ellipsis',
  2479. 'space',
  2480. 'Agrave',
  2481. 'Atilde',
  2482. 'Otilde',
  2483. 'OE',
  2484. 'oe',
  2485. 'endash',
  2486. 'emdash',
  2487. 'quotedblleft',
  2488. 'quotedblright',
  2489. 'quoteleft',
  2490. 'quoteright',
  2491. 'divide',
  2492. 'lozenge',
  2493. 'ydieresis',
  2494. 'Ydieresis',
  2495. 'fraction',
  2496. 'currency',
  2497. 'guilsinglleft',
  2498. 'guilsinglright',
  2499. 'fi',
  2500. 'fl',
  2501. 'daggerdbl',
  2502. 'periodcentered',
  2503. 'quotesinglbase',
  2504. 'quotedblbase',
  2505. 'perthousand',
  2506. 'Acircumflex',
  2507. 'Ecircumflex',
  2508. 'Aacute',
  2509. 'Edieresis',
  2510. 'Egrave',
  2511. 'Iacute',
  2512. 'Icircumflex',
  2513. 'Idieresis',
  2514. 'Igrave',
  2515. 'Oacute',
  2516. 'Ocircumflex',
  2517. 'apple',
  2518. 'Ograve',
  2519. 'Uacute',
  2520. 'Ucircumflex',
  2521. 'Ugrave',
  2522. 'dotlessi',
  2523. 'circumflex',
  2524. 'tilde',
  2525. 'macron',
  2526. 'breve',
  2527. 'dotaccent',
  2528. 'ring',
  2529. 'cedilla',
  2530. 'hungarumlaut',
  2531. 'ogonek',
  2532. 'caron'
  2533. ];
  2534. var StandardEncoding = [
  2535. '',
  2536. '',
  2537. '',
  2538. '',
  2539. '',
  2540. '',
  2541. '',
  2542. '',
  2543. '',
  2544. '',
  2545. '',
  2546. '',
  2547. '',
  2548. '',
  2549. '',
  2550. '',
  2551. '',
  2552. '',
  2553. '',
  2554. '',
  2555. '',
  2556. '',
  2557. '',
  2558. '',
  2559. '',
  2560. '',
  2561. '',
  2562. '',
  2563. '',
  2564. '',
  2565. '',
  2566. '',
  2567. 'space',
  2568. 'exclam',
  2569. 'quotedbl',
  2570. 'numbersign',
  2571. 'dollar',
  2572. 'percent',
  2573. 'ampersand',
  2574. 'quoteright',
  2575. 'parenleft',
  2576. 'parenright',
  2577. 'asterisk',
  2578. 'plus',
  2579. 'comma',
  2580. 'hyphen',
  2581. 'period',
  2582. 'slash',
  2583. 'zero',
  2584. 'one',
  2585. 'two',
  2586. 'three',
  2587. 'four',
  2588. 'five',
  2589. 'six',
  2590. 'seven',
  2591. 'eight',
  2592. 'nine',
  2593. 'colon',
  2594. 'semicolon',
  2595. 'less',
  2596. 'equal',
  2597. 'greater',
  2598. 'question',
  2599. 'at',
  2600. 'A',
  2601. 'B',
  2602. 'C',
  2603. 'D',
  2604. 'E',
  2605. 'F',
  2606. 'G',
  2607. 'H',
  2608. 'I',
  2609. 'J',
  2610. 'K',
  2611. 'L',
  2612. 'M',
  2613. 'N',
  2614. 'O',
  2615. 'P',
  2616. 'Q',
  2617. 'R',
  2618. 'S',
  2619. 'T',
  2620. 'U',
  2621. 'V',
  2622. 'W',
  2623. 'X',
  2624. 'Y',
  2625. 'Z',
  2626. 'bracketleft',
  2627. 'backslash',
  2628. 'bracketright',
  2629. 'asciicircum',
  2630. 'underscore',
  2631. 'quoteleft',
  2632. 'a',
  2633. 'b',
  2634. 'c',
  2635. 'd',
  2636. 'e',
  2637. 'f',
  2638. 'g',
  2639. 'h',
  2640. 'i',
  2641. 'j',
  2642. 'k',
  2643. 'l',
  2644. 'm',
  2645. 'n',
  2646. 'o',
  2647. 'p',
  2648. 'q',
  2649. 'r',
  2650. 's',
  2651. 't',
  2652. 'u',
  2653. 'v',
  2654. 'w',
  2655. 'x',
  2656. 'y',
  2657. 'z',
  2658. 'braceleft',
  2659. 'bar',
  2660. 'braceright',
  2661. 'asciitilde',
  2662. '',
  2663. '',
  2664. '',
  2665. '',
  2666. '',
  2667. '',
  2668. '',
  2669. '',
  2670. '',
  2671. '',
  2672. '',
  2673. '',
  2674. '',
  2675. '',
  2676. '',
  2677. '',
  2678. '',
  2679. '',
  2680. '',
  2681. '',
  2682. '',
  2683. '',
  2684. '',
  2685. '',
  2686. '',
  2687. '',
  2688. '',
  2689. '',
  2690. '',
  2691. '',
  2692. '',
  2693. '',
  2694. '',
  2695. '',
  2696. 'exclamdown',
  2697. 'cent',
  2698. 'sterling',
  2699. 'fraction',
  2700. 'yen',
  2701. 'florin',
  2702. 'section',
  2703. 'currency',
  2704. 'quotesingle',
  2705. 'quotedblleft',
  2706. 'guillemotleft',
  2707. 'guilsinglleft',
  2708. 'guilsinglright',
  2709. 'fi',
  2710. 'fl',
  2711. '',
  2712. 'endash',
  2713. 'dagger',
  2714. 'daggerdbl',
  2715. 'periodcentered',
  2716. '',
  2717. 'paragraph',
  2718. 'bullet',
  2719. 'quotesinglbase',
  2720. 'quotedblbase',
  2721. 'quotedblright',
  2722. 'guillemotright',
  2723. 'ellipsis',
  2724. 'perthousand',
  2725. '',
  2726. 'questiondown',
  2727. '',
  2728. 'grave',
  2729. 'acute',
  2730. 'circumflex',
  2731. 'tilde',
  2732. 'macron',
  2733. 'breve',
  2734. 'dotaccent',
  2735. 'dieresis',
  2736. '',
  2737. 'ring',
  2738. 'cedilla',
  2739. '',
  2740. 'hungarumlaut',
  2741. 'ogonek',
  2742. 'caron',
  2743. 'emdash',
  2744. '',
  2745. '',
  2746. '',
  2747. '',
  2748. '',
  2749. '',
  2750. '',
  2751. '',
  2752. '',
  2753. '',
  2754. '',
  2755. '',
  2756. '',
  2757. '',
  2758. '',
  2759. '',
  2760. 'AE',
  2761. '',
  2762. 'ordfeminine',
  2763. '',
  2764. '',
  2765. '',
  2766. '',
  2767. 'Lslash',
  2768. 'Oslash',
  2769. 'OE',
  2770. 'ordmasculine',
  2771. '',
  2772. '',
  2773. '',
  2774. '',
  2775. '',
  2776. 'ae',
  2777. '',
  2778. '',
  2779. '',
  2780. 'dotlessi',
  2781. '',
  2782. '',
  2783. 'lslash',
  2784. 'oslash',
  2785. 'oe',
  2786. 'germandbls'
  2787. ];
  2788. var WinAnsiEncoding = [
  2789. '',
  2790. '',
  2791. '',
  2792. '',
  2793. '',
  2794. '',
  2795. '',
  2796. '',
  2797. '',
  2798. '',
  2799. '',
  2800. '',
  2801. '',
  2802. '',
  2803. '',
  2804. '',
  2805. '',
  2806. '',
  2807. '',
  2808. '',
  2809. '',
  2810. '',
  2811. '',
  2812. '',
  2813. '',
  2814. '',
  2815. '',
  2816. '',
  2817. '',
  2818. '',
  2819. '',
  2820. '',
  2821. 'space',
  2822. 'exclam',
  2823. 'quotedbl',
  2824. 'numbersign',
  2825. 'dollar',
  2826. 'percent',
  2827. 'ampersand',
  2828. 'quotesingle',
  2829. 'parenleft',
  2830. 'parenright',
  2831. 'asterisk',
  2832. 'plus',
  2833. 'comma',
  2834. 'hyphen',
  2835. 'period',
  2836. 'slash',
  2837. 'zero',
  2838. 'one',
  2839. 'two',
  2840. 'three',
  2841. 'four',
  2842. 'five',
  2843. 'six',
  2844. 'seven',
  2845. 'eight',
  2846. 'nine',
  2847. 'colon',
  2848. 'semicolon',
  2849. 'less',
  2850. 'equal',
  2851. 'greater',
  2852. 'question',
  2853. 'at',
  2854. 'A',
  2855. 'B',
  2856. 'C',
  2857. 'D',
  2858. 'E',
  2859. 'F',
  2860. 'G',
  2861. 'H',
  2862. 'I',
  2863. 'J',
  2864. 'K',
  2865. 'L',
  2866. 'M',
  2867. 'N',
  2868. 'O',
  2869. 'P',
  2870. 'Q',
  2871. 'R',
  2872. 'S',
  2873. 'T',
  2874. 'U',
  2875. 'V',
  2876. 'W',
  2877. 'X',
  2878. 'Y',
  2879. 'Z',
  2880. 'bracketleft',
  2881. 'backslash',
  2882. 'bracketright',
  2883. 'asciicircum',
  2884. 'underscore',
  2885. 'grave',
  2886. 'a',
  2887. 'b',
  2888. 'c',
  2889. 'd',
  2890. 'e',
  2891. 'f',
  2892. 'g',
  2893. 'h',
  2894. 'i',
  2895. 'j',
  2896. 'k',
  2897. 'l',
  2898. 'm',
  2899. 'n',
  2900. 'o',
  2901. 'p',
  2902. 'q',
  2903. 'r',
  2904. 's',
  2905. 't',
  2906. 'u',
  2907. 'v',
  2908. 'w',
  2909. 'x',
  2910. 'y',
  2911. 'z',
  2912. 'braceleft',
  2913. 'bar',
  2914. 'braceright',
  2915. 'asciitilde',
  2916. 'bullet',
  2917. 'Euro',
  2918. 'bullet',
  2919. 'quotesinglbase',
  2920. 'florin',
  2921. 'quotedblbase',
  2922. 'ellipsis',
  2923. 'dagger',
  2924. 'daggerdbl',
  2925. 'circumflex',
  2926. 'perthousand',
  2927. 'Scaron',
  2928. 'guilsinglleft',
  2929. 'OE',
  2930. 'bullet',
  2931. 'Zcaron',
  2932. 'bullet',
  2933. 'bullet',
  2934. 'quoteleft',
  2935. 'quoteright',
  2936. 'quotedblleft',
  2937. 'quotedblright',
  2938. 'bullet',
  2939. 'endash',
  2940. 'emdash',
  2941. 'tilde',
  2942. 'trademark',
  2943. 'scaron',
  2944. 'guilsinglright',
  2945. 'oe',
  2946. 'bullet',
  2947. 'zcaron',
  2948. 'Ydieresis',
  2949. 'space',
  2950. 'exclamdown',
  2951. 'cent',
  2952. 'sterling',
  2953. 'currency',
  2954. 'yen',
  2955. 'brokenbar',
  2956. 'section',
  2957. 'dieresis',
  2958. 'copyright',
  2959. 'ordfeminine',
  2960. 'guillemotleft',
  2961. 'logicalnot',
  2962. 'hyphen',
  2963. 'registered',
  2964. 'macron',
  2965. 'degree',
  2966. 'plusminus',
  2967. 'twosuperior',
  2968. 'threesuperior',
  2969. 'acute',
  2970. 'mu',
  2971. 'paragraph',
  2972. 'periodcentered',
  2973. 'cedilla',
  2974. 'onesuperior',
  2975. 'ordmasculine',
  2976. 'guillemotright',
  2977. 'onequarter',
  2978. 'onehalf',
  2979. 'threequarters',
  2980. 'questiondown',
  2981. 'Agrave',
  2982. 'Aacute',
  2983. 'Acircumflex',
  2984. 'Atilde',
  2985. 'Adieresis',
  2986. 'Aring',
  2987. 'AE',
  2988. 'Ccedilla',
  2989. 'Egrave',
  2990. 'Eacute',
  2991. 'Ecircumflex',
  2992. 'Edieresis',
  2993. 'Igrave',
  2994. 'Iacute',
  2995. 'Icircumflex',
  2996. 'Idieresis',
  2997. 'Eth',
  2998. 'Ntilde',
  2999. 'Ograve',
  3000. 'Oacute',
  3001. 'Ocircumflex',
  3002. 'Otilde',
  3003. 'Odieresis',
  3004. 'multiply',
  3005. 'Oslash',
  3006. 'Ugrave',
  3007. 'Uacute',
  3008. 'Ucircumflex',
  3009. 'Udieresis',
  3010. 'Yacute',
  3011. 'Thorn',
  3012. 'germandbls',
  3013. 'agrave',
  3014. 'aacute',
  3015. 'acircumflex',
  3016. 'atilde',
  3017. 'adieresis',
  3018. 'aring',
  3019. 'ae',
  3020. 'ccedilla',
  3021. 'egrave',
  3022. 'eacute',
  3023. 'ecircumflex',
  3024. 'edieresis',
  3025. 'igrave',
  3026. 'iacute',
  3027. 'icircumflex',
  3028. 'idieresis',
  3029. 'eth',
  3030. 'ntilde',
  3031. 'ograve',
  3032. 'oacute',
  3033. 'ocircumflex',
  3034. 'otilde',
  3035. 'odieresis',
  3036. 'divide',
  3037. 'oslash',
  3038. 'ugrave',
  3039. 'uacute',
  3040. 'ucircumflex',
  3041. 'udieresis',
  3042. 'yacute',
  3043. 'thorn',
  3044. 'ydieresis'
  3045. ];
  3046. var SymbolSetEncoding = [
  3047. '',
  3048. '',
  3049. '',
  3050. '',
  3051. '',
  3052. '',
  3053. '',
  3054. '',
  3055. '',
  3056. '',
  3057. '',
  3058. '',
  3059. '',
  3060. '',
  3061. '',
  3062. '',
  3063. '',
  3064. '',
  3065. '',
  3066. '',
  3067. '',
  3068. '',
  3069. '',
  3070. '',
  3071. '',
  3072. '',
  3073. '',
  3074. '',
  3075. '',
  3076. '',
  3077. '',
  3078. '',
  3079. 'space',
  3080. 'exclam',
  3081. 'universal',
  3082. 'numbersign',
  3083. 'existential',
  3084. 'percent',
  3085. 'ampersand',
  3086. 'suchthat',
  3087. 'parenleft',
  3088. 'parenright',
  3089. 'asteriskmath',
  3090. 'plus',
  3091. 'comma',
  3092. 'minus',
  3093. 'period',
  3094. 'slash',
  3095. 'zero',
  3096. 'one',
  3097. 'two',
  3098. 'three',
  3099. 'four',
  3100. 'five',
  3101. 'six',
  3102. 'seven',
  3103. 'eight',
  3104. 'nine',
  3105. 'colon',
  3106. 'semicolon',
  3107. 'less',
  3108. 'equal',
  3109. 'greater',
  3110. 'question',
  3111. 'congruent',
  3112. 'Alpha',
  3113. 'Beta',
  3114. 'Chi',
  3115. 'Delta',
  3116. 'Epsilon',
  3117. 'Phi',
  3118. 'Gamma',
  3119. 'Eta',
  3120. 'Iota',
  3121. 'theta1',
  3122. 'Kappa',
  3123. 'Lambda',
  3124. 'Mu',
  3125. 'Nu',
  3126. 'Omicron',
  3127. 'Pi',
  3128. 'Theta',
  3129. 'Rho',
  3130. 'Sigma',
  3131. 'Tau',
  3132. 'Upsilon',
  3133. 'sigma1',
  3134. 'Omega',
  3135. 'Xi',
  3136. 'Psi',
  3137. 'Zeta',
  3138. 'bracketleft',
  3139. 'therefore',
  3140. 'bracketright',
  3141. 'perpendicular',
  3142. 'underscore',
  3143. 'radicalex',
  3144. 'alpha',
  3145. 'beta',
  3146. 'chi',
  3147. 'delta',
  3148. 'epsilon',
  3149. 'phi',
  3150. 'gamma',
  3151. 'eta',
  3152. 'iota',
  3153. 'phi1',
  3154. 'kappa',
  3155. 'lambda',
  3156. 'mu',
  3157. 'nu',
  3158. 'omicron',
  3159. 'pi',
  3160. 'theta',
  3161. 'rho',
  3162. 'sigma',
  3163. 'tau',
  3164. 'upsilon',
  3165. 'omega1',
  3166. 'omega',
  3167. 'xi',
  3168. 'psi',
  3169. 'zeta',
  3170. 'braceleft',
  3171. 'bar',
  3172. 'braceright',
  3173. 'similar',
  3174. '',
  3175. '',
  3176. '',
  3177. '',
  3178. '',
  3179. '',
  3180. '',
  3181. '',
  3182. '',
  3183. '',
  3184. '',
  3185. '',
  3186. '',
  3187. '',
  3188. '',
  3189. '',
  3190. '',
  3191. '',
  3192. '',
  3193. '',
  3194. '',
  3195. '',
  3196. '',
  3197. '',
  3198. '',
  3199. '',
  3200. '',
  3201. '',
  3202. '',
  3203. '',
  3204. '',
  3205. '',
  3206. '',
  3207. 'Euro',
  3208. 'Upsilon1',
  3209. 'minute',
  3210. 'lessequal',
  3211. 'fraction',
  3212. 'infinity',
  3213. 'florin',
  3214. 'club',
  3215. 'diamond',
  3216. 'heart',
  3217. 'spade',
  3218. 'arrowboth',
  3219. 'arrowleft',
  3220. 'arrowup',
  3221. 'arrowright',
  3222. 'arrowdown',
  3223. 'degree',
  3224. 'plusminus',
  3225. 'second',
  3226. 'greaterequal',
  3227. 'multiply',
  3228. 'proportional',
  3229. 'partialdiff',
  3230. 'bullet',
  3231. 'divide',
  3232. 'notequal',
  3233. 'equivalence',
  3234. 'approxequal',
  3235. 'ellipsis',
  3236. 'arrowvertex',
  3237. 'arrowhorizex',
  3238. 'carriagereturn',
  3239. 'aleph',
  3240. 'Ifraktur',
  3241. 'Rfraktur',
  3242. 'weierstrass',
  3243. 'circlemultiply',
  3244. 'circleplus',
  3245. 'emptyset',
  3246. 'intersection',
  3247. 'union',
  3248. 'propersuperset',
  3249. 'reflexsuperset',
  3250. 'notsubset',
  3251. 'propersubset',
  3252. 'reflexsubset',
  3253. 'element',
  3254. 'notelement',
  3255. 'angle',
  3256. 'gradient',
  3257. 'registerserif',
  3258. 'copyrightserif',
  3259. 'trademarkserif',
  3260. 'product',
  3261. 'radical',
  3262. 'dotmath',
  3263. 'logicalnot',
  3264. 'logicaland',
  3265. 'logicalor',
  3266. 'arrowdblboth',
  3267. 'arrowdblleft',
  3268. 'arrowdblup',
  3269. 'arrowdblright',
  3270. 'arrowdbldown',
  3271. 'lozenge',
  3272. 'angleleft',
  3273. 'registersans',
  3274. 'copyrightsans',
  3275. 'trademarksans',
  3276. 'summation',
  3277. 'parenlefttp',
  3278. 'parenleftex',
  3279. 'parenleftbt',
  3280. 'bracketlefttp',
  3281. 'bracketleftex',
  3282. 'bracketleftbt',
  3283. 'bracelefttp',
  3284. 'braceleftmid',
  3285. 'braceleftbt',
  3286. 'braceex',
  3287. '',
  3288. 'angleright',
  3289. 'integral',
  3290. 'integraltp',
  3291. 'integralex',
  3292. 'integralbt',
  3293. 'parenrighttp',
  3294. 'parenrightex',
  3295. 'parenrightbt',
  3296. 'bracketrighttp',
  3297. 'bracketrightex',
  3298. 'bracketrightbt',
  3299. 'bracerighttp',
  3300. 'bracerightmid',
  3301. 'bracerightbt'
  3302. ];
  3303. var ZapfDingbatsEncoding = [
  3304. '',
  3305. '',
  3306. '',
  3307. '',
  3308. '',
  3309. '',
  3310. '',
  3311. '',
  3312. '',
  3313. '',
  3314. '',
  3315. '',
  3316. '',
  3317. '',
  3318. '',
  3319. '',
  3320. '',
  3321. '',
  3322. '',
  3323. '',
  3324. '',
  3325. '',
  3326. '',
  3327. '',
  3328. '',
  3329. '',
  3330. '',
  3331. '',
  3332. '',
  3333. '',
  3334. '',
  3335. '',
  3336. 'space',
  3337. 'a1',
  3338. 'a2',
  3339. 'a202',
  3340. 'a3',
  3341. 'a4',
  3342. 'a5',
  3343. 'a119',
  3344. 'a118',
  3345. 'a117',
  3346. 'a11',
  3347. 'a12',
  3348. 'a13',
  3349. 'a14',
  3350. 'a15',
  3351. 'a16',
  3352. 'a105',
  3353. 'a17',
  3354. 'a18',
  3355. 'a19',
  3356. 'a20',
  3357. 'a21',
  3358. 'a22',
  3359. 'a23',
  3360. 'a24',
  3361. 'a25',
  3362. 'a26',
  3363. 'a27',
  3364. 'a28',
  3365. 'a6',
  3366. 'a7',
  3367. 'a8',
  3368. 'a9',
  3369. 'a10',
  3370. 'a29',
  3371. 'a30',
  3372. 'a31',
  3373. 'a32',
  3374. 'a33',
  3375. 'a34',
  3376. 'a35',
  3377. 'a36',
  3378. 'a37',
  3379. 'a38',
  3380. 'a39',
  3381. 'a40',
  3382. 'a41',
  3383. 'a42',
  3384. 'a43',
  3385. 'a44',
  3386. 'a45',
  3387. 'a46',
  3388. 'a47',
  3389. 'a48',
  3390. 'a49',
  3391. 'a50',
  3392. 'a51',
  3393. 'a52',
  3394. 'a53',
  3395. 'a54',
  3396. 'a55',
  3397. 'a56',
  3398. 'a57',
  3399. 'a58',
  3400. 'a59',
  3401. 'a60',
  3402. 'a61',
  3403. 'a62',
  3404. 'a63',
  3405. 'a64',
  3406. 'a65',
  3407. 'a66',
  3408. 'a67',
  3409. 'a68',
  3410. 'a69',
  3411. 'a70',
  3412. 'a71',
  3413. 'a72',
  3414. 'a73',
  3415. 'a74',
  3416. 'a203',
  3417. 'a75',
  3418. 'a204',
  3419. 'a76',
  3420. 'a77',
  3421. 'a78',
  3422. 'a79',
  3423. 'a81',
  3424. 'a82',
  3425. 'a83',
  3426. 'a84',
  3427. 'a97',
  3428. 'a98',
  3429. 'a99',
  3430. 'a100',
  3431. '',
  3432. 'a89',
  3433. 'a90',
  3434. 'a93',
  3435. 'a94',
  3436. 'a91',
  3437. 'a92',
  3438. 'a205',
  3439. 'a85',
  3440. 'a206',
  3441. 'a86',
  3442. 'a87',
  3443. 'a88',
  3444. 'a95',
  3445. 'a96',
  3446. '',
  3447. '',
  3448. '',
  3449. '',
  3450. '',
  3451. '',
  3452. '',
  3453. '',
  3454. '',
  3455. '',
  3456. '',
  3457. '',
  3458. '',
  3459. '',
  3460. '',
  3461. '',
  3462. '',
  3463. '',
  3464. '',
  3465. 'a101',
  3466. 'a102',
  3467. 'a103',
  3468. 'a104',
  3469. 'a106',
  3470. 'a107',
  3471. 'a108',
  3472. 'a112',
  3473. 'a111',
  3474. 'a110',
  3475. 'a109',
  3476. 'a120',
  3477. 'a121',
  3478. 'a122',
  3479. 'a123',
  3480. 'a124',
  3481. 'a125',
  3482. 'a126',
  3483. 'a127',
  3484. 'a128',
  3485. 'a129',
  3486. 'a130',
  3487. 'a131',
  3488. 'a132',
  3489. 'a133',
  3490. 'a134',
  3491. 'a135',
  3492. 'a136',
  3493. 'a137',
  3494. 'a138',
  3495. 'a139',
  3496. 'a140',
  3497. 'a141',
  3498. 'a142',
  3499. 'a143',
  3500. 'a144',
  3501. 'a145',
  3502. 'a146',
  3503. 'a147',
  3504. 'a148',
  3505. 'a149',
  3506. 'a150',
  3507. 'a151',
  3508. 'a152',
  3509. 'a153',
  3510. 'a154',
  3511. 'a155',
  3512. 'a156',
  3513. 'a157',
  3514. 'a158',
  3515. 'a159',
  3516. 'a160',
  3517. 'a161',
  3518. 'a163',
  3519. 'a164',
  3520. 'a196',
  3521. 'a165',
  3522. 'a192',
  3523. 'a166',
  3524. 'a167',
  3525. 'a168',
  3526. 'a169',
  3527. 'a170',
  3528. 'a171',
  3529. 'a172',
  3530. 'a173',
  3531. 'a162',
  3532. 'a174',
  3533. 'a175',
  3534. 'a176',
  3535. 'a177',
  3536. 'a178',
  3537. 'a179',
  3538. 'a193',
  3539. 'a180',
  3540. 'a199',
  3541. 'a181',
  3542. 'a200',
  3543. 'a182',
  3544. '',
  3545. 'a201',
  3546. 'a183',
  3547. 'a184',
  3548. 'a197',
  3549. 'a185',
  3550. 'a194',
  3551. 'a198',
  3552. 'a186',
  3553. 'a195',
  3554. 'a187',
  3555. 'a188',
  3556. 'a189',
  3557. 'a190',
  3558. 'a191'
  3559. ];
  3560. function getEncoding(encodingName) {
  3561. switch (encodingName) {
  3562. case 'WinAnsiEncoding':
  3563. return WinAnsiEncoding;
  3564. case 'StandardEncoding':
  3565. return StandardEncoding;
  3566. case 'MacRomanEncoding':
  3567. return MacRomanEncoding;
  3568. case 'SymbolSetEncoding':
  3569. return SymbolSetEncoding;
  3570. case 'ZapfDingbatsEncoding':
  3571. return ZapfDingbatsEncoding;
  3572. case 'ExpertEncoding':
  3573. return ExpertEncoding;
  3574. case 'MacExpertEncoding':
  3575. return MacExpertEncoding;
  3576. default:
  3577. return null;
  3578. }
  3579. }
  3580. exports.WinAnsiEncoding = WinAnsiEncoding;
  3581. exports.StandardEncoding = StandardEncoding;
  3582. exports.MacRomanEncoding = MacRomanEncoding;
  3583. exports.SymbolSetEncoding = SymbolSetEncoding;
  3584. exports.ZapfDingbatsEncoding = ZapfDingbatsEncoding;
  3585. exports.ExpertEncoding = ExpertEncoding;
  3586. exports.getEncoding = getEncoding;
  3587. }));
  3588. (function (root, factory) {
  3589. factory(root.pdfjsSharedUtil = {});
  3590. }(this, function (exports) {
  3591. var globalScope = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : this;
  3592. var FONT_IDENTITY_MATRIX = [
  3593. 0.001,
  3594. 0,
  3595. 0,
  3596. 0.001,
  3597. 0,
  3598. 0
  3599. ];
  3600. var TextRenderingMode = {
  3601. FILL: 0,
  3602. STROKE: 1,
  3603. FILL_STROKE: 2,
  3604. INVISIBLE: 3,
  3605. FILL_ADD_TO_PATH: 4,
  3606. STROKE_ADD_TO_PATH: 5,
  3607. FILL_STROKE_ADD_TO_PATH: 6,
  3608. ADD_TO_PATH: 7,
  3609. FILL_STROKE_MASK: 3,
  3610. ADD_TO_PATH_FLAG: 4
  3611. };
  3612. var ImageKind = {
  3613. GRAYSCALE_1BPP: 1,
  3614. RGB_24BPP: 2,
  3615. RGBA_32BPP: 3
  3616. };
  3617. var AnnotationType = {
  3618. TEXT: 1,
  3619. LINK: 2,
  3620. FREETEXT: 3,
  3621. LINE: 4,
  3622. SQUARE: 5,
  3623. CIRCLE: 6,
  3624. POLYGON: 7,
  3625. POLYLINE: 8,
  3626. HIGHLIGHT: 9,
  3627. UNDERLINE: 10,
  3628. SQUIGGLY: 11,
  3629. STRIKEOUT: 12,
  3630. STAMP: 13,
  3631. CARET: 14,
  3632. INK: 15,
  3633. POPUP: 16,
  3634. FILEATTACHMENT: 17,
  3635. SOUND: 18,
  3636. MOVIE: 19,
  3637. WIDGET: 20,
  3638. SCREEN: 21,
  3639. PRINTERMARK: 22,
  3640. TRAPNET: 23,
  3641. WATERMARK: 24,
  3642. THREED: 25,
  3643. REDACT: 26
  3644. };
  3645. var AnnotationFlag = {
  3646. INVISIBLE: 0x01,
  3647. HIDDEN: 0x02,
  3648. PRINT: 0x04,
  3649. NOZOOM: 0x08,
  3650. NOROTATE: 0x10,
  3651. NOVIEW: 0x20,
  3652. READONLY: 0x40,
  3653. LOCKED: 0x80,
  3654. TOGGLENOVIEW: 0x100,
  3655. LOCKEDCONTENTS: 0x200
  3656. };
  3657. var AnnotationFieldFlag = {
  3658. READONLY: 0x0000001,
  3659. REQUIRED: 0x0000002,
  3660. NOEXPORT: 0x0000004,
  3661. MULTILINE: 0x0001000,
  3662. PASSWORD: 0x0002000,
  3663. NOTOGGLETOOFF: 0x0004000,
  3664. RADIO: 0x0008000,
  3665. PUSHBUTTON: 0x0010000,
  3666. COMBO: 0x0020000,
  3667. EDIT: 0x0040000,
  3668. SORT: 0x0080000,
  3669. FILESELECT: 0x0100000,
  3670. MULTISELECT: 0x0200000,
  3671. DONOTSPELLCHECK: 0x0400000,
  3672. DONOTSCROLL: 0x0800000,
  3673. COMB: 0x1000000,
  3674. RICHTEXT: 0x2000000,
  3675. RADIOSINUNISON: 0x2000000,
  3676. COMMITONSELCHANGE: 0x4000000
  3677. };
  3678. var AnnotationBorderStyleType = {
  3679. SOLID: 1,
  3680. DASHED: 2,
  3681. BEVELED: 3,
  3682. INSET: 4,
  3683. UNDERLINE: 5
  3684. };
  3685. var StreamType = {
  3686. UNKNOWN: 0,
  3687. FLATE: 1,
  3688. LZW: 2,
  3689. DCT: 3,
  3690. JPX: 4,
  3691. JBIG: 5,
  3692. A85: 6,
  3693. AHX: 7,
  3694. CCF: 8,
  3695. RL: 9
  3696. };
  3697. var FontType = {
  3698. UNKNOWN: 0,
  3699. TYPE1: 1,
  3700. TYPE1C: 2,
  3701. CIDFONTTYPE0: 3,
  3702. CIDFONTTYPE0C: 4,
  3703. TRUETYPE: 5,
  3704. CIDFONTTYPE2: 6,
  3705. TYPE3: 7,
  3706. OPENTYPE: 8,
  3707. TYPE0: 9,
  3708. MMTYPE1: 10
  3709. };
  3710. var VERBOSITY_LEVELS = {
  3711. errors: 0,
  3712. warnings: 1,
  3713. infos: 5
  3714. };
  3715. // All the possible operations for an operator list.
  3716. var OPS = {
  3717. // Intentionally start from 1 so it is easy to spot bad operators that will be
  3718. // 0's.
  3719. dependency: 1,
  3720. setLineWidth: 2,
  3721. setLineCap: 3,
  3722. setLineJoin: 4,
  3723. setMiterLimit: 5,
  3724. setDash: 6,
  3725. setRenderingIntent: 7,
  3726. setFlatness: 8,
  3727. setGState: 9,
  3728. save: 10,
  3729. restore: 11,
  3730. transform: 12,
  3731. moveTo: 13,
  3732. lineTo: 14,
  3733. curveTo: 15,
  3734. curveTo2: 16,
  3735. curveTo3: 17,
  3736. closePath: 18,
  3737. rectangle: 19,
  3738. stroke: 20,
  3739. closeStroke: 21,
  3740. fill: 22,
  3741. eoFill: 23,
  3742. fillStroke: 24,
  3743. eoFillStroke: 25,
  3744. closeFillStroke: 26,
  3745. closeEOFillStroke: 27,
  3746. endPath: 28,
  3747. clip: 29,
  3748. eoClip: 30,
  3749. beginText: 31,
  3750. endText: 32,
  3751. setCharSpacing: 33,
  3752. setWordSpacing: 34,
  3753. setHScale: 35,
  3754. setLeading: 36,
  3755. setFont: 37,
  3756. setTextRenderingMode: 38,
  3757. setTextRise: 39,
  3758. moveText: 40,
  3759. setLeadingMoveText: 41,
  3760. setTextMatrix: 42,
  3761. nextLine: 43,
  3762. showText: 44,
  3763. showSpacedText: 45,
  3764. nextLineShowText: 46,
  3765. nextLineSetSpacingShowText: 47,
  3766. setCharWidth: 48,
  3767. setCharWidthAndBounds: 49,
  3768. setStrokeColorSpace: 50,
  3769. setFillColorSpace: 51,
  3770. setStrokeColor: 52,
  3771. setStrokeColorN: 53,
  3772. setFillColor: 54,
  3773. setFillColorN: 55,
  3774. setStrokeGray: 56,
  3775. setFillGray: 57,
  3776. setStrokeRGBColor: 58,
  3777. setFillRGBColor: 59,
  3778. setStrokeCMYKColor: 60,
  3779. setFillCMYKColor: 61,
  3780. shadingFill: 62,
  3781. beginInlineImage: 63,
  3782. beginImageData: 64,
  3783. endInlineImage: 65,
  3784. paintXObject: 66,
  3785. markPoint: 67,
  3786. markPointProps: 68,
  3787. beginMarkedContent: 69,
  3788. beginMarkedContentProps: 70,
  3789. endMarkedContent: 71,
  3790. beginCompat: 72,
  3791. endCompat: 73,
  3792. paintFormXObjectBegin: 74,
  3793. paintFormXObjectEnd: 75,
  3794. beginGroup: 76,
  3795. endGroup: 77,
  3796. beginAnnotations: 78,
  3797. endAnnotations: 79,
  3798. beginAnnotation: 80,
  3799. endAnnotation: 81,
  3800. paintJpegXObject: 82,
  3801. paintImageMaskXObject: 83,
  3802. paintImageMaskXObjectGroup: 84,
  3803. paintImageXObject: 85,
  3804. paintInlineImageXObject: 86,
  3805. paintInlineImageXObjectGroup: 87,
  3806. paintImageXObjectRepeat: 88,
  3807. paintImageMaskXObjectRepeat: 89,
  3808. paintSolidColorImageMask: 90,
  3809. constructPath: 91
  3810. };
  3811. var verbosity = VERBOSITY_LEVELS.warnings;
  3812. function setVerbosityLevel(level) {
  3813. verbosity = level;
  3814. }
  3815. function getVerbosityLevel() {
  3816. return verbosity;
  3817. }
  3818. // A notice for devs. These are good for things that are helpful to devs, such
  3819. // as warning that Workers were disabled, which is important to devs but not
  3820. // end users.
  3821. function info(msg) {
  3822. if (verbosity >= VERBOSITY_LEVELS.infos) {
  3823. console.log('Info: ' + msg);
  3824. }
  3825. }
  3826. // Non-fatal warnings.
  3827. function warn(msg) {
  3828. if (verbosity >= VERBOSITY_LEVELS.warnings) {
  3829. console.log('Warning: ' + msg);
  3830. }
  3831. }
  3832. // Deprecated API function -- display regardless of the PDFJS.verbosity setting.
  3833. function deprecated(details) {
  3834. console.log('Deprecated API usage: ' + details);
  3835. }
  3836. // Fatal errors that should trigger the fallback UI and halt execution by
  3837. // throwing an exception.
  3838. function error(msg) {
  3839. if (verbosity >= VERBOSITY_LEVELS.errors) {
  3840. console.log('Error: ' + msg);
  3841. console.log(backtrace());
  3842. }
  3843. throw new Error(msg);
  3844. }
  3845. function backtrace() {
  3846. try {
  3847. throw new Error();
  3848. } catch (e) {
  3849. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  3850. }
  3851. }
  3852. function assert(cond, msg) {
  3853. if (!cond) {
  3854. error(msg);
  3855. }
  3856. }
  3857. var UNSUPPORTED_FEATURES = {
  3858. unknown: 'unknown',
  3859. forms: 'forms',
  3860. javaScript: 'javaScript',
  3861. smask: 'smask',
  3862. shadingPattern: 'shadingPattern',
  3863. font: 'font'
  3864. };
  3865. // Checks if URLs have the same origin. For non-HTTP based URLs, returns false.
  3866. function isSameOrigin(baseUrl, otherUrl) {
  3867. try {
  3868. var base = new URL(baseUrl);
  3869. if (!base.origin || base.origin === 'null') {
  3870. return false;
  3871. }
  3872. } // non-HTTP url
  3873. catch (e) {
  3874. return false;
  3875. }
  3876. var other = new URL(otherUrl, base);
  3877. return base.origin === other.origin;
  3878. }
  3879. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  3880. function isValidUrl(url, allowRelative) {
  3881. if (!url || typeof url !== 'string') {
  3882. return false;
  3883. }
  3884. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  3885. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  3886. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  3887. if (!protocol) {
  3888. return allowRelative;
  3889. }
  3890. protocol = protocol[0].toLowerCase();
  3891. switch (protocol) {
  3892. case 'http':
  3893. case 'https':
  3894. case 'ftp':
  3895. case 'mailto':
  3896. case 'tel':
  3897. return true;
  3898. default:
  3899. return false;
  3900. }
  3901. }
  3902. function shadow(obj, prop, value) {
  3903. Object.defineProperty(obj, prop, {
  3904. value: value,
  3905. enumerable: true,
  3906. configurable: true,
  3907. writable: false
  3908. });
  3909. return value;
  3910. }
  3911. function getLookupTableFactory(initializer) {
  3912. var lookup;
  3913. return function () {
  3914. if (initializer) {
  3915. lookup = Object.create(null);
  3916. initializer(lookup);
  3917. initializer = null;
  3918. }
  3919. return lookup;
  3920. };
  3921. }
  3922. var PasswordResponses = {
  3923. NEED_PASSWORD: 1,
  3924. INCORRECT_PASSWORD: 2
  3925. };
  3926. var PasswordException = function PasswordExceptionClosure() {
  3927. function PasswordException(msg, code) {
  3928. this.name = 'PasswordException';
  3929. this.message = msg;
  3930. this.code = code;
  3931. }
  3932. PasswordException.prototype = new Error();
  3933. PasswordException.constructor = PasswordException;
  3934. return PasswordException;
  3935. }();
  3936. var UnknownErrorException = function UnknownErrorExceptionClosure() {
  3937. function UnknownErrorException(msg, details) {
  3938. this.name = 'UnknownErrorException';
  3939. this.message = msg;
  3940. this.details = details;
  3941. }
  3942. UnknownErrorException.prototype = new Error();
  3943. UnknownErrorException.constructor = UnknownErrorException;
  3944. return UnknownErrorException;
  3945. }();
  3946. var InvalidPDFException = function InvalidPDFExceptionClosure() {
  3947. function InvalidPDFException(msg) {
  3948. this.name = 'InvalidPDFException';
  3949. this.message = msg;
  3950. }
  3951. InvalidPDFException.prototype = new Error();
  3952. InvalidPDFException.constructor = InvalidPDFException;
  3953. return InvalidPDFException;
  3954. }();
  3955. var MissingPDFException = function MissingPDFExceptionClosure() {
  3956. function MissingPDFException(msg) {
  3957. this.name = 'MissingPDFException';
  3958. this.message = msg;
  3959. }
  3960. MissingPDFException.prototype = new Error();
  3961. MissingPDFException.constructor = MissingPDFException;
  3962. return MissingPDFException;
  3963. }();
  3964. var UnexpectedResponseException = function UnexpectedResponseExceptionClosure() {
  3965. function UnexpectedResponseException(msg, status) {
  3966. this.name = 'UnexpectedResponseException';
  3967. this.message = msg;
  3968. this.status = status;
  3969. }
  3970. UnexpectedResponseException.prototype = new Error();
  3971. UnexpectedResponseException.constructor = UnexpectedResponseException;
  3972. return UnexpectedResponseException;
  3973. }();
  3974. var NotImplementedException = function NotImplementedExceptionClosure() {
  3975. function NotImplementedException(msg) {
  3976. this.message = msg;
  3977. }
  3978. NotImplementedException.prototype = new Error();
  3979. NotImplementedException.prototype.name = 'NotImplementedException';
  3980. NotImplementedException.constructor = NotImplementedException;
  3981. return NotImplementedException;
  3982. }();
  3983. var MissingDataException = function MissingDataExceptionClosure() {
  3984. function MissingDataException(begin, end) {
  3985. this.begin = begin;
  3986. this.end = end;
  3987. this.message = 'Missing data [' + begin + ', ' + end + ')';
  3988. }
  3989. MissingDataException.prototype = new Error();
  3990. MissingDataException.prototype.name = 'MissingDataException';
  3991. MissingDataException.constructor = MissingDataException;
  3992. return MissingDataException;
  3993. }();
  3994. var XRefParseException = function XRefParseExceptionClosure() {
  3995. function XRefParseException(msg) {
  3996. this.message = msg;
  3997. }
  3998. XRefParseException.prototype = new Error();
  3999. XRefParseException.prototype.name = 'XRefParseException';
  4000. XRefParseException.constructor = XRefParseException;
  4001. return XRefParseException;
  4002. }();
  4003. var NullCharactersRegExp = /\x00/g;
  4004. function removeNullCharacters(str) {
  4005. if (typeof str !== 'string') {
  4006. warn('The argument for removeNullCharacters must be a string.');
  4007. return str;
  4008. }
  4009. return str.replace(NullCharactersRegExp, '');
  4010. }
  4011. function bytesToString(bytes) {
  4012. assert(bytes !== null && typeof bytes === 'object' && bytes.length !== undefined, 'Invalid argument for bytesToString');
  4013. var length = bytes.length;
  4014. var MAX_ARGUMENT_COUNT = 8192;
  4015. if (length < MAX_ARGUMENT_COUNT) {
  4016. return String.fromCharCode.apply(null, bytes);
  4017. }
  4018. var strBuf = [];
  4019. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  4020. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  4021. var chunk = bytes.subarray(i, chunkEnd);
  4022. strBuf.push(String.fromCharCode.apply(null, chunk));
  4023. }
  4024. return strBuf.join('');
  4025. }
  4026. function stringToBytes(str) {
  4027. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  4028. var length = str.length;
  4029. var bytes = new Uint8Array(length);
  4030. for (var i = 0; i < length; ++i) {
  4031. bytes[i] = str.charCodeAt(i) & 0xFF;
  4032. }
  4033. return bytes;
  4034. }
  4035. /**
  4036. * Gets length of the array (Array, Uint8Array, or string) in bytes.
  4037. * @param {Array|Uint8Array|string} arr
  4038. * @returns {number}
  4039. */
  4040. function arrayByteLength(arr) {
  4041. if (arr.length !== undefined) {
  4042. return arr.length;
  4043. }
  4044. assert(arr.byteLength !== undefined);
  4045. return arr.byteLength;
  4046. }
  4047. /**
  4048. * Combines array items (arrays) into single Uint8Array object.
  4049. * @param {Array} arr - the array of the arrays (Array, Uint8Array, or string).
  4050. * @returns {Uint8Array}
  4051. */
  4052. function arraysToBytes(arr) {
  4053. // Shortcut: if first and only item is Uint8Array, return it.
  4054. if (arr.length === 1 && arr[0] instanceof Uint8Array) {
  4055. return arr[0];
  4056. }
  4057. var resultLength = 0;
  4058. var i, ii = arr.length;
  4059. var item, itemLength;
  4060. for (i = 0; i < ii; i++) {
  4061. item = arr[i];
  4062. itemLength = arrayByteLength(item);
  4063. resultLength += itemLength;
  4064. }
  4065. var pos = 0;
  4066. var data = new Uint8Array(resultLength);
  4067. for (i = 0; i < ii; i++) {
  4068. item = arr[i];
  4069. if (!(item instanceof Uint8Array)) {
  4070. if (typeof item === 'string') {
  4071. item = stringToBytes(item);
  4072. } else {
  4073. item = new Uint8Array(item);
  4074. }
  4075. }
  4076. itemLength = item.byteLength;
  4077. data.set(item, pos);
  4078. pos += itemLength;
  4079. }
  4080. return data;
  4081. }
  4082. function string32(value) {
  4083. return String.fromCharCode(value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff);
  4084. }
  4085. function log2(x) {
  4086. var n = 1, i = 0;
  4087. while (x > n) {
  4088. n <<= 1;
  4089. i++;
  4090. }
  4091. return i;
  4092. }
  4093. function readInt8(data, start) {
  4094. return data[start] << 24 >> 24;
  4095. }
  4096. function readUint16(data, offset) {
  4097. return data[offset] << 8 | data[offset + 1];
  4098. }
  4099. function readUint32(data, offset) {
  4100. return (data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3]) >>> 0;
  4101. }
  4102. // Lazy test the endianness of the platform
  4103. // NOTE: This will be 'true' for simulated TypedArrays
  4104. function isLittleEndian() {
  4105. var buffer8 = new Uint8Array(2);
  4106. buffer8[0] = 1;
  4107. var buffer16 = new Uint16Array(buffer8.buffer);
  4108. return buffer16[0] === 1;
  4109. }
  4110. // Checks if it's possible to eval JS expressions.
  4111. function isEvalSupported() {
  4112. try {
  4113. new Function('');
  4114. return true;
  4115. } catch (e) {
  4116. return false;
  4117. }
  4118. }
  4119. var Uint32ArrayView = function Uint32ArrayViewClosure() {
  4120. function Uint32ArrayView(buffer, length) {
  4121. this.buffer = buffer;
  4122. this.byteLength = buffer.length;
  4123. this.length = length === undefined ? this.byteLength >> 2 : length;
  4124. ensureUint32ArrayViewProps(this.length);
  4125. }
  4126. Uint32ArrayView.prototype = Object.create(null);
  4127. var uint32ArrayViewSetters = 0;
  4128. function createUint32ArrayProp(index) {
  4129. return {
  4130. get: function () {
  4131. var buffer = this.buffer, offset = index << 2;
  4132. return (buffer[offset] | buffer[offset + 1] << 8 | buffer[offset + 2] << 16 | buffer[offset + 3] << 24) >>> 0;
  4133. },
  4134. set: function (value) {
  4135. var buffer = this.buffer, offset = index << 2;
  4136. buffer[offset] = value & 255;
  4137. buffer[offset + 1] = value >> 8 & 255;
  4138. buffer[offset + 2] = value >> 16 & 255;
  4139. buffer[offset + 3] = value >>> 24 & 255;
  4140. }
  4141. };
  4142. }
  4143. function ensureUint32ArrayViewProps(length) {
  4144. while (uint32ArrayViewSetters < length) {
  4145. Object.defineProperty(Uint32ArrayView.prototype, uint32ArrayViewSetters, createUint32ArrayProp(uint32ArrayViewSetters));
  4146. uint32ArrayViewSetters++;
  4147. }
  4148. }
  4149. return Uint32ArrayView;
  4150. }();
  4151. exports.Uint32ArrayView = Uint32ArrayView;
  4152. var IDENTITY_MATRIX = [
  4153. 1,
  4154. 0,
  4155. 0,
  4156. 1,
  4157. 0,
  4158. 0
  4159. ];
  4160. var Util = function UtilClosure() {
  4161. function Util() {
  4162. }
  4163. var rgbBuf = [
  4164. 'rgb(',
  4165. 0,
  4166. ',',
  4167. 0,
  4168. ',',
  4169. 0,
  4170. ')'
  4171. ];
  4172. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  4173. // creating many intermediate strings.
  4174. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  4175. rgbBuf[1] = r;
  4176. rgbBuf[3] = g;
  4177. rgbBuf[5] = b;
  4178. return rgbBuf.join('');
  4179. };
  4180. // Concatenates two transformation matrices together and returns the result.
  4181. Util.transform = function Util_transform(m1, m2) {
  4182. return [
  4183. m1[0] * m2[0] + m1[2] * m2[1],
  4184. m1[1] * m2[0] + m1[3] * m2[1],
  4185. m1[0] * m2[2] + m1[2] * m2[3],
  4186. m1[1] * m2[2] + m1[3] * m2[3],
  4187. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  4188. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  4189. ];
  4190. };
  4191. // For 2d affine transforms
  4192. Util.applyTransform = function Util_applyTransform(p, m) {
  4193. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  4194. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  4195. return [
  4196. xt,
  4197. yt
  4198. ];
  4199. };
  4200. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  4201. var d = m[0] * m[3] - m[1] * m[2];
  4202. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  4203. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  4204. return [
  4205. xt,
  4206. yt
  4207. ];
  4208. };
  4209. // Applies the transform to the rectangle and finds the minimum axially
  4210. // aligned bounding box.
  4211. Util.getAxialAlignedBoundingBox = function Util_getAxialAlignedBoundingBox(r, m) {
  4212. var p1 = Util.applyTransform(r, m);
  4213. var p2 = Util.applyTransform(r.slice(2, 4), m);
  4214. var p3 = Util.applyTransform([
  4215. r[0],
  4216. r[3]
  4217. ], m);
  4218. var p4 = Util.applyTransform([
  4219. r[2],
  4220. r[1]
  4221. ], m);
  4222. return [
  4223. Math.min(p1[0], p2[0], p3[0], p4[0]),
  4224. Math.min(p1[1], p2[1], p3[1], p4[1]),
  4225. Math.max(p1[0], p2[0], p3[0], p4[0]),
  4226. Math.max(p1[1], p2[1], p3[1], p4[1])
  4227. ];
  4228. };
  4229. Util.inverseTransform = function Util_inverseTransform(m) {
  4230. var d = m[0] * m[3] - m[1] * m[2];
  4231. return [
  4232. m[3] / d,
  4233. -m[1] / d,
  4234. -m[2] / d,
  4235. m[0] / d,
  4236. (m[2] * m[5] - m[4] * m[3]) / d,
  4237. (m[4] * m[1] - m[5] * m[0]) / d
  4238. ];
  4239. };
  4240. // Apply a generic 3d matrix M on a 3-vector v:
  4241. // | a b c | | X |
  4242. // | d e f | x | Y |
  4243. // | g h i | | Z |
  4244. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  4245. // with v as [X,Y,Z]
  4246. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  4247. return [
  4248. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  4249. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  4250. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  4251. ];
  4252. };
  4253. // This calculation uses Singular Value Decomposition.
  4254. // The SVD can be represented with formula A = USV. We are interested in the
  4255. // matrix S here because it represents the scale values.
  4256. Util.singularValueDecompose2dScale = function Util_singularValueDecompose2dScale(m) {
  4257. var transpose = [
  4258. m[0],
  4259. m[2],
  4260. m[1],
  4261. m[3]
  4262. ];
  4263. // Multiply matrix m with its transpose.
  4264. var a = m[0] * transpose[0] + m[1] * transpose[2];
  4265. var b = m[0] * transpose[1] + m[1] * transpose[3];
  4266. var c = m[2] * transpose[0] + m[3] * transpose[2];
  4267. var d = m[2] * transpose[1] + m[3] * transpose[3];
  4268. // Solve the second degree polynomial to get roots.
  4269. var first = (a + d) / 2;
  4270. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  4271. var sx = first + second || 1;
  4272. var sy = first - second || 1;
  4273. // Scale values are the square roots of the eigenvalues.
  4274. return [
  4275. Math.sqrt(sx),
  4276. Math.sqrt(sy)
  4277. ];
  4278. };
  4279. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  4280. // For coordinate systems whose origin lies in the bottom-left, this
  4281. // means normalization to (BL,TR) ordering. For systems with origin in the
  4282. // top-left, this means (TL,BR) ordering.
  4283. Util.normalizeRect = function Util_normalizeRect(rect) {
  4284. var r = rect.slice(0);
  4285. // clone rect
  4286. if (rect[0] > rect[2]) {
  4287. r[0] = rect[2];
  4288. r[2] = rect[0];
  4289. }
  4290. if (rect[1] > rect[3]) {
  4291. r[1] = rect[3];
  4292. r[3] = rect[1];
  4293. }
  4294. return r;
  4295. };
  4296. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  4297. // intersection of rect1 and rect2. If no intersection, returns 'false'
  4298. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  4299. Util.intersect = function Util_intersect(rect1, rect2) {
  4300. function compare(a, b) {
  4301. return a - b;
  4302. }
  4303. // Order points along the axes
  4304. var orderedX = [
  4305. rect1[0],
  4306. rect1[2],
  4307. rect2[0],
  4308. rect2[2]
  4309. ].sort(compare), orderedY = [
  4310. rect1[1],
  4311. rect1[3],
  4312. rect2[1],
  4313. rect2[3]
  4314. ].sort(compare), result = [];
  4315. rect1 = Util.normalizeRect(rect1);
  4316. rect2 = Util.normalizeRect(rect2);
  4317. // X: first and second points belong to different rectangles?
  4318. if (orderedX[0] === rect1[0] && orderedX[1] === rect2[0] || orderedX[0] === rect2[0] && orderedX[1] === rect1[0]) {
  4319. // Intersection must be between second and third points
  4320. result[0] = orderedX[1];
  4321. result[2] = orderedX[2];
  4322. } else {
  4323. return false;
  4324. }
  4325. // Y: first and second points belong to different rectangles?
  4326. if (orderedY[0] === rect1[1] && orderedY[1] === rect2[1] || orderedY[0] === rect2[1] && orderedY[1] === rect1[1]) {
  4327. // Intersection must be between second and third points
  4328. result[1] = orderedY[1];
  4329. result[3] = orderedY[2];
  4330. } else {
  4331. return false;
  4332. }
  4333. return result;
  4334. };
  4335. Util.sign = function Util_sign(num) {
  4336. return num < 0 ? -1 : 1;
  4337. };
  4338. var ROMAN_NUMBER_MAP = [
  4339. '',
  4340. 'C',
  4341. 'CC',
  4342. 'CCC',
  4343. 'CD',
  4344. 'D',
  4345. 'DC',
  4346. 'DCC',
  4347. 'DCCC',
  4348. 'CM',
  4349. '',
  4350. 'X',
  4351. 'XX',
  4352. 'XXX',
  4353. 'XL',
  4354. 'L',
  4355. 'LX',
  4356. 'LXX',
  4357. 'LXXX',
  4358. 'XC',
  4359. '',
  4360. 'I',
  4361. 'II',
  4362. 'III',
  4363. 'IV',
  4364. 'V',
  4365. 'VI',
  4366. 'VII',
  4367. 'VIII',
  4368. 'IX'
  4369. ];
  4370. /**
  4371. * Converts positive integers to (upper case) Roman numerals.
  4372. * @param {integer} number - The number that should be converted.
  4373. * @param {boolean} lowerCase - Indicates if the result should be converted
  4374. * to lower case letters. The default is false.
  4375. * @return {string} The resulting Roman number.
  4376. */
  4377. Util.toRoman = function Util_toRoman(number, lowerCase) {
  4378. assert(isInt(number) && number > 0, 'The number should be a positive integer.');
  4379. var pos, romanBuf = [];
  4380. // Thousands
  4381. while (number >= 1000) {
  4382. number -= 1000;
  4383. romanBuf.push('M');
  4384. }
  4385. // Hundreds
  4386. pos = number / 100 | 0;
  4387. number %= 100;
  4388. romanBuf.push(ROMAN_NUMBER_MAP[pos]);
  4389. // Tens
  4390. pos = number / 10 | 0;
  4391. number %= 10;
  4392. romanBuf.push(ROMAN_NUMBER_MAP[10 + pos]);
  4393. // Ones
  4394. romanBuf.push(ROMAN_NUMBER_MAP[20 + number]);
  4395. var romanStr = romanBuf.join('');
  4396. return lowerCase ? romanStr.toLowerCase() : romanStr;
  4397. };
  4398. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  4399. Array.prototype.push.apply(arr1, arr2);
  4400. };
  4401. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  4402. Array.prototype.unshift.apply(arr1, arr2);
  4403. };
  4404. Util.extendObj = function extendObj(obj1, obj2) {
  4405. for (var key in obj2) {
  4406. obj1[key] = obj2[key];
  4407. }
  4408. };
  4409. Util.getInheritableProperty = function Util_getInheritableProperty(dict, name, getArray) {
  4410. while (dict && !dict.has(name)) {
  4411. dict = dict.get('Parent');
  4412. }
  4413. if (!dict) {
  4414. return null;
  4415. }
  4416. return getArray ? dict.getArray(name) : dict.get(name);
  4417. };
  4418. Util.inherit = function Util_inherit(sub, base, prototype) {
  4419. sub.prototype = Object.create(base.prototype);
  4420. sub.prototype.constructor = sub;
  4421. for (var prop in prototype) {
  4422. sub.prototype[prop] = prototype[prop];
  4423. }
  4424. };
  4425. Util.loadScript = function Util_loadScript(src, callback) {
  4426. var script = document.createElement('script');
  4427. var loaded = false;
  4428. script.setAttribute('src', src);
  4429. if (callback) {
  4430. script.onload = function () {
  4431. if (!loaded) {
  4432. callback();
  4433. }
  4434. loaded = true;
  4435. };
  4436. }
  4437. document.getElementsByTagName('head')[0].appendChild(script);
  4438. };
  4439. return Util;
  4440. }();
  4441. /**
  4442. * PDF page viewport created based on scale, rotation and offset.
  4443. * @class
  4444. * @alias PageViewport
  4445. */
  4446. var PageViewport = function PageViewportClosure() {
  4447. /**
  4448. * @constructor
  4449. * @private
  4450. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  4451. * @param scale {number} scale of the viewport.
  4452. * @param rotation {number} rotations of the viewport in degrees.
  4453. * @param offsetX {number} offset X
  4454. * @param offsetY {number} offset Y
  4455. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  4456. */
  4457. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  4458. this.viewBox = viewBox;
  4459. this.scale = scale;
  4460. this.rotation = rotation;
  4461. this.offsetX = offsetX;
  4462. this.offsetY = offsetY;
  4463. // creating transform to convert pdf coordinate system to the normal
  4464. // canvas like coordinates taking in account scale and rotation
  4465. var centerX = (viewBox[2] + viewBox[0]) / 2;
  4466. var centerY = (viewBox[3] + viewBox[1]) / 2;
  4467. var rotateA, rotateB, rotateC, rotateD;
  4468. rotation = rotation % 360;
  4469. rotation = rotation < 0 ? rotation + 360 : rotation;
  4470. switch (rotation) {
  4471. case 180:
  4472. rotateA = -1;
  4473. rotateB = 0;
  4474. rotateC = 0;
  4475. rotateD = 1;
  4476. break;
  4477. case 90:
  4478. rotateA = 0;
  4479. rotateB = 1;
  4480. rotateC = 1;
  4481. rotateD = 0;
  4482. break;
  4483. case 270:
  4484. rotateA = 0;
  4485. rotateB = -1;
  4486. rotateC = -1;
  4487. rotateD = 0;
  4488. break;
  4489. //case 0:
  4490. default:
  4491. rotateA = 1;
  4492. rotateB = 0;
  4493. rotateC = 0;
  4494. rotateD = -1;
  4495. break;
  4496. }
  4497. if (dontFlip) {
  4498. rotateC = -rotateC;
  4499. rotateD = -rotateD;
  4500. }
  4501. var offsetCanvasX, offsetCanvasY;
  4502. var width, height;
  4503. if (rotateA === 0) {
  4504. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  4505. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  4506. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  4507. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  4508. } else {
  4509. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  4510. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  4511. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  4512. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  4513. }
  4514. // creating transform for the following operations:
  4515. // translate(-centerX, -centerY), rotate and flip vertically,
  4516. // scale, and translate(offsetCanvasX, offsetCanvasY)
  4517. this.transform = [
  4518. rotateA * scale,
  4519. rotateB * scale,
  4520. rotateC * scale,
  4521. rotateD * scale,
  4522. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  4523. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  4524. ];
  4525. this.width = width;
  4526. this.height = height;
  4527. this.fontScale = scale;
  4528. }
  4529. PageViewport.prototype = /** @lends PageViewport.prototype */
  4530. {
  4531. /**
  4532. * Clones viewport with additional properties.
  4533. * @param args {Object} (optional) If specified, may contain the 'scale' or
  4534. * 'rotation' properties to override the corresponding properties in
  4535. * the cloned viewport.
  4536. * @returns {PageViewport} Cloned viewport.
  4537. */
  4538. clone: function PageViewPort_clone(args) {
  4539. args = args || {};
  4540. var scale = 'scale' in args ? args.scale : this.scale;
  4541. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  4542. return new PageViewport(this.viewBox.slice(), scale, rotation, this.offsetX, this.offsetY, args.dontFlip);
  4543. },
  4544. /**
  4545. * Converts PDF point to the viewport coordinates. For examples, useful for
  4546. * converting PDF location into canvas pixel coordinates.
  4547. * @param x {number} X coordinate.
  4548. * @param y {number} Y coordinate.
  4549. * @returns {Object} Object that contains 'x' and 'y' properties of the
  4550. * point in the viewport coordinate space.
  4551. * @see {@link convertToPdfPoint}
  4552. * @see {@link convertToViewportRectangle}
  4553. */
  4554. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  4555. return Util.applyTransform([
  4556. x,
  4557. y
  4558. ], this.transform);
  4559. },
  4560. /**
  4561. * Converts PDF rectangle to the viewport coordinates.
  4562. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  4563. * @returns {Array} Contains corresponding coordinates of the rectangle
  4564. * in the viewport coordinate space.
  4565. * @see {@link convertToViewportPoint}
  4566. */
  4567. convertToViewportRectangle: function PageViewport_convertToViewportRectangle(rect) {
  4568. var tl = Util.applyTransform([
  4569. rect[0],
  4570. rect[1]
  4571. ], this.transform);
  4572. var br = Util.applyTransform([
  4573. rect[2],
  4574. rect[3]
  4575. ], this.transform);
  4576. return [
  4577. tl[0],
  4578. tl[1],
  4579. br[0],
  4580. br[1]
  4581. ];
  4582. },
  4583. /**
  4584. * Converts viewport coordinates to the PDF location. For examples, useful
  4585. * for converting canvas pixel location into PDF one.
  4586. * @param x {number} X coordinate.
  4587. * @param y {number} Y coordinate.
  4588. * @returns {Object} Object that contains 'x' and 'y' properties of the
  4589. * point in the PDF coordinate space.
  4590. * @see {@link convertToViewportPoint}
  4591. */
  4592. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  4593. return Util.applyInverseTransform([
  4594. x,
  4595. y
  4596. ], this.transform);
  4597. }
  4598. };
  4599. return PageViewport;
  4600. }();
  4601. var PDFStringTranslateTable = [
  4602. 0,
  4603. 0,
  4604. 0,
  4605. 0,
  4606. 0,
  4607. 0,
  4608. 0,
  4609. 0,
  4610. 0,
  4611. 0,
  4612. 0,
  4613. 0,
  4614. 0,
  4615. 0,
  4616. 0,
  4617. 0,
  4618. 0,
  4619. 0,
  4620. 0,
  4621. 0,
  4622. 0,
  4623. 0,
  4624. 0,
  4625. 0,
  4626. 0x2D8,
  4627. 0x2C7,
  4628. 0x2C6,
  4629. 0x2D9,
  4630. 0x2DD,
  4631. 0x2DB,
  4632. 0x2DA,
  4633. 0x2DC,
  4634. 0,
  4635. 0,
  4636. 0,
  4637. 0,
  4638. 0,
  4639. 0,
  4640. 0,
  4641. 0,
  4642. 0,
  4643. 0,
  4644. 0,
  4645. 0,
  4646. 0,
  4647. 0,
  4648. 0,
  4649. 0,
  4650. 0,
  4651. 0,
  4652. 0,
  4653. 0,
  4654. 0,
  4655. 0,
  4656. 0,
  4657. 0,
  4658. 0,
  4659. 0,
  4660. 0,
  4661. 0,
  4662. 0,
  4663. 0,
  4664. 0,
  4665. 0,
  4666. 0,
  4667. 0,
  4668. 0,
  4669. 0,
  4670. 0,
  4671. 0,
  4672. 0,
  4673. 0,
  4674. 0,
  4675. 0,
  4676. 0,
  4677. 0,
  4678. 0,
  4679. 0,
  4680. 0,
  4681. 0,
  4682. 0,
  4683. 0,
  4684. 0,
  4685. 0,
  4686. 0,
  4687. 0,
  4688. 0,
  4689. 0,
  4690. 0,
  4691. 0,
  4692. 0,
  4693. 0,
  4694. 0,
  4695. 0,
  4696. 0,
  4697. 0,
  4698. 0,
  4699. 0,
  4700. 0,
  4701. 0,
  4702. 0,
  4703. 0,
  4704. 0,
  4705. 0,
  4706. 0,
  4707. 0,
  4708. 0,
  4709. 0,
  4710. 0,
  4711. 0,
  4712. 0,
  4713. 0,
  4714. 0,
  4715. 0,
  4716. 0,
  4717. 0,
  4718. 0,
  4719. 0,
  4720. 0,
  4721. 0,
  4722. 0,
  4723. 0,
  4724. 0,
  4725. 0,
  4726. 0,
  4727. 0,
  4728. 0,
  4729. 0,
  4730. 0x2022,
  4731. 0x2020,
  4732. 0x2021,
  4733. 0x2026,
  4734. 0x2014,
  4735. 0x2013,
  4736. 0x192,
  4737. 0x2044,
  4738. 0x2039,
  4739. 0x203A,
  4740. 0x2212,
  4741. 0x2030,
  4742. 0x201E,
  4743. 0x201C,
  4744. 0x201D,
  4745. 0x2018,
  4746. 0x2019,
  4747. 0x201A,
  4748. 0x2122,
  4749. 0xFB01,
  4750. 0xFB02,
  4751. 0x141,
  4752. 0x152,
  4753. 0x160,
  4754. 0x178,
  4755. 0x17D,
  4756. 0x131,
  4757. 0x142,
  4758. 0x153,
  4759. 0x161,
  4760. 0x17E,
  4761. 0,
  4762. 0x20AC
  4763. ];
  4764. function stringToPDFString(str) {
  4765. var i, n = str.length, strBuf = [];
  4766. if (str[0] === '\xFE' && str[1] === '\xFF') {
  4767. // UTF16BE BOM
  4768. for (i = 2; i < n; i += 2) {
  4769. strBuf.push(String.fromCharCode(str.charCodeAt(i) << 8 | str.charCodeAt(i + 1)));
  4770. }
  4771. } else {
  4772. for (i = 0; i < n; ++i) {
  4773. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  4774. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  4775. }
  4776. }
  4777. return strBuf.join('');
  4778. }
  4779. function stringToUTF8String(str) {
  4780. return decodeURIComponent(escape(str));
  4781. }
  4782. function utf8StringToString(str) {
  4783. return unescape(encodeURIComponent(str));
  4784. }
  4785. function isEmptyObj(obj) {
  4786. for (var key in obj) {
  4787. return false;
  4788. }
  4789. return true;
  4790. }
  4791. function isBool(v) {
  4792. return typeof v === 'boolean';
  4793. }
  4794. function isInt(v) {
  4795. return typeof v === 'number' && (v | 0) === v;
  4796. }
  4797. function isNum(v) {
  4798. return typeof v === 'number';
  4799. }
  4800. function isString(v) {
  4801. return typeof v === 'string';
  4802. }
  4803. function isArray(v) {
  4804. return v instanceof Array;
  4805. }
  4806. function isArrayBuffer(v) {
  4807. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  4808. }
  4809. // Checks if ch is one of the following characters: SPACE, TAB, CR or LF.
  4810. function isSpace(ch) {
  4811. return ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A;
  4812. }
  4813. /**
  4814. * Promise Capability object.
  4815. *
  4816. * @typedef {Object} PromiseCapability
  4817. * @property {Promise} promise - A promise object.
  4818. * @property {function} resolve - Fulfills the promise.
  4819. * @property {function} reject - Rejects the promise.
  4820. */
  4821. /**
  4822. * Creates a promise capability object.
  4823. * @alias createPromiseCapability
  4824. *
  4825. * @return {PromiseCapability} A capability object contains:
  4826. * - a Promise, resolve and reject methods.
  4827. */
  4828. function createPromiseCapability() {
  4829. var capability = {};
  4830. capability.promise = new Promise(function (resolve, reject) {
  4831. capability.resolve = resolve;
  4832. capability.reject = reject;
  4833. });
  4834. return capability;
  4835. }
  4836. /**
  4837. * Polyfill for Promises:
  4838. * The following promise implementation tries to generally implement the
  4839. * Promise/A+ spec. Some notable differences from other promise libraries are:
  4840. * - There currently isn't a separate deferred and promise object.
  4841. * - Unhandled rejections eventually show an error if they aren't handled.
  4842. *
  4843. * Based off of the work in:
  4844. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  4845. */
  4846. (function PromiseClosure() {
  4847. if (globalScope.Promise) {
  4848. // Promises existing in the DOM/Worker, checking presence of all/resolve
  4849. if (typeof globalScope.Promise.all !== 'function') {
  4850. globalScope.Promise.all = function (iterable) {
  4851. var count = 0, results = [], resolve, reject;
  4852. var promise = new globalScope.Promise(function (resolve_, reject_) {
  4853. resolve = resolve_;
  4854. reject = reject_;
  4855. });
  4856. iterable.forEach(function (p, i) {
  4857. count++;
  4858. p.then(function (result) {
  4859. results[i] = result;
  4860. count--;
  4861. if (count === 0) {
  4862. resolve(results);
  4863. }
  4864. }, reject);
  4865. });
  4866. if (count === 0) {
  4867. resolve(results);
  4868. }
  4869. return promise;
  4870. };
  4871. }
  4872. if (typeof globalScope.Promise.resolve !== 'function') {
  4873. globalScope.Promise.resolve = function (value) {
  4874. return new globalScope.Promise(function (resolve) {
  4875. resolve(value);
  4876. });
  4877. };
  4878. }
  4879. if (typeof globalScope.Promise.reject !== 'function') {
  4880. globalScope.Promise.reject = function (reason) {
  4881. return new globalScope.Promise(function (resolve, reject) {
  4882. reject(reason);
  4883. });
  4884. };
  4885. }
  4886. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  4887. globalScope.Promise.prototype.catch = function (onReject) {
  4888. return globalScope.Promise.prototype.then(undefined, onReject);
  4889. };
  4890. }
  4891. return;
  4892. }
  4893. var STATUS_PENDING = 0;
  4894. var STATUS_RESOLVED = 1;
  4895. var STATUS_REJECTED = 2;
  4896. // In an attempt to avoid silent exceptions, unhandled rejections are
  4897. // tracked and if they aren't handled in a certain amount of time an
  4898. // error is logged.
  4899. var REJECTION_TIMEOUT = 500;
  4900. var HandlerManager = {
  4901. handlers: [],
  4902. running: false,
  4903. unhandledRejections: [],
  4904. pendingRejectionCheck: false,
  4905. scheduleHandlers: function scheduleHandlers(promise) {
  4906. if (promise._status === STATUS_PENDING) {
  4907. return;
  4908. }
  4909. this.handlers = this.handlers.concat(promise._handlers);
  4910. promise._handlers = [];
  4911. if (this.running) {
  4912. return;
  4913. }
  4914. this.running = true;
  4915. setTimeout(this.runHandlers.bind(this), 0);
  4916. },
  4917. runHandlers: function runHandlers() {
  4918. var RUN_TIMEOUT = 1;
  4919. // ms
  4920. var timeoutAt = Date.now() + RUN_TIMEOUT;
  4921. while (this.handlers.length > 0) {
  4922. var handler = this.handlers.shift();
  4923. var nextStatus = handler.thisPromise._status;
  4924. var nextValue = handler.thisPromise._value;
  4925. try {
  4926. if (nextStatus === STATUS_RESOLVED) {
  4927. if (typeof handler.onResolve === 'function') {
  4928. nextValue = handler.onResolve(nextValue);
  4929. }
  4930. } else if (typeof handler.onReject === 'function') {
  4931. nextValue = handler.onReject(nextValue);
  4932. nextStatus = STATUS_RESOLVED;
  4933. if (handler.thisPromise._unhandledRejection) {
  4934. this.removeUnhandeledRejection(handler.thisPromise);
  4935. }
  4936. }
  4937. } catch (ex) {
  4938. nextStatus = STATUS_REJECTED;
  4939. nextValue = ex;
  4940. }
  4941. handler.nextPromise._updateStatus(nextStatus, nextValue);
  4942. if (Date.now() >= timeoutAt) {
  4943. break;
  4944. }
  4945. }
  4946. if (this.handlers.length > 0) {
  4947. setTimeout(this.runHandlers.bind(this), 0);
  4948. return;
  4949. }
  4950. this.running = false;
  4951. },
  4952. addUnhandledRejection: function addUnhandledRejection(promise) {
  4953. this.unhandledRejections.push({
  4954. promise: promise,
  4955. time: Date.now()
  4956. });
  4957. this.scheduleRejectionCheck();
  4958. },
  4959. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  4960. promise._unhandledRejection = false;
  4961. for (var i = 0; i < this.unhandledRejections.length; i++) {
  4962. if (this.unhandledRejections[i].promise === promise) {
  4963. this.unhandledRejections.splice(i);
  4964. i--;
  4965. }
  4966. }
  4967. },
  4968. scheduleRejectionCheck: function scheduleRejectionCheck() {
  4969. if (this.pendingRejectionCheck) {
  4970. return;
  4971. }
  4972. this.pendingRejectionCheck = true;
  4973. setTimeout(function rejectionCheck() {
  4974. this.pendingRejectionCheck = false;
  4975. var now = Date.now();
  4976. for (var i = 0; i < this.unhandledRejections.length; i++) {
  4977. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  4978. var unhandled = this.unhandledRejections[i].promise._value;
  4979. var msg = 'Unhandled rejection: ' + unhandled;
  4980. if (unhandled.stack) {
  4981. msg += '\n' + unhandled.stack;
  4982. }
  4983. warn(msg);
  4984. this.unhandledRejections.splice(i);
  4985. i--;
  4986. }
  4987. }
  4988. if (this.unhandledRejections.length) {
  4989. this.scheduleRejectionCheck();
  4990. }
  4991. }.bind(this), REJECTION_TIMEOUT);
  4992. }
  4993. };
  4994. var Promise = function Promise(resolver) {
  4995. this._status = STATUS_PENDING;
  4996. this._handlers = [];
  4997. try {
  4998. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  4999. } catch (e) {
  5000. this._reject(e);
  5001. }
  5002. };
  5003. /**
  5004. * Builds a promise that is resolved when all the passed in promises are
  5005. * resolved.
  5006. * @param {array} promises array of data and/or promises to wait for.
  5007. * @return {Promise} New dependent promise.
  5008. */
  5009. Promise.all = function Promise_all(promises) {
  5010. var resolveAll, rejectAll;
  5011. var deferred = new Promise(function (resolve, reject) {
  5012. resolveAll = resolve;
  5013. rejectAll = reject;
  5014. });
  5015. var unresolved = promises.length;
  5016. var results = [];
  5017. if (unresolved === 0) {
  5018. resolveAll(results);
  5019. return deferred;
  5020. }
  5021. function reject(reason) {
  5022. if (deferred._status === STATUS_REJECTED) {
  5023. return;
  5024. }
  5025. results = [];
  5026. rejectAll(reason);
  5027. }
  5028. for (var i = 0, ii = promises.length; i < ii; ++i) {
  5029. var promise = promises[i];
  5030. var resolve = function (i) {
  5031. return function (value) {
  5032. if (deferred._status === STATUS_REJECTED) {
  5033. return;
  5034. }
  5035. results[i] = value;
  5036. unresolved--;
  5037. if (unresolved === 0) {
  5038. resolveAll(results);
  5039. }
  5040. };
  5041. }(i);
  5042. if (Promise.isPromise(promise)) {
  5043. promise.then(resolve, reject);
  5044. } else {
  5045. resolve(promise);
  5046. }
  5047. }
  5048. return deferred;
  5049. };
  5050. /**
  5051. * Checks if the value is likely a promise (has a 'then' function).
  5052. * @return {boolean} true if value is thenable
  5053. */
  5054. Promise.isPromise = function Promise_isPromise(value) {
  5055. return value && typeof value.then === 'function';
  5056. };
  5057. /**
  5058. * Creates resolved promise
  5059. * @param value resolve value
  5060. * @returns {Promise}
  5061. */
  5062. Promise.resolve = function Promise_resolve(value) {
  5063. return new Promise(function (resolve) {
  5064. resolve(value);
  5065. });
  5066. };
  5067. /**
  5068. * Creates rejected promise
  5069. * @param reason rejection value
  5070. * @returns {Promise}
  5071. */
  5072. Promise.reject = function Promise_reject(reason) {
  5073. return new Promise(function (resolve, reject) {
  5074. reject(reason);
  5075. });
  5076. };
  5077. Promise.prototype = {
  5078. _status: null,
  5079. _value: null,
  5080. _handlers: null,
  5081. _unhandledRejection: null,
  5082. _updateStatus: function Promise__updateStatus(status, value) {
  5083. if (this._status === STATUS_RESOLVED || this._status === STATUS_REJECTED) {
  5084. return;
  5085. }
  5086. if (status === STATUS_RESOLVED && Promise.isPromise(value)) {
  5087. value.then(this._updateStatus.bind(this, STATUS_RESOLVED), this._updateStatus.bind(this, STATUS_REJECTED));
  5088. return;
  5089. }
  5090. this._status = status;
  5091. this._value = value;
  5092. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  5093. this._unhandledRejection = true;
  5094. HandlerManager.addUnhandledRejection(this);
  5095. }
  5096. HandlerManager.scheduleHandlers(this);
  5097. },
  5098. _resolve: function Promise_resolve(value) {
  5099. this._updateStatus(STATUS_RESOLVED, value);
  5100. },
  5101. _reject: function Promise_reject(reason) {
  5102. this._updateStatus(STATUS_REJECTED, reason);
  5103. },
  5104. then: function Promise_then(onResolve, onReject) {
  5105. var nextPromise = new Promise(function (resolve, reject) {
  5106. this.resolve = resolve;
  5107. this.reject = reject;
  5108. });
  5109. this._handlers.push({
  5110. thisPromise: this,
  5111. onResolve: onResolve,
  5112. onReject: onReject,
  5113. nextPromise: nextPromise
  5114. });
  5115. HandlerManager.scheduleHandlers(this);
  5116. return nextPromise;
  5117. },
  5118. catch: function Promise_catch(onReject) {
  5119. return this.then(undefined, onReject);
  5120. }
  5121. };
  5122. globalScope.Promise = Promise;
  5123. }());
  5124. (function WeakMapClosure() {
  5125. if (globalScope.WeakMap) {
  5126. return;
  5127. }
  5128. var id = 0;
  5129. function WeakMap() {
  5130. this.id = '$weakmap' + id++;
  5131. }
  5132. WeakMap.prototype = {
  5133. has: function (obj) {
  5134. return !!Object.getOwnPropertyDescriptor(obj, this.id);
  5135. },
  5136. get: function (obj, defaultValue) {
  5137. return this.has(obj) ? obj[this.id] : defaultValue;
  5138. },
  5139. set: function (obj, value) {
  5140. Object.defineProperty(obj, this.id, {
  5141. value: value,
  5142. enumerable: false,
  5143. configurable: true
  5144. });
  5145. },
  5146. delete: function (obj) {
  5147. delete obj[this.id];
  5148. }
  5149. };
  5150. globalScope.WeakMap = WeakMap;
  5151. }());
  5152. var StatTimer = function StatTimerClosure() {
  5153. function rpad(str, pad, length) {
  5154. while (str.length < length) {
  5155. str += pad;
  5156. }
  5157. return str;
  5158. }
  5159. function StatTimer() {
  5160. this.started = Object.create(null);
  5161. this.times = [];
  5162. this.enabled = true;
  5163. }
  5164. StatTimer.prototype = {
  5165. time: function StatTimer_time(name) {
  5166. if (!this.enabled) {
  5167. return;
  5168. }
  5169. if (name in this.started) {
  5170. warn('Timer is already running for ' + name);
  5171. }
  5172. this.started[name] = Date.now();
  5173. },
  5174. timeEnd: function StatTimer_timeEnd(name) {
  5175. if (!this.enabled) {
  5176. return;
  5177. }
  5178. if (!(name in this.started)) {
  5179. warn('Timer has not been started for ' + name);
  5180. }
  5181. this.times.push({
  5182. 'name': name,
  5183. 'start': this.started[name],
  5184. 'end': Date.now()
  5185. });
  5186. // Remove timer from started so it can be called again.
  5187. delete this.started[name];
  5188. },
  5189. toString: function StatTimer_toString() {
  5190. var i, ii;
  5191. var times = this.times;
  5192. var out = '';
  5193. // Find the longest name for padding purposes.
  5194. var longest = 0;
  5195. for (i = 0, ii = times.length; i < ii; ++i) {
  5196. var name = times[i]['name'];
  5197. if (name.length > longest) {
  5198. longest = name.length;
  5199. }
  5200. }
  5201. for (i = 0, ii = times.length; i < ii; ++i) {
  5202. var span = times[i];
  5203. var duration = span.end - span.start;
  5204. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  5205. }
  5206. return out;
  5207. }
  5208. };
  5209. return StatTimer;
  5210. }();
  5211. var createBlob = function createBlob(data, contentType) {
  5212. if (typeof Blob !== 'undefined') {
  5213. return new Blob([data], { type: contentType });
  5214. }
  5215. warn('The "Blob" constructor is not supported.');
  5216. };
  5217. var createObjectURL = function createObjectURLClosure() {
  5218. // Blob/createObjectURL is not available, falling back to data schema.
  5219. var digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  5220. return function createObjectURL(data, contentType, forceDataSchema) {
  5221. if (!forceDataSchema && typeof URL !== 'undefined' && URL.createObjectURL) {
  5222. var blob = createBlob(data, contentType);
  5223. return URL.createObjectURL(blob);
  5224. }
  5225. var buffer = 'data:' + contentType + ';base64,';
  5226. for (var i = 0, ii = data.length; i < ii; i += 3) {
  5227. var b1 = data[i] & 0xFF;
  5228. var b2 = data[i + 1] & 0xFF;
  5229. var b3 = data[i + 2] & 0xFF;
  5230. var d1 = b1 >> 2, d2 = (b1 & 3) << 4 | b2 >> 4;
  5231. var d3 = i + 1 < ii ? (b2 & 0xF) << 2 | b3 >> 6 : 64;
  5232. var d4 = i + 2 < ii ? b3 & 0x3F : 64;
  5233. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  5234. }
  5235. return buffer;
  5236. };
  5237. }();
  5238. function MessageHandler(sourceName, targetName, comObj) {
  5239. this.sourceName = sourceName;
  5240. this.targetName = targetName;
  5241. this.comObj = comObj;
  5242. this.callbackIndex = 1;
  5243. this.postMessageTransfers = true;
  5244. var callbacksCapabilities = this.callbacksCapabilities = Object.create(null);
  5245. var ah = this.actionHandler = Object.create(null);
  5246. this._onComObjOnMessage = function messageHandlerComObjOnMessage(event) {
  5247. var data = event.data;
  5248. if (data.targetName !== this.sourceName) {
  5249. return;
  5250. }
  5251. if (data.isReply) {
  5252. var callbackId = data.callbackId;
  5253. if (data.callbackId in callbacksCapabilities) {
  5254. var callback = callbacksCapabilities[callbackId];
  5255. delete callbacksCapabilities[callbackId];
  5256. if ('error' in data) {
  5257. callback.reject(data.error);
  5258. } else {
  5259. callback.resolve(data.data);
  5260. }
  5261. } else {
  5262. error('Cannot resolve callback ' + callbackId);
  5263. }
  5264. } else if (data.action in ah) {
  5265. var action = ah[data.action];
  5266. if (data.callbackId) {
  5267. var sourceName = this.sourceName;
  5268. var targetName = data.sourceName;
  5269. Promise.resolve().then(function () {
  5270. return action[0].call(action[1], data.data);
  5271. }).then(function (result) {
  5272. comObj.postMessage({
  5273. sourceName: sourceName,
  5274. targetName: targetName,
  5275. isReply: true,
  5276. callbackId: data.callbackId,
  5277. data: result
  5278. });
  5279. }, function (reason) {
  5280. if (reason instanceof Error) {
  5281. // Serialize error to avoid "DataCloneError"
  5282. reason = reason + '';
  5283. }
  5284. comObj.postMessage({
  5285. sourceName: sourceName,
  5286. targetName: targetName,
  5287. isReply: true,
  5288. callbackId: data.callbackId,
  5289. error: reason
  5290. });
  5291. });
  5292. } else {
  5293. action[0].call(action[1], data.data);
  5294. }
  5295. } else {
  5296. error('Unknown action from worker: ' + data.action);
  5297. }
  5298. }.bind(this);
  5299. comObj.addEventListener('message', this._onComObjOnMessage);
  5300. }
  5301. MessageHandler.prototype = {
  5302. on: function messageHandlerOn(actionName, handler, scope) {
  5303. var ah = this.actionHandler;
  5304. if (ah[actionName]) {
  5305. error('There is already an actionName called "' + actionName + '"');
  5306. }
  5307. ah[actionName] = [
  5308. handler,
  5309. scope
  5310. ];
  5311. },
  5312. /**
  5313. * Sends a message to the comObj to invoke the action with the supplied data.
  5314. * @param {String} actionName Action to call.
  5315. * @param {JSON} data JSON data to send.
  5316. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  5317. */
  5318. send: function messageHandlerSend(actionName, data, transfers) {
  5319. var message = {
  5320. sourceName: this.sourceName,
  5321. targetName: this.targetName,
  5322. action: actionName,
  5323. data: data
  5324. };
  5325. this.postMessage(message, transfers);
  5326. },
  5327. /**
  5328. * Sends a message to the comObj to invoke the action with the supplied data.
  5329. * Expects that other side will callback with the response.
  5330. * @param {String} actionName Action to call.
  5331. * @param {JSON} data JSON data to send.
  5332. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  5333. * @returns {Promise} Promise to be resolved with response data.
  5334. */
  5335. sendWithPromise: function messageHandlerSendWithPromise(actionName, data, transfers) {
  5336. var callbackId = this.callbackIndex++;
  5337. var message = {
  5338. sourceName: this.sourceName,
  5339. targetName: this.targetName,
  5340. action: actionName,
  5341. data: data,
  5342. callbackId: callbackId
  5343. };
  5344. var capability = createPromiseCapability();
  5345. this.callbacksCapabilities[callbackId] = capability;
  5346. try {
  5347. this.postMessage(message, transfers);
  5348. } catch (e) {
  5349. capability.reject(e);
  5350. }
  5351. return capability.promise;
  5352. },
  5353. /**
  5354. * Sends raw message to the comObj.
  5355. * @private
  5356. * @param message {Object} Raw message.
  5357. * @param transfers List of transfers/ArrayBuffers, or undefined.
  5358. */
  5359. postMessage: function (message, transfers) {
  5360. if (transfers && this.postMessageTransfers) {
  5361. this.comObj.postMessage(message, transfers);
  5362. } else {
  5363. this.comObj.postMessage(message);
  5364. }
  5365. },
  5366. destroy: function () {
  5367. this.comObj.removeEventListener('message', this._onComObjOnMessage);
  5368. }
  5369. };
  5370. function loadJpegStream(id, imageUrl, objs) {
  5371. var img = new Image();
  5372. img.onload = function loadJpegStream_onloadClosure() {
  5373. objs.resolve(id, img);
  5374. };
  5375. img.onerror = function loadJpegStream_onerrorClosure() {
  5376. objs.resolve(id, null);
  5377. warn('Error during JPEG image loading');
  5378. };
  5379. img.src = imageUrl;
  5380. }
  5381. // Polyfill from https://github.com/Polymer/URL
  5382. /* Any copyright is dedicated to the Public Domain.
  5383. * http://creativecommons.org/publicdomain/zero/1.0/ */
  5384. (function checkURLConstructor(scope) {
  5385. // feature detect for URL constructor
  5386. var hasWorkingUrl = false;
  5387. try {
  5388. if (typeof URL === 'function' && typeof URL.prototype === 'object' && 'origin' in URL.prototype) {
  5389. var u = new URL('b', 'http://a');
  5390. u.pathname = 'c%20d';
  5391. hasWorkingUrl = u.href === 'http://a/c%20d';
  5392. }
  5393. } catch (e) {
  5394. }
  5395. if (hasWorkingUrl) {
  5396. return;
  5397. }
  5398. var relative = Object.create(null);
  5399. relative['ftp'] = 21;
  5400. relative['file'] = 0;
  5401. relative['gopher'] = 70;
  5402. relative['http'] = 80;
  5403. relative['https'] = 443;
  5404. relative['ws'] = 80;
  5405. relative['wss'] = 443;
  5406. var relativePathDotMapping = Object.create(null);
  5407. relativePathDotMapping['%2e'] = '.';
  5408. relativePathDotMapping['.%2e'] = '..';
  5409. relativePathDotMapping['%2e.'] = '..';
  5410. relativePathDotMapping['%2e%2e'] = '..';
  5411. function isRelativeScheme(scheme) {
  5412. return relative[scheme] !== undefined;
  5413. }
  5414. function invalid() {
  5415. clear.call(this);
  5416. this._isInvalid = true;
  5417. }
  5418. function IDNAToASCII(h) {
  5419. if ('' === h) {
  5420. invalid.call(this);
  5421. }
  5422. // XXX
  5423. return h.toLowerCase();
  5424. }
  5425. function percentEscape(c) {
  5426. var unicode = c.charCodeAt(0);
  5427. if (unicode > 0x20 && unicode < 0x7F && // " # < > ? `
  5428. [
  5429. 0x22,
  5430. 0x23,
  5431. 0x3C,
  5432. 0x3E,
  5433. 0x3F,
  5434. 0x60
  5435. ].indexOf(unicode) === -1) {
  5436. return c;
  5437. }
  5438. return encodeURIComponent(c);
  5439. }
  5440. function percentEscapeQuery(c) {
  5441. // XXX This actually needs to encode c using encoding and then
  5442. // convert the bytes one-by-one.
  5443. var unicode = c.charCodeAt(0);
  5444. if (unicode > 0x20 && unicode < 0x7F && // " # < > ` (do not escape '?')
  5445. [
  5446. 0x22,
  5447. 0x23,
  5448. 0x3C,
  5449. 0x3E,
  5450. 0x60
  5451. ].indexOf(unicode) === -1) {
  5452. return c;
  5453. }
  5454. return encodeURIComponent(c);
  5455. }
  5456. var EOF, ALPHA = /[a-zA-Z]/, ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/;
  5457. function parse(input, stateOverride, base) {
  5458. function err(message) {
  5459. errors.push(message);
  5460. }
  5461. var state = stateOverride || 'scheme start', cursor = 0, buffer = '', seenAt = false, seenBracket = false, errors = [];
  5462. loop:
  5463. while ((input[cursor - 1] !== EOF || cursor === 0) && !this._isInvalid) {
  5464. var c = input[cursor];
  5465. switch (state) {
  5466. case 'scheme start':
  5467. if (c && ALPHA.test(c)) {
  5468. buffer += c.toLowerCase();
  5469. // ASCII-safe
  5470. state = 'scheme';
  5471. } else if (!stateOverride) {
  5472. buffer = '';
  5473. state = 'no scheme';
  5474. continue;
  5475. } else {
  5476. err('Invalid scheme.');
  5477. break loop;
  5478. }
  5479. break;
  5480. case 'scheme':
  5481. if (c && ALPHANUMERIC.test(c)) {
  5482. buffer += c.toLowerCase();
  5483. } else // ASCII-safe
  5484. if (':' === c) {
  5485. this._scheme = buffer;
  5486. buffer = '';
  5487. if (stateOverride) {
  5488. break loop;
  5489. }
  5490. if (isRelativeScheme(this._scheme)) {
  5491. this._isRelative = true;
  5492. }
  5493. if ('file' === this._scheme) {
  5494. state = 'relative';
  5495. } else if (this._isRelative && base && base._scheme === this._scheme) {
  5496. state = 'relative or authority';
  5497. } else if (this._isRelative) {
  5498. state = 'authority first slash';
  5499. } else {
  5500. state = 'scheme data';
  5501. }
  5502. } else if (!stateOverride) {
  5503. buffer = '';
  5504. cursor = 0;
  5505. state = 'no scheme';
  5506. continue;
  5507. } else if (EOF === c) {
  5508. break loop;
  5509. } else {
  5510. err('Code point not allowed in scheme: ' + c);
  5511. break loop;
  5512. }
  5513. break;
  5514. case 'scheme data':
  5515. if ('?' === c) {
  5516. this._query = '?';
  5517. state = 'query';
  5518. } else if ('#' === c) {
  5519. this._fragment = '#';
  5520. state = 'fragment';
  5521. } else {
  5522. // XXX error handling
  5523. if (EOF !== c && '\t' !== c && '\n' !== c && '\r' !== c) {
  5524. this._schemeData += percentEscape(c);
  5525. }
  5526. }
  5527. break;
  5528. case 'no scheme':
  5529. if (!base || !isRelativeScheme(base._scheme)) {
  5530. err('Missing scheme.');
  5531. invalid.call(this);
  5532. } else {
  5533. state = 'relative';
  5534. continue;
  5535. }
  5536. break;
  5537. case 'relative or authority':
  5538. if ('/' === c && '/' === input[cursor + 1]) {
  5539. state = 'authority ignore slashes';
  5540. } else {
  5541. err('Expected /, got: ' + c);
  5542. state = 'relative';
  5543. continue;
  5544. }
  5545. break;
  5546. case 'relative':
  5547. this._isRelative = true;
  5548. if ('file' !== this._scheme) {
  5549. this._scheme = base._scheme;
  5550. }
  5551. if (EOF === c) {
  5552. this._host = base._host;
  5553. this._port = base._port;
  5554. this._path = base._path.slice();
  5555. this._query = base._query;
  5556. this._username = base._username;
  5557. this._password = base._password;
  5558. break loop;
  5559. } else if ('/' === c || '\\' === c) {
  5560. if ('\\' === c) {
  5561. err('\\ is an invalid code point.');
  5562. }
  5563. state = 'relative slash';
  5564. } else if ('?' === c) {
  5565. this._host = base._host;
  5566. this._port = base._port;
  5567. this._path = base._path.slice();
  5568. this._query = '?';
  5569. this._username = base._username;
  5570. this._password = base._password;
  5571. state = 'query';
  5572. } else if ('#' === c) {
  5573. this._host = base._host;
  5574. this._port = base._port;
  5575. this._path = base._path.slice();
  5576. this._query = base._query;
  5577. this._fragment = '#';
  5578. this._username = base._username;
  5579. this._password = base._password;
  5580. state = 'fragment';
  5581. } else {
  5582. var nextC = input[cursor + 1];
  5583. var nextNextC = input[cursor + 2];
  5584. if ('file' !== this._scheme || !ALPHA.test(c) || nextC !== ':' && nextC !== '|' || EOF !== nextNextC && '/' !== nextNextC && '\\' !== nextNextC && '?' !== nextNextC && '#' !== nextNextC) {
  5585. this._host = base._host;
  5586. this._port = base._port;
  5587. this._username = base._username;
  5588. this._password = base._password;
  5589. this._path = base._path.slice();
  5590. this._path.pop();
  5591. }
  5592. state = 'relative path';
  5593. continue;
  5594. }
  5595. break;
  5596. case 'relative slash':
  5597. if ('/' === c || '\\' === c) {
  5598. if ('\\' === c) {
  5599. err('\\ is an invalid code point.');
  5600. }
  5601. if ('file' === this._scheme) {
  5602. state = 'file host';
  5603. } else {
  5604. state = 'authority ignore slashes';
  5605. }
  5606. } else {
  5607. if ('file' !== this._scheme) {
  5608. this._host = base._host;
  5609. this._port = base._port;
  5610. this._username = base._username;
  5611. this._password = base._password;
  5612. }
  5613. state = 'relative path';
  5614. continue;
  5615. }
  5616. break;
  5617. case 'authority first slash':
  5618. if ('/' === c) {
  5619. state = 'authority second slash';
  5620. } else {
  5621. err('Expected \'/\', got: ' + c);
  5622. state = 'authority ignore slashes';
  5623. continue;
  5624. }
  5625. break;
  5626. case 'authority second slash':
  5627. state = 'authority ignore slashes';
  5628. if ('/' !== c) {
  5629. err('Expected \'/\', got: ' + c);
  5630. continue;
  5631. }
  5632. break;
  5633. case 'authority ignore slashes':
  5634. if ('/' !== c && '\\' !== c) {
  5635. state = 'authority';
  5636. continue;
  5637. } else {
  5638. err('Expected authority, got: ' + c);
  5639. }
  5640. break;
  5641. case 'authority':
  5642. if ('@' === c) {
  5643. if (seenAt) {
  5644. err('@ already seen.');
  5645. buffer += '%40';
  5646. }
  5647. seenAt = true;
  5648. for (var i = 0; i < buffer.length; i++) {
  5649. var cp = buffer[i];
  5650. if ('\t' === cp || '\n' === cp || '\r' === cp) {
  5651. err('Invalid whitespace in authority.');
  5652. continue;
  5653. }
  5654. // XXX check URL code points
  5655. if (':' === cp && null === this._password) {
  5656. this._password = '';
  5657. continue;
  5658. }
  5659. var tempC = percentEscape(cp);
  5660. if (null !== this._password) {
  5661. this._password += tempC;
  5662. } else {
  5663. this._username += tempC;
  5664. }
  5665. }
  5666. buffer = '';
  5667. } else if (EOF === c || '/' === c || '\\' === c || '?' === c || '#' === c) {
  5668. cursor -= buffer.length;
  5669. buffer = '';
  5670. state = 'host';
  5671. continue;
  5672. } else {
  5673. buffer += c;
  5674. }
  5675. break;
  5676. case 'file host':
  5677. if (EOF === c || '/' === c || '\\' === c || '?' === c || '#' === c) {
  5678. if (buffer.length === 2 && ALPHA.test(buffer[0]) && (buffer[1] === ':' || buffer[1] === '|')) {
  5679. state = 'relative path';
  5680. } else if (buffer.length === 0) {
  5681. state = 'relative path start';
  5682. } else {
  5683. this._host = IDNAToASCII.call(this, buffer);
  5684. buffer = '';
  5685. state = 'relative path start';
  5686. }
  5687. continue;
  5688. } else if ('\t' === c || '\n' === c || '\r' === c) {
  5689. err('Invalid whitespace in file host.');
  5690. } else {
  5691. buffer += c;
  5692. }
  5693. break;
  5694. case 'host':
  5695. case 'hostname':
  5696. if (':' === c && !seenBracket) {
  5697. // XXX host parsing
  5698. this._host = IDNAToASCII.call(this, buffer);
  5699. buffer = '';
  5700. state = 'port';
  5701. if ('hostname' === stateOverride) {
  5702. break loop;
  5703. }
  5704. } else if (EOF === c || '/' === c || '\\' === c || '?' === c || '#' === c) {
  5705. this._host = IDNAToASCII.call(this, buffer);
  5706. buffer = '';
  5707. state = 'relative path start';
  5708. if (stateOverride) {
  5709. break loop;
  5710. }
  5711. continue;
  5712. } else if ('\t' !== c && '\n' !== c && '\r' !== c) {
  5713. if ('[' === c) {
  5714. seenBracket = true;
  5715. } else if (']' === c) {
  5716. seenBracket = false;
  5717. }
  5718. buffer += c;
  5719. } else {
  5720. err('Invalid code point in host/hostname: ' + c);
  5721. }
  5722. break;
  5723. case 'port':
  5724. if (/[0-9]/.test(c)) {
  5725. buffer += c;
  5726. } else if (EOF === c || '/' === c || '\\' === c || '?' === c || '#' === c || stateOverride) {
  5727. if ('' !== buffer) {
  5728. var temp = parseInt(buffer, 10);
  5729. if (temp !== relative[this._scheme]) {
  5730. this._port = temp + '';
  5731. }
  5732. buffer = '';
  5733. }
  5734. if (stateOverride) {
  5735. break loop;
  5736. }
  5737. state = 'relative path start';
  5738. continue;
  5739. } else if ('\t' === c || '\n' === c || '\r' === c) {
  5740. err('Invalid code point in port: ' + c);
  5741. } else {
  5742. invalid.call(this);
  5743. }
  5744. break;
  5745. case 'relative path start':
  5746. if ('\\' === c) {
  5747. err('\'\\\' not allowed in path.');
  5748. }
  5749. state = 'relative path';
  5750. if ('/' !== c && '\\' !== c) {
  5751. continue;
  5752. }
  5753. break;
  5754. case 'relative path':
  5755. if (EOF === c || '/' === c || '\\' === c || !stateOverride && ('?' === c || '#' === c)) {
  5756. if ('\\' === c) {
  5757. err('\\ not allowed in relative path.');
  5758. }
  5759. var tmp;
  5760. if (tmp = relativePathDotMapping[buffer.toLowerCase()]) {
  5761. buffer = tmp;
  5762. }
  5763. if ('..' === buffer) {
  5764. this._path.pop();
  5765. if ('/' !== c && '\\' !== c) {
  5766. this._path.push('');
  5767. }
  5768. } else if ('.' === buffer && '/' !== c && '\\' !== c) {
  5769. this._path.push('');
  5770. } else if ('.' !== buffer) {
  5771. if ('file' === this._scheme && this._path.length === 0 && buffer.length === 2 && ALPHA.test(buffer[0]) && buffer[1] === '|') {
  5772. buffer = buffer[0] + ':';
  5773. }
  5774. this._path.push(buffer);
  5775. }
  5776. buffer = '';
  5777. if ('?' === c) {
  5778. this._query = '?';
  5779. state = 'query';
  5780. } else if ('#' === c) {
  5781. this._fragment = '#';
  5782. state = 'fragment';
  5783. }
  5784. } else if ('\t' !== c && '\n' !== c && '\r' !== c) {
  5785. buffer += percentEscape(c);
  5786. }
  5787. break;
  5788. case 'query':
  5789. if (!stateOverride && '#' === c) {
  5790. this._fragment = '#';
  5791. state = 'fragment';
  5792. } else if (EOF !== c && '\t' !== c && '\n' !== c && '\r' !== c) {
  5793. this._query += percentEscapeQuery(c);
  5794. }
  5795. break;
  5796. case 'fragment':
  5797. if (EOF !== c && '\t' !== c && '\n' !== c && '\r' !== c) {
  5798. this._fragment += c;
  5799. }
  5800. break;
  5801. }
  5802. cursor++;
  5803. }
  5804. }
  5805. function clear() {
  5806. this._scheme = '';
  5807. this._schemeData = '';
  5808. this._username = '';
  5809. this._password = null;
  5810. this._host = '';
  5811. this._port = '';
  5812. this._path = [];
  5813. this._query = '';
  5814. this._fragment = '';
  5815. this._isInvalid = false;
  5816. this._isRelative = false;
  5817. }
  5818. // Does not process domain names or IP addresses.
  5819. // Does not handle encoding for the query parameter.
  5820. function JURL(url, base)
  5821. /* , encoding */
  5822. {
  5823. if (base !== undefined && !(base instanceof JURL)) {
  5824. base = new JURL(String(base));
  5825. }
  5826. this._url = url;
  5827. clear.call(this);
  5828. var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, '');
  5829. // encoding = encoding || 'utf-8'
  5830. parse.call(this, input, null, base);
  5831. }
  5832. JURL.prototype = {
  5833. toString: function () {
  5834. return this.href;
  5835. },
  5836. get href() {
  5837. if (this._isInvalid) {
  5838. return this._url;
  5839. }
  5840. var authority = '';
  5841. if ('' !== this._username || null !== this._password) {
  5842. authority = this._username + (null !== this._password ? ':' + this._password : '') + '@';
  5843. }
  5844. return this.protocol + (this._isRelative ? '//' + authority + this.host : '') + this.pathname + this._query + this._fragment;
  5845. },
  5846. set href(href) {
  5847. clear.call(this);
  5848. parse.call(this, href);
  5849. },
  5850. get protocol() {
  5851. return this._scheme + ':';
  5852. },
  5853. set protocol(protocol) {
  5854. if (this._isInvalid) {
  5855. return;
  5856. }
  5857. parse.call(this, protocol + ':', 'scheme start');
  5858. },
  5859. get host() {
  5860. return this._isInvalid ? '' : this._port ? this._host + ':' + this._port : this._host;
  5861. },
  5862. set host(host) {
  5863. if (this._isInvalid || !this._isRelative) {
  5864. return;
  5865. }
  5866. parse.call(this, host, 'host');
  5867. },
  5868. get hostname() {
  5869. return this._host;
  5870. },
  5871. set hostname(hostname) {
  5872. if (this._isInvalid || !this._isRelative) {
  5873. return;
  5874. }
  5875. parse.call(this, hostname, 'hostname');
  5876. },
  5877. get port() {
  5878. return this._port;
  5879. },
  5880. set port(port) {
  5881. if (this._isInvalid || !this._isRelative) {
  5882. return;
  5883. }
  5884. parse.call(this, port, 'port');
  5885. },
  5886. get pathname() {
  5887. return this._isInvalid ? '' : this._isRelative ? '/' + this._path.join('/') : this._schemeData;
  5888. },
  5889. set pathname(pathname) {
  5890. if (this._isInvalid || !this._isRelative) {
  5891. return;
  5892. }
  5893. this._path = [];
  5894. parse.call(this, pathname, 'relative path start');
  5895. },
  5896. get search() {
  5897. return this._isInvalid || !this._query || '?' === this._query ? '' : this._query;
  5898. },
  5899. set search(search) {
  5900. if (this._isInvalid || !this._isRelative) {
  5901. return;
  5902. }
  5903. this._query = '?';
  5904. if ('?' === search[0]) {
  5905. search = search.slice(1);
  5906. }
  5907. parse.call(this, search, 'query');
  5908. },
  5909. get hash() {
  5910. return this._isInvalid || !this._fragment || '#' === this._fragment ? '' : this._fragment;
  5911. },
  5912. set hash(hash) {
  5913. if (this._isInvalid) {
  5914. return;
  5915. }
  5916. this._fragment = '#';
  5917. if ('#' === hash[0]) {
  5918. hash = hash.slice(1);
  5919. }
  5920. parse.call(this, hash, 'fragment');
  5921. },
  5922. get origin() {
  5923. var host;
  5924. if (this._isInvalid || !this._scheme) {
  5925. return '';
  5926. }
  5927. // javascript: Gecko returns String(""), WebKit/Blink String("null")
  5928. // Gecko throws error for "data://"
  5929. // data: Gecko returns "", Blink returns "data://", WebKit returns "null"
  5930. // Gecko returns String("") for file: mailto:
  5931. // WebKit/Blink returns String("SCHEME://") for file: mailto:
  5932. switch (this._scheme) {
  5933. case 'data':
  5934. case 'file':
  5935. case 'javascript':
  5936. case 'mailto':
  5937. return 'null';
  5938. }
  5939. host = this.host;
  5940. if (!host) {
  5941. return '';
  5942. }
  5943. return this._scheme + '://' + host;
  5944. }
  5945. };
  5946. // Copy over the static methods
  5947. var OriginalURL = scope.URL;
  5948. if (OriginalURL) {
  5949. JURL.createObjectURL = function (blob) {
  5950. // IE extension allows a second optional options argument.
  5951. // http://msdn.microsoft.com/en-us/library/ie/hh772302(v=vs.85).aspx
  5952. return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
  5953. };
  5954. JURL.revokeObjectURL = function (url) {
  5955. OriginalURL.revokeObjectURL(url);
  5956. };
  5957. }
  5958. scope.URL = JURL;
  5959. }(globalScope));
  5960. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  5961. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  5962. exports.OPS = OPS;
  5963. exports.VERBOSITY_LEVELS = VERBOSITY_LEVELS;
  5964. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  5965. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  5966. exports.AnnotationFieldFlag = AnnotationFieldFlag;
  5967. exports.AnnotationFlag = AnnotationFlag;
  5968. exports.AnnotationType = AnnotationType;
  5969. exports.FontType = FontType;
  5970. exports.ImageKind = ImageKind;
  5971. exports.InvalidPDFException = InvalidPDFException;
  5972. exports.MessageHandler = MessageHandler;
  5973. exports.MissingDataException = MissingDataException;
  5974. exports.MissingPDFException = MissingPDFException;
  5975. exports.NotImplementedException = NotImplementedException;
  5976. exports.PageViewport = PageViewport;
  5977. exports.PasswordException = PasswordException;
  5978. exports.PasswordResponses = PasswordResponses;
  5979. exports.StatTimer = StatTimer;
  5980. exports.StreamType = StreamType;
  5981. exports.TextRenderingMode = TextRenderingMode;
  5982. exports.UnexpectedResponseException = UnexpectedResponseException;
  5983. exports.UnknownErrorException = UnknownErrorException;
  5984. exports.Util = Util;
  5985. exports.XRefParseException = XRefParseException;
  5986. exports.arrayByteLength = arrayByteLength;
  5987. exports.arraysToBytes = arraysToBytes;
  5988. exports.assert = assert;
  5989. exports.bytesToString = bytesToString;
  5990. exports.createBlob = createBlob;
  5991. exports.createPromiseCapability = createPromiseCapability;
  5992. exports.createObjectURL = createObjectURL;
  5993. exports.deprecated = deprecated;
  5994. exports.error = error;
  5995. exports.getLookupTableFactory = getLookupTableFactory;
  5996. exports.getVerbosityLevel = getVerbosityLevel;
  5997. exports.globalScope = globalScope;
  5998. exports.info = info;
  5999. exports.isArray = isArray;
  6000. exports.isArrayBuffer = isArrayBuffer;
  6001. exports.isBool = isBool;
  6002. exports.isEmptyObj = isEmptyObj;
  6003. exports.isInt = isInt;
  6004. exports.isNum = isNum;
  6005. exports.isString = isString;
  6006. exports.isSpace = isSpace;
  6007. exports.isSameOrigin = isSameOrigin;
  6008. exports.isValidUrl = isValidUrl;
  6009. exports.isLittleEndian = isLittleEndian;
  6010. exports.isEvalSupported = isEvalSupported;
  6011. exports.loadJpegStream = loadJpegStream;
  6012. exports.log2 = log2;
  6013. exports.readInt8 = readInt8;
  6014. exports.readUint16 = readUint16;
  6015. exports.readUint32 = readUint32;
  6016. exports.removeNullCharacters = removeNullCharacters;
  6017. exports.setVerbosityLevel = setVerbosityLevel;
  6018. exports.shadow = shadow;
  6019. exports.string32 = string32;
  6020. exports.stringToBytes = stringToBytes;
  6021. exports.stringToPDFString = stringToPDFString;
  6022. exports.stringToUTF8String = stringToUTF8String;
  6023. exports.utf8StringToString = utf8StringToString;
  6024. exports.warn = warn;
  6025. }));
  6026. (function (root, factory) {
  6027. factory(root.pdfjsCoreCFFParser = {}, root.pdfjsSharedUtil, root.pdfjsCoreCharsets, root.pdfjsCoreEncodings);
  6028. }(this, function (exports, sharedUtil, coreCharsets, coreEncodings) {
  6029. var error = sharedUtil.error;
  6030. var info = sharedUtil.info;
  6031. var bytesToString = sharedUtil.bytesToString;
  6032. var warn = sharedUtil.warn;
  6033. var isArray = sharedUtil.isArray;
  6034. var Util = sharedUtil.Util;
  6035. var stringToBytes = sharedUtil.stringToBytes;
  6036. var assert = sharedUtil.assert;
  6037. var ISOAdobeCharset = coreCharsets.ISOAdobeCharset;
  6038. var ExpertCharset = coreCharsets.ExpertCharset;
  6039. var ExpertSubsetCharset = coreCharsets.ExpertSubsetCharset;
  6040. var StandardEncoding = coreEncodings.StandardEncoding;
  6041. var ExpertEncoding = coreEncodings.ExpertEncoding;
  6042. // Maximum subroutine call depth of type 2 chartrings. Matches OTS.
  6043. var MAX_SUBR_NESTING = 10;
  6044. /**
  6045. * The CFF class takes a Type1 file and wrap it into a
  6046. * 'Compact Font Format' which itself embed Type2 charstrings.
  6047. */
  6048. var CFFStandardStrings = [
  6049. '.notdef',
  6050. 'space',
  6051. 'exclam',
  6052. 'quotedbl',
  6053. 'numbersign',
  6054. 'dollar',
  6055. 'percent',
  6056. 'ampersand',
  6057. 'quoteright',
  6058. 'parenleft',
  6059. 'parenright',
  6060. 'asterisk',
  6061. 'plus',
  6062. 'comma',
  6063. 'hyphen',
  6064. 'period',
  6065. 'slash',
  6066. 'zero',
  6067. 'one',
  6068. 'two',
  6069. 'three',
  6070. 'four',
  6071. 'five',
  6072. 'six',
  6073. 'seven',
  6074. 'eight',
  6075. 'nine',
  6076. 'colon',
  6077. 'semicolon',
  6078. 'less',
  6079. 'equal',
  6080. 'greater',
  6081. 'question',
  6082. 'at',
  6083. 'A',
  6084. 'B',
  6085. 'C',
  6086. 'D',
  6087. 'E',
  6088. 'F',
  6089. 'G',
  6090. 'H',
  6091. 'I',
  6092. 'J',
  6093. 'K',
  6094. 'L',
  6095. 'M',
  6096. 'N',
  6097. 'O',
  6098. 'P',
  6099. 'Q',
  6100. 'R',
  6101. 'S',
  6102. 'T',
  6103. 'U',
  6104. 'V',
  6105. 'W',
  6106. 'X',
  6107. 'Y',
  6108. 'Z',
  6109. 'bracketleft',
  6110. 'backslash',
  6111. 'bracketright',
  6112. 'asciicircum',
  6113. 'underscore',
  6114. 'quoteleft',
  6115. 'a',
  6116. 'b',
  6117. 'c',
  6118. 'd',
  6119. 'e',
  6120. 'f',
  6121. 'g',
  6122. 'h',
  6123. 'i',
  6124. 'j',
  6125. 'k',
  6126. 'l',
  6127. 'm',
  6128. 'n',
  6129. 'o',
  6130. 'p',
  6131. 'q',
  6132. 'r',
  6133. 's',
  6134. 't',
  6135. 'u',
  6136. 'v',
  6137. 'w',
  6138. 'x',
  6139. 'y',
  6140. 'z',
  6141. 'braceleft',
  6142. 'bar',
  6143. 'braceright',
  6144. 'asciitilde',
  6145. 'exclamdown',
  6146. 'cent',
  6147. 'sterling',
  6148. 'fraction',
  6149. 'yen',
  6150. 'florin',
  6151. 'section',
  6152. 'currency',
  6153. 'quotesingle',
  6154. 'quotedblleft',
  6155. 'guillemotleft',
  6156. 'guilsinglleft',
  6157. 'guilsinglright',
  6158. 'fi',
  6159. 'fl',
  6160. 'endash',
  6161. 'dagger',
  6162. 'daggerdbl',
  6163. 'periodcentered',
  6164. 'paragraph',
  6165. 'bullet',
  6166. 'quotesinglbase',
  6167. 'quotedblbase',
  6168. 'quotedblright',
  6169. 'guillemotright',
  6170. 'ellipsis',
  6171. 'perthousand',
  6172. 'questiondown',
  6173. 'grave',
  6174. 'acute',
  6175. 'circumflex',
  6176. 'tilde',
  6177. 'macron',
  6178. 'breve',
  6179. 'dotaccent',
  6180. 'dieresis',
  6181. 'ring',
  6182. 'cedilla',
  6183. 'hungarumlaut',
  6184. 'ogonek',
  6185. 'caron',
  6186. 'emdash',
  6187. 'AE',
  6188. 'ordfeminine',
  6189. 'Lslash',
  6190. 'Oslash',
  6191. 'OE',
  6192. 'ordmasculine',
  6193. 'ae',
  6194. 'dotlessi',
  6195. 'lslash',
  6196. 'oslash',
  6197. 'oe',
  6198. 'germandbls',
  6199. 'onesuperior',
  6200. 'logicalnot',
  6201. 'mu',
  6202. 'trademark',
  6203. 'Eth',
  6204. 'onehalf',
  6205. 'plusminus',
  6206. 'Thorn',
  6207. 'onequarter',
  6208. 'divide',
  6209. 'brokenbar',
  6210. 'degree',
  6211. 'thorn',
  6212. 'threequarters',
  6213. 'twosuperior',
  6214. 'registered',
  6215. 'minus',
  6216. 'eth',
  6217. 'multiply',
  6218. 'threesuperior',
  6219. 'copyright',
  6220. 'Aacute',
  6221. 'Acircumflex',
  6222. 'Adieresis',
  6223. 'Agrave',
  6224. 'Aring',
  6225. 'Atilde',
  6226. 'Ccedilla',
  6227. 'Eacute',
  6228. 'Ecircumflex',
  6229. 'Edieresis',
  6230. 'Egrave',
  6231. 'Iacute',
  6232. 'Icircumflex',
  6233. 'Idieresis',
  6234. 'Igrave',
  6235. 'Ntilde',
  6236. 'Oacute',
  6237. 'Ocircumflex',
  6238. 'Odieresis',
  6239. 'Ograve',
  6240. 'Otilde',
  6241. 'Scaron',
  6242. 'Uacute',
  6243. 'Ucircumflex',
  6244. 'Udieresis',
  6245. 'Ugrave',
  6246. 'Yacute',
  6247. 'Ydieresis',
  6248. 'Zcaron',
  6249. 'aacute',
  6250. 'acircumflex',
  6251. 'adieresis',
  6252. 'agrave',
  6253. 'aring',
  6254. 'atilde',
  6255. 'ccedilla',
  6256. 'eacute',
  6257. 'ecircumflex',
  6258. 'edieresis',
  6259. 'egrave',
  6260. 'iacute',
  6261. 'icircumflex',
  6262. 'idieresis',
  6263. 'igrave',
  6264. 'ntilde',
  6265. 'oacute',
  6266. 'ocircumflex',
  6267. 'odieresis',
  6268. 'ograve',
  6269. 'otilde',
  6270. 'scaron',
  6271. 'uacute',
  6272. 'ucircumflex',
  6273. 'udieresis',
  6274. 'ugrave',
  6275. 'yacute',
  6276. 'ydieresis',
  6277. 'zcaron',
  6278. 'exclamsmall',
  6279. 'Hungarumlautsmall',
  6280. 'dollaroldstyle',
  6281. 'dollarsuperior',
  6282. 'ampersandsmall',
  6283. 'Acutesmall',
  6284. 'parenleftsuperior',
  6285. 'parenrightsuperior',
  6286. 'twodotenleader',
  6287. 'onedotenleader',
  6288. 'zerooldstyle',
  6289. 'oneoldstyle',
  6290. 'twooldstyle',
  6291. 'threeoldstyle',
  6292. 'fouroldstyle',
  6293. 'fiveoldstyle',
  6294. 'sixoldstyle',
  6295. 'sevenoldstyle',
  6296. 'eightoldstyle',
  6297. 'nineoldstyle',
  6298. 'commasuperior',
  6299. 'threequartersemdash',
  6300. 'periodsuperior',
  6301. 'questionsmall',
  6302. 'asuperior',
  6303. 'bsuperior',
  6304. 'centsuperior',
  6305. 'dsuperior',
  6306. 'esuperior',
  6307. 'isuperior',
  6308. 'lsuperior',
  6309. 'msuperior',
  6310. 'nsuperior',
  6311. 'osuperior',
  6312. 'rsuperior',
  6313. 'ssuperior',
  6314. 'tsuperior',
  6315. 'ff',
  6316. 'ffi',
  6317. 'ffl',
  6318. 'parenleftinferior',
  6319. 'parenrightinferior',
  6320. 'Circumflexsmall',
  6321. 'hyphensuperior',
  6322. 'Gravesmall',
  6323. 'Asmall',
  6324. 'Bsmall',
  6325. 'Csmall',
  6326. 'Dsmall',
  6327. 'Esmall',
  6328. 'Fsmall',
  6329. 'Gsmall',
  6330. 'Hsmall',
  6331. 'Ismall',
  6332. 'Jsmall',
  6333. 'Ksmall',
  6334. 'Lsmall',
  6335. 'Msmall',
  6336. 'Nsmall',
  6337. 'Osmall',
  6338. 'Psmall',
  6339. 'Qsmall',
  6340. 'Rsmall',
  6341. 'Ssmall',
  6342. 'Tsmall',
  6343. 'Usmall',
  6344. 'Vsmall',
  6345. 'Wsmall',
  6346. 'Xsmall',
  6347. 'Ysmall',
  6348. 'Zsmall',
  6349. 'colonmonetary',
  6350. 'onefitted',
  6351. 'rupiah',
  6352. 'Tildesmall',
  6353. 'exclamdownsmall',
  6354. 'centoldstyle',
  6355. 'Lslashsmall',
  6356. 'Scaronsmall',
  6357. 'Zcaronsmall',
  6358. 'Dieresissmall',
  6359. 'Brevesmall',
  6360. 'Caronsmall',
  6361. 'Dotaccentsmall',
  6362. 'Macronsmall',
  6363. 'figuredash',
  6364. 'hypheninferior',
  6365. 'Ogoneksmall',
  6366. 'Ringsmall',
  6367. 'Cedillasmall',
  6368. 'questiondownsmall',
  6369. 'oneeighth',
  6370. 'threeeighths',
  6371. 'fiveeighths',
  6372. 'seveneighths',
  6373. 'onethird',
  6374. 'twothirds',
  6375. 'zerosuperior',
  6376. 'foursuperior',
  6377. 'fivesuperior',
  6378. 'sixsuperior',
  6379. 'sevensuperior',
  6380. 'eightsuperior',
  6381. 'ninesuperior',
  6382. 'zeroinferior',
  6383. 'oneinferior',
  6384. 'twoinferior',
  6385. 'threeinferior',
  6386. 'fourinferior',
  6387. 'fiveinferior',
  6388. 'sixinferior',
  6389. 'seveninferior',
  6390. 'eightinferior',
  6391. 'nineinferior',
  6392. 'centinferior',
  6393. 'dollarinferior',
  6394. 'periodinferior',
  6395. 'commainferior',
  6396. 'Agravesmall',
  6397. 'Aacutesmall',
  6398. 'Acircumflexsmall',
  6399. 'Atildesmall',
  6400. 'Adieresissmall',
  6401. 'Aringsmall',
  6402. 'AEsmall',
  6403. 'Ccedillasmall',
  6404. 'Egravesmall',
  6405. 'Eacutesmall',
  6406. 'Ecircumflexsmall',
  6407. 'Edieresissmall',
  6408. 'Igravesmall',
  6409. 'Iacutesmall',
  6410. 'Icircumflexsmall',
  6411. 'Idieresissmall',
  6412. 'Ethsmall',
  6413. 'Ntildesmall',
  6414. 'Ogravesmall',
  6415. 'Oacutesmall',
  6416. 'Ocircumflexsmall',
  6417. 'Otildesmall',
  6418. 'Odieresissmall',
  6419. 'OEsmall',
  6420. 'Oslashsmall',
  6421. 'Ugravesmall',
  6422. 'Uacutesmall',
  6423. 'Ucircumflexsmall',
  6424. 'Udieresissmall',
  6425. 'Yacutesmall',
  6426. 'Thornsmall',
  6427. 'Ydieresissmall',
  6428. '001.000',
  6429. '001.001',
  6430. '001.002',
  6431. '001.003',
  6432. 'Black',
  6433. 'Bold',
  6434. 'Book',
  6435. 'Light',
  6436. 'Medium',
  6437. 'Regular',
  6438. 'Roman',
  6439. 'Semibold'
  6440. ];
  6441. var CFFParser = function CFFParserClosure() {
  6442. var CharstringValidationData = [
  6443. null,
  6444. {
  6445. id: 'hstem',
  6446. min: 2,
  6447. stackClearing: true,
  6448. stem: true
  6449. },
  6450. null,
  6451. {
  6452. id: 'vstem',
  6453. min: 2,
  6454. stackClearing: true,
  6455. stem: true
  6456. },
  6457. {
  6458. id: 'vmoveto',
  6459. min: 1,
  6460. stackClearing: true
  6461. },
  6462. {
  6463. id: 'rlineto',
  6464. min: 2,
  6465. resetStack: true
  6466. },
  6467. {
  6468. id: 'hlineto',
  6469. min: 1,
  6470. resetStack: true
  6471. },
  6472. {
  6473. id: 'vlineto',
  6474. min: 1,
  6475. resetStack: true
  6476. },
  6477. {
  6478. id: 'rrcurveto',
  6479. min: 6,
  6480. resetStack: true
  6481. },
  6482. null,
  6483. {
  6484. id: 'callsubr',
  6485. min: 1,
  6486. undefStack: true
  6487. },
  6488. {
  6489. id: 'return',
  6490. min: 0,
  6491. undefStack: true
  6492. },
  6493. null,
  6494. // 12
  6495. null,
  6496. {
  6497. id: 'endchar',
  6498. min: 0,
  6499. stackClearing: true
  6500. },
  6501. null,
  6502. null,
  6503. null,
  6504. {
  6505. id: 'hstemhm',
  6506. min: 2,
  6507. stackClearing: true,
  6508. stem: true
  6509. },
  6510. {
  6511. id: 'hintmask',
  6512. min: 0,
  6513. stackClearing: true
  6514. },
  6515. {
  6516. id: 'cntrmask',
  6517. min: 0,
  6518. stackClearing: true
  6519. },
  6520. {
  6521. id: 'rmoveto',
  6522. min: 2,
  6523. stackClearing: true
  6524. },
  6525. {
  6526. id: 'hmoveto',
  6527. min: 1,
  6528. stackClearing: true
  6529. },
  6530. {
  6531. id: 'vstemhm',
  6532. min: 2,
  6533. stackClearing: true,
  6534. stem: true
  6535. },
  6536. {
  6537. id: 'rcurveline',
  6538. min: 8,
  6539. resetStack: true
  6540. },
  6541. {
  6542. id: 'rlinecurve',
  6543. min: 8,
  6544. resetStack: true
  6545. },
  6546. {
  6547. id: 'vvcurveto',
  6548. min: 4,
  6549. resetStack: true
  6550. },
  6551. {
  6552. id: 'hhcurveto',
  6553. min: 4,
  6554. resetStack: true
  6555. },
  6556. null,
  6557. // shortint
  6558. {
  6559. id: 'callgsubr',
  6560. min: 1,
  6561. undefStack: true
  6562. },
  6563. {
  6564. id: 'vhcurveto',
  6565. min: 4,
  6566. resetStack: true
  6567. },
  6568. {
  6569. id: 'hvcurveto',
  6570. min: 4,
  6571. resetStack: true
  6572. }
  6573. ];
  6574. var CharstringValidationData12 = [
  6575. null,
  6576. null,
  6577. null,
  6578. {
  6579. id: 'and',
  6580. min: 2,
  6581. stackDelta: -1
  6582. },
  6583. {
  6584. id: 'or',
  6585. min: 2,
  6586. stackDelta: -1
  6587. },
  6588. {
  6589. id: 'not',
  6590. min: 1,
  6591. stackDelta: 0
  6592. },
  6593. null,
  6594. null,
  6595. null,
  6596. {
  6597. id: 'abs',
  6598. min: 1,
  6599. stackDelta: 0
  6600. },
  6601. {
  6602. id: 'add',
  6603. min: 2,
  6604. stackDelta: -1,
  6605. stackFn: function stack_div(stack, index) {
  6606. stack[index - 2] = stack[index - 2] + stack[index - 1];
  6607. }
  6608. },
  6609. {
  6610. id: 'sub',
  6611. min: 2,
  6612. stackDelta: -1,
  6613. stackFn: function stack_div(stack, index) {
  6614. stack[index - 2] = stack[index - 2] - stack[index - 1];
  6615. }
  6616. },
  6617. {
  6618. id: 'div',
  6619. min: 2,
  6620. stackDelta: -1,
  6621. stackFn: function stack_div(stack, index) {
  6622. stack[index - 2] = stack[index - 2] / stack[index - 1];
  6623. }
  6624. },
  6625. null,
  6626. {
  6627. id: 'neg',
  6628. min: 1,
  6629. stackDelta: 0,
  6630. stackFn: function stack_div(stack, index) {
  6631. stack[index - 1] = -stack[index - 1];
  6632. }
  6633. },
  6634. {
  6635. id: 'eq',
  6636. min: 2,
  6637. stackDelta: -1
  6638. },
  6639. null,
  6640. null,
  6641. {
  6642. id: 'drop',
  6643. min: 1,
  6644. stackDelta: -1
  6645. },
  6646. null,
  6647. {
  6648. id: 'put',
  6649. min: 2,
  6650. stackDelta: -2
  6651. },
  6652. {
  6653. id: 'get',
  6654. min: 1,
  6655. stackDelta: 0
  6656. },
  6657. {
  6658. id: 'ifelse',
  6659. min: 4,
  6660. stackDelta: -3
  6661. },
  6662. {
  6663. id: 'random',
  6664. min: 0,
  6665. stackDelta: 1
  6666. },
  6667. {
  6668. id: 'mul',
  6669. min: 2,
  6670. stackDelta: -1,
  6671. stackFn: function stack_div(stack, index) {
  6672. stack[index - 2] = stack[index - 2] * stack[index - 1];
  6673. }
  6674. },
  6675. null,
  6676. {
  6677. id: 'sqrt',
  6678. min: 1,
  6679. stackDelta: 0
  6680. },
  6681. {
  6682. id: 'dup',
  6683. min: 1,
  6684. stackDelta: 1
  6685. },
  6686. {
  6687. id: 'exch',
  6688. min: 2,
  6689. stackDelta: 0
  6690. },
  6691. {
  6692. id: 'index',
  6693. min: 2,
  6694. stackDelta: 0
  6695. },
  6696. {
  6697. id: 'roll',
  6698. min: 3,
  6699. stackDelta: -2
  6700. },
  6701. null,
  6702. null,
  6703. null,
  6704. {
  6705. id: 'hflex',
  6706. min: 7,
  6707. resetStack: true
  6708. },
  6709. {
  6710. id: 'flex',
  6711. min: 13,
  6712. resetStack: true
  6713. },
  6714. {
  6715. id: 'hflex1',
  6716. min: 9,
  6717. resetStack: true
  6718. },
  6719. {
  6720. id: 'flex1',
  6721. min: 11,
  6722. resetStack: true
  6723. }
  6724. ];
  6725. function CFFParser(file, properties, seacAnalysisEnabled) {
  6726. this.bytes = file.getBytes();
  6727. this.properties = properties;
  6728. this.seacAnalysisEnabled = !!seacAnalysisEnabled;
  6729. }
  6730. CFFParser.prototype = {
  6731. parse: function CFFParser_parse() {
  6732. var properties = this.properties;
  6733. var cff = new CFF();
  6734. this.cff = cff;
  6735. // The first five sections must be in order, all the others are reached
  6736. // via offsets contained in one of the below.
  6737. var header = this.parseHeader();
  6738. var nameIndex = this.parseIndex(header.endPos);
  6739. var topDictIndex = this.parseIndex(nameIndex.endPos);
  6740. var stringIndex = this.parseIndex(topDictIndex.endPos);
  6741. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  6742. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  6743. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  6744. cff.header = header.obj;
  6745. cff.names = this.parseNameIndex(nameIndex.obj);
  6746. cff.strings = this.parseStringIndex(stringIndex.obj);
  6747. cff.topDict = topDict;
  6748. cff.globalSubrIndex = globalSubrIndex.obj;
  6749. this.parsePrivateDict(cff.topDict);
  6750. cff.isCIDFont = topDict.hasName('ROS');
  6751. var charStringOffset = topDict.getByName('CharStrings');
  6752. var charStringIndex = this.parseIndex(charStringOffset).obj;
  6753. var fontMatrix = topDict.getByName('FontMatrix');
  6754. if (fontMatrix) {
  6755. properties.fontMatrix = fontMatrix;
  6756. }
  6757. var fontBBox = topDict.getByName('FontBBox');
  6758. if (fontBBox) {
  6759. // adjusting ascent/descent
  6760. properties.ascent = fontBBox[3];
  6761. properties.descent = fontBBox[1];
  6762. properties.ascentScaled = true;
  6763. }
  6764. var charset, encoding;
  6765. if (cff.isCIDFont) {
  6766. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  6767. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  6768. var dictRaw = fdArrayIndex.get(i);
  6769. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw), cff.strings);
  6770. this.parsePrivateDict(fontDict);
  6771. cff.fdArray.push(fontDict);
  6772. }
  6773. // cid fonts don't have an encoding
  6774. encoding = null;
  6775. charset = this.parseCharsets(topDict.getByName('charset'), charStringIndex.count, cff.strings, true);
  6776. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'), charStringIndex.count);
  6777. } else {
  6778. charset = this.parseCharsets(topDict.getByName('charset'), charStringIndex.count, cff.strings, false);
  6779. encoding = this.parseEncoding(topDict.getByName('Encoding'), properties, cff.strings, charset.charset);
  6780. }
  6781. cff.charset = charset;
  6782. cff.encoding = encoding;
  6783. var charStringsAndSeacs = this.parseCharStrings(charStringIndex, topDict.privateDict.subrsIndex, globalSubrIndex.obj, cff.fdSelect, cff.fdArray);
  6784. cff.charStrings = charStringsAndSeacs.charStrings;
  6785. cff.seacs = charStringsAndSeacs.seacs;
  6786. cff.widths = charStringsAndSeacs.widths;
  6787. return cff;
  6788. },
  6789. parseHeader: function CFFParser_parseHeader() {
  6790. var bytes = this.bytes;
  6791. var bytesLength = bytes.length;
  6792. var offset = 0;
  6793. // Prevent an infinite loop, by checking that the offset is within the
  6794. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  6795. while (offset < bytesLength && bytes[offset] !== 1) {
  6796. ++offset;
  6797. }
  6798. if (offset >= bytesLength) {
  6799. error('Invalid CFF header');
  6800. } else if (offset !== 0) {
  6801. info('cff data is shifted');
  6802. bytes = bytes.subarray(offset);
  6803. this.bytes = bytes;
  6804. }
  6805. var major = bytes[0];
  6806. var minor = bytes[1];
  6807. var hdrSize = bytes[2];
  6808. var offSize = bytes[3];
  6809. var header = new CFFHeader(major, minor, hdrSize, offSize);
  6810. return {
  6811. obj: header,
  6812. endPos: hdrSize
  6813. };
  6814. },
  6815. parseDict: function CFFParser_parseDict(dict) {
  6816. var pos = 0;
  6817. function parseOperand() {
  6818. var value = dict[pos++];
  6819. if (value === 30) {
  6820. return parseFloatOperand();
  6821. } else if (value === 28) {
  6822. value = dict[pos++];
  6823. value = (value << 24 | dict[pos++] << 16) >> 16;
  6824. return value;
  6825. } else if (value === 29) {
  6826. value = dict[pos++];
  6827. value = value << 8 | dict[pos++];
  6828. value = value << 8 | dict[pos++];
  6829. value = value << 8 | dict[pos++];
  6830. return value;
  6831. } else if (value >= 32 && value <= 246) {
  6832. return value - 139;
  6833. } else if (value >= 247 && value <= 250) {
  6834. return (value - 247) * 256 + dict[pos++] + 108;
  6835. } else if (value >= 251 && value <= 254) {
  6836. return -((value - 251) * 256) - dict[pos++] - 108;
  6837. } else {
  6838. error('255 is not a valid DICT command');
  6839. }
  6840. return -1;
  6841. }
  6842. function parseFloatOperand() {
  6843. var str = '';
  6844. var eof = 15;
  6845. var lookup = [
  6846. '0',
  6847. '1',
  6848. '2',
  6849. '3',
  6850. '4',
  6851. '5',
  6852. '6',
  6853. '7',
  6854. '8',
  6855. '9',
  6856. '.',
  6857. 'E',
  6858. 'E-',
  6859. null,
  6860. '-'
  6861. ];
  6862. var length = dict.length;
  6863. while (pos < length) {
  6864. var b = dict[pos++];
  6865. var b1 = b >> 4;
  6866. var b2 = b & 15;
  6867. if (b1 === eof) {
  6868. break;
  6869. }
  6870. str += lookup[b1];
  6871. if (b2 === eof) {
  6872. break;
  6873. }
  6874. str += lookup[b2];
  6875. }
  6876. return parseFloat(str);
  6877. }
  6878. var operands = [];
  6879. var entries = [];
  6880. pos = 0;
  6881. var end = dict.length;
  6882. while (pos < end) {
  6883. var b = dict[pos];
  6884. if (b <= 21) {
  6885. if (b === 12) {
  6886. b = b << 8 | dict[++pos];
  6887. }
  6888. entries.push([
  6889. b,
  6890. operands
  6891. ]);
  6892. operands = [];
  6893. ++pos;
  6894. } else {
  6895. operands.push(parseOperand());
  6896. }
  6897. }
  6898. return entries;
  6899. },
  6900. parseIndex: function CFFParser_parseIndex(pos) {
  6901. var cffIndex = new CFFIndex();
  6902. var bytes = this.bytes;
  6903. var count = bytes[pos++] << 8 | bytes[pos++];
  6904. var offsets = [];
  6905. var end = pos;
  6906. var i, ii;
  6907. if (count !== 0) {
  6908. var offsetSize = bytes[pos++];
  6909. // add 1 for offset to determine size of last object
  6910. var startPos = pos + (count + 1) * offsetSize - 1;
  6911. for (i = 0, ii = count + 1; i < ii; ++i) {
  6912. var offset = 0;
  6913. for (var j = 0; j < offsetSize; ++j) {
  6914. offset <<= 8;
  6915. offset += bytes[pos++];
  6916. }
  6917. offsets.push(startPos + offset);
  6918. }
  6919. end = offsets[count];
  6920. }
  6921. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  6922. var offsetStart = offsets[i];
  6923. var offsetEnd = offsets[i + 1];
  6924. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  6925. }
  6926. return {
  6927. obj: cffIndex,
  6928. endPos: end
  6929. };
  6930. },
  6931. parseNameIndex: function CFFParser_parseNameIndex(index) {
  6932. var names = [];
  6933. for (var i = 0, ii = index.count; i < ii; ++i) {
  6934. var name = index.get(i);
  6935. // OTS doesn't allow names to be over 127 characters.
  6936. var length = Math.min(name.length, 127);
  6937. var data = [];
  6938. // OTS also only permits certain characters in the name.
  6939. for (var j = 0; j < length; ++j) {
  6940. var c = name[j];
  6941. if (j === 0 && c === 0) {
  6942. data[j] = c;
  6943. continue;
  6944. }
  6945. if (c < 33 || c > 126 || c === 91 || /* [ */
  6946. c === 93 || /* ] */
  6947. c === 40 || /* ( */
  6948. c === 41 || /* ) */
  6949. c === 123 || /* { */
  6950. c === 125 || /* } */
  6951. c === 60 || /* < */
  6952. c === 62 || /* > */
  6953. c === 47 || /* / */
  6954. c === 37 || /* % */
  6955. c === 35)
  6956. /* # */
  6957. {
  6958. data[j] = 95;
  6959. continue;
  6960. }
  6961. data[j] = c;
  6962. }
  6963. names.push(bytesToString(data));
  6964. }
  6965. return names;
  6966. },
  6967. parseStringIndex: function CFFParser_parseStringIndex(index) {
  6968. var strings = new CFFStrings();
  6969. for (var i = 0, ii = index.count; i < ii; ++i) {
  6970. var data = index.get(i);
  6971. strings.add(bytesToString(data));
  6972. }
  6973. return strings;
  6974. },
  6975. createDict: function CFFParser_createDict(Type, dict, strings) {
  6976. var cffDict = new Type(strings);
  6977. for (var i = 0, ii = dict.length; i < ii; ++i) {
  6978. var pair = dict[i];
  6979. var key = pair[0];
  6980. var value = pair[1];
  6981. cffDict.setByKey(key, value);
  6982. }
  6983. return cffDict;
  6984. },
  6985. parseCharString: function CFFParser_parseCharString(state, data, localSubrIndex, globalSubrIndex) {
  6986. if (state.callDepth > MAX_SUBR_NESTING) {
  6987. return false;
  6988. }
  6989. var stackSize = state.stackSize;
  6990. var stack = state.stack;
  6991. var length = data.length;
  6992. for (var j = 0; j < length;) {
  6993. var value = data[j++];
  6994. var validationCommand = null;
  6995. if (value === 12) {
  6996. var q = data[j++];
  6997. if (q === 0) {
  6998. // The CFF specification state that the 'dotsection' command
  6999. // (12, 0) is deprecated and treated as a no-op, but all Type2
  7000. // charstrings processors should support them. Unfortunately
  7001. // the font sanitizer don't. As a workaround the sequence (12, 0)
  7002. // is replaced by a useless (0, hmoveto).
  7003. data[j - 2] = 139;
  7004. data[j - 1] = 22;
  7005. stackSize = 0;
  7006. } else {
  7007. validationCommand = CharstringValidationData12[q];
  7008. }
  7009. } else if (value === 28) {
  7010. // number (16 bit)
  7011. stack[stackSize] = (data[j] << 24 | data[j + 1] << 16) >> 16;
  7012. j += 2;
  7013. stackSize++;
  7014. } else if (value === 14) {
  7015. if (stackSize >= 4) {
  7016. stackSize -= 4;
  7017. if (this.seacAnalysisEnabled) {
  7018. state.seac = stack.slice(stackSize, stackSize + 4);
  7019. return false;
  7020. }
  7021. }
  7022. validationCommand = CharstringValidationData[value];
  7023. } else if (value >= 32 && value <= 246) {
  7024. // number
  7025. stack[stackSize] = value - 139;
  7026. stackSize++;
  7027. } else if (value >= 247 && value <= 254) {
  7028. // number (+1 bytes)
  7029. stack[stackSize] = value < 251 ? (value - 247 << 8) + data[j] + 108 : -(value - 251 << 8) - data[j] - 108;
  7030. j++;
  7031. stackSize++;
  7032. } else if (value === 255) {
  7033. // number (32 bit)
  7034. stack[stackSize] = (data[j] << 24 | data[j + 1] << 16 | data[j + 2] << 8 | data[j + 3]) / 65536;
  7035. j += 4;
  7036. stackSize++;
  7037. } else if (value === 19 || value === 20) {
  7038. state.hints += stackSize >> 1;
  7039. // skipping right amount of hints flag data
  7040. j += state.hints + 7 >> 3;
  7041. stackSize %= 2;
  7042. validationCommand = CharstringValidationData[value];
  7043. } else if (value === 10 || value === 29) {
  7044. var subrsIndex;
  7045. if (value === 10) {
  7046. subrsIndex = localSubrIndex;
  7047. } else {
  7048. subrsIndex = globalSubrIndex;
  7049. }
  7050. if (!subrsIndex) {
  7051. validationCommand = CharstringValidationData[value];
  7052. warn('Missing subrsIndex for ' + validationCommand.id);
  7053. return false;
  7054. }
  7055. var bias = 32768;
  7056. if (subrsIndex.count < 1240) {
  7057. bias = 107;
  7058. } else if (subrsIndex.count < 33900) {
  7059. bias = 1131;
  7060. }
  7061. var subrNumber = stack[--stackSize] + bias;
  7062. if (subrNumber < 0 || subrNumber >= subrsIndex.count) {
  7063. validationCommand = CharstringValidationData[value];
  7064. warn('Out of bounds subrIndex for ' + validationCommand.id);
  7065. return false;
  7066. }
  7067. state.stackSize = stackSize;
  7068. state.callDepth++;
  7069. var valid = this.parseCharString(state, subrsIndex.get(subrNumber), localSubrIndex, globalSubrIndex);
  7070. if (!valid) {
  7071. return false;
  7072. }
  7073. state.callDepth--;
  7074. stackSize = state.stackSize;
  7075. continue;
  7076. } else if (value === 11) {
  7077. state.stackSize = stackSize;
  7078. return true;
  7079. } else {
  7080. validationCommand = CharstringValidationData[value];
  7081. }
  7082. if (validationCommand) {
  7083. if (validationCommand.stem) {
  7084. state.hints += stackSize >> 1;
  7085. }
  7086. if ('min' in validationCommand) {
  7087. if (!state.undefStack && stackSize < validationCommand.min) {
  7088. warn('Not enough parameters for ' + validationCommand.id + '; actual: ' + stackSize + ', expected: ' + validationCommand.min);
  7089. return false;
  7090. }
  7091. }
  7092. if (state.firstStackClearing && validationCommand.stackClearing) {
  7093. state.firstStackClearing = false;
  7094. // the optional character width can be found before the first
  7095. // stack-clearing command arguments
  7096. stackSize -= validationCommand.min;
  7097. if (stackSize >= 2 && validationCommand.stem) {
  7098. // there are even amount of arguments for stem commands
  7099. stackSize %= 2;
  7100. } else if (stackSize > 1) {
  7101. warn('Found too many parameters for stack-clearing command');
  7102. }
  7103. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  7104. state.width = stack[stackSize - 1];
  7105. }
  7106. }
  7107. if ('stackDelta' in validationCommand) {
  7108. if ('stackFn' in validationCommand) {
  7109. validationCommand.stackFn(stack, stackSize);
  7110. }
  7111. stackSize += validationCommand.stackDelta;
  7112. } else if (validationCommand.stackClearing) {
  7113. stackSize = 0;
  7114. } else if (validationCommand.resetStack) {
  7115. stackSize = 0;
  7116. state.undefStack = false;
  7117. } else if (validationCommand.undefStack) {
  7118. stackSize = 0;
  7119. state.undefStack = true;
  7120. state.firstStackClearing = false;
  7121. }
  7122. }
  7123. }
  7124. state.stackSize = stackSize;
  7125. return true;
  7126. },
  7127. parseCharStrings: function CFFParser_parseCharStrings(charStrings, localSubrIndex, globalSubrIndex, fdSelect, fdArray) {
  7128. var seacs = [];
  7129. var widths = [];
  7130. var count = charStrings.count;
  7131. for (var i = 0; i < count; i++) {
  7132. var charstring = charStrings.get(i);
  7133. var state = {
  7134. callDepth: 0,
  7135. stackSize: 0,
  7136. stack: [],
  7137. undefStack: true,
  7138. hints: 0,
  7139. firstStackClearing: true,
  7140. seac: null,
  7141. width: null
  7142. };
  7143. var valid = true;
  7144. var localSubrToUse = null;
  7145. if (fdSelect && fdArray.length) {
  7146. var fdIndex = fdSelect.getFDIndex(i);
  7147. if (fdIndex === -1) {
  7148. warn('Glyph index is not in fd select.');
  7149. valid = false;
  7150. }
  7151. if (fdIndex >= fdArray.length) {
  7152. warn('Invalid fd index for glyph index.');
  7153. valid = false;
  7154. }
  7155. if (valid) {
  7156. localSubrToUse = fdArray[fdIndex].privateDict.subrsIndex;
  7157. }
  7158. } else if (localSubrIndex) {
  7159. localSubrToUse = localSubrIndex;
  7160. }
  7161. if (valid) {
  7162. valid = this.parseCharString(state, charstring, localSubrToUse, globalSubrIndex);
  7163. }
  7164. if (state.width !== null) {
  7165. widths[i] = state.width;
  7166. }
  7167. if (state.seac !== null) {
  7168. seacs[i] = state.seac;
  7169. }
  7170. if (!valid) {
  7171. // resetting invalid charstring to single 'endchar'
  7172. charStrings.set(i, new Uint8Array([14]));
  7173. }
  7174. }
  7175. return {
  7176. charStrings: charStrings,
  7177. seacs: seacs,
  7178. widths: widths
  7179. };
  7180. },
  7181. emptyPrivateDictionary: function CFFParser_emptyPrivateDictionary(parentDict) {
  7182. var privateDict = this.createDict(CFFPrivateDict, [], parentDict.strings);
  7183. parentDict.setByKey(18, [
  7184. 0,
  7185. 0
  7186. ]);
  7187. parentDict.privateDict = privateDict;
  7188. },
  7189. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  7190. // no private dict, do nothing
  7191. if (!parentDict.hasName('Private')) {
  7192. this.emptyPrivateDictionary(parentDict);
  7193. return;
  7194. }
  7195. var privateOffset = parentDict.getByName('Private');
  7196. // make sure the params are formatted correctly
  7197. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  7198. parentDict.removeByName('Private');
  7199. return;
  7200. }
  7201. var size = privateOffset[0];
  7202. var offset = privateOffset[1];
  7203. // remove empty dicts or ones that refer to invalid location
  7204. if (size === 0 || offset >= this.bytes.length) {
  7205. this.emptyPrivateDictionary(parentDict);
  7206. return;
  7207. }
  7208. var privateDictEnd = offset + size;
  7209. var dictData = this.bytes.subarray(offset, privateDictEnd);
  7210. var dict = this.parseDict(dictData);
  7211. var privateDict = this.createDict(CFFPrivateDict, dict, parentDict.strings);
  7212. parentDict.privateDict = privateDict;
  7213. // Parse the Subrs index also since it's relative to the private dict.
  7214. if (!privateDict.getByName('Subrs')) {
  7215. return;
  7216. }
  7217. var subrsOffset = privateDict.getByName('Subrs');
  7218. var relativeOffset = offset + subrsOffset;
  7219. // Validate the offset.
  7220. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  7221. this.emptyPrivateDictionary(parentDict);
  7222. return;
  7223. }
  7224. var subrsIndex = this.parseIndex(relativeOffset);
  7225. privateDict.subrsIndex = subrsIndex.obj;
  7226. },
  7227. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  7228. if (pos === 0) {
  7229. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE, ISOAdobeCharset);
  7230. } else if (pos === 1) {
  7231. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT, ExpertCharset);
  7232. } else if (pos === 2) {
  7233. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET, ExpertSubsetCharset);
  7234. }
  7235. var bytes = this.bytes;
  7236. var start = pos;
  7237. var format = bytes[pos++];
  7238. var charset = ['.notdef'];
  7239. var id, count, i;
  7240. // subtract 1 for the .notdef glyph
  7241. length -= 1;
  7242. switch (format) {
  7243. case 0:
  7244. for (i = 0; i < length; i++) {
  7245. id = bytes[pos++] << 8 | bytes[pos++];
  7246. charset.push(cid ? id : strings.get(id));
  7247. }
  7248. break;
  7249. case 1:
  7250. while (charset.length <= length) {
  7251. id = bytes[pos++] << 8 | bytes[pos++];
  7252. count = bytes[pos++];
  7253. for (i = 0; i <= count; i++) {
  7254. charset.push(cid ? id++ : strings.get(id++));
  7255. }
  7256. }
  7257. break;
  7258. case 2:
  7259. while (charset.length <= length) {
  7260. id = bytes[pos++] << 8 | bytes[pos++];
  7261. count = bytes[pos++] << 8 | bytes[pos++];
  7262. for (i = 0; i <= count; i++) {
  7263. charset.push(cid ? id++ : strings.get(id++));
  7264. }
  7265. }
  7266. break;
  7267. default:
  7268. error('Unknown charset format');
  7269. }
  7270. // Raw won't be needed if we actually compile the charset.
  7271. var end = pos;
  7272. var raw = bytes.subarray(start, end);
  7273. return new CFFCharset(false, format, charset, raw);
  7274. },
  7275. parseEncoding: function CFFParser_parseEncoding(pos, properties, strings, charset) {
  7276. var encoding = Object.create(null);
  7277. var bytes = this.bytes;
  7278. var predefined = false;
  7279. var hasSupplement = false;
  7280. var format, i, ii;
  7281. var raw = null;
  7282. function readSupplement() {
  7283. var supplementsCount = bytes[pos++];
  7284. for (i = 0; i < supplementsCount; i++) {
  7285. var code = bytes[pos++];
  7286. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  7287. encoding[code] = charset.indexOf(strings.get(sid));
  7288. }
  7289. }
  7290. if (pos === 0 || pos === 1) {
  7291. predefined = true;
  7292. format = pos;
  7293. var baseEncoding = pos ? ExpertEncoding : StandardEncoding;
  7294. for (i = 0, ii = charset.length; i < ii; i++) {
  7295. var index = baseEncoding.indexOf(charset[i]);
  7296. if (index !== -1) {
  7297. encoding[index] = i;
  7298. }
  7299. }
  7300. } else {
  7301. var dataStart = pos;
  7302. format = bytes[pos++];
  7303. switch (format & 0x7f) {
  7304. case 0:
  7305. var glyphsCount = bytes[pos++];
  7306. for (i = 1; i <= glyphsCount; i++) {
  7307. encoding[bytes[pos++]] = i;
  7308. }
  7309. break;
  7310. case 1:
  7311. var rangesCount = bytes[pos++];
  7312. var gid = 1;
  7313. for (i = 0; i < rangesCount; i++) {
  7314. var start = bytes[pos++];
  7315. var left = bytes[pos++];
  7316. for (var j = start; j <= start + left; j++) {
  7317. encoding[j] = gid++;
  7318. }
  7319. }
  7320. break;
  7321. default:
  7322. error('Unknown encoding format: ' + format + ' in CFF');
  7323. break;
  7324. }
  7325. var dataEnd = pos;
  7326. if (format & 0x80) {
  7327. // The font sanitizer does not support CFF encoding with a
  7328. // supplement, since the encoding is not really used to map
  7329. // between gid to glyph, let's overwrite what is declared in
  7330. // the top dictionary to let the sanitizer think the font use
  7331. // StandardEncoding, that's a lie but that's ok.
  7332. bytes[dataStart] &= 0x7f;
  7333. readSupplement();
  7334. hasSupplement = true;
  7335. }
  7336. raw = bytes.subarray(dataStart, dataEnd);
  7337. }
  7338. format = format & 0x7f;
  7339. return new CFFEncoding(predefined, format, encoding, raw);
  7340. },
  7341. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  7342. var start = pos;
  7343. var bytes = this.bytes;
  7344. var format = bytes[pos++];
  7345. var fdSelect = [], rawBytes;
  7346. var i, invalidFirstGID = false;
  7347. switch (format) {
  7348. case 0:
  7349. for (i = 0; i < length; ++i) {
  7350. var id = bytes[pos++];
  7351. fdSelect.push(id);
  7352. }
  7353. rawBytes = bytes.subarray(start, pos);
  7354. break;
  7355. case 3:
  7356. var rangesCount = bytes[pos++] << 8 | bytes[pos++];
  7357. for (i = 0; i < rangesCount; ++i) {
  7358. var first = bytes[pos++] << 8 | bytes[pos++];
  7359. if (i === 0 && first !== 0) {
  7360. warn('parseFDSelect: The first range must have a first GID of 0' + ' -- trying to recover.');
  7361. invalidFirstGID = true;
  7362. first = 0;
  7363. }
  7364. var fdIndex = bytes[pos++];
  7365. var next = bytes[pos] << 8 | bytes[pos + 1];
  7366. for (var j = first; j < next; ++j) {
  7367. fdSelect.push(fdIndex);
  7368. }
  7369. }
  7370. // Advance past the sentinel(next).
  7371. pos += 2;
  7372. rawBytes = bytes.subarray(start, pos);
  7373. if (invalidFirstGID) {
  7374. rawBytes[3] = rawBytes[4] = 0;
  7375. }
  7376. // Adjust the first range, first GID.
  7377. break;
  7378. default:
  7379. error('parseFDSelect: Unknown format "' + format + '".');
  7380. break;
  7381. }
  7382. assert(fdSelect.length === length, 'parseFDSelect: Invalid font data.');
  7383. return new CFFFDSelect(fdSelect, rawBytes);
  7384. }
  7385. };
  7386. return CFFParser;
  7387. }();
  7388. // Compact Font Format
  7389. var CFF = function CFFClosure() {
  7390. function CFF() {
  7391. this.header = null;
  7392. this.names = [];
  7393. this.topDict = null;
  7394. this.strings = new CFFStrings();
  7395. this.globalSubrIndex = null;
  7396. // The following could really be per font, but since we only have one font
  7397. // store them here.
  7398. this.encoding = null;
  7399. this.charset = null;
  7400. this.charStrings = null;
  7401. this.fdArray = [];
  7402. this.fdSelect = null;
  7403. this.isCIDFont = false;
  7404. }
  7405. return CFF;
  7406. }();
  7407. var CFFHeader = function CFFHeaderClosure() {
  7408. function CFFHeader(major, minor, hdrSize, offSize) {
  7409. this.major = major;
  7410. this.minor = minor;
  7411. this.hdrSize = hdrSize;
  7412. this.offSize = offSize;
  7413. }
  7414. return CFFHeader;
  7415. }();
  7416. var CFFStrings = function CFFStringsClosure() {
  7417. function CFFStrings() {
  7418. this.strings = [];
  7419. }
  7420. CFFStrings.prototype = {
  7421. get: function CFFStrings_get(index) {
  7422. if (index >= 0 && index <= 390) {
  7423. return CFFStandardStrings[index];
  7424. }
  7425. if (index - 391 <= this.strings.length) {
  7426. return this.strings[index - 391];
  7427. }
  7428. return CFFStandardStrings[0];
  7429. },
  7430. add: function CFFStrings_add(value) {
  7431. this.strings.push(value);
  7432. },
  7433. get count() {
  7434. return this.strings.length;
  7435. }
  7436. };
  7437. return CFFStrings;
  7438. }();
  7439. var CFFIndex = function CFFIndexClosure() {
  7440. function CFFIndex() {
  7441. this.objects = [];
  7442. this.length = 0;
  7443. }
  7444. CFFIndex.prototype = {
  7445. add: function CFFIndex_add(data) {
  7446. this.length += data.length;
  7447. this.objects.push(data);
  7448. },
  7449. set: function CFFIndex_set(index, data) {
  7450. this.length += data.length - this.objects[index].length;
  7451. this.objects[index] = data;
  7452. },
  7453. get: function CFFIndex_get(index) {
  7454. return this.objects[index];
  7455. },
  7456. get count() {
  7457. return this.objects.length;
  7458. }
  7459. };
  7460. return CFFIndex;
  7461. }();
  7462. var CFFDict = function CFFDictClosure() {
  7463. function CFFDict(tables, strings) {
  7464. this.keyToNameMap = tables.keyToNameMap;
  7465. this.nameToKeyMap = tables.nameToKeyMap;
  7466. this.defaults = tables.defaults;
  7467. this.types = tables.types;
  7468. this.opcodes = tables.opcodes;
  7469. this.order = tables.order;
  7470. this.strings = strings;
  7471. this.values = Object.create(null);
  7472. }
  7473. CFFDict.prototype = {
  7474. // value should always be an array
  7475. setByKey: function CFFDict_setByKey(key, value) {
  7476. if (!(key in this.keyToNameMap)) {
  7477. return false;
  7478. }
  7479. // ignore empty values
  7480. if (value.length === 0) {
  7481. return true;
  7482. }
  7483. var type = this.types[key];
  7484. // remove the array wrapping these types of values
  7485. if (type === 'num' || type === 'sid' || type === 'offset') {
  7486. value = value[0];
  7487. // Ignore invalid values (fixes bug 1068432).
  7488. if (isNaN(value)) {
  7489. warn('Invalid CFFDict value: ' + value + ', for key: ' + key + '.');
  7490. return true;
  7491. }
  7492. }
  7493. this.values[key] = value;
  7494. return true;
  7495. },
  7496. setByName: function CFFDict_setByName(name, value) {
  7497. if (!(name in this.nameToKeyMap)) {
  7498. error('Invalid dictionary name "' + name + '"');
  7499. }
  7500. this.values[this.nameToKeyMap[name]] = value;
  7501. },
  7502. hasName: function CFFDict_hasName(name) {
  7503. return this.nameToKeyMap[name] in this.values;
  7504. },
  7505. getByName: function CFFDict_getByName(name) {
  7506. if (!(name in this.nameToKeyMap)) {
  7507. error('Invalid dictionary name "' + name + '"');
  7508. }
  7509. var key = this.nameToKeyMap[name];
  7510. if (!(key in this.values)) {
  7511. return this.defaults[key];
  7512. }
  7513. return this.values[key];
  7514. },
  7515. removeByName: function CFFDict_removeByName(name) {
  7516. delete this.values[this.nameToKeyMap[name]];
  7517. }
  7518. };
  7519. CFFDict.createTables = function CFFDict_createTables(layout) {
  7520. var tables = {
  7521. keyToNameMap: {},
  7522. nameToKeyMap: {},
  7523. defaults: {},
  7524. types: {},
  7525. opcodes: {},
  7526. order: []
  7527. };
  7528. for (var i = 0, ii = layout.length; i < ii; ++i) {
  7529. var entry = layout[i];
  7530. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  7531. tables.keyToNameMap[key] = entry[1];
  7532. tables.nameToKeyMap[entry[1]] = key;
  7533. tables.types[key] = entry[2];
  7534. tables.defaults[key] = entry[3];
  7535. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  7536. tables.order.push(key);
  7537. }
  7538. return tables;
  7539. };
  7540. return CFFDict;
  7541. }();
  7542. var CFFTopDict = function CFFTopDictClosure() {
  7543. var layout = [
  7544. [
  7545. [
  7546. 12,
  7547. 30
  7548. ],
  7549. 'ROS',
  7550. [
  7551. 'sid',
  7552. 'sid',
  7553. 'num'
  7554. ],
  7555. null
  7556. ],
  7557. [
  7558. [
  7559. 12,
  7560. 20
  7561. ],
  7562. 'SyntheticBase',
  7563. 'num',
  7564. null
  7565. ],
  7566. [
  7567. 0,
  7568. 'version',
  7569. 'sid',
  7570. null
  7571. ],
  7572. [
  7573. 1,
  7574. 'Notice',
  7575. 'sid',
  7576. null
  7577. ],
  7578. [
  7579. [
  7580. 12,
  7581. 0
  7582. ],
  7583. 'Copyright',
  7584. 'sid',
  7585. null
  7586. ],
  7587. [
  7588. 2,
  7589. 'FullName',
  7590. 'sid',
  7591. null
  7592. ],
  7593. [
  7594. 3,
  7595. 'FamilyName',
  7596. 'sid',
  7597. null
  7598. ],
  7599. [
  7600. 4,
  7601. 'Weight',
  7602. 'sid',
  7603. null
  7604. ],
  7605. [
  7606. [
  7607. 12,
  7608. 1
  7609. ],
  7610. 'isFixedPitch',
  7611. 'num',
  7612. 0
  7613. ],
  7614. [
  7615. [
  7616. 12,
  7617. 2
  7618. ],
  7619. 'ItalicAngle',
  7620. 'num',
  7621. 0
  7622. ],
  7623. [
  7624. [
  7625. 12,
  7626. 3
  7627. ],
  7628. 'UnderlinePosition',
  7629. 'num',
  7630. -100
  7631. ],
  7632. [
  7633. [
  7634. 12,
  7635. 4
  7636. ],
  7637. 'UnderlineThickness',
  7638. 'num',
  7639. 50
  7640. ],
  7641. [
  7642. [
  7643. 12,
  7644. 5
  7645. ],
  7646. 'PaintType',
  7647. 'num',
  7648. 0
  7649. ],
  7650. [
  7651. [
  7652. 12,
  7653. 6
  7654. ],
  7655. 'CharstringType',
  7656. 'num',
  7657. 2
  7658. ],
  7659. [
  7660. [
  7661. 12,
  7662. 7
  7663. ],
  7664. 'FontMatrix',
  7665. [
  7666. 'num',
  7667. 'num',
  7668. 'num',
  7669. 'num',
  7670. 'num',
  7671. 'num'
  7672. ],
  7673. [
  7674. 0.001,
  7675. 0,
  7676. 0,
  7677. 0.001,
  7678. 0,
  7679. 0
  7680. ]
  7681. ],
  7682. [
  7683. 13,
  7684. 'UniqueID',
  7685. 'num',
  7686. null
  7687. ],
  7688. [
  7689. 5,
  7690. 'FontBBox',
  7691. [
  7692. 'num',
  7693. 'num',
  7694. 'num',
  7695. 'num'
  7696. ],
  7697. [
  7698. 0,
  7699. 0,
  7700. 0,
  7701. 0
  7702. ]
  7703. ],
  7704. [
  7705. [
  7706. 12,
  7707. 8
  7708. ],
  7709. 'StrokeWidth',
  7710. 'num',
  7711. 0
  7712. ],
  7713. [
  7714. 14,
  7715. 'XUID',
  7716. 'array',
  7717. null
  7718. ],
  7719. [
  7720. 15,
  7721. 'charset',
  7722. 'offset',
  7723. 0
  7724. ],
  7725. [
  7726. 16,
  7727. 'Encoding',
  7728. 'offset',
  7729. 0
  7730. ],
  7731. [
  7732. 17,
  7733. 'CharStrings',
  7734. 'offset',
  7735. 0
  7736. ],
  7737. [
  7738. 18,
  7739. 'Private',
  7740. [
  7741. 'offset',
  7742. 'offset'
  7743. ],
  7744. null
  7745. ],
  7746. [
  7747. [
  7748. 12,
  7749. 21
  7750. ],
  7751. 'PostScript',
  7752. 'sid',
  7753. null
  7754. ],
  7755. [
  7756. [
  7757. 12,
  7758. 22
  7759. ],
  7760. 'BaseFontName',
  7761. 'sid',
  7762. null
  7763. ],
  7764. [
  7765. [
  7766. 12,
  7767. 23
  7768. ],
  7769. 'BaseFontBlend',
  7770. 'delta',
  7771. null
  7772. ],
  7773. [
  7774. [
  7775. 12,
  7776. 31
  7777. ],
  7778. 'CIDFontVersion',
  7779. 'num',
  7780. 0
  7781. ],
  7782. [
  7783. [
  7784. 12,
  7785. 32
  7786. ],
  7787. 'CIDFontRevision',
  7788. 'num',
  7789. 0
  7790. ],
  7791. [
  7792. [
  7793. 12,
  7794. 33
  7795. ],
  7796. 'CIDFontType',
  7797. 'num',
  7798. 0
  7799. ],
  7800. [
  7801. [
  7802. 12,
  7803. 34
  7804. ],
  7805. 'CIDCount',
  7806. 'num',
  7807. 8720
  7808. ],
  7809. [
  7810. [
  7811. 12,
  7812. 35
  7813. ],
  7814. 'UIDBase',
  7815. 'num',
  7816. null
  7817. ],
  7818. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  7819. // before FDArray.
  7820. [
  7821. [
  7822. 12,
  7823. 37
  7824. ],
  7825. 'FDSelect',
  7826. 'offset',
  7827. null
  7828. ],
  7829. [
  7830. [
  7831. 12,
  7832. 36
  7833. ],
  7834. 'FDArray',
  7835. 'offset',
  7836. null
  7837. ],
  7838. [
  7839. [
  7840. 12,
  7841. 38
  7842. ],
  7843. 'FontName',
  7844. 'sid',
  7845. null
  7846. ]
  7847. ];
  7848. var tables = null;
  7849. function CFFTopDict(strings) {
  7850. if (tables === null) {
  7851. tables = CFFDict.createTables(layout);
  7852. }
  7853. CFFDict.call(this, tables, strings);
  7854. this.privateDict = null;
  7855. }
  7856. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  7857. return CFFTopDict;
  7858. }();
  7859. var CFFPrivateDict = function CFFPrivateDictClosure() {
  7860. var layout = [
  7861. [
  7862. 6,
  7863. 'BlueValues',
  7864. 'delta',
  7865. null
  7866. ],
  7867. [
  7868. 7,
  7869. 'OtherBlues',
  7870. 'delta',
  7871. null
  7872. ],
  7873. [
  7874. 8,
  7875. 'FamilyBlues',
  7876. 'delta',
  7877. null
  7878. ],
  7879. [
  7880. 9,
  7881. 'FamilyOtherBlues',
  7882. 'delta',
  7883. null
  7884. ],
  7885. [
  7886. [
  7887. 12,
  7888. 9
  7889. ],
  7890. 'BlueScale',
  7891. 'num',
  7892. 0.039625
  7893. ],
  7894. [
  7895. [
  7896. 12,
  7897. 10
  7898. ],
  7899. 'BlueShift',
  7900. 'num',
  7901. 7
  7902. ],
  7903. [
  7904. [
  7905. 12,
  7906. 11
  7907. ],
  7908. 'BlueFuzz',
  7909. 'num',
  7910. 1
  7911. ],
  7912. [
  7913. 10,
  7914. 'StdHW',
  7915. 'num',
  7916. null
  7917. ],
  7918. [
  7919. 11,
  7920. 'StdVW',
  7921. 'num',
  7922. null
  7923. ],
  7924. [
  7925. [
  7926. 12,
  7927. 12
  7928. ],
  7929. 'StemSnapH',
  7930. 'delta',
  7931. null
  7932. ],
  7933. [
  7934. [
  7935. 12,
  7936. 13
  7937. ],
  7938. 'StemSnapV',
  7939. 'delta',
  7940. null
  7941. ],
  7942. [
  7943. [
  7944. 12,
  7945. 14
  7946. ],
  7947. 'ForceBold',
  7948. 'num',
  7949. 0
  7950. ],
  7951. [
  7952. [
  7953. 12,
  7954. 17
  7955. ],
  7956. 'LanguageGroup',
  7957. 'num',
  7958. 0
  7959. ],
  7960. [
  7961. [
  7962. 12,
  7963. 18
  7964. ],
  7965. 'ExpansionFactor',
  7966. 'num',
  7967. 0.06
  7968. ],
  7969. [
  7970. [
  7971. 12,
  7972. 19
  7973. ],
  7974. 'initialRandomSeed',
  7975. 'num',
  7976. 0
  7977. ],
  7978. [
  7979. 20,
  7980. 'defaultWidthX',
  7981. 'num',
  7982. 0
  7983. ],
  7984. [
  7985. 21,
  7986. 'nominalWidthX',
  7987. 'num',
  7988. 0
  7989. ],
  7990. [
  7991. 19,
  7992. 'Subrs',
  7993. 'offset',
  7994. null
  7995. ]
  7996. ];
  7997. var tables = null;
  7998. function CFFPrivateDict(strings) {
  7999. if (tables === null) {
  8000. tables = CFFDict.createTables(layout);
  8001. }
  8002. CFFDict.call(this, tables, strings);
  8003. this.subrsIndex = null;
  8004. }
  8005. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  8006. return CFFPrivateDict;
  8007. }();
  8008. var CFFCharsetPredefinedTypes = {
  8009. ISO_ADOBE: 0,
  8010. EXPERT: 1,
  8011. EXPERT_SUBSET: 2
  8012. };
  8013. var CFFCharset = function CFFCharsetClosure() {
  8014. function CFFCharset(predefined, format, charset, raw) {
  8015. this.predefined = predefined;
  8016. this.format = format;
  8017. this.charset = charset;
  8018. this.raw = raw;
  8019. }
  8020. return CFFCharset;
  8021. }();
  8022. var CFFEncoding = function CFFEncodingClosure() {
  8023. function CFFEncoding(predefined, format, encoding, raw) {
  8024. this.predefined = predefined;
  8025. this.format = format;
  8026. this.encoding = encoding;
  8027. this.raw = raw;
  8028. }
  8029. return CFFEncoding;
  8030. }();
  8031. var CFFFDSelect = function CFFFDSelectClosure() {
  8032. function CFFFDSelect(fdSelect, raw) {
  8033. this.fdSelect = fdSelect;
  8034. this.raw = raw;
  8035. }
  8036. CFFFDSelect.prototype = {
  8037. getFDIndex: function CFFFDSelect_get(glyphIndex) {
  8038. if (glyphIndex < 0 || glyphIndex >= this.fdSelect.length) {
  8039. return -1;
  8040. }
  8041. return this.fdSelect[glyphIndex];
  8042. }
  8043. };
  8044. return CFFFDSelect;
  8045. }();
  8046. // Helper class to keep track of where an offset is within the data and helps
  8047. // filling in that offset once it's known.
  8048. var CFFOffsetTracker = function CFFOffsetTrackerClosure() {
  8049. function CFFOffsetTracker() {
  8050. this.offsets = Object.create(null);
  8051. }
  8052. CFFOffsetTracker.prototype = {
  8053. isTracking: function CFFOffsetTracker_isTracking(key) {
  8054. return key in this.offsets;
  8055. },
  8056. track: function CFFOffsetTracker_track(key, location) {
  8057. if (key in this.offsets) {
  8058. error('Already tracking location of ' + key);
  8059. }
  8060. this.offsets[key] = location;
  8061. },
  8062. offset: function CFFOffsetTracker_offset(value) {
  8063. for (var key in this.offsets) {
  8064. this.offsets[key] += value;
  8065. }
  8066. },
  8067. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key, values, output) {
  8068. if (!(key in this.offsets)) {
  8069. error('Not tracking location of ' + key);
  8070. }
  8071. var data = output.data;
  8072. var dataOffset = this.offsets[key];
  8073. var size = 5;
  8074. for (var i = 0, ii = values.length; i < ii; ++i) {
  8075. var offset0 = i * size + dataOffset;
  8076. var offset1 = offset0 + 1;
  8077. var offset2 = offset0 + 2;
  8078. var offset3 = offset0 + 3;
  8079. var offset4 = offset0 + 4;
  8080. // It's easy to screw up offsets so perform this sanity check.
  8081. if (data[offset0] !== 0x1d || data[offset1] !== 0 || data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  8082. error('writing to an offset that is not empty');
  8083. }
  8084. var value = values[i];
  8085. data[offset0] = 0x1d;
  8086. data[offset1] = value >> 24 & 0xFF;
  8087. data[offset2] = value >> 16 & 0xFF;
  8088. data[offset3] = value >> 8 & 0xFF;
  8089. data[offset4] = value & 0xFF;
  8090. }
  8091. }
  8092. };
  8093. return CFFOffsetTracker;
  8094. }();
  8095. // Takes a CFF and converts it to the binary representation.
  8096. var CFFCompiler = function CFFCompilerClosure() {
  8097. function CFFCompiler(cff) {
  8098. this.cff = cff;
  8099. }
  8100. CFFCompiler.prototype = {
  8101. compile: function CFFCompiler_compile() {
  8102. var cff = this.cff;
  8103. var output = {
  8104. data: [],
  8105. length: 0,
  8106. add: function CFFCompiler_add(data) {
  8107. this.data = this.data.concat(data);
  8108. this.length = this.data.length;
  8109. }
  8110. };
  8111. // Compile the five entries that must be in order.
  8112. var header = this.compileHeader(cff.header);
  8113. output.add(header);
  8114. var nameIndex = this.compileNameIndex(cff.names);
  8115. output.add(nameIndex);
  8116. if (cff.isCIDFont) {
  8117. // The spec is unclear on how font matrices should relate to each other
  8118. // when there is one in the main top dict and the sub top dicts.
  8119. // Windows handles this differently than linux and osx so we have to
  8120. // normalize to work on all.
  8121. // Rules based off of some mailing list discussions:
  8122. // - If main font has a matrix and subfont doesn't, use the main matrix.
  8123. // - If no main font matrix and there is a subfont matrix, use the
  8124. // subfont matrix.
  8125. // - If both have matrices, concat together.
  8126. // - If neither have matrices, use default.
  8127. // To make this work on all platforms we move the top matrix into each
  8128. // sub top dict and concat if necessary.
  8129. if (cff.topDict.hasName('FontMatrix')) {
  8130. var base = cff.topDict.getByName('FontMatrix');
  8131. cff.topDict.removeByName('FontMatrix');
  8132. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  8133. var subDict = cff.fdArray[i];
  8134. var matrix = base.slice(0);
  8135. if (subDict.hasName('FontMatrix')) {
  8136. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  8137. }
  8138. subDict.setByName('FontMatrix', matrix);
  8139. }
  8140. }
  8141. }
  8142. var compiled = this.compileTopDicts([cff.topDict], output.length, cff.isCIDFont);
  8143. output.add(compiled.output);
  8144. var topDictTracker = compiled.trackers[0];
  8145. var stringIndex = this.compileStringIndex(cff.strings.strings);
  8146. output.add(stringIndex);
  8147. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  8148. output.add(globalSubrIndex);
  8149. // Now start on the other entries that have no specific order.
  8150. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  8151. if (cff.encoding.predefined) {
  8152. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format], output);
  8153. } else {
  8154. var encoding = this.compileEncoding(cff.encoding);
  8155. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  8156. output.add(encoding);
  8157. }
  8158. }
  8159. if (cff.charset && cff.topDict.hasName('charset')) {
  8160. if (cff.charset.predefined) {
  8161. topDictTracker.setEntryLocation('charset', [cff.charset.format], output);
  8162. } else {
  8163. var charset = this.compileCharset(cff.charset);
  8164. topDictTracker.setEntryLocation('charset', [output.length], output);
  8165. output.add(charset);
  8166. }
  8167. }
  8168. var charStrings = this.compileCharStrings(cff.charStrings);
  8169. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  8170. output.add(charStrings);
  8171. if (cff.isCIDFont) {
  8172. // For some reason FDSelect must be in front of FDArray on windows. OSX
  8173. // and linux don't seem to care.
  8174. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  8175. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  8176. output.add(fdSelect);
  8177. // It is unclear if the sub font dictionary can have CID related
  8178. // dictionary keys, but the sanitizer doesn't like them so remove them.
  8179. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  8180. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  8181. output.add(compiled.output);
  8182. var fontDictTrackers = compiled.trackers;
  8183. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  8184. }
  8185. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  8186. // If the font data ends with INDEX whose object data is zero-length,
  8187. // the sanitizer will bail out. Add a dummy byte to avoid that.
  8188. output.add([0]);
  8189. return output.data;
  8190. },
  8191. encodeNumber: function CFFCompiler_encodeNumber(value) {
  8192. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) {
  8193. // isInt
  8194. return this.encodeInteger(value);
  8195. } else {
  8196. return this.encodeFloat(value);
  8197. }
  8198. },
  8199. encodeFloat: function CFFCompiler_encodeFloat(num) {
  8200. var value = num.toString();
  8201. // rounding inaccurate doubles
  8202. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  8203. if (m) {
  8204. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  8205. value = (Math.round(num * epsilon) / epsilon).toString();
  8206. }
  8207. var nibbles = '';
  8208. var i, ii;
  8209. for (i = 0, ii = value.length; i < ii; ++i) {
  8210. var a = value[i];
  8211. if (a === 'e') {
  8212. nibbles += value[++i] === '-' ? 'c' : 'b';
  8213. } else if (a === '.') {
  8214. nibbles += 'a';
  8215. } else if (a === '-') {
  8216. nibbles += 'e';
  8217. } else {
  8218. nibbles += a;
  8219. }
  8220. }
  8221. nibbles += nibbles.length & 1 ? 'f' : 'ff';
  8222. var out = [30];
  8223. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  8224. out.push(parseInt(nibbles.substr(i, 2), 16));
  8225. }
  8226. return out;
  8227. },
  8228. encodeInteger: function CFFCompiler_encodeInteger(value) {
  8229. var code;
  8230. if (value >= -107 && value <= 107) {
  8231. code = [value + 139];
  8232. } else if (value >= 108 && value <= 1131) {
  8233. value = value - 108;
  8234. code = [
  8235. (value >> 8) + 247,
  8236. value & 0xFF
  8237. ];
  8238. } else if (value >= -1131 && value <= -108) {
  8239. value = -value - 108;
  8240. code = [
  8241. (value >> 8) + 251,
  8242. value & 0xFF
  8243. ];
  8244. } else if (value >= -32768 && value <= 32767) {
  8245. code = [
  8246. 0x1c,
  8247. value >> 8 & 0xFF,
  8248. value & 0xFF
  8249. ];
  8250. } else {
  8251. code = [
  8252. 0x1d,
  8253. value >> 24 & 0xFF,
  8254. value >> 16 & 0xFF,
  8255. value >> 8 & 0xFF,
  8256. value & 0xFF
  8257. ];
  8258. }
  8259. return code;
  8260. },
  8261. compileHeader: function CFFCompiler_compileHeader(header) {
  8262. return [
  8263. header.major,
  8264. header.minor,
  8265. header.hdrSize,
  8266. header.offSize
  8267. ];
  8268. },
  8269. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  8270. var nameIndex = new CFFIndex();
  8271. for (var i = 0, ii = names.length; i < ii; ++i) {
  8272. nameIndex.add(stringToBytes(names[i]));
  8273. }
  8274. return this.compileIndex(nameIndex);
  8275. },
  8276. compileTopDicts: function CFFCompiler_compileTopDicts(dicts, length, removeCidKeys) {
  8277. var fontDictTrackers = [];
  8278. var fdArrayIndex = new CFFIndex();
  8279. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  8280. var fontDict = dicts[i];
  8281. if (removeCidKeys) {
  8282. fontDict.removeByName('CIDFontVersion');
  8283. fontDict.removeByName('CIDFontRevision');
  8284. fontDict.removeByName('CIDFontType');
  8285. fontDict.removeByName('CIDCount');
  8286. fontDict.removeByName('UIDBase');
  8287. }
  8288. var fontDictTracker = new CFFOffsetTracker();
  8289. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  8290. fontDictTrackers.push(fontDictTracker);
  8291. fdArrayIndex.add(fontDictData);
  8292. fontDictTracker.offset(length);
  8293. }
  8294. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  8295. return {
  8296. trackers: fontDictTrackers,
  8297. output: fdArrayIndex
  8298. };
  8299. },
  8300. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts, trackers, output) {
  8301. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  8302. var fontDict = dicts[i];
  8303. assert(fontDict.privateDict && fontDict.hasName('Private'), 'There must be an private dictionary.');
  8304. var privateDict = fontDict.privateDict;
  8305. var privateDictTracker = new CFFOffsetTracker();
  8306. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  8307. var outputLength = output.length;
  8308. privateDictTracker.offset(outputLength);
  8309. if (!privateDictData.length) {
  8310. // The private dictionary was empty, set the output length to zero to
  8311. // ensure the offset length isn't out of bounds in the eyes of the
  8312. // sanitizer.
  8313. outputLength = 0;
  8314. }
  8315. trackers[i].setEntryLocation('Private', [
  8316. privateDictData.length,
  8317. outputLength
  8318. ], output);
  8319. output.add(privateDictData);
  8320. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  8321. var subrs = this.compileIndex(privateDict.subrsIndex);
  8322. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length], output);
  8323. output.add(subrs);
  8324. }
  8325. }
  8326. },
  8327. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  8328. var out = [];
  8329. // The dictionary keys must be in a certain order.
  8330. var order = dict.order;
  8331. for (var i = 0; i < order.length; ++i) {
  8332. var key = order[i];
  8333. if (!(key in dict.values)) {
  8334. continue;
  8335. }
  8336. var values = dict.values[key];
  8337. var types = dict.types[key];
  8338. if (!isArray(types)) {
  8339. types = [types];
  8340. }
  8341. if (!isArray(values)) {
  8342. values = [values];
  8343. }
  8344. // Remove any empty dict values.
  8345. if (values.length === 0) {
  8346. continue;
  8347. }
  8348. for (var j = 0, jj = types.length; j < jj; ++j) {
  8349. var type = types[j];
  8350. var value = values[j];
  8351. switch (type) {
  8352. case 'num':
  8353. case 'sid':
  8354. out = out.concat(this.encodeNumber(value));
  8355. break;
  8356. case 'offset':
  8357. // For offsets we just insert a 32bit integer so we don't have to
  8358. // deal with figuring out the length of the offset when it gets
  8359. // replaced later on by the compiler.
  8360. var name = dict.keyToNameMap[key];
  8361. // Some offsets have the offset and the length, so just record the
  8362. // position of the first one.
  8363. if (!offsetTracker.isTracking(name)) {
  8364. offsetTracker.track(name, out.length);
  8365. }
  8366. out = out.concat([
  8367. 0x1d,
  8368. 0,
  8369. 0,
  8370. 0,
  8371. 0
  8372. ]);
  8373. break;
  8374. case 'array':
  8375. case 'delta':
  8376. out = out.concat(this.encodeNumber(value));
  8377. for (var k = 1, kk = values.length; k < kk; ++k) {
  8378. out = out.concat(this.encodeNumber(values[k]));
  8379. }
  8380. break;
  8381. default:
  8382. error('Unknown data type of ' + type);
  8383. break;
  8384. }
  8385. }
  8386. out = out.concat(dict.opcodes[key]);
  8387. }
  8388. return out;
  8389. },
  8390. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  8391. var stringIndex = new CFFIndex();
  8392. for (var i = 0, ii = strings.length; i < ii; ++i) {
  8393. stringIndex.add(stringToBytes(strings[i]));
  8394. }
  8395. return this.compileIndex(stringIndex);
  8396. },
  8397. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  8398. var globalSubrIndex = this.cff.globalSubrIndex;
  8399. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  8400. },
  8401. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  8402. return this.compileIndex(charStrings);
  8403. },
  8404. compileCharset: function CFFCompiler_compileCharset(charset) {
  8405. return this.compileTypedArray(charset.raw);
  8406. },
  8407. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  8408. return this.compileTypedArray(encoding.raw);
  8409. },
  8410. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  8411. return this.compileTypedArray(fdSelect);
  8412. },
  8413. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  8414. var out = [];
  8415. for (var i = 0, ii = data.length; i < ii; ++i) {
  8416. out[i] = data[i];
  8417. }
  8418. return out;
  8419. },
  8420. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  8421. trackers = trackers || [];
  8422. var objects = index.objects;
  8423. // First 2 bytes contains the number of objects contained into this index
  8424. var count = objects.length;
  8425. // If there is no object, just create an index. This technically
  8426. // should just be [0, 0] but OTS has an issue with that.
  8427. if (count === 0) {
  8428. return [
  8429. 0,
  8430. 0,
  8431. 0
  8432. ];
  8433. }
  8434. var data = [
  8435. count >> 8 & 0xFF,
  8436. count & 0xff
  8437. ];
  8438. var lastOffset = 1, i;
  8439. for (i = 0; i < count; ++i) {
  8440. lastOffset += objects[i].length;
  8441. }
  8442. var offsetSize;
  8443. if (lastOffset < 0x100) {
  8444. offsetSize = 1;
  8445. } else if (lastOffset < 0x10000) {
  8446. offsetSize = 2;
  8447. } else if (lastOffset < 0x1000000) {
  8448. offsetSize = 3;
  8449. } else {
  8450. offsetSize = 4;
  8451. }
  8452. // Next byte contains the offset size use to reference object in the file
  8453. data.push(offsetSize);
  8454. // Add another offset after this one because we need a new offset
  8455. var relativeOffset = 1;
  8456. for (i = 0; i < count + 1; i++) {
  8457. if (offsetSize === 1) {
  8458. data.push(relativeOffset & 0xFF);
  8459. } else if (offsetSize === 2) {
  8460. data.push(relativeOffset >> 8 & 0xFF, relativeOffset & 0xFF);
  8461. } else if (offsetSize === 3) {
  8462. data.push(relativeOffset >> 16 & 0xFF, relativeOffset >> 8 & 0xFF, relativeOffset & 0xFF);
  8463. } else {
  8464. data.push(relativeOffset >>> 24 & 0xFF, relativeOffset >> 16 & 0xFF, relativeOffset >> 8 & 0xFF, relativeOffset & 0xFF);
  8465. }
  8466. if (objects[i]) {
  8467. relativeOffset += objects[i].length;
  8468. }
  8469. }
  8470. for (i = 0; i < count; i++) {
  8471. // Notify the tracker where the object will be offset in the data.
  8472. if (trackers[i]) {
  8473. trackers[i].offset(data.length);
  8474. }
  8475. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  8476. data.push(objects[i][j]);
  8477. }
  8478. }
  8479. return data;
  8480. }
  8481. };
  8482. return CFFCompiler;
  8483. }();
  8484. exports.CFFStandardStrings = CFFStandardStrings;
  8485. exports.CFFParser = CFFParser;
  8486. exports.CFF = CFF;
  8487. exports.CFFHeader = CFFHeader;
  8488. exports.CFFStrings = CFFStrings;
  8489. exports.CFFIndex = CFFIndex;
  8490. exports.CFFCharset = CFFCharset;
  8491. exports.CFFTopDict = CFFTopDict;
  8492. exports.CFFPrivateDict = CFFPrivateDict;
  8493. exports.CFFCompiler = CFFCompiler;
  8494. }));
  8495. (function (root, factory) {
  8496. factory(root.pdfjsCoreChunkedStream = {}, root.pdfjsSharedUtil);
  8497. }(this, function (exports, sharedUtil) {
  8498. var MissingDataException = sharedUtil.MissingDataException;
  8499. var arrayByteLength = sharedUtil.arrayByteLength;
  8500. var arraysToBytes = sharedUtil.arraysToBytes;
  8501. var assert = sharedUtil.assert;
  8502. var createPromiseCapability = sharedUtil.createPromiseCapability;
  8503. var isInt = sharedUtil.isInt;
  8504. var isEmptyObj = sharedUtil.isEmptyObj;
  8505. var ChunkedStream = function ChunkedStreamClosure() {
  8506. function ChunkedStream(length, chunkSize, manager) {
  8507. this.bytes = new Uint8Array(length);
  8508. this.start = 0;
  8509. this.pos = 0;
  8510. this.end = length;
  8511. this.chunkSize = chunkSize;
  8512. this.loadedChunks = [];
  8513. this.numChunksLoaded = 0;
  8514. this.numChunks = Math.ceil(length / chunkSize);
  8515. this.manager = manager;
  8516. this.progressiveDataLength = 0;
  8517. this.lastSuccessfulEnsureByteChunk = -1;
  8518. }
  8519. // a single-entry cache
  8520. // required methods for a stream. if a particular stream does not
  8521. // implement these, an error should be thrown
  8522. ChunkedStream.prototype = {
  8523. getMissingChunks: function ChunkedStream_getMissingChunks() {
  8524. var chunks = [];
  8525. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  8526. if (!this.loadedChunks[chunk]) {
  8527. chunks.push(chunk);
  8528. }
  8529. }
  8530. return chunks;
  8531. },
  8532. getBaseStreams: function ChunkedStream_getBaseStreams() {
  8533. return [this];
  8534. },
  8535. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  8536. return this.numChunksLoaded === this.numChunks;
  8537. },
  8538. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  8539. var end = begin + chunk.byteLength;
  8540. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  8541. // Using this.length is inaccurate here since this.start can be moved
  8542. // See ChunkedStream.moveStart()
  8543. var length = this.bytes.length;
  8544. assert(end % this.chunkSize === 0 || end === length, 'Bad end offset: ' + end);
  8545. this.bytes.set(new Uint8Array(chunk), begin);
  8546. var chunkSize = this.chunkSize;
  8547. var beginChunk = Math.floor(begin / chunkSize);
  8548. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  8549. var curChunk;
  8550. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  8551. if (!this.loadedChunks[curChunk]) {
  8552. this.loadedChunks[curChunk] = true;
  8553. ++this.numChunksLoaded;
  8554. }
  8555. }
  8556. },
  8557. onReceiveProgressiveData: function ChunkedStream_onReceiveProgressiveData(data) {
  8558. var position = this.progressiveDataLength;
  8559. var beginChunk = Math.floor(position / this.chunkSize);
  8560. this.bytes.set(new Uint8Array(data), position);
  8561. position += data.byteLength;
  8562. this.progressiveDataLength = position;
  8563. var endChunk = position >= this.end ? this.numChunks : Math.floor(position / this.chunkSize);
  8564. var curChunk;
  8565. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  8566. if (!this.loadedChunks[curChunk]) {
  8567. this.loadedChunks[curChunk] = true;
  8568. ++this.numChunksLoaded;
  8569. }
  8570. }
  8571. },
  8572. ensureByte: function ChunkedStream_ensureByte(pos) {
  8573. var chunk = Math.floor(pos / this.chunkSize);
  8574. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  8575. return;
  8576. }
  8577. if (!this.loadedChunks[chunk]) {
  8578. throw new MissingDataException(pos, pos + 1);
  8579. }
  8580. this.lastSuccessfulEnsureByteChunk = chunk;
  8581. },
  8582. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  8583. if (begin >= end) {
  8584. return;
  8585. }
  8586. if (end <= this.progressiveDataLength) {
  8587. return;
  8588. }
  8589. var chunkSize = this.chunkSize;
  8590. var beginChunk = Math.floor(begin / chunkSize);
  8591. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  8592. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  8593. if (!this.loadedChunks[chunk]) {
  8594. throw new MissingDataException(begin, end);
  8595. }
  8596. }
  8597. },
  8598. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  8599. var chunk, numChunks = this.numChunks;
  8600. for (var i = 0; i < numChunks; ++i) {
  8601. chunk = (beginChunk + i) % numChunks;
  8602. // Wrap around to beginning
  8603. if (!this.loadedChunks[chunk]) {
  8604. return chunk;
  8605. }
  8606. }
  8607. return null;
  8608. },
  8609. hasChunk: function ChunkedStream_hasChunk(chunk) {
  8610. return !!this.loadedChunks[chunk];
  8611. },
  8612. get length() {
  8613. return this.end - this.start;
  8614. },
  8615. get isEmpty() {
  8616. return this.length === 0;
  8617. },
  8618. getByte: function ChunkedStream_getByte() {
  8619. var pos = this.pos;
  8620. if (pos >= this.end) {
  8621. return -1;
  8622. }
  8623. this.ensureByte(pos);
  8624. return this.bytes[this.pos++];
  8625. },
  8626. getUint16: function ChunkedStream_getUint16() {
  8627. var b0 = this.getByte();
  8628. var b1 = this.getByte();
  8629. if (b0 === -1 || b1 === -1) {
  8630. return -1;
  8631. }
  8632. return (b0 << 8) + b1;
  8633. },
  8634. getInt32: function ChunkedStream_getInt32() {
  8635. var b0 = this.getByte();
  8636. var b1 = this.getByte();
  8637. var b2 = this.getByte();
  8638. var b3 = this.getByte();
  8639. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  8640. },
  8641. // returns subarray of original buffer
  8642. // should only be read
  8643. getBytes: function ChunkedStream_getBytes(length) {
  8644. var bytes = this.bytes;
  8645. var pos = this.pos;
  8646. var strEnd = this.end;
  8647. if (!length) {
  8648. this.ensureRange(pos, strEnd);
  8649. return bytes.subarray(pos, strEnd);
  8650. }
  8651. var end = pos + length;
  8652. if (end > strEnd) {
  8653. end = strEnd;
  8654. }
  8655. this.ensureRange(pos, end);
  8656. this.pos = end;
  8657. return bytes.subarray(pos, end);
  8658. },
  8659. peekByte: function ChunkedStream_peekByte() {
  8660. var peekedByte = this.getByte();
  8661. this.pos--;
  8662. return peekedByte;
  8663. },
  8664. peekBytes: function ChunkedStream_peekBytes(length) {
  8665. var bytes = this.getBytes(length);
  8666. this.pos -= bytes.length;
  8667. return bytes;
  8668. },
  8669. getByteRange: function ChunkedStream_getBytes(begin, end) {
  8670. this.ensureRange(begin, end);
  8671. return this.bytes.subarray(begin, end);
  8672. },
  8673. skip: function ChunkedStream_skip(n) {
  8674. if (!n) {
  8675. n = 1;
  8676. }
  8677. this.pos += n;
  8678. },
  8679. reset: function ChunkedStream_reset() {
  8680. this.pos = this.start;
  8681. },
  8682. moveStart: function ChunkedStream_moveStart() {
  8683. this.start = this.pos;
  8684. },
  8685. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  8686. this.ensureRange(start, start + length);
  8687. function ChunkedStreamSubstream() {
  8688. }
  8689. ChunkedStreamSubstream.prototype = Object.create(this);
  8690. ChunkedStreamSubstream.prototype.getMissingChunks = function () {
  8691. var chunkSize = this.chunkSize;
  8692. var beginChunk = Math.floor(this.start / chunkSize);
  8693. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  8694. var missingChunks = [];
  8695. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  8696. if (!this.loadedChunks[chunk]) {
  8697. missingChunks.push(chunk);
  8698. }
  8699. }
  8700. return missingChunks;
  8701. };
  8702. var subStream = new ChunkedStreamSubstream();
  8703. subStream.pos = subStream.start = start;
  8704. subStream.end = start + length || this.end;
  8705. subStream.dict = dict;
  8706. return subStream;
  8707. },
  8708. isStream: true
  8709. };
  8710. return ChunkedStream;
  8711. }();
  8712. var ChunkedStreamManager = function ChunkedStreamManagerClosure() {
  8713. function ChunkedStreamManager(pdfNetworkStream, args) {
  8714. var chunkSize = args.rangeChunkSize;
  8715. var length = args.length;
  8716. this.stream = new ChunkedStream(length, chunkSize, this);
  8717. this.length = length;
  8718. this.chunkSize = chunkSize;
  8719. this.pdfNetworkStream = pdfNetworkStream;
  8720. this.url = args.url;
  8721. this.disableAutoFetch = args.disableAutoFetch;
  8722. this.msgHandler = args.msgHandler;
  8723. this.currRequestId = 0;
  8724. this.chunksNeededByRequest = Object.create(null);
  8725. this.requestsByChunk = Object.create(null);
  8726. this.promisesByRequest = Object.create(null);
  8727. this.progressiveDataLength = 0;
  8728. this.aborted = false;
  8729. this._loadedStreamCapability = createPromiseCapability();
  8730. }
  8731. ChunkedStreamManager.prototype = {
  8732. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  8733. return this._loadedStreamCapability.promise;
  8734. },
  8735. sendRequest: function ChunkedStreamManager_sendRequest(begin, end) {
  8736. var rangeReader = this.pdfNetworkStream.getRangeReader(begin, end);
  8737. if (!rangeReader.isStreamingSupported) {
  8738. rangeReader.onProgress = this.onProgress.bind(this);
  8739. }
  8740. var chunks = [], loaded = 0;
  8741. var manager = this;
  8742. var promise = new Promise(function (resolve, reject) {
  8743. var readChunk = function (chunk) {
  8744. try {
  8745. if (!chunk.done) {
  8746. var data = chunk.value;
  8747. chunks.push(data);
  8748. loaded += arrayByteLength(data);
  8749. if (rangeReader.isStreamingSupported) {
  8750. manager.onProgress({ loaded: loaded });
  8751. }
  8752. rangeReader.read().then(readChunk, reject);
  8753. return;
  8754. }
  8755. var chunkData = arraysToBytes(chunks);
  8756. chunks = null;
  8757. resolve(chunkData);
  8758. } catch (e) {
  8759. reject(e);
  8760. }
  8761. };
  8762. rangeReader.read().then(readChunk, reject);
  8763. });
  8764. promise.then(function (data) {
  8765. if (this.aborted) {
  8766. return;
  8767. }
  8768. // ignoring any data after abort
  8769. this.onReceiveData({
  8770. chunk: data,
  8771. begin: begin
  8772. });
  8773. }.bind(this));
  8774. },
  8775. // TODO check errors
  8776. // Get all the chunks that are not yet loaded and groups them into
  8777. // contiguous ranges to load in as few requests as possible
  8778. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  8779. var missingChunks = this.stream.getMissingChunks();
  8780. this._requestChunks(missingChunks);
  8781. return this._loadedStreamCapability.promise;
  8782. },
  8783. _requestChunks: function ChunkedStreamManager_requestChunks(chunks) {
  8784. var requestId = this.currRequestId++;
  8785. var i, ii;
  8786. var chunksNeeded = Object.create(null);
  8787. this.chunksNeededByRequest[requestId] = chunksNeeded;
  8788. for (i = 0, ii = chunks.length; i < ii; i++) {
  8789. if (!this.stream.hasChunk(chunks[i])) {
  8790. chunksNeeded[chunks[i]] = true;
  8791. }
  8792. }
  8793. if (isEmptyObj(chunksNeeded)) {
  8794. return Promise.resolve();
  8795. }
  8796. var capability = createPromiseCapability();
  8797. this.promisesByRequest[requestId] = capability;
  8798. var chunksToRequest = [];
  8799. for (var chunk in chunksNeeded) {
  8800. chunk = chunk | 0;
  8801. if (!(chunk in this.requestsByChunk)) {
  8802. this.requestsByChunk[chunk] = [];
  8803. chunksToRequest.push(chunk);
  8804. }
  8805. this.requestsByChunk[chunk].push(requestId);
  8806. }
  8807. if (!chunksToRequest.length) {
  8808. return capability.promise;
  8809. }
  8810. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  8811. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  8812. var groupedChunk = groupedChunksToRequest[i];
  8813. var begin = groupedChunk.beginChunk * this.chunkSize;
  8814. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  8815. this.sendRequest(begin, end);
  8816. }
  8817. return capability.promise;
  8818. },
  8819. getStream: function ChunkedStreamManager_getStream() {
  8820. return this.stream;
  8821. },
  8822. // Loads any chunks in the requested range that are not yet loaded
  8823. requestRange: function ChunkedStreamManager_requestRange(begin, end) {
  8824. end = Math.min(end, this.length);
  8825. var beginChunk = this.getBeginChunk(begin);
  8826. var endChunk = this.getEndChunk(end);
  8827. var chunks = [];
  8828. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  8829. chunks.push(chunk);
  8830. }
  8831. return this._requestChunks(chunks);
  8832. },
  8833. requestRanges: function ChunkedStreamManager_requestRanges(ranges) {
  8834. ranges = ranges || [];
  8835. var chunksToRequest = [];
  8836. for (var i = 0; i < ranges.length; i++) {
  8837. var beginChunk = this.getBeginChunk(ranges[i].begin);
  8838. var endChunk = this.getEndChunk(ranges[i].end);
  8839. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  8840. if (chunksToRequest.indexOf(chunk) < 0) {
  8841. chunksToRequest.push(chunk);
  8842. }
  8843. }
  8844. }
  8845. chunksToRequest.sort(function (a, b) {
  8846. return a - b;
  8847. });
  8848. return this._requestChunks(chunksToRequest);
  8849. },
  8850. // Groups a sorted array of chunks into as few contiguous larger
  8851. // chunks as possible
  8852. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  8853. var groupedChunks = [];
  8854. var beginChunk = -1;
  8855. var prevChunk = -1;
  8856. for (var i = 0; i < chunks.length; ++i) {
  8857. var chunk = chunks[i];
  8858. if (beginChunk < 0) {
  8859. beginChunk = chunk;
  8860. }
  8861. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  8862. groupedChunks.push({
  8863. beginChunk: beginChunk,
  8864. endChunk: prevChunk + 1
  8865. });
  8866. beginChunk = chunk;
  8867. }
  8868. if (i + 1 === chunks.length) {
  8869. groupedChunks.push({
  8870. beginChunk: beginChunk,
  8871. endChunk: chunk + 1
  8872. });
  8873. }
  8874. prevChunk = chunk;
  8875. }
  8876. return groupedChunks;
  8877. },
  8878. onProgress: function ChunkedStreamManager_onProgress(args) {
  8879. var bytesLoaded = this.stream.numChunksLoaded * this.chunkSize + args.loaded;
  8880. this.msgHandler.send('DocProgress', {
  8881. loaded: bytesLoaded,
  8882. total: this.length
  8883. });
  8884. },
  8885. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  8886. var chunk = args.chunk;
  8887. var isProgressive = args.begin === undefined;
  8888. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  8889. var end = begin + chunk.byteLength;
  8890. var beginChunk = Math.floor(begin / this.chunkSize);
  8891. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) : Math.ceil(end / this.chunkSize);
  8892. if (isProgressive) {
  8893. this.stream.onReceiveProgressiveData(chunk);
  8894. this.progressiveDataLength = end;
  8895. } else {
  8896. this.stream.onReceiveData(begin, chunk);
  8897. }
  8898. if (this.stream.allChunksLoaded()) {
  8899. this._loadedStreamCapability.resolve(this.stream);
  8900. }
  8901. var loadedRequests = [];
  8902. var i, requestId;
  8903. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  8904. // The server might return more chunks than requested
  8905. var requestIds = this.requestsByChunk[chunk] || [];
  8906. delete this.requestsByChunk[chunk];
  8907. for (i = 0; i < requestIds.length; ++i) {
  8908. requestId = requestIds[i];
  8909. var chunksNeeded = this.chunksNeededByRequest[requestId];
  8910. if (chunk in chunksNeeded) {
  8911. delete chunksNeeded[chunk];
  8912. }
  8913. if (!isEmptyObj(chunksNeeded)) {
  8914. continue;
  8915. }
  8916. loadedRequests.push(requestId);
  8917. }
  8918. }
  8919. // If there are no pending requests, automatically fetch the next
  8920. // unfetched chunk of the PDF
  8921. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  8922. var nextEmptyChunk;
  8923. if (this.stream.numChunksLoaded === 1) {
  8924. // This is a special optimization so that after fetching the first
  8925. // chunk, rather than fetching the second chunk, we fetch the last
  8926. // chunk.
  8927. var lastChunk = this.stream.numChunks - 1;
  8928. if (!this.stream.hasChunk(lastChunk)) {
  8929. nextEmptyChunk = lastChunk;
  8930. }
  8931. } else {
  8932. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  8933. }
  8934. if (isInt(nextEmptyChunk)) {
  8935. this._requestChunks([nextEmptyChunk]);
  8936. }
  8937. }
  8938. for (i = 0; i < loadedRequests.length; ++i) {
  8939. requestId = loadedRequests[i];
  8940. var capability = this.promisesByRequest[requestId];
  8941. delete this.promisesByRequest[requestId];
  8942. capability.resolve();
  8943. }
  8944. this.msgHandler.send('DocProgress', {
  8945. loaded: this.stream.numChunksLoaded * this.chunkSize,
  8946. total: this.length
  8947. });
  8948. },
  8949. onError: function ChunkedStreamManager_onError(err) {
  8950. this._loadedStreamCapability.reject(err);
  8951. },
  8952. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  8953. var chunk = Math.floor(begin / this.chunkSize);
  8954. return chunk;
  8955. },
  8956. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  8957. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  8958. return chunk;
  8959. },
  8960. abort: function ChunkedStreamManager_abort() {
  8961. this.aborted = true;
  8962. if (this.pdfNetworkStream) {
  8963. this.pdfNetworkStream.cancelAllRequests('abort');
  8964. }
  8965. for (var requestId in this.promisesByRequest) {
  8966. var capability = this.promisesByRequest[requestId];
  8967. capability.reject(new Error('Request was aborted'));
  8968. }
  8969. }
  8970. };
  8971. return ChunkedStreamManager;
  8972. }();
  8973. exports.ChunkedStream = ChunkedStream;
  8974. exports.ChunkedStreamManager = ChunkedStreamManager;
  8975. }));
  8976. (function (root, factory) {
  8977. factory(root.pdfjsCoreGlyphList = {}, root.pdfjsSharedUtil);
  8978. }(this, function (exports, sharedUtil) {
  8979. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  8980. var getGlyphsUnicode = getLookupTableFactory(function (t) {
  8981. t['A'] = 0x0041;
  8982. t['AE'] = 0x00C6;
  8983. t['AEacute'] = 0x01FC;
  8984. t['AEmacron'] = 0x01E2;
  8985. t['AEsmall'] = 0xF7E6;
  8986. t['Aacute'] = 0x00C1;
  8987. t['Aacutesmall'] = 0xF7E1;
  8988. t['Abreve'] = 0x0102;
  8989. t['Abreveacute'] = 0x1EAE;
  8990. t['Abrevecyrillic'] = 0x04D0;
  8991. t['Abrevedotbelow'] = 0x1EB6;
  8992. t['Abrevegrave'] = 0x1EB0;
  8993. t['Abrevehookabove'] = 0x1EB2;
  8994. t['Abrevetilde'] = 0x1EB4;
  8995. t['Acaron'] = 0x01CD;
  8996. t['Acircle'] = 0x24B6;
  8997. t['Acircumflex'] = 0x00C2;
  8998. t['Acircumflexacute'] = 0x1EA4;
  8999. t['Acircumflexdotbelow'] = 0x1EAC;
  9000. t['Acircumflexgrave'] = 0x1EA6;
  9001. t['Acircumflexhookabove'] = 0x1EA8;
  9002. t['Acircumflexsmall'] = 0xF7E2;
  9003. t['Acircumflextilde'] = 0x1EAA;
  9004. t['Acute'] = 0xF6C9;
  9005. t['Acutesmall'] = 0xF7B4;
  9006. t['Acyrillic'] = 0x0410;
  9007. t['Adblgrave'] = 0x0200;
  9008. t['Adieresis'] = 0x00C4;
  9009. t['Adieresiscyrillic'] = 0x04D2;
  9010. t['Adieresismacron'] = 0x01DE;
  9011. t['Adieresissmall'] = 0xF7E4;
  9012. t['Adotbelow'] = 0x1EA0;
  9013. t['Adotmacron'] = 0x01E0;
  9014. t['Agrave'] = 0x00C0;
  9015. t['Agravesmall'] = 0xF7E0;
  9016. t['Ahookabove'] = 0x1EA2;
  9017. t['Aiecyrillic'] = 0x04D4;
  9018. t['Ainvertedbreve'] = 0x0202;
  9019. t['Alpha'] = 0x0391;
  9020. t['Alphatonos'] = 0x0386;
  9021. t['Amacron'] = 0x0100;
  9022. t['Amonospace'] = 0xFF21;
  9023. t['Aogonek'] = 0x0104;
  9024. t['Aring'] = 0x00C5;
  9025. t['Aringacute'] = 0x01FA;
  9026. t['Aringbelow'] = 0x1E00;
  9027. t['Aringsmall'] = 0xF7E5;
  9028. t['Asmall'] = 0xF761;
  9029. t['Atilde'] = 0x00C3;
  9030. t['Atildesmall'] = 0xF7E3;
  9031. t['Aybarmenian'] = 0x0531;
  9032. t['B'] = 0x0042;
  9033. t['Bcircle'] = 0x24B7;
  9034. t['Bdotaccent'] = 0x1E02;
  9035. t['Bdotbelow'] = 0x1E04;
  9036. t['Becyrillic'] = 0x0411;
  9037. t['Benarmenian'] = 0x0532;
  9038. t['Beta'] = 0x0392;
  9039. t['Bhook'] = 0x0181;
  9040. t['Blinebelow'] = 0x1E06;
  9041. t['Bmonospace'] = 0xFF22;
  9042. t['Brevesmall'] = 0xF6F4;
  9043. t['Bsmall'] = 0xF762;
  9044. t['Btopbar'] = 0x0182;
  9045. t['C'] = 0x0043;
  9046. t['Caarmenian'] = 0x053E;
  9047. t['Cacute'] = 0x0106;
  9048. t['Caron'] = 0xF6CA;
  9049. t['Caronsmall'] = 0xF6F5;
  9050. t['Ccaron'] = 0x010C;
  9051. t['Ccedilla'] = 0x00C7;
  9052. t['Ccedillaacute'] = 0x1E08;
  9053. t['Ccedillasmall'] = 0xF7E7;
  9054. t['Ccircle'] = 0x24B8;
  9055. t['Ccircumflex'] = 0x0108;
  9056. t['Cdot'] = 0x010A;
  9057. t['Cdotaccent'] = 0x010A;
  9058. t['Cedillasmall'] = 0xF7B8;
  9059. t['Chaarmenian'] = 0x0549;
  9060. t['Cheabkhasiancyrillic'] = 0x04BC;
  9061. t['Checyrillic'] = 0x0427;
  9062. t['Chedescenderabkhasiancyrillic'] = 0x04BE;
  9063. t['Chedescendercyrillic'] = 0x04B6;
  9064. t['Chedieresiscyrillic'] = 0x04F4;
  9065. t['Cheharmenian'] = 0x0543;
  9066. t['Chekhakassiancyrillic'] = 0x04CB;
  9067. t['Cheverticalstrokecyrillic'] = 0x04B8;
  9068. t['Chi'] = 0x03A7;
  9069. t['Chook'] = 0x0187;
  9070. t['Circumflexsmall'] = 0xF6F6;
  9071. t['Cmonospace'] = 0xFF23;
  9072. t['Coarmenian'] = 0x0551;
  9073. t['Csmall'] = 0xF763;
  9074. t['D'] = 0x0044;
  9075. t['DZ'] = 0x01F1;
  9076. t['DZcaron'] = 0x01C4;
  9077. t['Daarmenian'] = 0x0534;
  9078. t['Dafrican'] = 0x0189;
  9079. t['Dcaron'] = 0x010E;
  9080. t['Dcedilla'] = 0x1E10;
  9081. t['Dcircle'] = 0x24B9;
  9082. t['Dcircumflexbelow'] = 0x1E12;
  9083. t['Dcroat'] = 0x0110;
  9084. t['Ddotaccent'] = 0x1E0A;
  9085. t['Ddotbelow'] = 0x1E0C;
  9086. t['Decyrillic'] = 0x0414;
  9087. t['Deicoptic'] = 0x03EE;
  9088. t['Delta'] = 0x2206;
  9089. t['Deltagreek'] = 0x0394;
  9090. t['Dhook'] = 0x018A;
  9091. t['Dieresis'] = 0xF6CB;
  9092. t['DieresisAcute'] = 0xF6CC;
  9093. t['DieresisGrave'] = 0xF6CD;
  9094. t['Dieresissmall'] = 0xF7A8;
  9095. t['Digammagreek'] = 0x03DC;
  9096. t['Djecyrillic'] = 0x0402;
  9097. t['Dlinebelow'] = 0x1E0E;
  9098. t['Dmonospace'] = 0xFF24;
  9099. t['Dotaccentsmall'] = 0xF6F7;
  9100. t['Dslash'] = 0x0110;
  9101. t['Dsmall'] = 0xF764;
  9102. t['Dtopbar'] = 0x018B;
  9103. t['Dz'] = 0x01F2;
  9104. t['Dzcaron'] = 0x01C5;
  9105. t['Dzeabkhasiancyrillic'] = 0x04E0;
  9106. t['Dzecyrillic'] = 0x0405;
  9107. t['Dzhecyrillic'] = 0x040F;
  9108. t['E'] = 0x0045;
  9109. t['Eacute'] = 0x00C9;
  9110. t['Eacutesmall'] = 0xF7E9;
  9111. t['Ebreve'] = 0x0114;
  9112. t['Ecaron'] = 0x011A;
  9113. t['Ecedillabreve'] = 0x1E1C;
  9114. t['Echarmenian'] = 0x0535;
  9115. t['Ecircle'] = 0x24BA;
  9116. t['Ecircumflex'] = 0x00CA;
  9117. t['Ecircumflexacute'] = 0x1EBE;
  9118. t['Ecircumflexbelow'] = 0x1E18;
  9119. t['Ecircumflexdotbelow'] = 0x1EC6;
  9120. t['Ecircumflexgrave'] = 0x1EC0;
  9121. t['Ecircumflexhookabove'] = 0x1EC2;
  9122. t['Ecircumflexsmall'] = 0xF7EA;
  9123. t['Ecircumflextilde'] = 0x1EC4;
  9124. t['Ecyrillic'] = 0x0404;
  9125. t['Edblgrave'] = 0x0204;
  9126. t['Edieresis'] = 0x00CB;
  9127. t['Edieresissmall'] = 0xF7EB;
  9128. t['Edot'] = 0x0116;
  9129. t['Edotaccent'] = 0x0116;
  9130. t['Edotbelow'] = 0x1EB8;
  9131. t['Efcyrillic'] = 0x0424;
  9132. t['Egrave'] = 0x00C8;
  9133. t['Egravesmall'] = 0xF7E8;
  9134. t['Eharmenian'] = 0x0537;
  9135. t['Ehookabove'] = 0x1EBA;
  9136. t['Eightroman'] = 0x2167;
  9137. t['Einvertedbreve'] = 0x0206;
  9138. t['Eiotifiedcyrillic'] = 0x0464;
  9139. t['Elcyrillic'] = 0x041B;
  9140. t['Elevenroman'] = 0x216A;
  9141. t['Emacron'] = 0x0112;
  9142. t['Emacronacute'] = 0x1E16;
  9143. t['Emacrongrave'] = 0x1E14;
  9144. t['Emcyrillic'] = 0x041C;
  9145. t['Emonospace'] = 0xFF25;
  9146. t['Encyrillic'] = 0x041D;
  9147. t['Endescendercyrillic'] = 0x04A2;
  9148. t['Eng'] = 0x014A;
  9149. t['Enghecyrillic'] = 0x04A4;
  9150. t['Enhookcyrillic'] = 0x04C7;
  9151. t['Eogonek'] = 0x0118;
  9152. t['Eopen'] = 0x0190;
  9153. t['Epsilon'] = 0x0395;
  9154. t['Epsilontonos'] = 0x0388;
  9155. t['Ercyrillic'] = 0x0420;
  9156. t['Ereversed'] = 0x018E;
  9157. t['Ereversedcyrillic'] = 0x042D;
  9158. t['Escyrillic'] = 0x0421;
  9159. t['Esdescendercyrillic'] = 0x04AA;
  9160. t['Esh'] = 0x01A9;
  9161. t['Esmall'] = 0xF765;
  9162. t['Eta'] = 0x0397;
  9163. t['Etarmenian'] = 0x0538;
  9164. t['Etatonos'] = 0x0389;
  9165. t['Eth'] = 0x00D0;
  9166. t['Ethsmall'] = 0xF7F0;
  9167. t['Etilde'] = 0x1EBC;
  9168. t['Etildebelow'] = 0x1E1A;
  9169. t['Euro'] = 0x20AC;
  9170. t['Ezh'] = 0x01B7;
  9171. t['Ezhcaron'] = 0x01EE;
  9172. t['Ezhreversed'] = 0x01B8;
  9173. t['F'] = 0x0046;
  9174. t['Fcircle'] = 0x24BB;
  9175. t['Fdotaccent'] = 0x1E1E;
  9176. t['Feharmenian'] = 0x0556;
  9177. t['Feicoptic'] = 0x03E4;
  9178. t['Fhook'] = 0x0191;
  9179. t['Fitacyrillic'] = 0x0472;
  9180. t['Fiveroman'] = 0x2164;
  9181. t['Fmonospace'] = 0xFF26;
  9182. t['Fourroman'] = 0x2163;
  9183. t['Fsmall'] = 0xF766;
  9184. t['G'] = 0x0047;
  9185. t['GBsquare'] = 0x3387;
  9186. t['Gacute'] = 0x01F4;
  9187. t['Gamma'] = 0x0393;
  9188. t['Gammaafrican'] = 0x0194;
  9189. t['Gangiacoptic'] = 0x03EA;
  9190. t['Gbreve'] = 0x011E;
  9191. t['Gcaron'] = 0x01E6;
  9192. t['Gcedilla'] = 0x0122;
  9193. t['Gcircle'] = 0x24BC;
  9194. t['Gcircumflex'] = 0x011C;
  9195. t['Gcommaaccent'] = 0x0122;
  9196. t['Gdot'] = 0x0120;
  9197. t['Gdotaccent'] = 0x0120;
  9198. t['Gecyrillic'] = 0x0413;
  9199. t['Ghadarmenian'] = 0x0542;
  9200. t['Ghemiddlehookcyrillic'] = 0x0494;
  9201. t['Ghestrokecyrillic'] = 0x0492;
  9202. t['Gheupturncyrillic'] = 0x0490;
  9203. t['Ghook'] = 0x0193;
  9204. t['Gimarmenian'] = 0x0533;
  9205. t['Gjecyrillic'] = 0x0403;
  9206. t['Gmacron'] = 0x1E20;
  9207. t['Gmonospace'] = 0xFF27;
  9208. t['Grave'] = 0xF6CE;
  9209. t['Gravesmall'] = 0xF760;
  9210. t['Gsmall'] = 0xF767;
  9211. t['Gsmallhook'] = 0x029B;
  9212. t['Gstroke'] = 0x01E4;
  9213. t['H'] = 0x0048;
  9214. t['H18533'] = 0x25CF;
  9215. t['H18543'] = 0x25AA;
  9216. t['H18551'] = 0x25AB;
  9217. t['H22073'] = 0x25A1;
  9218. t['HPsquare'] = 0x33CB;
  9219. t['Haabkhasiancyrillic'] = 0x04A8;
  9220. t['Hadescendercyrillic'] = 0x04B2;
  9221. t['Hardsigncyrillic'] = 0x042A;
  9222. t['Hbar'] = 0x0126;
  9223. t['Hbrevebelow'] = 0x1E2A;
  9224. t['Hcedilla'] = 0x1E28;
  9225. t['Hcircle'] = 0x24BD;
  9226. t['Hcircumflex'] = 0x0124;
  9227. t['Hdieresis'] = 0x1E26;
  9228. t['Hdotaccent'] = 0x1E22;
  9229. t['Hdotbelow'] = 0x1E24;
  9230. t['Hmonospace'] = 0xFF28;
  9231. t['Hoarmenian'] = 0x0540;
  9232. t['Horicoptic'] = 0x03E8;
  9233. t['Hsmall'] = 0xF768;
  9234. t['Hungarumlaut'] = 0xF6CF;
  9235. t['Hungarumlautsmall'] = 0xF6F8;
  9236. t['Hzsquare'] = 0x3390;
  9237. t['I'] = 0x0049;
  9238. t['IAcyrillic'] = 0x042F;
  9239. t['IJ'] = 0x0132;
  9240. t['IUcyrillic'] = 0x042E;
  9241. t['Iacute'] = 0x00CD;
  9242. t['Iacutesmall'] = 0xF7ED;
  9243. t['Ibreve'] = 0x012C;
  9244. t['Icaron'] = 0x01CF;
  9245. t['Icircle'] = 0x24BE;
  9246. t['Icircumflex'] = 0x00CE;
  9247. t['Icircumflexsmall'] = 0xF7EE;
  9248. t['Icyrillic'] = 0x0406;
  9249. t['Idblgrave'] = 0x0208;
  9250. t['Idieresis'] = 0x00CF;
  9251. t['Idieresisacute'] = 0x1E2E;
  9252. t['Idieresiscyrillic'] = 0x04E4;
  9253. t['Idieresissmall'] = 0xF7EF;
  9254. t['Idot'] = 0x0130;
  9255. t['Idotaccent'] = 0x0130;
  9256. t['Idotbelow'] = 0x1ECA;
  9257. t['Iebrevecyrillic'] = 0x04D6;
  9258. t['Iecyrillic'] = 0x0415;
  9259. t['Ifraktur'] = 0x2111;
  9260. t['Igrave'] = 0x00CC;
  9261. t['Igravesmall'] = 0xF7EC;
  9262. t['Ihookabove'] = 0x1EC8;
  9263. t['Iicyrillic'] = 0x0418;
  9264. t['Iinvertedbreve'] = 0x020A;
  9265. t['Iishortcyrillic'] = 0x0419;
  9266. t['Imacron'] = 0x012A;
  9267. t['Imacroncyrillic'] = 0x04E2;
  9268. t['Imonospace'] = 0xFF29;
  9269. t['Iniarmenian'] = 0x053B;
  9270. t['Iocyrillic'] = 0x0401;
  9271. t['Iogonek'] = 0x012E;
  9272. t['Iota'] = 0x0399;
  9273. t['Iotaafrican'] = 0x0196;
  9274. t['Iotadieresis'] = 0x03AA;
  9275. t['Iotatonos'] = 0x038A;
  9276. t['Ismall'] = 0xF769;
  9277. t['Istroke'] = 0x0197;
  9278. t['Itilde'] = 0x0128;
  9279. t['Itildebelow'] = 0x1E2C;
  9280. t['Izhitsacyrillic'] = 0x0474;
  9281. t['Izhitsadblgravecyrillic'] = 0x0476;
  9282. t['J'] = 0x004A;
  9283. t['Jaarmenian'] = 0x0541;
  9284. t['Jcircle'] = 0x24BF;
  9285. t['Jcircumflex'] = 0x0134;
  9286. t['Jecyrillic'] = 0x0408;
  9287. t['Jheharmenian'] = 0x054B;
  9288. t['Jmonospace'] = 0xFF2A;
  9289. t['Jsmall'] = 0xF76A;
  9290. t['K'] = 0x004B;
  9291. t['KBsquare'] = 0x3385;
  9292. t['KKsquare'] = 0x33CD;
  9293. t['Kabashkircyrillic'] = 0x04A0;
  9294. t['Kacute'] = 0x1E30;
  9295. t['Kacyrillic'] = 0x041A;
  9296. t['Kadescendercyrillic'] = 0x049A;
  9297. t['Kahookcyrillic'] = 0x04C3;
  9298. t['Kappa'] = 0x039A;
  9299. t['Kastrokecyrillic'] = 0x049E;
  9300. t['Kaverticalstrokecyrillic'] = 0x049C;
  9301. t['Kcaron'] = 0x01E8;
  9302. t['Kcedilla'] = 0x0136;
  9303. t['Kcircle'] = 0x24C0;
  9304. t['Kcommaaccent'] = 0x0136;
  9305. t['Kdotbelow'] = 0x1E32;
  9306. t['Keharmenian'] = 0x0554;
  9307. t['Kenarmenian'] = 0x053F;
  9308. t['Khacyrillic'] = 0x0425;
  9309. t['Kheicoptic'] = 0x03E6;
  9310. t['Khook'] = 0x0198;
  9311. t['Kjecyrillic'] = 0x040C;
  9312. t['Klinebelow'] = 0x1E34;
  9313. t['Kmonospace'] = 0xFF2B;
  9314. t['Koppacyrillic'] = 0x0480;
  9315. t['Koppagreek'] = 0x03DE;
  9316. t['Ksicyrillic'] = 0x046E;
  9317. t['Ksmall'] = 0xF76B;
  9318. t['L'] = 0x004C;
  9319. t['LJ'] = 0x01C7;
  9320. t['LL'] = 0xF6BF;
  9321. t['Lacute'] = 0x0139;
  9322. t['Lambda'] = 0x039B;
  9323. t['Lcaron'] = 0x013D;
  9324. t['Lcedilla'] = 0x013B;
  9325. t['Lcircle'] = 0x24C1;
  9326. t['Lcircumflexbelow'] = 0x1E3C;
  9327. t['Lcommaaccent'] = 0x013B;
  9328. t['Ldot'] = 0x013F;
  9329. t['Ldotaccent'] = 0x013F;
  9330. t['Ldotbelow'] = 0x1E36;
  9331. t['Ldotbelowmacron'] = 0x1E38;
  9332. t['Liwnarmenian'] = 0x053C;
  9333. t['Lj'] = 0x01C8;
  9334. t['Ljecyrillic'] = 0x0409;
  9335. t['Llinebelow'] = 0x1E3A;
  9336. t['Lmonospace'] = 0xFF2C;
  9337. t['Lslash'] = 0x0141;
  9338. t['Lslashsmall'] = 0xF6F9;
  9339. t['Lsmall'] = 0xF76C;
  9340. t['M'] = 0x004D;
  9341. t['MBsquare'] = 0x3386;
  9342. t['Macron'] = 0xF6D0;
  9343. t['Macronsmall'] = 0xF7AF;
  9344. t['Macute'] = 0x1E3E;
  9345. t['Mcircle'] = 0x24C2;
  9346. t['Mdotaccent'] = 0x1E40;
  9347. t['Mdotbelow'] = 0x1E42;
  9348. t['Menarmenian'] = 0x0544;
  9349. t['Mmonospace'] = 0xFF2D;
  9350. t['Msmall'] = 0xF76D;
  9351. t['Mturned'] = 0x019C;
  9352. t['Mu'] = 0x039C;
  9353. t['N'] = 0x004E;
  9354. t['NJ'] = 0x01CA;
  9355. t['Nacute'] = 0x0143;
  9356. t['Ncaron'] = 0x0147;
  9357. t['Ncedilla'] = 0x0145;
  9358. t['Ncircle'] = 0x24C3;
  9359. t['Ncircumflexbelow'] = 0x1E4A;
  9360. t['Ncommaaccent'] = 0x0145;
  9361. t['Ndotaccent'] = 0x1E44;
  9362. t['Ndotbelow'] = 0x1E46;
  9363. t['Nhookleft'] = 0x019D;
  9364. t['Nineroman'] = 0x2168;
  9365. t['Nj'] = 0x01CB;
  9366. t['Njecyrillic'] = 0x040A;
  9367. t['Nlinebelow'] = 0x1E48;
  9368. t['Nmonospace'] = 0xFF2E;
  9369. t['Nowarmenian'] = 0x0546;
  9370. t['Nsmall'] = 0xF76E;
  9371. t['Ntilde'] = 0x00D1;
  9372. t['Ntildesmall'] = 0xF7F1;
  9373. t['Nu'] = 0x039D;
  9374. t['O'] = 0x004F;
  9375. t['OE'] = 0x0152;
  9376. t['OEsmall'] = 0xF6FA;
  9377. t['Oacute'] = 0x00D3;
  9378. t['Oacutesmall'] = 0xF7F3;
  9379. t['Obarredcyrillic'] = 0x04E8;
  9380. t['Obarreddieresiscyrillic'] = 0x04EA;
  9381. t['Obreve'] = 0x014E;
  9382. t['Ocaron'] = 0x01D1;
  9383. t['Ocenteredtilde'] = 0x019F;
  9384. t['Ocircle'] = 0x24C4;
  9385. t['Ocircumflex'] = 0x00D4;
  9386. t['Ocircumflexacute'] = 0x1ED0;
  9387. t['Ocircumflexdotbelow'] = 0x1ED8;
  9388. t['Ocircumflexgrave'] = 0x1ED2;
  9389. t['Ocircumflexhookabove'] = 0x1ED4;
  9390. t['Ocircumflexsmall'] = 0xF7F4;
  9391. t['Ocircumflextilde'] = 0x1ED6;
  9392. t['Ocyrillic'] = 0x041E;
  9393. t['Odblacute'] = 0x0150;
  9394. t['Odblgrave'] = 0x020C;
  9395. t['Odieresis'] = 0x00D6;
  9396. t['Odieresiscyrillic'] = 0x04E6;
  9397. t['Odieresissmall'] = 0xF7F6;
  9398. t['Odotbelow'] = 0x1ECC;
  9399. t['Ogoneksmall'] = 0xF6FB;
  9400. t['Ograve'] = 0x00D2;
  9401. t['Ogravesmall'] = 0xF7F2;
  9402. t['Oharmenian'] = 0x0555;
  9403. t['Ohm'] = 0x2126;
  9404. t['Ohookabove'] = 0x1ECE;
  9405. t['Ohorn'] = 0x01A0;
  9406. t['Ohornacute'] = 0x1EDA;
  9407. t['Ohorndotbelow'] = 0x1EE2;
  9408. t['Ohorngrave'] = 0x1EDC;
  9409. t['Ohornhookabove'] = 0x1EDE;
  9410. t['Ohorntilde'] = 0x1EE0;
  9411. t['Ohungarumlaut'] = 0x0150;
  9412. t['Oi'] = 0x01A2;
  9413. t['Oinvertedbreve'] = 0x020E;
  9414. t['Omacron'] = 0x014C;
  9415. t['Omacronacute'] = 0x1E52;
  9416. t['Omacrongrave'] = 0x1E50;
  9417. t['Omega'] = 0x2126;
  9418. t['Omegacyrillic'] = 0x0460;
  9419. t['Omegagreek'] = 0x03A9;
  9420. t['Omegaroundcyrillic'] = 0x047A;
  9421. t['Omegatitlocyrillic'] = 0x047C;
  9422. t['Omegatonos'] = 0x038F;
  9423. t['Omicron'] = 0x039F;
  9424. t['Omicrontonos'] = 0x038C;
  9425. t['Omonospace'] = 0xFF2F;
  9426. t['Oneroman'] = 0x2160;
  9427. t['Oogonek'] = 0x01EA;
  9428. t['Oogonekmacron'] = 0x01EC;
  9429. t['Oopen'] = 0x0186;
  9430. t['Oslash'] = 0x00D8;
  9431. t['Oslashacute'] = 0x01FE;
  9432. t['Oslashsmall'] = 0xF7F8;
  9433. t['Osmall'] = 0xF76F;
  9434. t['Ostrokeacute'] = 0x01FE;
  9435. t['Otcyrillic'] = 0x047E;
  9436. t['Otilde'] = 0x00D5;
  9437. t['Otildeacute'] = 0x1E4C;
  9438. t['Otildedieresis'] = 0x1E4E;
  9439. t['Otildesmall'] = 0xF7F5;
  9440. t['P'] = 0x0050;
  9441. t['Pacute'] = 0x1E54;
  9442. t['Pcircle'] = 0x24C5;
  9443. t['Pdotaccent'] = 0x1E56;
  9444. t['Pecyrillic'] = 0x041F;
  9445. t['Peharmenian'] = 0x054A;
  9446. t['Pemiddlehookcyrillic'] = 0x04A6;
  9447. t['Phi'] = 0x03A6;
  9448. t['Phook'] = 0x01A4;
  9449. t['Pi'] = 0x03A0;
  9450. t['Piwrarmenian'] = 0x0553;
  9451. t['Pmonospace'] = 0xFF30;
  9452. t['Psi'] = 0x03A8;
  9453. t['Psicyrillic'] = 0x0470;
  9454. t['Psmall'] = 0xF770;
  9455. t['Q'] = 0x0051;
  9456. t['Qcircle'] = 0x24C6;
  9457. t['Qmonospace'] = 0xFF31;
  9458. t['Qsmall'] = 0xF771;
  9459. t['R'] = 0x0052;
  9460. t['Raarmenian'] = 0x054C;
  9461. t['Racute'] = 0x0154;
  9462. t['Rcaron'] = 0x0158;
  9463. t['Rcedilla'] = 0x0156;
  9464. t['Rcircle'] = 0x24C7;
  9465. t['Rcommaaccent'] = 0x0156;
  9466. t['Rdblgrave'] = 0x0210;
  9467. t['Rdotaccent'] = 0x1E58;
  9468. t['Rdotbelow'] = 0x1E5A;
  9469. t['Rdotbelowmacron'] = 0x1E5C;
  9470. t['Reharmenian'] = 0x0550;
  9471. t['Rfraktur'] = 0x211C;
  9472. t['Rho'] = 0x03A1;
  9473. t['Ringsmall'] = 0xF6FC;
  9474. t['Rinvertedbreve'] = 0x0212;
  9475. t['Rlinebelow'] = 0x1E5E;
  9476. t['Rmonospace'] = 0xFF32;
  9477. t['Rsmall'] = 0xF772;
  9478. t['Rsmallinverted'] = 0x0281;
  9479. t['Rsmallinvertedsuperior'] = 0x02B6;
  9480. t['S'] = 0x0053;
  9481. t['SF010000'] = 0x250C;
  9482. t['SF020000'] = 0x2514;
  9483. t['SF030000'] = 0x2510;
  9484. t['SF040000'] = 0x2518;
  9485. t['SF050000'] = 0x253C;
  9486. t['SF060000'] = 0x252C;
  9487. t['SF070000'] = 0x2534;
  9488. t['SF080000'] = 0x251C;
  9489. t['SF090000'] = 0x2524;
  9490. t['SF100000'] = 0x2500;
  9491. t['SF110000'] = 0x2502;
  9492. t['SF190000'] = 0x2561;
  9493. t['SF200000'] = 0x2562;
  9494. t['SF210000'] = 0x2556;
  9495. t['SF220000'] = 0x2555;
  9496. t['SF230000'] = 0x2563;
  9497. t['SF240000'] = 0x2551;
  9498. t['SF250000'] = 0x2557;
  9499. t['SF260000'] = 0x255D;
  9500. t['SF270000'] = 0x255C;
  9501. t['SF280000'] = 0x255B;
  9502. t['SF360000'] = 0x255E;
  9503. t['SF370000'] = 0x255F;
  9504. t['SF380000'] = 0x255A;
  9505. t['SF390000'] = 0x2554;
  9506. t['SF400000'] = 0x2569;
  9507. t['SF410000'] = 0x2566;
  9508. t['SF420000'] = 0x2560;
  9509. t['SF430000'] = 0x2550;
  9510. t['SF440000'] = 0x256C;
  9511. t['SF450000'] = 0x2567;
  9512. t['SF460000'] = 0x2568;
  9513. t['SF470000'] = 0x2564;
  9514. t['SF480000'] = 0x2565;
  9515. t['SF490000'] = 0x2559;
  9516. t['SF500000'] = 0x2558;
  9517. t['SF510000'] = 0x2552;
  9518. t['SF520000'] = 0x2553;
  9519. t['SF530000'] = 0x256B;
  9520. t['SF540000'] = 0x256A;
  9521. t['Sacute'] = 0x015A;
  9522. t['Sacutedotaccent'] = 0x1E64;
  9523. t['Sampigreek'] = 0x03E0;
  9524. t['Scaron'] = 0x0160;
  9525. t['Scarondotaccent'] = 0x1E66;
  9526. t['Scaronsmall'] = 0xF6FD;
  9527. t['Scedilla'] = 0x015E;
  9528. t['Schwa'] = 0x018F;
  9529. t['Schwacyrillic'] = 0x04D8;
  9530. t['Schwadieresiscyrillic'] = 0x04DA;
  9531. t['Scircle'] = 0x24C8;
  9532. t['Scircumflex'] = 0x015C;
  9533. t['Scommaaccent'] = 0x0218;
  9534. t['Sdotaccent'] = 0x1E60;
  9535. t['Sdotbelow'] = 0x1E62;
  9536. t['Sdotbelowdotaccent'] = 0x1E68;
  9537. t['Seharmenian'] = 0x054D;
  9538. t['Sevenroman'] = 0x2166;
  9539. t['Shaarmenian'] = 0x0547;
  9540. t['Shacyrillic'] = 0x0428;
  9541. t['Shchacyrillic'] = 0x0429;
  9542. t['Sheicoptic'] = 0x03E2;
  9543. t['Shhacyrillic'] = 0x04BA;
  9544. t['Shimacoptic'] = 0x03EC;
  9545. t['Sigma'] = 0x03A3;
  9546. t['Sixroman'] = 0x2165;
  9547. t['Smonospace'] = 0xFF33;
  9548. t['Softsigncyrillic'] = 0x042C;
  9549. t['Ssmall'] = 0xF773;
  9550. t['Stigmagreek'] = 0x03DA;
  9551. t['T'] = 0x0054;
  9552. t['Tau'] = 0x03A4;
  9553. t['Tbar'] = 0x0166;
  9554. t['Tcaron'] = 0x0164;
  9555. t['Tcedilla'] = 0x0162;
  9556. t['Tcircle'] = 0x24C9;
  9557. t['Tcircumflexbelow'] = 0x1E70;
  9558. t['Tcommaaccent'] = 0x0162;
  9559. t['Tdotaccent'] = 0x1E6A;
  9560. t['Tdotbelow'] = 0x1E6C;
  9561. t['Tecyrillic'] = 0x0422;
  9562. t['Tedescendercyrillic'] = 0x04AC;
  9563. t['Tenroman'] = 0x2169;
  9564. t['Tetsecyrillic'] = 0x04B4;
  9565. t['Theta'] = 0x0398;
  9566. t['Thook'] = 0x01AC;
  9567. t['Thorn'] = 0x00DE;
  9568. t['Thornsmall'] = 0xF7FE;
  9569. t['Threeroman'] = 0x2162;
  9570. t['Tildesmall'] = 0xF6FE;
  9571. t['Tiwnarmenian'] = 0x054F;
  9572. t['Tlinebelow'] = 0x1E6E;
  9573. t['Tmonospace'] = 0xFF34;
  9574. t['Toarmenian'] = 0x0539;
  9575. t['Tonefive'] = 0x01BC;
  9576. t['Tonesix'] = 0x0184;
  9577. t['Tonetwo'] = 0x01A7;
  9578. t['Tretroflexhook'] = 0x01AE;
  9579. t['Tsecyrillic'] = 0x0426;
  9580. t['Tshecyrillic'] = 0x040B;
  9581. t['Tsmall'] = 0xF774;
  9582. t['Twelveroman'] = 0x216B;
  9583. t['Tworoman'] = 0x2161;
  9584. t['U'] = 0x0055;
  9585. t['Uacute'] = 0x00DA;
  9586. t['Uacutesmall'] = 0xF7FA;
  9587. t['Ubreve'] = 0x016C;
  9588. t['Ucaron'] = 0x01D3;
  9589. t['Ucircle'] = 0x24CA;
  9590. t['Ucircumflex'] = 0x00DB;
  9591. t['Ucircumflexbelow'] = 0x1E76;
  9592. t['Ucircumflexsmall'] = 0xF7FB;
  9593. t['Ucyrillic'] = 0x0423;
  9594. t['Udblacute'] = 0x0170;
  9595. t['Udblgrave'] = 0x0214;
  9596. t['Udieresis'] = 0x00DC;
  9597. t['Udieresisacute'] = 0x01D7;
  9598. t['Udieresisbelow'] = 0x1E72;
  9599. t['Udieresiscaron'] = 0x01D9;
  9600. t['Udieresiscyrillic'] = 0x04F0;
  9601. t['Udieresisgrave'] = 0x01DB;
  9602. t['Udieresismacron'] = 0x01D5;
  9603. t['Udieresissmall'] = 0xF7FC;
  9604. t['Udotbelow'] = 0x1EE4;
  9605. t['Ugrave'] = 0x00D9;
  9606. t['Ugravesmall'] = 0xF7F9;
  9607. t['Uhookabove'] = 0x1EE6;
  9608. t['Uhorn'] = 0x01AF;
  9609. t['Uhornacute'] = 0x1EE8;
  9610. t['Uhorndotbelow'] = 0x1EF0;
  9611. t['Uhorngrave'] = 0x1EEA;
  9612. t['Uhornhookabove'] = 0x1EEC;
  9613. t['Uhorntilde'] = 0x1EEE;
  9614. t['Uhungarumlaut'] = 0x0170;
  9615. t['Uhungarumlautcyrillic'] = 0x04F2;
  9616. t['Uinvertedbreve'] = 0x0216;
  9617. t['Ukcyrillic'] = 0x0478;
  9618. t['Umacron'] = 0x016A;
  9619. t['Umacroncyrillic'] = 0x04EE;
  9620. t['Umacrondieresis'] = 0x1E7A;
  9621. t['Umonospace'] = 0xFF35;
  9622. t['Uogonek'] = 0x0172;
  9623. t['Upsilon'] = 0x03A5;
  9624. t['Upsilon1'] = 0x03D2;
  9625. t['Upsilonacutehooksymbolgreek'] = 0x03D3;
  9626. t['Upsilonafrican'] = 0x01B1;
  9627. t['Upsilondieresis'] = 0x03AB;
  9628. t['Upsilondieresishooksymbolgreek'] = 0x03D4;
  9629. t['Upsilonhooksymbol'] = 0x03D2;
  9630. t['Upsilontonos'] = 0x038E;
  9631. t['Uring'] = 0x016E;
  9632. t['Ushortcyrillic'] = 0x040E;
  9633. t['Usmall'] = 0xF775;
  9634. t['Ustraightcyrillic'] = 0x04AE;
  9635. t['Ustraightstrokecyrillic'] = 0x04B0;
  9636. t['Utilde'] = 0x0168;
  9637. t['Utildeacute'] = 0x1E78;
  9638. t['Utildebelow'] = 0x1E74;
  9639. t['V'] = 0x0056;
  9640. t['Vcircle'] = 0x24CB;
  9641. t['Vdotbelow'] = 0x1E7E;
  9642. t['Vecyrillic'] = 0x0412;
  9643. t['Vewarmenian'] = 0x054E;
  9644. t['Vhook'] = 0x01B2;
  9645. t['Vmonospace'] = 0xFF36;
  9646. t['Voarmenian'] = 0x0548;
  9647. t['Vsmall'] = 0xF776;
  9648. t['Vtilde'] = 0x1E7C;
  9649. t['W'] = 0x0057;
  9650. t['Wacute'] = 0x1E82;
  9651. t['Wcircle'] = 0x24CC;
  9652. t['Wcircumflex'] = 0x0174;
  9653. t['Wdieresis'] = 0x1E84;
  9654. t['Wdotaccent'] = 0x1E86;
  9655. t['Wdotbelow'] = 0x1E88;
  9656. t['Wgrave'] = 0x1E80;
  9657. t['Wmonospace'] = 0xFF37;
  9658. t['Wsmall'] = 0xF777;
  9659. t['X'] = 0x0058;
  9660. t['Xcircle'] = 0x24CD;
  9661. t['Xdieresis'] = 0x1E8C;
  9662. t['Xdotaccent'] = 0x1E8A;
  9663. t['Xeharmenian'] = 0x053D;
  9664. t['Xi'] = 0x039E;
  9665. t['Xmonospace'] = 0xFF38;
  9666. t['Xsmall'] = 0xF778;
  9667. t['Y'] = 0x0059;
  9668. t['Yacute'] = 0x00DD;
  9669. t['Yacutesmall'] = 0xF7FD;
  9670. t['Yatcyrillic'] = 0x0462;
  9671. t['Ycircle'] = 0x24CE;
  9672. t['Ycircumflex'] = 0x0176;
  9673. t['Ydieresis'] = 0x0178;
  9674. t['Ydieresissmall'] = 0xF7FF;
  9675. t['Ydotaccent'] = 0x1E8E;
  9676. t['Ydotbelow'] = 0x1EF4;
  9677. t['Yericyrillic'] = 0x042B;
  9678. t['Yerudieresiscyrillic'] = 0x04F8;
  9679. t['Ygrave'] = 0x1EF2;
  9680. t['Yhook'] = 0x01B3;
  9681. t['Yhookabove'] = 0x1EF6;
  9682. t['Yiarmenian'] = 0x0545;
  9683. t['Yicyrillic'] = 0x0407;
  9684. t['Yiwnarmenian'] = 0x0552;
  9685. t['Ymonospace'] = 0xFF39;
  9686. t['Ysmall'] = 0xF779;
  9687. t['Ytilde'] = 0x1EF8;
  9688. t['Yusbigcyrillic'] = 0x046A;
  9689. t['Yusbigiotifiedcyrillic'] = 0x046C;
  9690. t['Yuslittlecyrillic'] = 0x0466;
  9691. t['Yuslittleiotifiedcyrillic'] = 0x0468;
  9692. t['Z'] = 0x005A;
  9693. t['Zaarmenian'] = 0x0536;
  9694. t['Zacute'] = 0x0179;
  9695. t['Zcaron'] = 0x017D;
  9696. t['Zcaronsmall'] = 0xF6FF;
  9697. t['Zcircle'] = 0x24CF;
  9698. t['Zcircumflex'] = 0x1E90;
  9699. t['Zdot'] = 0x017B;
  9700. t['Zdotaccent'] = 0x017B;
  9701. t['Zdotbelow'] = 0x1E92;
  9702. t['Zecyrillic'] = 0x0417;
  9703. t['Zedescendercyrillic'] = 0x0498;
  9704. t['Zedieresiscyrillic'] = 0x04DE;
  9705. t['Zeta'] = 0x0396;
  9706. t['Zhearmenian'] = 0x053A;
  9707. t['Zhebrevecyrillic'] = 0x04C1;
  9708. t['Zhecyrillic'] = 0x0416;
  9709. t['Zhedescendercyrillic'] = 0x0496;
  9710. t['Zhedieresiscyrillic'] = 0x04DC;
  9711. t['Zlinebelow'] = 0x1E94;
  9712. t['Zmonospace'] = 0xFF3A;
  9713. t['Zsmall'] = 0xF77A;
  9714. t['Zstroke'] = 0x01B5;
  9715. t['a'] = 0x0061;
  9716. t['aabengali'] = 0x0986;
  9717. t['aacute'] = 0x00E1;
  9718. t['aadeva'] = 0x0906;
  9719. t['aagujarati'] = 0x0A86;
  9720. t['aagurmukhi'] = 0x0A06;
  9721. t['aamatragurmukhi'] = 0x0A3E;
  9722. t['aarusquare'] = 0x3303;
  9723. t['aavowelsignbengali'] = 0x09BE;
  9724. t['aavowelsigndeva'] = 0x093E;
  9725. t['aavowelsigngujarati'] = 0x0ABE;
  9726. t['abbreviationmarkarmenian'] = 0x055F;
  9727. t['abbreviationsigndeva'] = 0x0970;
  9728. t['abengali'] = 0x0985;
  9729. t['abopomofo'] = 0x311A;
  9730. t['abreve'] = 0x0103;
  9731. t['abreveacute'] = 0x1EAF;
  9732. t['abrevecyrillic'] = 0x04D1;
  9733. t['abrevedotbelow'] = 0x1EB7;
  9734. t['abrevegrave'] = 0x1EB1;
  9735. t['abrevehookabove'] = 0x1EB3;
  9736. t['abrevetilde'] = 0x1EB5;
  9737. t['acaron'] = 0x01CE;
  9738. t['acircle'] = 0x24D0;
  9739. t['acircumflex'] = 0x00E2;
  9740. t['acircumflexacute'] = 0x1EA5;
  9741. t['acircumflexdotbelow'] = 0x1EAD;
  9742. t['acircumflexgrave'] = 0x1EA7;
  9743. t['acircumflexhookabove'] = 0x1EA9;
  9744. t['acircumflextilde'] = 0x1EAB;
  9745. t['acute'] = 0x00B4;
  9746. t['acutebelowcmb'] = 0x0317;
  9747. t['acutecmb'] = 0x0301;
  9748. t['acutecomb'] = 0x0301;
  9749. t['acutedeva'] = 0x0954;
  9750. t['acutelowmod'] = 0x02CF;
  9751. t['acutetonecmb'] = 0x0341;
  9752. t['acyrillic'] = 0x0430;
  9753. t['adblgrave'] = 0x0201;
  9754. t['addakgurmukhi'] = 0x0A71;
  9755. t['adeva'] = 0x0905;
  9756. t['adieresis'] = 0x00E4;
  9757. t['adieresiscyrillic'] = 0x04D3;
  9758. t['adieresismacron'] = 0x01DF;
  9759. t['adotbelow'] = 0x1EA1;
  9760. t['adotmacron'] = 0x01E1;
  9761. t['ae'] = 0x00E6;
  9762. t['aeacute'] = 0x01FD;
  9763. t['aekorean'] = 0x3150;
  9764. t['aemacron'] = 0x01E3;
  9765. t['afii00208'] = 0x2015;
  9766. t['afii08941'] = 0x20A4;
  9767. t['afii10017'] = 0x0410;
  9768. t['afii10018'] = 0x0411;
  9769. t['afii10019'] = 0x0412;
  9770. t['afii10020'] = 0x0413;
  9771. t['afii10021'] = 0x0414;
  9772. t['afii10022'] = 0x0415;
  9773. t['afii10023'] = 0x0401;
  9774. t['afii10024'] = 0x0416;
  9775. t['afii10025'] = 0x0417;
  9776. t['afii10026'] = 0x0418;
  9777. t['afii10027'] = 0x0419;
  9778. t['afii10028'] = 0x041A;
  9779. t['afii10029'] = 0x041B;
  9780. t['afii10030'] = 0x041C;
  9781. t['afii10031'] = 0x041D;
  9782. t['afii10032'] = 0x041E;
  9783. t['afii10033'] = 0x041F;
  9784. t['afii10034'] = 0x0420;
  9785. t['afii10035'] = 0x0421;
  9786. t['afii10036'] = 0x0422;
  9787. t['afii10037'] = 0x0423;
  9788. t['afii10038'] = 0x0424;
  9789. t['afii10039'] = 0x0425;
  9790. t['afii10040'] = 0x0426;
  9791. t['afii10041'] = 0x0427;
  9792. t['afii10042'] = 0x0428;
  9793. t['afii10043'] = 0x0429;
  9794. t['afii10044'] = 0x042A;
  9795. t['afii10045'] = 0x042B;
  9796. t['afii10046'] = 0x042C;
  9797. t['afii10047'] = 0x042D;
  9798. t['afii10048'] = 0x042E;
  9799. t['afii10049'] = 0x042F;
  9800. t['afii10050'] = 0x0490;
  9801. t['afii10051'] = 0x0402;
  9802. t['afii10052'] = 0x0403;
  9803. t['afii10053'] = 0x0404;
  9804. t['afii10054'] = 0x0405;
  9805. t['afii10055'] = 0x0406;
  9806. t['afii10056'] = 0x0407;
  9807. t['afii10057'] = 0x0408;
  9808. t['afii10058'] = 0x0409;
  9809. t['afii10059'] = 0x040A;
  9810. t['afii10060'] = 0x040B;
  9811. t['afii10061'] = 0x040C;
  9812. t['afii10062'] = 0x040E;
  9813. t['afii10063'] = 0xF6C4;
  9814. t['afii10064'] = 0xF6C5;
  9815. t['afii10065'] = 0x0430;
  9816. t['afii10066'] = 0x0431;
  9817. t['afii10067'] = 0x0432;
  9818. t['afii10068'] = 0x0433;
  9819. t['afii10069'] = 0x0434;
  9820. t['afii10070'] = 0x0435;
  9821. t['afii10071'] = 0x0451;
  9822. t['afii10072'] = 0x0436;
  9823. t['afii10073'] = 0x0437;
  9824. t['afii10074'] = 0x0438;
  9825. t['afii10075'] = 0x0439;
  9826. t['afii10076'] = 0x043A;
  9827. t['afii10077'] = 0x043B;
  9828. t['afii10078'] = 0x043C;
  9829. t['afii10079'] = 0x043D;
  9830. t['afii10080'] = 0x043E;
  9831. t['afii10081'] = 0x043F;
  9832. t['afii10082'] = 0x0440;
  9833. t['afii10083'] = 0x0441;
  9834. t['afii10084'] = 0x0442;
  9835. t['afii10085'] = 0x0443;
  9836. t['afii10086'] = 0x0444;
  9837. t['afii10087'] = 0x0445;
  9838. t['afii10088'] = 0x0446;
  9839. t['afii10089'] = 0x0447;
  9840. t['afii10090'] = 0x0448;
  9841. t['afii10091'] = 0x0449;
  9842. t['afii10092'] = 0x044A;
  9843. t['afii10093'] = 0x044B;
  9844. t['afii10094'] = 0x044C;
  9845. t['afii10095'] = 0x044D;
  9846. t['afii10096'] = 0x044E;
  9847. t['afii10097'] = 0x044F;
  9848. t['afii10098'] = 0x0491;
  9849. t['afii10099'] = 0x0452;
  9850. t['afii10100'] = 0x0453;
  9851. t['afii10101'] = 0x0454;
  9852. t['afii10102'] = 0x0455;
  9853. t['afii10103'] = 0x0456;
  9854. t['afii10104'] = 0x0457;
  9855. t['afii10105'] = 0x0458;
  9856. t['afii10106'] = 0x0459;
  9857. t['afii10107'] = 0x045A;
  9858. t['afii10108'] = 0x045B;
  9859. t['afii10109'] = 0x045C;
  9860. t['afii10110'] = 0x045E;
  9861. t['afii10145'] = 0x040F;
  9862. t['afii10146'] = 0x0462;
  9863. t['afii10147'] = 0x0472;
  9864. t['afii10148'] = 0x0474;
  9865. t['afii10192'] = 0xF6C6;
  9866. t['afii10193'] = 0x045F;
  9867. t['afii10194'] = 0x0463;
  9868. t['afii10195'] = 0x0473;
  9869. t['afii10196'] = 0x0475;
  9870. t['afii10831'] = 0xF6C7;
  9871. t['afii10832'] = 0xF6C8;
  9872. t['afii10846'] = 0x04D9;
  9873. t['afii299'] = 0x200E;
  9874. t['afii300'] = 0x200F;
  9875. t['afii301'] = 0x200D;
  9876. t['afii57381'] = 0x066A;
  9877. t['afii57388'] = 0x060C;
  9878. t['afii57392'] = 0x0660;
  9879. t['afii57393'] = 0x0661;
  9880. t['afii57394'] = 0x0662;
  9881. t['afii57395'] = 0x0663;
  9882. t['afii57396'] = 0x0664;
  9883. t['afii57397'] = 0x0665;
  9884. t['afii57398'] = 0x0666;
  9885. t['afii57399'] = 0x0667;
  9886. t['afii57400'] = 0x0668;
  9887. t['afii57401'] = 0x0669;
  9888. t['afii57403'] = 0x061B;
  9889. t['afii57407'] = 0x061F;
  9890. t['afii57409'] = 0x0621;
  9891. t['afii57410'] = 0x0622;
  9892. t['afii57411'] = 0x0623;
  9893. t['afii57412'] = 0x0624;
  9894. t['afii57413'] = 0x0625;
  9895. t['afii57414'] = 0x0626;
  9896. t['afii57415'] = 0x0627;
  9897. t['afii57416'] = 0x0628;
  9898. t['afii57417'] = 0x0629;
  9899. t['afii57418'] = 0x062A;
  9900. t['afii57419'] = 0x062B;
  9901. t['afii57420'] = 0x062C;
  9902. t['afii57421'] = 0x062D;
  9903. t['afii57422'] = 0x062E;
  9904. t['afii57423'] = 0x062F;
  9905. t['afii57424'] = 0x0630;
  9906. t['afii57425'] = 0x0631;
  9907. t['afii57426'] = 0x0632;
  9908. t['afii57427'] = 0x0633;
  9909. t['afii57428'] = 0x0634;
  9910. t['afii57429'] = 0x0635;
  9911. t['afii57430'] = 0x0636;
  9912. t['afii57431'] = 0x0637;
  9913. t['afii57432'] = 0x0638;
  9914. t['afii57433'] = 0x0639;
  9915. t['afii57434'] = 0x063A;
  9916. t['afii57440'] = 0x0640;
  9917. t['afii57441'] = 0x0641;
  9918. t['afii57442'] = 0x0642;
  9919. t['afii57443'] = 0x0643;
  9920. t['afii57444'] = 0x0644;
  9921. t['afii57445'] = 0x0645;
  9922. t['afii57446'] = 0x0646;
  9923. t['afii57448'] = 0x0648;
  9924. t['afii57449'] = 0x0649;
  9925. t['afii57450'] = 0x064A;
  9926. t['afii57451'] = 0x064B;
  9927. t['afii57452'] = 0x064C;
  9928. t['afii57453'] = 0x064D;
  9929. t['afii57454'] = 0x064E;
  9930. t['afii57455'] = 0x064F;
  9931. t['afii57456'] = 0x0650;
  9932. t['afii57457'] = 0x0651;
  9933. t['afii57458'] = 0x0652;
  9934. t['afii57470'] = 0x0647;
  9935. t['afii57505'] = 0x06A4;
  9936. t['afii57506'] = 0x067E;
  9937. t['afii57507'] = 0x0686;
  9938. t['afii57508'] = 0x0698;
  9939. t['afii57509'] = 0x06AF;
  9940. t['afii57511'] = 0x0679;
  9941. t['afii57512'] = 0x0688;
  9942. t['afii57513'] = 0x0691;
  9943. t['afii57514'] = 0x06BA;
  9944. t['afii57519'] = 0x06D2;
  9945. t['afii57534'] = 0x06D5;
  9946. t['afii57636'] = 0x20AA;
  9947. t['afii57645'] = 0x05BE;
  9948. t['afii57658'] = 0x05C3;
  9949. t['afii57664'] = 0x05D0;
  9950. t['afii57665'] = 0x05D1;
  9951. t['afii57666'] = 0x05D2;
  9952. t['afii57667'] = 0x05D3;
  9953. t['afii57668'] = 0x05D4;
  9954. t['afii57669'] = 0x05D5;
  9955. t['afii57670'] = 0x05D6;
  9956. t['afii57671'] = 0x05D7;
  9957. t['afii57672'] = 0x05D8;
  9958. t['afii57673'] = 0x05D9;
  9959. t['afii57674'] = 0x05DA;
  9960. t['afii57675'] = 0x05DB;
  9961. t['afii57676'] = 0x05DC;
  9962. t['afii57677'] = 0x05DD;
  9963. t['afii57678'] = 0x05DE;
  9964. t['afii57679'] = 0x05DF;
  9965. t['afii57680'] = 0x05E0;
  9966. t['afii57681'] = 0x05E1;
  9967. t['afii57682'] = 0x05E2;
  9968. t['afii57683'] = 0x05E3;
  9969. t['afii57684'] = 0x05E4;
  9970. t['afii57685'] = 0x05E5;
  9971. t['afii57686'] = 0x05E6;
  9972. t['afii57687'] = 0x05E7;
  9973. t['afii57688'] = 0x05E8;
  9974. t['afii57689'] = 0x05E9;
  9975. t['afii57690'] = 0x05EA;
  9976. t['afii57694'] = 0xFB2A;
  9977. t['afii57695'] = 0xFB2B;
  9978. t['afii57700'] = 0xFB4B;
  9979. t['afii57705'] = 0xFB1F;
  9980. t['afii57716'] = 0x05F0;
  9981. t['afii57717'] = 0x05F1;
  9982. t['afii57718'] = 0x05F2;
  9983. t['afii57723'] = 0xFB35;
  9984. t['afii57793'] = 0x05B4;
  9985. t['afii57794'] = 0x05B5;
  9986. t['afii57795'] = 0x05B6;
  9987. t['afii57796'] = 0x05BB;
  9988. t['afii57797'] = 0x05B8;
  9989. t['afii57798'] = 0x05B7;
  9990. t['afii57799'] = 0x05B0;
  9991. t['afii57800'] = 0x05B2;
  9992. t['afii57801'] = 0x05B1;
  9993. t['afii57802'] = 0x05B3;
  9994. t['afii57803'] = 0x05C2;
  9995. t['afii57804'] = 0x05C1;
  9996. t['afii57806'] = 0x05B9;
  9997. t['afii57807'] = 0x05BC;
  9998. t['afii57839'] = 0x05BD;
  9999. t['afii57841'] = 0x05BF;
  10000. t['afii57842'] = 0x05C0;
  10001. t['afii57929'] = 0x02BC;
  10002. t['afii61248'] = 0x2105;
  10003. t['afii61289'] = 0x2113;
  10004. t['afii61352'] = 0x2116;
  10005. t['afii61573'] = 0x202C;
  10006. t['afii61574'] = 0x202D;
  10007. t['afii61575'] = 0x202E;
  10008. t['afii61664'] = 0x200C;
  10009. t['afii63167'] = 0x066D;
  10010. t['afii64937'] = 0x02BD;
  10011. t['agrave'] = 0x00E0;
  10012. t['agujarati'] = 0x0A85;
  10013. t['agurmukhi'] = 0x0A05;
  10014. t['ahiragana'] = 0x3042;
  10015. t['ahookabove'] = 0x1EA3;
  10016. t['aibengali'] = 0x0990;
  10017. t['aibopomofo'] = 0x311E;
  10018. t['aideva'] = 0x0910;
  10019. t['aiecyrillic'] = 0x04D5;
  10020. t['aigujarati'] = 0x0A90;
  10021. t['aigurmukhi'] = 0x0A10;
  10022. t['aimatragurmukhi'] = 0x0A48;
  10023. t['ainarabic'] = 0x0639;
  10024. t['ainfinalarabic'] = 0xFECA;
  10025. t['aininitialarabic'] = 0xFECB;
  10026. t['ainmedialarabic'] = 0xFECC;
  10027. t['ainvertedbreve'] = 0x0203;
  10028. t['aivowelsignbengali'] = 0x09C8;
  10029. t['aivowelsigndeva'] = 0x0948;
  10030. t['aivowelsigngujarati'] = 0x0AC8;
  10031. t['akatakana'] = 0x30A2;
  10032. t['akatakanahalfwidth'] = 0xFF71;
  10033. t['akorean'] = 0x314F;
  10034. t['alef'] = 0x05D0;
  10035. t['alefarabic'] = 0x0627;
  10036. t['alefdageshhebrew'] = 0xFB30;
  10037. t['aleffinalarabic'] = 0xFE8E;
  10038. t['alefhamzaabovearabic'] = 0x0623;
  10039. t['alefhamzaabovefinalarabic'] = 0xFE84;
  10040. t['alefhamzabelowarabic'] = 0x0625;
  10041. t['alefhamzabelowfinalarabic'] = 0xFE88;
  10042. t['alefhebrew'] = 0x05D0;
  10043. t['aleflamedhebrew'] = 0xFB4F;
  10044. t['alefmaddaabovearabic'] = 0x0622;
  10045. t['alefmaddaabovefinalarabic'] = 0xFE82;
  10046. t['alefmaksuraarabic'] = 0x0649;
  10047. t['alefmaksurafinalarabic'] = 0xFEF0;
  10048. t['alefmaksurainitialarabic'] = 0xFEF3;
  10049. t['alefmaksuramedialarabic'] = 0xFEF4;
  10050. t['alefpatahhebrew'] = 0xFB2E;
  10051. t['alefqamatshebrew'] = 0xFB2F;
  10052. t['aleph'] = 0x2135;
  10053. t['allequal'] = 0x224C;
  10054. t['alpha'] = 0x03B1;
  10055. t['alphatonos'] = 0x03AC;
  10056. t['amacron'] = 0x0101;
  10057. t['amonospace'] = 0xFF41;
  10058. t['ampersand'] = 0x0026;
  10059. t['ampersandmonospace'] = 0xFF06;
  10060. t['ampersandsmall'] = 0xF726;
  10061. t['amsquare'] = 0x33C2;
  10062. t['anbopomofo'] = 0x3122;
  10063. t['angbopomofo'] = 0x3124;
  10064. t['angbracketleft'] = 0x3008;
  10065. // Glyph is missing from Adobe's original list.
  10066. t['angbracketright'] = 0x3009;
  10067. // Glyph is missing from Adobe's original list.
  10068. t['angkhankhuthai'] = 0x0E5A;
  10069. t['angle'] = 0x2220;
  10070. t['anglebracketleft'] = 0x3008;
  10071. t['anglebracketleftvertical'] = 0xFE3F;
  10072. t['anglebracketright'] = 0x3009;
  10073. t['anglebracketrightvertical'] = 0xFE40;
  10074. t['angleleft'] = 0x2329;
  10075. t['angleright'] = 0x232A;
  10076. t['angstrom'] = 0x212B;
  10077. t['anoteleia'] = 0x0387;
  10078. t['anudattadeva'] = 0x0952;
  10079. t['anusvarabengali'] = 0x0982;
  10080. t['anusvaradeva'] = 0x0902;
  10081. t['anusvaragujarati'] = 0x0A82;
  10082. t['aogonek'] = 0x0105;
  10083. t['apaatosquare'] = 0x3300;
  10084. t['aparen'] = 0x249C;
  10085. t['apostrophearmenian'] = 0x055A;
  10086. t['apostrophemod'] = 0x02BC;
  10087. t['apple'] = 0xF8FF;
  10088. t['approaches'] = 0x2250;
  10089. t['approxequal'] = 0x2248;
  10090. t['approxequalorimage'] = 0x2252;
  10091. t['approximatelyequal'] = 0x2245;
  10092. t['araeaekorean'] = 0x318E;
  10093. t['araeakorean'] = 0x318D;
  10094. t['arc'] = 0x2312;
  10095. t['arighthalfring'] = 0x1E9A;
  10096. t['aring'] = 0x00E5;
  10097. t['aringacute'] = 0x01FB;
  10098. t['aringbelow'] = 0x1E01;
  10099. t['arrowboth'] = 0x2194;
  10100. t['arrowdashdown'] = 0x21E3;
  10101. t['arrowdashleft'] = 0x21E0;
  10102. t['arrowdashright'] = 0x21E2;
  10103. t['arrowdashup'] = 0x21E1;
  10104. t['arrowdblboth'] = 0x21D4;
  10105. t['arrowdbldown'] = 0x21D3;
  10106. t['arrowdblleft'] = 0x21D0;
  10107. t['arrowdblright'] = 0x21D2;
  10108. t['arrowdblup'] = 0x21D1;
  10109. t['arrowdown'] = 0x2193;
  10110. t['arrowdownleft'] = 0x2199;
  10111. t['arrowdownright'] = 0x2198;
  10112. t['arrowdownwhite'] = 0x21E9;
  10113. t['arrowheaddownmod'] = 0x02C5;
  10114. t['arrowheadleftmod'] = 0x02C2;
  10115. t['arrowheadrightmod'] = 0x02C3;
  10116. t['arrowheadupmod'] = 0x02C4;
  10117. t['arrowhorizex'] = 0xF8E7;
  10118. t['arrowleft'] = 0x2190;
  10119. t['arrowleftdbl'] = 0x21D0;
  10120. t['arrowleftdblstroke'] = 0x21CD;
  10121. t['arrowleftoverright'] = 0x21C6;
  10122. t['arrowleftwhite'] = 0x21E6;
  10123. t['arrowright'] = 0x2192;
  10124. t['arrowrightdblstroke'] = 0x21CF;
  10125. t['arrowrightheavy'] = 0x279E;
  10126. t['arrowrightoverleft'] = 0x21C4;
  10127. t['arrowrightwhite'] = 0x21E8;
  10128. t['arrowtableft'] = 0x21E4;
  10129. t['arrowtabright'] = 0x21E5;
  10130. t['arrowup'] = 0x2191;
  10131. t['arrowupdn'] = 0x2195;
  10132. t['arrowupdnbse'] = 0x21A8;
  10133. t['arrowupdownbase'] = 0x21A8;
  10134. t['arrowupleft'] = 0x2196;
  10135. t['arrowupleftofdown'] = 0x21C5;
  10136. t['arrowupright'] = 0x2197;
  10137. t['arrowupwhite'] = 0x21E7;
  10138. t['arrowvertex'] = 0xF8E6;
  10139. t['asciicircum'] = 0x005E;
  10140. t['asciicircummonospace'] = 0xFF3E;
  10141. t['asciitilde'] = 0x007E;
  10142. t['asciitildemonospace'] = 0xFF5E;
  10143. t['ascript'] = 0x0251;
  10144. t['ascriptturned'] = 0x0252;
  10145. t['asmallhiragana'] = 0x3041;
  10146. t['asmallkatakana'] = 0x30A1;
  10147. t['asmallkatakanahalfwidth'] = 0xFF67;
  10148. t['asterisk'] = 0x002A;
  10149. t['asteriskaltonearabic'] = 0x066D;
  10150. t['asteriskarabic'] = 0x066D;
  10151. t['asteriskmath'] = 0x2217;
  10152. t['asteriskmonospace'] = 0xFF0A;
  10153. t['asterisksmall'] = 0xFE61;
  10154. t['asterism'] = 0x2042;
  10155. t['asuperior'] = 0xF6E9;
  10156. t['asymptoticallyequal'] = 0x2243;
  10157. t['at'] = 0x0040;
  10158. t['atilde'] = 0x00E3;
  10159. t['atmonospace'] = 0xFF20;
  10160. t['atsmall'] = 0xFE6B;
  10161. t['aturned'] = 0x0250;
  10162. t['aubengali'] = 0x0994;
  10163. t['aubopomofo'] = 0x3120;
  10164. t['audeva'] = 0x0914;
  10165. t['augujarati'] = 0x0A94;
  10166. t['augurmukhi'] = 0x0A14;
  10167. t['aulengthmarkbengali'] = 0x09D7;
  10168. t['aumatragurmukhi'] = 0x0A4C;
  10169. t['auvowelsignbengali'] = 0x09CC;
  10170. t['auvowelsigndeva'] = 0x094C;
  10171. t['auvowelsigngujarati'] = 0x0ACC;
  10172. t['avagrahadeva'] = 0x093D;
  10173. t['aybarmenian'] = 0x0561;
  10174. t['ayin'] = 0x05E2;
  10175. t['ayinaltonehebrew'] = 0xFB20;
  10176. t['ayinhebrew'] = 0x05E2;
  10177. t['b'] = 0x0062;
  10178. t['babengali'] = 0x09AC;
  10179. t['backslash'] = 0x005C;
  10180. t['backslashmonospace'] = 0xFF3C;
  10181. t['badeva'] = 0x092C;
  10182. t['bagujarati'] = 0x0AAC;
  10183. t['bagurmukhi'] = 0x0A2C;
  10184. t['bahiragana'] = 0x3070;
  10185. t['bahtthai'] = 0x0E3F;
  10186. t['bakatakana'] = 0x30D0;
  10187. t['bar'] = 0x007C;
  10188. t['barmonospace'] = 0xFF5C;
  10189. t['bbopomofo'] = 0x3105;
  10190. t['bcircle'] = 0x24D1;
  10191. t['bdotaccent'] = 0x1E03;
  10192. t['bdotbelow'] = 0x1E05;
  10193. t['beamedsixteenthnotes'] = 0x266C;
  10194. t['because'] = 0x2235;
  10195. t['becyrillic'] = 0x0431;
  10196. t['beharabic'] = 0x0628;
  10197. t['behfinalarabic'] = 0xFE90;
  10198. t['behinitialarabic'] = 0xFE91;
  10199. t['behiragana'] = 0x3079;
  10200. t['behmedialarabic'] = 0xFE92;
  10201. t['behmeeminitialarabic'] = 0xFC9F;
  10202. t['behmeemisolatedarabic'] = 0xFC08;
  10203. t['behnoonfinalarabic'] = 0xFC6D;
  10204. t['bekatakana'] = 0x30D9;
  10205. t['benarmenian'] = 0x0562;
  10206. t['bet'] = 0x05D1;
  10207. t['beta'] = 0x03B2;
  10208. t['betasymbolgreek'] = 0x03D0;
  10209. t['betdagesh'] = 0xFB31;
  10210. t['betdageshhebrew'] = 0xFB31;
  10211. t['bethebrew'] = 0x05D1;
  10212. t['betrafehebrew'] = 0xFB4C;
  10213. t['bhabengali'] = 0x09AD;
  10214. t['bhadeva'] = 0x092D;
  10215. t['bhagujarati'] = 0x0AAD;
  10216. t['bhagurmukhi'] = 0x0A2D;
  10217. t['bhook'] = 0x0253;
  10218. t['bihiragana'] = 0x3073;
  10219. t['bikatakana'] = 0x30D3;
  10220. t['bilabialclick'] = 0x0298;
  10221. t['bindigurmukhi'] = 0x0A02;
  10222. t['birusquare'] = 0x3331;
  10223. t['blackcircle'] = 0x25CF;
  10224. t['blackdiamond'] = 0x25C6;
  10225. t['blackdownpointingtriangle'] = 0x25BC;
  10226. t['blackleftpointingpointer'] = 0x25C4;
  10227. t['blackleftpointingtriangle'] = 0x25C0;
  10228. t['blacklenticularbracketleft'] = 0x3010;
  10229. t['blacklenticularbracketleftvertical'] = 0xFE3B;
  10230. t['blacklenticularbracketright'] = 0x3011;
  10231. t['blacklenticularbracketrightvertical'] = 0xFE3C;
  10232. t['blacklowerlefttriangle'] = 0x25E3;
  10233. t['blacklowerrighttriangle'] = 0x25E2;
  10234. t['blackrectangle'] = 0x25AC;
  10235. t['blackrightpointingpointer'] = 0x25BA;
  10236. t['blackrightpointingtriangle'] = 0x25B6;
  10237. t['blacksmallsquare'] = 0x25AA;
  10238. t['blacksmilingface'] = 0x263B;
  10239. t['blacksquare'] = 0x25A0;
  10240. t['blackstar'] = 0x2605;
  10241. t['blackupperlefttriangle'] = 0x25E4;
  10242. t['blackupperrighttriangle'] = 0x25E5;
  10243. t['blackuppointingsmalltriangle'] = 0x25B4;
  10244. t['blackuppointingtriangle'] = 0x25B2;
  10245. t['blank'] = 0x2423;
  10246. t['blinebelow'] = 0x1E07;
  10247. t['block'] = 0x2588;
  10248. t['bmonospace'] = 0xFF42;
  10249. t['bobaimaithai'] = 0x0E1A;
  10250. t['bohiragana'] = 0x307C;
  10251. t['bokatakana'] = 0x30DC;
  10252. t['bparen'] = 0x249D;
  10253. t['bqsquare'] = 0x33C3;
  10254. t['braceex'] = 0xF8F4;
  10255. t['braceleft'] = 0x007B;
  10256. t['braceleftbt'] = 0xF8F3;
  10257. t['braceleftmid'] = 0xF8F2;
  10258. t['braceleftmonospace'] = 0xFF5B;
  10259. t['braceleftsmall'] = 0xFE5B;
  10260. t['bracelefttp'] = 0xF8F1;
  10261. t['braceleftvertical'] = 0xFE37;
  10262. t['braceright'] = 0x007D;
  10263. t['bracerightbt'] = 0xF8FE;
  10264. t['bracerightmid'] = 0xF8FD;
  10265. t['bracerightmonospace'] = 0xFF5D;
  10266. t['bracerightsmall'] = 0xFE5C;
  10267. t['bracerighttp'] = 0xF8FC;
  10268. t['bracerightvertical'] = 0xFE38;
  10269. t['bracketleft'] = 0x005B;
  10270. t['bracketleftbt'] = 0xF8F0;
  10271. t['bracketleftex'] = 0xF8EF;
  10272. t['bracketleftmonospace'] = 0xFF3B;
  10273. t['bracketlefttp'] = 0xF8EE;
  10274. t['bracketright'] = 0x005D;
  10275. t['bracketrightbt'] = 0xF8FB;
  10276. t['bracketrightex'] = 0xF8FA;
  10277. t['bracketrightmonospace'] = 0xFF3D;
  10278. t['bracketrighttp'] = 0xF8F9;
  10279. t['breve'] = 0x02D8;
  10280. t['brevebelowcmb'] = 0x032E;
  10281. t['brevecmb'] = 0x0306;
  10282. t['breveinvertedbelowcmb'] = 0x032F;
  10283. t['breveinvertedcmb'] = 0x0311;
  10284. t['breveinverteddoublecmb'] = 0x0361;
  10285. t['bridgebelowcmb'] = 0x032A;
  10286. t['bridgeinvertedbelowcmb'] = 0x033A;
  10287. t['brokenbar'] = 0x00A6;
  10288. t['bstroke'] = 0x0180;
  10289. t['bsuperior'] = 0xF6EA;
  10290. t['btopbar'] = 0x0183;
  10291. t['buhiragana'] = 0x3076;
  10292. t['bukatakana'] = 0x30D6;
  10293. t['bullet'] = 0x2022;
  10294. t['bulletinverse'] = 0x25D8;
  10295. t['bulletoperator'] = 0x2219;
  10296. t['bullseye'] = 0x25CE;
  10297. t['c'] = 0x0063;
  10298. t['caarmenian'] = 0x056E;
  10299. t['cabengali'] = 0x099A;
  10300. t['cacute'] = 0x0107;
  10301. t['cadeva'] = 0x091A;
  10302. t['cagujarati'] = 0x0A9A;
  10303. t['cagurmukhi'] = 0x0A1A;
  10304. t['calsquare'] = 0x3388;
  10305. t['candrabindubengali'] = 0x0981;
  10306. t['candrabinducmb'] = 0x0310;
  10307. t['candrabindudeva'] = 0x0901;
  10308. t['candrabindugujarati'] = 0x0A81;
  10309. t['capslock'] = 0x21EA;
  10310. t['careof'] = 0x2105;
  10311. t['caron'] = 0x02C7;
  10312. t['caronbelowcmb'] = 0x032C;
  10313. t['caroncmb'] = 0x030C;
  10314. t['carriagereturn'] = 0x21B5;
  10315. t['cbopomofo'] = 0x3118;
  10316. t['ccaron'] = 0x010D;
  10317. t['ccedilla'] = 0x00E7;
  10318. t['ccedillaacute'] = 0x1E09;
  10319. t['ccircle'] = 0x24D2;
  10320. t['ccircumflex'] = 0x0109;
  10321. t['ccurl'] = 0x0255;
  10322. t['cdot'] = 0x010B;
  10323. t['cdotaccent'] = 0x010B;
  10324. t['cdsquare'] = 0x33C5;
  10325. t['cedilla'] = 0x00B8;
  10326. t['cedillacmb'] = 0x0327;
  10327. t['cent'] = 0x00A2;
  10328. t['centigrade'] = 0x2103;
  10329. t['centinferior'] = 0xF6DF;
  10330. t['centmonospace'] = 0xFFE0;
  10331. t['centoldstyle'] = 0xF7A2;
  10332. t['centsuperior'] = 0xF6E0;
  10333. t['chaarmenian'] = 0x0579;
  10334. t['chabengali'] = 0x099B;
  10335. t['chadeva'] = 0x091B;
  10336. t['chagujarati'] = 0x0A9B;
  10337. t['chagurmukhi'] = 0x0A1B;
  10338. t['chbopomofo'] = 0x3114;
  10339. t['cheabkhasiancyrillic'] = 0x04BD;
  10340. t['checkmark'] = 0x2713;
  10341. t['checyrillic'] = 0x0447;
  10342. t['chedescenderabkhasiancyrillic'] = 0x04BF;
  10343. t['chedescendercyrillic'] = 0x04B7;
  10344. t['chedieresiscyrillic'] = 0x04F5;
  10345. t['cheharmenian'] = 0x0573;
  10346. t['chekhakassiancyrillic'] = 0x04CC;
  10347. t['cheverticalstrokecyrillic'] = 0x04B9;
  10348. t['chi'] = 0x03C7;
  10349. t['chieuchacirclekorean'] = 0x3277;
  10350. t['chieuchaparenkorean'] = 0x3217;
  10351. t['chieuchcirclekorean'] = 0x3269;
  10352. t['chieuchkorean'] = 0x314A;
  10353. t['chieuchparenkorean'] = 0x3209;
  10354. t['chochangthai'] = 0x0E0A;
  10355. t['chochanthai'] = 0x0E08;
  10356. t['chochingthai'] = 0x0E09;
  10357. t['chochoethai'] = 0x0E0C;
  10358. t['chook'] = 0x0188;
  10359. t['cieucacirclekorean'] = 0x3276;
  10360. t['cieucaparenkorean'] = 0x3216;
  10361. t['cieuccirclekorean'] = 0x3268;
  10362. t['cieuckorean'] = 0x3148;
  10363. t['cieucparenkorean'] = 0x3208;
  10364. t['cieucuparenkorean'] = 0x321C;
  10365. t['circle'] = 0x25CB;
  10366. t['circlecopyrt'] = 0x00A9;
  10367. // Glyph is missing from Adobe's original list.
  10368. t['circlemultiply'] = 0x2297;
  10369. t['circleot'] = 0x2299;
  10370. t['circleplus'] = 0x2295;
  10371. t['circlepostalmark'] = 0x3036;
  10372. t['circlewithlefthalfblack'] = 0x25D0;
  10373. t['circlewithrighthalfblack'] = 0x25D1;
  10374. t['circumflex'] = 0x02C6;
  10375. t['circumflexbelowcmb'] = 0x032D;
  10376. t['circumflexcmb'] = 0x0302;
  10377. t['clear'] = 0x2327;
  10378. t['clickalveolar'] = 0x01C2;
  10379. t['clickdental'] = 0x01C0;
  10380. t['clicklateral'] = 0x01C1;
  10381. t['clickretroflex'] = 0x01C3;
  10382. t['club'] = 0x2663;
  10383. t['clubsuitblack'] = 0x2663;
  10384. t['clubsuitwhite'] = 0x2667;
  10385. t['cmcubedsquare'] = 0x33A4;
  10386. t['cmonospace'] = 0xFF43;
  10387. t['cmsquaredsquare'] = 0x33A0;
  10388. t['coarmenian'] = 0x0581;
  10389. t['colon'] = 0x003A;
  10390. t['colonmonetary'] = 0x20A1;
  10391. t['colonmonospace'] = 0xFF1A;
  10392. t['colonsign'] = 0x20A1;
  10393. t['colonsmall'] = 0xFE55;
  10394. t['colontriangularhalfmod'] = 0x02D1;
  10395. t['colontriangularmod'] = 0x02D0;
  10396. t['comma'] = 0x002C;
  10397. t['commaabovecmb'] = 0x0313;
  10398. t['commaaboverightcmb'] = 0x0315;
  10399. t['commaaccent'] = 0xF6C3;
  10400. t['commaarabic'] = 0x060C;
  10401. t['commaarmenian'] = 0x055D;
  10402. t['commainferior'] = 0xF6E1;
  10403. t['commamonospace'] = 0xFF0C;
  10404. t['commareversedabovecmb'] = 0x0314;
  10405. t['commareversedmod'] = 0x02BD;
  10406. t['commasmall'] = 0xFE50;
  10407. t['commasuperior'] = 0xF6E2;
  10408. t['commaturnedabovecmb'] = 0x0312;
  10409. t['commaturnedmod'] = 0x02BB;
  10410. t['compass'] = 0x263C;
  10411. t['congruent'] = 0x2245;
  10412. t['contourintegral'] = 0x222E;
  10413. t['control'] = 0x2303;
  10414. t['controlACK'] = 0x0006;
  10415. t['controlBEL'] = 0x0007;
  10416. t['controlBS'] = 0x0008;
  10417. t['controlCAN'] = 0x0018;
  10418. t['controlCR'] = 0x000D;
  10419. t['controlDC1'] = 0x0011;
  10420. t['controlDC2'] = 0x0012;
  10421. t['controlDC3'] = 0x0013;
  10422. t['controlDC4'] = 0x0014;
  10423. t['controlDEL'] = 0x007F;
  10424. t['controlDLE'] = 0x0010;
  10425. t['controlEM'] = 0x0019;
  10426. t['controlENQ'] = 0x0005;
  10427. t['controlEOT'] = 0x0004;
  10428. t['controlESC'] = 0x001B;
  10429. t['controlETB'] = 0x0017;
  10430. t['controlETX'] = 0x0003;
  10431. t['controlFF'] = 0x000C;
  10432. t['controlFS'] = 0x001C;
  10433. t['controlGS'] = 0x001D;
  10434. t['controlHT'] = 0x0009;
  10435. t['controlLF'] = 0x000A;
  10436. t['controlNAK'] = 0x0015;
  10437. t['controlRS'] = 0x001E;
  10438. t['controlSI'] = 0x000F;
  10439. t['controlSO'] = 0x000E;
  10440. t['controlSOT'] = 0x0002;
  10441. t['controlSTX'] = 0x0001;
  10442. t['controlSUB'] = 0x001A;
  10443. t['controlSYN'] = 0x0016;
  10444. t['controlUS'] = 0x001F;
  10445. t['controlVT'] = 0x000B;
  10446. t['copyright'] = 0x00A9;
  10447. t['copyrightsans'] = 0xF8E9;
  10448. t['copyrightserif'] = 0xF6D9;
  10449. t['cornerbracketleft'] = 0x300C;
  10450. t['cornerbracketlefthalfwidth'] = 0xFF62;
  10451. t['cornerbracketleftvertical'] = 0xFE41;
  10452. t['cornerbracketright'] = 0x300D;
  10453. t['cornerbracketrighthalfwidth'] = 0xFF63;
  10454. t['cornerbracketrightvertical'] = 0xFE42;
  10455. t['corporationsquare'] = 0x337F;
  10456. t['cosquare'] = 0x33C7;
  10457. t['coverkgsquare'] = 0x33C6;
  10458. t['cparen'] = 0x249E;
  10459. t['cruzeiro'] = 0x20A2;
  10460. t['cstretched'] = 0x0297;
  10461. t['curlyand'] = 0x22CF;
  10462. t['curlyor'] = 0x22CE;
  10463. t['currency'] = 0x00A4;
  10464. t['cyrBreve'] = 0xF6D1;
  10465. t['cyrFlex'] = 0xF6D2;
  10466. t['cyrbreve'] = 0xF6D4;
  10467. t['cyrflex'] = 0xF6D5;
  10468. t['d'] = 0x0064;
  10469. t['daarmenian'] = 0x0564;
  10470. t['dabengali'] = 0x09A6;
  10471. t['dadarabic'] = 0x0636;
  10472. t['dadeva'] = 0x0926;
  10473. t['dadfinalarabic'] = 0xFEBE;
  10474. t['dadinitialarabic'] = 0xFEBF;
  10475. t['dadmedialarabic'] = 0xFEC0;
  10476. t['dagesh'] = 0x05BC;
  10477. t['dageshhebrew'] = 0x05BC;
  10478. t['dagger'] = 0x2020;
  10479. t['daggerdbl'] = 0x2021;
  10480. t['dagujarati'] = 0x0AA6;
  10481. t['dagurmukhi'] = 0x0A26;
  10482. t['dahiragana'] = 0x3060;
  10483. t['dakatakana'] = 0x30C0;
  10484. t['dalarabic'] = 0x062F;
  10485. t['dalet'] = 0x05D3;
  10486. t['daletdagesh'] = 0xFB33;
  10487. t['daletdageshhebrew'] = 0xFB33;
  10488. t['dalethebrew'] = 0x05D3;
  10489. t['dalfinalarabic'] = 0xFEAA;
  10490. t['dammaarabic'] = 0x064F;
  10491. t['dammalowarabic'] = 0x064F;
  10492. t['dammatanaltonearabic'] = 0x064C;
  10493. t['dammatanarabic'] = 0x064C;
  10494. t['danda'] = 0x0964;
  10495. t['dargahebrew'] = 0x05A7;
  10496. t['dargalefthebrew'] = 0x05A7;
  10497. t['dasiapneumatacyrilliccmb'] = 0x0485;
  10498. t['dblGrave'] = 0xF6D3;
  10499. t['dblanglebracketleft'] = 0x300A;
  10500. t['dblanglebracketleftvertical'] = 0xFE3D;
  10501. t['dblanglebracketright'] = 0x300B;
  10502. t['dblanglebracketrightvertical'] = 0xFE3E;
  10503. t['dblarchinvertedbelowcmb'] = 0x032B;
  10504. t['dblarrowleft'] = 0x21D4;
  10505. t['dblarrowright'] = 0x21D2;
  10506. t['dbldanda'] = 0x0965;
  10507. t['dblgrave'] = 0xF6D6;
  10508. t['dblgravecmb'] = 0x030F;
  10509. t['dblintegral'] = 0x222C;
  10510. t['dbllowline'] = 0x2017;
  10511. t['dbllowlinecmb'] = 0x0333;
  10512. t['dbloverlinecmb'] = 0x033F;
  10513. t['dblprimemod'] = 0x02BA;
  10514. t['dblverticalbar'] = 0x2016;
  10515. t['dblverticallineabovecmb'] = 0x030E;
  10516. t['dbopomofo'] = 0x3109;
  10517. t['dbsquare'] = 0x33C8;
  10518. t['dcaron'] = 0x010F;
  10519. t['dcedilla'] = 0x1E11;
  10520. t['dcircle'] = 0x24D3;
  10521. t['dcircumflexbelow'] = 0x1E13;
  10522. t['dcroat'] = 0x0111;
  10523. t['ddabengali'] = 0x09A1;
  10524. t['ddadeva'] = 0x0921;
  10525. t['ddagujarati'] = 0x0AA1;
  10526. t['ddagurmukhi'] = 0x0A21;
  10527. t['ddalarabic'] = 0x0688;
  10528. t['ddalfinalarabic'] = 0xFB89;
  10529. t['dddhadeva'] = 0x095C;
  10530. t['ddhabengali'] = 0x09A2;
  10531. t['ddhadeva'] = 0x0922;
  10532. t['ddhagujarati'] = 0x0AA2;
  10533. t['ddhagurmukhi'] = 0x0A22;
  10534. t['ddotaccent'] = 0x1E0B;
  10535. t['ddotbelow'] = 0x1E0D;
  10536. t['decimalseparatorarabic'] = 0x066B;
  10537. t['decimalseparatorpersian'] = 0x066B;
  10538. t['decyrillic'] = 0x0434;
  10539. t['degree'] = 0x00B0;
  10540. t['dehihebrew'] = 0x05AD;
  10541. t['dehiragana'] = 0x3067;
  10542. t['deicoptic'] = 0x03EF;
  10543. t['dekatakana'] = 0x30C7;
  10544. t['deleteleft'] = 0x232B;
  10545. t['deleteright'] = 0x2326;
  10546. t['delta'] = 0x03B4;
  10547. t['deltaturned'] = 0x018D;
  10548. t['denominatorminusonenumeratorbengali'] = 0x09F8;
  10549. t['dezh'] = 0x02A4;
  10550. t['dhabengali'] = 0x09A7;
  10551. t['dhadeva'] = 0x0927;
  10552. t['dhagujarati'] = 0x0AA7;
  10553. t['dhagurmukhi'] = 0x0A27;
  10554. t['dhook'] = 0x0257;
  10555. t['dialytikatonos'] = 0x0385;
  10556. t['dialytikatonoscmb'] = 0x0344;
  10557. t['diamond'] = 0x2666;
  10558. t['diamondsuitwhite'] = 0x2662;
  10559. t['dieresis'] = 0x00A8;
  10560. t['dieresisacute'] = 0xF6D7;
  10561. t['dieresisbelowcmb'] = 0x0324;
  10562. t['dieresiscmb'] = 0x0308;
  10563. t['dieresisgrave'] = 0xF6D8;
  10564. t['dieresistonos'] = 0x0385;
  10565. t['dihiragana'] = 0x3062;
  10566. t['dikatakana'] = 0x30C2;
  10567. t['dittomark'] = 0x3003;
  10568. t['divide'] = 0x00F7;
  10569. t['divides'] = 0x2223;
  10570. t['divisionslash'] = 0x2215;
  10571. t['djecyrillic'] = 0x0452;
  10572. t['dkshade'] = 0x2593;
  10573. t['dlinebelow'] = 0x1E0F;
  10574. t['dlsquare'] = 0x3397;
  10575. t['dmacron'] = 0x0111;
  10576. t['dmonospace'] = 0xFF44;
  10577. t['dnblock'] = 0x2584;
  10578. t['dochadathai'] = 0x0E0E;
  10579. t['dodekthai'] = 0x0E14;
  10580. t['dohiragana'] = 0x3069;
  10581. t['dokatakana'] = 0x30C9;
  10582. t['dollar'] = 0x0024;
  10583. t['dollarinferior'] = 0xF6E3;
  10584. t['dollarmonospace'] = 0xFF04;
  10585. t['dollaroldstyle'] = 0xF724;
  10586. t['dollarsmall'] = 0xFE69;
  10587. t['dollarsuperior'] = 0xF6E4;
  10588. t['dong'] = 0x20AB;
  10589. t['dorusquare'] = 0x3326;
  10590. t['dotaccent'] = 0x02D9;
  10591. t['dotaccentcmb'] = 0x0307;
  10592. t['dotbelowcmb'] = 0x0323;
  10593. t['dotbelowcomb'] = 0x0323;
  10594. t['dotkatakana'] = 0x30FB;
  10595. t['dotlessi'] = 0x0131;
  10596. t['dotlessj'] = 0xF6BE;
  10597. t['dotlessjstrokehook'] = 0x0284;
  10598. t['dotmath'] = 0x22C5;
  10599. t['dottedcircle'] = 0x25CC;
  10600. t['doubleyodpatah'] = 0xFB1F;
  10601. t['doubleyodpatahhebrew'] = 0xFB1F;
  10602. t['downtackbelowcmb'] = 0x031E;
  10603. t['downtackmod'] = 0x02D5;
  10604. t['dparen'] = 0x249F;
  10605. t['dsuperior'] = 0xF6EB;
  10606. t['dtail'] = 0x0256;
  10607. t['dtopbar'] = 0x018C;
  10608. t['duhiragana'] = 0x3065;
  10609. t['dukatakana'] = 0x30C5;
  10610. t['dz'] = 0x01F3;
  10611. t['dzaltone'] = 0x02A3;
  10612. t['dzcaron'] = 0x01C6;
  10613. t['dzcurl'] = 0x02A5;
  10614. t['dzeabkhasiancyrillic'] = 0x04E1;
  10615. t['dzecyrillic'] = 0x0455;
  10616. t['dzhecyrillic'] = 0x045F;
  10617. t['e'] = 0x0065;
  10618. t['eacute'] = 0x00E9;
  10619. t['earth'] = 0x2641;
  10620. t['ebengali'] = 0x098F;
  10621. t['ebopomofo'] = 0x311C;
  10622. t['ebreve'] = 0x0115;
  10623. t['ecandradeva'] = 0x090D;
  10624. t['ecandragujarati'] = 0x0A8D;
  10625. t['ecandravowelsigndeva'] = 0x0945;
  10626. t['ecandravowelsigngujarati'] = 0x0AC5;
  10627. t['ecaron'] = 0x011B;
  10628. t['ecedillabreve'] = 0x1E1D;
  10629. t['echarmenian'] = 0x0565;
  10630. t['echyiwnarmenian'] = 0x0587;
  10631. t['ecircle'] = 0x24D4;
  10632. t['ecircumflex'] = 0x00EA;
  10633. t['ecircumflexacute'] = 0x1EBF;
  10634. t['ecircumflexbelow'] = 0x1E19;
  10635. t['ecircumflexdotbelow'] = 0x1EC7;
  10636. t['ecircumflexgrave'] = 0x1EC1;
  10637. t['ecircumflexhookabove'] = 0x1EC3;
  10638. t['ecircumflextilde'] = 0x1EC5;
  10639. t['ecyrillic'] = 0x0454;
  10640. t['edblgrave'] = 0x0205;
  10641. t['edeva'] = 0x090F;
  10642. t['edieresis'] = 0x00EB;
  10643. t['edot'] = 0x0117;
  10644. t['edotaccent'] = 0x0117;
  10645. t['edotbelow'] = 0x1EB9;
  10646. t['eegurmukhi'] = 0x0A0F;
  10647. t['eematragurmukhi'] = 0x0A47;
  10648. t['efcyrillic'] = 0x0444;
  10649. t['egrave'] = 0x00E8;
  10650. t['egujarati'] = 0x0A8F;
  10651. t['eharmenian'] = 0x0567;
  10652. t['ehbopomofo'] = 0x311D;
  10653. t['ehiragana'] = 0x3048;
  10654. t['ehookabove'] = 0x1EBB;
  10655. t['eibopomofo'] = 0x311F;
  10656. t['eight'] = 0x0038;
  10657. t['eightarabic'] = 0x0668;
  10658. t['eightbengali'] = 0x09EE;
  10659. t['eightcircle'] = 0x2467;
  10660. t['eightcircleinversesansserif'] = 0x2791;
  10661. t['eightdeva'] = 0x096E;
  10662. t['eighteencircle'] = 0x2471;
  10663. t['eighteenparen'] = 0x2485;
  10664. t['eighteenperiod'] = 0x2499;
  10665. t['eightgujarati'] = 0x0AEE;
  10666. t['eightgurmukhi'] = 0x0A6E;
  10667. t['eighthackarabic'] = 0x0668;
  10668. t['eighthangzhou'] = 0x3028;
  10669. t['eighthnotebeamed'] = 0x266B;
  10670. t['eightideographicparen'] = 0x3227;
  10671. t['eightinferior'] = 0x2088;
  10672. t['eightmonospace'] = 0xFF18;
  10673. t['eightoldstyle'] = 0xF738;
  10674. t['eightparen'] = 0x247B;
  10675. t['eightperiod'] = 0x248F;
  10676. t['eightpersian'] = 0x06F8;
  10677. t['eightroman'] = 0x2177;
  10678. t['eightsuperior'] = 0x2078;
  10679. t['eightthai'] = 0x0E58;
  10680. t['einvertedbreve'] = 0x0207;
  10681. t['eiotifiedcyrillic'] = 0x0465;
  10682. t['ekatakana'] = 0x30A8;
  10683. t['ekatakanahalfwidth'] = 0xFF74;
  10684. t['ekonkargurmukhi'] = 0x0A74;
  10685. t['ekorean'] = 0x3154;
  10686. t['elcyrillic'] = 0x043B;
  10687. t['element'] = 0x2208;
  10688. t['elevencircle'] = 0x246A;
  10689. t['elevenparen'] = 0x247E;
  10690. t['elevenperiod'] = 0x2492;
  10691. t['elevenroman'] = 0x217A;
  10692. t['ellipsis'] = 0x2026;
  10693. t['ellipsisvertical'] = 0x22EE;
  10694. t['emacron'] = 0x0113;
  10695. t['emacronacute'] = 0x1E17;
  10696. t['emacrongrave'] = 0x1E15;
  10697. t['emcyrillic'] = 0x043C;
  10698. t['emdash'] = 0x2014;
  10699. t['emdashvertical'] = 0xFE31;
  10700. t['emonospace'] = 0xFF45;
  10701. t['emphasismarkarmenian'] = 0x055B;
  10702. t['emptyset'] = 0x2205;
  10703. t['enbopomofo'] = 0x3123;
  10704. t['encyrillic'] = 0x043D;
  10705. t['endash'] = 0x2013;
  10706. t['endashvertical'] = 0xFE32;
  10707. t['endescendercyrillic'] = 0x04A3;
  10708. t['eng'] = 0x014B;
  10709. t['engbopomofo'] = 0x3125;
  10710. t['enghecyrillic'] = 0x04A5;
  10711. t['enhookcyrillic'] = 0x04C8;
  10712. t['enspace'] = 0x2002;
  10713. t['eogonek'] = 0x0119;
  10714. t['eokorean'] = 0x3153;
  10715. t['eopen'] = 0x025B;
  10716. t['eopenclosed'] = 0x029A;
  10717. t['eopenreversed'] = 0x025C;
  10718. t['eopenreversedclosed'] = 0x025E;
  10719. t['eopenreversedhook'] = 0x025D;
  10720. t['eparen'] = 0x24A0;
  10721. t['epsilon'] = 0x03B5;
  10722. t['epsilontonos'] = 0x03AD;
  10723. t['equal'] = 0x003D;
  10724. t['equalmonospace'] = 0xFF1D;
  10725. t['equalsmall'] = 0xFE66;
  10726. t['equalsuperior'] = 0x207C;
  10727. t['equivalence'] = 0x2261;
  10728. t['erbopomofo'] = 0x3126;
  10729. t['ercyrillic'] = 0x0440;
  10730. t['ereversed'] = 0x0258;
  10731. t['ereversedcyrillic'] = 0x044D;
  10732. t['escyrillic'] = 0x0441;
  10733. t['esdescendercyrillic'] = 0x04AB;
  10734. t['esh'] = 0x0283;
  10735. t['eshcurl'] = 0x0286;
  10736. t['eshortdeva'] = 0x090E;
  10737. t['eshortvowelsigndeva'] = 0x0946;
  10738. t['eshreversedloop'] = 0x01AA;
  10739. t['eshsquatreversed'] = 0x0285;
  10740. t['esmallhiragana'] = 0x3047;
  10741. t['esmallkatakana'] = 0x30A7;
  10742. t['esmallkatakanahalfwidth'] = 0xFF6A;
  10743. t['estimated'] = 0x212E;
  10744. t['esuperior'] = 0xF6EC;
  10745. t['eta'] = 0x03B7;
  10746. t['etarmenian'] = 0x0568;
  10747. t['etatonos'] = 0x03AE;
  10748. t['eth'] = 0x00F0;
  10749. t['etilde'] = 0x1EBD;
  10750. t['etildebelow'] = 0x1E1B;
  10751. t['etnahtafoukhhebrew'] = 0x0591;
  10752. t['etnahtafoukhlefthebrew'] = 0x0591;
  10753. t['etnahtahebrew'] = 0x0591;
  10754. t['etnahtalefthebrew'] = 0x0591;
  10755. t['eturned'] = 0x01DD;
  10756. t['eukorean'] = 0x3161;
  10757. t['euro'] = 0x20AC;
  10758. t['evowelsignbengali'] = 0x09C7;
  10759. t['evowelsigndeva'] = 0x0947;
  10760. t['evowelsigngujarati'] = 0x0AC7;
  10761. t['exclam'] = 0x0021;
  10762. t['exclamarmenian'] = 0x055C;
  10763. t['exclamdbl'] = 0x203C;
  10764. t['exclamdown'] = 0x00A1;
  10765. t['exclamdownsmall'] = 0xF7A1;
  10766. t['exclammonospace'] = 0xFF01;
  10767. t['exclamsmall'] = 0xF721;
  10768. t['existential'] = 0x2203;
  10769. t['ezh'] = 0x0292;
  10770. t['ezhcaron'] = 0x01EF;
  10771. t['ezhcurl'] = 0x0293;
  10772. t['ezhreversed'] = 0x01B9;
  10773. t['ezhtail'] = 0x01BA;
  10774. t['f'] = 0x0066;
  10775. t['fadeva'] = 0x095E;
  10776. t['fagurmukhi'] = 0x0A5E;
  10777. t['fahrenheit'] = 0x2109;
  10778. t['fathaarabic'] = 0x064E;
  10779. t['fathalowarabic'] = 0x064E;
  10780. t['fathatanarabic'] = 0x064B;
  10781. t['fbopomofo'] = 0x3108;
  10782. t['fcircle'] = 0x24D5;
  10783. t['fdotaccent'] = 0x1E1F;
  10784. t['feharabic'] = 0x0641;
  10785. t['feharmenian'] = 0x0586;
  10786. t['fehfinalarabic'] = 0xFED2;
  10787. t['fehinitialarabic'] = 0xFED3;
  10788. t['fehmedialarabic'] = 0xFED4;
  10789. t['feicoptic'] = 0x03E5;
  10790. t['female'] = 0x2640;
  10791. t['ff'] = 0xFB00;
  10792. t['ffi'] = 0xFB03;
  10793. t['ffl'] = 0xFB04;
  10794. t['fi'] = 0xFB01;
  10795. t['fifteencircle'] = 0x246E;
  10796. t['fifteenparen'] = 0x2482;
  10797. t['fifteenperiod'] = 0x2496;
  10798. t['figuredash'] = 0x2012;
  10799. t['filledbox'] = 0x25A0;
  10800. t['filledrect'] = 0x25AC;
  10801. t['finalkaf'] = 0x05DA;
  10802. t['finalkafdagesh'] = 0xFB3A;
  10803. t['finalkafdageshhebrew'] = 0xFB3A;
  10804. t['finalkafhebrew'] = 0x05DA;
  10805. t['finalmem'] = 0x05DD;
  10806. t['finalmemhebrew'] = 0x05DD;
  10807. t['finalnun'] = 0x05DF;
  10808. t['finalnunhebrew'] = 0x05DF;
  10809. t['finalpe'] = 0x05E3;
  10810. t['finalpehebrew'] = 0x05E3;
  10811. t['finaltsadi'] = 0x05E5;
  10812. t['finaltsadihebrew'] = 0x05E5;
  10813. t['firsttonechinese'] = 0x02C9;
  10814. t['fisheye'] = 0x25C9;
  10815. t['fitacyrillic'] = 0x0473;
  10816. t['five'] = 0x0035;
  10817. t['fivearabic'] = 0x0665;
  10818. t['fivebengali'] = 0x09EB;
  10819. t['fivecircle'] = 0x2464;
  10820. t['fivecircleinversesansserif'] = 0x278E;
  10821. t['fivedeva'] = 0x096B;
  10822. t['fiveeighths'] = 0x215D;
  10823. t['fivegujarati'] = 0x0AEB;
  10824. t['fivegurmukhi'] = 0x0A6B;
  10825. t['fivehackarabic'] = 0x0665;
  10826. t['fivehangzhou'] = 0x3025;
  10827. t['fiveideographicparen'] = 0x3224;
  10828. t['fiveinferior'] = 0x2085;
  10829. t['fivemonospace'] = 0xFF15;
  10830. t['fiveoldstyle'] = 0xF735;
  10831. t['fiveparen'] = 0x2478;
  10832. t['fiveperiod'] = 0x248C;
  10833. t['fivepersian'] = 0x06F5;
  10834. t['fiveroman'] = 0x2174;
  10835. t['fivesuperior'] = 0x2075;
  10836. t['fivethai'] = 0x0E55;
  10837. t['fl'] = 0xFB02;
  10838. t['florin'] = 0x0192;
  10839. t['fmonospace'] = 0xFF46;
  10840. t['fmsquare'] = 0x3399;
  10841. t['fofanthai'] = 0x0E1F;
  10842. t['fofathai'] = 0x0E1D;
  10843. t['fongmanthai'] = 0x0E4F;
  10844. t['forall'] = 0x2200;
  10845. t['four'] = 0x0034;
  10846. t['fourarabic'] = 0x0664;
  10847. t['fourbengali'] = 0x09EA;
  10848. t['fourcircle'] = 0x2463;
  10849. t['fourcircleinversesansserif'] = 0x278D;
  10850. t['fourdeva'] = 0x096A;
  10851. t['fourgujarati'] = 0x0AEA;
  10852. t['fourgurmukhi'] = 0x0A6A;
  10853. t['fourhackarabic'] = 0x0664;
  10854. t['fourhangzhou'] = 0x3024;
  10855. t['fourideographicparen'] = 0x3223;
  10856. t['fourinferior'] = 0x2084;
  10857. t['fourmonospace'] = 0xFF14;
  10858. t['fournumeratorbengali'] = 0x09F7;
  10859. t['fouroldstyle'] = 0xF734;
  10860. t['fourparen'] = 0x2477;
  10861. t['fourperiod'] = 0x248B;
  10862. t['fourpersian'] = 0x06F4;
  10863. t['fourroman'] = 0x2173;
  10864. t['foursuperior'] = 0x2074;
  10865. t['fourteencircle'] = 0x246D;
  10866. t['fourteenparen'] = 0x2481;
  10867. t['fourteenperiod'] = 0x2495;
  10868. t['fourthai'] = 0x0E54;
  10869. t['fourthtonechinese'] = 0x02CB;
  10870. t['fparen'] = 0x24A1;
  10871. t['fraction'] = 0x2044;
  10872. t['franc'] = 0x20A3;
  10873. t['g'] = 0x0067;
  10874. t['gabengali'] = 0x0997;
  10875. t['gacute'] = 0x01F5;
  10876. t['gadeva'] = 0x0917;
  10877. t['gafarabic'] = 0x06AF;
  10878. t['gaffinalarabic'] = 0xFB93;
  10879. t['gafinitialarabic'] = 0xFB94;
  10880. t['gafmedialarabic'] = 0xFB95;
  10881. t['gagujarati'] = 0x0A97;
  10882. t['gagurmukhi'] = 0x0A17;
  10883. t['gahiragana'] = 0x304C;
  10884. t['gakatakana'] = 0x30AC;
  10885. t['gamma'] = 0x03B3;
  10886. t['gammalatinsmall'] = 0x0263;
  10887. t['gammasuperior'] = 0x02E0;
  10888. t['gangiacoptic'] = 0x03EB;
  10889. t['gbopomofo'] = 0x310D;
  10890. t['gbreve'] = 0x011F;
  10891. t['gcaron'] = 0x01E7;
  10892. t['gcedilla'] = 0x0123;
  10893. t['gcircle'] = 0x24D6;
  10894. t['gcircumflex'] = 0x011D;
  10895. t['gcommaaccent'] = 0x0123;
  10896. t['gdot'] = 0x0121;
  10897. t['gdotaccent'] = 0x0121;
  10898. t['gecyrillic'] = 0x0433;
  10899. t['gehiragana'] = 0x3052;
  10900. t['gekatakana'] = 0x30B2;
  10901. t['geometricallyequal'] = 0x2251;
  10902. t['gereshaccenthebrew'] = 0x059C;
  10903. t['gereshhebrew'] = 0x05F3;
  10904. t['gereshmuqdamhebrew'] = 0x059D;
  10905. t['germandbls'] = 0x00DF;
  10906. t['gershayimaccenthebrew'] = 0x059E;
  10907. t['gershayimhebrew'] = 0x05F4;
  10908. t['getamark'] = 0x3013;
  10909. t['ghabengali'] = 0x0998;
  10910. t['ghadarmenian'] = 0x0572;
  10911. t['ghadeva'] = 0x0918;
  10912. t['ghagujarati'] = 0x0A98;
  10913. t['ghagurmukhi'] = 0x0A18;
  10914. t['ghainarabic'] = 0x063A;
  10915. t['ghainfinalarabic'] = 0xFECE;
  10916. t['ghaininitialarabic'] = 0xFECF;
  10917. t['ghainmedialarabic'] = 0xFED0;
  10918. t['ghemiddlehookcyrillic'] = 0x0495;
  10919. t['ghestrokecyrillic'] = 0x0493;
  10920. t['gheupturncyrillic'] = 0x0491;
  10921. t['ghhadeva'] = 0x095A;
  10922. t['ghhagurmukhi'] = 0x0A5A;
  10923. t['ghook'] = 0x0260;
  10924. t['ghzsquare'] = 0x3393;
  10925. t['gihiragana'] = 0x304E;
  10926. t['gikatakana'] = 0x30AE;
  10927. t['gimarmenian'] = 0x0563;
  10928. t['gimel'] = 0x05D2;
  10929. t['gimeldagesh'] = 0xFB32;
  10930. t['gimeldageshhebrew'] = 0xFB32;
  10931. t['gimelhebrew'] = 0x05D2;
  10932. t['gjecyrillic'] = 0x0453;
  10933. t['glottalinvertedstroke'] = 0x01BE;
  10934. t['glottalstop'] = 0x0294;
  10935. t['glottalstopinverted'] = 0x0296;
  10936. t['glottalstopmod'] = 0x02C0;
  10937. t['glottalstopreversed'] = 0x0295;
  10938. t['glottalstopreversedmod'] = 0x02C1;
  10939. t['glottalstopreversedsuperior'] = 0x02E4;
  10940. t['glottalstopstroke'] = 0x02A1;
  10941. t['glottalstopstrokereversed'] = 0x02A2;
  10942. t['gmacron'] = 0x1E21;
  10943. t['gmonospace'] = 0xFF47;
  10944. t['gohiragana'] = 0x3054;
  10945. t['gokatakana'] = 0x30B4;
  10946. t['gparen'] = 0x24A2;
  10947. t['gpasquare'] = 0x33AC;
  10948. t['gradient'] = 0x2207;
  10949. t['grave'] = 0x0060;
  10950. t['gravebelowcmb'] = 0x0316;
  10951. t['gravecmb'] = 0x0300;
  10952. t['gravecomb'] = 0x0300;
  10953. t['gravedeva'] = 0x0953;
  10954. t['gravelowmod'] = 0x02CE;
  10955. t['gravemonospace'] = 0xFF40;
  10956. t['gravetonecmb'] = 0x0340;
  10957. t['greater'] = 0x003E;
  10958. t['greaterequal'] = 0x2265;
  10959. t['greaterequalorless'] = 0x22DB;
  10960. t['greatermonospace'] = 0xFF1E;
  10961. t['greaterorequivalent'] = 0x2273;
  10962. t['greaterorless'] = 0x2277;
  10963. t['greateroverequal'] = 0x2267;
  10964. t['greatersmall'] = 0xFE65;
  10965. t['gscript'] = 0x0261;
  10966. t['gstroke'] = 0x01E5;
  10967. t['guhiragana'] = 0x3050;
  10968. t['guillemotleft'] = 0x00AB;
  10969. t['guillemotright'] = 0x00BB;
  10970. t['guilsinglleft'] = 0x2039;
  10971. t['guilsinglright'] = 0x203A;
  10972. t['gukatakana'] = 0x30B0;
  10973. t['guramusquare'] = 0x3318;
  10974. t['gysquare'] = 0x33C9;
  10975. t['h'] = 0x0068;
  10976. t['haabkhasiancyrillic'] = 0x04A9;
  10977. t['haaltonearabic'] = 0x06C1;
  10978. t['habengali'] = 0x09B9;
  10979. t['hadescendercyrillic'] = 0x04B3;
  10980. t['hadeva'] = 0x0939;
  10981. t['hagujarati'] = 0x0AB9;
  10982. t['hagurmukhi'] = 0x0A39;
  10983. t['haharabic'] = 0x062D;
  10984. t['hahfinalarabic'] = 0xFEA2;
  10985. t['hahinitialarabic'] = 0xFEA3;
  10986. t['hahiragana'] = 0x306F;
  10987. t['hahmedialarabic'] = 0xFEA4;
  10988. t['haitusquare'] = 0x332A;
  10989. t['hakatakana'] = 0x30CF;
  10990. t['hakatakanahalfwidth'] = 0xFF8A;
  10991. t['halantgurmukhi'] = 0x0A4D;
  10992. t['hamzaarabic'] = 0x0621;
  10993. t['hamzalowarabic'] = 0x0621;
  10994. t['hangulfiller'] = 0x3164;
  10995. t['hardsigncyrillic'] = 0x044A;
  10996. t['harpoonleftbarbup'] = 0x21BC;
  10997. t['harpoonrightbarbup'] = 0x21C0;
  10998. t['hasquare'] = 0x33CA;
  10999. t['hatafpatah'] = 0x05B2;
  11000. t['hatafpatah16'] = 0x05B2;
  11001. t['hatafpatah23'] = 0x05B2;
  11002. t['hatafpatah2f'] = 0x05B2;
  11003. t['hatafpatahhebrew'] = 0x05B2;
  11004. t['hatafpatahnarrowhebrew'] = 0x05B2;
  11005. t['hatafpatahquarterhebrew'] = 0x05B2;
  11006. t['hatafpatahwidehebrew'] = 0x05B2;
  11007. t['hatafqamats'] = 0x05B3;
  11008. t['hatafqamats1b'] = 0x05B3;
  11009. t['hatafqamats28'] = 0x05B3;
  11010. t['hatafqamats34'] = 0x05B3;
  11011. t['hatafqamatshebrew'] = 0x05B3;
  11012. t['hatafqamatsnarrowhebrew'] = 0x05B3;
  11013. t['hatafqamatsquarterhebrew'] = 0x05B3;
  11014. t['hatafqamatswidehebrew'] = 0x05B3;
  11015. t['hatafsegol'] = 0x05B1;
  11016. t['hatafsegol17'] = 0x05B1;
  11017. t['hatafsegol24'] = 0x05B1;
  11018. t['hatafsegol30'] = 0x05B1;
  11019. t['hatafsegolhebrew'] = 0x05B1;
  11020. t['hatafsegolnarrowhebrew'] = 0x05B1;
  11021. t['hatafsegolquarterhebrew'] = 0x05B1;
  11022. t['hatafsegolwidehebrew'] = 0x05B1;
  11023. t['hbar'] = 0x0127;
  11024. t['hbopomofo'] = 0x310F;
  11025. t['hbrevebelow'] = 0x1E2B;
  11026. t['hcedilla'] = 0x1E29;
  11027. t['hcircle'] = 0x24D7;
  11028. t['hcircumflex'] = 0x0125;
  11029. t['hdieresis'] = 0x1E27;
  11030. t['hdotaccent'] = 0x1E23;
  11031. t['hdotbelow'] = 0x1E25;
  11032. t['he'] = 0x05D4;
  11033. t['heart'] = 0x2665;
  11034. t['heartsuitblack'] = 0x2665;
  11035. t['heartsuitwhite'] = 0x2661;
  11036. t['hedagesh'] = 0xFB34;
  11037. t['hedageshhebrew'] = 0xFB34;
  11038. t['hehaltonearabic'] = 0x06C1;
  11039. t['heharabic'] = 0x0647;
  11040. t['hehebrew'] = 0x05D4;
  11041. t['hehfinalaltonearabic'] = 0xFBA7;
  11042. t['hehfinalalttwoarabic'] = 0xFEEA;
  11043. t['hehfinalarabic'] = 0xFEEA;
  11044. t['hehhamzaabovefinalarabic'] = 0xFBA5;
  11045. t['hehhamzaaboveisolatedarabic'] = 0xFBA4;
  11046. t['hehinitialaltonearabic'] = 0xFBA8;
  11047. t['hehinitialarabic'] = 0xFEEB;
  11048. t['hehiragana'] = 0x3078;
  11049. t['hehmedialaltonearabic'] = 0xFBA9;
  11050. t['hehmedialarabic'] = 0xFEEC;
  11051. t['heiseierasquare'] = 0x337B;
  11052. t['hekatakana'] = 0x30D8;
  11053. t['hekatakanahalfwidth'] = 0xFF8D;
  11054. t['hekutaarusquare'] = 0x3336;
  11055. t['henghook'] = 0x0267;
  11056. t['herutusquare'] = 0x3339;
  11057. t['het'] = 0x05D7;
  11058. t['hethebrew'] = 0x05D7;
  11059. t['hhook'] = 0x0266;
  11060. t['hhooksuperior'] = 0x02B1;
  11061. t['hieuhacirclekorean'] = 0x327B;
  11062. t['hieuhaparenkorean'] = 0x321B;
  11063. t['hieuhcirclekorean'] = 0x326D;
  11064. t['hieuhkorean'] = 0x314E;
  11065. t['hieuhparenkorean'] = 0x320D;
  11066. t['hihiragana'] = 0x3072;
  11067. t['hikatakana'] = 0x30D2;
  11068. t['hikatakanahalfwidth'] = 0xFF8B;
  11069. t['hiriq'] = 0x05B4;
  11070. t['hiriq14'] = 0x05B4;
  11071. t['hiriq21'] = 0x05B4;
  11072. t['hiriq2d'] = 0x05B4;
  11073. t['hiriqhebrew'] = 0x05B4;
  11074. t['hiriqnarrowhebrew'] = 0x05B4;
  11075. t['hiriqquarterhebrew'] = 0x05B4;
  11076. t['hiriqwidehebrew'] = 0x05B4;
  11077. t['hlinebelow'] = 0x1E96;
  11078. t['hmonospace'] = 0xFF48;
  11079. t['hoarmenian'] = 0x0570;
  11080. t['hohipthai'] = 0x0E2B;
  11081. t['hohiragana'] = 0x307B;
  11082. t['hokatakana'] = 0x30DB;
  11083. t['hokatakanahalfwidth'] = 0xFF8E;
  11084. t['holam'] = 0x05B9;
  11085. t['holam19'] = 0x05B9;
  11086. t['holam26'] = 0x05B9;
  11087. t['holam32'] = 0x05B9;
  11088. t['holamhebrew'] = 0x05B9;
  11089. t['holamnarrowhebrew'] = 0x05B9;
  11090. t['holamquarterhebrew'] = 0x05B9;
  11091. t['holamwidehebrew'] = 0x05B9;
  11092. t['honokhukthai'] = 0x0E2E;
  11093. t['hookabovecomb'] = 0x0309;
  11094. t['hookcmb'] = 0x0309;
  11095. t['hookpalatalizedbelowcmb'] = 0x0321;
  11096. t['hookretroflexbelowcmb'] = 0x0322;
  11097. t['hoonsquare'] = 0x3342;
  11098. t['horicoptic'] = 0x03E9;
  11099. t['horizontalbar'] = 0x2015;
  11100. t['horncmb'] = 0x031B;
  11101. t['hotsprings'] = 0x2668;
  11102. t['house'] = 0x2302;
  11103. t['hparen'] = 0x24A3;
  11104. t['hsuperior'] = 0x02B0;
  11105. t['hturned'] = 0x0265;
  11106. t['huhiragana'] = 0x3075;
  11107. t['huiitosquare'] = 0x3333;
  11108. t['hukatakana'] = 0x30D5;
  11109. t['hukatakanahalfwidth'] = 0xFF8C;
  11110. t['hungarumlaut'] = 0x02DD;
  11111. t['hungarumlautcmb'] = 0x030B;
  11112. t['hv'] = 0x0195;
  11113. t['hyphen'] = 0x002D;
  11114. t['hypheninferior'] = 0xF6E5;
  11115. t['hyphenmonospace'] = 0xFF0D;
  11116. t['hyphensmall'] = 0xFE63;
  11117. t['hyphensuperior'] = 0xF6E6;
  11118. t['hyphentwo'] = 0x2010;
  11119. t['i'] = 0x0069;
  11120. t['iacute'] = 0x00ED;
  11121. t['iacyrillic'] = 0x044F;
  11122. t['ibengali'] = 0x0987;
  11123. t['ibopomofo'] = 0x3127;
  11124. t['ibreve'] = 0x012D;
  11125. t['icaron'] = 0x01D0;
  11126. t['icircle'] = 0x24D8;
  11127. t['icircumflex'] = 0x00EE;
  11128. t['icyrillic'] = 0x0456;
  11129. t['idblgrave'] = 0x0209;
  11130. t['ideographearthcircle'] = 0x328F;
  11131. t['ideographfirecircle'] = 0x328B;
  11132. t['ideographicallianceparen'] = 0x323F;
  11133. t['ideographiccallparen'] = 0x323A;
  11134. t['ideographiccentrecircle'] = 0x32A5;
  11135. t['ideographicclose'] = 0x3006;
  11136. t['ideographiccomma'] = 0x3001;
  11137. t['ideographiccommaleft'] = 0xFF64;
  11138. t['ideographiccongratulationparen'] = 0x3237;
  11139. t['ideographiccorrectcircle'] = 0x32A3;
  11140. t['ideographicearthparen'] = 0x322F;
  11141. t['ideographicenterpriseparen'] = 0x323D;
  11142. t['ideographicexcellentcircle'] = 0x329D;
  11143. t['ideographicfestivalparen'] = 0x3240;
  11144. t['ideographicfinancialcircle'] = 0x3296;
  11145. t['ideographicfinancialparen'] = 0x3236;
  11146. t['ideographicfireparen'] = 0x322B;
  11147. t['ideographichaveparen'] = 0x3232;
  11148. t['ideographichighcircle'] = 0x32A4;
  11149. t['ideographiciterationmark'] = 0x3005;
  11150. t['ideographiclaborcircle'] = 0x3298;
  11151. t['ideographiclaborparen'] = 0x3238;
  11152. t['ideographicleftcircle'] = 0x32A7;
  11153. t['ideographiclowcircle'] = 0x32A6;
  11154. t['ideographicmedicinecircle'] = 0x32A9;
  11155. t['ideographicmetalparen'] = 0x322E;
  11156. t['ideographicmoonparen'] = 0x322A;
  11157. t['ideographicnameparen'] = 0x3234;
  11158. t['ideographicperiod'] = 0x3002;
  11159. t['ideographicprintcircle'] = 0x329E;
  11160. t['ideographicreachparen'] = 0x3243;
  11161. t['ideographicrepresentparen'] = 0x3239;
  11162. t['ideographicresourceparen'] = 0x323E;
  11163. t['ideographicrightcircle'] = 0x32A8;
  11164. t['ideographicsecretcircle'] = 0x3299;
  11165. t['ideographicselfparen'] = 0x3242;
  11166. t['ideographicsocietyparen'] = 0x3233;
  11167. t['ideographicspace'] = 0x3000;
  11168. t['ideographicspecialparen'] = 0x3235;
  11169. t['ideographicstockparen'] = 0x3231;
  11170. t['ideographicstudyparen'] = 0x323B;
  11171. t['ideographicsunparen'] = 0x3230;
  11172. t['ideographicsuperviseparen'] = 0x323C;
  11173. t['ideographicwaterparen'] = 0x322C;
  11174. t['ideographicwoodparen'] = 0x322D;
  11175. t['ideographiczero'] = 0x3007;
  11176. t['ideographmetalcircle'] = 0x328E;
  11177. t['ideographmooncircle'] = 0x328A;
  11178. t['ideographnamecircle'] = 0x3294;
  11179. t['ideographsuncircle'] = 0x3290;
  11180. t['ideographwatercircle'] = 0x328C;
  11181. t['ideographwoodcircle'] = 0x328D;
  11182. t['ideva'] = 0x0907;
  11183. t['idieresis'] = 0x00EF;
  11184. t['idieresisacute'] = 0x1E2F;
  11185. t['idieresiscyrillic'] = 0x04E5;
  11186. t['idotbelow'] = 0x1ECB;
  11187. t['iebrevecyrillic'] = 0x04D7;
  11188. t['iecyrillic'] = 0x0435;
  11189. t['ieungacirclekorean'] = 0x3275;
  11190. t['ieungaparenkorean'] = 0x3215;
  11191. t['ieungcirclekorean'] = 0x3267;
  11192. t['ieungkorean'] = 0x3147;
  11193. t['ieungparenkorean'] = 0x3207;
  11194. t['igrave'] = 0x00EC;
  11195. t['igujarati'] = 0x0A87;
  11196. t['igurmukhi'] = 0x0A07;
  11197. t['ihiragana'] = 0x3044;
  11198. t['ihookabove'] = 0x1EC9;
  11199. t['iibengali'] = 0x0988;
  11200. t['iicyrillic'] = 0x0438;
  11201. t['iideva'] = 0x0908;
  11202. t['iigujarati'] = 0x0A88;
  11203. t['iigurmukhi'] = 0x0A08;
  11204. t['iimatragurmukhi'] = 0x0A40;
  11205. t['iinvertedbreve'] = 0x020B;
  11206. t['iishortcyrillic'] = 0x0439;
  11207. t['iivowelsignbengali'] = 0x09C0;
  11208. t['iivowelsigndeva'] = 0x0940;
  11209. t['iivowelsigngujarati'] = 0x0AC0;
  11210. t['ij'] = 0x0133;
  11211. t['ikatakana'] = 0x30A4;
  11212. t['ikatakanahalfwidth'] = 0xFF72;
  11213. t['ikorean'] = 0x3163;
  11214. t['ilde'] = 0x02DC;
  11215. t['iluyhebrew'] = 0x05AC;
  11216. t['imacron'] = 0x012B;
  11217. t['imacroncyrillic'] = 0x04E3;
  11218. t['imageorapproximatelyequal'] = 0x2253;
  11219. t['imatragurmukhi'] = 0x0A3F;
  11220. t['imonospace'] = 0xFF49;
  11221. t['increment'] = 0x2206;
  11222. t['infinity'] = 0x221E;
  11223. t['iniarmenian'] = 0x056B;
  11224. t['integral'] = 0x222B;
  11225. t['integralbottom'] = 0x2321;
  11226. t['integralbt'] = 0x2321;
  11227. t['integralex'] = 0xF8F5;
  11228. t['integraltop'] = 0x2320;
  11229. t['integraltp'] = 0x2320;
  11230. t['intersection'] = 0x2229;
  11231. t['intisquare'] = 0x3305;
  11232. t['invbullet'] = 0x25D8;
  11233. t['invcircle'] = 0x25D9;
  11234. t['invsmileface'] = 0x263B;
  11235. t['iocyrillic'] = 0x0451;
  11236. t['iogonek'] = 0x012F;
  11237. t['iota'] = 0x03B9;
  11238. t['iotadieresis'] = 0x03CA;
  11239. t['iotadieresistonos'] = 0x0390;
  11240. t['iotalatin'] = 0x0269;
  11241. t['iotatonos'] = 0x03AF;
  11242. t['iparen'] = 0x24A4;
  11243. t['irigurmukhi'] = 0x0A72;
  11244. t['ismallhiragana'] = 0x3043;
  11245. t['ismallkatakana'] = 0x30A3;
  11246. t['ismallkatakanahalfwidth'] = 0xFF68;
  11247. t['issharbengali'] = 0x09FA;
  11248. t['istroke'] = 0x0268;
  11249. t['isuperior'] = 0xF6ED;
  11250. t['iterationhiragana'] = 0x309D;
  11251. t['iterationkatakana'] = 0x30FD;
  11252. t['itilde'] = 0x0129;
  11253. t['itildebelow'] = 0x1E2D;
  11254. t['iubopomofo'] = 0x3129;
  11255. t['iucyrillic'] = 0x044E;
  11256. t['ivowelsignbengali'] = 0x09BF;
  11257. t['ivowelsigndeva'] = 0x093F;
  11258. t['ivowelsigngujarati'] = 0x0ABF;
  11259. t['izhitsacyrillic'] = 0x0475;
  11260. t['izhitsadblgravecyrillic'] = 0x0477;
  11261. t['j'] = 0x006A;
  11262. t['jaarmenian'] = 0x0571;
  11263. t['jabengali'] = 0x099C;
  11264. t['jadeva'] = 0x091C;
  11265. t['jagujarati'] = 0x0A9C;
  11266. t['jagurmukhi'] = 0x0A1C;
  11267. t['jbopomofo'] = 0x3110;
  11268. t['jcaron'] = 0x01F0;
  11269. t['jcircle'] = 0x24D9;
  11270. t['jcircumflex'] = 0x0135;
  11271. t['jcrossedtail'] = 0x029D;
  11272. t['jdotlessstroke'] = 0x025F;
  11273. t['jecyrillic'] = 0x0458;
  11274. t['jeemarabic'] = 0x062C;
  11275. t['jeemfinalarabic'] = 0xFE9E;
  11276. t['jeeminitialarabic'] = 0xFE9F;
  11277. t['jeemmedialarabic'] = 0xFEA0;
  11278. t['jeharabic'] = 0x0698;
  11279. t['jehfinalarabic'] = 0xFB8B;
  11280. t['jhabengali'] = 0x099D;
  11281. t['jhadeva'] = 0x091D;
  11282. t['jhagujarati'] = 0x0A9D;
  11283. t['jhagurmukhi'] = 0x0A1D;
  11284. t['jheharmenian'] = 0x057B;
  11285. t['jis'] = 0x3004;
  11286. t['jmonospace'] = 0xFF4A;
  11287. t['jparen'] = 0x24A5;
  11288. t['jsuperior'] = 0x02B2;
  11289. t['k'] = 0x006B;
  11290. t['kabashkircyrillic'] = 0x04A1;
  11291. t['kabengali'] = 0x0995;
  11292. t['kacute'] = 0x1E31;
  11293. t['kacyrillic'] = 0x043A;
  11294. t['kadescendercyrillic'] = 0x049B;
  11295. t['kadeva'] = 0x0915;
  11296. t['kaf'] = 0x05DB;
  11297. t['kafarabic'] = 0x0643;
  11298. t['kafdagesh'] = 0xFB3B;
  11299. t['kafdageshhebrew'] = 0xFB3B;
  11300. t['kaffinalarabic'] = 0xFEDA;
  11301. t['kafhebrew'] = 0x05DB;
  11302. t['kafinitialarabic'] = 0xFEDB;
  11303. t['kafmedialarabic'] = 0xFEDC;
  11304. t['kafrafehebrew'] = 0xFB4D;
  11305. t['kagujarati'] = 0x0A95;
  11306. t['kagurmukhi'] = 0x0A15;
  11307. t['kahiragana'] = 0x304B;
  11308. t['kahookcyrillic'] = 0x04C4;
  11309. t['kakatakana'] = 0x30AB;
  11310. t['kakatakanahalfwidth'] = 0xFF76;
  11311. t['kappa'] = 0x03BA;
  11312. t['kappasymbolgreek'] = 0x03F0;
  11313. t['kapyeounmieumkorean'] = 0x3171;
  11314. t['kapyeounphieuphkorean'] = 0x3184;
  11315. t['kapyeounpieupkorean'] = 0x3178;
  11316. t['kapyeounssangpieupkorean'] = 0x3179;
  11317. t['karoriisquare'] = 0x330D;
  11318. t['kashidaautoarabic'] = 0x0640;
  11319. t['kashidaautonosidebearingarabic'] = 0x0640;
  11320. t['kasmallkatakana'] = 0x30F5;
  11321. t['kasquare'] = 0x3384;
  11322. t['kasraarabic'] = 0x0650;
  11323. t['kasratanarabic'] = 0x064D;
  11324. t['kastrokecyrillic'] = 0x049F;
  11325. t['katahiraprolongmarkhalfwidth'] = 0xFF70;
  11326. t['kaverticalstrokecyrillic'] = 0x049D;
  11327. t['kbopomofo'] = 0x310E;
  11328. t['kcalsquare'] = 0x3389;
  11329. t['kcaron'] = 0x01E9;
  11330. t['kcedilla'] = 0x0137;
  11331. t['kcircle'] = 0x24DA;
  11332. t['kcommaaccent'] = 0x0137;
  11333. t['kdotbelow'] = 0x1E33;
  11334. t['keharmenian'] = 0x0584;
  11335. t['kehiragana'] = 0x3051;
  11336. t['kekatakana'] = 0x30B1;
  11337. t['kekatakanahalfwidth'] = 0xFF79;
  11338. t['kenarmenian'] = 0x056F;
  11339. t['kesmallkatakana'] = 0x30F6;
  11340. t['kgreenlandic'] = 0x0138;
  11341. t['khabengali'] = 0x0996;
  11342. t['khacyrillic'] = 0x0445;
  11343. t['khadeva'] = 0x0916;
  11344. t['khagujarati'] = 0x0A96;
  11345. t['khagurmukhi'] = 0x0A16;
  11346. t['khaharabic'] = 0x062E;
  11347. t['khahfinalarabic'] = 0xFEA6;
  11348. t['khahinitialarabic'] = 0xFEA7;
  11349. t['khahmedialarabic'] = 0xFEA8;
  11350. t['kheicoptic'] = 0x03E7;
  11351. t['khhadeva'] = 0x0959;
  11352. t['khhagurmukhi'] = 0x0A59;
  11353. t['khieukhacirclekorean'] = 0x3278;
  11354. t['khieukhaparenkorean'] = 0x3218;
  11355. t['khieukhcirclekorean'] = 0x326A;
  11356. t['khieukhkorean'] = 0x314B;
  11357. t['khieukhparenkorean'] = 0x320A;
  11358. t['khokhaithai'] = 0x0E02;
  11359. t['khokhonthai'] = 0x0E05;
  11360. t['khokhuatthai'] = 0x0E03;
  11361. t['khokhwaithai'] = 0x0E04;
  11362. t['khomutthai'] = 0x0E5B;
  11363. t['khook'] = 0x0199;
  11364. t['khorakhangthai'] = 0x0E06;
  11365. t['khzsquare'] = 0x3391;
  11366. t['kihiragana'] = 0x304D;
  11367. t['kikatakana'] = 0x30AD;
  11368. t['kikatakanahalfwidth'] = 0xFF77;
  11369. t['kiroguramusquare'] = 0x3315;
  11370. t['kiromeetorusquare'] = 0x3316;
  11371. t['kirosquare'] = 0x3314;
  11372. t['kiyeokacirclekorean'] = 0x326E;
  11373. t['kiyeokaparenkorean'] = 0x320E;
  11374. t['kiyeokcirclekorean'] = 0x3260;
  11375. t['kiyeokkorean'] = 0x3131;
  11376. t['kiyeokparenkorean'] = 0x3200;
  11377. t['kiyeoksioskorean'] = 0x3133;
  11378. t['kjecyrillic'] = 0x045C;
  11379. t['klinebelow'] = 0x1E35;
  11380. t['klsquare'] = 0x3398;
  11381. t['kmcubedsquare'] = 0x33A6;
  11382. t['kmonospace'] = 0xFF4B;
  11383. t['kmsquaredsquare'] = 0x33A2;
  11384. t['kohiragana'] = 0x3053;
  11385. t['kohmsquare'] = 0x33C0;
  11386. t['kokaithai'] = 0x0E01;
  11387. t['kokatakana'] = 0x30B3;
  11388. t['kokatakanahalfwidth'] = 0xFF7A;
  11389. t['kooposquare'] = 0x331E;
  11390. t['koppacyrillic'] = 0x0481;
  11391. t['koreanstandardsymbol'] = 0x327F;
  11392. t['koroniscmb'] = 0x0343;
  11393. t['kparen'] = 0x24A6;
  11394. t['kpasquare'] = 0x33AA;
  11395. t['ksicyrillic'] = 0x046F;
  11396. t['ktsquare'] = 0x33CF;
  11397. t['kturned'] = 0x029E;
  11398. t['kuhiragana'] = 0x304F;
  11399. t['kukatakana'] = 0x30AF;
  11400. t['kukatakanahalfwidth'] = 0xFF78;
  11401. t['kvsquare'] = 0x33B8;
  11402. t['kwsquare'] = 0x33BE;
  11403. t['l'] = 0x006C;
  11404. t['labengali'] = 0x09B2;
  11405. t['lacute'] = 0x013A;
  11406. t['ladeva'] = 0x0932;
  11407. t['lagujarati'] = 0x0AB2;
  11408. t['lagurmukhi'] = 0x0A32;
  11409. t['lakkhangyaothai'] = 0x0E45;
  11410. t['lamaleffinalarabic'] = 0xFEFC;
  11411. t['lamalefhamzaabovefinalarabic'] = 0xFEF8;
  11412. t['lamalefhamzaaboveisolatedarabic'] = 0xFEF7;
  11413. t['lamalefhamzabelowfinalarabic'] = 0xFEFA;
  11414. t['lamalefhamzabelowisolatedarabic'] = 0xFEF9;
  11415. t['lamalefisolatedarabic'] = 0xFEFB;
  11416. t['lamalefmaddaabovefinalarabic'] = 0xFEF6;
  11417. t['lamalefmaddaaboveisolatedarabic'] = 0xFEF5;
  11418. t['lamarabic'] = 0x0644;
  11419. t['lambda'] = 0x03BB;
  11420. t['lambdastroke'] = 0x019B;
  11421. t['lamed'] = 0x05DC;
  11422. t['lameddagesh'] = 0xFB3C;
  11423. t['lameddageshhebrew'] = 0xFB3C;
  11424. t['lamedhebrew'] = 0x05DC;
  11425. t['lamfinalarabic'] = 0xFEDE;
  11426. t['lamhahinitialarabic'] = 0xFCCA;
  11427. t['laminitialarabic'] = 0xFEDF;
  11428. t['lamjeeminitialarabic'] = 0xFCC9;
  11429. t['lamkhahinitialarabic'] = 0xFCCB;
  11430. t['lamlamhehisolatedarabic'] = 0xFDF2;
  11431. t['lammedialarabic'] = 0xFEE0;
  11432. t['lammeemhahinitialarabic'] = 0xFD88;
  11433. t['lammeeminitialarabic'] = 0xFCCC;
  11434. t['largecircle'] = 0x25EF;
  11435. t['lbar'] = 0x019A;
  11436. t['lbelt'] = 0x026C;
  11437. t['lbopomofo'] = 0x310C;
  11438. t['lcaron'] = 0x013E;
  11439. t['lcedilla'] = 0x013C;
  11440. t['lcircle'] = 0x24DB;
  11441. t['lcircumflexbelow'] = 0x1E3D;
  11442. t['lcommaaccent'] = 0x013C;
  11443. t['ldot'] = 0x0140;
  11444. t['ldotaccent'] = 0x0140;
  11445. t['ldotbelow'] = 0x1E37;
  11446. t['ldotbelowmacron'] = 0x1E39;
  11447. t['leftangleabovecmb'] = 0x031A;
  11448. t['lefttackbelowcmb'] = 0x0318;
  11449. t['less'] = 0x003C;
  11450. t['lessequal'] = 0x2264;
  11451. t['lessequalorgreater'] = 0x22DA;
  11452. t['lessmonospace'] = 0xFF1C;
  11453. t['lessorequivalent'] = 0x2272;
  11454. t['lessorgreater'] = 0x2276;
  11455. t['lessoverequal'] = 0x2266;
  11456. t['lesssmall'] = 0xFE64;
  11457. t['lezh'] = 0x026E;
  11458. t['lfblock'] = 0x258C;
  11459. t['lhookretroflex'] = 0x026D;
  11460. t['lira'] = 0x20A4;
  11461. t['liwnarmenian'] = 0x056C;
  11462. t['lj'] = 0x01C9;
  11463. t['ljecyrillic'] = 0x0459;
  11464. t['ll'] = 0xF6C0;
  11465. t['lladeva'] = 0x0933;
  11466. t['llagujarati'] = 0x0AB3;
  11467. t['llinebelow'] = 0x1E3B;
  11468. t['llladeva'] = 0x0934;
  11469. t['llvocalicbengali'] = 0x09E1;
  11470. t['llvocalicdeva'] = 0x0961;
  11471. t['llvocalicvowelsignbengali'] = 0x09E3;
  11472. t['llvocalicvowelsigndeva'] = 0x0963;
  11473. t['lmiddletilde'] = 0x026B;
  11474. t['lmonospace'] = 0xFF4C;
  11475. t['lmsquare'] = 0x33D0;
  11476. t['lochulathai'] = 0x0E2C;
  11477. t['logicaland'] = 0x2227;
  11478. t['logicalnot'] = 0x00AC;
  11479. t['logicalnotreversed'] = 0x2310;
  11480. t['logicalor'] = 0x2228;
  11481. t['lolingthai'] = 0x0E25;
  11482. t['longs'] = 0x017F;
  11483. t['lowlinecenterline'] = 0xFE4E;
  11484. t['lowlinecmb'] = 0x0332;
  11485. t['lowlinedashed'] = 0xFE4D;
  11486. t['lozenge'] = 0x25CA;
  11487. t['lparen'] = 0x24A7;
  11488. t['lslash'] = 0x0142;
  11489. t['lsquare'] = 0x2113;
  11490. t['lsuperior'] = 0xF6EE;
  11491. t['ltshade'] = 0x2591;
  11492. t['luthai'] = 0x0E26;
  11493. t['lvocalicbengali'] = 0x098C;
  11494. t['lvocalicdeva'] = 0x090C;
  11495. t['lvocalicvowelsignbengali'] = 0x09E2;
  11496. t['lvocalicvowelsigndeva'] = 0x0962;
  11497. t['lxsquare'] = 0x33D3;
  11498. t['m'] = 0x006D;
  11499. t['mabengali'] = 0x09AE;
  11500. t['macron'] = 0x00AF;
  11501. t['macronbelowcmb'] = 0x0331;
  11502. t['macroncmb'] = 0x0304;
  11503. t['macronlowmod'] = 0x02CD;
  11504. t['macronmonospace'] = 0xFFE3;
  11505. t['macute'] = 0x1E3F;
  11506. t['madeva'] = 0x092E;
  11507. t['magujarati'] = 0x0AAE;
  11508. t['magurmukhi'] = 0x0A2E;
  11509. t['mahapakhhebrew'] = 0x05A4;
  11510. t['mahapakhlefthebrew'] = 0x05A4;
  11511. t['mahiragana'] = 0x307E;
  11512. t['maichattawalowleftthai'] = 0xF895;
  11513. t['maichattawalowrightthai'] = 0xF894;
  11514. t['maichattawathai'] = 0x0E4B;
  11515. t['maichattawaupperleftthai'] = 0xF893;
  11516. t['maieklowleftthai'] = 0xF88C;
  11517. t['maieklowrightthai'] = 0xF88B;
  11518. t['maiekthai'] = 0x0E48;
  11519. t['maiekupperleftthai'] = 0xF88A;
  11520. t['maihanakatleftthai'] = 0xF884;
  11521. t['maihanakatthai'] = 0x0E31;
  11522. t['maitaikhuleftthai'] = 0xF889;
  11523. t['maitaikhuthai'] = 0x0E47;
  11524. t['maitholowleftthai'] = 0xF88F;
  11525. t['maitholowrightthai'] = 0xF88E;
  11526. t['maithothai'] = 0x0E49;
  11527. t['maithoupperleftthai'] = 0xF88D;
  11528. t['maitrilowleftthai'] = 0xF892;
  11529. t['maitrilowrightthai'] = 0xF891;
  11530. t['maitrithai'] = 0x0E4A;
  11531. t['maitriupperleftthai'] = 0xF890;
  11532. t['maiyamokthai'] = 0x0E46;
  11533. t['makatakana'] = 0x30DE;
  11534. t['makatakanahalfwidth'] = 0xFF8F;
  11535. t['male'] = 0x2642;
  11536. t['mansyonsquare'] = 0x3347;
  11537. t['maqafhebrew'] = 0x05BE;
  11538. t['mars'] = 0x2642;
  11539. t['masoracirclehebrew'] = 0x05AF;
  11540. t['masquare'] = 0x3383;
  11541. t['mbopomofo'] = 0x3107;
  11542. t['mbsquare'] = 0x33D4;
  11543. t['mcircle'] = 0x24DC;
  11544. t['mcubedsquare'] = 0x33A5;
  11545. t['mdotaccent'] = 0x1E41;
  11546. t['mdotbelow'] = 0x1E43;
  11547. t['meemarabic'] = 0x0645;
  11548. t['meemfinalarabic'] = 0xFEE2;
  11549. t['meeminitialarabic'] = 0xFEE3;
  11550. t['meemmedialarabic'] = 0xFEE4;
  11551. t['meemmeeminitialarabic'] = 0xFCD1;
  11552. t['meemmeemisolatedarabic'] = 0xFC48;
  11553. t['meetorusquare'] = 0x334D;
  11554. t['mehiragana'] = 0x3081;
  11555. t['meizierasquare'] = 0x337E;
  11556. t['mekatakana'] = 0x30E1;
  11557. t['mekatakanahalfwidth'] = 0xFF92;
  11558. t['mem'] = 0x05DE;
  11559. t['memdagesh'] = 0xFB3E;
  11560. t['memdageshhebrew'] = 0xFB3E;
  11561. t['memhebrew'] = 0x05DE;
  11562. t['menarmenian'] = 0x0574;
  11563. t['merkhahebrew'] = 0x05A5;
  11564. t['merkhakefulahebrew'] = 0x05A6;
  11565. t['merkhakefulalefthebrew'] = 0x05A6;
  11566. t['merkhalefthebrew'] = 0x05A5;
  11567. t['mhook'] = 0x0271;
  11568. t['mhzsquare'] = 0x3392;
  11569. t['middledotkatakanahalfwidth'] = 0xFF65;
  11570. t['middot'] = 0x00B7;
  11571. t['mieumacirclekorean'] = 0x3272;
  11572. t['mieumaparenkorean'] = 0x3212;
  11573. t['mieumcirclekorean'] = 0x3264;
  11574. t['mieumkorean'] = 0x3141;
  11575. t['mieumpansioskorean'] = 0x3170;
  11576. t['mieumparenkorean'] = 0x3204;
  11577. t['mieumpieupkorean'] = 0x316E;
  11578. t['mieumsioskorean'] = 0x316F;
  11579. t['mihiragana'] = 0x307F;
  11580. t['mikatakana'] = 0x30DF;
  11581. t['mikatakanahalfwidth'] = 0xFF90;
  11582. t['minus'] = 0x2212;
  11583. t['minusbelowcmb'] = 0x0320;
  11584. t['minuscircle'] = 0x2296;
  11585. t['minusmod'] = 0x02D7;
  11586. t['minusplus'] = 0x2213;
  11587. t['minute'] = 0x2032;
  11588. t['miribaarusquare'] = 0x334A;
  11589. t['mirisquare'] = 0x3349;
  11590. t['mlonglegturned'] = 0x0270;
  11591. t['mlsquare'] = 0x3396;
  11592. t['mmcubedsquare'] = 0x33A3;
  11593. t['mmonospace'] = 0xFF4D;
  11594. t['mmsquaredsquare'] = 0x339F;
  11595. t['mohiragana'] = 0x3082;
  11596. t['mohmsquare'] = 0x33C1;
  11597. t['mokatakana'] = 0x30E2;
  11598. t['mokatakanahalfwidth'] = 0xFF93;
  11599. t['molsquare'] = 0x33D6;
  11600. t['momathai'] = 0x0E21;
  11601. t['moverssquare'] = 0x33A7;
  11602. t['moverssquaredsquare'] = 0x33A8;
  11603. t['mparen'] = 0x24A8;
  11604. t['mpasquare'] = 0x33AB;
  11605. t['mssquare'] = 0x33B3;
  11606. t['msuperior'] = 0xF6EF;
  11607. t['mturned'] = 0x026F;
  11608. t['mu'] = 0x00B5;
  11609. t['mu1'] = 0x00B5;
  11610. t['muasquare'] = 0x3382;
  11611. t['muchgreater'] = 0x226B;
  11612. t['muchless'] = 0x226A;
  11613. t['mufsquare'] = 0x338C;
  11614. t['mugreek'] = 0x03BC;
  11615. t['mugsquare'] = 0x338D;
  11616. t['muhiragana'] = 0x3080;
  11617. t['mukatakana'] = 0x30E0;
  11618. t['mukatakanahalfwidth'] = 0xFF91;
  11619. t['mulsquare'] = 0x3395;
  11620. t['multiply'] = 0x00D7;
  11621. t['mumsquare'] = 0x339B;
  11622. t['munahhebrew'] = 0x05A3;
  11623. t['munahlefthebrew'] = 0x05A3;
  11624. t['musicalnote'] = 0x266A;
  11625. t['musicalnotedbl'] = 0x266B;
  11626. t['musicflatsign'] = 0x266D;
  11627. t['musicsharpsign'] = 0x266F;
  11628. t['mussquare'] = 0x33B2;
  11629. t['muvsquare'] = 0x33B6;
  11630. t['muwsquare'] = 0x33BC;
  11631. t['mvmegasquare'] = 0x33B9;
  11632. t['mvsquare'] = 0x33B7;
  11633. t['mwmegasquare'] = 0x33BF;
  11634. t['mwsquare'] = 0x33BD;
  11635. t['n'] = 0x006E;
  11636. t['nabengali'] = 0x09A8;
  11637. t['nabla'] = 0x2207;
  11638. t['nacute'] = 0x0144;
  11639. t['nadeva'] = 0x0928;
  11640. t['nagujarati'] = 0x0AA8;
  11641. t['nagurmukhi'] = 0x0A28;
  11642. t['nahiragana'] = 0x306A;
  11643. t['nakatakana'] = 0x30CA;
  11644. t['nakatakanahalfwidth'] = 0xFF85;
  11645. t['napostrophe'] = 0x0149;
  11646. t['nasquare'] = 0x3381;
  11647. t['nbopomofo'] = 0x310B;
  11648. t['nbspace'] = 0x00A0;
  11649. t['ncaron'] = 0x0148;
  11650. t['ncedilla'] = 0x0146;
  11651. t['ncircle'] = 0x24DD;
  11652. t['ncircumflexbelow'] = 0x1E4B;
  11653. t['ncommaaccent'] = 0x0146;
  11654. t['ndotaccent'] = 0x1E45;
  11655. t['ndotbelow'] = 0x1E47;
  11656. t['nehiragana'] = 0x306D;
  11657. t['nekatakana'] = 0x30CD;
  11658. t['nekatakanahalfwidth'] = 0xFF88;
  11659. t['newsheqelsign'] = 0x20AA;
  11660. t['nfsquare'] = 0x338B;
  11661. t['ngabengali'] = 0x0999;
  11662. t['ngadeva'] = 0x0919;
  11663. t['ngagujarati'] = 0x0A99;
  11664. t['ngagurmukhi'] = 0x0A19;
  11665. t['ngonguthai'] = 0x0E07;
  11666. t['nhiragana'] = 0x3093;
  11667. t['nhookleft'] = 0x0272;
  11668. t['nhookretroflex'] = 0x0273;
  11669. t['nieunacirclekorean'] = 0x326F;
  11670. t['nieunaparenkorean'] = 0x320F;
  11671. t['nieuncieuckorean'] = 0x3135;
  11672. t['nieuncirclekorean'] = 0x3261;
  11673. t['nieunhieuhkorean'] = 0x3136;
  11674. t['nieunkorean'] = 0x3134;
  11675. t['nieunpansioskorean'] = 0x3168;
  11676. t['nieunparenkorean'] = 0x3201;
  11677. t['nieunsioskorean'] = 0x3167;
  11678. t['nieuntikeutkorean'] = 0x3166;
  11679. t['nihiragana'] = 0x306B;
  11680. t['nikatakana'] = 0x30CB;
  11681. t['nikatakanahalfwidth'] = 0xFF86;
  11682. t['nikhahitleftthai'] = 0xF899;
  11683. t['nikhahitthai'] = 0x0E4D;
  11684. t['nine'] = 0x0039;
  11685. t['ninearabic'] = 0x0669;
  11686. t['ninebengali'] = 0x09EF;
  11687. t['ninecircle'] = 0x2468;
  11688. t['ninecircleinversesansserif'] = 0x2792;
  11689. t['ninedeva'] = 0x096F;
  11690. t['ninegujarati'] = 0x0AEF;
  11691. t['ninegurmukhi'] = 0x0A6F;
  11692. t['ninehackarabic'] = 0x0669;
  11693. t['ninehangzhou'] = 0x3029;
  11694. t['nineideographicparen'] = 0x3228;
  11695. t['nineinferior'] = 0x2089;
  11696. t['ninemonospace'] = 0xFF19;
  11697. t['nineoldstyle'] = 0xF739;
  11698. t['nineparen'] = 0x247C;
  11699. t['nineperiod'] = 0x2490;
  11700. t['ninepersian'] = 0x06F9;
  11701. t['nineroman'] = 0x2178;
  11702. t['ninesuperior'] = 0x2079;
  11703. t['nineteencircle'] = 0x2472;
  11704. t['nineteenparen'] = 0x2486;
  11705. t['nineteenperiod'] = 0x249A;
  11706. t['ninethai'] = 0x0E59;
  11707. t['nj'] = 0x01CC;
  11708. t['njecyrillic'] = 0x045A;
  11709. t['nkatakana'] = 0x30F3;
  11710. t['nkatakanahalfwidth'] = 0xFF9D;
  11711. t['nlegrightlong'] = 0x019E;
  11712. t['nlinebelow'] = 0x1E49;
  11713. t['nmonospace'] = 0xFF4E;
  11714. t['nmsquare'] = 0x339A;
  11715. t['nnabengali'] = 0x09A3;
  11716. t['nnadeva'] = 0x0923;
  11717. t['nnagujarati'] = 0x0AA3;
  11718. t['nnagurmukhi'] = 0x0A23;
  11719. t['nnnadeva'] = 0x0929;
  11720. t['nohiragana'] = 0x306E;
  11721. t['nokatakana'] = 0x30CE;
  11722. t['nokatakanahalfwidth'] = 0xFF89;
  11723. t['nonbreakingspace'] = 0x00A0;
  11724. t['nonenthai'] = 0x0E13;
  11725. t['nonuthai'] = 0x0E19;
  11726. t['noonarabic'] = 0x0646;
  11727. t['noonfinalarabic'] = 0xFEE6;
  11728. t['noonghunnaarabic'] = 0x06BA;
  11729. t['noonghunnafinalarabic'] = 0xFB9F;
  11730. t['nooninitialarabic'] = 0xFEE7;
  11731. t['noonjeeminitialarabic'] = 0xFCD2;
  11732. t['noonjeemisolatedarabic'] = 0xFC4B;
  11733. t['noonmedialarabic'] = 0xFEE8;
  11734. t['noonmeeminitialarabic'] = 0xFCD5;
  11735. t['noonmeemisolatedarabic'] = 0xFC4E;
  11736. t['noonnoonfinalarabic'] = 0xFC8D;
  11737. t['notcontains'] = 0x220C;
  11738. t['notelement'] = 0x2209;
  11739. t['notelementof'] = 0x2209;
  11740. t['notequal'] = 0x2260;
  11741. t['notgreater'] = 0x226F;
  11742. t['notgreaternorequal'] = 0x2271;
  11743. t['notgreaternorless'] = 0x2279;
  11744. t['notidentical'] = 0x2262;
  11745. t['notless'] = 0x226E;
  11746. t['notlessnorequal'] = 0x2270;
  11747. t['notparallel'] = 0x2226;
  11748. t['notprecedes'] = 0x2280;
  11749. t['notsubset'] = 0x2284;
  11750. t['notsucceeds'] = 0x2281;
  11751. t['notsuperset'] = 0x2285;
  11752. t['nowarmenian'] = 0x0576;
  11753. t['nparen'] = 0x24A9;
  11754. t['nssquare'] = 0x33B1;
  11755. t['nsuperior'] = 0x207F;
  11756. t['ntilde'] = 0x00F1;
  11757. t['nu'] = 0x03BD;
  11758. t['nuhiragana'] = 0x306C;
  11759. t['nukatakana'] = 0x30CC;
  11760. t['nukatakanahalfwidth'] = 0xFF87;
  11761. t['nuktabengali'] = 0x09BC;
  11762. t['nuktadeva'] = 0x093C;
  11763. t['nuktagujarati'] = 0x0ABC;
  11764. t['nuktagurmukhi'] = 0x0A3C;
  11765. t['numbersign'] = 0x0023;
  11766. t['numbersignmonospace'] = 0xFF03;
  11767. t['numbersignsmall'] = 0xFE5F;
  11768. t['numeralsigngreek'] = 0x0374;
  11769. t['numeralsignlowergreek'] = 0x0375;
  11770. t['numero'] = 0x2116;
  11771. t['nun'] = 0x05E0;
  11772. t['nundagesh'] = 0xFB40;
  11773. t['nundageshhebrew'] = 0xFB40;
  11774. t['nunhebrew'] = 0x05E0;
  11775. t['nvsquare'] = 0x33B5;
  11776. t['nwsquare'] = 0x33BB;
  11777. t['nyabengali'] = 0x099E;
  11778. t['nyadeva'] = 0x091E;
  11779. t['nyagujarati'] = 0x0A9E;
  11780. t['nyagurmukhi'] = 0x0A1E;
  11781. t['o'] = 0x006F;
  11782. t['oacute'] = 0x00F3;
  11783. t['oangthai'] = 0x0E2D;
  11784. t['obarred'] = 0x0275;
  11785. t['obarredcyrillic'] = 0x04E9;
  11786. t['obarreddieresiscyrillic'] = 0x04EB;
  11787. t['obengali'] = 0x0993;
  11788. t['obopomofo'] = 0x311B;
  11789. t['obreve'] = 0x014F;
  11790. t['ocandradeva'] = 0x0911;
  11791. t['ocandragujarati'] = 0x0A91;
  11792. t['ocandravowelsigndeva'] = 0x0949;
  11793. t['ocandravowelsigngujarati'] = 0x0AC9;
  11794. t['ocaron'] = 0x01D2;
  11795. t['ocircle'] = 0x24DE;
  11796. t['ocircumflex'] = 0x00F4;
  11797. t['ocircumflexacute'] = 0x1ED1;
  11798. t['ocircumflexdotbelow'] = 0x1ED9;
  11799. t['ocircumflexgrave'] = 0x1ED3;
  11800. t['ocircumflexhookabove'] = 0x1ED5;
  11801. t['ocircumflextilde'] = 0x1ED7;
  11802. t['ocyrillic'] = 0x043E;
  11803. t['odblacute'] = 0x0151;
  11804. t['odblgrave'] = 0x020D;
  11805. t['odeva'] = 0x0913;
  11806. t['odieresis'] = 0x00F6;
  11807. t['odieresiscyrillic'] = 0x04E7;
  11808. t['odotbelow'] = 0x1ECD;
  11809. t['oe'] = 0x0153;
  11810. t['oekorean'] = 0x315A;
  11811. t['ogonek'] = 0x02DB;
  11812. t['ogonekcmb'] = 0x0328;
  11813. t['ograve'] = 0x00F2;
  11814. t['ogujarati'] = 0x0A93;
  11815. t['oharmenian'] = 0x0585;
  11816. t['ohiragana'] = 0x304A;
  11817. t['ohookabove'] = 0x1ECF;
  11818. t['ohorn'] = 0x01A1;
  11819. t['ohornacute'] = 0x1EDB;
  11820. t['ohorndotbelow'] = 0x1EE3;
  11821. t['ohorngrave'] = 0x1EDD;
  11822. t['ohornhookabove'] = 0x1EDF;
  11823. t['ohorntilde'] = 0x1EE1;
  11824. t['ohungarumlaut'] = 0x0151;
  11825. t['oi'] = 0x01A3;
  11826. t['oinvertedbreve'] = 0x020F;
  11827. t['okatakana'] = 0x30AA;
  11828. t['okatakanahalfwidth'] = 0xFF75;
  11829. t['okorean'] = 0x3157;
  11830. t['olehebrew'] = 0x05AB;
  11831. t['omacron'] = 0x014D;
  11832. t['omacronacute'] = 0x1E53;
  11833. t['omacrongrave'] = 0x1E51;
  11834. t['omdeva'] = 0x0950;
  11835. t['omega'] = 0x03C9;
  11836. t['omega1'] = 0x03D6;
  11837. t['omegacyrillic'] = 0x0461;
  11838. t['omegalatinclosed'] = 0x0277;
  11839. t['omegaroundcyrillic'] = 0x047B;
  11840. t['omegatitlocyrillic'] = 0x047D;
  11841. t['omegatonos'] = 0x03CE;
  11842. t['omgujarati'] = 0x0AD0;
  11843. t['omicron'] = 0x03BF;
  11844. t['omicrontonos'] = 0x03CC;
  11845. t['omonospace'] = 0xFF4F;
  11846. t['one'] = 0x0031;
  11847. t['onearabic'] = 0x0661;
  11848. t['onebengali'] = 0x09E7;
  11849. t['onecircle'] = 0x2460;
  11850. t['onecircleinversesansserif'] = 0x278A;
  11851. t['onedeva'] = 0x0967;
  11852. t['onedotenleader'] = 0x2024;
  11853. t['oneeighth'] = 0x215B;
  11854. t['onefitted'] = 0xF6DC;
  11855. t['onegujarati'] = 0x0AE7;
  11856. t['onegurmukhi'] = 0x0A67;
  11857. t['onehackarabic'] = 0x0661;
  11858. t['onehalf'] = 0x00BD;
  11859. t['onehangzhou'] = 0x3021;
  11860. t['oneideographicparen'] = 0x3220;
  11861. t['oneinferior'] = 0x2081;
  11862. t['onemonospace'] = 0xFF11;
  11863. t['onenumeratorbengali'] = 0x09F4;
  11864. t['oneoldstyle'] = 0xF731;
  11865. t['oneparen'] = 0x2474;
  11866. t['oneperiod'] = 0x2488;
  11867. t['onepersian'] = 0x06F1;
  11868. t['onequarter'] = 0x00BC;
  11869. t['oneroman'] = 0x2170;
  11870. t['onesuperior'] = 0x00B9;
  11871. t['onethai'] = 0x0E51;
  11872. t['onethird'] = 0x2153;
  11873. t['oogonek'] = 0x01EB;
  11874. t['oogonekmacron'] = 0x01ED;
  11875. t['oogurmukhi'] = 0x0A13;
  11876. t['oomatragurmukhi'] = 0x0A4B;
  11877. t['oopen'] = 0x0254;
  11878. t['oparen'] = 0x24AA;
  11879. t['openbullet'] = 0x25E6;
  11880. t['option'] = 0x2325;
  11881. t['ordfeminine'] = 0x00AA;
  11882. t['ordmasculine'] = 0x00BA;
  11883. t['orthogonal'] = 0x221F;
  11884. t['oshortdeva'] = 0x0912;
  11885. t['oshortvowelsigndeva'] = 0x094A;
  11886. t['oslash'] = 0x00F8;
  11887. t['oslashacute'] = 0x01FF;
  11888. t['osmallhiragana'] = 0x3049;
  11889. t['osmallkatakana'] = 0x30A9;
  11890. t['osmallkatakanahalfwidth'] = 0xFF6B;
  11891. t['ostrokeacute'] = 0x01FF;
  11892. t['osuperior'] = 0xF6F0;
  11893. t['otcyrillic'] = 0x047F;
  11894. t['otilde'] = 0x00F5;
  11895. t['otildeacute'] = 0x1E4D;
  11896. t['otildedieresis'] = 0x1E4F;
  11897. t['oubopomofo'] = 0x3121;
  11898. t['overline'] = 0x203E;
  11899. t['overlinecenterline'] = 0xFE4A;
  11900. t['overlinecmb'] = 0x0305;
  11901. t['overlinedashed'] = 0xFE49;
  11902. t['overlinedblwavy'] = 0xFE4C;
  11903. t['overlinewavy'] = 0xFE4B;
  11904. t['overscore'] = 0x00AF;
  11905. t['ovowelsignbengali'] = 0x09CB;
  11906. t['ovowelsigndeva'] = 0x094B;
  11907. t['ovowelsigngujarati'] = 0x0ACB;
  11908. t['p'] = 0x0070;
  11909. t['paampssquare'] = 0x3380;
  11910. t['paasentosquare'] = 0x332B;
  11911. t['pabengali'] = 0x09AA;
  11912. t['pacute'] = 0x1E55;
  11913. t['padeva'] = 0x092A;
  11914. t['pagedown'] = 0x21DF;
  11915. t['pageup'] = 0x21DE;
  11916. t['pagujarati'] = 0x0AAA;
  11917. t['pagurmukhi'] = 0x0A2A;
  11918. t['pahiragana'] = 0x3071;
  11919. t['paiyannoithai'] = 0x0E2F;
  11920. t['pakatakana'] = 0x30D1;
  11921. t['palatalizationcyrilliccmb'] = 0x0484;
  11922. t['palochkacyrillic'] = 0x04C0;
  11923. t['pansioskorean'] = 0x317F;
  11924. t['paragraph'] = 0x00B6;
  11925. t['parallel'] = 0x2225;
  11926. t['parenleft'] = 0x0028;
  11927. t['parenleftaltonearabic'] = 0xFD3E;
  11928. t['parenleftbt'] = 0xF8ED;
  11929. t['parenleftex'] = 0xF8EC;
  11930. t['parenleftinferior'] = 0x208D;
  11931. t['parenleftmonospace'] = 0xFF08;
  11932. t['parenleftsmall'] = 0xFE59;
  11933. t['parenleftsuperior'] = 0x207D;
  11934. t['parenlefttp'] = 0xF8EB;
  11935. t['parenleftvertical'] = 0xFE35;
  11936. t['parenright'] = 0x0029;
  11937. t['parenrightaltonearabic'] = 0xFD3F;
  11938. t['parenrightbt'] = 0xF8F8;
  11939. t['parenrightex'] = 0xF8F7;
  11940. t['parenrightinferior'] = 0x208E;
  11941. t['parenrightmonospace'] = 0xFF09;
  11942. t['parenrightsmall'] = 0xFE5A;
  11943. t['parenrightsuperior'] = 0x207E;
  11944. t['parenrighttp'] = 0xF8F6;
  11945. t['parenrightvertical'] = 0xFE36;
  11946. t['partialdiff'] = 0x2202;
  11947. t['paseqhebrew'] = 0x05C0;
  11948. t['pashtahebrew'] = 0x0599;
  11949. t['pasquare'] = 0x33A9;
  11950. t['patah'] = 0x05B7;
  11951. t['patah11'] = 0x05B7;
  11952. t['patah1d'] = 0x05B7;
  11953. t['patah2a'] = 0x05B7;
  11954. t['patahhebrew'] = 0x05B7;
  11955. t['patahnarrowhebrew'] = 0x05B7;
  11956. t['patahquarterhebrew'] = 0x05B7;
  11957. t['patahwidehebrew'] = 0x05B7;
  11958. t['pazerhebrew'] = 0x05A1;
  11959. t['pbopomofo'] = 0x3106;
  11960. t['pcircle'] = 0x24DF;
  11961. t['pdotaccent'] = 0x1E57;
  11962. t['pe'] = 0x05E4;
  11963. t['pecyrillic'] = 0x043F;
  11964. t['pedagesh'] = 0xFB44;
  11965. t['pedageshhebrew'] = 0xFB44;
  11966. t['peezisquare'] = 0x333B;
  11967. t['pefinaldageshhebrew'] = 0xFB43;
  11968. t['peharabic'] = 0x067E;
  11969. t['peharmenian'] = 0x057A;
  11970. t['pehebrew'] = 0x05E4;
  11971. t['pehfinalarabic'] = 0xFB57;
  11972. t['pehinitialarabic'] = 0xFB58;
  11973. t['pehiragana'] = 0x307A;
  11974. t['pehmedialarabic'] = 0xFB59;
  11975. t['pekatakana'] = 0x30DA;
  11976. t['pemiddlehookcyrillic'] = 0x04A7;
  11977. t['perafehebrew'] = 0xFB4E;
  11978. t['percent'] = 0x0025;
  11979. t['percentarabic'] = 0x066A;
  11980. t['percentmonospace'] = 0xFF05;
  11981. t['percentsmall'] = 0xFE6A;
  11982. t['period'] = 0x002E;
  11983. t['periodarmenian'] = 0x0589;
  11984. t['periodcentered'] = 0x00B7;
  11985. t['periodhalfwidth'] = 0xFF61;
  11986. t['periodinferior'] = 0xF6E7;
  11987. t['periodmonospace'] = 0xFF0E;
  11988. t['periodsmall'] = 0xFE52;
  11989. t['periodsuperior'] = 0xF6E8;
  11990. t['perispomenigreekcmb'] = 0x0342;
  11991. t['perpendicular'] = 0x22A5;
  11992. t['perthousand'] = 0x2030;
  11993. t['peseta'] = 0x20A7;
  11994. t['pfsquare'] = 0x338A;
  11995. t['phabengali'] = 0x09AB;
  11996. t['phadeva'] = 0x092B;
  11997. t['phagujarati'] = 0x0AAB;
  11998. t['phagurmukhi'] = 0x0A2B;
  11999. t['phi'] = 0x03C6;
  12000. t['phi1'] = 0x03D5;
  12001. t['phieuphacirclekorean'] = 0x327A;
  12002. t['phieuphaparenkorean'] = 0x321A;
  12003. t['phieuphcirclekorean'] = 0x326C;
  12004. t['phieuphkorean'] = 0x314D;
  12005. t['phieuphparenkorean'] = 0x320C;
  12006. t['philatin'] = 0x0278;
  12007. t['phinthuthai'] = 0x0E3A;
  12008. t['phisymbolgreek'] = 0x03D5;
  12009. t['phook'] = 0x01A5;
  12010. t['phophanthai'] = 0x0E1E;
  12011. t['phophungthai'] = 0x0E1C;
  12012. t['phosamphaothai'] = 0x0E20;
  12013. t['pi'] = 0x03C0;
  12014. t['pieupacirclekorean'] = 0x3273;
  12015. t['pieupaparenkorean'] = 0x3213;
  12016. t['pieupcieuckorean'] = 0x3176;
  12017. t['pieupcirclekorean'] = 0x3265;
  12018. t['pieupkiyeokkorean'] = 0x3172;
  12019. t['pieupkorean'] = 0x3142;
  12020. t['pieupparenkorean'] = 0x3205;
  12021. t['pieupsioskiyeokkorean'] = 0x3174;
  12022. t['pieupsioskorean'] = 0x3144;
  12023. t['pieupsiostikeutkorean'] = 0x3175;
  12024. t['pieupthieuthkorean'] = 0x3177;
  12025. t['pieuptikeutkorean'] = 0x3173;
  12026. t['pihiragana'] = 0x3074;
  12027. t['pikatakana'] = 0x30D4;
  12028. t['pisymbolgreek'] = 0x03D6;
  12029. t['piwrarmenian'] = 0x0583;
  12030. t['plus'] = 0x002B;
  12031. t['plusbelowcmb'] = 0x031F;
  12032. t['pluscircle'] = 0x2295;
  12033. t['plusminus'] = 0x00B1;
  12034. t['plusmod'] = 0x02D6;
  12035. t['plusmonospace'] = 0xFF0B;
  12036. t['plussmall'] = 0xFE62;
  12037. t['plussuperior'] = 0x207A;
  12038. t['pmonospace'] = 0xFF50;
  12039. t['pmsquare'] = 0x33D8;
  12040. t['pohiragana'] = 0x307D;
  12041. t['pointingindexdownwhite'] = 0x261F;
  12042. t['pointingindexleftwhite'] = 0x261C;
  12043. t['pointingindexrightwhite'] = 0x261E;
  12044. t['pointingindexupwhite'] = 0x261D;
  12045. t['pokatakana'] = 0x30DD;
  12046. t['poplathai'] = 0x0E1B;
  12047. t['postalmark'] = 0x3012;
  12048. t['postalmarkface'] = 0x3020;
  12049. t['pparen'] = 0x24AB;
  12050. t['precedes'] = 0x227A;
  12051. t['prescription'] = 0x211E;
  12052. t['primemod'] = 0x02B9;
  12053. t['primereversed'] = 0x2035;
  12054. t['product'] = 0x220F;
  12055. t['projective'] = 0x2305;
  12056. t['prolongedkana'] = 0x30FC;
  12057. t['propellor'] = 0x2318;
  12058. t['propersubset'] = 0x2282;
  12059. t['propersuperset'] = 0x2283;
  12060. t['proportion'] = 0x2237;
  12061. t['proportional'] = 0x221D;
  12062. t['psi'] = 0x03C8;
  12063. t['psicyrillic'] = 0x0471;
  12064. t['psilipneumatacyrilliccmb'] = 0x0486;
  12065. t['pssquare'] = 0x33B0;
  12066. t['puhiragana'] = 0x3077;
  12067. t['pukatakana'] = 0x30D7;
  12068. t['pvsquare'] = 0x33B4;
  12069. t['pwsquare'] = 0x33BA;
  12070. t['q'] = 0x0071;
  12071. t['qadeva'] = 0x0958;
  12072. t['qadmahebrew'] = 0x05A8;
  12073. t['qafarabic'] = 0x0642;
  12074. t['qaffinalarabic'] = 0xFED6;
  12075. t['qafinitialarabic'] = 0xFED7;
  12076. t['qafmedialarabic'] = 0xFED8;
  12077. t['qamats'] = 0x05B8;
  12078. t['qamats10'] = 0x05B8;
  12079. t['qamats1a'] = 0x05B8;
  12080. t['qamats1c'] = 0x05B8;
  12081. t['qamats27'] = 0x05B8;
  12082. t['qamats29'] = 0x05B8;
  12083. t['qamats33'] = 0x05B8;
  12084. t['qamatsde'] = 0x05B8;
  12085. t['qamatshebrew'] = 0x05B8;
  12086. t['qamatsnarrowhebrew'] = 0x05B8;
  12087. t['qamatsqatanhebrew'] = 0x05B8;
  12088. t['qamatsqatannarrowhebrew'] = 0x05B8;
  12089. t['qamatsqatanquarterhebrew'] = 0x05B8;
  12090. t['qamatsqatanwidehebrew'] = 0x05B8;
  12091. t['qamatsquarterhebrew'] = 0x05B8;
  12092. t['qamatswidehebrew'] = 0x05B8;
  12093. t['qarneyparahebrew'] = 0x059F;
  12094. t['qbopomofo'] = 0x3111;
  12095. t['qcircle'] = 0x24E0;
  12096. t['qhook'] = 0x02A0;
  12097. t['qmonospace'] = 0xFF51;
  12098. t['qof'] = 0x05E7;
  12099. t['qofdagesh'] = 0xFB47;
  12100. t['qofdageshhebrew'] = 0xFB47;
  12101. t['qofhebrew'] = 0x05E7;
  12102. t['qparen'] = 0x24AC;
  12103. t['quarternote'] = 0x2669;
  12104. t['qubuts'] = 0x05BB;
  12105. t['qubuts18'] = 0x05BB;
  12106. t['qubuts25'] = 0x05BB;
  12107. t['qubuts31'] = 0x05BB;
  12108. t['qubutshebrew'] = 0x05BB;
  12109. t['qubutsnarrowhebrew'] = 0x05BB;
  12110. t['qubutsquarterhebrew'] = 0x05BB;
  12111. t['qubutswidehebrew'] = 0x05BB;
  12112. t['question'] = 0x003F;
  12113. t['questionarabic'] = 0x061F;
  12114. t['questionarmenian'] = 0x055E;
  12115. t['questiondown'] = 0x00BF;
  12116. t['questiondownsmall'] = 0xF7BF;
  12117. t['questiongreek'] = 0x037E;
  12118. t['questionmonospace'] = 0xFF1F;
  12119. t['questionsmall'] = 0xF73F;
  12120. t['quotedbl'] = 0x0022;
  12121. t['quotedblbase'] = 0x201E;
  12122. t['quotedblleft'] = 0x201C;
  12123. t['quotedblmonospace'] = 0xFF02;
  12124. t['quotedblprime'] = 0x301E;
  12125. t['quotedblprimereversed'] = 0x301D;
  12126. t['quotedblright'] = 0x201D;
  12127. t['quoteleft'] = 0x2018;
  12128. t['quoteleftreversed'] = 0x201B;
  12129. t['quotereversed'] = 0x201B;
  12130. t['quoteright'] = 0x2019;
  12131. t['quoterightn'] = 0x0149;
  12132. t['quotesinglbase'] = 0x201A;
  12133. t['quotesingle'] = 0x0027;
  12134. t['quotesinglemonospace'] = 0xFF07;
  12135. t['r'] = 0x0072;
  12136. t['raarmenian'] = 0x057C;
  12137. t['rabengali'] = 0x09B0;
  12138. t['racute'] = 0x0155;
  12139. t['radeva'] = 0x0930;
  12140. t['radical'] = 0x221A;
  12141. t['radicalex'] = 0xF8E5;
  12142. t['radoverssquare'] = 0x33AE;
  12143. t['radoverssquaredsquare'] = 0x33AF;
  12144. t['radsquare'] = 0x33AD;
  12145. t['rafe'] = 0x05BF;
  12146. t['rafehebrew'] = 0x05BF;
  12147. t['ragujarati'] = 0x0AB0;
  12148. t['ragurmukhi'] = 0x0A30;
  12149. t['rahiragana'] = 0x3089;
  12150. t['rakatakana'] = 0x30E9;
  12151. t['rakatakanahalfwidth'] = 0xFF97;
  12152. t['ralowerdiagonalbengali'] = 0x09F1;
  12153. t['ramiddlediagonalbengali'] = 0x09F0;
  12154. t['ramshorn'] = 0x0264;
  12155. t['ratio'] = 0x2236;
  12156. t['rbopomofo'] = 0x3116;
  12157. t['rcaron'] = 0x0159;
  12158. t['rcedilla'] = 0x0157;
  12159. t['rcircle'] = 0x24E1;
  12160. t['rcommaaccent'] = 0x0157;
  12161. t['rdblgrave'] = 0x0211;
  12162. t['rdotaccent'] = 0x1E59;
  12163. t['rdotbelow'] = 0x1E5B;
  12164. t['rdotbelowmacron'] = 0x1E5D;
  12165. t['referencemark'] = 0x203B;
  12166. t['reflexsubset'] = 0x2286;
  12167. t['reflexsuperset'] = 0x2287;
  12168. t['registered'] = 0x00AE;
  12169. t['registersans'] = 0xF8E8;
  12170. t['registerserif'] = 0xF6DA;
  12171. t['reharabic'] = 0x0631;
  12172. t['reharmenian'] = 0x0580;
  12173. t['rehfinalarabic'] = 0xFEAE;
  12174. t['rehiragana'] = 0x308C;
  12175. t['rekatakana'] = 0x30EC;
  12176. t['rekatakanahalfwidth'] = 0xFF9A;
  12177. t['resh'] = 0x05E8;
  12178. t['reshdageshhebrew'] = 0xFB48;
  12179. t['reshhebrew'] = 0x05E8;
  12180. t['reversedtilde'] = 0x223D;
  12181. t['reviahebrew'] = 0x0597;
  12182. t['reviamugrashhebrew'] = 0x0597;
  12183. t['revlogicalnot'] = 0x2310;
  12184. t['rfishhook'] = 0x027E;
  12185. t['rfishhookreversed'] = 0x027F;
  12186. t['rhabengali'] = 0x09DD;
  12187. t['rhadeva'] = 0x095D;
  12188. t['rho'] = 0x03C1;
  12189. t['rhook'] = 0x027D;
  12190. t['rhookturned'] = 0x027B;
  12191. t['rhookturnedsuperior'] = 0x02B5;
  12192. t['rhosymbolgreek'] = 0x03F1;
  12193. t['rhotichookmod'] = 0x02DE;
  12194. t['rieulacirclekorean'] = 0x3271;
  12195. t['rieulaparenkorean'] = 0x3211;
  12196. t['rieulcirclekorean'] = 0x3263;
  12197. t['rieulhieuhkorean'] = 0x3140;
  12198. t['rieulkiyeokkorean'] = 0x313A;
  12199. t['rieulkiyeoksioskorean'] = 0x3169;
  12200. t['rieulkorean'] = 0x3139;
  12201. t['rieulmieumkorean'] = 0x313B;
  12202. t['rieulpansioskorean'] = 0x316C;
  12203. t['rieulparenkorean'] = 0x3203;
  12204. t['rieulphieuphkorean'] = 0x313F;
  12205. t['rieulpieupkorean'] = 0x313C;
  12206. t['rieulpieupsioskorean'] = 0x316B;
  12207. t['rieulsioskorean'] = 0x313D;
  12208. t['rieulthieuthkorean'] = 0x313E;
  12209. t['rieultikeutkorean'] = 0x316A;
  12210. t['rieulyeorinhieuhkorean'] = 0x316D;
  12211. t['rightangle'] = 0x221F;
  12212. t['righttackbelowcmb'] = 0x0319;
  12213. t['righttriangle'] = 0x22BF;
  12214. t['rihiragana'] = 0x308A;
  12215. t['rikatakana'] = 0x30EA;
  12216. t['rikatakanahalfwidth'] = 0xFF98;
  12217. t['ring'] = 0x02DA;
  12218. t['ringbelowcmb'] = 0x0325;
  12219. t['ringcmb'] = 0x030A;
  12220. t['ringhalfleft'] = 0x02BF;
  12221. t['ringhalfleftarmenian'] = 0x0559;
  12222. t['ringhalfleftbelowcmb'] = 0x031C;
  12223. t['ringhalfleftcentered'] = 0x02D3;
  12224. t['ringhalfright'] = 0x02BE;
  12225. t['ringhalfrightbelowcmb'] = 0x0339;
  12226. t['ringhalfrightcentered'] = 0x02D2;
  12227. t['rinvertedbreve'] = 0x0213;
  12228. t['rittorusquare'] = 0x3351;
  12229. t['rlinebelow'] = 0x1E5F;
  12230. t['rlongleg'] = 0x027C;
  12231. t['rlonglegturned'] = 0x027A;
  12232. t['rmonospace'] = 0xFF52;
  12233. t['rohiragana'] = 0x308D;
  12234. t['rokatakana'] = 0x30ED;
  12235. t['rokatakanahalfwidth'] = 0xFF9B;
  12236. t['roruathai'] = 0x0E23;
  12237. t['rparen'] = 0x24AD;
  12238. t['rrabengali'] = 0x09DC;
  12239. t['rradeva'] = 0x0931;
  12240. t['rragurmukhi'] = 0x0A5C;
  12241. t['rreharabic'] = 0x0691;
  12242. t['rrehfinalarabic'] = 0xFB8D;
  12243. t['rrvocalicbengali'] = 0x09E0;
  12244. t['rrvocalicdeva'] = 0x0960;
  12245. t['rrvocalicgujarati'] = 0x0AE0;
  12246. t['rrvocalicvowelsignbengali'] = 0x09C4;
  12247. t['rrvocalicvowelsigndeva'] = 0x0944;
  12248. t['rrvocalicvowelsigngujarati'] = 0x0AC4;
  12249. t['rsuperior'] = 0xF6F1;
  12250. t['rtblock'] = 0x2590;
  12251. t['rturned'] = 0x0279;
  12252. t['rturnedsuperior'] = 0x02B4;
  12253. t['ruhiragana'] = 0x308B;
  12254. t['rukatakana'] = 0x30EB;
  12255. t['rukatakanahalfwidth'] = 0xFF99;
  12256. t['rupeemarkbengali'] = 0x09F2;
  12257. t['rupeesignbengali'] = 0x09F3;
  12258. t['rupiah'] = 0xF6DD;
  12259. t['ruthai'] = 0x0E24;
  12260. t['rvocalicbengali'] = 0x098B;
  12261. t['rvocalicdeva'] = 0x090B;
  12262. t['rvocalicgujarati'] = 0x0A8B;
  12263. t['rvocalicvowelsignbengali'] = 0x09C3;
  12264. t['rvocalicvowelsigndeva'] = 0x0943;
  12265. t['rvocalicvowelsigngujarati'] = 0x0AC3;
  12266. t['s'] = 0x0073;
  12267. t['sabengali'] = 0x09B8;
  12268. t['sacute'] = 0x015B;
  12269. t['sacutedotaccent'] = 0x1E65;
  12270. t['sadarabic'] = 0x0635;
  12271. t['sadeva'] = 0x0938;
  12272. t['sadfinalarabic'] = 0xFEBA;
  12273. t['sadinitialarabic'] = 0xFEBB;
  12274. t['sadmedialarabic'] = 0xFEBC;
  12275. t['sagujarati'] = 0x0AB8;
  12276. t['sagurmukhi'] = 0x0A38;
  12277. t['sahiragana'] = 0x3055;
  12278. t['sakatakana'] = 0x30B5;
  12279. t['sakatakanahalfwidth'] = 0xFF7B;
  12280. t['sallallahoualayhewasallamarabic'] = 0xFDFA;
  12281. t['samekh'] = 0x05E1;
  12282. t['samekhdagesh'] = 0xFB41;
  12283. t['samekhdageshhebrew'] = 0xFB41;
  12284. t['samekhhebrew'] = 0x05E1;
  12285. t['saraaathai'] = 0x0E32;
  12286. t['saraaethai'] = 0x0E41;
  12287. t['saraaimaimalaithai'] = 0x0E44;
  12288. t['saraaimaimuanthai'] = 0x0E43;
  12289. t['saraamthai'] = 0x0E33;
  12290. t['saraathai'] = 0x0E30;
  12291. t['saraethai'] = 0x0E40;
  12292. t['saraiileftthai'] = 0xF886;
  12293. t['saraiithai'] = 0x0E35;
  12294. t['saraileftthai'] = 0xF885;
  12295. t['saraithai'] = 0x0E34;
  12296. t['saraothai'] = 0x0E42;
  12297. t['saraueeleftthai'] = 0xF888;
  12298. t['saraueethai'] = 0x0E37;
  12299. t['saraueleftthai'] = 0xF887;
  12300. t['sarauethai'] = 0x0E36;
  12301. t['sarauthai'] = 0x0E38;
  12302. t['sarauuthai'] = 0x0E39;
  12303. t['sbopomofo'] = 0x3119;
  12304. t['scaron'] = 0x0161;
  12305. t['scarondotaccent'] = 0x1E67;
  12306. t['scedilla'] = 0x015F;
  12307. t['schwa'] = 0x0259;
  12308. t['schwacyrillic'] = 0x04D9;
  12309. t['schwadieresiscyrillic'] = 0x04DB;
  12310. t['schwahook'] = 0x025A;
  12311. t['scircle'] = 0x24E2;
  12312. t['scircumflex'] = 0x015D;
  12313. t['scommaaccent'] = 0x0219;
  12314. t['sdotaccent'] = 0x1E61;
  12315. t['sdotbelow'] = 0x1E63;
  12316. t['sdotbelowdotaccent'] = 0x1E69;
  12317. t['seagullbelowcmb'] = 0x033C;
  12318. t['second'] = 0x2033;
  12319. t['secondtonechinese'] = 0x02CA;
  12320. t['section'] = 0x00A7;
  12321. t['seenarabic'] = 0x0633;
  12322. t['seenfinalarabic'] = 0xFEB2;
  12323. t['seeninitialarabic'] = 0xFEB3;
  12324. t['seenmedialarabic'] = 0xFEB4;
  12325. t['segol'] = 0x05B6;
  12326. t['segol13'] = 0x05B6;
  12327. t['segol1f'] = 0x05B6;
  12328. t['segol2c'] = 0x05B6;
  12329. t['segolhebrew'] = 0x05B6;
  12330. t['segolnarrowhebrew'] = 0x05B6;
  12331. t['segolquarterhebrew'] = 0x05B6;
  12332. t['segoltahebrew'] = 0x0592;
  12333. t['segolwidehebrew'] = 0x05B6;
  12334. t['seharmenian'] = 0x057D;
  12335. t['sehiragana'] = 0x305B;
  12336. t['sekatakana'] = 0x30BB;
  12337. t['sekatakanahalfwidth'] = 0xFF7E;
  12338. t['semicolon'] = 0x003B;
  12339. t['semicolonarabic'] = 0x061B;
  12340. t['semicolonmonospace'] = 0xFF1B;
  12341. t['semicolonsmall'] = 0xFE54;
  12342. t['semivoicedmarkkana'] = 0x309C;
  12343. t['semivoicedmarkkanahalfwidth'] = 0xFF9F;
  12344. t['sentisquare'] = 0x3322;
  12345. t['sentosquare'] = 0x3323;
  12346. t['seven'] = 0x0037;
  12347. t['sevenarabic'] = 0x0667;
  12348. t['sevenbengali'] = 0x09ED;
  12349. t['sevencircle'] = 0x2466;
  12350. t['sevencircleinversesansserif'] = 0x2790;
  12351. t['sevendeva'] = 0x096D;
  12352. t['seveneighths'] = 0x215E;
  12353. t['sevengujarati'] = 0x0AED;
  12354. t['sevengurmukhi'] = 0x0A6D;
  12355. t['sevenhackarabic'] = 0x0667;
  12356. t['sevenhangzhou'] = 0x3027;
  12357. t['sevenideographicparen'] = 0x3226;
  12358. t['seveninferior'] = 0x2087;
  12359. t['sevenmonospace'] = 0xFF17;
  12360. t['sevenoldstyle'] = 0xF737;
  12361. t['sevenparen'] = 0x247A;
  12362. t['sevenperiod'] = 0x248E;
  12363. t['sevenpersian'] = 0x06F7;
  12364. t['sevenroman'] = 0x2176;
  12365. t['sevensuperior'] = 0x2077;
  12366. t['seventeencircle'] = 0x2470;
  12367. t['seventeenparen'] = 0x2484;
  12368. t['seventeenperiod'] = 0x2498;
  12369. t['seventhai'] = 0x0E57;
  12370. t['sfthyphen'] = 0x00AD;
  12371. t['shaarmenian'] = 0x0577;
  12372. t['shabengali'] = 0x09B6;
  12373. t['shacyrillic'] = 0x0448;
  12374. t['shaddaarabic'] = 0x0651;
  12375. t['shaddadammaarabic'] = 0xFC61;
  12376. t['shaddadammatanarabic'] = 0xFC5E;
  12377. t['shaddafathaarabic'] = 0xFC60;
  12378. t['shaddakasraarabic'] = 0xFC62;
  12379. t['shaddakasratanarabic'] = 0xFC5F;
  12380. t['shade'] = 0x2592;
  12381. t['shadedark'] = 0x2593;
  12382. t['shadelight'] = 0x2591;
  12383. t['shademedium'] = 0x2592;
  12384. t['shadeva'] = 0x0936;
  12385. t['shagujarati'] = 0x0AB6;
  12386. t['shagurmukhi'] = 0x0A36;
  12387. t['shalshelethebrew'] = 0x0593;
  12388. t['shbopomofo'] = 0x3115;
  12389. t['shchacyrillic'] = 0x0449;
  12390. t['sheenarabic'] = 0x0634;
  12391. t['sheenfinalarabic'] = 0xFEB6;
  12392. t['sheeninitialarabic'] = 0xFEB7;
  12393. t['sheenmedialarabic'] = 0xFEB8;
  12394. t['sheicoptic'] = 0x03E3;
  12395. t['sheqel'] = 0x20AA;
  12396. t['sheqelhebrew'] = 0x20AA;
  12397. t['sheva'] = 0x05B0;
  12398. t['sheva115'] = 0x05B0;
  12399. t['sheva15'] = 0x05B0;
  12400. t['sheva22'] = 0x05B0;
  12401. t['sheva2e'] = 0x05B0;
  12402. t['shevahebrew'] = 0x05B0;
  12403. t['shevanarrowhebrew'] = 0x05B0;
  12404. t['shevaquarterhebrew'] = 0x05B0;
  12405. t['shevawidehebrew'] = 0x05B0;
  12406. t['shhacyrillic'] = 0x04BB;
  12407. t['shimacoptic'] = 0x03ED;
  12408. t['shin'] = 0x05E9;
  12409. t['shindagesh'] = 0xFB49;
  12410. t['shindageshhebrew'] = 0xFB49;
  12411. t['shindageshshindot'] = 0xFB2C;
  12412. t['shindageshshindothebrew'] = 0xFB2C;
  12413. t['shindageshsindot'] = 0xFB2D;
  12414. t['shindageshsindothebrew'] = 0xFB2D;
  12415. t['shindothebrew'] = 0x05C1;
  12416. t['shinhebrew'] = 0x05E9;
  12417. t['shinshindot'] = 0xFB2A;
  12418. t['shinshindothebrew'] = 0xFB2A;
  12419. t['shinsindot'] = 0xFB2B;
  12420. t['shinsindothebrew'] = 0xFB2B;
  12421. t['shook'] = 0x0282;
  12422. t['sigma'] = 0x03C3;
  12423. t['sigma1'] = 0x03C2;
  12424. t['sigmafinal'] = 0x03C2;
  12425. t['sigmalunatesymbolgreek'] = 0x03F2;
  12426. t['sihiragana'] = 0x3057;
  12427. t['sikatakana'] = 0x30B7;
  12428. t['sikatakanahalfwidth'] = 0xFF7C;
  12429. t['siluqhebrew'] = 0x05BD;
  12430. t['siluqlefthebrew'] = 0x05BD;
  12431. t['similar'] = 0x223C;
  12432. t['sindothebrew'] = 0x05C2;
  12433. t['siosacirclekorean'] = 0x3274;
  12434. t['siosaparenkorean'] = 0x3214;
  12435. t['sioscieuckorean'] = 0x317E;
  12436. t['sioscirclekorean'] = 0x3266;
  12437. t['sioskiyeokkorean'] = 0x317A;
  12438. t['sioskorean'] = 0x3145;
  12439. t['siosnieunkorean'] = 0x317B;
  12440. t['siosparenkorean'] = 0x3206;
  12441. t['siospieupkorean'] = 0x317D;
  12442. t['siostikeutkorean'] = 0x317C;
  12443. t['six'] = 0x0036;
  12444. t['sixarabic'] = 0x0666;
  12445. t['sixbengali'] = 0x09EC;
  12446. t['sixcircle'] = 0x2465;
  12447. t['sixcircleinversesansserif'] = 0x278F;
  12448. t['sixdeva'] = 0x096C;
  12449. t['sixgujarati'] = 0x0AEC;
  12450. t['sixgurmukhi'] = 0x0A6C;
  12451. t['sixhackarabic'] = 0x0666;
  12452. t['sixhangzhou'] = 0x3026;
  12453. t['sixideographicparen'] = 0x3225;
  12454. t['sixinferior'] = 0x2086;
  12455. t['sixmonospace'] = 0xFF16;
  12456. t['sixoldstyle'] = 0xF736;
  12457. t['sixparen'] = 0x2479;
  12458. t['sixperiod'] = 0x248D;
  12459. t['sixpersian'] = 0x06F6;
  12460. t['sixroman'] = 0x2175;
  12461. t['sixsuperior'] = 0x2076;
  12462. t['sixteencircle'] = 0x246F;
  12463. t['sixteencurrencydenominatorbengali'] = 0x09F9;
  12464. t['sixteenparen'] = 0x2483;
  12465. t['sixteenperiod'] = 0x2497;
  12466. t['sixthai'] = 0x0E56;
  12467. t['slash'] = 0x002F;
  12468. t['slashmonospace'] = 0xFF0F;
  12469. t['slong'] = 0x017F;
  12470. t['slongdotaccent'] = 0x1E9B;
  12471. t['smileface'] = 0x263A;
  12472. t['smonospace'] = 0xFF53;
  12473. t['sofpasuqhebrew'] = 0x05C3;
  12474. t['softhyphen'] = 0x00AD;
  12475. t['softsigncyrillic'] = 0x044C;
  12476. t['sohiragana'] = 0x305D;
  12477. t['sokatakana'] = 0x30BD;
  12478. t['sokatakanahalfwidth'] = 0xFF7F;
  12479. t['soliduslongoverlaycmb'] = 0x0338;
  12480. t['solidusshortoverlaycmb'] = 0x0337;
  12481. t['sorusithai'] = 0x0E29;
  12482. t['sosalathai'] = 0x0E28;
  12483. t['sosothai'] = 0x0E0B;
  12484. t['sosuathai'] = 0x0E2A;
  12485. t['space'] = 0x0020;
  12486. t['spacehackarabic'] = 0x0020;
  12487. t['spade'] = 0x2660;
  12488. t['spadesuitblack'] = 0x2660;
  12489. t['spadesuitwhite'] = 0x2664;
  12490. t['sparen'] = 0x24AE;
  12491. t['squarebelowcmb'] = 0x033B;
  12492. t['squarecc'] = 0x33C4;
  12493. t['squarecm'] = 0x339D;
  12494. t['squarediagonalcrosshatchfill'] = 0x25A9;
  12495. t['squarehorizontalfill'] = 0x25A4;
  12496. t['squarekg'] = 0x338F;
  12497. t['squarekm'] = 0x339E;
  12498. t['squarekmcapital'] = 0x33CE;
  12499. t['squareln'] = 0x33D1;
  12500. t['squarelog'] = 0x33D2;
  12501. t['squaremg'] = 0x338E;
  12502. t['squaremil'] = 0x33D5;
  12503. t['squaremm'] = 0x339C;
  12504. t['squaremsquared'] = 0x33A1;
  12505. t['squareorthogonalcrosshatchfill'] = 0x25A6;
  12506. t['squareupperlefttolowerrightfill'] = 0x25A7;
  12507. t['squareupperrighttolowerleftfill'] = 0x25A8;
  12508. t['squareverticalfill'] = 0x25A5;
  12509. t['squarewhitewithsmallblack'] = 0x25A3;
  12510. t['srsquare'] = 0x33DB;
  12511. t['ssabengali'] = 0x09B7;
  12512. t['ssadeva'] = 0x0937;
  12513. t['ssagujarati'] = 0x0AB7;
  12514. t['ssangcieuckorean'] = 0x3149;
  12515. t['ssanghieuhkorean'] = 0x3185;
  12516. t['ssangieungkorean'] = 0x3180;
  12517. t['ssangkiyeokkorean'] = 0x3132;
  12518. t['ssangnieunkorean'] = 0x3165;
  12519. t['ssangpieupkorean'] = 0x3143;
  12520. t['ssangsioskorean'] = 0x3146;
  12521. t['ssangtikeutkorean'] = 0x3138;
  12522. t['ssuperior'] = 0xF6F2;
  12523. t['sterling'] = 0x00A3;
  12524. t['sterlingmonospace'] = 0xFFE1;
  12525. t['strokelongoverlaycmb'] = 0x0336;
  12526. t['strokeshortoverlaycmb'] = 0x0335;
  12527. t['subset'] = 0x2282;
  12528. t['subsetnotequal'] = 0x228A;
  12529. t['subsetorequal'] = 0x2286;
  12530. t['succeeds'] = 0x227B;
  12531. t['suchthat'] = 0x220B;
  12532. t['suhiragana'] = 0x3059;
  12533. t['sukatakana'] = 0x30B9;
  12534. t['sukatakanahalfwidth'] = 0xFF7D;
  12535. t['sukunarabic'] = 0x0652;
  12536. t['summation'] = 0x2211;
  12537. t['sun'] = 0x263C;
  12538. t['superset'] = 0x2283;
  12539. t['supersetnotequal'] = 0x228B;
  12540. t['supersetorequal'] = 0x2287;
  12541. t['svsquare'] = 0x33DC;
  12542. t['syouwaerasquare'] = 0x337C;
  12543. t['t'] = 0x0074;
  12544. t['tabengali'] = 0x09A4;
  12545. t['tackdown'] = 0x22A4;
  12546. t['tackleft'] = 0x22A3;
  12547. t['tadeva'] = 0x0924;
  12548. t['tagujarati'] = 0x0AA4;
  12549. t['tagurmukhi'] = 0x0A24;
  12550. t['taharabic'] = 0x0637;
  12551. t['tahfinalarabic'] = 0xFEC2;
  12552. t['tahinitialarabic'] = 0xFEC3;
  12553. t['tahiragana'] = 0x305F;
  12554. t['tahmedialarabic'] = 0xFEC4;
  12555. t['taisyouerasquare'] = 0x337D;
  12556. t['takatakana'] = 0x30BF;
  12557. t['takatakanahalfwidth'] = 0xFF80;
  12558. t['tatweelarabic'] = 0x0640;
  12559. t['tau'] = 0x03C4;
  12560. t['tav'] = 0x05EA;
  12561. t['tavdages'] = 0xFB4A;
  12562. t['tavdagesh'] = 0xFB4A;
  12563. t['tavdageshhebrew'] = 0xFB4A;
  12564. t['tavhebrew'] = 0x05EA;
  12565. t['tbar'] = 0x0167;
  12566. t['tbopomofo'] = 0x310A;
  12567. t['tcaron'] = 0x0165;
  12568. t['tccurl'] = 0x02A8;
  12569. t['tcedilla'] = 0x0163;
  12570. t['tcheharabic'] = 0x0686;
  12571. t['tchehfinalarabic'] = 0xFB7B;
  12572. t['tchehinitialarabic'] = 0xFB7C;
  12573. t['tchehmedialarabic'] = 0xFB7D;
  12574. t['tcircle'] = 0x24E3;
  12575. t['tcircumflexbelow'] = 0x1E71;
  12576. t['tcommaaccent'] = 0x0163;
  12577. t['tdieresis'] = 0x1E97;
  12578. t['tdotaccent'] = 0x1E6B;
  12579. t['tdotbelow'] = 0x1E6D;
  12580. t['tecyrillic'] = 0x0442;
  12581. t['tedescendercyrillic'] = 0x04AD;
  12582. t['teharabic'] = 0x062A;
  12583. t['tehfinalarabic'] = 0xFE96;
  12584. t['tehhahinitialarabic'] = 0xFCA2;
  12585. t['tehhahisolatedarabic'] = 0xFC0C;
  12586. t['tehinitialarabic'] = 0xFE97;
  12587. t['tehiragana'] = 0x3066;
  12588. t['tehjeeminitialarabic'] = 0xFCA1;
  12589. t['tehjeemisolatedarabic'] = 0xFC0B;
  12590. t['tehmarbutaarabic'] = 0x0629;
  12591. t['tehmarbutafinalarabic'] = 0xFE94;
  12592. t['tehmedialarabic'] = 0xFE98;
  12593. t['tehmeeminitialarabic'] = 0xFCA4;
  12594. t['tehmeemisolatedarabic'] = 0xFC0E;
  12595. t['tehnoonfinalarabic'] = 0xFC73;
  12596. t['tekatakana'] = 0x30C6;
  12597. t['tekatakanahalfwidth'] = 0xFF83;
  12598. t['telephone'] = 0x2121;
  12599. t['telephoneblack'] = 0x260E;
  12600. t['telishagedolahebrew'] = 0x05A0;
  12601. t['telishaqetanahebrew'] = 0x05A9;
  12602. t['tencircle'] = 0x2469;
  12603. t['tenideographicparen'] = 0x3229;
  12604. t['tenparen'] = 0x247D;
  12605. t['tenperiod'] = 0x2491;
  12606. t['tenroman'] = 0x2179;
  12607. t['tesh'] = 0x02A7;
  12608. t['tet'] = 0x05D8;
  12609. t['tetdagesh'] = 0xFB38;
  12610. t['tetdageshhebrew'] = 0xFB38;
  12611. t['tethebrew'] = 0x05D8;
  12612. t['tetsecyrillic'] = 0x04B5;
  12613. t['tevirhebrew'] = 0x059B;
  12614. t['tevirlefthebrew'] = 0x059B;
  12615. t['thabengali'] = 0x09A5;
  12616. t['thadeva'] = 0x0925;
  12617. t['thagujarati'] = 0x0AA5;
  12618. t['thagurmukhi'] = 0x0A25;
  12619. t['thalarabic'] = 0x0630;
  12620. t['thalfinalarabic'] = 0xFEAC;
  12621. t['thanthakhatlowleftthai'] = 0xF898;
  12622. t['thanthakhatlowrightthai'] = 0xF897;
  12623. t['thanthakhatthai'] = 0x0E4C;
  12624. t['thanthakhatupperleftthai'] = 0xF896;
  12625. t['theharabic'] = 0x062B;
  12626. t['thehfinalarabic'] = 0xFE9A;
  12627. t['thehinitialarabic'] = 0xFE9B;
  12628. t['thehmedialarabic'] = 0xFE9C;
  12629. t['thereexists'] = 0x2203;
  12630. t['therefore'] = 0x2234;
  12631. t['theta'] = 0x03B8;
  12632. t['theta1'] = 0x03D1;
  12633. t['thetasymbolgreek'] = 0x03D1;
  12634. t['thieuthacirclekorean'] = 0x3279;
  12635. t['thieuthaparenkorean'] = 0x3219;
  12636. t['thieuthcirclekorean'] = 0x326B;
  12637. t['thieuthkorean'] = 0x314C;
  12638. t['thieuthparenkorean'] = 0x320B;
  12639. t['thirteencircle'] = 0x246C;
  12640. t['thirteenparen'] = 0x2480;
  12641. t['thirteenperiod'] = 0x2494;
  12642. t['thonangmonthothai'] = 0x0E11;
  12643. t['thook'] = 0x01AD;
  12644. t['thophuthaothai'] = 0x0E12;
  12645. t['thorn'] = 0x00FE;
  12646. t['thothahanthai'] = 0x0E17;
  12647. t['thothanthai'] = 0x0E10;
  12648. t['thothongthai'] = 0x0E18;
  12649. t['thothungthai'] = 0x0E16;
  12650. t['thousandcyrillic'] = 0x0482;
  12651. t['thousandsseparatorarabic'] = 0x066C;
  12652. t['thousandsseparatorpersian'] = 0x066C;
  12653. t['three'] = 0x0033;
  12654. t['threearabic'] = 0x0663;
  12655. t['threebengali'] = 0x09E9;
  12656. t['threecircle'] = 0x2462;
  12657. t['threecircleinversesansserif'] = 0x278C;
  12658. t['threedeva'] = 0x0969;
  12659. t['threeeighths'] = 0x215C;
  12660. t['threegujarati'] = 0x0AE9;
  12661. t['threegurmukhi'] = 0x0A69;
  12662. t['threehackarabic'] = 0x0663;
  12663. t['threehangzhou'] = 0x3023;
  12664. t['threeideographicparen'] = 0x3222;
  12665. t['threeinferior'] = 0x2083;
  12666. t['threemonospace'] = 0xFF13;
  12667. t['threenumeratorbengali'] = 0x09F6;
  12668. t['threeoldstyle'] = 0xF733;
  12669. t['threeparen'] = 0x2476;
  12670. t['threeperiod'] = 0x248A;
  12671. t['threepersian'] = 0x06F3;
  12672. t['threequarters'] = 0x00BE;
  12673. t['threequartersemdash'] = 0xF6DE;
  12674. t['threeroman'] = 0x2172;
  12675. t['threesuperior'] = 0x00B3;
  12676. t['threethai'] = 0x0E53;
  12677. t['thzsquare'] = 0x3394;
  12678. t['tihiragana'] = 0x3061;
  12679. t['tikatakana'] = 0x30C1;
  12680. t['tikatakanahalfwidth'] = 0xFF81;
  12681. t['tikeutacirclekorean'] = 0x3270;
  12682. t['tikeutaparenkorean'] = 0x3210;
  12683. t['tikeutcirclekorean'] = 0x3262;
  12684. t['tikeutkorean'] = 0x3137;
  12685. t['tikeutparenkorean'] = 0x3202;
  12686. t['tilde'] = 0x02DC;
  12687. t['tildebelowcmb'] = 0x0330;
  12688. t['tildecmb'] = 0x0303;
  12689. t['tildecomb'] = 0x0303;
  12690. t['tildedoublecmb'] = 0x0360;
  12691. t['tildeoperator'] = 0x223C;
  12692. t['tildeoverlaycmb'] = 0x0334;
  12693. t['tildeverticalcmb'] = 0x033E;
  12694. t['timescircle'] = 0x2297;
  12695. t['tipehahebrew'] = 0x0596;
  12696. t['tipehalefthebrew'] = 0x0596;
  12697. t['tippigurmukhi'] = 0x0A70;
  12698. t['titlocyrilliccmb'] = 0x0483;
  12699. t['tiwnarmenian'] = 0x057F;
  12700. t['tlinebelow'] = 0x1E6F;
  12701. t['tmonospace'] = 0xFF54;
  12702. t['toarmenian'] = 0x0569;
  12703. t['tohiragana'] = 0x3068;
  12704. t['tokatakana'] = 0x30C8;
  12705. t['tokatakanahalfwidth'] = 0xFF84;
  12706. t['tonebarextrahighmod'] = 0x02E5;
  12707. t['tonebarextralowmod'] = 0x02E9;
  12708. t['tonebarhighmod'] = 0x02E6;
  12709. t['tonebarlowmod'] = 0x02E8;
  12710. t['tonebarmidmod'] = 0x02E7;
  12711. t['tonefive'] = 0x01BD;
  12712. t['tonesix'] = 0x0185;
  12713. t['tonetwo'] = 0x01A8;
  12714. t['tonos'] = 0x0384;
  12715. t['tonsquare'] = 0x3327;
  12716. t['topatakthai'] = 0x0E0F;
  12717. t['tortoiseshellbracketleft'] = 0x3014;
  12718. t['tortoiseshellbracketleftsmall'] = 0xFE5D;
  12719. t['tortoiseshellbracketleftvertical'] = 0xFE39;
  12720. t['tortoiseshellbracketright'] = 0x3015;
  12721. t['tortoiseshellbracketrightsmall'] = 0xFE5E;
  12722. t['tortoiseshellbracketrightvertical'] = 0xFE3A;
  12723. t['totaothai'] = 0x0E15;
  12724. t['tpalatalhook'] = 0x01AB;
  12725. t['tparen'] = 0x24AF;
  12726. t['trademark'] = 0x2122;
  12727. t['trademarksans'] = 0xF8EA;
  12728. t['trademarkserif'] = 0xF6DB;
  12729. t['tretroflexhook'] = 0x0288;
  12730. t['triagdn'] = 0x25BC;
  12731. t['triaglf'] = 0x25C4;
  12732. t['triagrt'] = 0x25BA;
  12733. t['triagup'] = 0x25B2;
  12734. t['ts'] = 0x02A6;
  12735. t['tsadi'] = 0x05E6;
  12736. t['tsadidagesh'] = 0xFB46;
  12737. t['tsadidageshhebrew'] = 0xFB46;
  12738. t['tsadihebrew'] = 0x05E6;
  12739. t['tsecyrillic'] = 0x0446;
  12740. t['tsere'] = 0x05B5;
  12741. t['tsere12'] = 0x05B5;
  12742. t['tsere1e'] = 0x05B5;
  12743. t['tsere2b'] = 0x05B5;
  12744. t['tserehebrew'] = 0x05B5;
  12745. t['tserenarrowhebrew'] = 0x05B5;
  12746. t['tserequarterhebrew'] = 0x05B5;
  12747. t['tserewidehebrew'] = 0x05B5;
  12748. t['tshecyrillic'] = 0x045B;
  12749. t['tsuperior'] = 0xF6F3;
  12750. t['ttabengali'] = 0x099F;
  12751. t['ttadeva'] = 0x091F;
  12752. t['ttagujarati'] = 0x0A9F;
  12753. t['ttagurmukhi'] = 0x0A1F;
  12754. t['tteharabic'] = 0x0679;
  12755. t['ttehfinalarabic'] = 0xFB67;
  12756. t['ttehinitialarabic'] = 0xFB68;
  12757. t['ttehmedialarabic'] = 0xFB69;
  12758. t['tthabengali'] = 0x09A0;
  12759. t['tthadeva'] = 0x0920;
  12760. t['tthagujarati'] = 0x0AA0;
  12761. t['tthagurmukhi'] = 0x0A20;
  12762. t['tturned'] = 0x0287;
  12763. t['tuhiragana'] = 0x3064;
  12764. t['tukatakana'] = 0x30C4;
  12765. t['tukatakanahalfwidth'] = 0xFF82;
  12766. t['tusmallhiragana'] = 0x3063;
  12767. t['tusmallkatakana'] = 0x30C3;
  12768. t['tusmallkatakanahalfwidth'] = 0xFF6F;
  12769. t['twelvecircle'] = 0x246B;
  12770. t['twelveparen'] = 0x247F;
  12771. t['twelveperiod'] = 0x2493;
  12772. t['twelveroman'] = 0x217B;
  12773. t['twentycircle'] = 0x2473;
  12774. t['twentyhangzhou'] = 0x5344;
  12775. t['twentyparen'] = 0x2487;
  12776. t['twentyperiod'] = 0x249B;
  12777. t['two'] = 0x0032;
  12778. t['twoarabic'] = 0x0662;
  12779. t['twobengali'] = 0x09E8;
  12780. t['twocircle'] = 0x2461;
  12781. t['twocircleinversesansserif'] = 0x278B;
  12782. t['twodeva'] = 0x0968;
  12783. t['twodotenleader'] = 0x2025;
  12784. t['twodotleader'] = 0x2025;
  12785. t['twodotleadervertical'] = 0xFE30;
  12786. t['twogujarati'] = 0x0AE8;
  12787. t['twogurmukhi'] = 0x0A68;
  12788. t['twohackarabic'] = 0x0662;
  12789. t['twohangzhou'] = 0x3022;
  12790. t['twoideographicparen'] = 0x3221;
  12791. t['twoinferior'] = 0x2082;
  12792. t['twomonospace'] = 0xFF12;
  12793. t['twonumeratorbengali'] = 0x09F5;
  12794. t['twooldstyle'] = 0xF732;
  12795. t['twoparen'] = 0x2475;
  12796. t['twoperiod'] = 0x2489;
  12797. t['twopersian'] = 0x06F2;
  12798. t['tworoman'] = 0x2171;
  12799. t['twostroke'] = 0x01BB;
  12800. t['twosuperior'] = 0x00B2;
  12801. t['twothai'] = 0x0E52;
  12802. t['twothirds'] = 0x2154;
  12803. t['u'] = 0x0075;
  12804. t['uacute'] = 0x00FA;
  12805. t['ubar'] = 0x0289;
  12806. t['ubengali'] = 0x0989;
  12807. t['ubopomofo'] = 0x3128;
  12808. t['ubreve'] = 0x016D;
  12809. t['ucaron'] = 0x01D4;
  12810. t['ucircle'] = 0x24E4;
  12811. t['ucircumflex'] = 0x00FB;
  12812. t['ucircumflexbelow'] = 0x1E77;
  12813. t['ucyrillic'] = 0x0443;
  12814. t['udattadeva'] = 0x0951;
  12815. t['udblacute'] = 0x0171;
  12816. t['udblgrave'] = 0x0215;
  12817. t['udeva'] = 0x0909;
  12818. t['udieresis'] = 0x00FC;
  12819. t['udieresisacute'] = 0x01D8;
  12820. t['udieresisbelow'] = 0x1E73;
  12821. t['udieresiscaron'] = 0x01DA;
  12822. t['udieresiscyrillic'] = 0x04F1;
  12823. t['udieresisgrave'] = 0x01DC;
  12824. t['udieresismacron'] = 0x01D6;
  12825. t['udotbelow'] = 0x1EE5;
  12826. t['ugrave'] = 0x00F9;
  12827. t['ugujarati'] = 0x0A89;
  12828. t['ugurmukhi'] = 0x0A09;
  12829. t['uhiragana'] = 0x3046;
  12830. t['uhookabove'] = 0x1EE7;
  12831. t['uhorn'] = 0x01B0;
  12832. t['uhornacute'] = 0x1EE9;
  12833. t['uhorndotbelow'] = 0x1EF1;
  12834. t['uhorngrave'] = 0x1EEB;
  12835. t['uhornhookabove'] = 0x1EED;
  12836. t['uhorntilde'] = 0x1EEF;
  12837. t['uhungarumlaut'] = 0x0171;
  12838. t['uhungarumlautcyrillic'] = 0x04F3;
  12839. t['uinvertedbreve'] = 0x0217;
  12840. t['ukatakana'] = 0x30A6;
  12841. t['ukatakanahalfwidth'] = 0xFF73;
  12842. t['ukcyrillic'] = 0x0479;
  12843. t['ukorean'] = 0x315C;
  12844. t['umacron'] = 0x016B;
  12845. t['umacroncyrillic'] = 0x04EF;
  12846. t['umacrondieresis'] = 0x1E7B;
  12847. t['umatragurmukhi'] = 0x0A41;
  12848. t['umonospace'] = 0xFF55;
  12849. t['underscore'] = 0x005F;
  12850. t['underscoredbl'] = 0x2017;
  12851. t['underscoremonospace'] = 0xFF3F;
  12852. t['underscorevertical'] = 0xFE33;
  12853. t['underscorewavy'] = 0xFE4F;
  12854. t['union'] = 0x222A;
  12855. t['universal'] = 0x2200;
  12856. t['uogonek'] = 0x0173;
  12857. t['uparen'] = 0x24B0;
  12858. t['upblock'] = 0x2580;
  12859. t['upperdothebrew'] = 0x05C4;
  12860. t['upsilon'] = 0x03C5;
  12861. t['upsilondieresis'] = 0x03CB;
  12862. t['upsilondieresistonos'] = 0x03B0;
  12863. t['upsilonlatin'] = 0x028A;
  12864. t['upsilontonos'] = 0x03CD;
  12865. t['uptackbelowcmb'] = 0x031D;
  12866. t['uptackmod'] = 0x02D4;
  12867. t['uragurmukhi'] = 0x0A73;
  12868. t['uring'] = 0x016F;
  12869. t['ushortcyrillic'] = 0x045E;
  12870. t['usmallhiragana'] = 0x3045;
  12871. t['usmallkatakana'] = 0x30A5;
  12872. t['usmallkatakanahalfwidth'] = 0xFF69;
  12873. t['ustraightcyrillic'] = 0x04AF;
  12874. t['ustraightstrokecyrillic'] = 0x04B1;
  12875. t['utilde'] = 0x0169;
  12876. t['utildeacute'] = 0x1E79;
  12877. t['utildebelow'] = 0x1E75;
  12878. t['uubengali'] = 0x098A;
  12879. t['uudeva'] = 0x090A;
  12880. t['uugujarati'] = 0x0A8A;
  12881. t['uugurmukhi'] = 0x0A0A;
  12882. t['uumatragurmukhi'] = 0x0A42;
  12883. t['uuvowelsignbengali'] = 0x09C2;
  12884. t['uuvowelsigndeva'] = 0x0942;
  12885. t['uuvowelsigngujarati'] = 0x0AC2;
  12886. t['uvowelsignbengali'] = 0x09C1;
  12887. t['uvowelsigndeva'] = 0x0941;
  12888. t['uvowelsigngujarati'] = 0x0AC1;
  12889. t['v'] = 0x0076;
  12890. t['vadeva'] = 0x0935;
  12891. t['vagujarati'] = 0x0AB5;
  12892. t['vagurmukhi'] = 0x0A35;
  12893. t['vakatakana'] = 0x30F7;
  12894. t['vav'] = 0x05D5;
  12895. t['vavdagesh'] = 0xFB35;
  12896. t['vavdagesh65'] = 0xFB35;
  12897. t['vavdageshhebrew'] = 0xFB35;
  12898. t['vavhebrew'] = 0x05D5;
  12899. t['vavholam'] = 0xFB4B;
  12900. t['vavholamhebrew'] = 0xFB4B;
  12901. t['vavvavhebrew'] = 0x05F0;
  12902. t['vavyodhebrew'] = 0x05F1;
  12903. t['vcircle'] = 0x24E5;
  12904. t['vdotbelow'] = 0x1E7F;
  12905. t['vecyrillic'] = 0x0432;
  12906. t['veharabic'] = 0x06A4;
  12907. t['vehfinalarabic'] = 0xFB6B;
  12908. t['vehinitialarabic'] = 0xFB6C;
  12909. t['vehmedialarabic'] = 0xFB6D;
  12910. t['vekatakana'] = 0x30F9;
  12911. t['venus'] = 0x2640;
  12912. t['verticalbar'] = 0x007C;
  12913. t['verticallineabovecmb'] = 0x030D;
  12914. t['verticallinebelowcmb'] = 0x0329;
  12915. t['verticallinelowmod'] = 0x02CC;
  12916. t['verticallinemod'] = 0x02C8;
  12917. t['vewarmenian'] = 0x057E;
  12918. t['vhook'] = 0x028B;
  12919. t['vikatakana'] = 0x30F8;
  12920. t['viramabengali'] = 0x09CD;
  12921. t['viramadeva'] = 0x094D;
  12922. t['viramagujarati'] = 0x0ACD;
  12923. t['visargabengali'] = 0x0983;
  12924. t['visargadeva'] = 0x0903;
  12925. t['visargagujarati'] = 0x0A83;
  12926. t['vmonospace'] = 0xFF56;
  12927. t['voarmenian'] = 0x0578;
  12928. t['voicediterationhiragana'] = 0x309E;
  12929. t['voicediterationkatakana'] = 0x30FE;
  12930. t['voicedmarkkana'] = 0x309B;
  12931. t['voicedmarkkanahalfwidth'] = 0xFF9E;
  12932. t['vokatakana'] = 0x30FA;
  12933. t['vparen'] = 0x24B1;
  12934. t['vtilde'] = 0x1E7D;
  12935. t['vturned'] = 0x028C;
  12936. t['vuhiragana'] = 0x3094;
  12937. t['vukatakana'] = 0x30F4;
  12938. t['w'] = 0x0077;
  12939. t['wacute'] = 0x1E83;
  12940. t['waekorean'] = 0x3159;
  12941. t['wahiragana'] = 0x308F;
  12942. t['wakatakana'] = 0x30EF;
  12943. t['wakatakanahalfwidth'] = 0xFF9C;
  12944. t['wakorean'] = 0x3158;
  12945. t['wasmallhiragana'] = 0x308E;
  12946. t['wasmallkatakana'] = 0x30EE;
  12947. t['wattosquare'] = 0x3357;
  12948. t['wavedash'] = 0x301C;
  12949. t['wavyunderscorevertical'] = 0xFE34;
  12950. t['wawarabic'] = 0x0648;
  12951. t['wawfinalarabic'] = 0xFEEE;
  12952. t['wawhamzaabovearabic'] = 0x0624;
  12953. t['wawhamzaabovefinalarabic'] = 0xFE86;
  12954. t['wbsquare'] = 0x33DD;
  12955. t['wcircle'] = 0x24E6;
  12956. t['wcircumflex'] = 0x0175;
  12957. t['wdieresis'] = 0x1E85;
  12958. t['wdotaccent'] = 0x1E87;
  12959. t['wdotbelow'] = 0x1E89;
  12960. t['wehiragana'] = 0x3091;
  12961. t['weierstrass'] = 0x2118;
  12962. t['wekatakana'] = 0x30F1;
  12963. t['wekorean'] = 0x315E;
  12964. t['weokorean'] = 0x315D;
  12965. t['wgrave'] = 0x1E81;
  12966. t['whitebullet'] = 0x25E6;
  12967. t['whitecircle'] = 0x25CB;
  12968. t['whitecircleinverse'] = 0x25D9;
  12969. t['whitecornerbracketleft'] = 0x300E;
  12970. t['whitecornerbracketleftvertical'] = 0xFE43;
  12971. t['whitecornerbracketright'] = 0x300F;
  12972. t['whitecornerbracketrightvertical'] = 0xFE44;
  12973. t['whitediamond'] = 0x25C7;
  12974. t['whitediamondcontainingblacksmalldiamond'] = 0x25C8;
  12975. t['whitedownpointingsmalltriangle'] = 0x25BF;
  12976. t['whitedownpointingtriangle'] = 0x25BD;
  12977. t['whiteleftpointingsmalltriangle'] = 0x25C3;
  12978. t['whiteleftpointingtriangle'] = 0x25C1;
  12979. t['whitelenticularbracketleft'] = 0x3016;
  12980. t['whitelenticularbracketright'] = 0x3017;
  12981. t['whiterightpointingsmalltriangle'] = 0x25B9;
  12982. t['whiterightpointingtriangle'] = 0x25B7;
  12983. t['whitesmallsquare'] = 0x25AB;
  12984. t['whitesmilingface'] = 0x263A;
  12985. t['whitesquare'] = 0x25A1;
  12986. t['whitestar'] = 0x2606;
  12987. t['whitetelephone'] = 0x260F;
  12988. t['whitetortoiseshellbracketleft'] = 0x3018;
  12989. t['whitetortoiseshellbracketright'] = 0x3019;
  12990. t['whiteuppointingsmalltriangle'] = 0x25B5;
  12991. t['whiteuppointingtriangle'] = 0x25B3;
  12992. t['wihiragana'] = 0x3090;
  12993. t['wikatakana'] = 0x30F0;
  12994. t['wikorean'] = 0x315F;
  12995. t['wmonospace'] = 0xFF57;
  12996. t['wohiragana'] = 0x3092;
  12997. t['wokatakana'] = 0x30F2;
  12998. t['wokatakanahalfwidth'] = 0xFF66;
  12999. t['won'] = 0x20A9;
  13000. t['wonmonospace'] = 0xFFE6;
  13001. t['wowaenthai'] = 0x0E27;
  13002. t['wparen'] = 0x24B2;
  13003. t['wring'] = 0x1E98;
  13004. t['wsuperior'] = 0x02B7;
  13005. t['wturned'] = 0x028D;
  13006. t['wynn'] = 0x01BF;
  13007. t['x'] = 0x0078;
  13008. t['xabovecmb'] = 0x033D;
  13009. t['xbopomofo'] = 0x3112;
  13010. t['xcircle'] = 0x24E7;
  13011. t['xdieresis'] = 0x1E8D;
  13012. t['xdotaccent'] = 0x1E8B;
  13013. t['xeharmenian'] = 0x056D;
  13014. t['xi'] = 0x03BE;
  13015. t['xmonospace'] = 0xFF58;
  13016. t['xparen'] = 0x24B3;
  13017. t['xsuperior'] = 0x02E3;
  13018. t['y'] = 0x0079;
  13019. t['yaadosquare'] = 0x334E;
  13020. t['yabengali'] = 0x09AF;
  13021. t['yacute'] = 0x00FD;
  13022. t['yadeva'] = 0x092F;
  13023. t['yaekorean'] = 0x3152;
  13024. t['yagujarati'] = 0x0AAF;
  13025. t['yagurmukhi'] = 0x0A2F;
  13026. t['yahiragana'] = 0x3084;
  13027. t['yakatakana'] = 0x30E4;
  13028. t['yakatakanahalfwidth'] = 0xFF94;
  13029. t['yakorean'] = 0x3151;
  13030. t['yamakkanthai'] = 0x0E4E;
  13031. t['yasmallhiragana'] = 0x3083;
  13032. t['yasmallkatakana'] = 0x30E3;
  13033. t['yasmallkatakanahalfwidth'] = 0xFF6C;
  13034. t['yatcyrillic'] = 0x0463;
  13035. t['ycircle'] = 0x24E8;
  13036. t['ycircumflex'] = 0x0177;
  13037. t['ydieresis'] = 0x00FF;
  13038. t['ydotaccent'] = 0x1E8F;
  13039. t['ydotbelow'] = 0x1EF5;
  13040. t['yeharabic'] = 0x064A;
  13041. t['yehbarreearabic'] = 0x06D2;
  13042. t['yehbarreefinalarabic'] = 0xFBAF;
  13043. t['yehfinalarabic'] = 0xFEF2;
  13044. t['yehhamzaabovearabic'] = 0x0626;
  13045. t['yehhamzaabovefinalarabic'] = 0xFE8A;
  13046. t['yehhamzaaboveinitialarabic'] = 0xFE8B;
  13047. t['yehhamzaabovemedialarabic'] = 0xFE8C;
  13048. t['yehinitialarabic'] = 0xFEF3;
  13049. t['yehmedialarabic'] = 0xFEF4;
  13050. t['yehmeeminitialarabic'] = 0xFCDD;
  13051. t['yehmeemisolatedarabic'] = 0xFC58;
  13052. t['yehnoonfinalarabic'] = 0xFC94;
  13053. t['yehthreedotsbelowarabic'] = 0x06D1;
  13054. t['yekorean'] = 0x3156;
  13055. t['yen'] = 0x00A5;
  13056. t['yenmonospace'] = 0xFFE5;
  13057. t['yeokorean'] = 0x3155;
  13058. t['yeorinhieuhkorean'] = 0x3186;
  13059. t['yerahbenyomohebrew'] = 0x05AA;
  13060. t['yerahbenyomolefthebrew'] = 0x05AA;
  13061. t['yericyrillic'] = 0x044B;
  13062. t['yerudieresiscyrillic'] = 0x04F9;
  13063. t['yesieungkorean'] = 0x3181;
  13064. t['yesieungpansioskorean'] = 0x3183;
  13065. t['yesieungsioskorean'] = 0x3182;
  13066. t['yetivhebrew'] = 0x059A;
  13067. t['ygrave'] = 0x1EF3;
  13068. t['yhook'] = 0x01B4;
  13069. t['yhookabove'] = 0x1EF7;
  13070. t['yiarmenian'] = 0x0575;
  13071. t['yicyrillic'] = 0x0457;
  13072. t['yikorean'] = 0x3162;
  13073. t['yinyang'] = 0x262F;
  13074. t['yiwnarmenian'] = 0x0582;
  13075. t['ymonospace'] = 0xFF59;
  13076. t['yod'] = 0x05D9;
  13077. t['yoddagesh'] = 0xFB39;
  13078. t['yoddageshhebrew'] = 0xFB39;
  13079. t['yodhebrew'] = 0x05D9;
  13080. t['yodyodhebrew'] = 0x05F2;
  13081. t['yodyodpatahhebrew'] = 0xFB1F;
  13082. t['yohiragana'] = 0x3088;
  13083. t['yoikorean'] = 0x3189;
  13084. t['yokatakana'] = 0x30E8;
  13085. t['yokatakanahalfwidth'] = 0xFF96;
  13086. t['yokorean'] = 0x315B;
  13087. t['yosmallhiragana'] = 0x3087;
  13088. t['yosmallkatakana'] = 0x30E7;
  13089. t['yosmallkatakanahalfwidth'] = 0xFF6E;
  13090. t['yotgreek'] = 0x03F3;
  13091. t['yoyaekorean'] = 0x3188;
  13092. t['yoyakorean'] = 0x3187;
  13093. t['yoyakthai'] = 0x0E22;
  13094. t['yoyingthai'] = 0x0E0D;
  13095. t['yparen'] = 0x24B4;
  13096. t['ypogegrammeni'] = 0x037A;
  13097. t['ypogegrammenigreekcmb'] = 0x0345;
  13098. t['yr'] = 0x01A6;
  13099. t['yring'] = 0x1E99;
  13100. t['ysuperior'] = 0x02B8;
  13101. t['ytilde'] = 0x1EF9;
  13102. t['yturned'] = 0x028E;
  13103. t['yuhiragana'] = 0x3086;
  13104. t['yuikorean'] = 0x318C;
  13105. t['yukatakana'] = 0x30E6;
  13106. t['yukatakanahalfwidth'] = 0xFF95;
  13107. t['yukorean'] = 0x3160;
  13108. t['yusbigcyrillic'] = 0x046B;
  13109. t['yusbigiotifiedcyrillic'] = 0x046D;
  13110. t['yuslittlecyrillic'] = 0x0467;
  13111. t['yuslittleiotifiedcyrillic'] = 0x0469;
  13112. t['yusmallhiragana'] = 0x3085;
  13113. t['yusmallkatakana'] = 0x30E5;
  13114. t['yusmallkatakanahalfwidth'] = 0xFF6D;
  13115. t['yuyekorean'] = 0x318B;
  13116. t['yuyeokorean'] = 0x318A;
  13117. t['yyabengali'] = 0x09DF;
  13118. t['yyadeva'] = 0x095F;
  13119. t['z'] = 0x007A;
  13120. t['zaarmenian'] = 0x0566;
  13121. t['zacute'] = 0x017A;
  13122. t['zadeva'] = 0x095B;
  13123. t['zagurmukhi'] = 0x0A5B;
  13124. t['zaharabic'] = 0x0638;
  13125. t['zahfinalarabic'] = 0xFEC6;
  13126. t['zahinitialarabic'] = 0xFEC7;
  13127. t['zahiragana'] = 0x3056;
  13128. t['zahmedialarabic'] = 0xFEC8;
  13129. t['zainarabic'] = 0x0632;
  13130. t['zainfinalarabic'] = 0xFEB0;
  13131. t['zakatakana'] = 0x30B6;
  13132. t['zaqefgadolhebrew'] = 0x0595;
  13133. t['zaqefqatanhebrew'] = 0x0594;
  13134. t['zarqahebrew'] = 0x0598;
  13135. t['zayin'] = 0x05D6;
  13136. t['zayindagesh'] = 0xFB36;
  13137. t['zayindageshhebrew'] = 0xFB36;
  13138. t['zayinhebrew'] = 0x05D6;
  13139. t['zbopomofo'] = 0x3117;
  13140. t['zcaron'] = 0x017E;
  13141. t['zcircle'] = 0x24E9;
  13142. t['zcircumflex'] = 0x1E91;
  13143. t['zcurl'] = 0x0291;
  13144. t['zdot'] = 0x017C;
  13145. t['zdotaccent'] = 0x017C;
  13146. t['zdotbelow'] = 0x1E93;
  13147. t['zecyrillic'] = 0x0437;
  13148. t['zedescendercyrillic'] = 0x0499;
  13149. t['zedieresiscyrillic'] = 0x04DF;
  13150. t['zehiragana'] = 0x305C;
  13151. t['zekatakana'] = 0x30BC;
  13152. t['zero'] = 0x0030;
  13153. t['zeroarabic'] = 0x0660;
  13154. t['zerobengali'] = 0x09E6;
  13155. t['zerodeva'] = 0x0966;
  13156. t['zerogujarati'] = 0x0AE6;
  13157. t['zerogurmukhi'] = 0x0A66;
  13158. t['zerohackarabic'] = 0x0660;
  13159. t['zeroinferior'] = 0x2080;
  13160. t['zeromonospace'] = 0xFF10;
  13161. t['zerooldstyle'] = 0xF730;
  13162. t['zeropersian'] = 0x06F0;
  13163. t['zerosuperior'] = 0x2070;
  13164. t['zerothai'] = 0x0E50;
  13165. t['zerowidthjoiner'] = 0xFEFF;
  13166. t['zerowidthnonjoiner'] = 0x200C;
  13167. t['zerowidthspace'] = 0x200B;
  13168. t['zeta'] = 0x03B6;
  13169. t['zhbopomofo'] = 0x3113;
  13170. t['zhearmenian'] = 0x056A;
  13171. t['zhebrevecyrillic'] = 0x04C2;
  13172. t['zhecyrillic'] = 0x0436;
  13173. t['zhedescendercyrillic'] = 0x0497;
  13174. t['zhedieresiscyrillic'] = 0x04DD;
  13175. t['zihiragana'] = 0x3058;
  13176. t['zikatakana'] = 0x30B8;
  13177. t['zinorhebrew'] = 0x05AE;
  13178. t['zlinebelow'] = 0x1E95;
  13179. t['zmonospace'] = 0xFF5A;
  13180. t['zohiragana'] = 0x305E;
  13181. t['zokatakana'] = 0x30BE;
  13182. t['zparen'] = 0x24B5;
  13183. t['zretroflexhook'] = 0x0290;
  13184. t['zstroke'] = 0x01B6;
  13185. t['zuhiragana'] = 0x305A;
  13186. t['zukatakana'] = 0x30BA;
  13187. t['.notdef'] = 0x0000;
  13188. });
  13189. var getDingbatsGlyphsUnicode = getLookupTableFactory(function (t) {
  13190. t['space'] = 0x0020;
  13191. t['a1'] = 0x2701;
  13192. t['a2'] = 0x2702;
  13193. t['a202'] = 0x2703;
  13194. t['a3'] = 0x2704;
  13195. t['a4'] = 0x260E;
  13196. t['a5'] = 0x2706;
  13197. t['a119'] = 0x2707;
  13198. t['a118'] = 0x2708;
  13199. t['a117'] = 0x2709;
  13200. t['a11'] = 0x261B;
  13201. t['a12'] = 0x261E;
  13202. t['a13'] = 0x270C;
  13203. t['a14'] = 0x270D;
  13204. t['a15'] = 0x270E;
  13205. t['a16'] = 0x270F;
  13206. t['a105'] = 0x2710;
  13207. t['a17'] = 0x2711;
  13208. t['a18'] = 0x2712;
  13209. t['a19'] = 0x2713;
  13210. t['a20'] = 0x2714;
  13211. t['a21'] = 0x2715;
  13212. t['a22'] = 0x2716;
  13213. t['a23'] = 0x2717;
  13214. t['a24'] = 0x2718;
  13215. t['a25'] = 0x2719;
  13216. t['a26'] = 0x271A;
  13217. t['a27'] = 0x271B;
  13218. t['a28'] = 0x271C;
  13219. t['a6'] = 0x271D;
  13220. t['a7'] = 0x271E;
  13221. t['a8'] = 0x271F;
  13222. t['a9'] = 0x2720;
  13223. t['a10'] = 0x2721;
  13224. t['a29'] = 0x2722;
  13225. t['a30'] = 0x2723;
  13226. t['a31'] = 0x2724;
  13227. t['a32'] = 0x2725;
  13228. t['a33'] = 0x2726;
  13229. t['a34'] = 0x2727;
  13230. t['a35'] = 0x2605;
  13231. t['a36'] = 0x2729;
  13232. t['a37'] = 0x272A;
  13233. t['a38'] = 0x272B;
  13234. t['a39'] = 0x272C;
  13235. t['a40'] = 0x272D;
  13236. t['a41'] = 0x272E;
  13237. t['a42'] = 0x272F;
  13238. t['a43'] = 0x2730;
  13239. t['a44'] = 0x2731;
  13240. t['a45'] = 0x2732;
  13241. t['a46'] = 0x2733;
  13242. t['a47'] = 0x2734;
  13243. t['a48'] = 0x2735;
  13244. t['a49'] = 0x2736;
  13245. t['a50'] = 0x2737;
  13246. t['a51'] = 0x2738;
  13247. t['a52'] = 0x2739;
  13248. t['a53'] = 0x273A;
  13249. t['a54'] = 0x273B;
  13250. t['a55'] = 0x273C;
  13251. t['a56'] = 0x273D;
  13252. t['a57'] = 0x273E;
  13253. t['a58'] = 0x273F;
  13254. t['a59'] = 0x2740;
  13255. t['a60'] = 0x2741;
  13256. t['a61'] = 0x2742;
  13257. t['a62'] = 0x2743;
  13258. t['a63'] = 0x2744;
  13259. t['a64'] = 0x2745;
  13260. t['a65'] = 0x2746;
  13261. t['a66'] = 0x2747;
  13262. t['a67'] = 0x2748;
  13263. t['a68'] = 0x2749;
  13264. t['a69'] = 0x274A;
  13265. t['a70'] = 0x274B;
  13266. t['a71'] = 0x25CF;
  13267. t['a72'] = 0x274D;
  13268. t['a73'] = 0x25A0;
  13269. t['a74'] = 0x274F;
  13270. t['a203'] = 0x2750;
  13271. t['a75'] = 0x2751;
  13272. t['a204'] = 0x2752;
  13273. t['a76'] = 0x25B2;
  13274. t['a77'] = 0x25BC;
  13275. t['a78'] = 0x25C6;
  13276. t['a79'] = 0x2756;
  13277. t['a81'] = 0x25D7;
  13278. t['a82'] = 0x2758;
  13279. t['a83'] = 0x2759;
  13280. t['a84'] = 0x275A;
  13281. t['a97'] = 0x275B;
  13282. t['a98'] = 0x275C;
  13283. t['a99'] = 0x275D;
  13284. t['a100'] = 0x275E;
  13285. t['a101'] = 0x2761;
  13286. t['a102'] = 0x2762;
  13287. t['a103'] = 0x2763;
  13288. t['a104'] = 0x2764;
  13289. t['a106'] = 0x2765;
  13290. t['a107'] = 0x2766;
  13291. t['a108'] = 0x2767;
  13292. t['a112'] = 0x2663;
  13293. t['a111'] = 0x2666;
  13294. t['a110'] = 0x2665;
  13295. t['a109'] = 0x2660;
  13296. t['a120'] = 0x2460;
  13297. t['a121'] = 0x2461;
  13298. t['a122'] = 0x2462;
  13299. t['a123'] = 0x2463;
  13300. t['a124'] = 0x2464;
  13301. t['a125'] = 0x2465;
  13302. t['a126'] = 0x2466;
  13303. t['a127'] = 0x2467;
  13304. t['a128'] = 0x2468;
  13305. t['a129'] = 0x2469;
  13306. t['a130'] = 0x2776;
  13307. t['a131'] = 0x2777;
  13308. t['a132'] = 0x2778;
  13309. t['a133'] = 0x2779;
  13310. t['a134'] = 0x277A;
  13311. t['a135'] = 0x277B;
  13312. t['a136'] = 0x277C;
  13313. t['a137'] = 0x277D;
  13314. t['a138'] = 0x277E;
  13315. t['a139'] = 0x277F;
  13316. t['a140'] = 0x2780;
  13317. t['a141'] = 0x2781;
  13318. t['a142'] = 0x2782;
  13319. t['a143'] = 0x2783;
  13320. t['a144'] = 0x2784;
  13321. t['a145'] = 0x2785;
  13322. t['a146'] = 0x2786;
  13323. t['a147'] = 0x2787;
  13324. t['a148'] = 0x2788;
  13325. t['a149'] = 0x2789;
  13326. t['a150'] = 0x278A;
  13327. t['a151'] = 0x278B;
  13328. t['a152'] = 0x278C;
  13329. t['a153'] = 0x278D;
  13330. t['a154'] = 0x278E;
  13331. t['a155'] = 0x278F;
  13332. t['a156'] = 0x2790;
  13333. t['a157'] = 0x2791;
  13334. t['a158'] = 0x2792;
  13335. t['a159'] = 0x2793;
  13336. t['a160'] = 0x2794;
  13337. t['a161'] = 0x2192;
  13338. t['a163'] = 0x2194;
  13339. t['a164'] = 0x2195;
  13340. t['a196'] = 0x2798;
  13341. t['a165'] = 0x2799;
  13342. t['a192'] = 0x279A;
  13343. t['a166'] = 0x279B;
  13344. t['a167'] = 0x279C;
  13345. t['a168'] = 0x279D;
  13346. t['a169'] = 0x279E;
  13347. t['a170'] = 0x279F;
  13348. t['a171'] = 0x27A0;
  13349. t['a172'] = 0x27A1;
  13350. t['a173'] = 0x27A2;
  13351. t['a162'] = 0x27A3;
  13352. t['a174'] = 0x27A4;
  13353. t['a175'] = 0x27A5;
  13354. t['a176'] = 0x27A6;
  13355. t['a177'] = 0x27A7;
  13356. t['a178'] = 0x27A8;
  13357. t['a179'] = 0x27A9;
  13358. t['a193'] = 0x27AA;
  13359. t['a180'] = 0x27AB;
  13360. t['a199'] = 0x27AC;
  13361. t['a181'] = 0x27AD;
  13362. t['a200'] = 0x27AE;
  13363. t['a182'] = 0x27AF;
  13364. t['a201'] = 0x27B1;
  13365. t['a183'] = 0x27B2;
  13366. t['a184'] = 0x27B3;
  13367. t['a197'] = 0x27B4;
  13368. t['a185'] = 0x27B5;
  13369. t['a194'] = 0x27B6;
  13370. t['a198'] = 0x27B7;
  13371. t['a186'] = 0x27B8;
  13372. t['a195'] = 0x27B9;
  13373. t['a187'] = 0x27BA;
  13374. t['a188'] = 0x27BB;
  13375. t['a189'] = 0x27BC;
  13376. t['a190'] = 0x27BD;
  13377. t['a191'] = 0x27BE;
  13378. t['a89'] = 0x2768;
  13379. // 0xF8D7
  13380. t['a90'] = 0x2769;
  13381. // 0xF8D8
  13382. t['a93'] = 0x276A;
  13383. // 0xF8D9
  13384. t['a94'] = 0x276B;
  13385. // 0xF8DA
  13386. t['a91'] = 0x276C;
  13387. // 0xF8DB
  13388. t['a92'] = 0x276D;
  13389. // 0xF8DC
  13390. t['a205'] = 0x276E;
  13391. // 0xF8DD
  13392. t['a85'] = 0x276F;
  13393. // 0xF8DE
  13394. t['a206'] = 0x2770;
  13395. // 0xF8DF
  13396. t['a86'] = 0x2771;
  13397. // 0xF8E0
  13398. t['a87'] = 0x2772;
  13399. // 0xF8E1
  13400. t['a88'] = 0x2773;
  13401. // 0xF8E2
  13402. t['a95'] = 0x2774;
  13403. // 0xF8E3
  13404. t['a96'] = 0x2775;
  13405. // 0xF8E4
  13406. t['.notdef'] = 0x0000;
  13407. });
  13408. exports.getGlyphsUnicode = getGlyphsUnicode;
  13409. exports.getDingbatsGlyphsUnicode = getDingbatsGlyphsUnicode;
  13410. }));
  13411. (function (root, factory) {
  13412. factory(root.pdfjsCoreJbig2 = {}, root.pdfjsSharedUtil, root.pdfjsCoreArithmeticDecoder);
  13413. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  13414. var error = sharedUtil.error;
  13415. var log2 = sharedUtil.log2;
  13416. var readInt8 = sharedUtil.readInt8;
  13417. var readUint16 = sharedUtil.readUint16;
  13418. var readUint32 = sharedUtil.readUint32;
  13419. var shadow = sharedUtil.shadow;
  13420. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  13421. var Jbig2Image = function Jbig2ImageClosure() {
  13422. // Utility data structures
  13423. function ContextCache() {
  13424. }
  13425. ContextCache.prototype = {
  13426. getContexts: function (id) {
  13427. if (id in this) {
  13428. return this[id];
  13429. }
  13430. return this[id] = new Int8Array(1 << 16);
  13431. }
  13432. };
  13433. function DecodingContext(data, start, end) {
  13434. this.data = data;
  13435. this.start = start;
  13436. this.end = end;
  13437. }
  13438. DecodingContext.prototype = {
  13439. get decoder() {
  13440. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  13441. return shadow(this, 'decoder', decoder);
  13442. },
  13443. get contextCache() {
  13444. var cache = new ContextCache();
  13445. return shadow(this, 'contextCache', cache);
  13446. }
  13447. };
  13448. // Annex A. Arithmetic Integer Decoding Procedure
  13449. // A.2 Procedure for decoding values
  13450. function decodeInteger(contextCache, procedure, decoder) {
  13451. var contexts = contextCache.getContexts(procedure);
  13452. var prev = 1;
  13453. function readBits(length) {
  13454. var v = 0;
  13455. for (var i = 0; i < length; i++) {
  13456. var bit = decoder.readBit(contexts, prev);
  13457. prev = prev < 256 ? prev << 1 | bit : (prev << 1 | bit) & 511 | 256;
  13458. v = v << 1 | bit;
  13459. }
  13460. return v >>> 0;
  13461. }
  13462. var sign = readBits(1);
  13463. var value = readBits(1) ? readBits(1) ? readBits(1) ? readBits(1) ? readBits(1) ? readBits(32) + 4436 : readBits(12) + 340 : readBits(8) + 84 : readBits(6) + 20 : readBits(4) + 4 : readBits(2);
  13464. return sign === 0 ? value : value > 0 ? -value : null;
  13465. }
  13466. // A.3 The IAID decoding procedure
  13467. function decodeIAID(contextCache, decoder, codeLength) {
  13468. var contexts = contextCache.getContexts('IAID');
  13469. var prev = 1;
  13470. for (var i = 0; i < codeLength; i++) {
  13471. var bit = decoder.readBit(contexts, prev);
  13472. prev = prev << 1 | bit;
  13473. }
  13474. if (codeLength < 31) {
  13475. return prev & (1 << codeLength) - 1;
  13476. }
  13477. return prev & 0x7FFFFFFF;
  13478. }
  13479. // 7.3 Segment types
  13480. var SegmentTypes = [
  13481. 'SymbolDictionary',
  13482. null,
  13483. null,
  13484. null,
  13485. 'IntermediateTextRegion',
  13486. null,
  13487. 'ImmediateTextRegion',
  13488. 'ImmediateLosslessTextRegion',
  13489. null,
  13490. null,
  13491. null,
  13492. null,
  13493. null,
  13494. null,
  13495. null,
  13496. null,
  13497. 'patternDictionary',
  13498. null,
  13499. null,
  13500. null,
  13501. 'IntermediateHalftoneRegion',
  13502. null,
  13503. 'ImmediateHalftoneRegion',
  13504. 'ImmediateLosslessHalftoneRegion',
  13505. null,
  13506. null,
  13507. null,
  13508. null,
  13509. null,
  13510. null,
  13511. null,
  13512. null,
  13513. null,
  13514. null,
  13515. null,
  13516. null,
  13517. 'IntermediateGenericRegion',
  13518. null,
  13519. 'ImmediateGenericRegion',
  13520. 'ImmediateLosslessGenericRegion',
  13521. 'IntermediateGenericRefinementRegion',
  13522. null,
  13523. 'ImmediateGenericRefinementRegion',
  13524. 'ImmediateLosslessGenericRefinementRegion',
  13525. null,
  13526. null,
  13527. null,
  13528. null,
  13529. 'PageInformation',
  13530. 'EndOfPage',
  13531. 'EndOfStripe',
  13532. 'EndOfFile',
  13533. 'Profiles',
  13534. 'Tables',
  13535. null,
  13536. null,
  13537. null,
  13538. null,
  13539. null,
  13540. null,
  13541. null,
  13542. null,
  13543. 'Extension'
  13544. ];
  13545. var CodingTemplates = [
  13546. [
  13547. {
  13548. x: -1,
  13549. y: -2
  13550. },
  13551. {
  13552. x: 0,
  13553. y: -2
  13554. },
  13555. {
  13556. x: 1,
  13557. y: -2
  13558. },
  13559. {
  13560. x: -2,
  13561. y: -1
  13562. },
  13563. {
  13564. x: -1,
  13565. y: -1
  13566. },
  13567. {
  13568. x: 0,
  13569. y: -1
  13570. },
  13571. {
  13572. x: 1,
  13573. y: -1
  13574. },
  13575. {
  13576. x: 2,
  13577. y: -1
  13578. },
  13579. {
  13580. x: -4,
  13581. y: 0
  13582. },
  13583. {
  13584. x: -3,
  13585. y: 0
  13586. },
  13587. {
  13588. x: -2,
  13589. y: 0
  13590. },
  13591. {
  13592. x: -1,
  13593. y: 0
  13594. }
  13595. ],
  13596. [
  13597. {
  13598. x: -1,
  13599. y: -2
  13600. },
  13601. {
  13602. x: 0,
  13603. y: -2
  13604. },
  13605. {
  13606. x: 1,
  13607. y: -2
  13608. },
  13609. {
  13610. x: 2,
  13611. y: -2
  13612. },
  13613. {
  13614. x: -2,
  13615. y: -1
  13616. },
  13617. {
  13618. x: -1,
  13619. y: -1
  13620. },
  13621. {
  13622. x: 0,
  13623. y: -1
  13624. },
  13625. {
  13626. x: 1,
  13627. y: -1
  13628. },
  13629. {
  13630. x: 2,
  13631. y: -1
  13632. },
  13633. {
  13634. x: -3,
  13635. y: 0
  13636. },
  13637. {
  13638. x: -2,
  13639. y: 0
  13640. },
  13641. {
  13642. x: -1,
  13643. y: 0
  13644. }
  13645. ],
  13646. [
  13647. {
  13648. x: -1,
  13649. y: -2
  13650. },
  13651. {
  13652. x: 0,
  13653. y: -2
  13654. },
  13655. {
  13656. x: 1,
  13657. y: -2
  13658. },
  13659. {
  13660. x: -2,
  13661. y: -1
  13662. },
  13663. {
  13664. x: -1,
  13665. y: -1
  13666. },
  13667. {
  13668. x: 0,
  13669. y: -1
  13670. },
  13671. {
  13672. x: 1,
  13673. y: -1
  13674. },
  13675. {
  13676. x: -2,
  13677. y: 0
  13678. },
  13679. {
  13680. x: -1,
  13681. y: 0
  13682. }
  13683. ],
  13684. [
  13685. {
  13686. x: -3,
  13687. y: -1
  13688. },
  13689. {
  13690. x: -2,
  13691. y: -1
  13692. },
  13693. {
  13694. x: -1,
  13695. y: -1
  13696. },
  13697. {
  13698. x: 0,
  13699. y: -1
  13700. },
  13701. {
  13702. x: 1,
  13703. y: -1
  13704. },
  13705. {
  13706. x: -4,
  13707. y: 0
  13708. },
  13709. {
  13710. x: -3,
  13711. y: 0
  13712. },
  13713. {
  13714. x: -2,
  13715. y: 0
  13716. },
  13717. {
  13718. x: -1,
  13719. y: 0
  13720. }
  13721. ]
  13722. ];
  13723. var RefinementTemplates = [
  13724. {
  13725. coding: [
  13726. {
  13727. x: 0,
  13728. y: -1
  13729. },
  13730. {
  13731. x: 1,
  13732. y: -1
  13733. },
  13734. {
  13735. x: -1,
  13736. y: 0
  13737. }
  13738. ],
  13739. reference: [
  13740. {
  13741. x: 0,
  13742. y: -1
  13743. },
  13744. {
  13745. x: 1,
  13746. y: -1
  13747. },
  13748. {
  13749. x: -1,
  13750. y: 0
  13751. },
  13752. {
  13753. x: 0,
  13754. y: 0
  13755. },
  13756. {
  13757. x: 1,
  13758. y: 0
  13759. },
  13760. {
  13761. x: -1,
  13762. y: 1
  13763. },
  13764. {
  13765. x: 0,
  13766. y: 1
  13767. },
  13768. {
  13769. x: 1,
  13770. y: 1
  13771. }
  13772. ]
  13773. },
  13774. {
  13775. coding: [
  13776. {
  13777. x: -1,
  13778. y: -1
  13779. },
  13780. {
  13781. x: 0,
  13782. y: -1
  13783. },
  13784. {
  13785. x: 1,
  13786. y: -1
  13787. },
  13788. {
  13789. x: -1,
  13790. y: 0
  13791. }
  13792. ],
  13793. reference: [
  13794. {
  13795. x: 0,
  13796. y: -1
  13797. },
  13798. {
  13799. x: -1,
  13800. y: 0
  13801. },
  13802. {
  13803. x: 0,
  13804. y: 0
  13805. },
  13806. {
  13807. x: 1,
  13808. y: 0
  13809. },
  13810. {
  13811. x: 0,
  13812. y: 1
  13813. },
  13814. {
  13815. x: 1,
  13816. y: 1
  13817. }
  13818. ]
  13819. }
  13820. ];
  13821. // See 6.2.5.7 Decoding the bitmap.
  13822. var ReusedContexts = [
  13823. 0x9B25,
  13824. // 10011 0110010 0101
  13825. 0x0795,
  13826. // 0011 110010 101
  13827. 0x00E5,
  13828. // 001 11001 01
  13829. 0x0195
  13830. ];
  13831. // 011001 0101
  13832. var RefinementReusedContexts = [
  13833. 0x0020,
  13834. // '000' + '0' (coding) + '00010000' + '0' (reference)
  13835. 0x0008
  13836. ];
  13837. // '0000' + '001000'
  13838. function decodeBitmapTemplate0(width, height, decodingContext) {
  13839. var decoder = decodingContext.decoder;
  13840. var contexts = decodingContext.contextCache.getContexts('GB');
  13841. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  13842. // ...ooooo....
  13843. // ..ooooooo... Context template for current pixel (X)
  13844. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  13845. var OLD_PIXEL_MASK = 0x7BF7;
  13846. // 01111 0111111 0111
  13847. for (i = 0; i < height; i++) {
  13848. row = bitmap[i] = new Uint8Array(width);
  13849. row1 = i < 1 ? row : bitmap[i - 1];
  13850. row2 = i < 2 ? row : bitmap[i - 2];
  13851. // At the beginning of each row:
  13852. // Fill contextLabel with pixels that are above/right of (X)
  13853. contextLabel = row2[0] << 13 | row2[1] << 12 | row2[2] << 11 | row1[0] << 7 | row1[1] << 6 | row1[2] << 5 | row1[3] << 4;
  13854. for (j = 0; j < width; j++) {
  13855. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  13856. // At each pixel: Clear contextLabel pixels that are shifted
  13857. // out of the context, then add new ones.
  13858. contextLabel = (contextLabel & OLD_PIXEL_MASK) << 1 | (j + 3 < width ? row2[j + 3] << 11 : 0) | (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  13859. }
  13860. }
  13861. return bitmap;
  13862. }
  13863. // 6.2 Generic Region Decoding Procedure
  13864. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at, decodingContext) {
  13865. if (mmr) {
  13866. error('JBIG2 error: MMR encoding is not supported');
  13867. }
  13868. // Use optimized version for the most common case
  13869. if (templateIndex === 0 && !skip && !prediction && at.length === 4 && at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 && at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  13870. return decodeBitmapTemplate0(width, height, decodingContext);
  13871. }
  13872. var useskip = !!skip;
  13873. var template = CodingTemplates[templateIndex].concat(at);
  13874. // Sorting is non-standard, and it is not required. But sorting increases
  13875. // the number of template bits that can be reused from the previous
  13876. // contextLabel in the main loop.
  13877. template.sort(function (a, b) {
  13878. return a.y - b.y || a.x - b.x;
  13879. });
  13880. var templateLength = template.length;
  13881. var templateX = new Int8Array(templateLength);
  13882. var templateY = new Int8Array(templateLength);
  13883. var changingTemplateEntries = [];
  13884. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  13885. var c, k;
  13886. for (k = 0; k < templateLength; k++) {
  13887. templateX[k] = template[k].x;
  13888. templateY[k] = template[k].y;
  13889. minX = Math.min(minX, template[k].x);
  13890. maxX = Math.max(maxX, template[k].x);
  13891. minY = Math.min(minY, template[k].y);
  13892. // Check if the template pixel appears in two consecutive context labels,
  13893. // so it can be reused. Otherwise, we add it to the list of changing
  13894. // template entries.
  13895. if (k < templateLength - 1 && template[k].y === template[k + 1].y && template[k].x === template[k + 1].x - 1) {
  13896. reuseMask |= 1 << templateLength - 1 - k;
  13897. } else {
  13898. changingTemplateEntries.push(k);
  13899. }
  13900. }
  13901. var changingEntriesLength = changingTemplateEntries.length;
  13902. var changingTemplateX = new Int8Array(changingEntriesLength);
  13903. var changingTemplateY = new Int8Array(changingEntriesLength);
  13904. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  13905. for (c = 0; c < changingEntriesLength; c++) {
  13906. k = changingTemplateEntries[c];
  13907. changingTemplateX[c] = template[k].x;
  13908. changingTemplateY[c] = template[k].y;
  13909. changingTemplateBit[c] = 1 << templateLength - 1 - k;
  13910. }
  13911. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  13912. var sbb_left = -minX;
  13913. var sbb_top = -minY;
  13914. var sbb_right = width - maxX;
  13915. var pseudoPixelContext = ReusedContexts[templateIndex];
  13916. var row = new Uint8Array(width);
  13917. var bitmap = [];
  13918. var decoder = decodingContext.decoder;
  13919. var contexts = decodingContext.contextCache.getContexts('GB');
  13920. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  13921. for (var i = 0; i < height; i++) {
  13922. if (prediction) {
  13923. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  13924. ltp ^= sltp;
  13925. if (ltp) {
  13926. bitmap.push(row);
  13927. // duplicate previous row
  13928. continue;
  13929. }
  13930. }
  13931. row = new Uint8Array(row);
  13932. bitmap.push(row);
  13933. for (j = 0; j < width; j++) {
  13934. if (useskip && skip[i][j]) {
  13935. row[j] = 0;
  13936. continue;
  13937. }
  13938. // Are we in the middle of a scanline, so we can reuse contextLabel
  13939. // bits?
  13940. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  13941. // If yes, we can just shift the bits that are reusable and only
  13942. // fetch the remaining ones.
  13943. contextLabel = contextLabel << 1 & reuseMask;
  13944. for (k = 0; k < changingEntriesLength; k++) {
  13945. i0 = i + changingTemplateY[k];
  13946. j0 = j + changingTemplateX[k];
  13947. bit = bitmap[i0][j0];
  13948. if (bit) {
  13949. bit = changingTemplateBit[k];
  13950. contextLabel |= bit;
  13951. }
  13952. }
  13953. } else {
  13954. // compute the contextLabel from scratch
  13955. contextLabel = 0;
  13956. shift = templateLength - 1;
  13957. for (k = 0; k < templateLength; k++, shift--) {
  13958. j0 = j + templateX[k];
  13959. if (j0 >= 0 && j0 < width) {
  13960. i0 = i + templateY[k];
  13961. if (i0 >= 0) {
  13962. bit = bitmap[i0][j0];
  13963. if (bit) {
  13964. contextLabel |= bit << shift;
  13965. }
  13966. }
  13967. }
  13968. }
  13969. }
  13970. var pixel = decoder.readBit(contexts, contextLabel);
  13971. row[j] = pixel;
  13972. }
  13973. }
  13974. return bitmap;
  13975. }
  13976. // 6.3.2 Generic Refinement Region Decoding Procedure
  13977. function decodeRefinement(width, height, templateIndex, referenceBitmap, offsetX, offsetY, prediction, at, decodingContext) {
  13978. var codingTemplate = RefinementTemplates[templateIndex].coding;
  13979. if (templateIndex === 0) {
  13980. codingTemplate = codingTemplate.concat([at[0]]);
  13981. }
  13982. var codingTemplateLength = codingTemplate.length;
  13983. var codingTemplateX = new Int32Array(codingTemplateLength);
  13984. var codingTemplateY = new Int32Array(codingTemplateLength);
  13985. var k;
  13986. for (k = 0; k < codingTemplateLength; k++) {
  13987. codingTemplateX[k] = codingTemplate[k].x;
  13988. codingTemplateY[k] = codingTemplate[k].y;
  13989. }
  13990. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  13991. if (templateIndex === 0) {
  13992. referenceTemplate = referenceTemplate.concat([at[1]]);
  13993. }
  13994. var referenceTemplateLength = referenceTemplate.length;
  13995. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  13996. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  13997. for (k = 0; k < referenceTemplateLength; k++) {
  13998. referenceTemplateX[k] = referenceTemplate[k].x;
  13999. referenceTemplateY[k] = referenceTemplate[k].y;
  14000. }
  14001. var referenceWidth = referenceBitmap[0].length;
  14002. var referenceHeight = referenceBitmap.length;
  14003. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  14004. var bitmap = [];
  14005. var decoder = decodingContext.decoder;
  14006. var contexts = decodingContext.contextCache.getContexts('GR');
  14007. var ltp = 0;
  14008. for (var i = 0; i < height; i++) {
  14009. if (prediction) {
  14010. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  14011. ltp ^= sltp;
  14012. if (ltp) {
  14013. error('JBIG2 error: prediction is not supported');
  14014. }
  14015. }
  14016. var row = new Uint8Array(width);
  14017. bitmap.push(row);
  14018. for (var j = 0; j < width; j++) {
  14019. var i0, j0;
  14020. var contextLabel = 0;
  14021. for (k = 0; k < codingTemplateLength; k++) {
  14022. i0 = i + codingTemplateY[k];
  14023. j0 = j + codingTemplateX[k];
  14024. if (i0 < 0 || j0 < 0 || j0 >= width) {
  14025. contextLabel <<= 1;
  14026. } else
  14027. // out of bound pixel
  14028. {
  14029. contextLabel = contextLabel << 1 | bitmap[i0][j0];
  14030. }
  14031. }
  14032. for (k = 0; k < referenceTemplateLength; k++) {
  14033. i0 = i + referenceTemplateY[k] + offsetY;
  14034. j0 = j + referenceTemplateX[k] + offsetX;
  14035. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 || j0 >= referenceWidth) {
  14036. contextLabel <<= 1;
  14037. } else
  14038. // out of bound pixel
  14039. {
  14040. contextLabel = contextLabel << 1 | referenceBitmap[i0][j0];
  14041. }
  14042. }
  14043. var pixel = decoder.readBit(contexts, contextLabel);
  14044. row[j] = pixel;
  14045. }
  14046. }
  14047. return bitmap;
  14048. }
  14049. // 6.5.5 Decoding the symbol dictionary
  14050. function decodeSymbolDictionary(huffman, refinement, symbols, numberOfNewSymbols, numberOfExportedSymbols, huffmanTables, templateIndex, at, refinementTemplateIndex, refinementAt, decodingContext) {
  14051. if (huffman) {
  14052. error('JBIG2 error: huffman is not supported');
  14053. }
  14054. var newSymbols = [];
  14055. var currentHeight = 0;
  14056. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  14057. var decoder = decodingContext.decoder;
  14058. var contextCache = decodingContext.contextCache;
  14059. while (newSymbols.length < numberOfNewSymbols) {
  14060. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder);
  14061. // 6.5.6
  14062. currentHeight += deltaHeight;
  14063. var currentWidth = 0;
  14064. var totalWidth = 0;
  14065. while (true) {
  14066. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder);
  14067. // 6.5.7
  14068. if (deltaWidth === null) {
  14069. break;
  14070. }
  14071. // OOB
  14072. currentWidth += deltaWidth;
  14073. totalWidth += currentWidth;
  14074. var bitmap;
  14075. if (refinement) {
  14076. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  14077. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  14078. if (numberOfInstances > 1) {
  14079. bitmap = decodeTextRegion(huffman, refinement, currentWidth, currentHeight, 0, numberOfInstances, 1, //strip size
  14080. symbols.concat(newSymbols), symbolCodeLength, 0, //transposed
  14081. 0, //ds offset
  14082. 1, //top left 7.4.3.1.1
  14083. 0, //OR operator
  14084. huffmanTables, refinementTemplateIndex, refinementAt, decodingContext);
  14085. } else {
  14086. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  14087. var rdx = decodeInteger(contextCache, 'IARDX', decoder);
  14088. // 6.4.11.3
  14089. var rdy = decodeInteger(contextCache, 'IARDY', decoder);
  14090. // 6.4.11.4
  14091. var symbol = symbolId < symbols.length ? symbols[symbolId] : newSymbols[symbolId - symbols.length];
  14092. bitmap = decodeRefinement(currentWidth, currentHeight, refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt, decodingContext);
  14093. }
  14094. } else {
  14095. // 6.5.8.1 Direct-coded symbol bitmap
  14096. bitmap = decodeBitmap(false, currentWidth, currentHeight, templateIndex, false, null, at, decodingContext);
  14097. }
  14098. newSymbols.push(bitmap);
  14099. }
  14100. }
  14101. // 6.5.10 Exported symbols
  14102. var exportedSymbols = [];
  14103. var flags = [], currentFlag = false;
  14104. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  14105. while (flags.length < totalSymbolsLength) {
  14106. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  14107. while (runLength--) {
  14108. flags.push(currentFlag);
  14109. }
  14110. currentFlag = !currentFlag;
  14111. }
  14112. for (var i = 0, ii = symbols.length; i < ii; i++) {
  14113. if (flags[i]) {
  14114. exportedSymbols.push(symbols[i]);
  14115. }
  14116. }
  14117. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  14118. if (flags[i]) {
  14119. exportedSymbols.push(newSymbols[j]);
  14120. }
  14121. }
  14122. return exportedSymbols;
  14123. }
  14124. function decodeTextRegion(huffman, refinement, width, height, defaultPixelValue, numberOfSymbolInstances, stripSize, inputSymbols, symbolCodeLength, transposed, dsOffset, referenceCorner, combinationOperator, huffmanTables, refinementTemplateIndex, refinementAt, decodingContext) {
  14125. if (huffman) {
  14126. error('JBIG2 error: huffman is not supported');
  14127. }
  14128. // Prepare bitmap
  14129. var bitmap = [];
  14130. var i, row;
  14131. for (i = 0; i < height; i++) {
  14132. row = new Uint8Array(width);
  14133. if (defaultPixelValue) {
  14134. for (var j = 0; j < width; j++) {
  14135. row[j] = defaultPixelValue;
  14136. }
  14137. }
  14138. bitmap.push(row);
  14139. }
  14140. var decoder = decodingContext.decoder;
  14141. var contextCache = decodingContext.contextCache;
  14142. var stripT = -decodeInteger(contextCache, 'IADT', decoder);
  14143. // 6.4.6
  14144. var firstS = 0;
  14145. i = 0;
  14146. while (i < numberOfSymbolInstances) {
  14147. var deltaT = decodeInteger(contextCache, 'IADT', decoder);
  14148. // 6.4.6
  14149. stripT += deltaT;
  14150. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder);
  14151. // 6.4.7
  14152. firstS += deltaFirstS;
  14153. var currentS = firstS;
  14154. do {
  14155. var currentT = stripSize === 1 ? 0 : decodeInteger(contextCache, 'IAIT', decoder);
  14156. // 6.4.9
  14157. var t = stripSize * stripT + currentT;
  14158. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  14159. var applyRefinement = refinement && decodeInteger(contextCache, 'IARI', decoder);
  14160. var symbolBitmap = inputSymbols[symbolId];
  14161. var symbolWidth = symbolBitmap[0].length;
  14162. var symbolHeight = symbolBitmap.length;
  14163. if (applyRefinement) {
  14164. var rdw = decodeInteger(contextCache, 'IARDW', decoder);
  14165. // 6.4.11.1
  14166. var rdh = decodeInteger(contextCache, 'IARDH', decoder);
  14167. // 6.4.11.2
  14168. var rdx = decodeInteger(contextCache, 'IARDX', decoder);
  14169. // 6.4.11.3
  14170. var rdy = decodeInteger(contextCache, 'IARDY', decoder);
  14171. // 6.4.11.4
  14172. symbolWidth += rdw;
  14173. symbolHeight += rdh;
  14174. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight, refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx, (rdh >> 1) + rdy, false, refinementAt, decodingContext);
  14175. }
  14176. var offsetT = t - (referenceCorner & 1 ? 0 : symbolHeight);
  14177. var offsetS = currentS - (referenceCorner & 2 ? symbolWidth : 0);
  14178. var s2, t2, symbolRow;
  14179. if (transposed) {
  14180. // Place Symbol Bitmap from T1,S1
  14181. for (s2 = 0; s2 < symbolHeight; s2++) {
  14182. row = bitmap[offsetS + s2];
  14183. if (!row) {
  14184. continue;
  14185. }
  14186. symbolRow = symbolBitmap[s2];
  14187. // To ignore Parts of Symbol bitmap which goes
  14188. // outside bitmap region
  14189. var maxWidth = Math.min(width - offsetT, symbolWidth);
  14190. switch (combinationOperator) {
  14191. case 0:
  14192. // OR
  14193. for (t2 = 0; t2 < maxWidth; t2++) {
  14194. row[offsetT + t2] |= symbolRow[t2];
  14195. }
  14196. break;
  14197. case 2:
  14198. // XOR
  14199. for (t2 = 0; t2 < maxWidth; t2++) {
  14200. row[offsetT + t2] ^= symbolRow[t2];
  14201. }
  14202. break;
  14203. default:
  14204. error('JBIG2 error: operator ' + combinationOperator + ' is not supported');
  14205. }
  14206. }
  14207. currentS += symbolHeight - 1;
  14208. } else {
  14209. for (t2 = 0; t2 < symbolHeight; t2++) {
  14210. row = bitmap[offsetT + t2];
  14211. if (!row) {
  14212. continue;
  14213. }
  14214. symbolRow = symbolBitmap[t2];
  14215. switch (combinationOperator) {
  14216. case 0:
  14217. // OR
  14218. for (s2 = 0; s2 < symbolWidth; s2++) {
  14219. row[offsetS + s2] |= symbolRow[s2];
  14220. }
  14221. break;
  14222. case 2:
  14223. // XOR
  14224. for (s2 = 0; s2 < symbolWidth; s2++) {
  14225. row[offsetS + s2] ^= symbolRow[s2];
  14226. }
  14227. break;
  14228. default:
  14229. error('JBIG2 error: operator ' + combinationOperator + ' is not supported');
  14230. }
  14231. }
  14232. currentS += symbolWidth - 1;
  14233. }
  14234. i++;
  14235. var deltaS = decodeInteger(contextCache, 'IADS', decoder);
  14236. // 6.4.8
  14237. if (deltaS === null) {
  14238. break;
  14239. }
  14240. // OOB
  14241. currentS += deltaS + dsOffset;
  14242. } while (true);
  14243. }
  14244. return bitmap;
  14245. }
  14246. function readSegmentHeader(data, start) {
  14247. var segmentHeader = {};
  14248. segmentHeader.number = readUint32(data, start);
  14249. var flags = data[start + 4];
  14250. var segmentType = flags & 0x3F;
  14251. if (!SegmentTypes[segmentType]) {
  14252. error('JBIG2 error: invalid segment type: ' + segmentType);
  14253. }
  14254. segmentHeader.type = segmentType;
  14255. segmentHeader.typeName = SegmentTypes[segmentType];
  14256. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  14257. var pageAssociationFieldSize = !!(flags & 0x40);
  14258. var referredFlags = data[start + 5];
  14259. var referredToCount = referredFlags >> 5 & 7;
  14260. var retainBits = [referredFlags & 31];
  14261. var position = start + 6;
  14262. if (referredFlags === 7) {
  14263. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  14264. position += 3;
  14265. var bytes = referredToCount + 7 >> 3;
  14266. retainBits[0] = data[position++];
  14267. while (--bytes > 0) {
  14268. retainBits.push(data[position++]);
  14269. }
  14270. } else if (referredFlags === 5 || referredFlags === 6) {
  14271. error('JBIG2 error: invalid referred-to flags');
  14272. }
  14273. segmentHeader.retainBits = retainBits;
  14274. var referredToSegmentNumberSize = segmentHeader.number <= 256 ? 1 : segmentHeader.number <= 65536 ? 2 : 4;
  14275. var referredTo = [];
  14276. var i, ii;
  14277. for (i = 0; i < referredToCount; i++) {
  14278. var number = referredToSegmentNumberSize === 1 ? data[position] : referredToSegmentNumberSize === 2 ? readUint16(data, position) : readUint32(data, position);
  14279. referredTo.push(number);
  14280. position += referredToSegmentNumberSize;
  14281. }
  14282. segmentHeader.referredTo = referredTo;
  14283. if (!pageAssociationFieldSize) {
  14284. segmentHeader.pageAssociation = data[position++];
  14285. } else {
  14286. segmentHeader.pageAssociation = readUint32(data, position);
  14287. position += 4;
  14288. }
  14289. segmentHeader.length = readUint32(data, position);
  14290. position += 4;
  14291. if (segmentHeader.length === 0xFFFFFFFF) {
  14292. // 7.2.7 Segment data length, unknown segment length
  14293. if (segmentType === 38) {
  14294. // ImmediateGenericRegion
  14295. var genericRegionInfo = readRegionSegmentInformation(data, position);
  14296. var genericRegionSegmentFlags = data[position + RegionSegmentInformationFieldLength];
  14297. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  14298. // searching for the segment end
  14299. var searchPatternLength = 6;
  14300. var searchPattern = new Uint8Array(searchPatternLength);
  14301. if (!genericRegionMmr) {
  14302. searchPattern[0] = 0xFF;
  14303. searchPattern[1] = 0xAC;
  14304. }
  14305. searchPattern[2] = genericRegionInfo.height >>> 24 & 0xFF;
  14306. searchPattern[3] = genericRegionInfo.height >> 16 & 0xFF;
  14307. searchPattern[4] = genericRegionInfo.height >> 8 & 0xFF;
  14308. searchPattern[5] = genericRegionInfo.height & 0xFF;
  14309. for (i = position, ii = data.length; i < ii; i++) {
  14310. var j = 0;
  14311. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  14312. j++;
  14313. }
  14314. if (j === searchPatternLength) {
  14315. segmentHeader.length = i + searchPatternLength;
  14316. break;
  14317. }
  14318. }
  14319. if (segmentHeader.length === 0xFFFFFFFF) {
  14320. error('JBIG2 error: segment end was not found');
  14321. }
  14322. } else {
  14323. error('JBIG2 error: invalid unknown segment length');
  14324. }
  14325. }
  14326. segmentHeader.headerEnd = position;
  14327. return segmentHeader;
  14328. }
  14329. function readSegments(header, data, start, end) {
  14330. var segments = [];
  14331. var position = start;
  14332. while (position < end) {
  14333. var segmentHeader = readSegmentHeader(data, position);
  14334. position = segmentHeader.headerEnd;
  14335. var segment = {
  14336. header: segmentHeader,
  14337. data: data
  14338. };
  14339. if (!header.randomAccess) {
  14340. segment.start = position;
  14341. position += segmentHeader.length;
  14342. segment.end = position;
  14343. }
  14344. segments.push(segment);
  14345. if (segmentHeader.type === 51) {
  14346. break;
  14347. }
  14348. }
  14349. // end of file is found
  14350. if (header.randomAccess) {
  14351. for (var i = 0, ii = segments.length; i < ii; i++) {
  14352. segments[i].start = position;
  14353. position += segments[i].header.length;
  14354. segments[i].end = position;
  14355. }
  14356. }
  14357. return segments;
  14358. }
  14359. // 7.4.1 Region segment information field
  14360. function readRegionSegmentInformation(data, start) {
  14361. return {
  14362. width: readUint32(data, start),
  14363. height: readUint32(data, start + 4),
  14364. x: readUint32(data, start + 8),
  14365. y: readUint32(data, start + 12),
  14366. combinationOperator: data[start + 16] & 7
  14367. };
  14368. }
  14369. var RegionSegmentInformationFieldLength = 17;
  14370. function processSegment(segment, visitor) {
  14371. var header = segment.header;
  14372. var data = segment.data, position = segment.start, end = segment.end;
  14373. var args, at, i, atLength;
  14374. switch (header.type) {
  14375. case 0:
  14376. // SymbolDictionary
  14377. // 7.4.2 Symbol dictionary segment syntax
  14378. var dictionary = {};
  14379. var dictionaryFlags = readUint16(data, position);
  14380. // 7.4.2.1.1
  14381. dictionary.huffman = !!(dictionaryFlags & 1);
  14382. dictionary.refinement = !!(dictionaryFlags & 2);
  14383. dictionary.huffmanDHSelector = dictionaryFlags >> 2 & 3;
  14384. dictionary.huffmanDWSelector = dictionaryFlags >> 4 & 3;
  14385. dictionary.bitmapSizeSelector = dictionaryFlags >> 6 & 1;
  14386. dictionary.aggregationInstancesSelector = dictionaryFlags >> 7 & 1;
  14387. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  14388. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  14389. dictionary.template = dictionaryFlags >> 10 & 3;
  14390. dictionary.refinementTemplate = dictionaryFlags >> 12 & 1;
  14391. position += 2;
  14392. if (!dictionary.huffman) {
  14393. atLength = dictionary.template === 0 ? 4 : 1;
  14394. at = [];
  14395. for (i = 0; i < atLength; i++) {
  14396. at.push({
  14397. x: readInt8(data, position),
  14398. y: readInt8(data, position + 1)
  14399. });
  14400. position += 2;
  14401. }
  14402. dictionary.at = at;
  14403. }
  14404. if (dictionary.refinement && !dictionary.refinementTemplate) {
  14405. at = [];
  14406. for (i = 0; i < 2; i++) {
  14407. at.push({
  14408. x: readInt8(data, position),
  14409. y: readInt8(data, position + 1)
  14410. });
  14411. position += 2;
  14412. }
  14413. dictionary.refinementAt = at;
  14414. }
  14415. dictionary.numberOfExportedSymbols = readUint32(data, position);
  14416. position += 4;
  14417. dictionary.numberOfNewSymbols = readUint32(data, position);
  14418. position += 4;
  14419. args = [
  14420. dictionary,
  14421. header.number,
  14422. header.referredTo,
  14423. data,
  14424. position,
  14425. end
  14426. ];
  14427. break;
  14428. case 6:
  14429. // ImmediateTextRegion
  14430. case 7:
  14431. // ImmediateLosslessTextRegion
  14432. var textRegion = {};
  14433. textRegion.info = readRegionSegmentInformation(data, position);
  14434. position += RegionSegmentInformationFieldLength;
  14435. var textRegionSegmentFlags = readUint16(data, position);
  14436. position += 2;
  14437. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  14438. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  14439. textRegion.stripSize = 1 << (textRegionSegmentFlags >> 2 & 3);
  14440. textRegion.referenceCorner = textRegionSegmentFlags >> 4 & 3;
  14441. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  14442. textRegion.combinationOperator = textRegionSegmentFlags >> 7 & 3;
  14443. textRegion.defaultPixelValue = textRegionSegmentFlags >> 9 & 1;
  14444. textRegion.dsOffset = textRegionSegmentFlags << 17 >> 27;
  14445. textRegion.refinementTemplate = textRegionSegmentFlags >> 15 & 1;
  14446. if (textRegion.huffman) {
  14447. var textRegionHuffmanFlags = readUint16(data, position);
  14448. position += 2;
  14449. textRegion.huffmanFS = textRegionHuffmanFlags & 3;
  14450. textRegion.huffmanDS = textRegionHuffmanFlags >> 2 & 3;
  14451. textRegion.huffmanDT = textRegionHuffmanFlags >> 4 & 3;
  14452. textRegion.huffmanRefinementDW = textRegionHuffmanFlags >> 6 & 3;
  14453. textRegion.huffmanRefinementDH = textRegionHuffmanFlags >> 8 & 3;
  14454. textRegion.huffmanRefinementDX = textRegionHuffmanFlags >> 10 & 3;
  14455. textRegion.huffmanRefinementDY = textRegionHuffmanFlags >> 12 & 3;
  14456. textRegion.huffmanRefinementSizeSelector = !!(textRegionHuffmanFlags & 14);
  14457. }
  14458. if (textRegion.refinement && !textRegion.refinementTemplate) {
  14459. at = [];
  14460. for (i = 0; i < 2; i++) {
  14461. at.push({
  14462. x: readInt8(data, position),
  14463. y: readInt8(data, position + 1)
  14464. });
  14465. position += 2;
  14466. }
  14467. textRegion.refinementAt = at;
  14468. }
  14469. textRegion.numberOfSymbolInstances = readUint32(data, position);
  14470. position += 4;
  14471. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  14472. if (textRegion.huffman) {
  14473. error('JBIG2 error: huffman is not supported');
  14474. }
  14475. args = [
  14476. textRegion,
  14477. header.referredTo,
  14478. data,
  14479. position,
  14480. end
  14481. ];
  14482. break;
  14483. case 38:
  14484. // ImmediateGenericRegion
  14485. case 39:
  14486. // ImmediateLosslessGenericRegion
  14487. var genericRegion = {};
  14488. genericRegion.info = readRegionSegmentInformation(data, position);
  14489. position += RegionSegmentInformationFieldLength;
  14490. var genericRegionSegmentFlags = data[position++];
  14491. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  14492. genericRegion.template = genericRegionSegmentFlags >> 1 & 3;
  14493. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  14494. if (!genericRegion.mmr) {
  14495. atLength = genericRegion.template === 0 ? 4 : 1;
  14496. at = [];
  14497. for (i = 0; i < atLength; i++) {
  14498. at.push({
  14499. x: readInt8(data, position),
  14500. y: readInt8(data, position + 1)
  14501. });
  14502. position += 2;
  14503. }
  14504. genericRegion.at = at;
  14505. }
  14506. args = [
  14507. genericRegion,
  14508. data,
  14509. position,
  14510. end
  14511. ];
  14512. break;
  14513. case 48:
  14514. // PageInformation
  14515. var pageInfo = {
  14516. width: readUint32(data, position),
  14517. height: readUint32(data, position + 4),
  14518. resolutionX: readUint32(data, position + 8),
  14519. resolutionY: readUint32(data, position + 12)
  14520. };
  14521. if (pageInfo.height === 0xFFFFFFFF) {
  14522. delete pageInfo.height;
  14523. }
  14524. var pageSegmentFlags = data[position + 16];
  14525. var pageStripingInformation = readUint16(data, position + 17);
  14526. pageInfo.lossless = !!(pageSegmentFlags & 1);
  14527. pageInfo.refinement = !!(pageSegmentFlags & 2);
  14528. pageInfo.defaultPixelValue = pageSegmentFlags >> 2 & 1;
  14529. pageInfo.combinationOperator = pageSegmentFlags >> 3 & 3;
  14530. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  14531. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  14532. args = [pageInfo];
  14533. break;
  14534. case 49:
  14535. // EndOfPage
  14536. break;
  14537. case 50:
  14538. // EndOfStripe
  14539. break;
  14540. case 51:
  14541. // EndOfFile
  14542. break;
  14543. case 62:
  14544. // 7.4.15 defines 2 extension types which
  14545. // are comments and can be ignored.
  14546. break;
  14547. default:
  14548. error('JBIG2 error: segment type ' + header.typeName + '(' + header.type + ') is not implemented');
  14549. }
  14550. var callbackName = 'on' + header.typeName;
  14551. if (callbackName in visitor) {
  14552. visitor[callbackName].apply(visitor, args);
  14553. }
  14554. }
  14555. function processSegments(segments, visitor) {
  14556. for (var i = 0, ii = segments.length; i < ii; i++) {
  14557. processSegment(segments[i], visitor);
  14558. }
  14559. }
  14560. function parseJbig2(data, start, end) {
  14561. var position = start;
  14562. if (data[position] !== 0x97 || data[position + 1] !== 0x4A || data[position + 2] !== 0x42 || data[position + 3] !== 0x32 || data[position + 4] !== 0x0D || data[position + 5] !== 0x0A || data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  14563. error('JBIG2 error: invalid header');
  14564. }
  14565. var header = {};
  14566. position += 8;
  14567. var flags = data[position++];
  14568. header.randomAccess = !(flags & 1);
  14569. if (!(flags & 2)) {
  14570. header.numberOfPages = readUint32(data, position);
  14571. position += 4;
  14572. }
  14573. var segments = readSegments(header, data, position, end);
  14574. error('Not implemented');
  14575. }
  14576. // processSegments(segments, new SimpleSegmentVisitor());
  14577. function parseJbig2Chunks(chunks) {
  14578. var visitor = new SimpleSegmentVisitor();
  14579. for (var i = 0, ii = chunks.length; i < ii; i++) {
  14580. var chunk = chunks[i];
  14581. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  14582. processSegments(segments, visitor);
  14583. }
  14584. return visitor.buffer;
  14585. }
  14586. function SimpleSegmentVisitor() {
  14587. }
  14588. SimpleSegmentVisitor.prototype = {
  14589. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  14590. this.currentPageInfo = info;
  14591. var rowSize = info.width + 7 >> 3;
  14592. var buffer = new Uint8Array(rowSize * info.height);
  14593. // The contents of ArrayBuffers are initialized to 0.
  14594. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  14595. if (info.defaultPixelValue) {
  14596. for (var i = 0, ii = buffer.length; i < ii; i++) {
  14597. buffer[i] = 0xFF;
  14598. }
  14599. }
  14600. this.buffer = buffer;
  14601. },
  14602. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  14603. var pageInfo = this.currentPageInfo;
  14604. var width = regionInfo.width, height = regionInfo.height;
  14605. var rowSize = pageInfo.width + 7 >> 3;
  14606. var combinationOperator = pageInfo.combinationOperatorOverride ? regionInfo.combinationOperator : pageInfo.combinationOperator;
  14607. var buffer = this.buffer;
  14608. var mask0 = 128 >> (regionInfo.x & 7);
  14609. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  14610. var i, j, mask, offset;
  14611. switch (combinationOperator) {
  14612. case 0:
  14613. // OR
  14614. for (i = 0; i < height; i++) {
  14615. mask = mask0;
  14616. offset = offset0;
  14617. for (j = 0; j < width; j++) {
  14618. if (bitmap[i][j]) {
  14619. buffer[offset] |= mask;
  14620. }
  14621. mask >>= 1;
  14622. if (!mask) {
  14623. mask = 128;
  14624. offset++;
  14625. }
  14626. }
  14627. offset0 += rowSize;
  14628. }
  14629. break;
  14630. case 2:
  14631. // XOR
  14632. for (i = 0; i < height; i++) {
  14633. mask = mask0;
  14634. offset = offset0;
  14635. for (j = 0; j < width; j++) {
  14636. if (bitmap[i][j]) {
  14637. buffer[offset] ^= mask;
  14638. }
  14639. mask >>= 1;
  14640. if (!mask) {
  14641. mask = 128;
  14642. offset++;
  14643. }
  14644. }
  14645. offset0 += rowSize;
  14646. }
  14647. break;
  14648. default:
  14649. error('JBIG2 error: operator ' + combinationOperator + ' is not supported');
  14650. }
  14651. },
  14652. onImmediateGenericRegion: function SimpleSegmentVisitor_onImmediateGenericRegion(region, data, start, end) {
  14653. var regionInfo = region.info;
  14654. var decodingContext = new DecodingContext(data, start, end);
  14655. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height, region.template, region.prediction, null, region.at, decodingContext);
  14656. this.drawBitmap(regionInfo, bitmap);
  14657. },
  14658. onImmediateLosslessGenericRegion: function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  14659. this.onImmediateGenericRegion.apply(this, arguments);
  14660. },
  14661. onSymbolDictionary: function SimpleSegmentVisitor_onSymbolDictionary(dictionary, currentSegment, referredSegments, data, start, end) {
  14662. var huffmanTables;
  14663. if (dictionary.huffman) {
  14664. error('JBIG2 error: huffman is not supported');
  14665. }
  14666. // Combines exported symbols from all referred segments
  14667. var symbols = this.symbols;
  14668. if (!symbols) {
  14669. this.symbols = symbols = {};
  14670. }
  14671. var inputSymbols = [];
  14672. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  14673. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  14674. }
  14675. var decodingContext = new DecodingContext(data, start, end);
  14676. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman, dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols, dictionary.numberOfExportedSymbols, huffmanTables, dictionary.template, dictionary.at, dictionary.refinementTemplate, dictionary.refinementAt, decodingContext);
  14677. },
  14678. onImmediateTextRegion: function SimpleSegmentVisitor_onImmediateTextRegion(region, referredSegments, data, start, end) {
  14679. var regionInfo = region.info;
  14680. var huffmanTables;
  14681. // Combines exported symbols from all referred segments
  14682. var symbols = this.symbols;
  14683. var inputSymbols = [];
  14684. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  14685. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  14686. }
  14687. var symbolCodeLength = log2(inputSymbols.length);
  14688. var decodingContext = new DecodingContext(data, start, end);
  14689. var bitmap = decodeTextRegion(region.huffman, region.refinement, regionInfo.width, regionInfo.height, region.defaultPixelValue, region.numberOfSymbolInstances, region.stripSize, inputSymbols, symbolCodeLength, region.transposed, region.dsOffset, region.referenceCorner, region.combinationOperator, huffmanTables, region.refinementTemplate, region.refinementAt, decodingContext);
  14690. this.drawBitmap(regionInfo, bitmap);
  14691. },
  14692. onImmediateLosslessTextRegion: function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  14693. this.onImmediateTextRegion.apply(this, arguments);
  14694. }
  14695. };
  14696. function Jbig2Image() {
  14697. }
  14698. Jbig2Image.prototype = {
  14699. parseChunks: function Jbig2Image_parseChunks(chunks) {
  14700. return parseJbig2Chunks(chunks);
  14701. }
  14702. };
  14703. return Jbig2Image;
  14704. }();
  14705. exports.Jbig2Image = Jbig2Image;
  14706. }));
  14707. (function (root, factory) {
  14708. factory(root.pdfjsCoreJpg = {}, root.pdfjsSharedUtil);
  14709. }(this, function (exports, sharedUtil) {
  14710. var error = sharedUtil.error;
  14711. /**
  14712. * This code was forked from https://github.com/notmasteryet/jpgjs.
  14713. * The original version was created by GitHub user notmasteryet.
  14714. *
  14715. * - The JPEG specification can be found in the ITU CCITT Recommendation T.81
  14716. * (www.w3.org/Graphics/JPEG/itu-t81.pdf)
  14717. * - The JFIF specification can be found in the JPEG File Interchange Format
  14718. * (www.w3.org/Graphics/JPEG/jfif3.pdf)
  14719. * - The Adobe Application-Specific JPEG markers in the
  14720. * Supporting the DCT Filters in PostScript Level 2, Technical Note #5116
  14721. * (partners.adobe.com/public/developer/en/ps/sdk/5116.DCT_Filter.pdf)
  14722. */
  14723. var JpegImage = function JpegImageClosure() {
  14724. var dctZigZag = new Uint8Array([
  14725. 0,
  14726. 1,
  14727. 8,
  14728. 16,
  14729. 9,
  14730. 2,
  14731. 3,
  14732. 10,
  14733. 17,
  14734. 24,
  14735. 32,
  14736. 25,
  14737. 18,
  14738. 11,
  14739. 4,
  14740. 5,
  14741. 12,
  14742. 19,
  14743. 26,
  14744. 33,
  14745. 40,
  14746. 48,
  14747. 41,
  14748. 34,
  14749. 27,
  14750. 20,
  14751. 13,
  14752. 6,
  14753. 7,
  14754. 14,
  14755. 21,
  14756. 28,
  14757. 35,
  14758. 42,
  14759. 49,
  14760. 56,
  14761. 57,
  14762. 50,
  14763. 43,
  14764. 36,
  14765. 29,
  14766. 22,
  14767. 15,
  14768. 23,
  14769. 30,
  14770. 37,
  14771. 44,
  14772. 51,
  14773. 58,
  14774. 59,
  14775. 52,
  14776. 45,
  14777. 38,
  14778. 31,
  14779. 39,
  14780. 46,
  14781. 53,
  14782. 60,
  14783. 61,
  14784. 54,
  14785. 47,
  14786. 55,
  14787. 62,
  14788. 63
  14789. ]);
  14790. var dctCos1 = 4017;
  14791. // cos(pi/16)
  14792. var dctSin1 = 799;
  14793. // sin(pi/16)
  14794. var dctCos3 = 3406;
  14795. // cos(3*pi/16)
  14796. var dctSin3 = 2276;
  14797. // sin(3*pi/16)
  14798. var dctCos6 = 1567;
  14799. // cos(6*pi/16)
  14800. var dctSin6 = 3784;
  14801. // sin(6*pi/16)
  14802. var dctSqrt2 = 5793;
  14803. // sqrt(2)
  14804. var dctSqrt1d2 = 2896;
  14805. // sqrt(2) / 2
  14806. function JpegImage() {
  14807. this.decodeTransform = null;
  14808. this.colorTransform = -1;
  14809. }
  14810. function buildHuffmanTable(codeLengths, values) {
  14811. var k = 0, code = [], i, j, length = 16;
  14812. while (length > 0 && !codeLengths[length - 1]) {
  14813. length--;
  14814. }
  14815. code.push({
  14816. children: [],
  14817. index: 0
  14818. });
  14819. var p = code[0], q;
  14820. for (i = 0; i < length; i++) {
  14821. for (j = 0; j < codeLengths[i]; j++) {
  14822. p = code.pop();
  14823. p.children[p.index] = values[k];
  14824. while (p.index > 0) {
  14825. p = code.pop();
  14826. }
  14827. p.index++;
  14828. code.push(p);
  14829. while (code.length <= i) {
  14830. code.push(q = {
  14831. children: [],
  14832. index: 0
  14833. });
  14834. p.children[p.index] = q.children;
  14835. p = q;
  14836. }
  14837. k++;
  14838. }
  14839. if (i + 1 < length) {
  14840. // p here points to last code
  14841. code.push(q = {
  14842. children: [],
  14843. index: 0
  14844. });
  14845. p.children[p.index] = q.children;
  14846. p = q;
  14847. }
  14848. }
  14849. return code[0].children;
  14850. }
  14851. function getBlockBufferOffset(component, row, col) {
  14852. return 64 * ((component.blocksPerLine + 1) * row + col);
  14853. }
  14854. function decodeScan(data, offset, frame, components, resetInterval, spectralStart, spectralEnd, successivePrev, successive) {
  14855. var mcusPerLine = frame.mcusPerLine;
  14856. var progressive = frame.progressive;
  14857. var startOffset = offset, bitsData = 0, bitsCount = 0;
  14858. function readBit() {
  14859. if (bitsCount > 0) {
  14860. bitsCount--;
  14861. return bitsData >> bitsCount & 1;
  14862. }
  14863. bitsData = data[offset++];
  14864. if (bitsData === 0xFF) {
  14865. var nextByte = data[offset++];
  14866. if (nextByte) {
  14867. error('JPEG error: unexpected marker ' + (bitsData << 8 | nextByte).toString(16));
  14868. }
  14869. }
  14870. // unstuff 0
  14871. bitsCount = 7;
  14872. return bitsData >>> 7;
  14873. }
  14874. function decodeHuffman(tree) {
  14875. var node = tree;
  14876. while (true) {
  14877. node = node[readBit()];
  14878. if (typeof node === 'number') {
  14879. return node;
  14880. }
  14881. if (typeof node !== 'object') {
  14882. error('JPEG error: invalid huffman sequence');
  14883. }
  14884. }
  14885. }
  14886. function receive(length) {
  14887. var n = 0;
  14888. while (length > 0) {
  14889. n = n << 1 | readBit();
  14890. length--;
  14891. }
  14892. return n;
  14893. }
  14894. function receiveAndExtend(length) {
  14895. if (length === 1) {
  14896. return readBit() === 1 ? 1 : -1;
  14897. }
  14898. var n = receive(length);
  14899. if (n >= 1 << length - 1) {
  14900. return n;
  14901. }
  14902. return n + (-1 << length) + 1;
  14903. }
  14904. function decodeBaseline(component, offset) {
  14905. var t = decodeHuffman(component.huffmanTableDC);
  14906. var diff = t === 0 ? 0 : receiveAndExtend(t);
  14907. component.blockData[offset] = component.pred += diff;
  14908. var k = 1;
  14909. while (k < 64) {
  14910. var rs = decodeHuffman(component.huffmanTableAC);
  14911. var s = rs & 15, r = rs >> 4;
  14912. if (s === 0) {
  14913. if (r < 15) {
  14914. break;
  14915. }
  14916. k += 16;
  14917. continue;
  14918. }
  14919. k += r;
  14920. var z = dctZigZag[k];
  14921. component.blockData[offset + z] = receiveAndExtend(s);
  14922. k++;
  14923. }
  14924. }
  14925. function decodeDCFirst(component, offset) {
  14926. var t = decodeHuffman(component.huffmanTableDC);
  14927. var diff = t === 0 ? 0 : receiveAndExtend(t) << successive;
  14928. component.blockData[offset] = component.pred += diff;
  14929. }
  14930. function decodeDCSuccessive(component, offset) {
  14931. component.blockData[offset] |= readBit() << successive;
  14932. }
  14933. var eobrun = 0;
  14934. function decodeACFirst(component, offset) {
  14935. if (eobrun > 0) {
  14936. eobrun--;
  14937. return;
  14938. }
  14939. var k = spectralStart, e = spectralEnd;
  14940. while (k <= e) {
  14941. var rs = decodeHuffman(component.huffmanTableAC);
  14942. var s = rs & 15, r = rs >> 4;
  14943. if (s === 0) {
  14944. if (r < 15) {
  14945. eobrun = receive(r) + (1 << r) - 1;
  14946. break;
  14947. }
  14948. k += 16;
  14949. continue;
  14950. }
  14951. k += r;
  14952. var z = dctZigZag[k];
  14953. component.blockData[offset + z] = receiveAndExtend(s) * (1 << successive);
  14954. k++;
  14955. }
  14956. }
  14957. var successiveACState = 0, successiveACNextValue;
  14958. function decodeACSuccessive(component, offset) {
  14959. var k = spectralStart;
  14960. var e = spectralEnd;
  14961. var r = 0;
  14962. var s;
  14963. var rs;
  14964. while (k <= e) {
  14965. var z = dctZigZag[k];
  14966. switch (successiveACState) {
  14967. case 0:
  14968. // initial state
  14969. rs = decodeHuffman(component.huffmanTableAC);
  14970. s = rs & 15;
  14971. r = rs >> 4;
  14972. if (s === 0) {
  14973. if (r < 15) {
  14974. eobrun = receive(r) + (1 << r);
  14975. successiveACState = 4;
  14976. } else {
  14977. r = 16;
  14978. successiveACState = 1;
  14979. }
  14980. } else {
  14981. if (s !== 1) {
  14982. error('JPEG error: invalid ACn encoding');
  14983. }
  14984. successiveACNextValue = receiveAndExtend(s);
  14985. successiveACState = r ? 2 : 3;
  14986. }
  14987. continue;
  14988. case 1:
  14989. // skipping r zero items
  14990. case 2:
  14991. if (component.blockData[offset + z]) {
  14992. component.blockData[offset + z] += readBit() << successive;
  14993. } else {
  14994. r--;
  14995. if (r === 0) {
  14996. successiveACState = successiveACState === 2 ? 3 : 0;
  14997. }
  14998. }
  14999. break;
  15000. case 3:
  15001. // set value for a zero item
  15002. if (component.blockData[offset + z]) {
  15003. component.blockData[offset + z] += readBit() << successive;
  15004. } else {
  15005. component.blockData[offset + z] = successiveACNextValue << successive;
  15006. successiveACState = 0;
  15007. }
  15008. break;
  15009. case 4:
  15010. // eob
  15011. if (component.blockData[offset + z]) {
  15012. component.blockData[offset + z] += readBit() << successive;
  15013. }
  15014. break;
  15015. }
  15016. k++;
  15017. }
  15018. if (successiveACState === 4) {
  15019. eobrun--;
  15020. if (eobrun === 0) {
  15021. successiveACState = 0;
  15022. }
  15023. }
  15024. }
  15025. function decodeMcu(component, decode, mcu, row, col) {
  15026. var mcuRow = mcu / mcusPerLine | 0;
  15027. var mcuCol = mcu % mcusPerLine;
  15028. var blockRow = mcuRow * component.v + row;
  15029. var blockCol = mcuCol * component.h + col;
  15030. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  15031. decode(component, offset);
  15032. }
  15033. function decodeBlock(component, decode, mcu) {
  15034. var blockRow = mcu / component.blocksPerLine | 0;
  15035. var blockCol = mcu % component.blocksPerLine;
  15036. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  15037. decode(component, offset);
  15038. }
  15039. var componentsLength = components.length;
  15040. var component, i, j, k, n;
  15041. var decodeFn;
  15042. if (progressive) {
  15043. if (spectralStart === 0) {
  15044. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  15045. } else {
  15046. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  15047. }
  15048. } else {
  15049. decodeFn = decodeBaseline;
  15050. }
  15051. var mcu = 0, marker;
  15052. var mcuExpected;
  15053. if (componentsLength === 1) {
  15054. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  15055. } else {
  15056. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  15057. }
  15058. if (!resetInterval) {
  15059. resetInterval = mcuExpected;
  15060. }
  15061. var h, v;
  15062. while (mcu < mcuExpected) {
  15063. // reset interval stuff
  15064. for (i = 0; i < componentsLength; i++) {
  15065. components[i].pred = 0;
  15066. }
  15067. eobrun = 0;
  15068. if (componentsLength === 1) {
  15069. component = components[0];
  15070. for (n = 0; n < resetInterval; n++) {
  15071. decodeBlock(component, decodeFn, mcu);
  15072. mcu++;
  15073. }
  15074. } else {
  15075. for (n = 0; n < resetInterval; n++) {
  15076. for (i = 0; i < componentsLength; i++) {
  15077. component = components[i];
  15078. h = component.h;
  15079. v = component.v;
  15080. for (j = 0; j < v; j++) {
  15081. for (k = 0; k < h; k++) {
  15082. decodeMcu(component, decodeFn, mcu, j, k);
  15083. }
  15084. }
  15085. }
  15086. mcu++;
  15087. }
  15088. }
  15089. // find marker
  15090. bitsCount = 0;
  15091. marker = data[offset] << 8 | data[offset + 1];
  15092. // Some bad images seem to pad Scan blocks with zero bytes, skip past
  15093. // those to attempt to find a valid marker (fixes issue4090.pdf).
  15094. while (data[offset] === 0x00 && offset < data.length - 1) {
  15095. offset++;
  15096. marker = data[offset] << 8 | data[offset + 1];
  15097. }
  15098. if (marker <= 0xFF00) {
  15099. error('JPEG error: marker was not found');
  15100. }
  15101. if (marker >= 0xFFD0 && marker <= 0xFFD7) {
  15102. // RSTx
  15103. offset += 2;
  15104. } else {
  15105. break;
  15106. }
  15107. }
  15108. return offset - startOffset;
  15109. }
  15110. // A port of poppler's IDCT method which in turn is taken from:
  15111. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  15112. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  15113. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  15114. // 988-991.
  15115. function quantizeAndInverse(component, blockBufferOffset, p) {
  15116. var qt = component.quantizationTable, blockData = component.blockData;
  15117. var v0, v1, v2, v3, v4, v5, v6, v7;
  15118. var p0, p1, p2, p3, p4, p5, p6, p7;
  15119. var t;
  15120. if (!qt) {
  15121. error('JPEG error: missing required Quantization Table.');
  15122. }
  15123. // inverse DCT on rows
  15124. for (var row = 0; row < 64; row += 8) {
  15125. // gather block data
  15126. p0 = blockData[blockBufferOffset + row];
  15127. p1 = blockData[blockBufferOffset + row + 1];
  15128. p2 = blockData[blockBufferOffset + row + 2];
  15129. p3 = blockData[blockBufferOffset + row + 3];
  15130. p4 = blockData[blockBufferOffset + row + 4];
  15131. p5 = blockData[blockBufferOffset + row + 5];
  15132. p6 = blockData[blockBufferOffset + row + 6];
  15133. p7 = blockData[blockBufferOffset + row + 7];
  15134. // dequant p0
  15135. p0 *= qt[row];
  15136. // check for all-zero AC coefficients
  15137. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  15138. t = dctSqrt2 * p0 + 512 >> 10;
  15139. p[row] = t;
  15140. p[row + 1] = t;
  15141. p[row + 2] = t;
  15142. p[row + 3] = t;
  15143. p[row + 4] = t;
  15144. p[row + 5] = t;
  15145. p[row + 6] = t;
  15146. p[row + 7] = t;
  15147. continue;
  15148. }
  15149. // dequant p1 ... p7
  15150. p1 *= qt[row + 1];
  15151. p2 *= qt[row + 2];
  15152. p3 *= qt[row + 3];
  15153. p4 *= qt[row + 4];
  15154. p5 *= qt[row + 5];
  15155. p6 *= qt[row + 6];
  15156. p7 *= qt[row + 7];
  15157. // stage 4
  15158. v0 = dctSqrt2 * p0 + 128 >> 8;
  15159. v1 = dctSqrt2 * p4 + 128 >> 8;
  15160. v2 = p2;
  15161. v3 = p6;
  15162. v4 = dctSqrt1d2 * (p1 - p7) + 128 >> 8;
  15163. v7 = dctSqrt1d2 * (p1 + p7) + 128 >> 8;
  15164. v5 = p3 << 4;
  15165. v6 = p5 << 4;
  15166. // stage 3
  15167. v0 = v0 + v1 + 1 >> 1;
  15168. v1 = v0 - v1;
  15169. t = v2 * dctSin6 + v3 * dctCos6 + 128 >> 8;
  15170. v2 = v2 * dctCos6 - v3 * dctSin6 + 128 >> 8;
  15171. v3 = t;
  15172. v4 = v4 + v6 + 1 >> 1;
  15173. v6 = v4 - v6;
  15174. v7 = v7 + v5 + 1 >> 1;
  15175. v5 = v7 - v5;
  15176. // stage 2
  15177. v0 = v0 + v3 + 1 >> 1;
  15178. v3 = v0 - v3;
  15179. v1 = v1 + v2 + 1 >> 1;
  15180. v2 = v1 - v2;
  15181. t = v4 * dctSin3 + v7 * dctCos3 + 2048 >> 12;
  15182. v4 = v4 * dctCos3 - v7 * dctSin3 + 2048 >> 12;
  15183. v7 = t;
  15184. t = v5 * dctSin1 + v6 * dctCos1 + 2048 >> 12;
  15185. v5 = v5 * dctCos1 - v6 * dctSin1 + 2048 >> 12;
  15186. v6 = t;
  15187. // stage 1
  15188. p[row] = v0 + v7;
  15189. p[row + 7] = v0 - v7;
  15190. p[row + 1] = v1 + v6;
  15191. p[row + 6] = v1 - v6;
  15192. p[row + 2] = v2 + v5;
  15193. p[row + 5] = v2 - v5;
  15194. p[row + 3] = v3 + v4;
  15195. p[row + 4] = v3 - v4;
  15196. }
  15197. // inverse DCT on columns
  15198. for (var col = 0; col < 8; ++col) {
  15199. p0 = p[col];
  15200. p1 = p[col + 8];
  15201. p2 = p[col + 16];
  15202. p3 = p[col + 24];
  15203. p4 = p[col + 32];
  15204. p5 = p[col + 40];
  15205. p6 = p[col + 48];
  15206. p7 = p[col + 56];
  15207. // check for all-zero AC coefficients
  15208. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  15209. t = dctSqrt2 * p0 + 8192 >> 14;
  15210. // convert to 8 bit
  15211. t = t < -2040 ? 0 : t >= 2024 ? 255 : t + 2056 >> 4;
  15212. blockData[blockBufferOffset + col] = t;
  15213. blockData[blockBufferOffset + col + 8] = t;
  15214. blockData[blockBufferOffset + col + 16] = t;
  15215. blockData[blockBufferOffset + col + 24] = t;
  15216. blockData[blockBufferOffset + col + 32] = t;
  15217. blockData[blockBufferOffset + col + 40] = t;
  15218. blockData[blockBufferOffset + col + 48] = t;
  15219. blockData[blockBufferOffset + col + 56] = t;
  15220. continue;
  15221. }
  15222. // stage 4
  15223. v0 = dctSqrt2 * p0 + 2048 >> 12;
  15224. v1 = dctSqrt2 * p4 + 2048 >> 12;
  15225. v2 = p2;
  15226. v3 = p6;
  15227. v4 = dctSqrt1d2 * (p1 - p7) + 2048 >> 12;
  15228. v7 = dctSqrt1d2 * (p1 + p7) + 2048 >> 12;
  15229. v5 = p3;
  15230. v6 = p5;
  15231. // stage 3
  15232. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  15233. // converting to UInt8 range later.
  15234. v0 = (v0 + v1 + 1 >> 1) + 4112;
  15235. v1 = v0 - v1;
  15236. t = v2 * dctSin6 + v3 * dctCos6 + 2048 >> 12;
  15237. v2 = v2 * dctCos6 - v3 * dctSin6 + 2048 >> 12;
  15238. v3 = t;
  15239. v4 = v4 + v6 + 1 >> 1;
  15240. v6 = v4 - v6;
  15241. v7 = v7 + v5 + 1 >> 1;
  15242. v5 = v7 - v5;
  15243. // stage 2
  15244. v0 = v0 + v3 + 1 >> 1;
  15245. v3 = v0 - v3;
  15246. v1 = v1 + v2 + 1 >> 1;
  15247. v2 = v1 - v2;
  15248. t = v4 * dctSin3 + v7 * dctCos3 + 2048 >> 12;
  15249. v4 = v4 * dctCos3 - v7 * dctSin3 + 2048 >> 12;
  15250. v7 = t;
  15251. t = v5 * dctSin1 + v6 * dctCos1 + 2048 >> 12;
  15252. v5 = v5 * dctCos1 - v6 * dctSin1 + 2048 >> 12;
  15253. v6 = t;
  15254. // stage 1
  15255. p0 = v0 + v7;
  15256. p7 = v0 - v7;
  15257. p1 = v1 + v6;
  15258. p6 = v1 - v6;
  15259. p2 = v2 + v5;
  15260. p5 = v2 - v5;
  15261. p3 = v3 + v4;
  15262. p4 = v3 - v4;
  15263. // convert to 8-bit integers
  15264. p0 = p0 < 16 ? 0 : p0 >= 4080 ? 255 : p0 >> 4;
  15265. p1 = p1 < 16 ? 0 : p1 >= 4080 ? 255 : p1 >> 4;
  15266. p2 = p2 < 16 ? 0 : p2 >= 4080 ? 255 : p2 >> 4;
  15267. p3 = p3 < 16 ? 0 : p3 >= 4080 ? 255 : p3 >> 4;
  15268. p4 = p4 < 16 ? 0 : p4 >= 4080 ? 255 : p4 >> 4;
  15269. p5 = p5 < 16 ? 0 : p5 >= 4080 ? 255 : p5 >> 4;
  15270. p6 = p6 < 16 ? 0 : p6 >= 4080 ? 255 : p6 >> 4;
  15271. p7 = p7 < 16 ? 0 : p7 >= 4080 ? 255 : p7 >> 4;
  15272. // store block data
  15273. blockData[blockBufferOffset + col] = p0;
  15274. blockData[blockBufferOffset + col + 8] = p1;
  15275. blockData[blockBufferOffset + col + 16] = p2;
  15276. blockData[blockBufferOffset + col + 24] = p3;
  15277. blockData[blockBufferOffset + col + 32] = p4;
  15278. blockData[blockBufferOffset + col + 40] = p5;
  15279. blockData[blockBufferOffset + col + 48] = p6;
  15280. blockData[blockBufferOffset + col + 56] = p7;
  15281. }
  15282. }
  15283. function buildComponentData(frame, component) {
  15284. var blocksPerLine = component.blocksPerLine;
  15285. var blocksPerColumn = component.blocksPerColumn;
  15286. var computationBuffer = new Int16Array(64);
  15287. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  15288. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  15289. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  15290. quantizeAndInverse(component, offset, computationBuffer);
  15291. }
  15292. }
  15293. return component.blockData;
  15294. }
  15295. function clamp0to255(a) {
  15296. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  15297. }
  15298. JpegImage.prototype = {
  15299. parse: function parse(data) {
  15300. function readUint16() {
  15301. var value = data[offset] << 8 | data[offset + 1];
  15302. offset += 2;
  15303. return value;
  15304. }
  15305. function readDataBlock() {
  15306. var length = readUint16();
  15307. var array = data.subarray(offset, offset + length - 2);
  15308. offset += array.length;
  15309. return array;
  15310. }
  15311. function prepareComponents(frame) {
  15312. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  15313. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  15314. for (var i = 0; i < frame.components.length; i++) {
  15315. component = frame.components[i];
  15316. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) * component.h / frame.maxH);
  15317. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) * component.v / frame.maxV);
  15318. var blocksPerLineForMcu = mcusPerLine * component.h;
  15319. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  15320. var blocksBufferSize = 64 * blocksPerColumnForMcu * (blocksPerLineForMcu + 1);
  15321. component.blockData = new Int16Array(blocksBufferSize);
  15322. component.blocksPerLine = blocksPerLine;
  15323. component.blocksPerColumn = blocksPerColumn;
  15324. }
  15325. frame.mcusPerLine = mcusPerLine;
  15326. frame.mcusPerColumn = mcusPerColumn;
  15327. }
  15328. var offset = 0;
  15329. var jfif = null;
  15330. var adobe = null;
  15331. var frame, resetInterval;
  15332. var quantizationTables = [];
  15333. var huffmanTablesAC = [], huffmanTablesDC = [];
  15334. var fileMarker = readUint16();
  15335. if (fileMarker !== 0xFFD8) {
  15336. // SOI (Start of Image)
  15337. error('JPEG error: SOI not found');
  15338. }
  15339. fileMarker = readUint16();
  15340. while (fileMarker !== 0xFFD9) {
  15341. // EOI (End of image)
  15342. var i, j, l;
  15343. switch (fileMarker) {
  15344. case 0xFFE0:
  15345. // APP0 (Application Specific)
  15346. case 0xFFE1:
  15347. // APP1
  15348. case 0xFFE2:
  15349. // APP2
  15350. case 0xFFE3:
  15351. // APP3
  15352. case 0xFFE4:
  15353. // APP4
  15354. case 0xFFE5:
  15355. // APP5
  15356. case 0xFFE6:
  15357. // APP6
  15358. case 0xFFE7:
  15359. // APP7
  15360. case 0xFFE8:
  15361. // APP8
  15362. case 0xFFE9:
  15363. // APP9
  15364. case 0xFFEA:
  15365. // APP10
  15366. case 0xFFEB:
  15367. // APP11
  15368. case 0xFFEC:
  15369. // APP12
  15370. case 0xFFED:
  15371. // APP13
  15372. case 0xFFEE:
  15373. // APP14
  15374. case 0xFFEF:
  15375. // APP15
  15376. case 0xFFFE:
  15377. // COM (Comment)
  15378. var appData = readDataBlock();
  15379. if (fileMarker === 0xFFE0) {
  15380. if (appData[0] === 0x4A && appData[1] === 0x46 && appData[2] === 0x49 && appData[3] === 0x46 && appData[4] === 0) {
  15381. // 'JFIF\x00'
  15382. jfif = {
  15383. version: {
  15384. major: appData[5],
  15385. minor: appData[6]
  15386. },
  15387. densityUnits: appData[7],
  15388. xDensity: appData[8] << 8 | appData[9],
  15389. yDensity: appData[10] << 8 | appData[11],
  15390. thumbWidth: appData[12],
  15391. thumbHeight: appData[13],
  15392. thumbData: appData.subarray(14, 14 + 3 * appData[12] * appData[13])
  15393. };
  15394. }
  15395. }
  15396. // TODO APP1 - Exif
  15397. if (fileMarker === 0xFFEE) {
  15398. if (appData[0] === 0x41 && appData[1] === 0x64 && appData[2] === 0x6F && appData[3] === 0x62 && appData[4] === 0x65) {
  15399. // 'Adobe'
  15400. adobe = {
  15401. version: appData[5] << 8 | appData[6],
  15402. flags0: appData[7] << 8 | appData[8],
  15403. flags1: appData[9] << 8 | appData[10],
  15404. transformCode: appData[11]
  15405. };
  15406. }
  15407. }
  15408. break;
  15409. case 0xFFDB:
  15410. // DQT (Define Quantization Tables)
  15411. var quantizationTablesLength = readUint16();
  15412. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  15413. var z;
  15414. while (offset < quantizationTablesEnd) {
  15415. var quantizationTableSpec = data[offset++];
  15416. var tableData = new Uint16Array(64);
  15417. if (quantizationTableSpec >> 4 === 0) {
  15418. // 8 bit values
  15419. for (j = 0; j < 64; j++) {
  15420. z = dctZigZag[j];
  15421. tableData[z] = data[offset++];
  15422. }
  15423. } else if (quantizationTableSpec >> 4 === 1) {
  15424. //16 bit
  15425. for (j = 0; j < 64; j++) {
  15426. z = dctZigZag[j];
  15427. tableData[z] = readUint16();
  15428. }
  15429. } else {
  15430. error('JPEG error: DQT - invalid table spec');
  15431. }
  15432. quantizationTables[quantizationTableSpec & 15] = tableData;
  15433. }
  15434. break;
  15435. case 0xFFC0:
  15436. // SOF0 (Start of Frame, Baseline DCT)
  15437. case 0xFFC1:
  15438. // SOF1 (Start of Frame, Extended DCT)
  15439. case 0xFFC2:
  15440. // SOF2 (Start of Frame, Progressive DCT)
  15441. if (frame) {
  15442. error('JPEG error: Only single frame JPEGs supported');
  15443. }
  15444. readUint16();
  15445. // skip data length
  15446. frame = {};
  15447. frame.extended = fileMarker === 0xFFC1;
  15448. frame.progressive = fileMarker === 0xFFC2;
  15449. frame.precision = data[offset++];
  15450. frame.scanLines = readUint16();
  15451. frame.samplesPerLine = readUint16();
  15452. frame.components = [];
  15453. frame.componentIds = {};
  15454. var componentsCount = data[offset++], componentId;
  15455. var maxH = 0, maxV = 0;
  15456. for (i = 0; i < componentsCount; i++) {
  15457. componentId = data[offset];
  15458. var h = data[offset + 1] >> 4;
  15459. var v = data[offset + 1] & 15;
  15460. if (maxH < h) {
  15461. maxH = h;
  15462. }
  15463. if (maxV < v) {
  15464. maxV = v;
  15465. }
  15466. var qId = data[offset + 2];
  15467. l = frame.components.push({
  15468. h: h,
  15469. v: v,
  15470. quantizationId: qId,
  15471. quantizationTable: null
  15472. });
  15473. // See comment below.
  15474. frame.componentIds[componentId] = l - 1;
  15475. offset += 3;
  15476. }
  15477. frame.maxH = maxH;
  15478. frame.maxV = maxV;
  15479. prepareComponents(frame);
  15480. break;
  15481. case 0xFFC4:
  15482. // DHT (Define Huffman Tables)
  15483. var huffmanLength = readUint16();
  15484. for (i = 2; i < huffmanLength;) {
  15485. var huffmanTableSpec = data[offset++];
  15486. var codeLengths = new Uint8Array(16);
  15487. var codeLengthSum = 0;
  15488. for (j = 0; j < 16; j++, offset++) {
  15489. codeLengthSum += codeLengths[j] = data[offset];
  15490. }
  15491. var huffmanValues = new Uint8Array(codeLengthSum);
  15492. for (j = 0; j < codeLengthSum; j++, offset++) {
  15493. huffmanValues[j] = data[offset];
  15494. }
  15495. i += 17 + codeLengthSum;
  15496. (huffmanTableSpec >> 4 === 0 ? huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] = buildHuffmanTable(codeLengths, huffmanValues);
  15497. }
  15498. break;
  15499. case 0xFFDD:
  15500. // DRI (Define Restart Interval)
  15501. readUint16();
  15502. // skip data length
  15503. resetInterval = readUint16();
  15504. break;
  15505. case 0xFFDA:
  15506. // SOS (Start of Scan)
  15507. var scanLength = readUint16();
  15508. var selectorsCount = data[offset++];
  15509. var components = [], component;
  15510. for (i = 0; i < selectorsCount; i++) {
  15511. var componentIndex = frame.componentIds[data[offset++]];
  15512. component = frame.components[componentIndex];
  15513. var tableSpec = data[offset++];
  15514. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  15515. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  15516. components.push(component);
  15517. }
  15518. var spectralStart = data[offset++];
  15519. var spectralEnd = data[offset++];
  15520. var successiveApproximation = data[offset++];
  15521. var processed = decodeScan(data, offset, frame, components, resetInterval, spectralStart, spectralEnd, successiveApproximation >> 4, successiveApproximation & 15);
  15522. offset += processed;
  15523. break;
  15524. case 0xFFFF:
  15525. // Fill bytes
  15526. if (data[offset] !== 0xFF) {
  15527. // Avoid skipping a valid marker.
  15528. offset--;
  15529. }
  15530. break;
  15531. default:
  15532. if (data[offset - 3] === 0xFF && data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  15533. // could be incorrect encoding -- last 0xFF byte of the previous
  15534. // block was eaten by the encoder
  15535. offset -= 3;
  15536. break;
  15537. }
  15538. error('JPEG error: unknown marker ' + fileMarker.toString(16));
  15539. }
  15540. fileMarker = readUint16();
  15541. }
  15542. this.width = frame.samplesPerLine;
  15543. this.height = frame.scanLines;
  15544. this.jfif = jfif;
  15545. this.adobe = adobe;
  15546. this.components = [];
  15547. for (i = 0; i < frame.components.length; i++) {
  15548. component = frame.components[i];
  15549. // Prevent errors when DQT markers are placed after SOF{n} markers,
  15550. // by assigning the `quantizationTable` entry after the entire image
  15551. // has been parsed (fixes issue7406.pdf).
  15552. var quantizationTable = quantizationTables[component.quantizationId];
  15553. if (quantizationTable) {
  15554. component.quantizationTable = quantizationTable;
  15555. }
  15556. this.components.push({
  15557. output: buildComponentData(frame, component),
  15558. scaleX: component.h / frame.maxH,
  15559. scaleY: component.v / frame.maxV,
  15560. blocksPerLine: component.blocksPerLine,
  15561. blocksPerColumn: component.blocksPerColumn
  15562. });
  15563. }
  15564. this.numComponents = this.components.length;
  15565. },
  15566. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  15567. var scaleX = this.width / width, scaleY = this.height / height;
  15568. var component, componentScaleX, componentScaleY, blocksPerScanline;
  15569. var x, y, i, j, k;
  15570. var index;
  15571. var offset = 0;
  15572. var output;
  15573. var numComponents = this.components.length;
  15574. var dataLength = width * height * numComponents;
  15575. var data = new Uint8Array(dataLength);
  15576. var xScaleBlockOffset = new Uint32Array(width);
  15577. var mask3LSB = 0xfffffff8;
  15578. // used to clear the 3 LSBs
  15579. for (i = 0; i < numComponents; i++) {
  15580. component = this.components[i];
  15581. componentScaleX = component.scaleX * scaleX;
  15582. componentScaleY = component.scaleY * scaleY;
  15583. offset = i;
  15584. output = component.output;
  15585. blocksPerScanline = component.blocksPerLine + 1 << 3;
  15586. // precalculate the xScaleBlockOffset
  15587. for (x = 0; x < width; x++) {
  15588. j = 0 | x * componentScaleX;
  15589. xScaleBlockOffset[x] = (j & mask3LSB) << 3 | j & 7;
  15590. }
  15591. // linearize the blocks of the component
  15592. for (y = 0; y < height; y++) {
  15593. j = 0 | y * componentScaleY;
  15594. index = blocksPerScanline * (j & mask3LSB) | (j & 7) << 3;
  15595. for (x = 0; x < width; x++) {
  15596. data[offset] = output[index + xScaleBlockOffset[x]];
  15597. offset += numComponents;
  15598. }
  15599. }
  15600. }
  15601. // decodeTransform contains pairs of multiplier (-256..256) and additive
  15602. var transform = this.decodeTransform;
  15603. if (transform) {
  15604. for (i = 0; i < dataLength;) {
  15605. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  15606. data[i] = (data[i] * transform[k] >> 8) + transform[k + 1];
  15607. }
  15608. }
  15609. }
  15610. return data;
  15611. },
  15612. _isColorConversionNeeded: function isColorConversionNeeded() {
  15613. if (this.adobe && this.adobe.transformCode) {
  15614. // The adobe transform marker overrides any previous setting
  15615. return true;
  15616. } else if (this.numComponents === 3) {
  15617. if (!this.adobe && this.colorTransform === 0) {
  15618. // If the Adobe transform marker is not present and the image
  15619. // dictionary has a 'ColorTransform' entry, explicitly set to `0`,
  15620. // then the colours should *not* be transformed.
  15621. return false;
  15622. }
  15623. return true;
  15624. } else {
  15625. // `this.numComponents !== 3`
  15626. if (!this.adobe && this.colorTransform === 1) {
  15627. // If the Adobe transform marker is not present and the image
  15628. // dictionary has a 'ColorTransform' entry, explicitly set to `1`,
  15629. // then the colours should be transformed.
  15630. return true;
  15631. }
  15632. return false;
  15633. }
  15634. },
  15635. _convertYccToRgb: function convertYccToRgb(data) {
  15636. var Y, Cb, Cr;
  15637. for (var i = 0, length = data.length; i < length; i += 3) {
  15638. Y = data[i];
  15639. Cb = data[i + 1];
  15640. Cr = data[i + 2];
  15641. data[i] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  15642. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  15643. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  15644. }
  15645. return data;
  15646. },
  15647. _convertYcckToRgb: function convertYcckToRgb(data) {
  15648. var Y, Cb, Cr, k;
  15649. var offset = 0;
  15650. for (var i = 0, length = data.length; i < length; i += 4) {
  15651. Y = data[i];
  15652. Cb = data[i + 1];
  15653. Cr = data[i + 2];
  15654. k = data[i + 3];
  15655. var r = -122.67195406894 + Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr - 5.4080610064599e-5 * Y + 0.00048449797120281 * k - 0.154362151871126) + Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y - 0.00477271405408747 * k + 1.53380253221734) + Y * (0.000961250184130688 * Y - 0.00266257332283933 * k + 0.48357088451265) + k * (-0.000336197177618394 * k + 0.484791561490776);
  15656. var g = 107.268039397724 + Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr + 0.000659397001245577 * Y + 0.000426105652938837 * k - 0.176491792462875) + Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y + 0.000770482631801132 * k - 0.151051492775562) + Y * (0.00126935368114843 * Y - 0.00265090189010898 * k + 0.25802910206845) + k * (-0.000318913117588328 * k - 0.213742400323665);
  15657. var b = -20.810012546947 + Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr + 0.0020741088115012 * Y - 0.00288260236853442 * k + 0.814272968359295) + Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y + 0.000560833691242812 * k - 0.195152027534049) + Y * (0.00174418132927582 * Y - 0.00255243321439347 * k + 0.116935020465145) + k * (-0.000343531996510555 * k + 0.24165260232407);
  15658. data[offset++] = clamp0to255(r);
  15659. data[offset++] = clamp0to255(g);
  15660. data[offset++] = clamp0to255(b);
  15661. }
  15662. return data;
  15663. },
  15664. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  15665. var Y, Cb, Cr;
  15666. for (var i = 0, length = data.length; i < length; i += 4) {
  15667. Y = data[i];
  15668. Cb = data[i + 1];
  15669. Cr = data[i + 2];
  15670. data[i] = clamp0to255(434.456 - Y - 1.402 * Cr);
  15671. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  15672. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  15673. }
  15674. // K in data[i + 3] is unchanged
  15675. return data;
  15676. },
  15677. _convertCmykToRgb: function convertCmykToRgb(data) {
  15678. var c, m, y, k;
  15679. var offset = 0;
  15680. var min = -255 * 255 * 255;
  15681. var scale = 1 / 255 / 255;
  15682. for (var i = 0, length = data.length; i < length; i += 4) {
  15683. c = data[i];
  15684. m = data[i + 1];
  15685. y = data[i + 2];
  15686. k = data[i + 3];
  15687. var r = c * (-4.387332384609988 * c + 54.48615194189176 * m + 18.82290502165302 * y + 212.25662451639585 * k - 72734.4411664936) + m * (1.7149763477362134 * m - 5.6096736904047315 * y - 17.873870861415444 * k - 1401.7366389350734) + y * (-2.5217340131683033 * y - 21.248923337353073 * k + 4465.541406466231) - k * (21.86122147463605 * k + 48317.86113160301);
  15688. var g = c * (8.841041422036149 * c + 60.118027045597366 * m + 6.871425592049007 * y + 31.159100130055922 * k - 20220.756542821975) + m * (-15.310361306967817 * m + 17.575251261109482 * y + 131.35250912493976 * k - 48691.05921601825) + y * (4.444339102852739 * y + 9.8632861493405 * k - 6341.191035517494) - k * (20.737325471181034 * k + 47890.15695978492);
  15689. var b = c * (0.8842522430003296 * c + 8.078677503112928 * m + 30.89978309703729 * y - 0.23883238689178934 * k - 3616.812083916688) + m * (10.49593273432072 * m + 63.02378494754052 * y + 50.606957656360734 * k - 28620.90484698408) + y * (0.03296041114873217 * y + 115.60384449646641 * k - 49363.43385999684) - k * (22.33816807309886 * k + 45932.16563550634);
  15690. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  15691. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  15692. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  15693. }
  15694. return data;
  15695. },
  15696. getData: function getData(width, height, forceRGBoutput) {
  15697. if (this.numComponents > 4) {
  15698. error('JPEG error: Unsupported color mode');
  15699. }
  15700. // type of data: Uint8Array(width * height * numComponents)
  15701. var data = this._getLinearizedBlockData(width, height);
  15702. if (this.numComponents === 1 && forceRGBoutput) {
  15703. var dataLength = data.length;
  15704. var rgbData = new Uint8Array(dataLength * 3);
  15705. var offset = 0;
  15706. for (var i = 0; i < dataLength; i++) {
  15707. var grayColor = data[i];
  15708. rgbData[offset++] = grayColor;
  15709. rgbData[offset++] = grayColor;
  15710. rgbData[offset++] = grayColor;
  15711. }
  15712. return rgbData;
  15713. } else if (this.numComponents === 3 && this._isColorConversionNeeded()) {
  15714. return this._convertYccToRgb(data);
  15715. } else if (this.numComponents === 4) {
  15716. if (this._isColorConversionNeeded()) {
  15717. if (forceRGBoutput) {
  15718. return this._convertYcckToRgb(data);
  15719. } else {
  15720. return this._convertYcckToCmyk(data);
  15721. }
  15722. } else if (forceRGBoutput) {
  15723. return this._convertCmykToRgb(data);
  15724. }
  15725. }
  15726. return data;
  15727. }
  15728. };
  15729. return JpegImage;
  15730. }();
  15731. exports.JpegImage = JpegImage;
  15732. }));
  15733. (function (root, factory) {
  15734. factory(root.pdfjsCoreJpx = {}, root.pdfjsSharedUtil, root.pdfjsCoreArithmeticDecoder);
  15735. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  15736. var info = sharedUtil.info;
  15737. var warn = sharedUtil.warn;
  15738. var error = sharedUtil.error;
  15739. var log2 = sharedUtil.log2;
  15740. var readUint16 = sharedUtil.readUint16;
  15741. var readUint32 = sharedUtil.readUint32;
  15742. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  15743. var JpxImage = function JpxImageClosure() {
  15744. // Table E.1
  15745. var SubbandsGainLog2 = {
  15746. 'LL': 0,
  15747. 'LH': 1,
  15748. 'HL': 1,
  15749. 'HH': 2
  15750. };
  15751. function JpxImage() {
  15752. this.failOnCorruptedImage = false;
  15753. }
  15754. JpxImage.prototype = {
  15755. parse: function JpxImage_parse(data) {
  15756. var head = readUint16(data, 0);
  15757. // No box header, immediate start of codestream (SOC)
  15758. if (head === 0xFF4F) {
  15759. this.parseCodestream(data, 0, data.length);
  15760. return;
  15761. }
  15762. var position = 0, length = data.length;
  15763. while (position < length) {
  15764. var headerSize = 8;
  15765. var lbox = readUint32(data, position);
  15766. var tbox = readUint32(data, position + 4);
  15767. position += headerSize;
  15768. if (lbox === 1) {
  15769. // XLBox: read UInt64 according to spec.
  15770. // JavaScript's int precision of 53 bit should be sufficient here.
  15771. lbox = readUint32(data, position) * 4294967296 + readUint32(data, position + 4);
  15772. position += 8;
  15773. headerSize += 8;
  15774. }
  15775. if (lbox === 0) {
  15776. lbox = length - position + headerSize;
  15777. }
  15778. if (lbox < headerSize) {
  15779. error('JPX Error: Invalid box field size');
  15780. }
  15781. var dataLength = lbox - headerSize;
  15782. var jumpDataLength = true;
  15783. switch (tbox) {
  15784. case 0x6A703268:
  15785. // 'jp2h'
  15786. jumpDataLength = false;
  15787. // parsing child boxes
  15788. break;
  15789. case 0x636F6C72:
  15790. // 'colr'
  15791. // Colorspaces are not used, the CS from the PDF is used.
  15792. var method = data[position];
  15793. if (method === 1) {
  15794. // enumerated colorspace
  15795. var colorspace = readUint32(data, position + 3);
  15796. switch (colorspace) {
  15797. case 16:
  15798. // this indicates a sRGB colorspace
  15799. case 17:
  15800. // this indicates a grayscale colorspace
  15801. case 18:
  15802. // this indicates a YUV colorspace
  15803. break;
  15804. default:
  15805. warn('Unknown colorspace ' + colorspace);
  15806. break;
  15807. }
  15808. } else if (method === 2) {
  15809. info('ICC profile not supported');
  15810. }
  15811. break;
  15812. case 0x6A703263:
  15813. // 'jp2c'
  15814. this.parseCodestream(data, position, position + dataLength);
  15815. break;
  15816. case 0x6A502020:
  15817. // 'jP\024\024'
  15818. if (0x0d0a870a !== readUint32(data, position)) {
  15819. warn('Invalid JP2 signature');
  15820. }
  15821. break;
  15822. // The following header types are valid but currently not used:
  15823. case 0x6A501A1A:
  15824. // 'jP\032\032'
  15825. case 0x66747970:
  15826. // 'ftyp'
  15827. case 0x72726571:
  15828. // 'rreq'
  15829. case 0x72657320:
  15830. // 'res '
  15831. case 0x69686472:
  15832. // 'ihdr'
  15833. break;
  15834. default:
  15835. var headerType = String.fromCharCode(tbox >> 24 & 0xFF, tbox >> 16 & 0xFF, tbox >> 8 & 0xFF, tbox & 0xFF);
  15836. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  15837. break;
  15838. }
  15839. if (jumpDataLength) {
  15840. position += dataLength;
  15841. }
  15842. }
  15843. },
  15844. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  15845. var newByte = stream.getByte();
  15846. while (newByte >= 0) {
  15847. var oldByte = newByte;
  15848. newByte = stream.getByte();
  15849. var code = oldByte << 8 | newByte;
  15850. // Image and tile size (SIZ)
  15851. if (code === 0xFF51) {
  15852. stream.skip(4);
  15853. var Xsiz = stream.getInt32() >>> 0;
  15854. // Byte 4
  15855. var Ysiz = stream.getInt32() >>> 0;
  15856. // Byte 8
  15857. var XOsiz = stream.getInt32() >>> 0;
  15858. // Byte 12
  15859. var YOsiz = stream.getInt32() >>> 0;
  15860. // Byte 16
  15861. stream.skip(16);
  15862. var Csiz = stream.getUint16();
  15863. // Byte 36
  15864. this.width = Xsiz - XOsiz;
  15865. this.height = Ysiz - YOsiz;
  15866. this.componentsCount = Csiz;
  15867. // Results are always returned as Uint8Arrays
  15868. this.bitsPerComponent = 8;
  15869. return;
  15870. }
  15871. }
  15872. error('JPX Error: No size marker found in JPX stream');
  15873. },
  15874. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  15875. var context = {};
  15876. var doNotRecover = false;
  15877. try {
  15878. var position = start;
  15879. while (position + 1 < end) {
  15880. var code = readUint16(data, position);
  15881. position += 2;
  15882. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  15883. switch (code) {
  15884. case 0xFF4F:
  15885. // Start of codestream (SOC)
  15886. context.mainHeader = true;
  15887. break;
  15888. case 0xFFD9:
  15889. // End of codestream (EOC)
  15890. break;
  15891. case 0xFF51:
  15892. // Image and tile size (SIZ)
  15893. length = readUint16(data, position);
  15894. var siz = {};
  15895. siz.Xsiz = readUint32(data, position + 4);
  15896. siz.Ysiz = readUint32(data, position + 8);
  15897. siz.XOsiz = readUint32(data, position + 12);
  15898. siz.YOsiz = readUint32(data, position + 16);
  15899. siz.XTsiz = readUint32(data, position + 20);
  15900. siz.YTsiz = readUint32(data, position + 24);
  15901. siz.XTOsiz = readUint32(data, position + 28);
  15902. siz.YTOsiz = readUint32(data, position + 32);
  15903. var componentsCount = readUint16(data, position + 36);
  15904. siz.Csiz = componentsCount;
  15905. var components = [];
  15906. j = position + 38;
  15907. for (var i = 0; i < componentsCount; i++) {
  15908. var component = {
  15909. precision: (data[j] & 0x7F) + 1,
  15910. isSigned: !!(data[j] & 0x80),
  15911. XRsiz: data[j + 1],
  15912. YRsiz: data[j + 1]
  15913. };
  15914. calculateComponentDimensions(component, siz);
  15915. components.push(component);
  15916. }
  15917. context.SIZ = siz;
  15918. context.components = components;
  15919. calculateTileGrids(context, components);
  15920. context.QCC = [];
  15921. context.COC = [];
  15922. break;
  15923. case 0xFF5C:
  15924. // Quantization default (QCD)
  15925. length = readUint16(data, position);
  15926. var qcd = {};
  15927. j = position + 2;
  15928. sqcd = data[j++];
  15929. switch (sqcd & 0x1F) {
  15930. case 0:
  15931. spqcdSize = 8;
  15932. scalarExpounded = true;
  15933. break;
  15934. case 1:
  15935. spqcdSize = 16;
  15936. scalarExpounded = false;
  15937. break;
  15938. case 2:
  15939. spqcdSize = 16;
  15940. scalarExpounded = true;
  15941. break;
  15942. default:
  15943. throw new Error('Invalid SQcd value ' + sqcd);
  15944. }
  15945. qcd.noQuantization = spqcdSize === 8;
  15946. qcd.scalarExpounded = scalarExpounded;
  15947. qcd.guardBits = sqcd >> 5;
  15948. spqcds = [];
  15949. while (j < length + position) {
  15950. var spqcd = {};
  15951. if (spqcdSize === 8) {
  15952. spqcd.epsilon = data[j++] >> 3;
  15953. spqcd.mu = 0;
  15954. } else {
  15955. spqcd.epsilon = data[j] >> 3;
  15956. spqcd.mu = (data[j] & 0x7) << 8 | data[j + 1];
  15957. j += 2;
  15958. }
  15959. spqcds.push(spqcd);
  15960. }
  15961. qcd.SPqcds = spqcds;
  15962. if (context.mainHeader) {
  15963. context.QCD = qcd;
  15964. } else {
  15965. context.currentTile.QCD = qcd;
  15966. context.currentTile.QCC = [];
  15967. }
  15968. break;
  15969. case 0xFF5D:
  15970. // Quantization component (QCC)
  15971. length = readUint16(data, position);
  15972. var qcc = {};
  15973. j = position + 2;
  15974. var cqcc;
  15975. if (context.SIZ.Csiz < 257) {
  15976. cqcc = data[j++];
  15977. } else {
  15978. cqcc = readUint16(data, j);
  15979. j += 2;
  15980. }
  15981. sqcd = data[j++];
  15982. switch (sqcd & 0x1F) {
  15983. case 0:
  15984. spqcdSize = 8;
  15985. scalarExpounded = true;
  15986. break;
  15987. case 1:
  15988. spqcdSize = 16;
  15989. scalarExpounded = false;
  15990. break;
  15991. case 2:
  15992. spqcdSize = 16;
  15993. scalarExpounded = true;
  15994. break;
  15995. default:
  15996. throw new Error('Invalid SQcd value ' + sqcd);
  15997. }
  15998. qcc.noQuantization = spqcdSize === 8;
  15999. qcc.scalarExpounded = scalarExpounded;
  16000. qcc.guardBits = sqcd >> 5;
  16001. spqcds = [];
  16002. while (j < length + position) {
  16003. spqcd = {};
  16004. if (spqcdSize === 8) {
  16005. spqcd.epsilon = data[j++] >> 3;
  16006. spqcd.mu = 0;
  16007. } else {
  16008. spqcd.epsilon = data[j] >> 3;
  16009. spqcd.mu = (data[j] & 0x7) << 8 | data[j + 1];
  16010. j += 2;
  16011. }
  16012. spqcds.push(spqcd);
  16013. }
  16014. qcc.SPqcds = spqcds;
  16015. if (context.mainHeader) {
  16016. context.QCC[cqcc] = qcc;
  16017. } else {
  16018. context.currentTile.QCC[cqcc] = qcc;
  16019. }
  16020. break;
  16021. case 0xFF52:
  16022. // Coding style default (COD)
  16023. length = readUint16(data, position);
  16024. var cod = {};
  16025. j = position + 2;
  16026. var scod = data[j++];
  16027. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  16028. cod.sopMarkerUsed = !!(scod & 2);
  16029. cod.ephMarkerUsed = !!(scod & 4);
  16030. cod.progressionOrder = data[j++];
  16031. cod.layersCount = readUint16(data, j);
  16032. j += 2;
  16033. cod.multipleComponentTransform = data[j++];
  16034. cod.decompositionLevelsCount = data[j++];
  16035. cod.xcb = (data[j++] & 0xF) + 2;
  16036. cod.ycb = (data[j++] & 0xF) + 2;
  16037. var blockStyle = data[j++];
  16038. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  16039. cod.resetContextProbabilities = !!(blockStyle & 2);
  16040. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  16041. cod.verticalyStripe = !!(blockStyle & 8);
  16042. cod.predictableTermination = !!(blockStyle & 16);
  16043. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  16044. cod.reversibleTransformation = data[j++];
  16045. if (cod.entropyCoderWithCustomPrecincts) {
  16046. var precinctsSizes = [];
  16047. while (j < length + position) {
  16048. var precinctsSize = data[j++];
  16049. precinctsSizes.push({
  16050. PPx: precinctsSize & 0xF,
  16051. PPy: precinctsSize >> 4
  16052. });
  16053. }
  16054. cod.precinctsSizes = precinctsSizes;
  16055. }
  16056. var unsupported = [];
  16057. if (cod.selectiveArithmeticCodingBypass) {
  16058. unsupported.push('selectiveArithmeticCodingBypass');
  16059. }
  16060. if (cod.resetContextProbabilities) {
  16061. unsupported.push('resetContextProbabilities');
  16062. }
  16063. if (cod.terminationOnEachCodingPass) {
  16064. unsupported.push('terminationOnEachCodingPass');
  16065. }
  16066. if (cod.verticalyStripe) {
  16067. unsupported.push('verticalyStripe');
  16068. }
  16069. if (cod.predictableTermination) {
  16070. unsupported.push('predictableTermination');
  16071. }
  16072. if (unsupported.length > 0) {
  16073. doNotRecover = true;
  16074. throw new Error('Unsupported COD options (' + unsupported.join(', ') + ')');
  16075. }
  16076. if (context.mainHeader) {
  16077. context.COD = cod;
  16078. } else {
  16079. context.currentTile.COD = cod;
  16080. context.currentTile.COC = [];
  16081. }
  16082. break;
  16083. case 0xFF90:
  16084. // Start of tile-part (SOT)
  16085. length = readUint16(data, position);
  16086. tile = {};
  16087. tile.index = readUint16(data, position + 2);
  16088. tile.length = readUint32(data, position + 4);
  16089. tile.dataEnd = tile.length + position - 2;
  16090. tile.partIndex = data[position + 8];
  16091. tile.partsCount = data[position + 9];
  16092. context.mainHeader = false;
  16093. if (tile.partIndex === 0) {
  16094. // reset component specific settings
  16095. tile.COD = context.COD;
  16096. tile.COC = context.COC.slice(0);
  16097. // clone of the global COC
  16098. tile.QCD = context.QCD;
  16099. tile.QCC = context.QCC.slice(0);
  16100. }
  16101. // clone of the global COC
  16102. context.currentTile = tile;
  16103. break;
  16104. case 0xFF93:
  16105. // Start of data (SOD)
  16106. tile = context.currentTile;
  16107. if (tile.partIndex === 0) {
  16108. initializeTile(context, tile.index);
  16109. buildPackets(context);
  16110. }
  16111. // moving to the end of the data
  16112. length = tile.dataEnd - position;
  16113. parseTilePackets(context, data, position, length);
  16114. break;
  16115. case 0xFF55:
  16116. // Tile-part lengths, main header (TLM)
  16117. case 0xFF57:
  16118. // Packet length, main header (PLM)
  16119. case 0xFF58:
  16120. // Packet length, tile-part header (PLT)
  16121. case 0xFF64:
  16122. // Comment (COM)
  16123. length = readUint16(data, position);
  16124. // skipping content
  16125. break;
  16126. case 0xFF53:
  16127. // Coding style component (COC)
  16128. throw new Error('Codestream code 0xFF53 (COC) is ' + 'not implemented');
  16129. default:
  16130. throw new Error('Unknown codestream code: ' + code.toString(16));
  16131. }
  16132. position += length;
  16133. }
  16134. } catch (e) {
  16135. if (doNotRecover || this.failOnCorruptedImage) {
  16136. error('JPX Error: ' + e.message);
  16137. } else {
  16138. warn('JPX: Trying to recover from: ' + e.message);
  16139. }
  16140. }
  16141. this.tiles = transformComponents(context);
  16142. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  16143. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  16144. this.componentsCount = context.SIZ.Csiz;
  16145. }
  16146. };
  16147. function calculateComponentDimensions(component, siz) {
  16148. // Section B.2 Component mapping
  16149. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  16150. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  16151. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  16152. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  16153. component.width = component.x1 - component.x0;
  16154. component.height = component.y1 - component.y0;
  16155. }
  16156. function calculateTileGrids(context, components) {
  16157. var siz = context.SIZ;
  16158. // Section B.3 Division into tile and tile-components
  16159. var tile, tiles = [];
  16160. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  16161. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  16162. for (var q = 0; q < numYtiles; q++) {
  16163. for (var p = 0; p < numXtiles; p++) {
  16164. tile = {};
  16165. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  16166. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  16167. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  16168. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  16169. tile.width = tile.tx1 - tile.tx0;
  16170. tile.height = tile.ty1 - tile.ty0;
  16171. tile.components = [];
  16172. tiles.push(tile);
  16173. }
  16174. }
  16175. context.tiles = tiles;
  16176. var componentsCount = siz.Csiz;
  16177. for (var i = 0, ii = componentsCount; i < ii; i++) {
  16178. var component = components[i];
  16179. for (var j = 0, jj = tiles.length; j < jj; j++) {
  16180. var tileComponent = {};
  16181. tile = tiles[j];
  16182. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  16183. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  16184. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  16185. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  16186. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  16187. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  16188. tile.components[i] = tileComponent;
  16189. }
  16190. }
  16191. }
  16192. function getBlocksDimensions(context, component, r) {
  16193. var codOrCoc = component.codingStyleParameters;
  16194. var result = {};
  16195. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  16196. result.PPx = 15;
  16197. result.PPy = 15;
  16198. } else {
  16199. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  16200. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  16201. }
  16202. // calculate codeblock size as described in section B.7
  16203. result.xcb_ = r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) : Math.min(codOrCoc.xcb, result.PPx);
  16204. result.ycb_ = r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) : Math.min(codOrCoc.ycb, result.PPy);
  16205. return result;
  16206. }
  16207. function buildPrecincts(context, resolution, dimensions) {
  16208. // Section B.6 Division resolution to precincts
  16209. var precinctWidth = 1 << dimensions.PPx;
  16210. var precinctHeight = 1 << dimensions.PPy;
  16211. // Jasper introduces codeblock groups for mapping each subband codeblocks
  16212. // to precincts. Precinct partition divides a resolution according to width
  16213. // and height parameters. The subband that belongs to the resolution level
  16214. // has a different size than the level, unless it is the zero resolution.
  16215. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  16216. // The precinct partitioning for a particular subband is derived from a
  16217. // partitioning of its parent LL band (i.e., the LL band at the next higher
  16218. // resolution level)... The LL band associated with each resolution level is
  16219. // divided into precincts... Each of the resulting precinct regions is then
  16220. // mapped into its child subbands (if any) at the next lower resolution
  16221. // level. This is accomplished by using the coordinate transformation
  16222. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  16223. // coordinates of a point in the LL band and child subband, respectively.
  16224. var isZeroRes = resolution.resLevel === 0;
  16225. var precinctWidthInSubband = 1 << dimensions.PPx + (isZeroRes ? 0 : -1);
  16226. var precinctHeightInSubband = 1 << dimensions.PPy + (isZeroRes ? 0 : -1);
  16227. var numprecinctswide = resolution.trx1 > resolution.trx0 ? Math.ceil(resolution.trx1 / precinctWidth) - Math.floor(resolution.trx0 / precinctWidth) : 0;
  16228. var numprecinctshigh = resolution.try1 > resolution.try0 ? Math.ceil(resolution.try1 / precinctHeight) - Math.floor(resolution.try0 / precinctHeight) : 0;
  16229. var numprecincts = numprecinctswide * numprecinctshigh;
  16230. resolution.precinctParameters = {
  16231. precinctWidth: precinctWidth,
  16232. precinctHeight: precinctHeight,
  16233. numprecinctswide: numprecinctswide,
  16234. numprecinctshigh: numprecinctshigh,
  16235. numprecincts: numprecincts,
  16236. precinctWidthInSubband: precinctWidthInSubband,
  16237. precinctHeightInSubband: precinctHeightInSubband
  16238. };
  16239. }
  16240. function buildCodeblocks(context, subband, dimensions) {
  16241. // Section B.7 Division sub-band into code-blocks
  16242. var xcb_ = dimensions.xcb_;
  16243. var ycb_ = dimensions.ycb_;
  16244. var codeblockWidth = 1 << xcb_;
  16245. var codeblockHeight = 1 << ycb_;
  16246. var cbx0 = subband.tbx0 >> xcb_;
  16247. var cby0 = subband.tby0 >> ycb_;
  16248. var cbx1 = subband.tbx1 + codeblockWidth - 1 >> xcb_;
  16249. var cby1 = subband.tby1 + codeblockHeight - 1 >> ycb_;
  16250. var precinctParameters = subband.resolution.precinctParameters;
  16251. var codeblocks = [];
  16252. var precincts = [];
  16253. var i, j, codeblock, precinctNumber;
  16254. for (j = cby0; j < cby1; j++) {
  16255. for (i = cbx0; i < cbx1; i++) {
  16256. codeblock = {
  16257. cbx: i,
  16258. cby: j,
  16259. tbx0: codeblockWidth * i,
  16260. tby0: codeblockHeight * j,
  16261. tbx1: codeblockWidth * (i + 1),
  16262. tby1: codeblockHeight * (j + 1)
  16263. };
  16264. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  16265. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  16266. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  16267. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  16268. // Calculate precinct number for this codeblock, codeblock position
  16269. // should be relative to its subband, use actual dimension and position
  16270. // See comment about codeblock group width and height
  16271. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) / precinctParameters.precinctWidthInSubband);
  16272. var pj = Math.floor((codeblock.tby0_ - subband.tby0) / precinctParameters.precinctHeightInSubband);
  16273. precinctNumber = pi + pj * precinctParameters.numprecinctswide;
  16274. codeblock.precinctNumber = precinctNumber;
  16275. codeblock.subbandType = subband.type;
  16276. codeblock.Lblock = 3;
  16277. if (codeblock.tbx1_ <= codeblock.tbx0_ || codeblock.tby1_ <= codeblock.tby0_) {
  16278. continue;
  16279. }
  16280. codeblocks.push(codeblock);
  16281. // building precinct for the sub-band
  16282. var precinct = precincts[precinctNumber];
  16283. if (precinct !== undefined) {
  16284. if (i < precinct.cbxMin) {
  16285. precinct.cbxMin = i;
  16286. } else if (i > precinct.cbxMax) {
  16287. precinct.cbxMax = i;
  16288. }
  16289. if (j < precinct.cbyMin) {
  16290. precinct.cbxMin = j;
  16291. } else if (j > precinct.cbyMax) {
  16292. precinct.cbyMax = j;
  16293. }
  16294. } else {
  16295. precincts[precinctNumber] = precinct = {
  16296. cbxMin: i,
  16297. cbyMin: j,
  16298. cbxMax: i,
  16299. cbyMax: j
  16300. };
  16301. }
  16302. codeblock.precinct = precinct;
  16303. }
  16304. }
  16305. subband.codeblockParameters = {
  16306. codeblockWidth: xcb_,
  16307. codeblockHeight: ycb_,
  16308. numcodeblockwide: cbx1 - cbx0 + 1,
  16309. numcodeblockhigh: cby1 - cby0 + 1
  16310. };
  16311. subband.codeblocks = codeblocks;
  16312. subband.precincts = precincts;
  16313. }
  16314. function createPacket(resolution, precinctNumber, layerNumber) {
  16315. var precinctCodeblocks = [];
  16316. // Section B.10.8 Order of info in packet
  16317. var subbands = resolution.subbands;
  16318. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  16319. for (var i = 0, ii = subbands.length; i < ii; i++) {
  16320. var subband = subbands[i];
  16321. var codeblocks = subband.codeblocks;
  16322. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  16323. var codeblock = codeblocks[j];
  16324. if (codeblock.precinctNumber !== precinctNumber) {
  16325. continue;
  16326. }
  16327. precinctCodeblocks.push(codeblock);
  16328. }
  16329. }
  16330. return {
  16331. layerNumber: layerNumber,
  16332. codeblocks: precinctCodeblocks
  16333. };
  16334. }
  16335. function LayerResolutionComponentPositionIterator(context) {
  16336. var siz = context.SIZ;
  16337. var tileIndex = context.currentTile.index;
  16338. var tile = context.tiles[tileIndex];
  16339. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  16340. var componentsCount = siz.Csiz;
  16341. var maxDecompositionLevelsCount = 0;
  16342. for (var q = 0; q < componentsCount; q++) {
  16343. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, tile.components[q].codingStyleParameters.decompositionLevelsCount);
  16344. }
  16345. var l = 0, r = 0, i = 0, k = 0;
  16346. this.nextPacket = function JpxImage_nextPacket() {
  16347. // Section B.12.1.1 Layer-resolution-component-position
  16348. for (; l < layersCount; l++) {
  16349. for (; r <= maxDecompositionLevelsCount; r++) {
  16350. for (; i < componentsCount; i++) {
  16351. var component = tile.components[i];
  16352. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  16353. continue;
  16354. }
  16355. var resolution = component.resolutions[r];
  16356. var numprecincts = resolution.precinctParameters.numprecincts;
  16357. for (; k < numprecincts;) {
  16358. var packet = createPacket(resolution, k, l);
  16359. k++;
  16360. return packet;
  16361. }
  16362. k = 0;
  16363. }
  16364. i = 0;
  16365. }
  16366. r = 0;
  16367. }
  16368. error('JPX Error: Out of packets');
  16369. };
  16370. }
  16371. function ResolutionLayerComponentPositionIterator(context) {
  16372. var siz = context.SIZ;
  16373. var tileIndex = context.currentTile.index;
  16374. var tile = context.tiles[tileIndex];
  16375. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  16376. var componentsCount = siz.Csiz;
  16377. var maxDecompositionLevelsCount = 0;
  16378. for (var q = 0; q < componentsCount; q++) {
  16379. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, tile.components[q].codingStyleParameters.decompositionLevelsCount);
  16380. }
  16381. var r = 0, l = 0, i = 0, k = 0;
  16382. this.nextPacket = function JpxImage_nextPacket() {
  16383. // Section B.12.1.2 Resolution-layer-component-position
  16384. for (; r <= maxDecompositionLevelsCount; r++) {
  16385. for (; l < layersCount; l++) {
  16386. for (; i < componentsCount; i++) {
  16387. var component = tile.components[i];
  16388. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  16389. continue;
  16390. }
  16391. var resolution = component.resolutions[r];
  16392. var numprecincts = resolution.precinctParameters.numprecincts;
  16393. for (; k < numprecincts;) {
  16394. var packet = createPacket(resolution, k, l);
  16395. k++;
  16396. return packet;
  16397. }
  16398. k = 0;
  16399. }
  16400. i = 0;
  16401. }
  16402. l = 0;
  16403. }
  16404. error('JPX Error: Out of packets');
  16405. };
  16406. }
  16407. function ResolutionPositionComponentLayerIterator(context) {
  16408. var siz = context.SIZ;
  16409. var tileIndex = context.currentTile.index;
  16410. var tile = context.tiles[tileIndex];
  16411. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  16412. var componentsCount = siz.Csiz;
  16413. var l, r, c, p;
  16414. var maxDecompositionLevelsCount = 0;
  16415. for (c = 0; c < componentsCount; c++) {
  16416. var component = tile.components[c];
  16417. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount, component.codingStyleParameters.decompositionLevelsCount);
  16418. }
  16419. var maxNumPrecinctsInLevel = new Int32Array(maxDecompositionLevelsCount + 1);
  16420. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  16421. var maxNumPrecincts = 0;
  16422. for (c = 0; c < componentsCount; ++c) {
  16423. var resolutions = tile.components[c].resolutions;
  16424. if (r < resolutions.length) {
  16425. maxNumPrecincts = Math.max(maxNumPrecincts, resolutions[r].precinctParameters.numprecincts);
  16426. }
  16427. }
  16428. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  16429. }
  16430. l = 0;
  16431. r = 0;
  16432. c = 0;
  16433. p = 0;
  16434. this.nextPacket = function JpxImage_nextPacket() {
  16435. // Section B.12.1.3 Resolution-position-component-layer
  16436. for (; r <= maxDecompositionLevelsCount; r++) {
  16437. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  16438. for (; c < componentsCount; c++) {
  16439. var component = tile.components[c];
  16440. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  16441. continue;
  16442. }
  16443. var resolution = component.resolutions[r];
  16444. var numprecincts = resolution.precinctParameters.numprecincts;
  16445. if (p >= numprecincts) {
  16446. continue;
  16447. }
  16448. for (; l < layersCount;) {
  16449. var packet = createPacket(resolution, p, l);
  16450. l++;
  16451. return packet;
  16452. }
  16453. l = 0;
  16454. }
  16455. c = 0;
  16456. }
  16457. p = 0;
  16458. }
  16459. error('JPX Error: Out of packets');
  16460. };
  16461. }
  16462. function PositionComponentResolutionLayerIterator(context) {
  16463. var siz = context.SIZ;
  16464. var tileIndex = context.currentTile.index;
  16465. var tile = context.tiles[tileIndex];
  16466. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  16467. var componentsCount = siz.Csiz;
  16468. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  16469. var precinctsIterationSizes = precinctsSizes;
  16470. var l = 0, r = 0, c = 0, px = 0, py = 0;
  16471. this.nextPacket = function JpxImage_nextPacket() {
  16472. // Section B.12.1.4 Position-component-resolution-layer
  16473. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  16474. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  16475. for (; c < componentsCount; c++) {
  16476. var component = tile.components[c];
  16477. var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
  16478. for (; r <= decompositionLevelsCount; r++) {
  16479. var resolution = component.resolutions[r];
  16480. var sizeInImageScale = precinctsSizes.components[c].resolutions[r];
  16481. var k = getPrecinctIndexIfExist(px, py, sizeInImageScale, precinctsIterationSizes, resolution);
  16482. if (k === null) {
  16483. continue;
  16484. }
  16485. for (; l < layersCount;) {
  16486. var packet = createPacket(resolution, k, l);
  16487. l++;
  16488. return packet;
  16489. }
  16490. l = 0;
  16491. }
  16492. r = 0;
  16493. }
  16494. c = 0;
  16495. }
  16496. px = 0;
  16497. }
  16498. error('JPX Error: Out of packets');
  16499. };
  16500. }
  16501. function ComponentPositionResolutionLayerIterator(context) {
  16502. var siz = context.SIZ;
  16503. var tileIndex = context.currentTile.index;
  16504. var tile = context.tiles[tileIndex];
  16505. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  16506. var componentsCount = siz.Csiz;
  16507. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  16508. var l = 0, r = 0, c = 0, px = 0, py = 0;
  16509. this.nextPacket = function JpxImage_nextPacket() {
  16510. // Section B.12.1.5 Component-position-resolution-layer
  16511. for (; c < componentsCount; ++c) {
  16512. var component = tile.components[c];
  16513. var precinctsIterationSizes = precinctsSizes.components[c];
  16514. var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
  16515. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  16516. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  16517. for (; r <= decompositionLevelsCount; r++) {
  16518. var resolution = component.resolutions[r];
  16519. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  16520. var k = getPrecinctIndexIfExist(px, py, sizeInImageScale, precinctsIterationSizes, resolution);
  16521. if (k === null) {
  16522. continue;
  16523. }
  16524. for (; l < layersCount;) {
  16525. var packet = createPacket(resolution, k, l);
  16526. l++;
  16527. return packet;
  16528. }
  16529. l = 0;
  16530. }
  16531. r = 0;
  16532. }
  16533. px = 0;
  16534. }
  16535. py = 0;
  16536. }
  16537. error('JPX Error: Out of packets');
  16538. };
  16539. }
  16540. function getPrecinctIndexIfExist(pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  16541. var posX = pxIndex * precinctIterationSizes.minWidth;
  16542. var posY = pyIndex * precinctIterationSizes.minHeight;
  16543. if (posX % sizeInImageScale.width !== 0 || posY % sizeInImageScale.height !== 0) {
  16544. return null;
  16545. }
  16546. var startPrecinctRowIndex = posY / sizeInImageScale.width * resolution.precinctParameters.numprecinctswide;
  16547. return posX / sizeInImageScale.height + startPrecinctRowIndex;
  16548. }
  16549. function getPrecinctSizesInImageScale(tile) {
  16550. var componentsCount = tile.components.length;
  16551. var minWidth = Number.MAX_VALUE;
  16552. var minHeight = Number.MAX_VALUE;
  16553. var maxNumWide = 0;
  16554. var maxNumHigh = 0;
  16555. var sizePerComponent = new Array(componentsCount);
  16556. for (var c = 0; c < componentsCount; c++) {
  16557. var component = tile.components[c];
  16558. var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
  16559. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  16560. var minWidthCurrentComponent = Number.MAX_VALUE;
  16561. var minHeightCurrentComponent = Number.MAX_VALUE;
  16562. var maxNumWideCurrentComponent = 0;
  16563. var maxNumHighCurrentComponent = 0;
  16564. var scale = 1;
  16565. for (var r = decompositionLevelsCount; r >= 0; --r) {
  16566. var resolution = component.resolutions[r];
  16567. var widthCurrentResolution = scale * resolution.precinctParameters.precinctWidth;
  16568. var heightCurrentResolution = scale * resolution.precinctParameters.precinctHeight;
  16569. minWidthCurrentComponent = Math.min(minWidthCurrentComponent, widthCurrentResolution);
  16570. minHeightCurrentComponent = Math.min(minHeightCurrentComponent, heightCurrentResolution);
  16571. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent, resolution.precinctParameters.numprecinctswide);
  16572. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent, resolution.precinctParameters.numprecinctshigh);
  16573. sizePerResolution[r] = {
  16574. width: widthCurrentResolution,
  16575. height: heightCurrentResolution
  16576. };
  16577. scale <<= 1;
  16578. }
  16579. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  16580. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  16581. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  16582. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  16583. sizePerComponent[c] = {
  16584. resolutions: sizePerResolution,
  16585. minWidth: minWidthCurrentComponent,
  16586. minHeight: minHeightCurrentComponent,
  16587. maxNumWide: maxNumWideCurrentComponent,
  16588. maxNumHigh: maxNumHighCurrentComponent
  16589. };
  16590. }
  16591. return {
  16592. components: sizePerComponent,
  16593. minWidth: minWidth,
  16594. minHeight: minHeight,
  16595. maxNumWide: maxNumWide,
  16596. maxNumHigh: maxNumHigh
  16597. };
  16598. }
  16599. function buildPackets(context) {
  16600. var siz = context.SIZ;
  16601. var tileIndex = context.currentTile.index;
  16602. var tile = context.tiles[tileIndex];
  16603. var componentsCount = siz.Csiz;
  16604. // Creating resolutions and sub-bands for each component
  16605. for (var c = 0; c < componentsCount; c++) {
  16606. var component = tile.components[c];
  16607. var decompositionLevelsCount = component.codingStyleParameters.decompositionLevelsCount;
  16608. // Section B.5 Resolution levels and sub-bands
  16609. var resolutions = [];
  16610. var subbands = [];
  16611. for (var r = 0; r <= decompositionLevelsCount; r++) {
  16612. var blocksDimensions = getBlocksDimensions(context, component, r);
  16613. var resolution = {};
  16614. var scale = 1 << decompositionLevelsCount - r;
  16615. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  16616. resolution.try0 = Math.ceil(component.tcy0 / scale);
  16617. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  16618. resolution.try1 = Math.ceil(component.tcy1 / scale);
  16619. resolution.resLevel = r;
  16620. buildPrecincts(context, resolution, blocksDimensions);
  16621. resolutions.push(resolution);
  16622. var subband;
  16623. if (r === 0) {
  16624. // one sub-band (LL) with last decomposition
  16625. subband = {};
  16626. subband.type = 'LL';
  16627. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  16628. subband.tby0 = Math.ceil(component.tcy0 / scale);
  16629. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  16630. subband.tby1 = Math.ceil(component.tcy1 / scale);
  16631. subband.resolution = resolution;
  16632. buildCodeblocks(context, subband, blocksDimensions);
  16633. subbands.push(subband);
  16634. resolution.subbands = [subband];
  16635. } else {
  16636. var bscale = 1 << decompositionLevelsCount - r + 1;
  16637. var resolutionSubbands = [];
  16638. // three sub-bands (HL, LH and HH) with rest of decompositions
  16639. subband = {};
  16640. subband.type = 'HL';
  16641. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  16642. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  16643. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  16644. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  16645. subband.resolution = resolution;
  16646. buildCodeblocks(context, subband, blocksDimensions);
  16647. subbands.push(subband);
  16648. resolutionSubbands.push(subband);
  16649. subband = {};
  16650. subband.type = 'LH';
  16651. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  16652. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  16653. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  16654. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  16655. subband.resolution = resolution;
  16656. buildCodeblocks(context, subband, blocksDimensions);
  16657. subbands.push(subband);
  16658. resolutionSubbands.push(subband);
  16659. subband = {};
  16660. subband.type = 'HH';
  16661. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  16662. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  16663. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  16664. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  16665. subband.resolution = resolution;
  16666. buildCodeblocks(context, subband, blocksDimensions);
  16667. subbands.push(subband);
  16668. resolutionSubbands.push(subband);
  16669. resolution.subbands = resolutionSubbands;
  16670. }
  16671. }
  16672. component.resolutions = resolutions;
  16673. component.subbands = subbands;
  16674. }
  16675. // Generate the packets sequence
  16676. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  16677. switch (progressionOrder) {
  16678. case 0:
  16679. tile.packetsIterator = new LayerResolutionComponentPositionIterator(context);
  16680. break;
  16681. case 1:
  16682. tile.packetsIterator = new ResolutionLayerComponentPositionIterator(context);
  16683. break;
  16684. case 2:
  16685. tile.packetsIterator = new ResolutionPositionComponentLayerIterator(context);
  16686. break;
  16687. case 3:
  16688. tile.packetsIterator = new PositionComponentResolutionLayerIterator(context);
  16689. break;
  16690. case 4:
  16691. tile.packetsIterator = new ComponentPositionResolutionLayerIterator(context);
  16692. break;
  16693. default:
  16694. error('JPX Error: Unsupported progression order ' + progressionOrder);
  16695. }
  16696. }
  16697. function parseTilePackets(context, data, offset, dataLength) {
  16698. var position = 0;
  16699. var buffer, bufferSize = 0, skipNextBit = false;
  16700. function readBits(count) {
  16701. while (bufferSize < count) {
  16702. var b = data[offset + position];
  16703. position++;
  16704. if (skipNextBit) {
  16705. buffer = buffer << 7 | b;
  16706. bufferSize += 7;
  16707. skipNextBit = false;
  16708. } else {
  16709. buffer = buffer << 8 | b;
  16710. bufferSize += 8;
  16711. }
  16712. if (b === 0xFF) {
  16713. skipNextBit = true;
  16714. }
  16715. }
  16716. bufferSize -= count;
  16717. return buffer >>> bufferSize & (1 << count) - 1;
  16718. }
  16719. function skipMarkerIfEqual(value) {
  16720. if (data[offset + position - 1] === 0xFF && data[offset + position] === value) {
  16721. skipBytes(1);
  16722. return true;
  16723. } else if (data[offset + position] === 0xFF && data[offset + position + 1] === value) {
  16724. skipBytes(2);
  16725. return true;
  16726. }
  16727. return false;
  16728. }
  16729. function skipBytes(count) {
  16730. position += count;
  16731. }
  16732. function alignToByte() {
  16733. bufferSize = 0;
  16734. if (skipNextBit) {
  16735. position++;
  16736. skipNextBit = false;
  16737. }
  16738. }
  16739. function readCodingpasses() {
  16740. if (readBits(1) === 0) {
  16741. return 1;
  16742. }
  16743. if (readBits(1) === 0) {
  16744. return 2;
  16745. }
  16746. var value = readBits(2);
  16747. if (value < 3) {
  16748. return value + 3;
  16749. }
  16750. value = readBits(5);
  16751. if (value < 31) {
  16752. return value + 6;
  16753. }
  16754. value = readBits(7);
  16755. return value + 37;
  16756. }
  16757. var tileIndex = context.currentTile.index;
  16758. var tile = context.tiles[tileIndex];
  16759. var sopMarkerUsed = context.COD.sopMarkerUsed;
  16760. var ephMarkerUsed = context.COD.ephMarkerUsed;
  16761. var packetsIterator = tile.packetsIterator;
  16762. while (position < dataLength) {
  16763. alignToByte();
  16764. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  16765. // Skip also marker segment length and packet sequence ID
  16766. skipBytes(4);
  16767. }
  16768. var packet = packetsIterator.nextPacket();
  16769. if (!readBits(1)) {
  16770. continue;
  16771. }
  16772. var layerNumber = packet.layerNumber;
  16773. var queue = [], codeblock;
  16774. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  16775. codeblock = packet.codeblocks[i];
  16776. var precinct = codeblock.precinct;
  16777. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  16778. var codeblockRow = codeblock.cby - precinct.cbyMin;
  16779. var codeblockIncluded = false;
  16780. var firstTimeInclusion = false;
  16781. var valueReady;
  16782. if (codeblock['included'] !== undefined) {
  16783. codeblockIncluded = !!readBits(1);
  16784. } else {
  16785. // reading inclusion tree
  16786. precinct = codeblock.precinct;
  16787. var inclusionTree, zeroBitPlanesTree;
  16788. if (precinct['inclusionTree'] !== undefined) {
  16789. inclusionTree = precinct.inclusionTree;
  16790. } else {
  16791. // building inclusion and zero bit-planes trees
  16792. var width = precinct.cbxMax - precinct.cbxMin + 1;
  16793. var height = precinct.cbyMax - precinct.cbyMin + 1;
  16794. inclusionTree = new InclusionTree(width, height, layerNumber);
  16795. zeroBitPlanesTree = new TagTree(width, height);
  16796. precinct.inclusionTree = inclusionTree;
  16797. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  16798. }
  16799. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  16800. while (true) {
  16801. if (readBits(1)) {
  16802. valueReady = !inclusionTree.nextLevel();
  16803. if (valueReady) {
  16804. codeblock.included = true;
  16805. codeblockIncluded = firstTimeInclusion = true;
  16806. break;
  16807. }
  16808. } else {
  16809. inclusionTree.incrementValue(layerNumber);
  16810. break;
  16811. }
  16812. }
  16813. }
  16814. }
  16815. if (!codeblockIncluded) {
  16816. continue;
  16817. }
  16818. if (firstTimeInclusion) {
  16819. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  16820. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  16821. while (true) {
  16822. if (readBits(1)) {
  16823. valueReady = !zeroBitPlanesTree.nextLevel();
  16824. if (valueReady) {
  16825. break;
  16826. }
  16827. } else {
  16828. zeroBitPlanesTree.incrementValue();
  16829. }
  16830. }
  16831. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  16832. }
  16833. var codingpasses = readCodingpasses();
  16834. while (readBits(1)) {
  16835. codeblock.Lblock++;
  16836. }
  16837. var codingpassesLog2 = log2(codingpasses);
  16838. // rounding down log2
  16839. var bits = (codingpasses < 1 << codingpassesLog2 ? codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  16840. var codedDataLength = readBits(bits);
  16841. queue.push({
  16842. codeblock: codeblock,
  16843. codingpasses: codingpasses,
  16844. dataLength: codedDataLength
  16845. });
  16846. }
  16847. alignToByte();
  16848. if (ephMarkerUsed) {
  16849. skipMarkerIfEqual(0x92);
  16850. }
  16851. while (queue.length > 0) {
  16852. var packetItem = queue.shift();
  16853. codeblock = packetItem.codeblock;
  16854. if (codeblock['data'] === undefined) {
  16855. codeblock.data = [];
  16856. }
  16857. codeblock.data.push({
  16858. data: data,
  16859. start: offset + position,
  16860. end: offset + position + packetItem.dataLength,
  16861. codingpasses: packetItem.codingpasses
  16862. });
  16863. position += packetItem.dataLength;
  16864. }
  16865. }
  16866. return position;
  16867. }
  16868. function copyCoefficients(coefficients, levelWidth, levelHeight, subband, delta, mb, reversible, segmentationSymbolUsed) {
  16869. var x0 = subband.tbx0;
  16870. var y0 = subband.tby0;
  16871. var width = subband.tbx1 - subband.tbx0;
  16872. var codeblocks = subband.codeblocks;
  16873. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  16874. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  16875. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  16876. var codeblock = codeblocks[i];
  16877. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  16878. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  16879. if (blockWidth === 0 || blockHeight === 0) {
  16880. continue;
  16881. }
  16882. if (codeblock['data'] === undefined) {
  16883. continue;
  16884. }
  16885. var bitModel, currentCodingpassType;
  16886. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType, codeblock.zeroBitPlanes, mb);
  16887. currentCodingpassType = 2;
  16888. // first bit plane starts from cleanup
  16889. // collect data
  16890. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  16891. var j, jj, dataItem;
  16892. for (j = 0, jj = data.length; j < jj; j++) {
  16893. dataItem = data[j];
  16894. totalLength += dataItem.end - dataItem.start;
  16895. codingpasses += dataItem.codingpasses;
  16896. }
  16897. var encodedData = new Uint8Array(totalLength);
  16898. var position = 0;
  16899. for (j = 0, jj = data.length; j < jj; j++) {
  16900. dataItem = data[j];
  16901. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  16902. encodedData.set(chunk, position);
  16903. position += chunk.length;
  16904. }
  16905. // decoding the item
  16906. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  16907. bitModel.setDecoder(decoder);
  16908. for (j = 0; j < codingpasses; j++) {
  16909. switch (currentCodingpassType) {
  16910. case 0:
  16911. bitModel.runSignificancePropagationPass();
  16912. break;
  16913. case 1:
  16914. bitModel.runMagnitudeRefinementPass();
  16915. break;
  16916. case 2:
  16917. bitModel.runCleanupPass();
  16918. if (segmentationSymbolUsed) {
  16919. bitModel.checkSegmentationSymbol();
  16920. }
  16921. break;
  16922. }
  16923. currentCodingpassType = (currentCodingpassType + 1) % 3;
  16924. }
  16925. var offset = codeblock.tbx0_ - x0 + (codeblock.tby0_ - y0) * width;
  16926. var sign = bitModel.coefficentsSign;
  16927. var magnitude = bitModel.coefficentsMagnitude;
  16928. var bitsDecoded = bitModel.bitsDecoded;
  16929. var magnitudeCorrection = reversible ? 0 : 0.5;
  16930. var k, n, nb;
  16931. position = 0;
  16932. // Do the interleaving of Section F.3.3 here, so we do not need
  16933. // to copy later. LL level is not interleaved, just copied.
  16934. var interleave = subband.type !== 'LL';
  16935. for (j = 0; j < blockHeight; j++) {
  16936. var row = offset / width | 0;
  16937. // row in the non-interleaved subband
  16938. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  16939. for (k = 0; k < blockWidth; k++) {
  16940. n = magnitude[position];
  16941. if (n !== 0) {
  16942. n = (n + magnitudeCorrection) * delta;
  16943. if (sign[position] !== 0) {
  16944. n = -n;
  16945. }
  16946. nb = bitsDecoded[position];
  16947. var pos = interleave ? levelOffset + (offset << 1) : offset;
  16948. if (reversible && nb >= mb) {
  16949. coefficients[pos] = n;
  16950. } else {
  16951. coefficients[pos] = n * (1 << mb - nb);
  16952. }
  16953. }
  16954. offset++;
  16955. position++;
  16956. }
  16957. offset += width - blockWidth;
  16958. }
  16959. }
  16960. }
  16961. function transformTile(context, tile, c) {
  16962. var component = tile.components[c];
  16963. var codingStyleParameters = component.codingStyleParameters;
  16964. var quantizationParameters = component.quantizationParameters;
  16965. var decompositionLevelsCount = codingStyleParameters.decompositionLevelsCount;
  16966. var spqcds = quantizationParameters.SPqcds;
  16967. var scalarExpounded = quantizationParameters.scalarExpounded;
  16968. var guardBits = quantizationParameters.guardBits;
  16969. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  16970. var precision = context.components[c].precision;
  16971. var reversible = codingStyleParameters.reversibleTransformation;
  16972. var transform = reversible ? new ReversibleTransform() : new IrreversibleTransform();
  16973. var subbandCoefficients = [];
  16974. var b = 0;
  16975. for (var i = 0; i <= decompositionLevelsCount; i++) {
  16976. var resolution = component.resolutions[i];
  16977. var width = resolution.trx1 - resolution.trx0;
  16978. var height = resolution.try1 - resolution.try0;
  16979. // Allocate space for the whole sublevel.
  16980. var coefficients = new Float32Array(width * height);
  16981. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  16982. var mu, epsilon;
  16983. if (!scalarExpounded) {
  16984. // formula E-5
  16985. mu = spqcds[0].mu;
  16986. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  16987. } else {
  16988. mu = spqcds[b].mu;
  16989. epsilon = spqcds[b].epsilon;
  16990. b++;
  16991. }
  16992. var subband = resolution.subbands[j];
  16993. var gainLog2 = SubbandsGainLog2[subband.type];
  16994. // calculate quantization coefficient (Section E.1.1.1)
  16995. var delta = reversible ? 1 : Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048);
  16996. var mb = guardBits + epsilon - 1;
  16997. // In the first resolution level, copyCoefficients will fill the
  16998. // whole array with coefficients. In the succeeding passes,
  16999. // copyCoefficients will consecutively fill in the values that belong
  17000. // to the interleaved positions of the HL, LH, and HH coefficients.
  17001. // The LL coefficients will then be interleaved in Transform.iterate().
  17002. copyCoefficients(coefficients, width, height, subband, delta, mb, reversible, segmentationSymbolUsed);
  17003. }
  17004. subbandCoefficients.push({
  17005. width: width,
  17006. height: height,
  17007. items: coefficients
  17008. });
  17009. }
  17010. var result = transform.calculate(subbandCoefficients, component.tcx0, component.tcy0);
  17011. return {
  17012. left: component.tcx0,
  17013. top: component.tcy0,
  17014. width: result.width,
  17015. height: result.height,
  17016. items: result.items
  17017. };
  17018. }
  17019. function transformComponents(context) {
  17020. var siz = context.SIZ;
  17021. var components = context.components;
  17022. var componentsCount = siz.Csiz;
  17023. var resultImages = [];
  17024. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  17025. var tile = context.tiles[i];
  17026. var transformedTiles = [];
  17027. var c;
  17028. for (c = 0; c < componentsCount; c++) {
  17029. transformedTiles[c] = transformTile(context, tile, c);
  17030. }
  17031. var tile0 = transformedTiles[0];
  17032. var out = new Uint8Array(tile0.items.length * componentsCount);
  17033. var result = {
  17034. left: tile0.left,
  17035. top: tile0.top,
  17036. width: tile0.width,
  17037. height: tile0.height,
  17038. items: out
  17039. };
  17040. // Section G.2.2 Inverse multi component transform
  17041. var shift, offset, max, min, maxK;
  17042. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  17043. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  17044. var fourComponents = componentsCount === 4;
  17045. var y0items = transformedTiles[0].items;
  17046. var y1items = transformedTiles[1].items;
  17047. var y2items = transformedTiles[2].items;
  17048. var y3items = fourComponents ? transformedTiles[3].items : null;
  17049. // HACK: The multiple component transform formulas below assume that
  17050. // all components have the same precision. With this in mind, we
  17051. // compute shift and offset only once.
  17052. shift = components[0].precision - 8;
  17053. offset = (128 << shift) + 0.5;
  17054. max = 255 * (1 << shift);
  17055. maxK = max * 0.5;
  17056. min = -maxK;
  17057. var component0 = tile.components[0];
  17058. var alpha01 = componentsCount - 3;
  17059. jj = y0items.length;
  17060. if (!component0.codingStyleParameters.reversibleTransformation) {
  17061. // inverse irreversible multiple component transform
  17062. for (j = 0; j < jj; j++, pos += alpha01) {
  17063. y0 = y0items[j] + offset;
  17064. y1 = y1items[j];
  17065. y2 = y2items[j];
  17066. r = y0 + 1.402 * y2;
  17067. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  17068. b = y0 + 1.772 * y1;
  17069. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  17070. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  17071. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  17072. }
  17073. } else {
  17074. // inverse reversible multiple component transform
  17075. for (j = 0; j < jj; j++, pos += alpha01) {
  17076. y0 = y0items[j] + offset;
  17077. y1 = y1items[j];
  17078. y2 = y2items[j];
  17079. g = y0 - (y2 + y1 >> 2);
  17080. r = g + y2;
  17081. b = g + y1;
  17082. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  17083. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  17084. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  17085. }
  17086. }
  17087. if (fourComponents) {
  17088. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  17089. k = y3items[j];
  17090. out[pos] = k <= min ? 0 : k >= maxK ? 255 : k + offset >> shift;
  17091. }
  17092. }
  17093. } else {
  17094. // no multi-component transform
  17095. for (c = 0; c < componentsCount; c++) {
  17096. var items = transformedTiles[c].items;
  17097. shift = components[c].precision - 8;
  17098. offset = (128 << shift) + 0.5;
  17099. max = 127.5 * (1 << shift);
  17100. min = -max;
  17101. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  17102. val = items[j];
  17103. out[pos] = val <= min ? 0 : val >= max ? 255 : val + offset >> shift;
  17104. pos += componentsCount;
  17105. }
  17106. }
  17107. }
  17108. resultImages.push(result);
  17109. }
  17110. return resultImages;
  17111. }
  17112. function initializeTile(context, tileIndex) {
  17113. var siz = context.SIZ;
  17114. var componentsCount = siz.Csiz;
  17115. var tile = context.tiles[tileIndex];
  17116. for (var c = 0; c < componentsCount; c++) {
  17117. var component = tile.components[c];
  17118. var qcdOrQcc = context.currentTile.QCC[c] !== undefined ? context.currentTile.QCC[c] : context.currentTile.QCD;
  17119. component.quantizationParameters = qcdOrQcc;
  17120. var codOrCoc = context.currentTile.COC[c] !== undefined ? context.currentTile.COC[c] : context.currentTile.COD;
  17121. component.codingStyleParameters = codOrCoc;
  17122. }
  17123. tile.codingStyleDefaultParameters = context.currentTile.COD;
  17124. }
  17125. // Section B.10.2 Tag trees
  17126. var TagTree = function TagTreeClosure() {
  17127. function TagTree(width, height) {
  17128. var levelsLength = log2(Math.max(width, height)) + 1;
  17129. this.levels = [];
  17130. for (var i = 0; i < levelsLength; i++) {
  17131. var level = {
  17132. width: width,
  17133. height: height,
  17134. items: []
  17135. };
  17136. this.levels.push(level);
  17137. width = Math.ceil(width / 2);
  17138. height = Math.ceil(height / 2);
  17139. }
  17140. }
  17141. TagTree.prototype = {
  17142. reset: function TagTree_reset(i, j) {
  17143. var currentLevel = 0, value = 0, level;
  17144. while (currentLevel < this.levels.length) {
  17145. level = this.levels[currentLevel];
  17146. var index = i + j * level.width;
  17147. if (level.items[index] !== undefined) {
  17148. value = level.items[index];
  17149. break;
  17150. }
  17151. level.index = index;
  17152. i >>= 1;
  17153. j >>= 1;
  17154. currentLevel++;
  17155. }
  17156. currentLevel--;
  17157. level = this.levels[currentLevel];
  17158. level.items[level.index] = value;
  17159. this.currentLevel = currentLevel;
  17160. delete this.value;
  17161. },
  17162. incrementValue: function TagTree_incrementValue() {
  17163. var level = this.levels[this.currentLevel];
  17164. level.items[level.index]++;
  17165. },
  17166. nextLevel: function TagTree_nextLevel() {
  17167. var currentLevel = this.currentLevel;
  17168. var level = this.levels[currentLevel];
  17169. var value = level.items[level.index];
  17170. currentLevel--;
  17171. if (currentLevel < 0) {
  17172. this.value = value;
  17173. return false;
  17174. }
  17175. this.currentLevel = currentLevel;
  17176. level = this.levels[currentLevel];
  17177. level.items[level.index] = value;
  17178. return true;
  17179. }
  17180. };
  17181. return TagTree;
  17182. }();
  17183. var InclusionTree = function InclusionTreeClosure() {
  17184. function InclusionTree(width, height, defaultValue) {
  17185. var levelsLength = log2(Math.max(width, height)) + 1;
  17186. this.levels = [];
  17187. for (var i = 0; i < levelsLength; i++) {
  17188. var items = new Uint8Array(width * height);
  17189. for (var j = 0, jj = items.length; j < jj; j++) {
  17190. items[j] = defaultValue;
  17191. }
  17192. var level = {
  17193. width: width,
  17194. height: height,
  17195. items: items
  17196. };
  17197. this.levels.push(level);
  17198. width = Math.ceil(width / 2);
  17199. height = Math.ceil(height / 2);
  17200. }
  17201. }
  17202. InclusionTree.prototype = {
  17203. reset: function InclusionTree_reset(i, j, stopValue) {
  17204. var currentLevel = 0;
  17205. while (currentLevel < this.levels.length) {
  17206. var level = this.levels[currentLevel];
  17207. var index = i + j * level.width;
  17208. level.index = index;
  17209. var value = level.items[index];
  17210. if (value === 0xFF) {
  17211. break;
  17212. }
  17213. if (value > stopValue) {
  17214. this.currentLevel = currentLevel;
  17215. // already know about this one, propagating the value to top levels
  17216. this.propagateValues();
  17217. return false;
  17218. }
  17219. i >>= 1;
  17220. j >>= 1;
  17221. currentLevel++;
  17222. }
  17223. this.currentLevel = currentLevel - 1;
  17224. return true;
  17225. },
  17226. incrementValue: function InclusionTree_incrementValue(stopValue) {
  17227. var level = this.levels[this.currentLevel];
  17228. level.items[level.index] = stopValue + 1;
  17229. this.propagateValues();
  17230. },
  17231. propagateValues: function InclusionTree_propagateValues() {
  17232. var levelIndex = this.currentLevel;
  17233. var level = this.levels[levelIndex];
  17234. var currentValue = level.items[level.index];
  17235. while (--levelIndex >= 0) {
  17236. level = this.levels[levelIndex];
  17237. level.items[level.index] = currentValue;
  17238. }
  17239. },
  17240. nextLevel: function InclusionTree_nextLevel() {
  17241. var currentLevel = this.currentLevel;
  17242. var level = this.levels[currentLevel];
  17243. var value = level.items[level.index];
  17244. level.items[level.index] = 0xFF;
  17245. currentLevel--;
  17246. if (currentLevel < 0) {
  17247. return false;
  17248. }
  17249. this.currentLevel = currentLevel;
  17250. level = this.levels[currentLevel];
  17251. level.items[level.index] = value;
  17252. return true;
  17253. }
  17254. };
  17255. return InclusionTree;
  17256. }();
  17257. // Section D. Coefficient bit modeling
  17258. var BitModel = function BitModelClosure() {
  17259. var UNIFORM_CONTEXT = 17;
  17260. var RUNLENGTH_CONTEXT = 18;
  17261. // Table D-1
  17262. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  17263. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  17264. var LLAndLHContextsLabel = new Uint8Array([
  17265. 0,
  17266. 5,
  17267. 8,
  17268. 0,
  17269. 3,
  17270. 7,
  17271. 8,
  17272. 0,
  17273. 4,
  17274. 7,
  17275. 8,
  17276. 0,
  17277. 0,
  17278. 0,
  17279. 0,
  17280. 0,
  17281. 1,
  17282. 6,
  17283. 8,
  17284. 0,
  17285. 3,
  17286. 7,
  17287. 8,
  17288. 0,
  17289. 4,
  17290. 7,
  17291. 8,
  17292. 0,
  17293. 0,
  17294. 0,
  17295. 0,
  17296. 0,
  17297. 2,
  17298. 6,
  17299. 8,
  17300. 0,
  17301. 3,
  17302. 7,
  17303. 8,
  17304. 0,
  17305. 4,
  17306. 7,
  17307. 8,
  17308. 0,
  17309. 0,
  17310. 0,
  17311. 0,
  17312. 0,
  17313. 2,
  17314. 6,
  17315. 8,
  17316. 0,
  17317. 3,
  17318. 7,
  17319. 8,
  17320. 0,
  17321. 4,
  17322. 7,
  17323. 8,
  17324. 0,
  17325. 0,
  17326. 0,
  17327. 0,
  17328. 0,
  17329. 2,
  17330. 6,
  17331. 8,
  17332. 0,
  17333. 3,
  17334. 7,
  17335. 8,
  17336. 0,
  17337. 4,
  17338. 7,
  17339. 8
  17340. ]);
  17341. var HLContextLabel = new Uint8Array([
  17342. 0,
  17343. 3,
  17344. 4,
  17345. 0,
  17346. 5,
  17347. 7,
  17348. 7,
  17349. 0,
  17350. 8,
  17351. 8,
  17352. 8,
  17353. 0,
  17354. 0,
  17355. 0,
  17356. 0,
  17357. 0,
  17358. 1,
  17359. 3,
  17360. 4,
  17361. 0,
  17362. 6,
  17363. 7,
  17364. 7,
  17365. 0,
  17366. 8,
  17367. 8,
  17368. 8,
  17369. 0,
  17370. 0,
  17371. 0,
  17372. 0,
  17373. 0,
  17374. 2,
  17375. 3,
  17376. 4,
  17377. 0,
  17378. 6,
  17379. 7,
  17380. 7,
  17381. 0,
  17382. 8,
  17383. 8,
  17384. 8,
  17385. 0,
  17386. 0,
  17387. 0,
  17388. 0,
  17389. 0,
  17390. 2,
  17391. 3,
  17392. 4,
  17393. 0,
  17394. 6,
  17395. 7,
  17396. 7,
  17397. 0,
  17398. 8,
  17399. 8,
  17400. 8,
  17401. 0,
  17402. 0,
  17403. 0,
  17404. 0,
  17405. 0,
  17406. 2,
  17407. 3,
  17408. 4,
  17409. 0,
  17410. 6,
  17411. 7,
  17412. 7,
  17413. 0,
  17414. 8,
  17415. 8,
  17416. 8
  17417. ]);
  17418. var HHContextLabel = new Uint8Array([
  17419. 0,
  17420. 1,
  17421. 2,
  17422. 0,
  17423. 1,
  17424. 2,
  17425. 2,
  17426. 0,
  17427. 2,
  17428. 2,
  17429. 2,
  17430. 0,
  17431. 0,
  17432. 0,
  17433. 0,
  17434. 0,
  17435. 3,
  17436. 4,
  17437. 5,
  17438. 0,
  17439. 4,
  17440. 5,
  17441. 5,
  17442. 0,
  17443. 5,
  17444. 5,
  17445. 5,
  17446. 0,
  17447. 0,
  17448. 0,
  17449. 0,
  17450. 0,
  17451. 6,
  17452. 7,
  17453. 7,
  17454. 0,
  17455. 7,
  17456. 7,
  17457. 7,
  17458. 0,
  17459. 7,
  17460. 7,
  17461. 7,
  17462. 0,
  17463. 0,
  17464. 0,
  17465. 0,
  17466. 0,
  17467. 8,
  17468. 8,
  17469. 8,
  17470. 0,
  17471. 8,
  17472. 8,
  17473. 8,
  17474. 0,
  17475. 8,
  17476. 8,
  17477. 8,
  17478. 0,
  17479. 0,
  17480. 0,
  17481. 0,
  17482. 0,
  17483. 8,
  17484. 8,
  17485. 8,
  17486. 0,
  17487. 8,
  17488. 8,
  17489. 8,
  17490. 0,
  17491. 8,
  17492. 8,
  17493. 8
  17494. ]);
  17495. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  17496. this.width = width;
  17497. this.height = height;
  17498. this.contextLabelTable = subband === 'HH' ? HHContextLabel : subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel;
  17499. var coefficientCount = width * height;
  17500. // coefficients outside the encoding region treated as insignificant
  17501. // add border state cells for significanceState
  17502. this.neighborsSignificance = new Uint8Array(coefficientCount);
  17503. this.coefficentsSign = new Uint8Array(coefficientCount);
  17504. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) : mb > 6 ? new Uint16Array(coefficientCount) : new Uint8Array(coefficientCount);
  17505. this.processingFlags = new Uint8Array(coefficientCount);
  17506. var bitsDecoded = new Uint8Array(coefficientCount);
  17507. if (zeroBitPlanes !== 0) {
  17508. for (var i = 0; i < coefficientCount; i++) {
  17509. bitsDecoded[i] = zeroBitPlanes;
  17510. }
  17511. }
  17512. this.bitsDecoded = bitsDecoded;
  17513. this.reset();
  17514. }
  17515. BitModel.prototype = {
  17516. setDecoder: function BitModel_setDecoder(decoder) {
  17517. this.decoder = decoder;
  17518. },
  17519. reset: function BitModel_reset() {
  17520. // We have 17 contexts that are accessed via context labels,
  17521. // plus the uniform and runlength context.
  17522. this.contexts = new Int8Array(19);
  17523. // Contexts are packed into 1 byte:
  17524. // highest 7 bits carry the index, lowest bit carries mps
  17525. this.contexts[0] = 4 << 1 | 0;
  17526. this.contexts[UNIFORM_CONTEXT] = 46 << 1 | 0;
  17527. this.contexts[RUNLENGTH_CONTEXT] = 3 << 1 | 0;
  17528. },
  17529. setNeighborsSignificance: function BitModel_setNeighborsSignificance(row, column, index) {
  17530. var neighborsSignificance = this.neighborsSignificance;
  17531. var width = this.width, height = this.height;
  17532. var left = column > 0;
  17533. var right = column + 1 < width;
  17534. var i;
  17535. if (row > 0) {
  17536. i = index - width;
  17537. if (left) {
  17538. neighborsSignificance[i - 1] += 0x10;
  17539. }
  17540. if (right) {
  17541. neighborsSignificance[i + 1] += 0x10;
  17542. }
  17543. neighborsSignificance[i] += 0x04;
  17544. }
  17545. if (row + 1 < height) {
  17546. i = index + width;
  17547. if (left) {
  17548. neighborsSignificance[i - 1] += 0x10;
  17549. }
  17550. if (right) {
  17551. neighborsSignificance[i + 1] += 0x10;
  17552. }
  17553. neighborsSignificance[i] += 0x04;
  17554. }
  17555. if (left) {
  17556. neighborsSignificance[index - 1] += 0x01;
  17557. }
  17558. if (right) {
  17559. neighborsSignificance[index + 1] += 0x01;
  17560. }
  17561. neighborsSignificance[index] |= 0x80;
  17562. },
  17563. runSignificancePropagationPass: function BitModel_runSignificancePropagationPass() {
  17564. var decoder = this.decoder;
  17565. var width = this.width, height = this.height;
  17566. var coefficentsMagnitude = this.coefficentsMagnitude;
  17567. var coefficentsSign = this.coefficentsSign;
  17568. var neighborsSignificance = this.neighborsSignificance;
  17569. var processingFlags = this.processingFlags;
  17570. var contexts = this.contexts;
  17571. var labels = this.contextLabelTable;
  17572. var bitsDecoded = this.bitsDecoded;
  17573. var processedInverseMask = ~1;
  17574. var processedMask = 1;
  17575. var firstMagnitudeBitMask = 2;
  17576. for (var i0 = 0; i0 < height; i0 += 4) {
  17577. for (var j = 0; j < width; j++) {
  17578. var index = i0 * width + j;
  17579. for (var i1 = 0; i1 < 4; i1++, index += width) {
  17580. var i = i0 + i1;
  17581. if (i >= height) {
  17582. break;
  17583. }
  17584. // clear processed flag first
  17585. processingFlags[index] &= processedInverseMask;
  17586. if (coefficentsMagnitude[index] || !neighborsSignificance[index]) {
  17587. continue;
  17588. }
  17589. var contextLabel = labels[neighborsSignificance[index]];
  17590. var decision = decoder.readBit(contexts, contextLabel);
  17591. if (decision) {
  17592. var sign = this.decodeSignBit(i, j, index);
  17593. coefficentsSign[index] = sign;
  17594. coefficentsMagnitude[index] = 1;
  17595. this.setNeighborsSignificance(i, j, index);
  17596. processingFlags[index] |= firstMagnitudeBitMask;
  17597. }
  17598. bitsDecoded[index]++;
  17599. processingFlags[index] |= processedMask;
  17600. }
  17601. }
  17602. }
  17603. },
  17604. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  17605. var width = this.width, height = this.height;
  17606. var coefficentsMagnitude = this.coefficentsMagnitude;
  17607. var coefficentsSign = this.coefficentsSign;
  17608. var contribution, sign0, sign1, significance1;
  17609. var contextLabel, decoded;
  17610. // calculate horizontal contribution
  17611. significance1 = column > 0 && coefficentsMagnitude[index - 1] !== 0;
  17612. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  17613. sign1 = coefficentsSign[index + 1];
  17614. if (significance1) {
  17615. sign0 = coefficentsSign[index - 1];
  17616. contribution = 1 - sign1 - sign0;
  17617. } else {
  17618. contribution = 1 - sign1 - sign1;
  17619. }
  17620. } else if (significance1) {
  17621. sign0 = coefficentsSign[index - 1];
  17622. contribution = 1 - sign0 - sign0;
  17623. } else {
  17624. contribution = 0;
  17625. }
  17626. var horizontalContribution = 3 * contribution;
  17627. // calculate vertical contribution and combine with the horizontal
  17628. significance1 = row > 0 && coefficentsMagnitude[index - width] !== 0;
  17629. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  17630. sign1 = coefficentsSign[index + width];
  17631. if (significance1) {
  17632. sign0 = coefficentsSign[index - width];
  17633. contribution = 1 - sign1 - sign0 + horizontalContribution;
  17634. } else {
  17635. contribution = 1 - sign1 - sign1 + horizontalContribution;
  17636. }
  17637. } else if (significance1) {
  17638. sign0 = coefficentsSign[index - width];
  17639. contribution = 1 - sign0 - sign0 + horizontalContribution;
  17640. } else {
  17641. contribution = horizontalContribution;
  17642. }
  17643. if (contribution >= 0) {
  17644. contextLabel = 9 + contribution;
  17645. decoded = this.decoder.readBit(this.contexts, contextLabel);
  17646. } else {
  17647. contextLabel = 9 - contribution;
  17648. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  17649. }
  17650. return decoded;
  17651. },
  17652. runMagnitudeRefinementPass: function BitModel_runMagnitudeRefinementPass() {
  17653. var decoder = this.decoder;
  17654. var width = this.width, height = this.height;
  17655. var coefficentsMagnitude = this.coefficentsMagnitude;
  17656. var neighborsSignificance = this.neighborsSignificance;
  17657. var contexts = this.contexts;
  17658. var bitsDecoded = this.bitsDecoded;
  17659. var processingFlags = this.processingFlags;
  17660. var processedMask = 1;
  17661. var firstMagnitudeBitMask = 2;
  17662. var length = width * height;
  17663. var width4 = width * 4;
  17664. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  17665. indexNext = Math.min(length, index0 + width4);
  17666. for (var j = 0; j < width; j++) {
  17667. for (var index = index0 + j; index < indexNext; index += width) {
  17668. // significant but not those that have just become
  17669. if (!coefficentsMagnitude[index] || (processingFlags[index] & processedMask) !== 0) {
  17670. continue;
  17671. }
  17672. var contextLabel = 16;
  17673. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  17674. processingFlags[index] ^= firstMagnitudeBitMask;
  17675. // first refinement
  17676. var significance = neighborsSignificance[index] & 127;
  17677. contextLabel = significance === 0 ? 15 : 14;
  17678. }
  17679. var bit = decoder.readBit(contexts, contextLabel);
  17680. coefficentsMagnitude[index] = coefficentsMagnitude[index] << 1 | bit;
  17681. bitsDecoded[index]++;
  17682. processingFlags[index] |= processedMask;
  17683. }
  17684. }
  17685. }
  17686. },
  17687. runCleanupPass: function BitModel_runCleanupPass() {
  17688. var decoder = this.decoder;
  17689. var width = this.width, height = this.height;
  17690. var neighborsSignificance = this.neighborsSignificance;
  17691. var coefficentsMagnitude = this.coefficentsMagnitude;
  17692. var coefficentsSign = this.coefficentsSign;
  17693. var contexts = this.contexts;
  17694. var labels = this.contextLabelTable;
  17695. var bitsDecoded = this.bitsDecoded;
  17696. var processingFlags = this.processingFlags;
  17697. var processedMask = 1;
  17698. var firstMagnitudeBitMask = 2;
  17699. var oneRowDown = width;
  17700. var twoRowsDown = width * 2;
  17701. var threeRowsDown = width * 3;
  17702. var iNext;
  17703. for (var i0 = 0; i0 < height; i0 = iNext) {
  17704. iNext = Math.min(i0 + 4, height);
  17705. var indexBase = i0 * width;
  17706. var checkAllEmpty = i0 + 3 < height;
  17707. for (var j = 0; j < width; j++) {
  17708. var index0 = indexBase + j;
  17709. // using the property: labels[neighborsSignificance[index]] === 0
  17710. // when neighborsSignificance[index] === 0
  17711. var allEmpty = checkAllEmpty && processingFlags[index0] === 0 && processingFlags[index0 + oneRowDown] === 0 && processingFlags[index0 + twoRowsDown] === 0 && processingFlags[index0 + threeRowsDown] === 0 && neighborsSignificance[index0] === 0 && neighborsSignificance[index0 + oneRowDown] === 0 && neighborsSignificance[index0 + twoRowsDown] === 0 && neighborsSignificance[index0 + threeRowsDown] === 0;
  17712. var i1 = 0, index = index0;
  17713. var i = i0, sign;
  17714. if (allEmpty) {
  17715. var hasSignificantCoefficent = decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  17716. if (!hasSignificantCoefficent) {
  17717. bitsDecoded[index0]++;
  17718. bitsDecoded[index0 + oneRowDown]++;
  17719. bitsDecoded[index0 + twoRowsDown]++;
  17720. bitsDecoded[index0 + threeRowsDown]++;
  17721. continue;
  17722. }
  17723. // next column
  17724. i1 = decoder.readBit(contexts, UNIFORM_CONTEXT) << 1 | decoder.readBit(contexts, UNIFORM_CONTEXT);
  17725. if (i1 !== 0) {
  17726. i = i0 + i1;
  17727. index += i1 * width;
  17728. }
  17729. sign = this.decodeSignBit(i, j, index);
  17730. coefficentsSign[index] = sign;
  17731. coefficentsMagnitude[index] = 1;
  17732. this.setNeighborsSignificance(i, j, index);
  17733. processingFlags[index] |= firstMagnitudeBitMask;
  17734. index = index0;
  17735. for (var i2 = i0; i2 <= i; i2++, index += width) {
  17736. bitsDecoded[index]++;
  17737. }
  17738. i1++;
  17739. }
  17740. for (i = i0 + i1; i < iNext; i++, index += width) {
  17741. if (coefficentsMagnitude[index] || (processingFlags[index] & processedMask) !== 0) {
  17742. continue;
  17743. }
  17744. var contextLabel = labels[neighborsSignificance[index]];
  17745. var decision = decoder.readBit(contexts, contextLabel);
  17746. if (decision === 1) {
  17747. sign = this.decodeSignBit(i, j, index);
  17748. coefficentsSign[index] = sign;
  17749. coefficentsMagnitude[index] = 1;
  17750. this.setNeighborsSignificance(i, j, index);
  17751. processingFlags[index] |= firstMagnitudeBitMask;
  17752. }
  17753. bitsDecoded[index]++;
  17754. }
  17755. }
  17756. }
  17757. },
  17758. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  17759. var decoder = this.decoder;
  17760. var contexts = this.contexts;
  17761. var symbol = decoder.readBit(contexts, UNIFORM_CONTEXT) << 3 | decoder.readBit(contexts, UNIFORM_CONTEXT) << 2 | decoder.readBit(contexts, UNIFORM_CONTEXT) << 1 | decoder.readBit(contexts, UNIFORM_CONTEXT);
  17762. if (symbol !== 0xA) {
  17763. error('JPX Error: Invalid segmentation symbol');
  17764. }
  17765. }
  17766. };
  17767. return BitModel;
  17768. }();
  17769. // Section F, Discrete wavelet transformation
  17770. var Transform = function TransformClosure() {
  17771. function Transform() {
  17772. }
  17773. Transform.prototype.calculate = function transformCalculate(subbands, u0, v0) {
  17774. var ll = subbands[0];
  17775. for (var i = 1, ii = subbands.length; i < ii; i++) {
  17776. ll = this.iterate(ll, subbands[i], u0, v0);
  17777. }
  17778. return ll;
  17779. };
  17780. Transform.prototype.extend = function extend(buffer, offset, size) {
  17781. // Section F.3.7 extending... using max extension of 4
  17782. var i1 = offset - 1, j1 = offset + 1;
  17783. var i2 = offset + size - 2, j2 = offset + size;
  17784. buffer[i1--] = buffer[j1++];
  17785. buffer[j2++] = buffer[i2--];
  17786. buffer[i1--] = buffer[j1++];
  17787. buffer[j2++] = buffer[i2--];
  17788. buffer[i1--] = buffer[j1++];
  17789. buffer[j2++] = buffer[i2--];
  17790. buffer[i1] = buffer[j1];
  17791. buffer[j2] = buffer[i2];
  17792. };
  17793. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh, u0, v0) {
  17794. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  17795. var width = hl_lh_hh.width;
  17796. var height = hl_lh_hh.height;
  17797. var items = hl_lh_hh.items;
  17798. var i, j, k, l, u, v;
  17799. // Interleave LL according to Section F.3.3
  17800. for (k = 0, i = 0; i < llHeight; i++) {
  17801. l = i * 2 * width;
  17802. for (j = 0; j < llWidth; j++, k++, l += 2) {
  17803. items[l] = llItems[k];
  17804. }
  17805. }
  17806. // The LL band is not needed anymore.
  17807. llItems = ll.items = null;
  17808. var bufferPadding = 4;
  17809. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  17810. // Section F.3.4 HOR_SR
  17811. if (width === 1) {
  17812. // if width = 1, when u0 even keep items as is, when odd divide by 2
  17813. if ((u0 & 1) !== 0) {
  17814. for (v = 0, k = 0; v < height; v++, k += width) {
  17815. items[k] *= 0.5;
  17816. }
  17817. }
  17818. } else {
  17819. for (v = 0, k = 0; v < height; v++, k += width) {
  17820. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  17821. this.extend(rowBuffer, bufferPadding, width);
  17822. this.filter(rowBuffer, bufferPadding, width);
  17823. items.set(rowBuffer.subarray(bufferPadding, bufferPadding + width), k);
  17824. }
  17825. }
  17826. // Accesses to the items array can take long, because it may not fit into
  17827. // CPU cache and has to be fetched from main memory. Since subsequent
  17828. // accesses to the items array are not local when reading columns, we
  17829. // have a cache miss every time. To reduce cache misses, get up to
  17830. // 'numBuffers' items at a time and store them into the individual
  17831. // buffers. The colBuffers should be small enough to fit into CPU cache.
  17832. var numBuffers = 16;
  17833. var colBuffers = [];
  17834. for (i = 0; i < numBuffers; i++) {
  17835. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  17836. }
  17837. var b, currentBuffer = 0;
  17838. ll = bufferPadding + height;
  17839. // Section F.3.5 VER_SR
  17840. if (height === 1) {
  17841. // if height = 1, when v0 even keep items as is, when odd divide by 2
  17842. if ((v0 & 1) !== 0) {
  17843. for (u = 0; u < width; u++) {
  17844. items[u] *= 0.5;
  17845. }
  17846. }
  17847. } else {
  17848. for (u = 0; u < width; u++) {
  17849. // if we ran out of buffers, copy several image columns at once
  17850. if (currentBuffer === 0) {
  17851. numBuffers = Math.min(width - u, numBuffers);
  17852. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  17853. for (b = 0; b < numBuffers; b++) {
  17854. colBuffers[b][l] = items[k + b];
  17855. }
  17856. }
  17857. currentBuffer = numBuffers;
  17858. }
  17859. currentBuffer--;
  17860. var buffer = colBuffers[currentBuffer];
  17861. this.extend(buffer, bufferPadding, height);
  17862. this.filter(buffer, bufferPadding, height);
  17863. // If this is last buffer in this group of buffers, flush all buffers.
  17864. if (currentBuffer === 0) {
  17865. k = u - numBuffers + 1;
  17866. for (l = bufferPadding; l < ll; k += width, l++) {
  17867. for (b = 0; b < numBuffers; b++) {
  17868. items[k + b] = colBuffers[b][l];
  17869. }
  17870. }
  17871. }
  17872. }
  17873. }
  17874. return {
  17875. width: width,
  17876. height: height,
  17877. items: items
  17878. };
  17879. };
  17880. return Transform;
  17881. }();
  17882. // Section 3.8.2 Irreversible 9-7 filter
  17883. var IrreversibleTransform = function IrreversibleTransformClosure() {
  17884. function IrreversibleTransform() {
  17885. Transform.call(this);
  17886. }
  17887. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  17888. IrreversibleTransform.prototype.filter = function irreversibleTransformFilter(x, offset, length) {
  17889. var len = length >> 1;
  17890. offset = offset | 0;
  17891. var j, n, current, next;
  17892. var alpha = -1.586134342059924;
  17893. var beta = -0.052980118572961;
  17894. var gamma = 0.882911075530934;
  17895. var delta = 0.443506852043971;
  17896. var K = 1.230174104914001;
  17897. var K_ = 1 / K;
  17898. // step 1 is combined with step 3
  17899. // step 2
  17900. j = offset - 3;
  17901. for (n = len + 4; n--; j += 2) {
  17902. x[j] *= K_;
  17903. }
  17904. // step 1 & 3
  17905. j = offset - 2;
  17906. current = delta * x[j - 1];
  17907. for (n = len + 3; n--; j += 2) {
  17908. next = delta * x[j + 1];
  17909. x[j] = K * x[j] - current - next;
  17910. if (n--) {
  17911. j += 2;
  17912. current = delta * x[j + 1];
  17913. x[j] = K * x[j] - current - next;
  17914. } else {
  17915. break;
  17916. }
  17917. }
  17918. // step 4
  17919. j = offset - 1;
  17920. current = gamma * x[j - 1];
  17921. for (n = len + 2; n--; j += 2) {
  17922. next = gamma * x[j + 1];
  17923. x[j] -= current + next;
  17924. if (n--) {
  17925. j += 2;
  17926. current = gamma * x[j + 1];
  17927. x[j] -= current + next;
  17928. } else {
  17929. break;
  17930. }
  17931. }
  17932. // step 5
  17933. j = offset;
  17934. current = beta * x[j - 1];
  17935. for (n = len + 1; n--; j += 2) {
  17936. next = beta * x[j + 1];
  17937. x[j] -= current + next;
  17938. if (n--) {
  17939. j += 2;
  17940. current = beta * x[j + 1];
  17941. x[j] -= current + next;
  17942. } else {
  17943. break;
  17944. }
  17945. }
  17946. // step 6
  17947. if (len !== 0) {
  17948. j = offset + 1;
  17949. current = alpha * x[j - 1];
  17950. for (n = len; n--; j += 2) {
  17951. next = alpha * x[j + 1];
  17952. x[j] -= current + next;
  17953. if (n--) {
  17954. j += 2;
  17955. current = alpha * x[j + 1];
  17956. x[j] -= current + next;
  17957. } else {
  17958. break;
  17959. }
  17960. }
  17961. }
  17962. };
  17963. return IrreversibleTransform;
  17964. }();
  17965. // Section 3.8.1 Reversible 5-3 filter
  17966. var ReversibleTransform = function ReversibleTransformClosure() {
  17967. function ReversibleTransform() {
  17968. Transform.call(this);
  17969. }
  17970. ReversibleTransform.prototype = Object.create(Transform.prototype);
  17971. ReversibleTransform.prototype.filter = function reversibleTransformFilter(x, offset, length) {
  17972. var len = length >> 1;
  17973. offset = offset | 0;
  17974. var j, n;
  17975. for (j = offset, n = len + 1; n--; j += 2) {
  17976. x[j] -= x[j - 1] + x[j + 1] + 2 >> 2;
  17977. }
  17978. for (j = offset + 1, n = len; n--; j += 2) {
  17979. x[j] += x[j - 1] + x[j + 1] >> 1;
  17980. }
  17981. };
  17982. return ReversibleTransform;
  17983. }();
  17984. return JpxImage;
  17985. }();
  17986. exports.JpxImage = JpxImage;
  17987. }));
  17988. (function (root, factory) {
  17989. factory(root.pdfjsCoreMetrics = {}, root.pdfjsSharedUtil);
  17990. }(this, function (exports, sharedUtil) {
  17991. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  17992. // The Metrics object contains glyph widths (in glyph space units).
  17993. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  17994. // space unit corresponds to 1/1000th of text space unit.
  17995. var getMetrics = getLookupTableFactory(function (t) {
  17996. t['Courier'] = 600;
  17997. t['Courier-Bold'] = 600;
  17998. t['Courier-BoldOblique'] = 600;
  17999. t['Courier-Oblique'] = 600;
  18000. t['Helvetica'] = getLookupTableFactory(function (t) {
  18001. t['space'] = 278;
  18002. t['exclam'] = 278;
  18003. t['quotedbl'] = 355;
  18004. t['numbersign'] = 556;
  18005. t['dollar'] = 556;
  18006. t['percent'] = 889;
  18007. t['ampersand'] = 667;
  18008. t['quoteright'] = 222;
  18009. t['parenleft'] = 333;
  18010. t['parenright'] = 333;
  18011. t['asterisk'] = 389;
  18012. t['plus'] = 584;
  18013. t['comma'] = 278;
  18014. t['hyphen'] = 333;
  18015. t['period'] = 278;
  18016. t['slash'] = 278;
  18017. t['zero'] = 556;
  18018. t['one'] = 556;
  18019. t['two'] = 556;
  18020. t['three'] = 556;
  18021. t['four'] = 556;
  18022. t['five'] = 556;
  18023. t['six'] = 556;
  18024. t['seven'] = 556;
  18025. t['eight'] = 556;
  18026. t['nine'] = 556;
  18027. t['colon'] = 278;
  18028. t['semicolon'] = 278;
  18029. t['less'] = 584;
  18030. t['equal'] = 584;
  18031. t['greater'] = 584;
  18032. t['question'] = 556;
  18033. t['at'] = 1015;
  18034. t['A'] = 667;
  18035. t['B'] = 667;
  18036. t['C'] = 722;
  18037. t['D'] = 722;
  18038. t['E'] = 667;
  18039. t['F'] = 611;
  18040. t['G'] = 778;
  18041. t['H'] = 722;
  18042. t['I'] = 278;
  18043. t['J'] = 500;
  18044. t['K'] = 667;
  18045. t['L'] = 556;
  18046. t['M'] = 833;
  18047. t['N'] = 722;
  18048. t['O'] = 778;
  18049. t['P'] = 667;
  18050. t['Q'] = 778;
  18051. t['R'] = 722;
  18052. t['S'] = 667;
  18053. t['T'] = 611;
  18054. t['U'] = 722;
  18055. t['V'] = 667;
  18056. t['W'] = 944;
  18057. t['X'] = 667;
  18058. t['Y'] = 667;
  18059. t['Z'] = 611;
  18060. t['bracketleft'] = 278;
  18061. t['backslash'] = 278;
  18062. t['bracketright'] = 278;
  18063. t['asciicircum'] = 469;
  18064. t['underscore'] = 556;
  18065. t['quoteleft'] = 222;
  18066. t['a'] = 556;
  18067. t['b'] = 556;
  18068. t['c'] = 500;
  18069. t['d'] = 556;
  18070. t['e'] = 556;
  18071. t['f'] = 278;
  18072. t['g'] = 556;
  18073. t['h'] = 556;
  18074. t['i'] = 222;
  18075. t['j'] = 222;
  18076. t['k'] = 500;
  18077. t['l'] = 222;
  18078. t['m'] = 833;
  18079. t['n'] = 556;
  18080. t['o'] = 556;
  18081. t['p'] = 556;
  18082. t['q'] = 556;
  18083. t['r'] = 333;
  18084. t['s'] = 500;
  18085. t['t'] = 278;
  18086. t['u'] = 556;
  18087. t['v'] = 500;
  18088. t['w'] = 722;
  18089. t['x'] = 500;
  18090. t['y'] = 500;
  18091. t['z'] = 500;
  18092. t['braceleft'] = 334;
  18093. t['bar'] = 260;
  18094. t['braceright'] = 334;
  18095. t['asciitilde'] = 584;
  18096. t['exclamdown'] = 333;
  18097. t['cent'] = 556;
  18098. t['sterling'] = 556;
  18099. t['fraction'] = 167;
  18100. t['yen'] = 556;
  18101. t['florin'] = 556;
  18102. t['section'] = 556;
  18103. t['currency'] = 556;
  18104. t['quotesingle'] = 191;
  18105. t['quotedblleft'] = 333;
  18106. t['guillemotleft'] = 556;
  18107. t['guilsinglleft'] = 333;
  18108. t['guilsinglright'] = 333;
  18109. t['fi'] = 500;
  18110. t['fl'] = 500;
  18111. t['endash'] = 556;
  18112. t['dagger'] = 556;
  18113. t['daggerdbl'] = 556;
  18114. t['periodcentered'] = 278;
  18115. t['paragraph'] = 537;
  18116. t['bullet'] = 350;
  18117. t['quotesinglbase'] = 222;
  18118. t['quotedblbase'] = 333;
  18119. t['quotedblright'] = 333;
  18120. t['guillemotright'] = 556;
  18121. t['ellipsis'] = 1000;
  18122. t['perthousand'] = 1000;
  18123. t['questiondown'] = 611;
  18124. t['grave'] = 333;
  18125. t['acute'] = 333;
  18126. t['circumflex'] = 333;
  18127. t['tilde'] = 333;
  18128. t['macron'] = 333;
  18129. t['breve'] = 333;
  18130. t['dotaccent'] = 333;
  18131. t['dieresis'] = 333;
  18132. t['ring'] = 333;
  18133. t['cedilla'] = 333;
  18134. t['hungarumlaut'] = 333;
  18135. t['ogonek'] = 333;
  18136. t['caron'] = 333;
  18137. t['emdash'] = 1000;
  18138. t['AE'] = 1000;
  18139. t['ordfeminine'] = 370;
  18140. t['Lslash'] = 556;
  18141. t['Oslash'] = 778;
  18142. t['OE'] = 1000;
  18143. t['ordmasculine'] = 365;
  18144. t['ae'] = 889;
  18145. t['dotlessi'] = 278;
  18146. t['lslash'] = 222;
  18147. t['oslash'] = 611;
  18148. t['oe'] = 944;
  18149. t['germandbls'] = 611;
  18150. t['Idieresis'] = 278;
  18151. t['eacute'] = 556;
  18152. t['abreve'] = 556;
  18153. t['uhungarumlaut'] = 556;
  18154. t['ecaron'] = 556;
  18155. t['Ydieresis'] = 667;
  18156. t['divide'] = 584;
  18157. t['Yacute'] = 667;
  18158. t['Acircumflex'] = 667;
  18159. t['aacute'] = 556;
  18160. t['Ucircumflex'] = 722;
  18161. t['yacute'] = 500;
  18162. t['scommaaccent'] = 500;
  18163. t['ecircumflex'] = 556;
  18164. t['Uring'] = 722;
  18165. t['Udieresis'] = 722;
  18166. t['aogonek'] = 556;
  18167. t['Uacute'] = 722;
  18168. t['uogonek'] = 556;
  18169. t['Edieresis'] = 667;
  18170. t['Dcroat'] = 722;
  18171. t['commaaccent'] = 250;
  18172. t['copyright'] = 737;
  18173. t['Emacron'] = 667;
  18174. t['ccaron'] = 500;
  18175. t['aring'] = 556;
  18176. t['Ncommaaccent'] = 722;
  18177. t['lacute'] = 222;
  18178. t['agrave'] = 556;
  18179. t['Tcommaaccent'] = 611;
  18180. t['Cacute'] = 722;
  18181. t['atilde'] = 556;
  18182. t['Edotaccent'] = 667;
  18183. t['scaron'] = 500;
  18184. t['scedilla'] = 500;
  18185. t['iacute'] = 278;
  18186. t['lozenge'] = 471;
  18187. t['Rcaron'] = 722;
  18188. t['Gcommaaccent'] = 778;
  18189. t['ucircumflex'] = 556;
  18190. t['acircumflex'] = 556;
  18191. t['Amacron'] = 667;
  18192. t['rcaron'] = 333;
  18193. t['ccedilla'] = 500;
  18194. t['Zdotaccent'] = 611;
  18195. t['Thorn'] = 667;
  18196. t['Omacron'] = 778;
  18197. t['Racute'] = 722;
  18198. t['Sacute'] = 667;
  18199. t['dcaron'] = 643;
  18200. t['Umacron'] = 722;
  18201. t['uring'] = 556;
  18202. t['threesuperior'] = 333;
  18203. t['Ograve'] = 778;
  18204. t['Agrave'] = 667;
  18205. t['Abreve'] = 667;
  18206. t['multiply'] = 584;
  18207. t['uacute'] = 556;
  18208. t['Tcaron'] = 611;
  18209. t['partialdiff'] = 476;
  18210. t['ydieresis'] = 500;
  18211. t['Nacute'] = 722;
  18212. t['icircumflex'] = 278;
  18213. t['Ecircumflex'] = 667;
  18214. t['adieresis'] = 556;
  18215. t['edieresis'] = 556;
  18216. t['cacute'] = 500;
  18217. t['nacute'] = 556;
  18218. t['umacron'] = 556;
  18219. t['Ncaron'] = 722;
  18220. t['Iacute'] = 278;
  18221. t['plusminus'] = 584;
  18222. t['brokenbar'] = 260;
  18223. t['registered'] = 737;
  18224. t['Gbreve'] = 778;
  18225. t['Idotaccent'] = 278;
  18226. t['summation'] = 600;
  18227. t['Egrave'] = 667;
  18228. t['racute'] = 333;
  18229. t['omacron'] = 556;
  18230. t['Zacute'] = 611;
  18231. t['Zcaron'] = 611;
  18232. t['greaterequal'] = 549;
  18233. t['Eth'] = 722;
  18234. t['Ccedilla'] = 722;
  18235. t['lcommaaccent'] = 222;
  18236. t['tcaron'] = 317;
  18237. t['eogonek'] = 556;
  18238. t['Uogonek'] = 722;
  18239. t['Aacute'] = 667;
  18240. t['Adieresis'] = 667;
  18241. t['egrave'] = 556;
  18242. t['zacute'] = 500;
  18243. t['iogonek'] = 222;
  18244. t['Oacute'] = 778;
  18245. t['oacute'] = 556;
  18246. t['amacron'] = 556;
  18247. t['sacute'] = 500;
  18248. t['idieresis'] = 278;
  18249. t['Ocircumflex'] = 778;
  18250. t['Ugrave'] = 722;
  18251. t['Delta'] = 612;
  18252. t['thorn'] = 556;
  18253. t['twosuperior'] = 333;
  18254. t['Odieresis'] = 778;
  18255. t['mu'] = 556;
  18256. t['igrave'] = 278;
  18257. t['ohungarumlaut'] = 556;
  18258. t['Eogonek'] = 667;
  18259. t['dcroat'] = 556;
  18260. t['threequarters'] = 834;
  18261. t['Scedilla'] = 667;
  18262. t['lcaron'] = 299;
  18263. t['Kcommaaccent'] = 667;
  18264. t['Lacute'] = 556;
  18265. t['trademark'] = 1000;
  18266. t['edotaccent'] = 556;
  18267. t['Igrave'] = 278;
  18268. t['Imacron'] = 278;
  18269. t['Lcaron'] = 556;
  18270. t['onehalf'] = 834;
  18271. t['lessequal'] = 549;
  18272. t['ocircumflex'] = 556;
  18273. t['ntilde'] = 556;
  18274. t['Uhungarumlaut'] = 722;
  18275. t['Eacute'] = 667;
  18276. t['emacron'] = 556;
  18277. t['gbreve'] = 556;
  18278. t['onequarter'] = 834;
  18279. t['Scaron'] = 667;
  18280. t['Scommaaccent'] = 667;
  18281. t['Ohungarumlaut'] = 778;
  18282. t['degree'] = 400;
  18283. t['ograve'] = 556;
  18284. t['Ccaron'] = 722;
  18285. t['ugrave'] = 556;
  18286. t['radical'] = 453;
  18287. t['Dcaron'] = 722;
  18288. t['rcommaaccent'] = 333;
  18289. t['Ntilde'] = 722;
  18290. t['otilde'] = 556;
  18291. t['Rcommaaccent'] = 722;
  18292. t['Lcommaaccent'] = 556;
  18293. t['Atilde'] = 667;
  18294. t['Aogonek'] = 667;
  18295. t['Aring'] = 667;
  18296. t['Otilde'] = 778;
  18297. t['zdotaccent'] = 500;
  18298. t['Ecaron'] = 667;
  18299. t['Iogonek'] = 278;
  18300. t['kcommaaccent'] = 500;
  18301. t['minus'] = 584;
  18302. t['Icircumflex'] = 278;
  18303. t['ncaron'] = 556;
  18304. t['tcommaaccent'] = 278;
  18305. t['logicalnot'] = 584;
  18306. t['odieresis'] = 556;
  18307. t['udieresis'] = 556;
  18308. t['notequal'] = 549;
  18309. t['gcommaaccent'] = 556;
  18310. t['eth'] = 556;
  18311. t['zcaron'] = 500;
  18312. t['ncommaaccent'] = 556;
  18313. t['onesuperior'] = 333;
  18314. t['imacron'] = 278;
  18315. t['Euro'] = 556;
  18316. });
  18317. t['Helvetica-Bold'] = getLookupTableFactory(function (t) {
  18318. t['space'] = 278;
  18319. t['exclam'] = 333;
  18320. t['quotedbl'] = 474;
  18321. t['numbersign'] = 556;
  18322. t['dollar'] = 556;
  18323. t['percent'] = 889;
  18324. t['ampersand'] = 722;
  18325. t['quoteright'] = 278;
  18326. t['parenleft'] = 333;
  18327. t['parenright'] = 333;
  18328. t['asterisk'] = 389;
  18329. t['plus'] = 584;
  18330. t['comma'] = 278;
  18331. t['hyphen'] = 333;
  18332. t['period'] = 278;
  18333. t['slash'] = 278;
  18334. t['zero'] = 556;
  18335. t['one'] = 556;
  18336. t['two'] = 556;
  18337. t['three'] = 556;
  18338. t['four'] = 556;
  18339. t['five'] = 556;
  18340. t['six'] = 556;
  18341. t['seven'] = 556;
  18342. t['eight'] = 556;
  18343. t['nine'] = 556;
  18344. t['colon'] = 333;
  18345. t['semicolon'] = 333;
  18346. t['less'] = 584;
  18347. t['equal'] = 584;
  18348. t['greater'] = 584;
  18349. t['question'] = 611;
  18350. t['at'] = 975;
  18351. t['A'] = 722;
  18352. t['B'] = 722;
  18353. t['C'] = 722;
  18354. t['D'] = 722;
  18355. t['E'] = 667;
  18356. t['F'] = 611;
  18357. t['G'] = 778;
  18358. t['H'] = 722;
  18359. t['I'] = 278;
  18360. t['J'] = 556;
  18361. t['K'] = 722;
  18362. t['L'] = 611;
  18363. t['M'] = 833;
  18364. t['N'] = 722;
  18365. t['O'] = 778;
  18366. t['P'] = 667;
  18367. t['Q'] = 778;
  18368. t['R'] = 722;
  18369. t['S'] = 667;
  18370. t['T'] = 611;
  18371. t['U'] = 722;
  18372. t['V'] = 667;
  18373. t['W'] = 944;
  18374. t['X'] = 667;
  18375. t['Y'] = 667;
  18376. t['Z'] = 611;
  18377. t['bracketleft'] = 333;
  18378. t['backslash'] = 278;
  18379. t['bracketright'] = 333;
  18380. t['asciicircum'] = 584;
  18381. t['underscore'] = 556;
  18382. t['quoteleft'] = 278;
  18383. t['a'] = 556;
  18384. t['b'] = 611;
  18385. t['c'] = 556;
  18386. t['d'] = 611;
  18387. t['e'] = 556;
  18388. t['f'] = 333;
  18389. t['g'] = 611;
  18390. t['h'] = 611;
  18391. t['i'] = 278;
  18392. t['j'] = 278;
  18393. t['k'] = 556;
  18394. t['l'] = 278;
  18395. t['m'] = 889;
  18396. t['n'] = 611;
  18397. t['o'] = 611;
  18398. t['p'] = 611;
  18399. t['q'] = 611;
  18400. t['r'] = 389;
  18401. t['s'] = 556;
  18402. t['t'] = 333;
  18403. t['u'] = 611;
  18404. t['v'] = 556;
  18405. t['w'] = 778;
  18406. t['x'] = 556;
  18407. t['y'] = 556;
  18408. t['z'] = 500;
  18409. t['braceleft'] = 389;
  18410. t['bar'] = 280;
  18411. t['braceright'] = 389;
  18412. t['asciitilde'] = 584;
  18413. t['exclamdown'] = 333;
  18414. t['cent'] = 556;
  18415. t['sterling'] = 556;
  18416. t['fraction'] = 167;
  18417. t['yen'] = 556;
  18418. t['florin'] = 556;
  18419. t['section'] = 556;
  18420. t['currency'] = 556;
  18421. t['quotesingle'] = 238;
  18422. t['quotedblleft'] = 500;
  18423. t['guillemotleft'] = 556;
  18424. t['guilsinglleft'] = 333;
  18425. t['guilsinglright'] = 333;
  18426. t['fi'] = 611;
  18427. t['fl'] = 611;
  18428. t['endash'] = 556;
  18429. t['dagger'] = 556;
  18430. t['daggerdbl'] = 556;
  18431. t['periodcentered'] = 278;
  18432. t['paragraph'] = 556;
  18433. t['bullet'] = 350;
  18434. t['quotesinglbase'] = 278;
  18435. t['quotedblbase'] = 500;
  18436. t['quotedblright'] = 500;
  18437. t['guillemotright'] = 556;
  18438. t['ellipsis'] = 1000;
  18439. t['perthousand'] = 1000;
  18440. t['questiondown'] = 611;
  18441. t['grave'] = 333;
  18442. t['acute'] = 333;
  18443. t['circumflex'] = 333;
  18444. t['tilde'] = 333;
  18445. t['macron'] = 333;
  18446. t['breve'] = 333;
  18447. t['dotaccent'] = 333;
  18448. t['dieresis'] = 333;
  18449. t['ring'] = 333;
  18450. t['cedilla'] = 333;
  18451. t['hungarumlaut'] = 333;
  18452. t['ogonek'] = 333;
  18453. t['caron'] = 333;
  18454. t['emdash'] = 1000;
  18455. t['AE'] = 1000;
  18456. t['ordfeminine'] = 370;
  18457. t['Lslash'] = 611;
  18458. t['Oslash'] = 778;
  18459. t['OE'] = 1000;
  18460. t['ordmasculine'] = 365;
  18461. t['ae'] = 889;
  18462. t['dotlessi'] = 278;
  18463. t['lslash'] = 278;
  18464. t['oslash'] = 611;
  18465. t['oe'] = 944;
  18466. t['germandbls'] = 611;
  18467. t['Idieresis'] = 278;
  18468. t['eacute'] = 556;
  18469. t['abreve'] = 556;
  18470. t['uhungarumlaut'] = 611;
  18471. t['ecaron'] = 556;
  18472. t['Ydieresis'] = 667;
  18473. t['divide'] = 584;
  18474. t['Yacute'] = 667;
  18475. t['Acircumflex'] = 722;
  18476. t['aacute'] = 556;
  18477. t['Ucircumflex'] = 722;
  18478. t['yacute'] = 556;
  18479. t['scommaaccent'] = 556;
  18480. t['ecircumflex'] = 556;
  18481. t['Uring'] = 722;
  18482. t['Udieresis'] = 722;
  18483. t['aogonek'] = 556;
  18484. t['Uacute'] = 722;
  18485. t['uogonek'] = 611;
  18486. t['Edieresis'] = 667;
  18487. t['Dcroat'] = 722;
  18488. t['commaaccent'] = 250;
  18489. t['copyright'] = 737;
  18490. t['Emacron'] = 667;
  18491. t['ccaron'] = 556;
  18492. t['aring'] = 556;
  18493. t['Ncommaaccent'] = 722;
  18494. t['lacute'] = 278;
  18495. t['agrave'] = 556;
  18496. t['Tcommaaccent'] = 611;
  18497. t['Cacute'] = 722;
  18498. t['atilde'] = 556;
  18499. t['Edotaccent'] = 667;
  18500. t['scaron'] = 556;
  18501. t['scedilla'] = 556;
  18502. t['iacute'] = 278;
  18503. t['lozenge'] = 494;
  18504. t['Rcaron'] = 722;
  18505. t['Gcommaaccent'] = 778;
  18506. t['ucircumflex'] = 611;
  18507. t['acircumflex'] = 556;
  18508. t['Amacron'] = 722;
  18509. t['rcaron'] = 389;
  18510. t['ccedilla'] = 556;
  18511. t['Zdotaccent'] = 611;
  18512. t['Thorn'] = 667;
  18513. t['Omacron'] = 778;
  18514. t['Racute'] = 722;
  18515. t['Sacute'] = 667;
  18516. t['dcaron'] = 743;
  18517. t['Umacron'] = 722;
  18518. t['uring'] = 611;
  18519. t['threesuperior'] = 333;
  18520. t['Ograve'] = 778;
  18521. t['Agrave'] = 722;
  18522. t['Abreve'] = 722;
  18523. t['multiply'] = 584;
  18524. t['uacute'] = 611;
  18525. t['Tcaron'] = 611;
  18526. t['partialdiff'] = 494;
  18527. t['ydieresis'] = 556;
  18528. t['Nacute'] = 722;
  18529. t['icircumflex'] = 278;
  18530. t['Ecircumflex'] = 667;
  18531. t['adieresis'] = 556;
  18532. t['edieresis'] = 556;
  18533. t['cacute'] = 556;
  18534. t['nacute'] = 611;
  18535. t['umacron'] = 611;
  18536. t['Ncaron'] = 722;
  18537. t['Iacute'] = 278;
  18538. t['plusminus'] = 584;
  18539. t['brokenbar'] = 280;
  18540. t['registered'] = 737;
  18541. t['Gbreve'] = 778;
  18542. t['Idotaccent'] = 278;
  18543. t['summation'] = 600;
  18544. t['Egrave'] = 667;
  18545. t['racute'] = 389;
  18546. t['omacron'] = 611;
  18547. t['Zacute'] = 611;
  18548. t['Zcaron'] = 611;
  18549. t['greaterequal'] = 549;
  18550. t['Eth'] = 722;
  18551. t['Ccedilla'] = 722;
  18552. t['lcommaaccent'] = 278;
  18553. t['tcaron'] = 389;
  18554. t['eogonek'] = 556;
  18555. t['Uogonek'] = 722;
  18556. t['Aacute'] = 722;
  18557. t['Adieresis'] = 722;
  18558. t['egrave'] = 556;
  18559. t['zacute'] = 500;
  18560. t['iogonek'] = 278;
  18561. t['Oacute'] = 778;
  18562. t['oacute'] = 611;
  18563. t['amacron'] = 556;
  18564. t['sacute'] = 556;
  18565. t['idieresis'] = 278;
  18566. t['Ocircumflex'] = 778;
  18567. t['Ugrave'] = 722;
  18568. t['Delta'] = 612;
  18569. t['thorn'] = 611;
  18570. t['twosuperior'] = 333;
  18571. t['Odieresis'] = 778;
  18572. t['mu'] = 611;
  18573. t['igrave'] = 278;
  18574. t['ohungarumlaut'] = 611;
  18575. t['Eogonek'] = 667;
  18576. t['dcroat'] = 611;
  18577. t['threequarters'] = 834;
  18578. t['Scedilla'] = 667;
  18579. t['lcaron'] = 400;
  18580. t['Kcommaaccent'] = 722;
  18581. t['Lacute'] = 611;
  18582. t['trademark'] = 1000;
  18583. t['edotaccent'] = 556;
  18584. t['Igrave'] = 278;
  18585. t['Imacron'] = 278;
  18586. t['Lcaron'] = 611;
  18587. t['onehalf'] = 834;
  18588. t['lessequal'] = 549;
  18589. t['ocircumflex'] = 611;
  18590. t['ntilde'] = 611;
  18591. t['Uhungarumlaut'] = 722;
  18592. t['Eacute'] = 667;
  18593. t['emacron'] = 556;
  18594. t['gbreve'] = 611;
  18595. t['onequarter'] = 834;
  18596. t['Scaron'] = 667;
  18597. t['Scommaaccent'] = 667;
  18598. t['Ohungarumlaut'] = 778;
  18599. t['degree'] = 400;
  18600. t['ograve'] = 611;
  18601. t['Ccaron'] = 722;
  18602. t['ugrave'] = 611;
  18603. t['radical'] = 549;
  18604. t['Dcaron'] = 722;
  18605. t['rcommaaccent'] = 389;
  18606. t['Ntilde'] = 722;
  18607. t['otilde'] = 611;
  18608. t['Rcommaaccent'] = 722;
  18609. t['Lcommaaccent'] = 611;
  18610. t['Atilde'] = 722;
  18611. t['Aogonek'] = 722;
  18612. t['Aring'] = 722;
  18613. t['Otilde'] = 778;
  18614. t['zdotaccent'] = 500;
  18615. t['Ecaron'] = 667;
  18616. t['Iogonek'] = 278;
  18617. t['kcommaaccent'] = 556;
  18618. t['minus'] = 584;
  18619. t['Icircumflex'] = 278;
  18620. t['ncaron'] = 611;
  18621. t['tcommaaccent'] = 333;
  18622. t['logicalnot'] = 584;
  18623. t['odieresis'] = 611;
  18624. t['udieresis'] = 611;
  18625. t['notequal'] = 549;
  18626. t['gcommaaccent'] = 611;
  18627. t['eth'] = 611;
  18628. t['zcaron'] = 500;
  18629. t['ncommaaccent'] = 611;
  18630. t['onesuperior'] = 333;
  18631. t['imacron'] = 278;
  18632. t['Euro'] = 556;
  18633. });
  18634. t['Helvetica-BoldOblique'] = getLookupTableFactory(function (t) {
  18635. t['space'] = 278;
  18636. t['exclam'] = 333;
  18637. t['quotedbl'] = 474;
  18638. t['numbersign'] = 556;
  18639. t['dollar'] = 556;
  18640. t['percent'] = 889;
  18641. t['ampersand'] = 722;
  18642. t['quoteright'] = 278;
  18643. t['parenleft'] = 333;
  18644. t['parenright'] = 333;
  18645. t['asterisk'] = 389;
  18646. t['plus'] = 584;
  18647. t['comma'] = 278;
  18648. t['hyphen'] = 333;
  18649. t['period'] = 278;
  18650. t['slash'] = 278;
  18651. t['zero'] = 556;
  18652. t['one'] = 556;
  18653. t['two'] = 556;
  18654. t['three'] = 556;
  18655. t['four'] = 556;
  18656. t['five'] = 556;
  18657. t['six'] = 556;
  18658. t['seven'] = 556;
  18659. t['eight'] = 556;
  18660. t['nine'] = 556;
  18661. t['colon'] = 333;
  18662. t['semicolon'] = 333;
  18663. t['less'] = 584;
  18664. t['equal'] = 584;
  18665. t['greater'] = 584;
  18666. t['question'] = 611;
  18667. t['at'] = 975;
  18668. t['A'] = 722;
  18669. t['B'] = 722;
  18670. t['C'] = 722;
  18671. t['D'] = 722;
  18672. t['E'] = 667;
  18673. t['F'] = 611;
  18674. t['G'] = 778;
  18675. t['H'] = 722;
  18676. t['I'] = 278;
  18677. t['J'] = 556;
  18678. t['K'] = 722;
  18679. t['L'] = 611;
  18680. t['M'] = 833;
  18681. t['N'] = 722;
  18682. t['O'] = 778;
  18683. t['P'] = 667;
  18684. t['Q'] = 778;
  18685. t['R'] = 722;
  18686. t['S'] = 667;
  18687. t['T'] = 611;
  18688. t['U'] = 722;
  18689. t['V'] = 667;
  18690. t['W'] = 944;
  18691. t['X'] = 667;
  18692. t['Y'] = 667;
  18693. t['Z'] = 611;
  18694. t['bracketleft'] = 333;
  18695. t['backslash'] = 278;
  18696. t['bracketright'] = 333;
  18697. t['asciicircum'] = 584;
  18698. t['underscore'] = 556;
  18699. t['quoteleft'] = 278;
  18700. t['a'] = 556;
  18701. t['b'] = 611;
  18702. t['c'] = 556;
  18703. t['d'] = 611;
  18704. t['e'] = 556;
  18705. t['f'] = 333;
  18706. t['g'] = 611;
  18707. t['h'] = 611;
  18708. t['i'] = 278;
  18709. t['j'] = 278;
  18710. t['k'] = 556;
  18711. t['l'] = 278;
  18712. t['m'] = 889;
  18713. t['n'] = 611;
  18714. t['o'] = 611;
  18715. t['p'] = 611;
  18716. t['q'] = 611;
  18717. t['r'] = 389;
  18718. t['s'] = 556;
  18719. t['t'] = 333;
  18720. t['u'] = 611;
  18721. t['v'] = 556;
  18722. t['w'] = 778;
  18723. t['x'] = 556;
  18724. t['y'] = 556;
  18725. t['z'] = 500;
  18726. t['braceleft'] = 389;
  18727. t['bar'] = 280;
  18728. t['braceright'] = 389;
  18729. t['asciitilde'] = 584;
  18730. t['exclamdown'] = 333;
  18731. t['cent'] = 556;
  18732. t['sterling'] = 556;
  18733. t['fraction'] = 167;
  18734. t['yen'] = 556;
  18735. t['florin'] = 556;
  18736. t['section'] = 556;
  18737. t['currency'] = 556;
  18738. t['quotesingle'] = 238;
  18739. t['quotedblleft'] = 500;
  18740. t['guillemotleft'] = 556;
  18741. t['guilsinglleft'] = 333;
  18742. t['guilsinglright'] = 333;
  18743. t['fi'] = 611;
  18744. t['fl'] = 611;
  18745. t['endash'] = 556;
  18746. t['dagger'] = 556;
  18747. t['daggerdbl'] = 556;
  18748. t['periodcentered'] = 278;
  18749. t['paragraph'] = 556;
  18750. t['bullet'] = 350;
  18751. t['quotesinglbase'] = 278;
  18752. t['quotedblbase'] = 500;
  18753. t['quotedblright'] = 500;
  18754. t['guillemotright'] = 556;
  18755. t['ellipsis'] = 1000;
  18756. t['perthousand'] = 1000;
  18757. t['questiondown'] = 611;
  18758. t['grave'] = 333;
  18759. t['acute'] = 333;
  18760. t['circumflex'] = 333;
  18761. t['tilde'] = 333;
  18762. t['macron'] = 333;
  18763. t['breve'] = 333;
  18764. t['dotaccent'] = 333;
  18765. t['dieresis'] = 333;
  18766. t['ring'] = 333;
  18767. t['cedilla'] = 333;
  18768. t['hungarumlaut'] = 333;
  18769. t['ogonek'] = 333;
  18770. t['caron'] = 333;
  18771. t['emdash'] = 1000;
  18772. t['AE'] = 1000;
  18773. t['ordfeminine'] = 370;
  18774. t['Lslash'] = 611;
  18775. t['Oslash'] = 778;
  18776. t['OE'] = 1000;
  18777. t['ordmasculine'] = 365;
  18778. t['ae'] = 889;
  18779. t['dotlessi'] = 278;
  18780. t['lslash'] = 278;
  18781. t['oslash'] = 611;
  18782. t['oe'] = 944;
  18783. t['germandbls'] = 611;
  18784. t['Idieresis'] = 278;
  18785. t['eacute'] = 556;
  18786. t['abreve'] = 556;
  18787. t['uhungarumlaut'] = 611;
  18788. t['ecaron'] = 556;
  18789. t['Ydieresis'] = 667;
  18790. t['divide'] = 584;
  18791. t['Yacute'] = 667;
  18792. t['Acircumflex'] = 722;
  18793. t['aacute'] = 556;
  18794. t['Ucircumflex'] = 722;
  18795. t['yacute'] = 556;
  18796. t['scommaaccent'] = 556;
  18797. t['ecircumflex'] = 556;
  18798. t['Uring'] = 722;
  18799. t['Udieresis'] = 722;
  18800. t['aogonek'] = 556;
  18801. t['Uacute'] = 722;
  18802. t['uogonek'] = 611;
  18803. t['Edieresis'] = 667;
  18804. t['Dcroat'] = 722;
  18805. t['commaaccent'] = 250;
  18806. t['copyright'] = 737;
  18807. t['Emacron'] = 667;
  18808. t['ccaron'] = 556;
  18809. t['aring'] = 556;
  18810. t['Ncommaaccent'] = 722;
  18811. t['lacute'] = 278;
  18812. t['agrave'] = 556;
  18813. t['Tcommaaccent'] = 611;
  18814. t['Cacute'] = 722;
  18815. t['atilde'] = 556;
  18816. t['Edotaccent'] = 667;
  18817. t['scaron'] = 556;
  18818. t['scedilla'] = 556;
  18819. t['iacute'] = 278;
  18820. t['lozenge'] = 494;
  18821. t['Rcaron'] = 722;
  18822. t['Gcommaaccent'] = 778;
  18823. t['ucircumflex'] = 611;
  18824. t['acircumflex'] = 556;
  18825. t['Amacron'] = 722;
  18826. t['rcaron'] = 389;
  18827. t['ccedilla'] = 556;
  18828. t['Zdotaccent'] = 611;
  18829. t['Thorn'] = 667;
  18830. t['Omacron'] = 778;
  18831. t['Racute'] = 722;
  18832. t['Sacute'] = 667;
  18833. t['dcaron'] = 743;
  18834. t['Umacron'] = 722;
  18835. t['uring'] = 611;
  18836. t['threesuperior'] = 333;
  18837. t['Ograve'] = 778;
  18838. t['Agrave'] = 722;
  18839. t['Abreve'] = 722;
  18840. t['multiply'] = 584;
  18841. t['uacute'] = 611;
  18842. t['Tcaron'] = 611;
  18843. t['partialdiff'] = 494;
  18844. t['ydieresis'] = 556;
  18845. t['Nacute'] = 722;
  18846. t['icircumflex'] = 278;
  18847. t['Ecircumflex'] = 667;
  18848. t['adieresis'] = 556;
  18849. t['edieresis'] = 556;
  18850. t['cacute'] = 556;
  18851. t['nacute'] = 611;
  18852. t['umacron'] = 611;
  18853. t['Ncaron'] = 722;
  18854. t['Iacute'] = 278;
  18855. t['plusminus'] = 584;
  18856. t['brokenbar'] = 280;
  18857. t['registered'] = 737;
  18858. t['Gbreve'] = 778;
  18859. t['Idotaccent'] = 278;
  18860. t['summation'] = 600;
  18861. t['Egrave'] = 667;
  18862. t['racute'] = 389;
  18863. t['omacron'] = 611;
  18864. t['Zacute'] = 611;
  18865. t['Zcaron'] = 611;
  18866. t['greaterequal'] = 549;
  18867. t['Eth'] = 722;
  18868. t['Ccedilla'] = 722;
  18869. t['lcommaaccent'] = 278;
  18870. t['tcaron'] = 389;
  18871. t['eogonek'] = 556;
  18872. t['Uogonek'] = 722;
  18873. t['Aacute'] = 722;
  18874. t['Adieresis'] = 722;
  18875. t['egrave'] = 556;
  18876. t['zacute'] = 500;
  18877. t['iogonek'] = 278;
  18878. t['Oacute'] = 778;
  18879. t['oacute'] = 611;
  18880. t['amacron'] = 556;
  18881. t['sacute'] = 556;
  18882. t['idieresis'] = 278;
  18883. t['Ocircumflex'] = 778;
  18884. t['Ugrave'] = 722;
  18885. t['Delta'] = 612;
  18886. t['thorn'] = 611;
  18887. t['twosuperior'] = 333;
  18888. t['Odieresis'] = 778;
  18889. t['mu'] = 611;
  18890. t['igrave'] = 278;
  18891. t['ohungarumlaut'] = 611;
  18892. t['Eogonek'] = 667;
  18893. t['dcroat'] = 611;
  18894. t['threequarters'] = 834;
  18895. t['Scedilla'] = 667;
  18896. t['lcaron'] = 400;
  18897. t['Kcommaaccent'] = 722;
  18898. t['Lacute'] = 611;
  18899. t['trademark'] = 1000;
  18900. t['edotaccent'] = 556;
  18901. t['Igrave'] = 278;
  18902. t['Imacron'] = 278;
  18903. t['Lcaron'] = 611;
  18904. t['onehalf'] = 834;
  18905. t['lessequal'] = 549;
  18906. t['ocircumflex'] = 611;
  18907. t['ntilde'] = 611;
  18908. t['Uhungarumlaut'] = 722;
  18909. t['Eacute'] = 667;
  18910. t['emacron'] = 556;
  18911. t['gbreve'] = 611;
  18912. t['onequarter'] = 834;
  18913. t['Scaron'] = 667;
  18914. t['Scommaaccent'] = 667;
  18915. t['Ohungarumlaut'] = 778;
  18916. t['degree'] = 400;
  18917. t['ograve'] = 611;
  18918. t['Ccaron'] = 722;
  18919. t['ugrave'] = 611;
  18920. t['radical'] = 549;
  18921. t['Dcaron'] = 722;
  18922. t['rcommaaccent'] = 389;
  18923. t['Ntilde'] = 722;
  18924. t['otilde'] = 611;
  18925. t['Rcommaaccent'] = 722;
  18926. t['Lcommaaccent'] = 611;
  18927. t['Atilde'] = 722;
  18928. t['Aogonek'] = 722;
  18929. t['Aring'] = 722;
  18930. t['Otilde'] = 778;
  18931. t['zdotaccent'] = 500;
  18932. t['Ecaron'] = 667;
  18933. t['Iogonek'] = 278;
  18934. t['kcommaaccent'] = 556;
  18935. t['minus'] = 584;
  18936. t['Icircumflex'] = 278;
  18937. t['ncaron'] = 611;
  18938. t['tcommaaccent'] = 333;
  18939. t['logicalnot'] = 584;
  18940. t['odieresis'] = 611;
  18941. t['udieresis'] = 611;
  18942. t['notequal'] = 549;
  18943. t['gcommaaccent'] = 611;
  18944. t['eth'] = 611;
  18945. t['zcaron'] = 500;
  18946. t['ncommaaccent'] = 611;
  18947. t['onesuperior'] = 333;
  18948. t['imacron'] = 278;
  18949. t['Euro'] = 556;
  18950. });
  18951. t['Helvetica-Oblique'] = getLookupTableFactory(function (t) {
  18952. t['space'] = 278;
  18953. t['exclam'] = 278;
  18954. t['quotedbl'] = 355;
  18955. t['numbersign'] = 556;
  18956. t['dollar'] = 556;
  18957. t['percent'] = 889;
  18958. t['ampersand'] = 667;
  18959. t['quoteright'] = 222;
  18960. t['parenleft'] = 333;
  18961. t['parenright'] = 333;
  18962. t['asterisk'] = 389;
  18963. t['plus'] = 584;
  18964. t['comma'] = 278;
  18965. t['hyphen'] = 333;
  18966. t['period'] = 278;
  18967. t['slash'] = 278;
  18968. t['zero'] = 556;
  18969. t['one'] = 556;
  18970. t['two'] = 556;
  18971. t['three'] = 556;
  18972. t['four'] = 556;
  18973. t['five'] = 556;
  18974. t['six'] = 556;
  18975. t['seven'] = 556;
  18976. t['eight'] = 556;
  18977. t['nine'] = 556;
  18978. t['colon'] = 278;
  18979. t['semicolon'] = 278;
  18980. t['less'] = 584;
  18981. t['equal'] = 584;
  18982. t['greater'] = 584;
  18983. t['question'] = 556;
  18984. t['at'] = 1015;
  18985. t['A'] = 667;
  18986. t['B'] = 667;
  18987. t['C'] = 722;
  18988. t['D'] = 722;
  18989. t['E'] = 667;
  18990. t['F'] = 611;
  18991. t['G'] = 778;
  18992. t['H'] = 722;
  18993. t['I'] = 278;
  18994. t['J'] = 500;
  18995. t['K'] = 667;
  18996. t['L'] = 556;
  18997. t['M'] = 833;
  18998. t['N'] = 722;
  18999. t['O'] = 778;
  19000. t['P'] = 667;
  19001. t['Q'] = 778;
  19002. t['R'] = 722;
  19003. t['S'] = 667;
  19004. t['T'] = 611;
  19005. t['U'] = 722;
  19006. t['V'] = 667;
  19007. t['W'] = 944;
  19008. t['X'] = 667;
  19009. t['Y'] = 667;
  19010. t['Z'] = 611;
  19011. t['bracketleft'] = 278;
  19012. t['backslash'] = 278;
  19013. t['bracketright'] = 278;
  19014. t['asciicircum'] = 469;
  19015. t['underscore'] = 556;
  19016. t['quoteleft'] = 222;
  19017. t['a'] = 556;
  19018. t['b'] = 556;
  19019. t['c'] = 500;
  19020. t['d'] = 556;
  19021. t['e'] = 556;
  19022. t['f'] = 278;
  19023. t['g'] = 556;
  19024. t['h'] = 556;
  19025. t['i'] = 222;
  19026. t['j'] = 222;
  19027. t['k'] = 500;
  19028. t['l'] = 222;
  19029. t['m'] = 833;
  19030. t['n'] = 556;
  19031. t['o'] = 556;
  19032. t['p'] = 556;
  19033. t['q'] = 556;
  19034. t['r'] = 333;
  19035. t['s'] = 500;
  19036. t['t'] = 278;
  19037. t['u'] = 556;
  19038. t['v'] = 500;
  19039. t['w'] = 722;
  19040. t['x'] = 500;
  19041. t['y'] = 500;
  19042. t['z'] = 500;
  19043. t['braceleft'] = 334;
  19044. t['bar'] = 260;
  19045. t['braceright'] = 334;
  19046. t['asciitilde'] = 584;
  19047. t['exclamdown'] = 333;
  19048. t['cent'] = 556;
  19049. t['sterling'] = 556;
  19050. t['fraction'] = 167;
  19051. t['yen'] = 556;
  19052. t['florin'] = 556;
  19053. t['section'] = 556;
  19054. t['currency'] = 556;
  19055. t['quotesingle'] = 191;
  19056. t['quotedblleft'] = 333;
  19057. t['guillemotleft'] = 556;
  19058. t['guilsinglleft'] = 333;
  19059. t['guilsinglright'] = 333;
  19060. t['fi'] = 500;
  19061. t['fl'] = 500;
  19062. t['endash'] = 556;
  19063. t['dagger'] = 556;
  19064. t['daggerdbl'] = 556;
  19065. t['periodcentered'] = 278;
  19066. t['paragraph'] = 537;
  19067. t['bullet'] = 350;
  19068. t['quotesinglbase'] = 222;
  19069. t['quotedblbase'] = 333;
  19070. t['quotedblright'] = 333;
  19071. t['guillemotright'] = 556;
  19072. t['ellipsis'] = 1000;
  19073. t['perthousand'] = 1000;
  19074. t['questiondown'] = 611;
  19075. t['grave'] = 333;
  19076. t['acute'] = 333;
  19077. t['circumflex'] = 333;
  19078. t['tilde'] = 333;
  19079. t['macron'] = 333;
  19080. t['breve'] = 333;
  19081. t['dotaccent'] = 333;
  19082. t['dieresis'] = 333;
  19083. t['ring'] = 333;
  19084. t['cedilla'] = 333;
  19085. t['hungarumlaut'] = 333;
  19086. t['ogonek'] = 333;
  19087. t['caron'] = 333;
  19088. t['emdash'] = 1000;
  19089. t['AE'] = 1000;
  19090. t['ordfeminine'] = 370;
  19091. t['Lslash'] = 556;
  19092. t['Oslash'] = 778;
  19093. t['OE'] = 1000;
  19094. t['ordmasculine'] = 365;
  19095. t['ae'] = 889;
  19096. t['dotlessi'] = 278;
  19097. t['lslash'] = 222;
  19098. t['oslash'] = 611;
  19099. t['oe'] = 944;
  19100. t['germandbls'] = 611;
  19101. t['Idieresis'] = 278;
  19102. t['eacute'] = 556;
  19103. t['abreve'] = 556;
  19104. t['uhungarumlaut'] = 556;
  19105. t['ecaron'] = 556;
  19106. t['Ydieresis'] = 667;
  19107. t['divide'] = 584;
  19108. t['Yacute'] = 667;
  19109. t['Acircumflex'] = 667;
  19110. t['aacute'] = 556;
  19111. t['Ucircumflex'] = 722;
  19112. t['yacute'] = 500;
  19113. t['scommaaccent'] = 500;
  19114. t['ecircumflex'] = 556;
  19115. t['Uring'] = 722;
  19116. t['Udieresis'] = 722;
  19117. t['aogonek'] = 556;
  19118. t['Uacute'] = 722;
  19119. t['uogonek'] = 556;
  19120. t['Edieresis'] = 667;
  19121. t['Dcroat'] = 722;
  19122. t['commaaccent'] = 250;
  19123. t['copyright'] = 737;
  19124. t['Emacron'] = 667;
  19125. t['ccaron'] = 500;
  19126. t['aring'] = 556;
  19127. t['Ncommaaccent'] = 722;
  19128. t['lacute'] = 222;
  19129. t['agrave'] = 556;
  19130. t['Tcommaaccent'] = 611;
  19131. t['Cacute'] = 722;
  19132. t['atilde'] = 556;
  19133. t['Edotaccent'] = 667;
  19134. t['scaron'] = 500;
  19135. t['scedilla'] = 500;
  19136. t['iacute'] = 278;
  19137. t['lozenge'] = 471;
  19138. t['Rcaron'] = 722;
  19139. t['Gcommaaccent'] = 778;
  19140. t['ucircumflex'] = 556;
  19141. t['acircumflex'] = 556;
  19142. t['Amacron'] = 667;
  19143. t['rcaron'] = 333;
  19144. t['ccedilla'] = 500;
  19145. t['Zdotaccent'] = 611;
  19146. t['Thorn'] = 667;
  19147. t['Omacron'] = 778;
  19148. t['Racute'] = 722;
  19149. t['Sacute'] = 667;
  19150. t['dcaron'] = 643;
  19151. t['Umacron'] = 722;
  19152. t['uring'] = 556;
  19153. t['threesuperior'] = 333;
  19154. t['Ograve'] = 778;
  19155. t['Agrave'] = 667;
  19156. t['Abreve'] = 667;
  19157. t['multiply'] = 584;
  19158. t['uacute'] = 556;
  19159. t['Tcaron'] = 611;
  19160. t['partialdiff'] = 476;
  19161. t['ydieresis'] = 500;
  19162. t['Nacute'] = 722;
  19163. t['icircumflex'] = 278;
  19164. t['Ecircumflex'] = 667;
  19165. t['adieresis'] = 556;
  19166. t['edieresis'] = 556;
  19167. t['cacute'] = 500;
  19168. t['nacute'] = 556;
  19169. t['umacron'] = 556;
  19170. t['Ncaron'] = 722;
  19171. t['Iacute'] = 278;
  19172. t['plusminus'] = 584;
  19173. t['brokenbar'] = 260;
  19174. t['registered'] = 737;
  19175. t['Gbreve'] = 778;
  19176. t['Idotaccent'] = 278;
  19177. t['summation'] = 600;
  19178. t['Egrave'] = 667;
  19179. t['racute'] = 333;
  19180. t['omacron'] = 556;
  19181. t['Zacute'] = 611;
  19182. t['Zcaron'] = 611;
  19183. t['greaterequal'] = 549;
  19184. t['Eth'] = 722;
  19185. t['Ccedilla'] = 722;
  19186. t['lcommaaccent'] = 222;
  19187. t['tcaron'] = 317;
  19188. t['eogonek'] = 556;
  19189. t['Uogonek'] = 722;
  19190. t['Aacute'] = 667;
  19191. t['Adieresis'] = 667;
  19192. t['egrave'] = 556;
  19193. t['zacute'] = 500;
  19194. t['iogonek'] = 222;
  19195. t['Oacute'] = 778;
  19196. t['oacute'] = 556;
  19197. t['amacron'] = 556;
  19198. t['sacute'] = 500;
  19199. t['idieresis'] = 278;
  19200. t['Ocircumflex'] = 778;
  19201. t['Ugrave'] = 722;
  19202. t['Delta'] = 612;
  19203. t['thorn'] = 556;
  19204. t['twosuperior'] = 333;
  19205. t['Odieresis'] = 778;
  19206. t['mu'] = 556;
  19207. t['igrave'] = 278;
  19208. t['ohungarumlaut'] = 556;
  19209. t['Eogonek'] = 667;
  19210. t['dcroat'] = 556;
  19211. t['threequarters'] = 834;
  19212. t['Scedilla'] = 667;
  19213. t['lcaron'] = 299;
  19214. t['Kcommaaccent'] = 667;
  19215. t['Lacute'] = 556;
  19216. t['trademark'] = 1000;
  19217. t['edotaccent'] = 556;
  19218. t['Igrave'] = 278;
  19219. t['Imacron'] = 278;
  19220. t['Lcaron'] = 556;
  19221. t['onehalf'] = 834;
  19222. t['lessequal'] = 549;
  19223. t['ocircumflex'] = 556;
  19224. t['ntilde'] = 556;
  19225. t['Uhungarumlaut'] = 722;
  19226. t['Eacute'] = 667;
  19227. t['emacron'] = 556;
  19228. t['gbreve'] = 556;
  19229. t['onequarter'] = 834;
  19230. t['Scaron'] = 667;
  19231. t['Scommaaccent'] = 667;
  19232. t['Ohungarumlaut'] = 778;
  19233. t['degree'] = 400;
  19234. t['ograve'] = 556;
  19235. t['Ccaron'] = 722;
  19236. t['ugrave'] = 556;
  19237. t['radical'] = 453;
  19238. t['Dcaron'] = 722;
  19239. t['rcommaaccent'] = 333;
  19240. t['Ntilde'] = 722;
  19241. t['otilde'] = 556;
  19242. t['Rcommaaccent'] = 722;
  19243. t['Lcommaaccent'] = 556;
  19244. t['Atilde'] = 667;
  19245. t['Aogonek'] = 667;
  19246. t['Aring'] = 667;
  19247. t['Otilde'] = 778;
  19248. t['zdotaccent'] = 500;
  19249. t['Ecaron'] = 667;
  19250. t['Iogonek'] = 278;
  19251. t['kcommaaccent'] = 500;
  19252. t['minus'] = 584;
  19253. t['Icircumflex'] = 278;
  19254. t['ncaron'] = 556;
  19255. t['tcommaaccent'] = 278;
  19256. t['logicalnot'] = 584;
  19257. t['odieresis'] = 556;
  19258. t['udieresis'] = 556;
  19259. t['notequal'] = 549;
  19260. t['gcommaaccent'] = 556;
  19261. t['eth'] = 556;
  19262. t['zcaron'] = 500;
  19263. t['ncommaaccent'] = 556;
  19264. t['onesuperior'] = 333;
  19265. t['imacron'] = 278;
  19266. t['Euro'] = 556;
  19267. });
  19268. t['Symbol'] = getLookupTableFactory(function (t) {
  19269. t['space'] = 250;
  19270. t['exclam'] = 333;
  19271. t['universal'] = 713;
  19272. t['numbersign'] = 500;
  19273. t['existential'] = 549;
  19274. t['percent'] = 833;
  19275. t['ampersand'] = 778;
  19276. t['suchthat'] = 439;
  19277. t['parenleft'] = 333;
  19278. t['parenright'] = 333;
  19279. t['asteriskmath'] = 500;
  19280. t['plus'] = 549;
  19281. t['comma'] = 250;
  19282. t['minus'] = 549;
  19283. t['period'] = 250;
  19284. t['slash'] = 278;
  19285. t['zero'] = 500;
  19286. t['one'] = 500;
  19287. t['two'] = 500;
  19288. t['three'] = 500;
  19289. t['four'] = 500;
  19290. t['five'] = 500;
  19291. t['six'] = 500;
  19292. t['seven'] = 500;
  19293. t['eight'] = 500;
  19294. t['nine'] = 500;
  19295. t['colon'] = 278;
  19296. t['semicolon'] = 278;
  19297. t['less'] = 549;
  19298. t['equal'] = 549;
  19299. t['greater'] = 549;
  19300. t['question'] = 444;
  19301. t['congruent'] = 549;
  19302. t['Alpha'] = 722;
  19303. t['Beta'] = 667;
  19304. t['Chi'] = 722;
  19305. t['Delta'] = 612;
  19306. t['Epsilon'] = 611;
  19307. t['Phi'] = 763;
  19308. t['Gamma'] = 603;
  19309. t['Eta'] = 722;
  19310. t['Iota'] = 333;
  19311. t['theta1'] = 631;
  19312. t['Kappa'] = 722;
  19313. t['Lambda'] = 686;
  19314. t['Mu'] = 889;
  19315. t['Nu'] = 722;
  19316. t['Omicron'] = 722;
  19317. t['Pi'] = 768;
  19318. t['Theta'] = 741;
  19319. t['Rho'] = 556;
  19320. t['Sigma'] = 592;
  19321. t['Tau'] = 611;
  19322. t['Upsilon'] = 690;
  19323. t['sigma1'] = 439;
  19324. t['Omega'] = 768;
  19325. t['Xi'] = 645;
  19326. t['Psi'] = 795;
  19327. t['Zeta'] = 611;
  19328. t['bracketleft'] = 333;
  19329. t['therefore'] = 863;
  19330. t['bracketright'] = 333;
  19331. t['perpendicular'] = 658;
  19332. t['underscore'] = 500;
  19333. t['radicalex'] = 500;
  19334. t['alpha'] = 631;
  19335. t['beta'] = 549;
  19336. t['chi'] = 549;
  19337. t['delta'] = 494;
  19338. t['epsilon'] = 439;
  19339. t['phi'] = 521;
  19340. t['gamma'] = 411;
  19341. t['eta'] = 603;
  19342. t['iota'] = 329;
  19343. t['phi1'] = 603;
  19344. t['kappa'] = 549;
  19345. t['lambda'] = 549;
  19346. t['mu'] = 576;
  19347. t['nu'] = 521;
  19348. t['omicron'] = 549;
  19349. t['pi'] = 549;
  19350. t['theta'] = 521;
  19351. t['rho'] = 549;
  19352. t['sigma'] = 603;
  19353. t['tau'] = 439;
  19354. t['upsilon'] = 576;
  19355. t['omega1'] = 713;
  19356. t['omega'] = 686;
  19357. t['xi'] = 493;
  19358. t['psi'] = 686;
  19359. t['zeta'] = 494;
  19360. t['braceleft'] = 480;
  19361. t['bar'] = 200;
  19362. t['braceright'] = 480;
  19363. t['similar'] = 549;
  19364. t['Euro'] = 750;
  19365. t['Upsilon1'] = 620;
  19366. t['minute'] = 247;
  19367. t['lessequal'] = 549;
  19368. t['fraction'] = 167;
  19369. t['infinity'] = 713;
  19370. t['florin'] = 500;
  19371. t['club'] = 753;
  19372. t['diamond'] = 753;
  19373. t['heart'] = 753;
  19374. t['spade'] = 753;
  19375. t['arrowboth'] = 1042;
  19376. t['arrowleft'] = 987;
  19377. t['arrowup'] = 603;
  19378. t['arrowright'] = 987;
  19379. t['arrowdown'] = 603;
  19380. t['degree'] = 400;
  19381. t['plusminus'] = 549;
  19382. t['second'] = 411;
  19383. t['greaterequal'] = 549;
  19384. t['multiply'] = 549;
  19385. t['proportional'] = 713;
  19386. t['partialdiff'] = 494;
  19387. t['bullet'] = 460;
  19388. t['divide'] = 549;
  19389. t['notequal'] = 549;
  19390. t['equivalence'] = 549;
  19391. t['approxequal'] = 549;
  19392. t['ellipsis'] = 1000;
  19393. t['arrowvertex'] = 603;
  19394. t['arrowhorizex'] = 1000;
  19395. t['carriagereturn'] = 658;
  19396. t['aleph'] = 823;
  19397. t['Ifraktur'] = 686;
  19398. t['Rfraktur'] = 795;
  19399. t['weierstrass'] = 987;
  19400. t['circlemultiply'] = 768;
  19401. t['circleplus'] = 768;
  19402. t['emptyset'] = 823;
  19403. t['intersection'] = 768;
  19404. t['union'] = 768;
  19405. t['propersuperset'] = 713;
  19406. t['reflexsuperset'] = 713;
  19407. t['notsubset'] = 713;
  19408. t['propersubset'] = 713;
  19409. t['reflexsubset'] = 713;
  19410. t['element'] = 713;
  19411. t['notelement'] = 713;
  19412. t['angle'] = 768;
  19413. t['gradient'] = 713;
  19414. t['registerserif'] = 790;
  19415. t['copyrightserif'] = 790;
  19416. t['trademarkserif'] = 890;
  19417. t['product'] = 823;
  19418. t['radical'] = 549;
  19419. t['dotmath'] = 250;
  19420. t['logicalnot'] = 713;
  19421. t['logicaland'] = 603;
  19422. t['logicalor'] = 603;
  19423. t['arrowdblboth'] = 1042;
  19424. t['arrowdblleft'] = 987;
  19425. t['arrowdblup'] = 603;
  19426. t['arrowdblright'] = 987;
  19427. t['arrowdbldown'] = 603;
  19428. t['lozenge'] = 494;
  19429. t['angleleft'] = 329;
  19430. t['registersans'] = 790;
  19431. t['copyrightsans'] = 790;
  19432. t['trademarksans'] = 786;
  19433. t['summation'] = 713;
  19434. t['parenlefttp'] = 384;
  19435. t['parenleftex'] = 384;
  19436. t['parenleftbt'] = 384;
  19437. t['bracketlefttp'] = 384;
  19438. t['bracketleftex'] = 384;
  19439. t['bracketleftbt'] = 384;
  19440. t['bracelefttp'] = 494;
  19441. t['braceleftmid'] = 494;
  19442. t['braceleftbt'] = 494;
  19443. t['braceex'] = 494;
  19444. t['angleright'] = 329;
  19445. t['integral'] = 274;
  19446. t['integraltp'] = 686;
  19447. t['integralex'] = 686;
  19448. t['integralbt'] = 686;
  19449. t['parenrighttp'] = 384;
  19450. t['parenrightex'] = 384;
  19451. t['parenrightbt'] = 384;
  19452. t['bracketrighttp'] = 384;
  19453. t['bracketrightex'] = 384;
  19454. t['bracketrightbt'] = 384;
  19455. t['bracerighttp'] = 494;
  19456. t['bracerightmid'] = 494;
  19457. t['bracerightbt'] = 494;
  19458. t['apple'] = 790;
  19459. });
  19460. t['Times-Roman'] = getLookupTableFactory(function (t) {
  19461. t['space'] = 250;
  19462. t['exclam'] = 333;
  19463. t['quotedbl'] = 408;
  19464. t['numbersign'] = 500;
  19465. t['dollar'] = 500;
  19466. t['percent'] = 833;
  19467. t['ampersand'] = 778;
  19468. t['quoteright'] = 333;
  19469. t['parenleft'] = 333;
  19470. t['parenright'] = 333;
  19471. t['asterisk'] = 500;
  19472. t['plus'] = 564;
  19473. t['comma'] = 250;
  19474. t['hyphen'] = 333;
  19475. t['period'] = 250;
  19476. t['slash'] = 278;
  19477. t['zero'] = 500;
  19478. t['one'] = 500;
  19479. t['two'] = 500;
  19480. t['three'] = 500;
  19481. t['four'] = 500;
  19482. t['five'] = 500;
  19483. t['six'] = 500;
  19484. t['seven'] = 500;
  19485. t['eight'] = 500;
  19486. t['nine'] = 500;
  19487. t['colon'] = 278;
  19488. t['semicolon'] = 278;
  19489. t['less'] = 564;
  19490. t['equal'] = 564;
  19491. t['greater'] = 564;
  19492. t['question'] = 444;
  19493. t['at'] = 921;
  19494. t['A'] = 722;
  19495. t['B'] = 667;
  19496. t['C'] = 667;
  19497. t['D'] = 722;
  19498. t['E'] = 611;
  19499. t['F'] = 556;
  19500. t['G'] = 722;
  19501. t['H'] = 722;
  19502. t['I'] = 333;
  19503. t['J'] = 389;
  19504. t['K'] = 722;
  19505. t['L'] = 611;
  19506. t['M'] = 889;
  19507. t['N'] = 722;
  19508. t['O'] = 722;
  19509. t['P'] = 556;
  19510. t['Q'] = 722;
  19511. t['R'] = 667;
  19512. t['S'] = 556;
  19513. t['T'] = 611;
  19514. t['U'] = 722;
  19515. t['V'] = 722;
  19516. t['W'] = 944;
  19517. t['X'] = 722;
  19518. t['Y'] = 722;
  19519. t['Z'] = 611;
  19520. t['bracketleft'] = 333;
  19521. t['backslash'] = 278;
  19522. t['bracketright'] = 333;
  19523. t['asciicircum'] = 469;
  19524. t['underscore'] = 500;
  19525. t['quoteleft'] = 333;
  19526. t['a'] = 444;
  19527. t['b'] = 500;
  19528. t['c'] = 444;
  19529. t['d'] = 500;
  19530. t['e'] = 444;
  19531. t['f'] = 333;
  19532. t['g'] = 500;
  19533. t['h'] = 500;
  19534. t['i'] = 278;
  19535. t['j'] = 278;
  19536. t['k'] = 500;
  19537. t['l'] = 278;
  19538. t['m'] = 778;
  19539. t['n'] = 500;
  19540. t['o'] = 500;
  19541. t['p'] = 500;
  19542. t['q'] = 500;
  19543. t['r'] = 333;
  19544. t['s'] = 389;
  19545. t['t'] = 278;
  19546. t['u'] = 500;
  19547. t['v'] = 500;
  19548. t['w'] = 722;
  19549. t['x'] = 500;
  19550. t['y'] = 500;
  19551. t['z'] = 444;
  19552. t['braceleft'] = 480;
  19553. t['bar'] = 200;
  19554. t['braceright'] = 480;
  19555. t['asciitilde'] = 541;
  19556. t['exclamdown'] = 333;
  19557. t['cent'] = 500;
  19558. t['sterling'] = 500;
  19559. t['fraction'] = 167;
  19560. t['yen'] = 500;
  19561. t['florin'] = 500;
  19562. t['section'] = 500;
  19563. t['currency'] = 500;
  19564. t['quotesingle'] = 180;
  19565. t['quotedblleft'] = 444;
  19566. t['guillemotleft'] = 500;
  19567. t['guilsinglleft'] = 333;
  19568. t['guilsinglright'] = 333;
  19569. t['fi'] = 556;
  19570. t['fl'] = 556;
  19571. t['endash'] = 500;
  19572. t['dagger'] = 500;
  19573. t['daggerdbl'] = 500;
  19574. t['periodcentered'] = 250;
  19575. t['paragraph'] = 453;
  19576. t['bullet'] = 350;
  19577. t['quotesinglbase'] = 333;
  19578. t['quotedblbase'] = 444;
  19579. t['quotedblright'] = 444;
  19580. t['guillemotright'] = 500;
  19581. t['ellipsis'] = 1000;
  19582. t['perthousand'] = 1000;
  19583. t['questiondown'] = 444;
  19584. t['grave'] = 333;
  19585. t['acute'] = 333;
  19586. t['circumflex'] = 333;
  19587. t['tilde'] = 333;
  19588. t['macron'] = 333;
  19589. t['breve'] = 333;
  19590. t['dotaccent'] = 333;
  19591. t['dieresis'] = 333;
  19592. t['ring'] = 333;
  19593. t['cedilla'] = 333;
  19594. t['hungarumlaut'] = 333;
  19595. t['ogonek'] = 333;
  19596. t['caron'] = 333;
  19597. t['emdash'] = 1000;
  19598. t['AE'] = 889;
  19599. t['ordfeminine'] = 276;
  19600. t['Lslash'] = 611;
  19601. t['Oslash'] = 722;
  19602. t['OE'] = 889;
  19603. t['ordmasculine'] = 310;
  19604. t['ae'] = 667;
  19605. t['dotlessi'] = 278;
  19606. t['lslash'] = 278;
  19607. t['oslash'] = 500;
  19608. t['oe'] = 722;
  19609. t['germandbls'] = 500;
  19610. t['Idieresis'] = 333;
  19611. t['eacute'] = 444;
  19612. t['abreve'] = 444;
  19613. t['uhungarumlaut'] = 500;
  19614. t['ecaron'] = 444;
  19615. t['Ydieresis'] = 722;
  19616. t['divide'] = 564;
  19617. t['Yacute'] = 722;
  19618. t['Acircumflex'] = 722;
  19619. t['aacute'] = 444;
  19620. t['Ucircumflex'] = 722;
  19621. t['yacute'] = 500;
  19622. t['scommaaccent'] = 389;
  19623. t['ecircumflex'] = 444;
  19624. t['Uring'] = 722;
  19625. t['Udieresis'] = 722;
  19626. t['aogonek'] = 444;
  19627. t['Uacute'] = 722;
  19628. t['uogonek'] = 500;
  19629. t['Edieresis'] = 611;
  19630. t['Dcroat'] = 722;
  19631. t['commaaccent'] = 250;
  19632. t['copyright'] = 760;
  19633. t['Emacron'] = 611;
  19634. t['ccaron'] = 444;
  19635. t['aring'] = 444;
  19636. t['Ncommaaccent'] = 722;
  19637. t['lacute'] = 278;
  19638. t['agrave'] = 444;
  19639. t['Tcommaaccent'] = 611;
  19640. t['Cacute'] = 667;
  19641. t['atilde'] = 444;
  19642. t['Edotaccent'] = 611;
  19643. t['scaron'] = 389;
  19644. t['scedilla'] = 389;
  19645. t['iacute'] = 278;
  19646. t['lozenge'] = 471;
  19647. t['Rcaron'] = 667;
  19648. t['Gcommaaccent'] = 722;
  19649. t['ucircumflex'] = 500;
  19650. t['acircumflex'] = 444;
  19651. t['Amacron'] = 722;
  19652. t['rcaron'] = 333;
  19653. t['ccedilla'] = 444;
  19654. t['Zdotaccent'] = 611;
  19655. t['Thorn'] = 556;
  19656. t['Omacron'] = 722;
  19657. t['Racute'] = 667;
  19658. t['Sacute'] = 556;
  19659. t['dcaron'] = 588;
  19660. t['Umacron'] = 722;
  19661. t['uring'] = 500;
  19662. t['threesuperior'] = 300;
  19663. t['Ograve'] = 722;
  19664. t['Agrave'] = 722;
  19665. t['Abreve'] = 722;
  19666. t['multiply'] = 564;
  19667. t['uacute'] = 500;
  19668. t['Tcaron'] = 611;
  19669. t['partialdiff'] = 476;
  19670. t['ydieresis'] = 500;
  19671. t['Nacute'] = 722;
  19672. t['icircumflex'] = 278;
  19673. t['Ecircumflex'] = 611;
  19674. t['adieresis'] = 444;
  19675. t['edieresis'] = 444;
  19676. t['cacute'] = 444;
  19677. t['nacute'] = 500;
  19678. t['umacron'] = 500;
  19679. t['Ncaron'] = 722;
  19680. t['Iacute'] = 333;
  19681. t['plusminus'] = 564;
  19682. t['brokenbar'] = 200;
  19683. t['registered'] = 760;
  19684. t['Gbreve'] = 722;
  19685. t['Idotaccent'] = 333;
  19686. t['summation'] = 600;
  19687. t['Egrave'] = 611;
  19688. t['racute'] = 333;
  19689. t['omacron'] = 500;
  19690. t['Zacute'] = 611;
  19691. t['Zcaron'] = 611;
  19692. t['greaterequal'] = 549;
  19693. t['Eth'] = 722;
  19694. t['Ccedilla'] = 667;
  19695. t['lcommaaccent'] = 278;
  19696. t['tcaron'] = 326;
  19697. t['eogonek'] = 444;
  19698. t['Uogonek'] = 722;
  19699. t['Aacute'] = 722;
  19700. t['Adieresis'] = 722;
  19701. t['egrave'] = 444;
  19702. t['zacute'] = 444;
  19703. t['iogonek'] = 278;
  19704. t['Oacute'] = 722;
  19705. t['oacute'] = 500;
  19706. t['amacron'] = 444;
  19707. t['sacute'] = 389;
  19708. t['idieresis'] = 278;
  19709. t['Ocircumflex'] = 722;
  19710. t['Ugrave'] = 722;
  19711. t['Delta'] = 612;
  19712. t['thorn'] = 500;
  19713. t['twosuperior'] = 300;
  19714. t['Odieresis'] = 722;
  19715. t['mu'] = 500;
  19716. t['igrave'] = 278;
  19717. t['ohungarumlaut'] = 500;
  19718. t['Eogonek'] = 611;
  19719. t['dcroat'] = 500;
  19720. t['threequarters'] = 750;
  19721. t['Scedilla'] = 556;
  19722. t['lcaron'] = 344;
  19723. t['Kcommaaccent'] = 722;
  19724. t['Lacute'] = 611;
  19725. t['trademark'] = 980;
  19726. t['edotaccent'] = 444;
  19727. t['Igrave'] = 333;
  19728. t['Imacron'] = 333;
  19729. t['Lcaron'] = 611;
  19730. t['onehalf'] = 750;
  19731. t['lessequal'] = 549;
  19732. t['ocircumflex'] = 500;
  19733. t['ntilde'] = 500;
  19734. t['Uhungarumlaut'] = 722;
  19735. t['Eacute'] = 611;
  19736. t['emacron'] = 444;
  19737. t['gbreve'] = 500;
  19738. t['onequarter'] = 750;
  19739. t['Scaron'] = 556;
  19740. t['Scommaaccent'] = 556;
  19741. t['Ohungarumlaut'] = 722;
  19742. t['degree'] = 400;
  19743. t['ograve'] = 500;
  19744. t['Ccaron'] = 667;
  19745. t['ugrave'] = 500;
  19746. t['radical'] = 453;
  19747. t['Dcaron'] = 722;
  19748. t['rcommaaccent'] = 333;
  19749. t['Ntilde'] = 722;
  19750. t['otilde'] = 500;
  19751. t['Rcommaaccent'] = 667;
  19752. t['Lcommaaccent'] = 611;
  19753. t['Atilde'] = 722;
  19754. t['Aogonek'] = 722;
  19755. t['Aring'] = 722;
  19756. t['Otilde'] = 722;
  19757. t['zdotaccent'] = 444;
  19758. t['Ecaron'] = 611;
  19759. t['Iogonek'] = 333;
  19760. t['kcommaaccent'] = 500;
  19761. t['minus'] = 564;
  19762. t['Icircumflex'] = 333;
  19763. t['ncaron'] = 500;
  19764. t['tcommaaccent'] = 278;
  19765. t['logicalnot'] = 564;
  19766. t['odieresis'] = 500;
  19767. t['udieresis'] = 500;
  19768. t['notequal'] = 549;
  19769. t['gcommaaccent'] = 500;
  19770. t['eth'] = 500;
  19771. t['zcaron'] = 444;
  19772. t['ncommaaccent'] = 500;
  19773. t['onesuperior'] = 300;
  19774. t['imacron'] = 278;
  19775. t['Euro'] = 500;
  19776. });
  19777. t['Times-Bold'] = getLookupTableFactory(function (t) {
  19778. t['space'] = 250;
  19779. t['exclam'] = 333;
  19780. t['quotedbl'] = 555;
  19781. t['numbersign'] = 500;
  19782. t['dollar'] = 500;
  19783. t['percent'] = 1000;
  19784. t['ampersand'] = 833;
  19785. t['quoteright'] = 333;
  19786. t['parenleft'] = 333;
  19787. t['parenright'] = 333;
  19788. t['asterisk'] = 500;
  19789. t['plus'] = 570;
  19790. t['comma'] = 250;
  19791. t['hyphen'] = 333;
  19792. t['period'] = 250;
  19793. t['slash'] = 278;
  19794. t['zero'] = 500;
  19795. t['one'] = 500;
  19796. t['two'] = 500;
  19797. t['three'] = 500;
  19798. t['four'] = 500;
  19799. t['five'] = 500;
  19800. t['six'] = 500;
  19801. t['seven'] = 500;
  19802. t['eight'] = 500;
  19803. t['nine'] = 500;
  19804. t['colon'] = 333;
  19805. t['semicolon'] = 333;
  19806. t['less'] = 570;
  19807. t['equal'] = 570;
  19808. t['greater'] = 570;
  19809. t['question'] = 500;
  19810. t['at'] = 930;
  19811. t['A'] = 722;
  19812. t['B'] = 667;
  19813. t['C'] = 722;
  19814. t['D'] = 722;
  19815. t['E'] = 667;
  19816. t['F'] = 611;
  19817. t['G'] = 778;
  19818. t['H'] = 778;
  19819. t['I'] = 389;
  19820. t['J'] = 500;
  19821. t['K'] = 778;
  19822. t['L'] = 667;
  19823. t['M'] = 944;
  19824. t['N'] = 722;
  19825. t['O'] = 778;
  19826. t['P'] = 611;
  19827. t['Q'] = 778;
  19828. t['R'] = 722;
  19829. t['S'] = 556;
  19830. t['T'] = 667;
  19831. t['U'] = 722;
  19832. t['V'] = 722;
  19833. t['W'] = 1000;
  19834. t['X'] = 722;
  19835. t['Y'] = 722;
  19836. t['Z'] = 667;
  19837. t['bracketleft'] = 333;
  19838. t['backslash'] = 278;
  19839. t['bracketright'] = 333;
  19840. t['asciicircum'] = 581;
  19841. t['underscore'] = 500;
  19842. t['quoteleft'] = 333;
  19843. t['a'] = 500;
  19844. t['b'] = 556;
  19845. t['c'] = 444;
  19846. t['d'] = 556;
  19847. t['e'] = 444;
  19848. t['f'] = 333;
  19849. t['g'] = 500;
  19850. t['h'] = 556;
  19851. t['i'] = 278;
  19852. t['j'] = 333;
  19853. t['k'] = 556;
  19854. t['l'] = 278;
  19855. t['m'] = 833;
  19856. t['n'] = 556;
  19857. t['o'] = 500;
  19858. t['p'] = 556;
  19859. t['q'] = 556;
  19860. t['r'] = 444;
  19861. t['s'] = 389;
  19862. t['t'] = 333;
  19863. t['u'] = 556;
  19864. t['v'] = 500;
  19865. t['w'] = 722;
  19866. t['x'] = 500;
  19867. t['y'] = 500;
  19868. t['z'] = 444;
  19869. t['braceleft'] = 394;
  19870. t['bar'] = 220;
  19871. t['braceright'] = 394;
  19872. t['asciitilde'] = 520;
  19873. t['exclamdown'] = 333;
  19874. t['cent'] = 500;
  19875. t['sterling'] = 500;
  19876. t['fraction'] = 167;
  19877. t['yen'] = 500;
  19878. t['florin'] = 500;
  19879. t['section'] = 500;
  19880. t['currency'] = 500;
  19881. t['quotesingle'] = 278;
  19882. t['quotedblleft'] = 500;
  19883. t['guillemotleft'] = 500;
  19884. t['guilsinglleft'] = 333;
  19885. t['guilsinglright'] = 333;
  19886. t['fi'] = 556;
  19887. t['fl'] = 556;
  19888. t['endash'] = 500;
  19889. t['dagger'] = 500;
  19890. t['daggerdbl'] = 500;
  19891. t['periodcentered'] = 250;
  19892. t['paragraph'] = 540;
  19893. t['bullet'] = 350;
  19894. t['quotesinglbase'] = 333;
  19895. t['quotedblbase'] = 500;
  19896. t['quotedblright'] = 500;
  19897. t['guillemotright'] = 500;
  19898. t['ellipsis'] = 1000;
  19899. t['perthousand'] = 1000;
  19900. t['questiondown'] = 500;
  19901. t['grave'] = 333;
  19902. t['acute'] = 333;
  19903. t['circumflex'] = 333;
  19904. t['tilde'] = 333;
  19905. t['macron'] = 333;
  19906. t['breve'] = 333;
  19907. t['dotaccent'] = 333;
  19908. t['dieresis'] = 333;
  19909. t['ring'] = 333;
  19910. t['cedilla'] = 333;
  19911. t['hungarumlaut'] = 333;
  19912. t['ogonek'] = 333;
  19913. t['caron'] = 333;
  19914. t['emdash'] = 1000;
  19915. t['AE'] = 1000;
  19916. t['ordfeminine'] = 300;
  19917. t['Lslash'] = 667;
  19918. t['Oslash'] = 778;
  19919. t['OE'] = 1000;
  19920. t['ordmasculine'] = 330;
  19921. t['ae'] = 722;
  19922. t['dotlessi'] = 278;
  19923. t['lslash'] = 278;
  19924. t['oslash'] = 500;
  19925. t['oe'] = 722;
  19926. t['germandbls'] = 556;
  19927. t['Idieresis'] = 389;
  19928. t['eacute'] = 444;
  19929. t['abreve'] = 500;
  19930. t['uhungarumlaut'] = 556;
  19931. t['ecaron'] = 444;
  19932. t['Ydieresis'] = 722;
  19933. t['divide'] = 570;
  19934. t['Yacute'] = 722;
  19935. t['Acircumflex'] = 722;
  19936. t['aacute'] = 500;
  19937. t['Ucircumflex'] = 722;
  19938. t['yacute'] = 500;
  19939. t['scommaaccent'] = 389;
  19940. t['ecircumflex'] = 444;
  19941. t['Uring'] = 722;
  19942. t['Udieresis'] = 722;
  19943. t['aogonek'] = 500;
  19944. t['Uacute'] = 722;
  19945. t['uogonek'] = 556;
  19946. t['Edieresis'] = 667;
  19947. t['Dcroat'] = 722;
  19948. t['commaaccent'] = 250;
  19949. t['copyright'] = 747;
  19950. t['Emacron'] = 667;
  19951. t['ccaron'] = 444;
  19952. t['aring'] = 500;
  19953. t['Ncommaaccent'] = 722;
  19954. t['lacute'] = 278;
  19955. t['agrave'] = 500;
  19956. t['Tcommaaccent'] = 667;
  19957. t['Cacute'] = 722;
  19958. t['atilde'] = 500;
  19959. t['Edotaccent'] = 667;
  19960. t['scaron'] = 389;
  19961. t['scedilla'] = 389;
  19962. t['iacute'] = 278;
  19963. t['lozenge'] = 494;
  19964. t['Rcaron'] = 722;
  19965. t['Gcommaaccent'] = 778;
  19966. t['ucircumflex'] = 556;
  19967. t['acircumflex'] = 500;
  19968. t['Amacron'] = 722;
  19969. t['rcaron'] = 444;
  19970. t['ccedilla'] = 444;
  19971. t['Zdotaccent'] = 667;
  19972. t['Thorn'] = 611;
  19973. t['Omacron'] = 778;
  19974. t['Racute'] = 722;
  19975. t['Sacute'] = 556;
  19976. t['dcaron'] = 672;
  19977. t['Umacron'] = 722;
  19978. t['uring'] = 556;
  19979. t['threesuperior'] = 300;
  19980. t['Ograve'] = 778;
  19981. t['Agrave'] = 722;
  19982. t['Abreve'] = 722;
  19983. t['multiply'] = 570;
  19984. t['uacute'] = 556;
  19985. t['Tcaron'] = 667;
  19986. t['partialdiff'] = 494;
  19987. t['ydieresis'] = 500;
  19988. t['Nacute'] = 722;
  19989. t['icircumflex'] = 278;
  19990. t['Ecircumflex'] = 667;
  19991. t['adieresis'] = 500;
  19992. t['edieresis'] = 444;
  19993. t['cacute'] = 444;
  19994. t['nacute'] = 556;
  19995. t['umacron'] = 556;
  19996. t['Ncaron'] = 722;
  19997. t['Iacute'] = 389;
  19998. t['plusminus'] = 570;
  19999. t['brokenbar'] = 220;
  20000. t['registered'] = 747;
  20001. t['Gbreve'] = 778;
  20002. t['Idotaccent'] = 389;
  20003. t['summation'] = 600;
  20004. t['Egrave'] = 667;
  20005. t['racute'] = 444;
  20006. t['omacron'] = 500;
  20007. t['Zacute'] = 667;
  20008. t['Zcaron'] = 667;
  20009. t['greaterequal'] = 549;
  20010. t['Eth'] = 722;
  20011. t['Ccedilla'] = 722;
  20012. t['lcommaaccent'] = 278;
  20013. t['tcaron'] = 416;
  20014. t['eogonek'] = 444;
  20015. t['Uogonek'] = 722;
  20016. t['Aacute'] = 722;
  20017. t['Adieresis'] = 722;
  20018. t['egrave'] = 444;
  20019. t['zacute'] = 444;
  20020. t['iogonek'] = 278;
  20021. t['Oacute'] = 778;
  20022. t['oacute'] = 500;
  20023. t['amacron'] = 500;
  20024. t['sacute'] = 389;
  20025. t['idieresis'] = 278;
  20026. t['Ocircumflex'] = 778;
  20027. t['Ugrave'] = 722;
  20028. t['Delta'] = 612;
  20029. t['thorn'] = 556;
  20030. t['twosuperior'] = 300;
  20031. t['Odieresis'] = 778;
  20032. t['mu'] = 556;
  20033. t['igrave'] = 278;
  20034. t['ohungarumlaut'] = 500;
  20035. t['Eogonek'] = 667;
  20036. t['dcroat'] = 556;
  20037. t['threequarters'] = 750;
  20038. t['Scedilla'] = 556;
  20039. t['lcaron'] = 394;
  20040. t['Kcommaaccent'] = 778;
  20041. t['Lacute'] = 667;
  20042. t['trademark'] = 1000;
  20043. t['edotaccent'] = 444;
  20044. t['Igrave'] = 389;
  20045. t['Imacron'] = 389;
  20046. t['Lcaron'] = 667;
  20047. t['onehalf'] = 750;
  20048. t['lessequal'] = 549;
  20049. t['ocircumflex'] = 500;
  20050. t['ntilde'] = 556;
  20051. t['Uhungarumlaut'] = 722;
  20052. t['Eacute'] = 667;
  20053. t['emacron'] = 444;
  20054. t['gbreve'] = 500;
  20055. t['onequarter'] = 750;
  20056. t['Scaron'] = 556;
  20057. t['Scommaaccent'] = 556;
  20058. t['Ohungarumlaut'] = 778;
  20059. t['degree'] = 400;
  20060. t['ograve'] = 500;
  20061. t['Ccaron'] = 722;
  20062. t['ugrave'] = 556;
  20063. t['radical'] = 549;
  20064. t['Dcaron'] = 722;
  20065. t['rcommaaccent'] = 444;
  20066. t['Ntilde'] = 722;
  20067. t['otilde'] = 500;
  20068. t['Rcommaaccent'] = 722;
  20069. t['Lcommaaccent'] = 667;
  20070. t['Atilde'] = 722;
  20071. t['Aogonek'] = 722;
  20072. t['Aring'] = 722;
  20073. t['Otilde'] = 778;
  20074. t['zdotaccent'] = 444;
  20075. t['Ecaron'] = 667;
  20076. t['Iogonek'] = 389;
  20077. t['kcommaaccent'] = 556;
  20078. t['minus'] = 570;
  20079. t['Icircumflex'] = 389;
  20080. t['ncaron'] = 556;
  20081. t['tcommaaccent'] = 333;
  20082. t['logicalnot'] = 570;
  20083. t['odieresis'] = 500;
  20084. t['udieresis'] = 556;
  20085. t['notequal'] = 549;
  20086. t['gcommaaccent'] = 500;
  20087. t['eth'] = 500;
  20088. t['zcaron'] = 444;
  20089. t['ncommaaccent'] = 556;
  20090. t['onesuperior'] = 300;
  20091. t['imacron'] = 278;
  20092. t['Euro'] = 500;
  20093. });
  20094. t['Times-BoldItalic'] = getLookupTableFactory(function (t) {
  20095. t['space'] = 250;
  20096. t['exclam'] = 389;
  20097. t['quotedbl'] = 555;
  20098. t['numbersign'] = 500;
  20099. t['dollar'] = 500;
  20100. t['percent'] = 833;
  20101. t['ampersand'] = 778;
  20102. t['quoteright'] = 333;
  20103. t['parenleft'] = 333;
  20104. t['parenright'] = 333;
  20105. t['asterisk'] = 500;
  20106. t['plus'] = 570;
  20107. t['comma'] = 250;
  20108. t['hyphen'] = 333;
  20109. t['period'] = 250;
  20110. t['slash'] = 278;
  20111. t['zero'] = 500;
  20112. t['one'] = 500;
  20113. t['two'] = 500;
  20114. t['three'] = 500;
  20115. t['four'] = 500;
  20116. t['five'] = 500;
  20117. t['six'] = 500;
  20118. t['seven'] = 500;
  20119. t['eight'] = 500;
  20120. t['nine'] = 500;
  20121. t['colon'] = 333;
  20122. t['semicolon'] = 333;
  20123. t['less'] = 570;
  20124. t['equal'] = 570;
  20125. t['greater'] = 570;
  20126. t['question'] = 500;
  20127. t['at'] = 832;
  20128. t['A'] = 667;
  20129. t['B'] = 667;
  20130. t['C'] = 667;
  20131. t['D'] = 722;
  20132. t['E'] = 667;
  20133. t['F'] = 667;
  20134. t['G'] = 722;
  20135. t['H'] = 778;
  20136. t['I'] = 389;
  20137. t['J'] = 500;
  20138. t['K'] = 667;
  20139. t['L'] = 611;
  20140. t['M'] = 889;
  20141. t['N'] = 722;
  20142. t['O'] = 722;
  20143. t['P'] = 611;
  20144. t['Q'] = 722;
  20145. t['R'] = 667;
  20146. t['S'] = 556;
  20147. t['T'] = 611;
  20148. t['U'] = 722;
  20149. t['V'] = 667;
  20150. t['W'] = 889;
  20151. t['X'] = 667;
  20152. t['Y'] = 611;
  20153. t['Z'] = 611;
  20154. t['bracketleft'] = 333;
  20155. t['backslash'] = 278;
  20156. t['bracketright'] = 333;
  20157. t['asciicircum'] = 570;
  20158. t['underscore'] = 500;
  20159. t['quoteleft'] = 333;
  20160. t['a'] = 500;
  20161. t['b'] = 500;
  20162. t['c'] = 444;
  20163. t['d'] = 500;
  20164. t['e'] = 444;
  20165. t['f'] = 333;
  20166. t['g'] = 500;
  20167. t['h'] = 556;
  20168. t['i'] = 278;
  20169. t['j'] = 278;
  20170. t['k'] = 500;
  20171. t['l'] = 278;
  20172. t['m'] = 778;
  20173. t['n'] = 556;
  20174. t['o'] = 500;
  20175. t['p'] = 500;
  20176. t['q'] = 500;
  20177. t['r'] = 389;
  20178. t['s'] = 389;
  20179. t['t'] = 278;
  20180. t['u'] = 556;
  20181. t['v'] = 444;
  20182. t['w'] = 667;
  20183. t['x'] = 500;
  20184. t['y'] = 444;
  20185. t['z'] = 389;
  20186. t['braceleft'] = 348;
  20187. t['bar'] = 220;
  20188. t['braceright'] = 348;
  20189. t['asciitilde'] = 570;
  20190. t['exclamdown'] = 389;
  20191. t['cent'] = 500;
  20192. t['sterling'] = 500;
  20193. t['fraction'] = 167;
  20194. t['yen'] = 500;
  20195. t['florin'] = 500;
  20196. t['section'] = 500;
  20197. t['currency'] = 500;
  20198. t['quotesingle'] = 278;
  20199. t['quotedblleft'] = 500;
  20200. t['guillemotleft'] = 500;
  20201. t['guilsinglleft'] = 333;
  20202. t['guilsinglright'] = 333;
  20203. t['fi'] = 556;
  20204. t['fl'] = 556;
  20205. t['endash'] = 500;
  20206. t['dagger'] = 500;
  20207. t['daggerdbl'] = 500;
  20208. t['periodcentered'] = 250;
  20209. t['paragraph'] = 500;
  20210. t['bullet'] = 350;
  20211. t['quotesinglbase'] = 333;
  20212. t['quotedblbase'] = 500;
  20213. t['quotedblright'] = 500;
  20214. t['guillemotright'] = 500;
  20215. t['ellipsis'] = 1000;
  20216. t['perthousand'] = 1000;
  20217. t['questiondown'] = 500;
  20218. t['grave'] = 333;
  20219. t['acute'] = 333;
  20220. t['circumflex'] = 333;
  20221. t['tilde'] = 333;
  20222. t['macron'] = 333;
  20223. t['breve'] = 333;
  20224. t['dotaccent'] = 333;
  20225. t['dieresis'] = 333;
  20226. t['ring'] = 333;
  20227. t['cedilla'] = 333;
  20228. t['hungarumlaut'] = 333;
  20229. t['ogonek'] = 333;
  20230. t['caron'] = 333;
  20231. t['emdash'] = 1000;
  20232. t['AE'] = 944;
  20233. t['ordfeminine'] = 266;
  20234. t['Lslash'] = 611;
  20235. t['Oslash'] = 722;
  20236. t['OE'] = 944;
  20237. t['ordmasculine'] = 300;
  20238. t['ae'] = 722;
  20239. t['dotlessi'] = 278;
  20240. t['lslash'] = 278;
  20241. t['oslash'] = 500;
  20242. t['oe'] = 722;
  20243. t['germandbls'] = 500;
  20244. t['Idieresis'] = 389;
  20245. t['eacute'] = 444;
  20246. t['abreve'] = 500;
  20247. t['uhungarumlaut'] = 556;
  20248. t['ecaron'] = 444;
  20249. t['Ydieresis'] = 611;
  20250. t['divide'] = 570;
  20251. t['Yacute'] = 611;
  20252. t['Acircumflex'] = 667;
  20253. t['aacute'] = 500;
  20254. t['Ucircumflex'] = 722;
  20255. t['yacute'] = 444;
  20256. t['scommaaccent'] = 389;
  20257. t['ecircumflex'] = 444;
  20258. t['Uring'] = 722;
  20259. t['Udieresis'] = 722;
  20260. t['aogonek'] = 500;
  20261. t['Uacute'] = 722;
  20262. t['uogonek'] = 556;
  20263. t['Edieresis'] = 667;
  20264. t['Dcroat'] = 722;
  20265. t['commaaccent'] = 250;
  20266. t['copyright'] = 747;
  20267. t['Emacron'] = 667;
  20268. t['ccaron'] = 444;
  20269. t['aring'] = 500;
  20270. t['Ncommaaccent'] = 722;
  20271. t['lacute'] = 278;
  20272. t['agrave'] = 500;
  20273. t['Tcommaaccent'] = 611;
  20274. t['Cacute'] = 667;
  20275. t['atilde'] = 500;
  20276. t['Edotaccent'] = 667;
  20277. t['scaron'] = 389;
  20278. t['scedilla'] = 389;
  20279. t['iacute'] = 278;
  20280. t['lozenge'] = 494;
  20281. t['Rcaron'] = 667;
  20282. t['Gcommaaccent'] = 722;
  20283. t['ucircumflex'] = 556;
  20284. t['acircumflex'] = 500;
  20285. t['Amacron'] = 667;
  20286. t['rcaron'] = 389;
  20287. t['ccedilla'] = 444;
  20288. t['Zdotaccent'] = 611;
  20289. t['Thorn'] = 611;
  20290. t['Omacron'] = 722;
  20291. t['Racute'] = 667;
  20292. t['Sacute'] = 556;
  20293. t['dcaron'] = 608;
  20294. t['Umacron'] = 722;
  20295. t['uring'] = 556;
  20296. t['threesuperior'] = 300;
  20297. t['Ograve'] = 722;
  20298. t['Agrave'] = 667;
  20299. t['Abreve'] = 667;
  20300. t['multiply'] = 570;
  20301. t['uacute'] = 556;
  20302. t['Tcaron'] = 611;
  20303. t['partialdiff'] = 494;
  20304. t['ydieresis'] = 444;
  20305. t['Nacute'] = 722;
  20306. t['icircumflex'] = 278;
  20307. t['Ecircumflex'] = 667;
  20308. t['adieresis'] = 500;
  20309. t['edieresis'] = 444;
  20310. t['cacute'] = 444;
  20311. t['nacute'] = 556;
  20312. t['umacron'] = 556;
  20313. t['Ncaron'] = 722;
  20314. t['Iacute'] = 389;
  20315. t['plusminus'] = 570;
  20316. t['brokenbar'] = 220;
  20317. t['registered'] = 747;
  20318. t['Gbreve'] = 722;
  20319. t['Idotaccent'] = 389;
  20320. t['summation'] = 600;
  20321. t['Egrave'] = 667;
  20322. t['racute'] = 389;
  20323. t['omacron'] = 500;
  20324. t['Zacute'] = 611;
  20325. t['Zcaron'] = 611;
  20326. t['greaterequal'] = 549;
  20327. t['Eth'] = 722;
  20328. t['Ccedilla'] = 667;
  20329. t['lcommaaccent'] = 278;
  20330. t['tcaron'] = 366;
  20331. t['eogonek'] = 444;
  20332. t['Uogonek'] = 722;
  20333. t['Aacute'] = 667;
  20334. t['Adieresis'] = 667;
  20335. t['egrave'] = 444;
  20336. t['zacute'] = 389;
  20337. t['iogonek'] = 278;
  20338. t['Oacute'] = 722;
  20339. t['oacute'] = 500;
  20340. t['amacron'] = 500;
  20341. t['sacute'] = 389;
  20342. t['idieresis'] = 278;
  20343. t['Ocircumflex'] = 722;
  20344. t['Ugrave'] = 722;
  20345. t['Delta'] = 612;
  20346. t['thorn'] = 500;
  20347. t['twosuperior'] = 300;
  20348. t['Odieresis'] = 722;
  20349. t['mu'] = 576;
  20350. t['igrave'] = 278;
  20351. t['ohungarumlaut'] = 500;
  20352. t['Eogonek'] = 667;
  20353. t['dcroat'] = 500;
  20354. t['threequarters'] = 750;
  20355. t['Scedilla'] = 556;
  20356. t['lcaron'] = 382;
  20357. t['Kcommaaccent'] = 667;
  20358. t['Lacute'] = 611;
  20359. t['trademark'] = 1000;
  20360. t['edotaccent'] = 444;
  20361. t['Igrave'] = 389;
  20362. t['Imacron'] = 389;
  20363. t['Lcaron'] = 611;
  20364. t['onehalf'] = 750;
  20365. t['lessequal'] = 549;
  20366. t['ocircumflex'] = 500;
  20367. t['ntilde'] = 556;
  20368. t['Uhungarumlaut'] = 722;
  20369. t['Eacute'] = 667;
  20370. t['emacron'] = 444;
  20371. t['gbreve'] = 500;
  20372. t['onequarter'] = 750;
  20373. t['Scaron'] = 556;
  20374. t['Scommaaccent'] = 556;
  20375. t['Ohungarumlaut'] = 722;
  20376. t['degree'] = 400;
  20377. t['ograve'] = 500;
  20378. t['Ccaron'] = 667;
  20379. t['ugrave'] = 556;
  20380. t['radical'] = 549;
  20381. t['Dcaron'] = 722;
  20382. t['rcommaaccent'] = 389;
  20383. t['Ntilde'] = 722;
  20384. t['otilde'] = 500;
  20385. t['Rcommaaccent'] = 667;
  20386. t['Lcommaaccent'] = 611;
  20387. t['Atilde'] = 667;
  20388. t['Aogonek'] = 667;
  20389. t['Aring'] = 667;
  20390. t['Otilde'] = 722;
  20391. t['zdotaccent'] = 389;
  20392. t['Ecaron'] = 667;
  20393. t['Iogonek'] = 389;
  20394. t['kcommaaccent'] = 500;
  20395. t['minus'] = 606;
  20396. t['Icircumflex'] = 389;
  20397. t['ncaron'] = 556;
  20398. t['tcommaaccent'] = 278;
  20399. t['logicalnot'] = 606;
  20400. t['odieresis'] = 500;
  20401. t['udieresis'] = 556;
  20402. t['notequal'] = 549;
  20403. t['gcommaaccent'] = 500;
  20404. t['eth'] = 500;
  20405. t['zcaron'] = 389;
  20406. t['ncommaaccent'] = 556;
  20407. t['onesuperior'] = 300;
  20408. t['imacron'] = 278;
  20409. t['Euro'] = 500;
  20410. });
  20411. t['Times-Italic'] = getLookupTableFactory(function (t) {
  20412. t['space'] = 250;
  20413. t['exclam'] = 333;
  20414. t['quotedbl'] = 420;
  20415. t['numbersign'] = 500;
  20416. t['dollar'] = 500;
  20417. t['percent'] = 833;
  20418. t['ampersand'] = 778;
  20419. t['quoteright'] = 333;
  20420. t['parenleft'] = 333;
  20421. t['parenright'] = 333;
  20422. t['asterisk'] = 500;
  20423. t['plus'] = 675;
  20424. t['comma'] = 250;
  20425. t['hyphen'] = 333;
  20426. t['period'] = 250;
  20427. t['slash'] = 278;
  20428. t['zero'] = 500;
  20429. t['one'] = 500;
  20430. t['two'] = 500;
  20431. t['three'] = 500;
  20432. t['four'] = 500;
  20433. t['five'] = 500;
  20434. t['six'] = 500;
  20435. t['seven'] = 500;
  20436. t['eight'] = 500;
  20437. t['nine'] = 500;
  20438. t['colon'] = 333;
  20439. t['semicolon'] = 333;
  20440. t['less'] = 675;
  20441. t['equal'] = 675;
  20442. t['greater'] = 675;
  20443. t['question'] = 500;
  20444. t['at'] = 920;
  20445. t['A'] = 611;
  20446. t['B'] = 611;
  20447. t['C'] = 667;
  20448. t['D'] = 722;
  20449. t['E'] = 611;
  20450. t['F'] = 611;
  20451. t['G'] = 722;
  20452. t['H'] = 722;
  20453. t['I'] = 333;
  20454. t['J'] = 444;
  20455. t['K'] = 667;
  20456. t['L'] = 556;
  20457. t['M'] = 833;
  20458. t['N'] = 667;
  20459. t['O'] = 722;
  20460. t['P'] = 611;
  20461. t['Q'] = 722;
  20462. t['R'] = 611;
  20463. t['S'] = 500;
  20464. t['T'] = 556;
  20465. t['U'] = 722;
  20466. t['V'] = 611;
  20467. t['W'] = 833;
  20468. t['X'] = 611;
  20469. t['Y'] = 556;
  20470. t['Z'] = 556;
  20471. t['bracketleft'] = 389;
  20472. t['backslash'] = 278;
  20473. t['bracketright'] = 389;
  20474. t['asciicircum'] = 422;
  20475. t['underscore'] = 500;
  20476. t['quoteleft'] = 333;
  20477. t['a'] = 500;
  20478. t['b'] = 500;
  20479. t['c'] = 444;
  20480. t['d'] = 500;
  20481. t['e'] = 444;
  20482. t['f'] = 278;
  20483. t['g'] = 500;
  20484. t['h'] = 500;
  20485. t['i'] = 278;
  20486. t['j'] = 278;
  20487. t['k'] = 444;
  20488. t['l'] = 278;
  20489. t['m'] = 722;
  20490. t['n'] = 500;
  20491. t['o'] = 500;
  20492. t['p'] = 500;
  20493. t['q'] = 500;
  20494. t['r'] = 389;
  20495. t['s'] = 389;
  20496. t['t'] = 278;
  20497. t['u'] = 500;
  20498. t['v'] = 444;
  20499. t['w'] = 667;
  20500. t['x'] = 444;
  20501. t['y'] = 444;
  20502. t['z'] = 389;
  20503. t['braceleft'] = 400;
  20504. t['bar'] = 275;
  20505. t['braceright'] = 400;
  20506. t['asciitilde'] = 541;
  20507. t['exclamdown'] = 389;
  20508. t['cent'] = 500;
  20509. t['sterling'] = 500;
  20510. t['fraction'] = 167;
  20511. t['yen'] = 500;
  20512. t['florin'] = 500;
  20513. t['section'] = 500;
  20514. t['currency'] = 500;
  20515. t['quotesingle'] = 214;
  20516. t['quotedblleft'] = 556;
  20517. t['guillemotleft'] = 500;
  20518. t['guilsinglleft'] = 333;
  20519. t['guilsinglright'] = 333;
  20520. t['fi'] = 500;
  20521. t['fl'] = 500;
  20522. t['endash'] = 500;
  20523. t['dagger'] = 500;
  20524. t['daggerdbl'] = 500;
  20525. t['periodcentered'] = 250;
  20526. t['paragraph'] = 523;
  20527. t['bullet'] = 350;
  20528. t['quotesinglbase'] = 333;
  20529. t['quotedblbase'] = 556;
  20530. t['quotedblright'] = 556;
  20531. t['guillemotright'] = 500;
  20532. t['ellipsis'] = 889;
  20533. t['perthousand'] = 1000;
  20534. t['questiondown'] = 500;
  20535. t['grave'] = 333;
  20536. t['acute'] = 333;
  20537. t['circumflex'] = 333;
  20538. t['tilde'] = 333;
  20539. t['macron'] = 333;
  20540. t['breve'] = 333;
  20541. t['dotaccent'] = 333;
  20542. t['dieresis'] = 333;
  20543. t['ring'] = 333;
  20544. t['cedilla'] = 333;
  20545. t['hungarumlaut'] = 333;
  20546. t['ogonek'] = 333;
  20547. t['caron'] = 333;
  20548. t['emdash'] = 889;
  20549. t['AE'] = 889;
  20550. t['ordfeminine'] = 276;
  20551. t['Lslash'] = 556;
  20552. t['Oslash'] = 722;
  20553. t['OE'] = 944;
  20554. t['ordmasculine'] = 310;
  20555. t['ae'] = 667;
  20556. t['dotlessi'] = 278;
  20557. t['lslash'] = 278;
  20558. t['oslash'] = 500;
  20559. t['oe'] = 667;
  20560. t['germandbls'] = 500;
  20561. t['Idieresis'] = 333;
  20562. t['eacute'] = 444;
  20563. t['abreve'] = 500;
  20564. t['uhungarumlaut'] = 500;
  20565. t['ecaron'] = 444;
  20566. t['Ydieresis'] = 556;
  20567. t['divide'] = 675;
  20568. t['Yacute'] = 556;
  20569. t['Acircumflex'] = 611;
  20570. t['aacute'] = 500;
  20571. t['Ucircumflex'] = 722;
  20572. t['yacute'] = 444;
  20573. t['scommaaccent'] = 389;
  20574. t['ecircumflex'] = 444;
  20575. t['Uring'] = 722;
  20576. t['Udieresis'] = 722;
  20577. t['aogonek'] = 500;
  20578. t['Uacute'] = 722;
  20579. t['uogonek'] = 500;
  20580. t['Edieresis'] = 611;
  20581. t['Dcroat'] = 722;
  20582. t['commaaccent'] = 250;
  20583. t['copyright'] = 760;
  20584. t['Emacron'] = 611;
  20585. t['ccaron'] = 444;
  20586. t['aring'] = 500;
  20587. t['Ncommaaccent'] = 667;
  20588. t['lacute'] = 278;
  20589. t['agrave'] = 500;
  20590. t['Tcommaaccent'] = 556;
  20591. t['Cacute'] = 667;
  20592. t['atilde'] = 500;
  20593. t['Edotaccent'] = 611;
  20594. t['scaron'] = 389;
  20595. t['scedilla'] = 389;
  20596. t['iacute'] = 278;
  20597. t['lozenge'] = 471;
  20598. t['Rcaron'] = 611;
  20599. t['Gcommaaccent'] = 722;
  20600. t['ucircumflex'] = 500;
  20601. t['acircumflex'] = 500;
  20602. t['Amacron'] = 611;
  20603. t['rcaron'] = 389;
  20604. t['ccedilla'] = 444;
  20605. t['Zdotaccent'] = 556;
  20606. t['Thorn'] = 611;
  20607. t['Omacron'] = 722;
  20608. t['Racute'] = 611;
  20609. t['Sacute'] = 500;
  20610. t['dcaron'] = 544;
  20611. t['Umacron'] = 722;
  20612. t['uring'] = 500;
  20613. t['threesuperior'] = 300;
  20614. t['Ograve'] = 722;
  20615. t['Agrave'] = 611;
  20616. t['Abreve'] = 611;
  20617. t['multiply'] = 675;
  20618. t['uacute'] = 500;
  20619. t['Tcaron'] = 556;
  20620. t['partialdiff'] = 476;
  20621. t['ydieresis'] = 444;
  20622. t['Nacute'] = 667;
  20623. t['icircumflex'] = 278;
  20624. t['Ecircumflex'] = 611;
  20625. t['adieresis'] = 500;
  20626. t['edieresis'] = 444;
  20627. t['cacute'] = 444;
  20628. t['nacute'] = 500;
  20629. t['umacron'] = 500;
  20630. t['Ncaron'] = 667;
  20631. t['Iacute'] = 333;
  20632. t['plusminus'] = 675;
  20633. t['brokenbar'] = 275;
  20634. t['registered'] = 760;
  20635. t['Gbreve'] = 722;
  20636. t['Idotaccent'] = 333;
  20637. t['summation'] = 600;
  20638. t['Egrave'] = 611;
  20639. t['racute'] = 389;
  20640. t['omacron'] = 500;
  20641. t['Zacute'] = 556;
  20642. t['Zcaron'] = 556;
  20643. t['greaterequal'] = 549;
  20644. t['Eth'] = 722;
  20645. t['Ccedilla'] = 667;
  20646. t['lcommaaccent'] = 278;
  20647. t['tcaron'] = 300;
  20648. t['eogonek'] = 444;
  20649. t['Uogonek'] = 722;
  20650. t['Aacute'] = 611;
  20651. t['Adieresis'] = 611;
  20652. t['egrave'] = 444;
  20653. t['zacute'] = 389;
  20654. t['iogonek'] = 278;
  20655. t['Oacute'] = 722;
  20656. t['oacute'] = 500;
  20657. t['amacron'] = 500;
  20658. t['sacute'] = 389;
  20659. t['idieresis'] = 278;
  20660. t['Ocircumflex'] = 722;
  20661. t['Ugrave'] = 722;
  20662. t['Delta'] = 612;
  20663. t['thorn'] = 500;
  20664. t['twosuperior'] = 300;
  20665. t['Odieresis'] = 722;
  20666. t['mu'] = 500;
  20667. t['igrave'] = 278;
  20668. t['ohungarumlaut'] = 500;
  20669. t['Eogonek'] = 611;
  20670. t['dcroat'] = 500;
  20671. t['threequarters'] = 750;
  20672. t['Scedilla'] = 500;
  20673. t['lcaron'] = 300;
  20674. t['Kcommaaccent'] = 667;
  20675. t['Lacute'] = 556;
  20676. t['trademark'] = 980;
  20677. t['edotaccent'] = 444;
  20678. t['Igrave'] = 333;
  20679. t['Imacron'] = 333;
  20680. t['Lcaron'] = 611;
  20681. t['onehalf'] = 750;
  20682. t['lessequal'] = 549;
  20683. t['ocircumflex'] = 500;
  20684. t['ntilde'] = 500;
  20685. t['Uhungarumlaut'] = 722;
  20686. t['Eacute'] = 611;
  20687. t['emacron'] = 444;
  20688. t['gbreve'] = 500;
  20689. t['onequarter'] = 750;
  20690. t['Scaron'] = 500;
  20691. t['Scommaaccent'] = 500;
  20692. t['Ohungarumlaut'] = 722;
  20693. t['degree'] = 400;
  20694. t['ograve'] = 500;
  20695. t['Ccaron'] = 667;
  20696. t['ugrave'] = 500;
  20697. t['radical'] = 453;
  20698. t['Dcaron'] = 722;
  20699. t['rcommaaccent'] = 389;
  20700. t['Ntilde'] = 667;
  20701. t['otilde'] = 500;
  20702. t['Rcommaaccent'] = 611;
  20703. t['Lcommaaccent'] = 556;
  20704. t['Atilde'] = 611;
  20705. t['Aogonek'] = 611;
  20706. t['Aring'] = 611;
  20707. t['Otilde'] = 722;
  20708. t['zdotaccent'] = 389;
  20709. t['Ecaron'] = 611;
  20710. t['Iogonek'] = 333;
  20711. t['kcommaaccent'] = 444;
  20712. t['minus'] = 675;
  20713. t['Icircumflex'] = 333;
  20714. t['ncaron'] = 500;
  20715. t['tcommaaccent'] = 278;
  20716. t['logicalnot'] = 675;
  20717. t['odieresis'] = 500;
  20718. t['udieresis'] = 500;
  20719. t['notequal'] = 549;
  20720. t['gcommaaccent'] = 500;
  20721. t['eth'] = 500;
  20722. t['zcaron'] = 389;
  20723. t['ncommaaccent'] = 500;
  20724. t['onesuperior'] = 300;
  20725. t['imacron'] = 278;
  20726. t['Euro'] = 500;
  20727. });
  20728. t['ZapfDingbats'] = getLookupTableFactory(function (t) {
  20729. t['space'] = 278;
  20730. t['a1'] = 974;
  20731. t['a2'] = 961;
  20732. t['a202'] = 974;
  20733. t['a3'] = 980;
  20734. t['a4'] = 719;
  20735. t['a5'] = 789;
  20736. t['a119'] = 790;
  20737. t['a118'] = 791;
  20738. t['a117'] = 690;
  20739. t['a11'] = 960;
  20740. t['a12'] = 939;
  20741. t['a13'] = 549;
  20742. t['a14'] = 855;
  20743. t['a15'] = 911;
  20744. t['a16'] = 933;
  20745. t['a105'] = 911;
  20746. t['a17'] = 945;
  20747. t['a18'] = 974;
  20748. t['a19'] = 755;
  20749. t['a20'] = 846;
  20750. t['a21'] = 762;
  20751. t['a22'] = 761;
  20752. t['a23'] = 571;
  20753. t['a24'] = 677;
  20754. t['a25'] = 763;
  20755. t['a26'] = 760;
  20756. t['a27'] = 759;
  20757. t['a28'] = 754;
  20758. t['a6'] = 494;
  20759. t['a7'] = 552;
  20760. t['a8'] = 537;
  20761. t['a9'] = 577;
  20762. t['a10'] = 692;
  20763. t['a29'] = 786;
  20764. t['a30'] = 788;
  20765. t['a31'] = 788;
  20766. t['a32'] = 790;
  20767. t['a33'] = 793;
  20768. t['a34'] = 794;
  20769. t['a35'] = 816;
  20770. t['a36'] = 823;
  20771. t['a37'] = 789;
  20772. t['a38'] = 841;
  20773. t['a39'] = 823;
  20774. t['a40'] = 833;
  20775. t['a41'] = 816;
  20776. t['a42'] = 831;
  20777. t['a43'] = 923;
  20778. t['a44'] = 744;
  20779. t['a45'] = 723;
  20780. t['a46'] = 749;
  20781. t['a47'] = 790;
  20782. t['a48'] = 792;
  20783. t['a49'] = 695;
  20784. t['a50'] = 776;
  20785. t['a51'] = 768;
  20786. t['a52'] = 792;
  20787. t['a53'] = 759;
  20788. t['a54'] = 707;
  20789. t['a55'] = 708;
  20790. t['a56'] = 682;
  20791. t['a57'] = 701;
  20792. t['a58'] = 826;
  20793. t['a59'] = 815;
  20794. t['a60'] = 789;
  20795. t['a61'] = 789;
  20796. t['a62'] = 707;
  20797. t['a63'] = 687;
  20798. t['a64'] = 696;
  20799. t['a65'] = 689;
  20800. t['a66'] = 786;
  20801. t['a67'] = 787;
  20802. t['a68'] = 713;
  20803. t['a69'] = 791;
  20804. t['a70'] = 785;
  20805. t['a71'] = 791;
  20806. t['a72'] = 873;
  20807. t['a73'] = 761;
  20808. t['a74'] = 762;
  20809. t['a203'] = 762;
  20810. t['a75'] = 759;
  20811. t['a204'] = 759;
  20812. t['a76'] = 892;
  20813. t['a77'] = 892;
  20814. t['a78'] = 788;
  20815. t['a79'] = 784;
  20816. t['a81'] = 438;
  20817. t['a82'] = 138;
  20818. t['a83'] = 277;
  20819. t['a84'] = 415;
  20820. t['a97'] = 392;
  20821. t['a98'] = 392;
  20822. t['a99'] = 668;
  20823. t['a100'] = 668;
  20824. t['a89'] = 390;
  20825. t['a90'] = 390;
  20826. t['a93'] = 317;
  20827. t['a94'] = 317;
  20828. t['a91'] = 276;
  20829. t['a92'] = 276;
  20830. t['a205'] = 509;
  20831. t['a85'] = 509;
  20832. t['a206'] = 410;
  20833. t['a86'] = 410;
  20834. t['a87'] = 234;
  20835. t['a88'] = 234;
  20836. t['a95'] = 334;
  20837. t['a96'] = 334;
  20838. t['a101'] = 732;
  20839. t['a102'] = 544;
  20840. t['a103'] = 544;
  20841. t['a104'] = 910;
  20842. t['a106'] = 667;
  20843. t['a107'] = 760;
  20844. t['a108'] = 760;
  20845. t['a112'] = 776;
  20846. t['a111'] = 595;
  20847. t['a110'] = 694;
  20848. t['a109'] = 626;
  20849. t['a120'] = 788;
  20850. t['a121'] = 788;
  20851. t['a122'] = 788;
  20852. t['a123'] = 788;
  20853. t['a124'] = 788;
  20854. t['a125'] = 788;
  20855. t['a126'] = 788;
  20856. t['a127'] = 788;
  20857. t['a128'] = 788;
  20858. t['a129'] = 788;
  20859. t['a130'] = 788;
  20860. t['a131'] = 788;
  20861. t['a132'] = 788;
  20862. t['a133'] = 788;
  20863. t['a134'] = 788;
  20864. t['a135'] = 788;
  20865. t['a136'] = 788;
  20866. t['a137'] = 788;
  20867. t['a138'] = 788;
  20868. t['a139'] = 788;
  20869. t['a140'] = 788;
  20870. t['a141'] = 788;
  20871. t['a142'] = 788;
  20872. t['a143'] = 788;
  20873. t['a144'] = 788;
  20874. t['a145'] = 788;
  20875. t['a146'] = 788;
  20876. t['a147'] = 788;
  20877. t['a148'] = 788;
  20878. t['a149'] = 788;
  20879. t['a150'] = 788;
  20880. t['a151'] = 788;
  20881. t['a152'] = 788;
  20882. t['a153'] = 788;
  20883. t['a154'] = 788;
  20884. t['a155'] = 788;
  20885. t['a156'] = 788;
  20886. t['a157'] = 788;
  20887. t['a158'] = 788;
  20888. t['a159'] = 788;
  20889. t['a160'] = 894;
  20890. t['a161'] = 838;
  20891. t['a163'] = 1016;
  20892. t['a164'] = 458;
  20893. t['a196'] = 748;
  20894. t['a165'] = 924;
  20895. t['a192'] = 748;
  20896. t['a166'] = 918;
  20897. t['a167'] = 927;
  20898. t['a168'] = 928;
  20899. t['a169'] = 928;
  20900. t['a170'] = 834;
  20901. t['a171'] = 873;
  20902. t['a172'] = 828;
  20903. t['a173'] = 924;
  20904. t['a162'] = 924;
  20905. t['a174'] = 917;
  20906. t['a175'] = 930;
  20907. t['a176'] = 931;
  20908. t['a177'] = 463;
  20909. t['a178'] = 883;
  20910. t['a179'] = 836;
  20911. t['a193'] = 836;
  20912. t['a180'] = 867;
  20913. t['a199'] = 867;
  20914. t['a181'] = 696;
  20915. t['a200'] = 696;
  20916. t['a182'] = 874;
  20917. t['a201'] = 874;
  20918. t['a183'] = 760;
  20919. t['a184'] = 946;
  20920. t['a197'] = 771;
  20921. t['a185'] = 865;
  20922. t['a194'] = 771;
  20923. t['a198'] = 888;
  20924. t['a186'] = 967;
  20925. t['a195'] = 888;
  20926. t['a187'] = 831;
  20927. t['a188'] = 873;
  20928. t['a189'] = 927;
  20929. t['a190'] = 970;
  20930. t['a191'] = 918;
  20931. });
  20932. });
  20933. exports.getMetrics = getMetrics;
  20934. }));
  20935. (function (root, factory) {
  20936. factory(root.pdfjsCoreMurmurHash3 = {}, root.pdfjsSharedUtil);
  20937. }(this, function (exports, sharedUtil) {
  20938. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  20939. var MurmurHash3_64 = function MurmurHash3_64Closure(seed) {
  20940. // Workaround for missing math precision in JS.
  20941. var MASK_HIGH = 0xffff0000;
  20942. var MASK_LOW = 0xffff;
  20943. function MurmurHash3_64(seed) {
  20944. var SEED = 0xc3d2e1f0;
  20945. this.h1 = seed ? seed & 0xffffffff : SEED;
  20946. this.h2 = seed ? seed & 0xffffffff : SEED;
  20947. }
  20948. var alwaysUseUint32ArrayView = false;
  20949. // old webkits have issues with non-aligned arrays
  20950. try {
  20951. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  20952. } catch (e) {
  20953. alwaysUseUint32ArrayView = true;
  20954. }
  20955. MurmurHash3_64.prototype = {
  20956. update: function MurmurHash3_64_update(input) {
  20957. var useUint32ArrayView = alwaysUseUint32ArrayView;
  20958. var i;
  20959. if (typeof input === 'string') {
  20960. var data = new Uint8Array(input.length * 2);
  20961. var length = 0;
  20962. for (i = 0; i < input.length; i++) {
  20963. var code = input.charCodeAt(i);
  20964. if (code <= 0xff) {
  20965. data[length++] = code;
  20966. } else {
  20967. data[length++] = code >>> 8;
  20968. data[length++] = code & 0xff;
  20969. }
  20970. }
  20971. } else if (input instanceof Uint8Array) {
  20972. data = input;
  20973. length = data.length;
  20974. } else if (typeof input === 'object' && 'length' in input) {
  20975. // processing regular arrays as well, e.g. for IE9
  20976. data = input;
  20977. length = data.length;
  20978. useUint32ArrayView = true;
  20979. } else {
  20980. throw new Error('Wrong data format in MurmurHash3_64_update. ' + 'Input must be a string or array.');
  20981. }
  20982. var blockCounts = length >> 2;
  20983. var tailLength = length - blockCounts * 4;
  20984. // we don't care about endianness here
  20985. var dataUint32 = useUint32ArrayView ? new Uint32ArrayView(data, blockCounts) : new Uint32Array(data.buffer, 0, blockCounts);
  20986. var k1 = 0;
  20987. var k2 = 0;
  20988. var h1 = this.h1;
  20989. var h2 = this.h2;
  20990. var C1 = 0xcc9e2d51;
  20991. var C2 = 0x1b873593;
  20992. var C1_LOW = C1 & MASK_LOW;
  20993. var C2_LOW = C2 & MASK_LOW;
  20994. for (i = 0; i < blockCounts; i++) {
  20995. if (i & 1) {
  20996. k1 = dataUint32[i];
  20997. k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
  20998. k1 = k1 << 15 | k1 >>> 17;
  20999. k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
  21000. h1 ^= k1;
  21001. h1 = h1 << 13 | h1 >>> 19;
  21002. h1 = h1 * 5 + 0xe6546b64;
  21003. } else {
  21004. k2 = dataUint32[i];
  21005. k2 = k2 * C1 & MASK_HIGH | k2 * C1_LOW & MASK_LOW;
  21006. k2 = k2 << 15 | k2 >>> 17;
  21007. k2 = k2 * C2 & MASK_HIGH | k2 * C2_LOW & MASK_LOW;
  21008. h2 ^= k2;
  21009. h2 = h2 << 13 | h2 >>> 19;
  21010. h2 = h2 * 5 + 0xe6546b64;
  21011. }
  21012. }
  21013. k1 = 0;
  21014. switch (tailLength) {
  21015. case 3:
  21016. k1 ^= data[blockCounts * 4 + 2] << 16;
  21017. case 2:
  21018. k1 ^= data[blockCounts * 4 + 1] << 8;
  21019. case 1:
  21020. k1 ^= data[blockCounts * 4];
  21021. k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
  21022. k1 = k1 << 15 | k1 >>> 17;
  21023. k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
  21024. if (blockCounts & 1) {
  21025. h1 ^= k1;
  21026. } else {
  21027. h2 ^= k1;
  21028. }
  21029. }
  21030. this.h1 = h1;
  21031. this.h2 = h2;
  21032. return this;
  21033. },
  21034. hexdigest: function MurmurHash3_64_hexdigest() {
  21035. var h1 = this.h1;
  21036. var h2 = this.h2;
  21037. h1 ^= h2 >>> 1;
  21038. h1 = h1 * 0xed558ccd & MASK_HIGH | h1 * 0x8ccd & MASK_LOW;
  21039. h2 = h2 * 0xff51afd7 & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16;
  21040. h1 ^= h2 >>> 1;
  21041. h1 = h1 * 0x1a85ec53 & MASK_HIGH | h1 * 0xec53 & MASK_LOW;
  21042. h2 = h2 * 0xc4ceb9fe & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16;
  21043. h1 ^= h2 >>> 1;
  21044. for (var i = 0, arr = [
  21045. h1,
  21046. h2
  21047. ], str = ''; i < arr.length; i++) {
  21048. var hex = (arr[i] >>> 0).toString(16);
  21049. while (hex.length < 8) {
  21050. hex = '0' + hex;
  21051. }
  21052. str += hex;
  21053. }
  21054. return str;
  21055. }
  21056. };
  21057. return MurmurHash3_64;
  21058. }();
  21059. exports.MurmurHash3_64 = MurmurHash3_64;
  21060. }));
  21061. (function (root, factory) {
  21062. factory(root.pdfjsCorePrimitives = {}, root.pdfjsSharedUtil);
  21063. }(this, function (exports, sharedUtil) {
  21064. var isArray = sharedUtil.isArray;
  21065. var Name = function NameClosure() {
  21066. function Name(name) {
  21067. this.name = name;
  21068. }
  21069. Name.prototype = {};
  21070. var nameCache = Object.create(null);
  21071. Name.get = function Name_get(name) {
  21072. var nameValue = nameCache[name];
  21073. return nameValue ? nameValue : nameCache[name] = new Name(name);
  21074. };
  21075. return Name;
  21076. }();
  21077. var Cmd = function CmdClosure() {
  21078. function Cmd(cmd) {
  21079. this.cmd = cmd;
  21080. }
  21081. Cmd.prototype = {};
  21082. var cmdCache = Object.create(null);
  21083. Cmd.get = function Cmd_get(cmd) {
  21084. var cmdValue = cmdCache[cmd];
  21085. return cmdValue ? cmdValue : cmdCache[cmd] = new Cmd(cmd);
  21086. };
  21087. return Cmd;
  21088. }();
  21089. var Dict = function DictClosure() {
  21090. var nonSerializable = function nonSerializableClosure() {
  21091. return nonSerializable;
  21092. };
  21093. // creating closure on some variable
  21094. // xref is optional
  21095. function Dict(xref) {
  21096. // Map should only be used internally, use functions below to access.
  21097. this.map = Object.create(null);
  21098. this.xref = xref;
  21099. this.objId = null;
  21100. this.__nonSerializable__ = nonSerializable;
  21101. }
  21102. // disable cloning of the Dict
  21103. Dict.prototype = {
  21104. assignXref: function Dict_assignXref(newXref) {
  21105. this.xref = newXref;
  21106. },
  21107. // automatically dereferences Ref objects
  21108. get: function Dict_get(key1, key2, key3) {
  21109. var value;
  21110. var xref = this.xref;
  21111. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map || typeof key2 === 'undefined') {
  21112. return xref ? xref.fetchIfRef(value) : value;
  21113. }
  21114. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map || typeof key3 === 'undefined') {
  21115. return xref ? xref.fetchIfRef(value) : value;
  21116. }
  21117. value = this.map[key3] || null;
  21118. return xref ? xref.fetchIfRef(value) : value;
  21119. },
  21120. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  21121. getAsync: function Dict_getAsync(key1, key2, key3) {
  21122. var value;
  21123. var xref = this.xref;
  21124. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map || typeof key2 === 'undefined') {
  21125. if (xref) {
  21126. return xref.fetchIfRefAsync(value);
  21127. }
  21128. return Promise.resolve(value);
  21129. }
  21130. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map || typeof key3 === 'undefined') {
  21131. if (xref) {
  21132. return xref.fetchIfRefAsync(value);
  21133. }
  21134. return Promise.resolve(value);
  21135. }
  21136. value = this.map[key3] || null;
  21137. if (xref) {
  21138. return xref.fetchIfRefAsync(value);
  21139. }
  21140. return Promise.resolve(value);
  21141. },
  21142. // Same as get(), but dereferences all elements if the result is an Array.
  21143. getArray: function Dict_getArray(key1, key2, key3) {
  21144. var value = this.get(key1, key2, key3);
  21145. var xref = this.xref;
  21146. if (!isArray(value) || !xref) {
  21147. return value;
  21148. }
  21149. value = value.slice();
  21150. // Ensure that we don't modify the Dict data.
  21151. for (var i = 0, ii = value.length; i < ii; i++) {
  21152. if (!isRef(value[i])) {
  21153. continue;
  21154. }
  21155. value[i] = xref.fetch(value[i]);
  21156. }
  21157. return value;
  21158. },
  21159. // no dereferencing
  21160. getRaw: function Dict_getRaw(key) {
  21161. return this.map[key];
  21162. },
  21163. getKeys: function Dict_getKeys() {
  21164. return Object.keys(this.map);
  21165. },
  21166. set: function Dict_set(key, value) {
  21167. this.map[key] = value;
  21168. },
  21169. has: function Dict_has(key) {
  21170. return key in this.map;
  21171. },
  21172. forEach: function Dict_forEach(callback) {
  21173. for (var key in this.map) {
  21174. callback(key, this.get(key));
  21175. }
  21176. }
  21177. };
  21178. Dict.empty = new Dict(null);
  21179. Dict.merge = function Dict_merge(xref, dictArray) {
  21180. var mergedDict = new Dict(xref);
  21181. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  21182. var dict = dictArray[i];
  21183. if (!isDict(dict)) {
  21184. continue;
  21185. }
  21186. for (var keyName in dict.map) {
  21187. if (mergedDict.map[keyName]) {
  21188. continue;
  21189. }
  21190. mergedDict.map[keyName] = dict.map[keyName];
  21191. }
  21192. }
  21193. return mergedDict;
  21194. };
  21195. return Dict;
  21196. }();
  21197. var Ref = function RefClosure() {
  21198. function Ref(num, gen) {
  21199. this.num = num;
  21200. this.gen = gen;
  21201. }
  21202. Ref.prototype = {
  21203. toString: function Ref_toString() {
  21204. // This function is hot, so we make the string as compact as possible.
  21205. // |this.gen| is almost always zero, so we treat that case specially.
  21206. var str = this.num + 'R';
  21207. if (this.gen !== 0) {
  21208. str += this.gen;
  21209. }
  21210. return str;
  21211. }
  21212. };
  21213. return Ref;
  21214. }();
  21215. // The reference is identified by number and generation.
  21216. // This structure stores only one instance of the reference.
  21217. var RefSet = function RefSetClosure() {
  21218. function RefSet() {
  21219. this.dict = Object.create(null);
  21220. }
  21221. RefSet.prototype = {
  21222. has: function RefSet_has(ref) {
  21223. return ref.toString() in this.dict;
  21224. },
  21225. put: function RefSet_put(ref) {
  21226. this.dict[ref.toString()] = true;
  21227. },
  21228. remove: function RefSet_remove(ref) {
  21229. delete this.dict[ref.toString()];
  21230. }
  21231. };
  21232. return RefSet;
  21233. }();
  21234. var RefSetCache = function RefSetCacheClosure() {
  21235. function RefSetCache() {
  21236. this.dict = Object.create(null);
  21237. }
  21238. RefSetCache.prototype = {
  21239. get: function RefSetCache_get(ref) {
  21240. return this.dict[ref.toString()];
  21241. },
  21242. has: function RefSetCache_has(ref) {
  21243. return ref.toString() in this.dict;
  21244. },
  21245. put: function RefSetCache_put(ref, obj) {
  21246. this.dict[ref.toString()] = obj;
  21247. },
  21248. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  21249. this.dict[ref.toString()] = this.get(aliasRef);
  21250. },
  21251. forEach: function RefSetCache_forEach(fn, thisArg) {
  21252. for (var i in this.dict) {
  21253. fn.call(thisArg, this.dict[i]);
  21254. }
  21255. },
  21256. clear: function RefSetCache_clear() {
  21257. this.dict = Object.create(null);
  21258. }
  21259. };
  21260. return RefSetCache;
  21261. }();
  21262. function isName(v, name) {
  21263. return v instanceof Name && (name === undefined || v.name === name);
  21264. }
  21265. function isCmd(v, cmd) {
  21266. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  21267. }
  21268. function isDict(v, type) {
  21269. return v instanceof Dict && (type === undefined || isName(v.get('Type'), type));
  21270. }
  21271. function isRef(v) {
  21272. return v instanceof Ref;
  21273. }
  21274. function isRefsEqual(v1, v2) {
  21275. return v1.num === v2.num && v1.gen === v2.gen;
  21276. }
  21277. function isStream(v) {
  21278. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  21279. }
  21280. exports.Cmd = Cmd;
  21281. exports.Dict = Dict;
  21282. exports.Name = Name;
  21283. exports.Ref = Ref;
  21284. exports.RefSet = RefSet;
  21285. exports.RefSetCache = RefSetCache;
  21286. exports.isCmd = isCmd;
  21287. exports.isDict = isDict;
  21288. exports.isName = isName;
  21289. exports.isRef = isRef;
  21290. exports.isRefsEqual = isRefsEqual;
  21291. exports.isStream = isStream;
  21292. }));
  21293. (function (root, factory) {
  21294. factory(root.pdfjsCoreStandardFonts = {}, root.pdfjsSharedUtil);
  21295. }(this, function (exports, sharedUtil) {
  21296. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  21297. /**
  21298. * Hold a map of decoded fonts and of the standard fourteen Type1
  21299. * fonts and their acronyms.
  21300. */
  21301. var getStdFontMap = getLookupTableFactory(function (t) {
  21302. t['ArialNarrow'] = 'Helvetica';
  21303. t['ArialNarrow-Bold'] = 'Helvetica-Bold';
  21304. t['ArialNarrow-BoldItalic'] = 'Helvetica-BoldOblique';
  21305. t['ArialNarrow-Italic'] = 'Helvetica-Oblique';
  21306. t['ArialBlack'] = 'Helvetica';
  21307. t['ArialBlack-Bold'] = 'Helvetica-Bold';
  21308. t['ArialBlack-BoldItalic'] = 'Helvetica-BoldOblique';
  21309. t['ArialBlack-Italic'] = 'Helvetica-Oblique';
  21310. t['Arial'] = 'Helvetica';
  21311. t['Arial-Bold'] = 'Helvetica-Bold';
  21312. t['Arial-BoldItalic'] = 'Helvetica-BoldOblique';
  21313. t['Arial-Italic'] = 'Helvetica-Oblique';
  21314. t['Arial-BoldItalicMT'] = 'Helvetica-BoldOblique';
  21315. t['Arial-BoldMT'] = 'Helvetica-Bold';
  21316. t['Arial-ItalicMT'] = 'Helvetica-Oblique';
  21317. t['ArialMT'] = 'Helvetica';
  21318. t['Courier-Bold'] = 'Courier-Bold';
  21319. t['Courier-BoldItalic'] = 'Courier-BoldOblique';
  21320. t['Courier-Italic'] = 'Courier-Oblique';
  21321. t['CourierNew'] = 'Courier';
  21322. t['CourierNew-Bold'] = 'Courier-Bold';
  21323. t['CourierNew-BoldItalic'] = 'Courier-BoldOblique';
  21324. t['CourierNew-Italic'] = 'Courier-Oblique';
  21325. t['CourierNewPS-BoldItalicMT'] = 'Courier-BoldOblique';
  21326. t['CourierNewPS-BoldMT'] = 'Courier-Bold';
  21327. t['CourierNewPS-ItalicMT'] = 'Courier-Oblique';
  21328. t['CourierNewPSMT'] = 'Courier';
  21329. t['Helvetica'] = 'Helvetica';
  21330. t['Helvetica-Bold'] = 'Helvetica-Bold';
  21331. t['Helvetica-BoldItalic'] = 'Helvetica-BoldOblique';
  21332. t['Helvetica-BoldOblique'] = 'Helvetica-BoldOblique';
  21333. t['Helvetica-Italic'] = 'Helvetica-Oblique';
  21334. t['Helvetica-Oblique'] = 'Helvetica-Oblique';
  21335. t['Symbol-Bold'] = 'Symbol';
  21336. t['Symbol-BoldItalic'] = 'Symbol';
  21337. t['Symbol-Italic'] = 'Symbol';
  21338. t['TimesNewRoman'] = 'Times-Roman';
  21339. t['TimesNewRoman-Bold'] = 'Times-Bold';
  21340. t['TimesNewRoman-BoldItalic'] = 'Times-BoldItalic';
  21341. t['TimesNewRoman-Italic'] = 'Times-Italic';
  21342. t['TimesNewRomanPS'] = 'Times-Roman';
  21343. t['TimesNewRomanPS-Bold'] = 'Times-Bold';
  21344. t['TimesNewRomanPS-BoldItalic'] = 'Times-BoldItalic';
  21345. t['TimesNewRomanPS-BoldItalicMT'] = 'Times-BoldItalic';
  21346. t['TimesNewRomanPS-BoldMT'] = 'Times-Bold';
  21347. t['TimesNewRomanPS-Italic'] = 'Times-Italic';
  21348. t['TimesNewRomanPS-ItalicMT'] = 'Times-Italic';
  21349. t['TimesNewRomanPSMT'] = 'Times-Roman';
  21350. t['TimesNewRomanPSMT-Bold'] = 'Times-Bold';
  21351. t['TimesNewRomanPSMT-BoldItalic'] = 'Times-BoldItalic';
  21352. t['TimesNewRomanPSMT-Italic'] = 'Times-Italic';
  21353. });
  21354. /**
  21355. * Holds the map of the non-standard fonts that might be included as
  21356. * a standard fonts without glyph data.
  21357. */
  21358. var getNonStdFontMap = getLookupTableFactory(function (t) {
  21359. t['CenturyGothic'] = 'Helvetica';
  21360. t['CenturyGothic-Bold'] = 'Helvetica-Bold';
  21361. t['CenturyGothic-BoldItalic'] = 'Helvetica-BoldOblique';
  21362. t['CenturyGothic-Italic'] = 'Helvetica-Oblique';
  21363. t['ComicSansMS'] = 'Comic Sans MS';
  21364. t['ComicSansMS-Bold'] = 'Comic Sans MS-Bold';
  21365. t['ComicSansMS-BoldItalic'] = 'Comic Sans MS-BoldItalic';
  21366. t['ComicSansMS-Italic'] = 'Comic Sans MS-Italic';
  21367. t['LucidaConsole'] = 'Courier';
  21368. t['LucidaConsole-Bold'] = 'Courier-Bold';
  21369. t['LucidaConsole-BoldItalic'] = 'Courier-BoldOblique';
  21370. t['LucidaConsole-Italic'] = 'Courier-Oblique';
  21371. t['MS-Gothic'] = 'MS Gothic';
  21372. t['MS-Gothic-Bold'] = 'MS Gothic-Bold';
  21373. t['MS-Gothic-BoldItalic'] = 'MS Gothic-BoldItalic';
  21374. t['MS-Gothic-Italic'] = 'MS Gothic-Italic';
  21375. t['MS-Mincho'] = 'MS Mincho';
  21376. t['MS-Mincho-Bold'] = 'MS Mincho-Bold';
  21377. t['MS-Mincho-BoldItalic'] = 'MS Mincho-BoldItalic';
  21378. t['MS-Mincho-Italic'] = 'MS Mincho-Italic';
  21379. t['MS-PGothic'] = 'MS PGothic';
  21380. t['MS-PGothic-Bold'] = 'MS PGothic-Bold';
  21381. t['MS-PGothic-BoldItalic'] = 'MS PGothic-BoldItalic';
  21382. t['MS-PGothic-Italic'] = 'MS PGothic-Italic';
  21383. t['MS-PMincho'] = 'MS PMincho';
  21384. t['MS-PMincho-Bold'] = 'MS PMincho-Bold';
  21385. t['MS-PMincho-BoldItalic'] = 'MS PMincho-BoldItalic';
  21386. t['MS-PMincho-Italic'] = 'MS PMincho-Italic';
  21387. t['Wingdings'] = 'ZapfDingbats';
  21388. });
  21389. var getSerifFonts = getLookupTableFactory(function (t) {
  21390. t['Adobe Jenson'] = true;
  21391. t['Adobe Text'] = true;
  21392. t['Albertus'] = true;
  21393. t['Aldus'] = true;
  21394. t['Alexandria'] = true;
  21395. t['Algerian'] = true;
  21396. t['American Typewriter'] = true;
  21397. t['Antiqua'] = true;
  21398. t['Apex'] = true;
  21399. t['Arno'] = true;
  21400. t['Aster'] = true;
  21401. t['Aurora'] = true;
  21402. t['Baskerville'] = true;
  21403. t['Bell'] = true;
  21404. t['Bembo'] = true;
  21405. t['Bembo Schoolbook'] = true;
  21406. t['Benguiat'] = true;
  21407. t['Berkeley Old Style'] = true;
  21408. t['Bernhard Modern'] = true;
  21409. t['Berthold City'] = true;
  21410. t['Bodoni'] = true;
  21411. t['Bauer Bodoni'] = true;
  21412. t['Book Antiqua'] = true;
  21413. t['Bookman'] = true;
  21414. t['Bordeaux Roman'] = true;
  21415. t['Californian FB'] = true;
  21416. t['Calisto'] = true;
  21417. t['Calvert'] = true;
  21418. t['Capitals'] = true;
  21419. t['Cambria'] = true;
  21420. t['Cartier'] = true;
  21421. t['Caslon'] = true;
  21422. t['Catull'] = true;
  21423. t['Centaur'] = true;
  21424. t['Century Old Style'] = true;
  21425. t['Century Schoolbook'] = true;
  21426. t['Chaparral'] = true;
  21427. t['Charis SIL'] = true;
  21428. t['Cheltenham'] = true;
  21429. t['Cholla Slab'] = true;
  21430. t['Clarendon'] = true;
  21431. t['Clearface'] = true;
  21432. t['Cochin'] = true;
  21433. t['Colonna'] = true;
  21434. t['Computer Modern'] = true;
  21435. t['Concrete Roman'] = true;
  21436. t['Constantia'] = true;
  21437. t['Cooper Black'] = true;
  21438. t['Corona'] = true;
  21439. t['Ecotype'] = true;
  21440. t['Egyptienne'] = true;
  21441. t['Elephant'] = true;
  21442. t['Excelsior'] = true;
  21443. t['Fairfield'] = true;
  21444. t['FF Scala'] = true;
  21445. t['Folkard'] = true;
  21446. t['Footlight'] = true;
  21447. t['FreeSerif'] = true;
  21448. t['Friz Quadrata'] = true;
  21449. t['Garamond'] = true;
  21450. t['Gentium'] = true;
  21451. t['Georgia'] = true;
  21452. t['Gloucester'] = true;
  21453. t['Goudy Old Style'] = true;
  21454. t['Goudy Schoolbook'] = true;
  21455. t['Goudy Pro Font'] = true;
  21456. t['Granjon'] = true;
  21457. t['Guardian Egyptian'] = true;
  21458. t['Heather'] = true;
  21459. t['Hercules'] = true;
  21460. t['High Tower Text'] = true;
  21461. t['Hiroshige'] = true;
  21462. t['Hoefler Text'] = true;
  21463. t['Humana Serif'] = true;
  21464. t['Imprint'] = true;
  21465. t['Ionic No. 5'] = true;
  21466. t['Janson'] = true;
  21467. t['Joanna'] = true;
  21468. t['Korinna'] = true;
  21469. t['Lexicon'] = true;
  21470. t['Liberation Serif'] = true;
  21471. t['Linux Libertine'] = true;
  21472. t['Literaturnaya'] = true;
  21473. t['Lucida'] = true;
  21474. t['Lucida Bright'] = true;
  21475. t['Melior'] = true;
  21476. t['Memphis'] = true;
  21477. t['Miller'] = true;
  21478. t['Minion'] = true;
  21479. t['Modern'] = true;
  21480. t['Mona Lisa'] = true;
  21481. t['Mrs Eaves'] = true;
  21482. t['MS Serif'] = true;
  21483. t['Museo Slab'] = true;
  21484. t['New York'] = true;
  21485. t['Nimbus Roman'] = true;
  21486. t['NPS Rawlinson Roadway'] = true;
  21487. t['Palatino'] = true;
  21488. t['Perpetua'] = true;
  21489. t['Plantin'] = true;
  21490. t['Plantin Schoolbook'] = true;
  21491. t['Playbill'] = true;
  21492. t['Poor Richard'] = true;
  21493. t['Rawlinson Roadway'] = true;
  21494. t['Renault'] = true;
  21495. t['Requiem'] = true;
  21496. t['Rockwell'] = true;
  21497. t['Roman'] = true;
  21498. t['Rotis Serif'] = true;
  21499. t['Sabon'] = true;
  21500. t['Scala'] = true;
  21501. t['Seagull'] = true;
  21502. t['Sistina'] = true;
  21503. t['Souvenir'] = true;
  21504. t['STIX'] = true;
  21505. t['Stone Informal'] = true;
  21506. t['Stone Serif'] = true;
  21507. t['Sylfaen'] = true;
  21508. t['Times'] = true;
  21509. t['Trajan'] = true;
  21510. t['Trinité'] = true;
  21511. t['Trump Mediaeval'] = true;
  21512. t['Utopia'] = true;
  21513. t['Vale Type'] = true;
  21514. t['Bitstream Vera'] = true;
  21515. t['Vera Serif'] = true;
  21516. t['Versailles'] = true;
  21517. t['Wanted'] = true;
  21518. t['Weiss'] = true;
  21519. t['Wide Latin'] = true;
  21520. t['Windsor'] = true;
  21521. t['XITS'] = true;
  21522. });
  21523. var getSymbolsFonts = getLookupTableFactory(function (t) {
  21524. t['Dingbats'] = true;
  21525. t['Symbol'] = true;
  21526. t['ZapfDingbats'] = true;
  21527. });
  21528. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID
  21529. // fonts, but does not embed the CID to GID mapping. The mapping is incomplete
  21530. // for all glyphs, but common for some set of the standard fonts.
  21531. var getGlyphMapForStandardFonts = getLookupTableFactory(function (t) {
  21532. t[2] = 10;
  21533. t[3] = 32;
  21534. t[4] = 33;
  21535. t[5] = 34;
  21536. t[6] = 35;
  21537. t[7] = 36;
  21538. t[8] = 37;
  21539. t[9] = 38;
  21540. t[10] = 39;
  21541. t[11] = 40;
  21542. t[12] = 41;
  21543. t[13] = 42;
  21544. t[14] = 43;
  21545. t[15] = 44;
  21546. t[16] = 45;
  21547. t[17] = 46;
  21548. t[18] = 47;
  21549. t[19] = 48;
  21550. t[20] = 49;
  21551. t[21] = 50;
  21552. t[22] = 51;
  21553. t[23] = 52;
  21554. t[24] = 53;
  21555. t[25] = 54;
  21556. t[26] = 55;
  21557. t[27] = 56;
  21558. t[28] = 57;
  21559. t[29] = 58;
  21560. t[30] = 894;
  21561. t[31] = 60;
  21562. t[32] = 61;
  21563. t[33] = 62;
  21564. t[34] = 63;
  21565. t[35] = 64;
  21566. t[36] = 65;
  21567. t[37] = 66;
  21568. t[38] = 67;
  21569. t[39] = 68;
  21570. t[40] = 69;
  21571. t[41] = 70;
  21572. t[42] = 71;
  21573. t[43] = 72;
  21574. t[44] = 73;
  21575. t[45] = 74;
  21576. t[46] = 75;
  21577. t[47] = 76;
  21578. t[48] = 77;
  21579. t[49] = 78;
  21580. t[50] = 79;
  21581. t[51] = 80;
  21582. t[52] = 81;
  21583. t[53] = 82;
  21584. t[54] = 83;
  21585. t[55] = 84;
  21586. t[56] = 85;
  21587. t[57] = 86;
  21588. t[58] = 87;
  21589. t[59] = 88;
  21590. t[60] = 89;
  21591. t[61] = 90;
  21592. t[62] = 91;
  21593. t[63] = 92;
  21594. t[64] = 93;
  21595. t[65] = 94;
  21596. t[66] = 95;
  21597. t[67] = 96;
  21598. t[68] = 97;
  21599. t[69] = 98;
  21600. t[70] = 99;
  21601. t[71] = 100;
  21602. t[72] = 101;
  21603. t[73] = 102;
  21604. t[74] = 103;
  21605. t[75] = 104;
  21606. t[76] = 105;
  21607. t[77] = 106;
  21608. t[78] = 107;
  21609. t[79] = 108;
  21610. t[80] = 109;
  21611. t[81] = 110;
  21612. t[82] = 111;
  21613. t[83] = 112;
  21614. t[84] = 113;
  21615. t[85] = 114;
  21616. t[86] = 115;
  21617. t[87] = 116;
  21618. t[88] = 117;
  21619. t[89] = 118;
  21620. t[90] = 119;
  21621. t[91] = 120;
  21622. t[92] = 121;
  21623. t[93] = 122;
  21624. t[94] = 123;
  21625. t[95] = 124;
  21626. t[96] = 125;
  21627. t[97] = 126;
  21628. t[98] = 196;
  21629. t[99] = 197;
  21630. t[100] = 199;
  21631. t[101] = 201;
  21632. t[102] = 209;
  21633. t[103] = 214;
  21634. t[104] = 220;
  21635. t[105] = 225;
  21636. t[106] = 224;
  21637. t[107] = 226;
  21638. t[108] = 228;
  21639. t[109] = 227;
  21640. t[110] = 229;
  21641. t[111] = 231;
  21642. t[112] = 233;
  21643. t[113] = 232;
  21644. t[114] = 234;
  21645. t[115] = 235;
  21646. t[116] = 237;
  21647. t[117] = 236;
  21648. t[118] = 238;
  21649. t[119] = 239;
  21650. t[120] = 241;
  21651. t[121] = 243;
  21652. t[122] = 242;
  21653. t[123] = 244;
  21654. t[124] = 246;
  21655. t[125] = 245;
  21656. t[126] = 250;
  21657. t[127] = 249;
  21658. t[128] = 251;
  21659. t[129] = 252;
  21660. t[130] = 8224;
  21661. t[131] = 176;
  21662. t[132] = 162;
  21663. t[133] = 163;
  21664. t[134] = 167;
  21665. t[135] = 8226;
  21666. t[136] = 182;
  21667. t[137] = 223;
  21668. t[138] = 174;
  21669. t[139] = 169;
  21670. t[140] = 8482;
  21671. t[141] = 180;
  21672. t[142] = 168;
  21673. t[143] = 8800;
  21674. t[144] = 198;
  21675. t[145] = 216;
  21676. t[146] = 8734;
  21677. t[147] = 177;
  21678. t[148] = 8804;
  21679. t[149] = 8805;
  21680. t[150] = 165;
  21681. t[151] = 181;
  21682. t[152] = 8706;
  21683. t[153] = 8721;
  21684. t[154] = 8719;
  21685. t[156] = 8747;
  21686. t[157] = 170;
  21687. t[158] = 186;
  21688. t[159] = 8486;
  21689. t[160] = 230;
  21690. t[161] = 248;
  21691. t[162] = 191;
  21692. t[163] = 161;
  21693. t[164] = 172;
  21694. t[165] = 8730;
  21695. t[166] = 402;
  21696. t[167] = 8776;
  21697. t[168] = 8710;
  21698. t[169] = 171;
  21699. t[170] = 187;
  21700. t[171] = 8230;
  21701. t[210] = 218;
  21702. t[223] = 711;
  21703. t[224] = 321;
  21704. t[225] = 322;
  21705. t[227] = 353;
  21706. t[229] = 382;
  21707. t[234] = 253;
  21708. t[252] = 263;
  21709. t[253] = 268;
  21710. t[254] = 269;
  21711. t[258] = 258;
  21712. t[260] = 260;
  21713. t[261] = 261;
  21714. t[265] = 280;
  21715. t[266] = 281;
  21716. t[268] = 283;
  21717. t[269] = 313;
  21718. t[275] = 323;
  21719. t[276] = 324;
  21720. t[278] = 328;
  21721. t[284] = 345;
  21722. t[285] = 346;
  21723. t[286] = 347;
  21724. t[292] = 367;
  21725. t[295] = 377;
  21726. t[296] = 378;
  21727. t[298] = 380;
  21728. t[305] = 963;
  21729. t[306] = 964;
  21730. t[307] = 966;
  21731. t[308] = 8215;
  21732. t[309] = 8252;
  21733. t[310] = 8319;
  21734. t[311] = 8359;
  21735. t[312] = 8592;
  21736. t[313] = 8593;
  21737. t[337] = 9552;
  21738. t[493] = 1039;
  21739. t[494] = 1040;
  21740. t[705] = 1524;
  21741. t[706] = 8362;
  21742. t[710] = 64288;
  21743. t[711] = 64298;
  21744. t[759] = 1617;
  21745. t[761] = 1776;
  21746. t[763] = 1778;
  21747. t[775] = 1652;
  21748. t[777] = 1764;
  21749. t[778] = 1780;
  21750. t[779] = 1781;
  21751. t[780] = 1782;
  21752. t[782] = 771;
  21753. t[783] = 64726;
  21754. t[786] = 8363;
  21755. t[788] = 8532;
  21756. t[790] = 768;
  21757. t[791] = 769;
  21758. t[792] = 768;
  21759. t[795] = 803;
  21760. t[797] = 64336;
  21761. t[798] = 64337;
  21762. t[799] = 64342;
  21763. t[800] = 64343;
  21764. t[801] = 64344;
  21765. t[802] = 64345;
  21766. t[803] = 64362;
  21767. t[804] = 64363;
  21768. t[805] = 64364;
  21769. t[2424] = 7821;
  21770. t[2425] = 7822;
  21771. t[2426] = 7823;
  21772. t[2427] = 7824;
  21773. t[2428] = 7825;
  21774. t[2429] = 7826;
  21775. t[2430] = 7827;
  21776. t[2433] = 7682;
  21777. t[2678] = 8045;
  21778. t[2679] = 8046;
  21779. t[2830] = 1552;
  21780. t[2838] = 686;
  21781. t[2840] = 751;
  21782. t[2842] = 753;
  21783. t[2843] = 754;
  21784. t[2844] = 755;
  21785. t[2846] = 757;
  21786. t[2856] = 767;
  21787. t[2857] = 848;
  21788. t[2858] = 849;
  21789. t[2862] = 853;
  21790. t[2863] = 854;
  21791. t[2864] = 855;
  21792. t[2865] = 861;
  21793. t[2866] = 862;
  21794. t[2906] = 7460;
  21795. t[2908] = 7462;
  21796. t[2909] = 7463;
  21797. t[2910] = 7464;
  21798. t[2912] = 7466;
  21799. t[2913] = 7467;
  21800. t[2914] = 7468;
  21801. t[2916] = 7470;
  21802. t[2917] = 7471;
  21803. t[2918] = 7472;
  21804. t[2920] = 7474;
  21805. t[2921] = 7475;
  21806. t[2922] = 7476;
  21807. t[2924] = 7478;
  21808. t[2925] = 7479;
  21809. t[2926] = 7480;
  21810. t[2928] = 7482;
  21811. t[2929] = 7483;
  21812. t[2930] = 7484;
  21813. t[2932] = 7486;
  21814. t[2933] = 7487;
  21815. t[2934] = 7488;
  21816. t[2936] = 7490;
  21817. t[2937] = 7491;
  21818. t[2938] = 7492;
  21819. t[2940] = 7494;
  21820. t[2941] = 7495;
  21821. t[2942] = 7496;
  21822. t[2944] = 7498;
  21823. t[2946] = 7500;
  21824. t[2948] = 7502;
  21825. t[2950] = 7504;
  21826. t[2951] = 7505;
  21827. t[2952] = 7506;
  21828. t[2954] = 7508;
  21829. t[2955] = 7509;
  21830. t[2956] = 7510;
  21831. t[2958] = 7512;
  21832. t[2959] = 7513;
  21833. t[2960] = 7514;
  21834. t[2962] = 7516;
  21835. t[2963] = 7517;
  21836. t[2964] = 7518;
  21837. t[2966] = 7520;
  21838. t[2967] = 7521;
  21839. t[2968] = 7522;
  21840. t[2970] = 7524;
  21841. t[2971] = 7525;
  21842. t[2972] = 7526;
  21843. t[2974] = 7528;
  21844. t[2975] = 7529;
  21845. t[2976] = 7530;
  21846. t[2978] = 1537;
  21847. t[2979] = 1538;
  21848. t[2980] = 1539;
  21849. t[2982] = 1549;
  21850. t[2983] = 1551;
  21851. t[2984] = 1552;
  21852. t[2986] = 1554;
  21853. t[2987] = 1555;
  21854. t[2988] = 1556;
  21855. t[2990] = 1623;
  21856. t[2991] = 1624;
  21857. t[2995] = 1775;
  21858. t[2999] = 1791;
  21859. t[3002] = 64290;
  21860. t[3003] = 64291;
  21861. t[3004] = 64292;
  21862. t[3006] = 64294;
  21863. t[3007] = 64295;
  21864. t[3008] = 64296;
  21865. t[3011] = 1900;
  21866. t[3014] = 8223;
  21867. t[3015] = 8244;
  21868. t[3017] = 7532;
  21869. t[3018] = 7533;
  21870. t[3019] = 7534;
  21871. t[3075] = 7590;
  21872. t[3076] = 7591;
  21873. t[3079] = 7594;
  21874. t[3080] = 7595;
  21875. t[3083] = 7598;
  21876. t[3084] = 7599;
  21877. t[3087] = 7602;
  21878. t[3088] = 7603;
  21879. t[3091] = 7606;
  21880. t[3092] = 7607;
  21881. t[3095] = 7610;
  21882. t[3096] = 7611;
  21883. t[3099] = 7614;
  21884. t[3100] = 7615;
  21885. t[3103] = 7618;
  21886. t[3104] = 7619;
  21887. t[3107] = 8337;
  21888. t[3108] = 8338;
  21889. t[3116] = 1884;
  21890. t[3119] = 1885;
  21891. t[3120] = 1885;
  21892. t[3123] = 1886;
  21893. t[3124] = 1886;
  21894. t[3127] = 1887;
  21895. t[3128] = 1887;
  21896. t[3131] = 1888;
  21897. t[3132] = 1888;
  21898. t[3135] = 1889;
  21899. t[3136] = 1889;
  21900. t[3139] = 1890;
  21901. t[3140] = 1890;
  21902. t[3143] = 1891;
  21903. t[3144] = 1891;
  21904. t[3147] = 1892;
  21905. t[3148] = 1892;
  21906. t[3153] = 580;
  21907. t[3154] = 581;
  21908. t[3157] = 584;
  21909. t[3158] = 585;
  21910. t[3161] = 588;
  21911. t[3162] = 589;
  21912. t[3165] = 891;
  21913. t[3166] = 892;
  21914. t[3169] = 1274;
  21915. t[3170] = 1275;
  21916. t[3173] = 1278;
  21917. t[3174] = 1279;
  21918. t[3181] = 7622;
  21919. t[3182] = 7623;
  21920. t[3282] = 11799;
  21921. t[3316] = 578;
  21922. t[3379] = 42785;
  21923. t[3393] = 1159;
  21924. t[3416] = 8377;
  21925. });
  21926. // The glyph map for ArialBlack differs slightly from the glyph map used for
  21927. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  21928. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  21929. var getSupplementalGlyphMapForArialBlack = getLookupTableFactory(function (t) {
  21930. t[227] = 322;
  21931. t[264] = 261;
  21932. t[291] = 346;
  21933. });
  21934. exports.getStdFontMap = getStdFontMap;
  21935. exports.getNonStdFontMap = getNonStdFontMap;
  21936. exports.getSerifFonts = getSerifFonts;
  21937. exports.getSymbolsFonts = getSymbolsFonts;
  21938. exports.getGlyphMapForStandardFonts = getGlyphMapForStandardFonts;
  21939. exports.getSupplementalGlyphMapForArialBlack = getSupplementalGlyphMapForArialBlack;
  21940. }));
  21941. (function (root, factory) {
  21942. factory(root.pdfjsCoreUnicode = {}, root.pdfjsSharedUtil);
  21943. }(this, function (exports, sharedUtil) {
  21944. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  21945. // Some characters, e.g. copyrightserif, are mapped to the private use area
  21946. // and might not be displayed using standard fonts. Mapping/hacking well-known
  21947. // chars to the similar equivalents in the normal characters range.
  21948. var getSpecialPUASymbols = getLookupTableFactory(function (t) {
  21949. t[63721] = 0x00A9;
  21950. // copyrightsans (0xF8E9) => copyright
  21951. t[63193] = 0x00A9;
  21952. // copyrightserif (0xF6D9) => copyright
  21953. t[63720] = 0x00AE;
  21954. // registersans (0xF8E8) => registered
  21955. t[63194] = 0x00AE;
  21956. // registerserif (0xF6DA) => registered
  21957. t[63722] = 0x2122;
  21958. // trademarksans (0xF8EA) => trademark
  21959. t[63195] = 0x2122;
  21960. // trademarkserif (0xF6DB) => trademark
  21961. t[63729] = 0x23A7;
  21962. // bracelefttp (0xF8F1)
  21963. t[63730] = 0x23A8;
  21964. // braceleftmid (0xF8F2)
  21965. t[63731] = 0x23A9;
  21966. // braceleftbt (0xF8F3)
  21967. t[63740] = 0x23AB;
  21968. // bracerighttp (0xF8FC)
  21969. t[63741] = 0x23AC;
  21970. // bracerightmid (0xF8FD)
  21971. t[63742] = 0x23AD;
  21972. // bracerightbt (0xF8FE)
  21973. t[63726] = 0x23A1;
  21974. // bracketlefttp (0xF8EE)
  21975. t[63727] = 0x23A2;
  21976. // bracketleftex (0xF8EF)
  21977. t[63728] = 0x23A3;
  21978. // bracketleftbt (0xF8F0)
  21979. t[63737] = 0x23A4;
  21980. // bracketrighttp (0xF8F9)
  21981. t[63738] = 0x23A5;
  21982. // bracketrightex (0xF8FA)
  21983. t[63739] = 0x23A6;
  21984. // bracketrightbt (0xF8FB)
  21985. t[63723] = 0x239B;
  21986. // parenlefttp (0xF8EB)
  21987. t[63724] = 0x239C;
  21988. // parenleftex (0xF8EC)
  21989. t[63725] = 0x239D;
  21990. // parenleftbt (0xF8ED)
  21991. t[63734] = 0x239E;
  21992. // parenrighttp (0xF8F6)
  21993. t[63735] = 0x239F;
  21994. // parenrightex (0xF8F7)
  21995. t[63736] = 0x23A0;
  21996. });
  21997. // parenrightbt (0xF8F8)
  21998. function mapSpecialUnicodeValues(code) {
  21999. if (code >= 0xFFF0 && code <= 0xFFFF) {
  22000. // Specials unicode block.
  22001. return 0;
  22002. } else if (code >= 0xF600 && code <= 0xF8FF) {
  22003. return getSpecialPUASymbols()[code] || code;
  22004. }
  22005. return code;
  22006. }
  22007. function getUnicodeForGlyph(name, glyphsUnicodeMap) {
  22008. var unicode = glyphsUnicodeMap[name];
  22009. if (unicode !== undefined) {
  22010. return unicode;
  22011. }
  22012. if (!name) {
  22013. return -1;
  22014. }
  22015. // Try to recover valid Unicode values from 'uniXXXX'/'uXXXX{XX}' glyphs.
  22016. if (name[0] === 'u') {
  22017. var nameLen = name.length, hexStr;
  22018. if (nameLen === 7 && name[1] === 'n' && name[2] === 'i') {
  22019. // 'uniXXXX'
  22020. hexStr = name.substr(3);
  22021. } else if (nameLen >= 5 && nameLen <= 7) {
  22022. // 'uXXXX{XX}'
  22023. hexStr = name.substr(1);
  22024. } else {
  22025. return -1;
  22026. }
  22027. // Check for upper-case hexadecimal characters, to avoid false positives.
  22028. if (hexStr === hexStr.toUpperCase()) {
  22029. unicode = parseInt(hexStr, 16);
  22030. if (unicode >= 0) {
  22031. return unicode;
  22032. }
  22033. }
  22034. }
  22035. return -1;
  22036. }
  22037. var UnicodeRanges = [
  22038. {
  22039. 'begin': 0x0000,
  22040. 'end': 0x007F
  22041. },
  22042. // Basic Latin
  22043. {
  22044. 'begin': 0x0080,
  22045. 'end': 0x00FF
  22046. },
  22047. // Latin-1 Supplement
  22048. {
  22049. 'begin': 0x0100,
  22050. 'end': 0x017F
  22051. },
  22052. // Latin Extended-A
  22053. {
  22054. 'begin': 0x0180,
  22055. 'end': 0x024F
  22056. },
  22057. // Latin Extended-B
  22058. {
  22059. 'begin': 0x0250,
  22060. 'end': 0x02AF
  22061. },
  22062. // IPA Extensions
  22063. {
  22064. 'begin': 0x02B0,
  22065. 'end': 0x02FF
  22066. },
  22067. // Spacing Modifier Letters
  22068. {
  22069. 'begin': 0x0300,
  22070. 'end': 0x036F
  22071. },
  22072. // Combining Diacritical Marks
  22073. {
  22074. 'begin': 0x0370,
  22075. 'end': 0x03FF
  22076. },
  22077. // Greek and Coptic
  22078. {
  22079. 'begin': 0x2C80,
  22080. 'end': 0x2CFF
  22081. },
  22082. // Coptic
  22083. {
  22084. 'begin': 0x0400,
  22085. 'end': 0x04FF
  22086. },
  22087. // Cyrillic
  22088. {
  22089. 'begin': 0x0530,
  22090. 'end': 0x058F
  22091. },
  22092. // Armenian
  22093. {
  22094. 'begin': 0x0590,
  22095. 'end': 0x05FF
  22096. },
  22097. // Hebrew
  22098. {
  22099. 'begin': 0xA500,
  22100. 'end': 0xA63F
  22101. },
  22102. // Vai
  22103. {
  22104. 'begin': 0x0600,
  22105. 'end': 0x06FF
  22106. },
  22107. // Arabic
  22108. {
  22109. 'begin': 0x07C0,
  22110. 'end': 0x07FF
  22111. },
  22112. // NKo
  22113. {
  22114. 'begin': 0x0900,
  22115. 'end': 0x097F
  22116. },
  22117. // Devanagari
  22118. {
  22119. 'begin': 0x0980,
  22120. 'end': 0x09FF
  22121. },
  22122. // Bengali
  22123. {
  22124. 'begin': 0x0A00,
  22125. 'end': 0x0A7F
  22126. },
  22127. // Gurmukhi
  22128. {
  22129. 'begin': 0x0A80,
  22130. 'end': 0x0AFF
  22131. },
  22132. // Gujarati
  22133. {
  22134. 'begin': 0x0B00,
  22135. 'end': 0x0B7F
  22136. },
  22137. // Oriya
  22138. {
  22139. 'begin': 0x0B80,
  22140. 'end': 0x0BFF
  22141. },
  22142. // Tamil
  22143. {
  22144. 'begin': 0x0C00,
  22145. 'end': 0x0C7F
  22146. },
  22147. // Telugu
  22148. {
  22149. 'begin': 0x0C80,
  22150. 'end': 0x0CFF
  22151. },
  22152. // Kannada
  22153. {
  22154. 'begin': 0x0D00,
  22155. 'end': 0x0D7F
  22156. },
  22157. // Malayalam
  22158. {
  22159. 'begin': 0x0E00,
  22160. 'end': 0x0E7F
  22161. },
  22162. // Thai
  22163. {
  22164. 'begin': 0x0E80,
  22165. 'end': 0x0EFF
  22166. },
  22167. // Lao
  22168. {
  22169. 'begin': 0x10A0,
  22170. 'end': 0x10FF
  22171. },
  22172. // Georgian
  22173. {
  22174. 'begin': 0x1B00,
  22175. 'end': 0x1B7F
  22176. },
  22177. // Balinese
  22178. {
  22179. 'begin': 0x1100,
  22180. 'end': 0x11FF
  22181. },
  22182. // Hangul Jamo
  22183. {
  22184. 'begin': 0x1E00,
  22185. 'end': 0x1EFF
  22186. },
  22187. // Latin Extended Additional
  22188. {
  22189. 'begin': 0x1F00,
  22190. 'end': 0x1FFF
  22191. },
  22192. // Greek Extended
  22193. {
  22194. 'begin': 0x2000,
  22195. 'end': 0x206F
  22196. },
  22197. // General Punctuation
  22198. {
  22199. 'begin': 0x2070,
  22200. 'end': 0x209F
  22201. },
  22202. // Superscripts And Subscripts
  22203. {
  22204. 'begin': 0x20A0,
  22205. 'end': 0x20CF
  22206. },
  22207. // Currency Symbol
  22208. {
  22209. 'begin': 0x20D0,
  22210. 'end': 0x20FF
  22211. },
  22212. // Combining Diacritical Marks
  22213. {
  22214. 'begin': 0x2100,
  22215. 'end': 0x214F
  22216. },
  22217. // Letterlike Symbols
  22218. {
  22219. 'begin': 0x2150,
  22220. 'end': 0x218F
  22221. },
  22222. // Number Forms
  22223. {
  22224. 'begin': 0x2190,
  22225. 'end': 0x21FF
  22226. },
  22227. // Arrows
  22228. {
  22229. 'begin': 0x2200,
  22230. 'end': 0x22FF
  22231. },
  22232. // Mathematical Operators
  22233. {
  22234. 'begin': 0x2300,
  22235. 'end': 0x23FF
  22236. },
  22237. // Miscellaneous Technical
  22238. {
  22239. 'begin': 0x2400,
  22240. 'end': 0x243F
  22241. },
  22242. // Control Pictures
  22243. {
  22244. 'begin': 0x2440,
  22245. 'end': 0x245F
  22246. },
  22247. // Optical Character Recognition
  22248. {
  22249. 'begin': 0x2460,
  22250. 'end': 0x24FF
  22251. },
  22252. // Enclosed Alphanumerics
  22253. {
  22254. 'begin': 0x2500,
  22255. 'end': 0x257F
  22256. },
  22257. // Box Drawing
  22258. {
  22259. 'begin': 0x2580,
  22260. 'end': 0x259F
  22261. },
  22262. // Block Elements
  22263. {
  22264. 'begin': 0x25A0,
  22265. 'end': 0x25FF
  22266. },
  22267. // Geometric Shapes
  22268. {
  22269. 'begin': 0x2600,
  22270. 'end': 0x26FF
  22271. },
  22272. // Miscellaneous Symbols
  22273. {
  22274. 'begin': 0x2700,
  22275. 'end': 0x27BF
  22276. },
  22277. // Dingbats
  22278. {
  22279. 'begin': 0x3000,
  22280. 'end': 0x303F
  22281. },
  22282. // CJK Symbols And Punctuation
  22283. {
  22284. 'begin': 0x3040,
  22285. 'end': 0x309F
  22286. },
  22287. // Hiragana
  22288. {
  22289. 'begin': 0x30A0,
  22290. 'end': 0x30FF
  22291. },
  22292. // Katakana
  22293. {
  22294. 'begin': 0x3100,
  22295. 'end': 0x312F
  22296. },
  22297. // Bopomofo
  22298. {
  22299. 'begin': 0x3130,
  22300. 'end': 0x318F
  22301. },
  22302. // Hangul Compatibility Jamo
  22303. {
  22304. 'begin': 0xA840,
  22305. 'end': 0xA87F
  22306. },
  22307. // Phags-pa
  22308. {
  22309. 'begin': 0x3200,
  22310. 'end': 0x32FF
  22311. },
  22312. // Enclosed CJK Letters And Months
  22313. {
  22314. 'begin': 0x3300,
  22315. 'end': 0x33FF
  22316. },
  22317. // CJK Compatibility
  22318. {
  22319. 'begin': 0xAC00,
  22320. 'end': 0xD7AF
  22321. },
  22322. // Hangul Syllables
  22323. {
  22324. 'begin': 0xD800,
  22325. 'end': 0xDFFF
  22326. },
  22327. // Non-Plane 0 *
  22328. {
  22329. 'begin': 0x10900,
  22330. 'end': 0x1091F
  22331. },
  22332. // Phoenicia
  22333. {
  22334. 'begin': 0x4E00,
  22335. 'end': 0x9FFF
  22336. },
  22337. // CJK Unified Ideographs
  22338. {
  22339. 'begin': 0xE000,
  22340. 'end': 0xF8FF
  22341. },
  22342. // Private Use Area (plane 0)
  22343. {
  22344. 'begin': 0x31C0,
  22345. 'end': 0x31EF
  22346. },
  22347. // CJK Strokes
  22348. {
  22349. 'begin': 0xFB00,
  22350. 'end': 0xFB4F
  22351. },
  22352. // Alphabetic Presentation Forms
  22353. {
  22354. 'begin': 0xFB50,
  22355. 'end': 0xFDFF
  22356. },
  22357. // Arabic Presentation Forms-A
  22358. {
  22359. 'begin': 0xFE20,
  22360. 'end': 0xFE2F
  22361. },
  22362. // Combining Half Marks
  22363. {
  22364. 'begin': 0xFE10,
  22365. 'end': 0xFE1F
  22366. },
  22367. // Vertical Forms
  22368. {
  22369. 'begin': 0xFE50,
  22370. 'end': 0xFE6F
  22371. },
  22372. // Small Form Variants
  22373. {
  22374. 'begin': 0xFE70,
  22375. 'end': 0xFEFF
  22376. },
  22377. // Arabic Presentation Forms-B
  22378. {
  22379. 'begin': 0xFF00,
  22380. 'end': 0xFFEF
  22381. },
  22382. // Halfwidth And Fullwidth Forms
  22383. {
  22384. 'begin': 0xFFF0,
  22385. 'end': 0xFFFF
  22386. },
  22387. // Specials
  22388. {
  22389. 'begin': 0x0F00,
  22390. 'end': 0x0FFF
  22391. },
  22392. // Tibetan
  22393. {
  22394. 'begin': 0x0700,
  22395. 'end': 0x074F
  22396. },
  22397. // Syriac
  22398. {
  22399. 'begin': 0x0780,
  22400. 'end': 0x07BF
  22401. },
  22402. // Thaana
  22403. {
  22404. 'begin': 0x0D80,
  22405. 'end': 0x0DFF
  22406. },
  22407. // Sinhala
  22408. {
  22409. 'begin': 0x1000,
  22410. 'end': 0x109F
  22411. },
  22412. // Myanmar
  22413. {
  22414. 'begin': 0x1200,
  22415. 'end': 0x137F
  22416. },
  22417. // Ethiopic
  22418. {
  22419. 'begin': 0x13A0,
  22420. 'end': 0x13FF
  22421. },
  22422. // Cherokee
  22423. {
  22424. 'begin': 0x1400,
  22425. 'end': 0x167F
  22426. },
  22427. // Unified Canadian Aboriginal Syllabics
  22428. {
  22429. 'begin': 0x1680,
  22430. 'end': 0x169F
  22431. },
  22432. // Ogham
  22433. {
  22434. 'begin': 0x16A0,
  22435. 'end': 0x16FF
  22436. },
  22437. // Runic
  22438. {
  22439. 'begin': 0x1780,
  22440. 'end': 0x17FF
  22441. },
  22442. // Khmer
  22443. {
  22444. 'begin': 0x1800,
  22445. 'end': 0x18AF
  22446. },
  22447. // Mongolian
  22448. {
  22449. 'begin': 0x2800,
  22450. 'end': 0x28FF
  22451. },
  22452. // Braille Patterns
  22453. {
  22454. 'begin': 0xA000,
  22455. 'end': 0xA48F
  22456. },
  22457. // Yi Syllables
  22458. {
  22459. 'begin': 0x1700,
  22460. 'end': 0x171F
  22461. },
  22462. // Tagalog
  22463. {
  22464. 'begin': 0x10300,
  22465. 'end': 0x1032F
  22466. },
  22467. // Old Italic
  22468. {
  22469. 'begin': 0x10330,
  22470. 'end': 0x1034F
  22471. },
  22472. // Gothic
  22473. {
  22474. 'begin': 0x10400,
  22475. 'end': 0x1044F
  22476. },
  22477. // Deseret
  22478. {
  22479. 'begin': 0x1D000,
  22480. 'end': 0x1D0FF
  22481. },
  22482. // Byzantine Musical Symbols
  22483. {
  22484. 'begin': 0x1D400,
  22485. 'end': 0x1D7FF
  22486. },
  22487. // Mathematical Alphanumeric Symbols
  22488. {
  22489. 'begin': 0xFF000,
  22490. 'end': 0xFFFFD
  22491. },
  22492. // Private Use (plane 15)
  22493. {
  22494. 'begin': 0xFE00,
  22495. 'end': 0xFE0F
  22496. },
  22497. // Variation Selectors
  22498. {
  22499. 'begin': 0xE0000,
  22500. 'end': 0xE007F
  22501. },
  22502. // Tags
  22503. {
  22504. 'begin': 0x1900,
  22505. 'end': 0x194F
  22506. },
  22507. // Limbu
  22508. {
  22509. 'begin': 0x1950,
  22510. 'end': 0x197F
  22511. },
  22512. // Tai Le
  22513. {
  22514. 'begin': 0x1980,
  22515. 'end': 0x19DF
  22516. },
  22517. // New Tai Lue
  22518. {
  22519. 'begin': 0x1A00,
  22520. 'end': 0x1A1F
  22521. },
  22522. // Buginese
  22523. {
  22524. 'begin': 0x2C00,
  22525. 'end': 0x2C5F
  22526. },
  22527. // Glagolitic
  22528. {
  22529. 'begin': 0x2D30,
  22530. 'end': 0x2D7F
  22531. },
  22532. // Tifinagh
  22533. {
  22534. 'begin': 0x4DC0,
  22535. 'end': 0x4DFF
  22536. },
  22537. // Yijing Hexagram Symbols
  22538. {
  22539. 'begin': 0xA800,
  22540. 'end': 0xA82F
  22541. },
  22542. // Syloti Nagri
  22543. {
  22544. 'begin': 0x10000,
  22545. 'end': 0x1007F
  22546. },
  22547. // Linear B Syllabary
  22548. {
  22549. 'begin': 0x10140,
  22550. 'end': 0x1018F
  22551. },
  22552. // Ancient Greek Numbers
  22553. {
  22554. 'begin': 0x10380,
  22555. 'end': 0x1039F
  22556. },
  22557. // Ugaritic
  22558. {
  22559. 'begin': 0x103A0,
  22560. 'end': 0x103DF
  22561. },
  22562. // Old Persian
  22563. {
  22564. 'begin': 0x10450,
  22565. 'end': 0x1047F
  22566. },
  22567. // Shavian
  22568. {
  22569. 'begin': 0x10480,
  22570. 'end': 0x104AF
  22571. },
  22572. // Osmanya
  22573. {
  22574. 'begin': 0x10800,
  22575. 'end': 0x1083F
  22576. },
  22577. // Cypriot Syllabary
  22578. {
  22579. 'begin': 0x10A00,
  22580. 'end': 0x10A5F
  22581. },
  22582. // Kharoshthi
  22583. {
  22584. 'begin': 0x1D300,
  22585. 'end': 0x1D35F
  22586. },
  22587. // Tai Xuan Jing Symbols
  22588. {
  22589. 'begin': 0x12000,
  22590. 'end': 0x123FF
  22591. },
  22592. // Cuneiform
  22593. {
  22594. 'begin': 0x1D360,
  22595. 'end': 0x1D37F
  22596. },
  22597. // Counting Rod Numerals
  22598. {
  22599. 'begin': 0x1B80,
  22600. 'end': 0x1BBF
  22601. },
  22602. // Sundanese
  22603. {
  22604. 'begin': 0x1C00,
  22605. 'end': 0x1C4F
  22606. },
  22607. // Lepcha
  22608. {
  22609. 'begin': 0x1C50,
  22610. 'end': 0x1C7F
  22611. },
  22612. // Ol Chiki
  22613. {
  22614. 'begin': 0xA880,
  22615. 'end': 0xA8DF
  22616. },
  22617. // Saurashtra
  22618. {
  22619. 'begin': 0xA900,
  22620. 'end': 0xA92F
  22621. },
  22622. // Kayah Li
  22623. {
  22624. 'begin': 0xA930,
  22625. 'end': 0xA95F
  22626. },
  22627. // Rejang
  22628. {
  22629. 'begin': 0xAA00,
  22630. 'end': 0xAA5F
  22631. },
  22632. // Cham
  22633. {
  22634. 'begin': 0x10190,
  22635. 'end': 0x101CF
  22636. },
  22637. // Ancient Symbols
  22638. {
  22639. 'begin': 0x101D0,
  22640. 'end': 0x101FF
  22641. },
  22642. // Phaistos Disc
  22643. {
  22644. 'begin': 0x102A0,
  22645. 'end': 0x102DF
  22646. },
  22647. // Carian
  22648. {
  22649. 'begin': 0x1F030,
  22650. 'end': 0x1F09F
  22651. }
  22652. ];
  22653. // Domino Tiles
  22654. function getUnicodeRangeFor(value) {
  22655. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  22656. var range = UnicodeRanges[i];
  22657. if (value >= range.begin && value < range.end) {
  22658. return i;
  22659. }
  22660. }
  22661. return -1;
  22662. }
  22663. function isRTLRangeFor(value) {
  22664. var range = UnicodeRanges[13];
  22665. if (value >= range.begin && value < range.end) {
  22666. return true;
  22667. }
  22668. range = UnicodeRanges[11];
  22669. if (value >= range.begin && value < range.end) {
  22670. return true;
  22671. }
  22672. return false;
  22673. }
  22674. // The normalization table is obtained by filtering the Unicode characters
  22675. // database with <compat> entries.
  22676. var getNormalizedUnicodes = getLookupTableFactory(function (t) {
  22677. t['\u00A8'] = '\u0020\u0308';
  22678. t['\u00AF'] = '\u0020\u0304';
  22679. t['\u00B4'] = '\u0020\u0301';
  22680. t['\u00B5'] = '\u03BC';
  22681. t['\u00B8'] = '\u0020\u0327';
  22682. t['\u0132'] = '\u0049\u004A';
  22683. t['\u0133'] = '\u0069\u006A';
  22684. t['\u013F'] = '\u004C\u00B7';
  22685. t['\u0140'] = '\u006C\u00B7';
  22686. t['\u0149'] = '\u02BC\u006E';
  22687. t['\u017F'] = '\u0073';
  22688. t['\u01C4'] = '\u0044\u017D';
  22689. t['\u01C5'] = '\u0044\u017E';
  22690. t['\u01C6'] = '\u0064\u017E';
  22691. t['\u01C7'] = '\u004C\u004A';
  22692. t['\u01C8'] = '\u004C\u006A';
  22693. t['\u01C9'] = '\u006C\u006A';
  22694. t['\u01CA'] = '\u004E\u004A';
  22695. t['\u01CB'] = '\u004E\u006A';
  22696. t['\u01CC'] = '\u006E\u006A';
  22697. t['\u01F1'] = '\u0044\u005A';
  22698. t['\u01F2'] = '\u0044\u007A';
  22699. t['\u01F3'] = '\u0064\u007A';
  22700. t['\u02D8'] = '\u0020\u0306';
  22701. t['\u02D9'] = '\u0020\u0307';
  22702. t['\u02DA'] = '\u0020\u030A';
  22703. t['\u02DB'] = '\u0020\u0328';
  22704. t['\u02DC'] = '\u0020\u0303';
  22705. t['\u02DD'] = '\u0020\u030B';
  22706. t['\u037A'] = '\u0020\u0345';
  22707. t['\u0384'] = '\u0020\u0301';
  22708. t['\u03D0'] = '\u03B2';
  22709. t['\u03D1'] = '\u03B8';
  22710. t['\u03D2'] = '\u03A5';
  22711. t['\u03D5'] = '\u03C6';
  22712. t['\u03D6'] = '\u03C0';
  22713. t['\u03F0'] = '\u03BA';
  22714. t['\u03F1'] = '\u03C1';
  22715. t['\u03F2'] = '\u03C2';
  22716. t['\u03F4'] = '\u0398';
  22717. t['\u03F5'] = '\u03B5';
  22718. t['\u03F9'] = '\u03A3';
  22719. t['\u0587'] = '\u0565\u0582';
  22720. t['\u0675'] = '\u0627\u0674';
  22721. t['\u0676'] = '\u0648\u0674';
  22722. t['\u0677'] = '\u06C7\u0674';
  22723. t['\u0678'] = '\u064A\u0674';
  22724. t['\u0E33'] = '\u0E4D\u0E32';
  22725. t['\u0EB3'] = '\u0ECD\u0EB2';
  22726. t['\u0EDC'] = '\u0EAB\u0E99';
  22727. t['\u0EDD'] = '\u0EAB\u0EA1';
  22728. t['\u0F77'] = '\u0FB2\u0F81';
  22729. t['\u0F79'] = '\u0FB3\u0F81';
  22730. t['\u1E9A'] = '\u0061\u02BE';
  22731. t['\u1FBD'] = '\u0020\u0313';
  22732. t['\u1FBF'] = '\u0020\u0313';
  22733. t['\u1FC0'] = '\u0020\u0342';
  22734. t['\u1FFE'] = '\u0020\u0314';
  22735. t['\u2002'] = '\u0020';
  22736. t['\u2003'] = '\u0020';
  22737. t['\u2004'] = '\u0020';
  22738. t['\u2005'] = '\u0020';
  22739. t['\u2006'] = '\u0020';
  22740. t['\u2008'] = '\u0020';
  22741. t['\u2009'] = '\u0020';
  22742. t['\u200A'] = '\u0020';
  22743. t['\u2017'] = '\u0020\u0333';
  22744. t['\u2024'] = '\u002E';
  22745. t['\u2025'] = '\u002E\u002E';
  22746. t['\u2026'] = '\u002E\u002E\u002E';
  22747. t['\u2033'] = '\u2032\u2032';
  22748. t['\u2034'] = '\u2032\u2032\u2032';
  22749. t['\u2036'] = '\u2035\u2035';
  22750. t['\u2037'] = '\u2035\u2035\u2035';
  22751. t['\u203C'] = '\u0021\u0021';
  22752. t['\u203E'] = '\u0020\u0305';
  22753. t['\u2047'] = '\u003F\u003F';
  22754. t['\u2048'] = '\u003F\u0021';
  22755. t['\u2049'] = '\u0021\u003F';
  22756. t['\u2057'] = '\u2032\u2032\u2032\u2032';
  22757. t['\u205F'] = '\u0020';
  22758. t['\u20A8'] = '\u0052\u0073';
  22759. t['\u2100'] = '\u0061\u002F\u0063';
  22760. t['\u2101'] = '\u0061\u002F\u0073';
  22761. t['\u2103'] = '\u00B0\u0043';
  22762. t['\u2105'] = '\u0063\u002F\u006F';
  22763. t['\u2106'] = '\u0063\u002F\u0075';
  22764. t['\u2107'] = '\u0190';
  22765. t['\u2109'] = '\u00B0\u0046';
  22766. t['\u2116'] = '\u004E\u006F';
  22767. t['\u2121'] = '\u0054\u0045\u004C';
  22768. t['\u2135'] = '\u05D0';
  22769. t['\u2136'] = '\u05D1';
  22770. t['\u2137'] = '\u05D2';
  22771. t['\u2138'] = '\u05D3';
  22772. t['\u213B'] = '\u0046\u0041\u0058';
  22773. t['\u2160'] = '\u0049';
  22774. t['\u2161'] = '\u0049\u0049';
  22775. t['\u2162'] = '\u0049\u0049\u0049';
  22776. t['\u2163'] = '\u0049\u0056';
  22777. t['\u2164'] = '\u0056';
  22778. t['\u2165'] = '\u0056\u0049';
  22779. t['\u2166'] = '\u0056\u0049\u0049';
  22780. t['\u2167'] = '\u0056\u0049\u0049\u0049';
  22781. t['\u2168'] = '\u0049\u0058';
  22782. t['\u2169'] = '\u0058';
  22783. t['\u216A'] = '\u0058\u0049';
  22784. t['\u216B'] = '\u0058\u0049\u0049';
  22785. t['\u216C'] = '\u004C';
  22786. t['\u216D'] = '\u0043';
  22787. t['\u216E'] = '\u0044';
  22788. t['\u216F'] = '\u004D';
  22789. t['\u2170'] = '\u0069';
  22790. t['\u2171'] = '\u0069\u0069';
  22791. t['\u2172'] = '\u0069\u0069\u0069';
  22792. t['\u2173'] = '\u0069\u0076';
  22793. t['\u2174'] = '\u0076';
  22794. t['\u2175'] = '\u0076\u0069';
  22795. t['\u2176'] = '\u0076\u0069\u0069';
  22796. t['\u2177'] = '\u0076\u0069\u0069\u0069';
  22797. t['\u2178'] = '\u0069\u0078';
  22798. t['\u2179'] = '\u0078';
  22799. t['\u217A'] = '\u0078\u0069';
  22800. t['\u217B'] = '\u0078\u0069\u0069';
  22801. t['\u217C'] = '\u006C';
  22802. t['\u217D'] = '\u0063';
  22803. t['\u217E'] = '\u0064';
  22804. t['\u217F'] = '\u006D';
  22805. t['\u222C'] = '\u222B\u222B';
  22806. t['\u222D'] = '\u222B\u222B\u222B';
  22807. t['\u222F'] = '\u222E\u222E';
  22808. t['\u2230'] = '\u222E\u222E\u222E';
  22809. t['\u2474'] = '\u0028\u0031\u0029';
  22810. t['\u2475'] = '\u0028\u0032\u0029';
  22811. t['\u2476'] = '\u0028\u0033\u0029';
  22812. t['\u2477'] = '\u0028\u0034\u0029';
  22813. t['\u2478'] = '\u0028\u0035\u0029';
  22814. t['\u2479'] = '\u0028\u0036\u0029';
  22815. t['\u247A'] = '\u0028\u0037\u0029';
  22816. t['\u247B'] = '\u0028\u0038\u0029';
  22817. t['\u247C'] = '\u0028\u0039\u0029';
  22818. t['\u247D'] = '\u0028\u0031\u0030\u0029';
  22819. t['\u247E'] = '\u0028\u0031\u0031\u0029';
  22820. t['\u247F'] = '\u0028\u0031\u0032\u0029';
  22821. t['\u2480'] = '\u0028\u0031\u0033\u0029';
  22822. t['\u2481'] = '\u0028\u0031\u0034\u0029';
  22823. t['\u2482'] = '\u0028\u0031\u0035\u0029';
  22824. t['\u2483'] = '\u0028\u0031\u0036\u0029';
  22825. t['\u2484'] = '\u0028\u0031\u0037\u0029';
  22826. t['\u2485'] = '\u0028\u0031\u0038\u0029';
  22827. t['\u2486'] = '\u0028\u0031\u0039\u0029';
  22828. t['\u2487'] = '\u0028\u0032\u0030\u0029';
  22829. t['\u2488'] = '\u0031\u002E';
  22830. t['\u2489'] = '\u0032\u002E';
  22831. t['\u248A'] = '\u0033\u002E';
  22832. t['\u248B'] = '\u0034\u002E';
  22833. t['\u248C'] = '\u0035\u002E';
  22834. t['\u248D'] = '\u0036\u002E';
  22835. t['\u248E'] = '\u0037\u002E';
  22836. t['\u248F'] = '\u0038\u002E';
  22837. t['\u2490'] = '\u0039\u002E';
  22838. t['\u2491'] = '\u0031\u0030\u002E';
  22839. t['\u2492'] = '\u0031\u0031\u002E';
  22840. t['\u2493'] = '\u0031\u0032\u002E';
  22841. t['\u2494'] = '\u0031\u0033\u002E';
  22842. t['\u2495'] = '\u0031\u0034\u002E';
  22843. t['\u2496'] = '\u0031\u0035\u002E';
  22844. t['\u2497'] = '\u0031\u0036\u002E';
  22845. t['\u2498'] = '\u0031\u0037\u002E';
  22846. t['\u2499'] = '\u0031\u0038\u002E';
  22847. t['\u249A'] = '\u0031\u0039\u002E';
  22848. t['\u249B'] = '\u0032\u0030\u002E';
  22849. t['\u249C'] = '\u0028\u0061\u0029';
  22850. t['\u249D'] = '\u0028\u0062\u0029';
  22851. t['\u249E'] = '\u0028\u0063\u0029';
  22852. t['\u249F'] = '\u0028\u0064\u0029';
  22853. t['\u24A0'] = '\u0028\u0065\u0029';
  22854. t['\u24A1'] = '\u0028\u0066\u0029';
  22855. t['\u24A2'] = '\u0028\u0067\u0029';
  22856. t['\u24A3'] = '\u0028\u0068\u0029';
  22857. t['\u24A4'] = '\u0028\u0069\u0029';
  22858. t['\u24A5'] = '\u0028\u006A\u0029';
  22859. t['\u24A6'] = '\u0028\u006B\u0029';
  22860. t['\u24A7'] = '\u0028\u006C\u0029';
  22861. t['\u24A8'] = '\u0028\u006D\u0029';
  22862. t['\u24A9'] = '\u0028\u006E\u0029';
  22863. t['\u24AA'] = '\u0028\u006F\u0029';
  22864. t['\u24AB'] = '\u0028\u0070\u0029';
  22865. t['\u24AC'] = '\u0028\u0071\u0029';
  22866. t['\u24AD'] = '\u0028\u0072\u0029';
  22867. t['\u24AE'] = '\u0028\u0073\u0029';
  22868. t['\u24AF'] = '\u0028\u0074\u0029';
  22869. t['\u24B0'] = '\u0028\u0075\u0029';
  22870. t['\u24B1'] = '\u0028\u0076\u0029';
  22871. t['\u24B2'] = '\u0028\u0077\u0029';
  22872. t['\u24B3'] = '\u0028\u0078\u0029';
  22873. t['\u24B4'] = '\u0028\u0079\u0029';
  22874. t['\u24B5'] = '\u0028\u007A\u0029';
  22875. t['\u2A0C'] = '\u222B\u222B\u222B\u222B';
  22876. t['\u2A74'] = '\u003A\u003A\u003D';
  22877. t['\u2A75'] = '\u003D\u003D';
  22878. t['\u2A76'] = '\u003D\u003D\u003D';
  22879. t['\u2E9F'] = '\u6BCD';
  22880. t['\u2EF3'] = '\u9F9F';
  22881. t['\u2F00'] = '\u4E00';
  22882. t['\u2F01'] = '\u4E28';
  22883. t['\u2F02'] = '\u4E36';
  22884. t['\u2F03'] = '\u4E3F';
  22885. t['\u2F04'] = '\u4E59';
  22886. t['\u2F05'] = '\u4E85';
  22887. t['\u2F06'] = '\u4E8C';
  22888. t['\u2F07'] = '\u4EA0';
  22889. t['\u2F08'] = '\u4EBA';
  22890. t['\u2F09'] = '\u513F';
  22891. t['\u2F0A'] = '\u5165';
  22892. t['\u2F0B'] = '\u516B';
  22893. t['\u2F0C'] = '\u5182';
  22894. t['\u2F0D'] = '\u5196';
  22895. t['\u2F0E'] = '\u51AB';
  22896. t['\u2F0F'] = '\u51E0';
  22897. t['\u2F10'] = '\u51F5';
  22898. t['\u2F11'] = '\u5200';
  22899. t['\u2F12'] = '\u529B';
  22900. t['\u2F13'] = '\u52F9';
  22901. t['\u2F14'] = '\u5315';
  22902. t['\u2F15'] = '\u531A';
  22903. t['\u2F16'] = '\u5338';
  22904. t['\u2F17'] = '\u5341';
  22905. t['\u2F18'] = '\u535C';
  22906. t['\u2F19'] = '\u5369';
  22907. t['\u2F1A'] = '\u5382';
  22908. t['\u2F1B'] = '\u53B6';
  22909. t['\u2F1C'] = '\u53C8';
  22910. t['\u2F1D'] = '\u53E3';
  22911. t['\u2F1E'] = '\u56D7';
  22912. t['\u2F1F'] = '\u571F';
  22913. t['\u2F20'] = '\u58EB';
  22914. t['\u2F21'] = '\u5902';
  22915. t['\u2F22'] = '\u590A';
  22916. t['\u2F23'] = '\u5915';
  22917. t['\u2F24'] = '\u5927';
  22918. t['\u2F25'] = '\u5973';
  22919. t['\u2F26'] = '\u5B50';
  22920. t['\u2F27'] = '\u5B80';
  22921. t['\u2F28'] = '\u5BF8';
  22922. t['\u2F29'] = '\u5C0F';
  22923. t['\u2F2A'] = '\u5C22';
  22924. t['\u2F2B'] = '\u5C38';
  22925. t['\u2F2C'] = '\u5C6E';
  22926. t['\u2F2D'] = '\u5C71';
  22927. t['\u2F2E'] = '\u5DDB';
  22928. t['\u2F2F'] = '\u5DE5';
  22929. t['\u2F30'] = '\u5DF1';
  22930. t['\u2F31'] = '\u5DFE';
  22931. t['\u2F32'] = '\u5E72';
  22932. t['\u2F33'] = '\u5E7A';
  22933. t['\u2F34'] = '\u5E7F';
  22934. t['\u2F35'] = '\u5EF4';
  22935. t['\u2F36'] = '\u5EFE';
  22936. t['\u2F37'] = '\u5F0B';
  22937. t['\u2F38'] = '\u5F13';
  22938. t['\u2F39'] = '\u5F50';
  22939. t['\u2F3A'] = '\u5F61';
  22940. t['\u2F3B'] = '\u5F73';
  22941. t['\u2F3C'] = '\u5FC3';
  22942. t['\u2F3D'] = '\u6208';
  22943. t['\u2F3E'] = '\u6236';
  22944. t['\u2F3F'] = '\u624B';
  22945. t['\u2F40'] = '\u652F';
  22946. t['\u2F41'] = '\u6534';
  22947. t['\u2F42'] = '\u6587';
  22948. t['\u2F43'] = '\u6597';
  22949. t['\u2F44'] = '\u65A4';
  22950. t['\u2F45'] = '\u65B9';
  22951. t['\u2F46'] = '\u65E0';
  22952. t['\u2F47'] = '\u65E5';
  22953. t['\u2F48'] = '\u66F0';
  22954. t['\u2F49'] = '\u6708';
  22955. t['\u2F4A'] = '\u6728';
  22956. t['\u2F4B'] = '\u6B20';
  22957. t['\u2F4C'] = '\u6B62';
  22958. t['\u2F4D'] = '\u6B79';
  22959. t['\u2F4E'] = '\u6BB3';
  22960. t['\u2F4F'] = '\u6BCB';
  22961. t['\u2F50'] = '\u6BD4';
  22962. t['\u2F51'] = '\u6BDB';
  22963. t['\u2F52'] = '\u6C0F';
  22964. t['\u2F53'] = '\u6C14';
  22965. t['\u2F54'] = '\u6C34';
  22966. t['\u2F55'] = '\u706B';
  22967. t['\u2F56'] = '\u722A';
  22968. t['\u2F57'] = '\u7236';
  22969. t['\u2F58'] = '\u723B';
  22970. t['\u2F59'] = '\u723F';
  22971. t['\u2F5A'] = '\u7247';
  22972. t['\u2F5B'] = '\u7259';
  22973. t['\u2F5C'] = '\u725B';
  22974. t['\u2F5D'] = '\u72AC';
  22975. t['\u2F5E'] = '\u7384';
  22976. t['\u2F5F'] = '\u7389';
  22977. t['\u2F60'] = '\u74DC';
  22978. t['\u2F61'] = '\u74E6';
  22979. t['\u2F62'] = '\u7518';
  22980. t['\u2F63'] = '\u751F';
  22981. t['\u2F64'] = '\u7528';
  22982. t['\u2F65'] = '\u7530';
  22983. t['\u2F66'] = '\u758B';
  22984. t['\u2F67'] = '\u7592';
  22985. t['\u2F68'] = '\u7676';
  22986. t['\u2F69'] = '\u767D';
  22987. t['\u2F6A'] = '\u76AE';
  22988. t['\u2F6B'] = '\u76BF';
  22989. t['\u2F6C'] = '\u76EE';
  22990. t['\u2F6D'] = '\u77DB';
  22991. t['\u2F6E'] = '\u77E2';
  22992. t['\u2F6F'] = '\u77F3';
  22993. t['\u2F70'] = '\u793A';
  22994. t['\u2F71'] = '\u79B8';
  22995. t['\u2F72'] = '\u79BE';
  22996. t['\u2F73'] = '\u7A74';
  22997. t['\u2F74'] = '\u7ACB';
  22998. t['\u2F75'] = '\u7AF9';
  22999. t['\u2F76'] = '\u7C73';
  23000. t['\u2F77'] = '\u7CF8';
  23001. t['\u2F78'] = '\u7F36';
  23002. t['\u2F79'] = '\u7F51';
  23003. t['\u2F7A'] = '\u7F8A';
  23004. t['\u2F7B'] = '\u7FBD';
  23005. t['\u2F7C'] = '\u8001';
  23006. t['\u2F7D'] = '\u800C';
  23007. t['\u2F7E'] = '\u8012';
  23008. t['\u2F7F'] = '\u8033';
  23009. t['\u2F80'] = '\u807F';
  23010. t['\u2F81'] = '\u8089';
  23011. t['\u2F82'] = '\u81E3';
  23012. t['\u2F83'] = '\u81EA';
  23013. t['\u2F84'] = '\u81F3';
  23014. t['\u2F85'] = '\u81FC';
  23015. t['\u2F86'] = '\u820C';
  23016. t['\u2F87'] = '\u821B';
  23017. t['\u2F88'] = '\u821F';
  23018. t['\u2F89'] = '\u826E';
  23019. t['\u2F8A'] = '\u8272';
  23020. t['\u2F8B'] = '\u8278';
  23021. t['\u2F8C'] = '\u864D';
  23022. t['\u2F8D'] = '\u866B';
  23023. t['\u2F8E'] = '\u8840';
  23024. t['\u2F8F'] = '\u884C';
  23025. t['\u2F90'] = '\u8863';
  23026. t['\u2F91'] = '\u897E';
  23027. t['\u2F92'] = '\u898B';
  23028. t['\u2F93'] = '\u89D2';
  23029. t['\u2F94'] = '\u8A00';
  23030. t['\u2F95'] = '\u8C37';
  23031. t['\u2F96'] = '\u8C46';
  23032. t['\u2F97'] = '\u8C55';
  23033. t['\u2F98'] = '\u8C78';
  23034. t['\u2F99'] = '\u8C9D';
  23035. t['\u2F9A'] = '\u8D64';
  23036. t['\u2F9B'] = '\u8D70';
  23037. t['\u2F9C'] = '\u8DB3';
  23038. t['\u2F9D'] = '\u8EAB';
  23039. t['\u2F9E'] = '\u8ECA';
  23040. t['\u2F9F'] = '\u8F9B';
  23041. t['\u2FA0'] = '\u8FB0';
  23042. t['\u2FA1'] = '\u8FB5';
  23043. t['\u2FA2'] = '\u9091';
  23044. t['\u2FA3'] = '\u9149';
  23045. t['\u2FA4'] = '\u91C6';
  23046. t['\u2FA5'] = '\u91CC';
  23047. t['\u2FA6'] = '\u91D1';
  23048. t['\u2FA7'] = '\u9577';
  23049. t['\u2FA8'] = '\u9580';
  23050. t['\u2FA9'] = '\u961C';
  23051. t['\u2FAA'] = '\u96B6';
  23052. t['\u2FAB'] = '\u96B9';
  23053. t['\u2FAC'] = '\u96E8';
  23054. t['\u2FAD'] = '\u9751';
  23055. t['\u2FAE'] = '\u975E';
  23056. t['\u2FAF'] = '\u9762';
  23057. t['\u2FB0'] = '\u9769';
  23058. t['\u2FB1'] = '\u97CB';
  23059. t['\u2FB2'] = '\u97ED';
  23060. t['\u2FB3'] = '\u97F3';
  23061. t['\u2FB4'] = '\u9801';
  23062. t['\u2FB5'] = '\u98A8';
  23063. t['\u2FB6'] = '\u98DB';
  23064. t['\u2FB7'] = '\u98DF';
  23065. t['\u2FB8'] = '\u9996';
  23066. t['\u2FB9'] = '\u9999';
  23067. t['\u2FBA'] = '\u99AC';
  23068. t['\u2FBB'] = '\u9AA8';
  23069. t['\u2FBC'] = '\u9AD8';
  23070. t['\u2FBD'] = '\u9ADF';
  23071. t['\u2FBE'] = '\u9B25';
  23072. t['\u2FBF'] = '\u9B2F';
  23073. t['\u2FC0'] = '\u9B32';
  23074. t['\u2FC1'] = '\u9B3C';
  23075. t['\u2FC2'] = '\u9B5A';
  23076. t['\u2FC3'] = '\u9CE5';
  23077. t['\u2FC4'] = '\u9E75';
  23078. t['\u2FC5'] = '\u9E7F';
  23079. t['\u2FC6'] = '\u9EA5';
  23080. t['\u2FC7'] = '\u9EBB';
  23081. t['\u2FC8'] = '\u9EC3';
  23082. t['\u2FC9'] = '\u9ECD';
  23083. t['\u2FCA'] = '\u9ED1';
  23084. t['\u2FCB'] = '\u9EF9';
  23085. t['\u2FCC'] = '\u9EFD';
  23086. t['\u2FCD'] = '\u9F0E';
  23087. t['\u2FCE'] = '\u9F13';
  23088. t['\u2FCF'] = '\u9F20';
  23089. t['\u2FD0'] = '\u9F3B';
  23090. t['\u2FD1'] = '\u9F4A';
  23091. t['\u2FD2'] = '\u9F52';
  23092. t['\u2FD3'] = '\u9F8D';
  23093. t['\u2FD4'] = '\u9F9C';
  23094. t['\u2FD5'] = '\u9FA0';
  23095. t['\u3036'] = '\u3012';
  23096. t['\u3038'] = '\u5341';
  23097. t['\u3039'] = '\u5344';
  23098. t['\u303A'] = '\u5345';
  23099. t['\u309B'] = '\u0020\u3099';
  23100. t['\u309C'] = '\u0020\u309A';
  23101. t['\u3131'] = '\u1100';
  23102. t['\u3132'] = '\u1101';
  23103. t['\u3133'] = '\u11AA';
  23104. t['\u3134'] = '\u1102';
  23105. t['\u3135'] = '\u11AC';
  23106. t['\u3136'] = '\u11AD';
  23107. t['\u3137'] = '\u1103';
  23108. t['\u3138'] = '\u1104';
  23109. t['\u3139'] = '\u1105';
  23110. t['\u313A'] = '\u11B0';
  23111. t['\u313B'] = '\u11B1';
  23112. t['\u313C'] = '\u11B2';
  23113. t['\u313D'] = '\u11B3';
  23114. t['\u313E'] = '\u11B4';
  23115. t['\u313F'] = '\u11B5';
  23116. t['\u3140'] = '\u111A';
  23117. t['\u3141'] = '\u1106';
  23118. t['\u3142'] = '\u1107';
  23119. t['\u3143'] = '\u1108';
  23120. t['\u3144'] = '\u1121';
  23121. t['\u3145'] = '\u1109';
  23122. t['\u3146'] = '\u110A';
  23123. t['\u3147'] = '\u110B';
  23124. t['\u3148'] = '\u110C';
  23125. t['\u3149'] = '\u110D';
  23126. t['\u314A'] = '\u110E';
  23127. t['\u314B'] = '\u110F';
  23128. t['\u314C'] = '\u1110';
  23129. t['\u314D'] = '\u1111';
  23130. t['\u314E'] = '\u1112';
  23131. t['\u314F'] = '\u1161';
  23132. t['\u3150'] = '\u1162';
  23133. t['\u3151'] = '\u1163';
  23134. t['\u3152'] = '\u1164';
  23135. t['\u3153'] = '\u1165';
  23136. t['\u3154'] = '\u1166';
  23137. t['\u3155'] = '\u1167';
  23138. t['\u3156'] = '\u1168';
  23139. t['\u3157'] = '\u1169';
  23140. t['\u3158'] = '\u116A';
  23141. t['\u3159'] = '\u116B';
  23142. t['\u315A'] = '\u116C';
  23143. t['\u315B'] = '\u116D';
  23144. t['\u315C'] = '\u116E';
  23145. t['\u315D'] = '\u116F';
  23146. t['\u315E'] = '\u1170';
  23147. t['\u315F'] = '\u1171';
  23148. t['\u3160'] = '\u1172';
  23149. t['\u3161'] = '\u1173';
  23150. t['\u3162'] = '\u1174';
  23151. t['\u3163'] = '\u1175';
  23152. t['\u3164'] = '\u1160';
  23153. t['\u3165'] = '\u1114';
  23154. t['\u3166'] = '\u1115';
  23155. t['\u3167'] = '\u11C7';
  23156. t['\u3168'] = '\u11C8';
  23157. t['\u3169'] = '\u11CC';
  23158. t['\u316A'] = '\u11CE';
  23159. t['\u316B'] = '\u11D3';
  23160. t['\u316C'] = '\u11D7';
  23161. t['\u316D'] = '\u11D9';
  23162. t['\u316E'] = '\u111C';
  23163. t['\u316F'] = '\u11DD';
  23164. t['\u3170'] = '\u11DF';
  23165. t['\u3171'] = '\u111D';
  23166. t['\u3172'] = '\u111E';
  23167. t['\u3173'] = '\u1120';
  23168. t['\u3174'] = '\u1122';
  23169. t['\u3175'] = '\u1123';
  23170. t['\u3176'] = '\u1127';
  23171. t['\u3177'] = '\u1129';
  23172. t['\u3178'] = '\u112B';
  23173. t['\u3179'] = '\u112C';
  23174. t['\u317A'] = '\u112D';
  23175. t['\u317B'] = '\u112E';
  23176. t['\u317C'] = '\u112F';
  23177. t['\u317D'] = '\u1132';
  23178. t['\u317E'] = '\u1136';
  23179. t['\u317F'] = '\u1140';
  23180. t['\u3180'] = '\u1147';
  23181. t['\u3181'] = '\u114C';
  23182. t['\u3182'] = '\u11F1';
  23183. t['\u3183'] = '\u11F2';
  23184. t['\u3184'] = '\u1157';
  23185. t['\u3185'] = '\u1158';
  23186. t['\u3186'] = '\u1159';
  23187. t['\u3187'] = '\u1184';
  23188. t['\u3188'] = '\u1185';
  23189. t['\u3189'] = '\u1188';
  23190. t['\u318A'] = '\u1191';
  23191. t['\u318B'] = '\u1192';
  23192. t['\u318C'] = '\u1194';
  23193. t['\u318D'] = '\u119E';
  23194. t['\u318E'] = '\u11A1';
  23195. t['\u3200'] = '\u0028\u1100\u0029';
  23196. t['\u3201'] = '\u0028\u1102\u0029';
  23197. t['\u3202'] = '\u0028\u1103\u0029';
  23198. t['\u3203'] = '\u0028\u1105\u0029';
  23199. t['\u3204'] = '\u0028\u1106\u0029';
  23200. t['\u3205'] = '\u0028\u1107\u0029';
  23201. t['\u3206'] = '\u0028\u1109\u0029';
  23202. t['\u3207'] = '\u0028\u110B\u0029';
  23203. t['\u3208'] = '\u0028\u110C\u0029';
  23204. t['\u3209'] = '\u0028\u110E\u0029';
  23205. t['\u320A'] = '\u0028\u110F\u0029';
  23206. t['\u320B'] = '\u0028\u1110\u0029';
  23207. t['\u320C'] = '\u0028\u1111\u0029';
  23208. t['\u320D'] = '\u0028\u1112\u0029';
  23209. t['\u320E'] = '\u0028\u1100\u1161\u0029';
  23210. t['\u320F'] = '\u0028\u1102\u1161\u0029';
  23211. t['\u3210'] = '\u0028\u1103\u1161\u0029';
  23212. t['\u3211'] = '\u0028\u1105\u1161\u0029';
  23213. t['\u3212'] = '\u0028\u1106\u1161\u0029';
  23214. t['\u3213'] = '\u0028\u1107\u1161\u0029';
  23215. t['\u3214'] = '\u0028\u1109\u1161\u0029';
  23216. t['\u3215'] = '\u0028\u110B\u1161\u0029';
  23217. t['\u3216'] = '\u0028\u110C\u1161\u0029';
  23218. t['\u3217'] = '\u0028\u110E\u1161\u0029';
  23219. t['\u3218'] = '\u0028\u110F\u1161\u0029';
  23220. t['\u3219'] = '\u0028\u1110\u1161\u0029';
  23221. t['\u321A'] = '\u0028\u1111\u1161\u0029';
  23222. t['\u321B'] = '\u0028\u1112\u1161\u0029';
  23223. t['\u321C'] = '\u0028\u110C\u116E\u0029';
  23224. t['\u321D'] = '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029';
  23225. t['\u321E'] = '\u0028\u110B\u1169\u1112\u116E\u0029';
  23226. t['\u3220'] = '\u0028\u4E00\u0029';
  23227. t['\u3221'] = '\u0028\u4E8C\u0029';
  23228. t['\u3222'] = '\u0028\u4E09\u0029';
  23229. t['\u3223'] = '\u0028\u56DB\u0029';
  23230. t['\u3224'] = '\u0028\u4E94\u0029';
  23231. t['\u3225'] = '\u0028\u516D\u0029';
  23232. t['\u3226'] = '\u0028\u4E03\u0029';
  23233. t['\u3227'] = '\u0028\u516B\u0029';
  23234. t['\u3228'] = '\u0028\u4E5D\u0029';
  23235. t['\u3229'] = '\u0028\u5341\u0029';
  23236. t['\u322A'] = '\u0028\u6708\u0029';
  23237. t['\u322B'] = '\u0028\u706B\u0029';
  23238. t['\u322C'] = '\u0028\u6C34\u0029';
  23239. t['\u322D'] = '\u0028\u6728\u0029';
  23240. t['\u322E'] = '\u0028\u91D1\u0029';
  23241. t['\u322F'] = '\u0028\u571F\u0029';
  23242. t['\u3230'] = '\u0028\u65E5\u0029';
  23243. t['\u3231'] = '\u0028\u682A\u0029';
  23244. t['\u3232'] = '\u0028\u6709\u0029';
  23245. t['\u3233'] = '\u0028\u793E\u0029';
  23246. t['\u3234'] = '\u0028\u540D\u0029';
  23247. t['\u3235'] = '\u0028\u7279\u0029';
  23248. t['\u3236'] = '\u0028\u8CA1\u0029';
  23249. t['\u3237'] = '\u0028\u795D\u0029';
  23250. t['\u3238'] = '\u0028\u52B4\u0029';
  23251. t['\u3239'] = '\u0028\u4EE3\u0029';
  23252. t['\u323A'] = '\u0028\u547C\u0029';
  23253. t['\u323B'] = '\u0028\u5B66\u0029';
  23254. t['\u323C'] = '\u0028\u76E3\u0029';
  23255. t['\u323D'] = '\u0028\u4F01\u0029';
  23256. t['\u323E'] = '\u0028\u8CC7\u0029';
  23257. t['\u323F'] = '\u0028\u5354\u0029';
  23258. t['\u3240'] = '\u0028\u796D\u0029';
  23259. t['\u3241'] = '\u0028\u4F11\u0029';
  23260. t['\u3242'] = '\u0028\u81EA\u0029';
  23261. t['\u3243'] = '\u0028\u81F3\u0029';
  23262. t['\u32C0'] = '\u0031\u6708';
  23263. t['\u32C1'] = '\u0032\u6708';
  23264. t['\u32C2'] = '\u0033\u6708';
  23265. t['\u32C3'] = '\u0034\u6708';
  23266. t['\u32C4'] = '\u0035\u6708';
  23267. t['\u32C5'] = '\u0036\u6708';
  23268. t['\u32C6'] = '\u0037\u6708';
  23269. t['\u32C7'] = '\u0038\u6708';
  23270. t['\u32C8'] = '\u0039\u6708';
  23271. t['\u32C9'] = '\u0031\u0030\u6708';
  23272. t['\u32CA'] = '\u0031\u0031\u6708';
  23273. t['\u32CB'] = '\u0031\u0032\u6708';
  23274. t['\u3358'] = '\u0030\u70B9';
  23275. t['\u3359'] = '\u0031\u70B9';
  23276. t['\u335A'] = '\u0032\u70B9';
  23277. t['\u335B'] = '\u0033\u70B9';
  23278. t['\u335C'] = '\u0034\u70B9';
  23279. t['\u335D'] = '\u0035\u70B9';
  23280. t['\u335E'] = '\u0036\u70B9';
  23281. t['\u335F'] = '\u0037\u70B9';
  23282. t['\u3360'] = '\u0038\u70B9';
  23283. t['\u3361'] = '\u0039\u70B9';
  23284. t['\u3362'] = '\u0031\u0030\u70B9';
  23285. t['\u3363'] = '\u0031\u0031\u70B9';
  23286. t['\u3364'] = '\u0031\u0032\u70B9';
  23287. t['\u3365'] = '\u0031\u0033\u70B9';
  23288. t['\u3366'] = '\u0031\u0034\u70B9';
  23289. t['\u3367'] = '\u0031\u0035\u70B9';
  23290. t['\u3368'] = '\u0031\u0036\u70B9';
  23291. t['\u3369'] = '\u0031\u0037\u70B9';
  23292. t['\u336A'] = '\u0031\u0038\u70B9';
  23293. t['\u336B'] = '\u0031\u0039\u70B9';
  23294. t['\u336C'] = '\u0032\u0030\u70B9';
  23295. t['\u336D'] = '\u0032\u0031\u70B9';
  23296. t['\u336E'] = '\u0032\u0032\u70B9';
  23297. t['\u336F'] = '\u0032\u0033\u70B9';
  23298. t['\u3370'] = '\u0032\u0034\u70B9';
  23299. t['\u33E0'] = '\u0031\u65E5';
  23300. t['\u33E1'] = '\u0032\u65E5';
  23301. t['\u33E2'] = '\u0033\u65E5';
  23302. t['\u33E3'] = '\u0034\u65E5';
  23303. t['\u33E4'] = '\u0035\u65E5';
  23304. t['\u33E5'] = '\u0036\u65E5';
  23305. t['\u33E6'] = '\u0037\u65E5';
  23306. t['\u33E7'] = '\u0038\u65E5';
  23307. t['\u33E8'] = '\u0039\u65E5';
  23308. t['\u33E9'] = '\u0031\u0030\u65E5';
  23309. t['\u33EA'] = '\u0031\u0031\u65E5';
  23310. t['\u33EB'] = '\u0031\u0032\u65E5';
  23311. t['\u33EC'] = '\u0031\u0033\u65E5';
  23312. t['\u33ED'] = '\u0031\u0034\u65E5';
  23313. t['\u33EE'] = '\u0031\u0035\u65E5';
  23314. t['\u33EF'] = '\u0031\u0036\u65E5';
  23315. t['\u33F0'] = '\u0031\u0037\u65E5';
  23316. t['\u33F1'] = '\u0031\u0038\u65E5';
  23317. t['\u33F2'] = '\u0031\u0039\u65E5';
  23318. t['\u33F3'] = '\u0032\u0030\u65E5';
  23319. t['\u33F4'] = '\u0032\u0031\u65E5';
  23320. t['\u33F5'] = '\u0032\u0032\u65E5';
  23321. t['\u33F6'] = '\u0032\u0033\u65E5';
  23322. t['\u33F7'] = '\u0032\u0034\u65E5';
  23323. t['\u33F8'] = '\u0032\u0035\u65E5';
  23324. t['\u33F9'] = '\u0032\u0036\u65E5';
  23325. t['\u33FA'] = '\u0032\u0037\u65E5';
  23326. t['\u33FB'] = '\u0032\u0038\u65E5';
  23327. t['\u33FC'] = '\u0032\u0039\u65E5';
  23328. t['\u33FD'] = '\u0033\u0030\u65E5';
  23329. t['\u33FE'] = '\u0033\u0031\u65E5';
  23330. t['\uFB00'] = '\u0066\u0066';
  23331. t['\uFB01'] = '\u0066\u0069';
  23332. t['\uFB02'] = '\u0066\u006C';
  23333. t['\uFB03'] = '\u0066\u0066\u0069';
  23334. t['\uFB04'] = '\u0066\u0066\u006C';
  23335. t['\uFB05'] = '\u017F\u0074';
  23336. t['\uFB06'] = '\u0073\u0074';
  23337. t['\uFB13'] = '\u0574\u0576';
  23338. t['\uFB14'] = '\u0574\u0565';
  23339. t['\uFB15'] = '\u0574\u056B';
  23340. t['\uFB16'] = '\u057E\u0576';
  23341. t['\uFB17'] = '\u0574\u056D';
  23342. t['\uFB4F'] = '\u05D0\u05DC';
  23343. t['\uFB50'] = '\u0671';
  23344. t['\uFB51'] = '\u0671';
  23345. t['\uFB52'] = '\u067B';
  23346. t['\uFB53'] = '\u067B';
  23347. t['\uFB54'] = '\u067B';
  23348. t['\uFB55'] = '\u067B';
  23349. t['\uFB56'] = '\u067E';
  23350. t['\uFB57'] = '\u067E';
  23351. t['\uFB58'] = '\u067E';
  23352. t['\uFB59'] = '\u067E';
  23353. t['\uFB5A'] = '\u0680';
  23354. t['\uFB5B'] = '\u0680';
  23355. t['\uFB5C'] = '\u0680';
  23356. t['\uFB5D'] = '\u0680';
  23357. t['\uFB5E'] = '\u067A';
  23358. t['\uFB5F'] = '\u067A';
  23359. t['\uFB60'] = '\u067A';
  23360. t['\uFB61'] = '\u067A';
  23361. t['\uFB62'] = '\u067F';
  23362. t['\uFB63'] = '\u067F';
  23363. t['\uFB64'] = '\u067F';
  23364. t['\uFB65'] = '\u067F';
  23365. t['\uFB66'] = '\u0679';
  23366. t['\uFB67'] = '\u0679';
  23367. t['\uFB68'] = '\u0679';
  23368. t['\uFB69'] = '\u0679';
  23369. t['\uFB6A'] = '\u06A4';
  23370. t['\uFB6B'] = '\u06A4';
  23371. t['\uFB6C'] = '\u06A4';
  23372. t['\uFB6D'] = '\u06A4';
  23373. t['\uFB6E'] = '\u06A6';
  23374. t['\uFB6F'] = '\u06A6';
  23375. t['\uFB70'] = '\u06A6';
  23376. t['\uFB71'] = '\u06A6';
  23377. t['\uFB72'] = '\u0684';
  23378. t['\uFB73'] = '\u0684';
  23379. t['\uFB74'] = '\u0684';
  23380. t['\uFB75'] = '\u0684';
  23381. t['\uFB76'] = '\u0683';
  23382. t['\uFB77'] = '\u0683';
  23383. t['\uFB78'] = '\u0683';
  23384. t['\uFB79'] = '\u0683';
  23385. t['\uFB7A'] = '\u0686';
  23386. t['\uFB7B'] = '\u0686';
  23387. t['\uFB7C'] = '\u0686';
  23388. t['\uFB7D'] = '\u0686';
  23389. t['\uFB7E'] = '\u0687';
  23390. t['\uFB7F'] = '\u0687';
  23391. t['\uFB80'] = '\u0687';
  23392. t['\uFB81'] = '\u0687';
  23393. t['\uFB82'] = '\u068D';
  23394. t['\uFB83'] = '\u068D';
  23395. t['\uFB84'] = '\u068C';
  23396. t['\uFB85'] = '\u068C';
  23397. t['\uFB86'] = '\u068E';
  23398. t['\uFB87'] = '\u068E';
  23399. t['\uFB88'] = '\u0688';
  23400. t['\uFB89'] = '\u0688';
  23401. t['\uFB8A'] = '\u0698';
  23402. t['\uFB8B'] = '\u0698';
  23403. t['\uFB8C'] = '\u0691';
  23404. t['\uFB8D'] = '\u0691';
  23405. t['\uFB8E'] = '\u06A9';
  23406. t['\uFB8F'] = '\u06A9';
  23407. t['\uFB90'] = '\u06A9';
  23408. t['\uFB91'] = '\u06A9';
  23409. t['\uFB92'] = '\u06AF';
  23410. t['\uFB93'] = '\u06AF';
  23411. t['\uFB94'] = '\u06AF';
  23412. t['\uFB95'] = '\u06AF';
  23413. t['\uFB96'] = '\u06B3';
  23414. t['\uFB97'] = '\u06B3';
  23415. t['\uFB98'] = '\u06B3';
  23416. t['\uFB99'] = '\u06B3';
  23417. t['\uFB9A'] = '\u06B1';
  23418. t['\uFB9B'] = '\u06B1';
  23419. t['\uFB9C'] = '\u06B1';
  23420. t['\uFB9D'] = '\u06B1';
  23421. t['\uFB9E'] = '\u06BA';
  23422. t['\uFB9F'] = '\u06BA';
  23423. t['\uFBA0'] = '\u06BB';
  23424. t['\uFBA1'] = '\u06BB';
  23425. t['\uFBA2'] = '\u06BB';
  23426. t['\uFBA3'] = '\u06BB';
  23427. t['\uFBA4'] = '\u06C0';
  23428. t['\uFBA5'] = '\u06C0';
  23429. t['\uFBA6'] = '\u06C1';
  23430. t['\uFBA7'] = '\u06C1';
  23431. t['\uFBA8'] = '\u06C1';
  23432. t['\uFBA9'] = '\u06C1';
  23433. t['\uFBAA'] = '\u06BE';
  23434. t['\uFBAB'] = '\u06BE';
  23435. t['\uFBAC'] = '\u06BE';
  23436. t['\uFBAD'] = '\u06BE';
  23437. t['\uFBAE'] = '\u06D2';
  23438. t['\uFBAF'] = '\u06D2';
  23439. t['\uFBB0'] = '\u06D3';
  23440. t['\uFBB1'] = '\u06D3';
  23441. t['\uFBD3'] = '\u06AD';
  23442. t['\uFBD4'] = '\u06AD';
  23443. t['\uFBD5'] = '\u06AD';
  23444. t['\uFBD6'] = '\u06AD';
  23445. t['\uFBD7'] = '\u06C7';
  23446. t['\uFBD8'] = '\u06C7';
  23447. t['\uFBD9'] = '\u06C6';
  23448. t['\uFBDA'] = '\u06C6';
  23449. t['\uFBDB'] = '\u06C8';
  23450. t['\uFBDC'] = '\u06C8';
  23451. t['\uFBDD'] = '\u0677';
  23452. t['\uFBDE'] = '\u06CB';
  23453. t['\uFBDF'] = '\u06CB';
  23454. t['\uFBE0'] = '\u06C5';
  23455. t['\uFBE1'] = '\u06C5';
  23456. t['\uFBE2'] = '\u06C9';
  23457. t['\uFBE3'] = '\u06C9';
  23458. t['\uFBE4'] = '\u06D0';
  23459. t['\uFBE5'] = '\u06D0';
  23460. t['\uFBE6'] = '\u06D0';
  23461. t['\uFBE7'] = '\u06D0';
  23462. t['\uFBE8'] = '\u0649';
  23463. t['\uFBE9'] = '\u0649';
  23464. t['\uFBEA'] = '\u0626\u0627';
  23465. t['\uFBEB'] = '\u0626\u0627';
  23466. t['\uFBEC'] = '\u0626\u06D5';
  23467. t['\uFBED'] = '\u0626\u06D5';
  23468. t['\uFBEE'] = '\u0626\u0648';
  23469. t['\uFBEF'] = '\u0626\u0648';
  23470. t['\uFBF0'] = '\u0626\u06C7';
  23471. t['\uFBF1'] = '\u0626\u06C7';
  23472. t['\uFBF2'] = '\u0626\u06C6';
  23473. t['\uFBF3'] = '\u0626\u06C6';
  23474. t['\uFBF4'] = '\u0626\u06C8';
  23475. t['\uFBF5'] = '\u0626\u06C8';
  23476. t['\uFBF6'] = '\u0626\u06D0';
  23477. t['\uFBF7'] = '\u0626\u06D0';
  23478. t['\uFBF8'] = '\u0626\u06D0';
  23479. t['\uFBF9'] = '\u0626\u0649';
  23480. t['\uFBFA'] = '\u0626\u0649';
  23481. t['\uFBFB'] = '\u0626\u0649';
  23482. t['\uFBFC'] = '\u06CC';
  23483. t['\uFBFD'] = '\u06CC';
  23484. t['\uFBFE'] = '\u06CC';
  23485. t['\uFBFF'] = '\u06CC';
  23486. t['\uFC00'] = '\u0626\u062C';
  23487. t['\uFC01'] = '\u0626\u062D';
  23488. t['\uFC02'] = '\u0626\u0645';
  23489. t['\uFC03'] = '\u0626\u0649';
  23490. t['\uFC04'] = '\u0626\u064A';
  23491. t['\uFC05'] = '\u0628\u062C';
  23492. t['\uFC06'] = '\u0628\u062D';
  23493. t['\uFC07'] = '\u0628\u062E';
  23494. t['\uFC08'] = '\u0628\u0645';
  23495. t['\uFC09'] = '\u0628\u0649';
  23496. t['\uFC0A'] = '\u0628\u064A';
  23497. t['\uFC0B'] = '\u062A\u062C';
  23498. t['\uFC0C'] = '\u062A\u062D';
  23499. t['\uFC0D'] = '\u062A\u062E';
  23500. t['\uFC0E'] = '\u062A\u0645';
  23501. t['\uFC0F'] = '\u062A\u0649';
  23502. t['\uFC10'] = '\u062A\u064A';
  23503. t['\uFC11'] = '\u062B\u062C';
  23504. t['\uFC12'] = '\u062B\u0645';
  23505. t['\uFC13'] = '\u062B\u0649';
  23506. t['\uFC14'] = '\u062B\u064A';
  23507. t['\uFC15'] = '\u062C\u062D';
  23508. t['\uFC16'] = '\u062C\u0645';
  23509. t['\uFC17'] = '\u062D\u062C';
  23510. t['\uFC18'] = '\u062D\u0645';
  23511. t['\uFC19'] = '\u062E\u062C';
  23512. t['\uFC1A'] = '\u062E\u062D';
  23513. t['\uFC1B'] = '\u062E\u0645';
  23514. t['\uFC1C'] = '\u0633\u062C';
  23515. t['\uFC1D'] = '\u0633\u062D';
  23516. t['\uFC1E'] = '\u0633\u062E';
  23517. t['\uFC1F'] = '\u0633\u0645';
  23518. t['\uFC20'] = '\u0635\u062D';
  23519. t['\uFC21'] = '\u0635\u0645';
  23520. t['\uFC22'] = '\u0636\u062C';
  23521. t['\uFC23'] = '\u0636\u062D';
  23522. t['\uFC24'] = '\u0636\u062E';
  23523. t['\uFC25'] = '\u0636\u0645';
  23524. t['\uFC26'] = '\u0637\u062D';
  23525. t['\uFC27'] = '\u0637\u0645';
  23526. t['\uFC28'] = '\u0638\u0645';
  23527. t['\uFC29'] = '\u0639\u062C';
  23528. t['\uFC2A'] = '\u0639\u0645';
  23529. t['\uFC2B'] = '\u063A\u062C';
  23530. t['\uFC2C'] = '\u063A\u0645';
  23531. t['\uFC2D'] = '\u0641\u062C';
  23532. t['\uFC2E'] = '\u0641\u062D';
  23533. t['\uFC2F'] = '\u0641\u062E';
  23534. t['\uFC30'] = '\u0641\u0645';
  23535. t['\uFC31'] = '\u0641\u0649';
  23536. t['\uFC32'] = '\u0641\u064A';
  23537. t['\uFC33'] = '\u0642\u062D';
  23538. t['\uFC34'] = '\u0642\u0645';
  23539. t['\uFC35'] = '\u0642\u0649';
  23540. t['\uFC36'] = '\u0642\u064A';
  23541. t['\uFC37'] = '\u0643\u0627';
  23542. t['\uFC38'] = '\u0643\u062C';
  23543. t['\uFC39'] = '\u0643\u062D';
  23544. t['\uFC3A'] = '\u0643\u062E';
  23545. t['\uFC3B'] = '\u0643\u0644';
  23546. t['\uFC3C'] = '\u0643\u0645';
  23547. t['\uFC3D'] = '\u0643\u0649';
  23548. t['\uFC3E'] = '\u0643\u064A';
  23549. t['\uFC3F'] = '\u0644\u062C';
  23550. t['\uFC40'] = '\u0644\u062D';
  23551. t['\uFC41'] = '\u0644\u062E';
  23552. t['\uFC42'] = '\u0644\u0645';
  23553. t['\uFC43'] = '\u0644\u0649';
  23554. t['\uFC44'] = '\u0644\u064A';
  23555. t['\uFC45'] = '\u0645\u062C';
  23556. t['\uFC46'] = '\u0645\u062D';
  23557. t['\uFC47'] = '\u0645\u062E';
  23558. t['\uFC48'] = '\u0645\u0645';
  23559. t['\uFC49'] = '\u0645\u0649';
  23560. t['\uFC4A'] = '\u0645\u064A';
  23561. t['\uFC4B'] = '\u0646\u062C';
  23562. t['\uFC4C'] = '\u0646\u062D';
  23563. t['\uFC4D'] = '\u0646\u062E';
  23564. t['\uFC4E'] = '\u0646\u0645';
  23565. t['\uFC4F'] = '\u0646\u0649';
  23566. t['\uFC50'] = '\u0646\u064A';
  23567. t['\uFC51'] = '\u0647\u062C';
  23568. t['\uFC52'] = '\u0647\u0645';
  23569. t['\uFC53'] = '\u0647\u0649';
  23570. t['\uFC54'] = '\u0647\u064A';
  23571. t['\uFC55'] = '\u064A\u062C';
  23572. t['\uFC56'] = '\u064A\u062D';
  23573. t['\uFC57'] = '\u064A\u062E';
  23574. t['\uFC58'] = '\u064A\u0645';
  23575. t['\uFC59'] = '\u064A\u0649';
  23576. t['\uFC5A'] = '\u064A\u064A';
  23577. t['\uFC5B'] = '\u0630\u0670';
  23578. t['\uFC5C'] = '\u0631\u0670';
  23579. t['\uFC5D'] = '\u0649\u0670';
  23580. t['\uFC5E'] = '\u0020\u064C\u0651';
  23581. t['\uFC5F'] = '\u0020\u064D\u0651';
  23582. t['\uFC60'] = '\u0020\u064E\u0651';
  23583. t['\uFC61'] = '\u0020\u064F\u0651';
  23584. t['\uFC62'] = '\u0020\u0650\u0651';
  23585. t['\uFC63'] = '\u0020\u0651\u0670';
  23586. t['\uFC64'] = '\u0626\u0631';
  23587. t['\uFC65'] = '\u0626\u0632';
  23588. t['\uFC66'] = '\u0626\u0645';
  23589. t['\uFC67'] = '\u0626\u0646';
  23590. t['\uFC68'] = '\u0626\u0649';
  23591. t['\uFC69'] = '\u0626\u064A';
  23592. t['\uFC6A'] = '\u0628\u0631';
  23593. t['\uFC6B'] = '\u0628\u0632';
  23594. t['\uFC6C'] = '\u0628\u0645';
  23595. t['\uFC6D'] = '\u0628\u0646';
  23596. t['\uFC6E'] = '\u0628\u0649';
  23597. t['\uFC6F'] = '\u0628\u064A';
  23598. t['\uFC70'] = '\u062A\u0631';
  23599. t['\uFC71'] = '\u062A\u0632';
  23600. t['\uFC72'] = '\u062A\u0645';
  23601. t['\uFC73'] = '\u062A\u0646';
  23602. t['\uFC74'] = '\u062A\u0649';
  23603. t['\uFC75'] = '\u062A\u064A';
  23604. t['\uFC76'] = '\u062B\u0631';
  23605. t['\uFC77'] = '\u062B\u0632';
  23606. t['\uFC78'] = '\u062B\u0645';
  23607. t['\uFC79'] = '\u062B\u0646';
  23608. t['\uFC7A'] = '\u062B\u0649';
  23609. t['\uFC7B'] = '\u062B\u064A';
  23610. t['\uFC7C'] = '\u0641\u0649';
  23611. t['\uFC7D'] = '\u0641\u064A';
  23612. t['\uFC7E'] = '\u0642\u0649';
  23613. t['\uFC7F'] = '\u0642\u064A';
  23614. t['\uFC80'] = '\u0643\u0627';
  23615. t['\uFC81'] = '\u0643\u0644';
  23616. t['\uFC82'] = '\u0643\u0645';
  23617. t['\uFC83'] = '\u0643\u0649';
  23618. t['\uFC84'] = '\u0643\u064A';
  23619. t['\uFC85'] = '\u0644\u0645';
  23620. t['\uFC86'] = '\u0644\u0649';
  23621. t['\uFC87'] = '\u0644\u064A';
  23622. t['\uFC88'] = '\u0645\u0627';
  23623. t['\uFC89'] = '\u0645\u0645';
  23624. t['\uFC8A'] = '\u0646\u0631';
  23625. t['\uFC8B'] = '\u0646\u0632';
  23626. t['\uFC8C'] = '\u0646\u0645';
  23627. t['\uFC8D'] = '\u0646\u0646';
  23628. t['\uFC8E'] = '\u0646\u0649';
  23629. t['\uFC8F'] = '\u0646\u064A';
  23630. t['\uFC90'] = '\u0649\u0670';
  23631. t['\uFC91'] = '\u064A\u0631';
  23632. t['\uFC92'] = '\u064A\u0632';
  23633. t['\uFC93'] = '\u064A\u0645';
  23634. t['\uFC94'] = '\u064A\u0646';
  23635. t['\uFC95'] = '\u064A\u0649';
  23636. t['\uFC96'] = '\u064A\u064A';
  23637. t['\uFC97'] = '\u0626\u062C';
  23638. t['\uFC98'] = '\u0626\u062D';
  23639. t['\uFC99'] = '\u0626\u062E';
  23640. t['\uFC9A'] = '\u0626\u0645';
  23641. t['\uFC9B'] = '\u0626\u0647';
  23642. t['\uFC9C'] = '\u0628\u062C';
  23643. t['\uFC9D'] = '\u0628\u062D';
  23644. t['\uFC9E'] = '\u0628\u062E';
  23645. t['\uFC9F'] = '\u0628\u0645';
  23646. t['\uFCA0'] = '\u0628\u0647';
  23647. t['\uFCA1'] = '\u062A\u062C';
  23648. t['\uFCA2'] = '\u062A\u062D';
  23649. t['\uFCA3'] = '\u062A\u062E';
  23650. t['\uFCA4'] = '\u062A\u0645';
  23651. t['\uFCA5'] = '\u062A\u0647';
  23652. t['\uFCA6'] = '\u062B\u0645';
  23653. t['\uFCA7'] = '\u062C\u062D';
  23654. t['\uFCA8'] = '\u062C\u0645';
  23655. t['\uFCA9'] = '\u062D\u062C';
  23656. t['\uFCAA'] = '\u062D\u0645';
  23657. t['\uFCAB'] = '\u062E\u062C';
  23658. t['\uFCAC'] = '\u062E\u0645';
  23659. t['\uFCAD'] = '\u0633\u062C';
  23660. t['\uFCAE'] = '\u0633\u062D';
  23661. t['\uFCAF'] = '\u0633\u062E';
  23662. t['\uFCB0'] = '\u0633\u0645';
  23663. t['\uFCB1'] = '\u0635\u062D';
  23664. t['\uFCB2'] = '\u0635\u062E';
  23665. t['\uFCB3'] = '\u0635\u0645';
  23666. t['\uFCB4'] = '\u0636\u062C';
  23667. t['\uFCB5'] = '\u0636\u062D';
  23668. t['\uFCB6'] = '\u0636\u062E';
  23669. t['\uFCB7'] = '\u0636\u0645';
  23670. t['\uFCB8'] = '\u0637\u062D';
  23671. t['\uFCB9'] = '\u0638\u0645';
  23672. t['\uFCBA'] = '\u0639\u062C';
  23673. t['\uFCBB'] = '\u0639\u0645';
  23674. t['\uFCBC'] = '\u063A\u062C';
  23675. t['\uFCBD'] = '\u063A\u0645';
  23676. t['\uFCBE'] = '\u0641\u062C';
  23677. t['\uFCBF'] = '\u0641\u062D';
  23678. t['\uFCC0'] = '\u0641\u062E';
  23679. t['\uFCC1'] = '\u0641\u0645';
  23680. t['\uFCC2'] = '\u0642\u062D';
  23681. t['\uFCC3'] = '\u0642\u0645';
  23682. t['\uFCC4'] = '\u0643\u062C';
  23683. t['\uFCC5'] = '\u0643\u062D';
  23684. t['\uFCC6'] = '\u0643\u062E';
  23685. t['\uFCC7'] = '\u0643\u0644';
  23686. t['\uFCC8'] = '\u0643\u0645';
  23687. t['\uFCC9'] = '\u0644\u062C';
  23688. t['\uFCCA'] = '\u0644\u062D';
  23689. t['\uFCCB'] = '\u0644\u062E';
  23690. t['\uFCCC'] = '\u0644\u0645';
  23691. t['\uFCCD'] = '\u0644\u0647';
  23692. t['\uFCCE'] = '\u0645\u062C';
  23693. t['\uFCCF'] = '\u0645\u062D';
  23694. t['\uFCD0'] = '\u0645\u062E';
  23695. t['\uFCD1'] = '\u0645\u0645';
  23696. t['\uFCD2'] = '\u0646\u062C';
  23697. t['\uFCD3'] = '\u0646\u062D';
  23698. t['\uFCD4'] = '\u0646\u062E';
  23699. t['\uFCD5'] = '\u0646\u0645';
  23700. t['\uFCD6'] = '\u0646\u0647';
  23701. t['\uFCD7'] = '\u0647\u062C';
  23702. t['\uFCD8'] = '\u0647\u0645';
  23703. t['\uFCD9'] = '\u0647\u0670';
  23704. t['\uFCDA'] = '\u064A\u062C';
  23705. t['\uFCDB'] = '\u064A\u062D';
  23706. t['\uFCDC'] = '\u064A\u062E';
  23707. t['\uFCDD'] = '\u064A\u0645';
  23708. t['\uFCDE'] = '\u064A\u0647';
  23709. t['\uFCDF'] = '\u0626\u0645';
  23710. t['\uFCE0'] = '\u0626\u0647';
  23711. t['\uFCE1'] = '\u0628\u0645';
  23712. t['\uFCE2'] = '\u0628\u0647';
  23713. t['\uFCE3'] = '\u062A\u0645';
  23714. t['\uFCE4'] = '\u062A\u0647';
  23715. t['\uFCE5'] = '\u062B\u0645';
  23716. t['\uFCE6'] = '\u062B\u0647';
  23717. t['\uFCE7'] = '\u0633\u0645';
  23718. t['\uFCE8'] = '\u0633\u0647';
  23719. t['\uFCE9'] = '\u0634\u0645';
  23720. t['\uFCEA'] = '\u0634\u0647';
  23721. t['\uFCEB'] = '\u0643\u0644';
  23722. t['\uFCEC'] = '\u0643\u0645';
  23723. t['\uFCED'] = '\u0644\u0645';
  23724. t['\uFCEE'] = '\u0646\u0645';
  23725. t['\uFCEF'] = '\u0646\u0647';
  23726. t['\uFCF0'] = '\u064A\u0645';
  23727. t['\uFCF1'] = '\u064A\u0647';
  23728. t['\uFCF2'] = '\u0640\u064E\u0651';
  23729. t['\uFCF3'] = '\u0640\u064F\u0651';
  23730. t['\uFCF4'] = '\u0640\u0650\u0651';
  23731. t['\uFCF5'] = '\u0637\u0649';
  23732. t['\uFCF6'] = '\u0637\u064A';
  23733. t['\uFCF7'] = '\u0639\u0649';
  23734. t['\uFCF8'] = '\u0639\u064A';
  23735. t['\uFCF9'] = '\u063A\u0649';
  23736. t['\uFCFA'] = '\u063A\u064A';
  23737. t['\uFCFB'] = '\u0633\u0649';
  23738. t['\uFCFC'] = '\u0633\u064A';
  23739. t['\uFCFD'] = '\u0634\u0649';
  23740. t['\uFCFE'] = '\u0634\u064A';
  23741. t['\uFCFF'] = '\u062D\u0649';
  23742. t['\uFD00'] = '\u062D\u064A';
  23743. t['\uFD01'] = '\u062C\u0649';
  23744. t['\uFD02'] = '\u062C\u064A';
  23745. t['\uFD03'] = '\u062E\u0649';
  23746. t['\uFD04'] = '\u062E\u064A';
  23747. t['\uFD05'] = '\u0635\u0649';
  23748. t['\uFD06'] = '\u0635\u064A';
  23749. t['\uFD07'] = '\u0636\u0649';
  23750. t['\uFD08'] = '\u0636\u064A';
  23751. t['\uFD09'] = '\u0634\u062C';
  23752. t['\uFD0A'] = '\u0634\u062D';
  23753. t['\uFD0B'] = '\u0634\u062E';
  23754. t['\uFD0C'] = '\u0634\u0645';
  23755. t['\uFD0D'] = '\u0634\u0631';
  23756. t['\uFD0E'] = '\u0633\u0631';
  23757. t['\uFD0F'] = '\u0635\u0631';
  23758. t['\uFD10'] = '\u0636\u0631';
  23759. t['\uFD11'] = '\u0637\u0649';
  23760. t['\uFD12'] = '\u0637\u064A';
  23761. t['\uFD13'] = '\u0639\u0649';
  23762. t['\uFD14'] = '\u0639\u064A';
  23763. t['\uFD15'] = '\u063A\u0649';
  23764. t['\uFD16'] = '\u063A\u064A';
  23765. t['\uFD17'] = '\u0633\u0649';
  23766. t['\uFD18'] = '\u0633\u064A';
  23767. t['\uFD19'] = '\u0634\u0649';
  23768. t['\uFD1A'] = '\u0634\u064A';
  23769. t['\uFD1B'] = '\u062D\u0649';
  23770. t['\uFD1C'] = '\u062D\u064A';
  23771. t['\uFD1D'] = '\u062C\u0649';
  23772. t['\uFD1E'] = '\u062C\u064A';
  23773. t['\uFD1F'] = '\u062E\u0649';
  23774. t['\uFD20'] = '\u062E\u064A';
  23775. t['\uFD21'] = '\u0635\u0649';
  23776. t['\uFD22'] = '\u0635\u064A';
  23777. t['\uFD23'] = '\u0636\u0649';
  23778. t['\uFD24'] = '\u0636\u064A';
  23779. t['\uFD25'] = '\u0634\u062C';
  23780. t['\uFD26'] = '\u0634\u062D';
  23781. t['\uFD27'] = '\u0634\u062E';
  23782. t['\uFD28'] = '\u0634\u0645';
  23783. t['\uFD29'] = '\u0634\u0631';
  23784. t['\uFD2A'] = '\u0633\u0631';
  23785. t['\uFD2B'] = '\u0635\u0631';
  23786. t['\uFD2C'] = '\u0636\u0631';
  23787. t['\uFD2D'] = '\u0634\u062C';
  23788. t['\uFD2E'] = '\u0634\u062D';
  23789. t['\uFD2F'] = '\u0634\u062E';
  23790. t['\uFD30'] = '\u0634\u0645';
  23791. t['\uFD31'] = '\u0633\u0647';
  23792. t['\uFD32'] = '\u0634\u0647';
  23793. t['\uFD33'] = '\u0637\u0645';
  23794. t['\uFD34'] = '\u0633\u062C';
  23795. t['\uFD35'] = '\u0633\u062D';
  23796. t['\uFD36'] = '\u0633\u062E';
  23797. t['\uFD37'] = '\u0634\u062C';
  23798. t['\uFD38'] = '\u0634\u062D';
  23799. t['\uFD39'] = '\u0634\u062E';
  23800. t['\uFD3A'] = '\u0637\u0645';
  23801. t['\uFD3B'] = '\u0638\u0645';
  23802. t['\uFD3C'] = '\u0627\u064B';
  23803. t['\uFD3D'] = '\u0627\u064B';
  23804. t['\uFD50'] = '\u062A\u062C\u0645';
  23805. t['\uFD51'] = '\u062A\u062D\u062C';
  23806. t['\uFD52'] = '\u062A\u062D\u062C';
  23807. t['\uFD53'] = '\u062A\u062D\u0645';
  23808. t['\uFD54'] = '\u062A\u062E\u0645';
  23809. t['\uFD55'] = '\u062A\u0645\u062C';
  23810. t['\uFD56'] = '\u062A\u0645\u062D';
  23811. t['\uFD57'] = '\u062A\u0645\u062E';
  23812. t['\uFD58'] = '\u062C\u0645\u062D';
  23813. t['\uFD59'] = '\u062C\u0645\u062D';
  23814. t['\uFD5A'] = '\u062D\u0645\u064A';
  23815. t['\uFD5B'] = '\u062D\u0645\u0649';
  23816. t['\uFD5C'] = '\u0633\u062D\u062C';
  23817. t['\uFD5D'] = '\u0633\u062C\u062D';
  23818. t['\uFD5E'] = '\u0633\u062C\u0649';
  23819. t['\uFD5F'] = '\u0633\u0645\u062D';
  23820. t['\uFD60'] = '\u0633\u0645\u062D';
  23821. t['\uFD61'] = '\u0633\u0645\u062C';
  23822. t['\uFD62'] = '\u0633\u0645\u0645';
  23823. t['\uFD63'] = '\u0633\u0645\u0645';
  23824. t['\uFD64'] = '\u0635\u062D\u062D';
  23825. t['\uFD65'] = '\u0635\u062D\u062D';
  23826. t['\uFD66'] = '\u0635\u0645\u0645';
  23827. t['\uFD67'] = '\u0634\u062D\u0645';
  23828. t['\uFD68'] = '\u0634\u062D\u0645';
  23829. t['\uFD69'] = '\u0634\u062C\u064A';
  23830. t['\uFD6A'] = '\u0634\u0645\u062E';
  23831. t['\uFD6B'] = '\u0634\u0645\u062E';
  23832. t['\uFD6C'] = '\u0634\u0645\u0645';
  23833. t['\uFD6D'] = '\u0634\u0645\u0645';
  23834. t['\uFD6E'] = '\u0636\u062D\u0649';
  23835. t['\uFD6F'] = '\u0636\u062E\u0645';
  23836. t['\uFD70'] = '\u0636\u062E\u0645';
  23837. t['\uFD71'] = '\u0637\u0645\u062D';
  23838. t['\uFD72'] = '\u0637\u0645\u062D';
  23839. t['\uFD73'] = '\u0637\u0645\u0645';
  23840. t['\uFD74'] = '\u0637\u0645\u064A';
  23841. t['\uFD75'] = '\u0639\u062C\u0645';
  23842. t['\uFD76'] = '\u0639\u0645\u0645';
  23843. t['\uFD77'] = '\u0639\u0645\u0645';
  23844. t['\uFD78'] = '\u0639\u0645\u0649';
  23845. t['\uFD79'] = '\u063A\u0645\u0645';
  23846. t['\uFD7A'] = '\u063A\u0645\u064A';
  23847. t['\uFD7B'] = '\u063A\u0645\u0649';
  23848. t['\uFD7C'] = '\u0641\u062E\u0645';
  23849. t['\uFD7D'] = '\u0641\u062E\u0645';
  23850. t['\uFD7E'] = '\u0642\u0645\u062D';
  23851. t['\uFD7F'] = '\u0642\u0645\u0645';
  23852. t['\uFD80'] = '\u0644\u062D\u0645';
  23853. t['\uFD81'] = '\u0644\u062D\u064A';
  23854. t['\uFD82'] = '\u0644\u062D\u0649';
  23855. t['\uFD83'] = '\u0644\u062C\u062C';
  23856. t['\uFD84'] = '\u0644\u062C\u062C';
  23857. t['\uFD85'] = '\u0644\u062E\u0645';
  23858. t['\uFD86'] = '\u0644\u062E\u0645';
  23859. t['\uFD87'] = '\u0644\u0645\u062D';
  23860. t['\uFD88'] = '\u0644\u0645\u062D';
  23861. t['\uFD89'] = '\u0645\u062D\u062C';
  23862. t['\uFD8A'] = '\u0645\u062D\u0645';
  23863. t['\uFD8B'] = '\u0645\u062D\u064A';
  23864. t['\uFD8C'] = '\u0645\u062C\u062D';
  23865. t['\uFD8D'] = '\u0645\u062C\u0645';
  23866. t['\uFD8E'] = '\u0645\u062E\u062C';
  23867. t['\uFD8F'] = '\u0645\u062E\u0645';
  23868. t['\uFD92'] = '\u0645\u062C\u062E';
  23869. t['\uFD93'] = '\u0647\u0645\u062C';
  23870. t['\uFD94'] = '\u0647\u0645\u0645';
  23871. t['\uFD95'] = '\u0646\u062D\u0645';
  23872. t['\uFD96'] = '\u0646\u062D\u0649';
  23873. t['\uFD97'] = '\u0646\u062C\u0645';
  23874. t['\uFD98'] = '\u0646\u062C\u0645';
  23875. t['\uFD99'] = '\u0646\u062C\u0649';
  23876. t['\uFD9A'] = '\u0646\u0645\u064A';
  23877. t['\uFD9B'] = '\u0646\u0645\u0649';
  23878. t['\uFD9C'] = '\u064A\u0645\u0645';
  23879. t['\uFD9D'] = '\u064A\u0645\u0645';
  23880. t['\uFD9E'] = '\u0628\u062E\u064A';
  23881. t['\uFD9F'] = '\u062A\u062C\u064A';
  23882. t['\uFDA0'] = '\u062A\u062C\u0649';
  23883. t['\uFDA1'] = '\u062A\u062E\u064A';
  23884. t['\uFDA2'] = '\u062A\u062E\u0649';
  23885. t['\uFDA3'] = '\u062A\u0645\u064A';
  23886. t['\uFDA4'] = '\u062A\u0645\u0649';
  23887. t['\uFDA5'] = '\u062C\u0645\u064A';
  23888. t['\uFDA6'] = '\u062C\u062D\u0649';
  23889. t['\uFDA7'] = '\u062C\u0645\u0649';
  23890. t['\uFDA8'] = '\u0633\u062E\u0649';
  23891. t['\uFDA9'] = '\u0635\u062D\u064A';
  23892. t['\uFDAA'] = '\u0634\u062D\u064A';
  23893. t['\uFDAB'] = '\u0636\u062D\u064A';
  23894. t['\uFDAC'] = '\u0644\u062C\u064A';
  23895. t['\uFDAD'] = '\u0644\u0645\u064A';
  23896. t['\uFDAE'] = '\u064A\u062D\u064A';
  23897. t['\uFDAF'] = '\u064A\u062C\u064A';
  23898. t['\uFDB0'] = '\u064A\u0645\u064A';
  23899. t['\uFDB1'] = '\u0645\u0645\u064A';
  23900. t['\uFDB2'] = '\u0642\u0645\u064A';
  23901. t['\uFDB3'] = '\u0646\u062D\u064A';
  23902. t['\uFDB4'] = '\u0642\u0645\u062D';
  23903. t['\uFDB5'] = '\u0644\u062D\u0645';
  23904. t['\uFDB6'] = '\u0639\u0645\u064A';
  23905. t['\uFDB7'] = '\u0643\u0645\u064A';
  23906. t['\uFDB8'] = '\u0646\u062C\u062D';
  23907. t['\uFDB9'] = '\u0645\u062E\u064A';
  23908. t['\uFDBA'] = '\u0644\u062C\u0645';
  23909. t['\uFDBB'] = '\u0643\u0645\u0645';
  23910. t['\uFDBC'] = '\u0644\u062C\u0645';
  23911. t['\uFDBD'] = '\u0646\u062C\u062D';
  23912. t['\uFDBE'] = '\u062C\u062D\u064A';
  23913. t['\uFDBF'] = '\u062D\u062C\u064A';
  23914. t['\uFDC0'] = '\u0645\u062C\u064A';
  23915. t['\uFDC1'] = '\u0641\u0645\u064A';
  23916. t['\uFDC2'] = '\u0628\u062D\u064A';
  23917. t['\uFDC3'] = '\u0643\u0645\u0645';
  23918. t['\uFDC4'] = '\u0639\u062C\u0645';
  23919. t['\uFDC5'] = '\u0635\u0645\u0645';
  23920. t['\uFDC6'] = '\u0633\u062E\u064A';
  23921. t['\uFDC7'] = '\u0646\u062C\u064A';
  23922. t['\uFE49'] = '\u203E';
  23923. t['\uFE4A'] = '\u203E';
  23924. t['\uFE4B'] = '\u203E';
  23925. t['\uFE4C'] = '\u203E';
  23926. t['\uFE4D'] = '\u005F';
  23927. t['\uFE4E'] = '\u005F';
  23928. t['\uFE4F'] = '\u005F';
  23929. t['\uFE80'] = '\u0621';
  23930. t['\uFE81'] = '\u0622';
  23931. t['\uFE82'] = '\u0622';
  23932. t['\uFE83'] = '\u0623';
  23933. t['\uFE84'] = '\u0623';
  23934. t['\uFE85'] = '\u0624';
  23935. t['\uFE86'] = '\u0624';
  23936. t['\uFE87'] = '\u0625';
  23937. t['\uFE88'] = '\u0625';
  23938. t['\uFE89'] = '\u0626';
  23939. t['\uFE8A'] = '\u0626';
  23940. t['\uFE8B'] = '\u0626';
  23941. t['\uFE8C'] = '\u0626';
  23942. t['\uFE8D'] = '\u0627';
  23943. t['\uFE8E'] = '\u0627';
  23944. t['\uFE8F'] = '\u0628';
  23945. t['\uFE90'] = '\u0628';
  23946. t['\uFE91'] = '\u0628';
  23947. t['\uFE92'] = '\u0628';
  23948. t['\uFE93'] = '\u0629';
  23949. t['\uFE94'] = '\u0629';
  23950. t['\uFE95'] = '\u062A';
  23951. t['\uFE96'] = '\u062A';
  23952. t['\uFE97'] = '\u062A';
  23953. t['\uFE98'] = '\u062A';
  23954. t['\uFE99'] = '\u062B';
  23955. t['\uFE9A'] = '\u062B';
  23956. t['\uFE9B'] = '\u062B';
  23957. t['\uFE9C'] = '\u062B';
  23958. t['\uFE9D'] = '\u062C';
  23959. t['\uFE9E'] = '\u062C';
  23960. t['\uFE9F'] = '\u062C';
  23961. t['\uFEA0'] = '\u062C';
  23962. t['\uFEA1'] = '\u062D';
  23963. t['\uFEA2'] = '\u062D';
  23964. t['\uFEA3'] = '\u062D';
  23965. t['\uFEA4'] = '\u062D';
  23966. t['\uFEA5'] = '\u062E';
  23967. t['\uFEA6'] = '\u062E';
  23968. t['\uFEA7'] = '\u062E';
  23969. t['\uFEA8'] = '\u062E';
  23970. t['\uFEA9'] = '\u062F';
  23971. t['\uFEAA'] = '\u062F';
  23972. t['\uFEAB'] = '\u0630';
  23973. t['\uFEAC'] = '\u0630';
  23974. t['\uFEAD'] = '\u0631';
  23975. t['\uFEAE'] = '\u0631';
  23976. t['\uFEAF'] = '\u0632';
  23977. t['\uFEB0'] = '\u0632';
  23978. t['\uFEB1'] = '\u0633';
  23979. t['\uFEB2'] = '\u0633';
  23980. t['\uFEB3'] = '\u0633';
  23981. t['\uFEB4'] = '\u0633';
  23982. t['\uFEB5'] = '\u0634';
  23983. t['\uFEB6'] = '\u0634';
  23984. t['\uFEB7'] = '\u0634';
  23985. t['\uFEB8'] = '\u0634';
  23986. t['\uFEB9'] = '\u0635';
  23987. t['\uFEBA'] = '\u0635';
  23988. t['\uFEBB'] = '\u0635';
  23989. t['\uFEBC'] = '\u0635';
  23990. t['\uFEBD'] = '\u0636';
  23991. t['\uFEBE'] = '\u0636';
  23992. t['\uFEBF'] = '\u0636';
  23993. t['\uFEC0'] = '\u0636';
  23994. t['\uFEC1'] = '\u0637';
  23995. t['\uFEC2'] = '\u0637';
  23996. t['\uFEC3'] = '\u0637';
  23997. t['\uFEC4'] = '\u0637';
  23998. t['\uFEC5'] = '\u0638';
  23999. t['\uFEC6'] = '\u0638';
  24000. t['\uFEC7'] = '\u0638';
  24001. t['\uFEC8'] = '\u0638';
  24002. t['\uFEC9'] = '\u0639';
  24003. t['\uFECA'] = '\u0639';
  24004. t['\uFECB'] = '\u0639';
  24005. t['\uFECC'] = '\u0639';
  24006. t['\uFECD'] = '\u063A';
  24007. t['\uFECE'] = '\u063A';
  24008. t['\uFECF'] = '\u063A';
  24009. t['\uFED0'] = '\u063A';
  24010. t['\uFED1'] = '\u0641';
  24011. t['\uFED2'] = '\u0641';
  24012. t['\uFED3'] = '\u0641';
  24013. t['\uFED4'] = '\u0641';
  24014. t['\uFED5'] = '\u0642';
  24015. t['\uFED6'] = '\u0642';
  24016. t['\uFED7'] = '\u0642';
  24017. t['\uFED8'] = '\u0642';
  24018. t['\uFED9'] = '\u0643';
  24019. t['\uFEDA'] = '\u0643';
  24020. t['\uFEDB'] = '\u0643';
  24021. t['\uFEDC'] = '\u0643';
  24022. t['\uFEDD'] = '\u0644';
  24023. t['\uFEDE'] = '\u0644';
  24024. t['\uFEDF'] = '\u0644';
  24025. t['\uFEE0'] = '\u0644';
  24026. t['\uFEE1'] = '\u0645';
  24027. t['\uFEE2'] = '\u0645';
  24028. t['\uFEE3'] = '\u0645';
  24029. t['\uFEE4'] = '\u0645';
  24030. t['\uFEE5'] = '\u0646';
  24031. t['\uFEE6'] = '\u0646';
  24032. t['\uFEE7'] = '\u0646';
  24033. t['\uFEE8'] = '\u0646';
  24034. t['\uFEE9'] = '\u0647';
  24035. t['\uFEEA'] = '\u0647';
  24036. t['\uFEEB'] = '\u0647';
  24037. t['\uFEEC'] = '\u0647';
  24038. t['\uFEED'] = '\u0648';
  24039. t['\uFEEE'] = '\u0648';
  24040. t['\uFEEF'] = '\u0649';
  24041. t['\uFEF0'] = '\u0649';
  24042. t['\uFEF1'] = '\u064A';
  24043. t['\uFEF2'] = '\u064A';
  24044. t['\uFEF3'] = '\u064A';
  24045. t['\uFEF4'] = '\u064A';
  24046. t['\uFEF5'] = '\u0644\u0622';
  24047. t['\uFEF6'] = '\u0644\u0622';
  24048. t['\uFEF7'] = '\u0644\u0623';
  24049. t['\uFEF8'] = '\u0644\u0623';
  24050. t['\uFEF9'] = '\u0644\u0625';
  24051. t['\uFEFA'] = '\u0644\u0625';
  24052. t['\uFEFB'] = '\u0644\u0627';
  24053. t['\uFEFC'] = '\u0644\u0627';
  24054. });
  24055. function reverseIfRtl(chars) {
  24056. var charsLength = chars.length;
  24057. //reverse an arabic ligature
  24058. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  24059. return chars;
  24060. }
  24061. var s = '';
  24062. for (var ii = charsLength - 1; ii >= 0; ii--) {
  24063. s += chars[ii];
  24064. }
  24065. return s;
  24066. }
  24067. exports.mapSpecialUnicodeValues = mapSpecialUnicodeValues;
  24068. exports.reverseIfRtl = reverseIfRtl;
  24069. exports.getUnicodeRangeFor = getUnicodeRangeFor;
  24070. exports.getNormalizedUnicodes = getNormalizedUnicodes;
  24071. exports.getUnicodeForGlyph = getUnicodeForGlyph;
  24072. }));
  24073. (function (root, factory) {
  24074. factory(root.pdfjsCoreStream = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreJbig2, root.pdfjsCoreJpg, root.pdfjsCoreJpx);
  24075. }(this, function (exports, sharedUtil, corePrimitives, coreJbig2, coreJpg, coreJpx) {
  24076. var Util = sharedUtil.Util;
  24077. var error = sharedUtil.error;
  24078. var info = sharedUtil.info;
  24079. var isInt = sharedUtil.isInt;
  24080. var isArray = sharedUtil.isArray;
  24081. var createObjectURL = sharedUtil.createObjectURL;
  24082. var shadow = sharedUtil.shadow;
  24083. var warn = sharedUtil.warn;
  24084. var isSpace = sharedUtil.isSpace;
  24085. var Dict = corePrimitives.Dict;
  24086. var isDict = corePrimitives.isDict;
  24087. var Jbig2Image = coreJbig2.Jbig2Image;
  24088. var JpegImage = coreJpg.JpegImage;
  24089. var JpxImage = coreJpx.JpxImage;
  24090. var Stream = function StreamClosure() {
  24091. function Stream(arrayBuffer, start, length, dict) {
  24092. this.bytes = arrayBuffer instanceof Uint8Array ? arrayBuffer : new Uint8Array(arrayBuffer);
  24093. this.start = start || 0;
  24094. this.pos = this.start;
  24095. this.end = start + length || this.bytes.length;
  24096. this.dict = dict;
  24097. }
  24098. // required methods for a stream. if a particular stream does not
  24099. // implement these, an error should be thrown
  24100. Stream.prototype = {
  24101. get length() {
  24102. return this.end - this.start;
  24103. },
  24104. get isEmpty() {
  24105. return this.length === 0;
  24106. },
  24107. getByte: function Stream_getByte() {
  24108. if (this.pos >= this.end) {
  24109. return -1;
  24110. }
  24111. return this.bytes[this.pos++];
  24112. },
  24113. getUint16: function Stream_getUint16() {
  24114. var b0 = this.getByte();
  24115. var b1 = this.getByte();
  24116. if (b0 === -1 || b1 === -1) {
  24117. return -1;
  24118. }
  24119. return (b0 << 8) + b1;
  24120. },
  24121. getInt32: function Stream_getInt32() {
  24122. var b0 = this.getByte();
  24123. var b1 = this.getByte();
  24124. var b2 = this.getByte();
  24125. var b3 = this.getByte();
  24126. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  24127. },
  24128. // returns subarray of original buffer
  24129. // should only be read
  24130. getBytes: function Stream_getBytes(length) {
  24131. var bytes = this.bytes;
  24132. var pos = this.pos;
  24133. var strEnd = this.end;
  24134. if (!length) {
  24135. return bytes.subarray(pos, strEnd);
  24136. }
  24137. var end = pos + length;
  24138. if (end > strEnd) {
  24139. end = strEnd;
  24140. }
  24141. this.pos = end;
  24142. return bytes.subarray(pos, end);
  24143. },
  24144. peekByte: function Stream_peekByte() {
  24145. var peekedByte = this.getByte();
  24146. this.pos--;
  24147. return peekedByte;
  24148. },
  24149. peekBytes: function Stream_peekBytes(length) {
  24150. var bytes = this.getBytes(length);
  24151. this.pos -= bytes.length;
  24152. return bytes;
  24153. },
  24154. skip: function Stream_skip(n) {
  24155. if (!n) {
  24156. n = 1;
  24157. }
  24158. this.pos += n;
  24159. },
  24160. reset: function Stream_reset() {
  24161. this.pos = this.start;
  24162. },
  24163. moveStart: function Stream_moveStart() {
  24164. this.start = this.pos;
  24165. },
  24166. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  24167. return new Stream(this.bytes.buffer, start, length, dict);
  24168. },
  24169. isStream: true
  24170. };
  24171. return Stream;
  24172. }();
  24173. var StringStream = function StringStreamClosure() {
  24174. function StringStream(str) {
  24175. var length = str.length;
  24176. var bytes = new Uint8Array(length);
  24177. for (var n = 0; n < length; ++n) {
  24178. bytes[n] = str.charCodeAt(n);
  24179. }
  24180. Stream.call(this, bytes);
  24181. }
  24182. StringStream.prototype = Stream.prototype;
  24183. return StringStream;
  24184. }();
  24185. // super class for the decoding streams
  24186. var DecodeStream = function DecodeStreamClosure() {
  24187. // Lots of DecodeStreams are created whose buffers are never used. For these
  24188. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  24189. // having special cases that would be required if we used |null| for an empty
  24190. // buffer.
  24191. var emptyBuffer = new Uint8Array(0);
  24192. function DecodeStream(maybeMinBufferLength) {
  24193. this.pos = 0;
  24194. this.bufferLength = 0;
  24195. this.eof = false;
  24196. this.buffer = emptyBuffer;
  24197. this.minBufferLength = 512;
  24198. if (maybeMinBufferLength) {
  24199. // Compute the first power of two that is as big as maybeMinBufferLength.
  24200. while (this.minBufferLength < maybeMinBufferLength) {
  24201. this.minBufferLength *= 2;
  24202. }
  24203. }
  24204. }
  24205. DecodeStream.prototype = {
  24206. get isEmpty() {
  24207. while (!this.eof && this.bufferLength === 0) {
  24208. this.readBlock();
  24209. }
  24210. return this.bufferLength === 0;
  24211. },
  24212. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  24213. var buffer = this.buffer;
  24214. if (requested <= buffer.byteLength) {
  24215. return buffer;
  24216. }
  24217. var size = this.minBufferLength;
  24218. while (size < requested) {
  24219. size *= 2;
  24220. }
  24221. var buffer2 = new Uint8Array(size);
  24222. buffer2.set(buffer);
  24223. return this.buffer = buffer2;
  24224. },
  24225. getByte: function DecodeStream_getByte() {
  24226. var pos = this.pos;
  24227. while (this.bufferLength <= pos) {
  24228. if (this.eof) {
  24229. return -1;
  24230. }
  24231. this.readBlock();
  24232. }
  24233. return this.buffer[this.pos++];
  24234. },
  24235. getUint16: function DecodeStream_getUint16() {
  24236. var b0 = this.getByte();
  24237. var b1 = this.getByte();
  24238. if (b0 === -1 || b1 === -1) {
  24239. return -1;
  24240. }
  24241. return (b0 << 8) + b1;
  24242. },
  24243. getInt32: function DecodeStream_getInt32() {
  24244. var b0 = this.getByte();
  24245. var b1 = this.getByte();
  24246. var b2 = this.getByte();
  24247. var b3 = this.getByte();
  24248. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  24249. },
  24250. getBytes: function DecodeStream_getBytes(length) {
  24251. var end, pos = this.pos;
  24252. if (length) {
  24253. this.ensureBuffer(pos + length);
  24254. end = pos + length;
  24255. while (!this.eof && this.bufferLength < end) {
  24256. this.readBlock();
  24257. }
  24258. var bufEnd = this.bufferLength;
  24259. if (end > bufEnd) {
  24260. end = bufEnd;
  24261. }
  24262. } else {
  24263. while (!this.eof) {
  24264. this.readBlock();
  24265. }
  24266. end = this.bufferLength;
  24267. }
  24268. this.pos = end;
  24269. return this.buffer.subarray(pos, end);
  24270. },
  24271. peekByte: function DecodeStream_peekByte() {
  24272. var peekedByte = this.getByte();
  24273. this.pos--;
  24274. return peekedByte;
  24275. },
  24276. peekBytes: function DecodeStream_peekBytes(length) {
  24277. var bytes = this.getBytes(length);
  24278. this.pos -= bytes.length;
  24279. return bytes;
  24280. },
  24281. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  24282. var end = start + length;
  24283. while (this.bufferLength <= end && !this.eof) {
  24284. this.readBlock();
  24285. }
  24286. return new Stream(this.buffer, start, length, dict);
  24287. },
  24288. skip: function DecodeStream_skip(n) {
  24289. if (!n) {
  24290. n = 1;
  24291. }
  24292. this.pos += n;
  24293. },
  24294. reset: function DecodeStream_reset() {
  24295. this.pos = 0;
  24296. },
  24297. getBaseStreams: function DecodeStream_getBaseStreams() {
  24298. if (this.str && this.str.getBaseStreams) {
  24299. return this.str.getBaseStreams();
  24300. }
  24301. return [];
  24302. }
  24303. };
  24304. return DecodeStream;
  24305. }();
  24306. var StreamsSequenceStream = function StreamsSequenceStreamClosure() {
  24307. function StreamsSequenceStream(streams) {
  24308. this.streams = streams;
  24309. DecodeStream.call(this, /* maybeLength = */
  24310. null);
  24311. }
  24312. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  24313. StreamsSequenceStream.prototype.readBlock = function streamSequenceStreamReadBlock() {
  24314. var streams = this.streams;
  24315. if (streams.length === 0) {
  24316. this.eof = true;
  24317. return;
  24318. }
  24319. var stream = streams.shift();
  24320. var chunk = stream.getBytes();
  24321. var bufferLength = this.bufferLength;
  24322. var newLength = bufferLength + chunk.length;
  24323. var buffer = this.ensureBuffer(newLength);
  24324. buffer.set(chunk, bufferLength);
  24325. this.bufferLength = newLength;
  24326. };
  24327. StreamsSequenceStream.prototype.getBaseStreams = function StreamsSequenceStream_getBaseStreams() {
  24328. var baseStreams = [];
  24329. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  24330. var stream = this.streams[i];
  24331. if (stream.getBaseStreams) {
  24332. Util.appendToArray(baseStreams, stream.getBaseStreams());
  24333. }
  24334. }
  24335. return baseStreams;
  24336. };
  24337. return StreamsSequenceStream;
  24338. }();
  24339. var FlateStream = function FlateStreamClosure() {
  24340. var codeLenCodeMap = new Int32Array([
  24341. 16,
  24342. 17,
  24343. 18,
  24344. 0,
  24345. 8,
  24346. 7,
  24347. 9,
  24348. 6,
  24349. 10,
  24350. 5,
  24351. 11,
  24352. 4,
  24353. 12,
  24354. 3,
  24355. 13,
  24356. 2,
  24357. 14,
  24358. 1,
  24359. 15
  24360. ]);
  24361. var lengthDecode = new Int32Array([
  24362. 0x00003,
  24363. 0x00004,
  24364. 0x00005,
  24365. 0x00006,
  24366. 0x00007,
  24367. 0x00008,
  24368. 0x00009,
  24369. 0x0000a,
  24370. 0x1000b,
  24371. 0x1000d,
  24372. 0x1000f,
  24373. 0x10011,
  24374. 0x20013,
  24375. 0x20017,
  24376. 0x2001b,
  24377. 0x2001f,
  24378. 0x30023,
  24379. 0x3002b,
  24380. 0x30033,
  24381. 0x3003b,
  24382. 0x40043,
  24383. 0x40053,
  24384. 0x40063,
  24385. 0x40073,
  24386. 0x50083,
  24387. 0x500a3,
  24388. 0x500c3,
  24389. 0x500e3,
  24390. 0x00102,
  24391. 0x00102,
  24392. 0x00102
  24393. ]);
  24394. var distDecode = new Int32Array([
  24395. 0x00001,
  24396. 0x00002,
  24397. 0x00003,
  24398. 0x00004,
  24399. 0x10005,
  24400. 0x10007,
  24401. 0x20009,
  24402. 0x2000d,
  24403. 0x30011,
  24404. 0x30019,
  24405. 0x40021,
  24406. 0x40031,
  24407. 0x50041,
  24408. 0x50061,
  24409. 0x60081,
  24410. 0x600c1,
  24411. 0x70101,
  24412. 0x70181,
  24413. 0x80201,
  24414. 0x80301,
  24415. 0x90401,
  24416. 0x90601,
  24417. 0xa0801,
  24418. 0xa0c01,
  24419. 0xb1001,
  24420. 0xb1801,
  24421. 0xc2001,
  24422. 0xc3001,
  24423. 0xd4001,
  24424. 0xd6001
  24425. ]);
  24426. var fixedLitCodeTab = [
  24427. new Int32Array([
  24428. 0x70100,
  24429. 0x80050,
  24430. 0x80010,
  24431. 0x80118,
  24432. 0x70110,
  24433. 0x80070,
  24434. 0x80030,
  24435. 0x900c0,
  24436. 0x70108,
  24437. 0x80060,
  24438. 0x80020,
  24439. 0x900a0,
  24440. 0x80000,
  24441. 0x80080,
  24442. 0x80040,
  24443. 0x900e0,
  24444. 0x70104,
  24445. 0x80058,
  24446. 0x80018,
  24447. 0x90090,
  24448. 0x70114,
  24449. 0x80078,
  24450. 0x80038,
  24451. 0x900d0,
  24452. 0x7010c,
  24453. 0x80068,
  24454. 0x80028,
  24455. 0x900b0,
  24456. 0x80008,
  24457. 0x80088,
  24458. 0x80048,
  24459. 0x900f0,
  24460. 0x70102,
  24461. 0x80054,
  24462. 0x80014,
  24463. 0x8011c,
  24464. 0x70112,
  24465. 0x80074,
  24466. 0x80034,
  24467. 0x900c8,
  24468. 0x7010a,
  24469. 0x80064,
  24470. 0x80024,
  24471. 0x900a8,
  24472. 0x80004,
  24473. 0x80084,
  24474. 0x80044,
  24475. 0x900e8,
  24476. 0x70106,
  24477. 0x8005c,
  24478. 0x8001c,
  24479. 0x90098,
  24480. 0x70116,
  24481. 0x8007c,
  24482. 0x8003c,
  24483. 0x900d8,
  24484. 0x7010e,
  24485. 0x8006c,
  24486. 0x8002c,
  24487. 0x900b8,
  24488. 0x8000c,
  24489. 0x8008c,
  24490. 0x8004c,
  24491. 0x900f8,
  24492. 0x70101,
  24493. 0x80052,
  24494. 0x80012,
  24495. 0x8011a,
  24496. 0x70111,
  24497. 0x80072,
  24498. 0x80032,
  24499. 0x900c4,
  24500. 0x70109,
  24501. 0x80062,
  24502. 0x80022,
  24503. 0x900a4,
  24504. 0x80002,
  24505. 0x80082,
  24506. 0x80042,
  24507. 0x900e4,
  24508. 0x70105,
  24509. 0x8005a,
  24510. 0x8001a,
  24511. 0x90094,
  24512. 0x70115,
  24513. 0x8007a,
  24514. 0x8003a,
  24515. 0x900d4,
  24516. 0x7010d,
  24517. 0x8006a,
  24518. 0x8002a,
  24519. 0x900b4,
  24520. 0x8000a,
  24521. 0x8008a,
  24522. 0x8004a,
  24523. 0x900f4,
  24524. 0x70103,
  24525. 0x80056,
  24526. 0x80016,
  24527. 0x8011e,
  24528. 0x70113,
  24529. 0x80076,
  24530. 0x80036,
  24531. 0x900cc,
  24532. 0x7010b,
  24533. 0x80066,
  24534. 0x80026,
  24535. 0x900ac,
  24536. 0x80006,
  24537. 0x80086,
  24538. 0x80046,
  24539. 0x900ec,
  24540. 0x70107,
  24541. 0x8005e,
  24542. 0x8001e,
  24543. 0x9009c,
  24544. 0x70117,
  24545. 0x8007e,
  24546. 0x8003e,
  24547. 0x900dc,
  24548. 0x7010f,
  24549. 0x8006e,
  24550. 0x8002e,
  24551. 0x900bc,
  24552. 0x8000e,
  24553. 0x8008e,
  24554. 0x8004e,
  24555. 0x900fc,
  24556. 0x70100,
  24557. 0x80051,
  24558. 0x80011,
  24559. 0x80119,
  24560. 0x70110,
  24561. 0x80071,
  24562. 0x80031,
  24563. 0x900c2,
  24564. 0x70108,
  24565. 0x80061,
  24566. 0x80021,
  24567. 0x900a2,
  24568. 0x80001,
  24569. 0x80081,
  24570. 0x80041,
  24571. 0x900e2,
  24572. 0x70104,
  24573. 0x80059,
  24574. 0x80019,
  24575. 0x90092,
  24576. 0x70114,
  24577. 0x80079,
  24578. 0x80039,
  24579. 0x900d2,
  24580. 0x7010c,
  24581. 0x80069,
  24582. 0x80029,
  24583. 0x900b2,
  24584. 0x80009,
  24585. 0x80089,
  24586. 0x80049,
  24587. 0x900f2,
  24588. 0x70102,
  24589. 0x80055,
  24590. 0x80015,
  24591. 0x8011d,
  24592. 0x70112,
  24593. 0x80075,
  24594. 0x80035,
  24595. 0x900ca,
  24596. 0x7010a,
  24597. 0x80065,
  24598. 0x80025,
  24599. 0x900aa,
  24600. 0x80005,
  24601. 0x80085,
  24602. 0x80045,
  24603. 0x900ea,
  24604. 0x70106,
  24605. 0x8005d,
  24606. 0x8001d,
  24607. 0x9009a,
  24608. 0x70116,
  24609. 0x8007d,
  24610. 0x8003d,
  24611. 0x900da,
  24612. 0x7010e,
  24613. 0x8006d,
  24614. 0x8002d,
  24615. 0x900ba,
  24616. 0x8000d,
  24617. 0x8008d,
  24618. 0x8004d,
  24619. 0x900fa,
  24620. 0x70101,
  24621. 0x80053,
  24622. 0x80013,
  24623. 0x8011b,
  24624. 0x70111,
  24625. 0x80073,
  24626. 0x80033,
  24627. 0x900c6,
  24628. 0x70109,
  24629. 0x80063,
  24630. 0x80023,
  24631. 0x900a6,
  24632. 0x80003,
  24633. 0x80083,
  24634. 0x80043,
  24635. 0x900e6,
  24636. 0x70105,
  24637. 0x8005b,
  24638. 0x8001b,
  24639. 0x90096,
  24640. 0x70115,
  24641. 0x8007b,
  24642. 0x8003b,
  24643. 0x900d6,
  24644. 0x7010d,
  24645. 0x8006b,
  24646. 0x8002b,
  24647. 0x900b6,
  24648. 0x8000b,
  24649. 0x8008b,
  24650. 0x8004b,
  24651. 0x900f6,
  24652. 0x70103,
  24653. 0x80057,
  24654. 0x80017,
  24655. 0x8011f,
  24656. 0x70113,
  24657. 0x80077,
  24658. 0x80037,
  24659. 0x900ce,
  24660. 0x7010b,
  24661. 0x80067,
  24662. 0x80027,
  24663. 0x900ae,
  24664. 0x80007,
  24665. 0x80087,
  24666. 0x80047,
  24667. 0x900ee,
  24668. 0x70107,
  24669. 0x8005f,
  24670. 0x8001f,
  24671. 0x9009e,
  24672. 0x70117,
  24673. 0x8007f,
  24674. 0x8003f,
  24675. 0x900de,
  24676. 0x7010f,
  24677. 0x8006f,
  24678. 0x8002f,
  24679. 0x900be,
  24680. 0x8000f,
  24681. 0x8008f,
  24682. 0x8004f,
  24683. 0x900fe,
  24684. 0x70100,
  24685. 0x80050,
  24686. 0x80010,
  24687. 0x80118,
  24688. 0x70110,
  24689. 0x80070,
  24690. 0x80030,
  24691. 0x900c1,
  24692. 0x70108,
  24693. 0x80060,
  24694. 0x80020,
  24695. 0x900a1,
  24696. 0x80000,
  24697. 0x80080,
  24698. 0x80040,
  24699. 0x900e1,
  24700. 0x70104,
  24701. 0x80058,
  24702. 0x80018,
  24703. 0x90091,
  24704. 0x70114,
  24705. 0x80078,
  24706. 0x80038,
  24707. 0x900d1,
  24708. 0x7010c,
  24709. 0x80068,
  24710. 0x80028,
  24711. 0x900b1,
  24712. 0x80008,
  24713. 0x80088,
  24714. 0x80048,
  24715. 0x900f1,
  24716. 0x70102,
  24717. 0x80054,
  24718. 0x80014,
  24719. 0x8011c,
  24720. 0x70112,
  24721. 0x80074,
  24722. 0x80034,
  24723. 0x900c9,
  24724. 0x7010a,
  24725. 0x80064,
  24726. 0x80024,
  24727. 0x900a9,
  24728. 0x80004,
  24729. 0x80084,
  24730. 0x80044,
  24731. 0x900e9,
  24732. 0x70106,
  24733. 0x8005c,
  24734. 0x8001c,
  24735. 0x90099,
  24736. 0x70116,
  24737. 0x8007c,
  24738. 0x8003c,
  24739. 0x900d9,
  24740. 0x7010e,
  24741. 0x8006c,
  24742. 0x8002c,
  24743. 0x900b9,
  24744. 0x8000c,
  24745. 0x8008c,
  24746. 0x8004c,
  24747. 0x900f9,
  24748. 0x70101,
  24749. 0x80052,
  24750. 0x80012,
  24751. 0x8011a,
  24752. 0x70111,
  24753. 0x80072,
  24754. 0x80032,
  24755. 0x900c5,
  24756. 0x70109,
  24757. 0x80062,
  24758. 0x80022,
  24759. 0x900a5,
  24760. 0x80002,
  24761. 0x80082,
  24762. 0x80042,
  24763. 0x900e5,
  24764. 0x70105,
  24765. 0x8005a,
  24766. 0x8001a,
  24767. 0x90095,
  24768. 0x70115,
  24769. 0x8007a,
  24770. 0x8003a,
  24771. 0x900d5,
  24772. 0x7010d,
  24773. 0x8006a,
  24774. 0x8002a,
  24775. 0x900b5,
  24776. 0x8000a,
  24777. 0x8008a,
  24778. 0x8004a,
  24779. 0x900f5,
  24780. 0x70103,
  24781. 0x80056,
  24782. 0x80016,
  24783. 0x8011e,
  24784. 0x70113,
  24785. 0x80076,
  24786. 0x80036,
  24787. 0x900cd,
  24788. 0x7010b,
  24789. 0x80066,
  24790. 0x80026,
  24791. 0x900ad,
  24792. 0x80006,
  24793. 0x80086,
  24794. 0x80046,
  24795. 0x900ed,
  24796. 0x70107,
  24797. 0x8005e,
  24798. 0x8001e,
  24799. 0x9009d,
  24800. 0x70117,
  24801. 0x8007e,
  24802. 0x8003e,
  24803. 0x900dd,
  24804. 0x7010f,
  24805. 0x8006e,
  24806. 0x8002e,
  24807. 0x900bd,
  24808. 0x8000e,
  24809. 0x8008e,
  24810. 0x8004e,
  24811. 0x900fd,
  24812. 0x70100,
  24813. 0x80051,
  24814. 0x80011,
  24815. 0x80119,
  24816. 0x70110,
  24817. 0x80071,
  24818. 0x80031,
  24819. 0x900c3,
  24820. 0x70108,
  24821. 0x80061,
  24822. 0x80021,
  24823. 0x900a3,
  24824. 0x80001,
  24825. 0x80081,
  24826. 0x80041,
  24827. 0x900e3,
  24828. 0x70104,
  24829. 0x80059,
  24830. 0x80019,
  24831. 0x90093,
  24832. 0x70114,
  24833. 0x80079,
  24834. 0x80039,
  24835. 0x900d3,
  24836. 0x7010c,
  24837. 0x80069,
  24838. 0x80029,
  24839. 0x900b3,
  24840. 0x80009,
  24841. 0x80089,
  24842. 0x80049,
  24843. 0x900f3,
  24844. 0x70102,
  24845. 0x80055,
  24846. 0x80015,
  24847. 0x8011d,
  24848. 0x70112,
  24849. 0x80075,
  24850. 0x80035,
  24851. 0x900cb,
  24852. 0x7010a,
  24853. 0x80065,
  24854. 0x80025,
  24855. 0x900ab,
  24856. 0x80005,
  24857. 0x80085,
  24858. 0x80045,
  24859. 0x900eb,
  24860. 0x70106,
  24861. 0x8005d,
  24862. 0x8001d,
  24863. 0x9009b,
  24864. 0x70116,
  24865. 0x8007d,
  24866. 0x8003d,
  24867. 0x900db,
  24868. 0x7010e,
  24869. 0x8006d,
  24870. 0x8002d,
  24871. 0x900bb,
  24872. 0x8000d,
  24873. 0x8008d,
  24874. 0x8004d,
  24875. 0x900fb,
  24876. 0x70101,
  24877. 0x80053,
  24878. 0x80013,
  24879. 0x8011b,
  24880. 0x70111,
  24881. 0x80073,
  24882. 0x80033,
  24883. 0x900c7,
  24884. 0x70109,
  24885. 0x80063,
  24886. 0x80023,
  24887. 0x900a7,
  24888. 0x80003,
  24889. 0x80083,
  24890. 0x80043,
  24891. 0x900e7,
  24892. 0x70105,
  24893. 0x8005b,
  24894. 0x8001b,
  24895. 0x90097,
  24896. 0x70115,
  24897. 0x8007b,
  24898. 0x8003b,
  24899. 0x900d7,
  24900. 0x7010d,
  24901. 0x8006b,
  24902. 0x8002b,
  24903. 0x900b7,
  24904. 0x8000b,
  24905. 0x8008b,
  24906. 0x8004b,
  24907. 0x900f7,
  24908. 0x70103,
  24909. 0x80057,
  24910. 0x80017,
  24911. 0x8011f,
  24912. 0x70113,
  24913. 0x80077,
  24914. 0x80037,
  24915. 0x900cf,
  24916. 0x7010b,
  24917. 0x80067,
  24918. 0x80027,
  24919. 0x900af,
  24920. 0x80007,
  24921. 0x80087,
  24922. 0x80047,
  24923. 0x900ef,
  24924. 0x70107,
  24925. 0x8005f,
  24926. 0x8001f,
  24927. 0x9009f,
  24928. 0x70117,
  24929. 0x8007f,
  24930. 0x8003f,
  24931. 0x900df,
  24932. 0x7010f,
  24933. 0x8006f,
  24934. 0x8002f,
  24935. 0x900bf,
  24936. 0x8000f,
  24937. 0x8008f,
  24938. 0x8004f,
  24939. 0x900ff
  24940. ]),
  24941. 9
  24942. ];
  24943. var fixedDistCodeTab = [
  24944. new Int32Array([
  24945. 0x50000,
  24946. 0x50010,
  24947. 0x50008,
  24948. 0x50018,
  24949. 0x50004,
  24950. 0x50014,
  24951. 0x5000c,
  24952. 0x5001c,
  24953. 0x50002,
  24954. 0x50012,
  24955. 0x5000a,
  24956. 0x5001a,
  24957. 0x50006,
  24958. 0x50016,
  24959. 0x5000e,
  24960. 0x00000,
  24961. 0x50001,
  24962. 0x50011,
  24963. 0x50009,
  24964. 0x50019,
  24965. 0x50005,
  24966. 0x50015,
  24967. 0x5000d,
  24968. 0x5001d,
  24969. 0x50003,
  24970. 0x50013,
  24971. 0x5000b,
  24972. 0x5001b,
  24973. 0x50007,
  24974. 0x50017,
  24975. 0x5000f,
  24976. 0x00000
  24977. ]),
  24978. 5
  24979. ];
  24980. function FlateStream(str, maybeLength) {
  24981. this.str = str;
  24982. this.dict = str.dict;
  24983. var cmf = str.getByte();
  24984. var flg = str.getByte();
  24985. if (cmf === -1 || flg === -1) {
  24986. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  24987. }
  24988. if ((cmf & 0x0f) !== 0x08) {
  24989. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  24990. }
  24991. if (((cmf << 8) + flg) % 31 !== 0) {
  24992. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  24993. }
  24994. if (flg & 0x20) {
  24995. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  24996. }
  24997. this.codeSize = 0;
  24998. this.codeBuf = 0;
  24999. DecodeStream.call(this, maybeLength);
  25000. }
  25001. FlateStream.prototype = Object.create(DecodeStream.prototype);
  25002. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  25003. var str = this.str;
  25004. var codeSize = this.codeSize;
  25005. var codeBuf = this.codeBuf;
  25006. var b;
  25007. while (codeSize < bits) {
  25008. if ((b = str.getByte()) === -1) {
  25009. error('Bad encoding in flate stream');
  25010. }
  25011. codeBuf |= b << codeSize;
  25012. codeSize += 8;
  25013. }
  25014. b = codeBuf & (1 << bits) - 1;
  25015. this.codeBuf = codeBuf >> bits;
  25016. this.codeSize = codeSize -= bits;
  25017. return b;
  25018. };
  25019. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  25020. var str = this.str;
  25021. var codes = table[0];
  25022. var maxLen = table[1];
  25023. var codeSize = this.codeSize;
  25024. var codeBuf = this.codeBuf;
  25025. var b;
  25026. while (codeSize < maxLen) {
  25027. if ((b = str.getByte()) === -1) {
  25028. // premature end of stream. code might however still be valid.
  25029. // codeSize < codeLen check below guards against incomplete codeVal.
  25030. break;
  25031. }
  25032. codeBuf |= b << codeSize;
  25033. codeSize += 8;
  25034. }
  25035. var code = codes[codeBuf & (1 << maxLen) - 1];
  25036. var codeLen = code >> 16;
  25037. var codeVal = code & 0xffff;
  25038. if (codeLen < 1 || codeSize < codeLen) {
  25039. error('Bad encoding in flate stream');
  25040. }
  25041. this.codeBuf = codeBuf >> codeLen;
  25042. this.codeSize = codeSize - codeLen;
  25043. return codeVal;
  25044. };
  25045. FlateStream.prototype.generateHuffmanTable = function flateStreamGenerateHuffmanTable(lengths) {
  25046. var n = lengths.length;
  25047. // find max code length
  25048. var maxLen = 0;
  25049. var i;
  25050. for (i = 0; i < n; ++i) {
  25051. if (lengths[i] > maxLen) {
  25052. maxLen = lengths[i];
  25053. }
  25054. }
  25055. // build the table
  25056. var size = 1 << maxLen;
  25057. var codes = new Int32Array(size);
  25058. for (var len = 1, code = 0, skip = 2; len <= maxLen; ++len, code <<= 1, skip <<= 1) {
  25059. for (var val = 0; val < n; ++val) {
  25060. if (lengths[val] === len) {
  25061. // bit-reverse the code
  25062. var code2 = 0;
  25063. var t = code;
  25064. for (i = 0; i < len; ++i) {
  25065. code2 = code2 << 1 | t & 1;
  25066. t >>= 1;
  25067. }
  25068. // fill the table entries
  25069. for (i = code2; i < size; i += skip) {
  25070. codes[i] = len << 16 | val;
  25071. }
  25072. ++code;
  25073. }
  25074. }
  25075. }
  25076. return [
  25077. codes,
  25078. maxLen
  25079. ];
  25080. };
  25081. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  25082. var buffer, len;
  25083. var str = this.str;
  25084. // read block header
  25085. var hdr = this.getBits(3);
  25086. if (hdr & 1) {
  25087. this.eof = true;
  25088. }
  25089. hdr >>= 1;
  25090. if (hdr === 0) {
  25091. // uncompressed block
  25092. var b;
  25093. if ((b = str.getByte()) === -1) {
  25094. error('Bad block header in flate stream');
  25095. }
  25096. var blockLen = b;
  25097. if ((b = str.getByte()) === -1) {
  25098. error('Bad block header in flate stream');
  25099. }
  25100. blockLen |= b << 8;
  25101. if ((b = str.getByte()) === -1) {
  25102. error('Bad block header in flate stream');
  25103. }
  25104. var check = b;
  25105. if ((b = str.getByte()) === -1) {
  25106. error('Bad block header in flate stream');
  25107. }
  25108. check |= b << 8;
  25109. if (check !== (~blockLen & 0xffff) && (blockLen !== 0 || check !== 0)) {
  25110. // Ignoring error for bad "empty" block (see issue 1277)
  25111. error('Bad uncompressed block length in flate stream');
  25112. }
  25113. this.codeBuf = 0;
  25114. this.codeSize = 0;
  25115. var bufferLength = this.bufferLength;
  25116. buffer = this.ensureBuffer(bufferLength + blockLen);
  25117. var end = bufferLength + blockLen;
  25118. this.bufferLength = end;
  25119. if (blockLen === 0) {
  25120. if (str.peekByte() === -1) {
  25121. this.eof = true;
  25122. }
  25123. } else {
  25124. for (var n = bufferLength; n < end; ++n) {
  25125. if ((b = str.getByte()) === -1) {
  25126. this.eof = true;
  25127. break;
  25128. }
  25129. buffer[n] = b;
  25130. }
  25131. }
  25132. return;
  25133. }
  25134. var litCodeTable;
  25135. var distCodeTable;
  25136. if (hdr === 1) {
  25137. // compressed block, fixed codes
  25138. litCodeTable = fixedLitCodeTab;
  25139. distCodeTable = fixedDistCodeTab;
  25140. } else if (hdr === 2) {
  25141. // compressed block, dynamic codes
  25142. var numLitCodes = this.getBits(5) + 257;
  25143. var numDistCodes = this.getBits(5) + 1;
  25144. var numCodeLenCodes = this.getBits(4) + 4;
  25145. // build the code lengths code table
  25146. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  25147. var i;
  25148. for (i = 0; i < numCodeLenCodes; ++i) {
  25149. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  25150. }
  25151. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  25152. // build the literal and distance code tables
  25153. len = 0;
  25154. i = 0;
  25155. var codes = numLitCodes + numDistCodes;
  25156. var codeLengths = new Uint8Array(codes);
  25157. var bitsLength, bitsOffset, what;
  25158. while (i < codes) {
  25159. var code = this.getCode(codeLenCodeTab);
  25160. if (code === 16) {
  25161. bitsLength = 2;
  25162. bitsOffset = 3;
  25163. what = len;
  25164. } else if (code === 17) {
  25165. bitsLength = 3;
  25166. bitsOffset = 3;
  25167. what = len = 0;
  25168. } else if (code === 18) {
  25169. bitsLength = 7;
  25170. bitsOffset = 11;
  25171. what = len = 0;
  25172. } else {
  25173. codeLengths[i++] = len = code;
  25174. continue;
  25175. }
  25176. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  25177. while (repeatLength-- > 0) {
  25178. codeLengths[i++] = what;
  25179. }
  25180. }
  25181. litCodeTable = this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  25182. distCodeTable = this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  25183. } else {
  25184. error('Unknown block type in flate stream');
  25185. }
  25186. buffer = this.buffer;
  25187. var limit = buffer ? buffer.length : 0;
  25188. var pos = this.bufferLength;
  25189. while (true) {
  25190. var code1 = this.getCode(litCodeTable);
  25191. if (code1 < 256) {
  25192. if (pos + 1 >= limit) {
  25193. buffer = this.ensureBuffer(pos + 1);
  25194. limit = buffer.length;
  25195. }
  25196. buffer[pos++] = code1;
  25197. continue;
  25198. }
  25199. if (code1 === 256) {
  25200. this.bufferLength = pos;
  25201. return;
  25202. }
  25203. code1 -= 257;
  25204. code1 = lengthDecode[code1];
  25205. var code2 = code1 >> 16;
  25206. if (code2 > 0) {
  25207. code2 = this.getBits(code2);
  25208. }
  25209. len = (code1 & 0xffff) + code2;
  25210. code1 = this.getCode(distCodeTable);
  25211. code1 = distDecode[code1];
  25212. code2 = code1 >> 16;
  25213. if (code2 > 0) {
  25214. code2 = this.getBits(code2);
  25215. }
  25216. var dist = (code1 & 0xffff) + code2;
  25217. if (pos + len >= limit) {
  25218. buffer = this.ensureBuffer(pos + len);
  25219. limit = buffer.length;
  25220. }
  25221. for (var k = 0; k < len; ++k, ++pos) {
  25222. buffer[pos] = buffer[pos - dist];
  25223. }
  25224. }
  25225. };
  25226. return FlateStream;
  25227. }();
  25228. var PredictorStream = function PredictorStreamClosure() {
  25229. function PredictorStream(str, maybeLength, params) {
  25230. if (!isDict(params)) {
  25231. return str;
  25232. }
  25233. // no prediction
  25234. var predictor = this.predictor = params.get('Predictor') || 1;
  25235. if (predictor <= 1) {
  25236. return str;
  25237. }
  25238. // no prediction
  25239. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  25240. error('Unsupported predictor: ' + predictor);
  25241. }
  25242. if (predictor === 2) {
  25243. this.readBlock = this.readBlockTiff;
  25244. } else {
  25245. this.readBlock = this.readBlockPng;
  25246. }
  25247. this.str = str;
  25248. this.dict = str.dict;
  25249. var colors = this.colors = params.get('Colors') || 1;
  25250. var bits = this.bits = params.get('BitsPerComponent') || 8;
  25251. var columns = this.columns = params.get('Columns') || 1;
  25252. this.pixBytes = colors * bits + 7 >> 3;
  25253. this.rowBytes = columns * colors * bits + 7 >> 3;
  25254. DecodeStream.call(this, maybeLength);
  25255. return this;
  25256. }
  25257. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  25258. PredictorStream.prototype.readBlockTiff = function predictorStreamReadBlockTiff() {
  25259. var rowBytes = this.rowBytes;
  25260. var bufferLength = this.bufferLength;
  25261. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  25262. var bits = this.bits;
  25263. var colors = this.colors;
  25264. var rawBytes = this.str.getBytes(rowBytes);
  25265. this.eof = !rawBytes.length;
  25266. if (this.eof) {
  25267. return;
  25268. }
  25269. var inbuf = 0, outbuf = 0;
  25270. var inbits = 0, outbits = 0;
  25271. var pos = bufferLength;
  25272. var i;
  25273. if (bits === 1) {
  25274. for (i = 0; i < rowBytes; ++i) {
  25275. var c = rawBytes[i];
  25276. inbuf = inbuf << 8 | c;
  25277. // bitwise addition is exclusive or
  25278. // first shift inbuf and then add
  25279. buffer[pos++] = (c ^ inbuf >> colors) & 0xFF;
  25280. // truncate inbuf (assumes colors < 16)
  25281. inbuf &= 0xFFFF;
  25282. }
  25283. } else if (bits === 8) {
  25284. for (i = 0; i < colors; ++i) {
  25285. buffer[pos++] = rawBytes[i];
  25286. }
  25287. for (; i < rowBytes; ++i) {
  25288. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  25289. pos++;
  25290. }
  25291. } else {
  25292. var compArray = new Uint8Array(colors + 1);
  25293. var bitMask = (1 << bits) - 1;
  25294. var j = 0, k = bufferLength;
  25295. var columns = this.columns;
  25296. for (i = 0; i < columns; ++i) {
  25297. for (var kk = 0; kk < colors; ++kk) {
  25298. if (inbits < bits) {
  25299. inbuf = inbuf << 8 | rawBytes[j++] & 0xFF;
  25300. inbits += 8;
  25301. }
  25302. compArray[kk] = compArray[kk] + (inbuf >> inbits - bits) & bitMask;
  25303. inbits -= bits;
  25304. outbuf = outbuf << bits | compArray[kk];
  25305. outbits += bits;
  25306. if (outbits >= 8) {
  25307. buffer[k++] = outbuf >> outbits - 8 & 0xFF;
  25308. outbits -= 8;
  25309. }
  25310. }
  25311. }
  25312. if (outbits > 0) {
  25313. buffer[k++] = (outbuf << 8 - outbits) + (inbuf & (1 << 8 - outbits) - 1);
  25314. }
  25315. }
  25316. this.bufferLength += rowBytes;
  25317. };
  25318. PredictorStream.prototype.readBlockPng = function predictorStreamReadBlockPng() {
  25319. var rowBytes = this.rowBytes;
  25320. var pixBytes = this.pixBytes;
  25321. var predictor = this.str.getByte();
  25322. var rawBytes = this.str.getBytes(rowBytes);
  25323. this.eof = !rawBytes.length;
  25324. if (this.eof) {
  25325. return;
  25326. }
  25327. var bufferLength = this.bufferLength;
  25328. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  25329. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  25330. if (prevRow.length === 0) {
  25331. prevRow = new Uint8Array(rowBytes);
  25332. }
  25333. var i, j = bufferLength, up, c;
  25334. switch (predictor) {
  25335. case 0:
  25336. for (i = 0; i < rowBytes; ++i) {
  25337. buffer[j++] = rawBytes[i];
  25338. }
  25339. break;
  25340. case 1:
  25341. for (i = 0; i < pixBytes; ++i) {
  25342. buffer[j++] = rawBytes[i];
  25343. }
  25344. for (; i < rowBytes; ++i) {
  25345. buffer[j] = buffer[j - pixBytes] + rawBytes[i] & 0xFF;
  25346. j++;
  25347. }
  25348. break;
  25349. case 2:
  25350. for (i = 0; i < rowBytes; ++i) {
  25351. buffer[j++] = prevRow[i] + rawBytes[i] & 0xFF;
  25352. }
  25353. break;
  25354. case 3:
  25355. for (i = 0; i < pixBytes; ++i) {
  25356. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  25357. }
  25358. for (; i < rowBytes; ++i) {
  25359. buffer[j] = (prevRow[i] + buffer[j - pixBytes] >> 1) + rawBytes[i] & 0xFF;
  25360. j++;
  25361. }
  25362. break;
  25363. case 4:
  25364. // we need to save the up left pixels values. the simplest way
  25365. // is to create a new buffer
  25366. for (i = 0; i < pixBytes; ++i) {
  25367. up = prevRow[i];
  25368. c = rawBytes[i];
  25369. buffer[j++] = up + c;
  25370. }
  25371. for (; i < rowBytes; ++i) {
  25372. up = prevRow[i];
  25373. var upLeft = prevRow[i - pixBytes];
  25374. var left = buffer[j - pixBytes];
  25375. var p = left + up - upLeft;
  25376. var pa = p - left;
  25377. if (pa < 0) {
  25378. pa = -pa;
  25379. }
  25380. var pb = p - up;
  25381. if (pb < 0) {
  25382. pb = -pb;
  25383. }
  25384. var pc = p - upLeft;
  25385. if (pc < 0) {
  25386. pc = -pc;
  25387. }
  25388. c = rawBytes[i];
  25389. if (pa <= pb && pa <= pc) {
  25390. buffer[j++] = left + c;
  25391. } else if (pb <= pc) {
  25392. buffer[j++] = up + c;
  25393. } else {
  25394. buffer[j++] = upLeft + c;
  25395. }
  25396. }
  25397. break;
  25398. default:
  25399. error('Unsupported predictor: ' + predictor);
  25400. }
  25401. this.bufferLength += rowBytes;
  25402. };
  25403. return PredictorStream;
  25404. }();
  25405. /**
  25406. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  25407. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  25408. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  25409. * a library to decode these images and the stream behaves like all the other
  25410. * DecodeStreams.
  25411. */
  25412. var JpegStream = function JpegStreamClosure() {
  25413. function JpegStream(stream, maybeLength, dict) {
  25414. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  25415. // Note: this seems to mainly affect inline images.
  25416. var ch;
  25417. while ((ch = stream.getByte()) !== -1) {
  25418. if (ch === 0xFF) {
  25419. // Find the first byte of the SOI marker (0xFFD8).
  25420. stream.skip(-1);
  25421. // Reset the stream position to the SOI.
  25422. break;
  25423. }
  25424. }
  25425. this.stream = stream;
  25426. this.maybeLength = maybeLength;
  25427. this.dict = dict;
  25428. DecodeStream.call(this, maybeLength);
  25429. }
  25430. JpegStream.prototype = Object.create(DecodeStream.prototype);
  25431. Object.defineProperty(JpegStream.prototype, 'bytes', {
  25432. get: function JpegStream_bytes() {
  25433. // If this.maybeLength is null, we'll get the entire stream.
  25434. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  25435. },
  25436. configurable: true
  25437. });
  25438. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  25439. if (this.bufferLength) {
  25440. return;
  25441. }
  25442. var jpegImage = new JpegImage();
  25443. // Checking if values need to be transformed before conversion.
  25444. var decodeArr = this.dict.getArray('Decode', 'D');
  25445. if (this.forceRGB && isArray(decodeArr)) {
  25446. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  25447. var decodeArrLength = decodeArr.length;
  25448. var transform = new Int32Array(decodeArrLength);
  25449. var transformNeeded = false;
  25450. var maxValue = (1 << bitsPerComponent) - 1;
  25451. for (var i = 0; i < decodeArrLength; i += 2) {
  25452. transform[i] = (decodeArr[i + 1] - decodeArr[i]) * 256 | 0;
  25453. transform[i + 1] = decodeArr[i] * maxValue | 0;
  25454. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  25455. transformNeeded = true;
  25456. }
  25457. }
  25458. if (transformNeeded) {
  25459. jpegImage.decodeTransform = transform;
  25460. }
  25461. }
  25462. // Fetching the 'ColorTransform' entry, if it exists.
  25463. var decodeParams = this.dict.get('DecodeParms', 'DP');
  25464. if (isDict(decodeParams)) {
  25465. var colorTransform = decodeParams.get('ColorTransform');
  25466. if (isInt(colorTransform)) {
  25467. jpegImage.colorTransform = colorTransform;
  25468. }
  25469. }
  25470. jpegImage.parse(this.bytes);
  25471. var data = jpegImage.getData(this.drawWidth, this.drawHeight, this.forceRGB);
  25472. this.buffer = data;
  25473. this.bufferLength = data.length;
  25474. this.eof = true;
  25475. };
  25476. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  25477. this.ensureBuffer();
  25478. return this.buffer;
  25479. };
  25480. JpegStream.prototype.getIR = function JpegStream_getIR(forceDataSchema) {
  25481. return createObjectURL(this.bytes, 'image/jpeg', forceDataSchema);
  25482. };
  25483. return JpegStream;
  25484. }();
  25485. /**
  25486. * For JPEG 2000's we use a library to decode these images and
  25487. * the stream behaves like all the other DecodeStreams.
  25488. */
  25489. var JpxStream = function JpxStreamClosure() {
  25490. function JpxStream(stream, maybeLength, dict) {
  25491. this.stream = stream;
  25492. this.maybeLength = maybeLength;
  25493. this.dict = dict;
  25494. DecodeStream.call(this, maybeLength);
  25495. }
  25496. JpxStream.prototype = Object.create(DecodeStream.prototype);
  25497. Object.defineProperty(JpxStream.prototype, 'bytes', {
  25498. get: function JpxStream_bytes() {
  25499. // If this.maybeLength is null, we'll get the entire stream.
  25500. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  25501. },
  25502. configurable: true
  25503. });
  25504. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  25505. if (this.bufferLength) {
  25506. return;
  25507. }
  25508. var jpxImage = new JpxImage();
  25509. jpxImage.parse(this.bytes);
  25510. var width = jpxImage.width;
  25511. var height = jpxImage.height;
  25512. var componentsCount = jpxImage.componentsCount;
  25513. var tileCount = jpxImage.tiles.length;
  25514. if (tileCount === 1) {
  25515. this.buffer = jpxImage.tiles[0].items;
  25516. } else {
  25517. var data = new Uint8Array(width * height * componentsCount);
  25518. for (var k = 0; k < tileCount; k++) {
  25519. var tileComponents = jpxImage.tiles[k];
  25520. var tileWidth = tileComponents.width;
  25521. var tileHeight = tileComponents.height;
  25522. var tileLeft = tileComponents.left;
  25523. var tileTop = tileComponents.top;
  25524. var src = tileComponents.items;
  25525. var srcPosition = 0;
  25526. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  25527. var imgRowSize = width * componentsCount;
  25528. var tileRowSize = tileWidth * componentsCount;
  25529. for (var j = 0; j < tileHeight; j++) {
  25530. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  25531. data.set(rowBytes, dataPosition);
  25532. srcPosition += tileRowSize;
  25533. dataPosition += imgRowSize;
  25534. }
  25535. }
  25536. this.buffer = data;
  25537. }
  25538. this.bufferLength = this.buffer.length;
  25539. this.eof = true;
  25540. };
  25541. return JpxStream;
  25542. }();
  25543. /**
  25544. * For JBIG2's we use a library to decode these images and
  25545. * the stream behaves like all the other DecodeStreams.
  25546. */
  25547. var Jbig2Stream = function Jbig2StreamClosure() {
  25548. function Jbig2Stream(stream, maybeLength, dict) {
  25549. this.stream = stream;
  25550. this.maybeLength = maybeLength;
  25551. this.dict = dict;
  25552. DecodeStream.call(this, maybeLength);
  25553. }
  25554. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  25555. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  25556. get: function Jbig2Stream_bytes() {
  25557. // If this.maybeLength is null, we'll get the entire stream.
  25558. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  25559. },
  25560. configurable: true
  25561. });
  25562. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  25563. if (this.bufferLength) {
  25564. return;
  25565. }
  25566. var jbig2Image = new Jbig2Image();
  25567. var chunks = [];
  25568. var decodeParams = this.dict.getArray('DecodeParms', 'DP');
  25569. // According to the PDF specification, DecodeParms can be either
  25570. // a dictionary, or an array whose elements are dictionaries.
  25571. if (isArray(decodeParams)) {
  25572. if (decodeParams.length > 1) {
  25573. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' + 'not supported.');
  25574. }
  25575. decodeParams = decodeParams[0];
  25576. }
  25577. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  25578. var globalsStream = decodeParams.get('JBIG2Globals');
  25579. var globals = globalsStream.getBytes();
  25580. chunks.push({
  25581. data: globals,
  25582. start: 0,
  25583. end: globals.length
  25584. });
  25585. }
  25586. chunks.push({
  25587. data: this.bytes,
  25588. start: 0,
  25589. end: this.bytes.length
  25590. });
  25591. var data = jbig2Image.parseChunks(chunks);
  25592. var dataLength = data.length;
  25593. // JBIG2 had black as 1 and white as 0, inverting the colors
  25594. for (var i = 0; i < dataLength; i++) {
  25595. data[i] ^= 0xFF;
  25596. }
  25597. this.buffer = data;
  25598. this.bufferLength = dataLength;
  25599. this.eof = true;
  25600. };
  25601. return Jbig2Stream;
  25602. }();
  25603. var DecryptStream = function DecryptStreamClosure() {
  25604. function DecryptStream(str, maybeLength, decrypt) {
  25605. this.str = str;
  25606. this.dict = str.dict;
  25607. this.decrypt = decrypt;
  25608. this.nextChunk = null;
  25609. this.initialized = false;
  25610. DecodeStream.call(this, maybeLength);
  25611. }
  25612. var chunkSize = 512;
  25613. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  25614. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  25615. var chunk;
  25616. if (this.initialized) {
  25617. chunk = this.nextChunk;
  25618. } else {
  25619. chunk = this.str.getBytes(chunkSize);
  25620. this.initialized = true;
  25621. }
  25622. if (!chunk || chunk.length === 0) {
  25623. this.eof = true;
  25624. return;
  25625. }
  25626. this.nextChunk = this.str.getBytes(chunkSize);
  25627. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  25628. var decrypt = this.decrypt;
  25629. chunk = decrypt(chunk, !hasMoreData);
  25630. var bufferLength = this.bufferLength;
  25631. var i, n = chunk.length;
  25632. var buffer = this.ensureBuffer(bufferLength + n);
  25633. for (i = 0; i < n; i++) {
  25634. buffer[bufferLength++] = chunk[i];
  25635. }
  25636. this.bufferLength = bufferLength;
  25637. };
  25638. return DecryptStream;
  25639. }();
  25640. var Ascii85Stream = function Ascii85StreamClosure() {
  25641. function Ascii85Stream(str, maybeLength) {
  25642. this.str = str;
  25643. this.dict = str.dict;
  25644. this.input = new Uint8Array(5);
  25645. // Most streams increase in size when decoded, but Ascii85 streams
  25646. // typically shrink by ~20%.
  25647. if (maybeLength) {
  25648. maybeLength = 0.8 * maybeLength;
  25649. }
  25650. DecodeStream.call(this, maybeLength);
  25651. }
  25652. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  25653. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  25654. var TILDA_CHAR = 0x7E;
  25655. // '~'
  25656. var Z_LOWER_CHAR = 0x7A;
  25657. // 'z'
  25658. var EOF = -1;
  25659. var str = this.str;
  25660. var c = str.getByte();
  25661. while (isSpace(c)) {
  25662. c = str.getByte();
  25663. }
  25664. if (c === EOF || c === TILDA_CHAR) {
  25665. this.eof = true;
  25666. return;
  25667. }
  25668. var bufferLength = this.bufferLength, buffer;
  25669. var i;
  25670. // special code for z
  25671. if (c === Z_LOWER_CHAR) {
  25672. buffer = this.ensureBuffer(bufferLength + 4);
  25673. for (i = 0; i < 4; ++i) {
  25674. buffer[bufferLength + i] = 0;
  25675. }
  25676. this.bufferLength += 4;
  25677. } else {
  25678. var input = this.input;
  25679. input[0] = c;
  25680. for (i = 1; i < 5; ++i) {
  25681. c = str.getByte();
  25682. while (isSpace(c)) {
  25683. c = str.getByte();
  25684. }
  25685. input[i] = c;
  25686. if (c === EOF || c === TILDA_CHAR) {
  25687. break;
  25688. }
  25689. }
  25690. buffer = this.ensureBuffer(bufferLength + i - 1);
  25691. this.bufferLength += i - 1;
  25692. // partial ending;
  25693. if (i < 5) {
  25694. for (; i < 5; ++i) {
  25695. input[i] = 0x21 + 84;
  25696. }
  25697. this.eof = true;
  25698. }
  25699. var t = 0;
  25700. for (i = 0; i < 5; ++i) {
  25701. t = t * 85 + (input[i] - 0x21);
  25702. }
  25703. for (i = 3; i >= 0; --i) {
  25704. buffer[bufferLength + i] = t & 0xFF;
  25705. t >>= 8;
  25706. }
  25707. }
  25708. };
  25709. return Ascii85Stream;
  25710. }();
  25711. var AsciiHexStream = function AsciiHexStreamClosure() {
  25712. function AsciiHexStream(str, maybeLength) {
  25713. this.str = str;
  25714. this.dict = str.dict;
  25715. this.firstDigit = -1;
  25716. // Most streams increase in size when decoded, but AsciiHex streams shrink
  25717. // by 50%.
  25718. if (maybeLength) {
  25719. maybeLength = 0.5 * maybeLength;
  25720. }
  25721. DecodeStream.call(this, maybeLength);
  25722. }
  25723. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  25724. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  25725. var UPSTREAM_BLOCK_SIZE = 8000;
  25726. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  25727. if (!bytes.length) {
  25728. this.eof = true;
  25729. return;
  25730. }
  25731. var maxDecodeLength = bytes.length + 1 >> 1;
  25732. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  25733. var bufferLength = this.bufferLength;
  25734. var firstDigit = this.firstDigit;
  25735. for (var i = 0, ii = bytes.length; i < ii; i++) {
  25736. var ch = bytes[i], digit;
  25737. if (ch >= 0x30 && ch <= 0x39) {
  25738. // '0'-'9'
  25739. digit = ch & 0x0F;
  25740. } else if (ch >= 0x41 && ch <= 0x46 || ch >= 0x61 && ch <= 0x66) {
  25741. // 'A'-'Z', 'a'-'z'
  25742. digit = (ch & 0x0F) + 9;
  25743. } else if (ch === 0x3E) {
  25744. // '>'
  25745. this.eof = true;
  25746. break;
  25747. } else {
  25748. // probably whitespace
  25749. continue;
  25750. }
  25751. // ignoring
  25752. if (firstDigit < 0) {
  25753. firstDigit = digit;
  25754. } else {
  25755. buffer[bufferLength++] = firstDigit << 4 | digit;
  25756. firstDigit = -1;
  25757. }
  25758. }
  25759. if (firstDigit >= 0 && this.eof) {
  25760. // incomplete byte
  25761. buffer[bufferLength++] = firstDigit << 4;
  25762. firstDigit = -1;
  25763. }
  25764. this.firstDigit = firstDigit;
  25765. this.bufferLength = bufferLength;
  25766. };
  25767. return AsciiHexStream;
  25768. }();
  25769. var RunLengthStream = function RunLengthStreamClosure() {
  25770. function RunLengthStream(str, maybeLength) {
  25771. this.str = str;
  25772. this.dict = str.dict;
  25773. DecodeStream.call(this, maybeLength);
  25774. }
  25775. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  25776. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  25777. // The repeatHeader has following format. The first byte defines type of run
  25778. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  25779. // (in addition to the second byte from the header), n = 129 through 255 -
  25780. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  25781. var repeatHeader = this.str.getBytes(2);
  25782. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  25783. this.eof = true;
  25784. return;
  25785. }
  25786. var buffer;
  25787. var bufferLength = this.bufferLength;
  25788. var n = repeatHeader[0];
  25789. if (n < 128) {
  25790. // copy n bytes
  25791. buffer = this.ensureBuffer(bufferLength + n + 1);
  25792. buffer[bufferLength++] = repeatHeader[1];
  25793. if (n > 0) {
  25794. var source = this.str.getBytes(n);
  25795. buffer.set(source, bufferLength);
  25796. bufferLength += n;
  25797. }
  25798. } else {
  25799. n = 257 - n;
  25800. var b = repeatHeader[1];
  25801. buffer = this.ensureBuffer(bufferLength + n + 1);
  25802. for (var i = 0; i < n; i++) {
  25803. buffer[bufferLength++] = b;
  25804. }
  25805. }
  25806. this.bufferLength = bufferLength;
  25807. };
  25808. return RunLengthStream;
  25809. }();
  25810. var CCITTFaxStream = function CCITTFaxStreamClosure() {
  25811. var ccittEOL = -2;
  25812. var ccittEOF = -1;
  25813. var twoDimPass = 0;
  25814. var twoDimHoriz = 1;
  25815. var twoDimVert0 = 2;
  25816. var twoDimVertR1 = 3;
  25817. var twoDimVertL1 = 4;
  25818. var twoDimVertR2 = 5;
  25819. var twoDimVertL2 = 6;
  25820. var twoDimVertR3 = 7;
  25821. var twoDimVertL3 = 8;
  25822. var twoDimTable = [
  25823. [
  25824. -1,
  25825. -1
  25826. ],
  25827. [
  25828. -1,
  25829. -1
  25830. ],
  25831. // 000000x
  25832. [
  25833. 7,
  25834. twoDimVertL3
  25835. ],
  25836. // 0000010
  25837. [
  25838. 7,
  25839. twoDimVertR3
  25840. ],
  25841. // 0000011
  25842. [
  25843. 6,
  25844. twoDimVertL2
  25845. ],
  25846. [
  25847. 6,
  25848. twoDimVertL2
  25849. ],
  25850. // 000010x
  25851. [
  25852. 6,
  25853. twoDimVertR2
  25854. ],
  25855. [
  25856. 6,
  25857. twoDimVertR2
  25858. ],
  25859. // 000011x
  25860. [
  25861. 4,
  25862. twoDimPass
  25863. ],
  25864. [
  25865. 4,
  25866. twoDimPass
  25867. ],
  25868. // 0001xxx
  25869. [
  25870. 4,
  25871. twoDimPass
  25872. ],
  25873. [
  25874. 4,
  25875. twoDimPass
  25876. ],
  25877. [
  25878. 4,
  25879. twoDimPass
  25880. ],
  25881. [
  25882. 4,
  25883. twoDimPass
  25884. ],
  25885. [
  25886. 4,
  25887. twoDimPass
  25888. ],
  25889. [
  25890. 4,
  25891. twoDimPass
  25892. ],
  25893. [
  25894. 3,
  25895. twoDimHoriz
  25896. ],
  25897. [
  25898. 3,
  25899. twoDimHoriz
  25900. ],
  25901. // 001xxxx
  25902. [
  25903. 3,
  25904. twoDimHoriz
  25905. ],
  25906. [
  25907. 3,
  25908. twoDimHoriz
  25909. ],
  25910. [
  25911. 3,
  25912. twoDimHoriz
  25913. ],
  25914. [
  25915. 3,
  25916. twoDimHoriz
  25917. ],
  25918. [
  25919. 3,
  25920. twoDimHoriz
  25921. ],
  25922. [
  25923. 3,
  25924. twoDimHoriz
  25925. ],
  25926. [
  25927. 3,
  25928. twoDimHoriz
  25929. ],
  25930. [
  25931. 3,
  25932. twoDimHoriz
  25933. ],
  25934. [
  25935. 3,
  25936. twoDimHoriz
  25937. ],
  25938. [
  25939. 3,
  25940. twoDimHoriz
  25941. ],
  25942. [
  25943. 3,
  25944. twoDimHoriz
  25945. ],
  25946. [
  25947. 3,
  25948. twoDimHoriz
  25949. ],
  25950. [
  25951. 3,
  25952. twoDimHoriz
  25953. ],
  25954. [
  25955. 3,
  25956. twoDimHoriz
  25957. ],
  25958. [
  25959. 3,
  25960. twoDimVertL1
  25961. ],
  25962. [
  25963. 3,
  25964. twoDimVertL1
  25965. ],
  25966. // 010xxxx
  25967. [
  25968. 3,
  25969. twoDimVertL1
  25970. ],
  25971. [
  25972. 3,
  25973. twoDimVertL1
  25974. ],
  25975. [
  25976. 3,
  25977. twoDimVertL1
  25978. ],
  25979. [
  25980. 3,
  25981. twoDimVertL1
  25982. ],
  25983. [
  25984. 3,
  25985. twoDimVertL1
  25986. ],
  25987. [
  25988. 3,
  25989. twoDimVertL1
  25990. ],
  25991. [
  25992. 3,
  25993. twoDimVertL1
  25994. ],
  25995. [
  25996. 3,
  25997. twoDimVertL1
  25998. ],
  25999. [
  26000. 3,
  26001. twoDimVertL1
  26002. ],
  26003. [
  26004. 3,
  26005. twoDimVertL1
  26006. ],
  26007. [
  26008. 3,
  26009. twoDimVertL1
  26010. ],
  26011. [
  26012. 3,
  26013. twoDimVertL1
  26014. ],
  26015. [
  26016. 3,
  26017. twoDimVertL1
  26018. ],
  26019. [
  26020. 3,
  26021. twoDimVertL1
  26022. ],
  26023. [
  26024. 3,
  26025. twoDimVertR1
  26026. ],
  26027. [
  26028. 3,
  26029. twoDimVertR1
  26030. ],
  26031. // 011xxxx
  26032. [
  26033. 3,
  26034. twoDimVertR1
  26035. ],
  26036. [
  26037. 3,
  26038. twoDimVertR1
  26039. ],
  26040. [
  26041. 3,
  26042. twoDimVertR1
  26043. ],
  26044. [
  26045. 3,
  26046. twoDimVertR1
  26047. ],
  26048. [
  26049. 3,
  26050. twoDimVertR1
  26051. ],
  26052. [
  26053. 3,
  26054. twoDimVertR1
  26055. ],
  26056. [
  26057. 3,
  26058. twoDimVertR1
  26059. ],
  26060. [
  26061. 3,
  26062. twoDimVertR1
  26063. ],
  26064. [
  26065. 3,
  26066. twoDimVertR1
  26067. ],
  26068. [
  26069. 3,
  26070. twoDimVertR1
  26071. ],
  26072. [
  26073. 3,
  26074. twoDimVertR1
  26075. ],
  26076. [
  26077. 3,
  26078. twoDimVertR1
  26079. ],
  26080. [
  26081. 3,
  26082. twoDimVertR1
  26083. ],
  26084. [
  26085. 3,
  26086. twoDimVertR1
  26087. ],
  26088. [
  26089. 1,
  26090. twoDimVert0
  26091. ],
  26092. [
  26093. 1,
  26094. twoDimVert0
  26095. ],
  26096. // 1xxxxxx
  26097. [
  26098. 1,
  26099. twoDimVert0
  26100. ],
  26101. [
  26102. 1,
  26103. twoDimVert0
  26104. ],
  26105. [
  26106. 1,
  26107. twoDimVert0
  26108. ],
  26109. [
  26110. 1,
  26111. twoDimVert0
  26112. ],
  26113. [
  26114. 1,
  26115. twoDimVert0
  26116. ],
  26117. [
  26118. 1,
  26119. twoDimVert0
  26120. ],
  26121. [
  26122. 1,
  26123. twoDimVert0
  26124. ],
  26125. [
  26126. 1,
  26127. twoDimVert0
  26128. ],
  26129. [
  26130. 1,
  26131. twoDimVert0
  26132. ],
  26133. [
  26134. 1,
  26135. twoDimVert0
  26136. ],
  26137. [
  26138. 1,
  26139. twoDimVert0
  26140. ],
  26141. [
  26142. 1,
  26143. twoDimVert0
  26144. ],
  26145. [
  26146. 1,
  26147. twoDimVert0
  26148. ],
  26149. [
  26150. 1,
  26151. twoDimVert0
  26152. ],
  26153. [
  26154. 1,
  26155. twoDimVert0
  26156. ],
  26157. [
  26158. 1,
  26159. twoDimVert0
  26160. ],
  26161. [
  26162. 1,
  26163. twoDimVert0
  26164. ],
  26165. [
  26166. 1,
  26167. twoDimVert0
  26168. ],
  26169. [
  26170. 1,
  26171. twoDimVert0
  26172. ],
  26173. [
  26174. 1,
  26175. twoDimVert0
  26176. ],
  26177. [
  26178. 1,
  26179. twoDimVert0
  26180. ],
  26181. [
  26182. 1,
  26183. twoDimVert0
  26184. ],
  26185. [
  26186. 1,
  26187. twoDimVert0
  26188. ],
  26189. [
  26190. 1,
  26191. twoDimVert0
  26192. ],
  26193. [
  26194. 1,
  26195. twoDimVert0
  26196. ],
  26197. [
  26198. 1,
  26199. twoDimVert0
  26200. ],
  26201. [
  26202. 1,
  26203. twoDimVert0
  26204. ],
  26205. [
  26206. 1,
  26207. twoDimVert0
  26208. ],
  26209. [
  26210. 1,
  26211. twoDimVert0
  26212. ],
  26213. [
  26214. 1,
  26215. twoDimVert0
  26216. ],
  26217. [
  26218. 1,
  26219. twoDimVert0
  26220. ],
  26221. [
  26222. 1,
  26223. twoDimVert0
  26224. ],
  26225. [
  26226. 1,
  26227. twoDimVert0
  26228. ],
  26229. [
  26230. 1,
  26231. twoDimVert0
  26232. ],
  26233. [
  26234. 1,
  26235. twoDimVert0
  26236. ],
  26237. [
  26238. 1,
  26239. twoDimVert0
  26240. ],
  26241. [
  26242. 1,
  26243. twoDimVert0
  26244. ],
  26245. [
  26246. 1,
  26247. twoDimVert0
  26248. ],
  26249. [
  26250. 1,
  26251. twoDimVert0
  26252. ],
  26253. [
  26254. 1,
  26255. twoDimVert0
  26256. ],
  26257. [
  26258. 1,
  26259. twoDimVert0
  26260. ],
  26261. [
  26262. 1,
  26263. twoDimVert0
  26264. ],
  26265. [
  26266. 1,
  26267. twoDimVert0
  26268. ],
  26269. [
  26270. 1,
  26271. twoDimVert0
  26272. ],
  26273. [
  26274. 1,
  26275. twoDimVert0
  26276. ],
  26277. [
  26278. 1,
  26279. twoDimVert0
  26280. ],
  26281. [
  26282. 1,
  26283. twoDimVert0
  26284. ],
  26285. [
  26286. 1,
  26287. twoDimVert0
  26288. ],
  26289. [
  26290. 1,
  26291. twoDimVert0
  26292. ],
  26293. [
  26294. 1,
  26295. twoDimVert0
  26296. ],
  26297. [
  26298. 1,
  26299. twoDimVert0
  26300. ],
  26301. [
  26302. 1,
  26303. twoDimVert0
  26304. ],
  26305. [
  26306. 1,
  26307. twoDimVert0
  26308. ],
  26309. [
  26310. 1,
  26311. twoDimVert0
  26312. ],
  26313. [
  26314. 1,
  26315. twoDimVert0
  26316. ],
  26317. [
  26318. 1,
  26319. twoDimVert0
  26320. ],
  26321. [
  26322. 1,
  26323. twoDimVert0
  26324. ],
  26325. [
  26326. 1,
  26327. twoDimVert0
  26328. ],
  26329. [
  26330. 1,
  26331. twoDimVert0
  26332. ],
  26333. [
  26334. 1,
  26335. twoDimVert0
  26336. ],
  26337. [
  26338. 1,
  26339. twoDimVert0
  26340. ],
  26341. [
  26342. 1,
  26343. twoDimVert0
  26344. ]
  26345. ];
  26346. var whiteTable1 = [
  26347. [
  26348. -1,
  26349. -1
  26350. ],
  26351. // 00000
  26352. [
  26353. 12,
  26354. ccittEOL
  26355. ],
  26356. // 00001
  26357. [
  26358. -1,
  26359. -1
  26360. ],
  26361. [
  26362. -1,
  26363. -1
  26364. ],
  26365. // 0001x
  26366. [
  26367. -1,
  26368. -1
  26369. ],
  26370. [
  26371. -1,
  26372. -1
  26373. ],
  26374. [
  26375. -1,
  26376. -1
  26377. ],
  26378. [
  26379. -1,
  26380. -1
  26381. ],
  26382. // 001xx
  26383. [
  26384. -1,
  26385. -1
  26386. ],
  26387. [
  26388. -1,
  26389. -1
  26390. ],
  26391. [
  26392. -1,
  26393. -1
  26394. ],
  26395. [
  26396. -1,
  26397. -1
  26398. ],
  26399. // 010xx
  26400. [
  26401. -1,
  26402. -1
  26403. ],
  26404. [
  26405. -1,
  26406. -1
  26407. ],
  26408. [
  26409. -1,
  26410. -1
  26411. ],
  26412. [
  26413. -1,
  26414. -1
  26415. ],
  26416. // 011xx
  26417. [
  26418. 11,
  26419. 1792
  26420. ],
  26421. [
  26422. 11,
  26423. 1792
  26424. ],
  26425. // 1000x
  26426. [
  26427. 12,
  26428. 1984
  26429. ],
  26430. // 10010
  26431. [
  26432. 12,
  26433. 2048
  26434. ],
  26435. // 10011
  26436. [
  26437. 12,
  26438. 2112
  26439. ],
  26440. // 10100
  26441. [
  26442. 12,
  26443. 2176
  26444. ],
  26445. // 10101
  26446. [
  26447. 12,
  26448. 2240
  26449. ],
  26450. // 10110
  26451. [
  26452. 12,
  26453. 2304
  26454. ],
  26455. // 10111
  26456. [
  26457. 11,
  26458. 1856
  26459. ],
  26460. [
  26461. 11,
  26462. 1856
  26463. ],
  26464. // 1100x
  26465. [
  26466. 11,
  26467. 1920
  26468. ],
  26469. [
  26470. 11,
  26471. 1920
  26472. ],
  26473. // 1101x
  26474. [
  26475. 12,
  26476. 2368
  26477. ],
  26478. // 11100
  26479. [
  26480. 12,
  26481. 2432
  26482. ],
  26483. // 11101
  26484. [
  26485. 12,
  26486. 2496
  26487. ],
  26488. // 11110
  26489. [
  26490. 12,
  26491. 2560
  26492. ]
  26493. ];
  26494. // 11111
  26495. var whiteTable2 = [
  26496. [
  26497. -1,
  26498. -1
  26499. ],
  26500. [
  26501. -1,
  26502. -1
  26503. ],
  26504. [
  26505. -1,
  26506. -1
  26507. ],
  26508. [
  26509. -1,
  26510. -1
  26511. ],
  26512. // 0000000xx
  26513. [
  26514. 8,
  26515. 29
  26516. ],
  26517. [
  26518. 8,
  26519. 29
  26520. ],
  26521. // 00000010x
  26522. [
  26523. 8,
  26524. 30
  26525. ],
  26526. [
  26527. 8,
  26528. 30
  26529. ],
  26530. // 00000011x
  26531. [
  26532. 8,
  26533. 45
  26534. ],
  26535. [
  26536. 8,
  26537. 45
  26538. ],
  26539. // 00000100x
  26540. [
  26541. 8,
  26542. 46
  26543. ],
  26544. [
  26545. 8,
  26546. 46
  26547. ],
  26548. // 00000101x
  26549. [
  26550. 7,
  26551. 22
  26552. ],
  26553. [
  26554. 7,
  26555. 22
  26556. ],
  26557. [
  26558. 7,
  26559. 22
  26560. ],
  26561. [
  26562. 7,
  26563. 22
  26564. ],
  26565. // 0000011xx
  26566. [
  26567. 7,
  26568. 23
  26569. ],
  26570. [
  26571. 7,
  26572. 23
  26573. ],
  26574. [
  26575. 7,
  26576. 23
  26577. ],
  26578. [
  26579. 7,
  26580. 23
  26581. ],
  26582. // 0000100xx
  26583. [
  26584. 8,
  26585. 47
  26586. ],
  26587. [
  26588. 8,
  26589. 47
  26590. ],
  26591. // 00001010x
  26592. [
  26593. 8,
  26594. 48
  26595. ],
  26596. [
  26597. 8,
  26598. 48
  26599. ],
  26600. // 00001011x
  26601. [
  26602. 6,
  26603. 13
  26604. ],
  26605. [
  26606. 6,
  26607. 13
  26608. ],
  26609. [
  26610. 6,
  26611. 13
  26612. ],
  26613. [
  26614. 6,
  26615. 13
  26616. ],
  26617. // 000011xxx
  26618. [
  26619. 6,
  26620. 13
  26621. ],
  26622. [
  26623. 6,
  26624. 13
  26625. ],
  26626. [
  26627. 6,
  26628. 13
  26629. ],
  26630. [
  26631. 6,
  26632. 13
  26633. ],
  26634. [
  26635. 7,
  26636. 20
  26637. ],
  26638. [
  26639. 7,
  26640. 20
  26641. ],
  26642. [
  26643. 7,
  26644. 20
  26645. ],
  26646. [
  26647. 7,
  26648. 20
  26649. ],
  26650. // 0001000xx
  26651. [
  26652. 8,
  26653. 33
  26654. ],
  26655. [
  26656. 8,
  26657. 33
  26658. ],
  26659. // 00010010x
  26660. [
  26661. 8,
  26662. 34
  26663. ],
  26664. [
  26665. 8,
  26666. 34
  26667. ],
  26668. // 00010011x
  26669. [
  26670. 8,
  26671. 35
  26672. ],
  26673. [
  26674. 8,
  26675. 35
  26676. ],
  26677. // 00010100x
  26678. [
  26679. 8,
  26680. 36
  26681. ],
  26682. [
  26683. 8,
  26684. 36
  26685. ],
  26686. // 00010101x
  26687. [
  26688. 8,
  26689. 37
  26690. ],
  26691. [
  26692. 8,
  26693. 37
  26694. ],
  26695. // 00010110x
  26696. [
  26697. 8,
  26698. 38
  26699. ],
  26700. [
  26701. 8,
  26702. 38
  26703. ],
  26704. // 00010111x
  26705. [
  26706. 7,
  26707. 19
  26708. ],
  26709. [
  26710. 7,
  26711. 19
  26712. ],
  26713. [
  26714. 7,
  26715. 19
  26716. ],
  26717. [
  26718. 7,
  26719. 19
  26720. ],
  26721. // 0001100xx
  26722. [
  26723. 8,
  26724. 31
  26725. ],
  26726. [
  26727. 8,
  26728. 31
  26729. ],
  26730. // 00011010x
  26731. [
  26732. 8,
  26733. 32
  26734. ],
  26735. [
  26736. 8,
  26737. 32
  26738. ],
  26739. // 00011011x
  26740. [
  26741. 6,
  26742. 1
  26743. ],
  26744. [
  26745. 6,
  26746. 1
  26747. ],
  26748. [
  26749. 6,
  26750. 1
  26751. ],
  26752. [
  26753. 6,
  26754. 1
  26755. ],
  26756. // 000111xxx
  26757. [
  26758. 6,
  26759. 1
  26760. ],
  26761. [
  26762. 6,
  26763. 1
  26764. ],
  26765. [
  26766. 6,
  26767. 1
  26768. ],
  26769. [
  26770. 6,
  26771. 1
  26772. ],
  26773. [
  26774. 6,
  26775. 12
  26776. ],
  26777. [
  26778. 6,
  26779. 12
  26780. ],
  26781. [
  26782. 6,
  26783. 12
  26784. ],
  26785. [
  26786. 6,
  26787. 12
  26788. ],
  26789. // 001000xxx
  26790. [
  26791. 6,
  26792. 12
  26793. ],
  26794. [
  26795. 6,
  26796. 12
  26797. ],
  26798. [
  26799. 6,
  26800. 12
  26801. ],
  26802. [
  26803. 6,
  26804. 12
  26805. ],
  26806. [
  26807. 8,
  26808. 53
  26809. ],
  26810. [
  26811. 8,
  26812. 53
  26813. ],
  26814. // 00100100x
  26815. [
  26816. 8,
  26817. 54
  26818. ],
  26819. [
  26820. 8,
  26821. 54
  26822. ],
  26823. // 00100101x
  26824. [
  26825. 7,
  26826. 26
  26827. ],
  26828. [
  26829. 7,
  26830. 26
  26831. ],
  26832. [
  26833. 7,
  26834. 26
  26835. ],
  26836. [
  26837. 7,
  26838. 26
  26839. ],
  26840. // 0010011xx
  26841. [
  26842. 8,
  26843. 39
  26844. ],
  26845. [
  26846. 8,
  26847. 39
  26848. ],
  26849. // 00101000x
  26850. [
  26851. 8,
  26852. 40
  26853. ],
  26854. [
  26855. 8,
  26856. 40
  26857. ],
  26858. // 00101001x
  26859. [
  26860. 8,
  26861. 41
  26862. ],
  26863. [
  26864. 8,
  26865. 41
  26866. ],
  26867. // 00101010x
  26868. [
  26869. 8,
  26870. 42
  26871. ],
  26872. [
  26873. 8,
  26874. 42
  26875. ],
  26876. // 00101011x
  26877. [
  26878. 8,
  26879. 43
  26880. ],
  26881. [
  26882. 8,
  26883. 43
  26884. ],
  26885. // 00101100x
  26886. [
  26887. 8,
  26888. 44
  26889. ],
  26890. [
  26891. 8,
  26892. 44
  26893. ],
  26894. // 00101101x
  26895. [
  26896. 7,
  26897. 21
  26898. ],
  26899. [
  26900. 7,
  26901. 21
  26902. ],
  26903. [
  26904. 7,
  26905. 21
  26906. ],
  26907. [
  26908. 7,
  26909. 21
  26910. ],
  26911. // 0010111xx
  26912. [
  26913. 7,
  26914. 28
  26915. ],
  26916. [
  26917. 7,
  26918. 28
  26919. ],
  26920. [
  26921. 7,
  26922. 28
  26923. ],
  26924. [
  26925. 7,
  26926. 28
  26927. ],
  26928. // 0011000xx
  26929. [
  26930. 8,
  26931. 61
  26932. ],
  26933. [
  26934. 8,
  26935. 61
  26936. ],
  26937. // 00110010x
  26938. [
  26939. 8,
  26940. 62
  26941. ],
  26942. [
  26943. 8,
  26944. 62
  26945. ],
  26946. // 00110011x
  26947. [
  26948. 8,
  26949. 63
  26950. ],
  26951. [
  26952. 8,
  26953. 63
  26954. ],
  26955. // 00110100x
  26956. [
  26957. 8,
  26958. 0
  26959. ],
  26960. [
  26961. 8,
  26962. 0
  26963. ],
  26964. // 00110101x
  26965. [
  26966. 8,
  26967. 320
  26968. ],
  26969. [
  26970. 8,
  26971. 320
  26972. ],
  26973. // 00110110x
  26974. [
  26975. 8,
  26976. 384
  26977. ],
  26978. [
  26979. 8,
  26980. 384
  26981. ],
  26982. // 00110111x
  26983. [
  26984. 5,
  26985. 10
  26986. ],
  26987. [
  26988. 5,
  26989. 10
  26990. ],
  26991. [
  26992. 5,
  26993. 10
  26994. ],
  26995. [
  26996. 5,
  26997. 10
  26998. ],
  26999. // 00111xxxx
  27000. [
  27001. 5,
  27002. 10
  27003. ],
  27004. [
  27005. 5,
  27006. 10
  27007. ],
  27008. [
  27009. 5,
  27010. 10
  27011. ],
  27012. [
  27013. 5,
  27014. 10
  27015. ],
  27016. [
  27017. 5,
  27018. 10
  27019. ],
  27020. [
  27021. 5,
  27022. 10
  27023. ],
  27024. [
  27025. 5,
  27026. 10
  27027. ],
  27028. [
  27029. 5,
  27030. 10
  27031. ],
  27032. [
  27033. 5,
  27034. 10
  27035. ],
  27036. [
  27037. 5,
  27038. 10
  27039. ],
  27040. [
  27041. 5,
  27042. 10
  27043. ],
  27044. [
  27045. 5,
  27046. 10
  27047. ],
  27048. [
  27049. 5,
  27050. 11
  27051. ],
  27052. [
  27053. 5,
  27054. 11
  27055. ],
  27056. [
  27057. 5,
  27058. 11
  27059. ],
  27060. [
  27061. 5,
  27062. 11
  27063. ],
  27064. // 01000xxxx
  27065. [
  27066. 5,
  27067. 11
  27068. ],
  27069. [
  27070. 5,
  27071. 11
  27072. ],
  27073. [
  27074. 5,
  27075. 11
  27076. ],
  27077. [
  27078. 5,
  27079. 11
  27080. ],
  27081. [
  27082. 5,
  27083. 11
  27084. ],
  27085. [
  27086. 5,
  27087. 11
  27088. ],
  27089. [
  27090. 5,
  27091. 11
  27092. ],
  27093. [
  27094. 5,
  27095. 11
  27096. ],
  27097. [
  27098. 5,
  27099. 11
  27100. ],
  27101. [
  27102. 5,
  27103. 11
  27104. ],
  27105. [
  27106. 5,
  27107. 11
  27108. ],
  27109. [
  27110. 5,
  27111. 11
  27112. ],
  27113. [
  27114. 7,
  27115. 27
  27116. ],
  27117. [
  27118. 7,
  27119. 27
  27120. ],
  27121. [
  27122. 7,
  27123. 27
  27124. ],
  27125. [
  27126. 7,
  27127. 27
  27128. ],
  27129. // 0100100xx
  27130. [
  27131. 8,
  27132. 59
  27133. ],
  27134. [
  27135. 8,
  27136. 59
  27137. ],
  27138. // 01001010x
  27139. [
  27140. 8,
  27141. 60
  27142. ],
  27143. [
  27144. 8,
  27145. 60
  27146. ],
  27147. // 01001011x
  27148. [
  27149. 9,
  27150. 1472
  27151. ],
  27152. // 010011000
  27153. [
  27154. 9,
  27155. 1536
  27156. ],
  27157. // 010011001
  27158. [
  27159. 9,
  27160. 1600
  27161. ],
  27162. // 010011010
  27163. [
  27164. 9,
  27165. 1728
  27166. ],
  27167. // 010011011
  27168. [
  27169. 7,
  27170. 18
  27171. ],
  27172. [
  27173. 7,
  27174. 18
  27175. ],
  27176. [
  27177. 7,
  27178. 18
  27179. ],
  27180. [
  27181. 7,
  27182. 18
  27183. ],
  27184. // 0100111xx
  27185. [
  27186. 7,
  27187. 24
  27188. ],
  27189. [
  27190. 7,
  27191. 24
  27192. ],
  27193. [
  27194. 7,
  27195. 24
  27196. ],
  27197. [
  27198. 7,
  27199. 24
  27200. ],
  27201. // 0101000xx
  27202. [
  27203. 8,
  27204. 49
  27205. ],
  27206. [
  27207. 8,
  27208. 49
  27209. ],
  27210. // 01010010x
  27211. [
  27212. 8,
  27213. 50
  27214. ],
  27215. [
  27216. 8,
  27217. 50
  27218. ],
  27219. // 01010011x
  27220. [
  27221. 8,
  27222. 51
  27223. ],
  27224. [
  27225. 8,
  27226. 51
  27227. ],
  27228. // 01010100x
  27229. [
  27230. 8,
  27231. 52
  27232. ],
  27233. [
  27234. 8,
  27235. 52
  27236. ],
  27237. // 01010101x
  27238. [
  27239. 7,
  27240. 25
  27241. ],
  27242. [
  27243. 7,
  27244. 25
  27245. ],
  27246. [
  27247. 7,
  27248. 25
  27249. ],
  27250. [
  27251. 7,
  27252. 25
  27253. ],
  27254. // 0101011xx
  27255. [
  27256. 8,
  27257. 55
  27258. ],
  27259. [
  27260. 8,
  27261. 55
  27262. ],
  27263. // 01011000x
  27264. [
  27265. 8,
  27266. 56
  27267. ],
  27268. [
  27269. 8,
  27270. 56
  27271. ],
  27272. // 01011001x
  27273. [
  27274. 8,
  27275. 57
  27276. ],
  27277. [
  27278. 8,
  27279. 57
  27280. ],
  27281. // 01011010x
  27282. [
  27283. 8,
  27284. 58
  27285. ],
  27286. [
  27287. 8,
  27288. 58
  27289. ],
  27290. // 01011011x
  27291. [
  27292. 6,
  27293. 192
  27294. ],
  27295. [
  27296. 6,
  27297. 192
  27298. ],
  27299. [
  27300. 6,
  27301. 192
  27302. ],
  27303. [
  27304. 6,
  27305. 192
  27306. ],
  27307. // 010111xxx
  27308. [
  27309. 6,
  27310. 192
  27311. ],
  27312. [
  27313. 6,
  27314. 192
  27315. ],
  27316. [
  27317. 6,
  27318. 192
  27319. ],
  27320. [
  27321. 6,
  27322. 192
  27323. ],
  27324. [
  27325. 6,
  27326. 1664
  27327. ],
  27328. [
  27329. 6,
  27330. 1664
  27331. ],
  27332. [
  27333. 6,
  27334. 1664
  27335. ],
  27336. [
  27337. 6,
  27338. 1664
  27339. ],
  27340. // 011000xxx
  27341. [
  27342. 6,
  27343. 1664
  27344. ],
  27345. [
  27346. 6,
  27347. 1664
  27348. ],
  27349. [
  27350. 6,
  27351. 1664
  27352. ],
  27353. [
  27354. 6,
  27355. 1664
  27356. ],
  27357. [
  27358. 8,
  27359. 448
  27360. ],
  27361. [
  27362. 8,
  27363. 448
  27364. ],
  27365. // 01100100x
  27366. [
  27367. 8,
  27368. 512
  27369. ],
  27370. [
  27371. 8,
  27372. 512
  27373. ],
  27374. // 01100101x
  27375. [
  27376. 9,
  27377. 704
  27378. ],
  27379. // 011001100
  27380. [
  27381. 9,
  27382. 768
  27383. ],
  27384. // 011001101
  27385. [
  27386. 8,
  27387. 640
  27388. ],
  27389. [
  27390. 8,
  27391. 640
  27392. ],
  27393. // 01100111x
  27394. [
  27395. 8,
  27396. 576
  27397. ],
  27398. [
  27399. 8,
  27400. 576
  27401. ],
  27402. // 01101000x
  27403. [
  27404. 9,
  27405. 832
  27406. ],
  27407. // 011010010
  27408. [
  27409. 9,
  27410. 896
  27411. ],
  27412. // 011010011
  27413. [
  27414. 9,
  27415. 960
  27416. ],
  27417. // 011010100
  27418. [
  27419. 9,
  27420. 1024
  27421. ],
  27422. // 011010101
  27423. [
  27424. 9,
  27425. 1088
  27426. ],
  27427. // 011010110
  27428. [
  27429. 9,
  27430. 1152
  27431. ],
  27432. // 011010111
  27433. [
  27434. 9,
  27435. 1216
  27436. ],
  27437. // 011011000
  27438. [
  27439. 9,
  27440. 1280
  27441. ],
  27442. // 011011001
  27443. [
  27444. 9,
  27445. 1344
  27446. ],
  27447. // 011011010
  27448. [
  27449. 9,
  27450. 1408
  27451. ],
  27452. // 011011011
  27453. [
  27454. 7,
  27455. 256
  27456. ],
  27457. [
  27458. 7,
  27459. 256
  27460. ],
  27461. [
  27462. 7,
  27463. 256
  27464. ],
  27465. [
  27466. 7,
  27467. 256
  27468. ],
  27469. // 0110111xx
  27470. [
  27471. 4,
  27472. 2
  27473. ],
  27474. [
  27475. 4,
  27476. 2
  27477. ],
  27478. [
  27479. 4,
  27480. 2
  27481. ],
  27482. [
  27483. 4,
  27484. 2
  27485. ],
  27486. // 0111xxxxx
  27487. [
  27488. 4,
  27489. 2
  27490. ],
  27491. [
  27492. 4,
  27493. 2
  27494. ],
  27495. [
  27496. 4,
  27497. 2
  27498. ],
  27499. [
  27500. 4,
  27501. 2
  27502. ],
  27503. [
  27504. 4,
  27505. 2
  27506. ],
  27507. [
  27508. 4,
  27509. 2
  27510. ],
  27511. [
  27512. 4,
  27513. 2
  27514. ],
  27515. [
  27516. 4,
  27517. 2
  27518. ],
  27519. [
  27520. 4,
  27521. 2
  27522. ],
  27523. [
  27524. 4,
  27525. 2
  27526. ],
  27527. [
  27528. 4,
  27529. 2
  27530. ],
  27531. [
  27532. 4,
  27533. 2
  27534. ],
  27535. [
  27536. 4,
  27537. 2
  27538. ],
  27539. [
  27540. 4,
  27541. 2
  27542. ],
  27543. [
  27544. 4,
  27545. 2
  27546. ],
  27547. [
  27548. 4,
  27549. 2
  27550. ],
  27551. [
  27552. 4,
  27553. 2
  27554. ],
  27555. [
  27556. 4,
  27557. 2
  27558. ],
  27559. [
  27560. 4,
  27561. 2
  27562. ],
  27563. [
  27564. 4,
  27565. 2
  27566. ],
  27567. [
  27568. 4,
  27569. 2
  27570. ],
  27571. [
  27572. 4,
  27573. 2
  27574. ],
  27575. [
  27576. 4,
  27577. 2
  27578. ],
  27579. [
  27580. 4,
  27581. 2
  27582. ],
  27583. [
  27584. 4,
  27585. 2
  27586. ],
  27587. [
  27588. 4,
  27589. 2
  27590. ],
  27591. [
  27592. 4,
  27593. 2
  27594. ],
  27595. [
  27596. 4,
  27597. 2
  27598. ],
  27599. [
  27600. 4,
  27601. 3
  27602. ],
  27603. [
  27604. 4,
  27605. 3
  27606. ],
  27607. [
  27608. 4,
  27609. 3
  27610. ],
  27611. [
  27612. 4,
  27613. 3
  27614. ],
  27615. // 1000xxxxx
  27616. [
  27617. 4,
  27618. 3
  27619. ],
  27620. [
  27621. 4,
  27622. 3
  27623. ],
  27624. [
  27625. 4,
  27626. 3
  27627. ],
  27628. [
  27629. 4,
  27630. 3
  27631. ],
  27632. [
  27633. 4,
  27634. 3
  27635. ],
  27636. [
  27637. 4,
  27638. 3
  27639. ],
  27640. [
  27641. 4,
  27642. 3
  27643. ],
  27644. [
  27645. 4,
  27646. 3
  27647. ],
  27648. [
  27649. 4,
  27650. 3
  27651. ],
  27652. [
  27653. 4,
  27654. 3
  27655. ],
  27656. [
  27657. 4,
  27658. 3
  27659. ],
  27660. [
  27661. 4,
  27662. 3
  27663. ],
  27664. [
  27665. 4,
  27666. 3
  27667. ],
  27668. [
  27669. 4,
  27670. 3
  27671. ],
  27672. [
  27673. 4,
  27674. 3
  27675. ],
  27676. [
  27677. 4,
  27678. 3
  27679. ],
  27680. [
  27681. 4,
  27682. 3
  27683. ],
  27684. [
  27685. 4,
  27686. 3
  27687. ],
  27688. [
  27689. 4,
  27690. 3
  27691. ],
  27692. [
  27693. 4,
  27694. 3
  27695. ],
  27696. [
  27697. 4,
  27698. 3
  27699. ],
  27700. [
  27701. 4,
  27702. 3
  27703. ],
  27704. [
  27705. 4,
  27706. 3
  27707. ],
  27708. [
  27709. 4,
  27710. 3
  27711. ],
  27712. [
  27713. 4,
  27714. 3
  27715. ],
  27716. [
  27717. 4,
  27718. 3
  27719. ],
  27720. [
  27721. 4,
  27722. 3
  27723. ],
  27724. [
  27725. 4,
  27726. 3
  27727. ],
  27728. [
  27729. 5,
  27730. 128
  27731. ],
  27732. [
  27733. 5,
  27734. 128
  27735. ],
  27736. [
  27737. 5,
  27738. 128
  27739. ],
  27740. [
  27741. 5,
  27742. 128
  27743. ],
  27744. // 10010xxxx
  27745. [
  27746. 5,
  27747. 128
  27748. ],
  27749. [
  27750. 5,
  27751. 128
  27752. ],
  27753. [
  27754. 5,
  27755. 128
  27756. ],
  27757. [
  27758. 5,
  27759. 128
  27760. ],
  27761. [
  27762. 5,
  27763. 128
  27764. ],
  27765. [
  27766. 5,
  27767. 128
  27768. ],
  27769. [
  27770. 5,
  27771. 128
  27772. ],
  27773. [
  27774. 5,
  27775. 128
  27776. ],
  27777. [
  27778. 5,
  27779. 128
  27780. ],
  27781. [
  27782. 5,
  27783. 128
  27784. ],
  27785. [
  27786. 5,
  27787. 128
  27788. ],
  27789. [
  27790. 5,
  27791. 128
  27792. ],
  27793. [
  27794. 5,
  27795. 8
  27796. ],
  27797. [
  27798. 5,
  27799. 8
  27800. ],
  27801. [
  27802. 5,
  27803. 8
  27804. ],
  27805. [
  27806. 5,
  27807. 8
  27808. ],
  27809. // 10011xxxx
  27810. [
  27811. 5,
  27812. 8
  27813. ],
  27814. [
  27815. 5,
  27816. 8
  27817. ],
  27818. [
  27819. 5,
  27820. 8
  27821. ],
  27822. [
  27823. 5,
  27824. 8
  27825. ],
  27826. [
  27827. 5,
  27828. 8
  27829. ],
  27830. [
  27831. 5,
  27832. 8
  27833. ],
  27834. [
  27835. 5,
  27836. 8
  27837. ],
  27838. [
  27839. 5,
  27840. 8
  27841. ],
  27842. [
  27843. 5,
  27844. 8
  27845. ],
  27846. [
  27847. 5,
  27848. 8
  27849. ],
  27850. [
  27851. 5,
  27852. 8
  27853. ],
  27854. [
  27855. 5,
  27856. 8
  27857. ],
  27858. [
  27859. 5,
  27860. 9
  27861. ],
  27862. [
  27863. 5,
  27864. 9
  27865. ],
  27866. [
  27867. 5,
  27868. 9
  27869. ],
  27870. [
  27871. 5,
  27872. 9
  27873. ],
  27874. // 10100xxxx
  27875. [
  27876. 5,
  27877. 9
  27878. ],
  27879. [
  27880. 5,
  27881. 9
  27882. ],
  27883. [
  27884. 5,
  27885. 9
  27886. ],
  27887. [
  27888. 5,
  27889. 9
  27890. ],
  27891. [
  27892. 5,
  27893. 9
  27894. ],
  27895. [
  27896. 5,
  27897. 9
  27898. ],
  27899. [
  27900. 5,
  27901. 9
  27902. ],
  27903. [
  27904. 5,
  27905. 9
  27906. ],
  27907. [
  27908. 5,
  27909. 9
  27910. ],
  27911. [
  27912. 5,
  27913. 9
  27914. ],
  27915. [
  27916. 5,
  27917. 9
  27918. ],
  27919. [
  27920. 5,
  27921. 9
  27922. ],
  27923. [
  27924. 6,
  27925. 16
  27926. ],
  27927. [
  27928. 6,
  27929. 16
  27930. ],
  27931. [
  27932. 6,
  27933. 16
  27934. ],
  27935. [
  27936. 6,
  27937. 16
  27938. ],
  27939. // 101010xxx
  27940. [
  27941. 6,
  27942. 16
  27943. ],
  27944. [
  27945. 6,
  27946. 16
  27947. ],
  27948. [
  27949. 6,
  27950. 16
  27951. ],
  27952. [
  27953. 6,
  27954. 16
  27955. ],
  27956. [
  27957. 6,
  27958. 17
  27959. ],
  27960. [
  27961. 6,
  27962. 17
  27963. ],
  27964. [
  27965. 6,
  27966. 17
  27967. ],
  27968. [
  27969. 6,
  27970. 17
  27971. ],
  27972. // 101011xxx
  27973. [
  27974. 6,
  27975. 17
  27976. ],
  27977. [
  27978. 6,
  27979. 17
  27980. ],
  27981. [
  27982. 6,
  27983. 17
  27984. ],
  27985. [
  27986. 6,
  27987. 17
  27988. ],
  27989. [
  27990. 4,
  27991. 4
  27992. ],
  27993. [
  27994. 4,
  27995. 4
  27996. ],
  27997. [
  27998. 4,
  27999. 4
  28000. ],
  28001. [
  28002. 4,
  28003. 4
  28004. ],
  28005. // 1011xxxxx
  28006. [
  28007. 4,
  28008. 4
  28009. ],
  28010. [
  28011. 4,
  28012. 4
  28013. ],
  28014. [
  28015. 4,
  28016. 4
  28017. ],
  28018. [
  28019. 4,
  28020. 4
  28021. ],
  28022. [
  28023. 4,
  28024. 4
  28025. ],
  28026. [
  28027. 4,
  28028. 4
  28029. ],
  28030. [
  28031. 4,
  28032. 4
  28033. ],
  28034. [
  28035. 4,
  28036. 4
  28037. ],
  28038. [
  28039. 4,
  28040. 4
  28041. ],
  28042. [
  28043. 4,
  28044. 4
  28045. ],
  28046. [
  28047. 4,
  28048. 4
  28049. ],
  28050. [
  28051. 4,
  28052. 4
  28053. ],
  28054. [
  28055. 4,
  28056. 4
  28057. ],
  28058. [
  28059. 4,
  28060. 4
  28061. ],
  28062. [
  28063. 4,
  28064. 4
  28065. ],
  28066. [
  28067. 4,
  28068. 4
  28069. ],
  28070. [
  28071. 4,
  28072. 4
  28073. ],
  28074. [
  28075. 4,
  28076. 4
  28077. ],
  28078. [
  28079. 4,
  28080. 4
  28081. ],
  28082. [
  28083. 4,
  28084. 4
  28085. ],
  28086. [
  28087. 4,
  28088. 4
  28089. ],
  28090. [
  28091. 4,
  28092. 4
  28093. ],
  28094. [
  28095. 4,
  28096. 4
  28097. ],
  28098. [
  28099. 4,
  28100. 4
  28101. ],
  28102. [
  28103. 4,
  28104. 4
  28105. ],
  28106. [
  28107. 4,
  28108. 4
  28109. ],
  28110. [
  28111. 4,
  28112. 4
  28113. ],
  28114. [
  28115. 4,
  28116. 4
  28117. ],
  28118. [
  28119. 4,
  28120. 5
  28121. ],
  28122. [
  28123. 4,
  28124. 5
  28125. ],
  28126. [
  28127. 4,
  28128. 5
  28129. ],
  28130. [
  28131. 4,
  28132. 5
  28133. ],
  28134. // 1100xxxxx
  28135. [
  28136. 4,
  28137. 5
  28138. ],
  28139. [
  28140. 4,
  28141. 5
  28142. ],
  28143. [
  28144. 4,
  28145. 5
  28146. ],
  28147. [
  28148. 4,
  28149. 5
  28150. ],
  28151. [
  28152. 4,
  28153. 5
  28154. ],
  28155. [
  28156. 4,
  28157. 5
  28158. ],
  28159. [
  28160. 4,
  28161. 5
  28162. ],
  28163. [
  28164. 4,
  28165. 5
  28166. ],
  28167. [
  28168. 4,
  28169. 5
  28170. ],
  28171. [
  28172. 4,
  28173. 5
  28174. ],
  28175. [
  28176. 4,
  28177. 5
  28178. ],
  28179. [
  28180. 4,
  28181. 5
  28182. ],
  28183. [
  28184. 4,
  28185. 5
  28186. ],
  28187. [
  28188. 4,
  28189. 5
  28190. ],
  28191. [
  28192. 4,
  28193. 5
  28194. ],
  28195. [
  28196. 4,
  28197. 5
  28198. ],
  28199. [
  28200. 4,
  28201. 5
  28202. ],
  28203. [
  28204. 4,
  28205. 5
  28206. ],
  28207. [
  28208. 4,
  28209. 5
  28210. ],
  28211. [
  28212. 4,
  28213. 5
  28214. ],
  28215. [
  28216. 4,
  28217. 5
  28218. ],
  28219. [
  28220. 4,
  28221. 5
  28222. ],
  28223. [
  28224. 4,
  28225. 5
  28226. ],
  28227. [
  28228. 4,
  28229. 5
  28230. ],
  28231. [
  28232. 4,
  28233. 5
  28234. ],
  28235. [
  28236. 4,
  28237. 5
  28238. ],
  28239. [
  28240. 4,
  28241. 5
  28242. ],
  28243. [
  28244. 4,
  28245. 5
  28246. ],
  28247. [
  28248. 6,
  28249. 14
  28250. ],
  28251. [
  28252. 6,
  28253. 14
  28254. ],
  28255. [
  28256. 6,
  28257. 14
  28258. ],
  28259. [
  28260. 6,
  28261. 14
  28262. ],
  28263. // 110100xxx
  28264. [
  28265. 6,
  28266. 14
  28267. ],
  28268. [
  28269. 6,
  28270. 14
  28271. ],
  28272. [
  28273. 6,
  28274. 14
  28275. ],
  28276. [
  28277. 6,
  28278. 14
  28279. ],
  28280. [
  28281. 6,
  28282. 15
  28283. ],
  28284. [
  28285. 6,
  28286. 15
  28287. ],
  28288. [
  28289. 6,
  28290. 15
  28291. ],
  28292. [
  28293. 6,
  28294. 15
  28295. ],
  28296. // 110101xxx
  28297. [
  28298. 6,
  28299. 15
  28300. ],
  28301. [
  28302. 6,
  28303. 15
  28304. ],
  28305. [
  28306. 6,
  28307. 15
  28308. ],
  28309. [
  28310. 6,
  28311. 15
  28312. ],
  28313. [
  28314. 5,
  28315. 64
  28316. ],
  28317. [
  28318. 5,
  28319. 64
  28320. ],
  28321. [
  28322. 5,
  28323. 64
  28324. ],
  28325. [
  28326. 5,
  28327. 64
  28328. ],
  28329. // 11011xxxx
  28330. [
  28331. 5,
  28332. 64
  28333. ],
  28334. [
  28335. 5,
  28336. 64
  28337. ],
  28338. [
  28339. 5,
  28340. 64
  28341. ],
  28342. [
  28343. 5,
  28344. 64
  28345. ],
  28346. [
  28347. 5,
  28348. 64
  28349. ],
  28350. [
  28351. 5,
  28352. 64
  28353. ],
  28354. [
  28355. 5,
  28356. 64
  28357. ],
  28358. [
  28359. 5,
  28360. 64
  28361. ],
  28362. [
  28363. 5,
  28364. 64
  28365. ],
  28366. [
  28367. 5,
  28368. 64
  28369. ],
  28370. [
  28371. 5,
  28372. 64
  28373. ],
  28374. [
  28375. 5,
  28376. 64
  28377. ],
  28378. [
  28379. 4,
  28380. 6
  28381. ],
  28382. [
  28383. 4,
  28384. 6
  28385. ],
  28386. [
  28387. 4,
  28388. 6
  28389. ],
  28390. [
  28391. 4,
  28392. 6
  28393. ],
  28394. // 1110xxxxx
  28395. [
  28396. 4,
  28397. 6
  28398. ],
  28399. [
  28400. 4,
  28401. 6
  28402. ],
  28403. [
  28404. 4,
  28405. 6
  28406. ],
  28407. [
  28408. 4,
  28409. 6
  28410. ],
  28411. [
  28412. 4,
  28413. 6
  28414. ],
  28415. [
  28416. 4,
  28417. 6
  28418. ],
  28419. [
  28420. 4,
  28421. 6
  28422. ],
  28423. [
  28424. 4,
  28425. 6
  28426. ],
  28427. [
  28428. 4,
  28429. 6
  28430. ],
  28431. [
  28432. 4,
  28433. 6
  28434. ],
  28435. [
  28436. 4,
  28437. 6
  28438. ],
  28439. [
  28440. 4,
  28441. 6
  28442. ],
  28443. [
  28444. 4,
  28445. 6
  28446. ],
  28447. [
  28448. 4,
  28449. 6
  28450. ],
  28451. [
  28452. 4,
  28453. 6
  28454. ],
  28455. [
  28456. 4,
  28457. 6
  28458. ],
  28459. [
  28460. 4,
  28461. 6
  28462. ],
  28463. [
  28464. 4,
  28465. 6
  28466. ],
  28467. [
  28468. 4,
  28469. 6
  28470. ],
  28471. [
  28472. 4,
  28473. 6
  28474. ],
  28475. [
  28476. 4,
  28477. 6
  28478. ],
  28479. [
  28480. 4,
  28481. 6
  28482. ],
  28483. [
  28484. 4,
  28485. 6
  28486. ],
  28487. [
  28488. 4,
  28489. 6
  28490. ],
  28491. [
  28492. 4,
  28493. 6
  28494. ],
  28495. [
  28496. 4,
  28497. 6
  28498. ],
  28499. [
  28500. 4,
  28501. 6
  28502. ],
  28503. [
  28504. 4,
  28505. 6
  28506. ],
  28507. [
  28508. 4,
  28509. 7
  28510. ],
  28511. [
  28512. 4,
  28513. 7
  28514. ],
  28515. [
  28516. 4,
  28517. 7
  28518. ],
  28519. [
  28520. 4,
  28521. 7
  28522. ],
  28523. // 1111xxxxx
  28524. [
  28525. 4,
  28526. 7
  28527. ],
  28528. [
  28529. 4,
  28530. 7
  28531. ],
  28532. [
  28533. 4,
  28534. 7
  28535. ],
  28536. [
  28537. 4,
  28538. 7
  28539. ],
  28540. [
  28541. 4,
  28542. 7
  28543. ],
  28544. [
  28545. 4,
  28546. 7
  28547. ],
  28548. [
  28549. 4,
  28550. 7
  28551. ],
  28552. [
  28553. 4,
  28554. 7
  28555. ],
  28556. [
  28557. 4,
  28558. 7
  28559. ],
  28560. [
  28561. 4,
  28562. 7
  28563. ],
  28564. [
  28565. 4,
  28566. 7
  28567. ],
  28568. [
  28569. 4,
  28570. 7
  28571. ],
  28572. [
  28573. 4,
  28574. 7
  28575. ],
  28576. [
  28577. 4,
  28578. 7
  28579. ],
  28580. [
  28581. 4,
  28582. 7
  28583. ],
  28584. [
  28585. 4,
  28586. 7
  28587. ],
  28588. [
  28589. 4,
  28590. 7
  28591. ],
  28592. [
  28593. 4,
  28594. 7
  28595. ],
  28596. [
  28597. 4,
  28598. 7
  28599. ],
  28600. [
  28601. 4,
  28602. 7
  28603. ],
  28604. [
  28605. 4,
  28606. 7
  28607. ],
  28608. [
  28609. 4,
  28610. 7
  28611. ],
  28612. [
  28613. 4,
  28614. 7
  28615. ],
  28616. [
  28617. 4,
  28618. 7
  28619. ],
  28620. [
  28621. 4,
  28622. 7
  28623. ],
  28624. [
  28625. 4,
  28626. 7
  28627. ],
  28628. [
  28629. 4,
  28630. 7
  28631. ],
  28632. [
  28633. 4,
  28634. 7
  28635. ]
  28636. ];
  28637. var blackTable1 = [
  28638. [
  28639. -1,
  28640. -1
  28641. ],
  28642. [
  28643. -1,
  28644. -1
  28645. ],
  28646. // 000000000000x
  28647. [
  28648. 12,
  28649. ccittEOL
  28650. ],
  28651. [
  28652. 12,
  28653. ccittEOL
  28654. ],
  28655. // 000000000001x
  28656. [
  28657. -1,
  28658. -1
  28659. ],
  28660. [
  28661. -1,
  28662. -1
  28663. ],
  28664. [
  28665. -1,
  28666. -1
  28667. ],
  28668. [
  28669. -1,
  28670. -1
  28671. ],
  28672. // 00000000001xx
  28673. [
  28674. -1,
  28675. -1
  28676. ],
  28677. [
  28678. -1,
  28679. -1
  28680. ],
  28681. [
  28682. -1,
  28683. -1
  28684. ],
  28685. [
  28686. -1,
  28687. -1
  28688. ],
  28689. // 00000000010xx
  28690. [
  28691. -1,
  28692. -1
  28693. ],
  28694. [
  28695. -1,
  28696. -1
  28697. ],
  28698. [
  28699. -1,
  28700. -1
  28701. ],
  28702. [
  28703. -1,
  28704. -1
  28705. ],
  28706. // 00000000011xx
  28707. [
  28708. -1,
  28709. -1
  28710. ],
  28711. [
  28712. -1,
  28713. -1
  28714. ],
  28715. [
  28716. -1,
  28717. -1
  28718. ],
  28719. [
  28720. -1,
  28721. -1
  28722. ],
  28723. // 00000000100xx
  28724. [
  28725. -1,
  28726. -1
  28727. ],
  28728. [
  28729. -1,
  28730. -1
  28731. ],
  28732. [
  28733. -1,
  28734. -1
  28735. ],
  28736. [
  28737. -1,
  28738. -1
  28739. ],
  28740. // 00000000101xx
  28741. [
  28742. -1,
  28743. -1
  28744. ],
  28745. [
  28746. -1,
  28747. -1
  28748. ],
  28749. [
  28750. -1,
  28751. -1
  28752. ],
  28753. [
  28754. -1,
  28755. -1
  28756. ],
  28757. // 00000000110xx
  28758. [
  28759. -1,
  28760. -1
  28761. ],
  28762. [
  28763. -1,
  28764. -1
  28765. ],
  28766. [
  28767. -1,
  28768. -1
  28769. ],
  28770. [
  28771. -1,
  28772. -1
  28773. ],
  28774. // 00000000111xx
  28775. [
  28776. 11,
  28777. 1792
  28778. ],
  28779. [
  28780. 11,
  28781. 1792
  28782. ],
  28783. [
  28784. 11,
  28785. 1792
  28786. ],
  28787. [
  28788. 11,
  28789. 1792
  28790. ],
  28791. // 00000001000xx
  28792. [
  28793. 12,
  28794. 1984
  28795. ],
  28796. [
  28797. 12,
  28798. 1984
  28799. ],
  28800. // 000000010010x
  28801. [
  28802. 12,
  28803. 2048
  28804. ],
  28805. [
  28806. 12,
  28807. 2048
  28808. ],
  28809. // 000000010011x
  28810. [
  28811. 12,
  28812. 2112
  28813. ],
  28814. [
  28815. 12,
  28816. 2112
  28817. ],
  28818. // 000000010100x
  28819. [
  28820. 12,
  28821. 2176
  28822. ],
  28823. [
  28824. 12,
  28825. 2176
  28826. ],
  28827. // 000000010101x
  28828. [
  28829. 12,
  28830. 2240
  28831. ],
  28832. [
  28833. 12,
  28834. 2240
  28835. ],
  28836. // 000000010110x
  28837. [
  28838. 12,
  28839. 2304
  28840. ],
  28841. [
  28842. 12,
  28843. 2304
  28844. ],
  28845. // 000000010111x
  28846. [
  28847. 11,
  28848. 1856
  28849. ],
  28850. [
  28851. 11,
  28852. 1856
  28853. ],
  28854. [
  28855. 11,
  28856. 1856
  28857. ],
  28858. [
  28859. 11,
  28860. 1856
  28861. ],
  28862. // 00000001100xx
  28863. [
  28864. 11,
  28865. 1920
  28866. ],
  28867. [
  28868. 11,
  28869. 1920
  28870. ],
  28871. [
  28872. 11,
  28873. 1920
  28874. ],
  28875. [
  28876. 11,
  28877. 1920
  28878. ],
  28879. // 00000001101xx
  28880. [
  28881. 12,
  28882. 2368
  28883. ],
  28884. [
  28885. 12,
  28886. 2368
  28887. ],
  28888. // 000000011100x
  28889. [
  28890. 12,
  28891. 2432
  28892. ],
  28893. [
  28894. 12,
  28895. 2432
  28896. ],
  28897. // 000000011101x
  28898. [
  28899. 12,
  28900. 2496
  28901. ],
  28902. [
  28903. 12,
  28904. 2496
  28905. ],
  28906. // 000000011110x
  28907. [
  28908. 12,
  28909. 2560
  28910. ],
  28911. [
  28912. 12,
  28913. 2560
  28914. ],
  28915. // 000000011111x
  28916. [
  28917. 10,
  28918. 18
  28919. ],
  28920. [
  28921. 10,
  28922. 18
  28923. ],
  28924. [
  28925. 10,
  28926. 18
  28927. ],
  28928. [
  28929. 10,
  28930. 18
  28931. ],
  28932. // 0000001000xxx
  28933. [
  28934. 10,
  28935. 18
  28936. ],
  28937. [
  28938. 10,
  28939. 18
  28940. ],
  28941. [
  28942. 10,
  28943. 18
  28944. ],
  28945. [
  28946. 10,
  28947. 18
  28948. ],
  28949. [
  28950. 12,
  28951. 52
  28952. ],
  28953. [
  28954. 12,
  28955. 52
  28956. ],
  28957. // 000000100100x
  28958. [
  28959. 13,
  28960. 640
  28961. ],
  28962. // 0000001001010
  28963. [
  28964. 13,
  28965. 704
  28966. ],
  28967. // 0000001001011
  28968. [
  28969. 13,
  28970. 768
  28971. ],
  28972. // 0000001001100
  28973. [
  28974. 13,
  28975. 832
  28976. ],
  28977. // 0000001001101
  28978. [
  28979. 12,
  28980. 55
  28981. ],
  28982. [
  28983. 12,
  28984. 55
  28985. ],
  28986. // 000000100111x
  28987. [
  28988. 12,
  28989. 56
  28990. ],
  28991. [
  28992. 12,
  28993. 56
  28994. ],
  28995. // 000000101000x
  28996. [
  28997. 13,
  28998. 1280
  28999. ],
  29000. // 0000001010010
  29001. [
  29002. 13,
  29003. 1344
  29004. ],
  29005. // 0000001010011
  29006. [
  29007. 13,
  29008. 1408
  29009. ],
  29010. // 0000001010100
  29011. [
  29012. 13,
  29013. 1472
  29014. ],
  29015. // 0000001010101
  29016. [
  29017. 12,
  29018. 59
  29019. ],
  29020. [
  29021. 12,
  29022. 59
  29023. ],
  29024. // 000000101011x
  29025. [
  29026. 12,
  29027. 60
  29028. ],
  29029. [
  29030. 12,
  29031. 60
  29032. ],
  29033. // 000000101100x
  29034. [
  29035. 13,
  29036. 1536
  29037. ],
  29038. // 0000001011010
  29039. [
  29040. 13,
  29041. 1600
  29042. ],
  29043. // 0000001011011
  29044. [
  29045. 11,
  29046. 24
  29047. ],
  29048. [
  29049. 11,
  29050. 24
  29051. ],
  29052. [
  29053. 11,
  29054. 24
  29055. ],
  29056. [
  29057. 11,
  29058. 24
  29059. ],
  29060. // 00000010111xx
  29061. [
  29062. 11,
  29063. 25
  29064. ],
  29065. [
  29066. 11,
  29067. 25
  29068. ],
  29069. [
  29070. 11,
  29071. 25
  29072. ],
  29073. [
  29074. 11,
  29075. 25
  29076. ],
  29077. // 00000011000xx
  29078. [
  29079. 13,
  29080. 1664
  29081. ],
  29082. // 0000001100100
  29083. [
  29084. 13,
  29085. 1728
  29086. ],
  29087. // 0000001100101
  29088. [
  29089. 12,
  29090. 320
  29091. ],
  29092. [
  29093. 12,
  29094. 320
  29095. ],
  29096. // 000000110011x
  29097. [
  29098. 12,
  29099. 384
  29100. ],
  29101. [
  29102. 12,
  29103. 384
  29104. ],
  29105. // 000000110100x
  29106. [
  29107. 12,
  29108. 448
  29109. ],
  29110. [
  29111. 12,
  29112. 448
  29113. ],
  29114. // 000000110101x
  29115. [
  29116. 13,
  29117. 512
  29118. ],
  29119. // 0000001101100
  29120. [
  29121. 13,
  29122. 576
  29123. ],
  29124. // 0000001101101
  29125. [
  29126. 12,
  29127. 53
  29128. ],
  29129. [
  29130. 12,
  29131. 53
  29132. ],
  29133. // 000000110111x
  29134. [
  29135. 12,
  29136. 54
  29137. ],
  29138. [
  29139. 12,
  29140. 54
  29141. ],
  29142. // 000000111000x
  29143. [
  29144. 13,
  29145. 896
  29146. ],
  29147. // 0000001110010
  29148. [
  29149. 13,
  29150. 960
  29151. ],
  29152. // 0000001110011
  29153. [
  29154. 13,
  29155. 1024
  29156. ],
  29157. // 0000001110100
  29158. [
  29159. 13,
  29160. 1088
  29161. ],
  29162. // 0000001110101
  29163. [
  29164. 13,
  29165. 1152
  29166. ],
  29167. // 0000001110110
  29168. [
  29169. 13,
  29170. 1216
  29171. ],
  29172. // 0000001110111
  29173. [
  29174. 10,
  29175. 64
  29176. ],
  29177. [
  29178. 10,
  29179. 64
  29180. ],
  29181. [
  29182. 10,
  29183. 64
  29184. ],
  29185. [
  29186. 10,
  29187. 64
  29188. ],
  29189. // 0000001111xxx
  29190. [
  29191. 10,
  29192. 64
  29193. ],
  29194. [
  29195. 10,
  29196. 64
  29197. ],
  29198. [
  29199. 10,
  29200. 64
  29201. ],
  29202. [
  29203. 10,
  29204. 64
  29205. ]
  29206. ];
  29207. var blackTable2 = [
  29208. [
  29209. 8,
  29210. 13
  29211. ],
  29212. [
  29213. 8,
  29214. 13
  29215. ],
  29216. [
  29217. 8,
  29218. 13
  29219. ],
  29220. [
  29221. 8,
  29222. 13
  29223. ],
  29224. // 00000100xxxx
  29225. [
  29226. 8,
  29227. 13
  29228. ],
  29229. [
  29230. 8,
  29231. 13
  29232. ],
  29233. [
  29234. 8,
  29235. 13
  29236. ],
  29237. [
  29238. 8,
  29239. 13
  29240. ],
  29241. [
  29242. 8,
  29243. 13
  29244. ],
  29245. [
  29246. 8,
  29247. 13
  29248. ],
  29249. [
  29250. 8,
  29251. 13
  29252. ],
  29253. [
  29254. 8,
  29255. 13
  29256. ],
  29257. [
  29258. 8,
  29259. 13
  29260. ],
  29261. [
  29262. 8,
  29263. 13
  29264. ],
  29265. [
  29266. 8,
  29267. 13
  29268. ],
  29269. [
  29270. 8,
  29271. 13
  29272. ],
  29273. [
  29274. 11,
  29275. 23
  29276. ],
  29277. [
  29278. 11,
  29279. 23
  29280. ],
  29281. // 00000101000x
  29282. [
  29283. 12,
  29284. 50
  29285. ],
  29286. // 000001010010
  29287. [
  29288. 12,
  29289. 51
  29290. ],
  29291. // 000001010011
  29292. [
  29293. 12,
  29294. 44
  29295. ],
  29296. // 000001010100
  29297. [
  29298. 12,
  29299. 45
  29300. ],
  29301. // 000001010101
  29302. [
  29303. 12,
  29304. 46
  29305. ],
  29306. // 000001010110
  29307. [
  29308. 12,
  29309. 47
  29310. ],
  29311. // 000001010111
  29312. [
  29313. 12,
  29314. 57
  29315. ],
  29316. // 000001011000
  29317. [
  29318. 12,
  29319. 58
  29320. ],
  29321. // 000001011001
  29322. [
  29323. 12,
  29324. 61
  29325. ],
  29326. // 000001011010
  29327. [
  29328. 12,
  29329. 256
  29330. ],
  29331. // 000001011011
  29332. [
  29333. 10,
  29334. 16
  29335. ],
  29336. [
  29337. 10,
  29338. 16
  29339. ],
  29340. [
  29341. 10,
  29342. 16
  29343. ],
  29344. [
  29345. 10,
  29346. 16
  29347. ],
  29348. // 0000010111xx
  29349. [
  29350. 10,
  29351. 17
  29352. ],
  29353. [
  29354. 10,
  29355. 17
  29356. ],
  29357. [
  29358. 10,
  29359. 17
  29360. ],
  29361. [
  29362. 10,
  29363. 17
  29364. ],
  29365. // 0000011000xx
  29366. [
  29367. 12,
  29368. 48
  29369. ],
  29370. // 000001100100
  29371. [
  29372. 12,
  29373. 49
  29374. ],
  29375. // 000001100101
  29376. [
  29377. 12,
  29378. 62
  29379. ],
  29380. // 000001100110
  29381. [
  29382. 12,
  29383. 63
  29384. ],
  29385. // 000001100111
  29386. [
  29387. 12,
  29388. 30
  29389. ],
  29390. // 000001101000
  29391. [
  29392. 12,
  29393. 31
  29394. ],
  29395. // 000001101001
  29396. [
  29397. 12,
  29398. 32
  29399. ],
  29400. // 000001101010
  29401. [
  29402. 12,
  29403. 33
  29404. ],
  29405. // 000001101011
  29406. [
  29407. 12,
  29408. 40
  29409. ],
  29410. // 000001101100
  29411. [
  29412. 12,
  29413. 41
  29414. ],
  29415. // 000001101101
  29416. [
  29417. 11,
  29418. 22
  29419. ],
  29420. [
  29421. 11,
  29422. 22
  29423. ],
  29424. // 00000110111x
  29425. [
  29426. 8,
  29427. 14
  29428. ],
  29429. [
  29430. 8,
  29431. 14
  29432. ],
  29433. [
  29434. 8,
  29435. 14
  29436. ],
  29437. [
  29438. 8,
  29439. 14
  29440. ],
  29441. // 00000111xxxx
  29442. [
  29443. 8,
  29444. 14
  29445. ],
  29446. [
  29447. 8,
  29448. 14
  29449. ],
  29450. [
  29451. 8,
  29452. 14
  29453. ],
  29454. [
  29455. 8,
  29456. 14
  29457. ],
  29458. [
  29459. 8,
  29460. 14
  29461. ],
  29462. [
  29463. 8,
  29464. 14
  29465. ],
  29466. [
  29467. 8,
  29468. 14
  29469. ],
  29470. [
  29471. 8,
  29472. 14
  29473. ],
  29474. [
  29475. 8,
  29476. 14
  29477. ],
  29478. [
  29479. 8,
  29480. 14
  29481. ],
  29482. [
  29483. 8,
  29484. 14
  29485. ],
  29486. [
  29487. 8,
  29488. 14
  29489. ],
  29490. [
  29491. 7,
  29492. 10
  29493. ],
  29494. [
  29495. 7,
  29496. 10
  29497. ],
  29498. [
  29499. 7,
  29500. 10
  29501. ],
  29502. [
  29503. 7,
  29504. 10
  29505. ],
  29506. // 0000100xxxxx
  29507. [
  29508. 7,
  29509. 10
  29510. ],
  29511. [
  29512. 7,
  29513. 10
  29514. ],
  29515. [
  29516. 7,
  29517. 10
  29518. ],
  29519. [
  29520. 7,
  29521. 10
  29522. ],
  29523. [
  29524. 7,
  29525. 10
  29526. ],
  29527. [
  29528. 7,
  29529. 10
  29530. ],
  29531. [
  29532. 7,
  29533. 10
  29534. ],
  29535. [
  29536. 7,
  29537. 10
  29538. ],
  29539. [
  29540. 7,
  29541. 10
  29542. ],
  29543. [
  29544. 7,
  29545. 10
  29546. ],
  29547. [
  29548. 7,
  29549. 10
  29550. ],
  29551. [
  29552. 7,
  29553. 10
  29554. ],
  29555. [
  29556. 7,
  29557. 10
  29558. ],
  29559. [
  29560. 7,
  29561. 10
  29562. ],
  29563. [
  29564. 7,
  29565. 10
  29566. ],
  29567. [
  29568. 7,
  29569. 10
  29570. ],
  29571. [
  29572. 7,
  29573. 10
  29574. ],
  29575. [
  29576. 7,
  29577. 10
  29578. ],
  29579. [
  29580. 7,
  29581. 10
  29582. ],
  29583. [
  29584. 7,
  29585. 10
  29586. ],
  29587. [
  29588. 7,
  29589. 10
  29590. ],
  29591. [
  29592. 7,
  29593. 10
  29594. ],
  29595. [
  29596. 7,
  29597. 10
  29598. ],
  29599. [
  29600. 7,
  29601. 10
  29602. ],
  29603. [
  29604. 7,
  29605. 10
  29606. ],
  29607. [
  29608. 7,
  29609. 10
  29610. ],
  29611. [
  29612. 7,
  29613. 10
  29614. ],
  29615. [
  29616. 7,
  29617. 10
  29618. ],
  29619. [
  29620. 7,
  29621. 11
  29622. ],
  29623. [
  29624. 7,
  29625. 11
  29626. ],
  29627. [
  29628. 7,
  29629. 11
  29630. ],
  29631. [
  29632. 7,
  29633. 11
  29634. ],
  29635. // 0000101xxxxx
  29636. [
  29637. 7,
  29638. 11
  29639. ],
  29640. [
  29641. 7,
  29642. 11
  29643. ],
  29644. [
  29645. 7,
  29646. 11
  29647. ],
  29648. [
  29649. 7,
  29650. 11
  29651. ],
  29652. [
  29653. 7,
  29654. 11
  29655. ],
  29656. [
  29657. 7,
  29658. 11
  29659. ],
  29660. [
  29661. 7,
  29662. 11
  29663. ],
  29664. [
  29665. 7,
  29666. 11
  29667. ],
  29668. [
  29669. 7,
  29670. 11
  29671. ],
  29672. [
  29673. 7,
  29674. 11
  29675. ],
  29676. [
  29677. 7,
  29678. 11
  29679. ],
  29680. [
  29681. 7,
  29682. 11
  29683. ],
  29684. [
  29685. 7,
  29686. 11
  29687. ],
  29688. [
  29689. 7,
  29690. 11
  29691. ],
  29692. [
  29693. 7,
  29694. 11
  29695. ],
  29696. [
  29697. 7,
  29698. 11
  29699. ],
  29700. [
  29701. 7,
  29702. 11
  29703. ],
  29704. [
  29705. 7,
  29706. 11
  29707. ],
  29708. [
  29709. 7,
  29710. 11
  29711. ],
  29712. [
  29713. 7,
  29714. 11
  29715. ],
  29716. [
  29717. 7,
  29718. 11
  29719. ],
  29720. [
  29721. 7,
  29722. 11
  29723. ],
  29724. [
  29725. 7,
  29726. 11
  29727. ],
  29728. [
  29729. 7,
  29730. 11
  29731. ],
  29732. [
  29733. 7,
  29734. 11
  29735. ],
  29736. [
  29737. 7,
  29738. 11
  29739. ],
  29740. [
  29741. 7,
  29742. 11
  29743. ],
  29744. [
  29745. 7,
  29746. 11
  29747. ],
  29748. [
  29749. 9,
  29750. 15
  29751. ],
  29752. [
  29753. 9,
  29754. 15
  29755. ],
  29756. [
  29757. 9,
  29758. 15
  29759. ],
  29760. [
  29761. 9,
  29762. 15
  29763. ],
  29764. // 000011000xxx
  29765. [
  29766. 9,
  29767. 15
  29768. ],
  29769. [
  29770. 9,
  29771. 15
  29772. ],
  29773. [
  29774. 9,
  29775. 15
  29776. ],
  29777. [
  29778. 9,
  29779. 15
  29780. ],
  29781. [
  29782. 12,
  29783. 128
  29784. ],
  29785. // 000011001000
  29786. [
  29787. 12,
  29788. 192
  29789. ],
  29790. // 000011001001
  29791. [
  29792. 12,
  29793. 26
  29794. ],
  29795. // 000011001010
  29796. [
  29797. 12,
  29798. 27
  29799. ],
  29800. // 000011001011
  29801. [
  29802. 12,
  29803. 28
  29804. ],
  29805. // 000011001100
  29806. [
  29807. 12,
  29808. 29
  29809. ],
  29810. // 000011001101
  29811. [
  29812. 11,
  29813. 19
  29814. ],
  29815. [
  29816. 11,
  29817. 19
  29818. ],
  29819. // 00001100111x
  29820. [
  29821. 11,
  29822. 20
  29823. ],
  29824. [
  29825. 11,
  29826. 20
  29827. ],
  29828. // 00001101000x
  29829. [
  29830. 12,
  29831. 34
  29832. ],
  29833. // 000011010010
  29834. [
  29835. 12,
  29836. 35
  29837. ],
  29838. // 000011010011
  29839. [
  29840. 12,
  29841. 36
  29842. ],
  29843. // 000011010100
  29844. [
  29845. 12,
  29846. 37
  29847. ],
  29848. // 000011010101
  29849. [
  29850. 12,
  29851. 38
  29852. ],
  29853. // 000011010110
  29854. [
  29855. 12,
  29856. 39
  29857. ],
  29858. // 000011010111
  29859. [
  29860. 11,
  29861. 21
  29862. ],
  29863. [
  29864. 11,
  29865. 21
  29866. ],
  29867. // 00001101100x
  29868. [
  29869. 12,
  29870. 42
  29871. ],
  29872. // 000011011010
  29873. [
  29874. 12,
  29875. 43
  29876. ],
  29877. // 000011011011
  29878. [
  29879. 10,
  29880. 0
  29881. ],
  29882. [
  29883. 10,
  29884. 0
  29885. ],
  29886. [
  29887. 10,
  29888. 0
  29889. ],
  29890. [
  29891. 10,
  29892. 0
  29893. ],
  29894. // 0000110111xx
  29895. [
  29896. 7,
  29897. 12
  29898. ],
  29899. [
  29900. 7,
  29901. 12
  29902. ],
  29903. [
  29904. 7,
  29905. 12
  29906. ],
  29907. [
  29908. 7,
  29909. 12
  29910. ],
  29911. // 0000111xxxxx
  29912. [
  29913. 7,
  29914. 12
  29915. ],
  29916. [
  29917. 7,
  29918. 12
  29919. ],
  29920. [
  29921. 7,
  29922. 12
  29923. ],
  29924. [
  29925. 7,
  29926. 12
  29927. ],
  29928. [
  29929. 7,
  29930. 12
  29931. ],
  29932. [
  29933. 7,
  29934. 12
  29935. ],
  29936. [
  29937. 7,
  29938. 12
  29939. ],
  29940. [
  29941. 7,
  29942. 12
  29943. ],
  29944. [
  29945. 7,
  29946. 12
  29947. ],
  29948. [
  29949. 7,
  29950. 12
  29951. ],
  29952. [
  29953. 7,
  29954. 12
  29955. ],
  29956. [
  29957. 7,
  29958. 12
  29959. ],
  29960. [
  29961. 7,
  29962. 12
  29963. ],
  29964. [
  29965. 7,
  29966. 12
  29967. ],
  29968. [
  29969. 7,
  29970. 12
  29971. ],
  29972. [
  29973. 7,
  29974. 12
  29975. ],
  29976. [
  29977. 7,
  29978. 12
  29979. ],
  29980. [
  29981. 7,
  29982. 12
  29983. ],
  29984. [
  29985. 7,
  29986. 12
  29987. ],
  29988. [
  29989. 7,
  29990. 12
  29991. ],
  29992. [
  29993. 7,
  29994. 12
  29995. ],
  29996. [
  29997. 7,
  29998. 12
  29999. ],
  30000. [
  30001. 7,
  30002. 12
  30003. ],
  30004. [
  30005. 7,
  30006. 12
  30007. ],
  30008. [
  30009. 7,
  30010. 12
  30011. ],
  30012. [
  30013. 7,
  30014. 12
  30015. ],
  30016. [
  30017. 7,
  30018. 12
  30019. ],
  30020. [
  30021. 7,
  30022. 12
  30023. ]
  30024. ];
  30025. var blackTable3 = [
  30026. [
  30027. -1,
  30028. -1
  30029. ],
  30030. [
  30031. -1,
  30032. -1
  30033. ],
  30034. [
  30035. -1,
  30036. -1
  30037. ],
  30038. [
  30039. -1,
  30040. -1
  30041. ],
  30042. // 0000xx
  30043. [
  30044. 6,
  30045. 9
  30046. ],
  30047. // 000100
  30048. [
  30049. 6,
  30050. 8
  30051. ],
  30052. // 000101
  30053. [
  30054. 5,
  30055. 7
  30056. ],
  30057. [
  30058. 5,
  30059. 7
  30060. ],
  30061. // 00011x
  30062. [
  30063. 4,
  30064. 6
  30065. ],
  30066. [
  30067. 4,
  30068. 6
  30069. ],
  30070. [
  30071. 4,
  30072. 6
  30073. ],
  30074. [
  30075. 4,
  30076. 6
  30077. ],
  30078. // 0010xx
  30079. [
  30080. 4,
  30081. 5
  30082. ],
  30083. [
  30084. 4,
  30085. 5
  30086. ],
  30087. [
  30088. 4,
  30089. 5
  30090. ],
  30091. [
  30092. 4,
  30093. 5
  30094. ],
  30095. // 0011xx
  30096. [
  30097. 3,
  30098. 1
  30099. ],
  30100. [
  30101. 3,
  30102. 1
  30103. ],
  30104. [
  30105. 3,
  30106. 1
  30107. ],
  30108. [
  30109. 3,
  30110. 1
  30111. ],
  30112. // 010xxx
  30113. [
  30114. 3,
  30115. 1
  30116. ],
  30117. [
  30118. 3,
  30119. 1
  30120. ],
  30121. [
  30122. 3,
  30123. 1
  30124. ],
  30125. [
  30126. 3,
  30127. 1
  30128. ],
  30129. [
  30130. 3,
  30131. 4
  30132. ],
  30133. [
  30134. 3,
  30135. 4
  30136. ],
  30137. [
  30138. 3,
  30139. 4
  30140. ],
  30141. [
  30142. 3,
  30143. 4
  30144. ],
  30145. // 011xxx
  30146. [
  30147. 3,
  30148. 4
  30149. ],
  30150. [
  30151. 3,
  30152. 4
  30153. ],
  30154. [
  30155. 3,
  30156. 4
  30157. ],
  30158. [
  30159. 3,
  30160. 4
  30161. ],
  30162. [
  30163. 2,
  30164. 3
  30165. ],
  30166. [
  30167. 2,
  30168. 3
  30169. ],
  30170. [
  30171. 2,
  30172. 3
  30173. ],
  30174. [
  30175. 2,
  30176. 3
  30177. ],
  30178. // 10xxxx
  30179. [
  30180. 2,
  30181. 3
  30182. ],
  30183. [
  30184. 2,
  30185. 3
  30186. ],
  30187. [
  30188. 2,
  30189. 3
  30190. ],
  30191. [
  30192. 2,
  30193. 3
  30194. ],
  30195. [
  30196. 2,
  30197. 3
  30198. ],
  30199. [
  30200. 2,
  30201. 3
  30202. ],
  30203. [
  30204. 2,
  30205. 3
  30206. ],
  30207. [
  30208. 2,
  30209. 3
  30210. ],
  30211. [
  30212. 2,
  30213. 3
  30214. ],
  30215. [
  30216. 2,
  30217. 3
  30218. ],
  30219. [
  30220. 2,
  30221. 3
  30222. ],
  30223. [
  30224. 2,
  30225. 3
  30226. ],
  30227. [
  30228. 2,
  30229. 2
  30230. ],
  30231. [
  30232. 2,
  30233. 2
  30234. ],
  30235. [
  30236. 2,
  30237. 2
  30238. ],
  30239. [
  30240. 2,
  30241. 2
  30242. ],
  30243. // 11xxxx
  30244. [
  30245. 2,
  30246. 2
  30247. ],
  30248. [
  30249. 2,
  30250. 2
  30251. ],
  30252. [
  30253. 2,
  30254. 2
  30255. ],
  30256. [
  30257. 2,
  30258. 2
  30259. ],
  30260. [
  30261. 2,
  30262. 2
  30263. ],
  30264. [
  30265. 2,
  30266. 2
  30267. ],
  30268. [
  30269. 2,
  30270. 2
  30271. ],
  30272. [
  30273. 2,
  30274. 2
  30275. ],
  30276. [
  30277. 2,
  30278. 2
  30279. ],
  30280. [
  30281. 2,
  30282. 2
  30283. ],
  30284. [
  30285. 2,
  30286. 2
  30287. ],
  30288. [
  30289. 2,
  30290. 2
  30291. ]
  30292. ];
  30293. function CCITTFaxStream(str, maybeLength, params) {
  30294. this.str = str;
  30295. this.dict = str.dict;
  30296. params = params || Dict.empty;
  30297. this.encoding = params.get('K') || 0;
  30298. this.eoline = params.get('EndOfLine') || false;
  30299. this.byteAlign = params.get('EncodedByteAlign') || false;
  30300. this.columns = params.get('Columns') || 1728;
  30301. this.rows = params.get('Rows') || 0;
  30302. var eoblock = params.get('EndOfBlock');
  30303. if (eoblock === null || eoblock === undefined) {
  30304. eoblock = true;
  30305. }
  30306. this.eoblock = eoblock;
  30307. this.black = params.get('BlackIs1') || false;
  30308. this.codingLine = new Uint32Array(this.columns + 1);
  30309. this.refLine = new Uint32Array(this.columns + 2);
  30310. this.codingLine[0] = this.columns;
  30311. this.codingPos = 0;
  30312. this.row = 0;
  30313. this.nextLine2D = this.encoding < 0;
  30314. this.inputBits = 0;
  30315. this.inputBuf = 0;
  30316. this.outputBits = 0;
  30317. var code1;
  30318. while ((code1 = this.lookBits(12)) === 0) {
  30319. this.eatBits(1);
  30320. }
  30321. if (code1 === 1) {
  30322. this.eatBits(12);
  30323. }
  30324. if (this.encoding > 0) {
  30325. this.nextLine2D = !this.lookBits(1);
  30326. this.eatBits(1);
  30327. }
  30328. DecodeStream.call(this, maybeLength);
  30329. }
  30330. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  30331. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  30332. while (!this.eof) {
  30333. var c = this.lookChar();
  30334. this.ensureBuffer(this.bufferLength + 1);
  30335. this.buffer[this.bufferLength++] = c;
  30336. }
  30337. };
  30338. CCITTFaxStream.prototype.addPixels = function ccittFaxStreamAddPixels(a1, blackPixels) {
  30339. var codingLine = this.codingLine;
  30340. var codingPos = this.codingPos;
  30341. if (a1 > codingLine[codingPos]) {
  30342. if (a1 > this.columns) {
  30343. info('row is wrong length');
  30344. this.err = true;
  30345. a1 = this.columns;
  30346. }
  30347. if (codingPos & 1 ^ blackPixels) {
  30348. ++codingPos;
  30349. }
  30350. codingLine[codingPos] = a1;
  30351. }
  30352. this.codingPos = codingPos;
  30353. };
  30354. CCITTFaxStream.prototype.addPixelsNeg = function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  30355. var codingLine = this.codingLine;
  30356. var codingPos = this.codingPos;
  30357. if (a1 > codingLine[codingPos]) {
  30358. if (a1 > this.columns) {
  30359. info('row is wrong length');
  30360. this.err = true;
  30361. a1 = this.columns;
  30362. }
  30363. if (codingPos & 1 ^ blackPixels) {
  30364. ++codingPos;
  30365. }
  30366. codingLine[codingPos] = a1;
  30367. } else if (a1 < codingLine[codingPos]) {
  30368. if (a1 < 0) {
  30369. info('invalid code');
  30370. this.err = true;
  30371. a1 = 0;
  30372. }
  30373. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  30374. --codingPos;
  30375. }
  30376. codingLine[codingPos] = a1;
  30377. }
  30378. this.codingPos = codingPos;
  30379. };
  30380. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  30381. var refLine = this.refLine;
  30382. var codingLine = this.codingLine;
  30383. var columns = this.columns;
  30384. var refPos, blackPixels, bits, i;
  30385. if (this.outputBits === 0) {
  30386. if (this.eof) {
  30387. return null;
  30388. }
  30389. this.err = false;
  30390. var code1, code2, code3;
  30391. if (this.nextLine2D) {
  30392. for (i = 0; codingLine[i] < columns; ++i) {
  30393. refLine[i] = codingLine[i];
  30394. }
  30395. refLine[i++] = columns;
  30396. refLine[i] = columns;
  30397. codingLine[0] = 0;
  30398. this.codingPos = 0;
  30399. refPos = 0;
  30400. blackPixels = 0;
  30401. while (codingLine[this.codingPos] < columns) {
  30402. code1 = this.getTwoDimCode();
  30403. switch (code1) {
  30404. case twoDimPass:
  30405. this.addPixels(refLine[refPos + 1], blackPixels);
  30406. if (refLine[refPos + 1] < columns) {
  30407. refPos += 2;
  30408. }
  30409. break;
  30410. case twoDimHoriz:
  30411. code1 = code2 = 0;
  30412. if (blackPixels) {
  30413. do {
  30414. code1 += code3 = this.getBlackCode();
  30415. } while (code3 >= 64);
  30416. do {
  30417. code2 += code3 = this.getWhiteCode();
  30418. } while (code3 >= 64);
  30419. } else {
  30420. do {
  30421. code1 += code3 = this.getWhiteCode();
  30422. } while (code3 >= 64);
  30423. do {
  30424. code2 += code3 = this.getBlackCode();
  30425. } while (code3 >= 64);
  30426. }
  30427. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  30428. if (codingLine[this.codingPos] < columns) {
  30429. this.addPixels(codingLine[this.codingPos] + code2, blackPixels ^ 1);
  30430. }
  30431. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  30432. refPos += 2;
  30433. }
  30434. break;
  30435. case twoDimVertR3:
  30436. this.addPixels(refLine[refPos] + 3, blackPixels);
  30437. blackPixels ^= 1;
  30438. if (codingLine[this.codingPos] < columns) {
  30439. ++refPos;
  30440. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  30441. refPos += 2;
  30442. }
  30443. }
  30444. break;
  30445. case twoDimVertR2:
  30446. this.addPixels(refLine[refPos] + 2, blackPixels);
  30447. blackPixels ^= 1;
  30448. if (codingLine[this.codingPos] < columns) {
  30449. ++refPos;
  30450. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  30451. refPos += 2;
  30452. }
  30453. }
  30454. break;
  30455. case twoDimVertR1:
  30456. this.addPixels(refLine[refPos] + 1, blackPixels);
  30457. blackPixels ^= 1;
  30458. if (codingLine[this.codingPos] < columns) {
  30459. ++refPos;
  30460. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  30461. refPos += 2;
  30462. }
  30463. }
  30464. break;
  30465. case twoDimVert0:
  30466. this.addPixels(refLine[refPos], blackPixels);
  30467. blackPixels ^= 1;
  30468. if (codingLine[this.codingPos] < columns) {
  30469. ++refPos;
  30470. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  30471. refPos += 2;
  30472. }
  30473. }
  30474. break;
  30475. case twoDimVertL3:
  30476. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  30477. blackPixels ^= 1;
  30478. if (codingLine[this.codingPos] < columns) {
  30479. if (refPos > 0) {
  30480. --refPos;
  30481. } else {
  30482. ++refPos;
  30483. }
  30484. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  30485. refPos += 2;
  30486. }
  30487. }
  30488. break;
  30489. case twoDimVertL2:
  30490. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  30491. blackPixels ^= 1;
  30492. if (codingLine[this.codingPos] < columns) {
  30493. if (refPos > 0) {
  30494. --refPos;
  30495. } else {
  30496. ++refPos;
  30497. }
  30498. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  30499. refPos += 2;
  30500. }
  30501. }
  30502. break;
  30503. case twoDimVertL1:
  30504. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  30505. blackPixels ^= 1;
  30506. if (codingLine[this.codingPos] < columns) {
  30507. if (refPos > 0) {
  30508. --refPos;
  30509. } else {
  30510. ++refPos;
  30511. }
  30512. while (refLine[refPos] <= codingLine[this.codingPos] && refLine[refPos] < columns) {
  30513. refPos += 2;
  30514. }
  30515. }
  30516. break;
  30517. case ccittEOF:
  30518. this.addPixels(columns, 0);
  30519. this.eof = true;
  30520. break;
  30521. default:
  30522. info('bad 2d code');
  30523. this.addPixels(columns, 0);
  30524. this.err = true;
  30525. }
  30526. }
  30527. } else {
  30528. codingLine[0] = 0;
  30529. this.codingPos = 0;
  30530. blackPixels = 0;
  30531. while (codingLine[this.codingPos] < columns) {
  30532. code1 = 0;
  30533. if (blackPixels) {
  30534. do {
  30535. code1 += code3 = this.getBlackCode();
  30536. } while (code3 >= 64);
  30537. } else {
  30538. do {
  30539. code1 += code3 = this.getWhiteCode();
  30540. } while (code3 >= 64);
  30541. }
  30542. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  30543. blackPixels ^= 1;
  30544. }
  30545. }
  30546. var gotEOL = false;
  30547. if (this.byteAlign) {
  30548. this.inputBits &= ~7;
  30549. }
  30550. if (!this.eoblock && this.row === this.rows - 1) {
  30551. this.eof = true;
  30552. } else {
  30553. code1 = this.lookBits(12);
  30554. if (this.eoline) {
  30555. while (code1 !== ccittEOF && code1 !== 1) {
  30556. this.eatBits(1);
  30557. code1 = this.lookBits(12);
  30558. }
  30559. } else {
  30560. while (code1 === 0) {
  30561. this.eatBits(1);
  30562. code1 = this.lookBits(12);
  30563. }
  30564. }
  30565. if (code1 === 1) {
  30566. this.eatBits(12);
  30567. gotEOL = true;
  30568. } else if (code1 === ccittEOF) {
  30569. this.eof = true;
  30570. }
  30571. }
  30572. if (!this.eof && this.encoding > 0) {
  30573. this.nextLine2D = !this.lookBits(1);
  30574. this.eatBits(1);
  30575. }
  30576. if (this.eoblock && gotEOL && this.byteAlign) {
  30577. code1 = this.lookBits(12);
  30578. if (code1 === 1) {
  30579. this.eatBits(12);
  30580. if (this.encoding > 0) {
  30581. this.lookBits(1);
  30582. this.eatBits(1);
  30583. }
  30584. if (this.encoding >= 0) {
  30585. for (i = 0; i < 4; ++i) {
  30586. code1 = this.lookBits(12);
  30587. if (code1 !== 1) {
  30588. info('bad rtc code: ' + code1);
  30589. }
  30590. this.eatBits(12);
  30591. if (this.encoding > 0) {
  30592. this.lookBits(1);
  30593. this.eatBits(1);
  30594. }
  30595. }
  30596. }
  30597. this.eof = true;
  30598. }
  30599. } else if (this.err && this.eoline) {
  30600. while (true) {
  30601. code1 = this.lookBits(13);
  30602. if (code1 === ccittEOF) {
  30603. this.eof = true;
  30604. return null;
  30605. }
  30606. if (code1 >> 1 === 1) {
  30607. break;
  30608. }
  30609. this.eatBits(1);
  30610. }
  30611. this.eatBits(12);
  30612. if (this.encoding > 0) {
  30613. this.eatBits(1);
  30614. this.nextLine2D = !(code1 & 1);
  30615. }
  30616. }
  30617. if (codingLine[0] > 0) {
  30618. this.outputBits = codingLine[this.codingPos = 0];
  30619. } else {
  30620. this.outputBits = codingLine[this.codingPos = 1];
  30621. }
  30622. this.row++;
  30623. }
  30624. var c;
  30625. if (this.outputBits >= 8) {
  30626. c = this.codingPos & 1 ? 0 : 0xFF;
  30627. this.outputBits -= 8;
  30628. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  30629. this.codingPos++;
  30630. this.outputBits = codingLine[this.codingPos] - codingLine[this.codingPos - 1];
  30631. }
  30632. } else {
  30633. bits = 8;
  30634. c = 0;
  30635. do {
  30636. if (this.outputBits > bits) {
  30637. c <<= bits;
  30638. if (!(this.codingPos & 1)) {
  30639. c |= 0xFF >> 8 - bits;
  30640. }
  30641. this.outputBits -= bits;
  30642. bits = 0;
  30643. } else {
  30644. c <<= this.outputBits;
  30645. if (!(this.codingPos & 1)) {
  30646. c |= 0xFF >> 8 - this.outputBits;
  30647. }
  30648. bits -= this.outputBits;
  30649. this.outputBits = 0;
  30650. if (codingLine[this.codingPos] < columns) {
  30651. this.codingPos++;
  30652. this.outputBits = codingLine[this.codingPos] - codingLine[this.codingPos - 1];
  30653. } else if (bits > 0) {
  30654. c <<= bits;
  30655. bits = 0;
  30656. }
  30657. }
  30658. } while (bits);
  30659. }
  30660. if (this.black) {
  30661. c ^= 0xFF;
  30662. }
  30663. return c;
  30664. };
  30665. // This functions returns the code found from the table.
  30666. // The start and end parameters set the boundaries for searching the table.
  30667. // The limit parameter is optional. Function returns an array with three
  30668. // values. The first array element indicates whether a valid code is being
  30669. // returned. The second array element is the actual code. The third array
  30670. // element indicates whether EOF was reached.
  30671. CCITTFaxStream.prototype.findTableCode = function ccittFaxStreamFindTableCode(start, end, table, limit) {
  30672. var limitValue = limit || 0;
  30673. for (var i = start; i <= end; ++i) {
  30674. var code = this.lookBits(i);
  30675. if (code === ccittEOF) {
  30676. return [
  30677. true,
  30678. 1,
  30679. false
  30680. ];
  30681. }
  30682. if (i < end) {
  30683. code <<= end - i;
  30684. }
  30685. if (!limitValue || code >= limitValue) {
  30686. var p = table[code - limitValue];
  30687. if (p[0] === i) {
  30688. this.eatBits(i);
  30689. return [
  30690. true,
  30691. p[1],
  30692. true
  30693. ];
  30694. }
  30695. }
  30696. }
  30697. return [
  30698. false,
  30699. 0,
  30700. false
  30701. ];
  30702. };
  30703. CCITTFaxStream.prototype.getTwoDimCode = function ccittFaxStreamGetTwoDimCode() {
  30704. var code = 0;
  30705. var p;
  30706. if (this.eoblock) {
  30707. code = this.lookBits(7);
  30708. p = twoDimTable[code];
  30709. if (p && p[0] > 0) {
  30710. this.eatBits(p[0]);
  30711. return p[1];
  30712. }
  30713. } else {
  30714. var result = this.findTableCode(1, 7, twoDimTable);
  30715. if (result[0] && result[2]) {
  30716. return result[1];
  30717. }
  30718. }
  30719. info('Bad two dim code');
  30720. return ccittEOF;
  30721. };
  30722. CCITTFaxStream.prototype.getWhiteCode = function ccittFaxStreamGetWhiteCode() {
  30723. var code = 0;
  30724. var p;
  30725. if (this.eoblock) {
  30726. code = this.lookBits(12);
  30727. if (code === ccittEOF) {
  30728. return 1;
  30729. }
  30730. if (code >> 5 === 0) {
  30731. p = whiteTable1[code];
  30732. } else {
  30733. p = whiteTable2[code >> 3];
  30734. }
  30735. if (p[0] > 0) {
  30736. this.eatBits(p[0]);
  30737. return p[1];
  30738. }
  30739. } else {
  30740. var result = this.findTableCode(1, 9, whiteTable2);
  30741. if (result[0]) {
  30742. return result[1];
  30743. }
  30744. result = this.findTableCode(11, 12, whiteTable1);
  30745. if (result[0]) {
  30746. return result[1];
  30747. }
  30748. }
  30749. info('bad white code');
  30750. this.eatBits(1);
  30751. return 1;
  30752. };
  30753. CCITTFaxStream.prototype.getBlackCode = function ccittFaxStreamGetBlackCode() {
  30754. var code, p;
  30755. if (this.eoblock) {
  30756. code = this.lookBits(13);
  30757. if (code === ccittEOF) {
  30758. return 1;
  30759. }
  30760. if (code >> 7 === 0) {
  30761. p = blackTable1[code];
  30762. } else if (code >> 9 === 0 && code >> 7 !== 0) {
  30763. p = blackTable2[(code >> 1) - 64];
  30764. } else {
  30765. p = blackTable3[code >> 7];
  30766. }
  30767. if (p[0] > 0) {
  30768. this.eatBits(p[0]);
  30769. return p[1];
  30770. }
  30771. } else {
  30772. var result = this.findTableCode(2, 6, blackTable3);
  30773. if (result[0]) {
  30774. return result[1];
  30775. }
  30776. result = this.findTableCode(7, 12, blackTable2, 64);
  30777. if (result[0]) {
  30778. return result[1];
  30779. }
  30780. result = this.findTableCode(10, 13, blackTable1);
  30781. if (result[0]) {
  30782. return result[1];
  30783. }
  30784. }
  30785. info('bad black code');
  30786. this.eatBits(1);
  30787. return 1;
  30788. };
  30789. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  30790. var c;
  30791. while (this.inputBits < n) {
  30792. if ((c = this.str.getByte()) === -1) {
  30793. if (this.inputBits === 0) {
  30794. return ccittEOF;
  30795. }
  30796. return this.inputBuf << n - this.inputBits & 0xFFFF >> 16 - n;
  30797. }
  30798. this.inputBuf = this.inputBuf << 8 | c;
  30799. this.inputBits += 8;
  30800. }
  30801. return this.inputBuf >> this.inputBits - n & 0xFFFF >> 16 - n;
  30802. };
  30803. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  30804. if ((this.inputBits -= n) < 0) {
  30805. this.inputBits = 0;
  30806. }
  30807. };
  30808. return CCITTFaxStream;
  30809. }();
  30810. var LZWStream = function LZWStreamClosure() {
  30811. function LZWStream(str, maybeLength, earlyChange) {
  30812. this.str = str;
  30813. this.dict = str.dict;
  30814. this.cachedData = 0;
  30815. this.bitsCached = 0;
  30816. var maxLzwDictionarySize = 4096;
  30817. var lzwState = {
  30818. earlyChange: earlyChange,
  30819. codeLength: 9,
  30820. nextCode: 258,
  30821. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  30822. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  30823. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  30824. currentSequence: new Uint8Array(maxLzwDictionarySize),
  30825. currentSequenceLength: 0
  30826. };
  30827. for (var i = 0; i < 256; ++i) {
  30828. lzwState.dictionaryValues[i] = i;
  30829. lzwState.dictionaryLengths[i] = 1;
  30830. }
  30831. this.lzwState = lzwState;
  30832. DecodeStream.call(this, maybeLength);
  30833. }
  30834. LZWStream.prototype = Object.create(DecodeStream.prototype);
  30835. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  30836. var bitsCached = this.bitsCached;
  30837. var cachedData = this.cachedData;
  30838. while (bitsCached < n) {
  30839. var c = this.str.getByte();
  30840. if (c === -1) {
  30841. this.eof = true;
  30842. return null;
  30843. }
  30844. cachedData = cachedData << 8 | c;
  30845. bitsCached += 8;
  30846. }
  30847. this.bitsCached = bitsCached -= n;
  30848. this.cachedData = cachedData;
  30849. this.lastCode = null;
  30850. return cachedData >>> bitsCached & (1 << n) - 1;
  30851. };
  30852. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  30853. var blockSize = 512;
  30854. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  30855. var i, j, q;
  30856. var lzwState = this.lzwState;
  30857. if (!lzwState) {
  30858. return;
  30859. }
  30860. // eof was found
  30861. var earlyChange = lzwState.earlyChange;
  30862. var nextCode = lzwState.nextCode;
  30863. var dictionaryValues = lzwState.dictionaryValues;
  30864. var dictionaryLengths = lzwState.dictionaryLengths;
  30865. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  30866. var codeLength = lzwState.codeLength;
  30867. var prevCode = lzwState.prevCode;
  30868. var currentSequence = lzwState.currentSequence;
  30869. var currentSequenceLength = lzwState.currentSequenceLength;
  30870. var decodedLength = 0;
  30871. var currentBufferLength = this.bufferLength;
  30872. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  30873. for (i = 0; i < blockSize; i++) {
  30874. var code = this.readBits(codeLength);
  30875. var hasPrev = currentSequenceLength > 0;
  30876. if (code < 256) {
  30877. currentSequence[0] = code;
  30878. currentSequenceLength = 1;
  30879. } else if (code >= 258) {
  30880. if (code < nextCode) {
  30881. currentSequenceLength = dictionaryLengths[code];
  30882. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  30883. currentSequence[j] = dictionaryValues[q];
  30884. q = dictionaryPrevCodes[q];
  30885. }
  30886. } else {
  30887. currentSequence[currentSequenceLength++] = currentSequence[0];
  30888. }
  30889. } else if (code === 256) {
  30890. codeLength = 9;
  30891. nextCode = 258;
  30892. currentSequenceLength = 0;
  30893. continue;
  30894. } else {
  30895. this.eof = true;
  30896. delete this.lzwState;
  30897. break;
  30898. }
  30899. if (hasPrev) {
  30900. dictionaryPrevCodes[nextCode] = prevCode;
  30901. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  30902. dictionaryValues[nextCode] = currentSequence[0];
  30903. nextCode++;
  30904. codeLength = nextCode + earlyChange & nextCode + earlyChange - 1 ? codeLength : Math.min(Math.log(nextCode + earlyChange) / 0.6931471805599453 + 1, 12) | 0;
  30905. }
  30906. prevCode = code;
  30907. decodedLength += currentSequenceLength;
  30908. if (estimatedDecodedSize < decodedLength) {
  30909. do {
  30910. estimatedDecodedSize += decodedSizeDelta;
  30911. } while (estimatedDecodedSize < decodedLength);
  30912. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  30913. }
  30914. for (j = 0; j < currentSequenceLength; j++) {
  30915. buffer[currentBufferLength++] = currentSequence[j];
  30916. }
  30917. }
  30918. lzwState.nextCode = nextCode;
  30919. lzwState.codeLength = codeLength;
  30920. lzwState.prevCode = prevCode;
  30921. lzwState.currentSequenceLength = currentSequenceLength;
  30922. this.bufferLength = currentBufferLength;
  30923. };
  30924. return LZWStream;
  30925. }();
  30926. var NullStream = function NullStreamClosure() {
  30927. function NullStream() {
  30928. Stream.call(this, new Uint8Array(0));
  30929. }
  30930. NullStream.prototype = Stream.prototype;
  30931. return NullStream;
  30932. }();
  30933. exports.Ascii85Stream = Ascii85Stream;
  30934. exports.AsciiHexStream = AsciiHexStream;
  30935. exports.CCITTFaxStream = CCITTFaxStream;
  30936. exports.DecryptStream = DecryptStream;
  30937. exports.DecodeStream = DecodeStream;
  30938. exports.FlateStream = FlateStream;
  30939. exports.Jbig2Stream = Jbig2Stream;
  30940. exports.JpegStream = JpegStream;
  30941. exports.JpxStream = JpxStream;
  30942. exports.NullStream = NullStream;
  30943. exports.PredictorStream = PredictorStream;
  30944. exports.RunLengthStream = RunLengthStream;
  30945. exports.Stream = Stream;
  30946. exports.StreamsSequenceStream = StreamsSequenceStream;
  30947. exports.StringStream = StringStream;
  30948. exports.LZWStream = LZWStream;
  30949. }));
  30950. (function (root, factory) {
  30951. factory(root.pdfjsCoreCrypto = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  30952. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  30953. var PasswordException = sharedUtil.PasswordException;
  30954. var PasswordResponses = sharedUtil.PasswordResponses;
  30955. var bytesToString = sharedUtil.bytesToString;
  30956. var error = sharedUtil.error;
  30957. var isInt = sharedUtil.isInt;
  30958. var stringToBytes = sharedUtil.stringToBytes;
  30959. var utf8StringToString = sharedUtil.utf8StringToString;
  30960. var warn = sharedUtil.warn;
  30961. var Name = corePrimitives.Name;
  30962. var isName = corePrimitives.isName;
  30963. var isDict = corePrimitives.isDict;
  30964. var DecryptStream = coreStream.DecryptStream;
  30965. var ARCFourCipher = function ARCFourCipherClosure() {
  30966. function ARCFourCipher(key) {
  30967. this.a = 0;
  30968. this.b = 0;
  30969. var s = new Uint8Array(256);
  30970. var i, j = 0, tmp, keyLength = key.length;
  30971. for (i = 0; i < 256; ++i) {
  30972. s[i] = i;
  30973. }
  30974. for (i = 0; i < 256; ++i) {
  30975. tmp = s[i];
  30976. j = j + tmp + key[i % keyLength] & 0xFF;
  30977. s[i] = s[j];
  30978. s[j] = tmp;
  30979. }
  30980. this.s = s;
  30981. }
  30982. ARCFourCipher.prototype = {
  30983. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  30984. var i, n = data.length, tmp, tmp2;
  30985. var a = this.a, b = this.b, s = this.s;
  30986. var output = new Uint8Array(n);
  30987. for (i = 0; i < n; ++i) {
  30988. a = a + 1 & 0xFF;
  30989. tmp = s[a];
  30990. b = b + tmp & 0xFF;
  30991. tmp2 = s[b];
  30992. s[a] = tmp2;
  30993. s[b] = tmp;
  30994. output[i] = data[i] ^ s[tmp + tmp2 & 0xFF];
  30995. }
  30996. this.a = a;
  30997. this.b = b;
  30998. return output;
  30999. }
  31000. };
  31001. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  31002. return ARCFourCipher;
  31003. }();
  31004. var calculateMD5 = function calculateMD5Closure() {
  31005. var r = new Uint8Array([
  31006. 7,
  31007. 12,
  31008. 17,
  31009. 22,
  31010. 7,
  31011. 12,
  31012. 17,
  31013. 22,
  31014. 7,
  31015. 12,
  31016. 17,
  31017. 22,
  31018. 7,
  31019. 12,
  31020. 17,
  31021. 22,
  31022. 5,
  31023. 9,
  31024. 14,
  31025. 20,
  31026. 5,
  31027. 9,
  31028. 14,
  31029. 20,
  31030. 5,
  31031. 9,
  31032. 14,
  31033. 20,
  31034. 5,
  31035. 9,
  31036. 14,
  31037. 20,
  31038. 4,
  31039. 11,
  31040. 16,
  31041. 23,
  31042. 4,
  31043. 11,
  31044. 16,
  31045. 23,
  31046. 4,
  31047. 11,
  31048. 16,
  31049. 23,
  31050. 4,
  31051. 11,
  31052. 16,
  31053. 23,
  31054. 6,
  31055. 10,
  31056. 15,
  31057. 21,
  31058. 6,
  31059. 10,
  31060. 15,
  31061. 21,
  31062. 6,
  31063. 10,
  31064. 15,
  31065. 21,
  31066. 6,
  31067. 10,
  31068. 15,
  31069. 21
  31070. ]);
  31071. var k = new Int32Array([
  31072. -680876936,
  31073. -389564586,
  31074. 606105819,
  31075. -1044525330,
  31076. -176418897,
  31077. 1200080426,
  31078. -1473231341,
  31079. -45705983,
  31080. 1770035416,
  31081. -1958414417,
  31082. -42063,
  31083. -1990404162,
  31084. 1804603682,
  31085. -40341101,
  31086. -1502002290,
  31087. 1236535329,
  31088. -165796510,
  31089. -1069501632,
  31090. 643717713,
  31091. -373897302,
  31092. -701558691,
  31093. 38016083,
  31094. -660478335,
  31095. -405537848,
  31096. 568446438,
  31097. -1019803690,
  31098. -187363961,
  31099. 1163531501,
  31100. -1444681467,
  31101. -51403784,
  31102. 1735328473,
  31103. -1926607734,
  31104. -378558,
  31105. -2022574463,
  31106. 1839030562,
  31107. -35309556,
  31108. -1530992060,
  31109. 1272893353,
  31110. -155497632,
  31111. -1094730640,
  31112. 681279174,
  31113. -358537222,
  31114. -722521979,
  31115. 76029189,
  31116. -640364487,
  31117. -421815835,
  31118. 530742520,
  31119. -995338651,
  31120. -198630844,
  31121. 1126891415,
  31122. -1416354905,
  31123. -57434055,
  31124. 1700485571,
  31125. -1894986606,
  31126. -1051523,
  31127. -2054922799,
  31128. 1873313359,
  31129. -30611744,
  31130. -1560198380,
  31131. 1309151649,
  31132. -145523070,
  31133. -1120210379,
  31134. 718787259,
  31135. -343485551
  31136. ]);
  31137. function hash(data, offset, length) {
  31138. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  31139. // pre-processing
  31140. var paddedLength = length + 72 & ~63;
  31141. // data + 9 extra bytes
  31142. var padded = new Uint8Array(paddedLength);
  31143. var i, j, n;
  31144. for (i = 0; i < length; ++i) {
  31145. padded[i] = data[offset++];
  31146. }
  31147. padded[i++] = 0x80;
  31148. n = paddedLength - 8;
  31149. while (i < n) {
  31150. padded[i++] = 0;
  31151. }
  31152. padded[i++] = length << 3 & 0xFF;
  31153. padded[i++] = length >> 5 & 0xFF;
  31154. padded[i++] = length >> 13 & 0xFF;
  31155. padded[i++] = length >> 21 & 0xFF;
  31156. padded[i++] = length >>> 29 & 0xFF;
  31157. padded[i++] = 0;
  31158. padded[i++] = 0;
  31159. padded[i++] = 0;
  31160. var w = new Int32Array(16);
  31161. for (i = 0; i < paddedLength;) {
  31162. for (j = 0; j < 16; ++j, i += 4) {
  31163. w[j] = padded[i] | padded[i + 1] << 8 | padded[i + 2] << 16 | padded[i + 3] << 24;
  31164. }
  31165. var a = h0, b = h1, c = h2, d = h3, f, g;
  31166. for (j = 0; j < 64; ++j) {
  31167. if (j < 16) {
  31168. f = b & c | ~b & d;
  31169. g = j;
  31170. } else if (j < 32) {
  31171. f = d & b | ~d & c;
  31172. g = 5 * j + 1 & 15;
  31173. } else if (j < 48) {
  31174. f = b ^ c ^ d;
  31175. g = 3 * j + 5 & 15;
  31176. } else {
  31177. f = c ^ (b | ~d);
  31178. g = 7 * j & 15;
  31179. }
  31180. var tmp = d, rotateArg = a + f + k[j] + w[g] | 0, rotate = r[j];
  31181. d = c;
  31182. c = b;
  31183. b = b + (rotateArg << rotate | rotateArg >>> 32 - rotate) | 0;
  31184. a = tmp;
  31185. }
  31186. h0 = h0 + a | 0;
  31187. h1 = h1 + b | 0;
  31188. h2 = h2 + c | 0;
  31189. h3 = h3 + d | 0;
  31190. }
  31191. return new Uint8Array([
  31192. h0 & 0xFF,
  31193. h0 >> 8 & 0xFF,
  31194. h0 >> 16 & 0xFF,
  31195. h0 >>> 24 & 0xFF,
  31196. h1 & 0xFF,
  31197. h1 >> 8 & 0xFF,
  31198. h1 >> 16 & 0xFF,
  31199. h1 >>> 24 & 0xFF,
  31200. h2 & 0xFF,
  31201. h2 >> 8 & 0xFF,
  31202. h2 >> 16 & 0xFF,
  31203. h2 >>> 24 & 0xFF,
  31204. h3 & 0xFF,
  31205. h3 >> 8 & 0xFF,
  31206. h3 >> 16 & 0xFF,
  31207. h3 >>> 24 & 0xFF
  31208. ]);
  31209. }
  31210. return hash;
  31211. }();
  31212. var Word64 = function Word64Closure() {
  31213. function Word64(highInteger, lowInteger) {
  31214. this.high = highInteger | 0;
  31215. this.low = lowInteger | 0;
  31216. }
  31217. Word64.prototype = {
  31218. and: function Word64_and(word) {
  31219. this.high &= word.high;
  31220. this.low &= word.low;
  31221. },
  31222. xor: function Word64_xor(word) {
  31223. this.high ^= word.high;
  31224. this.low ^= word.low;
  31225. },
  31226. or: function Word64_or(word) {
  31227. this.high |= word.high;
  31228. this.low |= word.low;
  31229. },
  31230. shiftRight: function Word64_shiftRight(places) {
  31231. if (places >= 32) {
  31232. this.low = this.high >>> places - 32 | 0;
  31233. this.high = 0;
  31234. } else {
  31235. this.low = this.low >>> places | this.high << 32 - places;
  31236. this.high = this.high >>> places | 0;
  31237. }
  31238. },
  31239. shiftLeft: function Word64_shiftLeft(places) {
  31240. if (places >= 32) {
  31241. this.high = this.low << places - 32;
  31242. this.low = 0;
  31243. } else {
  31244. this.high = this.high << places | this.low >>> 32 - places;
  31245. this.low = this.low << places;
  31246. }
  31247. },
  31248. rotateRight: function Word64_rotateRight(places) {
  31249. var low, high;
  31250. if (places & 32) {
  31251. high = this.low;
  31252. low = this.high;
  31253. } else {
  31254. low = this.low;
  31255. high = this.high;
  31256. }
  31257. places &= 31;
  31258. this.low = low >>> places | high << 32 - places;
  31259. this.high = high >>> places | low << 32 - places;
  31260. },
  31261. not: function Word64_not() {
  31262. this.high = ~this.high;
  31263. this.low = ~this.low;
  31264. },
  31265. add: function Word64_add(word) {
  31266. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  31267. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  31268. if (lowAdd > 0xFFFFFFFF) {
  31269. highAdd += 1;
  31270. }
  31271. this.low = lowAdd | 0;
  31272. this.high = highAdd | 0;
  31273. },
  31274. copyTo: function Word64_copyTo(bytes, offset) {
  31275. bytes[offset] = this.high >>> 24 & 0xFF;
  31276. bytes[offset + 1] = this.high >> 16 & 0xFF;
  31277. bytes[offset + 2] = this.high >> 8 & 0xFF;
  31278. bytes[offset + 3] = this.high & 0xFF;
  31279. bytes[offset + 4] = this.low >>> 24 & 0xFF;
  31280. bytes[offset + 5] = this.low >> 16 & 0xFF;
  31281. bytes[offset + 6] = this.low >> 8 & 0xFF;
  31282. bytes[offset + 7] = this.low & 0xFF;
  31283. },
  31284. assign: function Word64_assign(word) {
  31285. this.high = word.high;
  31286. this.low = word.low;
  31287. }
  31288. };
  31289. return Word64;
  31290. }();
  31291. var calculateSHA256 = function calculateSHA256Closure() {
  31292. function rotr(x, n) {
  31293. return x >>> n | x << 32 - n;
  31294. }
  31295. function ch(x, y, z) {
  31296. return x & y ^ ~x & z;
  31297. }
  31298. function maj(x, y, z) {
  31299. return x & y ^ x & z ^ y & z;
  31300. }
  31301. function sigma(x) {
  31302. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  31303. }
  31304. function sigmaPrime(x) {
  31305. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  31306. }
  31307. function littleSigma(x) {
  31308. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  31309. }
  31310. function littleSigmaPrime(x) {
  31311. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  31312. }
  31313. var k = [
  31314. 0x428a2f98,
  31315. 0x71374491,
  31316. 0xb5c0fbcf,
  31317. 0xe9b5dba5,
  31318. 0x3956c25b,
  31319. 0x59f111f1,
  31320. 0x923f82a4,
  31321. 0xab1c5ed5,
  31322. 0xd807aa98,
  31323. 0x12835b01,
  31324. 0x243185be,
  31325. 0x550c7dc3,
  31326. 0x72be5d74,
  31327. 0x80deb1fe,
  31328. 0x9bdc06a7,
  31329. 0xc19bf174,
  31330. 0xe49b69c1,
  31331. 0xefbe4786,
  31332. 0x0fc19dc6,
  31333. 0x240ca1cc,
  31334. 0x2de92c6f,
  31335. 0x4a7484aa,
  31336. 0x5cb0a9dc,
  31337. 0x76f988da,
  31338. 0x983e5152,
  31339. 0xa831c66d,
  31340. 0xb00327c8,
  31341. 0xbf597fc7,
  31342. 0xc6e00bf3,
  31343. 0xd5a79147,
  31344. 0x06ca6351,
  31345. 0x14292967,
  31346. 0x27b70a85,
  31347. 0x2e1b2138,
  31348. 0x4d2c6dfc,
  31349. 0x53380d13,
  31350. 0x650a7354,
  31351. 0x766a0abb,
  31352. 0x81c2c92e,
  31353. 0x92722c85,
  31354. 0xa2bfe8a1,
  31355. 0xa81a664b,
  31356. 0xc24b8b70,
  31357. 0xc76c51a3,
  31358. 0xd192e819,
  31359. 0xd6990624,
  31360. 0xf40e3585,
  31361. 0x106aa070,
  31362. 0x19a4c116,
  31363. 0x1e376c08,
  31364. 0x2748774c,
  31365. 0x34b0bcb5,
  31366. 0x391c0cb3,
  31367. 0x4ed8aa4a,
  31368. 0x5b9cca4f,
  31369. 0x682e6ff3,
  31370. 0x748f82ee,
  31371. 0x78a5636f,
  31372. 0x84c87814,
  31373. 0x8cc70208,
  31374. 0x90befffa,
  31375. 0xa4506ceb,
  31376. 0xbef9a3f7,
  31377. 0xc67178f2
  31378. ];
  31379. function hash(data, offset, length) {
  31380. // initial hash values
  31381. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372, h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c, h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  31382. // pre-processing
  31383. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  31384. var padded = new Uint8Array(paddedLength);
  31385. var i, j, n;
  31386. for (i = 0; i < length; ++i) {
  31387. padded[i] = data[offset++];
  31388. }
  31389. padded[i++] = 0x80;
  31390. n = paddedLength - 8;
  31391. while (i < n) {
  31392. padded[i++] = 0;
  31393. }
  31394. padded[i++] = 0;
  31395. padded[i++] = 0;
  31396. padded[i++] = 0;
  31397. padded[i++] = length >>> 29 & 0xFF;
  31398. padded[i++] = length >> 21 & 0xFF;
  31399. padded[i++] = length >> 13 & 0xFF;
  31400. padded[i++] = length >> 5 & 0xFF;
  31401. padded[i++] = length << 3 & 0xFF;
  31402. var w = new Uint32Array(64);
  31403. // for each 512 bit block
  31404. for (i = 0; i < paddedLength;) {
  31405. for (j = 0; j < 16; ++j) {
  31406. w[j] = padded[i] << 24 | padded[i + 1] << 16 | padded[i + 2] << 8 | padded[i + 3];
  31407. i += 4;
  31408. }
  31409. for (j = 16; j < 64; ++j) {
  31410. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] + littleSigma(w[j - 15]) + w[j - 16] | 0;
  31411. }
  31412. var a = h0, b = h1, c = h2, d = h3, e = h4, f = h5, g = h6, h = h7, t1, t2;
  31413. for (j = 0; j < 64; ++j) {
  31414. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  31415. t2 = sigma(a) + maj(a, b, c);
  31416. h = g;
  31417. g = f;
  31418. f = e;
  31419. e = d + t1 | 0;
  31420. d = c;
  31421. c = b;
  31422. b = a;
  31423. a = t1 + t2 | 0;
  31424. }
  31425. h0 = h0 + a | 0;
  31426. h1 = h1 + b | 0;
  31427. h2 = h2 + c | 0;
  31428. h3 = h3 + d | 0;
  31429. h4 = h4 + e | 0;
  31430. h5 = h5 + f | 0;
  31431. h6 = h6 + g | 0;
  31432. h7 = h7 + h | 0;
  31433. }
  31434. return new Uint8Array([
  31435. h0 >> 24 & 0xFF,
  31436. h0 >> 16 & 0xFF,
  31437. h0 >> 8 & 0xFF,
  31438. h0 & 0xFF,
  31439. h1 >> 24 & 0xFF,
  31440. h1 >> 16 & 0xFF,
  31441. h1 >> 8 & 0xFF,
  31442. h1 & 0xFF,
  31443. h2 >> 24 & 0xFF,
  31444. h2 >> 16 & 0xFF,
  31445. h2 >> 8 & 0xFF,
  31446. h2 & 0xFF,
  31447. h3 >> 24 & 0xFF,
  31448. h3 >> 16 & 0xFF,
  31449. h3 >> 8 & 0xFF,
  31450. h3 & 0xFF,
  31451. h4 >> 24 & 0xFF,
  31452. h4 >> 16 & 0xFF,
  31453. h4 >> 8 & 0xFF,
  31454. h4 & 0xFF,
  31455. h5 >> 24 & 0xFF,
  31456. h5 >> 16 & 0xFF,
  31457. h5 >> 8 & 0xFF,
  31458. h5 & 0xFF,
  31459. h6 >> 24 & 0xFF,
  31460. h6 >> 16 & 0xFF,
  31461. h6 >> 8 & 0xFF,
  31462. h6 & 0xFF,
  31463. h7 >> 24 & 0xFF,
  31464. h7 >> 16 & 0xFF,
  31465. h7 >> 8 & 0xFF,
  31466. h7 & 0xFF
  31467. ]);
  31468. }
  31469. return hash;
  31470. }();
  31471. var calculateSHA512 = function calculateSHA512Closure() {
  31472. function ch(result, x, y, z, tmp) {
  31473. result.assign(x);
  31474. result.and(y);
  31475. tmp.assign(x);
  31476. tmp.not();
  31477. tmp.and(z);
  31478. result.xor(tmp);
  31479. }
  31480. function maj(result, x, y, z, tmp) {
  31481. result.assign(x);
  31482. result.and(y);
  31483. tmp.assign(x);
  31484. tmp.and(z);
  31485. result.xor(tmp);
  31486. tmp.assign(y);
  31487. tmp.and(z);
  31488. result.xor(tmp);
  31489. }
  31490. function sigma(result, x, tmp) {
  31491. result.assign(x);
  31492. result.rotateRight(28);
  31493. tmp.assign(x);
  31494. tmp.rotateRight(34);
  31495. result.xor(tmp);
  31496. tmp.assign(x);
  31497. tmp.rotateRight(39);
  31498. result.xor(tmp);
  31499. }
  31500. function sigmaPrime(result, x, tmp) {
  31501. result.assign(x);
  31502. result.rotateRight(14);
  31503. tmp.assign(x);
  31504. tmp.rotateRight(18);
  31505. result.xor(tmp);
  31506. tmp.assign(x);
  31507. tmp.rotateRight(41);
  31508. result.xor(tmp);
  31509. }
  31510. function littleSigma(result, x, tmp) {
  31511. result.assign(x);
  31512. result.rotateRight(1);
  31513. tmp.assign(x);
  31514. tmp.rotateRight(8);
  31515. result.xor(tmp);
  31516. tmp.assign(x);
  31517. tmp.shiftRight(7);
  31518. result.xor(tmp);
  31519. }
  31520. function littleSigmaPrime(result, x, tmp) {
  31521. result.assign(x);
  31522. result.rotateRight(19);
  31523. tmp.assign(x);
  31524. tmp.rotateRight(61);
  31525. result.xor(tmp);
  31526. tmp.assign(x);
  31527. tmp.shiftRight(6);
  31528. result.xor(tmp);
  31529. }
  31530. var k = [
  31531. new Word64(0x428a2f98, 0xd728ae22),
  31532. new Word64(0x71374491, 0x23ef65cd),
  31533. new Word64(0xb5c0fbcf, 0xec4d3b2f),
  31534. new Word64(0xe9b5dba5, 0x8189dbbc),
  31535. new Word64(0x3956c25b, 0xf348b538),
  31536. new Word64(0x59f111f1, 0xb605d019),
  31537. new Word64(0x923f82a4, 0xaf194f9b),
  31538. new Word64(0xab1c5ed5, 0xda6d8118),
  31539. new Word64(0xd807aa98, 0xa3030242),
  31540. new Word64(0x12835b01, 0x45706fbe),
  31541. new Word64(0x243185be, 0x4ee4b28c),
  31542. new Word64(0x550c7dc3, 0xd5ffb4e2),
  31543. new Word64(0x72be5d74, 0xf27b896f),
  31544. new Word64(0x80deb1fe, 0x3b1696b1),
  31545. new Word64(0x9bdc06a7, 0x25c71235),
  31546. new Word64(0xc19bf174, 0xcf692694),
  31547. new Word64(0xe49b69c1, 0x9ef14ad2),
  31548. new Word64(0xefbe4786, 0x384f25e3),
  31549. new Word64(0x0fc19dc6, 0x8b8cd5b5),
  31550. new Word64(0x240ca1cc, 0x77ac9c65),
  31551. new Word64(0x2de92c6f, 0x592b0275),
  31552. new Word64(0x4a7484aa, 0x6ea6e483),
  31553. new Word64(0x5cb0a9dc, 0xbd41fbd4),
  31554. new Word64(0x76f988da, 0x831153b5),
  31555. new Word64(0x983e5152, 0xee66dfab),
  31556. new Word64(0xa831c66d, 0x2db43210),
  31557. new Word64(0xb00327c8, 0x98fb213f),
  31558. new Word64(0xbf597fc7, 0xbeef0ee4),
  31559. new Word64(0xc6e00bf3, 0x3da88fc2),
  31560. new Word64(0xd5a79147, 0x930aa725),
  31561. new Word64(0x06ca6351, 0xe003826f),
  31562. new Word64(0x14292967, 0x0a0e6e70),
  31563. new Word64(0x27b70a85, 0x46d22ffc),
  31564. new Word64(0x2e1b2138, 0x5c26c926),
  31565. new Word64(0x4d2c6dfc, 0x5ac42aed),
  31566. new Word64(0x53380d13, 0x9d95b3df),
  31567. new Word64(0x650a7354, 0x8baf63de),
  31568. new Word64(0x766a0abb, 0x3c77b2a8),
  31569. new Word64(0x81c2c92e, 0x47edaee6),
  31570. new Word64(0x92722c85, 0x1482353b),
  31571. new Word64(0xa2bfe8a1, 0x4cf10364),
  31572. new Word64(0xa81a664b, 0xbc423001),
  31573. new Word64(0xc24b8b70, 0xd0f89791),
  31574. new Word64(0xc76c51a3, 0x0654be30),
  31575. new Word64(0xd192e819, 0xd6ef5218),
  31576. new Word64(0xd6990624, 0x5565a910),
  31577. new Word64(0xf40e3585, 0x5771202a),
  31578. new Word64(0x106aa070, 0x32bbd1b8),
  31579. new Word64(0x19a4c116, 0xb8d2d0c8),
  31580. new Word64(0x1e376c08, 0x5141ab53),
  31581. new Word64(0x2748774c, 0xdf8eeb99),
  31582. new Word64(0x34b0bcb5, 0xe19b48a8),
  31583. new Word64(0x391c0cb3, 0xc5c95a63),
  31584. new Word64(0x4ed8aa4a, 0xe3418acb),
  31585. new Word64(0x5b9cca4f, 0x7763e373),
  31586. new Word64(0x682e6ff3, 0xd6b2b8a3),
  31587. new Word64(0x748f82ee, 0x5defb2fc),
  31588. new Word64(0x78a5636f, 0x43172f60),
  31589. new Word64(0x84c87814, 0xa1f0ab72),
  31590. new Word64(0x8cc70208, 0x1a6439ec),
  31591. new Word64(0x90befffa, 0x23631e28),
  31592. new Word64(0xa4506ceb, 0xde82bde9),
  31593. new Word64(0xbef9a3f7, 0xb2c67915),
  31594. new Word64(0xc67178f2, 0xe372532b),
  31595. new Word64(0xca273ece, 0xea26619c),
  31596. new Word64(0xd186b8c7, 0x21c0c207),
  31597. new Word64(0xeada7dd6, 0xcde0eb1e),
  31598. new Word64(0xf57d4f7f, 0xee6ed178),
  31599. new Word64(0x06f067aa, 0x72176fba),
  31600. new Word64(0x0a637dc5, 0xa2c898a6),
  31601. new Word64(0x113f9804, 0xbef90dae),
  31602. new Word64(0x1b710b35, 0x131c471b),
  31603. new Word64(0x28db77f5, 0x23047d84),
  31604. new Word64(0x32caab7b, 0x40c72493),
  31605. new Word64(0x3c9ebe0a, 0x15c9bebc),
  31606. new Word64(0x431d67c4, 0x9c100d4c),
  31607. new Word64(0x4cc5d4be, 0xcb3e42b6),
  31608. new Word64(0x597f299c, 0xfc657e2a),
  31609. new Word64(0x5fcb6fab, 0x3ad6faec),
  31610. new Word64(0x6c44198c, 0x4a475817)
  31611. ];
  31612. function hash(data, offset, length, mode384) {
  31613. mode384 = !!mode384;
  31614. // initial hash values
  31615. var h0, h1, h2, h3, h4, h5, h6, h7;
  31616. if (!mode384) {
  31617. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  31618. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  31619. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  31620. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  31621. h4 = new Word64(0x510e527f, 0xade682d1);
  31622. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  31623. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  31624. h7 = new Word64(0x5be0cd19, 0x137e2179);
  31625. } else {
  31626. // SHA384 is exactly the same
  31627. // except with different starting values and a trimmed result
  31628. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  31629. h1 = new Word64(0x629a292a, 0x367cd507);
  31630. h2 = new Word64(0x9159015a, 0x3070dd17);
  31631. h3 = new Word64(0x152fecd8, 0xf70e5939);
  31632. h4 = new Word64(0x67332667, 0xffc00b31);
  31633. h5 = new Word64(0x8eb44a87, 0x68581511);
  31634. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  31635. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  31636. }
  31637. // pre-processing
  31638. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  31639. var padded = new Uint8Array(paddedLength);
  31640. var i, j, n;
  31641. for (i = 0; i < length; ++i) {
  31642. padded[i] = data[offset++];
  31643. }
  31644. padded[i++] = 0x80;
  31645. n = paddedLength - 16;
  31646. while (i < n) {
  31647. padded[i++] = 0;
  31648. }
  31649. padded[i++] = 0;
  31650. padded[i++] = 0;
  31651. padded[i++] = 0;
  31652. padded[i++] = 0;
  31653. padded[i++] = 0;
  31654. padded[i++] = 0;
  31655. padded[i++] = 0;
  31656. padded[i++] = 0;
  31657. padded[i++] = 0;
  31658. padded[i++] = 0;
  31659. padded[i++] = 0;
  31660. padded[i++] = length >>> 29 & 0xFF;
  31661. padded[i++] = length >> 21 & 0xFF;
  31662. padded[i++] = length >> 13 & 0xFF;
  31663. padded[i++] = length >> 5 & 0xFF;
  31664. padded[i++] = length << 3 & 0xFF;
  31665. var w = new Array(80);
  31666. for (i = 0; i < 80; i++) {
  31667. w[i] = new Word64(0, 0);
  31668. }
  31669. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  31670. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  31671. var g = new Word64(0, 0), h = new Word64(0, 0);
  31672. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  31673. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  31674. // for each 1024 bit block
  31675. for (i = 0; i < paddedLength;) {
  31676. for (j = 0; j < 16; ++j) {
  31677. w[j].high = padded[i] << 24 | padded[i + 1] << 16 | padded[i + 2] << 8 | padded[i + 3];
  31678. w[j].low = padded[i + 4] << 24 | padded[i + 5] << 16 | padded[i + 6] << 8 | padded[i + 7];
  31679. i += 8;
  31680. }
  31681. for (j = 16; j < 80; ++j) {
  31682. tmp3 = w[j];
  31683. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  31684. tmp3.add(w[j - 7]);
  31685. littleSigma(tmp1, w[j - 15], tmp2);
  31686. tmp3.add(tmp1);
  31687. tmp3.add(w[j - 16]);
  31688. }
  31689. a.assign(h0);
  31690. b.assign(h1);
  31691. c.assign(h2);
  31692. d.assign(h3);
  31693. e.assign(h4);
  31694. f.assign(h5);
  31695. g.assign(h6);
  31696. h.assign(h7);
  31697. for (j = 0; j < 80; ++j) {
  31698. t1.assign(h);
  31699. sigmaPrime(tmp1, e, tmp2);
  31700. t1.add(tmp1);
  31701. ch(tmp1, e, f, g, tmp2);
  31702. t1.add(tmp1);
  31703. t1.add(k[j]);
  31704. t1.add(w[j]);
  31705. sigma(t2, a, tmp2);
  31706. maj(tmp1, a, b, c, tmp2);
  31707. t2.add(tmp1);
  31708. tmp3 = h;
  31709. h = g;
  31710. g = f;
  31711. f = e;
  31712. d.add(t1);
  31713. e = d;
  31714. d = c;
  31715. c = b;
  31716. b = a;
  31717. tmp3.assign(t1);
  31718. tmp3.add(t2);
  31719. a = tmp3;
  31720. }
  31721. h0.add(a);
  31722. h1.add(b);
  31723. h2.add(c);
  31724. h3.add(d);
  31725. h4.add(e);
  31726. h5.add(f);
  31727. h6.add(g);
  31728. h7.add(h);
  31729. }
  31730. var result;
  31731. if (!mode384) {
  31732. result = new Uint8Array(64);
  31733. h0.copyTo(result, 0);
  31734. h1.copyTo(result, 8);
  31735. h2.copyTo(result, 16);
  31736. h3.copyTo(result, 24);
  31737. h4.copyTo(result, 32);
  31738. h5.copyTo(result, 40);
  31739. h6.copyTo(result, 48);
  31740. h7.copyTo(result, 56);
  31741. } else {
  31742. result = new Uint8Array(48);
  31743. h0.copyTo(result, 0);
  31744. h1.copyTo(result, 8);
  31745. h2.copyTo(result, 16);
  31746. h3.copyTo(result, 24);
  31747. h4.copyTo(result, 32);
  31748. h5.copyTo(result, 40);
  31749. }
  31750. return result;
  31751. }
  31752. return hash;
  31753. }();
  31754. var calculateSHA384 = function calculateSHA384Closure() {
  31755. function hash(data, offset, length) {
  31756. return calculateSHA512(data, offset, length, true);
  31757. }
  31758. return hash;
  31759. }();
  31760. var NullCipher = function NullCipherClosure() {
  31761. function NullCipher() {
  31762. }
  31763. NullCipher.prototype = {
  31764. decryptBlock: function NullCipher_decryptBlock(data) {
  31765. return data;
  31766. }
  31767. };
  31768. return NullCipher;
  31769. }();
  31770. var AES128Cipher = function AES128CipherClosure() {
  31771. var rcon = new Uint8Array([
  31772. 0x8d,
  31773. 0x01,
  31774. 0x02,
  31775. 0x04,
  31776. 0x08,
  31777. 0x10,
  31778. 0x20,
  31779. 0x40,
  31780. 0x80,
  31781. 0x1b,
  31782. 0x36,
  31783. 0x6c,
  31784. 0xd8,
  31785. 0xab,
  31786. 0x4d,
  31787. 0x9a,
  31788. 0x2f,
  31789. 0x5e,
  31790. 0xbc,
  31791. 0x63,
  31792. 0xc6,
  31793. 0x97,
  31794. 0x35,
  31795. 0x6a,
  31796. 0xd4,
  31797. 0xb3,
  31798. 0x7d,
  31799. 0xfa,
  31800. 0xef,
  31801. 0xc5,
  31802. 0x91,
  31803. 0x39,
  31804. 0x72,
  31805. 0xe4,
  31806. 0xd3,
  31807. 0xbd,
  31808. 0x61,
  31809. 0xc2,
  31810. 0x9f,
  31811. 0x25,
  31812. 0x4a,
  31813. 0x94,
  31814. 0x33,
  31815. 0x66,
  31816. 0xcc,
  31817. 0x83,
  31818. 0x1d,
  31819. 0x3a,
  31820. 0x74,
  31821. 0xe8,
  31822. 0xcb,
  31823. 0x8d,
  31824. 0x01,
  31825. 0x02,
  31826. 0x04,
  31827. 0x08,
  31828. 0x10,
  31829. 0x20,
  31830. 0x40,
  31831. 0x80,
  31832. 0x1b,
  31833. 0x36,
  31834. 0x6c,
  31835. 0xd8,
  31836. 0xab,
  31837. 0x4d,
  31838. 0x9a,
  31839. 0x2f,
  31840. 0x5e,
  31841. 0xbc,
  31842. 0x63,
  31843. 0xc6,
  31844. 0x97,
  31845. 0x35,
  31846. 0x6a,
  31847. 0xd4,
  31848. 0xb3,
  31849. 0x7d,
  31850. 0xfa,
  31851. 0xef,
  31852. 0xc5,
  31853. 0x91,
  31854. 0x39,
  31855. 0x72,
  31856. 0xe4,
  31857. 0xd3,
  31858. 0xbd,
  31859. 0x61,
  31860. 0xc2,
  31861. 0x9f,
  31862. 0x25,
  31863. 0x4a,
  31864. 0x94,
  31865. 0x33,
  31866. 0x66,
  31867. 0xcc,
  31868. 0x83,
  31869. 0x1d,
  31870. 0x3a,
  31871. 0x74,
  31872. 0xe8,
  31873. 0xcb,
  31874. 0x8d,
  31875. 0x01,
  31876. 0x02,
  31877. 0x04,
  31878. 0x08,
  31879. 0x10,
  31880. 0x20,
  31881. 0x40,
  31882. 0x80,
  31883. 0x1b,
  31884. 0x36,
  31885. 0x6c,
  31886. 0xd8,
  31887. 0xab,
  31888. 0x4d,
  31889. 0x9a,
  31890. 0x2f,
  31891. 0x5e,
  31892. 0xbc,
  31893. 0x63,
  31894. 0xc6,
  31895. 0x97,
  31896. 0x35,
  31897. 0x6a,
  31898. 0xd4,
  31899. 0xb3,
  31900. 0x7d,
  31901. 0xfa,
  31902. 0xef,
  31903. 0xc5,
  31904. 0x91,
  31905. 0x39,
  31906. 0x72,
  31907. 0xe4,
  31908. 0xd3,
  31909. 0xbd,
  31910. 0x61,
  31911. 0xc2,
  31912. 0x9f,
  31913. 0x25,
  31914. 0x4a,
  31915. 0x94,
  31916. 0x33,
  31917. 0x66,
  31918. 0xcc,
  31919. 0x83,
  31920. 0x1d,
  31921. 0x3a,
  31922. 0x74,
  31923. 0xe8,
  31924. 0xcb,
  31925. 0x8d,
  31926. 0x01,
  31927. 0x02,
  31928. 0x04,
  31929. 0x08,
  31930. 0x10,
  31931. 0x20,
  31932. 0x40,
  31933. 0x80,
  31934. 0x1b,
  31935. 0x36,
  31936. 0x6c,
  31937. 0xd8,
  31938. 0xab,
  31939. 0x4d,
  31940. 0x9a,
  31941. 0x2f,
  31942. 0x5e,
  31943. 0xbc,
  31944. 0x63,
  31945. 0xc6,
  31946. 0x97,
  31947. 0x35,
  31948. 0x6a,
  31949. 0xd4,
  31950. 0xb3,
  31951. 0x7d,
  31952. 0xfa,
  31953. 0xef,
  31954. 0xc5,
  31955. 0x91,
  31956. 0x39,
  31957. 0x72,
  31958. 0xe4,
  31959. 0xd3,
  31960. 0xbd,
  31961. 0x61,
  31962. 0xc2,
  31963. 0x9f,
  31964. 0x25,
  31965. 0x4a,
  31966. 0x94,
  31967. 0x33,
  31968. 0x66,
  31969. 0xcc,
  31970. 0x83,
  31971. 0x1d,
  31972. 0x3a,
  31973. 0x74,
  31974. 0xe8,
  31975. 0xcb,
  31976. 0x8d,
  31977. 0x01,
  31978. 0x02,
  31979. 0x04,
  31980. 0x08,
  31981. 0x10,
  31982. 0x20,
  31983. 0x40,
  31984. 0x80,
  31985. 0x1b,
  31986. 0x36,
  31987. 0x6c,
  31988. 0xd8,
  31989. 0xab,
  31990. 0x4d,
  31991. 0x9a,
  31992. 0x2f,
  31993. 0x5e,
  31994. 0xbc,
  31995. 0x63,
  31996. 0xc6,
  31997. 0x97,
  31998. 0x35,
  31999. 0x6a,
  32000. 0xd4,
  32001. 0xb3,
  32002. 0x7d,
  32003. 0xfa,
  32004. 0xef,
  32005. 0xc5,
  32006. 0x91,
  32007. 0x39,
  32008. 0x72,
  32009. 0xe4,
  32010. 0xd3,
  32011. 0xbd,
  32012. 0x61,
  32013. 0xc2,
  32014. 0x9f,
  32015. 0x25,
  32016. 0x4a,
  32017. 0x94,
  32018. 0x33,
  32019. 0x66,
  32020. 0xcc,
  32021. 0x83,
  32022. 0x1d,
  32023. 0x3a,
  32024. 0x74,
  32025. 0xe8,
  32026. 0xcb,
  32027. 0x8d
  32028. ]);
  32029. var s = new Uint8Array([
  32030. 0x63,
  32031. 0x7c,
  32032. 0x77,
  32033. 0x7b,
  32034. 0xf2,
  32035. 0x6b,
  32036. 0x6f,
  32037. 0xc5,
  32038. 0x30,
  32039. 0x01,
  32040. 0x67,
  32041. 0x2b,
  32042. 0xfe,
  32043. 0xd7,
  32044. 0xab,
  32045. 0x76,
  32046. 0xca,
  32047. 0x82,
  32048. 0xc9,
  32049. 0x7d,
  32050. 0xfa,
  32051. 0x59,
  32052. 0x47,
  32053. 0xf0,
  32054. 0xad,
  32055. 0xd4,
  32056. 0xa2,
  32057. 0xaf,
  32058. 0x9c,
  32059. 0xa4,
  32060. 0x72,
  32061. 0xc0,
  32062. 0xb7,
  32063. 0xfd,
  32064. 0x93,
  32065. 0x26,
  32066. 0x36,
  32067. 0x3f,
  32068. 0xf7,
  32069. 0xcc,
  32070. 0x34,
  32071. 0xa5,
  32072. 0xe5,
  32073. 0xf1,
  32074. 0x71,
  32075. 0xd8,
  32076. 0x31,
  32077. 0x15,
  32078. 0x04,
  32079. 0xc7,
  32080. 0x23,
  32081. 0xc3,
  32082. 0x18,
  32083. 0x96,
  32084. 0x05,
  32085. 0x9a,
  32086. 0x07,
  32087. 0x12,
  32088. 0x80,
  32089. 0xe2,
  32090. 0xeb,
  32091. 0x27,
  32092. 0xb2,
  32093. 0x75,
  32094. 0x09,
  32095. 0x83,
  32096. 0x2c,
  32097. 0x1a,
  32098. 0x1b,
  32099. 0x6e,
  32100. 0x5a,
  32101. 0xa0,
  32102. 0x52,
  32103. 0x3b,
  32104. 0xd6,
  32105. 0xb3,
  32106. 0x29,
  32107. 0xe3,
  32108. 0x2f,
  32109. 0x84,
  32110. 0x53,
  32111. 0xd1,
  32112. 0x00,
  32113. 0xed,
  32114. 0x20,
  32115. 0xfc,
  32116. 0xb1,
  32117. 0x5b,
  32118. 0x6a,
  32119. 0xcb,
  32120. 0xbe,
  32121. 0x39,
  32122. 0x4a,
  32123. 0x4c,
  32124. 0x58,
  32125. 0xcf,
  32126. 0xd0,
  32127. 0xef,
  32128. 0xaa,
  32129. 0xfb,
  32130. 0x43,
  32131. 0x4d,
  32132. 0x33,
  32133. 0x85,
  32134. 0x45,
  32135. 0xf9,
  32136. 0x02,
  32137. 0x7f,
  32138. 0x50,
  32139. 0x3c,
  32140. 0x9f,
  32141. 0xa8,
  32142. 0x51,
  32143. 0xa3,
  32144. 0x40,
  32145. 0x8f,
  32146. 0x92,
  32147. 0x9d,
  32148. 0x38,
  32149. 0xf5,
  32150. 0xbc,
  32151. 0xb6,
  32152. 0xda,
  32153. 0x21,
  32154. 0x10,
  32155. 0xff,
  32156. 0xf3,
  32157. 0xd2,
  32158. 0xcd,
  32159. 0x0c,
  32160. 0x13,
  32161. 0xec,
  32162. 0x5f,
  32163. 0x97,
  32164. 0x44,
  32165. 0x17,
  32166. 0xc4,
  32167. 0xa7,
  32168. 0x7e,
  32169. 0x3d,
  32170. 0x64,
  32171. 0x5d,
  32172. 0x19,
  32173. 0x73,
  32174. 0x60,
  32175. 0x81,
  32176. 0x4f,
  32177. 0xdc,
  32178. 0x22,
  32179. 0x2a,
  32180. 0x90,
  32181. 0x88,
  32182. 0x46,
  32183. 0xee,
  32184. 0xb8,
  32185. 0x14,
  32186. 0xde,
  32187. 0x5e,
  32188. 0x0b,
  32189. 0xdb,
  32190. 0xe0,
  32191. 0x32,
  32192. 0x3a,
  32193. 0x0a,
  32194. 0x49,
  32195. 0x06,
  32196. 0x24,
  32197. 0x5c,
  32198. 0xc2,
  32199. 0xd3,
  32200. 0xac,
  32201. 0x62,
  32202. 0x91,
  32203. 0x95,
  32204. 0xe4,
  32205. 0x79,
  32206. 0xe7,
  32207. 0xc8,
  32208. 0x37,
  32209. 0x6d,
  32210. 0x8d,
  32211. 0xd5,
  32212. 0x4e,
  32213. 0xa9,
  32214. 0x6c,
  32215. 0x56,
  32216. 0xf4,
  32217. 0xea,
  32218. 0x65,
  32219. 0x7a,
  32220. 0xae,
  32221. 0x08,
  32222. 0xba,
  32223. 0x78,
  32224. 0x25,
  32225. 0x2e,
  32226. 0x1c,
  32227. 0xa6,
  32228. 0xb4,
  32229. 0xc6,
  32230. 0xe8,
  32231. 0xdd,
  32232. 0x74,
  32233. 0x1f,
  32234. 0x4b,
  32235. 0xbd,
  32236. 0x8b,
  32237. 0x8a,
  32238. 0x70,
  32239. 0x3e,
  32240. 0xb5,
  32241. 0x66,
  32242. 0x48,
  32243. 0x03,
  32244. 0xf6,
  32245. 0x0e,
  32246. 0x61,
  32247. 0x35,
  32248. 0x57,
  32249. 0xb9,
  32250. 0x86,
  32251. 0xc1,
  32252. 0x1d,
  32253. 0x9e,
  32254. 0xe1,
  32255. 0xf8,
  32256. 0x98,
  32257. 0x11,
  32258. 0x69,
  32259. 0xd9,
  32260. 0x8e,
  32261. 0x94,
  32262. 0x9b,
  32263. 0x1e,
  32264. 0x87,
  32265. 0xe9,
  32266. 0xce,
  32267. 0x55,
  32268. 0x28,
  32269. 0xdf,
  32270. 0x8c,
  32271. 0xa1,
  32272. 0x89,
  32273. 0x0d,
  32274. 0xbf,
  32275. 0xe6,
  32276. 0x42,
  32277. 0x68,
  32278. 0x41,
  32279. 0x99,
  32280. 0x2d,
  32281. 0x0f,
  32282. 0xb0,
  32283. 0x54,
  32284. 0xbb,
  32285. 0x16
  32286. ]);
  32287. var inv_s = new Uint8Array([
  32288. 0x52,
  32289. 0x09,
  32290. 0x6a,
  32291. 0xd5,
  32292. 0x30,
  32293. 0x36,
  32294. 0xa5,
  32295. 0x38,
  32296. 0xbf,
  32297. 0x40,
  32298. 0xa3,
  32299. 0x9e,
  32300. 0x81,
  32301. 0xf3,
  32302. 0xd7,
  32303. 0xfb,
  32304. 0x7c,
  32305. 0xe3,
  32306. 0x39,
  32307. 0x82,
  32308. 0x9b,
  32309. 0x2f,
  32310. 0xff,
  32311. 0x87,
  32312. 0x34,
  32313. 0x8e,
  32314. 0x43,
  32315. 0x44,
  32316. 0xc4,
  32317. 0xde,
  32318. 0xe9,
  32319. 0xcb,
  32320. 0x54,
  32321. 0x7b,
  32322. 0x94,
  32323. 0x32,
  32324. 0xa6,
  32325. 0xc2,
  32326. 0x23,
  32327. 0x3d,
  32328. 0xee,
  32329. 0x4c,
  32330. 0x95,
  32331. 0x0b,
  32332. 0x42,
  32333. 0xfa,
  32334. 0xc3,
  32335. 0x4e,
  32336. 0x08,
  32337. 0x2e,
  32338. 0xa1,
  32339. 0x66,
  32340. 0x28,
  32341. 0xd9,
  32342. 0x24,
  32343. 0xb2,
  32344. 0x76,
  32345. 0x5b,
  32346. 0xa2,
  32347. 0x49,
  32348. 0x6d,
  32349. 0x8b,
  32350. 0xd1,
  32351. 0x25,
  32352. 0x72,
  32353. 0xf8,
  32354. 0xf6,
  32355. 0x64,
  32356. 0x86,
  32357. 0x68,
  32358. 0x98,
  32359. 0x16,
  32360. 0xd4,
  32361. 0xa4,
  32362. 0x5c,
  32363. 0xcc,
  32364. 0x5d,
  32365. 0x65,
  32366. 0xb6,
  32367. 0x92,
  32368. 0x6c,
  32369. 0x70,
  32370. 0x48,
  32371. 0x50,
  32372. 0xfd,
  32373. 0xed,
  32374. 0xb9,
  32375. 0xda,
  32376. 0x5e,
  32377. 0x15,
  32378. 0x46,
  32379. 0x57,
  32380. 0xa7,
  32381. 0x8d,
  32382. 0x9d,
  32383. 0x84,
  32384. 0x90,
  32385. 0xd8,
  32386. 0xab,
  32387. 0x00,
  32388. 0x8c,
  32389. 0xbc,
  32390. 0xd3,
  32391. 0x0a,
  32392. 0xf7,
  32393. 0xe4,
  32394. 0x58,
  32395. 0x05,
  32396. 0xb8,
  32397. 0xb3,
  32398. 0x45,
  32399. 0x06,
  32400. 0xd0,
  32401. 0x2c,
  32402. 0x1e,
  32403. 0x8f,
  32404. 0xca,
  32405. 0x3f,
  32406. 0x0f,
  32407. 0x02,
  32408. 0xc1,
  32409. 0xaf,
  32410. 0xbd,
  32411. 0x03,
  32412. 0x01,
  32413. 0x13,
  32414. 0x8a,
  32415. 0x6b,
  32416. 0x3a,
  32417. 0x91,
  32418. 0x11,
  32419. 0x41,
  32420. 0x4f,
  32421. 0x67,
  32422. 0xdc,
  32423. 0xea,
  32424. 0x97,
  32425. 0xf2,
  32426. 0xcf,
  32427. 0xce,
  32428. 0xf0,
  32429. 0xb4,
  32430. 0xe6,
  32431. 0x73,
  32432. 0x96,
  32433. 0xac,
  32434. 0x74,
  32435. 0x22,
  32436. 0xe7,
  32437. 0xad,
  32438. 0x35,
  32439. 0x85,
  32440. 0xe2,
  32441. 0xf9,
  32442. 0x37,
  32443. 0xe8,
  32444. 0x1c,
  32445. 0x75,
  32446. 0xdf,
  32447. 0x6e,
  32448. 0x47,
  32449. 0xf1,
  32450. 0x1a,
  32451. 0x71,
  32452. 0x1d,
  32453. 0x29,
  32454. 0xc5,
  32455. 0x89,
  32456. 0x6f,
  32457. 0xb7,
  32458. 0x62,
  32459. 0x0e,
  32460. 0xaa,
  32461. 0x18,
  32462. 0xbe,
  32463. 0x1b,
  32464. 0xfc,
  32465. 0x56,
  32466. 0x3e,
  32467. 0x4b,
  32468. 0xc6,
  32469. 0xd2,
  32470. 0x79,
  32471. 0x20,
  32472. 0x9a,
  32473. 0xdb,
  32474. 0xc0,
  32475. 0xfe,
  32476. 0x78,
  32477. 0xcd,
  32478. 0x5a,
  32479. 0xf4,
  32480. 0x1f,
  32481. 0xdd,
  32482. 0xa8,
  32483. 0x33,
  32484. 0x88,
  32485. 0x07,
  32486. 0xc7,
  32487. 0x31,
  32488. 0xb1,
  32489. 0x12,
  32490. 0x10,
  32491. 0x59,
  32492. 0x27,
  32493. 0x80,
  32494. 0xec,
  32495. 0x5f,
  32496. 0x60,
  32497. 0x51,
  32498. 0x7f,
  32499. 0xa9,
  32500. 0x19,
  32501. 0xb5,
  32502. 0x4a,
  32503. 0x0d,
  32504. 0x2d,
  32505. 0xe5,
  32506. 0x7a,
  32507. 0x9f,
  32508. 0x93,
  32509. 0xc9,
  32510. 0x9c,
  32511. 0xef,
  32512. 0xa0,
  32513. 0xe0,
  32514. 0x3b,
  32515. 0x4d,
  32516. 0xae,
  32517. 0x2a,
  32518. 0xf5,
  32519. 0xb0,
  32520. 0xc8,
  32521. 0xeb,
  32522. 0xbb,
  32523. 0x3c,
  32524. 0x83,
  32525. 0x53,
  32526. 0x99,
  32527. 0x61,
  32528. 0x17,
  32529. 0x2b,
  32530. 0x04,
  32531. 0x7e,
  32532. 0xba,
  32533. 0x77,
  32534. 0xd6,
  32535. 0x26,
  32536. 0xe1,
  32537. 0x69,
  32538. 0x14,
  32539. 0x63,
  32540. 0x55,
  32541. 0x21,
  32542. 0x0c,
  32543. 0x7d
  32544. ]);
  32545. var mixCol = new Uint8Array(256);
  32546. for (var i = 0; i < 256; i++) {
  32547. if (i < 128) {
  32548. mixCol[i] = i << 1;
  32549. } else {
  32550. mixCol[i] = i << 1 ^ 0x1b;
  32551. }
  32552. }
  32553. var mix = new Uint32Array([
  32554. 0x00000000,
  32555. 0x0e090d0b,
  32556. 0x1c121a16,
  32557. 0x121b171d,
  32558. 0x3824342c,
  32559. 0x362d3927,
  32560. 0x24362e3a,
  32561. 0x2a3f2331,
  32562. 0x70486858,
  32563. 0x7e416553,
  32564. 0x6c5a724e,
  32565. 0x62537f45,
  32566. 0x486c5c74,
  32567. 0x4665517f,
  32568. 0x547e4662,
  32569. 0x5a774b69,
  32570. 0xe090d0b0,
  32571. 0xee99ddbb,
  32572. 0xfc82caa6,
  32573. 0xf28bc7ad,
  32574. 0xd8b4e49c,
  32575. 0xd6bde997,
  32576. 0xc4a6fe8a,
  32577. 0xcaaff381,
  32578. 0x90d8b8e8,
  32579. 0x9ed1b5e3,
  32580. 0x8ccaa2fe,
  32581. 0x82c3aff5,
  32582. 0xa8fc8cc4,
  32583. 0xa6f581cf,
  32584. 0xb4ee96d2,
  32585. 0xbae79bd9,
  32586. 0xdb3bbb7b,
  32587. 0xd532b670,
  32588. 0xc729a16d,
  32589. 0xc920ac66,
  32590. 0xe31f8f57,
  32591. 0xed16825c,
  32592. 0xff0d9541,
  32593. 0xf104984a,
  32594. 0xab73d323,
  32595. 0xa57ade28,
  32596. 0xb761c935,
  32597. 0xb968c43e,
  32598. 0x9357e70f,
  32599. 0x9d5eea04,
  32600. 0x8f45fd19,
  32601. 0x814cf012,
  32602. 0x3bab6bcb,
  32603. 0x35a266c0,
  32604. 0x27b971dd,
  32605. 0x29b07cd6,
  32606. 0x038f5fe7,
  32607. 0x0d8652ec,
  32608. 0x1f9d45f1,
  32609. 0x119448fa,
  32610. 0x4be30393,
  32611. 0x45ea0e98,
  32612. 0x57f11985,
  32613. 0x59f8148e,
  32614. 0x73c737bf,
  32615. 0x7dce3ab4,
  32616. 0x6fd52da9,
  32617. 0x61dc20a2,
  32618. 0xad766df6,
  32619. 0xa37f60fd,
  32620. 0xb16477e0,
  32621. 0xbf6d7aeb,
  32622. 0x955259da,
  32623. 0x9b5b54d1,
  32624. 0x894043cc,
  32625. 0x87494ec7,
  32626. 0xdd3e05ae,
  32627. 0xd33708a5,
  32628. 0xc12c1fb8,
  32629. 0xcf2512b3,
  32630. 0xe51a3182,
  32631. 0xeb133c89,
  32632. 0xf9082b94,
  32633. 0xf701269f,
  32634. 0x4de6bd46,
  32635. 0x43efb04d,
  32636. 0x51f4a750,
  32637. 0x5ffdaa5b,
  32638. 0x75c2896a,
  32639. 0x7bcb8461,
  32640. 0x69d0937c,
  32641. 0x67d99e77,
  32642. 0x3daed51e,
  32643. 0x33a7d815,
  32644. 0x21bccf08,
  32645. 0x2fb5c203,
  32646. 0x058ae132,
  32647. 0x0b83ec39,
  32648. 0x1998fb24,
  32649. 0x1791f62f,
  32650. 0x764dd68d,
  32651. 0x7844db86,
  32652. 0x6a5fcc9b,
  32653. 0x6456c190,
  32654. 0x4e69e2a1,
  32655. 0x4060efaa,
  32656. 0x527bf8b7,
  32657. 0x5c72f5bc,
  32658. 0x0605bed5,
  32659. 0x080cb3de,
  32660. 0x1a17a4c3,
  32661. 0x141ea9c8,
  32662. 0x3e218af9,
  32663. 0x302887f2,
  32664. 0x223390ef,
  32665. 0x2c3a9de4,
  32666. 0x96dd063d,
  32667. 0x98d40b36,
  32668. 0x8acf1c2b,
  32669. 0x84c61120,
  32670. 0xaef93211,
  32671. 0xa0f03f1a,
  32672. 0xb2eb2807,
  32673. 0xbce2250c,
  32674. 0xe6956e65,
  32675. 0xe89c636e,
  32676. 0xfa877473,
  32677. 0xf48e7978,
  32678. 0xdeb15a49,
  32679. 0xd0b85742,
  32680. 0xc2a3405f,
  32681. 0xccaa4d54,
  32682. 0x41ecdaf7,
  32683. 0x4fe5d7fc,
  32684. 0x5dfec0e1,
  32685. 0x53f7cdea,
  32686. 0x79c8eedb,
  32687. 0x77c1e3d0,
  32688. 0x65daf4cd,
  32689. 0x6bd3f9c6,
  32690. 0x31a4b2af,
  32691. 0x3fadbfa4,
  32692. 0x2db6a8b9,
  32693. 0x23bfa5b2,
  32694. 0x09808683,
  32695. 0x07898b88,
  32696. 0x15929c95,
  32697. 0x1b9b919e,
  32698. 0xa17c0a47,
  32699. 0xaf75074c,
  32700. 0xbd6e1051,
  32701. 0xb3671d5a,
  32702. 0x99583e6b,
  32703. 0x97513360,
  32704. 0x854a247d,
  32705. 0x8b432976,
  32706. 0xd134621f,
  32707. 0xdf3d6f14,
  32708. 0xcd267809,
  32709. 0xc32f7502,
  32710. 0xe9105633,
  32711. 0xe7195b38,
  32712. 0xf5024c25,
  32713. 0xfb0b412e,
  32714. 0x9ad7618c,
  32715. 0x94de6c87,
  32716. 0x86c57b9a,
  32717. 0x88cc7691,
  32718. 0xa2f355a0,
  32719. 0xacfa58ab,
  32720. 0xbee14fb6,
  32721. 0xb0e842bd,
  32722. 0xea9f09d4,
  32723. 0xe49604df,
  32724. 0xf68d13c2,
  32725. 0xf8841ec9,
  32726. 0xd2bb3df8,
  32727. 0xdcb230f3,
  32728. 0xcea927ee,
  32729. 0xc0a02ae5,
  32730. 0x7a47b13c,
  32731. 0x744ebc37,
  32732. 0x6655ab2a,
  32733. 0x685ca621,
  32734. 0x42638510,
  32735. 0x4c6a881b,
  32736. 0x5e719f06,
  32737. 0x5078920d,
  32738. 0x0a0fd964,
  32739. 0x0406d46f,
  32740. 0x161dc372,
  32741. 0x1814ce79,
  32742. 0x322bed48,
  32743. 0x3c22e043,
  32744. 0x2e39f75e,
  32745. 0x2030fa55,
  32746. 0xec9ab701,
  32747. 0xe293ba0a,
  32748. 0xf088ad17,
  32749. 0xfe81a01c,
  32750. 0xd4be832d,
  32751. 0xdab78e26,
  32752. 0xc8ac993b,
  32753. 0xc6a59430,
  32754. 0x9cd2df59,
  32755. 0x92dbd252,
  32756. 0x80c0c54f,
  32757. 0x8ec9c844,
  32758. 0xa4f6eb75,
  32759. 0xaaffe67e,
  32760. 0xb8e4f163,
  32761. 0xb6edfc68,
  32762. 0x0c0a67b1,
  32763. 0x02036aba,
  32764. 0x10187da7,
  32765. 0x1e1170ac,
  32766. 0x342e539d,
  32767. 0x3a275e96,
  32768. 0x283c498b,
  32769. 0x26354480,
  32770. 0x7c420fe9,
  32771. 0x724b02e2,
  32772. 0x605015ff,
  32773. 0x6e5918f4,
  32774. 0x44663bc5,
  32775. 0x4a6f36ce,
  32776. 0x587421d3,
  32777. 0x567d2cd8,
  32778. 0x37a10c7a,
  32779. 0x39a80171,
  32780. 0x2bb3166c,
  32781. 0x25ba1b67,
  32782. 0x0f853856,
  32783. 0x018c355d,
  32784. 0x13972240,
  32785. 0x1d9e2f4b,
  32786. 0x47e96422,
  32787. 0x49e06929,
  32788. 0x5bfb7e34,
  32789. 0x55f2733f,
  32790. 0x7fcd500e,
  32791. 0x71c45d05,
  32792. 0x63df4a18,
  32793. 0x6dd64713,
  32794. 0xd731dcca,
  32795. 0xd938d1c1,
  32796. 0xcb23c6dc,
  32797. 0xc52acbd7,
  32798. 0xef15e8e6,
  32799. 0xe11ce5ed,
  32800. 0xf307f2f0,
  32801. 0xfd0efffb,
  32802. 0xa779b492,
  32803. 0xa970b999,
  32804. 0xbb6bae84,
  32805. 0xb562a38f,
  32806. 0x9f5d80be,
  32807. 0x91548db5,
  32808. 0x834f9aa8,
  32809. 0x8d4697a3
  32810. ]);
  32811. function expandKey128(cipherKey) {
  32812. var b = 176, result = new Uint8Array(b);
  32813. result.set(cipherKey);
  32814. for (var j = 16, i = 1; j < b; ++i) {
  32815. // RotWord
  32816. var t1 = result[j - 3], t2 = result[j - 2], t3 = result[j - 1], t4 = result[j - 4];
  32817. // SubWord
  32818. t1 = s[t1];
  32819. t2 = s[t2];
  32820. t3 = s[t3];
  32821. t4 = s[t4];
  32822. // Rcon
  32823. t1 = t1 ^ rcon[i];
  32824. for (var n = 0; n < 4; ++n) {
  32825. result[j] = t1 ^= result[j - 16];
  32826. j++;
  32827. result[j] = t2 ^= result[j - 16];
  32828. j++;
  32829. result[j] = t3 ^= result[j - 16];
  32830. j++;
  32831. result[j] = t4 ^= result[j - 16];
  32832. j++;
  32833. }
  32834. }
  32835. return result;
  32836. }
  32837. function decrypt128(input, key) {
  32838. var state = new Uint8Array(16);
  32839. state.set(input);
  32840. var i, j, k;
  32841. var t, u, v;
  32842. // AddRoundKey
  32843. for (j = 0, k = 160; j < 16; ++j, ++k) {
  32844. state[j] ^= key[k];
  32845. }
  32846. for (i = 9; i >= 1; --i) {
  32847. // InvShiftRows
  32848. t = state[13];
  32849. state[13] = state[9];
  32850. state[9] = state[5];
  32851. state[5] = state[1];
  32852. state[1] = t;
  32853. t = state[14];
  32854. u = state[10];
  32855. state[14] = state[6];
  32856. state[10] = state[2];
  32857. state[6] = t;
  32858. state[2] = u;
  32859. t = state[15];
  32860. u = state[11];
  32861. v = state[7];
  32862. state[15] = state[3];
  32863. state[11] = t;
  32864. state[7] = u;
  32865. state[3] = v;
  32866. // InvSubBytes
  32867. for (j = 0; j < 16; ++j) {
  32868. state[j] = inv_s[state[j]];
  32869. }
  32870. // AddRoundKey
  32871. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  32872. state[j] ^= key[k];
  32873. }
  32874. // InvMixColumns
  32875. for (j = 0; j < 16; j += 4) {
  32876. var s0 = mix[state[j]], s1 = mix[state[j + 1]], s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  32877. t = s0 ^ s1 >>> 8 ^ s1 << 24 ^ s2 >>> 16 ^ s2 << 16 ^ s3 >>> 24 ^ s3 << 8;
  32878. state[j] = t >>> 24 & 0xFF;
  32879. state[j + 1] = t >> 16 & 0xFF;
  32880. state[j + 2] = t >> 8 & 0xFF;
  32881. state[j + 3] = t & 0xFF;
  32882. }
  32883. }
  32884. // InvShiftRows
  32885. t = state[13];
  32886. state[13] = state[9];
  32887. state[9] = state[5];
  32888. state[5] = state[1];
  32889. state[1] = t;
  32890. t = state[14];
  32891. u = state[10];
  32892. state[14] = state[6];
  32893. state[10] = state[2];
  32894. state[6] = t;
  32895. state[2] = u;
  32896. t = state[15];
  32897. u = state[11];
  32898. v = state[7];
  32899. state[15] = state[3];
  32900. state[11] = t;
  32901. state[7] = u;
  32902. state[3] = v;
  32903. for (j = 0; j < 16; ++j) {
  32904. // InvSubBytes
  32905. state[j] = inv_s[state[j]];
  32906. // AddRoundKey
  32907. state[j] ^= key[j];
  32908. }
  32909. return state;
  32910. }
  32911. function encrypt128(input, key) {
  32912. var t, u, v, k;
  32913. var state = new Uint8Array(16);
  32914. state.set(input);
  32915. for (j = 0; j < 16; ++j) {
  32916. // AddRoundKey
  32917. state[j] ^= key[j];
  32918. }
  32919. for (i = 1; i < 10; i++) {
  32920. //SubBytes
  32921. for (j = 0; j < 16; ++j) {
  32922. state[j] = s[state[j]];
  32923. }
  32924. //ShiftRows
  32925. v = state[1];
  32926. state[1] = state[5];
  32927. state[5] = state[9];
  32928. state[9] = state[13];
  32929. state[13] = v;
  32930. v = state[2];
  32931. u = state[6];
  32932. state[2] = state[10];
  32933. state[6] = state[14];
  32934. state[10] = v;
  32935. state[14] = u;
  32936. v = state[3];
  32937. u = state[7];
  32938. t = state[11];
  32939. state[3] = state[15];
  32940. state[7] = v;
  32941. state[11] = u;
  32942. state[15] = t;
  32943. //MixColumns
  32944. for (var j = 0; j < 16; j += 4) {
  32945. var s0 = state[j + 0], s1 = state[j + 1];
  32946. var s2 = state[j + 2], s3 = state[j + 3];
  32947. t = s0 ^ s1 ^ s2 ^ s3;
  32948. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  32949. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  32950. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  32951. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  32952. }
  32953. //AddRoundKey
  32954. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  32955. state[j] ^= key[k];
  32956. }
  32957. }
  32958. //SubBytes
  32959. for (j = 0; j < 16; ++j) {
  32960. state[j] = s[state[j]];
  32961. }
  32962. //ShiftRows
  32963. v = state[1];
  32964. state[1] = state[5];
  32965. state[5] = state[9];
  32966. state[9] = state[13];
  32967. state[13] = v;
  32968. v = state[2];
  32969. u = state[6];
  32970. state[2] = state[10];
  32971. state[6] = state[14];
  32972. state[10] = v;
  32973. state[14] = u;
  32974. v = state[3];
  32975. u = state[7];
  32976. t = state[11];
  32977. state[3] = state[15];
  32978. state[7] = v;
  32979. state[11] = u;
  32980. state[15] = t;
  32981. //AddRoundKey
  32982. for (j = 0, k = 160; j < 16; ++j, ++k) {
  32983. state[j] ^= key[k];
  32984. }
  32985. return state;
  32986. }
  32987. function AES128Cipher(key) {
  32988. this.key = expandKey128(key);
  32989. this.buffer = new Uint8Array(16);
  32990. this.bufferPosition = 0;
  32991. }
  32992. function decryptBlock2(data, finalize) {
  32993. var i, j, ii, sourceLength = data.length, buffer = this.buffer, bufferLength = this.bufferPosition, result = [], iv = this.iv;
  32994. for (i = 0; i < sourceLength; ++i) {
  32995. buffer[bufferLength] = data[i];
  32996. ++bufferLength;
  32997. if (bufferLength < 16) {
  32998. continue;
  32999. }
  33000. // buffer is full, decrypting
  33001. var plain = decrypt128(buffer, this.key);
  33002. // xor-ing the IV vector to get plain text
  33003. for (j = 0; j < 16; ++j) {
  33004. plain[j] ^= iv[j];
  33005. }
  33006. iv = buffer;
  33007. result.push(plain);
  33008. buffer = new Uint8Array(16);
  33009. bufferLength = 0;
  33010. }
  33011. // saving incomplete buffer
  33012. this.buffer = buffer;
  33013. this.bufferLength = bufferLength;
  33014. this.iv = iv;
  33015. if (result.length === 0) {
  33016. return new Uint8Array([]);
  33017. }
  33018. // combining plain text blocks into one
  33019. var outputLength = 16 * result.length;
  33020. if (finalize) {
  33021. // undo a padding that is described in RFC 2898
  33022. var lastBlock = result[result.length - 1];
  33023. var psLen = lastBlock[15];
  33024. if (psLen <= 16) {
  33025. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  33026. if (lastBlock[i] !== psLen) {
  33027. // Invalid padding, assume that the block has no padding.
  33028. psLen = 0;
  33029. break;
  33030. }
  33031. }
  33032. outputLength -= psLen;
  33033. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  33034. }
  33035. }
  33036. var output = new Uint8Array(outputLength);
  33037. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  33038. output.set(result[i], j);
  33039. }
  33040. return output;
  33041. }
  33042. AES128Cipher.prototype = {
  33043. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  33044. var i, sourceLength = data.length;
  33045. var buffer = this.buffer, bufferLength = this.bufferPosition;
  33046. // waiting for IV values -- they are at the start of the stream
  33047. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  33048. buffer[bufferLength] = data[i];
  33049. }
  33050. if (bufferLength < 16) {
  33051. // need more data
  33052. this.bufferLength = bufferLength;
  33053. return new Uint8Array([]);
  33054. }
  33055. this.iv = buffer;
  33056. this.buffer = new Uint8Array(16);
  33057. this.bufferLength = 0;
  33058. // starting decryption
  33059. this.decryptBlock = decryptBlock2;
  33060. return this.decryptBlock(data.subarray(16), finalize);
  33061. },
  33062. encrypt: function AES128Cipher_encrypt(data, iv) {
  33063. var i, j, ii, sourceLength = data.length, buffer = this.buffer, bufferLength = this.bufferPosition, result = [];
  33064. if (!iv) {
  33065. iv = new Uint8Array(16);
  33066. }
  33067. for (i = 0; i < sourceLength; ++i) {
  33068. buffer[bufferLength] = data[i];
  33069. ++bufferLength;
  33070. if (bufferLength < 16) {
  33071. continue;
  33072. }
  33073. for (j = 0; j < 16; ++j) {
  33074. buffer[j] ^= iv[j];
  33075. }
  33076. // buffer is full, encrypting
  33077. var cipher = encrypt128(buffer, this.key);
  33078. iv = cipher;
  33079. result.push(cipher);
  33080. buffer = new Uint8Array(16);
  33081. bufferLength = 0;
  33082. }
  33083. // saving incomplete buffer
  33084. this.buffer = buffer;
  33085. this.bufferLength = bufferLength;
  33086. this.iv = iv;
  33087. if (result.length === 0) {
  33088. return new Uint8Array([]);
  33089. }
  33090. // combining plain text blocks into one
  33091. var outputLength = 16 * result.length;
  33092. var output = new Uint8Array(outputLength);
  33093. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  33094. output.set(result[i], j);
  33095. }
  33096. return output;
  33097. }
  33098. };
  33099. return AES128Cipher;
  33100. }();
  33101. var AES256Cipher = function AES256CipherClosure() {
  33102. var rcon = new Uint8Array([
  33103. 0x8d,
  33104. 0x01,
  33105. 0x02,
  33106. 0x04,
  33107. 0x08,
  33108. 0x10,
  33109. 0x20,
  33110. 0x40,
  33111. 0x80,
  33112. 0x1b,
  33113. 0x36,
  33114. 0x6c,
  33115. 0xd8,
  33116. 0xab,
  33117. 0x4d,
  33118. 0x9a,
  33119. 0x2f,
  33120. 0x5e,
  33121. 0xbc,
  33122. 0x63,
  33123. 0xc6,
  33124. 0x97,
  33125. 0x35,
  33126. 0x6a,
  33127. 0xd4,
  33128. 0xb3,
  33129. 0x7d,
  33130. 0xfa,
  33131. 0xef,
  33132. 0xc5,
  33133. 0x91,
  33134. 0x39,
  33135. 0x72,
  33136. 0xe4,
  33137. 0xd3,
  33138. 0xbd,
  33139. 0x61,
  33140. 0xc2,
  33141. 0x9f,
  33142. 0x25,
  33143. 0x4a,
  33144. 0x94,
  33145. 0x33,
  33146. 0x66,
  33147. 0xcc,
  33148. 0x83,
  33149. 0x1d,
  33150. 0x3a,
  33151. 0x74,
  33152. 0xe8,
  33153. 0xcb,
  33154. 0x8d,
  33155. 0x01,
  33156. 0x02,
  33157. 0x04,
  33158. 0x08,
  33159. 0x10,
  33160. 0x20,
  33161. 0x40,
  33162. 0x80,
  33163. 0x1b,
  33164. 0x36,
  33165. 0x6c,
  33166. 0xd8,
  33167. 0xab,
  33168. 0x4d,
  33169. 0x9a,
  33170. 0x2f,
  33171. 0x5e,
  33172. 0xbc,
  33173. 0x63,
  33174. 0xc6,
  33175. 0x97,
  33176. 0x35,
  33177. 0x6a,
  33178. 0xd4,
  33179. 0xb3,
  33180. 0x7d,
  33181. 0xfa,
  33182. 0xef,
  33183. 0xc5,
  33184. 0x91,
  33185. 0x39,
  33186. 0x72,
  33187. 0xe4,
  33188. 0xd3,
  33189. 0xbd,
  33190. 0x61,
  33191. 0xc2,
  33192. 0x9f,
  33193. 0x25,
  33194. 0x4a,
  33195. 0x94,
  33196. 0x33,
  33197. 0x66,
  33198. 0xcc,
  33199. 0x83,
  33200. 0x1d,
  33201. 0x3a,
  33202. 0x74,
  33203. 0xe8,
  33204. 0xcb,
  33205. 0x8d,
  33206. 0x01,
  33207. 0x02,
  33208. 0x04,
  33209. 0x08,
  33210. 0x10,
  33211. 0x20,
  33212. 0x40,
  33213. 0x80,
  33214. 0x1b,
  33215. 0x36,
  33216. 0x6c,
  33217. 0xd8,
  33218. 0xab,
  33219. 0x4d,
  33220. 0x9a,
  33221. 0x2f,
  33222. 0x5e,
  33223. 0xbc,
  33224. 0x63,
  33225. 0xc6,
  33226. 0x97,
  33227. 0x35,
  33228. 0x6a,
  33229. 0xd4,
  33230. 0xb3,
  33231. 0x7d,
  33232. 0xfa,
  33233. 0xef,
  33234. 0xc5,
  33235. 0x91,
  33236. 0x39,
  33237. 0x72,
  33238. 0xe4,
  33239. 0xd3,
  33240. 0xbd,
  33241. 0x61,
  33242. 0xc2,
  33243. 0x9f,
  33244. 0x25,
  33245. 0x4a,
  33246. 0x94,
  33247. 0x33,
  33248. 0x66,
  33249. 0xcc,
  33250. 0x83,
  33251. 0x1d,
  33252. 0x3a,
  33253. 0x74,
  33254. 0xe8,
  33255. 0xcb,
  33256. 0x8d,
  33257. 0x01,
  33258. 0x02,
  33259. 0x04,
  33260. 0x08,
  33261. 0x10,
  33262. 0x20,
  33263. 0x40,
  33264. 0x80,
  33265. 0x1b,
  33266. 0x36,
  33267. 0x6c,
  33268. 0xd8,
  33269. 0xab,
  33270. 0x4d,
  33271. 0x9a,
  33272. 0x2f,
  33273. 0x5e,
  33274. 0xbc,
  33275. 0x63,
  33276. 0xc6,
  33277. 0x97,
  33278. 0x35,
  33279. 0x6a,
  33280. 0xd4,
  33281. 0xb3,
  33282. 0x7d,
  33283. 0xfa,
  33284. 0xef,
  33285. 0xc5,
  33286. 0x91,
  33287. 0x39,
  33288. 0x72,
  33289. 0xe4,
  33290. 0xd3,
  33291. 0xbd,
  33292. 0x61,
  33293. 0xc2,
  33294. 0x9f,
  33295. 0x25,
  33296. 0x4a,
  33297. 0x94,
  33298. 0x33,
  33299. 0x66,
  33300. 0xcc,
  33301. 0x83,
  33302. 0x1d,
  33303. 0x3a,
  33304. 0x74,
  33305. 0xe8,
  33306. 0xcb,
  33307. 0x8d,
  33308. 0x01,
  33309. 0x02,
  33310. 0x04,
  33311. 0x08,
  33312. 0x10,
  33313. 0x20,
  33314. 0x40,
  33315. 0x80,
  33316. 0x1b,
  33317. 0x36,
  33318. 0x6c,
  33319. 0xd8,
  33320. 0xab,
  33321. 0x4d,
  33322. 0x9a,
  33323. 0x2f,
  33324. 0x5e,
  33325. 0xbc,
  33326. 0x63,
  33327. 0xc6,
  33328. 0x97,
  33329. 0x35,
  33330. 0x6a,
  33331. 0xd4,
  33332. 0xb3,
  33333. 0x7d,
  33334. 0xfa,
  33335. 0xef,
  33336. 0xc5,
  33337. 0x91,
  33338. 0x39,
  33339. 0x72,
  33340. 0xe4,
  33341. 0xd3,
  33342. 0xbd,
  33343. 0x61,
  33344. 0xc2,
  33345. 0x9f,
  33346. 0x25,
  33347. 0x4a,
  33348. 0x94,
  33349. 0x33,
  33350. 0x66,
  33351. 0xcc,
  33352. 0x83,
  33353. 0x1d,
  33354. 0x3a,
  33355. 0x74,
  33356. 0xe8,
  33357. 0xcb,
  33358. 0x8d
  33359. ]);
  33360. var s = new Uint8Array([
  33361. 0x63,
  33362. 0x7c,
  33363. 0x77,
  33364. 0x7b,
  33365. 0xf2,
  33366. 0x6b,
  33367. 0x6f,
  33368. 0xc5,
  33369. 0x30,
  33370. 0x01,
  33371. 0x67,
  33372. 0x2b,
  33373. 0xfe,
  33374. 0xd7,
  33375. 0xab,
  33376. 0x76,
  33377. 0xca,
  33378. 0x82,
  33379. 0xc9,
  33380. 0x7d,
  33381. 0xfa,
  33382. 0x59,
  33383. 0x47,
  33384. 0xf0,
  33385. 0xad,
  33386. 0xd4,
  33387. 0xa2,
  33388. 0xaf,
  33389. 0x9c,
  33390. 0xa4,
  33391. 0x72,
  33392. 0xc0,
  33393. 0xb7,
  33394. 0xfd,
  33395. 0x93,
  33396. 0x26,
  33397. 0x36,
  33398. 0x3f,
  33399. 0xf7,
  33400. 0xcc,
  33401. 0x34,
  33402. 0xa5,
  33403. 0xe5,
  33404. 0xf1,
  33405. 0x71,
  33406. 0xd8,
  33407. 0x31,
  33408. 0x15,
  33409. 0x04,
  33410. 0xc7,
  33411. 0x23,
  33412. 0xc3,
  33413. 0x18,
  33414. 0x96,
  33415. 0x05,
  33416. 0x9a,
  33417. 0x07,
  33418. 0x12,
  33419. 0x80,
  33420. 0xe2,
  33421. 0xeb,
  33422. 0x27,
  33423. 0xb2,
  33424. 0x75,
  33425. 0x09,
  33426. 0x83,
  33427. 0x2c,
  33428. 0x1a,
  33429. 0x1b,
  33430. 0x6e,
  33431. 0x5a,
  33432. 0xa0,
  33433. 0x52,
  33434. 0x3b,
  33435. 0xd6,
  33436. 0xb3,
  33437. 0x29,
  33438. 0xe3,
  33439. 0x2f,
  33440. 0x84,
  33441. 0x53,
  33442. 0xd1,
  33443. 0x00,
  33444. 0xed,
  33445. 0x20,
  33446. 0xfc,
  33447. 0xb1,
  33448. 0x5b,
  33449. 0x6a,
  33450. 0xcb,
  33451. 0xbe,
  33452. 0x39,
  33453. 0x4a,
  33454. 0x4c,
  33455. 0x58,
  33456. 0xcf,
  33457. 0xd0,
  33458. 0xef,
  33459. 0xaa,
  33460. 0xfb,
  33461. 0x43,
  33462. 0x4d,
  33463. 0x33,
  33464. 0x85,
  33465. 0x45,
  33466. 0xf9,
  33467. 0x02,
  33468. 0x7f,
  33469. 0x50,
  33470. 0x3c,
  33471. 0x9f,
  33472. 0xa8,
  33473. 0x51,
  33474. 0xa3,
  33475. 0x40,
  33476. 0x8f,
  33477. 0x92,
  33478. 0x9d,
  33479. 0x38,
  33480. 0xf5,
  33481. 0xbc,
  33482. 0xb6,
  33483. 0xda,
  33484. 0x21,
  33485. 0x10,
  33486. 0xff,
  33487. 0xf3,
  33488. 0xd2,
  33489. 0xcd,
  33490. 0x0c,
  33491. 0x13,
  33492. 0xec,
  33493. 0x5f,
  33494. 0x97,
  33495. 0x44,
  33496. 0x17,
  33497. 0xc4,
  33498. 0xa7,
  33499. 0x7e,
  33500. 0x3d,
  33501. 0x64,
  33502. 0x5d,
  33503. 0x19,
  33504. 0x73,
  33505. 0x60,
  33506. 0x81,
  33507. 0x4f,
  33508. 0xdc,
  33509. 0x22,
  33510. 0x2a,
  33511. 0x90,
  33512. 0x88,
  33513. 0x46,
  33514. 0xee,
  33515. 0xb8,
  33516. 0x14,
  33517. 0xde,
  33518. 0x5e,
  33519. 0x0b,
  33520. 0xdb,
  33521. 0xe0,
  33522. 0x32,
  33523. 0x3a,
  33524. 0x0a,
  33525. 0x49,
  33526. 0x06,
  33527. 0x24,
  33528. 0x5c,
  33529. 0xc2,
  33530. 0xd3,
  33531. 0xac,
  33532. 0x62,
  33533. 0x91,
  33534. 0x95,
  33535. 0xe4,
  33536. 0x79,
  33537. 0xe7,
  33538. 0xc8,
  33539. 0x37,
  33540. 0x6d,
  33541. 0x8d,
  33542. 0xd5,
  33543. 0x4e,
  33544. 0xa9,
  33545. 0x6c,
  33546. 0x56,
  33547. 0xf4,
  33548. 0xea,
  33549. 0x65,
  33550. 0x7a,
  33551. 0xae,
  33552. 0x08,
  33553. 0xba,
  33554. 0x78,
  33555. 0x25,
  33556. 0x2e,
  33557. 0x1c,
  33558. 0xa6,
  33559. 0xb4,
  33560. 0xc6,
  33561. 0xe8,
  33562. 0xdd,
  33563. 0x74,
  33564. 0x1f,
  33565. 0x4b,
  33566. 0xbd,
  33567. 0x8b,
  33568. 0x8a,
  33569. 0x70,
  33570. 0x3e,
  33571. 0xb5,
  33572. 0x66,
  33573. 0x48,
  33574. 0x03,
  33575. 0xf6,
  33576. 0x0e,
  33577. 0x61,
  33578. 0x35,
  33579. 0x57,
  33580. 0xb9,
  33581. 0x86,
  33582. 0xc1,
  33583. 0x1d,
  33584. 0x9e,
  33585. 0xe1,
  33586. 0xf8,
  33587. 0x98,
  33588. 0x11,
  33589. 0x69,
  33590. 0xd9,
  33591. 0x8e,
  33592. 0x94,
  33593. 0x9b,
  33594. 0x1e,
  33595. 0x87,
  33596. 0xe9,
  33597. 0xce,
  33598. 0x55,
  33599. 0x28,
  33600. 0xdf,
  33601. 0x8c,
  33602. 0xa1,
  33603. 0x89,
  33604. 0x0d,
  33605. 0xbf,
  33606. 0xe6,
  33607. 0x42,
  33608. 0x68,
  33609. 0x41,
  33610. 0x99,
  33611. 0x2d,
  33612. 0x0f,
  33613. 0xb0,
  33614. 0x54,
  33615. 0xbb,
  33616. 0x16
  33617. ]);
  33618. var inv_s = new Uint8Array([
  33619. 0x52,
  33620. 0x09,
  33621. 0x6a,
  33622. 0xd5,
  33623. 0x30,
  33624. 0x36,
  33625. 0xa5,
  33626. 0x38,
  33627. 0xbf,
  33628. 0x40,
  33629. 0xa3,
  33630. 0x9e,
  33631. 0x81,
  33632. 0xf3,
  33633. 0xd7,
  33634. 0xfb,
  33635. 0x7c,
  33636. 0xe3,
  33637. 0x39,
  33638. 0x82,
  33639. 0x9b,
  33640. 0x2f,
  33641. 0xff,
  33642. 0x87,
  33643. 0x34,
  33644. 0x8e,
  33645. 0x43,
  33646. 0x44,
  33647. 0xc4,
  33648. 0xde,
  33649. 0xe9,
  33650. 0xcb,
  33651. 0x54,
  33652. 0x7b,
  33653. 0x94,
  33654. 0x32,
  33655. 0xa6,
  33656. 0xc2,
  33657. 0x23,
  33658. 0x3d,
  33659. 0xee,
  33660. 0x4c,
  33661. 0x95,
  33662. 0x0b,
  33663. 0x42,
  33664. 0xfa,
  33665. 0xc3,
  33666. 0x4e,
  33667. 0x08,
  33668. 0x2e,
  33669. 0xa1,
  33670. 0x66,
  33671. 0x28,
  33672. 0xd9,
  33673. 0x24,
  33674. 0xb2,
  33675. 0x76,
  33676. 0x5b,
  33677. 0xa2,
  33678. 0x49,
  33679. 0x6d,
  33680. 0x8b,
  33681. 0xd1,
  33682. 0x25,
  33683. 0x72,
  33684. 0xf8,
  33685. 0xf6,
  33686. 0x64,
  33687. 0x86,
  33688. 0x68,
  33689. 0x98,
  33690. 0x16,
  33691. 0xd4,
  33692. 0xa4,
  33693. 0x5c,
  33694. 0xcc,
  33695. 0x5d,
  33696. 0x65,
  33697. 0xb6,
  33698. 0x92,
  33699. 0x6c,
  33700. 0x70,
  33701. 0x48,
  33702. 0x50,
  33703. 0xfd,
  33704. 0xed,
  33705. 0xb9,
  33706. 0xda,
  33707. 0x5e,
  33708. 0x15,
  33709. 0x46,
  33710. 0x57,
  33711. 0xa7,
  33712. 0x8d,
  33713. 0x9d,
  33714. 0x84,
  33715. 0x90,
  33716. 0xd8,
  33717. 0xab,
  33718. 0x00,
  33719. 0x8c,
  33720. 0xbc,
  33721. 0xd3,
  33722. 0x0a,
  33723. 0xf7,
  33724. 0xe4,
  33725. 0x58,
  33726. 0x05,
  33727. 0xb8,
  33728. 0xb3,
  33729. 0x45,
  33730. 0x06,
  33731. 0xd0,
  33732. 0x2c,
  33733. 0x1e,
  33734. 0x8f,
  33735. 0xca,
  33736. 0x3f,
  33737. 0x0f,
  33738. 0x02,
  33739. 0xc1,
  33740. 0xaf,
  33741. 0xbd,
  33742. 0x03,
  33743. 0x01,
  33744. 0x13,
  33745. 0x8a,
  33746. 0x6b,
  33747. 0x3a,
  33748. 0x91,
  33749. 0x11,
  33750. 0x41,
  33751. 0x4f,
  33752. 0x67,
  33753. 0xdc,
  33754. 0xea,
  33755. 0x97,
  33756. 0xf2,
  33757. 0xcf,
  33758. 0xce,
  33759. 0xf0,
  33760. 0xb4,
  33761. 0xe6,
  33762. 0x73,
  33763. 0x96,
  33764. 0xac,
  33765. 0x74,
  33766. 0x22,
  33767. 0xe7,
  33768. 0xad,
  33769. 0x35,
  33770. 0x85,
  33771. 0xe2,
  33772. 0xf9,
  33773. 0x37,
  33774. 0xe8,
  33775. 0x1c,
  33776. 0x75,
  33777. 0xdf,
  33778. 0x6e,
  33779. 0x47,
  33780. 0xf1,
  33781. 0x1a,
  33782. 0x71,
  33783. 0x1d,
  33784. 0x29,
  33785. 0xc5,
  33786. 0x89,
  33787. 0x6f,
  33788. 0xb7,
  33789. 0x62,
  33790. 0x0e,
  33791. 0xaa,
  33792. 0x18,
  33793. 0xbe,
  33794. 0x1b,
  33795. 0xfc,
  33796. 0x56,
  33797. 0x3e,
  33798. 0x4b,
  33799. 0xc6,
  33800. 0xd2,
  33801. 0x79,
  33802. 0x20,
  33803. 0x9a,
  33804. 0xdb,
  33805. 0xc0,
  33806. 0xfe,
  33807. 0x78,
  33808. 0xcd,
  33809. 0x5a,
  33810. 0xf4,
  33811. 0x1f,
  33812. 0xdd,
  33813. 0xa8,
  33814. 0x33,
  33815. 0x88,
  33816. 0x07,
  33817. 0xc7,
  33818. 0x31,
  33819. 0xb1,
  33820. 0x12,
  33821. 0x10,
  33822. 0x59,
  33823. 0x27,
  33824. 0x80,
  33825. 0xec,
  33826. 0x5f,
  33827. 0x60,
  33828. 0x51,
  33829. 0x7f,
  33830. 0xa9,
  33831. 0x19,
  33832. 0xb5,
  33833. 0x4a,
  33834. 0x0d,
  33835. 0x2d,
  33836. 0xe5,
  33837. 0x7a,
  33838. 0x9f,
  33839. 0x93,
  33840. 0xc9,
  33841. 0x9c,
  33842. 0xef,
  33843. 0xa0,
  33844. 0xe0,
  33845. 0x3b,
  33846. 0x4d,
  33847. 0xae,
  33848. 0x2a,
  33849. 0xf5,
  33850. 0xb0,
  33851. 0xc8,
  33852. 0xeb,
  33853. 0xbb,
  33854. 0x3c,
  33855. 0x83,
  33856. 0x53,
  33857. 0x99,
  33858. 0x61,
  33859. 0x17,
  33860. 0x2b,
  33861. 0x04,
  33862. 0x7e,
  33863. 0xba,
  33864. 0x77,
  33865. 0xd6,
  33866. 0x26,
  33867. 0xe1,
  33868. 0x69,
  33869. 0x14,
  33870. 0x63,
  33871. 0x55,
  33872. 0x21,
  33873. 0x0c,
  33874. 0x7d
  33875. ]);
  33876. var mixCol = new Uint8Array(256);
  33877. for (var i = 0; i < 256; i++) {
  33878. if (i < 128) {
  33879. mixCol[i] = i << 1;
  33880. } else {
  33881. mixCol[i] = i << 1 ^ 0x1b;
  33882. }
  33883. }
  33884. var mix = new Uint32Array([
  33885. 0x00000000,
  33886. 0x0e090d0b,
  33887. 0x1c121a16,
  33888. 0x121b171d,
  33889. 0x3824342c,
  33890. 0x362d3927,
  33891. 0x24362e3a,
  33892. 0x2a3f2331,
  33893. 0x70486858,
  33894. 0x7e416553,
  33895. 0x6c5a724e,
  33896. 0x62537f45,
  33897. 0x486c5c74,
  33898. 0x4665517f,
  33899. 0x547e4662,
  33900. 0x5a774b69,
  33901. 0xe090d0b0,
  33902. 0xee99ddbb,
  33903. 0xfc82caa6,
  33904. 0xf28bc7ad,
  33905. 0xd8b4e49c,
  33906. 0xd6bde997,
  33907. 0xc4a6fe8a,
  33908. 0xcaaff381,
  33909. 0x90d8b8e8,
  33910. 0x9ed1b5e3,
  33911. 0x8ccaa2fe,
  33912. 0x82c3aff5,
  33913. 0xa8fc8cc4,
  33914. 0xa6f581cf,
  33915. 0xb4ee96d2,
  33916. 0xbae79bd9,
  33917. 0xdb3bbb7b,
  33918. 0xd532b670,
  33919. 0xc729a16d,
  33920. 0xc920ac66,
  33921. 0xe31f8f57,
  33922. 0xed16825c,
  33923. 0xff0d9541,
  33924. 0xf104984a,
  33925. 0xab73d323,
  33926. 0xa57ade28,
  33927. 0xb761c935,
  33928. 0xb968c43e,
  33929. 0x9357e70f,
  33930. 0x9d5eea04,
  33931. 0x8f45fd19,
  33932. 0x814cf012,
  33933. 0x3bab6bcb,
  33934. 0x35a266c0,
  33935. 0x27b971dd,
  33936. 0x29b07cd6,
  33937. 0x038f5fe7,
  33938. 0x0d8652ec,
  33939. 0x1f9d45f1,
  33940. 0x119448fa,
  33941. 0x4be30393,
  33942. 0x45ea0e98,
  33943. 0x57f11985,
  33944. 0x59f8148e,
  33945. 0x73c737bf,
  33946. 0x7dce3ab4,
  33947. 0x6fd52da9,
  33948. 0x61dc20a2,
  33949. 0xad766df6,
  33950. 0xa37f60fd,
  33951. 0xb16477e0,
  33952. 0xbf6d7aeb,
  33953. 0x955259da,
  33954. 0x9b5b54d1,
  33955. 0x894043cc,
  33956. 0x87494ec7,
  33957. 0xdd3e05ae,
  33958. 0xd33708a5,
  33959. 0xc12c1fb8,
  33960. 0xcf2512b3,
  33961. 0xe51a3182,
  33962. 0xeb133c89,
  33963. 0xf9082b94,
  33964. 0xf701269f,
  33965. 0x4de6bd46,
  33966. 0x43efb04d,
  33967. 0x51f4a750,
  33968. 0x5ffdaa5b,
  33969. 0x75c2896a,
  33970. 0x7bcb8461,
  33971. 0x69d0937c,
  33972. 0x67d99e77,
  33973. 0x3daed51e,
  33974. 0x33a7d815,
  33975. 0x21bccf08,
  33976. 0x2fb5c203,
  33977. 0x058ae132,
  33978. 0x0b83ec39,
  33979. 0x1998fb24,
  33980. 0x1791f62f,
  33981. 0x764dd68d,
  33982. 0x7844db86,
  33983. 0x6a5fcc9b,
  33984. 0x6456c190,
  33985. 0x4e69e2a1,
  33986. 0x4060efaa,
  33987. 0x527bf8b7,
  33988. 0x5c72f5bc,
  33989. 0x0605bed5,
  33990. 0x080cb3de,
  33991. 0x1a17a4c3,
  33992. 0x141ea9c8,
  33993. 0x3e218af9,
  33994. 0x302887f2,
  33995. 0x223390ef,
  33996. 0x2c3a9de4,
  33997. 0x96dd063d,
  33998. 0x98d40b36,
  33999. 0x8acf1c2b,
  34000. 0x84c61120,
  34001. 0xaef93211,
  34002. 0xa0f03f1a,
  34003. 0xb2eb2807,
  34004. 0xbce2250c,
  34005. 0xe6956e65,
  34006. 0xe89c636e,
  34007. 0xfa877473,
  34008. 0xf48e7978,
  34009. 0xdeb15a49,
  34010. 0xd0b85742,
  34011. 0xc2a3405f,
  34012. 0xccaa4d54,
  34013. 0x41ecdaf7,
  34014. 0x4fe5d7fc,
  34015. 0x5dfec0e1,
  34016. 0x53f7cdea,
  34017. 0x79c8eedb,
  34018. 0x77c1e3d0,
  34019. 0x65daf4cd,
  34020. 0x6bd3f9c6,
  34021. 0x31a4b2af,
  34022. 0x3fadbfa4,
  34023. 0x2db6a8b9,
  34024. 0x23bfa5b2,
  34025. 0x09808683,
  34026. 0x07898b88,
  34027. 0x15929c95,
  34028. 0x1b9b919e,
  34029. 0xa17c0a47,
  34030. 0xaf75074c,
  34031. 0xbd6e1051,
  34032. 0xb3671d5a,
  34033. 0x99583e6b,
  34034. 0x97513360,
  34035. 0x854a247d,
  34036. 0x8b432976,
  34037. 0xd134621f,
  34038. 0xdf3d6f14,
  34039. 0xcd267809,
  34040. 0xc32f7502,
  34041. 0xe9105633,
  34042. 0xe7195b38,
  34043. 0xf5024c25,
  34044. 0xfb0b412e,
  34045. 0x9ad7618c,
  34046. 0x94de6c87,
  34047. 0x86c57b9a,
  34048. 0x88cc7691,
  34049. 0xa2f355a0,
  34050. 0xacfa58ab,
  34051. 0xbee14fb6,
  34052. 0xb0e842bd,
  34053. 0xea9f09d4,
  34054. 0xe49604df,
  34055. 0xf68d13c2,
  34056. 0xf8841ec9,
  34057. 0xd2bb3df8,
  34058. 0xdcb230f3,
  34059. 0xcea927ee,
  34060. 0xc0a02ae5,
  34061. 0x7a47b13c,
  34062. 0x744ebc37,
  34063. 0x6655ab2a,
  34064. 0x685ca621,
  34065. 0x42638510,
  34066. 0x4c6a881b,
  34067. 0x5e719f06,
  34068. 0x5078920d,
  34069. 0x0a0fd964,
  34070. 0x0406d46f,
  34071. 0x161dc372,
  34072. 0x1814ce79,
  34073. 0x322bed48,
  34074. 0x3c22e043,
  34075. 0x2e39f75e,
  34076. 0x2030fa55,
  34077. 0xec9ab701,
  34078. 0xe293ba0a,
  34079. 0xf088ad17,
  34080. 0xfe81a01c,
  34081. 0xd4be832d,
  34082. 0xdab78e26,
  34083. 0xc8ac993b,
  34084. 0xc6a59430,
  34085. 0x9cd2df59,
  34086. 0x92dbd252,
  34087. 0x80c0c54f,
  34088. 0x8ec9c844,
  34089. 0xa4f6eb75,
  34090. 0xaaffe67e,
  34091. 0xb8e4f163,
  34092. 0xb6edfc68,
  34093. 0x0c0a67b1,
  34094. 0x02036aba,
  34095. 0x10187da7,
  34096. 0x1e1170ac,
  34097. 0x342e539d,
  34098. 0x3a275e96,
  34099. 0x283c498b,
  34100. 0x26354480,
  34101. 0x7c420fe9,
  34102. 0x724b02e2,
  34103. 0x605015ff,
  34104. 0x6e5918f4,
  34105. 0x44663bc5,
  34106. 0x4a6f36ce,
  34107. 0x587421d3,
  34108. 0x567d2cd8,
  34109. 0x37a10c7a,
  34110. 0x39a80171,
  34111. 0x2bb3166c,
  34112. 0x25ba1b67,
  34113. 0x0f853856,
  34114. 0x018c355d,
  34115. 0x13972240,
  34116. 0x1d9e2f4b,
  34117. 0x47e96422,
  34118. 0x49e06929,
  34119. 0x5bfb7e34,
  34120. 0x55f2733f,
  34121. 0x7fcd500e,
  34122. 0x71c45d05,
  34123. 0x63df4a18,
  34124. 0x6dd64713,
  34125. 0xd731dcca,
  34126. 0xd938d1c1,
  34127. 0xcb23c6dc,
  34128. 0xc52acbd7,
  34129. 0xef15e8e6,
  34130. 0xe11ce5ed,
  34131. 0xf307f2f0,
  34132. 0xfd0efffb,
  34133. 0xa779b492,
  34134. 0xa970b999,
  34135. 0xbb6bae84,
  34136. 0xb562a38f,
  34137. 0x9f5d80be,
  34138. 0x91548db5,
  34139. 0x834f9aa8,
  34140. 0x8d4697a3
  34141. ]);
  34142. function expandKey256(cipherKey) {
  34143. var b = 240, result = new Uint8Array(b);
  34144. var r = 1;
  34145. result.set(cipherKey);
  34146. for (var j = 32, i = 1; j < b; ++i) {
  34147. if (j % 32 === 16) {
  34148. t1 = s[t1];
  34149. t2 = s[t2];
  34150. t3 = s[t3];
  34151. t4 = s[t4];
  34152. } else if (j % 32 === 0) {
  34153. // RotWord
  34154. var t1 = result[j - 3], t2 = result[j - 2], t3 = result[j - 1], t4 = result[j - 4];
  34155. // SubWord
  34156. t1 = s[t1];
  34157. t2 = s[t2];
  34158. t3 = s[t3];
  34159. t4 = s[t4];
  34160. // Rcon
  34161. t1 = t1 ^ r;
  34162. if ((r <<= 1) >= 256) {
  34163. r = (r ^ 0x1b) & 0xFF;
  34164. }
  34165. }
  34166. for (var n = 0; n < 4; ++n) {
  34167. result[j] = t1 ^= result[j - 32];
  34168. j++;
  34169. result[j] = t2 ^= result[j - 32];
  34170. j++;
  34171. result[j] = t3 ^= result[j - 32];
  34172. j++;
  34173. result[j] = t4 ^= result[j - 32];
  34174. j++;
  34175. }
  34176. }
  34177. return result;
  34178. }
  34179. function decrypt256(input, key) {
  34180. var state = new Uint8Array(16);
  34181. state.set(input);
  34182. var i, j, k;
  34183. var t, u, v;
  34184. // AddRoundKey
  34185. for (j = 0, k = 224; j < 16; ++j, ++k) {
  34186. state[j] ^= key[k];
  34187. }
  34188. for (i = 13; i >= 1; --i) {
  34189. // InvShiftRows
  34190. t = state[13];
  34191. state[13] = state[9];
  34192. state[9] = state[5];
  34193. state[5] = state[1];
  34194. state[1] = t;
  34195. t = state[14];
  34196. u = state[10];
  34197. state[14] = state[6];
  34198. state[10] = state[2];
  34199. state[6] = t;
  34200. state[2] = u;
  34201. t = state[15];
  34202. u = state[11];
  34203. v = state[7];
  34204. state[15] = state[3];
  34205. state[11] = t;
  34206. state[7] = u;
  34207. state[3] = v;
  34208. // InvSubBytes
  34209. for (j = 0; j < 16; ++j) {
  34210. state[j] = inv_s[state[j]];
  34211. }
  34212. // AddRoundKey
  34213. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  34214. state[j] ^= key[k];
  34215. }
  34216. // InvMixColumns
  34217. for (j = 0; j < 16; j += 4) {
  34218. var s0 = mix[state[j]], s1 = mix[state[j + 1]], s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  34219. t = s0 ^ s1 >>> 8 ^ s1 << 24 ^ s2 >>> 16 ^ s2 << 16 ^ s3 >>> 24 ^ s3 << 8;
  34220. state[j] = t >>> 24 & 0xFF;
  34221. state[j + 1] = t >> 16 & 0xFF;
  34222. state[j + 2] = t >> 8 & 0xFF;
  34223. state[j + 3] = t & 0xFF;
  34224. }
  34225. }
  34226. // InvShiftRows
  34227. t = state[13];
  34228. state[13] = state[9];
  34229. state[9] = state[5];
  34230. state[5] = state[1];
  34231. state[1] = t;
  34232. t = state[14];
  34233. u = state[10];
  34234. state[14] = state[6];
  34235. state[10] = state[2];
  34236. state[6] = t;
  34237. state[2] = u;
  34238. t = state[15];
  34239. u = state[11];
  34240. v = state[7];
  34241. state[15] = state[3];
  34242. state[11] = t;
  34243. state[7] = u;
  34244. state[3] = v;
  34245. for (j = 0; j < 16; ++j) {
  34246. // InvSubBytes
  34247. state[j] = inv_s[state[j]];
  34248. // AddRoundKey
  34249. state[j] ^= key[j];
  34250. }
  34251. return state;
  34252. }
  34253. function encrypt256(input, key) {
  34254. var t, u, v, k;
  34255. var state = new Uint8Array(16);
  34256. state.set(input);
  34257. for (j = 0; j < 16; ++j) {
  34258. // AddRoundKey
  34259. state[j] ^= key[j];
  34260. }
  34261. for (i = 1; i < 14; i++) {
  34262. //SubBytes
  34263. for (j = 0; j < 16; ++j) {
  34264. state[j] = s[state[j]];
  34265. }
  34266. //ShiftRows
  34267. v = state[1];
  34268. state[1] = state[5];
  34269. state[5] = state[9];
  34270. state[9] = state[13];
  34271. state[13] = v;
  34272. v = state[2];
  34273. u = state[6];
  34274. state[2] = state[10];
  34275. state[6] = state[14];
  34276. state[10] = v;
  34277. state[14] = u;
  34278. v = state[3];
  34279. u = state[7];
  34280. t = state[11];
  34281. state[3] = state[15];
  34282. state[7] = v;
  34283. state[11] = u;
  34284. state[15] = t;
  34285. //MixColumns
  34286. for (var j = 0; j < 16; j += 4) {
  34287. var s0 = state[j + 0], s1 = state[j + 1];
  34288. var s2 = state[j + 2], s3 = state[j + 3];
  34289. t = s0 ^ s1 ^ s2 ^ s3;
  34290. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  34291. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  34292. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  34293. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  34294. }
  34295. //AddRoundKey
  34296. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  34297. state[j] ^= key[k];
  34298. }
  34299. }
  34300. //SubBytes
  34301. for (j = 0; j < 16; ++j) {
  34302. state[j] = s[state[j]];
  34303. }
  34304. //ShiftRows
  34305. v = state[1];
  34306. state[1] = state[5];
  34307. state[5] = state[9];
  34308. state[9] = state[13];
  34309. state[13] = v;
  34310. v = state[2];
  34311. u = state[6];
  34312. state[2] = state[10];
  34313. state[6] = state[14];
  34314. state[10] = v;
  34315. state[14] = u;
  34316. v = state[3];
  34317. u = state[7];
  34318. t = state[11];
  34319. state[3] = state[15];
  34320. state[7] = v;
  34321. state[11] = u;
  34322. state[15] = t;
  34323. //AddRoundKey
  34324. for (j = 0, k = 224; j < 16; ++j, ++k) {
  34325. state[j] ^= key[k];
  34326. }
  34327. return state;
  34328. }
  34329. function AES256Cipher(key) {
  34330. this.key = expandKey256(key);
  34331. this.buffer = new Uint8Array(16);
  34332. this.bufferPosition = 0;
  34333. }
  34334. function decryptBlock2(data, finalize) {
  34335. var i, j, ii, sourceLength = data.length, buffer = this.buffer, bufferLength = this.bufferPosition, result = [], iv = this.iv;
  34336. for (i = 0; i < sourceLength; ++i) {
  34337. buffer[bufferLength] = data[i];
  34338. ++bufferLength;
  34339. if (bufferLength < 16) {
  34340. continue;
  34341. }
  34342. // buffer is full, decrypting
  34343. var plain = decrypt256(buffer, this.key);
  34344. // xor-ing the IV vector to get plain text
  34345. for (j = 0; j < 16; ++j) {
  34346. plain[j] ^= iv[j];
  34347. }
  34348. iv = buffer;
  34349. result.push(plain);
  34350. buffer = new Uint8Array(16);
  34351. bufferLength = 0;
  34352. }
  34353. // saving incomplete buffer
  34354. this.buffer = buffer;
  34355. this.bufferLength = bufferLength;
  34356. this.iv = iv;
  34357. if (result.length === 0) {
  34358. return new Uint8Array([]);
  34359. }
  34360. // combining plain text blocks into one
  34361. var outputLength = 16 * result.length;
  34362. if (finalize) {
  34363. // undo a padding that is described in RFC 2898
  34364. var lastBlock = result[result.length - 1];
  34365. var psLen = lastBlock[15];
  34366. if (psLen <= 16) {
  34367. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  34368. if (lastBlock[i] !== psLen) {
  34369. // Invalid padding, assume that the block has no padding.
  34370. psLen = 0;
  34371. break;
  34372. }
  34373. }
  34374. outputLength -= psLen;
  34375. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  34376. }
  34377. }
  34378. var output = new Uint8Array(outputLength);
  34379. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  34380. output.set(result[i], j);
  34381. }
  34382. return output;
  34383. }
  34384. AES256Cipher.prototype = {
  34385. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  34386. var i, sourceLength = data.length;
  34387. var buffer = this.buffer, bufferLength = this.bufferPosition;
  34388. // if not supplied an IV wait for IV values
  34389. // they are at the start of the stream
  34390. if (iv) {
  34391. this.iv = iv;
  34392. } else {
  34393. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  34394. buffer[bufferLength] = data[i];
  34395. }
  34396. if (bufferLength < 16) {
  34397. //need more data
  34398. this.bufferLength = bufferLength;
  34399. return new Uint8Array([]);
  34400. }
  34401. this.iv = buffer;
  34402. data = data.subarray(16);
  34403. }
  34404. this.buffer = new Uint8Array(16);
  34405. this.bufferLength = 0;
  34406. // starting decryption
  34407. this.decryptBlock = decryptBlock2;
  34408. return this.decryptBlock(data, finalize);
  34409. },
  34410. encrypt: function AES256Cipher_encrypt(data, iv) {
  34411. var i, j, ii, sourceLength = data.length, buffer = this.buffer, bufferLength = this.bufferPosition, result = [];
  34412. if (!iv) {
  34413. iv = new Uint8Array(16);
  34414. }
  34415. for (i = 0; i < sourceLength; ++i) {
  34416. buffer[bufferLength] = data[i];
  34417. ++bufferLength;
  34418. if (bufferLength < 16) {
  34419. continue;
  34420. }
  34421. for (j = 0; j < 16; ++j) {
  34422. buffer[j] ^= iv[j];
  34423. }
  34424. // buffer is full, encrypting
  34425. var cipher = encrypt256(buffer, this.key);
  34426. this.iv = cipher;
  34427. result.push(cipher);
  34428. buffer = new Uint8Array(16);
  34429. bufferLength = 0;
  34430. }
  34431. // saving incomplete buffer
  34432. this.buffer = buffer;
  34433. this.bufferLength = bufferLength;
  34434. this.iv = iv;
  34435. if (result.length === 0) {
  34436. return new Uint8Array([]);
  34437. }
  34438. // combining plain text blocks into one
  34439. var outputLength = 16 * result.length;
  34440. var output = new Uint8Array(outputLength);
  34441. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  34442. output.set(result[i], j);
  34443. }
  34444. return output;
  34445. }
  34446. };
  34447. return AES256Cipher;
  34448. }();
  34449. var PDF17 = function PDF17Closure() {
  34450. function compareByteArrays(array1, array2) {
  34451. if (array1.length !== array2.length) {
  34452. return false;
  34453. }
  34454. for (var i = 0; i < array1.length; i++) {
  34455. if (array1[i] !== array2[i]) {
  34456. return false;
  34457. }
  34458. }
  34459. return true;
  34460. }
  34461. function PDF17() {
  34462. }
  34463. PDF17.prototype = {
  34464. checkOwnerPassword: function PDF17_checkOwnerPassword(password, ownerValidationSalt, userBytes, ownerPassword) {
  34465. var hashData = new Uint8Array(password.length + 56);
  34466. hashData.set(password, 0);
  34467. hashData.set(ownerValidationSalt, password.length);
  34468. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  34469. var result = calculateSHA256(hashData, 0, hashData.length);
  34470. return compareByteArrays(result, ownerPassword);
  34471. },
  34472. checkUserPassword: function PDF17_checkUserPassword(password, userValidationSalt, userPassword) {
  34473. var hashData = new Uint8Array(password.length + 8);
  34474. hashData.set(password, 0);
  34475. hashData.set(userValidationSalt, password.length);
  34476. var result = calculateSHA256(hashData, 0, hashData.length);
  34477. return compareByteArrays(result, userPassword);
  34478. },
  34479. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes, ownerEncryption) {
  34480. var hashData = new Uint8Array(password.length + 56);
  34481. hashData.set(password, 0);
  34482. hashData.set(ownerKeySalt, password.length);
  34483. hashData.set(userBytes, password.length + ownerKeySalt.length);
  34484. var key = calculateSHA256(hashData, 0, hashData.length);
  34485. var cipher = new AES256Cipher(key);
  34486. return cipher.decryptBlock(ownerEncryption, false, new Uint8Array(16));
  34487. },
  34488. getUserKey: function PDF17_getUserKey(password, userKeySalt, userEncryption) {
  34489. var hashData = new Uint8Array(password.length + 8);
  34490. hashData.set(password, 0);
  34491. hashData.set(userKeySalt, password.length);
  34492. //key is the decryption key for the UE string
  34493. var key = calculateSHA256(hashData, 0, hashData.length);
  34494. var cipher = new AES256Cipher(key);
  34495. return cipher.decryptBlock(userEncryption, false, new Uint8Array(16));
  34496. }
  34497. };
  34498. return PDF17;
  34499. }();
  34500. var PDF20 = function PDF20Closure() {
  34501. function concatArrays(array1, array2) {
  34502. var t = new Uint8Array(array1.length + array2.length);
  34503. t.set(array1, 0);
  34504. t.set(array2, array1.length);
  34505. return t;
  34506. }
  34507. function calculatePDF20Hash(password, input, userBytes) {
  34508. //This refers to Algorithm 2.B as defined in ISO 32000-2
  34509. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  34510. var e = [0];
  34511. var i = 0;
  34512. while (i < 64 || e[e.length - 1] > i - 32) {
  34513. var arrayLength = password.length + k.length + userBytes.length;
  34514. var k1 = new Uint8Array(arrayLength * 64);
  34515. var array = concatArrays(password, k);
  34516. array = concatArrays(array, userBytes);
  34517. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  34518. k1.set(array, pos);
  34519. }
  34520. //AES128 CBC NO PADDING with
  34521. //first 16 bytes of k as the key and the second 16 as the iv.
  34522. var cipher = new AES128Cipher(k.subarray(0, 16));
  34523. e = cipher.encrypt(k1, k.subarray(16, 32));
  34524. //Now we have to take the first 16 bytes of an unsigned
  34525. //big endian integer... and compute the remainder
  34526. //modulo 3.... That is a fairly large number and
  34527. //JavaScript isn't going to handle that well...
  34528. //So we're using a trick that allows us to perform
  34529. //modulo math byte by byte
  34530. var remainder = 0;
  34531. for (var z = 0; z < 16; z++) {
  34532. remainder *= 256 % 3;
  34533. remainder %= 3;
  34534. remainder += (e[z] >>> 0) % 3;
  34535. remainder %= 3;
  34536. }
  34537. if (remainder === 0) {
  34538. k = calculateSHA256(e, 0, e.length);
  34539. } else if (remainder === 1) {
  34540. k = calculateSHA384(e, 0, e.length);
  34541. } else if (remainder === 2) {
  34542. k = calculateSHA512(e, 0, e.length);
  34543. }
  34544. i++;
  34545. }
  34546. return k.subarray(0, 32);
  34547. }
  34548. function PDF20() {
  34549. }
  34550. function compareByteArrays(array1, array2) {
  34551. if (array1.length !== array2.length) {
  34552. return false;
  34553. }
  34554. for (var i = 0; i < array1.length; i++) {
  34555. if (array1[i] !== array2[i]) {
  34556. return false;
  34557. }
  34558. }
  34559. return true;
  34560. }
  34561. PDF20.prototype = {
  34562. hash: function PDF20_hash(password, concatBytes, userBytes) {
  34563. return calculatePDF20Hash(password, concatBytes, userBytes);
  34564. },
  34565. checkOwnerPassword: function PDF20_checkOwnerPassword(password, ownerValidationSalt, userBytes, ownerPassword) {
  34566. var hashData = new Uint8Array(password.length + 56);
  34567. hashData.set(password, 0);
  34568. hashData.set(ownerValidationSalt, password.length);
  34569. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  34570. var result = calculatePDF20Hash(password, hashData, userBytes);
  34571. return compareByteArrays(result, ownerPassword);
  34572. },
  34573. checkUserPassword: function PDF20_checkUserPassword(password, userValidationSalt, userPassword) {
  34574. var hashData = new Uint8Array(password.length + 8);
  34575. hashData.set(password, 0);
  34576. hashData.set(userValidationSalt, password.length);
  34577. var result = calculatePDF20Hash(password, hashData, []);
  34578. return compareByteArrays(result, userPassword);
  34579. },
  34580. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes, ownerEncryption) {
  34581. var hashData = new Uint8Array(password.length + 56);
  34582. hashData.set(password, 0);
  34583. hashData.set(ownerKeySalt, password.length);
  34584. hashData.set(userBytes, password.length + ownerKeySalt.length);
  34585. var key = calculatePDF20Hash(password, hashData, userBytes);
  34586. var cipher = new AES256Cipher(key);
  34587. return cipher.decryptBlock(ownerEncryption, false, new Uint8Array(16));
  34588. },
  34589. getUserKey: function PDF20_getUserKey(password, userKeySalt, userEncryption) {
  34590. var hashData = new Uint8Array(password.length + 8);
  34591. hashData.set(password, 0);
  34592. hashData.set(userKeySalt, password.length);
  34593. //key is the decryption key for the UE string
  34594. var key = calculatePDF20Hash(password, hashData, []);
  34595. var cipher = new AES256Cipher(key);
  34596. return cipher.decryptBlock(userEncryption, false, new Uint8Array(16));
  34597. }
  34598. };
  34599. return PDF20;
  34600. }();
  34601. var CipherTransform = function CipherTransformClosure() {
  34602. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  34603. this.stringCipherConstructor = stringCipherConstructor;
  34604. this.streamCipherConstructor = streamCipherConstructor;
  34605. }
  34606. CipherTransform.prototype = {
  34607. createStream: function CipherTransform_createStream(stream, length) {
  34608. var cipher = new this.streamCipherConstructor();
  34609. return new DecryptStream(stream, length, function cipherTransformDecryptStream(data, finalize) {
  34610. return cipher.decryptBlock(data, finalize);
  34611. });
  34612. },
  34613. decryptString: function CipherTransform_decryptString(s) {
  34614. var cipher = new this.stringCipherConstructor();
  34615. var data = stringToBytes(s);
  34616. data = cipher.decryptBlock(data, true);
  34617. return bytesToString(data);
  34618. }
  34619. };
  34620. return CipherTransform;
  34621. }();
  34622. var CipherTransformFactory = function CipherTransformFactoryClosure() {
  34623. var defaultPasswordBytes = new Uint8Array([
  34624. 0x28,
  34625. 0xBF,
  34626. 0x4E,
  34627. 0x5E,
  34628. 0x4E,
  34629. 0x75,
  34630. 0x8A,
  34631. 0x41,
  34632. 0x64,
  34633. 0x00,
  34634. 0x4E,
  34635. 0x56,
  34636. 0xFF,
  34637. 0xFA,
  34638. 0x01,
  34639. 0x08,
  34640. 0x2E,
  34641. 0x2E,
  34642. 0x00,
  34643. 0xB6,
  34644. 0xD0,
  34645. 0x68,
  34646. 0x3E,
  34647. 0x80,
  34648. 0x2F,
  34649. 0x0C,
  34650. 0xA9,
  34651. 0xFE,
  34652. 0x64,
  34653. 0x53,
  34654. 0x69,
  34655. 0x7A
  34656. ]);
  34657. function createEncryptionKey20(revision, password, ownerPassword, ownerValidationSalt, ownerKeySalt, uBytes, userPassword, userValidationSalt, userKeySalt, ownerEncryption, userEncryption, perms) {
  34658. if (password) {
  34659. var passwordLength = Math.min(127, password.length);
  34660. password = password.subarray(0, passwordLength);
  34661. } else {
  34662. password = [];
  34663. }
  34664. var pdfAlgorithm;
  34665. if (revision === 6) {
  34666. pdfAlgorithm = new PDF20();
  34667. } else {
  34668. pdfAlgorithm = new PDF17();
  34669. }
  34670. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt, userPassword)) {
  34671. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  34672. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt, uBytes, ownerPassword)) {
  34673. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes, ownerEncryption);
  34674. }
  34675. return null;
  34676. }
  34677. function prepareKeyData(fileId, password, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata) {
  34678. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  34679. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  34680. if (password) {
  34681. n = Math.min(32, password.length);
  34682. for (; i < n; ++i) {
  34683. hashData[i] = password[i];
  34684. }
  34685. }
  34686. j = 0;
  34687. while (i < 32) {
  34688. hashData[i++] = defaultPasswordBytes[j++];
  34689. }
  34690. // as now the padded password in the hashData[0..i]
  34691. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  34692. hashData[i++] = ownerPassword[j];
  34693. }
  34694. hashData[i++] = flags & 0xFF;
  34695. hashData[i++] = flags >> 8 & 0xFF;
  34696. hashData[i++] = flags >> 16 & 0xFF;
  34697. hashData[i++] = flags >>> 24 & 0xFF;
  34698. for (j = 0, n = fileId.length; j < n; ++j) {
  34699. hashData[i++] = fileId[j];
  34700. }
  34701. if (revision >= 4 && !encryptMetadata) {
  34702. hashData[i++] = 0xFF;
  34703. hashData[i++] = 0xFF;
  34704. hashData[i++] = 0xFF;
  34705. hashData[i++] = 0xFF;
  34706. }
  34707. var hash = calculateMD5(hashData, 0, i);
  34708. var keyLengthInBytes = keyLength >> 3;
  34709. if (revision >= 3) {
  34710. for (j = 0; j < 50; ++j) {
  34711. hash = calculateMD5(hash, 0, keyLengthInBytes);
  34712. }
  34713. }
  34714. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  34715. var cipher, checkData;
  34716. if (revision >= 3) {
  34717. for (i = 0; i < 32; ++i) {
  34718. hashData[i] = defaultPasswordBytes[i];
  34719. }
  34720. for (j = 0, n = fileId.length; j < n; ++j) {
  34721. hashData[i++] = fileId[j];
  34722. }
  34723. cipher = new ARCFourCipher(encryptionKey);
  34724. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  34725. n = encryptionKey.length;
  34726. var derivedKey = new Uint8Array(n), k;
  34727. for (j = 1; j <= 19; ++j) {
  34728. for (k = 0; k < n; ++k) {
  34729. derivedKey[k] = encryptionKey[k] ^ j;
  34730. }
  34731. cipher = new ARCFourCipher(derivedKey);
  34732. checkData = cipher.encryptBlock(checkData);
  34733. }
  34734. for (j = 0, n = checkData.length; j < n; ++j) {
  34735. if (userPassword[j] !== checkData[j]) {
  34736. return null;
  34737. }
  34738. }
  34739. } else {
  34740. cipher = new ARCFourCipher(encryptionKey);
  34741. checkData = cipher.encryptBlock(defaultPasswordBytes);
  34742. for (j = 0, n = checkData.length; j < n; ++j) {
  34743. if (userPassword[j] !== checkData[j]) {
  34744. return null;
  34745. }
  34746. }
  34747. }
  34748. return encryptionKey;
  34749. }
  34750. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  34751. var hashData = new Uint8Array(32), i = 0, j, n;
  34752. n = Math.min(32, password.length);
  34753. for (; i < n; ++i) {
  34754. hashData[i] = password[i];
  34755. }
  34756. j = 0;
  34757. while (i < 32) {
  34758. hashData[i++] = defaultPasswordBytes[j++];
  34759. }
  34760. var hash = calculateMD5(hashData, 0, i);
  34761. var keyLengthInBytes = keyLength >> 3;
  34762. if (revision >= 3) {
  34763. for (j = 0; j < 50; ++j) {
  34764. hash = calculateMD5(hash, 0, hash.length);
  34765. }
  34766. }
  34767. var cipher, userPassword;
  34768. if (revision >= 3) {
  34769. userPassword = ownerPassword;
  34770. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  34771. for (j = 19; j >= 0; j--) {
  34772. for (k = 0; k < keyLengthInBytes; ++k) {
  34773. derivedKey[k] = hash[k] ^ j;
  34774. }
  34775. cipher = new ARCFourCipher(derivedKey);
  34776. userPassword = cipher.encryptBlock(userPassword);
  34777. }
  34778. } else {
  34779. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  34780. userPassword = cipher.encryptBlock(ownerPassword);
  34781. }
  34782. return userPassword;
  34783. }
  34784. var identityName = Name.get('Identity');
  34785. function CipherTransformFactory(dict, fileId, password) {
  34786. var filter = dict.get('Filter');
  34787. if (!isName(filter, 'Standard')) {
  34788. error('unknown encryption method');
  34789. }
  34790. this.dict = dict;
  34791. var algorithm = dict.get('V');
  34792. if (!isInt(algorithm) || algorithm !== 1 && algorithm !== 2 && algorithm !== 4 && algorithm !== 5) {
  34793. error('unsupported encryption algorithm');
  34794. }
  34795. this.algorithm = algorithm;
  34796. var keyLength = dict.get('Length');
  34797. if (!keyLength) {
  34798. // Spec asks to rely on encryption dictionary's Length entry, however
  34799. // some PDFs don't have it. Trying to recover.
  34800. if (algorithm <= 3) {
  34801. // For 1 and 2 it's fixed to 40-bit, for 3 40-bit is a minimal value.
  34802. keyLength = 40;
  34803. } else {
  34804. // Trying to find default handler -- it usually has Length.
  34805. var cfDict = dict.get('CF');
  34806. var streamCryptoName = dict.get('StmF');
  34807. if (isDict(cfDict) && isName(streamCryptoName)) {
  34808. var handlerDict = cfDict.get(streamCryptoName.name);
  34809. keyLength = handlerDict && handlerDict.get('Length') || 128;
  34810. if (keyLength < 40) {
  34811. // Sometimes it's incorrect value of bits, generators specify bytes.
  34812. keyLength <<= 3;
  34813. }
  34814. }
  34815. }
  34816. }
  34817. if (!isInt(keyLength) || keyLength < 40 || keyLength % 8 !== 0) {
  34818. error('invalid key length');
  34819. }
  34820. // prepare keys
  34821. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  34822. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  34823. var flags = dict.get('P');
  34824. var revision = dict.get('R');
  34825. // meaningful when V is 4 or 5
  34826. var encryptMetadata = (algorithm === 4 || algorithm === 5) && dict.get('EncryptMetadata') !== false;
  34827. this.encryptMetadata = encryptMetadata;
  34828. var fileIdBytes = stringToBytes(fileId);
  34829. var passwordBytes;
  34830. if (password) {
  34831. if (revision === 6) {
  34832. try {
  34833. password = utf8StringToString(password);
  34834. } catch (ex) {
  34835. warn('CipherTransformFactory: ' + 'Unable to convert UTF8 encoded password.');
  34836. }
  34837. }
  34838. passwordBytes = stringToBytes(password);
  34839. }
  34840. var encryptionKey;
  34841. if (algorithm !== 5) {
  34842. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata);
  34843. } else {
  34844. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  34845. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  34846. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  34847. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  34848. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  34849. var ownerEncryption = stringToBytes(dict.get('OE'));
  34850. var userEncryption = stringToBytes(dict.get('UE'));
  34851. var perms = stringToBytes(dict.get('Perms'));
  34852. encryptionKey = createEncryptionKey20(revision, passwordBytes, ownerPassword, ownerValidationSalt, ownerKeySalt, uBytes, userPassword, userValidationSalt, userKeySalt, ownerEncryption, userEncryption, perms);
  34853. }
  34854. if (!encryptionKey && !password) {
  34855. throw new PasswordException('No password given', PasswordResponses.NEED_PASSWORD);
  34856. } else if (!encryptionKey && password) {
  34857. // Attempting use the password as an owner password
  34858. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword, revision, keyLength);
  34859. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword, ownerPassword, userPassword, flags, revision, keyLength, encryptMetadata);
  34860. }
  34861. if (!encryptionKey) {
  34862. throw new PasswordException('Incorrect Password', PasswordResponses.INCORRECT_PASSWORD);
  34863. }
  34864. this.encryptionKey = encryptionKey;
  34865. if (algorithm >= 4) {
  34866. this.cf = dict.get('CF');
  34867. this.stmf = dict.get('StmF') || identityName;
  34868. this.strf = dict.get('StrF') || identityName;
  34869. this.eff = dict.get('EFF') || this.stmf;
  34870. }
  34871. }
  34872. function buildObjectKey(num, gen, encryptionKey, isAes) {
  34873. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  34874. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  34875. key[i] = encryptionKey[i];
  34876. }
  34877. key[i++] = num & 0xFF;
  34878. key[i++] = num >> 8 & 0xFF;
  34879. key[i++] = num >> 16 & 0xFF;
  34880. key[i++] = gen & 0xFF;
  34881. key[i++] = gen >> 8 & 0xFF;
  34882. if (isAes) {
  34883. key[i++] = 0x73;
  34884. key[i++] = 0x41;
  34885. key[i++] = 0x6C;
  34886. key[i++] = 0x54;
  34887. }
  34888. var hash = calculateMD5(key, 0, i);
  34889. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  34890. }
  34891. function buildCipherConstructor(cf, name, num, gen, key) {
  34892. var cryptFilter = cf.get(name.name);
  34893. var cfm;
  34894. if (cryptFilter !== null && cryptFilter !== undefined) {
  34895. cfm = cryptFilter.get('CFM');
  34896. }
  34897. if (!cfm || cfm.name === 'None') {
  34898. return function cipherTransformFactoryBuildCipherConstructorNone() {
  34899. return new NullCipher();
  34900. };
  34901. }
  34902. if ('V2' === cfm.name) {
  34903. return function cipherTransformFactoryBuildCipherConstructorV2() {
  34904. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  34905. };
  34906. }
  34907. if ('AESV2' === cfm.name) {
  34908. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  34909. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  34910. };
  34911. }
  34912. if ('AESV3' === cfm.name) {
  34913. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  34914. return new AES256Cipher(key);
  34915. };
  34916. }
  34917. error('Unknown crypto method');
  34918. }
  34919. CipherTransformFactory.prototype = {
  34920. createCipherTransform: function CipherTransformFactory_createCipherTransform(num, gen) {
  34921. if (this.algorithm === 4 || this.algorithm === 5) {
  34922. return new CipherTransform(buildCipherConstructor(this.cf, this.stmf, num, gen, this.encryptionKey), buildCipherConstructor(this.cf, this.strf, num, gen, this.encryptionKey));
  34923. }
  34924. // algorithms 1 and 2
  34925. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  34926. var cipherConstructor = function buildCipherCipherConstructor() {
  34927. return new ARCFourCipher(key);
  34928. };
  34929. return new CipherTransform(cipherConstructor, cipherConstructor);
  34930. }
  34931. };
  34932. return CipherTransformFactory;
  34933. }();
  34934. exports.AES128Cipher = AES128Cipher;
  34935. exports.AES256Cipher = AES256Cipher;
  34936. exports.ARCFourCipher = ARCFourCipher;
  34937. exports.CipherTransformFactory = CipherTransformFactory;
  34938. exports.PDF17 = PDF17;
  34939. exports.PDF20 = PDF20;
  34940. exports.calculateMD5 = calculateMD5;
  34941. exports.calculateSHA256 = calculateSHA256;
  34942. exports.calculateSHA384 = calculateSHA384;
  34943. exports.calculateSHA512 = calculateSHA512;
  34944. }));
  34945. (function (root, factory) {
  34946. factory(root.pdfjsCoreFontRenderer = {}, root.pdfjsSharedUtil, root.pdfjsCoreStream, root.pdfjsCoreGlyphList, root.pdfjsCoreEncodings, root.pdfjsCoreCFFParser);
  34947. }(this, function (exports, sharedUtil, coreStream, coreGlyphList, coreEncodings, coreCFFParser) {
  34948. var Util = sharedUtil.Util;
  34949. var bytesToString = sharedUtil.bytesToString;
  34950. var error = sharedUtil.error;
  34951. var Stream = coreStream.Stream;
  34952. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  34953. var StandardEncoding = coreEncodings.StandardEncoding;
  34954. var CFFParser = coreCFFParser.CFFParser;
  34955. var FontRendererFactory = function FontRendererFactoryClosure() {
  34956. function getLong(data, offset) {
  34957. return data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3];
  34958. }
  34959. function getUshort(data, offset) {
  34960. return data[offset] << 8 | data[offset + 1];
  34961. }
  34962. function parseCmap(data, start, end) {
  34963. var offset = getUshort(data, start + 2) === 1 ? getLong(data, start + 8) : getLong(data, start + 16);
  34964. var format = getUshort(data, start + offset);
  34965. var length, ranges, p, i;
  34966. if (format === 4) {
  34967. length = getUshort(data, start + offset + 2);
  34968. var segCount = getUshort(data, start + offset + 6) >> 1;
  34969. p = start + offset + 14;
  34970. ranges = [];
  34971. for (i = 0; i < segCount; i++, p += 2) {
  34972. ranges[i] = { end: getUshort(data, p) };
  34973. }
  34974. p += 2;
  34975. for (i = 0; i < segCount; i++, p += 2) {
  34976. ranges[i].start = getUshort(data, p);
  34977. }
  34978. for (i = 0; i < segCount; i++, p += 2) {
  34979. ranges[i].idDelta = getUshort(data, p);
  34980. }
  34981. for (i = 0; i < segCount; i++, p += 2) {
  34982. var idOffset = getUshort(data, p);
  34983. if (idOffset === 0) {
  34984. continue;
  34985. }
  34986. ranges[i].ids = [];
  34987. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  34988. ranges[i].ids[j] = getUshort(data, p + idOffset);
  34989. idOffset += 2;
  34990. }
  34991. }
  34992. return ranges;
  34993. } else if (format === 12) {
  34994. length = getLong(data, start + offset + 4);
  34995. var groups = getLong(data, start + offset + 12);
  34996. p = start + offset + 16;
  34997. ranges = [];
  34998. for (i = 0; i < groups; i++) {
  34999. ranges.push({
  35000. start: getLong(data, p),
  35001. end: getLong(data, p + 4),
  35002. idDelta: getLong(data, p + 8) - getLong(data, p)
  35003. });
  35004. p += 12;
  35005. }
  35006. return ranges;
  35007. }
  35008. error('not supported cmap: ' + format);
  35009. }
  35010. function parseCff(data, start, end, seacAnalysisEnabled) {
  35011. var properties = {};
  35012. var parser = new CFFParser(new Stream(data, start, end - start), properties, seacAnalysisEnabled);
  35013. var cff = parser.parse();
  35014. return {
  35015. glyphs: cff.charStrings.objects,
  35016. subrs: cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex && cff.topDict.privateDict.subrsIndex.objects,
  35017. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  35018. };
  35019. }
  35020. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  35021. var itemSize, itemDecode;
  35022. if (isGlyphLocationsLong) {
  35023. itemSize = 4;
  35024. itemDecode = function fontItemDecodeLong(data, offset) {
  35025. return data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3];
  35026. };
  35027. } else {
  35028. itemSize = 2;
  35029. itemDecode = function fontItemDecode(data, offset) {
  35030. return data[offset] << 9 | data[offset + 1] << 1;
  35031. };
  35032. }
  35033. var glyphs = [];
  35034. var startOffset = itemDecode(loca, 0);
  35035. for (var j = itemSize; j < loca.length; j += itemSize) {
  35036. var endOffset = itemDecode(loca, j);
  35037. glyphs.push(glyf.subarray(startOffset, endOffset));
  35038. startOffset = endOffset;
  35039. }
  35040. return glyphs;
  35041. }
  35042. function lookupCmap(ranges, unicode) {
  35043. var code = unicode.charCodeAt(0), gid = 0;
  35044. var l = 0, r = ranges.length - 1;
  35045. while (l < r) {
  35046. var c = l + r + 1 >> 1;
  35047. if (code < ranges[c].start) {
  35048. r = c - 1;
  35049. } else {
  35050. l = c;
  35051. }
  35052. }
  35053. if (ranges[l].start <= code && code <= ranges[l].end) {
  35054. gid = ranges[l].idDelta + (ranges[l].ids ? ranges[l].ids[code - ranges[l].start] : code) & 0xFFFF;
  35055. }
  35056. return {
  35057. charCode: code,
  35058. glyphId: gid
  35059. };
  35060. }
  35061. function compileGlyf(code, cmds, font) {
  35062. function moveTo(x, y) {
  35063. cmds.push({
  35064. cmd: 'moveTo',
  35065. args: [
  35066. x,
  35067. y
  35068. ]
  35069. });
  35070. }
  35071. function lineTo(x, y) {
  35072. cmds.push({
  35073. cmd: 'lineTo',
  35074. args: [
  35075. x,
  35076. y
  35077. ]
  35078. });
  35079. }
  35080. function quadraticCurveTo(xa, ya, x, y) {
  35081. cmds.push({
  35082. cmd: 'quadraticCurveTo',
  35083. args: [
  35084. xa,
  35085. ya,
  35086. x,
  35087. y
  35088. ]
  35089. });
  35090. }
  35091. var i = 0;
  35092. var numberOfContours = (code[i] << 24 | code[i + 1] << 16) >> 16;
  35093. var flags;
  35094. var x = 0, y = 0;
  35095. i += 10;
  35096. if (numberOfContours < 0) {
  35097. // composite glyph
  35098. do {
  35099. flags = code[i] << 8 | code[i + 1];
  35100. var glyphIndex = code[i + 2] << 8 | code[i + 3];
  35101. i += 4;
  35102. var arg1, arg2;
  35103. if (flags & 0x01) {
  35104. arg1 = (code[i] << 24 | code[i + 1] << 16) >> 16;
  35105. arg2 = (code[i + 2] << 24 | code[i + 3] << 16) >> 16;
  35106. i += 4;
  35107. } else {
  35108. arg1 = code[i++];
  35109. arg2 = code[i++];
  35110. }
  35111. if (flags & 0x02) {
  35112. x = arg1;
  35113. y = arg2;
  35114. } else {
  35115. x = 0;
  35116. y = 0;
  35117. }
  35118. // TODO "they are points" ?
  35119. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  35120. if (flags & 0x08) {
  35121. scaleX = scaleY = (code[i] << 24 | code[i + 1] << 16) / 1073741824;
  35122. i += 2;
  35123. } else if (flags & 0x40) {
  35124. scaleX = (code[i] << 24 | code[i + 1] << 16) / 1073741824;
  35125. scaleY = (code[i + 2] << 24 | code[i + 3] << 16) / 1073741824;
  35126. i += 4;
  35127. } else if (flags & 0x80) {
  35128. scaleX = (code[i] << 24 | code[i + 1] << 16) / 1073741824;
  35129. scale01 = (code[i + 2] << 24 | code[i + 3] << 16) / 1073741824;
  35130. scale10 = (code[i + 4] << 24 | code[i + 5] << 16) / 1073741824;
  35131. scaleY = (code[i + 6] << 24 | code[i + 7] << 16) / 1073741824;
  35132. i += 8;
  35133. }
  35134. var subglyph = font.glyphs[glyphIndex];
  35135. if (subglyph) {
  35136. cmds.push({ cmd: 'save' });
  35137. cmds.push({
  35138. cmd: 'transform',
  35139. args: [
  35140. scaleX,
  35141. scale01,
  35142. scale10,
  35143. scaleY,
  35144. x,
  35145. y
  35146. ]
  35147. });
  35148. compileGlyf(subglyph, cmds, font);
  35149. cmds.push({ cmd: 'restore' });
  35150. }
  35151. } while (flags & 0x20);
  35152. } else {
  35153. // simple glyph
  35154. var endPtsOfContours = [];
  35155. var j, jj;
  35156. for (j = 0; j < numberOfContours; j++) {
  35157. endPtsOfContours.push(code[i] << 8 | code[i + 1]);
  35158. i += 2;
  35159. }
  35160. var instructionLength = code[i] << 8 | code[i + 1];
  35161. i += 2 + instructionLength;
  35162. // skipping the instructions
  35163. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  35164. var points = [];
  35165. while (points.length < numberOfPoints) {
  35166. flags = code[i++];
  35167. var repeat = 1;
  35168. if (flags & 0x08) {
  35169. repeat += code[i++];
  35170. }
  35171. while (repeat-- > 0) {
  35172. points.push({ flags: flags });
  35173. }
  35174. }
  35175. for (j = 0; j < numberOfPoints; j++) {
  35176. switch (points[j].flags & 0x12) {
  35177. case 0x00:
  35178. x += (code[i] << 24 | code[i + 1] << 16) >> 16;
  35179. i += 2;
  35180. break;
  35181. case 0x02:
  35182. x -= code[i++];
  35183. break;
  35184. case 0x12:
  35185. x += code[i++];
  35186. break;
  35187. }
  35188. points[j].x = x;
  35189. }
  35190. for (j = 0; j < numberOfPoints; j++) {
  35191. switch (points[j].flags & 0x24) {
  35192. case 0x00:
  35193. y += (code[i] << 24 | code[i + 1] << 16) >> 16;
  35194. i += 2;
  35195. break;
  35196. case 0x04:
  35197. y -= code[i++];
  35198. break;
  35199. case 0x24:
  35200. y += code[i++];
  35201. break;
  35202. }
  35203. points[j].y = y;
  35204. }
  35205. var startPoint = 0;
  35206. for (i = 0; i < numberOfContours; i++) {
  35207. var endPoint = endPtsOfContours[i];
  35208. // contours might have implicit points, which is located in the middle
  35209. // between two neighboring off-curve points
  35210. var contour = points.slice(startPoint, endPoint + 1);
  35211. if (contour[0].flags & 1) {
  35212. contour.push(contour[0]);
  35213. } else // using start point at the contour end
  35214. if (contour[contour.length - 1].flags & 1) {
  35215. // first is off-curve point, trying to use one from the end
  35216. contour.unshift(contour[contour.length - 1]);
  35217. } else {
  35218. // start and end are off-curve points, creating implicit one
  35219. var p = {
  35220. flags: 1,
  35221. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  35222. y: (contour[0].y + contour[contour.length - 1].y) / 2
  35223. };
  35224. contour.unshift(p);
  35225. contour.push(p);
  35226. }
  35227. moveTo(contour[0].x, contour[0].y);
  35228. for (j = 1, jj = contour.length; j < jj; j++) {
  35229. if (contour[j].flags & 1) {
  35230. lineTo(contour[j].x, contour[j].y);
  35231. } else if (contour[j + 1].flags & 1) {
  35232. quadraticCurveTo(contour[j].x, contour[j].y, contour[j + 1].x, contour[j + 1].y);
  35233. j++;
  35234. } else {
  35235. quadraticCurveTo(contour[j].x, contour[j].y, (contour[j].x + contour[j + 1].x) / 2, (contour[j].y + contour[j + 1].y) / 2);
  35236. }
  35237. }
  35238. startPoint = endPoint + 1;
  35239. }
  35240. }
  35241. }
  35242. function compileCharString(code, cmds, font) {
  35243. var stack = [];
  35244. var x = 0, y = 0;
  35245. var stems = 0;
  35246. function moveTo(x, y) {
  35247. cmds.push({
  35248. cmd: 'moveTo',
  35249. args: [
  35250. x,
  35251. y
  35252. ]
  35253. });
  35254. }
  35255. function lineTo(x, y) {
  35256. cmds.push({
  35257. cmd: 'lineTo',
  35258. args: [
  35259. x,
  35260. y
  35261. ]
  35262. });
  35263. }
  35264. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  35265. cmds.push({
  35266. cmd: 'bezierCurveTo',
  35267. args: [
  35268. x1,
  35269. y1,
  35270. x2,
  35271. y2,
  35272. x,
  35273. y
  35274. ]
  35275. });
  35276. }
  35277. function parse(code) {
  35278. var i = 0;
  35279. while (i < code.length) {
  35280. var stackClean = false;
  35281. var v = code[i++];
  35282. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  35283. switch (v) {
  35284. case 1:
  35285. // hstem
  35286. stems += stack.length >> 1;
  35287. stackClean = true;
  35288. break;
  35289. case 3:
  35290. // vstem
  35291. stems += stack.length >> 1;
  35292. stackClean = true;
  35293. break;
  35294. case 4:
  35295. // vmoveto
  35296. y += stack.pop();
  35297. moveTo(x, y);
  35298. stackClean = true;
  35299. break;
  35300. case 5:
  35301. // rlineto
  35302. while (stack.length > 0) {
  35303. x += stack.shift();
  35304. y += stack.shift();
  35305. lineTo(x, y);
  35306. }
  35307. break;
  35308. case 6:
  35309. // hlineto
  35310. while (stack.length > 0) {
  35311. x += stack.shift();
  35312. lineTo(x, y);
  35313. if (stack.length === 0) {
  35314. break;
  35315. }
  35316. y += stack.shift();
  35317. lineTo(x, y);
  35318. }
  35319. break;
  35320. case 7:
  35321. // vlineto
  35322. while (stack.length > 0) {
  35323. y += stack.shift();
  35324. lineTo(x, y);
  35325. if (stack.length === 0) {
  35326. break;
  35327. }
  35328. x += stack.shift();
  35329. lineTo(x, y);
  35330. }
  35331. break;
  35332. case 8:
  35333. // rrcurveto
  35334. while (stack.length > 0) {
  35335. xa = x + stack.shift();
  35336. ya = y + stack.shift();
  35337. xb = xa + stack.shift();
  35338. yb = ya + stack.shift();
  35339. x = xb + stack.shift();
  35340. y = yb + stack.shift();
  35341. bezierCurveTo(xa, ya, xb, yb, x, y);
  35342. }
  35343. break;
  35344. case 10:
  35345. // callsubr
  35346. n = stack.pop() + font.subrsBias;
  35347. subrCode = font.subrs[n];
  35348. if (subrCode) {
  35349. parse(subrCode);
  35350. }
  35351. break;
  35352. case 11:
  35353. // return
  35354. return;
  35355. case 12:
  35356. v = code[i++];
  35357. switch (v) {
  35358. case 34:
  35359. // flex
  35360. xa = x + stack.shift();
  35361. xb = xa + stack.shift();
  35362. y1 = y + stack.shift();
  35363. x = xb + stack.shift();
  35364. bezierCurveTo(xa, y, xb, y1, x, y1);
  35365. xa = x + stack.shift();
  35366. xb = xa + stack.shift();
  35367. x = xb + stack.shift();
  35368. bezierCurveTo(xa, y1, xb, y, x, y);
  35369. break;
  35370. case 35:
  35371. // flex
  35372. xa = x + stack.shift();
  35373. ya = y + stack.shift();
  35374. xb = xa + stack.shift();
  35375. yb = ya + stack.shift();
  35376. x = xb + stack.shift();
  35377. y = yb + stack.shift();
  35378. bezierCurveTo(xa, ya, xb, yb, x, y);
  35379. xa = x + stack.shift();
  35380. ya = y + stack.shift();
  35381. xb = xa + stack.shift();
  35382. yb = ya + stack.shift();
  35383. x = xb + stack.shift();
  35384. y = yb + stack.shift();
  35385. bezierCurveTo(xa, ya, xb, yb, x, y);
  35386. stack.pop();
  35387. // fd
  35388. break;
  35389. case 36:
  35390. // hflex1
  35391. xa = x + stack.shift();
  35392. y1 = y + stack.shift();
  35393. xb = xa + stack.shift();
  35394. y2 = y1 + stack.shift();
  35395. x = xb + stack.shift();
  35396. bezierCurveTo(xa, y1, xb, y2, x, y2);
  35397. xa = x + stack.shift();
  35398. xb = xa + stack.shift();
  35399. y3 = y2 + stack.shift();
  35400. x = xb + stack.shift();
  35401. bezierCurveTo(xa, y2, xb, y3, x, y);
  35402. break;
  35403. case 37:
  35404. // flex1
  35405. var x0 = x, y0 = y;
  35406. xa = x + stack.shift();
  35407. ya = y + stack.shift();
  35408. xb = xa + stack.shift();
  35409. yb = ya + stack.shift();
  35410. x = xb + stack.shift();
  35411. y = yb + stack.shift();
  35412. bezierCurveTo(xa, ya, xb, yb, x, y);
  35413. xa = x + stack.shift();
  35414. ya = y + stack.shift();
  35415. xb = xa + stack.shift();
  35416. yb = ya + stack.shift();
  35417. x = xb;
  35418. y = yb;
  35419. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  35420. x += stack.shift();
  35421. } else {
  35422. y += stack.shift();
  35423. }
  35424. bezierCurveTo(xa, ya, xb, yb, x, y);
  35425. break;
  35426. default:
  35427. error('unknown operator: 12 ' + v);
  35428. }
  35429. break;
  35430. case 14:
  35431. // endchar
  35432. if (stack.length >= 4) {
  35433. var achar = stack.pop();
  35434. var bchar = stack.pop();
  35435. y = stack.pop();
  35436. x = stack.pop();
  35437. cmds.push({ cmd: 'save' });
  35438. cmds.push({
  35439. cmd: 'translate',
  35440. args: [
  35441. x,
  35442. y
  35443. ]
  35444. });
  35445. var cmap = lookupCmap(font.cmap, String.fromCharCode(font.glyphNameMap[StandardEncoding[achar]]));
  35446. compileCharString(font.glyphs[cmap.glyphId], cmds, font);
  35447. cmds.push({ cmd: 'restore' });
  35448. cmap = lookupCmap(font.cmap, String.fromCharCode(font.glyphNameMap[StandardEncoding[bchar]]));
  35449. compileCharString(font.glyphs[cmap.glyphId], cmds, font);
  35450. }
  35451. return;
  35452. case 18:
  35453. // hstemhm
  35454. stems += stack.length >> 1;
  35455. stackClean = true;
  35456. break;
  35457. case 19:
  35458. // hintmask
  35459. stems += stack.length >> 1;
  35460. i += stems + 7 >> 3;
  35461. stackClean = true;
  35462. break;
  35463. case 20:
  35464. // cntrmask
  35465. stems += stack.length >> 1;
  35466. i += stems + 7 >> 3;
  35467. stackClean = true;
  35468. break;
  35469. case 21:
  35470. // rmoveto
  35471. y += stack.pop();
  35472. x += stack.pop();
  35473. moveTo(x, y);
  35474. stackClean = true;
  35475. break;
  35476. case 22:
  35477. // hmoveto
  35478. x += stack.pop();
  35479. moveTo(x, y);
  35480. stackClean = true;
  35481. break;
  35482. case 23:
  35483. // vstemhm
  35484. stems += stack.length >> 1;
  35485. stackClean = true;
  35486. break;
  35487. case 24:
  35488. // rcurveline
  35489. while (stack.length > 2) {
  35490. xa = x + stack.shift();
  35491. ya = y + stack.shift();
  35492. xb = xa + stack.shift();
  35493. yb = ya + stack.shift();
  35494. x = xb + stack.shift();
  35495. y = yb + stack.shift();
  35496. bezierCurveTo(xa, ya, xb, yb, x, y);
  35497. }
  35498. x += stack.shift();
  35499. y += stack.shift();
  35500. lineTo(x, y);
  35501. break;
  35502. case 25:
  35503. // rlinecurve
  35504. while (stack.length > 6) {
  35505. x += stack.shift();
  35506. y += stack.shift();
  35507. lineTo(x, y);
  35508. }
  35509. xa = x + stack.shift();
  35510. ya = y + stack.shift();
  35511. xb = xa + stack.shift();
  35512. yb = ya + stack.shift();
  35513. x = xb + stack.shift();
  35514. y = yb + stack.shift();
  35515. bezierCurveTo(xa, ya, xb, yb, x, y);
  35516. break;
  35517. case 26:
  35518. // vvcurveto
  35519. if (stack.length % 2) {
  35520. x += stack.shift();
  35521. }
  35522. while (stack.length > 0) {
  35523. xa = x;
  35524. ya = y + stack.shift();
  35525. xb = xa + stack.shift();
  35526. yb = ya + stack.shift();
  35527. x = xb;
  35528. y = yb + stack.shift();
  35529. bezierCurveTo(xa, ya, xb, yb, x, y);
  35530. }
  35531. break;
  35532. case 27:
  35533. // hhcurveto
  35534. if (stack.length % 2) {
  35535. y += stack.shift();
  35536. }
  35537. while (stack.length > 0) {
  35538. xa = x + stack.shift();
  35539. ya = y;
  35540. xb = xa + stack.shift();
  35541. yb = ya + stack.shift();
  35542. x = xb + stack.shift();
  35543. y = yb;
  35544. bezierCurveTo(xa, ya, xb, yb, x, y);
  35545. }
  35546. break;
  35547. case 28:
  35548. stack.push((code[i] << 24 | code[i + 1] << 16) >> 16);
  35549. i += 2;
  35550. break;
  35551. case 29:
  35552. // callgsubr
  35553. n = stack.pop() + font.gsubrsBias;
  35554. subrCode = font.gsubrs[n];
  35555. if (subrCode) {
  35556. parse(subrCode);
  35557. }
  35558. break;
  35559. case 30:
  35560. // vhcurveto
  35561. while (stack.length > 0) {
  35562. xa = x;
  35563. ya = y + stack.shift();
  35564. xb = xa + stack.shift();
  35565. yb = ya + stack.shift();
  35566. x = xb + stack.shift();
  35567. y = yb + (stack.length === 1 ? stack.shift() : 0);
  35568. bezierCurveTo(xa, ya, xb, yb, x, y);
  35569. if (stack.length === 0) {
  35570. break;
  35571. }
  35572. xa = x + stack.shift();
  35573. ya = y;
  35574. xb = xa + stack.shift();
  35575. yb = ya + stack.shift();
  35576. y = yb + stack.shift();
  35577. x = xb + (stack.length === 1 ? stack.shift() : 0);
  35578. bezierCurveTo(xa, ya, xb, yb, x, y);
  35579. }
  35580. break;
  35581. case 31:
  35582. // hvcurveto
  35583. while (stack.length > 0) {
  35584. xa = x + stack.shift();
  35585. ya = y;
  35586. xb = xa + stack.shift();
  35587. yb = ya + stack.shift();
  35588. y = yb + stack.shift();
  35589. x = xb + (stack.length === 1 ? stack.shift() : 0);
  35590. bezierCurveTo(xa, ya, xb, yb, x, y);
  35591. if (stack.length === 0) {
  35592. break;
  35593. }
  35594. xa = x;
  35595. ya = y + stack.shift();
  35596. xb = xa + stack.shift();
  35597. yb = ya + stack.shift();
  35598. x = xb + stack.shift();
  35599. y = yb + (stack.length === 1 ? stack.shift() : 0);
  35600. bezierCurveTo(xa, ya, xb, yb, x, y);
  35601. }
  35602. break;
  35603. default:
  35604. if (v < 32) {
  35605. error('unknown operator: ' + v);
  35606. }
  35607. if (v < 247) {
  35608. stack.push(v - 139);
  35609. } else if (v < 251) {
  35610. stack.push((v - 247) * 256 + code[i++] + 108);
  35611. } else if (v < 255) {
  35612. stack.push(-(v - 251) * 256 - code[i++] - 108);
  35613. } else {
  35614. stack.push((code[i] << 24 | code[i + 1] << 16 | code[i + 2] << 8 | code[i + 3]) / 65536);
  35615. i += 4;
  35616. }
  35617. break;
  35618. }
  35619. if (stackClean) {
  35620. stack.length = 0;
  35621. }
  35622. }
  35623. }
  35624. parse(code);
  35625. }
  35626. var noop = '';
  35627. function CompiledFont(fontMatrix) {
  35628. this.compiledGlyphs = Object.create(null);
  35629. this.compiledCharCodeToGlyphId = Object.create(null);
  35630. this.fontMatrix = fontMatrix;
  35631. }
  35632. CompiledFont.prototype = {
  35633. getPathJs: function (unicode) {
  35634. var cmap = lookupCmap(this.cmap, unicode);
  35635. var fn = this.compiledGlyphs[cmap.glyphId];
  35636. if (!fn) {
  35637. fn = this.compileGlyph(this.glyphs[cmap.glyphId]);
  35638. this.compiledGlyphs[cmap.glyphId] = fn;
  35639. }
  35640. if (this.compiledCharCodeToGlyphId[cmap.charCode] === undefined) {
  35641. this.compiledCharCodeToGlyphId[cmap.charCode] = cmap.glyphId;
  35642. }
  35643. return fn;
  35644. },
  35645. compileGlyph: function (code) {
  35646. if (!code || code.length === 0 || code[0] === 14) {
  35647. return noop;
  35648. }
  35649. var cmds = [];
  35650. cmds.push({ cmd: 'save' });
  35651. cmds.push({
  35652. cmd: 'transform',
  35653. args: this.fontMatrix.slice()
  35654. });
  35655. cmds.push({
  35656. cmd: 'scale',
  35657. args: [
  35658. 'size',
  35659. '-size'
  35660. ]
  35661. });
  35662. this.compileGlyphImpl(code, cmds);
  35663. cmds.push({ cmd: 'restore' });
  35664. return cmds;
  35665. },
  35666. compileGlyphImpl: function () {
  35667. error('Children classes should implement this.');
  35668. },
  35669. hasBuiltPath: function (unicode) {
  35670. var cmap = lookupCmap(this.cmap, unicode);
  35671. return this.compiledGlyphs[cmap.glyphId] !== undefined && this.compiledCharCodeToGlyphId[cmap.charCode] !== undefined;
  35672. }
  35673. };
  35674. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  35675. fontMatrix = fontMatrix || [
  35676. 0.000488,
  35677. 0,
  35678. 0,
  35679. 0.000488,
  35680. 0,
  35681. 0
  35682. ];
  35683. CompiledFont.call(this, fontMatrix);
  35684. this.glyphs = glyphs;
  35685. this.cmap = cmap;
  35686. }
  35687. Util.inherit(TrueTypeCompiled, CompiledFont, {
  35688. compileGlyphImpl: function (code, cmds) {
  35689. compileGlyf(code, cmds, this);
  35690. }
  35691. });
  35692. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  35693. fontMatrix = fontMatrix || [
  35694. 0.001,
  35695. 0,
  35696. 0,
  35697. 0.001,
  35698. 0,
  35699. 0
  35700. ];
  35701. CompiledFont.call(this, fontMatrix);
  35702. this.glyphs = cffInfo.glyphs;
  35703. this.gsubrs = cffInfo.gsubrs || [];
  35704. this.subrs = cffInfo.subrs || [];
  35705. this.cmap = cmap;
  35706. this.glyphNameMap = glyphNameMap || getGlyphsUnicode();
  35707. this.gsubrsBias = this.gsubrs.length < 1240 ? 107 : this.gsubrs.length < 33900 ? 1131 : 32768;
  35708. this.subrsBias = this.subrs.length < 1240 ? 107 : this.subrs.length < 33900 ? 1131 : 32768;
  35709. }
  35710. Util.inherit(Type2Compiled, CompiledFont, {
  35711. compileGlyphImpl: function (code, cmds) {
  35712. compileCharString(code, cmds, this);
  35713. }
  35714. });
  35715. return {
  35716. create: function FontRendererFactory_create(font, seacAnalysisEnabled) {
  35717. var data = new Uint8Array(font.data);
  35718. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  35719. var numTables = getUshort(data, 4);
  35720. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  35721. var tag = bytesToString(data.subarray(p, p + 4));
  35722. var offset = getLong(data, p + 8);
  35723. var length = getLong(data, p + 12);
  35724. switch (tag) {
  35725. case 'cmap':
  35726. cmap = parseCmap(data, offset, offset + length);
  35727. break;
  35728. case 'glyf':
  35729. glyf = data.subarray(offset, offset + length);
  35730. break;
  35731. case 'loca':
  35732. loca = data.subarray(offset, offset + length);
  35733. break;
  35734. case 'head':
  35735. unitsPerEm = getUshort(data, offset + 18);
  35736. indexToLocFormat = getUshort(data, offset + 50);
  35737. break;
  35738. case 'CFF ':
  35739. cff = parseCff(data, offset, offset + length, seacAnalysisEnabled);
  35740. break;
  35741. }
  35742. }
  35743. if (glyf) {
  35744. var fontMatrix = !unitsPerEm ? font.fontMatrix : [
  35745. 1 / unitsPerEm,
  35746. 0,
  35747. 0,
  35748. 1 / unitsPerEm,
  35749. 0,
  35750. 0
  35751. ];
  35752. return new TrueTypeCompiled(parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  35753. } else {
  35754. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  35755. }
  35756. }
  35757. };
  35758. }();
  35759. exports.FontRendererFactory = FontRendererFactory;
  35760. }));
  35761. (function (root, factory) {
  35762. factory(root.pdfjsCoreParser = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  35763. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  35764. var MissingDataException = sharedUtil.MissingDataException;
  35765. var StreamType = sharedUtil.StreamType;
  35766. var assert = sharedUtil.assert;
  35767. var error = sharedUtil.error;
  35768. var info = sharedUtil.info;
  35769. var isArray = sharedUtil.isArray;
  35770. var isInt = sharedUtil.isInt;
  35771. var isNum = sharedUtil.isNum;
  35772. var isString = sharedUtil.isString;
  35773. var warn = sharedUtil.warn;
  35774. var Cmd = corePrimitives.Cmd;
  35775. var Dict = corePrimitives.Dict;
  35776. var Name = corePrimitives.Name;
  35777. var Ref = corePrimitives.Ref;
  35778. var isCmd = corePrimitives.isCmd;
  35779. var isDict = corePrimitives.isDict;
  35780. var isName = corePrimitives.isName;
  35781. var Ascii85Stream = coreStream.Ascii85Stream;
  35782. var AsciiHexStream = coreStream.AsciiHexStream;
  35783. var CCITTFaxStream = coreStream.CCITTFaxStream;
  35784. var FlateStream = coreStream.FlateStream;
  35785. var Jbig2Stream = coreStream.Jbig2Stream;
  35786. var JpegStream = coreStream.JpegStream;
  35787. var JpxStream = coreStream.JpxStream;
  35788. var LZWStream = coreStream.LZWStream;
  35789. var NullStream = coreStream.NullStream;
  35790. var PredictorStream = coreStream.PredictorStream;
  35791. var RunLengthStream = coreStream.RunLengthStream;
  35792. var EOF = {};
  35793. function isEOF(v) {
  35794. return v === EOF;
  35795. }
  35796. var MAX_LENGTH_TO_CACHE = 1000;
  35797. var Parser = function ParserClosure() {
  35798. function Parser(lexer, allowStreams, xref, recoveryMode) {
  35799. this.lexer = lexer;
  35800. this.allowStreams = allowStreams;
  35801. this.xref = xref;
  35802. this.recoveryMode = recoveryMode || false;
  35803. this.imageCache = Object.create(null);
  35804. this.refill();
  35805. }
  35806. Parser.prototype = {
  35807. refill: function Parser_refill() {
  35808. this.buf1 = this.lexer.getObj();
  35809. this.buf2 = this.lexer.getObj();
  35810. },
  35811. shift: function Parser_shift() {
  35812. if (isCmd(this.buf2, 'ID')) {
  35813. this.buf1 = this.buf2;
  35814. this.buf2 = null;
  35815. } else {
  35816. this.buf1 = this.buf2;
  35817. this.buf2 = this.lexer.getObj();
  35818. }
  35819. },
  35820. tryShift: function Parser_tryShift() {
  35821. try {
  35822. this.shift();
  35823. return true;
  35824. } catch (e) {
  35825. if (e instanceof MissingDataException) {
  35826. throw e;
  35827. }
  35828. // Upon failure, the caller should reset this.lexer.pos to a known good
  35829. // state and call this.shift() twice to reset the buffers.
  35830. return false;
  35831. }
  35832. },
  35833. getObj: function Parser_getObj(cipherTransform) {
  35834. var buf1 = this.buf1;
  35835. this.shift();
  35836. if (buf1 instanceof Cmd) {
  35837. switch (buf1.cmd) {
  35838. case 'BI':
  35839. // inline image
  35840. return this.makeInlineImage(cipherTransform);
  35841. case '[':
  35842. // array
  35843. var array = [];
  35844. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  35845. array.push(this.getObj(cipherTransform));
  35846. }
  35847. if (isEOF(this.buf1)) {
  35848. if (!this.recoveryMode) {
  35849. error('End of file inside array');
  35850. }
  35851. return array;
  35852. }
  35853. this.shift();
  35854. return array;
  35855. case '<<':
  35856. // dictionary or stream
  35857. var dict = new Dict(this.xref);
  35858. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  35859. if (!isName(this.buf1)) {
  35860. info('Malformed dictionary: key must be a name object');
  35861. this.shift();
  35862. continue;
  35863. }
  35864. var key = this.buf1.name;
  35865. this.shift();
  35866. if (isEOF(this.buf1)) {
  35867. break;
  35868. }
  35869. dict.set(key, this.getObj(cipherTransform));
  35870. }
  35871. if (isEOF(this.buf1)) {
  35872. if (!this.recoveryMode) {
  35873. error('End of file inside dictionary');
  35874. }
  35875. return dict;
  35876. }
  35877. // Stream objects are not allowed inside content streams or
  35878. // object streams.
  35879. if (isCmd(this.buf2, 'stream')) {
  35880. return this.allowStreams ? this.makeStream(dict, cipherTransform) : dict;
  35881. }
  35882. this.shift();
  35883. return dict;
  35884. default:
  35885. // simple object
  35886. return buf1;
  35887. }
  35888. }
  35889. if (isInt(buf1)) {
  35890. // indirect reference or integer
  35891. var num = buf1;
  35892. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  35893. var ref = new Ref(num, this.buf1);
  35894. this.shift();
  35895. this.shift();
  35896. return ref;
  35897. }
  35898. return num;
  35899. }
  35900. if (isString(buf1)) {
  35901. // string
  35902. var str = buf1;
  35903. if (cipherTransform) {
  35904. str = cipherTransform.decryptString(str);
  35905. }
  35906. return str;
  35907. }
  35908. // simple object
  35909. return buf1;
  35910. },
  35911. /**
  35912. * Find the end of the stream by searching for the /EI\s/.
  35913. * @returns {number} The inline stream length.
  35914. */
  35915. findDefaultInlineStreamEnd: function Parser_findDefaultInlineStreamEnd(stream) {
  35916. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  35917. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  35918. while ((ch = stream.getByte()) !== -1) {
  35919. if (state === 0) {
  35920. state = ch === E ? 1 : 0;
  35921. } else if (state === 1) {
  35922. state = ch === I ? 2 : 0;
  35923. } else {
  35924. assert(state === 2);
  35925. if (ch === SPACE || ch === LF || ch === CR) {
  35926. // Let's check the next five bytes are ASCII... just be sure.
  35927. n = 5;
  35928. followingBytes = stream.peekBytes(n);
  35929. for (i = 0; i < n; i++) {
  35930. ch = followingBytes[i];
  35931. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  35932. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  35933. // it's binary stuff. Resetting the state.
  35934. state = 0;
  35935. break;
  35936. }
  35937. }
  35938. if (state === 2) {
  35939. break;
  35940. }
  35941. } else
  35942. // Finished!
  35943. {
  35944. state = 0;
  35945. }
  35946. }
  35947. }
  35948. return stream.pos - 4 - startPos;
  35949. },
  35950. /**
  35951. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  35952. * @returns {number} The inline stream length.
  35953. */
  35954. findDCTDecodeInlineStreamEnd: function Parser_findDCTDecodeInlineStreamEnd(stream) {
  35955. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  35956. while ((b = stream.getByte()) !== -1) {
  35957. if (b !== 0xFF) {
  35958. // Not a valid marker.
  35959. continue;
  35960. }
  35961. switch (stream.getByte()) {
  35962. case 0x00:
  35963. // Byte stuffing.
  35964. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  35965. break;
  35966. case 0xFF:
  35967. // Fill byte.
  35968. // Avoid skipping a valid marker, resetting the stream position.
  35969. stream.skip(-1);
  35970. break;
  35971. case 0xD9:
  35972. // EOI
  35973. foundEOI = true;
  35974. break;
  35975. case 0xC0:
  35976. // SOF0
  35977. case 0xC1:
  35978. // SOF1
  35979. case 0xC2:
  35980. // SOF2
  35981. case 0xC3:
  35982. // SOF3
  35983. case 0xC5:
  35984. // SOF5
  35985. case 0xC6:
  35986. // SOF6
  35987. case 0xC7:
  35988. // SOF7
  35989. case 0xC9:
  35990. // SOF9
  35991. case 0xCA:
  35992. // SOF10
  35993. case 0xCB:
  35994. // SOF11
  35995. case 0xCD:
  35996. // SOF13
  35997. case 0xCE:
  35998. // SOF14
  35999. case 0xCF:
  36000. // SOF15
  36001. case 0xC4:
  36002. // DHT
  36003. case 0xCC:
  36004. // DAC
  36005. case 0xDA:
  36006. // SOS
  36007. case 0xDB:
  36008. // DQT
  36009. case 0xDC:
  36010. // DNL
  36011. case 0xDD:
  36012. // DRI
  36013. case 0xDE:
  36014. // DHP
  36015. case 0xDF:
  36016. // EXP
  36017. case 0xE0:
  36018. // APP0
  36019. case 0xE1:
  36020. // APP1
  36021. case 0xE2:
  36022. // APP2
  36023. case 0xE3:
  36024. // APP3
  36025. case 0xE4:
  36026. // APP4
  36027. case 0xE5:
  36028. // APP5
  36029. case 0xE6:
  36030. // APP6
  36031. case 0xE7:
  36032. // APP7
  36033. case 0xE8:
  36034. // APP8
  36035. case 0xE9:
  36036. // APP9
  36037. case 0xEA:
  36038. // APP10
  36039. case 0xEB:
  36040. // APP11
  36041. case 0xEC:
  36042. // APP12
  36043. case 0xED:
  36044. // APP13
  36045. case 0xEE:
  36046. // APP14
  36047. case 0xEF:
  36048. // APP15
  36049. case 0xFE:
  36050. // COM
  36051. // The marker should be followed by the length of the segment.
  36052. markerLength = stream.getUint16();
  36053. if (markerLength > 2) {
  36054. // |markerLength| contains the byte length of the marker segment,
  36055. // including its own length (2 bytes) and excluding the marker.
  36056. stream.skip(markerLength - 2);
  36057. } else
  36058. // Jump to the next marker.
  36059. {
  36060. // The marker length is invalid, resetting the stream position.
  36061. stream.skip(-2);
  36062. }
  36063. break;
  36064. }
  36065. if (foundEOI) {
  36066. break;
  36067. }
  36068. }
  36069. length = stream.pos - startPos;
  36070. if (b === -1) {
  36071. warn('Inline DCTDecode image stream: ' + 'EOI marker not found, searching for /EI/ instead.');
  36072. stream.skip(-length);
  36073. // Reset the stream position.
  36074. return this.findDefaultInlineStreamEnd(stream);
  36075. }
  36076. this.inlineStreamSkipEI(stream);
  36077. return length;
  36078. },
  36079. /**
  36080. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  36081. * @returns {number} The inline stream length.
  36082. */
  36083. findASCII85DecodeInlineStreamEnd: function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  36084. var TILDE = 0x7E, GT = 0x3E;
  36085. var startPos = stream.pos, ch, length;
  36086. while ((ch = stream.getByte()) !== -1) {
  36087. if (ch === TILDE && stream.peekByte() === GT) {
  36088. stream.skip();
  36089. break;
  36090. }
  36091. }
  36092. length = stream.pos - startPos;
  36093. if (ch === -1) {
  36094. warn('Inline ASCII85Decode image stream: ' + 'EOD marker not found, searching for /EI/ instead.');
  36095. stream.skip(-length);
  36096. // Reset the stream position.
  36097. return this.findDefaultInlineStreamEnd(stream);
  36098. }
  36099. this.inlineStreamSkipEI(stream);
  36100. return length;
  36101. },
  36102. /**
  36103. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  36104. * @returns {number} The inline stream length.
  36105. */
  36106. findASCIIHexDecodeInlineStreamEnd: function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  36107. var GT = 0x3E;
  36108. var startPos = stream.pos, ch, length;
  36109. while ((ch = stream.getByte()) !== -1) {
  36110. if (ch === GT) {
  36111. break;
  36112. }
  36113. }
  36114. length = stream.pos - startPos;
  36115. if (ch === -1) {
  36116. warn('Inline ASCIIHexDecode image stream: ' + 'EOD marker not found, searching for /EI/ instead.');
  36117. stream.skip(-length);
  36118. // Reset the stream position.
  36119. return this.findDefaultInlineStreamEnd(stream);
  36120. }
  36121. this.inlineStreamSkipEI(stream);
  36122. return length;
  36123. },
  36124. /**
  36125. * Skip over the /EI/ for streams where we search for an EOD marker.
  36126. */
  36127. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  36128. var E = 0x45, I = 0x49;
  36129. var state = 0, ch;
  36130. while ((ch = stream.getByte()) !== -1) {
  36131. if (state === 0) {
  36132. state = ch === E ? 1 : 0;
  36133. } else if (state === 1) {
  36134. state = ch === I ? 2 : 0;
  36135. } else if (state === 2) {
  36136. break;
  36137. }
  36138. }
  36139. },
  36140. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  36141. var lexer = this.lexer;
  36142. var stream = lexer.stream;
  36143. // Parse dictionary.
  36144. var dict = new Dict(this.xref);
  36145. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  36146. if (!isName(this.buf1)) {
  36147. error('Dictionary key must be a name object');
  36148. }
  36149. var key = this.buf1.name;
  36150. this.shift();
  36151. if (isEOF(this.buf1)) {
  36152. break;
  36153. }
  36154. dict.set(key, this.getObj(cipherTransform));
  36155. }
  36156. // Extract the name of the first (i.e. the current) image filter.
  36157. var filter = dict.get('Filter', 'F'), filterName;
  36158. if (isName(filter)) {
  36159. filterName = filter.name;
  36160. } else if (isArray(filter) && isName(filter[0])) {
  36161. filterName = filter[0].name;
  36162. }
  36163. // Parse image stream.
  36164. var startPos = stream.pos, length, i, ii;
  36165. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  36166. length = this.findDCTDecodeInlineStreamEnd(stream);
  36167. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  36168. length = this.findASCII85DecodeInlineStreamEnd(stream);
  36169. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  36170. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  36171. } else {
  36172. length = this.findDefaultInlineStreamEnd(stream);
  36173. }
  36174. var imageStream = stream.makeSubStream(startPos, length, dict);
  36175. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  36176. // adler32 checksum.
  36177. var adler32;
  36178. if (length < MAX_LENGTH_TO_CACHE) {
  36179. var imageBytes = imageStream.getBytes();
  36180. imageStream.reset();
  36181. var a = 1;
  36182. var b = 0;
  36183. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  36184. // No modulo required in the loop if imageBytes.length < 5552.
  36185. a += imageBytes[i] & 0xff;
  36186. b += a;
  36187. }
  36188. adler32 = b % 65521 << 16 | a % 65521;
  36189. if (this.imageCache.adler32 === adler32) {
  36190. this.buf2 = Cmd.get('EI');
  36191. this.shift();
  36192. this.imageCache[adler32].reset();
  36193. return this.imageCache[adler32];
  36194. }
  36195. }
  36196. if (cipherTransform) {
  36197. imageStream = cipherTransform.createStream(imageStream, length);
  36198. }
  36199. imageStream = this.filter(imageStream, dict, length);
  36200. imageStream.dict = dict;
  36201. if (adler32 !== undefined) {
  36202. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  36203. this.imageCache[adler32] = imageStream;
  36204. }
  36205. this.buf2 = Cmd.get('EI');
  36206. this.shift();
  36207. return imageStream;
  36208. },
  36209. makeStream: function Parser_makeStream(dict, cipherTransform) {
  36210. var lexer = this.lexer;
  36211. var stream = lexer.stream;
  36212. // get stream start position
  36213. lexer.skipToNextLine();
  36214. var pos = stream.pos - 1;
  36215. // get length
  36216. var length = dict.get('Length');
  36217. if (!isInt(length)) {
  36218. info('Bad ' + length + ' attribute in stream');
  36219. length = 0;
  36220. }
  36221. // skip over the stream data
  36222. stream.pos = pos + length;
  36223. lexer.nextChar();
  36224. // Shift '>>' and check whether the new object marks the end of the stream
  36225. if (this.tryShift() && isCmd(this.buf2, 'endstream')) {
  36226. this.shift();
  36227. } else
  36228. // 'stream'
  36229. {
  36230. // bad stream length, scanning for endstream
  36231. stream.pos = pos;
  36232. var SCAN_BLOCK_SIZE = 2048;
  36233. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  36234. var ENDSTREAM_SIGNATURE = [
  36235. 0x65,
  36236. 0x6E,
  36237. 0x64,
  36238. 0x73,
  36239. 0x74,
  36240. 0x72,
  36241. 0x65,
  36242. 0x61,
  36243. 0x6D
  36244. ];
  36245. var skipped = 0, found = false, i, j;
  36246. while (stream.pos < stream.end) {
  36247. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  36248. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  36249. if (scanLength <= 0) {
  36250. break;
  36251. }
  36252. found = false;
  36253. i = 0;
  36254. while (i < scanLength) {
  36255. j = 0;
  36256. while (j < ENDSTREAM_SIGNATURE_LENGTH && scanBytes[i + j] === ENDSTREAM_SIGNATURE[j]) {
  36257. j++;
  36258. }
  36259. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  36260. found = true;
  36261. break;
  36262. }
  36263. i++;
  36264. }
  36265. if (found) {
  36266. skipped += i;
  36267. stream.pos += i;
  36268. break;
  36269. }
  36270. skipped += scanLength;
  36271. stream.pos += scanLength;
  36272. }
  36273. if (!found) {
  36274. error('Missing endstream');
  36275. }
  36276. length = skipped;
  36277. lexer.nextChar();
  36278. this.shift();
  36279. this.shift();
  36280. }
  36281. this.shift();
  36282. // 'endstream'
  36283. stream = stream.makeSubStream(pos, length, dict);
  36284. if (cipherTransform) {
  36285. stream = cipherTransform.createStream(stream, length);
  36286. }
  36287. stream = this.filter(stream, dict, length);
  36288. stream.dict = dict;
  36289. return stream;
  36290. },
  36291. filter: function Parser_filter(stream, dict, length) {
  36292. var filter = dict.get('Filter', 'F');
  36293. var params = dict.get('DecodeParms', 'DP');
  36294. if (isName(filter)) {
  36295. return this.makeFilter(stream, filter.name, length, params);
  36296. }
  36297. var maybeLength = length;
  36298. if (isArray(filter)) {
  36299. var filterArray = filter;
  36300. var paramsArray = params;
  36301. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  36302. filter = filterArray[i];
  36303. if (!isName(filter)) {
  36304. error('Bad filter name: ' + filter);
  36305. }
  36306. params = null;
  36307. if (isArray(paramsArray) && i in paramsArray) {
  36308. params = paramsArray[i];
  36309. }
  36310. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  36311. // after the first stream the length variable is invalid
  36312. maybeLength = null;
  36313. }
  36314. }
  36315. return stream;
  36316. },
  36317. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  36318. // Since the 'Length' entry in the stream dictionary can be completely
  36319. // wrong, e.g. zero for non-empty streams, only skip parsing the stream
  36320. // when we can be absolutely certain that it actually is empty.
  36321. if (maybeLength === 0) {
  36322. warn('Empty "' + name + '" stream.');
  36323. return new NullStream(stream);
  36324. }
  36325. try {
  36326. if (params && this.xref) {
  36327. params = this.xref.fetchIfRef(params);
  36328. }
  36329. var xrefStreamStats = this.xref.stats.streamTypes;
  36330. if (name === 'FlateDecode' || name === 'Fl') {
  36331. xrefStreamStats[StreamType.FLATE] = true;
  36332. if (params) {
  36333. return new PredictorStream(new FlateStream(stream, maybeLength), maybeLength, params);
  36334. }
  36335. return new FlateStream(stream, maybeLength);
  36336. }
  36337. if (name === 'LZWDecode' || name === 'LZW') {
  36338. xrefStreamStats[StreamType.LZW] = true;
  36339. var earlyChange = 1;
  36340. if (params) {
  36341. if (params.has('EarlyChange')) {
  36342. earlyChange = params.get('EarlyChange');
  36343. }
  36344. return new PredictorStream(new LZWStream(stream, maybeLength, earlyChange), maybeLength, params);
  36345. }
  36346. return new LZWStream(stream, maybeLength, earlyChange);
  36347. }
  36348. if (name === 'DCTDecode' || name === 'DCT') {
  36349. xrefStreamStats[StreamType.DCT] = true;
  36350. return new JpegStream(stream, maybeLength, stream.dict);
  36351. }
  36352. if (name === 'JPXDecode' || name === 'JPX') {
  36353. xrefStreamStats[StreamType.JPX] = true;
  36354. return new JpxStream(stream, maybeLength, stream.dict);
  36355. }
  36356. if (name === 'ASCII85Decode' || name === 'A85') {
  36357. xrefStreamStats[StreamType.A85] = true;
  36358. return new Ascii85Stream(stream, maybeLength);
  36359. }
  36360. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  36361. xrefStreamStats[StreamType.AHX] = true;
  36362. return new AsciiHexStream(stream, maybeLength);
  36363. }
  36364. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  36365. xrefStreamStats[StreamType.CCF] = true;
  36366. return new CCITTFaxStream(stream, maybeLength, params);
  36367. }
  36368. if (name === 'RunLengthDecode' || name === 'RL') {
  36369. xrefStreamStats[StreamType.RL] = true;
  36370. return new RunLengthStream(stream, maybeLength);
  36371. }
  36372. if (name === 'JBIG2Decode') {
  36373. xrefStreamStats[StreamType.JBIG] = true;
  36374. return new Jbig2Stream(stream, maybeLength, stream.dict);
  36375. }
  36376. warn('filter "' + name + '" not supported yet');
  36377. return stream;
  36378. } catch (ex) {
  36379. if (ex instanceof MissingDataException) {
  36380. throw ex;
  36381. }
  36382. warn('Invalid stream: \"' + ex + '\"');
  36383. return new NullStream(stream);
  36384. }
  36385. }
  36386. };
  36387. return Parser;
  36388. }();
  36389. var Lexer = function LexerClosure() {
  36390. function Lexer(stream, knownCommands) {
  36391. this.stream = stream;
  36392. this.nextChar();
  36393. // While lexing, we build up many strings one char at a time. Using += for
  36394. // this can result in lots of garbage strings. It's better to build an
  36395. // array of single-char strings and then join() them together at the end.
  36396. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  36397. // purpose uses less memory than using a new array for each string.
  36398. this.strBuf = [];
  36399. // The PDFs might have "glued" commands with other commands, operands or
  36400. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  36401. // commands and their prefixes. The prefixes are built the following way:
  36402. // if there a command that is a prefix of the other valid command or
  36403. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  36404. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  36405. // other commands or literals as a prefix. The knowCommands is optional.
  36406. this.knownCommands = knownCommands;
  36407. }
  36408. // A '1' in this array means the character is white space. A '1' or
  36409. // '2' means the character ends a name or command.
  36410. var specialChars = [
  36411. 1,
  36412. 0,
  36413. 0,
  36414. 0,
  36415. 0,
  36416. 0,
  36417. 0,
  36418. 0,
  36419. 0,
  36420. 1,
  36421. 1,
  36422. 0,
  36423. 1,
  36424. 1,
  36425. 0,
  36426. 0,
  36427. // 0x
  36428. 0,
  36429. 0,
  36430. 0,
  36431. 0,
  36432. 0,
  36433. 0,
  36434. 0,
  36435. 0,
  36436. 0,
  36437. 0,
  36438. 0,
  36439. 0,
  36440. 0,
  36441. 0,
  36442. 0,
  36443. 0,
  36444. // 1x
  36445. 1,
  36446. 0,
  36447. 0,
  36448. 0,
  36449. 0,
  36450. 2,
  36451. 0,
  36452. 0,
  36453. 2,
  36454. 2,
  36455. 0,
  36456. 0,
  36457. 0,
  36458. 0,
  36459. 0,
  36460. 2,
  36461. // 2x
  36462. 0,
  36463. 0,
  36464. 0,
  36465. 0,
  36466. 0,
  36467. 0,
  36468. 0,
  36469. 0,
  36470. 0,
  36471. 0,
  36472. 0,
  36473. 0,
  36474. 2,
  36475. 0,
  36476. 2,
  36477. 0,
  36478. // 3x
  36479. 0,
  36480. 0,
  36481. 0,
  36482. 0,
  36483. 0,
  36484. 0,
  36485. 0,
  36486. 0,
  36487. 0,
  36488. 0,
  36489. 0,
  36490. 0,
  36491. 0,
  36492. 0,
  36493. 0,
  36494. 0,
  36495. // 4x
  36496. 0,
  36497. 0,
  36498. 0,
  36499. 0,
  36500. 0,
  36501. 0,
  36502. 0,
  36503. 0,
  36504. 0,
  36505. 0,
  36506. 0,
  36507. 2,
  36508. 0,
  36509. 2,
  36510. 0,
  36511. 0,
  36512. // 5x
  36513. 0,
  36514. 0,
  36515. 0,
  36516. 0,
  36517. 0,
  36518. 0,
  36519. 0,
  36520. 0,
  36521. 0,
  36522. 0,
  36523. 0,
  36524. 0,
  36525. 0,
  36526. 0,
  36527. 0,
  36528. 0,
  36529. // 6x
  36530. 0,
  36531. 0,
  36532. 0,
  36533. 0,
  36534. 0,
  36535. 0,
  36536. 0,
  36537. 0,
  36538. 0,
  36539. 0,
  36540. 0,
  36541. 2,
  36542. 0,
  36543. 2,
  36544. 0,
  36545. 0,
  36546. // 7x
  36547. 0,
  36548. 0,
  36549. 0,
  36550. 0,
  36551. 0,
  36552. 0,
  36553. 0,
  36554. 0,
  36555. 0,
  36556. 0,
  36557. 0,
  36558. 0,
  36559. 0,
  36560. 0,
  36561. 0,
  36562. 0,
  36563. // 8x
  36564. 0,
  36565. 0,
  36566. 0,
  36567. 0,
  36568. 0,
  36569. 0,
  36570. 0,
  36571. 0,
  36572. 0,
  36573. 0,
  36574. 0,
  36575. 0,
  36576. 0,
  36577. 0,
  36578. 0,
  36579. 0,
  36580. // 9x
  36581. 0,
  36582. 0,
  36583. 0,
  36584. 0,
  36585. 0,
  36586. 0,
  36587. 0,
  36588. 0,
  36589. 0,
  36590. 0,
  36591. 0,
  36592. 0,
  36593. 0,
  36594. 0,
  36595. 0,
  36596. 0,
  36597. // ax
  36598. 0,
  36599. 0,
  36600. 0,
  36601. 0,
  36602. 0,
  36603. 0,
  36604. 0,
  36605. 0,
  36606. 0,
  36607. 0,
  36608. 0,
  36609. 0,
  36610. 0,
  36611. 0,
  36612. 0,
  36613. 0,
  36614. // bx
  36615. 0,
  36616. 0,
  36617. 0,
  36618. 0,
  36619. 0,
  36620. 0,
  36621. 0,
  36622. 0,
  36623. 0,
  36624. 0,
  36625. 0,
  36626. 0,
  36627. 0,
  36628. 0,
  36629. 0,
  36630. 0,
  36631. // cx
  36632. 0,
  36633. 0,
  36634. 0,
  36635. 0,
  36636. 0,
  36637. 0,
  36638. 0,
  36639. 0,
  36640. 0,
  36641. 0,
  36642. 0,
  36643. 0,
  36644. 0,
  36645. 0,
  36646. 0,
  36647. 0,
  36648. // dx
  36649. 0,
  36650. 0,
  36651. 0,
  36652. 0,
  36653. 0,
  36654. 0,
  36655. 0,
  36656. 0,
  36657. 0,
  36658. 0,
  36659. 0,
  36660. 0,
  36661. 0,
  36662. 0,
  36663. 0,
  36664. 0,
  36665. // ex
  36666. 0,
  36667. 0,
  36668. 0,
  36669. 0,
  36670. 0,
  36671. 0,
  36672. 0,
  36673. 0,
  36674. 0,
  36675. 0,
  36676. 0,
  36677. 0,
  36678. 0,
  36679. 0,
  36680. 0,
  36681. 0
  36682. ];
  36683. // fx
  36684. function toHexDigit(ch) {
  36685. if (ch >= 0x30 && ch <= 0x39) {
  36686. // '0'-'9'
  36687. return ch & 0x0F;
  36688. }
  36689. if (ch >= 0x41 && ch <= 0x46 || ch >= 0x61 && ch <= 0x66) {
  36690. // 'A'-'F', 'a'-'f'
  36691. return (ch & 0x0F) + 9;
  36692. }
  36693. return -1;
  36694. }
  36695. Lexer.prototype = {
  36696. nextChar: function Lexer_nextChar() {
  36697. return this.currentChar = this.stream.getByte();
  36698. },
  36699. peekChar: function Lexer_peekChar() {
  36700. return this.stream.peekByte();
  36701. },
  36702. getNumber: function Lexer_getNumber() {
  36703. var ch = this.currentChar;
  36704. var eNotation = false;
  36705. var divideBy = 0;
  36706. // different from 0 if it's a floating point value
  36707. var sign = 1;
  36708. if (ch === 0x2D) {
  36709. // '-'
  36710. sign = -1;
  36711. ch = this.nextChar();
  36712. if (ch === 0x2D) {
  36713. // '-'
  36714. // Ignore double negative (this is consistent with Adobe Reader).
  36715. ch = this.nextChar();
  36716. }
  36717. } else if (ch === 0x2B) {
  36718. // '+'
  36719. ch = this.nextChar();
  36720. }
  36721. if (ch === 0x2E) {
  36722. // '.'
  36723. divideBy = 10;
  36724. ch = this.nextChar();
  36725. }
  36726. if (ch < 0x30 || ch > 0x39) {
  36727. // '0' - '9'
  36728. error('Invalid number: ' + String.fromCharCode(ch));
  36729. return 0;
  36730. }
  36731. var baseValue = ch - 0x30;
  36732. // '0'
  36733. var powerValue = 0;
  36734. var powerValueSign = 1;
  36735. while ((ch = this.nextChar()) >= 0) {
  36736. if (0x30 <= ch && ch <= 0x39) {
  36737. // '0' - '9'
  36738. var currentDigit = ch - 0x30;
  36739. // '0'
  36740. if (eNotation) {
  36741. // We are after an 'e' or 'E'
  36742. powerValue = powerValue * 10 + currentDigit;
  36743. } else {
  36744. if (divideBy !== 0) {
  36745. // We are after a point
  36746. divideBy *= 10;
  36747. }
  36748. baseValue = baseValue * 10 + currentDigit;
  36749. }
  36750. } else if (ch === 0x2E) {
  36751. // '.'
  36752. if (divideBy === 0) {
  36753. divideBy = 1;
  36754. } else {
  36755. // A number can have only one '.'
  36756. break;
  36757. }
  36758. } else if (ch === 0x2D) {
  36759. // '-'
  36760. // ignore minus signs in the middle of numbers to match
  36761. // Adobe's behavior
  36762. warn('Badly formatted number');
  36763. } else if (ch === 0x45 || ch === 0x65) {
  36764. // 'E', 'e'
  36765. // 'E' can be either a scientific notation or the beginning of a new
  36766. // operator
  36767. ch = this.peekChar();
  36768. if (ch === 0x2B || ch === 0x2D) {
  36769. // '+', '-'
  36770. powerValueSign = ch === 0x2D ? -1 : 1;
  36771. this.nextChar();
  36772. } else // Consume the sign character
  36773. if (ch < 0x30 || ch > 0x39) {
  36774. // '0' - '9'
  36775. // The 'E' must be the beginning of a new operator
  36776. break;
  36777. }
  36778. eNotation = true;
  36779. } else {
  36780. // the last character doesn't belong to us
  36781. break;
  36782. }
  36783. }
  36784. if (divideBy !== 0) {
  36785. baseValue /= divideBy;
  36786. }
  36787. if (eNotation) {
  36788. baseValue *= Math.pow(10, powerValueSign * powerValue);
  36789. }
  36790. return sign * baseValue;
  36791. },
  36792. getString: function Lexer_getString() {
  36793. var numParen = 1;
  36794. var done = false;
  36795. var strBuf = this.strBuf;
  36796. strBuf.length = 0;
  36797. var ch = this.nextChar();
  36798. while (true) {
  36799. var charBuffered = false;
  36800. switch (ch | 0) {
  36801. case -1:
  36802. warn('Unterminated string');
  36803. done = true;
  36804. break;
  36805. case 0x28:
  36806. // '('
  36807. ++numParen;
  36808. strBuf.push('(');
  36809. break;
  36810. case 0x29:
  36811. // ')'
  36812. if (--numParen === 0) {
  36813. this.nextChar();
  36814. // consume strings ')'
  36815. done = true;
  36816. } else {
  36817. strBuf.push(')');
  36818. }
  36819. break;
  36820. case 0x5C:
  36821. // '\\'
  36822. ch = this.nextChar();
  36823. switch (ch) {
  36824. case -1:
  36825. warn('Unterminated string');
  36826. done = true;
  36827. break;
  36828. case 0x6E:
  36829. // 'n'
  36830. strBuf.push('\n');
  36831. break;
  36832. case 0x72:
  36833. // 'r'
  36834. strBuf.push('\r');
  36835. break;
  36836. case 0x74:
  36837. // 't'
  36838. strBuf.push('\t');
  36839. break;
  36840. case 0x62:
  36841. // 'b'
  36842. strBuf.push('\b');
  36843. break;
  36844. case 0x66:
  36845. // 'f'
  36846. strBuf.push('\f');
  36847. break;
  36848. case 0x5C:
  36849. // '\'
  36850. case 0x28:
  36851. // '('
  36852. case 0x29:
  36853. // ')'
  36854. strBuf.push(String.fromCharCode(ch));
  36855. break;
  36856. case 0x30:
  36857. case 0x31:
  36858. case 0x32:
  36859. case 0x33:
  36860. // '0'-'3'
  36861. case 0x34:
  36862. case 0x35:
  36863. case 0x36:
  36864. case 0x37:
  36865. // '4'-'7'
  36866. var x = ch & 0x0F;
  36867. ch = this.nextChar();
  36868. charBuffered = true;
  36869. if (ch >= 0x30 && ch <= 0x37) {
  36870. // '0'-'7'
  36871. x = (x << 3) + (ch & 0x0F);
  36872. ch = this.nextChar();
  36873. if (ch >= 0x30 && ch <= 0x37) {
  36874. // '0'-'7'
  36875. charBuffered = false;
  36876. x = (x << 3) + (ch & 0x0F);
  36877. }
  36878. }
  36879. strBuf.push(String.fromCharCode(x));
  36880. break;
  36881. case 0x0D:
  36882. // CR
  36883. if (this.peekChar() === 0x0A) {
  36884. // LF
  36885. this.nextChar();
  36886. }
  36887. break;
  36888. case 0x0A:
  36889. // LF
  36890. break;
  36891. default:
  36892. strBuf.push(String.fromCharCode(ch));
  36893. break;
  36894. }
  36895. break;
  36896. default:
  36897. strBuf.push(String.fromCharCode(ch));
  36898. break;
  36899. }
  36900. if (done) {
  36901. break;
  36902. }
  36903. if (!charBuffered) {
  36904. ch = this.nextChar();
  36905. }
  36906. }
  36907. return strBuf.join('');
  36908. },
  36909. getName: function Lexer_getName() {
  36910. var ch, previousCh;
  36911. var strBuf = this.strBuf;
  36912. strBuf.length = 0;
  36913. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  36914. if (ch === 0x23) {
  36915. // '#'
  36916. ch = this.nextChar();
  36917. if (specialChars[ch]) {
  36918. warn('Lexer_getName: ' + 'NUMBER SIGN (#) should be followed by a hexadecimal number.');
  36919. strBuf.push('#');
  36920. break;
  36921. }
  36922. var x = toHexDigit(ch);
  36923. if (x !== -1) {
  36924. previousCh = ch;
  36925. ch = this.nextChar();
  36926. var x2 = toHexDigit(ch);
  36927. if (x2 === -1) {
  36928. warn('Lexer_getName: Illegal digit (' + String.fromCharCode(ch) + ') in hexadecimal number.');
  36929. strBuf.push('#', String.fromCharCode(previousCh));
  36930. if (specialChars[ch]) {
  36931. break;
  36932. }
  36933. strBuf.push(String.fromCharCode(ch));
  36934. continue;
  36935. }
  36936. strBuf.push(String.fromCharCode(x << 4 | x2));
  36937. } else {
  36938. strBuf.push('#', String.fromCharCode(ch));
  36939. }
  36940. } else {
  36941. strBuf.push(String.fromCharCode(ch));
  36942. }
  36943. }
  36944. if (strBuf.length > 127) {
  36945. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  36946. }
  36947. return Name.get(strBuf.join(''));
  36948. },
  36949. getHexString: function Lexer_getHexString() {
  36950. var strBuf = this.strBuf;
  36951. strBuf.length = 0;
  36952. var ch = this.currentChar;
  36953. var isFirstHex = true;
  36954. var firstDigit;
  36955. var secondDigit;
  36956. while (true) {
  36957. if (ch < 0) {
  36958. warn('Unterminated hex string');
  36959. break;
  36960. } else if (ch === 0x3E) {
  36961. // '>'
  36962. this.nextChar();
  36963. break;
  36964. } else if (specialChars[ch] === 1) {
  36965. ch = this.nextChar();
  36966. continue;
  36967. } else {
  36968. if (isFirstHex) {
  36969. firstDigit = toHexDigit(ch);
  36970. if (firstDigit === -1) {
  36971. warn('Ignoring invalid character "' + ch + '" in hex string');
  36972. ch = this.nextChar();
  36973. continue;
  36974. }
  36975. } else {
  36976. secondDigit = toHexDigit(ch);
  36977. if (secondDigit === -1) {
  36978. warn('Ignoring invalid character "' + ch + '" in hex string');
  36979. ch = this.nextChar();
  36980. continue;
  36981. }
  36982. strBuf.push(String.fromCharCode(firstDigit << 4 | secondDigit));
  36983. }
  36984. isFirstHex = !isFirstHex;
  36985. ch = this.nextChar();
  36986. }
  36987. }
  36988. return strBuf.join('');
  36989. },
  36990. getObj: function Lexer_getObj() {
  36991. // skip whitespace and comments
  36992. var comment = false;
  36993. var ch = this.currentChar;
  36994. while (true) {
  36995. if (ch < 0) {
  36996. return EOF;
  36997. }
  36998. if (comment) {
  36999. if (ch === 0x0A || ch === 0x0D) {
  37000. // LF, CR
  37001. comment = false;
  37002. }
  37003. } else if (ch === 0x25) {
  37004. // '%'
  37005. comment = true;
  37006. } else if (specialChars[ch] !== 1) {
  37007. break;
  37008. }
  37009. ch = this.nextChar();
  37010. }
  37011. // start reading token
  37012. switch (ch | 0) {
  37013. case 0x30:
  37014. case 0x31:
  37015. case 0x32:
  37016. case 0x33:
  37017. case 0x34:
  37018. // '0'-'4'
  37019. case 0x35:
  37020. case 0x36:
  37021. case 0x37:
  37022. case 0x38:
  37023. case 0x39:
  37024. // '5'-'9'
  37025. case 0x2B:
  37026. case 0x2D:
  37027. case 0x2E:
  37028. // '+', '-', '.'
  37029. return this.getNumber();
  37030. case 0x28:
  37031. // '('
  37032. return this.getString();
  37033. case 0x2F:
  37034. // '/'
  37035. return this.getName();
  37036. // array punctuation
  37037. case 0x5B:
  37038. // '['
  37039. this.nextChar();
  37040. return Cmd.get('[');
  37041. case 0x5D:
  37042. // ']'
  37043. this.nextChar();
  37044. return Cmd.get(']');
  37045. // hex string or dict punctuation
  37046. case 0x3C:
  37047. // '<'
  37048. ch = this.nextChar();
  37049. if (ch === 0x3C) {
  37050. // dict punctuation
  37051. this.nextChar();
  37052. return Cmd.get('<<');
  37053. }
  37054. return this.getHexString();
  37055. // dict punctuation
  37056. case 0x3E:
  37057. // '>'
  37058. ch = this.nextChar();
  37059. if (ch === 0x3E) {
  37060. this.nextChar();
  37061. return Cmd.get('>>');
  37062. }
  37063. return Cmd.get('>');
  37064. case 0x7B:
  37065. // '{'
  37066. this.nextChar();
  37067. return Cmd.get('{');
  37068. case 0x7D:
  37069. // '}'
  37070. this.nextChar();
  37071. return Cmd.get('}');
  37072. case 0x29:
  37073. // ')'
  37074. error('Illegal character: ' + ch);
  37075. break;
  37076. }
  37077. // command
  37078. var str = String.fromCharCode(ch);
  37079. var knownCommands = this.knownCommands;
  37080. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  37081. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  37082. // stop if known command is found and next character does not make
  37083. // the str a command
  37084. var possibleCommand = str + String.fromCharCode(ch);
  37085. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  37086. break;
  37087. }
  37088. if (str.length === 128) {
  37089. error('Command token too long: ' + str.length);
  37090. }
  37091. str = possibleCommand;
  37092. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  37093. }
  37094. if (str === 'true') {
  37095. return true;
  37096. }
  37097. if (str === 'false') {
  37098. return false;
  37099. }
  37100. if (str === 'null') {
  37101. return null;
  37102. }
  37103. return Cmd.get(str);
  37104. },
  37105. skipToNextLine: function Lexer_skipToNextLine() {
  37106. var ch = this.currentChar;
  37107. while (ch >= 0) {
  37108. if (ch === 0x0D) {
  37109. // CR
  37110. ch = this.nextChar();
  37111. if (ch === 0x0A) {
  37112. // LF
  37113. this.nextChar();
  37114. }
  37115. break;
  37116. } else if (ch === 0x0A) {
  37117. // LF
  37118. this.nextChar();
  37119. break;
  37120. }
  37121. ch = this.nextChar();
  37122. }
  37123. }
  37124. };
  37125. return Lexer;
  37126. }();
  37127. var Linearization = {
  37128. create: function LinearizationCreate(stream) {
  37129. function getInt(name, allowZeroValue) {
  37130. var obj = linDict.get(name);
  37131. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  37132. return obj;
  37133. }
  37134. throw new Error('The "' + name + '" parameter in the linearization ' + 'dictionary is invalid.');
  37135. }
  37136. function getHints() {
  37137. var hints = linDict.get('H'), hintsLength, item;
  37138. if (isArray(hints) && ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  37139. for (var index = 0; index < hintsLength; index++) {
  37140. if (!(isInt(item = hints[index]) && item > 0)) {
  37141. throw new Error('Hint (' + index + ') in the linearization dictionary is invalid.');
  37142. }
  37143. }
  37144. return hints;
  37145. }
  37146. throw new Error('Hint array in the linearization dictionary is invalid.');
  37147. }
  37148. var parser = new Parser(new Lexer(stream), false, null);
  37149. var obj1 = parser.getObj();
  37150. var obj2 = parser.getObj();
  37151. var obj3 = parser.getObj();
  37152. var linDict = parser.getObj();
  37153. var obj, length;
  37154. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) && isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  37155. return null;
  37156. } else // No valid linearization dictionary found.
  37157. if ((length = getInt('L')) !== stream.length) {
  37158. throw new Error('The "L" parameter in the linearization dictionary ' + 'does not equal the stream length.');
  37159. }
  37160. return {
  37161. length: length,
  37162. hints: getHints(),
  37163. objectNumberFirst: getInt('O'),
  37164. endFirst: getInt('E'),
  37165. numPages: getInt('N'),
  37166. mainXRefEntriesOffset: getInt('T'),
  37167. pageFirst: linDict.has('P') ? getInt('P', true) : 0
  37168. };
  37169. }
  37170. };
  37171. exports.EOF = EOF;
  37172. exports.Lexer = Lexer;
  37173. exports.Linearization = Linearization;
  37174. exports.Parser = Parser;
  37175. exports.isEOF = isEOF;
  37176. }));
  37177. (function (root, factory) {
  37178. factory(root.pdfjsCoreType1Parser = {}, root.pdfjsSharedUtil, root.pdfjsCoreStream, root.pdfjsCoreEncodings);
  37179. }(this, function (exports, sharedUtil, coreStream, coreEncodings) {
  37180. var warn = sharedUtil.warn;
  37181. var isSpace = sharedUtil.isSpace;
  37182. var Stream = coreStream.Stream;
  37183. var getEncoding = coreEncodings.getEncoding;
  37184. // Hinting is currently disabled due to unknown problems on windows
  37185. // in tracemonkey and various other pdfs with type1 fonts.
  37186. var HINTING_ENABLED = false;
  37187. /*
  37188. * CharStrings are encoded following the the CharString Encoding sequence
  37189. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  37190. * The value in a byte indicates a command, a number, or subsequent bytes
  37191. * that are to be interpreted in a special way.
  37192. *
  37193. * CharString Number Encoding:
  37194. * A CharString byte containing the values from 32 through 255 inclusive
  37195. * indicate an integer. These values are decoded in four ranges.
  37196. *
  37197. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  37198. * indicate the integer v - 139. Thus, the integer values from -107 through
  37199. * 107 inclusive may be encoded in single byte.
  37200. *
  37201. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  37202. * indicates an integer involving the next byte, w, according to the formula:
  37203. * [(v - 247) x 256] + w + 108
  37204. *
  37205. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  37206. * indicates an integer involving the next byte, w, according to the formula:
  37207. * -[(v - 251) * 256] - w - 108
  37208. *
  37209. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  37210. * are a two complement signed integer. The first of these bytes contains the
  37211. * highest order bits, the second byte contains the next higher order bits
  37212. * and the fourth byte contain the lowest order bits.
  37213. *
  37214. *
  37215. * CharString Command Encoding:
  37216. * CharStrings commands are encoded in 1 or 2 bytes.
  37217. *
  37218. * Single byte commands are encoded in 1 byte that contains a value between
  37219. * 0 and 31 inclusive.
  37220. * If a command byte contains the value 12, then the value in the next byte
  37221. * indicates a command. This "escape" mechanism allows many extra commands
  37222. * to be encoded and this encoding technique helps to minimize the length of
  37223. * the charStrings.
  37224. */
  37225. var Type1CharString = function Type1CharStringClosure() {
  37226. var COMMAND_MAP = {
  37227. 'hstem': [1],
  37228. 'vstem': [3],
  37229. 'vmoveto': [4],
  37230. 'rlineto': [5],
  37231. 'hlineto': [6],
  37232. 'vlineto': [7],
  37233. 'rrcurveto': [8],
  37234. 'callsubr': [10],
  37235. 'flex': [
  37236. 12,
  37237. 35
  37238. ],
  37239. 'drop': [
  37240. 12,
  37241. 18
  37242. ],
  37243. 'endchar': [14],
  37244. 'rmoveto': [21],
  37245. 'hmoveto': [22],
  37246. 'vhcurveto': [30],
  37247. 'hvcurveto': [31]
  37248. };
  37249. function Type1CharString() {
  37250. this.width = 0;
  37251. this.lsb = 0;
  37252. this.flexing = false;
  37253. this.output = [];
  37254. this.stack = [];
  37255. }
  37256. Type1CharString.prototype = {
  37257. convert: function Type1CharString_convert(encoded, subrs, seacAnalysisEnabled) {
  37258. var count = encoded.length;
  37259. var error = false;
  37260. var wx, sbx, subrNumber;
  37261. for (var i = 0; i < count; i++) {
  37262. var value = encoded[i];
  37263. if (value < 32) {
  37264. if (value === 12) {
  37265. value = (value << 8) + encoded[++i];
  37266. }
  37267. switch (value) {
  37268. case 1:
  37269. // hstem
  37270. if (!HINTING_ENABLED) {
  37271. this.stack = [];
  37272. break;
  37273. }
  37274. error = this.executeCommand(2, COMMAND_MAP.hstem);
  37275. break;
  37276. case 3:
  37277. // vstem
  37278. if (!HINTING_ENABLED) {
  37279. this.stack = [];
  37280. break;
  37281. }
  37282. error = this.executeCommand(2, COMMAND_MAP.vstem);
  37283. break;
  37284. case 4:
  37285. // vmoveto
  37286. if (this.flexing) {
  37287. if (this.stack.length < 1) {
  37288. error = true;
  37289. break;
  37290. }
  37291. // Add the dx for flex and but also swap the values so they are
  37292. // the right order.
  37293. var dy = this.stack.pop();
  37294. this.stack.push(0, dy);
  37295. break;
  37296. }
  37297. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  37298. break;
  37299. case 5:
  37300. // rlineto
  37301. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  37302. break;
  37303. case 6:
  37304. // hlineto
  37305. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  37306. break;
  37307. case 7:
  37308. // vlineto
  37309. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  37310. break;
  37311. case 8:
  37312. // rrcurveto
  37313. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  37314. break;
  37315. case 9:
  37316. // closepath
  37317. // closepath is a Type1 command that does not take argument and is
  37318. // useless in Type2 and it can simply be ignored.
  37319. this.stack = [];
  37320. break;
  37321. case 10:
  37322. // callsubr
  37323. if (this.stack.length < 1) {
  37324. error = true;
  37325. break;
  37326. }
  37327. subrNumber = this.stack.pop();
  37328. error = this.convert(subrs[subrNumber], subrs, seacAnalysisEnabled);
  37329. break;
  37330. case 11:
  37331. // return
  37332. return error;
  37333. case 13:
  37334. // hsbw
  37335. if (this.stack.length < 2) {
  37336. error = true;
  37337. break;
  37338. }
  37339. // To convert to type2 we have to move the width value to the
  37340. // first part of the charstring and then use hmoveto with lsb.
  37341. wx = this.stack.pop();
  37342. sbx = this.stack.pop();
  37343. this.lsb = sbx;
  37344. this.width = wx;
  37345. this.stack.push(wx, sbx);
  37346. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  37347. break;
  37348. case 14:
  37349. // endchar
  37350. this.output.push(COMMAND_MAP.endchar[0]);
  37351. break;
  37352. case 21:
  37353. // rmoveto
  37354. if (this.flexing) {
  37355. break;
  37356. }
  37357. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  37358. break;
  37359. case 22:
  37360. // hmoveto
  37361. if (this.flexing) {
  37362. // Add the dy for flex.
  37363. this.stack.push(0);
  37364. break;
  37365. }
  37366. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  37367. break;
  37368. case 30:
  37369. // vhcurveto
  37370. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  37371. break;
  37372. case 31:
  37373. // hvcurveto
  37374. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  37375. break;
  37376. case (12 << 8) + 0:
  37377. // dotsection
  37378. // dotsection is a Type1 command to specify some hinting feature
  37379. // for dots that do not take a parameter and it can safely be
  37380. // ignored for Type2.
  37381. this.stack = [];
  37382. break;
  37383. case (12 << 8) + 1:
  37384. // vstem3
  37385. if (!HINTING_ENABLED) {
  37386. this.stack = [];
  37387. break;
  37388. }
  37389. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  37390. // multiple parameters, so instead of returning [vh]stem3 take a
  37391. // shortcut and return [vhstem] instead.
  37392. error = this.executeCommand(2, COMMAND_MAP.vstem);
  37393. break;
  37394. case (12 << 8) + 2:
  37395. // hstem3
  37396. if (!HINTING_ENABLED) {
  37397. this.stack = [];
  37398. break;
  37399. }
  37400. // See vstem3.
  37401. error = this.executeCommand(2, COMMAND_MAP.hstem);
  37402. break;
  37403. case (12 << 8) + 6:
  37404. // seac
  37405. // seac is like type 2's special endchar but it doesn't use the
  37406. // first argument asb, so remove it.
  37407. if (seacAnalysisEnabled) {
  37408. this.seac = this.stack.splice(-4, 4);
  37409. error = this.executeCommand(0, COMMAND_MAP.endchar);
  37410. } else {
  37411. error = this.executeCommand(4, COMMAND_MAP.endchar);
  37412. }
  37413. break;
  37414. case (12 << 8) + 7:
  37415. // sbw
  37416. if (this.stack.length < 4) {
  37417. error = true;
  37418. break;
  37419. }
  37420. // To convert to type2 we have to move the width value to the
  37421. // first part of the charstring and then use rmoveto with
  37422. // (dx, dy). The height argument will not be used for vmtx and
  37423. // vhea tables reconstruction -- ignoring it.
  37424. var wy = this.stack.pop();
  37425. wx = this.stack.pop();
  37426. var sby = this.stack.pop();
  37427. sbx = this.stack.pop();
  37428. this.lsb = sbx;
  37429. this.width = wx;
  37430. this.stack.push(wx, sbx, sby);
  37431. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  37432. break;
  37433. case (12 << 8) + 12:
  37434. // div
  37435. if (this.stack.length < 2) {
  37436. error = true;
  37437. break;
  37438. }
  37439. var num2 = this.stack.pop();
  37440. var num1 = this.stack.pop();
  37441. this.stack.push(num1 / num2);
  37442. break;
  37443. case (12 << 8) + 16:
  37444. // callothersubr
  37445. if (this.stack.length < 2) {
  37446. error = true;
  37447. break;
  37448. }
  37449. subrNumber = this.stack.pop();
  37450. var numArgs = this.stack.pop();
  37451. if (subrNumber === 0 && numArgs === 3) {
  37452. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  37453. this.stack.push(flexArgs[2] + flexArgs[0], // bcp1x + rpx
  37454. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  37455. flexArgs[4], // bcp2x
  37456. flexArgs[5], // bcp2y
  37457. flexArgs[6], // p2x
  37458. flexArgs[7], // p2y
  37459. flexArgs[8], // bcp3x
  37460. flexArgs[9], // bcp3y
  37461. flexArgs[10], // bcp4x
  37462. flexArgs[11], // bcp4y
  37463. flexArgs[12], // p3x
  37464. flexArgs[13], // p3y
  37465. flexArgs[14]);
  37466. // flexDepth
  37467. // 15 = finalx unused by flex
  37468. // 16 = finaly unused by flex
  37469. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  37470. this.flexing = false;
  37471. this.stack.push(flexArgs[15], flexArgs[16]);
  37472. } else if (subrNumber === 1 && numArgs === 0) {
  37473. this.flexing = true;
  37474. }
  37475. break;
  37476. case (12 << 8) + 17:
  37477. // pop
  37478. // Ignore this since it is only used with othersubr.
  37479. break;
  37480. case (12 << 8) + 33:
  37481. // setcurrentpoint
  37482. // Ignore for now.
  37483. this.stack = [];
  37484. break;
  37485. default:
  37486. warn('Unknown type 1 charstring command of "' + value + '"');
  37487. break;
  37488. }
  37489. if (error) {
  37490. break;
  37491. }
  37492. continue;
  37493. } else if (value <= 246) {
  37494. value = value - 139;
  37495. } else if (value <= 250) {
  37496. value = (value - 247) * 256 + encoded[++i] + 108;
  37497. } else if (value <= 254) {
  37498. value = -((value - 251) * 256) - encoded[++i] - 108;
  37499. } else {
  37500. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 | (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  37501. }
  37502. this.stack.push(value);
  37503. }
  37504. return error;
  37505. },
  37506. executeCommand: function (howManyArgs, command, keepStack) {
  37507. var stackLength = this.stack.length;
  37508. if (howManyArgs > stackLength) {
  37509. return true;
  37510. }
  37511. var start = stackLength - howManyArgs;
  37512. for (var i = start; i < stackLength; i++) {
  37513. var value = this.stack[i];
  37514. if (value === (value | 0)) {
  37515. // int
  37516. this.output.push(28, value >> 8 & 0xff, value & 0xff);
  37517. } else {
  37518. // fixed point
  37519. value = 65536 * value | 0;
  37520. this.output.push(255, value >> 24 & 0xFF, value >> 16 & 0xFF, value >> 8 & 0xFF, value & 0xFF);
  37521. }
  37522. }
  37523. this.output.push.apply(this.output, command);
  37524. if (keepStack) {
  37525. this.stack.splice(start, howManyArgs);
  37526. } else {
  37527. this.stack.length = 0;
  37528. }
  37529. return false;
  37530. }
  37531. };
  37532. return Type1CharString;
  37533. }();
  37534. /*
  37535. * Type1Parser encapsulate the needed code for parsing a Type1 font
  37536. * program. Some of its logic depends on the Type2 charstrings
  37537. * structure.
  37538. * Note: this doesn't really parse the font since that would require evaluation
  37539. * of PostScript, but it is possible in most cases to extract what we need
  37540. * without a full parse.
  37541. */
  37542. var Type1Parser = function Type1ParserClosure() {
  37543. /*
  37544. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  37545. * of Plaintext Bytes. The function took a key as a parameter which can be
  37546. * for decrypting the eexec block of for decoding charStrings.
  37547. */
  37548. var EEXEC_ENCRYPT_KEY = 55665;
  37549. var CHAR_STRS_ENCRYPT_KEY = 4330;
  37550. function isHexDigit(code) {
  37551. return code >= 48 && code <= 57 || // '0'-'9'
  37552. code >= 65 && code <= 70 || // 'A'-'F'
  37553. code >= 97 && code <= 102;
  37554. }
  37555. // 'a'-'f'
  37556. function decrypt(data, key, discardNumber) {
  37557. if (discardNumber >= data.length) {
  37558. return new Uint8Array(0);
  37559. }
  37560. var r = key | 0, c1 = 52845, c2 = 22719, i, j;
  37561. for (i = 0; i < discardNumber; i++) {
  37562. r = (data[i] + r) * c1 + c2 & (1 << 16) - 1;
  37563. }
  37564. var count = data.length - discardNumber;
  37565. var decrypted = new Uint8Array(count);
  37566. for (i = discardNumber, j = 0; j < count; i++, j++) {
  37567. var value = data[i];
  37568. decrypted[j] = value ^ r >> 8;
  37569. r = (value + r) * c1 + c2 & (1 << 16) - 1;
  37570. }
  37571. return decrypted;
  37572. }
  37573. function decryptAscii(data, key, discardNumber) {
  37574. var r = key | 0, c1 = 52845, c2 = 22719;
  37575. var count = data.length, maybeLength = count >>> 1;
  37576. var decrypted = new Uint8Array(maybeLength);
  37577. var i, j;
  37578. for (i = 0, j = 0; i < count; i++) {
  37579. var digit1 = data[i];
  37580. if (!isHexDigit(digit1)) {
  37581. continue;
  37582. }
  37583. i++;
  37584. var digit2;
  37585. while (i < count && !isHexDigit(digit2 = data[i])) {
  37586. i++;
  37587. }
  37588. if (i < count) {
  37589. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  37590. decrypted[j++] = value ^ r >> 8;
  37591. r = (value + r) * c1 + c2 & (1 << 16) - 1;
  37592. }
  37593. }
  37594. return Array.prototype.slice.call(decrypted, discardNumber, j);
  37595. }
  37596. function isSpecial(c) {
  37597. return c === 0x2F || // '/'
  37598. c === 0x5B || c === 0x5D || // '[', ']'
  37599. c === 0x7B || c === 0x7D || // '{', '}'
  37600. c === 0x28 || c === 0x29;
  37601. }
  37602. // '(', ')'
  37603. function Type1Parser(stream, encrypted, seacAnalysisEnabled) {
  37604. if (encrypted) {
  37605. var data = stream.getBytes();
  37606. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) && isHexDigit(data[2]) && isHexDigit(data[3]));
  37607. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) : decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  37608. }
  37609. this.seacAnalysisEnabled = !!seacAnalysisEnabled;
  37610. this.stream = stream;
  37611. this.nextChar();
  37612. }
  37613. Type1Parser.prototype = {
  37614. readNumberArray: function Type1Parser_readNumberArray() {
  37615. this.getToken();
  37616. // read '[' or '{' (arrays can start with either)
  37617. var array = [];
  37618. while (true) {
  37619. var token = this.getToken();
  37620. if (token === null || token === ']' || token === '}') {
  37621. break;
  37622. }
  37623. array.push(parseFloat(token || 0));
  37624. }
  37625. return array;
  37626. },
  37627. readNumber: function Type1Parser_readNumber() {
  37628. var token = this.getToken();
  37629. return parseFloat(token || 0);
  37630. },
  37631. readInt: function Type1Parser_readInt() {
  37632. // Use '| 0' to prevent setting a double into length such as the double
  37633. // does not flow into the loop variable.
  37634. var token = this.getToken();
  37635. return parseInt(token || 0, 10) | 0;
  37636. },
  37637. readBoolean: function Type1Parser_readBoolean() {
  37638. var token = this.getToken();
  37639. // Use 1 and 0 since that's what type2 charstrings use.
  37640. return token === 'true' ? 1 : 0;
  37641. },
  37642. nextChar: function Type1_nextChar() {
  37643. return this.currentChar = this.stream.getByte();
  37644. },
  37645. getToken: function Type1Parser_getToken() {
  37646. // Eat whitespace and comments.
  37647. var comment = false;
  37648. var ch = this.currentChar;
  37649. while (true) {
  37650. if (ch === -1) {
  37651. return null;
  37652. }
  37653. if (comment) {
  37654. if (ch === 0x0A || ch === 0x0D) {
  37655. comment = false;
  37656. }
  37657. } else if (ch === 0x25) {
  37658. // '%'
  37659. comment = true;
  37660. } else if (!isSpace(ch)) {
  37661. break;
  37662. }
  37663. ch = this.nextChar();
  37664. }
  37665. if (isSpecial(ch)) {
  37666. this.nextChar();
  37667. return String.fromCharCode(ch);
  37668. }
  37669. var token = '';
  37670. do {
  37671. token += String.fromCharCode(ch);
  37672. ch = this.nextChar();
  37673. } while (ch >= 0 && !isSpace(ch) && !isSpecial(ch));
  37674. return token;
  37675. },
  37676. /*
  37677. * Returns an object containing a Subrs array and a CharStrings
  37678. * array extracted from and eexec encrypted block of data
  37679. */
  37680. extractFontProgram: function Type1Parser_extractFontProgram() {
  37681. var stream = this.stream;
  37682. var subrs = [], charstrings = [];
  37683. var privateData = Object.create(null);
  37684. privateData['lenIV'] = 4;
  37685. var program = {
  37686. subrs: [],
  37687. charstrings: [],
  37688. properties: { 'privateData': privateData }
  37689. };
  37690. var token, length, data, lenIV, encoded;
  37691. while ((token = this.getToken()) !== null) {
  37692. if (token !== '/') {
  37693. continue;
  37694. }
  37695. token = this.getToken();
  37696. switch (token) {
  37697. case 'CharStrings':
  37698. // The number immediately following CharStrings must be greater or
  37699. // equal to the number of CharStrings.
  37700. this.getToken();
  37701. this.getToken();
  37702. // read in 'dict'
  37703. this.getToken();
  37704. // read in 'dup'
  37705. this.getToken();
  37706. // read in 'begin'
  37707. while (true) {
  37708. token = this.getToken();
  37709. if (token === null || token === 'end') {
  37710. break;
  37711. }
  37712. if (token !== '/') {
  37713. continue;
  37714. }
  37715. var glyph = this.getToken();
  37716. length = this.readInt();
  37717. this.getToken();
  37718. // read in 'RD' or '-|'
  37719. data = stream.makeSubStream(stream.pos, length);
  37720. lenIV = program.properties.privateData['lenIV'];
  37721. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  37722. // Skip past the required space and binary data.
  37723. stream.skip(length);
  37724. this.nextChar();
  37725. token = this.getToken();
  37726. // read in 'ND' or '|-'
  37727. if (token === 'noaccess') {
  37728. this.getToken();
  37729. }
  37730. // read in 'def'
  37731. charstrings.push({
  37732. glyph: glyph,
  37733. encoded: encoded
  37734. });
  37735. }
  37736. break;
  37737. case 'Subrs':
  37738. var num = this.readInt();
  37739. this.getToken();
  37740. // read in 'array'
  37741. while ((token = this.getToken()) === 'dup') {
  37742. var index = this.readInt();
  37743. length = this.readInt();
  37744. this.getToken();
  37745. // read in 'RD' or '-|'
  37746. data = stream.makeSubStream(stream.pos, length);
  37747. lenIV = program.properties.privateData['lenIV'];
  37748. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  37749. // Skip past the required space and binary data.
  37750. stream.skip(length);
  37751. this.nextChar();
  37752. token = this.getToken();
  37753. // read in 'NP' or '|'
  37754. if (token === 'noaccess') {
  37755. this.getToken();
  37756. }
  37757. // read in 'put'
  37758. subrs[index] = encoded;
  37759. }
  37760. break;
  37761. case 'BlueValues':
  37762. case 'OtherBlues':
  37763. case 'FamilyBlues':
  37764. case 'FamilyOtherBlues':
  37765. var blueArray = this.readNumberArray();
  37766. // *Blue* values may contain invalid data: disables reading of
  37767. // those values when hinting is disabled.
  37768. if (blueArray.length > 0 && blueArray.length % 2 === 0 && HINTING_ENABLED) {
  37769. program.properties.privateData[token] = blueArray;
  37770. }
  37771. break;
  37772. case 'StemSnapH':
  37773. case 'StemSnapV':
  37774. program.properties.privateData[token] = this.readNumberArray();
  37775. break;
  37776. case 'StdHW':
  37777. case 'StdVW':
  37778. program.properties.privateData[token] = this.readNumberArray()[0];
  37779. break;
  37780. case 'BlueShift':
  37781. case 'lenIV':
  37782. case 'BlueFuzz':
  37783. case 'BlueScale':
  37784. case 'LanguageGroup':
  37785. case 'ExpansionFactor':
  37786. program.properties.privateData[token] = this.readNumber();
  37787. break;
  37788. case 'ForceBold':
  37789. program.properties.privateData[token] = this.readBoolean();
  37790. break;
  37791. }
  37792. }
  37793. for (var i = 0; i < charstrings.length; i++) {
  37794. glyph = charstrings[i].glyph;
  37795. encoded = charstrings[i].encoded;
  37796. var charString = new Type1CharString();
  37797. var error = charString.convert(encoded, subrs, this.seacAnalysisEnabled);
  37798. var output = charString.output;
  37799. if (error) {
  37800. // It seems when FreeType encounters an error while evaluating a glyph
  37801. // that it completely ignores the glyph so we'll mimic that behaviour
  37802. // here and put an endchar to make the validator happy.
  37803. output = [14];
  37804. }
  37805. program.charstrings.push({
  37806. glyphName: glyph,
  37807. charstring: output,
  37808. width: charString.width,
  37809. lsb: charString.lsb,
  37810. seac: charString.seac
  37811. });
  37812. }
  37813. return program;
  37814. },
  37815. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  37816. var token;
  37817. while ((token = this.getToken()) !== null) {
  37818. if (token !== '/') {
  37819. continue;
  37820. }
  37821. token = this.getToken();
  37822. switch (token) {
  37823. case 'FontMatrix':
  37824. var matrix = this.readNumberArray();
  37825. properties.fontMatrix = matrix;
  37826. break;
  37827. case 'Encoding':
  37828. var encodingArg = this.getToken();
  37829. var encoding;
  37830. if (!/^\d+$/.test(encodingArg)) {
  37831. // encoding name is specified
  37832. encoding = getEncoding(encodingArg);
  37833. } else {
  37834. encoding = [];
  37835. var size = parseInt(encodingArg, 10) | 0;
  37836. this.getToken();
  37837. // read in 'array'
  37838. for (var j = 0; j < size; j++) {
  37839. token = this.getToken();
  37840. // skipping till first dup or def (e.g. ignoring for statement)
  37841. while (token !== 'dup' && token !== 'def') {
  37842. token = this.getToken();
  37843. if (token === null) {
  37844. return;
  37845. }
  37846. }
  37847. // invalid header
  37848. if (token === 'def') {
  37849. break;
  37850. }
  37851. // read all array data
  37852. var index = this.readInt();
  37853. this.getToken();
  37854. // read in '/'
  37855. var glyph = this.getToken();
  37856. encoding[index] = glyph;
  37857. this.getToken();
  37858. }
  37859. }
  37860. // read the in 'put'
  37861. properties.builtInEncoding = encoding;
  37862. break;
  37863. case 'FontBBox':
  37864. var fontBBox = this.readNumberArray();
  37865. // adjusting ascent/descent
  37866. properties.ascent = fontBBox[3];
  37867. properties.descent = fontBBox[1];
  37868. properties.ascentScaled = true;
  37869. break;
  37870. }
  37871. }
  37872. }
  37873. };
  37874. return Type1Parser;
  37875. }();
  37876. exports.Type1Parser = Type1Parser;
  37877. }));
  37878. (function (root, factory) {
  37879. factory(root.pdfjsCoreCMap = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser);
  37880. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser) {
  37881. var Util = sharedUtil.Util;
  37882. var assert = sharedUtil.assert;
  37883. var warn = sharedUtil.warn;
  37884. var error = sharedUtil.error;
  37885. var isInt = sharedUtil.isInt;
  37886. var isString = sharedUtil.isString;
  37887. var MissingDataException = sharedUtil.MissingDataException;
  37888. var isName = corePrimitives.isName;
  37889. var isCmd = corePrimitives.isCmd;
  37890. var isStream = corePrimitives.isStream;
  37891. var StringStream = coreStream.StringStream;
  37892. var Lexer = coreParser.Lexer;
  37893. var isEOF = coreParser.isEOF;
  37894. var BUILT_IN_CMAPS = [
  37895. // << Start unicode maps.
  37896. 'Adobe-GB1-UCS2',
  37897. 'Adobe-CNS1-UCS2',
  37898. 'Adobe-Japan1-UCS2',
  37899. 'Adobe-Korea1-UCS2',
  37900. // >> End unicode maps.
  37901. '78-EUC-H',
  37902. '78-EUC-V',
  37903. '78-H',
  37904. '78-RKSJ-H',
  37905. '78-RKSJ-V',
  37906. '78-V',
  37907. '78ms-RKSJ-H',
  37908. '78ms-RKSJ-V',
  37909. '83pv-RKSJ-H',
  37910. '90ms-RKSJ-H',
  37911. '90ms-RKSJ-V',
  37912. '90msp-RKSJ-H',
  37913. '90msp-RKSJ-V',
  37914. '90pv-RKSJ-H',
  37915. '90pv-RKSJ-V',
  37916. 'Add-H',
  37917. 'Add-RKSJ-H',
  37918. 'Add-RKSJ-V',
  37919. 'Add-V',
  37920. 'Adobe-CNS1-0',
  37921. 'Adobe-CNS1-1',
  37922. 'Adobe-CNS1-2',
  37923. 'Adobe-CNS1-3',
  37924. 'Adobe-CNS1-4',
  37925. 'Adobe-CNS1-5',
  37926. 'Adobe-CNS1-6',
  37927. 'Adobe-GB1-0',
  37928. 'Adobe-GB1-1',
  37929. 'Adobe-GB1-2',
  37930. 'Adobe-GB1-3',
  37931. 'Adobe-GB1-4',
  37932. 'Adobe-GB1-5',
  37933. 'Adobe-Japan1-0',
  37934. 'Adobe-Japan1-1',
  37935. 'Adobe-Japan1-2',
  37936. 'Adobe-Japan1-3',
  37937. 'Adobe-Japan1-4',
  37938. 'Adobe-Japan1-5',
  37939. 'Adobe-Japan1-6',
  37940. 'Adobe-Korea1-0',
  37941. 'Adobe-Korea1-1',
  37942. 'Adobe-Korea1-2',
  37943. 'B5-H',
  37944. 'B5-V',
  37945. 'B5pc-H',
  37946. 'B5pc-V',
  37947. 'CNS-EUC-H',
  37948. 'CNS-EUC-V',
  37949. 'CNS1-H',
  37950. 'CNS1-V',
  37951. 'CNS2-H',
  37952. 'CNS2-V',
  37953. 'ETHK-B5-H',
  37954. 'ETHK-B5-V',
  37955. 'ETen-B5-H',
  37956. 'ETen-B5-V',
  37957. 'ETenms-B5-H',
  37958. 'ETenms-B5-V',
  37959. 'EUC-H',
  37960. 'EUC-V',
  37961. 'Ext-H',
  37962. 'Ext-RKSJ-H',
  37963. 'Ext-RKSJ-V',
  37964. 'Ext-V',
  37965. 'GB-EUC-H',
  37966. 'GB-EUC-V',
  37967. 'GB-H',
  37968. 'GB-V',
  37969. 'GBK-EUC-H',
  37970. 'GBK-EUC-V',
  37971. 'GBK2K-H',
  37972. 'GBK2K-V',
  37973. 'GBKp-EUC-H',
  37974. 'GBKp-EUC-V',
  37975. 'GBT-EUC-H',
  37976. 'GBT-EUC-V',
  37977. 'GBT-H',
  37978. 'GBT-V',
  37979. 'GBTpc-EUC-H',
  37980. 'GBTpc-EUC-V',
  37981. 'GBpc-EUC-H',
  37982. 'GBpc-EUC-V',
  37983. 'H',
  37984. 'HKdla-B5-H',
  37985. 'HKdla-B5-V',
  37986. 'HKdlb-B5-H',
  37987. 'HKdlb-B5-V',
  37988. 'HKgccs-B5-H',
  37989. 'HKgccs-B5-V',
  37990. 'HKm314-B5-H',
  37991. 'HKm314-B5-V',
  37992. 'HKm471-B5-H',
  37993. 'HKm471-B5-V',
  37994. 'HKscs-B5-H',
  37995. 'HKscs-B5-V',
  37996. 'Hankaku',
  37997. 'Hiragana',
  37998. 'KSC-EUC-H',
  37999. 'KSC-EUC-V',
  38000. 'KSC-H',
  38001. 'KSC-Johab-H',
  38002. 'KSC-Johab-V',
  38003. 'KSC-V',
  38004. 'KSCms-UHC-H',
  38005. 'KSCms-UHC-HW-H',
  38006. 'KSCms-UHC-HW-V',
  38007. 'KSCms-UHC-V',
  38008. 'KSCpc-EUC-H',
  38009. 'KSCpc-EUC-V',
  38010. 'Katakana',
  38011. 'NWP-H',
  38012. 'NWP-V',
  38013. 'RKSJ-H',
  38014. 'RKSJ-V',
  38015. 'Roman',
  38016. 'UniCNS-UCS2-H',
  38017. 'UniCNS-UCS2-V',
  38018. 'UniCNS-UTF16-H',
  38019. 'UniCNS-UTF16-V',
  38020. 'UniCNS-UTF32-H',
  38021. 'UniCNS-UTF32-V',
  38022. 'UniCNS-UTF8-H',
  38023. 'UniCNS-UTF8-V',
  38024. 'UniGB-UCS2-H',
  38025. 'UniGB-UCS2-V',
  38026. 'UniGB-UTF16-H',
  38027. 'UniGB-UTF16-V',
  38028. 'UniGB-UTF32-H',
  38029. 'UniGB-UTF32-V',
  38030. 'UniGB-UTF8-H',
  38031. 'UniGB-UTF8-V',
  38032. 'UniJIS-UCS2-H',
  38033. 'UniJIS-UCS2-HW-H',
  38034. 'UniJIS-UCS2-HW-V',
  38035. 'UniJIS-UCS2-V',
  38036. 'UniJIS-UTF16-H',
  38037. 'UniJIS-UTF16-V',
  38038. 'UniJIS-UTF32-H',
  38039. 'UniJIS-UTF32-V',
  38040. 'UniJIS-UTF8-H',
  38041. 'UniJIS-UTF8-V',
  38042. 'UniJIS2004-UTF16-H',
  38043. 'UniJIS2004-UTF16-V',
  38044. 'UniJIS2004-UTF32-H',
  38045. 'UniJIS2004-UTF32-V',
  38046. 'UniJIS2004-UTF8-H',
  38047. 'UniJIS2004-UTF8-V',
  38048. 'UniJISPro-UCS2-HW-V',
  38049. 'UniJISPro-UCS2-V',
  38050. 'UniJISPro-UTF8-V',
  38051. 'UniJISX0213-UTF32-H',
  38052. 'UniJISX0213-UTF32-V',
  38053. 'UniJISX02132004-UTF32-H',
  38054. 'UniJISX02132004-UTF32-V',
  38055. 'UniKS-UCS2-H',
  38056. 'UniKS-UCS2-V',
  38057. 'UniKS-UTF16-H',
  38058. 'UniKS-UTF16-V',
  38059. 'UniKS-UTF32-H',
  38060. 'UniKS-UTF32-V',
  38061. 'UniKS-UTF8-H',
  38062. 'UniKS-UTF8-V',
  38063. 'V',
  38064. 'WP-Symbol'
  38065. ];
  38066. // CMap, not to be confused with TrueType's cmap.
  38067. var CMap = function CMapClosure() {
  38068. function CMap(builtInCMap) {
  38069. // Codespace ranges are stored as follows:
  38070. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  38071. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  38072. this.codespaceRanges = [
  38073. [],
  38074. [],
  38075. [],
  38076. []
  38077. ];
  38078. this.numCodespaceRanges = 0;
  38079. // Map entries have one of two forms.
  38080. // - cid chars are 16-bit unsigned integers, stored as integers.
  38081. // - bf chars are variable-length byte sequences, stored as strings, with
  38082. // one byte per character.
  38083. this._map = [];
  38084. this.name = '';
  38085. this.vertical = false;
  38086. this.useCMap = null;
  38087. this.builtInCMap = builtInCMap;
  38088. }
  38089. CMap.prototype = {
  38090. addCodespaceRange: function (n, low, high) {
  38091. this.codespaceRanges[n - 1].push(low, high);
  38092. this.numCodespaceRanges++;
  38093. },
  38094. mapCidRange: function (low, high, dstLow) {
  38095. while (low <= high) {
  38096. this._map[low++] = dstLow++;
  38097. }
  38098. },
  38099. mapBfRange: function (low, high, dstLow) {
  38100. var lastByte = dstLow.length - 1;
  38101. while (low <= high) {
  38102. this._map[low++] = dstLow;
  38103. // Only the last byte has to be incremented.
  38104. dstLow = dstLow.substr(0, lastByte) + String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  38105. }
  38106. },
  38107. mapBfRangeToArray: function (low, high, array) {
  38108. var i = 0, ii = array.length;
  38109. while (low <= high && i < ii) {
  38110. this._map[low] = array[i++];
  38111. ++low;
  38112. }
  38113. },
  38114. // This is used for both bf and cid chars.
  38115. mapOne: function (src, dst) {
  38116. this._map[src] = dst;
  38117. },
  38118. lookup: function (code) {
  38119. return this._map[code];
  38120. },
  38121. contains: function (code) {
  38122. return this._map[code] !== undefined;
  38123. },
  38124. forEach: function (callback) {
  38125. // Most maps have fewer than 65536 entries, and for those we use normal
  38126. // array iteration. But really sparse tables are possible -- e.g. with
  38127. // indices in the *billions*. For such tables we use for..in, which isn't
  38128. // ideal because it stringifies the indices for all present elements, but
  38129. // it does avoid iterating over every undefined entry.
  38130. var map = this._map;
  38131. var length = map.length;
  38132. var i;
  38133. if (length <= 0x10000) {
  38134. for (i = 0; i < length; i++) {
  38135. if (map[i] !== undefined) {
  38136. callback(i, map[i]);
  38137. }
  38138. }
  38139. } else {
  38140. for (i in this._map) {
  38141. callback(i, map[i]);
  38142. }
  38143. }
  38144. },
  38145. charCodeOf: function (value) {
  38146. return this._map.indexOf(value);
  38147. },
  38148. getMap: function () {
  38149. return this._map;
  38150. },
  38151. readCharCode: function (str, offset, out) {
  38152. var c = 0;
  38153. var codespaceRanges = this.codespaceRanges;
  38154. var codespaceRangesLen = this.codespaceRanges.length;
  38155. // 9.7.6.2 CMap Mapping
  38156. // The code length is at most 4.
  38157. for (var n = 0; n < codespaceRangesLen; n++) {
  38158. c = (c << 8 | str.charCodeAt(offset + n)) >>> 0;
  38159. // Check each codespace range to see if it falls within.
  38160. var codespaceRange = codespaceRanges[n];
  38161. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  38162. var low = codespaceRange[k++];
  38163. var high = codespaceRange[k++];
  38164. if (c >= low && c <= high) {
  38165. out.charcode = c;
  38166. out.length = n + 1;
  38167. return;
  38168. }
  38169. }
  38170. }
  38171. out.charcode = 0;
  38172. out.length = 1;
  38173. },
  38174. get length() {
  38175. return this._map.length;
  38176. },
  38177. get isIdentityCMap() {
  38178. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  38179. return false;
  38180. }
  38181. if (this._map.length !== 0x10000) {
  38182. return false;
  38183. }
  38184. for (var i = 0; i < 0x10000; i++) {
  38185. if (this._map[i] !== i) {
  38186. return false;
  38187. }
  38188. }
  38189. return true;
  38190. }
  38191. };
  38192. return CMap;
  38193. }();
  38194. // A special case of CMap, where the _map array implicitly has a length of
  38195. // 65536 and each element is equal to its index.
  38196. var IdentityCMap = function IdentityCMapClosure() {
  38197. function IdentityCMap(vertical, n) {
  38198. CMap.call(this);
  38199. this.vertical = vertical;
  38200. this.addCodespaceRange(n, 0, 0xffff);
  38201. }
  38202. Util.inherit(IdentityCMap, CMap, {});
  38203. IdentityCMap.prototype = {
  38204. addCodespaceRange: CMap.prototype.addCodespaceRange,
  38205. mapCidRange: function (low, high, dstLow) {
  38206. error('should not call mapCidRange');
  38207. },
  38208. mapBfRange: function (low, high, dstLow) {
  38209. error('should not call mapBfRange');
  38210. },
  38211. mapBfRangeToArray: function (low, high, array) {
  38212. error('should not call mapBfRangeToArray');
  38213. },
  38214. mapOne: function (src, dst) {
  38215. error('should not call mapCidOne');
  38216. },
  38217. lookup: function (code) {
  38218. return isInt(code) && code <= 0xffff ? code : undefined;
  38219. },
  38220. contains: function (code) {
  38221. return isInt(code) && code <= 0xffff;
  38222. },
  38223. forEach: function (callback) {
  38224. for (var i = 0; i <= 0xffff; i++) {
  38225. callback(i, i);
  38226. }
  38227. },
  38228. charCodeOf: function (value) {
  38229. return isInt(value) && value <= 0xffff ? value : -1;
  38230. },
  38231. getMap: function () {
  38232. // Sometimes identity maps must be instantiated, but it's rare.
  38233. var map = new Array(0x10000);
  38234. for (var i = 0; i <= 0xffff; i++) {
  38235. map[i] = i;
  38236. }
  38237. return map;
  38238. },
  38239. readCharCode: CMap.prototype.readCharCode,
  38240. get length() {
  38241. return 0x10000;
  38242. },
  38243. get isIdentityCMap() {
  38244. error('should not access .isIdentityCMap');
  38245. }
  38246. };
  38247. return IdentityCMap;
  38248. }();
  38249. var BinaryCMapReader = function BinaryCMapReaderClosure() {
  38250. function fetchBinaryData(url) {
  38251. return new Promise(function (resolve, reject) {
  38252. var request = new XMLHttpRequest();
  38253. request.open('GET', url, true);
  38254. request.responseType = 'arraybuffer';
  38255. request.onreadystatechange = function () {
  38256. if (request.readyState === XMLHttpRequest.DONE) {
  38257. if (!request.response || request.status !== 200 && request.status !== 0) {
  38258. reject(new Error('Unable to get binary cMap at: ' + url));
  38259. } else {
  38260. resolve(new Uint8Array(request.response));
  38261. }
  38262. }
  38263. };
  38264. request.send(null);
  38265. });
  38266. }
  38267. function hexToInt(a, size) {
  38268. var n = 0;
  38269. for (var i = 0; i <= size; i++) {
  38270. n = n << 8 | a[i];
  38271. }
  38272. return n >>> 0;
  38273. }
  38274. function hexToStr(a, size) {
  38275. // This code is hot. Special-case some common values to avoid creating an
  38276. // object with subarray().
  38277. if (size === 1) {
  38278. return String.fromCharCode(a[0], a[1]);
  38279. }
  38280. if (size === 3) {
  38281. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  38282. }
  38283. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  38284. }
  38285. function addHex(a, b, size) {
  38286. var c = 0;
  38287. for (var i = size; i >= 0; i--) {
  38288. c += a[i] + b[i];
  38289. a[i] = c & 255;
  38290. c >>= 8;
  38291. }
  38292. }
  38293. function incHex(a, size) {
  38294. var c = 1;
  38295. for (var i = size; i >= 0 && c > 0; i--) {
  38296. c += a[i];
  38297. a[i] = c & 255;
  38298. c >>= 8;
  38299. }
  38300. }
  38301. var MAX_NUM_SIZE = 16;
  38302. var MAX_ENCODED_NUM_SIZE = 19;
  38303. // ceil(MAX_NUM_SIZE * 7 / 8)
  38304. function BinaryCMapStream(data) {
  38305. this.buffer = data;
  38306. this.pos = 0;
  38307. this.end = data.length;
  38308. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  38309. }
  38310. BinaryCMapStream.prototype = {
  38311. readByte: function () {
  38312. if (this.pos >= this.end) {
  38313. return -1;
  38314. }
  38315. return this.buffer[this.pos++];
  38316. },
  38317. readNumber: function () {
  38318. var n = 0;
  38319. var last;
  38320. do {
  38321. var b = this.readByte();
  38322. if (b < 0) {
  38323. error('unexpected EOF in bcmap');
  38324. }
  38325. last = !(b & 0x80);
  38326. n = n << 7 | b & 0x7F;
  38327. } while (!last);
  38328. return n;
  38329. },
  38330. readSigned: function () {
  38331. var n = this.readNumber();
  38332. return n & 1 ? ~(n >>> 1) : n >>> 1;
  38333. },
  38334. readHex: function (num, size) {
  38335. num.set(this.buffer.subarray(this.pos, this.pos + size + 1));
  38336. this.pos += size + 1;
  38337. },
  38338. readHexNumber: function (num, size) {
  38339. var last;
  38340. var stack = this.tmpBuf, sp = 0;
  38341. do {
  38342. var b = this.readByte();
  38343. if (b < 0) {
  38344. error('unexpected EOF in bcmap');
  38345. }
  38346. last = !(b & 0x80);
  38347. stack[sp++] = b & 0x7F;
  38348. } while (!last);
  38349. var i = size, buffer = 0, bufferSize = 0;
  38350. while (i >= 0) {
  38351. while (bufferSize < 8 && stack.length > 0) {
  38352. buffer = stack[--sp] << bufferSize | buffer;
  38353. bufferSize += 7;
  38354. }
  38355. num[i] = buffer & 255;
  38356. i--;
  38357. buffer >>= 8;
  38358. bufferSize -= 8;
  38359. }
  38360. },
  38361. readHexSigned: function (num, size) {
  38362. this.readHexNumber(num, size);
  38363. var sign = num[size] & 1 ? 255 : 0;
  38364. var c = 0;
  38365. for (var i = 0; i <= size; i++) {
  38366. c = (c & 1) << 8 | num[i];
  38367. num[i] = c >> 1 ^ sign;
  38368. }
  38369. },
  38370. readString: function () {
  38371. var len = this.readNumber();
  38372. var s = '';
  38373. for (var i = 0; i < len; i++) {
  38374. s += String.fromCharCode(this.readNumber());
  38375. }
  38376. return s;
  38377. }
  38378. };
  38379. function processBinaryCMap(url, cMap, extend) {
  38380. return fetchBinaryData(url).then(function (data) {
  38381. var stream = new BinaryCMapStream(data);
  38382. var header = stream.readByte();
  38383. cMap.vertical = !!(header & 1);
  38384. var useCMap = null;
  38385. var start = new Uint8Array(MAX_NUM_SIZE);
  38386. var end = new Uint8Array(MAX_NUM_SIZE);
  38387. var char = new Uint8Array(MAX_NUM_SIZE);
  38388. var charCode = new Uint8Array(MAX_NUM_SIZE);
  38389. var tmp = new Uint8Array(MAX_NUM_SIZE);
  38390. var code;
  38391. var b;
  38392. while ((b = stream.readByte()) >= 0) {
  38393. var type = b >> 5;
  38394. if (type === 7) {
  38395. // metadata, e.g. comment or usecmap
  38396. switch (b & 0x1F) {
  38397. case 0:
  38398. stream.readString();
  38399. // skipping comment
  38400. break;
  38401. case 1:
  38402. useCMap = stream.readString();
  38403. break;
  38404. }
  38405. continue;
  38406. }
  38407. var sequence = !!(b & 0x10);
  38408. var dataSize = b & 15;
  38409. assert(dataSize + 1 <= MAX_NUM_SIZE);
  38410. var ucs2DataSize = 1;
  38411. var subitemsCount = stream.readNumber();
  38412. var i;
  38413. switch (type) {
  38414. case 0:
  38415. // codespacerange
  38416. stream.readHex(start, dataSize);
  38417. stream.readHexNumber(end, dataSize);
  38418. addHex(end, start, dataSize);
  38419. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize), hexToInt(end, dataSize));
  38420. for (i = 1; i < subitemsCount; i++) {
  38421. incHex(end, dataSize);
  38422. stream.readHexNumber(start, dataSize);
  38423. addHex(start, end, dataSize);
  38424. stream.readHexNumber(end, dataSize);
  38425. addHex(end, start, dataSize);
  38426. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize), hexToInt(end, dataSize));
  38427. }
  38428. break;
  38429. case 1:
  38430. // notdefrange
  38431. stream.readHex(start, dataSize);
  38432. stream.readHexNumber(end, dataSize);
  38433. addHex(end, start, dataSize);
  38434. code = stream.readNumber();
  38435. // undefined range, skipping
  38436. for (i = 1; i < subitemsCount; i++) {
  38437. incHex(end, dataSize);
  38438. stream.readHexNumber(start, dataSize);
  38439. addHex(start, end, dataSize);
  38440. stream.readHexNumber(end, dataSize);
  38441. addHex(end, start, dataSize);
  38442. code = stream.readNumber();
  38443. }
  38444. // nop
  38445. break;
  38446. case 2:
  38447. // cidchar
  38448. stream.readHex(char, dataSize);
  38449. code = stream.readNumber();
  38450. cMap.mapOne(hexToInt(char, dataSize), code);
  38451. for (i = 1; i < subitemsCount; i++) {
  38452. incHex(char, dataSize);
  38453. if (!sequence) {
  38454. stream.readHexNumber(tmp, dataSize);
  38455. addHex(char, tmp, dataSize);
  38456. }
  38457. code = stream.readSigned() + (code + 1);
  38458. cMap.mapOne(hexToInt(char, dataSize), code);
  38459. }
  38460. break;
  38461. case 3:
  38462. // cidrange
  38463. stream.readHex(start, dataSize);
  38464. stream.readHexNumber(end, dataSize);
  38465. addHex(end, start, dataSize);
  38466. code = stream.readNumber();
  38467. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize), code);
  38468. for (i = 1; i < subitemsCount; i++) {
  38469. incHex(end, dataSize);
  38470. if (!sequence) {
  38471. stream.readHexNumber(start, dataSize);
  38472. addHex(start, end, dataSize);
  38473. } else {
  38474. start.set(end);
  38475. }
  38476. stream.readHexNumber(end, dataSize);
  38477. addHex(end, start, dataSize);
  38478. code = stream.readNumber();
  38479. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize), code);
  38480. }
  38481. break;
  38482. case 4:
  38483. // bfchar
  38484. stream.readHex(char, ucs2DataSize);
  38485. stream.readHex(charCode, dataSize);
  38486. cMap.mapOne(hexToInt(char, ucs2DataSize), hexToStr(charCode, dataSize));
  38487. for (i = 1; i < subitemsCount; i++) {
  38488. incHex(char, ucs2DataSize);
  38489. if (!sequence) {
  38490. stream.readHexNumber(tmp, ucs2DataSize);
  38491. addHex(char, tmp, ucs2DataSize);
  38492. }
  38493. incHex(charCode, dataSize);
  38494. stream.readHexSigned(tmp, dataSize);
  38495. addHex(charCode, tmp, dataSize);
  38496. cMap.mapOne(hexToInt(char, ucs2DataSize), hexToStr(charCode, dataSize));
  38497. }
  38498. break;
  38499. case 5:
  38500. // bfrange
  38501. stream.readHex(start, ucs2DataSize);
  38502. stream.readHexNumber(end, ucs2DataSize);
  38503. addHex(end, start, ucs2DataSize);
  38504. stream.readHex(charCode, dataSize);
  38505. cMap.mapBfRange(hexToInt(start, ucs2DataSize), hexToInt(end, ucs2DataSize), hexToStr(charCode, dataSize));
  38506. for (i = 1; i < subitemsCount; i++) {
  38507. incHex(end, ucs2DataSize);
  38508. if (!sequence) {
  38509. stream.readHexNumber(start, ucs2DataSize);
  38510. addHex(start, end, ucs2DataSize);
  38511. } else {
  38512. start.set(end);
  38513. }
  38514. stream.readHexNumber(end, ucs2DataSize);
  38515. addHex(end, start, ucs2DataSize);
  38516. stream.readHex(charCode, dataSize);
  38517. cMap.mapBfRange(hexToInt(start, ucs2DataSize), hexToInt(end, ucs2DataSize), hexToStr(charCode, dataSize));
  38518. }
  38519. break;
  38520. default:
  38521. error('Unknown type: ' + type);
  38522. break;
  38523. }
  38524. }
  38525. if (useCMap) {
  38526. return extend(useCMap);
  38527. }
  38528. return cMap;
  38529. });
  38530. }
  38531. function BinaryCMapReader() {
  38532. }
  38533. BinaryCMapReader.prototype = { read: processBinaryCMap };
  38534. return BinaryCMapReader;
  38535. }();
  38536. var CMapFactory = function CMapFactoryClosure() {
  38537. function strToInt(str) {
  38538. var a = 0;
  38539. for (var i = 0; i < str.length; i++) {
  38540. a = a << 8 | str.charCodeAt(i);
  38541. }
  38542. return a >>> 0;
  38543. }
  38544. function expectString(obj) {
  38545. if (!isString(obj)) {
  38546. error('Malformed CMap: expected string.');
  38547. }
  38548. }
  38549. function expectInt(obj) {
  38550. if (!isInt(obj)) {
  38551. error('Malformed CMap: expected int.');
  38552. }
  38553. }
  38554. function parseBfChar(cMap, lexer) {
  38555. while (true) {
  38556. var obj = lexer.getObj();
  38557. if (isEOF(obj)) {
  38558. break;
  38559. }
  38560. if (isCmd(obj, 'endbfchar')) {
  38561. return;
  38562. }
  38563. expectString(obj);
  38564. var src = strToInt(obj);
  38565. obj = lexer.getObj();
  38566. // TODO are /dstName used?
  38567. expectString(obj);
  38568. var dst = obj;
  38569. cMap.mapOne(src, dst);
  38570. }
  38571. }
  38572. function parseBfRange(cMap, lexer) {
  38573. while (true) {
  38574. var obj = lexer.getObj();
  38575. if (isEOF(obj)) {
  38576. break;
  38577. }
  38578. if (isCmd(obj, 'endbfrange')) {
  38579. return;
  38580. }
  38581. expectString(obj);
  38582. var low = strToInt(obj);
  38583. obj = lexer.getObj();
  38584. expectString(obj);
  38585. var high = strToInt(obj);
  38586. obj = lexer.getObj();
  38587. if (isInt(obj) || isString(obj)) {
  38588. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  38589. cMap.mapBfRange(low, high, dstLow);
  38590. } else if (isCmd(obj, '[')) {
  38591. obj = lexer.getObj();
  38592. var array = [];
  38593. while (!isCmd(obj, ']') && !isEOF(obj)) {
  38594. array.push(obj);
  38595. obj = lexer.getObj();
  38596. }
  38597. cMap.mapBfRangeToArray(low, high, array);
  38598. } else {
  38599. break;
  38600. }
  38601. }
  38602. error('Invalid bf range.');
  38603. }
  38604. function parseCidChar(cMap, lexer) {
  38605. while (true) {
  38606. var obj = lexer.getObj();
  38607. if (isEOF(obj)) {
  38608. break;
  38609. }
  38610. if (isCmd(obj, 'endcidchar')) {
  38611. return;
  38612. }
  38613. expectString(obj);
  38614. var src = strToInt(obj);
  38615. obj = lexer.getObj();
  38616. expectInt(obj);
  38617. var dst = obj;
  38618. cMap.mapOne(src, dst);
  38619. }
  38620. }
  38621. function parseCidRange(cMap, lexer) {
  38622. while (true) {
  38623. var obj = lexer.getObj();
  38624. if (isEOF(obj)) {
  38625. break;
  38626. }
  38627. if (isCmd(obj, 'endcidrange')) {
  38628. return;
  38629. }
  38630. expectString(obj);
  38631. var low = strToInt(obj);
  38632. obj = lexer.getObj();
  38633. expectString(obj);
  38634. var high = strToInt(obj);
  38635. obj = lexer.getObj();
  38636. expectInt(obj);
  38637. var dstLow = obj;
  38638. cMap.mapCidRange(low, high, dstLow);
  38639. }
  38640. }
  38641. function parseCodespaceRange(cMap, lexer) {
  38642. while (true) {
  38643. var obj = lexer.getObj();
  38644. if (isEOF(obj)) {
  38645. break;
  38646. }
  38647. if (isCmd(obj, 'endcodespacerange')) {
  38648. return;
  38649. }
  38650. if (!isString(obj)) {
  38651. break;
  38652. }
  38653. var low = strToInt(obj);
  38654. obj = lexer.getObj();
  38655. if (!isString(obj)) {
  38656. break;
  38657. }
  38658. var high = strToInt(obj);
  38659. cMap.addCodespaceRange(obj.length, low, high);
  38660. }
  38661. error('Invalid codespace range.');
  38662. }
  38663. function parseWMode(cMap, lexer) {
  38664. var obj = lexer.getObj();
  38665. if (isInt(obj)) {
  38666. cMap.vertical = !!obj;
  38667. }
  38668. }
  38669. function parseCMapName(cMap, lexer) {
  38670. var obj = lexer.getObj();
  38671. if (isName(obj) && isString(obj.name)) {
  38672. cMap.name = obj.name;
  38673. }
  38674. }
  38675. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  38676. var previous;
  38677. var embededUseCMap;
  38678. objLoop:
  38679. while (true) {
  38680. try {
  38681. var obj = lexer.getObj();
  38682. if (isEOF(obj)) {
  38683. break;
  38684. } else if (isName(obj)) {
  38685. if (obj.name === 'WMode') {
  38686. parseWMode(cMap, lexer);
  38687. } else if (obj.name === 'CMapName') {
  38688. parseCMapName(cMap, lexer);
  38689. }
  38690. previous = obj;
  38691. } else if (isCmd(obj)) {
  38692. switch (obj.cmd) {
  38693. case 'endcmap':
  38694. break objLoop;
  38695. case 'usecmap':
  38696. if (isName(previous)) {
  38697. embededUseCMap = previous.name;
  38698. }
  38699. break;
  38700. case 'begincodespacerange':
  38701. parseCodespaceRange(cMap, lexer);
  38702. break;
  38703. case 'beginbfchar':
  38704. parseBfChar(cMap, lexer);
  38705. break;
  38706. case 'begincidchar':
  38707. parseCidChar(cMap, lexer);
  38708. break;
  38709. case 'beginbfrange':
  38710. parseBfRange(cMap, lexer);
  38711. break;
  38712. case 'begincidrange':
  38713. parseCidRange(cMap, lexer);
  38714. break;
  38715. }
  38716. }
  38717. } catch (ex) {
  38718. if (ex instanceof MissingDataException) {
  38719. throw ex;
  38720. }
  38721. warn('Invalid cMap data: ' + ex);
  38722. continue;
  38723. }
  38724. }
  38725. if (!useCMap && embededUseCMap) {
  38726. // Load the usecmap definition from the file only if there wasn't one
  38727. // specified.
  38728. useCMap = embededUseCMap;
  38729. }
  38730. if (useCMap) {
  38731. return extendCMap(cMap, builtInCMapParams, useCMap);
  38732. }
  38733. return Promise.resolve(cMap);
  38734. }
  38735. function extendCMap(cMap, builtInCMapParams, useCMap) {
  38736. return createBuiltInCMap(useCMap, builtInCMapParams).then(function (newCMap) {
  38737. cMap.useCMap = newCMap;
  38738. // If there aren't any code space ranges defined clone all the parent ones
  38739. // into this cMap.
  38740. if (cMap.numCodespaceRanges === 0) {
  38741. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  38742. for (var i = 0; i < useCodespaceRanges.length; i++) {
  38743. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  38744. }
  38745. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  38746. }
  38747. // Merge the map into the current one, making sure not to override
  38748. // any previously defined entries.
  38749. cMap.useCMap.forEach(function (key, value) {
  38750. if (!cMap.contains(key)) {
  38751. cMap.mapOne(key, cMap.useCMap.lookup(key));
  38752. }
  38753. });
  38754. return cMap;
  38755. });
  38756. }
  38757. function parseBinaryCMap(name, builtInCMapParams) {
  38758. var url = builtInCMapParams.url + name + '.bcmap';
  38759. var cMap = new CMap(true);
  38760. return new BinaryCMapReader().read(url, cMap, function (useCMap) {
  38761. return extendCMap(cMap, builtInCMapParams, useCMap);
  38762. });
  38763. }
  38764. function createBuiltInCMap(name, builtInCMapParams) {
  38765. if (name === 'Identity-H') {
  38766. return Promise.resolve(new IdentityCMap(false, 2));
  38767. } else if (name === 'Identity-V') {
  38768. return Promise.resolve(new IdentityCMap(true, 2));
  38769. }
  38770. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  38771. return Promise.reject(new Error('Unknown cMap name: ' + name));
  38772. }
  38773. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  38774. if (builtInCMapParams.packed) {
  38775. return parseBinaryCMap(name, builtInCMapParams);
  38776. }
  38777. return new Promise(function (resolve, reject) {
  38778. var url = builtInCMapParams.url + name;
  38779. var request = new XMLHttpRequest();
  38780. request.onreadystatechange = function () {
  38781. if (request.readyState === XMLHttpRequest.DONE) {
  38782. if (request.status === 200 || request.status === 0) {
  38783. var cMap = new CMap(true);
  38784. var lexer = new Lexer(new StringStream(request.responseText));
  38785. parseCMap(cMap, lexer, builtInCMapParams, null).then(function (parsedCMap) {
  38786. resolve(parsedCMap);
  38787. });
  38788. } else {
  38789. reject(new Error('Unable to get cMap at: ' + url));
  38790. }
  38791. }
  38792. };
  38793. request.open('GET', url, true);
  38794. request.send(null);
  38795. });
  38796. }
  38797. return {
  38798. create: function (encoding, builtInCMapParams, useCMap) {
  38799. if (isName(encoding)) {
  38800. return createBuiltInCMap(encoding.name, builtInCMapParams);
  38801. } else if (isStream(encoding)) {
  38802. var cMap = new CMap();
  38803. var lexer = new Lexer(encoding);
  38804. return parseCMap(cMap, lexer, builtInCMapParams, useCMap).then(function (parsedCMap) {
  38805. if (parsedCMap.isIdentityCMap) {
  38806. return createBuiltInCMap(parsedCMap.name, builtInCMapParams);
  38807. }
  38808. return parsedCMap;
  38809. });
  38810. }
  38811. return Promise.reject(new Error('Encoding required.'));
  38812. }
  38813. };
  38814. }();
  38815. exports.CMap = CMap;
  38816. exports.CMapFactory = CMapFactory;
  38817. exports.IdentityCMap = IdentityCMap;
  38818. }));
  38819. (function (root, factory) {
  38820. factory(root.pdfjsCoreFonts = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreGlyphList, root.pdfjsCoreFontRenderer, root.pdfjsCoreEncodings, root.pdfjsCoreStandardFonts, root.pdfjsCoreUnicode, root.pdfjsCoreType1Parser, root.pdfjsCoreCFFParser);
  38821. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreGlyphList, coreFontRenderer, coreEncodings, coreStandardFonts, coreUnicode, coreType1Parser, coreCFFParser) {
  38822. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  38823. var FontType = sharedUtil.FontType;
  38824. var assert = sharedUtil.assert;
  38825. var bytesToString = sharedUtil.bytesToString;
  38826. var error = sharedUtil.error;
  38827. var info = sharedUtil.info;
  38828. var isArray = sharedUtil.isArray;
  38829. var isInt = sharedUtil.isInt;
  38830. var isNum = sharedUtil.isNum;
  38831. var readUint32 = sharedUtil.readUint32;
  38832. var shadow = sharedUtil.shadow;
  38833. var string32 = sharedUtil.string32;
  38834. var warn = sharedUtil.warn;
  38835. var MissingDataException = sharedUtil.MissingDataException;
  38836. var isSpace = sharedUtil.isSpace;
  38837. var Stream = coreStream.Stream;
  38838. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  38839. var getDingbatsGlyphsUnicode = coreGlyphList.getDingbatsGlyphsUnicode;
  38840. var FontRendererFactory = coreFontRenderer.FontRendererFactory;
  38841. var StandardEncoding = coreEncodings.StandardEncoding;
  38842. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  38843. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  38844. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  38845. var getEncoding = coreEncodings.getEncoding;
  38846. var getStdFontMap = coreStandardFonts.getStdFontMap;
  38847. var getNonStdFontMap = coreStandardFonts.getNonStdFontMap;
  38848. var getGlyphMapForStandardFonts = coreStandardFonts.getGlyphMapForStandardFonts;
  38849. var getSupplementalGlyphMapForArialBlack = coreStandardFonts.getSupplementalGlyphMapForArialBlack;
  38850. var getUnicodeRangeFor = coreUnicode.getUnicodeRangeFor;
  38851. var mapSpecialUnicodeValues = coreUnicode.mapSpecialUnicodeValues;
  38852. var getUnicodeForGlyph = coreUnicode.getUnicodeForGlyph;
  38853. var Type1Parser = coreType1Parser.Type1Parser;
  38854. var CFFStandardStrings = coreCFFParser.CFFStandardStrings;
  38855. var CFFParser = coreCFFParser.CFFParser;
  38856. var CFFCompiler = coreCFFParser.CFFCompiler;
  38857. var CFF = coreCFFParser.CFF;
  38858. var CFFHeader = coreCFFParser.CFFHeader;
  38859. var CFFTopDict = coreCFFParser.CFFTopDict;
  38860. var CFFPrivateDict = coreCFFParser.CFFPrivateDict;
  38861. var CFFStrings = coreCFFParser.CFFStrings;
  38862. var CFFIndex = coreCFFParser.CFFIndex;
  38863. var CFFCharset = coreCFFParser.CFFCharset;
  38864. // Unicode Private Use Area
  38865. var PRIVATE_USE_OFFSET_START = 0xE000;
  38866. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  38867. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  38868. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  38869. // except for Type 3 fonts
  38870. var PDF_GLYPH_SPACE_UNITS = 1000;
  38871. // Accented charactars are not displayed properly on Windows, using this flag
  38872. // to control analysis of seac charstrings.
  38873. var SEAC_ANALYSIS_ENABLED = false;
  38874. var FontFlags = {
  38875. FixedPitch: 1,
  38876. Serif: 2,
  38877. Symbolic: 4,
  38878. Script: 8,
  38879. Nonsymbolic: 32,
  38880. Italic: 64,
  38881. AllCap: 65536,
  38882. SmallCap: 131072,
  38883. ForceBold: 262144
  38884. };
  38885. var MacStandardGlyphOrdering = [
  38886. '.notdef',
  38887. '.null',
  38888. 'nonmarkingreturn',
  38889. 'space',
  38890. 'exclam',
  38891. 'quotedbl',
  38892. 'numbersign',
  38893. 'dollar',
  38894. 'percent',
  38895. 'ampersand',
  38896. 'quotesingle',
  38897. 'parenleft',
  38898. 'parenright',
  38899. 'asterisk',
  38900. 'plus',
  38901. 'comma',
  38902. 'hyphen',
  38903. 'period',
  38904. 'slash',
  38905. 'zero',
  38906. 'one',
  38907. 'two',
  38908. 'three',
  38909. 'four',
  38910. 'five',
  38911. 'six',
  38912. 'seven',
  38913. 'eight',
  38914. 'nine',
  38915. 'colon',
  38916. 'semicolon',
  38917. 'less',
  38918. 'equal',
  38919. 'greater',
  38920. 'question',
  38921. 'at',
  38922. 'A',
  38923. 'B',
  38924. 'C',
  38925. 'D',
  38926. 'E',
  38927. 'F',
  38928. 'G',
  38929. 'H',
  38930. 'I',
  38931. 'J',
  38932. 'K',
  38933. 'L',
  38934. 'M',
  38935. 'N',
  38936. 'O',
  38937. 'P',
  38938. 'Q',
  38939. 'R',
  38940. 'S',
  38941. 'T',
  38942. 'U',
  38943. 'V',
  38944. 'W',
  38945. 'X',
  38946. 'Y',
  38947. 'Z',
  38948. 'bracketleft',
  38949. 'backslash',
  38950. 'bracketright',
  38951. 'asciicircum',
  38952. 'underscore',
  38953. 'grave',
  38954. 'a',
  38955. 'b',
  38956. 'c',
  38957. 'd',
  38958. 'e',
  38959. 'f',
  38960. 'g',
  38961. 'h',
  38962. 'i',
  38963. 'j',
  38964. 'k',
  38965. 'l',
  38966. 'm',
  38967. 'n',
  38968. 'o',
  38969. 'p',
  38970. 'q',
  38971. 'r',
  38972. 's',
  38973. 't',
  38974. 'u',
  38975. 'v',
  38976. 'w',
  38977. 'x',
  38978. 'y',
  38979. 'z',
  38980. 'braceleft',
  38981. 'bar',
  38982. 'braceright',
  38983. 'asciitilde',
  38984. 'Adieresis',
  38985. 'Aring',
  38986. 'Ccedilla',
  38987. 'Eacute',
  38988. 'Ntilde',
  38989. 'Odieresis',
  38990. 'Udieresis',
  38991. 'aacute',
  38992. 'agrave',
  38993. 'acircumflex',
  38994. 'adieresis',
  38995. 'atilde',
  38996. 'aring',
  38997. 'ccedilla',
  38998. 'eacute',
  38999. 'egrave',
  39000. 'ecircumflex',
  39001. 'edieresis',
  39002. 'iacute',
  39003. 'igrave',
  39004. 'icircumflex',
  39005. 'idieresis',
  39006. 'ntilde',
  39007. 'oacute',
  39008. 'ograve',
  39009. 'ocircumflex',
  39010. 'odieresis',
  39011. 'otilde',
  39012. 'uacute',
  39013. 'ugrave',
  39014. 'ucircumflex',
  39015. 'udieresis',
  39016. 'dagger',
  39017. 'degree',
  39018. 'cent',
  39019. 'sterling',
  39020. 'section',
  39021. 'bullet',
  39022. 'paragraph',
  39023. 'germandbls',
  39024. 'registered',
  39025. 'copyright',
  39026. 'trademark',
  39027. 'acute',
  39028. 'dieresis',
  39029. 'notequal',
  39030. 'AE',
  39031. 'Oslash',
  39032. 'infinity',
  39033. 'plusminus',
  39034. 'lessequal',
  39035. 'greaterequal',
  39036. 'yen',
  39037. 'mu',
  39038. 'partialdiff',
  39039. 'summation',
  39040. 'product',
  39041. 'pi',
  39042. 'integral',
  39043. 'ordfeminine',
  39044. 'ordmasculine',
  39045. 'Omega',
  39046. 'ae',
  39047. 'oslash',
  39048. 'questiondown',
  39049. 'exclamdown',
  39050. 'logicalnot',
  39051. 'radical',
  39052. 'florin',
  39053. 'approxequal',
  39054. 'Delta',
  39055. 'guillemotleft',
  39056. 'guillemotright',
  39057. 'ellipsis',
  39058. 'nonbreakingspace',
  39059. 'Agrave',
  39060. 'Atilde',
  39061. 'Otilde',
  39062. 'OE',
  39063. 'oe',
  39064. 'endash',
  39065. 'emdash',
  39066. 'quotedblleft',
  39067. 'quotedblright',
  39068. 'quoteleft',
  39069. 'quoteright',
  39070. 'divide',
  39071. 'lozenge',
  39072. 'ydieresis',
  39073. 'Ydieresis',
  39074. 'fraction',
  39075. 'currency',
  39076. 'guilsinglleft',
  39077. 'guilsinglright',
  39078. 'fi',
  39079. 'fl',
  39080. 'daggerdbl',
  39081. 'periodcentered',
  39082. 'quotesinglbase',
  39083. 'quotedblbase',
  39084. 'perthousand',
  39085. 'Acircumflex',
  39086. 'Ecircumflex',
  39087. 'Aacute',
  39088. 'Edieresis',
  39089. 'Egrave',
  39090. 'Iacute',
  39091. 'Icircumflex',
  39092. 'Idieresis',
  39093. 'Igrave',
  39094. 'Oacute',
  39095. 'Ocircumflex',
  39096. 'apple',
  39097. 'Ograve',
  39098. 'Uacute',
  39099. 'Ucircumflex',
  39100. 'Ugrave',
  39101. 'dotlessi',
  39102. 'circumflex',
  39103. 'tilde',
  39104. 'macron',
  39105. 'breve',
  39106. 'dotaccent',
  39107. 'ring',
  39108. 'cedilla',
  39109. 'hungarumlaut',
  39110. 'ogonek',
  39111. 'caron',
  39112. 'Lslash',
  39113. 'lslash',
  39114. 'Scaron',
  39115. 'scaron',
  39116. 'Zcaron',
  39117. 'zcaron',
  39118. 'brokenbar',
  39119. 'Eth',
  39120. 'eth',
  39121. 'Yacute',
  39122. 'yacute',
  39123. 'Thorn',
  39124. 'thorn',
  39125. 'minus',
  39126. 'multiply',
  39127. 'onesuperior',
  39128. 'twosuperior',
  39129. 'threesuperior',
  39130. 'onehalf',
  39131. 'onequarter',
  39132. 'threequarters',
  39133. 'franc',
  39134. 'Gbreve',
  39135. 'gbreve',
  39136. 'Idotaccent',
  39137. 'Scedilla',
  39138. 'scedilla',
  39139. 'Cacute',
  39140. 'cacute',
  39141. 'Ccaron',
  39142. 'ccaron',
  39143. 'dcroat'
  39144. ];
  39145. function adjustWidths(properties) {
  39146. if (!properties.fontMatrix) {
  39147. return;
  39148. }
  39149. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  39150. return;
  39151. }
  39152. // adjusting width to fontMatrix scale
  39153. var scale = 0.001 / properties.fontMatrix[0];
  39154. var glyphsWidths = properties.widths;
  39155. for (var glyph in glyphsWidths) {
  39156. glyphsWidths[glyph] *= scale;
  39157. }
  39158. properties.defaultWidth *= scale;
  39159. }
  39160. function adjustToUnicode(properties, builtInEncoding) {
  39161. if (properties.hasIncludedToUnicodeMap) {
  39162. return;
  39163. }
  39164. // The font dictionary has a `ToUnicode` entry.
  39165. if (properties.hasEncoding) {
  39166. return;
  39167. }
  39168. // The font dictionary has an `Encoding` entry.
  39169. if (builtInEncoding === properties.defaultEncoding) {
  39170. return;
  39171. }
  39172. // No point in trying to adjust `toUnicode` if the encodings match.
  39173. if (properties.toUnicode instanceof IdentityToUnicodeMap) {
  39174. return;
  39175. }
  39176. var toUnicode = [], glyphsUnicodeMap = getGlyphsUnicode();
  39177. for (var charCode in builtInEncoding) {
  39178. var glyphName = builtInEncoding[charCode];
  39179. var unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  39180. if (unicode !== -1) {
  39181. toUnicode[charCode] = String.fromCharCode(unicode);
  39182. }
  39183. }
  39184. properties.toUnicode.amend(toUnicode);
  39185. }
  39186. function getFontType(type, subtype) {
  39187. switch (type) {
  39188. case 'Type1':
  39189. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  39190. case 'CIDFontType0':
  39191. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C : FontType.CIDFONTTYPE0;
  39192. case 'OpenType':
  39193. return FontType.OPENTYPE;
  39194. case 'TrueType':
  39195. return FontType.TRUETYPE;
  39196. case 'CIDFontType2':
  39197. return FontType.CIDFONTTYPE2;
  39198. case 'MMType1':
  39199. return FontType.MMTYPE1;
  39200. case 'Type0':
  39201. return FontType.TYPE0;
  39202. default:
  39203. return FontType.UNKNOWN;
  39204. }
  39205. }
  39206. // Some bad PDF generators, e.g. Scribus PDF, include glyph names
  39207. // in a 'uniXXXX' format -- attempting to recover proper ones.
  39208. function recoverGlyphName(name, glyphsUnicodeMap) {
  39209. if (glyphsUnicodeMap[name] !== undefined) {
  39210. return name;
  39211. }
  39212. // The glyph name is non-standard, trying to recover.
  39213. var unicode = getUnicodeForGlyph(name, glyphsUnicodeMap);
  39214. if (unicode !== -1) {
  39215. for (var key in glyphsUnicodeMap) {
  39216. if (glyphsUnicodeMap[key] === unicode) {
  39217. return key;
  39218. }
  39219. }
  39220. }
  39221. info('Unable to recover a standard glyph name for: ' + name);
  39222. return name;
  39223. }
  39224. var Glyph = function GlyphClosure() {
  39225. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont) {
  39226. this.fontChar = fontChar;
  39227. this.unicode = unicode;
  39228. this.accent = accent;
  39229. this.width = width;
  39230. this.vmetric = vmetric;
  39231. this.operatorListId = operatorListId;
  39232. this.isSpace = isSpace;
  39233. this.isInFont = isInFont;
  39234. }
  39235. Glyph.prototype.matchesForCache = function (fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont) {
  39236. 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;
  39237. };
  39238. return Glyph;
  39239. }();
  39240. var ToUnicodeMap = function ToUnicodeMapClosure() {
  39241. function ToUnicodeMap(cmap) {
  39242. // The elements of this._map can be integers or strings, depending on how
  39243. // |cmap| was created.
  39244. this._map = cmap;
  39245. }
  39246. ToUnicodeMap.prototype = {
  39247. get length() {
  39248. return this._map.length;
  39249. },
  39250. forEach: function (callback) {
  39251. for (var charCode in this._map) {
  39252. callback(charCode, this._map[charCode].charCodeAt(0));
  39253. }
  39254. },
  39255. has: function (i) {
  39256. return this._map[i] !== undefined;
  39257. },
  39258. get: function (i) {
  39259. return this._map[i];
  39260. },
  39261. charCodeOf: function (v) {
  39262. return this._map.indexOf(v);
  39263. },
  39264. amend: function (map) {
  39265. for (var charCode in map) {
  39266. this._map[charCode] = map[charCode];
  39267. }
  39268. }
  39269. };
  39270. return ToUnicodeMap;
  39271. }();
  39272. var IdentityToUnicodeMap = function IdentityToUnicodeMapClosure() {
  39273. function IdentityToUnicodeMap(firstChar, lastChar) {
  39274. this.firstChar = firstChar;
  39275. this.lastChar = lastChar;
  39276. }
  39277. IdentityToUnicodeMap.prototype = {
  39278. get length() {
  39279. return this.lastChar + 1 - this.firstChar;
  39280. },
  39281. forEach: function (callback) {
  39282. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  39283. callback(i, i);
  39284. }
  39285. },
  39286. has: function (i) {
  39287. return this.firstChar <= i && i <= this.lastChar;
  39288. },
  39289. get: function (i) {
  39290. if (this.firstChar <= i && i <= this.lastChar) {
  39291. return String.fromCharCode(i);
  39292. }
  39293. return undefined;
  39294. },
  39295. charCodeOf: function (v) {
  39296. return isInt(v) && v >= this.firstChar && v <= this.lastChar ? v : -1;
  39297. },
  39298. amend: function (map) {
  39299. error('Should not call amend()');
  39300. }
  39301. };
  39302. return IdentityToUnicodeMap;
  39303. }();
  39304. var OpenTypeFileBuilder = function OpenTypeFileBuilderClosure() {
  39305. function writeInt16(dest, offset, num) {
  39306. dest[offset] = num >> 8 & 0xFF;
  39307. dest[offset + 1] = num & 0xFF;
  39308. }
  39309. function writeInt32(dest, offset, num) {
  39310. dest[offset] = num >> 24 & 0xFF;
  39311. dest[offset + 1] = num >> 16 & 0xFF;
  39312. dest[offset + 2] = num >> 8 & 0xFF;
  39313. dest[offset + 3] = num & 0xFF;
  39314. }
  39315. function writeData(dest, offset, data) {
  39316. var i, ii;
  39317. if (data instanceof Uint8Array) {
  39318. dest.set(data, offset);
  39319. } else if (typeof data === 'string') {
  39320. for (i = 0, ii = data.length; i < ii; i++) {
  39321. dest[offset++] = data.charCodeAt(i) & 0xFF;
  39322. }
  39323. } else {
  39324. // treating everything else as array
  39325. for (i = 0, ii = data.length; i < ii; i++) {
  39326. dest[offset++] = data[i] & 0xFF;
  39327. }
  39328. }
  39329. }
  39330. function OpenTypeFileBuilder(sfnt) {
  39331. this.sfnt = sfnt;
  39332. this.tables = Object.create(null);
  39333. }
  39334. OpenTypeFileBuilder.getSearchParams = function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  39335. var maxPower2 = 1, log2 = 0;
  39336. while ((maxPower2 ^ entriesCount) > maxPower2) {
  39337. maxPower2 <<= 1;
  39338. log2++;
  39339. }
  39340. var searchRange = maxPower2 * entrySize;
  39341. return {
  39342. range: searchRange,
  39343. entry: log2,
  39344. rangeShift: entrySize * entriesCount - searchRange
  39345. };
  39346. };
  39347. var OTF_HEADER_SIZE = 12;
  39348. var OTF_TABLE_ENTRY_SIZE = 16;
  39349. OpenTypeFileBuilder.prototype = {
  39350. toArray: function OpenTypeFileBuilder_toArray() {
  39351. var sfnt = this.sfnt;
  39352. // Tables needs to be written by ascendant alphabetic order
  39353. var tables = this.tables;
  39354. var tablesNames = Object.keys(tables);
  39355. tablesNames.sort();
  39356. var numTables = tablesNames.length;
  39357. var i, j, jj, table, tableName;
  39358. // layout the tables data
  39359. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  39360. var tableOffsets = [offset];
  39361. for (i = 0; i < numTables; i++) {
  39362. table = tables[tablesNames[i]];
  39363. var paddedLength = (table.length + 3 & ~3) >>> 0;
  39364. offset += paddedLength;
  39365. tableOffsets.push(offset);
  39366. }
  39367. var file = new Uint8Array(offset);
  39368. // write the table data first (mostly for checksum)
  39369. for (i = 0; i < numTables; i++) {
  39370. table = tables[tablesNames[i]];
  39371. writeData(file, tableOffsets[i], table);
  39372. }
  39373. // sfnt version (4 bytes)
  39374. if (sfnt === 'true') {
  39375. // Windows hates the Mac TrueType sfnt version number
  39376. sfnt = string32(0x00010000);
  39377. }
  39378. file[0] = sfnt.charCodeAt(0) & 0xFF;
  39379. file[1] = sfnt.charCodeAt(1) & 0xFF;
  39380. file[2] = sfnt.charCodeAt(2) & 0xFF;
  39381. file[3] = sfnt.charCodeAt(3) & 0xFF;
  39382. // numTables (2 bytes)
  39383. writeInt16(file, 4, numTables);
  39384. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  39385. // searchRange (2 bytes)
  39386. writeInt16(file, 6, searchParams.range);
  39387. // entrySelector (2 bytes)
  39388. writeInt16(file, 8, searchParams.entry);
  39389. // rangeShift (2 bytes)
  39390. writeInt16(file, 10, searchParams.rangeShift);
  39391. offset = OTF_HEADER_SIZE;
  39392. // writing table entries
  39393. for (i = 0; i < numTables; i++) {
  39394. tableName = tablesNames[i];
  39395. file[offset] = tableName.charCodeAt(0) & 0xFF;
  39396. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  39397. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  39398. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  39399. // checksum
  39400. var checksum = 0;
  39401. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  39402. var quad = readUint32(file, j);
  39403. checksum = checksum + quad >>> 0;
  39404. }
  39405. writeInt32(file, offset + 4, checksum);
  39406. // offset
  39407. writeInt32(file, offset + 8, tableOffsets[i]);
  39408. // length
  39409. writeInt32(file, offset + 12, tables[tableName].length);
  39410. offset += OTF_TABLE_ENTRY_SIZE;
  39411. }
  39412. return file;
  39413. },
  39414. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  39415. if (tag in this.tables) {
  39416. throw new Error('Table ' + tag + ' already exists');
  39417. }
  39418. this.tables[tag] = data;
  39419. }
  39420. };
  39421. return OpenTypeFileBuilder;
  39422. }();
  39423. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  39424. // issues when they are painted on the canvas, e.g. complex-script shaping or
  39425. // control/whitespace characters. The ranges are listed in pairs: the first item
  39426. // is a code of the first problematic code, the second one is the next
  39427. // non-problematic code. The ranges must be in sorted order.
  39428. var ProblematicCharRanges = new Int32Array([
  39429. // Control characters.
  39430. 0x0000,
  39431. 0x0020,
  39432. 0x007F,
  39433. 0x00A1,
  39434. 0x00AD,
  39435. 0x00AE,
  39436. // Chars that is used in complex-script shaping.
  39437. 0x0600,
  39438. 0x0780,
  39439. 0x08A0,
  39440. 0x10A0,
  39441. 0x1780,
  39442. 0x1800,
  39443. 0x1C00,
  39444. 0x1C50,
  39445. // General punctuation chars.
  39446. 0x2000,
  39447. 0x2010,
  39448. 0x2011,
  39449. 0x2012,
  39450. 0x2028,
  39451. 0x2030,
  39452. 0x205F,
  39453. 0x2070,
  39454. 0x25CC,
  39455. 0x25CD,
  39456. 0x3000,
  39457. 0x3001,
  39458. // Chars that is used in complex-script shaping.
  39459. 0xAA60,
  39460. 0xAA80,
  39461. // Specials Unicode block.
  39462. 0xFFF0,
  39463. 0x10000
  39464. ]);
  39465. /**
  39466. * 'Font' is the class the outside world should use, it encapsulate all the font
  39467. * decoding logics whatever type it is (assuming the font type is supported).
  39468. *
  39469. * For example to read a Type1 font and to attach it to the document:
  39470. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  39471. * type1Font.bind();
  39472. */
  39473. var Font = function FontClosure() {
  39474. function Font(name, file, properties) {
  39475. var charCode, glyphName, unicode;
  39476. this.name = name;
  39477. this.loadedName = properties.loadedName;
  39478. this.isType3Font = properties.isType3Font;
  39479. this.sizes = [];
  39480. this.missingFile = false;
  39481. this.glyphCache = Object.create(null);
  39482. var names = name.split('+');
  39483. names = names.length > 1 ? names[1] : names[0];
  39484. names = names.split(/[-,_]/g)[0];
  39485. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  39486. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  39487. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  39488. var type = properties.type;
  39489. var subtype = properties.subtype;
  39490. this.type = type;
  39491. this.fallbackName = this.isMonospace ? 'monospace' : this.isSerifFont ? 'serif' : 'sans-serif';
  39492. this.differences = properties.differences;
  39493. this.widths = properties.widths;
  39494. this.defaultWidth = properties.defaultWidth;
  39495. this.composite = properties.composite;
  39496. this.wideChars = properties.wideChars;
  39497. this.cMap = properties.cMap;
  39498. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  39499. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  39500. this.fontMatrix = properties.fontMatrix;
  39501. this.bbox = properties.bbox;
  39502. this.toUnicode = properties.toUnicode;
  39503. this.toFontChar = [];
  39504. if (properties.type === 'Type3') {
  39505. for (charCode = 0; charCode < 256; charCode++) {
  39506. this.toFontChar[charCode] = this.differences[charCode] || properties.defaultEncoding[charCode];
  39507. }
  39508. this.fontType = FontType.TYPE3;
  39509. return;
  39510. }
  39511. this.cidEncoding = properties.cidEncoding;
  39512. this.vertical = properties.vertical;
  39513. if (this.vertical) {
  39514. this.vmetrics = properties.vmetrics;
  39515. this.defaultVMetrics = properties.defaultVMetrics;
  39516. }
  39517. var glyphsUnicodeMap;
  39518. if (!file || file.isEmpty) {
  39519. if (file) {
  39520. // Some bad PDF generators will include empty font files,
  39521. // attempting to recover by assuming that no file exists.
  39522. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  39523. }
  39524. this.missingFile = true;
  39525. // The file data is not specified. Trying to fix the font name
  39526. // to be used with the canvas.font.
  39527. var fontName = name.replace(/[,_]/g, '-');
  39528. var stdFontMap = getStdFontMap(), nonStdFontMap = getNonStdFontMap();
  39529. var isStandardFont = !!stdFontMap[fontName] || !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  39530. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  39531. this.bold = fontName.search(/bold/gi) !== -1;
  39532. this.italic = fontName.search(/oblique/gi) !== -1 || fontName.search(/italic/gi) !== -1;
  39533. // Use 'name' instead of 'fontName' here because the original
  39534. // name ArialBlack for example will be replaced by Helvetica.
  39535. this.black = name.search(/Black/g) !== -1;
  39536. // if at least one width is present, remeasure all chars when exists
  39537. this.remeasure = Object.keys(this.widths).length > 0;
  39538. if (isStandardFont && type === 'CIDFontType2' && properties.cidEncoding.indexOf('Identity-') === 0) {
  39539. var GlyphMapForStandardFonts = getGlyphMapForStandardFonts();
  39540. // Standard fonts might be embedded as CID font without glyph mapping.
  39541. // Building one based on GlyphMapForStandardFonts.
  39542. var map = [];
  39543. for (charCode in GlyphMapForStandardFonts) {
  39544. map[+charCode] = GlyphMapForStandardFonts[charCode];
  39545. }
  39546. if (/ArialBlack/i.test(name)) {
  39547. var SupplementalGlyphMapForArialBlack = getSupplementalGlyphMapForArialBlack();
  39548. for (charCode in SupplementalGlyphMapForArialBlack) {
  39549. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  39550. }
  39551. }
  39552. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  39553. if (!isIdentityUnicode) {
  39554. this.toUnicode.forEach(function (charCode, unicodeCharCode) {
  39555. map[+charCode] = unicodeCharCode;
  39556. });
  39557. }
  39558. this.toFontChar = map;
  39559. this.toUnicode = new ToUnicodeMap(map);
  39560. } else if (/Symbol/i.test(fontName)) {
  39561. this.toFontChar = buildToFontChar(SymbolSetEncoding, getGlyphsUnicode(), properties.differences);
  39562. } else if (/Dingbats/i.test(fontName)) {
  39563. if (/Wingdings/i.test(name)) {
  39564. warn('Non-embedded Wingdings font, falling back to ZapfDingbats.');
  39565. }
  39566. this.toFontChar = buildToFontChar(ZapfDingbatsEncoding, getDingbatsGlyphsUnicode(), properties.differences);
  39567. } else if (isStandardFont) {
  39568. this.toFontChar = buildToFontChar(properties.defaultEncoding, getGlyphsUnicode(), properties.differences);
  39569. } else {
  39570. glyphsUnicodeMap = getGlyphsUnicode();
  39571. this.toUnicode.forEach(function (charCode, unicodeCharCode) {
  39572. if (!this.composite) {
  39573. glyphName = properties.differences[charCode] || properties.defaultEncoding[charCode];
  39574. unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  39575. if (unicode !== -1) {
  39576. unicodeCharCode = unicode;
  39577. }
  39578. }
  39579. this.toFontChar[charCode] = unicodeCharCode;
  39580. }.bind(this));
  39581. }
  39582. this.loadedName = fontName.split('-')[0];
  39583. this.loading = false;
  39584. this.fontType = getFontType(type, subtype);
  39585. return;
  39586. }
  39587. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  39588. if (subtype === 'Type1C') {
  39589. if (type !== 'Type1' && type !== 'MMType1') {
  39590. // Some TrueType fonts by mistake claim Type1C
  39591. if (isTrueTypeFile(file)) {
  39592. subtype = 'TrueType';
  39593. } else {
  39594. type = 'Type1';
  39595. }
  39596. } else if (isOpenTypeFile(file)) {
  39597. // Sometimes the type/subtype can be a complete lie (see issue7598.pdf).
  39598. type = subtype = 'OpenType';
  39599. }
  39600. }
  39601. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  39602. type = 'CIDFontType0';
  39603. }
  39604. if (subtype === 'OpenType') {
  39605. type = 'OpenType';
  39606. }
  39607. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  39608. if (type === 'CIDFontType0') {
  39609. if (isType1File(file)) {
  39610. subtype = 'CIDFontType0';
  39611. } else if (isOpenTypeFile(file)) {
  39612. // Sometimes the type/subtype can be a complete lie (see issue6782.pdf).
  39613. type = subtype = 'OpenType';
  39614. } else {
  39615. subtype = 'CIDFontType0C';
  39616. }
  39617. }
  39618. var data;
  39619. switch (type) {
  39620. case 'MMType1':
  39621. info('MMType1 font (' + name + '), falling back to Type1.');
  39622. case 'Type1':
  39623. case 'CIDFontType0':
  39624. this.mimetype = 'font/opentype';
  39625. var cff = subtype === 'Type1C' || subtype === 'CIDFontType0C' ? new CFFFont(file, properties) : new Type1Font(name, file, properties);
  39626. adjustWidths(properties);
  39627. // Wrap the CFF data inside an OTF font file
  39628. data = this.convert(name, cff, properties);
  39629. break;
  39630. case 'OpenType':
  39631. case 'TrueType':
  39632. case 'CIDFontType2':
  39633. this.mimetype = 'font/opentype';
  39634. // Repair the TrueType file. It is can be damaged in the point of
  39635. // view of the sanitizer
  39636. data = this.checkAndRepair(name, file, properties);
  39637. if (this.isOpenType) {
  39638. adjustWidths(properties);
  39639. type = 'OpenType';
  39640. }
  39641. break;
  39642. default:
  39643. error('Font ' + type + ' is not supported');
  39644. break;
  39645. }
  39646. this.data = data;
  39647. this.fontType = getFontType(type, subtype);
  39648. // Transfer some properties again that could change during font conversion
  39649. this.fontMatrix = properties.fontMatrix;
  39650. this.widths = properties.widths;
  39651. this.defaultWidth = properties.defaultWidth;
  39652. this.toUnicode = properties.toUnicode;
  39653. this.encoding = properties.baseEncoding;
  39654. this.seacMap = properties.seacMap;
  39655. this.loading = true;
  39656. }
  39657. Font.getFontID = function () {
  39658. var ID = 1;
  39659. return function Font_getFontID() {
  39660. return String(ID++);
  39661. };
  39662. }();
  39663. function int16(b0, b1) {
  39664. return (b0 << 8) + b1;
  39665. }
  39666. function signedInt16(b0, b1) {
  39667. var value = (b0 << 8) + b1;
  39668. return value & 1 << 15 ? value - 0x10000 : value;
  39669. }
  39670. function int32(b0, b1, b2, b3) {
  39671. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  39672. }
  39673. function string16(value) {
  39674. return String.fromCharCode(value >> 8 & 0xff, value & 0xff);
  39675. }
  39676. function safeString16(value) {
  39677. // clamp value to the 16-bit int range
  39678. value = value > 0x7FFF ? 0x7FFF : value < -0x8000 ? -0x8000 : value;
  39679. return String.fromCharCode(value >> 8 & 0xff, value & 0xff);
  39680. }
  39681. function isTrueTypeFile(file) {
  39682. var header = file.peekBytes(4);
  39683. return readUint32(header, 0) === 0x00010000;
  39684. }
  39685. function isOpenTypeFile(file) {
  39686. var header = file.peekBytes(4);
  39687. return bytesToString(header) === 'OTTO';
  39688. }
  39689. function isType1File(file) {
  39690. var header = file.peekBytes(2);
  39691. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  39692. if (header[0] === 0x25 && header[1] === 0x21) {
  39693. return true;
  39694. }
  39695. // ... obviously some fonts violate that part of the specification,
  39696. // please refer to the comment in |Type1Font| below.
  39697. if (header[0] === 0x80 && header[1] === 0x01) {
  39698. // pfb file header.
  39699. return true;
  39700. }
  39701. return false;
  39702. }
  39703. function buildToFontChar(encoding, glyphsUnicodeMap, differences) {
  39704. var toFontChar = [], unicode;
  39705. for (var i = 0, ii = encoding.length; i < ii; i++) {
  39706. unicode = getUnicodeForGlyph(encoding[i], glyphsUnicodeMap);
  39707. if (unicode !== -1) {
  39708. toFontChar[i] = unicode;
  39709. }
  39710. }
  39711. for (var charCode in differences) {
  39712. unicode = getUnicodeForGlyph(differences[charCode], glyphsUnicodeMap);
  39713. if (unicode !== -1) {
  39714. toFontChar[+charCode] = unicode;
  39715. }
  39716. }
  39717. return toFontChar;
  39718. }
  39719. /**
  39720. * Helper function for |adjustMapping|.
  39721. * @return {boolean}
  39722. */
  39723. function isProblematicUnicodeLocation(code) {
  39724. // Using binary search to find a range start.
  39725. var i = 0, j = ProblematicCharRanges.length - 1;
  39726. while (i < j) {
  39727. var c = i + j + 1 >> 1;
  39728. if (code < ProblematicCharRanges[c]) {
  39729. j = c - 1;
  39730. } else {
  39731. i = c;
  39732. }
  39733. }
  39734. // Even index means code in problematic range.
  39735. return !(i & 1);
  39736. }
  39737. /**
  39738. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  39739. * with their unicode value. It also moves char codes that are in known
  39740. * problematic locations.
  39741. * @return {Object} Two properties:
  39742. * 'toFontChar' - maps original char codes(the value that will be read
  39743. * from commands such as show text) to the char codes that will be used in the
  39744. * font that we build
  39745. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  39746. */
  39747. function adjustMapping(charCodeToGlyphId, properties) {
  39748. var toUnicode = properties.toUnicode;
  39749. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  39750. var isIdentityUnicode = properties.toUnicode instanceof IdentityToUnicodeMap;
  39751. var newMap = Object.create(null);
  39752. var toFontChar = [];
  39753. var usedFontCharCodes = [];
  39754. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  39755. for (var originalCharCode in charCodeToGlyphId) {
  39756. originalCharCode |= 0;
  39757. var glyphId = charCodeToGlyphId[originalCharCode];
  39758. var fontCharCode = originalCharCode;
  39759. // First try to map the value to a unicode position if a non identity map
  39760. // was created.
  39761. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  39762. var unicode = toUnicode.get(fontCharCode);
  39763. // TODO: Try to map ligatures to the correct spot.
  39764. if (unicode.length === 1) {
  39765. fontCharCode = unicode.charCodeAt(0);
  39766. }
  39767. }
  39768. // Try to move control characters, special characters and already mapped
  39769. // characters to the private use area since they will not be drawn by
  39770. // canvas if left in their current position. Also, move characters if the
  39771. // font was symbolic and there is only an identity unicode map since the
  39772. // characters probably aren't in the correct position (fixes an issue
  39773. // with firefox and thuluthfont).
  39774. if ((usedFontCharCodes[fontCharCode] !== undefined || isProblematicUnicodeLocation(fontCharCode) || isSymbolic && isIdentityUnicode) && nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) {
  39775. // Room left.
  39776. // Loop to try and find a free spot in the private use area.
  39777. do {
  39778. fontCharCode = nextAvailableFontCharCode++;
  39779. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  39780. fontCharCode = 0xF020;
  39781. nextAvailableFontCharCode = fontCharCode + 1;
  39782. }
  39783. } while (usedFontCharCodes[fontCharCode] !== undefined && nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  39784. }
  39785. newMap[fontCharCode] = glyphId;
  39786. toFontChar[originalCharCode] = fontCharCode;
  39787. usedFontCharCodes[fontCharCode] = true;
  39788. }
  39789. return {
  39790. toFontChar: toFontChar,
  39791. charCodeToGlyphId: newMap,
  39792. nextAvailableFontCharCode: nextAvailableFontCharCode
  39793. };
  39794. }
  39795. function getRanges(glyphs, numGlyphs) {
  39796. // Array.sort() sorts by characters, not numerically, so convert to an
  39797. // array of characters.
  39798. var codes = [];
  39799. for (var charCode in glyphs) {
  39800. // Remove an invalid glyph ID mappings to make OTS happy.
  39801. if (glyphs[charCode] >= numGlyphs) {
  39802. continue;
  39803. }
  39804. codes.push({
  39805. fontCharCode: charCode | 0,
  39806. glyphId: glyphs[charCode]
  39807. });
  39808. }
  39809. codes.sort(function fontGetRangesSort(a, b) {
  39810. return a.fontCharCode - b.fontCharCode;
  39811. });
  39812. // Split the sorted codes into ranges.
  39813. var ranges = [];
  39814. var length = codes.length;
  39815. for (var n = 0; n < length;) {
  39816. var start = codes[n].fontCharCode;
  39817. var codeIndices = [codes[n].glyphId];
  39818. ++n;
  39819. var end = start;
  39820. while (n < length && end + 1 === codes[n].fontCharCode) {
  39821. codeIndices.push(codes[n].glyphId);
  39822. ++end;
  39823. ++n;
  39824. if (end === 0xFFFF) {
  39825. break;
  39826. }
  39827. }
  39828. ranges.push([
  39829. start,
  39830. end,
  39831. codeIndices
  39832. ]);
  39833. }
  39834. return ranges;
  39835. }
  39836. function createCmapTable(glyphs, numGlyphs) {
  39837. var ranges = getRanges(glyphs, numGlyphs);
  39838. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  39839. var cmap = '\x00\x00' + // version
  39840. string16(numTables) + // numTables
  39841. '\x00\x03' + // platformID
  39842. '\x00\x01' + // encodingID
  39843. string32(4 + numTables * 8);
  39844. // start of the table record
  39845. var i, ii, j, jj;
  39846. for (i = ranges.length - 1; i >= 0; --i) {
  39847. if (ranges[i][0] <= 0xFFFF) {
  39848. break;
  39849. }
  39850. }
  39851. var bmpLength = i + 1;
  39852. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  39853. ranges[i][1] = 0xFFFE;
  39854. }
  39855. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  39856. var segCount = bmpLength + trailingRangesCount;
  39857. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  39858. // Fill up the 4 parallel arrays describing the segments.
  39859. var startCount = '';
  39860. var endCount = '';
  39861. var idDeltas = '';
  39862. var idRangeOffsets = '';
  39863. var glyphsIds = '';
  39864. var bias = 0;
  39865. var range, start, end, codes;
  39866. for (i = 0, ii = bmpLength; i < ii; i++) {
  39867. range = ranges[i];
  39868. start = range[0];
  39869. end = range[1];
  39870. startCount += string16(start);
  39871. endCount += string16(end);
  39872. codes = range[2];
  39873. var contiguous = true;
  39874. for (j = 1, jj = codes.length; j < jj; ++j) {
  39875. if (codes[j] !== codes[j - 1] + 1) {
  39876. contiguous = false;
  39877. break;
  39878. }
  39879. }
  39880. if (!contiguous) {
  39881. var offset = (segCount - i) * 2 + bias * 2;
  39882. bias += end - start + 1;
  39883. idDeltas += string16(0);
  39884. idRangeOffsets += string16(offset);
  39885. for (j = 0, jj = codes.length; j < jj; ++j) {
  39886. glyphsIds += string16(codes[j]);
  39887. }
  39888. } else {
  39889. var startCode = codes[0];
  39890. idDeltas += string16(startCode - start & 0xFFFF);
  39891. idRangeOffsets += string16(0);
  39892. }
  39893. }
  39894. if (trailingRangesCount > 0) {
  39895. endCount += '\xFF\xFF';
  39896. startCount += '\xFF\xFF';
  39897. idDeltas += '\x00\x01';
  39898. idRangeOffsets += '\x00\x00';
  39899. }
  39900. var format314 = '\x00\x00' + // language
  39901. string16(2 * segCount) + string16(searchParams.range) + string16(searchParams.entry) + string16(searchParams.rangeShift) + endCount + '\x00\x00' + startCount + idDeltas + idRangeOffsets + glyphsIds;
  39902. var format31012 = '';
  39903. var header31012 = '';
  39904. if (numTables > 1) {
  39905. cmap += '\x00\x03' + // platformID
  39906. '\x00\x0A' + // encodingID
  39907. string32(4 + numTables * 8 + 4 + format314.length);
  39908. // start of the table record
  39909. format31012 = '';
  39910. for (i = 0, ii = ranges.length; i < ii; i++) {
  39911. range = ranges[i];
  39912. start = range[0];
  39913. codes = range[2];
  39914. var code = codes[0];
  39915. for (j = 1, jj = codes.length; j < jj; ++j) {
  39916. if (codes[j] !== codes[j - 1] + 1) {
  39917. end = range[0] + j - 1;
  39918. format31012 += string32(start) + // startCharCode
  39919. string32(end) + // endCharCode
  39920. string32(code);
  39921. // startGlyphID
  39922. start = end + 1;
  39923. code = codes[j];
  39924. }
  39925. }
  39926. format31012 += string32(start) + // startCharCode
  39927. string32(range[1]) + // endCharCode
  39928. string32(code);
  39929. }
  39930. // startGlyphID
  39931. header31012 = '\x00\x0C' + // format
  39932. '\x00\x00' + // reserved
  39933. string32(format31012.length + 16) + // length
  39934. '\x00\x00\x00\x00' + // language
  39935. string32(format31012.length / 12);
  39936. }
  39937. // nGroups
  39938. return cmap + '\x00\x04' + // format
  39939. string16(format314.length + 4) + // length
  39940. format314 + header31012 + format31012;
  39941. }
  39942. function validateOS2Table(os2) {
  39943. var stream = new Stream(os2.data);
  39944. var version = stream.getUint16();
  39945. // TODO verify all OS/2 tables fields, but currently we validate only those
  39946. // that give us issues
  39947. stream.getBytes(60);
  39948. // skipping type, misc sizes, panose, unicode ranges
  39949. var selection = stream.getUint16();
  39950. if (version < 4 && selection & 0x0300) {
  39951. return false;
  39952. }
  39953. var firstChar = stream.getUint16();
  39954. var lastChar = stream.getUint16();
  39955. if (firstChar > lastChar) {
  39956. return false;
  39957. }
  39958. stream.getBytes(6);
  39959. // skipping sTypoAscender/Descender/LineGap
  39960. var usWinAscent = stream.getUint16();
  39961. if (usWinAscent === 0) {
  39962. // makes font unreadable by windows
  39963. return false;
  39964. }
  39965. // OS/2 appears to be valid, resetting some fields
  39966. os2.data[8] = os2.data[9] = 0;
  39967. // IE rejects fonts if fsType != 0
  39968. return true;
  39969. }
  39970. function createOS2Table(properties, charstrings, override) {
  39971. override = override || {
  39972. unitsPerEm: 0,
  39973. yMax: 0,
  39974. yMin: 0,
  39975. ascent: 0,
  39976. descent: 0
  39977. };
  39978. var ulUnicodeRange1 = 0;
  39979. var ulUnicodeRange2 = 0;
  39980. var ulUnicodeRange3 = 0;
  39981. var ulUnicodeRange4 = 0;
  39982. var firstCharIndex = null;
  39983. var lastCharIndex = 0;
  39984. if (charstrings) {
  39985. for (var code in charstrings) {
  39986. code |= 0;
  39987. if (firstCharIndex > code || !firstCharIndex) {
  39988. firstCharIndex = code;
  39989. }
  39990. if (lastCharIndex < code) {
  39991. lastCharIndex = code;
  39992. }
  39993. var position = getUnicodeRangeFor(code);
  39994. if (position < 32) {
  39995. ulUnicodeRange1 |= 1 << position;
  39996. } else if (position < 64) {
  39997. ulUnicodeRange2 |= 1 << position - 32;
  39998. } else if (position < 96) {
  39999. ulUnicodeRange3 |= 1 << position - 64;
  40000. } else if (position < 123) {
  40001. ulUnicodeRange4 |= 1 << position - 96;
  40002. } else {
  40003. error('Unicode ranges Bits > 123 are reserved for internal usage');
  40004. }
  40005. }
  40006. } else {
  40007. // TODO
  40008. firstCharIndex = 0;
  40009. lastCharIndex = 255;
  40010. }
  40011. var bbox = properties.bbox || [
  40012. 0,
  40013. 0,
  40014. 0,
  40015. 0
  40016. ];
  40017. var unitsPerEm = override.unitsPerEm || 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  40018. // if the font units differ to the PDF glyph space units
  40019. // then scale up the values
  40020. var scale = properties.ascentScaled ? 1.0 : unitsPerEm / PDF_GLYPH_SPACE_UNITS;
  40021. var typoAscent = override.ascent || Math.round(scale * (properties.ascent || bbox[3]));
  40022. var typoDescent = override.descent || Math.round(scale * (properties.descent || bbox[1]));
  40023. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  40024. typoDescent = -typoDescent;
  40025. }
  40026. // fixing incorrect descent
  40027. var winAscent = override.yMax || typoAscent;
  40028. var winDescent = -override.yMin || -typoDescent;
  40029. return '\x00\x03' + // version
  40030. '\x02\x24' + // xAvgCharWidth
  40031. '\x01\xF4' + // usWeightClass
  40032. '\x00\x05' + // usWidthClass
  40033. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  40034. '\x02\x8A' + // ySubscriptXSize
  40035. '\x02\xBB' + // ySubscriptYSize
  40036. '\x00\x00' + // ySubscriptXOffset
  40037. '\x00\x8C' + // ySubscriptYOffset
  40038. '\x02\x8A' + // ySuperScriptXSize
  40039. '\x02\xBB' + // ySuperScriptYSize
  40040. '\x00\x00' + // ySuperScriptXOffset
  40041. '\x01\xDF' + // ySuperScriptYOffset
  40042. '\x00\x31' + // yStrikeOutSize
  40043. '\x01\x02' + // yStrikeOutPosition
  40044. '\x00\x00' + // sFamilyClass
  40045. '\x00\x00\x06' + String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) + '\x00\x00\x00\x00\x00\x00' + // Panose
  40046. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  40047. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  40048. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  40049. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  40050. '\x2A\x32\x31\x2A' + // achVendID
  40051. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  40052. string16(firstCharIndex || properties.firstChar) + // usFirstCharIndex
  40053. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  40054. string16(typoAscent) + // sTypoAscender
  40055. string16(typoDescent) + // sTypoDescender
  40056. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  40057. string16(winAscent) + // usWinAscent
  40058. string16(winDescent) + // usWinDescent
  40059. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  40060. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  40061. string16(properties.xHeight) + // sxHeight
  40062. string16(properties.capHeight) + // sCapHeight
  40063. string16(0) + // usDefaultChar
  40064. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  40065. '\x00\x03';
  40066. }
  40067. // usMaxContext
  40068. function createPostTable(properties) {
  40069. var angle = Math.floor(properties.italicAngle * Math.pow(2, 16));
  40070. return '\x00\x03\x00\x00' + // Version number
  40071. string32(angle) + // italicAngle
  40072. '\x00\x00' + // underlinePosition
  40073. '\x00\x00' + // underlineThickness
  40074. string32(properties.fixedPitch) + // isFixedPitch
  40075. '\x00\x00\x00\x00' + // minMemType42
  40076. '\x00\x00\x00\x00' + // maxMemType42
  40077. '\x00\x00\x00\x00' + // minMemType1
  40078. '\x00\x00\x00\x00';
  40079. }
  40080. // maxMemType1
  40081. function createNameTable(name, proto) {
  40082. if (!proto) {
  40083. proto = [
  40084. [],
  40085. []
  40086. ];
  40087. }
  40088. // no strings and unicode strings
  40089. var strings = [
  40090. proto[0][0] || 'Original licence',
  40091. // 0.Copyright
  40092. proto[0][1] || name,
  40093. // 1.Font family
  40094. proto[0][2] || 'Unknown',
  40095. // 2.Font subfamily (font weight)
  40096. proto[0][3] || 'uniqueID',
  40097. // 3.Unique ID
  40098. proto[0][4] || name,
  40099. // 4.Full font name
  40100. proto[0][5] || 'Version 0.11',
  40101. // 5.Version
  40102. proto[0][6] || '',
  40103. // 6.Postscript name
  40104. proto[0][7] || 'Unknown',
  40105. // 7.Trademark
  40106. proto[0][8] || 'Unknown',
  40107. // 8.Manufacturer
  40108. proto[0][9] || 'Unknown'
  40109. ];
  40110. // 9.Designer
  40111. // Mac want 1-byte per character strings while Windows want
  40112. // 2-bytes per character, so duplicate the names table
  40113. var stringsUnicode = [];
  40114. var i, ii, j, jj, str;
  40115. for (i = 0, ii = strings.length; i < ii; i++) {
  40116. str = proto[1][i] || strings[i];
  40117. var strBufUnicode = [];
  40118. for (j = 0, jj = str.length; j < jj; j++) {
  40119. strBufUnicode.push(string16(str.charCodeAt(j)));
  40120. }
  40121. stringsUnicode.push(strBufUnicode.join(''));
  40122. }
  40123. var names = [
  40124. strings,
  40125. stringsUnicode
  40126. ];
  40127. var platforms = [
  40128. '\x00\x01',
  40129. '\x00\x03'
  40130. ];
  40131. var encodings = [
  40132. '\x00\x00',
  40133. '\x00\x01'
  40134. ];
  40135. var languages = [
  40136. '\x00\x00',
  40137. '\x04\x09'
  40138. ];
  40139. var namesRecordCount = strings.length * platforms.length;
  40140. var nameTable = '\x00\x00' + // format
  40141. string16(namesRecordCount) + // Number of names Record
  40142. string16(namesRecordCount * 12 + 6);
  40143. // Storage
  40144. // Build the name records field
  40145. var strOffset = 0;
  40146. for (i = 0, ii = platforms.length; i < ii; i++) {
  40147. var strs = names[i];
  40148. for (j = 0, jj = strs.length; j < jj; j++) {
  40149. str = strs[j];
  40150. var nameRecord = platforms[i] + // platform ID
  40151. encodings[i] + // encoding ID
  40152. languages[i] + // language ID
  40153. string16(j) + // name ID
  40154. string16(str.length) + string16(strOffset);
  40155. nameTable += nameRecord;
  40156. strOffset += str.length;
  40157. }
  40158. }
  40159. nameTable += strings.join('') + stringsUnicode.join('');
  40160. return nameTable;
  40161. }
  40162. Font.prototype = {
  40163. name: null,
  40164. font: null,
  40165. mimetype: null,
  40166. encoding: null,
  40167. get renderer() {
  40168. var renderer = FontRendererFactory.create(this, SEAC_ANALYSIS_ENABLED);
  40169. return shadow(this, 'renderer', renderer);
  40170. },
  40171. exportData: function Font_exportData() {
  40172. // TODO remove enumerating of the properties, e.g. hardcode exact names.
  40173. var data = {};
  40174. for (var i in this) {
  40175. if (this.hasOwnProperty(i)) {
  40176. data[i] = this[i];
  40177. }
  40178. }
  40179. return data;
  40180. },
  40181. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  40182. function readTableEntry(file) {
  40183. var tag = bytesToString(file.getBytes(4));
  40184. var checksum = file.getInt32() >>> 0;
  40185. var offset = file.getInt32() >>> 0;
  40186. var length = file.getInt32() >>> 0;
  40187. // Read the table associated data
  40188. var previousPosition = file.pos;
  40189. file.pos = file.start ? file.start : 0;
  40190. file.skip(offset);
  40191. var data = file.getBytes(length);
  40192. file.pos = previousPosition;
  40193. if (tag === 'head') {
  40194. // clearing checksum adjustment
  40195. data[8] = data[9] = data[10] = data[11] = 0;
  40196. data[17] |= 0x20;
  40197. }
  40198. //Set font optimized for cleartype flag
  40199. return {
  40200. tag: tag,
  40201. checksum: checksum,
  40202. length: length,
  40203. offset: offset,
  40204. data: data
  40205. };
  40206. }
  40207. function readOpenTypeHeader(ttf) {
  40208. return {
  40209. version: bytesToString(ttf.getBytes(4)),
  40210. numTables: ttf.getUint16(),
  40211. searchRange: ttf.getUint16(),
  40212. entrySelector: ttf.getUint16(),
  40213. rangeShift: ttf.getUint16()
  40214. };
  40215. }
  40216. /**
  40217. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  40218. * PDF spec
  40219. */
  40220. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  40221. if (!cmap) {
  40222. warn('No cmap table available.');
  40223. return {
  40224. platformId: -1,
  40225. encodingId: -1,
  40226. mappings: [],
  40227. hasShortCmap: false
  40228. };
  40229. }
  40230. var segment;
  40231. var start = (font.start ? font.start : 0) + cmap.offset;
  40232. font.pos = start;
  40233. var version = font.getUint16();
  40234. var numTables = font.getUint16();
  40235. var potentialTable;
  40236. var canBreak = false;
  40237. // There's an order of preference in terms of which cmap subtable to
  40238. // use:
  40239. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  40240. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  40241. // The following takes advantage of the fact that the tables are sorted
  40242. // to work.
  40243. for (var i = 0; i < numTables; i++) {
  40244. var platformId = font.getUint16();
  40245. var encodingId = font.getUint16();
  40246. var offset = font.getInt32() >>> 0;
  40247. var useTable = false;
  40248. if (platformId === 0 && encodingId === 0) {
  40249. useTable = true;
  40250. } else // Continue the loop since there still may be a higher priority
  40251. // table.
  40252. if (platformId === 1 && encodingId === 0) {
  40253. useTable = true;
  40254. } else // Continue the loop since there still may be a higher priority
  40255. // table.
  40256. if (platformId === 3 && encodingId === 1 && (!isSymbolicFont && hasEncoding || !potentialTable)) {
  40257. useTable = true;
  40258. if (!isSymbolicFont) {
  40259. canBreak = true;
  40260. }
  40261. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  40262. useTable = true;
  40263. canBreak = true;
  40264. }
  40265. if (useTable) {
  40266. potentialTable = {
  40267. platformId: platformId,
  40268. encodingId: encodingId,
  40269. offset: offset
  40270. };
  40271. }
  40272. if (canBreak) {
  40273. break;
  40274. }
  40275. }
  40276. if (potentialTable) {
  40277. font.pos = start + potentialTable.offset;
  40278. }
  40279. if (!potentialTable || font.peekByte() === -1) {
  40280. warn('Could not find a preferred cmap table.');
  40281. return {
  40282. platformId: -1,
  40283. encodingId: -1,
  40284. mappings: [],
  40285. hasShortCmap: false
  40286. };
  40287. }
  40288. var format = font.getUint16();
  40289. var length = font.getUint16();
  40290. var language = font.getUint16();
  40291. var hasShortCmap = false;
  40292. var mappings = [];
  40293. var j, glyphId;
  40294. // TODO(mack): refactor this cmap subtable reading logic out
  40295. if (format === 0) {
  40296. for (j = 0; j < 256; j++) {
  40297. var index = font.getByte();
  40298. if (!index) {
  40299. continue;
  40300. }
  40301. mappings.push({
  40302. charCode: j,
  40303. glyphId: index
  40304. });
  40305. }
  40306. hasShortCmap = true;
  40307. } else if (format === 4) {
  40308. // re-creating the table in format 4 since the encoding
  40309. // might be changed
  40310. var segCount = font.getUint16() >> 1;
  40311. font.getBytes(6);
  40312. // skipping range fields
  40313. var segIndex, segments = [];
  40314. for (segIndex = 0; segIndex < segCount; segIndex++) {
  40315. segments.push({ end: font.getUint16() });
  40316. }
  40317. font.getUint16();
  40318. for (segIndex = 0; segIndex < segCount; segIndex++) {
  40319. segments[segIndex].start = font.getUint16();
  40320. }
  40321. for (segIndex = 0; segIndex < segCount; segIndex++) {
  40322. segments[segIndex].delta = font.getUint16();
  40323. }
  40324. var offsetsCount = 0;
  40325. for (segIndex = 0; segIndex < segCount; segIndex++) {
  40326. segment = segments[segIndex];
  40327. var rangeOffset = font.getUint16();
  40328. if (!rangeOffset) {
  40329. segment.offsetIndex = -1;
  40330. continue;
  40331. }
  40332. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  40333. segment.offsetIndex = offsetIndex;
  40334. offsetsCount = Math.max(offsetsCount, offsetIndex + segment.end - segment.start + 1);
  40335. }
  40336. var offsets = [];
  40337. for (j = 0; j < offsetsCount; j++) {
  40338. offsets.push(font.getUint16());
  40339. }
  40340. for (segIndex = 0; segIndex < segCount; segIndex++) {
  40341. segment = segments[segIndex];
  40342. start = segment.start;
  40343. var end = segment.end;
  40344. var delta = segment.delta;
  40345. offsetIndex = segment.offsetIndex;
  40346. for (j = start; j <= end; j++) {
  40347. if (j === 0xFFFF) {
  40348. continue;
  40349. }
  40350. glyphId = offsetIndex < 0 ? j : offsets[offsetIndex + j - start];
  40351. glyphId = glyphId + delta & 0xFFFF;
  40352. if (glyphId === 0) {
  40353. continue;
  40354. }
  40355. mappings.push({
  40356. charCode: j,
  40357. glyphId: glyphId
  40358. });
  40359. }
  40360. }
  40361. } else if (format === 6) {
  40362. // Format 6 is a 2-bytes dense mapping, which means the font data
  40363. // lives glue together even if they are pretty far in the unicode
  40364. // table. (This looks weird, so I can have missed something), this
  40365. // works on Linux but seems to fails on Mac so let's rewrite the
  40366. // cmap table to a 3-1-4 style
  40367. var firstCode = font.getUint16();
  40368. var entryCount = font.getUint16();
  40369. for (j = 0; j < entryCount; j++) {
  40370. glyphId = font.getUint16();
  40371. var charCode = firstCode + j;
  40372. mappings.push({
  40373. charCode: charCode,
  40374. glyphId: glyphId
  40375. });
  40376. }
  40377. } else {
  40378. warn('cmap table has unsupported format: ' + format);
  40379. return {
  40380. platformId: -1,
  40381. encodingId: -1,
  40382. mappings: [],
  40383. hasShortCmap: false
  40384. };
  40385. }
  40386. // removing duplicate entries
  40387. mappings.sort(function (a, b) {
  40388. return a.charCode - b.charCode;
  40389. });
  40390. for (i = 1; i < mappings.length; i++) {
  40391. if (mappings[i - 1].charCode === mappings[i].charCode) {
  40392. mappings.splice(i, 1);
  40393. i--;
  40394. }
  40395. }
  40396. return {
  40397. platformId: potentialTable.platformId,
  40398. encodingId: potentialTable.encodingId,
  40399. mappings: mappings,
  40400. hasShortCmap: hasShortCmap
  40401. };
  40402. }
  40403. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  40404. if (!header) {
  40405. if (metrics) {
  40406. metrics.data = null;
  40407. }
  40408. return;
  40409. }
  40410. font.pos = (font.start ? font.start : 0) + header.offset;
  40411. font.pos += header.length - 2;
  40412. var numOfMetrics = font.getUint16();
  40413. if (numOfMetrics > numGlyphs) {
  40414. info('The numOfMetrics (' + numOfMetrics + ') should not be ' + 'greater than the numGlyphs (' + numGlyphs + ')');
  40415. // Reduce numOfMetrics if it is greater than numGlyphs
  40416. numOfMetrics = numGlyphs;
  40417. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  40418. header.data[35] = numOfMetrics & 0x00ff;
  40419. }
  40420. var numOfSidebearings = numGlyphs - numOfMetrics;
  40421. var numMissing = numOfSidebearings - (metrics.length - numOfMetrics * 4 >> 1);
  40422. if (numMissing > 0) {
  40423. // For each missing glyph, we set both the width and lsb to 0 (zero).
  40424. // Since we need to add two properties for each glyph, this explains
  40425. // the use of |numMissing * 2| when initializing the typed array.
  40426. var entries = new Uint8Array(metrics.length + numMissing * 2);
  40427. entries.set(metrics.data);
  40428. metrics.data = entries;
  40429. }
  40430. }
  40431. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart, hintsValid) {
  40432. if (sourceEnd - sourceStart <= 12) {
  40433. // glyph with data less than 12 is invalid one
  40434. return 0;
  40435. }
  40436. var glyf = source.subarray(sourceStart, sourceEnd);
  40437. var contoursCount = glyf[0] << 8 | glyf[1];
  40438. if (contoursCount & 0x8000) {
  40439. // complex glyph, writing as is
  40440. dest.set(glyf, destStart);
  40441. return glyf.length;
  40442. }
  40443. var i, j = 10, flagsCount = 0;
  40444. for (i = 0; i < contoursCount; i++) {
  40445. var endPoint = glyf[j] << 8 | glyf[j + 1];
  40446. flagsCount = endPoint + 1;
  40447. j += 2;
  40448. }
  40449. // skipping instructions
  40450. var instructionsStart = j;
  40451. var instructionsLength = glyf[j] << 8 | glyf[j + 1];
  40452. j += 2 + instructionsLength;
  40453. var instructionsEnd = j;
  40454. // validating flags
  40455. var coordinatesLength = 0;
  40456. for (i = 0; i < flagsCount; i++) {
  40457. var flag = glyf[j++];
  40458. if (flag & 0xC0) {
  40459. // reserved flags must be zero, cleaning up
  40460. glyf[j - 1] = flag & 0x3F;
  40461. }
  40462. var xyLength = (flag & 2 ? 1 : flag & 16 ? 0 : 2) + (flag & 4 ? 1 : flag & 32 ? 0 : 2);
  40463. coordinatesLength += xyLength;
  40464. if (flag & 8) {
  40465. var repeat = glyf[j++];
  40466. i += repeat;
  40467. coordinatesLength += repeat * xyLength;
  40468. }
  40469. }
  40470. // glyph without coordinates will be rejected
  40471. if (coordinatesLength === 0) {
  40472. return 0;
  40473. }
  40474. var glyphDataLength = j + coordinatesLength;
  40475. if (glyphDataLength > glyf.length) {
  40476. // not enough data for coordinates
  40477. return 0;
  40478. }
  40479. if (!hintsValid && instructionsLength > 0) {
  40480. dest.set(glyf.subarray(0, instructionsStart), destStart);
  40481. dest.set([
  40482. 0,
  40483. 0
  40484. ], destStart + instructionsStart);
  40485. dest.set(glyf.subarray(instructionsEnd, glyphDataLength), destStart + instructionsStart + 2);
  40486. glyphDataLength -= instructionsLength;
  40487. if (glyf.length - glyphDataLength > 3) {
  40488. glyphDataLength = glyphDataLength + 3 & ~3;
  40489. }
  40490. return glyphDataLength;
  40491. }
  40492. if (glyf.length - glyphDataLength > 3) {
  40493. // truncating and aligning to 4 bytes the long glyph data
  40494. glyphDataLength = glyphDataLength + 3 & ~3;
  40495. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  40496. return glyphDataLength;
  40497. }
  40498. // glyph data is fine
  40499. dest.set(glyf, destStart);
  40500. return glyf.length;
  40501. }
  40502. function sanitizeHead(head, numGlyphs, locaLength) {
  40503. var data = head.data;
  40504. // Validate version:
  40505. // Should always be 0x00010000
  40506. var version = int32(data[0], data[1], data[2], data[3]);
  40507. if (version >> 16 !== 1) {
  40508. info('Attempting to fix invalid version in head table: ' + version);
  40509. data[0] = 0;
  40510. data[1] = 1;
  40511. data[2] = 0;
  40512. data[3] = 0;
  40513. }
  40514. var indexToLocFormat = int16(data[50], data[51]);
  40515. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  40516. info('Attempting to fix invalid indexToLocFormat in head table: ' + indexToLocFormat);
  40517. // The value of indexToLocFormat should be 0 if the loca table
  40518. // consists of short offsets, and should be 1 if the loca table
  40519. // consists of long offsets.
  40520. //
  40521. // The number of entries in the loca table should be numGlyphs + 1.
  40522. //
  40523. // Using this information, we can work backwards to deduce if the
  40524. // size of each offset in the loca table, and thus figure out the
  40525. // appropriate value for indexToLocFormat.
  40526. var numGlyphsPlusOne = numGlyphs + 1;
  40527. if (locaLength === numGlyphsPlusOne << 1) {
  40528. // 0x0000 indicates the loca table consists of short offsets
  40529. data[50] = 0;
  40530. data[51] = 0;
  40531. } else if (locaLength === numGlyphsPlusOne << 2) {
  40532. // 0x0001 indicates the loca table consists of long offsets
  40533. data[50] = 0;
  40534. data[51] = 1;
  40535. } else {
  40536. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  40537. }
  40538. }
  40539. }
  40540. function sanitizeGlyphLocations(loca, glyf, numGlyphs, isGlyphLocationsLong, hintsValid, dupFirstEntry) {
  40541. var itemSize, itemDecode, itemEncode;
  40542. if (isGlyphLocationsLong) {
  40543. itemSize = 4;
  40544. itemDecode = function fontItemDecodeLong(data, offset) {
  40545. return data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3];
  40546. };
  40547. itemEncode = function fontItemEncodeLong(data, offset, value) {
  40548. data[offset] = value >>> 24 & 0xFF;
  40549. data[offset + 1] = value >> 16 & 0xFF;
  40550. data[offset + 2] = value >> 8 & 0xFF;
  40551. data[offset + 3] = value & 0xFF;
  40552. };
  40553. } else {
  40554. itemSize = 2;
  40555. itemDecode = function fontItemDecode(data, offset) {
  40556. return data[offset] << 9 | data[offset + 1] << 1;
  40557. };
  40558. itemEncode = function fontItemEncode(data, offset, value) {
  40559. data[offset] = value >> 9 & 0xFF;
  40560. data[offset + 1] = value >> 1 & 0xFF;
  40561. };
  40562. }
  40563. var locaData = loca.data;
  40564. var locaDataSize = itemSize * (1 + numGlyphs);
  40565. // is loca.data too short or long?
  40566. if (locaData.length !== locaDataSize) {
  40567. locaData = new Uint8Array(locaDataSize);
  40568. locaData.set(loca.data.subarray(0, locaDataSize));
  40569. loca.data = locaData;
  40570. }
  40571. // removing the invalid glyphs
  40572. var oldGlyfData = glyf.data;
  40573. var oldGlyfDataLength = oldGlyfData.length;
  40574. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  40575. var startOffset = itemDecode(locaData, 0);
  40576. var writeOffset = 0;
  40577. var missingGlyphData = Object.create(null);
  40578. itemEncode(locaData, 0, writeOffset);
  40579. var i, j;
  40580. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  40581. var endOffset = itemDecode(locaData, j);
  40582. if (endOffset > oldGlyfDataLength && (oldGlyfDataLength + 3 & ~3) === endOffset) {
  40583. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  40584. // the glyf table size, which makes last glyph out of range.
  40585. endOffset = oldGlyfDataLength;
  40586. }
  40587. if (endOffset > oldGlyfDataLength) {
  40588. // glyph end offset points outside glyf data, rejecting the glyph
  40589. itemEncode(locaData, j, writeOffset);
  40590. startOffset = endOffset;
  40591. continue;
  40592. }
  40593. if (startOffset === endOffset) {
  40594. missingGlyphData[i] = true;
  40595. }
  40596. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset, newGlyfData, writeOffset, hintsValid);
  40597. writeOffset += newLength;
  40598. itemEncode(locaData, j, writeOffset);
  40599. startOffset = endOffset;
  40600. }
  40601. if (writeOffset === 0) {
  40602. // glyf table cannot be empty -- redoing the glyf and loca tables
  40603. // to have single glyph with one point
  40604. var simpleGlyph = new Uint8Array([
  40605. 0,
  40606. 1,
  40607. 0,
  40608. 0,
  40609. 0,
  40610. 0,
  40611. 0,
  40612. 0,
  40613. 0,
  40614. 0,
  40615. 0,
  40616. 0,
  40617. 0,
  40618. 0,
  40619. 49,
  40620. 0
  40621. ]);
  40622. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  40623. itemEncode(locaData, j, simpleGlyph.length);
  40624. }
  40625. glyf.data = simpleGlyph;
  40626. return missingGlyphData;
  40627. }
  40628. if (dupFirstEntry) {
  40629. var firstEntryLength = itemDecode(locaData, itemSize);
  40630. if (newGlyfData.length > firstEntryLength + writeOffset) {
  40631. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  40632. } else {
  40633. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  40634. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  40635. }
  40636. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  40637. itemEncode(loca.data, locaData.length - itemSize, writeOffset + firstEntryLength);
  40638. } else {
  40639. glyf.data = newGlyfData.subarray(0, writeOffset);
  40640. }
  40641. return missingGlyphData;
  40642. }
  40643. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  40644. var start = (font.start ? font.start : 0) + post.offset;
  40645. font.pos = start;
  40646. var length = post.length, end = start + length;
  40647. var version = font.getInt32();
  40648. // skip rest to the tables
  40649. font.getBytes(28);
  40650. var glyphNames;
  40651. var valid = true;
  40652. var i;
  40653. switch (version) {
  40654. case 0x00010000:
  40655. glyphNames = MacStandardGlyphOrdering;
  40656. break;
  40657. case 0x00020000:
  40658. var numGlyphs = font.getUint16();
  40659. if (numGlyphs !== maxpNumGlyphs) {
  40660. valid = false;
  40661. break;
  40662. }
  40663. var glyphNameIndexes = [];
  40664. for (i = 0; i < numGlyphs; ++i) {
  40665. var index = font.getUint16();
  40666. if (index >= 32768) {
  40667. valid = false;
  40668. break;
  40669. }
  40670. glyphNameIndexes.push(index);
  40671. }
  40672. if (!valid) {
  40673. break;
  40674. }
  40675. var customNames = [];
  40676. var strBuf = [];
  40677. while (font.pos < end) {
  40678. var stringLength = font.getByte();
  40679. strBuf.length = stringLength;
  40680. for (i = 0; i < stringLength; ++i) {
  40681. strBuf[i] = String.fromCharCode(font.getByte());
  40682. }
  40683. customNames.push(strBuf.join(''));
  40684. }
  40685. glyphNames = [];
  40686. for (i = 0; i < numGlyphs; ++i) {
  40687. var j = glyphNameIndexes[i];
  40688. if (j < 258) {
  40689. glyphNames.push(MacStandardGlyphOrdering[j]);
  40690. continue;
  40691. }
  40692. glyphNames.push(customNames[j - 258]);
  40693. }
  40694. break;
  40695. case 0x00030000:
  40696. break;
  40697. default:
  40698. warn('Unknown/unsupported post table version ' + version);
  40699. valid = false;
  40700. if (properties.defaultEncoding) {
  40701. glyphNames = properties.defaultEncoding;
  40702. }
  40703. break;
  40704. }
  40705. properties.glyphNames = glyphNames;
  40706. return valid;
  40707. }
  40708. function readNameTable(nameTable) {
  40709. var start = (font.start ? font.start : 0) + nameTable.offset;
  40710. font.pos = start;
  40711. var names = [
  40712. [],
  40713. []
  40714. ];
  40715. var length = nameTable.length, end = start + length;
  40716. var format = font.getUint16();
  40717. var FORMAT_0_HEADER_LENGTH = 6;
  40718. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  40719. // unsupported name table format or table "too" small
  40720. return names;
  40721. }
  40722. var numRecords = font.getUint16();
  40723. var stringsStart = font.getUint16();
  40724. var records = [];
  40725. var NAME_RECORD_LENGTH = 12;
  40726. var i, ii;
  40727. for (i = 0; i < numRecords && font.pos + NAME_RECORD_LENGTH <= end; i++) {
  40728. var r = {
  40729. platform: font.getUint16(),
  40730. encoding: font.getUint16(),
  40731. language: font.getUint16(),
  40732. name: font.getUint16(),
  40733. length: font.getUint16(),
  40734. offset: font.getUint16()
  40735. };
  40736. // using only Macintosh and Windows platform/encoding names
  40737. if (r.platform === 1 && r.encoding === 0 && r.language === 0 || r.platform === 3 && r.encoding === 1 && r.language === 0x409) {
  40738. records.push(r);
  40739. }
  40740. }
  40741. for (i = 0, ii = records.length; i < ii; i++) {
  40742. var record = records[i];
  40743. if (record.length <= 0) {
  40744. continue;
  40745. }
  40746. // Nothing to process, ignoring.
  40747. var pos = start + stringsStart + record.offset;
  40748. if (pos + record.length > end) {
  40749. continue;
  40750. }
  40751. // outside of name table, ignoring
  40752. font.pos = pos;
  40753. var nameIndex = record.name;
  40754. if (record.encoding) {
  40755. // unicode
  40756. var str = '';
  40757. for (var j = 0, jj = record.length; j < jj; j += 2) {
  40758. str += String.fromCharCode(font.getUint16());
  40759. }
  40760. names[1][nameIndex] = str;
  40761. } else {
  40762. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  40763. }
  40764. }
  40765. return names;
  40766. }
  40767. var TTOpsStackDeltas = [
  40768. 0,
  40769. 0,
  40770. 0,
  40771. 0,
  40772. 0,
  40773. 0,
  40774. 0,
  40775. 0,
  40776. -2,
  40777. -2,
  40778. -2,
  40779. -2,
  40780. 0,
  40781. 0,
  40782. -2,
  40783. -5,
  40784. -1,
  40785. -1,
  40786. -1,
  40787. -1,
  40788. -1,
  40789. -1,
  40790. -1,
  40791. -1,
  40792. 0,
  40793. 0,
  40794. -1,
  40795. 0,
  40796. -1,
  40797. -1,
  40798. -1,
  40799. -1,
  40800. 1,
  40801. -1,
  40802. -999,
  40803. 0,
  40804. 1,
  40805. 0,
  40806. -1,
  40807. -2,
  40808. 0,
  40809. -1,
  40810. -2,
  40811. -1,
  40812. -1,
  40813. 0,
  40814. -1,
  40815. -1,
  40816. 0,
  40817. 0,
  40818. -999,
  40819. -999,
  40820. -1,
  40821. -1,
  40822. -1,
  40823. -1,
  40824. -2,
  40825. -999,
  40826. -2,
  40827. -2,
  40828. -999,
  40829. 0,
  40830. -2,
  40831. -2,
  40832. 0,
  40833. 0,
  40834. -2,
  40835. 0,
  40836. -2,
  40837. 0,
  40838. 0,
  40839. 0,
  40840. -2,
  40841. -1,
  40842. -1,
  40843. 1,
  40844. 1,
  40845. 0,
  40846. 0,
  40847. -1,
  40848. -1,
  40849. -1,
  40850. -1,
  40851. -1,
  40852. -1,
  40853. -1,
  40854. 0,
  40855. 0,
  40856. -1,
  40857. 0,
  40858. -1,
  40859. -1,
  40860. 0,
  40861. -999,
  40862. -1,
  40863. -1,
  40864. -1,
  40865. -1,
  40866. -1,
  40867. -1,
  40868. 0,
  40869. 0,
  40870. 0,
  40871. 0,
  40872. 0,
  40873. 0,
  40874. 0,
  40875. 0,
  40876. 0,
  40877. 0,
  40878. 0,
  40879. 0,
  40880. -2,
  40881. -999,
  40882. -999,
  40883. -999,
  40884. -999,
  40885. -999,
  40886. -1,
  40887. -1,
  40888. -2,
  40889. -2,
  40890. 0,
  40891. 0,
  40892. 0,
  40893. 0,
  40894. -1,
  40895. -1,
  40896. -999,
  40897. -2,
  40898. -2,
  40899. 0,
  40900. 0,
  40901. -1,
  40902. -2,
  40903. -2,
  40904. 0,
  40905. 0,
  40906. 0,
  40907. -1,
  40908. -1,
  40909. -1,
  40910. -2
  40911. ];
  40912. // 0xC0-DF == -1 and 0xE0-FF == -2
  40913. function sanitizeTTProgram(table, ttContext) {
  40914. var data = table.data;
  40915. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  40916. var stack = [];
  40917. var callstack = [];
  40918. var functionsCalled = [];
  40919. var tooComplexToFollowFunctions = ttContext.tooComplexToFollowFunctions;
  40920. var inFDEF = false, ifLevel = 0, inELSE = 0;
  40921. for (var ii = data.length; i < ii;) {
  40922. var op = data[i++];
  40923. // The TrueType instruction set docs can be found at
  40924. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  40925. if (op === 0x40) {
  40926. // NPUSHB - pushes n bytes
  40927. n = data[i++];
  40928. if (inFDEF || inELSE) {
  40929. i += n;
  40930. } else {
  40931. for (j = 0; j < n; j++) {
  40932. stack.push(data[i++]);
  40933. }
  40934. }
  40935. } else if (op === 0x41) {
  40936. // NPUSHW - pushes n words
  40937. n = data[i++];
  40938. if (inFDEF || inELSE) {
  40939. i += n * 2;
  40940. } else {
  40941. for (j = 0; j < n; j++) {
  40942. b = data[i++];
  40943. stack.push(b << 8 | data[i++]);
  40944. }
  40945. }
  40946. } else if ((op & 0xF8) === 0xB0) {
  40947. // PUSHB - pushes bytes
  40948. n = op - 0xB0 + 1;
  40949. if (inFDEF || inELSE) {
  40950. i += n;
  40951. } else {
  40952. for (j = 0; j < n; j++) {
  40953. stack.push(data[i++]);
  40954. }
  40955. }
  40956. } else if ((op & 0xF8) === 0xB8) {
  40957. // PUSHW - pushes words
  40958. n = op - 0xB8 + 1;
  40959. if (inFDEF || inELSE) {
  40960. i += n * 2;
  40961. } else {
  40962. for (j = 0; j < n; j++) {
  40963. b = data[i++];
  40964. stack.push(b << 8 | data[i++]);
  40965. }
  40966. }
  40967. } else if (op === 0x2B && !tooComplexToFollowFunctions) {
  40968. // CALL
  40969. if (!inFDEF && !inELSE) {
  40970. // collecting inforamtion about which functions are used
  40971. funcId = stack[stack.length - 1];
  40972. ttContext.functionsUsed[funcId] = true;
  40973. if (funcId in ttContext.functionsStackDeltas) {
  40974. stack.length += ttContext.functionsStackDeltas[funcId];
  40975. } else if (funcId in ttContext.functionsDefined && functionsCalled.indexOf(funcId) < 0) {
  40976. callstack.push({
  40977. data: data,
  40978. i: i,
  40979. stackTop: stack.length - 1
  40980. });
  40981. functionsCalled.push(funcId);
  40982. pc = ttContext.functionsDefined[funcId];
  40983. if (!pc) {
  40984. warn('TT: CALL non-existent function');
  40985. ttContext.hintsValid = false;
  40986. return;
  40987. }
  40988. data = pc.data;
  40989. i = pc.i;
  40990. }
  40991. }
  40992. } else if (op === 0x2C && !tooComplexToFollowFunctions) {
  40993. // FDEF
  40994. if (inFDEF || inELSE) {
  40995. warn('TT: nested FDEFs not allowed');
  40996. tooComplexToFollowFunctions = true;
  40997. }
  40998. inFDEF = true;
  40999. // collecting inforamtion about which functions are defined
  41000. lastDeff = i;
  41001. funcId = stack.pop();
  41002. ttContext.functionsDefined[funcId] = {
  41003. data: data,
  41004. i: i
  41005. };
  41006. } else if (op === 0x2D) {
  41007. // ENDF - end of function
  41008. if (inFDEF) {
  41009. inFDEF = false;
  41010. lastEndf = i;
  41011. } else {
  41012. pc = callstack.pop();
  41013. if (!pc) {
  41014. warn('TT: ENDF bad stack');
  41015. ttContext.hintsValid = false;
  41016. return;
  41017. }
  41018. funcId = functionsCalled.pop();
  41019. data = pc.data;
  41020. i = pc.i;
  41021. ttContext.functionsStackDeltas[funcId] = stack.length - pc.stackTop;
  41022. }
  41023. } else if (op === 0x89) {
  41024. // IDEF - instruction definition
  41025. if (inFDEF || inELSE) {
  41026. warn('TT: nested IDEFs not allowed');
  41027. tooComplexToFollowFunctions = true;
  41028. }
  41029. inFDEF = true;
  41030. // recording it as a function to track ENDF
  41031. lastDeff = i;
  41032. } else if (op === 0x58) {
  41033. // IF
  41034. ++ifLevel;
  41035. } else if (op === 0x1B) {
  41036. // ELSE
  41037. inELSE = ifLevel;
  41038. } else if (op === 0x59) {
  41039. // EIF
  41040. if (inELSE === ifLevel) {
  41041. inELSE = 0;
  41042. }
  41043. --ifLevel;
  41044. } else if (op === 0x1C) {
  41045. // JMPR
  41046. if (!inFDEF && !inELSE) {
  41047. var offset = stack[stack.length - 1];
  41048. // only jumping forward to prevent infinite loop
  41049. if (offset > 0) {
  41050. i += offset - 1;
  41051. }
  41052. }
  41053. }
  41054. // Adjusting stack not extactly, but just enough to get function id
  41055. if (!inFDEF && !inELSE) {
  41056. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] : op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  41057. if (op >= 0x71 && op <= 0x75) {
  41058. n = stack.pop();
  41059. if (n === n) {
  41060. stackDelta = -n * 2;
  41061. }
  41062. }
  41063. while (stackDelta < 0 && stack.length > 0) {
  41064. stack.pop();
  41065. stackDelta++;
  41066. }
  41067. while (stackDelta > 0) {
  41068. stack.push(NaN);
  41069. // pushing any number into stack
  41070. stackDelta--;
  41071. }
  41072. }
  41073. }
  41074. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  41075. var content = [data];
  41076. if (i > data.length) {
  41077. content.push(new Uint8Array(i - data.length));
  41078. }
  41079. if (lastDeff > lastEndf) {
  41080. warn('TT: complementing a missing function tail');
  41081. // new function definition started, but not finished
  41082. // complete function by [CLEAR, ENDF]
  41083. content.push(new Uint8Array([
  41084. 0x22,
  41085. 0x2D
  41086. ]));
  41087. }
  41088. foldTTTable(table, content);
  41089. }
  41090. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  41091. if (ttContext.tooComplexToFollowFunctions) {
  41092. return;
  41093. }
  41094. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  41095. warn('TT: more functions defined than expected');
  41096. ttContext.hintsValid = false;
  41097. return;
  41098. }
  41099. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  41100. if (j > maxFunctionDefs) {
  41101. warn('TT: invalid function id: ' + j);
  41102. ttContext.hintsValid = false;
  41103. return;
  41104. }
  41105. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  41106. warn('TT: undefined function: ' + j);
  41107. ttContext.hintsValid = false;
  41108. return;
  41109. }
  41110. }
  41111. }
  41112. function foldTTTable(table, content) {
  41113. if (content.length > 1) {
  41114. // concatenating the content items
  41115. var newLength = 0;
  41116. var j, jj;
  41117. for (j = 0, jj = content.length; j < jj; j++) {
  41118. newLength += content[j].length;
  41119. }
  41120. newLength = newLength + 3 & ~3;
  41121. var result = new Uint8Array(newLength);
  41122. var pos = 0;
  41123. for (j = 0, jj = content.length; j < jj; j++) {
  41124. result.set(content[j], pos);
  41125. pos += content[j].length;
  41126. }
  41127. table.data = result;
  41128. table.length = newLength;
  41129. }
  41130. }
  41131. function sanitizeTTPrograms(fpgm, prep, cvt, maxFunctionDefs) {
  41132. var ttContext = {
  41133. functionsDefined: [],
  41134. functionsUsed: [],
  41135. functionsStackDeltas: [],
  41136. tooComplexToFollowFunctions: false,
  41137. hintsValid: true
  41138. };
  41139. if (fpgm) {
  41140. sanitizeTTProgram(fpgm, ttContext);
  41141. }
  41142. if (prep) {
  41143. sanitizeTTProgram(prep, ttContext);
  41144. }
  41145. if (fpgm) {
  41146. checkInvalidFunctions(ttContext, maxFunctionDefs);
  41147. }
  41148. if (cvt && cvt.length & 1) {
  41149. var cvtData = new Uint8Array(cvt.length + 1);
  41150. cvtData.set(cvt.data);
  41151. cvt.data = cvtData;
  41152. }
  41153. return ttContext.hintsValid;
  41154. }
  41155. // The following steps modify the original font data, making copy
  41156. font = new Stream(new Uint8Array(font.getBytes()));
  41157. var VALID_TABLES = [
  41158. 'OS/2',
  41159. 'cmap',
  41160. 'head',
  41161. 'hhea',
  41162. 'hmtx',
  41163. 'maxp',
  41164. 'name',
  41165. 'post',
  41166. 'loca',
  41167. 'glyf',
  41168. 'fpgm',
  41169. 'prep',
  41170. 'cvt ',
  41171. 'CFF '
  41172. ];
  41173. var header = readOpenTypeHeader(font);
  41174. var numTables = header.numTables;
  41175. var cff, cffFile;
  41176. var tables = Object.create(null);
  41177. tables['OS/2'] = null;
  41178. tables['cmap'] = null;
  41179. tables['head'] = null;
  41180. tables['hhea'] = null;
  41181. tables['hmtx'] = null;
  41182. tables['maxp'] = null;
  41183. tables['name'] = null;
  41184. tables['post'] = null;
  41185. var table;
  41186. for (var i = 0; i < numTables; i++) {
  41187. table = readTableEntry(font);
  41188. if (VALID_TABLES.indexOf(table.tag) < 0) {
  41189. continue;
  41190. }
  41191. // skipping table if it's not a required or optional table
  41192. if (table.length === 0) {
  41193. continue;
  41194. }
  41195. // skipping empty tables
  41196. tables[table.tag] = table;
  41197. }
  41198. var isTrueType = !tables['CFF '];
  41199. if (!isTrueType) {
  41200. // OpenType font
  41201. if (header.version === 'OTTO' && properties.type !== 'CIDFontType2' || !tables['head'] || !tables['hhea'] || !tables['maxp'] || !tables['post']) {
  41202. // no major tables: throwing everything at CFFFont
  41203. cffFile = new Stream(tables['CFF '].data);
  41204. cff = new CFFFont(cffFile, properties);
  41205. adjustWidths(properties);
  41206. return this.convert(name, cff, properties);
  41207. }
  41208. delete tables['glyf'];
  41209. delete tables['loca'];
  41210. delete tables['fpgm'];
  41211. delete tables['prep'];
  41212. delete tables['cvt '];
  41213. this.isOpenType = true;
  41214. } else {
  41215. if (!tables['loca']) {
  41216. error('Required "loca" table is not found');
  41217. }
  41218. if (!tables['glyf']) {
  41219. warn('Required "glyf" table is not found -- trying to recover.');
  41220. // Note: We use `sanitizeGlyphLocations` to add dummy glyf data below.
  41221. tables['glyf'] = {
  41222. tag: 'glyf',
  41223. data: new Uint8Array(0)
  41224. };
  41225. }
  41226. this.isOpenType = false;
  41227. }
  41228. if (!tables['maxp']) {
  41229. error('Required "maxp" table is not found');
  41230. }
  41231. font.pos = (font.start || 0) + tables['maxp'].offset;
  41232. var version = font.getInt32();
  41233. var numGlyphs = font.getUint16();
  41234. var maxFunctionDefs = 0;
  41235. if (version >= 0x00010000 && tables['maxp'].length >= 22) {
  41236. // maxZones can be invalid
  41237. font.pos += 8;
  41238. var maxZones = font.getUint16();
  41239. if (maxZones > 2) {
  41240. // reset to 2 if font has invalid maxZones
  41241. tables['maxp'].data[14] = 0;
  41242. tables['maxp'].data[15] = 2;
  41243. }
  41244. font.pos += 4;
  41245. maxFunctionDefs = font.getUint16();
  41246. }
  41247. var dupFirstEntry = false;
  41248. if (properties.type === 'CIDFontType2' && properties.toUnicode && properties.toUnicode.get(0) > '\u0000') {
  41249. // oracle's defect (see 3427), duplicating first entry
  41250. dupFirstEntry = true;
  41251. numGlyphs++;
  41252. tables['maxp'].data[4] = numGlyphs >> 8;
  41253. tables['maxp'].data[5] = numGlyphs & 255;
  41254. }
  41255. var hintsValid = sanitizeTTPrograms(tables['fpgm'], tables['prep'], tables['cvt '], maxFunctionDefs);
  41256. if (!hintsValid) {
  41257. delete tables['fpgm'];
  41258. delete tables['prep'];
  41259. delete tables['cvt '];
  41260. }
  41261. // Ensure the hmtx table contains the advance width and
  41262. // sidebearings information for numGlyphs in the maxp table
  41263. sanitizeMetrics(font, tables['hhea'], tables['hmtx'], numGlyphs);
  41264. if (!tables['head']) {
  41265. error('Required "head" table is not found');
  41266. }
  41267. sanitizeHead(tables['head'], numGlyphs, isTrueType ? tables['loca'].length : 0);
  41268. var missingGlyphs = Object.create(null);
  41269. if (isTrueType) {
  41270. var isGlyphLocationsLong = int16(tables['head'].data[50], tables['head'].data[51]);
  41271. missingGlyphs = sanitizeGlyphLocations(tables['loca'], tables['glyf'], numGlyphs, isGlyphLocationsLong, hintsValid, dupFirstEntry);
  41272. }
  41273. if (!tables['hhea']) {
  41274. error('Required "hhea" table is not found');
  41275. }
  41276. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  41277. // Sometimes it's 0. That needs to be fixed
  41278. if (tables['hhea'].data[10] === 0 && tables['hhea'].data[11] === 0) {
  41279. tables['hhea'].data[10] = 0xFF;
  41280. tables['hhea'].data[11] = 0xFF;
  41281. }
  41282. // Extract some more font properties from the OpenType head and
  41283. // hhea tables; yMin and descent value are always negative.
  41284. var metricsOverride = {
  41285. unitsPerEm: int16(tables['head'].data[18], tables['head'].data[19]),
  41286. yMax: int16(tables['head'].data[42], tables['head'].data[43]),
  41287. yMin: signedInt16(tables['head'].data[38], tables['head'].data[39]),
  41288. ascent: int16(tables['hhea'].data[4], tables['hhea'].data[5]),
  41289. descent: signedInt16(tables['hhea'].data[6], tables['hhea'].data[7])
  41290. };
  41291. // PDF FontDescriptor metrics lie -- using data from actual font.
  41292. this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
  41293. this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
  41294. // The 'post' table has glyphs names.
  41295. if (tables['post']) {
  41296. var valid = readPostScriptTable(tables['post'], properties, numGlyphs);
  41297. if (!valid) {
  41298. tables['post'] = null;
  41299. }
  41300. }
  41301. var charCodeToGlyphId = [], charCode;
  41302. var toUnicode = properties.toUnicode, widths = properties.widths;
  41303. var skipToUnicode = toUnicode instanceof IdentityToUnicodeMap || toUnicode.length === 0x10000;
  41304. // Helper function to try to skip mapping of empty glyphs.
  41305. // Note: In some cases, just relying on the glyph data doesn't work,
  41306. // hence we also use a few heuristics to fix various PDF files.
  41307. function hasGlyph(glyphId, charCode, widthCode) {
  41308. if (!missingGlyphs[glyphId]) {
  41309. return true;
  41310. }
  41311. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  41312. return true;
  41313. }
  41314. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  41315. return true;
  41316. }
  41317. return false;
  41318. }
  41319. if (properties.type === 'CIDFontType2') {
  41320. var cidToGidMap = properties.cidToGidMap || [];
  41321. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  41322. properties.cMap.forEach(function (charCode, cid) {
  41323. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  41324. var glyphId = -1;
  41325. if (isCidToGidMapEmpty) {
  41326. glyphId = cid;
  41327. } else if (cidToGidMap[cid] !== undefined) {
  41328. glyphId = cidToGidMap[cid];
  41329. }
  41330. if (glyphId >= 0 && glyphId < numGlyphs && hasGlyph(glyphId, charCode, cid)) {
  41331. charCodeToGlyphId[charCode] = glyphId;
  41332. }
  41333. });
  41334. if (dupFirstEntry && (isCidToGidMapEmpty || !charCodeToGlyphId[0])) {
  41335. // We don't duplicate the first entry in the `charCodeToGlyphId` map
  41336. // if the font has a `CIDToGIDMap` which has already mapped the first
  41337. // entry to a non-zero `glyphId` (fixes issue7544.pdf).
  41338. charCodeToGlyphId[0] = numGlyphs - 1;
  41339. }
  41340. } else {
  41341. // Most of the following logic in this code branch is based on the
  41342. // 9.6.6.4 of the PDF spec.
  41343. var cmapTable = readCmapTable(tables['cmap'], font, this.isSymbolicFont, properties.hasEncoding);
  41344. var cmapPlatformId = cmapTable.platformId;
  41345. var cmapEncodingId = cmapTable.encodingId;
  41346. var cmapMappings = cmapTable.mappings;
  41347. var cmapMappingsLength = cmapMappings.length;
  41348. // The spec seems to imply that if the font is symbolic the encoding
  41349. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  41350. // where the the font is symbolic and it has an encoding.
  41351. if (properties.hasEncoding && (cmapPlatformId === 3 && cmapEncodingId === 1 || cmapPlatformId === 1 && cmapEncodingId === 0) || cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  41352. !!getEncoding(properties.baseEncodingName)) {
  41353. // Temporary hack
  41354. // When no preferred cmap table was found and |baseEncodingName| is
  41355. // one of the predefined encodings, we seem to obtain a better
  41356. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  41357. // TODO: Note that this is a hack which should be removed as soon as
  41358. // we have proper support for more exotic cmap tables.
  41359. var baseEncoding = [];
  41360. if (properties.baseEncodingName === 'MacRomanEncoding' || properties.baseEncodingName === 'WinAnsiEncoding') {
  41361. baseEncoding = getEncoding(properties.baseEncodingName);
  41362. }
  41363. var glyphsUnicodeMap = getGlyphsUnicode();
  41364. for (charCode = 0; charCode < 256; charCode++) {
  41365. var glyphName, standardGlyphName;
  41366. if (this.differences && charCode in this.differences) {
  41367. glyphName = this.differences[charCode];
  41368. } else if (charCode in baseEncoding && baseEncoding[charCode] !== '') {
  41369. glyphName = baseEncoding[charCode];
  41370. } else {
  41371. glyphName = StandardEncoding[charCode];
  41372. }
  41373. if (!glyphName) {
  41374. continue;
  41375. }
  41376. // Ensure that non-standard glyph names are resolved to valid ones.
  41377. standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
  41378. var unicodeOrCharCode, isUnicode = false;
  41379. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  41380. unicodeOrCharCode = glyphsUnicodeMap[standardGlyphName];
  41381. isUnicode = true;
  41382. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  41383. // TODO: the encoding needs to be updated with mac os table.
  41384. unicodeOrCharCode = MacRomanEncoding.indexOf(standardGlyphName);
  41385. }
  41386. var found = false;
  41387. for (i = 0; i < cmapMappingsLength; ++i) {
  41388. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  41389. continue;
  41390. }
  41391. var code = isUnicode ? charCode : unicodeOrCharCode;
  41392. if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
  41393. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  41394. found = true;
  41395. break;
  41396. }
  41397. }
  41398. if (!found && properties.glyphNames) {
  41399. // Try to map using the post table.
  41400. var glyphId = properties.glyphNames.indexOf(glyphName);
  41401. // The post table ought to use the same kind of glyph names as the
  41402. // `differences` array, but check the standard ones as a fallback.
  41403. if (glyphId === -1 && standardGlyphName !== glyphName) {
  41404. glyphId = properties.glyphNames.indexOf(standardGlyphName);
  41405. }
  41406. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  41407. charCodeToGlyphId[charCode] = glyphId;
  41408. found = true;
  41409. }
  41410. }
  41411. if (!found) {
  41412. charCodeToGlyphId[charCode] = 0;
  41413. }
  41414. }
  41415. } else // notdef
  41416. if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  41417. // Default Unicode semantics, use the charcodes as is.
  41418. for (i = 0; i < cmapMappingsLength; ++i) {
  41419. charCodeToGlyphId[cmapMappings[i].charCode] = cmapMappings[i].glyphId;
  41420. }
  41421. } else {
  41422. // For (3, 0) cmap tables:
  41423. // The charcode key being stored in charCodeToGlyphId is the lower
  41424. // byte of the two-byte charcodes of the cmap table since according to
  41425. // the spec: 'each byte from the string shall be prepended with the
  41426. // high byte of the range [of charcodes in the cmap table], to form
  41427. // a two-byte character, which shall be used to select the
  41428. // associated glyph description from the subtable'.
  41429. //
  41430. // For (1, 0) cmap tables:
  41431. // 'single bytes from the string shall be used to look up the
  41432. // associated glyph descriptions from the subtable'. This means
  41433. // charcodes in the cmap will be single bytes, so no-op since
  41434. // glyph.charCode & 0xFF === glyph.charCode
  41435. for (i = 0; i < cmapMappingsLength; ++i) {
  41436. charCode = cmapMappings[i].charCode & 0xFF;
  41437. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  41438. }
  41439. }
  41440. }
  41441. if (charCodeToGlyphId.length === 0) {
  41442. // defines at least one glyph
  41443. charCodeToGlyphId[0] = 0;
  41444. }
  41445. // Converting glyphs and ids into font's cmap table
  41446. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  41447. this.toFontChar = newMapping.toFontChar;
  41448. tables['cmap'] = {
  41449. tag: 'cmap',
  41450. data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphs)
  41451. };
  41452. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  41453. tables['OS/2'] = {
  41454. tag: 'OS/2',
  41455. data: createOS2Table(properties, newMapping.charCodeToGlyphId, metricsOverride)
  41456. };
  41457. }
  41458. // Rewrite the 'post' table if needed
  41459. if (!tables['post']) {
  41460. tables['post'] = {
  41461. tag: 'post',
  41462. data: createPostTable(properties)
  41463. };
  41464. }
  41465. if (!isTrueType) {
  41466. try {
  41467. // Trying to repair CFF file
  41468. cffFile = new Stream(tables['CFF '].data);
  41469. var parser = new CFFParser(cffFile, properties, SEAC_ANALYSIS_ENABLED);
  41470. cff = parser.parse();
  41471. var compiler = new CFFCompiler(cff);
  41472. tables['CFF '].data = compiler.compile();
  41473. } catch (e) {
  41474. warn('Failed to compile font ' + properties.loadedName);
  41475. }
  41476. }
  41477. // Re-creating 'name' table
  41478. if (!tables['name']) {
  41479. tables['name'] = {
  41480. tag: 'name',
  41481. data: createNameTable(this.name)
  41482. };
  41483. } else {
  41484. // ... using existing 'name' table as prototype
  41485. var namePrototype = readNameTable(tables['name']);
  41486. tables['name'].data = createNameTable(name, namePrototype);
  41487. }
  41488. var builder = new OpenTypeFileBuilder(header.version);
  41489. for (var tableTag in tables) {
  41490. builder.addTable(tableTag, tables[tableTag].data);
  41491. }
  41492. return builder.toArray();
  41493. },
  41494. convert: function Font_convert(fontName, font, properties) {
  41495. // TODO: Check the charstring widths to determine this.
  41496. properties.fixedPitch = false;
  41497. if (properties.builtInEncoding) {
  41498. // For Type1 fonts that do not include either `ToUnicode` or `Encoding`
  41499. // data, attempt to use the `builtInEncoding` to improve text selection.
  41500. adjustToUnicode(properties, properties.builtInEncoding);
  41501. }
  41502. var mapping = font.getGlyphMapping(properties);
  41503. var newMapping = adjustMapping(mapping, properties);
  41504. this.toFontChar = newMapping.toFontChar;
  41505. var numGlyphs = font.numGlyphs;
  41506. function getCharCodes(charCodeToGlyphId, glyphId) {
  41507. var charCodes = null;
  41508. for (var charCode in charCodeToGlyphId) {
  41509. if (glyphId === charCodeToGlyphId[charCode]) {
  41510. if (!charCodes) {
  41511. charCodes = [];
  41512. }
  41513. charCodes.push(charCode | 0);
  41514. }
  41515. }
  41516. return charCodes;
  41517. }
  41518. function createCharCode(charCodeToGlyphId, glyphId) {
  41519. for (var charCode in charCodeToGlyphId) {
  41520. if (glyphId === charCodeToGlyphId[charCode]) {
  41521. return charCode | 0;
  41522. }
  41523. }
  41524. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] = glyphId;
  41525. return newMapping.nextAvailableFontCharCode++;
  41526. }
  41527. var seacs = font.seacs;
  41528. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  41529. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  41530. var charset = font.getCharset();
  41531. var seacMap = Object.create(null);
  41532. for (var glyphId in seacs) {
  41533. glyphId |= 0;
  41534. var seac = seacs[glyphId];
  41535. var baseGlyphName = StandardEncoding[seac[2]];
  41536. var accentGlyphName = StandardEncoding[seac[3]];
  41537. var baseGlyphId = charset.indexOf(baseGlyphName);
  41538. var accentGlyphId = charset.indexOf(accentGlyphName);
  41539. if (baseGlyphId < 0 || accentGlyphId < 0) {
  41540. continue;
  41541. }
  41542. var accentOffset = {
  41543. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  41544. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  41545. };
  41546. var charCodes = getCharCodes(mapping, glyphId);
  41547. if (!charCodes) {
  41548. // There's no point in mapping it if the char code was never mapped
  41549. // to begin with.
  41550. continue;
  41551. }
  41552. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  41553. var charCode = charCodes[i];
  41554. // Find a fontCharCode that maps to the base and accent glyphs.
  41555. // If one doesn't exists, create it.
  41556. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  41557. var baseFontCharCode = createCharCode(charCodeToGlyphId, baseGlyphId);
  41558. var accentFontCharCode = createCharCode(charCodeToGlyphId, accentGlyphId);
  41559. seacMap[charCode] = {
  41560. baseFontCharCode: baseFontCharCode,
  41561. accentFontCharCode: accentFontCharCode,
  41562. accentOffset: accentOffset
  41563. };
  41564. }
  41565. }
  41566. properties.seacMap = seacMap;
  41567. }
  41568. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  41569. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  41570. // PostScript Font Program
  41571. builder.addTable('CFF ', font.data);
  41572. // OS/2 and Windows Specific metrics
  41573. builder.addTable('OS/2', createOS2Table(properties, newMapping.charCodeToGlyphId));
  41574. // Character to glyphs mapping
  41575. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId, numGlyphs));
  41576. // Font header
  41577. builder.addTable('head', '\x00\x01\x00\x00' + // Version number
  41578. '\x00\x00\x10\x00' + // fontRevision
  41579. '\x00\x00\x00\x00' + // checksumAdjustement
  41580. '\x5F\x0F\x3C\xF5' + // magicNumber
  41581. '\x00\x00' + // Flags
  41582. safeString16(unitsPerEm) + // unitsPerEM
  41583. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  41584. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  41585. '\x00\x00' + // xMin
  41586. safeString16(properties.descent) + // yMin
  41587. '\x0F\xFF' + // xMax
  41588. safeString16(properties.ascent) + // yMax
  41589. string16(properties.italicAngle ? 2 : 0) + // macStyle
  41590. '\x00\x11' + // lowestRecPPEM
  41591. '\x00\x00' + // fontDirectionHint
  41592. '\x00\x00' + // indexToLocFormat
  41593. '\x00\x00');
  41594. // glyphDataFormat
  41595. // Horizontal header
  41596. builder.addTable('hhea', '\x00\x01\x00\x00' + // Version number
  41597. safeString16(properties.ascent) + // Typographic Ascent
  41598. safeString16(properties.descent) + // Typographic Descent
  41599. '\x00\x00' + // Line Gap
  41600. '\xFF\xFF' + // advanceWidthMax
  41601. '\x00\x00' + // minLeftSidebearing
  41602. '\x00\x00' + // minRightSidebearing
  41603. '\x00\x00' + // xMaxExtent
  41604. safeString16(properties.capHeight) + // caretSlopeRise
  41605. safeString16(Math.tan(properties.italicAngle) * properties.xHeight) + // caretSlopeRun
  41606. '\x00\x00' + // caretOffset
  41607. '\x00\x00' + // -reserved-
  41608. '\x00\x00' + // -reserved-
  41609. '\x00\x00' + // -reserved-
  41610. '\x00\x00' + // -reserved-
  41611. '\x00\x00' + // metricDataFormat
  41612. string16(numGlyphs));
  41613. // Number of HMetrics
  41614. // Horizontal metrics
  41615. builder.addTable('hmtx', function fontFieldsHmtx() {
  41616. var charstrings = font.charstrings;
  41617. var cffWidths = font.cff ? font.cff.widths : null;
  41618. var hmtx = '\x00\x00\x00\x00';
  41619. // Fake .notdef
  41620. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  41621. var width = 0;
  41622. if (charstrings) {
  41623. var charstring = charstrings[i - 1];
  41624. width = 'width' in charstring ? charstring.width : 0;
  41625. } else if (cffWidths) {
  41626. width = Math.ceil(cffWidths[i] || 0);
  41627. }
  41628. hmtx += string16(width) + string16(0);
  41629. }
  41630. return hmtx;
  41631. }());
  41632. // Maximum profile
  41633. builder.addTable('maxp', '\x00\x00\x50\x00' + // Version number
  41634. string16(numGlyphs));
  41635. // Num of glyphs
  41636. // Naming tables
  41637. builder.addTable('name', createNameTable(fontName));
  41638. // PostScript information
  41639. builder.addTable('post', createPostTable(properties));
  41640. return builder.toArray();
  41641. },
  41642. get spaceWidth() {
  41643. if ('_shadowWidth' in this) {
  41644. return this._shadowWidth;
  41645. }
  41646. // trying to estimate space character width
  41647. var possibleSpaceReplacements = [
  41648. 'space',
  41649. 'minus',
  41650. 'one',
  41651. 'i',
  41652. 'I'
  41653. ];
  41654. var width;
  41655. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  41656. var glyphName = possibleSpaceReplacements[i];
  41657. // if possible, getting width by glyph name
  41658. if (glyphName in this.widths) {
  41659. width = this.widths[glyphName];
  41660. break;
  41661. }
  41662. var glyphsUnicodeMap = getGlyphsUnicode();
  41663. var glyphUnicode = glyphsUnicodeMap[glyphName];
  41664. // finding the charcode via unicodeToCID map
  41665. var charcode = 0;
  41666. if (this.composite) {
  41667. if (this.cMap.contains(glyphUnicode)) {
  41668. charcode = this.cMap.lookup(glyphUnicode);
  41669. }
  41670. }
  41671. // ... via toUnicode map
  41672. if (!charcode && this.toUnicode) {
  41673. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  41674. }
  41675. // setting it to unicode if negative or undefined
  41676. if (charcode <= 0) {
  41677. charcode = glyphUnicode;
  41678. }
  41679. // trying to get width via charcode
  41680. width = this.widths[charcode];
  41681. if (width) {
  41682. break;
  41683. }
  41684. }
  41685. // the non-zero width found
  41686. width = width || this.defaultWidth;
  41687. // Do not shadow the property here. See discussion:
  41688. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  41689. this._shadowWidth = width;
  41690. return width;
  41691. },
  41692. charToGlyph: function Font_charToGlyph(charcode, isSpace) {
  41693. var fontCharCode, width, operatorListId;
  41694. var widthCode = charcode;
  41695. if (this.cMap && this.cMap.contains(charcode)) {
  41696. widthCode = this.cMap.lookup(charcode);
  41697. }
  41698. width = this.widths[widthCode];
  41699. width = isNum(width) ? width : this.defaultWidth;
  41700. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  41701. var unicode = this.toUnicode.get(charcode) || charcode;
  41702. if (typeof unicode === 'number') {
  41703. unicode = String.fromCharCode(unicode);
  41704. }
  41705. var isInFont = charcode in this.toFontChar;
  41706. // First try the toFontChar map, if it's not there then try falling
  41707. // back to the char code.
  41708. fontCharCode = this.toFontChar[charcode] || charcode;
  41709. if (this.missingFile) {
  41710. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  41711. }
  41712. if (this.isType3Font) {
  41713. // Font char code in this case is actually a glyph name.
  41714. operatorListId = fontCharCode;
  41715. }
  41716. var accent = null;
  41717. if (this.seacMap && this.seacMap[charcode]) {
  41718. isInFont = true;
  41719. var seac = this.seacMap[charcode];
  41720. fontCharCode = seac.baseFontCharCode;
  41721. accent = {
  41722. fontChar: String.fromCharCode(seac.accentFontCharCode),
  41723. offset: seac.accentOffset
  41724. };
  41725. }
  41726. var fontChar = String.fromCharCode(fontCharCode);
  41727. var glyph = this.glyphCache[charcode];
  41728. if (!glyph || !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont)) {
  41729. glyph = new Glyph(fontChar, unicode, accent, width, vmetric, operatorListId, isSpace, isInFont);
  41730. this.glyphCache[charcode] = glyph;
  41731. }
  41732. return glyph;
  41733. },
  41734. charsToGlyphs: function Font_charsToGlyphs(chars) {
  41735. var charsCache = this.charsCache;
  41736. var glyphs, glyph, charcode;
  41737. // if we translated this string before, just grab it from the cache
  41738. if (charsCache) {
  41739. glyphs = charsCache[chars];
  41740. if (glyphs) {
  41741. return glyphs;
  41742. }
  41743. }
  41744. // lazily create the translation cache
  41745. if (!charsCache) {
  41746. charsCache = this.charsCache = Object.create(null);
  41747. }
  41748. glyphs = [];
  41749. var charsCacheKey = chars;
  41750. var i = 0, ii;
  41751. if (this.cMap) {
  41752. // composite fonts have multi-byte strings convert the string from
  41753. // single-byte to multi-byte
  41754. var c = Object.create(null);
  41755. while (i < chars.length) {
  41756. this.cMap.readCharCode(chars, i, c);
  41757. charcode = c.charcode;
  41758. var length = c.length;
  41759. i += length;
  41760. // Space is char with code 0x20 and length 1 in multiple-byte codes.
  41761. var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
  41762. glyph = this.charToGlyph(charcode, isSpace);
  41763. glyphs.push(glyph);
  41764. }
  41765. } else {
  41766. for (i = 0, ii = chars.length; i < ii; ++i) {
  41767. charcode = chars.charCodeAt(i);
  41768. glyph = this.charToGlyph(charcode, charcode === 0x20);
  41769. glyphs.push(glyph);
  41770. }
  41771. }
  41772. // Enter the translated string into the cache
  41773. return charsCache[charsCacheKey] = glyphs;
  41774. }
  41775. };
  41776. return Font;
  41777. }();
  41778. var ErrorFont = function ErrorFontClosure() {
  41779. function ErrorFont(error) {
  41780. this.error = error;
  41781. this.loadedName = 'g_font_error';
  41782. this.loading = false;
  41783. }
  41784. ErrorFont.prototype = {
  41785. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  41786. return [];
  41787. },
  41788. exportData: function ErrorFont_exportData() {
  41789. return { error: this.error };
  41790. }
  41791. };
  41792. return ErrorFont;
  41793. }();
  41794. /**
  41795. * Shared logic for building a char code to glyph id mapping for Type1 and
  41796. * simple CFF fonts. See section 9.6.6.2 of the spec.
  41797. * @param {Object} properties Font properties object.
  41798. * @param {Object} builtInEncoding The encoding contained within the actual font
  41799. * data.
  41800. * @param {Array} glyphNames Array of glyph names where the index is the
  41801. * glyph ID.
  41802. * @returns {Object} A char code to glyph ID map.
  41803. */
  41804. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  41805. var charCodeToGlyphId = Object.create(null);
  41806. var glyphId, charCode, baseEncoding;
  41807. if (properties.baseEncodingName) {
  41808. // If a valid base encoding name was used, the mapping is initialized with
  41809. // that.
  41810. baseEncoding = getEncoding(properties.baseEncodingName);
  41811. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  41812. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  41813. if (glyphId >= 0) {
  41814. charCodeToGlyphId[charCode] = glyphId;
  41815. } else {
  41816. charCodeToGlyphId[charCode] = 0;
  41817. }
  41818. }
  41819. } else // notdef
  41820. if (!!(properties.flags & FontFlags.Symbolic)) {
  41821. // For a symbolic font the encoding should be the fonts built-in
  41822. // encoding.
  41823. for (charCode in builtInEncoding) {
  41824. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  41825. }
  41826. } else {
  41827. // For non-symbolic fonts that don't have a base encoding the standard
  41828. // encoding should be used.
  41829. baseEncoding = StandardEncoding;
  41830. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  41831. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  41832. if (glyphId >= 0) {
  41833. charCodeToGlyphId[charCode] = glyphId;
  41834. } else {
  41835. charCodeToGlyphId[charCode] = 0;
  41836. }
  41837. }
  41838. }
  41839. // notdef
  41840. // Lastly, merge in the differences.
  41841. var differences = properties.differences, glyphsUnicodeMap;
  41842. if (differences) {
  41843. for (charCode in differences) {
  41844. var glyphName = differences[charCode];
  41845. glyphId = glyphNames.indexOf(glyphName);
  41846. if (glyphId === -1) {
  41847. if (!glyphsUnicodeMap) {
  41848. glyphsUnicodeMap = getGlyphsUnicode();
  41849. }
  41850. var standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
  41851. if (standardGlyphName !== glyphName) {
  41852. glyphId = glyphNames.indexOf(standardGlyphName);
  41853. }
  41854. }
  41855. if (glyphId >= 0) {
  41856. charCodeToGlyphId[charCode] = glyphId;
  41857. } else {
  41858. charCodeToGlyphId[charCode] = 0;
  41859. }
  41860. }
  41861. }
  41862. // notdef
  41863. return charCodeToGlyphId;
  41864. }
  41865. // Type1Font is also a CIDFontType0.
  41866. var Type1Font = function Type1FontClosure() {
  41867. function findBlock(streamBytes, signature, startIndex) {
  41868. var streamBytesLength = streamBytes.length;
  41869. var signatureLength = signature.length;
  41870. var scanLength = streamBytesLength - signatureLength;
  41871. var i = startIndex, j, found = false;
  41872. while (i < scanLength) {
  41873. j = 0;
  41874. while (j < signatureLength && streamBytes[i + j] === signature[j]) {
  41875. j++;
  41876. }
  41877. if (j >= signatureLength) {
  41878. // `signature` found, skip over whitespace.
  41879. i += j;
  41880. while (i < streamBytesLength && isSpace(streamBytes[i])) {
  41881. i++;
  41882. }
  41883. found = true;
  41884. break;
  41885. }
  41886. i++;
  41887. }
  41888. return {
  41889. found: found,
  41890. length: i
  41891. };
  41892. }
  41893. function getHeaderBlock(stream, suggestedLength) {
  41894. var EEXEC_SIGNATURE = [
  41895. 0x65,
  41896. 0x65,
  41897. 0x78,
  41898. 0x65,
  41899. 0x63
  41900. ];
  41901. var streamStartPos = stream.pos;
  41902. // Save the initial stream position.
  41903. var headerBytes, headerBytesLength, block;
  41904. try {
  41905. headerBytes = stream.getBytes(suggestedLength);
  41906. headerBytesLength = headerBytes.length;
  41907. } catch (ex) {
  41908. if (ex instanceof MissingDataException) {
  41909. throw ex;
  41910. }
  41911. }
  41912. // Ignore errors if the `suggestedLength` is huge enough that a Uint8Array
  41913. // cannot hold the result of `getBytes`, and fallback to simply checking
  41914. // the entire stream (fixes issue3928.pdf).
  41915. if (headerBytesLength === suggestedLength) {
  41916. // Most of the time `suggestedLength` is correct, so to speed things up we
  41917. // initially only check the last few bytes to see if the header was found.
  41918. // Otherwise we (potentially) check the entire stream to prevent errors in
  41919. // `Type1Parser` (fixes issue5686.pdf).
  41920. block = findBlock(headerBytes, EEXEC_SIGNATURE, suggestedLength - 2 * EEXEC_SIGNATURE.length);
  41921. if (block.found && block.length === suggestedLength) {
  41922. return {
  41923. stream: new Stream(headerBytes),
  41924. length: suggestedLength
  41925. };
  41926. }
  41927. }
  41928. warn('Invalid "Length1" property in Type1 font -- trying to recover.');
  41929. stream.pos = streamStartPos;
  41930. // Reset the stream position.
  41931. var SCAN_BLOCK_LENGTH = 2048;
  41932. var actualLength;
  41933. while (true) {
  41934. var scanBytes = stream.peekBytes(SCAN_BLOCK_LENGTH);
  41935. block = findBlock(scanBytes, EEXEC_SIGNATURE, 0);
  41936. if (block.length === 0) {
  41937. break;
  41938. }
  41939. stream.pos += block.length;
  41940. // Update the stream position.
  41941. if (block.found) {
  41942. actualLength = stream.pos - streamStartPos;
  41943. break;
  41944. }
  41945. }
  41946. stream.pos = streamStartPos;
  41947. // Reset the stream position.
  41948. if (actualLength) {
  41949. return {
  41950. stream: new Stream(stream.getBytes(actualLength)),
  41951. length: actualLength
  41952. };
  41953. }
  41954. warn('Unable to recover "Length1" property in Type1 font -- using as is.');
  41955. return {
  41956. stream: new Stream(stream.getBytes(suggestedLength)),
  41957. length: suggestedLength
  41958. };
  41959. }
  41960. function getEexecBlock(stream, suggestedLength) {
  41961. // We should ideally parse the eexec block to ensure that `suggestedLength`
  41962. // is correct, so we don't truncate the block data if it's too small.
  41963. // However, this would also require checking if the fixed-content portion
  41964. // exists (using the 'Length3' property), and ensuring that it's valid.
  41965. //
  41966. // Given that `suggestedLength` almost always is correct, all the validation
  41967. // would require a great deal of unnecessary parsing for most fonts.
  41968. // To save time, we always fetch the entire stream instead, which also avoid
  41969. // issues if `suggestedLength` is huge (see comment in `getHeaderBlock`).
  41970. //
  41971. // NOTE: This means that the function can include the fixed-content portion
  41972. // in the returned eexec block. In practice this does *not* seem to matter,
  41973. // since `Type1Parser_extractFontProgram` will skip over any non-commands.
  41974. var eexecBytes = stream.getBytes();
  41975. return {
  41976. stream: new Stream(eexecBytes),
  41977. length: eexecBytes.length
  41978. };
  41979. }
  41980. function Type1Font(name, file, properties) {
  41981. // Some bad generators embed pfb file as is, we have to strip 6-byte header.
  41982. // Also, length1 and length2 might be off by 6 bytes as well.
  41983. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  41984. var PFB_HEADER_SIZE = 6;
  41985. var headerBlockLength = properties.length1;
  41986. var eexecBlockLength = properties.length2;
  41987. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  41988. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  41989. if (pfbHeaderPresent) {
  41990. file.skip(PFB_HEADER_SIZE);
  41991. headerBlockLength = pfbHeader[5] << 24 | pfbHeader[4] << 16 | pfbHeader[3] << 8 | pfbHeader[2];
  41992. }
  41993. // Get the data block containing glyphs and subrs information
  41994. var headerBlock = getHeaderBlock(file, headerBlockLength);
  41995. headerBlockLength = headerBlock.length;
  41996. var headerBlockParser = new Type1Parser(headerBlock.stream, false, SEAC_ANALYSIS_ENABLED);
  41997. headerBlockParser.extractFontHeader(properties);
  41998. if (pfbHeaderPresent) {
  41999. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  42000. eexecBlockLength = pfbHeader[5] << 24 | pfbHeader[4] << 16 | pfbHeader[3] << 8 | pfbHeader[2];
  42001. }
  42002. // Decrypt the data blocks and retrieve it's content
  42003. var eexecBlock = getEexecBlock(file, eexecBlockLength);
  42004. eexecBlockLength = eexecBlock.length;
  42005. var eexecBlockParser = new Type1Parser(eexecBlock.stream, true, SEAC_ANALYSIS_ENABLED);
  42006. var data = eexecBlockParser.extractFontProgram();
  42007. for (var info in data.properties) {
  42008. properties[info] = data.properties[info];
  42009. }
  42010. var charstrings = data.charstrings;
  42011. var type2Charstrings = this.getType2Charstrings(charstrings);
  42012. var subrs = this.getType2Subrs(data.subrs);
  42013. this.charstrings = charstrings;
  42014. this.data = this.wrap(name, type2Charstrings, this.charstrings, subrs, properties);
  42015. this.seacs = this.getSeacs(data.charstrings);
  42016. }
  42017. Type1Font.prototype = {
  42018. get numGlyphs() {
  42019. return this.charstrings.length + 1;
  42020. },
  42021. getCharset: function Type1Font_getCharset() {
  42022. var charset = ['.notdef'];
  42023. var charstrings = this.charstrings;
  42024. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  42025. charset.push(charstrings[glyphId].glyphName);
  42026. }
  42027. return charset;
  42028. },
  42029. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  42030. var charstrings = this.charstrings;
  42031. var glyphNames = ['.notdef'], glyphId;
  42032. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  42033. glyphNames.push(charstrings[glyphId].glyphName);
  42034. }
  42035. var encoding = properties.builtInEncoding;
  42036. if (encoding) {
  42037. var builtInEncoding = Object.create(null);
  42038. for (var charCode in encoding) {
  42039. glyphId = glyphNames.indexOf(encoding[charCode]);
  42040. if (glyphId >= 0) {
  42041. builtInEncoding[charCode] = glyphId;
  42042. }
  42043. }
  42044. }
  42045. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  42046. },
  42047. getSeacs: function Type1Font_getSeacs(charstrings) {
  42048. var i, ii;
  42049. var seacMap = [];
  42050. for (i = 0, ii = charstrings.length; i < ii; i++) {
  42051. var charstring = charstrings[i];
  42052. if (charstring.seac) {
  42053. // Offset by 1 for .notdef
  42054. seacMap[i + 1] = charstring.seac;
  42055. }
  42056. }
  42057. return seacMap;
  42058. },
  42059. getType2Charstrings: function Type1Font_getType2Charstrings(type1Charstrings) {
  42060. var type2Charstrings = [];
  42061. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  42062. type2Charstrings.push(type1Charstrings[i].charstring);
  42063. }
  42064. return type2Charstrings;
  42065. },
  42066. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  42067. var bias = 0;
  42068. var count = type1Subrs.length;
  42069. if (count < 1133) {
  42070. bias = 107;
  42071. } else if (count < 33769) {
  42072. bias = 1131;
  42073. } else {
  42074. bias = 32768;
  42075. }
  42076. // Add a bunch of empty subrs to deal with the Type2 bias
  42077. var type2Subrs = [];
  42078. var i;
  42079. for (i = 0; i < bias; i++) {
  42080. type2Subrs.push([0x0B]);
  42081. }
  42082. for (i = 0; i < count; i++) {
  42083. type2Subrs.push(type1Subrs[i]);
  42084. }
  42085. return type2Subrs;
  42086. },
  42087. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  42088. var cff = new CFF();
  42089. cff.header = new CFFHeader(1, 0, 4, 4);
  42090. cff.names = [name];
  42091. var topDict = new CFFTopDict();
  42092. // CFF strings IDs 0...390 are predefined names, so refering
  42093. // to entries in our own String INDEX starts at SID 391.
  42094. topDict.setByName('version', 391);
  42095. topDict.setByName('Notice', 392);
  42096. topDict.setByName('FullName', 393);
  42097. topDict.setByName('FamilyName', 394);
  42098. topDict.setByName('Weight', 395);
  42099. topDict.setByName('Encoding', null);
  42100. // placeholder
  42101. topDict.setByName('FontMatrix', properties.fontMatrix);
  42102. topDict.setByName('FontBBox', properties.bbox);
  42103. topDict.setByName('charset', null);
  42104. // placeholder
  42105. topDict.setByName('CharStrings', null);
  42106. // placeholder
  42107. topDict.setByName('Private', null);
  42108. // placeholder
  42109. cff.topDict = topDict;
  42110. var strings = new CFFStrings();
  42111. strings.add('Version 0.11');
  42112. // Version
  42113. strings.add('See original notice');
  42114. // Notice
  42115. strings.add(name);
  42116. // FullName
  42117. strings.add(name);
  42118. // FamilyName
  42119. strings.add('Medium');
  42120. // Weight
  42121. cff.strings = strings;
  42122. cff.globalSubrIndex = new CFFIndex();
  42123. var count = glyphs.length;
  42124. var charsetArray = [0];
  42125. var i, ii;
  42126. for (i = 0; i < count; i++) {
  42127. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  42128. // TODO: Insert the string and correctly map it. Previously it was
  42129. // thought mapping names that aren't in the standard strings to .notdef
  42130. // was fine, however in issue818 when mapping them all to .notdef the
  42131. // adieresis glyph no longer worked.
  42132. if (index === -1) {
  42133. index = 0;
  42134. }
  42135. charsetArray.push(index >> 8 & 0xff, index & 0xff);
  42136. }
  42137. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  42138. var charStringsIndex = new CFFIndex();
  42139. charStringsIndex.add([
  42140. 0x8B,
  42141. 0x0E
  42142. ]);
  42143. // .notdef
  42144. for (i = 0; i < count; i++) {
  42145. var glyph = glyphs[i];
  42146. // If the CharString outline is empty, replace it with .notdef to
  42147. // prevent OTS from rejecting the font (fixes bug1252420.pdf).
  42148. if (glyph.length === 0) {
  42149. charStringsIndex.add([
  42150. 0x8B,
  42151. 0x0E
  42152. ]);
  42153. // .notdef
  42154. continue;
  42155. }
  42156. charStringsIndex.add(glyph);
  42157. }
  42158. cff.charStrings = charStringsIndex;
  42159. var privateDict = new CFFPrivateDict();
  42160. privateDict.setByName('Subrs', null);
  42161. // placeholder
  42162. var fields = [
  42163. 'BlueValues',
  42164. 'OtherBlues',
  42165. 'FamilyBlues',
  42166. 'FamilyOtherBlues',
  42167. 'StemSnapH',
  42168. 'StemSnapV',
  42169. 'BlueShift',
  42170. 'BlueFuzz',
  42171. 'BlueScale',
  42172. 'LanguageGroup',
  42173. 'ExpansionFactor',
  42174. 'ForceBold',
  42175. 'StdHW',
  42176. 'StdVW'
  42177. ];
  42178. for (i = 0, ii = fields.length; i < ii; i++) {
  42179. var field = fields[i];
  42180. if (!(field in properties.privateData)) {
  42181. continue;
  42182. }
  42183. var value = properties.privateData[field];
  42184. if (isArray(value)) {
  42185. // All of the private dictionary array data in CFF must be stored as
  42186. // "delta-encoded" numbers.
  42187. for (var j = value.length - 1; j > 0; j--) {
  42188. value[j] -= value[j - 1];
  42189. }
  42190. }
  42191. // ... difference from previous value
  42192. privateDict.setByName(field, value);
  42193. }
  42194. cff.topDict.privateDict = privateDict;
  42195. var subrIndex = new CFFIndex();
  42196. for (i = 0, ii = subrs.length; i < ii; i++) {
  42197. subrIndex.add(subrs[i]);
  42198. }
  42199. privateDict.subrsIndex = subrIndex;
  42200. var compiler = new CFFCompiler(cff);
  42201. return compiler.compile();
  42202. }
  42203. };
  42204. return Type1Font;
  42205. }();
  42206. var CFFFont = function CFFFontClosure() {
  42207. function CFFFont(file, properties) {
  42208. this.properties = properties;
  42209. var parser = new CFFParser(file, properties, SEAC_ANALYSIS_ENABLED);
  42210. this.cff = parser.parse();
  42211. var compiler = new CFFCompiler(this.cff);
  42212. this.seacs = this.cff.seacs;
  42213. try {
  42214. this.data = compiler.compile();
  42215. } catch (e) {
  42216. warn('Failed to compile font ' + properties.loadedName);
  42217. // There may have just been an issue with the compiler, set the data
  42218. // anyway and hope the font loaded.
  42219. this.data = file;
  42220. }
  42221. }
  42222. CFFFont.prototype = {
  42223. get numGlyphs() {
  42224. return this.cff.charStrings.count;
  42225. },
  42226. getCharset: function CFFFont_getCharset() {
  42227. return this.cff.charset.charset;
  42228. },
  42229. getGlyphMapping: function CFFFont_getGlyphMapping() {
  42230. var cff = this.cff;
  42231. var properties = this.properties;
  42232. var charsets = cff.charset.charset;
  42233. var charCodeToGlyphId;
  42234. var glyphId;
  42235. if (properties.composite) {
  42236. charCodeToGlyphId = Object.create(null);
  42237. if (cff.isCIDFont) {
  42238. // If the font is actually a CID font then we should use the charset
  42239. // to map CIDs to GIDs.
  42240. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  42241. var cid = charsets[glyphId];
  42242. var charCode = properties.cMap.charCodeOf(cid);
  42243. charCodeToGlyphId[charCode] = glyphId;
  42244. }
  42245. } else {
  42246. // If it is NOT actually a CID font then CIDs should be mapped
  42247. // directly to GIDs.
  42248. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  42249. charCodeToGlyphId[glyphId] = glyphId;
  42250. }
  42251. }
  42252. return charCodeToGlyphId;
  42253. }
  42254. var encoding = cff.encoding ? cff.encoding.encoding : null;
  42255. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  42256. return charCodeToGlyphId;
  42257. }
  42258. };
  42259. return CFFFont;
  42260. }();
  42261. // Workaround for seac on Windows.
  42262. (function checkSeacSupport() {
  42263. if (typeof navigator !== 'undefined' && /Windows/.test(navigator.userAgent)) {
  42264. SEAC_ANALYSIS_ENABLED = true;
  42265. }
  42266. }());
  42267. // Workaround for Private Use Area characters in Chrome on Windows
  42268. // http://code.google.com/p/chromium/issues/detail?id=122465
  42269. // https://github.com/mozilla/pdf.js/issues/1689
  42270. (function checkChromeWindows() {
  42271. if (typeof navigator !== 'undefined' && /Windows.*Chrome/.test(navigator.userAgent)) {
  42272. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  42273. }
  42274. }());
  42275. exports.ErrorFont = ErrorFont;
  42276. exports.Font = Font;
  42277. exports.FontFlags = FontFlags;
  42278. exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
  42279. exports.ToUnicodeMap = ToUnicodeMap;
  42280. exports.getFontType = getFontType;
  42281. }));
  42282. (function (root, factory) {
  42283. factory(root.pdfjsCorePsParser = {}, root.pdfjsSharedUtil, root.pdfjsCoreParser);
  42284. }(this, function (exports, sharedUtil, coreParser) {
  42285. var error = sharedUtil.error;
  42286. var isSpace = sharedUtil.isSpace;
  42287. var EOF = coreParser.EOF;
  42288. var PostScriptParser = function PostScriptParserClosure() {
  42289. function PostScriptParser(lexer) {
  42290. this.lexer = lexer;
  42291. this.operators = [];
  42292. this.token = null;
  42293. this.prev = null;
  42294. }
  42295. PostScriptParser.prototype = {
  42296. nextToken: function PostScriptParser_nextToken() {
  42297. this.prev = this.token;
  42298. this.token = this.lexer.getToken();
  42299. },
  42300. accept: function PostScriptParser_accept(type) {
  42301. if (this.token.type === type) {
  42302. this.nextToken();
  42303. return true;
  42304. }
  42305. return false;
  42306. },
  42307. expect: function PostScriptParser_expect(type) {
  42308. if (this.accept(type)) {
  42309. return true;
  42310. }
  42311. error('Unexpected symbol: found ' + this.token.type + ' expected ' + type + '.');
  42312. },
  42313. parse: function PostScriptParser_parse() {
  42314. this.nextToken();
  42315. this.expect(PostScriptTokenTypes.LBRACE);
  42316. this.parseBlock();
  42317. this.expect(PostScriptTokenTypes.RBRACE);
  42318. return this.operators;
  42319. },
  42320. parseBlock: function PostScriptParser_parseBlock() {
  42321. while (true) {
  42322. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  42323. this.operators.push(this.prev.value);
  42324. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  42325. this.operators.push(this.prev.value);
  42326. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  42327. this.parseCondition();
  42328. } else {
  42329. return;
  42330. }
  42331. }
  42332. },
  42333. parseCondition: function PostScriptParser_parseCondition() {
  42334. // Add two place holders that will be updated later
  42335. var conditionLocation = this.operators.length;
  42336. this.operators.push(null, null);
  42337. this.parseBlock();
  42338. this.expect(PostScriptTokenTypes.RBRACE);
  42339. if (this.accept(PostScriptTokenTypes.IF)) {
  42340. // The true block is right after the 'if' so it just falls through on
  42341. // true else it jumps and skips the true block.
  42342. this.operators[conditionLocation] = this.operators.length;
  42343. this.operators[conditionLocation + 1] = 'jz';
  42344. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  42345. var jumpLocation = this.operators.length;
  42346. this.operators.push(null, null);
  42347. var endOfTrue = this.operators.length;
  42348. this.parseBlock();
  42349. this.expect(PostScriptTokenTypes.RBRACE);
  42350. this.expect(PostScriptTokenTypes.IFELSE);
  42351. // The jump is added at the end of the true block to skip the false
  42352. // block.
  42353. this.operators[jumpLocation] = this.operators.length;
  42354. this.operators[jumpLocation + 1] = 'j';
  42355. this.operators[conditionLocation] = endOfTrue;
  42356. this.operators[conditionLocation + 1] = 'jz';
  42357. } else {
  42358. error('PS Function: error parsing conditional.');
  42359. }
  42360. }
  42361. };
  42362. return PostScriptParser;
  42363. }();
  42364. var PostScriptTokenTypes = {
  42365. LBRACE: 0,
  42366. RBRACE: 1,
  42367. NUMBER: 2,
  42368. OPERATOR: 3,
  42369. IF: 4,
  42370. IFELSE: 5
  42371. };
  42372. var PostScriptToken = function PostScriptTokenClosure() {
  42373. function PostScriptToken(type, value) {
  42374. this.type = type;
  42375. this.value = value;
  42376. }
  42377. var opCache = Object.create(null);
  42378. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  42379. var opValue = opCache[op];
  42380. if (opValue) {
  42381. return opValue;
  42382. }
  42383. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  42384. };
  42385. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE, '{');
  42386. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE, '}');
  42387. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  42388. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE, 'IFELSE');
  42389. return PostScriptToken;
  42390. }();
  42391. var PostScriptLexer = function PostScriptLexerClosure() {
  42392. function PostScriptLexer(stream) {
  42393. this.stream = stream;
  42394. this.nextChar();
  42395. this.strBuf = [];
  42396. }
  42397. PostScriptLexer.prototype = {
  42398. nextChar: function PostScriptLexer_nextChar() {
  42399. return this.currentChar = this.stream.getByte();
  42400. },
  42401. getToken: function PostScriptLexer_getToken() {
  42402. var comment = false;
  42403. var ch = this.currentChar;
  42404. // skip comments
  42405. while (true) {
  42406. if (ch < 0) {
  42407. return EOF;
  42408. }
  42409. if (comment) {
  42410. if (ch === 0x0A || ch === 0x0D) {
  42411. comment = false;
  42412. }
  42413. } else if (ch === 0x25) {
  42414. // '%'
  42415. comment = true;
  42416. } else if (!isSpace(ch)) {
  42417. break;
  42418. }
  42419. ch = this.nextChar();
  42420. }
  42421. switch (ch | 0) {
  42422. case 0x30:
  42423. case 0x31:
  42424. case 0x32:
  42425. case 0x33:
  42426. case 0x34:
  42427. // '0'-'4'
  42428. case 0x35:
  42429. case 0x36:
  42430. case 0x37:
  42431. case 0x38:
  42432. case 0x39:
  42433. // '5'-'9'
  42434. case 0x2B:
  42435. case 0x2D:
  42436. case 0x2E:
  42437. // '+', '-', '.'
  42438. return new PostScriptToken(PostScriptTokenTypes.NUMBER, this.getNumber());
  42439. case 0x7B:
  42440. // '{'
  42441. this.nextChar();
  42442. return PostScriptToken.LBRACE;
  42443. case 0x7D:
  42444. // '}'
  42445. this.nextChar();
  42446. return PostScriptToken.RBRACE;
  42447. }
  42448. // operator
  42449. var strBuf = this.strBuf;
  42450. strBuf.length = 0;
  42451. strBuf[0] = String.fromCharCode(ch);
  42452. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  42453. (ch >= 0x41 && ch <= 0x5A || ch >= 0x61 && ch <= 0x7A)) {
  42454. strBuf.push(String.fromCharCode(ch));
  42455. }
  42456. var str = strBuf.join('');
  42457. switch (str.toLowerCase()) {
  42458. case 'if':
  42459. return PostScriptToken.IF;
  42460. case 'ifelse':
  42461. return PostScriptToken.IFELSE;
  42462. default:
  42463. return PostScriptToken.getOperator(str);
  42464. }
  42465. },
  42466. getNumber: function PostScriptLexer_getNumber() {
  42467. var ch = this.currentChar;
  42468. var strBuf = this.strBuf;
  42469. strBuf.length = 0;
  42470. strBuf[0] = String.fromCharCode(ch);
  42471. while ((ch = this.nextChar()) >= 0) {
  42472. if (ch >= 0x30 && ch <= 0x39 || // '0'-'9'
  42473. ch === 0x2D || ch === 0x2E) {
  42474. // '-', '.'
  42475. strBuf.push(String.fromCharCode(ch));
  42476. } else {
  42477. break;
  42478. }
  42479. }
  42480. var value = parseFloat(strBuf.join(''));
  42481. if (isNaN(value)) {
  42482. error('Invalid floating point number: ' + value);
  42483. }
  42484. return value;
  42485. }
  42486. };
  42487. return PostScriptLexer;
  42488. }();
  42489. exports.PostScriptLexer = PostScriptLexer;
  42490. exports.PostScriptParser = PostScriptParser;
  42491. }));
  42492. (function (root, factory) {
  42493. factory(root.pdfjsCoreFunction = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCorePsParser);
  42494. }(this, function (exports, sharedUtil, corePrimitives, corePsParser) {
  42495. var error = sharedUtil.error;
  42496. var info = sharedUtil.info;
  42497. var isArray = sharedUtil.isArray;
  42498. var isBool = sharedUtil.isBool;
  42499. var isDict = corePrimitives.isDict;
  42500. var isStream = corePrimitives.isStream;
  42501. var PostScriptLexer = corePsParser.PostScriptLexer;
  42502. var PostScriptParser = corePsParser.PostScriptParser;
  42503. var PDFFunction = function PDFFunctionClosure() {
  42504. var CONSTRUCT_SAMPLED = 0;
  42505. var CONSTRUCT_INTERPOLATED = 2;
  42506. var CONSTRUCT_STICHED = 3;
  42507. var CONSTRUCT_POSTSCRIPT = 4;
  42508. return {
  42509. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps, str) {
  42510. var i, ii;
  42511. var length = 1;
  42512. for (i = 0, ii = size.length; i < ii; i++) {
  42513. length *= size[i];
  42514. }
  42515. length *= outputSize;
  42516. var array = new Array(length);
  42517. var codeSize = 0;
  42518. var codeBuf = 0;
  42519. // 32 is a valid bps so shifting won't work
  42520. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  42521. var strBytes = str.getBytes((length * bps + 7) / 8);
  42522. var strIdx = 0;
  42523. for (i = 0; i < length; i++) {
  42524. while (codeSize < bps) {
  42525. codeBuf <<= 8;
  42526. codeBuf |= strBytes[strIdx++];
  42527. codeSize += 8;
  42528. }
  42529. codeSize -= bps;
  42530. array[i] = (codeBuf >> codeSize) * sampleMul;
  42531. codeBuf &= (1 << codeSize) - 1;
  42532. }
  42533. return array;
  42534. },
  42535. getIR: function PDFFunction_getIR(xref, fn) {
  42536. var dict = fn.dict;
  42537. if (!dict) {
  42538. dict = fn;
  42539. }
  42540. var types = [
  42541. this.constructSampled,
  42542. null,
  42543. this.constructInterpolated,
  42544. this.constructStiched,
  42545. this.constructPostScript
  42546. ];
  42547. var typeNum = dict.get('FunctionType');
  42548. var typeFn = types[typeNum];
  42549. if (!typeFn) {
  42550. error('Unknown type of function');
  42551. }
  42552. return typeFn.call(this, fn, dict, xref);
  42553. },
  42554. fromIR: function PDFFunction_fromIR(IR) {
  42555. var type = IR[0];
  42556. switch (type) {
  42557. case CONSTRUCT_SAMPLED:
  42558. return this.constructSampledFromIR(IR);
  42559. case CONSTRUCT_INTERPOLATED:
  42560. return this.constructInterpolatedFromIR(IR);
  42561. case CONSTRUCT_STICHED:
  42562. return this.constructStichedFromIR(IR);
  42563. //case CONSTRUCT_POSTSCRIPT:
  42564. default:
  42565. return this.constructPostScriptFromIR(IR);
  42566. }
  42567. },
  42568. parse: function PDFFunction_parse(xref, fn) {
  42569. var IR = this.getIR(xref, fn);
  42570. return this.fromIR(IR);
  42571. },
  42572. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  42573. if (!isArray(fnObj)) {
  42574. // not an array -- parsing as regular function
  42575. return this.parse(xref, fnObj);
  42576. }
  42577. var fnArray = [];
  42578. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  42579. var obj = xref.fetchIfRef(fnObj[j]);
  42580. fnArray.push(PDFFunction.parse(xref, obj));
  42581. }
  42582. return function (src, srcOffset, dest, destOffset) {
  42583. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  42584. fnArray[i](src, srcOffset, dest, destOffset + i);
  42585. }
  42586. };
  42587. },
  42588. constructSampled: function PDFFunction_constructSampled(str, dict) {
  42589. function toMultiArray(arr) {
  42590. var inputLength = arr.length;
  42591. var out = [];
  42592. var index = 0;
  42593. for (var i = 0; i < inputLength; i += 2) {
  42594. out[index] = [
  42595. arr[i],
  42596. arr[i + 1]
  42597. ];
  42598. ++index;
  42599. }
  42600. return out;
  42601. }
  42602. var domain = dict.getArray('Domain');
  42603. var range = dict.getArray('Range');
  42604. if (!domain || !range) {
  42605. error('No domain or range');
  42606. }
  42607. var inputSize = domain.length / 2;
  42608. var outputSize = range.length / 2;
  42609. domain = toMultiArray(domain);
  42610. range = toMultiArray(range);
  42611. var size = dict.get('Size');
  42612. var bps = dict.get('BitsPerSample');
  42613. var order = dict.get('Order') || 1;
  42614. if (order !== 1) {
  42615. // No description how cubic spline interpolation works in PDF32000:2008
  42616. // As in poppler, ignoring order, linear interpolation may work as good
  42617. info('No support for cubic spline interpolation: ' + order);
  42618. }
  42619. var encode = dict.getArray('Encode');
  42620. if (!encode) {
  42621. encode = [];
  42622. for (var i = 0; i < inputSize; ++i) {
  42623. encode.push(0);
  42624. encode.push(size[i] - 1);
  42625. }
  42626. }
  42627. encode = toMultiArray(encode);
  42628. var decode = dict.getArray('Decode');
  42629. if (!decode) {
  42630. decode = range;
  42631. } else {
  42632. decode = toMultiArray(decode);
  42633. }
  42634. var samples = this.getSampleArray(size, outputSize, bps, str);
  42635. return [
  42636. CONSTRUCT_SAMPLED,
  42637. inputSize,
  42638. domain,
  42639. encode,
  42640. decode,
  42641. samples,
  42642. size,
  42643. outputSize,
  42644. Math.pow(2, bps) - 1,
  42645. range
  42646. ];
  42647. },
  42648. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  42649. // See chapter 3, page 109 of the PDF reference
  42650. function interpolate(x, xmin, xmax, ymin, ymax) {
  42651. return ymin + (x - xmin) * ((ymax - ymin) / (xmax - xmin));
  42652. }
  42653. return function constructSampledFromIRResult(src, srcOffset, dest, destOffset) {
  42654. // See chapter 3, page 110 of the PDF reference.
  42655. var m = IR[1];
  42656. var domain = IR[2];
  42657. var encode = IR[3];
  42658. var decode = IR[4];
  42659. var samples = IR[5];
  42660. var size = IR[6];
  42661. var n = IR[7];
  42662. //var mask = IR[8];
  42663. var range = IR[9];
  42664. // Building the cube vertices: its part and sample index
  42665. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  42666. var cubeVertices = 1 << m;
  42667. var cubeN = new Float64Array(cubeVertices);
  42668. var cubeVertex = new Uint32Array(cubeVertices);
  42669. var i, j;
  42670. for (j = 0; j < cubeVertices; j++) {
  42671. cubeN[j] = 1;
  42672. }
  42673. var k = n, pos = 1;
  42674. // Map x_i to y_j for 0 <= i < m using the sampled function.
  42675. for (i = 0; i < m; ++i) {
  42676. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  42677. var domain_2i = domain[i][0];
  42678. var domain_2i_1 = domain[i][1];
  42679. var xi = Math.min(Math.max(src[srcOffset + i], domain_2i), domain_2i_1);
  42680. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  42681. // Encode_2i, Encode_2i+1)
  42682. var e = interpolate(xi, domain_2i, domain_2i_1, encode[i][0], encode[i][1]);
  42683. // e_i' = min(max(e_i, 0), Size_i - 1)
  42684. var size_i = size[i];
  42685. e = Math.min(Math.max(e, 0), size_i - 1);
  42686. // Adjusting the cube: N and vertex sample index
  42687. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1;
  42688. // e1 = e0 + 1;
  42689. var n0 = e0 + 1 - e;
  42690. // (e1 - e) / (e1 - e0);
  42691. var n1 = e - e0;
  42692. // (e - e0) / (e1 - e0);
  42693. var offset0 = e0 * k;
  42694. var offset1 = offset0 + k;
  42695. // e1 * k
  42696. for (j = 0; j < cubeVertices; j++) {
  42697. if (j & pos) {
  42698. cubeN[j] *= n1;
  42699. cubeVertex[j] += offset1;
  42700. } else {
  42701. cubeN[j] *= n0;
  42702. cubeVertex[j] += offset0;
  42703. }
  42704. }
  42705. k *= size_i;
  42706. pos <<= 1;
  42707. }
  42708. for (j = 0; j < n; ++j) {
  42709. // Sum all cube vertices' samples portions
  42710. var rj = 0;
  42711. for (i = 0; i < cubeVertices; i++) {
  42712. rj += samples[cubeVertex[i] + j] * cubeN[i];
  42713. }
  42714. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  42715. // Decode_2j, Decode_2j+1)
  42716. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  42717. // y_j = min(max(r_j, range_2j), range_2j+1)
  42718. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]), range[j][1]);
  42719. }
  42720. };
  42721. },
  42722. constructInterpolated: function PDFFunction_constructInterpolated(str, dict) {
  42723. var c0 = dict.getArray('C0') || [0];
  42724. var c1 = dict.getArray('C1') || [1];
  42725. var n = dict.get('N');
  42726. if (!isArray(c0) || !isArray(c1)) {
  42727. error('Illegal dictionary for interpolated function');
  42728. }
  42729. var length = c0.length;
  42730. var diff = [];
  42731. for (var i = 0; i < length; ++i) {
  42732. diff.push(c1[i] - c0[i]);
  42733. }
  42734. return [
  42735. CONSTRUCT_INTERPOLATED,
  42736. c0,
  42737. diff,
  42738. n
  42739. ];
  42740. },
  42741. constructInterpolatedFromIR: function PDFFunction_constructInterpolatedFromIR(IR) {
  42742. var c0 = IR[1];
  42743. var diff = IR[2];
  42744. var n = IR[3];
  42745. var length = diff.length;
  42746. return function constructInterpolatedFromIRResult(src, srcOffset, dest, destOffset) {
  42747. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  42748. for (var j = 0; j < length; ++j) {
  42749. dest[destOffset + j] = c0[j] + x * diff[j];
  42750. }
  42751. };
  42752. },
  42753. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  42754. var domain = dict.getArray('Domain');
  42755. if (!domain) {
  42756. error('No domain');
  42757. }
  42758. var inputSize = domain.length / 2;
  42759. if (inputSize !== 1) {
  42760. error('Bad domain for stiched function');
  42761. }
  42762. var fnRefs = dict.get('Functions');
  42763. var fns = [];
  42764. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  42765. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  42766. }
  42767. var bounds = dict.getArray('Bounds');
  42768. var encode = dict.getArray('Encode');
  42769. return [
  42770. CONSTRUCT_STICHED,
  42771. domain,
  42772. bounds,
  42773. encode,
  42774. fns
  42775. ];
  42776. },
  42777. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  42778. var domain = IR[1];
  42779. var bounds = IR[2];
  42780. var encode = IR[3];
  42781. var fnsIR = IR[4];
  42782. var fns = [];
  42783. var tmpBuf = new Float32Array(1);
  42784. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  42785. fns.push(PDFFunction.fromIR(fnsIR[i]));
  42786. }
  42787. return function constructStichedFromIRResult(src, srcOffset, dest, destOffset) {
  42788. var clip = function constructStichedFromIRClip(v, min, max) {
  42789. if (v > max) {
  42790. v = max;
  42791. } else if (v < min) {
  42792. v = min;
  42793. }
  42794. return v;
  42795. };
  42796. // clip to domain
  42797. var v = clip(src[srcOffset], domain[0], domain[1]);
  42798. // calculate which bound the value is in
  42799. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  42800. if (v < bounds[i]) {
  42801. break;
  42802. }
  42803. }
  42804. // encode value into domain of function
  42805. var dmin = domain[0];
  42806. if (i > 0) {
  42807. dmin = bounds[i - 1];
  42808. }
  42809. var dmax = domain[1];
  42810. if (i < bounds.length) {
  42811. dmax = bounds[i];
  42812. }
  42813. var rmin = encode[2 * i];
  42814. var rmax = encode[2 * i + 1];
  42815. // Prevent the value from becoming NaN as a result
  42816. // of division by zero (fixes issue6113.pdf).
  42817. tmpBuf[0] = dmin === dmax ? rmin : rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  42818. // call the appropriate function
  42819. fns[i](tmpBuf, 0, dest, destOffset);
  42820. };
  42821. },
  42822. constructPostScript: function PDFFunction_constructPostScript(fn, dict, xref) {
  42823. var domain = dict.getArray('Domain');
  42824. var range = dict.getArray('Range');
  42825. if (!domain) {
  42826. error('No domain.');
  42827. }
  42828. if (!range) {
  42829. error('No range.');
  42830. }
  42831. var lexer = new PostScriptLexer(fn);
  42832. var parser = new PostScriptParser(lexer);
  42833. var code = parser.parse();
  42834. return [
  42835. CONSTRUCT_POSTSCRIPT,
  42836. domain,
  42837. range,
  42838. code
  42839. ];
  42840. },
  42841. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(IR) {
  42842. var domain = IR[1];
  42843. var range = IR[2];
  42844. var code = IR[3];
  42845. var compiled = new PostScriptCompiler().compile(code, domain, range);
  42846. if (compiled) {
  42847. // Compiled function consists of simple expressions such as addition,
  42848. // subtraction, Math.max, and also contains 'var' and 'return'
  42849. // statements. See the generation in the PostScriptCompiler below.
  42850. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  42851. }
  42852. info('Unable to compile PS function');
  42853. var numOutputs = range.length >> 1;
  42854. var numInputs = domain.length >> 1;
  42855. var evaluator = new PostScriptEvaluator(code);
  42856. // Cache the values for a big speed up, the cache size is limited though
  42857. // since the number of possible values can be huge from a PS function.
  42858. var cache = Object.create(null);
  42859. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  42860. // seen in our tests.
  42861. var MAX_CACHE_SIZE = 2048 * 4;
  42862. var cache_available = MAX_CACHE_SIZE;
  42863. var tmpBuf = new Float32Array(numInputs);
  42864. return function constructPostScriptFromIRResult(src, srcOffset, dest, destOffset) {
  42865. var i, value;
  42866. var key = '';
  42867. var input = tmpBuf;
  42868. for (i = 0; i < numInputs; i++) {
  42869. value = src[srcOffset + i];
  42870. input[i] = value;
  42871. key += value + '_';
  42872. }
  42873. var cachedValue = cache[key];
  42874. if (cachedValue !== undefined) {
  42875. dest.set(cachedValue, destOffset);
  42876. return;
  42877. }
  42878. var output = new Float32Array(numOutputs);
  42879. var stack = evaluator.execute(input);
  42880. var stackIndex = stack.length - numOutputs;
  42881. for (i = 0; i < numOutputs; i++) {
  42882. value = stack[stackIndex + i];
  42883. var bound = range[i * 2];
  42884. if (value < bound) {
  42885. value = bound;
  42886. } else {
  42887. bound = range[i * 2 + 1];
  42888. if (value > bound) {
  42889. value = bound;
  42890. }
  42891. }
  42892. output[i] = value;
  42893. }
  42894. if (cache_available > 0) {
  42895. cache_available--;
  42896. cache[key] = output;
  42897. }
  42898. dest.set(output, destOffset);
  42899. };
  42900. }
  42901. };
  42902. }();
  42903. function isPDFFunction(v) {
  42904. var fnDict;
  42905. if (typeof v !== 'object') {
  42906. return false;
  42907. } else if (isDict(v)) {
  42908. fnDict = v;
  42909. } else if (isStream(v)) {
  42910. fnDict = v.dict;
  42911. } else {
  42912. return false;
  42913. }
  42914. return fnDict.has('FunctionType');
  42915. }
  42916. var PostScriptStack = function PostScriptStackClosure() {
  42917. var MAX_STACK_SIZE = 100;
  42918. function PostScriptStack(initialStack) {
  42919. this.stack = !initialStack ? [] : Array.prototype.slice.call(initialStack, 0);
  42920. }
  42921. PostScriptStack.prototype = {
  42922. push: function PostScriptStack_push(value) {
  42923. if (this.stack.length >= MAX_STACK_SIZE) {
  42924. error('PostScript function stack overflow.');
  42925. }
  42926. this.stack.push(value);
  42927. },
  42928. pop: function PostScriptStack_pop() {
  42929. if (this.stack.length <= 0) {
  42930. error('PostScript function stack underflow.');
  42931. }
  42932. return this.stack.pop();
  42933. },
  42934. copy: function PostScriptStack_copy(n) {
  42935. if (this.stack.length + n >= MAX_STACK_SIZE) {
  42936. error('PostScript function stack overflow.');
  42937. }
  42938. var stack = this.stack;
  42939. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  42940. stack.push(stack[i]);
  42941. }
  42942. },
  42943. index: function PostScriptStack_index(n) {
  42944. this.push(this.stack[this.stack.length - n - 1]);
  42945. },
  42946. // rotate the last n stack elements p times
  42947. roll: function PostScriptStack_roll(n, p) {
  42948. var stack = this.stack;
  42949. var l = stack.length - n;
  42950. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  42951. for (i = l, j = r; i < j; i++, j--) {
  42952. t = stack[i];
  42953. stack[i] = stack[j];
  42954. stack[j] = t;
  42955. }
  42956. for (i = l, j = c - 1; i < j; i++, j--) {
  42957. t = stack[i];
  42958. stack[i] = stack[j];
  42959. stack[j] = t;
  42960. }
  42961. for (i = c, j = r; i < j; i++, j--) {
  42962. t = stack[i];
  42963. stack[i] = stack[j];
  42964. stack[j] = t;
  42965. }
  42966. }
  42967. };
  42968. return PostScriptStack;
  42969. }();
  42970. var PostScriptEvaluator = function PostScriptEvaluatorClosure() {
  42971. function PostScriptEvaluator(operators) {
  42972. this.operators = operators;
  42973. }
  42974. PostScriptEvaluator.prototype = {
  42975. execute: function PostScriptEvaluator_execute(initialStack) {
  42976. var stack = new PostScriptStack(initialStack);
  42977. var counter = 0;
  42978. var operators = this.operators;
  42979. var length = operators.length;
  42980. var operator, a, b;
  42981. while (counter < length) {
  42982. operator = operators[counter++];
  42983. if (typeof operator === 'number') {
  42984. // Operator is really an operand and should be pushed to the stack.
  42985. stack.push(operator);
  42986. continue;
  42987. }
  42988. switch (operator) {
  42989. // non standard ps operators
  42990. case 'jz':
  42991. // jump if false
  42992. b = stack.pop();
  42993. a = stack.pop();
  42994. if (!a) {
  42995. counter = b;
  42996. }
  42997. break;
  42998. case 'j':
  42999. // jump
  43000. a = stack.pop();
  43001. counter = a;
  43002. break;
  43003. // all ps operators in alphabetical order (excluding if/ifelse)
  43004. case 'abs':
  43005. a = stack.pop();
  43006. stack.push(Math.abs(a));
  43007. break;
  43008. case 'add':
  43009. b = stack.pop();
  43010. a = stack.pop();
  43011. stack.push(a + b);
  43012. break;
  43013. case 'and':
  43014. b = stack.pop();
  43015. a = stack.pop();
  43016. if (isBool(a) && isBool(b)) {
  43017. stack.push(a && b);
  43018. } else {
  43019. stack.push(a & b);
  43020. }
  43021. break;
  43022. case 'atan':
  43023. a = stack.pop();
  43024. stack.push(Math.atan(a));
  43025. break;
  43026. case 'bitshift':
  43027. b = stack.pop();
  43028. a = stack.pop();
  43029. if (a > 0) {
  43030. stack.push(a << b);
  43031. } else {
  43032. stack.push(a >> b);
  43033. }
  43034. break;
  43035. case 'ceiling':
  43036. a = stack.pop();
  43037. stack.push(Math.ceil(a));
  43038. break;
  43039. case 'copy':
  43040. a = stack.pop();
  43041. stack.copy(a);
  43042. break;
  43043. case 'cos':
  43044. a = stack.pop();
  43045. stack.push(Math.cos(a));
  43046. break;
  43047. case 'cvi':
  43048. a = stack.pop() | 0;
  43049. stack.push(a);
  43050. break;
  43051. case 'cvr':
  43052. // noop
  43053. break;
  43054. case 'div':
  43055. b = stack.pop();
  43056. a = stack.pop();
  43057. stack.push(a / b);
  43058. break;
  43059. case 'dup':
  43060. stack.copy(1);
  43061. break;
  43062. case 'eq':
  43063. b = stack.pop();
  43064. a = stack.pop();
  43065. stack.push(a === b);
  43066. break;
  43067. case 'exch':
  43068. stack.roll(2, 1);
  43069. break;
  43070. case 'exp':
  43071. b = stack.pop();
  43072. a = stack.pop();
  43073. stack.push(Math.pow(a, b));
  43074. break;
  43075. case 'false':
  43076. stack.push(false);
  43077. break;
  43078. case 'floor':
  43079. a = stack.pop();
  43080. stack.push(Math.floor(a));
  43081. break;
  43082. case 'ge':
  43083. b = stack.pop();
  43084. a = stack.pop();
  43085. stack.push(a >= b);
  43086. break;
  43087. case 'gt':
  43088. b = stack.pop();
  43089. a = stack.pop();
  43090. stack.push(a > b);
  43091. break;
  43092. case 'idiv':
  43093. b = stack.pop();
  43094. a = stack.pop();
  43095. stack.push(a / b | 0);
  43096. break;
  43097. case 'index':
  43098. a = stack.pop();
  43099. stack.index(a);
  43100. break;
  43101. case 'le':
  43102. b = stack.pop();
  43103. a = stack.pop();
  43104. stack.push(a <= b);
  43105. break;
  43106. case 'ln':
  43107. a = stack.pop();
  43108. stack.push(Math.log(a));
  43109. break;
  43110. case 'log':
  43111. a = stack.pop();
  43112. stack.push(Math.log(a) / Math.LN10);
  43113. break;
  43114. case 'lt':
  43115. b = stack.pop();
  43116. a = stack.pop();
  43117. stack.push(a < b);
  43118. break;
  43119. case 'mod':
  43120. b = stack.pop();
  43121. a = stack.pop();
  43122. stack.push(a % b);
  43123. break;
  43124. case 'mul':
  43125. b = stack.pop();
  43126. a = stack.pop();
  43127. stack.push(a * b);
  43128. break;
  43129. case 'ne':
  43130. b = stack.pop();
  43131. a = stack.pop();
  43132. stack.push(a !== b);
  43133. break;
  43134. case 'neg':
  43135. a = stack.pop();
  43136. stack.push(-a);
  43137. break;
  43138. case 'not':
  43139. a = stack.pop();
  43140. if (isBool(a)) {
  43141. stack.push(!a);
  43142. } else {
  43143. stack.push(~a);
  43144. }
  43145. break;
  43146. case 'or':
  43147. b = stack.pop();
  43148. a = stack.pop();
  43149. if (isBool(a) && isBool(b)) {
  43150. stack.push(a || b);
  43151. } else {
  43152. stack.push(a | b);
  43153. }
  43154. break;
  43155. case 'pop':
  43156. stack.pop();
  43157. break;
  43158. case 'roll':
  43159. b = stack.pop();
  43160. a = stack.pop();
  43161. stack.roll(a, b);
  43162. break;
  43163. case 'round':
  43164. a = stack.pop();
  43165. stack.push(Math.round(a));
  43166. break;
  43167. case 'sin':
  43168. a = stack.pop();
  43169. stack.push(Math.sin(a));
  43170. break;
  43171. case 'sqrt':
  43172. a = stack.pop();
  43173. stack.push(Math.sqrt(a));
  43174. break;
  43175. case 'sub':
  43176. b = stack.pop();
  43177. a = stack.pop();
  43178. stack.push(a - b);
  43179. break;
  43180. case 'true':
  43181. stack.push(true);
  43182. break;
  43183. case 'truncate':
  43184. a = stack.pop();
  43185. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  43186. stack.push(a);
  43187. break;
  43188. case 'xor':
  43189. b = stack.pop();
  43190. a = stack.pop();
  43191. if (isBool(a) && isBool(b)) {
  43192. stack.push(a !== b);
  43193. } else {
  43194. stack.push(a ^ b);
  43195. }
  43196. break;
  43197. default:
  43198. error('Unknown operator ' + operator);
  43199. break;
  43200. }
  43201. }
  43202. return stack.stack;
  43203. }
  43204. };
  43205. return PostScriptEvaluator;
  43206. }();
  43207. // Most of the PDFs functions consist of simple operations such as:
  43208. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  43209. //
  43210. // We can compile most of such programs, and at the same moment, we can
  43211. // optimize some expressions using basic math properties. Keeping track of
  43212. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  43213. var PostScriptCompiler = function PostScriptCompilerClosure() {
  43214. function AstNode(type) {
  43215. this.type = type;
  43216. }
  43217. AstNode.prototype.visit = function (visitor) {
  43218. throw new Error('abstract method');
  43219. };
  43220. function AstArgument(index, min, max) {
  43221. AstNode.call(this, 'args');
  43222. this.index = index;
  43223. this.min = min;
  43224. this.max = max;
  43225. }
  43226. AstArgument.prototype = Object.create(AstNode.prototype);
  43227. AstArgument.prototype.visit = function (visitor) {
  43228. visitor.visitArgument(this);
  43229. };
  43230. function AstLiteral(number) {
  43231. AstNode.call(this, 'literal');
  43232. this.number = number;
  43233. this.min = number;
  43234. this.max = number;
  43235. }
  43236. AstLiteral.prototype = Object.create(AstNode.prototype);
  43237. AstLiteral.prototype.visit = function (visitor) {
  43238. visitor.visitLiteral(this);
  43239. };
  43240. function AstBinaryOperation(op, arg1, arg2, min, max) {
  43241. AstNode.call(this, 'binary');
  43242. this.op = op;
  43243. this.arg1 = arg1;
  43244. this.arg2 = arg2;
  43245. this.min = min;
  43246. this.max = max;
  43247. }
  43248. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  43249. AstBinaryOperation.prototype.visit = function (visitor) {
  43250. visitor.visitBinaryOperation(this);
  43251. };
  43252. function AstMin(arg, max) {
  43253. AstNode.call(this, 'max');
  43254. this.arg = arg;
  43255. this.min = arg.min;
  43256. this.max = max;
  43257. }
  43258. AstMin.prototype = Object.create(AstNode.prototype);
  43259. AstMin.prototype.visit = function (visitor) {
  43260. visitor.visitMin(this);
  43261. };
  43262. function AstVariable(index, min, max) {
  43263. AstNode.call(this, 'var');
  43264. this.index = index;
  43265. this.min = min;
  43266. this.max = max;
  43267. }
  43268. AstVariable.prototype = Object.create(AstNode.prototype);
  43269. AstVariable.prototype.visit = function (visitor) {
  43270. visitor.visitVariable(this);
  43271. };
  43272. function AstVariableDefinition(variable, arg) {
  43273. AstNode.call(this, 'definition');
  43274. this.variable = variable;
  43275. this.arg = arg;
  43276. }
  43277. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  43278. AstVariableDefinition.prototype.visit = function (visitor) {
  43279. visitor.visitVariableDefinition(this);
  43280. };
  43281. function ExpressionBuilderVisitor() {
  43282. this.parts = [];
  43283. }
  43284. ExpressionBuilderVisitor.prototype = {
  43285. visitArgument: function (arg) {
  43286. this.parts.push('Math.max(', arg.min, ', Math.min(', arg.max, ', src[srcOffset + ', arg.index, ']))');
  43287. },
  43288. visitVariable: function (variable) {
  43289. this.parts.push('v', variable.index);
  43290. },
  43291. visitLiteral: function (literal) {
  43292. this.parts.push(literal.number);
  43293. },
  43294. visitBinaryOperation: function (operation) {
  43295. this.parts.push('(');
  43296. operation.arg1.visit(this);
  43297. this.parts.push(' ', operation.op, ' ');
  43298. operation.arg2.visit(this);
  43299. this.parts.push(')');
  43300. },
  43301. visitVariableDefinition: function (definition) {
  43302. this.parts.push('var ');
  43303. definition.variable.visit(this);
  43304. this.parts.push(' = ');
  43305. definition.arg.visit(this);
  43306. this.parts.push(';');
  43307. },
  43308. visitMin: function (max) {
  43309. this.parts.push('Math.min(');
  43310. max.arg.visit(this);
  43311. this.parts.push(', ', max.max, ')');
  43312. },
  43313. toString: function () {
  43314. return this.parts.join('');
  43315. }
  43316. };
  43317. function buildAddOperation(num1, num2) {
  43318. if (num2.type === 'literal' && num2.number === 0) {
  43319. // optimization: second operand is 0
  43320. return num1;
  43321. }
  43322. if (num1.type === 'literal' && num1.number === 0) {
  43323. // optimization: first operand is 0
  43324. return num2;
  43325. }
  43326. if (num2.type === 'literal' && num1.type === 'literal') {
  43327. // optimization: operands operand are literals
  43328. return new AstLiteral(num1.number + num2.number);
  43329. }
  43330. return new AstBinaryOperation('+', num1, num2, num1.min + num2.min, num1.max + num2.max);
  43331. }
  43332. function buildMulOperation(num1, num2) {
  43333. if (num2.type === 'literal') {
  43334. // optimization: second operands is a literal...
  43335. if (num2.number === 0) {
  43336. return new AstLiteral(0);
  43337. } else // and it's 0
  43338. if (num2.number === 1) {
  43339. return num1;
  43340. } else // and it's 1
  43341. if (num1.type === 'literal') {
  43342. // ... and first operands is a literal too
  43343. return new AstLiteral(num1.number * num2.number);
  43344. }
  43345. }
  43346. if (num1.type === 'literal') {
  43347. // optimization: first operands is a literal...
  43348. if (num1.number === 0) {
  43349. return new AstLiteral(0);
  43350. } else // and it's 0
  43351. if (num1.number === 1) {
  43352. return num2;
  43353. }
  43354. }
  43355. // and it's 1
  43356. var min = Math.min(num1.min * num2.min, num1.min * num2.max, num1.max * num2.min, num1.max * num2.max);
  43357. var max = Math.max(num1.min * num2.min, num1.min * num2.max, num1.max * num2.min, num1.max * num2.max);
  43358. return new AstBinaryOperation('*', num1, num2, min, max);
  43359. }
  43360. function buildSubOperation(num1, num2) {
  43361. if (num2.type === 'literal') {
  43362. // optimization: second operands is a literal...
  43363. if (num2.number === 0) {
  43364. return num1;
  43365. } else // ... and it's 0
  43366. if (num1.type === 'literal') {
  43367. // ... and first operands is a literal too
  43368. return new AstLiteral(num1.number - num2.number);
  43369. }
  43370. }
  43371. if (num2.type === 'binary' && num2.op === '-' && num1.type === 'literal' && num1.number === 1 && num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  43372. // optimization for case: 1 - (1 - x)
  43373. return num2.arg2;
  43374. }
  43375. return new AstBinaryOperation('-', num1, num2, num1.min - num2.max, num1.max - num2.min);
  43376. }
  43377. function buildMinOperation(num1, max) {
  43378. if (num1.min >= max) {
  43379. // optimization: num1 min value is not less than required max
  43380. return new AstLiteral(max);
  43381. } else // just returning max
  43382. if (num1.max <= max) {
  43383. // optimization: num1 max value is not greater than required max
  43384. return num1;
  43385. }
  43386. // just returning an argument
  43387. return new AstMin(num1, max);
  43388. }
  43389. function PostScriptCompiler() {
  43390. }
  43391. PostScriptCompiler.prototype = {
  43392. compile: function PostScriptCompiler_compile(code, domain, range) {
  43393. var stack = [];
  43394. var i, ii;
  43395. var instructions = [];
  43396. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  43397. var lastRegister = 0;
  43398. var n, j;
  43399. var num1, num2, ast1, ast2, tmpVar, item;
  43400. for (i = 0; i < inputSize; i++) {
  43401. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  43402. }
  43403. for (i = 0, ii = code.length; i < ii; i++) {
  43404. item = code[i];
  43405. if (typeof item === 'number') {
  43406. stack.push(new AstLiteral(item));
  43407. continue;
  43408. }
  43409. switch (item) {
  43410. case 'add':
  43411. if (stack.length < 2) {
  43412. return null;
  43413. }
  43414. num2 = stack.pop();
  43415. num1 = stack.pop();
  43416. stack.push(buildAddOperation(num1, num2));
  43417. break;
  43418. case 'cvr':
  43419. if (stack.length < 1) {
  43420. return null;
  43421. }
  43422. break;
  43423. case 'mul':
  43424. if (stack.length < 2) {
  43425. return null;
  43426. }
  43427. num2 = stack.pop();
  43428. num1 = stack.pop();
  43429. stack.push(buildMulOperation(num1, num2));
  43430. break;
  43431. case 'sub':
  43432. if (stack.length < 2) {
  43433. return null;
  43434. }
  43435. num2 = stack.pop();
  43436. num1 = stack.pop();
  43437. stack.push(buildSubOperation(num1, num2));
  43438. break;
  43439. case 'exch':
  43440. if (stack.length < 2) {
  43441. return null;
  43442. }
  43443. ast1 = stack.pop();
  43444. ast2 = stack.pop();
  43445. stack.push(ast1, ast2);
  43446. break;
  43447. case 'pop':
  43448. if (stack.length < 1) {
  43449. return null;
  43450. }
  43451. stack.pop();
  43452. break;
  43453. case 'index':
  43454. if (stack.length < 1) {
  43455. return null;
  43456. }
  43457. num1 = stack.pop();
  43458. if (num1.type !== 'literal') {
  43459. return null;
  43460. }
  43461. n = num1.number;
  43462. if (n < 0 || (n | 0) !== n || stack.length < n) {
  43463. return null;
  43464. }
  43465. ast1 = stack[stack.length - n - 1];
  43466. if (ast1.type === 'literal' || ast1.type === 'var') {
  43467. stack.push(ast1);
  43468. break;
  43469. }
  43470. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  43471. stack[stack.length - n - 1] = tmpVar;
  43472. stack.push(tmpVar);
  43473. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  43474. break;
  43475. case 'dup':
  43476. if (stack.length < 1) {
  43477. return null;
  43478. }
  43479. 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]) {
  43480. // special case of the commands sequence for the min operation
  43481. num1 = stack.pop();
  43482. stack.push(buildMinOperation(num1, code[i + 1]));
  43483. i += 6;
  43484. break;
  43485. }
  43486. ast1 = stack[stack.length - 1];
  43487. if (ast1.type === 'literal' || ast1.type === 'var') {
  43488. // we don't have to save into intermediate variable a literal or
  43489. // variable.
  43490. stack.push(ast1);
  43491. break;
  43492. }
  43493. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  43494. stack[stack.length - 1] = tmpVar;
  43495. stack.push(tmpVar);
  43496. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  43497. break;
  43498. case 'roll':
  43499. if (stack.length < 2) {
  43500. return null;
  43501. }
  43502. num2 = stack.pop();
  43503. num1 = stack.pop();
  43504. if (num2.type !== 'literal' || num1.type !== 'literal') {
  43505. // both roll operands must be numbers
  43506. return null;
  43507. }
  43508. j = num2.number;
  43509. n = num1.number;
  43510. if (n <= 0 || (n | 0) !== n || (j | 0) !== j || stack.length < n) {
  43511. // ... and integers
  43512. return null;
  43513. }
  43514. j = (j % n + n) % n;
  43515. if (j === 0) {
  43516. break;
  43517. }
  43518. // just skipping -- there are nothing to rotate
  43519. Array.prototype.push.apply(stack, stack.splice(stack.length - n, n - j));
  43520. break;
  43521. default:
  43522. return null;
  43523. }
  43524. }
  43525. // unsupported operator
  43526. if (stack.length !== outputSize) {
  43527. return null;
  43528. }
  43529. var result = [];
  43530. instructions.forEach(function (instruction) {
  43531. var statementBuilder = new ExpressionBuilderVisitor();
  43532. instruction.visit(statementBuilder);
  43533. result.push(statementBuilder.toString());
  43534. });
  43535. stack.forEach(function (expr, i) {
  43536. var statementBuilder = new ExpressionBuilderVisitor();
  43537. expr.visit(statementBuilder);
  43538. var min = range[i * 2], max = range[i * 2 + 1];
  43539. var out = [statementBuilder.toString()];
  43540. if (min > expr.min) {
  43541. out.unshift('Math.max(', min, ', ');
  43542. out.push(')');
  43543. }
  43544. if (max < expr.max) {
  43545. out.unshift('Math.min(', max, ', ');
  43546. out.push(')');
  43547. }
  43548. out.unshift('dest[destOffset + ', i, '] = ');
  43549. out.push(';');
  43550. result.push(out.join(''));
  43551. });
  43552. return result.join('\n');
  43553. }
  43554. };
  43555. return PostScriptCompiler;
  43556. }();
  43557. exports.isPDFFunction = isPDFFunction;
  43558. exports.PDFFunction = PDFFunction;
  43559. exports.PostScriptEvaluator = PostScriptEvaluator;
  43560. exports.PostScriptCompiler = PostScriptCompiler;
  43561. }));
  43562. (function (root, factory) {
  43563. factory(root.pdfjsCoreColorSpace = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreFunction);
  43564. }(this, function (exports, sharedUtil, corePrimitives, coreFunction) {
  43565. var error = sharedUtil.error;
  43566. var info = sharedUtil.info;
  43567. var isArray = sharedUtil.isArray;
  43568. var isString = sharedUtil.isString;
  43569. var shadow = sharedUtil.shadow;
  43570. var warn = sharedUtil.warn;
  43571. var isDict = corePrimitives.isDict;
  43572. var isName = corePrimitives.isName;
  43573. var isStream = corePrimitives.isStream;
  43574. var PDFFunction = coreFunction.PDFFunction;
  43575. var ColorSpace = function ColorSpaceClosure() {
  43576. /**
  43577. * Resizes an RGB image with 3 components.
  43578. * @param {TypedArray} src - The source buffer.
  43579. * @param {Number} bpc - Number of bits per component.
  43580. * @param {Number} w1 - Original width.
  43581. * @param {Number} h1 - Original height.
  43582. * @param {Number} w2 - New width.
  43583. * @param {Number} h2 - New height.
  43584. * @param {Number} alpha01 - Size reserved for the alpha channel.
  43585. * @param {TypedArray} dest - The destination buffer.
  43586. */
  43587. function resizeRgbImage(src, bpc, w1, h1, w2, h2, alpha01, dest) {
  43588. var COMPONENTS = 3;
  43589. alpha01 = alpha01 !== 1 ? 0 : alpha01;
  43590. var xRatio = w1 / w2;
  43591. var yRatio = h1 / h2;
  43592. var i, j, py, newIndex = 0, oldIndex;
  43593. var xScaled = new Uint16Array(w2);
  43594. var w1Scanline = w1 * COMPONENTS;
  43595. for (i = 0; i < w2; i++) {
  43596. xScaled[i] = Math.floor(i * xRatio) * COMPONENTS;
  43597. }
  43598. for (i = 0; i < h2; i++) {
  43599. py = Math.floor(i * yRatio) * w1Scanline;
  43600. for (j = 0; j < w2; j++) {
  43601. oldIndex = py + xScaled[j];
  43602. dest[newIndex++] = src[oldIndex++];
  43603. dest[newIndex++] = src[oldIndex++];
  43604. dest[newIndex++] = src[oldIndex++];
  43605. newIndex += alpha01;
  43606. }
  43607. }
  43608. }
  43609. // Constructor should define this.numComps, this.defaultColor, this.name
  43610. function ColorSpace() {
  43611. error('should not call ColorSpace constructor');
  43612. }
  43613. ColorSpace.prototype = {
  43614. /**
  43615. * Converts the color value to the RGB color. The color components are
  43616. * located in the src array starting from the srcOffset. Returns the array
  43617. * of the rgb components, each value ranging from [0,255].
  43618. */
  43619. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  43620. var rgb = new Uint8Array(3);
  43621. this.getRgbItem(src, srcOffset, rgb, 0);
  43622. return rgb;
  43623. },
  43624. /**
  43625. * Converts the color value to the RGB color, similar to the getRgb method.
  43626. * The result placed into the dest array starting from the destOffset.
  43627. */
  43628. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset, dest, destOffset) {
  43629. error('Should not call ColorSpace.getRgbItem');
  43630. },
  43631. /**
  43632. * Converts the specified number of the color values to the RGB colors.
  43633. * The colors are located in the src array starting from the srcOffset.
  43634. * The result is placed into the dest array starting from the destOffset.
  43635. * The src array items shall be in [0,2^bits) range, the dest array items
  43636. * will be in [0,255] range. alpha01 indicates how many alpha components
  43637. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  43638. * array).
  43639. */
  43640. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  43641. error('Should not call ColorSpace.getRgbBuffer');
  43642. },
  43643. /**
  43644. * Determines the number of bytes required to store the result of the
  43645. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  43646. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  43647. */
  43648. getOutputLength: function ColorSpace_getOutputLength(inputLength, alpha01) {
  43649. error('Should not call ColorSpace.getOutputLength');
  43650. },
  43651. /**
  43652. * Returns true if source data will be equal the result/output data.
  43653. */
  43654. isPassthrough: function ColorSpace_isPassthrough(bits) {
  43655. return false;
  43656. },
  43657. /**
  43658. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  43659. * how many alpha components there are in the dest array; it will be either
  43660. * 0 (RGB array) or 1 (RGBA array).
  43661. */
  43662. fillRgb: function ColorSpace_fillRgb(dest, originalWidth, originalHeight, width, height, actualHeight, bpc, comps, alpha01) {
  43663. var count = originalWidth * originalHeight;
  43664. var rgbBuf = null;
  43665. var numComponentColors = 1 << bpc;
  43666. var needsResizing = originalHeight !== height || originalWidth !== width;
  43667. var i, ii;
  43668. if (this.isPassthrough(bpc)) {
  43669. rgbBuf = comps;
  43670. } else if (this.numComps === 1 && count > numComponentColors && this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  43671. // Optimization: create a color map when there is just one component and
  43672. // we are converting more colors than the size of the color map. We
  43673. // don't build the map if the colorspace is gray or rgb since those
  43674. // methods are faster than building a map. This mainly offers big speed
  43675. // ups for indexed and alternate colorspaces.
  43676. //
  43677. // TODO it may be worth while to cache the color map. While running
  43678. // testing I never hit a cache so I will leave that out for now (perhaps
  43679. // we are reparsing colorspaces too much?).
  43680. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) : new Uint16Array(numComponentColors);
  43681. var key;
  43682. for (i = 0; i < numComponentColors; i++) {
  43683. allColors[i] = i;
  43684. }
  43685. var colorMap = new Uint8Array(numComponentColors * 3);
  43686. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc, /* alpha01 = */
  43687. 0);
  43688. var destPos, rgbPos;
  43689. if (!needsResizing) {
  43690. // Fill in the RGB values directly into |dest|.
  43691. destPos = 0;
  43692. for (i = 0; i < count; ++i) {
  43693. key = comps[i] * 3;
  43694. dest[destPos++] = colorMap[key];
  43695. dest[destPos++] = colorMap[key + 1];
  43696. dest[destPos++] = colorMap[key + 2];
  43697. destPos += alpha01;
  43698. }
  43699. } else {
  43700. rgbBuf = new Uint8Array(count * 3);
  43701. rgbPos = 0;
  43702. for (i = 0; i < count; ++i) {
  43703. key = comps[i] * 3;
  43704. rgbBuf[rgbPos++] = colorMap[key];
  43705. rgbBuf[rgbPos++] = colorMap[key + 1];
  43706. rgbBuf[rgbPos++] = colorMap[key + 2];
  43707. }
  43708. }
  43709. } else {
  43710. if (!needsResizing) {
  43711. // Fill in the RGB values directly into |dest|.
  43712. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc, alpha01);
  43713. } else {
  43714. rgbBuf = new Uint8Array(count * 3);
  43715. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc, /* alpha01 = */
  43716. 0);
  43717. }
  43718. }
  43719. if (rgbBuf) {
  43720. if (needsResizing) {
  43721. resizeRgbImage(rgbBuf, bpc, originalWidth, originalHeight, width, height, alpha01, dest);
  43722. } else {
  43723. rgbPos = 0;
  43724. destPos = 0;
  43725. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  43726. dest[destPos++] = rgbBuf[rgbPos++];
  43727. dest[destPos++] = rgbBuf[rgbPos++];
  43728. dest[destPos++] = rgbBuf[rgbPos++];
  43729. destPos += alpha01;
  43730. }
  43731. }
  43732. }
  43733. },
  43734. /**
  43735. * True if the colorspace has components in the default range of [0, 1].
  43736. * This should be true for all colorspaces except for lab color spaces
  43737. * which are [0,100], [-128, 127], [-128, 127].
  43738. */
  43739. usesZeroToOneRange: true
  43740. };
  43741. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  43742. var IR = ColorSpace.parseToIR(cs, xref, res);
  43743. if (IR instanceof AlternateCS) {
  43744. return IR;
  43745. }
  43746. return ColorSpace.fromIR(IR);
  43747. };
  43748. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  43749. var name = isArray(IR) ? IR[0] : IR;
  43750. var whitePoint, blackPoint, gamma;
  43751. switch (name) {
  43752. case 'DeviceGrayCS':
  43753. return this.singletons.gray;
  43754. case 'DeviceRgbCS':
  43755. return this.singletons.rgb;
  43756. case 'DeviceCmykCS':
  43757. return this.singletons.cmyk;
  43758. case 'CalGrayCS':
  43759. whitePoint = IR[1];
  43760. blackPoint = IR[2];
  43761. gamma = IR[3];
  43762. return new CalGrayCS(whitePoint, blackPoint, gamma);
  43763. case 'CalRGBCS':
  43764. whitePoint = IR[1];
  43765. blackPoint = IR[2];
  43766. gamma = IR[3];
  43767. var matrix = IR[4];
  43768. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  43769. case 'PatternCS':
  43770. var basePatternCS = IR[1];
  43771. if (basePatternCS) {
  43772. basePatternCS = ColorSpace.fromIR(basePatternCS);
  43773. }
  43774. return new PatternCS(basePatternCS);
  43775. case 'IndexedCS':
  43776. var baseIndexedCS = IR[1];
  43777. var hiVal = IR[2];
  43778. var lookup = IR[3];
  43779. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  43780. case 'AlternateCS':
  43781. var numComps = IR[1];
  43782. var alt = IR[2];
  43783. var tintFnIR = IR[3];
  43784. return new AlternateCS(numComps, ColorSpace.fromIR(alt), PDFFunction.fromIR(tintFnIR));
  43785. case 'LabCS':
  43786. whitePoint = IR[1];
  43787. blackPoint = IR[2];
  43788. var range = IR[3];
  43789. return new LabCS(whitePoint, blackPoint, range);
  43790. default:
  43791. error('Unknown name ' + name);
  43792. }
  43793. return null;
  43794. };
  43795. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  43796. if (isName(cs)) {
  43797. var colorSpaces = res.get('ColorSpace');
  43798. if (isDict(colorSpaces)) {
  43799. var refcs = colorSpaces.get(cs.name);
  43800. if (refcs) {
  43801. cs = refcs;
  43802. }
  43803. }
  43804. }
  43805. cs = xref.fetchIfRef(cs);
  43806. var mode;
  43807. if (isName(cs)) {
  43808. mode = cs.name;
  43809. this.mode = mode;
  43810. switch (mode) {
  43811. case 'DeviceGray':
  43812. case 'G':
  43813. return 'DeviceGrayCS';
  43814. case 'DeviceRGB':
  43815. case 'RGB':
  43816. return 'DeviceRgbCS';
  43817. case 'DeviceCMYK':
  43818. case 'CMYK':
  43819. return 'DeviceCmykCS';
  43820. case 'Pattern':
  43821. return [
  43822. 'PatternCS',
  43823. null
  43824. ];
  43825. default:
  43826. error('unrecognized colorspace ' + mode);
  43827. }
  43828. } else if (isArray(cs)) {
  43829. mode = xref.fetchIfRef(cs[0]).name;
  43830. this.mode = mode;
  43831. var numComps, params, alt, whitePoint, blackPoint, gamma;
  43832. switch (mode) {
  43833. case 'DeviceGray':
  43834. case 'G':
  43835. return 'DeviceGrayCS';
  43836. case 'DeviceRGB':
  43837. case 'RGB':
  43838. return 'DeviceRgbCS';
  43839. case 'DeviceCMYK':
  43840. case 'CMYK':
  43841. return 'DeviceCmykCS';
  43842. case 'CalGray':
  43843. params = xref.fetchIfRef(cs[1]);
  43844. whitePoint = params.getArray('WhitePoint');
  43845. blackPoint = params.getArray('BlackPoint');
  43846. gamma = params.get('Gamma');
  43847. return [
  43848. 'CalGrayCS',
  43849. whitePoint,
  43850. blackPoint,
  43851. gamma
  43852. ];
  43853. case 'CalRGB':
  43854. params = xref.fetchIfRef(cs[1]);
  43855. whitePoint = params.getArray('WhitePoint');
  43856. blackPoint = params.getArray('BlackPoint');
  43857. gamma = params.getArray('Gamma');
  43858. var matrix = params.getArray('Matrix');
  43859. return [
  43860. 'CalRGBCS',
  43861. whitePoint,
  43862. blackPoint,
  43863. gamma,
  43864. matrix
  43865. ];
  43866. case 'ICCBased':
  43867. var stream = xref.fetchIfRef(cs[1]);
  43868. var dict = stream.dict;
  43869. numComps = dict.get('N');
  43870. alt = dict.get('Alternate');
  43871. if (alt) {
  43872. var altIR = ColorSpace.parseToIR(alt, xref, res);
  43873. // Parse the /Alternate CS to ensure that the number of components
  43874. // are correct, and also (indirectly) that it is not a PatternCS.
  43875. var altCS = ColorSpace.fromIR(altIR);
  43876. if (altCS.numComps === numComps) {
  43877. return altIR;
  43878. }
  43879. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  43880. }
  43881. if (numComps === 1) {
  43882. return 'DeviceGrayCS';
  43883. } else if (numComps === 3) {
  43884. return 'DeviceRgbCS';
  43885. } else if (numComps === 4) {
  43886. return 'DeviceCmykCS';
  43887. }
  43888. break;
  43889. case 'Pattern':
  43890. var basePatternCS = cs[1] || null;
  43891. if (basePatternCS) {
  43892. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  43893. }
  43894. return [
  43895. 'PatternCS',
  43896. basePatternCS
  43897. ];
  43898. case 'Indexed':
  43899. case 'I':
  43900. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  43901. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  43902. var lookup = xref.fetchIfRef(cs[3]);
  43903. if (isStream(lookup)) {
  43904. lookup = lookup.getBytes();
  43905. }
  43906. return [
  43907. 'IndexedCS',
  43908. baseIndexedCS,
  43909. hiVal,
  43910. lookup
  43911. ];
  43912. case 'Separation':
  43913. case 'DeviceN':
  43914. var name = xref.fetchIfRef(cs[1]);
  43915. numComps = 1;
  43916. if (isName(name)) {
  43917. numComps = 1;
  43918. } else if (isArray(name)) {
  43919. numComps = name.length;
  43920. }
  43921. alt = ColorSpace.parseToIR(cs[2], xref, res);
  43922. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  43923. return [
  43924. 'AlternateCS',
  43925. numComps,
  43926. alt,
  43927. tintFnIR
  43928. ];
  43929. case 'Lab':
  43930. params = xref.fetchIfRef(cs[1]);
  43931. whitePoint = params.getArray('WhitePoint');
  43932. blackPoint = params.getArray('BlackPoint');
  43933. var range = params.getArray('Range');
  43934. return [
  43935. 'LabCS',
  43936. whitePoint,
  43937. blackPoint,
  43938. range
  43939. ];
  43940. default:
  43941. error('unimplemented color space object "' + mode + '"');
  43942. }
  43943. } else {
  43944. error('unrecognized color space object: "' + cs + '"');
  43945. }
  43946. return null;
  43947. };
  43948. /**
  43949. * Checks if a decode map matches the default decode map for a color space.
  43950. * This handles the general decode maps where there are two values per
  43951. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  43952. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  43953. * slightly different.
  43954. * @param {Array} decode Decode map (usually from an image).
  43955. * @param {Number} n Number of components the color space has.
  43956. */
  43957. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  43958. if (!isArray(decode)) {
  43959. return true;
  43960. }
  43961. if (n * 2 !== decode.length) {
  43962. warn('The decode map is not the correct length');
  43963. return true;
  43964. }
  43965. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  43966. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  43967. return false;
  43968. }
  43969. }
  43970. return true;
  43971. };
  43972. ColorSpace.singletons = {
  43973. get gray() {
  43974. return shadow(this, 'gray', new DeviceGrayCS());
  43975. },
  43976. get rgb() {
  43977. return shadow(this, 'rgb', new DeviceRgbCS());
  43978. },
  43979. get cmyk() {
  43980. return shadow(this, 'cmyk', new DeviceCmykCS());
  43981. }
  43982. };
  43983. return ColorSpace;
  43984. }();
  43985. /**
  43986. * Alternate color space handles both Separation and DeviceN color spaces. A
  43987. * Separation color space is actually just a DeviceN with one color component.
  43988. * Both color spaces use a tinting function to convert colors to a base color
  43989. * space.
  43990. */
  43991. var AlternateCS = function AlternateCSClosure() {
  43992. function AlternateCS(numComps, base, tintFn) {
  43993. this.name = 'Alternate';
  43994. this.numComps = numComps;
  43995. this.defaultColor = new Float32Array(numComps);
  43996. for (var i = 0; i < numComps; ++i) {
  43997. this.defaultColor[i] = 1;
  43998. }
  43999. this.base = base;
  44000. this.tintFn = tintFn;
  44001. this.tmpBuf = new Float32Array(base.numComps);
  44002. }
  44003. AlternateCS.prototype = {
  44004. getRgb: ColorSpace.prototype.getRgb,
  44005. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset, dest, destOffset) {
  44006. var tmpBuf = this.tmpBuf;
  44007. this.tintFn(src, srcOffset, tmpBuf, 0);
  44008. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  44009. },
  44010. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  44011. var tintFn = this.tintFn;
  44012. var base = this.base;
  44013. var scale = 1 / ((1 << bits) - 1);
  44014. var baseNumComps = base.numComps;
  44015. var usesZeroToOneRange = base.usesZeroToOneRange;
  44016. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) && alpha01 === 0;
  44017. var pos = isPassthrough ? destOffset : 0;
  44018. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  44019. var numComps = this.numComps;
  44020. var scaled = new Float32Array(numComps);
  44021. var tinted = new Float32Array(baseNumComps);
  44022. var i, j;
  44023. if (usesZeroToOneRange) {
  44024. for (i = 0; i < count; i++) {
  44025. for (j = 0; j < numComps; j++) {
  44026. scaled[j] = src[srcOffset++] * scale;
  44027. }
  44028. tintFn(scaled, 0, tinted, 0);
  44029. for (j = 0; j < baseNumComps; j++) {
  44030. baseBuf[pos++] = tinted[j] * 255;
  44031. }
  44032. }
  44033. } else {
  44034. for (i = 0; i < count; i++) {
  44035. for (j = 0; j < numComps; j++) {
  44036. scaled[j] = src[srcOffset++] * scale;
  44037. }
  44038. tintFn(scaled, 0, tinted, 0);
  44039. base.getRgbItem(tinted, 0, baseBuf, pos);
  44040. pos += baseNumComps;
  44041. }
  44042. }
  44043. if (!isPassthrough) {
  44044. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  44045. }
  44046. },
  44047. getOutputLength: function AlternateCS_getOutputLength(inputLength, alpha01) {
  44048. return this.base.getOutputLength(inputLength * this.base.numComps / this.numComps, alpha01);
  44049. },
  44050. isPassthrough: ColorSpace.prototype.isPassthrough,
  44051. fillRgb: ColorSpace.prototype.fillRgb,
  44052. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  44053. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  44054. },
  44055. usesZeroToOneRange: true
  44056. };
  44057. return AlternateCS;
  44058. }();
  44059. var PatternCS = function PatternCSClosure() {
  44060. function PatternCS(baseCS) {
  44061. this.name = 'Pattern';
  44062. this.base = baseCS;
  44063. }
  44064. PatternCS.prototype = {};
  44065. return PatternCS;
  44066. }();
  44067. var IndexedCS = function IndexedCSClosure() {
  44068. function IndexedCS(base, highVal, lookup) {
  44069. this.name = 'Indexed';
  44070. this.numComps = 1;
  44071. this.defaultColor = new Uint8Array([0]);
  44072. this.base = base;
  44073. this.highVal = highVal;
  44074. var baseNumComps = base.numComps;
  44075. var length = baseNumComps * highVal;
  44076. var lookupArray;
  44077. if (isStream(lookup)) {
  44078. lookupArray = new Uint8Array(length);
  44079. var bytes = lookup.getBytes(length);
  44080. lookupArray.set(bytes);
  44081. } else if (isString(lookup)) {
  44082. lookupArray = new Uint8Array(length);
  44083. for (var i = 0; i < length; ++i) {
  44084. lookupArray[i] = lookup.charCodeAt(i);
  44085. }
  44086. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  44087. lookupArray = lookup;
  44088. } else {
  44089. error('Unrecognized lookup table: ' + lookup);
  44090. }
  44091. this.lookup = lookupArray;
  44092. }
  44093. IndexedCS.prototype = {
  44094. getRgb: ColorSpace.prototype.getRgb,
  44095. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset, dest, destOffset) {
  44096. var numComps = this.base.numComps;
  44097. var start = src[srcOffset] * numComps;
  44098. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  44099. },
  44100. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  44101. var base = this.base;
  44102. var numComps = base.numComps;
  44103. var outputDelta = base.getOutputLength(numComps, alpha01);
  44104. var lookup = this.lookup;
  44105. for (var i = 0; i < count; ++i) {
  44106. var lookupPos = src[srcOffset++] * numComps;
  44107. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  44108. destOffset += outputDelta;
  44109. }
  44110. },
  44111. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  44112. return this.base.getOutputLength(inputLength * this.base.numComps, alpha01);
  44113. },
  44114. isPassthrough: ColorSpace.prototype.isPassthrough,
  44115. fillRgb: ColorSpace.prototype.fillRgb,
  44116. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  44117. // indexed color maps shouldn't be changed
  44118. return true;
  44119. },
  44120. usesZeroToOneRange: true
  44121. };
  44122. return IndexedCS;
  44123. }();
  44124. var DeviceGrayCS = function DeviceGrayCSClosure() {
  44125. function DeviceGrayCS() {
  44126. this.name = 'DeviceGray';
  44127. this.numComps = 1;
  44128. this.defaultColor = new Float32Array([0]);
  44129. }
  44130. DeviceGrayCS.prototype = {
  44131. getRgb: ColorSpace.prototype.getRgb,
  44132. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset, dest, destOffset) {
  44133. var c = src[srcOffset] * 255 | 0;
  44134. c = c < 0 ? 0 : c > 255 ? 255 : c;
  44135. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  44136. },
  44137. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  44138. var scale = 255 / ((1 << bits) - 1);
  44139. var j = srcOffset, q = destOffset;
  44140. for (var i = 0; i < count; ++i) {
  44141. var c = scale * src[j++] | 0;
  44142. dest[q++] = c;
  44143. dest[q++] = c;
  44144. dest[q++] = c;
  44145. q += alpha01;
  44146. }
  44147. },
  44148. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength, alpha01) {
  44149. return inputLength * (3 + alpha01);
  44150. },
  44151. isPassthrough: ColorSpace.prototype.isPassthrough,
  44152. fillRgb: ColorSpace.prototype.fillRgb,
  44153. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  44154. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  44155. },
  44156. usesZeroToOneRange: true
  44157. };
  44158. return DeviceGrayCS;
  44159. }();
  44160. var DeviceRgbCS = function DeviceRgbCSClosure() {
  44161. function DeviceRgbCS() {
  44162. this.name = 'DeviceRGB';
  44163. this.numComps = 3;
  44164. this.defaultColor = new Float32Array([
  44165. 0,
  44166. 0,
  44167. 0
  44168. ]);
  44169. }
  44170. DeviceRgbCS.prototype = {
  44171. getRgb: ColorSpace.prototype.getRgb,
  44172. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset, dest, destOffset) {
  44173. var r = src[srcOffset] * 255 | 0;
  44174. var g = src[srcOffset + 1] * 255 | 0;
  44175. var b = src[srcOffset + 2] * 255 | 0;
  44176. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  44177. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  44178. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  44179. },
  44180. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  44181. if (bits === 8 && alpha01 === 0) {
  44182. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  44183. return;
  44184. }
  44185. var scale = 255 / ((1 << bits) - 1);
  44186. var j = srcOffset, q = destOffset;
  44187. for (var i = 0; i < count; ++i) {
  44188. dest[q++] = scale * src[j++] | 0;
  44189. dest[q++] = scale * src[j++] | 0;
  44190. dest[q++] = scale * src[j++] | 0;
  44191. q += alpha01;
  44192. }
  44193. },
  44194. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength, alpha01) {
  44195. return inputLength * (3 + alpha01) / 3 | 0;
  44196. },
  44197. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  44198. return bits === 8;
  44199. },
  44200. fillRgb: ColorSpace.prototype.fillRgb,
  44201. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  44202. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  44203. },
  44204. usesZeroToOneRange: true
  44205. };
  44206. return DeviceRgbCS;
  44207. }();
  44208. var DeviceCmykCS = function DeviceCmykCSClosure() {
  44209. // The coefficients below was found using numerical analysis: the method of
  44210. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  44211. // where color_value is the tabular value from the table of sampled RGB colors
  44212. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  44213. // CMYK color conversion using the estimation below:
  44214. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  44215. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  44216. var c = src[srcOffset + 0] * srcScale;
  44217. var m = src[srcOffset + 1] * srcScale;
  44218. var y = src[srcOffset + 2] * srcScale;
  44219. var k = src[srcOffset + 3] * srcScale;
  44220. 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;
  44221. 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;
  44222. 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;
  44223. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  44224. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  44225. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  44226. }
  44227. function DeviceCmykCS() {
  44228. this.name = 'DeviceCMYK';
  44229. this.numComps = 4;
  44230. this.defaultColor = new Float32Array([
  44231. 0,
  44232. 0,
  44233. 0,
  44234. 1
  44235. ]);
  44236. }
  44237. DeviceCmykCS.prototype = {
  44238. getRgb: ColorSpace.prototype.getRgb,
  44239. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset, dest, destOffset) {
  44240. convertToRgb(src, srcOffset, 1, dest, destOffset);
  44241. },
  44242. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  44243. var scale = 1 / ((1 << bits) - 1);
  44244. for (var i = 0; i < count; i++) {
  44245. convertToRgb(src, srcOffset, scale, dest, destOffset);
  44246. srcOffset += 4;
  44247. destOffset += 3 + alpha01;
  44248. }
  44249. },
  44250. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength, alpha01) {
  44251. return inputLength / 4 * (3 + alpha01) | 0;
  44252. },
  44253. isPassthrough: ColorSpace.prototype.isPassthrough,
  44254. fillRgb: ColorSpace.prototype.fillRgb,
  44255. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  44256. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  44257. },
  44258. usesZeroToOneRange: true
  44259. };
  44260. return DeviceCmykCS;
  44261. }();
  44262. //
  44263. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  44264. //
  44265. var CalGrayCS = function CalGrayCSClosure() {
  44266. function CalGrayCS(whitePoint, blackPoint, gamma) {
  44267. this.name = 'CalGray';
  44268. this.numComps = 1;
  44269. this.defaultColor = new Float32Array([0]);
  44270. if (!whitePoint) {
  44271. error('WhitePoint missing - required for color space CalGray');
  44272. }
  44273. blackPoint = blackPoint || [
  44274. 0,
  44275. 0,
  44276. 0
  44277. ];
  44278. gamma = gamma || 1;
  44279. // Translate arguments to spec variables.
  44280. this.XW = whitePoint[0];
  44281. this.YW = whitePoint[1];
  44282. this.ZW = whitePoint[2];
  44283. this.XB = blackPoint[0];
  44284. this.YB = blackPoint[1];
  44285. this.ZB = blackPoint[2];
  44286. this.G = gamma;
  44287. // Validate variables as per spec.
  44288. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  44289. error('Invalid WhitePoint components for ' + this.name + ', no fallback available');
  44290. }
  44291. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  44292. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  44293. this.XB = this.YB = this.ZB = 0;
  44294. }
  44295. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  44296. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB + ', ZB: ' + this.ZB + ', only default values are supported.');
  44297. }
  44298. if (this.G < 1) {
  44299. info('Invalid Gamma: ' + this.G + ' for ' + this.name + ', falling back to default');
  44300. this.G = 1;
  44301. }
  44302. }
  44303. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  44304. // A represents a gray component of a calibrated gray space.
  44305. // A <---> AG in the spec
  44306. var A = src[srcOffset] * scale;
  44307. var AG = Math.pow(A, cs.G);
  44308. // Computes L as per spec. ( = cs.YW * AG )
  44309. // Except if other than default BlackPoint values are used.
  44310. var L = cs.YW * AG;
  44311. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  44312. // Convert values to rgb range [0, 255].
  44313. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  44314. dest[destOffset] = val;
  44315. dest[destOffset + 1] = val;
  44316. dest[destOffset + 2] = val;
  44317. }
  44318. CalGrayCS.prototype = {
  44319. getRgb: ColorSpace.prototype.getRgb,
  44320. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset, dest, destOffset) {
  44321. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  44322. },
  44323. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  44324. var scale = 1 / ((1 << bits) - 1);
  44325. for (var i = 0; i < count; ++i) {
  44326. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  44327. srcOffset += 1;
  44328. destOffset += 3 + alpha01;
  44329. }
  44330. },
  44331. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  44332. return inputLength * (3 + alpha01);
  44333. },
  44334. isPassthrough: ColorSpace.prototype.isPassthrough,
  44335. fillRgb: ColorSpace.prototype.fillRgb,
  44336. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  44337. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  44338. },
  44339. usesZeroToOneRange: true
  44340. };
  44341. return CalGrayCS;
  44342. }();
  44343. //
  44344. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  44345. //
  44346. var CalRGBCS = function CalRGBCSClosure() {
  44347. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  44348. // matrices.
  44349. var BRADFORD_SCALE_MATRIX = new Float32Array([
  44350. 0.8951,
  44351. 0.2664,
  44352. -0.1614,
  44353. -0.7502,
  44354. 1.7135,
  44355. 0.0367,
  44356. 0.0389,
  44357. -0.0685,
  44358. 1.0296
  44359. ]);
  44360. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  44361. 0.9869929,
  44362. -0.1470543,
  44363. 0.1599627,
  44364. 0.4323053,
  44365. 0.5183603,
  44366. 0.0492912,
  44367. -0.0085287,
  44368. 0.0400428,
  44369. 0.9684867
  44370. ]);
  44371. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  44372. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  44373. 3.2404542,
  44374. -1.5371385,
  44375. -0.4985314,
  44376. -0.9692660,
  44377. 1.8760108,
  44378. 0.0415560,
  44379. 0.0556434,
  44380. -0.2040259,
  44381. 1.0572252
  44382. ]);
  44383. var FLAT_WHITEPOINT_MATRIX = new Float32Array([
  44384. 1,
  44385. 1,
  44386. 1
  44387. ]);
  44388. var tempNormalizeMatrix = new Float32Array(3);
  44389. var tempConvertMatrix1 = new Float32Array(3);
  44390. var tempConvertMatrix2 = new Float32Array(3);
  44391. var DECODE_L_CONSTANT = Math.pow((8 + 16) / 116, 3) / 8.0;
  44392. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  44393. this.name = 'CalRGB';
  44394. this.numComps = 3;
  44395. this.defaultColor = new Float32Array(3);
  44396. if (!whitePoint) {
  44397. error('WhitePoint missing - required for color space CalRGB');
  44398. }
  44399. blackPoint = blackPoint || new Float32Array(3);
  44400. gamma = gamma || new Float32Array([
  44401. 1,
  44402. 1,
  44403. 1
  44404. ]);
  44405. matrix = matrix || new Float32Array([
  44406. 1,
  44407. 0,
  44408. 0,
  44409. 0,
  44410. 1,
  44411. 0,
  44412. 0,
  44413. 0,
  44414. 1
  44415. ]);
  44416. // Translate arguments to spec variables.
  44417. var XW = whitePoint[0];
  44418. var YW = whitePoint[1];
  44419. var ZW = whitePoint[2];
  44420. this.whitePoint = whitePoint;
  44421. var XB = blackPoint[0];
  44422. var YB = blackPoint[1];
  44423. var ZB = blackPoint[2];
  44424. this.blackPoint = blackPoint;
  44425. this.GR = gamma[0];
  44426. this.GG = gamma[1];
  44427. this.GB = gamma[2];
  44428. this.MXA = matrix[0];
  44429. this.MYA = matrix[1];
  44430. this.MZA = matrix[2];
  44431. this.MXB = matrix[3];
  44432. this.MYB = matrix[4];
  44433. this.MZB = matrix[5];
  44434. this.MXC = matrix[6];
  44435. this.MYC = matrix[7];
  44436. this.MZC = matrix[8];
  44437. // Validate variables as per spec.
  44438. if (XW < 0 || ZW < 0 || YW !== 1) {
  44439. error('Invalid WhitePoint components for ' + this.name + ', no fallback available');
  44440. }
  44441. if (XB < 0 || YB < 0 || ZB < 0) {
  44442. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB + ', ' + ZB + '], falling back to default');
  44443. this.blackPoint = new Float32Array(3);
  44444. }
  44445. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  44446. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB + '] for ' + this.name + ', falling back to default');
  44447. this.GR = this.GG = this.GB = 1;
  44448. }
  44449. 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) {
  44450. 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');
  44451. this.MXA = this.MYB = this.MZC = 1;
  44452. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  44453. }
  44454. }
  44455. function matrixProduct(a, b, result) {
  44456. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  44457. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  44458. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  44459. }
  44460. function convertToFlat(sourceWhitePoint, LMS, result) {
  44461. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  44462. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  44463. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  44464. }
  44465. function convertToD65(sourceWhitePoint, LMS, result) {
  44466. var D65X = 0.95047;
  44467. var D65Y = 1;
  44468. var D65Z = 1.08883;
  44469. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  44470. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  44471. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  44472. }
  44473. function sRGBTransferFunction(color) {
  44474. // See http://en.wikipedia.org/wiki/SRGB.
  44475. if (color <= 0.0031308) {
  44476. return adjustToRange(0, 1, 12.92 * color);
  44477. }
  44478. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  44479. }
  44480. function adjustToRange(min, max, value) {
  44481. return Math.max(min, Math.min(max, value));
  44482. }
  44483. function decodeL(L) {
  44484. if (L < 0) {
  44485. return -decodeL(-L);
  44486. }
  44487. if (L > 8.0) {
  44488. return Math.pow((L + 16) / 116, 3);
  44489. }
  44490. return L * DECODE_L_CONSTANT;
  44491. }
  44492. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  44493. // In case the blackPoint is already the default blackPoint then there is
  44494. // no need to do compensation.
  44495. if (sourceBlackPoint[0] === 0 && sourceBlackPoint[1] === 0 && sourceBlackPoint[2] === 0) {
  44496. result[0] = XYZ_Flat[0];
  44497. result[1] = XYZ_Flat[1];
  44498. result[2] = XYZ_Flat[2];
  44499. return;
  44500. }
  44501. // For the blackPoint calculation details, please see
  44502. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  44503. // AdobeBPC.pdf.
  44504. // The destination blackPoint is the default blackPoint [0, 0, 0].
  44505. var zeroDecodeL = decodeL(0);
  44506. var X_DST = zeroDecodeL;
  44507. var X_SRC = decodeL(sourceBlackPoint[0]);
  44508. var Y_DST = zeroDecodeL;
  44509. var Y_SRC = decodeL(sourceBlackPoint[1]);
  44510. var Z_DST = zeroDecodeL;
  44511. var Z_SRC = decodeL(sourceBlackPoint[2]);
  44512. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  44513. var X_Offset = 1 - X_Scale;
  44514. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  44515. var Y_Offset = 1 - Y_Scale;
  44516. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  44517. var Z_Offset = 1 - Z_Scale;
  44518. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  44519. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  44520. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  44521. }
  44522. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  44523. // In case the whitePoint is already flat then there is no need to do
  44524. // normalization.
  44525. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  44526. result[0] = XYZ_In[0];
  44527. result[1] = XYZ_In[1];
  44528. result[2] = XYZ_In[2];
  44529. return;
  44530. }
  44531. var LMS = result;
  44532. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  44533. var LMS_Flat = tempNormalizeMatrix;
  44534. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  44535. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  44536. }
  44537. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  44538. var LMS = result;
  44539. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  44540. var LMS_D65 = tempNormalizeMatrix;
  44541. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  44542. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  44543. }
  44544. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  44545. // A, B and C represent a red, green and blue components of a calibrated
  44546. // rgb space.
  44547. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  44548. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  44549. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  44550. // A <---> AGR in the spec
  44551. // B <---> BGG in the spec
  44552. // C <---> CGB in the spec
  44553. var AGR = Math.pow(A, cs.GR);
  44554. var BGG = Math.pow(B, cs.GG);
  44555. var CGB = Math.pow(C, cs.GB);
  44556. // Computes intermediate variables L, M, N as per spec.
  44557. // To decode X, Y, Z values map L, M, N directly to them.
  44558. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  44559. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  44560. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  44561. // The following calculations are based on this document:
  44562. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  44563. // AdobeBPC.pdf.
  44564. var XYZ = tempConvertMatrix1;
  44565. XYZ[0] = X;
  44566. XYZ[1] = Y;
  44567. XYZ[2] = Z;
  44568. var XYZ_Flat = tempConvertMatrix2;
  44569. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  44570. var XYZ_Black = tempConvertMatrix1;
  44571. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  44572. var XYZ_D65 = tempConvertMatrix2;
  44573. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  44574. var SRGB = tempConvertMatrix1;
  44575. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  44576. var sR = sRGBTransferFunction(SRGB[0]);
  44577. var sG = sRGBTransferFunction(SRGB[1]);
  44578. var sB = sRGBTransferFunction(SRGB[2]);
  44579. // Convert the values to rgb range [0, 255].
  44580. dest[destOffset] = Math.round(sR * 255);
  44581. dest[destOffset + 1] = Math.round(sG * 255);
  44582. dest[destOffset + 2] = Math.round(sB * 255);
  44583. }
  44584. CalRGBCS.prototype = {
  44585. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  44586. var rgb = new Uint8Array(3);
  44587. this.getRgbItem(src, srcOffset, rgb, 0);
  44588. return rgb;
  44589. },
  44590. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset, dest, destOffset) {
  44591. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  44592. },
  44593. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  44594. var scale = 1 / ((1 << bits) - 1);
  44595. for (var i = 0; i < count; ++i) {
  44596. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  44597. srcOffset += 3;
  44598. destOffset += 3 + alpha01;
  44599. }
  44600. },
  44601. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  44602. return inputLength * (3 + alpha01) / 3 | 0;
  44603. },
  44604. isPassthrough: ColorSpace.prototype.isPassthrough,
  44605. fillRgb: ColorSpace.prototype.fillRgb,
  44606. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  44607. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  44608. },
  44609. usesZeroToOneRange: true
  44610. };
  44611. return CalRGBCS;
  44612. }();
  44613. //
  44614. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  44615. //
  44616. var LabCS = function LabCSClosure() {
  44617. function LabCS(whitePoint, blackPoint, range) {
  44618. this.name = 'Lab';
  44619. this.numComps = 3;
  44620. this.defaultColor = new Float32Array([
  44621. 0,
  44622. 0,
  44623. 0
  44624. ]);
  44625. if (!whitePoint) {
  44626. error('WhitePoint missing - required for color space Lab');
  44627. }
  44628. blackPoint = blackPoint || [
  44629. 0,
  44630. 0,
  44631. 0
  44632. ];
  44633. range = range || [
  44634. -100,
  44635. 100,
  44636. -100,
  44637. 100
  44638. ];
  44639. // Translate args to spec variables
  44640. this.XW = whitePoint[0];
  44641. this.YW = whitePoint[1];
  44642. this.ZW = whitePoint[2];
  44643. this.amin = range[0];
  44644. this.amax = range[1];
  44645. this.bmin = range[2];
  44646. this.bmax = range[3];
  44647. // These are here just for completeness - the spec doesn't offer any
  44648. // formulas that use BlackPoint in Lab
  44649. this.XB = blackPoint[0];
  44650. this.YB = blackPoint[1];
  44651. this.ZB = blackPoint[2];
  44652. // Validate vars as per spec
  44653. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  44654. error('Invalid WhitePoint components, no fallback available');
  44655. }
  44656. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  44657. info('Invalid BlackPoint, falling back to default');
  44658. this.XB = this.YB = this.ZB = 0;
  44659. }
  44660. if (this.amin > this.amax || this.bmin > this.bmax) {
  44661. info('Invalid Range, falling back to defaults');
  44662. this.amin = -100;
  44663. this.amax = 100;
  44664. this.bmin = -100;
  44665. this.bmax = 100;
  44666. }
  44667. }
  44668. // Function g(x) from spec
  44669. function fn_g(x) {
  44670. if (x >= 6 / 29) {
  44671. return x * x * x;
  44672. } else {
  44673. return 108 / 841 * (x - 4 / 29);
  44674. }
  44675. }
  44676. function decode(value, high1, low2, high2) {
  44677. return low2 + value * (high2 - low2) / high1;
  44678. }
  44679. // If decoding is needed maxVal should be 2^bits per component - 1.
  44680. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  44681. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  44682. // not the usual [0, 1]. If a command like setFillColor is used the src
  44683. // values will already be within the correct range. However, if we are
  44684. // converting an image we have to map the values to the correct range given
  44685. // above.
  44686. // Ls,as,bs <---> L*,a*,b* in the spec
  44687. var Ls = src[srcOffset];
  44688. var as = src[srcOffset + 1];
  44689. var bs = src[srcOffset + 2];
  44690. if (maxVal !== false) {
  44691. Ls = decode(Ls, maxVal, 0, 100);
  44692. as = decode(as, maxVal, cs.amin, cs.amax);
  44693. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  44694. }
  44695. // Adjust limits of 'as' and 'bs'
  44696. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  44697. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  44698. // Computes intermediate variables X,Y,Z as per spec
  44699. var M = (Ls + 16) / 116;
  44700. var L = M + as / 500;
  44701. var N = M - bs / 200;
  44702. var X = cs.XW * fn_g(L);
  44703. var Y = cs.YW * fn_g(M);
  44704. var Z = cs.ZW * fn_g(N);
  44705. var r, g, b;
  44706. // Using different conversions for D50 and D65 white points,
  44707. // per http://www.color.org/srgb.pdf
  44708. if (cs.ZW < 1) {
  44709. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  44710. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  44711. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  44712. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  44713. } else {
  44714. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  44715. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  44716. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  44717. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  44718. }
  44719. // clamp color values to [0,1] range then convert to [0,255] range.
  44720. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  44721. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  44722. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  44723. }
  44724. LabCS.prototype = {
  44725. getRgb: ColorSpace.prototype.getRgb,
  44726. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  44727. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  44728. },
  44729. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count, dest, destOffset, bits, alpha01) {
  44730. var maxVal = (1 << bits) - 1;
  44731. for (var i = 0; i < count; i++) {
  44732. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  44733. srcOffset += 3;
  44734. destOffset += 3 + alpha01;
  44735. }
  44736. },
  44737. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  44738. return inputLength * (3 + alpha01) / 3 | 0;
  44739. },
  44740. isPassthrough: ColorSpace.prototype.isPassthrough,
  44741. fillRgb: ColorSpace.prototype.fillRgb,
  44742. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  44743. // XXX: Decoding is handled with the lab conversion because of the strange
  44744. // ranges that are used.
  44745. return true;
  44746. },
  44747. usesZeroToOneRange: false
  44748. };
  44749. return LabCS;
  44750. }();
  44751. exports.ColorSpace = ColorSpace;
  44752. }));
  44753. (function (root, factory) {
  44754. factory(root.pdfjsCoreImage = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreColorSpace, root.pdfjsCoreStream, root.pdfjsCoreJpx);
  44755. }(this, function (exports, sharedUtil, corePrimitives, coreColorSpace, coreStream, coreJpx) {
  44756. var ImageKind = sharedUtil.ImageKind;
  44757. var assert = sharedUtil.assert;
  44758. var error = sharedUtil.error;
  44759. var info = sharedUtil.info;
  44760. var isArray = sharedUtil.isArray;
  44761. var warn = sharedUtil.warn;
  44762. var Name = corePrimitives.Name;
  44763. var isStream = corePrimitives.isStream;
  44764. var ColorSpace = coreColorSpace.ColorSpace;
  44765. var DecodeStream = coreStream.DecodeStream;
  44766. var JpegStream = coreStream.JpegStream;
  44767. var JpxImage = coreJpx.JpxImage;
  44768. var PDFImage = function PDFImageClosure() {
  44769. /**
  44770. * Decodes the image using native decoder if possible. Resolves the promise
  44771. * when the image data is ready.
  44772. */
  44773. function handleImageData(image, nativeDecoder) {
  44774. if (nativeDecoder && nativeDecoder.canDecode(image)) {
  44775. return nativeDecoder.decode(image);
  44776. } else {
  44777. return Promise.resolve(image);
  44778. }
  44779. }
  44780. /**
  44781. * Decode and clamp a value. The formula is different from the spec because we
  44782. * don't decode to float range [0,1], we decode it in the [0,max] range.
  44783. */
  44784. function decodeAndClamp(value, addend, coefficient, max) {
  44785. value = addend + value * coefficient;
  44786. // Clamp the value to the range
  44787. return value < 0 ? 0 : value > max ? max : value;
  44788. }
  44789. /**
  44790. * Resizes an image mask with 1 component.
  44791. * @param {TypedArray} src - The source buffer.
  44792. * @param {Number} bpc - Number of bits per component.
  44793. * @param {Number} w1 - Original width.
  44794. * @param {Number} h1 - Original height.
  44795. * @param {Number} w2 - New width.
  44796. * @param {Number} h2 - New height.
  44797. * @returns {TypedArray} The resized image mask buffer.
  44798. */
  44799. function resizeImageMask(src, bpc, w1, h1, w2, h2) {
  44800. var length = w2 * h2;
  44801. var dest = bpc <= 8 ? new Uint8Array(length) : bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length);
  44802. var xRatio = w1 / w2;
  44803. var yRatio = h1 / h2;
  44804. var i, j, py, newIndex = 0, oldIndex;
  44805. var xScaled = new Uint16Array(w2);
  44806. var w1Scanline = w1;
  44807. for (i = 0; i < w2; i++) {
  44808. xScaled[i] = Math.floor(i * xRatio);
  44809. }
  44810. for (i = 0; i < h2; i++) {
  44811. py = Math.floor(i * yRatio) * w1Scanline;
  44812. for (j = 0; j < w2; j++) {
  44813. oldIndex = py + xScaled[j];
  44814. dest[newIndex++] = src[oldIndex];
  44815. }
  44816. }
  44817. return dest;
  44818. }
  44819. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  44820. this.image = image;
  44821. var dict = image.dict;
  44822. if (dict.has('Filter')) {
  44823. var filter = dict.get('Filter').name;
  44824. if (filter === 'JPXDecode') {
  44825. var jpxImage = new JpxImage();
  44826. jpxImage.parseImageProperties(image.stream);
  44827. image.stream.reset();
  44828. image.bitsPerComponent = jpxImage.bitsPerComponent;
  44829. image.numComps = jpxImage.componentsCount;
  44830. } else if (filter === 'JBIG2Decode') {
  44831. image.bitsPerComponent = 1;
  44832. image.numComps = 1;
  44833. }
  44834. }
  44835. // TODO cache rendered images?
  44836. this.width = dict.get('Width', 'W');
  44837. this.height = dict.get('Height', 'H');
  44838. if (this.width < 1 || this.height < 1) {
  44839. error('Invalid image width: ' + this.width + ' or height: ' + this.height);
  44840. }
  44841. this.interpolate = dict.get('Interpolate', 'I') || false;
  44842. this.imageMask = dict.get('ImageMask', 'IM') || false;
  44843. this.matte = dict.get('Matte') || false;
  44844. var bitsPerComponent = image.bitsPerComponent;
  44845. if (!bitsPerComponent) {
  44846. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  44847. if (!bitsPerComponent) {
  44848. if (this.imageMask) {
  44849. bitsPerComponent = 1;
  44850. } else {
  44851. error('Bits per component missing in image: ' + this.imageMask);
  44852. }
  44853. }
  44854. }
  44855. this.bpc = bitsPerComponent;
  44856. if (!this.imageMask) {
  44857. var colorSpace = dict.get('ColorSpace', 'CS');
  44858. if (!colorSpace) {
  44859. info('JPX images (which do not require color spaces)');
  44860. switch (image.numComps) {
  44861. case 1:
  44862. colorSpace = Name.get('DeviceGray');
  44863. break;
  44864. case 3:
  44865. colorSpace = Name.get('DeviceRGB');
  44866. break;
  44867. case 4:
  44868. colorSpace = Name.get('DeviceCMYK');
  44869. break;
  44870. default:
  44871. error('JPX images with ' + this.numComps + ' color components not supported.');
  44872. }
  44873. }
  44874. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  44875. this.numComps = this.colorSpace.numComps;
  44876. }
  44877. this.decode = dict.getArray('Decode', 'D');
  44878. this.needsDecode = false;
  44879. if (this.decode && (this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode) || isMask && !ColorSpace.isDefaultDecode(this.decode, 1))) {
  44880. this.needsDecode = true;
  44881. // Do some preprocessing to avoid more math.
  44882. var max = (1 << bitsPerComponent) - 1;
  44883. this.decodeCoefficients = [];
  44884. this.decodeAddends = [];
  44885. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  44886. var dmin = this.decode[i];
  44887. var dmax = this.decode[i + 1];
  44888. this.decodeCoefficients[j] = dmax - dmin;
  44889. this.decodeAddends[j] = max * dmin;
  44890. }
  44891. }
  44892. if (smask) {
  44893. this.smask = new PDFImage(xref, res, smask, false);
  44894. } else if (mask) {
  44895. if (isStream(mask)) {
  44896. var maskDict = mask.dict, imageMask = maskDict.get('ImageMask', 'IM');
  44897. if (!imageMask) {
  44898. warn('Ignoring /Mask in image without /ImageMask.');
  44899. } else {
  44900. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  44901. }
  44902. } else {
  44903. // Color key mask (just an array).
  44904. this.mask = mask;
  44905. }
  44906. }
  44907. }
  44908. /**
  44909. * Handles processing of image data and returns the Promise that is resolved
  44910. * with a PDFImage when the image is ready to be used.
  44911. */
  44912. PDFImage.buildImage = function PDFImage_buildImage(handler, xref, res, image, inline, nativeDecoder) {
  44913. var imagePromise = handleImageData(image, nativeDecoder);
  44914. var smaskPromise;
  44915. var maskPromise;
  44916. var smask = image.dict.get('SMask');
  44917. var mask = image.dict.get('Mask');
  44918. if (smask) {
  44919. smaskPromise = handleImageData(smask, nativeDecoder);
  44920. maskPromise = Promise.resolve(null);
  44921. } else {
  44922. smaskPromise = Promise.resolve(null);
  44923. if (mask) {
  44924. if (isStream(mask)) {
  44925. maskPromise = handleImageData(mask, nativeDecoder);
  44926. } else if (isArray(mask)) {
  44927. maskPromise = Promise.resolve(mask);
  44928. } else {
  44929. warn('Unsupported mask format.');
  44930. maskPromise = Promise.resolve(null);
  44931. }
  44932. } else {
  44933. maskPromise = Promise.resolve(null);
  44934. }
  44935. }
  44936. return Promise.all([
  44937. imagePromise,
  44938. smaskPromise,
  44939. maskPromise
  44940. ]).then(function (results) {
  44941. var imageData = results[0];
  44942. var smaskData = results[1];
  44943. var maskData = results[2];
  44944. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  44945. });
  44946. };
  44947. PDFImage.createMask = function PDFImage_createMask(imgArray, width, height, imageIsFromDecodeStream, inverseDecode) {
  44948. // |imgArray| might not contain full data for every pixel of the mask, so
  44949. // we need to distinguish between |computedLength| and |actualLength|.
  44950. // In particular, if inverseDecode is true, then the array we return must
  44951. // have a length of |computedLength|.
  44952. var computedLength = (width + 7 >> 3) * height;
  44953. var actualLength = imgArray.byteLength;
  44954. var haveFullData = computedLength === actualLength;
  44955. var data, i;
  44956. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  44957. // imgArray came from a DecodeStream and its data is in an appropriate
  44958. // form, so we can just transfer it.
  44959. data = imgArray;
  44960. } else if (!inverseDecode) {
  44961. data = new Uint8Array(actualLength);
  44962. data.set(imgArray);
  44963. } else {
  44964. data = new Uint8Array(computedLength);
  44965. data.set(imgArray);
  44966. for (i = actualLength; i < computedLength; i++) {
  44967. data[i] = 0xff;
  44968. }
  44969. }
  44970. // If necessary, invert the original mask data (but not any extra we might
  44971. // have added above). It's safe to modify the array -- whether it's the
  44972. // original or a copy, we're about to transfer it anyway, so nothing else
  44973. // in this thread can be relying on its contents.
  44974. if (inverseDecode) {
  44975. for (i = 0; i < actualLength; i++) {
  44976. data[i] = ~data[i];
  44977. }
  44978. }
  44979. return {
  44980. data: data,
  44981. width: width,
  44982. height: height
  44983. };
  44984. };
  44985. PDFImage.prototype = {
  44986. get drawWidth() {
  44987. return Math.max(this.width, this.smask && this.smask.width || 0, this.mask && this.mask.width || 0);
  44988. },
  44989. get drawHeight() {
  44990. return Math.max(this.height, this.smask && this.smask.height || 0, this.mask && this.mask.height || 0);
  44991. },
  44992. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  44993. var bpc = this.bpc;
  44994. var numComps = this.numComps;
  44995. var decodeAddends = this.decodeAddends;
  44996. var decodeCoefficients = this.decodeCoefficients;
  44997. var max = (1 << bpc) - 1;
  44998. var i, ii;
  44999. if (bpc === 1) {
  45000. // If the buffer needed decode that means it just needs to be inverted.
  45001. for (i = 0, ii = buffer.length; i < ii; i++) {
  45002. buffer[i] = +!buffer[i];
  45003. }
  45004. return;
  45005. }
  45006. var index = 0;
  45007. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  45008. for (var j = 0; j < numComps; j++) {
  45009. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j], decodeCoefficients[j], max);
  45010. index++;
  45011. }
  45012. }
  45013. },
  45014. getComponents: function PDFImage_getComponents(buffer) {
  45015. var bpc = this.bpc;
  45016. // This image doesn't require any extra work.
  45017. if (bpc === 8) {
  45018. return buffer;
  45019. }
  45020. var width = this.width;
  45021. var height = this.height;
  45022. var numComps = this.numComps;
  45023. var length = width * height * numComps;
  45024. var bufferPos = 0;
  45025. var output = bpc <= 8 ? new Uint8Array(length) : bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length);
  45026. var rowComps = width * numComps;
  45027. var max = (1 << bpc) - 1;
  45028. var i = 0, ii, buf;
  45029. if (bpc === 1) {
  45030. // Optimization for reading 1 bpc images.
  45031. var mask, loop1End, loop2End;
  45032. for (var j = 0; j < height; j++) {
  45033. loop1End = i + (rowComps & ~7);
  45034. loop2End = i + rowComps;
  45035. // unroll loop for all full bytes
  45036. while (i < loop1End) {
  45037. buf = buffer[bufferPos++];
  45038. output[i] = buf >> 7 & 1;
  45039. output[i + 1] = buf >> 6 & 1;
  45040. output[i + 2] = buf >> 5 & 1;
  45041. output[i + 3] = buf >> 4 & 1;
  45042. output[i + 4] = buf >> 3 & 1;
  45043. output[i + 5] = buf >> 2 & 1;
  45044. output[i + 6] = buf >> 1 & 1;
  45045. output[i + 7] = buf & 1;
  45046. i += 8;
  45047. }
  45048. // handle remaining bits
  45049. if (i < loop2End) {
  45050. buf = buffer[bufferPos++];
  45051. mask = 128;
  45052. while (i < loop2End) {
  45053. output[i++] = +!!(buf & mask);
  45054. mask >>= 1;
  45055. }
  45056. }
  45057. }
  45058. } else {
  45059. // The general case that handles all other bpc values.
  45060. var bits = 0;
  45061. buf = 0;
  45062. for (i = 0, ii = length; i < ii; ++i) {
  45063. if (i % rowComps === 0) {
  45064. buf = 0;
  45065. bits = 0;
  45066. }
  45067. while (bits < bpc) {
  45068. buf = buf << 8 | buffer[bufferPos++];
  45069. bits += 8;
  45070. }
  45071. var remainingBits = bits - bpc;
  45072. var value = buf >> remainingBits;
  45073. output[i] = value < 0 ? 0 : value > max ? max : value;
  45074. buf = buf & (1 << remainingBits) - 1;
  45075. bits = remainingBits;
  45076. }
  45077. }
  45078. return output;
  45079. },
  45080. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height, actualHeight, image) {
  45081. var smask = this.smask;
  45082. var mask = this.mask;
  45083. var alphaBuf, sw, sh, i, ii, j;
  45084. if (smask) {
  45085. sw = smask.width;
  45086. sh = smask.height;
  45087. alphaBuf = new Uint8Array(sw * sh);
  45088. smask.fillGrayBuffer(alphaBuf);
  45089. if (sw !== width || sh !== height) {
  45090. alphaBuf = resizeImageMask(alphaBuf, smask.bpc, sw, sh, width, height);
  45091. }
  45092. } else if (mask) {
  45093. if (mask instanceof PDFImage) {
  45094. sw = mask.width;
  45095. sh = mask.height;
  45096. alphaBuf = new Uint8Array(sw * sh);
  45097. mask.numComps = 1;
  45098. mask.fillGrayBuffer(alphaBuf);
  45099. // Need to invert values in rgbaBuf
  45100. for (i = 0, ii = sw * sh; i < ii; ++i) {
  45101. alphaBuf[i] = 255 - alphaBuf[i];
  45102. }
  45103. if (sw !== width || sh !== height) {
  45104. alphaBuf = resizeImageMask(alphaBuf, mask.bpc, sw, sh, width, height);
  45105. }
  45106. } else if (isArray(mask)) {
  45107. // Color key mask: if any of the components are outside the range
  45108. // then they should be painted.
  45109. alphaBuf = new Uint8Array(width * height);
  45110. var numComps = this.numComps;
  45111. for (i = 0, ii = width * height; i < ii; ++i) {
  45112. var opacity = 0;
  45113. var imageOffset = i * numComps;
  45114. for (j = 0; j < numComps; ++j) {
  45115. var color = image[imageOffset + j];
  45116. var maskOffset = j * 2;
  45117. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  45118. opacity = 255;
  45119. break;
  45120. }
  45121. }
  45122. alphaBuf[i] = opacity;
  45123. }
  45124. } else {
  45125. error('Unknown mask format.');
  45126. }
  45127. }
  45128. if (alphaBuf) {
  45129. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  45130. rgbaBuf[j] = alphaBuf[i];
  45131. }
  45132. } else {
  45133. // No mask.
  45134. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  45135. rgbaBuf[j] = 255;
  45136. }
  45137. }
  45138. },
  45139. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  45140. var matte = this.smask && this.smask.matte;
  45141. if (!matte) {
  45142. return;
  45143. }
  45144. var matteRgb = this.colorSpace.getRgb(matte, 0);
  45145. var matteR = matteRgb[0];
  45146. var matteG = matteRgb[1];
  45147. var matteB = matteRgb[2];
  45148. var length = width * height * 4;
  45149. var r, g, b;
  45150. for (var i = 0; i < length; i += 4) {
  45151. var alpha = buffer[i + 3];
  45152. if (alpha === 0) {
  45153. // according formula we have to get Infinity in all components
  45154. // making it white (typical paper color) should be okay
  45155. buffer[i] = 255;
  45156. buffer[i + 1] = 255;
  45157. buffer[i + 2] = 255;
  45158. continue;
  45159. }
  45160. var k = 255 / alpha;
  45161. r = (buffer[i] - matteR) * k + matteR;
  45162. g = (buffer[i + 1] - matteG) * k + matteG;
  45163. b = (buffer[i + 2] - matteB) * k + matteB;
  45164. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  45165. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  45166. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  45167. }
  45168. },
  45169. createImageData: function PDFImage_createImageData(forceRGBA) {
  45170. var drawWidth = this.drawWidth;
  45171. var drawHeight = this.drawHeight;
  45172. var imgData = {
  45173. // other fields are filled in below
  45174. width: drawWidth,
  45175. height: drawHeight
  45176. };
  45177. var numComps = this.numComps;
  45178. var originalWidth = this.width;
  45179. var originalHeight = this.height;
  45180. var bpc = this.bpc;
  45181. // Rows start at byte boundary.
  45182. var rowBytes = originalWidth * numComps * bpc + 7 >> 3;
  45183. var imgArray;
  45184. if (!forceRGBA) {
  45185. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  45186. // without any complications, we pass a same-sized copy to the main
  45187. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  45188. // of memory for many scanned documents. It's also much faster.
  45189. //
  45190. // Similarly, if it is a 24-bit-per pixel RGB image without any
  45191. // complications, we avoid expanding by 1.333x to RGBA form.
  45192. var kind;
  45193. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  45194. kind = ImageKind.GRAYSCALE_1BPP;
  45195. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 && !this.needsDecode) {
  45196. kind = ImageKind.RGB_24BPP;
  45197. }
  45198. if (kind && !this.smask && !this.mask && drawWidth === originalWidth && drawHeight === originalHeight) {
  45199. imgData.kind = kind;
  45200. imgArray = this.getImageBytes(originalHeight * rowBytes);
  45201. // If imgArray came from a DecodeStream, we're safe to transfer it
  45202. // (and thus detach its underlying buffer) because it will constitute
  45203. // the entire DecodeStream's data. But if it came from a Stream, we
  45204. // need to copy it because it'll only be a portion of the Stream's
  45205. // data, and the rest will be read later on.
  45206. if (this.image instanceof DecodeStream) {
  45207. imgData.data = imgArray;
  45208. } else {
  45209. var newArray = new Uint8Array(imgArray.length);
  45210. newArray.set(imgArray);
  45211. imgData.data = newArray;
  45212. }
  45213. if (this.needsDecode) {
  45214. // Invert the buffer (which must be grayscale if we reached here).
  45215. assert(kind === ImageKind.GRAYSCALE_1BPP);
  45216. var buffer = imgData.data;
  45217. for (var i = 0, ii = buffer.length; i < ii; i++) {
  45218. buffer[i] ^= 0xff;
  45219. }
  45220. }
  45221. return imgData;
  45222. }
  45223. if (this.image instanceof JpegStream && !this.smask && !this.mask && (this.colorSpace.name === 'DeviceGray' || this.colorSpace.name === 'DeviceRGB' || this.colorSpace.name === 'DeviceCMYK')) {
  45224. imgData.kind = ImageKind.RGB_24BPP;
  45225. imgData.data = this.getImageBytes(originalHeight * rowBytes, drawWidth, drawHeight, true);
  45226. return imgData;
  45227. }
  45228. }
  45229. imgArray = this.getImageBytes(originalHeight * rowBytes);
  45230. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  45231. var actualHeight = 0 | imgArray.length / rowBytes * drawHeight / originalHeight;
  45232. var comps = this.getComponents(imgArray);
  45233. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  45234. // more compact RGB_24BPP form if allowable.
  45235. var alpha01, maybeUndoPreblend;
  45236. if (!forceRGBA && !this.smask && !this.mask) {
  45237. imgData.kind = ImageKind.RGB_24BPP;
  45238. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  45239. alpha01 = 0;
  45240. maybeUndoPreblend = false;
  45241. } else {
  45242. imgData.kind = ImageKind.RGBA_32BPP;
  45243. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  45244. alpha01 = 1;
  45245. maybeUndoPreblend = true;
  45246. // Color key masking (opacity) must be performed before decoding.
  45247. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight, comps);
  45248. }
  45249. if (this.needsDecode) {
  45250. this.decodeBuffer(comps);
  45251. }
  45252. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight, drawWidth, drawHeight, actualHeight, bpc, comps, alpha01);
  45253. if (maybeUndoPreblend) {
  45254. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  45255. }
  45256. return imgData;
  45257. },
  45258. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  45259. var numComps = this.numComps;
  45260. if (numComps !== 1) {
  45261. error('Reading gray scale from a color image: ' + numComps);
  45262. }
  45263. var width = this.width;
  45264. var height = this.height;
  45265. var bpc = this.bpc;
  45266. // rows start at byte boundary
  45267. var rowBytes = width * numComps * bpc + 7 >> 3;
  45268. var imgArray = this.getImageBytes(height * rowBytes);
  45269. var comps = this.getComponents(imgArray);
  45270. var i, length;
  45271. if (bpc === 1) {
  45272. // inline decoding (= inversion) for 1 bpc images
  45273. length = width * height;
  45274. if (this.needsDecode) {
  45275. // invert and scale to {0, 255}
  45276. for (i = 0; i < length; ++i) {
  45277. buffer[i] = comps[i] - 1 & 255;
  45278. }
  45279. } else {
  45280. // scale to {0, 255}
  45281. for (i = 0; i < length; ++i) {
  45282. buffer[i] = -comps[i] & 255;
  45283. }
  45284. }
  45285. return;
  45286. }
  45287. if (this.needsDecode) {
  45288. this.decodeBuffer(comps);
  45289. }
  45290. length = width * height;
  45291. // we aren't using a colorspace so we need to scale the value
  45292. var scale = 255 / ((1 << bpc) - 1);
  45293. for (i = 0; i < length; ++i) {
  45294. buffer[i] = scale * comps[i] | 0;
  45295. }
  45296. },
  45297. getImageBytes: function PDFImage_getImageBytes(length, drawWidth, drawHeight, forceRGB) {
  45298. this.image.reset();
  45299. this.image.drawWidth = drawWidth || this.width;
  45300. this.image.drawHeight = drawHeight || this.height;
  45301. this.image.forceRGB = !!forceRGB;
  45302. return this.image.getBytes(length);
  45303. }
  45304. };
  45305. return PDFImage;
  45306. }();
  45307. exports.PDFImage = PDFImage;
  45308. }));
  45309. (function (root, factory) {
  45310. factory(root.pdfjsCoreObj = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreCrypto, root.pdfjsCoreParser, root.pdfjsCoreChunkedStream, root.pdfjsCoreColorSpace);
  45311. }(this, function (exports, sharedUtil, corePrimitives, coreCrypto, coreParser, coreChunkedStream, coreColorSpace) {
  45312. var InvalidPDFException = sharedUtil.InvalidPDFException;
  45313. var MissingDataException = sharedUtil.MissingDataException;
  45314. var XRefParseException = sharedUtil.XRefParseException;
  45315. var assert = sharedUtil.assert;
  45316. var bytesToString = sharedUtil.bytesToString;
  45317. var createPromiseCapability = sharedUtil.createPromiseCapability;
  45318. var error = sharedUtil.error;
  45319. var info = sharedUtil.info;
  45320. var isArray = sharedUtil.isArray;
  45321. var isInt = sharedUtil.isInt;
  45322. var isString = sharedUtil.isString;
  45323. var shadow = sharedUtil.shadow;
  45324. var stringToPDFString = sharedUtil.stringToPDFString;
  45325. var stringToUTF8String = sharedUtil.stringToUTF8String;
  45326. var warn = sharedUtil.warn;
  45327. var isValidUrl = sharedUtil.isValidUrl;
  45328. var Util = sharedUtil.Util;
  45329. var Ref = corePrimitives.Ref;
  45330. var RefSet = corePrimitives.RefSet;
  45331. var RefSetCache = corePrimitives.RefSetCache;
  45332. var isName = corePrimitives.isName;
  45333. var isCmd = corePrimitives.isCmd;
  45334. var isDict = corePrimitives.isDict;
  45335. var isRef = corePrimitives.isRef;
  45336. var isRefsEqual = corePrimitives.isRefsEqual;
  45337. var isStream = corePrimitives.isStream;
  45338. var CipherTransformFactory = coreCrypto.CipherTransformFactory;
  45339. var Lexer = coreParser.Lexer;
  45340. var Parser = coreParser.Parser;
  45341. var ChunkedStream = coreChunkedStream.ChunkedStream;
  45342. var ColorSpace = coreColorSpace.ColorSpace;
  45343. var Catalog = function CatalogClosure() {
  45344. function Catalog(pdfManager, xref, pageFactory) {
  45345. this.pdfManager = pdfManager;
  45346. this.xref = xref;
  45347. this.catDict = xref.getCatalogObj();
  45348. this.fontCache = new RefSetCache();
  45349. assert(isDict(this.catDict), 'catalog object is not a dictionary');
  45350. // TODO refactor to move getPage() to the PDFDocument.
  45351. this.pageFactory = pageFactory;
  45352. this.pagePromises = [];
  45353. }
  45354. Catalog.prototype = {
  45355. get metadata() {
  45356. var streamRef = this.catDict.getRaw('Metadata');
  45357. if (!isRef(streamRef)) {
  45358. return shadow(this, 'metadata', null);
  45359. }
  45360. var encryptMetadata = !this.xref.encrypt ? false : this.xref.encrypt.encryptMetadata;
  45361. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  45362. var metadata;
  45363. if (stream && isDict(stream.dict)) {
  45364. var type = stream.dict.get('Type');
  45365. var subtype = stream.dict.get('Subtype');
  45366. if (isName(type, 'Metadata') && isName(subtype, 'XML')) {
  45367. // XXX: This should examine the charset the XML document defines,
  45368. // however since there are currently no real means to decode
  45369. // arbitrary charsets, let's just hope that the author of the PDF
  45370. // was reasonable enough to stick with the XML default charset,
  45371. // which is UTF-8.
  45372. try {
  45373. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  45374. } catch (e) {
  45375. info('Skipping invalid metadata.');
  45376. }
  45377. }
  45378. }
  45379. return shadow(this, 'metadata', metadata);
  45380. },
  45381. get toplevelPagesDict() {
  45382. var pagesObj = this.catDict.get('Pages');
  45383. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  45384. // shadow the prototype getter
  45385. return shadow(this, 'toplevelPagesDict', pagesObj);
  45386. },
  45387. get documentOutline() {
  45388. var obj = null;
  45389. try {
  45390. obj = this.readDocumentOutline();
  45391. } catch (ex) {
  45392. if (ex instanceof MissingDataException) {
  45393. throw ex;
  45394. }
  45395. warn('Unable to read document outline');
  45396. }
  45397. return shadow(this, 'documentOutline', obj);
  45398. },
  45399. readDocumentOutline: function Catalog_readDocumentOutline() {
  45400. var obj = this.catDict.get('Outlines');
  45401. if (!isDict(obj)) {
  45402. return null;
  45403. }
  45404. obj = obj.getRaw('First');
  45405. if (!isRef(obj)) {
  45406. return null;
  45407. }
  45408. var root = { items: [] };
  45409. var queue = [{
  45410. obj: obj,
  45411. parent: root
  45412. }];
  45413. // To avoid recursion, keep track of the already processed items.
  45414. var processed = new RefSet();
  45415. processed.put(obj);
  45416. var xref = this.xref, blackColor = new Uint8Array(3);
  45417. while (queue.length > 0) {
  45418. var i = queue.shift();
  45419. var outlineDict = xref.fetchIfRef(i.obj);
  45420. if (outlineDict === null) {
  45421. continue;
  45422. }
  45423. assert(outlineDict.has('Title'), 'Invalid outline item');
  45424. var actionDict = outlineDict.get('A'), dest = null, url = null;
  45425. if (actionDict) {
  45426. var destEntry = actionDict.get('D');
  45427. if (destEntry) {
  45428. dest = destEntry;
  45429. } else {
  45430. var uriEntry = actionDict.get('URI');
  45431. if (isString(uriEntry) && isValidUrl(uriEntry, false)) {
  45432. url = uriEntry;
  45433. }
  45434. }
  45435. } else if (outlineDict.has('Dest')) {
  45436. dest = outlineDict.getRaw('Dest');
  45437. if (isName(dest)) {
  45438. dest = dest.name;
  45439. }
  45440. }
  45441. var title = outlineDict.get('Title');
  45442. var flags = outlineDict.get('F') || 0;
  45443. var color = outlineDict.getArray('C'), rgbColor = blackColor;
  45444. // We only need to parse the color when it's valid, and non-default.
  45445. if (isArray(color) && color.length === 3 && (color[0] !== 0 || color[1] !== 0 || color[2] !== 0)) {
  45446. rgbColor = ColorSpace.singletons.rgb.getRgb(color, 0);
  45447. }
  45448. var outlineItem = {
  45449. dest: dest,
  45450. url: url,
  45451. title: stringToPDFString(title),
  45452. color: rgbColor,
  45453. count: outlineDict.get('Count'),
  45454. bold: !!(flags & 2),
  45455. italic: !!(flags & 1),
  45456. items: []
  45457. };
  45458. i.parent.items.push(outlineItem);
  45459. obj = outlineDict.getRaw('First');
  45460. if (isRef(obj) && !processed.has(obj)) {
  45461. queue.push({
  45462. obj: obj,
  45463. parent: outlineItem
  45464. });
  45465. processed.put(obj);
  45466. }
  45467. obj = outlineDict.getRaw('Next');
  45468. if (isRef(obj) && !processed.has(obj)) {
  45469. queue.push({
  45470. obj: obj,
  45471. parent: i.parent
  45472. });
  45473. processed.put(obj);
  45474. }
  45475. }
  45476. return root.items.length > 0 ? root.items : null;
  45477. },
  45478. get numPages() {
  45479. var obj = this.toplevelPagesDict.get('Count');
  45480. assert(isInt(obj), 'page count in top level pages object is not an integer');
  45481. // shadow the prototype getter
  45482. return shadow(this, 'num', obj);
  45483. },
  45484. get destinations() {
  45485. function fetchDestination(dest) {
  45486. return isDict(dest) ? dest.get('D') : dest;
  45487. }
  45488. var xref = this.xref;
  45489. var dests = {}, nameTreeRef, nameDictionaryRef;
  45490. var obj = this.catDict.get('Names');
  45491. if (obj && obj.has('Dests')) {
  45492. nameTreeRef = obj.getRaw('Dests');
  45493. } else if (this.catDict.has('Dests')) {
  45494. nameDictionaryRef = this.catDict.get('Dests');
  45495. }
  45496. if (nameDictionaryRef) {
  45497. // reading simple destination dictionary
  45498. obj = nameDictionaryRef;
  45499. obj.forEach(function catalogForEach(key, value) {
  45500. if (!value) {
  45501. return;
  45502. }
  45503. dests[key] = fetchDestination(value);
  45504. });
  45505. }
  45506. if (nameTreeRef) {
  45507. var nameTree = new NameTree(nameTreeRef, xref);
  45508. var names = nameTree.getAll();
  45509. for (var name in names) {
  45510. dests[name] = fetchDestination(names[name]);
  45511. }
  45512. }
  45513. return shadow(this, 'destinations', dests);
  45514. },
  45515. getDestination: function Catalog_getDestination(destinationId) {
  45516. function fetchDestination(dest) {
  45517. return isDict(dest) ? dest.get('D') : dest;
  45518. }
  45519. var xref = this.xref;
  45520. var dest = null, nameTreeRef, nameDictionaryRef;
  45521. var obj = this.catDict.get('Names');
  45522. if (obj && obj.has('Dests')) {
  45523. nameTreeRef = obj.getRaw('Dests');
  45524. } else if (this.catDict.has('Dests')) {
  45525. nameDictionaryRef = this.catDict.get('Dests');
  45526. }
  45527. if (nameDictionaryRef) {
  45528. // Simple destination dictionary.
  45529. var value = nameDictionaryRef.get(destinationId);
  45530. if (value) {
  45531. dest = fetchDestination(value);
  45532. }
  45533. }
  45534. if (nameTreeRef) {
  45535. var nameTree = new NameTree(nameTreeRef, xref);
  45536. dest = fetchDestination(nameTree.get(destinationId));
  45537. }
  45538. return dest;
  45539. },
  45540. get pageLabels() {
  45541. var obj = null;
  45542. try {
  45543. obj = this.readPageLabels();
  45544. } catch (ex) {
  45545. if (ex instanceof MissingDataException) {
  45546. throw ex;
  45547. }
  45548. warn('Unable to read page labels.');
  45549. }
  45550. return shadow(this, 'pageLabels', obj);
  45551. },
  45552. readPageLabels: function Catalog_readPageLabels() {
  45553. var obj = this.catDict.getRaw('PageLabels');
  45554. if (!obj) {
  45555. return null;
  45556. }
  45557. var pageLabels = new Array(this.numPages);
  45558. var style = null;
  45559. var prefix = '';
  45560. var start = 1;
  45561. var numberTree = new NumberTree(obj, this.xref);
  45562. var nums = numberTree.getAll();
  45563. var currentLabel = '', currentIndex = 1;
  45564. for (var i = 0, ii = this.numPages; i < ii; i++) {
  45565. if (i in nums) {
  45566. var labelDict = nums[i];
  45567. assert(isDict(labelDict), 'The PageLabel is not a dictionary.');
  45568. var type = labelDict.get('Type');
  45569. assert(!type || isName(type, 'PageLabel'), 'Invalid type in PageLabel dictionary.');
  45570. var s = labelDict.get('S');
  45571. assert(!s || isName(s), 'Invalid style in PageLabel dictionary.');
  45572. style = s ? s.name : null;
  45573. prefix = labelDict.get('P') || '';
  45574. assert(isString(prefix), 'Invalid prefix in PageLabel dictionary.');
  45575. start = labelDict.get('St') || 1;
  45576. assert(isInt(start), 'Invalid start in PageLabel dictionary.');
  45577. currentIndex = start;
  45578. }
  45579. switch (style) {
  45580. case 'D':
  45581. currentLabel = currentIndex;
  45582. break;
  45583. case 'R':
  45584. case 'r':
  45585. currentLabel = Util.toRoman(currentIndex, style === 'r');
  45586. break;
  45587. case 'A':
  45588. case 'a':
  45589. var LIMIT = 26;
  45590. // Use only the characters A--Z, or a--z.
  45591. var A_UPPER_CASE = 0x41, A_LOWER_CASE = 0x61;
  45592. var baseCharCode = style === 'a' ? A_LOWER_CASE : A_UPPER_CASE;
  45593. var letterIndex = currentIndex - 1;
  45594. var character = String.fromCharCode(baseCharCode + letterIndex % LIMIT);
  45595. var charBuf = [];
  45596. for (var j = 0, jj = letterIndex / LIMIT | 0; j <= jj; j++) {
  45597. charBuf.push(character);
  45598. }
  45599. currentLabel = charBuf.join('');
  45600. break;
  45601. default:
  45602. assert(!style, 'Invalid style "' + style + '" in PageLabel dictionary.');
  45603. }
  45604. pageLabels[i] = prefix + currentLabel;
  45605. currentLabel = '';
  45606. currentIndex++;
  45607. }
  45608. return pageLabels;
  45609. },
  45610. get attachments() {
  45611. var xref = this.xref;
  45612. var attachments = null, nameTreeRef;
  45613. var obj = this.catDict.get('Names');
  45614. if (obj) {
  45615. nameTreeRef = obj.getRaw('EmbeddedFiles');
  45616. }
  45617. if (nameTreeRef) {
  45618. var nameTree = new NameTree(nameTreeRef, xref);
  45619. var names = nameTree.getAll();
  45620. for (var name in names) {
  45621. var fs = new FileSpec(names[name], xref);
  45622. if (!attachments) {
  45623. attachments = Object.create(null);
  45624. }
  45625. attachments[stringToPDFString(name)] = fs.serializable;
  45626. }
  45627. }
  45628. return shadow(this, 'attachments', attachments);
  45629. },
  45630. get javaScript() {
  45631. var xref = this.xref;
  45632. var obj = this.catDict.get('Names');
  45633. var javaScript = [];
  45634. function appendIfJavaScriptDict(jsDict) {
  45635. var type = jsDict.get('S');
  45636. if (!isName(type, 'JavaScript')) {
  45637. return;
  45638. }
  45639. var js = jsDict.get('JS');
  45640. if (isStream(js)) {
  45641. js = bytesToString(js.getBytes());
  45642. } else if (!isString(js)) {
  45643. return;
  45644. }
  45645. javaScript.push(stringToPDFString(js));
  45646. }
  45647. if (obj && obj.has('JavaScript')) {
  45648. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  45649. var names = nameTree.getAll();
  45650. for (var name in names) {
  45651. // We don't really use the JavaScript right now. This code is
  45652. // defensive so we don't cause errors on document load.
  45653. var jsDict = names[name];
  45654. if (isDict(jsDict)) {
  45655. appendIfJavaScriptDict(jsDict);
  45656. }
  45657. }
  45658. }
  45659. // Append OpenAction actions to javaScript array
  45660. var openactionDict = this.catDict.get('OpenAction');
  45661. if (isDict(openactionDict, 'Action')) {
  45662. var actionType = openactionDict.get('S');
  45663. if (isName(actionType, 'Named')) {
  45664. // The named Print action is not a part of the PDF 1.7 specification,
  45665. // but is supported by many PDF readers/writers (including Adobe's).
  45666. var action = openactionDict.get('N');
  45667. if (isName(action, 'Print')) {
  45668. javaScript.push('print({});');
  45669. }
  45670. } else {
  45671. appendIfJavaScriptDict(openactionDict);
  45672. }
  45673. }
  45674. return shadow(this, 'javaScript', javaScript);
  45675. },
  45676. cleanup: function Catalog_cleanup() {
  45677. var promises = [];
  45678. this.fontCache.forEach(function (promise) {
  45679. promises.push(promise);
  45680. });
  45681. return Promise.all(promises).then(function (translatedFonts) {
  45682. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  45683. var font = translatedFonts[i].dict;
  45684. delete font.translated;
  45685. }
  45686. this.fontCache.clear();
  45687. }.bind(this));
  45688. },
  45689. getPage: function Catalog_getPage(pageIndex) {
  45690. if (!(pageIndex in this.pagePromises)) {
  45691. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(function (a) {
  45692. var dict = a[0];
  45693. var ref = a[1];
  45694. return this.pageFactory.createPage(pageIndex, dict, ref, this.fontCache);
  45695. }.bind(this));
  45696. }
  45697. return this.pagePromises[pageIndex];
  45698. },
  45699. getPageDict: function Catalog_getPageDict(pageIndex) {
  45700. var capability = createPromiseCapability();
  45701. var nodesToVisit = [this.catDict.getRaw('Pages')];
  45702. var currentPageIndex = 0;
  45703. var xref = this.xref;
  45704. var checkAllKids = false;
  45705. function next() {
  45706. while (nodesToVisit.length) {
  45707. var currentNode = nodesToVisit.pop();
  45708. if (isRef(currentNode)) {
  45709. xref.fetchAsync(currentNode).then(function (obj) {
  45710. if (isDict(obj, 'Page') || isDict(obj) && !obj.has('Kids')) {
  45711. if (pageIndex === currentPageIndex) {
  45712. capability.resolve([
  45713. obj,
  45714. currentNode
  45715. ]);
  45716. } else {
  45717. currentPageIndex++;
  45718. next();
  45719. }
  45720. return;
  45721. }
  45722. nodesToVisit.push(obj);
  45723. next();
  45724. }, capability.reject);
  45725. return;
  45726. }
  45727. // Must be a child page dictionary.
  45728. assert(isDict(currentNode), 'page dictionary kid reference points to wrong type of object');
  45729. var count = currentNode.get('Count');
  45730. // If the current node doesn't have any children, avoid getting stuck
  45731. // in an empty node further down in the tree (see issue5644.pdf).
  45732. if (count === 0) {
  45733. checkAllKids = true;
  45734. }
  45735. // Skip nodes where the page can't be.
  45736. if (currentPageIndex + count <= pageIndex) {
  45737. currentPageIndex += count;
  45738. continue;
  45739. }
  45740. var kids = currentNode.get('Kids');
  45741. assert(isArray(kids), 'page dictionary kids object is not an array');
  45742. if (!checkAllKids && count === kids.length) {
  45743. // Nodes that don't have the page have been skipped and this is the
  45744. // bottom of the tree which means the page requested must be a
  45745. // descendant of this pages node. Ideally we would just resolve the
  45746. // promise with the page ref here, but there is the case where more
  45747. // pages nodes could link to single a page (see issue 3666 pdf). To
  45748. // handle this push it back on the queue so if it is a pages node it
  45749. // will be descended into.
  45750. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  45751. currentPageIndex = pageIndex;
  45752. continue;
  45753. } else {
  45754. for (var last = kids.length - 1; last >= 0; last--) {
  45755. nodesToVisit.push(kids[last]);
  45756. }
  45757. }
  45758. }
  45759. capability.reject('Page index ' + pageIndex + ' not found.');
  45760. }
  45761. next();
  45762. return capability.promise;
  45763. },
  45764. getPageIndex: function Catalog_getPageIndex(pageRef) {
  45765. // The page tree nodes have the count of all the leaves below them. To get
  45766. // how many pages are before we just have to walk up the tree and keep
  45767. // adding the count of siblings to the left of the node.
  45768. var xref = this.xref;
  45769. function pagesBeforeRef(kidRef) {
  45770. var total = 0;
  45771. var parentRef;
  45772. return xref.fetchAsync(kidRef).then(function (node) {
  45773. if (isRefsEqual(kidRef, pageRef) && !isDict(node, 'Page') && !(isDict(node) && !node.has('Type') && node.has('Contents'))) {
  45774. throw new Error('The reference does not point to a /Page Dict.');
  45775. }
  45776. if (!node) {
  45777. return null;
  45778. }
  45779. assert(isDict(node), 'node must be a Dict.');
  45780. parentRef = node.getRaw('Parent');
  45781. return node.getAsync('Parent');
  45782. }).then(function (parent) {
  45783. if (!parent) {
  45784. return null;
  45785. }
  45786. assert(isDict(parent), 'parent must be a Dict.');
  45787. return parent.getAsync('Kids');
  45788. }).then(function (kids) {
  45789. if (!kids) {
  45790. return null;
  45791. }
  45792. var kidPromises = [];
  45793. var found = false;
  45794. for (var i = 0; i < kids.length; i++) {
  45795. var kid = kids[i];
  45796. assert(isRef(kid), 'kid must be a Ref.');
  45797. if (kid.num === kidRef.num) {
  45798. found = true;
  45799. break;
  45800. }
  45801. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  45802. if (kid.has('Count')) {
  45803. var count = kid.get('Count');
  45804. total += count;
  45805. } else {
  45806. // page leaf node
  45807. total++;
  45808. }
  45809. }));
  45810. }
  45811. if (!found) {
  45812. error('kid ref not found in parents kids');
  45813. }
  45814. return Promise.all(kidPromises).then(function () {
  45815. return [
  45816. total,
  45817. parentRef
  45818. ];
  45819. });
  45820. });
  45821. }
  45822. var total = 0;
  45823. function next(ref) {
  45824. return pagesBeforeRef(ref).then(function (args) {
  45825. if (!args) {
  45826. return total;
  45827. }
  45828. var count = args[0];
  45829. var parentRef = args[1];
  45830. total += count;
  45831. return next(parentRef);
  45832. });
  45833. }
  45834. return next(pageRef);
  45835. }
  45836. };
  45837. return Catalog;
  45838. }();
  45839. var XRef = function XRefClosure() {
  45840. function XRef(stream, password) {
  45841. this.stream = stream;
  45842. this.entries = [];
  45843. this.xrefstms = Object.create(null);
  45844. // prepare the XRef cache
  45845. this.cache = [];
  45846. this.password = password;
  45847. this.stats = {
  45848. streamTypes: [],
  45849. fontTypes: []
  45850. };
  45851. }
  45852. XRef.prototype = {
  45853. setStartXRef: function XRef_setStartXRef(startXRef) {
  45854. // Store the starting positions of xref tables as we process them
  45855. // so we can recover from missing data errors
  45856. this.startXRefQueue = [startXRef];
  45857. },
  45858. parse: function XRef_parse(recoveryMode) {
  45859. var trailerDict;
  45860. if (!recoveryMode) {
  45861. trailerDict = this.readXRef();
  45862. } else {
  45863. warn('Indexing all PDF objects');
  45864. trailerDict = this.indexObjects();
  45865. }
  45866. trailerDict.assignXref(this);
  45867. this.trailer = trailerDict;
  45868. var encrypt = trailerDict.get('Encrypt');
  45869. if (encrypt) {
  45870. var ids = trailerDict.get('ID');
  45871. var fileId = ids && ids.length ? ids[0] : '';
  45872. this.encrypt = new CipherTransformFactory(encrypt, fileId, this.password);
  45873. }
  45874. // get the root dictionary (catalog) object
  45875. if (!(this.root = trailerDict.get('Root'))) {
  45876. error('Invalid root reference');
  45877. }
  45878. },
  45879. processXRefTable: function XRef_processXRefTable(parser) {
  45880. if (!('tableState' in this)) {
  45881. // Stores state of the table as we process it so we can resume
  45882. // from middle of table in case of missing data error
  45883. this.tableState = {
  45884. entryNum: 0,
  45885. streamPos: parser.lexer.stream.pos,
  45886. parserBuf1: parser.buf1,
  45887. parserBuf2: parser.buf2
  45888. };
  45889. }
  45890. var obj = this.readXRefTable(parser);
  45891. // Sanity check
  45892. if (!isCmd(obj, 'trailer')) {
  45893. error('Invalid XRef table: could not find trailer dictionary');
  45894. }
  45895. // Read trailer dictionary, e.g.
  45896. // trailer
  45897. // << /Size 22
  45898. // /Root 20R
  45899. // /Info 10R
  45900. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  45901. // >>
  45902. // The parser goes through the entire stream << ... >> and provides
  45903. // a getter interface for the key-value table
  45904. var dict = parser.getObj();
  45905. // The pdflib PDF generator can generate a nested trailer dictionary
  45906. if (!isDict(dict) && dict.dict) {
  45907. dict = dict.dict;
  45908. }
  45909. if (!isDict(dict)) {
  45910. error('Invalid XRef table: could not parse trailer dictionary');
  45911. }
  45912. delete this.tableState;
  45913. return dict;
  45914. },
  45915. readXRefTable: function XRef_readXRefTable(parser) {
  45916. // Example of cross-reference table:
  45917. // xref
  45918. // 0 1 <-- subsection header (first obj #, obj count)
  45919. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  45920. // 23 2 <-- subsection header ... and so on ...
  45921. // 0000025518 00002 n
  45922. // 0000025635 00000 n
  45923. // trailer
  45924. // ...
  45925. var stream = parser.lexer.stream;
  45926. var tableState = this.tableState;
  45927. stream.pos = tableState.streamPos;
  45928. parser.buf1 = tableState.parserBuf1;
  45929. parser.buf2 = tableState.parserBuf2;
  45930. // Outer loop is over subsection headers
  45931. var obj;
  45932. while (true) {
  45933. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  45934. if (isCmd(obj = parser.getObj(), 'trailer')) {
  45935. break;
  45936. }
  45937. tableState.firstEntryNum = obj;
  45938. tableState.entryCount = parser.getObj();
  45939. }
  45940. var first = tableState.firstEntryNum;
  45941. var count = tableState.entryCount;
  45942. if (!isInt(first) || !isInt(count)) {
  45943. error('Invalid XRef table: wrong types in subsection header');
  45944. }
  45945. // Inner loop is over objects themselves
  45946. for (var i = tableState.entryNum; i < count; i++) {
  45947. tableState.streamPos = stream.pos;
  45948. tableState.entryNum = i;
  45949. tableState.parserBuf1 = parser.buf1;
  45950. tableState.parserBuf2 = parser.buf2;
  45951. var entry = {};
  45952. entry.offset = parser.getObj();
  45953. entry.gen = parser.getObj();
  45954. var type = parser.getObj();
  45955. if (isCmd(type, 'f')) {
  45956. entry.free = true;
  45957. } else if (isCmd(type, 'n')) {
  45958. entry.uncompressed = true;
  45959. }
  45960. // Validate entry obj
  45961. if (!isInt(entry.offset) || !isInt(entry.gen) || !(entry.free || entry.uncompressed)) {
  45962. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  45963. }
  45964. // The first xref table entry, i.e. obj 0, should be free. Attempting
  45965. // to adjust an incorrect first obj # (fixes issue 3248 and 7229).
  45966. if (i === 0 && entry.free && first === 1) {
  45967. first = 0;
  45968. }
  45969. if (!this.entries[i + first]) {
  45970. this.entries[i + first] = entry;
  45971. }
  45972. }
  45973. tableState.entryNum = 0;
  45974. tableState.streamPos = stream.pos;
  45975. tableState.parserBuf1 = parser.buf1;
  45976. tableState.parserBuf2 = parser.buf2;
  45977. delete tableState.firstEntryNum;
  45978. delete tableState.entryCount;
  45979. }
  45980. // Sanity check: as per spec, first object must be free
  45981. if (this.entries[0] && !this.entries[0].free) {
  45982. error('Invalid XRef table: unexpected first object');
  45983. }
  45984. return obj;
  45985. },
  45986. processXRefStream: function XRef_processXRefStream(stream) {
  45987. if (!('streamState' in this)) {
  45988. // Stores state of the stream as we process it so we can resume
  45989. // from middle of stream in case of missing data error
  45990. var streamParameters = stream.dict;
  45991. var byteWidths = streamParameters.get('W');
  45992. var range = streamParameters.get('Index');
  45993. if (!range) {
  45994. range = [
  45995. 0,
  45996. streamParameters.get('Size')
  45997. ];
  45998. }
  45999. this.streamState = {
  46000. entryRanges: range,
  46001. byteWidths: byteWidths,
  46002. entryNum: 0,
  46003. streamPos: stream.pos
  46004. };
  46005. }
  46006. this.readXRefStream(stream);
  46007. delete this.streamState;
  46008. return stream.dict;
  46009. },
  46010. readXRefStream: function XRef_readXRefStream(stream) {
  46011. var i, j;
  46012. var streamState = this.streamState;
  46013. stream.pos = streamState.streamPos;
  46014. var byteWidths = streamState.byteWidths;
  46015. var typeFieldWidth = byteWidths[0];
  46016. var offsetFieldWidth = byteWidths[1];
  46017. var generationFieldWidth = byteWidths[2];
  46018. var entryRanges = streamState.entryRanges;
  46019. while (entryRanges.length > 0) {
  46020. var first = entryRanges[0];
  46021. var n = entryRanges[1];
  46022. if (!isInt(first) || !isInt(n)) {
  46023. error('Invalid XRef range fields: ' + first + ', ' + n);
  46024. }
  46025. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) || !isInt(generationFieldWidth)) {
  46026. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  46027. }
  46028. for (i = streamState.entryNum; i < n; ++i) {
  46029. streamState.entryNum = i;
  46030. streamState.streamPos = stream.pos;
  46031. var type = 0, offset = 0, generation = 0;
  46032. for (j = 0; j < typeFieldWidth; ++j) {
  46033. type = type << 8 | stream.getByte();
  46034. }
  46035. // if type field is absent, its default value is 1
  46036. if (typeFieldWidth === 0) {
  46037. type = 1;
  46038. }
  46039. for (j = 0; j < offsetFieldWidth; ++j) {
  46040. offset = offset << 8 | stream.getByte();
  46041. }
  46042. for (j = 0; j < generationFieldWidth; ++j) {
  46043. generation = generation << 8 | stream.getByte();
  46044. }
  46045. var entry = {};
  46046. entry.offset = offset;
  46047. entry.gen = generation;
  46048. switch (type) {
  46049. case 0:
  46050. entry.free = true;
  46051. break;
  46052. case 1:
  46053. entry.uncompressed = true;
  46054. break;
  46055. case 2:
  46056. break;
  46057. default:
  46058. error('Invalid XRef entry type: ' + type);
  46059. }
  46060. if (!this.entries[first + i]) {
  46061. this.entries[first + i] = entry;
  46062. }
  46063. }
  46064. streamState.entryNum = 0;
  46065. streamState.streamPos = stream.pos;
  46066. entryRanges.splice(0, 2);
  46067. }
  46068. },
  46069. indexObjects: function XRef_indexObjects() {
  46070. // Simple scan through the PDF content to find objects,
  46071. // trailers and XRef streams.
  46072. var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
  46073. var PERCENT = 0x25, LT = 0x3C;
  46074. function readToken(data, offset) {
  46075. var token = '', ch = data[offset];
  46076. while (ch !== LF && ch !== CR && ch !== LT) {
  46077. if (++offset >= data.length) {
  46078. break;
  46079. }
  46080. token += String.fromCharCode(ch);
  46081. ch = data[offset];
  46082. }
  46083. return token;
  46084. }
  46085. function skipUntil(data, offset, what) {
  46086. var length = what.length, dataLength = data.length;
  46087. var skipped = 0;
  46088. // finding byte sequence
  46089. while (offset < dataLength) {
  46090. var i = 0;
  46091. while (i < length && data[offset + i] === what[i]) {
  46092. ++i;
  46093. }
  46094. if (i >= length) {
  46095. break;
  46096. }
  46097. // sequence found
  46098. offset++;
  46099. skipped++;
  46100. }
  46101. return skipped;
  46102. }
  46103. var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  46104. var trailerBytes = new Uint8Array([
  46105. 116,
  46106. 114,
  46107. 97,
  46108. 105,
  46109. 108,
  46110. 101,
  46111. 114
  46112. ]);
  46113. var startxrefBytes = new Uint8Array([
  46114. 115,
  46115. 116,
  46116. 97,
  46117. 114,
  46118. 116,
  46119. 120,
  46120. 114,
  46121. 101,
  46122. 102
  46123. ]);
  46124. var endobjBytes = new Uint8Array([
  46125. 101,
  46126. 110,
  46127. 100,
  46128. 111,
  46129. 98,
  46130. 106
  46131. ]);
  46132. var xrefBytes = new Uint8Array([
  46133. 47,
  46134. 88,
  46135. 82,
  46136. 101,
  46137. 102
  46138. ]);
  46139. // Clear out any existing entries, since they may be bogus.
  46140. this.entries.length = 0;
  46141. var stream = this.stream;
  46142. stream.pos = 0;
  46143. var buffer = stream.getBytes();
  46144. var position = stream.start, length = buffer.length;
  46145. var trailers = [], xrefStms = [];
  46146. while (position < length) {
  46147. var ch = buffer[position];
  46148. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  46149. ++position;
  46150. continue;
  46151. }
  46152. if (ch === PERCENT) {
  46153. // %-comment
  46154. do {
  46155. ++position;
  46156. if (position >= length) {
  46157. break;
  46158. }
  46159. ch = buffer[position];
  46160. } while (ch !== LF && ch !== CR);
  46161. continue;
  46162. }
  46163. var token = readToken(buffer, position);
  46164. var m;
  46165. if (token.indexOf('xref') === 0 && (token.length === 4 || /\s/.test(token[4]))) {
  46166. position += skipUntil(buffer, position, trailerBytes);
  46167. trailers.push(position);
  46168. position += skipUntil(buffer, position, startxrefBytes);
  46169. } else if (m = objRegExp.exec(token)) {
  46170. if (typeof this.entries[m[1]] === 'undefined') {
  46171. this.entries[m[1]] = {
  46172. offset: position - stream.start,
  46173. gen: m[2] | 0,
  46174. uncompressed: true
  46175. };
  46176. }
  46177. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  46178. var content = buffer.subarray(position, position + contentLength);
  46179. // checking XRef stream suspect
  46180. // (it shall have '/XRef' and next char is not a letter)
  46181. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  46182. if (xrefTagOffset < contentLength && content[xrefTagOffset + 5] < 64) {
  46183. xrefStms.push(position - stream.start);
  46184. this.xrefstms[position - stream.start] = 1;
  46185. }
  46186. // Avoid recursion
  46187. position += contentLength;
  46188. } else if (token.indexOf('trailer') === 0 && (token.length === 7 || /\s/.test(token[7]))) {
  46189. trailers.push(position);
  46190. position += skipUntil(buffer, position, startxrefBytes);
  46191. } else {
  46192. position += token.length + 1;
  46193. }
  46194. }
  46195. // reading XRef streams
  46196. var i, ii;
  46197. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  46198. this.startXRefQueue.push(xrefStms[i]);
  46199. this.readXRef(/* recoveryMode */
  46200. true);
  46201. }
  46202. // finding main trailer
  46203. var dict;
  46204. for (i = 0, ii = trailers.length; i < ii; ++i) {
  46205. stream.pos = trailers[i];
  46206. var parser = new Parser(new Lexer(stream), /* allowStreams = */
  46207. true, /* xref = */
  46208. this, /* recoveryMode = */
  46209. true);
  46210. var obj = parser.getObj();
  46211. if (!isCmd(obj, 'trailer')) {
  46212. continue;
  46213. }
  46214. // read the trailer dictionary
  46215. dict = parser.getObj();
  46216. if (!isDict(dict)) {
  46217. continue;
  46218. }
  46219. // taking the first one with 'ID'
  46220. if (dict.has('ID')) {
  46221. return dict;
  46222. }
  46223. }
  46224. // no tailer with 'ID', taking last one (if exists)
  46225. if (dict) {
  46226. return dict;
  46227. }
  46228. // nothing helps
  46229. // calling error() would reject worker with an UnknownErrorException.
  46230. throw new InvalidPDFException('Invalid PDF structure');
  46231. },
  46232. readXRef: function XRef_readXRef(recoveryMode) {
  46233. var stream = this.stream;
  46234. try {
  46235. while (this.startXRefQueue.length) {
  46236. var startXRef = this.startXRefQueue[0];
  46237. stream.pos = startXRef + stream.start;
  46238. var parser = new Parser(new Lexer(stream), true, this);
  46239. var obj = parser.getObj();
  46240. var dict;
  46241. // Get dictionary
  46242. if (isCmd(obj, 'xref')) {
  46243. // Parse end-of-file XRef
  46244. dict = this.processXRefTable(parser);
  46245. if (!this.topDict) {
  46246. this.topDict = dict;
  46247. }
  46248. // Recursively get other XRefs 'XRefStm', if any
  46249. obj = dict.get('XRefStm');
  46250. if (isInt(obj)) {
  46251. var pos = obj;
  46252. // ignore previously loaded xref streams
  46253. // (possible infinite recursion)
  46254. if (!(pos in this.xrefstms)) {
  46255. this.xrefstms[pos] = 1;
  46256. this.startXRefQueue.push(pos);
  46257. }
  46258. }
  46259. } else if (isInt(obj)) {
  46260. // Parse in-stream XRef
  46261. if (!isInt(parser.getObj()) || !isCmd(parser.getObj(), 'obj') || !isStream(obj = parser.getObj())) {
  46262. error('Invalid XRef stream');
  46263. }
  46264. dict = this.processXRefStream(obj);
  46265. if (!this.topDict) {
  46266. this.topDict = dict;
  46267. }
  46268. if (!dict) {
  46269. error('Failed to read XRef stream');
  46270. }
  46271. } else {
  46272. error('Invalid XRef stream header');
  46273. }
  46274. // Recursively get previous dictionary, if any
  46275. obj = dict.get('Prev');
  46276. if (isInt(obj)) {
  46277. this.startXRefQueue.push(obj);
  46278. } else if (isRef(obj)) {
  46279. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  46280. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  46281. this.startXRefQueue.push(obj.num);
  46282. }
  46283. this.startXRefQueue.shift();
  46284. }
  46285. return this.topDict;
  46286. } catch (e) {
  46287. if (e instanceof MissingDataException) {
  46288. throw e;
  46289. }
  46290. info('(while reading XRef): ' + e);
  46291. }
  46292. if (recoveryMode) {
  46293. return;
  46294. }
  46295. throw new XRefParseException();
  46296. },
  46297. getEntry: function XRef_getEntry(i) {
  46298. var xrefEntry = this.entries[i];
  46299. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  46300. return xrefEntry;
  46301. }
  46302. return null;
  46303. },
  46304. fetchIfRef: function XRef_fetchIfRef(obj) {
  46305. if (!isRef(obj)) {
  46306. return obj;
  46307. }
  46308. return this.fetch(obj);
  46309. },
  46310. fetch: function XRef_fetch(ref, suppressEncryption) {
  46311. assert(isRef(ref), 'ref object is not a reference');
  46312. var num = ref.num;
  46313. if (num in this.cache) {
  46314. var cacheEntry = this.cache[num];
  46315. return cacheEntry;
  46316. }
  46317. var xrefEntry = this.getEntry(num);
  46318. // the referenced entry can be free
  46319. if (xrefEntry === null) {
  46320. return this.cache[num] = null;
  46321. }
  46322. if (xrefEntry.uncompressed) {
  46323. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  46324. } else {
  46325. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  46326. }
  46327. if (isDict(xrefEntry)) {
  46328. xrefEntry.objId = ref.toString();
  46329. } else if (isStream(xrefEntry)) {
  46330. xrefEntry.dict.objId = ref.toString();
  46331. }
  46332. return xrefEntry;
  46333. },
  46334. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry, suppressEncryption) {
  46335. var gen = ref.gen;
  46336. var num = ref.num;
  46337. if (xrefEntry.gen !== gen) {
  46338. error('inconsistent generation in XRef');
  46339. }
  46340. var stream = this.stream.makeSubStream(xrefEntry.offset + this.stream.start);
  46341. var parser = new Parser(new Lexer(stream), true, this);
  46342. var obj1 = parser.getObj();
  46343. var obj2 = parser.getObj();
  46344. var obj3 = parser.getObj();
  46345. if (!isInt(obj1) || parseInt(obj1, 10) !== num || !isInt(obj2) || parseInt(obj2, 10) !== gen || !isCmd(obj3)) {
  46346. error('bad XRef entry');
  46347. }
  46348. if (!isCmd(obj3, 'obj')) {
  46349. // some bad PDFs use "obj1234" and really mean 1234
  46350. if (obj3.cmd.indexOf('obj') === 0) {
  46351. num = parseInt(obj3.cmd.substring(3), 10);
  46352. if (!isNaN(num)) {
  46353. return num;
  46354. }
  46355. }
  46356. error('bad XRef entry');
  46357. }
  46358. if (this.encrypt && !suppressEncryption) {
  46359. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  46360. } else {
  46361. xrefEntry = parser.getObj();
  46362. }
  46363. if (!isStream(xrefEntry)) {
  46364. this.cache[num] = xrefEntry;
  46365. }
  46366. return xrefEntry;
  46367. },
  46368. fetchCompressed: function XRef_fetchCompressed(xrefEntry, suppressEncryption) {
  46369. var tableOffset = xrefEntry.offset;
  46370. var stream = this.fetch(new Ref(tableOffset, 0));
  46371. if (!isStream(stream)) {
  46372. error('bad ObjStm stream');
  46373. }
  46374. var first = stream.dict.get('First');
  46375. var n = stream.dict.get('N');
  46376. if (!isInt(first) || !isInt(n)) {
  46377. error('invalid first and n parameters for ObjStm stream');
  46378. }
  46379. var parser = new Parser(new Lexer(stream), false, this);
  46380. parser.allowStreams = true;
  46381. var i, entries = [], num, nums = [];
  46382. // read the object numbers to populate cache
  46383. for (i = 0; i < n; ++i) {
  46384. num = parser.getObj();
  46385. if (!isInt(num)) {
  46386. error('invalid object number in the ObjStm stream: ' + num);
  46387. }
  46388. nums.push(num);
  46389. var offset = parser.getObj();
  46390. if (!isInt(offset)) {
  46391. error('invalid object offset in the ObjStm stream: ' + offset);
  46392. }
  46393. }
  46394. // read stream objects for cache
  46395. for (i = 0; i < n; ++i) {
  46396. entries.push(parser.getObj());
  46397. // The ObjStm should not contain 'endobj'. If it's present, skip over it
  46398. // to support corrupt PDFs (fixes issue 5241, bug 898610, bug 1037816).
  46399. if (isCmd(parser.buf1, 'endobj')) {
  46400. parser.shift();
  46401. }
  46402. num = nums[i];
  46403. var entry = this.entries[num];
  46404. if (entry && entry.offset === tableOffset && entry.gen === i) {
  46405. this.cache[num] = entries[i];
  46406. }
  46407. }
  46408. xrefEntry = entries[xrefEntry.gen];
  46409. if (xrefEntry === undefined) {
  46410. error('bad XRef entry for compressed object');
  46411. }
  46412. return xrefEntry;
  46413. },
  46414. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  46415. if (!isRef(obj)) {
  46416. return Promise.resolve(obj);
  46417. }
  46418. return this.fetchAsync(obj);
  46419. },
  46420. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  46421. var streamManager = this.stream.manager;
  46422. var xref = this;
  46423. return new Promise(function tryFetch(resolve, reject) {
  46424. try {
  46425. resolve(xref.fetch(ref, suppressEncryption));
  46426. } catch (e) {
  46427. if (e instanceof MissingDataException) {
  46428. streamManager.requestRange(e.begin, e.end).then(function () {
  46429. tryFetch(resolve, reject);
  46430. }, reject);
  46431. return;
  46432. }
  46433. reject(e);
  46434. }
  46435. });
  46436. },
  46437. getCatalogObj: function XRef_getCatalogObj() {
  46438. return this.root;
  46439. }
  46440. };
  46441. return XRef;
  46442. }();
  46443. /**
  46444. * A NameTree/NumberTree is like a Dict but has some advantageous properties,
  46445. * see the specification (7.9.6 and 7.9.7) for additional details.
  46446. * TODO: implement all the Dict functions and make this more efficient.
  46447. */
  46448. var NameOrNumberTree = function NameOrNumberTreeClosure() {
  46449. function NameOrNumberTree(root, xref) {
  46450. throw new Error('Cannot initialize NameOrNumberTree.');
  46451. }
  46452. NameOrNumberTree.prototype = {
  46453. getAll: function NameOrNumberTree_getAll() {
  46454. var dict = Object.create(null);
  46455. if (!this.root) {
  46456. return dict;
  46457. }
  46458. var xref = this.xref;
  46459. // Reading Name/Number tree.
  46460. var processed = new RefSet();
  46461. processed.put(this.root);
  46462. var queue = [this.root];
  46463. while (queue.length > 0) {
  46464. var i, n;
  46465. var obj = xref.fetchIfRef(queue.shift());
  46466. if (!isDict(obj)) {
  46467. continue;
  46468. }
  46469. if (obj.has('Kids')) {
  46470. var kids = obj.get('Kids');
  46471. for (i = 0, n = kids.length; i < n; i++) {
  46472. var kid = kids[i];
  46473. assert(!processed.has(kid), 'Duplicate entry in "' + this._type + '" tree.');
  46474. queue.push(kid);
  46475. processed.put(kid);
  46476. }
  46477. continue;
  46478. }
  46479. var entries = obj.get(this._type);
  46480. if (isArray(entries)) {
  46481. for (i = 0, n = entries.length; i < n; i += 2) {
  46482. dict[xref.fetchIfRef(entries[i])] = xref.fetchIfRef(entries[i + 1]);
  46483. }
  46484. }
  46485. }
  46486. return dict;
  46487. },
  46488. get: function NameOrNumberTree_get(key) {
  46489. if (!this.root) {
  46490. return null;
  46491. }
  46492. var xref = this.xref;
  46493. var kidsOrEntries = xref.fetchIfRef(this.root);
  46494. var loopCount = 0;
  46495. var MAX_LEVELS = 10;
  46496. var l, r, m;
  46497. // Perform a binary search to quickly find the entry that
  46498. // contains the key we are looking for.
  46499. while (kidsOrEntries.has('Kids')) {
  46500. if (++loopCount > MAX_LEVELS) {
  46501. warn('Search depth limit reached for "' + this._type + '" tree.');
  46502. return null;
  46503. }
  46504. var kids = kidsOrEntries.get('Kids');
  46505. if (!isArray(kids)) {
  46506. return null;
  46507. }
  46508. l = 0;
  46509. r = kids.length - 1;
  46510. while (l <= r) {
  46511. m = l + r >> 1;
  46512. var kid = xref.fetchIfRef(kids[m]);
  46513. var limits = kid.get('Limits');
  46514. if (key < xref.fetchIfRef(limits[0])) {
  46515. r = m - 1;
  46516. } else if (key > xref.fetchIfRef(limits[1])) {
  46517. l = m + 1;
  46518. } else {
  46519. kidsOrEntries = xref.fetchIfRef(kids[m]);
  46520. break;
  46521. }
  46522. }
  46523. if (l > r) {
  46524. return null;
  46525. }
  46526. }
  46527. // If we get here, then we have found the right entry. Now go through the
  46528. // entries in the dictionary until we find the key we're looking for.
  46529. var entries = kidsOrEntries.get(this._type);
  46530. if (isArray(entries)) {
  46531. // Perform a binary search to reduce the lookup time.
  46532. l = 0;
  46533. r = entries.length - 2;
  46534. while (l <= r) {
  46535. // Check only even indices (0, 2, 4, ...) because the
  46536. // odd indices contain the actual data.
  46537. m = l + r & ~1;
  46538. var currentKey = xref.fetchIfRef(entries[m]);
  46539. if (key < currentKey) {
  46540. r = m - 2;
  46541. } else if (key > currentKey) {
  46542. l = m + 2;
  46543. } else {
  46544. return xref.fetchIfRef(entries[m + 1]);
  46545. }
  46546. }
  46547. }
  46548. return null;
  46549. }
  46550. };
  46551. return NameOrNumberTree;
  46552. }();
  46553. var NameTree = function NameTreeClosure() {
  46554. function NameTree(root, xref) {
  46555. this.root = root;
  46556. this.xref = xref;
  46557. this._type = 'Names';
  46558. }
  46559. Util.inherit(NameTree, NameOrNumberTree, {});
  46560. return NameTree;
  46561. }();
  46562. var NumberTree = function NumberTreeClosure() {
  46563. function NumberTree(root, xref) {
  46564. this.root = root;
  46565. this.xref = xref;
  46566. this._type = 'Nums';
  46567. }
  46568. Util.inherit(NumberTree, NameOrNumberTree, {});
  46569. return NumberTree;
  46570. }();
  46571. /**
  46572. * "A PDF file can refer to the contents of another file by using a File
  46573. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  46574. * NOTE: Only embedded files are supported (as part of the attachments support)
  46575. * TODO: support the 'URL' file system (with caching if !/V), portable
  46576. * collections attributes and related files (/RF)
  46577. */
  46578. var FileSpec = function FileSpecClosure() {
  46579. function FileSpec(root, xref) {
  46580. if (!root || !isDict(root)) {
  46581. return;
  46582. }
  46583. this.xref = xref;
  46584. this.root = root;
  46585. if (root.has('FS')) {
  46586. this.fs = root.get('FS');
  46587. }
  46588. this.description = root.has('Desc') ? stringToPDFString(root.get('Desc')) : '';
  46589. if (root.has('RF')) {
  46590. warn('Related file specifications are not supported');
  46591. }
  46592. this.contentAvailable = true;
  46593. if (!root.has('EF')) {
  46594. this.contentAvailable = false;
  46595. warn('Non-embedded file specifications are not supported');
  46596. }
  46597. }
  46598. function pickPlatformItem(dict) {
  46599. // Look for the filename in this order:
  46600. // UF, F, Unix, Mac, DOS
  46601. if (dict.has('UF')) {
  46602. return dict.get('UF');
  46603. } else if (dict.has('F')) {
  46604. return dict.get('F');
  46605. } else if (dict.has('Unix')) {
  46606. return dict.get('Unix');
  46607. } else if (dict.has('Mac')) {
  46608. return dict.get('Mac');
  46609. } else if (dict.has('DOS')) {
  46610. return dict.get('DOS');
  46611. } else {
  46612. return null;
  46613. }
  46614. }
  46615. FileSpec.prototype = {
  46616. get filename() {
  46617. if (!this._filename && this.root) {
  46618. var filename = pickPlatformItem(this.root) || 'unnamed';
  46619. this._filename = stringToPDFString(filename).replace(/\\\\/g, '\\').replace(/\\\//g, '/').replace(/\\/g, '/');
  46620. }
  46621. return this._filename;
  46622. },
  46623. get content() {
  46624. if (!this.contentAvailable) {
  46625. return null;
  46626. }
  46627. if (!this.contentRef && this.root) {
  46628. this.contentRef = pickPlatformItem(this.root.get('EF'));
  46629. }
  46630. var content = null;
  46631. if (this.contentRef) {
  46632. var xref = this.xref;
  46633. var fileObj = xref.fetchIfRef(this.contentRef);
  46634. if (fileObj && isStream(fileObj)) {
  46635. content = fileObj.getBytes();
  46636. } else {
  46637. warn('Embedded file specification points to non-existing/invalid ' + 'content');
  46638. }
  46639. } else {
  46640. warn('Embedded file specification does not have a content');
  46641. }
  46642. return content;
  46643. },
  46644. get serializable() {
  46645. return {
  46646. filename: this.filename,
  46647. content: this.content
  46648. };
  46649. }
  46650. };
  46651. return FileSpec;
  46652. }();
  46653. /**
  46654. * A helper for loading missing data in object graphs. It traverses the graph
  46655. * depth first and queues up any objects that have missing data. Once it has
  46656. * has traversed as many objects that are available it attempts to bundle the
  46657. * missing data requests and then resume from the nodes that weren't ready.
  46658. *
  46659. * NOTE: It provides protection from circular references by keeping track of
  46660. * of loaded references. However, you must be careful not to load any graphs
  46661. * that have references to the catalog or other pages since that will cause the
  46662. * entire PDF document object graph to be traversed.
  46663. */
  46664. var ObjectLoader = function () {
  46665. function mayHaveChildren(value) {
  46666. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  46667. }
  46668. function addChildren(node, nodesToVisit) {
  46669. var value;
  46670. if (isDict(node) || isStream(node)) {
  46671. var map;
  46672. if (isDict(node)) {
  46673. map = node.map;
  46674. } else {
  46675. map = node.dict.map;
  46676. }
  46677. for (var key in map) {
  46678. value = map[key];
  46679. if (mayHaveChildren(value)) {
  46680. nodesToVisit.push(value);
  46681. }
  46682. }
  46683. } else if (isArray(node)) {
  46684. for (var i = 0, ii = node.length; i < ii; i++) {
  46685. value = node[i];
  46686. if (mayHaveChildren(value)) {
  46687. nodesToVisit.push(value);
  46688. }
  46689. }
  46690. }
  46691. }
  46692. function ObjectLoader(obj, keys, xref) {
  46693. this.obj = obj;
  46694. this.keys = keys;
  46695. this.xref = xref;
  46696. this.refSet = null;
  46697. this.capability = null;
  46698. }
  46699. ObjectLoader.prototype = {
  46700. load: function ObjectLoader_load() {
  46701. var keys = this.keys;
  46702. this.capability = createPromiseCapability();
  46703. // Don't walk the graph if all the data is already loaded.
  46704. if (!(this.xref.stream instanceof ChunkedStream) || this.xref.stream.getMissingChunks().length === 0) {
  46705. this.capability.resolve();
  46706. return this.capability.promise;
  46707. }
  46708. this.refSet = new RefSet();
  46709. // Setup the initial nodes to visit.
  46710. var nodesToVisit = [];
  46711. for (var i = 0; i < keys.length; i++) {
  46712. nodesToVisit.push(this.obj[keys[i]]);
  46713. }
  46714. this._walk(nodesToVisit);
  46715. return this.capability.promise;
  46716. },
  46717. _walk: function ObjectLoader_walk(nodesToVisit) {
  46718. var nodesToRevisit = [];
  46719. var pendingRequests = [];
  46720. // DFS walk of the object graph.
  46721. while (nodesToVisit.length) {
  46722. var currentNode = nodesToVisit.pop();
  46723. // Only references or chunked streams can cause missing data exceptions.
  46724. if (isRef(currentNode)) {
  46725. // Skip nodes that have already been visited.
  46726. if (this.refSet.has(currentNode)) {
  46727. continue;
  46728. }
  46729. try {
  46730. var ref = currentNode;
  46731. this.refSet.put(ref);
  46732. currentNode = this.xref.fetch(currentNode);
  46733. } catch (e) {
  46734. if (!(e instanceof MissingDataException)) {
  46735. throw e;
  46736. }
  46737. nodesToRevisit.push(currentNode);
  46738. pendingRequests.push({
  46739. begin: e.begin,
  46740. end: e.end
  46741. });
  46742. }
  46743. }
  46744. if (currentNode && currentNode.getBaseStreams) {
  46745. var baseStreams = currentNode.getBaseStreams();
  46746. var foundMissingData = false;
  46747. for (var i = 0; i < baseStreams.length; i++) {
  46748. var stream = baseStreams[i];
  46749. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  46750. foundMissingData = true;
  46751. pendingRequests.push({
  46752. begin: stream.start,
  46753. end: stream.end
  46754. });
  46755. }
  46756. }
  46757. if (foundMissingData) {
  46758. nodesToRevisit.push(currentNode);
  46759. }
  46760. }
  46761. addChildren(currentNode, nodesToVisit);
  46762. }
  46763. if (pendingRequests.length) {
  46764. this.xref.stream.manager.requestRanges(pendingRequests).then(function pendingRequestCallback() {
  46765. nodesToVisit = nodesToRevisit;
  46766. for (var i = 0; i < nodesToRevisit.length; i++) {
  46767. var node = nodesToRevisit[i];
  46768. // Remove any reference nodes from the currrent refset so they
  46769. // aren't skipped when we revist them.
  46770. if (isRef(node)) {
  46771. this.refSet.remove(node);
  46772. }
  46773. }
  46774. this._walk(nodesToVisit);
  46775. }.bind(this), this.capability.reject);
  46776. return;
  46777. }
  46778. // Everything is loaded.
  46779. this.refSet = null;
  46780. this.capability.resolve();
  46781. }
  46782. };
  46783. return ObjectLoader;
  46784. }();
  46785. exports.Catalog = Catalog;
  46786. exports.ObjectLoader = ObjectLoader;
  46787. exports.XRef = XRef;
  46788. exports.FileSpec = FileSpec;
  46789. }));
  46790. (function (root, factory) {
  46791. factory(root.pdfjsCorePattern = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreFunction, root.pdfjsCoreColorSpace);
  46792. }(this, function (exports, sharedUtil, corePrimitives, coreFunction, coreColorSpace) {
  46793. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  46794. var MissingDataException = sharedUtil.MissingDataException;
  46795. var Util = sharedUtil.Util;
  46796. var assert = sharedUtil.assert;
  46797. var error = sharedUtil.error;
  46798. var info = sharedUtil.info;
  46799. var warn = sharedUtil.warn;
  46800. var isStream = corePrimitives.isStream;
  46801. var PDFFunction = coreFunction.PDFFunction;
  46802. var ColorSpace = coreColorSpace.ColorSpace;
  46803. var ShadingType = {
  46804. FUNCTION_BASED: 1,
  46805. AXIAL: 2,
  46806. RADIAL: 3,
  46807. FREE_FORM_MESH: 4,
  46808. LATTICE_FORM_MESH: 5,
  46809. COONS_PATCH_MESH: 6,
  46810. TENSOR_PATCH_MESH: 7
  46811. };
  46812. var Pattern = function PatternClosure() {
  46813. // Constructor should define this.getPattern
  46814. function Pattern() {
  46815. error('should not call Pattern constructor');
  46816. }
  46817. Pattern.prototype = {
  46818. // Input: current Canvas context
  46819. // Output: the appropriate fillStyle or strokeStyle
  46820. getPattern: function Pattern_getPattern(ctx) {
  46821. error('Should not call Pattern.getStyle: ' + ctx);
  46822. }
  46823. };
  46824. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref, res, handler) {
  46825. var dict = isStream(shading) ? shading.dict : shading;
  46826. var type = dict.get('ShadingType');
  46827. try {
  46828. switch (type) {
  46829. case ShadingType.AXIAL:
  46830. case ShadingType.RADIAL:
  46831. // Both radial and axial shadings are handled by RadialAxial shading.
  46832. return new Shadings.RadialAxial(dict, matrix, xref, res);
  46833. case ShadingType.FREE_FORM_MESH:
  46834. case ShadingType.LATTICE_FORM_MESH:
  46835. case ShadingType.COONS_PATCH_MESH:
  46836. case ShadingType.TENSOR_PATCH_MESH:
  46837. return new Shadings.Mesh(shading, matrix, xref, res);
  46838. default:
  46839. throw new Error('Unsupported ShadingType: ' + type);
  46840. }
  46841. } catch (ex) {
  46842. if (ex instanceof MissingDataException) {
  46843. throw ex;
  46844. }
  46845. handler.send('UnsupportedFeature', { featureId: UNSUPPORTED_FEATURES.shadingPattern });
  46846. warn(ex);
  46847. return new Shadings.Dummy();
  46848. }
  46849. };
  46850. return Pattern;
  46851. }();
  46852. var Shadings = {};
  46853. // A small number to offset the first/last color stops so we can insert ones to
  46854. // support extend. Number.MIN_VALUE is too small and breaks the extend.
  46855. Shadings.SMALL_NUMBER = 1e-6;
  46856. // Radial and axial shading have very similar implementations
  46857. // If needed, the implementations can be broken into two classes
  46858. Shadings.RadialAxial = function RadialAxialClosure() {
  46859. function RadialAxial(dict, matrix, xref, res) {
  46860. this.matrix = matrix;
  46861. this.coordsArr = dict.getArray('Coords');
  46862. this.shadingType = dict.get('ShadingType');
  46863. this.type = 'Pattern';
  46864. var cs = dict.get('ColorSpace', 'CS');
  46865. cs = ColorSpace.parse(cs, xref, res);
  46866. this.cs = cs;
  46867. var t0 = 0.0, t1 = 1.0;
  46868. if (dict.has('Domain')) {
  46869. var domainArr = dict.getArray('Domain');
  46870. t0 = domainArr[0];
  46871. t1 = domainArr[1];
  46872. }
  46873. var extendStart = false, extendEnd = false;
  46874. if (dict.has('Extend')) {
  46875. var extendArr = dict.getArray('Extend');
  46876. extendStart = extendArr[0];
  46877. extendEnd = extendArr[1];
  46878. }
  46879. if (this.shadingType === ShadingType.RADIAL && (!extendStart || !extendEnd)) {
  46880. // Radial gradient only currently works if either circle is fully within
  46881. // the other circle.
  46882. var x1 = this.coordsArr[0];
  46883. var y1 = this.coordsArr[1];
  46884. var r1 = this.coordsArr[2];
  46885. var x2 = this.coordsArr[3];
  46886. var y2 = this.coordsArr[4];
  46887. var r2 = this.coordsArr[5];
  46888. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  46889. if (r1 <= r2 + distance && r2 <= r1 + distance) {
  46890. warn('Unsupported radial gradient.');
  46891. }
  46892. }
  46893. this.extendStart = extendStart;
  46894. this.extendEnd = extendEnd;
  46895. var fnObj = dict.get('Function');
  46896. var fn = PDFFunction.parseArray(xref, fnObj);
  46897. // 10 samples seems good enough for now, but probably won't work
  46898. // if there are sharp color changes. Ideally, we would implement
  46899. // the spec faithfully and add lossless optimizations.
  46900. var diff = t1 - t0;
  46901. var step = diff / 10;
  46902. var colorStops = this.colorStops = [];
  46903. // Protect against bad domains so we don't end up in an infinte loop below.
  46904. if (t0 >= t1 || step <= 0) {
  46905. // Acrobat doesn't seem to handle these cases so we'll ignore for
  46906. // now.
  46907. info('Bad shading domain.');
  46908. return;
  46909. }
  46910. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  46911. var rgbColor;
  46912. for (var i = t0; i <= t1; i += step) {
  46913. ratio[0] = i;
  46914. fn(ratio, 0, color, 0);
  46915. rgbColor = cs.getRgb(color, 0);
  46916. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  46917. colorStops.push([
  46918. (i - t0) / diff,
  46919. cssColor
  46920. ]);
  46921. }
  46922. var background = 'transparent';
  46923. if (dict.has('Background')) {
  46924. rgbColor = cs.getRgb(dict.get('Background'), 0);
  46925. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  46926. }
  46927. if (!extendStart) {
  46928. // Insert a color stop at the front and offset the first real color stop
  46929. // so it doesn't conflict with the one we insert.
  46930. colorStops.unshift([
  46931. 0,
  46932. background
  46933. ]);
  46934. colorStops[1][0] += Shadings.SMALL_NUMBER;
  46935. }
  46936. if (!extendEnd) {
  46937. // Same idea as above in extendStart but for the end.
  46938. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  46939. colorStops.push([
  46940. 1,
  46941. background
  46942. ]);
  46943. }
  46944. this.colorStops = colorStops;
  46945. }
  46946. RadialAxial.prototype = {
  46947. getIR: function RadialAxial_getIR() {
  46948. var coordsArr = this.coordsArr;
  46949. var shadingType = this.shadingType;
  46950. var type, p0, p1, r0, r1;
  46951. if (shadingType === ShadingType.AXIAL) {
  46952. p0 = [
  46953. coordsArr[0],
  46954. coordsArr[1]
  46955. ];
  46956. p1 = [
  46957. coordsArr[2],
  46958. coordsArr[3]
  46959. ];
  46960. r0 = null;
  46961. r1 = null;
  46962. type = 'axial';
  46963. } else if (shadingType === ShadingType.RADIAL) {
  46964. p0 = [
  46965. coordsArr[0],
  46966. coordsArr[1]
  46967. ];
  46968. p1 = [
  46969. coordsArr[3],
  46970. coordsArr[4]
  46971. ];
  46972. r0 = coordsArr[2];
  46973. r1 = coordsArr[5];
  46974. type = 'radial';
  46975. } else {
  46976. error('getPattern type unknown: ' + shadingType);
  46977. }
  46978. var matrix = this.matrix;
  46979. if (matrix) {
  46980. p0 = Util.applyTransform(p0, matrix);
  46981. p1 = Util.applyTransform(p1, matrix);
  46982. if (shadingType === ShadingType.RADIAL) {
  46983. var scale = Util.singularValueDecompose2dScale(matrix);
  46984. r0 *= scale[0];
  46985. r1 *= scale[1];
  46986. }
  46987. }
  46988. return [
  46989. 'RadialAxial',
  46990. type,
  46991. this.colorStops,
  46992. p0,
  46993. p1,
  46994. r0,
  46995. r1
  46996. ];
  46997. }
  46998. };
  46999. return RadialAxial;
  47000. }();
  47001. // All mesh shading. For now, they will be presented as set of the triangles
  47002. // to be drawn on the canvas and rgb color for each vertex.
  47003. Shadings.Mesh = function MeshClosure() {
  47004. function MeshStreamReader(stream, context) {
  47005. this.stream = stream;
  47006. this.context = context;
  47007. this.buffer = 0;
  47008. this.bufferLength = 0;
  47009. var numComps = context.numComps;
  47010. this.tmpCompsBuf = new Float32Array(numComps);
  47011. var csNumComps = context.colorSpace.numComps;
  47012. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) : this.tmpCompsBuf;
  47013. }
  47014. MeshStreamReader.prototype = {
  47015. get hasData() {
  47016. if (this.stream.end) {
  47017. return this.stream.pos < this.stream.end;
  47018. }
  47019. if (this.bufferLength > 0) {
  47020. return true;
  47021. }
  47022. var nextByte = this.stream.getByte();
  47023. if (nextByte < 0) {
  47024. return false;
  47025. }
  47026. this.buffer = nextByte;
  47027. this.bufferLength = 8;
  47028. return true;
  47029. },
  47030. readBits: function MeshStreamReader_readBits(n) {
  47031. var buffer = this.buffer;
  47032. var bufferLength = this.bufferLength;
  47033. if (n === 32) {
  47034. if (bufferLength === 0) {
  47035. return (this.stream.getByte() << 24 | this.stream.getByte() << 16 | this.stream.getByte() << 8 | this.stream.getByte()) >>> 0;
  47036. }
  47037. buffer = buffer << 24 | this.stream.getByte() << 16 | this.stream.getByte() << 8 | this.stream.getByte();
  47038. var nextByte = this.stream.getByte();
  47039. this.buffer = nextByte & (1 << bufferLength) - 1;
  47040. return (buffer << 8 - bufferLength | (nextByte & 0xFF) >> bufferLength) >>> 0;
  47041. }
  47042. if (n === 8 && bufferLength === 0) {
  47043. return this.stream.getByte();
  47044. }
  47045. while (bufferLength < n) {
  47046. buffer = buffer << 8 | this.stream.getByte();
  47047. bufferLength += 8;
  47048. }
  47049. bufferLength -= n;
  47050. this.bufferLength = bufferLength;
  47051. this.buffer = buffer & (1 << bufferLength) - 1;
  47052. return buffer >> bufferLength;
  47053. },
  47054. align: function MeshStreamReader_align() {
  47055. this.buffer = 0;
  47056. this.bufferLength = 0;
  47057. },
  47058. readFlag: function MeshStreamReader_readFlag() {
  47059. return this.readBits(this.context.bitsPerFlag);
  47060. },
  47061. readCoordinate: function MeshStreamReader_readCoordinate() {
  47062. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  47063. var xi = this.readBits(bitsPerCoordinate);
  47064. var yi = this.readBits(bitsPerCoordinate);
  47065. var decode = this.context.decode;
  47066. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) : 2.3283064365386963e-10;
  47067. // 2 ^ -32
  47068. return [
  47069. xi * scale * (decode[1] - decode[0]) + decode[0],
  47070. yi * scale * (decode[3] - decode[2]) + decode[2]
  47071. ];
  47072. },
  47073. readComponents: function MeshStreamReader_readComponents() {
  47074. var numComps = this.context.numComps;
  47075. var bitsPerComponent = this.context.bitsPerComponent;
  47076. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) : 2.3283064365386963e-10;
  47077. // 2 ^ -32
  47078. var decode = this.context.decode;
  47079. var components = this.tmpCompsBuf;
  47080. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  47081. var ci = this.readBits(bitsPerComponent);
  47082. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  47083. }
  47084. var color = this.tmpCsCompsBuf;
  47085. if (this.context.colorFn) {
  47086. this.context.colorFn(components, 0, color, 0);
  47087. }
  47088. return this.context.colorSpace.getRgb(color, 0);
  47089. }
  47090. };
  47091. function decodeType4Shading(mesh, reader) {
  47092. var coords = mesh.coords;
  47093. var colors = mesh.colors;
  47094. var operators = [];
  47095. var ps = [];
  47096. // not maintaining cs since that will match ps
  47097. var verticesLeft = 0;
  47098. // assuming we have all data to start a new triangle
  47099. while (reader.hasData) {
  47100. var f = reader.readFlag();
  47101. var coord = reader.readCoordinate();
  47102. var color = reader.readComponents();
  47103. if (verticesLeft === 0) {
  47104. // ignoring flags if we started a triangle
  47105. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  47106. switch (f) {
  47107. case 0:
  47108. verticesLeft = 3;
  47109. break;
  47110. case 1:
  47111. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  47112. verticesLeft = 1;
  47113. break;
  47114. case 2:
  47115. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  47116. verticesLeft = 1;
  47117. break;
  47118. }
  47119. operators.push(f);
  47120. }
  47121. ps.push(coords.length);
  47122. coords.push(coord);
  47123. colors.push(color);
  47124. verticesLeft--;
  47125. reader.align();
  47126. }
  47127. mesh.figures.push({
  47128. type: 'triangles',
  47129. coords: new Int32Array(ps),
  47130. colors: new Int32Array(ps)
  47131. });
  47132. }
  47133. function decodeType5Shading(mesh, reader, verticesPerRow) {
  47134. var coords = mesh.coords;
  47135. var colors = mesh.colors;
  47136. var ps = [];
  47137. // not maintaining cs since that will match ps
  47138. while (reader.hasData) {
  47139. var coord = reader.readCoordinate();
  47140. var color = reader.readComponents();
  47141. ps.push(coords.length);
  47142. coords.push(coord);
  47143. colors.push(color);
  47144. }
  47145. mesh.figures.push({
  47146. type: 'lattice',
  47147. coords: new Int32Array(ps),
  47148. colors: new Int32Array(ps),
  47149. verticesPerRow: verticesPerRow
  47150. });
  47151. }
  47152. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  47153. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  47154. var TRIANGLE_DENSITY = 20;
  47155. // count of triangles per entire mesh bounds
  47156. var getB = function getBClosure() {
  47157. function buildB(count) {
  47158. var lut = [];
  47159. for (var i = 0; i <= count; i++) {
  47160. var t = i / count, t_ = 1 - t;
  47161. lut.push(new Float32Array([
  47162. t_ * t_ * t_,
  47163. 3 * t * t_ * t_,
  47164. 3 * t * t * t_,
  47165. t * t * t
  47166. ]));
  47167. }
  47168. return lut;
  47169. }
  47170. var cache = [];
  47171. return function getB(count) {
  47172. if (!cache[count]) {
  47173. cache[count] = buildB(count);
  47174. }
  47175. return cache[count];
  47176. };
  47177. }();
  47178. function buildFigureFromPatch(mesh, index) {
  47179. var figure = mesh.figures[index];
  47180. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  47181. var coords = mesh.coords, colors = mesh.colors;
  47182. var pi = figure.coords;
  47183. var ci = figure.colors;
  47184. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0], coords[pi[12]][0], coords[pi[15]][0]);
  47185. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1], coords[pi[12]][1], coords[pi[15]][1]);
  47186. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0], coords[pi[12]][0], coords[pi[15]][0]);
  47187. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1], coords[pi[12]][1], coords[pi[15]][1]);
  47188. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY / (mesh.bounds[2] - mesh.bounds[0]));
  47189. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT, Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  47190. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY / (mesh.bounds[3] - mesh.bounds[1]));
  47191. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT, Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  47192. var verticesPerRow = splitXBy + 1;
  47193. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  47194. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  47195. var k = 0;
  47196. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  47197. var c0 = colors[ci[0]], c1 = colors[ci[1]], c2 = colors[ci[2]], c3 = colors[ci[3]];
  47198. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  47199. for (var row = 0; row <= splitYBy; row++) {
  47200. cl[0] = (c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy | 0;
  47201. cl[1] = (c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy | 0;
  47202. cl[2] = (c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy | 0;
  47203. cr[0] = (c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy | 0;
  47204. cr[1] = (c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy | 0;
  47205. cr[2] = (c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy | 0;
  47206. for (var col = 0; col <= splitXBy; col++, k++) {
  47207. if ((row === 0 || row === splitYBy) && (col === 0 || col === splitXBy)) {
  47208. continue;
  47209. }
  47210. var x = 0, y = 0;
  47211. var q = 0;
  47212. for (var i = 0; i <= 3; i++) {
  47213. for (var j = 0; j <= 3; j++, q++) {
  47214. var m = bRow[row][i] * bCol[col][j];
  47215. x += coords[pi[q]][0] * m;
  47216. y += coords[pi[q]][1] * m;
  47217. }
  47218. }
  47219. figureCoords[k] = coords.length;
  47220. coords.push([
  47221. x,
  47222. y
  47223. ]);
  47224. figureColors[k] = colors.length;
  47225. var newColor = new Uint8Array(3);
  47226. newColor[0] = (cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy | 0;
  47227. newColor[1] = (cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy | 0;
  47228. newColor[2] = (cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy | 0;
  47229. colors.push(newColor);
  47230. }
  47231. }
  47232. figureCoords[0] = pi[0];
  47233. figureColors[0] = ci[0];
  47234. figureCoords[splitXBy] = pi[3];
  47235. figureColors[splitXBy] = ci[1];
  47236. figureCoords[verticesPerRow * splitYBy] = pi[12];
  47237. figureColors[verticesPerRow * splitYBy] = ci[2];
  47238. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  47239. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  47240. mesh.figures[index] = {
  47241. type: 'lattice',
  47242. coords: figureCoords,
  47243. colors: figureColors,
  47244. verticesPerRow: verticesPerRow
  47245. };
  47246. }
  47247. function decodeType6Shading(mesh, reader) {
  47248. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  47249. var coords = mesh.coords;
  47250. var colors = mesh.colors;
  47251. var ps = new Int32Array(16);
  47252. // p00, p10, ..., p30, p01, ..., p33
  47253. var cs = new Int32Array(4);
  47254. // c00, c30, c03, c33
  47255. while (reader.hasData) {
  47256. var f = reader.readFlag();
  47257. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  47258. var i, ii;
  47259. var pi = coords.length;
  47260. for (i = 0, ii = f !== 0 ? 8 : 12; i < ii; i++) {
  47261. coords.push(reader.readCoordinate());
  47262. }
  47263. var ci = colors.length;
  47264. for (i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
  47265. colors.push(reader.readComponents());
  47266. }
  47267. var tmp1, tmp2, tmp3, tmp4;
  47268. switch (f) {
  47269. case 0:
  47270. ps[12] = pi + 3;
  47271. ps[13] = pi + 4;
  47272. ps[14] = pi + 5;
  47273. ps[15] = pi + 6;
  47274. ps[8] = pi + 2;
  47275. /* values for 5, 6, 9, 10 are */
  47276. ps[11] = pi + 7;
  47277. ps[4] = pi + 1;
  47278. /* calculated below */
  47279. ps[7] = pi + 8;
  47280. ps[0] = pi;
  47281. ps[1] = pi + 11;
  47282. ps[2] = pi + 10;
  47283. ps[3] = pi + 9;
  47284. cs[2] = ci + 1;
  47285. cs[3] = ci + 2;
  47286. cs[0] = ci;
  47287. cs[1] = ci + 3;
  47288. break;
  47289. case 1:
  47290. tmp1 = ps[12];
  47291. tmp2 = ps[13];
  47292. tmp3 = ps[14];
  47293. tmp4 = ps[15];
  47294. ps[12] = tmp4;
  47295. ps[13] = pi + 0;
  47296. ps[14] = pi + 1;
  47297. ps[15] = pi + 2;
  47298. ps[8] = tmp3;
  47299. /* values for 5, 6, 9, 10 are */
  47300. ps[11] = pi + 3;
  47301. ps[4] = tmp2;
  47302. /* calculated below */
  47303. ps[7] = pi + 4;
  47304. ps[0] = tmp1;
  47305. ps[1] = pi + 7;
  47306. ps[2] = pi + 6;
  47307. ps[3] = pi + 5;
  47308. tmp1 = cs[2];
  47309. tmp2 = cs[3];
  47310. cs[2] = tmp2;
  47311. cs[3] = ci;
  47312. cs[0] = tmp1;
  47313. cs[1] = ci + 1;
  47314. break;
  47315. case 2:
  47316. tmp1 = ps[15];
  47317. tmp2 = ps[11];
  47318. ps[12] = ps[3];
  47319. ps[13] = pi + 0;
  47320. ps[14] = pi + 1;
  47321. ps[15] = pi + 2;
  47322. ps[8] = ps[7];
  47323. /* values for 5, 6, 9, 10 are */
  47324. ps[11] = pi + 3;
  47325. ps[4] = tmp2;
  47326. /* calculated below */
  47327. ps[7] = pi + 4;
  47328. ps[0] = tmp1;
  47329. ps[1] = pi + 7;
  47330. ps[2] = pi + 6;
  47331. ps[3] = pi + 5;
  47332. tmp1 = cs[3];
  47333. cs[2] = cs[1];
  47334. cs[3] = ci;
  47335. cs[0] = tmp1;
  47336. cs[1] = ci + 1;
  47337. break;
  47338. case 3:
  47339. ps[12] = ps[0];
  47340. ps[13] = pi + 0;
  47341. ps[14] = pi + 1;
  47342. ps[15] = pi + 2;
  47343. ps[8] = ps[1];
  47344. /* values for 5, 6, 9, 10 are */
  47345. ps[11] = pi + 3;
  47346. ps[4] = ps[2];
  47347. /* calculated below */
  47348. ps[7] = pi + 4;
  47349. ps[0] = ps[3];
  47350. ps[1] = pi + 7;
  47351. ps[2] = pi + 6;
  47352. ps[3] = pi + 5;
  47353. cs[2] = cs[0];
  47354. cs[3] = ci;
  47355. cs[0] = cs[1];
  47356. cs[1] = ci + 1;
  47357. break;
  47358. }
  47359. // set p11, p12, p21, p22
  47360. ps[5] = coords.length;
  47361. coords.push([
  47362. (-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,
  47363. (-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
  47364. ]);
  47365. ps[6] = coords.length;
  47366. coords.push([
  47367. (-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,
  47368. (-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
  47369. ]);
  47370. ps[9] = coords.length;
  47371. coords.push([
  47372. (-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,
  47373. (-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
  47374. ]);
  47375. ps[10] = coords.length;
  47376. coords.push([
  47377. (-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,
  47378. (-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
  47379. ]);
  47380. mesh.figures.push({
  47381. type: 'patch',
  47382. coords: new Int32Array(ps),
  47383. // making copies of ps and cs
  47384. colors: new Int32Array(cs)
  47385. });
  47386. }
  47387. }
  47388. function decodeType7Shading(mesh, reader) {
  47389. var coords = mesh.coords;
  47390. var colors = mesh.colors;
  47391. var ps = new Int32Array(16);
  47392. // p00, p10, ..., p30, p01, ..., p33
  47393. var cs = new Int32Array(4);
  47394. // c00, c30, c03, c33
  47395. while (reader.hasData) {
  47396. var f = reader.readFlag();
  47397. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  47398. var i, ii;
  47399. var pi = coords.length;
  47400. for (i = 0, ii = f !== 0 ? 12 : 16; i < ii; i++) {
  47401. coords.push(reader.readCoordinate());
  47402. }
  47403. var ci = colors.length;
  47404. for (i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
  47405. colors.push(reader.readComponents());
  47406. }
  47407. var tmp1, tmp2, tmp3, tmp4;
  47408. switch (f) {
  47409. case 0:
  47410. ps[12] = pi + 3;
  47411. ps[13] = pi + 4;
  47412. ps[14] = pi + 5;
  47413. ps[15] = pi + 6;
  47414. ps[8] = pi + 2;
  47415. ps[9] = pi + 13;
  47416. ps[10] = pi + 14;
  47417. ps[11] = pi + 7;
  47418. ps[4] = pi + 1;
  47419. ps[5] = pi + 12;
  47420. ps[6] = pi + 15;
  47421. ps[7] = pi + 8;
  47422. ps[0] = pi;
  47423. ps[1] = pi + 11;
  47424. ps[2] = pi + 10;
  47425. ps[3] = pi + 9;
  47426. cs[2] = ci + 1;
  47427. cs[3] = ci + 2;
  47428. cs[0] = ci;
  47429. cs[1] = ci + 3;
  47430. break;
  47431. case 1:
  47432. tmp1 = ps[12];
  47433. tmp2 = ps[13];
  47434. tmp3 = ps[14];
  47435. tmp4 = ps[15];
  47436. ps[12] = tmp4;
  47437. ps[13] = pi + 0;
  47438. ps[14] = pi + 1;
  47439. ps[15] = pi + 2;
  47440. ps[8] = tmp3;
  47441. ps[9] = pi + 9;
  47442. ps[10] = pi + 10;
  47443. ps[11] = pi + 3;
  47444. ps[4] = tmp2;
  47445. ps[5] = pi + 8;
  47446. ps[6] = pi + 11;
  47447. ps[7] = pi + 4;
  47448. ps[0] = tmp1;
  47449. ps[1] = pi + 7;
  47450. ps[2] = pi + 6;
  47451. ps[3] = pi + 5;
  47452. tmp1 = cs[2];
  47453. tmp2 = cs[3];
  47454. cs[2] = tmp2;
  47455. cs[3] = ci;
  47456. cs[0] = tmp1;
  47457. cs[1] = ci + 1;
  47458. break;
  47459. case 2:
  47460. tmp1 = ps[15];
  47461. tmp2 = ps[11];
  47462. ps[12] = ps[3];
  47463. ps[13] = pi + 0;
  47464. ps[14] = pi + 1;
  47465. ps[15] = pi + 2;
  47466. ps[8] = ps[7];
  47467. ps[9] = pi + 9;
  47468. ps[10] = pi + 10;
  47469. ps[11] = pi + 3;
  47470. ps[4] = tmp2;
  47471. ps[5] = pi + 8;
  47472. ps[6] = pi + 11;
  47473. ps[7] = pi + 4;
  47474. ps[0] = tmp1;
  47475. ps[1] = pi + 7;
  47476. ps[2] = pi + 6;
  47477. ps[3] = pi + 5;
  47478. tmp1 = cs[3];
  47479. cs[2] = cs[1];
  47480. cs[3] = ci;
  47481. cs[0] = tmp1;
  47482. cs[1] = ci + 1;
  47483. break;
  47484. case 3:
  47485. ps[12] = ps[0];
  47486. ps[13] = pi + 0;
  47487. ps[14] = pi + 1;
  47488. ps[15] = pi + 2;
  47489. ps[8] = ps[1];
  47490. ps[9] = pi + 9;
  47491. ps[10] = pi + 10;
  47492. ps[11] = pi + 3;
  47493. ps[4] = ps[2];
  47494. ps[5] = pi + 8;
  47495. ps[6] = pi + 11;
  47496. ps[7] = pi + 4;
  47497. ps[0] = ps[3];
  47498. ps[1] = pi + 7;
  47499. ps[2] = pi + 6;
  47500. ps[3] = pi + 5;
  47501. cs[2] = cs[0];
  47502. cs[3] = ci;
  47503. cs[0] = cs[1];
  47504. cs[1] = ci + 1;
  47505. break;
  47506. }
  47507. mesh.figures.push({
  47508. type: 'patch',
  47509. coords: new Int32Array(ps),
  47510. // making copies of ps and cs
  47511. colors: new Int32Array(cs)
  47512. });
  47513. }
  47514. }
  47515. function updateBounds(mesh) {
  47516. var minX = mesh.coords[0][0], minY = mesh.coords[0][1], maxX = minX, maxY = minY;
  47517. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  47518. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  47519. minX = minX > x ? x : minX;
  47520. minY = minY > y ? y : minY;
  47521. maxX = maxX < x ? x : maxX;
  47522. maxY = maxY < y ? y : maxY;
  47523. }
  47524. mesh.bounds = [
  47525. minX,
  47526. minY,
  47527. maxX,
  47528. maxY
  47529. ];
  47530. }
  47531. function packData(mesh) {
  47532. var i, ii, j, jj;
  47533. var coords = mesh.coords;
  47534. var coordsPacked = new Float32Array(coords.length * 2);
  47535. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  47536. var xy = coords[i];
  47537. coordsPacked[j++] = xy[0];
  47538. coordsPacked[j++] = xy[1];
  47539. }
  47540. mesh.coords = coordsPacked;
  47541. var colors = mesh.colors;
  47542. var colorsPacked = new Uint8Array(colors.length * 3);
  47543. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  47544. var c = colors[i];
  47545. colorsPacked[j++] = c[0];
  47546. colorsPacked[j++] = c[1];
  47547. colorsPacked[j++] = c[2];
  47548. }
  47549. mesh.colors = colorsPacked;
  47550. var figures = mesh.figures;
  47551. for (i = 0, ii = figures.length; i < ii; i++) {
  47552. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  47553. for (j = 0, jj = ps.length; j < jj; j++) {
  47554. ps[j] *= 2;
  47555. cs[j] *= 3;
  47556. }
  47557. }
  47558. }
  47559. function Mesh(stream, matrix, xref, res) {
  47560. assert(isStream(stream), 'Mesh data is not a stream');
  47561. var dict = stream.dict;
  47562. this.matrix = matrix;
  47563. this.shadingType = dict.get('ShadingType');
  47564. this.type = 'Pattern';
  47565. this.bbox = dict.getArray('BBox');
  47566. var cs = dict.get('ColorSpace', 'CS');
  47567. cs = ColorSpace.parse(cs, xref, res);
  47568. this.cs = cs;
  47569. this.background = dict.has('Background') ? cs.getRgb(dict.get('Background'), 0) : null;
  47570. var fnObj = dict.get('Function');
  47571. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  47572. this.coords = [];
  47573. this.colors = [];
  47574. this.figures = [];
  47575. var decodeContext = {
  47576. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  47577. bitsPerComponent: dict.get('BitsPerComponent'),
  47578. bitsPerFlag: dict.get('BitsPerFlag'),
  47579. decode: dict.getArray('Decode'),
  47580. colorFn: fn,
  47581. colorSpace: cs,
  47582. numComps: fn ? 1 : cs.numComps
  47583. };
  47584. var reader = new MeshStreamReader(stream, decodeContext);
  47585. var patchMesh = false;
  47586. switch (this.shadingType) {
  47587. case ShadingType.FREE_FORM_MESH:
  47588. decodeType4Shading(this, reader);
  47589. break;
  47590. case ShadingType.LATTICE_FORM_MESH:
  47591. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  47592. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  47593. decodeType5Shading(this, reader, verticesPerRow);
  47594. break;
  47595. case ShadingType.COONS_PATCH_MESH:
  47596. decodeType6Shading(this, reader);
  47597. patchMesh = true;
  47598. break;
  47599. case ShadingType.TENSOR_PATCH_MESH:
  47600. decodeType7Shading(this, reader);
  47601. patchMesh = true;
  47602. break;
  47603. default:
  47604. error('Unsupported mesh type.');
  47605. break;
  47606. }
  47607. if (patchMesh) {
  47608. // dirty bounds calculation for determining, how dense shall be triangles
  47609. updateBounds(this);
  47610. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  47611. buildFigureFromPatch(this, i);
  47612. }
  47613. }
  47614. // calculate bounds
  47615. updateBounds(this);
  47616. packData(this);
  47617. }
  47618. Mesh.prototype = {
  47619. getIR: function Mesh_getIR() {
  47620. return [
  47621. 'Mesh',
  47622. this.shadingType,
  47623. this.coords,
  47624. this.colors,
  47625. this.figures,
  47626. this.bounds,
  47627. this.matrix,
  47628. this.bbox,
  47629. this.background
  47630. ];
  47631. }
  47632. };
  47633. return Mesh;
  47634. }();
  47635. Shadings.Dummy = function DummyClosure() {
  47636. function Dummy() {
  47637. this.type = 'Pattern';
  47638. }
  47639. Dummy.prototype = {
  47640. getIR: function Dummy_getIR() {
  47641. return ['Dummy'];
  47642. }
  47643. };
  47644. return Dummy;
  47645. }();
  47646. function getTilingPatternIR(operatorList, dict, args) {
  47647. var matrix = dict.getArray('Matrix');
  47648. var bbox = dict.getArray('BBox');
  47649. var xstep = dict.get('XStep');
  47650. var ystep = dict.get('YStep');
  47651. var paintType = dict.get('PaintType');
  47652. var tilingType = dict.get('TilingType');
  47653. return [
  47654. 'TilingPattern',
  47655. args,
  47656. operatorList,
  47657. matrix,
  47658. bbox,
  47659. xstep,
  47660. ystep,
  47661. paintType,
  47662. tilingType
  47663. ];
  47664. }
  47665. exports.Pattern = Pattern;
  47666. exports.getTilingPatternIR = getTilingPatternIR;
  47667. }));
  47668. (function (root, factory) {
  47669. 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);
  47670. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser, coreImage, coreColorSpace, coreMurmurHash3, coreFonts, coreFunction, corePattern, coreCMap, coreMetrics, coreBidi, coreEncodings, coreStandardFonts, coreUnicode, coreGlyphList) {
  47671. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  47672. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  47673. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  47674. var ImageKind = sharedUtil.ImageKind;
  47675. var OPS = sharedUtil.OPS;
  47676. var TextRenderingMode = sharedUtil.TextRenderingMode;
  47677. var Util = sharedUtil.Util;
  47678. var assert = sharedUtil.assert;
  47679. var createPromiseCapability = sharedUtil.createPromiseCapability;
  47680. var error = sharedUtil.error;
  47681. var info = sharedUtil.info;
  47682. var isArray = sharedUtil.isArray;
  47683. var isNum = sharedUtil.isNum;
  47684. var isString = sharedUtil.isString;
  47685. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  47686. var warn = sharedUtil.warn;
  47687. var Dict = corePrimitives.Dict;
  47688. var Name = corePrimitives.Name;
  47689. var isCmd = corePrimitives.isCmd;
  47690. var isDict = corePrimitives.isDict;
  47691. var isName = corePrimitives.isName;
  47692. var isRef = corePrimitives.isRef;
  47693. var isStream = corePrimitives.isStream;
  47694. var DecodeStream = coreStream.DecodeStream;
  47695. var JpegStream = coreStream.JpegStream;
  47696. var Stream = coreStream.Stream;
  47697. var Lexer = coreParser.Lexer;
  47698. var Parser = coreParser.Parser;
  47699. var isEOF = coreParser.isEOF;
  47700. var PDFImage = coreImage.PDFImage;
  47701. var ColorSpace = coreColorSpace.ColorSpace;
  47702. var MurmurHash3_64 = coreMurmurHash3.MurmurHash3_64;
  47703. var ErrorFont = coreFonts.ErrorFont;
  47704. var FontFlags = coreFonts.FontFlags;
  47705. var Font = coreFonts.Font;
  47706. var IdentityToUnicodeMap = coreFonts.IdentityToUnicodeMap;
  47707. var ToUnicodeMap = coreFonts.ToUnicodeMap;
  47708. var getFontType = coreFonts.getFontType;
  47709. var isPDFFunction = coreFunction.isPDFFunction;
  47710. var PDFFunction = coreFunction.PDFFunction;
  47711. var Pattern = corePattern.Pattern;
  47712. var getTilingPatternIR = corePattern.getTilingPatternIR;
  47713. var CMapFactory = coreCMap.CMapFactory;
  47714. var IdentityCMap = coreCMap.IdentityCMap;
  47715. var getMetrics = coreMetrics.getMetrics;
  47716. var bidi = coreBidi.bidi;
  47717. var WinAnsiEncoding = coreEncodings.WinAnsiEncoding;
  47718. var StandardEncoding = coreEncodings.StandardEncoding;
  47719. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  47720. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  47721. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  47722. var getEncoding = coreEncodings.getEncoding;
  47723. var getStdFontMap = coreStandardFonts.getStdFontMap;
  47724. var getSerifFonts = coreStandardFonts.getSerifFonts;
  47725. var getSymbolsFonts = coreStandardFonts.getSymbolsFonts;
  47726. var getNormalizedUnicodes = coreUnicode.getNormalizedUnicodes;
  47727. var reverseIfRtl = coreUnicode.reverseIfRtl;
  47728. var getUnicodeForGlyph = coreUnicode.getUnicodeForGlyph;
  47729. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  47730. var PartialEvaluator = function PartialEvaluatorClosure() {
  47731. var DefaultPartialEvaluatorOptions = {
  47732. forceDataSchema: false,
  47733. maxImageSize: -1,
  47734. disableFontFace: false,
  47735. cMapOptions: {
  47736. url: null,
  47737. packed: false
  47738. }
  47739. };
  47740. function NativeImageDecoder(xref, resources, handler, forceDataSchema) {
  47741. this.xref = xref;
  47742. this.resources = resources;
  47743. this.handler = handler;
  47744. this.forceDataSchema = forceDataSchema;
  47745. }
  47746. NativeImageDecoder.prototype = {
  47747. canDecode: function (image) {
  47748. return image instanceof JpegStream && NativeImageDecoder.isDecodable(image, this.xref, this.resources);
  47749. },
  47750. decode: function (image) {
  47751. // For natively supported JPEGs send them to the main thread for decoding.
  47752. var dict = image.dict;
  47753. var colorSpace = dict.get('ColorSpace', 'CS');
  47754. colorSpace = ColorSpace.parse(colorSpace, this.xref, this.resources);
  47755. var numComps = colorSpace.numComps;
  47756. var decodePromise = this.handler.sendWithPromise('JpegDecode', [
  47757. image.getIR(this.forceDataSchema),
  47758. numComps
  47759. ]);
  47760. return decodePromise.then(function (message) {
  47761. var data = message.data;
  47762. return new Stream(data, 0, data.length, image.dict);
  47763. });
  47764. }
  47765. };
  47766. /**
  47767. * Checks if the image can be decoded and displayed by the browser without any
  47768. * further processing such as color space conversions.
  47769. */
  47770. NativeImageDecoder.isSupported = function NativeImageDecoder_isSupported(image, xref, res) {
  47771. var dict = image.dict;
  47772. if (dict.has('DecodeParms') || dict.has('DP')) {
  47773. return false;
  47774. }
  47775. var cs = ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res);
  47776. return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') && cs.isDefaultDecode(dict.getArray('Decode', 'D'));
  47777. };
  47778. /**
  47779. * Checks if the image can be decoded by the browser.
  47780. */
  47781. NativeImageDecoder.isDecodable = function NativeImageDecoder_isDecodable(image, xref, res) {
  47782. var dict = image.dict;
  47783. if (dict.has('DecodeParms') || dict.has('DP')) {
  47784. return false;
  47785. }
  47786. var cs = ColorSpace.parse(dict.get('ColorSpace', 'CS'), xref, res);
  47787. return (cs.numComps === 1 || cs.numComps === 3) && cs.isDefaultDecode(dict.getArray('Decode', 'D'));
  47788. };
  47789. function PartialEvaluator(pdfManager, xref, handler, pageIndex, uniquePrefix, idCounters, fontCache, options) {
  47790. this.pdfManager = pdfManager;
  47791. this.xref = xref;
  47792. this.handler = handler;
  47793. this.pageIndex = pageIndex;
  47794. this.uniquePrefix = uniquePrefix;
  47795. this.idCounters = idCounters;
  47796. this.fontCache = fontCache;
  47797. this.options = options || DefaultPartialEvaluatorOptions;
  47798. }
  47799. // Trying to minimize Date.now() usage and check every 100 time
  47800. var TIME_SLOT_DURATION_MS = 20;
  47801. var CHECK_TIME_EVERY = 100;
  47802. function TimeSlotManager() {
  47803. this.reset();
  47804. }
  47805. TimeSlotManager.prototype = {
  47806. check: function TimeSlotManager_check() {
  47807. if (++this.checked < CHECK_TIME_EVERY) {
  47808. return false;
  47809. }
  47810. this.checked = 0;
  47811. return this.endTime <= Date.now();
  47812. },
  47813. reset: function TimeSlotManager_reset() {
  47814. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  47815. this.checked = 0;
  47816. }
  47817. };
  47818. var deferred = Promise.resolve();
  47819. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  47820. PartialEvaluator.prototype = {
  47821. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  47822. if (!isDict(resources)) {
  47823. return false;
  47824. }
  47825. var processed = Object.create(null);
  47826. if (resources.objId) {
  47827. processed[resources.objId] = true;
  47828. }
  47829. var nodes = [resources], xref = this.xref;
  47830. while (nodes.length) {
  47831. var key, i, ii;
  47832. var node = nodes.shift();
  47833. // First check the current resources for blend modes.
  47834. var graphicStates = node.get('ExtGState');
  47835. if (isDict(graphicStates)) {
  47836. var graphicStatesKeys = graphicStates.getKeys();
  47837. for (i = 0, ii = graphicStatesKeys.length; i < ii; i++) {
  47838. key = graphicStatesKeys[i];
  47839. var graphicState = graphicStates.get(key);
  47840. var bm = graphicState.get('BM');
  47841. if (isName(bm) && bm.name !== 'Normal') {
  47842. return true;
  47843. }
  47844. }
  47845. }
  47846. // Descend into the XObjects to look for more resources and blend modes.
  47847. var xObjects = node.get('XObject');
  47848. if (!isDict(xObjects)) {
  47849. continue;
  47850. }
  47851. var xObjectsKeys = xObjects.getKeys();
  47852. for (i = 0, ii = xObjectsKeys.length; i < ii; i++) {
  47853. key = xObjectsKeys[i];
  47854. var xObject = xObjects.getRaw(key);
  47855. if (isRef(xObject)) {
  47856. if (processed[xObject.toString()]) {
  47857. // The XObject has already been processed, and by avoiding a
  47858. // redundant `xref.fetch` we can *significantly* reduce the load
  47859. // time for badly generated PDF files (fixes issue6961.pdf).
  47860. continue;
  47861. }
  47862. xObject = xref.fetch(xObject);
  47863. }
  47864. if (!isStream(xObject)) {
  47865. continue;
  47866. }
  47867. if (xObject.dict.objId) {
  47868. if (processed[xObject.dict.objId]) {
  47869. // stream has objId and is processed already
  47870. continue;
  47871. }
  47872. processed[xObject.dict.objId] = true;
  47873. }
  47874. var xResources = xObject.dict.get('Resources');
  47875. // Checking objId to detect an infinite loop.
  47876. if (isDict(xResources) && (!xResources.objId || !processed[xResources.objId])) {
  47877. nodes.push(xResources);
  47878. if (xResources.objId) {
  47879. processed[xResources.objId] = true;
  47880. }
  47881. }
  47882. }
  47883. }
  47884. return false;
  47885. },
  47886. buildFormXObject: function PartialEvaluator_buildFormXObject(resources, xobj, smask, operatorList, task, initialState) {
  47887. var matrix = xobj.dict.getArray('Matrix');
  47888. var bbox = xobj.dict.getArray('BBox');
  47889. var group = xobj.dict.get('Group');
  47890. if (group) {
  47891. var groupOptions = {
  47892. matrix: matrix,
  47893. bbox: bbox,
  47894. smask: smask,
  47895. isolated: false,
  47896. knockout: false
  47897. };
  47898. var groupSubtype = group.get('S');
  47899. var colorSpace;
  47900. if (isName(groupSubtype, 'Transparency')) {
  47901. groupOptions.isolated = group.get('I') || false;
  47902. groupOptions.knockout = group.get('K') || false;
  47903. colorSpace = group.has('CS') ? ColorSpace.parse(group.get('CS'), this.xref, resources) : null;
  47904. }
  47905. if (smask && smask.backdrop) {
  47906. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  47907. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  47908. }
  47909. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  47910. }
  47911. operatorList.addOp(OPS.paintFormXObjectBegin, [
  47912. matrix,
  47913. bbox
  47914. ]);
  47915. return this.getOperatorList(xobj, task, xobj.dict.get('Resources') || resources, operatorList, initialState).then(function () {
  47916. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  47917. if (group) {
  47918. operatorList.addOp(OPS.endGroup, [groupOptions]);
  47919. }
  47920. });
  47921. },
  47922. buildPaintImageXObject: function PartialEvaluator_buildPaintImageXObject(resources, image, inline, operatorList, cacheKey, imageCache) {
  47923. var self = this;
  47924. var dict = image.dict;
  47925. var w = dict.get('Width', 'W');
  47926. var h = dict.get('Height', 'H');
  47927. if (!(w && isNum(w)) || !(h && isNum(h))) {
  47928. warn('Image dimensions are missing, or not numbers.');
  47929. return;
  47930. }
  47931. var maxImageSize = this.options.maxImageSize;
  47932. if (maxImageSize !== -1 && w * h > maxImageSize) {
  47933. warn('Image exceeded maximum allowed size and was removed.');
  47934. return;
  47935. }
  47936. var imageMask = dict.get('ImageMask', 'IM') || false;
  47937. var imgData, args;
  47938. if (imageMask) {
  47939. // This depends on a tmpCanvas being filled with the
  47940. // current fillStyle, such that processing the pixel
  47941. // data can't be done here. Instead of creating a
  47942. // complete PDFImage, only read the information needed
  47943. // for later.
  47944. var width = dict.get('Width', 'W');
  47945. var height = dict.get('Height', 'H');
  47946. var bitStrideLength = width + 7 >> 3;
  47947. var imgArray = image.getBytes(bitStrideLength * height);
  47948. var decode = dict.getArray('Decode', 'D');
  47949. var inverseDecode = !!decode && decode[0] > 0;
  47950. imgData = PDFImage.createMask(imgArray, width, height, image instanceof DecodeStream, inverseDecode);
  47951. imgData.cached = true;
  47952. args = [imgData];
  47953. operatorList.addOp(OPS.paintImageMaskXObject, args);
  47954. if (cacheKey) {
  47955. imageCache[cacheKey] = {
  47956. fn: OPS.paintImageMaskXObject,
  47957. args: args
  47958. };
  47959. }
  47960. return;
  47961. }
  47962. var softMask = dict.get('SMask', 'SM') || false;
  47963. var mask = dict.get('Mask') || false;
  47964. var SMALL_IMAGE_DIMENSIONS = 200;
  47965. // Inlining small images into the queue as RGB data
  47966. if (inline && !softMask && !mask && !(image instanceof JpegStream) && w + h < SMALL_IMAGE_DIMENSIONS) {
  47967. var imageObj = new PDFImage(this.xref, resources, image, inline, null, null);
  47968. // We force the use of RGBA_32BPP images here, because we can't handle
  47969. // any other kind.
  47970. imgData = imageObj.createImageData(/* forceRGBA = */
  47971. true);
  47972. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  47973. return;
  47974. }
  47975. // If there is no imageMask, create the PDFImage and a lot
  47976. // of image processing can be done here.
  47977. var uniquePrefix = this.uniquePrefix || '';
  47978. var objId = 'img_' + uniquePrefix + ++this.idCounters.obj;
  47979. operatorList.addDependency(objId);
  47980. args = [
  47981. objId,
  47982. w,
  47983. h
  47984. ];
  47985. if (!softMask && !mask && image instanceof JpegStream && NativeImageDecoder.isSupported(image, this.xref, resources)) {
  47986. // These JPEGs don't need any more processing so we can just send it.
  47987. operatorList.addOp(OPS.paintJpegXObject, args);
  47988. this.handler.send('obj', [
  47989. objId,
  47990. this.pageIndex,
  47991. 'JpegStream',
  47992. image.getIR(this.options.forceDataSchema)
  47993. ]);
  47994. return;
  47995. }
  47996. // Creates native image decoder only if a JPEG image or mask is present.
  47997. var nativeImageDecoder = null;
  47998. if (image instanceof JpegStream || mask instanceof JpegStream || softMask instanceof JpegStream) {
  47999. nativeImageDecoder = new NativeImageDecoder(self.xref, resources, self.handler, self.options.forceDataSchema);
  48000. }
  48001. PDFImage.buildImage(self.handler, self.xref, resources, image, inline, nativeImageDecoder).then(function (imageObj) {
  48002. var imgData = imageObj.createImageData(/* forceRGBA = */
  48003. false);
  48004. self.handler.send('obj', [
  48005. objId,
  48006. self.pageIndex,
  48007. 'Image',
  48008. imgData
  48009. ], [imgData.data.buffer]);
  48010. }).then(undefined, function (reason) {
  48011. warn('Unable to decode image: ' + reason);
  48012. self.handler.send('obj', [
  48013. objId,
  48014. self.pageIndex,
  48015. 'Image',
  48016. null
  48017. ]);
  48018. });
  48019. operatorList.addOp(OPS.paintImageXObject, args);
  48020. if (cacheKey) {
  48021. imageCache[cacheKey] = {
  48022. fn: OPS.paintImageXObject,
  48023. args: args
  48024. };
  48025. }
  48026. },
  48027. handleSMask: function PartialEvaluator_handleSmask(smask, resources, operatorList, task, stateManager) {
  48028. var smaskContent = smask.get('G');
  48029. var smaskOptions = {
  48030. subtype: smask.get('S').name,
  48031. backdrop: smask.get('BC')
  48032. };
  48033. // The SMask might have a alpha/luminosity value transfer function --
  48034. // we will build a map of integer values in range 0..255 to be fast.
  48035. var transferObj = smask.get('TR');
  48036. if (isPDFFunction(transferObj)) {
  48037. var transferFn = PDFFunction.parse(this.xref, transferObj);
  48038. var transferMap = new Uint8Array(256);
  48039. var tmp = new Float32Array(1);
  48040. for (var i = 0; i < 256; i++) {
  48041. tmp[0] = i / 255;
  48042. transferFn(tmp, 0, tmp, 0);
  48043. transferMap[i] = tmp[0] * 255 | 0;
  48044. }
  48045. smaskOptions.transferMap = transferMap;
  48046. }
  48047. return this.buildFormXObject(resources, smaskContent, smaskOptions, operatorList, task, stateManager.state.clone());
  48048. },
  48049. handleTilingType: function PartialEvaluator_handleTilingType(fn, args, resources, pattern, patternDict, operatorList, task) {
  48050. // Create an IR of the pattern code.
  48051. var tilingOpList = new OperatorList();
  48052. // Merge the available resources, to prevent issues when the patternDict
  48053. // is missing some /Resources entries (fixes issue6541.pdf).
  48054. var resourcesArray = [
  48055. patternDict.get('Resources'),
  48056. resources
  48057. ];
  48058. var patternResources = Dict.merge(this.xref, resourcesArray);
  48059. return this.getOperatorList(pattern, task, patternResources, tilingOpList).then(function () {
  48060. // Add the dependencies to the parent operator list so they are
  48061. // resolved before sub operator list is executed synchronously.
  48062. operatorList.addDependencies(tilingOpList.dependencies);
  48063. operatorList.addOp(fn, getTilingPatternIR({
  48064. fnArray: tilingOpList.fnArray,
  48065. argsArray: tilingOpList.argsArray
  48066. }, patternDict, args));
  48067. });
  48068. },
  48069. handleSetFont: function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef, operatorList, task, state) {
  48070. // TODO(mack): Not needed?
  48071. var fontName;
  48072. if (fontArgs) {
  48073. fontArgs = fontArgs.slice();
  48074. fontName = fontArgs[0].name;
  48075. }
  48076. var self = this;
  48077. return this.loadFont(fontName, fontRef, this.xref, resources).then(function (translated) {
  48078. if (!translated.font.isType3Font) {
  48079. return translated;
  48080. }
  48081. return translated.loadType3Data(self, resources, operatorList, task).then(function () {
  48082. return translated;
  48083. }, function (reason) {
  48084. // Error in the font data -- sending unsupported feature notification.
  48085. self.handler.send('UnsupportedFeature', { featureId: UNSUPPORTED_FEATURES.font });
  48086. return new TranslatedFont('g_font_error', new ErrorFont('Type3 font load error: ' + reason), translated.font);
  48087. });
  48088. }).then(function (translated) {
  48089. state.font = translated.font;
  48090. translated.send(self.handler);
  48091. return translated.loadedName;
  48092. });
  48093. },
  48094. handleText: function PartialEvaluator_handleText(chars, state) {
  48095. var font = state.font;
  48096. var glyphs = font.charsToGlyphs(chars);
  48097. var isAddToPathSet = !!(state.textRenderingMode & TextRenderingMode.ADD_TO_PATH_FLAG);
  48098. if (font.data && (isAddToPathSet || this.options.disableFontFace)) {
  48099. var buildPath = function (fontChar) {
  48100. if (!font.renderer.hasBuiltPath(fontChar)) {
  48101. var path = font.renderer.getPathJs(fontChar);
  48102. this.handler.send('commonobj', [
  48103. font.loadedName + '_path_' + fontChar,
  48104. 'FontPath',
  48105. path
  48106. ]);
  48107. }
  48108. }.bind(this);
  48109. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  48110. var glyph = glyphs[i];
  48111. buildPath(glyph.fontChar);
  48112. // If the glyph has an accent we need to build a path for its
  48113. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  48114. var accent = glyph.accent;
  48115. if (accent && accent.fontChar) {
  48116. buildPath(accent.fontChar);
  48117. }
  48118. }
  48119. }
  48120. return glyphs;
  48121. },
  48122. setGState: function PartialEvaluator_setGState(resources, gState, operatorList, task, xref, stateManager) {
  48123. // This array holds the converted/processed state data.
  48124. var gStateObj = [];
  48125. var gStateKeys = gState.getKeys();
  48126. var self = this;
  48127. var promise = Promise.resolve();
  48128. for (var i = 0, ii = gStateKeys.length; i < ii; i++) {
  48129. var key = gStateKeys[i];
  48130. var value = gState.get(key);
  48131. switch (key) {
  48132. case 'Type':
  48133. break;
  48134. case 'LW':
  48135. case 'LC':
  48136. case 'LJ':
  48137. case 'ML':
  48138. case 'D':
  48139. case 'RI':
  48140. case 'FL':
  48141. case 'CA':
  48142. case 'ca':
  48143. gStateObj.push([
  48144. key,
  48145. value
  48146. ]);
  48147. break;
  48148. case 'Font':
  48149. promise = promise.then(function () {
  48150. return self.handleSetFont(resources, null, value[0], operatorList, task, stateManager.state).then(function (loadedName) {
  48151. operatorList.addDependency(loadedName);
  48152. gStateObj.push([
  48153. key,
  48154. [
  48155. loadedName,
  48156. value[1]
  48157. ]
  48158. ]);
  48159. });
  48160. });
  48161. break;
  48162. case 'BM':
  48163. gStateObj.push([
  48164. key,
  48165. value
  48166. ]);
  48167. break;
  48168. case 'SMask':
  48169. if (isName(value, 'None')) {
  48170. gStateObj.push([
  48171. key,
  48172. false
  48173. ]);
  48174. break;
  48175. }
  48176. if (isDict(value)) {
  48177. promise = promise.then(function (dict) {
  48178. return self.handleSMask(dict, resources, operatorList, task, stateManager);
  48179. }.bind(this, value));
  48180. gStateObj.push([
  48181. key,
  48182. true
  48183. ]);
  48184. } else {
  48185. warn('Unsupported SMask type');
  48186. }
  48187. break;
  48188. // Only generate info log messages for the following since
  48189. // they are unlikely to have a big impact on the rendering.
  48190. case 'OP':
  48191. case 'op':
  48192. case 'OPM':
  48193. case 'BG':
  48194. case 'BG2':
  48195. case 'UCR':
  48196. case 'UCR2':
  48197. case 'TR':
  48198. case 'TR2':
  48199. case 'HT':
  48200. case 'SM':
  48201. case 'SA':
  48202. case 'AIS':
  48203. case 'TK':
  48204. // TODO implement these operators.
  48205. info('graphic state operator ' + key);
  48206. break;
  48207. default:
  48208. info('Unknown graphic state operator ' + key);
  48209. break;
  48210. }
  48211. }
  48212. return promise.then(function () {
  48213. if (gStateObj.length > 0) {
  48214. operatorList.addOp(OPS.setGState, [gStateObj]);
  48215. }
  48216. });
  48217. },
  48218. loadFont: function PartialEvaluator_loadFont(fontName, font, xref, resources) {
  48219. function errorFont() {
  48220. return Promise.resolve(new TranslatedFont('g_font_error', new ErrorFont('Font ' + fontName + ' is not available'), font));
  48221. }
  48222. var fontRef;
  48223. if (font) {
  48224. // Loading by ref.
  48225. assert(isRef(font));
  48226. fontRef = font;
  48227. } else {
  48228. // Loading by name.
  48229. var fontRes = resources.get('Font');
  48230. if (fontRes) {
  48231. fontRef = fontRes.getRaw(fontName);
  48232. } else {
  48233. warn('fontRes not available');
  48234. return errorFont();
  48235. }
  48236. }
  48237. if (!fontRef) {
  48238. warn('fontRef not available');
  48239. return errorFont();
  48240. }
  48241. if (this.fontCache.has(fontRef)) {
  48242. return this.fontCache.get(fontRef);
  48243. }
  48244. font = xref.fetchIfRef(fontRef);
  48245. if (!isDict(font)) {
  48246. return errorFont();
  48247. }
  48248. // We are holding `font.translated` references just for `fontRef`s that
  48249. // are not actually `Ref`s, but rather `Dict`s. See explanation below.
  48250. if (font.translated) {
  48251. return font.translated;
  48252. }
  48253. var fontCapability = createPromiseCapability();
  48254. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  48255. var descriptor = preEvaluatedFont.descriptor;
  48256. var fontRefIsRef = isRef(fontRef), fontID;
  48257. if (fontRefIsRef) {
  48258. fontID = fontRef.toString();
  48259. }
  48260. if (isDict(descriptor)) {
  48261. if (!descriptor.fontAliases) {
  48262. descriptor.fontAliases = Object.create(null);
  48263. }
  48264. var fontAliases = descriptor.fontAliases;
  48265. var hash = preEvaluatedFont.hash;
  48266. if (fontAliases[hash]) {
  48267. var aliasFontRef = fontAliases[hash].aliasRef;
  48268. if (fontRefIsRef && aliasFontRef && this.fontCache.has(aliasFontRef)) {
  48269. this.fontCache.putAlias(fontRef, aliasFontRef);
  48270. return this.fontCache.get(fontRef);
  48271. }
  48272. } else {
  48273. fontAliases[hash] = { fontID: Font.getFontID() };
  48274. }
  48275. if (fontRefIsRef) {
  48276. fontAliases[hash].aliasRef = fontRef;
  48277. }
  48278. fontID = fontAliases[hash].fontID;
  48279. }
  48280. // Workaround for bad PDF generators that reference fonts incorrectly,
  48281. // where `fontRef` is a `Dict` rather than a `Ref` (fixes bug946506.pdf).
  48282. // In this case we should not put the font into `this.fontCache` (which is
  48283. // a `RefSetCache`), since it's not meaningful to use a `Dict` as a key.
  48284. //
  48285. // However, if we don't cache the font it's not possible to remove it
  48286. // when `cleanup` is triggered from the API, which causes issues on
  48287. // subsequent rendering operations (see issue7403.pdf).
  48288. // A simple workaround would be to just not hold `font.translated`
  48289. // references in this case, but this would force us to unnecessarily load
  48290. // the same fonts over and over.
  48291. //
  48292. // Instead, we cheat a bit by attempting to use a modified `fontID` as a
  48293. // key in `this.fontCache`, to allow the font to be cached.
  48294. // NOTE: This works because `RefSetCache` calls `toString()` on provided
  48295. // keys. Also, since `fontRef` is used when getting cached fonts,
  48296. // we'll not accidentally match fonts cached with the `fontID`.
  48297. if (fontRefIsRef) {
  48298. this.fontCache.put(fontRef, fontCapability.promise);
  48299. } else {
  48300. if (!fontID) {
  48301. fontID = (this.uniquePrefix || 'F_') + ++this.idCounters.obj;
  48302. }
  48303. this.fontCache.put('id_' + fontID, fontCapability.promise);
  48304. }
  48305. assert(fontID, 'The "fontID" must be defined.');
  48306. // Keep track of each font we translated so the caller can
  48307. // load them asynchronously before calling display on a page.
  48308. font.loadedName = 'g_' + this.pdfManager.docId + '_f' + fontID;
  48309. font.translated = fontCapability.promise;
  48310. // TODO move promises into translate font
  48311. var translatedPromise;
  48312. try {
  48313. translatedPromise = this.translateFont(preEvaluatedFont, xref);
  48314. } catch (e) {
  48315. translatedPromise = Promise.reject(e);
  48316. }
  48317. var self = this;
  48318. translatedPromise.then(function (translatedFont) {
  48319. if (translatedFont.fontType !== undefined) {
  48320. var xrefFontStats = xref.stats.fontTypes;
  48321. xrefFontStats[translatedFont.fontType] = true;
  48322. }
  48323. fontCapability.resolve(new TranslatedFont(font.loadedName, translatedFont, font));
  48324. }, function (reason) {
  48325. // TODO fontCapability.reject?
  48326. // Error in the font data -- sending unsupported feature notification.
  48327. self.handler.send('UnsupportedFeature', { featureId: UNSUPPORTED_FEATURES.font });
  48328. try {
  48329. // error, but it's still nice to have font type reported
  48330. var descriptor = preEvaluatedFont.descriptor;
  48331. var fontFile3 = descriptor && descriptor.get('FontFile3');
  48332. var subtype = fontFile3 && fontFile3.get('Subtype');
  48333. var fontType = getFontType(preEvaluatedFont.type, subtype && subtype.name);
  48334. var xrefFontStats = xref.stats.fontTypes;
  48335. xrefFontStats[fontType] = true;
  48336. } catch (ex) {
  48337. }
  48338. fontCapability.resolve(new TranslatedFont(font.loadedName, new ErrorFont(reason instanceof Error ? reason.message : reason), font));
  48339. });
  48340. return fontCapability.promise;
  48341. },
  48342. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  48343. var lastIndex = operatorList.length - 1;
  48344. if (!args) {
  48345. args = [];
  48346. }
  48347. if (lastIndex < 0 || operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  48348. operatorList.addOp(OPS.constructPath, [
  48349. [fn],
  48350. args
  48351. ]);
  48352. } else {
  48353. var opArgs = operatorList.argsArray[lastIndex];
  48354. opArgs[0].push(fn);
  48355. Array.prototype.push.apply(opArgs[1], args);
  48356. }
  48357. },
  48358. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args, cs, patterns, resources, task, xref) {
  48359. // compile tiling patterns
  48360. var patternName = args[args.length - 1];
  48361. // SCN/scn applies patterns along with normal colors
  48362. var pattern;
  48363. if (isName(patternName) && (pattern = patterns.get(patternName.name))) {
  48364. var dict = isStream(pattern) ? pattern.dict : pattern;
  48365. var typeNum = dict.get('PatternType');
  48366. if (typeNum === TILING_PATTERN) {
  48367. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  48368. return this.handleTilingType(fn, color, resources, pattern, dict, operatorList, task);
  48369. } else if (typeNum === SHADING_PATTERN) {
  48370. var shading = dict.get('Shading');
  48371. var matrix = dict.getArray('Matrix');
  48372. pattern = Pattern.parseShading(shading, matrix, xref, resources, this.handler);
  48373. operatorList.addOp(fn, pattern.getIR());
  48374. return Promise.resolve();
  48375. } else {
  48376. return Promise.reject('Unknown PatternType: ' + typeNum);
  48377. }
  48378. }
  48379. // TODO shall we fail here?
  48380. operatorList.addOp(fn, args);
  48381. return Promise.resolve();
  48382. },
  48383. getOperatorList: function PartialEvaluator_getOperatorList(stream, task, resources, operatorList, initialState) {
  48384. var self = this;
  48385. var xref = this.xref;
  48386. var imageCache = Object.create(null);
  48387. assert(operatorList);
  48388. resources = resources || Dict.empty;
  48389. var xobjs = resources.get('XObject') || Dict.empty;
  48390. var patterns = resources.get('Pattern') || Dict.empty;
  48391. var stateManager = new StateManager(initialState || new EvalState());
  48392. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  48393. var timeSlotManager = new TimeSlotManager();
  48394. return new Promise(function promiseBody(resolve, reject) {
  48395. var next = function (promise) {
  48396. promise.then(function () {
  48397. try {
  48398. promiseBody(resolve, reject);
  48399. } catch (ex) {
  48400. reject(ex);
  48401. }
  48402. }, reject);
  48403. };
  48404. task.ensureNotTerminated();
  48405. timeSlotManager.reset();
  48406. var stop, operation = {}, i, ii, cs;
  48407. while (!(stop = timeSlotManager.check())) {
  48408. // The arguments parsed by read() are used beyond this loop, so we
  48409. // cannot reuse the same array on each iteration. Therefore we pass
  48410. // in |null| as the initial value (see the comment on
  48411. // EvaluatorPreprocessor_read() for why).
  48412. operation.args = null;
  48413. if (!preprocessor.read(operation)) {
  48414. break;
  48415. }
  48416. var args = operation.args;
  48417. var fn = operation.fn;
  48418. switch (fn | 0) {
  48419. case OPS.paintXObject:
  48420. if (args[0].code) {
  48421. break;
  48422. }
  48423. // eagerly compile XForm objects
  48424. var name = args[0].name;
  48425. if (!name) {
  48426. warn('XObject must be referred to by name.');
  48427. continue;
  48428. }
  48429. if (imageCache[name] !== undefined) {
  48430. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  48431. args = null;
  48432. continue;
  48433. }
  48434. var xobj = xobjs.get(name);
  48435. if (xobj) {
  48436. assert(isStream(xobj), 'XObject should be a stream');
  48437. var type = xobj.dict.get('Subtype');
  48438. assert(isName(type), 'XObject should have a Name subtype');
  48439. if (type.name === 'Form') {
  48440. stateManager.save();
  48441. next(self.buildFormXObject(resources, xobj, null, operatorList, task, stateManager.state.clone()).then(function () {
  48442. stateManager.restore();
  48443. }));
  48444. return;
  48445. } else if (type.name === 'Image') {
  48446. self.buildPaintImageXObject(resources, xobj, false, operatorList, name, imageCache);
  48447. args = null;
  48448. continue;
  48449. } else if (type.name === 'PS') {
  48450. // PostScript XObjects are unused when viewing documents.
  48451. // See section 4.7.1 of Adobe's PDF reference.
  48452. info('Ignored XObject subtype PS');
  48453. continue;
  48454. } else {
  48455. error('Unhandled XObject subtype ' + type.name);
  48456. }
  48457. }
  48458. break;
  48459. case OPS.setFont:
  48460. var fontSize = args[1];
  48461. // eagerly collect all fonts
  48462. next(self.handleSetFont(resources, args, null, operatorList, task, stateManager.state).then(function (loadedName) {
  48463. operatorList.addDependency(loadedName);
  48464. operatorList.addOp(OPS.setFont, [
  48465. loadedName,
  48466. fontSize
  48467. ]);
  48468. }));
  48469. return;
  48470. case OPS.endInlineImage:
  48471. var cacheKey = args[0].cacheKey;
  48472. if (cacheKey) {
  48473. var cacheEntry = imageCache[cacheKey];
  48474. if (cacheEntry !== undefined) {
  48475. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  48476. args = null;
  48477. continue;
  48478. }
  48479. }
  48480. self.buildPaintImageXObject(resources, args[0], true, operatorList, cacheKey, imageCache);
  48481. args = null;
  48482. continue;
  48483. case OPS.showText:
  48484. args[0] = self.handleText(args[0], stateManager.state);
  48485. break;
  48486. case OPS.showSpacedText:
  48487. var arr = args[0];
  48488. var combinedGlyphs = [];
  48489. var arrLength = arr.length;
  48490. var state = stateManager.state;
  48491. for (i = 0; i < arrLength; ++i) {
  48492. var arrItem = arr[i];
  48493. if (isString(arrItem)) {
  48494. Array.prototype.push.apply(combinedGlyphs, self.handleText(arrItem, state));
  48495. } else if (isNum(arrItem)) {
  48496. combinedGlyphs.push(arrItem);
  48497. }
  48498. }
  48499. args[0] = combinedGlyphs;
  48500. fn = OPS.showText;
  48501. break;
  48502. case OPS.nextLineShowText:
  48503. operatorList.addOp(OPS.nextLine);
  48504. args[0] = self.handleText(args[0], stateManager.state);
  48505. fn = OPS.showText;
  48506. break;
  48507. case OPS.nextLineSetSpacingShowText:
  48508. operatorList.addOp(OPS.nextLine);
  48509. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  48510. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  48511. args[0] = self.handleText(args[0], stateManager.state);
  48512. fn = OPS.showText;
  48513. break;
  48514. case OPS.setTextRenderingMode:
  48515. stateManager.state.textRenderingMode = args[0];
  48516. break;
  48517. case OPS.setFillColorSpace:
  48518. stateManager.state.fillColorSpace = ColorSpace.parse(args[0], xref, resources);
  48519. continue;
  48520. case OPS.setStrokeColorSpace:
  48521. stateManager.state.strokeColorSpace = ColorSpace.parse(args[0], xref, resources);
  48522. continue;
  48523. case OPS.setFillColor:
  48524. cs = stateManager.state.fillColorSpace;
  48525. args = cs.getRgb(args, 0);
  48526. fn = OPS.setFillRGBColor;
  48527. break;
  48528. case OPS.setStrokeColor:
  48529. cs = stateManager.state.strokeColorSpace;
  48530. args = cs.getRgb(args, 0);
  48531. fn = OPS.setStrokeRGBColor;
  48532. break;
  48533. case OPS.setFillGray:
  48534. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  48535. args = ColorSpace.singletons.gray.getRgb(args, 0);
  48536. fn = OPS.setFillRGBColor;
  48537. break;
  48538. case OPS.setStrokeGray:
  48539. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  48540. args = ColorSpace.singletons.gray.getRgb(args, 0);
  48541. fn = OPS.setStrokeRGBColor;
  48542. break;
  48543. case OPS.setFillCMYKColor:
  48544. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  48545. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  48546. fn = OPS.setFillRGBColor;
  48547. break;
  48548. case OPS.setStrokeCMYKColor:
  48549. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  48550. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  48551. fn = OPS.setStrokeRGBColor;
  48552. break;
  48553. case OPS.setFillRGBColor:
  48554. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  48555. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  48556. break;
  48557. case OPS.setStrokeRGBColor:
  48558. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  48559. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  48560. break;
  48561. case OPS.setFillColorN:
  48562. cs = stateManager.state.fillColorSpace;
  48563. if (cs.name === 'Pattern') {
  48564. next(self.handleColorN(operatorList, OPS.setFillColorN, args, cs, patterns, resources, task, xref));
  48565. return;
  48566. }
  48567. args = cs.getRgb(args, 0);
  48568. fn = OPS.setFillRGBColor;
  48569. break;
  48570. case OPS.setStrokeColorN:
  48571. cs = stateManager.state.strokeColorSpace;
  48572. if (cs.name === 'Pattern') {
  48573. next(self.handleColorN(operatorList, OPS.setStrokeColorN, args, cs, patterns, resources, task, xref));
  48574. return;
  48575. }
  48576. args = cs.getRgb(args, 0);
  48577. fn = OPS.setStrokeRGBColor;
  48578. break;
  48579. case OPS.shadingFill:
  48580. var shadingRes = resources.get('Shading');
  48581. if (!shadingRes) {
  48582. error('No shading resource found');
  48583. }
  48584. var shading = shadingRes.get(args[0].name);
  48585. if (!shading) {
  48586. error('No shading object found');
  48587. }
  48588. var shadingFill = Pattern.parseShading(shading, null, xref, resources, self.handler);
  48589. var patternIR = shadingFill.getIR();
  48590. args = [patternIR];
  48591. fn = OPS.shadingFill;
  48592. break;
  48593. case OPS.setGState:
  48594. var dictName = args[0];
  48595. var extGState = resources.get('ExtGState');
  48596. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  48597. break;
  48598. }
  48599. var gState = extGState.get(dictName.name);
  48600. next(self.setGState(resources, gState, operatorList, task, xref, stateManager));
  48601. return;
  48602. case OPS.moveTo:
  48603. case OPS.lineTo:
  48604. case OPS.curveTo:
  48605. case OPS.curveTo2:
  48606. case OPS.curveTo3:
  48607. case OPS.closePath:
  48608. self.buildPath(operatorList, fn, args);
  48609. continue;
  48610. case OPS.rectangle:
  48611. self.buildPath(operatorList, fn, args);
  48612. continue;
  48613. case OPS.markPoint:
  48614. case OPS.markPointProps:
  48615. case OPS.beginMarkedContent:
  48616. case OPS.beginMarkedContentProps:
  48617. case OPS.endMarkedContent:
  48618. case OPS.beginCompat:
  48619. case OPS.endCompat:
  48620. // Ignore operators where the corresponding handlers are known to
  48621. // be no-op in CanvasGraphics (display/canvas.js). This prevents
  48622. // serialization errors and is also a bit more efficient.
  48623. // We could also try to serialize all objects in a general way,
  48624. // e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
  48625. // but doing so is meaningless without knowing the semantics.
  48626. continue;
  48627. default:
  48628. // Note: Ignore the operator if it has `Dict` arguments, since
  48629. // those are non-serializable, otherwise postMessage will throw
  48630. // "An object could not be cloned.".
  48631. if (args !== null) {
  48632. for (i = 0, ii = args.length; i < ii; i++) {
  48633. if (args[i] instanceof Dict) {
  48634. break;
  48635. }
  48636. }
  48637. if (i < ii) {
  48638. warn('getOperatorList - ignoring operator: ' + fn);
  48639. continue;
  48640. }
  48641. }
  48642. }
  48643. operatorList.addOp(fn, args);
  48644. }
  48645. if (stop) {
  48646. next(deferred);
  48647. return;
  48648. }
  48649. // Some PDFs don't close all restores inside object/form.
  48650. // Closing those for them.
  48651. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  48652. operatorList.addOp(OPS.restore, []);
  48653. }
  48654. resolve();
  48655. });
  48656. },
  48657. getTextContent: function PartialEvaluator_getTextContent(stream, task, resources, stateManager, normalizeWhitespace, combineTextItems) {
  48658. stateManager = stateManager || new StateManager(new TextState());
  48659. var WhitespaceRegexp = /\s/g;
  48660. var textContent = {
  48661. items: [],
  48662. styles: Object.create(null)
  48663. };
  48664. var textContentItem = {
  48665. initialized: false,
  48666. str: [],
  48667. width: 0,
  48668. height: 0,
  48669. vertical: false,
  48670. lastAdvanceWidth: 0,
  48671. lastAdvanceHeight: 0,
  48672. textAdvanceScale: 0,
  48673. spaceWidth: 0,
  48674. fakeSpaceMin: Infinity,
  48675. fakeMultiSpaceMin: Infinity,
  48676. fakeMultiSpaceMax: -0,
  48677. textRunBreakAllowed: false,
  48678. transform: null,
  48679. fontName: null
  48680. };
  48681. var SPACE_FACTOR = 0.3;
  48682. var MULTI_SPACE_FACTOR = 1.5;
  48683. var MULTI_SPACE_FACTOR_MAX = 4;
  48684. var self = this;
  48685. var xref = this.xref;
  48686. resources = xref.fetchIfRef(resources) || Dict.empty;
  48687. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  48688. var xobjs = null;
  48689. var xobjsCache = Object.create(null);
  48690. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  48691. var textState;
  48692. function ensureTextContentItem() {
  48693. if (textContentItem.initialized) {
  48694. return textContentItem;
  48695. }
  48696. var font = textState.font;
  48697. if (!(font.loadedName in textContent.styles)) {
  48698. textContent.styles[font.loadedName] = {
  48699. fontFamily: font.fallbackName,
  48700. ascent: font.ascent,
  48701. descent: font.descent,
  48702. vertical: font.vertical
  48703. };
  48704. }
  48705. textContentItem.fontName = font.loadedName;
  48706. // 9.4.4 Text Space Details
  48707. var tsm = [
  48708. textState.fontSize * textState.textHScale,
  48709. 0,
  48710. 0,
  48711. textState.fontSize,
  48712. 0,
  48713. textState.textRise
  48714. ];
  48715. if (font.isType3Font && textState.fontMatrix !== FONT_IDENTITY_MATRIX && textState.fontSize === 1) {
  48716. var glyphHeight = font.bbox[3] - font.bbox[1];
  48717. if (glyphHeight > 0) {
  48718. glyphHeight = glyphHeight * textState.fontMatrix[3];
  48719. tsm[3] *= glyphHeight;
  48720. }
  48721. }
  48722. var trm = Util.transform(textState.ctm, Util.transform(textState.textMatrix, tsm));
  48723. textContentItem.transform = trm;
  48724. if (!font.vertical) {
  48725. textContentItem.width = 0;
  48726. textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  48727. textContentItem.vertical = false;
  48728. } else {
  48729. textContentItem.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  48730. textContentItem.height = 0;
  48731. textContentItem.vertical = true;
  48732. }
  48733. var a = textState.textLineMatrix[0];
  48734. var b = textState.textLineMatrix[1];
  48735. var scaleLineX = Math.sqrt(a * a + b * b);
  48736. a = textState.ctm[0];
  48737. b = textState.ctm[1];
  48738. var scaleCtmX = Math.sqrt(a * a + b * b);
  48739. textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
  48740. textContentItem.lastAdvanceWidth = 0;
  48741. textContentItem.lastAdvanceHeight = 0;
  48742. var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
  48743. if (spaceWidth) {
  48744. textContentItem.spaceWidth = spaceWidth;
  48745. textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
  48746. textContentItem.fakeMultiSpaceMin = spaceWidth * MULTI_SPACE_FACTOR;
  48747. textContentItem.fakeMultiSpaceMax = spaceWidth * MULTI_SPACE_FACTOR_MAX;
  48748. // It's okay for monospace fonts to fake as much space as needed.
  48749. textContentItem.textRunBreakAllowed = !font.isMonospace;
  48750. } else {
  48751. textContentItem.spaceWidth = 0;
  48752. textContentItem.fakeSpaceMin = Infinity;
  48753. textContentItem.fakeMultiSpaceMin = Infinity;
  48754. textContentItem.fakeMultiSpaceMax = 0;
  48755. textContentItem.textRunBreakAllowed = false;
  48756. }
  48757. textContentItem.initialized = true;
  48758. return textContentItem;
  48759. }
  48760. function replaceWhitespace(str) {
  48761. // Replaces all whitespaces with standard spaces (0x20), to avoid
  48762. // alignment issues between the textLayer and the canvas if the text
  48763. // contains e.g. tabs (fixes issue6612.pdf).
  48764. var i = 0, ii = str.length, code;
  48765. while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7F) {
  48766. i++;
  48767. }
  48768. return i < ii ? str.replace(WhitespaceRegexp, ' ') : str;
  48769. }
  48770. function runBidiTransform(textChunk) {
  48771. var str = textChunk.str.join('');
  48772. var bidiResult = bidi(str, -1, textChunk.vertical);
  48773. return {
  48774. str: normalizeWhitespace ? replaceWhitespace(bidiResult.str) : bidiResult.str,
  48775. dir: bidiResult.dir,
  48776. width: textChunk.width,
  48777. height: textChunk.height,
  48778. transform: textChunk.transform,
  48779. fontName: textChunk.fontName
  48780. };
  48781. }
  48782. function handleSetFont(fontName, fontRef) {
  48783. return self.loadFont(fontName, fontRef, xref, resources).then(function (translated) {
  48784. textState.font = translated.font;
  48785. textState.fontMatrix = translated.font.fontMatrix || FONT_IDENTITY_MATRIX;
  48786. });
  48787. }
  48788. function buildTextContentItem(chars) {
  48789. var font = textState.font;
  48790. var textChunk = ensureTextContentItem();
  48791. var width = 0;
  48792. var height = 0;
  48793. var glyphs = font.charsToGlyphs(chars);
  48794. var defaultVMetrics = font.defaultVMetrics;
  48795. for (var i = 0; i < glyphs.length; i++) {
  48796. var glyph = glyphs[i];
  48797. var vMetricX = null;
  48798. var vMetricY = null;
  48799. var glyphWidth = null;
  48800. if (font.vertical) {
  48801. if (glyph.vmetric) {
  48802. glyphWidth = glyph.vmetric[0];
  48803. vMetricX = glyph.vmetric[1];
  48804. vMetricY = glyph.vmetric[2];
  48805. } else {
  48806. glyphWidth = glyph.width;
  48807. vMetricX = glyph.width * 0.5;
  48808. vMetricY = defaultVMetrics[2];
  48809. }
  48810. } else {
  48811. glyphWidth = glyph.width;
  48812. }
  48813. var glyphUnicode = glyph.unicode;
  48814. var NormalizedUnicodes = getNormalizedUnicodes();
  48815. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  48816. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  48817. }
  48818. glyphUnicode = reverseIfRtl(glyphUnicode);
  48819. // The following will calculate the x and y of the individual glyphs.
  48820. // if (font.vertical) {
  48821. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  48822. // textState.fontMatrix[0];
  48823. // tsm[5] -= vMetricY * textState.fontSize *
  48824. // textState.fontMatrix[0];
  48825. // }
  48826. // var trm = Util.transform(textState.textMatrix, tsm);
  48827. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  48828. // var x = pt[0];
  48829. // var y = pt[1];
  48830. var charSpacing = textState.charSpacing;
  48831. if (glyph.isSpace) {
  48832. var wordSpacing = textState.wordSpacing;
  48833. charSpacing += wordSpacing;
  48834. if (wordSpacing > 0) {
  48835. addFakeSpaces(wordSpacing, textChunk.str);
  48836. }
  48837. }
  48838. var tx = 0;
  48839. var ty = 0;
  48840. if (!font.vertical) {
  48841. var w0 = glyphWidth * textState.fontMatrix[0];
  48842. tx = (w0 * textState.fontSize + charSpacing) * textState.textHScale;
  48843. width += tx;
  48844. } else {
  48845. var w1 = glyphWidth * textState.fontMatrix[0];
  48846. ty = w1 * textState.fontSize + charSpacing;
  48847. height += ty;
  48848. }
  48849. textState.translateTextMatrix(tx, ty);
  48850. textChunk.str.push(glyphUnicode);
  48851. }
  48852. if (!font.vertical) {
  48853. textChunk.lastAdvanceWidth = width;
  48854. textChunk.width += width * textChunk.textAdvanceScale;
  48855. } else {
  48856. textChunk.lastAdvanceHeight = height;
  48857. textChunk.height += Math.abs(height * textChunk.textAdvanceScale);
  48858. }
  48859. return textChunk;
  48860. }
  48861. function addFakeSpaces(width, strBuf) {
  48862. if (width < textContentItem.fakeSpaceMin) {
  48863. return;
  48864. }
  48865. if (width < textContentItem.fakeMultiSpaceMin) {
  48866. strBuf.push(' ');
  48867. return;
  48868. }
  48869. var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
  48870. while (fakeSpaces-- > 0) {
  48871. strBuf.push(' ');
  48872. }
  48873. }
  48874. function flushTextContentItem() {
  48875. if (!textContentItem.initialized) {
  48876. return;
  48877. }
  48878. textContent.items.push(runBidiTransform(textContentItem));
  48879. textContentItem.initialized = false;
  48880. textContentItem.str.length = 0;
  48881. }
  48882. var timeSlotManager = new TimeSlotManager();
  48883. return new Promise(function promiseBody(resolve, reject) {
  48884. var next = function (promise) {
  48885. promise.then(function () {
  48886. try {
  48887. promiseBody(resolve, reject);
  48888. } catch (ex) {
  48889. reject(ex);
  48890. }
  48891. }, reject);
  48892. };
  48893. task.ensureNotTerminated();
  48894. timeSlotManager.reset();
  48895. var stop, operation = {}, args = [];
  48896. while (!(stop = timeSlotManager.check())) {
  48897. // The arguments parsed by read() are not used beyond this loop, so
  48898. // we can reuse the same array on every iteration, thus avoiding
  48899. // unnecessary allocations.
  48900. args.length = 0;
  48901. operation.args = args;
  48902. if (!preprocessor.read(operation)) {
  48903. break;
  48904. }
  48905. textState = stateManager.state;
  48906. var fn = operation.fn;
  48907. args = operation.args;
  48908. var advance, diff;
  48909. switch (fn | 0) {
  48910. case OPS.setFont:
  48911. // Optimization to ignore multiple identical Tf commands.
  48912. var fontNameArg = args[0].name, fontSizeArg = args[1];
  48913. if (textState.font && fontNameArg === textState.fontName && fontSizeArg === textState.fontSize) {
  48914. break;
  48915. }
  48916. flushTextContentItem();
  48917. textState.fontName = fontNameArg;
  48918. textState.fontSize = fontSizeArg;
  48919. next(handleSetFont(fontNameArg, null));
  48920. return;
  48921. case OPS.setTextRise:
  48922. flushTextContentItem();
  48923. textState.textRise = args[0];
  48924. break;
  48925. case OPS.setHScale:
  48926. flushTextContentItem();
  48927. textState.textHScale = args[0] / 100;
  48928. break;
  48929. case OPS.setLeading:
  48930. flushTextContentItem();
  48931. textState.leading = args[0];
  48932. break;
  48933. case OPS.moveText:
  48934. // Optimization to treat same line movement as advance
  48935. var isSameTextLine = !textState.font ? false : (textState.font.vertical ? args[0] : args[1]) === 0;
  48936. advance = args[0] - args[1];
  48937. if (combineTextItems && isSameTextLine && textContentItem.initialized && advance > 0 && advance <= textContentItem.fakeMultiSpaceMax) {
  48938. textState.translateTextLineMatrix(args[0], args[1]);
  48939. textContentItem.width += args[0] - textContentItem.lastAdvanceWidth;
  48940. textContentItem.height += args[1] - textContentItem.lastAdvanceHeight;
  48941. diff = args[0] - textContentItem.lastAdvanceWidth - (args[1] - textContentItem.lastAdvanceHeight);
  48942. addFakeSpaces(diff, textContentItem.str);
  48943. break;
  48944. }
  48945. flushTextContentItem();
  48946. textState.translateTextLineMatrix(args[0], args[1]);
  48947. textState.textMatrix = textState.textLineMatrix.slice();
  48948. break;
  48949. case OPS.setLeadingMoveText:
  48950. flushTextContentItem();
  48951. textState.leading = -args[1];
  48952. textState.translateTextLineMatrix(args[0], args[1]);
  48953. textState.textMatrix = textState.textLineMatrix.slice();
  48954. break;
  48955. case OPS.nextLine:
  48956. flushTextContentItem();
  48957. textState.carriageReturn();
  48958. break;
  48959. case OPS.setTextMatrix:
  48960. // Optimization to treat same line movement as advance.
  48961. advance = textState.calcTextLineMatrixAdvance(args[0], args[1], args[2], args[3], args[4], args[5]);
  48962. if (combineTextItems && advance !== null && textContentItem.initialized && advance.value > 0 && advance.value <= textContentItem.fakeMultiSpaceMax) {
  48963. textState.translateTextLineMatrix(advance.width, advance.height);
  48964. textContentItem.width += advance.width - textContentItem.lastAdvanceWidth;
  48965. textContentItem.height += advance.height - textContentItem.lastAdvanceHeight;
  48966. diff = advance.width - textContentItem.lastAdvanceWidth - (advance.height - textContentItem.lastAdvanceHeight);
  48967. addFakeSpaces(diff, textContentItem.str);
  48968. break;
  48969. }
  48970. flushTextContentItem();
  48971. textState.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
  48972. textState.setTextLineMatrix(args[0], args[1], args[2], args[3], args[4], args[5]);
  48973. break;
  48974. case OPS.setCharSpacing:
  48975. textState.charSpacing = args[0];
  48976. break;
  48977. case OPS.setWordSpacing:
  48978. textState.wordSpacing = args[0];
  48979. break;
  48980. case OPS.beginText:
  48981. flushTextContentItem();
  48982. textState.textMatrix = IDENTITY_MATRIX.slice();
  48983. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  48984. break;
  48985. case OPS.showSpacedText:
  48986. var items = args[0];
  48987. var offset;
  48988. for (var j = 0, jj = items.length; j < jj; j++) {
  48989. if (typeof items[j] === 'string') {
  48990. buildTextContentItem(items[j]);
  48991. } else if (isNum(items[j])) {
  48992. ensureTextContentItem();
  48993. // PDF Specification 5.3.2 states:
  48994. // The number is expressed in thousandths of a unit of text
  48995. // space.
  48996. // This amount is subtracted from the current horizontal or
  48997. // vertical coordinate, depending on the writing mode.
  48998. // In the default coordinate system, a positive adjustment
  48999. // has the effect of moving the next glyph painted either to
  49000. // the left or down by the given amount.
  49001. advance = items[j] * textState.fontSize / 1000;
  49002. var breakTextRun = false;
  49003. if (textState.font.vertical) {
  49004. offset = advance * (textState.textHScale * textState.textMatrix[2] + textState.textMatrix[3]);
  49005. textState.translateTextMatrix(0, advance);
  49006. breakTextRun = textContentItem.textRunBreakAllowed && advance > textContentItem.fakeMultiSpaceMax;
  49007. if (!breakTextRun) {
  49008. // Value needs to be added to height to paint down.
  49009. textContentItem.height += offset;
  49010. }
  49011. } else {
  49012. advance = -advance;
  49013. offset = advance * (textState.textHScale * textState.textMatrix[0] + textState.textMatrix[1]);
  49014. textState.translateTextMatrix(advance, 0);
  49015. breakTextRun = textContentItem.textRunBreakAllowed && advance > textContentItem.fakeMultiSpaceMax;
  49016. if (!breakTextRun) {
  49017. // Value needs to be subtracted from width to paint left.
  49018. textContentItem.width += offset;
  49019. }
  49020. }
  49021. if (breakTextRun) {
  49022. flushTextContentItem();
  49023. } else if (advance > 0) {
  49024. addFakeSpaces(advance, textContentItem.str);
  49025. }
  49026. }
  49027. }
  49028. break;
  49029. case OPS.showText:
  49030. buildTextContentItem(args[0]);
  49031. break;
  49032. case OPS.nextLineShowText:
  49033. flushTextContentItem();
  49034. textState.carriageReturn();
  49035. buildTextContentItem(args[0]);
  49036. break;
  49037. case OPS.nextLineSetSpacingShowText:
  49038. flushTextContentItem();
  49039. textState.wordSpacing = args[0];
  49040. textState.charSpacing = args[1];
  49041. textState.carriageReturn();
  49042. buildTextContentItem(args[2]);
  49043. break;
  49044. case OPS.paintXObject:
  49045. flushTextContentItem();
  49046. if (args[0].code) {
  49047. break;
  49048. }
  49049. if (!xobjs) {
  49050. xobjs = resources.get('XObject') || Dict.empty;
  49051. }
  49052. var name = args[0].name;
  49053. if (xobjsCache.key === name) {
  49054. if (xobjsCache.texts) {
  49055. Util.appendToArray(textContent.items, xobjsCache.texts.items);
  49056. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  49057. }
  49058. break;
  49059. }
  49060. var xobj = xobjs.get(name);
  49061. if (!xobj) {
  49062. break;
  49063. }
  49064. assert(isStream(xobj), 'XObject should be a stream');
  49065. var type = xobj.dict.get('Subtype');
  49066. assert(isName(type), 'XObject should have a Name subtype');
  49067. if ('Form' !== type.name) {
  49068. xobjsCache.key = name;
  49069. xobjsCache.texts = null;
  49070. break;
  49071. }
  49072. stateManager.save();
  49073. var matrix = xobj.dict.getArray('Matrix');
  49074. if (isArray(matrix) && matrix.length === 6) {
  49075. stateManager.transform(matrix);
  49076. }
  49077. next(self.getTextContent(xobj, task, xobj.dict.get('Resources') || resources, stateManager, normalizeWhitespace, combineTextItems).then(function (formTextContent) {
  49078. Util.appendToArray(textContent.items, formTextContent.items);
  49079. Util.extendObj(textContent.styles, formTextContent.styles);
  49080. stateManager.restore();
  49081. xobjsCache.key = name;
  49082. xobjsCache.texts = formTextContent;
  49083. }));
  49084. return;
  49085. case OPS.setGState:
  49086. flushTextContentItem();
  49087. var dictName = args[0];
  49088. var extGState = resources.get('ExtGState');
  49089. if (!isDict(extGState) || !isName(dictName)) {
  49090. break;
  49091. }
  49092. var gState = extGState.get(dictName.name);
  49093. if (!isDict(gState)) {
  49094. break;
  49095. }
  49096. var gStateFont = gState.get('Font');
  49097. if (gStateFont) {
  49098. textState.fontName = null;
  49099. textState.fontSize = gStateFont[1];
  49100. next(handleSetFont(null, gStateFont[0]));
  49101. return;
  49102. }
  49103. break;
  49104. }
  49105. }
  49106. // switch
  49107. // while
  49108. if (stop) {
  49109. next(deferred);
  49110. return;
  49111. }
  49112. flushTextContentItem();
  49113. resolve(textContent);
  49114. });
  49115. },
  49116. extractDataStructures: function PartialEvaluator_extractDataStructures(dict, baseDict, xref, properties) {
  49117. // 9.10.2
  49118. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  49119. var toUnicodePromise = toUnicode ? this.readToUnicode(toUnicode) : Promise.resolve(undefined);
  49120. if (properties.composite) {
  49121. // CIDSystemInfo helps to match CID to glyphs
  49122. var cidSystemInfo = dict.get('CIDSystemInfo');
  49123. if (isDict(cidSystemInfo)) {
  49124. properties.cidSystemInfo = {
  49125. registry: cidSystemInfo.get('Registry'),
  49126. ordering: cidSystemInfo.get('Ordering'),
  49127. supplement: cidSystemInfo.get('Supplement')
  49128. };
  49129. }
  49130. var cidToGidMap = dict.get('CIDToGIDMap');
  49131. if (isStream(cidToGidMap)) {
  49132. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  49133. }
  49134. }
  49135. // Based on 9.6.6 of the spec the encoding can come from multiple places
  49136. // and depends on the font type. The base encoding and differences are
  49137. // read here, but the encoding that is actually used is chosen during
  49138. // glyph mapping in the font.
  49139. // TODO: Loading the built in encoding in the font would allow the
  49140. // differences to be merged in here not require us to hold on to it.
  49141. var differences = [];
  49142. var baseEncodingName = null;
  49143. var encoding;
  49144. if (dict.has('Encoding')) {
  49145. encoding = dict.get('Encoding');
  49146. if (isDict(encoding)) {
  49147. baseEncodingName = encoding.get('BaseEncoding');
  49148. baseEncodingName = isName(baseEncodingName) ? baseEncodingName.name : null;
  49149. // Load the differences between the base and original
  49150. if (encoding.has('Differences')) {
  49151. var diffEncoding = encoding.get('Differences');
  49152. var index = 0;
  49153. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  49154. var data = xref.fetchIfRef(diffEncoding[j]);
  49155. if (isNum(data)) {
  49156. index = data;
  49157. } else if (isName(data)) {
  49158. differences[index++] = data.name;
  49159. } else {
  49160. error('Invalid entry in \'Differences\' array: ' + data);
  49161. }
  49162. }
  49163. }
  49164. } else if (isName(encoding)) {
  49165. baseEncodingName = encoding.name;
  49166. } else {
  49167. error('Encoding is not a Name nor a Dict');
  49168. }
  49169. // According to table 114 if the encoding is a named encoding it must be
  49170. // one of these predefined encodings.
  49171. if (baseEncodingName !== 'MacRomanEncoding' && baseEncodingName !== 'MacExpertEncoding' && baseEncodingName !== 'WinAnsiEncoding') {
  49172. baseEncodingName = null;
  49173. }
  49174. }
  49175. if (baseEncodingName) {
  49176. properties.defaultEncoding = getEncoding(baseEncodingName).slice();
  49177. } else {
  49178. encoding = properties.type === 'TrueType' ? WinAnsiEncoding : StandardEncoding;
  49179. // The Symbolic attribute can be misused for regular fonts
  49180. // Heuristic: we have to check if the font is a standard one also
  49181. if (!!(properties.flags & FontFlags.Symbolic)) {
  49182. encoding = MacRomanEncoding;
  49183. if (!properties.file) {
  49184. if (/Symbol/i.test(properties.name)) {
  49185. encoding = SymbolSetEncoding;
  49186. } else if (/Dingbats/i.test(properties.name)) {
  49187. encoding = ZapfDingbatsEncoding;
  49188. }
  49189. }
  49190. }
  49191. properties.defaultEncoding = encoding;
  49192. }
  49193. properties.differences = differences;
  49194. properties.baseEncodingName = baseEncodingName;
  49195. properties.hasEncoding = !!baseEncodingName || differences.length > 0;
  49196. properties.dict = dict;
  49197. return toUnicodePromise.then(function (toUnicode) {
  49198. properties.toUnicode = toUnicode;
  49199. return this.buildToUnicode(properties);
  49200. }.bind(this)).then(function (toUnicode) {
  49201. properties.toUnicode = toUnicode;
  49202. return properties;
  49203. });
  49204. },
  49205. /**
  49206. * Builds a char code to unicode map based on section 9.10 of the spec.
  49207. * @param {Object} properties Font properties object.
  49208. * @return {Promise} A Promise that is resolved with a
  49209. * {ToUnicodeMap|IdentityToUnicodeMap} object.
  49210. */
  49211. buildToUnicode: function PartialEvaluator_buildToUnicode(properties) {
  49212. properties.hasIncludedToUnicodeMap = !!properties.toUnicode && properties.toUnicode.length > 0;
  49213. // Section 9.10.2 Mapping Character Codes to Unicode Values
  49214. if (properties.hasIncludedToUnicodeMap) {
  49215. return Promise.resolve(properties.toUnicode);
  49216. }
  49217. // According to the spec if the font is a simple font we should only map
  49218. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  49219. // the differences array only contains adobe standard or symbol set names,
  49220. // in pratice it seems better to always try to create a toUnicode
  49221. // map based of the default encoding.
  49222. var toUnicode, charcode, glyphName;
  49223. if (!properties.composite)
  49224. /* is simple font */
  49225. {
  49226. toUnicode = [];
  49227. var encoding = properties.defaultEncoding.slice();
  49228. var baseEncodingName = properties.baseEncodingName;
  49229. // Merge in the differences array.
  49230. var differences = properties.differences;
  49231. for (charcode in differences) {
  49232. glyphName = differences[charcode];
  49233. if (glyphName === '.notdef') {
  49234. // Skip .notdef to prevent rendering errors, e.g. boxes appearing
  49235. // where there should be spaces (fixes issue5256.pdf).
  49236. continue;
  49237. }
  49238. encoding[charcode] = glyphName;
  49239. }
  49240. var glyphsUnicodeMap = getGlyphsUnicode();
  49241. for (charcode in encoding) {
  49242. // a) Map the character code to a character name.
  49243. glyphName = encoding[charcode];
  49244. // b) Look up the character name in the Adobe Glyph List (see the
  49245. // Bibliography) to obtain the corresponding Unicode value.
  49246. if (glyphName === '') {
  49247. continue;
  49248. } else if (glyphsUnicodeMap[glyphName] === undefined) {
  49249. // (undocumented) c) Few heuristics to recognize unknown glyphs
  49250. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  49251. var code = 0;
  49252. switch (glyphName[0]) {
  49253. case 'G':
  49254. // Gxx glyph
  49255. if (glyphName.length === 3) {
  49256. code = parseInt(glyphName.substr(1), 16);
  49257. }
  49258. break;
  49259. case 'g':
  49260. // g00xx glyph
  49261. if (glyphName.length === 5) {
  49262. code = parseInt(glyphName.substr(1), 16);
  49263. }
  49264. break;
  49265. case 'C':
  49266. // Cddd glyph
  49267. case 'c':
  49268. // cddd glyph
  49269. if (glyphName.length >= 3) {
  49270. code = +glyphName.substr(1);
  49271. }
  49272. break;
  49273. default:
  49274. // 'uniXXXX'/'uXXXX{XX}' glyphs
  49275. var unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  49276. if (unicode !== -1) {
  49277. code = unicode;
  49278. }
  49279. }
  49280. if (code) {
  49281. // If |baseEncodingName| is one the predefined encodings,
  49282. // and |code| equals |charcode|, using the glyph defined in the
  49283. // baseEncoding seems to yield a better |toUnicode| mapping
  49284. // (fixes issue 5070).
  49285. if (baseEncodingName && code === +charcode) {
  49286. var baseEncoding = getEncoding(baseEncodingName);
  49287. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  49288. toUnicode[charcode] = String.fromCharCode(glyphsUnicodeMap[glyphName]);
  49289. continue;
  49290. }
  49291. }
  49292. toUnicode[charcode] = String.fromCharCode(code);
  49293. }
  49294. continue;
  49295. }
  49296. toUnicode[charcode] = String.fromCharCode(glyphsUnicodeMap[glyphName]);
  49297. }
  49298. return Promise.resolve(new ToUnicodeMap(toUnicode));
  49299. }
  49300. // If the font is a composite font that uses one of the predefined CMaps
  49301. // listed in Table 118 (except Identity–H and Identity–V) or whose
  49302. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  49303. // Adobe-Korea1 character collection:
  49304. 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'))) {
  49305. // Then:
  49306. // a) Map the character code to a character identifier (CID) according
  49307. // to the font’s CMap.
  49308. // b) Obtain the registry and ordering of the character collection used
  49309. // by the font’s CMap (for example, Adobe and Japan1) from its
  49310. // CIDSystemInfo dictionary.
  49311. var registry = properties.cidSystemInfo.registry;
  49312. var ordering = properties.cidSystemInfo.ordering;
  49313. // c) Construct a second CMap name by concatenating the registry and
  49314. // ordering obtained in step (b) in the format registry–ordering–UCS2
  49315. // (for example, Adobe–Japan1–UCS2).
  49316. var ucs2CMapName = Name.get(registry + '-' + ordering + '-UCS2');
  49317. // d) Obtain the CMap with the name constructed in step (c) (available
  49318. // from the ASN Web site; see the Bibliography).
  49319. return CMapFactory.create(ucs2CMapName, this.options.cMapOptions, null).then(function (ucs2CMap) {
  49320. var cMap = properties.cMap;
  49321. toUnicode = [];
  49322. cMap.forEach(function (charcode, cid) {
  49323. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  49324. // e) Map the CID obtained in step (a) according to the CMap
  49325. // obtained in step (d), producing a Unicode value.
  49326. var ucs2 = ucs2CMap.lookup(cid);
  49327. if (ucs2) {
  49328. toUnicode[charcode] = String.fromCharCode((ucs2.charCodeAt(0) << 8) + ucs2.charCodeAt(1));
  49329. }
  49330. });
  49331. return new ToUnicodeMap(toUnicode);
  49332. });
  49333. }
  49334. // The viewer's choice, just use an identity map.
  49335. return Promise.resolve(new IdentityToUnicodeMap(properties.firstChar, properties.lastChar));
  49336. },
  49337. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  49338. var cmapObj = toUnicode;
  49339. if (isName(cmapObj)) {
  49340. return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(function (cmap) {
  49341. if (cmap instanceof IdentityCMap) {
  49342. return new IdentityToUnicodeMap(0, 0xFFFF);
  49343. }
  49344. return new ToUnicodeMap(cmap.getMap());
  49345. });
  49346. } else if (isStream(cmapObj)) {
  49347. return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(function (cmap) {
  49348. if (cmap instanceof IdentityCMap) {
  49349. return new IdentityToUnicodeMap(0, 0xFFFF);
  49350. }
  49351. var map = new Array(cmap.length);
  49352. // Convert UTF-16BE
  49353. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  49354. // to iterate over all keys.
  49355. cmap.forEach(function (charCode, token) {
  49356. var str = [];
  49357. for (var k = 0; k < token.length; k += 2) {
  49358. var w1 = token.charCodeAt(k) << 8 | token.charCodeAt(k + 1);
  49359. if ((w1 & 0xF800) !== 0xD800) {
  49360. // w1 < 0xD800 || w1 > 0xDFFF
  49361. str.push(w1);
  49362. continue;
  49363. }
  49364. k += 2;
  49365. var w2 = token.charCodeAt(k) << 8 | token.charCodeAt(k + 1);
  49366. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  49367. }
  49368. map[charCode] = String.fromCharCode.apply(String, str);
  49369. });
  49370. return new ToUnicodeMap(map);
  49371. });
  49372. }
  49373. return Promise.resolve(null);
  49374. },
  49375. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  49376. // Extract the encoding from the CIDToGIDMap
  49377. var glyphsData = cidToGidStream.getBytes();
  49378. // Set encoding 0 to later verify the font has an encoding
  49379. var result = [];
  49380. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  49381. var glyphID = glyphsData[j++] << 8 | glyphsData[j];
  49382. if (glyphID === 0) {
  49383. continue;
  49384. }
  49385. var code = j >> 1;
  49386. result[code] = glyphID;
  49387. }
  49388. return result;
  49389. },
  49390. extractWidths: function PartialEvaluator_extractWidths(dict, xref, descriptor, properties) {
  49391. var glyphsWidths = [];
  49392. var defaultWidth = 0;
  49393. var glyphsVMetrics = [];
  49394. var defaultVMetrics;
  49395. var i, ii, j, jj, start, code, widths;
  49396. if (properties.composite) {
  49397. defaultWidth = dict.get('DW') || 1000;
  49398. widths = dict.get('W');
  49399. if (widths) {
  49400. for (i = 0, ii = widths.length; i < ii; i++) {
  49401. start = widths[i++];
  49402. code = xref.fetchIfRef(widths[i]);
  49403. if (isArray(code)) {
  49404. for (j = 0, jj = code.length; j < jj; j++) {
  49405. glyphsWidths[start++] = code[j];
  49406. }
  49407. } else {
  49408. var width = widths[++i];
  49409. for (j = start; j <= code; j++) {
  49410. glyphsWidths[j] = width;
  49411. }
  49412. }
  49413. }
  49414. }
  49415. if (properties.vertical) {
  49416. var vmetrics = dict.get('DW2') || [
  49417. 880,
  49418. -1000
  49419. ];
  49420. defaultVMetrics = [
  49421. vmetrics[1],
  49422. defaultWidth * 0.5,
  49423. vmetrics[0]
  49424. ];
  49425. vmetrics = dict.get('W2');
  49426. if (vmetrics) {
  49427. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  49428. start = vmetrics[i++];
  49429. code = xref.fetchIfRef(vmetrics[i]);
  49430. if (isArray(code)) {
  49431. for (j = 0, jj = code.length; j < jj; j++) {
  49432. glyphsVMetrics[start++] = [
  49433. code[j++],
  49434. code[j++],
  49435. code[j]
  49436. ];
  49437. }
  49438. } else {
  49439. var vmetric = [
  49440. vmetrics[++i],
  49441. vmetrics[++i],
  49442. vmetrics[++i]
  49443. ];
  49444. for (j = start; j <= code; j++) {
  49445. glyphsVMetrics[j] = vmetric;
  49446. }
  49447. }
  49448. }
  49449. }
  49450. }
  49451. } else {
  49452. var firstChar = properties.firstChar;
  49453. widths = dict.get('Widths');
  49454. if (widths) {
  49455. j = firstChar;
  49456. for (i = 0, ii = widths.length; i < ii; i++) {
  49457. glyphsWidths[j++] = widths[i];
  49458. }
  49459. defaultWidth = parseFloat(descriptor.get('MissingWidth')) || 0;
  49460. } else {
  49461. // Trying get the BaseFont metrics (see comment above).
  49462. var baseFontName = dict.get('BaseFont');
  49463. if (isName(baseFontName)) {
  49464. var metrics = this.getBaseFontMetrics(baseFontName.name);
  49465. glyphsWidths = this.buildCharCodeToWidth(metrics.widths, properties);
  49466. defaultWidth = metrics.defaultWidth;
  49467. }
  49468. }
  49469. }
  49470. // Heuristic: detection of monospace font by checking all non-zero widths
  49471. var isMonospace = true;
  49472. var firstWidth = defaultWidth;
  49473. for (var glyph in glyphsWidths) {
  49474. var glyphWidth = glyphsWidths[glyph];
  49475. if (!glyphWidth) {
  49476. continue;
  49477. }
  49478. if (!firstWidth) {
  49479. firstWidth = glyphWidth;
  49480. continue;
  49481. }
  49482. if (firstWidth !== glyphWidth) {
  49483. isMonospace = false;
  49484. break;
  49485. }
  49486. }
  49487. if (isMonospace) {
  49488. properties.flags |= FontFlags.FixedPitch;
  49489. }
  49490. properties.defaultWidth = defaultWidth;
  49491. properties.widths = glyphsWidths;
  49492. properties.defaultVMetrics = defaultVMetrics;
  49493. properties.vmetrics = glyphsVMetrics;
  49494. },
  49495. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  49496. // Simulating descriptor flags attribute
  49497. var fontNameWoStyle = baseFontName.split('-')[0];
  49498. return fontNameWoStyle in getSerifFonts() || fontNameWoStyle.search(/serif/gi) !== -1;
  49499. },
  49500. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  49501. var defaultWidth = 0;
  49502. var widths = [];
  49503. var monospace = false;
  49504. var stdFontMap = getStdFontMap();
  49505. var lookupName = stdFontMap[name] || name;
  49506. var Metrics = getMetrics();
  49507. if (!(lookupName in Metrics)) {
  49508. // Use default fonts for looking up font metrics if the passed
  49509. // font is not a base font
  49510. if (this.isSerifFont(name)) {
  49511. lookupName = 'Times-Roman';
  49512. } else {
  49513. lookupName = 'Helvetica';
  49514. }
  49515. }
  49516. var glyphWidths = Metrics[lookupName];
  49517. if (isNum(glyphWidths)) {
  49518. defaultWidth = glyphWidths;
  49519. monospace = true;
  49520. } else {
  49521. widths = glyphWidths();
  49522. }
  49523. // expand lazy widths array
  49524. return {
  49525. defaultWidth: defaultWidth,
  49526. monospace: monospace,
  49527. widths: widths
  49528. };
  49529. },
  49530. buildCharCodeToWidth: function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName, properties) {
  49531. var widths = Object.create(null);
  49532. var differences = properties.differences;
  49533. var encoding = properties.defaultEncoding;
  49534. for (var charCode = 0; charCode < 256; charCode++) {
  49535. if (charCode in differences && widthsByGlyphName[differences[charCode]]) {
  49536. widths[charCode] = widthsByGlyphName[differences[charCode]];
  49537. continue;
  49538. }
  49539. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  49540. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  49541. continue;
  49542. }
  49543. }
  49544. return widths;
  49545. },
  49546. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  49547. var baseDict = dict;
  49548. var type = dict.get('Subtype');
  49549. assert(isName(type), 'invalid font Subtype');
  49550. var composite = false;
  49551. var uint8array;
  49552. if (type.name === 'Type0') {
  49553. // If font is a composite
  49554. // - get the descendant font
  49555. // - set the type according to the descendant font
  49556. // - get the FontDescriptor from the descendant font
  49557. var df = dict.get('DescendantFonts');
  49558. if (!df) {
  49559. error('Descendant fonts are not specified');
  49560. }
  49561. dict = isArray(df) ? xref.fetchIfRef(df[0]) : df;
  49562. type = dict.get('Subtype');
  49563. assert(isName(type), 'invalid font Subtype');
  49564. composite = true;
  49565. }
  49566. var descriptor = dict.get('FontDescriptor');
  49567. if (descriptor) {
  49568. var hash = new MurmurHash3_64();
  49569. var encoding = baseDict.getRaw('Encoding');
  49570. if (isName(encoding)) {
  49571. hash.update(encoding.name);
  49572. } else if (isRef(encoding)) {
  49573. hash.update(encoding.toString());
  49574. } else if (isDict(encoding)) {
  49575. var keys = encoding.getKeys();
  49576. for (var i = 0, ii = keys.length; i < ii; i++) {
  49577. var entry = encoding.getRaw(keys[i]);
  49578. if (isName(entry)) {
  49579. hash.update(entry.name);
  49580. } else if (isRef(entry)) {
  49581. hash.update(entry.toString());
  49582. } else if (isArray(entry)) {
  49583. // 'Differences' entry.
  49584. // Ideally we should check the contents of the array, but to avoid
  49585. // parsing it here and then again in |extractDataStructures|,
  49586. // we only use the array length for now (fixes bug1157493.pdf).
  49587. hash.update(entry.length.toString());
  49588. }
  49589. }
  49590. }
  49591. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  49592. if (isStream(toUnicode)) {
  49593. var stream = toUnicode.str || toUnicode;
  49594. uint8array = stream.buffer ? new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) : new Uint8Array(stream.bytes.buffer, stream.start, stream.end - stream.start);
  49595. hash.update(uint8array);
  49596. } else if (isName(toUnicode)) {
  49597. hash.update(toUnicode.name);
  49598. }
  49599. var widths = dict.get('Widths') || baseDict.get('Widths');
  49600. if (widths) {
  49601. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  49602. hash.update(uint8array);
  49603. }
  49604. }
  49605. return {
  49606. descriptor: descriptor,
  49607. dict: dict,
  49608. baseDict: baseDict,
  49609. composite: composite,
  49610. type: type.name,
  49611. hash: hash ? hash.hexdigest() : ''
  49612. };
  49613. },
  49614. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont, xref) {
  49615. var baseDict = preEvaluatedFont.baseDict;
  49616. var dict = preEvaluatedFont.dict;
  49617. var composite = preEvaluatedFont.composite;
  49618. var descriptor = preEvaluatedFont.descriptor;
  49619. var type = preEvaluatedFont.type;
  49620. var maxCharIndex = composite ? 0xFFFF : 0xFF;
  49621. var cMapOptions = this.options.cMapOptions;
  49622. var properties;
  49623. if (!descriptor) {
  49624. if (type === 'Type3') {
  49625. // FontDescriptor is only required for Type3 fonts when the document
  49626. // is a tagged pdf. Create a barbebones one to get by.
  49627. descriptor = new Dict(null);
  49628. descriptor.set('FontName', Name.get(type));
  49629. descriptor.set('FontBBox', dict.getArray('FontBBox'));
  49630. } else {
  49631. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  49632. // FontDescriptor was not required.
  49633. // This case is here for compatibility.
  49634. var baseFontName = dict.get('BaseFont');
  49635. if (!isName(baseFontName)) {
  49636. error('Base font is not specified');
  49637. }
  49638. // Using base font name as a font name.
  49639. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  49640. var metrics = this.getBaseFontMetrics(baseFontName);
  49641. // Simulating descriptor flags attribute
  49642. var fontNameWoStyle = baseFontName.split('-')[0];
  49643. var flags = (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) | (metrics.monospace ? FontFlags.FixedPitch : 0) | (getSymbolsFonts()[fontNameWoStyle] ? FontFlags.Symbolic : FontFlags.Nonsymbolic);
  49644. properties = {
  49645. type: type,
  49646. name: baseFontName,
  49647. widths: metrics.widths,
  49648. defaultWidth: metrics.defaultWidth,
  49649. flags: flags,
  49650. firstChar: 0,
  49651. lastChar: maxCharIndex
  49652. };
  49653. return this.extractDataStructures(dict, dict, xref, properties).then(function (properties) {
  49654. properties.widths = this.buildCharCodeToWidth(metrics.widths, properties);
  49655. return new Font(baseFontName, null, properties);
  49656. }.bind(this));
  49657. }
  49658. }
  49659. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  49660. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  49661. // to ignore this rule when a variant of a standard font is used.
  49662. // TODO Fill the width array depending on which of the base font this is
  49663. // a variant.
  49664. var firstChar = dict.get('FirstChar') || 0;
  49665. var lastChar = dict.get('LastChar') || maxCharIndex;
  49666. var fontName = descriptor.get('FontName');
  49667. var baseFont = dict.get('BaseFont');
  49668. // Some bad PDFs have a string as the font name.
  49669. if (isString(fontName)) {
  49670. fontName = Name.get(fontName);
  49671. }
  49672. if (isString(baseFont)) {
  49673. baseFont = Name.get(baseFont);
  49674. }
  49675. if (type !== 'Type3') {
  49676. var fontNameStr = fontName && fontName.name;
  49677. var baseFontStr = baseFont && baseFont.name;
  49678. if (fontNameStr !== baseFontStr) {
  49679. info('The FontDescriptor\'s FontName is "' + fontNameStr + '" but should be the same as the Font\'s BaseFont "' + baseFontStr + '"');
  49680. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  49681. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  49682. if (fontNameStr && baseFontStr && baseFontStr.indexOf(fontNameStr) === 0) {
  49683. fontName = baseFont;
  49684. }
  49685. }
  49686. }
  49687. fontName = fontName || baseFont;
  49688. assert(isName(fontName), 'invalid font name');
  49689. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  49690. if (fontFile) {
  49691. if (fontFile.dict) {
  49692. var subtype = fontFile.dict.get('Subtype');
  49693. if (subtype) {
  49694. subtype = subtype.name;
  49695. }
  49696. var length1 = fontFile.dict.get('Length1');
  49697. var length2 = fontFile.dict.get('Length2');
  49698. var length3 = fontFile.dict.get('Length3');
  49699. }
  49700. }
  49701. properties = {
  49702. type: type,
  49703. name: fontName.name,
  49704. subtype: subtype,
  49705. file: fontFile,
  49706. length1: length1,
  49707. length2: length2,
  49708. length3: length3,
  49709. loadedName: baseDict.loadedName,
  49710. composite: composite,
  49711. wideChars: composite,
  49712. fixedPitch: false,
  49713. fontMatrix: dict.getArray('FontMatrix') || FONT_IDENTITY_MATRIX,
  49714. firstChar: firstChar || 0,
  49715. lastChar: lastChar || maxCharIndex,
  49716. bbox: descriptor.getArray('FontBBox'),
  49717. ascent: descriptor.get('Ascent'),
  49718. descent: descriptor.get('Descent'),
  49719. xHeight: descriptor.get('XHeight'),
  49720. capHeight: descriptor.get('CapHeight'),
  49721. flags: descriptor.get('Flags'),
  49722. italicAngle: descriptor.get('ItalicAngle'),
  49723. coded: false
  49724. };
  49725. var cMapPromise;
  49726. if (composite) {
  49727. var cidEncoding = baseDict.get('Encoding');
  49728. if (isName(cidEncoding)) {
  49729. properties.cidEncoding = cidEncoding.name;
  49730. }
  49731. cMapPromise = CMapFactory.create(cidEncoding, cMapOptions, null).then(function (cMap) {
  49732. properties.cMap = cMap;
  49733. properties.vertical = properties.cMap.vertical;
  49734. });
  49735. } else {
  49736. cMapPromise = Promise.resolve(undefined);
  49737. }
  49738. return cMapPromise.then(function () {
  49739. return this.extractDataStructures(dict, baseDict, xref, properties);
  49740. }.bind(this)).then(function (properties) {
  49741. this.extractWidths(dict, xref, descriptor, properties);
  49742. if (type === 'Type3') {
  49743. properties.isType3Font = true;
  49744. }
  49745. return new Font(fontName.name, fontFile, properties);
  49746. }.bind(this));
  49747. }
  49748. };
  49749. return PartialEvaluator;
  49750. }();
  49751. var TranslatedFont = function TranslatedFontClosure() {
  49752. function TranslatedFont(loadedName, font, dict) {
  49753. this.loadedName = loadedName;
  49754. this.font = font;
  49755. this.dict = dict;
  49756. this.type3Loaded = null;
  49757. this.sent = false;
  49758. }
  49759. TranslatedFont.prototype = {
  49760. send: function (handler) {
  49761. if (this.sent) {
  49762. return;
  49763. }
  49764. var fontData = this.font.exportData();
  49765. handler.send('commonobj', [
  49766. this.loadedName,
  49767. 'Font',
  49768. fontData
  49769. ]);
  49770. this.sent = true;
  49771. },
  49772. loadType3Data: function (evaluator, resources, parentOperatorList, task) {
  49773. assert(this.font.isType3Font);
  49774. if (this.type3Loaded) {
  49775. return this.type3Loaded;
  49776. }
  49777. var translatedFont = this.font;
  49778. var loadCharProcsPromise = Promise.resolve();
  49779. var charProcs = this.dict.get('CharProcs');
  49780. var fontResources = this.dict.get('Resources') || resources;
  49781. var charProcKeys = charProcs.getKeys();
  49782. var charProcOperatorList = Object.create(null);
  49783. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  49784. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  49785. var glyphStream = charProcs.get(key);
  49786. var operatorList = new OperatorList();
  49787. return evaluator.getOperatorList(glyphStream, task, fontResources, operatorList).then(function () {
  49788. charProcOperatorList[key] = operatorList.getIR();
  49789. // Add the dependencies to the parent operator list so they are
  49790. // resolved before sub operator list is executed synchronously.
  49791. parentOperatorList.addDependencies(operatorList.dependencies);
  49792. }, function (reason) {
  49793. warn('Type3 font resource \"' + key + '\" is not available');
  49794. var operatorList = new OperatorList();
  49795. charProcOperatorList[key] = operatorList.getIR();
  49796. });
  49797. }.bind(this, charProcKeys[i]));
  49798. }
  49799. this.type3Loaded = loadCharProcsPromise.then(function () {
  49800. translatedFont.charProcOperatorList = charProcOperatorList;
  49801. });
  49802. return this.type3Loaded;
  49803. }
  49804. };
  49805. return TranslatedFont;
  49806. }();
  49807. var OperatorList = function OperatorListClosure() {
  49808. var CHUNK_SIZE = 1000;
  49809. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5;
  49810. // close to chunk size
  49811. function getTransfers(queue) {
  49812. var transfers = [];
  49813. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  49814. for (var i = 0, ii = queue.length; i < ii; i++) {
  49815. switch (fnArray[i]) {
  49816. case OPS.paintInlineImageXObject:
  49817. case OPS.paintInlineImageXObjectGroup:
  49818. case OPS.paintImageMaskXObject:
  49819. var arg = argsArray[i][0];
  49820. // first param in imgData
  49821. if (!arg.cached) {
  49822. transfers.push(arg.data.buffer);
  49823. }
  49824. break;
  49825. }
  49826. }
  49827. return transfers;
  49828. }
  49829. function OperatorList(intent, messageHandler, pageIndex) {
  49830. this.messageHandler = messageHandler;
  49831. this.fnArray = [];
  49832. this.argsArray = [];
  49833. this.dependencies = Object.create(null);
  49834. this._totalLength = 0;
  49835. this.pageIndex = pageIndex;
  49836. this.intent = intent;
  49837. }
  49838. OperatorList.prototype = {
  49839. get length() {
  49840. return this.argsArray.length;
  49841. },
  49842. /**
  49843. * @returns {number} The total length of the entire operator list,
  49844. * since `this.length === 0` after flushing.
  49845. */
  49846. get totalLength() {
  49847. return this._totalLength + this.length;
  49848. },
  49849. addOp: function (fn, args) {
  49850. this.fnArray.push(fn);
  49851. this.argsArray.push(args);
  49852. if (this.messageHandler) {
  49853. if (this.fnArray.length >= CHUNK_SIZE) {
  49854. this.flush();
  49855. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT && (fn === OPS.restore || fn === OPS.endText)) {
  49856. // heuristic to flush on boundary of restore or endText
  49857. this.flush();
  49858. }
  49859. }
  49860. },
  49861. addDependency: function (dependency) {
  49862. if (dependency in this.dependencies) {
  49863. return;
  49864. }
  49865. this.dependencies[dependency] = true;
  49866. this.addOp(OPS.dependency, [dependency]);
  49867. },
  49868. addDependencies: function (dependencies) {
  49869. for (var key in dependencies) {
  49870. this.addDependency(key);
  49871. }
  49872. },
  49873. addOpList: function (opList) {
  49874. Util.extendObj(this.dependencies, opList.dependencies);
  49875. for (var i = 0, ii = opList.length; i < ii; i++) {
  49876. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  49877. }
  49878. },
  49879. getIR: function () {
  49880. return {
  49881. fnArray: this.fnArray,
  49882. argsArray: this.argsArray,
  49883. length: this.length
  49884. };
  49885. },
  49886. flush: function (lastChunk) {
  49887. if (this.intent !== 'oplist') {
  49888. new QueueOptimizer().optimize(this);
  49889. }
  49890. var transfers = getTransfers(this);
  49891. var length = this.length;
  49892. this._totalLength += length;
  49893. this.messageHandler.send('RenderPageChunk', {
  49894. operatorList: {
  49895. fnArray: this.fnArray,
  49896. argsArray: this.argsArray,
  49897. lastChunk: lastChunk,
  49898. length: length
  49899. },
  49900. pageIndex: this.pageIndex,
  49901. intent: this.intent
  49902. }, transfers);
  49903. this.dependencies = Object.create(null);
  49904. this.fnArray.length = 0;
  49905. this.argsArray.length = 0;
  49906. }
  49907. };
  49908. return OperatorList;
  49909. }();
  49910. var StateManager = function StateManagerClosure() {
  49911. function StateManager(initialState) {
  49912. this.state = initialState;
  49913. this.stateStack = [];
  49914. }
  49915. StateManager.prototype = {
  49916. save: function () {
  49917. var old = this.state;
  49918. this.stateStack.push(this.state);
  49919. this.state = old.clone();
  49920. },
  49921. restore: function () {
  49922. var prev = this.stateStack.pop();
  49923. if (prev) {
  49924. this.state = prev;
  49925. }
  49926. },
  49927. transform: function (args) {
  49928. this.state.ctm = Util.transform(this.state.ctm, args);
  49929. }
  49930. };
  49931. return StateManager;
  49932. }();
  49933. var TextState = function TextStateClosure() {
  49934. function TextState() {
  49935. this.ctm = new Float32Array(IDENTITY_MATRIX);
  49936. this.fontName = null;
  49937. this.fontSize = 0;
  49938. this.font = null;
  49939. this.fontMatrix = FONT_IDENTITY_MATRIX;
  49940. this.textMatrix = IDENTITY_MATRIX.slice();
  49941. this.textLineMatrix = IDENTITY_MATRIX.slice();
  49942. this.charSpacing = 0;
  49943. this.wordSpacing = 0;
  49944. this.leading = 0;
  49945. this.textHScale = 1;
  49946. this.textRise = 0;
  49947. }
  49948. TextState.prototype = {
  49949. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  49950. var m = this.textMatrix;
  49951. m[0] = a;
  49952. m[1] = b;
  49953. m[2] = c;
  49954. m[3] = d;
  49955. m[4] = e;
  49956. m[5] = f;
  49957. },
  49958. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  49959. var m = this.textLineMatrix;
  49960. m[0] = a;
  49961. m[1] = b;
  49962. m[2] = c;
  49963. m[3] = d;
  49964. m[4] = e;
  49965. m[5] = f;
  49966. },
  49967. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  49968. var m = this.textMatrix;
  49969. m[4] = m[0] * x + m[2] * y + m[4];
  49970. m[5] = m[1] * x + m[3] * y + m[5];
  49971. },
  49972. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  49973. var m = this.textLineMatrix;
  49974. m[4] = m[0] * x + m[2] * y + m[4];
  49975. m[5] = m[1] * x + m[3] * y + m[5];
  49976. },
  49977. calcTextLineMatrixAdvance: function TextState_calcTextLineMatrixAdvance(a, b, c, d, e, f) {
  49978. var font = this.font;
  49979. if (!font) {
  49980. return null;
  49981. }
  49982. var m = this.textLineMatrix;
  49983. if (!(a === m[0] && b === m[1] && c === m[2] && d === m[3])) {
  49984. return null;
  49985. }
  49986. var txDiff = e - m[4], tyDiff = f - m[5];
  49987. if (font.vertical && txDiff !== 0 || !font.vertical && tyDiff !== 0) {
  49988. return null;
  49989. }
  49990. var tx, ty, denominator = a * d - b * c;
  49991. if (font.vertical) {
  49992. tx = -tyDiff * c / denominator;
  49993. ty = tyDiff * a / denominator;
  49994. } else {
  49995. tx = txDiff * d / denominator;
  49996. ty = -txDiff * b / denominator;
  49997. }
  49998. return {
  49999. width: tx,
  50000. height: ty,
  50001. value: font.vertical ? ty : tx
  50002. };
  50003. },
  50004. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  50005. // 9.4.4 Text Space Details
  50006. var tsm = [
  50007. this.fontSize * this.textHScale,
  50008. 0,
  50009. 0,
  50010. this.fontSize,
  50011. 0,
  50012. this.textRise
  50013. ];
  50014. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  50015. },
  50016. carriageReturn: function TextState_carriageReturn() {
  50017. this.translateTextLineMatrix(0, -this.leading);
  50018. this.textMatrix = this.textLineMatrix.slice();
  50019. },
  50020. clone: function TextState_clone() {
  50021. var clone = Object.create(this);
  50022. clone.textMatrix = this.textMatrix.slice();
  50023. clone.textLineMatrix = this.textLineMatrix.slice();
  50024. clone.fontMatrix = this.fontMatrix.slice();
  50025. return clone;
  50026. }
  50027. };
  50028. return TextState;
  50029. }();
  50030. var EvalState = function EvalStateClosure() {
  50031. function EvalState() {
  50032. this.ctm = new Float32Array(IDENTITY_MATRIX);
  50033. this.font = null;
  50034. this.textRenderingMode = TextRenderingMode.FILL;
  50035. this.fillColorSpace = ColorSpace.singletons.gray;
  50036. this.strokeColorSpace = ColorSpace.singletons.gray;
  50037. }
  50038. EvalState.prototype = {
  50039. clone: function CanvasExtraState_clone() {
  50040. return Object.create(this);
  50041. }
  50042. };
  50043. return EvalState;
  50044. }();
  50045. var EvaluatorPreprocessor = function EvaluatorPreprocessorClosure() {
  50046. // Specifies properties for each command
  50047. //
  50048. // If variableArgs === true: [0, `numArgs`] expected
  50049. // If variableArgs === false: exactly `numArgs` expected
  50050. var getOPMap = getLookupTableFactory(function (t) {
  50051. // Graphic state
  50052. t['w'] = {
  50053. id: OPS.setLineWidth,
  50054. numArgs: 1,
  50055. variableArgs: false
  50056. };
  50057. t['J'] = {
  50058. id: OPS.setLineCap,
  50059. numArgs: 1,
  50060. variableArgs: false
  50061. };
  50062. t['j'] = {
  50063. id: OPS.setLineJoin,
  50064. numArgs: 1,
  50065. variableArgs: false
  50066. };
  50067. t['M'] = {
  50068. id: OPS.setMiterLimit,
  50069. numArgs: 1,
  50070. variableArgs: false
  50071. };
  50072. t['d'] = {
  50073. id: OPS.setDash,
  50074. numArgs: 2,
  50075. variableArgs: false
  50076. };
  50077. t['ri'] = {
  50078. id: OPS.setRenderingIntent,
  50079. numArgs: 1,
  50080. variableArgs: false
  50081. };
  50082. t['i'] = {
  50083. id: OPS.setFlatness,
  50084. numArgs: 1,
  50085. variableArgs: false
  50086. };
  50087. t['gs'] = {
  50088. id: OPS.setGState,
  50089. numArgs: 1,
  50090. variableArgs: false
  50091. };
  50092. t['q'] = {
  50093. id: OPS.save,
  50094. numArgs: 0,
  50095. variableArgs: false
  50096. };
  50097. t['Q'] = {
  50098. id: OPS.restore,
  50099. numArgs: 0,
  50100. variableArgs: false
  50101. };
  50102. t['cm'] = {
  50103. id: OPS.transform,
  50104. numArgs: 6,
  50105. variableArgs: false
  50106. };
  50107. // Path
  50108. t['m'] = {
  50109. id: OPS.moveTo,
  50110. numArgs: 2,
  50111. variableArgs: false
  50112. };
  50113. t['l'] = {
  50114. id: OPS.lineTo,
  50115. numArgs: 2,
  50116. variableArgs: false
  50117. };
  50118. t['c'] = {
  50119. id: OPS.curveTo,
  50120. numArgs: 6,
  50121. variableArgs: false
  50122. };
  50123. t['v'] = {
  50124. id: OPS.curveTo2,
  50125. numArgs: 4,
  50126. variableArgs: false
  50127. };
  50128. t['y'] = {
  50129. id: OPS.curveTo3,
  50130. numArgs: 4,
  50131. variableArgs: false
  50132. };
  50133. t['h'] = {
  50134. id: OPS.closePath,
  50135. numArgs: 0,
  50136. variableArgs: false
  50137. };
  50138. t['re'] = {
  50139. id: OPS.rectangle,
  50140. numArgs: 4,
  50141. variableArgs: false
  50142. };
  50143. t['S'] = {
  50144. id: OPS.stroke,
  50145. numArgs: 0,
  50146. variableArgs: false
  50147. };
  50148. t['s'] = {
  50149. id: OPS.closeStroke,
  50150. numArgs: 0,
  50151. variableArgs: false
  50152. };
  50153. t['f'] = {
  50154. id: OPS.fill,
  50155. numArgs: 0,
  50156. variableArgs: false
  50157. };
  50158. t['F'] = {
  50159. id: OPS.fill,
  50160. numArgs: 0,
  50161. variableArgs: false
  50162. };
  50163. t['f*'] = {
  50164. id: OPS.eoFill,
  50165. numArgs: 0,
  50166. variableArgs: false
  50167. };
  50168. t['B'] = {
  50169. id: OPS.fillStroke,
  50170. numArgs: 0,
  50171. variableArgs: false
  50172. };
  50173. t['B*'] = {
  50174. id: OPS.eoFillStroke,
  50175. numArgs: 0,
  50176. variableArgs: false
  50177. };
  50178. t['b'] = {
  50179. id: OPS.closeFillStroke,
  50180. numArgs: 0,
  50181. variableArgs: false
  50182. };
  50183. t['b*'] = {
  50184. id: OPS.closeEOFillStroke,
  50185. numArgs: 0,
  50186. variableArgs: false
  50187. };
  50188. t['n'] = {
  50189. id: OPS.endPath,
  50190. numArgs: 0,
  50191. variableArgs: false
  50192. };
  50193. // Clipping
  50194. t['W'] = {
  50195. id: OPS.clip,
  50196. numArgs: 0,
  50197. variableArgs: false
  50198. };
  50199. t['W*'] = {
  50200. id: OPS.eoClip,
  50201. numArgs: 0,
  50202. variableArgs: false
  50203. };
  50204. // Text
  50205. t['BT'] = {
  50206. id: OPS.beginText,
  50207. numArgs: 0,
  50208. variableArgs: false
  50209. };
  50210. t['ET'] = {
  50211. id: OPS.endText,
  50212. numArgs: 0,
  50213. variableArgs: false
  50214. };
  50215. t['Tc'] = {
  50216. id: OPS.setCharSpacing,
  50217. numArgs: 1,
  50218. variableArgs: false
  50219. };
  50220. t['Tw'] = {
  50221. id: OPS.setWordSpacing,
  50222. numArgs: 1,
  50223. variableArgs: false
  50224. };
  50225. t['Tz'] = {
  50226. id: OPS.setHScale,
  50227. numArgs: 1,
  50228. variableArgs: false
  50229. };
  50230. t['TL'] = {
  50231. id: OPS.setLeading,
  50232. numArgs: 1,
  50233. variableArgs: false
  50234. };
  50235. t['Tf'] = {
  50236. id: OPS.setFont,
  50237. numArgs: 2,
  50238. variableArgs: false
  50239. };
  50240. t['Tr'] = {
  50241. id: OPS.setTextRenderingMode,
  50242. numArgs: 1,
  50243. variableArgs: false
  50244. };
  50245. t['Ts'] = {
  50246. id: OPS.setTextRise,
  50247. numArgs: 1,
  50248. variableArgs: false
  50249. };
  50250. t['Td'] = {
  50251. id: OPS.moveText,
  50252. numArgs: 2,
  50253. variableArgs: false
  50254. };
  50255. t['TD'] = {
  50256. id: OPS.setLeadingMoveText,
  50257. numArgs: 2,
  50258. variableArgs: false
  50259. };
  50260. t['Tm'] = {
  50261. id: OPS.setTextMatrix,
  50262. numArgs: 6,
  50263. variableArgs: false
  50264. };
  50265. t['T*'] = {
  50266. id: OPS.nextLine,
  50267. numArgs: 0,
  50268. variableArgs: false
  50269. };
  50270. t['Tj'] = {
  50271. id: OPS.showText,
  50272. numArgs: 1,
  50273. variableArgs: false
  50274. };
  50275. t['TJ'] = {
  50276. id: OPS.showSpacedText,
  50277. numArgs: 1,
  50278. variableArgs: false
  50279. };
  50280. t['\''] = {
  50281. id: OPS.nextLineShowText,
  50282. numArgs: 1,
  50283. variableArgs: false
  50284. };
  50285. t['"'] = {
  50286. id: OPS.nextLineSetSpacingShowText,
  50287. numArgs: 3,
  50288. variableArgs: false
  50289. };
  50290. // Type3 fonts
  50291. t['d0'] = {
  50292. id: OPS.setCharWidth,
  50293. numArgs: 2,
  50294. variableArgs: false
  50295. };
  50296. t['d1'] = {
  50297. id: OPS.setCharWidthAndBounds,
  50298. numArgs: 6,
  50299. variableArgs: false
  50300. };
  50301. // Color
  50302. t['CS'] = {
  50303. id: OPS.setStrokeColorSpace,
  50304. numArgs: 1,
  50305. variableArgs: false
  50306. };
  50307. t['cs'] = {
  50308. id: OPS.setFillColorSpace,
  50309. numArgs: 1,
  50310. variableArgs: false
  50311. };
  50312. t['SC'] = {
  50313. id: OPS.setStrokeColor,
  50314. numArgs: 4,
  50315. variableArgs: true
  50316. };
  50317. t['SCN'] = {
  50318. id: OPS.setStrokeColorN,
  50319. numArgs: 33,
  50320. variableArgs: true
  50321. };
  50322. t['sc'] = {
  50323. id: OPS.setFillColor,
  50324. numArgs: 4,
  50325. variableArgs: true
  50326. };
  50327. t['scn'] = {
  50328. id: OPS.setFillColorN,
  50329. numArgs: 33,
  50330. variableArgs: true
  50331. };
  50332. t['G'] = {
  50333. id: OPS.setStrokeGray,
  50334. numArgs: 1,
  50335. variableArgs: false
  50336. };
  50337. t['g'] = {
  50338. id: OPS.setFillGray,
  50339. numArgs: 1,
  50340. variableArgs: false
  50341. };
  50342. t['RG'] = {
  50343. id: OPS.setStrokeRGBColor,
  50344. numArgs: 3,
  50345. variableArgs: false
  50346. };
  50347. t['rg'] = {
  50348. id: OPS.setFillRGBColor,
  50349. numArgs: 3,
  50350. variableArgs: false
  50351. };
  50352. t['K'] = {
  50353. id: OPS.setStrokeCMYKColor,
  50354. numArgs: 4,
  50355. variableArgs: false
  50356. };
  50357. t['k'] = {
  50358. id: OPS.setFillCMYKColor,
  50359. numArgs: 4,
  50360. variableArgs: false
  50361. };
  50362. // Shading
  50363. t['sh'] = {
  50364. id: OPS.shadingFill,
  50365. numArgs: 1,
  50366. variableArgs: false
  50367. };
  50368. // Images
  50369. t['BI'] = {
  50370. id: OPS.beginInlineImage,
  50371. numArgs: 0,
  50372. variableArgs: false
  50373. };
  50374. t['ID'] = {
  50375. id: OPS.beginImageData,
  50376. numArgs: 0,
  50377. variableArgs: false
  50378. };
  50379. t['EI'] = {
  50380. id: OPS.endInlineImage,
  50381. numArgs: 1,
  50382. variableArgs: false
  50383. };
  50384. // XObjects
  50385. t['Do'] = {
  50386. id: OPS.paintXObject,
  50387. numArgs: 1,
  50388. variableArgs: false
  50389. };
  50390. t['MP'] = {
  50391. id: OPS.markPoint,
  50392. numArgs: 1,
  50393. variableArgs: false
  50394. };
  50395. t['DP'] = {
  50396. id: OPS.markPointProps,
  50397. numArgs: 2,
  50398. variableArgs: false
  50399. };
  50400. t['BMC'] = {
  50401. id: OPS.beginMarkedContent,
  50402. numArgs: 1,
  50403. variableArgs: false
  50404. };
  50405. t['BDC'] = {
  50406. id: OPS.beginMarkedContentProps,
  50407. numArgs: 2,
  50408. variableArgs: false
  50409. };
  50410. t['EMC'] = {
  50411. id: OPS.endMarkedContent,
  50412. numArgs: 0,
  50413. variableArgs: false
  50414. };
  50415. // Compatibility
  50416. t['BX'] = {
  50417. id: OPS.beginCompat,
  50418. numArgs: 0,
  50419. variableArgs: false
  50420. };
  50421. t['EX'] = {
  50422. id: OPS.endCompat,
  50423. numArgs: 0,
  50424. variableArgs: false
  50425. };
  50426. // (reserved partial commands for the lexer)
  50427. t['BM'] = null;
  50428. t['BD'] = null;
  50429. t['true'] = null;
  50430. t['fa'] = null;
  50431. t['fal'] = null;
  50432. t['fals'] = null;
  50433. t['false'] = null;
  50434. t['nu'] = null;
  50435. t['nul'] = null;
  50436. t['null'] = null;
  50437. });
  50438. function EvaluatorPreprocessor(stream, xref, stateManager) {
  50439. this.opMap = getOPMap();
  50440. // TODO(mduan): pass array of knownCommands rather than this.opMap
  50441. // dictionary
  50442. this.parser = new Parser(new Lexer(stream, this.opMap), false, xref);
  50443. this.stateManager = stateManager;
  50444. this.nonProcessedArgs = [];
  50445. }
  50446. EvaluatorPreprocessor.prototype = {
  50447. get savedStatesDepth() {
  50448. return this.stateManager.stateStack.length;
  50449. },
  50450. // |operation| is an object with two fields:
  50451. //
  50452. // - |fn| is an out param.
  50453. //
  50454. // - |args| is an inout param. On entry, it should have one of two values.
  50455. //
  50456. // - An empty array. This indicates that the caller is providing the
  50457. // array in which the args will be stored in. The caller should use
  50458. // this value if it can reuse a single array for each call to read().
  50459. //
  50460. // - |null|. This indicates that the caller needs this function to create
  50461. // the array in which any args are stored in. If there are zero args,
  50462. // this function will leave |operation.args| as |null| (thus avoiding
  50463. // allocations that would occur if we used an empty array to represent
  50464. // zero arguments). Otherwise, it will replace |null| with a new array
  50465. // containing the arguments. The caller should use this value if it
  50466. // cannot reuse an array for each call to read().
  50467. //
  50468. // These two modes are present because this function is very hot and so
  50469. // avoiding allocations where possible is worthwhile.
  50470. //
  50471. read: function EvaluatorPreprocessor_read(operation) {
  50472. var args = operation.args;
  50473. while (true) {
  50474. var obj = this.parser.getObj();
  50475. if (isCmd(obj)) {
  50476. var cmd = obj.cmd;
  50477. // Check that the command is valid
  50478. var opSpec = this.opMap[cmd];
  50479. if (!opSpec) {
  50480. warn('Unknown command "' + cmd + '"');
  50481. continue;
  50482. }
  50483. var fn = opSpec.id;
  50484. var numArgs = opSpec.numArgs;
  50485. var argsLength = args !== null ? args.length : 0;
  50486. if (!opSpec.variableArgs) {
  50487. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  50488. if (argsLength !== numArgs) {
  50489. var nonProcessedArgs = this.nonProcessedArgs;
  50490. while (argsLength > numArgs) {
  50491. nonProcessedArgs.push(args.shift());
  50492. argsLength--;
  50493. }
  50494. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  50495. if (!args) {
  50496. args = [];
  50497. }
  50498. args.unshift(nonProcessedArgs.pop());
  50499. argsLength++;
  50500. }
  50501. }
  50502. if (argsLength < numArgs) {
  50503. // If we receive too few args, it's not possible to possible
  50504. // to execute the command, so skip the command
  50505. info('Command ' + fn + ': because expected ' + numArgs + ' args, but received ' + argsLength + ' args; skipping');
  50506. args = null;
  50507. continue;
  50508. }
  50509. } else if (argsLength > numArgs) {
  50510. info('Command ' + fn + ': expected [0,' + numArgs + '] args, but received ' + argsLength + ' args');
  50511. }
  50512. // TODO figure out how to type-check vararg functions
  50513. this.preprocessCommand(fn, args);
  50514. operation.fn = fn;
  50515. operation.args = args;
  50516. return true;
  50517. } else {
  50518. if (isEOF(obj)) {
  50519. return false;
  50520. }
  50521. // no more commands
  50522. // argument
  50523. if (obj !== null) {
  50524. if (!args) {
  50525. args = [];
  50526. }
  50527. args.push(obj);
  50528. assert(args.length <= 33, 'Too many arguments');
  50529. }
  50530. }
  50531. }
  50532. },
  50533. preprocessCommand: function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  50534. switch (fn | 0) {
  50535. case OPS.save:
  50536. this.stateManager.save();
  50537. break;
  50538. case OPS.restore:
  50539. this.stateManager.restore();
  50540. break;
  50541. case OPS.transform:
  50542. this.stateManager.transform(args);
  50543. break;
  50544. }
  50545. }
  50546. };
  50547. return EvaluatorPreprocessor;
  50548. }();
  50549. var QueueOptimizer = function QueueOptimizerClosure() {
  50550. function addState(parentState, pattern, fn) {
  50551. var state = parentState;
  50552. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  50553. var item = pattern[i];
  50554. state = state[item] || (state[item] = []);
  50555. }
  50556. state[pattern[pattern.length - 1]] = fn;
  50557. }
  50558. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray, argsArray) {
  50559. // Handles special case of mainly LaTeX documents which use image masks to
  50560. // draw lines with the current fill style.
  50561. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  50562. // have been found at iFirstSave.
  50563. var iFirstPIMXO = iFirstSave + 2;
  50564. for (var i = 0; i < count; i++) {
  50565. var arg = argsArray[iFirstPIMXO + 4 * i];
  50566. var imageMask = arg.length === 1 && arg[0];
  50567. if (imageMask && imageMask.width === 1 && imageMask.height === 1 && (!imageMask.data.length || imageMask.data.length === 1 && imageMask.data[0] === 0)) {
  50568. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  50569. continue;
  50570. }
  50571. break;
  50572. }
  50573. return count - i;
  50574. }
  50575. var InitialState = [];
  50576. // This replaces (save, transform, paintInlineImageXObject, restore)+
  50577. // sequences with one |paintInlineImageXObjectGroup| operation.
  50578. addState(InitialState, [
  50579. OPS.save,
  50580. OPS.transform,
  50581. OPS.paintInlineImageXObject,
  50582. OPS.restore
  50583. ], function foundInlineImageGroup(context) {
  50584. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  50585. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  50586. var MAX_WIDTH = 1000;
  50587. var IMAGE_PADDING = 1;
  50588. var fnArray = context.fnArray, argsArray = context.argsArray;
  50589. var curr = context.iCurr;
  50590. var iFirstSave = curr - 3;
  50591. var iFirstTransform = curr - 2;
  50592. var iFirstPIIXO = curr - 1;
  50593. // Look for the quartets.
  50594. var i = iFirstSave + 4;
  50595. var ii = fnArray.length;
  50596. while (i + 3 < ii) {
  50597. if (fnArray[i] !== OPS.save || fnArray[i + 1] !== OPS.transform || fnArray[i + 2] !== OPS.paintInlineImageXObject || fnArray[i + 3] !== OPS.restore) {
  50598. break;
  50599. }
  50600. // ops don't match
  50601. i += 4;
  50602. }
  50603. // At this point, i is the index of the first op past the last valid
  50604. // quartet.
  50605. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  50606. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  50607. return i;
  50608. }
  50609. // assuming that heights of those image is too small (~1 pixel)
  50610. // packing as much as possible by lines
  50611. var maxX = 0;
  50612. var map = [], maxLineHeight = 0;
  50613. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  50614. var q;
  50615. for (q = 0; q < count; q++) {
  50616. var transform = argsArray[iFirstTransform + (q << 2)];
  50617. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  50618. if (currentX + img.width > MAX_WIDTH) {
  50619. // starting new line
  50620. maxX = Math.max(maxX, currentX);
  50621. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  50622. currentX = 0;
  50623. maxLineHeight = 0;
  50624. }
  50625. map.push({
  50626. transform: transform,
  50627. x: currentX,
  50628. y: currentY,
  50629. w: img.width,
  50630. h: img.height
  50631. });
  50632. currentX += img.width + 2 * IMAGE_PADDING;
  50633. maxLineHeight = Math.max(maxLineHeight, img.height);
  50634. }
  50635. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  50636. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  50637. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  50638. var imgRowSize = imgWidth << 2;
  50639. for (q = 0; q < count; q++) {
  50640. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  50641. // Copy image by lines and extends pixels into padding.
  50642. var rowSize = map[q].w << 2;
  50643. var dataOffset = 0;
  50644. var offset = map[q].x + map[q].y * imgWidth << 2;
  50645. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  50646. for (var k = 0, kk = map[q].h; k < kk; k++) {
  50647. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  50648. dataOffset += rowSize;
  50649. offset += imgRowSize;
  50650. }
  50651. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  50652. while (offset >= 0) {
  50653. data[offset - 4] = data[offset];
  50654. data[offset - 3] = data[offset + 1];
  50655. data[offset - 2] = data[offset + 2];
  50656. data[offset - 1] = data[offset + 3];
  50657. data[offset + rowSize] = data[offset + rowSize - 4];
  50658. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  50659. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  50660. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  50661. offset -= imgRowSize;
  50662. }
  50663. }
  50664. // Replace queue items.
  50665. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  50666. argsArray.splice(iFirstSave, count * 4, [
  50667. {
  50668. width: imgWidth,
  50669. height: imgHeight,
  50670. kind: ImageKind.RGBA_32BPP,
  50671. data: imgData
  50672. },
  50673. map
  50674. ]);
  50675. return iFirstSave + 1;
  50676. });
  50677. // This replaces (save, transform, paintImageMaskXObject, restore)+
  50678. // sequences with one |paintImageMaskXObjectGroup| or one
  50679. // |paintImageMaskXObjectRepeat| operation.
  50680. addState(InitialState, [
  50681. OPS.save,
  50682. OPS.transform,
  50683. OPS.paintImageMaskXObject,
  50684. OPS.restore
  50685. ], function foundImageMaskGroup(context) {
  50686. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  50687. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  50688. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  50689. var fnArray = context.fnArray, argsArray = context.argsArray;
  50690. var curr = context.iCurr;
  50691. var iFirstSave = curr - 3;
  50692. var iFirstTransform = curr - 2;
  50693. var iFirstPIMXO = curr - 1;
  50694. // Look for the quartets.
  50695. var i = iFirstSave + 4;
  50696. var ii = fnArray.length;
  50697. while (i + 3 < ii) {
  50698. if (fnArray[i] !== OPS.save || fnArray[i + 1] !== OPS.transform || fnArray[i + 2] !== OPS.paintImageMaskXObject || fnArray[i + 3] !== OPS.restore) {
  50699. break;
  50700. }
  50701. // ops don't match
  50702. i += 4;
  50703. }
  50704. // At this point, i is the index of the first op past the last valid
  50705. // quartet.
  50706. var count = (i - iFirstSave) / 4;
  50707. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray, argsArray);
  50708. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  50709. return i;
  50710. }
  50711. var q;
  50712. var isSameImage = false;
  50713. var iTransform, transformArgs;
  50714. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  50715. if (argsArray[iFirstTransform][1] === 0 && argsArray[iFirstTransform][2] === 0) {
  50716. isSameImage = true;
  50717. var firstTransformArg0 = argsArray[iFirstTransform][0];
  50718. var firstTransformArg3 = argsArray[iFirstTransform][3];
  50719. iTransform = iFirstTransform + 4;
  50720. var iPIMXO = iFirstPIMXO + 4;
  50721. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  50722. transformArgs = argsArray[iTransform];
  50723. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 || transformArgs[0] !== firstTransformArg0 || transformArgs[1] !== 0 || transformArgs[2] !== 0 || transformArgs[3] !== firstTransformArg3) {
  50724. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  50725. isSameImage = false;
  50726. } else {
  50727. count = q;
  50728. }
  50729. break;
  50730. }
  50731. }
  50732. }
  50733. // different image or transform
  50734. if (isSameImage) {
  50735. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  50736. var positions = new Float32Array(count * 2);
  50737. iTransform = iFirstTransform;
  50738. for (q = 0; q < count; q++, iTransform += 4) {
  50739. transformArgs = argsArray[iTransform];
  50740. positions[q << 1] = transformArgs[4];
  50741. positions[(q << 1) + 1] = transformArgs[5];
  50742. }
  50743. // Replace queue items.
  50744. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  50745. argsArray.splice(iFirstSave, count * 4, [
  50746. firstPIMXOArg0,
  50747. firstTransformArg0,
  50748. firstTransformArg3,
  50749. positions
  50750. ]);
  50751. } else {
  50752. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  50753. var images = [];
  50754. for (q = 0; q < count; q++) {
  50755. transformArgs = argsArray[iFirstTransform + (q << 2)];
  50756. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  50757. images.push({
  50758. data: maskParams.data,
  50759. width: maskParams.width,
  50760. height: maskParams.height,
  50761. transform: transformArgs
  50762. });
  50763. }
  50764. // Replace queue items.
  50765. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  50766. argsArray.splice(iFirstSave, count * 4, [images]);
  50767. }
  50768. return iFirstSave + 1;
  50769. });
  50770. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  50771. // with one paintImageXObjectRepeat operation, if the |transform| and
  50772. // |paintImageXObjectRepeat| ops are appropriate.
  50773. addState(InitialState, [
  50774. OPS.save,
  50775. OPS.transform,
  50776. OPS.paintImageXObject,
  50777. OPS.restore
  50778. ], function (context) {
  50779. var MIN_IMAGES_IN_BLOCK = 3;
  50780. var MAX_IMAGES_IN_BLOCK = 1000;
  50781. var fnArray = context.fnArray, argsArray = context.argsArray;
  50782. var curr = context.iCurr;
  50783. var iFirstSave = curr - 3;
  50784. var iFirstTransform = curr - 2;
  50785. var iFirstPIXO = curr - 1;
  50786. var iFirstRestore = curr;
  50787. if (argsArray[iFirstTransform][1] !== 0 || argsArray[iFirstTransform][2] !== 0) {
  50788. return iFirstRestore + 1;
  50789. }
  50790. // transform has the wrong form
  50791. // Look for the quartets.
  50792. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  50793. var firstTransformArg0 = argsArray[iFirstTransform][0];
  50794. var firstTransformArg3 = argsArray[iFirstTransform][3];
  50795. var i = iFirstSave + 4;
  50796. var ii = fnArray.length;
  50797. while (i + 3 < ii) {
  50798. if (fnArray[i] !== OPS.save || fnArray[i + 1] !== OPS.transform || fnArray[i + 2] !== OPS.paintImageXObject || fnArray[i + 3] !== OPS.restore) {
  50799. break;
  50800. }
  50801. // ops don't match
  50802. if (argsArray[i + 1][0] !== firstTransformArg0 || argsArray[i + 1][1] !== 0 || argsArray[i + 1][2] !== 0 || argsArray[i + 1][3] !== firstTransformArg3) {
  50803. break;
  50804. }
  50805. // transforms don't match
  50806. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  50807. break;
  50808. }
  50809. // images don't match
  50810. i += 4;
  50811. }
  50812. // At this point, i is the index of the first op past the last valid
  50813. // quartet.
  50814. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  50815. if (count < MIN_IMAGES_IN_BLOCK) {
  50816. return i;
  50817. }
  50818. // Extract the (x,y) positions from all of the matching transforms.
  50819. var positions = new Float32Array(count * 2);
  50820. var iTransform = iFirstTransform;
  50821. for (var q = 0; q < count; q++, iTransform += 4) {
  50822. var transformArgs = argsArray[iTransform];
  50823. positions[q << 1] = transformArgs[4];
  50824. positions[(q << 1) + 1] = transformArgs[5];
  50825. }
  50826. // Replace queue items.
  50827. var args = [
  50828. firstPIXOArg0,
  50829. firstTransformArg0,
  50830. firstTransformArg3,
  50831. positions
  50832. ];
  50833. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  50834. argsArray.splice(iFirstSave, count * 4, args);
  50835. return iFirstSave + 1;
  50836. });
  50837. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  50838. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  50839. // sequences, if the font for each one is the same.
  50840. addState(InitialState, [
  50841. OPS.beginText,
  50842. OPS.setFont,
  50843. OPS.setTextMatrix,
  50844. OPS.showText,
  50845. OPS.endText
  50846. ], function (context) {
  50847. var MIN_CHARS_IN_BLOCK = 3;
  50848. var MAX_CHARS_IN_BLOCK = 1000;
  50849. var fnArray = context.fnArray, argsArray = context.argsArray;
  50850. var curr = context.iCurr;
  50851. var iFirstBeginText = curr - 4;
  50852. var iFirstSetFont = curr - 3;
  50853. var iFirstSetTextMatrix = curr - 2;
  50854. var iFirstShowText = curr - 1;
  50855. var iFirstEndText = curr;
  50856. // Look for the quintets.
  50857. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  50858. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  50859. var i = iFirstBeginText + 5;
  50860. var ii = fnArray.length;
  50861. while (i + 4 < ii) {
  50862. 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) {
  50863. break;
  50864. }
  50865. // ops don't match
  50866. if (argsArray[i + 1][0] !== firstSetFontArg0 || argsArray[i + 1][1] !== firstSetFontArg1) {
  50867. break;
  50868. }
  50869. // fonts don't match
  50870. i += 5;
  50871. }
  50872. // At this point, i is the index of the first op past the last valid
  50873. // quintet.
  50874. var count = Math.min((i - iFirstBeginText) / 5, MAX_CHARS_IN_BLOCK);
  50875. if (count < MIN_CHARS_IN_BLOCK) {
  50876. return i;
  50877. }
  50878. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  50879. // showText, endText), include that as well. (E.g. <something> might be
  50880. // |dependency|.)
  50881. var iFirst = iFirstBeginText;
  50882. 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) {
  50883. count++;
  50884. iFirst -= 5;
  50885. }
  50886. // Remove (endText, beginText, setFont) trios.
  50887. var iEndText = iFirst + 4;
  50888. for (var q = 1; q < count; q++) {
  50889. fnArray.splice(iEndText, 3);
  50890. argsArray.splice(iEndText, 3);
  50891. iEndText += 2;
  50892. }
  50893. return iEndText + 1;
  50894. });
  50895. function QueueOptimizer() {
  50896. }
  50897. QueueOptimizer.prototype = {
  50898. optimize: function QueueOptimizer_optimize(queue) {
  50899. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  50900. var context = {
  50901. iCurr: 0,
  50902. fnArray: fnArray,
  50903. argsArray: argsArray
  50904. };
  50905. var state;
  50906. var i = 0, ii = fnArray.length;
  50907. while (i < ii) {
  50908. state = (state || InitialState)[fnArray[i]];
  50909. if (typeof state === 'function') {
  50910. // we found some handler
  50911. context.iCurr = i;
  50912. // state() returns the index of the first non-matching op (if we
  50913. // didn't match) or the first op past the modified ops (if we did
  50914. // match and replace).
  50915. i = state(context);
  50916. state = undefined;
  50917. // reset the state machine
  50918. ii = context.fnArray.length;
  50919. } else {
  50920. i++;
  50921. }
  50922. }
  50923. }
  50924. };
  50925. return QueueOptimizer;
  50926. }();
  50927. exports.OperatorList = OperatorList;
  50928. exports.PartialEvaluator = PartialEvaluator;
  50929. }));
  50930. (function (root, factory) {
  50931. factory(root.pdfjsCoreAnnotation = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreColorSpace, root.pdfjsCoreObj, root.pdfjsCoreEvaluator);
  50932. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreColorSpace, coreObj, coreEvaluator) {
  50933. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  50934. var AnnotationFieldFlag = sharedUtil.AnnotationFieldFlag;
  50935. var AnnotationFlag = sharedUtil.AnnotationFlag;
  50936. var AnnotationType = sharedUtil.AnnotationType;
  50937. var OPS = sharedUtil.OPS;
  50938. var Util = sharedUtil.Util;
  50939. var isBool = sharedUtil.isBool;
  50940. var isString = sharedUtil.isString;
  50941. var isArray = sharedUtil.isArray;
  50942. var isInt = sharedUtil.isInt;
  50943. var isValidUrl = sharedUtil.isValidUrl;
  50944. var stringToBytes = sharedUtil.stringToBytes;
  50945. var stringToPDFString = sharedUtil.stringToPDFString;
  50946. var stringToUTF8String = sharedUtil.stringToUTF8String;
  50947. var warn = sharedUtil.warn;
  50948. var Dict = corePrimitives.Dict;
  50949. var isDict = corePrimitives.isDict;
  50950. var isName = corePrimitives.isName;
  50951. var isRef = corePrimitives.isRef;
  50952. var Stream = coreStream.Stream;
  50953. var ColorSpace = coreColorSpace.ColorSpace;
  50954. var ObjectLoader = coreObj.ObjectLoader;
  50955. var FileSpec = coreObj.FileSpec;
  50956. var OperatorList = coreEvaluator.OperatorList;
  50957. /**
  50958. * @class
  50959. * @alias AnnotationFactory
  50960. */
  50961. function AnnotationFactory() {
  50962. }
  50963. AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */
  50964. {
  50965. /**
  50966. * @param {XRef} xref
  50967. * @param {Object} ref
  50968. * @param {string} uniquePrefix
  50969. * @param {Object} idCounters
  50970. * @returns {Annotation}
  50971. */
  50972. create: function AnnotationFactory_create(xref, ref, uniquePrefix, idCounters) {
  50973. var dict = xref.fetchIfRef(ref);
  50974. if (!isDict(dict)) {
  50975. return;
  50976. }
  50977. var id = isRef(ref) ? ref.toString() : 'annot_' + (uniquePrefix || '') + ++idCounters.obj;
  50978. // Determine the annotation's subtype.
  50979. var subtype = dict.get('Subtype');
  50980. subtype = isName(subtype) ? subtype.name : null;
  50981. // Return the right annotation object based on the subtype and field type.
  50982. var parameters = {
  50983. xref: xref,
  50984. dict: dict,
  50985. ref: isRef(ref) ? ref : null,
  50986. subtype: subtype,
  50987. id: id
  50988. };
  50989. switch (subtype) {
  50990. case 'Link':
  50991. return new LinkAnnotation(parameters);
  50992. case 'Text':
  50993. return new TextAnnotation(parameters);
  50994. case 'Widget':
  50995. var fieldType = Util.getInheritableProperty(dict, 'FT');
  50996. fieldType = isName(fieldType) ? fieldType.name : null;
  50997. switch (fieldType) {
  50998. case 'Tx':
  50999. return new TextWidgetAnnotation(parameters);
  51000. case 'Ch':
  51001. return new ChoiceWidgetAnnotation(parameters);
  51002. }
  51003. warn('Unimplemented widget field type "' + fieldType + '", ' + 'falling back to base field type.');
  51004. return new WidgetAnnotation(parameters);
  51005. case 'Popup':
  51006. return new PopupAnnotation(parameters);
  51007. case 'Highlight':
  51008. return new HighlightAnnotation(parameters);
  51009. case 'Underline':
  51010. return new UnderlineAnnotation(parameters);
  51011. case 'Squiggly':
  51012. return new SquigglyAnnotation(parameters);
  51013. case 'StrikeOut':
  51014. return new StrikeOutAnnotation(parameters);
  51015. case 'FileAttachment':
  51016. return new FileAttachmentAnnotation(parameters);
  51017. default:
  51018. if (!subtype) {
  51019. warn('Annotation is missing the required /Subtype.');
  51020. } else {
  51021. warn('Unimplemented annotation type "' + subtype + '", ' + 'falling back to base annotation.');
  51022. }
  51023. return new Annotation(parameters);
  51024. }
  51025. }
  51026. };
  51027. var Annotation = function AnnotationClosure() {
  51028. // 12.5.5: Algorithm: Appearance streams
  51029. function getTransformMatrix(rect, bbox, matrix) {
  51030. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  51031. var minX = bounds[0];
  51032. var minY = bounds[1];
  51033. var maxX = bounds[2];
  51034. var maxY = bounds[3];
  51035. if (minX === maxX || minY === maxY) {
  51036. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  51037. // just apply the transform for rect
  51038. return [
  51039. 1,
  51040. 0,
  51041. 0,
  51042. 1,
  51043. rect[0],
  51044. rect[1]
  51045. ];
  51046. }
  51047. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  51048. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  51049. return [
  51050. xRatio,
  51051. 0,
  51052. 0,
  51053. yRatio,
  51054. rect[0] - minX * xRatio,
  51055. rect[1] - minY * yRatio
  51056. ];
  51057. }
  51058. function getDefaultAppearance(dict) {
  51059. var appearanceState = dict.get('AP');
  51060. if (!isDict(appearanceState)) {
  51061. return;
  51062. }
  51063. var appearance;
  51064. var appearances = appearanceState.get('N');
  51065. if (isDict(appearances)) {
  51066. var as = dict.get('AS');
  51067. if (as && appearances.has(as.name)) {
  51068. appearance = appearances.get(as.name);
  51069. }
  51070. } else {
  51071. appearance = appearances;
  51072. }
  51073. return appearance;
  51074. }
  51075. function Annotation(params) {
  51076. var dict = params.dict;
  51077. this.setFlags(dict.get('F'));
  51078. this.setRectangle(dict.getArray('Rect'));
  51079. this.setColor(dict.getArray('C'));
  51080. this.setBorderStyle(dict);
  51081. this.appearance = getDefaultAppearance(dict);
  51082. // Expose public properties using a data object.
  51083. this.data = {};
  51084. this.data.id = params.id;
  51085. this.data.subtype = params.subtype;
  51086. this.data.annotationFlags = this.flags;
  51087. this.data.rect = this.rectangle;
  51088. this.data.color = this.color;
  51089. this.data.borderStyle = this.borderStyle;
  51090. this.data.hasAppearance = !!this.appearance;
  51091. }
  51092. Annotation.prototype = {
  51093. /**
  51094. * @private
  51095. */
  51096. _hasFlag: function Annotation_hasFlag(flags, flag) {
  51097. return !!(flags & flag);
  51098. },
  51099. /**
  51100. * @private
  51101. */
  51102. _isViewable: function Annotation_isViewable(flags) {
  51103. return !this._hasFlag(flags, AnnotationFlag.INVISIBLE) && !this._hasFlag(flags, AnnotationFlag.HIDDEN) && !this._hasFlag(flags, AnnotationFlag.NOVIEW);
  51104. },
  51105. /**
  51106. * @private
  51107. */
  51108. _isPrintable: function AnnotationFlag_isPrintable(flags) {
  51109. return this._hasFlag(flags, AnnotationFlag.PRINT) && !this._hasFlag(flags, AnnotationFlag.INVISIBLE) && !this._hasFlag(flags, AnnotationFlag.HIDDEN);
  51110. },
  51111. /**
  51112. * @return {boolean}
  51113. */
  51114. get viewable() {
  51115. if (this.flags === 0) {
  51116. return true;
  51117. }
  51118. return this._isViewable(this.flags);
  51119. },
  51120. /**
  51121. * @return {boolean}
  51122. */
  51123. get printable() {
  51124. if (this.flags === 0) {
  51125. return false;
  51126. }
  51127. return this._isPrintable(this.flags);
  51128. },
  51129. /**
  51130. * Set the flags.
  51131. *
  51132. * @public
  51133. * @memberof Annotation
  51134. * @param {number} flags - Unsigned 32-bit integer specifying annotation
  51135. * characteristics
  51136. * @see {@link shared/util.js}
  51137. */
  51138. setFlags: function Annotation_setFlags(flags) {
  51139. this.flags = isInt(flags) && flags > 0 ? flags : 0;
  51140. },
  51141. /**
  51142. * Check if a provided flag is set.
  51143. *
  51144. * @public
  51145. * @memberof Annotation
  51146. * @param {number} flag - Hexadecimal representation for an annotation
  51147. * characteristic
  51148. * @return {boolean}
  51149. * @see {@link shared/util.js}
  51150. */
  51151. hasFlag: function Annotation_hasFlag(flag) {
  51152. return this._hasFlag(this.flags, flag);
  51153. },
  51154. /**
  51155. * Set the rectangle.
  51156. *
  51157. * @public
  51158. * @memberof Annotation
  51159. * @param {Array} rectangle - The rectangle array with exactly four entries
  51160. */
  51161. setRectangle: function Annotation_setRectangle(rectangle) {
  51162. if (isArray(rectangle) && rectangle.length === 4) {
  51163. this.rectangle = Util.normalizeRect(rectangle);
  51164. } else {
  51165. this.rectangle = [
  51166. 0,
  51167. 0,
  51168. 0,
  51169. 0
  51170. ];
  51171. }
  51172. },
  51173. /**
  51174. * Set the color and take care of color space conversion.
  51175. *
  51176. * @public
  51177. * @memberof Annotation
  51178. * @param {Array} color - The color array containing either 0
  51179. * (transparent), 1 (grayscale), 3 (RGB) or
  51180. * 4 (CMYK) elements
  51181. */
  51182. setColor: function Annotation_setColor(color) {
  51183. var rgbColor = new Uint8Array(3);
  51184. // Black in RGB color space (default)
  51185. if (!isArray(color)) {
  51186. this.color = rgbColor;
  51187. return;
  51188. }
  51189. switch (color.length) {
  51190. case 0:
  51191. // Transparent, which we indicate with a null value
  51192. this.color = null;
  51193. break;
  51194. case 1:
  51195. // Convert grayscale to RGB
  51196. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  51197. this.color = rgbColor;
  51198. break;
  51199. case 3:
  51200. // Convert RGB percentages to RGB
  51201. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  51202. this.color = rgbColor;
  51203. break;
  51204. case 4:
  51205. // Convert CMYK to RGB
  51206. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  51207. this.color = rgbColor;
  51208. break;
  51209. default:
  51210. this.color = rgbColor;
  51211. break;
  51212. }
  51213. },
  51214. /**
  51215. * Set the border style (as AnnotationBorderStyle object).
  51216. *
  51217. * @public
  51218. * @memberof Annotation
  51219. * @param {Dict} borderStyle - The border style dictionary
  51220. */
  51221. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  51222. this.borderStyle = new AnnotationBorderStyle();
  51223. if (!isDict(borderStyle)) {
  51224. return;
  51225. }
  51226. if (borderStyle.has('BS')) {
  51227. var dict = borderStyle.get('BS');
  51228. var dictType = dict.get('Type');
  51229. if (!dictType || isName(dictType, 'Border')) {
  51230. this.borderStyle.setWidth(dict.get('W'));
  51231. this.borderStyle.setStyle(dict.get('S'));
  51232. this.borderStyle.setDashArray(dict.getArray('D'));
  51233. }
  51234. } else if (borderStyle.has('Border')) {
  51235. var array = borderStyle.getArray('Border');
  51236. if (isArray(array) && array.length >= 3) {
  51237. this.borderStyle.setHorizontalCornerRadius(array[0]);
  51238. this.borderStyle.setVerticalCornerRadius(array[1]);
  51239. this.borderStyle.setWidth(array[2]);
  51240. if (array.length === 4) {
  51241. // Dash array available
  51242. this.borderStyle.setDashArray(array[3]);
  51243. }
  51244. }
  51245. } else {
  51246. // There are no border entries in the dictionary. According to the
  51247. // specification, we should draw a solid border of width 1 in that
  51248. // case, but Adobe Reader did not implement that part of the
  51249. // specification and instead draws no border at all, so we do the same.
  51250. // See also https://github.com/mozilla/pdf.js/issues/6179.
  51251. this.borderStyle.setWidth(0);
  51252. }
  51253. },
  51254. /**
  51255. * Prepare the annotation for working with a popup in the display layer.
  51256. *
  51257. * @private
  51258. * @memberof Annotation
  51259. * @param {Dict} dict - The annotation's data dictionary
  51260. */
  51261. _preparePopup: function Annotation_preparePopup(dict) {
  51262. if (!dict.has('C')) {
  51263. // Fall back to the default background color.
  51264. this.data.color = null;
  51265. }
  51266. this.data.hasPopup = dict.has('Popup');
  51267. this.data.title = stringToPDFString(dict.get('T') || '');
  51268. this.data.contents = stringToPDFString(dict.get('Contents') || '');
  51269. },
  51270. loadResources: function Annotation_loadResources(keys) {
  51271. return new Promise(function (resolve, reject) {
  51272. this.appearance.dict.getAsync('Resources').then(function (resources) {
  51273. if (!resources) {
  51274. resolve();
  51275. return;
  51276. }
  51277. var objectLoader = new ObjectLoader(resources.map, keys, resources.xref);
  51278. objectLoader.load().then(function () {
  51279. resolve(resources);
  51280. }, reject);
  51281. }, reject);
  51282. }.bind(this));
  51283. },
  51284. getOperatorList: function Annotation_getOperatorList(evaluator, task, renderForms) {
  51285. if (!this.appearance) {
  51286. return Promise.resolve(new OperatorList());
  51287. }
  51288. var data = this.data;
  51289. var appearanceDict = this.appearance.dict;
  51290. var resourcesPromise = this.loadResources([
  51291. 'ExtGState',
  51292. 'ColorSpace',
  51293. 'Pattern',
  51294. 'Shading',
  51295. 'XObject',
  51296. 'Font'
  51297. ]);
  51298. // ProcSet
  51299. // Properties
  51300. var bbox = appearanceDict.getArray('BBox') || [
  51301. 0,
  51302. 0,
  51303. 1,
  51304. 1
  51305. ];
  51306. var matrix = appearanceDict.getArray('Matrix') || [
  51307. 1,
  51308. 0,
  51309. 0,
  51310. 1,
  51311. 0,
  51312. 0
  51313. ];
  51314. var transform = getTransformMatrix(data.rect, bbox, matrix);
  51315. var self = this;
  51316. return resourcesPromise.then(function (resources) {
  51317. var opList = new OperatorList();
  51318. opList.addOp(OPS.beginAnnotation, [
  51319. data.rect,
  51320. transform,
  51321. matrix
  51322. ]);
  51323. return evaluator.getOperatorList(self.appearance, task, resources, opList).then(function () {
  51324. opList.addOp(OPS.endAnnotation, []);
  51325. self.appearance.reset();
  51326. return opList;
  51327. });
  51328. });
  51329. }
  51330. };
  51331. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(annotations, opList, partialEvaluator, task, intent, renderForms) {
  51332. var annotationPromises = [];
  51333. for (var i = 0, n = annotations.length; i < n; ++i) {
  51334. if (intent === 'display' && annotations[i].viewable || intent === 'print' && annotations[i].printable) {
  51335. annotationPromises.push(annotations[i].getOperatorList(partialEvaluator, task, renderForms));
  51336. }
  51337. }
  51338. return Promise.all(annotationPromises).then(function (operatorLists) {
  51339. opList.addOp(OPS.beginAnnotations, []);
  51340. for (var i = 0, n = operatorLists.length; i < n; ++i) {
  51341. opList.addOpList(operatorLists[i]);
  51342. }
  51343. opList.addOp(OPS.endAnnotations, []);
  51344. });
  51345. };
  51346. return Annotation;
  51347. }();
  51348. /**
  51349. * Contains all data regarding an annotation's border style.
  51350. *
  51351. * @class
  51352. */
  51353. var AnnotationBorderStyle = function AnnotationBorderStyleClosure() {
  51354. /**
  51355. * @constructor
  51356. * @private
  51357. */
  51358. function AnnotationBorderStyle() {
  51359. this.width = 1;
  51360. this.style = AnnotationBorderStyleType.SOLID;
  51361. this.dashArray = [3];
  51362. this.horizontalCornerRadius = 0;
  51363. this.verticalCornerRadius = 0;
  51364. }
  51365. AnnotationBorderStyle.prototype = {
  51366. /**
  51367. * Set the width.
  51368. *
  51369. * @public
  51370. * @memberof AnnotationBorderStyle
  51371. * @param {integer} width - The width
  51372. */
  51373. setWidth: function AnnotationBorderStyle_setWidth(width) {
  51374. if (width === (width | 0)) {
  51375. this.width = width;
  51376. }
  51377. },
  51378. /**
  51379. * Set the style.
  51380. *
  51381. * @public
  51382. * @memberof AnnotationBorderStyle
  51383. * @param {Object} style - The style object
  51384. * @see {@link shared/util.js}
  51385. */
  51386. setStyle: function AnnotationBorderStyle_setStyle(style) {
  51387. if (!style) {
  51388. return;
  51389. }
  51390. switch (style.name) {
  51391. case 'S':
  51392. this.style = AnnotationBorderStyleType.SOLID;
  51393. break;
  51394. case 'D':
  51395. this.style = AnnotationBorderStyleType.DASHED;
  51396. break;
  51397. case 'B':
  51398. this.style = AnnotationBorderStyleType.BEVELED;
  51399. break;
  51400. case 'I':
  51401. this.style = AnnotationBorderStyleType.INSET;
  51402. break;
  51403. case 'U':
  51404. this.style = AnnotationBorderStyleType.UNDERLINE;
  51405. break;
  51406. default:
  51407. break;
  51408. }
  51409. },
  51410. /**
  51411. * Set the dash array.
  51412. *
  51413. * @public
  51414. * @memberof AnnotationBorderStyle
  51415. * @param {Array} dashArray - The dash array with at least one element
  51416. */
  51417. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  51418. // We validate the dash array, but we do not use it because CSS does not
  51419. // allow us to change spacing of dashes. For more information, visit
  51420. // http://www.w3.org/TR/css3-background/#the-border-style.
  51421. if (isArray(dashArray) && dashArray.length > 0) {
  51422. // According to the PDF specification: the elements in a dashArray
  51423. // shall be numbers that are nonnegative and not all equal to zero.
  51424. var isValid = true;
  51425. var allZeros = true;
  51426. for (var i = 0, len = dashArray.length; i < len; i++) {
  51427. var element = dashArray[i];
  51428. var validNumber = +element >= 0;
  51429. if (!validNumber) {
  51430. isValid = false;
  51431. break;
  51432. } else if (element > 0) {
  51433. allZeros = false;
  51434. }
  51435. }
  51436. if (isValid && !allZeros) {
  51437. this.dashArray = dashArray;
  51438. } else {
  51439. this.width = 0;
  51440. }
  51441. } else // Adobe behavior when the array is invalid.
  51442. if (dashArray) {
  51443. this.width = 0;
  51444. }
  51445. },
  51446. // Adobe behavior when the array is invalid.
  51447. /**
  51448. * Set the horizontal corner radius (from a Border dictionary).
  51449. *
  51450. * @public
  51451. * @memberof AnnotationBorderStyle
  51452. * @param {integer} radius - The horizontal corner radius
  51453. */
  51454. setHorizontalCornerRadius: function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  51455. if (radius === (radius | 0)) {
  51456. this.horizontalCornerRadius = radius;
  51457. }
  51458. },
  51459. /**
  51460. * Set the vertical corner radius (from a Border dictionary).
  51461. *
  51462. * @public
  51463. * @memberof AnnotationBorderStyle
  51464. * @param {integer} radius - The vertical corner radius
  51465. */
  51466. setVerticalCornerRadius: function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  51467. if (radius === (radius | 0)) {
  51468. this.verticalCornerRadius = radius;
  51469. }
  51470. }
  51471. };
  51472. return AnnotationBorderStyle;
  51473. }();
  51474. var WidgetAnnotation = function WidgetAnnotationClosure() {
  51475. function WidgetAnnotation(params) {
  51476. Annotation.call(this, params);
  51477. var dict = params.dict;
  51478. var data = this.data;
  51479. data.annotationType = AnnotationType.WIDGET;
  51480. data.fieldValue = Util.getInheritableProperty(dict, 'V', /* getArray = */
  51481. true);
  51482. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  51483. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  51484. var fieldType = Util.getInheritableProperty(dict, 'FT');
  51485. data.fieldType = isName(fieldType) ? fieldType.name : null;
  51486. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  51487. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff');
  51488. if (!isInt(data.fieldFlags) || data.fieldFlags < 0) {
  51489. data.fieldFlags = 0;
  51490. }
  51491. data.readOnly = this.hasFieldFlag(AnnotationFieldFlag.READONLY);
  51492. // Hide signatures because we cannot validate them.
  51493. if (data.fieldType === 'Sig') {
  51494. this.setFlags(AnnotationFlag.HIDDEN);
  51495. }
  51496. // Building the full field name by collecting the field and
  51497. // its ancestors 'T' data and joining them using '.'.
  51498. var fieldName = [];
  51499. var namedItem = dict;
  51500. var ref = params.ref;
  51501. while (namedItem) {
  51502. var parent = namedItem.get('Parent');
  51503. var parentRef = namedItem.getRaw('Parent');
  51504. var name = namedItem.get('T');
  51505. if (name) {
  51506. fieldName.unshift(stringToPDFString(name));
  51507. } else if (parent && ref) {
  51508. // The field name is absent, that means more than one field
  51509. // with the same name may exist. Replacing the empty name
  51510. // with the '`' plus index in the parent's 'Kids' array.
  51511. // This is not in the PDF spec but necessary to id the
  51512. // the input controls.
  51513. var kids = parent.get('Kids');
  51514. var j, jj;
  51515. for (j = 0, jj = kids.length; j < jj; j++) {
  51516. var kidRef = kids[j];
  51517. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  51518. break;
  51519. }
  51520. }
  51521. fieldName.unshift('`' + j);
  51522. }
  51523. namedItem = parent;
  51524. ref = parentRef;
  51525. }
  51526. data.fullName = fieldName.join('.');
  51527. }
  51528. Util.inherit(WidgetAnnotation, Annotation, {
  51529. /**
  51530. * Check if a provided field flag is set.
  51531. *
  51532. * @public
  51533. * @memberof WidgetAnnotation
  51534. * @param {number} flag - Hexadecimal representation for an annotation
  51535. * field characteristic
  51536. * @return {boolean}
  51537. * @see {@link shared/util.js}
  51538. */
  51539. hasFieldFlag: function WidgetAnnotation_hasFieldFlag(flag) {
  51540. return !!(this.data.fieldFlags & flag);
  51541. }
  51542. });
  51543. return WidgetAnnotation;
  51544. }();
  51545. var TextWidgetAnnotation = function TextWidgetAnnotationClosure() {
  51546. function TextWidgetAnnotation(params) {
  51547. WidgetAnnotation.call(this, params);
  51548. // The field value is always a string.
  51549. this.data.fieldValue = stringToPDFString(this.data.fieldValue || '');
  51550. // Determine the alignment of text in the field.
  51551. var alignment = Util.getInheritableProperty(params.dict, 'Q');
  51552. if (!isInt(alignment) || alignment < 0 || alignment > 2) {
  51553. alignment = null;
  51554. }
  51555. this.data.textAlignment = alignment;
  51556. // Determine the maximum length of text in the field.
  51557. var maximumLength = Util.getInheritableProperty(params.dict, 'MaxLen');
  51558. if (!isInt(maximumLength) || maximumLength < 0) {
  51559. maximumLength = null;
  51560. }
  51561. this.data.maxLen = maximumLength;
  51562. // Process field flags for the display layer.
  51563. this.data.multiLine = this.hasFieldFlag(AnnotationFieldFlag.MULTILINE);
  51564. this.data.comb = this.hasFieldFlag(AnnotationFieldFlag.COMB) && !this.hasFieldFlag(AnnotationFieldFlag.MULTILINE) && !this.hasFieldFlag(AnnotationFieldFlag.PASSWORD) && !this.hasFieldFlag(AnnotationFieldFlag.FILESELECT) && this.data.maxLen !== null;
  51565. }
  51566. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  51567. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator, task, renderForms) {
  51568. var operatorList = new OperatorList();
  51569. // Do not render form elements on the canvas when interactive forms are
  51570. // enabled. The display layer is responsible for rendering them instead.
  51571. if (renderForms) {
  51572. return Promise.resolve(operatorList);
  51573. }
  51574. if (this.appearance) {
  51575. return Annotation.prototype.getOperatorList.call(this, evaluator, task, renderForms);
  51576. }
  51577. // Even if there is an appearance stream, ignore it. This is the
  51578. // behaviour used by Adobe Reader.
  51579. if (!this.data.defaultAppearance) {
  51580. return Promise.resolve(operatorList);
  51581. }
  51582. var stream = new Stream(stringToBytes(this.data.defaultAppearance));
  51583. return evaluator.getOperatorList(stream, task, this.fieldResources, operatorList).then(function () {
  51584. return operatorList;
  51585. });
  51586. }
  51587. });
  51588. return TextWidgetAnnotation;
  51589. }();
  51590. var ChoiceWidgetAnnotation = function ChoiceWidgetAnnotationClosure() {
  51591. function ChoiceWidgetAnnotation(params) {
  51592. WidgetAnnotation.call(this, params);
  51593. // Determine the options. The options array may consist of strings or
  51594. // arrays. If the array consists of arrays, then the first element of
  51595. // each array is the export value and the second element of each array is
  51596. // the display value. If the array consists of strings, then these
  51597. // represent both the export and display value. In this case, we convert
  51598. // it to an array of arrays as well for convenience in the display layer.
  51599. this.data.options = [];
  51600. var options = params.dict.getArray('Opt');
  51601. if (isArray(options)) {
  51602. for (var i = 0, ii = options.length; i < ii; i++) {
  51603. var option = options[i];
  51604. this.data.options[i] = {
  51605. exportValue: isArray(option) ? option[0] : option,
  51606. displayValue: isArray(option) ? option[1] : option
  51607. };
  51608. }
  51609. }
  51610. // Determine the field value. In this case, it may be a string or an
  51611. // array of strings. For convenience in the display layer, convert the
  51612. // string to an array of one string as well.
  51613. if (!isArray(this.data.fieldValue)) {
  51614. this.data.fieldValue = [this.data.fieldValue];
  51615. }
  51616. // Process field flags for the display layer.
  51617. this.data.combo = this.hasFieldFlag(AnnotationFieldFlag.COMBO);
  51618. this.data.multiSelect = this.hasFieldFlag(AnnotationFieldFlag.MULTISELECT);
  51619. }
  51620. Util.inherit(ChoiceWidgetAnnotation, WidgetAnnotation, {
  51621. getOperatorList: function ChoiceWidgetAnnotation_getOperatorList(evaluator, task, renderForms) {
  51622. var operatorList = new OperatorList();
  51623. // Do not render form elements on the canvas when interactive forms are
  51624. // enabled. The display layer is responsible for rendering them instead.
  51625. if (renderForms) {
  51626. return Promise.resolve(operatorList);
  51627. }
  51628. return Annotation.prototype.getOperatorList.call(this, evaluator, task, renderForms);
  51629. }
  51630. });
  51631. return ChoiceWidgetAnnotation;
  51632. }();
  51633. var TextAnnotation = function TextAnnotationClosure() {
  51634. var DEFAULT_ICON_SIZE = 22;
  51635. // px
  51636. function TextAnnotation(parameters) {
  51637. Annotation.call(this, parameters);
  51638. this.data.annotationType = AnnotationType.TEXT;
  51639. if (this.data.hasAppearance) {
  51640. this.data.name = 'NoIcon';
  51641. } else {
  51642. this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE;
  51643. this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE;
  51644. this.data.name = parameters.dict.has('Name') ? parameters.dict.get('Name').name : 'Note';
  51645. }
  51646. this._preparePopup(parameters.dict);
  51647. }
  51648. Util.inherit(TextAnnotation, Annotation, {});
  51649. return TextAnnotation;
  51650. }();
  51651. var LinkAnnotation = function LinkAnnotationClosure() {
  51652. function LinkAnnotation(params) {
  51653. Annotation.call(this, params);
  51654. var dict = params.dict;
  51655. var data = this.data;
  51656. data.annotationType = AnnotationType.LINK;
  51657. var action = dict.get('A'), url, dest;
  51658. if (action && isDict(action)) {
  51659. var linkType = action.get('S').name;
  51660. switch (linkType) {
  51661. case 'URI':
  51662. url = action.get('URI');
  51663. if (isName(url)) {
  51664. // Some bad PDFs do not put parentheses around relative URLs.
  51665. url = '/' + url.name;
  51666. } else if (url) {
  51667. url = addDefaultProtocolToUrl(url);
  51668. }
  51669. // TODO: pdf spec mentions urls can be relative to a Base
  51670. // entry in the dictionary.
  51671. break;
  51672. case 'GoTo':
  51673. dest = action.get('D');
  51674. break;
  51675. case 'GoToR':
  51676. var urlDict = action.get('F');
  51677. if (isDict(urlDict)) {
  51678. // We assume that we found a FileSpec dictionary
  51679. // and fetch the URL without checking any further.
  51680. url = urlDict.get('F') || null;
  51681. } else if (isString(urlDict)) {
  51682. url = urlDict;
  51683. }
  51684. // NOTE: the destination is relative to the *remote* document.
  51685. var remoteDest = action.get('D');
  51686. if (remoteDest) {
  51687. if (isName(remoteDest)) {
  51688. remoteDest = remoteDest.name;
  51689. }
  51690. if (isString(url)) {
  51691. var baseUrl = url.split('#')[0];
  51692. if (isString(remoteDest)) {
  51693. // In practice, a named destination may contain only a number.
  51694. // If that happens, use the '#nameddest=' form to avoid the link
  51695. // redirecting to a page, instead of the correct destination.
  51696. url = baseUrl + '#' + (/^\d+$/.test(remoteDest) ? 'nameddest=' : '') + remoteDest;
  51697. } else if (isArray(remoteDest)) {
  51698. url = baseUrl + '#' + JSON.stringify(remoteDest);
  51699. }
  51700. }
  51701. }
  51702. // The 'NewWindow' property, equal to `LinkTarget.BLANK`.
  51703. var newWindow = action.get('NewWindow');
  51704. if (isBool(newWindow)) {
  51705. data.newWindow = newWindow;
  51706. }
  51707. break;
  51708. case 'Named':
  51709. data.action = action.get('N').name;
  51710. break;
  51711. default:
  51712. warn('unrecognized link type: ' + linkType);
  51713. }
  51714. } else if (dict.has('Dest')) {
  51715. // Simple destination link.
  51716. dest = dict.get('Dest');
  51717. }
  51718. if (url) {
  51719. if (isValidUrl(url, /* allowRelative = */
  51720. false)) {
  51721. data.url = tryConvertUrlEncoding(url);
  51722. }
  51723. }
  51724. if (dest) {
  51725. data.dest = isName(dest) ? dest.name : dest;
  51726. }
  51727. }
  51728. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  51729. function addDefaultProtocolToUrl(url) {
  51730. if (isString(url) && url.indexOf('www.') === 0) {
  51731. return 'http://' + url;
  51732. }
  51733. return url;
  51734. }
  51735. function tryConvertUrlEncoding(url) {
  51736. // According to ISO 32000-1:2008, section 12.6.4.7, URIs should be encoded
  51737. // in 7-bit ASCII. Some bad PDFs use UTF-8 encoding, see Bugzilla 1122280.
  51738. try {
  51739. return stringToUTF8String(url);
  51740. } catch (e) {
  51741. return url;
  51742. }
  51743. }
  51744. Util.inherit(LinkAnnotation, Annotation, {});
  51745. return LinkAnnotation;
  51746. }();
  51747. var PopupAnnotation = function PopupAnnotationClosure() {
  51748. function PopupAnnotation(parameters) {
  51749. Annotation.call(this, parameters);
  51750. this.data.annotationType = AnnotationType.POPUP;
  51751. var dict = parameters.dict;
  51752. var parentItem = dict.get('Parent');
  51753. if (!parentItem) {
  51754. warn('Popup annotation has a missing or invalid parent annotation.');
  51755. return;
  51756. }
  51757. this.data.parentId = dict.getRaw('Parent').toString();
  51758. this.data.title = stringToPDFString(parentItem.get('T') || '');
  51759. this.data.contents = stringToPDFString(parentItem.get('Contents') || '');
  51760. if (!parentItem.has('C')) {
  51761. // Fall back to the default background color.
  51762. this.data.color = null;
  51763. } else {
  51764. this.setColor(parentItem.getArray('C'));
  51765. this.data.color = this.color;
  51766. }
  51767. // If the Popup annotation is not viewable, but the parent annotation is,
  51768. // that is most likely a bug. Fallback to inherit the flags from the parent
  51769. // annotation (this is consistent with the behaviour in Adobe Reader).
  51770. if (!this.viewable) {
  51771. var parentFlags = parentItem.get('F');
  51772. if (this._isViewable(parentFlags)) {
  51773. this.setFlags(parentFlags);
  51774. }
  51775. }
  51776. }
  51777. Util.inherit(PopupAnnotation, Annotation, {});
  51778. return PopupAnnotation;
  51779. }();
  51780. var HighlightAnnotation = function HighlightAnnotationClosure() {
  51781. function HighlightAnnotation(parameters) {
  51782. Annotation.call(this, parameters);
  51783. this.data.annotationType = AnnotationType.HIGHLIGHT;
  51784. this._preparePopup(parameters.dict);
  51785. // PDF viewers completely ignore any border styles.
  51786. this.data.borderStyle.setWidth(0);
  51787. }
  51788. Util.inherit(HighlightAnnotation, Annotation, {});
  51789. return HighlightAnnotation;
  51790. }();
  51791. var UnderlineAnnotation = function UnderlineAnnotationClosure() {
  51792. function UnderlineAnnotation(parameters) {
  51793. Annotation.call(this, parameters);
  51794. this.data.annotationType = AnnotationType.UNDERLINE;
  51795. this._preparePopup(parameters.dict);
  51796. // PDF viewers completely ignore any border styles.
  51797. this.data.borderStyle.setWidth(0);
  51798. }
  51799. Util.inherit(UnderlineAnnotation, Annotation, {});
  51800. return UnderlineAnnotation;
  51801. }();
  51802. var SquigglyAnnotation = function SquigglyAnnotationClosure() {
  51803. function SquigglyAnnotation(parameters) {
  51804. Annotation.call(this, parameters);
  51805. this.data.annotationType = AnnotationType.SQUIGGLY;
  51806. this._preparePopup(parameters.dict);
  51807. // PDF viewers completely ignore any border styles.
  51808. this.data.borderStyle.setWidth(0);
  51809. }
  51810. Util.inherit(SquigglyAnnotation, Annotation, {});
  51811. return SquigglyAnnotation;
  51812. }();
  51813. var StrikeOutAnnotation = function StrikeOutAnnotationClosure() {
  51814. function StrikeOutAnnotation(parameters) {
  51815. Annotation.call(this, parameters);
  51816. this.data.annotationType = AnnotationType.STRIKEOUT;
  51817. this._preparePopup(parameters.dict);
  51818. // PDF viewers completely ignore any border styles.
  51819. this.data.borderStyle.setWidth(0);
  51820. }
  51821. Util.inherit(StrikeOutAnnotation, Annotation, {});
  51822. return StrikeOutAnnotation;
  51823. }();
  51824. var FileAttachmentAnnotation = function FileAttachmentAnnotationClosure() {
  51825. function FileAttachmentAnnotation(parameters) {
  51826. Annotation.call(this, parameters);
  51827. var file = new FileSpec(parameters.dict.get('FS'), parameters.xref);
  51828. this.data.annotationType = AnnotationType.FILEATTACHMENT;
  51829. this.data.file = file.serializable;
  51830. this._preparePopup(parameters.dict);
  51831. }
  51832. Util.inherit(FileAttachmentAnnotation, Annotation, {});
  51833. return FileAttachmentAnnotation;
  51834. }();
  51835. exports.Annotation = Annotation;
  51836. exports.AnnotationBorderStyle = AnnotationBorderStyle;
  51837. exports.AnnotationFactory = AnnotationFactory;
  51838. }));
  51839. (function (root, factory) {
  51840. factory(root.pdfjsCoreDocument = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreObj, root.pdfjsCoreParser, root.pdfjsCoreCrypto, root.pdfjsCoreEvaluator, root.pdfjsCoreAnnotation);
  51841. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreObj, coreParser, coreCrypto, coreEvaluator, coreAnnotation) {
  51842. var MissingDataException = sharedUtil.MissingDataException;
  51843. var Util = sharedUtil.Util;
  51844. var assert = sharedUtil.assert;
  51845. var error = sharedUtil.error;
  51846. var info = sharedUtil.info;
  51847. var isArray = sharedUtil.isArray;
  51848. var isArrayBuffer = sharedUtil.isArrayBuffer;
  51849. var isString = sharedUtil.isString;
  51850. var shadow = sharedUtil.shadow;
  51851. var stringToBytes = sharedUtil.stringToBytes;
  51852. var stringToPDFString = sharedUtil.stringToPDFString;
  51853. var warn = sharedUtil.warn;
  51854. var isSpace = sharedUtil.isSpace;
  51855. var Dict = corePrimitives.Dict;
  51856. var isDict = corePrimitives.isDict;
  51857. var isName = corePrimitives.isName;
  51858. var isStream = corePrimitives.isStream;
  51859. var NullStream = coreStream.NullStream;
  51860. var Stream = coreStream.Stream;
  51861. var StreamsSequenceStream = coreStream.StreamsSequenceStream;
  51862. var Catalog = coreObj.Catalog;
  51863. var ObjectLoader = coreObj.ObjectLoader;
  51864. var XRef = coreObj.XRef;
  51865. var Linearization = coreParser.Linearization;
  51866. var calculateMD5 = coreCrypto.calculateMD5;
  51867. var OperatorList = coreEvaluator.OperatorList;
  51868. var PartialEvaluator = coreEvaluator.PartialEvaluator;
  51869. var Annotation = coreAnnotation.Annotation;
  51870. var AnnotationFactory = coreAnnotation.AnnotationFactory;
  51871. var Page = function PageClosure() {
  51872. var LETTER_SIZE_MEDIABOX = [
  51873. 0,
  51874. 0,
  51875. 612,
  51876. 792
  51877. ];
  51878. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  51879. this.pdfManager = pdfManager;
  51880. this.pageIndex = pageIndex;
  51881. this.pageDict = pageDict;
  51882. this.xref = xref;
  51883. this.ref = ref;
  51884. this.fontCache = fontCache;
  51885. this.uniquePrefix = 'p' + this.pageIndex + '_';
  51886. this.idCounters = { obj: 0 };
  51887. this.evaluatorOptions = pdfManager.evaluatorOptions;
  51888. this.resourcesPromise = null;
  51889. }
  51890. Page.prototype = {
  51891. getPageProp: function Page_getPageProp(key) {
  51892. return this.pageDict.get(key);
  51893. },
  51894. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  51895. var dict = this.pageDict, valueArray = null, loopCount = 0;
  51896. var MAX_LOOP_COUNT = 100;
  51897. // Always walk up the entire parent chain, to be able to find
  51898. // e.g. \Resources placed on multiple levels of the tree.
  51899. while (dict) {
  51900. var value = dict.get(key);
  51901. if (value) {
  51902. if (!valueArray) {
  51903. valueArray = [];
  51904. }
  51905. valueArray.push(value);
  51906. }
  51907. if (++loopCount > MAX_LOOP_COUNT) {
  51908. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  51909. break;
  51910. }
  51911. dict = dict.get('Parent');
  51912. }
  51913. if (!valueArray) {
  51914. return Dict.empty;
  51915. }
  51916. if (valueArray.length === 1 || !isDict(valueArray[0]) || loopCount > MAX_LOOP_COUNT) {
  51917. return valueArray[0];
  51918. }
  51919. return Dict.merge(this.xref, valueArray);
  51920. },
  51921. get content() {
  51922. return this.getPageProp('Contents');
  51923. },
  51924. get resources() {
  51925. // For robustness: The spec states that a \Resources entry has to be
  51926. // present, but can be empty. Some document omit it still, in this case
  51927. // we return an empty dictionary.
  51928. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  51929. },
  51930. get mediaBox() {
  51931. var obj = this.getInheritedPageProp('MediaBox');
  51932. // Reset invalid media box to letter size.
  51933. if (!isArray(obj) || obj.length !== 4) {
  51934. obj = LETTER_SIZE_MEDIABOX;
  51935. }
  51936. return shadow(this, 'mediaBox', obj);
  51937. },
  51938. get view() {
  51939. var mediaBox = this.mediaBox;
  51940. var cropBox = this.getInheritedPageProp('CropBox');
  51941. if (!isArray(cropBox) || cropBox.length !== 4) {
  51942. return shadow(this, 'view', mediaBox);
  51943. }
  51944. // From the spec, 6th ed., p.963:
  51945. // "The crop, bleed, trim, and art boxes should not ordinarily
  51946. // extend beyond the boundaries of the media box. If they do, they are
  51947. // effectively reduced to their intersection with the media box."
  51948. cropBox = Util.intersect(cropBox, mediaBox);
  51949. if (!cropBox) {
  51950. return shadow(this, 'view', mediaBox);
  51951. }
  51952. return shadow(this, 'view', cropBox);
  51953. },
  51954. get rotate() {
  51955. var rotate = this.getInheritedPageProp('Rotate') || 0;
  51956. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  51957. if (rotate % 90 !== 0) {
  51958. rotate = 0;
  51959. } else if (rotate >= 360) {
  51960. rotate = rotate % 360;
  51961. } else if (rotate < 0) {
  51962. // The spec doesn't cover negatives, assume its counterclockwise
  51963. // rotation. The following is the other implementation of modulo.
  51964. rotate = (rotate % 360 + 360) % 360;
  51965. }
  51966. return shadow(this, 'rotate', rotate);
  51967. },
  51968. getContentStream: function Page_getContentStream() {
  51969. var content = this.content;
  51970. var stream;
  51971. if (isArray(content)) {
  51972. // fetching items
  51973. var xref = this.xref;
  51974. var i, n = content.length;
  51975. var streams = [];
  51976. for (i = 0; i < n; ++i) {
  51977. streams.push(xref.fetchIfRef(content[i]));
  51978. }
  51979. stream = new StreamsSequenceStream(streams);
  51980. } else if (isStream(content)) {
  51981. stream = content;
  51982. } else {
  51983. // replacing non-existent page content with empty one
  51984. stream = new NullStream();
  51985. }
  51986. return stream;
  51987. },
  51988. loadResources: function Page_loadResources(keys) {
  51989. if (!this.resourcesPromise) {
  51990. // TODO: add async getInheritedPageProp and remove this.
  51991. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  51992. }
  51993. return this.resourcesPromise.then(function resourceSuccess() {
  51994. var objectLoader = new ObjectLoader(this.resources.map, keys, this.xref);
  51995. return objectLoader.load();
  51996. }.bind(this));
  51997. },
  51998. getOperatorList: function Page_getOperatorList(handler, task, intent, renderInteractiveForms) {
  51999. var self = this;
  52000. var pdfManager = this.pdfManager;
  52001. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream', []);
  52002. var resourcesPromise = this.loadResources([
  52003. 'ExtGState',
  52004. 'ColorSpace',
  52005. 'Pattern',
  52006. 'Shading',
  52007. 'XObject',
  52008. 'Font'
  52009. ]);
  52010. // ProcSet
  52011. // Properties
  52012. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref, handler, this.pageIndex, this.uniquePrefix, this.idCounters, this.fontCache, this.evaluatorOptions);
  52013. var dataPromises = Promise.all([
  52014. contentStreamPromise,
  52015. resourcesPromise
  52016. ]);
  52017. var pageListPromise = dataPromises.then(function (data) {
  52018. var contentStream = data[0];
  52019. var opList = new OperatorList(intent, handler, self.pageIndex);
  52020. handler.send('StartRenderPage', {
  52021. transparency: partialEvaluator.hasBlendModes(self.resources),
  52022. pageIndex: self.pageIndex,
  52023. intent: intent
  52024. });
  52025. return partialEvaluator.getOperatorList(contentStream, task, self.resources, opList).then(function () {
  52026. return opList;
  52027. });
  52028. });
  52029. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  52030. return Promise.all([
  52031. pageListPromise,
  52032. annotationsPromise
  52033. ]).then(function (datas) {
  52034. var pageOpList = datas[0];
  52035. var annotations = datas[1];
  52036. if (annotations.length === 0) {
  52037. pageOpList.flush(true);
  52038. return pageOpList;
  52039. }
  52040. var annotationsReadyPromise = Annotation.appendToOperatorList(annotations, pageOpList, partialEvaluator, task, intent, renderInteractiveForms);
  52041. return annotationsReadyPromise.then(function () {
  52042. pageOpList.flush(true);
  52043. return pageOpList;
  52044. });
  52045. });
  52046. },
  52047. extractTextContent: function Page_extractTextContent(task, normalizeWhitespace, combineTextItems) {
  52048. var handler = {
  52049. on: function nullHandlerOn() {
  52050. },
  52051. send: function nullHandlerSend() {
  52052. }
  52053. };
  52054. var self = this;
  52055. var pdfManager = this.pdfManager;
  52056. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream', []);
  52057. var resourcesPromise = this.loadResources([
  52058. 'ExtGState',
  52059. 'XObject',
  52060. 'Font'
  52061. ]);
  52062. var dataPromises = Promise.all([
  52063. contentStreamPromise,
  52064. resourcesPromise
  52065. ]);
  52066. return dataPromises.then(function (data) {
  52067. var contentStream = data[0];
  52068. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref, handler, self.pageIndex, self.uniquePrefix, self.idCounters, self.fontCache, self.evaluatorOptions);
  52069. return partialEvaluator.getTextContent(contentStream, task, self.resources, /* stateManager = */
  52070. null, normalizeWhitespace, combineTextItems);
  52071. });
  52072. },
  52073. getAnnotationsData: function Page_getAnnotationsData(intent) {
  52074. var annotations = this.annotations;
  52075. var annotationsData = [];
  52076. for (var i = 0, n = annotations.length; i < n; ++i) {
  52077. if (intent) {
  52078. if (!(intent === 'display' && annotations[i].viewable) && !(intent === 'print' && annotations[i].printable)) {
  52079. continue;
  52080. }
  52081. }
  52082. annotationsData.push(annotations[i].data);
  52083. }
  52084. return annotationsData;
  52085. },
  52086. get annotations() {
  52087. var annotations = [];
  52088. var annotationRefs = this.getInheritedPageProp('Annots') || [];
  52089. var annotationFactory = new AnnotationFactory();
  52090. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  52091. var annotationRef = annotationRefs[i];
  52092. var annotation = annotationFactory.create(this.xref, annotationRef, this.uniquePrefix, this.idCounters);
  52093. if (annotation) {
  52094. annotations.push(annotation);
  52095. }
  52096. }
  52097. return shadow(this, 'annotations', annotations);
  52098. }
  52099. };
  52100. return Page;
  52101. }();
  52102. /**
  52103. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  52104. * `PDFDoc`, this one doesn't have any job management code.
  52105. * Right now there exists one PDFDocument on the main thread + one object
  52106. * for each worker. If there is no worker support enabled, there are two
  52107. * `PDFDocument` objects on the main thread created.
  52108. */
  52109. var PDFDocument = function PDFDocumentClosure() {
  52110. var FINGERPRINT_FIRST_BYTES = 1024;
  52111. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' + '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  52112. function PDFDocument(pdfManager, arg, password) {
  52113. if (isStream(arg)) {
  52114. init.call(this, pdfManager, arg, password);
  52115. } else if (isArrayBuffer(arg)) {
  52116. init.call(this, pdfManager, new Stream(arg), password);
  52117. } else {
  52118. error('PDFDocument: Unknown argument type');
  52119. }
  52120. }
  52121. function init(pdfManager, stream, password) {
  52122. assert(stream.length > 0, 'stream must have data');
  52123. this.pdfManager = pdfManager;
  52124. this.stream = stream;
  52125. var xref = new XRef(this.stream, password, pdfManager);
  52126. this.xref = xref;
  52127. }
  52128. function find(stream, needle, limit, backwards) {
  52129. var pos = stream.pos;
  52130. var end = stream.end;
  52131. var strBuf = [];
  52132. if (pos + limit > end) {
  52133. limit = end - pos;
  52134. }
  52135. for (var n = 0; n < limit; ++n) {
  52136. strBuf.push(String.fromCharCode(stream.getByte()));
  52137. }
  52138. var str = strBuf.join('');
  52139. stream.pos = pos;
  52140. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  52141. if (index === -1) {
  52142. return false;
  52143. }
  52144. /* not found */
  52145. stream.pos += index;
  52146. return true;
  52147. }
  52148. /* found */
  52149. var DocumentInfoValidators = {
  52150. get entries() {
  52151. // Lazily build this since all the validation functions below are not
  52152. // defined until after this file loads.
  52153. return shadow(this, 'entries', {
  52154. Title: isString,
  52155. Author: isString,
  52156. Subject: isString,
  52157. Keywords: isString,
  52158. Creator: isString,
  52159. Producer: isString,
  52160. CreationDate: isString,
  52161. ModDate: isString,
  52162. Trapped: isName
  52163. });
  52164. }
  52165. };
  52166. PDFDocument.prototype = {
  52167. parse: function PDFDocument_parse(recoveryMode) {
  52168. this.setup(recoveryMode);
  52169. var version = this.catalog.catDict.get('Version');
  52170. if (isName(version)) {
  52171. this.pdfFormatVersion = version.name;
  52172. }
  52173. try {
  52174. // checking if AcroForm is present
  52175. this.acroForm = this.catalog.catDict.get('AcroForm');
  52176. if (this.acroForm) {
  52177. this.xfa = this.acroForm.get('XFA');
  52178. var fields = this.acroForm.get('Fields');
  52179. if ((!fields || !isArray(fields) || fields.length === 0) && !this.xfa) {
  52180. // no fields and no XFA -- not a form (?)
  52181. this.acroForm = null;
  52182. }
  52183. }
  52184. } catch (ex) {
  52185. info('Something wrong with AcroForm entry');
  52186. this.acroForm = null;
  52187. }
  52188. },
  52189. get linearization() {
  52190. var linearization = null;
  52191. if (this.stream.length) {
  52192. try {
  52193. linearization = Linearization.create(this.stream);
  52194. } catch (err) {
  52195. if (err instanceof MissingDataException) {
  52196. throw err;
  52197. }
  52198. info(err);
  52199. }
  52200. }
  52201. // shadow the prototype getter with a data property
  52202. return shadow(this, 'linearization', linearization);
  52203. },
  52204. get startXRef() {
  52205. var stream = this.stream;
  52206. var startXRef = 0;
  52207. var linearization = this.linearization;
  52208. if (linearization) {
  52209. // Find end of first obj.
  52210. stream.reset();
  52211. if (find(stream, 'endobj', 1024)) {
  52212. startXRef = stream.pos + 6;
  52213. }
  52214. } else {
  52215. // Find startxref by jumping backward from the end of the file.
  52216. var step = 1024;
  52217. var found = false, pos = stream.end;
  52218. while (!found && pos > 0) {
  52219. pos -= step - 'startxref'.length;
  52220. if (pos < 0) {
  52221. pos = 0;
  52222. }
  52223. stream.pos = pos;
  52224. found = find(stream, 'startxref', step, true);
  52225. }
  52226. if (found) {
  52227. stream.skip(9);
  52228. var ch;
  52229. do {
  52230. ch = stream.getByte();
  52231. } while (isSpace(ch));
  52232. var str = '';
  52233. while (ch >= 0x20 && ch <= 0x39) {
  52234. // < '9'
  52235. str += String.fromCharCode(ch);
  52236. ch = stream.getByte();
  52237. }
  52238. startXRef = parseInt(str, 10);
  52239. if (isNaN(startXRef)) {
  52240. startXRef = 0;
  52241. }
  52242. }
  52243. }
  52244. // shadow the prototype getter with a data property
  52245. return shadow(this, 'startXRef', startXRef);
  52246. },
  52247. get mainXRefEntriesOffset() {
  52248. var mainXRefEntriesOffset = 0;
  52249. var linearization = this.linearization;
  52250. if (linearization) {
  52251. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  52252. }
  52253. // shadow the prototype getter with a data property
  52254. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  52255. },
  52256. // Find the header, remove leading garbage and setup the stream
  52257. // starting from the header.
  52258. checkHeader: function PDFDocument_checkHeader() {
  52259. var stream = this.stream;
  52260. stream.reset();
  52261. if (find(stream, '%PDF-', 1024)) {
  52262. // Found the header, trim off any garbage before it.
  52263. stream.moveStart();
  52264. // Reading file format version
  52265. var MAX_VERSION_LENGTH = 12;
  52266. var version = '', ch;
  52267. while ((ch = stream.getByte()) > 0x20) {
  52268. // SPACE
  52269. if (version.length >= MAX_VERSION_LENGTH) {
  52270. break;
  52271. }
  52272. version += String.fromCharCode(ch);
  52273. }
  52274. if (!this.pdfFormatVersion) {
  52275. // removing "%PDF-"-prefix
  52276. this.pdfFormatVersion = version.substring(5);
  52277. }
  52278. return;
  52279. }
  52280. },
  52281. // May not be a PDF file, continue anyway.
  52282. parseStartXRef: function PDFDocument_parseStartXRef() {
  52283. var startXRef = this.startXRef;
  52284. this.xref.setStartXRef(startXRef);
  52285. },
  52286. setup: function PDFDocument_setup(recoveryMode) {
  52287. this.xref.parse(recoveryMode);
  52288. var self = this;
  52289. var pageFactory = {
  52290. createPage: function (pageIndex, dict, ref, fontCache) {
  52291. return new Page(self.pdfManager, self.xref, pageIndex, dict, ref, fontCache);
  52292. }
  52293. };
  52294. this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);
  52295. },
  52296. get numPages() {
  52297. var linearization = this.linearization;
  52298. var num = linearization ? linearization.numPages : this.catalog.numPages;
  52299. // shadow the prototype getter
  52300. return shadow(this, 'numPages', num);
  52301. },
  52302. get documentInfo() {
  52303. var docInfo = {
  52304. PDFFormatVersion: this.pdfFormatVersion,
  52305. IsAcroFormPresent: !!this.acroForm,
  52306. IsXFAPresent: !!this.xfa
  52307. };
  52308. var infoDict;
  52309. try {
  52310. infoDict = this.xref.trailer.get('Info');
  52311. } catch (err) {
  52312. info('The document information dictionary is invalid.');
  52313. }
  52314. if (infoDict) {
  52315. var validEntries = DocumentInfoValidators.entries;
  52316. // Only fill the document info with valid entries from the spec.
  52317. for (var key in validEntries) {
  52318. if (infoDict.has(key)) {
  52319. var value = infoDict.get(key);
  52320. // Make sure the value conforms to the spec.
  52321. if (validEntries[key](value)) {
  52322. docInfo[key] = typeof value !== 'string' ? value : stringToPDFString(value);
  52323. } else {
  52324. info('Bad value in document info for "' + key + '"');
  52325. }
  52326. }
  52327. }
  52328. }
  52329. return shadow(this, 'documentInfo', docInfo);
  52330. },
  52331. get fingerprint() {
  52332. var xref = this.xref, hash, fileID = '';
  52333. var idArray = xref.trailer.get('ID');
  52334. if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) && idArray[0] !== EMPTY_FINGERPRINT) {
  52335. hash = stringToBytes(idArray[0]);
  52336. } else {
  52337. if (this.stream.ensureRange) {
  52338. this.stream.ensureRange(0, Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  52339. }
  52340. hash = calculateMD5(this.stream.bytes.subarray(0, FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  52341. }
  52342. for (var i = 0, n = hash.length; i < n; i++) {
  52343. var hex = hash[i].toString(16);
  52344. fileID += hex.length === 1 ? '0' + hex : hex;
  52345. }
  52346. return shadow(this, 'fingerprint', fileID);
  52347. },
  52348. getPage: function PDFDocument_getPage(pageIndex) {
  52349. return this.catalog.getPage(pageIndex);
  52350. },
  52351. cleanup: function PDFDocument_cleanup() {
  52352. return this.catalog.cleanup();
  52353. }
  52354. };
  52355. return PDFDocument;
  52356. }();
  52357. exports.Page = Page;
  52358. exports.PDFDocument = PDFDocument;
  52359. }));
  52360. (function (root, factory) {
  52361. factory(root.pdfjsCorePdfManager = {}, root.pdfjsSharedUtil, root.pdfjsCoreStream, root.pdfjsCoreChunkedStream, root.pdfjsCoreDocument);
  52362. }(this, function (exports, sharedUtil, coreStream, coreChunkedStream, coreDocument) {
  52363. var NotImplementedException = sharedUtil.NotImplementedException;
  52364. var MissingDataException = sharedUtil.MissingDataException;
  52365. var createPromiseCapability = sharedUtil.createPromiseCapability;
  52366. var Util = sharedUtil.Util;
  52367. var Stream = coreStream.Stream;
  52368. var ChunkedStreamManager = coreChunkedStream.ChunkedStreamManager;
  52369. var PDFDocument = coreDocument.PDFDocument;
  52370. var BasePdfManager = function BasePdfManagerClosure() {
  52371. function BasePdfManager() {
  52372. throw new Error('Cannot initialize BaseManagerManager');
  52373. }
  52374. BasePdfManager.prototype = {
  52375. get docId() {
  52376. return this._docId;
  52377. },
  52378. onLoadedStream: function BasePdfManager_onLoadedStream() {
  52379. throw new NotImplementedException();
  52380. },
  52381. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  52382. return this.ensure(this.pdfDocument, prop, args);
  52383. },
  52384. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  52385. return this.ensure(this.pdfDocument.xref, prop, args);
  52386. },
  52387. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  52388. return this.ensure(this.pdfDocument.catalog, prop, args);
  52389. },
  52390. getPage: function BasePdfManager_getPage(pageIndex) {
  52391. return this.pdfDocument.getPage(pageIndex);
  52392. },
  52393. cleanup: function BasePdfManager_cleanup() {
  52394. return this.pdfDocument.cleanup();
  52395. },
  52396. ensure: function BasePdfManager_ensure(obj, prop, args) {
  52397. return new NotImplementedException();
  52398. },
  52399. requestRange: function BasePdfManager_requestRange(begin, end) {
  52400. return new NotImplementedException();
  52401. },
  52402. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  52403. return new NotImplementedException();
  52404. },
  52405. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  52406. return new NotImplementedException();
  52407. },
  52408. updatePassword: function BasePdfManager_updatePassword(password) {
  52409. this.pdfDocument.xref.password = this.password = password;
  52410. if (this._passwordChangedCapability) {
  52411. this._passwordChangedCapability.resolve();
  52412. }
  52413. },
  52414. passwordChanged: function BasePdfManager_passwordChanged() {
  52415. this._passwordChangedCapability = createPromiseCapability();
  52416. return this._passwordChangedCapability.promise;
  52417. },
  52418. terminate: function BasePdfManager_terminate() {
  52419. return new NotImplementedException();
  52420. }
  52421. };
  52422. return BasePdfManager;
  52423. }();
  52424. var LocalPdfManager = function LocalPdfManagerClosure() {
  52425. function LocalPdfManager(docId, data, password, evaluatorOptions) {
  52426. this._docId = docId;
  52427. this.evaluatorOptions = evaluatorOptions;
  52428. var stream = new Stream(data);
  52429. this.pdfDocument = new PDFDocument(this, stream, password);
  52430. this._loadedStreamCapability = createPromiseCapability();
  52431. this._loadedStreamCapability.resolve(stream);
  52432. }
  52433. Util.inherit(LocalPdfManager, BasePdfManager, {
  52434. ensure: function LocalPdfManager_ensure(obj, prop, args) {
  52435. return new Promise(function (resolve, reject) {
  52436. try {
  52437. var value = obj[prop];
  52438. var result;
  52439. if (typeof value === 'function') {
  52440. result = value.apply(obj, args);
  52441. } else {
  52442. result = value;
  52443. }
  52444. resolve(result);
  52445. } catch (e) {
  52446. reject(e);
  52447. }
  52448. });
  52449. },
  52450. requestRange: function LocalPdfManager_requestRange(begin, end) {
  52451. return Promise.resolve();
  52452. },
  52453. requestLoadedStream: function LocalPdfManager_requestLoadedStream() {
  52454. return;
  52455. },
  52456. onLoadedStream: function LocalPdfManager_onLoadedStream() {
  52457. return this._loadedStreamCapability.promise;
  52458. },
  52459. terminate: function LocalPdfManager_terminate() {
  52460. return;
  52461. }
  52462. });
  52463. return LocalPdfManager;
  52464. }();
  52465. var NetworkPdfManager = function NetworkPdfManagerClosure() {
  52466. function NetworkPdfManager(docId, pdfNetworkStream, args, evaluatorOptions) {
  52467. this._docId = docId;
  52468. this.msgHandler = args.msgHandler;
  52469. this.evaluatorOptions = evaluatorOptions;
  52470. var params = {
  52471. msgHandler: args.msgHandler,
  52472. url: args.url,
  52473. length: args.length,
  52474. disableAutoFetch: args.disableAutoFetch,
  52475. rangeChunkSize: args.rangeChunkSize
  52476. };
  52477. this.streamManager = new ChunkedStreamManager(pdfNetworkStream, params);
  52478. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(), args.password);
  52479. }
  52480. Util.inherit(NetworkPdfManager, BasePdfManager, {
  52481. ensure: function NetworkPdfManager_ensure(obj, prop, args) {
  52482. var pdfManager = this;
  52483. return new Promise(function (resolve, reject) {
  52484. function ensureHelper() {
  52485. try {
  52486. var result;
  52487. var value = obj[prop];
  52488. if (typeof value === 'function') {
  52489. result = value.apply(obj, args);
  52490. } else {
  52491. result = value;
  52492. }
  52493. resolve(result);
  52494. } catch (e) {
  52495. if (!(e instanceof MissingDataException)) {
  52496. reject(e);
  52497. return;
  52498. }
  52499. pdfManager.streamManager.requestRange(e.begin, e.end).then(ensureHelper, reject);
  52500. }
  52501. }
  52502. ensureHelper();
  52503. });
  52504. },
  52505. requestRange: function NetworkPdfManager_requestRange(begin, end) {
  52506. return this.streamManager.requestRange(begin, end);
  52507. },
  52508. requestLoadedStream: function NetworkPdfManager_requestLoadedStream() {
  52509. this.streamManager.requestAllChunks();
  52510. },
  52511. sendProgressiveData: function NetworkPdfManager_sendProgressiveData(chunk) {
  52512. this.streamManager.onReceiveData({ chunk: chunk });
  52513. },
  52514. onLoadedStream: function NetworkPdfManager_onLoadedStream() {
  52515. return this.streamManager.onLoadedStream();
  52516. },
  52517. terminate: function NetworkPdfManager_terminate() {
  52518. this.streamManager.abort();
  52519. }
  52520. });
  52521. return NetworkPdfManager;
  52522. }();
  52523. exports.LocalPdfManager = LocalPdfManager;
  52524. exports.NetworkPdfManager = NetworkPdfManager;
  52525. }));
  52526. (function (root, factory) {
  52527. factory(root.pdfjsCoreWorker = {}, root.pdfjsSharedUtil, root.pdfjsCorePrimitives, root.pdfjsCorePdfManager);
  52528. }(this, function (exports, sharedUtil, corePrimitives, corePdfManager) {
  52529. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  52530. var InvalidPDFException = sharedUtil.InvalidPDFException;
  52531. var MessageHandler = sharedUtil.MessageHandler;
  52532. var MissingPDFException = sharedUtil.MissingPDFException;
  52533. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  52534. var PasswordException = sharedUtil.PasswordException;
  52535. var PasswordResponses = sharedUtil.PasswordResponses;
  52536. var UnknownErrorException = sharedUtil.UnknownErrorException;
  52537. var XRefParseException = sharedUtil.XRefParseException;
  52538. var arrayByteLength = sharedUtil.arrayByteLength;
  52539. var arraysToBytes = sharedUtil.arraysToBytes;
  52540. var assert = sharedUtil.assert;
  52541. var createPromiseCapability = sharedUtil.createPromiseCapability;
  52542. var error = sharedUtil.error;
  52543. var info = sharedUtil.info;
  52544. var warn = sharedUtil.warn;
  52545. var setVerbosityLevel = sharedUtil.setVerbosityLevel;
  52546. var Ref = corePrimitives.Ref;
  52547. var LocalPdfManager = corePdfManager.LocalPdfManager;
  52548. var NetworkPdfManager = corePdfManager.NetworkPdfManager;
  52549. var globalScope = sharedUtil.globalScope;
  52550. var WorkerTask = function WorkerTaskClosure() {
  52551. function WorkerTask(name) {
  52552. this.name = name;
  52553. this.terminated = false;
  52554. this._capability = createPromiseCapability();
  52555. }
  52556. WorkerTask.prototype = {
  52557. get finished() {
  52558. return this._capability.promise;
  52559. },
  52560. finish: function () {
  52561. this._capability.resolve();
  52562. },
  52563. terminate: function () {
  52564. this.terminated = true;
  52565. },
  52566. ensureNotTerminated: function () {
  52567. if (this.terminated) {
  52568. throw new Error('Worker task was terminated');
  52569. }
  52570. }
  52571. };
  52572. return WorkerTask;
  52573. }();
  52574. /** @implements {IPDFStream} */
  52575. var PDFWorkerStream = function PDFWorkerStreamClosure() {
  52576. function PDFWorkerStream(params, msgHandler) {
  52577. this._queuedChunks = [];
  52578. var initialData = params.initialData;
  52579. if (initialData && initialData.length > 0) {
  52580. this._queuedChunks.push(initialData);
  52581. }
  52582. this._msgHandler = msgHandler;
  52583. this._isRangeSupported = !params.disableRange;
  52584. this._isStreamingSupported = !params.disableStream;
  52585. this._contentLength = params.length;
  52586. this._fullRequestReader = null;
  52587. this._rangeReaders = [];
  52588. msgHandler.on('OnDataRange', this._onReceiveData.bind(this));
  52589. msgHandler.on('OnDataProgress', this._onProgress.bind(this));
  52590. }
  52591. PDFWorkerStream.prototype = {
  52592. _onReceiveData: function PDFWorkerStream_onReceiveData(args) {
  52593. if (args.begin === undefined) {
  52594. if (this._fullRequestReader) {
  52595. this._fullRequestReader._enqueue(args.chunk);
  52596. } else {
  52597. this._queuedChunks.push(args.chunk);
  52598. }
  52599. } else {
  52600. var found = this._rangeReaders.some(function (rangeReader) {
  52601. if (rangeReader._begin !== args.begin) {
  52602. return false;
  52603. }
  52604. rangeReader._enqueue(args.chunk);
  52605. return true;
  52606. });
  52607. assert(found);
  52608. }
  52609. },
  52610. _onProgress: function PDFWorkerStream_onProgress(evt) {
  52611. if (this._rangeReaders.length > 0) {
  52612. // Reporting to first range reader.
  52613. var firstReader = this._rangeReaders[0];
  52614. if (firstReader.onProgress) {
  52615. firstReader.onProgress({ loaded: evt.loaded });
  52616. }
  52617. }
  52618. },
  52619. _removeRangeReader: function PDFWorkerStream_removeRangeReader(reader) {
  52620. var i = this._rangeReaders.indexOf(reader);
  52621. if (i >= 0) {
  52622. this._rangeReaders.splice(i, 1);
  52623. }
  52624. },
  52625. getFullReader: function PDFWorkerStream_getFullReader() {
  52626. assert(!this._fullRequestReader);
  52627. var queuedChunks = this._queuedChunks;
  52628. this._queuedChunks = null;
  52629. return new PDFWorkerStreamReader(this, queuedChunks);
  52630. },
  52631. getRangeReader: function PDFWorkerStream_getRangeReader(begin, end) {
  52632. var reader = new PDFWorkerStreamRangeReader(this, begin, end);
  52633. this._msgHandler.send('RequestDataRange', {
  52634. begin: begin,
  52635. end: end
  52636. });
  52637. this._rangeReaders.push(reader);
  52638. return reader;
  52639. },
  52640. cancelAllRequests: function PDFWorkerStream_cancelAllRequests(reason) {
  52641. if (this._fullRequestReader) {
  52642. this._fullRequestReader.cancel(reason);
  52643. }
  52644. var readers = this._rangeReaders.slice(0);
  52645. readers.forEach(function (rangeReader) {
  52646. rangeReader.cancel(reason);
  52647. });
  52648. }
  52649. };
  52650. /** @implements {IPDFStreamReader} */
  52651. function PDFWorkerStreamReader(stream, queuedChunks) {
  52652. this._stream = stream;
  52653. this._done = false;
  52654. this._queuedChunks = queuedChunks || [];
  52655. this._requests = [];
  52656. this._headersReady = Promise.resolve();
  52657. stream._fullRequestReader = this;
  52658. this.onProgress = null;
  52659. }
  52660. // not used
  52661. PDFWorkerStreamReader.prototype = {
  52662. _enqueue: function PDFWorkerStreamReader_enqueue(chunk) {
  52663. if (this._done) {
  52664. return;
  52665. }
  52666. // ignore new data
  52667. if (this._requests.length > 0) {
  52668. var requestCapability = this._requests.shift();
  52669. requestCapability.resolve({
  52670. value: chunk,
  52671. done: false
  52672. });
  52673. return;
  52674. }
  52675. this._queuedChunks.push(chunk);
  52676. },
  52677. get headersReady() {
  52678. return this._headersReady;
  52679. },
  52680. get isRangeSupported() {
  52681. return this._stream._isRangeSupported;
  52682. },
  52683. get isStreamingSupported() {
  52684. return this._stream._isStreamingSupported;
  52685. },
  52686. get contentLength() {
  52687. return this._stream._contentLength;
  52688. },
  52689. read: function PDFWorkerStreamReader_read() {
  52690. if (this._queuedChunks.length > 0) {
  52691. var chunk = this._queuedChunks.shift();
  52692. return Promise.resolve({
  52693. value: chunk,
  52694. done: false
  52695. });
  52696. }
  52697. if (this._done) {
  52698. return Promise.resolve({
  52699. value: undefined,
  52700. done: true
  52701. });
  52702. }
  52703. var requestCapability = createPromiseCapability();
  52704. this._requests.push(requestCapability);
  52705. return requestCapability.promise;
  52706. },
  52707. cancel: function PDFWorkerStreamReader_cancel(reason) {
  52708. this._done = true;
  52709. this._requests.forEach(function (requestCapability) {
  52710. requestCapability.resolve({
  52711. value: undefined,
  52712. done: true
  52713. });
  52714. });
  52715. this._requests = [];
  52716. }
  52717. };
  52718. /** @implements {IPDFStreamRangeReader} */
  52719. function PDFWorkerStreamRangeReader(stream, begin, end) {
  52720. this._stream = stream;
  52721. this._begin = begin;
  52722. this._end = end;
  52723. this._queuedChunk = null;
  52724. this._requests = [];
  52725. this._done = false;
  52726. this.onProgress = null;
  52727. }
  52728. PDFWorkerStreamRangeReader.prototype = {
  52729. _enqueue: function PDFWorkerStreamRangeReader_enqueue(chunk) {
  52730. if (this._done) {
  52731. return;
  52732. }
  52733. // ignore new data
  52734. if (this._requests.length === 0) {
  52735. this._queuedChunk = chunk;
  52736. } else {
  52737. var requestsCapability = this._requests.shift();
  52738. requestsCapability.resolve({
  52739. value: chunk,
  52740. done: false
  52741. });
  52742. this._requests.forEach(function (requestCapability) {
  52743. requestCapability.resolve({
  52744. value: undefined,
  52745. done: true
  52746. });
  52747. });
  52748. this._requests = [];
  52749. }
  52750. this._done = true;
  52751. this._stream._removeRangeReader(this);
  52752. },
  52753. get isStreamingSupported() {
  52754. return false;
  52755. },
  52756. read: function PDFWorkerStreamRangeReader_read() {
  52757. if (this._queuedChunk) {
  52758. return Promise.resolve({
  52759. value: this._queuedChunk,
  52760. done: false
  52761. });
  52762. }
  52763. if (this._done) {
  52764. return Promise.resolve({
  52765. value: undefined,
  52766. done: true
  52767. });
  52768. }
  52769. var requestCapability = createPromiseCapability();
  52770. this._requests.push(requestCapability);
  52771. return requestCapability.promise;
  52772. },
  52773. cancel: function PDFWorkerStreamRangeReader_cancel(reason) {
  52774. this._done = true;
  52775. this._requests.forEach(function (requestCapability) {
  52776. requestCapability.resolve({
  52777. value: undefined,
  52778. done: true
  52779. });
  52780. });
  52781. this._requests = [];
  52782. this._stream._removeRangeReader(this);
  52783. }
  52784. };
  52785. return PDFWorkerStream;
  52786. }();
  52787. /** @type IPDFStream */
  52788. var PDFNetworkStream;
  52789. /**
  52790. * Sets PDFNetworkStream class to be used as alternative PDF data transport.
  52791. * @param {IPDFStream} cls - the PDF data transport.
  52792. */
  52793. function setPDFNetworkStreamClass(cls) {
  52794. PDFNetworkStream = cls;
  52795. }
  52796. var WorkerMessageHandler = {
  52797. setup: function wphSetup(handler, port) {
  52798. var testMessageProcessed = false;
  52799. handler.on('test', function wphSetupTest(data) {
  52800. if (testMessageProcessed) {
  52801. return;
  52802. }
  52803. // we already processed 'test' message once
  52804. testMessageProcessed = true;
  52805. // check if Uint8Array can be sent to worker
  52806. if (!(data instanceof Uint8Array)) {
  52807. handler.send('test', 'main', false);
  52808. return;
  52809. }
  52810. // making sure postMessage transfers are working
  52811. var supportTransfers = data[0] === 255;
  52812. handler.postMessageTransfers = supportTransfers;
  52813. // check if the response property is supported by xhr
  52814. var xhr = new XMLHttpRequest();
  52815. var responseExists = 'response' in xhr;
  52816. // check if the property is actually implemented
  52817. try {
  52818. var dummy = xhr.responseType;
  52819. } catch (e) {
  52820. responseExists = false;
  52821. }
  52822. if (!responseExists) {
  52823. handler.send('test', false);
  52824. return;
  52825. }
  52826. handler.send('test', {
  52827. supportTypedArray: true,
  52828. supportTransfers: supportTransfers
  52829. });
  52830. });
  52831. handler.on('configure', function wphConfigure(data) {
  52832. setVerbosityLevel(data.verbosity);
  52833. });
  52834. handler.on('GetDocRequest', function wphSetupDoc(data) {
  52835. return WorkerMessageHandler.createDocumentHandler(data, port);
  52836. });
  52837. },
  52838. createDocumentHandler: function wphCreateDocumentHandler(docParams, port) {
  52839. // This context is actually holds references on pdfManager and handler,
  52840. // until the latter is destroyed.
  52841. var pdfManager;
  52842. var terminated = false;
  52843. var cancelXHRs = null;
  52844. var WorkerTasks = [];
  52845. var docId = docParams.docId;
  52846. var workerHandlerName = docParams.docId + '_worker';
  52847. var handler = new MessageHandler(workerHandlerName, docId, port);
  52848. // Ensure that postMessage transfers are correctly enabled/disabled,
  52849. // to prevent "DataCloneError" in older versions of IE (see issue 6957).
  52850. handler.postMessageTransfers = docParams.postMessageTransfers;
  52851. function ensureNotTerminated() {
  52852. if (terminated) {
  52853. throw new Error('Worker was terminated');
  52854. }
  52855. }
  52856. function startWorkerTask(task) {
  52857. WorkerTasks.push(task);
  52858. }
  52859. function finishWorkerTask(task) {
  52860. task.finish();
  52861. var i = WorkerTasks.indexOf(task);
  52862. WorkerTasks.splice(i, 1);
  52863. }
  52864. function loadDocument(recoveryMode) {
  52865. var loadDocumentCapability = createPromiseCapability();
  52866. var parseSuccess = function parseSuccess() {
  52867. var numPagesPromise = pdfManager.ensureDoc('numPages');
  52868. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  52869. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  52870. Promise.all([
  52871. numPagesPromise,
  52872. fingerprintPromise,
  52873. encryptedPromise
  52874. ]).then(function onDocReady(results) {
  52875. var doc = {
  52876. numPages: results[0],
  52877. fingerprint: results[1],
  52878. encrypted: !!results[2]
  52879. };
  52880. loadDocumentCapability.resolve(doc);
  52881. }, parseFailure);
  52882. };
  52883. var parseFailure = function parseFailure(e) {
  52884. loadDocumentCapability.reject(e);
  52885. };
  52886. pdfManager.ensureDoc('checkHeader', []).then(function () {
  52887. pdfManager.ensureDoc('parseStartXRef', []).then(function () {
  52888. pdfManager.ensureDoc('parse', [recoveryMode]).then(parseSuccess, parseFailure);
  52889. }, parseFailure);
  52890. }, parseFailure);
  52891. return loadDocumentCapability.promise;
  52892. }
  52893. function getPdfManager(data, evaluatorOptions) {
  52894. var pdfManagerCapability = createPromiseCapability();
  52895. var pdfManager;
  52896. var source = data.source;
  52897. if (source.data) {
  52898. try {
  52899. pdfManager = new LocalPdfManager(docId, source.data, source.password, evaluatorOptions);
  52900. pdfManagerCapability.resolve(pdfManager);
  52901. } catch (ex) {
  52902. pdfManagerCapability.reject(ex);
  52903. }
  52904. return pdfManagerCapability.promise;
  52905. }
  52906. var pdfStream;
  52907. try {
  52908. if (source.chunkedViewerLoading) {
  52909. pdfStream = new PDFWorkerStream(source, handler);
  52910. } else {
  52911. assert(PDFNetworkStream, 'pdfjs/core/network module is not loaded');
  52912. pdfStream = new PDFNetworkStream(data);
  52913. }
  52914. } catch (ex) {
  52915. pdfManagerCapability.reject(ex);
  52916. return pdfManagerCapability.promise;
  52917. }
  52918. var fullRequest = pdfStream.getFullReader();
  52919. fullRequest.headersReady.then(function () {
  52920. if (!fullRequest.isStreamingSupported || !fullRequest.isRangeSupported) {
  52921. // If stream or range are disabled, it's our only way to report
  52922. // loading progress.
  52923. fullRequest.onProgress = function (evt) {
  52924. handler.send('DocProgress', {
  52925. loaded: evt.loaded,
  52926. total: evt.total
  52927. });
  52928. };
  52929. }
  52930. if (!fullRequest.isRangeSupported) {
  52931. return;
  52932. }
  52933. // We don't need auto-fetch when streaming is enabled.
  52934. var disableAutoFetch = source.disableAutoFetch || fullRequest.isStreamingSupported;
  52935. pdfManager = new NetworkPdfManager(docId, pdfStream, {
  52936. msgHandler: handler,
  52937. url: source.url,
  52938. password: source.password,
  52939. length: fullRequest.contentLength,
  52940. disableAutoFetch: disableAutoFetch,
  52941. rangeChunkSize: source.rangeChunkSize
  52942. }, evaluatorOptions);
  52943. pdfManagerCapability.resolve(pdfManager);
  52944. cancelXHRs = null;
  52945. }).catch(function (reason) {
  52946. pdfManagerCapability.reject(reason);
  52947. cancelXHRs = null;
  52948. });
  52949. var cachedChunks = [], loaded = 0;
  52950. var flushChunks = function () {
  52951. var pdfFile = arraysToBytes(cachedChunks);
  52952. if (source.length && pdfFile.length !== source.length) {
  52953. warn('reported HTTP length is different from actual');
  52954. }
  52955. // the data is array, instantiating directly from it
  52956. try {
  52957. pdfManager = new LocalPdfManager(docId, pdfFile, source.password, evaluatorOptions);
  52958. pdfManagerCapability.resolve(pdfManager);
  52959. } catch (ex) {
  52960. pdfManagerCapability.reject(ex);
  52961. }
  52962. cachedChunks = [];
  52963. };
  52964. var readPromise = new Promise(function (resolve, reject) {
  52965. var readChunk = function (chunk) {
  52966. try {
  52967. ensureNotTerminated();
  52968. if (chunk.done) {
  52969. if (!pdfManager) {
  52970. flushChunks();
  52971. }
  52972. cancelXHRs = null;
  52973. return;
  52974. }
  52975. var data = chunk.value;
  52976. loaded += arrayByteLength(data);
  52977. if (!fullRequest.isStreamingSupported) {
  52978. handler.send('DocProgress', {
  52979. loaded: loaded,
  52980. total: Math.max(loaded, fullRequest.contentLength || 0)
  52981. });
  52982. }
  52983. if (pdfManager) {
  52984. pdfManager.sendProgressiveData(data);
  52985. } else {
  52986. cachedChunks.push(data);
  52987. }
  52988. fullRequest.read().then(readChunk, reject);
  52989. } catch (e) {
  52990. reject(e);
  52991. }
  52992. };
  52993. fullRequest.read().then(readChunk, reject);
  52994. });
  52995. readPromise.catch(function (e) {
  52996. pdfManagerCapability.reject(e);
  52997. cancelXHRs = null;
  52998. });
  52999. cancelXHRs = function () {
  53000. pdfStream.cancelAllRequests('abort');
  53001. };
  53002. return pdfManagerCapability.promise;
  53003. }
  53004. var setupDoc = function (data) {
  53005. var onSuccess = function (doc) {
  53006. ensureNotTerminated();
  53007. handler.send('GetDoc', { pdfInfo: doc });
  53008. };
  53009. var onFailure = function (e) {
  53010. if (e instanceof PasswordException) {
  53011. if (e.code === PasswordResponses.NEED_PASSWORD) {
  53012. handler.send('NeedPassword', e);
  53013. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  53014. handler.send('IncorrectPassword', e);
  53015. }
  53016. } else if (e instanceof InvalidPDFException) {
  53017. handler.send('InvalidPDF', e);
  53018. } else if (e instanceof MissingPDFException) {
  53019. handler.send('MissingPDF', e);
  53020. } else if (e instanceof UnexpectedResponseException) {
  53021. handler.send('UnexpectedResponse', e);
  53022. } else {
  53023. handler.send('UnknownError', new UnknownErrorException(e.message, e.toString()));
  53024. }
  53025. };
  53026. ensureNotTerminated();
  53027. var cMapOptions = {
  53028. url: data.cMapUrl === undefined ? null : data.cMapUrl,
  53029. packed: data.cMapPacked === true
  53030. };
  53031. var evaluatorOptions = {
  53032. forceDataSchema: data.disableCreateObjectURL,
  53033. maxImageSize: data.maxImageSize === undefined ? -1 : data.maxImageSize,
  53034. disableFontFace: data.disableFontFace,
  53035. cMapOptions: cMapOptions
  53036. };
  53037. getPdfManager(data, evaluatorOptions).then(function (newPdfManager) {
  53038. if (terminated) {
  53039. // We were in a process of setting up the manager, but it got
  53040. // terminated in the middle.
  53041. newPdfManager.terminate();
  53042. throw new Error('Worker was terminated');
  53043. }
  53044. pdfManager = newPdfManager;
  53045. handler.send('PDFManagerReady', null);
  53046. pdfManager.onLoadedStream().then(function (stream) {
  53047. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  53048. });
  53049. }).then(function pdfManagerReady() {
  53050. ensureNotTerminated();
  53051. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  53052. ensureNotTerminated();
  53053. // Try again with recoveryMode == true
  53054. if (!(ex instanceof XRefParseException)) {
  53055. if (ex instanceof PasswordException) {
  53056. // after password exception prepare to receive a new password
  53057. // to repeat loading
  53058. pdfManager.passwordChanged().then(pdfManagerReady);
  53059. }
  53060. onFailure(ex);
  53061. return;
  53062. }
  53063. pdfManager.requestLoadedStream();
  53064. pdfManager.onLoadedStream().then(function () {
  53065. ensureNotTerminated();
  53066. loadDocument(true).then(onSuccess, onFailure);
  53067. });
  53068. }, onFailure);
  53069. }, onFailure);
  53070. };
  53071. handler.on('GetPage', function wphSetupGetPage(data) {
  53072. return pdfManager.getPage(data.pageIndex).then(function (page) {
  53073. var rotatePromise = pdfManager.ensure(page, 'rotate');
  53074. var refPromise = pdfManager.ensure(page, 'ref');
  53075. var viewPromise = pdfManager.ensure(page, 'view');
  53076. return Promise.all([
  53077. rotatePromise,
  53078. refPromise,
  53079. viewPromise
  53080. ]).then(function (results) {
  53081. return {
  53082. rotate: results[0],
  53083. ref: results[1],
  53084. view: results[2]
  53085. };
  53086. });
  53087. });
  53088. });
  53089. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  53090. var ref = new Ref(data.ref.num, data.ref.gen);
  53091. var catalog = pdfManager.pdfDocument.catalog;
  53092. return catalog.getPageIndex(ref);
  53093. });
  53094. handler.on('GetDestinations', function wphSetupGetDestinations(data) {
  53095. return pdfManager.ensureCatalog('destinations');
  53096. });
  53097. handler.on('GetDestination', function wphSetupGetDestination(data) {
  53098. return pdfManager.ensureCatalog('getDestination', [data.id]);
  53099. });
  53100. handler.on('GetPageLabels', function wphSetupGetPageLabels(data) {
  53101. return pdfManager.ensureCatalog('pageLabels');
  53102. });
  53103. handler.on('GetAttachments', function wphSetupGetAttachments(data) {
  53104. return pdfManager.ensureCatalog('attachments');
  53105. });
  53106. handler.on('GetJavaScript', function wphSetupGetJavaScript(data) {
  53107. return pdfManager.ensureCatalog('javaScript');
  53108. });
  53109. handler.on('GetOutline', function wphSetupGetOutline(data) {
  53110. return pdfManager.ensureCatalog('documentOutline');
  53111. });
  53112. handler.on('GetMetadata', function wphSetupGetMetadata(data) {
  53113. return Promise.all([
  53114. pdfManager.ensureDoc('documentInfo'),
  53115. pdfManager.ensureCatalog('metadata')
  53116. ]);
  53117. });
  53118. handler.on('GetData', function wphSetupGetData(data) {
  53119. pdfManager.requestLoadedStream();
  53120. return pdfManager.onLoadedStream().then(function (stream) {
  53121. return stream.bytes;
  53122. });
  53123. });
  53124. handler.on('GetStats', function wphSetupGetStats(data) {
  53125. return pdfManager.pdfDocument.xref.stats;
  53126. });
  53127. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  53128. pdfManager.updatePassword(data);
  53129. });
  53130. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  53131. return pdfManager.getPage(data.pageIndex).then(function (page) {
  53132. return pdfManager.ensure(page, 'getAnnotationsData', [data.intent]);
  53133. });
  53134. });
  53135. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  53136. var pageIndex = data.pageIndex;
  53137. pdfManager.getPage(pageIndex).then(function (page) {
  53138. var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
  53139. startWorkerTask(task);
  53140. var pageNum = pageIndex + 1;
  53141. var start = Date.now();
  53142. // Pre compile the pdf page and fetch the fonts/images.
  53143. page.getOperatorList(handler, task, data.intent, data.renderInteractiveForms).then(function (operatorList) {
  53144. finishWorkerTask(task);
  53145. info('page=' + pageNum + ' - getOperatorList: time=' + (Date.now() - start) + 'ms, len=' + operatorList.totalLength);
  53146. }, function (e) {
  53147. finishWorkerTask(task);
  53148. if (task.terminated) {
  53149. return;
  53150. }
  53151. // ignoring errors from the terminated thread
  53152. // For compatibility with older behavior, generating unknown
  53153. // unsupported feature notification on errors.
  53154. handler.send('UnsupportedFeature', { featureId: UNSUPPORTED_FEATURES.unknown });
  53155. var minimumStackMessage = 'worker.js: while trying to getPage() and getOperatorList()';
  53156. var wrappedException;
  53157. // Turn the error into an obj that can be serialized
  53158. if (typeof e === 'string') {
  53159. wrappedException = {
  53160. message: e,
  53161. stack: minimumStackMessage
  53162. };
  53163. } else if (typeof e === 'object') {
  53164. wrappedException = {
  53165. message: e.message || e.toString(),
  53166. stack: e.stack || minimumStackMessage
  53167. };
  53168. } else {
  53169. wrappedException = {
  53170. message: 'Unknown exception type: ' + typeof e,
  53171. stack: minimumStackMessage
  53172. };
  53173. }
  53174. handler.send('PageError', {
  53175. pageNum: pageNum,
  53176. error: wrappedException,
  53177. intent: data.intent
  53178. });
  53179. });
  53180. });
  53181. }, this);
  53182. handler.on('GetTextContent', function wphExtractText(data) {
  53183. var pageIndex = data.pageIndex;
  53184. var normalizeWhitespace = data.normalizeWhitespace;
  53185. var combineTextItems = data.combineTextItems;
  53186. return pdfManager.getPage(pageIndex).then(function (page) {
  53187. var task = new WorkerTask('GetTextContent: page ' + pageIndex);
  53188. startWorkerTask(task);
  53189. var pageNum = pageIndex + 1;
  53190. var start = Date.now();
  53191. return page.extractTextContent(task, normalizeWhitespace, combineTextItems).then(function (textContent) {
  53192. finishWorkerTask(task);
  53193. info('text indexing: page=' + pageNum + ' - time=' + (Date.now() - start) + 'ms');
  53194. return textContent;
  53195. }, function (reason) {
  53196. finishWorkerTask(task);
  53197. if (task.terminated) {
  53198. return;
  53199. }
  53200. // ignoring errors from the terminated thread
  53201. throw reason;
  53202. });
  53203. });
  53204. });
  53205. handler.on('Cleanup', function wphCleanup(data) {
  53206. return pdfManager.cleanup();
  53207. });
  53208. handler.on('Terminate', function wphTerminate(data) {
  53209. terminated = true;
  53210. if (pdfManager) {
  53211. pdfManager.terminate();
  53212. pdfManager = null;
  53213. }
  53214. if (cancelXHRs) {
  53215. cancelXHRs();
  53216. }
  53217. var waitOn = [];
  53218. WorkerTasks.forEach(function (task) {
  53219. waitOn.push(task.finished);
  53220. task.terminate();
  53221. });
  53222. return Promise.all(waitOn).then(function () {
  53223. // Notice that even if we destroying handler, resolved response promise
  53224. // must be sent back.
  53225. handler.destroy();
  53226. handler = null;
  53227. });
  53228. });
  53229. handler.on('Ready', function wphReady(data) {
  53230. setupDoc(docParams);
  53231. docParams = null;
  53232. });
  53233. // we don't need docParams anymore -- saving memory.
  53234. return workerHandlerName;
  53235. }
  53236. };
  53237. function initializeWorker() {
  53238. if (!('console' in globalScope)) {
  53239. var consoleTimer = {};
  53240. var workerConsole = {
  53241. log: function log() {
  53242. var args = Array.prototype.slice.call(arguments);
  53243. globalScope.postMessage({
  53244. targetName: 'main',
  53245. action: 'console_log',
  53246. data: args
  53247. });
  53248. },
  53249. error: function error() {
  53250. var args = Array.prototype.slice.call(arguments);
  53251. globalScope.postMessage({
  53252. targetName: 'main',
  53253. action: 'console_error',
  53254. data: args
  53255. });
  53256. throw 'pdf.js execution error';
  53257. },
  53258. time: function time(name) {
  53259. consoleTimer[name] = Date.now();
  53260. },
  53261. timeEnd: function timeEnd(name) {
  53262. var time = consoleTimer[name];
  53263. if (!time) {
  53264. error('Unknown timer name ' + name);
  53265. }
  53266. this.log('Timer:', name, Date.now() - time);
  53267. }
  53268. };
  53269. globalScope.console = workerConsole;
  53270. }
  53271. var handler = new MessageHandler('worker', 'main', self);
  53272. WorkerMessageHandler.setup(handler, self);
  53273. handler.send('ready', null);
  53274. }
  53275. // Worker thread (and not node.js)?
  53276. if (typeof window === 'undefined' && !(typeof module !== 'undefined' && module.require)) {
  53277. initializeWorker();
  53278. }
  53279. exports.setPDFNetworkStreamClass = setPDFNetworkStreamClass;
  53280. exports.WorkerTask = WorkerTask;
  53281. exports.WorkerMessageHandler = WorkerMessageHandler;
  53282. }));
  53283. (function (root, factory) {
  53284. factory(root.pdfjsCoreNetwork = {}, root.pdfjsSharedUtil, root.pdfjsCoreWorker);
  53285. }(this, function (exports, sharedUtil, coreWorker) {
  53286. var OK_RESPONSE = 200;
  53287. var PARTIAL_CONTENT_RESPONSE = 206;
  53288. function NetworkManager(url, args) {
  53289. this.url = url;
  53290. args = args || {};
  53291. this.isHttp = /^https?:/i.test(url);
  53292. this.httpHeaders = this.isHttp && args.httpHeaders || {};
  53293. this.withCredentials = args.withCredentials || false;
  53294. this.getXhr = args.getXhr || function NetworkManager_getXhr() {
  53295. return new XMLHttpRequest();
  53296. };
  53297. this.currXhrId = 0;
  53298. this.pendingRequests = Object.create(null);
  53299. this.loadedRequests = Object.create(null);
  53300. }
  53301. function getArrayBuffer(xhr) {
  53302. var data = xhr.response;
  53303. if (typeof data !== 'string') {
  53304. return data;
  53305. }
  53306. var length = data.length;
  53307. var array = new Uint8Array(length);
  53308. for (var i = 0; i < length; i++) {
  53309. array[i] = data.charCodeAt(i) & 0xFF;
  53310. }
  53311. return array.buffer;
  53312. }
  53313. var supportsMozChunked = function supportsMozChunkedClosure() {
  53314. try {
  53315. var x = new XMLHttpRequest();
  53316. // Firefox 37- required .open() to be called before setting responseType.
  53317. // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
  53318. // Even though the URL is not visited, .open() could fail if the URL is
  53319. // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
  53320. // When this error occurs, this feature detection method will mistakenly
  53321. // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
  53322. x.open('GET', 'https://example.com');
  53323. x.responseType = 'moz-chunked-arraybuffer';
  53324. return x.responseType === 'moz-chunked-arraybuffer';
  53325. } catch (e) {
  53326. return false;
  53327. }
  53328. }();
  53329. NetworkManager.prototype = {
  53330. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  53331. var args = {
  53332. begin: begin,
  53333. end: end
  53334. };
  53335. for (var prop in listeners) {
  53336. args[prop] = listeners[prop];
  53337. }
  53338. return this.request(args);
  53339. },
  53340. requestFull: function NetworkManager_requestFull(listeners) {
  53341. return this.request(listeners);
  53342. },
  53343. request: function NetworkManager_request(args) {
  53344. var xhr = this.getXhr();
  53345. var xhrId = this.currXhrId++;
  53346. var pendingRequest = this.pendingRequests[xhrId] = { xhr: xhr };
  53347. xhr.open('GET', this.url);
  53348. xhr.withCredentials = this.withCredentials;
  53349. for (var property in this.httpHeaders) {
  53350. var value = this.httpHeaders[property];
  53351. if (typeof value === 'undefined') {
  53352. continue;
  53353. }
  53354. xhr.setRequestHeader(property, value);
  53355. }
  53356. if (this.isHttp && 'begin' in args && 'end' in args) {
  53357. var rangeStr = args.begin + '-' + (args.end - 1);
  53358. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  53359. pendingRequest.expectedStatus = 206;
  53360. } else {
  53361. pendingRequest.expectedStatus = 200;
  53362. }
  53363. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  53364. if (useMozChunkedLoading) {
  53365. xhr.responseType = 'moz-chunked-arraybuffer';
  53366. pendingRequest.onProgressiveData = args.onProgressiveData;
  53367. pendingRequest.mozChunked = true;
  53368. } else {
  53369. xhr.responseType = 'arraybuffer';
  53370. }
  53371. if (args.onError) {
  53372. xhr.onerror = function (evt) {
  53373. args.onError(xhr.status);
  53374. };
  53375. }
  53376. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  53377. xhr.onprogress = this.onProgress.bind(this, xhrId);
  53378. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  53379. pendingRequest.onDone = args.onDone;
  53380. pendingRequest.onError = args.onError;
  53381. pendingRequest.onProgress = args.onProgress;
  53382. xhr.send(null);
  53383. return xhrId;
  53384. },
  53385. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  53386. var pendingRequest = this.pendingRequests[xhrId];
  53387. if (!pendingRequest) {
  53388. // Maybe abortRequest was called...
  53389. return;
  53390. }
  53391. if (pendingRequest.mozChunked) {
  53392. var chunk = getArrayBuffer(pendingRequest.xhr);
  53393. pendingRequest.onProgressiveData(chunk);
  53394. }
  53395. var onProgress = pendingRequest.onProgress;
  53396. if (onProgress) {
  53397. onProgress(evt);
  53398. }
  53399. },
  53400. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  53401. var pendingRequest = this.pendingRequests[xhrId];
  53402. if (!pendingRequest) {
  53403. // Maybe abortRequest was called...
  53404. return;
  53405. }
  53406. var xhr = pendingRequest.xhr;
  53407. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  53408. pendingRequest.onHeadersReceived();
  53409. delete pendingRequest.onHeadersReceived;
  53410. }
  53411. if (xhr.readyState !== 4) {
  53412. return;
  53413. }
  53414. if (!(xhrId in this.pendingRequests)) {
  53415. // The XHR request might have been aborted in onHeadersReceived()
  53416. // callback, in which case we should abort request
  53417. return;
  53418. }
  53419. delete this.pendingRequests[xhrId];
  53420. // success status == 0 can be on ftp, file and other protocols
  53421. if (xhr.status === 0 && this.isHttp) {
  53422. if (pendingRequest.onError) {
  53423. pendingRequest.onError(xhr.status);
  53424. }
  53425. return;
  53426. }
  53427. var xhrStatus = xhr.status || OK_RESPONSE;
  53428. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  53429. // "A server MAY ignore the Range header". This means it's possible to
  53430. // get a 200 rather than a 206 response from a range request.
  53431. var ok_response_on_range_request = xhrStatus === OK_RESPONSE && pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  53432. if (!ok_response_on_range_request && xhrStatus !== pendingRequest.expectedStatus) {
  53433. if (pendingRequest.onError) {
  53434. pendingRequest.onError(xhr.status);
  53435. }
  53436. return;
  53437. }
  53438. this.loadedRequests[xhrId] = true;
  53439. var chunk = getArrayBuffer(xhr);
  53440. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  53441. var rangeHeader = xhr.getResponseHeader('Content-Range');
  53442. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  53443. var begin = parseInt(matches[1], 10);
  53444. pendingRequest.onDone({
  53445. begin: begin,
  53446. chunk: chunk
  53447. });
  53448. } else if (pendingRequest.onProgressiveData) {
  53449. pendingRequest.onDone(null);
  53450. } else if (chunk) {
  53451. pendingRequest.onDone({
  53452. begin: 0,
  53453. chunk: chunk
  53454. });
  53455. } else if (pendingRequest.onError) {
  53456. pendingRequest.onError(xhr.status);
  53457. }
  53458. },
  53459. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  53460. for (var xhrId in this.pendingRequests) {
  53461. return true;
  53462. }
  53463. return false;
  53464. },
  53465. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  53466. return this.pendingRequests[xhrId].xhr;
  53467. },
  53468. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  53469. return !!this.pendingRequests[xhrId].onProgressiveData;
  53470. },
  53471. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  53472. return xhrId in this.pendingRequests;
  53473. },
  53474. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  53475. return xhrId in this.loadedRequests;
  53476. },
  53477. abortAllRequests: function NetworkManager_abortAllRequests() {
  53478. for (var xhrId in this.pendingRequests) {
  53479. this.abortRequest(xhrId | 0);
  53480. }
  53481. },
  53482. abortRequest: function NetworkManager_abortRequest(xhrId) {
  53483. var xhr = this.pendingRequests[xhrId].xhr;
  53484. delete this.pendingRequests[xhrId];
  53485. xhr.abort();
  53486. }
  53487. };
  53488. var assert = sharedUtil.assert;
  53489. var createPromiseCapability = sharedUtil.createPromiseCapability;
  53490. var isInt = sharedUtil.isInt;
  53491. var MissingPDFException = sharedUtil.MissingPDFException;
  53492. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  53493. /** @implements {IPDFStream} */
  53494. function PDFNetworkStream(options) {
  53495. this._options = options;
  53496. var source = options.source;
  53497. this._manager = new NetworkManager(source.url, {
  53498. httpHeaders: source.httpHeaders,
  53499. withCredentials: source.withCredentials
  53500. });
  53501. this._rangeChunkSize = source.rangeChunkSize;
  53502. this._fullRequestReader = null;
  53503. this._rangeRequestReaders = [];
  53504. }
  53505. PDFNetworkStream.prototype = {
  53506. _onRangeRequestReaderClosed: function PDFNetworkStream_onRangeRequestReaderClosed(reader) {
  53507. var i = this._rangeRequestReaders.indexOf(reader);
  53508. if (i >= 0) {
  53509. this._rangeRequestReaders.splice(i, 1);
  53510. }
  53511. },
  53512. getFullReader: function PDFNetworkStream_getFullReader() {
  53513. assert(!this._fullRequestReader);
  53514. this._fullRequestReader = new PDFNetworkStreamFullRequestReader(this._manager, this._options);
  53515. return this._fullRequestReader;
  53516. },
  53517. getRangeReader: function PDFNetworkStream_getRangeReader(begin, end) {
  53518. var reader = new PDFNetworkStreamRangeRequestReader(this._manager, begin, end);
  53519. reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
  53520. this._rangeRequestReaders.push(reader);
  53521. return reader;
  53522. },
  53523. cancelAllRequests: function PDFNetworkStream_cancelAllRequests(reason) {
  53524. if (this._fullRequestReader) {
  53525. this._fullRequestReader.cancel(reason);
  53526. }
  53527. var readers = this._rangeRequestReaders.slice(0);
  53528. readers.forEach(function (reader) {
  53529. reader.cancel(reason);
  53530. });
  53531. }
  53532. };
  53533. /** @implements {IPDFStreamReader} */
  53534. function PDFNetworkStreamFullRequestReader(manager, options) {
  53535. this._manager = manager;
  53536. var source = options.source;
  53537. var args = {
  53538. onHeadersReceived: this._onHeadersReceived.bind(this),
  53539. onProgressiveData: source.disableStream ? null : this._onProgressiveData.bind(this),
  53540. onDone: this._onDone.bind(this),
  53541. onError: this._onError.bind(this),
  53542. onProgress: this._onProgress.bind(this)
  53543. };
  53544. this._url = source.url;
  53545. this._fullRequestId = manager.requestFull(args);
  53546. this._headersReceivedCapability = createPromiseCapability();
  53547. this._disableRange = options.disableRange || false;
  53548. this._contentLength = source.length;
  53549. // optional
  53550. this._rangeChunkSize = source.rangeChunkSize;
  53551. if (!this._rangeChunkSize && !this._disableRange) {
  53552. this._disableRange = true;
  53553. }
  53554. this._isStreamingSupported = false;
  53555. this._isRangeSupported = false;
  53556. this._cachedChunks = [];
  53557. this._requests = [];
  53558. this._done = false;
  53559. this._storedError = undefined;
  53560. this.onProgress = null;
  53561. }
  53562. PDFNetworkStreamFullRequestReader.prototype = {
  53563. _validateRangeRequestCapabilities: function PDFNetworkStreamFullRequestReader_validateRangeRequestCapabilities() {
  53564. if (this._disableRange) {
  53565. return false;
  53566. }
  53567. var networkManager = this._manager;
  53568. var fullRequestXhrId = this._fullRequestId;
  53569. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  53570. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  53571. return false;
  53572. }
  53573. var contentEncoding = fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  53574. if (contentEncoding !== 'identity') {
  53575. return false;
  53576. }
  53577. var length = fullRequestXhr.getResponseHeader('Content-Length');
  53578. length = parseInt(length, 10);
  53579. if (!isInt(length)) {
  53580. return false;
  53581. }
  53582. this._contentLength = length;
  53583. // setting right content length
  53584. if (length <= 2 * this._rangeChunkSize) {
  53585. // The file size is smaller than the size of two chunks, so it does
  53586. // not make any sense to abort the request and retry with a range
  53587. // request.
  53588. return false;
  53589. }
  53590. return true;
  53591. },
  53592. _onHeadersReceived: function PDFNetworkStreamFullRequestReader_onHeadersReceived() {
  53593. if (this._validateRangeRequestCapabilities()) {
  53594. this._isRangeSupported = true;
  53595. }
  53596. var networkManager = this._manager;
  53597. var fullRequestXhrId = this._fullRequestId;
  53598. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  53599. // We can continue fetching when progressive loading is enabled,
  53600. // and we don't need the autoFetch feature.
  53601. this._isStreamingSupported = true;
  53602. } else if (this._isRangeSupported) {
  53603. // NOTE: by cancelling the full request, and then issuing range
  53604. // requests, there will be an issue for sites where you can only
  53605. // request the pdf once. However, if this is the case, then the
  53606. // server should not be returning that it can support range
  53607. // requests.
  53608. networkManager.abortRequest(fullRequestXhrId);
  53609. }
  53610. this._headersReceivedCapability.resolve();
  53611. },
  53612. _onProgressiveData: function PDFNetworkStreamFullRequestReader_onProgressiveData(chunk) {
  53613. if (this._requests.length > 0) {
  53614. var requestCapability = this._requests.shift();
  53615. requestCapability.resolve({
  53616. value: chunk,
  53617. done: false
  53618. });
  53619. } else {
  53620. this._cachedChunks.push(chunk);
  53621. }
  53622. },
  53623. _onDone: function PDFNetworkStreamFullRequestReader_onDone(args) {
  53624. if (args) {
  53625. this._onProgressiveData(args.chunk);
  53626. }
  53627. this._done = true;
  53628. if (this._cachedChunks.length > 0) {
  53629. return;
  53630. }
  53631. this._requests.forEach(function (requestCapability) {
  53632. requestCapability.resolve({
  53633. value: undefined,
  53634. done: true
  53635. });
  53636. });
  53637. this._requests = [];
  53638. },
  53639. _onError: function PDFNetworkStreamFullRequestReader_onError(status) {
  53640. var url = this._url;
  53641. var exception;
  53642. if (status === 404 || status === 0 && /^file:/.test(url)) {
  53643. exception = new MissingPDFException('Missing PDF "' + url + '".');
  53644. } else {
  53645. exception = new UnexpectedResponseException('Unexpected server response (' + status + ') while retrieving PDF "' + url + '".', status);
  53646. }
  53647. this._storedError = exception;
  53648. this._headersReceivedCapability.reject(exception);
  53649. this._requests.forEach(function (requestCapability) {
  53650. requestCapability.reject(exception);
  53651. });
  53652. this._requests = [];
  53653. this._cachedChunks = [];
  53654. },
  53655. _onProgress: function PDFNetworkStreamFullRequestReader_onProgress(data) {
  53656. if (this.onProgress) {
  53657. this.onProgress({
  53658. loaded: data.loaded,
  53659. total: data.lengthComputable ? data.total : this._contentLength
  53660. });
  53661. }
  53662. },
  53663. get isRangeSupported() {
  53664. return this._isRangeSupported;
  53665. },
  53666. get isStreamingSupported() {
  53667. return this._isStreamingSupported;
  53668. },
  53669. get contentLength() {
  53670. return this._contentLength;
  53671. },
  53672. get headersReady() {
  53673. return this._headersReceivedCapability.promise;
  53674. },
  53675. read: function PDFNetworkStreamFullRequestReader_read() {
  53676. if (this._storedError) {
  53677. return Promise.reject(this._storedError);
  53678. }
  53679. if (this._cachedChunks.length > 0) {
  53680. var chunk = this._cachedChunks.shift();
  53681. return Promise.resolve(chunk);
  53682. }
  53683. if (this._done) {
  53684. return Promise.resolve({
  53685. value: undefined,
  53686. done: true
  53687. });
  53688. }
  53689. var requestCapability = createPromiseCapability();
  53690. this._requests.push(requestCapability);
  53691. return requestCapability.promise;
  53692. },
  53693. cancel: function PDFNetworkStreamFullRequestReader_cancel(reason) {
  53694. this._done = true;
  53695. this._headersReceivedCapability.reject(reason);
  53696. this._requests.forEach(function (requestCapability) {
  53697. requestCapability.resolve({
  53698. value: undefined,
  53699. done: true
  53700. });
  53701. });
  53702. this._requests = [];
  53703. if (this._manager.isPendingRequest(this._fullRequestId)) {
  53704. this._manager.abortRequest(this._fullRequestId);
  53705. }
  53706. this._fullRequestReader = null;
  53707. }
  53708. };
  53709. /** @implements {IPDFStreamRangeReader} */
  53710. function PDFNetworkStreamRangeRequestReader(manager, begin, end) {
  53711. this._manager = manager;
  53712. var args = {
  53713. onDone: this._onDone.bind(this),
  53714. onProgress: this._onProgress.bind(this)
  53715. };
  53716. this._requestId = manager.requestRange(begin, end, args);
  53717. this._requests = [];
  53718. this._queuedChunk = null;
  53719. this._done = false;
  53720. this.onProgress = null;
  53721. this.onClosed = null;
  53722. }
  53723. PDFNetworkStreamRangeRequestReader.prototype = {
  53724. _close: function PDFNetworkStreamRangeRequestReader_close() {
  53725. if (this.onClosed) {
  53726. this.onClosed(this);
  53727. }
  53728. },
  53729. _onDone: function PDFNetworkStreamRangeRequestReader_onDone(data) {
  53730. var chunk = data.chunk;
  53731. if (this._requests.length > 0) {
  53732. var requestCapability = this._requests.shift();
  53733. requestCapability.resolve({
  53734. value: chunk,
  53735. done: false
  53736. });
  53737. } else {
  53738. this._queuedChunk = chunk;
  53739. }
  53740. this._done = true;
  53741. this._requests.forEach(function (requestCapability) {
  53742. requestCapability.resolve({
  53743. value: undefined,
  53744. done: true
  53745. });
  53746. });
  53747. this._requests = [];
  53748. this._close();
  53749. },
  53750. _onProgress: function PDFNetworkStreamRangeRequestReader_onProgress(evt) {
  53751. if (!this.isStreamingSupported && this.onProgress) {
  53752. this.onProgress({ loaded: evt.loaded });
  53753. }
  53754. },
  53755. get isStreamingSupported() {
  53756. return false;
  53757. },
  53758. // TODO allow progressive range bytes loading
  53759. read: function PDFNetworkStreamRangeRequestReader_read() {
  53760. if (this._queuedChunk !== null) {
  53761. var chunk = this._queuedChunk;
  53762. this._queuedChunk = null;
  53763. return Promise.resolve({
  53764. value: chunk,
  53765. done: false
  53766. });
  53767. }
  53768. if (this._done) {
  53769. return Promise.resolve({
  53770. value: undefined,
  53771. done: true
  53772. });
  53773. }
  53774. var requestCapability = createPromiseCapability();
  53775. this._requests.push(requestCapability);
  53776. return requestCapability.promise;
  53777. },
  53778. cancel: function PDFNetworkStreamRangeRequestReader_cancel(reason) {
  53779. this._done = true;
  53780. this._requests.forEach(function (requestCapability) {
  53781. requestCapability.resolve({
  53782. value: undefined,
  53783. done: true
  53784. });
  53785. });
  53786. this._requests = [];
  53787. if (this._manager.isPendingRequest(this._requestId)) {
  53788. this._manager.abortRequest(this._requestId);
  53789. }
  53790. this._close();
  53791. }
  53792. };
  53793. coreWorker.setPDFNetworkStreamClass(PDFNetworkStream);
  53794. exports.PDFNetworkStream = PDFNetworkStream;
  53795. exports.NetworkManager = NetworkManager;
  53796. }));
  53797. }.call(pdfjsLibs));
  53798. exports.WorkerMessageHandler = pdfjsLibs.pdfjsCoreWorker.WorkerMessageHandler;
  53799. }));