2
0

pdf.worker.js 1.3 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593385943859538596385973859838599386003860138602386033860438605386063860738608386093861038611386123861338614386153861638617386183861938620386213862238623386243862538626386273862838629386303863138632386333863438635386363863738638386393864038641386423864338644386453864638647386483864938650386513865238653386543865538656386573865838659386603866138662386633866438665386663866738668386693867038671386723867338674386753867638677386783867938680386813868238683386843868538686386873868838689386903869138692386933869438695386963869738698386993870038701387023870338704387053870638707387083870938710387113871238713387143871538716387173871838719387203872138722387233872438725387263872738728387293873038731387323873338734387353873638737387383873938740387413874238743387443874538746387473874838749387503875138752387533875438755387563875738758387593876038761387623876338764387653876638767387683876938770387713877238773387743877538776387773877838779387803878138782387833878438785387863878738788387893879038791387923879338794387953879638797387983879938800388013880238803388043880538806388073880838809388103881138812388133881438815388163881738818388193882038821388223882338824388253882638827388283882938830388313883238833388343883538836388373883838839388403884138842388433884438845388463884738848388493885038851388523885338854388553885638857388583885938860388613886238863388643886538866388673886838869388703887138872388733887438875388763887738878388793888038881388823888338884388853888638887388883888938890388913889238893388943889538896388973889838899389003890138902389033890438905389063890738908389093891038911389123891338914389153891638917389183891938920389213892238923389243892538926389273892838929389303893138932389333893438935389363893738938389393894038941389423894338944389453894638947389483894938950389513895238953389543895538956389573895838959389603896138962389633896438965389663896738968389693897038971389723897338974389753897638977389783897938980389813898238983389843898538986389873898838989389903899138992389933899438995389963899738998389993900039001390023900339004390053900639007390083900939010390113901239013390143901539016390173901839019390203902139022390233902439025390263902739028390293903039031390323903339034390353903639037390383903939040390413904239043390443904539046390473904839049390503905139052390533905439055390563905739058390593906039061390623906339064390653906639067390683906939070390713907239073390743907539076390773907839079390803908139082390833908439085390863908739088390893909039091390923909339094390953909639097390983909939100391013910239103391043910539106391073910839109391103911139112391133911439115391163911739118391193912039121391223912339124391253912639127391283912939130391313913239133391343913539136391373913839139391403914139142391433914439145391463914739148391493915039151391523915339154391553915639157391583915939160391613916239163391643916539166391673916839169391703917139172391733917439175391763917739178391793918039181391823918339184391853918639187391883918939190391913919239193391943919539196391973919839199392003920139202392033920439205392063920739208392093921039211392123921339214392153921639217392183921939220392213922239223392243922539226392273922839229392303923139232392333923439235392363923739238392393924039241392423924339244392453924639247392483924939250392513925239253392543925539256392573925839259392603926139262392633926439265392663926739268392693927039271392723927339274392753927639277392783927939280392813928239283392843928539286392873928839289392903929139292392933929439295392963929739298392993930039301393023930339304393053930639307393083930939310393113931239313393143931539316393173931839319393203932139322393233932439325393263932739328393293933039331393323933339334393353933639337393383933939340393413934239343393443934539346393473934839349393503935139352393533935439355393563935739358393593936039361393623936339364393653936639367393683936939370393713937239373393743937539376393773937839379393803938139382393833938439385393863938739388393893939039391393923939339394393953939639397393983939939400394013940239403394043940539406394073940839409394103941139412394133941439415394163941739418394193942039421394223942339424394253942639427394283942939430394313943239433394343943539436394373943839439394403944139442394433944439445394463944739448394493945039451394523945339454394553945639457394583945939460394613946239463394643946539466394673946839469394703947139472394733947439475394763947739478394793948039481394823948339484394853948639487394883948939490394913949239493394943949539496394973949839499395003950139502395033950439505395063950739508395093951039511395123951339514395153951639517395183951939520395213952239523395243952539526395273952839529395303953139532395333953439535395363953739538395393954039541395423954339544395453954639547395483954939550395513955239553395543955539556395573955839559395603956139562395633956439565395663956739568395693957039571395723957339574395753957639577395783957939580395813958239583395843958539586395873958839589395903959139592395933959439595395963959739598395993960039601396023960339604396053960639607396083960939610396113961239613396143961539616396173961839619396203962139622396233962439625396263962739628396293963039631396323963339634396353963639637396383963939640396413964239643396443964539646396473964839649396503965139652396533965439655396563965739658396593966039661396623966339664396653966639667396683966939670396713967239673396743967539676396773967839679396803968139682396833968439685396863968739688396893969039691396923969339694396953969639697396983969939700397013970239703397043970539706397073970839709397103971139712397133971439715397163971739718397193972039721397223972339724397253972639727397283972939730397313973239733397343973539736397373973839739397403974139742397433974439745397463974739748397493975039751397523975339754397553975639757397583975939760397613976239763397643976539766397673976839769397703977139772397733977439775397763977739778397793978039781397823978339784397853978639787397883978939790397913979239793397943979539796397973979839799398003980139802398033980439805398063980739808398093981039811398123981339814398153981639817398183981939820398213982239823398243982539826398273982839829398303983139832398333983439835398363983739838398393984039841398423984339844398453984639847398483984939850398513985239853398543985539856398573985839859398603986139862398633986439865398663986739868398693987039871398723987339874398753987639877398783987939880398813988239883398843988539886398873988839889398903989139892398933989439895398963989739898398993990039901399023990339904399053990639907399083990939910399113991239913399143991539916399173991839919399203992139922399233992439925399263992739928399293993039931399323993339934399353993639937399383993939940399413994239943399443994539946399473994839949399503995139952399533995439955399563995739958399593996039961399623996339964399653996639967399683996939970399713997239973399743997539976399773997839979399803998139982399833998439985399863998739988399893999039991399923999339994399953999639997399983999940000400014000240003400044000540006400074000840009400104001140012400134001440015400164001740018400194002040021400224002340024400254002640027400284002940030400314003240033400344003540036400374003840039400404004140042400434004440045400464004740048400494005040051400524005340054400554005640057400584005940060400614006240063400644006540066400674006840069400704007140072400734007440075400764007740078400794008040081400824008340084400854008640087400884008940090400914009240093400944009540096400974009840099401004010140102401034010440105401064010740108401094011040111401124011340114401154011640117401184011940120401214012240123401244012540126401274012840129401304013140132401334013440135401364013740138401394014040141401424014340144401454014640147401484014940150401514015240153401544015540156401574015840159401604016140162401634016440165401664016740168401694017040171401724017340174401754017640177401784017940180401814018240183401844018540186401874018840189401904019140192401934019440195401964019740198401994020040201402024020340204402054020640207402084020940210402114021240213402144021540216402174021840219402204022140222402234022440225402264022740228402294023040231402324023340234402354023640237402384023940240402414024240243402444024540246402474024840249402504025140252402534025440255402564025740258402594026040261402624026340264402654026640267402684026940270402714027240273402744027540276402774027840279402804028140282402834028440285402864028740288402894029040291402924029340294402954029640297402984029940300403014030240303403044030540306403074030840309403104031140312403134031440315403164031740318403194032040321403224032340324403254032640327403284032940330403314033240333403344033540336403374033840339403404034140342403434034440345403464034740348403494035040351403524035340354403554035640357403584035940360403614036240363403644036540366403674036840369403704037140372403734037440375403764037740378403794038040381403824038340384403854038640387403884038940390403914039240393403944039540396403974039840399404004040140402404034040440405404064040740408404094041040411404124041340414404154041640417404184041940420404214042240423404244042540426404274042840429404304043140432404334043440435404364043740438404394044040441404424044340444404454044640447404484044940450404514045240453404544045540456404574045840459404604046140462404634046440465404664046740468404694047040471404724047340474404754047640477404784047940480404814048240483404844048540486404874048840489404904049140492404934049440495404964049740498404994050040501405024050340504405054050640507405084050940510405114051240513405144051540516405174051840519405204052140522405234052440525405264052740528405294053040531405324053340534405354053640537405384053940540405414054240543405444054540546405474054840549405504055140552405534055440555405564055740558405594056040561405624056340564405654056640567405684056940570405714057240573405744057540576405774057840579405804058140582405834058440585405864058740588405894059040591405924059340594405954059640597405984059940600406014060240603406044060540606406074060840609406104061140612406134061440615406164061740618406194062040621406224062340624406254062640627406284062940630406314063240633406344063540636406374063840639406404064140642406434064440645406464064740648406494065040651406524065340654406554065640657406584065940660406614066240663406644066540666406674066840669406704067140672406734067440675406764067740678406794068040681406824068340684406854068640687406884068940690406914069240693406944069540696406974069840699407004070140702407034070440705407064070740708407094071040711407124071340714407154071640717407184071940720407214072240723407244072540726407274072840729407304073140732407334073440735407364073740738407394074040741407424074340744407454074640747407484074940750407514075240753407544075540756407574075840759407604076140762407634076440765407664076740768407694077040771407724077340774407754077640777407784077940780407814078240783407844078540786407874078840789407904079140792407934079440795407964079740798407994080040801408024080340804408054080640807408084080940810408114081240813408144081540816408174081840819408204082140822408234082440825408264082740828408294083040831408324083340834408354083640837408384083940840408414084240843408444084540846408474084840849408504085140852408534085440855408564085740858408594086040861408624086340864408654086640867408684086940870408714087240873408744087540876408774087840879408804088140882408834088440885408864088740888408894089040891408924089340894408954089640897408984089940900409014090240903409044090540906409074090840909409104091140912409134091440915409164091740918409194092040921409224092340924409254092640927409284092940930409314093240933409344093540936409374093840939409404094140942409434094440945409464094740948409494095040951409524095340954409554095640957409584095940960409614096240963409644096540966409674096840969409704097140972409734097440975409764097740978409794098040981409824098340984409854098640987409884098940990409914099240993409944099540996409974099840999410004100141002410034100441005410064100741008410094101041011410124101341014410154101641017410184101941020410214102241023410244102541026410274102841029410304103141032410334103441035410364103741038410394104041041410424104341044410454104641047410484104941050410514105241053410544105541056410574105841059410604106141062410634106441065410664106741068410694107041071410724107341074410754107641077410784107941080410814108241083410844108541086410874108841089410904109141092410934109441095410964109741098410994110041101411024110341104411054110641107411084110941110411114111241113411144111541116411174111841119411204112141122411234112441125411264112741128411294113041131411324113341134411354113641137411384113941140411414114241143411444114541146411474114841149411504115141152411534115441155411564115741158411594116041161411624116341164411654116641167411684116941170411714117241173411744117541176411774117841179411804118141182411834118441185411864118741188411894119041191411924119341194411954119641197411984119941200412014120241203412044120541206412074120841209412104121141212412134121441215412164121741218412194122041221412224122341224412254122641227412284122941230412314123241233412344123541236412374123841239412404124141242412434124441245412464124741248412494125041251412524125341254412554125641257412584125941260412614126241263412644126541266412674126841269412704127141272412734127441275412764127741278412794128041281412824128341284412854128641287412884128941290412914129241293412944129541296412974129841299413004130141302413034130441305413064130741308413094131041311413124131341314413154131641317413184131941320413214132241323413244132541326413274132841329413304133141332413334133441335413364133741338413394134041341413424134341344413454134641347413484134941350413514135241353413544135541356413574135841359413604136141362413634136441365413664136741368413694137041371413724137341374413754137641377413784137941380413814138241383413844138541386413874138841389413904139141392413934139441395413964139741398413994140041401414024140341404414054140641407414084140941410414114141241413414144141541416414174141841419414204142141422414234142441425414264142741428414294143041431414324143341434414354143641437414384143941440414414144241443414444144541446414474144841449414504145141452414534145441455414564145741458414594146041461414624146341464414654146641467414684146941470414714147241473414744147541476414774147841479414804148141482414834148441485414864148741488414894149041491414924149341494414954149641497414984149941500415014150241503415044150541506415074150841509415104151141512415134151441515415164151741518415194152041521415224152341524415254152641527415284152941530415314153241533415344153541536415374153841539415404154141542415434154441545415464154741548415494155041551415524155341554415554155641557415584155941560415614156241563415644156541566415674156841569415704157141572415734157441575415764157741578415794158041581415824158341584415854158641587415884158941590415914159241593415944159541596415974159841599416004160141602416034160441605416064160741608416094161041611416124161341614416154161641617416184161941620416214162241623416244162541626416274162841629416304163141632416334163441635416364163741638416394164041641416424164341644416454164641647416484164941650416514165241653416544165541656416574165841659416604166141662416634166441665416664166741668416694167041671416724167341674416754167641677416784167941680416814168241683416844168541686416874168841689416904169141692416934169441695416964169741698416994170041701417024170341704417054170641707417084170941710417114171241713417144171541716417174171841719417204172141722417234172441725417264172741728417294173041731417324173341734417354173641737417384173941740417414174241743417444174541746417474174841749417504175141752417534175441755417564175741758417594176041761417624176341764417654176641767417684176941770417714177241773417744177541776417774177841779417804178141782417834178441785417864178741788417894179041791417924179341794417954179641797417984179941800418014180241803418044180541806418074180841809418104181141812418134181441815418164181741818418194182041821418224182341824418254182641827418284182941830418314183241833418344183541836418374183841839418404184141842418434184441845418464184741848418494185041851418524185341854418554185641857418584185941860418614186241863418644186541866418674186841869418704187141872418734187441875418764187741878418794188041881418824188341884418854188641887418884188941890418914189241893418944189541896418974189841899419004190141902419034190441905419064190741908419094191041911419124191341914419154191641917419184191941920419214192241923419244192541926419274192841929419304193141932419334193441935419364193741938419394194041941419424194341944419454194641947419484194941950419514195241953419544195541956419574195841959419604196141962419634196441965419664196741968419694197041971419724197341974419754197641977419784197941980419814198241983419844198541986419874198841989419904199141992419934199441995419964199741998419994200042001420024200342004420054200642007420084200942010420114201242013420144201542016420174201842019420204202142022420234202442025420264202742028420294203042031420324203342034420354203642037420384203942040420414204242043420444204542046420474204842049420504205142052420534205442055420564205742058420594206042061420624206342064420654206642067420684206942070420714207242073420744207542076420774207842079420804208142082420834208442085420864208742088420894209042091420924209342094420954209642097420984209942100421014210242103421044210542106421074210842109421104211142112421134211442115421164211742118421194212042121421224212342124421254212642127421284212942130421314213242133421344213542136421374213842139421404214142142421434214442145421464214742148421494215042151421524215342154421554215642157421584215942160421614216242163421644216542166421674216842169421704217142172421734217442175421764217742178421794218042181421824218342184421854218642187421884218942190421914219242193421944219542196421974219842199422004220142202422034220442205422064220742208422094221042211422124221342214422154221642217422184221942220422214222242223422244222542226422274222842229422304223142232422334223442235422364223742238422394224042241422424224342244422454224642247422484224942250422514225242253422544225542256422574225842259422604226142262422634226442265422664226742268422694227042271422724227342274422754227642277422784227942280422814228242283422844228542286422874228842289422904229142292422934229442295422964229742298422994230042301423024230342304423054230642307423084230942310423114231242313423144231542316423174231842319423204232142322423234232442325423264232742328423294233042331423324233342334423354233642337423384233942340423414234242343423444234542346423474234842349423504235142352423534235442355423564235742358423594236042361423624236342364423654236642367423684236942370423714237242373423744237542376423774237842379423804238142382423834238442385423864238742388423894239042391423924239342394423954239642397423984239942400424014240242403424044240542406424074240842409424104241142412424134241442415424164241742418424194242042421424224242342424424254242642427424284242942430424314243242433424344243542436424374243842439424404244142442424434244442445424464244742448424494245042451424524245342454424554245642457424584245942460424614246242463424644246542466424674246842469424704247142472424734247442475424764247742478424794248042481424824248342484424854248642487424884248942490424914249242493424944249542496424974249842499425004250142502425034250442505425064250742508425094251042511425124251342514425154251642517425184251942520425214252242523425244252542526425274252842529425304253142532425334253442535425364253742538425394254042541425424254342544425454254642547425484254942550425514255242553425544255542556425574255842559425604256142562425634256442565425664256742568425694257042571425724257342574425754257642577425784257942580425814258242583425844258542586425874258842589425904259142592425934259442595425964259742598425994260042601426024260342604426054260642607426084260942610426114261242613426144261542616426174261842619426204262142622426234262442625426264262742628426294263042631426324263342634426354263642637426384263942640426414264242643426444264542646426474264842649426504265142652426534265442655426564265742658426594266042661426624266342664426654266642667426684266942670426714267242673426744267542676426774267842679426804268142682426834268442685426864268742688426894269042691426924269342694426954269642697426984269942700427014270242703427044270542706427074270842709427104271142712427134271442715427164271742718427194272042721427224272342724427254272642727427284272942730427314273242733427344273542736427374273842739427404274142742427434274442745427464274742748427494275042751427524275342754427554275642757427584275942760427614276242763427644276542766427674276842769427704277142772427734277442775427764277742778427794278042781427824278342784427854278642787427884278942790427914279242793427944279542796427974279842799428004280142802428034280442805428064280742808428094281042811428124281342814428154281642817428184281942820428214282242823428244282542826428274282842829428304283142832428334283442835428364283742838428394284042841428424284342844428454284642847428484284942850428514285242853428544285542856428574285842859428604286142862428634286442865428664286742868428694287042871428724287342874428754287642877428784287942880428814288242883428844288542886428874288842889428904289142892428934289442895428964289742898428994290042901429024290342904
  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. /* jshint globalstrict: false */
  16. /* umdutils ignore */
  17. (function (root, factory) {
  18. 'use strict';
  19. if (typeof define === 'function' && define.amd) {
  20. define('pdfjs-dist/build/pdf.worker', ['exports'], factory);
  21. } else if (typeof exports !== 'undefined') {
  22. factory(exports);
  23. } else {
  24. factory((root.pdfjsDistBuildPdfWorker = {}));
  25. }
  26. }(this, function (exports) {
  27. // Use strict in our context only - users might not want it
  28. 'use strict';
  29. var pdfjsVersion = '1.4.121';
  30. var pdfjsBuild = '51f6aba';
  31. var pdfjsFilePath =
  32. typeof document !== 'undefined' && document.currentScript ?
  33. document.currentScript.src : null;
  34. var pdfjsLibs = {};
  35. (function pdfjsWrapper() {
  36. (function (root, factory) {
  37. {
  38. factory((root.pdfjsCoreArithmeticDecoder = {}));
  39. }
  40. }(this, function (exports) {
  41. /* This class implements the QM Coder decoding as defined in
  42. * JPEG 2000 Part I Final Committee Draft Version 1.0
  43. * Annex C.3 Arithmetic decoding procedure
  44. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  45. *
  46. * The arithmetic decoder is used in conjunction with context models to decode
  47. * JPEG2000 and JBIG2 streams.
  48. */
  49. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  50. // Table C-2
  51. var QeTable = [
  52. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  53. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  54. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  55. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  56. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  57. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  58. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  59. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  60. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  61. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  62. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  63. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  64. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  65. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  66. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  67. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  68. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  69. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  70. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  71. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  72. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  73. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  74. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  75. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  76. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  77. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  78. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  79. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  80. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  81. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  82. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  83. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  84. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  85. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  86. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  87. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  88. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  89. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  90. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  91. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  92. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  93. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  94. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  95. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  96. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  97. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  98. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  99. ];
  100. // C.3.5 Initialisation of the decoder (INITDEC)
  101. function ArithmeticDecoder(data, start, end) {
  102. this.data = data;
  103. this.bp = start;
  104. this.dataEnd = end;
  105. this.chigh = data[start];
  106. this.clow = 0;
  107. this.byteIn();
  108. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  109. this.clow = (this.clow << 7) & 0xFFFF;
  110. this.ct -= 7;
  111. this.a = 0x8000;
  112. }
  113. ArithmeticDecoder.prototype = {
  114. // C.3.4 Compressed data input (BYTEIN)
  115. byteIn: function ArithmeticDecoder_byteIn() {
  116. var data = this.data;
  117. var bp = this.bp;
  118. if (data[bp] === 0xFF) {
  119. var b1 = data[bp + 1];
  120. if (b1 > 0x8F) {
  121. this.clow += 0xFF00;
  122. this.ct = 8;
  123. } else {
  124. bp++;
  125. this.clow += (data[bp] << 9);
  126. this.ct = 7;
  127. this.bp = bp;
  128. }
  129. } else {
  130. bp++;
  131. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  132. this.ct = 8;
  133. this.bp = bp;
  134. }
  135. if (this.clow > 0xFFFF) {
  136. this.chigh += (this.clow >> 16);
  137. this.clow &= 0xFFFF;
  138. }
  139. },
  140. // C.3.2 Decoding a decision (DECODE)
  141. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  142. // contexts are packed into 1 byte:
  143. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  144. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  145. var qeTableIcx = QeTable[cx_index];
  146. var qeIcx = qeTableIcx.qe;
  147. var d;
  148. var a = this.a - qeIcx;
  149. if (this.chigh < qeIcx) {
  150. // exchangeLps
  151. if (a < qeIcx) {
  152. a = qeIcx;
  153. d = cx_mps;
  154. cx_index = qeTableIcx.nmps;
  155. } else {
  156. a = qeIcx;
  157. d = 1 ^ cx_mps;
  158. if (qeTableIcx.switchFlag === 1) {
  159. cx_mps = d;
  160. }
  161. cx_index = qeTableIcx.nlps;
  162. }
  163. } else {
  164. this.chigh -= qeIcx;
  165. if ((a & 0x8000) !== 0) {
  166. this.a = a;
  167. return cx_mps;
  168. }
  169. // exchangeMps
  170. if (a < qeIcx) {
  171. d = 1 ^ cx_mps;
  172. if (qeTableIcx.switchFlag === 1) {
  173. cx_mps = d;
  174. }
  175. cx_index = qeTableIcx.nlps;
  176. } else {
  177. d = cx_mps;
  178. cx_index = qeTableIcx.nmps;
  179. }
  180. }
  181. // C.3.3 renormD;
  182. do {
  183. if (this.ct === 0) {
  184. this.byteIn();
  185. }
  186. a <<= 1;
  187. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  188. this.clow = (this.clow << 1) & 0xFFFF;
  189. this.ct--;
  190. } while ((a & 0x8000) === 0);
  191. this.a = a;
  192. contexts[pos] = cx_index << 1 | cx_mps;
  193. return d;
  194. }
  195. };
  196. return ArithmeticDecoder;
  197. })();
  198. exports.ArithmeticDecoder = ArithmeticDecoder;
  199. }));
  200. (function (root, factory) {
  201. {
  202. factory((root.pdfjsCoreCharsets = {}));
  203. }
  204. }(this, function (exports) {
  205. var ISOAdobeCharset = [
  206. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  207. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  208. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  209. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  210. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  211. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  212. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  213. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  214. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  215. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  216. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  217. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  218. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  219. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  220. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  221. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  222. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  223. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  224. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  225. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  226. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  227. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  228. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  229. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  230. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  231. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  232. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  233. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  234. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  235. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  236. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  237. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  238. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  239. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  240. ];
  241. var ExpertCharset = [
  242. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  243. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  244. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  245. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  246. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  247. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  248. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  249. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  250. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  251. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  252. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  253. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  254. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  255. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  256. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  257. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  258. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  259. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  260. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  261. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  262. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  263. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  264. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  265. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  266. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  267. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  268. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  269. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  270. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  271. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  272. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  273. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  274. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  275. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  276. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  277. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  278. 'Ydieresissmall'
  279. ];
  280. var ExpertSubsetCharset = [
  281. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  282. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  283. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  284. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  285. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  286. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  287. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  288. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  289. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  290. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  291. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  292. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  293. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  294. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  295. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  296. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  297. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  298. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  299. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  300. 'periodinferior', 'commainferior'
  301. ];
  302. exports.ISOAdobeCharset = ISOAdobeCharset;
  303. exports.ExpertCharset = ExpertCharset;
  304. exports.ExpertSubsetCharset = ExpertSubsetCharset;
  305. }));
  306. (function (root, factory) {
  307. {
  308. factory((root.pdfjsCoreEncodings = {}));
  309. }
  310. }(this, function (exports) {
  311. var ExpertEncoding = [
  312. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  313. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  314. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  315. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  316. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  317. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  318. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  319. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  320. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  321. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  322. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  323. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  324. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  325. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  326. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  327. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  328. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  329. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  330. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  331. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  332. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  333. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  334. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  335. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  336. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  337. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  338. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  339. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  340. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  341. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  342. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  343. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  344. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  345. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  346. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  347. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  348. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  349. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  350. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  351. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  352. 'Ydieresissmall'];
  353. var MacExpertEncoding = [
  354. '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  355. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  356. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  357. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  358. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  359. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  360. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  361. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  362. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  363. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  364. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  365. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  366. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  367. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  368. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  369. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  370. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  371. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  372. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  373. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  374. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  375. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  376. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  377. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  378. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  379. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  380. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  381. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  382. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  383. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  384. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  385. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  386. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  387. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  388. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  389. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  390. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  391. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  392. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  393. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'];
  394. var MacRomanEncoding = [
  395. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  396. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  397. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  398. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  399. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  400. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  401. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  402. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  403. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  404. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  405. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  406. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  407. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  408. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  409. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  410. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  411. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  412. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  413. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  414. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  415. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  416. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  417. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  418. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  419. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  420. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  421. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  422. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  423. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  424. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  425. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  426. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  427. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  428. 'ogonek', 'caron'];
  429. var StandardEncoding = [
  430. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  431. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  432. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  433. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  434. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  435. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  436. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  437. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  438. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  439. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  440. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  441. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  442. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  443. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  444. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  445. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  446. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  447. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  448. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  449. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  450. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  451. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  452. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  453. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  454. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'];
  455. var WinAnsiEncoding = [
  456. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  457. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  458. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  459. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  460. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  461. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  462. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  463. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  464. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  465. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  466. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  467. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  468. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  469. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  470. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  471. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  472. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  473. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  474. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  475. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  476. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  477. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  478. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  479. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  480. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  481. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  482. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  483. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  484. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  485. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  486. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  487. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  488. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  489. 'ydieresis'];
  490. var SymbolSetEncoding = [
  491. '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  492. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  493. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  494. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  495. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  496. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  497. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  498. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  499. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  500. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  501. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  502. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  503. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  504. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  505. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  506. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  507. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  508. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  509. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  510. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  511. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  512. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  513. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  514. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  515. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  516. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  517. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  518. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  519. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  520. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  521. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  522. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  523. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  524. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  525. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  526. 'bracerightbt'];
  527. var ZapfDingbatsEncoding = [
  528. '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  529. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  530. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  531. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  532. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  533. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  534. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  535. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  536. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  537. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  538. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  539. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  540. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  541. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  542. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  543. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  544. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  545. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  546. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  547. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  548. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  549. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  550. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  551. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191'];
  552. function getEncoding(encodingName) {
  553. switch (encodingName) {
  554. case 'WinAnsiEncoding':
  555. return WinAnsiEncoding;
  556. case 'StandardEncoding':
  557. return StandardEncoding;
  558. case 'MacRomanEncoding':
  559. return MacRomanEncoding;
  560. case 'SymbolSetEncoding':
  561. return SymbolSetEncoding;
  562. case 'ZapfDingbatsEncoding':
  563. return ZapfDingbatsEncoding;
  564. case 'ExpertEncoding':
  565. return ExpertEncoding;
  566. case 'MacExpertEncoding':
  567. return MacExpertEncoding;
  568. default:
  569. return null;
  570. }
  571. }
  572. exports.WinAnsiEncoding = WinAnsiEncoding;
  573. exports.StandardEncoding = StandardEncoding;
  574. exports.MacRomanEncoding = MacRomanEncoding;
  575. exports.SymbolSetEncoding = SymbolSetEncoding;
  576. exports.ZapfDingbatsEncoding = ZapfDingbatsEncoding;
  577. exports.ExpertEncoding = ExpertEncoding;
  578. exports.getEncoding = getEncoding;
  579. }));
  580. (function (root, factory) {
  581. {
  582. factory((root.pdfjsCoreJpg = {}));
  583. }
  584. }(this, function (exports) {
  585. /*
  586. This code was forked from https://github.com/notmasteryet/jpgjs. The original
  587. version was created by github user notmasteryet
  588. - The JPEG specification can be found in the ITU CCITT Recommendation T.81
  589. (www.w3.org/Graphics/JPEG/itu-t81.pdf)
  590. - The JFIF specification can be found in the JPEG File Interchange Format
  591. (www.w3.org/Graphics/JPEG/jfif3.pdf)
  592. - The Adobe Application-Specific JPEG markers in the Supporting the DCT Filters
  593. in PostScript Level 2, Technical Note #5116
  594. (partners.adobe.com/public/developer/en/ps/sdk/5116.DCT_Filter.pdf)
  595. */
  596. var JpegImage = (function jpegImage() {
  597. var dctZigZag = new Uint8Array([
  598. 0,
  599. 1, 8,
  600. 16, 9, 2,
  601. 3, 10, 17, 24,
  602. 32, 25, 18, 11, 4,
  603. 5, 12, 19, 26, 33, 40,
  604. 48, 41, 34, 27, 20, 13, 6,
  605. 7, 14, 21, 28, 35, 42, 49, 56,
  606. 57, 50, 43, 36, 29, 22, 15,
  607. 23, 30, 37, 44, 51, 58,
  608. 59, 52, 45, 38, 31,
  609. 39, 46, 53, 60,
  610. 61, 54, 47,
  611. 55, 62,
  612. 63
  613. ]);
  614. var dctCos1 = 4017; // cos(pi/16)
  615. var dctSin1 = 799; // sin(pi/16)
  616. var dctCos3 = 3406; // cos(3*pi/16)
  617. var dctSin3 = 2276; // sin(3*pi/16)
  618. var dctCos6 = 1567; // cos(6*pi/16)
  619. var dctSin6 = 3784; // sin(6*pi/16)
  620. var dctSqrt2 = 5793; // sqrt(2)
  621. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  622. function constructor() {
  623. }
  624. function buildHuffmanTable(codeLengths, values) {
  625. var k = 0, code = [], i, j, length = 16;
  626. while (length > 0 && !codeLengths[length - 1]) {
  627. length--;
  628. }
  629. code.push({children: [], index: 0});
  630. var p = code[0], q;
  631. for (i = 0; i < length; i++) {
  632. for (j = 0; j < codeLengths[i]; j++) {
  633. p = code.pop();
  634. p.children[p.index] = values[k];
  635. while (p.index > 0) {
  636. p = code.pop();
  637. }
  638. p.index++;
  639. code.push(p);
  640. while (code.length <= i) {
  641. code.push(q = {children: [], index: 0});
  642. p.children[p.index] = q.children;
  643. p = q;
  644. }
  645. k++;
  646. }
  647. if (i + 1 < length) {
  648. // p here points to last code
  649. code.push(q = {children: [], index: 0});
  650. p.children[p.index] = q.children;
  651. p = q;
  652. }
  653. }
  654. return code[0].children;
  655. }
  656. function getBlockBufferOffset(component, row, col) {
  657. return 64 * ((component.blocksPerLine + 1) * row + col);
  658. }
  659. function decodeScan(data, offset, frame, components, resetInterval,
  660. spectralStart, spectralEnd, successivePrev, successive) {
  661. var mcusPerLine = frame.mcusPerLine;
  662. var progressive = frame.progressive;
  663. var startOffset = offset, bitsData = 0, bitsCount = 0;
  664. function readBit() {
  665. if (bitsCount > 0) {
  666. bitsCount--;
  667. return (bitsData >> bitsCount) & 1;
  668. }
  669. bitsData = data[offset++];
  670. if (bitsData === 0xFF) {
  671. var nextByte = data[offset++];
  672. if (nextByte) {
  673. throw 'unexpected marker: ' +
  674. ((bitsData << 8) | nextByte).toString(16);
  675. }
  676. // unstuff 0
  677. }
  678. bitsCount = 7;
  679. return bitsData >>> 7;
  680. }
  681. function decodeHuffman(tree) {
  682. var node = tree;
  683. while (true) {
  684. node = node[readBit()];
  685. if (typeof node === 'number') {
  686. return node;
  687. }
  688. if (typeof node !== 'object') {
  689. throw 'invalid huffman sequence';
  690. }
  691. }
  692. }
  693. function receive(length) {
  694. var n = 0;
  695. while (length > 0) {
  696. n = (n << 1) | readBit();
  697. length--;
  698. }
  699. return n;
  700. }
  701. function receiveAndExtend(length) {
  702. if (length === 1) {
  703. return readBit() === 1 ? 1 : -1;
  704. }
  705. var n = receive(length);
  706. if (n >= 1 << (length - 1)) {
  707. return n;
  708. }
  709. return n + (-1 << length) + 1;
  710. }
  711. function decodeBaseline(component, offset) {
  712. var t = decodeHuffman(component.huffmanTableDC);
  713. var diff = t === 0 ? 0 : receiveAndExtend(t);
  714. component.blockData[offset] = (component.pred += diff);
  715. var k = 1;
  716. while (k < 64) {
  717. var rs = decodeHuffman(component.huffmanTableAC);
  718. var s = rs & 15, r = rs >> 4;
  719. if (s === 0) {
  720. if (r < 15) {
  721. break;
  722. }
  723. k += 16;
  724. continue;
  725. }
  726. k += r;
  727. var z = dctZigZag[k];
  728. component.blockData[offset + z] = receiveAndExtend(s);
  729. k++;
  730. }
  731. }
  732. function decodeDCFirst(component, offset) {
  733. var t = decodeHuffman(component.huffmanTableDC);
  734. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  735. component.blockData[offset] = (component.pred += diff);
  736. }
  737. function decodeDCSuccessive(component, offset) {
  738. component.blockData[offset] |= readBit() << successive;
  739. }
  740. var eobrun = 0;
  741. function decodeACFirst(component, offset) {
  742. if (eobrun > 0) {
  743. eobrun--;
  744. return;
  745. }
  746. var k = spectralStart, e = spectralEnd;
  747. while (k <= e) {
  748. var rs = decodeHuffman(component.huffmanTableAC);
  749. var s = rs & 15, r = rs >> 4;
  750. if (s === 0) {
  751. if (r < 15) {
  752. eobrun = receive(r) + (1 << r) - 1;
  753. break;
  754. }
  755. k += 16;
  756. continue;
  757. }
  758. k += r;
  759. var z = dctZigZag[k];
  760. component.blockData[offset + z] =
  761. receiveAndExtend(s) * (1 << successive);
  762. k++;
  763. }
  764. }
  765. var successiveACState = 0, successiveACNextValue;
  766. function decodeACSuccessive(component, offset) {
  767. var k = spectralStart;
  768. var e = spectralEnd;
  769. var r = 0;
  770. var s;
  771. var rs;
  772. while (k <= e) {
  773. var z = dctZigZag[k];
  774. switch (successiveACState) {
  775. case 0: // initial state
  776. rs = decodeHuffman(component.huffmanTableAC);
  777. s = rs & 15;
  778. r = rs >> 4;
  779. if (s === 0) {
  780. if (r < 15) {
  781. eobrun = receive(r) + (1 << r);
  782. successiveACState = 4;
  783. } else {
  784. r = 16;
  785. successiveACState = 1;
  786. }
  787. } else {
  788. if (s !== 1) {
  789. throw 'invalid ACn encoding';
  790. }
  791. successiveACNextValue = receiveAndExtend(s);
  792. successiveACState = r ? 2 : 3;
  793. }
  794. continue;
  795. case 1: // skipping r zero items
  796. case 2:
  797. if (component.blockData[offset + z]) {
  798. component.blockData[offset + z] += (readBit() << successive);
  799. } else {
  800. r--;
  801. if (r === 0) {
  802. successiveACState = successiveACState === 2 ? 3 : 0;
  803. }
  804. }
  805. break;
  806. case 3: // set value for a zero item
  807. if (component.blockData[offset + z]) {
  808. component.blockData[offset + z] += (readBit() << successive);
  809. } else {
  810. component.blockData[offset + z] =
  811. successiveACNextValue << successive;
  812. successiveACState = 0;
  813. }
  814. break;
  815. case 4: // eob
  816. if (component.blockData[offset + z]) {
  817. component.blockData[offset + z] += (readBit() << successive);
  818. }
  819. break;
  820. }
  821. k++;
  822. }
  823. if (successiveACState === 4) {
  824. eobrun--;
  825. if (eobrun === 0) {
  826. successiveACState = 0;
  827. }
  828. }
  829. }
  830. function decodeMcu(component, decode, mcu, row, col) {
  831. var mcuRow = (mcu / mcusPerLine) | 0;
  832. var mcuCol = mcu % mcusPerLine;
  833. var blockRow = mcuRow * component.v + row;
  834. var blockCol = mcuCol * component.h + col;
  835. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  836. decode(component, offset);
  837. }
  838. function decodeBlock(component, decode, mcu) {
  839. var blockRow = (mcu / component.blocksPerLine) | 0;
  840. var blockCol = mcu % component.blocksPerLine;
  841. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  842. decode(component, offset);
  843. }
  844. var componentsLength = components.length;
  845. var component, i, j, k, n;
  846. var decodeFn;
  847. if (progressive) {
  848. if (spectralStart === 0) {
  849. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  850. } else {
  851. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  852. }
  853. } else {
  854. decodeFn = decodeBaseline;
  855. }
  856. var mcu = 0, marker;
  857. var mcuExpected;
  858. if (componentsLength === 1) {
  859. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  860. } else {
  861. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  862. }
  863. if (!resetInterval) {
  864. resetInterval = mcuExpected;
  865. }
  866. var h, v;
  867. while (mcu < mcuExpected) {
  868. // reset interval stuff
  869. for (i = 0; i < componentsLength; i++) {
  870. components[i].pred = 0;
  871. }
  872. eobrun = 0;
  873. if (componentsLength === 1) {
  874. component = components[0];
  875. for (n = 0; n < resetInterval; n++) {
  876. decodeBlock(component, decodeFn, mcu);
  877. mcu++;
  878. }
  879. } else {
  880. for (n = 0; n < resetInterval; n++) {
  881. for (i = 0; i < componentsLength; i++) {
  882. component = components[i];
  883. h = component.h;
  884. v = component.v;
  885. for (j = 0; j < v; j++) {
  886. for (k = 0; k < h; k++) {
  887. decodeMcu(component, decodeFn, mcu, j, k);
  888. }
  889. }
  890. }
  891. mcu++;
  892. }
  893. }
  894. // find marker
  895. bitsCount = 0;
  896. marker = (data[offset] << 8) | data[offset + 1];
  897. if (marker <= 0xFF00) {
  898. throw 'marker was not found';
  899. }
  900. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  901. offset += 2;
  902. } else {
  903. break;
  904. }
  905. }
  906. return offset - startOffset;
  907. }
  908. // A port of poppler's IDCT method which in turn is taken from:
  909. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  910. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  911. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  912. // 988-991.
  913. function quantizeAndInverse(component, blockBufferOffset, p) {
  914. var qt = component.quantizationTable, blockData = component.blockData;
  915. var v0, v1, v2, v3, v4, v5, v6, v7;
  916. var p0, p1, p2, p3, p4, p5, p6, p7;
  917. var t;
  918. // inverse DCT on rows
  919. for (var row = 0; row < 64; row += 8) {
  920. // gather block data
  921. p0 = blockData[blockBufferOffset + row];
  922. p1 = blockData[blockBufferOffset + row + 1];
  923. p2 = blockData[blockBufferOffset + row + 2];
  924. p3 = blockData[blockBufferOffset + row + 3];
  925. p4 = blockData[blockBufferOffset + row + 4];
  926. p5 = blockData[blockBufferOffset + row + 5];
  927. p6 = blockData[blockBufferOffset + row + 6];
  928. p7 = blockData[blockBufferOffset + row + 7];
  929. // dequant p0
  930. p0 *= qt[row];
  931. // check for all-zero AC coefficients
  932. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  933. t = (dctSqrt2 * p0 + 512) >> 10;
  934. p[row] = t;
  935. p[row + 1] = t;
  936. p[row + 2] = t;
  937. p[row + 3] = t;
  938. p[row + 4] = t;
  939. p[row + 5] = t;
  940. p[row + 6] = t;
  941. p[row + 7] = t;
  942. continue;
  943. }
  944. // dequant p1 ... p7
  945. p1 *= qt[row + 1];
  946. p2 *= qt[row + 2];
  947. p3 *= qt[row + 3];
  948. p4 *= qt[row + 4];
  949. p5 *= qt[row + 5];
  950. p6 *= qt[row + 6];
  951. p7 *= qt[row + 7];
  952. // stage 4
  953. v0 = (dctSqrt2 * p0 + 128) >> 8;
  954. v1 = (dctSqrt2 * p4 + 128) >> 8;
  955. v2 = p2;
  956. v3 = p6;
  957. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  958. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  959. v5 = p3 << 4;
  960. v6 = p5 << 4;
  961. // stage 3
  962. v0 = (v0 + v1 + 1) >> 1;
  963. v1 = v0 - v1;
  964. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  965. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  966. v3 = t;
  967. v4 = (v4 + v6 + 1) >> 1;
  968. v6 = v4 - v6;
  969. v7 = (v7 + v5 + 1) >> 1;
  970. v5 = v7 - v5;
  971. // stage 2
  972. v0 = (v0 + v3 + 1) >> 1;
  973. v3 = v0 - v3;
  974. v1 = (v1 + v2 + 1) >> 1;
  975. v2 = v1 - v2;
  976. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  977. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  978. v7 = t;
  979. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  980. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  981. v6 = t;
  982. // stage 1
  983. p[row] = v0 + v7;
  984. p[row + 7] = v0 - v7;
  985. p[row + 1] = v1 + v6;
  986. p[row + 6] = v1 - v6;
  987. p[row + 2] = v2 + v5;
  988. p[row + 5] = v2 - v5;
  989. p[row + 3] = v3 + v4;
  990. p[row + 4] = v3 - v4;
  991. }
  992. // inverse DCT on columns
  993. for (var col = 0; col < 8; ++col) {
  994. p0 = p[col];
  995. p1 = p[col + 8];
  996. p2 = p[col + 16];
  997. p3 = p[col + 24];
  998. p4 = p[col + 32];
  999. p5 = p[col + 40];
  1000. p6 = p[col + 48];
  1001. p7 = p[col + 56];
  1002. // check for all-zero AC coefficients
  1003. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  1004. t = (dctSqrt2 * p0 + 8192) >> 14;
  1005. // convert to 8 bit
  1006. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  1007. blockData[blockBufferOffset + col] = t;
  1008. blockData[blockBufferOffset + col + 8] = t;
  1009. blockData[blockBufferOffset + col + 16] = t;
  1010. blockData[blockBufferOffset + col + 24] = t;
  1011. blockData[blockBufferOffset + col + 32] = t;
  1012. blockData[blockBufferOffset + col + 40] = t;
  1013. blockData[blockBufferOffset + col + 48] = t;
  1014. blockData[blockBufferOffset + col + 56] = t;
  1015. continue;
  1016. }
  1017. // stage 4
  1018. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  1019. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  1020. v2 = p2;
  1021. v3 = p6;
  1022. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  1023. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  1024. v5 = p3;
  1025. v6 = p5;
  1026. // stage 3
  1027. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  1028. // converting to UInt8 range later.
  1029. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  1030. v1 = v0 - v1;
  1031. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  1032. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  1033. v3 = t;
  1034. v4 = (v4 + v6 + 1) >> 1;
  1035. v6 = v4 - v6;
  1036. v7 = (v7 + v5 + 1) >> 1;
  1037. v5 = v7 - v5;
  1038. // stage 2
  1039. v0 = (v0 + v3 + 1) >> 1;
  1040. v3 = v0 - v3;
  1041. v1 = (v1 + v2 + 1) >> 1;
  1042. v2 = v1 - v2;
  1043. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  1044. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  1045. v7 = t;
  1046. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  1047. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  1048. v6 = t;
  1049. // stage 1
  1050. p0 = v0 + v7;
  1051. p7 = v0 - v7;
  1052. p1 = v1 + v6;
  1053. p6 = v1 - v6;
  1054. p2 = v2 + v5;
  1055. p5 = v2 - v5;
  1056. p3 = v3 + v4;
  1057. p4 = v3 - v4;
  1058. // convert to 8-bit integers
  1059. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  1060. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  1061. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  1062. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  1063. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  1064. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  1065. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  1066. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  1067. // store block data
  1068. blockData[blockBufferOffset + col] = p0;
  1069. blockData[blockBufferOffset + col + 8] = p1;
  1070. blockData[blockBufferOffset + col + 16] = p2;
  1071. blockData[blockBufferOffset + col + 24] = p3;
  1072. blockData[blockBufferOffset + col + 32] = p4;
  1073. blockData[blockBufferOffset + col + 40] = p5;
  1074. blockData[blockBufferOffset + col + 48] = p6;
  1075. blockData[blockBufferOffset + col + 56] = p7;
  1076. }
  1077. }
  1078. function buildComponentData(frame, component) {
  1079. var blocksPerLine = component.blocksPerLine;
  1080. var blocksPerColumn = component.blocksPerColumn;
  1081. var computationBuffer = new Int16Array(64);
  1082. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  1083. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  1084. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  1085. quantizeAndInverse(component, offset, computationBuffer);
  1086. }
  1087. }
  1088. return component.blockData;
  1089. }
  1090. function clamp0to255(a) {
  1091. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  1092. }
  1093. constructor.prototype = {
  1094. parse: function parse(data) {
  1095. function readUint16() {
  1096. var value = (data[offset] << 8) | data[offset + 1];
  1097. offset += 2;
  1098. return value;
  1099. }
  1100. function readDataBlock() {
  1101. var length = readUint16();
  1102. var array = data.subarray(offset, offset + length - 2);
  1103. offset += array.length;
  1104. return array;
  1105. }
  1106. function prepareComponents(frame) {
  1107. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  1108. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  1109. for (var i = 0; i < frame.components.length; i++) {
  1110. component = frame.components[i];
  1111. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  1112. component.h / frame.maxH);
  1113. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  1114. component.v / frame.maxV);
  1115. var blocksPerLineForMcu = mcusPerLine * component.h;
  1116. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  1117. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  1118. (blocksPerLineForMcu + 1);
  1119. component.blockData = new Int16Array(blocksBufferSize);
  1120. component.blocksPerLine = blocksPerLine;
  1121. component.blocksPerColumn = blocksPerColumn;
  1122. }
  1123. frame.mcusPerLine = mcusPerLine;
  1124. frame.mcusPerColumn = mcusPerColumn;
  1125. }
  1126. var offset = 0;
  1127. var jfif = null;
  1128. var adobe = null;
  1129. var frame, resetInterval;
  1130. var quantizationTables = [];
  1131. var huffmanTablesAC = [], huffmanTablesDC = [];
  1132. var fileMarker = readUint16();
  1133. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  1134. throw 'SOI not found';
  1135. }
  1136. fileMarker = readUint16();
  1137. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  1138. var i, j, l;
  1139. switch(fileMarker) {
  1140. case 0xFFE0: // APP0 (Application Specific)
  1141. case 0xFFE1: // APP1
  1142. case 0xFFE2: // APP2
  1143. case 0xFFE3: // APP3
  1144. case 0xFFE4: // APP4
  1145. case 0xFFE5: // APP5
  1146. case 0xFFE6: // APP6
  1147. case 0xFFE7: // APP7
  1148. case 0xFFE8: // APP8
  1149. case 0xFFE9: // APP9
  1150. case 0xFFEA: // APP10
  1151. case 0xFFEB: // APP11
  1152. case 0xFFEC: // APP12
  1153. case 0xFFED: // APP13
  1154. case 0xFFEE: // APP14
  1155. case 0xFFEF: // APP15
  1156. case 0xFFFE: // COM (Comment)
  1157. var appData = readDataBlock();
  1158. if (fileMarker === 0xFFE0) {
  1159. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  1160. appData[2] === 0x49 && appData[3] === 0x46 &&
  1161. appData[4] === 0) { // 'JFIF\x00'
  1162. jfif = {
  1163. version: { major: appData[5], minor: appData[6] },
  1164. densityUnits: appData[7],
  1165. xDensity: (appData[8] << 8) | appData[9],
  1166. yDensity: (appData[10] << 8) | appData[11],
  1167. thumbWidth: appData[12],
  1168. thumbHeight: appData[13],
  1169. thumbData: appData.subarray(14, 14 +
  1170. 3 * appData[12] * appData[13])
  1171. };
  1172. }
  1173. }
  1174. // TODO APP1 - Exif
  1175. if (fileMarker === 0xFFEE) {
  1176. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  1177. appData[2] === 0x6F && appData[3] === 0x62 &&
  1178. appData[4] === 0x65) { // 'Adobe'
  1179. adobe = {
  1180. version: (appData[5] << 8) | appData[6],
  1181. flags0: (appData[7] << 8) | appData[8],
  1182. flags1: (appData[9] << 8) | appData[10],
  1183. transformCode: appData[11]
  1184. };
  1185. }
  1186. }
  1187. break;
  1188. case 0xFFDB: // DQT (Define Quantization Tables)
  1189. var quantizationTablesLength = readUint16();
  1190. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  1191. var z;
  1192. while (offset < quantizationTablesEnd) {
  1193. var quantizationTableSpec = data[offset++];
  1194. var tableData = new Uint16Array(64);
  1195. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  1196. for (j = 0; j < 64; j++) {
  1197. z = dctZigZag[j];
  1198. tableData[z] = data[offset++];
  1199. }
  1200. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  1201. for (j = 0; j < 64; j++) {
  1202. z = dctZigZag[j];
  1203. tableData[z] = readUint16();
  1204. }
  1205. } else {
  1206. throw 'DQT: invalid table spec';
  1207. }
  1208. quantizationTables[quantizationTableSpec & 15] = tableData;
  1209. }
  1210. break;
  1211. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  1212. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  1213. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  1214. if (frame) {
  1215. throw 'Only single frame JPEGs supported';
  1216. }
  1217. readUint16(); // skip data length
  1218. frame = {};
  1219. frame.extended = (fileMarker === 0xFFC1);
  1220. frame.progressive = (fileMarker === 0xFFC2);
  1221. frame.precision = data[offset++];
  1222. frame.scanLines = readUint16();
  1223. frame.samplesPerLine = readUint16();
  1224. frame.components = [];
  1225. frame.componentIds = {};
  1226. var componentsCount = data[offset++], componentId;
  1227. var maxH = 0, maxV = 0;
  1228. for (i = 0; i < componentsCount; i++) {
  1229. componentId = data[offset];
  1230. var h = data[offset + 1] >> 4;
  1231. var v = data[offset + 1] & 15;
  1232. if (maxH < h) {
  1233. maxH = h;
  1234. }
  1235. if (maxV < v) {
  1236. maxV = v;
  1237. }
  1238. var qId = data[offset + 2];
  1239. l = frame.components.push({
  1240. h: h,
  1241. v: v,
  1242. quantizationTable: quantizationTables[qId]
  1243. });
  1244. frame.componentIds[componentId] = l - 1;
  1245. offset += 3;
  1246. }
  1247. frame.maxH = maxH;
  1248. frame.maxV = maxV;
  1249. prepareComponents(frame);
  1250. break;
  1251. case 0xFFC4: // DHT (Define Huffman Tables)
  1252. var huffmanLength = readUint16();
  1253. for (i = 2; i < huffmanLength;) {
  1254. var huffmanTableSpec = data[offset++];
  1255. var codeLengths = new Uint8Array(16);
  1256. var codeLengthSum = 0;
  1257. for (j = 0; j < 16; j++, offset++) {
  1258. codeLengthSum += (codeLengths[j] = data[offset]);
  1259. }
  1260. var huffmanValues = new Uint8Array(codeLengthSum);
  1261. for (j = 0; j < codeLengthSum; j++, offset++) {
  1262. huffmanValues[j] = data[offset];
  1263. }
  1264. i += 17 + codeLengthSum;
  1265. ((huffmanTableSpec >> 4) === 0 ?
  1266. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  1267. buildHuffmanTable(codeLengths, huffmanValues);
  1268. }
  1269. break;
  1270. case 0xFFDD: // DRI (Define Restart Interval)
  1271. readUint16(); // skip data length
  1272. resetInterval = readUint16();
  1273. break;
  1274. case 0xFFDA: // SOS (Start of Scan)
  1275. var scanLength = readUint16();
  1276. var selectorsCount = data[offset++];
  1277. var components = [], component;
  1278. for (i = 0; i < selectorsCount; i++) {
  1279. var componentIndex = frame.componentIds[data[offset++]];
  1280. component = frame.components[componentIndex];
  1281. var tableSpec = data[offset++];
  1282. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  1283. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  1284. components.push(component);
  1285. }
  1286. var spectralStart = data[offset++];
  1287. var spectralEnd = data[offset++];
  1288. var successiveApproximation = data[offset++];
  1289. var processed = decodeScan(data, offset,
  1290. frame, components, resetInterval,
  1291. spectralStart, spectralEnd,
  1292. successiveApproximation >> 4, successiveApproximation & 15);
  1293. offset += processed;
  1294. break;
  1295. case 0xFFFF: // Fill bytes
  1296. if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
  1297. offset--;
  1298. }
  1299. break;
  1300. default:
  1301. if (data[offset - 3] === 0xFF &&
  1302. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  1303. // could be incorrect encoding -- last 0xFF byte of the previous
  1304. // block was eaten by the encoder
  1305. offset -= 3;
  1306. break;
  1307. }
  1308. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  1309. }
  1310. fileMarker = readUint16();
  1311. }
  1312. this.width = frame.samplesPerLine;
  1313. this.height = frame.scanLines;
  1314. this.jfif = jfif;
  1315. this.adobe = adobe;
  1316. this.components = [];
  1317. for (i = 0; i < frame.components.length; i++) {
  1318. component = frame.components[i];
  1319. this.components.push({
  1320. output: buildComponentData(frame, component),
  1321. scaleX: component.h / frame.maxH,
  1322. scaleY: component.v / frame.maxV,
  1323. blocksPerLine: component.blocksPerLine,
  1324. blocksPerColumn: component.blocksPerColumn
  1325. });
  1326. }
  1327. this.numComponents = this.components.length;
  1328. },
  1329. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  1330. var scaleX = this.width / width, scaleY = this.height / height;
  1331. var component, componentScaleX, componentScaleY, blocksPerScanline;
  1332. var x, y, i, j, k;
  1333. var index;
  1334. var offset = 0;
  1335. var output;
  1336. var numComponents = this.components.length;
  1337. var dataLength = width * height * numComponents;
  1338. var data = new Uint8Array(dataLength);
  1339. var xScaleBlockOffset = new Uint32Array(width);
  1340. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  1341. for (i = 0; i < numComponents; i++) {
  1342. component = this.components[i];
  1343. componentScaleX = component.scaleX * scaleX;
  1344. componentScaleY = component.scaleY * scaleY;
  1345. offset = i;
  1346. output = component.output;
  1347. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  1348. // precalculate the xScaleBlockOffset
  1349. for (x = 0; x < width; x++) {
  1350. j = 0 | (x * componentScaleX);
  1351. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  1352. }
  1353. // linearize the blocks of the component
  1354. for (y = 0; y < height; y++) {
  1355. j = 0 | (y * componentScaleY);
  1356. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  1357. for (x = 0; x < width; x++) {
  1358. data[offset] = output[index + xScaleBlockOffset[x]];
  1359. offset += numComponents;
  1360. }
  1361. }
  1362. }
  1363. // decodeTransform contains pairs of multiplier (-256..256) and additive
  1364. var transform = this.decodeTransform;
  1365. if (transform) {
  1366. for (i = 0; i < dataLength;) {
  1367. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  1368. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  1369. }
  1370. }
  1371. }
  1372. return data;
  1373. },
  1374. _isColorConversionNeeded: function isColorConversionNeeded() {
  1375. if (this.adobe && this.adobe.transformCode) {
  1376. // The adobe transform marker overrides any previous setting
  1377. return true;
  1378. } else if (this.numComponents === 3) {
  1379. return true;
  1380. } else {
  1381. return false;
  1382. }
  1383. },
  1384. _convertYccToRgb: function convertYccToRgb(data) {
  1385. var Y, Cb, Cr;
  1386. for (var i = 0, length = data.length; i < length; i += 3) {
  1387. Y = data[i ];
  1388. Cb = data[i + 1];
  1389. Cr = data[i + 2];
  1390. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  1391. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  1392. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  1393. }
  1394. return data;
  1395. },
  1396. _convertYcckToRgb: function convertYcckToRgb(data) {
  1397. var Y, Cb, Cr, k;
  1398. var offset = 0;
  1399. for (var i = 0, length = data.length; i < length; i += 4) {
  1400. Y = data[i];
  1401. Cb = data[i + 1];
  1402. Cr = data[i + 2];
  1403. k = data[i + 3];
  1404. var r = -122.67195406894 +
  1405. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  1406. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  1407. 0.154362151871126) +
  1408. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  1409. 0.00477271405408747 * k + 1.53380253221734) +
  1410. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  1411. 0.48357088451265) +
  1412. k * (-0.000336197177618394 * k + 0.484791561490776);
  1413. var g = 107.268039397724 +
  1414. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  1415. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  1416. 0.176491792462875) +
  1417. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  1418. 0.000770482631801132 * k - 0.151051492775562) +
  1419. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  1420. 0.25802910206845) +
  1421. k * (-0.000318913117588328 * k - 0.213742400323665);
  1422. var b = -20.810012546947 +
  1423. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  1424. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  1425. 0.814272968359295) +
  1426. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  1427. 0.000560833691242812 * k - 0.195152027534049) +
  1428. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  1429. 0.116935020465145) +
  1430. k * (-0.000343531996510555 * k + 0.24165260232407);
  1431. data[offset++] = clamp0to255(r);
  1432. data[offset++] = clamp0to255(g);
  1433. data[offset++] = clamp0to255(b);
  1434. }
  1435. return data;
  1436. },
  1437. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  1438. var Y, Cb, Cr;
  1439. for (var i = 0, length = data.length; i < length; i += 4) {
  1440. Y = data[i];
  1441. Cb = data[i + 1];
  1442. Cr = data[i + 2];
  1443. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  1444. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  1445. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  1446. // K in data[i + 3] is unchanged
  1447. }
  1448. return data;
  1449. },
  1450. _convertCmykToRgb: function convertCmykToRgb(data) {
  1451. var c, m, y, k;
  1452. var offset = 0;
  1453. var min = -255 * 255 * 255;
  1454. var scale = 1 / 255 / 255;
  1455. for (var i = 0, length = data.length; i < length; i += 4) {
  1456. c = data[i];
  1457. m = data[i + 1];
  1458. y = data[i + 2];
  1459. k = data[i + 3];
  1460. var r =
  1461. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  1462. 18.82290502165302 * y + 212.25662451639585 * k -
  1463. 72734.4411664936) +
  1464. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  1465. 17.873870861415444 * k - 1401.7366389350734) +
  1466. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  1467. 4465.541406466231) -
  1468. k * (21.86122147463605 * k + 48317.86113160301);
  1469. var g =
  1470. c * (8.841041422036149 * c + 60.118027045597366 * m +
  1471. 6.871425592049007 * y + 31.159100130055922 * k -
  1472. 20220.756542821975) +
  1473. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  1474. 131.35250912493976 * k - 48691.05921601825) +
  1475. y * (4.444339102852739 * y + 9.8632861493405 * k -
  1476. 6341.191035517494) -
  1477. k * (20.737325471181034 * k + 47890.15695978492);
  1478. var b =
  1479. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  1480. 30.89978309703729 * y - 0.23883238689178934 * k -
  1481. 3616.812083916688) +
  1482. m * (10.49593273432072 * m + 63.02378494754052 * y +
  1483. 50.606957656360734 * k - 28620.90484698408) +
  1484. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  1485. 49363.43385999684) -
  1486. k * (22.33816807309886 * k + 45932.16563550634);
  1487. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  1488. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  1489. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  1490. }
  1491. return data;
  1492. },
  1493. getData: function getData(width, height, forceRGBoutput) {
  1494. if (this.numComponents > 4) {
  1495. throw 'Unsupported color mode';
  1496. }
  1497. // type of data: Uint8Array(width * height * numComponents)
  1498. var data = this._getLinearizedBlockData(width, height);
  1499. if (this.numComponents === 1 && forceRGBoutput) {
  1500. var dataLength = data.length;
  1501. var rgbData = new Uint8Array(dataLength * 3);
  1502. var offset = 0;
  1503. for (var i = 0; i < dataLength; i++) {
  1504. var grayColor = data[i];
  1505. rgbData[offset++] = grayColor;
  1506. rgbData[offset++] = grayColor;
  1507. rgbData[offset++] = grayColor;
  1508. }
  1509. return rgbData;
  1510. } else if (this.numComponents === 3) {
  1511. return this._convertYccToRgb(data);
  1512. } else if (this.numComponents === 4) {
  1513. if (this._isColorConversionNeeded()) {
  1514. if (forceRGBoutput) {
  1515. return this._convertYcckToRgb(data);
  1516. } else {
  1517. return this._convertYcckToCmyk(data);
  1518. }
  1519. } else if (forceRGBoutput) {
  1520. return this._convertCmykToRgb(data);
  1521. }
  1522. }
  1523. return data;
  1524. }
  1525. };
  1526. return constructor;
  1527. })();
  1528. exports.JpegImage = JpegImage;
  1529. }));
  1530. (function (root, factory) {
  1531. {
  1532. factory((root.pdfjsSharedGlobal = {}));
  1533. }
  1534. }(this, function (exports) {
  1535. var globalScope = (typeof window !== 'undefined') ? window :
  1536. (typeof global !== 'undefined') ? global :
  1537. (typeof self !== 'undefined') ? self : this;
  1538. var isWorker = (typeof window === 'undefined');
  1539. // The global PDFJS object exposes the API
  1540. // In production, it will be declared outside a global wrapper
  1541. // In development, it will be declared here
  1542. if (!globalScope.PDFJS) {
  1543. globalScope.PDFJS = {};
  1544. }
  1545. if (typeof pdfjsVersion !== 'undefined') {
  1546. globalScope.PDFJS.version = pdfjsVersion;
  1547. }
  1548. if (typeof pdfjsVersion !== 'undefined') {
  1549. globalScope.PDFJS.build = pdfjsBuild;
  1550. }
  1551. globalScope.PDFJS.pdfBug = false;
  1552. exports.globalScope = globalScope;
  1553. exports.isWorker = isWorker;
  1554. exports.PDFJS = globalScope.PDFJS;
  1555. }));
  1556. (function (root, factory) {
  1557. {
  1558. factory((root.pdfjsCoreBidi = {}), root.pdfjsSharedGlobal);
  1559. }
  1560. }(this, function (exports, sharedGlobal) {
  1561. var PDFJS = sharedGlobal.PDFJS;
  1562. var bidi = PDFJS.bidi = (function bidiClosure() {
  1563. // Character types for symbols from 0000 to 00FF.
  1564. var baseTypes = [
  1565. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  1566. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  1567. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  1568. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  1569. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  1570. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  1571. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  1572. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  1573. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  1574. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  1575. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  1576. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  1577. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  1578. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  1579. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  1580. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  1581. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  1582. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  1583. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  1584. ];
  1585. // Character types for symbols from 0600 to 06FF
  1586. var arabicTypes = [
  1587. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1588. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  1589. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1590. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1591. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1592. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1593. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  1594. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  1595. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  1596. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  1597. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1598. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1599. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1600. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1601. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1602. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1603. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1604. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1605. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  1606. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  1607. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1608. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  1609. ];
  1610. function isOdd(i) {
  1611. return (i & 1) !== 0;
  1612. }
  1613. function isEven(i) {
  1614. return (i & 1) === 0;
  1615. }
  1616. function findUnequal(arr, start, value) {
  1617. for (var j = start, jj = arr.length; j < jj; ++j) {
  1618. if (arr[j] !== value) {
  1619. return j;
  1620. }
  1621. }
  1622. return j;
  1623. }
  1624. function setValues(arr, start, end, value) {
  1625. for (var j = start; j < end; ++j) {
  1626. arr[j] = value;
  1627. }
  1628. }
  1629. function reverseValues(arr, start, end) {
  1630. for (var i = start, j = end - 1; i < j; ++i, --j) {
  1631. var temp = arr[i];
  1632. arr[i] = arr[j];
  1633. arr[j] = temp;
  1634. }
  1635. }
  1636. function createBidiText(str, isLTR, vertical) {
  1637. return {
  1638. str: str,
  1639. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  1640. };
  1641. }
  1642. // These are used in bidi(), which is called frequently. We re-use them on
  1643. // each call to avoid unnecessary allocations.
  1644. var chars = [];
  1645. var types = [];
  1646. function bidi(str, startLevel, vertical) {
  1647. var isLTR = true;
  1648. var strLength = str.length;
  1649. if (strLength === 0 || vertical) {
  1650. return createBidiText(str, isLTR, vertical);
  1651. }
  1652. // Get types and fill arrays
  1653. chars.length = strLength;
  1654. types.length = strLength;
  1655. var numBidi = 0;
  1656. var i, ii;
  1657. for (i = 0; i < strLength; ++i) {
  1658. chars[i] = str.charAt(i);
  1659. var charCode = str.charCodeAt(i);
  1660. var charType = 'L';
  1661. if (charCode <= 0x00ff) {
  1662. charType = baseTypes[charCode];
  1663. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  1664. charType = 'R';
  1665. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  1666. charType = arabicTypes[charCode & 0xff];
  1667. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  1668. charType = 'AL';
  1669. }
  1670. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  1671. numBidi++;
  1672. }
  1673. types[i] = charType;
  1674. }
  1675. // Detect the bidi method
  1676. // - If there are no rtl characters then no bidi needed
  1677. // - If less than 30% chars are rtl then string is primarily ltr
  1678. // - If more than 30% chars are rtl then string is primarily rtl
  1679. if (numBidi === 0) {
  1680. isLTR = true;
  1681. return createBidiText(str, isLTR);
  1682. }
  1683. if (startLevel === -1) {
  1684. if ((strLength / numBidi) < 0.3) {
  1685. isLTR = true;
  1686. startLevel = 0;
  1687. } else {
  1688. isLTR = false;
  1689. startLevel = 1;
  1690. }
  1691. }
  1692. var levels = [];
  1693. for (i = 0; i < strLength; ++i) {
  1694. levels[i] = startLevel;
  1695. }
  1696. /*
  1697. X1-X10: skip most of this, since we are NOT doing the embeddings.
  1698. */
  1699. var e = (isOdd(startLevel) ? 'R' : 'L');
  1700. var sor = e;
  1701. var eor = sor;
  1702. /*
  1703. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  1704. type of the NSM to the type of the previous character. If the NSM is at the
  1705. start of the level run, it will get the type of sor.
  1706. */
  1707. var lastType = sor;
  1708. for (i = 0; i < strLength; ++i) {
  1709. if (types[i] === 'NSM') {
  1710. types[i] = lastType;
  1711. } else {
  1712. lastType = types[i];
  1713. }
  1714. }
  1715. /*
  1716. W2. Search backwards from each instance of a European number until the
  1717. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  1718. the type of the European number to Arabic number.
  1719. */
  1720. lastType = sor;
  1721. var t;
  1722. for (i = 0; i < strLength; ++i) {
  1723. t = types[i];
  1724. if (t === 'EN') {
  1725. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  1726. } else if (t === 'R' || t === 'L' || t === 'AL') {
  1727. lastType = t;
  1728. }
  1729. }
  1730. /*
  1731. W3. Change all ALs to R.
  1732. */
  1733. for (i = 0; i < strLength; ++i) {
  1734. t = types[i];
  1735. if (t === 'AL') {
  1736. types[i] = 'R';
  1737. }
  1738. }
  1739. /*
  1740. W4. A single European separator between two European numbers changes to a
  1741. European number. A single common separator between two numbers of the same
  1742. type changes to that type:
  1743. */
  1744. for (i = 1; i < strLength - 1; ++i) {
  1745. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  1746. types[i] = 'EN';
  1747. }
  1748. if (types[i] === 'CS' &&
  1749. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  1750. types[i + 1] === types[i - 1]) {
  1751. types[i] = types[i - 1];
  1752. }
  1753. }
  1754. /*
  1755. W5. A sequence of European terminators adjacent to European numbers changes
  1756. to all European numbers:
  1757. */
  1758. for (i = 0; i < strLength; ++i) {
  1759. if (types[i] === 'EN') {
  1760. // do before
  1761. var j;
  1762. for (j = i - 1; j >= 0; --j) {
  1763. if (types[j] !== 'ET') {
  1764. break;
  1765. }
  1766. types[j] = 'EN';
  1767. }
  1768. // do after
  1769. for (j = i + 1; j < strLength; --j) {
  1770. if (types[j] !== 'ET') {
  1771. break;
  1772. }
  1773. types[j] = 'EN';
  1774. }
  1775. }
  1776. }
  1777. /*
  1778. W6. Otherwise, separators and terminators change to Other Neutral:
  1779. */
  1780. for (i = 0; i < strLength; ++i) {
  1781. t = types[i];
  1782. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  1783. types[i] = 'ON';
  1784. }
  1785. }
  1786. /*
  1787. W7. Search backwards from each instance of a European number until the
  1788. first strong type (R, L, or sor) is found. If an L is found, then change
  1789. the type of the European number to L.
  1790. */
  1791. lastType = sor;
  1792. for (i = 0; i < strLength; ++i) {
  1793. t = types[i];
  1794. if (t === 'EN') {
  1795. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  1796. } else if (t === 'R' || t === 'L') {
  1797. lastType = t;
  1798. }
  1799. }
  1800. /*
  1801. N1. A sequence of neutrals takes the direction of the surrounding strong
  1802. text if the text on both sides has the same direction. European and Arabic
  1803. numbers are treated as though they were R. Start-of-level-run (sor) and
  1804. end-of-level-run (eor) are used at level run boundaries.
  1805. */
  1806. for (i = 0; i < strLength; ++i) {
  1807. if (types[i] === 'ON') {
  1808. var end = findUnequal(types, i + 1, 'ON');
  1809. var before = sor;
  1810. if (i > 0) {
  1811. before = types[i - 1];
  1812. }
  1813. var after = eor;
  1814. if (end + 1 < strLength) {
  1815. after = types[end + 1];
  1816. }
  1817. if (before !== 'L') {
  1818. before = 'R';
  1819. }
  1820. if (after !== 'L') {
  1821. after = 'R';
  1822. }
  1823. if (before === after) {
  1824. setValues(types, i, end, before);
  1825. }
  1826. i = end - 1; // reset to end (-1 so next iteration is ok)
  1827. }
  1828. }
  1829. /*
  1830. N2. Any remaining neutrals take the embedding direction.
  1831. */
  1832. for (i = 0; i < strLength; ++i) {
  1833. if (types[i] === 'ON') {
  1834. types[i] = e;
  1835. }
  1836. }
  1837. /*
  1838. I1. For all characters with an even (left-to-right) embedding direction,
  1839. those of type R go up one level and those of type AN or EN go up two
  1840. levels.
  1841. I2. For all characters with an odd (right-to-left) embedding direction,
  1842. those of type L, EN or AN go up one level.
  1843. */
  1844. for (i = 0; i < strLength; ++i) {
  1845. t = types[i];
  1846. if (isEven(levels[i])) {
  1847. if (t === 'R') {
  1848. levels[i] += 1;
  1849. } else if (t === 'AN' || t === 'EN') {
  1850. levels[i] += 2;
  1851. }
  1852. } else { // isOdd
  1853. if (t === 'L' || t === 'AN' || t === 'EN') {
  1854. levels[i] += 1;
  1855. }
  1856. }
  1857. }
  1858. /*
  1859. L1. On each line, reset the embedding level of the following characters to
  1860. the paragraph embedding level:
  1861. segment separators,
  1862. paragraph separators,
  1863. any sequence of whitespace characters preceding a segment separator or
  1864. paragraph separator, and any sequence of white space characters at the end
  1865. of the line.
  1866. */
  1867. // don't bother as text is only single line
  1868. /*
  1869. L2. From the highest level found in the text to the lowest odd level on
  1870. each line, reverse any contiguous sequence of characters that are at that
  1871. level or higher.
  1872. */
  1873. // find highest level & lowest odd level
  1874. var highestLevel = -1;
  1875. var lowestOddLevel = 99;
  1876. var level;
  1877. for (i = 0, ii = levels.length; i < ii; ++i) {
  1878. level = levels[i];
  1879. if (highestLevel < level) {
  1880. highestLevel = level;
  1881. }
  1882. if (lowestOddLevel > level && isOdd(level)) {
  1883. lowestOddLevel = level;
  1884. }
  1885. }
  1886. // now reverse between those limits
  1887. for (level = highestLevel; level >= lowestOddLevel; --level) {
  1888. // find segments to reverse
  1889. var start = -1;
  1890. for (i = 0, ii = levels.length; i < ii; ++i) {
  1891. if (levels[i] < level) {
  1892. if (start >= 0) {
  1893. reverseValues(chars, start, i);
  1894. start = -1;
  1895. }
  1896. } else if (start < 0) {
  1897. start = i;
  1898. }
  1899. }
  1900. if (start >= 0) {
  1901. reverseValues(chars, start, levels.length);
  1902. }
  1903. }
  1904. /*
  1905. L3. Combining marks applied to a right-to-left base character will at this
  1906. point precede their base character. If the rendering engine expects them to
  1907. follow the base characters in the final display process, then the ordering
  1908. of the marks and the base character must be reversed.
  1909. */
  1910. // don't bother for now
  1911. /*
  1912. L4. A character that possesses the mirrored property as specified by
  1913. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  1914. directionality of that character is R.
  1915. */
  1916. // don't mirror as characters are already mirrored in the pdf
  1917. // Finally, return string
  1918. for (i = 0, ii = chars.length; i < ii; ++i) {
  1919. var ch = chars[i];
  1920. if (ch === '<' || ch === '>') {
  1921. chars[i] = '';
  1922. }
  1923. }
  1924. return createBidiText(chars.join(''), isLTR);
  1925. }
  1926. return bidi;
  1927. })();
  1928. exports.bidi = bidi;
  1929. }));
  1930. (function (root, factory) {
  1931. {
  1932. factory((root.pdfjsSharedUtil = {}), root.pdfjsSharedGlobal);
  1933. }
  1934. }(this, function (exports, sharedGlobal) {
  1935. var PDFJS = sharedGlobal.PDFJS;
  1936. var globalScope = sharedGlobal.globalScope;
  1937. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  1938. var TextRenderingMode = {
  1939. FILL: 0,
  1940. STROKE: 1,
  1941. FILL_STROKE: 2,
  1942. INVISIBLE: 3,
  1943. FILL_ADD_TO_PATH: 4,
  1944. STROKE_ADD_TO_PATH: 5,
  1945. FILL_STROKE_ADD_TO_PATH: 6,
  1946. ADD_TO_PATH: 7,
  1947. FILL_STROKE_MASK: 3,
  1948. ADD_TO_PATH_FLAG: 4
  1949. };
  1950. var ImageKind = {
  1951. GRAYSCALE_1BPP: 1,
  1952. RGB_24BPP: 2,
  1953. RGBA_32BPP: 3
  1954. };
  1955. var AnnotationType = {
  1956. TEXT: 1,
  1957. LINK: 2,
  1958. FREETEXT: 3,
  1959. LINE: 4,
  1960. SQUARE: 5,
  1961. CIRCLE: 6,
  1962. POLYGON: 7,
  1963. POLYLINE: 8,
  1964. HIGHLIGHT: 9,
  1965. UNDERLINE: 10,
  1966. SQUIGGLY: 11,
  1967. STRIKEOUT: 12,
  1968. STAMP: 13,
  1969. CARET: 14,
  1970. INK: 15,
  1971. POPUP: 16,
  1972. FILEATTACHMENT: 17,
  1973. SOUND: 18,
  1974. MOVIE: 19,
  1975. WIDGET: 20,
  1976. SCREEN: 21,
  1977. PRINTERMARK: 22,
  1978. TRAPNET: 23,
  1979. WATERMARK: 24,
  1980. THREED: 25,
  1981. REDACT: 26
  1982. };
  1983. var AnnotationFlag = {
  1984. INVISIBLE: 0x01,
  1985. HIDDEN: 0x02,
  1986. PRINT: 0x04,
  1987. NOZOOM: 0x08,
  1988. NOROTATE: 0x10,
  1989. NOVIEW: 0x20,
  1990. READONLY: 0x40,
  1991. LOCKED: 0x80,
  1992. TOGGLENOVIEW: 0x100,
  1993. LOCKEDCONTENTS: 0x200
  1994. };
  1995. var AnnotationBorderStyleType = {
  1996. SOLID: 1,
  1997. DASHED: 2,
  1998. BEVELED: 3,
  1999. INSET: 4,
  2000. UNDERLINE: 5
  2001. };
  2002. var StreamType = {
  2003. UNKNOWN: 0,
  2004. FLATE: 1,
  2005. LZW: 2,
  2006. DCT: 3,
  2007. JPX: 4,
  2008. JBIG: 5,
  2009. A85: 6,
  2010. AHX: 7,
  2011. CCF: 8,
  2012. RL: 9
  2013. };
  2014. var FontType = {
  2015. UNKNOWN: 0,
  2016. TYPE1: 1,
  2017. TYPE1C: 2,
  2018. CIDFONTTYPE0: 3,
  2019. CIDFONTTYPE0C: 4,
  2020. TRUETYPE: 5,
  2021. CIDFONTTYPE2: 6,
  2022. TYPE3: 7,
  2023. OPENTYPE: 8,
  2024. TYPE0: 9,
  2025. MMTYPE1: 10
  2026. };
  2027. PDFJS.VERBOSITY_LEVELS = {
  2028. errors: 0,
  2029. warnings: 1,
  2030. infos: 5
  2031. };
  2032. // All the possible operations for an operator list.
  2033. var OPS = PDFJS.OPS = {
  2034. // Intentionally start from 1 so it is easy to spot bad operators that will be
  2035. // 0's.
  2036. dependency: 1,
  2037. setLineWidth: 2,
  2038. setLineCap: 3,
  2039. setLineJoin: 4,
  2040. setMiterLimit: 5,
  2041. setDash: 6,
  2042. setRenderingIntent: 7,
  2043. setFlatness: 8,
  2044. setGState: 9,
  2045. save: 10,
  2046. restore: 11,
  2047. transform: 12,
  2048. moveTo: 13,
  2049. lineTo: 14,
  2050. curveTo: 15,
  2051. curveTo2: 16,
  2052. curveTo3: 17,
  2053. closePath: 18,
  2054. rectangle: 19,
  2055. stroke: 20,
  2056. closeStroke: 21,
  2057. fill: 22,
  2058. eoFill: 23,
  2059. fillStroke: 24,
  2060. eoFillStroke: 25,
  2061. closeFillStroke: 26,
  2062. closeEOFillStroke: 27,
  2063. endPath: 28,
  2064. clip: 29,
  2065. eoClip: 30,
  2066. beginText: 31,
  2067. endText: 32,
  2068. setCharSpacing: 33,
  2069. setWordSpacing: 34,
  2070. setHScale: 35,
  2071. setLeading: 36,
  2072. setFont: 37,
  2073. setTextRenderingMode: 38,
  2074. setTextRise: 39,
  2075. moveText: 40,
  2076. setLeadingMoveText: 41,
  2077. setTextMatrix: 42,
  2078. nextLine: 43,
  2079. showText: 44,
  2080. showSpacedText: 45,
  2081. nextLineShowText: 46,
  2082. nextLineSetSpacingShowText: 47,
  2083. setCharWidth: 48,
  2084. setCharWidthAndBounds: 49,
  2085. setStrokeColorSpace: 50,
  2086. setFillColorSpace: 51,
  2087. setStrokeColor: 52,
  2088. setStrokeColorN: 53,
  2089. setFillColor: 54,
  2090. setFillColorN: 55,
  2091. setStrokeGray: 56,
  2092. setFillGray: 57,
  2093. setStrokeRGBColor: 58,
  2094. setFillRGBColor: 59,
  2095. setStrokeCMYKColor: 60,
  2096. setFillCMYKColor: 61,
  2097. shadingFill: 62,
  2098. beginInlineImage: 63,
  2099. beginImageData: 64,
  2100. endInlineImage: 65,
  2101. paintXObject: 66,
  2102. markPoint: 67,
  2103. markPointProps: 68,
  2104. beginMarkedContent: 69,
  2105. beginMarkedContentProps: 70,
  2106. endMarkedContent: 71,
  2107. beginCompat: 72,
  2108. endCompat: 73,
  2109. paintFormXObjectBegin: 74,
  2110. paintFormXObjectEnd: 75,
  2111. beginGroup: 76,
  2112. endGroup: 77,
  2113. beginAnnotations: 78,
  2114. endAnnotations: 79,
  2115. beginAnnotation: 80,
  2116. endAnnotation: 81,
  2117. paintJpegXObject: 82,
  2118. paintImageMaskXObject: 83,
  2119. paintImageMaskXObjectGroup: 84,
  2120. paintImageXObject: 85,
  2121. paintInlineImageXObject: 86,
  2122. paintInlineImageXObjectGroup: 87,
  2123. paintImageXObjectRepeat: 88,
  2124. paintImageMaskXObjectRepeat: 89,
  2125. paintSolidColorImageMask: 90,
  2126. constructPath: 91
  2127. };
  2128. // A notice for devs. These are good for things that are helpful to devs, such
  2129. // as warning that Workers were disabled, which is important to devs but not
  2130. // end users.
  2131. function info(msg) {
  2132. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
  2133. console.log('Info: ' + msg);
  2134. }
  2135. }
  2136. // Non-fatal warnings.
  2137. function warn(msg) {
  2138. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
  2139. console.log('Warning: ' + msg);
  2140. }
  2141. }
  2142. // Deprecated API function -- display regardless of the PDFJS.verbosity setting.
  2143. function deprecated(details) {
  2144. console.log('Deprecated API usage: ' + details);
  2145. }
  2146. // Fatal errors that should trigger the fallback UI and halt execution by
  2147. // throwing an exception.
  2148. function error(msg) {
  2149. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.errors) {
  2150. console.log('Error: ' + msg);
  2151. console.log(backtrace());
  2152. }
  2153. throw new Error(msg);
  2154. }
  2155. function backtrace() {
  2156. try {
  2157. throw new Error();
  2158. } catch (e) {
  2159. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  2160. }
  2161. }
  2162. function assert(cond, msg) {
  2163. if (!cond) {
  2164. error(msg);
  2165. }
  2166. }
  2167. var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
  2168. unknown: 'unknown',
  2169. forms: 'forms',
  2170. javaScript: 'javaScript',
  2171. smask: 'smask',
  2172. shadingPattern: 'shadingPattern',
  2173. font: 'font'
  2174. };
  2175. // Gets the file name from a given URL.
  2176. function getFilenameFromUrl(url) {
  2177. var anchor = url.indexOf('#');
  2178. var query = url.indexOf('?');
  2179. var end = Math.min(
  2180. anchor > 0 ? anchor : url.length,
  2181. query > 0 ? query : url.length);
  2182. return url.substring(url.lastIndexOf('/', end) + 1, end);
  2183. }
  2184. PDFJS.getFilenameFromUrl = getFilenameFromUrl;
  2185. // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
  2186. // absolute URL, it will be returned as is.
  2187. function combineUrl(baseUrl, url) {
  2188. if (!url) {
  2189. return baseUrl;
  2190. }
  2191. return new URL(url, baseUrl).href;
  2192. }
  2193. // Checks if URLs have the same origin. For non-HTTP based URLs, returns false.
  2194. function isSameOrigin(baseUrl, otherUrl) {
  2195. try {
  2196. var base = new URL(baseUrl);
  2197. if (!base.origin || base.origin === 'null') {
  2198. return false; // non-HTTP url
  2199. }
  2200. } catch (e) {
  2201. return false;
  2202. }
  2203. var other = new URL(otherUrl, base);
  2204. return base.origin === other.origin;
  2205. }
  2206. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  2207. function isValidUrl(url, allowRelative) {
  2208. if (!url) {
  2209. return false;
  2210. }
  2211. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  2212. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  2213. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  2214. if (!protocol) {
  2215. return allowRelative;
  2216. }
  2217. protocol = protocol[0].toLowerCase();
  2218. switch (protocol) {
  2219. case 'http':
  2220. case 'https':
  2221. case 'ftp':
  2222. case 'mailto':
  2223. case 'tel':
  2224. return true;
  2225. default:
  2226. return false;
  2227. }
  2228. }
  2229. PDFJS.isValidUrl = isValidUrl;
  2230. /**
  2231. * Adds various attributes (href, title, target, rel) to hyperlinks.
  2232. * @param {HTMLLinkElement} link - The link element.
  2233. * @param {Object} params - An object with the properties:
  2234. * @param {string} params.url - An absolute URL.
  2235. */
  2236. function addLinkAttributes(link, params) {
  2237. var url = params && params.url;
  2238. link.href = link.title = (url ? removeNullCharacters(url) : '');
  2239. if (url) {
  2240. if (isExternalLinkTargetSet()) {
  2241. link.target = LinkTargetStringMap[PDFJS.externalLinkTarget];
  2242. }
  2243. // Strip referrer from the URL.
  2244. link.rel = PDFJS.externalLinkRel;
  2245. }
  2246. }
  2247. PDFJS.addLinkAttributes = addLinkAttributes;
  2248. function shadow(obj, prop, value) {
  2249. Object.defineProperty(obj, prop, { value: value,
  2250. enumerable: true,
  2251. configurable: true,
  2252. writable: false });
  2253. return value;
  2254. }
  2255. PDFJS.shadow = shadow;
  2256. function getLookupTableFactory(initializer) {
  2257. var lookup;
  2258. return function () {
  2259. if (initializer) {
  2260. lookup = Object.create(null);
  2261. initializer(lookup);
  2262. initializer = null;
  2263. }
  2264. return lookup;
  2265. };
  2266. }
  2267. var LinkTarget = PDFJS.LinkTarget = {
  2268. NONE: 0, // Default value.
  2269. SELF: 1,
  2270. BLANK: 2,
  2271. PARENT: 3,
  2272. TOP: 4,
  2273. };
  2274. var LinkTargetStringMap = [
  2275. '',
  2276. '_self',
  2277. '_blank',
  2278. '_parent',
  2279. '_top'
  2280. ];
  2281. function isExternalLinkTargetSet() {
  2282. if (PDFJS.openExternalLinksInNewWindow) {
  2283. deprecated('PDFJS.openExternalLinksInNewWindow, please use ' +
  2284. '"PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK" instead.');
  2285. if (PDFJS.externalLinkTarget === LinkTarget.NONE) {
  2286. PDFJS.externalLinkTarget = LinkTarget.BLANK;
  2287. }
  2288. // Reset the deprecated parameter, to suppress further warnings.
  2289. PDFJS.openExternalLinksInNewWindow = false;
  2290. }
  2291. switch (PDFJS.externalLinkTarget) {
  2292. case LinkTarget.NONE:
  2293. return false;
  2294. case LinkTarget.SELF:
  2295. case LinkTarget.BLANK:
  2296. case LinkTarget.PARENT:
  2297. case LinkTarget.TOP:
  2298. return true;
  2299. }
  2300. warn('PDFJS.externalLinkTarget is invalid: ' + PDFJS.externalLinkTarget);
  2301. // Reset the external link target, to suppress further warnings.
  2302. PDFJS.externalLinkTarget = LinkTarget.NONE;
  2303. return false;
  2304. }
  2305. PDFJS.isExternalLinkTargetSet = isExternalLinkTargetSet;
  2306. var PasswordResponses = PDFJS.PasswordResponses = {
  2307. NEED_PASSWORD: 1,
  2308. INCORRECT_PASSWORD: 2
  2309. };
  2310. var PasswordException = (function PasswordExceptionClosure() {
  2311. function PasswordException(msg, code) {
  2312. this.name = 'PasswordException';
  2313. this.message = msg;
  2314. this.code = code;
  2315. }
  2316. PasswordException.prototype = new Error();
  2317. PasswordException.constructor = PasswordException;
  2318. return PasswordException;
  2319. })();
  2320. PDFJS.PasswordException = PasswordException;
  2321. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  2322. function UnknownErrorException(msg, details) {
  2323. this.name = 'UnknownErrorException';
  2324. this.message = msg;
  2325. this.details = details;
  2326. }
  2327. UnknownErrorException.prototype = new Error();
  2328. UnknownErrorException.constructor = UnknownErrorException;
  2329. return UnknownErrorException;
  2330. })();
  2331. PDFJS.UnknownErrorException = UnknownErrorException;
  2332. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  2333. function InvalidPDFException(msg) {
  2334. this.name = 'InvalidPDFException';
  2335. this.message = msg;
  2336. }
  2337. InvalidPDFException.prototype = new Error();
  2338. InvalidPDFException.constructor = InvalidPDFException;
  2339. return InvalidPDFException;
  2340. })();
  2341. PDFJS.InvalidPDFException = InvalidPDFException;
  2342. var MissingPDFException = (function MissingPDFExceptionClosure() {
  2343. function MissingPDFException(msg) {
  2344. this.name = 'MissingPDFException';
  2345. this.message = msg;
  2346. }
  2347. MissingPDFException.prototype = new Error();
  2348. MissingPDFException.constructor = MissingPDFException;
  2349. return MissingPDFException;
  2350. })();
  2351. PDFJS.MissingPDFException = MissingPDFException;
  2352. var UnexpectedResponseException =
  2353. (function UnexpectedResponseExceptionClosure() {
  2354. function UnexpectedResponseException(msg, status) {
  2355. this.name = 'UnexpectedResponseException';
  2356. this.message = msg;
  2357. this.status = status;
  2358. }
  2359. UnexpectedResponseException.prototype = new Error();
  2360. UnexpectedResponseException.constructor = UnexpectedResponseException;
  2361. return UnexpectedResponseException;
  2362. })();
  2363. PDFJS.UnexpectedResponseException = UnexpectedResponseException;
  2364. var NotImplementedException = (function NotImplementedExceptionClosure() {
  2365. function NotImplementedException(msg) {
  2366. this.message = msg;
  2367. }
  2368. NotImplementedException.prototype = new Error();
  2369. NotImplementedException.prototype.name = 'NotImplementedException';
  2370. NotImplementedException.constructor = NotImplementedException;
  2371. return NotImplementedException;
  2372. })();
  2373. var MissingDataException = (function MissingDataExceptionClosure() {
  2374. function MissingDataException(begin, end) {
  2375. this.begin = begin;
  2376. this.end = end;
  2377. this.message = 'Missing data [' + begin + ', ' + end + ')';
  2378. }
  2379. MissingDataException.prototype = new Error();
  2380. MissingDataException.prototype.name = 'MissingDataException';
  2381. MissingDataException.constructor = MissingDataException;
  2382. return MissingDataException;
  2383. })();
  2384. var XRefParseException = (function XRefParseExceptionClosure() {
  2385. function XRefParseException(msg) {
  2386. this.message = msg;
  2387. }
  2388. XRefParseException.prototype = new Error();
  2389. XRefParseException.prototype.name = 'XRefParseException';
  2390. XRefParseException.constructor = XRefParseException;
  2391. return XRefParseException;
  2392. })();
  2393. var NullCharactersRegExp = /\x00/g;
  2394. function removeNullCharacters(str) {
  2395. if (typeof str !== 'string') {
  2396. warn('The argument for removeNullCharacters must be a string.');
  2397. return str;
  2398. }
  2399. return str.replace(NullCharactersRegExp, '');
  2400. }
  2401. PDFJS.removeNullCharacters = removeNullCharacters;
  2402. function bytesToString(bytes) {
  2403. assert(bytes !== null && typeof bytes === 'object' &&
  2404. bytes.length !== undefined, 'Invalid argument for bytesToString');
  2405. var length = bytes.length;
  2406. var MAX_ARGUMENT_COUNT = 8192;
  2407. if (length < MAX_ARGUMENT_COUNT) {
  2408. return String.fromCharCode.apply(null, bytes);
  2409. }
  2410. var strBuf = [];
  2411. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  2412. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  2413. var chunk = bytes.subarray(i, chunkEnd);
  2414. strBuf.push(String.fromCharCode.apply(null, chunk));
  2415. }
  2416. return strBuf.join('');
  2417. }
  2418. function stringToBytes(str) {
  2419. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  2420. var length = str.length;
  2421. var bytes = new Uint8Array(length);
  2422. for (var i = 0; i < length; ++i) {
  2423. bytes[i] = str.charCodeAt(i) & 0xFF;
  2424. }
  2425. return bytes;
  2426. }
  2427. /**
  2428. * Gets length of the array (Array, Uint8Array, or string) in bytes.
  2429. * @param {Array|Uint8Array|string} arr
  2430. * @returns {number}
  2431. */
  2432. function arrayByteLength(arr) {
  2433. if (arr.length !== undefined) {
  2434. return arr.length;
  2435. }
  2436. assert(arr.byteLength !== undefined);
  2437. return arr.byteLength;
  2438. }
  2439. /**
  2440. * Combines array items (arrays) into single Uint8Array object.
  2441. * @param {Array} arr - the array of the arrays (Array, Uint8Array, or string).
  2442. * @returns {Uint8Array}
  2443. */
  2444. function arraysToBytes(arr) {
  2445. // Shortcut: if first and only item is Uint8Array, return it.
  2446. if (arr.length === 1 && (arr[0] instanceof Uint8Array)) {
  2447. return arr[0];
  2448. }
  2449. var resultLength = 0;
  2450. var i, ii = arr.length;
  2451. var item, itemLength ;
  2452. for (i = 0; i < ii; i++) {
  2453. item = arr[i];
  2454. itemLength = arrayByteLength(item);
  2455. resultLength += itemLength;
  2456. }
  2457. var pos = 0;
  2458. var data = new Uint8Array(resultLength);
  2459. for (i = 0; i < ii; i++) {
  2460. item = arr[i];
  2461. if (!(item instanceof Uint8Array)) {
  2462. if (typeof item === 'string') {
  2463. item = stringToBytes(item);
  2464. } else {
  2465. item = new Uint8Array(item);
  2466. }
  2467. }
  2468. itemLength = item.byteLength;
  2469. data.set(item, pos);
  2470. pos += itemLength;
  2471. }
  2472. return data;
  2473. }
  2474. function string32(value) {
  2475. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  2476. (value >> 8) & 0xff, value & 0xff);
  2477. }
  2478. function log2(x) {
  2479. var n = 1, i = 0;
  2480. while (x > n) {
  2481. n <<= 1;
  2482. i++;
  2483. }
  2484. return i;
  2485. }
  2486. function readInt8(data, start) {
  2487. return (data[start] << 24) >> 24;
  2488. }
  2489. function readUint16(data, offset) {
  2490. return (data[offset] << 8) | data[offset + 1];
  2491. }
  2492. function readUint32(data, offset) {
  2493. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  2494. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  2495. }
  2496. // Lazy test the endianness of the platform
  2497. // NOTE: This will be 'true' for simulated TypedArrays
  2498. function isLittleEndian() {
  2499. var buffer8 = new Uint8Array(2);
  2500. buffer8[0] = 1;
  2501. var buffer16 = new Uint16Array(buffer8.buffer);
  2502. return (buffer16[0] === 1);
  2503. }
  2504. Object.defineProperty(PDFJS, 'isLittleEndian', {
  2505. configurable: true,
  2506. get: function PDFJS_isLittleEndian() {
  2507. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  2508. }
  2509. });
  2510. // Lazy test if the userAgent support CanvasTypedArrays
  2511. function hasCanvasTypedArrays() {
  2512. var canvas = document.createElement('canvas');
  2513. canvas.width = canvas.height = 1;
  2514. var ctx = canvas.getContext('2d');
  2515. var imageData = ctx.createImageData(1, 1);
  2516. return (typeof imageData.data.buffer !== 'undefined');
  2517. }
  2518. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  2519. configurable: true,
  2520. get: function PDFJS_hasCanvasTypedArrays() {
  2521. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  2522. }
  2523. });
  2524. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  2525. function Uint32ArrayView(buffer, length) {
  2526. this.buffer = buffer;
  2527. this.byteLength = buffer.length;
  2528. this.length = length === undefined ? (this.byteLength >> 2) : length;
  2529. ensureUint32ArrayViewProps(this.length);
  2530. }
  2531. Uint32ArrayView.prototype = Object.create(null);
  2532. var uint32ArrayViewSetters = 0;
  2533. function createUint32ArrayProp(index) {
  2534. return {
  2535. get: function () {
  2536. var buffer = this.buffer, offset = index << 2;
  2537. return (buffer[offset] | (buffer[offset + 1] << 8) |
  2538. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  2539. },
  2540. set: function (value) {
  2541. var buffer = this.buffer, offset = index << 2;
  2542. buffer[offset] = value & 255;
  2543. buffer[offset + 1] = (value >> 8) & 255;
  2544. buffer[offset + 2] = (value >> 16) & 255;
  2545. buffer[offset + 3] = (value >>> 24) & 255;
  2546. }
  2547. };
  2548. }
  2549. function ensureUint32ArrayViewProps(length) {
  2550. while (uint32ArrayViewSetters < length) {
  2551. Object.defineProperty(Uint32ArrayView.prototype,
  2552. uint32ArrayViewSetters,
  2553. createUint32ArrayProp(uint32ArrayViewSetters));
  2554. uint32ArrayViewSetters++;
  2555. }
  2556. }
  2557. return Uint32ArrayView;
  2558. })();
  2559. exports.Uint32ArrayView = Uint32ArrayView;
  2560. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  2561. var Util = PDFJS.Util = (function UtilClosure() {
  2562. function Util() {}
  2563. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  2564. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  2565. // creating many intermediate strings.
  2566. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  2567. rgbBuf[1] = r;
  2568. rgbBuf[3] = g;
  2569. rgbBuf[5] = b;
  2570. return rgbBuf.join('');
  2571. };
  2572. // Concatenates two transformation matrices together and returns the result.
  2573. Util.transform = function Util_transform(m1, m2) {
  2574. return [
  2575. m1[0] * m2[0] + m1[2] * m2[1],
  2576. m1[1] * m2[0] + m1[3] * m2[1],
  2577. m1[0] * m2[2] + m1[2] * m2[3],
  2578. m1[1] * m2[2] + m1[3] * m2[3],
  2579. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  2580. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  2581. ];
  2582. };
  2583. // For 2d affine transforms
  2584. Util.applyTransform = function Util_applyTransform(p, m) {
  2585. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  2586. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  2587. return [xt, yt];
  2588. };
  2589. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  2590. var d = m[0] * m[3] - m[1] * m[2];
  2591. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  2592. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  2593. return [xt, yt];
  2594. };
  2595. // Applies the transform to the rectangle and finds the minimum axially
  2596. // aligned bounding box.
  2597. Util.getAxialAlignedBoundingBox =
  2598. function Util_getAxialAlignedBoundingBox(r, m) {
  2599. var p1 = Util.applyTransform(r, m);
  2600. var p2 = Util.applyTransform(r.slice(2, 4), m);
  2601. var p3 = Util.applyTransform([r[0], r[3]], m);
  2602. var p4 = Util.applyTransform([r[2], r[1]], m);
  2603. return [
  2604. Math.min(p1[0], p2[0], p3[0], p4[0]),
  2605. Math.min(p1[1], p2[1], p3[1], p4[1]),
  2606. Math.max(p1[0], p2[0], p3[0], p4[0]),
  2607. Math.max(p1[1], p2[1], p3[1], p4[1])
  2608. ];
  2609. };
  2610. Util.inverseTransform = function Util_inverseTransform(m) {
  2611. var d = m[0] * m[3] - m[1] * m[2];
  2612. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  2613. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  2614. };
  2615. // Apply a generic 3d matrix M on a 3-vector v:
  2616. // | a b c | | X |
  2617. // | d e f | x | Y |
  2618. // | g h i | | Z |
  2619. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  2620. // with v as [X,Y,Z]
  2621. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  2622. return [
  2623. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  2624. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  2625. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  2626. ];
  2627. };
  2628. // This calculation uses Singular Value Decomposition.
  2629. // The SVD can be represented with formula A = USV. We are interested in the
  2630. // matrix S here because it represents the scale values.
  2631. Util.singularValueDecompose2dScale =
  2632. function Util_singularValueDecompose2dScale(m) {
  2633. var transpose = [m[0], m[2], m[1], m[3]];
  2634. // Multiply matrix m with its transpose.
  2635. var a = m[0] * transpose[0] + m[1] * transpose[2];
  2636. var b = m[0] * transpose[1] + m[1] * transpose[3];
  2637. var c = m[2] * transpose[0] + m[3] * transpose[2];
  2638. var d = m[2] * transpose[1] + m[3] * transpose[3];
  2639. // Solve the second degree polynomial to get roots.
  2640. var first = (a + d) / 2;
  2641. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  2642. var sx = first + second || 1;
  2643. var sy = first - second || 1;
  2644. // Scale values are the square roots of the eigenvalues.
  2645. return [Math.sqrt(sx), Math.sqrt(sy)];
  2646. };
  2647. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  2648. // For coordinate systems whose origin lies in the bottom-left, this
  2649. // means normalization to (BL,TR) ordering. For systems with origin in the
  2650. // top-left, this means (TL,BR) ordering.
  2651. Util.normalizeRect = function Util_normalizeRect(rect) {
  2652. var r = rect.slice(0); // clone rect
  2653. if (rect[0] > rect[2]) {
  2654. r[0] = rect[2];
  2655. r[2] = rect[0];
  2656. }
  2657. if (rect[1] > rect[3]) {
  2658. r[1] = rect[3];
  2659. r[3] = rect[1];
  2660. }
  2661. return r;
  2662. };
  2663. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  2664. // intersection of rect1 and rect2. If no intersection, returns 'false'
  2665. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  2666. Util.intersect = function Util_intersect(rect1, rect2) {
  2667. function compare(a, b) {
  2668. return a - b;
  2669. }
  2670. // Order points along the axes
  2671. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  2672. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  2673. result = [];
  2674. rect1 = Util.normalizeRect(rect1);
  2675. rect2 = Util.normalizeRect(rect2);
  2676. // X: first and second points belong to different rectangles?
  2677. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  2678. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  2679. // Intersection must be between second and third points
  2680. result[0] = orderedX[1];
  2681. result[2] = orderedX[2];
  2682. } else {
  2683. return false;
  2684. }
  2685. // Y: first and second points belong to different rectangles?
  2686. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  2687. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  2688. // Intersection must be between second and third points
  2689. result[1] = orderedY[1];
  2690. result[3] = orderedY[2];
  2691. } else {
  2692. return false;
  2693. }
  2694. return result;
  2695. };
  2696. Util.sign = function Util_sign(num) {
  2697. return num < 0 ? -1 : 1;
  2698. };
  2699. var ROMAN_NUMBER_MAP = [
  2700. '', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM',
  2701. '', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC',
  2702. '', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'
  2703. ];
  2704. /**
  2705. * Converts positive integers to (upper case) Roman numerals.
  2706. * @param {integer} number - The number that should be converted.
  2707. * @param {boolean} lowerCase - Indicates if the result should be converted
  2708. * to lower case letters. The default is false.
  2709. * @return {string} The resulting Roman number.
  2710. */
  2711. Util.toRoman = function Util_toRoman(number, lowerCase) {
  2712. assert(isInt(number) && number > 0,
  2713. 'The number should be a positive integer.');
  2714. var pos, romanBuf = [];
  2715. // Thousands
  2716. while (number >= 1000) {
  2717. number -= 1000;
  2718. romanBuf.push('M');
  2719. }
  2720. // Hundreds
  2721. pos = (number / 100) | 0;
  2722. number %= 100;
  2723. romanBuf.push(ROMAN_NUMBER_MAP[pos]);
  2724. // Tens
  2725. pos = (number / 10) | 0;
  2726. number %= 10;
  2727. romanBuf.push(ROMAN_NUMBER_MAP[10 + pos]);
  2728. // Ones
  2729. romanBuf.push(ROMAN_NUMBER_MAP[20 + number]);
  2730. var romanStr = romanBuf.join('');
  2731. return (lowerCase ? romanStr.toLowerCase() : romanStr);
  2732. };
  2733. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  2734. Array.prototype.push.apply(arr1, arr2);
  2735. };
  2736. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  2737. Array.prototype.unshift.apply(arr1, arr2);
  2738. };
  2739. Util.extendObj = function extendObj(obj1, obj2) {
  2740. for (var key in obj2) {
  2741. obj1[key] = obj2[key];
  2742. }
  2743. };
  2744. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  2745. name) {
  2746. while (dict && !dict.has(name)) {
  2747. dict = dict.get('Parent');
  2748. }
  2749. if (!dict) {
  2750. return null;
  2751. }
  2752. return dict.get(name);
  2753. };
  2754. Util.inherit = function Util_inherit(sub, base, prototype) {
  2755. sub.prototype = Object.create(base.prototype);
  2756. sub.prototype.constructor = sub;
  2757. for (var prop in prototype) {
  2758. sub.prototype[prop] = prototype[prop];
  2759. }
  2760. };
  2761. Util.loadScript = function Util_loadScript(src, callback) {
  2762. var script = document.createElement('script');
  2763. var loaded = false;
  2764. script.setAttribute('src', src);
  2765. if (callback) {
  2766. script.onload = function() {
  2767. if (!loaded) {
  2768. callback();
  2769. }
  2770. loaded = true;
  2771. };
  2772. }
  2773. document.getElementsByTagName('head')[0].appendChild(script);
  2774. };
  2775. return Util;
  2776. })();
  2777. /**
  2778. * PDF page viewport created based on scale, rotation and offset.
  2779. * @class
  2780. * @alias PDFJS.PageViewport
  2781. */
  2782. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  2783. /**
  2784. * @constructor
  2785. * @private
  2786. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  2787. * @param scale {number} scale of the viewport.
  2788. * @param rotation {number} rotations of the viewport in degrees.
  2789. * @param offsetX {number} offset X
  2790. * @param offsetY {number} offset Y
  2791. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  2792. */
  2793. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  2794. this.viewBox = viewBox;
  2795. this.scale = scale;
  2796. this.rotation = rotation;
  2797. this.offsetX = offsetX;
  2798. this.offsetY = offsetY;
  2799. // creating transform to convert pdf coordinate system to the normal
  2800. // canvas like coordinates taking in account scale and rotation
  2801. var centerX = (viewBox[2] + viewBox[0]) / 2;
  2802. var centerY = (viewBox[3] + viewBox[1]) / 2;
  2803. var rotateA, rotateB, rotateC, rotateD;
  2804. rotation = rotation % 360;
  2805. rotation = rotation < 0 ? rotation + 360 : rotation;
  2806. switch (rotation) {
  2807. case 180:
  2808. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  2809. break;
  2810. case 90:
  2811. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  2812. break;
  2813. case 270:
  2814. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  2815. break;
  2816. //case 0:
  2817. default:
  2818. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  2819. break;
  2820. }
  2821. if (dontFlip) {
  2822. rotateC = -rotateC; rotateD = -rotateD;
  2823. }
  2824. var offsetCanvasX, offsetCanvasY;
  2825. var width, height;
  2826. if (rotateA === 0) {
  2827. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  2828. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  2829. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  2830. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  2831. } else {
  2832. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  2833. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  2834. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  2835. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  2836. }
  2837. // creating transform for the following operations:
  2838. // translate(-centerX, -centerY), rotate and flip vertically,
  2839. // scale, and translate(offsetCanvasX, offsetCanvasY)
  2840. this.transform = [
  2841. rotateA * scale,
  2842. rotateB * scale,
  2843. rotateC * scale,
  2844. rotateD * scale,
  2845. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  2846. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  2847. ];
  2848. this.width = width;
  2849. this.height = height;
  2850. this.fontScale = scale;
  2851. }
  2852. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  2853. /**
  2854. * Clones viewport with additional properties.
  2855. * @param args {Object} (optional) If specified, may contain the 'scale' or
  2856. * 'rotation' properties to override the corresponding properties in
  2857. * the cloned viewport.
  2858. * @returns {PDFJS.PageViewport} Cloned viewport.
  2859. */
  2860. clone: function PageViewPort_clone(args) {
  2861. args = args || {};
  2862. var scale = 'scale' in args ? args.scale : this.scale;
  2863. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  2864. return new PageViewport(this.viewBox.slice(), scale, rotation,
  2865. this.offsetX, this.offsetY, args.dontFlip);
  2866. },
  2867. /**
  2868. * Converts PDF point to the viewport coordinates. For examples, useful for
  2869. * converting PDF location into canvas pixel coordinates.
  2870. * @param x {number} X coordinate.
  2871. * @param y {number} Y coordinate.
  2872. * @returns {Object} Object that contains 'x' and 'y' properties of the
  2873. * point in the viewport coordinate space.
  2874. * @see {@link convertToPdfPoint}
  2875. * @see {@link convertToViewportRectangle}
  2876. */
  2877. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  2878. return Util.applyTransform([x, y], this.transform);
  2879. },
  2880. /**
  2881. * Converts PDF rectangle to the viewport coordinates.
  2882. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  2883. * @returns {Array} Contains corresponding coordinates of the rectangle
  2884. * in the viewport coordinate space.
  2885. * @see {@link convertToViewportPoint}
  2886. */
  2887. convertToViewportRectangle:
  2888. function PageViewport_convertToViewportRectangle(rect) {
  2889. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  2890. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  2891. return [tl[0], tl[1], br[0], br[1]];
  2892. },
  2893. /**
  2894. * Converts viewport coordinates to the PDF location. For examples, useful
  2895. * for converting canvas pixel location into PDF one.
  2896. * @param x {number} X coordinate.
  2897. * @param y {number} Y coordinate.
  2898. * @returns {Object} Object that contains 'x' and 'y' properties of the
  2899. * point in the PDF coordinate space.
  2900. * @see {@link convertToViewportPoint}
  2901. */
  2902. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  2903. return Util.applyInverseTransform([x, y], this.transform);
  2904. }
  2905. };
  2906. return PageViewport;
  2907. })();
  2908. var PDFStringTranslateTable = [
  2909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2910. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  2911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  2915. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  2916. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  2917. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  2918. ];
  2919. function stringToPDFString(str) {
  2920. var i, n = str.length, strBuf = [];
  2921. if (str[0] === '\xFE' && str[1] === '\xFF') {
  2922. // UTF16BE BOM
  2923. for (i = 2; i < n; i += 2) {
  2924. strBuf.push(String.fromCharCode(
  2925. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  2926. }
  2927. } else {
  2928. for (i = 0; i < n; ++i) {
  2929. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  2930. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  2931. }
  2932. }
  2933. return strBuf.join('');
  2934. }
  2935. function stringToUTF8String(str) {
  2936. return decodeURIComponent(escape(str));
  2937. }
  2938. function utf8StringToString(str) {
  2939. return unescape(encodeURIComponent(str));
  2940. }
  2941. function isEmptyObj(obj) {
  2942. for (var key in obj) {
  2943. return false;
  2944. }
  2945. return true;
  2946. }
  2947. function isBool(v) {
  2948. return typeof v === 'boolean';
  2949. }
  2950. function isInt(v) {
  2951. return typeof v === 'number' && ((v | 0) === v);
  2952. }
  2953. function isNum(v) {
  2954. return typeof v === 'number';
  2955. }
  2956. function isString(v) {
  2957. return typeof v === 'string';
  2958. }
  2959. function isArray(v) {
  2960. return v instanceof Array;
  2961. }
  2962. function isArrayBuffer(v) {
  2963. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  2964. }
  2965. /**
  2966. * Promise Capability object.
  2967. *
  2968. * @typedef {Object} PromiseCapability
  2969. * @property {Promise} promise - A promise object.
  2970. * @property {function} resolve - Fullfills the promise.
  2971. * @property {function} reject - Rejects the promise.
  2972. */
  2973. /**
  2974. * Creates a promise capability object.
  2975. * @alias PDFJS.createPromiseCapability
  2976. *
  2977. * @return {PromiseCapability} A capability object contains:
  2978. * - a Promise, resolve and reject methods.
  2979. */
  2980. function createPromiseCapability() {
  2981. var capability = {};
  2982. capability.promise = new Promise(function (resolve, reject) {
  2983. capability.resolve = resolve;
  2984. capability.reject = reject;
  2985. });
  2986. return capability;
  2987. }
  2988. PDFJS.createPromiseCapability = createPromiseCapability;
  2989. /**
  2990. * Polyfill for Promises:
  2991. * The following promise implementation tries to generally implement the
  2992. * Promise/A+ spec. Some notable differences from other promise libaries are:
  2993. * - There currently isn't a seperate deferred and promise object.
  2994. * - Unhandled rejections eventually show an error if they aren't handled.
  2995. *
  2996. * Based off of the work in:
  2997. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  2998. */
  2999. (function PromiseClosure() {
  3000. if (globalScope.Promise) {
  3001. // Promises existing in the DOM/Worker, checking presence of all/resolve
  3002. if (typeof globalScope.Promise.all !== 'function') {
  3003. globalScope.Promise.all = function (iterable) {
  3004. var count = 0, results = [], resolve, reject;
  3005. var promise = new globalScope.Promise(function (resolve_, reject_) {
  3006. resolve = resolve_;
  3007. reject = reject_;
  3008. });
  3009. iterable.forEach(function (p, i) {
  3010. count++;
  3011. p.then(function (result) {
  3012. results[i] = result;
  3013. count--;
  3014. if (count === 0) {
  3015. resolve(results);
  3016. }
  3017. }, reject);
  3018. });
  3019. if (count === 0) {
  3020. resolve(results);
  3021. }
  3022. return promise;
  3023. };
  3024. }
  3025. if (typeof globalScope.Promise.resolve !== 'function') {
  3026. globalScope.Promise.resolve = function (value) {
  3027. return new globalScope.Promise(function (resolve) { resolve(value); });
  3028. };
  3029. }
  3030. if (typeof globalScope.Promise.reject !== 'function') {
  3031. globalScope.Promise.reject = function (reason) {
  3032. return new globalScope.Promise(function (resolve, reject) {
  3033. reject(reason);
  3034. });
  3035. };
  3036. }
  3037. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  3038. globalScope.Promise.prototype.catch = function (onReject) {
  3039. return globalScope.Promise.prototype.then(undefined, onReject);
  3040. };
  3041. }
  3042. return;
  3043. }
  3044. var STATUS_PENDING = 0;
  3045. var STATUS_RESOLVED = 1;
  3046. var STATUS_REJECTED = 2;
  3047. // In an attempt to avoid silent exceptions, unhandled rejections are
  3048. // tracked and if they aren't handled in a certain amount of time an
  3049. // error is logged.
  3050. var REJECTION_TIMEOUT = 500;
  3051. var HandlerManager = {
  3052. handlers: [],
  3053. running: false,
  3054. unhandledRejections: [],
  3055. pendingRejectionCheck: false,
  3056. scheduleHandlers: function scheduleHandlers(promise) {
  3057. if (promise._status === STATUS_PENDING) {
  3058. return;
  3059. }
  3060. this.handlers = this.handlers.concat(promise._handlers);
  3061. promise._handlers = [];
  3062. if (this.running) {
  3063. return;
  3064. }
  3065. this.running = true;
  3066. setTimeout(this.runHandlers.bind(this), 0);
  3067. },
  3068. runHandlers: function runHandlers() {
  3069. var RUN_TIMEOUT = 1; // ms
  3070. var timeoutAt = Date.now() + RUN_TIMEOUT;
  3071. while (this.handlers.length > 0) {
  3072. var handler = this.handlers.shift();
  3073. var nextStatus = handler.thisPromise._status;
  3074. var nextValue = handler.thisPromise._value;
  3075. try {
  3076. if (nextStatus === STATUS_RESOLVED) {
  3077. if (typeof handler.onResolve === 'function') {
  3078. nextValue = handler.onResolve(nextValue);
  3079. }
  3080. } else if (typeof handler.onReject === 'function') {
  3081. nextValue = handler.onReject(nextValue);
  3082. nextStatus = STATUS_RESOLVED;
  3083. if (handler.thisPromise._unhandledRejection) {
  3084. this.removeUnhandeledRejection(handler.thisPromise);
  3085. }
  3086. }
  3087. } catch (ex) {
  3088. nextStatus = STATUS_REJECTED;
  3089. nextValue = ex;
  3090. }
  3091. handler.nextPromise._updateStatus(nextStatus, nextValue);
  3092. if (Date.now() >= timeoutAt) {
  3093. break;
  3094. }
  3095. }
  3096. if (this.handlers.length > 0) {
  3097. setTimeout(this.runHandlers.bind(this), 0);
  3098. return;
  3099. }
  3100. this.running = false;
  3101. },
  3102. addUnhandledRejection: function addUnhandledRejection(promise) {
  3103. this.unhandledRejections.push({
  3104. promise: promise,
  3105. time: Date.now()
  3106. });
  3107. this.scheduleRejectionCheck();
  3108. },
  3109. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  3110. promise._unhandledRejection = false;
  3111. for (var i = 0; i < this.unhandledRejections.length; i++) {
  3112. if (this.unhandledRejections[i].promise === promise) {
  3113. this.unhandledRejections.splice(i);
  3114. i--;
  3115. }
  3116. }
  3117. },
  3118. scheduleRejectionCheck: function scheduleRejectionCheck() {
  3119. if (this.pendingRejectionCheck) {
  3120. return;
  3121. }
  3122. this.pendingRejectionCheck = true;
  3123. setTimeout(function rejectionCheck() {
  3124. this.pendingRejectionCheck = false;
  3125. var now = Date.now();
  3126. for (var i = 0; i < this.unhandledRejections.length; i++) {
  3127. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  3128. var unhandled = this.unhandledRejections[i].promise._value;
  3129. var msg = 'Unhandled rejection: ' + unhandled;
  3130. if (unhandled.stack) {
  3131. msg += '\n' + unhandled.stack;
  3132. }
  3133. warn(msg);
  3134. this.unhandledRejections.splice(i);
  3135. i--;
  3136. }
  3137. }
  3138. if (this.unhandledRejections.length) {
  3139. this.scheduleRejectionCheck();
  3140. }
  3141. }.bind(this), REJECTION_TIMEOUT);
  3142. }
  3143. };
  3144. function Promise(resolver) {
  3145. this._status = STATUS_PENDING;
  3146. this._handlers = [];
  3147. try {
  3148. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  3149. } catch (e) {
  3150. this._reject(e);
  3151. }
  3152. }
  3153. /**
  3154. * Builds a promise that is resolved when all the passed in promises are
  3155. * resolved.
  3156. * @param {array} array of data and/or promises to wait for.
  3157. * @return {Promise} New dependant promise.
  3158. */
  3159. Promise.all = function Promise_all(promises) {
  3160. var resolveAll, rejectAll;
  3161. var deferred = new Promise(function (resolve, reject) {
  3162. resolveAll = resolve;
  3163. rejectAll = reject;
  3164. });
  3165. var unresolved = promises.length;
  3166. var results = [];
  3167. if (unresolved === 0) {
  3168. resolveAll(results);
  3169. return deferred;
  3170. }
  3171. function reject(reason) {
  3172. if (deferred._status === STATUS_REJECTED) {
  3173. return;
  3174. }
  3175. results = [];
  3176. rejectAll(reason);
  3177. }
  3178. for (var i = 0, ii = promises.length; i < ii; ++i) {
  3179. var promise = promises[i];
  3180. var resolve = (function(i) {
  3181. return function(value) {
  3182. if (deferred._status === STATUS_REJECTED) {
  3183. return;
  3184. }
  3185. results[i] = value;
  3186. unresolved--;
  3187. if (unresolved === 0) {
  3188. resolveAll(results);
  3189. }
  3190. };
  3191. })(i);
  3192. if (Promise.isPromise(promise)) {
  3193. promise.then(resolve, reject);
  3194. } else {
  3195. resolve(promise);
  3196. }
  3197. }
  3198. return deferred;
  3199. };
  3200. /**
  3201. * Checks if the value is likely a promise (has a 'then' function).
  3202. * @return {boolean} true if value is thenable
  3203. */
  3204. Promise.isPromise = function Promise_isPromise(value) {
  3205. return value && typeof value.then === 'function';
  3206. };
  3207. /**
  3208. * Creates resolved promise
  3209. * @param value resolve value
  3210. * @returns {Promise}
  3211. */
  3212. Promise.resolve = function Promise_resolve(value) {
  3213. return new Promise(function (resolve) { resolve(value); });
  3214. };
  3215. /**
  3216. * Creates rejected promise
  3217. * @param reason rejection value
  3218. * @returns {Promise}
  3219. */
  3220. Promise.reject = function Promise_reject(reason) {
  3221. return new Promise(function (resolve, reject) { reject(reason); });
  3222. };
  3223. Promise.prototype = {
  3224. _status: null,
  3225. _value: null,
  3226. _handlers: null,
  3227. _unhandledRejection: null,
  3228. _updateStatus: function Promise__updateStatus(status, value) {
  3229. if (this._status === STATUS_RESOLVED ||
  3230. this._status === STATUS_REJECTED) {
  3231. return;
  3232. }
  3233. if (status === STATUS_RESOLVED &&
  3234. Promise.isPromise(value)) {
  3235. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  3236. this._updateStatus.bind(this, STATUS_REJECTED));
  3237. return;
  3238. }
  3239. this._status = status;
  3240. this._value = value;
  3241. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  3242. this._unhandledRejection = true;
  3243. HandlerManager.addUnhandledRejection(this);
  3244. }
  3245. HandlerManager.scheduleHandlers(this);
  3246. },
  3247. _resolve: function Promise_resolve(value) {
  3248. this._updateStatus(STATUS_RESOLVED, value);
  3249. },
  3250. _reject: function Promise_reject(reason) {
  3251. this._updateStatus(STATUS_REJECTED, reason);
  3252. },
  3253. then: function Promise_then(onResolve, onReject) {
  3254. var nextPromise = new Promise(function (resolve, reject) {
  3255. this.resolve = resolve;
  3256. this.reject = reject;
  3257. });
  3258. this._handlers.push({
  3259. thisPromise: this,
  3260. onResolve: onResolve,
  3261. onReject: onReject,
  3262. nextPromise: nextPromise
  3263. });
  3264. HandlerManager.scheduleHandlers(this);
  3265. return nextPromise;
  3266. },
  3267. catch: function Promise_catch(onReject) {
  3268. return this.then(undefined, onReject);
  3269. }
  3270. };
  3271. globalScope.Promise = Promise;
  3272. })();
  3273. var StatTimer = (function StatTimerClosure() {
  3274. function rpad(str, pad, length) {
  3275. while (str.length < length) {
  3276. str += pad;
  3277. }
  3278. return str;
  3279. }
  3280. function StatTimer() {
  3281. this.started = Object.create(null);
  3282. this.times = [];
  3283. this.enabled = true;
  3284. }
  3285. StatTimer.prototype = {
  3286. time: function StatTimer_time(name) {
  3287. if (!this.enabled) {
  3288. return;
  3289. }
  3290. if (name in this.started) {
  3291. warn('Timer is already running for ' + name);
  3292. }
  3293. this.started[name] = Date.now();
  3294. },
  3295. timeEnd: function StatTimer_timeEnd(name) {
  3296. if (!this.enabled) {
  3297. return;
  3298. }
  3299. if (!(name in this.started)) {
  3300. warn('Timer has not been started for ' + name);
  3301. }
  3302. this.times.push({
  3303. 'name': name,
  3304. 'start': this.started[name],
  3305. 'end': Date.now()
  3306. });
  3307. // Remove timer from started so it can be called again.
  3308. delete this.started[name];
  3309. },
  3310. toString: function StatTimer_toString() {
  3311. var i, ii;
  3312. var times = this.times;
  3313. var out = '';
  3314. // Find the longest name for padding purposes.
  3315. var longest = 0;
  3316. for (i = 0, ii = times.length; i < ii; ++i) {
  3317. var name = times[i]['name'];
  3318. if (name.length > longest) {
  3319. longest = name.length;
  3320. }
  3321. }
  3322. for (i = 0, ii = times.length; i < ii; ++i) {
  3323. var span = times[i];
  3324. var duration = span.end - span.start;
  3325. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  3326. }
  3327. return out;
  3328. }
  3329. };
  3330. return StatTimer;
  3331. })();
  3332. PDFJS.createBlob = function createBlob(data, contentType) {
  3333. if (typeof Blob !== 'undefined') {
  3334. return new Blob([data], { type: contentType });
  3335. }
  3336. // Blob builder is deprecated in FF14 and removed in FF18.
  3337. var bb = new MozBlobBuilder();
  3338. bb.append(data);
  3339. return bb.getBlob(contentType);
  3340. };
  3341. PDFJS.createObjectURL = (function createObjectURLClosure() {
  3342. // Blob/createObjectURL is not available, falling back to data schema.
  3343. var digits =
  3344. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  3345. return function createObjectURL(data, contentType) {
  3346. if (!PDFJS.disableCreateObjectURL &&
  3347. typeof URL !== 'undefined' && URL.createObjectURL) {
  3348. var blob = PDFJS.createBlob(data, contentType);
  3349. return URL.createObjectURL(blob);
  3350. }
  3351. var buffer = 'data:' + contentType + ';base64,';
  3352. for (var i = 0, ii = data.length; i < ii; i += 3) {
  3353. var b1 = data[i] & 0xFF;
  3354. var b2 = data[i + 1] & 0xFF;
  3355. var b3 = data[i + 2] & 0xFF;
  3356. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  3357. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  3358. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  3359. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  3360. }
  3361. return buffer;
  3362. };
  3363. })();
  3364. function MessageHandler(sourceName, targetName, comObj) {
  3365. this.sourceName = sourceName;
  3366. this.targetName = targetName;
  3367. this.comObj = comObj;
  3368. this.callbackIndex = 1;
  3369. this.postMessageTransfers = true;
  3370. var callbacksCapabilities = this.callbacksCapabilities = Object.create(null);
  3371. var ah = this.actionHandler = Object.create(null);
  3372. this._onComObjOnMessage = function messageHandlerComObjOnMessage(event) {
  3373. var data = event.data;
  3374. if (data.targetName !== this.sourceName) {
  3375. return;
  3376. }
  3377. if (data.isReply) {
  3378. var callbackId = data.callbackId;
  3379. if (data.callbackId in callbacksCapabilities) {
  3380. var callback = callbacksCapabilities[callbackId];
  3381. delete callbacksCapabilities[callbackId];
  3382. if ('error' in data) {
  3383. callback.reject(data.error);
  3384. } else {
  3385. callback.resolve(data.data);
  3386. }
  3387. } else {
  3388. error('Cannot resolve callback ' + callbackId);
  3389. }
  3390. } else if (data.action in ah) {
  3391. var action = ah[data.action];
  3392. if (data.callbackId) {
  3393. var sourceName = this.sourceName;
  3394. var targetName = data.sourceName;
  3395. Promise.resolve().then(function () {
  3396. return action[0].call(action[1], data.data);
  3397. }).then(function (result) {
  3398. comObj.postMessage({
  3399. sourceName: sourceName,
  3400. targetName: targetName,
  3401. isReply: true,
  3402. callbackId: data.callbackId,
  3403. data: result
  3404. });
  3405. }, function (reason) {
  3406. if (reason instanceof Error) {
  3407. // Serialize error to avoid "DataCloneError"
  3408. reason = reason + '';
  3409. }
  3410. comObj.postMessage({
  3411. sourceName: sourceName,
  3412. targetName: targetName,
  3413. isReply: true,
  3414. callbackId: data.callbackId,
  3415. error: reason
  3416. });
  3417. });
  3418. } else {
  3419. action[0].call(action[1], data.data);
  3420. }
  3421. } else {
  3422. error('Unknown action from worker: ' + data.action);
  3423. }
  3424. }.bind(this);
  3425. comObj.addEventListener('message', this._onComObjOnMessage);
  3426. }
  3427. MessageHandler.prototype = {
  3428. on: function messageHandlerOn(actionName, handler, scope) {
  3429. var ah = this.actionHandler;
  3430. if (ah[actionName]) {
  3431. error('There is already an actionName called "' + actionName + '"');
  3432. }
  3433. ah[actionName] = [handler, scope];
  3434. },
  3435. /**
  3436. * Sends a message to the comObj to invoke the action with the supplied data.
  3437. * @param {String} actionName Action to call.
  3438. * @param {JSON} data JSON data to send.
  3439. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  3440. */
  3441. send: function messageHandlerSend(actionName, data, transfers) {
  3442. var message = {
  3443. sourceName: this.sourceName,
  3444. targetName: this.targetName,
  3445. action: actionName,
  3446. data: data
  3447. };
  3448. this.postMessage(message, transfers);
  3449. },
  3450. /**
  3451. * Sends a message to the comObj to invoke the action with the supplied data.
  3452. * Expects that other side will callback with the response.
  3453. * @param {String} actionName Action to call.
  3454. * @param {JSON} data JSON data to send.
  3455. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  3456. * @returns {Promise} Promise to be resolved with response data.
  3457. */
  3458. sendWithPromise:
  3459. function messageHandlerSendWithPromise(actionName, data, transfers) {
  3460. var callbackId = this.callbackIndex++;
  3461. var message = {
  3462. sourceName: this.sourceName,
  3463. targetName: this.targetName,
  3464. action: actionName,
  3465. data: data,
  3466. callbackId: callbackId
  3467. };
  3468. var capability = createPromiseCapability();
  3469. this.callbacksCapabilities[callbackId] = capability;
  3470. try {
  3471. this.postMessage(message, transfers);
  3472. } catch (e) {
  3473. capability.reject(e);
  3474. }
  3475. return capability.promise;
  3476. },
  3477. /**
  3478. * Sends raw message to the comObj.
  3479. * @private
  3480. * @param message {Object} Raw message.
  3481. * @param transfers List of transfers/ArrayBuffers, or undefined.
  3482. */
  3483. postMessage: function (message, transfers) {
  3484. if (transfers && this.postMessageTransfers) {
  3485. this.comObj.postMessage(message, transfers);
  3486. } else {
  3487. this.comObj.postMessage(message);
  3488. }
  3489. },
  3490. destroy: function () {
  3491. this.comObj.removeEventListener('message', this._onComObjOnMessage);
  3492. }
  3493. };
  3494. function loadJpegStream(id, imageUrl, objs) {
  3495. var img = new Image();
  3496. img.onload = (function loadJpegStream_onloadClosure() {
  3497. objs.resolve(id, img);
  3498. });
  3499. img.onerror = (function loadJpegStream_onerrorClosure() {
  3500. objs.resolve(id, null);
  3501. warn('Error during JPEG image loading');
  3502. });
  3503. img.src = imageUrl;
  3504. }
  3505. // Polyfill from https://github.com/Polymer/URL
  3506. /* Any copyright is dedicated to the Public Domain.
  3507. * http://creativecommons.org/publicdomain/zero/1.0/ */
  3508. (function checkURLConstructor(scope) {
  3509. /* jshint ignore:start */
  3510. // feature detect for URL constructor
  3511. var hasWorkingUrl = false;
  3512. try {
  3513. if (typeof URL === 'function' &&
  3514. typeof URL.prototype === 'object' &&
  3515. ('origin' in URL.prototype)) {
  3516. var u = new URL('b', 'http://a');
  3517. u.pathname = 'c%20d';
  3518. hasWorkingUrl = u.href === 'http://a/c%20d';
  3519. }
  3520. } catch(e) { }
  3521. if (hasWorkingUrl)
  3522. return;
  3523. var relative = Object.create(null);
  3524. relative['ftp'] = 21;
  3525. relative['file'] = 0;
  3526. relative['gopher'] = 70;
  3527. relative['http'] = 80;
  3528. relative['https'] = 443;
  3529. relative['ws'] = 80;
  3530. relative['wss'] = 443;
  3531. var relativePathDotMapping = Object.create(null);
  3532. relativePathDotMapping['%2e'] = '.';
  3533. relativePathDotMapping['.%2e'] = '..';
  3534. relativePathDotMapping['%2e.'] = '..';
  3535. relativePathDotMapping['%2e%2e'] = '..';
  3536. function isRelativeScheme(scheme) {
  3537. return relative[scheme] !== undefined;
  3538. }
  3539. function invalid() {
  3540. clear.call(this);
  3541. this._isInvalid = true;
  3542. }
  3543. function IDNAToASCII(h) {
  3544. if ('' == h) {
  3545. invalid.call(this)
  3546. }
  3547. // XXX
  3548. return h.toLowerCase()
  3549. }
  3550. function percentEscape(c) {
  3551. var unicode = c.charCodeAt(0);
  3552. if (unicode > 0x20 &&
  3553. unicode < 0x7F &&
  3554. // " # < > ? `
  3555. [0x22, 0x23, 0x3C, 0x3E, 0x3F, 0x60].indexOf(unicode) == -1
  3556. ) {
  3557. return c;
  3558. }
  3559. return encodeURIComponent(c);
  3560. }
  3561. function percentEscapeQuery(c) {
  3562. // XXX This actually needs to encode c using encoding and then
  3563. // convert the bytes one-by-one.
  3564. var unicode = c.charCodeAt(0);
  3565. if (unicode > 0x20 &&
  3566. unicode < 0x7F &&
  3567. // " # < > ` (do not escape '?')
  3568. [0x22, 0x23, 0x3C, 0x3E, 0x60].indexOf(unicode) == -1
  3569. ) {
  3570. return c;
  3571. }
  3572. return encodeURIComponent(c);
  3573. }
  3574. var EOF = undefined,
  3575. ALPHA = /[a-zA-Z]/,
  3576. ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/;
  3577. function parse(input, stateOverride, base) {
  3578. function err(message) {
  3579. errors.push(message)
  3580. }
  3581. var state = stateOverride || 'scheme start',
  3582. cursor = 0,
  3583. buffer = '',
  3584. seenAt = false,
  3585. seenBracket = false,
  3586. errors = [];
  3587. loop: while ((input[cursor - 1] != EOF || cursor == 0) && !this._isInvalid) {
  3588. var c = input[cursor];
  3589. switch (state) {
  3590. case 'scheme start':
  3591. if (c && ALPHA.test(c)) {
  3592. buffer += c.toLowerCase(); // ASCII-safe
  3593. state = 'scheme';
  3594. } else if (!stateOverride) {
  3595. buffer = '';
  3596. state = 'no scheme';
  3597. continue;
  3598. } else {
  3599. err('Invalid scheme.');
  3600. break loop;
  3601. }
  3602. break;
  3603. case 'scheme':
  3604. if (c && ALPHANUMERIC.test(c)) {
  3605. buffer += c.toLowerCase(); // ASCII-safe
  3606. } else if (':' == c) {
  3607. this._scheme = buffer;
  3608. buffer = '';
  3609. if (stateOverride) {
  3610. break loop;
  3611. }
  3612. if (isRelativeScheme(this._scheme)) {
  3613. this._isRelative = true;
  3614. }
  3615. if ('file' == this._scheme) {
  3616. state = 'relative';
  3617. } else if (this._isRelative && base && base._scheme == this._scheme) {
  3618. state = 'relative or authority';
  3619. } else if (this._isRelative) {
  3620. state = 'authority first slash';
  3621. } else {
  3622. state = 'scheme data';
  3623. }
  3624. } else if (!stateOverride) {
  3625. buffer = '';
  3626. cursor = 0;
  3627. state = 'no scheme';
  3628. continue;
  3629. } else if (EOF == c) {
  3630. break loop;
  3631. } else {
  3632. err('Code point not allowed in scheme: ' + c)
  3633. break loop;
  3634. }
  3635. break;
  3636. case 'scheme data':
  3637. if ('?' == c) {
  3638. this._query = '?';
  3639. state = 'query';
  3640. } else if ('#' == c) {
  3641. this._fragment = '#';
  3642. state = 'fragment';
  3643. } else {
  3644. // XXX error handling
  3645. if (EOF != c && '\t' != c && '\n' != c && '\r' != c) {
  3646. this._schemeData += percentEscape(c);
  3647. }
  3648. }
  3649. break;
  3650. case 'no scheme':
  3651. if (!base || !(isRelativeScheme(base._scheme))) {
  3652. err('Missing scheme.');
  3653. invalid.call(this);
  3654. } else {
  3655. state = 'relative';
  3656. continue;
  3657. }
  3658. break;
  3659. case 'relative or authority':
  3660. if ('/' == c && '/' == input[cursor+1]) {
  3661. state = 'authority ignore slashes';
  3662. } else {
  3663. err('Expected /, got: ' + c);
  3664. state = 'relative';
  3665. continue
  3666. }
  3667. break;
  3668. case 'relative':
  3669. this._isRelative = true;
  3670. if ('file' != this._scheme)
  3671. this._scheme = base._scheme;
  3672. if (EOF == c) {
  3673. this._host = base._host;
  3674. this._port = base._port;
  3675. this._path = base._path.slice();
  3676. this._query = base._query;
  3677. this._username = base._username;
  3678. this._password = base._password;
  3679. break loop;
  3680. } else if ('/' == c || '\\' == c) {
  3681. if ('\\' == c)
  3682. err('\\ is an invalid code point.');
  3683. state = 'relative slash';
  3684. } else if ('?' == c) {
  3685. this._host = base._host;
  3686. this._port = base._port;
  3687. this._path = base._path.slice();
  3688. this._query = '?';
  3689. this._username = base._username;
  3690. this._password = base._password;
  3691. state = 'query';
  3692. } else if ('#' == c) {
  3693. this._host = base._host;
  3694. this._port = base._port;
  3695. this._path = base._path.slice();
  3696. this._query = base._query;
  3697. this._fragment = '#';
  3698. this._username = base._username;
  3699. this._password = base._password;
  3700. state = 'fragment';
  3701. } else {
  3702. var nextC = input[cursor+1]
  3703. var nextNextC = input[cursor+2]
  3704. if (
  3705. 'file' != this._scheme || !ALPHA.test(c) ||
  3706. (nextC != ':' && nextC != '|') ||
  3707. (EOF != nextNextC && '/' != nextNextC && '\\' != nextNextC && '?' != nextNextC && '#' != nextNextC)) {
  3708. this._host = base._host;
  3709. this._port = base._port;
  3710. this._username = base._username;
  3711. this._password = base._password;
  3712. this._path = base._path.slice();
  3713. this._path.pop();
  3714. }
  3715. state = 'relative path';
  3716. continue;
  3717. }
  3718. break;
  3719. case 'relative slash':
  3720. if ('/' == c || '\\' == c) {
  3721. if ('\\' == c) {
  3722. err('\\ is an invalid code point.');
  3723. }
  3724. if ('file' == this._scheme) {
  3725. state = 'file host';
  3726. } else {
  3727. state = 'authority ignore slashes';
  3728. }
  3729. } else {
  3730. if ('file' != this._scheme) {
  3731. this._host = base._host;
  3732. this._port = base._port;
  3733. this._username = base._username;
  3734. this._password = base._password;
  3735. }
  3736. state = 'relative path';
  3737. continue;
  3738. }
  3739. break;
  3740. case 'authority first slash':
  3741. if ('/' == c) {
  3742. state = 'authority second slash';
  3743. } else {
  3744. err("Expected '/', got: " + c);
  3745. state = 'authority ignore slashes';
  3746. continue;
  3747. }
  3748. break;
  3749. case 'authority second slash':
  3750. state = 'authority ignore slashes';
  3751. if ('/' != c) {
  3752. err("Expected '/', got: " + c);
  3753. continue;
  3754. }
  3755. break;
  3756. case 'authority ignore slashes':
  3757. if ('/' != c && '\\' != c) {
  3758. state = 'authority';
  3759. continue;
  3760. } else {
  3761. err('Expected authority, got: ' + c);
  3762. }
  3763. break;
  3764. case 'authority':
  3765. if ('@' == c) {
  3766. if (seenAt) {
  3767. err('@ already seen.');
  3768. buffer += '%40';
  3769. }
  3770. seenAt = true;
  3771. for (var i = 0; i < buffer.length; i++) {
  3772. var cp = buffer[i];
  3773. if ('\t' == cp || '\n' == cp || '\r' == cp) {
  3774. err('Invalid whitespace in authority.');
  3775. continue;
  3776. }
  3777. // XXX check URL code points
  3778. if (':' == cp && null === this._password) {
  3779. this._password = '';
  3780. continue;
  3781. }
  3782. var tempC = percentEscape(cp);
  3783. (null !== this._password) ? this._password += tempC : this._username += tempC;
  3784. }
  3785. buffer = '';
  3786. } else if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c) {
  3787. cursor -= buffer.length;
  3788. buffer = '';
  3789. state = 'host';
  3790. continue;
  3791. } else {
  3792. buffer += c;
  3793. }
  3794. break;
  3795. case 'file host':
  3796. if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c) {
  3797. if (buffer.length == 2 && ALPHA.test(buffer[0]) && (buffer[1] == ':' || buffer[1] == '|')) {
  3798. state = 'relative path';
  3799. } else if (buffer.length == 0) {
  3800. state = 'relative path start';
  3801. } else {
  3802. this._host = IDNAToASCII.call(this, buffer);
  3803. buffer = '';
  3804. state = 'relative path start';
  3805. }
  3806. continue;
  3807. } else if ('\t' == c || '\n' == c || '\r' == c) {
  3808. err('Invalid whitespace in file host.');
  3809. } else {
  3810. buffer += c;
  3811. }
  3812. break;
  3813. case 'host':
  3814. case 'hostname':
  3815. if (':' == c && !seenBracket) {
  3816. // XXX host parsing
  3817. this._host = IDNAToASCII.call(this, buffer);
  3818. buffer = '';
  3819. state = 'port';
  3820. if ('hostname' == stateOverride) {
  3821. break loop;
  3822. }
  3823. } else if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c) {
  3824. this._host = IDNAToASCII.call(this, buffer);
  3825. buffer = '';
  3826. state = 'relative path start';
  3827. if (stateOverride) {
  3828. break loop;
  3829. }
  3830. continue;
  3831. } else if ('\t' != c && '\n' != c && '\r' != c) {
  3832. if ('[' == c) {
  3833. seenBracket = true;
  3834. } else if (']' == c) {
  3835. seenBracket = false;
  3836. }
  3837. buffer += c;
  3838. } else {
  3839. err('Invalid code point in host/hostname: ' + c);
  3840. }
  3841. break;
  3842. case 'port':
  3843. if (/[0-9]/.test(c)) {
  3844. buffer += c;
  3845. } else if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c || stateOverride) {
  3846. if ('' != buffer) {
  3847. var temp = parseInt(buffer, 10);
  3848. if (temp != relative[this._scheme]) {
  3849. this._port = temp + '';
  3850. }
  3851. buffer = '';
  3852. }
  3853. if (stateOverride) {
  3854. break loop;
  3855. }
  3856. state = 'relative path start';
  3857. continue;
  3858. } else if ('\t' == c || '\n' == c || '\r' == c) {
  3859. err('Invalid code point in port: ' + c);
  3860. } else {
  3861. invalid.call(this);
  3862. }
  3863. break;
  3864. case 'relative path start':
  3865. if ('\\' == c)
  3866. err("'\\' not allowed in path.");
  3867. state = 'relative path';
  3868. if ('/' != c && '\\' != c) {
  3869. continue;
  3870. }
  3871. break;
  3872. case 'relative path':
  3873. if (EOF == c || '/' == c || '\\' == c || (!stateOverride && ('?' == c || '#' == c))) {
  3874. if ('\\' == c) {
  3875. err('\\ not allowed in relative path.');
  3876. }
  3877. var tmp;
  3878. if (tmp = relativePathDotMapping[buffer.toLowerCase()]) {
  3879. buffer = tmp;
  3880. }
  3881. if ('..' == buffer) {
  3882. this._path.pop();
  3883. if ('/' != c && '\\' != c) {
  3884. this._path.push('');
  3885. }
  3886. } else if ('.' == buffer && '/' != c && '\\' != c) {
  3887. this._path.push('');
  3888. } else if ('.' != buffer) {
  3889. if ('file' == this._scheme && this._path.length == 0 && buffer.length == 2 && ALPHA.test(buffer[0]) && buffer[1] == '|') {
  3890. buffer = buffer[0] + ':';
  3891. }
  3892. this._path.push(buffer);
  3893. }
  3894. buffer = '';
  3895. if ('?' == c) {
  3896. this._query = '?';
  3897. state = 'query';
  3898. } else if ('#' == c) {
  3899. this._fragment = '#';
  3900. state = 'fragment';
  3901. }
  3902. } else if ('\t' != c && '\n' != c && '\r' != c) {
  3903. buffer += percentEscape(c);
  3904. }
  3905. break;
  3906. case 'query':
  3907. if (!stateOverride && '#' == c) {
  3908. this._fragment = '#';
  3909. state = 'fragment';
  3910. } else if (EOF != c && '\t' != c && '\n' != c && '\r' != c) {
  3911. this._query += percentEscapeQuery(c);
  3912. }
  3913. break;
  3914. case 'fragment':
  3915. if (EOF != c && '\t' != c && '\n' != c && '\r' != c) {
  3916. this._fragment += c;
  3917. }
  3918. break;
  3919. }
  3920. cursor++;
  3921. }
  3922. }
  3923. function clear() {
  3924. this._scheme = '';
  3925. this._schemeData = '';
  3926. this._username = '';
  3927. this._password = null;
  3928. this._host = '';
  3929. this._port = '';
  3930. this._path = [];
  3931. this._query = '';
  3932. this._fragment = '';
  3933. this._isInvalid = false;
  3934. this._isRelative = false;
  3935. }
  3936. // Does not process domain names or IP addresses.
  3937. // Does not handle encoding for the query parameter.
  3938. function jURL(url, base /* , encoding */) {
  3939. if (base !== undefined && !(base instanceof jURL))
  3940. base = new jURL(String(base));
  3941. this._url = url;
  3942. clear.call(this);
  3943. var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, '');
  3944. // encoding = encoding || 'utf-8'
  3945. parse.call(this, input, null, base);
  3946. }
  3947. jURL.prototype = {
  3948. toString: function() {
  3949. return this.href;
  3950. },
  3951. get href() {
  3952. if (this._isInvalid)
  3953. return this._url;
  3954. var authority = '';
  3955. if ('' != this._username || null != this._password) {
  3956. authority = this._username +
  3957. (null != this._password ? ':' + this._password : '') + '@';
  3958. }
  3959. return this.protocol +
  3960. (this._isRelative ? '//' + authority + this.host : '') +
  3961. this.pathname + this._query + this._fragment;
  3962. },
  3963. set href(href) {
  3964. clear.call(this);
  3965. parse.call(this, href);
  3966. },
  3967. get protocol() {
  3968. return this._scheme + ':';
  3969. },
  3970. set protocol(protocol) {
  3971. if (this._isInvalid)
  3972. return;
  3973. parse.call(this, protocol + ':', 'scheme start');
  3974. },
  3975. get host() {
  3976. return this._isInvalid ? '' : this._port ?
  3977. this._host + ':' + this._port : this._host;
  3978. },
  3979. set host(host) {
  3980. if (this._isInvalid || !this._isRelative)
  3981. return;
  3982. parse.call(this, host, 'host');
  3983. },
  3984. get hostname() {
  3985. return this._host;
  3986. },
  3987. set hostname(hostname) {
  3988. if (this._isInvalid || !this._isRelative)
  3989. return;
  3990. parse.call(this, hostname, 'hostname');
  3991. },
  3992. get port() {
  3993. return this._port;
  3994. },
  3995. set port(port) {
  3996. if (this._isInvalid || !this._isRelative)
  3997. return;
  3998. parse.call(this, port, 'port');
  3999. },
  4000. get pathname() {
  4001. return this._isInvalid ? '' : this._isRelative ?
  4002. '/' + this._path.join('/') : this._schemeData;
  4003. },
  4004. set pathname(pathname) {
  4005. if (this._isInvalid || !this._isRelative)
  4006. return;
  4007. this._path = [];
  4008. parse.call(this, pathname, 'relative path start');
  4009. },
  4010. get search() {
  4011. return this._isInvalid || !this._query || '?' == this._query ?
  4012. '' : this._query;
  4013. },
  4014. set search(search) {
  4015. if (this._isInvalid || !this._isRelative)
  4016. return;
  4017. this._query = '?';
  4018. if ('?' == search[0])
  4019. search = search.slice(1);
  4020. parse.call(this, search, 'query');
  4021. },
  4022. get hash() {
  4023. return this._isInvalid || !this._fragment || '#' == this._fragment ?
  4024. '' : this._fragment;
  4025. },
  4026. set hash(hash) {
  4027. if (this._isInvalid)
  4028. return;
  4029. this._fragment = '#';
  4030. if ('#' == hash[0])
  4031. hash = hash.slice(1);
  4032. parse.call(this, hash, 'fragment');
  4033. },
  4034. get origin() {
  4035. var host;
  4036. if (this._isInvalid || !this._scheme) {
  4037. return '';
  4038. }
  4039. // javascript: Gecko returns String(""), WebKit/Blink String("null")
  4040. // Gecko throws error for "data://"
  4041. // data: Gecko returns "", Blink returns "data://", WebKit returns "null"
  4042. // Gecko returns String("") for file: mailto:
  4043. // WebKit/Blink returns String("SCHEME://") for file: mailto:
  4044. switch (this._scheme) {
  4045. case 'data':
  4046. case 'file':
  4047. case 'javascript':
  4048. case 'mailto':
  4049. return 'null';
  4050. }
  4051. host = this.host;
  4052. if (!host) {
  4053. return '';
  4054. }
  4055. return this._scheme + '://' + host;
  4056. }
  4057. };
  4058. // Copy over the static methods
  4059. var OriginalURL = scope.URL;
  4060. if (OriginalURL) {
  4061. jURL.createObjectURL = function(blob) {
  4062. // IE extension allows a second optional options argument.
  4063. // http://msdn.microsoft.com/en-us/library/ie/hh772302(v=vs.85).aspx
  4064. return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
  4065. };
  4066. jURL.revokeObjectURL = function(url) {
  4067. OriginalURL.revokeObjectURL(url);
  4068. };
  4069. }
  4070. scope.URL = jURL;
  4071. /* jshint ignore:end */
  4072. })(globalScope);
  4073. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  4074. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  4075. exports.OPS = OPS;
  4076. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  4077. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  4078. exports.AnnotationFlag = AnnotationFlag;
  4079. exports.AnnotationType = AnnotationType;
  4080. exports.FontType = FontType;
  4081. exports.ImageKind = ImageKind;
  4082. exports.InvalidPDFException = InvalidPDFException;
  4083. exports.LinkTarget = LinkTarget;
  4084. exports.LinkTargetStringMap = LinkTargetStringMap;
  4085. exports.MessageHandler = MessageHandler;
  4086. exports.MissingDataException = MissingDataException;
  4087. exports.MissingPDFException = MissingPDFException;
  4088. exports.NotImplementedException = NotImplementedException;
  4089. exports.PasswordException = PasswordException;
  4090. exports.PasswordResponses = PasswordResponses;
  4091. exports.StatTimer = StatTimer;
  4092. exports.StreamType = StreamType;
  4093. exports.TextRenderingMode = TextRenderingMode;
  4094. exports.UnexpectedResponseException = UnexpectedResponseException;
  4095. exports.UnknownErrorException = UnknownErrorException;
  4096. exports.Util = Util;
  4097. exports.XRefParseException = XRefParseException;
  4098. exports.arrayByteLength = arrayByteLength;
  4099. exports.arraysToBytes = arraysToBytes;
  4100. exports.assert = assert;
  4101. exports.bytesToString = bytesToString;
  4102. exports.combineUrl = combineUrl;
  4103. exports.createPromiseCapability = createPromiseCapability;
  4104. exports.deprecated = deprecated;
  4105. exports.error = error;
  4106. exports.getFilenameFromUrl = getFilenameFromUrl;
  4107. exports.getLookupTableFactory = getLookupTableFactory;
  4108. exports.info = info;
  4109. exports.isArray = isArray;
  4110. exports.isArrayBuffer = isArrayBuffer;
  4111. exports.isBool = isBool;
  4112. exports.isEmptyObj = isEmptyObj;
  4113. exports.isExternalLinkTargetSet = isExternalLinkTargetSet;
  4114. exports.isInt = isInt;
  4115. exports.isNum = isNum;
  4116. exports.isString = isString;
  4117. exports.isSameOrigin = isSameOrigin;
  4118. exports.isValidUrl = isValidUrl;
  4119. exports.addLinkAttributes = addLinkAttributes;
  4120. exports.loadJpegStream = loadJpegStream;
  4121. exports.log2 = log2;
  4122. exports.readInt8 = readInt8;
  4123. exports.readUint16 = readUint16;
  4124. exports.readUint32 = readUint32;
  4125. exports.removeNullCharacters = removeNullCharacters;
  4126. exports.shadow = shadow;
  4127. exports.string32 = string32;
  4128. exports.stringToBytes = stringToBytes;
  4129. exports.stringToPDFString = stringToPDFString;
  4130. exports.stringToUTF8String = stringToUTF8String;
  4131. exports.utf8StringToString = utf8StringToString;
  4132. exports.warn = warn;
  4133. }));
  4134. (function (root, factory) {
  4135. {
  4136. factory((root.pdfjsCoreChunkedStream = {}), root.pdfjsSharedUtil);
  4137. }
  4138. }(this, function (exports, sharedUtil) {
  4139. var MissingDataException = sharedUtil.MissingDataException;
  4140. var arrayByteLength = sharedUtil.arrayByteLength;
  4141. var arraysToBytes = sharedUtil.arraysToBytes;
  4142. var assert = sharedUtil.assert;
  4143. var createPromiseCapability = sharedUtil.createPromiseCapability;
  4144. var isInt = sharedUtil.isInt;
  4145. var isEmptyObj = sharedUtil.isEmptyObj;
  4146. var ChunkedStream = (function ChunkedStreamClosure() {
  4147. function ChunkedStream(length, chunkSize, manager) {
  4148. this.bytes = new Uint8Array(length);
  4149. this.start = 0;
  4150. this.pos = 0;
  4151. this.end = length;
  4152. this.chunkSize = chunkSize;
  4153. this.loadedChunks = [];
  4154. this.numChunksLoaded = 0;
  4155. this.numChunks = Math.ceil(length / chunkSize);
  4156. this.manager = manager;
  4157. this.progressiveDataLength = 0;
  4158. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  4159. }
  4160. // required methods for a stream. if a particular stream does not
  4161. // implement these, an error should be thrown
  4162. ChunkedStream.prototype = {
  4163. getMissingChunks: function ChunkedStream_getMissingChunks() {
  4164. var chunks = [];
  4165. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  4166. if (!this.loadedChunks[chunk]) {
  4167. chunks.push(chunk);
  4168. }
  4169. }
  4170. return chunks;
  4171. },
  4172. getBaseStreams: function ChunkedStream_getBaseStreams() {
  4173. return [this];
  4174. },
  4175. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  4176. return this.numChunksLoaded === this.numChunks;
  4177. },
  4178. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  4179. var end = begin + chunk.byteLength;
  4180. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  4181. // Using this.length is inaccurate here since this.start can be moved
  4182. // See ChunkedStream.moveStart()
  4183. var length = this.bytes.length;
  4184. assert(end % this.chunkSize === 0 || end === length,
  4185. 'Bad end offset: ' + end);
  4186. this.bytes.set(new Uint8Array(chunk), begin);
  4187. var chunkSize = this.chunkSize;
  4188. var beginChunk = Math.floor(begin / chunkSize);
  4189. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  4190. var curChunk;
  4191. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  4192. if (!this.loadedChunks[curChunk]) {
  4193. this.loadedChunks[curChunk] = true;
  4194. ++this.numChunksLoaded;
  4195. }
  4196. }
  4197. },
  4198. onReceiveProgressiveData:
  4199. function ChunkedStream_onReceiveProgressiveData(data) {
  4200. var position = this.progressiveDataLength;
  4201. var beginChunk = Math.floor(position / this.chunkSize);
  4202. this.bytes.set(new Uint8Array(data), position);
  4203. position += data.byteLength;
  4204. this.progressiveDataLength = position;
  4205. var endChunk = position >= this.end ? this.numChunks :
  4206. Math.floor(position / this.chunkSize);
  4207. var curChunk;
  4208. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  4209. if (!this.loadedChunks[curChunk]) {
  4210. this.loadedChunks[curChunk] = true;
  4211. ++this.numChunksLoaded;
  4212. }
  4213. }
  4214. },
  4215. ensureByte: function ChunkedStream_ensureByte(pos) {
  4216. var chunk = Math.floor(pos / this.chunkSize);
  4217. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  4218. return;
  4219. }
  4220. if (!this.loadedChunks[chunk]) {
  4221. throw new MissingDataException(pos, pos + 1);
  4222. }
  4223. this.lastSuccessfulEnsureByteChunk = chunk;
  4224. },
  4225. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  4226. if (begin >= end) {
  4227. return;
  4228. }
  4229. if (end <= this.progressiveDataLength) {
  4230. return;
  4231. }
  4232. var chunkSize = this.chunkSize;
  4233. var beginChunk = Math.floor(begin / chunkSize);
  4234. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  4235. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  4236. if (!this.loadedChunks[chunk]) {
  4237. throw new MissingDataException(begin, end);
  4238. }
  4239. }
  4240. },
  4241. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  4242. var chunk, numChunks = this.numChunks;
  4243. for (var i = 0; i < numChunks; ++i) {
  4244. chunk = (beginChunk + i) % numChunks; // Wrap around to beginning
  4245. if (!this.loadedChunks[chunk]) {
  4246. return chunk;
  4247. }
  4248. }
  4249. return null;
  4250. },
  4251. hasChunk: function ChunkedStream_hasChunk(chunk) {
  4252. return !!this.loadedChunks[chunk];
  4253. },
  4254. get length() {
  4255. return this.end - this.start;
  4256. },
  4257. get isEmpty() {
  4258. return this.length === 0;
  4259. },
  4260. getByte: function ChunkedStream_getByte() {
  4261. var pos = this.pos;
  4262. if (pos >= this.end) {
  4263. return -1;
  4264. }
  4265. this.ensureByte(pos);
  4266. return this.bytes[this.pos++];
  4267. },
  4268. getUint16: function ChunkedStream_getUint16() {
  4269. var b0 = this.getByte();
  4270. var b1 = this.getByte();
  4271. if (b0 === -1 || b1 === -1) {
  4272. return -1;
  4273. }
  4274. return (b0 << 8) + b1;
  4275. },
  4276. getInt32: function ChunkedStream_getInt32() {
  4277. var b0 = this.getByte();
  4278. var b1 = this.getByte();
  4279. var b2 = this.getByte();
  4280. var b3 = this.getByte();
  4281. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  4282. },
  4283. // returns subarray of original buffer
  4284. // should only be read
  4285. getBytes: function ChunkedStream_getBytes(length) {
  4286. var bytes = this.bytes;
  4287. var pos = this.pos;
  4288. var strEnd = this.end;
  4289. if (!length) {
  4290. this.ensureRange(pos, strEnd);
  4291. return bytes.subarray(pos, strEnd);
  4292. }
  4293. var end = pos + length;
  4294. if (end > strEnd) {
  4295. end = strEnd;
  4296. }
  4297. this.ensureRange(pos, end);
  4298. this.pos = end;
  4299. return bytes.subarray(pos, end);
  4300. },
  4301. peekByte: function ChunkedStream_peekByte() {
  4302. var peekedByte = this.getByte();
  4303. this.pos--;
  4304. return peekedByte;
  4305. },
  4306. peekBytes: function ChunkedStream_peekBytes(length) {
  4307. var bytes = this.getBytes(length);
  4308. this.pos -= bytes.length;
  4309. return bytes;
  4310. },
  4311. getByteRange: function ChunkedStream_getBytes(begin, end) {
  4312. this.ensureRange(begin, end);
  4313. return this.bytes.subarray(begin, end);
  4314. },
  4315. skip: function ChunkedStream_skip(n) {
  4316. if (!n) {
  4317. n = 1;
  4318. }
  4319. this.pos += n;
  4320. },
  4321. reset: function ChunkedStream_reset() {
  4322. this.pos = this.start;
  4323. },
  4324. moveStart: function ChunkedStream_moveStart() {
  4325. this.start = this.pos;
  4326. },
  4327. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  4328. this.ensureRange(start, start + length);
  4329. function ChunkedStreamSubstream() {}
  4330. ChunkedStreamSubstream.prototype = Object.create(this);
  4331. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  4332. var chunkSize = this.chunkSize;
  4333. var beginChunk = Math.floor(this.start / chunkSize);
  4334. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  4335. var missingChunks = [];
  4336. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  4337. if (!this.loadedChunks[chunk]) {
  4338. missingChunks.push(chunk);
  4339. }
  4340. }
  4341. return missingChunks;
  4342. };
  4343. var subStream = new ChunkedStreamSubstream();
  4344. subStream.pos = subStream.start = start;
  4345. subStream.end = start + length || this.end;
  4346. subStream.dict = dict;
  4347. return subStream;
  4348. },
  4349. isStream: true
  4350. };
  4351. return ChunkedStream;
  4352. })();
  4353. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  4354. function ChunkedStreamManager(pdfNetworkStream, args) {
  4355. var chunkSize = args.rangeChunkSize;
  4356. var length = args.length;
  4357. this.stream = new ChunkedStream(length, chunkSize, this);
  4358. this.length = length;
  4359. this.chunkSize = chunkSize;
  4360. this.pdfNetworkStream = pdfNetworkStream;
  4361. this.url = args.url;
  4362. this.disableAutoFetch = args.disableAutoFetch;
  4363. this.msgHandler = args.msgHandler;
  4364. this.currRequestId = 0;
  4365. this.chunksNeededByRequest = Object.create(null);
  4366. this.requestsByChunk = Object.create(null);
  4367. this.promisesByRequest = Object.create(null);
  4368. this.progressiveDataLength = 0;
  4369. this.aborted = false;
  4370. this._loadedStreamCapability = createPromiseCapability();
  4371. }
  4372. ChunkedStreamManager.prototype = {
  4373. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  4374. return this._loadedStreamCapability.promise;
  4375. },
  4376. sendRequest: function ChunkedStreamManager_sendRequest(begin, end) {
  4377. var rangeReader = this.pdfNetworkStream.getRangeReader(begin, end);
  4378. if (!rangeReader.isStreamingSupported) {
  4379. rangeReader.onProgress = this.onProgress.bind(this);
  4380. }
  4381. var chunks = [], loaded = 0;
  4382. var manager = this;
  4383. var promise = new Promise(function (resolve, reject) {
  4384. var readChunk = function (chunk) {
  4385. try {
  4386. if (!chunk.done) {
  4387. var data = chunk.value;
  4388. chunks.push(data);
  4389. loaded += arrayByteLength(data);
  4390. if (rangeReader.isStreamingSupported) {
  4391. manager.onProgress({loaded: loaded});
  4392. }
  4393. rangeReader.read().then(readChunk, reject);
  4394. return;
  4395. }
  4396. var chunkData = arraysToBytes(chunks);
  4397. chunks = null;
  4398. resolve(chunkData);
  4399. } catch (e) {
  4400. reject(e);
  4401. }
  4402. };
  4403. rangeReader.read().then(readChunk, reject);
  4404. });
  4405. promise.then(function (data) {
  4406. if (this.aborted) {
  4407. return; // ignoring any data after abort
  4408. }
  4409. this.onReceiveData({chunk: data, begin: begin});
  4410. }.bind(this));
  4411. // TODO check errors
  4412. },
  4413. // Get all the chunks that are not yet loaded and groups them into
  4414. // contiguous ranges to load in as few requests as possible
  4415. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  4416. var missingChunks = this.stream.getMissingChunks();
  4417. this._requestChunks(missingChunks);
  4418. return this._loadedStreamCapability.promise;
  4419. },
  4420. _requestChunks: function ChunkedStreamManager_requestChunks(chunks) {
  4421. var requestId = this.currRequestId++;
  4422. var i, ii;
  4423. var chunksNeeded = Object.create(null);
  4424. this.chunksNeededByRequest[requestId] = chunksNeeded;
  4425. for (i = 0, ii = chunks.length; i < ii; i++) {
  4426. if (!this.stream.hasChunk(chunks[i])) {
  4427. chunksNeeded[chunks[i]] = true;
  4428. }
  4429. }
  4430. if (isEmptyObj(chunksNeeded)) {
  4431. return Promise.resolve();
  4432. }
  4433. var capability = createPromiseCapability();
  4434. this.promisesByRequest[requestId] = capability;
  4435. var chunksToRequest = [];
  4436. for (var chunk in chunksNeeded) {
  4437. chunk = chunk | 0;
  4438. if (!(chunk in this.requestsByChunk)) {
  4439. this.requestsByChunk[chunk] = [];
  4440. chunksToRequest.push(chunk);
  4441. }
  4442. this.requestsByChunk[chunk].push(requestId);
  4443. }
  4444. if (!chunksToRequest.length) {
  4445. return capability.promise;
  4446. }
  4447. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  4448. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  4449. var groupedChunk = groupedChunksToRequest[i];
  4450. var begin = groupedChunk.beginChunk * this.chunkSize;
  4451. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  4452. this.sendRequest(begin, end);
  4453. }
  4454. return capability.promise;
  4455. },
  4456. getStream: function ChunkedStreamManager_getStream() {
  4457. return this.stream;
  4458. },
  4459. // Loads any chunks in the requested range that are not yet loaded
  4460. requestRange: function ChunkedStreamManager_requestRange(begin, end) {
  4461. end = Math.min(end, this.length);
  4462. var beginChunk = this.getBeginChunk(begin);
  4463. var endChunk = this.getEndChunk(end);
  4464. var chunks = [];
  4465. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  4466. chunks.push(chunk);
  4467. }
  4468. return this._requestChunks(chunks);
  4469. },
  4470. requestRanges: function ChunkedStreamManager_requestRanges(ranges) {
  4471. ranges = ranges || [];
  4472. var chunksToRequest = [];
  4473. for (var i = 0; i < ranges.length; i++) {
  4474. var beginChunk = this.getBeginChunk(ranges[i].begin);
  4475. var endChunk = this.getEndChunk(ranges[i].end);
  4476. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  4477. if (chunksToRequest.indexOf(chunk) < 0) {
  4478. chunksToRequest.push(chunk);
  4479. }
  4480. }
  4481. }
  4482. chunksToRequest.sort(function(a, b) { return a - b; });
  4483. return this._requestChunks(chunksToRequest);
  4484. },
  4485. // Groups a sorted array of chunks into as few contiguous larger
  4486. // chunks as possible
  4487. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  4488. var groupedChunks = [];
  4489. var beginChunk = -1;
  4490. var prevChunk = -1;
  4491. for (var i = 0; i < chunks.length; ++i) {
  4492. var chunk = chunks[i];
  4493. if (beginChunk < 0) {
  4494. beginChunk = chunk;
  4495. }
  4496. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  4497. groupedChunks.push({ beginChunk: beginChunk,
  4498. endChunk: prevChunk + 1 });
  4499. beginChunk = chunk;
  4500. }
  4501. if (i + 1 === chunks.length) {
  4502. groupedChunks.push({ beginChunk: beginChunk,
  4503. endChunk: chunk + 1 });
  4504. }
  4505. prevChunk = chunk;
  4506. }
  4507. return groupedChunks;
  4508. },
  4509. onProgress: function ChunkedStreamManager_onProgress(args) {
  4510. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  4511. args.loaded);
  4512. this.msgHandler.send('DocProgress', {
  4513. loaded: bytesLoaded,
  4514. total: this.length
  4515. });
  4516. },
  4517. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  4518. var chunk = args.chunk;
  4519. var isProgressive = args.begin === undefined;
  4520. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  4521. var end = begin + chunk.byteLength;
  4522. var beginChunk = Math.floor(begin / this.chunkSize);
  4523. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  4524. Math.ceil(end / this.chunkSize);
  4525. if (isProgressive) {
  4526. this.stream.onReceiveProgressiveData(chunk);
  4527. this.progressiveDataLength = end;
  4528. } else {
  4529. this.stream.onReceiveData(begin, chunk);
  4530. }
  4531. if (this.stream.allChunksLoaded()) {
  4532. this._loadedStreamCapability.resolve(this.stream);
  4533. }
  4534. var loadedRequests = [];
  4535. var i, requestId;
  4536. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  4537. // The server might return more chunks than requested
  4538. var requestIds = this.requestsByChunk[chunk] || [];
  4539. delete this.requestsByChunk[chunk];
  4540. for (i = 0; i < requestIds.length; ++i) {
  4541. requestId = requestIds[i];
  4542. var chunksNeeded = this.chunksNeededByRequest[requestId];
  4543. if (chunk in chunksNeeded) {
  4544. delete chunksNeeded[chunk];
  4545. }
  4546. if (!isEmptyObj(chunksNeeded)) {
  4547. continue;
  4548. }
  4549. loadedRequests.push(requestId);
  4550. }
  4551. }
  4552. // If there are no pending requests, automatically fetch the next
  4553. // unfetched chunk of the PDF
  4554. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  4555. var nextEmptyChunk;
  4556. if (this.stream.numChunksLoaded === 1) {
  4557. // This is a special optimization so that after fetching the first
  4558. // chunk, rather than fetching the second chunk, we fetch the last
  4559. // chunk.
  4560. var lastChunk = this.stream.numChunks - 1;
  4561. if (!this.stream.hasChunk(lastChunk)) {
  4562. nextEmptyChunk = lastChunk;
  4563. }
  4564. } else {
  4565. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  4566. }
  4567. if (isInt(nextEmptyChunk)) {
  4568. this._requestChunks([nextEmptyChunk]);
  4569. }
  4570. }
  4571. for (i = 0; i < loadedRequests.length; ++i) {
  4572. requestId = loadedRequests[i];
  4573. var capability = this.promisesByRequest[requestId];
  4574. delete this.promisesByRequest[requestId];
  4575. capability.resolve();
  4576. }
  4577. this.msgHandler.send('DocProgress', {
  4578. loaded: this.stream.numChunksLoaded * this.chunkSize,
  4579. total: this.length
  4580. });
  4581. },
  4582. onError: function ChunkedStreamManager_onError(err) {
  4583. this._loadedStreamCapability.reject(err);
  4584. },
  4585. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  4586. var chunk = Math.floor(begin / this.chunkSize);
  4587. return chunk;
  4588. },
  4589. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  4590. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  4591. return chunk;
  4592. },
  4593. abort: function ChunkedStreamManager_abort() {
  4594. this.aborted = true;
  4595. if (this.pdfNetworkStream) {
  4596. this.pdfNetworkStream.cancelAllRequests('abort');
  4597. }
  4598. for(var requestId in this.promisesByRequest) {
  4599. var capability = this.promisesByRequest[requestId];
  4600. capability.reject(new Error('Request was aborted'));
  4601. }
  4602. }
  4603. };
  4604. return ChunkedStreamManager;
  4605. })();
  4606. exports.ChunkedStream = ChunkedStream;
  4607. exports.ChunkedStreamManager = ChunkedStreamManager;
  4608. }));
  4609. (function (root, factory) {
  4610. {
  4611. factory((root.pdfjsCoreGlyphList = {}), root.pdfjsSharedUtil);
  4612. }
  4613. }(this, function (exports, sharedUtil) {
  4614. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  4615. var getGlyphsUnicode = getLookupTableFactory(function (t) {
  4616. t['A'] = 0x0041;
  4617. t['AE'] = 0x00C6;
  4618. t['AEacute'] = 0x01FC;
  4619. t['AEmacron'] = 0x01E2;
  4620. t['AEsmall'] = 0xF7E6;
  4621. t['Aacute'] = 0x00C1;
  4622. t['Aacutesmall'] = 0xF7E1;
  4623. t['Abreve'] = 0x0102;
  4624. t['Abreveacute'] = 0x1EAE;
  4625. t['Abrevecyrillic'] = 0x04D0;
  4626. t['Abrevedotbelow'] = 0x1EB6;
  4627. t['Abrevegrave'] = 0x1EB0;
  4628. t['Abrevehookabove'] = 0x1EB2;
  4629. t['Abrevetilde'] = 0x1EB4;
  4630. t['Acaron'] = 0x01CD;
  4631. t['Acircle'] = 0x24B6;
  4632. t['Acircumflex'] = 0x00C2;
  4633. t['Acircumflexacute'] = 0x1EA4;
  4634. t['Acircumflexdotbelow'] = 0x1EAC;
  4635. t['Acircumflexgrave'] = 0x1EA6;
  4636. t['Acircumflexhookabove'] = 0x1EA8;
  4637. t['Acircumflexsmall'] = 0xF7E2;
  4638. t['Acircumflextilde'] = 0x1EAA;
  4639. t['Acute'] = 0xF6C9;
  4640. t['Acutesmall'] = 0xF7B4;
  4641. t['Acyrillic'] = 0x0410;
  4642. t['Adblgrave'] = 0x0200;
  4643. t['Adieresis'] = 0x00C4;
  4644. t['Adieresiscyrillic'] = 0x04D2;
  4645. t['Adieresismacron'] = 0x01DE;
  4646. t['Adieresissmall'] = 0xF7E4;
  4647. t['Adotbelow'] = 0x1EA0;
  4648. t['Adotmacron'] = 0x01E0;
  4649. t['Agrave'] = 0x00C0;
  4650. t['Agravesmall'] = 0xF7E0;
  4651. t['Ahookabove'] = 0x1EA2;
  4652. t['Aiecyrillic'] = 0x04D4;
  4653. t['Ainvertedbreve'] = 0x0202;
  4654. t['Alpha'] = 0x0391;
  4655. t['Alphatonos'] = 0x0386;
  4656. t['Amacron'] = 0x0100;
  4657. t['Amonospace'] = 0xFF21;
  4658. t['Aogonek'] = 0x0104;
  4659. t['Aring'] = 0x00C5;
  4660. t['Aringacute'] = 0x01FA;
  4661. t['Aringbelow'] = 0x1E00;
  4662. t['Aringsmall'] = 0xF7E5;
  4663. t['Asmall'] = 0xF761;
  4664. t['Atilde'] = 0x00C3;
  4665. t['Atildesmall'] = 0xF7E3;
  4666. t['Aybarmenian'] = 0x0531;
  4667. t['B'] = 0x0042;
  4668. t['Bcircle'] = 0x24B7;
  4669. t['Bdotaccent'] = 0x1E02;
  4670. t['Bdotbelow'] = 0x1E04;
  4671. t['Becyrillic'] = 0x0411;
  4672. t['Benarmenian'] = 0x0532;
  4673. t['Beta'] = 0x0392;
  4674. t['Bhook'] = 0x0181;
  4675. t['Blinebelow'] = 0x1E06;
  4676. t['Bmonospace'] = 0xFF22;
  4677. t['Brevesmall'] = 0xF6F4;
  4678. t['Bsmall'] = 0xF762;
  4679. t['Btopbar'] = 0x0182;
  4680. t['C'] = 0x0043;
  4681. t['Caarmenian'] = 0x053E;
  4682. t['Cacute'] = 0x0106;
  4683. t['Caron'] = 0xF6CA;
  4684. t['Caronsmall'] = 0xF6F5;
  4685. t['Ccaron'] = 0x010C;
  4686. t['Ccedilla'] = 0x00C7;
  4687. t['Ccedillaacute'] = 0x1E08;
  4688. t['Ccedillasmall'] = 0xF7E7;
  4689. t['Ccircle'] = 0x24B8;
  4690. t['Ccircumflex'] = 0x0108;
  4691. t['Cdot'] = 0x010A;
  4692. t['Cdotaccent'] = 0x010A;
  4693. t['Cedillasmall'] = 0xF7B8;
  4694. t['Chaarmenian'] = 0x0549;
  4695. t['Cheabkhasiancyrillic'] = 0x04BC;
  4696. t['Checyrillic'] = 0x0427;
  4697. t['Chedescenderabkhasiancyrillic'] = 0x04BE;
  4698. t['Chedescendercyrillic'] = 0x04B6;
  4699. t['Chedieresiscyrillic'] = 0x04F4;
  4700. t['Cheharmenian'] = 0x0543;
  4701. t['Chekhakassiancyrillic'] = 0x04CB;
  4702. t['Cheverticalstrokecyrillic'] = 0x04B8;
  4703. t['Chi'] = 0x03A7;
  4704. t['Chook'] = 0x0187;
  4705. t['Circumflexsmall'] = 0xF6F6;
  4706. t['Cmonospace'] = 0xFF23;
  4707. t['Coarmenian'] = 0x0551;
  4708. t['Csmall'] = 0xF763;
  4709. t['D'] = 0x0044;
  4710. t['DZ'] = 0x01F1;
  4711. t['DZcaron'] = 0x01C4;
  4712. t['Daarmenian'] = 0x0534;
  4713. t['Dafrican'] = 0x0189;
  4714. t['Dcaron'] = 0x010E;
  4715. t['Dcedilla'] = 0x1E10;
  4716. t['Dcircle'] = 0x24B9;
  4717. t['Dcircumflexbelow'] = 0x1E12;
  4718. t['Dcroat'] = 0x0110;
  4719. t['Ddotaccent'] = 0x1E0A;
  4720. t['Ddotbelow'] = 0x1E0C;
  4721. t['Decyrillic'] = 0x0414;
  4722. t['Deicoptic'] = 0x03EE;
  4723. t['Delta'] = 0x2206;
  4724. t['Deltagreek'] = 0x0394;
  4725. t['Dhook'] = 0x018A;
  4726. t['Dieresis'] = 0xF6CB;
  4727. t['DieresisAcute'] = 0xF6CC;
  4728. t['DieresisGrave'] = 0xF6CD;
  4729. t['Dieresissmall'] = 0xF7A8;
  4730. t['Digammagreek'] = 0x03DC;
  4731. t['Djecyrillic'] = 0x0402;
  4732. t['Dlinebelow'] = 0x1E0E;
  4733. t['Dmonospace'] = 0xFF24;
  4734. t['Dotaccentsmall'] = 0xF6F7;
  4735. t['Dslash'] = 0x0110;
  4736. t['Dsmall'] = 0xF764;
  4737. t['Dtopbar'] = 0x018B;
  4738. t['Dz'] = 0x01F2;
  4739. t['Dzcaron'] = 0x01C5;
  4740. t['Dzeabkhasiancyrillic'] = 0x04E0;
  4741. t['Dzecyrillic'] = 0x0405;
  4742. t['Dzhecyrillic'] = 0x040F;
  4743. t['E'] = 0x0045;
  4744. t['Eacute'] = 0x00C9;
  4745. t['Eacutesmall'] = 0xF7E9;
  4746. t['Ebreve'] = 0x0114;
  4747. t['Ecaron'] = 0x011A;
  4748. t['Ecedillabreve'] = 0x1E1C;
  4749. t['Echarmenian'] = 0x0535;
  4750. t['Ecircle'] = 0x24BA;
  4751. t['Ecircumflex'] = 0x00CA;
  4752. t['Ecircumflexacute'] = 0x1EBE;
  4753. t['Ecircumflexbelow'] = 0x1E18;
  4754. t['Ecircumflexdotbelow'] = 0x1EC6;
  4755. t['Ecircumflexgrave'] = 0x1EC0;
  4756. t['Ecircumflexhookabove'] = 0x1EC2;
  4757. t['Ecircumflexsmall'] = 0xF7EA;
  4758. t['Ecircumflextilde'] = 0x1EC4;
  4759. t['Ecyrillic'] = 0x0404;
  4760. t['Edblgrave'] = 0x0204;
  4761. t['Edieresis'] = 0x00CB;
  4762. t['Edieresissmall'] = 0xF7EB;
  4763. t['Edot'] = 0x0116;
  4764. t['Edotaccent'] = 0x0116;
  4765. t['Edotbelow'] = 0x1EB8;
  4766. t['Efcyrillic'] = 0x0424;
  4767. t['Egrave'] = 0x00C8;
  4768. t['Egravesmall'] = 0xF7E8;
  4769. t['Eharmenian'] = 0x0537;
  4770. t['Ehookabove'] = 0x1EBA;
  4771. t['Eightroman'] = 0x2167;
  4772. t['Einvertedbreve'] = 0x0206;
  4773. t['Eiotifiedcyrillic'] = 0x0464;
  4774. t['Elcyrillic'] = 0x041B;
  4775. t['Elevenroman'] = 0x216A;
  4776. t['Emacron'] = 0x0112;
  4777. t['Emacronacute'] = 0x1E16;
  4778. t['Emacrongrave'] = 0x1E14;
  4779. t['Emcyrillic'] = 0x041C;
  4780. t['Emonospace'] = 0xFF25;
  4781. t['Encyrillic'] = 0x041D;
  4782. t['Endescendercyrillic'] = 0x04A2;
  4783. t['Eng'] = 0x014A;
  4784. t['Enghecyrillic'] = 0x04A4;
  4785. t['Enhookcyrillic'] = 0x04C7;
  4786. t['Eogonek'] = 0x0118;
  4787. t['Eopen'] = 0x0190;
  4788. t['Epsilon'] = 0x0395;
  4789. t['Epsilontonos'] = 0x0388;
  4790. t['Ercyrillic'] = 0x0420;
  4791. t['Ereversed'] = 0x018E;
  4792. t['Ereversedcyrillic'] = 0x042D;
  4793. t['Escyrillic'] = 0x0421;
  4794. t['Esdescendercyrillic'] = 0x04AA;
  4795. t['Esh'] = 0x01A9;
  4796. t['Esmall'] = 0xF765;
  4797. t['Eta'] = 0x0397;
  4798. t['Etarmenian'] = 0x0538;
  4799. t['Etatonos'] = 0x0389;
  4800. t['Eth'] = 0x00D0;
  4801. t['Ethsmall'] = 0xF7F0;
  4802. t['Etilde'] = 0x1EBC;
  4803. t['Etildebelow'] = 0x1E1A;
  4804. t['Euro'] = 0x20AC;
  4805. t['Ezh'] = 0x01B7;
  4806. t['Ezhcaron'] = 0x01EE;
  4807. t['Ezhreversed'] = 0x01B8;
  4808. t['F'] = 0x0046;
  4809. t['Fcircle'] = 0x24BB;
  4810. t['Fdotaccent'] = 0x1E1E;
  4811. t['Feharmenian'] = 0x0556;
  4812. t['Feicoptic'] = 0x03E4;
  4813. t['Fhook'] = 0x0191;
  4814. t['Fitacyrillic'] = 0x0472;
  4815. t['Fiveroman'] = 0x2164;
  4816. t['Fmonospace'] = 0xFF26;
  4817. t['Fourroman'] = 0x2163;
  4818. t['Fsmall'] = 0xF766;
  4819. t['G'] = 0x0047;
  4820. t['GBsquare'] = 0x3387;
  4821. t['Gacute'] = 0x01F4;
  4822. t['Gamma'] = 0x0393;
  4823. t['Gammaafrican'] = 0x0194;
  4824. t['Gangiacoptic'] = 0x03EA;
  4825. t['Gbreve'] = 0x011E;
  4826. t['Gcaron'] = 0x01E6;
  4827. t['Gcedilla'] = 0x0122;
  4828. t['Gcircle'] = 0x24BC;
  4829. t['Gcircumflex'] = 0x011C;
  4830. t['Gcommaaccent'] = 0x0122;
  4831. t['Gdot'] = 0x0120;
  4832. t['Gdotaccent'] = 0x0120;
  4833. t['Gecyrillic'] = 0x0413;
  4834. t['Ghadarmenian'] = 0x0542;
  4835. t['Ghemiddlehookcyrillic'] = 0x0494;
  4836. t['Ghestrokecyrillic'] = 0x0492;
  4837. t['Gheupturncyrillic'] = 0x0490;
  4838. t['Ghook'] = 0x0193;
  4839. t['Gimarmenian'] = 0x0533;
  4840. t['Gjecyrillic'] = 0x0403;
  4841. t['Gmacron'] = 0x1E20;
  4842. t['Gmonospace'] = 0xFF27;
  4843. t['Grave'] = 0xF6CE;
  4844. t['Gravesmall'] = 0xF760;
  4845. t['Gsmall'] = 0xF767;
  4846. t['Gsmallhook'] = 0x029B;
  4847. t['Gstroke'] = 0x01E4;
  4848. t['H'] = 0x0048;
  4849. t['H18533'] = 0x25CF;
  4850. t['H18543'] = 0x25AA;
  4851. t['H18551'] = 0x25AB;
  4852. t['H22073'] = 0x25A1;
  4853. t['HPsquare'] = 0x33CB;
  4854. t['Haabkhasiancyrillic'] = 0x04A8;
  4855. t['Hadescendercyrillic'] = 0x04B2;
  4856. t['Hardsigncyrillic'] = 0x042A;
  4857. t['Hbar'] = 0x0126;
  4858. t['Hbrevebelow'] = 0x1E2A;
  4859. t['Hcedilla'] = 0x1E28;
  4860. t['Hcircle'] = 0x24BD;
  4861. t['Hcircumflex'] = 0x0124;
  4862. t['Hdieresis'] = 0x1E26;
  4863. t['Hdotaccent'] = 0x1E22;
  4864. t['Hdotbelow'] = 0x1E24;
  4865. t['Hmonospace'] = 0xFF28;
  4866. t['Hoarmenian'] = 0x0540;
  4867. t['Horicoptic'] = 0x03E8;
  4868. t['Hsmall'] = 0xF768;
  4869. t['Hungarumlaut'] = 0xF6CF;
  4870. t['Hungarumlautsmall'] = 0xF6F8;
  4871. t['Hzsquare'] = 0x3390;
  4872. t['I'] = 0x0049;
  4873. t['IAcyrillic'] = 0x042F;
  4874. t['IJ'] = 0x0132;
  4875. t['IUcyrillic'] = 0x042E;
  4876. t['Iacute'] = 0x00CD;
  4877. t['Iacutesmall'] = 0xF7ED;
  4878. t['Ibreve'] = 0x012C;
  4879. t['Icaron'] = 0x01CF;
  4880. t['Icircle'] = 0x24BE;
  4881. t['Icircumflex'] = 0x00CE;
  4882. t['Icircumflexsmall'] = 0xF7EE;
  4883. t['Icyrillic'] = 0x0406;
  4884. t['Idblgrave'] = 0x0208;
  4885. t['Idieresis'] = 0x00CF;
  4886. t['Idieresisacute'] = 0x1E2E;
  4887. t['Idieresiscyrillic'] = 0x04E4;
  4888. t['Idieresissmall'] = 0xF7EF;
  4889. t['Idot'] = 0x0130;
  4890. t['Idotaccent'] = 0x0130;
  4891. t['Idotbelow'] = 0x1ECA;
  4892. t['Iebrevecyrillic'] = 0x04D6;
  4893. t['Iecyrillic'] = 0x0415;
  4894. t['Ifraktur'] = 0x2111;
  4895. t['Igrave'] = 0x00CC;
  4896. t['Igravesmall'] = 0xF7EC;
  4897. t['Ihookabove'] = 0x1EC8;
  4898. t['Iicyrillic'] = 0x0418;
  4899. t['Iinvertedbreve'] = 0x020A;
  4900. t['Iishortcyrillic'] = 0x0419;
  4901. t['Imacron'] = 0x012A;
  4902. t['Imacroncyrillic'] = 0x04E2;
  4903. t['Imonospace'] = 0xFF29;
  4904. t['Iniarmenian'] = 0x053B;
  4905. t['Iocyrillic'] = 0x0401;
  4906. t['Iogonek'] = 0x012E;
  4907. t['Iota'] = 0x0399;
  4908. t['Iotaafrican'] = 0x0196;
  4909. t['Iotadieresis'] = 0x03AA;
  4910. t['Iotatonos'] = 0x038A;
  4911. t['Ismall'] = 0xF769;
  4912. t['Istroke'] = 0x0197;
  4913. t['Itilde'] = 0x0128;
  4914. t['Itildebelow'] = 0x1E2C;
  4915. t['Izhitsacyrillic'] = 0x0474;
  4916. t['Izhitsadblgravecyrillic'] = 0x0476;
  4917. t['J'] = 0x004A;
  4918. t['Jaarmenian'] = 0x0541;
  4919. t['Jcircle'] = 0x24BF;
  4920. t['Jcircumflex'] = 0x0134;
  4921. t['Jecyrillic'] = 0x0408;
  4922. t['Jheharmenian'] = 0x054B;
  4923. t['Jmonospace'] = 0xFF2A;
  4924. t['Jsmall'] = 0xF76A;
  4925. t['K'] = 0x004B;
  4926. t['KBsquare'] = 0x3385;
  4927. t['KKsquare'] = 0x33CD;
  4928. t['Kabashkircyrillic'] = 0x04A0;
  4929. t['Kacute'] = 0x1E30;
  4930. t['Kacyrillic'] = 0x041A;
  4931. t['Kadescendercyrillic'] = 0x049A;
  4932. t['Kahookcyrillic'] = 0x04C3;
  4933. t['Kappa'] = 0x039A;
  4934. t['Kastrokecyrillic'] = 0x049E;
  4935. t['Kaverticalstrokecyrillic'] = 0x049C;
  4936. t['Kcaron'] = 0x01E8;
  4937. t['Kcedilla'] = 0x0136;
  4938. t['Kcircle'] = 0x24C0;
  4939. t['Kcommaaccent'] = 0x0136;
  4940. t['Kdotbelow'] = 0x1E32;
  4941. t['Keharmenian'] = 0x0554;
  4942. t['Kenarmenian'] = 0x053F;
  4943. t['Khacyrillic'] = 0x0425;
  4944. t['Kheicoptic'] = 0x03E6;
  4945. t['Khook'] = 0x0198;
  4946. t['Kjecyrillic'] = 0x040C;
  4947. t['Klinebelow'] = 0x1E34;
  4948. t['Kmonospace'] = 0xFF2B;
  4949. t['Koppacyrillic'] = 0x0480;
  4950. t['Koppagreek'] = 0x03DE;
  4951. t['Ksicyrillic'] = 0x046E;
  4952. t['Ksmall'] = 0xF76B;
  4953. t['L'] = 0x004C;
  4954. t['LJ'] = 0x01C7;
  4955. t['LL'] = 0xF6BF;
  4956. t['Lacute'] = 0x0139;
  4957. t['Lambda'] = 0x039B;
  4958. t['Lcaron'] = 0x013D;
  4959. t['Lcedilla'] = 0x013B;
  4960. t['Lcircle'] = 0x24C1;
  4961. t['Lcircumflexbelow'] = 0x1E3C;
  4962. t['Lcommaaccent'] = 0x013B;
  4963. t['Ldot'] = 0x013F;
  4964. t['Ldotaccent'] = 0x013F;
  4965. t['Ldotbelow'] = 0x1E36;
  4966. t['Ldotbelowmacron'] = 0x1E38;
  4967. t['Liwnarmenian'] = 0x053C;
  4968. t['Lj'] = 0x01C8;
  4969. t['Ljecyrillic'] = 0x0409;
  4970. t['Llinebelow'] = 0x1E3A;
  4971. t['Lmonospace'] = 0xFF2C;
  4972. t['Lslash'] = 0x0141;
  4973. t['Lslashsmall'] = 0xF6F9;
  4974. t['Lsmall'] = 0xF76C;
  4975. t['M'] = 0x004D;
  4976. t['MBsquare'] = 0x3386;
  4977. t['Macron'] = 0xF6D0;
  4978. t['Macronsmall'] = 0xF7AF;
  4979. t['Macute'] = 0x1E3E;
  4980. t['Mcircle'] = 0x24C2;
  4981. t['Mdotaccent'] = 0x1E40;
  4982. t['Mdotbelow'] = 0x1E42;
  4983. t['Menarmenian'] = 0x0544;
  4984. t['Mmonospace'] = 0xFF2D;
  4985. t['Msmall'] = 0xF76D;
  4986. t['Mturned'] = 0x019C;
  4987. t['Mu'] = 0x039C;
  4988. t['N'] = 0x004E;
  4989. t['NJ'] = 0x01CA;
  4990. t['Nacute'] = 0x0143;
  4991. t['Ncaron'] = 0x0147;
  4992. t['Ncedilla'] = 0x0145;
  4993. t['Ncircle'] = 0x24C3;
  4994. t['Ncircumflexbelow'] = 0x1E4A;
  4995. t['Ncommaaccent'] = 0x0145;
  4996. t['Ndotaccent'] = 0x1E44;
  4997. t['Ndotbelow'] = 0x1E46;
  4998. t['Nhookleft'] = 0x019D;
  4999. t['Nineroman'] = 0x2168;
  5000. t['Nj'] = 0x01CB;
  5001. t['Njecyrillic'] = 0x040A;
  5002. t['Nlinebelow'] = 0x1E48;
  5003. t['Nmonospace'] = 0xFF2E;
  5004. t['Nowarmenian'] = 0x0546;
  5005. t['Nsmall'] = 0xF76E;
  5006. t['Ntilde'] = 0x00D1;
  5007. t['Ntildesmall'] = 0xF7F1;
  5008. t['Nu'] = 0x039D;
  5009. t['O'] = 0x004F;
  5010. t['OE'] = 0x0152;
  5011. t['OEsmall'] = 0xF6FA;
  5012. t['Oacute'] = 0x00D3;
  5013. t['Oacutesmall'] = 0xF7F3;
  5014. t['Obarredcyrillic'] = 0x04E8;
  5015. t['Obarreddieresiscyrillic'] = 0x04EA;
  5016. t['Obreve'] = 0x014E;
  5017. t['Ocaron'] = 0x01D1;
  5018. t['Ocenteredtilde'] = 0x019F;
  5019. t['Ocircle'] = 0x24C4;
  5020. t['Ocircumflex'] = 0x00D4;
  5021. t['Ocircumflexacute'] = 0x1ED0;
  5022. t['Ocircumflexdotbelow'] = 0x1ED8;
  5023. t['Ocircumflexgrave'] = 0x1ED2;
  5024. t['Ocircumflexhookabove'] = 0x1ED4;
  5025. t['Ocircumflexsmall'] = 0xF7F4;
  5026. t['Ocircumflextilde'] = 0x1ED6;
  5027. t['Ocyrillic'] = 0x041E;
  5028. t['Odblacute'] = 0x0150;
  5029. t['Odblgrave'] = 0x020C;
  5030. t['Odieresis'] = 0x00D6;
  5031. t['Odieresiscyrillic'] = 0x04E6;
  5032. t['Odieresissmall'] = 0xF7F6;
  5033. t['Odotbelow'] = 0x1ECC;
  5034. t['Ogoneksmall'] = 0xF6FB;
  5035. t['Ograve'] = 0x00D2;
  5036. t['Ogravesmall'] = 0xF7F2;
  5037. t['Oharmenian'] = 0x0555;
  5038. t['Ohm'] = 0x2126;
  5039. t['Ohookabove'] = 0x1ECE;
  5040. t['Ohorn'] = 0x01A0;
  5041. t['Ohornacute'] = 0x1EDA;
  5042. t['Ohorndotbelow'] = 0x1EE2;
  5043. t['Ohorngrave'] = 0x1EDC;
  5044. t['Ohornhookabove'] = 0x1EDE;
  5045. t['Ohorntilde'] = 0x1EE0;
  5046. t['Ohungarumlaut'] = 0x0150;
  5047. t['Oi'] = 0x01A2;
  5048. t['Oinvertedbreve'] = 0x020E;
  5049. t['Omacron'] = 0x014C;
  5050. t['Omacronacute'] = 0x1E52;
  5051. t['Omacrongrave'] = 0x1E50;
  5052. t['Omega'] = 0x2126;
  5053. t['Omegacyrillic'] = 0x0460;
  5054. t['Omegagreek'] = 0x03A9;
  5055. t['Omegaroundcyrillic'] = 0x047A;
  5056. t['Omegatitlocyrillic'] = 0x047C;
  5057. t['Omegatonos'] = 0x038F;
  5058. t['Omicron'] = 0x039F;
  5059. t['Omicrontonos'] = 0x038C;
  5060. t['Omonospace'] = 0xFF2F;
  5061. t['Oneroman'] = 0x2160;
  5062. t['Oogonek'] = 0x01EA;
  5063. t['Oogonekmacron'] = 0x01EC;
  5064. t['Oopen'] = 0x0186;
  5065. t['Oslash'] = 0x00D8;
  5066. t['Oslashacute'] = 0x01FE;
  5067. t['Oslashsmall'] = 0xF7F8;
  5068. t['Osmall'] = 0xF76F;
  5069. t['Ostrokeacute'] = 0x01FE;
  5070. t['Otcyrillic'] = 0x047E;
  5071. t['Otilde'] = 0x00D5;
  5072. t['Otildeacute'] = 0x1E4C;
  5073. t['Otildedieresis'] = 0x1E4E;
  5074. t['Otildesmall'] = 0xF7F5;
  5075. t['P'] = 0x0050;
  5076. t['Pacute'] = 0x1E54;
  5077. t['Pcircle'] = 0x24C5;
  5078. t['Pdotaccent'] = 0x1E56;
  5079. t['Pecyrillic'] = 0x041F;
  5080. t['Peharmenian'] = 0x054A;
  5081. t['Pemiddlehookcyrillic'] = 0x04A6;
  5082. t['Phi'] = 0x03A6;
  5083. t['Phook'] = 0x01A4;
  5084. t['Pi'] = 0x03A0;
  5085. t['Piwrarmenian'] = 0x0553;
  5086. t['Pmonospace'] = 0xFF30;
  5087. t['Psi'] = 0x03A8;
  5088. t['Psicyrillic'] = 0x0470;
  5089. t['Psmall'] = 0xF770;
  5090. t['Q'] = 0x0051;
  5091. t['Qcircle'] = 0x24C6;
  5092. t['Qmonospace'] = 0xFF31;
  5093. t['Qsmall'] = 0xF771;
  5094. t['R'] = 0x0052;
  5095. t['Raarmenian'] = 0x054C;
  5096. t['Racute'] = 0x0154;
  5097. t['Rcaron'] = 0x0158;
  5098. t['Rcedilla'] = 0x0156;
  5099. t['Rcircle'] = 0x24C7;
  5100. t['Rcommaaccent'] = 0x0156;
  5101. t['Rdblgrave'] = 0x0210;
  5102. t['Rdotaccent'] = 0x1E58;
  5103. t['Rdotbelow'] = 0x1E5A;
  5104. t['Rdotbelowmacron'] = 0x1E5C;
  5105. t['Reharmenian'] = 0x0550;
  5106. t['Rfraktur'] = 0x211C;
  5107. t['Rho'] = 0x03A1;
  5108. t['Ringsmall'] = 0xF6FC;
  5109. t['Rinvertedbreve'] = 0x0212;
  5110. t['Rlinebelow'] = 0x1E5E;
  5111. t['Rmonospace'] = 0xFF32;
  5112. t['Rsmall'] = 0xF772;
  5113. t['Rsmallinverted'] = 0x0281;
  5114. t['Rsmallinvertedsuperior'] = 0x02B6;
  5115. t['S'] = 0x0053;
  5116. t['SF010000'] = 0x250C;
  5117. t['SF020000'] = 0x2514;
  5118. t['SF030000'] = 0x2510;
  5119. t['SF040000'] = 0x2518;
  5120. t['SF050000'] = 0x253C;
  5121. t['SF060000'] = 0x252C;
  5122. t['SF070000'] = 0x2534;
  5123. t['SF080000'] = 0x251C;
  5124. t['SF090000'] = 0x2524;
  5125. t['SF100000'] = 0x2500;
  5126. t['SF110000'] = 0x2502;
  5127. t['SF190000'] = 0x2561;
  5128. t['SF200000'] = 0x2562;
  5129. t['SF210000'] = 0x2556;
  5130. t['SF220000'] = 0x2555;
  5131. t['SF230000'] = 0x2563;
  5132. t['SF240000'] = 0x2551;
  5133. t['SF250000'] = 0x2557;
  5134. t['SF260000'] = 0x255D;
  5135. t['SF270000'] = 0x255C;
  5136. t['SF280000'] = 0x255B;
  5137. t['SF360000'] = 0x255E;
  5138. t['SF370000'] = 0x255F;
  5139. t['SF380000'] = 0x255A;
  5140. t['SF390000'] = 0x2554;
  5141. t['SF400000'] = 0x2569;
  5142. t['SF410000'] = 0x2566;
  5143. t['SF420000'] = 0x2560;
  5144. t['SF430000'] = 0x2550;
  5145. t['SF440000'] = 0x256C;
  5146. t['SF450000'] = 0x2567;
  5147. t['SF460000'] = 0x2568;
  5148. t['SF470000'] = 0x2564;
  5149. t['SF480000'] = 0x2565;
  5150. t['SF490000'] = 0x2559;
  5151. t['SF500000'] = 0x2558;
  5152. t['SF510000'] = 0x2552;
  5153. t['SF520000'] = 0x2553;
  5154. t['SF530000'] = 0x256B;
  5155. t['SF540000'] = 0x256A;
  5156. t['Sacute'] = 0x015A;
  5157. t['Sacutedotaccent'] = 0x1E64;
  5158. t['Sampigreek'] = 0x03E0;
  5159. t['Scaron'] = 0x0160;
  5160. t['Scarondotaccent'] = 0x1E66;
  5161. t['Scaronsmall'] = 0xF6FD;
  5162. t['Scedilla'] = 0x015E;
  5163. t['Schwa'] = 0x018F;
  5164. t['Schwacyrillic'] = 0x04D8;
  5165. t['Schwadieresiscyrillic'] = 0x04DA;
  5166. t['Scircle'] = 0x24C8;
  5167. t['Scircumflex'] = 0x015C;
  5168. t['Scommaaccent'] = 0x0218;
  5169. t['Sdotaccent'] = 0x1E60;
  5170. t['Sdotbelow'] = 0x1E62;
  5171. t['Sdotbelowdotaccent'] = 0x1E68;
  5172. t['Seharmenian'] = 0x054D;
  5173. t['Sevenroman'] = 0x2166;
  5174. t['Shaarmenian'] = 0x0547;
  5175. t['Shacyrillic'] = 0x0428;
  5176. t['Shchacyrillic'] = 0x0429;
  5177. t['Sheicoptic'] = 0x03E2;
  5178. t['Shhacyrillic'] = 0x04BA;
  5179. t['Shimacoptic'] = 0x03EC;
  5180. t['Sigma'] = 0x03A3;
  5181. t['Sixroman'] = 0x2165;
  5182. t['Smonospace'] = 0xFF33;
  5183. t['Softsigncyrillic'] = 0x042C;
  5184. t['Ssmall'] = 0xF773;
  5185. t['Stigmagreek'] = 0x03DA;
  5186. t['T'] = 0x0054;
  5187. t['Tau'] = 0x03A4;
  5188. t['Tbar'] = 0x0166;
  5189. t['Tcaron'] = 0x0164;
  5190. t['Tcedilla'] = 0x0162;
  5191. t['Tcircle'] = 0x24C9;
  5192. t['Tcircumflexbelow'] = 0x1E70;
  5193. t['Tcommaaccent'] = 0x0162;
  5194. t['Tdotaccent'] = 0x1E6A;
  5195. t['Tdotbelow'] = 0x1E6C;
  5196. t['Tecyrillic'] = 0x0422;
  5197. t['Tedescendercyrillic'] = 0x04AC;
  5198. t['Tenroman'] = 0x2169;
  5199. t['Tetsecyrillic'] = 0x04B4;
  5200. t['Theta'] = 0x0398;
  5201. t['Thook'] = 0x01AC;
  5202. t['Thorn'] = 0x00DE;
  5203. t['Thornsmall'] = 0xF7FE;
  5204. t['Threeroman'] = 0x2162;
  5205. t['Tildesmall'] = 0xF6FE;
  5206. t['Tiwnarmenian'] = 0x054F;
  5207. t['Tlinebelow'] = 0x1E6E;
  5208. t['Tmonospace'] = 0xFF34;
  5209. t['Toarmenian'] = 0x0539;
  5210. t['Tonefive'] = 0x01BC;
  5211. t['Tonesix'] = 0x0184;
  5212. t['Tonetwo'] = 0x01A7;
  5213. t['Tretroflexhook'] = 0x01AE;
  5214. t['Tsecyrillic'] = 0x0426;
  5215. t['Tshecyrillic'] = 0x040B;
  5216. t['Tsmall'] = 0xF774;
  5217. t['Twelveroman'] = 0x216B;
  5218. t['Tworoman'] = 0x2161;
  5219. t['U'] = 0x0055;
  5220. t['Uacute'] = 0x00DA;
  5221. t['Uacutesmall'] = 0xF7FA;
  5222. t['Ubreve'] = 0x016C;
  5223. t['Ucaron'] = 0x01D3;
  5224. t['Ucircle'] = 0x24CA;
  5225. t['Ucircumflex'] = 0x00DB;
  5226. t['Ucircumflexbelow'] = 0x1E76;
  5227. t['Ucircumflexsmall'] = 0xF7FB;
  5228. t['Ucyrillic'] = 0x0423;
  5229. t['Udblacute'] = 0x0170;
  5230. t['Udblgrave'] = 0x0214;
  5231. t['Udieresis'] = 0x00DC;
  5232. t['Udieresisacute'] = 0x01D7;
  5233. t['Udieresisbelow'] = 0x1E72;
  5234. t['Udieresiscaron'] = 0x01D9;
  5235. t['Udieresiscyrillic'] = 0x04F0;
  5236. t['Udieresisgrave'] = 0x01DB;
  5237. t['Udieresismacron'] = 0x01D5;
  5238. t['Udieresissmall'] = 0xF7FC;
  5239. t['Udotbelow'] = 0x1EE4;
  5240. t['Ugrave'] = 0x00D9;
  5241. t['Ugravesmall'] = 0xF7F9;
  5242. t['Uhookabove'] = 0x1EE6;
  5243. t['Uhorn'] = 0x01AF;
  5244. t['Uhornacute'] = 0x1EE8;
  5245. t['Uhorndotbelow'] = 0x1EF0;
  5246. t['Uhorngrave'] = 0x1EEA;
  5247. t['Uhornhookabove'] = 0x1EEC;
  5248. t['Uhorntilde'] = 0x1EEE;
  5249. t['Uhungarumlaut'] = 0x0170;
  5250. t['Uhungarumlautcyrillic'] = 0x04F2;
  5251. t['Uinvertedbreve'] = 0x0216;
  5252. t['Ukcyrillic'] = 0x0478;
  5253. t['Umacron'] = 0x016A;
  5254. t['Umacroncyrillic'] = 0x04EE;
  5255. t['Umacrondieresis'] = 0x1E7A;
  5256. t['Umonospace'] = 0xFF35;
  5257. t['Uogonek'] = 0x0172;
  5258. t['Upsilon'] = 0x03A5;
  5259. t['Upsilon1'] = 0x03D2;
  5260. t['Upsilonacutehooksymbolgreek'] = 0x03D3;
  5261. t['Upsilonafrican'] = 0x01B1;
  5262. t['Upsilondieresis'] = 0x03AB;
  5263. t['Upsilondieresishooksymbolgreek'] = 0x03D4;
  5264. t['Upsilonhooksymbol'] = 0x03D2;
  5265. t['Upsilontonos'] = 0x038E;
  5266. t['Uring'] = 0x016E;
  5267. t['Ushortcyrillic'] = 0x040E;
  5268. t['Usmall'] = 0xF775;
  5269. t['Ustraightcyrillic'] = 0x04AE;
  5270. t['Ustraightstrokecyrillic'] = 0x04B0;
  5271. t['Utilde'] = 0x0168;
  5272. t['Utildeacute'] = 0x1E78;
  5273. t['Utildebelow'] = 0x1E74;
  5274. t['V'] = 0x0056;
  5275. t['Vcircle'] = 0x24CB;
  5276. t['Vdotbelow'] = 0x1E7E;
  5277. t['Vecyrillic'] = 0x0412;
  5278. t['Vewarmenian'] = 0x054E;
  5279. t['Vhook'] = 0x01B2;
  5280. t['Vmonospace'] = 0xFF36;
  5281. t['Voarmenian'] = 0x0548;
  5282. t['Vsmall'] = 0xF776;
  5283. t['Vtilde'] = 0x1E7C;
  5284. t['W'] = 0x0057;
  5285. t['Wacute'] = 0x1E82;
  5286. t['Wcircle'] = 0x24CC;
  5287. t['Wcircumflex'] = 0x0174;
  5288. t['Wdieresis'] = 0x1E84;
  5289. t['Wdotaccent'] = 0x1E86;
  5290. t['Wdotbelow'] = 0x1E88;
  5291. t['Wgrave'] = 0x1E80;
  5292. t['Wmonospace'] = 0xFF37;
  5293. t['Wsmall'] = 0xF777;
  5294. t['X'] = 0x0058;
  5295. t['Xcircle'] = 0x24CD;
  5296. t['Xdieresis'] = 0x1E8C;
  5297. t['Xdotaccent'] = 0x1E8A;
  5298. t['Xeharmenian'] = 0x053D;
  5299. t['Xi'] = 0x039E;
  5300. t['Xmonospace'] = 0xFF38;
  5301. t['Xsmall'] = 0xF778;
  5302. t['Y'] = 0x0059;
  5303. t['Yacute'] = 0x00DD;
  5304. t['Yacutesmall'] = 0xF7FD;
  5305. t['Yatcyrillic'] = 0x0462;
  5306. t['Ycircle'] = 0x24CE;
  5307. t['Ycircumflex'] = 0x0176;
  5308. t['Ydieresis'] = 0x0178;
  5309. t['Ydieresissmall'] = 0xF7FF;
  5310. t['Ydotaccent'] = 0x1E8E;
  5311. t['Ydotbelow'] = 0x1EF4;
  5312. t['Yericyrillic'] = 0x042B;
  5313. t['Yerudieresiscyrillic'] = 0x04F8;
  5314. t['Ygrave'] = 0x1EF2;
  5315. t['Yhook'] = 0x01B3;
  5316. t['Yhookabove'] = 0x1EF6;
  5317. t['Yiarmenian'] = 0x0545;
  5318. t['Yicyrillic'] = 0x0407;
  5319. t['Yiwnarmenian'] = 0x0552;
  5320. t['Ymonospace'] = 0xFF39;
  5321. t['Ysmall'] = 0xF779;
  5322. t['Ytilde'] = 0x1EF8;
  5323. t['Yusbigcyrillic'] = 0x046A;
  5324. t['Yusbigiotifiedcyrillic'] = 0x046C;
  5325. t['Yuslittlecyrillic'] = 0x0466;
  5326. t['Yuslittleiotifiedcyrillic'] = 0x0468;
  5327. t['Z'] = 0x005A;
  5328. t['Zaarmenian'] = 0x0536;
  5329. t['Zacute'] = 0x0179;
  5330. t['Zcaron'] = 0x017D;
  5331. t['Zcaronsmall'] = 0xF6FF;
  5332. t['Zcircle'] = 0x24CF;
  5333. t['Zcircumflex'] = 0x1E90;
  5334. t['Zdot'] = 0x017B;
  5335. t['Zdotaccent'] = 0x017B;
  5336. t['Zdotbelow'] = 0x1E92;
  5337. t['Zecyrillic'] = 0x0417;
  5338. t['Zedescendercyrillic'] = 0x0498;
  5339. t['Zedieresiscyrillic'] = 0x04DE;
  5340. t['Zeta'] = 0x0396;
  5341. t['Zhearmenian'] = 0x053A;
  5342. t['Zhebrevecyrillic'] = 0x04C1;
  5343. t['Zhecyrillic'] = 0x0416;
  5344. t['Zhedescendercyrillic'] = 0x0496;
  5345. t['Zhedieresiscyrillic'] = 0x04DC;
  5346. t['Zlinebelow'] = 0x1E94;
  5347. t['Zmonospace'] = 0xFF3A;
  5348. t['Zsmall'] = 0xF77A;
  5349. t['Zstroke'] = 0x01B5;
  5350. t['a'] = 0x0061;
  5351. t['aabengali'] = 0x0986;
  5352. t['aacute'] = 0x00E1;
  5353. t['aadeva'] = 0x0906;
  5354. t['aagujarati'] = 0x0A86;
  5355. t['aagurmukhi'] = 0x0A06;
  5356. t['aamatragurmukhi'] = 0x0A3E;
  5357. t['aarusquare'] = 0x3303;
  5358. t['aavowelsignbengali'] = 0x09BE;
  5359. t['aavowelsigndeva'] = 0x093E;
  5360. t['aavowelsigngujarati'] = 0x0ABE;
  5361. t['abbreviationmarkarmenian'] = 0x055F;
  5362. t['abbreviationsigndeva'] = 0x0970;
  5363. t['abengali'] = 0x0985;
  5364. t['abopomofo'] = 0x311A;
  5365. t['abreve'] = 0x0103;
  5366. t['abreveacute'] = 0x1EAF;
  5367. t['abrevecyrillic'] = 0x04D1;
  5368. t['abrevedotbelow'] = 0x1EB7;
  5369. t['abrevegrave'] = 0x1EB1;
  5370. t['abrevehookabove'] = 0x1EB3;
  5371. t['abrevetilde'] = 0x1EB5;
  5372. t['acaron'] = 0x01CE;
  5373. t['acircle'] = 0x24D0;
  5374. t['acircumflex'] = 0x00E2;
  5375. t['acircumflexacute'] = 0x1EA5;
  5376. t['acircumflexdotbelow'] = 0x1EAD;
  5377. t['acircumflexgrave'] = 0x1EA7;
  5378. t['acircumflexhookabove'] = 0x1EA9;
  5379. t['acircumflextilde'] = 0x1EAB;
  5380. t['acute'] = 0x00B4;
  5381. t['acutebelowcmb'] = 0x0317;
  5382. t['acutecmb'] = 0x0301;
  5383. t['acutecomb'] = 0x0301;
  5384. t['acutedeva'] = 0x0954;
  5385. t['acutelowmod'] = 0x02CF;
  5386. t['acutetonecmb'] = 0x0341;
  5387. t['acyrillic'] = 0x0430;
  5388. t['adblgrave'] = 0x0201;
  5389. t['addakgurmukhi'] = 0x0A71;
  5390. t['adeva'] = 0x0905;
  5391. t['adieresis'] = 0x00E4;
  5392. t['adieresiscyrillic'] = 0x04D3;
  5393. t['adieresismacron'] = 0x01DF;
  5394. t['adotbelow'] = 0x1EA1;
  5395. t['adotmacron'] = 0x01E1;
  5396. t['ae'] = 0x00E6;
  5397. t['aeacute'] = 0x01FD;
  5398. t['aekorean'] = 0x3150;
  5399. t['aemacron'] = 0x01E3;
  5400. t['afii00208'] = 0x2015;
  5401. t['afii08941'] = 0x20A4;
  5402. t['afii10017'] = 0x0410;
  5403. t['afii10018'] = 0x0411;
  5404. t['afii10019'] = 0x0412;
  5405. t['afii10020'] = 0x0413;
  5406. t['afii10021'] = 0x0414;
  5407. t['afii10022'] = 0x0415;
  5408. t['afii10023'] = 0x0401;
  5409. t['afii10024'] = 0x0416;
  5410. t['afii10025'] = 0x0417;
  5411. t['afii10026'] = 0x0418;
  5412. t['afii10027'] = 0x0419;
  5413. t['afii10028'] = 0x041A;
  5414. t['afii10029'] = 0x041B;
  5415. t['afii10030'] = 0x041C;
  5416. t['afii10031'] = 0x041D;
  5417. t['afii10032'] = 0x041E;
  5418. t['afii10033'] = 0x041F;
  5419. t['afii10034'] = 0x0420;
  5420. t['afii10035'] = 0x0421;
  5421. t['afii10036'] = 0x0422;
  5422. t['afii10037'] = 0x0423;
  5423. t['afii10038'] = 0x0424;
  5424. t['afii10039'] = 0x0425;
  5425. t['afii10040'] = 0x0426;
  5426. t['afii10041'] = 0x0427;
  5427. t['afii10042'] = 0x0428;
  5428. t['afii10043'] = 0x0429;
  5429. t['afii10044'] = 0x042A;
  5430. t['afii10045'] = 0x042B;
  5431. t['afii10046'] = 0x042C;
  5432. t['afii10047'] = 0x042D;
  5433. t['afii10048'] = 0x042E;
  5434. t['afii10049'] = 0x042F;
  5435. t['afii10050'] = 0x0490;
  5436. t['afii10051'] = 0x0402;
  5437. t['afii10052'] = 0x0403;
  5438. t['afii10053'] = 0x0404;
  5439. t['afii10054'] = 0x0405;
  5440. t['afii10055'] = 0x0406;
  5441. t['afii10056'] = 0x0407;
  5442. t['afii10057'] = 0x0408;
  5443. t['afii10058'] = 0x0409;
  5444. t['afii10059'] = 0x040A;
  5445. t['afii10060'] = 0x040B;
  5446. t['afii10061'] = 0x040C;
  5447. t['afii10062'] = 0x040E;
  5448. t['afii10063'] = 0xF6C4;
  5449. t['afii10064'] = 0xF6C5;
  5450. t['afii10065'] = 0x0430;
  5451. t['afii10066'] = 0x0431;
  5452. t['afii10067'] = 0x0432;
  5453. t['afii10068'] = 0x0433;
  5454. t['afii10069'] = 0x0434;
  5455. t['afii10070'] = 0x0435;
  5456. t['afii10071'] = 0x0451;
  5457. t['afii10072'] = 0x0436;
  5458. t['afii10073'] = 0x0437;
  5459. t['afii10074'] = 0x0438;
  5460. t['afii10075'] = 0x0439;
  5461. t['afii10076'] = 0x043A;
  5462. t['afii10077'] = 0x043B;
  5463. t['afii10078'] = 0x043C;
  5464. t['afii10079'] = 0x043D;
  5465. t['afii10080'] = 0x043E;
  5466. t['afii10081'] = 0x043F;
  5467. t['afii10082'] = 0x0440;
  5468. t['afii10083'] = 0x0441;
  5469. t['afii10084'] = 0x0442;
  5470. t['afii10085'] = 0x0443;
  5471. t['afii10086'] = 0x0444;
  5472. t['afii10087'] = 0x0445;
  5473. t['afii10088'] = 0x0446;
  5474. t['afii10089'] = 0x0447;
  5475. t['afii10090'] = 0x0448;
  5476. t['afii10091'] = 0x0449;
  5477. t['afii10092'] = 0x044A;
  5478. t['afii10093'] = 0x044B;
  5479. t['afii10094'] = 0x044C;
  5480. t['afii10095'] = 0x044D;
  5481. t['afii10096'] = 0x044E;
  5482. t['afii10097'] = 0x044F;
  5483. t['afii10098'] = 0x0491;
  5484. t['afii10099'] = 0x0452;
  5485. t['afii10100'] = 0x0453;
  5486. t['afii10101'] = 0x0454;
  5487. t['afii10102'] = 0x0455;
  5488. t['afii10103'] = 0x0456;
  5489. t['afii10104'] = 0x0457;
  5490. t['afii10105'] = 0x0458;
  5491. t['afii10106'] = 0x0459;
  5492. t['afii10107'] = 0x045A;
  5493. t['afii10108'] = 0x045B;
  5494. t['afii10109'] = 0x045C;
  5495. t['afii10110'] = 0x045E;
  5496. t['afii10145'] = 0x040F;
  5497. t['afii10146'] = 0x0462;
  5498. t['afii10147'] = 0x0472;
  5499. t['afii10148'] = 0x0474;
  5500. t['afii10192'] = 0xF6C6;
  5501. t['afii10193'] = 0x045F;
  5502. t['afii10194'] = 0x0463;
  5503. t['afii10195'] = 0x0473;
  5504. t['afii10196'] = 0x0475;
  5505. t['afii10831'] = 0xF6C7;
  5506. t['afii10832'] = 0xF6C8;
  5507. t['afii10846'] = 0x04D9;
  5508. t['afii299'] = 0x200E;
  5509. t['afii300'] = 0x200F;
  5510. t['afii301'] = 0x200D;
  5511. t['afii57381'] = 0x066A;
  5512. t['afii57388'] = 0x060C;
  5513. t['afii57392'] = 0x0660;
  5514. t['afii57393'] = 0x0661;
  5515. t['afii57394'] = 0x0662;
  5516. t['afii57395'] = 0x0663;
  5517. t['afii57396'] = 0x0664;
  5518. t['afii57397'] = 0x0665;
  5519. t['afii57398'] = 0x0666;
  5520. t['afii57399'] = 0x0667;
  5521. t['afii57400'] = 0x0668;
  5522. t['afii57401'] = 0x0669;
  5523. t['afii57403'] = 0x061B;
  5524. t['afii57407'] = 0x061F;
  5525. t['afii57409'] = 0x0621;
  5526. t['afii57410'] = 0x0622;
  5527. t['afii57411'] = 0x0623;
  5528. t['afii57412'] = 0x0624;
  5529. t['afii57413'] = 0x0625;
  5530. t['afii57414'] = 0x0626;
  5531. t['afii57415'] = 0x0627;
  5532. t['afii57416'] = 0x0628;
  5533. t['afii57417'] = 0x0629;
  5534. t['afii57418'] = 0x062A;
  5535. t['afii57419'] = 0x062B;
  5536. t['afii57420'] = 0x062C;
  5537. t['afii57421'] = 0x062D;
  5538. t['afii57422'] = 0x062E;
  5539. t['afii57423'] = 0x062F;
  5540. t['afii57424'] = 0x0630;
  5541. t['afii57425'] = 0x0631;
  5542. t['afii57426'] = 0x0632;
  5543. t['afii57427'] = 0x0633;
  5544. t['afii57428'] = 0x0634;
  5545. t['afii57429'] = 0x0635;
  5546. t['afii57430'] = 0x0636;
  5547. t['afii57431'] = 0x0637;
  5548. t['afii57432'] = 0x0638;
  5549. t['afii57433'] = 0x0639;
  5550. t['afii57434'] = 0x063A;
  5551. t['afii57440'] = 0x0640;
  5552. t['afii57441'] = 0x0641;
  5553. t['afii57442'] = 0x0642;
  5554. t['afii57443'] = 0x0643;
  5555. t['afii57444'] = 0x0644;
  5556. t['afii57445'] = 0x0645;
  5557. t['afii57446'] = 0x0646;
  5558. t['afii57448'] = 0x0648;
  5559. t['afii57449'] = 0x0649;
  5560. t['afii57450'] = 0x064A;
  5561. t['afii57451'] = 0x064B;
  5562. t['afii57452'] = 0x064C;
  5563. t['afii57453'] = 0x064D;
  5564. t['afii57454'] = 0x064E;
  5565. t['afii57455'] = 0x064F;
  5566. t['afii57456'] = 0x0650;
  5567. t['afii57457'] = 0x0651;
  5568. t['afii57458'] = 0x0652;
  5569. t['afii57470'] = 0x0647;
  5570. t['afii57505'] = 0x06A4;
  5571. t['afii57506'] = 0x067E;
  5572. t['afii57507'] = 0x0686;
  5573. t['afii57508'] = 0x0698;
  5574. t['afii57509'] = 0x06AF;
  5575. t['afii57511'] = 0x0679;
  5576. t['afii57512'] = 0x0688;
  5577. t['afii57513'] = 0x0691;
  5578. t['afii57514'] = 0x06BA;
  5579. t['afii57519'] = 0x06D2;
  5580. t['afii57534'] = 0x06D5;
  5581. t['afii57636'] = 0x20AA;
  5582. t['afii57645'] = 0x05BE;
  5583. t['afii57658'] = 0x05C3;
  5584. t['afii57664'] = 0x05D0;
  5585. t['afii57665'] = 0x05D1;
  5586. t['afii57666'] = 0x05D2;
  5587. t['afii57667'] = 0x05D3;
  5588. t['afii57668'] = 0x05D4;
  5589. t['afii57669'] = 0x05D5;
  5590. t['afii57670'] = 0x05D6;
  5591. t['afii57671'] = 0x05D7;
  5592. t['afii57672'] = 0x05D8;
  5593. t['afii57673'] = 0x05D9;
  5594. t['afii57674'] = 0x05DA;
  5595. t['afii57675'] = 0x05DB;
  5596. t['afii57676'] = 0x05DC;
  5597. t['afii57677'] = 0x05DD;
  5598. t['afii57678'] = 0x05DE;
  5599. t['afii57679'] = 0x05DF;
  5600. t['afii57680'] = 0x05E0;
  5601. t['afii57681'] = 0x05E1;
  5602. t['afii57682'] = 0x05E2;
  5603. t['afii57683'] = 0x05E3;
  5604. t['afii57684'] = 0x05E4;
  5605. t['afii57685'] = 0x05E5;
  5606. t['afii57686'] = 0x05E6;
  5607. t['afii57687'] = 0x05E7;
  5608. t['afii57688'] = 0x05E8;
  5609. t['afii57689'] = 0x05E9;
  5610. t['afii57690'] = 0x05EA;
  5611. t['afii57694'] = 0xFB2A;
  5612. t['afii57695'] = 0xFB2B;
  5613. t['afii57700'] = 0xFB4B;
  5614. t['afii57705'] = 0xFB1F;
  5615. t['afii57716'] = 0x05F0;
  5616. t['afii57717'] = 0x05F1;
  5617. t['afii57718'] = 0x05F2;
  5618. t['afii57723'] = 0xFB35;
  5619. t['afii57793'] = 0x05B4;
  5620. t['afii57794'] = 0x05B5;
  5621. t['afii57795'] = 0x05B6;
  5622. t['afii57796'] = 0x05BB;
  5623. t['afii57797'] = 0x05B8;
  5624. t['afii57798'] = 0x05B7;
  5625. t['afii57799'] = 0x05B0;
  5626. t['afii57800'] = 0x05B2;
  5627. t['afii57801'] = 0x05B1;
  5628. t['afii57802'] = 0x05B3;
  5629. t['afii57803'] = 0x05C2;
  5630. t['afii57804'] = 0x05C1;
  5631. t['afii57806'] = 0x05B9;
  5632. t['afii57807'] = 0x05BC;
  5633. t['afii57839'] = 0x05BD;
  5634. t['afii57841'] = 0x05BF;
  5635. t['afii57842'] = 0x05C0;
  5636. t['afii57929'] = 0x02BC;
  5637. t['afii61248'] = 0x2105;
  5638. t['afii61289'] = 0x2113;
  5639. t['afii61352'] = 0x2116;
  5640. t['afii61573'] = 0x202C;
  5641. t['afii61574'] = 0x202D;
  5642. t['afii61575'] = 0x202E;
  5643. t['afii61664'] = 0x200C;
  5644. t['afii63167'] = 0x066D;
  5645. t['afii64937'] = 0x02BD;
  5646. t['agrave'] = 0x00E0;
  5647. t['agujarati'] = 0x0A85;
  5648. t['agurmukhi'] = 0x0A05;
  5649. t['ahiragana'] = 0x3042;
  5650. t['ahookabove'] = 0x1EA3;
  5651. t['aibengali'] = 0x0990;
  5652. t['aibopomofo'] = 0x311E;
  5653. t['aideva'] = 0x0910;
  5654. t['aiecyrillic'] = 0x04D5;
  5655. t['aigujarati'] = 0x0A90;
  5656. t['aigurmukhi'] = 0x0A10;
  5657. t['aimatragurmukhi'] = 0x0A48;
  5658. t['ainarabic'] = 0x0639;
  5659. t['ainfinalarabic'] = 0xFECA;
  5660. t['aininitialarabic'] = 0xFECB;
  5661. t['ainmedialarabic'] = 0xFECC;
  5662. t['ainvertedbreve'] = 0x0203;
  5663. t['aivowelsignbengali'] = 0x09C8;
  5664. t['aivowelsigndeva'] = 0x0948;
  5665. t['aivowelsigngujarati'] = 0x0AC8;
  5666. t['akatakana'] = 0x30A2;
  5667. t['akatakanahalfwidth'] = 0xFF71;
  5668. t['akorean'] = 0x314F;
  5669. t['alef'] = 0x05D0;
  5670. t['alefarabic'] = 0x0627;
  5671. t['alefdageshhebrew'] = 0xFB30;
  5672. t['aleffinalarabic'] = 0xFE8E;
  5673. t['alefhamzaabovearabic'] = 0x0623;
  5674. t['alefhamzaabovefinalarabic'] = 0xFE84;
  5675. t['alefhamzabelowarabic'] = 0x0625;
  5676. t['alefhamzabelowfinalarabic'] = 0xFE88;
  5677. t['alefhebrew'] = 0x05D0;
  5678. t['aleflamedhebrew'] = 0xFB4F;
  5679. t['alefmaddaabovearabic'] = 0x0622;
  5680. t['alefmaddaabovefinalarabic'] = 0xFE82;
  5681. t['alefmaksuraarabic'] = 0x0649;
  5682. t['alefmaksurafinalarabic'] = 0xFEF0;
  5683. t['alefmaksurainitialarabic'] = 0xFEF3;
  5684. t['alefmaksuramedialarabic'] = 0xFEF4;
  5685. t['alefpatahhebrew'] = 0xFB2E;
  5686. t['alefqamatshebrew'] = 0xFB2F;
  5687. t['aleph'] = 0x2135;
  5688. t['allequal'] = 0x224C;
  5689. t['alpha'] = 0x03B1;
  5690. t['alphatonos'] = 0x03AC;
  5691. t['amacron'] = 0x0101;
  5692. t['amonospace'] = 0xFF41;
  5693. t['ampersand'] = 0x0026;
  5694. t['ampersandmonospace'] = 0xFF06;
  5695. t['ampersandsmall'] = 0xF726;
  5696. t['amsquare'] = 0x33C2;
  5697. t['anbopomofo'] = 0x3122;
  5698. t['angbopomofo'] = 0x3124;
  5699. t['angbracketleft'] = 0x3008; // Glyph is missing from Adobe's original list.
  5700. t['angbracketright'] = 0x3009; // Glyph is missing from Adobe's original list.
  5701. t['angkhankhuthai'] = 0x0E5A;
  5702. t['angle'] = 0x2220;
  5703. t['anglebracketleft'] = 0x3008;
  5704. t['anglebracketleftvertical'] = 0xFE3F;
  5705. t['anglebracketright'] = 0x3009;
  5706. t['anglebracketrightvertical'] = 0xFE40;
  5707. t['angleleft'] = 0x2329;
  5708. t['angleright'] = 0x232A;
  5709. t['angstrom'] = 0x212B;
  5710. t['anoteleia'] = 0x0387;
  5711. t['anudattadeva'] = 0x0952;
  5712. t['anusvarabengali'] = 0x0982;
  5713. t['anusvaradeva'] = 0x0902;
  5714. t['anusvaragujarati'] = 0x0A82;
  5715. t['aogonek'] = 0x0105;
  5716. t['apaatosquare'] = 0x3300;
  5717. t['aparen'] = 0x249C;
  5718. t['apostrophearmenian'] = 0x055A;
  5719. t['apostrophemod'] = 0x02BC;
  5720. t['apple'] = 0xF8FF;
  5721. t['approaches'] = 0x2250;
  5722. t['approxequal'] = 0x2248;
  5723. t['approxequalorimage'] = 0x2252;
  5724. t['approximatelyequal'] = 0x2245;
  5725. t['araeaekorean'] = 0x318E;
  5726. t['araeakorean'] = 0x318D;
  5727. t['arc'] = 0x2312;
  5728. t['arighthalfring'] = 0x1E9A;
  5729. t['aring'] = 0x00E5;
  5730. t['aringacute'] = 0x01FB;
  5731. t['aringbelow'] = 0x1E01;
  5732. t['arrowboth'] = 0x2194;
  5733. t['arrowdashdown'] = 0x21E3;
  5734. t['arrowdashleft'] = 0x21E0;
  5735. t['arrowdashright'] = 0x21E2;
  5736. t['arrowdashup'] = 0x21E1;
  5737. t['arrowdblboth'] = 0x21D4;
  5738. t['arrowdbldown'] = 0x21D3;
  5739. t['arrowdblleft'] = 0x21D0;
  5740. t['arrowdblright'] = 0x21D2;
  5741. t['arrowdblup'] = 0x21D1;
  5742. t['arrowdown'] = 0x2193;
  5743. t['arrowdownleft'] = 0x2199;
  5744. t['arrowdownright'] = 0x2198;
  5745. t['arrowdownwhite'] = 0x21E9;
  5746. t['arrowheaddownmod'] = 0x02C5;
  5747. t['arrowheadleftmod'] = 0x02C2;
  5748. t['arrowheadrightmod'] = 0x02C3;
  5749. t['arrowheadupmod'] = 0x02C4;
  5750. t['arrowhorizex'] = 0xF8E7;
  5751. t['arrowleft'] = 0x2190;
  5752. t['arrowleftdbl'] = 0x21D0;
  5753. t['arrowleftdblstroke'] = 0x21CD;
  5754. t['arrowleftoverright'] = 0x21C6;
  5755. t['arrowleftwhite'] = 0x21E6;
  5756. t['arrowright'] = 0x2192;
  5757. t['arrowrightdblstroke'] = 0x21CF;
  5758. t['arrowrightheavy'] = 0x279E;
  5759. t['arrowrightoverleft'] = 0x21C4;
  5760. t['arrowrightwhite'] = 0x21E8;
  5761. t['arrowtableft'] = 0x21E4;
  5762. t['arrowtabright'] = 0x21E5;
  5763. t['arrowup'] = 0x2191;
  5764. t['arrowupdn'] = 0x2195;
  5765. t['arrowupdnbse'] = 0x21A8;
  5766. t['arrowupdownbase'] = 0x21A8;
  5767. t['arrowupleft'] = 0x2196;
  5768. t['arrowupleftofdown'] = 0x21C5;
  5769. t['arrowupright'] = 0x2197;
  5770. t['arrowupwhite'] = 0x21E7;
  5771. t['arrowvertex'] = 0xF8E6;
  5772. t['asciicircum'] = 0x005E;
  5773. t['asciicircummonospace'] = 0xFF3E;
  5774. t['asciitilde'] = 0x007E;
  5775. t['asciitildemonospace'] = 0xFF5E;
  5776. t['ascript'] = 0x0251;
  5777. t['ascriptturned'] = 0x0252;
  5778. t['asmallhiragana'] = 0x3041;
  5779. t['asmallkatakana'] = 0x30A1;
  5780. t['asmallkatakanahalfwidth'] = 0xFF67;
  5781. t['asterisk'] = 0x002A;
  5782. t['asteriskaltonearabic'] = 0x066D;
  5783. t['asteriskarabic'] = 0x066D;
  5784. t['asteriskmath'] = 0x2217;
  5785. t['asteriskmonospace'] = 0xFF0A;
  5786. t['asterisksmall'] = 0xFE61;
  5787. t['asterism'] = 0x2042;
  5788. t['asuperior'] = 0xF6E9;
  5789. t['asymptoticallyequal'] = 0x2243;
  5790. t['at'] = 0x0040;
  5791. t['atilde'] = 0x00E3;
  5792. t['atmonospace'] = 0xFF20;
  5793. t['atsmall'] = 0xFE6B;
  5794. t['aturned'] = 0x0250;
  5795. t['aubengali'] = 0x0994;
  5796. t['aubopomofo'] = 0x3120;
  5797. t['audeva'] = 0x0914;
  5798. t['augujarati'] = 0x0A94;
  5799. t['augurmukhi'] = 0x0A14;
  5800. t['aulengthmarkbengali'] = 0x09D7;
  5801. t['aumatragurmukhi'] = 0x0A4C;
  5802. t['auvowelsignbengali'] = 0x09CC;
  5803. t['auvowelsigndeva'] = 0x094C;
  5804. t['auvowelsigngujarati'] = 0x0ACC;
  5805. t['avagrahadeva'] = 0x093D;
  5806. t['aybarmenian'] = 0x0561;
  5807. t['ayin'] = 0x05E2;
  5808. t['ayinaltonehebrew'] = 0xFB20;
  5809. t['ayinhebrew'] = 0x05E2;
  5810. t['b'] = 0x0062;
  5811. t['babengali'] = 0x09AC;
  5812. t['backslash'] = 0x005C;
  5813. t['backslashmonospace'] = 0xFF3C;
  5814. t['badeva'] = 0x092C;
  5815. t['bagujarati'] = 0x0AAC;
  5816. t['bagurmukhi'] = 0x0A2C;
  5817. t['bahiragana'] = 0x3070;
  5818. t['bahtthai'] = 0x0E3F;
  5819. t['bakatakana'] = 0x30D0;
  5820. t['bar'] = 0x007C;
  5821. t['barmonospace'] = 0xFF5C;
  5822. t['bbopomofo'] = 0x3105;
  5823. t['bcircle'] = 0x24D1;
  5824. t['bdotaccent'] = 0x1E03;
  5825. t['bdotbelow'] = 0x1E05;
  5826. t['beamedsixteenthnotes'] = 0x266C;
  5827. t['because'] = 0x2235;
  5828. t['becyrillic'] = 0x0431;
  5829. t['beharabic'] = 0x0628;
  5830. t['behfinalarabic'] = 0xFE90;
  5831. t['behinitialarabic'] = 0xFE91;
  5832. t['behiragana'] = 0x3079;
  5833. t['behmedialarabic'] = 0xFE92;
  5834. t['behmeeminitialarabic'] = 0xFC9F;
  5835. t['behmeemisolatedarabic'] = 0xFC08;
  5836. t['behnoonfinalarabic'] = 0xFC6D;
  5837. t['bekatakana'] = 0x30D9;
  5838. t['benarmenian'] = 0x0562;
  5839. t['bet'] = 0x05D1;
  5840. t['beta'] = 0x03B2;
  5841. t['betasymbolgreek'] = 0x03D0;
  5842. t['betdagesh'] = 0xFB31;
  5843. t['betdageshhebrew'] = 0xFB31;
  5844. t['bethebrew'] = 0x05D1;
  5845. t['betrafehebrew'] = 0xFB4C;
  5846. t['bhabengali'] = 0x09AD;
  5847. t['bhadeva'] = 0x092D;
  5848. t['bhagujarati'] = 0x0AAD;
  5849. t['bhagurmukhi'] = 0x0A2D;
  5850. t['bhook'] = 0x0253;
  5851. t['bihiragana'] = 0x3073;
  5852. t['bikatakana'] = 0x30D3;
  5853. t['bilabialclick'] = 0x0298;
  5854. t['bindigurmukhi'] = 0x0A02;
  5855. t['birusquare'] = 0x3331;
  5856. t['blackcircle'] = 0x25CF;
  5857. t['blackdiamond'] = 0x25C6;
  5858. t['blackdownpointingtriangle'] = 0x25BC;
  5859. t['blackleftpointingpointer'] = 0x25C4;
  5860. t['blackleftpointingtriangle'] = 0x25C0;
  5861. t['blacklenticularbracketleft'] = 0x3010;
  5862. t['blacklenticularbracketleftvertical'] = 0xFE3B;
  5863. t['blacklenticularbracketright'] = 0x3011;
  5864. t['blacklenticularbracketrightvertical'] = 0xFE3C;
  5865. t['blacklowerlefttriangle'] = 0x25E3;
  5866. t['blacklowerrighttriangle'] = 0x25E2;
  5867. t['blackrectangle'] = 0x25AC;
  5868. t['blackrightpointingpointer'] = 0x25BA;
  5869. t['blackrightpointingtriangle'] = 0x25B6;
  5870. t['blacksmallsquare'] = 0x25AA;
  5871. t['blacksmilingface'] = 0x263B;
  5872. t['blacksquare'] = 0x25A0;
  5873. t['blackstar'] = 0x2605;
  5874. t['blackupperlefttriangle'] = 0x25E4;
  5875. t['blackupperrighttriangle'] = 0x25E5;
  5876. t['blackuppointingsmalltriangle'] = 0x25B4;
  5877. t['blackuppointingtriangle'] = 0x25B2;
  5878. t['blank'] = 0x2423;
  5879. t['blinebelow'] = 0x1E07;
  5880. t['block'] = 0x2588;
  5881. t['bmonospace'] = 0xFF42;
  5882. t['bobaimaithai'] = 0x0E1A;
  5883. t['bohiragana'] = 0x307C;
  5884. t['bokatakana'] = 0x30DC;
  5885. t['bparen'] = 0x249D;
  5886. t['bqsquare'] = 0x33C3;
  5887. t['braceex'] = 0xF8F4;
  5888. t['braceleft'] = 0x007B;
  5889. t['braceleftbt'] = 0xF8F3;
  5890. t['braceleftmid'] = 0xF8F2;
  5891. t['braceleftmonospace'] = 0xFF5B;
  5892. t['braceleftsmall'] = 0xFE5B;
  5893. t['bracelefttp'] = 0xF8F1;
  5894. t['braceleftvertical'] = 0xFE37;
  5895. t['braceright'] = 0x007D;
  5896. t['bracerightbt'] = 0xF8FE;
  5897. t['bracerightmid'] = 0xF8FD;
  5898. t['bracerightmonospace'] = 0xFF5D;
  5899. t['bracerightsmall'] = 0xFE5C;
  5900. t['bracerighttp'] = 0xF8FC;
  5901. t['bracerightvertical'] = 0xFE38;
  5902. t['bracketleft'] = 0x005B;
  5903. t['bracketleftbt'] = 0xF8F0;
  5904. t['bracketleftex'] = 0xF8EF;
  5905. t['bracketleftmonospace'] = 0xFF3B;
  5906. t['bracketlefttp'] = 0xF8EE;
  5907. t['bracketright'] = 0x005D;
  5908. t['bracketrightbt'] = 0xF8FB;
  5909. t['bracketrightex'] = 0xF8FA;
  5910. t['bracketrightmonospace'] = 0xFF3D;
  5911. t['bracketrighttp'] = 0xF8F9;
  5912. t['breve'] = 0x02D8;
  5913. t['brevebelowcmb'] = 0x032E;
  5914. t['brevecmb'] = 0x0306;
  5915. t['breveinvertedbelowcmb'] = 0x032F;
  5916. t['breveinvertedcmb'] = 0x0311;
  5917. t['breveinverteddoublecmb'] = 0x0361;
  5918. t['bridgebelowcmb'] = 0x032A;
  5919. t['bridgeinvertedbelowcmb'] = 0x033A;
  5920. t['brokenbar'] = 0x00A6;
  5921. t['bstroke'] = 0x0180;
  5922. t['bsuperior'] = 0xF6EA;
  5923. t['btopbar'] = 0x0183;
  5924. t['buhiragana'] = 0x3076;
  5925. t['bukatakana'] = 0x30D6;
  5926. t['bullet'] = 0x2022;
  5927. t['bulletinverse'] = 0x25D8;
  5928. t['bulletoperator'] = 0x2219;
  5929. t['bullseye'] = 0x25CE;
  5930. t['c'] = 0x0063;
  5931. t['caarmenian'] = 0x056E;
  5932. t['cabengali'] = 0x099A;
  5933. t['cacute'] = 0x0107;
  5934. t['cadeva'] = 0x091A;
  5935. t['cagujarati'] = 0x0A9A;
  5936. t['cagurmukhi'] = 0x0A1A;
  5937. t['calsquare'] = 0x3388;
  5938. t['candrabindubengali'] = 0x0981;
  5939. t['candrabinducmb'] = 0x0310;
  5940. t['candrabindudeva'] = 0x0901;
  5941. t['candrabindugujarati'] = 0x0A81;
  5942. t['capslock'] = 0x21EA;
  5943. t['careof'] = 0x2105;
  5944. t['caron'] = 0x02C7;
  5945. t['caronbelowcmb'] = 0x032C;
  5946. t['caroncmb'] = 0x030C;
  5947. t['carriagereturn'] = 0x21B5;
  5948. t['cbopomofo'] = 0x3118;
  5949. t['ccaron'] = 0x010D;
  5950. t['ccedilla'] = 0x00E7;
  5951. t['ccedillaacute'] = 0x1E09;
  5952. t['ccircle'] = 0x24D2;
  5953. t['ccircumflex'] = 0x0109;
  5954. t['ccurl'] = 0x0255;
  5955. t['cdot'] = 0x010B;
  5956. t['cdotaccent'] = 0x010B;
  5957. t['cdsquare'] = 0x33C5;
  5958. t['cedilla'] = 0x00B8;
  5959. t['cedillacmb'] = 0x0327;
  5960. t['cent'] = 0x00A2;
  5961. t['centigrade'] = 0x2103;
  5962. t['centinferior'] = 0xF6DF;
  5963. t['centmonospace'] = 0xFFE0;
  5964. t['centoldstyle'] = 0xF7A2;
  5965. t['centsuperior'] = 0xF6E0;
  5966. t['chaarmenian'] = 0x0579;
  5967. t['chabengali'] = 0x099B;
  5968. t['chadeva'] = 0x091B;
  5969. t['chagujarati'] = 0x0A9B;
  5970. t['chagurmukhi'] = 0x0A1B;
  5971. t['chbopomofo'] = 0x3114;
  5972. t['cheabkhasiancyrillic'] = 0x04BD;
  5973. t['checkmark'] = 0x2713;
  5974. t['checyrillic'] = 0x0447;
  5975. t['chedescenderabkhasiancyrillic'] = 0x04BF;
  5976. t['chedescendercyrillic'] = 0x04B7;
  5977. t['chedieresiscyrillic'] = 0x04F5;
  5978. t['cheharmenian'] = 0x0573;
  5979. t['chekhakassiancyrillic'] = 0x04CC;
  5980. t['cheverticalstrokecyrillic'] = 0x04B9;
  5981. t['chi'] = 0x03C7;
  5982. t['chieuchacirclekorean'] = 0x3277;
  5983. t['chieuchaparenkorean'] = 0x3217;
  5984. t['chieuchcirclekorean'] = 0x3269;
  5985. t['chieuchkorean'] = 0x314A;
  5986. t['chieuchparenkorean'] = 0x3209;
  5987. t['chochangthai'] = 0x0E0A;
  5988. t['chochanthai'] = 0x0E08;
  5989. t['chochingthai'] = 0x0E09;
  5990. t['chochoethai'] = 0x0E0C;
  5991. t['chook'] = 0x0188;
  5992. t['cieucacirclekorean'] = 0x3276;
  5993. t['cieucaparenkorean'] = 0x3216;
  5994. t['cieuccirclekorean'] = 0x3268;
  5995. t['cieuckorean'] = 0x3148;
  5996. t['cieucparenkorean'] = 0x3208;
  5997. t['cieucuparenkorean'] = 0x321C;
  5998. t['circle'] = 0x25CB;
  5999. t['circlecopyrt'] = 0x00A9; // Glyph is missing from Adobe's original list.
  6000. t['circlemultiply'] = 0x2297;
  6001. t['circleot'] = 0x2299;
  6002. t['circleplus'] = 0x2295;
  6003. t['circlepostalmark'] = 0x3036;
  6004. t['circlewithlefthalfblack'] = 0x25D0;
  6005. t['circlewithrighthalfblack'] = 0x25D1;
  6006. t['circumflex'] = 0x02C6;
  6007. t['circumflexbelowcmb'] = 0x032D;
  6008. t['circumflexcmb'] = 0x0302;
  6009. t['clear'] = 0x2327;
  6010. t['clickalveolar'] = 0x01C2;
  6011. t['clickdental'] = 0x01C0;
  6012. t['clicklateral'] = 0x01C1;
  6013. t['clickretroflex'] = 0x01C3;
  6014. t['club'] = 0x2663;
  6015. t['clubsuitblack'] = 0x2663;
  6016. t['clubsuitwhite'] = 0x2667;
  6017. t['cmcubedsquare'] = 0x33A4;
  6018. t['cmonospace'] = 0xFF43;
  6019. t['cmsquaredsquare'] = 0x33A0;
  6020. t['coarmenian'] = 0x0581;
  6021. t['colon'] = 0x003A;
  6022. t['colonmonetary'] = 0x20A1;
  6023. t['colonmonospace'] = 0xFF1A;
  6024. t['colonsign'] = 0x20A1;
  6025. t['colonsmall'] = 0xFE55;
  6026. t['colontriangularhalfmod'] = 0x02D1;
  6027. t['colontriangularmod'] = 0x02D0;
  6028. t['comma'] = 0x002C;
  6029. t['commaabovecmb'] = 0x0313;
  6030. t['commaaboverightcmb'] = 0x0315;
  6031. t['commaaccent'] = 0xF6C3;
  6032. t['commaarabic'] = 0x060C;
  6033. t['commaarmenian'] = 0x055D;
  6034. t['commainferior'] = 0xF6E1;
  6035. t['commamonospace'] = 0xFF0C;
  6036. t['commareversedabovecmb'] = 0x0314;
  6037. t['commareversedmod'] = 0x02BD;
  6038. t['commasmall'] = 0xFE50;
  6039. t['commasuperior'] = 0xF6E2;
  6040. t['commaturnedabovecmb'] = 0x0312;
  6041. t['commaturnedmod'] = 0x02BB;
  6042. t['compass'] = 0x263C;
  6043. t['congruent'] = 0x2245;
  6044. t['contourintegral'] = 0x222E;
  6045. t['control'] = 0x2303;
  6046. t['controlACK'] = 0x0006;
  6047. t['controlBEL'] = 0x0007;
  6048. t['controlBS'] = 0x0008;
  6049. t['controlCAN'] = 0x0018;
  6050. t['controlCR'] = 0x000D;
  6051. t['controlDC1'] = 0x0011;
  6052. t['controlDC2'] = 0x0012;
  6053. t['controlDC3'] = 0x0013;
  6054. t['controlDC4'] = 0x0014;
  6055. t['controlDEL'] = 0x007F;
  6056. t['controlDLE'] = 0x0010;
  6057. t['controlEM'] = 0x0019;
  6058. t['controlENQ'] = 0x0005;
  6059. t['controlEOT'] = 0x0004;
  6060. t['controlESC'] = 0x001B;
  6061. t['controlETB'] = 0x0017;
  6062. t['controlETX'] = 0x0003;
  6063. t['controlFF'] = 0x000C;
  6064. t['controlFS'] = 0x001C;
  6065. t['controlGS'] = 0x001D;
  6066. t['controlHT'] = 0x0009;
  6067. t['controlLF'] = 0x000A;
  6068. t['controlNAK'] = 0x0015;
  6069. t['controlRS'] = 0x001E;
  6070. t['controlSI'] = 0x000F;
  6071. t['controlSO'] = 0x000E;
  6072. t['controlSOT'] = 0x0002;
  6073. t['controlSTX'] = 0x0001;
  6074. t['controlSUB'] = 0x001A;
  6075. t['controlSYN'] = 0x0016;
  6076. t['controlUS'] = 0x001F;
  6077. t['controlVT'] = 0x000B;
  6078. t['copyright'] = 0x00A9;
  6079. t['copyrightsans'] = 0xF8E9;
  6080. t['copyrightserif'] = 0xF6D9;
  6081. t['cornerbracketleft'] = 0x300C;
  6082. t['cornerbracketlefthalfwidth'] = 0xFF62;
  6083. t['cornerbracketleftvertical'] = 0xFE41;
  6084. t['cornerbracketright'] = 0x300D;
  6085. t['cornerbracketrighthalfwidth'] = 0xFF63;
  6086. t['cornerbracketrightvertical'] = 0xFE42;
  6087. t['corporationsquare'] = 0x337F;
  6088. t['cosquare'] = 0x33C7;
  6089. t['coverkgsquare'] = 0x33C6;
  6090. t['cparen'] = 0x249E;
  6091. t['cruzeiro'] = 0x20A2;
  6092. t['cstretched'] = 0x0297;
  6093. t['curlyand'] = 0x22CF;
  6094. t['curlyor'] = 0x22CE;
  6095. t['currency'] = 0x00A4;
  6096. t['cyrBreve'] = 0xF6D1;
  6097. t['cyrFlex'] = 0xF6D2;
  6098. t['cyrbreve'] = 0xF6D4;
  6099. t['cyrflex'] = 0xF6D5;
  6100. t['d'] = 0x0064;
  6101. t['daarmenian'] = 0x0564;
  6102. t['dabengali'] = 0x09A6;
  6103. t['dadarabic'] = 0x0636;
  6104. t['dadeva'] = 0x0926;
  6105. t['dadfinalarabic'] = 0xFEBE;
  6106. t['dadinitialarabic'] = 0xFEBF;
  6107. t['dadmedialarabic'] = 0xFEC0;
  6108. t['dagesh'] = 0x05BC;
  6109. t['dageshhebrew'] = 0x05BC;
  6110. t['dagger'] = 0x2020;
  6111. t['daggerdbl'] = 0x2021;
  6112. t['dagujarati'] = 0x0AA6;
  6113. t['dagurmukhi'] = 0x0A26;
  6114. t['dahiragana'] = 0x3060;
  6115. t['dakatakana'] = 0x30C0;
  6116. t['dalarabic'] = 0x062F;
  6117. t['dalet'] = 0x05D3;
  6118. t['daletdagesh'] = 0xFB33;
  6119. t['daletdageshhebrew'] = 0xFB33;
  6120. t['dalethebrew'] = 0x05D3;
  6121. t['dalfinalarabic'] = 0xFEAA;
  6122. t['dammaarabic'] = 0x064F;
  6123. t['dammalowarabic'] = 0x064F;
  6124. t['dammatanaltonearabic'] = 0x064C;
  6125. t['dammatanarabic'] = 0x064C;
  6126. t['danda'] = 0x0964;
  6127. t['dargahebrew'] = 0x05A7;
  6128. t['dargalefthebrew'] = 0x05A7;
  6129. t['dasiapneumatacyrilliccmb'] = 0x0485;
  6130. t['dblGrave'] = 0xF6D3;
  6131. t['dblanglebracketleft'] = 0x300A;
  6132. t['dblanglebracketleftvertical'] = 0xFE3D;
  6133. t['dblanglebracketright'] = 0x300B;
  6134. t['dblanglebracketrightvertical'] = 0xFE3E;
  6135. t['dblarchinvertedbelowcmb'] = 0x032B;
  6136. t['dblarrowleft'] = 0x21D4;
  6137. t['dblarrowright'] = 0x21D2;
  6138. t['dbldanda'] = 0x0965;
  6139. t['dblgrave'] = 0xF6D6;
  6140. t['dblgravecmb'] = 0x030F;
  6141. t['dblintegral'] = 0x222C;
  6142. t['dbllowline'] = 0x2017;
  6143. t['dbllowlinecmb'] = 0x0333;
  6144. t['dbloverlinecmb'] = 0x033F;
  6145. t['dblprimemod'] = 0x02BA;
  6146. t['dblverticalbar'] = 0x2016;
  6147. t['dblverticallineabovecmb'] = 0x030E;
  6148. t['dbopomofo'] = 0x3109;
  6149. t['dbsquare'] = 0x33C8;
  6150. t['dcaron'] = 0x010F;
  6151. t['dcedilla'] = 0x1E11;
  6152. t['dcircle'] = 0x24D3;
  6153. t['dcircumflexbelow'] = 0x1E13;
  6154. t['dcroat'] = 0x0111;
  6155. t['ddabengali'] = 0x09A1;
  6156. t['ddadeva'] = 0x0921;
  6157. t['ddagujarati'] = 0x0AA1;
  6158. t['ddagurmukhi'] = 0x0A21;
  6159. t['ddalarabic'] = 0x0688;
  6160. t['ddalfinalarabic'] = 0xFB89;
  6161. t['dddhadeva'] = 0x095C;
  6162. t['ddhabengali'] = 0x09A2;
  6163. t['ddhadeva'] = 0x0922;
  6164. t['ddhagujarati'] = 0x0AA2;
  6165. t['ddhagurmukhi'] = 0x0A22;
  6166. t['ddotaccent'] = 0x1E0B;
  6167. t['ddotbelow'] = 0x1E0D;
  6168. t['decimalseparatorarabic'] = 0x066B;
  6169. t['decimalseparatorpersian'] = 0x066B;
  6170. t['decyrillic'] = 0x0434;
  6171. t['degree'] = 0x00B0;
  6172. t['dehihebrew'] = 0x05AD;
  6173. t['dehiragana'] = 0x3067;
  6174. t['deicoptic'] = 0x03EF;
  6175. t['dekatakana'] = 0x30C7;
  6176. t['deleteleft'] = 0x232B;
  6177. t['deleteright'] = 0x2326;
  6178. t['delta'] = 0x03B4;
  6179. t['deltaturned'] = 0x018D;
  6180. t['denominatorminusonenumeratorbengali'] = 0x09F8;
  6181. t['dezh'] = 0x02A4;
  6182. t['dhabengali'] = 0x09A7;
  6183. t['dhadeva'] = 0x0927;
  6184. t['dhagujarati'] = 0x0AA7;
  6185. t['dhagurmukhi'] = 0x0A27;
  6186. t['dhook'] = 0x0257;
  6187. t['dialytikatonos'] = 0x0385;
  6188. t['dialytikatonoscmb'] = 0x0344;
  6189. t['diamond'] = 0x2666;
  6190. t['diamondsuitwhite'] = 0x2662;
  6191. t['dieresis'] = 0x00A8;
  6192. t['dieresisacute'] = 0xF6D7;
  6193. t['dieresisbelowcmb'] = 0x0324;
  6194. t['dieresiscmb'] = 0x0308;
  6195. t['dieresisgrave'] = 0xF6D8;
  6196. t['dieresistonos'] = 0x0385;
  6197. t['dihiragana'] = 0x3062;
  6198. t['dikatakana'] = 0x30C2;
  6199. t['dittomark'] = 0x3003;
  6200. t['divide'] = 0x00F7;
  6201. t['divides'] = 0x2223;
  6202. t['divisionslash'] = 0x2215;
  6203. t['djecyrillic'] = 0x0452;
  6204. t['dkshade'] = 0x2593;
  6205. t['dlinebelow'] = 0x1E0F;
  6206. t['dlsquare'] = 0x3397;
  6207. t['dmacron'] = 0x0111;
  6208. t['dmonospace'] = 0xFF44;
  6209. t['dnblock'] = 0x2584;
  6210. t['dochadathai'] = 0x0E0E;
  6211. t['dodekthai'] = 0x0E14;
  6212. t['dohiragana'] = 0x3069;
  6213. t['dokatakana'] = 0x30C9;
  6214. t['dollar'] = 0x0024;
  6215. t['dollarinferior'] = 0xF6E3;
  6216. t['dollarmonospace'] = 0xFF04;
  6217. t['dollaroldstyle'] = 0xF724;
  6218. t['dollarsmall'] = 0xFE69;
  6219. t['dollarsuperior'] = 0xF6E4;
  6220. t['dong'] = 0x20AB;
  6221. t['dorusquare'] = 0x3326;
  6222. t['dotaccent'] = 0x02D9;
  6223. t['dotaccentcmb'] = 0x0307;
  6224. t['dotbelowcmb'] = 0x0323;
  6225. t['dotbelowcomb'] = 0x0323;
  6226. t['dotkatakana'] = 0x30FB;
  6227. t['dotlessi'] = 0x0131;
  6228. t['dotlessj'] = 0xF6BE;
  6229. t['dotlessjstrokehook'] = 0x0284;
  6230. t['dotmath'] = 0x22C5;
  6231. t['dottedcircle'] = 0x25CC;
  6232. t['doubleyodpatah'] = 0xFB1F;
  6233. t['doubleyodpatahhebrew'] = 0xFB1F;
  6234. t['downtackbelowcmb'] = 0x031E;
  6235. t['downtackmod'] = 0x02D5;
  6236. t['dparen'] = 0x249F;
  6237. t['dsuperior'] = 0xF6EB;
  6238. t['dtail'] = 0x0256;
  6239. t['dtopbar'] = 0x018C;
  6240. t['duhiragana'] = 0x3065;
  6241. t['dukatakana'] = 0x30C5;
  6242. t['dz'] = 0x01F3;
  6243. t['dzaltone'] = 0x02A3;
  6244. t['dzcaron'] = 0x01C6;
  6245. t['dzcurl'] = 0x02A5;
  6246. t['dzeabkhasiancyrillic'] = 0x04E1;
  6247. t['dzecyrillic'] = 0x0455;
  6248. t['dzhecyrillic'] = 0x045F;
  6249. t['e'] = 0x0065;
  6250. t['eacute'] = 0x00E9;
  6251. t['earth'] = 0x2641;
  6252. t['ebengali'] = 0x098F;
  6253. t['ebopomofo'] = 0x311C;
  6254. t['ebreve'] = 0x0115;
  6255. t['ecandradeva'] = 0x090D;
  6256. t['ecandragujarati'] = 0x0A8D;
  6257. t['ecandravowelsigndeva'] = 0x0945;
  6258. t['ecandravowelsigngujarati'] = 0x0AC5;
  6259. t['ecaron'] = 0x011B;
  6260. t['ecedillabreve'] = 0x1E1D;
  6261. t['echarmenian'] = 0x0565;
  6262. t['echyiwnarmenian'] = 0x0587;
  6263. t['ecircle'] = 0x24D4;
  6264. t['ecircumflex'] = 0x00EA;
  6265. t['ecircumflexacute'] = 0x1EBF;
  6266. t['ecircumflexbelow'] = 0x1E19;
  6267. t['ecircumflexdotbelow'] = 0x1EC7;
  6268. t['ecircumflexgrave'] = 0x1EC1;
  6269. t['ecircumflexhookabove'] = 0x1EC3;
  6270. t['ecircumflextilde'] = 0x1EC5;
  6271. t['ecyrillic'] = 0x0454;
  6272. t['edblgrave'] = 0x0205;
  6273. t['edeva'] = 0x090F;
  6274. t['edieresis'] = 0x00EB;
  6275. t['edot'] = 0x0117;
  6276. t['edotaccent'] = 0x0117;
  6277. t['edotbelow'] = 0x1EB9;
  6278. t['eegurmukhi'] = 0x0A0F;
  6279. t['eematragurmukhi'] = 0x0A47;
  6280. t['efcyrillic'] = 0x0444;
  6281. t['egrave'] = 0x00E8;
  6282. t['egujarati'] = 0x0A8F;
  6283. t['eharmenian'] = 0x0567;
  6284. t['ehbopomofo'] = 0x311D;
  6285. t['ehiragana'] = 0x3048;
  6286. t['ehookabove'] = 0x1EBB;
  6287. t['eibopomofo'] = 0x311F;
  6288. t['eight'] = 0x0038;
  6289. t['eightarabic'] = 0x0668;
  6290. t['eightbengali'] = 0x09EE;
  6291. t['eightcircle'] = 0x2467;
  6292. t['eightcircleinversesansserif'] = 0x2791;
  6293. t['eightdeva'] = 0x096E;
  6294. t['eighteencircle'] = 0x2471;
  6295. t['eighteenparen'] = 0x2485;
  6296. t['eighteenperiod'] = 0x2499;
  6297. t['eightgujarati'] = 0x0AEE;
  6298. t['eightgurmukhi'] = 0x0A6E;
  6299. t['eighthackarabic'] = 0x0668;
  6300. t['eighthangzhou'] = 0x3028;
  6301. t['eighthnotebeamed'] = 0x266B;
  6302. t['eightideographicparen'] = 0x3227;
  6303. t['eightinferior'] = 0x2088;
  6304. t['eightmonospace'] = 0xFF18;
  6305. t['eightoldstyle'] = 0xF738;
  6306. t['eightparen'] = 0x247B;
  6307. t['eightperiod'] = 0x248F;
  6308. t['eightpersian'] = 0x06F8;
  6309. t['eightroman'] = 0x2177;
  6310. t['eightsuperior'] = 0x2078;
  6311. t['eightthai'] = 0x0E58;
  6312. t['einvertedbreve'] = 0x0207;
  6313. t['eiotifiedcyrillic'] = 0x0465;
  6314. t['ekatakana'] = 0x30A8;
  6315. t['ekatakanahalfwidth'] = 0xFF74;
  6316. t['ekonkargurmukhi'] = 0x0A74;
  6317. t['ekorean'] = 0x3154;
  6318. t['elcyrillic'] = 0x043B;
  6319. t['element'] = 0x2208;
  6320. t['elevencircle'] = 0x246A;
  6321. t['elevenparen'] = 0x247E;
  6322. t['elevenperiod'] = 0x2492;
  6323. t['elevenroman'] = 0x217A;
  6324. t['ellipsis'] = 0x2026;
  6325. t['ellipsisvertical'] = 0x22EE;
  6326. t['emacron'] = 0x0113;
  6327. t['emacronacute'] = 0x1E17;
  6328. t['emacrongrave'] = 0x1E15;
  6329. t['emcyrillic'] = 0x043C;
  6330. t['emdash'] = 0x2014;
  6331. t['emdashvertical'] = 0xFE31;
  6332. t['emonospace'] = 0xFF45;
  6333. t['emphasismarkarmenian'] = 0x055B;
  6334. t['emptyset'] = 0x2205;
  6335. t['enbopomofo'] = 0x3123;
  6336. t['encyrillic'] = 0x043D;
  6337. t['endash'] = 0x2013;
  6338. t['endashvertical'] = 0xFE32;
  6339. t['endescendercyrillic'] = 0x04A3;
  6340. t['eng'] = 0x014B;
  6341. t['engbopomofo'] = 0x3125;
  6342. t['enghecyrillic'] = 0x04A5;
  6343. t['enhookcyrillic'] = 0x04C8;
  6344. t['enspace'] = 0x2002;
  6345. t['eogonek'] = 0x0119;
  6346. t['eokorean'] = 0x3153;
  6347. t['eopen'] = 0x025B;
  6348. t['eopenclosed'] = 0x029A;
  6349. t['eopenreversed'] = 0x025C;
  6350. t['eopenreversedclosed'] = 0x025E;
  6351. t['eopenreversedhook'] = 0x025D;
  6352. t['eparen'] = 0x24A0;
  6353. t['epsilon'] = 0x03B5;
  6354. t['epsilontonos'] = 0x03AD;
  6355. t['equal'] = 0x003D;
  6356. t['equalmonospace'] = 0xFF1D;
  6357. t['equalsmall'] = 0xFE66;
  6358. t['equalsuperior'] = 0x207C;
  6359. t['equivalence'] = 0x2261;
  6360. t['erbopomofo'] = 0x3126;
  6361. t['ercyrillic'] = 0x0440;
  6362. t['ereversed'] = 0x0258;
  6363. t['ereversedcyrillic'] = 0x044D;
  6364. t['escyrillic'] = 0x0441;
  6365. t['esdescendercyrillic'] = 0x04AB;
  6366. t['esh'] = 0x0283;
  6367. t['eshcurl'] = 0x0286;
  6368. t['eshortdeva'] = 0x090E;
  6369. t['eshortvowelsigndeva'] = 0x0946;
  6370. t['eshreversedloop'] = 0x01AA;
  6371. t['eshsquatreversed'] = 0x0285;
  6372. t['esmallhiragana'] = 0x3047;
  6373. t['esmallkatakana'] = 0x30A7;
  6374. t['esmallkatakanahalfwidth'] = 0xFF6A;
  6375. t['estimated'] = 0x212E;
  6376. t['esuperior'] = 0xF6EC;
  6377. t['eta'] = 0x03B7;
  6378. t['etarmenian'] = 0x0568;
  6379. t['etatonos'] = 0x03AE;
  6380. t['eth'] = 0x00F0;
  6381. t['etilde'] = 0x1EBD;
  6382. t['etildebelow'] = 0x1E1B;
  6383. t['etnahtafoukhhebrew'] = 0x0591;
  6384. t['etnahtafoukhlefthebrew'] = 0x0591;
  6385. t['etnahtahebrew'] = 0x0591;
  6386. t['etnahtalefthebrew'] = 0x0591;
  6387. t['eturned'] = 0x01DD;
  6388. t['eukorean'] = 0x3161;
  6389. t['euro'] = 0x20AC;
  6390. t['evowelsignbengali'] = 0x09C7;
  6391. t['evowelsigndeva'] = 0x0947;
  6392. t['evowelsigngujarati'] = 0x0AC7;
  6393. t['exclam'] = 0x0021;
  6394. t['exclamarmenian'] = 0x055C;
  6395. t['exclamdbl'] = 0x203C;
  6396. t['exclamdown'] = 0x00A1;
  6397. t['exclamdownsmall'] = 0xF7A1;
  6398. t['exclammonospace'] = 0xFF01;
  6399. t['exclamsmall'] = 0xF721;
  6400. t['existential'] = 0x2203;
  6401. t['ezh'] = 0x0292;
  6402. t['ezhcaron'] = 0x01EF;
  6403. t['ezhcurl'] = 0x0293;
  6404. t['ezhreversed'] = 0x01B9;
  6405. t['ezhtail'] = 0x01BA;
  6406. t['f'] = 0x0066;
  6407. t['fadeva'] = 0x095E;
  6408. t['fagurmukhi'] = 0x0A5E;
  6409. t['fahrenheit'] = 0x2109;
  6410. t['fathaarabic'] = 0x064E;
  6411. t['fathalowarabic'] = 0x064E;
  6412. t['fathatanarabic'] = 0x064B;
  6413. t['fbopomofo'] = 0x3108;
  6414. t['fcircle'] = 0x24D5;
  6415. t['fdotaccent'] = 0x1E1F;
  6416. t['feharabic'] = 0x0641;
  6417. t['feharmenian'] = 0x0586;
  6418. t['fehfinalarabic'] = 0xFED2;
  6419. t['fehinitialarabic'] = 0xFED3;
  6420. t['fehmedialarabic'] = 0xFED4;
  6421. t['feicoptic'] = 0x03E5;
  6422. t['female'] = 0x2640;
  6423. t['ff'] = 0xFB00;
  6424. t['ffi'] = 0xFB03;
  6425. t['ffl'] = 0xFB04;
  6426. t['fi'] = 0xFB01;
  6427. t['fifteencircle'] = 0x246E;
  6428. t['fifteenparen'] = 0x2482;
  6429. t['fifteenperiod'] = 0x2496;
  6430. t['figuredash'] = 0x2012;
  6431. t['filledbox'] = 0x25A0;
  6432. t['filledrect'] = 0x25AC;
  6433. t['finalkaf'] = 0x05DA;
  6434. t['finalkafdagesh'] = 0xFB3A;
  6435. t['finalkafdageshhebrew'] = 0xFB3A;
  6436. t['finalkafhebrew'] = 0x05DA;
  6437. t['finalmem'] = 0x05DD;
  6438. t['finalmemhebrew'] = 0x05DD;
  6439. t['finalnun'] = 0x05DF;
  6440. t['finalnunhebrew'] = 0x05DF;
  6441. t['finalpe'] = 0x05E3;
  6442. t['finalpehebrew'] = 0x05E3;
  6443. t['finaltsadi'] = 0x05E5;
  6444. t['finaltsadihebrew'] = 0x05E5;
  6445. t['firsttonechinese'] = 0x02C9;
  6446. t['fisheye'] = 0x25C9;
  6447. t['fitacyrillic'] = 0x0473;
  6448. t['five'] = 0x0035;
  6449. t['fivearabic'] = 0x0665;
  6450. t['fivebengali'] = 0x09EB;
  6451. t['fivecircle'] = 0x2464;
  6452. t['fivecircleinversesansserif'] = 0x278E;
  6453. t['fivedeva'] = 0x096B;
  6454. t['fiveeighths'] = 0x215D;
  6455. t['fivegujarati'] = 0x0AEB;
  6456. t['fivegurmukhi'] = 0x0A6B;
  6457. t['fivehackarabic'] = 0x0665;
  6458. t['fivehangzhou'] = 0x3025;
  6459. t['fiveideographicparen'] = 0x3224;
  6460. t['fiveinferior'] = 0x2085;
  6461. t['fivemonospace'] = 0xFF15;
  6462. t['fiveoldstyle'] = 0xF735;
  6463. t['fiveparen'] = 0x2478;
  6464. t['fiveperiod'] = 0x248C;
  6465. t['fivepersian'] = 0x06F5;
  6466. t['fiveroman'] = 0x2174;
  6467. t['fivesuperior'] = 0x2075;
  6468. t['fivethai'] = 0x0E55;
  6469. t['fl'] = 0xFB02;
  6470. t['florin'] = 0x0192;
  6471. t['fmonospace'] = 0xFF46;
  6472. t['fmsquare'] = 0x3399;
  6473. t['fofanthai'] = 0x0E1F;
  6474. t['fofathai'] = 0x0E1D;
  6475. t['fongmanthai'] = 0x0E4F;
  6476. t['forall'] = 0x2200;
  6477. t['four'] = 0x0034;
  6478. t['fourarabic'] = 0x0664;
  6479. t['fourbengali'] = 0x09EA;
  6480. t['fourcircle'] = 0x2463;
  6481. t['fourcircleinversesansserif'] = 0x278D;
  6482. t['fourdeva'] = 0x096A;
  6483. t['fourgujarati'] = 0x0AEA;
  6484. t['fourgurmukhi'] = 0x0A6A;
  6485. t['fourhackarabic'] = 0x0664;
  6486. t['fourhangzhou'] = 0x3024;
  6487. t['fourideographicparen'] = 0x3223;
  6488. t['fourinferior'] = 0x2084;
  6489. t['fourmonospace'] = 0xFF14;
  6490. t['fournumeratorbengali'] = 0x09F7;
  6491. t['fouroldstyle'] = 0xF734;
  6492. t['fourparen'] = 0x2477;
  6493. t['fourperiod'] = 0x248B;
  6494. t['fourpersian'] = 0x06F4;
  6495. t['fourroman'] = 0x2173;
  6496. t['foursuperior'] = 0x2074;
  6497. t['fourteencircle'] = 0x246D;
  6498. t['fourteenparen'] = 0x2481;
  6499. t['fourteenperiod'] = 0x2495;
  6500. t['fourthai'] = 0x0E54;
  6501. t['fourthtonechinese'] = 0x02CB;
  6502. t['fparen'] = 0x24A1;
  6503. t['fraction'] = 0x2044;
  6504. t['franc'] = 0x20A3;
  6505. t['g'] = 0x0067;
  6506. t['gabengali'] = 0x0997;
  6507. t['gacute'] = 0x01F5;
  6508. t['gadeva'] = 0x0917;
  6509. t['gafarabic'] = 0x06AF;
  6510. t['gaffinalarabic'] = 0xFB93;
  6511. t['gafinitialarabic'] = 0xFB94;
  6512. t['gafmedialarabic'] = 0xFB95;
  6513. t['gagujarati'] = 0x0A97;
  6514. t['gagurmukhi'] = 0x0A17;
  6515. t['gahiragana'] = 0x304C;
  6516. t['gakatakana'] = 0x30AC;
  6517. t['gamma'] = 0x03B3;
  6518. t['gammalatinsmall'] = 0x0263;
  6519. t['gammasuperior'] = 0x02E0;
  6520. t['gangiacoptic'] = 0x03EB;
  6521. t['gbopomofo'] = 0x310D;
  6522. t['gbreve'] = 0x011F;
  6523. t['gcaron'] = 0x01E7;
  6524. t['gcedilla'] = 0x0123;
  6525. t['gcircle'] = 0x24D6;
  6526. t['gcircumflex'] = 0x011D;
  6527. t['gcommaaccent'] = 0x0123;
  6528. t['gdot'] = 0x0121;
  6529. t['gdotaccent'] = 0x0121;
  6530. t['gecyrillic'] = 0x0433;
  6531. t['gehiragana'] = 0x3052;
  6532. t['gekatakana'] = 0x30B2;
  6533. t['geometricallyequal'] = 0x2251;
  6534. t['gereshaccenthebrew'] = 0x059C;
  6535. t['gereshhebrew'] = 0x05F3;
  6536. t['gereshmuqdamhebrew'] = 0x059D;
  6537. t['germandbls'] = 0x00DF;
  6538. t['gershayimaccenthebrew'] = 0x059E;
  6539. t['gershayimhebrew'] = 0x05F4;
  6540. t['getamark'] = 0x3013;
  6541. t['ghabengali'] = 0x0998;
  6542. t['ghadarmenian'] = 0x0572;
  6543. t['ghadeva'] = 0x0918;
  6544. t['ghagujarati'] = 0x0A98;
  6545. t['ghagurmukhi'] = 0x0A18;
  6546. t['ghainarabic'] = 0x063A;
  6547. t['ghainfinalarabic'] = 0xFECE;
  6548. t['ghaininitialarabic'] = 0xFECF;
  6549. t['ghainmedialarabic'] = 0xFED0;
  6550. t['ghemiddlehookcyrillic'] = 0x0495;
  6551. t['ghestrokecyrillic'] = 0x0493;
  6552. t['gheupturncyrillic'] = 0x0491;
  6553. t['ghhadeva'] = 0x095A;
  6554. t['ghhagurmukhi'] = 0x0A5A;
  6555. t['ghook'] = 0x0260;
  6556. t['ghzsquare'] = 0x3393;
  6557. t['gihiragana'] = 0x304E;
  6558. t['gikatakana'] = 0x30AE;
  6559. t['gimarmenian'] = 0x0563;
  6560. t['gimel'] = 0x05D2;
  6561. t['gimeldagesh'] = 0xFB32;
  6562. t['gimeldageshhebrew'] = 0xFB32;
  6563. t['gimelhebrew'] = 0x05D2;
  6564. t['gjecyrillic'] = 0x0453;
  6565. t['glottalinvertedstroke'] = 0x01BE;
  6566. t['glottalstop'] = 0x0294;
  6567. t['glottalstopinverted'] = 0x0296;
  6568. t['glottalstopmod'] = 0x02C0;
  6569. t['glottalstopreversed'] = 0x0295;
  6570. t['glottalstopreversedmod'] = 0x02C1;
  6571. t['glottalstopreversedsuperior'] = 0x02E4;
  6572. t['glottalstopstroke'] = 0x02A1;
  6573. t['glottalstopstrokereversed'] = 0x02A2;
  6574. t['gmacron'] = 0x1E21;
  6575. t['gmonospace'] = 0xFF47;
  6576. t['gohiragana'] = 0x3054;
  6577. t['gokatakana'] = 0x30B4;
  6578. t['gparen'] = 0x24A2;
  6579. t['gpasquare'] = 0x33AC;
  6580. t['gradient'] = 0x2207;
  6581. t['grave'] = 0x0060;
  6582. t['gravebelowcmb'] = 0x0316;
  6583. t['gravecmb'] = 0x0300;
  6584. t['gravecomb'] = 0x0300;
  6585. t['gravedeva'] = 0x0953;
  6586. t['gravelowmod'] = 0x02CE;
  6587. t['gravemonospace'] = 0xFF40;
  6588. t['gravetonecmb'] = 0x0340;
  6589. t['greater'] = 0x003E;
  6590. t['greaterequal'] = 0x2265;
  6591. t['greaterequalorless'] = 0x22DB;
  6592. t['greatermonospace'] = 0xFF1E;
  6593. t['greaterorequivalent'] = 0x2273;
  6594. t['greaterorless'] = 0x2277;
  6595. t['greateroverequal'] = 0x2267;
  6596. t['greatersmall'] = 0xFE65;
  6597. t['gscript'] = 0x0261;
  6598. t['gstroke'] = 0x01E5;
  6599. t['guhiragana'] = 0x3050;
  6600. t['guillemotleft'] = 0x00AB;
  6601. t['guillemotright'] = 0x00BB;
  6602. t['guilsinglleft'] = 0x2039;
  6603. t['guilsinglright'] = 0x203A;
  6604. t['gukatakana'] = 0x30B0;
  6605. t['guramusquare'] = 0x3318;
  6606. t['gysquare'] = 0x33C9;
  6607. t['h'] = 0x0068;
  6608. t['haabkhasiancyrillic'] = 0x04A9;
  6609. t['haaltonearabic'] = 0x06C1;
  6610. t['habengali'] = 0x09B9;
  6611. t['hadescendercyrillic'] = 0x04B3;
  6612. t['hadeva'] = 0x0939;
  6613. t['hagujarati'] = 0x0AB9;
  6614. t['hagurmukhi'] = 0x0A39;
  6615. t['haharabic'] = 0x062D;
  6616. t['hahfinalarabic'] = 0xFEA2;
  6617. t['hahinitialarabic'] = 0xFEA3;
  6618. t['hahiragana'] = 0x306F;
  6619. t['hahmedialarabic'] = 0xFEA4;
  6620. t['haitusquare'] = 0x332A;
  6621. t['hakatakana'] = 0x30CF;
  6622. t['hakatakanahalfwidth'] = 0xFF8A;
  6623. t['halantgurmukhi'] = 0x0A4D;
  6624. t['hamzaarabic'] = 0x0621;
  6625. t['hamzalowarabic'] = 0x0621;
  6626. t['hangulfiller'] = 0x3164;
  6627. t['hardsigncyrillic'] = 0x044A;
  6628. t['harpoonleftbarbup'] = 0x21BC;
  6629. t['harpoonrightbarbup'] = 0x21C0;
  6630. t['hasquare'] = 0x33CA;
  6631. t['hatafpatah'] = 0x05B2;
  6632. t['hatafpatah16'] = 0x05B2;
  6633. t['hatafpatah23'] = 0x05B2;
  6634. t['hatafpatah2f'] = 0x05B2;
  6635. t['hatafpatahhebrew'] = 0x05B2;
  6636. t['hatafpatahnarrowhebrew'] = 0x05B2;
  6637. t['hatafpatahquarterhebrew'] = 0x05B2;
  6638. t['hatafpatahwidehebrew'] = 0x05B2;
  6639. t['hatafqamats'] = 0x05B3;
  6640. t['hatafqamats1b'] = 0x05B3;
  6641. t['hatafqamats28'] = 0x05B3;
  6642. t['hatafqamats34'] = 0x05B3;
  6643. t['hatafqamatshebrew'] = 0x05B3;
  6644. t['hatafqamatsnarrowhebrew'] = 0x05B3;
  6645. t['hatafqamatsquarterhebrew'] = 0x05B3;
  6646. t['hatafqamatswidehebrew'] = 0x05B3;
  6647. t['hatafsegol'] = 0x05B1;
  6648. t['hatafsegol17'] = 0x05B1;
  6649. t['hatafsegol24'] = 0x05B1;
  6650. t['hatafsegol30'] = 0x05B1;
  6651. t['hatafsegolhebrew'] = 0x05B1;
  6652. t['hatafsegolnarrowhebrew'] = 0x05B1;
  6653. t['hatafsegolquarterhebrew'] = 0x05B1;
  6654. t['hatafsegolwidehebrew'] = 0x05B1;
  6655. t['hbar'] = 0x0127;
  6656. t['hbopomofo'] = 0x310F;
  6657. t['hbrevebelow'] = 0x1E2B;
  6658. t['hcedilla'] = 0x1E29;
  6659. t['hcircle'] = 0x24D7;
  6660. t['hcircumflex'] = 0x0125;
  6661. t['hdieresis'] = 0x1E27;
  6662. t['hdotaccent'] = 0x1E23;
  6663. t['hdotbelow'] = 0x1E25;
  6664. t['he'] = 0x05D4;
  6665. t['heart'] = 0x2665;
  6666. t['heartsuitblack'] = 0x2665;
  6667. t['heartsuitwhite'] = 0x2661;
  6668. t['hedagesh'] = 0xFB34;
  6669. t['hedageshhebrew'] = 0xFB34;
  6670. t['hehaltonearabic'] = 0x06C1;
  6671. t['heharabic'] = 0x0647;
  6672. t['hehebrew'] = 0x05D4;
  6673. t['hehfinalaltonearabic'] = 0xFBA7;
  6674. t['hehfinalalttwoarabic'] = 0xFEEA;
  6675. t['hehfinalarabic'] = 0xFEEA;
  6676. t['hehhamzaabovefinalarabic'] = 0xFBA5;
  6677. t['hehhamzaaboveisolatedarabic'] = 0xFBA4;
  6678. t['hehinitialaltonearabic'] = 0xFBA8;
  6679. t['hehinitialarabic'] = 0xFEEB;
  6680. t['hehiragana'] = 0x3078;
  6681. t['hehmedialaltonearabic'] = 0xFBA9;
  6682. t['hehmedialarabic'] = 0xFEEC;
  6683. t['heiseierasquare'] = 0x337B;
  6684. t['hekatakana'] = 0x30D8;
  6685. t['hekatakanahalfwidth'] = 0xFF8D;
  6686. t['hekutaarusquare'] = 0x3336;
  6687. t['henghook'] = 0x0267;
  6688. t['herutusquare'] = 0x3339;
  6689. t['het'] = 0x05D7;
  6690. t['hethebrew'] = 0x05D7;
  6691. t['hhook'] = 0x0266;
  6692. t['hhooksuperior'] = 0x02B1;
  6693. t['hieuhacirclekorean'] = 0x327B;
  6694. t['hieuhaparenkorean'] = 0x321B;
  6695. t['hieuhcirclekorean'] = 0x326D;
  6696. t['hieuhkorean'] = 0x314E;
  6697. t['hieuhparenkorean'] = 0x320D;
  6698. t['hihiragana'] = 0x3072;
  6699. t['hikatakana'] = 0x30D2;
  6700. t['hikatakanahalfwidth'] = 0xFF8B;
  6701. t['hiriq'] = 0x05B4;
  6702. t['hiriq14'] = 0x05B4;
  6703. t['hiriq21'] = 0x05B4;
  6704. t['hiriq2d'] = 0x05B4;
  6705. t['hiriqhebrew'] = 0x05B4;
  6706. t['hiriqnarrowhebrew'] = 0x05B4;
  6707. t['hiriqquarterhebrew'] = 0x05B4;
  6708. t['hiriqwidehebrew'] = 0x05B4;
  6709. t['hlinebelow'] = 0x1E96;
  6710. t['hmonospace'] = 0xFF48;
  6711. t['hoarmenian'] = 0x0570;
  6712. t['hohipthai'] = 0x0E2B;
  6713. t['hohiragana'] = 0x307B;
  6714. t['hokatakana'] = 0x30DB;
  6715. t['hokatakanahalfwidth'] = 0xFF8E;
  6716. t['holam'] = 0x05B9;
  6717. t['holam19'] = 0x05B9;
  6718. t['holam26'] = 0x05B9;
  6719. t['holam32'] = 0x05B9;
  6720. t['holamhebrew'] = 0x05B9;
  6721. t['holamnarrowhebrew'] = 0x05B9;
  6722. t['holamquarterhebrew'] = 0x05B9;
  6723. t['holamwidehebrew'] = 0x05B9;
  6724. t['honokhukthai'] = 0x0E2E;
  6725. t['hookabovecomb'] = 0x0309;
  6726. t['hookcmb'] = 0x0309;
  6727. t['hookpalatalizedbelowcmb'] = 0x0321;
  6728. t['hookretroflexbelowcmb'] = 0x0322;
  6729. t['hoonsquare'] = 0x3342;
  6730. t['horicoptic'] = 0x03E9;
  6731. t['horizontalbar'] = 0x2015;
  6732. t['horncmb'] = 0x031B;
  6733. t['hotsprings'] = 0x2668;
  6734. t['house'] = 0x2302;
  6735. t['hparen'] = 0x24A3;
  6736. t['hsuperior'] = 0x02B0;
  6737. t['hturned'] = 0x0265;
  6738. t['huhiragana'] = 0x3075;
  6739. t['huiitosquare'] = 0x3333;
  6740. t['hukatakana'] = 0x30D5;
  6741. t['hukatakanahalfwidth'] = 0xFF8C;
  6742. t['hungarumlaut'] = 0x02DD;
  6743. t['hungarumlautcmb'] = 0x030B;
  6744. t['hv'] = 0x0195;
  6745. t['hyphen'] = 0x002D;
  6746. t['hypheninferior'] = 0xF6E5;
  6747. t['hyphenmonospace'] = 0xFF0D;
  6748. t['hyphensmall'] = 0xFE63;
  6749. t['hyphensuperior'] = 0xF6E6;
  6750. t['hyphentwo'] = 0x2010;
  6751. t['i'] = 0x0069;
  6752. t['iacute'] = 0x00ED;
  6753. t['iacyrillic'] = 0x044F;
  6754. t['ibengali'] = 0x0987;
  6755. t['ibopomofo'] = 0x3127;
  6756. t['ibreve'] = 0x012D;
  6757. t['icaron'] = 0x01D0;
  6758. t['icircle'] = 0x24D8;
  6759. t['icircumflex'] = 0x00EE;
  6760. t['icyrillic'] = 0x0456;
  6761. t['idblgrave'] = 0x0209;
  6762. t['ideographearthcircle'] = 0x328F;
  6763. t['ideographfirecircle'] = 0x328B;
  6764. t['ideographicallianceparen'] = 0x323F;
  6765. t['ideographiccallparen'] = 0x323A;
  6766. t['ideographiccentrecircle'] = 0x32A5;
  6767. t['ideographicclose'] = 0x3006;
  6768. t['ideographiccomma'] = 0x3001;
  6769. t['ideographiccommaleft'] = 0xFF64;
  6770. t['ideographiccongratulationparen'] = 0x3237;
  6771. t['ideographiccorrectcircle'] = 0x32A3;
  6772. t['ideographicearthparen'] = 0x322F;
  6773. t['ideographicenterpriseparen'] = 0x323D;
  6774. t['ideographicexcellentcircle'] = 0x329D;
  6775. t['ideographicfestivalparen'] = 0x3240;
  6776. t['ideographicfinancialcircle'] = 0x3296;
  6777. t['ideographicfinancialparen'] = 0x3236;
  6778. t['ideographicfireparen'] = 0x322B;
  6779. t['ideographichaveparen'] = 0x3232;
  6780. t['ideographichighcircle'] = 0x32A4;
  6781. t['ideographiciterationmark'] = 0x3005;
  6782. t['ideographiclaborcircle'] = 0x3298;
  6783. t['ideographiclaborparen'] = 0x3238;
  6784. t['ideographicleftcircle'] = 0x32A7;
  6785. t['ideographiclowcircle'] = 0x32A6;
  6786. t['ideographicmedicinecircle'] = 0x32A9;
  6787. t['ideographicmetalparen'] = 0x322E;
  6788. t['ideographicmoonparen'] = 0x322A;
  6789. t['ideographicnameparen'] = 0x3234;
  6790. t['ideographicperiod'] = 0x3002;
  6791. t['ideographicprintcircle'] = 0x329E;
  6792. t['ideographicreachparen'] = 0x3243;
  6793. t['ideographicrepresentparen'] = 0x3239;
  6794. t['ideographicresourceparen'] = 0x323E;
  6795. t['ideographicrightcircle'] = 0x32A8;
  6796. t['ideographicsecretcircle'] = 0x3299;
  6797. t['ideographicselfparen'] = 0x3242;
  6798. t['ideographicsocietyparen'] = 0x3233;
  6799. t['ideographicspace'] = 0x3000;
  6800. t['ideographicspecialparen'] = 0x3235;
  6801. t['ideographicstockparen'] = 0x3231;
  6802. t['ideographicstudyparen'] = 0x323B;
  6803. t['ideographicsunparen'] = 0x3230;
  6804. t['ideographicsuperviseparen'] = 0x323C;
  6805. t['ideographicwaterparen'] = 0x322C;
  6806. t['ideographicwoodparen'] = 0x322D;
  6807. t['ideographiczero'] = 0x3007;
  6808. t['ideographmetalcircle'] = 0x328E;
  6809. t['ideographmooncircle'] = 0x328A;
  6810. t['ideographnamecircle'] = 0x3294;
  6811. t['ideographsuncircle'] = 0x3290;
  6812. t['ideographwatercircle'] = 0x328C;
  6813. t['ideographwoodcircle'] = 0x328D;
  6814. t['ideva'] = 0x0907;
  6815. t['idieresis'] = 0x00EF;
  6816. t['idieresisacute'] = 0x1E2F;
  6817. t['idieresiscyrillic'] = 0x04E5;
  6818. t['idotbelow'] = 0x1ECB;
  6819. t['iebrevecyrillic'] = 0x04D7;
  6820. t['iecyrillic'] = 0x0435;
  6821. t['ieungacirclekorean'] = 0x3275;
  6822. t['ieungaparenkorean'] = 0x3215;
  6823. t['ieungcirclekorean'] = 0x3267;
  6824. t['ieungkorean'] = 0x3147;
  6825. t['ieungparenkorean'] = 0x3207;
  6826. t['igrave'] = 0x00EC;
  6827. t['igujarati'] = 0x0A87;
  6828. t['igurmukhi'] = 0x0A07;
  6829. t['ihiragana'] = 0x3044;
  6830. t['ihookabove'] = 0x1EC9;
  6831. t['iibengali'] = 0x0988;
  6832. t['iicyrillic'] = 0x0438;
  6833. t['iideva'] = 0x0908;
  6834. t['iigujarati'] = 0x0A88;
  6835. t['iigurmukhi'] = 0x0A08;
  6836. t['iimatragurmukhi'] = 0x0A40;
  6837. t['iinvertedbreve'] = 0x020B;
  6838. t['iishortcyrillic'] = 0x0439;
  6839. t['iivowelsignbengali'] = 0x09C0;
  6840. t['iivowelsigndeva'] = 0x0940;
  6841. t['iivowelsigngujarati'] = 0x0AC0;
  6842. t['ij'] = 0x0133;
  6843. t['ikatakana'] = 0x30A4;
  6844. t['ikatakanahalfwidth'] = 0xFF72;
  6845. t['ikorean'] = 0x3163;
  6846. t['ilde'] = 0x02DC;
  6847. t['iluyhebrew'] = 0x05AC;
  6848. t['imacron'] = 0x012B;
  6849. t['imacroncyrillic'] = 0x04E3;
  6850. t['imageorapproximatelyequal'] = 0x2253;
  6851. t['imatragurmukhi'] = 0x0A3F;
  6852. t['imonospace'] = 0xFF49;
  6853. t['increment'] = 0x2206;
  6854. t['infinity'] = 0x221E;
  6855. t['iniarmenian'] = 0x056B;
  6856. t['integral'] = 0x222B;
  6857. t['integralbottom'] = 0x2321;
  6858. t['integralbt'] = 0x2321;
  6859. t['integralex'] = 0xF8F5;
  6860. t['integraltop'] = 0x2320;
  6861. t['integraltp'] = 0x2320;
  6862. t['intersection'] = 0x2229;
  6863. t['intisquare'] = 0x3305;
  6864. t['invbullet'] = 0x25D8;
  6865. t['invcircle'] = 0x25D9;
  6866. t['invsmileface'] = 0x263B;
  6867. t['iocyrillic'] = 0x0451;
  6868. t['iogonek'] = 0x012F;
  6869. t['iota'] = 0x03B9;
  6870. t['iotadieresis'] = 0x03CA;
  6871. t['iotadieresistonos'] = 0x0390;
  6872. t['iotalatin'] = 0x0269;
  6873. t['iotatonos'] = 0x03AF;
  6874. t['iparen'] = 0x24A4;
  6875. t['irigurmukhi'] = 0x0A72;
  6876. t['ismallhiragana'] = 0x3043;
  6877. t['ismallkatakana'] = 0x30A3;
  6878. t['ismallkatakanahalfwidth'] = 0xFF68;
  6879. t['issharbengali'] = 0x09FA;
  6880. t['istroke'] = 0x0268;
  6881. t['isuperior'] = 0xF6ED;
  6882. t['iterationhiragana'] = 0x309D;
  6883. t['iterationkatakana'] = 0x30FD;
  6884. t['itilde'] = 0x0129;
  6885. t['itildebelow'] = 0x1E2D;
  6886. t['iubopomofo'] = 0x3129;
  6887. t['iucyrillic'] = 0x044E;
  6888. t['ivowelsignbengali'] = 0x09BF;
  6889. t['ivowelsigndeva'] = 0x093F;
  6890. t['ivowelsigngujarati'] = 0x0ABF;
  6891. t['izhitsacyrillic'] = 0x0475;
  6892. t['izhitsadblgravecyrillic'] = 0x0477;
  6893. t['j'] = 0x006A;
  6894. t['jaarmenian'] = 0x0571;
  6895. t['jabengali'] = 0x099C;
  6896. t['jadeva'] = 0x091C;
  6897. t['jagujarati'] = 0x0A9C;
  6898. t['jagurmukhi'] = 0x0A1C;
  6899. t['jbopomofo'] = 0x3110;
  6900. t['jcaron'] = 0x01F0;
  6901. t['jcircle'] = 0x24D9;
  6902. t['jcircumflex'] = 0x0135;
  6903. t['jcrossedtail'] = 0x029D;
  6904. t['jdotlessstroke'] = 0x025F;
  6905. t['jecyrillic'] = 0x0458;
  6906. t['jeemarabic'] = 0x062C;
  6907. t['jeemfinalarabic'] = 0xFE9E;
  6908. t['jeeminitialarabic'] = 0xFE9F;
  6909. t['jeemmedialarabic'] = 0xFEA0;
  6910. t['jeharabic'] = 0x0698;
  6911. t['jehfinalarabic'] = 0xFB8B;
  6912. t['jhabengali'] = 0x099D;
  6913. t['jhadeva'] = 0x091D;
  6914. t['jhagujarati'] = 0x0A9D;
  6915. t['jhagurmukhi'] = 0x0A1D;
  6916. t['jheharmenian'] = 0x057B;
  6917. t['jis'] = 0x3004;
  6918. t['jmonospace'] = 0xFF4A;
  6919. t['jparen'] = 0x24A5;
  6920. t['jsuperior'] = 0x02B2;
  6921. t['k'] = 0x006B;
  6922. t['kabashkircyrillic'] = 0x04A1;
  6923. t['kabengali'] = 0x0995;
  6924. t['kacute'] = 0x1E31;
  6925. t['kacyrillic'] = 0x043A;
  6926. t['kadescendercyrillic'] = 0x049B;
  6927. t['kadeva'] = 0x0915;
  6928. t['kaf'] = 0x05DB;
  6929. t['kafarabic'] = 0x0643;
  6930. t['kafdagesh'] = 0xFB3B;
  6931. t['kafdageshhebrew'] = 0xFB3B;
  6932. t['kaffinalarabic'] = 0xFEDA;
  6933. t['kafhebrew'] = 0x05DB;
  6934. t['kafinitialarabic'] = 0xFEDB;
  6935. t['kafmedialarabic'] = 0xFEDC;
  6936. t['kafrafehebrew'] = 0xFB4D;
  6937. t['kagujarati'] = 0x0A95;
  6938. t['kagurmukhi'] = 0x0A15;
  6939. t['kahiragana'] = 0x304B;
  6940. t['kahookcyrillic'] = 0x04C4;
  6941. t['kakatakana'] = 0x30AB;
  6942. t['kakatakanahalfwidth'] = 0xFF76;
  6943. t['kappa'] = 0x03BA;
  6944. t['kappasymbolgreek'] = 0x03F0;
  6945. t['kapyeounmieumkorean'] = 0x3171;
  6946. t['kapyeounphieuphkorean'] = 0x3184;
  6947. t['kapyeounpieupkorean'] = 0x3178;
  6948. t['kapyeounssangpieupkorean'] = 0x3179;
  6949. t['karoriisquare'] = 0x330D;
  6950. t['kashidaautoarabic'] = 0x0640;
  6951. t['kashidaautonosidebearingarabic'] = 0x0640;
  6952. t['kasmallkatakana'] = 0x30F5;
  6953. t['kasquare'] = 0x3384;
  6954. t['kasraarabic'] = 0x0650;
  6955. t['kasratanarabic'] = 0x064D;
  6956. t['kastrokecyrillic'] = 0x049F;
  6957. t['katahiraprolongmarkhalfwidth'] = 0xFF70;
  6958. t['kaverticalstrokecyrillic'] = 0x049D;
  6959. t['kbopomofo'] = 0x310E;
  6960. t['kcalsquare'] = 0x3389;
  6961. t['kcaron'] = 0x01E9;
  6962. t['kcedilla'] = 0x0137;
  6963. t['kcircle'] = 0x24DA;
  6964. t['kcommaaccent'] = 0x0137;
  6965. t['kdotbelow'] = 0x1E33;
  6966. t['keharmenian'] = 0x0584;
  6967. t['kehiragana'] = 0x3051;
  6968. t['kekatakana'] = 0x30B1;
  6969. t['kekatakanahalfwidth'] = 0xFF79;
  6970. t['kenarmenian'] = 0x056F;
  6971. t['kesmallkatakana'] = 0x30F6;
  6972. t['kgreenlandic'] = 0x0138;
  6973. t['khabengali'] = 0x0996;
  6974. t['khacyrillic'] = 0x0445;
  6975. t['khadeva'] = 0x0916;
  6976. t['khagujarati'] = 0x0A96;
  6977. t['khagurmukhi'] = 0x0A16;
  6978. t['khaharabic'] = 0x062E;
  6979. t['khahfinalarabic'] = 0xFEA6;
  6980. t['khahinitialarabic'] = 0xFEA7;
  6981. t['khahmedialarabic'] = 0xFEA8;
  6982. t['kheicoptic'] = 0x03E7;
  6983. t['khhadeva'] = 0x0959;
  6984. t['khhagurmukhi'] = 0x0A59;
  6985. t['khieukhacirclekorean'] = 0x3278;
  6986. t['khieukhaparenkorean'] = 0x3218;
  6987. t['khieukhcirclekorean'] = 0x326A;
  6988. t['khieukhkorean'] = 0x314B;
  6989. t['khieukhparenkorean'] = 0x320A;
  6990. t['khokhaithai'] = 0x0E02;
  6991. t['khokhonthai'] = 0x0E05;
  6992. t['khokhuatthai'] = 0x0E03;
  6993. t['khokhwaithai'] = 0x0E04;
  6994. t['khomutthai'] = 0x0E5B;
  6995. t['khook'] = 0x0199;
  6996. t['khorakhangthai'] = 0x0E06;
  6997. t['khzsquare'] = 0x3391;
  6998. t['kihiragana'] = 0x304D;
  6999. t['kikatakana'] = 0x30AD;
  7000. t['kikatakanahalfwidth'] = 0xFF77;
  7001. t['kiroguramusquare'] = 0x3315;
  7002. t['kiromeetorusquare'] = 0x3316;
  7003. t['kirosquare'] = 0x3314;
  7004. t['kiyeokacirclekorean'] = 0x326E;
  7005. t['kiyeokaparenkorean'] = 0x320E;
  7006. t['kiyeokcirclekorean'] = 0x3260;
  7007. t['kiyeokkorean'] = 0x3131;
  7008. t['kiyeokparenkorean'] = 0x3200;
  7009. t['kiyeoksioskorean'] = 0x3133;
  7010. t['kjecyrillic'] = 0x045C;
  7011. t['klinebelow'] = 0x1E35;
  7012. t['klsquare'] = 0x3398;
  7013. t['kmcubedsquare'] = 0x33A6;
  7014. t['kmonospace'] = 0xFF4B;
  7015. t['kmsquaredsquare'] = 0x33A2;
  7016. t['kohiragana'] = 0x3053;
  7017. t['kohmsquare'] = 0x33C0;
  7018. t['kokaithai'] = 0x0E01;
  7019. t['kokatakana'] = 0x30B3;
  7020. t['kokatakanahalfwidth'] = 0xFF7A;
  7021. t['kooposquare'] = 0x331E;
  7022. t['koppacyrillic'] = 0x0481;
  7023. t['koreanstandardsymbol'] = 0x327F;
  7024. t['koroniscmb'] = 0x0343;
  7025. t['kparen'] = 0x24A6;
  7026. t['kpasquare'] = 0x33AA;
  7027. t['ksicyrillic'] = 0x046F;
  7028. t['ktsquare'] = 0x33CF;
  7029. t['kturned'] = 0x029E;
  7030. t['kuhiragana'] = 0x304F;
  7031. t['kukatakana'] = 0x30AF;
  7032. t['kukatakanahalfwidth'] = 0xFF78;
  7033. t['kvsquare'] = 0x33B8;
  7034. t['kwsquare'] = 0x33BE;
  7035. t['l'] = 0x006C;
  7036. t['labengali'] = 0x09B2;
  7037. t['lacute'] = 0x013A;
  7038. t['ladeva'] = 0x0932;
  7039. t['lagujarati'] = 0x0AB2;
  7040. t['lagurmukhi'] = 0x0A32;
  7041. t['lakkhangyaothai'] = 0x0E45;
  7042. t['lamaleffinalarabic'] = 0xFEFC;
  7043. t['lamalefhamzaabovefinalarabic'] = 0xFEF8;
  7044. t['lamalefhamzaaboveisolatedarabic'] = 0xFEF7;
  7045. t['lamalefhamzabelowfinalarabic'] = 0xFEFA;
  7046. t['lamalefhamzabelowisolatedarabic'] = 0xFEF9;
  7047. t['lamalefisolatedarabic'] = 0xFEFB;
  7048. t['lamalefmaddaabovefinalarabic'] = 0xFEF6;
  7049. t['lamalefmaddaaboveisolatedarabic'] = 0xFEF5;
  7050. t['lamarabic'] = 0x0644;
  7051. t['lambda'] = 0x03BB;
  7052. t['lambdastroke'] = 0x019B;
  7053. t['lamed'] = 0x05DC;
  7054. t['lameddagesh'] = 0xFB3C;
  7055. t['lameddageshhebrew'] = 0xFB3C;
  7056. t['lamedhebrew'] = 0x05DC;
  7057. t['lamfinalarabic'] = 0xFEDE;
  7058. t['lamhahinitialarabic'] = 0xFCCA;
  7059. t['laminitialarabic'] = 0xFEDF;
  7060. t['lamjeeminitialarabic'] = 0xFCC9;
  7061. t['lamkhahinitialarabic'] = 0xFCCB;
  7062. t['lamlamhehisolatedarabic'] = 0xFDF2;
  7063. t['lammedialarabic'] = 0xFEE0;
  7064. t['lammeemhahinitialarabic'] = 0xFD88;
  7065. t['lammeeminitialarabic'] = 0xFCCC;
  7066. t['largecircle'] = 0x25EF;
  7067. t['lbar'] = 0x019A;
  7068. t['lbelt'] = 0x026C;
  7069. t['lbopomofo'] = 0x310C;
  7070. t['lcaron'] = 0x013E;
  7071. t['lcedilla'] = 0x013C;
  7072. t['lcircle'] = 0x24DB;
  7073. t['lcircumflexbelow'] = 0x1E3D;
  7074. t['lcommaaccent'] = 0x013C;
  7075. t['ldot'] = 0x0140;
  7076. t['ldotaccent'] = 0x0140;
  7077. t['ldotbelow'] = 0x1E37;
  7078. t['ldotbelowmacron'] = 0x1E39;
  7079. t['leftangleabovecmb'] = 0x031A;
  7080. t['lefttackbelowcmb'] = 0x0318;
  7081. t['less'] = 0x003C;
  7082. t['lessequal'] = 0x2264;
  7083. t['lessequalorgreater'] = 0x22DA;
  7084. t['lessmonospace'] = 0xFF1C;
  7085. t['lessorequivalent'] = 0x2272;
  7086. t['lessorgreater'] = 0x2276;
  7087. t['lessoverequal'] = 0x2266;
  7088. t['lesssmall'] = 0xFE64;
  7089. t['lezh'] = 0x026E;
  7090. t['lfblock'] = 0x258C;
  7091. t['lhookretroflex'] = 0x026D;
  7092. t['lira'] = 0x20A4;
  7093. t['liwnarmenian'] = 0x056C;
  7094. t['lj'] = 0x01C9;
  7095. t['ljecyrillic'] = 0x0459;
  7096. t['ll'] = 0xF6C0;
  7097. t['lladeva'] = 0x0933;
  7098. t['llagujarati'] = 0x0AB3;
  7099. t['llinebelow'] = 0x1E3B;
  7100. t['llladeva'] = 0x0934;
  7101. t['llvocalicbengali'] = 0x09E1;
  7102. t['llvocalicdeva'] = 0x0961;
  7103. t['llvocalicvowelsignbengali'] = 0x09E3;
  7104. t['llvocalicvowelsigndeva'] = 0x0963;
  7105. t['lmiddletilde'] = 0x026B;
  7106. t['lmonospace'] = 0xFF4C;
  7107. t['lmsquare'] = 0x33D0;
  7108. t['lochulathai'] = 0x0E2C;
  7109. t['logicaland'] = 0x2227;
  7110. t['logicalnot'] = 0x00AC;
  7111. t['logicalnotreversed'] = 0x2310;
  7112. t['logicalor'] = 0x2228;
  7113. t['lolingthai'] = 0x0E25;
  7114. t['longs'] = 0x017F;
  7115. t['lowlinecenterline'] = 0xFE4E;
  7116. t['lowlinecmb'] = 0x0332;
  7117. t['lowlinedashed'] = 0xFE4D;
  7118. t['lozenge'] = 0x25CA;
  7119. t['lparen'] = 0x24A7;
  7120. t['lslash'] = 0x0142;
  7121. t['lsquare'] = 0x2113;
  7122. t['lsuperior'] = 0xF6EE;
  7123. t['ltshade'] = 0x2591;
  7124. t['luthai'] = 0x0E26;
  7125. t['lvocalicbengali'] = 0x098C;
  7126. t['lvocalicdeva'] = 0x090C;
  7127. t['lvocalicvowelsignbengali'] = 0x09E2;
  7128. t['lvocalicvowelsigndeva'] = 0x0962;
  7129. t['lxsquare'] = 0x33D3;
  7130. t['m'] = 0x006D;
  7131. t['mabengali'] = 0x09AE;
  7132. t['macron'] = 0x00AF;
  7133. t['macronbelowcmb'] = 0x0331;
  7134. t['macroncmb'] = 0x0304;
  7135. t['macronlowmod'] = 0x02CD;
  7136. t['macronmonospace'] = 0xFFE3;
  7137. t['macute'] = 0x1E3F;
  7138. t['madeva'] = 0x092E;
  7139. t['magujarati'] = 0x0AAE;
  7140. t['magurmukhi'] = 0x0A2E;
  7141. t['mahapakhhebrew'] = 0x05A4;
  7142. t['mahapakhlefthebrew'] = 0x05A4;
  7143. t['mahiragana'] = 0x307E;
  7144. t['maichattawalowleftthai'] = 0xF895;
  7145. t['maichattawalowrightthai'] = 0xF894;
  7146. t['maichattawathai'] = 0x0E4B;
  7147. t['maichattawaupperleftthai'] = 0xF893;
  7148. t['maieklowleftthai'] = 0xF88C;
  7149. t['maieklowrightthai'] = 0xF88B;
  7150. t['maiekthai'] = 0x0E48;
  7151. t['maiekupperleftthai'] = 0xF88A;
  7152. t['maihanakatleftthai'] = 0xF884;
  7153. t['maihanakatthai'] = 0x0E31;
  7154. t['maitaikhuleftthai'] = 0xF889;
  7155. t['maitaikhuthai'] = 0x0E47;
  7156. t['maitholowleftthai'] = 0xF88F;
  7157. t['maitholowrightthai'] = 0xF88E;
  7158. t['maithothai'] = 0x0E49;
  7159. t['maithoupperleftthai'] = 0xF88D;
  7160. t['maitrilowleftthai'] = 0xF892;
  7161. t['maitrilowrightthai'] = 0xF891;
  7162. t['maitrithai'] = 0x0E4A;
  7163. t['maitriupperleftthai'] = 0xF890;
  7164. t['maiyamokthai'] = 0x0E46;
  7165. t['makatakana'] = 0x30DE;
  7166. t['makatakanahalfwidth'] = 0xFF8F;
  7167. t['male'] = 0x2642;
  7168. t['mansyonsquare'] = 0x3347;
  7169. t['maqafhebrew'] = 0x05BE;
  7170. t['mars'] = 0x2642;
  7171. t['masoracirclehebrew'] = 0x05AF;
  7172. t['masquare'] = 0x3383;
  7173. t['mbopomofo'] = 0x3107;
  7174. t['mbsquare'] = 0x33D4;
  7175. t['mcircle'] = 0x24DC;
  7176. t['mcubedsquare'] = 0x33A5;
  7177. t['mdotaccent'] = 0x1E41;
  7178. t['mdotbelow'] = 0x1E43;
  7179. t['meemarabic'] = 0x0645;
  7180. t['meemfinalarabic'] = 0xFEE2;
  7181. t['meeminitialarabic'] = 0xFEE3;
  7182. t['meemmedialarabic'] = 0xFEE4;
  7183. t['meemmeeminitialarabic'] = 0xFCD1;
  7184. t['meemmeemisolatedarabic'] = 0xFC48;
  7185. t['meetorusquare'] = 0x334D;
  7186. t['mehiragana'] = 0x3081;
  7187. t['meizierasquare'] = 0x337E;
  7188. t['mekatakana'] = 0x30E1;
  7189. t['mekatakanahalfwidth'] = 0xFF92;
  7190. t['mem'] = 0x05DE;
  7191. t['memdagesh'] = 0xFB3E;
  7192. t['memdageshhebrew'] = 0xFB3E;
  7193. t['memhebrew'] = 0x05DE;
  7194. t['menarmenian'] = 0x0574;
  7195. t['merkhahebrew'] = 0x05A5;
  7196. t['merkhakefulahebrew'] = 0x05A6;
  7197. t['merkhakefulalefthebrew'] = 0x05A6;
  7198. t['merkhalefthebrew'] = 0x05A5;
  7199. t['mhook'] = 0x0271;
  7200. t['mhzsquare'] = 0x3392;
  7201. t['middledotkatakanahalfwidth'] = 0xFF65;
  7202. t['middot'] = 0x00B7;
  7203. t['mieumacirclekorean'] = 0x3272;
  7204. t['mieumaparenkorean'] = 0x3212;
  7205. t['mieumcirclekorean'] = 0x3264;
  7206. t['mieumkorean'] = 0x3141;
  7207. t['mieumpansioskorean'] = 0x3170;
  7208. t['mieumparenkorean'] = 0x3204;
  7209. t['mieumpieupkorean'] = 0x316E;
  7210. t['mieumsioskorean'] = 0x316F;
  7211. t['mihiragana'] = 0x307F;
  7212. t['mikatakana'] = 0x30DF;
  7213. t['mikatakanahalfwidth'] = 0xFF90;
  7214. t['minus'] = 0x2212;
  7215. t['minusbelowcmb'] = 0x0320;
  7216. t['minuscircle'] = 0x2296;
  7217. t['minusmod'] = 0x02D7;
  7218. t['minusplus'] = 0x2213;
  7219. t['minute'] = 0x2032;
  7220. t['miribaarusquare'] = 0x334A;
  7221. t['mirisquare'] = 0x3349;
  7222. t['mlonglegturned'] = 0x0270;
  7223. t['mlsquare'] = 0x3396;
  7224. t['mmcubedsquare'] = 0x33A3;
  7225. t['mmonospace'] = 0xFF4D;
  7226. t['mmsquaredsquare'] = 0x339F;
  7227. t['mohiragana'] = 0x3082;
  7228. t['mohmsquare'] = 0x33C1;
  7229. t['mokatakana'] = 0x30E2;
  7230. t['mokatakanahalfwidth'] = 0xFF93;
  7231. t['molsquare'] = 0x33D6;
  7232. t['momathai'] = 0x0E21;
  7233. t['moverssquare'] = 0x33A7;
  7234. t['moverssquaredsquare'] = 0x33A8;
  7235. t['mparen'] = 0x24A8;
  7236. t['mpasquare'] = 0x33AB;
  7237. t['mssquare'] = 0x33B3;
  7238. t['msuperior'] = 0xF6EF;
  7239. t['mturned'] = 0x026F;
  7240. t['mu'] = 0x00B5;
  7241. t['mu1'] = 0x00B5;
  7242. t['muasquare'] = 0x3382;
  7243. t['muchgreater'] = 0x226B;
  7244. t['muchless'] = 0x226A;
  7245. t['mufsquare'] = 0x338C;
  7246. t['mugreek'] = 0x03BC;
  7247. t['mugsquare'] = 0x338D;
  7248. t['muhiragana'] = 0x3080;
  7249. t['mukatakana'] = 0x30E0;
  7250. t['mukatakanahalfwidth'] = 0xFF91;
  7251. t['mulsquare'] = 0x3395;
  7252. t['multiply'] = 0x00D7;
  7253. t['mumsquare'] = 0x339B;
  7254. t['munahhebrew'] = 0x05A3;
  7255. t['munahlefthebrew'] = 0x05A3;
  7256. t['musicalnote'] = 0x266A;
  7257. t['musicalnotedbl'] = 0x266B;
  7258. t['musicflatsign'] = 0x266D;
  7259. t['musicsharpsign'] = 0x266F;
  7260. t['mussquare'] = 0x33B2;
  7261. t['muvsquare'] = 0x33B6;
  7262. t['muwsquare'] = 0x33BC;
  7263. t['mvmegasquare'] = 0x33B9;
  7264. t['mvsquare'] = 0x33B7;
  7265. t['mwmegasquare'] = 0x33BF;
  7266. t['mwsquare'] = 0x33BD;
  7267. t['n'] = 0x006E;
  7268. t['nabengali'] = 0x09A8;
  7269. t['nabla'] = 0x2207;
  7270. t['nacute'] = 0x0144;
  7271. t['nadeva'] = 0x0928;
  7272. t['nagujarati'] = 0x0AA8;
  7273. t['nagurmukhi'] = 0x0A28;
  7274. t['nahiragana'] = 0x306A;
  7275. t['nakatakana'] = 0x30CA;
  7276. t['nakatakanahalfwidth'] = 0xFF85;
  7277. t['napostrophe'] = 0x0149;
  7278. t['nasquare'] = 0x3381;
  7279. t['nbopomofo'] = 0x310B;
  7280. t['nbspace'] = 0x00A0;
  7281. t['ncaron'] = 0x0148;
  7282. t['ncedilla'] = 0x0146;
  7283. t['ncircle'] = 0x24DD;
  7284. t['ncircumflexbelow'] = 0x1E4B;
  7285. t['ncommaaccent'] = 0x0146;
  7286. t['ndotaccent'] = 0x1E45;
  7287. t['ndotbelow'] = 0x1E47;
  7288. t['nehiragana'] = 0x306D;
  7289. t['nekatakana'] = 0x30CD;
  7290. t['nekatakanahalfwidth'] = 0xFF88;
  7291. t['newsheqelsign'] = 0x20AA;
  7292. t['nfsquare'] = 0x338B;
  7293. t['ngabengali'] = 0x0999;
  7294. t['ngadeva'] = 0x0919;
  7295. t['ngagujarati'] = 0x0A99;
  7296. t['ngagurmukhi'] = 0x0A19;
  7297. t['ngonguthai'] = 0x0E07;
  7298. t['nhiragana'] = 0x3093;
  7299. t['nhookleft'] = 0x0272;
  7300. t['nhookretroflex'] = 0x0273;
  7301. t['nieunacirclekorean'] = 0x326F;
  7302. t['nieunaparenkorean'] = 0x320F;
  7303. t['nieuncieuckorean'] = 0x3135;
  7304. t['nieuncirclekorean'] = 0x3261;
  7305. t['nieunhieuhkorean'] = 0x3136;
  7306. t['nieunkorean'] = 0x3134;
  7307. t['nieunpansioskorean'] = 0x3168;
  7308. t['nieunparenkorean'] = 0x3201;
  7309. t['nieunsioskorean'] = 0x3167;
  7310. t['nieuntikeutkorean'] = 0x3166;
  7311. t['nihiragana'] = 0x306B;
  7312. t['nikatakana'] = 0x30CB;
  7313. t['nikatakanahalfwidth'] = 0xFF86;
  7314. t['nikhahitleftthai'] = 0xF899;
  7315. t['nikhahitthai'] = 0x0E4D;
  7316. t['nine'] = 0x0039;
  7317. t['ninearabic'] = 0x0669;
  7318. t['ninebengali'] = 0x09EF;
  7319. t['ninecircle'] = 0x2468;
  7320. t['ninecircleinversesansserif'] = 0x2792;
  7321. t['ninedeva'] = 0x096F;
  7322. t['ninegujarati'] = 0x0AEF;
  7323. t['ninegurmukhi'] = 0x0A6F;
  7324. t['ninehackarabic'] = 0x0669;
  7325. t['ninehangzhou'] = 0x3029;
  7326. t['nineideographicparen'] = 0x3228;
  7327. t['nineinferior'] = 0x2089;
  7328. t['ninemonospace'] = 0xFF19;
  7329. t['nineoldstyle'] = 0xF739;
  7330. t['nineparen'] = 0x247C;
  7331. t['nineperiod'] = 0x2490;
  7332. t['ninepersian'] = 0x06F9;
  7333. t['nineroman'] = 0x2178;
  7334. t['ninesuperior'] = 0x2079;
  7335. t['nineteencircle'] = 0x2472;
  7336. t['nineteenparen'] = 0x2486;
  7337. t['nineteenperiod'] = 0x249A;
  7338. t['ninethai'] = 0x0E59;
  7339. t['nj'] = 0x01CC;
  7340. t['njecyrillic'] = 0x045A;
  7341. t['nkatakana'] = 0x30F3;
  7342. t['nkatakanahalfwidth'] = 0xFF9D;
  7343. t['nlegrightlong'] = 0x019E;
  7344. t['nlinebelow'] = 0x1E49;
  7345. t['nmonospace'] = 0xFF4E;
  7346. t['nmsquare'] = 0x339A;
  7347. t['nnabengali'] = 0x09A3;
  7348. t['nnadeva'] = 0x0923;
  7349. t['nnagujarati'] = 0x0AA3;
  7350. t['nnagurmukhi'] = 0x0A23;
  7351. t['nnnadeva'] = 0x0929;
  7352. t['nohiragana'] = 0x306E;
  7353. t['nokatakana'] = 0x30CE;
  7354. t['nokatakanahalfwidth'] = 0xFF89;
  7355. t['nonbreakingspace'] = 0x00A0;
  7356. t['nonenthai'] = 0x0E13;
  7357. t['nonuthai'] = 0x0E19;
  7358. t['noonarabic'] = 0x0646;
  7359. t['noonfinalarabic'] = 0xFEE6;
  7360. t['noonghunnaarabic'] = 0x06BA;
  7361. t['noonghunnafinalarabic'] = 0xFB9F;
  7362. t['nooninitialarabic'] = 0xFEE7;
  7363. t['noonjeeminitialarabic'] = 0xFCD2;
  7364. t['noonjeemisolatedarabic'] = 0xFC4B;
  7365. t['noonmedialarabic'] = 0xFEE8;
  7366. t['noonmeeminitialarabic'] = 0xFCD5;
  7367. t['noonmeemisolatedarabic'] = 0xFC4E;
  7368. t['noonnoonfinalarabic'] = 0xFC8D;
  7369. t['notcontains'] = 0x220C;
  7370. t['notelement'] = 0x2209;
  7371. t['notelementof'] = 0x2209;
  7372. t['notequal'] = 0x2260;
  7373. t['notgreater'] = 0x226F;
  7374. t['notgreaternorequal'] = 0x2271;
  7375. t['notgreaternorless'] = 0x2279;
  7376. t['notidentical'] = 0x2262;
  7377. t['notless'] = 0x226E;
  7378. t['notlessnorequal'] = 0x2270;
  7379. t['notparallel'] = 0x2226;
  7380. t['notprecedes'] = 0x2280;
  7381. t['notsubset'] = 0x2284;
  7382. t['notsucceeds'] = 0x2281;
  7383. t['notsuperset'] = 0x2285;
  7384. t['nowarmenian'] = 0x0576;
  7385. t['nparen'] = 0x24A9;
  7386. t['nssquare'] = 0x33B1;
  7387. t['nsuperior'] = 0x207F;
  7388. t['ntilde'] = 0x00F1;
  7389. t['nu'] = 0x03BD;
  7390. t['nuhiragana'] = 0x306C;
  7391. t['nukatakana'] = 0x30CC;
  7392. t['nukatakanahalfwidth'] = 0xFF87;
  7393. t['nuktabengali'] = 0x09BC;
  7394. t['nuktadeva'] = 0x093C;
  7395. t['nuktagujarati'] = 0x0ABC;
  7396. t['nuktagurmukhi'] = 0x0A3C;
  7397. t['numbersign'] = 0x0023;
  7398. t['numbersignmonospace'] = 0xFF03;
  7399. t['numbersignsmall'] = 0xFE5F;
  7400. t['numeralsigngreek'] = 0x0374;
  7401. t['numeralsignlowergreek'] = 0x0375;
  7402. t['numero'] = 0x2116;
  7403. t['nun'] = 0x05E0;
  7404. t['nundagesh'] = 0xFB40;
  7405. t['nundageshhebrew'] = 0xFB40;
  7406. t['nunhebrew'] = 0x05E0;
  7407. t['nvsquare'] = 0x33B5;
  7408. t['nwsquare'] = 0x33BB;
  7409. t['nyabengali'] = 0x099E;
  7410. t['nyadeva'] = 0x091E;
  7411. t['nyagujarati'] = 0x0A9E;
  7412. t['nyagurmukhi'] = 0x0A1E;
  7413. t['o'] = 0x006F;
  7414. t['oacute'] = 0x00F3;
  7415. t['oangthai'] = 0x0E2D;
  7416. t['obarred'] = 0x0275;
  7417. t['obarredcyrillic'] = 0x04E9;
  7418. t['obarreddieresiscyrillic'] = 0x04EB;
  7419. t['obengali'] = 0x0993;
  7420. t['obopomofo'] = 0x311B;
  7421. t['obreve'] = 0x014F;
  7422. t['ocandradeva'] = 0x0911;
  7423. t['ocandragujarati'] = 0x0A91;
  7424. t['ocandravowelsigndeva'] = 0x0949;
  7425. t['ocandravowelsigngujarati'] = 0x0AC9;
  7426. t['ocaron'] = 0x01D2;
  7427. t['ocircle'] = 0x24DE;
  7428. t['ocircumflex'] = 0x00F4;
  7429. t['ocircumflexacute'] = 0x1ED1;
  7430. t['ocircumflexdotbelow'] = 0x1ED9;
  7431. t['ocircumflexgrave'] = 0x1ED3;
  7432. t['ocircumflexhookabove'] = 0x1ED5;
  7433. t['ocircumflextilde'] = 0x1ED7;
  7434. t['ocyrillic'] = 0x043E;
  7435. t['odblacute'] = 0x0151;
  7436. t['odblgrave'] = 0x020D;
  7437. t['odeva'] = 0x0913;
  7438. t['odieresis'] = 0x00F6;
  7439. t['odieresiscyrillic'] = 0x04E7;
  7440. t['odotbelow'] = 0x1ECD;
  7441. t['oe'] = 0x0153;
  7442. t['oekorean'] = 0x315A;
  7443. t['ogonek'] = 0x02DB;
  7444. t['ogonekcmb'] = 0x0328;
  7445. t['ograve'] = 0x00F2;
  7446. t['ogujarati'] = 0x0A93;
  7447. t['oharmenian'] = 0x0585;
  7448. t['ohiragana'] = 0x304A;
  7449. t['ohookabove'] = 0x1ECF;
  7450. t['ohorn'] = 0x01A1;
  7451. t['ohornacute'] = 0x1EDB;
  7452. t['ohorndotbelow'] = 0x1EE3;
  7453. t['ohorngrave'] = 0x1EDD;
  7454. t['ohornhookabove'] = 0x1EDF;
  7455. t['ohorntilde'] = 0x1EE1;
  7456. t['ohungarumlaut'] = 0x0151;
  7457. t['oi'] = 0x01A3;
  7458. t['oinvertedbreve'] = 0x020F;
  7459. t['okatakana'] = 0x30AA;
  7460. t['okatakanahalfwidth'] = 0xFF75;
  7461. t['okorean'] = 0x3157;
  7462. t['olehebrew'] = 0x05AB;
  7463. t['omacron'] = 0x014D;
  7464. t['omacronacute'] = 0x1E53;
  7465. t['omacrongrave'] = 0x1E51;
  7466. t['omdeva'] = 0x0950;
  7467. t['omega'] = 0x03C9;
  7468. t['omega1'] = 0x03D6;
  7469. t['omegacyrillic'] = 0x0461;
  7470. t['omegalatinclosed'] = 0x0277;
  7471. t['omegaroundcyrillic'] = 0x047B;
  7472. t['omegatitlocyrillic'] = 0x047D;
  7473. t['omegatonos'] = 0x03CE;
  7474. t['omgujarati'] = 0x0AD0;
  7475. t['omicron'] = 0x03BF;
  7476. t['omicrontonos'] = 0x03CC;
  7477. t['omonospace'] = 0xFF4F;
  7478. t['one'] = 0x0031;
  7479. t['onearabic'] = 0x0661;
  7480. t['onebengali'] = 0x09E7;
  7481. t['onecircle'] = 0x2460;
  7482. t['onecircleinversesansserif'] = 0x278A;
  7483. t['onedeva'] = 0x0967;
  7484. t['onedotenleader'] = 0x2024;
  7485. t['oneeighth'] = 0x215B;
  7486. t['onefitted'] = 0xF6DC;
  7487. t['onegujarati'] = 0x0AE7;
  7488. t['onegurmukhi'] = 0x0A67;
  7489. t['onehackarabic'] = 0x0661;
  7490. t['onehalf'] = 0x00BD;
  7491. t['onehangzhou'] = 0x3021;
  7492. t['oneideographicparen'] = 0x3220;
  7493. t['oneinferior'] = 0x2081;
  7494. t['onemonospace'] = 0xFF11;
  7495. t['onenumeratorbengali'] = 0x09F4;
  7496. t['oneoldstyle'] = 0xF731;
  7497. t['oneparen'] = 0x2474;
  7498. t['oneperiod'] = 0x2488;
  7499. t['onepersian'] = 0x06F1;
  7500. t['onequarter'] = 0x00BC;
  7501. t['oneroman'] = 0x2170;
  7502. t['onesuperior'] = 0x00B9;
  7503. t['onethai'] = 0x0E51;
  7504. t['onethird'] = 0x2153;
  7505. t['oogonek'] = 0x01EB;
  7506. t['oogonekmacron'] = 0x01ED;
  7507. t['oogurmukhi'] = 0x0A13;
  7508. t['oomatragurmukhi'] = 0x0A4B;
  7509. t['oopen'] = 0x0254;
  7510. t['oparen'] = 0x24AA;
  7511. t['openbullet'] = 0x25E6;
  7512. t['option'] = 0x2325;
  7513. t['ordfeminine'] = 0x00AA;
  7514. t['ordmasculine'] = 0x00BA;
  7515. t['orthogonal'] = 0x221F;
  7516. t['oshortdeva'] = 0x0912;
  7517. t['oshortvowelsigndeva'] = 0x094A;
  7518. t['oslash'] = 0x00F8;
  7519. t['oslashacute'] = 0x01FF;
  7520. t['osmallhiragana'] = 0x3049;
  7521. t['osmallkatakana'] = 0x30A9;
  7522. t['osmallkatakanahalfwidth'] = 0xFF6B;
  7523. t['ostrokeacute'] = 0x01FF;
  7524. t['osuperior'] = 0xF6F0;
  7525. t['otcyrillic'] = 0x047F;
  7526. t['otilde'] = 0x00F5;
  7527. t['otildeacute'] = 0x1E4D;
  7528. t['otildedieresis'] = 0x1E4F;
  7529. t['oubopomofo'] = 0x3121;
  7530. t['overline'] = 0x203E;
  7531. t['overlinecenterline'] = 0xFE4A;
  7532. t['overlinecmb'] = 0x0305;
  7533. t['overlinedashed'] = 0xFE49;
  7534. t['overlinedblwavy'] = 0xFE4C;
  7535. t['overlinewavy'] = 0xFE4B;
  7536. t['overscore'] = 0x00AF;
  7537. t['ovowelsignbengali'] = 0x09CB;
  7538. t['ovowelsigndeva'] = 0x094B;
  7539. t['ovowelsigngujarati'] = 0x0ACB;
  7540. t['p'] = 0x0070;
  7541. t['paampssquare'] = 0x3380;
  7542. t['paasentosquare'] = 0x332B;
  7543. t['pabengali'] = 0x09AA;
  7544. t['pacute'] = 0x1E55;
  7545. t['padeva'] = 0x092A;
  7546. t['pagedown'] = 0x21DF;
  7547. t['pageup'] = 0x21DE;
  7548. t['pagujarati'] = 0x0AAA;
  7549. t['pagurmukhi'] = 0x0A2A;
  7550. t['pahiragana'] = 0x3071;
  7551. t['paiyannoithai'] = 0x0E2F;
  7552. t['pakatakana'] = 0x30D1;
  7553. t['palatalizationcyrilliccmb'] = 0x0484;
  7554. t['palochkacyrillic'] = 0x04C0;
  7555. t['pansioskorean'] = 0x317F;
  7556. t['paragraph'] = 0x00B6;
  7557. t['parallel'] = 0x2225;
  7558. t['parenleft'] = 0x0028;
  7559. t['parenleftaltonearabic'] = 0xFD3E;
  7560. t['parenleftbt'] = 0xF8ED;
  7561. t['parenleftex'] = 0xF8EC;
  7562. t['parenleftinferior'] = 0x208D;
  7563. t['parenleftmonospace'] = 0xFF08;
  7564. t['parenleftsmall'] = 0xFE59;
  7565. t['parenleftsuperior'] = 0x207D;
  7566. t['parenlefttp'] = 0xF8EB;
  7567. t['parenleftvertical'] = 0xFE35;
  7568. t['parenright'] = 0x0029;
  7569. t['parenrightaltonearabic'] = 0xFD3F;
  7570. t['parenrightbt'] = 0xF8F8;
  7571. t['parenrightex'] = 0xF8F7;
  7572. t['parenrightinferior'] = 0x208E;
  7573. t['parenrightmonospace'] = 0xFF09;
  7574. t['parenrightsmall'] = 0xFE5A;
  7575. t['parenrightsuperior'] = 0x207E;
  7576. t['parenrighttp'] = 0xF8F6;
  7577. t['parenrightvertical'] = 0xFE36;
  7578. t['partialdiff'] = 0x2202;
  7579. t['paseqhebrew'] = 0x05C0;
  7580. t['pashtahebrew'] = 0x0599;
  7581. t['pasquare'] = 0x33A9;
  7582. t['patah'] = 0x05B7;
  7583. t['patah11'] = 0x05B7;
  7584. t['patah1d'] = 0x05B7;
  7585. t['patah2a'] = 0x05B7;
  7586. t['patahhebrew'] = 0x05B7;
  7587. t['patahnarrowhebrew'] = 0x05B7;
  7588. t['patahquarterhebrew'] = 0x05B7;
  7589. t['patahwidehebrew'] = 0x05B7;
  7590. t['pazerhebrew'] = 0x05A1;
  7591. t['pbopomofo'] = 0x3106;
  7592. t['pcircle'] = 0x24DF;
  7593. t['pdotaccent'] = 0x1E57;
  7594. t['pe'] = 0x05E4;
  7595. t['pecyrillic'] = 0x043F;
  7596. t['pedagesh'] = 0xFB44;
  7597. t['pedageshhebrew'] = 0xFB44;
  7598. t['peezisquare'] = 0x333B;
  7599. t['pefinaldageshhebrew'] = 0xFB43;
  7600. t['peharabic'] = 0x067E;
  7601. t['peharmenian'] = 0x057A;
  7602. t['pehebrew'] = 0x05E4;
  7603. t['pehfinalarabic'] = 0xFB57;
  7604. t['pehinitialarabic'] = 0xFB58;
  7605. t['pehiragana'] = 0x307A;
  7606. t['pehmedialarabic'] = 0xFB59;
  7607. t['pekatakana'] = 0x30DA;
  7608. t['pemiddlehookcyrillic'] = 0x04A7;
  7609. t['perafehebrew'] = 0xFB4E;
  7610. t['percent'] = 0x0025;
  7611. t['percentarabic'] = 0x066A;
  7612. t['percentmonospace'] = 0xFF05;
  7613. t['percentsmall'] = 0xFE6A;
  7614. t['period'] = 0x002E;
  7615. t['periodarmenian'] = 0x0589;
  7616. t['periodcentered'] = 0x00B7;
  7617. t['periodhalfwidth'] = 0xFF61;
  7618. t['periodinferior'] = 0xF6E7;
  7619. t['periodmonospace'] = 0xFF0E;
  7620. t['periodsmall'] = 0xFE52;
  7621. t['periodsuperior'] = 0xF6E8;
  7622. t['perispomenigreekcmb'] = 0x0342;
  7623. t['perpendicular'] = 0x22A5;
  7624. t['perthousand'] = 0x2030;
  7625. t['peseta'] = 0x20A7;
  7626. t['pfsquare'] = 0x338A;
  7627. t['phabengali'] = 0x09AB;
  7628. t['phadeva'] = 0x092B;
  7629. t['phagujarati'] = 0x0AAB;
  7630. t['phagurmukhi'] = 0x0A2B;
  7631. t['phi'] = 0x03C6;
  7632. t['phi1'] = 0x03D5;
  7633. t['phieuphacirclekorean'] = 0x327A;
  7634. t['phieuphaparenkorean'] = 0x321A;
  7635. t['phieuphcirclekorean'] = 0x326C;
  7636. t['phieuphkorean'] = 0x314D;
  7637. t['phieuphparenkorean'] = 0x320C;
  7638. t['philatin'] = 0x0278;
  7639. t['phinthuthai'] = 0x0E3A;
  7640. t['phisymbolgreek'] = 0x03D5;
  7641. t['phook'] = 0x01A5;
  7642. t['phophanthai'] = 0x0E1E;
  7643. t['phophungthai'] = 0x0E1C;
  7644. t['phosamphaothai'] = 0x0E20;
  7645. t['pi'] = 0x03C0;
  7646. t['pieupacirclekorean'] = 0x3273;
  7647. t['pieupaparenkorean'] = 0x3213;
  7648. t['pieupcieuckorean'] = 0x3176;
  7649. t['pieupcirclekorean'] = 0x3265;
  7650. t['pieupkiyeokkorean'] = 0x3172;
  7651. t['pieupkorean'] = 0x3142;
  7652. t['pieupparenkorean'] = 0x3205;
  7653. t['pieupsioskiyeokkorean'] = 0x3174;
  7654. t['pieupsioskorean'] = 0x3144;
  7655. t['pieupsiostikeutkorean'] = 0x3175;
  7656. t['pieupthieuthkorean'] = 0x3177;
  7657. t['pieuptikeutkorean'] = 0x3173;
  7658. t['pihiragana'] = 0x3074;
  7659. t['pikatakana'] = 0x30D4;
  7660. t['pisymbolgreek'] = 0x03D6;
  7661. t['piwrarmenian'] = 0x0583;
  7662. t['plus'] = 0x002B;
  7663. t['plusbelowcmb'] = 0x031F;
  7664. t['pluscircle'] = 0x2295;
  7665. t['plusminus'] = 0x00B1;
  7666. t['plusmod'] = 0x02D6;
  7667. t['plusmonospace'] = 0xFF0B;
  7668. t['plussmall'] = 0xFE62;
  7669. t['plussuperior'] = 0x207A;
  7670. t['pmonospace'] = 0xFF50;
  7671. t['pmsquare'] = 0x33D8;
  7672. t['pohiragana'] = 0x307D;
  7673. t['pointingindexdownwhite'] = 0x261F;
  7674. t['pointingindexleftwhite'] = 0x261C;
  7675. t['pointingindexrightwhite'] = 0x261E;
  7676. t['pointingindexupwhite'] = 0x261D;
  7677. t['pokatakana'] = 0x30DD;
  7678. t['poplathai'] = 0x0E1B;
  7679. t['postalmark'] = 0x3012;
  7680. t['postalmarkface'] = 0x3020;
  7681. t['pparen'] = 0x24AB;
  7682. t['precedes'] = 0x227A;
  7683. t['prescription'] = 0x211E;
  7684. t['primemod'] = 0x02B9;
  7685. t['primereversed'] = 0x2035;
  7686. t['product'] = 0x220F;
  7687. t['projective'] = 0x2305;
  7688. t['prolongedkana'] = 0x30FC;
  7689. t['propellor'] = 0x2318;
  7690. t['propersubset'] = 0x2282;
  7691. t['propersuperset'] = 0x2283;
  7692. t['proportion'] = 0x2237;
  7693. t['proportional'] = 0x221D;
  7694. t['psi'] = 0x03C8;
  7695. t['psicyrillic'] = 0x0471;
  7696. t['psilipneumatacyrilliccmb'] = 0x0486;
  7697. t['pssquare'] = 0x33B0;
  7698. t['puhiragana'] = 0x3077;
  7699. t['pukatakana'] = 0x30D7;
  7700. t['pvsquare'] = 0x33B4;
  7701. t['pwsquare'] = 0x33BA;
  7702. t['q'] = 0x0071;
  7703. t['qadeva'] = 0x0958;
  7704. t['qadmahebrew'] = 0x05A8;
  7705. t['qafarabic'] = 0x0642;
  7706. t['qaffinalarabic'] = 0xFED6;
  7707. t['qafinitialarabic'] = 0xFED7;
  7708. t['qafmedialarabic'] = 0xFED8;
  7709. t['qamats'] = 0x05B8;
  7710. t['qamats10'] = 0x05B8;
  7711. t['qamats1a'] = 0x05B8;
  7712. t['qamats1c'] = 0x05B8;
  7713. t['qamats27'] = 0x05B8;
  7714. t['qamats29'] = 0x05B8;
  7715. t['qamats33'] = 0x05B8;
  7716. t['qamatsde'] = 0x05B8;
  7717. t['qamatshebrew'] = 0x05B8;
  7718. t['qamatsnarrowhebrew'] = 0x05B8;
  7719. t['qamatsqatanhebrew'] = 0x05B8;
  7720. t['qamatsqatannarrowhebrew'] = 0x05B8;
  7721. t['qamatsqatanquarterhebrew'] = 0x05B8;
  7722. t['qamatsqatanwidehebrew'] = 0x05B8;
  7723. t['qamatsquarterhebrew'] = 0x05B8;
  7724. t['qamatswidehebrew'] = 0x05B8;
  7725. t['qarneyparahebrew'] = 0x059F;
  7726. t['qbopomofo'] = 0x3111;
  7727. t['qcircle'] = 0x24E0;
  7728. t['qhook'] = 0x02A0;
  7729. t['qmonospace'] = 0xFF51;
  7730. t['qof'] = 0x05E7;
  7731. t['qofdagesh'] = 0xFB47;
  7732. t['qofdageshhebrew'] = 0xFB47;
  7733. t['qofhebrew'] = 0x05E7;
  7734. t['qparen'] = 0x24AC;
  7735. t['quarternote'] = 0x2669;
  7736. t['qubuts'] = 0x05BB;
  7737. t['qubuts18'] = 0x05BB;
  7738. t['qubuts25'] = 0x05BB;
  7739. t['qubuts31'] = 0x05BB;
  7740. t['qubutshebrew'] = 0x05BB;
  7741. t['qubutsnarrowhebrew'] = 0x05BB;
  7742. t['qubutsquarterhebrew'] = 0x05BB;
  7743. t['qubutswidehebrew'] = 0x05BB;
  7744. t['question'] = 0x003F;
  7745. t['questionarabic'] = 0x061F;
  7746. t['questionarmenian'] = 0x055E;
  7747. t['questiondown'] = 0x00BF;
  7748. t['questiondownsmall'] = 0xF7BF;
  7749. t['questiongreek'] = 0x037E;
  7750. t['questionmonospace'] = 0xFF1F;
  7751. t['questionsmall'] = 0xF73F;
  7752. t['quotedbl'] = 0x0022;
  7753. t['quotedblbase'] = 0x201E;
  7754. t['quotedblleft'] = 0x201C;
  7755. t['quotedblmonospace'] = 0xFF02;
  7756. t['quotedblprime'] = 0x301E;
  7757. t['quotedblprimereversed'] = 0x301D;
  7758. t['quotedblright'] = 0x201D;
  7759. t['quoteleft'] = 0x2018;
  7760. t['quoteleftreversed'] = 0x201B;
  7761. t['quotereversed'] = 0x201B;
  7762. t['quoteright'] = 0x2019;
  7763. t['quoterightn'] = 0x0149;
  7764. t['quotesinglbase'] = 0x201A;
  7765. t['quotesingle'] = 0x0027;
  7766. t['quotesinglemonospace'] = 0xFF07;
  7767. t['r'] = 0x0072;
  7768. t['raarmenian'] = 0x057C;
  7769. t['rabengali'] = 0x09B0;
  7770. t['racute'] = 0x0155;
  7771. t['radeva'] = 0x0930;
  7772. t['radical'] = 0x221A;
  7773. t['radicalex'] = 0xF8E5;
  7774. t['radoverssquare'] = 0x33AE;
  7775. t['radoverssquaredsquare'] = 0x33AF;
  7776. t['radsquare'] = 0x33AD;
  7777. t['rafe'] = 0x05BF;
  7778. t['rafehebrew'] = 0x05BF;
  7779. t['ragujarati'] = 0x0AB0;
  7780. t['ragurmukhi'] = 0x0A30;
  7781. t['rahiragana'] = 0x3089;
  7782. t['rakatakana'] = 0x30E9;
  7783. t['rakatakanahalfwidth'] = 0xFF97;
  7784. t['ralowerdiagonalbengali'] = 0x09F1;
  7785. t['ramiddlediagonalbengali'] = 0x09F0;
  7786. t['ramshorn'] = 0x0264;
  7787. t['ratio'] = 0x2236;
  7788. t['rbopomofo'] = 0x3116;
  7789. t['rcaron'] = 0x0159;
  7790. t['rcedilla'] = 0x0157;
  7791. t['rcircle'] = 0x24E1;
  7792. t['rcommaaccent'] = 0x0157;
  7793. t['rdblgrave'] = 0x0211;
  7794. t['rdotaccent'] = 0x1E59;
  7795. t['rdotbelow'] = 0x1E5B;
  7796. t['rdotbelowmacron'] = 0x1E5D;
  7797. t['referencemark'] = 0x203B;
  7798. t['reflexsubset'] = 0x2286;
  7799. t['reflexsuperset'] = 0x2287;
  7800. t['registered'] = 0x00AE;
  7801. t['registersans'] = 0xF8E8;
  7802. t['registerserif'] = 0xF6DA;
  7803. t['reharabic'] = 0x0631;
  7804. t['reharmenian'] = 0x0580;
  7805. t['rehfinalarabic'] = 0xFEAE;
  7806. t['rehiragana'] = 0x308C;
  7807. t['rekatakana'] = 0x30EC;
  7808. t['rekatakanahalfwidth'] = 0xFF9A;
  7809. t['resh'] = 0x05E8;
  7810. t['reshdageshhebrew'] = 0xFB48;
  7811. t['reshhebrew'] = 0x05E8;
  7812. t['reversedtilde'] = 0x223D;
  7813. t['reviahebrew'] = 0x0597;
  7814. t['reviamugrashhebrew'] = 0x0597;
  7815. t['revlogicalnot'] = 0x2310;
  7816. t['rfishhook'] = 0x027E;
  7817. t['rfishhookreversed'] = 0x027F;
  7818. t['rhabengali'] = 0x09DD;
  7819. t['rhadeva'] = 0x095D;
  7820. t['rho'] = 0x03C1;
  7821. t['rhook'] = 0x027D;
  7822. t['rhookturned'] = 0x027B;
  7823. t['rhookturnedsuperior'] = 0x02B5;
  7824. t['rhosymbolgreek'] = 0x03F1;
  7825. t['rhotichookmod'] = 0x02DE;
  7826. t['rieulacirclekorean'] = 0x3271;
  7827. t['rieulaparenkorean'] = 0x3211;
  7828. t['rieulcirclekorean'] = 0x3263;
  7829. t['rieulhieuhkorean'] = 0x3140;
  7830. t['rieulkiyeokkorean'] = 0x313A;
  7831. t['rieulkiyeoksioskorean'] = 0x3169;
  7832. t['rieulkorean'] = 0x3139;
  7833. t['rieulmieumkorean'] = 0x313B;
  7834. t['rieulpansioskorean'] = 0x316C;
  7835. t['rieulparenkorean'] = 0x3203;
  7836. t['rieulphieuphkorean'] = 0x313F;
  7837. t['rieulpieupkorean'] = 0x313C;
  7838. t['rieulpieupsioskorean'] = 0x316B;
  7839. t['rieulsioskorean'] = 0x313D;
  7840. t['rieulthieuthkorean'] = 0x313E;
  7841. t['rieultikeutkorean'] = 0x316A;
  7842. t['rieulyeorinhieuhkorean'] = 0x316D;
  7843. t['rightangle'] = 0x221F;
  7844. t['righttackbelowcmb'] = 0x0319;
  7845. t['righttriangle'] = 0x22BF;
  7846. t['rihiragana'] = 0x308A;
  7847. t['rikatakana'] = 0x30EA;
  7848. t['rikatakanahalfwidth'] = 0xFF98;
  7849. t['ring'] = 0x02DA;
  7850. t['ringbelowcmb'] = 0x0325;
  7851. t['ringcmb'] = 0x030A;
  7852. t['ringhalfleft'] = 0x02BF;
  7853. t['ringhalfleftarmenian'] = 0x0559;
  7854. t['ringhalfleftbelowcmb'] = 0x031C;
  7855. t['ringhalfleftcentered'] = 0x02D3;
  7856. t['ringhalfright'] = 0x02BE;
  7857. t['ringhalfrightbelowcmb'] = 0x0339;
  7858. t['ringhalfrightcentered'] = 0x02D2;
  7859. t['rinvertedbreve'] = 0x0213;
  7860. t['rittorusquare'] = 0x3351;
  7861. t['rlinebelow'] = 0x1E5F;
  7862. t['rlongleg'] = 0x027C;
  7863. t['rlonglegturned'] = 0x027A;
  7864. t['rmonospace'] = 0xFF52;
  7865. t['rohiragana'] = 0x308D;
  7866. t['rokatakana'] = 0x30ED;
  7867. t['rokatakanahalfwidth'] = 0xFF9B;
  7868. t['roruathai'] = 0x0E23;
  7869. t['rparen'] = 0x24AD;
  7870. t['rrabengali'] = 0x09DC;
  7871. t['rradeva'] = 0x0931;
  7872. t['rragurmukhi'] = 0x0A5C;
  7873. t['rreharabic'] = 0x0691;
  7874. t['rrehfinalarabic'] = 0xFB8D;
  7875. t['rrvocalicbengali'] = 0x09E0;
  7876. t['rrvocalicdeva'] = 0x0960;
  7877. t['rrvocalicgujarati'] = 0x0AE0;
  7878. t['rrvocalicvowelsignbengali'] = 0x09C4;
  7879. t['rrvocalicvowelsigndeva'] = 0x0944;
  7880. t['rrvocalicvowelsigngujarati'] = 0x0AC4;
  7881. t['rsuperior'] = 0xF6F1;
  7882. t['rtblock'] = 0x2590;
  7883. t['rturned'] = 0x0279;
  7884. t['rturnedsuperior'] = 0x02B4;
  7885. t['ruhiragana'] = 0x308B;
  7886. t['rukatakana'] = 0x30EB;
  7887. t['rukatakanahalfwidth'] = 0xFF99;
  7888. t['rupeemarkbengali'] = 0x09F2;
  7889. t['rupeesignbengali'] = 0x09F3;
  7890. t['rupiah'] = 0xF6DD;
  7891. t['ruthai'] = 0x0E24;
  7892. t['rvocalicbengali'] = 0x098B;
  7893. t['rvocalicdeva'] = 0x090B;
  7894. t['rvocalicgujarati'] = 0x0A8B;
  7895. t['rvocalicvowelsignbengali'] = 0x09C3;
  7896. t['rvocalicvowelsigndeva'] = 0x0943;
  7897. t['rvocalicvowelsigngujarati'] = 0x0AC3;
  7898. t['s'] = 0x0073;
  7899. t['sabengali'] = 0x09B8;
  7900. t['sacute'] = 0x015B;
  7901. t['sacutedotaccent'] = 0x1E65;
  7902. t['sadarabic'] = 0x0635;
  7903. t['sadeva'] = 0x0938;
  7904. t['sadfinalarabic'] = 0xFEBA;
  7905. t['sadinitialarabic'] = 0xFEBB;
  7906. t['sadmedialarabic'] = 0xFEBC;
  7907. t['sagujarati'] = 0x0AB8;
  7908. t['sagurmukhi'] = 0x0A38;
  7909. t['sahiragana'] = 0x3055;
  7910. t['sakatakana'] = 0x30B5;
  7911. t['sakatakanahalfwidth'] = 0xFF7B;
  7912. t['sallallahoualayhewasallamarabic'] = 0xFDFA;
  7913. t['samekh'] = 0x05E1;
  7914. t['samekhdagesh'] = 0xFB41;
  7915. t['samekhdageshhebrew'] = 0xFB41;
  7916. t['samekhhebrew'] = 0x05E1;
  7917. t['saraaathai'] = 0x0E32;
  7918. t['saraaethai'] = 0x0E41;
  7919. t['saraaimaimalaithai'] = 0x0E44;
  7920. t['saraaimaimuanthai'] = 0x0E43;
  7921. t['saraamthai'] = 0x0E33;
  7922. t['saraathai'] = 0x0E30;
  7923. t['saraethai'] = 0x0E40;
  7924. t['saraiileftthai'] = 0xF886;
  7925. t['saraiithai'] = 0x0E35;
  7926. t['saraileftthai'] = 0xF885;
  7927. t['saraithai'] = 0x0E34;
  7928. t['saraothai'] = 0x0E42;
  7929. t['saraueeleftthai'] = 0xF888;
  7930. t['saraueethai'] = 0x0E37;
  7931. t['saraueleftthai'] = 0xF887;
  7932. t['sarauethai'] = 0x0E36;
  7933. t['sarauthai'] = 0x0E38;
  7934. t['sarauuthai'] = 0x0E39;
  7935. t['sbopomofo'] = 0x3119;
  7936. t['scaron'] = 0x0161;
  7937. t['scarondotaccent'] = 0x1E67;
  7938. t['scedilla'] = 0x015F;
  7939. t['schwa'] = 0x0259;
  7940. t['schwacyrillic'] = 0x04D9;
  7941. t['schwadieresiscyrillic'] = 0x04DB;
  7942. t['schwahook'] = 0x025A;
  7943. t['scircle'] = 0x24E2;
  7944. t['scircumflex'] = 0x015D;
  7945. t['scommaaccent'] = 0x0219;
  7946. t['sdotaccent'] = 0x1E61;
  7947. t['sdotbelow'] = 0x1E63;
  7948. t['sdotbelowdotaccent'] = 0x1E69;
  7949. t['seagullbelowcmb'] = 0x033C;
  7950. t['second'] = 0x2033;
  7951. t['secondtonechinese'] = 0x02CA;
  7952. t['section'] = 0x00A7;
  7953. t['seenarabic'] = 0x0633;
  7954. t['seenfinalarabic'] = 0xFEB2;
  7955. t['seeninitialarabic'] = 0xFEB3;
  7956. t['seenmedialarabic'] = 0xFEB4;
  7957. t['segol'] = 0x05B6;
  7958. t['segol13'] = 0x05B6;
  7959. t['segol1f'] = 0x05B6;
  7960. t['segol2c'] = 0x05B6;
  7961. t['segolhebrew'] = 0x05B6;
  7962. t['segolnarrowhebrew'] = 0x05B6;
  7963. t['segolquarterhebrew'] = 0x05B6;
  7964. t['segoltahebrew'] = 0x0592;
  7965. t['segolwidehebrew'] = 0x05B6;
  7966. t['seharmenian'] = 0x057D;
  7967. t['sehiragana'] = 0x305B;
  7968. t['sekatakana'] = 0x30BB;
  7969. t['sekatakanahalfwidth'] = 0xFF7E;
  7970. t['semicolon'] = 0x003B;
  7971. t['semicolonarabic'] = 0x061B;
  7972. t['semicolonmonospace'] = 0xFF1B;
  7973. t['semicolonsmall'] = 0xFE54;
  7974. t['semivoicedmarkkana'] = 0x309C;
  7975. t['semivoicedmarkkanahalfwidth'] = 0xFF9F;
  7976. t['sentisquare'] = 0x3322;
  7977. t['sentosquare'] = 0x3323;
  7978. t['seven'] = 0x0037;
  7979. t['sevenarabic'] = 0x0667;
  7980. t['sevenbengali'] = 0x09ED;
  7981. t['sevencircle'] = 0x2466;
  7982. t['sevencircleinversesansserif'] = 0x2790;
  7983. t['sevendeva'] = 0x096D;
  7984. t['seveneighths'] = 0x215E;
  7985. t['sevengujarati'] = 0x0AED;
  7986. t['sevengurmukhi'] = 0x0A6D;
  7987. t['sevenhackarabic'] = 0x0667;
  7988. t['sevenhangzhou'] = 0x3027;
  7989. t['sevenideographicparen'] = 0x3226;
  7990. t['seveninferior'] = 0x2087;
  7991. t['sevenmonospace'] = 0xFF17;
  7992. t['sevenoldstyle'] = 0xF737;
  7993. t['sevenparen'] = 0x247A;
  7994. t['sevenperiod'] = 0x248E;
  7995. t['sevenpersian'] = 0x06F7;
  7996. t['sevenroman'] = 0x2176;
  7997. t['sevensuperior'] = 0x2077;
  7998. t['seventeencircle'] = 0x2470;
  7999. t['seventeenparen'] = 0x2484;
  8000. t['seventeenperiod'] = 0x2498;
  8001. t['seventhai'] = 0x0E57;
  8002. t['sfthyphen'] = 0x00AD;
  8003. t['shaarmenian'] = 0x0577;
  8004. t['shabengali'] = 0x09B6;
  8005. t['shacyrillic'] = 0x0448;
  8006. t['shaddaarabic'] = 0x0651;
  8007. t['shaddadammaarabic'] = 0xFC61;
  8008. t['shaddadammatanarabic'] = 0xFC5E;
  8009. t['shaddafathaarabic'] = 0xFC60;
  8010. t['shaddakasraarabic'] = 0xFC62;
  8011. t['shaddakasratanarabic'] = 0xFC5F;
  8012. t['shade'] = 0x2592;
  8013. t['shadedark'] = 0x2593;
  8014. t['shadelight'] = 0x2591;
  8015. t['shademedium'] = 0x2592;
  8016. t['shadeva'] = 0x0936;
  8017. t['shagujarati'] = 0x0AB6;
  8018. t['shagurmukhi'] = 0x0A36;
  8019. t['shalshelethebrew'] = 0x0593;
  8020. t['shbopomofo'] = 0x3115;
  8021. t['shchacyrillic'] = 0x0449;
  8022. t['sheenarabic'] = 0x0634;
  8023. t['sheenfinalarabic'] = 0xFEB6;
  8024. t['sheeninitialarabic'] = 0xFEB7;
  8025. t['sheenmedialarabic'] = 0xFEB8;
  8026. t['sheicoptic'] = 0x03E3;
  8027. t['sheqel'] = 0x20AA;
  8028. t['sheqelhebrew'] = 0x20AA;
  8029. t['sheva'] = 0x05B0;
  8030. t['sheva115'] = 0x05B0;
  8031. t['sheva15'] = 0x05B0;
  8032. t['sheva22'] = 0x05B0;
  8033. t['sheva2e'] = 0x05B0;
  8034. t['shevahebrew'] = 0x05B0;
  8035. t['shevanarrowhebrew'] = 0x05B0;
  8036. t['shevaquarterhebrew'] = 0x05B0;
  8037. t['shevawidehebrew'] = 0x05B0;
  8038. t['shhacyrillic'] = 0x04BB;
  8039. t['shimacoptic'] = 0x03ED;
  8040. t['shin'] = 0x05E9;
  8041. t['shindagesh'] = 0xFB49;
  8042. t['shindageshhebrew'] = 0xFB49;
  8043. t['shindageshshindot'] = 0xFB2C;
  8044. t['shindageshshindothebrew'] = 0xFB2C;
  8045. t['shindageshsindot'] = 0xFB2D;
  8046. t['shindageshsindothebrew'] = 0xFB2D;
  8047. t['shindothebrew'] = 0x05C1;
  8048. t['shinhebrew'] = 0x05E9;
  8049. t['shinshindot'] = 0xFB2A;
  8050. t['shinshindothebrew'] = 0xFB2A;
  8051. t['shinsindot'] = 0xFB2B;
  8052. t['shinsindothebrew'] = 0xFB2B;
  8053. t['shook'] = 0x0282;
  8054. t['sigma'] = 0x03C3;
  8055. t['sigma1'] = 0x03C2;
  8056. t['sigmafinal'] = 0x03C2;
  8057. t['sigmalunatesymbolgreek'] = 0x03F2;
  8058. t['sihiragana'] = 0x3057;
  8059. t['sikatakana'] = 0x30B7;
  8060. t['sikatakanahalfwidth'] = 0xFF7C;
  8061. t['siluqhebrew'] = 0x05BD;
  8062. t['siluqlefthebrew'] = 0x05BD;
  8063. t['similar'] = 0x223C;
  8064. t['sindothebrew'] = 0x05C2;
  8065. t['siosacirclekorean'] = 0x3274;
  8066. t['siosaparenkorean'] = 0x3214;
  8067. t['sioscieuckorean'] = 0x317E;
  8068. t['sioscirclekorean'] = 0x3266;
  8069. t['sioskiyeokkorean'] = 0x317A;
  8070. t['sioskorean'] = 0x3145;
  8071. t['siosnieunkorean'] = 0x317B;
  8072. t['siosparenkorean'] = 0x3206;
  8073. t['siospieupkorean'] = 0x317D;
  8074. t['siostikeutkorean'] = 0x317C;
  8075. t['six'] = 0x0036;
  8076. t['sixarabic'] = 0x0666;
  8077. t['sixbengali'] = 0x09EC;
  8078. t['sixcircle'] = 0x2465;
  8079. t['sixcircleinversesansserif'] = 0x278F;
  8080. t['sixdeva'] = 0x096C;
  8081. t['sixgujarati'] = 0x0AEC;
  8082. t['sixgurmukhi'] = 0x0A6C;
  8083. t['sixhackarabic'] = 0x0666;
  8084. t['sixhangzhou'] = 0x3026;
  8085. t['sixideographicparen'] = 0x3225;
  8086. t['sixinferior'] = 0x2086;
  8087. t['sixmonospace'] = 0xFF16;
  8088. t['sixoldstyle'] = 0xF736;
  8089. t['sixparen'] = 0x2479;
  8090. t['sixperiod'] = 0x248D;
  8091. t['sixpersian'] = 0x06F6;
  8092. t['sixroman'] = 0x2175;
  8093. t['sixsuperior'] = 0x2076;
  8094. t['sixteencircle'] = 0x246F;
  8095. t['sixteencurrencydenominatorbengali'] = 0x09F9;
  8096. t['sixteenparen'] = 0x2483;
  8097. t['sixteenperiod'] = 0x2497;
  8098. t['sixthai'] = 0x0E56;
  8099. t['slash'] = 0x002F;
  8100. t['slashmonospace'] = 0xFF0F;
  8101. t['slong'] = 0x017F;
  8102. t['slongdotaccent'] = 0x1E9B;
  8103. t['smileface'] = 0x263A;
  8104. t['smonospace'] = 0xFF53;
  8105. t['sofpasuqhebrew'] = 0x05C3;
  8106. t['softhyphen'] = 0x00AD;
  8107. t['softsigncyrillic'] = 0x044C;
  8108. t['sohiragana'] = 0x305D;
  8109. t['sokatakana'] = 0x30BD;
  8110. t['sokatakanahalfwidth'] = 0xFF7F;
  8111. t['soliduslongoverlaycmb'] = 0x0338;
  8112. t['solidusshortoverlaycmb'] = 0x0337;
  8113. t['sorusithai'] = 0x0E29;
  8114. t['sosalathai'] = 0x0E28;
  8115. t['sosothai'] = 0x0E0B;
  8116. t['sosuathai'] = 0x0E2A;
  8117. t['space'] = 0x0020;
  8118. t['spacehackarabic'] = 0x0020;
  8119. t['spade'] = 0x2660;
  8120. t['spadesuitblack'] = 0x2660;
  8121. t['spadesuitwhite'] = 0x2664;
  8122. t['sparen'] = 0x24AE;
  8123. t['squarebelowcmb'] = 0x033B;
  8124. t['squarecc'] = 0x33C4;
  8125. t['squarecm'] = 0x339D;
  8126. t['squarediagonalcrosshatchfill'] = 0x25A9;
  8127. t['squarehorizontalfill'] = 0x25A4;
  8128. t['squarekg'] = 0x338F;
  8129. t['squarekm'] = 0x339E;
  8130. t['squarekmcapital'] = 0x33CE;
  8131. t['squareln'] = 0x33D1;
  8132. t['squarelog'] = 0x33D2;
  8133. t['squaremg'] = 0x338E;
  8134. t['squaremil'] = 0x33D5;
  8135. t['squaremm'] = 0x339C;
  8136. t['squaremsquared'] = 0x33A1;
  8137. t['squareorthogonalcrosshatchfill'] = 0x25A6;
  8138. t['squareupperlefttolowerrightfill'] = 0x25A7;
  8139. t['squareupperrighttolowerleftfill'] = 0x25A8;
  8140. t['squareverticalfill'] = 0x25A5;
  8141. t['squarewhitewithsmallblack'] = 0x25A3;
  8142. t['srsquare'] = 0x33DB;
  8143. t['ssabengali'] = 0x09B7;
  8144. t['ssadeva'] = 0x0937;
  8145. t['ssagujarati'] = 0x0AB7;
  8146. t['ssangcieuckorean'] = 0x3149;
  8147. t['ssanghieuhkorean'] = 0x3185;
  8148. t['ssangieungkorean'] = 0x3180;
  8149. t['ssangkiyeokkorean'] = 0x3132;
  8150. t['ssangnieunkorean'] = 0x3165;
  8151. t['ssangpieupkorean'] = 0x3143;
  8152. t['ssangsioskorean'] = 0x3146;
  8153. t['ssangtikeutkorean'] = 0x3138;
  8154. t['ssuperior'] = 0xF6F2;
  8155. t['sterling'] = 0x00A3;
  8156. t['sterlingmonospace'] = 0xFFE1;
  8157. t['strokelongoverlaycmb'] = 0x0336;
  8158. t['strokeshortoverlaycmb'] = 0x0335;
  8159. t['subset'] = 0x2282;
  8160. t['subsetnotequal'] = 0x228A;
  8161. t['subsetorequal'] = 0x2286;
  8162. t['succeeds'] = 0x227B;
  8163. t['suchthat'] = 0x220B;
  8164. t['suhiragana'] = 0x3059;
  8165. t['sukatakana'] = 0x30B9;
  8166. t['sukatakanahalfwidth'] = 0xFF7D;
  8167. t['sukunarabic'] = 0x0652;
  8168. t['summation'] = 0x2211;
  8169. t['sun'] = 0x263C;
  8170. t['superset'] = 0x2283;
  8171. t['supersetnotequal'] = 0x228B;
  8172. t['supersetorequal'] = 0x2287;
  8173. t['svsquare'] = 0x33DC;
  8174. t['syouwaerasquare'] = 0x337C;
  8175. t['t'] = 0x0074;
  8176. t['tabengali'] = 0x09A4;
  8177. t['tackdown'] = 0x22A4;
  8178. t['tackleft'] = 0x22A3;
  8179. t['tadeva'] = 0x0924;
  8180. t['tagujarati'] = 0x0AA4;
  8181. t['tagurmukhi'] = 0x0A24;
  8182. t['taharabic'] = 0x0637;
  8183. t['tahfinalarabic'] = 0xFEC2;
  8184. t['tahinitialarabic'] = 0xFEC3;
  8185. t['tahiragana'] = 0x305F;
  8186. t['tahmedialarabic'] = 0xFEC4;
  8187. t['taisyouerasquare'] = 0x337D;
  8188. t['takatakana'] = 0x30BF;
  8189. t['takatakanahalfwidth'] = 0xFF80;
  8190. t['tatweelarabic'] = 0x0640;
  8191. t['tau'] = 0x03C4;
  8192. t['tav'] = 0x05EA;
  8193. t['tavdages'] = 0xFB4A;
  8194. t['tavdagesh'] = 0xFB4A;
  8195. t['tavdageshhebrew'] = 0xFB4A;
  8196. t['tavhebrew'] = 0x05EA;
  8197. t['tbar'] = 0x0167;
  8198. t['tbopomofo'] = 0x310A;
  8199. t['tcaron'] = 0x0165;
  8200. t['tccurl'] = 0x02A8;
  8201. t['tcedilla'] = 0x0163;
  8202. t['tcheharabic'] = 0x0686;
  8203. t['tchehfinalarabic'] = 0xFB7B;
  8204. t['tchehinitialarabic'] = 0xFB7C;
  8205. t['tchehmedialarabic'] = 0xFB7D;
  8206. t['tcircle'] = 0x24E3;
  8207. t['tcircumflexbelow'] = 0x1E71;
  8208. t['tcommaaccent'] = 0x0163;
  8209. t['tdieresis'] = 0x1E97;
  8210. t['tdotaccent'] = 0x1E6B;
  8211. t['tdotbelow'] = 0x1E6D;
  8212. t['tecyrillic'] = 0x0442;
  8213. t['tedescendercyrillic'] = 0x04AD;
  8214. t['teharabic'] = 0x062A;
  8215. t['tehfinalarabic'] = 0xFE96;
  8216. t['tehhahinitialarabic'] = 0xFCA2;
  8217. t['tehhahisolatedarabic'] = 0xFC0C;
  8218. t['tehinitialarabic'] = 0xFE97;
  8219. t['tehiragana'] = 0x3066;
  8220. t['tehjeeminitialarabic'] = 0xFCA1;
  8221. t['tehjeemisolatedarabic'] = 0xFC0B;
  8222. t['tehmarbutaarabic'] = 0x0629;
  8223. t['tehmarbutafinalarabic'] = 0xFE94;
  8224. t['tehmedialarabic'] = 0xFE98;
  8225. t['tehmeeminitialarabic'] = 0xFCA4;
  8226. t['tehmeemisolatedarabic'] = 0xFC0E;
  8227. t['tehnoonfinalarabic'] = 0xFC73;
  8228. t['tekatakana'] = 0x30C6;
  8229. t['tekatakanahalfwidth'] = 0xFF83;
  8230. t['telephone'] = 0x2121;
  8231. t['telephoneblack'] = 0x260E;
  8232. t['telishagedolahebrew'] = 0x05A0;
  8233. t['telishaqetanahebrew'] = 0x05A9;
  8234. t['tencircle'] = 0x2469;
  8235. t['tenideographicparen'] = 0x3229;
  8236. t['tenparen'] = 0x247D;
  8237. t['tenperiod'] = 0x2491;
  8238. t['tenroman'] = 0x2179;
  8239. t['tesh'] = 0x02A7;
  8240. t['tet'] = 0x05D8;
  8241. t['tetdagesh'] = 0xFB38;
  8242. t['tetdageshhebrew'] = 0xFB38;
  8243. t['tethebrew'] = 0x05D8;
  8244. t['tetsecyrillic'] = 0x04B5;
  8245. t['tevirhebrew'] = 0x059B;
  8246. t['tevirlefthebrew'] = 0x059B;
  8247. t['thabengali'] = 0x09A5;
  8248. t['thadeva'] = 0x0925;
  8249. t['thagujarati'] = 0x0AA5;
  8250. t['thagurmukhi'] = 0x0A25;
  8251. t['thalarabic'] = 0x0630;
  8252. t['thalfinalarabic'] = 0xFEAC;
  8253. t['thanthakhatlowleftthai'] = 0xF898;
  8254. t['thanthakhatlowrightthai'] = 0xF897;
  8255. t['thanthakhatthai'] = 0x0E4C;
  8256. t['thanthakhatupperleftthai'] = 0xF896;
  8257. t['theharabic'] = 0x062B;
  8258. t['thehfinalarabic'] = 0xFE9A;
  8259. t['thehinitialarabic'] = 0xFE9B;
  8260. t['thehmedialarabic'] = 0xFE9C;
  8261. t['thereexists'] = 0x2203;
  8262. t['therefore'] = 0x2234;
  8263. t['theta'] = 0x03B8;
  8264. t['theta1'] = 0x03D1;
  8265. t['thetasymbolgreek'] = 0x03D1;
  8266. t['thieuthacirclekorean'] = 0x3279;
  8267. t['thieuthaparenkorean'] = 0x3219;
  8268. t['thieuthcirclekorean'] = 0x326B;
  8269. t['thieuthkorean'] = 0x314C;
  8270. t['thieuthparenkorean'] = 0x320B;
  8271. t['thirteencircle'] = 0x246C;
  8272. t['thirteenparen'] = 0x2480;
  8273. t['thirteenperiod'] = 0x2494;
  8274. t['thonangmonthothai'] = 0x0E11;
  8275. t['thook'] = 0x01AD;
  8276. t['thophuthaothai'] = 0x0E12;
  8277. t['thorn'] = 0x00FE;
  8278. t['thothahanthai'] = 0x0E17;
  8279. t['thothanthai'] = 0x0E10;
  8280. t['thothongthai'] = 0x0E18;
  8281. t['thothungthai'] = 0x0E16;
  8282. t['thousandcyrillic'] = 0x0482;
  8283. t['thousandsseparatorarabic'] = 0x066C;
  8284. t['thousandsseparatorpersian'] = 0x066C;
  8285. t['three'] = 0x0033;
  8286. t['threearabic'] = 0x0663;
  8287. t['threebengali'] = 0x09E9;
  8288. t['threecircle'] = 0x2462;
  8289. t['threecircleinversesansserif'] = 0x278C;
  8290. t['threedeva'] = 0x0969;
  8291. t['threeeighths'] = 0x215C;
  8292. t['threegujarati'] = 0x0AE9;
  8293. t['threegurmukhi'] = 0x0A69;
  8294. t['threehackarabic'] = 0x0663;
  8295. t['threehangzhou'] = 0x3023;
  8296. t['threeideographicparen'] = 0x3222;
  8297. t['threeinferior'] = 0x2083;
  8298. t['threemonospace'] = 0xFF13;
  8299. t['threenumeratorbengali'] = 0x09F6;
  8300. t['threeoldstyle'] = 0xF733;
  8301. t['threeparen'] = 0x2476;
  8302. t['threeperiod'] = 0x248A;
  8303. t['threepersian'] = 0x06F3;
  8304. t['threequarters'] = 0x00BE;
  8305. t['threequartersemdash'] = 0xF6DE;
  8306. t['threeroman'] = 0x2172;
  8307. t['threesuperior'] = 0x00B3;
  8308. t['threethai'] = 0x0E53;
  8309. t['thzsquare'] = 0x3394;
  8310. t['tihiragana'] = 0x3061;
  8311. t['tikatakana'] = 0x30C1;
  8312. t['tikatakanahalfwidth'] = 0xFF81;
  8313. t['tikeutacirclekorean'] = 0x3270;
  8314. t['tikeutaparenkorean'] = 0x3210;
  8315. t['tikeutcirclekorean'] = 0x3262;
  8316. t['tikeutkorean'] = 0x3137;
  8317. t['tikeutparenkorean'] = 0x3202;
  8318. t['tilde'] = 0x02DC;
  8319. t['tildebelowcmb'] = 0x0330;
  8320. t['tildecmb'] = 0x0303;
  8321. t['tildecomb'] = 0x0303;
  8322. t['tildedoublecmb'] = 0x0360;
  8323. t['tildeoperator'] = 0x223C;
  8324. t['tildeoverlaycmb'] = 0x0334;
  8325. t['tildeverticalcmb'] = 0x033E;
  8326. t['timescircle'] = 0x2297;
  8327. t['tipehahebrew'] = 0x0596;
  8328. t['tipehalefthebrew'] = 0x0596;
  8329. t['tippigurmukhi'] = 0x0A70;
  8330. t['titlocyrilliccmb'] = 0x0483;
  8331. t['tiwnarmenian'] = 0x057F;
  8332. t['tlinebelow'] = 0x1E6F;
  8333. t['tmonospace'] = 0xFF54;
  8334. t['toarmenian'] = 0x0569;
  8335. t['tohiragana'] = 0x3068;
  8336. t['tokatakana'] = 0x30C8;
  8337. t['tokatakanahalfwidth'] = 0xFF84;
  8338. t['tonebarextrahighmod'] = 0x02E5;
  8339. t['tonebarextralowmod'] = 0x02E9;
  8340. t['tonebarhighmod'] = 0x02E6;
  8341. t['tonebarlowmod'] = 0x02E8;
  8342. t['tonebarmidmod'] = 0x02E7;
  8343. t['tonefive'] = 0x01BD;
  8344. t['tonesix'] = 0x0185;
  8345. t['tonetwo'] = 0x01A8;
  8346. t['tonos'] = 0x0384;
  8347. t['tonsquare'] = 0x3327;
  8348. t['topatakthai'] = 0x0E0F;
  8349. t['tortoiseshellbracketleft'] = 0x3014;
  8350. t['tortoiseshellbracketleftsmall'] = 0xFE5D;
  8351. t['tortoiseshellbracketleftvertical'] = 0xFE39;
  8352. t['tortoiseshellbracketright'] = 0x3015;
  8353. t['tortoiseshellbracketrightsmall'] = 0xFE5E;
  8354. t['tortoiseshellbracketrightvertical'] = 0xFE3A;
  8355. t['totaothai'] = 0x0E15;
  8356. t['tpalatalhook'] = 0x01AB;
  8357. t['tparen'] = 0x24AF;
  8358. t['trademark'] = 0x2122;
  8359. t['trademarksans'] = 0xF8EA;
  8360. t['trademarkserif'] = 0xF6DB;
  8361. t['tretroflexhook'] = 0x0288;
  8362. t['triagdn'] = 0x25BC;
  8363. t['triaglf'] = 0x25C4;
  8364. t['triagrt'] = 0x25BA;
  8365. t['triagup'] = 0x25B2;
  8366. t['ts'] = 0x02A6;
  8367. t['tsadi'] = 0x05E6;
  8368. t['tsadidagesh'] = 0xFB46;
  8369. t['tsadidageshhebrew'] = 0xFB46;
  8370. t['tsadihebrew'] = 0x05E6;
  8371. t['tsecyrillic'] = 0x0446;
  8372. t['tsere'] = 0x05B5;
  8373. t['tsere12'] = 0x05B5;
  8374. t['tsere1e'] = 0x05B5;
  8375. t['tsere2b'] = 0x05B5;
  8376. t['tserehebrew'] = 0x05B5;
  8377. t['tserenarrowhebrew'] = 0x05B5;
  8378. t['tserequarterhebrew'] = 0x05B5;
  8379. t['tserewidehebrew'] = 0x05B5;
  8380. t['tshecyrillic'] = 0x045B;
  8381. t['tsuperior'] = 0xF6F3;
  8382. t['ttabengali'] = 0x099F;
  8383. t['ttadeva'] = 0x091F;
  8384. t['ttagujarati'] = 0x0A9F;
  8385. t['ttagurmukhi'] = 0x0A1F;
  8386. t['tteharabic'] = 0x0679;
  8387. t['ttehfinalarabic'] = 0xFB67;
  8388. t['ttehinitialarabic'] = 0xFB68;
  8389. t['ttehmedialarabic'] = 0xFB69;
  8390. t['tthabengali'] = 0x09A0;
  8391. t['tthadeva'] = 0x0920;
  8392. t['tthagujarati'] = 0x0AA0;
  8393. t['tthagurmukhi'] = 0x0A20;
  8394. t['tturned'] = 0x0287;
  8395. t['tuhiragana'] = 0x3064;
  8396. t['tukatakana'] = 0x30C4;
  8397. t['tukatakanahalfwidth'] = 0xFF82;
  8398. t['tusmallhiragana'] = 0x3063;
  8399. t['tusmallkatakana'] = 0x30C3;
  8400. t['tusmallkatakanahalfwidth'] = 0xFF6F;
  8401. t['twelvecircle'] = 0x246B;
  8402. t['twelveparen'] = 0x247F;
  8403. t['twelveperiod'] = 0x2493;
  8404. t['twelveroman'] = 0x217B;
  8405. t['twentycircle'] = 0x2473;
  8406. t['twentyhangzhou'] = 0x5344;
  8407. t['twentyparen'] = 0x2487;
  8408. t['twentyperiod'] = 0x249B;
  8409. t['two'] = 0x0032;
  8410. t['twoarabic'] = 0x0662;
  8411. t['twobengali'] = 0x09E8;
  8412. t['twocircle'] = 0x2461;
  8413. t['twocircleinversesansserif'] = 0x278B;
  8414. t['twodeva'] = 0x0968;
  8415. t['twodotenleader'] = 0x2025;
  8416. t['twodotleader'] = 0x2025;
  8417. t['twodotleadervertical'] = 0xFE30;
  8418. t['twogujarati'] = 0x0AE8;
  8419. t['twogurmukhi'] = 0x0A68;
  8420. t['twohackarabic'] = 0x0662;
  8421. t['twohangzhou'] = 0x3022;
  8422. t['twoideographicparen'] = 0x3221;
  8423. t['twoinferior'] = 0x2082;
  8424. t['twomonospace'] = 0xFF12;
  8425. t['twonumeratorbengali'] = 0x09F5;
  8426. t['twooldstyle'] = 0xF732;
  8427. t['twoparen'] = 0x2475;
  8428. t['twoperiod'] = 0x2489;
  8429. t['twopersian'] = 0x06F2;
  8430. t['tworoman'] = 0x2171;
  8431. t['twostroke'] = 0x01BB;
  8432. t['twosuperior'] = 0x00B2;
  8433. t['twothai'] = 0x0E52;
  8434. t['twothirds'] = 0x2154;
  8435. t['u'] = 0x0075;
  8436. t['uacute'] = 0x00FA;
  8437. t['ubar'] = 0x0289;
  8438. t['ubengali'] = 0x0989;
  8439. t['ubopomofo'] = 0x3128;
  8440. t['ubreve'] = 0x016D;
  8441. t['ucaron'] = 0x01D4;
  8442. t['ucircle'] = 0x24E4;
  8443. t['ucircumflex'] = 0x00FB;
  8444. t['ucircumflexbelow'] = 0x1E77;
  8445. t['ucyrillic'] = 0x0443;
  8446. t['udattadeva'] = 0x0951;
  8447. t['udblacute'] = 0x0171;
  8448. t['udblgrave'] = 0x0215;
  8449. t['udeva'] = 0x0909;
  8450. t['udieresis'] = 0x00FC;
  8451. t['udieresisacute'] = 0x01D8;
  8452. t['udieresisbelow'] = 0x1E73;
  8453. t['udieresiscaron'] = 0x01DA;
  8454. t['udieresiscyrillic'] = 0x04F1;
  8455. t['udieresisgrave'] = 0x01DC;
  8456. t['udieresismacron'] = 0x01D6;
  8457. t['udotbelow'] = 0x1EE5;
  8458. t['ugrave'] = 0x00F9;
  8459. t['ugujarati'] = 0x0A89;
  8460. t['ugurmukhi'] = 0x0A09;
  8461. t['uhiragana'] = 0x3046;
  8462. t['uhookabove'] = 0x1EE7;
  8463. t['uhorn'] = 0x01B0;
  8464. t['uhornacute'] = 0x1EE9;
  8465. t['uhorndotbelow'] = 0x1EF1;
  8466. t['uhorngrave'] = 0x1EEB;
  8467. t['uhornhookabove'] = 0x1EED;
  8468. t['uhorntilde'] = 0x1EEF;
  8469. t['uhungarumlaut'] = 0x0171;
  8470. t['uhungarumlautcyrillic'] = 0x04F3;
  8471. t['uinvertedbreve'] = 0x0217;
  8472. t['ukatakana'] = 0x30A6;
  8473. t['ukatakanahalfwidth'] = 0xFF73;
  8474. t['ukcyrillic'] = 0x0479;
  8475. t['ukorean'] = 0x315C;
  8476. t['umacron'] = 0x016B;
  8477. t['umacroncyrillic'] = 0x04EF;
  8478. t['umacrondieresis'] = 0x1E7B;
  8479. t['umatragurmukhi'] = 0x0A41;
  8480. t['umonospace'] = 0xFF55;
  8481. t['underscore'] = 0x005F;
  8482. t['underscoredbl'] = 0x2017;
  8483. t['underscoremonospace'] = 0xFF3F;
  8484. t['underscorevertical'] = 0xFE33;
  8485. t['underscorewavy'] = 0xFE4F;
  8486. t['union'] = 0x222A;
  8487. t['universal'] = 0x2200;
  8488. t['uogonek'] = 0x0173;
  8489. t['uparen'] = 0x24B0;
  8490. t['upblock'] = 0x2580;
  8491. t['upperdothebrew'] = 0x05C4;
  8492. t['upsilon'] = 0x03C5;
  8493. t['upsilondieresis'] = 0x03CB;
  8494. t['upsilondieresistonos'] = 0x03B0;
  8495. t['upsilonlatin'] = 0x028A;
  8496. t['upsilontonos'] = 0x03CD;
  8497. t['uptackbelowcmb'] = 0x031D;
  8498. t['uptackmod'] = 0x02D4;
  8499. t['uragurmukhi'] = 0x0A73;
  8500. t['uring'] = 0x016F;
  8501. t['ushortcyrillic'] = 0x045E;
  8502. t['usmallhiragana'] = 0x3045;
  8503. t['usmallkatakana'] = 0x30A5;
  8504. t['usmallkatakanahalfwidth'] = 0xFF69;
  8505. t['ustraightcyrillic'] = 0x04AF;
  8506. t['ustraightstrokecyrillic'] = 0x04B1;
  8507. t['utilde'] = 0x0169;
  8508. t['utildeacute'] = 0x1E79;
  8509. t['utildebelow'] = 0x1E75;
  8510. t['uubengali'] = 0x098A;
  8511. t['uudeva'] = 0x090A;
  8512. t['uugujarati'] = 0x0A8A;
  8513. t['uugurmukhi'] = 0x0A0A;
  8514. t['uumatragurmukhi'] = 0x0A42;
  8515. t['uuvowelsignbengali'] = 0x09C2;
  8516. t['uuvowelsigndeva'] = 0x0942;
  8517. t['uuvowelsigngujarati'] = 0x0AC2;
  8518. t['uvowelsignbengali'] = 0x09C1;
  8519. t['uvowelsigndeva'] = 0x0941;
  8520. t['uvowelsigngujarati'] = 0x0AC1;
  8521. t['v'] = 0x0076;
  8522. t['vadeva'] = 0x0935;
  8523. t['vagujarati'] = 0x0AB5;
  8524. t['vagurmukhi'] = 0x0A35;
  8525. t['vakatakana'] = 0x30F7;
  8526. t['vav'] = 0x05D5;
  8527. t['vavdagesh'] = 0xFB35;
  8528. t['vavdagesh65'] = 0xFB35;
  8529. t['vavdageshhebrew'] = 0xFB35;
  8530. t['vavhebrew'] = 0x05D5;
  8531. t['vavholam'] = 0xFB4B;
  8532. t['vavholamhebrew'] = 0xFB4B;
  8533. t['vavvavhebrew'] = 0x05F0;
  8534. t['vavyodhebrew'] = 0x05F1;
  8535. t['vcircle'] = 0x24E5;
  8536. t['vdotbelow'] = 0x1E7F;
  8537. t['vecyrillic'] = 0x0432;
  8538. t['veharabic'] = 0x06A4;
  8539. t['vehfinalarabic'] = 0xFB6B;
  8540. t['vehinitialarabic'] = 0xFB6C;
  8541. t['vehmedialarabic'] = 0xFB6D;
  8542. t['vekatakana'] = 0x30F9;
  8543. t['venus'] = 0x2640;
  8544. t['verticalbar'] = 0x007C;
  8545. t['verticallineabovecmb'] = 0x030D;
  8546. t['verticallinebelowcmb'] = 0x0329;
  8547. t['verticallinelowmod'] = 0x02CC;
  8548. t['verticallinemod'] = 0x02C8;
  8549. t['vewarmenian'] = 0x057E;
  8550. t['vhook'] = 0x028B;
  8551. t['vikatakana'] = 0x30F8;
  8552. t['viramabengali'] = 0x09CD;
  8553. t['viramadeva'] = 0x094D;
  8554. t['viramagujarati'] = 0x0ACD;
  8555. t['visargabengali'] = 0x0983;
  8556. t['visargadeva'] = 0x0903;
  8557. t['visargagujarati'] = 0x0A83;
  8558. t['vmonospace'] = 0xFF56;
  8559. t['voarmenian'] = 0x0578;
  8560. t['voicediterationhiragana'] = 0x309E;
  8561. t['voicediterationkatakana'] = 0x30FE;
  8562. t['voicedmarkkana'] = 0x309B;
  8563. t['voicedmarkkanahalfwidth'] = 0xFF9E;
  8564. t['vokatakana'] = 0x30FA;
  8565. t['vparen'] = 0x24B1;
  8566. t['vtilde'] = 0x1E7D;
  8567. t['vturned'] = 0x028C;
  8568. t['vuhiragana'] = 0x3094;
  8569. t['vukatakana'] = 0x30F4;
  8570. t['w'] = 0x0077;
  8571. t['wacute'] = 0x1E83;
  8572. t['waekorean'] = 0x3159;
  8573. t['wahiragana'] = 0x308F;
  8574. t['wakatakana'] = 0x30EF;
  8575. t['wakatakanahalfwidth'] = 0xFF9C;
  8576. t['wakorean'] = 0x3158;
  8577. t['wasmallhiragana'] = 0x308E;
  8578. t['wasmallkatakana'] = 0x30EE;
  8579. t['wattosquare'] = 0x3357;
  8580. t['wavedash'] = 0x301C;
  8581. t['wavyunderscorevertical'] = 0xFE34;
  8582. t['wawarabic'] = 0x0648;
  8583. t['wawfinalarabic'] = 0xFEEE;
  8584. t['wawhamzaabovearabic'] = 0x0624;
  8585. t['wawhamzaabovefinalarabic'] = 0xFE86;
  8586. t['wbsquare'] = 0x33DD;
  8587. t['wcircle'] = 0x24E6;
  8588. t['wcircumflex'] = 0x0175;
  8589. t['wdieresis'] = 0x1E85;
  8590. t['wdotaccent'] = 0x1E87;
  8591. t['wdotbelow'] = 0x1E89;
  8592. t['wehiragana'] = 0x3091;
  8593. t['weierstrass'] = 0x2118;
  8594. t['wekatakana'] = 0x30F1;
  8595. t['wekorean'] = 0x315E;
  8596. t['weokorean'] = 0x315D;
  8597. t['wgrave'] = 0x1E81;
  8598. t['whitebullet'] = 0x25E6;
  8599. t['whitecircle'] = 0x25CB;
  8600. t['whitecircleinverse'] = 0x25D9;
  8601. t['whitecornerbracketleft'] = 0x300E;
  8602. t['whitecornerbracketleftvertical'] = 0xFE43;
  8603. t['whitecornerbracketright'] = 0x300F;
  8604. t['whitecornerbracketrightvertical'] = 0xFE44;
  8605. t['whitediamond'] = 0x25C7;
  8606. t['whitediamondcontainingblacksmalldiamond'] = 0x25C8;
  8607. t['whitedownpointingsmalltriangle'] = 0x25BF;
  8608. t['whitedownpointingtriangle'] = 0x25BD;
  8609. t['whiteleftpointingsmalltriangle'] = 0x25C3;
  8610. t['whiteleftpointingtriangle'] = 0x25C1;
  8611. t['whitelenticularbracketleft'] = 0x3016;
  8612. t['whitelenticularbracketright'] = 0x3017;
  8613. t['whiterightpointingsmalltriangle'] = 0x25B9;
  8614. t['whiterightpointingtriangle'] = 0x25B7;
  8615. t['whitesmallsquare'] = 0x25AB;
  8616. t['whitesmilingface'] = 0x263A;
  8617. t['whitesquare'] = 0x25A1;
  8618. t['whitestar'] = 0x2606;
  8619. t['whitetelephone'] = 0x260F;
  8620. t['whitetortoiseshellbracketleft'] = 0x3018;
  8621. t['whitetortoiseshellbracketright'] = 0x3019;
  8622. t['whiteuppointingsmalltriangle'] = 0x25B5;
  8623. t['whiteuppointingtriangle'] = 0x25B3;
  8624. t['wihiragana'] = 0x3090;
  8625. t['wikatakana'] = 0x30F0;
  8626. t['wikorean'] = 0x315F;
  8627. t['wmonospace'] = 0xFF57;
  8628. t['wohiragana'] = 0x3092;
  8629. t['wokatakana'] = 0x30F2;
  8630. t['wokatakanahalfwidth'] = 0xFF66;
  8631. t['won'] = 0x20A9;
  8632. t['wonmonospace'] = 0xFFE6;
  8633. t['wowaenthai'] = 0x0E27;
  8634. t['wparen'] = 0x24B2;
  8635. t['wring'] = 0x1E98;
  8636. t['wsuperior'] = 0x02B7;
  8637. t['wturned'] = 0x028D;
  8638. t['wynn'] = 0x01BF;
  8639. t['x'] = 0x0078;
  8640. t['xabovecmb'] = 0x033D;
  8641. t['xbopomofo'] = 0x3112;
  8642. t['xcircle'] = 0x24E7;
  8643. t['xdieresis'] = 0x1E8D;
  8644. t['xdotaccent'] = 0x1E8B;
  8645. t['xeharmenian'] = 0x056D;
  8646. t['xi'] = 0x03BE;
  8647. t['xmonospace'] = 0xFF58;
  8648. t['xparen'] = 0x24B3;
  8649. t['xsuperior'] = 0x02E3;
  8650. t['y'] = 0x0079;
  8651. t['yaadosquare'] = 0x334E;
  8652. t['yabengali'] = 0x09AF;
  8653. t['yacute'] = 0x00FD;
  8654. t['yadeva'] = 0x092F;
  8655. t['yaekorean'] = 0x3152;
  8656. t['yagujarati'] = 0x0AAF;
  8657. t['yagurmukhi'] = 0x0A2F;
  8658. t['yahiragana'] = 0x3084;
  8659. t['yakatakana'] = 0x30E4;
  8660. t['yakatakanahalfwidth'] = 0xFF94;
  8661. t['yakorean'] = 0x3151;
  8662. t['yamakkanthai'] = 0x0E4E;
  8663. t['yasmallhiragana'] = 0x3083;
  8664. t['yasmallkatakana'] = 0x30E3;
  8665. t['yasmallkatakanahalfwidth'] = 0xFF6C;
  8666. t['yatcyrillic'] = 0x0463;
  8667. t['ycircle'] = 0x24E8;
  8668. t['ycircumflex'] = 0x0177;
  8669. t['ydieresis'] = 0x00FF;
  8670. t['ydotaccent'] = 0x1E8F;
  8671. t['ydotbelow'] = 0x1EF5;
  8672. t['yeharabic'] = 0x064A;
  8673. t['yehbarreearabic'] = 0x06D2;
  8674. t['yehbarreefinalarabic'] = 0xFBAF;
  8675. t['yehfinalarabic'] = 0xFEF2;
  8676. t['yehhamzaabovearabic'] = 0x0626;
  8677. t['yehhamzaabovefinalarabic'] = 0xFE8A;
  8678. t['yehhamzaaboveinitialarabic'] = 0xFE8B;
  8679. t['yehhamzaabovemedialarabic'] = 0xFE8C;
  8680. t['yehinitialarabic'] = 0xFEF3;
  8681. t['yehmedialarabic'] = 0xFEF4;
  8682. t['yehmeeminitialarabic'] = 0xFCDD;
  8683. t['yehmeemisolatedarabic'] = 0xFC58;
  8684. t['yehnoonfinalarabic'] = 0xFC94;
  8685. t['yehthreedotsbelowarabic'] = 0x06D1;
  8686. t['yekorean'] = 0x3156;
  8687. t['yen'] = 0x00A5;
  8688. t['yenmonospace'] = 0xFFE5;
  8689. t['yeokorean'] = 0x3155;
  8690. t['yeorinhieuhkorean'] = 0x3186;
  8691. t['yerahbenyomohebrew'] = 0x05AA;
  8692. t['yerahbenyomolefthebrew'] = 0x05AA;
  8693. t['yericyrillic'] = 0x044B;
  8694. t['yerudieresiscyrillic'] = 0x04F9;
  8695. t['yesieungkorean'] = 0x3181;
  8696. t['yesieungpansioskorean'] = 0x3183;
  8697. t['yesieungsioskorean'] = 0x3182;
  8698. t['yetivhebrew'] = 0x059A;
  8699. t['ygrave'] = 0x1EF3;
  8700. t['yhook'] = 0x01B4;
  8701. t['yhookabove'] = 0x1EF7;
  8702. t['yiarmenian'] = 0x0575;
  8703. t['yicyrillic'] = 0x0457;
  8704. t['yikorean'] = 0x3162;
  8705. t['yinyang'] = 0x262F;
  8706. t['yiwnarmenian'] = 0x0582;
  8707. t['ymonospace'] = 0xFF59;
  8708. t['yod'] = 0x05D9;
  8709. t['yoddagesh'] = 0xFB39;
  8710. t['yoddageshhebrew'] = 0xFB39;
  8711. t['yodhebrew'] = 0x05D9;
  8712. t['yodyodhebrew'] = 0x05F2;
  8713. t['yodyodpatahhebrew'] = 0xFB1F;
  8714. t['yohiragana'] = 0x3088;
  8715. t['yoikorean'] = 0x3189;
  8716. t['yokatakana'] = 0x30E8;
  8717. t['yokatakanahalfwidth'] = 0xFF96;
  8718. t['yokorean'] = 0x315B;
  8719. t['yosmallhiragana'] = 0x3087;
  8720. t['yosmallkatakana'] = 0x30E7;
  8721. t['yosmallkatakanahalfwidth'] = 0xFF6E;
  8722. t['yotgreek'] = 0x03F3;
  8723. t['yoyaekorean'] = 0x3188;
  8724. t['yoyakorean'] = 0x3187;
  8725. t['yoyakthai'] = 0x0E22;
  8726. t['yoyingthai'] = 0x0E0D;
  8727. t['yparen'] = 0x24B4;
  8728. t['ypogegrammeni'] = 0x037A;
  8729. t['ypogegrammenigreekcmb'] = 0x0345;
  8730. t['yr'] = 0x01A6;
  8731. t['yring'] = 0x1E99;
  8732. t['ysuperior'] = 0x02B8;
  8733. t['ytilde'] = 0x1EF9;
  8734. t['yturned'] = 0x028E;
  8735. t['yuhiragana'] = 0x3086;
  8736. t['yuikorean'] = 0x318C;
  8737. t['yukatakana'] = 0x30E6;
  8738. t['yukatakanahalfwidth'] = 0xFF95;
  8739. t['yukorean'] = 0x3160;
  8740. t['yusbigcyrillic'] = 0x046B;
  8741. t['yusbigiotifiedcyrillic'] = 0x046D;
  8742. t['yuslittlecyrillic'] = 0x0467;
  8743. t['yuslittleiotifiedcyrillic'] = 0x0469;
  8744. t['yusmallhiragana'] = 0x3085;
  8745. t['yusmallkatakana'] = 0x30E5;
  8746. t['yusmallkatakanahalfwidth'] = 0xFF6D;
  8747. t['yuyekorean'] = 0x318B;
  8748. t['yuyeokorean'] = 0x318A;
  8749. t['yyabengali'] = 0x09DF;
  8750. t['yyadeva'] = 0x095F;
  8751. t['z'] = 0x007A;
  8752. t['zaarmenian'] = 0x0566;
  8753. t['zacute'] = 0x017A;
  8754. t['zadeva'] = 0x095B;
  8755. t['zagurmukhi'] = 0x0A5B;
  8756. t['zaharabic'] = 0x0638;
  8757. t['zahfinalarabic'] = 0xFEC6;
  8758. t['zahinitialarabic'] = 0xFEC7;
  8759. t['zahiragana'] = 0x3056;
  8760. t['zahmedialarabic'] = 0xFEC8;
  8761. t['zainarabic'] = 0x0632;
  8762. t['zainfinalarabic'] = 0xFEB0;
  8763. t['zakatakana'] = 0x30B6;
  8764. t['zaqefgadolhebrew'] = 0x0595;
  8765. t['zaqefqatanhebrew'] = 0x0594;
  8766. t['zarqahebrew'] = 0x0598;
  8767. t['zayin'] = 0x05D6;
  8768. t['zayindagesh'] = 0xFB36;
  8769. t['zayindageshhebrew'] = 0xFB36;
  8770. t['zayinhebrew'] = 0x05D6;
  8771. t['zbopomofo'] = 0x3117;
  8772. t['zcaron'] = 0x017E;
  8773. t['zcircle'] = 0x24E9;
  8774. t['zcircumflex'] = 0x1E91;
  8775. t['zcurl'] = 0x0291;
  8776. t['zdot'] = 0x017C;
  8777. t['zdotaccent'] = 0x017C;
  8778. t['zdotbelow'] = 0x1E93;
  8779. t['zecyrillic'] = 0x0437;
  8780. t['zedescendercyrillic'] = 0x0499;
  8781. t['zedieresiscyrillic'] = 0x04DF;
  8782. t['zehiragana'] = 0x305C;
  8783. t['zekatakana'] = 0x30BC;
  8784. t['zero'] = 0x0030;
  8785. t['zeroarabic'] = 0x0660;
  8786. t['zerobengali'] = 0x09E6;
  8787. t['zerodeva'] = 0x0966;
  8788. t['zerogujarati'] = 0x0AE6;
  8789. t['zerogurmukhi'] = 0x0A66;
  8790. t['zerohackarabic'] = 0x0660;
  8791. t['zeroinferior'] = 0x2080;
  8792. t['zeromonospace'] = 0xFF10;
  8793. t['zerooldstyle'] = 0xF730;
  8794. t['zeropersian'] = 0x06F0;
  8795. t['zerosuperior'] = 0x2070;
  8796. t['zerothai'] = 0x0E50;
  8797. t['zerowidthjoiner'] = 0xFEFF;
  8798. t['zerowidthnonjoiner'] = 0x200C;
  8799. t['zerowidthspace'] = 0x200B;
  8800. t['zeta'] = 0x03B6;
  8801. t['zhbopomofo'] = 0x3113;
  8802. t['zhearmenian'] = 0x056A;
  8803. t['zhebrevecyrillic'] = 0x04C2;
  8804. t['zhecyrillic'] = 0x0436;
  8805. t['zhedescendercyrillic'] = 0x0497;
  8806. t['zhedieresiscyrillic'] = 0x04DD;
  8807. t['zihiragana'] = 0x3058;
  8808. t['zikatakana'] = 0x30B8;
  8809. t['zinorhebrew'] = 0x05AE;
  8810. t['zlinebelow'] = 0x1E95;
  8811. t['zmonospace'] = 0xFF5A;
  8812. t['zohiragana'] = 0x305E;
  8813. t['zokatakana'] = 0x30BE;
  8814. t['zparen'] = 0x24B5;
  8815. t['zretroflexhook'] = 0x0290;
  8816. t['zstroke'] = 0x01B6;
  8817. t['zuhiragana'] = 0x305A;
  8818. t['zukatakana'] = 0x30BA;
  8819. t['.notdef'] = 0x0000;
  8820. });
  8821. var getDingbatsGlyphsUnicode = getLookupTableFactory(function (t) {
  8822. t['space'] = 0x0020;
  8823. t['a1'] = 0x2701;
  8824. t['a2'] = 0x2702;
  8825. t['a202'] = 0x2703;
  8826. t['a3'] = 0x2704;
  8827. t['a4'] = 0x260E;
  8828. t['a5'] = 0x2706;
  8829. t['a119'] = 0x2707;
  8830. t['a118'] = 0x2708;
  8831. t['a117'] = 0x2709;
  8832. t['a11'] = 0x261B;
  8833. t['a12'] = 0x261E;
  8834. t['a13'] = 0x270C;
  8835. t['a14'] = 0x270D;
  8836. t['a15'] = 0x270E;
  8837. t['a16'] = 0x270F;
  8838. t['a105'] = 0x2710;
  8839. t['a17'] = 0x2711;
  8840. t['a18'] = 0x2712;
  8841. t['a19'] = 0x2713;
  8842. t['a20'] = 0x2714;
  8843. t['a21'] = 0x2715;
  8844. t['a22'] = 0x2716;
  8845. t['a23'] = 0x2717;
  8846. t['a24'] = 0x2718;
  8847. t['a25'] = 0x2719;
  8848. t['a26'] = 0x271A;
  8849. t['a27'] = 0x271B;
  8850. t['a28'] = 0x271C;
  8851. t['a6'] = 0x271D;
  8852. t['a7'] = 0x271E;
  8853. t['a8'] = 0x271F;
  8854. t['a9'] = 0x2720;
  8855. t['a10'] = 0x2721;
  8856. t['a29'] = 0x2722;
  8857. t['a30'] = 0x2723;
  8858. t['a31'] = 0x2724;
  8859. t['a32'] = 0x2725;
  8860. t['a33'] = 0x2726;
  8861. t['a34'] = 0x2727;
  8862. t['a35'] = 0x2605;
  8863. t['a36'] = 0x2729;
  8864. t['a37'] = 0x272A;
  8865. t['a38'] = 0x272B;
  8866. t['a39'] = 0x272C;
  8867. t['a40'] = 0x272D;
  8868. t['a41'] = 0x272E;
  8869. t['a42'] = 0x272F;
  8870. t['a43'] = 0x2730;
  8871. t['a44'] = 0x2731;
  8872. t['a45'] = 0x2732;
  8873. t['a46'] = 0x2733;
  8874. t['a47'] = 0x2734;
  8875. t['a48'] = 0x2735;
  8876. t['a49'] = 0x2736;
  8877. t['a50'] = 0x2737;
  8878. t['a51'] = 0x2738;
  8879. t['a52'] = 0x2739;
  8880. t['a53'] = 0x273A;
  8881. t['a54'] = 0x273B;
  8882. t['a55'] = 0x273C;
  8883. t['a56'] = 0x273D;
  8884. t['a57'] = 0x273E;
  8885. t['a58'] = 0x273F;
  8886. t['a59'] = 0x2740;
  8887. t['a60'] = 0x2741;
  8888. t['a61'] = 0x2742;
  8889. t['a62'] = 0x2743;
  8890. t['a63'] = 0x2744;
  8891. t['a64'] = 0x2745;
  8892. t['a65'] = 0x2746;
  8893. t['a66'] = 0x2747;
  8894. t['a67'] = 0x2748;
  8895. t['a68'] = 0x2749;
  8896. t['a69'] = 0x274A;
  8897. t['a70'] = 0x274B;
  8898. t['a71'] = 0x25CF;
  8899. t['a72'] = 0x274D;
  8900. t['a73'] = 0x25A0;
  8901. t['a74'] = 0x274F;
  8902. t['a203'] = 0x2750;
  8903. t['a75'] = 0x2751;
  8904. t['a204'] = 0x2752;
  8905. t['a76'] = 0x25B2;
  8906. t['a77'] = 0x25BC;
  8907. t['a78'] = 0x25C6;
  8908. t['a79'] = 0x2756;
  8909. t['a81'] = 0x25D7;
  8910. t['a82'] = 0x2758;
  8911. t['a83'] = 0x2759;
  8912. t['a84'] = 0x275A;
  8913. t['a97'] = 0x275B;
  8914. t['a98'] = 0x275C;
  8915. t['a99'] = 0x275D;
  8916. t['a100'] = 0x275E;
  8917. t['a101'] = 0x2761;
  8918. t['a102'] = 0x2762;
  8919. t['a103'] = 0x2763;
  8920. t['a104'] = 0x2764;
  8921. t['a106'] = 0x2765;
  8922. t['a107'] = 0x2766;
  8923. t['a108'] = 0x2767;
  8924. t['a112'] = 0x2663;
  8925. t['a111'] = 0x2666;
  8926. t['a110'] = 0x2665;
  8927. t['a109'] = 0x2660;
  8928. t['a120'] = 0x2460;
  8929. t['a121'] = 0x2461;
  8930. t['a122'] = 0x2462;
  8931. t['a123'] = 0x2463;
  8932. t['a124'] = 0x2464;
  8933. t['a125'] = 0x2465;
  8934. t['a126'] = 0x2466;
  8935. t['a127'] = 0x2467;
  8936. t['a128'] = 0x2468;
  8937. t['a129'] = 0x2469;
  8938. t['a130'] = 0x2776;
  8939. t['a131'] = 0x2777;
  8940. t['a132'] = 0x2778;
  8941. t['a133'] = 0x2779;
  8942. t['a134'] = 0x277A;
  8943. t['a135'] = 0x277B;
  8944. t['a136'] = 0x277C;
  8945. t['a137'] = 0x277D;
  8946. t['a138'] = 0x277E;
  8947. t['a139'] = 0x277F;
  8948. t['a140'] = 0x2780;
  8949. t['a141'] = 0x2781;
  8950. t['a142'] = 0x2782;
  8951. t['a143'] = 0x2783;
  8952. t['a144'] = 0x2784;
  8953. t['a145'] = 0x2785;
  8954. t['a146'] = 0x2786;
  8955. t['a147'] = 0x2787;
  8956. t['a148'] = 0x2788;
  8957. t['a149'] = 0x2789;
  8958. t['a150'] = 0x278A;
  8959. t['a151'] = 0x278B;
  8960. t['a152'] = 0x278C;
  8961. t['a153'] = 0x278D;
  8962. t['a154'] = 0x278E;
  8963. t['a155'] = 0x278F;
  8964. t['a156'] = 0x2790;
  8965. t['a157'] = 0x2791;
  8966. t['a158'] = 0x2792;
  8967. t['a159'] = 0x2793;
  8968. t['a160'] = 0x2794;
  8969. t['a161'] = 0x2192;
  8970. t['a163'] = 0x2194;
  8971. t['a164'] = 0x2195;
  8972. t['a196'] = 0x2798;
  8973. t['a165'] = 0x2799;
  8974. t['a192'] = 0x279A;
  8975. t['a166'] = 0x279B;
  8976. t['a167'] = 0x279C;
  8977. t['a168'] = 0x279D;
  8978. t['a169'] = 0x279E;
  8979. t['a170'] = 0x279F;
  8980. t['a171'] = 0x27A0;
  8981. t['a172'] = 0x27A1;
  8982. t['a173'] = 0x27A2;
  8983. t['a162'] = 0x27A3;
  8984. t['a174'] = 0x27A4;
  8985. t['a175'] = 0x27A5;
  8986. t['a176'] = 0x27A6;
  8987. t['a177'] = 0x27A7;
  8988. t['a178'] = 0x27A8;
  8989. t['a179'] = 0x27A9;
  8990. t['a193'] = 0x27AA;
  8991. t['a180'] = 0x27AB;
  8992. t['a199'] = 0x27AC;
  8993. t['a181'] = 0x27AD;
  8994. t['a200'] = 0x27AE;
  8995. t['a182'] = 0x27AF;
  8996. t['a201'] = 0x27B1;
  8997. t['a183'] = 0x27B2;
  8998. t['a184'] = 0x27B3;
  8999. t['a197'] = 0x27B4;
  9000. t['a185'] = 0x27B5;
  9001. t['a194'] = 0x27B6;
  9002. t['a198'] = 0x27B7;
  9003. t['a186'] = 0x27B8;
  9004. t['a195'] = 0x27B9;
  9005. t['a187'] = 0x27BA;
  9006. t['a188'] = 0x27BB;
  9007. t['a189'] = 0x27BC;
  9008. t['a190'] = 0x27BD;
  9009. t['a191'] = 0x27BE;
  9010. t['a89'] = 0x2768; // 0xF8D7
  9011. t['a90'] = 0x2769; // 0xF8D8
  9012. t['a93'] = 0x276A; // 0xF8D9
  9013. t['a94'] = 0x276B; // 0xF8DA
  9014. t['a91'] = 0x276C; // 0xF8DB
  9015. t['a92'] = 0x276D; // 0xF8DC
  9016. t['a205'] = 0x276E; // 0xF8DD
  9017. t['a85'] = 0x276F; // 0xF8DE
  9018. t['a206'] = 0x2770; // 0xF8DF
  9019. t['a86'] = 0x2771; // 0xF8E0
  9020. t['a87'] = 0x2772; // 0xF8E1
  9021. t['a88'] = 0x2773; // 0xF8E2
  9022. t['a95'] = 0x2774; // 0xF8E3
  9023. t['a96'] = 0x2775; // 0xF8E4
  9024. t['.notdef'] = 0x0000;
  9025. });
  9026. exports.getGlyphsUnicode = getGlyphsUnicode;
  9027. exports.getDingbatsGlyphsUnicode = getDingbatsGlyphsUnicode;
  9028. }));
  9029. (function (root, factory) {
  9030. {
  9031. factory((root.pdfjsCoreJbig2 = {}), root.pdfjsSharedUtil,
  9032. root.pdfjsCoreArithmeticDecoder);
  9033. }
  9034. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  9035. var error = sharedUtil.error;
  9036. var log2 = sharedUtil.log2;
  9037. var readInt8 = sharedUtil.readInt8;
  9038. var readUint16 = sharedUtil.readUint16;
  9039. var readUint32 = sharedUtil.readUint32;
  9040. var shadow = sharedUtil.shadow;
  9041. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  9042. var Jbig2Image = (function Jbig2ImageClosure() {
  9043. // Utility data structures
  9044. function ContextCache() {}
  9045. ContextCache.prototype = {
  9046. getContexts: function(id) {
  9047. if (id in this) {
  9048. return this[id];
  9049. }
  9050. return (this[id] = new Int8Array(1 << 16));
  9051. }
  9052. };
  9053. function DecodingContext(data, start, end) {
  9054. this.data = data;
  9055. this.start = start;
  9056. this.end = end;
  9057. }
  9058. DecodingContext.prototype = {
  9059. get decoder() {
  9060. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  9061. return shadow(this, 'decoder', decoder);
  9062. },
  9063. get contextCache() {
  9064. var cache = new ContextCache();
  9065. return shadow(this, 'contextCache', cache);
  9066. }
  9067. };
  9068. // Annex A. Arithmetic Integer Decoding Procedure
  9069. // A.2 Procedure for decoding values
  9070. function decodeInteger(contextCache, procedure, decoder) {
  9071. var contexts = contextCache.getContexts(procedure);
  9072. var prev = 1;
  9073. function readBits(length) {
  9074. var v = 0;
  9075. for (var i = 0; i < length; i++) {
  9076. var bit = decoder.readBit(contexts, prev);
  9077. prev = (prev < 256 ? (prev << 1) | bit :
  9078. (((prev << 1) | bit) & 511) | 256);
  9079. v = (v << 1) | bit;
  9080. }
  9081. return v >>> 0;
  9082. }
  9083. var sign = readBits(1);
  9084. var value = readBits(1) ?
  9085. (readBits(1) ?
  9086. (readBits(1) ?
  9087. (readBits(1) ?
  9088. (readBits(1) ?
  9089. (readBits(32) + 4436) :
  9090. readBits(12) + 340) :
  9091. readBits(8) + 84) :
  9092. readBits(6) + 20) :
  9093. readBits(4) + 4) :
  9094. readBits(2);
  9095. return (sign === 0 ? value : (value > 0 ? -value : null));
  9096. }
  9097. // A.3 The IAID decoding procedure
  9098. function decodeIAID(contextCache, decoder, codeLength) {
  9099. var contexts = contextCache.getContexts('IAID');
  9100. var prev = 1;
  9101. for (var i = 0; i < codeLength; i++) {
  9102. var bit = decoder.readBit(contexts, prev);
  9103. prev = (prev << 1) | bit;
  9104. }
  9105. if (codeLength < 31) {
  9106. return prev & ((1 << codeLength) - 1);
  9107. }
  9108. return prev & 0x7FFFFFFF;
  9109. }
  9110. // 7.3 Segment types
  9111. var SegmentTypes = [
  9112. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  9113. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  9114. null, null, null, null, null, 'patternDictionary', null, null, null,
  9115. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  9116. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  9117. null, null, null, null, null, 'IntermediateGenericRegion', null,
  9118. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  9119. 'IntermediateGenericRefinementRegion', null,
  9120. 'ImmediateGenericRefinementRegion',
  9121. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  9122. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  9123. 'Tables', null, null, null, null, null, null, null, null,
  9124. 'Extension'
  9125. ];
  9126. var CodingTemplates = [
  9127. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  9128. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  9129. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  9130. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  9131. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  9132. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  9133. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  9134. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  9135. {x: -1, y: 0}],
  9136. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  9137. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  9138. ];
  9139. var RefinementTemplates = [
  9140. {
  9141. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  9142. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  9143. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  9144. },
  9145. {
  9146. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  9147. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  9148. {x: 0, y: 1}, {x: 1, y: 1}]
  9149. }
  9150. ];
  9151. // See 6.2.5.7 Decoding the bitmap.
  9152. var ReusedContexts = [
  9153. 0x9B25, // 10011 0110010 0101
  9154. 0x0795, // 0011 110010 101
  9155. 0x00E5, // 001 11001 01
  9156. 0x0195 // 011001 0101
  9157. ];
  9158. var RefinementReusedContexts = [
  9159. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  9160. 0x0008 // '0000' + '001000'
  9161. ];
  9162. function decodeBitmapTemplate0(width, height, decodingContext) {
  9163. var decoder = decodingContext.decoder;
  9164. var contexts = decodingContext.contextCache.getContexts('GB');
  9165. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  9166. // ...ooooo....
  9167. // ..ooooooo... Context template for current pixel (X)
  9168. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  9169. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  9170. for (i = 0; i < height; i++) {
  9171. row = bitmap[i] = new Uint8Array(width);
  9172. row1 = (i < 1) ? row : bitmap[i - 1];
  9173. row2 = (i < 2) ? row : bitmap[i - 2];
  9174. // At the beginning of each row:
  9175. // Fill contextLabel with pixels that are above/right of (X)
  9176. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  9177. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  9178. (row1[3] << 4);
  9179. for (j = 0; j < width; j++) {
  9180. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  9181. // At each pixel: Clear contextLabel pixels that are shifted
  9182. // out of the context, then add new ones.
  9183. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  9184. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  9185. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  9186. }
  9187. }
  9188. return bitmap;
  9189. }
  9190. // 6.2 Generic Region Decoding Procedure
  9191. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  9192. decodingContext) {
  9193. if (mmr) {
  9194. error('JBIG2 error: MMR encoding is not supported');
  9195. }
  9196. // Use optimized version for the most common case
  9197. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  9198. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  9199. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  9200. return decodeBitmapTemplate0(width, height, decodingContext);
  9201. }
  9202. var useskip = !!skip;
  9203. var template = CodingTemplates[templateIndex].concat(at);
  9204. // Sorting is non-standard, and it is not required. But sorting increases
  9205. // the number of template bits that can be reused from the previous
  9206. // contextLabel in the main loop.
  9207. template.sort(function (a, b) {
  9208. return (a.y - b.y) || (a.x - b.x);
  9209. });
  9210. var templateLength = template.length;
  9211. var templateX = new Int8Array(templateLength);
  9212. var templateY = new Int8Array(templateLength);
  9213. var changingTemplateEntries = [];
  9214. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  9215. var c, k;
  9216. for (k = 0; k < templateLength; k++) {
  9217. templateX[k] = template[k].x;
  9218. templateY[k] = template[k].y;
  9219. minX = Math.min(minX, template[k].x);
  9220. maxX = Math.max(maxX, template[k].x);
  9221. minY = Math.min(minY, template[k].y);
  9222. // Check if the template pixel appears in two consecutive context labels,
  9223. // so it can be reused. Otherwise, we add it to the list of changing
  9224. // template entries.
  9225. if (k < templateLength - 1 &&
  9226. template[k].y === template[k + 1].y &&
  9227. template[k].x === template[k + 1].x - 1) {
  9228. reuseMask |= 1 << (templateLength - 1 - k);
  9229. } else {
  9230. changingTemplateEntries.push(k);
  9231. }
  9232. }
  9233. var changingEntriesLength = changingTemplateEntries.length;
  9234. var changingTemplateX = new Int8Array(changingEntriesLength);
  9235. var changingTemplateY = new Int8Array(changingEntriesLength);
  9236. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  9237. for (c = 0; c < changingEntriesLength; c++) {
  9238. k = changingTemplateEntries[c];
  9239. changingTemplateX[c] = template[k].x;
  9240. changingTemplateY[c] = template[k].y;
  9241. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  9242. }
  9243. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  9244. var sbb_left = -minX;
  9245. var sbb_top = -minY;
  9246. var sbb_right = width - maxX;
  9247. var pseudoPixelContext = ReusedContexts[templateIndex];
  9248. var row = new Uint8Array(width);
  9249. var bitmap = [];
  9250. var decoder = decodingContext.decoder;
  9251. var contexts = decodingContext.contextCache.getContexts('GB');
  9252. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  9253. for (var i = 0; i < height; i++) {
  9254. if (prediction) {
  9255. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  9256. ltp ^= sltp;
  9257. if (ltp) {
  9258. bitmap.push(row); // duplicate previous row
  9259. continue;
  9260. }
  9261. }
  9262. row = new Uint8Array(row);
  9263. bitmap.push(row);
  9264. for (j = 0; j < width; j++) {
  9265. if (useskip && skip[i][j]) {
  9266. row[j] = 0;
  9267. continue;
  9268. }
  9269. // Are we in the middle of a scanline, so we can reuse contextLabel
  9270. // bits?
  9271. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  9272. // If yes, we can just shift the bits that are reusable and only
  9273. // fetch the remaining ones.
  9274. contextLabel = (contextLabel << 1) & reuseMask;
  9275. for (k = 0; k < changingEntriesLength; k++) {
  9276. i0 = i + changingTemplateY[k];
  9277. j0 = j + changingTemplateX[k];
  9278. bit = bitmap[i0][j0];
  9279. if (bit) {
  9280. bit = changingTemplateBit[k];
  9281. contextLabel |= bit;
  9282. }
  9283. }
  9284. } else {
  9285. // compute the contextLabel from scratch
  9286. contextLabel = 0;
  9287. shift = templateLength - 1;
  9288. for (k = 0; k < templateLength; k++, shift--) {
  9289. j0 = j + templateX[k];
  9290. if (j0 >= 0 && j0 < width) {
  9291. i0 = i + templateY[k];
  9292. if (i0 >= 0) {
  9293. bit = bitmap[i0][j0];
  9294. if (bit) {
  9295. contextLabel |= bit << shift;
  9296. }
  9297. }
  9298. }
  9299. }
  9300. }
  9301. var pixel = decoder.readBit(contexts, contextLabel);
  9302. row[j] = pixel;
  9303. }
  9304. }
  9305. return bitmap;
  9306. }
  9307. // 6.3.2 Generic Refinement Region Decoding Procedure
  9308. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  9309. offsetX, offsetY, prediction, at,
  9310. decodingContext) {
  9311. var codingTemplate = RefinementTemplates[templateIndex].coding;
  9312. if (templateIndex === 0) {
  9313. codingTemplate = codingTemplate.concat([at[0]]);
  9314. }
  9315. var codingTemplateLength = codingTemplate.length;
  9316. var codingTemplateX = new Int32Array(codingTemplateLength);
  9317. var codingTemplateY = new Int32Array(codingTemplateLength);
  9318. var k;
  9319. for (k = 0; k < codingTemplateLength; k++) {
  9320. codingTemplateX[k] = codingTemplate[k].x;
  9321. codingTemplateY[k] = codingTemplate[k].y;
  9322. }
  9323. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  9324. if (templateIndex === 0) {
  9325. referenceTemplate = referenceTemplate.concat([at[1]]);
  9326. }
  9327. var referenceTemplateLength = referenceTemplate.length;
  9328. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  9329. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  9330. for (k = 0; k < referenceTemplateLength; k++) {
  9331. referenceTemplateX[k] = referenceTemplate[k].x;
  9332. referenceTemplateY[k] = referenceTemplate[k].y;
  9333. }
  9334. var referenceWidth = referenceBitmap[0].length;
  9335. var referenceHeight = referenceBitmap.length;
  9336. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  9337. var bitmap = [];
  9338. var decoder = decodingContext.decoder;
  9339. var contexts = decodingContext.contextCache.getContexts('GR');
  9340. var ltp = 0;
  9341. for (var i = 0; i < height; i++) {
  9342. if (prediction) {
  9343. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  9344. ltp ^= sltp;
  9345. if (ltp) {
  9346. error('JBIG2 error: prediction is not supported');
  9347. }
  9348. }
  9349. var row = new Uint8Array(width);
  9350. bitmap.push(row);
  9351. for (var j = 0; j < width; j++) {
  9352. var i0, j0;
  9353. var contextLabel = 0;
  9354. for (k = 0; k < codingTemplateLength; k++) {
  9355. i0 = i + codingTemplateY[k];
  9356. j0 = j + codingTemplateX[k];
  9357. if (i0 < 0 || j0 < 0 || j0 >= width) {
  9358. contextLabel <<= 1; // out of bound pixel
  9359. } else {
  9360. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  9361. }
  9362. }
  9363. for (k = 0; k < referenceTemplateLength; k++) {
  9364. i0 = i + referenceTemplateY[k] + offsetY;
  9365. j0 = j + referenceTemplateX[k] + offsetX;
  9366. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  9367. j0 >= referenceWidth) {
  9368. contextLabel <<= 1; // out of bound pixel
  9369. } else {
  9370. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  9371. }
  9372. }
  9373. var pixel = decoder.readBit(contexts, contextLabel);
  9374. row[j] = pixel;
  9375. }
  9376. }
  9377. return bitmap;
  9378. }
  9379. // 6.5.5 Decoding the symbol dictionary
  9380. function decodeSymbolDictionary(huffman, refinement, symbols,
  9381. numberOfNewSymbols, numberOfExportedSymbols,
  9382. huffmanTables, templateIndex, at,
  9383. refinementTemplateIndex, refinementAt,
  9384. decodingContext) {
  9385. if (huffman) {
  9386. error('JBIG2 error: huffman is not supported');
  9387. }
  9388. var newSymbols = [];
  9389. var currentHeight = 0;
  9390. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  9391. var decoder = decodingContext.decoder;
  9392. var contextCache = decodingContext.contextCache;
  9393. while (newSymbols.length < numberOfNewSymbols) {
  9394. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  9395. currentHeight += deltaHeight;
  9396. var currentWidth = 0;
  9397. var totalWidth = 0;
  9398. while (true) {
  9399. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  9400. if (deltaWidth === null) {
  9401. break; // OOB
  9402. }
  9403. currentWidth += deltaWidth;
  9404. totalWidth += currentWidth;
  9405. var bitmap;
  9406. if (refinement) {
  9407. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  9408. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  9409. if (numberOfInstances > 1) {
  9410. bitmap = decodeTextRegion(huffman, refinement,
  9411. currentWidth, currentHeight, 0,
  9412. numberOfInstances, 1, //strip size
  9413. symbols.concat(newSymbols),
  9414. symbolCodeLength,
  9415. 0, //transposed
  9416. 0, //ds offset
  9417. 1, //top left 7.4.3.1.1
  9418. 0, //OR operator
  9419. huffmanTables,
  9420. refinementTemplateIndex, refinementAt,
  9421. decodingContext);
  9422. } else {
  9423. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  9424. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  9425. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  9426. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  9427. newSymbols[symbolId - symbols.length]);
  9428. bitmap = decodeRefinement(currentWidth, currentHeight,
  9429. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  9430. decodingContext);
  9431. }
  9432. } else {
  9433. // 6.5.8.1 Direct-coded symbol bitmap
  9434. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  9435. templateIndex, false, null, at, decodingContext);
  9436. }
  9437. newSymbols.push(bitmap);
  9438. }
  9439. }
  9440. // 6.5.10 Exported symbols
  9441. var exportedSymbols = [];
  9442. var flags = [], currentFlag = false;
  9443. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  9444. while (flags.length < totalSymbolsLength) {
  9445. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  9446. while (runLength--) {
  9447. flags.push(currentFlag);
  9448. }
  9449. currentFlag = !currentFlag;
  9450. }
  9451. for (var i = 0, ii = symbols.length; i < ii; i++) {
  9452. if (flags[i]) {
  9453. exportedSymbols.push(symbols[i]);
  9454. }
  9455. }
  9456. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  9457. if (flags[i]) {
  9458. exportedSymbols.push(newSymbols[j]);
  9459. }
  9460. }
  9461. return exportedSymbols;
  9462. }
  9463. function decodeTextRegion(huffman, refinement, width, height,
  9464. defaultPixelValue, numberOfSymbolInstances,
  9465. stripSize, inputSymbols, symbolCodeLength,
  9466. transposed, dsOffset, referenceCorner,
  9467. combinationOperator, huffmanTables,
  9468. refinementTemplateIndex, refinementAt,
  9469. decodingContext) {
  9470. if (huffman) {
  9471. error('JBIG2 error: huffman is not supported');
  9472. }
  9473. // Prepare bitmap
  9474. var bitmap = [];
  9475. var i, row;
  9476. for (i = 0; i < height; i++) {
  9477. row = new Uint8Array(width);
  9478. if (defaultPixelValue) {
  9479. for (var j = 0; j < width; j++) {
  9480. row[j] = defaultPixelValue;
  9481. }
  9482. }
  9483. bitmap.push(row);
  9484. }
  9485. var decoder = decodingContext.decoder;
  9486. var contextCache = decodingContext.contextCache;
  9487. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  9488. var firstS = 0;
  9489. i = 0;
  9490. while (i < numberOfSymbolInstances) {
  9491. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  9492. stripT += deltaT;
  9493. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  9494. firstS += deltaFirstS;
  9495. var currentS = firstS;
  9496. do {
  9497. var currentT = (stripSize === 1 ? 0 :
  9498. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  9499. var t = stripSize * stripT + currentT;
  9500. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  9501. var applyRefinement = (refinement &&
  9502. decodeInteger(contextCache, 'IARI', decoder));
  9503. var symbolBitmap = inputSymbols[symbolId];
  9504. var symbolWidth = symbolBitmap[0].length;
  9505. var symbolHeight = symbolBitmap.length;
  9506. if (applyRefinement) {
  9507. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  9508. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  9509. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  9510. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  9511. symbolWidth += rdw;
  9512. symbolHeight += rdh;
  9513. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  9514. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  9515. (rdh >> 1) + rdy, false, refinementAt,
  9516. decodingContext);
  9517. }
  9518. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  9519. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  9520. var s2, t2, symbolRow;
  9521. if (transposed) {
  9522. // Place Symbol Bitmap from T1,S1
  9523. for (s2 = 0; s2 < symbolHeight; s2++) {
  9524. row = bitmap[offsetS + s2];
  9525. if (!row) {
  9526. continue;
  9527. }
  9528. symbolRow = symbolBitmap[s2];
  9529. // To ignore Parts of Symbol bitmap which goes
  9530. // outside bitmap region
  9531. var maxWidth = Math.min(width - offsetT, symbolWidth);
  9532. switch (combinationOperator) {
  9533. case 0: // OR
  9534. for (t2 = 0; t2 < maxWidth; t2++) {
  9535. row[offsetT + t2] |= symbolRow[t2];
  9536. }
  9537. break;
  9538. case 2: // XOR
  9539. for (t2 = 0; t2 < maxWidth; t2++) {
  9540. row[offsetT + t2] ^= symbolRow[t2];
  9541. }
  9542. break;
  9543. default:
  9544. error('JBIG2 error: operator ' + combinationOperator +
  9545. ' is not supported');
  9546. }
  9547. }
  9548. currentS += symbolHeight - 1;
  9549. } else {
  9550. for (t2 = 0; t2 < symbolHeight; t2++) {
  9551. row = bitmap[offsetT + t2];
  9552. if (!row) {
  9553. continue;
  9554. }
  9555. symbolRow = symbolBitmap[t2];
  9556. switch (combinationOperator) {
  9557. case 0: // OR
  9558. for (s2 = 0; s2 < symbolWidth; s2++) {
  9559. row[offsetS + s2] |= symbolRow[s2];
  9560. }
  9561. break;
  9562. case 2: // XOR
  9563. for (s2 = 0; s2 < symbolWidth; s2++) {
  9564. row[offsetS + s2] ^= symbolRow[s2];
  9565. }
  9566. break;
  9567. default:
  9568. error('JBIG2 error: operator ' + combinationOperator +
  9569. ' is not supported');
  9570. }
  9571. }
  9572. currentS += symbolWidth - 1;
  9573. }
  9574. i++;
  9575. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  9576. if (deltaS === null) {
  9577. break; // OOB
  9578. }
  9579. currentS += deltaS + dsOffset;
  9580. } while (true);
  9581. }
  9582. return bitmap;
  9583. }
  9584. function readSegmentHeader(data, start) {
  9585. var segmentHeader = {};
  9586. segmentHeader.number = readUint32(data, start);
  9587. var flags = data[start + 4];
  9588. var segmentType = flags & 0x3F;
  9589. if (!SegmentTypes[segmentType]) {
  9590. error('JBIG2 error: invalid segment type: ' + segmentType);
  9591. }
  9592. segmentHeader.type = segmentType;
  9593. segmentHeader.typeName = SegmentTypes[segmentType];
  9594. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  9595. var pageAssociationFieldSize = !!(flags & 0x40);
  9596. var referredFlags = data[start + 5];
  9597. var referredToCount = (referredFlags >> 5) & 7;
  9598. var retainBits = [referredFlags & 31];
  9599. var position = start + 6;
  9600. if (referredFlags === 7) {
  9601. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  9602. position += 3;
  9603. var bytes = (referredToCount + 7) >> 3;
  9604. retainBits[0] = data[position++];
  9605. while (--bytes > 0) {
  9606. retainBits.push(data[position++]);
  9607. }
  9608. } else if (referredFlags === 5 || referredFlags === 6) {
  9609. error('JBIG2 error: invalid referred-to flags');
  9610. }
  9611. segmentHeader.retainBits = retainBits;
  9612. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  9613. (segmentHeader.number <= 65536 ? 2 : 4));
  9614. var referredTo = [];
  9615. var i, ii;
  9616. for (i = 0; i < referredToCount; i++) {
  9617. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  9618. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  9619. readUint32(data, position)));
  9620. referredTo.push(number);
  9621. position += referredToSegmentNumberSize;
  9622. }
  9623. segmentHeader.referredTo = referredTo;
  9624. if (!pageAssociationFieldSize) {
  9625. segmentHeader.pageAssociation = data[position++];
  9626. } else {
  9627. segmentHeader.pageAssociation = readUint32(data, position);
  9628. position += 4;
  9629. }
  9630. segmentHeader.length = readUint32(data, position);
  9631. position += 4;
  9632. if (segmentHeader.length === 0xFFFFFFFF) {
  9633. // 7.2.7 Segment data length, unknown segment length
  9634. if (segmentType === 38) { // ImmediateGenericRegion
  9635. var genericRegionInfo = readRegionSegmentInformation(data, position);
  9636. var genericRegionSegmentFlags = data[position +
  9637. RegionSegmentInformationFieldLength];
  9638. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  9639. // searching for the segment end
  9640. var searchPatternLength = 6;
  9641. var searchPattern = new Uint8Array(searchPatternLength);
  9642. if (!genericRegionMmr) {
  9643. searchPattern[0] = 0xFF;
  9644. searchPattern[1] = 0xAC;
  9645. }
  9646. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  9647. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  9648. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  9649. searchPattern[5] = genericRegionInfo.height & 0xFF;
  9650. for (i = position, ii = data.length; i < ii; i++) {
  9651. var j = 0;
  9652. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  9653. j++;
  9654. }
  9655. if (j === searchPatternLength) {
  9656. segmentHeader.length = i + searchPatternLength;
  9657. break;
  9658. }
  9659. }
  9660. if (segmentHeader.length === 0xFFFFFFFF) {
  9661. error('JBIG2 error: segment end was not found');
  9662. }
  9663. } else {
  9664. error('JBIG2 error: invalid unknown segment length');
  9665. }
  9666. }
  9667. segmentHeader.headerEnd = position;
  9668. return segmentHeader;
  9669. }
  9670. function readSegments(header, data, start, end) {
  9671. var segments = [];
  9672. var position = start;
  9673. while (position < end) {
  9674. var segmentHeader = readSegmentHeader(data, position);
  9675. position = segmentHeader.headerEnd;
  9676. var segment = {
  9677. header: segmentHeader,
  9678. data: data
  9679. };
  9680. if (!header.randomAccess) {
  9681. segment.start = position;
  9682. position += segmentHeader.length;
  9683. segment.end = position;
  9684. }
  9685. segments.push(segment);
  9686. if (segmentHeader.type === 51) {
  9687. break; // end of file is found
  9688. }
  9689. }
  9690. if (header.randomAccess) {
  9691. for (var i = 0, ii = segments.length; i < ii; i++) {
  9692. segments[i].start = position;
  9693. position += segments[i].header.length;
  9694. segments[i].end = position;
  9695. }
  9696. }
  9697. return segments;
  9698. }
  9699. // 7.4.1 Region segment information field
  9700. function readRegionSegmentInformation(data, start) {
  9701. return {
  9702. width: readUint32(data, start),
  9703. height: readUint32(data, start + 4),
  9704. x: readUint32(data, start + 8),
  9705. y: readUint32(data, start + 12),
  9706. combinationOperator: data[start + 16] & 7
  9707. };
  9708. }
  9709. var RegionSegmentInformationFieldLength = 17;
  9710. function processSegment(segment, visitor) {
  9711. var header = segment.header;
  9712. var data = segment.data, position = segment.start, end = segment.end;
  9713. var args, at, i, atLength;
  9714. switch (header.type) {
  9715. case 0: // SymbolDictionary
  9716. // 7.4.2 Symbol dictionary segment syntax
  9717. var dictionary = {};
  9718. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  9719. dictionary.huffman = !!(dictionaryFlags & 1);
  9720. dictionary.refinement = !!(dictionaryFlags & 2);
  9721. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  9722. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  9723. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  9724. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  9725. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  9726. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  9727. dictionary.template = (dictionaryFlags >> 10) & 3;
  9728. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  9729. position += 2;
  9730. if (!dictionary.huffman) {
  9731. atLength = dictionary.template === 0 ? 4 : 1;
  9732. at = [];
  9733. for (i = 0; i < atLength; i++) {
  9734. at.push({
  9735. x: readInt8(data, position),
  9736. y: readInt8(data, position + 1)
  9737. });
  9738. position += 2;
  9739. }
  9740. dictionary.at = at;
  9741. }
  9742. if (dictionary.refinement && !dictionary.refinementTemplate) {
  9743. at = [];
  9744. for (i = 0; i < 2; i++) {
  9745. at.push({
  9746. x: readInt8(data, position),
  9747. y: readInt8(data, position + 1)
  9748. });
  9749. position += 2;
  9750. }
  9751. dictionary.refinementAt = at;
  9752. }
  9753. dictionary.numberOfExportedSymbols = readUint32(data, position);
  9754. position += 4;
  9755. dictionary.numberOfNewSymbols = readUint32(data, position);
  9756. position += 4;
  9757. args = [dictionary, header.number, header.referredTo,
  9758. data, position, end];
  9759. break;
  9760. case 6: // ImmediateTextRegion
  9761. case 7: // ImmediateLosslessTextRegion
  9762. var textRegion = {};
  9763. textRegion.info = readRegionSegmentInformation(data, position);
  9764. position += RegionSegmentInformationFieldLength;
  9765. var textRegionSegmentFlags = readUint16(data, position);
  9766. position += 2;
  9767. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  9768. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  9769. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  9770. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  9771. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  9772. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  9773. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  9774. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  9775. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  9776. if (textRegion.huffman) {
  9777. var textRegionHuffmanFlags = readUint16(data, position);
  9778. position += 2;
  9779. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  9780. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  9781. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  9782. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  9783. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  9784. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  9785. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  9786. textRegion.huffmanRefinementSizeSelector =
  9787. !!(textRegionHuffmanFlags & 14);
  9788. }
  9789. if (textRegion.refinement && !textRegion.refinementTemplate) {
  9790. at = [];
  9791. for (i = 0; i < 2; i++) {
  9792. at.push({
  9793. x: readInt8(data, position),
  9794. y: readInt8(data, position + 1)
  9795. });
  9796. position += 2;
  9797. }
  9798. textRegion.refinementAt = at;
  9799. }
  9800. textRegion.numberOfSymbolInstances = readUint32(data, position);
  9801. position += 4;
  9802. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  9803. if (textRegion.huffman) {
  9804. error('JBIG2 error: huffman is not supported');
  9805. }
  9806. args = [textRegion, header.referredTo, data, position, end];
  9807. break;
  9808. case 38: // ImmediateGenericRegion
  9809. case 39: // ImmediateLosslessGenericRegion
  9810. var genericRegion = {};
  9811. genericRegion.info = readRegionSegmentInformation(data, position);
  9812. position += RegionSegmentInformationFieldLength;
  9813. var genericRegionSegmentFlags = data[position++];
  9814. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  9815. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  9816. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  9817. if (!genericRegion.mmr) {
  9818. atLength = genericRegion.template === 0 ? 4 : 1;
  9819. at = [];
  9820. for (i = 0; i < atLength; i++) {
  9821. at.push({
  9822. x: readInt8(data, position),
  9823. y: readInt8(data, position + 1)
  9824. });
  9825. position += 2;
  9826. }
  9827. genericRegion.at = at;
  9828. }
  9829. args = [genericRegion, data, position, end];
  9830. break;
  9831. case 48: // PageInformation
  9832. var pageInfo = {
  9833. width: readUint32(data, position),
  9834. height: readUint32(data, position + 4),
  9835. resolutionX: readUint32(data, position + 8),
  9836. resolutionY: readUint32(data, position + 12)
  9837. };
  9838. if (pageInfo.height === 0xFFFFFFFF) {
  9839. delete pageInfo.height;
  9840. }
  9841. var pageSegmentFlags = data[position + 16];
  9842. var pageStripingInformation = readUint16(data, position + 17);
  9843. pageInfo.lossless = !!(pageSegmentFlags & 1);
  9844. pageInfo.refinement = !!(pageSegmentFlags & 2);
  9845. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  9846. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  9847. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  9848. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  9849. args = [pageInfo];
  9850. break;
  9851. case 49: // EndOfPage
  9852. break;
  9853. case 50: // EndOfStripe
  9854. break;
  9855. case 51: // EndOfFile
  9856. break;
  9857. case 62: // 7.4.15 defines 2 extension types which
  9858. // are comments and can be ignored.
  9859. break;
  9860. default:
  9861. error('JBIG2 error: segment type ' + header.typeName + '(' +
  9862. header.type + ') is not implemented');
  9863. }
  9864. var callbackName = 'on' + header.typeName;
  9865. if (callbackName in visitor) {
  9866. visitor[callbackName].apply(visitor, args);
  9867. }
  9868. }
  9869. function processSegments(segments, visitor) {
  9870. for (var i = 0, ii = segments.length; i < ii; i++) {
  9871. processSegment(segments[i], visitor);
  9872. }
  9873. }
  9874. function parseJbig2(data, start, end) {
  9875. var position = start;
  9876. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  9877. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  9878. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  9879. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  9880. error('JBIG2 error: invalid header');
  9881. }
  9882. var header = {};
  9883. position += 8;
  9884. var flags = data[position++];
  9885. header.randomAccess = !(flags & 1);
  9886. if (!(flags & 2)) {
  9887. header.numberOfPages = readUint32(data, position);
  9888. position += 4;
  9889. }
  9890. var segments = readSegments(header, data, position, end);
  9891. error('Not implemented');
  9892. // processSegments(segments, new SimpleSegmentVisitor());
  9893. }
  9894. function parseJbig2Chunks(chunks) {
  9895. var visitor = new SimpleSegmentVisitor();
  9896. for (var i = 0, ii = chunks.length; i < ii; i++) {
  9897. var chunk = chunks[i];
  9898. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  9899. processSegments(segments, visitor);
  9900. }
  9901. return visitor.buffer;
  9902. }
  9903. function SimpleSegmentVisitor() {}
  9904. SimpleSegmentVisitor.prototype = {
  9905. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  9906. this.currentPageInfo = info;
  9907. var rowSize = (info.width + 7) >> 3;
  9908. var buffer = new Uint8Array(rowSize * info.height);
  9909. // The contents of ArrayBuffers are initialized to 0.
  9910. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  9911. if (info.defaultPixelValue) {
  9912. for (var i = 0, ii = buffer.length; i < ii; i++) {
  9913. buffer[i] = 0xFF;
  9914. }
  9915. }
  9916. this.buffer = buffer;
  9917. },
  9918. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  9919. var pageInfo = this.currentPageInfo;
  9920. var width = regionInfo.width, height = regionInfo.height;
  9921. var rowSize = (pageInfo.width + 7) >> 3;
  9922. var combinationOperator = pageInfo.combinationOperatorOverride ?
  9923. regionInfo.combinationOperator : pageInfo.combinationOperator;
  9924. var buffer = this.buffer;
  9925. var mask0 = 128 >> (regionInfo.x & 7);
  9926. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  9927. var i, j, mask, offset;
  9928. switch (combinationOperator) {
  9929. case 0: // OR
  9930. for (i = 0; i < height; i++) {
  9931. mask = mask0;
  9932. offset = offset0;
  9933. for (j = 0; j < width; j++) {
  9934. if (bitmap[i][j]) {
  9935. buffer[offset] |= mask;
  9936. }
  9937. mask >>= 1;
  9938. if (!mask) {
  9939. mask = 128;
  9940. offset++;
  9941. }
  9942. }
  9943. offset0 += rowSize;
  9944. }
  9945. break;
  9946. case 2: // XOR
  9947. for (i = 0; i < height; i++) {
  9948. mask = mask0;
  9949. offset = offset0;
  9950. for (j = 0; j < width; j++) {
  9951. if (bitmap[i][j]) {
  9952. buffer[offset] ^= mask;
  9953. }
  9954. mask >>= 1;
  9955. if (!mask) {
  9956. mask = 128;
  9957. offset++;
  9958. }
  9959. }
  9960. offset0 += rowSize;
  9961. }
  9962. break;
  9963. default:
  9964. error('JBIG2 error: operator ' + combinationOperator +
  9965. ' is not supported');
  9966. }
  9967. },
  9968. onImmediateGenericRegion:
  9969. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  9970. start, end) {
  9971. var regionInfo = region.info;
  9972. var decodingContext = new DecodingContext(data, start, end);
  9973. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  9974. region.template, region.prediction, null,
  9975. region.at, decodingContext);
  9976. this.drawBitmap(regionInfo, bitmap);
  9977. },
  9978. onImmediateLosslessGenericRegion:
  9979. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  9980. this.onImmediateGenericRegion.apply(this, arguments);
  9981. },
  9982. onSymbolDictionary:
  9983. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  9984. currentSegment,
  9985. referredSegments,
  9986. data, start, end) {
  9987. var huffmanTables;
  9988. if (dictionary.huffman) {
  9989. error('JBIG2 error: huffman is not supported');
  9990. }
  9991. // Combines exported symbols from all referred segments
  9992. var symbols = this.symbols;
  9993. if (!symbols) {
  9994. this.symbols = symbols = {};
  9995. }
  9996. var inputSymbols = [];
  9997. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  9998. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  9999. }
  10000. var decodingContext = new DecodingContext(data, start, end);
  10001. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  10002. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  10003. dictionary.numberOfExportedSymbols, huffmanTables,
  10004. dictionary.template, dictionary.at,
  10005. dictionary.refinementTemplate, dictionary.refinementAt,
  10006. decodingContext);
  10007. },
  10008. onImmediateTextRegion:
  10009. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  10010. referredSegments,
  10011. data, start, end) {
  10012. var regionInfo = region.info;
  10013. var huffmanTables;
  10014. // Combines exported symbols from all referred segments
  10015. var symbols = this.symbols;
  10016. var inputSymbols = [];
  10017. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  10018. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  10019. }
  10020. var symbolCodeLength = log2(inputSymbols.length);
  10021. var decodingContext = new DecodingContext(data, start, end);
  10022. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  10023. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  10024. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  10025. symbolCodeLength, region.transposed, region.dsOffset,
  10026. region.referenceCorner, region.combinationOperator, huffmanTables,
  10027. region.refinementTemplate, region.refinementAt, decodingContext);
  10028. this.drawBitmap(regionInfo, bitmap);
  10029. },
  10030. onImmediateLosslessTextRegion:
  10031. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  10032. this.onImmediateTextRegion.apply(this, arguments);
  10033. }
  10034. };
  10035. function Jbig2Image() {}
  10036. Jbig2Image.prototype = {
  10037. parseChunks: function Jbig2Image_parseChunks(chunks) {
  10038. return parseJbig2Chunks(chunks);
  10039. }
  10040. };
  10041. return Jbig2Image;
  10042. })();
  10043. exports.Jbig2Image = Jbig2Image;
  10044. }));
  10045. (function (root, factory) {
  10046. {
  10047. factory((root.pdfjsCoreJpx = {}), root.pdfjsSharedUtil,
  10048. root.pdfjsCoreArithmeticDecoder);
  10049. }
  10050. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  10051. var info = sharedUtil.info;
  10052. var log2 = sharedUtil.log2;
  10053. var readUint16 = sharedUtil.readUint16;
  10054. var readUint32 = sharedUtil.readUint32;
  10055. var warn = sharedUtil.warn;
  10056. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  10057. var JpxImage = (function JpxImageClosure() {
  10058. // Table E.1
  10059. var SubbandsGainLog2 = {
  10060. 'LL': 0,
  10061. 'LH': 1,
  10062. 'HL': 1,
  10063. 'HH': 2
  10064. };
  10065. function JpxImage() {
  10066. this.failOnCorruptedImage = false;
  10067. }
  10068. JpxImage.prototype = {
  10069. parse: function JpxImage_parse(data) {
  10070. var head = readUint16(data, 0);
  10071. // No box header, immediate start of codestream (SOC)
  10072. if (head === 0xFF4F) {
  10073. this.parseCodestream(data, 0, data.length);
  10074. return;
  10075. }
  10076. var position = 0, length = data.length;
  10077. while (position < length) {
  10078. var headerSize = 8;
  10079. var lbox = readUint32(data, position);
  10080. var tbox = readUint32(data, position + 4);
  10081. position += headerSize;
  10082. if (lbox === 1) {
  10083. // XLBox: read UInt64 according to spec.
  10084. // JavaScript's int precision of 53 bit should be sufficient here.
  10085. lbox = readUint32(data, position) * 4294967296 +
  10086. readUint32(data, position + 4);
  10087. position += 8;
  10088. headerSize += 8;
  10089. }
  10090. if (lbox === 0) {
  10091. lbox = length - position + headerSize;
  10092. }
  10093. if (lbox < headerSize) {
  10094. throw new Error('JPX Error: Invalid box field size');
  10095. }
  10096. var dataLength = lbox - headerSize;
  10097. var jumpDataLength = true;
  10098. switch (tbox) {
  10099. case 0x6A703268: // 'jp2h'
  10100. jumpDataLength = false; // parsing child boxes
  10101. break;
  10102. case 0x636F6C72: // 'colr'
  10103. // Colorspaces are not used, the CS from the PDF is used.
  10104. var method = data[position];
  10105. if (method === 1) {
  10106. // enumerated colorspace
  10107. var colorspace = readUint32(data, position + 3);
  10108. switch (colorspace) {
  10109. case 16: // this indicates a sRGB colorspace
  10110. case 17: // this indicates a grayscale colorspace
  10111. case 18: // this indicates a YUV colorspace
  10112. break;
  10113. default:
  10114. warn('Unknown colorspace ' + colorspace);
  10115. break;
  10116. }
  10117. } else if (method === 2) {
  10118. info('ICC profile not supported');
  10119. }
  10120. break;
  10121. case 0x6A703263: // 'jp2c'
  10122. this.parseCodestream(data, position, position + dataLength);
  10123. break;
  10124. case 0x6A502020: // 'jP\024\024'
  10125. if (0x0d0a870a !== readUint32(data, position)) {
  10126. warn('Invalid JP2 signature');
  10127. }
  10128. break;
  10129. // The following header types are valid but currently not used:
  10130. case 0x6A501A1A: // 'jP\032\032'
  10131. case 0x66747970: // 'ftyp'
  10132. case 0x72726571: // 'rreq'
  10133. case 0x72657320: // 'res '
  10134. case 0x69686472: // 'ihdr'
  10135. break;
  10136. default:
  10137. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  10138. (tbox >> 16) & 0xFF,
  10139. (tbox >> 8) & 0xFF,
  10140. tbox & 0xFF);
  10141. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  10142. break;
  10143. }
  10144. if (jumpDataLength) {
  10145. position += dataLength;
  10146. }
  10147. }
  10148. },
  10149. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  10150. var newByte = stream.getByte();
  10151. while (newByte >= 0) {
  10152. var oldByte = newByte;
  10153. newByte = stream.getByte();
  10154. var code = (oldByte << 8) | newByte;
  10155. // Image and tile size (SIZ)
  10156. if (code === 0xFF51) {
  10157. stream.skip(4);
  10158. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  10159. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  10160. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  10161. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  10162. stream.skip(16);
  10163. var Csiz = stream.getUint16(); // Byte 36
  10164. this.width = Xsiz - XOsiz;
  10165. this.height = Ysiz - YOsiz;
  10166. this.componentsCount = Csiz;
  10167. // Results are always returned as Uint8Arrays
  10168. this.bitsPerComponent = 8;
  10169. return;
  10170. }
  10171. }
  10172. throw new Error('JPX Error: No size marker found in JPX stream');
  10173. },
  10174. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  10175. var context = {};
  10176. try {
  10177. var doNotRecover = false;
  10178. var position = start;
  10179. while (position + 1 < end) {
  10180. var code = readUint16(data, position);
  10181. position += 2;
  10182. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  10183. switch (code) {
  10184. case 0xFF4F: // Start of codestream (SOC)
  10185. context.mainHeader = true;
  10186. break;
  10187. case 0xFFD9: // End of codestream (EOC)
  10188. break;
  10189. case 0xFF51: // Image and tile size (SIZ)
  10190. length = readUint16(data, position);
  10191. var siz = {};
  10192. siz.Xsiz = readUint32(data, position + 4);
  10193. siz.Ysiz = readUint32(data, position + 8);
  10194. siz.XOsiz = readUint32(data, position + 12);
  10195. siz.YOsiz = readUint32(data, position + 16);
  10196. siz.XTsiz = readUint32(data, position + 20);
  10197. siz.YTsiz = readUint32(data, position + 24);
  10198. siz.XTOsiz = readUint32(data, position + 28);
  10199. siz.YTOsiz = readUint32(data, position + 32);
  10200. var componentsCount = readUint16(data, position + 36);
  10201. siz.Csiz = componentsCount;
  10202. var components = [];
  10203. j = position + 38;
  10204. for (var i = 0; i < componentsCount; i++) {
  10205. var component = {
  10206. precision: (data[j] & 0x7F) + 1,
  10207. isSigned: !!(data[j] & 0x80),
  10208. XRsiz: data[j + 1],
  10209. YRsiz: data[j + 1]
  10210. };
  10211. calculateComponentDimensions(component, siz);
  10212. components.push(component);
  10213. }
  10214. context.SIZ = siz;
  10215. context.components = components;
  10216. calculateTileGrids(context, components);
  10217. context.QCC = [];
  10218. context.COC = [];
  10219. break;
  10220. case 0xFF5C: // Quantization default (QCD)
  10221. length = readUint16(data, position);
  10222. var qcd = {};
  10223. j = position + 2;
  10224. sqcd = data[j++];
  10225. switch (sqcd & 0x1F) {
  10226. case 0:
  10227. spqcdSize = 8;
  10228. scalarExpounded = true;
  10229. break;
  10230. case 1:
  10231. spqcdSize = 16;
  10232. scalarExpounded = false;
  10233. break;
  10234. case 2:
  10235. spqcdSize = 16;
  10236. scalarExpounded = true;
  10237. break;
  10238. default:
  10239. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  10240. }
  10241. qcd.noQuantization = (spqcdSize === 8);
  10242. qcd.scalarExpounded = scalarExpounded;
  10243. qcd.guardBits = sqcd >> 5;
  10244. spqcds = [];
  10245. while (j < length + position) {
  10246. var spqcd = {};
  10247. if (spqcdSize === 8) {
  10248. spqcd.epsilon = data[j++] >> 3;
  10249. spqcd.mu = 0;
  10250. } else {
  10251. spqcd.epsilon = data[j] >> 3;
  10252. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  10253. j += 2;
  10254. }
  10255. spqcds.push(spqcd);
  10256. }
  10257. qcd.SPqcds = spqcds;
  10258. if (context.mainHeader) {
  10259. context.QCD = qcd;
  10260. } else {
  10261. context.currentTile.QCD = qcd;
  10262. context.currentTile.QCC = [];
  10263. }
  10264. break;
  10265. case 0xFF5D: // Quantization component (QCC)
  10266. length = readUint16(data, position);
  10267. var qcc = {};
  10268. j = position + 2;
  10269. var cqcc;
  10270. if (context.SIZ.Csiz < 257) {
  10271. cqcc = data[j++];
  10272. } else {
  10273. cqcc = readUint16(data, j);
  10274. j += 2;
  10275. }
  10276. sqcd = data[j++];
  10277. switch (sqcd & 0x1F) {
  10278. case 0:
  10279. spqcdSize = 8;
  10280. scalarExpounded = true;
  10281. break;
  10282. case 1:
  10283. spqcdSize = 16;
  10284. scalarExpounded = false;
  10285. break;
  10286. case 2:
  10287. spqcdSize = 16;
  10288. scalarExpounded = true;
  10289. break;
  10290. default:
  10291. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  10292. }
  10293. qcc.noQuantization = (spqcdSize === 8);
  10294. qcc.scalarExpounded = scalarExpounded;
  10295. qcc.guardBits = sqcd >> 5;
  10296. spqcds = [];
  10297. while (j < (length + position)) {
  10298. spqcd = {};
  10299. if (spqcdSize === 8) {
  10300. spqcd.epsilon = data[j++] >> 3;
  10301. spqcd.mu = 0;
  10302. } else {
  10303. spqcd.epsilon = data[j] >> 3;
  10304. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  10305. j += 2;
  10306. }
  10307. spqcds.push(spqcd);
  10308. }
  10309. qcc.SPqcds = spqcds;
  10310. if (context.mainHeader) {
  10311. context.QCC[cqcc] = qcc;
  10312. } else {
  10313. context.currentTile.QCC[cqcc] = qcc;
  10314. }
  10315. break;
  10316. case 0xFF52: // Coding style default (COD)
  10317. length = readUint16(data, position);
  10318. var cod = {};
  10319. j = position + 2;
  10320. var scod = data[j++];
  10321. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  10322. cod.sopMarkerUsed = !!(scod & 2);
  10323. cod.ephMarkerUsed = !!(scod & 4);
  10324. cod.progressionOrder = data[j++];
  10325. cod.layersCount = readUint16(data, j);
  10326. j += 2;
  10327. cod.multipleComponentTransform = data[j++];
  10328. cod.decompositionLevelsCount = data[j++];
  10329. cod.xcb = (data[j++] & 0xF) + 2;
  10330. cod.ycb = (data[j++] & 0xF) + 2;
  10331. var blockStyle = data[j++];
  10332. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  10333. cod.resetContextProbabilities = !!(blockStyle & 2);
  10334. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  10335. cod.verticalyStripe = !!(blockStyle & 8);
  10336. cod.predictableTermination = !!(blockStyle & 16);
  10337. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  10338. cod.reversibleTransformation = data[j++];
  10339. if (cod.entropyCoderWithCustomPrecincts) {
  10340. var precinctsSizes = [];
  10341. while (j < length + position) {
  10342. var precinctsSize = data[j++];
  10343. precinctsSizes.push({
  10344. PPx: precinctsSize & 0xF,
  10345. PPy: precinctsSize >> 4
  10346. });
  10347. }
  10348. cod.precinctsSizes = precinctsSizes;
  10349. }
  10350. var unsupported = [];
  10351. if (cod.selectiveArithmeticCodingBypass) {
  10352. unsupported.push('selectiveArithmeticCodingBypass');
  10353. }
  10354. if (cod.resetContextProbabilities) {
  10355. unsupported.push('resetContextProbabilities');
  10356. }
  10357. if (cod.terminationOnEachCodingPass) {
  10358. unsupported.push('terminationOnEachCodingPass');
  10359. }
  10360. if (cod.verticalyStripe) {
  10361. unsupported.push('verticalyStripe');
  10362. }
  10363. if (cod.predictableTermination) {
  10364. unsupported.push('predictableTermination');
  10365. }
  10366. if (unsupported.length > 0) {
  10367. doNotRecover = true;
  10368. throw new Error('JPX Error: Unsupported COD options (' +
  10369. unsupported.join(', ') + ')');
  10370. }
  10371. if (context.mainHeader) {
  10372. context.COD = cod;
  10373. } else {
  10374. context.currentTile.COD = cod;
  10375. context.currentTile.COC = [];
  10376. }
  10377. break;
  10378. case 0xFF90: // Start of tile-part (SOT)
  10379. length = readUint16(data, position);
  10380. tile = {};
  10381. tile.index = readUint16(data, position + 2);
  10382. tile.length = readUint32(data, position + 4);
  10383. tile.dataEnd = tile.length + position - 2;
  10384. tile.partIndex = data[position + 8];
  10385. tile.partsCount = data[position + 9];
  10386. context.mainHeader = false;
  10387. if (tile.partIndex === 0) {
  10388. // reset component specific settings
  10389. tile.COD = context.COD;
  10390. tile.COC = context.COC.slice(0); // clone of the global COC
  10391. tile.QCD = context.QCD;
  10392. tile.QCC = context.QCC.slice(0); // clone of the global COC
  10393. }
  10394. context.currentTile = tile;
  10395. break;
  10396. case 0xFF93: // Start of data (SOD)
  10397. tile = context.currentTile;
  10398. if (tile.partIndex === 0) {
  10399. initializeTile(context, tile.index);
  10400. buildPackets(context);
  10401. }
  10402. // moving to the end of the data
  10403. length = tile.dataEnd - position;
  10404. parseTilePackets(context, data, position, length);
  10405. break;
  10406. case 0xFF55: // Tile-part lengths, main header (TLM)
  10407. case 0xFF57: // Packet length, main header (PLM)
  10408. case 0xFF58: // Packet length, tile-part header (PLT)
  10409. case 0xFF64: // Comment (COM)
  10410. length = readUint16(data, position);
  10411. // skipping content
  10412. break;
  10413. case 0xFF53: // Coding style component (COC)
  10414. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  10415. 'not implemented');
  10416. default:
  10417. throw new Error('JPX Error: Unknown codestream code: ' +
  10418. code.toString(16));
  10419. }
  10420. position += length;
  10421. }
  10422. } catch (e) {
  10423. if (doNotRecover || this.failOnCorruptedImage) {
  10424. throw e;
  10425. } else {
  10426. warn('Trying to recover from ' + e.message);
  10427. }
  10428. }
  10429. this.tiles = transformComponents(context);
  10430. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  10431. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  10432. this.componentsCount = context.SIZ.Csiz;
  10433. }
  10434. };
  10435. function calculateComponentDimensions(component, siz) {
  10436. // Section B.2 Component mapping
  10437. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  10438. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  10439. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  10440. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  10441. component.width = component.x1 - component.x0;
  10442. component.height = component.y1 - component.y0;
  10443. }
  10444. function calculateTileGrids(context, components) {
  10445. var siz = context.SIZ;
  10446. // Section B.3 Division into tile and tile-components
  10447. var tile, tiles = [];
  10448. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  10449. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  10450. for (var q = 0; q < numYtiles; q++) {
  10451. for (var p = 0; p < numXtiles; p++) {
  10452. tile = {};
  10453. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  10454. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  10455. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  10456. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  10457. tile.width = tile.tx1 - tile.tx0;
  10458. tile.height = tile.ty1 - tile.ty0;
  10459. tile.components = [];
  10460. tiles.push(tile);
  10461. }
  10462. }
  10463. context.tiles = tiles;
  10464. var componentsCount = siz.Csiz;
  10465. for (var i = 0, ii = componentsCount; i < ii; i++) {
  10466. var component = components[i];
  10467. for (var j = 0, jj = tiles.length; j < jj; j++) {
  10468. var tileComponent = {};
  10469. tile = tiles[j];
  10470. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  10471. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  10472. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  10473. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  10474. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  10475. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  10476. tile.components[i] = tileComponent;
  10477. }
  10478. }
  10479. }
  10480. function getBlocksDimensions(context, component, r) {
  10481. var codOrCoc = component.codingStyleParameters;
  10482. var result = {};
  10483. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  10484. result.PPx = 15;
  10485. result.PPy = 15;
  10486. } else {
  10487. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  10488. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  10489. }
  10490. // calculate codeblock size as described in section B.7
  10491. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  10492. Math.min(codOrCoc.xcb, result.PPx));
  10493. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  10494. Math.min(codOrCoc.ycb, result.PPy));
  10495. return result;
  10496. }
  10497. function buildPrecincts(context, resolution, dimensions) {
  10498. // Section B.6 Division resolution to precincts
  10499. var precinctWidth = 1 << dimensions.PPx;
  10500. var precinctHeight = 1 << dimensions.PPy;
  10501. // Jasper introduces codeblock groups for mapping each subband codeblocks
  10502. // to precincts. Precinct partition divides a resolution according to width
  10503. // and height parameters. The subband that belongs to the resolution level
  10504. // has a different size than the level, unless it is the zero resolution.
  10505. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  10506. // The precinct partitioning for a particular subband is derived from a
  10507. // partitioning of its parent LL band (i.e., the LL band at the next higher
  10508. // resolution level)... The LL band associated with each resolution level is
  10509. // divided into precincts... Each of the resulting precinct regions is then
  10510. // mapped into its child subbands (if any) at the next lower resolution
  10511. // level. This is accomplished by using the coordinate transformation
  10512. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  10513. // coordinates of a point in the LL band and child subband, respectively.
  10514. var isZeroRes = resolution.resLevel === 0;
  10515. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  10516. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  10517. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  10518. Math.ceil(resolution.trx1 / precinctWidth) -
  10519. Math.floor(resolution.trx0 / precinctWidth) : 0);
  10520. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  10521. Math.ceil(resolution.try1 / precinctHeight) -
  10522. Math.floor(resolution.try0 / precinctHeight) : 0);
  10523. var numprecincts = numprecinctswide * numprecinctshigh;
  10524. resolution.precinctParameters = {
  10525. precinctWidth: precinctWidth,
  10526. precinctHeight: precinctHeight,
  10527. numprecinctswide: numprecinctswide,
  10528. numprecinctshigh: numprecinctshigh,
  10529. numprecincts: numprecincts,
  10530. precinctWidthInSubband: precinctWidthInSubband,
  10531. precinctHeightInSubband: precinctHeightInSubband
  10532. };
  10533. }
  10534. function buildCodeblocks(context, subband, dimensions) {
  10535. // Section B.7 Division sub-band into code-blocks
  10536. var xcb_ = dimensions.xcb_;
  10537. var ycb_ = dimensions.ycb_;
  10538. var codeblockWidth = 1 << xcb_;
  10539. var codeblockHeight = 1 << ycb_;
  10540. var cbx0 = subband.tbx0 >> xcb_;
  10541. var cby0 = subband.tby0 >> ycb_;
  10542. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  10543. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  10544. var precinctParameters = subband.resolution.precinctParameters;
  10545. var codeblocks = [];
  10546. var precincts = [];
  10547. var i, j, codeblock, precinctNumber;
  10548. for (j = cby0; j < cby1; j++) {
  10549. for (i = cbx0; i < cbx1; i++) {
  10550. codeblock = {
  10551. cbx: i,
  10552. cby: j,
  10553. tbx0: codeblockWidth * i,
  10554. tby0: codeblockHeight * j,
  10555. tbx1: codeblockWidth * (i + 1),
  10556. tby1: codeblockHeight * (j + 1)
  10557. };
  10558. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  10559. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  10560. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  10561. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  10562. // Calculate precinct number for this codeblock, codeblock position
  10563. // should be relative to its subband, use actual dimension and position
  10564. // See comment about codeblock group width and height
  10565. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  10566. precinctParameters.precinctWidthInSubband);
  10567. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  10568. precinctParameters.precinctHeightInSubband);
  10569. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  10570. codeblock.precinctNumber = precinctNumber;
  10571. codeblock.subbandType = subband.type;
  10572. codeblock.Lblock = 3;
  10573. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  10574. codeblock.tby1_ <= codeblock.tby0_) {
  10575. continue;
  10576. }
  10577. codeblocks.push(codeblock);
  10578. // building precinct for the sub-band
  10579. var precinct = precincts[precinctNumber];
  10580. if (precinct !== undefined) {
  10581. if (i < precinct.cbxMin) {
  10582. precinct.cbxMin = i;
  10583. } else if (i > precinct.cbxMax) {
  10584. precinct.cbxMax = i;
  10585. }
  10586. if (j < precinct.cbyMin) {
  10587. precinct.cbxMin = j;
  10588. } else if (j > precinct.cbyMax) {
  10589. precinct.cbyMax = j;
  10590. }
  10591. } else {
  10592. precincts[precinctNumber] = precinct = {
  10593. cbxMin: i,
  10594. cbyMin: j,
  10595. cbxMax: i,
  10596. cbyMax: j
  10597. };
  10598. }
  10599. codeblock.precinct = precinct;
  10600. }
  10601. }
  10602. subband.codeblockParameters = {
  10603. codeblockWidth: xcb_,
  10604. codeblockHeight: ycb_,
  10605. numcodeblockwide: cbx1 - cbx0 + 1,
  10606. numcodeblockhigh: cby1 - cby0 + 1
  10607. };
  10608. subband.codeblocks = codeblocks;
  10609. subband.precincts = precincts;
  10610. }
  10611. function createPacket(resolution, precinctNumber, layerNumber) {
  10612. var precinctCodeblocks = [];
  10613. // Section B.10.8 Order of info in packet
  10614. var subbands = resolution.subbands;
  10615. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  10616. for (var i = 0, ii = subbands.length; i < ii; i++) {
  10617. var subband = subbands[i];
  10618. var codeblocks = subband.codeblocks;
  10619. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  10620. var codeblock = codeblocks[j];
  10621. if (codeblock.precinctNumber !== precinctNumber) {
  10622. continue;
  10623. }
  10624. precinctCodeblocks.push(codeblock);
  10625. }
  10626. }
  10627. return {
  10628. layerNumber: layerNumber,
  10629. codeblocks: precinctCodeblocks
  10630. };
  10631. }
  10632. function LayerResolutionComponentPositionIterator(context) {
  10633. var siz = context.SIZ;
  10634. var tileIndex = context.currentTile.index;
  10635. var tile = context.tiles[tileIndex];
  10636. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  10637. var componentsCount = siz.Csiz;
  10638. var maxDecompositionLevelsCount = 0;
  10639. for (var q = 0; q < componentsCount; q++) {
  10640. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  10641. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  10642. }
  10643. var l = 0, r = 0, i = 0, k = 0;
  10644. this.nextPacket = function JpxImage_nextPacket() {
  10645. // Section B.12.1.1 Layer-resolution-component-position
  10646. for (; l < layersCount; l++) {
  10647. for (; r <= maxDecompositionLevelsCount; r++) {
  10648. for (; i < componentsCount; i++) {
  10649. var component = tile.components[i];
  10650. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  10651. continue;
  10652. }
  10653. var resolution = component.resolutions[r];
  10654. var numprecincts = resolution.precinctParameters.numprecincts;
  10655. for (; k < numprecincts;) {
  10656. var packet = createPacket(resolution, k, l);
  10657. k++;
  10658. return packet;
  10659. }
  10660. k = 0;
  10661. }
  10662. i = 0;
  10663. }
  10664. r = 0;
  10665. }
  10666. throw new Error('JPX Error: Out of packets');
  10667. };
  10668. }
  10669. function ResolutionLayerComponentPositionIterator(context) {
  10670. var siz = context.SIZ;
  10671. var tileIndex = context.currentTile.index;
  10672. var tile = context.tiles[tileIndex];
  10673. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  10674. var componentsCount = siz.Csiz;
  10675. var maxDecompositionLevelsCount = 0;
  10676. for (var q = 0; q < componentsCount; q++) {
  10677. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  10678. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  10679. }
  10680. var r = 0, l = 0, i = 0, k = 0;
  10681. this.nextPacket = function JpxImage_nextPacket() {
  10682. // Section B.12.1.2 Resolution-layer-component-position
  10683. for (; r <= maxDecompositionLevelsCount; r++) {
  10684. for (; l < layersCount; l++) {
  10685. for (; i < componentsCount; i++) {
  10686. var component = tile.components[i];
  10687. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  10688. continue;
  10689. }
  10690. var resolution = component.resolutions[r];
  10691. var numprecincts = resolution.precinctParameters.numprecincts;
  10692. for (; k < numprecincts;) {
  10693. var packet = createPacket(resolution, k, l);
  10694. k++;
  10695. return packet;
  10696. }
  10697. k = 0;
  10698. }
  10699. i = 0;
  10700. }
  10701. l = 0;
  10702. }
  10703. throw new Error('JPX Error: Out of packets');
  10704. };
  10705. }
  10706. function ResolutionPositionComponentLayerIterator(context) {
  10707. var siz = context.SIZ;
  10708. var tileIndex = context.currentTile.index;
  10709. var tile = context.tiles[tileIndex];
  10710. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  10711. var componentsCount = siz.Csiz;
  10712. var l, r, c, p;
  10713. var maxDecompositionLevelsCount = 0;
  10714. for (c = 0; c < componentsCount; c++) {
  10715. var component = tile.components[c];
  10716. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  10717. component.codingStyleParameters.decompositionLevelsCount);
  10718. }
  10719. var maxNumPrecinctsInLevel = new Int32Array(
  10720. maxDecompositionLevelsCount + 1);
  10721. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  10722. var maxNumPrecincts = 0;
  10723. for (c = 0; c < componentsCount; ++c) {
  10724. var resolutions = tile.components[c].resolutions;
  10725. if (r < resolutions.length) {
  10726. maxNumPrecincts = Math.max(maxNumPrecincts,
  10727. resolutions[r].precinctParameters.numprecincts);
  10728. }
  10729. }
  10730. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  10731. }
  10732. l = 0;
  10733. r = 0;
  10734. c = 0;
  10735. p = 0;
  10736. this.nextPacket = function JpxImage_nextPacket() {
  10737. // Section B.12.1.3 Resolution-position-component-layer
  10738. for (; r <= maxDecompositionLevelsCount; r++) {
  10739. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  10740. for (; c < componentsCount; c++) {
  10741. var component = tile.components[c];
  10742. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  10743. continue;
  10744. }
  10745. var resolution = component.resolutions[r];
  10746. var numprecincts = resolution.precinctParameters.numprecincts;
  10747. if (p >= numprecincts) {
  10748. continue;
  10749. }
  10750. for (; l < layersCount;) {
  10751. var packet = createPacket(resolution, p, l);
  10752. l++;
  10753. return packet;
  10754. }
  10755. l = 0;
  10756. }
  10757. c = 0;
  10758. }
  10759. p = 0;
  10760. }
  10761. throw new Error('JPX Error: Out of packets');
  10762. };
  10763. }
  10764. function PositionComponentResolutionLayerIterator(context) {
  10765. var siz = context.SIZ;
  10766. var tileIndex = context.currentTile.index;
  10767. var tile = context.tiles[tileIndex];
  10768. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  10769. var componentsCount = siz.Csiz;
  10770. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  10771. var precinctsIterationSizes = precinctsSizes;
  10772. var l = 0, r = 0, c = 0, px = 0, py = 0;
  10773. this.nextPacket = function JpxImage_nextPacket() {
  10774. // Section B.12.1.4 Position-component-resolution-layer
  10775. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  10776. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  10777. for (; c < componentsCount; c++) {
  10778. var component = tile.components[c];
  10779. var decompositionLevelsCount =
  10780. component.codingStyleParameters.decompositionLevelsCount;
  10781. for (; r <= decompositionLevelsCount; r++) {
  10782. var resolution = component.resolutions[r];
  10783. var sizeInImageScale =
  10784. precinctsSizes.components[c].resolutions[r];
  10785. var k = getPrecinctIndexIfExist(
  10786. px,
  10787. py,
  10788. sizeInImageScale,
  10789. precinctsIterationSizes,
  10790. resolution);
  10791. if (k === null) {
  10792. continue;
  10793. }
  10794. for (; l < layersCount;) {
  10795. var packet = createPacket(resolution, k, l);
  10796. l++;
  10797. return packet;
  10798. }
  10799. l = 0;
  10800. }
  10801. r = 0;
  10802. }
  10803. c = 0;
  10804. }
  10805. px = 0;
  10806. }
  10807. throw new Error('JPX Error: Out of packets');
  10808. };
  10809. }
  10810. function ComponentPositionResolutionLayerIterator(context) {
  10811. var siz = context.SIZ;
  10812. var tileIndex = context.currentTile.index;
  10813. var tile = context.tiles[tileIndex];
  10814. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  10815. var componentsCount = siz.Csiz;
  10816. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  10817. var l = 0, r = 0, c = 0, px = 0, py = 0;
  10818. this.nextPacket = function JpxImage_nextPacket() {
  10819. // Section B.12.1.5 Component-position-resolution-layer
  10820. for (; c < componentsCount; ++c) {
  10821. var component = tile.components[c];
  10822. var precinctsIterationSizes = precinctsSizes.components[c];
  10823. var decompositionLevelsCount =
  10824. component.codingStyleParameters.decompositionLevelsCount;
  10825. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  10826. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  10827. for (; r <= decompositionLevelsCount; r++) {
  10828. var resolution = component.resolutions[r];
  10829. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  10830. var k = getPrecinctIndexIfExist(
  10831. px,
  10832. py,
  10833. sizeInImageScale,
  10834. precinctsIterationSizes,
  10835. resolution);
  10836. if (k === null) {
  10837. continue;
  10838. }
  10839. for (; l < layersCount;) {
  10840. var packet = createPacket(resolution, k, l);
  10841. l++;
  10842. return packet;
  10843. }
  10844. l = 0;
  10845. }
  10846. r = 0;
  10847. }
  10848. px = 0;
  10849. }
  10850. py = 0;
  10851. }
  10852. throw new Error('JPX Error: Out of packets');
  10853. };
  10854. }
  10855. function getPrecinctIndexIfExist(
  10856. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  10857. var posX = pxIndex * precinctIterationSizes.minWidth;
  10858. var posY = pyIndex * precinctIterationSizes.minHeight;
  10859. if (posX % sizeInImageScale.width !== 0 ||
  10860. posY % sizeInImageScale.height !== 0) {
  10861. return null;
  10862. }
  10863. var startPrecinctRowIndex =
  10864. (posY / sizeInImageScale.width) *
  10865. resolution.precinctParameters.numprecinctswide;
  10866. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  10867. }
  10868. function getPrecinctSizesInImageScale(tile) {
  10869. var componentsCount = tile.components.length;
  10870. var minWidth = Number.MAX_VALUE;
  10871. var minHeight = Number.MAX_VALUE;
  10872. var maxNumWide = 0;
  10873. var maxNumHigh = 0;
  10874. var sizePerComponent = new Array(componentsCount);
  10875. for (var c = 0; c < componentsCount; c++) {
  10876. var component = tile.components[c];
  10877. var decompositionLevelsCount =
  10878. component.codingStyleParameters.decompositionLevelsCount;
  10879. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  10880. var minWidthCurrentComponent = Number.MAX_VALUE;
  10881. var minHeightCurrentComponent = Number.MAX_VALUE;
  10882. var maxNumWideCurrentComponent = 0;
  10883. var maxNumHighCurrentComponent = 0;
  10884. var scale = 1;
  10885. for (var r = decompositionLevelsCount; r >= 0; --r) {
  10886. var resolution = component.resolutions[r];
  10887. var widthCurrentResolution =
  10888. scale * resolution.precinctParameters.precinctWidth;
  10889. var heightCurrentResolution =
  10890. scale * resolution.precinctParameters.precinctHeight;
  10891. minWidthCurrentComponent = Math.min(
  10892. minWidthCurrentComponent,
  10893. widthCurrentResolution);
  10894. minHeightCurrentComponent = Math.min(
  10895. minHeightCurrentComponent,
  10896. heightCurrentResolution);
  10897. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  10898. resolution.precinctParameters.numprecinctswide);
  10899. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  10900. resolution.precinctParameters.numprecinctshigh);
  10901. sizePerResolution[r] = {
  10902. width: widthCurrentResolution,
  10903. height: heightCurrentResolution
  10904. };
  10905. scale <<= 1;
  10906. }
  10907. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  10908. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  10909. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  10910. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  10911. sizePerComponent[c] = {
  10912. resolutions: sizePerResolution,
  10913. minWidth: minWidthCurrentComponent,
  10914. minHeight: minHeightCurrentComponent,
  10915. maxNumWide: maxNumWideCurrentComponent,
  10916. maxNumHigh: maxNumHighCurrentComponent
  10917. };
  10918. }
  10919. return {
  10920. components: sizePerComponent,
  10921. minWidth: minWidth,
  10922. minHeight: minHeight,
  10923. maxNumWide: maxNumWide,
  10924. maxNumHigh: maxNumHigh
  10925. };
  10926. }
  10927. function buildPackets(context) {
  10928. var siz = context.SIZ;
  10929. var tileIndex = context.currentTile.index;
  10930. var tile = context.tiles[tileIndex];
  10931. var componentsCount = siz.Csiz;
  10932. // Creating resolutions and sub-bands for each component
  10933. for (var c = 0; c < componentsCount; c++) {
  10934. var component = tile.components[c];
  10935. var decompositionLevelsCount =
  10936. component.codingStyleParameters.decompositionLevelsCount;
  10937. // Section B.5 Resolution levels and sub-bands
  10938. var resolutions = [];
  10939. var subbands = [];
  10940. for (var r = 0; r <= decompositionLevelsCount; r++) {
  10941. var blocksDimensions = getBlocksDimensions(context, component, r);
  10942. var resolution = {};
  10943. var scale = 1 << (decompositionLevelsCount - r);
  10944. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  10945. resolution.try0 = Math.ceil(component.tcy0 / scale);
  10946. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  10947. resolution.try1 = Math.ceil(component.tcy1 / scale);
  10948. resolution.resLevel = r;
  10949. buildPrecincts(context, resolution, blocksDimensions);
  10950. resolutions.push(resolution);
  10951. var subband;
  10952. if (r === 0) {
  10953. // one sub-band (LL) with last decomposition
  10954. subband = {};
  10955. subband.type = 'LL';
  10956. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  10957. subband.tby0 = Math.ceil(component.tcy0 / scale);
  10958. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  10959. subband.tby1 = Math.ceil(component.tcy1 / scale);
  10960. subband.resolution = resolution;
  10961. buildCodeblocks(context, subband, blocksDimensions);
  10962. subbands.push(subband);
  10963. resolution.subbands = [subband];
  10964. } else {
  10965. var bscale = 1 << (decompositionLevelsCount - r + 1);
  10966. var resolutionSubbands = [];
  10967. // three sub-bands (HL, LH and HH) with rest of decompositions
  10968. subband = {};
  10969. subband.type = 'HL';
  10970. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  10971. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  10972. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  10973. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  10974. subband.resolution = resolution;
  10975. buildCodeblocks(context, subband, blocksDimensions);
  10976. subbands.push(subband);
  10977. resolutionSubbands.push(subband);
  10978. subband = {};
  10979. subband.type = 'LH';
  10980. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  10981. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  10982. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  10983. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  10984. subband.resolution = resolution;
  10985. buildCodeblocks(context, subband, blocksDimensions);
  10986. subbands.push(subband);
  10987. resolutionSubbands.push(subband);
  10988. subband = {};
  10989. subband.type = 'HH';
  10990. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  10991. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  10992. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  10993. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  10994. subband.resolution = resolution;
  10995. buildCodeblocks(context, subband, blocksDimensions);
  10996. subbands.push(subband);
  10997. resolutionSubbands.push(subband);
  10998. resolution.subbands = resolutionSubbands;
  10999. }
  11000. }
  11001. component.resolutions = resolutions;
  11002. component.subbands = subbands;
  11003. }
  11004. // Generate the packets sequence
  11005. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  11006. switch (progressionOrder) {
  11007. case 0:
  11008. tile.packetsIterator =
  11009. new LayerResolutionComponentPositionIterator(context);
  11010. break;
  11011. case 1:
  11012. tile.packetsIterator =
  11013. new ResolutionLayerComponentPositionIterator(context);
  11014. break;
  11015. case 2:
  11016. tile.packetsIterator =
  11017. new ResolutionPositionComponentLayerIterator(context);
  11018. break;
  11019. case 3:
  11020. tile.packetsIterator =
  11021. new PositionComponentResolutionLayerIterator(context);
  11022. break;
  11023. case 4:
  11024. tile.packetsIterator =
  11025. new ComponentPositionResolutionLayerIterator(context);
  11026. break;
  11027. default:
  11028. throw new Error('JPX Error: Unsupported progression order ' +
  11029. progressionOrder);
  11030. }
  11031. }
  11032. function parseTilePackets(context, data, offset, dataLength) {
  11033. var position = 0;
  11034. var buffer, bufferSize = 0, skipNextBit = false;
  11035. function readBits(count) {
  11036. while (bufferSize < count) {
  11037. var b = data[offset + position];
  11038. position++;
  11039. if (skipNextBit) {
  11040. buffer = (buffer << 7) | b;
  11041. bufferSize += 7;
  11042. skipNextBit = false;
  11043. } else {
  11044. buffer = (buffer << 8) | b;
  11045. bufferSize += 8;
  11046. }
  11047. if (b === 0xFF) {
  11048. skipNextBit = true;
  11049. }
  11050. }
  11051. bufferSize -= count;
  11052. return (buffer >>> bufferSize) & ((1 << count) - 1);
  11053. }
  11054. function skipMarkerIfEqual(value) {
  11055. if (data[offset + position - 1] === 0xFF &&
  11056. data[offset + position] === value) {
  11057. skipBytes(1);
  11058. return true;
  11059. } else if (data[offset + position] === 0xFF &&
  11060. data[offset + position + 1] === value) {
  11061. skipBytes(2);
  11062. return true;
  11063. }
  11064. return false;
  11065. }
  11066. function skipBytes(count) {
  11067. position += count;
  11068. }
  11069. function alignToByte() {
  11070. bufferSize = 0;
  11071. if (skipNextBit) {
  11072. position++;
  11073. skipNextBit = false;
  11074. }
  11075. }
  11076. function readCodingpasses() {
  11077. if (readBits(1) === 0) {
  11078. return 1;
  11079. }
  11080. if (readBits(1) === 0) {
  11081. return 2;
  11082. }
  11083. var value = readBits(2);
  11084. if (value < 3) {
  11085. return value + 3;
  11086. }
  11087. value = readBits(5);
  11088. if (value < 31) {
  11089. return value + 6;
  11090. }
  11091. value = readBits(7);
  11092. return value + 37;
  11093. }
  11094. var tileIndex = context.currentTile.index;
  11095. var tile = context.tiles[tileIndex];
  11096. var sopMarkerUsed = context.COD.sopMarkerUsed;
  11097. var ephMarkerUsed = context.COD.ephMarkerUsed;
  11098. var packetsIterator = tile.packetsIterator;
  11099. while (position < dataLength) {
  11100. alignToByte();
  11101. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  11102. // Skip also marker segment length and packet sequence ID
  11103. skipBytes(4);
  11104. }
  11105. var packet = packetsIterator.nextPacket();
  11106. if (!readBits(1)) {
  11107. continue;
  11108. }
  11109. var layerNumber = packet.layerNumber;
  11110. var queue = [], codeblock;
  11111. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  11112. codeblock = packet.codeblocks[i];
  11113. var precinct = codeblock.precinct;
  11114. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  11115. var codeblockRow = codeblock.cby - precinct.cbyMin;
  11116. var codeblockIncluded = false;
  11117. var firstTimeInclusion = false;
  11118. var valueReady;
  11119. if (codeblock['included'] !== undefined) {
  11120. codeblockIncluded = !!readBits(1);
  11121. } else {
  11122. // reading inclusion tree
  11123. precinct = codeblock.precinct;
  11124. var inclusionTree, zeroBitPlanesTree;
  11125. if (precinct['inclusionTree'] !== undefined) {
  11126. inclusionTree = precinct.inclusionTree;
  11127. } else {
  11128. // building inclusion and zero bit-planes trees
  11129. var width = precinct.cbxMax - precinct.cbxMin + 1;
  11130. var height = precinct.cbyMax - precinct.cbyMin + 1;
  11131. inclusionTree = new InclusionTree(width, height, layerNumber);
  11132. zeroBitPlanesTree = new TagTree(width, height);
  11133. precinct.inclusionTree = inclusionTree;
  11134. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  11135. }
  11136. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  11137. while (true) {
  11138. if (readBits(1)) {
  11139. valueReady = !inclusionTree.nextLevel();
  11140. if (valueReady) {
  11141. codeblock.included = true;
  11142. codeblockIncluded = firstTimeInclusion = true;
  11143. break;
  11144. }
  11145. } else {
  11146. inclusionTree.incrementValue(layerNumber);
  11147. break;
  11148. }
  11149. }
  11150. }
  11151. }
  11152. if (!codeblockIncluded) {
  11153. continue;
  11154. }
  11155. if (firstTimeInclusion) {
  11156. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  11157. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  11158. while (true) {
  11159. if (readBits(1)) {
  11160. valueReady = !zeroBitPlanesTree.nextLevel();
  11161. if (valueReady) {
  11162. break;
  11163. }
  11164. } else {
  11165. zeroBitPlanesTree.incrementValue();
  11166. }
  11167. }
  11168. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  11169. }
  11170. var codingpasses = readCodingpasses();
  11171. while (readBits(1)) {
  11172. codeblock.Lblock++;
  11173. }
  11174. var codingpassesLog2 = log2(codingpasses);
  11175. // rounding down log2
  11176. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  11177. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  11178. var codedDataLength = readBits(bits);
  11179. queue.push({
  11180. codeblock: codeblock,
  11181. codingpasses: codingpasses,
  11182. dataLength: codedDataLength
  11183. });
  11184. }
  11185. alignToByte();
  11186. if (ephMarkerUsed) {
  11187. skipMarkerIfEqual(0x92);
  11188. }
  11189. while (queue.length > 0) {
  11190. var packetItem = queue.shift();
  11191. codeblock = packetItem.codeblock;
  11192. if (codeblock['data'] === undefined) {
  11193. codeblock.data = [];
  11194. }
  11195. codeblock.data.push({
  11196. data: data,
  11197. start: offset + position,
  11198. end: offset + position + packetItem.dataLength,
  11199. codingpasses: packetItem.codingpasses
  11200. });
  11201. position += packetItem.dataLength;
  11202. }
  11203. }
  11204. return position;
  11205. }
  11206. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  11207. delta, mb, reversible, segmentationSymbolUsed) {
  11208. var x0 = subband.tbx0;
  11209. var y0 = subband.tby0;
  11210. var width = subband.tbx1 - subband.tbx0;
  11211. var codeblocks = subband.codeblocks;
  11212. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  11213. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  11214. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  11215. var codeblock = codeblocks[i];
  11216. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  11217. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  11218. if (blockWidth === 0 || blockHeight === 0) {
  11219. continue;
  11220. }
  11221. if (codeblock['data'] === undefined) {
  11222. continue;
  11223. }
  11224. var bitModel, currentCodingpassType;
  11225. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  11226. codeblock.zeroBitPlanes, mb);
  11227. currentCodingpassType = 2; // first bit plane starts from cleanup
  11228. // collect data
  11229. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  11230. var j, jj, dataItem;
  11231. for (j = 0, jj = data.length; j < jj; j++) {
  11232. dataItem = data[j];
  11233. totalLength += dataItem.end - dataItem.start;
  11234. codingpasses += dataItem.codingpasses;
  11235. }
  11236. var encodedData = new Uint8Array(totalLength);
  11237. var position = 0;
  11238. for (j = 0, jj = data.length; j < jj; j++) {
  11239. dataItem = data[j];
  11240. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  11241. encodedData.set(chunk, position);
  11242. position += chunk.length;
  11243. }
  11244. // decoding the item
  11245. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  11246. bitModel.setDecoder(decoder);
  11247. for (j = 0; j < codingpasses; j++) {
  11248. switch (currentCodingpassType) {
  11249. case 0:
  11250. bitModel.runSignificancePropogationPass();
  11251. break;
  11252. case 1:
  11253. bitModel.runMagnitudeRefinementPass();
  11254. break;
  11255. case 2:
  11256. bitModel.runCleanupPass();
  11257. if (segmentationSymbolUsed) {
  11258. bitModel.checkSegmentationSymbol();
  11259. }
  11260. break;
  11261. }
  11262. currentCodingpassType = (currentCodingpassType + 1) % 3;
  11263. }
  11264. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  11265. var sign = bitModel.coefficentsSign;
  11266. var magnitude = bitModel.coefficentsMagnitude;
  11267. var bitsDecoded = bitModel.bitsDecoded;
  11268. var magnitudeCorrection = reversible ? 0 : 0.5;
  11269. var k, n, nb;
  11270. position = 0;
  11271. // Do the interleaving of Section F.3.3 here, so we do not need
  11272. // to copy later. LL level is not interleaved, just copied.
  11273. var interleave = (subband.type !== 'LL');
  11274. for (j = 0; j < blockHeight; j++) {
  11275. var row = (offset / width) | 0; // row in the non-interleaved subband
  11276. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  11277. for (k = 0; k < blockWidth; k++) {
  11278. n = magnitude[position];
  11279. if (n !== 0) {
  11280. n = (n + magnitudeCorrection) * delta;
  11281. if (sign[position] !== 0) {
  11282. n = -n;
  11283. }
  11284. nb = bitsDecoded[position];
  11285. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  11286. if (reversible && (nb >= mb)) {
  11287. coefficients[pos] = n;
  11288. } else {
  11289. coefficients[pos] = n * (1 << (mb - nb));
  11290. }
  11291. }
  11292. offset++;
  11293. position++;
  11294. }
  11295. offset += width - blockWidth;
  11296. }
  11297. }
  11298. }
  11299. function transformTile(context, tile, c) {
  11300. var component = tile.components[c];
  11301. var codingStyleParameters = component.codingStyleParameters;
  11302. var quantizationParameters = component.quantizationParameters;
  11303. var decompositionLevelsCount =
  11304. codingStyleParameters.decompositionLevelsCount;
  11305. var spqcds = quantizationParameters.SPqcds;
  11306. var scalarExpounded = quantizationParameters.scalarExpounded;
  11307. var guardBits = quantizationParameters.guardBits;
  11308. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  11309. var precision = context.components[c].precision;
  11310. var reversible = codingStyleParameters.reversibleTransformation;
  11311. var transform = (reversible ? new ReversibleTransform() :
  11312. new IrreversibleTransform());
  11313. var subbandCoefficients = [];
  11314. var b = 0;
  11315. for (var i = 0; i <= decompositionLevelsCount; i++) {
  11316. var resolution = component.resolutions[i];
  11317. var width = resolution.trx1 - resolution.trx0;
  11318. var height = resolution.try1 - resolution.try0;
  11319. // Allocate space for the whole sublevel.
  11320. var coefficients = new Float32Array(width * height);
  11321. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  11322. var mu, epsilon;
  11323. if (!scalarExpounded) {
  11324. // formula E-5
  11325. mu = spqcds[0].mu;
  11326. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  11327. } else {
  11328. mu = spqcds[b].mu;
  11329. epsilon = spqcds[b].epsilon;
  11330. b++;
  11331. }
  11332. var subband = resolution.subbands[j];
  11333. var gainLog2 = SubbandsGainLog2[subband.type];
  11334. // calulate quantization coefficient (Section E.1.1.1)
  11335. var delta = (reversible ? 1 :
  11336. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  11337. var mb = (guardBits + epsilon - 1);
  11338. // In the first resolution level, copyCoefficients will fill the
  11339. // whole array with coefficients. In the succeding passes,
  11340. // copyCoefficients will consecutively fill in the values that belong
  11341. // to the interleaved positions of the HL, LH, and HH coefficients.
  11342. // The LL coefficients will then be interleaved in Transform.iterate().
  11343. copyCoefficients(coefficients, width, height, subband, delta, mb,
  11344. reversible, segmentationSymbolUsed);
  11345. }
  11346. subbandCoefficients.push({
  11347. width: width,
  11348. height: height,
  11349. items: coefficients
  11350. });
  11351. }
  11352. var result = transform.calculate(subbandCoefficients,
  11353. component.tcx0, component.tcy0);
  11354. return {
  11355. left: component.tcx0,
  11356. top: component.tcy0,
  11357. width: result.width,
  11358. height: result.height,
  11359. items: result.items
  11360. };
  11361. }
  11362. function transformComponents(context) {
  11363. var siz = context.SIZ;
  11364. var components = context.components;
  11365. var componentsCount = siz.Csiz;
  11366. var resultImages = [];
  11367. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  11368. var tile = context.tiles[i];
  11369. var transformedTiles = [];
  11370. var c;
  11371. for (c = 0; c < componentsCount; c++) {
  11372. transformedTiles[c] = transformTile(context, tile, c);
  11373. }
  11374. var tile0 = transformedTiles[0];
  11375. var out = new Uint8Array(tile0.items.length * componentsCount);
  11376. var result = {
  11377. left: tile0.left,
  11378. top: tile0.top,
  11379. width: tile0.width,
  11380. height: tile0.height,
  11381. items: out
  11382. };
  11383. // Section G.2.2 Inverse multi component transform
  11384. var shift, offset, max, min, maxK;
  11385. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  11386. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  11387. var fourComponents = componentsCount === 4;
  11388. var y0items = transformedTiles[0].items;
  11389. var y1items = transformedTiles[1].items;
  11390. var y2items = transformedTiles[2].items;
  11391. var y3items = fourComponents ? transformedTiles[3].items : null;
  11392. // HACK: The multiple component transform formulas below assume that
  11393. // all components have the same precision. With this in mind, we
  11394. // compute shift and offset only once.
  11395. shift = components[0].precision - 8;
  11396. offset = (128 << shift) + 0.5;
  11397. max = 255 * (1 << shift);
  11398. maxK = max * 0.5;
  11399. min = -maxK;
  11400. var component0 = tile.components[0];
  11401. var alpha01 = componentsCount - 3;
  11402. jj = y0items.length;
  11403. if (!component0.codingStyleParameters.reversibleTransformation) {
  11404. // inverse irreversible multiple component transform
  11405. for (j = 0; j < jj; j++, pos += alpha01) {
  11406. y0 = y0items[j] + offset;
  11407. y1 = y1items[j];
  11408. y2 = y2items[j];
  11409. r = y0 + 1.402 * y2;
  11410. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  11411. b = y0 + 1.772 * y1;
  11412. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  11413. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  11414. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  11415. }
  11416. } else {
  11417. // inverse reversible multiple component transform
  11418. for (j = 0; j < jj; j++, pos += alpha01) {
  11419. y0 = y0items[j] + offset;
  11420. y1 = y1items[j];
  11421. y2 = y2items[j];
  11422. g = y0 - ((y2 + y1) >> 2);
  11423. r = g + y2;
  11424. b = g + y1;
  11425. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  11426. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  11427. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  11428. }
  11429. }
  11430. if (fourComponents) {
  11431. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  11432. k = y3items[j];
  11433. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  11434. }
  11435. }
  11436. } else { // no multi-component transform
  11437. for (c = 0; c < componentsCount; c++) {
  11438. var items = transformedTiles[c].items;
  11439. shift = components[c].precision - 8;
  11440. offset = (128 << shift) + 0.5;
  11441. max = (127.5 * (1 << shift));
  11442. min = -max;
  11443. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  11444. val = items[j];
  11445. out[pos] = val <= min ? 0 :
  11446. val >= max ? 255 : (val + offset) >> shift;
  11447. pos += componentsCount;
  11448. }
  11449. }
  11450. }
  11451. resultImages.push(result);
  11452. }
  11453. return resultImages;
  11454. }
  11455. function initializeTile(context, tileIndex) {
  11456. var siz = context.SIZ;
  11457. var componentsCount = siz.Csiz;
  11458. var tile = context.tiles[tileIndex];
  11459. for (var c = 0; c < componentsCount; c++) {
  11460. var component = tile.components[c];
  11461. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  11462. context.currentTile.QCC[c] : context.currentTile.QCD);
  11463. component.quantizationParameters = qcdOrQcc;
  11464. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  11465. context.currentTile.COC[c] : context.currentTile.COD);
  11466. component.codingStyleParameters = codOrCoc;
  11467. }
  11468. tile.codingStyleDefaultParameters = context.currentTile.COD;
  11469. }
  11470. // Section B.10.2 Tag trees
  11471. var TagTree = (function TagTreeClosure() {
  11472. function TagTree(width, height) {
  11473. var levelsLength = log2(Math.max(width, height)) + 1;
  11474. this.levels = [];
  11475. for (var i = 0; i < levelsLength; i++) {
  11476. var level = {
  11477. width: width,
  11478. height: height,
  11479. items: []
  11480. };
  11481. this.levels.push(level);
  11482. width = Math.ceil(width / 2);
  11483. height = Math.ceil(height / 2);
  11484. }
  11485. }
  11486. TagTree.prototype = {
  11487. reset: function TagTree_reset(i, j) {
  11488. var currentLevel = 0, value = 0, level;
  11489. while (currentLevel < this.levels.length) {
  11490. level = this.levels[currentLevel];
  11491. var index = i + j * level.width;
  11492. if (level.items[index] !== undefined) {
  11493. value = level.items[index];
  11494. break;
  11495. }
  11496. level.index = index;
  11497. i >>= 1;
  11498. j >>= 1;
  11499. currentLevel++;
  11500. }
  11501. currentLevel--;
  11502. level = this.levels[currentLevel];
  11503. level.items[level.index] = value;
  11504. this.currentLevel = currentLevel;
  11505. delete this.value;
  11506. },
  11507. incrementValue: function TagTree_incrementValue() {
  11508. var level = this.levels[this.currentLevel];
  11509. level.items[level.index]++;
  11510. },
  11511. nextLevel: function TagTree_nextLevel() {
  11512. var currentLevel = this.currentLevel;
  11513. var level = this.levels[currentLevel];
  11514. var value = level.items[level.index];
  11515. currentLevel--;
  11516. if (currentLevel < 0) {
  11517. this.value = value;
  11518. return false;
  11519. }
  11520. this.currentLevel = currentLevel;
  11521. level = this.levels[currentLevel];
  11522. level.items[level.index] = value;
  11523. return true;
  11524. }
  11525. };
  11526. return TagTree;
  11527. })();
  11528. var InclusionTree = (function InclusionTreeClosure() {
  11529. function InclusionTree(width, height, defaultValue) {
  11530. var levelsLength = log2(Math.max(width, height)) + 1;
  11531. this.levels = [];
  11532. for (var i = 0; i < levelsLength; i++) {
  11533. var items = new Uint8Array(width * height);
  11534. for (var j = 0, jj = items.length; j < jj; j++) {
  11535. items[j] = defaultValue;
  11536. }
  11537. var level = {
  11538. width: width,
  11539. height: height,
  11540. items: items
  11541. };
  11542. this.levels.push(level);
  11543. width = Math.ceil(width / 2);
  11544. height = Math.ceil(height / 2);
  11545. }
  11546. }
  11547. InclusionTree.prototype = {
  11548. reset: function InclusionTree_reset(i, j, stopValue) {
  11549. var currentLevel = 0;
  11550. while (currentLevel < this.levels.length) {
  11551. var level = this.levels[currentLevel];
  11552. var index = i + j * level.width;
  11553. level.index = index;
  11554. var value = level.items[index];
  11555. if (value === 0xFF) {
  11556. break;
  11557. }
  11558. if (value > stopValue) {
  11559. this.currentLevel = currentLevel;
  11560. // already know about this one, propagating the value to top levels
  11561. this.propagateValues();
  11562. return false;
  11563. }
  11564. i >>= 1;
  11565. j >>= 1;
  11566. currentLevel++;
  11567. }
  11568. this.currentLevel = currentLevel - 1;
  11569. return true;
  11570. },
  11571. incrementValue: function InclusionTree_incrementValue(stopValue) {
  11572. var level = this.levels[this.currentLevel];
  11573. level.items[level.index] = stopValue + 1;
  11574. this.propagateValues();
  11575. },
  11576. propagateValues: function InclusionTree_propagateValues() {
  11577. var levelIndex = this.currentLevel;
  11578. var level = this.levels[levelIndex];
  11579. var currentValue = level.items[level.index];
  11580. while (--levelIndex >= 0) {
  11581. level = this.levels[levelIndex];
  11582. level.items[level.index] = currentValue;
  11583. }
  11584. },
  11585. nextLevel: function InclusionTree_nextLevel() {
  11586. var currentLevel = this.currentLevel;
  11587. var level = this.levels[currentLevel];
  11588. var value = level.items[level.index];
  11589. level.items[level.index] = 0xFF;
  11590. currentLevel--;
  11591. if (currentLevel < 0) {
  11592. return false;
  11593. }
  11594. this.currentLevel = currentLevel;
  11595. level = this.levels[currentLevel];
  11596. level.items[level.index] = value;
  11597. return true;
  11598. }
  11599. };
  11600. return InclusionTree;
  11601. })();
  11602. // Section D. Coefficient bit modeling
  11603. var BitModel = (function BitModelClosure() {
  11604. var UNIFORM_CONTEXT = 17;
  11605. var RUNLENGTH_CONTEXT = 18;
  11606. // Table D-1
  11607. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  11608. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  11609. var LLAndLHContextsLabel = new Uint8Array([
  11610. 0, 5, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 1, 6, 8, 0, 3, 7, 8, 0, 4,
  11611. 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6,
  11612. 8, 0, 3, 7, 8, 0, 4, 7, 8, 0, 0, 0, 0, 0, 2, 6, 8, 0, 3, 7, 8, 0, 4, 7, 8
  11613. ]);
  11614. var HLContextLabel = new Uint8Array([
  11615. 0, 3, 4, 0, 5, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 1, 3, 4, 0, 6, 7, 7, 0, 8,
  11616. 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3,
  11617. 4, 0, 6, 7, 7, 0, 8, 8, 8, 0, 0, 0, 0, 0, 2, 3, 4, 0, 6, 7, 7, 0, 8, 8, 8
  11618. ]);
  11619. var HHContextLabel = new Uint8Array([
  11620. 0, 1, 2, 0, 1, 2, 2, 0, 2, 2, 2, 0, 0, 0, 0, 0, 3, 4, 5, 0, 4, 5, 5, 0, 5,
  11621. 5, 5, 0, 0, 0, 0, 0, 6, 7, 7, 0, 7, 7, 7, 0, 7, 7, 7, 0, 0, 0, 0, 0, 8, 8,
  11622. 8, 0, 8, 8, 8, 0, 8, 8, 8, 0, 0, 0, 0, 0, 8, 8, 8, 0, 8, 8, 8, 0, 8, 8, 8
  11623. ]);
  11624. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  11625. this.width = width;
  11626. this.height = height;
  11627. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  11628. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  11629. var coefficientCount = width * height;
  11630. // coefficients outside the encoding region treated as insignificant
  11631. // add border state cells for significanceState
  11632. this.neighborsSignificance = new Uint8Array(coefficientCount);
  11633. this.coefficentsSign = new Uint8Array(coefficientCount);
  11634. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  11635. mb > 6 ? new Uint16Array(coefficientCount) :
  11636. new Uint8Array(coefficientCount);
  11637. this.processingFlags = new Uint8Array(coefficientCount);
  11638. var bitsDecoded = new Uint8Array(coefficientCount);
  11639. if (zeroBitPlanes !== 0) {
  11640. for (var i = 0; i < coefficientCount; i++) {
  11641. bitsDecoded[i] = zeroBitPlanes;
  11642. }
  11643. }
  11644. this.bitsDecoded = bitsDecoded;
  11645. this.reset();
  11646. }
  11647. BitModel.prototype = {
  11648. setDecoder: function BitModel_setDecoder(decoder) {
  11649. this.decoder = decoder;
  11650. },
  11651. reset: function BitModel_reset() {
  11652. // We have 17 contexts that are accessed via context labels,
  11653. // plus the uniform and runlength context.
  11654. this.contexts = new Int8Array(19);
  11655. // Contexts are packed into 1 byte:
  11656. // highest 7 bits carry the index, lowest bit carries mps
  11657. this.contexts[0] = (4 << 1) | 0;
  11658. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  11659. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  11660. },
  11661. setNeighborsSignificance:
  11662. function BitModel_setNeighborsSignificance(row, column, index) {
  11663. var neighborsSignificance = this.neighborsSignificance;
  11664. var width = this.width, height = this.height;
  11665. var left = (column > 0);
  11666. var right = (column + 1 < width);
  11667. var i;
  11668. if (row > 0) {
  11669. i = index - width;
  11670. if (left) {
  11671. neighborsSignificance[i - 1] += 0x10;
  11672. }
  11673. if (right) {
  11674. neighborsSignificance[i + 1] += 0x10;
  11675. }
  11676. neighborsSignificance[i] += 0x04;
  11677. }
  11678. if (row + 1 < height) {
  11679. i = index + width;
  11680. if (left) {
  11681. neighborsSignificance[i - 1] += 0x10;
  11682. }
  11683. if (right) {
  11684. neighborsSignificance[i + 1] += 0x10;
  11685. }
  11686. neighborsSignificance[i] += 0x04;
  11687. }
  11688. if (left) {
  11689. neighborsSignificance[index - 1] += 0x01;
  11690. }
  11691. if (right) {
  11692. neighborsSignificance[index + 1] += 0x01;
  11693. }
  11694. neighborsSignificance[index] |= 0x80;
  11695. },
  11696. runSignificancePropogationPass:
  11697. function BitModel_runSignificancePropogationPass() {
  11698. var decoder = this.decoder;
  11699. var width = this.width, height = this.height;
  11700. var coefficentsMagnitude = this.coefficentsMagnitude;
  11701. var coefficentsSign = this.coefficentsSign;
  11702. var neighborsSignificance = this.neighborsSignificance;
  11703. var processingFlags = this.processingFlags;
  11704. var contexts = this.contexts;
  11705. var labels = this.contextLabelTable;
  11706. var bitsDecoded = this.bitsDecoded;
  11707. var processedInverseMask = ~1;
  11708. var processedMask = 1;
  11709. var firstMagnitudeBitMask = 2;
  11710. for (var i0 = 0; i0 < height; i0 += 4) {
  11711. for (var j = 0; j < width; j++) {
  11712. var index = i0 * width + j;
  11713. for (var i1 = 0; i1 < 4; i1++, index += width) {
  11714. var i = i0 + i1;
  11715. if (i >= height) {
  11716. break;
  11717. }
  11718. // clear processed flag first
  11719. processingFlags[index] &= processedInverseMask;
  11720. if (coefficentsMagnitude[index] ||
  11721. !neighborsSignificance[index]) {
  11722. continue;
  11723. }
  11724. var contextLabel = labels[neighborsSignificance[index]];
  11725. var decision = decoder.readBit(contexts, contextLabel);
  11726. if (decision) {
  11727. var sign = this.decodeSignBit(i, j, index);
  11728. coefficentsSign[index] = sign;
  11729. coefficentsMagnitude[index] = 1;
  11730. this.setNeighborsSignificance(i, j, index);
  11731. processingFlags[index] |= firstMagnitudeBitMask;
  11732. }
  11733. bitsDecoded[index]++;
  11734. processingFlags[index] |= processedMask;
  11735. }
  11736. }
  11737. }
  11738. },
  11739. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  11740. var width = this.width, height = this.height;
  11741. var coefficentsMagnitude = this.coefficentsMagnitude;
  11742. var coefficentsSign = this.coefficentsSign;
  11743. var contribution, sign0, sign1, significance1;
  11744. var contextLabel, decoded;
  11745. // calculate horizontal contribution
  11746. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  11747. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  11748. sign1 = coefficentsSign[index + 1];
  11749. if (significance1) {
  11750. sign0 = coefficentsSign[index - 1];
  11751. contribution = 1 - sign1 - sign0;
  11752. } else {
  11753. contribution = 1 - sign1 - sign1;
  11754. }
  11755. } else if (significance1) {
  11756. sign0 = coefficentsSign[index - 1];
  11757. contribution = 1 - sign0 - sign0;
  11758. } else {
  11759. contribution = 0;
  11760. }
  11761. var horizontalContribution = 3 * contribution;
  11762. // calculate vertical contribution and combine with the horizontal
  11763. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  11764. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  11765. sign1 = coefficentsSign[index + width];
  11766. if (significance1) {
  11767. sign0 = coefficentsSign[index - width];
  11768. contribution = 1 - sign1 - sign0 + horizontalContribution;
  11769. } else {
  11770. contribution = 1 - sign1 - sign1 + horizontalContribution;
  11771. }
  11772. } else if (significance1) {
  11773. sign0 = coefficentsSign[index - width];
  11774. contribution = 1 - sign0 - sign0 + horizontalContribution;
  11775. } else {
  11776. contribution = horizontalContribution;
  11777. }
  11778. if (contribution >= 0) {
  11779. contextLabel = 9 + contribution;
  11780. decoded = this.decoder.readBit(this.contexts, contextLabel);
  11781. } else {
  11782. contextLabel = 9 - contribution;
  11783. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  11784. }
  11785. return decoded;
  11786. },
  11787. runMagnitudeRefinementPass:
  11788. function BitModel_runMagnitudeRefinementPass() {
  11789. var decoder = this.decoder;
  11790. var width = this.width, height = this.height;
  11791. var coefficentsMagnitude = this.coefficentsMagnitude;
  11792. var neighborsSignificance = this.neighborsSignificance;
  11793. var contexts = this.contexts;
  11794. var bitsDecoded = this.bitsDecoded;
  11795. var processingFlags = this.processingFlags;
  11796. var processedMask = 1;
  11797. var firstMagnitudeBitMask = 2;
  11798. var length = width * height;
  11799. var width4 = width * 4;
  11800. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  11801. indexNext = Math.min(length, index0 + width4);
  11802. for (var j = 0; j < width; j++) {
  11803. for (var index = index0 + j; index < indexNext; index += width) {
  11804. // significant but not those that have just become
  11805. if (!coefficentsMagnitude[index] ||
  11806. (processingFlags[index] & processedMask) !== 0) {
  11807. continue;
  11808. }
  11809. var contextLabel = 16;
  11810. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  11811. processingFlags[index] ^= firstMagnitudeBitMask;
  11812. // first refinement
  11813. var significance = neighborsSignificance[index] & 127;
  11814. contextLabel = significance === 0 ? 15 : 14;
  11815. }
  11816. var bit = decoder.readBit(contexts, contextLabel);
  11817. coefficentsMagnitude[index] =
  11818. (coefficentsMagnitude[index] << 1) | bit;
  11819. bitsDecoded[index]++;
  11820. processingFlags[index] |= processedMask;
  11821. }
  11822. }
  11823. }
  11824. },
  11825. runCleanupPass: function BitModel_runCleanupPass() {
  11826. var decoder = this.decoder;
  11827. var width = this.width, height = this.height;
  11828. var neighborsSignificance = this.neighborsSignificance;
  11829. var coefficentsMagnitude = this.coefficentsMagnitude;
  11830. var coefficentsSign = this.coefficentsSign;
  11831. var contexts = this.contexts;
  11832. var labels = this.contextLabelTable;
  11833. var bitsDecoded = this.bitsDecoded;
  11834. var processingFlags = this.processingFlags;
  11835. var processedMask = 1;
  11836. var firstMagnitudeBitMask = 2;
  11837. var oneRowDown = width;
  11838. var twoRowsDown = width * 2;
  11839. var threeRowsDown = width * 3;
  11840. var iNext;
  11841. for (var i0 = 0; i0 < height; i0 = iNext) {
  11842. iNext = Math.min(i0 + 4, height);
  11843. var indexBase = i0 * width;
  11844. var checkAllEmpty = i0 + 3 < height;
  11845. for (var j = 0; j < width; j++) {
  11846. var index0 = indexBase + j;
  11847. // using the property: labels[neighborsSignificance[index]] === 0
  11848. // when neighborsSignificance[index] === 0
  11849. var allEmpty = (checkAllEmpty &&
  11850. processingFlags[index0] === 0 &&
  11851. processingFlags[index0 + oneRowDown] === 0 &&
  11852. processingFlags[index0 + twoRowsDown] === 0 &&
  11853. processingFlags[index0 + threeRowsDown] === 0 &&
  11854. neighborsSignificance[index0] === 0 &&
  11855. neighborsSignificance[index0 + oneRowDown] === 0 &&
  11856. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  11857. neighborsSignificance[index0 + threeRowsDown] === 0);
  11858. var i1 = 0, index = index0;
  11859. var i = i0, sign;
  11860. if (allEmpty) {
  11861. var hasSignificantCoefficent =
  11862. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  11863. if (!hasSignificantCoefficent) {
  11864. bitsDecoded[index0]++;
  11865. bitsDecoded[index0 + oneRowDown]++;
  11866. bitsDecoded[index0 + twoRowsDown]++;
  11867. bitsDecoded[index0 + threeRowsDown]++;
  11868. continue; // next column
  11869. }
  11870. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  11871. decoder.readBit(contexts, UNIFORM_CONTEXT);
  11872. if (i1 !== 0) {
  11873. i = i0 + i1;
  11874. index += i1 * width;
  11875. }
  11876. sign = this.decodeSignBit(i, j, index);
  11877. coefficentsSign[index] = sign;
  11878. coefficentsMagnitude[index] = 1;
  11879. this.setNeighborsSignificance(i, j, index);
  11880. processingFlags[index] |= firstMagnitudeBitMask;
  11881. index = index0;
  11882. for (var i2 = i0; i2 <= i; i2++, index += width) {
  11883. bitsDecoded[index]++;
  11884. }
  11885. i1++;
  11886. }
  11887. for (i = i0 + i1; i < iNext; i++, index += width) {
  11888. if (coefficentsMagnitude[index] ||
  11889. (processingFlags[index] & processedMask) !== 0) {
  11890. continue;
  11891. }
  11892. var contextLabel = labels[neighborsSignificance[index]];
  11893. var decision = decoder.readBit(contexts, contextLabel);
  11894. if (decision === 1) {
  11895. sign = this.decodeSignBit(i, j, index);
  11896. coefficentsSign[index] = sign;
  11897. coefficentsMagnitude[index] = 1;
  11898. this.setNeighborsSignificance(i, j, index);
  11899. processingFlags[index] |= firstMagnitudeBitMask;
  11900. }
  11901. bitsDecoded[index]++;
  11902. }
  11903. }
  11904. }
  11905. },
  11906. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  11907. var decoder = this.decoder;
  11908. var contexts = this.contexts;
  11909. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  11910. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  11911. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  11912. decoder.readBit(contexts, UNIFORM_CONTEXT);
  11913. if (symbol !== 0xA) {
  11914. throw new Error('JPX Error: Invalid segmentation symbol');
  11915. }
  11916. }
  11917. };
  11918. return BitModel;
  11919. })();
  11920. // Section F, Discrete wavelet transformation
  11921. var Transform = (function TransformClosure() {
  11922. function Transform() {}
  11923. Transform.prototype.calculate =
  11924. function transformCalculate(subbands, u0, v0) {
  11925. var ll = subbands[0];
  11926. for (var i = 1, ii = subbands.length; i < ii; i++) {
  11927. ll = this.iterate(ll, subbands[i], u0, v0);
  11928. }
  11929. return ll;
  11930. };
  11931. Transform.prototype.extend = function extend(buffer, offset, size) {
  11932. // Section F.3.7 extending... using max extension of 4
  11933. var i1 = offset - 1, j1 = offset + 1;
  11934. var i2 = offset + size - 2, j2 = offset + size;
  11935. buffer[i1--] = buffer[j1++];
  11936. buffer[j2++] = buffer[i2--];
  11937. buffer[i1--] = buffer[j1++];
  11938. buffer[j2++] = buffer[i2--];
  11939. buffer[i1--] = buffer[j1++];
  11940. buffer[j2++] = buffer[i2--];
  11941. buffer[i1] = buffer[j1];
  11942. buffer[j2] = buffer[i2];
  11943. };
  11944. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  11945. u0, v0) {
  11946. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  11947. var width = hl_lh_hh.width;
  11948. var height = hl_lh_hh.height;
  11949. var items = hl_lh_hh.items;
  11950. var i, j, k, l, u, v;
  11951. // Interleave LL according to Section F.3.3
  11952. for (k = 0, i = 0; i < llHeight; i++) {
  11953. l = i * 2 * width;
  11954. for (j = 0; j < llWidth; j++, k++, l += 2) {
  11955. items[l] = llItems[k];
  11956. }
  11957. }
  11958. // The LL band is not needed anymore.
  11959. llItems = ll.items = null;
  11960. var bufferPadding = 4;
  11961. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  11962. // Section F.3.4 HOR_SR
  11963. if (width === 1) {
  11964. // if width = 1, when u0 even keep items as is, when odd divide by 2
  11965. if ((u0 & 1) !== 0) {
  11966. for (v = 0, k = 0; v < height; v++, k += width) {
  11967. items[k] *= 0.5;
  11968. }
  11969. }
  11970. } else {
  11971. for (v = 0, k = 0; v < height; v++, k += width) {
  11972. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  11973. this.extend(rowBuffer, bufferPadding, width);
  11974. this.filter(rowBuffer, bufferPadding, width);
  11975. items.set(
  11976. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  11977. k);
  11978. }
  11979. }
  11980. // Accesses to the items array can take long, because it may not fit into
  11981. // CPU cache and has to be fetched from main memory. Since subsequent
  11982. // accesses to the items array are not local when reading columns, we
  11983. // have a cache miss every time. To reduce cache misses, get up to
  11984. // 'numBuffers' items at a time and store them into the individual
  11985. // buffers. The colBuffers should be small enough to fit into CPU cache.
  11986. var numBuffers = 16;
  11987. var colBuffers = [];
  11988. for (i = 0; i < numBuffers; i++) {
  11989. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  11990. }
  11991. var b, currentBuffer = 0;
  11992. ll = bufferPadding + height;
  11993. // Section F.3.5 VER_SR
  11994. if (height === 1) {
  11995. // if height = 1, when v0 even keep items as is, when odd divide by 2
  11996. if ((v0 & 1) !== 0) {
  11997. for (u = 0; u < width; u++) {
  11998. items[u] *= 0.5;
  11999. }
  12000. }
  12001. } else {
  12002. for (u = 0; u < width; u++) {
  12003. // if we ran out of buffers, copy several image columns at once
  12004. if (currentBuffer === 0) {
  12005. numBuffers = Math.min(width - u, numBuffers);
  12006. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  12007. for (b = 0; b < numBuffers; b++) {
  12008. colBuffers[b][l] = items[k + b];
  12009. }
  12010. }
  12011. currentBuffer = numBuffers;
  12012. }
  12013. currentBuffer--;
  12014. var buffer = colBuffers[currentBuffer];
  12015. this.extend(buffer, bufferPadding, height);
  12016. this.filter(buffer, bufferPadding, height);
  12017. // If this is last buffer in this group of buffers, flush all buffers.
  12018. if (currentBuffer === 0) {
  12019. k = u - numBuffers + 1;
  12020. for (l = bufferPadding; l < ll; k += width, l++) {
  12021. for (b = 0; b < numBuffers; b++) {
  12022. items[k + b] = colBuffers[b][l];
  12023. }
  12024. }
  12025. }
  12026. }
  12027. }
  12028. return {
  12029. width: width,
  12030. height: height,
  12031. items: items
  12032. };
  12033. };
  12034. return Transform;
  12035. })();
  12036. // Section 3.8.2 Irreversible 9-7 filter
  12037. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  12038. function IrreversibleTransform() {
  12039. Transform.call(this);
  12040. }
  12041. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  12042. IrreversibleTransform.prototype.filter =
  12043. function irreversibleTransformFilter(x, offset, length) {
  12044. var len = length >> 1;
  12045. offset = offset | 0;
  12046. var j, n, current, next;
  12047. var alpha = -1.586134342059924;
  12048. var beta = -0.052980118572961;
  12049. var gamma = 0.882911075530934;
  12050. var delta = 0.443506852043971;
  12051. var K = 1.230174104914001;
  12052. var K_ = 1 / K;
  12053. // step 1 is combined with step 3
  12054. // step 2
  12055. j = offset - 3;
  12056. for (n = len + 4; n--; j += 2) {
  12057. x[j] *= K_;
  12058. }
  12059. // step 1 & 3
  12060. j = offset - 2;
  12061. current = delta * x[j -1];
  12062. for (n = len + 3; n--; j += 2) {
  12063. next = delta * x[j + 1];
  12064. x[j] = K * x[j] - current - next;
  12065. if (n--) {
  12066. j += 2;
  12067. current = delta * x[j + 1];
  12068. x[j] = K * x[j] - current - next;
  12069. } else {
  12070. break;
  12071. }
  12072. }
  12073. // step 4
  12074. j = offset - 1;
  12075. current = gamma * x[j - 1];
  12076. for (n = len + 2; n--; j += 2) {
  12077. next = gamma * x[j + 1];
  12078. x[j] -= current + next;
  12079. if (n--) {
  12080. j += 2;
  12081. current = gamma * x[j + 1];
  12082. x[j] -= current + next;
  12083. } else {
  12084. break;
  12085. }
  12086. }
  12087. // step 5
  12088. j = offset;
  12089. current = beta * x[j - 1];
  12090. for (n = len + 1; n--; j += 2) {
  12091. next = beta * x[j + 1];
  12092. x[j] -= current + next;
  12093. if (n--) {
  12094. j += 2;
  12095. current = beta * x[j + 1];
  12096. x[j] -= current + next;
  12097. } else {
  12098. break;
  12099. }
  12100. }
  12101. // step 6
  12102. if (len !== 0) {
  12103. j = offset + 1;
  12104. current = alpha * x[j - 1];
  12105. for (n = len; n--; j += 2) {
  12106. next = alpha * x[j + 1];
  12107. x[j] -= current + next;
  12108. if (n--) {
  12109. j += 2;
  12110. current = alpha * x[j + 1];
  12111. x[j] -= current + next;
  12112. } else {
  12113. break;
  12114. }
  12115. }
  12116. }
  12117. };
  12118. return IrreversibleTransform;
  12119. })();
  12120. // Section 3.8.1 Reversible 5-3 filter
  12121. var ReversibleTransform = (function ReversibleTransformClosure() {
  12122. function ReversibleTransform() {
  12123. Transform.call(this);
  12124. }
  12125. ReversibleTransform.prototype = Object.create(Transform.prototype);
  12126. ReversibleTransform.prototype.filter =
  12127. function reversibleTransformFilter(x, offset, length) {
  12128. var len = length >> 1;
  12129. offset = offset | 0;
  12130. var j, n;
  12131. for (j = offset, n = len + 1; n--; j += 2) {
  12132. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  12133. }
  12134. for (j = offset + 1, n = len; n--; j += 2) {
  12135. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  12136. }
  12137. };
  12138. return ReversibleTransform;
  12139. })();
  12140. return JpxImage;
  12141. })();
  12142. exports.JpxImage = JpxImage;
  12143. }));
  12144. (function (root, factory) {
  12145. {
  12146. factory((root.pdfjsCoreMetrics = {}), root.pdfjsSharedUtil);
  12147. }
  12148. }(this, function (exports, sharedUtil) {
  12149. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  12150. // The Metrics object contains glyph widths (in glyph space units).
  12151. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  12152. // space unit corresponds to 1/1000th of text space unit.
  12153. var getMetrics = getLookupTableFactory(function (t) {
  12154. t['Courier'] = 600;
  12155. t['Courier-Bold'] = 600;
  12156. t['Courier-BoldOblique'] = 600;
  12157. t['Courier-Oblique'] = 600;
  12158. t['Helvetica'] = getLookupTableFactory(function (t) {
  12159. t['space'] = 278;
  12160. t['exclam'] = 278;
  12161. t['quotedbl'] = 355;
  12162. t['numbersign'] = 556;
  12163. t['dollar'] = 556;
  12164. t['percent'] = 889;
  12165. t['ampersand'] = 667;
  12166. t['quoteright'] = 222;
  12167. t['parenleft'] = 333;
  12168. t['parenright'] = 333;
  12169. t['asterisk'] = 389;
  12170. t['plus'] = 584;
  12171. t['comma'] = 278;
  12172. t['hyphen'] = 333;
  12173. t['period'] = 278;
  12174. t['slash'] = 278;
  12175. t['zero'] = 556;
  12176. t['one'] = 556;
  12177. t['two'] = 556;
  12178. t['three'] = 556;
  12179. t['four'] = 556;
  12180. t['five'] = 556;
  12181. t['six'] = 556;
  12182. t['seven'] = 556;
  12183. t['eight'] = 556;
  12184. t['nine'] = 556;
  12185. t['colon'] = 278;
  12186. t['semicolon'] = 278;
  12187. t['less'] = 584;
  12188. t['equal'] = 584;
  12189. t['greater'] = 584;
  12190. t['question'] = 556;
  12191. t['at'] = 1015;
  12192. t['A'] = 667;
  12193. t['B'] = 667;
  12194. t['C'] = 722;
  12195. t['D'] = 722;
  12196. t['E'] = 667;
  12197. t['F'] = 611;
  12198. t['G'] = 778;
  12199. t['H'] = 722;
  12200. t['I'] = 278;
  12201. t['J'] = 500;
  12202. t['K'] = 667;
  12203. t['L'] = 556;
  12204. t['M'] = 833;
  12205. t['N'] = 722;
  12206. t['O'] = 778;
  12207. t['P'] = 667;
  12208. t['Q'] = 778;
  12209. t['R'] = 722;
  12210. t['S'] = 667;
  12211. t['T'] = 611;
  12212. t['U'] = 722;
  12213. t['V'] = 667;
  12214. t['W'] = 944;
  12215. t['X'] = 667;
  12216. t['Y'] = 667;
  12217. t['Z'] = 611;
  12218. t['bracketleft'] = 278;
  12219. t['backslash'] = 278;
  12220. t['bracketright'] = 278;
  12221. t['asciicircum'] = 469;
  12222. t['underscore'] = 556;
  12223. t['quoteleft'] = 222;
  12224. t['a'] = 556;
  12225. t['b'] = 556;
  12226. t['c'] = 500;
  12227. t['d'] = 556;
  12228. t['e'] = 556;
  12229. t['f'] = 278;
  12230. t['g'] = 556;
  12231. t['h'] = 556;
  12232. t['i'] = 222;
  12233. t['j'] = 222;
  12234. t['k'] = 500;
  12235. t['l'] = 222;
  12236. t['m'] = 833;
  12237. t['n'] = 556;
  12238. t['o'] = 556;
  12239. t['p'] = 556;
  12240. t['q'] = 556;
  12241. t['r'] = 333;
  12242. t['s'] = 500;
  12243. t['t'] = 278;
  12244. t['u'] = 556;
  12245. t['v'] = 500;
  12246. t['w'] = 722;
  12247. t['x'] = 500;
  12248. t['y'] = 500;
  12249. t['z'] = 500;
  12250. t['braceleft'] = 334;
  12251. t['bar'] = 260;
  12252. t['braceright'] = 334;
  12253. t['asciitilde'] = 584;
  12254. t['exclamdown'] = 333;
  12255. t['cent'] = 556;
  12256. t['sterling'] = 556;
  12257. t['fraction'] = 167;
  12258. t['yen'] = 556;
  12259. t['florin'] = 556;
  12260. t['section'] = 556;
  12261. t['currency'] = 556;
  12262. t['quotesingle'] = 191;
  12263. t['quotedblleft'] = 333;
  12264. t['guillemotleft'] = 556;
  12265. t['guilsinglleft'] = 333;
  12266. t['guilsinglright'] = 333;
  12267. t['fi'] = 500;
  12268. t['fl'] = 500;
  12269. t['endash'] = 556;
  12270. t['dagger'] = 556;
  12271. t['daggerdbl'] = 556;
  12272. t['periodcentered'] = 278;
  12273. t['paragraph'] = 537;
  12274. t['bullet'] = 350;
  12275. t['quotesinglbase'] = 222;
  12276. t['quotedblbase'] = 333;
  12277. t['quotedblright'] = 333;
  12278. t['guillemotright'] = 556;
  12279. t['ellipsis'] = 1000;
  12280. t['perthousand'] = 1000;
  12281. t['questiondown'] = 611;
  12282. t['grave'] = 333;
  12283. t['acute'] = 333;
  12284. t['circumflex'] = 333;
  12285. t['tilde'] = 333;
  12286. t['macron'] = 333;
  12287. t['breve'] = 333;
  12288. t['dotaccent'] = 333;
  12289. t['dieresis'] = 333;
  12290. t['ring'] = 333;
  12291. t['cedilla'] = 333;
  12292. t['hungarumlaut'] = 333;
  12293. t['ogonek'] = 333;
  12294. t['caron'] = 333;
  12295. t['emdash'] = 1000;
  12296. t['AE'] = 1000;
  12297. t['ordfeminine'] = 370;
  12298. t['Lslash'] = 556;
  12299. t['Oslash'] = 778;
  12300. t['OE'] = 1000;
  12301. t['ordmasculine'] = 365;
  12302. t['ae'] = 889;
  12303. t['dotlessi'] = 278;
  12304. t['lslash'] = 222;
  12305. t['oslash'] = 611;
  12306. t['oe'] = 944;
  12307. t['germandbls'] = 611;
  12308. t['Idieresis'] = 278;
  12309. t['eacute'] = 556;
  12310. t['abreve'] = 556;
  12311. t['uhungarumlaut'] = 556;
  12312. t['ecaron'] = 556;
  12313. t['Ydieresis'] = 667;
  12314. t['divide'] = 584;
  12315. t['Yacute'] = 667;
  12316. t['Acircumflex'] = 667;
  12317. t['aacute'] = 556;
  12318. t['Ucircumflex'] = 722;
  12319. t['yacute'] = 500;
  12320. t['scommaaccent'] = 500;
  12321. t['ecircumflex'] = 556;
  12322. t['Uring'] = 722;
  12323. t['Udieresis'] = 722;
  12324. t['aogonek'] = 556;
  12325. t['Uacute'] = 722;
  12326. t['uogonek'] = 556;
  12327. t['Edieresis'] = 667;
  12328. t['Dcroat'] = 722;
  12329. t['commaaccent'] = 250;
  12330. t['copyright'] = 737;
  12331. t['Emacron'] = 667;
  12332. t['ccaron'] = 500;
  12333. t['aring'] = 556;
  12334. t['Ncommaaccent'] = 722;
  12335. t['lacute'] = 222;
  12336. t['agrave'] = 556;
  12337. t['Tcommaaccent'] = 611;
  12338. t['Cacute'] = 722;
  12339. t['atilde'] = 556;
  12340. t['Edotaccent'] = 667;
  12341. t['scaron'] = 500;
  12342. t['scedilla'] = 500;
  12343. t['iacute'] = 278;
  12344. t['lozenge'] = 471;
  12345. t['Rcaron'] = 722;
  12346. t['Gcommaaccent'] = 778;
  12347. t['ucircumflex'] = 556;
  12348. t['acircumflex'] = 556;
  12349. t['Amacron'] = 667;
  12350. t['rcaron'] = 333;
  12351. t['ccedilla'] = 500;
  12352. t['Zdotaccent'] = 611;
  12353. t['Thorn'] = 667;
  12354. t['Omacron'] = 778;
  12355. t['Racute'] = 722;
  12356. t['Sacute'] = 667;
  12357. t['dcaron'] = 643;
  12358. t['Umacron'] = 722;
  12359. t['uring'] = 556;
  12360. t['threesuperior'] = 333;
  12361. t['Ograve'] = 778;
  12362. t['Agrave'] = 667;
  12363. t['Abreve'] = 667;
  12364. t['multiply'] = 584;
  12365. t['uacute'] = 556;
  12366. t['Tcaron'] = 611;
  12367. t['partialdiff'] = 476;
  12368. t['ydieresis'] = 500;
  12369. t['Nacute'] = 722;
  12370. t['icircumflex'] = 278;
  12371. t['Ecircumflex'] = 667;
  12372. t['adieresis'] = 556;
  12373. t['edieresis'] = 556;
  12374. t['cacute'] = 500;
  12375. t['nacute'] = 556;
  12376. t['umacron'] = 556;
  12377. t['Ncaron'] = 722;
  12378. t['Iacute'] = 278;
  12379. t['plusminus'] = 584;
  12380. t['brokenbar'] = 260;
  12381. t['registered'] = 737;
  12382. t['Gbreve'] = 778;
  12383. t['Idotaccent'] = 278;
  12384. t['summation'] = 600;
  12385. t['Egrave'] = 667;
  12386. t['racute'] = 333;
  12387. t['omacron'] = 556;
  12388. t['Zacute'] = 611;
  12389. t['Zcaron'] = 611;
  12390. t['greaterequal'] = 549;
  12391. t['Eth'] = 722;
  12392. t['Ccedilla'] = 722;
  12393. t['lcommaaccent'] = 222;
  12394. t['tcaron'] = 317;
  12395. t['eogonek'] = 556;
  12396. t['Uogonek'] = 722;
  12397. t['Aacute'] = 667;
  12398. t['Adieresis'] = 667;
  12399. t['egrave'] = 556;
  12400. t['zacute'] = 500;
  12401. t['iogonek'] = 222;
  12402. t['Oacute'] = 778;
  12403. t['oacute'] = 556;
  12404. t['amacron'] = 556;
  12405. t['sacute'] = 500;
  12406. t['idieresis'] = 278;
  12407. t['Ocircumflex'] = 778;
  12408. t['Ugrave'] = 722;
  12409. t['Delta'] = 612;
  12410. t['thorn'] = 556;
  12411. t['twosuperior'] = 333;
  12412. t['Odieresis'] = 778;
  12413. t['mu'] = 556;
  12414. t['igrave'] = 278;
  12415. t['ohungarumlaut'] = 556;
  12416. t['Eogonek'] = 667;
  12417. t['dcroat'] = 556;
  12418. t['threequarters'] = 834;
  12419. t['Scedilla'] = 667;
  12420. t['lcaron'] = 299;
  12421. t['Kcommaaccent'] = 667;
  12422. t['Lacute'] = 556;
  12423. t['trademark'] = 1000;
  12424. t['edotaccent'] = 556;
  12425. t['Igrave'] = 278;
  12426. t['Imacron'] = 278;
  12427. t['Lcaron'] = 556;
  12428. t['onehalf'] = 834;
  12429. t['lessequal'] = 549;
  12430. t['ocircumflex'] = 556;
  12431. t['ntilde'] = 556;
  12432. t['Uhungarumlaut'] = 722;
  12433. t['Eacute'] = 667;
  12434. t['emacron'] = 556;
  12435. t['gbreve'] = 556;
  12436. t['onequarter'] = 834;
  12437. t['Scaron'] = 667;
  12438. t['Scommaaccent'] = 667;
  12439. t['Ohungarumlaut'] = 778;
  12440. t['degree'] = 400;
  12441. t['ograve'] = 556;
  12442. t['Ccaron'] = 722;
  12443. t['ugrave'] = 556;
  12444. t['radical'] = 453;
  12445. t['Dcaron'] = 722;
  12446. t['rcommaaccent'] = 333;
  12447. t['Ntilde'] = 722;
  12448. t['otilde'] = 556;
  12449. t['Rcommaaccent'] = 722;
  12450. t['Lcommaaccent'] = 556;
  12451. t['Atilde'] = 667;
  12452. t['Aogonek'] = 667;
  12453. t['Aring'] = 667;
  12454. t['Otilde'] = 778;
  12455. t['zdotaccent'] = 500;
  12456. t['Ecaron'] = 667;
  12457. t['Iogonek'] = 278;
  12458. t['kcommaaccent'] = 500;
  12459. t['minus'] = 584;
  12460. t['Icircumflex'] = 278;
  12461. t['ncaron'] = 556;
  12462. t['tcommaaccent'] = 278;
  12463. t['logicalnot'] = 584;
  12464. t['odieresis'] = 556;
  12465. t['udieresis'] = 556;
  12466. t['notequal'] = 549;
  12467. t['gcommaaccent'] = 556;
  12468. t['eth'] = 556;
  12469. t['zcaron'] = 500;
  12470. t['ncommaaccent'] = 556;
  12471. t['onesuperior'] = 333;
  12472. t['imacron'] = 278;
  12473. t['Euro'] = 556;
  12474. });
  12475. t['Helvetica-Bold'] = getLookupTableFactory(function (t) {
  12476. t['space'] = 278;
  12477. t['exclam'] = 333;
  12478. t['quotedbl'] = 474;
  12479. t['numbersign'] = 556;
  12480. t['dollar'] = 556;
  12481. t['percent'] = 889;
  12482. t['ampersand'] = 722;
  12483. t['quoteright'] = 278;
  12484. t['parenleft'] = 333;
  12485. t['parenright'] = 333;
  12486. t['asterisk'] = 389;
  12487. t['plus'] = 584;
  12488. t['comma'] = 278;
  12489. t['hyphen'] = 333;
  12490. t['period'] = 278;
  12491. t['slash'] = 278;
  12492. t['zero'] = 556;
  12493. t['one'] = 556;
  12494. t['two'] = 556;
  12495. t['three'] = 556;
  12496. t['four'] = 556;
  12497. t['five'] = 556;
  12498. t['six'] = 556;
  12499. t['seven'] = 556;
  12500. t['eight'] = 556;
  12501. t['nine'] = 556;
  12502. t['colon'] = 333;
  12503. t['semicolon'] = 333;
  12504. t['less'] = 584;
  12505. t['equal'] = 584;
  12506. t['greater'] = 584;
  12507. t['question'] = 611;
  12508. t['at'] = 975;
  12509. t['A'] = 722;
  12510. t['B'] = 722;
  12511. t['C'] = 722;
  12512. t['D'] = 722;
  12513. t['E'] = 667;
  12514. t['F'] = 611;
  12515. t['G'] = 778;
  12516. t['H'] = 722;
  12517. t['I'] = 278;
  12518. t['J'] = 556;
  12519. t['K'] = 722;
  12520. t['L'] = 611;
  12521. t['M'] = 833;
  12522. t['N'] = 722;
  12523. t['O'] = 778;
  12524. t['P'] = 667;
  12525. t['Q'] = 778;
  12526. t['R'] = 722;
  12527. t['S'] = 667;
  12528. t['T'] = 611;
  12529. t['U'] = 722;
  12530. t['V'] = 667;
  12531. t['W'] = 944;
  12532. t['X'] = 667;
  12533. t['Y'] = 667;
  12534. t['Z'] = 611;
  12535. t['bracketleft'] = 333;
  12536. t['backslash'] = 278;
  12537. t['bracketright'] = 333;
  12538. t['asciicircum'] = 584;
  12539. t['underscore'] = 556;
  12540. t['quoteleft'] = 278;
  12541. t['a'] = 556;
  12542. t['b'] = 611;
  12543. t['c'] = 556;
  12544. t['d'] = 611;
  12545. t['e'] = 556;
  12546. t['f'] = 333;
  12547. t['g'] = 611;
  12548. t['h'] = 611;
  12549. t['i'] = 278;
  12550. t['j'] = 278;
  12551. t['k'] = 556;
  12552. t['l'] = 278;
  12553. t['m'] = 889;
  12554. t['n'] = 611;
  12555. t['o'] = 611;
  12556. t['p'] = 611;
  12557. t['q'] = 611;
  12558. t['r'] = 389;
  12559. t['s'] = 556;
  12560. t['t'] = 333;
  12561. t['u'] = 611;
  12562. t['v'] = 556;
  12563. t['w'] = 778;
  12564. t['x'] = 556;
  12565. t['y'] = 556;
  12566. t['z'] = 500;
  12567. t['braceleft'] = 389;
  12568. t['bar'] = 280;
  12569. t['braceright'] = 389;
  12570. t['asciitilde'] = 584;
  12571. t['exclamdown'] = 333;
  12572. t['cent'] = 556;
  12573. t['sterling'] = 556;
  12574. t['fraction'] = 167;
  12575. t['yen'] = 556;
  12576. t['florin'] = 556;
  12577. t['section'] = 556;
  12578. t['currency'] = 556;
  12579. t['quotesingle'] = 238;
  12580. t['quotedblleft'] = 500;
  12581. t['guillemotleft'] = 556;
  12582. t['guilsinglleft'] = 333;
  12583. t['guilsinglright'] = 333;
  12584. t['fi'] = 611;
  12585. t['fl'] = 611;
  12586. t['endash'] = 556;
  12587. t['dagger'] = 556;
  12588. t['daggerdbl'] = 556;
  12589. t['periodcentered'] = 278;
  12590. t['paragraph'] = 556;
  12591. t['bullet'] = 350;
  12592. t['quotesinglbase'] = 278;
  12593. t['quotedblbase'] = 500;
  12594. t['quotedblright'] = 500;
  12595. t['guillemotright'] = 556;
  12596. t['ellipsis'] = 1000;
  12597. t['perthousand'] = 1000;
  12598. t['questiondown'] = 611;
  12599. t['grave'] = 333;
  12600. t['acute'] = 333;
  12601. t['circumflex'] = 333;
  12602. t['tilde'] = 333;
  12603. t['macron'] = 333;
  12604. t['breve'] = 333;
  12605. t['dotaccent'] = 333;
  12606. t['dieresis'] = 333;
  12607. t['ring'] = 333;
  12608. t['cedilla'] = 333;
  12609. t['hungarumlaut'] = 333;
  12610. t['ogonek'] = 333;
  12611. t['caron'] = 333;
  12612. t['emdash'] = 1000;
  12613. t['AE'] = 1000;
  12614. t['ordfeminine'] = 370;
  12615. t['Lslash'] = 611;
  12616. t['Oslash'] = 778;
  12617. t['OE'] = 1000;
  12618. t['ordmasculine'] = 365;
  12619. t['ae'] = 889;
  12620. t['dotlessi'] = 278;
  12621. t['lslash'] = 278;
  12622. t['oslash'] = 611;
  12623. t['oe'] = 944;
  12624. t['germandbls'] = 611;
  12625. t['Idieresis'] = 278;
  12626. t['eacute'] = 556;
  12627. t['abreve'] = 556;
  12628. t['uhungarumlaut'] = 611;
  12629. t['ecaron'] = 556;
  12630. t['Ydieresis'] = 667;
  12631. t['divide'] = 584;
  12632. t['Yacute'] = 667;
  12633. t['Acircumflex'] = 722;
  12634. t['aacute'] = 556;
  12635. t['Ucircumflex'] = 722;
  12636. t['yacute'] = 556;
  12637. t['scommaaccent'] = 556;
  12638. t['ecircumflex'] = 556;
  12639. t['Uring'] = 722;
  12640. t['Udieresis'] = 722;
  12641. t['aogonek'] = 556;
  12642. t['Uacute'] = 722;
  12643. t['uogonek'] = 611;
  12644. t['Edieresis'] = 667;
  12645. t['Dcroat'] = 722;
  12646. t['commaaccent'] = 250;
  12647. t['copyright'] = 737;
  12648. t['Emacron'] = 667;
  12649. t['ccaron'] = 556;
  12650. t['aring'] = 556;
  12651. t['Ncommaaccent'] = 722;
  12652. t['lacute'] = 278;
  12653. t['agrave'] = 556;
  12654. t['Tcommaaccent'] = 611;
  12655. t['Cacute'] = 722;
  12656. t['atilde'] = 556;
  12657. t['Edotaccent'] = 667;
  12658. t['scaron'] = 556;
  12659. t['scedilla'] = 556;
  12660. t['iacute'] = 278;
  12661. t['lozenge'] = 494;
  12662. t['Rcaron'] = 722;
  12663. t['Gcommaaccent'] = 778;
  12664. t['ucircumflex'] = 611;
  12665. t['acircumflex'] = 556;
  12666. t['Amacron'] = 722;
  12667. t['rcaron'] = 389;
  12668. t['ccedilla'] = 556;
  12669. t['Zdotaccent'] = 611;
  12670. t['Thorn'] = 667;
  12671. t['Omacron'] = 778;
  12672. t['Racute'] = 722;
  12673. t['Sacute'] = 667;
  12674. t['dcaron'] = 743;
  12675. t['Umacron'] = 722;
  12676. t['uring'] = 611;
  12677. t['threesuperior'] = 333;
  12678. t['Ograve'] = 778;
  12679. t['Agrave'] = 722;
  12680. t['Abreve'] = 722;
  12681. t['multiply'] = 584;
  12682. t['uacute'] = 611;
  12683. t['Tcaron'] = 611;
  12684. t['partialdiff'] = 494;
  12685. t['ydieresis'] = 556;
  12686. t['Nacute'] = 722;
  12687. t['icircumflex'] = 278;
  12688. t['Ecircumflex'] = 667;
  12689. t['adieresis'] = 556;
  12690. t['edieresis'] = 556;
  12691. t['cacute'] = 556;
  12692. t['nacute'] = 611;
  12693. t['umacron'] = 611;
  12694. t['Ncaron'] = 722;
  12695. t['Iacute'] = 278;
  12696. t['plusminus'] = 584;
  12697. t['brokenbar'] = 280;
  12698. t['registered'] = 737;
  12699. t['Gbreve'] = 778;
  12700. t['Idotaccent'] = 278;
  12701. t['summation'] = 600;
  12702. t['Egrave'] = 667;
  12703. t['racute'] = 389;
  12704. t['omacron'] = 611;
  12705. t['Zacute'] = 611;
  12706. t['Zcaron'] = 611;
  12707. t['greaterequal'] = 549;
  12708. t['Eth'] = 722;
  12709. t['Ccedilla'] = 722;
  12710. t['lcommaaccent'] = 278;
  12711. t['tcaron'] = 389;
  12712. t['eogonek'] = 556;
  12713. t['Uogonek'] = 722;
  12714. t['Aacute'] = 722;
  12715. t['Adieresis'] = 722;
  12716. t['egrave'] = 556;
  12717. t['zacute'] = 500;
  12718. t['iogonek'] = 278;
  12719. t['Oacute'] = 778;
  12720. t['oacute'] = 611;
  12721. t['amacron'] = 556;
  12722. t['sacute'] = 556;
  12723. t['idieresis'] = 278;
  12724. t['Ocircumflex'] = 778;
  12725. t['Ugrave'] = 722;
  12726. t['Delta'] = 612;
  12727. t['thorn'] = 611;
  12728. t['twosuperior'] = 333;
  12729. t['Odieresis'] = 778;
  12730. t['mu'] = 611;
  12731. t['igrave'] = 278;
  12732. t['ohungarumlaut'] = 611;
  12733. t['Eogonek'] = 667;
  12734. t['dcroat'] = 611;
  12735. t['threequarters'] = 834;
  12736. t['Scedilla'] = 667;
  12737. t['lcaron'] = 400;
  12738. t['Kcommaaccent'] = 722;
  12739. t['Lacute'] = 611;
  12740. t['trademark'] = 1000;
  12741. t['edotaccent'] = 556;
  12742. t['Igrave'] = 278;
  12743. t['Imacron'] = 278;
  12744. t['Lcaron'] = 611;
  12745. t['onehalf'] = 834;
  12746. t['lessequal'] = 549;
  12747. t['ocircumflex'] = 611;
  12748. t['ntilde'] = 611;
  12749. t['Uhungarumlaut'] = 722;
  12750. t['Eacute'] = 667;
  12751. t['emacron'] = 556;
  12752. t['gbreve'] = 611;
  12753. t['onequarter'] = 834;
  12754. t['Scaron'] = 667;
  12755. t['Scommaaccent'] = 667;
  12756. t['Ohungarumlaut'] = 778;
  12757. t['degree'] = 400;
  12758. t['ograve'] = 611;
  12759. t['Ccaron'] = 722;
  12760. t['ugrave'] = 611;
  12761. t['radical'] = 549;
  12762. t['Dcaron'] = 722;
  12763. t['rcommaaccent'] = 389;
  12764. t['Ntilde'] = 722;
  12765. t['otilde'] = 611;
  12766. t['Rcommaaccent'] = 722;
  12767. t['Lcommaaccent'] = 611;
  12768. t['Atilde'] = 722;
  12769. t['Aogonek'] = 722;
  12770. t['Aring'] = 722;
  12771. t['Otilde'] = 778;
  12772. t['zdotaccent'] = 500;
  12773. t['Ecaron'] = 667;
  12774. t['Iogonek'] = 278;
  12775. t['kcommaaccent'] = 556;
  12776. t['minus'] = 584;
  12777. t['Icircumflex'] = 278;
  12778. t['ncaron'] = 611;
  12779. t['tcommaaccent'] = 333;
  12780. t['logicalnot'] = 584;
  12781. t['odieresis'] = 611;
  12782. t['udieresis'] = 611;
  12783. t['notequal'] = 549;
  12784. t['gcommaaccent'] = 611;
  12785. t['eth'] = 611;
  12786. t['zcaron'] = 500;
  12787. t['ncommaaccent'] = 611;
  12788. t['onesuperior'] = 333;
  12789. t['imacron'] = 278;
  12790. t['Euro'] = 556;
  12791. });
  12792. t['Helvetica-BoldOblique'] = getLookupTableFactory(function (t) {
  12793. t['space'] = 278;
  12794. t['exclam'] = 333;
  12795. t['quotedbl'] = 474;
  12796. t['numbersign'] = 556;
  12797. t['dollar'] = 556;
  12798. t['percent'] = 889;
  12799. t['ampersand'] = 722;
  12800. t['quoteright'] = 278;
  12801. t['parenleft'] = 333;
  12802. t['parenright'] = 333;
  12803. t['asterisk'] = 389;
  12804. t['plus'] = 584;
  12805. t['comma'] = 278;
  12806. t['hyphen'] = 333;
  12807. t['period'] = 278;
  12808. t['slash'] = 278;
  12809. t['zero'] = 556;
  12810. t['one'] = 556;
  12811. t['two'] = 556;
  12812. t['three'] = 556;
  12813. t['four'] = 556;
  12814. t['five'] = 556;
  12815. t['six'] = 556;
  12816. t['seven'] = 556;
  12817. t['eight'] = 556;
  12818. t['nine'] = 556;
  12819. t['colon'] = 333;
  12820. t['semicolon'] = 333;
  12821. t['less'] = 584;
  12822. t['equal'] = 584;
  12823. t['greater'] = 584;
  12824. t['question'] = 611;
  12825. t['at'] = 975;
  12826. t['A'] = 722;
  12827. t['B'] = 722;
  12828. t['C'] = 722;
  12829. t['D'] = 722;
  12830. t['E'] = 667;
  12831. t['F'] = 611;
  12832. t['G'] = 778;
  12833. t['H'] = 722;
  12834. t['I'] = 278;
  12835. t['J'] = 556;
  12836. t['K'] = 722;
  12837. t['L'] = 611;
  12838. t['M'] = 833;
  12839. t['N'] = 722;
  12840. t['O'] = 778;
  12841. t['P'] = 667;
  12842. t['Q'] = 778;
  12843. t['R'] = 722;
  12844. t['S'] = 667;
  12845. t['T'] = 611;
  12846. t['U'] = 722;
  12847. t['V'] = 667;
  12848. t['W'] = 944;
  12849. t['X'] = 667;
  12850. t['Y'] = 667;
  12851. t['Z'] = 611;
  12852. t['bracketleft'] = 333;
  12853. t['backslash'] = 278;
  12854. t['bracketright'] = 333;
  12855. t['asciicircum'] = 584;
  12856. t['underscore'] = 556;
  12857. t['quoteleft'] = 278;
  12858. t['a'] = 556;
  12859. t['b'] = 611;
  12860. t['c'] = 556;
  12861. t['d'] = 611;
  12862. t['e'] = 556;
  12863. t['f'] = 333;
  12864. t['g'] = 611;
  12865. t['h'] = 611;
  12866. t['i'] = 278;
  12867. t['j'] = 278;
  12868. t['k'] = 556;
  12869. t['l'] = 278;
  12870. t['m'] = 889;
  12871. t['n'] = 611;
  12872. t['o'] = 611;
  12873. t['p'] = 611;
  12874. t['q'] = 611;
  12875. t['r'] = 389;
  12876. t['s'] = 556;
  12877. t['t'] = 333;
  12878. t['u'] = 611;
  12879. t['v'] = 556;
  12880. t['w'] = 778;
  12881. t['x'] = 556;
  12882. t['y'] = 556;
  12883. t['z'] = 500;
  12884. t['braceleft'] = 389;
  12885. t['bar'] = 280;
  12886. t['braceright'] = 389;
  12887. t['asciitilde'] = 584;
  12888. t['exclamdown'] = 333;
  12889. t['cent'] = 556;
  12890. t['sterling'] = 556;
  12891. t['fraction'] = 167;
  12892. t['yen'] = 556;
  12893. t['florin'] = 556;
  12894. t['section'] = 556;
  12895. t['currency'] = 556;
  12896. t['quotesingle'] = 238;
  12897. t['quotedblleft'] = 500;
  12898. t['guillemotleft'] = 556;
  12899. t['guilsinglleft'] = 333;
  12900. t['guilsinglright'] = 333;
  12901. t['fi'] = 611;
  12902. t['fl'] = 611;
  12903. t['endash'] = 556;
  12904. t['dagger'] = 556;
  12905. t['daggerdbl'] = 556;
  12906. t['periodcentered'] = 278;
  12907. t['paragraph'] = 556;
  12908. t['bullet'] = 350;
  12909. t['quotesinglbase'] = 278;
  12910. t['quotedblbase'] = 500;
  12911. t['quotedblright'] = 500;
  12912. t['guillemotright'] = 556;
  12913. t['ellipsis'] = 1000;
  12914. t['perthousand'] = 1000;
  12915. t['questiondown'] = 611;
  12916. t['grave'] = 333;
  12917. t['acute'] = 333;
  12918. t['circumflex'] = 333;
  12919. t['tilde'] = 333;
  12920. t['macron'] = 333;
  12921. t['breve'] = 333;
  12922. t['dotaccent'] = 333;
  12923. t['dieresis'] = 333;
  12924. t['ring'] = 333;
  12925. t['cedilla'] = 333;
  12926. t['hungarumlaut'] = 333;
  12927. t['ogonek'] = 333;
  12928. t['caron'] = 333;
  12929. t['emdash'] = 1000;
  12930. t['AE'] = 1000;
  12931. t['ordfeminine'] = 370;
  12932. t['Lslash'] = 611;
  12933. t['Oslash'] = 778;
  12934. t['OE'] = 1000;
  12935. t['ordmasculine'] = 365;
  12936. t['ae'] = 889;
  12937. t['dotlessi'] = 278;
  12938. t['lslash'] = 278;
  12939. t['oslash'] = 611;
  12940. t['oe'] = 944;
  12941. t['germandbls'] = 611;
  12942. t['Idieresis'] = 278;
  12943. t['eacute'] = 556;
  12944. t['abreve'] = 556;
  12945. t['uhungarumlaut'] = 611;
  12946. t['ecaron'] = 556;
  12947. t['Ydieresis'] = 667;
  12948. t['divide'] = 584;
  12949. t['Yacute'] = 667;
  12950. t['Acircumflex'] = 722;
  12951. t['aacute'] = 556;
  12952. t['Ucircumflex'] = 722;
  12953. t['yacute'] = 556;
  12954. t['scommaaccent'] = 556;
  12955. t['ecircumflex'] = 556;
  12956. t['Uring'] = 722;
  12957. t['Udieresis'] = 722;
  12958. t['aogonek'] = 556;
  12959. t['Uacute'] = 722;
  12960. t['uogonek'] = 611;
  12961. t['Edieresis'] = 667;
  12962. t['Dcroat'] = 722;
  12963. t['commaaccent'] = 250;
  12964. t['copyright'] = 737;
  12965. t['Emacron'] = 667;
  12966. t['ccaron'] = 556;
  12967. t['aring'] = 556;
  12968. t['Ncommaaccent'] = 722;
  12969. t['lacute'] = 278;
  12970. t['agrave'] = 556;
  12971. t['Tcommaaccent'] = 611;
  12972. t['Cacute'] = 722;
  12973. t['atilde'] = 556;
  12974. t['Edotaccent'] = 667;
  12975. t['scaron'] = 556;
  12976. t['scedilla'] = 556;
  12977. t['iacute'] = 278;
  12978. t['lozenge'] = 494;
  12979. t['Rcaron'] = 722;
  12980. t['Gcommaaccent'] = 778;
  12981. t['ucircumflex'] = 611;
  12982. t['acircumflex'] = 556;
  12983. t['Amacron'] = 722;
  12984. t['rcaron'] = 389;
  12985. t['ccedilla'] = 556;
  12986. t['Zdotaccent'] = 611;
  12987. t['Thorn'] = 667;
  12988. t['Omacron'] = 778;
  12989. t['Racute'] = 722;
  12990. t['Sacute'] = 667;
  12991. t['dcaron'] = 743;
  12992. t['Umacron'] = 722;
  12993. t['uring'] = 611;
  12994. t['threesuperior'] = 333;
  12995. t['Ograve'] = 778;
  12996. t['Agrave'] = 722;
  12997. t['Abreve'] = 722;
  12998. t['multiply'] = 584;
  12999. t['uacute'] = 611;
  13000. t['Tcaron'] = 611;
  13001. t['partialdiff'] = 494;
  13002. t['ydieresis'] = 556;
  13003. t['Nacute'] = 722;
  13004. t['icircumflex'] = 278;
  13005. t['Ecircumflex'] = 667;
  13006. t['adieresis'] = 556;
  13007. t['edieresis'] = 556;
  13008. t['cacute'] = 556;
  13009. t['nacute'] = 611;
  13010. t['umacron'] = 611;
  13011. t['Ncaron'] = 722;
  13012. t['Iacute'] = 278;
  13013. t['plusminus'] = 584;
  13014. t['brokenbar'] = 280;
  13015. t['registered'] = 737;
  13016. t['Gbreve'] = 778;
  13017. t['Idotaccent'] = 278;
  13018. t['summation'] = 600;
  13019. t['Egrave'] = 667;
  13020. t['racute'] = 389;
  13021. t['omacron'] = 611;
  13022. t['Zacute'] = 611;
  13023. t['Zcaron'] = 611;
  13024. t['greaterequal'] = 549;
  13025. t['Eth'] = 722;
  13026. t['Ccedilla'] = 722;
  13027. t['lcommaaccent'] = 278;
  13028. t['tcaron'] = 389;
  13029. t['eogonek'] = 556;
  13030. t['Uogonek'] = 722;
  13031. t['Aacute'] = 722;
  13032. t['Adieresis'] = 722;
  13033. t['egrave'] = 556;
  13034. t['zacute'] = 500;
  13035. t['iogonek'] = 278;
  13036. t['Oacute'] = 778;
  13037. t['oacute'] = 611;
  13038. t['amacron'] = 556;
  13039. t['sacute'] = 556;
  13040. t['idieresis'] = 278;
  13041. t['Ocircumflex'] = 778;
  13042. t['Ugrave'] = 722;
  13043. t['Delta'] = 612;
  13044. t['thorn'] = 611;
  13045. t['twosuperior'] = 333;
  13046. t['Odieresis'] = 778;
  13047. t['mu'] = 611;
  13048. t['igrave'] = 278;
  13049. t['ohungarumlaut'] = 611;
  13050. t['Eogonek'] = 667;
  13051. t['dcroat'] = 611;
  13052. t['threequarters'] = 834;
  13053. t['Scedilla'] = 667;
  13054. t['lcaron'] = 400;
  13055. t['Kcommaaccent'] = 722;
  13056. t['Lacute'] = 611;
  13057. t['trademark'] = 1000;
  13058. t['edotaccent'] = 556;
  13059. t['Igrave'] = 278;
  13060. t['Imacron'] = 278;
  13061. t['Lcaron'] = 611;
  13062. t['onehalf'] = 834;
  13063. t['lessequal'] = 549;
  13064. t['ocircumflex'] = 611;
  13065. t['ntilde'] = 611;
  13066. t['Uhungarumlaut'] = 722;
  13067. t['Eacute'] = 667;
  13068. t['emacron'] = 556;
  13069. t['gbreve'] = 611;
  13070. t['onequarter'] = 834;
  13071. t['Scaron'] = 667;
  13072. t['Scommaaccent'] = 667;
  13073. t['Ohungarumlaut'] = 778;
  13074. t['degree'] = 400;
  13075. t['ograve'] = 611;
  13076. t['Ccaron'] = 722;
  13077. t['ugrave'] = 611;
  13078. t['radical'] = 549;
  13079. t['Dcaron'] = 722;
  13080. t['rcommaaccent'] = 389;
  13081. t['Ntilde'] = 722;
  13082. t['otilde'] = 611;
  13083. t['Rcommaaccent'] = 722;
  13084. t['Lcommaaccent'] = 611;
  13085. t['Atilde'] = 722;
  13086. t['Aogonek'] = 722;
  13087. t['Aring'] = 722;
  13088. t['Otilde'] = 778;
  13089. t['zdotaccent'] = 500;
  13090. t['Ecaron'] = 667;
  13091. t['Iogonek'] = 278;
  13092. t['kcommaaccent'] = 556;
  13093. t['minus'] = 584;
  13094. t['Icircumflex'] = 278;
  13095. t['ncaron'] = 611;
  13096. t['tcommaaccent'] = 333;
  13097. t['logicalnot'] = 584;
  13098. t['odieresis'] = 611;
  13099. t['udieresis'] = 611;
  13100. t['notequal'] = 549;
  13101. t['gcommaaccent'] = 611;
  13102. t['eth'] = 611;
  13103. t['zcaron'] = 500;
  13104. t['ncommaaccent'] = 611;
  13105. t['onesuperior'] = 333;
  13106. t['imacron'] = 278;
  13107. t['Euro'] = 556;
  13108. });
  13109. t['Helvetica-Oblique'] = getLookupTableFactory(function (t) {
  13110. t['space'] = 278;
  13111. t['exclam'] = 278;
  13112. t['quotedbl'] = 355;
  13113. t['numbersign'] = 556;
  13114. t['dollar'] = 556;
  13115. t['percent'] = 889;
  13116. t['ampersand'] = 667;
  13117. t['quoteright'] = 222;
  13118. t['parenleft'] = 333;
  13119. t['parenright'] = 333;
  13120. t['asterisk'] = 389;
  13121. t['plus'] = 584;
  13122. t['comma'] = 278;
  13123. t['hyphen'] = 333;
  13124. t['period'] = 278;
  13125. t['slash'] = 278;
  13126. t['zero'] = 556;
  13127. t['one'] = 556;
  13128. t['two'] = 556;
  13129. t['three'] = 556;
  13130. t['four'] = 556;
  13131. t['five'] = 556;
  13132. t['six'] = 556;
  13133. t['seven'] = 556;
  13134. t['eight'] = 556;
  13135. t['nine'] = 556;
  13136. t['colon'] = 278;
  13137. t['semicolon'] = 278;
  13138. t['less'] = 584;
  13139. t['equal'] = 584;
  13140. t['greater'] = 584;
  13141. t['question'] = 556;
  13142. t['at'] = 1015;
  13143. t['A'] = 667;
  13144. t['B'] = 667;
  13145. t['C'] = 722;
  13146. t['D'] = 722;
  13147. t['E'] = 667;
  13148. t['F'] = 611;
  13149. t['G'] = 778;
  13150. t['H'] = 722;
  13151. t['I'] = 278;
  13152. t['J'] = 500;
  13153. t['K'] = 667;
  13154. t['L'] = 556;
  13155. t['M'] = 833;
  13156. t['N'] = 722;
  13157. t['O'] = 778;
  13158. t['P'] = 667;
  13159. t['Q'] = 778;
  13160. t['R'] = 722;
  13161. t['S'] = 667;
  13162. t['T'] = 611;
  13163. t['U'] = 722;
  13164. t['V'] = 667;
  13165. t['W'] = 944;
  13166. t['X'] = 667;
  13167. t['Y'] = 667;
  13168. t['Z'] = 611;
  13169. t['bracketleft'] = 278;
  13170. t['backslash'] = 278;
  13171. t['bracketright'] = 278;
  13172. t['asciicircum'] = 469;
  13173. t['underscore'] = 556;
  13174. t['quoteleft'] = 222;
  13175. t['a'] = 556;
  13176. t['b'] = 556;
  13177. t['c'] = 500;
  13178. t['d'] = 556;
  13179. t['e'] = 556;
  13180. t['f'] = 278;
  13181. t['g'] = 556;
  13182. t['h'] = 556;
  13183. t['i'] = 222;
  13184. t['j'] = 222;
  13185. t['k'] = 500;
  13186. t['l'] = 222;
  13187. t['m'] = 833;
  13188. t['n'] = 556;
  13189. t['o'] = 556;
  13190. t['p'] = 556;
  13191. t['q'] = 556;
  13192. t['r'] = 333;
  13193. t['s'] = 500;
  13194. t['t'] = 278;
  13195. t['u'] = 556;
  13196. t['v'] = 500;
  13197. t['w'] = 722;
  13198. t['x'] = 500;
  13199. t['y'] = 500;
  13200. t['z'] = 500;
  13201. t['braceleft'] = 334;
  13202. t['bar'] = 260;
  13203. t['braceright'] = 334;
  13204. t['asciitilde'] = 584;
  13205. t['exclamdown'] = 333;
  13206. t['cent'] = 556;
  13207. t['sterling'] = 556;
  13208. t['fraction'] = 167;
  13209. t['yen'] = 556;
  13210. t['florin'] = 556;
  13211. t['section'] = 556;
  13212. t['currency'] = 556;
  13213. t['quotesingle'] = 191;
  13214. t['quotedblleft'] = 333;
  13215. t['guillemotleft'] = 556;
  13216. t['guilsinglleft'] = 333;
  13217. t['guilsinglright'] = 333;
  13218. t['fi'] = 500;
  13219. t['fl'] = 500;
  13220. t['endash'] = 556;
  13221. t['dagger'] = 556;
  13222. t['daggerdbl'] = 556;
  13223. t['periodcentered'] = 278;
  13224. t['paragraph'] = 537;
  13225. t['bullet'] = 350;
  13226. t['quotesinglbase'] = 222;
  13227. t['quotedblbase'] = 333;
  13228. t['quotedblright'] = 333;
  13229. t['guillemotright'] = 556;
  13230. t['ellipsis'] = 1000;
  13231. t['perthousand'] = 1000;
  13232. t['questiondown'] = 611;
  13233. t['grave'] = 333;
  13234. t['acute'] = 333;
  13235. t['circumflex'] = 333;
  13236. t['tilde'] = 333;
  13237. t['macron'] = 333;
  13238. t['breve'] = 333;
  13239. t['dotaccent'] = 333;
  13240. t['dieresis'] = 333;
  13241. t['ring'] = 333;
  13242. t['cedilla'] = 333;
  13243. t['hungarumlaut'] = 333;
  13244. t['ogonek'] = 333;
  13245. t['caron'] = 333;
  13246. t['emdash'] = 1000;
  13247. t['AE'] = 1000;
  13248. t['ordfeminine'] = 370;
  13249. t['Lslash'] = 556;
  13250. t['Oslash'] = 778;
  13251. t['OE'] = 1000;
  13252. t['ordmasculine'] = 365;
  13253. t['ae'] = 889;
  13254. t['dotlessi'] = 278;
  13255. t['lslash'] = 222;
  13256. t['oslash'] = 611;
  13257. t['oe'] = 944;
  13258. t['germandbls'] = 611;
  13259. t['Idieresis'] = 278;
  13260. t['eacute'] = 556;
  13261. t['abreve'] = 556;
  13262. t['uhungarumlaut'] = 556;
  13263. t['ecaron'] = 556;
  13264. t['Ydieresis'] = 667;
  13265. t['divide'] = 584;
  13266. t['Yacute'] = 667;
  13267. t['Acircumflex'] = 667;
  13268. t['aacute'] = 556;
  13269. t['Ucircumflex'] = 722;
  13270. t['yacute'] = 500;
  13271. t['scommaaccent'] = 500;
  13272. t['ecircumflex'] = 556;
  13273. t['Uring'] = 722;
  13274. t['Udieresis'] = 722;
  13275. t['aogonek'] = 556;
  13276. t['Uacute'] = 722;
  13277. t['uogonek'] = 556;
  13278. t['Edieresis'] = 667;
  13279. t['Dcroat'] = 722;
  13280. t['commaaccent'] = 250;
  13281. t['copyright'] = 737;
  13282. t['Emacron'] = 667;
  13283. t['ccaron'] = 500;
  13284. t['aring'] = 556;
  13285. t['Ncommaaccent'] = 722;
  13286. t['lacute'] = 222;
  13287. t['agrave'] = 556;
  13288. t['Tcommaaccent'] = 611;
  13289. t['Cacute'] = 722;
  13290. t['atilde'] = 556;
  13291. t['Edotaccent'] = 667;
  13292. t['scaron'] = 500;
  13293. t['scedilla'] = 500;
  13294. t['iacute'] = 278;
  13295. t['lozenge'] = 471;
  13296. t['Rcaron'] = 722;
  13297. t['Gcommaaccent'] = 778;
  13298. t['ucircumflex'] = 556;
  13299. t['acircumflex'] = 556;
  13300. t['Amacron'] = 667;
  13301. t['rcaron'] = 333;
  13302. t['ccedilla'] = 500;
  13303. t['Zdotaccent'] = 611;
  13304. t['Thorn'] = 667;
  13305. t['Omacron'] = 778;
  13306. t['Racute'] = 722;
  13307. t['Sacute'] = 667;
  13308. t['dcaron'] = 643;
  13309. t['Umacron'] = 722;
  13310. t['uring'] = 556;
  13311. t['threesuperior'] = 333;
  13312. t['Ograve'] = 778;
  13313. t['Agrave'] = 667;
  13314. t['Abreve'] = 667;
  13315. t['multiply'] = 584;
  13316. t['uacute'] = 556;
  13317. t['Tcaron'] = 611;
  13318. t['partialdiff'] = 476;
  13319. t['ydieresis'] = 500;
  13320. t['Nacute'] = 722;
  13321. t['icircumflex'] = 278;
  13322. t['Ecircumflex'] = 667;
  13323. t['adieresis'] = 556;
  13324. t['edieresis'] = 556;
  13325. t['cacute'] = 500;
  13326. t['nacute'] = 556;
  13327. t['umacron'] = 556;
  13328. t['Ncaron'] = 722;
  13329. t['Iacute'] = 278;
  13330. t['plusminus'] = 584;
  13331. t['brokenbar'] = 260;
  13332. t['registered'] = 737;
  13333. t['Gbreve'] = 778;
  13334. t['Idotaccent'] = 278;
  13335. t['summation'] = 600;
  13336. t['Egrave'] = 667;
  13337. t['racute'] = 333;
  13338. t['omacron'] = 556;
  13339. t['Zacute'] = 611;
  13340. t['Zcaron'] = 611;
  13341. t['greaterequal'] = 549;
  13342. t['Eth'] = 722;
  13343. t['Ccedilla'] = 722;
  13344. t['lcommaaccent'] = 222;
  13345. t['tcaron'] = 317;
  13346. t['eogonek'] = 556;
  13347. t['Uogonek'] = 722;
  13348. t['Aacute'] = 667;
  13349. t['Adieresis'] = 667;
  13350. t['egrave'] = 556;
  13351. t['zacute'] = 500;
  13352. t['iogonek'] = 222;
  13353. t['Oacute'] = 778;
  13354. t['oacute'] = 556;
  13355. t['amacron'] = 556;
  13356. t['sacute'] = 500;
  13357. t['idieresis'] = 278;
  13358. t['Ocircumflex'] = 778;
  13359. t['Ugrave'] = 722;
  13360. t['Delta'] = 612;
  13361. t['thorn'] = 556;
  13362. t['twosuperior'] = 333;
  13363. t['Odieresis'] = 778;
  13364. t['mu'] = 556;
  13365. t['igrave'] = 278;
  13366. t['ohungarumlaut'] = 556;
  13367. t['Eogonek'] = 667;
  13368. t['dcroat'] = 556;
  13369. t['threequarters'] = 834;
  13370. t['Scedilla'] = 667;
  13371. t['lcaron'] = 299;
  13372. t['Kcommaaccent'] = 667;
  13373. t['Lacute'] = 556;
  13374. t['trademark'] = 1000;
  13375. t['edotaccent'] = 556;
  13376. t['Igrave'] = 278;
  13377. t['Imacron'] = 278;
  13378. t['Lcaron'] = 556;
  13379. t['onehalf'] = 834;
  13380. t['lessequal'] = 549;
  13381. t['ocircumflex'] = 556;
  13382. t['ntilde'] = 556;
  13383. t['Uhungarumlaut'] = 722;
  13384. t['Eacute'] = 667;
  13385. t['emacron'] = 556;
  13386. t['gbreve'] = 556;
  13387. t['onequarter'] = 834;
  13388. t['Scaron'] = 667;
  13389. t['Scommaaccent'] = 667;
  13390. t['Ohungarumlaut'] = 778;
  13391. t['degree'] = 400;
  13392. t['ograve'] = 556;
  13393. t['Ccaron'] = 722;
  13394. t['ugrave'] = 556;
  13395. t['radical'] = 453;
  13396. t['Dcaron'] = 722;
  13397. t['rcommaaccent'] = 333;
  13398. t['Ntilde'] = 722;
  13399. t['otilde'] = 556;
  13400. t['Rcommaaccent'] = 722;
  13401. t['Lcommaaccent'] = 556;
  13402. t['Atilde'] = 667;
  13403. t['Aogonek'] = 667;
  13404. t['Aring'] = 667;
  13405. t['Otilde'] = 778;
  13406. t['zdotaccent'] = 500;
  13407. t['Ecaron'] = 667;
  13408. t['Iogonek'] = 278;
  13409. t['kcommaaccent'] = 500;
  13410. t['minus'] = 584;
  13411. t['Icircumflex'] = 278;
  13412. t['ncaron'] = 556;
  13413. t['tcommaaccent'] = 278;
  13414. t['logicalnot'] = 584;
  13415. t['odieresis'] = 556;
  13416. t['udieresis'] = 556;
  13417. t['notequal'] = 549;
  13418. t['gcommaaccent'] = 556;
  13419. t['eth'] = 556;
  13420. t['zcaron'] = 500;
  13421. t['ncommaaccent'] = 556;
  13422. t['onesuperior'] = 333;
  13423. t['imacron'] = 278;
  13424. t['Euro'] = 556;
  13425. });
  13426. t['Symbol'] = getLookupTableFactory(function (t) {
  13427. t['space'] = 250;
  13428. t['exclam'] = 333;
  13429. t['universal'] = 713;
  13430. t['numbersign'] = 500;
  13431. t['existential'] = 549;
  13432. t['percent'] = 833;
  13433. t['ampersand'] = 778;
  13434. t['suchthat'] = 439;
  13435. t['parenleft'] = 333;
  13436. t['parenright'] = 333;
  13437. t['asteriskmath'] = 500;
  13438. t['plus'] = 549;
  13439. t['comma'] = 250;
  13440. t['minus'] = 549;
  13441. t['period'] = 250;
  13442. t['slash'] = 278;
  13443. t['zero'] = 500;
  13444. t['one'] = 500;
  13445. t['two'] = 500;
  13446. t['three'] = 500;
  13447. t['four'] = 500;
  13448. t['five'] = 500;
  13449. t['six'] = 500;
  13450. t['seven'] = 500;
  13451. t['eight'] = 500;
  13452. t['nine'] = 500;
  13453. t['colon'] = 278;
  13454. t['semicolon'] = 278;
  13455. t['less'] = 549;
  13456. t['equal'] = 549;
  13457. t['greater'] = 549;
  13458. t['question'] = 444;
  13459. t['congruent'] = 549;
  13460. t['Alpha'] = 722;
  13461. t['Beta'] = 667;
  13462. t['Chi'] = 722;
  13463. t['Delta'] = 612;
  13464. t['Epsilon'] = 611;
  13465. t['Phi'] = 763;
  13466. t['Gamma'] = 603;
  13467. t['Eta'] = 722;
  13468. t['Iota'] = 333;
  13469. t['theta1'] = 631;
  13470. t['Kappa'] = 722;
  13471. t['Lambda'] = 686;
  13472. t['Mu'] = 889;
  13473. t['Nu'] = 722;
  13474. t['Omicron'] = 722;
  13475. t['Pi'] = 768;
  13476. t['Theta'] = 741;
  13477. t['Rho'] = 556;
  13478. t['Sigma'] = 592;
  13479. t['Tau'] = 611;
  13480. t['Upsilon'] = 690;
  13481. t['sigma1'] = 439;
  13482. t['Omega'] = 768;
  13483. t['Xi'] = 645;
  13484. t['Psi'] = 795;
  13485. t['Zeta'] = 611;
  13486. t['bracketleft'] = 333;
  13487. t['therefore'] = 863;
  13488. t['bracketright'] = 333;
  13489. t['perpendicular'] = 658;
  13490. t['underscore'] = 500;
  13491. t['radicalex'] = 500;
  13492. t['alpha'] = 631;
  13493. t['beta'] = 549;
  13494. t['chi'] = 549;
  13495. t['delta'] = 494;
  13496. t['epsilon'] = 439;
  13497. t['phi'] = 521;
  13498. t['gamma'] = 411;
  13499. t['eta'] = 603;
  13500. t['iota'] = 329;
  13501. t['phi1'] = 603;
  13502. t['kappa'] = 549;
  13503. t['lambda'] = 549;
  13504. t['mu'] = 576;
  13505. t['nu'] = 521;
  13506. t['omicron'] = 549;
  13507. t['pi'] = 549;
  13508. t['theta'] = 521;
  13509. t['rho'] = 549;
  13510. t['sigma'] = 603;
  13511. t['tau'] = 439;
  13512. t['upsilon'] = 576;
  13513. t['omega1'] = 713;
  13514. t['omega'] = 686;
  13515. t['xi'] = 493;
  13516. t['psi'] = 686;
  13517. t['zeta'] = 494;
  13518. t['braceleft'] = 480;
  13519. t['bar'] = 200;
  13520. t['braceright'] = 480;
  13521. t['similar'] = 549;
  13522. t['Euro'] = 750;
  13523. t['Upsilon1'] = 620;
  13524. t['minute'] = 247;
  13525. t['lessequal'] = 549;
  13526. t['fraction'] = 167;
  13527. t['infinity'] = 713;
  13528. t['florin'] = 500;
  13529. t['club'] = 753;
  13530. t['diamond'] = 753;
  13531. t['heart'] = 753;
  13532. t['spade'] = 753;
  13533. t['arrowboth'] = 1042;
  13534. t['arrowleft'] = 987;
  13535. t['arrowup'] = 603;
  13536. t['arrowright'] = 987;
  13537. t['arrowdown'] = 603;
  13538. t['degree'] = 400;
  13539. t['plusminus'] = 549;
  13540. t['second'] = 411;
  13541. t['greaterequal'] = 549;
  13542. t['multiply'] = 549;
  13543. t['proportional'] = 713;
  13544. t['partialdiff'] = 494;
  13545. t['bullet'] = 460;
  13546. t['divide'] = 549;
  13547. t['notequal'] = 549;
  13548. t['equivalence'] = 549;
  13549. t['approxequal'] = 549;
  13550. t['ellipsis'] = 1000;
  13551. t['arrowvertex'] = 603;
  13552. t['arrowhorizex'] = 1000;
  13553. t['carriagereturn'] = 658;
  13554. t['aleph'] = 823;
  13555. t['Ifraktur'] = 686;
  13556. t['Rfraktur'] = 795;
  13557. t['weierstrass'] = 987;
  13558. t['circlemultiply'] = 768;
  13559. t['circleplus'] = 768;
  13560. t['emptyset'] = 823;
  13561. t['intersection'] = 768;
  13562. t['union'] = 768;
  13563. t['propersuperset'] = 713;
  13564. t['reflexsuperset'] = 713;
  13565. t['notsubset'] = 713;
  13566. t['propersubset'] = 713;
  13567. t['reflexsubset'] = 713;
  13568. t['element'] = 713;
  13569. t['notelement'] = 713;
  13570. t['angle'] = 768;
  13571. t['gradient'] = 713;
  13572. t['registerserif'] = 790;
  13573. t['copyrightserif'] = 790;
  13574. t['trademarkserif'] = 890;
  13575. t['product'] = 823;
  13576. t['radical'] = 549;
  13577. t['dotmath'] = 250;
  13578. t['logicalnot'] = 713;
  13579. t['logicaland'] = 603;
  13580. t['logicalor'] = 603;
  13581. t['arrowdblboth'] = 1042;
  13582. t['arrowdblleft'] = 987;
  13583. t['arrowdblup'] = 603;
  13584. t['arrowdblright'] = 987;
  13585. t['arrowdbldown'] = 603;
  13586. t['lozenge'] = 494;
  13587. t['angleleft'] = 329;
  13588. t['registersans'] = 790;
  13589. t['copyrightsans'] = 790;
  13590. t['trademarksans'] = 786;
  13591. t['summation'] = 713;
  13592. t['parenlefttp'] = 384;
  13593. t['parenleftex'] = 384;
  13594. t['parenleftbt'] = 384;
  13595. t['bracketlefttp'] = 384;
  13596. t['bracketleftex'] = 384;
  13597. t['bracketleftbt'] = 384;
  13598. t['bracelefttp'] = 494;
  13599. t['braceleftmid'] = 494;
  13600. t['braceleftbt'] = 494;
  13601. t['braceex'] = 494;
  13602. t['angleright'] = 329;
  13603. t['integral'] = 274;
  13604. t['integraltp'] = 686;
  13605. t['integralex'] = 686;
  13606. t['integralbt'] = 686;
  13607. t['parenrighttp'] = 384;
  13608. t['parenrightex'] = 384;
  13609. t['parenrightbt'] = 384;
  13610. t['bracketrighttp'] = 384;
  13611. t['bracketrightex'] = 384;
  13612. t['bracketrightbt'] = 384;
  13613. t['bracerighttp'] = 494;
  13614. t['bracerightmid'] = 494;
  13615. t['bracerightbt'] = 494;
  13616. t['apple'] = 790;
  13617. });
  13618. t['Times-Roman'] = getLookupTableFactory(function (t) {
  13619. t['space'] = 250;
  13620. t['exclam'] = 333;
  13621. t['quotedbl'] = 408;
  13622. t['numbersign'] = 500;
  13623. t['dollar'] = 500;
  13624. t['percent'] = 833;
  13625. t['ampersand'] = 778;
  13626. t['quoteright'] = 333;
  13627. t['parenleft'] = 333;
  13628. t['parenright'] = 333;
  13629. t['asterisk'] = 500;
  13630. t['plus'] = 564;
  13631. t['comma'] = 250;
  13632. t['hyphen'] = 333;
  13633. t['period'] = 250;
  13634. t['slash'] = 278;
  13635. t['zero'] = 500;
  13636. t['one'] = 500;
  13637. t['two'] = 500;
  13638. t['three'] = 500;
  13639. t['four'] = 500;
  13640. t['five'] = 500;
  13641. t['six'] = 500;
  13642. t['seven'] = 500;
  13643. t['eight'] = 500;
  13644. t['nine'] = 500;
  13645. t['colon'] = 278;
  13646. t['semicolon'] = 278;
  13647. t['less'] = 564;
  13648. t['equal'] = 564;
  13649. t['greater'] = 564;
  13650. t['question'] = 444;
  13651. t['at'] = 921;
  13652. t['A'] = 722;
  13653. t['B'] = 667;
  13654. t['C'] = 667;
  13655. t['D'] = 722;
  13656. t['E'] = 611;
  13657. t['F'] = 556;
  13658. t['G'] = 722;
  13659. t['H'] = 722;
  13660. t['I'] = 333;
  13661. t['J'] = 389;
  13662. t['K'] = 722;
  13663. t['L'] = 611;
  13664. t['M'] = 889;
  13665. t['N'] = 722;
  13666. t['O'] = 722;
  13667. t['P'] = 556;
  13668. t['Q'] = 722;
  13669. t['R'] = 667;
  13670. t['S'] = 556;
  13671. t['T'] = 611;
  13672. t['U'] = 722;
  13673. t['V'] = 722;
  13674. t['W'] = 944;
  13675. t['X'] = 722;
  13676. t['Y'] = 722;
  13677. t['Z'] = 611;
  13678. t['bracketleft'] = 333;
  13679. t['backslash'] = 278;
  13680. t['bracketright'] = 333;
  13681. t['asciicircum'] = 469;
  13682. t['underscore'] = 500;
  13683. t['quoteleft'] = 333;
  13684. t['a'] = 444;
  13685. t['b'] = 500;
  13686. t['c'] = 444;
  13687. t['d'] = 500;
  13688. t['e'] = 444;
  13689. t['f'] = 333;
  13690. t['g'] = 500;
  13691. t['h'] = 500;
  13692. t['i'] = 278;
  13693. t['j'] = 278;
  13694. t['k'] = 500;
  13695. t['l'] = 278;
  13696. t['m'] = 778;
  13697. t['n'] = 500;
  13698. t['o'] = 500;
  13699. t['p'] = 500;
  13700. t['q'] = 500;
  13701. t['r'] = 333;
  13702. t['s'] = 389;
  13703. t['t'] = 278;
  13704. t['u'] = 500;
  13705. t['v'] = 500;
  13706. t['w'] = 722;
  13707. t['x'] = 500;
  13708. t['y'] = 500;
  13709. t['z'] = 444;
  13710. t['braceleft'] = 480;
  13711. t['bar'] = 200;
  13712. t['braceright'] = 480;
  13713. t['asciitilde'] = 541;
  13714. t['exclamdown'] = 333;
  13715. t['cent'] = 500;
  13716. t['sterling'] = 500;
  13717. t['fraction'] = 167;
  13718. t['yen'] = 500;
  13719. t['florin'] = 500;
  13720. t['section'] = 500;
  13721. t['currency'] = 500;
  13722. t['quotesingle'] = 180;
  13723. t['quotedblleft'] = 444;
  13724. t['guillemotleft'] = 500;
  13725. t['guilsinglleft'] = 333;
  13726. t['guilsinglright'] = 333;
  13727. t['fi'] = 556;
  13728. t['fl'] = 556;
  13729. t['endash'] = 500;
  13730. t['dagger'] = 500;
  13731. t['daggerdbl'] = 500;
  13732. t['periodcentered'] = 250;
  13733. t['paragraph'] = 453;
  13734. t['bullet'] = 350;
  13735. t['quotesinglbase'] = 333;
  13736. t['quotedblbase'] = 444;
  13737. t['quotedblright'] = 444;
  13738. t['guillemotright'] = 500;
  13739. t['ellipsis'] = 1000;
  13740. t['perthousand'] = 1000;
  13741. t['questiondown'] = 444;
  13742. t['grave'] = 333;
  13743. t['acute'] = 333;
  13744. t['circumflex'] = 333;
  13745. t['tilde'] = 333;
  13746. t['macron'] = 333;
  13747. t['breve'] = 333;
  13748. t['dotaccent'] = 333;
  13749. t['dieresis'] = 333;
  13750. t['ring'] = 333;
  13751. t['cedilla'] = 333;
  13752. t['hungarumlaut'] = 333;
  13753. t['ogonek'] = 333;
  13754. t['caron'] = 333;
  13755. t['emdash'] = 1000;
  13756. t['AE'] = 889;
  13757. t['ordfeminine'] = 276;
  13758. t['Lslash'] = 611;
  13759. t['Oslash'] = 722;
  13760. t['OE'] = 889;
  13761. t['ordmasculine'] = 310;
  13762. t['ae'] = 667;
  13763. t['dotlessi'] = 278;
  13764. t['lslash'] = 278;
  13765. t['oslash'] = 500;
  13766. t['oe'] = 722;
  13767. t['germandbls'] = 500;
  13768. t['Idieresis'] = 333;
  13769. t['eacute'] = 444;
  13770. t['abreve'] = 444;
  13771. t['uhungarumlaut'] = 500;
  13772. t['ecaron'] = 444;
  13773. t['Ydieresis'] = 722;
  13774. t['divide'] = 564;
  13775. t['Yacute'] = 722;
  13776. t['Acircumflex'] = 722;
  13777. t['aacute'] = 444;
  13778. t['Ucircumflex'] = 722;
  13779. t['yacute'] = 500;
  13780. t['scommaaccent'] = 389;
  13781. t['ecircumflex'] = 444;
  13782. t['Uring'] = 722;
  13783. t['Udieresis'] = 722;
  13784. t['aogonek'] = 444;
  13785. t['Uacute'] = 722;
  13786. t['uogonek'] = 500;
  13787. t['Edieresis'] = 611;
  13788. t['Dcroat'] = 722;
  13789. t['commaaccent'] = 250;
  13790. t['copyright'] = 760;
  13791. t['Emacron'] = 611;
  13792. t['ccaron'] = 444;
  13793. t['aring'] = 444;
  13794. t['Ncommaaccent'] = 722;
  13795. t['lacute'] = 278;
  13796. t['agrave'] = 444;
  13797. t['Tcommaaccent'] = 611;
  13798. t['Cacute'] = 667;
  13799. t['atilde'] = 444;
  13800. t['Edotaccent'] = 611;
  13801. t['scaron'] = 389;
  13802. t['scedilla'] = 389;
  13803. t['iacute'] = 278;
  13804. t['lozenge'] = 471;
  13805. t['Rcaron'] = 667;
  13806. t['Gcommaaccent'] = 722;
  13807. t['ucircumflex'] = 500;
  13808. t['acircumflex'] = 444;
  13809. t['Amacron'] = 722;
  13810. t['rcaron'] = 333;
  13811. t['ccedilla'] = 444;
  13812. t['Zdotaccent'] = 611;
  13813. t['Thorn'] = 556;
  13814. t['Omacron'] = 722;
  13815. t['Racute'] = 667;
  13816. t['Sacute'] = 556;
  13817. t['dcaron'] = 588;
  13818. t['Umacron'] = 722;
  13819. t['uring'] = 500;
  13820. t['threesuperior'] = 300;
  13821. t['Ograve'] = 722;
  13822. t['Agrave'] = 722;
  13823. t['Abreve'] = 722;
  13824. t['multiply'] = 564;
  13825. t['uacute'] = 500;
  13826. t['Tcaron'] = 611;
  13827. t['partialdiff'] = 476;
  13828. t['ydieresis'] = 500;
  13829. t['Nacute'] = 722;
  13830. t['icircumflex'] = 278;
  13831. t['Ecircumflex'] = 611;
  13832. t['adieresis'] = 444;
  13833. t['edieresis'] = 444;
  13834. t['cacute'] = 444;
  13835. t['nacute'] = 500;
  13836. t['umacron'] = 500;
  13837. t['Ncaron'] = 722;
  13838. t['Iacute'] = 333;
  13839. t['plusminus'] = 564;
  13840. t['brokenbar'] = 200;
  13841. t['registered'] = 760;
  13842. t['Gbreve'] = 722;
  13843. t['Idotaccent'] = 333;
  13844. t['summation'] = 600;
  13845. t['Egrave'] = 611;
  13846. t['racute'] = 333;
  13847. t['omacron'] = 500;
  13848. t['Zacute'] = 611;
  13849. t['Zcaron'] = 611;
  13850. t['greaterequal'] = 549;
  13851. t['Eth'] = 722;
  13852. t['Ccedilla'] = 667;
  13853. t['lcommaaccent'] = 278;
  13854. t['tcaron'] = 326;
  13855. t['eogonek'] = 444;
  13856. t['Uogonek'] = 722;
  13857. t['Aacute'] = 722;
  13858. t['Adieresis'] = 722;
  13859. t['egrave'] = 444;
  13860. t['zacute'] = 444;
  13861. t['iogonek'] = 278;
  13862. t['Oacute'] = 722;
  13863. t['oacute'] = 500;
  13864. t['amacron'] = 444;
  13865. t['sacute'] = 389;
  13866. t['idieresis'] = 278;
  13867. t['Ocircumflex'] = 722;
  13868. t['Ugrave'] = 722;
  13869. t['Delta'] = 612;
  13870. t['thorn'] = 500;
  13871. t['twosuperior'] = 300;
  13872. t['Odieresis'] = 722;
  13873. t['mu'] = 500;
  13874. t['igrave'] = 278;
  13875. t['ohungarumlaut'] = 500;
  13876. t['Eogonek'] = 611;
  13877. t['dcroat'] = 500;
  13878. t['threequarters'] = 750;
  13879. t['Scedilla'] = 556;
  13880. t['lcaron'] = 344;
  13881. t['Kcommaaccent'] = 722;
  13882. t['Lacute'] = 611;
  13883. t['trademark'] = 980;
  13884. t['edotaccent'] = 444;
  13885. t['Igrave'] = 333;
  13886. t['Imacron'] = 333;
  13887. t['Lcaron'] = 611;
  13888. t['onehalf'] = 750;
  13889. t['lessequal'] = 549;
  13890. t['ocircumflex'] = 500;
  13891. t['ntilde'] = 500;
  13892. t['Uhungarumlaut'] = 722;
  13893. t['Eacute'] = 611;
  13894. t['emacron'] = 444;
  13895. t['gbreve'] = 500;
  13896. t['onequarter'] = 750;
  13897. t['Scaron'] = 556;
  13898. t['Scommaaccent'] = 556;
  13899. t['Ohungarumlaut'] = 722;
  13900. t['degree'] = 400;
  13901. t['ograve'] = 500;
  13902. t['Ccaron'] = 667;
  13903. t['ugrave'] = 500;
  13904. t['radical'] = 453;
  13905. t['Dcaron'] = 722;
  13906. t['rcommaaccent'] = 333;
  13907. t['Ntilde'] = 722;
  13908. t['otilde'] = 500;
  13909. t['Rcommaaccent'] = 667;
  13910. t['Lcommaaccent'] = 611;
  13911. t['Atilde'] = 722;
  13912. t['Aogonek'] = 722;
  13913. t['Aring'] = 722;
  13914. t['Otilde'] = 722;
  13915. t['zdotaccent'] = 444;
  13916. t['Ecaron'] = 611;
  13917. t['Iogonek'] = 333;
  13918. t['kcommaaccent'] = 500;
  13919. t['minus'] = 564;
  13920. t['Icircumflex'] = 333;
  13921. t['ncaron'] = 500;
  13922. t['tcommaaccent'] = 278;
  13923. t['logicalnot'] = 564;
  13924. t['odieresis'] = 500;
  13925. t['udieresis'] = 500;
  13926. t['notequal'] = 549;
  13927. t['gcommaaccent'] = 500;
  13928. t['eth'] = 500;
  13929. t['zcaron'] = 444;
  13930. t['ncommaaccent'] = 500;
  13931. t['onesuperior'] = 300;
  13932. t['imacron'] = 278;
  13933. t['Euro'] = 500;
  13934. });
  13935. t['Times-Bold'] = getLookupTableFactory(function (t) {
  13936. t['space'] = 250;
  13937. t['exclam'] = 333;
  13938. t['quotedbl'] = 555;
  13939. t['numbersign'] = 500;
  13940. t['dollar'] = 500;
  13941. t['percent'] = 1000;
  13942. t['ampersand'] = 833;
  13943. t['quoteright'] = 333;
  13944. t['parenleft'] = 333;
  13945. t['parenright'] = 333;
  13946. t['asterisk'] = 500;
  13947. t['plus'] = 570;
  13948. t['comma'] = 250;
  13949. t['hyphen'] = 333;
  13950. t['period'] = 250;
  13951. t['slash'] = 278;
  13952. t['zero'] = 500;
  13953. t['one'] = 500;
  13954. t['two'] = 500;
  13955. t['three'] = 500;
  13956. t['four'] = 500;
  13957. t['five'] = 500;
  13958. t['six'] = 500;
  13959. t['seven'] = 500;
  13960. t['eight'] = 500;
  13961. t['nine'] = 500;
  13962. t['colon'] = 333;
  13963. t['semicolon'] = 333;
  13964. t['less'] = 570;
  13965. t['equal'] = 570;
  13966. t['greater'] = 570;
  13967. t['question'] = 500;
  13968. t['at'] = 930;
  13969. t['A'] = 722;
  13970. t['B'] = 667;
  13971. t['C'] = 722;
  13972. t['D'] = 722;
  13973. t['E'] = 667;
  13974. t['F'] = 611;
  13975. t['G'] = 778;
  13976. t['H'] = 778;
  13977. t['I'] = 389;
  13978. t['J'] = 500;
  13979. t['K'] = 778;
  13980. t['L'] = 667;
  13981. t['M'] = 944;
  13982. t['N'] = 722;
  13983. t['O'] = 778;
  13984. t['P'] = 611;
  13985. t['Q'] = 778;
  13986. t['R'] = 722;
  13987. t['S'] = 556;
  13988. t['T'] = 667;
  13989. t['U'] = 722;
  13990. t['V'] = 722;
  13991. t['W'] = 1000;
  13992. t['X'] = 722;
  13993. t['Y'] = 722;
  13994. t['Z'] = 667;
  13995. t['bracketleft'] = 333;
  13996. t['backslash'] = 278;
  13997. t['bracketright'] = 333;
  13998. t['asciicircum'] = 581;
  13999. t['underscore'] = 500;
  14000. t['quoteleft'] = 333;
  14001. t['a'] = 500;
  14002. t['b'] = 556;
  14003. t['c'] = 444;
  14004. t['d'] = 556;
  14005. t['e'] = 444;
  14006. t['f'] = 333;
  14007. t['g'] = 500;
  14008. t['h'] = 556;
  14009. t['i'] = 278;
  14010. t['j'] = 333;
  14011. t['k'] = 556;
  14012. t['l'] = 278;
  14013. t['m'] = 833;
  14014. t['n'] = 556;
  14015. t['o'] = 500;
  14016. t['p'] = 556;
  14017. t['q'] = 556;
  14018. t['r'] = 444;
  14019. t['s'] = 389;
  14020. t['t'] = 333;
  14021. t['u'] = 556;
  14022. t['v'] = 500;
  14023. t['w'] = 722;
  14024. t['x'] = 500;
  14025. t['y'] = 500;
  14026. t['z'] = 444;
  14027. t['braceleft'] = 394;
  14028. t['bar'] = 220;
  14029. t['braceright'] = 394;
  14030. t['asciitilde'] = 520;
  14031. t['exclamdown'] = 333;
  14032. t['cent'] = 500;
  14033. t['sterling'] = 500;
  14034. t['fraction'] = 167;
  14035. t['yen'] = 500;
  14036. t['florin'] = 500;
  14037. t['section'] = 500;
  14038. t['currency'] = 500;
  14039. t['quotesingle'] = 278;
  14040. t['quotedblleft'] = 500;
  14041. t['guillemotleft'] = 500;
  14042. t['guilsinglleft'] = 333;
  14043. t['guilsinglright'] = 333;
  14044. t['fi'] = 556;
  14045. t['fl'] = 556;
  14046. t['endash'] = 500;
  14047. t['dagger'] = 500;
  14048. t['daggerdbl'] = 500;
  14049. t['periodcentered'] = 250;
  14050. t['paragraph'] = 540;
  14051. t['bullet'] = 350;
  14052. t['quotesinglbase'] = 333;
  14053. t['quotedblbase'] = 500;
  14054. t['quotedblright'] = 500;
  14055. t['guillemotright'] = 500;
  14056. t['ellipsis'] = 1000;
  14057. t['perthousand'] = 1000;
  14058. t['questiondown'] = 500;
  14059. t['grave'] = 333;
  14060. t['acute'] = 333;
  14061. t['circumflex'] = 333;
  14062. t['tilde'] = 333;
  14063. t['macron'] = 333;
  14064. t['breve'] = 333;
  14065. t['dotaccent'] = 333;
  14066. t['dieresis'] = 333;
  14067. t['ring'] = 333;
  14068. t['cedilla'] = 333;
  14069. t['hungarumlaut'] = 333;
  14070. t['ogonek'] = 333;
  14071. t['caron'] = 333;
  14072. t['emdash'] = 1000;
  14073. t['AE'] = 1000;
  14074. t['ordfeminine'] = 300;
  14075. t['Lslash'] = 667;
  14076. t['Oslash'] = 778;
  14077. t['OE'] = 1000;
  14078. t['ordmasculine'] = 330;
  14079. t['ae'] = 722;
  14080. t['dotlessi'] = 278;
  14081. t['lslash'] = 278;
  14082. t['oslash'] = 500;
  14083. t['oe'] = 722;
  14084. t['germandbls'] = 556;
  14085. t['Idieresis'] = 389;
  14086. t['eacute'] = 444;
  14087. t['abreve'] = 500;
  14088. t['uhungarumlaut'] = 556;
  14089. t['ecaron'] = 444;
  14090. t['Ydieresis'] = 722;
  14091. t['divide'] = 570;
  14092. t['Yacute'] = 722;
  14093. t['Acircumflex'] = 722;
  14094. t['aacute'] = 500;
  14095. t['Ucircumflex'] = 722;
  14096. t['yacute'] = 500;
  14097. t['scommaaccent'] = 389;
  14098. t['ecircumflex'] = 444;
  14099. t['Uring'] = 722;
  14100. t['Udieresis'] = 722;
  14101. t['aogonek'] = 500;
  14102. t['Uacute'] = 722;
  14103. t['uogonek'] = 556;
  14104. t['Edieresis'] = 667;
  14105. t['Dcroat'] = 722;
  14106. t['commaaccent'] = 250;
  14107. t['copyright'] = 747;
  14108. t['Emacron'] = 667;
  14109. t['ccaron'] = 444;
  14110. t['aring'] = 500;
  14111. t['Ncommaaccent'] = 722;
  14112. t['lacute'] = 278;
  14113. t['agrave'] = 500;
  14114. t['Tcommaaccent'] = 667;
  14115. t['Cacute'] = 722;
  14116. t['atilde'] = 500;
  14117. t['Edotaccent'] = 667;
  14118. t['scaron'] = 389;
  14119. t['scedilla'] = 389;
  14120. t['iacute'] = 278;
  14121. t['lozenge'] = 494;
  14122. t['Rcaron'] = 722;
  14123. t['Gcommaaccent'] = 778;
  14124. t['ucircumflex'] = 556;
  14125. t['acircumflex'] = 500;
  14126. t['Amacron'] = 722;
  14127. t['rcaron'] = 444;
  14128. t['ccedilla'] = 444;
  14129. t['Zdotaccent'] = 667;
  14130. t['Thorn'] = 611;
  14131. t['Omacron'] = 778;
  14132. t['Racute'] = 722;
  14133. t['Sacute'] = 556;
  14134. t['dcaron'] = 672;
  14135. t['Umacron'] = 722;
  14136. t['uring'] = 556;
  14137. t['threesuperior'] = 300;
  14138. t['Ograve'] = 778;
  14139. t['Agrave'] = 722;
  14140. t['Abreve'] = 722;
  14141. t['multiply'] = 570;
  14142. t['uacute'] = 556;
  14143. t['Tcaron'] = 667;
  14144. t['partialdiff'] = 494;
  14145. t['ydieresis'] = 500;
  14146. t['Nacute'] = 722;
  14147. t['icircumflex'] = 278;
  14148. t['Ecircumflex'] = 667;
  14149. t['adieresis'] = 500;
  14150. t['edieresis'] = 444;
  14151. t['cacute'] = 444;
  14152. t['nacute'] = 556;
  14153. t['umacron'] = 556;
  14154. t['Ncaron'] = 722;
  14155. t['Iacute'] = 389;
  14156. t['plusminus'] = 570;
  14157. t['brokenbar'] = 220;
  14158. t['registered'] = 747;
  14159. t['Gbreve'] = 778;
  14160. t['Idotaccent'] = 389;
  14161. t['summation'] = 600;
  14162. t['Egrave'] = 667;
  14163. t['racute'] = 444;
  14164. t['omacron'] = 500;
  14165. t['Zacute'] = 667;
  14166. t['Zcaron'] = 667;
  14167. t['greaterequal'] = 549;
  14168. t['Eth'] = 722;
  14169. t['Ccedilla'] = 722;
  14170. t['lcommaaccent'] = 278;
  14171. t['tcaron'] = 416;
  14172. t['eogonek'] = 444;
  14173. t['Uogonek'] = 722;
  14174. t['Aacute'] = 722;
  14175. t['Adieresis'] = 722;
  14176. t['egrave'] = 444;
  14177. t['zacute'] = 444;
  14178. t['iogonek'] = 278;
  14179. t['Oacute'] = 778;
  14180. t['oacute'] = 500;
  14181. t['amacron'] = 500;
  14182. t['sacute'] = 389;
  14183. t['idieresis'] = 278;
  14184. t['Ocircumflex'] = 778;
  14185. t['Ugrave'] = 722;
  14186. t['Delta'] = 612;
  14187. t['thorn'] = 556;
  14188. t['twosuperior'] = 300;
  14189. t['Odieresis'] = 778;
  14190. t['mu'] = 556;
  14191. t['igrave'] = 278;
  14192. t['ohungarumlaut'] = 500;
  14193. t['Eogonek'] = 667;
  14194. t['dcroat'] = 556;
  14195. t['threequarters'] = 750;
  14196. t['Scedilla'] = 556;
  14197. t['lcaron'] = 394;
  14198. t['Kcommaaccent'] = 778;
  14199. t['Lacute'] = 667;
  14200. t['trademark'] = 1000;
  14201. t['edotaccent'] = 444;
  14202. t['Igrave'] = 389;
  14203. t['Imacron'] = 389;
  14204. t['Lcaron'] = 667;
  14205. t['onehalf'] = 750;
  14206. t['lessequal'] = 549;
  14207. t['ocircumflex'] = 500;
  14208. t['ntilde'] = 556;
  14209. t['Uhungarumlaut'] = 722;
  14210. t['Eacute'] = 667;
  14211. t['emacron'] = 444;
  14212. t['gbreve'] = 500;
  14213. t['onequarter'] = 750;
  14214. t['Scaron'] = 556;
  14215. t['Scommaaccent'] = 556;
  14216. t['Ohungarumlaut'] = 778;
  14217. t['degree'] = 400;
  14218. t['ograve'] = 500;
  14219. t['Ccaron'] = 722;
  14220. t['ugrave'] = 556;
  14221. t['radical'] = 549;
  14222. t['Dcaron'] = 722;
  14223. t['rcommaaccent'] = 444;
  14224. t['Ntilde'] = 722;
  14225. t['otilde'] = 500;
  14226. t['Rcommaaccent'] = 722;
  14227. t['Lcommaaccent'] = 667;
  14228. t['Atilde'] = 722;
  14229. t['Aogonek'] = 722;
  14230. t['Aring'] = 722;
  14231. t['Otilde'] = 778;
  14232. t['zdotaccent'] = 444;
  14233. t['Ecaron'] = 667;
  14234. t['Iogonek'] = 389;
  14235. t['kcommaaccent'] = 556;
  14236. t['minus'] = 570;
  14237. t['Icircumflex'] = 389;
  14238. t['ncaron'] = 556;
  14239. t['tcommaaccent'] = 333;
  14240. t['logicalnot'] = 570;
  14241. t['odieresis'] = 500;
  14242. t['udieresis'] = 556;
  14243. t['notequal'] = 549;
  14244. t['gcommaaccent'] = 500;
  14245. t['eth'] = 500;
  14246. t['zcaron'] = 444;
  14247. t['ncommaaccent'] = 556;
  14248. t['onesuperior'] = 300;
  14249. t['imacron'] = 278;
  14250. t['Euro'] = 500;
  14251. });
  14252. t['Times-BoldItalic'] = getLookupTableFactory(function (t) {
  14253. t['space'] = 250;
  14254. t['exclam'] = 389;
  14255. t['quotedbl'] = 555;
  14256. t['numbersign'] = 500;
  14257. t['dollar'] = 500;
  14258. t['percent'] = 833;
  14259. t['ampersand'] = 778;
  14260. t['quoteright'] = 333;
  14261. t['parenleft'] = 333;
  14262. t['parenright'] = 333;
  14263. t['asterisk'] = 500;
  14264. t['plus'] = 570;
  14265. t['comma'] = 250;
  14266. t['hyphen'] = 333;
  14267. t['period'] = 250;
  14268. t['slash'] = 278;
  14269. t['zero'] = 500;
  14270. t['one'] = 500;
  14271. t['two'] = 500;
  14272. t['three'] = 500;
  14273. t['four'] = 500;
  14274. t['five'] = 500;
  14275. t['six'] = 500;
  14276. t['seven'] = 500;
  14277. t['eight'] = 500;
  14278. t['nine'] = 500;
  14279. t['colon'] = 333;
  14280. t['semicolon'] = 333;
  14281. t['less'] = 570;
  14282. t['equal'] = 570;
  14283. t['greater'] = 570;
  14284. t['question'] = 500;
  14285. t['at'] = 832;
  14286. t['A'] = 667;
  14287. t['B'] = 667;
  14288. t['C'] = 667;
  14289. t['D'] = 722;
  14290. t['E'] = 667;
  14291. t['F'] = 667;
  14292. t['G'] = 722;
  14293. t['H'] = 778;
  14294. t['I'] = 389;
  14295. t['J'] = 500;
  14296. t['K'] = 667;
  14297. t['L'] = 611;
  14298. t['M'] = 889;
  14299. t['N'] = 722;
  14300. t['O'] = 722;
  14301. t['P'] = 611;
  14302. t['Q'] = 722;
  14303. t['R'] = 667;
  14304. t['S'] = 556;
  14305. t['T'] = 611;
  14306. t['U'] = 722;
  14307. t['V'] = 667;
  14308. t['W'] = 889;
  14309. t['X'] = 667;
  14310. t['Y'] = 611;
  14311. t['Z'] = 611;
  14312. t['bracketleft'] = 333;
  14313. t['backslash'] = 278;
  14314. t['bracketright'] = 333;
  14315. t['asciicircum'] = 570;
  14316. t['underscore'] = 500;
  14317. t['quoteleft'] = 333;
  14318. t['a'] = 500;
  14319. t['b'] = 500;
  14320. t['c'] = 444;
  14321. t['d'] = 500;
  14322. t['e'] = 444;
  14323. t['f'] = 333;
  14324. t['g'] = 500;
  14325. t['h'] = 556;
  14326. t['i'] = 278;
  14327. t['j'] = 278;
  14328. t['k'] = 500;
  14329. t['l'] = 278;
  14330. t['m'] = 778;
  14331. t['n'] = 556;
  14332. t['o'] = 500;
  14333. t['p'] = 500;
  14334. t['q'] = 500;
  14335. t['r'] = 389;
  14336. t['s'] = 389;
  14337. t['t'] = 278;
  14338. t['u'] = 556;
  14339. t['v'] = 444;
  14340. t['w'] = 667;
  14341. t['x'] = 500;
  14342. t['y'] = 444;
  14343. t['z'] = 389;
  14344. t['braceleft'] = 348;
  14345. t['bar'] = 220;
  14346. t['braceright'] = 348;
  14347. t['asciitilde'] = 570;
  14348. t['exclamdown'] = 389;
  14349. t['cent'] = 500;
  14350. t['sterling'] = 500;
  14351. t['fraction'] = 167;
  14352. t['yen'] = 500;
  14353. t['florin'] = 500;
  14354. t['section'] = 500;
  14355. t['currency'] = 500;
  14356. t['quotesingle'] = 278;
  14357. t['quotedblleft'] = 500;
  14358. t['guillemotleft'] = 500;
  14359. t['guilsinglleft'] = 333;
  14360. t['guilsinglright'] = 333;
  14361. t['fi'] = 556;
  14362. t['fl'] = 556;
  14363. t['endash'] = 500;
  14364. t['dagger'] = 500;
  14365. t['daggerdbl'] = 500;
  14366. t['periodcentered'] = 250;
  14367. t['paragraph'] = 500;
  14368. t['bullet'] = 350;
  14369. t['quotesinglbase'] = 333;
  14370. t['quotedblbase'] = 500;
  14371. t['quotedblright'] = 500;
  14372. t['guillemotright'] = 500;
  14373. t['ellipsis'] = 1000;
  14374. t['perthousand'] = 1000;
  14375. t['questiondown'] = 500;
  14376. t['grave'] = 333;
  14377. t['acute'] = 333;
  14378. t['circumflex'] = 333;
  14379. t['tilde'] = 333;
  14380. t['macron'] = 333;
  14381. t['breve'] = 333;
  14382. t['dotaccent'] = 333;
  14383. t['dieresis'] = 333;
  14384. t['ring'] = 333;
  14385. t['cedilla'] = 333;
  14386. t['hungarumlaut'] = 333;
  14387. t['ogonek'] = 333;
  14388. t['caron'] = 333;
  14389. t['emdash'] = 1000;
  14390. t['AE'] = 944;
  14391. t['ordfeminine'] = 266;
  14392. t['Lslash'] = 611;
  14393. t['Oslash'] = 722;
  14394. t['OE'] = 944;
  14395. t['ordmasculine'] = 300;
  14396. t['ae'] = 722;
  14397. t['dotlessi'] = 278;
  14398. t['lslash'] = 278;
  14399. t['oslash'] = 500;
  14400. t['oe'] = 722;
  14401. t['germandbls'] = 500;
  14402. t['Idieresis'] = 389;
  14403. t['eacute'] = 444;
  14404. t['abreve'] = 500;
  14405. t['uhungarumlaut'] = 556;
  14406. t['ecaron'] = 444;
  14407. t['Ydieresis'] = 611;
  14408. t['divide'] = 570;
  14409. t['Yacute'] = 611;
  14410. t['Acircumflex'] = 667;
  14411. t['aacute'] = 500;
  14412. t['Ucircumflex'] = 722;
  14413. t['yacute'] = 444;
  14414. t['scommaaccent'] = 389;
  14415. t['ecircumflex'] = 444;
  14416. t['Uring'] = 722;
  14417. t['Udieresis'] = 722;
  14418. t['aogonek'] = 500;
  14419. t['Uacute'] = 722;
  14420. t['uogonek'] = 556;
  14421. t['Edieresis'] = 667;
  14422. t['Dcroat'] = 722;
  14423. t['commaaccent'] = 250;
  14424. t['copyright'] = 747;
  14425. t['Emacron'] = 667;
  14426. t['ccaron'] = 444;
  14427. t['aring'] = 500;
  14428. t['Ncommaaccent'] = 722;
  14429. t['lacute'] = 278;
  14430. t['agrave'] = 500;
  14431. t['Tcommaaccent'] = 611;
  14432. t['Cacute'] = 667;
  14433. t['atilde'] = 500;
  14434. t['Edotaccent'] = 667;
  14435. t['scaron'] = 389;
  14436. t['scedilla'] = 389;
  14437. t['iacute'] = 278;
  14438. t['lozenge'] = 494;
  14439. t['Rcaron'] = 667;
  14440. t['Gcommaaccent'] = 722;
  14441. t['ucircumflex'] = 556;
  14442. t['acircumflex'] = 500;
  14443. t['Amacron'] = 667;
  14444. t['rcaron'] = 389;
  14445. t['ccedilla'] = 444;
  14446. t['Zdotaccent'] = 611;
  14447. t['Thorn'] = 611;
  14448. t['Omacron'] = 722;
  14449. t['Racute'] = 667;
  14450. t['Sacute'] = 556;
  14451. t['dcaron'] = 608;
  14452. t['Umacron'] = 722;
  14453. t['uring'] = 556;
  14454. t['threesuperior'] = 300;
  14455. t['Ograve'] = 722;
  14456. t['Agrave'] = 667;
  14457. t['Abreve'] = 667;
  14458. t['multiply'] = 570;
  14459. t['uacute'] = 556;
  14460. t['Tcaron'] = 611;
  14461. t['partialdiff'] = 494;
  14462. t['ydieresis'] = 444;
  14463. t['Nacute'] = 722;
  14464. t['icircumflex'] = 278;
  14465. t['Ecircumflex'] = 667;
  14466. t['adieresis'] = 500;
  14467. t['edieresis'] = 444;
  14468. t['cacute'] = 444;
  14469. t['nacute'] = 556;
  14470. t['umacron'] = 556;
  14471. t['Ncaron'] = 722;
  14472. t['Iacute'] = 389;
  14473. t['plusminus'] = 570;
  14474. t['brokenbar'] = 220;
  14475. t['registered'] = 747;
  14476. t['Gbreve'] = 722;
  14477. t['Idotaccent'] = 389;
  14478. t['summation'] = 600;
  14479. t['Egrave'] = 667;
  14480. t['racute'] = 389;
  14481. t['omacron'] = 500;
  14482. t['Zacute'] = 611;
  14483. t['Zcaron'] = 611;
  14484. t['greaterequal'] = 549;
  14485. t['Eth'] = 722;
  14486. t['Ccedilla'] = 667;
  14487. t['lcommaaccent'] = 278;
  14488. t['tcaron'] = 366;
  14489. t['eogonek'] = 444;
  14490. t['Uogonek'] = 722;
  14491. t['Aacute'] = 667;
  14492. t['Adieresis'] = 667;
  14493. t['egrave'] = 444;
  14494. t['zacute'] = 389;
  14495. t['iogonek'] = 278;
  14496. t['Oacute'] = 722;
  14497. t['oacute'] = 500;
  14498. t['amacron'] = 500;
  14499. t['sacute'] = 389;
  14500. t['idieresis'] = 278;
  14501. t['Ocircumflex'] = 722;
  14502. t['Ugrave'] = 722;
  14503. t['Delta'] = 612;
  14504. t['thorn'] = 500;
  14505. t['twosuperior'] = 300;
  14506. t['Odieresis'] = 722;
  14507. t['mu'] = 576;
  14508. t['igrave'] = 278;
  14509. t['ohungarumlaut'] = 500;
  14510. t['Eogonek'] = 667;
  14511. t['dcroat'] = 500;
  14512. t['threequarters'] = 750;
  14513. t['Scedilla'] = 556;
  14514. t['lcaron'] = 382;
  14515. t['Kcommaaccent'] = 667;
  14516. t['Lacute'] = 611;
  14517. t['trademark'] = 1000;
  14518. t['edotaccent'] = 444;
  14519. t['Igrave'] = 389;
  14520. t['Imacron'] = 389;
  14521. t['Lcaron'] = 611;
  14522. t['onehalf'] = 750;
  14523. t['lessequal'] = 549;
  14524. t['ocircumflex'] = 500;
  14525. t['ntilde'] = 556;
  14526. t['Uhungarumlaut'] = 722;
  14527. t['Eacute'] = 667;
  14528. t['emacron'] = 444;
  14529. t['gbreve'] = 500;
  14530. t['onequarter'] = 750;
  14531. t['Scaron'] = 556;
  14532. t['Scommaaccent'] = 556;
  14533. t['Ohungarumlaut'] = 722;
  14534. t['degree'] = 400;
  14535. t['ograve'] = 500;
  14536. t['Ccaron'] = 667;
  14537. t['ugrave'] = 556;
  14538. t['radical'] = 549;
  14539. t['Dcaron'] = 722;
  14540. t['rcommaaccent'] = 389;
  14541. t['Ntilde'] = 722;
  14542. t['otilde'] = 500;
  14543. t['Rcommaaccent'] = 667;
  14544. t['Lcommaaccent'] = 611;
  14545. t['Atilde'] = 667;
  14546. t['Aogonek'] = 667;
  14547. t['Aring'] = 667;
  14548. t['Otilde'] = 722;
  14549. t['zdotaccent'] = 389;
  14550. t['Ecaron'] = 667;
  14551. t['Iogonek'] = 389;
  14552. t['kcommaaccent'] = 500;
  14553. t['minus'] = 606;
  14554. t['Icircumflex'] = 389;
  14555. t['ncaron'] = 556;
  14556. t['tcommaaccent'] = 278;
  14557. t['logicalnot'] = 606;
  14558. t['odieresis'] = 500;
  14559. t['udieresis'] = 556;
  14560. t['notequal'] = 549;
  14561. t['gcommaaccent'] = 500;
  14562. t['eth'] = 500;
  14563. t['zcaron'] = 389;
  14564. t['ncommaaccent'] = 556;
  14565. t['onesuperior'] = 300;
  14566. t['imacron'] = 278;
  14567. t['Euro'] = 500;
  14568. });
  14569. t['Times-Italic'] = getLookupTableFactory(function (t) {
  14570. t['space'] = 250;
  14571. t['exclam'] = 333;
  14572. t['quotedbl'] = 420;
  14573. t['numbersign'] = 500;
  14574. t['dollar'] = 500;
  14575. t['percent'] = 833;
  14576. t['ampersand'] = 778;
  14577. t['quoteright'] = 333;
  14578. t['parenleft'] = 333;
  14579. t['parenright'] = 333;
  14580. t['asterisk'] = 500;
  14581. t['plus'] = 675;
  14582. t['comma'] = 250;
  14583. t['hyphen'] = 333;
  14584. t['period'] = 250;
  14585. t['slash'] = 278;
  14586. t['zero'] = 500;
  14587. t['one'] = 500;
  14588. t['two'] = 500;
  14589. t['three'] = 500;
  14590. t['four'] = 500;
  14591. t['five'] = 500;
  14592. t['six'] = 500;
  14593. t['seven'] = 500;
  14594. t['eight'] = 500;
  14595. t['nine'] = 500;
  14596. t['colon'] = 333;
  14597. t['semicolon'] = 333;
  14598. t['less'] = 675;
  14599. t['equal'] = 675;
  14600. t['greater'] = 675;
  14601. t['question'] = 500;
  14602. t['at'] = 920;
  14603. t['A'] = 611;
  14604. t['B'] = 611;
  14605. t['C'] = 667;
  14606. t['D'] = 722;
  14607. t['E'] = 611;
  14608. t['F'] = 611;
  14609. t['G'] = 722;
  14610. t['H'] = 722;
  14611. t['I'] = 333;
  14612. t['J'] = 444;
  14613. t['K'] = 667;
  14614. t['L'] = 556;
  14615. t['M'] = 833;
  14616. t['N'] = 667;
  14617. t['O'] = 722;
  14618. t['P'] = 611;
  14619. t['Q'] = 722;
  14620. t['R'] = 611;
  14621. t['S'] = 500;
  14622. t['T'] = 556;
  14623. t['U'] = 722;
  14624. t['V'] = 611;
  14625. t['W'] = 833;
  14626. t['X'] = 611;
  14627. t['Y'] = 556;
  14628. t['Z'] = 556;
  14629. t['bracketleft'] = 389;
  14630. t['backslash'] = 278;
  14631. t['bracketright'] = 389;
  14632. t['asciicircum'] = 422;
  14633. t['underscore'] = 500;
  14634. t['quoteleft'] = 333;
  14635. t['a'] = 500;
  14636. t['b'] = 500;
  14637. t['c'] = 444;
  14638. t['d'] = 500;
  14639. t['e'] = 444;
  14640. t['f'] = 278;
  14641. t['g'] = 500;
  14642. t['h'] = 500;
  14643. t['i'] = 278;
  14644. t['j'] = 278;
  14645. t['k'] = 444;
  14646. t['l'] = 278;
  14647. t['m'] = 722;
  14648. t['n'] = 500;
  14649. t['o'] = 500;
  14650. t['p'] = 500;
  14651. t['q'] = 500;
  14652. t['r'] = 389;
  14653. t['s'] = 389;
  14654. t['t'] = 278;
  14655. t['u'] = 500;
  14656. t['v'] = 444;
  14657. t['w'] = 667;
  14658. t['x'] = 444;
  14659. t['y'] = 444;
  14660. t['z'] = 389;
  14661. t['braceleft'] = 400;
  14662. t['bar'] = 275;
  14663. t['braceright'] = 400;
  14664. t['asciitilde'] = 541;
  14665. t['exclamdown'] = 389;
  14666. t['cent'] = 500;
  14667. t['sterling'] = 500;
  14668. t['fraction'] = 167;
  14669. t['yen'] = 500;
  14670. t['florin'] = 500;
  14671. t['section'] = 500;
  14672. t['currency'] = 500;
  14673. t['quotesingle'] = 214;
  14674. t['quotedblleft'] = 556;
  14675. t['guillemotleft'] = 500;
  14676. t['guilsinglleft'] = 333;
  14677. t['guilsinglright'] = 333;
  14678. t['fi'] = 500;
  14679. t['fl'] = 500;
  14680. t['endash'] = 500;
  14681. t['dagger'] = 500;
  14682. t['daggerdbl'] = 500;
  14683. t['periodcentered'] = 250;
  14684. t['paragraph'] = 523;
  14685. t['bullet'] = 350;
  14686. t['quotesinglbase'] = 333;
  14687. t['quotedblbase'] = 556;
  14688. t['quotedblright'] = 556;
  14689. t['guillemotright'] = 500;
  14690. t['ellipsis'] = 889;
  14691. t['perthousand'] = 1000;
  14692. t['questiondown'] = 500;
  14693. t['grave'] = 333;
  14694. t['acute'] = 333;
  14695. t['circumflex'] = 333;
  14696. t['tilde'] = 333;
  14697. t['macron'] = 333;
  14698. t['breve'] = 333;
  14699. t['dotaccent'] = 333;
  14700. t['dieresis'] = 333;
  14701. t['ring'] = 333;
  14702. t['cedilla'] = 333;
  14703. t['hungarumlaut'] = 333;
  14704. t['ogonek'] = 333;
  14705. t['caron'] = 333;
  14706. t['emdash'] = 889;
  14707. t['AE'] = 889;
  14708. t['ordfeminine'] = 276;
  14709. t['Lslash'] = 556;
  14710. t['Oslash'] = 722;
  14711. t['OE'] = 944;
  14712. t['ordmasculine'] = 310;
  14713. t['ae'] = 667;
  14714. t['dotlessi'] = 278;
  14715. t['lslash'] = 278;
  14716. t['oslash'] = 500;
  14717. t['oe'] = 667;
  14718. t['germandbls'] = 500;
  14719. t['Idieresis'] = 333;
  14720. t['eacute'] = 444;
  14721. t['abreve'] = 500;
  14722. t['uhungarumlaut'] = 500;
  14723. t['ecaron'] = 444;
  14724. t['Ydieresis'] = 556;
  14725. t['divide'] = 675;
  14726. t['Yacute'] = 556;
  14727. t['Acircumflex'] = 611;
  14728. t['aacute'] = 500;
  14729. t['Ucircumflex'] = 722;
  14730. t['yacute'] = 444;
  14731. t['scommaaccent'] = 389;
  14732. t['ecircumflex'] = 444;
  14733. t['Uring'] = 722;
  14734. t['Udieresis'] = 722;
  14735. t['aogonek'] = 500;
  14736. t['Uacute'] = 722;
  14737. t['uogonek'] = 500;
  14738. t['Edieresis'] = 611;
  14739. t['Dcroat'] = 722;
  14740. t['commaaccent'] = 250;
  14741. t['copyright'] = 760;
  14742. t['Emacron'] = 611;
  14743. t['ccaron'] = 444;
  14744. t['aring'] = 500;
  14745. t['Ncommaaccent'] = 667;
  14746. t['lacute'] = 278;
  14747. t['agrave'] = 500;
  14748. t['Tcommaaccent'] = 556;
  14749. t['Cacute'] = 667;
  14750. t['atilde'] = 500;
  14751. t['Edotaccent'] = 611;
  14752. t['scaron'] = 389;
  14753. t['scedilla'] = 389;
  14754. t['iacute'] = 278;
  14755. t['lozenge'] = 471;
  14756. t['Rcaron'] = 611;
  14757. t['Gcommaaccent'] = 722;
  14758. t['ucircumflex'] = 500;
  14759. t['acircumflex'] = 500;
  14760. t['Amacron'] = 611;
  14761. t['rcaron'] = 389;
  14762. t['ccedilla'] = 444;
  14763. t['Zdotaccent'] = 556;
  14764. t['Thorn'] = 611;
  14765. t['Omacron'] = 722;
  14766. t['Racute'] = 611;
  14767. t['Sacute'] = 500;
  14768. t['dcaron'] = 544;
  14769. t['Umacron'] = 722;
  14770. t['uring'] = 500;
  14771. t['threesuperior'] = 300;
  14772. t['Ograve'] = 722;
  14773. t['Agrave'] = 611;
  14774. t['Abreve'] = 611;
  14775. t['multiply'] = 675;
  14776. t['uacute'] = 500;
  14777. t['Tcaron'] = 556;
  14778. t['partialdiff'] = 476;
  14779. t['ydieresis'] = 444;
  14780. t['Nacute'] = 667;
  14781. t['icircumflex'] = 278;
  14782. t['Ecircumflex'] = 611;
  14783. t['adieresis'] = 500;
  14784. t['edieresis'] = 444;
  14785. t['cacute'] = 444;
  14786. t['nacute'] = 500;
  14787. t['umacron'] = 500;
  14788. t['Ncaron'] = 667;
  14789. t['Iacute'] = 333;
  14790. t['plusminus'] = 675;
  14791. t['brokenbar'] = 275;
  14792. t['registered'] = 760;
  14793. t['Gbreve'] = 722;
  14794. t['Idotaccent'] = 333;
  14795. t['summation'] = 600;
  14796. t['Egrave'] = 611;
  14797. t['racute'] = 389;
  14798. t['omacron'] = 500;
  14799. t['Zacute'] = 556;
  14800. t['Zcaron'] = 556;
  14801. t['greaterequal'] = 549;
  14802. t['Eth'] = 722;
  14803. t['Ccedilla'] = 667;
  14804. t['lcommaaccent'] = 278;
  14805. t['tcaron'] = 300;
  14806. t['eogonek'] = 444;
  14807. t['Uogonek'] = 722;
  14808. t['Aacute'] = 611;
  14809. t['Adieresis'] = 611;
  14810. t['egrave'] = 444;
  14811. t['zacute'] = 389;
  14812. t['iogonek'] = 278;
  14813. t['Oacute'] = 722;
  14814. t['oacute'] = 500;
  14815. t['amacron'] = 500;
  14816. t['sacute'] = 389;
  14817. t['idieresis'] = 278;
  14818. t['Ocircumflex'] = 722;
  14819. t['Ugrave'] = 722;
  14820. t['Delta'] = 612;
  14821. t['thorn'] = 500;
  14822. t['twosuperior'] = 300;
  14823. t['Odieresis'] = 722;
  14824. t['mu'] = 500;
  14825. t['igrave'] = 278;
  14826. t['ohungarumlaut'] = 500;
  14827. t['Eogonek'] = 611;
  14828. t['dcroat'] = 500;
  14829. t['threequarters'] = 750;
  14830. t['Scedilla'] = 500;
  14831. t['lcaron'] = 300;
  14832. t['Kcommaaccent'] = 667;
  14833. t['Lacute'] = 556;
  14834. t['trademark'] = 980;
  14835. t['edotaccent'] = 444;
  14836. t['Igrave'] = 333;
  14837. t['Imacron'] = 333;
  14838. t['Lcaron'] = 611;
  14839. t['onehalf'] = 750;
  14840. t['lessequal'] = 549;
  14841. t['ocircumflex'] = 500;
  14842. t['ntilde'] = 500;
  14843. t['Uhungarumlaut'] = 722;
  14844. t['Eacute'] = 611;
  14845. t['emacron'] = 444;
  14846. t['gbreve'] = 500;
  14847. t['onequarter'] = 750;
  14848. t['Scaron'] = 500;
  14849. t['Scommaaccent'] = 500;
  14850. t['Ohungarumlaut'] = 722;
  14851. t['degree'] = 400;
  14852. t['ograve'] = 500;
  14853. t['Ccaron'] = 667;
  14854. t['ugrave'] = 500;
  14855. t['radical'] = 453;
  14856. t['Dcaron'] = 722;
  14857. t['rcommaaccent'] = 389;
  14858. t['Ntilde'] = 667;
  14859. t['otilde'] = 500;
  14860. t['Rcommaaccent'] = 611;
  14861. t['Lcommaaccent'] = 556;
  14862. t['Atilde'] = 611;
  14863. t['Aogonek'] = 611;
  14864. t['Aring'] = 611;
  14865. t['Otilde'] = 722;
  14866. t['zdotaccent'] = 389;
  14867. t['Ecaron'] = 611;
  14868. t['Iogonek'] = 333;
  14869. t['kcommaaccent'] = 444;
  14870. t['minus'] = 675;
  14871. t['Icircumflex'] = 333;
  14872. t['ncaron'] = 500;
  14873. t['tcommaaccent'] = 278;
  14874. t['logicalnot'] = 675;
  14875. t['odieresis'] = 500;
  14876. t['udieresis'] = 500;
  14877. t['notequal'] = 549;
  14878. t['gcommaaccent'] = 500;
  14879. t['eth'] = 500;
  14880. t['zcaron'] = 389;
  14881. t['ncommaaccent'] = 500;
  14882. t['onesuperior'] = 300;
  14883. t['imacron'] = 278;
  14884. t['Euro'] = 500;
  14885. });
  14886. t['ZapfDingbats'] = getLookupTableFactory(function (t) {
  14887. t['space'] = 278;
  14888. t['a1'] = 974;
  14889. t['a2'] = 961;
  14890. t['a202'] = 974;
  14891. t['a3'] = 980;
  14892. t['a4'] = 719;
  14893. t['a5'] = 789;
  14894. t['a119'] = 790;
  14895. t['a118'] = 791;
  14896. t['a117'] = 690;
  14897. t['a11'] = 960;
  14898. t['a12'] = 939;
  14899. t['a13'] = 549;
  14900. t['a14'] = 855;
  14901. t['a15'] = 911;
  14902. t['a16'] = 933;
  14903. t['a105'] = 911;
  14904. t['a17'] = 945;
  14905. t['a18'] = 974;
  14906. t['a19'] = 755;
  14907. t['a20'] = 846;
  14908. t['a21'] = 762;
  14909. t['a22'] = 761;
  14910. t['a23'] = 571;
  14911. t['a24'] = 677;
  14912. t['a25'] = 763;
  14913. t['a26'] = 760;
  14914. t['a27'] = 759;
  14915. t['a28'] = 754;
  14916. t['a6'] = 494;
  14917. t['a7'] = 552;
  14918. t['a8'] = 537;
  14919. t['a9'] = 577;
  14920. t['a10'] = 692;
  14921. t['a29'] = 786;
  14922. t['a30'] = 788;
  14923. t['a31'] = 788;
  14924. t['a32'] = 790;
  14925. t['a33'] = 793;
  14926. t['a34'] = 794;
  14927. t['a35'] = 816;
  14928. t['a36'] = 823;
  14929. t['a37'] = 789;
  14930. t['a38'] = 841;
  14931. t['a39'] = 823;
  14932. t['a40'] = 833;
  14933. t['a41'] = 816;
  14934. t['a42'] = 831;
  14935. t['a43'] = 923;
  14936. t['a44'] = 744;
  14937. t['a45'] = 723;
  14938. t['a46'] = 749;
  14939. t['a47'] = 790;
  14940. t['a48'] = 792;
  14941. t['a49'] = 695;
  14942. t['a50'] = 776;
  14943. t['a51'] = 768;
  14944. t['a52'] = 792;
  14945. t['a53'] = 759;
  14946. t['a54'] = 707;
  14947. t['a55'] = 708;
  14948. t['a56'] = 682;
  14949. t['a57'] = 701;
  14950. t['a58'] = 826;
  14951. t['a59'] = 815;
  14952. t['a60'] = 789;
  14953. t['a61'] = 789;
  14954. t['a62'] = 707;
  14955. t['a63'] = 687;
  14956. t['a64'] = 696;
  14957. t['a65'] = 689;
  14958. t['a66'] = 786;
  14959. t['a67'] = 787;
  14960. t['a68'] = 713;
  14961. t['a69'] = 791;
  14962. t['a70'] = 785;
  14963. t['a71'] = 791;
  14964. t['a72'] = 873;
  14965. t['a73'] = 761;
  14966. t['a74'] = 762;
  14967. t['a203'] = 762;
  14968. t['a75'] = 759;
  14969. t['a204'] = 759;
  14970. t['a76'] = 892;
  14971. t['a77'] = 892;
  14972. t['a78'] = 788;
  14973. t['a79'] = 784;
  14974. t['a81'] = 438;
  14975. t['a82'] = 138;
  14976. t['a83'] = 277;
  14977. t['a84'] = 415;
  14978. t['a97'] = 392;
  14979. t['a98'] = 392;
  14980. t['a99'] = 668;
  14981. t['a100'] = 668;
  14982. t['a89'] = 390;
  14983. t['a90'] = 390;
  14984. t['a93'] = 317;
  14985. t['a94'] = 317;
  14986. t['a91'] = 276;
  14987. t['a92'] = 276;
  14988. t['a205'] = 509;
  14989. t['a85'] = 509;
  14990. t['a206'] = 410;
  14991. t['a86'] = 410;
  14992. t['a87'] = 234;
  14993. t['a88'] = 234;
  14994. t['a95'] = 334;
  14995. t['a96'] = 334;
  14996. t['a101'] = 732;
  14997. t['a102'] = 544;
  14998. t['a103'] = 544;
  14999. t['a104'] = 910;
  15000. t['a106'] = 667;
  15001. t['a107'] = 760;
  15002. t['a108'] = 760;
  15003. t['a112'] = 776;
  15004. t['a111'] = 595;
  15005. t['a110'] = 694;
  15006. t['a109'] = 626;
  15007. t['a120'] = 788;
  15008. t['a121'] = 788;
  15009. t['a122'] = 788;
  15010. t['a123'] = 788;
  15011. t['a124'] = 788;
  15012. t['a125'] = 788;
  15013. t['a126'] = 788;
  15014. t['a127'] = 788;
  15015. t['a128'] = 788;
  15016. t['a129'] = 788;
  15017. t['a130'] = 788;
  15018. t['a131'] = 788;
  15019. t['a132'] = 788;
  15020. t['a133'] = 788;
  15021. t['a134'] = 788;
  15022. t['a135'] = 788;
  15023. t['a136'] = 788;
  15024. t['a137'] = 788;
  15025. t['a138'] = 788;
  15026. t['a139'] = 788;
  15027. t['a140'] = 788;
  15028. t['a141'] = 788;
  15029. t['a142'] = 788;
  15030. t['a143'] = 788;
  15031. t['a144'] = 788;
  15032. t['a145'] = 788;
  15033. t['a146'] = 788;
  15034. t['a147'] = 788;
  15035. t['a148'] = 788;
  15036. t['a149'] = 788;
  15037. t['a150'] = 788;
  15038. t['a151'] = 788;
  15039. t['a152'] = 788;
  15040. t['a153'] = 788;
  15041. t['a154'] = 788;
  15042. t['a155'] = 788;
  15043. t['a156'] = 788;
  15044. t['a157'] = 788;
  15045. t['a158'] = 788;
  15046. t['a159'] = 788;
  15047. t['a160'] = 894;
  15048. t['a161'] = 838;
  15049. t['a163'] = 1016;
  15050. t['a164'] = 458;
  15051. t['a196'] = 748;
  15052. t['a165'] = 924;
  15053. t['a192'] = 748;
  15054. t['a166'] = 918;
  15055. t['a167'] = 927;
  15056. t['a168'] = 928;
  15057. t['a169'] = 928;
  15058. t['a170'] = 834;
  15059. t['a171'] = 873;
  15060. t['a172'] = 828;
  15061. t['a173'] = 924;
  15062. t['a162'] = 924;
  15063. t['a174'] = 917;
  15064. t['a175'] = 930;
  15065. t['a176'] = 931;
  15066. t['a177'] = 463;
  15067. t['a178'] = 883;
  15068. t['a179'] = 836;
  15069. t['a193'] = 836;
  15070. t['a180'] = 867;
  15071. t['a199'] = 867;
  15072. t['a181'] = 696;
  15073. t['a200'] = 696;
  15074. t['a182'] = 874;
  15075. t['a201'] = 874;
  15076. t['a183'] = 760;
  15077. t['a184'] = 946;
  15078. t['a197'] = 771;
  15079. t['a185'] = 865;
  15080. t['a194'] = 771;
  15081. t['a198'] = 888;
  15082. t['a186'] = 967;
  15083. t['a195'] = 888;
  15084. t['a187'] = 831;
  15085. t['a188'] = 873;
  15086. t['a189'] = 927;
  15087. t['a190'] = 970;
  15088. t['a191'] = 918;
  15089. });
  15090. });
  15091. exports.getMetrics = getMetrics;
  15092. }));
  15093. (function (root, factory) {
  15094. {
  15095. factory((root.pdfjsCoreMurmurHash3 = {}), root.pdfjsSharedUtil);
  15096. }
  15097. }(this, function (exports, sharedUtil) {
  15098. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  15099. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  15100. // Workaround for missing math precison in JS.
  15101. var MASK_HIGH = 0xffff0000;
  15102. var MASK_LOW = 0xffff;
  15103. function MurmurHash3_64 (seed) {
  15104. var SEED = 0xc3d2e1f0;
  15105. this.h1 = seed ? seed & 0xffffffff : SEED;
  15106. this.h2 = seed ? seed & 0xffffffff : SEED;
  15107. }
  15108. var alwaysUseUint32ArrayView = false;
  15109. // old webkits have issues with non-aligned arrays
  15110. try {
  15111. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  15112. } catch (e) {
  15113. alwaysUseUint32ArrayView = true;
  15114. }
  15115. MurmurHash3_64.prototype = {
  15116. update: function MurmurHash3_64_update(input) {
  15117. var useUint32ArrayView = alwaysUseUint32ArrayView;
  15118. var i;
  15119. if (typeof input === 'string') {
  15120. var data = new Uint8Array(input.length * 2);
  15121. var length = 0;
  15122. for (i = 0; i < input.length; i++) {
  15123. var code = input.charCodeAt(i);
  15124. if (code <= 0xff) {
  15125. data[length++] = code;
  15126. }
  15127. else {
  15128. data[length++] = code >>> 8;
  15129. data[length++] = code & 0xff;
  15130. }
  15131. }
  15132. } else if (input instanceof Uint8Array) {
  15133. data = input;
  15134. length = data.length;
  15135. } else if (typeof input === 'object' && ('length' in input)) {
  15136. // processing regular arrays as well, e.g. for IE9
  15137. data = input;
  15138. length = data.length;
  15139. useUint32ArrayView = true;
  15140. } else {
  15141. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  15142. 'Input must be a string or array.');
  15143. }
  15144. var blockCounts = length >> 2;
  15145. var tailLength = length - blockCounts * 4;
  15146. // we don't care about endianness here
  15147. var dataUint32 = useUint32ArrayView ?
  15148. new Uint32ArrayView(data, blockCounts) :
  15149. new Uint32Array(data.buffer, 0, blockCounts);
  15150. var k1 = 0;
  15151. var k2 = 0;
  15152. var h1 = this.h1;
  15153. var h2 = this.h2;
  15154. var C1 = 0xcc9e2d51;
  15155. var C2 = 0x1b873593;
  15156. var C1_LOW = C1 & MASK_LOW;
  15157. var C2_LOW = C2 & MASK_LOW;
  15158. for (i = 0; i < blockCounts; i++) {
  15159. if (i & 1) {
  15160. k1 = dataUint32[i];
  15161. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  15162. k1 = k1 << 15 | k1 >>> 17;
  15163. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  15164. h1 ^= k1;
  15165. h1 = h1 << 13 | h1 >>> 19;
  15166. h1 = h1 * 5 + 0xe6546b64;
  15167. } else {
  15168. k2 = dataUint32[i];
  15169. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  15170. k2 = k2 << 15 | k2 >>> 17;
  15171. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  15172. h2 ^= k2;
  15173. h2 = h2 << 13 | h2 >>> 19;
  15174. h2 = h2 * 5 + 0xe6546b64;
  15175. }
  15176. }
  15177. k1 = 0;
  15178. switch (tailLength) {
  15179. case 3:
  15180. k1 ^= data[blockCounts * 4 + 2] << 16;
  15181. /* falls through */
  15182. case 2:
  15183. k1 ^= data[blockCounts * 4 + 1] << 8;
  15184. /* falls through */
  15185. case 1:
  15186. k1 ^= data[blockCounts * 4];
  15187. /* falls through */
  15188. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  15189. k1 = k1 << 15 | k1 >>> 17;
  15190. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  15191. if (blockCounts & 1) {
  15192. h1 ^= k1;
  15193. } else {
  15194. h2 ^= k1;
  15195. }
  15196. }
  15197. this.h1 = h1;
  15198. this.h2 = h2;
  15199. return this;
  15200. },
  15201. hexdigest: function MurmurHash3_64_hexdigest () {
  15202. var h1 = this.h1;
  15203. var h2 = this.h2;
  15204. h1 ^= h2 >>> 1;
  15205. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  15206. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  15207. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  15208. h1 ^= h2 >>> 1;
  15209. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  15210. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  15211. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  15212. h1 ^= h2 >>> 1;
  15213. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  15214. var hex = (arr[i] >>> 0).toString(16);
  15215. while (hex.length < 8) {
  15216. hex = '0' + hex;
  15217. }
  15218. str += hex;
  15219. }
  15220. return str;
  15221. }
  15222. };
  15223. return MurmurHash3_64;
  15224. })();
  15225. exports.MurmurHash3_64 = MurmurHash3_64;
  15226. }));
  15227. (function (root, factory) {
  15228. {
  15229. factory((root.pdfjsCorePrimitives = {}), root.pdfjsSharedUtil);
  15230. }
  15231. }(this, function (exports, sharedUtil) {
  15232. var isArray = sharedUtil.isArray;
  15233. var Name = (function NameClosure() {
  15234. function Name(name) {
  15235. this.name = name;
  15236. }
  15237. Name.prototype = {};
  15238. var nameCache = Object.create(null);
  15239. Name.get = function Name_get(name) {
  15240. var nameValue = nameCache[name];
  15241. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  15242. };
  15243. return Name;
  15244. })();
  15245. var Cmd = (function CmdClosure() {
  15246. function Cmd(cmd) {
  15247. this.cmd = cmd;
  15248. }
  15249. Cmd.prototype = {};
  15250. var cmdCache = Object.create(null);
  15251. Cmd.get = function Cmd_get(cmd) {
  15252. var cmdValue = cmdCache[cmd];
  15253. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  15254. };
  15255. return Cmd;
  15256. })();
  15257. var Dict = (function DictClosure() {
  15258. var nonSerializable = function nonSerializableClosure() {
  15259. return nonSerializable; // creating closure on some variable
  15260. };
  15261. // xref is optional
  15262. function Dict(xref) {
  15263. // Map should only be used internally, use functions below to access.
  15264. this.map = Object.create(null);
  15265. this.xref = xref;
  15266. this.objId = null;
  15267. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  15268. }
  15269. Dict.prototype = {
  15270. assignXref: function Dict_assignXref(newXref) {
  15271. this.xref = newXref;
  15272. },
  15273. // automatically dereferences Ref objects
  15274. get: function Dict_get(key1, key2, key3) {
  15275. var value;
  15276. var xref = this.xref;
  15277. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  15278. typeof key2 === 'undefined') {
  15279. return xref ? xref.fetchIfRef(value) : value;
  15280. }
  15281. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  15282. typeof key3 === 'undefined') {
  15283. return xref ? xref.fetchIfRef(value) : value;
  15284. }
  15285. value = this.map[key3] || null;
  15286. return xref ? xref.fetchIfRef(value) : value;
  15287. },
  15288. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  15289. getAsync: function Dict_getAsync(key1, key2, key3) {
  15290. var value;
  15291. var xref = this.xref;
  15292. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  15293. typeof key2 === 'undefined') {
  15294. if (xref) {
  15295. return xref.fetchIfRefAsync(value);
  15296. }
  15297. return Promise.resolve(value);
  15298. }
  15299. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  15300. typeof key3 === 'undefined') {
  15301. if (xref) {
  15302. return xref.fetchIfRefAsync(value);
  15303. }
  15304. return Promise.resolve(value);
  15305. }
  15306. value = this.map[key3] || null;
  15307. if (xref) {
  15308. return xref.fetchIfRefAsync(value);
  15309. }
  15310. return Promise.resolve(value);
  15311. },
  15312. // Same as get(), but dereferences all elements if the result is an Array.
  15313. getArray: function Dict_getArray(key1, key2, key3) {
  15314. var value = this.get(key1, key2, key3);
  15315. var xref = this.xref;
  15316. if (!isArray(value) || !xref) {
  15317. return value;
  15318. }
  15319. value = value.slice(); // Ensure that we don't modify the Dict data.
  15320. for (var i = 0, ii = value.length; i < ii; i++) {
  15321. if (!isRef(value[i])) {
  15322. continue;
  15323. }
  15324. value[i] = xref.fetch(value[i]);
  15325. }
  15326. return value;
  15327. },
  15328. // no dereferencing
  15329. getRaw: function Dict_getRaw(key) {
  15330. return this.map[key];
  15331. },
  15332. getKeys: function Dict_getKeys() {
  15333. return Object.keys(this.map);
  15334. },
  15335. set: function Dict_set(key, value) {
  15336. this.map[key] = value;
  15337. },
  15338. has: function Dict_has(key) {
  15339. return key in this.map;
  15340. },
  15341. forEach: function Dict_forEach(callback) {
  15342. for (var key in this.map) {
  15343. callback(key, this.get(key));
  15344. }
  15345. }
  15346. };
  15347. Dict.empty = new Dict(null);
  15348. Dict.merge = function Dict_merge(xref, dictArray) {
  15349. var mergedDict = new Dict(xref);
  15350. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  15351. var dict = dictArray[i];
  15352. if (!isDict(dict)) {
  15353. continue;
  15354. }
  15355. for (var keyName in dict.map) {
  15356. if (mergedDict.map[keyName]) {
  15357. continue;
  15358. }
  15359. mergedDict.map[keyName] = dict.map[keyName];
  15360. }
  15361. }
  15362. return mergedDict;
  15363. };
  15364. return Dict;
  15365. })();
  15366. var Ref = (function RefClosure() {
  15367. function Ref(num, gen) {
  15368. this.num = num;
  15369. this.gen = gen;
  15370. }
  15371. Ref.prototype = {
  15372. toString: function Ref_toString() {
  15373. // This function is hot, so we make the string as compact as possible.
  15374. // |this.gen| is almost always zero, so we treat that case specially.
  15375. var str = this.num + 'R';
  15376. if (this.gen !== 0) {
  15377. str += this.gen;
  15378. }
  15379. return str;
  15380. }
  15381. };
  15382. return Ref;
  15383. })();
  15384. // The reference is identified by number and generation.
  15385. // This structure stores only one instance of the reference.
  15386. var RefSet = (function RefSetClosure() {
  15387. function RefSet() {
  15388. this.dict = Object.create(null);
  15389. }
  15390. RefSet.prototype = {
  15391. has: function RefSet_has(ref) {
  15392. return ref.toString() in this.dict;
  15393. },
  15394. put: function RefSet_put(ref) {
  15395. this.dict[ref.toString()] = true;
  15396. },
  15397. remove: function RefSet_remove(ref) {
  15398. delete this.dict[ref.toString()];
  15399. }
  15400. };
  15401. return RefSet;
  15402. })();
  15403. var RefSetCache = (function RefSetCacheClosure() {
  15404. function RefSetCache() {
  15405. this.dict = Object.create(null);
  15406. }
  15407. RefSetCache.prototype = {
  15408. get: function RefSetCache_get(ref) {
  15409. return this.dict[ref.toString()];
  15410. },
  15411. has: function RefSetCache_has(ref) {
  15412. return ref.toString() in this.dict;
  15413. },
  15414. put: function RefSetCache_put(ref, obj) {
  15415. this.dict[ref.toString()] = obj;
  15416. },
  15417. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  15418. this.dict[ref.toString()] = this.get(aliasRef);
  15419. },
  15420. forEach: function RefSetCache_forEach(fn, thisArg) {
  15421. for (var i in this.dict) {
  15422. fn.call(thisArg, this.dict[i]);
  15423. }
  15424. },
  15425. clear: function RefSetCache_clear() {
  15426. this.dict = Object.create(null);
  15427. }
  15428. };
  15429. return RefSetCache;
  15430. })();
  15431. function isName(v) {
  15432. return v instanceof Name;
  15433. }
  15434. function isCmd(v, cmd) {
  15435. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  15436. }
  15437. function isDict(v, type) {
  15438. if (!(v instanceof Dict)) {
  15439. return false;
  15440. }
  15441. if (!type) {
  15442. return true;
  15443. }
  15444. var dictType = v.get('Type');
  15445. return isName(dictType) && dictType.name === type;
  15446. }
  15447. function isRef(v) {
  15448. return v instanceof Ref;
  15449. }
  15450. function isStream(v) {
  15451. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  15452. }
  15453. exports.Cmd = Cmd;
  15454. exports.Dict = Dict;
  15455. exports.Name = Name;
  15456. exports.Ref = Ref;
  15457. exports.RefSet = RefSet;
  15458. exports.RefSetCache = RefSetCache;
  15459. exports.isCmd = isCmd;
  15460. exports.isDict = isDict;
  15461. exports.isName = isName;
  15462. exports.isRef = isRef;
  15463. exports.isStream = isStream;
  15464. }));
  15465. (function (root, factory) {
  15466. {
  15467. factory((root.pdfjsCoreStandardFonts = {}), root.pdfjsSharedUtil);
  15468. }
  15469. }(this, function (exports, sharedUtil) {
  15470. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  15471. /**
  15472. * Hold a map of decoded fonts and of the standard fourteen Type1
  15473. * fonts and their acronyms.
  15474. */
  15475. var getStdFontMap = getLookupTableFactory(function (t) {
  15476. t['ArialNarrow'] = 'Helvetica';
  15477. t['ArialNarrow-Bold'] = 'Helvetica-Bold';
  15478. t['ArialNarrow-BoldItalic'] = 'Helvetica-BoldOblique';
  15479. t['ArialNarrow-Italic'] = 'Helvetica-Oblique';
  15480. t['ArialBlack'] = 'Helvetica';
  15481. t['ArialBlack-Bold'] = 'Helvetica-Bold';
  15482. t['ArialBlack-BoldItalic'] = 'Helvetica-BoldOblique';
  15483. t['ArialBlack-Italic'] = 'Helvetica-Oblique';
  15484. t['Arial'] = 'Helvetica';
  15485. t['Arial-Bold'] = 'Helvetica-Bold';
  15486. t['Arial-BoldItalic'] = 'Helvetica-BoldOblique';
  15487. t['Arial-Italic'] = 'Helvetica-Oblique';
  15488. t['Arial-BoldItalicMT'] = 'Helvetica-BoldOblique';
  15489. t['Arial-BoldMT'] = 'Helvetica-Bold';
  15490. t['Arial-ItalicMT'] = 'Helvetica-Oblique';
  15491. t['ArialMT'] = 'Helvetica';
  15492. t['Courier-Bold'] = 'Courier-Bold';
  15493. t['Courier-BoldItalic'] = 'Courier-BoldOblique';
  15494. t['Courier-Italic'] = 'Courier-Oblique';
  15495. t['CourierNew'] = 'Courier';
  15496. t['CourierNew-Bold'] = 'Courier-Bold';
  15497. t['CourierNew-BoldItalic'] = 'Courier-BoldOblique';
  15498. t['CourierNew-Italic'] = 'Courier-Oblique';
  15499. t['CourierNewPS-BoldItalicMT'] = 'Courier-BoldOblique';
  15500. t['CourierNewPS-BoldMT'] = 'Courier-Bold';
  15501. t['CourierNewPS-ItalicMT'] = 'Courier-Oblique';
  15502. t['CourierNewPSMT'] = 'Courier';
  15503. t['Helvetica'] = 'Helvetica';
  15504. t['Helvetica-Bold'] = 'Helvetica-Bold';
  15505. t['Helvetica-BoldItalic'] = 'Helvetica-BoldOblique';
  15506. t['Helvetica-BoldOblique'] = 'Helvetica-BoldOblique';
  15507. t['Helvetica-Italic'] = 'Helvetica-Oblique';
  15508. t['Helvetica-Oblique'] = 'Helvetica-Oblique';
  15509. t['Symbol-Bold'] = 'Symbol';
  15510. t['Symbol-BoldItalic'] = 'Symbol';
  15511. t['Symbol-Italic'] = 'Symbol';
  15512. t['TimesNewRoman'] = 'Times-Roman';
  15513. t['TimesNewRoman-Bold'] = 'Times-Bold';
  15514. t['TimesNewRoman-BoldItalic'] = 'Times-BoldItalic';
  15515. t['TimesNewRoman-Italic'] = 'Times-Italic';
  15516. t['TimesNewRomanPS'] = 'Times-Roman';
  15517. t['TimesNewRomanPS-Bold'] = 'Times-Bold';
  15518. t['TimesNewRomanPS-BoldItalic'] = 'Times-BoldItalic';
  15519. t['TimesNewRomanPS-BoldItalicMT'] = 'Times-BoldItalic';
  15520. t['TimesNewRomanPS-BoldMT'] = 'Times-Bold';
  15521. t['TimesNewRomanPS-Italic'] = 'Times-Italic';
  15522. t['TimesNewRomanPS-ItalicMT'] = 'Times-Italic';
  15523. t['TimesNewRomanPSMT'] = 'Times-Roman';
  15524. t['TimesNewRomanPSMT-Bold'] = 'Times-Bold';
  15525. t['TimesNewRomanPSMT-BoldItalic'] = 'Times-BoldItalic';
  15526. t['TimesNewRomanPSMT-Italic'] = 'Times-Italic';
  15527. });
  15528. /**
  15529. * Holds the map of the non-standard fonts that might be included as
  15530. * a standard fonts without glyph data.
  15531. */
  15532. var getNonStdFontMap = getLookupTableFactory(function (t) {
  15533. t['CenturyGothic'] = 'Helvetica';
  15534. t['CenturyGothic-Bold'] = 'Helvetica-Bold';
  15535. t['CenturyGothic-BoldItalic'] = 'Helvetica-BoldOblique';
  15536. t['CenturyGothic-Italic'] = 'Helvetica-Oblique';
  15537. t['ComicSansMS'] = 'Comic Sans MS';
  15538. t['ComicSansMS-Bold'] = 'Comic Sans MS-Bold';
  15539. t['ComicSansMS-BoldItalic'] = 'Comic Sans MS-BoldItalic';
  15540. t['ComicSansMS-Italic'] = 'Comic Sans MS-Italic';
  15541. t['LucidaConsole'] = 'Courier';
  15542. t['LucidaConsole-Bold'] = 'Courier-Bold';
  15543. t['LucidaConsole-BoldItalic'] = 'Courier-BoldOblique';
  15544. t['LucidaConsole-Italic'] = 'Courier-Oblique';
  15545. t['MS-Gothic'] = 'MS Gothic';
  15546. t['MS-Gothic-Bold'] = 'MS Gothic-Bold';
  15547. t['MS-Gothic-BoldItalic'] = 'MS Gothic-BoldItalic';
  15548. t['MS-Gothic-Italic'] = 'MS Gothic-Italic';
  15549. t['MS-Mincho'] = 'MS Mincho';
  15550. t['MS-Mincho-Bold'] = 'MS Mincho-Bold';
  15551. t['MS-Mincho-BoldItalic'] = 'MS Mincho-BoldItalic';
  15552. t['MS-Mincho-Italic'] = 'MS Mincho-Italic';
  15553. t['MS-PGothic'] = 'MS PGothic';
  15554. t['MS-PGothic-Bold'] = 'MS PGothic-Bold';
  15555. t['MS-PGothic-BoldItalic'] = 'MS PGothic-BoldItalic';
  15556. t['MS-PGothic-Italic'] = 'MS PGothic-Italic';
  15557. t['MS-PMincho'] = 'MS PMincho';
  15558. t['MS-PMincho-Bold'] = 'MS PMincho-Bold';
  15559. t['MS-PMincho-BoldItalic'] = 'MS PMincho-BoldItalic';
  15560. t['MS-PMincho-Italic'] = 'MS PMincho-Italic';
  15561. t['Wingdings'] = 'ZapfDingbats';
  15562. });
  15563. var getSerifFonts = getLookupTableFactory(function (t) {
  15564. t['Adobe Jenson'] = true;
  15565. t['Adobe Text'] = true;
  15566. t['Albertus'] = true;
  15567. t['Aldus'] = true;
  15568. t['Alexandria'] = true;
  15569. t['Algerian'] = true;
  15570. t['American Typewriter'] = true;
  15571. t['Antiqua'] = true;
  15572. t['Apex'] = true;
  15573. t['Arno'] = true;
  15574. t['Aster'] = true;
  15575. t['Aurora'] = true;
  15576. t['Baskerville'] = true;
  15577. t['Bell'] = true;
  15578. t['Bembo'] = true;
  15579. t['Bembo Schoolbook'] = true;
  15580. t['Benguiat'] = true;
  15581. t['Berkeley Old Style'] = true;
  15582. t['Bernhard Modern'] = true;
  15583. t['Berthold City'] = true;
  15584. t['Bodoni'] = true;
  15585. t['Bauer Bodoni'] = true;
  15586. t['Book Antiqua'] = true;
  15587. t['Bookman'] = true;
  15588. t['Bordeaux Roman'] = true;
  15589. t['Californian FB'] = true;
  15590. t['Calisto'] = true;
  15591. t['Calvert'] = true;
  15592. t['Capitals'] = true;
  15593. t['Cambria'] = true;
  15594. t['Cartier'] = true;
  15595. t['Caslon'] = true;
  15596. t['Catull'] = true;
  15597. t['Centaur'] = true;
  15598. t['Century Old Style'] = true;
  15599. t['Century Schoolbook'] = true;
  15600. t['Chaparral'] = true;
  15601. t['Charis SIL'] = true;
  15602. t['Cheltenham'] = true;
  15603. t['Cholla Slab'] = true;
  15604. t['Clarendon'] = true;
  15605. t['Clearface'] = true;
  15606. t['Cochin'] = true;
  15607. t['Colonna'] = true;
  15608. t['Computer Modern'] = true;
  15609. t['Concrete Roman'] = true;
  15610. t['Constantia'] = true;
  15611. t['Cooper Black'] = true;
  15612. t['Corona'] = true;
  15613. t['Ecotype'] = true;
  15614. t['Egyptienne'] = true;
  15615. t['Elephant'] = true;
  15616. t['Excelsior'] = true;
  15617. t['Fairfield'] = true;
  15618. t['FF Scala'] = true;
  15619. t['Folkard'] = true;
  15620. t['Footlight'] = true;
  15621. t['FreeSerif'] = true;
  15622. t['Friz Quadrata'] = true;
  15623. t['Garamond'] = true;
  15624. t['Gentium'] = true;
  15625. t['Georgia'] = true;
  15626. t['Gloucester'] = true;
  15627. t['Goudy Old Style'] = true;
  15628. t['Goudy Schoolbook'] = true;
  15629. t['Goudy Pro Font'] = true;
  15630. t['Granjon'] = true;
  15631. t['Guardian Egyptian'] = true;
  15632. t['Heather'] = true;
  15633. t['Hercules'] = true;
  15634. t['High Tower Text'] = true;
  15635. t['Hiroshige'] = true;
  15636. t['Hoefler Text'] = true;
  15637. t['Humana Serif'] = true;
  15638. t['Imprint'] = true;
  15639. t['Ionic No. 5'] = true;
  15640. t['Janson'] = true;
  15641. t['Joanna'] = true;
  15642. t['Korinna'] = true;
  15643. t['Lexicon'] = true;
  15644. t['Liberation Serif'] = true;
  15645. t['Linux Libertine'] = true;
  15646. t['Literaturnaya'] = true;
  15647. t['Lucida'] = true;
  15648. t['Lucida Bright'] = true;
  15649. t['Melior'] = true;
  15650. t['Memphis'] = true;
  15651. t['Miller'] = true;
  15652. t['Minion'] = true;
  15653. t['Modern'] = true;
  15654. t['Mona Lisa'] = true;
  15655. t['Mrs Eaves'] = true;
  15656. t['MS Serif'] = true;
  15657. t['Museo Slab'] = true;
  15658. t['New York'] = true;
  15659. t['Nimbus Roman'] = true;
  15660. t['NPS Rawlinson Roadway'] = true;
  15661. t['Palatino'] = true;
  15662. t['Perpetua'] = true;
  15663. t['Plantin'] = true;
  15664. t['Plantin Schoolbook'] = true;
  15665. t['Playbill'] = true;
  15666. t['Poor Richard'] = true;
  15667. t['Rawlinson Roadway'] = true;
  15668. t['Renault'] = true;
  15669. t['Requiem'] = true;
  15670. t['Rockwell'] = true;
  15671. t['Roman'] = true;
  15672. t['Rotis Serif'] = true;
  15673. t['Sabon'] = true;
  15674. t['Scala'] = true;
  15675. t['Seagull'] = true;
  15676. t['Sistina'] = true;
  15677. t['Souvenir'] = true;
  15678. t['STIX'] = true;
  15679. t['Stone Informal'] = true;
  15680. t['Stone Serif'] = true;
  15681. t['Sylfaen'] = true;
  15682. t['Times'] = true;
  15683. t['Trajan'] = true;
  15684. t['Trinité'] = true;
  15685. t['Trump Mediaeval'] = true;
  15686. t['Utopia'] = true;
  15687. t['Vale Type'] = true;
  15688. t['Bitstream Vera'] = true;
  15689. t['Vera Serif'] = true;
  15690. t['Versailles'] = true;
  15691. t['Wanted'] = true;
  15692. t['Weiss'] = true;
  15693. t['Wide Latin'] = true;
  15694. t['Windsor'] = true;
  15695. t['XITS'] = true;
  15696. });
  15697. var getSymbolsFonts = getLookupTableFactory(function (t) {
  15698. t['Dingbats'] = true;
  15699. t['Symbol'] = true;
  15700. t['ZapfDingbats'] = true;
  15701. });
  15702. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID
  15703. // fonts, but does not embed the CID to GID mapping. The mapping is incomplete
  15704. // for all glyphs, but common for some set of the standard fonts.
  15705. var getGlyphMapForStandardFonts = getLookupTableFactory(function (t) {
  15706. t[2] = 10; t[3] = 32; t[4] = 33; t[5] = 34; t[6] = 35; t[7] = 36; t[8] = 37;
  15707. t[9] = 38; t[10] = 39; t[11] = 40; t[12] = 41; t[13] = 42; t[14] = 43;
  15708. t[15] = 44; t[16] = 45; t[17] = 46; t[18] = 47; t[19] = 48; t[20] = 49;
  15709. t[21] = 50; t[22] = 51; t[23] = 52; t[24] = 53; t[25] = 54; t[26] = 55;
  15710. t[27] = 56; t[28] = 57; t[29] = 58; t[30] = 894; t[31] = 60; t[32] = 61;
  15711. t[33] = 62; t[34] = 63; t[35] = 64; t[36] = 65; t[37] = 66; t[38] = 67;
  15712. t[39] = 68; t[40] = 69; t[41] = 70; t[42] = 71; t[43] = 72; t[44] = 73;
  15713. t[45] = 74; t[46] = 75; t[47] = 76; t[48] = 77; t[49] = 78; t[50] = 79;
  15714. t[51] = 80; t[52] = 81; t[53] = 82; t[54] = 83; t[55] = 84; t[56] = 85;
  15715. t[57] = 86; t[58] = 87; t[59] = 88; t[60] = 89; t[61] = 90; t[62] = 91;
  15716. t[63] = 92; t[64] = 93; t[65] = 94; t[66] = 95; t[67] = 96; t[68] = 97;
  15717. t[69] = 98; t[70] = 99; t[71] = 100; t[72] = 101; t[73] = 102; t[74] = 103;
  15718. t[75] = 104; t[76] = 105; t[77] = 106; t[78] = 107; t[79] = 108;
  15719. t[80] = 109; t[81] = 110; t[82] = 111; t[83] = 112; t[84] = 113;
  15720. t[85] = 114; t[86] = 115; t[87] = 116; t[88] = 117; t[89] = 118;
  15721. t[90] = 119; t[91] = 120; t[92] = 121; t[93] = 122; t[94] = 123;
  15722. t[95] = 124; t[96] = 125; t[97] = 126; t[98] = 196; t[99] = 197;
  15723. t[100] = 199; t[101] = 201; t[102] = 209; t[103] = 214; t[104] = 220;
  15724. t[105] = 225; t[106] = 224; t[107] = 226; t[108] = 228; t[109] = 227;
  15725. t[110] = 229; t[111] = 231; t[112] = 233; t[113] = 232; t[114] = 234;
  15726. t[115] = 235; t[116] = 237; t[117] = 236; t[118] = 238; t[119] = 239;
  15727. t[120] = 241; t[121] = 243; t[122] = 242; t[123] = 244; t[124] = 246;
  15728. t[125] = 245; t[126] = 250; t[127] = 249; t[128] = 251; t[129] = 252;
  15729. t[130] = 8224; t[131] = 176; t[132] = 162; t[133] = 163; t[134] = 167;
  15730. t[135] = 8226; t[136] = 182; t[137] = 223; t[138] = 174; t[139] = 169;
  15731. t[140] = 8482; t[141] = 180; t[142] = 168; t[143] = 8800; t[144] = 198;
  15732. t[145] = 216; t[146] = 8734; t[147] = 177; t[148] = 8804; t[149] = 8805;
  15733. t[150] = 165; t[151] = 181; t[152] = 8706; t[153] = 8721; t[154] = 8719;
  15734. t[156] = 8747; t[157] = 170; t[158] = 186; t[159] = 8486; t[160] = 230;
  15735. t[161] = 248; t[162] = 191; t[163] = 161; t[164] = 172; t[165] = 8730;
  15736. t[166] = 402; t[167] = 8776; t[168] = 8710; t[169] = 171; t[170] = 187;
  15737. t[171] = 8230; t[210] = 218; t[223] = 711; t[224] = 321; t[225] = 322;
  15738. t[227] = 353; t[229] = 382; t[234] = 253; t[252] = 263; t[253] = 268;
  15739. t[254] = 269; t[258] = 258; t[260] = 260; t[261] = 261; t[265] = 280;
  15740. t[266] = 281; t[268] = 283; t[269] = 313; t[275] = 323; t[276] = 324;
  15741. t[278] = 328; t[284] = 345; t[285] = 346; t[286] = 347; t[292] = 367;
  15742. t[295] = 377; t[296] = 378; t[298] = 380; t[305] = 963; t[306] = 964;
  15743. t[307] = 966; t[308] = 8215; t[309] = 8252; t[310] = 8319; t[311] = 8359;
  15744. t[312] = 8592; t[313] = 8593; t[337] = 9552; t[493] = 1039;
  15745. t[494] = 1040; t[705] = 1524; t[706] = 8362; t[710] = 64288; t[711] = 64298;
  15746. t[759] = 1617; t[761] = 1776; t[763] = 1778; t[775] = 1652; t[777] = 1764;
  15747. t[778] = 1780; t[779] = 1781; t[780] = 1782; t[782] = 771; t[783] = 64726;
  15748. t[786] = 8363; t[788] = 8532; t[790] = 768; t[791] = 769; t[792] = 768;
  15749. t[795] = 803; t[797] = 64336; t[798] = 64337; t[799] = 64342;
  15750. t[800] = 64343; t[801] = 64344; t[802] = 64345; t[803] = 64362;
  15751. t[804] = 64363; t[805] = 64364; t[2424] = 7821; t[2425] = 7822;
  15752. t[2426] = 7823; t[2427] = 7824; t[2428] = 7825; t[2429] = 7826;
  15753. t[2430] = 7827; t[2433] = 7682; t[2678] = 8045; t[2679] = 8046;
  15754. t[2830] = 1552; t[2838] = 686; t[2840] = 751; t[2842] = 753; t[2843] = 754;
  15755. t[2844] = 755; t[2846] = 757; t[2856] = 767; t[2857] = 848; t[2858] = 849;
  15756. t[2862] = 853; t[2863] = 854; t[2864] = 855; t[2865] = 861; t[2866] = 862;
  15757. t[2906] = 7460; t[2908] = 7462; t[2909] = 7463; t[2910] = 7464;
  15758. t[2912] = 7466; t[2913] = 7467; t[2914] = 7468; t[2916] = 7470;
  15759. t[2917] = 7471; t[2918] = 7472; t[2920] = 7474; t[2921] = 7475;
  15760. t[2922] = 7476; t[2924] = 7478; t[2925] = 7479; t[2926] = 7480;
  15761. t[2928] = 7482; t[2929] = 7483; t[2930] = 7484; t[2932] = 7486;
  15762. t[2933] = 7487; t[2934] = 7488; t[2936] = 7490; t[2937] = 7491;
  15763. t[2938] = 7492; t[2940] = 7494; t[2941] = 7495; t[2942] = 7496;
  15764. t[2944] = 7498; t[2946] = 7500; t[2948] = 7502; t[2950] = 7504;
  15765. t[2951] = 7505; t[2952] = 7506; t[2954] = 7508; t[2955] = 7509;
  15766. t[2956] = 7510; t[2958] = 7512; t[2959] = 7513; t[2960] = 7514;
  15767. t[2962] = 7516; t[2963] = 7517; t[2964] = 7518; t[2966] = 7520;
  15768. t[2967] = 7521; t[2968] = 7522; t[2970] = 7524; t[2971] = 7525;
  15769. t[2972] = 7526; t[2974] = 7528; t[2975] = 7529; t[2976] = 7530;
  15770. t[2978] = 1537; t[2979] = 1538; t[2980] = 1539; t[2982] = 1549;
  15771. t[2983] = 1551; t[2984] = 1552; t[2986] = 1554; t[2987] = 1555;
  15772. t[2988] = 1556; t[2990] = 1623; t[2991] = 1624; t[2995] = 1775;
  15773. t[2999] = 1791; t[3002] = 64290; t[3003] = 64291; t[3004] = 64292;
  15774. t[3006] = 64294; t[3007] = 64295; t[3008] = 64296; t[3011] = 1900;
  15775. t[3014] = 8223; t[3015] = 8244; t[3017] = 7532; t[3018] = 7533;
  15776. t[3019] = 7534; t[3075] = 7590; t[3076] = 7591; t[3079] = 7594;
  15777. t[3080] = 7595; t[3083] = 7598; t[3084] = 7599; t[3087] = 7602;
  15778. t[3088] = 7603; t[3091] = 7606; t[3092] = 7607; t[3095] = 7610;
  15779. t[3096] = 7611; t[3099] = 7614; t[3100] = 7615; t[3103] = 7618;
  15780. t[3104] = 7619; t[3107] = 8337; t[3108] = 8338; t[3116] = 1884;
  15781. t[3119] = 1885; t[3120] = 1885; t[3123] = 1886; t[3124] = 1886;
  15782. t[3127] = 1887; t[3128] = 1887; t[3131] = 1888; t[3132] = 1888;
  15783. t[3135] = 1889; t[3136] = 1889; t[3139] = 1890; t[3140] = 1890;
  15784. t[3143] = 1891; t[3144] = 1891; t[3147] = 1892; t[3148] = 1892;
  15785. t[3153] = 580; t[3154] = 581; t[3157] = 584; t[3158] = 585; t[3161] = 588;
  15786. t[3162] = 589; t[3165] = 891; t[3166] = 892; t[3169] = 1274; t[3170] = 1275;
  15787. t[3173] = 1278; t[3174] = 1279; t[3181] = 7622; t[3182] = 7623;
  15788. t[3282] = 11799; t[3316] = 578; t[3379] = 42785; t[3393] = 1159;
  15789. t[3416] = 8377;
  15790. });
  15791. // The glyph map for ArialBlack differs slightly from the glyph map used for
  15792. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  15793. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  15794. var getSupplementalGlyphMapForArialBlack =
  15795. getLookupTableFactory(function (t) {
  15796. t[227] = 322; t[264] = 261; t[291] = 346;
  15797. });
  15798. exports.getStdFontMap = getStdFontMap;
  15799. exports.getNonStdFontMap = getNonStdFontMap;
  15800. exports.getSerifFonts = getSerifFonts;
  15801. exports.getSymbolsFonts = getSymbolsFonts;
  15802. exports.getGlyphMapForStandardFonts = getGlyphMapForStandardFonts;
  15803. exports.getSupplementalGlyphMapForArialBlack =
  15804. getSupplementalGlyphMapForArialBlack;
  15805. }));
  15806. (function (root, factory) {
  15807. {
  15808. factory((root.pdfjsCoreUnicode = {}), root.pdfjsSharedUtil);
  15809. }
  15810. }(this, function (exports, sharedUtil) {
  15811. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  15812. // Some characters, e.g. copyrightserif, are mapped to the private use area
  15813. // and might not be displayed using standard fonts. Mapping/hacking well-known
  15814. // chars to the similar equivalents in the normal characters range.
  15815. var getSpecialPUASymbols = getLookupTableFactory(function (t) {
  15816. t[63721] = 0x00A9; // copyrightsans (0xF8E9) => copyright
  15817. t[63193] = 0x00A9; // copyrightserif (0xF6D9) => copyright
  15818. t[63720] = 0x00AE; // registersans (0xF8E8) => registered
  15819. t[63194] = 0x00AE; // registerserif (0xF6DA) => registered
  15820. t[63722] = 0x2122; // trademarksans (0xF8EA) => trademark
  15821. t[63195] = 0x2122; // trademarkserif (0xF6DB) => trademark
  15822. t[63729] = 0x23A7; // bracelefttp (0xF8F1)
  15823. t[63730] = 0x23A8; // braceleftmid (0xF8F2)
  15824. t[63731] = 0x23A9; // braceleftbt (0xF8F3)
  15825. t[63740] = 0x23AB; // bracerighttp (0xF8FC)
  15826. t[63741] = 0x23AC; // bracerightmid (0xF8FD)
  15827. t[63742] = 0x23AD; // bracerightbt (0xF8FE)
  15828. t[63726] = 0x23A1; // bracketlefttp (0xF8EE)
  15829. t[63727] = 0x23A2; // bracketleftex (0xF8EF)
  15830. t[63728] = 0x23A3; // bracketleftbt (0xF8F0)
  15831. t[63737] = 0x23A4; // bracketrighttp (0xF8F9)
  15832. t[63738] = 0x23A5; // bracketrightex (0xF8FA)
  15833. t[63739] = 0x23A6; // bracketrightbt (0xF8FB)
  15834. t[63723] = 0x239B; // parenlefttp (0xF8EB)
  15835. t[63724] = 0x239C; // parenleftex (0xF8EC)
  15836. t[63725] = 0x239D; // parenleftbt (0xF8ED)
  15837. t[63734] = 0x239E; // parenrighttp (0xF8F6)
  15838. t[63735] = 0x239F; // parenrightex (0xF8F7)
  15839. t[63736] = 0x23A0; // parenrightbt (0xF8F8)
  15840. });
  15841. function mapSpecialUnicodeValues(code) {
  15842. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  15843. return 0;
  15844. } else if (code >= 0xF600 && code <= 0xF8FF) {
  15845. return (getSpecialPUASymbols()[code] || code);
  15846. }
  15847. return code;
  15848. }
  15849. var UnicodeRanges = [
  15850. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  15851. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  15852. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  15853. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  15854. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  15855. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  15856. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  15857. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  15858. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  15859. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  15860. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  15861. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  15862. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  15863. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  15864. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  15865. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  15866. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  15867. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  15868. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  15869. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  15870. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  15871. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  15872. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  15873. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  15874. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  15875. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  15876. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  15877. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  15878. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  15879. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  15880. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  15881. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  15882. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  15883. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  15884. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks
  15885. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  15886. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  15887. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  15888. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  15889. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  15890. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  15891. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  15892. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  15893. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  15894. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  15895. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  15896. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  15897. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  15898. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  15899. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  15900. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  15901. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  15902. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  15903. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  15904. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  15905. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  15906. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  15907. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  15908. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  15909. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  15910. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  15911. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  15912. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  15913. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  15914. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  15915. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  15916. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  15917. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  15918. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  15919. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  15920. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  15921. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  15922. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  15923. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  15924. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  15925. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  15926. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  15927. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  15928. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  15929. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  15930. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  15931. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  15932. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  15933. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  15934. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  15935. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  15936. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  15937. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  15938. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  15939. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  15940. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  15941. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  15942. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  15943. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  15944. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  15945. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  15946. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  15947. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  15948. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  15949. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  15950. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  15951. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  15952. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  15953. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  15954. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  15955. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  15956. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  15957. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  15958. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  15959. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  15960. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  15961. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  15962. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  15963. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  15964. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  15965. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  15966. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  15967. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  15968. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  15969. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  15970. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  15971. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  15972. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  15973. ];
  15974. function getUnicodeRangeFor(value) {
  15975. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  15976. var range = UnicodeRanges[i];
  15977. if (value >= range.begin && value < range.end) {
  15978. return i;
  15979. }
  15980. }
  15981. return -1;
  15982. }
  15983. function isRTLRangeFor(value) {
  15984. var range = UnicodeRanges[13];
  15985. if (value >= range.begin && value < range.end) {
  15986. return true;
  15987. }
  15988. range = UnicodeRanges[11];
  15989. if (value >= range.begin && value < range.end) {
  15990. return true;
  15991. }
  15992. return false;
  15993. }
  15994. // The normalization table is obtained by filtering the Unicode characters
  15995. // database with <compat> entries.
  15996. var getNormalizedUnicodes = getLookupTableFactory(function (t) {
  15997. t['\u00A8'] = '\u0020\u0308';
  15998. t['\u00AF'] = '\u0020\u0304';
  15999. t['\u00B4'] = '\u0020\u0301';
  16000. t['\u00B5'] = '\u03BC';
  16001. t['\u00B8'] = '\u0020\u0327';
  16002. t['\u0132'] = '\u0049\u004A';
  16003. t['\u0133'] = '\u0069\u006A';
  16004. t['\u013F'] = '\u004C\u00B7';
  16005. t['\u0140'] = '\u006C\u00B7';
  16006. t['\u0149'] = '\u02BC\u006E';
  16007. t['\u017F'] = '\u0073';
  16008. t['\u01C4'] = '\u0044\u017D';
  16009. t['\u01C5'] = '\u0044\u017E';
  16010. t['\u01C6'] = '\u0064\u017E';
  16011. t['\u01C7'] = '\u004C\u004A';
  16012. t['\u01C8'] = '\u004C\u006A';
  16013. t['\u01C9'] = '\u006C\u006A';
  16014. t['\u01CA'] = '\u004E\u004A';
  16015. t['\u01CB'] = '\u004E\u006A';
  16016. t['\u01CC'] = '\u006E\u006A';
  16017. t['\u01F1'] = '\u0044\u005A';
  16018. t['\u01F2'] = '\u0044\u007A';
  16019. t['\u01F3'] = '\u0064\u007A';
  16020. t['\u02D8'] = '\u0020\u0306';
  16021. t['\u02D9'] = '\u0020\u0307';
  16022. t['\u02DA'] = '\u0020\u030A';
  16023. t['\u02DB'] = '\u0020\u0328';
  16024. t['\u02DC'] = '\u0020\u0303';
  16025. t['\u02DD'] = '\u0020\u030B';
  16026. t['\u037A'] = '\u0020\u0345';
  16027. t['\u0384'] = '\u0020\u0301';
  16028. t['\u03D0'] = '\u03B2';
  16029. t['\u03D1'] = '\u03B8';
  16030. t['\u03D2'] = '\u03A5';
  16031. t['\u03D5'] = '\u03C6';
  16032. t['\u03D6'] = '\u03C0';
  16033. t['\u03F0'] = '\u03BA';
  16034. t['\u03F1'] = '\u03C1';
  16035. t['\u03F2'] = '\u03C2';
  16036. t['\u03F4'] = '\u0398';
  16037. t['\u03F5'] = '\u03B5';
  16038. t['\u03F9'] = '\u03A3';
  16039. t['\u0587'] = '\u0565\u0582';
  16040. t['\u0675'] = '\u0627\u0674';
  16041. t['\u0676'] = '\u0648\u0674';
  16042. t['\u0677'] = '\u06C7\u0674';
  16043. t['\u0678'] = '\u064A\u0674';
  16044. t['\u0E33'] = '\u0E4D\u0E32';
  16045. t['\u0EB3'] = '\u0ECD\u0EB2';
  16046. t['\u0EDC'] = '\u0EAB\u0E99';
  16047. t['\u0EDD'] = '\u0EAB\u0EA1';
  16048. t['\u0F77'] = '\u0FB2\u0F81';
  16049. t['\u0F79'] = '\u0FB3\u0F81';
  16050. t['\u1E9A'] = '\u0061\u02BE';
  16051. t['\u1FBD'] = '\u0020\u0313';
  16052. t['\u1FBF'] = '\u0020\u0313';
  16053. t['\u1FC0'] = '\u0020\u0342';
  16054. t['\u1FFE'] = '\u0020\u0314';
  16055. t['\u2002'] = '\u0020';
  16056. t['\u2003'] = '\u0020';
  16057. t['\u2004'] = '\u0020';
  16058. t['\u2005'] = '\u0020';
  16059. t['\u2006'] = '\u0020';
  16060. t['\u2008'] = '\u0020';
  16061. t['\u2009'] = '\u0020';
  16062. t['\u200A'] = '\u0020';
  16063. t['\u2017'] = '\u0020\u0333';
  16064. t['\u2024'] = '\u002E';
  16065. t['\u2025'] = '\u002E\u002E';
  16066. t['\u2026'] = '\u002E\u002E\u002E';
  16067. t['\u2033'] = '\u2032\u2032';
  16068. t['\u2034'] = '\u2032\u2032\u2032';
  16069. t['\u2036'] = '\u2035\u2035';
  16070. t['\u2037'] = '\u2035\u2035\u2035';
  16071. t['\u203C'] = '\u0021\u0021';
  16072. t['\u203E'] = '\u0020\u0305';
  16073. t['\u2047'] = '\u003F\u003F';
  16074. t['\u2048'] = '\u003F\u0021';
  16075. t['\u2049'] = '\u0021\u003F';
  16076. t['\u2057'] = '\u2032\u2032\u2032\u2032';
  16077. t['\u205F'] = '\u0020';
  16078. t['\u20A8'] = '\u0052\u0073';
  16079. t['\u2100'] = '\u0061\u002F\u0063';
  16080. t['\u2101'] = '\u0061\u002F\u0073';
  16081. t['\u2103'] = '\u00B0\u0043';
  16082. t['\u2105'] = '\u0063\u002F\u006F';
  16083. t['\u2106'] = '\u0063\u002F\u0075';
  16084. t['\u2107'] = '\u0190';
  16085. t['\u2109'] = '\u00B0\u0046';
  16086. t['\u2116'] = '\u004E\u006F';
  16087. t['\u2121'] = '\u0054\u0045\u004C';
  16088. t['\u2135'] = '\u05D0';
  16089. t['\u2136'] = '\u05D1';
  16090. t['\u2137'] = '\u05D2';
  16091. t['\u2138'] = '\u05D3';
  16092. t['\u213B'] = '\u0046\u0041\u0058';
  16093. t['\u2160'] = '\u0049';
  16094. t['\u2161'] = '\u0049\u0049';
  16095. t['\u2162'] = '\u0049\u0049\u0049';
  16096. t['\u2163'] = '\u0049\u0056';
  16097. t['\u2164'] = '\u0056';
  16098. t['\u2165'] = '\u0056\u0049';
  16099. t['\u2166'] = '\u0056\u0049\u0049';
  16100. t['\u2167'] = '\u0056\u0049\u0049\u0049';
  16101. t['\u2168'] = '\u0049\u0058';
  16102. t['\u2169'] = '\u0058';
  16103. t['\u216A'] = '\u0058\u0049';
  16104. t['\u216B'] = '\u0058\u0049\u0049';
  16105. t['\u216C'] = '\u004C';
  16106. t['\u216D'] = '\u0043';
  16107. t['\u216E'] = '\u0044';
  16108. t['\u216F'] = '\u004D';
  16109. t['\u2170'] = '\u0069';
  16110. t['\u2171'] = '\u0069\u0069';
  16111. t['\u2172'] = '\u0069\u0069\u0069';
  16112. t['\u2173'] = '\u0069\u0076';
  16113. t['\u2174'] = '\u0076';
  16114. t['\u2175'] = '\u0076\u0069';
  16115. t['\u2176'] = '\u0076\u0069\u0069';
  16116. t['\u2177'] = '\u0076\u0069\u0069\u0069';
  16117. t['\u2178'] = '\u0069\u0078';
  16118. t['\u2179'] = '\u0078';
  16119. t['\u217A'] = '\u0078\u0069';
  16120. t['\u217B'] = '\u0078\u0069\u0069';
  16121. t['\u217C'] = '\u006C';
  16122. t['\u217D'] = '\u0063';
  16123. t['\u217E'] = '\u0064';
  16124. t['\u217F'] = '\u006D';
  16125. t['\u222C'] = '\u222B\u222B';
  16126. t['\u222D'] = '\u222B\u222B\u222B';
  16127. t['\u222F'] = '\u222E\u222E';
  16128. t['\u2230'] = '\u222E\u222E\u222E';
  16129. t['\u2474'] = '\u0028\u0031\u0029';
  16130. t['\u2475'] = '\u0028\u0032\u0029';
  16131. t['\u2476'] = '\u0028\u0033\u0029';
  16132. t['\u2477'] = '\u0028\u0034\u0029';
  16133. t['\u2478'] = '\u0028\u0035\u0029';
  16134. t['\u2479'] = '\u0028\u0036\u0029';
  16135. t['\u247A'] = '\u0028\u0037\u0029';
  16136. t['\u247B'] = '\u0028\u0038\u0029';
  16137. t['\u247C'] = '\u0028\u0039\u0029';
  16138. t['\u247D'] = '\u0028\u0031\u0030\u0029';
  16139. t['\u247E'] = '\u0028\u0031\u0031\u0029';
  16140. t['\u247F'] = '\u0028\u0031\u0032\u0029';
  16141. t['\u2480'] = '\u0028\u0031\u0033\u0029';
  16142. t['\u2481'] = '\u0028\u0031\u0034\u0029';
  16143. t['\u2482'] = '\u0028\u0031\u0035\u0029';
  16144. t['\u2483'] = '\u0028\u0031\u0036\u0029';
  16145. t['\u2484'] = '\u0028\u0031\u0037\u0029';
  16146. t['\u2485'] = '\u0028\u0031\u0038\u0029';
  16147. t['\u2486'] = '\u0028\u0031\u0039\u0029';
  16148. t['\u2487'] = '\u0028\u0032\u0030\u0029';
  16149. t['\u2488'] = '\u0031\u002E';
  16150. t['\u2489'] = '\u0032\u002E';
  16151. t['\u248A'] = '\u0033\u002E';
  16152. t['\u248B'] = '\u0034\u002E';
  16153. t['\u248C'] = '\u0035\u002E';
  16154. t['\u248D'] = '\u0036\u002E';
  16155. t['\u248E'] = '\u0037\u002E';
  16156. t['\u248F'] = '\u0038\u002E';
  16157. t['\u2490'] = '\u0039\u002E';
  16158. t['\u2491'] = '\u0031\u0030\u002E';
  16159. t['\u2492'] = '\u0031\u0031\u002E';
  16160. t['\u2493'] = '\u0031\u0032\u002E';
  16161. t['\u2494'] = '\u0031\u0033\u002E';
  16162. t['\u2495'] = '\u0031\u0034\u002E';
  16163. t['\u2496'] = '\u0031\u0035\u002E';
  16164. t['\u2497'] = '\u0031\u0036\u002E';
  16165. t['\u2498'] = '\u0031\u0037\u002E';
  16166. t['\u2499'] = '\u0031\u0038\u002E';
  16167. t['\u249A'] = '\u0031\u0039\u002E';
  16168. t['\u249B'] = '\u0032\u0030\u002E';
  16169. t['\u249C'] = '\u0028\u0061\u0029';
  16170. t['\u249D'] = '\u0028\u0062\u0029';
  16171. t['\u249E'] = '\u0028\u0063\u0029';
  16172. t['\u249F'] = '\u0028\u0064\u0029';
  16173. t['\u24A0'] = '\u0028\u0065\u0029';
  16174. t['\u24A1'] = '\u0028\u0066\u0029';
  16175. t['\u24A2'] = '\u0028\u0067\u0029';
  16176. t['\u24A3'] = '\u0028\u0068\u0029';
  16177. t['\u24A4'] = '\u0028\u0069\u0029';
  16178. t['\u24A5'] = '\u0028\u006A\u0029';
  16179. t['\u24A6'] = '\u0028\u006B\u0029';
  16180. t['\u24A7'] = '\u0028\u006C\u0029';
  16181. t['\u24A8'] = '\u0028\u006D\u0029';
  16182. t['\u24A9'] = '\u0028\u006E\u0029';
  16183. t['\u24AA'] = '\u0028\u006F\u0029';
  16184. t['\u24AB'] = '\u0028\u0070\u0029';
  16185. t['\u24AC'] = '\u0028\u0071\u0029';
  16186. t['\u24AD'] = '\u0028\u0072\u0029';
  16187. t['\u24AE'] = '\u0028\u0073\u0029';
  16188. t['\u24AF'] = '\u0028\u0074\u0029';
  16189. t['\u24B0'] = '\u0028\u0075\u0029';
  16190. t['\u24B1'] = '\u0028\u0076\u0029';
  16191. t['\u24B2'] = '\u0028\u0077\u0029';
  16192. t['\u24B3'] = '\u0028\u0078\u0029';
  16193. t['\u24B4'] = '\u0028\u0079\u0029';
  16194. t['\u24B5'] = '\u0028\u007A\u0029';
  16195. t['\u2A0C'] = '\u222B\u222B\u222B\u222B';
  16196. t['\u2A74'] = '\u003A\u003A\u003D';
  16197. t['\u2A75'] = '\u003D\u003D';
  16198. t['\u2A76'] = '\u003D\u003D\u003D';
  16199. t['\u2E9F'] = '\u6BCD';
  16200. t['\u2EF3'] = '\u9F9F';
  16201. t['\u2F00'] = '\u4E00';
  16202. t['\u2F01'] = '\u4E28';
  16203. t['\u2F02'] = '\u4E36';
  16204. t['\u2F03'] = '\u4E3F';
  16205. t['\u2F04'] = '\u4E59';
  16206. t['\u2F05'] = '\u4E85';
  16207. t['\u2F06'] = '\u4E8C';
  16208. t['\u2F07'] = '\u4EA0';
  16209. t['\u2F08'] = '\u4EBA';
  16210. t['\u2F09'] = '\u513F';
  16211. t['\u2F0A'] = '\u5165';
  16212. t['\u2F0B'] = '\u516B';
  16213. t['\u2F0C'] = '\u5182';
  16214. t['\u2F0D'] = '\u5196';
  16215. t['\u2F0E'] = '\u51AB';
  16216. t['\u2F0F'] = '\u51E0';
  16217. t['\u2F10'] = '\u51F5';
  16218. t['\u2F11'] = '\u5200';
  16219. t['\u2F12'] = '\u529B';
  16220. t['\u2F13'] = '\u52F9';
  16221. t['\u2F14'] = '\u5315';
  16222. t['\u2F15'] = '\u531A';
  16223. t['\u2F16'] = '\u5338';
  16224. t['\u2F17'] = '\u5341';
  16225. t['\u2F18'] = '\u535C';
  16226. t['\u2F19'] = '\u5369';
  16227. t['\u2F1A'] = '\u5382';
  16228. t['\u2F1B'] = '\u53B6';
  16229. t['\u2F1C'] = '\u53C8';
  16230. t['\u2F1D'] = '\u53E3';
  16231. t['\u2F1E'] = '\u56D7';
  16232. t['\u2F1F'] = '\u571F';
  16233. t['\u2F20'] = '\u58EB';
  16234. t['\u2F21'] = '\u5902';
  16235. t['\u2F22'] = '\u590A';
  16236. t['\u2F23'] = '\u5915';
  16237. t['\u2F24'] = '\u5927';
  16238. t['\u2F25'] = '\u5973';
  16239. t['\u2F26'] = '\u5B50';
  16240. t['\u2F27'] = '\u5B80';
  16241. t['\u2F28'] = '\u5BF8';
  16242. t['\u2F29'] = '\u5C0F';
  16243. t['\u2F2A'] = '\u5C22';
  16244. t['\u2F2B'] = '\u5C38';
  16245. t['\u2F2C'] = '\u5C6E';
  16246. t['\u2F2D'] = '\u5C71';
  16247. t['\u2F2E'] = '\u5DDB';
  16248. t['\u2F2F'] = '\u5DE5';
  16249. t['\u2F30'] = '\u5DF1';
  16250. t['\u2F31'] = '\u5DFE';
  16251. t['\u2F32'] = '\u5E72';
  16252. t['\u2F33'] = '\u5E7A';
  16253. t['\u2F34'] = '\u5E7F';
  16254. t['\u2F35'] = '\u5EF4';
  16255. t['\u2F36'] = '\u5EFE';
  16256. t['\u2F37'] = '\u5F0B';
  16257. t['\u2F38'] = '\u5F13';
  16258. t['\u2F39'] = '\u5F50';
  16259. t['\u2F3A'] = '\u5F61';
  16260. t['\u2F3B'] = '\u5F73';
  16261. t['\u2F3C'] = '\u5FC3';
  16262. t['\u2F3D'] = '\u6208';
  16263. t['\u2F3E'] = '\u6236';
  16264. t['\u2F3F'] = '\u624B';
  16265. t['\u2F40'] = '\u652F';
  16266. t['\u2F41'] = '\u6534';
  16267. t['\u2F42'] = '\u6587';
  16268. t['\u2F43'] = '\u6597';
  16269. t['\u2F44'] = '\u65A4';
  16270. t['\u2F45'] = '\u65B9';
  16271. t['\u2F46'] = '\u65E0';
  16272. t['\u2F47'] = '\u65E5';
  16273. t['\u2F48'] = '\u66F0';
  16274. t['\u2F49'] = '\u6708';
  16275. t['\u2F4A'] = '\u6728';
  16276. t['\u2F4B'] = '\u6B20';
  16277. t['\u2F4C'] = '\u6B62';
  16278. t['\u2F4D'] = '\u6B79';
  16279. t['\u2F4E'] = '\u6BB3';
  16280. t['\u2F4F'] = '\u6BCB';
  16281. t['\u2F50'] = '\u6BD4';
  16282. t['\u2F51'] = '\u6BDB';
  16283. t['\u2F52'] = '\u6C0F';
  16284. t['\u2F53'] = '\u6C14';
  16285. t['\u2F54'] = '\u6C34';
  16286. t['\u2F55'] = '\u706B';
  16287. t['\u2F56'] = '\u722A';
  16288. t['\u2F57'] = '\u7236';
  16289. t['\u2F58'] = '\u723B';
  16290. t['\u2F59'] = '\u723F';
  16291. t['\u2F5A'] = '\u7247';
  16292. t['\u2F5B'] = '\u7259';
  16293. t['\u2F5C'] = '\u725B';
  16294. t['\u2F5D'] = '\u72AC';
  16295. t['\u2F5E'] = '\u7384';
  16296. t['\u2F5F'] = '\u7389';
  16297. t['\u2F60'] = '\u74DC';
  16298. t['\u2F61'] = '\u74E6';
  16299. t['\u2F62'] = '\u7518';
  16300. t['\u2F63'] = '\u751F';
  16301. t['\u2F64'] = '\u7528';
  16302. t['\u2F65'] = '\u7530';
  16303. t['\u2F66'] = '\u758B';
  16304. t['\u2F67'] = '\u7592';
  16305. t['\u2F68'] = '\u7676';
  16306. t['\u2F69'] = '\u767D';
  16307. t['\u2F6A'] = '\u76AE';
  16308. t['\u2F6B'] = '\u76BF';
  16309. t['\u2F6C'] = '\u76EE';
  16310. t['\u2F6D'] = '\u77DB';
  16311. t['\u2F6E'] = '\u77E2';
  16312. t['\u2F6F'] = '\u77F3';
  16313. t['\u2F70'] = '\u793A';
  16314. t['\u2F71'] = '\u79B8';
  16315. t['\u2F72'] = '\u79BE';
  16316. t['\u2F73'] = '\u7A74';
  16317. t['\u2F74'] = '\u7ACB';
  16318. t['\u2F75'] = '\u7AF9';
  16319. t['\u2F76'] = '\u7C73';
  16320. t['\u2F77'] = '\u7CF8';
  16321. t['\u2F78'] = '\u7F36';
  16322. t['\u2F79'] = '\u7F51';
  16323. t['\u2F7A'] = '\u7F8A';
  16324. t['\u2F7B'] = '\u7FBD';
  16325. t['\u2F7C'] = '\u8001';
  16326. t['\u2F7D'] = '\u800C';
  16327. t['\u2F7E'] = '\u8012';
  16328. t['\u2F7F'] = '\u8033';
  16329. t['\u2F80'] = '\u807F';
  16330. t['\u2F81'] = '\u8089';
  16331. t['\u2F82'] = '\u81E3';
  16332. t['\u2F83'] = '\u81EA';
  16333. t['\u2F84'] = '\u81F3';
  16334. t['\u2F85'] = '\u81FC';
  16335. t['\u2F86'] = '\u820C';
  16336. t['\u2F87'] = '\u821B';
  16337. t['\u2F88'] = '\u821F';
  16338. t['\u2F89'] = '\u826E';
  16339. t['\u2F8A'] = '\u8272';
  16340. t['\u2F8B'] = '\u8278';
  16341. t['\u2F8C'] = '\u864D';
  16342. t['\u2F8D'] = '\u866B';
  16343. t['\u2F8E'] = '\u8840';
  16344. t['\u2F8F'] = '\u884C';
  16345. t['\u2F90'] = '\u8863';
  16346. t['\u2F91'] = '\u897E';
  16347. t['\u2F92'] = '\u898B';
  16348. t['\u2F93'] = '\u89D2';
  16349. t['\u2F94'] = '\u8A00';
  16350. t['\u2F95'] = '\u8C37';
  16351. t['\u2F96'] = '\u8C46';
  16352. t['\u2F97'] = '\u8C55';
  16353. t['\u2F98'] = '\u8C78';
  16354. t['\u2F99'] = '\u8C9D';
  16355. t['\u2F9A'] = '\u8D64';
  16356. t['\u2F9B'] = '\u8D70';
  16357. t['\u2F9C'] = '\u8DB3';
  16358. t['\u2F9D'] = '\u8EAB';
  16359. t['\u2F9E'] = '\u8ECA';
  16360. t['\u2F9F'] = '\u8F9B';
  16361. t['\u2FA0'] = '\u8FB0';
  16362. t['\u2FA1'] = '\u8FB5';
  16363. t['\u2FA2'] = '\u9091';
  16364. t['\u2FA3'] = '\u9149';
  16365. t['\u2FA4'] = '\u91C6';
  16366. t['\u2FA5'] = '\u91CC';
  16367. t['\u2FA6'] = '\u91D1';
  16368. t['\u2FA7'] = '\u9577';
  16369. t['\u2FA8'] = '\u9580';
  16370. t['\u2FA9'] = '\u961C';
  16371. t['\u2FAA'] = '\u96B6';
  16372. t['\u2FAB'] = '\u96B9';
  16373. t['\u2FAC'] = '\u96E8';
  16374. t['\u2FAD'] = '\u9751';
  16375. t['\u2FAE'] = '\u975E';
  16376. t['\u2FAF'] = '\u9762';
  16377. t['\u2FB0'] = '\u9769';
  16378. t['\u2FB1'] = '\u97CB';
  16379. t['\u2FB2'] = '\u97ED';
  16380. t['\u2FB3'] = '\u97F3';
  16381. t['\u2FB4'] = '\u9801';
  16382. t['\u2FB5'] = '\u98A8';
  16383. t['\u2FB6'] = '\u98DB';
  16384. t['\u2FB7'] = '\u98DF';
  16385. t['\u2FB8'] = '\u9996';
  16386. t['\u2FB9'] = '\u9999';
  16387. t['\u2FBA'] = '\u99AC';
  16388. t['\u2FBB'] = '\u9AA8';
  16389. t['\u2FBC'] = '\u9AD8';
  16390. t['\u2FBD'] = '\u9ADF';
  16391. t['\u2FBE'] = '\u9B25';
  16392. t['\u2FBF'] = '\u9B2F';
  16393. t['\u2FC0'] = '\u9B32';
  16394. t['\u2FC1'] = '\u9B3C';
  16395. t['\u2FC2'] = '\u9B5A';
  16396. t['\u2FC3'] = '\u9CE5';
  16397. t['\u2FC4'] = '\u9E75';
  16398. t['\u2FC5'] = '\u9E7F';
  16399. t['\u2FC6'] = '\u9EA5';
  16400. t['\u2FC7'] = '\u9EBB';
  16401. t['\u2FC8'] = '\u9EC3';
  16402. t['\u2FC9'] = '\u9ECD';
  16403. t['\u2FCA'] = '\u9ED1';
  16404. t['\u2FCB'] = '\u9EF9';
  16405. t['\u2FCC'] = '\u9EFD';
  16406. t['\u2FCD'] = '\u9F0E';
  16407. t['\u2FCE'] = '\u9F13';
  16408. t['\u2FCF'] = '\u9F20';
  16409. t['\u2FD0'] = '\u9F3B';
  16410. t['\u2FD1'] = '\u9F4A';
  16411. t['\u2FD2'] = '\u9F52';
  16412. t['\u2FD3'] = '\u9F8D';
  16413. t['\u2FD4'] = '\u9F9C';
  16414. t['\u2FD5'] = '\u9FA0';
  16415. t['\u3036'] = '\u3012';
  16416. t['\u3038'] = '\u5341';
  16417. t['\u3039'] = '\u5344';
  16418. t['\u303A'] = '\u5345';
  16419. t['\u309B'] = '\u0020\u3099';
  16420. t['\u309C'] = '\u0020\u309A';
  16421. t['\u3131'] = '\u1100';
  16422. t['\u3132'] = '\u1101';
  16423. t['\u3133'] = '\u11AA';
  16424. t['\u3134'] = '\u1102';
  16425. t['\u3135'] = '\u11AC';
  16426. t['\u3136'] = '\u11AD';
  16427. t['\u3137'] = '\u1103';
  16428. t['\u3138'] = '\u1104';
  16429. t['\u3139'] = '\u1105';
  16430. t['\u313A'] = '\u11B0';
  16431. t['\u313B'] = '\u11B1';
  16432. t['\u313C'] = '\u11B2';
  16433. t['\u313D'] = '\u11B3';
  16434. t['\u313E'] = '\u11B4';
  16435. t['\u313F'] = '\u11B5';
  16436. t['\u3140'] = '\u111A';
  16437. t['\u3141'] = '\u1106';
  16438. t['\u3142'] = '\u1107';
  16439. t['\u3143'] = '\u1108';
  16440. t['\u3144'] = '\u1121';
  16441. t['\u3145'] = '\u1109';
  16442. t['\u3146'] = '\u110A';
  16443. t['\u3147'] = '\u110B';
  16444. t['\u3148'] = '\u110C';
  16445. t['\u3149'] = '\u110D';
  16446. t['\u314A'] = '\u110E';
  16447. t['\u314B'] = '\u110F';
  16448. t['\u314C'] = '\u1110';
  16449. t['\u314D'] = '\u1111';
  16450. t['\u314E'] = '\u1112';
  16451. t['\u314F'] = '\u1161';
  16452. t['\u3150'] = '\u1162';
  16453. t['\u3151'] = '\u1163';
  16454. t['\u3152'] = '\u1164';
  16455. t['\u3153'] = '\u1165';
  16456. t['\u3154'] = '\u1166';
  16457. t['\u3155'] = '\u1167';
  16458. t['\u3156'] = '\u1168';
  16459. t['\u3157'] = '\u1169';
  16460. t['\u3158'] = '\u116A';
  16461. t['\u3159'] = '\u116B';
  16462. t['\u315A'] = '\u116C';
  16463. t['\u315B'] = '\u116D';
  16464. t['\u315C'] = '\u116E';
  16465. t['\u315D'] = '\u116F';
  16466. t['\u315E'] = '\u1170';
  16467. t['\u315F'] = '\u1171';
  16468. t['\u3160'] = '\u1172';
  16469. t['\u3161'] = '\u1173';
  16470. t['\u3162'] = '\u1174';
  16471. t['\u3163'] = '\u1175';
  16472. t['\u3164'] = '\u1160';
  16473. t['\u3165'] = '\u1114';
  16474. t['\u3166'] = '\u1115';
  16475. t['\u3167'] = '\u11C7';
  16476. t['\u3168'] = '\u11C8';
  16477. t['\u3169'] = '\u11CC';
  16478. t['\u316A'] = '\u11CE';
  16479. t['\u316B'] = '\u11D3';
  16480. t['\u316C'] = '\u11D7';
  16481. t['\u316D'] = '\u11D9';
  16482. t['\u316E'] = '\u111C';
  16483. t['\u316F'] = '\u11DD';
  16484. t['\u3170'] = '\u11DF';
  16485. t['\u3171'] = '\u111D';
  16486. t['\u3172'] = '\u111E';
  16487. t['\u3173'] = '\u1120';
  16488. t['\u3174'] = '\u1122';
  16489. t['\u3175'] = '\u1123';
  16490. t['\u3176'] = '\u1127';
  16491. t['\u3177'] = '\u1129';
  16492. t['\u3178'] = '\u112B';
  16493. t['\u3179'] = '\u112C';
  16494. t['\u317A'] = '\u112D';
  16495. t['\u317B'] = '\u112E';
  16496. t['\u317C'] = '\u112F';
  16497. t['\u317D'] = '\u1132';
  16498. t['\u317E'] = '\u1136';
  16499. t['\u317F'] = '\u1140';
  16500. t['\u3180'] = '\u1147';
  16501. t['\u3181'] = '\u114C';
  16502. t['\u3182'] = '\u11F1';
  16503. t['\u3183'] = '\u11F2';
  16504. t['\u3184'] = '\u1157';
  16505. t['\u3185'] = '\u1158';
  16506. t['\u3186'] = '\u1159';
  16507. t['\u3187'] = '\u1184';
  16508. t['\u3188'] = '\u1185';
  16509. t['\u3189'] = '\u1188';
  16510. t['\u318A'] = '\u1191';
  16511. t['\u318B'] = '\u1192';
  16512. t['\u318C'] = '\u1194';
  16513. t['\u318D'] = '\u119E';
  16514. t['\u318E'] = '\u11A1';
  16515. t['\u3200'] = '\u0028\u1100\u0029';
  16516. t['\u3201'] = '\u0028\u1102\u0029';
  16517. t['\u3202'] = '\u0028\u1103\u0029';
  16518. t['\u3203'] = '\u0028\u1105\u0029';
  16519. t['\u3204'] = '\u0028\u1106\u0029';
  16520. t['\u3205'] = '\u0028\u1107\u0029';
  16521. t['\u3206'] = '\u0028\u1109\u0029';
  16522. t['\u3207'] = '\u0028\u110B\u0029';
  16523. t['\u3208'] = '\u0028\u110C\u0029';
  16524. t['\u3209'] = '\u0028\u110E\u0029';
  16525. t['\u320A'] = '\u0028\u110F\u0029';
  16526. t['\u320B'] = '\u0028\u1110\u0029';
  16527. t['\u320C'] = '\u0028\u1111\u0029';
  16528. t['\u320D'] = '\u0028\u1112\u0029';
  16529. t['\u320E'] = '\u0028\u1100\u1161\u0029';
  16530. t['\u320F'] = '\u0028\u1102\u1161\u0029';
  16531. t['\u3210'] = '\u0028\u1103\u1161\u0029';
  16532. t['\u3211'] = '\u0028\u1105\u1161\u0029';
  16533. t['\u3212'] = '\u0028\u1106\u1161\u0029';
  16534. t['\u3213'] = '\u0028\u1107\u1161\u0029';
  16535. t['\u3214'] = '\u0028\u1109\u1161\u0029';
  16536. t['\u3215'] = '\u0028\u110B\u1161\u0029';
  16537. t['\u3216'] = '\u0028\u110C\u1161\u0029';
  16538. t['\u3217'] = '\u0028\u110E\u1161\u0029';
  16539. t['\u3218'] = '\u0028\u110F\u1161\u0029';
  16540. t['\u3219'] = '\u0028\u1110\u1161\u0029';
  16541. t['\u321A'] = '\u0028\u1111\u1161\u0029';
  16542. t['\u321B'] = '\u0028\u1112\u1161\u0029';
  16543. t['\u321C'] = '\u0028\u110C\u116E\u0029';
  16544. t['\u321D'] = '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029';
  16545. t['\u321E'] = '\u0028\u110B\u1169\u1112\u116E\u0029';
  16546. t['\u3220'] = '\u0028\u4E00\u0029';
  16547. t['\u3221'] = '\u0028\u4E8C\u0029';
  16548. t['\u3222'] = '\u0028\u4E09\u0029';
  16549. t['\u3223'] = '\u0028\u56DB\u0029';
  16550. t['\u3224'] = '\u0028\u4E94\u0029';
  16551. t['\u3225'] = '\u0028\u516D\u0029';
  16552. t['\u3226'] = '\u0028\u4E03\u0029';
  16553. t['\u3227'] = '\u0028\u516B\u0029';
  16554. t['\u3228'] = '\u0028\u4E5D\u0029';
  16555. t['\u3229'] = '\u0028\u5341\u0029';
  16556. t['\u322A'] = '\u0028\u6708\u0029';
  16557. t['\u322B'] = '\u0028\u706B\u0029';
  16558. t['\u322C'] = '\u0028\u6C34\u0029';
  16559. t['\u322D'] = '\u0028\u6728\u0029';
  16560. t['\u322E'] = '\u0028\u91D1\u0029';
  16561. t['\u322F'] = '\u0028\u571F\u0029';
  16562. t['\u3230'] = '\u0028\u65E5\u0029';
  16563. t['\u3231'] = '\u0028\u682A\u0029';
  16564. t['\u3232'] = '\u0028\u6709\u0029';
  16565. t['\u3233'] = '\u0028\u793E\u0029';
  16566. t['\u3234'] = '\u0028\u540D\u0029';
  16567. t['\u3235'] = '\u0028\u7279\u0029';
  16568. t['\u3236'] = '\u0028\u8CA1\u0029';
  16569. t['\u3237'] = '\u0028\u795D\u0029';
  16570. t['\u3238'] = '\u0028\u52B4\u0029';
  16571. t['\u3239'] = '\u0028\u4EE3\u0029';
  16572. t['\u323A'] = '\u0028\u547C\u0029';
  16573. t['\u323B'] = '\u0028\u5B66\u0029';
  16574. t['\u323C'] = '\u0028\u76E3\u0029';
  16575. t['\u323D'] = '\u0028\u4F01\u0029';
  16576. t['\u323E'] = '\u0028\u8CC7\u0029';
  16577. t['\u323F'] = '\u0028\u5354\u0029';
  16578. t['\u3240'] = '\u0028\u796D\u0029';
  16579. t['\u3241'] = '\u0028\u4F11\u0029';
  16580. t['\u3242'] = '\u0028\u81EA\u0029';
  16581. t['\u3243'] = '\u0028\u81F3\u0029';
  16582. t['\u32C0'] = '\u0031\u6708';
  16583. t['\u32C1'] = '\u0032\u6708';
  16584. t['\u32C2'] = '\u0033\u6708';
  16585. t['\u32C3'] = '\u0034\u6708';
  16586. t['\u32C4'] = '\u0035\u6708';
  16587. t['\u32C5'] = '\u0036\u6708';
  16588. t['\u32C6'] = '\u0037\u6708';
  16589. t['\u32C7'] = '\u0038\u6708';
  16590. t['\u32C8'] = '\u0039\u6708';
  16591. t['\u32C9'] = '\u0031\u0030\u6708';
  16592. t['\u32CA'] = '\u0031\u0031\u6708';
  16593. t['\u32CB'] = '\u0031\u0032\u6708';
  16594. t['\u3358'] = '\u0030\u70B9';
  16595. t['\u3359'] = '\u0031\u70B9';
  16596. t['\u335A'] = '\u0032\u70B9';
  16597. t['\u335B'] = '\u0033\u70B9';
  16598. t['\u335C'] = '\u0034\u70B9';
  16599. t['\u335D'] = '\u0035\u70B9';
  16600. t['\u335E'] = '\u0036\u70B9';
  16601. t['\u335F'] = '\u0037\u70B9';
  16602. t['\u3360'] = '\u0038\u70B9';
  16603. t['\u3361'] = '\u0039\u70B9';
  16604. t['\u3362'] = '\u0031\u0030\u70B9';
  16605. t['\u3363'] = '\u0031\u0031\u70B9';
  16606. t['\u3364'] = '\u0031\u0032\u70B9';
  16607. t['\u3365'] = '\u0031\u0033\u70B9';
  16608. t['\u3366'] = '\u0031\u0034\u70B9';
  16609. t['\u3367'] = '\u0031\u0035\u70B9';
  16610. t['\u3368'] = '\u0031\u0036\u70B9';
  16611. t['\u3369'] = '\u0031\u0037\u70B9';
  16612. t['\u336A'] = '\u0031\u0038\u70B9';
  16613. t['\u336B'] = '\u0031\u0039\u70B9';
  16614. t['\u336C'] = '\u0032\u0030\u70B9';
  16615. t['\u336D'] = '\u0032\u0031\u70B9';
  16616. t['\u336E'] = '\u0032\u0032\u70B9';
  16617. t['\u336F'] = '\u0032\u0033\u70B9';
  16618. t['\u3370'] = '\u0032\u0034\u70B9';
  16619. t['\u33E0'] = '\u0031\u65E5';
  16620. t['\u33E1'] = '\u0032\u65E5';
  16621. t['\u33E2'] = '\u0033\u65E5';
  16622. t['\u33E3'] = '\u0034\u65E5';
  16623. t['\u33E4'] = '\u0035\u65E5';
  16624. t['\u33E5'] = '\u0036\u65E5';
  16625. t['\u33E6'] = '\u0037\u65E5';
  16626. t['\u33E7'] = '\u0038\u65E5';
  16627. t['\u33E8'] = '\u0039\u65E5';
  16628. t['\u33E9'] = '\u0031\u0030\u65E5';
  16629. t['\u33EA'] = '\u0031\u0031\u65E5';
  16630. t['\u33EB'] = '\u0031\u0032\u65E5';
  16631. t['\u33EC'] = '\u0031\u0033\u65E5';
  16632. t['\u33ED'] = '\u0031\u0034\u65E5';
  16633. t['\u33EE'] = '\u0031\u0035\u65E5';
  16634. t['\u33EF'] = '\u0031\u0036\u65E5';
  16635. t['\u33F0'] = '\u0031\u0037\u65E5';
  16636. t['\u33F1'] = '\u0031\u0038\u65E5';
  16637. t['\u33F2'] = '\u0031\u0039\u65E5';
  16638. t['\u33F3'] = '\u0032\u0030\u65E5';
  16639. t['\u33F4'] = '\u0032\u0031\u65E5';
  16640. t['\u33F5'] = '\u0032\u0032\u65E5';
  16641. t['\u33F6'] = '\u0032\u0033\u65E5';
  16642. t['\u33F7'] = '\u0032\u0034\u65E5';
  16643. t['\u33F8'] = '\u0032\u0035\u65E5';
  16644. t['\u33F9'] = '\u0032\u0036\u65E5';
  16645. t['\u33FA'] = '\u0032\u0037\u65E5';
  16646. t['\u33FB'] = '\u0032\u0038\u65E5';
  16647. t['\u33FC'] = '\u0032\u0039\u65E5';
  16648. t['\u33FD'] = '\u0033\u0030\u65E5';
  16649. t['\u33FE'] = '\u0033\u0031\u65E5';
  16650. t['\uFB00'] = '\u0066\u0066';
  16651. t['\uFB01'] = '\u0066\u0069';
  16652. t['\uFB02'] = '\u0066\u006C';
  16653. t['\uFB03'] = '\u0066\u0066\u0069';
  16654. t['\uFB04'] = '\u0066\u0066\u006C';
  16655. t['\uFB05'] = '\u017F\u0074';
  16656. t['\uFB06'] = '\u0073\u0074';
  16657. t['\uFB13'] = '\u0574\u0576';
  16658. t['\uFB14'] = '\u0574\u0565';
  16659. t['\uFB15'] = '\u0574\u056B';
  16660. t['\uFB16'] = '\u057E\u0576';
  16661. t['\uFB17'] = '\u0574\u056D';
  16662. t['\uFB4F'] = '\u05D0\u05DC';
  16663. t['\uFB50'] = '\u0671';
  16664. t['\uFB51'] = '\u0671';
  16665. t['\uFB52'] = '\u067B';
  16666. t['\uFB53'] = '\u067B';
  16667. t['\uFB54'] = '\u067B';
  16668. t['\uFB55'] = '\u067B';
  16669. t['\uFB56'] = '\u067E';
  16670. t['\uFB57'] = '\u067E';
  16671. t['\uFB58'] = '\u067E';
  16672. t['\uFB59'] = '\u067E';
  16673. t['\uFB5A'] = '\u0680';
  16674. t['\uFB5B'] = '\u0680';
  16675. t['\uFB5C'] = '\u0680';
  16676. t['\uFB5D'] = '\u0680';
  16677. t['\uFB5E'] = '\u067A';
  16678. t['\uFB5F'] = '\u067A';
  16679. t['\uFB60'] = '\u067A';
  16680. t['\uFB61'] = '\u067A';
  16681. t['\uFB62'] = '\u067F';
  16682. t['\uFB63'] = '\u067F';
  16683. t['\uFB64'] = '\u067F';
  16684. t['\uFB65'] = '\u067F';
  16685. t['\uFB66'] = '\u0679';
  16686. t['\uFB67'] = '\u0679';
  16687. t['\uFB68'] = '\u0679';
  16688. t['\uFB69'] = '\u0679';
  16689. t['\uFB6A'] = '\u06A4';
  16690. t['\uFB6B'] = '\u06A4';
  16691. t['\uFB6C'] = '\u06A4';
  16692. t['\uFB6D'] = '\u06A4';
  16693. t['\uFB6E'] = '\u06A6';
  16694. t['\uFB6F'] = '\u06A6';
  16695. t['\uFB70'] = '\u06A6';
  16696. t['\uFB71'] = '\u06A6';
  16697. t['\uFB72'] = '\u0684';
  16698. t['\uFB73'] = '\u0684';
  16699. t['\uFB74'] = '\u0684';
  16700. t['\uFB75'] = '\u0684';
  16701. t['\uFB76'] = '\u0683';
  16702. t['\uFB77'] = '\u0683';
  16703. t['\uFB78'] = '\u0683';
  16704. t['\uFB79'] = '\u0683';
  16705. t['\uFB7A'] = '\u0686';
  16706. t['\uFB7B'] = '\u0686';
  16707. t['\uFB7C'] = '\u0686';
  16708. t['\uFB7D'] = '\u0686';
  16709. t['\uFB7E'] = '\u0687';
  16710. t['\uFB7F'] = '\u0687';
  16711. t['\uFB80'] = '\u0687';
  16712. t['\uFB81'] = '\u0687';
  16713. t['\uFB82'] = '\u068D';
  16714. t['\uFB83'] = '\u068D';
  16715. t['\uFB84'] = '\u068C';
  16716. t['\uFB85'] = '\u068C';
  16717. t['\uFB86'] = '\u068E';
  16718. t['\uFB87'] = '\u068E';
  16719. t['\uFB88'] = '\u0688';
  16720. t['\uFB89'] = '\u0688';
  16721. t['\uFB8A'] = '\u0698';
  16722. t['\uFB8B'] = '\u0698';
  16723. t['\uFB8C'] = '\u0691';
  16724. t['\uFB8D'] = '\u0691';
  16725. t['\uFB8E'] = '\u06A9';
  16726. t['\uFB8F'] = '\u06A9';
  16727. t['\uFB90'] = '\u06A9';
  16728. t['\uFB91'] = '\u06A9';
  16729. t['\uFB92'] = '\u06AF';
  16730. t['\uFB93'] = '\u06AF';
  16731. t['\uFB94'] = '\u06AF';
  16732. t['\uFB95'] = '\u06AF';
  16733. t['\uFB96'] = '\u06B3';
  16734. t['\uFB97'] = '\u06B3';
  16735. t['\uFB98'] = '\u06B3';
  16736. t['\uFB99'] = '\u06B3';
  16737. t['\uFB9A'] = '\u06B1';
  16738. t['\uFB9B'] = '\u06B1';
  16739. t['\uFB9C'] = '\u06B1';
  16740. t['\uFB9D'] = '\u06B1';
  16741. t['\uFB9E'] = '\u06BA';
  16742. t['\uFB9F'] = '\u06BA';
  16743. t['\uFBA0'] = '\u06BB';
  16744. t['\uFBA1'] = '\u06BB';
  16745. t['\uFBA2'] = '\u06BB';
  16746. t['\uFBA3'] = '\u06BB';
  16747. t['\uFBA4'] = '\u06C0';
  16748. t['\uFBA5'] = '\u06C0';
  16749. t['\uFBA6'] = '\u06C1';
  16750. t['\uFBA7'] = '\u06C1';
  16751. t['\uFBA8'] = '\u06C1';
  16752. t['\uFBA9'] = '\u06C1';
  16753. t['\uFBAA'] = '\u06BE';
  16754. t['\uFBAB'] = '\u06BE';
  16755. t['\uFBAC'] = '\u06BE';
  16756. t['\uFBAD'] = '\u06BE';
  16757. t['\uFBAE'] = '\u06D2';
  16758. t['\uFBAF'] = '\u06D2';
  16759. t['\uFBB0'] = '\u06D3';
  16760. t['\uFBB1'] = '\u06D3';
  16761. t['\uFBD3'] = '\u06AD';
  16762. t['\uFBD4'] = '\u06AD';
  16763. t['\uFBD5'] = '\u06AD';
  16764. t['\uFBD6'] = '\u06AD';
  16765. t['\uFBD7'] = '\u06C7';
  16766. t['\uFBD8'] = '\u06C7';
  16767. t['\uFBD9'] = '\u06C6';
  16768. t['\uFBDA'] = '\u06C6';
  16769. t['\uFBDB'] = '\u06C8';
  16770. t['\uFBDC'] = '\u06C8';
  16771. t['\uFBDD'] = '\u0677';
  16772. t['\uFBDE'] = '\u06CB';
  16773. t['\uFBDF'] = '\u06CB';
  16774. t['\uFBE0'] = '\u06C5';
  16775. t['\uFBE1'] = '\u06C5';
  16776. t['\uFBE2'] = '\u06C9';
  16777. t['\uFBE3'] = '\u06C9';
  16778. t['\uFBE4'] = '\u06D0';
  16779. t['\uFBE5'] = '\u06D0';
  16780. t['\uFBE6'] = '\u06D0';
  16781. t['\uFBE7'] = '\u06D0';
  16782. t['\uFBE8'] = '\u0649';
  16783. t['\uFBE9'] = '\u0649';
  16784. t['\uFBEA'] = '\u0626\u0627';
  16785. t['\uFBEB'] = '\u0626\u0627';
  16786. t['\uFBEC'] = '\u0626\u06D5';
  16787. t['\uFBED'] = '\u0626\u06D5';
  16788. t['\uFBEE'] = '\u0626\u0648';
  16789. t['\uFBEF'] = '\u0626\u0648';
  16790. t['\uFBF0'] = '\u0626\u06C7';
  16791. t['\uFBF1'] = '\u0626\u06C7';
  16792. t['\uFBF2'] = '\u0626\u06C6';
  16793. t['\uFBF3'] = '\u0626\u06C6';
  16794. t['\uFBF4'] = '\u0626\u06C8';
  16795. t['\uFBF5'] = '\u0626\u06C8';
  16796. t['\uFBF6'] = '\u0626\u06D0';
  16797. t['\uFBF7'] = '\u0626\u06D0';
  16798. t['\uFBF8'] = '\u0626\u06D0';
  16799. t['\uFBF9'] = '\u0626\u0649';
  16800. t['\uFBFA'] = '\u0626\u0649';
  16801. t['\uFBFB'] = '\u0626\u0649';
  16802. t['\uFBFC'] = '\u06CC';
  16803. t['\uFBFD'] = '\u06CC';
  16804. t['\uFBFE'] = '\u06CC';
  16805. t['\uFBFF'] = '\u06CC';
  16806. t['\uFC00'] = '\u0626\u062C';
  16807. t['\uFC01'] = '\u0626\u062D';
  16808. t['\uFC02'] = '\u0626\u0645';
  16809. t['\uFC03'] = '\u0626\u0649';
  16810. t['\uFC04'] = '\u0626\u064A';
  16811. t['\uFC05'] = '\u0628\u062C';
  16812. t['\uFC06'] = '\u0628\u062D';
  16813. t['\uFC07'] = '\u0628\u062E';
  16814. t['\uFC08'] = '\u0628\u0645';
  16815. t['\uFC09'] = '\u0628\u0649';
  16816. t['\uFC0A'] = '\u0628\u064A';
  16817. t['\uFC0B'] = '\u062A\u062C';
  16818. t['\uFC0C'] = '\u062A\u062D';
  16819. t['\uFC0D'] = '\u062A\u062E';
  16820. t['\uFC0E'] = '\u062A\u0645';
  16821. t['\uFC0F'] = '\u062A\u0649';
  16822. t['\uFC10'] = '\u062A\u064A';
  16823. t['\uFC11'] = '\u062B\u062C';
  16824. t['\uFC12'] = '\u062B\u0645';
  16825. t['\uFC13'] = '\u062B\u0649';
  16826. t['\uFC14'] = '\u062B\u064A';
  16827. t['\uFC15'] = '\u062C\u062D';
  16828. t['\uFC16'] = '\u062C\u0645';
  16829. t['\uFC17'] = '\u062D\u062C';
  16830. t['\uFC18'] = '\u062D\u0645';
  16831. t['\uFC19'] = '\u062E\u062C';
  16832. t['\uFC1A'] = '\u062E\u062D';
  16833. t['\uFC1B'] = '\u062E\u0645';
  16834. t['\uFC1C'] = '\u0633\u062C';
  16835. t['\uFC1D'] = '\u0633\u062D';
  16836. t['\uFC1E'] = '\u0633\u062E';
  16837. t['\uFC1F'] = '\u0633\u0645';
  16838. t['\uFC20'] = '\u0635\u062D';
  16839. t['\uFC21'] = '\u0635\u0645';
  16840. t['\uFC22'] = '\u0636\u062C';
  16841. t['\uFC23'] = '\u0636\u062D';
  16842. t['\uFC24'] = '\u0636\u062E';
  16843. t['\uFC25'] = '\u0636\u0645';
  16844. t['\uFC26'] = '\u0637\u062D';
  16845. t['\uFC27'] = '\u0637\u0645';
  16846. t['\uFC28'] = '\u0638\u0645';
  16847. t['\uFC29'] = '\u0639\u062C';
  16848. t['\uFC2A'] = '\u0639\u0645';
  16849. t['\uFC2B'] = '\u063A\u062C';
  16850. t['\uFC2C'] = '\u063A\u0645';
  16851. t['\uFC2D'] = '\u0641\u062C';
  16852. t['\uFC2E'] = '\u0641\u062D';
  16853. t['\uFC2F'] = '\u0641\u062E';
  16854. t['\uFC30'] = '\u0641\u0645';
  16855. t['\uFC31'] = '\u0641\u0649';
  16856. t['\uFC32'] = '\u0641\u064A';
  16857. t['\uFC33'] = '\u0642\u062D';
  16858. t['\uFC34'] = '\u0642\u0645';
  16859. t['\uFC35'] = '\u0642\u0649';
  16860. t['\uFC36'] = '\u0642\u064A';
  16861. t['\uFC37'] = '\u0643\u0627';
  16862. t['\uFC38'] = '\u0643\u062C';
  16863. t['\uFC39'] = '\u0643\u062D';
  16864. t['\uFC3A'] = '\u0643\u062E';
  16865. t['\uFC3B'] = '\u0643\u0644';
  16866. t['\uFC3C'] = '\u0643\u0645';
  16867. t['\uFC3D'] = '\u0643\u0649';
  16868. t['\uFC3E'] = '\u0643\u064A';
  16869. t['\uFC3F'] = '\u0644\u062C';
  16870. t['\uFC40'] = '\u0644\u062D';
  16871. t['\uFC41'] = '\u0644\u062E';
  16872. t['\uFC42'] = '\u0644\u0645';
  16873. t['\uFC43'] = '\u0644\u0649';
  16874. t['\uFC44'] = '\u0644\u064A';
  16875. t['\uFC45'] = '\u0645\u062C';
  16876. t['\uFC46'] = '\u0645\u062D';
  16877. t['\uFC47'] = '\u0645\u062E';
  16878. t['\uFC48'] = '\u0645\u0645';
  16879. t['\uFC49'] = '\u0645\u0649';
  16880. t['\uFC4A'] = '\u0645\u064A';
  16881. t['\uFC4B'] = '\u0646\u062C';
  16882. t['\uFC4C'] = '\u0646\u062D';
  16883. t['\uFC4D'] = '\u0646\u062E';
  16884. t['\uFC4E'] = '\u0646\u0645';
  16885. t['\uFC4F'] = '\u0646\u0649';
  16886. t['\uFC50'] = '\u0646\u064A';
  16887. t['\uFC51'] = '\u0647\u062C';
  16888. t['\uFC52'] = '\u0647\u0645';
  16889. t['\uFC53'] = '\u0647\u0649';
  16890. t['\uFC54'] = '\u0647\u064A';
  16891. t['\uFC55'] = '\u064A\u062C';
  16892. t['\uFC56'] = '\u064A\u062D';
  16893. t['\uFC57'] = '\u064A\u062E';
  16894. t['\uFC58'] = '\u064A\u0645';
  16895. t['\uFC59'] = '\u064A\u0649';
  16896. t['\uFC5A'] = '\u064A\u064A';
  16897. t['\uFC5B'] = '\u0630\u0670';
  16898. t['\uFC5C'] = '\u0631\u0670';
  16899. t['\uFC5D'] = '\u0649\u0670';
  16900. t['\uFC5E'] = '\u0020\u064C\u0651';
  16901. t['\uFC5F'] = '\u0020\u064D\u0651';
  16902. t['\uFC60'] = '\u0020\u064E\u0651';
  16903. t['\uFC61'] = '\u0020\u064F\u0651';
  16904. t['\uFC62'] = '\u0020\u0650\u0651';
  16905. t['\uFC63'] = '\u0020\u0651\u0670';
  16906. t['\uFC64'] = '\u0626\u0631';
  16907. t['\uFC65'] = '\u0626\u0632';
  16908. t['\uFC66'] = '\u0626\u0645';
  16909. t['\uFC67'] = '\u0626\u0646';
  16910. t['\uFC68'] = '\u0626\u0649';
  16911. t['\uFC69'] = '\u0626\u064A';
  16912. t['\uFC6A'] = '\u0628\u0631';
  16913. t['\uFC6B'] = '\u0628\u0632';
  16914. t['\uFC6C'] = '\u0628\u0645';
  16915. t['\uFC6D'] = '\u0628\u0646';
  16916. t['\uFC6E'] = '\u0628\u0649';
  16917. t['\uFC6F'] = '\u0628\u064A';
  16918. t['\uFC70'] = '\u062A\u0631';
  16919. t['\uFC71'] = '\u062A\u0632';
  16920. t['\uFC72'] = '\u062A\u0645';
  16921. t['\uFC73'] = '\u062A\u0646';
  16922. t['\uFC74'] = '\u062A\u0649';
  16923. t['\uFC75'] = '\u062A\u064A';
  16924. t['\uFC76'] = '\u062B\u0631';
  16925. t['\uFC77'] = '\u062B\u0632';
  16926. t['\uFC78'] = '\u062B\u0645';
  16927. t['\uFC79'] = '\u062B\u0646';
  16928. t['\uFC7A'] = '\u062B\u0649';
  16929. t['\uFC7B'] = '\u062B\u064A';
  16930. t['\uFC7C'] = '\u0641\u0649';
  16931. t['\uFC7D'] = '\u0641\u064A';
  16932. t['\uFC7E'] = '\u0642\u0649';
  16933. t['\uFC7F'] = '\u0642\u064A';
  16934. t['\uFC80'] = '\u0643\u0627';
  16935. t['\uFC81'] = '\u0643\u0644';
  16936. t['\uFC82'] = '\u0643\u0645';
  16937. t['\uFC83'] = '\u0643\u0649';
  16938. t['\uFC84'] = '\u0643\u064A';
  16939. t['\uFC85'] = '\u0644\u0645';
  16940. t['\uFC86'] = '\u0644\u0649';
  16941. t['\uFC87'] = '\u0644\u064A';
  16942. t['\uFC88'] = '\u0645\u0627';
  16943. t['\uFC89'] = '\u0645\u0645';
  16944. t['\uFC8A'] = '\u0646\u0631';
  16945. t['\uFC8B'] = '\u0646\u0632';
  16946. t['\uFC8C'] = '\u0646\u0645';
  16947. t['\uFC8D'] = '\u0646\u0646';
  16948. t['\uFC8E'] = '\u0646\u0649';
  16949. t['\uFC8F'] = '\u0646\u064A';
  16950. t['\uFC90'] = '\u0649\u0670';
  16951. t['\uFC91'] = '\u064A\u0631';
  16952. t['\uFC92'] = '\u064A\u0632';
  16953. t['\uFC93'] = '\u064A\u0645';
  16954. t['\uFC94'] = '\u064A\u0646';
  16955. t['\uFC95'] = '\u064A\u0649';
  16956. t['\uFC96'] = '\u064A\u064A';
  16957. t['\uFC97'] = '\u0626\u062C';
  16958. t['\uFC98'] = '\u0626\u062D';
  16959. t['\uFC99'] = '\u0626\u062E';
  16960. t['\uFC9A'] = '\u0626\u0645';
  16961. t['\uFC9B'] = '\u0626\u0647';
  16962. t['\uFC9C'] = '\u0628\u062C';
  16963. t['\uFC9D'] = '\u0628\u062D';
  16964. t['\uFC9E'] = '\u0628\u062E';
  16965. t['\uFC9F'] = '\u0628\u0645';
  16966. t['\uFCA0'] = '\u0628\u0647';
  16967. t['\uFCA1'] = '\u062A\u062C';
  16968. t['\uFCA2'] = '\u062A\u062D';
  16969. t['\uFCA3'] = '\u062A\u062E';
  16970. t['\uFCA4'] = '\u062A\u0645';
  16971. t['\uFCA5'] = '\u062A\u0647';
  16972. t['\uFCA6'] = '\u062B\u0645';
  16973. t['\uFCA7'] = '\u062C\u062D';
  16974. t['\uFCA8'] = '\u062C\u0645';
  16975. t['\uFCA9'] = '\u062D\u062C';
  16976. t['\uFCAA'] = '\u062D\u0645';
  16977. t['\uFCAB'] = '\u062E\u062C';
  16978. t['\uFCAC'] = '\u062E\u0645';
  16979. t['\uFCAD'] = '\u0633\u062C';
  16980. t['\uFCAE'] = '\u0633\u062D';
  16981. t['\uFCAF'] = '\u0633\u062E';
  16982. t['\uFCB0'] = '\u0633\u0645';
  16983. t['\uFCB1'] = '\u0635\u062D';
  16984. t['\uFCB2'] = '\u0635\u062E';
  16985. t['\uFCB3'] = '\u0635\u0645';
  16986. t['\uFCB4'] = '\u0636\u062C';
  16987. t['\uFCB5'] = '\u0636\u062D';
  16988. t['\uFCB6'] = '\u0636\u062E';
  16989. t['\uFCB7'] = '\u0636\u0645';
  16990. t['\uFCB8'] = '\u0637\u062D';
  16991. t['\uFCB9'] = '\u0638\u0645';
  16992. t['\uFCBA'] = '\u0639\u062C';
  16993. t['\uFCBB'] = '\u0639\u0645';
  16994. t['\uFCBC'] = '\u063A\u062C';
  16995. t['\uFCBD'] = '\u063A\u0645';
  16996. t['\uFCBE'] = '\u0641\u062C';
  16997. t['\uFCBF'] = '\u0641\u062D';
  16998. t['\uFCC0'] = '\u0641\u062E';
  16999. t['\uFCC1'] = '\u0641\u0645';
  17000. t['\uFCC2'] = '\u0642\u062D';
  17001. t['\uFCC3'] = '\u0642\u0645';
  17002. t['\uFCC4'] = '\u0643\u062C';
  17003. t['\uFCC5'] = '\u0643\u062D';
  17004. t['\uFCC6'] = '\u0643\u062E';
  17005. t['\uFCC7'] = '\u0643\u0644';
  17006. t['\uFCC8'] = '\u0643\u0645';
  17007. t['\uFCC9'] = '\u0644\u062C';
  17008. t['\uFCCA'] = '\u0644\u062D';
  17009. t['\uFCCB'] = '\u0644\u062E';
  17010. t['\uFCCC'] = '\u0644\u0645';
  17011. t['\uFCCD'] = '\u0644\u0647';
  17012. t['\uFCCE'] = '\u0645\u062C';
  17013. t['\uFCCF'] = '\u0645\u062D';
  17014. t['\uFCD0'] = '\u0645\u062E';
  17015. t['\uFCD1'] = '\u0645\u0645';
  17016. t['\uFCD2'] = '\u0646\u062C';
  17017. t['\uFCD3'] = '\u0646\u062D';
  17018. t['\uFCD4'] = '\u0646\u062E';
  17019. t['\uFCD5'] = '\u0646\u0645';
  17020. t['\uFCD6'] = '\u0646\u0647';
  17021. t['\uFCD7'] = '\u0647\u062C';
  17022. t['\uFCD8'] = '\u0647\u0645';
  17023. t['\uFCD9'] = '\u0647\u0670';
  17024. t['\uFCDA'] = '\u064A\u062C';
  17025. t['\uFCDB'] = '\u064A\u062D';
  17026. t['\uFCDC'] = '\u064A\u062E';
  17027. t['\uFCDD'] = '\u064A\u0645';
  17028. t['\uFCDE'] = '\u064A\u0647';
  17029. t['\uFCDF'] = '\u0626\u0645';
  17030. t['\uFCE0'] = '\u0626\u0647';
  17031. t['\uFCE1'] = '\u0628\u0645';
  17032. t['\uFCE2'] = '\u0628\u0647';
  17033. t['\uFCE3'] = '\u062A\u0645';
  17034. t['\uFCE4'] = '\u062A\u0647';
  17035. t['\uFCE5'] = '\u062B\u0645';
  17036. t['\uFCE6'] = '\u062B\u0647';
  17037. t['\uFCE7'] = '\u0633\u0645';
  17038. t['\uFCE8'] = '\u0633\u0647';
  17039. t['\uFCE9'] = '\u0634\u0645';
  17040. t['\uFCEA'] = '\u0634\u0647';
  17041. t['\uFCEB'] = '\u0643\u0644';
  17042. t['\uFCEC'] = '\u0643\u0645';
  17043. t['\uFCED'] = '\u0644\u0645';
  17044. t['\uFCEE'] = '\u0646\u0645';
  17045. t['\uFCEF'] = '\u0646\u0647';
  17046. t['\uFCF0'] = '\u064A\u0645';
  17047. t['\uFCF1'] = '\u064A\u0647';
  17048. t['\uFCF2'] = '\u0640\u064E\u0651';
  17049. t['\uFCF3'] = '\u0640\u064F\u0651';
  17050. t['\uFCF4'] = '\u0640\u0650\u0651';
  17051. t['\uFCF5'] = '\u0637\u0649';
  17052. t['\uFCF6'] = '\u0637\u064A';
  17053. t['\uFCF7'] = '\u0639\u0649';
  17054. t['\uFCF8'] = '\u0639\u064A';
  17055. t['\uFCF9'] = '\u063A\u0649';
  17056. t['\uFCFA'] = '\u063A\u064A';
  17057. t['\uFCFB'] = '\u0633\u0649';
  17058. t['\uFCFC'] = '\u0633\u064A';
  17059. t['\uFCFD'] = '\u0634\u0649';
  17060. t['\uFCFE'] = '\u0634\u064A';
  17061. t['\uFCFF'] = '\u062D\u0649';
  17062. t['\uFD00'] = '\u062D\u064A';
  17063. t['\uFD01'] = '\u062C\u0649';
  17064. t['\uFD02'] = '\u062C\u064A';
  17065. t['\uFD03'] = '\u062E\u0649';
  17066. t['\uFD04'] = '\u062E\u064A';
  17067. t['\uFD05'] = '\u0635\u0649';
  17068. t['\uFD06'] = '\u0635\u064A';
  17069. t['\uFD07'] = '\u0636\u0649';
  17070. t['\uFD08'] = '\u0636\u064A';
  17071. t['\uFD09'] = '\u0634\u062C';
  17072. t['\uFD0A'] = '\u0634\u062D';
  17073. t['\uFD0B'] = '\u0634\u062E';
  17074. t['\uFD0C'] = '\u0634\u0645';
  17075. t['\uFD0D'] = '\u0634\u0631';
  17076. t['\uFD0E'] = '\u0633\u0631';
  17077. t['\uFD0F'] = '\u0635\u0631';
  17078. t['\uFD10'] = '\u0636\u0631';
  17079. t['\uFD11'] = '\u0637\u0649';
  17080. t['\uFD12'] = '\u0637\u064A';
  17081. t['\uFD13'] = '\u0639\u0649';
  17082. t['\uFD14'] = '\u0639\u064A';
  17083. t['\uFD15'] = '\u063A\u0649';
  17084. t['\uFD16'] = '\u063A\u064A';
  17085. t['\uFD17'] = '\u0633\u0649';
  17086. t['\uFD18'] = '\u0633\u064A';
  17087. t['\uFD19'] = '\u0634\u0649';
  17088. t['\uFD1A'] = '\u0634\u064A';
  17089. t['\uFD1B'] = '\u062D\u0649';
  17090. t['\uFD1C'] = '\u062D\u064A';
  17091. t['\uFD1D'] = '\u062C\u0649';
  17092. t['\uFD1E'] = '\u062C\u064A';
  17093. t['\uFD1F'] = '\u062E\u0649';
  17094. t['\uFD20'] = '\u062E\u064A';
  17095. t['\uFD21'] = '\u0635\u0649';
  17096. t['\uFD22'] = '\u0635\u064A';
  17097. t['\uFD23'] = '\u0636\u0649';
  17098. t['\uFD24'] = '\u0636\u064A';
  17099. t['\uFD25'] = '\u0634\u062C';
  17100. t['\uFD26'] = '\u0634\u062D';
  17101. t['\uFD27'] = '\u0634\u062E';
  17102. t['\uFD28'] = '\u0634\u0645';
  17103. t['\uFD29'] = '\u0634\u0631';
  17104. t['\uFD2A'] = '\u0633\u0631';
  17105. t['\uFD2B'] = '\u0635\u0631';
  17106. t['\uFD2C'] = '\u0636\u0631';
  17107. t['\uFD2D'] = '\u0634\u062C';
  17108. t['\uFD2E'] = '\u0634\u062D';
  17109. t['\uFD2F'] = '\u0634\u062E';
  17110. t['\uFD30'] = '\u0634\u0645';
  17111. t['\uFD31'] = '\u0633\u0647';
  17112. t['\uFD32'] = '\u0634\u0647';
  17113. t['\uFD33'] = '\u0637\u0645';
  17114. t['\uFD34'] = '\u0633\u062C';
  17115. t['\uFD35'] = '\u0633\u062D';
  17116. t['\uFD36'] = '\u0633\u062E';
  17117. t['\uFD37'] = '\u0634\u062C';
  17118. t['\uFD38'] = '\u0634\u062D';
  17119. t['\uFD39'] = '\u0634\u062E';
  17120. t['\uFD3A'] = '\u0637\u0645';
  17121. t['\uFD3B'] = '\u0638\u0645';
  17122. t['\uFD3C'] = '\u0627\u064B';
  17123. t['\uFD3D'] = '\u0627\u064B';
  17124. t['\uFD50'] = '\u062A\u062C\u0645';
  17125. t['\uFD51'] = '\u062A\u062D\u062C';
  17126. t['\uFD52'] = '\u062A\u062D\u062C';
  17127. t['\uFD53'] = '\u062A\u062D\u0645';
  17128. t['\uFD54'] = '\u062A\u062E\u0645';
  17129. t['\uFD55'] = '\u062A\u0645\u062C';
  17130. t['\uFD56'] = '\u062A\u0645\u062D';
  17131. t['\uFD57'] = '\u062A\u0645\u062E';
  17132. t['\uFD58'] = '\u062C\u0645\u062D';
  17133. t['\uFD59'] = '\u062C\u0645\u062D';
  17134. t['\uFD5A'] = '\u062D\u0645\u064A';
  17135. t['\uFD5B'] = '\u062D\u0645\u0649';
  17136. t['\uFD5C'] = '\u0633\u062D\u062C';
  17137. t['\uFD5D'] = '\u0633\u062C\u062D';
  17138. t['\uFD5E'] = '\u0633\u062C\u0649';
  17139. t['\uFD5F'] = '\u0633\u0645\u062D';
  17140. t['\uFD60'] = '\u0633\u0645\u062D';
  17141. t['\uFD61'] = '\u0633\u0645\u062C';
  17142. t['\uFD62'] = '\u0633\u0645\u0645';
  17143. t['\uFD63'] = '\u0633\u0645\u0645';
  17144. t['\uFD64'] = '\u0635\u062D\u062D';
  17145. t['\uFD65'] = '\u0635\u062D\u062D';
  17146. t['\uFD66'] = '\u0635\u0645\u0645';
  17147. t['\uFD67'] = '\u0634\u062D\u0645';
  17148. t['\uFD68'] = '\u0634\u062D\u0645';
  17149. t['\uFD69'] = '\u0634\u062C\u064A';
  17150. t['\uFD6A'] = '\u0634\u0645\u062E';
  17151. t['\uFD6B'] = '\u0634\u0645\u062E';
  17152. t['\uFD6C'] = '\u0634\u0645\u0645';
  17153. t['\uFD6D'] = '\u0634\u0645\u0645';
  17154. t['\uFD6E'] = '\u0636\u062D\u0649';
  17155. t['\uFD6F'] = '\u0636\u062E\u0645';
  17156. t['\uFD70'] = '\u0636\u062E\u0645';
  17157. t['\uFD71'] = '\u0637\u0645\u062D';
  17158. t['\uFD72'] = '\u0637\u0645\u062D';
  17159. t['\uFD73'] = '\u0637\u0645\u0645';
  17160. t['\uFD74'] = '\u0637\u0645\u064A';
  17161. t['\uFD75'] = '\u0639\u062C\u0645';
  17162. t['\uFD76'] = '\u0639\u0645\u0645';
  17163. t['\uFD77'] = '\u0639\u0645\u0645';
  17164. t['\uFD78'] = '\u0639\u0645\u0649';
  17165. t['\uFD79'] = '\u063A\u0645\u0645';
  17166. t['\uFD7A'] = '\u063A\u0645\u064A';
  17167. t['\uFD7B'] = '\u063A\u0645\u0649';
  17168. t['\uFD7C'] = '\u0641\u062E\u0645';
  17169. t['\uFD7D'] = '\u0641\u062E\u0645';
  17170. t['\uFD7E'] = '\u0642\u0645\u062D';
  17171. t['\uFD7F'] = '\u0642\u0645\u0645';
  17172. t['\uFD80'] = '\u0644\u062D\u0645';
  17173. t['\uFD81'] = '\u0644\u062D\u064A';
  17174. t['\uFD82'] = '\u0644\u062D\u0649';
  17175. t['\uFD83'] = '\u0644\u062C\u062C';
  17176. t['\uFD84'] = '\u0644\u062C\u062C';
  17177. t['\uFD85'] = '\u0644\u062E\u0645';
  17178. t['\uFD86'] = '\u0644\u062E\u0645';
  17179. t['\uFD87'] = '\u0644\u0645\u062D';
  17180. t['\uFD88'] = '\u0644\u0645\u062D';
  17181. t['\uFD89'] = '\u0645\u062D\u062C';
  17182. t['\uFD8A'] = '\u0645\u062D\u0645';
  17183. t['\uFD8B'] = '\u0645\u062D\u064A';
  17184. t['\uFD8C'] = '\u0645\u062C\u062D';
  17185. t['\uFD8D'] = '\u0645\u062C\u0645';
  17186. t['\uFD8E'] = '\u0645\u062E\u062C';
  17187. t['\uFD8F'] = '\u0645\u062E\u0645';
  17188. t['\uFD92'] = '\u0645\u062C\u062E';
  17189. t['\uFD93'] = '\u0647\u0645\u062C';
  17190. t['\uFD94'] = '\u0647\u0645\u0645';
  17191. t['\uFD95'] = '\u0646\u062D\u0645';
  17192. t['\uFD96'] = '\u0646\u062D\u0649';
  17193. t['\uFD97'] = '\u0646\u062C\u0645';
  17194. t['\uFD98'] = '\u0646\u062C\u0645';
  17195. t['\uFD99'] = '\u0646\u062C\u0649';
  17196. t['\uFD9A'] = '\u0646\u0645\u064A';
  17197. t['\uFD9B'] = '\u0646\u0645\u0649';
  17198. t['\uFD9C'] = '\u064A\u0645\u0645';
  17199. t['\uFD9D'] = '\u064A\u0645\u0645';
  17200. t['\uFD9E'] = '\u0628\u062E\u064A';
  17201. t['\uFD9F'] = '\u062A\u062C\u064A';
  17202. t['\uFDA0'] = '\u062A\u062C\u0649';
  17203. t['\uFDA1'] = '\u062A\u062E\u064A';
  17204. t['\uFDA2'] = '\u062A\u062E\u0649';
  17205. t['\uFDA3'] = '\u062A\u0645\u064A';
  17206. t['\uFDA4'] = '\u062A\u0645\u0649';
  17207. t['\uFDA5'] = '\u062C\u0645\u064A';
  17208. t['\uFDA6'] = '\u062C\u062D\u0649';
  17209. t['\uFDA7'] = '\u062C\u0645\u0649';
  17210. t['\uFDA8'] = '\u0633\u062E\u0649';
  17211. t['\uFDA9'] = '\u0635\u062D\u064A';
  17212. t['\uFDAA'] = '\u0634\u062D\u064A';
  17213. t['\uFDAB'] = '\u0636\u062D\u064A';
  17214. t['\uFDAC'] = '\u0644\u062C\u064A';
  17215. t['\uFDAD'] = '\u0644\u0645\u064A';
  17216. t['\uFDAE'] = '\u064A\u062D\u064A';
  17217. t['\uFDAF'] = '\u064A\u062C\u064A';
  17218. t['\uFDB0'] = '\u064A\u0645\u064A';
  17219. t['\uFDB1'] = '\u0645\u0645\u064A';
  17220. t['\uFDB2'] = '\u0642\u0645\u064A';
  17221. t['\uFDB3'] = '\u0646\u062D\u064A';
  17222. t['\uFDB4'] = '\u0642\u0645\u062D';
  17223. t['\uFDB5'] = '\u0644\u062D\u0645';
  17224. t['\uFDB6'] = '\u0639\u0645\u064A';
  17225. t['\uFDB7'] = '\u0643\u0645\u064A';
  17226. t['\uFDB8'] = '\u0646\u062C\u062D';
  17227. t['\uFDB9'] = '\u0645\u062E\u064A';
  17228. t['\uFDBA'] = '\u0644\u062C\u0645';
  17229. t['\uFDBB'] = '\u0643\u0645\u0645';
  17230. t['\uFDBC'] = '\u0644\u062C\u0645';
  17231. t['\uFDBD'] = '\u0646\u062C\u062D';
  17232. t['\uFDBE'] = '\u062C\u062D\u064A';
  17233. t['\uFDBF'] = '\u062D\u062C\u064A';
  17234. t['\uFDC0'] = '\u0645\u062C\u064A';
  17235. t['\uFDC1'] = '\u0641\u0645\u064A';
  17236. t['\uFDC2'] = '\u0628\u062D\u064A';
  17237. t['\uFDC3'] = '\u0643\u0645\u0645';
  17238. t['\uFDC4'] = '\u0639\u062C\u0645';
  17239. t['\uFDC5'] = '\u0635\u0645\u0645';
  17240. t['\uFDC6'] = '\u0633\u062E\u064A';
  17241. t['\uFDC7'] = '\u0646\u062C\u064A';
  17242. t['\uFE49'] = '\u203E';
  17243. t['\uFE4A'] = '\u203E';
  17244. t['\uFE4B'] = '\u203E';
  17245. t['\uFE4C'] = '\u203E';
  17246. t['\uFE4D'] = '\u005F';
  17247. t['\uFE4E'] = '\u005F';
  17248. t['\uFE4F'] = '\u005F';
  17249. t['\uFE80'] = '\u0621';
  17250. t['\uFE81'] = '\u0622';
  17251. t['\uFE82'] = '\u0622';
  17252. t['\uFE83'] = '\u0623';
  17253. t['\uFE84'] = '\u0623';
  17254. t['\uFE85'] = '\u0624';
  17255. t['\uFE86'] = '\u0624';
  17256. t['\uFE87'] = '\u0625';
  17257. t['\uFE88'] = '\u0625';
  17258. t['\uFE89'] = '\u0626';
  17259. t['\uFE8A'] = '\u0626';
  17260. t['\uFE8B'] = '\u0626';
  17261. t['\uFE8C'] = '\u0626';
  17262. t['\uFE8D'] = '\u0627';
  17263. t['\uFE8E'] = '\u0627';
  17264. t['\uFE8F'] = '\u0628';
  17265. t['\uFE90'] = '\u0628';
  17266. t['\uFE91'] = '\u0628';
  17267. t['\uFE92'] = '\u0628';
  17268. t['\uFE93'] = '\u0629';
  17269. t['\uFE94'] = '\u0629';
  17270. t['\uFE95'] = '\u062A';
  17271. t['\uFE96'] = '\u062A';
  17272. t['\uFE97'] = '\u062A';
  17273. t['\uFE98'] = '\u062A';
  17274. t['\uFE99'] = '\u062B';
  17275. t['\uFE9A'] = '\u062B';
  17276. t['\uFE9B'] = '\u062B';
  17277. t['\uFE9C'] = '\u062B';
  17278. t['\uFE9D'] = '\u062C';
  17279. t['\uFE9E'] = '\u062C';
  17280. t['\uFE9F'] = '\u062C';
  17281. t['\uFEA0'] = '\u062C';
  17282. t['\uFEA1'] = '\u062D';
  17283. t['\uFEA2'] = '\u062D';
  17284. t['\uFEA3'] = '\u062D';
  17285. t['\uFEA4'] = '\u062D';
  17286. t['\uFEA5'] = '\u062E';
  17287. t['\uFEA6'] = '\u062E';
  17288. t['\uFEA7'] = '\u062E';
  17289. t['\uFEA8'] = '\u062E';
  17290. t['\uFEA9'] = '\u062F';
  17291. t['\uFEAA'] = '\u062F';
  17292. t['\uFEAB'] = '\u0630';
  17293. t['\uFEAC'] = '\u0630';
  17294. t['\uFEAD'] = '\u0631';
  17295. t['\uFEAE'] = '\u0631';
  17296. t['\uFEAF'] = '\u0632';
  17297. t['\uFEB0'] = '\u0632';
  17298. t['\uFEB1'] = '\u0633';
  17299. t['\uFEB2'] = '\u0633';
  17300. t['\uFEB3'] = '\u0633';
  17301. t['\uFEB4'] = '\u0633';
  17302. t['\uFEB5'] = '\u0634';
  17303. t['\uFEB6'] = '\u0634';
  17304. t['\uFEB7'] = '\u0634';
  17305. t['\uFEB8'] = '\u0634';
  17306. t['\uFEB9'] = '\u0635';
  17307. t['\uFEBA'] = '\u0635';
  17308. t['\uFEBB'] = '\u0635';
  17309. t['\uFEBC'] = '\u0635';
  17310. t['\uFEBD'] = '\u0636';
  17311. t['\uFEBE'] = '\u0636';
  17312. t['\uFEBF'] = '\u0636';
  17313. t['\uFEC0'] = '\u0636';
  17314. t['\uFEC1'] = '\u0637';
  17315. t['\uFEC2'] = '\u0637';
  17316. t['\uFEC3'] = '\u0637';
  17317. t['\uFEC4'] = '\u0637';
  17318. t['\uFEC5'] = '\u0638';
  17319. t['\uFEC6'] = '\u0638';
  17320. t['\uFEC7'] = '\u0638';
  17321. t['\uFEC8'] = '\u0638';
  17322. t['\uFEC9'] = '\u0639';
  17323. t['\uFECA'] = '\u0639';
  17324. t['\uFECB'] = '\u0639';
  17325. t['\uFECC'] = '\u0639';
  17326. t['\uFECD'] = '\u063A';
  17327. t['\uFECE'] = '\u063A';
  17328. t['\uFECF'] = '\u063A';
  17329. t['\uFED0'] = '\u063A';
  17330. t['\uFED1'] = '\u0641';
  17331. t['\uFED2'] = '\u0641';
  17332. t['\uFED3'] = '\u0641';
  17333. t['\uFED4'] = '\u0641';
  17334. t['\uFED5'] = '\u0642';
  17335. t['\uFED6'] = '\u0642';
  17336. t['\uFED7'] = '\u0642';
  17337. t['\uFED8'] = '\u0642';
  17338. t['\uFED9'] = '\u0643';
  17339. t['\uFEDA'] = '\u0643';
  17340. t['\uFEDB'] = '\u0643';
  17341. t['\uFEDC'] = '\u0643';
  17342. t['\uFEDD'] = '\u0644';
  17343. t['\uFEDE'] = '\u0644';
  17344. t['\uFEDF'] = '\u0644';
  17345. t['\uFEE0'] = '\u0644';
  17346. t['\uFEE1'] = '\u0645';
  17347. t['\uFEE2'] = '\u0645';
  17348. t['\uFEE3'] = '\u0645';
  17349. t['\uFEE4'] = '\u0645';
  17350. t['\uFEE5'] = '\u0646';
  17351. t['\uFEE6'] = '\u0646';
  17352. t['\uFEE7'] = '\u0646';
  17353. t['\uFEE8'] = '\u0646';
  17354. t['\uFEE9'] = '\u0647';
  17355. t['\uFEEA'] = '\u0647';
  17356. t['\uFEEB'] = '\u0647';
  17357. t['\uFEEC'] = '\u0647';
  17358. t['\uFEED'] = '\u0648';
  17359. t['\uFEEE'] = '\u0648';
  17360. t['\uFEEF'] = '\u0649';
  17361. t['\uFEF0'] = '\u0649';
  17362. t['\uFEF1'] = '\u064A';
  17363. t['\uFEF2'] = '\u064A';
  17364. t['\uFEF3'] = '\u064A';
  17365. t['\uFEF4'] = '\u064A';
  17366. t['\uFEF5'] = '\u0644\u0622';
  17367. t['\uFEF6'] = '\u0644\u0622';
  17368. t['\uFEF7'] = '\u0644\u0623';
  17369. t['\uFEF8'] = '\u0644\u0623';
  17370. t['\uFEF9'] = '\u0644\u0625';
  17371. t['\uFEFA'] = '\u0644\u0625';
  17372. t['\uFEFB'] = '\u0644\u0627';
  17373. t['\uFEFC'] = '\u0644\u0627';
  17374. });
  17375. function reverseIfRtl(chars) {
  17376. var charsLength = chars.length;
  17377. //reverse an arabic ligature
  17378. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  17379. return chars;
  17380. }
  17381. var s = '';
  17382. for (var ii = charsLength - 1; ii >= 0; ii--) {
  17383. s += chars[ii];
  17384. }
  17385. return s;
  17386. }
  17387. exports.mapSpecialUnicodeValues = mapSpecialUnicodeValues;
  17388. exports.reverseIfRtl = reverseIfRtl;
  17389. exports.getUnicodeRangeFor = getUnicodeRangeFor;
  17390. exports.getNormalizedUnicodes = getNormalizedUnicodes;
  17391. }));
  17392. (function (root, factory) {
  17393. {
  17394. factory((root.pdfjsCoreStream = {}), root.pdfjsSharedUtil,
  17395. root.pdfjsCorePrimitives, root.pdfjsCoreJbig2, root.pdfjsCoreJpg,
  17396. root.pdfjsCoreJpx);
  17397. }
  17398. }(this, function (exports, sharedUtil, corePrimitives, coreJbig2, coreJpg,
  17399. coreJpx) {
  17400. var Util = sharedUtil.Util;
  17401. var error = sharedUtil.error;
  17402. var info = sharedUtil.info;
  17403. var isArray = sharedUtil.isArray;
  17404. var shadow = sharedUtil.shadow;
  17405. var warn = sharedUtil.warn;
  17406. var Dict = corePrimitives.Dict;
  17407. var Jbig2Image = coreJbig2.Jbig2Image;
  17408. var JpegImage = coreJpg.JpegImage;
  17409. var JpxImage = coreJpx.JpxImage;
  17410. var coreParser; // see _setCoreParser below
  17411. var EOF; // = coreParser.EOF;
  17412. var Lexer; // = coreParser.Lexer;
  17413. var coreColorSpace; // see _setCoreColorSpace below
  17414. var ColorSpace; // = coreColorSpace.ColorSpace;
  17415. var Stream = (function StreamClosure() {
  17416. function Stream(arrayBuffer, start, length, dict) {
  17417. this.bytes = (arrayBuffer instanceof Uint8Array ?
  17418. arrayBuffer : new Uint8Array(arrayBuffer));
  17419. this.start = start || 0;
  17420. this.pos = this.start;
  17421. this.end = (start + length) || this.bytes.length;
  17422. this.dict = dict;
  17423. }
  17424. // required methods for a stream. if a particular stream does not
  17425. // implement these, an error should be thrown
  17426. Stream.prototype = {
  17427. get length() {
  17428. return this.end - this.start;
  17429. },
  17430. get isEmpty() {
  17431. return this.length === 0;
  17432. },
  17433. getByte: function Stream_getByte() {
  17434. if (this.pos >= this.end) {
  17435. return -1;
  17436. }
  17437. return this.bytes[this.pos++];
  17438. },
  17439. getUint16: function Stream_getUint16() {
  17440. var b0 = this.getByte();
  17441. var b1 = this.getByte();
  17442. if (b0 === -1 || b1 === -1) {
  17443. return -1;
  17444. }
  17445. return (b0 << 8) + b1;
  17446. },
  17447. getInt32: function Stream_getInt32() {
  17448. var b0 = this.getByte();
  17449. var b1 = this.getByte();
  17450. var b2 = this.getByte();
  17451. var b3 = this.getByte();
  17452. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  17453. },
  17454. // returns subarray of original buffer
  17455. // should only be read
  17456. getBytes: function Stream_getBytes(length) {
  17457. var bytes = this.bytes;
  17458. var pos = this.pos;
  17459. var strEnd = this.end;
  17460. if (!length) {
  17461. return bytes.subarray(pos, strEnd);
  17462. }
  17463. var end = pos + length;
  17464. if (end > strEnd) {
  17465. end = strEnd;
  17466. }
  17467. this.pos = end;
  17468. return bytes.subarray(pos, end);
  17469. },
  17470. peekByte: function Stream_peekByte() {
  17471. var peekedByte = this.getByte();
  17472. this.pos--;
  17473. return peekedByte;
  17474. },
  17475. peekBytes: function Stream_peekBytes(length) {
  17476. var bytes = this.getBytes(length);
  17477. this.pos -= bytes.length;
  17478. return bytes;
  17479. },
  17480. skip: function Stream_skip(n) {
  17481. if (!n) {
  17482. n = 1;
  17483. }
  17484. this.pos += n;
  17485. },
  17486. reset: function Stream_reset() {
  17487. this.pos = this.start;
  17488. },
  17489. moveStart: function Stream_moveStart() {
  17490. this.start = this.pos;
  17491. },
  17492. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  17493. return new Stream(this.bytes.buffer, start, length, dict);
  17494. },
  17495. isStream: true
  17496. };
  17497. return Stream;
  17498. })();
  17499. var StringStream = (function StringStreamClosure() {
  17500. function StringStream(str) {
  17501. var length = str.length;
  17502. var bytes = new Uint8Array(length);
  17503. for (var n = 0; n < length; ++n) {
  17504. bytes[n] = str.charCodeAt(n);
  17505. }
  17506. Stream.call(this, bytes);
  17507. }
  17508. StringStream.prototype = Stream.prototype;
  17509. return StringStream;
  17510. })();
  17511. // super class for the decoding streams
  17512. var DecodeStream = (function DecodeStreamClosure() {
  17513. // Lots of DecodeStreams are created whose buffers are never used. For these
  17514. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  17515. // having special cases that would be required if we used |null| for an empty
  17516. // buffer.
  17517. var emptyBuffer = new Uint8Array(0);
  17518. function DecodeStream(maybeMinBufferLength) {
  17519. this.pos = 0;
  17520. this.bufferLength = 0;
  17521. this.eof = false;
  17522. this.buffer = emptyBuffer;
  17523. this.minBufferLength = 512;
  17524. if (maybeMinBufferLength) {
  17525. // Compute the first power of two that is as big as maybeMinBufferLength.
  17526. while (this.minBufferLength < maybeMinBufferLength) {
  17527. this.minBufferLength *= 2;
  17528. }
  17529. }
  17530. }
  17531. DecodeStream.prototype = {
  17532. get isEmpty() {
  17533. while (!this.eof && this.bufferLength === 0) {
  17534. this.readBlock();
  17535. }
  17536. return this.bufferLength === 0;
  17537. },
  17538. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  17539. var buffer = this.buffer;
  17540. if (requested <= buffer.byteLength) {
  17541. return buffer;
  17542. }
  17543. var size = this.minBufferLength;
  17544. while (size < requested) {
  17545. size *= 2;
  17546. }
  17547. var buffer2 = new Uint8Array(size);
  17548. buffer2.set(buffer);
  17549. return (this.buffer = buffer2);
  17550. },
  17551. getByte: function DecodeStream_getByte() {
  17552. var pos = this.pos;
  17553. while (this.bufferLength <= pos) {
  17554. if (this.eof) {
  17555. return -1;
  17556. }
  17557. this.readBlock();
  17558. }
  17559. return this.buffer[this.pos++];
  17560. },
  17561. getUint16: function DecodeStream_getUint16() {
  17562. var b0 = this.getByte();
  17563. var b1 = this.getByte();
  17564. if (b0 === -1 || b1 === -1) {
  17565. return -1;
  17566. }
  17567. return (b0 << 8) + b1;
  17568. },
  17569. getInt32: function DecodeStream_getInt32() {
  17570. var b0 = this.getByte();
  17571. var b1 = this.getByte();
  17572. var b2 = this.getByte();
  17573. var b3 = this.getByte();
  17574. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  17575. },
  17576. getBytes: function DecodeStream_getBytes(length) {
  17577. var end, pos = this.pos;
  17578. if (length) {
  17579. this.ensureBuffer(pos + length);
  17580. end = pos + length;
  17581. while (!this.eof && this.bufferLength < end) {
  17582. this.readBlock();
  17583. }
  17584. var bufEnd = this.bufferLength;
  17585. if (end > bufEnd) {
  17586. end = bufEnd;
  17587. }
  17588. } else {
  17589. while (!this.eof) {
  17590. this.readBlock();
  17591. }
  17592. end = this.bufferLength;
  17593. }
  17594. this.pos = end;
  17595. return this.buffer.subarray(pos, end);
  17596. },
  17597. peekByte: function DecodeStream_peekByte() {
  17598. var peekedByte = this.getByte();
  17599. this.pos--;
  17600. return peekedByte;
  17601. },
  17602. peekBytes: function DecodeStream_peekBytes(length) {
  17603. var bytes = this.getBytes(length);
  17604. this.pos -= bytes.length;
  17605. return bytes;
  17606. },
  17607. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  17608. var end = start + length;
  17609. while (this.bufferLength <= end && !this.eof) {
  17610. this.readBlock();
  17611. }
  17612. return new Stream(this.buffer, start, length, dict);
  17613. },
  17614. skip: function DecodeStream_skip(n) {
  17615. if (!n) {
  17616. n = 1;
  17617. }
  17618. this.pos += n;
  17619. },
  17620. reset: function DecodeStream_reset() {
  17621. this.pos = 0;
  17622. },
  17623. getBaseStreams: function DecodeStream_getBaseStreams() {
  17624. if (this.str && this.str.getBaseStreams) {
  17625. return this.str.getBaseStreams();
  17626. }
  17627. return [];
  17628. }
  17629. };
  17630. return DecodeStream;
  17631. })();
  17632. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  17633. function StreamsSequenceStream(streams) {
  17634. this.streams = streams;
  17635. DecodeStream.call(this, /* maybeLength = */ null);
  17636. }
  17637. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  17638. StreamsSequenceStream.prototype.readBlock =
  17639. function streamSequenceStreamReadBlock() {
  17640. var streams = this.streams;
  17641. if (streams.length === 0) {
  17642. this.eof = true;
  17643. return;
  17644. }
  17645. var stream = streams.shift();
  17646. var chunk = stream.getBytes();
  17647. var bufferLength = this.bufferLength;
  17648. var newLength = bufferLength + chunk.length;
  17649. var buffer = this.ensureBuffer(newLength);
  17650. buffer.set(chunk, bufferLength);
  17651. this.bufferLength = newLength;
  17652. };
  17653. StreamsSequenceStream.prototype.getBaseStreams =
  17654. function StreamsSequenceStream_getBaseStreams() {
  17655. var baseStreams = [];
  17656. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  17657. var stream = this.streams[i];
  17658. if (stream.getBaseStreams) {
  17659. Util.appendToArray(baseStreams, stream.getBaseStreams());
  17660. }
  17661. }
  17662. return baseStreams;
  17663. };
  17664. return StreamsSequenceStream;
  17665. })();
  17666. var FlateStream = (function FlateStreamClosure() {
  17667. var codeLenCodeMap = new Int32Array([
  17668. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  17669. ]);
  17670. var lengthDecode = new Int32Array([
  17671. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  17672. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  17673. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  17674. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  17675. ]);
  17676. var distDecode = new Int32Array([
  17677. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  17678. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  17679. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  17680. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  17681. ]);
  17682. var fixedLitCodeTab = [new Int32Array([
  17683. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  17684. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  17685. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  17686. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  17687. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  17688. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  17689. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  17690. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  17691. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  17692. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  17693. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  17694. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  17695. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  17696. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  17697. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  17698. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  17699. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  17700. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  17701. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  17702. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  17703. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  17704. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  17705. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  17706. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  17707. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  17708. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  17709. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  17710. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  17711. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  17712. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  17713. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  17714. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  17715. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  17716. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  17717. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  17718. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  17719. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  17720. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  17721. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  17722. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  17723. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  17724. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  17725. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  17726. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  17727. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  17728. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  17729. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  17730. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  17731. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  17732. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  17733. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  17734. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  17735. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  17736. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  17737. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  17738. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  17739. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  17740. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  17741. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  17742. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  17743. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  17744. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  17745. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  17746. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  17747. ]), 9];
  17748. var fixedDistCodeTab = [new Int32Array([
  17749. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  17750. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  17751. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  17752. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  17753. ]), 5];
  17754. function FlateStream(str, maybeLength) {
  17755. this.str = str;
  17756. this.dict = str.dict;
  17757. var cmf = str.getByte();
  17758. var flg = str.getByte();
  17759. if (cmf === -1 || flg === -1) {
  17760. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  17761. }
  17762. if ((cmf & 0x0f) !== 0x08) {
  17763. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  17764. }
  17765. if ((((cmf << 8) + flg) % 31) !== 0) {
  17766. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  17767. }
  17768. if (flg & 0x20) {
  17769. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  17770. }
  17771. this.codeSize = 0;
  17772. this.codeBuf = 0;
  17773. DecodeStream.call(this, maybeLength);
  17774. }
  17775. FlateStream.prototype = Object.create(DecodeStream.prototype);
  17776. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  17777. var str = this.str;
  17778. var codeSize = this.codeSize;
  17779. var codeBuf = this.codeBuf;
  17780. var b;
  17781. while (codeSize < bits) {
  17782. if ((b = str.getByte()) === -1) {
  17783. error('Bad encoding in flate stream');
  17784. }
  17785. codeBuf |= b << codeSize;
  17786. codeSize += 8;
  17787. }
  17788. b = codeBuf & ((1 << bits) - 1);
  17789. this.codeBuf = codeBuf >> bits;
  17790. this.codeSize = codeSize -= bits;
  17791. return b;
  17792. };
  17793. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  17794. var str = this.str;
  17795. var codes = table[0];
  17796. var maxLen = table[1];
  17797. var codeSize = this.codeSize;
  17798. var codeBuf = this.codeBuf;
  17799. var b;
  17800. while (codeSize < maxLen) {
  17801. if ((b = str.getByte()) === -1) {
  17802. // premature end of stream. code might however still be valid.
  17803. // codeSize < codeLen check below guards against incomplete codeVal.
  17804. break;
  17805. }
  17806. codeBuf |= (b << codeSize);
  17807. codeSize += 8;
  17808. }
  17809. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  17810. var codeLen = code >> 16;
  17811. var codeVal = code & 0xffff;
  17812. if (codeLen < 1 || codeSize < codeLen) {
  17813. error('Bad encoding in flate stream');
  17814. }
  17815. this.codeBuf = (codeBuf >> codeLen);
  17816. this.codeSize = (codeSize - codeLen);
  17817. return codeVal;
  17818. };
  17819. FlateStream.prototype.generateHuffmanTable =
  17820. function flateStreamGenerateHuffmanTable(lengths) {
  17821. var n = lengths.length;
  17822. // find max code length
  17823. var maxLen = 0;
  17824. var i;
  17825. for (i = 0; i < n; ++i) {
  17826. if (lengths[i] > maxLen) {
  17827. maxLen = lengths[i];
  17828. }
  17829. }
  17830. // build the table
  17831. var size = 1 << maxLen;
  17832. var codes = new Int32Array(size);
  17833. for (var len = 1, code = 0, skip = 2;
  17834. len <= maxLen;
  17835. ++len, code <<= 1, skip <<= 1) {
  17836. for (var val = 0; val < n; ++val) {
  17837. if (lengths[val] === len) {
  17838. // bit-reverse the code
  17839. var code2 = 0;
  17840. var t = code;
  17841. for (i = 0; i < len; ++i) {
  17842. code2 = (code2 << 1) | (t & 1);
  17843. t >>= 1;
  17844. }
  17845. // fill the table entries
  17846. for (i = code2; i < size; i += skip) {
  17847. codes[i] = (len << 16) | val;
  17848. }
  17849. ++code;
  17850. }
  17851. }
  17852. }
  17853. return [codes, maxLen];
  17854. };
  17855. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  17856. var buffer, len;
  17857. var str = this.str;
  17858. // read block header
  17859. var hdr = this.getBits(3);
  17860. if (hdr & 1) {
  17861. this.eof = true;
  17862. }
  17863. hdr >>= 1;
  17864. if (hdr === 0) { // uncompressed block
  17865. var b;
  17866. if ((b = str.getByte()) === -1) {
  17867. error('Bad block header in flate stream');
  17868. }
  17869. var blockLen = b;
  17870. if ((b = str.getByte()) === -1) {
  17871. error('Bad block header in flate stream');
  17872. }
  17873. blockLen |= (b << 8);
  17874. if ((b = str.getByte()) === -1) {
  17875. error('Bad block header in flate stream');
  17876. }
  17877. var check = b;
  17878. if ((b = str.getByte()) === -1) {
  17879. error('Bad block header in flate stream');
  17880. }
  17881. check |= (b << 8);
  17882. if (check !== (~blockLen & 0xffff) &&
  17883. (blockLen !== 0 || check !== 0)) {
  17884. // Ignoring error for bad "empty" block (see issue 1277)
  17885. error('Bad uncompressed block length in flate stream');
  17886. }
  17887. this.codeBuf = 0;
  17888. this.codeSize = 0;
  17889. var bufferLength = this.bufferLength;
  17890. buffer = this.ensureBuffer(bufferLength + blockLen);
  17891. var end = bufferLength + blockLen;
  17892. this.bufferLength = end;
  17893. if (blockLen === 0) {
  17894. if (str.peekByte() === -1) {
  17895. this.eof = true;
  17896. }
  17897. } else {
  17898. for (var n = bufferLength; n < end; ++n) {
  17899. if ((b = str.getByte()) === -1) {
  17900. this.eof = true;
  17901. break;
  17902. }
  17903. buffer[n] = b;
  17904. }
  17905. }
  17906. return;
  17907. }
  17908. var litCodeTable;
  17909. var distCodeTable;
  17910. if (hdr === 1) { // compressed block, fixed codes
  17911. litCodeTable = fixedLitCodeTab;
  17912. distCodeTable = fixedDistCodeTab;
  17913. } else if (hdr === 2) { // compressed block, dynamic codes
  17914. var numLitCodes = this.getBits(5) + 257;
  17915. var numDistCodes = this.getBits(5) + 1;
  17916. var numCodeLenCodes = this.getBits(4) + 4;
  17917. // build the code lengths code table
  17918. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  17919. var i;
  17920. for (i = 0; i < numCodeLenCodes; ++i) {
  17921. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  17922. }
  17923. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  17924. // build the literal and distance code tables
  17925. len = 0;
  17926. i = 0;
  17927. var codes = numLitCodes + numDistCodes;
  17928. var codeLengths = new Uint8Array(codes);
  17929. var bitsLength, bitsOffset, what;
  17930. while (i < codes) {
  17931. var code = this.getCode(codeLenCodeTab);
  17932. if (code === 16) {
  17933. bitsLength = 2; bitsOffset = 3; what = len;
  17934. } else if (code === 17) {
  17935. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  17936. } else if (code === 18) {
  17937. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  17938. } else {
  17939. codeLengths[i++] = len = code;
  17940. continue;
  17941. }
  17942. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  17943. while (repeatLength-- > 0) {
  17944. codeLengths[i++] = what;
  17945. }
  17946. }
  17947. litCodeTable =
  17948. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  17949. distCodeTable =
  17950. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  17951. } else {
  17952. error('Unknown block type in flate stream');
  17953. }
  17954. buffer = this.buffer;
  17955. var limit = buffer ? buffer.length : 0;
  17956. var pos = this.bufferLength;
  17957. while (true) {
  17958. var code1 = this.getCode(litCodeTable);
  17959. if (code1 < 256) {
  17960. if (pos + 1 >= limit) {
  17961. buffer = this.ensureBuffer(pos + 1);
  17962. limit = buffer.length;
  17963. }
  17964. buffer[pos++] = code1;
  17965. continue;
  17966. }
  17967. if (code1 === 256) {
  17968. this.bufferLength = pos;
  17969. return;
  17970. }
  17971. code1 -= 257;
  17972. code1 = lengthDecode[code1];
  17973. var code2 = code1 >> 16;
  17974. if (code2 > 0) {
  17975. code2 = this.getBits(code2);
  17976. }
  17977. len = (code1 & 0xffff) + code2;
  17978. code1 = this.getCode(distCodeTable);
  17979. code1 = distDecode[code1];
  17980. code2 = code1 >> 16;
  17981. if (code2 > 0) {
  17982. code2 = this.getBits(code2);
  17983. }
  17984. var dist = (code1 & 0xffff) + code2;
  17985. if (pos + len >= limit) {
  17986. buffer = this.ensureBuffer(pos + len);
  17987. limit = buffer.length;
  17988. }
  17989. for (var k = 0; k < len; ++k, ++pos) {
  17990. buffer[pos] = buffer[pos - dist];
  17991. }
  17992. }
  17993. };
  17994. return FlateStream;
  17995. })();
  17996. var PredictorStream = (function PredictorStreamClosure() {
  17997. function PredictorStream(str, maybeLength, params) {
  17998. var predictor = this.predictor = params.get('Predictor') || 1;
  17999. if (predictor <= 1) {
  18000. return str; // no prediction
  18001. }
  18002. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  18003. error('Unsupported predictor: ' + predictor);
  18004. }
  18005. if (predictor === 2) {
  18006. this.readBlock = this.readBlockTiff;
  18007. } else {
  18008. this.readBlock = this.readBlockPng;
  18009. }
  18010. this.str = str;
  18011. this.dict = str.dict;
  18012. var colors = this.colors = params.get('Colors') || 1;
  18013. var bits = this.bits = params.get('BitsPerComponent') || 8;
  18014. var columns = this.columns = params.get('Columns') || 1;
  18015. this.pixBytes = (colors * bits + 7) >> 3;
  18016. this.rowBytes = (columns * colors * bits + 7) >> 3;
  18017. DecodeStream.call(this, maybeLength);
  18018. return this;
  18019. }
  18020. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  18021. PredictorStream.prototype.readBlockTiff =
  18022. function predictorStreamReadBlockTiff() {
  18023. var rowBytes = this.rowBytes;
  18024. var bufferLength = this.bufferLength;
  18025. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  18026. var bits = this.bits;
  18027. var colors = this.colors;
  18028. var rawBytes = this.str.getBytes(rowBytes);
  18029. this.eof = !rawBytes.length;
  18030. if (this.eof) {
  18031. return;
  18032. }
  18033. var inbuf = 0, outbuf = 0;
  18034. var inbits = 0, outbits = 0;
  18035. var pos = bufferLength;
  18036. var i;
  18037. if (bits === 1) {
  18038. for (i = 0; i < rowBytes; ++i) {
  18039. var c = rawBytes[i];
  18040. inbuf = (inbuf << 8) | c;
  18041. // bitwise addition is exclusive or
  18042. // first shift inbuf and then add
  18043. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  18044. // truncate inbuf (assumes colors < 16)
  18045. inbuf &= 0xFFFF;
  18046. }
  18047. } else if (bits === 8) {
  18048. for (i = 0; i < colors; ++i) {
  18049. buffer[pos++] = rawBytes[i];
  18050. }
  18051. for (; i < rowBytes; ++i) {
  18052. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  18053. pos++;
  18054. }
  18055. } else {
  18056. var compArray = new Uint8Array(colors + 1);
  18057. var bitMask = (1 << bits) - 1;
  18058. var j = 0, k = bufferLength;
  18059. var columns = this.columns;
  18060. for (i = 0; i < columns; ++i) {
  18061. for (var kk = 0; kk < colors; ++kk) {
  18062. if (inbits < bits) {
  18063. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  18064. inbits += 8;
  18065. }
  18066. compArray[kk] = (compArray[kk] +
  18067. (inbuf >> (inbits - bits))) & bitMask;
  18068. inbits -= bits;
  18069. outbuf = (outbuf << bits) | compArray[kk];
  18070. outbits += bits;
  18071. if (outbits >= 8) {
  18072. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  18073. outbits -= 8;
  18074. }
  18075. }
  18076. }
  18077. if (outbits > 0) {
  18078. buffer[k++] = (outbuf << (8 - outbits)) +
  18079. (inbuf & ((1 << (8 - outbits)) - 1));
  18080. }
  18081. }
  18082. this.bufferLength += rowBytes;
  18083. };
  18084. PredictorStream.prototype.readBlockPng =
  18085. function predictorStreamReadBlockPng() {
  18086. var rowBytes = this.rowBytes;
  18087. var pixBytes = this.pixBytes;
  18088. var predictor = this.str.getByte();
  18089. var rawBytes = this.str.getBytes(rowBytes);
  18090. this.eof = !rawBytes.length;
  18091. if (this.eof) {
  18092. return;
  18093. }
  18094. var bufferLength = this.bufferLength;
  18095. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  18096. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  18097. if (prevRow.length === 0) {
  18098. prevRow = new Uint8Array(rowBytes);
  18099. }
  18100. var i, j = bufferLength, up, c;
  18101. switch (predictor) {
  18102. case 0:
  18103. for (i = 0; i < rowBytes; ++i) {
  18104. buffer[j++] = rawBytes[i];
  18105. }
  18106. break;
  18107. case 1:
  18108. for (i = 0; i < pixBytes; ++i) {
  18109. buffer[j++] = rawBytes[i];
  18110. }
  18111. for (; i < rowBytes; ++i) {
  18112. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  18113. j++;
  18114. }
  18115. break;
  18116. case 2:
  18117. for (i = 0; i < rowBytes; ++i) {
  18118. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  18119. }
  18120. break;
  18121. case 3:
  18122. for (i = 0; i < pixBytes; ++i) {
  18123. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  18124. }
  18125. for (; i < rowBytes; ++i) {
  18126. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  18127. rawBytes[i]) & 0xFF;
  18128. j++;
  18129. }
  18130. break;
  18131. case 4:
  18132. // we need to save the up left pixels values. the simplest way
  18133. // is to create a new buffer
  18134. for (i = 0; i < pixBytes; ++i) {
  18135. up = prevRow[i];
  18136. c = rawBytes[i];
  18137. buffer[j++] = up + c;
  18138. }
  18139. for (; i < rowBytes; ++i) {
  18140. up = prevRow[i];
  18141. var upLeft = prevRow[i - pixBytes];
  18142. var left = buffer[j - pixBytes];
  18143. var p = left + up - upLeft;
  18144. var pa = p - left;
  18145. if (pa < 0) {
  18146. pa = -pa;
  18147. }
  18148. var pb = p - up;
  18149. if (pb < 0) {
  18150. pb = -pb;
  18151. }
  18152. var pc = p - upLeft;
  18153. if (pc < 0) {
  18154. pc = -pc;
  18155. }
  18156. c = rawBytes[i];
  18157. if (pa <= pb && pa <= pc) {
  18158. buffer[j++] = left + c;
  18159. } else if (pb <= pc) {
  18160. buffer[j++] = up + c;
  18161. } else {
  18162. buffer[j++] = upLeft + c;
  18163. }
  18164. }
  18165. break;
  18166. default:
  18167. error('Unsupported predictor: ' + predictor);
  18168. }
  18169. this.bufferLength += rowBytes;
  18170. };
  18171. return PredictorStream;
  18172. })();
  18173. /**
  18174. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  18175. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  18176. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  18177. * a library to decode these images and the stream behaves like all the other
  18178. * DecodeStreams.
  18179. */
  18180. var JpegStream = (function JpegStreamClosure() {
  18181. function JpegStream(stream, maybeLength, dict, xref) {
  18182. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  18183. // Note: this seems to mainly affect inline images.
  18184. var ch;
  18185. while ((ch = stream.getByte()) !== -1) {
  18186. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  18187. stream.skip(-1); // Reset the stream position to the SOI.
  18188. break;
  18189. }
  18190. }
  18191. this.stream = stream;
  18192. this.maybeLength = maybeLength;
  18193. this.dict = dict;
  18194. DecodeStream.call(this, maybeLength);
  18195. }
  18196. JpegStream.prototype = Object.create(DecodeStream.prototype);
  18197. Object.defineProperty(JpegStream.prototype, 'bytes', {
  18198. get: function JpegStream_bytes() {
  18199. // If this.maybeLength is null, we'll get the entire stream.
  18200. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  18201. },
  18202. configurable: true
  18203. });
  18204. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  18205. if (this.bufferLength) {
  18206. return;
  18207. }
  18208. try {
  18209. var jpegImage = new JpegImage();
  18210. // checking if values needs to be transformed before conversion
  18211. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  18212. var decodeArr = this.dict.get('Decode');
  18213. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  18214. var decodeArrLength = decodeArr.length;
  18215. var transform = new Int32Array(decodeArrLength);
  18216. var transformNeeded = false;
  18217. var maxValue = (1 << bitsPerComponent) - 1;
  18218. for (var i = 0; i < decodeArrLength; i += 2) {
  18219. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  18220. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  18221. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  18222. transformNeeded = true;
  18223. }
  18224. }
  18225. if (transformNeeded) {
  18226. jpegImage.decodeTransform = transform;
  18227. }
  18228. }
  18229. jpegImage.parse(this.bytes);
  18230. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  18231. this.forceRGB);
  18232. this.buffer = data;
  18233. this.bufferLength = data.length;
  18234. this.eof = true;
  18235. } catch (e) {
  18236. error('JPEG error: ' + e);
  18237. }
  18238. };
  18239. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  18240. this.ensureBuffer();
  18241. return this.buffer;
  18242. };
  18243. JpegStream.prototype.getIR = function JpegStream_getIR() {
  18244. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  18245. };
  18246. /**
  18247. * Checks if the image can be decoded and displayed by the browser without any
  18248. * further processing such as color space conversions.
  18249. */
  18250. JpegStream.prototype.isNativelySupported =
  18251. function JpegStream_isNativelySupported(xref, res) {
  18252. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  18253. return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') &&
  18254. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  18255. };
  18256. /**
  18257. * Checks if the image can be decoded by the browser.
  18258. */
  18259. JpegStream.prototype.isNativelyDecodable =
  18260. function JpegStream_isNativelyDecodable(xref, res) {
  18261. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  18262. return (cs.numComps === 1 || cs.numComps === 3) &&
  18263. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  18264. };
  18265. return JpegStream;
  18266. })();
  18267. /**
  18268. * For JPEG 2000's we use a library to decode these images and
  18269. * the stream behaves like all the other DecodeStreams.
  18270. */
  18271. var JpxStream = (function JpxStreamClosure() {
  18272. function JpxStream(stream, maybeLength, dict) {
  18273. this.stream = stream;
  18274. this.maybeLength = maybeLength;
  18275. this.dict = dict;
  18276. DecodeStream.call(this, maybeLength);
  18277. }
  18278. JpxStream.prototype = Object.create(DecodeStream.prototype);
  18279. Object.defineProperty(JpxStream.prototype, 'bytes', {
  18280. get: function JpxStream_bytes() {
  18281. // If this.maybeLength is null, we'll get the entire stream.
  18282. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  18283. },
  18284. configurable: true
  18285. });
  18286. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  18287. if (this.bufferLength) {
  18288. return;
  18289. }
  18290. var jpxImage = new JpxImage();
  18291. jpxImage.parse(this.bytes);
  18292. var width = jpxImage.width;
  18293. var height = jpxImage.height;
  18294. var componentsCount = jpxImage.componentsCount;
  18295. var tileCount = jpxImage.tiles.length;
  18296. if (tileCount === 1) {
  18297. this.buffer = jpxImage.tiles[0].items;
  18298. } else {
  18299. var data = new Uint8Array(width * height * componentsCount);
  18300. for (var k = 0; k < tileCount; k++) {
  18301. var tileComponents = jpxImage.tiles[k];
  18302. var tileWidth = tileComponents.width;
  18303. var tileHeight = tileComponents.height;
  18304. var tileLeft = tileComponents.left;
  18305. var tileTop = tileComponents.top;
  18306. var src = tileComponents.items;
  18307. var srcPosition = 0;
  18308. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  18309. var imgRowSize = width * componentsCount;
  18310. var tileRowSize = tileWidth * componentsCount;
  18311. for (var j = 0; j < tileHeight; j++) {
  18312. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  18313. data.set(rowBytes, dataPosition);
  18314. srcPosition += tileRowSize;
  18315. dataPosition += imgRowSize;
  18316. }
  18317. }
  18318. this.buffer = data;
  18319. }
  18320. this.bufferLength = this.buffer.length;
  18321. this.eof = true;
  18322. };
  18323. return JpxStream;
  18324. })();
  18325. /**
  18326. * For JBIG2's we use a library to decode these images and
  18327. * the stream behaves like all the other DecodeStreams.
  18328. */
  18329. var Jbig2Stream = (function Jbig2StreamClosure() {
  18330. function Jbig2Stream(stream, maybeLength, dict) {
  18331. this.stream = stream;
  18332. this.maybeLength = maybeLength;
  18333. this.dict = dict;
  18334. DecodeStream.call(this, maybeLength);
  18335. }
  18336. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  18337. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  18338. get: function Jbig2Stream_bytes() {
  18339. // If this.maybeLength is null, we'll get the entire stream.
  18340. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  18341. },
  18342. configurable: true
  18343. });
  18344. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  18345. if (this.bufferLength) {
  18346. return;
  18347. }
  18348. var jbig2Image = new Jbig2Image();
  18349. var chunks = [], xref = this.dict.xref;
  18350. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  18351. // According to the PDF specification, DecodeParms can be either
  18352. // a dictionary, or an array whose elements are dictionaries.
  18353. if (isArray(decodeParams)) {
  18354. if (decodeParams.length > 1) {
  18355. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  18356. 'not supported.');
  18357. }
  18358. decodeParams = xref.fetchIfRef(decodeParams[0]);
  18359. }
  18360. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  18361. var globalsStream = decodeParams.get('JBIG2Globals');
  18362. var globals = globalsStream.getBytes();
  18363. chunks.push({data: globals, start: 0, end: globals.length});
  18364. }
  18365. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  18366. var data = jbig2Image.parseChunks(chunks);
  18367. var dataLength = data.length;
  18368. // JBIG2 had black as 1 and white as 0, inverting the colors
  18369. for (var i = 0; i < dataLength; i++) {
  18370. data[i] ^= 0xFF;
  18371. }
  18372. this.buffer = data;
  18373. this.bufferLength = dataLength;
  18374. this.eof = true;
  18375. };
  18376. return Jbig2Stream;
  18377. })();
  18378. var DecryptStream = (function DecryptStreamClosure() {
  18379. function DecryptStream(str, maybeLength, decrypt) {
  18380. this.str = str;
  18381. this.dict = str.dict;
  18382. this.decrypt = decrypt;
  18383. this.nextChunk = null;
  18384. this.initialized = false;
  18385. DecodeStream.call(this, maybeLength);
  18386. }
  18387. var chunkSize = 512;
  18388. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  18389. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  18390. var chunk;
  18391. if (this.initialized) {
  18392. chunk = this.nextChunk;
  18393. } else {
  18394. chunk = this.str.getBytes(chunkSize);
  18395. this.initialized = true;
  18396. }
  18397. if (!chunk || chunk.length === 0) {
  18398. this.eof = true;
  18399. return;
  18400. }
  18401. this.nextChunk = this.str.getBytes(chunkSize);
  18402. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  18403. var decrypt = this.decrypt;
  18404. chunk = decrypt(chunk, !hasMoreData);
  18405. var bufferLength = this.bufferLength;
  18406. var i, n = chunk.length;
  18407. var buffer = this.ensureBuffer(bufferLength + n);
  18408. for (i = 0; i < n; i++) {
  18409. buffer[bufferLength++] = chunk[i];
  18410. }
  18411. this.bufferLength = bufferLength;
  18412. };
  18413. return DecryptStream;
  18414. })();
  18415. var Ascii85Stream = (function Ascii85StreamClosure() {
  18416. function Ascii85Stream(str, maybeLength) {
  18417. this.str = str;
  18418. this.dict = str.dict;
  18419. this.input = new Uint8Array(5);
  18420. // Most streams increase in size when decoded, but Ascii85 streams
  18421. // typically shrink by ~20%.
  18422. if (maybeLength) {
  18423. maybeLength = 0.8 * maybeLength;
  18424. }
  18425. DecodeStream.call(this, maybeLength);
  18426. }
  18427. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  18428. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  18429. var TILDA_CHAR = 0x7E; // '~'
  18430. var Z_LOWER_CHAR = 0x7A; // 'z'
  18431. var EOF = -1;
  18432. var str = this.str;
  18433. var c = str.getByte();
  18434. while (Lexer.isSpace(c)) {
  18435. c = str.getByte();
  18436. }
  18437. if (c === EOF || c === TILDA_CHAR) {
  18438. this.eof = true;
  18439. return;
  18440. }
  18441. var bufferLength = this.bufferLength, buffer;
  18442. var i;
  18443. // special code for z
  18444. if (c === Z_LOWER_CHAR) {
  18445. buffer = this.ensureBuffer(bufferLength + 4);
  18446. for (i = 0; i < 4; ++i) {
  18447. buffer[bufferLength + i] = 0;
  18448. }
  18449. this.bufferLength += 4;
  18450. } else {
  18451. var input = this.input;
  18452. input[0] = c;
  18453. for (i = 1; i < 5; ++i) {
  18454. c = str.getByte();
  18455. while (Lexer.isSpace(c)) {
  18456. c = str.getByte();
  18457. }
  18458. input[i] = c;
  18459. if (c === EOF || c === TILDA_CHAR) {
  18460. break;
  18461. }
  18462. }
  18463. buffer = this.ensureBuffer(bufferLength + i - 1);
  18464. this.bufferLength += i - 1;
  18465. // partial ending;
  18466. if (i < 5) {
  18467. for (; i < 5; ++i) {
  18468. input[i] = 0x21 + 84;
  18469. }
  18470. this.eof = true;
  18471. }
  18472. var t = 0;
  18473. for (i = 0; i < 5; ++i) {
  18474. t = t * 85 + (input[i] - 0x21);
  18475. }
  18476. for (i = 3; i >= 0; --i) {
  18477. buffer[bufferLength + i] = t & 0xFF;
  18478. t >>= 8;
  18479. }
  18480. }
  18481. };
  18482. return Ascii85Stream;
  18483. })();
  18484. var AsciiHexStream = (function AsciiHexStreamClosure() {
  18485. function AsciiHexStream(str, maybeLength) {
  18486. this.str = str;
  18487. this.dict = str.dict;
  18488. this.firstDigit = -1;
  18489. // Most streams increase in size when decoded, but AsciiHex streams shrink
  18490. // by 50%.
  18491. if (maybeLength) {
  18492. maybeLength = 0.5 * maybeLength;
  18493. }
  18494. DecodeStream.call(this, maybeLength);
  18495. }
  18496. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  18497. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  18498. var UPSTREAM_BLOCK_SIZE = 8000;
  18499. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  18500. if (!bytes.length) {
  18501. this.eof = true;
  18502. return;
  18503. }
  18504. var maxDecodeLength = (bytes.length + 1) >> 1;
  18505. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  18506. var bufferLength = this.bufferLength;
  18507. var firstDigit = this.firstDigit;
  18508. for (var i = 0, ii = bytes.length; i < ii; i++) {
  18509. var ch = bytes[i], digit;
  18510. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  18511. digit = ch & 0x0F;
  18512. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  18513. // 'A'-'Z', 'a'-'z'
  18514. digit = (ch & 0x0F) + 9;
  18515. } else if (ch === 0x3E) { // '>'
  18516. this.eof = true;
  18517. break;
  18518. } else { // probably whitespace
  18519. continue; // ignoring
  18520. }
  18521. if (firstDigit < 0) {
  18522. firstDigit = digit;
  18523. } else {
  18524. buffer[bufferLength++] = (firstDigit << 4) | digit;
  18525. firstDigit = -1;
  18526. }
  18527. }
  18528. if (firstDigit >= 0 && this.eof) {
  18529. // incomplete byte
  18530. buffer[bufferLength++] = (firstDigit << 4);
  18531. firstDigit = -1;
  18532. }
  18533. this.firstDigit = firstDigit;
  18534. this.bufferLength = bufferLength;
  18535. };
  18536. return AsciiHexStream;
  18537. })();
  18538. var RunLengthStream = (function RunLengthStreamClosure() {
  18539. function RunLengthStream(str, maybeLength) {
  18540. this.str = str;
  18541. this.dict = str.dict;
  18542. DecodeStream.call(this, maybeLength);
  18543. }
  18544. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  18545. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  18546. // The repeatHeader has following format. The first byte defines type of run
  18547. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  18548. // (in addition to the second byte from the header), n = 129 through 255 -
  18549. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  18550. var repeatHeader = this.str.getBytes(2);
  18551. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  18552. this.eof = true;
  18553. return;
  18554. }
  18555. var buffer;
  18556. var bufferLength = this.bufferLength;
  18557. var n = repeatHeader[0];
  18558. if (n < 128) {
  18559. // copy n bytes
  18560. buffer = this.ensureBuffer(bufferLength + n + 1);
  18561. buffer[bufferLength++] = repeatHeader[1];
  18562. if (n > 0) {
  18563. var source = this.str.getBytes(n);
  18564. buffer.set(source, bufferLength);
  18565. bufferLength += n;
  18566. }
  18567. } else {
  18568. n = 257 - n;
  18569. var b = repeatHeader[1];
  18570. buffer = this.ensureBuffer(bufferLength + n + 1);
  18571. for (var i = 0; i < n; i++) {
  18572. buffer[bufferLength++] = b;
  18573. }
  18574. }
  18575. this.bufferLength = bufferLength;
  18576. };
  18577. return RunLengthStream;
  18578. })();
  18579. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  18580. var ccittEOL = -2;
  18581. var twoDimPass = 0;
  18582. var twoDimHoriz = 1;
  18583. var twoDimVert0 = 2;
  18584. var twoDimVertR1 = 3;
  18585. var twoDimVertL1 = 4;
  18586. var twoDimVertR2 = 5;
  18587. var twoDimVertL2 = 6;
  18588. var twoDimVertR3 = 7;
  18589. var twoDimVertL3 = 8;
  18590. var twoDimTable = [
  18591. [-1, -1], [-1, -1], // 000000x
  18592. [7, twoDimVertL3], // 0000010
  18593. [7, twoDimVertR3], // 0000011
  18594. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  18595. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  18596. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  18597. [4, twoDimPass], [4, twoDimPass],
  18598. [4, twoDimPass], [4, twoDimPass],
  18599. [4, twoDimPass], [4, twoDimPass],
  18600. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  18601. [3, twoDimHoriz], [3, twoDimHoriz],
  18602. [3, twoDimHoriz], [3, twoDimHoriz],
  18603. [3, twoDimHoriz], [3, twoDimHoriz],
  18604. [3, twoDimHoriz], [3, twoDimHoriz],
  18605. [3, twoDimHoriz], [3, twoDimHoriz],
  18606. [3, twoDimHoriz], [3, twoDimHoriz],
  18607. [3, twoDimHoriz], [3, twoDimHoriz],
  18608. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  18609. [3, twoDimVertL1], [3, twoDimVertL1],
  18610. [3, twoDimVertL1], [3, twoDimVertL1],
  18611. [3, twoDimVertL1], [3, twoDimVertL1],
  18612. [3, twoDimVertL1], [3, twoDimVertL1],
  18613. [3, twoDimVertL1], [3, twoDimVertL1],
  18614. [3, twoDimVertL1], [3, twoDimVertL1],
  18615. [3, twoDimVertL1], [3, twoDimVertL1],
  18616. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  18617. [3, twoDimVertR1], [3, twoDimVertR1],
  18618. [3, twoDimVertR1], [3, twoDimVertR1],
  18619. [3, twoDimVertR1], [3, twoDimVertR1],
  18620. [3, twoDimVertR1], [3, twoDimVertR1],
  18621. [3, twoDimVertR1], [3, twoDimVertR1],
  18622. [3, twoDimVertR1], [3, twoDimVertR1],
  18623. [3, twoDimVertR1], [3, twoDimVertR1],
  18624. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  18625. [1, twoDimVert0], [1, twoDimVert0],
  18626. [1, twoDimVert0], [1, twoDimVert0],
  18627. [1, twoDimVert0], [1, twoDimVert0],
  18628. [1, twoDimVert0], [1, twoDimVert0],
  18629. [1, twoDimVert0], [1, twoDimVert0],
  18630. [1, twoDimVert0], [1, twoDimVert0],
  18631. [1, twoDimVert0], [1, twoDimVert0],
  18632. [1, twoDimVert0], [1, twoDimVert0],
  18633. [1, twoDimVert0], [1, twoDimVert0],
  18634. [1, twoDimVert0], [1, twoDimVert0],
  18635. [1, twoDimVert0], [1, twoDimVert0],
  18636. [1, twoDimVert0], [1, twoDimVert0],
  18637. [1, twoDimVert0], [1, twoDimVert0],
  18638. [1, twoDimVert0], [1, twoDimVert0],
  18639. [1, twoDimVert0], [1, twoDimVert0],
  18640. [1, twoDimVert0], [1, twoDimVert0],
  18641. [1, twoDimVert0], [1, twoDimVert0],
  18642. [1, twoDimVert0], [1, twoDimVert0],
  18643. [1, twoDimVert0], [1, twoDimVert0],
  18644. [1, twoDimVert0], [1, twoDimVert0],
  18645. [1, twoDimVert0], [1, twoDimVert0],
  18646. [1, twoDimVert0], [1, twoDimVert0],
  18647. [1, twoDimVert0], [1, twoDimVert0],
  18648. [1, twoDimVert0], [1, twoDimVert0],
  18649. [1, twoDimVert0], [1, twoDimVert0],
  18650. [1, twoDimVert0], [1, twoDimVert0],
  18651. [1, twoDimVert0], [1, twoDimVert0],
  18652. [1, twoDimVert0], [1, twoDimVert0],
  18653. [1, twoDimVert0], [1, twoDimVert0],
  18654. [1, twoDimVert0], [1, twoDimVert0],
  18655. [1, twoDimVert0], [1, twoDimVert0]
  18656. ];
  18657. var whiteTable1 = [
  18658. [-1, -1], // 00000
  18659. [12, ccittEOL], // 00001
  18660. [-1, -1], [-1, -1], // 0001x
  18661. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  18662. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  18663. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  18664. [11, 1792], [11, 1792], // 1000x
  18665. [12, 1984], // 10010
  18666. [12, 2048], // 10011
  18667. [12, 2112], // 10100
  18668. [12, 2176], // 10101
  18669. [12, 2240], // 10110
  18670. [12, 2304], // 10111
  18671. [11, 1856], [11, 1856], // 1100x
  18672. [11, 1920], [11, 1920], // 1101x
  18673. [12, 2368], // 11100
  18674. [12, 2432], // 11101
  18675. [12, 2496], // 11110
  18676. [12, 2560] // 11111
  18677. ];
  18678. var whiteTable2 = [
  18679. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  18680. [8, 29], [8, 29], // 00000010x
  18681. [8, 30], [8, 30], // 00000011x
  18682. [8, 45], [8, 45], // 00000100x
  18683. [8, 46], [8, 46], // 00000101x
  18684. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  18685. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  18686. [8, 47], [8, 47], // 00001010x
  18687. [8, 48], [8, 48], // 00001011x
  18688. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  18689. [6, 13], [6, 13], [6, 13], [6, 13],
  18690. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  18691. [8, 33], [8, 33], // 00010010x
  18692. [8, 34], [8, 34], // 00010011x
  18693. [8, 35], [8, 35], // 00010100x
  18694. [8, 36], [8, 36], // 00010101x
  18695. [8, 37], [8, 37], // 00010110x
  18696. [8, 38], [8, 38], // 00010111x
  18697. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  18698. [8, 31], [8, 31], // 00011010x
  18699. [8, 32], [8, 32], // 00011011x
  18700. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  18701. [6, 1], [6, 1], [6, 1], [6, 1],
  18702. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  18703. [6, 12], [6, 12], [6, 12], [6, 12],
  18704. [8, 53], [8, 53], // 00100100x
  18705. [8, 54], [8, 54], // 00100101x
  18706. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  18707. [8, 39], [8, 39], // 00101000x
  18708. [8, 40], [8, 40], // 00101001x
  18709. [8, 41], [8, 41], // 00101010x
  18710. [8, 42], [8, 42], // 00101011x
  18711. [8, 43], [8, 43], // 00101100x
  18712. [8, 44], [8, 44], // 00101101x
  18713. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  18714. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  18715. [8, 61], [8, 61], // 00110010x
  18716. [8, 62], [8, 62], // 00110011x
  18717. [8, 63], [8, 63], // 00110100x
  18718. [8, 0], [8, 0], // 00110101x
  18719. [8, 320], [8, 320], // 00110110x
  18720. [8, 384], [8, 384], // 00110111x
  18721. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  18722. [5, 10], [5, 10], [5, 10], [5, 10],
  18723. [5, 10], [5, 10], [5, 10], [5, 10],
  18724. [5, 10], [5, 10], [5, 10], [5, 10],
  18725. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  18726. [5, 11], [5, 11], [5, 11], [5, 11],
  18727. [5, 11], [5, 11], [5, 11], [5, 11],
  18728. [5, 11], [5, 11], [5, 11], [5, 11],
  18729. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  18730. [8, 59], [8, 59], // 01001010x
  18731. [8, 60], [8, 60], // 01001011x
  18732. [9, 1472], // 010011000
  18733. [9, 1536], // 010011001
  18734. [9, 1600], // 010011010
  18735. [9, 1728], // 010011011
  18736. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  18737. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  18738. [8, 49], [8, 49], // 01010010x
  18739. [8, 50], [8, 50], // 01010011x
  18740. [8, 51], [8, 51], // 01010100x
  18741. [8, 52], [8, 52], // 01010101x
  18742. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  18743. [8, 55], [8, 55], // 01011000x
  18744. [8, 56], [8, 56], // 01011001x
  18745. [8, 57], [8, 57], // 01011010x
  18746. [8, 58], [8, 58], // 01011011x
  18747. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  18748. [6, 192], [6, 192], [6, 192], [6, 192],
  18749. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  18750. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  18751. [8, 448], [8, 448], // 01100100x
  18752. [8, 512], [8, 512], // 01100101x
  18753. [9, 704], // 011001100
  18754. [9, 768], // 011001101
  18755. [8, 640], [8, 640], // 01100111x
  18756. [8, 576], [8, 576], // 01101000x
  18757. [9, 832], // 011010010
  18758. [9, 896], // 011010011
  18759. [9, 960], // 011010100
  18760. [9, 1024], // 011010101
  18761. [9, 1088], // 011010110
  18762. [9, 1152], // 011010111
  18763. [9, 1216], // 011011000
  18764. [9, 1280], // 011011001
  18765. [9, 1344], // 011011010
  18766. [9, 1408], // 011011011
  18767. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  18768. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  18769. [4, 2], [4, 2], [4, 2], [4, 2],
  18770. [4, 2], [4, 2], [4, 2], [4, 2],
  18771. [4, 2], [4, 2], [4, 2], [4, 2],
  18772. [4, 2], [4, 2], [4, 2], [4, 2],
  18773. [4, 2], [4, 2], [4, 2], [4, 2],
  18774. [4, 2], [4, 2], [4, 2], [4, 2],
  18775. [4, 2], [4, 2], [4, 2], [4, 2],
  18776. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  18777. [4, 3], [4, 3], [4, 3], [4, 3],
  18778. [4, 3], [4, 3], [4, 3], [4, 3],
  18779. [4, 3], [4, 3], [4, 3], [4, 3],
  18780. [4, 3], [4, 3], [4, 3], [4, 3],
  18781. [4, 3], [4, 3], [4, 3], [4, 3],
  18782. [4, 3], [4, 3], [4, 3], [4, 3],
  18783. [4, 3], [4, 3], [4, 3], [4, 3],
  18784. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  18785. [5, 128], [5, 128], [5, 128], [5, 128],
  18786. [5, 128], [5, 128], [5, 128], [5, 128],
  18787. [5, 128], [5, 128], [5, 128], [5, 128],
  18788. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  18789. [5, 8], [5, 8], [5, 8], [5, 8],
  18790. [5, 8], [5, 8], [5, 8], [5, 8],
  18791. [5, 8], [5, 8], [5, 8], [5, 8],
  18792. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  18793. [5, 9], [5, 9], [5, 9], [5, 9],
  18794. [5, 9], [5, 9], [5, 9], [5, 9],
  18795. [5, 9], [5, 9], [5, 9], [5, 9],
  18796. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  18797. [6, 16], [6, 16], [6, 16], [6, 16],
  18798. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  18799. [6, 17], [6, 17], [6, 17], [6, 17],
  18800. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  18801. [4, 4], [4, 4], [4, 4], [4, 4],
  18802. [4, 4], [4, 4], [4, 4], [4, 4],
  18803. [4, 4], [4, 4], [4, 4], [4, 4],
  18804. [4, 4], [4, 4], [4, 4], [4, 4],
  18805. [4, 4], [4, 4], [4, 4], [4, 4],
  18806. [4, 4], [4, 4], [4, 4], [4, 4],
  18807. [4, 4], [4, 4], [4, 4], [4, 4],
  18808. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  18809. [4, 5], [4, 5], [4, 5], [4, 5],
  18810. [4, 5], [4, 5], [4, 5], [4, 5],
  18811. [4, 5], [4, 5], [4, 5], [4, 5],
  18812. [4, 5], [4, 5], [4, 5], [4, 5],
  18813. [4, 5], [4, 5], [4, 5], [4, 5],
  18814. [4, 5], [4, 5], [4, 5], [4, 5],
  18815. [4, 5], [4, 5], [4, 5], [4, 5],
  18816. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  18817. [6, 14], [6, 14], [6, 14], [6, 14],
  18818. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  18819. [6, 15], [6, 15], [6, 15], [6, 15],
  18820. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  18821. [5, 64], [5, 64], [5, 64], [5, 64],
  18822. [5, 64], [5, 64], [5, 64], [5, 64],
  18823. [5, 64], [5, 64], [5, 64], [5, 64],
  18824. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  18825. [4, 6], [4, 6], [4, 6], [4, 6],
  18826. [4, 6], [4, 6], [4, 6], [4, 6],
  18827. [4, 6], [4, 6], [4, 6], [4, 6],
  18828. [4, 6], [4, 6], [4, 6], [4, 6],
  18829. [4, 6], [4, 6], [4, 6], [4, 6],
  18830. [4, 6], [4, 6], [4, 6], [4, 6],
  18831. [4, 6], [4, 6], [4, 6], [4, 6],
  18832. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  18833. [4, 7], [4, 7], [4, 7], [4, 7],
  18834. [4, 7], [4, 7], [4, 7], [4, 7],
  18835. [4, 7], [4, 7], [4, 7], [4, 7],
  18836. [4, 7], [4, 7], [4, 7], [4, 7],
  18837. [4, 7], [4, 7], [4, 7], [4, 7],
  18838. [4, 7], [4, 7], [4, 7], [4, 7],
  18839. [4, 7], [4, 7], [4, 7], [4, 7]
  18840. ];
  18841. var blackTable1 = [
  18842. [-1, -1], [-1, -1], // 000000000000x
  18843. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  18844. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  18845. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  18846. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  18847. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  18848. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  18849. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  18850. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  18851. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  18852. [12, 1984], [12, 1984], // 000000010010x
  18853. [12, 2048], [12, 2048], // 000000010011x
  18854. [12, 2112], [12, 2112], // 000000010100x
  18855. [12, 2176], [12, 2176], // 000000010101x
  18856. [12, 2240], [12, 2240], // 000000010110x
  18857. [12, 2304], [12, 2304], // 000000010111x
  18858. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  18859. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  18860. [12, 2368], [12, 2368], // 000000011100x
  18861. [12, 2432], [12, 2432], // 000000011101x
  18862. [12, 2496], [12, 2496], // 000000011110x
  18863. [12, 2560], [12, 2560], // 000000011111x
  18864. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  18865. [10, 18], [10, 18], [10, 18], [10, 18],
  18866. [12, 52], [12, 52], // 000000100100x
  18867. [13, 640], // 0000001001010
  18868. [13, 704], // 0000001001011
  18869. [13, 768], // 0000001001100
  18870. [13, 832], // 0000001001101
  18871. [12, 55], [12, 55], // 000000100111x
  18872. [12, 56], [12, 56], // 000000101000x
  18873. [13, 1280], // 0000001010010
  18874. [13, 1344], // 0000001010011
  18875. [13, 1408], // 0000001010100
  18876. [13, 1472], // 0000001010101
  18877. [12, 59], [12, 59], // 000000101011x
  18878. [12, 60], [12, 60], // 000000101100x
  18879. [13, 1536], // 0000001011010
  18880. [13, 1600], // 0000001011011
  18881. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  18882. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  18883. [13, 1664], // 0000001100100
  18884. [13, 1728], // 0000001100101
  18885. [12, 320], [12, 320], // 000000110011x
  18886. [12, 384], [12, 384], // 000000110100x
  18887. [12, 448], [12, 448], // 000000110101x
  18888. [13, 512], // 0000001101100
  18889. [13, 576], // 0000001101101
  18890. [12, 53], [12, 53], // 000000110111x
  18891. [12, 54], [12, 54], // 000000111000x
  18892. [13, 896], // 0000001110010
  18893. [13, 960], // 0000001110011
  18894. [13, 1024], // 0000001110100
  18895. [13, 1088], // 0000001110101
  18896. [13, 1152], // 0000001110110
  18897. [13, 1216], // 0000001110111
  18898. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  18899. [10, 64], [10, 64], [10, 64], [10, 64]
  18900. ];
  18901. var blackTable2 = [
  18902. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  18903. [8, 13], [8, 13], [8, 13], [8, 13],
  18904. [8, 13], [8, 13], [8, 13], [8, 13],
  18905. [8, 13], [8, 13], [8, 13], [8, 13],
  18906. [11, 23], [11, 23], // 00000101000x
  18907. [12, 50], // 000001010010
  18908. [12, 51], // 000001010011
  18909. [12, 44], // 000001010100
  18910. [12, 45], // 000001010101
  18911. [12, 46], // 000001010110
  18912. [12, 47], // 000001010111
  18913. [12, 57], // 000001011000
  18914. [12, 58], // 000001011001
  18915. [12, 61], // 000001011010
  18916. [12, 256], // 000001011011
  18917. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  18918. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  18919. [12, 48], // 000001100100
  18920. [12, 49], // 000001100101
  18921. [12, 62], // 000001100110
  18922. [12, 63], // 000001100111
  18923. [12, 30], // 000001101000
  18924. [12, 31], // 000001101001
  18925. [12, 32], // 000001101010
  18926. [12, 33], // 000001101011
  18927. [12, 40], // 000001101100
  18928. [12, 41], // 000001101101
  18929. [11, 22], [11, 22], // 00000110111x
  18930. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  18931. [8, 14], [8, 14], [8, 14], [8, 14],
  18932. [8, 14], [8, 14], [8, 14], [8, 14],
  18933. [8, 14], [8, 14], [8, 14], [8, 14],
  18934. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  18935. [7, 10], [7, 10], [7, 10], [7, 10],
  18936. [7, 10], [7, 10], [7, 10], [7, 10],
  18937. [7, 10], [7, 10], [7, 10], [7, 10],
  18938. [7, 10], [7, 10], [7, 10], [7, 10],
  18939. [7, 10], [7, 10], [7, 10], [7, 10],
  18940. [7, 10], [7, 10], [7, 10], [7, 10],
  18941. [7, 10], [7, 10], [7, 10], [7, 10],
  18942. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  18943. [7, 11], [7, 11], [7, 11], [7, 11],
  18944. [7, 11], [7, 11], [7, 11], [7, 11],
  18945. [7, 11], [7, 11], [7, 11], [7, 11],
  18946. [7, 11], [7, 11], [7, 11], [7, 11],
  18947. [7, 11], [7, 11], [7, 11], [7, 11],
  18948. [7, 11], [7, 11], [7, 11], [7, 11],
  18949. [7, 11], [7, 11], [7, 11], [7, 11],
  18950. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  18951. [9, 15], [9, 15], [9, 15], [9, 15],
  18952. [12, 128], // 000011001000
  18953. [12, 192], // 000011001001
  18954. [12, 26], // 000011001010
  18955. [12, 27], // 000011001011
  18956. [12, 28], // 000011001100
  18957. [12, 29], // 000011001101
  18958. [11, 19], [11, 19], // 00001100111x
  18959. [11, 20], [11, 20], // 00001101000x
  18960. [12, 34], // 000011010010
  18961. [12, 35], // 000011010011
  18962. [12, 36], // 000011010100
  18963. [12, 37], // 000011010101
  18964. [12, 38], // 000011010110
  18965. [12, 39], // 000011010111
  18966. [11, 21], [11, 21], // 00001101100x
  18967. [12, 42], // 000011011010
  18968. [12, 43], // 000011011011
  18969. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  18970. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  18971. [7, 12], [7, 12], [7, 12], [7, 12],
  18972. [7, 12], [7, 12], [7, 12], [7, 12],
  18973. [7, 12], [7, 12], [7, 12], [7, 12],
  18974. [7, 12], [7, 12], [7, 12], [7, 12],
  18975. [7, 12], [7, 12], [7, 12], [7, 12],
  18976. [7, 12], [7, 12], [7, 12], [7, 12],
  18977. [7, 12], [7, 12], [7, 12], [7, 12]
  18978. ];
  18979. var blackTable3 = [
  18980. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  18981. [6, 9], // 000100
  18982. [6, 8], // 000101
  18983. [5, 7], [5, 7], // 00011x
  18984. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  18985. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  18986. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  18987. [3, 1], [3, 1], [3, 1], [3, 1],
  18988. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  18989. [3, 4], [3, 4], [3, 4], [3, 4],
  18990. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  18991. [2, 3], [2, 3], [2, 3], [2, 3],
  18992. [2, 3], [2, 3], [2, 3], [2, 3],
  18993. [2, 3], [2, 3], [2, 3], [2, 3],
  18994. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  18995. [2, 2], [2, 2], [2, 2], [2, 2],
  18996. [2, 2], [2, 2], [2, 2], [2, 2],
  18997. [2, 2], [2, 2], [2, 2], [2, 2]
  18998. ];
  18999. function CCITTFaxStream(str, maybeLength, params) {
  19000. this.str = str;
  19001. this.dict = str.dict;
  19002. params = params || Dict.empty;
  19003. this.encoding = params.get('K') || 0;
  19004. this.eoline = params.get('EndOfLine') || false;
  19005. this.byteAlign = params.get('EncodedByteAlign') || false;
  19006. this.columns = params.get('Columns') || 1728;
  19007. this.rows = params.get('Rows') || 0;
  19008. var eoblock = params.get('EndOfBlock');
  19009. if (eoblock === null || eoblock === undefined) {
  19010. eoblock = true;
  19011. }
  19012. this.eoblock = eoblock;
  19013. this.black = params.get('BlackIs1') || false;
  19014. this.codingLine = new Uint32Array(this.columns + 1);
  19015. this.refLine = new Uint32Array(this.columns + 2);
  19016. this.codingLine[0] = this.columns;
  19017. this.codingPos = 0;
  19018. this.row = 0;
  19019. this.nextLine2D = this.encoding < 0;
  19020. this.inputBits = 0;
  19021. this.inputBuf = 0;
  19022. this.outputBits = 0;
  19023. var code1;
  19024. while ((code1 = this.lookBits(12)) === 0) {
  19025. this.eatBits(1);
  19026. }
  19027. if (code1 === 1) {
  19028. this.eatBits(12);
  19029. }
  19030. if (this.encoding > 0) {
  19031. this.nextLine2D = !this.lookBits(1);
  19032. this.eatBits(1);
  19033. }
  19034. DecodeStream.call(this, maybeLength);
  19035. }
  19036. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  19037. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  19038. while (!this.eof) {
  19039. var c = this.lookChar();
  19040. this.ensureBuffer(this.bufferLength + 1);
  19041. this.buffer[this.bufferLength++] = c;
  19042. }
  19043. };
  19044. CCITTFaxStream.prototype.addPixels =
  19045. function ccittFaxStreamAddPixels(a1, blackPixels) {
  19046. var codingLine = this.codingLine;
  19047. var codingPos = this.codingPos;
  19048. if (a1 > codingLine[codingPos]) {
  19049. if (a1 > this.columns) {
  19050. info('row is wrong length');
  19051. this.err = true;
  19052. a1 = this.columns;
  19053. }
  19054. if ((codingPos & 1) ^ blackPixels) {
  19055. ++codingPos;
  19056. }
  19057. codingLine[codingPos] = a1;
  19058. }
  19059. this.codingPos = codingPos;
  19060. };
  19061. CCITTFaxStream.prototype.addPixelsNeg =
  19062. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  19063. var codingLine = this.codingLine;
  19064. var codingPos = this.codingPos;
  19065. if (a1 > codingLine[codingPos]) {
  19066. if (a1 > this.columns) {
  19067. info('row is wrong length');
  19068. this.err = true;
  19069. a1 = this.columns;
  19070. }
  19071. if ((codingPos & 1) ^ blackPixels) {
  19072. ++codingPos;
  19073. }
  19074. codingLine[codingPos] = a1;
  19075. } else if (a1 < codingLine[codingPos]) {
  19076. if (a1 < 0) {
  19077. info('invalid code');
  19078. this.err = true;
  19079. a1 = 0;
  19080. }
  19081. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  19082. --codingPos;
  19083. }
  19084. codingLine[codingPos] = a1;
  19085. }
  19086. this.codingPos = codingPos;
  19087. };
  19088. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  19089. var refLine = this.refLine;
  19090. var codingLine = this.codingLine;
  19091. var columns = this.columns;
  19092. var refPos, blackPixels, bits, i;
  19093. if (this.outputBits === 0) {
  19094. if (this.eof) {
  19095. return null;
  19096. }
  19097. this.err = false;
  19098. var code1, code2, code3;
  19099. if (this.nextLine2D) {
  19100. for (i = 0; codingLine[i] < columns; ++i) {
  19101. refLine[i] = codingLine[i];
  19102. }
  19103. refLine[i++] = columns;
  19104. refLine[i] = columns;
  19105. codingLine[0] = 0;
  19106. this.codingPos = 0;
  19107. refPos = 0;
  19108. blackPixels = 0;
  19109. while (codingLine[this.codingPos] < columns) {
  19110. code1 = this.getTwoDimCode();
  19111. switch (code1) {
  19112. case twoDimPass:
  19113. this.addPixels(refLine[refPos + 1], blackPixels);
  19114. if (refLine[refPos + 1] < columns) {
  19115. refPos += 2;
  19116. }
  19117. break;
  19118. case twoDimHoriz:
  19119. code1 = code2 = 0;
  19120. if (blackPixels) {
  19121. do {
  19122. code1 += (code3 = this.getBlackCode());
  19123. } while (code3 >= 64);
  19124. do {
  19125. code2 += (code3 = this.getWhiteCode());
  19126. } while (code3 >= 64);
  19127. } else {
  19128. do {
  19129. code1 += (code3 = this.getWhiteCode());
  19130. } while (code3 >= 64);
  19131. do {
  19132. code2 += (code3 = this.getBlackCode());
  19133. } while (code3 >= 64);
  19134. }
  19135. this.addPixels(codingLine[this.codingPos] +
  19136. code1, blackPixels);
  19137. if (codingLine[this.codingPos] < columns) {
  19138. this.addPixels(codingLine[this.codingPos] + code2,
  19139. blackPixels ^ 1);
  19140. }
  19141. while (refLine[refPos] <= codingLine[this.codingPos] &&
  19142. refLine[refPos] < columns) {
  19143. refPos += 2;
  19144. }
  19145. break;
  19146. case twoDimVertR3:
  19147. this.addPixels(refLine[refPos] + 3, blackPixels);
  19148. blackPixels ^= 1;
  19149. if (codingLine[this.codingPos] < columns) {
  19150. ++refPos;
  19151. while (refLine[refPos] <= codingLine[this.codingPos] &&
  19152. refLine[refPos] < columns) {
  19153. refPos += 2;
  19154. }
  19155. }
  19156. break;
  19157. case twoDimVertR2:
  19158. this.addPixels(refLine[refPos] + 2, blackPixels);
  19159. blackPixels ^= 1;
  19160. if (codingLine[this.codingPos] < columns) {
  19161. ++refPos;
  19162. while (refLine[refPos] <= codingLine[this.codingPos] &&
  19163. refLine[refPos] < columns) {
  19164. refPos += 2;
  19165. }
  19166. }
  19167. break;
  19168. case twoDimVertR1:
  19169. this.addPixels(refLine[refPos] + 1, blackPixels);
  19170. blackPixels ^= 1;
  19171. if (codingLine[this.codingPos] < columns) {
  19172. ++refPos;
  19173. while (refLine[refPos] <= codingLine[this.codingPos] &&
  19174. refLine[refPos] < columns) {
  19175. refPos += 2;
  19176. }
  19177. }
  19178. break;
  19179. case twoDimVert0:
  19180. this.addPixels(refLine[refPos], blackPixels);
  19181. blackPixels ^= 1;
  19182. if (codingLine[this.codingPos] < columns) {
  19183. ++refPos;
  19184. while (refLine[refPos] <= codingLine[this.codingPos] &&
  19185. refLine[refPos] < columns) {
  19186. refPos += 2;
  19187. }
  19188. }
  19189. break;
  19190. case twoDimVertL3:
  19191. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  19192. blackPixels ^= 1;
  19193. if (codingLine[this.codingPos] < columns) {
  19194. if (refPos > 0) {
  19195. --refPos;
  19196. } else {
  19197. ++refPos;
  19198. }
  19199. while (refLine[refPos] <= codingLine[this.codingPos] &&
  19200. refLine[refPos] < columns) {
  19201. refPos += 2;
  19202. }
  19203. }
  19204. break;
  19205. case twoDimVertL2:
  19206. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  19207. blackPixels ^= 1;
  19208. if (codingLine[this.codingPos] < columns) {
  19209. if (refPos > 0) {
  19210. --refPos;
  19211. } else {
  19212. ++refPos;
  19213. }
  19214. while (refLine[refPos] <= codingLine[this.codingPos] &&
  19215. refLine[refPos] < columns) {
  19216. refPos += 2;
  19217. }
  19218. }
  19219. break;
  19220. case twoDimVertL1:
  19221. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  19222. blackPixels ^= 1;
  19223. if (codingLine[this.codingPos] < columns) {
  19224. if (refPos > 0) {
  19225. --refPos;
  19226. } else {
  19227. ++refPos;
  19228. }
  19229. while (refLine[refPos] <= codingLine[this.codingPos] &&
  19230. refLine[refPos] < columns) {
  19231. refPos += 2;
  19232. }
  19233. }
  19234. break;
  19235. case EOF:
  19236. this.addPixels(columns, 0);
  19237. this.eof = true;
  19238. break;
  19239. default:
  19240. info('bad 2d code');
  19241. this.addPixels(columns, 0);
  19242. this.err = true;
  19243. }
  19244. }
  19245. } else {
  19246. codingLine[0] = 0;
  19247. this.codingPos = 0;
  19248. blackPixels = 0;
  19249. while (codingLine[this.codingPos] < columns) {
  19250. code1 = 0;
  19251. if (blackPixels) {
  19252. do {
  19253. code1 += (code3 = this.getBlackCode());
  19254. } while (code3 >= 64);
  19255. } else {
  19256. do {
  19257. code1 += (code3 = this.getWhiteCode());
  19258. } while (code3 >= 64);
  19259. }
  19260. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  19261. blackPixels ^= 1;
  19262. }
  19263. }
  19264. var gotEOL = false;
  19265. if (this.byteAlign) {
  19266. this.inputBits &= ~7;
  19267. }
  19268. if (!this.eoblock && this.row === this.rows - 1) {
  19269. this.eof = true;
  19270. } else {
  19271. code1 = this.lookBits(12);
  19272. if (this.eoline) {
  19273. while (code1 !== EOF && code1 !== 1) {
  19274. this.eatBits(1);
  19275. code1 = this.lookBits(12);
  19276. }
  19277. } else {
  19278. while (code1 === 0) {
  19279. this.eatBits(1);
  19280. code1 = this.lookBits(12);
  19281. }
  19282. }
  19283. if (code1 === 1) {
  19284. this.eatBits(12);
  19285. gotEOL = true;
  19286. } else if (code1 === EOF) {
  19287. this.eof = true;
  19288. }
  19289. }
  19290. if (!this.eof && this.encoding > 0) {
  19291. this.nextLine2D = !this.lookBits(1);
  19292. this.eatBits(1);
  19293. }
  19294. if (this.eoblock && gotEOL && this.byteAlign) {
  19295. code1 = this.lookBits(12);
  19296. if (code1 === 1) {
  19297. this.eatBits(12);
  19298. if (this.encoding > 0) {
  19299. this.lookBits(1);
  19300. this.eatBits(1);
  19301. }
  19302. if (this.encoding >= 0) {
  19303. for (i = 0; i < 4; ++i) {
  19304. code1 = this.lookBits(12);
  19305. if (code1 !== 1) {
  19306. info('bad rtc code: ' + code1);
  19307. }
  19308. this.eatBits(12);
  19309. if (this.encoding > 0) {
  19310. this.lookBits(1);
  19311. this.eatBits(1);
  19312. }
  19313. }
  19314. }
  19315. this.eof = true;
  19316. }
  19317. } else if (this.err && this.eoline) {
  19318. while (true) {
  19319. code1 = this.lookBits(13);
  19320. if (code1 === EOF) {
  19321. this.eof = true;
  19322. return null;
  19323. }
  19324. if ((code1 >> 1) === 1) {
  19325. break;
  19326. }
  19327. this.eatBits(1);
  19328. }
  19329. this.eatBits(12);
  19330. if (this.encoding > 0) {
  19331. this.eatBits(1);
  19332. this.nextLine2D = !(code1 & 1);
  19333. }
  19334. }
  19335. if (codingLine[0] > 0) {
  19336. this.outputBits = codingLine[this.codingPos = 0];
  19337. } else {
  19338. this.outputBits = codingLine[this.codingPos = 1];
  19339. }
  19340. this.row++;
  19341. }
  19342. var c;
  19343. if (this.outputBits >= 8) {
  19344. c = (this.codingPos & 1) ? 0 : 0xFF;
  19345. this.outputBits -= 8;
  19346. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  19347. this.codingPos++;
  19348. this.outputBits = (codingLine[this.codingPos] -
  19349. codingLine[this.codingPos - 1]);
  19350. }
  19351. } else {
  19352. bits = 8;
  19353. c = 0;
  19354. do {
  19355. if (this.outputBits > bits) {
  19356. c <<= bits;
  19357. if (!(this.codingPos & 1)) {
  19358. c |= 0xFF >> (8 - bits);
  19359. }
  19360. this.outputBits -= bits;
  19361. bits = 0;
  19362. } else {
  19363. c <<= this.outputBits;
  19364. if (!(this.codingPos & 1)) {
  19365. c |= 0xFF >> (8 - this.outputBits);
  19366. }
  19367. bits -= this.outputBits;
  19368. this.outputBits = 0;
  19369. if (codingLine[this.codingPos] < columns) {
  19370. this.codingPos++;
  19371. this.outputBits = (codingLine[this.codingPos] -
  19372. codingLine[this.codingPos - 1]);
  19373. } else if (bits > 0) {
  19374. c <<= bits;
  19375. bits = 0;
  19376. }
  19377. }
  19378. } while (bits);
  19379. }
  19380. if (this.black) {
  19381. c ^= 0xFF;
  19382. }
  19383. return c;
  19384. };
  19385. // This functions returns the code found from the table.
  19386. // The start and end parameters set the boundaries for searching the table.
  19387. // The limit parameter is optional. Function returns an array with three
  19388. // values. The first array element indicates whether a valid code is being
  19389. // returned. The second array element is the actual code. The third array
  19390. // element indicates whether EOF was reached.
  19391. CCITTFaxStream.prototype.findTableCode =
  19392. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  19393. var limitValue = limit || 0;
  19394. for (var i = start; i <= end; ++i) {
  19395. var code = this.lookBits(i);
  19396. if (code === EOF) {
  19397. return [true, 1, false];
  19398. }
  19399. if (i < end) {
  19400. code <<= end - i;
  19401. }
  19402. if (!limitValue || code >= limitValue) {
  19403. var p = table[code - limitValue];
  19404. if (p[0] === i) {
  19405. this.eatBits(i);
  19406. return [true, p[1], true];
  19407. }
  19408. }
  19409. }
  19410. return [false, 0, false];
  19411. };
  19412. CCITTFaxStream.prototype.getTwoDimCode =
  19413. function ccittFaxStreamGetTwoDimCode() {
  19414. var code = 0;
  19415. var p;
  19416. if (this.eoblock) {
  19417. code = this.lookBits(7);
  19418. p = twoDimTable[code];
  19419. if (p && p[0] > 0) {
  19420. this.eatBits(p[0]);
  19421. return p[1];
  19422. }
  19423. } else {
  19424. var result = this.findTableCode(1, 7, twoDimTable);
  19425. if (result[0] && result[2]) {
  19426. return result[1];
  19427. }
  19428. }
  19429. info('Bad two dim code');
  19430. return EOF;
  19431. };
  19432. CCITTFaxStream.prototype.getWhiteCode =
  19433. function ccittFaxStreamGetWhiteCode() {
  19434. var code = 0;
  19435. var p;
  19436. if (this.eoblock) {
  19437. code = this.lookBits(12);
  19438. if (code === EOF) {
  19439. return 1;
  19440. }
  19441. if ((code >> 5) === 0) {
  19442. p = whiteTable1[code];
  19443. } else {
  19444. p = whiteTable2[code >> 3];
  19445. }
  19446. if (p[0] > 0) {
  19447. this.eatBits(p[0]);
  19448. return p[1];
  19449. }
  19450. } else {
  19451. var result = this.findTableCode(1, 9, whiteTable2);
  19452. if (result[0]) {
  19453. return result[1];
  19454. }
  19455. result = this.findTableCode(11, 12, whiteTable1);
  19456. if (result[0]) {
  19457. return result[1];
  19458. }
  19459. }
  19460. info('bad white code');
  19461. this.eatBits(1);
  19462. return 1;
  19463. };
  19464. CCITTFaxStream.prototype.getBlackCode =
  19465. function ccittFaxStreamGetBlackCode() {
  19466. var code, p;
  19467. if (this.eoblock) {
  19468. code = this.lookBits(13);
  19469. if (code === EOF) {
  19470. return 1;
  19471. }
  19472. if ((code >> 7) === 0) {
  19473. p = blackTable1[code];
  19474. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  19475. p = blackTable2[(code >> 1) - 64];
  19476. } else {
  19477. p = blackTable3[code >> 7];
  19478. }
  19479. if (p[0] > 0) {
  19480. this.eatBits(p[0]);
  19481. return p[1];
  19482. }
  19483. } else {
  19484. var result = this.findTableCode(2, 6, blackTable3);
  19485. if (result[0]) {
  19486. return result[1];
  19487. }
  19488. result = this.findTableCode(7, 12, blackTable2, 64);
  19489. if (result[0]) {
  19490. return result[1];
  19491. }
  19492. result = this.findTableCode(10, 13, blackTable1);
  19493. if (result[0]) {
  19494. return result[1];
  19495. }
  19496. }
  19497. info('bad black code');
  19498. this.eatBits(1);
  19499. return 1;
  19500. };
  19501. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  19502. var c;
  19503. while (this.inputBits < n) {
  19504. if ((c = this.str.getByte()) === -1) {
  19505. if (this.inputBits === 0) {
  19506. return EOF;
  19507. }
  19508. return ((this.inputBuf << (n - this.inputBits)) &
  19509. (0xFFFF >> (16 - n)));
  19510. }
  19511. this.inputBuf = (this.inputBuf << 8) + c;
  19512. this.inputBits += 8;
  19513. }
  19514. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  19515. };
  19516. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  19517. if ((this.inputBits -= n) < 0) {
  19518. this.inputBits = 0;
  19519. }
  19520. };
  19521. return CCITTFaxStream;
  19522. })();
  19523. var LZWStream = (function LZWStreamClosure() {
  19524. function LZWStream(str, maybeLength, earlyChange) {
  19525. this.str = str;
  19526. this.dict = str.dict;
  19527. this.cachedData = 0;
  19528. this.bitsCached = 0;
  19529. var maxLzwDictionarySize = 4096;
  19530. var lzwState = {
  19531. earlyChange: earlyChange,
  19532. codeLength: 9,
  19533. nextCode: 258,
  19534. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  19535. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  19536. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  19537. currentSequence: new Uint8Array(maxLzwDictionarySize),
  19538. currentSequenceLength: 0
  19539. };
  19540. for (var i = 0; i < 256; ++i) {
  19541. lzwState.dictionaryValues[i] = i;
  19542. lzwState.dictionaryLengths[i] = 1;
  19543. }
  19544. this.lzwState = lzwState;
  19545. DecodeStream.call(this, maybeLength);
  19546. }
  19547. LZWStream.prototype = Object.create(DecodeStream.prototype);
  19548. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  19549. var bitsCached = this.bitsCached;
  19550. var cachedData = this.cachedData;
  19551. while (bitsCached < n) {
  19552. var c = this.str.getByte();
  19553. if (c === -1) {
  19554. this.eof = true;
  19555. return null;
  19556. }
  19557. cachedData = (cachedData << 8) | c;
  19558. bitsCached += 8;
  19559. }
  19560. this.bitsCached = (bitsCached -= n);
  19561. this.cachedData = cachedData;
  19562. this.lastCode = null;
  19563. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  19564. };
  19565. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  19566. var blockSize = 512;
  19567. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  19568. var i, j, q;
  19569. var lzwState = this.lzwState;
  19570. if (!lzwState) {
  19571. return; // eof was found
  19572. }
  19573. var earlyChange = lzwState.earlyChange;
  19574. var nextCode = lzwState.nextCode;
  19575. var dictionaryValues = lzwState.dictionaryValues;
  19576. var dictionaryLengths = lzwState.dictionaryLengths;
  19577. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  19578. var codeLength = lzwState.codeLength;
  19579. var prevCode = lzwState.prevCode;
  19580. var currentSequence = lzwState.currentSequence;
  19581. var currentSequenceLength = lzwState.currentSequenceLength;
  19582. var decodedLength = 0;
  19583. var currentBufferLength = this.bufferLength;
  19584. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  19585. for (i = 0; i < blockSize; i++) {
  19586. var code = this.readBits(codeLength);
  19587. var hasPrev = currentSequenceLength > 0;
  19588. if (code < 256) {
  19589. currentSequence[0] = code;
  19590. currentSequenceLength = 1;
  19591. } else if (code >= 258) {
  19592. if (code < nextCode) {
  19593. currentSequenceLength = dictionaryLengths[code];
  19594. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  19595. currentSequence[j] = dictionaryValues[q];
  19596. q = dictionaryPrevCodes[q];
  19597. }
  19598. } else {
  19599. currentSequence[currentSequenceLength++] = currentSequence[0];
  19600. }
  19601. } else if (code === 256) {
  19602. codeLength = 9;
  19603. nextCode = 258;
  19604. currentSequenceLength = 0;
  19605. continue;
  19606. } else {
  19607. this.eof = true;
  19608. delete this.lzwState;
  19609. break;
  19610. }
  19611. if (hasPrev) {
  19612. dictionaryPrevCodes[nextCode] = prevCode;
  19613. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  19614. dictionaryValues[nextCode] = currentSequence[0];
  19615. nextCode++;
  19616. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  19617. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  19618. 0.6931471805599453 + 1, 12) | 0;
  19619. }
  19620. prevCode = code;
  19621. decodedLength += currentSequenceLength;
  19622. if (estimatedDecodedSize < decodedLength) {
  19623. do {
  19624. estimatedDecodedSize += decodedSizeDelta;
  19625. } while (estimatedDecodedSize < decodedLength);
  19626. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  19627. }
  19628. for (j = 0; j < currentSequenceLength; j++) {
  19629. buffer[currentBufferLength++] = currentSequence[j];
  19630. }
  19631. }
  19632. lzwState.nextCode = nextCode;
  19633. lzwState.codeLength = codeLength;
  19634. lzwState.prevCode = prevCode;
  19635. lzwState.currentSequenceLength = currentSequenceLength;
  19636. this.bufferLength = currentBufferLength;
  19637. };
  19638. return LZWStream;
  19639. })();
  19640. var NullStream = (function NullStreamClosure() {
  19641. function NullStream() {
  19642. Stream.call(this, new Uint8Array(0));
  19643. }
  19644. NullStream.prototype = Stream.prototype;
  19645. return NullStream;
  19646. })();
  19647. // TODO refactor to remove dependency on parser.js
  19648. function _setCoreParser(coreParser_) {
  19649. coreParser = coreParser_;
  19650. EOF = coreParser_.EOF;
  19651. Lexer = coreParser_.Lexer;
  19652. }
  19653. exports._setCoreParser = _setCoreParser;
  19654. // TODO refactor to remove dependency on colorspace.js
  19655. function _setCoreColorSpace(coreColorSpace_) {
  19656. coreColorSpace = coreColorSpace_;
  19657. ColorSpace = coreColorSpace_.ColorSpace;
  19658. }
  19659. exports._setCoreColorSpace = _setCoreColorSpace;
  19660. exports.Ascii85Stream = Ascii85Stream;
  19661. exports.AsciiHexStream = AsciiHexStream;
  19662. exports.CCITTFaxStream = CCITTFaxStream;
  19663. exports.DecryptStream = DecryptStream;
  19664. exports.DecodeStream = DecodeStream;
  19665. exports.FlateStream = FlateStream;
  19666. exports.Jbig2Stream = Jbig2Stream;
  19667. exports.JpegStream = JpegStream;
  19668. exports.JpxStream = JpxStream;
  19669. exports.NullStream = NullStream;
  19670. exports.PredictorStream = PredictorStream;
  19671. exports.RunLengthStream = RunLengthStream;
  19672. exports.Stream = Stream;
  19673. exports.StreamsSequenceStream = StreamsSequenceStream;
  19674. exports.StringStream = StringStream;
  19675. exports.LZWStream = LZWStream;
  19676. }));
  19677. (function (root, factory) {
  19678. {
  19679. factory((root.pdfjsCoreCrypto = {}), root.pdfjsSharedUtil,
  19680. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  19681. }
  19682. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  19683. var PasswordException = sharedUtil.PasswordException;
  19684. var PasswordResponses = sharedUtil.PasswordResponses;
  19685. var bytesToString = sharedUtil.bytesToString;
  19686. var error = sharedUtil.error;
  19687. var isInt = sharedUtil.isInt;
  19688. var stringToBytes = sharedUtil.stringToBytes;
  19689. var utf8StringToString = sharedUtil.utf8StringToString;
  19690. var warn = sharedUtil.warn;
  19691. var Name = corePrimitives.Name;
  19692. var isName = corePrimitives.isName;
  19693. var isDict = corePrimitives.isDict;
  19694. var DecryptStream = coreStream.DecryptStream;
  19695. var ARCFourCipher = (function ARCFourCipherClosure() {
  19696. function ARCFourCipher(key) {
  19697. this.a = 0;
  19698. this.b = 0;
  19699. var s = new Uint8Array(256);
  19700. var i, j = 0, tmp, keyLength = key.length;
  19701. for (i = 0; i < 256; ++i) {
  19702. s[i] = i;
  19703. }
  19704. for (i = 0; i < 256; ++i) {
  19705. tmp = s[i];
  19706. j = (j + tmp + key[i % keyLength]) & 0xFF;
  19707. s[i] = s[j];
  19708. s[j] = tmp;
  19709. }
  19710. this.s = s;
  19711. }
  19712. ARCFourCipher.prototype = {
  19713. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  19714. var i, n = data.length, tmp, tmp2;
  19715. var a = this.a, b = this.b, s = this.s;
  19716. var output = new Uint8Array(n);
  19717. for (i = 0; i < n; ++i) {
  19718. a = (a + 1) & 0xFF;
  19719. tmp = s[a];
  19720. b = (b + tmp) & 0xFF;
  19721. tmp2 = s[b];
  19722. s[a] = tmp2;
  19723. s[b] = tmp;
  19724. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  19725. }
  19726. this.a = a;
  19727. this.b = b;
  19728. return output;
  19729. }
  19730. };
  19731. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  19732. return ARCFourCipher;
  19733. })();
  19734. var calculateMD5 = (function calculateMD5Closure() {
  19735. var r = new Uint8Array([
  19736. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  19737. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  19738. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  19739. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  19740. var k = new Int32Array([
  19741. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  19742. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  19743. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  19744. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  19745. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  19746. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  19747. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  19748. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  19749. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  19750. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  19751. -145523070, -1120210379, 718787259, -343485551]);
  19752. function hash(data, offset, length) {
  19753. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  19754. // pre-processing
  19755. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  19756. var padded = new Uint8Array(paddedLength);
  19757. var i, j, n;
  19758. for (i = 0; i < length; ++i) {
  19759. padded[i] = data[offset++];
  19760. }
  19761. padded[i++] = 0x80;
  19762. n = paddedLength - 8;
  19763. while (i < n) {
  19764. padded[i++] = 0;
  19765. }
  19766. padded[i++] = (length << 3) & 0xFF;
  19767. padded[i++] = (length >> 5) & 0xFF;
  19768. padded[i++] = (length >> 13) & 0xFF;
  19769. padded[i++] = (length >> 21) & 0xFF;
  19770. padded[i++] = (length >>> 29) & 0xFF;
  19771. padded[i++] = 0;
  19772. padded[i++] = 0;
  19773. padded[i++] = 0;
  19774. var w = new Int32Array(16);
  19775. for (i = 0; i < paddedLength;) {
  19776. for (j = 0; j < 16; ++j, i += 4) {
  19777. w[j] = (padded[i] | (padded[i + 1] << 8) |
  19778. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  19779. }
  19780. var a = h0, b = h1, c = h2, d = h3, f, g;
  19781. for (j = 0; j < 64; ++j) {
  19782. if (j < 16) {
  19783. f = (b & c) | ((~b) & d);
  19784. g = j;
  19785. } else if (j < 32) {
  19786. f = (d & b) | ((~d) & c);
  19787. g = (5 * j + 1) & 15;
  19788. } else if (j < 48) {
  19789. f = b ^ c ^ d;
  19790. g = (3 * j + 5) & 15;
  19791. } else {
  19792. f = c ^ (b | (~d));
  19793. g = (7 * j) & 15;
  19794. }
  19795. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  19796. d = c;
  19797. c = b;
  19798. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  19799. a = tmp;
  19800. }
  19801. h0 = (h0 + a) | 0;
  19802. h1 = (h1 + b) | 0;
  19803. h2 = (h2 + c) | 0;
  19804. h3 = (h3 + d) | 0;
  19805. }
  19806. return new Uint8Array([
  19807. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  19808. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  19809. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  19810. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  19811. ]);
  19812. }
  19813. return hash;
  19814. })();
  19815. var Word64 = (function Word64Closure() {
  19816. function Word64(highInteger, lowInteger) {
  19817. this.high = highInteger | 0;
  19818. this.low = lowInteger | 0;
  19819. }
  19820. Word64.prototype = {
  19821. and: function Word64_and(word) {
  19822. this.high &= word.high;
  19823. this.low &= word.low;
  19824. },
  19825. xor: function Word64_xor(word) {
  19826. this.high ^= word.high;
  19827. this.low ^= word.low;
  19828. },
  19829. or: function Word64_or(word) {
  19830. this.high |= word.high;
  19831. this.low |= word.low;
  19832. },
  19833. shiftRight: function Word64_shiftRight(places) {
  19834. if (places >= 32) {
  19835. this.low = (this.high >>> (places - 32)) | 0;
  19836. this.high = 0;
  19837. } else {
  19838. this.low = (this.low >>> places) | (this.high << (32 - places));
  19839. this.high = (this.high >>> places) | 0;
  19840. }
  19841. },
  19842. shiftLeft: function Word64_shiftLeft(places) {
  19843. if (places >= 32) {
  19844. this.high = this.low << (places - 32);
  19845. this.low = 0;
  19846. } else {
  19847. this.high = (this.high << places) | (this.low >>> (32 - places));
  19848. this.low = this.low << places;
  19849. }
  19850. },
  19851. rotateRight: function Word64_rotateRight(places) {
  19852. var low, high;
  19853. if (places & 32) {
  19854. high = this.low;
  19855. low = this.high;
  19856. } else {
  19857. low = this.low;
  19858. high = this.high;
  19859. }
  19860. places &= 31;
  19861. this.low = (low >>> places) | (high << (32 - places));
  19862. this.high = (high >>> places) | (low << (32 - places));
  19863. },
  19864. not: function Word64_not() {
  19865. this.high = ~this.high;
  19866. this.low = ~this.low;
  19867. },
  19868. add: function Word64_add(word) {
  19869. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  19870. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  19871. if (lowAdd > 0xFFFFFFFF) {
  19872. highAdd += 1;
  19873. }
  19874. this.low = lowAdd | 0;
  19875. this.high = highAdd | 0;
  19876. },
  19877. copyTo: function Word64_copyTo(bytes, offset) {
  19878. bytes[offset] = (this.high >>> 24) & 0xFF;
  19879. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  19880. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  19881. bytes[offset + 3] = this.high & 0xFF;
  19882. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  19883. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  19884. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  19885. bytes[offset + 7] = this.low & 0xFF;
  19886. },
  19887. assign: function Word64_assign(word) {
  19888. this.high = word.high;
  19889. this.low = word.low;
  19890. }
  19891. };
  19892. return Word64;
  19893. })();
  19894. var calculateSHA256 = (function calculateSHA256Closure() {
  19895. function rotr(x, n) {
  19896. return (x >>> n) | (x << 32 - n);
  19897. }
  19898. function ch(x, y, z) {
  19899. return (x & y) ^ (~x & z);
  19900. }
  19901. function maj(x, y, z) {
  19902. return (x & y) ^ (x & z) ^ (y & z);
  19903. }
  19904. function sigma(x) {
  19905. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  19906. }
  19907. function sigmaPrime(x) {
  19908. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  19909. }
  19910. function littleSigma(x) {
  19911. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  19912. }
  19913. function littleSigmaPrime(x) {
  19914. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  19915. }
  19916. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  19917. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  19918. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  19919. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  19920. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  19921. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  19922. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  19923. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  19924. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  19925. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  19926. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  19927. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  19928. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  19929. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  19930. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  19931. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  19932. function hash(data, offset, length) {
  19933. // initial hash values
  19934. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  19935. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  19936. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  19937. // pre-processing
  19938. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  19939. var padded = new Uint8Array(paddedLength);
  19940. var i, j, n;
  19941. for (i = 0; i < length; ++i) {
  19942. padded[i] = data[offset++];
  19943. }
  19944. padded[i++] = 0x80;
  19945. n = paddedLength - 8;
  19946. while (i < n) {
  19947. padded[i++] = 0;
  19948. }
  19949. padded[i++] = 0;
  19950. padded[i++] = 0;
  19951. padded[i++] = 0;
  19952. padded[i++] = (length >>> 29) & 0xFF;
  19953. padded[i++] = (length >> 21) & 0xFF;
  19954. padded[i++] = (length >> 13) & 0xFF;
  19955. padded[i++] = (length >> 5) & 0xFF;
  19956. padded[i++] = (length << 3) & 0xFF;
  19957. var w = new Uint32Array(64);
  19958. // for each 512 bit block
  19959. for (i = 0; i < paddedLength;) {
  19960. for (j = 0; j < 16; ++j) {
  19961. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  19962. (padded[i + 2] << 8) | (padded[i + 3]));
  19963. i += 4;
  19964. }
  19965. for (j = 16; j < 64; ++j) {
  19966. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  19967. littleSigma(w[j - 15]) + w[j - 16] | 0;
  19968. }
  19969. var a = h0, b = h1, c = h2, d = h3, e = h4,
  19970. f = h5, g = h6, h = h7, t1, t2;
  19971. for (j = 0; j < 64; ++j) {
  19972. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  19973. t2 = sigma(a) + maj(a, b, c);
  19974. h = g;
  19975. g = f;
  19976. f = e;
  19977. e = (d + t1) | 0;
  19978. d = c;
  19979. c = b;
  19980. b = a;
  19981. a = (t1 + t2) | 0;
  19982. }
  19983. h0 = (h0 + a) | 0;
  19984. h1 = (h1 + b) | 0;
  19985. h2 = (h2 + c) | 0;
  19986. h3 = (h3 + d) | 0;
  19987. h4 = (h4 + e) | 0;
  19988. h5 = (h5 + f) | 0;
  19989. h6 = (h6 + g) | 0;
  19990. h7 = (h7 + h) | 0;
  19991. }
  19992. return new Uint8Array([
  19993. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  19994. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  19995. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  19996. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  19997. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  19998. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  19999. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  20000. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  20001. ]);
  20002. }
  20003. return hash;
  20004. })();
  20005. var calculateSHA512 = (function calculateSHA512Closure() {
  20006. function ch(result, x, y, z, tmp) {
  20007. result.assign(x);
  20008. result.and(y);
  20009. tmp.assign(x);
  20010. tmp.not();
  20011. tmp.and(z);
  20012. result.xor(tmp);
  20013. }
  20014. function maj(result, x, y, z, tmp) {
  20015. result.assign(x);
  20016. result.and(y);
  20017. tmp.assign(x);
  20018. tmp.and(z);
  20019. result.xor(tmp);
  20020. tmp.assign(y);
  20021. tmp.and(z);
  20022. result.xor(tmp);
  20023. }
  20024. function sigma(result, x, tmp) {
  20025. result.assign(x);
  20026. result.rotateRight(28);
  20027. tmp.assign(x);
  20028. tmp.rotateRight(34);
  20029. result.xor(tmp);
  20030. tmp.assign(x);
  20031. tmp.rotateRight(39);
  20032. result.xor(tmp);
  20033. }
  20034. function sigmaPrime(result, x, tmp) {
  20035. result.assign(x);
  20036. result.rotateRight(14);
  20037. tmp.assign(x);
  20038. tmp.rotateRight(18);
  20039. result.xor(tmp);
  20040. tmp.assign(x);
  20041. tmp.rotateRight(41);
  20042. result.xor(tmp);
  20043. }
  20044. function littleSigma(result, x, tmp) {
  20045. result.assign(x);
  20046. result.rotateRight(1);
  20047. tmp.assign(x);
  20048. tmp.rotateRight(8);
  20049. result.xor(tmp);
  20050. tmp.assign(x);
  20051. tmp.shiftRight(7);
  20052. result.xor(tmp);
  20053. }
  20054. function littleSigmaPrime(result, x, tmp) {
  20055. result.assign(x);
  20056. result.rotateRight(19);
  20057. tmp.assign(x);
  20058. tmp.rotateRight(61);
  20059. result.xor(tmp);
  20060. tmp.assign(x);
  20061. tmp.shiftRight(6);
  20062. result.xor(tmp);
  20063. }
  20064. var k = [
  20065. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  20066. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  20067. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  20068. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  20069. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  20070. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  20071. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  20072. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  20073. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  20074. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  20075. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  20076. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  20077. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  20078. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  20079. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  20080. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  20081. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  20082. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  20083. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  20084. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  20085. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  20086. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  20087. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  20088. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  20089. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  20090. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  20091. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  20092. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  20093. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  20094. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  20095. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  20096. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  20097. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  20098. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  20099. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  20100. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  20101. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  20102. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  20103. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  20104. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  20105. function hash(data, offset, length, mode384) {
  20106. mode384 = !!mode384;
  20107. // initial hash values
  20108. var h0, h1, h2, h3, h4, h5, h6, h7;
  20109. if (!mode384) {
  20110. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  20111. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  20112. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  20113. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  20114. h4 = new Word64(0x510e527f, 0xade682d1);
  20115. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  20116. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  20117. h7 = new Word64(0x5be0cd19, 0x137e2179);
  20118. }
  20119. else {
  20120. // SHA384 is exactly the same
  20121. // except with different starting values and a trimmed result
  20122. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  20123. h1 = new Word64(0x629a292a, 0x367cd507);
  20124. h2 = new Word64(0x9159015a, 0x3070dd17);
  20125. h3 = new Word64(0x152fecd8, 0xf70e5939);
  20126. h4 = new Word64(0x67332667, 0xffc00b31);
  20127. h5 = new Word64(0x8eb44a87, 0x68581511);
  20128. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  20129. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  20130. }
  20131. // pre-processing
  20132. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  20133. var padded = new Uint8Array(paddedLength);
  20134. var i, j, n;
  20135. for (i = 0; i < length; ++i) {
  20136. padded[i] = data[offset++];
  20137. }
  20138. padded[i++] = 0x80;
  20139. n = paddedLength - 16;
  20140. while (i < n) {
  20141. padded[i++] = 0;
  20142. }
  20143. padded[i++] = 0;
  20144. padded[i++] = 0;
  20145. padded[i++] = 0;
  20146. padded[i++] = 0;
  20147. padded[i++] = 0;
  20148. padded[i++] = 0;
  20149. padded[i++] = 0;
  20150. padded[i++] = 0;
  20151. padded[i++] = 0;
  20152. padded[i++] = 0;
  20153. padded[i++] = 0;
  20154. padded[i++] = (length >>> 29) & 0xFF;
  20155. padded[i++] = (length >> 21) & 0xFF;
  20156. padded[i++] = (length >> 13) & 0xFF;
  20157. padded[i++] = (length >> 5) & 0xFF;
  20158. padded[i++] = (length << 3) & 0xFF;
  20159. var w = new Array(80);
  20160. for (i = 0; i < 80; i++) {
  20161. w[i] = new Word64(0, 0);
  20162. }
  20163. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  20164. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  20165. var g = new Word64(0, 0), h = new Word64(0, 0);
  20166. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  20167. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  20168. // for each 1024 bit block
  20169. for (i = 0; i < paddedLength;) {
  20170. for (j = 0; j < 16; ++j) {
  20171. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  20172. (padded[i + 2] << 8) | (padded[i + 3]);
  20173. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  20174. (padded[i + 6]) << 8 | (padded[i + 7]);
  20175. i += 8;
  20176. }
  20177. for (j = 16; j < 80; ++j) {
  20178. tmp3 = w[j];
  20179. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  20180. tmp3.add(w[j - 7]);
  20181. littleSigma(tmp1, w[j - 15], tmp2);
  20182. tmp3.add(tmp1);
  20183. tmp3.add(w[j - 16]);
  20184. }
  20185. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  20186. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  20187. for (j = 0; j < 80; ++j) {
  20188. t1.assign(h);
  20189. sigmaPrime(tmp1, e, tmp2);
  20190. t1.add(tmp1);
  20191. ch(tmp1, e, f, g, tmp2);
  20192. t1.add(tmp1);
  20193. t1.add(k[j]);
  20194. t1.add(w[j]);
  20195. sigma(t2, a, tmp2);
  20196. maj(tmp1, a, b, c, tmp2);
  20197. t2.add(tmp1);
  20198. tmp3 = h;
  20199. h = g;
  20200. g = f;
  20201. f = e;
  20202. d.add(t1);
  20203. e = d;
  20204. d = c;
  20205. c = b;
  20206. b = a;
  20207. tmp3.assign(t1);
  20208. tmp3.add(t2);
  20209. a = tmp3;
  20210. }
  20211. h0.add(a);
  20212. h1.add(b);
  20213. h2.add(c);
  20214. h3.add(d);
  20215. h4.add(e);
  20216. h5.add(f);
  20217. h6.add(g);
  20218. h7.add(h);
  20219. }
  20220. var result;
  20221. if (!mode384) {
  20222. result = new Uint8Array(64);
  20223. h0.copyTo(result,0);
  20224. h1.copyTo(result,8);
  20225. h2.copyTo(result,16);
  20226. h3.copyTo(result,24);
  20227. h4.copyTo(result,32);
  20228. h5.copyTo(result,40);
  20229. h6.copyTo(result,48);
  20230. h7.copyTo(result,56);
  20231. }
  20232. else {
  20233. result = new Uint8Array(48);
  20234. h0.copyTo(result,0);
  20235. h1.copyTo(result,8);
  20236. h2.copyTo(result,16);
  20237. h3.copyTo(result,24);
  20238. h4.copyTo(result,32);
  20239. h5.copyTo(result,40);
  20240. }
  20241. return result;
  20242. }
  20243. return hash;
  20244. })();
  20245. var calculateSHA384 = (function calculateSHA384Closure() {
  20246. function hash(data, offset, length) {
  20247. return calculateSHA512(data, offset, length, true);
  20248. }
  20249. return hash;
  20250. })();
  20251. var NullCipher = (function NullCipherClosure() {
  20252. function NullCipher() {
  20253. }
  20254. NullCipher.prototype = {
  20255. decryptBlock: function NullCipher_decryptBlock(data) {
  20256. return data;
  20257. }
  20258. };
  20259. return NullCipher;
  20260. })();
  20261. var AES128Cipher = (function AES128CipherClosure() {
  20262. var rcon = new Uint8Array([
  20263. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  20264. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  20265. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  20266. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  20267. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  20268. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  20269. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  20270. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  20271. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  20272. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  20273. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  20274. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  20275. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  20276. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  20277. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  20278. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  20279. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  20280. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  20281. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  20282. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  20283. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  20284. 0x74, 0xe8, 0xcb, 0x8d]);
  20285. var s = new Uint8Array([
  20286. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  20287. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  20288. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  20289. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  20290. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  20291. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  20292. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  20293. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  20294. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  20295. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  20296. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  20297. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  20298. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  20299. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  20300. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  20301. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  20302. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  20303. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  20304. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  20305. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  20306. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  20307. 0xb0, 0x54, 0xbb, 0x16]);
  20308. var inv_s = new Uint8Array([
  20309. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  20310. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  20311. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  20312. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  20313. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  20314. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  20315. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  20316. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  20317. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  20318. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  20319. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  20320. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  20321. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  20322. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  20323. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  20324. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  20325. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  20326. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  20327. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  20328. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  20329. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  20330. 0x55, 0x21, 0x0c, 0x7d]);
  20331. var mixCol = new Uint8Array(256);
  20332. for (var i = 0; i < 256; i++) {
  20333. if (i < 128) {
  20334. mixCol[i] = i << 1;
  20335. } else {
  20336. mixCol[i] = (i << 1) ^ 0x1b;
  20337. }
  20338. }
  20339. var mix = new Uint32Array([
  20340. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  20341. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  20342. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  20343. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  20344. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  20345. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  20346. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  20347. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  20348. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  20349. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  20350. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  20351. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  20352. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  20353. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  20354. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  20355. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  20356. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  20357. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  20358. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  20359. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  20360. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  20361. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  20362. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  20363. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  20364. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  20365. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  20366. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  20367. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  20368. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  20369. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  20370. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  20371. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  20372. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  20373. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  20374. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  20375. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  20376. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  20377. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  20378. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  20379. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  20380. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  20381. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  20382. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  20383. function expandKey128(cipherKey) {
  20384. var b = 176, result = new Uint8Array(b);
  20385. result.set(cipherKey);
  20386. for (var j = 16, i = 1; j < b; ++i) {
  20387. // RotWord
  20388. var t1 = result[j - 3], t2 = result[j - 2],
  20389. t3 = result[j - 1], t4 = result[j - 4];
  20390. // SubWord
  20391. t1 = s[t1];
  20392. t2 = s[t2];
  20393. t3 = s[t3];
  20394. t4 = s[t4];
  20395. // Rcon
  20396. t1 = t1 ^ rcon[i];
  20397. for (var n = 0; n < 4; ++n) {
  20398. result[j] = (t1 ^= result[j - 16]);
  20399. j++;
  20400. result[j] = (t2 ^= result[j - 16]);
  20401. j++;
  20402. result[j] = (t3 ^= result[j - 16]);
  20403. j++;
  20404. result[j] = (t4 ^= result[j - 16]);
  20405. j++;
  20406. }
  20407. }
  20408. return result;
  20409. }
  20410. function decrypt128(input, key) {
  20411. var state = new Uint8Array(16);
  20412. state.set(input);
  20413. var i, j, k;
  20414. var t, u, v;
  20415. // AddRoundKey
  20416. for (j = 0, k = 160; j < 16; ++j, ++k) {
  20417. state[j] ^= key[k];
  20418. }
  20419. for (i = 9; i >= 1; --i) {
  20420. // InvShiftRows
  20421. t = state[13];
  20422. state[13] = state[9];
  20423. state[9] = state[5];
  20424. state[5] = state[1];
  20425. state[1] = t;
  20426. t = state[14];
  20427. u = state[10];
  20428. state[14] = state[6];
  20429. state[10] = state[2];
  20430. state[6] = t;
  20431. state[2] = u;
  20432. t = state[15];
  20433. u = state[11];
  20434. v = state[7];
  20435. state[15] = state[3];
  20436. state[11] = t;
  20437. state[7] = u;
  20438. state[3] = v;
  20439. // InvSubBytes
  20440. for (j = 0; j < 16; ++j) {
  20441. state[j] = inv_s[state[j]];
  20442. }
  20443. // AddRoundKey
  20444. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  20445. state[j] ^= key[k];
  20446. }
  20447. // InvMixColumns
  20448. for (j = 0; j < 16; j += 4) {
  20449. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  20450. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  20451. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  20452. (s3 >>> 24) ^ (s3 << 8));
  20453. state[j] = (t >>> 24) & 0xFF;
  20454. state[j + 1] = (t >> 16) & 0xFF;
  20455. state[j + 2] = (t >> 8) & 0xFF;
  20456. state[j + 3] = t & 0xFF;
  20457. }
  20458. }
  20459. // InvShiftRows
  20460. t = state[13];
  20461. state[13] = state[9];
  20462. state[9] = state[5];
  20463. state[5] = state[1];
  20464. state[1] = t;
  20465. t = state[14];
  20466. u = state[10];
  20467. state[14] = state[6];
  20468. state[10] = state[2];
  20469. state[6] = t;
  20470. state[2] = u;
  20471. t = state[15];
  20472. u = state[11];
  20473. v = state[7];
  20474. state[15] = state[3];
  20475. state[11] = t;
  20476. state[7] = u;
  20477. state[3] = v;
  20478. for (j = 0; j < 16; ++j) {
  20479. // InvSubBytes
  20480. state[j] = inv_s[state[j]];
  20481. // AddRoundKey
  20482. state[j] ^= key[j];
  20483. }
  20484. return state;
  20485. }
  20486. function encrypt128(input, key) {
  20487. var t, u, v, k;
  20488. var state = new Uint8Array(16);
  20489. state.set(input);
  20490. for (j = 0; j < 16; ++j) {
  20491. // AddRoundKey
  20492. state[j] ^= key[j];
  20493. }
  20494. for (i = 1; i < 10; i++) {
  20495. //SubBytes
  20496. for (j = 0; j < 16; ++j) {
  20497. state[j] = s[state[j]];
  20498. }
  20499. //ShiftRows
  20500. v = state[1];
  20501. state[1] = state[5];
  20502. state[5] = state[9];
  20503. state[9] = state[13];
  20504. state[13] = v;
  20505. v = state[2];
  20506. u = state[6];
  20507. state[2] = state[10];
  20508. state[6] = state[14];
  20509. state[10] = v;
  20510. state[14] = u;
  20511. v = state[3];
  20512. u = state[7];
  20513. t = state[11];
  20514. state[3] = state[15];
  20515. state[7] = v;
  20516. state[11] = u;
  20517. state[15] = t;
  20518. //MixColumns
  20519. for (var j = 0; j < 16; j += 4) {
  20520. var s0 = state[j + 0], s1 = state[j + 1];
  20521. var s2 = state[j + 2], s3 = state[j + 3];
  20522. t = s0 ^ s1 ^ s2 ^ s3;
  20523. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  20524. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  20525. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  20526. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  20527. }
  20528. //AddRoundKey
  20529. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  20530. state[j] ^= key[k];
  20531. }
  20532. }
  20533. //SubBytes
  20534. for (j = 0; j < 16; ++j) {
  20535. state[j] = s[state[j]];
  20536. }
  20537. //ShiftRows
  20538. v = state[1];
  20539. state[1] = state[5];
  20540. state[5] = state[9];
  20541. state[9] = state[13];
  20542. state[13] = v;
  20543. v = state[2];
  20544. u = state[6];
  20545. state[2] = state[10];
  20546. state[6] = state[14];
  20547. state[10] = v;
  20548. state[14] = u;
  20549. v = state[3];
  20550. u = state[7];
  20551. t = state[11];
  20552. state[3] = state[15];
  20553. state[7] = v;
  20554. state[11] = u;
  20555. state[15] = t;
  20556. //AddRoundKey
  20557. for (j = 0, k = 160; j < 16; ++j, ++k) {
  20558. state[j] ^= key[k];
  20559. }
  20560. return state;
  20561. }
  20562. function AES128Cipher(key) {
  20563. this.key = expandKey128(key);
  20564. this.buffer = new Uint8Array(16);
  20565. this.bufferPosition = 0;
  20566. }
  20567. function decryptBlock2(data, finalize) {
  20568. var i, j, ii, sourceLength = data.length,
  20569. buffer = this.buffer, bufferLength = this.bufferPosition,
  20570. result = [], iv = this.iv;
  20571. for (i = 0; i < sourceLength; ++i) {
  20572. buffer[bufferLength] = data[i];
  20573. ++bufferLength;
  20574. if (bufferLength < 16) {
  20575. continue;
  20576. }
  20577. // buffer is full, decrypting
  20578. var plain = decrypt128(buffer, this.key);
  20579. // xor-ing the IV vector to get plain text
  20580. for (j = 0; j < 16; ++j) {
  20581. plain[j] ^= iv[j];
  20582. }
  20583. iv = buffer;
  20584. result.push(plain);
  20585. buffer = new Uint8Array(16);
  20586. bufferLength = 0;
  20587. }
  20588. // saving incomplete buffer
  20589. this.buffer = buffer;
  20590. this.bufferLength = bufferLength;
  20591. this.iv = iv;
  20592. if (result.length === 0) {
  20593. return new Uint8Array([]);
  20594. }
  20595. // combining plain text blocks into one
  20596. var outputLength = 16 * result.length;
  20597. if (finalize) {
  20598. // undo a padding that is described in RFC 2898
  20599. var lastBlock = result[result.length - 1];
  20600. var psLen = lastBlock[15];
  20601. if (psLen <= 16) {
  20602. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  20603. if (lastBlock[i] !== psLen) {
  20604. // Invalid padding, assume that the block has no padding.
  20605. psLen = 0;
  20606. break;
  20607. }
  20608. }
  20609. outputLength -= psLen;
  20610. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  20611. }
  20612. }
  20613. var output = new Uint8Array(outputLength);
  20614. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  20615. output.set(result[i], j);
  20616. }
  20617. return output;
  20618. }
  20619. AES128Cipher.prototype = {
  20620. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  20621. var i, sourceLength = data.length;
  20622. var buffer = this.buffer, bufferLength = this.bufferPosition;
  20623. // waiting for IV values -- they are at the start of the stream
  20624. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  20625. buffer[bufferLength] = data[i];
  20626. }
  20627. if (bufferLength < 16) {
  20628. // need more data
  20629. this.bufferLength = bufferLength;
  20630. return new Uint8Array([]);
  20631. }
  20632. this.iv = buffer;
  20633. this.buffer = new Uint8Array(16);
  20634. this.bufferLength = 0;
  20635. // starting decryption
  20636. this.decryptBlock = decryptBlock2;
  20637. return this.decryptBlock(data.subarray(16), finalize);
  20638. },
  20639. encrypt: function AES128Cipher_encrypt(data, iv) {
  20640. var i, j, ii, sourceLength = data.length,
  20641. buffer = this.buffer, bufferLength = this.bufferPosition,
  20642. result = [];
  20643. if (!iv) {
  20644. iv = new Uint8Array(16);
  20645. }
  20646. for (i = 0; i < sourceLength; ++i) {
  20647. buffer[bufferLength] = data[i];
  20648. ++bufferLength;
  20649. if (bufferLength < 16) {
  20650. continue;
  20651. }
  20652. for (j = 0; j < 16; ++j) {
  20653. buffer[j] ^= iv[j];
  20654. }
  20655. // buffer is full, encrypting
  20656. var cipher = encrypt128(buffer, this.key);
  20657. iv = cipher;
  20658. result.push(cipher);
  20659. buffer = new Uint8Array(16);
  20660. bufferLength = 0;
  20661. }
  20662. // saving incomplete buffer
  20663. this.buffer = buffer;
  20664. this.bufferLength = bufferLength;
  20665. this.iv = iv;
  20666. if (result.length === 0) {
  20667. return new Uint8Array([]);
  20668. }
  20669. // combining plain text blocks into one
  20670. var outputLength = 16 * result.length;
  20671. var output = new Uint8Array(outputLength);
  20672. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  20673. output.set(result[i], j);
  20674. }
  20675. return output;
  20676. }
  20677. };
  20678. return AES128Cipher;
  20679. })();
  20680. var AES256Cipher = (function AES256CipherClosure() {
  20681. var rcon = new Uint8Array([
  20682. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  20683. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  20684. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  20685. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  20686. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  20687. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  20688. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  20689. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  20690. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  20691. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  20692. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  20693. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  20694. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  20695. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  20696. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  20697. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  20698. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  20699. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  20700. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  20701. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  20702. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  20703. 0x74, 0xe8, 0xcb, 0x8d]);
  20704. var s = new Uint8Array([
  20705. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  20706. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  20707. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  20708. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  20709. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  20710. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  20711. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  20712. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  20713. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  20714. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  20715. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  20716. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  20717. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  20718. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  20719. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  20720. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  20721. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  20722. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  20723. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  20724. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  20725. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  20726. 0xb0, 0x54, 0xbb, 0x16]);
  20727. var inv_s = new Uint8Array([
  20728. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  20729. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  20730. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  20731. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  20732. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  20733. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  20734. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  20735. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  20736. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  20737. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  20738. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  20739. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  20740. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  20741. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  20742. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  20743. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  20744. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  20745. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  20746. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  20747. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  20748. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  20749. 0x55, 0x21, 0x0c, 0x7d]);
  20750. var mixCol = new Uint8Array(256);
  20751. for (var i = 0; i < 256; i++) {
  20752. if (i < 128) {
  20753. mixCol[i] = i << 1;
  20754. } else {
  20755. mixCol[i] = (i << 1) ^ 0x1b;
  20756. }
  20757. }
  20758. var mix = new Uint32Array([
  20759. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  20760. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  20761. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  20762. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  20763. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  20764. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  20765. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  20766. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  20767. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  20768. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  20769. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  20770. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  20771. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  20772. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  20773. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  20774. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  20775. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  20776. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  20777. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  20778. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  20779. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  20780. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  20781. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  20782. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  20783. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  20784. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  20785. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  20786. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  20787. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  20788. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  20789. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  20790. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  20791. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  20792. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  20793. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  20794. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  20795. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  20796. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  20797. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  20798. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  20799. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  20800. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  20801. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  20802. function expandKey256(cipherKey) {
  20803. var b = 240, result = new Uint8Array(b);
  20804. var r = 1;
  20805. result.set(cipherKey);
  20806. for (var j = 32, i = 1; j < b; ++i) {
  20807. if (j % 32 === 16) {
  20808. t1 = s[t1];
  20809. t2 = s[t2];
  20810. t3 = s[t3];
  20811. t4 = s[t4];
  20812. } else if (j % 32 === 0) {
  20813. // RotWord
  20814. var t1 = result[j - 3], t2 = result[j - 2],
  20815. t3 = result[j - 1], t4 = result[j - 4];
  20816. // SubWord
  20817. t1 = s[t1];
  20818. t2 = s[t2];
  20819. t3 = s[t3];
  20820. t4 = s[t4];
  20821. // Rcon
  20822. t1 = t1 ^ r;
  20823. if ((r <<= 1) >= 256) {
  20824. r = (r ^ 0x1b) & 0xFF;
  20825. }
  20826. }
  20827. for (var n = 0; n < 4; ++n) {
  20828. result[j] = (t1 ^= result[j - 32]);
  20829. j++;
  20830. result[j] = (t2 ^= result[j - 32]);
  20831. j++;
  20832. result[j] = (t3 ^= result[j - 32]);
  20833. j++;
  20834. result[j] = (t4 ^= result[j - 32]);
  20835. j++;
  20836. }
  20837. }
  20838. return result;
  20839. }
  20840. function decrypt256(input, key) {
  20841. var state = new Uint8Array(16);
  20842. state.set(input);
  20843. var i, j, k;
  20844. var t, u, v;
  20845. // AddRoundKey
  20846. for (j = 0, k = 224; j < 16; ++j, ++k) {
  20847. state[j] ^= key[k];
  20848. }
  20849. for (i = 13; i >= 1; --i) {
  20850. // InvShiftRows
  20851. t = state[13];
  20852. state[13] = state[9];
  20853. state[9] = state[5];
  20854. state[5] = state[1];
  20855. state[1] = t;
  20856. t = state[14];
  20857. u = state[10];
  20858. state[14] = state[6];
  20859. state[10] = state[2];
  20860. state[6] = t;
  20861. state[2] = u;
  20862. t = state[15];
  20863. u = state[11];
  20864. v = state[7];
  20865. state[15] = state[3];
  20866. state[11] = t;
  20867. state[7] = u;
  20868. state[3] = v;
  20869. // InvSubBytes
  20870. for (j = 0; j < 16; ++j) {
  20871. state[j] = inv_s[state[j]];
  20872. }
  20873. // AddRoundKey
  20874. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  20875. state[j] ^= key[k];
  20876. }
  20877. // InvMixColumns
  20878. for (j = 0; j < 16; j += 4) {
  20879. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  20880. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  20881. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  20882. (s3 >>> 24) ^ (s3 << 8));
  20883. state[j] = (t >>> 24) & 0xFF;
  20884. state[j + 1] = (t >> 16) & 0xFF;
  20885. state[j + 2] = (t >> 8) & 0xFF;
  20886. state[j + 3] = t & 0xFF;
  20887. }
  20888. }
  20889. // InvShiftRows
  20890. t = state[13];
  20891. state[13] = state[9];
  20892. state[9] = state[5];
  20893. state[5] = state[1];
  20894. state[1] = t;
  20895. t = state[14];
  20896. u = state[10];
  20897. state[14] = state[6];
  20898. state[10] = state[2];
  20899. state[6] = t;
  20900. state[2] = u;
  20901. t = state[15];
  20902. u = state[11];
  20903. v = state[7];
  20904. state[15] = state[3];
  20905. state[11] = t;
  20906. state[7] = u;
  20907. state[3] = v;
  20908. for (j = 0; j < 16; ++j) {
  20909. // InvSubBytes
  20910. state[j] = inv_s[state[j]];
  20911. // AddRoundKey
  20912. state[j] ^= key[j];
  20913. }
  20914. return state;
  20915. }
  20916. function encrypt256(input, key) {
  20917. var t, u, v, k;
  20918. var state = new Uint8Array(16);
  20919. state.set(input);
  20920. for (j = 0; j < 16; ++j) {
  20921. // AddRoundKey
  20922. state[j] ^= key[j];
  20923. }
  20924. for (i = 1; i < 14; i++) {
  20925. //SubBytes
  20926. for (j = 0; j < 16; ++j) {
  20927. state[j] = s[state[j]];
  20928. }
  20929. //ShiftRows
  20930. v = state[1];
  20931. state[1] = state[5];
  20932. state[5] = state[9];
  20933. state[9] = state[13];
  20934. state[13] = v;
  20935. v = state[2];
  20936. u = state[6];
  20937. state[2] = state[10];
  20938. state[6] = state[14];
  20939. state[10] = v;
  20940. state[14] = u;
  20941. v = state[3];
  20942. u = state[7];
  20943. t = state[11];
  20944. state[3] = state[15];
  20945. state[7] = v;
  20946. state[11] = u;
  20947. state[15] = t;
  20948. //MixColumns
  20949. for (var j = 0; j < 16; j += 4) {
  20950. var s0 = state[j + 0], s1 = state[j + 1];
  20951. var s2 = state[j + 2], s3 = state[j + 3];
  20952. t = s0 ^ s1 ^ s2 ^ s3;
  20953. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  20954. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  20955. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  20956. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  20957. }
  20958. //AddRoundKey
  20959. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  20960. state[j] ^= key[k];
  20961. }
  20962. }
  20963. //SubBytes
  20964. for (j = 0; j < 16; ++j) {
  20965. state[j] = s[state[j]];
  20966. }
  20967. //ShiftRows
  20968. v = state[1];
  20969. state[1] = state[5];
  20970. state[5] = state[9];
  20971. state[9] = state[13];
  20972. state[13] = v;
  20973. v = state[2];
  20974. u = state[6];
  20975. state[2] = state[10];
  20976. state[6] = state[14];
  20977. state[10] = v;
  20978. state[14] = u;
  20979. v = state[3];
  20980. u = state[7];
  20981. t = state[11];
  20982. state[3] = state[15];
  20983. state[7] = v;
  20984. state[11] = u;
  20985. state[15] = t;
  20986. //AddRoundKey
  20987. for (j = 0, k = 224; j < 16; ++j, ++k) {
  20988. state[j] ^= key[k];
  20989. }
  20990. return state;
  20991. }
  20992. function AES256Cipher(key) {
  20993. this.key = expandKey256(key);
  20994. this.buffer = new Uint8Array(16);
  20995. this.bufferPosition = 0;
  20996. }
  20997. function decryptBlock2(data, finalize) {
  20998. var i, j, ii, sourceLength = data.length,
  20999. buffer = this.buffer, bufferLength = this.bufferPosition,
  21000. result = [], iv = this.iv;
  21001. for (i = 0; i < sourceLength; ++i) {
  21002. buffer[bufferLength] = data[i];
  21003. ++bufferLength;
  21004. if (bufferLength < 16) {
  21005. continue;
  21006. }
  21007. // buffer is full, decrypting
  21008. var plain = decrypt256(buffer, this.key);
  21009. // xor-ing the IV vector to get plain text
  21010. for (j = 0; j < 16; ++j) {
  21011. plain[j] ^= iv[j];
  21012. }
  21013. iv = buffer;
  21014. result.push(plain);
  21015. buffer = new Uint8Array(16);
  21016. bufferLength = 0;
  21017. }
  21018. // saving incomplete buffer
  21019. this.buffer = buffer;
  21020. this.bufferLength = bufferLength;
  21021. this.iv = iv;
  21022. if (result.length === 0) {
  21023. return new Uint8Array([]);
  21024. }
  21025. // combining plain text blocks into one
  21026. var outputLength = 16 * result.length;
  21027. if (finalize) {
  21028. // undo a padding that is described in RFC 2898
  21029. var lastBlock = result[result.length - 1];
  21030. var psLen = lastBlock[15];
  21031. if (psLen <= 16) {
  21032. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  21033. if (lastBlock[i] !== psLen) {
  21034. // Invalid padding, assume that the block has no padding.
  21035. psLen = 0;
  21036. break;
  21037. }
  21038. }
  21039. outputLength -= psLen;
  21040. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  21041. }
  21042. }
  21043. var output = new Uint8Array(outputLength);
  21044. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  21045. output.set(result[i], j);
  21046. }
  21047. return output;
  21048. }
  21049. AES256Cipher.prototype = {
  21050. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  21051. var i, sourceLength = data.length;
  21052. var buffer = this.buffer, bufferLength = this.bufferPosition;
  21053. // if not supplied an IV wait for IV values
  21054. // they are at the start of the stream
  21055. if (iv) {
  21056. this.iv = iv;
  21057. } else {
  21058. for (i = 0; bufferLength < 16 &&
  21059. i < sourceLength; ++i, ++bufferLength) {
  21060. buffer[bufferLength] = data[i];
  21061. }
  21062. if (bufferLength < 16) {
  21063. //need more data
  21064. this.bufferLength = bufferLength;
  21065. return new Uint8Array([]);
  21066. }
  21067. this.iv = buffer;
  21068. data = data.subarray(16);
  21069. }
  21070. this.buffer = new Uint8Array(16);
  21071. this.bufferLength = 0;
  21072. // starting decryption
  21073. this.decryptBlock = decryptBlock2;
  21074. return this.decryptBlock(data, finalize);
  21075. },
  21076. encrypt: function AES256Cipher_encrypt(data, iv) {
  21077. var i, j, ii, sourceLength = data.length,
  21078. buffer = this.buffer, bufferLength = this.bufferPosition,
  21079. result = [];
  21080. if (!iv) {
  21081. iv = new Uint8Array(16);
  21082. }
  21083. for (i = 0; i < sourceLength; ++i) {
  21084. buffer[bufferLength] = data[i];
  21085. ++bufferLength;
  21086. if (bufferLength < 16) {
  21087. continue;
  21088. }
  21089. for (j = 0; j < 16; ++j) {
  21090. buffer[j] ^= iv[j];
  21091. }
  21092. // buffer is full, encrypting
  21093. var cipher = encrypt256(buffer, this.key);
  21094. this.iv = cipher;
  21095. result.push(cipher);
  21096. buffer = new Uint8Array(16);
  21097. bufferLength = 0;
  21098. }
  21099. // saving incomplete buffer
  21100. this.buffer = buffer;
  21101. this.bufferLength = bufferLength;
  21102. this.iv = iv;
  21103. if (result.length === 0) {
  21104. return new Uint8Array([]);
  21105. }
  21106. // combining plain text blocks into one
  21107. var outputLength = 16 * result.length;
  21108. var output = new Uint8Array(outputLength);
  21109. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  21110. output.set(result[i], j);
  21111. }
  21112. return output;
  21113. }
  21114. };
  21115. return AES256Cipher;
  21116. })();
  21117. var PDF17 = (function PDF17Closure() {
  21118. function compareByteArrays(array1, array2) {
  21119. if (array1.length !== array2.length) {
  21120. return false;
  21121. }
  21122. for (var i = 0; i < array1.length; i++) {
  21123. if (array1[i] !== array2[i]) {
  21124. return false;
  21125. }
  21126. }
  21127. return true;
  21128. }
  21129. function PDF17() {
  21130. }
  21131. PDF17.prototype = {
  21132. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  21133. ownerValidationSalt,
  21134. userBytes,
  21135. ownerPassword) {
  21136. var hashData = new Uint8Array(password.length + 56);
  21137. hashData.set(password, 0);
  21138. hashData.set(ownerValidationSalt, password.length);
  21139. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  21140. var result = calculateSHA256(hashData, 0, hashData.length);
  21141. return compareByteArrays(result, ownerPassword);
  21142. },
  21143. checkUserPassword: function PDF17_checkUserPassword(password,
  21144. userValidationSalt,
  21145. userPassword) {
  21146. var hashData = new Uint8Array(password.length + 8);
  21147. hashData.set(password, 0);
  21148. hashData.set(userValidationSalt, password.length);
  21149. var result = calculateSHA256(hashData, 0, hashData.length);
  21150. return compareByteArrays(result, userPassword);
  21151. },
  21152. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  21153. ownerEncryption) {
  21154. var hashData = new Uint8Array(password.length + 56);
  21155. hashData.set(password, 0);
  21156. hashData.set(ownerKeySalt, password.length);
  21157. hashData.set(userBytes, password.length + ownerKeySalt.length);
  21158. var key = calculateSHA256(hashData, 0, hashData.length);
  21159. var cipher = new AES256Cipher(key);
  21160. return cipher.decryptBlock(ownerEncryption,
  21161. false,
  21162. new Uint8Array(16));
  21163. },
  21164. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  21165. userEncryption) {
  21166. var hashData = new Uint8Array(password.length + 8);
  21167. hashData.set(password, 0);
  21168. hashData.set(userKeySalt, password.length);
  21169. //key is the decryption key for the UE string
  21170. var key = calculateSHA256(hashData, 0, hashData.length);
  21171. var cipher = new AES256Cipher(key);
  21172. return cipher.decryptBlock(userEncryption,
  21173. false,
  21174. new Uint8Array(16));
  21175. }
  21176. };
  21177. return PDF17;
  21178. })();
  21179. var PDF20 = (function PDF20Closure() {
  21180. function concatArrays(array1, array2) {
  21181. var t = new Uint8Array(array1.length + array2.length);
  21182. t.set(array1, 0);
  21183. t.set(array2, array1.length);
  21184. return t;
  21185. }
  21186. function calculatePDF20Hash(password, input, userBytes) {
  21187. //This refers to Algorithm 2.B as defined in ISO 32000-2
  21188. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  21189. var e = [0];
  21190. var i = 0;
  21191. while (i < 64 || e[e.length - 1] > i - 32) {
  21192. var arrayLength = password.length + k.length + userBytes.length;
  21193. var k1 = new Uint8Array(arrayLength * 64);
  21194. var array = concatArrays(password, k);
  21195. array = concatArrays(array, userBytes);
  21196. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  21197. k1.set(array, pos);
  21198. }
  21199. //AES128 CBC NO PADDING with
  21200. //first 16 bytes of k as the key and the second 16 as the iv.
  21201. var cipher = new AES128Cipher(k.subarray(0, 16));
  21202. e = cipher.encrypt(k1, k.subarray(16, 32));
  21203. //Now we have to take the first 16 bytes of an unsigned
  21204. //big endian integer... and compute the remainder
  21205. //modulo 3.... That is a fairly large number and
  21206. //JavaScript isn't going to handle that well...
  21207. //So we're using a trick that allows us to perform
  21208. //modulo math byte by byte
  21209. var remainder = 0;
  21210. for (var z = 0; z < 16; z++) {
  21211. remainder *= (256 % 3);
  21212. remainder %= 3;
  21213. remainder += ((e[z] >>> 0) % 3);
  21214. remainder %= 3;
  21215. }
  21216. if (remainder === 0) {
  21217. k = calculateSHA256(e, 0, e.length);
  21218. }
  21219. else if (remainder === 1) {
  21220. k = calculateSHA384(e, 0, e.length);
  21221. }
  21222. else if (remainder === 2) {
  21223. k = calculateSHA512(e, 0, e.length);
  21224. }
  21225. i++;
  21226. }
  21227. return k.subarray(0, 32);
  21228. }
  21229. function PDF20() {
  21230. }
  21231. function compareByteArrays(array1, array2) {
  21232. if (array1.length !== array2.length) {
  21233. return false;
  21234. }
  21235. for (var i = 0; i < array1.length; i++) {
  21236. if (array1[i] !== array2[i]) {
  21237. return false;
  21238. }
  21239. }
  21240. return true;
  21241. }
  21242. PDF20.prototype = {
  21243. hash: function PDF20_hash(password, concatBytes, userBytes) {
  21244. return calculatePDF20Hash(password, concatBytes, userBytes);
  21245. },
  21246. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  21247. ownerValidationSalt,
  21248. userBytes,
  21249. ownerPassword) {
  21250. var hashData = new Uint8Array(password.length + 56);
  21251. hashData.set(password, 0);
  21252. hashData.set(ownerValidationSalt, password.length);
  21253. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  21254. var result = calculatePDF20Hash(password, hashData, userBytes);
  21255. return compareByteArrays(result, ownerPassword);
  21256. },
  21257. checkUserPassword: function PDF20_checkUserPassword(password,
  21258. userValidationSalt,
  21259. userPassword) {
  21260. var hashData = new Uint8Array(password.length + 8);
  21261. hashData.set(password, 0);
  21262. hashData.set(userValidationSalt, password.length);
  21263. var result = calculatePDF20Hash(password, hashData, []);
  21264. return compareByteArrays(result, userPassword);
  21265. },
  21266. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  21267. ownerEncryption) {
  21268. var hashData = new Uint8Array(password.length + 56);
  21269. hashData.set(password, 0);
  21270. hashData.set(ownerKeySalt, password.length);
  21271. hashData.set(userBytes, password.length + ownerKeySalt.length);
  21272. var key = calculatePDF20Hash(password, hashData, userBytes);
  21273. var cipher = new AES256Cipher(key);
  21274. return cipher.decryptBlock(ownerEncryption,
  21275. false,
  21276. new Uint8Array(16));
  21277. },
  21278. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  21279. userEncryption) {
  21280. var hashData = new Uint8Array(password.length + 8);
  21281. hashData.set(password, 0);
  21282. hashData.set(userKeySalt, password.length);
  21283. //key is the decryption key for the UE string
  21284. var key = calculatePDF20Hash(password, hashData, []);
  21285. var cipher = new AES256Cipher(key);
  21286. return cipher.decryptBlock(userEncryption,
  21287. false,
  21288. new Uint8Array(16));
  21289. }
  21290. };
  21291. return PDF20;
  21292. })();
  21293. var CipherTransform = (function CipherTransformClosure() {
  21294. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  21295. this.stringCipherConstructor = stringCipherConstructor;
  21296. this.streamCipherConstructor = streamCipherConstructor;
  21297. }
  21298. CipherTransform.prototype = {
  21299. createStream: function CipherTransform_createStream(stream, length) {
  21300. var cipher = new this.streamCipherConstructor();
  21301. return new DecryptStream(stream, length,
  21302. function cipherTransformDecryptStream(data, finalize) {
  21303. return cipher.decryptBlock(data, finalize);
  21304. }
  21305. );
  21306. },
  21307. decryptString: function CipherTransform_decryptString(s) {
  21308. var cipher = new this.stringCipherConstructor();
  21309. var data = stringToBytes(s);
  21310. data = cipher.decryptBlock(data, true);
  21311. return bytesToString(data);
  21312. }
  21313. };
  21314. return CipherTransform;
  21315. })();
  21316. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  21317. var defaultPasswordBytes = new Uint8Array([
  21318. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  21319. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  21320. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  21321. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  21322. function createEncryptionKey20(revision, password, ownerPassword,
  21323. ownerValidationSalt, ownerKeySalt, uBytes,
  21324. userPassword, userValidationSalt, userKeySalt,
  21325. ownerEncryption, userEncryption, perms) {
  21326. if (password) {
  21327. var passwordLength = Math.min(127, password.length);
  21328. password = password.subarray(0, passwordLength);
  21329. } else {
  21330. password = [];
  21331. }
  21332. var pdfAlgorithm;
  21333. if (revision === 6) {
  21334. pdfAlgorithm = new PDF20();
  21335. } else {
  21336. pdfAlgorithm = new PDF17();
  21337. }
  21338. if (pdfAlgorithm) {
  21339. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  21340. userPassword)) {
  21341. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  21342. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password,
  21343. ownerValidationSalt,
  21344. uBytes,
  21345. ownerPassword)) {
  21346. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  21347. ownerEncryption);
  21348. }
  21349. }
  21350. return null;
  21351. }
  21352. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  21353. flags, revision, keyLength, encryptMetadata) {
  21354. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  21355. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  21356. if (password) {
  21357. n = Math.min(32, password.length);
  21358. for (; i < n; ++i) {
  21359. hashData[i] = password[i];
  21360. }
  21361. }
  21362. j = 0;
  21363. while (i < 32) {
  21364. hashData[i++] = defaultPasswordBytes[j++];
  21365. }
  21366. // as now the padded password in the hashData[0..i]
  21367. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  21368. hashData[i++] = ownerPassword[j];
  21369. }
  21370. hashData[i++] = flags & 0xFF;
  21371. hashData[i++] = (flags >> 8) & 0xFF;
  21372. hashData[i++] = (flags >> 16) & 0xFF;
  21373. hashData[i++] = (flags >>> 24) & 0xFF;
  21374. for (j = 0, n = fileId.length; j < n; ++j) {
  21375. hashData[i++] = fileId[j];
  21376. }
  21377. if (revision >= 4 && !encryptMetadata) {
  21378. hashData[i++] = 0xFF;
  21379. hashData[i++] = 0xFF;
  21380. hashData[i++] = 0xFF;
  21381. hashData[i++] = 0xFF;
  21382. }
  21383. var hash = calculateMD5(hashData, 0, i);
  21384. var keyLengthInBytes = keyLength >> 3;
  21385. if (revision >= 3) {
  21386. for (j = 0; j < 50; ++j) {
  21387. hash = calculateMD5(hash, 0, keyLengthInBytes);
  21388. }
  21389. }
  21390. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  21391. var cipher, checkData;
  21392. if (revision >= 3) {
  21393. for (i = 0; i < 32; ++i) {
  21394. hashData[i] = defaultPasswordBytes[i];
  21395. }
  21396. for (j = 0, n = fileId.length; j < n; ++j) {
  21397. hashData[i++] = fileId[j];
  21398. }
  21399. cipher = new ARCFourCipher(encryptionKey);
  21400. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  21401. n = encryptionKey.length;
  21402. var derivedKey = new Uint8Array(n), k;
  21403. for (j = 1; j <= 19; ++j) {
  21404. for (k = 0; k < n; ++k) {
  21405. derivedKey[k] = encryptionKey[k] ^ j;
  21406. }
  21407. cipher = new ARCFourCipher(derivedKey);
  21408. checkData = cipher.encryptBlock(checkData);
  21409. }
  21410. for (j = 0, n = checkData.length; j < n; ++j) {
  21411. if (userPassword[j] !== checkData[j]) {
  21412. return null;
  21413. }
  21414. }
  21415. } else {
  21416. cipher = new ARCFourCipher(encryptionKey);
  21417. checkData = cipher.encryptBlock(defaultPasswordBytes);
  21418. for (j = 0, n = checkData.length; j < n; ++j) {
  21419. if (userPassword[j] !== checkData[j]) {
  21420. return null;
  21421. }
  21422. }
  21423. }
  21424. return encryptionKey;
  21425. }
  21426. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  21427. var hashData = new Uint8Array(32), i = 0, j, n;
  21428. n = Math.min(32, password.length);
  21429. for (; i < n; ++i) {
  21430. hashData[i] = password[i];
  21431. }
  21432. j = 0;
  21433. while (i < 32) {
  21434. hashData[i++] = defaultPasswordBytes[j++];
  21435. }
  21436. var hash = calculateMD5(hashData, 0, i);
  21437. var keyLengthInBytes = keyLength >> 3;
  21438. if (revision >= 3) {
  21439. for (j = 0; j < 50; ++j) {
  21440. hash = calculateMD5(hash, 0, hash.length);
  21441. }
  21442. }
  21443. var cipher, userPassword;
  21444. if (revision >= 3) {
  21445. userPassword = ownerPassword;
  21446. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  21447. for (j = 19; j >= 0; j--) {
  21448. for (k = 0; k < keyLengthInBytes; ++k) {
  21449. derivedKey[k] = hash[k] ^ j;
  21450. }
  21451. cipher = new ARCFourCipher(derivedKey);
  21452. userPassword = cipher.encryptBlock(userPassword);
  21453. }
  21454. } else {
  21455. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  21456. userPassword = cipher.encryptBlock(ownerPassword);
  21457. }
  21458. return userPassword;
  21459. }
  21460. var identityName = Name.get('Identity');
  21461. function CipherTransformFactory(dict, fileId, password) {
  21462. var filter = dict.get('Filter');
  21463. if (!isName(filter) || filter.name !== 'Standard') {
  21464. error('unknown encryption method');
  21465. }
  21466. this.dict = dict;
  21467. var algorithm = dict.get('V');
  21468. if (!isInt(algorithm) ||
  21469. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  21470. algorithm !== 5)) {
  21471. error('unsupported encryption algorithm');
  21472. }
  21473. this.algorithm = algorithm;
  21474. var keyLength = dict.get('Length');
  21475. if (!keyLength) {
  21476. // Spec asks to rely on encryption dictionary's Length entry, however
  21477. // some PDFs don't have it. Trying to recover.
  21478. if (algorithm <= 3) {
  21479. // For 1 and 2 it's fixed to 40-bit, for 3 40-bit is a minimal value.
  21480. keyLength = 40;
  21481. } else {
  21482. // Trying to find default handler -- it usually has Length.
  21483. var cfDict = dict.get('CF');
  21484. var streamCryptoName = dict.get('StmF');
  21485. if (isDict(cfDict) && isName(streamCryptoName)) {
  21486. var handlerDict = cfDict.get(streamCryptoName.name);
  21487. keyLength = (handlerDict && handlerDict.get('Length')) || 128;
  21488. if (keyLength < 40) {
  21489. // Sometimes it's incorrect value of bits, generators specify bytes.
  21490. keyLength <<= 3;
  21491. }
  21492. }
  21493. }
  21494. }
  21495. if (!isInt(keyLength) ||
  21496. keyLength < 40 || (keyLength % 8) !== 0) {
  21497. error('invalid key length');
  21498. }
  21499. // prepare keys
  21500. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  21501. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  21502. var flags = dict.get('P');
  21503. var revision = dict.get('R');
  21504. // meaningful when V is 4 or 5
  21505. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  21506. dict.get('EncryptMetadata') !== false);
  21507. this.encryptMetadata = encryptMetadata;
  21508. var fileIdBytes = stringToBytes(fileId);
  21509. var passwordBytes;
  21510. if (password) {
  21511. if (revision === 6) {
  21512. try {
  21513. password = utf8StringToString(password);
  21514. } catch (ex) {
  21515. warn('CipherTransformFactory: ' +
  21516. 'Unable to convert UTF8 encoded password.');
  21517. }
  21518. }
  21519. passwordBytes = stringToBytes(password);
  21520. }
  21521. var encryptionKey;
  21522. if (algorithm !== 5) {
  21523. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  21524. ownerPassword, userPassword, flags,
  21525. revision, keyLength, encryptMetadata);
  21526. }
  21527. else {
  21528. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  21529. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  21530. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  21531. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  21532. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  21533. var ownerEncryption = stringToBytes(dict.get('OE'));
  21534. var userEncryption = stringToBytes(dict.get('UE'));
  21535. var perms = stringToBytes(dict.get('Perms'));
  21536. encryptionKey =
  21537. createEncryptionKey20(revision, passwordBytes,
  21538. ownerPassword, ownerValidationSalt,
  21539. ownerKeySalt, uBytes,
  21540. userPassword, userValidationSalt,
  21541. userKeySalt, ownerEncryption,
  21542. userEncryption, perms);
  21543. }
  21544. if (!encryptionKey && !password) {
  21545. throw new PasswordException('No password given',
  21546. PasswordResponses.NEED_PASSWORD);
  21547. } else if (!encryptionKey && password) {
  21548. // Attempting use the password as an owner password
  21549. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  21550. revision, keyLength);
  21551. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  21552. ownerPassword, userPassword, flags,
  21553. revision, keyLength, encryptMetadata);
  21554. }
  21555. if (!encryptionKey) {
  21556. throw new PasswordException('Incorrect Password',
  21557. PasswordResponses.INCORRECT_PASSWORD);
  21558. }
  21559. this.encryptionKey = encryptionKey;
  21560. if (algorithm >= 4) {
  21561. this.cf = dict.get('CF');
  21562. this.stmf = dict.get('StmF') || identityName;
  21563. this.strf = dict.get('StrF') || identityName;
  21564. this.eff = dict.get('EFF') || this.stmf;
  21565. }
  21566. }
  21567. function buildObjectKey(num, gen, encryptionKey, isAes) {
  21568. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  21569. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  21570. key[i] = encryptionKey[i];
  21571. }
  21572. key[i++] = num & 0xFF;
  21573. key[i++] = (num >> 8) & 0xFF;
  21574. key[i++] = (num >> 16) & 0xFF;
  21575. key[i++] = gen & 0xFF;
  21576. key[i++] = (gen >> 8) & 0xFF;
  21577. if (isAes) {
  21578. key[i++] = 0x73;
  21579. key[i++] = 0x41;
  21580. key[i++] = 0x6C;
  21581. key[i++] = 0x54;
  21582. }
  21583. var hash = calculateMD5(key, 0, i);
  21584. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  21585. }
  21586. function buildCipherConstructor(cf, name, num, gen, key) {
  21587. var cryptFilter = cf.get(name.name);
  21588. var cfm;
  21589. if (cryptFilter !== null && cryptFilter !== undefined) {
  21590. cfm = cryptFilter.get('CFM');
  21591. }
  21592. if (!cfm || cfm.name === 'None') {
  21593. return function cipherTransformFactoryBuildCipherConstructorNone() {
  21594. return new NullCipher();
  21595. };
  21596. }
  21597. if ('V2' === cfm.name) {
  21598. return function cipherTransformFactoryBuildCipherConstructorV2() {
  21599. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  21600. };
  21601. }
  21602. if ('AESV2' === cfm.name) {
  21603. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  21604. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  21605. };
  21606. }
  21607. if ('AESV3' === cfm.name) {
  21608. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  21609. return new AES256Cipher(key);
  21610. };
  21611. }
  21612. error('Unknown crypto method');
  21613. }
  21614. CipherTransformFactory.prototype = {
  21615. createCipherTransform:
  21616. function CipherTransformFactory_createCipherTransform(num, gen) {
  21617. if (this.algorithm === 4 || this.algorithm === 5) {
  21618. return new CipherTransform(
  21619. buildCipherConstructor(this.cf, this.stmf,
  21620. num, gen, this.encryptionKey),
  21621. buildCipherConstructor(this.cf, this.strf,
  21622. num, gen, this.encryptionKey));
  21623. }
  21624. // algorithms 1 and 2
  21625. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  21626. var cipherConstructor = function buildCipherCipherConstructor() {
  21627. return new ARCFourCipher(key);
  21628. };
  21629. return new CipherTransform(cipherConstructor, cipherConstructor);
  21630. }
  21631. };
  21632. return CipherTransformFactory;
  21633. })();
  21634. exports.AES128Cipher = AES128Cipher;
  21635. exports.AES256Cipher = AES256Cipher;
  21636. exports.ARCFourCipher = ARCFourCipher;
  21637. exports.CipherTransformFactory = CipherTransformFactory;
  21638. exports.PDF17 = PDF17;
  21639. exports.PDF20 = PDF20;
  21640. exports.calculateMD5 = calculateMD5;
  21641. exports.calculateSHA256 = calculateSHA256;
  21642. exports.calculateSHA384 = calculateSHA384;
  21643. exports.calculateSHA512 = calculateSHA512;
  21644. }));
  21645. (function (root, factory) {
  21646. {
  21647. factory((root.pdfjsCoreFontRenderer = {}), root.pdfjsSharedUtil,
  21648. root.pdfjsCoreStream, root.pdfjsCoreGlyphList, root.pdfjsCoreEncodings);
  21649. }
  21650. }(this, function (exports, sharedUtil, coreStream, coreGlyphList,
  21651. coreEncodings) {
  21652. var Util = sharedUtil.Util;
  21653. var bytesToString = sharedUtil.bytesToString;
  21654. var error = sharedUtil.error;
  21655. var Stream = coreStream.Stream;
  21656. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  21657. var StandardEncoding = coreEncodings.StandardEncoding;
  21658. var coreFonts; // see _setCoreFonts below
  21659. var CFFParser; // = coreFonts.CFFParser;
  21660. var FontRendererFactory = (function FontRendererFactoryClosure() {
  21661. function getLong(data, offset) {
  21662. return (data[offset] << 24) | (data[offset + 1] << 16) |
  21663. (data[offset + 2] << 8) | data[offset + 3];
  21664. }
  21665. function getUshort(data, offset) {
  21666. return (data[offset] << 8) | data[offset + 1];
  21667. }
  21668. function parseCmap(data, start, end) {
  21669. var offset = (getUshort(data, start + 2) === 1 ?
  21670. getLong(data, start + 8) : getLong(data, start + 16));
  21671. var format = getUshort(data, start + offset);
  21672. var length, ranges, p, i;
  21673. if (format === 4) {
  21674. length = getUshort(data, start + offset + 2);
  21675. var segCount = getUshort(data, start + offset + 6) >> 1;
  21676. p = start + offset + 14;
  21677. ranges = [];
  21678. for (i = 0; i < segCount; i++, p += 2) {
  21679. ranges[i] = {end: getUshort(data, p)};
  21680. }
  21681. p += 2;
  21682. for (i = 0; i < segCount; i++, p += 2) {
  21683. ranges[i].start = getUshort(data, p);
  21684. }
  21685. for (i = 0; i < segCount; i++, p += 2) {
  21686. ranges[i].idDelta = getUshort(data, p);
  21687. }
  21688. for (i = 0; i < segCount; i++, p += 2) {
  21689. var idOffset = getUshort(data, p);
  21690. if (idOffset === 0) {
  21691. continue;
  21692. }
  21693. ranges[i].ids = [];
  21694. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  21695. ranges[i].ids[j] = getUshort(data, p + idOffset);
  21696. idOffset += 2;
  21697. }
  21698. }
  21699. return ranges;
  21700. } else if (format === 12) {
  21701. length = getLong(data, start + offset + 4);
  21702. var groups = getLong(data, start + offset + 12);
  21703. p = start + offset + 16;
  21704. ranges = [];
  21705. for (i = 0; i < groups; i++) {
  21706. ranges.push({
  21707. start: getLong(data, p),
  21708. end: getLong(data, p + 4),
  21709. idDelta: getLong(data, p + 8) - getLong(data, p)
  21710. });
  21711. p += 12;
  21712. }
  21713. return ranges;
  21714. }
  21715. error('not supported cmap: ' + format);
  21716. }
  21717. function parseCff(data, start, end) {
  21718. var properties = {};
  21719. var parser = new CFFParser(new Stream(data, start, end - start),
  21720. properties);
  21721. var cff = parser.parse();
  21722. return {
  21723. glyphs: cff.charStrings.objects,
  21724. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  21725. cff.topDict.privateDict.subrsIndex.objects),
  21726. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  21727. };
  21728. }
  21729. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  21730. var itemSize, itemDecode;
  21731. if (isGlyphLocationsLong) {
  21732. itemSize = 4;
  21733. itemDecode = function fontItemDecodeLong(data, offset) {
  21734. return (data[offset] << 24) | (data[offset + 1] << 16) |
  21735. (data[offset + 2] << 8) | data[offset + 3];
  21736. };
  21737. } else {
  21738. itemSize = 2;
  21739. itemDecode = function fontItemDecode(data, offset) {
  21740. return (data[offset] << 9) | (data[offset + 1] << 1);
  21741. };
  21742. }
  21743. var glyphs = [];
  21744. var startOffset = itemDecode(loca, 0);
  21745. for (var j = itemSize; j < loca.length; j += itemSize) {
  21746. var endOffset = itemDecode(loca, j);
  21747. glyphs.push(glyf.subarray(startOffset, endOffset));
  21748. startOffset = endOffset;
  21749. }
  21750. return glyphs;
  21751. }
  21752. function lookupCmap(ranges, unicode) {
  21753. var code = unicode.charCodeAt(0);
  21754. var l = 0, r = ranges.length - 1;
  21755. while (l < r) {
  21756. var c = (l + r + 1) >> 1;
  21757. if (code < ranges[c].start) {
  21758. r = c - 1;
  21759. } else {
  21760. l = c;
  21761. }
  21762. }
  21763. if (ranges[l].start <= code && code <= ranges[l].end) {
  21764. return (ranges[l].idDelta + (ranges[l].ids ?
  21765. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  21766. }
  21767. return 0;
  21768. }
  21769. function compileGlyf(code, cmds, font) {
  21770. function moveTo(x, y) {
  21771. cmds.push({cmd: 'moveTo', args: [x, y]});
  21772. }
  21773. function lineTo(x, y) {
  21774. cmds.push({cmd: 'lineTo', args: [x, y]});
  21775. }
  21776. function quadraticCurveTo(xa, ya, x, y) {
  21777. cmds.push({cmd: 'quadraticCurveTo', args: [xa, ya, x, y]});
  21778. }
  21779. var i = 0;
  21780. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  21781. var flags;
  21782. var x = 0, y = 0;
  21783. i += 10;
  21784. if (numberOfContours < 0) {
  21785. // composite glyph
  21786. do {
  21787. flags = (code[i] << 8) | code[i + 1];
  21788. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  21789. i += 4;
  21790. var arg1, arg2;
  21791. if ((flags & 0x01)) {
  21792. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  21793. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  21794. i += 4;
  21795. } else {
  21796. arg1 = code[i++]; arg2 = code[i++];
  21797. }
  21798. if ((flags & 0x02)) {
  21799. x = arg1;
  21800. y = arg2;
  21801. } else {
  21802. x = 0; y = 0; // TODO "they are points" ?
  21803. }
  21804. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  21805. if ((flags & 0x08)) {
  21806. scaleX =
  21807. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  21808. i += 2;
  21809. } else if ((flags & 0x40)) {
  21810. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  21811. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  21812. i += 4;
  21813. } else if ((flags & 0x80)) {
  21814. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  21815. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  21816. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  21817. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  21818. i += 8;
  21819. }
  21820. var subglyph = font.glyphs[glyphIndex];
  21821. if (subglyph) {
  21822. cmds.push({cmd: 'save'});
  21823. cmds.push({cmd: 'transform',
  21824. args: [scaleX, scale01, scale10, scaleY, x, y]});
  21825. compileGlyf(subglyph, cmds, font);
  21826. cmds.push({cmd: 'restore'});
  21827. }
  21828. } while ((flags & 0x20));
  21829. } else {
  21830. // simple glyph
  21831. var endPtsOfContours = [];
  21832. var j, jj;
  21833. for (j = 0; j < numberOfContours; j++) {
  21834. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  21835. i += 2;
  21836. }
  21837. var instructionLength = (code[i] << 8) | code[i + 1];
  21838. i += 2 + instructionLength; // skipping the instructions
  21839. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  21840. var points = [];
  21841. while (points.length < numberOfPoints) {
  21842. flags = code[i++];
  21843. var repeat = 1;
  21844. if ((flags & 0x08)) {
  21845. repeat += code[i++];
  21846. }
  21847. while (repeat-- > 0) {
  21848. points.push({flags: flags});
  21849. }
  21850. }
  21851. for (j = 0; j < numberOfPoints; j++) {
  21852. switch (points[j].flags & 0x12) {
  21853. case 0x00:
  21854. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  21855. i += 2;
  21856. break;
  21857. case 0x02:
  21858. x -= code[i++];
  21859. break;
  21860. case 0x12:
  21861. x += code[i++];
  21862. break;
  21863. }
  21864. points[j].x = x;
  21865. }
  21866. for (j = 0; j < numberOfPoints; j++) {
  21867. switch (points[j].flags & 0x24) {
  21868. case 0x00:
  21869. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  21870. i += 2;
  21871. break;
  21872. case 0x04:
  21873. y -= code[i++];
  21874. break;
  21875. case 0x24:
  21876. y += code[i++];
  21877. break;
  21878. }
  21879. points[j].y = y;
  21880. }
  21881. var startPoint = 0;
  21882. for (i = 0; i < numberOfContours; i++) {
  21883. var endPoint = endPtsOfContours[i];
  21884. // contours might have implicit points, which is located in the middle
  21885. // between two neighboring off-curve points
  21886. var contour = points.slice(startPoint, endPoint + 1);
  21887. if ((contour[0].flags & 1)) {
  21888. contour.push(contour[0]); // using start point at the contour end
  21889. } else if ((contour[contour.length - 1].flags & 1)) {
  21890. // first is off-curve point, trying to use one from the end
  21891. contour.unshift(contour[contour.length - 1]);
  21892. } else {
  21893. // start and end are off-curve points, creating implicit one
  21894. var p = {
  21895. flags: 1,
  21896. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  21897. y: (contour[0].y + contour[contour.length - 1].y) / 2
  21898. };
  21899. contour.unshift(p);
  21900. contour.push(p);
  21901. }
  21902. moveTo(contour[0].x, contour[0].y);
  21903. for (j = 1, jj = contour.length; j < jj; j++) {
  21904. if ((contour[j].flags & 1)) {
  21905. lineTo(contour[j].x, contour[j].y);
  21906. } else if ((contour[j + 1].flags & 1)){
  21907. quadraticCurveTo(contour[j].x, contour[j].y,
  21908. contour[j + 1].x, contour[j + 1].y);
  21909. j++;
  21910. } else {
  21911. quadraticCurveTo(contour[j].x, contour[j].y,
  21912. (contour[j].x + contour[j + 1].x) / 2,
  21913. (contour[j].y + contour[j + 1].y) / 2);
  21914. }
  21915. }
  21916. startPoint = endPoint + 1;
  21917. }
  21918. }
  21919. }
  21920. function compileCharString(code, cmds, font) {
  21921. var stack = [];
  21922. var x = 0, y = 0;
  21923. var stems = 0;
  21924. function moveTo(x, y) {
  21925. cmds.push({cmd: 'moveTo', args: [x, y]});
  21926. }
  21927. function lineTo(x, y) {
  21928. cmds.push({cmd: 'lineTo', args: [x, y]});
  21929. }
  21930. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  21931. cmds.push({cmd: 'bezierCurveTo', args: [x1, y1, x2, y2, x, y]});
  21932. }
  21933. function parse(code) {
  21934. var i = 0;
  21935. while (i < code.length) {
  21936. var stackClean = false;
  21937. var v = code[i++];
  21938. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  21939. switch (v) {
  21940. case 1: // hstem
  21941. stems += stack.length >> 1;
  21942. stackClean = true;
  21943. break;
  21944. case 3: // vstem
  21945. stems += stack.length >> 1;
  21946. stackClean = true;
  21947. break;
  21948. case 4: // vmoveto
  21949. y += stack.pop();
  21950. moveTo(x, y);
  21951. stackClean = true;
  21952. break;
  21953. case 5: // rlineto
  21954. while (stack.length > 0) {
  21955. x += stack.shift();
  21956. y += stack.shift();
  21957. lineTo(x, y);
  21958. }
  21959. break;
  21960. case 6: // hlineto
  21961. while (stack.length > 0) {
  21962. x += stack.shift();
  21963. lineTo(x, y);
  21964. if (stack.length === 0) {
  21965. break;
  21966. }
  21967. y += stack.shift();
  21968. lineTo(x, y);
  21969. }
  21970. break;
  21971. case 7: // vlineto
  21972. while (stack.length > 0) {
  21973. y += stack.shift();
  21974. lineTo(x, y);
  21975. if (stack.length === 0) {
  21976. break;
  21977. }
  21978. x += stack.shift();
  21979. lineTo(x, y);
  21980. }
  21981. break;
  21982. case 8: // rrcurveto
  21983. while (stack.length > 0) {
  21984. xa = x + stack.shift(); ya = y + stack.shift();
  21985. xb = xa + stack.shift(); yb = ya + stack.shift();
  21986. x = xb + stack.shift(); y = yb + stack.shift();
  21987. bezierCurveTo(xa, ya, xb, yb, x, y);
  21988. }
  21989. break;
  21990. case 10: // callsubr
  21991. n = stack.pop() + font.subrsBias;
  21992. subrCode = font.subrs[n];
  21993. if (subrCode) {
  21994. parse(subrCode);
  21995. }
  21996. break;
  21997. case 11: // return
  21998. return;
  21999. case 12:
  22000. v = code[i++];
  22001. switch (v) {
  22002. case 34: // flex
  22003. xa = x + stack.shift();
  22004. xb = xa + stack.shift(); y1 = y + stack.shift();
  22005. x = xb + stack.shift();
  22006. bezierCurveTo(xa, y, xb, y1, x, y1);
  22007. xa = x + stack.shift();
  22008. xb = xa + stack.shift();
  22009. x = xb + stack.shift();
  22010. bezierCurveTo(xa, y1, xb, y, x, y);
  22011. break;
  22012. case 35: // flex
  22013. xa = x + stack.shift(); ya = y + stack.shift();
  22014. xb = xa + stack.shift(); yb = ya + stack.shift();
  22015. x = xb + stack.shift(); y = yb + stack.shift();
  22016. bezierCurveTo(xa, ya, xb, yb, x, y);
  22017. xa = x + stack.shift(); ya = y + stack.shift();
  22018. xb = xa + stack.shift(); yb = ya + stack.shift();
  22019. x = xb + stack.shift(); y = yb + stack.shift();
  22020. bezierCurveTo(xa, ya, xb, yb, x, y);
  22021. stack.pop(); // fd
  22022. break;
  22023. case 36: // hflex1
  22024. xa = x + stack.shift(); y1 = y + stack.shift();
  22025. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  22026. x = xb + stack.shift();
  22027. bezierCurveTo(xa, y1, xb, y2, x, y2);
  22028. xa = x + stack.shift();
  22029. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  22030. x = xb + stack.shift();
  22031. bezierCurveTo(xa, y2, xb, y3, x, y);
  22032. break;
  22033. case 37: // flex1
  22034. var x0 = x, y0 = y;
  22035. xa = x + stack.shift(); ya = y + stack.shift();
  22036. xb = xa + stack.shift(); yb = ya + stack.shift();
  22037. x = xb + stack.shift(); y = yb + stack.shift();
  22038. bezierCurveTo(xa, ya, xb, yb, x, y);
  22039. xa = x + stack.shift(); ya = y + stack.shift();
  22040. xb = xa + stack.shift(); yb = ya + stack.shift();
  22041. x = xb; y = yb;
  22042. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  22043. x += stack.shift();
  22044. } else {
  22045. y += stack.shift();
  22046. }
  22047. bezierCurveTo(xa, ya, xb, yb, x, y);
  22048. break;
  22049. default:
  22050. error('unknown operator: 12 ' + v);
  22051. }
  22052. break;
  22053. case 14: // endchar
  22054. if (stack.length >= 4) {
  22055. var achar = stack.pop();
  22056. var bchar = stack.pop();
  22057. y = stack.pop();
  22058. x = stack.pop();
  22059. cmds.push({cmd: 'save'});
  22060. cmds.push({cmd: 'translate', args: [x, y]});
  22061. var gid = lookupCmap(font.cmap, String.fromCharCode(
  22062. font.glyphNameMap[StandardEncoding[achar]]));
  22063. compileCharString(font.glyphs[gid], cmds, font);
  22064. cmds.push({cmd: 'restore'});
  22065. gid = lookupCmap(font.cmap, String.fromCharCode(
  22066. font.glyphNameMap[StandardEncoding[bchar]]));
  22067. compileCharString(font.glyphs[gid], cmds, font);
  22068. }
  22069. return;
  22070. case 18: // hstemhm
  22071. stems += stack.length >> 1;
  22072. stackClean = true;
  22073. break;
  22074. case 19: // hintmask
  22075. stems += stack.length >> 1;
  22076. i += (stems + 7) >> 3;
  22077. stackClean = true;
  22078. break;
  22079. case 20: // cntrmask
  22080. stems += stack.length >> 1;
  22081. i += (stems + 7) >> 3;
  22082. stackClean = true;
  22083. break;
  22084. case 21: // rmoveto
  22085. y += stack.pop();
  22086. x += stack.pop();
  22087. moveTo(x, y);
  22088. stackClean = true;
  22089. break;
  22090. case 22: // hmoveto
  22091. x += stack.pop();
  22092. moveTo(x, y);
  22093. stackClean = true;
  22094. break;
  22095. case 23: // vstemhm
  22096. stems += stack.length >> 1;
  22097. stackClean = true;
  22098. break;
  22099. case 24: // rcurveline
  22100. while (stack.length > 2) {
  22101. xa = x + stack.shift(); ya = y + stack.shift();
  22102. xb = xa + stack.shift(); yb = ya + stack.shift();
  22103. x = xb + stack.shift(); y = yb + stack.shift();
  22104. bezierCurveTo(xa, ya, xb, yb, x, y);
  22105. }
  22106. x += stack.shift();
  22107. y += stack.shift();
  22108. lineTo(x, y);
  22109. break;
  22110. case 25: // rlinecurve
  22111. while (stack.length > 6) {
  22112. x += stack.shift();
  22113. y += stack.shift();
  22114. lineTo(x, y);
  22115. }
  22116. xa = x + stack.shift(); ya = y + stack.shift();
  22117. xb = xa + stack.shift(); yb = ya + stack.shift();
  22118. x = xb + stack.shift(); y = yb + stack.shift();
  22119. bezierCurveTo(xa, ya, xb, yb, x, y);
  22120. break;
  22121. case 26: // vvcurveto
  22122. if (stack.length % 2) {
  22123. x += stack.shift();
  22124. }
  22125. while (stack.length > 0) {
  22126. xa = x; ya = y + stack.shift();
  22127. xb = xa + stack.shift(); yb = ya + stack.shift();
  22128. x = xb; y = yb + stack.shift();
  22129. bezierCurveTo(xa, ya, xb, yb, x, y);
  22130. }
  22131. break;
  22132. case 27: // hhcurveto
  22133. if (stack.length % 2) {
  22134. y += stack.shift();
  22135. }
  22136. while (stack.length > 0) {
  22137. xa = x + stack.shift(); ya = y;
  22138. xb = xa + stack.shift(); yb = ya + stack.shift();
  22139. x = xb + stack.shift(); y = yb;
  22140. bezierCurveTo(xa, ya, xb, yb, x, y);
  22141. }
  22142. break;
  22143. case 28:
  22144. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  22145. i += 2;
  22146. break;
  22147. case 29: // callgsubr
  22148. n = stack.pop() + font.gsubrsBias;
  22149. subrCode = font.gsubrs[n];
  22150. if (subrCode) {
  22151. parse(subrCode);
  22152. }
  22153. break;
  22154. case 30: // vhcurveto
  22155. while (stack.length > 0) {
  22156. xa = x; ya = y + stack.shift();
  22157. xb = xa + stack.shift(); yb = ya + stack.shift();
  22158. x = xb + stack.shift();
  22159. y = yb + (stack.length === 1 ? stack.shift() : 0);
  22160. bezierCurveTo(xa, ya, xb, yb, x, y);
  22161. if (stack.length === 0) {
  22162. break;
  22163. }
  22164. xa = x + stack.shift(); ya = y;
  22165. xb = xa + stack.shift(); yb = ya + stack.shift();
  22166. y = yb + stack.shift();
  22167. x = xb + (stack.length === 1 ? stack.shift() : 0);
  22168. bezierCurveTo(xa, ya, xb, yb, x, y);
  22169. }
  22170. break;
  22171. case 31: // hvcurveto
  22172. while (stack.length > 0) {
  22173. xa = x + stack.shift(); ya = y;
  22174. xb = xa + stack.shift(); yb = ya + stack.shift();
  22175. y = yb + stack.shift();
  22176. x = xb + (stack.length === 1 ? stack.shift() : 0);
  22177. bezierCurveTo(xa, ya, xb, yb, x, y);
  22178. if (stack.length === 0) {
  22179. break;
  22180. }
  22181. xa = x; ya = y + stack.shift();
  22182. xb = xa + stack.shift(); yb = ya + stack.shift();
  22183. x = xb + stack.shift();
  22184. y = yb + (stack.length === 1 ? stack.shift() : 0);
  22185. bezierCurveTo(xa, ya, xb, yb, x, y);
  22186. }
  22187. break;
  22188. default:
  22189. if (v < 32) {
  22190. error('unknown operator: ' + v);
  22191. }
  22192. if (v < 247) {
  22193. stack.push(v - 139);
  22194. } else if (v < 251) {
  22195. stack.push((v - 247) * 256 + code[i++] + 108);
  22196. } else if (v < 255) {
  22197. stack.push(-(v - 251) * 256 - code[i++] - 108);
  22198. } else {
  22199. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  22200. (code[i + 2] << 8) | code[i + 3]) / 65536);
  22201. i += 4;
  22202. }
  22203. break;
  22204. }
  22205. if (stackClean) {
  22206. stack.length = 0;
  22207. }
  22208. }
  22209. }
  22210. parse(code);
  22211. }
  22212. var noop = '';
  22213. function CompiledFont(fontMatrix) {
  22214. this.compiledGlyphs = Object.create(null);
  22215. this.fontMatrix = fontMatrix;
  22216. }
  22217. CompiledFont.prototype = {
  22218. getPathJs: function (unicode) {
  22219. var gid = lookupCmap(this.cmap, unicode);
  22220. var fn = this.compiledGlyphs[gid];
  22221. if (!fn) {
  22222. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  22223. }
  22224. return fn;
  22225. },
  22226. compileGlyph: function (code) {
  22227. if (!code || code.length === 0 || code[0] === 14) {
  22228. return noop;
  22229. }
  22230. var cmds = [];
  22231. cmds.push({cmd: 'save'});
  22232. cmds.push({cmd: 'transform', args: this.fontMatrix.slice()});
  22233. cmds.push({cmd: 'scale', args: ['size', '-size']});
  22234. this.compileGlyphImpl(code, cmds);
  22235. cmds.push({cmd: 'restore'});
  22236. return cmds;
  22237. },
  22238. compileGlyphImpl: function () {
  22239. error('Children classes should implement this.');
  22240. },
  22241. hasBuiltPath: function (unicode) {
  22242. var gid = lookupCmap(this.cmap, unicode);
  22243. return gid in this.compiledGlyphs;
  22244. }
  22245. };
  22246. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  22247. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  22248. CompiledFont.call(this, fontMatrix);
  22249. this.glyphs = glyphs;
  22250. this.cmap = cmap;
  22251. this.compiledGlyphs = [];
  22252. }
  22253. Util.inherit(TrueTypeCompiled, CompiledFont, {
  22254. compileGlyphImpl: function (code, cmds) {
  22255. compileGlyf(code, cmds, this);
  22256. }
  22257. });
  22258. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  22259. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  22260. CompiledFont.call(this, fontMatrix);
  22261. this.glyphs = cffInfo.glyphs;
  22262. this.gsubrs = cffInfo.gsubrs || [];
  22263. this.subrs = cffInfo.subrs || [];
  22264. this.cmap = cmap;
  22265. this.glyphNameMap = glyphNameMap || getGlyphsUnicode();
  22266. this.compiledGlyphs = [];
  22267. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  22268. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  22269. this.subrsBias = (this.subrs.length < 1240 ?
  22270. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  22271. }
  22272. Util.inherit(Type2Compiled, CompiledFont, {
  22273. compileGlyphImpl: function (code, cmds) {
  22274. compileCharString(code, cmds, this);
  22275. }
  22276. });
  22277. return {
  22278. create: function FontRendererFactory_create(font) {
  22279. var data = new Uint8Array(font.data);
  22280. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  22281. var numTables = getUshort(data, 4);
  22282. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  22283. var tag = bytesToString(data.subarray(p, p + 4));
  22284. var offset = getLong(data, p + 8);
  22285. var length = getLong(data, p + 12);
  22286. switch (tag) {
  22287. case 'cmap':
  22288. cmap = parseCmap(data, offset, offset + length);
  22289. break;
  22290. case 'glyf':
  22291. glyf = data.subarray(offset, offset + length);
  22292. break;
  22293. case 'loca':
  22294. loca = data.subarray(offset, offset + length);
  22295. break;
  22296. case 'head':
  22297. unitsPerEm = getUshort(data, offset + 18);
  22298. indexToLocFormat = getUshort(data, offset + 50);
  22299. break;
  22300. case 'CFF ':
  22301. cff = parseCff(data, offset, offset + length);
  22302. break;
  22303. }
  22304. }
  22305. if (glyf) {
  22306. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  22307. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  22308. return new TrueTypeCompiled(
  22309. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  22310. } else {
  22311. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  22312. }
  22313. }
  22314. };
  22315. })();
  22316. // TODO refactor to remove cyclic dependency on fonts.js
  22317. function _setCoreFonts(coreFonts_) {
  22318. coreFonts = coreFonts_;
  22319. CFFParser = coreFonts_.CFFParser;
  22320. }
  22321. exports._setCoreFonts = _setCoreFonts;
  22322. exports.FontRendererFactory = FontRendererFactory;
  22323. }));
  22324. (function (root, factory) {
  22325. {
  22326. factory((root.pdfjsCoreParser = {}), root.pdfjsSharedUtil,
  22327. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  22328. }
  22329. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  22330. var MissingDataException = sharedUtil.MissingDataException;
  22331. var StreamType = sharedUtil.StreamType;
  22332. var assert = sharedUtil.assert;
  22333. var error = sharedUtil.error;
  22334. var info = sharedUtil.info;
  22335. var isArray = sharedUtil.isArray;
  22336. var isInt = sharedUtil.isInt;
  22337. var isNum = sharedUtil.isNum;
  22338. var isString = sharedUtil.isString;
  22339. var warn = sharedUtil.warn;
  22340. var Cmd = corePrimitives.Cmd;
  22341. var Dict = corePrimitives.Dict;
  22342. var Name = corePrimitives.Name;
  22343. var Ref = corePrimitives.Ref;
  22344. var isCmd = corePrimitives.isCmd;
  22345. var isDict = corePrimitives.isDict;
  22346. var isName = corePrimitives.isName;
  22347. var Ascii85Stream = coreStream.Ascii85Stream;
  22348. var AsciiHexStream = coreStream.AsciiHexStream;
  22349. var CCITTFaxStream = coreStream.CCITTFaxStream;
  22350. var FlateStream = coreStream.FlateStream;
  22351. var Jbig2Stream = coreStream.Jbig2Stream;
  22352. var JpegStream = coreStream.JpegStream;
  22353. var JpxStream = coreStream.JpxStream;
  22354. var LZWStream = coreStream.LZWStream;
  22355. var NullStream = coreStream.NullStream;
  22356. var PredictorStream = coreStream.PredictorStream;
  22357. var RunLengthStream = coreStream.RunLengthStream;
  22358. var EOF = {};
  22359. function isEOF(v) {
  22360. return (v === EOF);
  22361. }
  22362. var MAX_LENGTH_TO_CACHE = 1000;
  22363. var Parser = (function ParserClosure() {
  22364. function Parser(lexer, allowStreams, xref) {
  22365. this.lexer = lexer;
  22366. this.allowStreams = allowStreams;
  22367. this.xref = xref;
  22368. this.imageCache = Object.create(null);
  22369. this.refill();
  22370. }
  22371. Parser.prototype = {
  22372. refill: function Parser_refill() {
  22373. this.buf1 = this.lexer.getObj();
  22374. this.buf2 = this.lexer.getObj();
  22375. },
  22376. shift: function Parser_shift() {
  22377. if (isCmd(this.buf2, 'ID')) {
  22378. this.buf1 = this.buf2;
  22379. this.buf2 = null;
  22380. } else {
  22381. this.buf1 = this.buf2;
  22382. this.buf2 = this.lexer.getObj();
  22383. }
  22384. },
  22385. tryShift: function Parser_tryShift() {
  22386. try {
  22387. this.shift();
  22388. return true;
  22389. } catch (e) {
  22390. if (e instanceof MissingDataException) {
  22391. throw e;
  22392. }
  22393. // Upon failure, the caller should reset this.lexer.pos to a known good
  22394. // state and call this.shift() twice to reset the buffers.
  22395. return false;
  22396. }
  22397. },
  22398. getObj: function Parser_getObj(cipherTransform) {
  22399. var buf1 = this.buf1;
  22400. this.shift();
  22401. if (buf1 instanceof Cmd) {
  22402. switch (buf1.cmd) {
  22403. case 'BI': // inline image
  22404. return this.makeInlineImage(cipherTransform);
  22405. case '[': // array
  22406. var array = [];
  22407. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  22408. array.push(this.getObj(cipherTransform));
  22409. }
  22410. if (isEOF(this.buf1)) {
  22411. error('End of file inside array');
  22412. }
  22413. this.shift();
  22414. return array;
  22415. case '<<': // dictionary or stream
  22416. var dict = new Dict(this.xref);
  22417. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  22418. if (!isName(this.buf1)) {
  22419. info('Malformed dictionary: key must be a name object');
  22420. this.shift();
  22421. continue;
  22422. }
  22423. var key = this.buf1.name;
  22424. this.shift();
  22425. if (isEOF(this.buf1)) {
  22426. break;
  22427. }
  22428. dict.set(key, this.getObj(cipherTransform));
  22429. }
  22430. if (isEOF(this.buf1)) {
  22431. error('End of file inside dictionary');
  22432. }
  22433. // Stream objects are not allowed inside content streams or
  22434. // object streams.
  22435. if (isCmd(this.buf2, 'stream')) {
  22436. return (this.allowStreams ?
  22437. this.makeStream(dict, cipherTransform) : dict);
  22438. }
  22439. this.shift();
  22440. return dict;
  22441. default: // simple object
  22442. return buf1;
  22443. }
  22444. }
  22445. if (isInt(buf1)) { // indirect reference or integer
  22446. var num = buf1;
  22447. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  22448. var ref = new Ref(num, this.buf1);
  22449. this.shift();
  22450. this.shift();
  22451. return ref;
  22452. }
  22453. return num;
  22454. }
  22455. if (isString(buf1)) { // string
  22456. var str = buf1;
  22457. if (cipherTransform) {
  22458. str = cipherTransform.decryptString(str);
  22459. }
  22460. return str;
  22461. }
  22462. // simple object
  22463. return buf1;
  22464. },
  22465. /**
  22466. * Find the end of the stream by searching for the /EI\s/.
  22467. * @returns {number} The inline stream length.
  22468. */
  22469. findDefaultInlineStreamEnd:
  22470. function Parser_findDefaultInlineStreamEnd(stream) {
  22471. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  22472. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  22473. while ((ch = stream.getByte()) !== -1) {
  22474. if (state === 0) {
  22475. state = (ch === E) ? 1 : 0;
  22476. } else if (state === 1) {
  22477. state = (ch === I) ? 2 : 0;
  22478. } else {
  22479. assert(state === 2);
  22480. if (ch === SPACE || ch === LF || ch === CR) {
  22481. // Let's check the next five bytes are ASCII... just be sure.
  22482. n = 5;
  22483. followingBytes = stream.peekBytes(n);
  22484. for (i = 0; i < n; i++) {
  22485. ch = followingBytes[i];
  22486. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  22487. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  22488. // it's binary stuff. Resetting the state.
  22489. state = 0;
  22490. break;
  22491. }
  22492. }
  22493. if (state === 2) {
  22494. break; // Finished!
  22495. }
  22496. } else {
  22497. state = 0;
  22498. }
  22499. }
  22500. }
  22501. return ((stream.pos - 4) - startPos);
  22502. },
  22503. /**
  22504. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  22505. * @returns {number} The inline stream length.
  22506. */
  22507. findDCTDecodeInlineStreamEnd:
  22508. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  22509. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  22510. while ((b = stream.getByte()) !== -1) {
  22511. if (b !== 0xFF) { // Not a valid marker.
  22512. continue;
  22513. }
  22514. switch (stream.getByte()) {
  22515. case 0x00: // Byte stuffing.
  22516. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  22517. break;
  22518. case 0xFF: // Fill byte.
  22519. // Avoid skipping a valid marker, resetting the stream position.
  22520. stream.skip(-1);
  22521. break;
  22522. case 0xD9: // EOI
  22523. foundEOI = true;
  22524. break;
  22525. case 0xC0: // SOF0
  22526. case 0xC1: // SOF1
  22527. case 0xC2: // SOF2
  22528. case 0xC3: // SOF3
  22529. case 0xC5: // SOF5
  22530. case 0xC6: // SOF6
  22531. case 0xC7: // SOF7
  22532. case 0xC9: // SOF9
  22533. case 0xCA: // SOF10
  22534. case 0xCB: // SOF11
  22535. case 0xCD: // SOF13
  22536. case 0xCE: // SOF14
  22537. case 0xCF: // SOF15
  22538. case 0xC4: // DHT
  22539. case 0xCC: // DAC
  22540. case 0xDA: // SOS
  22541. case 0xDB: // DQT
  22542. case 0xDC: // DNL
  22543. case 0xDD: // DRI
  22544. case 0xDE: // DHP
  22545. case 0xDF: // EXP
  22546. case 0xE0: // APP0
  22547. case 0xE1: // APP1
  22548. case 0xE2: // APP2
  22549. case 0xE3: // APP3
  22550. case 0xE4: // APP4
  22551. case 0xE5: // APP5
  22552. case 0xE6: // APP6
  22553. case 0xE7: // APP7
  22554. case 0xE8: // APP8
  22555. case 0xE9: // APP9
  22556. case 0xEA: // APP10
  22557. case 0xEB: // APP11
  22558. case 0xEC: // APP12
  22559. case 0xED: // APP13
  22560. case 0xEE: // APP14
  22561. case 0xEF: // APP15
  22562. case 0xFE: // COM
  22563. // The marker should be followed by the length of the segment.
  22564. markerLength = stream.getUint16();
  22565. if (markerLength > 2) {
  22566. // |markerLength| contains the byte length of the marker segment,
  22567. // including its own length (2 bytes) and excluding the marker.
  22568. stream.skip(markerLength - 2); // Jump to the next marker.
  22569. } else {
  22570. // The marker length is invalid, resetting the stream position.
  22571. stream.skip(-2);
  22572. }
  22573. break;
  22574. }
  22575. if (foundEOI) {
  22576. break;
  22577. }
  22578. }
  22579. length = stream.pos - startPos;
  22580. if (b === -1) {
  22581. warn('Inline DCTDecode image stream: ' +
  22582. 'EOI marker not found, searching for /EI/ instead.');
  22583. stream.skip(-length); // Reset the stream position.
  22584. return this.findDefaultInlineStreamEnd(stream);
  22585. }
  22586. this.inlineStreamSkipEI(stream);
  22587. return length;
  22588. },
  22589. /**
  22590. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  22591. * @returns {number} The inline stream length.
  22592. */
  22593. findASCII85DecodeInlineStreamEnd:
  22594. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  22595. var TILDE = 0x7E, GT = 0x3E;
  22596. var startPos = stream.pos, ch, length;
  22597. while ((ch = stream.getByte()) !== -1) {
  22598. if (ch === TILDE && stream.peekByte() === GT) {
  22599. stream.skip();
  22600. break;
  22601. }
  22602. }
  22603. length = stream.pos - startPos;
  22604. if (ch === -1) {
  22605. warn('Inline ASCII85Decode image stream: ' +
  22606. 'EOD marker not found, searching for /EI/ instead.');
  22607. stream.skip(-length); // Reset the stream position.
  22608. return this.findDefaultInlineStreamEnd(stream);
  22609. }
  22610. this.inlineStreamSkipEI(stream);
  22611. return length;
  22612. },
  22613. /**
  22614. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  22615. * @returns {number} The inline stream length.
  22616. */
  22617. findASCIIHexDecodeInlineStreamEnd:
  22618. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  22619. var GT = 0x3E;
  22620. var startPos = stream.pos, ch, length;
  22621. while ((ch = stream.getByte()) !== -1) {
  22622. if (ch === GT) {
  22623. break;
  22624. }
  22625. }
  22626. length = stream.pos - startPos;
  22627. if (ch === -1) {
  22628. warn('Inline ASCIIHexDecode image stream: ' +
  22629. 'EOD marker not found, searching for /EI/ instead.');
  22630. stream.skip(-length); // Reset the stream position.
  22631. return this.findDefaultInlineStreamEnd(stream);
  22632. }
  22633. this.inlineStreamSkipEI(stream);
  22634. return length;
  22635. },
  22636. /**
  22637. * Skip over the /EI/ for streams where we search for an EOD marker.
  22638. */
  22639. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  22640. var E = 0x45, I = 0x49;
  22641. var state = 0, ch;
  22642. while ((ch = stream.getByte()) !== -1) {
  22643. if (state === 0) {
  22644. state = (ch === E) ? 1 : 0;
  22645. } else if (state === 1) {
  22646. state = (ch === I) ? 2 : 0;
  22647. } else if (state === 2) {
  22648. break;
  22649. }
  22650. }
  22651. },
  22652. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  22653. var lexer = this.lexer;
  22654. var stream = lexer.stream;
  22655. // Parse dictionary.
  22656. var dict = new Dict(this.xref);
  22657. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  22658. if (!isName(this.buf1)) {
  22659. error('Dictionary key must be a name object');
  22660. }
  22661. var key = this.buf1.name;
  22662. this.shift();
  22663. if (isEOF(this.buf1)) {
  22664. break;
  22665. }
  22666. dict.set(key, this.getObj(cipherTransform));
  22667. }
  22668. // Extract the name of the first (i.e. the current) image filter.
  22669. var filter = dict.get('Filter', 'F'), filterName;
  22670. if (isName(filter)) {
  22671. filterName = filter.name;
  22672. } else if (isArray(filter) && isName(filter[0])) {
  22673. filterName = filter[0].name;
  22674. }
  22675. // Parse image stream.
  22676. var startPos = stream.pos, length, i, ii;
  22677. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  22678. length = this.findDCTDecodeInlineStreamEnd(stream);
  22679. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  22680. length = this.findASCII85DecodeInlineStreamEnd(stream);
  22681. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  22682. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  22683. } else {
  22684. length = this.findDefaultInlineStreamEnd(stream);
  22685. }
  22686. var imageStream = stream.makeSubStream(startPos, length, dict);
  22687. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  22688. // adler32 checksum.
  22689. var adler32;
  22690. if (length < MAX_LENGTH_TO_CACHE) {
  22691. var imageBytes = imageStream.getBytes();
  22692. imageStream.reset();
  22693. var a = 1;
  22694. var b = 0;
  22695. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  22696. // No modulo required in the loop if imageBytes.length < 5552.
  22697. a += imageBytes[i] & 0xff;
  22698. b += a;
  22699. }
  22700. adler32 = ((b % 65521) << 16) | (a % 65521);
  22701. if (this.imageCache.adler32 === adler32) {
  22702. this.buf2 = Cmd.get('EI');
  22703. this.shift();
  22704. this.imageCache[adler32].reset();
  22705. return this.imageCache[adler32];
  22706. }
  22707. }
  22708. if (cipherTransform) {
  22709. imageStream = cipherTransform.createStream(imageStream, length);
  22710. }
  22711. imageStream = this.filter(imageStream, dict, length);
  22712. imageStream.dict = dict;
  22713. if (adler32 !== undefined) {
  22714. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  22715. this.imageCache[adler32] = imageStream;
  22716. }
  22717. this.buf2 = Cmd.get('EI');
  22718. this.shift();
  22719. return imageStream;
  22720. },
  22721. makeStream: function Parser_makeStream(dict, cipherTransform) {
  22722. var lexer = this.lexer;
  22723. var stream = lexer.stream;
  22724. // get stream start position
  22725. lexer.skipToNextLine();
  22726. var pos = stream.pos - 1;
  22727. // get length
  22728. var length = dict.get('Length');
  22729. if (!isInt(length)) {
  22730. info('Bad ' + length + ' attribute in stream');
  22731. length = 0;
  22732. }
  22733. // skip over the stream data
  22734. stream.pos = pos + length;
  22735. lexer.nextChar();
  22736. // Shift '>>' and check whether the new object marks the end of the stream
  22737. if (this.tryShift() && isCmd(this.buf2, 'endstream')) {
  22738. this.shift(); // 'stream'
  22739. } else {
  22740. // bad stream length, scanning for endstream
  22741. stream.pos = pos;
  22742. var SCAN_BLOCK_SIZE = 2048;
  22743. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  22744. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  22745. 0x61, 0x6D];
  22746. var skipped = 0, found = false, i, j;
  22747. while (stream.pos < stream.end) {
  22748. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  22749. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  22750. if (scanLength <= 0) {
  22751. break;
  22752. }
  22753. found = false;
  22754. i = 0;
  22755. while (i < scanLength) {
  22756. j = 0;
  22757. while (j < ENDSTREAM_SIGNATURE_LENGTH &&
  22758. scanBytes[i + j] === ENDSTREAM_SIGNATURE[j]) {
  22759. j++;
  22760. }
  22761. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  22762. found = true;
  22763. break;
  22764. }
  22765. i++;
  22766. }
  22767. if (found) {
  22768. skipped += i;
  22769. stream.pos += i;
  22770. break;
  22771. }
  22772. skipped += scanLength;
  22773. stream.pos += scanLength;
  22774. }
  22775. if (!found) {
  22776. error('Missing endstream');
  22777. }
  22778. length = skipped;
  22779. lexer.nextChar();
  22780. this.shift();
  22781. this.shift();
  22782. }
  22783. this.shift(); // 'endstream'
  22784. stream = stream.makeSubStream(pos, length, dict);
  22785. if (cipherTransform) {
  22786. stream = cipherTransform.createStream(stream, length);
  22787. }
  22788. stream = this.filter(stream, dict, length);
  22789. stream.dict = dict;
  22790. return stream;
  22791. },
  22792. filter: function Parser_filter(stream, dict, length) {
  22793. var filter = dict.get('Filter', 'F');
  22794. var params = dict.get('DecodeParms', 'DP');
  22795. if (isName(filter)) {
  22796. return this.makeFilter(stream, filter.name, length, params);
  22797. }
  22798. var maybeLength = length;
  22799. if (isArray(filter)) {
  22800. var filterArray = filter;
  22801. var paramsArray = params;
  22802. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  22803. filter = filterArray[i];
  22804. if (!isName(filter)) {
  22805. error('Bad filter name: ' + filter);
  22806. }
  22807. params = null;
  22808. if (isArray(paramsArray) && (i in paramsArray)) {
  22809. params = paramsArray[i];
  22810. }
  22811. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  22812. // after the first stream the length variable is invalid
  22813. maybeLength = null;
  22814. }
  22815. }
  22816. return stream;
  22817. },
  22818. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  22819. if (stream.dict.get('Length') === 0 && !maybeLength) {
  22820. warn('Empty "' + name + '" stream.');
  22821. return new NullStream(stream);
  22822. }
  22823. try {
  22824. if (params && this.xref) {
  22825. params = this.xref.fetchIfRef(params);
  22826. }
  22827. var xrefStreamStats = this.xref.stats.streamTypes;
  22828. if (name === 'FlateDecode' || name === 'Fl') {
  22829. xrefStreamStats[StreamType.FLATE] = true;
  22830. if (params) {
  22831. return new PredictorStream(new FlateStream(stream, maybeLength),
  22832. maybeLength, params);
  22833. }
  22834. return new FlateStream(stream, maybeLength);
  22835. }
  22836. if (name === 'LZWDecode' || name === 'LZW') {
  22837. xrefStreamStats[StreamType.LZW] = true;
  22838. var earlyChange = 1;
  22839. if (params) {
  22840. if (params.has('EarlyChange')) {
  22841. earlyChange = params.get('EarlyChange');
  22842. }
  22843. return new PredictorStream(
  22844. new LZWStream(stream, maybeLength, earlyChange),
  22845. maybeLength, params);
  22846. }
  22847. return new LZWStream(stream, maybeLength, earlyChange);
  22848. }
  22849. if (name === 'DCTDecode' || name === 'DCT') {
  22850. xrefStreamStats[StreamType.DCT] = true;
  22851. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  22852. }
  22853. if (name === 'JPXDecode' || name === 'JPX') {
  22854. xrefStreamStats[StreamType.JPX] = true;
  22855. return new JpxStream(stream, maybeLength, stream.dict);
  22856. }
  22857. if (name === 'ASCII85Decode' || name === 'A85') {
  22858. xrefStreamStats[StreamType.A85] = true;
  22859. return new Ascii85Stream(stream, maybeLength);
  22860. }
  22861. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  22862. xrefStreamStats[StreamType.AHX] = true;
  22863. return new AsciiHexStream(stream, maybeLength);
  22864. }
  22865. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  22866. xrefStreamStats[StreamType.CCF] = true;
  22867. return new CCITTFaxStream(stream, maybeLength, params);
  22868. }
  22869. if (name === 'RunLengthDecode' || name === 'RL') {
  22870. xrefStreamStats[StreamType.RL] = true;
  22871. return new RunLengthStream(stream, maybeLength);
  22872. }
  22873. if (name === 'JBIG2Decode') {
  22874. xrefStreamStats[StreamType.JBIG] = true;
  22875. return new Jbig2Stream(stream, maybeLength, stream.dict);
  22876. }
  22877. warn('filter "' + name + '" not supported yet');
  22878. return stream;
  22879. } catch (ex) {
  22880. if (ex instanceof MissingDataException) {
  22881. throw ex;
  22882. }
  22883. warn('Invalid stream: \"' + ex + '\"');
  22884. return new NullStream(stream);
  22885. }
  22886. }
  22887. };
  22888. return Parser;
  22889. })();
  22890. var Lexer = (function LexerClosure() {
  22891. function Lexer(stream, knownCommands) {
  22892. this.stream = stream;
  22893. this.nextChar();
  22894. // While lexing, we build up many strings one char at a time. Using += for
  22895. // this can result in lots of garbage strings. It's better to build an
  22896. // array of single-char strings and then join() them together at the end.
  22897. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  22898. // purpose uses less memory than using a new array for each string.
  22899. this.strBuf = [];
  22900. // The PDFs might have "glued" commands with other commands, operands or
  22901. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  22902. // commands and their prefixes. The prefixes are built the following way:
  22903. // if there a command that is a prefix of the other valid command or
  22904. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  22905. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  22906. // other commands or literals as a prefix. The knowCommands is optional.
  22907. this.knownCommands = knownCommands;
  22908. }
  22909. Lexer.isSpace = function Lexer_isSpace(ch) {
  22910. // Space is one of the following characters: SPACE, TAB, CR or LF.
  22911. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  22912. };
  22913. // A '1' in this array means the character is white space. A '1' or
  22914. // '2' means the character ends a name or command.
  22915. var specialChars = [
  22916. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  22917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  22918. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  22919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  22920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  22921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  22922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  22923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  22924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  22925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  22926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  22927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  22928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  22929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  22930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  22931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  22932. ];
  22933. function toHexDigit(ch) {
  22934. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  22935. return ch & 0x0F;
  22936. }
  22937. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  22938. // 'A'-'F', 'a'-'f'
  22939. return (ch & 0x0F) + 9;
  22940. }
  22941. return -1;
  22942. }
  22943. Lexer.prototype = {
  22944. nextChar: function Lexer_nextChar() {
  22945. return (this.currentChar = this.stream.getByte());
  22946. },
  22947. peekChar: function Lexer_peekChar() {
  22948. return this.stream.peekByte();
  22949. },
  22950. getNumber: function Lexer_getNumber() {
  22951. var ch = this.currentChar;
  22952. var eNotation = false;
  22953. var divideBy = 0; // different from 0 if it's a floating point value
  22954. var sign = 1;
  22955. if (ch === 0x2D) { // '-'
  22956. sign = -1;
  22957. ch = this.nextChar();
  22958. if (ch === 0x2D) { // '-'
  22959. // Ignore double negative (this is consistent with Adobe Reader).
  22960. ch = this.nextChar();
  22961. }
  22962. } else if (ch === 0x2B) { // '+'
  22963. ch = this.nextChar();
  22964. }
  22965. if (ch === 0x2E) { // '.'
  22966. divideBy = 10;
  22967. ch = this.nextChar();
  22968. }
  22969. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  22970. error('Invalid number: ' + String.fromCharCode(ch));
  22971. return 0;
  22972. }
  22973. var baseValue = ch - 0x30; // '0'
  22974. var powerValue = 0;
  22975. var powerValueSign = 1;
  22976. while ((ch = this.nextChar()) >= 0) {
  22977. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  22978. var currentDigit = ch - 0x30; // '0'
  22979. if (eNotation) { // We are after an 'e' or 'E'
  22980. powerValue = powerValue * 10 + currentDigit;
  22981. } else {
  22982. if (divideBy !== 0) { // We are after a point
  22983. divideBy *= 10;
  22984. }
  22985. baseValue = baseValue * 10 + currentDigit;
  22986. }
  22987. } else if (ch === 0x2E) { // '.'
  22988. if (divideBy === 0) {
  22989. divideBy = 1;
  22990. } else {
  22991. // A number can have only one '.'
  22992. break;
  22993. }
  22994. } else if (ch === 0x2D) { // '-'
  22995. // ignore minus signs in the middle of numbers to match
  22996. // Adobe's behavior
  22997. warn('Badly formated number');
  22998. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  22999. // 'E' can be either a scientific notation or the beginning of a new
  23000. // operator
  23001. ch = this.peekChar();
  23002. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  23003. powerValueSign = (ch === 0x2D) ? -1 : 1;
  23004. this.nextChar(); // Consume the sign character
  23005. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  23006. // The 'E' must be the beginning of a new operator
  23007. break;
  23008. }
  23009. eNotation = true;
  23010. } else {
  23011. // the last character doesn't belong to us
  23012. break;
  23013. }
  23014. }
  23015. if (divideBy !== 0) {
  23016. baseValue /= divideBy;
  23017. }
  23018. if (eNotation) {
  23019. baseValue *= Math.pow(10, powerValueSign * powerValue);
  23020. }
  23021. return sign * baseValue;
  23022. },
  23023. getString: function Lexer_getString() {
  23024. var numParen = 1;
  23025. var done = false;
  23026. var strBuf = this.strBuf;
  23027. strBuf.length = 0;
  23028. var ch = this.nextChar();
  23029. while (true) {
  23030. var charBuffered = false;
  23031. switch (ch | 0) {
  23032. case -1:
  23033. warn('Unterminated string');
  23034. done = true;
  23035. break;
  23036. case 0x28: // '('
  23037. ++numParen;
  23038. strBuf.push('(');
  23039. break;
  23040. case 0x29: // ')'
  23041. if (--numParen === 0) {
  23042. this.nextChar(); // consume strings ')'
  23043. done = true;
  23044. } else {
  23045. strBuf.push(')');
  23046. }
  23047. break;
  23048. case 0x5C: // '\\'
  23049. ch = this.nextChar();
  23050. switch (ch) {
  23051. case -1:
  23052. warn('Unterminated string');
  23053. done = true;
  23054. break;
  23055. case 0x6E: // 'n'
  23056. strBuf.push('\n');
  23057. break;
  23058. case 0x72: // 'r'
  23059. strBuf.push('\r');
  23060. break;
  23061. case 0x74: // 't'
  23062. strBuf.push('\t');
  23063. break;
  23064. case 0x62: // 'b'
  23065. strBuf.push('\b');
  23066. break;
  23067. case 0x66: // 'f'
  23068. strBuf.push('\f');
  23069. break;
  23070. case 0x5C: // '\'
  23071. case 0x28: // '('
  23072. case 0x29: // ')'
  23073. strBuf.push(String.fromCharCode(ch));
  23074. break;
  23075. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  23076. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  23077. var x = ch & 0x0F;
  23078. ch = this.nextChar();
  23079. charBuffered = true;
  23080. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  23081. x = (x << 3) + (ch & 0x0F);
  23082. ch = this.nextChar();
  23083. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  23084. charBuffered = false;
  23085. x = (x << 3) + (ch & 0x0F);
  23086. }
  23087. }
  23088. strBuf.push(String.fromCharCode(x));
  23089. break;
  23090. case 0x0D: // CR
  23091. if (this.peekChar() === 0x0A) { // LF
  23092. this.nextChar();
  23093. }
  23094. break;
  23095. case 0x0A: // LF
  23096. break;
  23097. default:
  23098. strBuf.push(String.fromCharCode(ch));
  23099. break;
  23100. }
  23101. break;
  23102. default:
  23103. strBuf.push(String.fromCharCode(ch));
  23104. break;
  23105. }
  23106. if (done) {
  23107. break;
  23108. }
  23109. if (!charBuffered) {
  23110. ch = this.nextChar();
  23111. }
  23112. }
  23113. return strBuf.join('');
  23114. },
  23115. getName: function Lexer_getName() {
  23116. var ch, previousCh;
  23117. var strBuf = this.strBuf;
  23118. strBuf.length = 0;
  23119. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  23120. if (ch === 0x23) { // '#'
  23121. ch = this.nextChar();
  23122. if (specialChars[ch]) {
  23123. warn('Lexer_getName: ' +
  23124. 'NUMBER SIGN (#) should be followed by a hexadecimal number.');
  23125. strBuf.push('#');
  23126. break;
  23127. }
  23128. var x = toHexDigit(ch);
  23129. if (x !== -1) {
  23130. previousCh = ch;
  23131. ch = this.nextChar();
  23132. var x2 = toHexDigit(ch);
  23133. if (x2 === -1) {
  23134. warn('Lexer_getName: Illegal digit (' +
  23135. String.fromCharCode(ch) +') in hexadecimal number.');
  23136. strBuf.push('#', String.fromCharCode(previousCh));
  23137. if (specialChars[ch]) {
  23138. break;
  23139. }
  23140. strBuf.push(String.fromCharCode(ch));
  23141. continue;
  23142. }
  23143. strBuf.push(String.fromCharCode((x << 4) | x2));
  23144. } else {
  23145. strBuf.push('#', String.fromCharCode(ch));
  23146. }
  23147. } else {
  23148. strBuf.push(String.fromCharCode(ch));
  23149. }
  23150. }
  23151. if (strBuf.length > 127) {
  23152. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  23153. }
  23154. return Name.get(strBuf.join(''));
  23155. },
  23156. getHexString: function Lexer_getHexString() {
  23157. var strBuf = this.strBuf;
  23158. strBuf.length = 0;
  23159. var ch = this.currentChar;
  23160. var isFirstHex = true;
  23161. var firstDigit;
  23162. var secondDigit;
  23163. while (true) {
  23164. if (ch < 0) {
  23165. warn('Unterminated hex string');
  23166. break;
  23167. } else if (ch === 0x3E) { // '>'
  23168. this.nextChar();
  23169. break;
  23170. } else if (specialChars[ch] === 1) {
  23171. ch = this.nextChar();
  23172. continue;
  23173. } else {
  23174. if (isFirstHex) {
  23175. firstDigit = toHexDigit(ch);
  23176. if (firstDigit === -1) {
  23177. warn('Ignoring invalid character "' + ch + '" in hex string');
  23178. ch = this.nextChar();
  23179. continue;
  23180. }
  23181. } else {
  23182. secondDigit = toHexDigit(ch);
  23183. if (secondDigit === -1) {
  23184. warn('Ignoring invalid character "' + ch + '" in hex string');
  23185. ch = this.nextChar();
  23186. continue;
  23187. }
  23188. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  23189. }
  23190. isFirstHex = !isFirstHex;
  23191. ch = this.nextChar();
  23192. }
  23193. }
  23194. return strBuf.join('');
  23195. },
  23196. getObj: function Lexer_getObj() {
  23197. // skip whitespace and comments
  23198. var comment = false;
  23199. var ch = this.currentChar;
  23200. while (true) {
  23201. if (ch < 0) {
  23202. return EOF;
  23203. }
  23204. if (comment) {
  23205. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  23206. comment = false;
  23207. }
  23208. } else if (ch === 0x25) { // '%'
  23209. comment = true;
  23210. } else if (specialChars[ch] !== 1) {
  23211. break;
  23212. }
  23213. ch = this.nextChar();
  23214. }
  23215. // start reading token
  23216. switch (ch | 0) {
  23217. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  23218. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  23219. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  23220. return this.getNumber();
  23221. case 0x28: // '('
  23222. return this.getString();
  23223. case 0x2F: // '/'
  23224. return this.getName();
  23225. // array punctuation
  23226. case 0x5B: // '['
  23227. this.nextChar();
  23228. return Cmd.get('[');
  23229. case 0x5D: // ']'
  23230. this.nextChar();
  23231. return Cmd.get(']');
  23232. // hex string or dict punctuation
  23233. case 0x3C: // '<'
  23234. ch = this.nextChar();
  23235. if (ch === 0x3C) {
  23236. // dict punctuation
  23237. this.nextChar();
  23238. return Cmd.get('<<');
  23239. }
  23240. return this.getHexString();
  23241. // dict punctuation
  23242. case 0x3E: // '>'
  23243. ch = this.nextChar();
  23244. if (ch === 0x3E) {
  23245. this.nextChar();
  23246. return Cmd.get('>>');
  23247. }
  23248. return Cmd.get('>');
  23249. case 0x7B: // '{'
  23250. this.nextChar();
  23251. return Cmd.get('{');
  23252. case 0x7D: // '}'
  23253. this.nextChar();
  23254. return Cmd.get('}');
  23255. case 0x29: // ')'
  23256. error('Illegal character: ' + ch);
  23257. break;
  23258. }
  23259. // command
  23260. var str = String.fromCharCode(ch);
  23261. var knownCommands = this.knownCommands;
  23262. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  23263. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  23264. // stop if known command is found and next character does not make
  23265. // the str a command
  23266. var possibleCommand = str + String.fromCharCode(ch);
  23267. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  23268. break;
  23269. }
  23270. if (str.length === 128) {
  23271. error('Command token too long: ' + str.length);
  23272. }
  23273. str = possibleCommand;
  23274. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  23275. }
  23276. if (str === 'true') {
  23277. return true;
  23278. }
  23279. if (str === 'false') {
  23280. return false;
  23281. }
  23282. if (str === 'null') {
  23283. return null;
  23284. }
  23285. return Cmd.get(str);
  23286. },
  23287. skipToNextLine: function Lexer_skipToNextLine() {
  23288. var ch = this.currentChar;
  23289. while (ch >= 0) {
  23290. if (ch === 0x0D) { // CR
  23291. ch = this.nextChar();
  23292. if (ch === 0x0A) { // LF
  23293. this.nextChar();
  23294. }
  23295. break;
  23296. } else if (ch === 0x0A) { // LF
  23297. this.nextChar();
  23298. break;
  23299. }
  23300. ch = this.nextChar();
  23301. }
  23302. }
  23303. };
  23304. return Lexer;
  23305. })();
  23306. var Linearization = {
  23307. create: function LinearizationCreate(stream) {
  23308. function getInt(name, allowZeroValue) {
  23309. var obj = linDict.get(name);
  23310. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  23311. return obj;
  23312. }
  23313. throw new Error('The "' + name + '" parameter in the linearization ' +
  23314. 'dictionary is invalid.');
  23315. }
  23316. function getHints() {
  23317. var hints = linDict.get('H'), hintsLength, item;
  23318. if (isArray(hints) &&
  23319. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  23320. for (var index = 0; index < hintsLength; index++) {
  23321. if (!(isInt(item = hints[index]) && item > 0)) {
  23322. throw new Error('Hint (' + index +
  23323. ') in the linearization dictionary is invalid.');
  23324. }
  23325. }
  23326. return hints;
  23327. }
  23328. throw new Error('Hint array in the linearization dictionary is invalid.');
  23329. }
  23330. var parser = new Parser(new Lexer(stream), false, null);
  23331. var obj1 = parser.getObj();
  23332. var obj2 = parser.getObj();
  23333. var obj3 = parser.getObj();
  23334. var linDict = parser.getObj();
  23335. var obj, length;
  23336. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  23337. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  23338. return null; // No valid linearization dictionary found.
  23339. } else if ((length = getInt('L')) !== stream.length) {
  23340. throw new Error('The "L" parameter in the linearization dictionary ' +
  23341. 'does not equal the stream length.');
  23342. }
  23343. return {
  23344. length: length,
  23345. hints: getHints(),
  23346. objectNumberFirst: getInt('O'),
  23347. endFirst: getInt('E'),
  23348. numPages: getInt('N'),
  23349. mainXRefEntriesOffset: getInt('T'),
  23350. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  23351. };
  23352. }
  23353. };
  23354. exports.EOF = EOF;
  23355. exports.Lexer = Lexer;
  23356. exports.Linearization = Linearization;
  23357. exports.Parser = Parser;
  23358. exports.isEOF = isEOF;
  23359. // TODO refactor to remove dependency on stream.js
  23360. coreStream._setCoreParser(exports);
  23361. }));
  23362. (function (root, factory) {
  23363. {
  23364. factory((root.pdfjsCoreCMap = {}), root.pdfjsSharedUtil,
  23365. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser);
  23366. }
  23367. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser) {
  23368. var Util = sharedUtil.Util;
  23369. var assert = sharedUtil.assert;
  23370. var error = sharedUtil.error;
  23371. var isInt = sharedUtil.isInt;
  23372. var isString = sharedUtil.isString;
  23373. var warn = sharedUtil.warn;
  23374. var isName = corePrimitives.isName;
  23375. var isCmd = corePrimitives.isCmd;
  23376. var isStream = corePrimitives.isStream;
  23377. var StringStream = coreStream.StringStream;
  23378. var Lexer = coreParser.Lexer;
  23379. var isEOF = coreParser.isEOF;
  23380. var BUILT_IN_CMAPS = [
  23381. // << Start unicode maps.
  23382. 'Adobe-GB1-UCS2',
  23383. 'Adobe-CNS1-UCS2',
  23384. 'Adobe-Japan1-UCS2',
  23385. 'Adobe-Korea1-UCS2',
  23386. // >> End unicode maps.
  23387. '78-EUC-H',
  23388. '78-EUC-V',
  23389. '78-H',
  23390. '78-RKSJ-H',
  23391. '78-RKSJ-V',
  23392. '78-V',
  23393. '78ms-RKSJ-H',
  23394. '78ms-RKSJ-V',
  23395. '83pv-RKSJ-H',
  23396. '90ms-RKSJ-H',
  23397. '90ms-RKSJ-V',
  23398. '90msp-RKSJ-H',
  23399. '90msp-RKSJ-V',
  23400. '90pv-RKSJ-H',
  23401. '90pv-RKSJ-V',
  23402. 'Add-H',
  23403. 'Add-RKSJ-H',
  23404. 'Add-RKSJ-V',
  23405. 'Add-V',
  23406. 'Adobe-CNS1-0',
  23407. 'Adobe-CNS1-1',
  23408. 'Adobe-CNS1-2',
  23409. 'Adobe-CNS1-3',
  23410. 'Adobe-CNS1-4',
  23411. 'Adobe-CNS1-5',
  23412. 'Adobe-CNS1-6',
  23413. 'Adobe-GB1-0',
  23414. 'Adobe-GB1-1',
  23415. 'Adobe-GB1-2',
  23416. 'Adobe-GB1-3',
  23417. 'Adobe-GB1-4',
  23418. 'Adobe-GB1-5',
  23419. 'Adobe-Japan1-0',
  23420. 'Adobe-Japan1-1',
  23421. 'Adobe-Japan1-2',
  23422. 'Adobe-Japan1-3',
  23423. 'Adobe-Japan1-4',
  23424. 'Adobe-Japan1-5',
  23425. 'Adobe-Japan1-6',
  23426. 'Adobe-Korea1-0',
  23427. 'Adobe-Korea1-1',
  23428. 'Adobe-Korea1-2',
  23429. 'B5-H',
  23430. 'B5-V',
  23431. 'B5pc-H',
  23432. 'B5pc-V',
  23433. 'CNS-EUC-H',
  23434. 'CNS-EUC-V',
  23435. 'CNS1-H',
  23436. 'CNS1-V',
  23437. 'CNS2-H',
  23438. 'CNS2-V',
  23439. 'ETHK-B5-H',
  23440. 'ETHK-B5-V',
  23441. 'ETen-B5-H',
  23442. 'ETen-B5-V',
  23443. 'ETenms-B5-H',
  23444. 'ETenms-B5-V',
  23445. 'EUC-H',
  23446. 'EUC-V',
  23447. 'Ext-H',
  23448. 'Ext-RKSJ-H',
  23449. 'Ext-RKSJ-V',
  23450. 'Ext-V',
  23451. 'GB-EUC-H',
  23452. 'GB-EUC-V',
  23453. 'GB-H',
  23454. 'GB-V',
  23455. 'GBK-EUC-H',
  23456. 'GBK-EUC-V',
  23457. 'GBK2K-H',
  23458. 'GBK2K-V',
  23459. 'GBKp-EUC-H',
  23460. 'GBKp-EUC-V',
  23461. 'GBT-EUC-H',
  23462. 'GBT-EUC-V',
  23463. 'GBT-H',
  23464. 'GBT-V',
  23465. 'GBTpc-EUC-H',
  23466. 'GBTpc-EUC-V',
  23467. 'GBpc-EUC-H',
  23468. 'GBpc-EUC-V',
  23469. 'H',
  23470. 'HKdla-B5-H',
  23471. 'HKdla-B5-V',
  23472. 'HKdlb-B5-H',
  23473. 'HKdlb-B5-V',
  23474. 'HKgccs-B5-H',
  23475. 'HKgccs-B5-V',
  23476. 'HKm314-B5-H',
  23477. 'HKm314-B5-V',
  23478. 'HKm471-B5-H',
  23479. 'HKm471-B5-V',
  23480. 'HKscs-B5-H',
  23481. 'HKscs-B5-V',
  23482. 'Hankaku',
  23483. 'Hiragana',
  23484. 'KSC-EUC-H',
  23485. 'KSC-EUC-V',
  23486. 'KSC-H',
  23487. 'KSC-Johab-H',
  23488. 'KSC-Johab-V',
  23489. 'KSC-V',
  23490. 'KSCms-UHC-H',
  23491. 'KSCms-UHC-HW-H',
  23492. 'KSCms-UHC-HW-V',
  23493. 'KSCms-UHC-V',
  23494. 'KSCpc-EUC-H',
  23495. 'KSCpc-EUC-V',
  23496. 'Katakana',
  23497. 'NWP-H',
  23498. 'NWP-V',
  23499. 'RKSJ-H',
  23500. 'RKSJ-V',
  23501. 'Roman',
  23502. 'UniCNS-UCS2-H',
  23503. 'UniCNS-UCS2-V',
  23504. 'UniCNS-UTF16-H',
  23505. 'UniCNS-UTF16-V',
  23506. 'UniCNS-UTF32-H',
  23507. 'UniCNS-UTF32-V',
  23508. 'UniCNS-UTF8-H',
  23509. 'UniCNS-UTF8-V',
  23510. 'UniGB-UCS2-H',
  23511. 'UniGB-UCS2-V',
  23512. 'UniGB-UTF16-H',
  23513. 'UniGB-UTF16-V',
  23514. 'UniGB-UTF32-H',
  23515. 'UniGB-UTF32-V',
  23516. 'UniGB-UTF8-H',
  23517. 'UniGB-UTF8-V',
  23518. 'UniJIS-UCS2-H',
  23519. 'UniJIS-UCS2-HW-H',
  23520. 'UniJIS-UCS2-HW-V',
  23521. 'UniJIS-UCS2-V',
  23522. 'UniJIS-UTF16-H',
  23523. 'UniJIS-UTF16-V',
  23524. 'UniJIS-UTF32-H',
  23525. 'UniJIS-UTF32-V',
  23526. 'UniJIS-UTF8-H',
  23527. 'UniJIS-UTF8-V',
  23528. 'UniJIS2004-UTF16-H',
  23529. 'UniJIS2004-UTF16-V',
  23530. 'UniJIS2004-UTF32-H',
  23531. 'UniJIS2004-UTF32-V',
  23532. 'UniJIS2004-UTF8-H',
  23533. 'UniJIS2004-UTF8-V',
  23534. 'UniJISPro-UCS2-HW-V',
  23535. 'UniJISPro-UCS2-V',
  23536. 'UniJISPro-UTF8-V',
  23537. 'UniJISX0213-UTF32-H',
  23538. 'UniJISX0213-UTF32-V',
  23539. 'UniJISX02132004-UTF32-H',
  23540. 'UniJISX02132004-UTF32-V',
  23541. 'UniKS-UCS2-H',
  23542. 'UniKS-UCS2-V',
  23543. 'UniKS-UTF16-H',
  23544. 'UniKS-UTF16-V',
  23545. 'UniKS-UTF32-H',
  23546. 'UniKS-UTF32-V',
  23547. 'UniKS-UTF8-H',
  23548. 'UniKS-UTF8-V',
  23549. 'V',
  23550. 'WP-Symbol'];
  23551. // CMap, not to be confused with TrueType's cmap.
  23552. var CMap = (function CMapClosure() {
  23553. function CMap(builtInCMap) {
  23554. // Codespace ranges are stored as follows:
  23555. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  23556. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  23557. this.codespaceRanges = [[], [], [], []];
  23558. this.numCodespaceRanges = 0;
  23559. // Map entries have one of two forms.
  23560. // - cid chars are 16-bit unsigned integers, stored as integers.
  23561. // - bf chars are variable-length byte sequences, stored as strings, with
  23562. // one byte per character.
  23563. this._map = [];
  23564. this.name = '';
  23565. this.vertical = false;
  23566. this.useCMap = null;
  23567. this.builtInCMap = builtInCMap;
  23568. }
  23569. CMap.prototype = {
  23570. addCodespaceRange: function(n, low, high) {
  23571. this.codespaceRanges[n - 1].push(low, high);
  23572. this.numCodespaceRanges++;
  23573. },
  23574. mapCidRange: function(low, high, dstLow) {
  23575. while (low <= high) {
  23576. this._map[low++] = dstLow++;
  23577. }
  23578. },
  23579. mapBfRange: function(low, high, dstLow) {
  23580. var lastByte = dstLow.length - 1;
  23581. while (low <= high) {
  23582. this._map[low++] = dstLow;
  23583. // Only the last byte has to be incremented.
  23584. dstLow = dstLow.substr(0, lastByte) +
  23585. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  23586. }
  23587. },
  23588. mapBfRangeToArray: function(low, high, array) {
  23589. var i = 0, ii = array.length;
  23590. while (low <= high && i < ii) {
  23591. this._map[low] = array[i++];
  23592. ++low;
  23593. }
  23594. },
  23595. // This is used for both bf and cid chars.
  23596. mapOne: function(src, dst) {
  23597. this._map[src] = dst;
  23598. },
  23599. lookup: function(code) {
  23600. return this._map[code];
  23601. },
  23602. contains: function(code) {
  23603. return this._map[code] !== undefined;
  23604. },
  23605. forEach: function(callback) {
  23606. // Most maps have fewer than 65536 entries, and for those we use normal
  23607. // array iteration. But really sparse tables are possible -- e.g. with
  23608. // indices in the *billions*. For such tables we use for..in, which isn't
  23609. // ideal because it stringifies the indices for all present elements, but
  23610. // it does avoid iterating over every undefined entry.
  23611. var map = this._map;
  23612. var length = map.length;
  23613. var i;
  23614. if (length <= 0x10000) {
  23615. for (i = 0; i < length; i++) {
  23616. if (map[i] !== undefined) {
  23617. callback(i, map[i]);
  23618. }
  23619. }
  23620. } else {
  23621. for (i in this._map) {
  23622. callback(i, map[i]);
  23623. }
  23624. }
  23625. },
  23626. charCodeOf: function(value) {
  23627. return this._map.indexOf(value);
  23628. },
  23629. getMap: function() {
  23630. return this._map;
  23631. },
  23632. readCharCode: function(str, offset, out) {
  23633. var c = 0;
  23634. var codespaceRanges = this.codespaceRanges;
  23635. var codespaceRangesLen = this.codespaceRanges.length;
  23636. // 9.7.6.2 CMap Mapping
  23637. // The code length is at most 4.
  23638. for (var n = 0; n < codespaceRangesLen; n++) {
  23639. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  23640. // Check each codespace range to see if it falls within.
  23641. var codespaceRange = codespaceRanges[n];
  23642. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  23643. var low = codespaceRange[k++];
  23644. var high = codespaceRange[k++];
  23645. if (c >= low && c <= high) {
  23646. out.charcode = c;
  23647. out.length = n + 1;
  23648. return;
  23649. }
  23650. }
  23651. }
  23652. out.charcode = 0;
  23653. out.length = 1;
  23654. },
  23655. get length() {
  23656. return this._map.length;
  23657. },
  23658. get isIdentityCMap() {
  23659. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  23660. return false;
  23661. }
  23662. if (this._map.length !== 0x10000) {
  23663. return false;
  23664. }
  23665. for (var i = 0; i < 0x10000; i++) {
  23666. if (this._map[i] !== i) {
  23667. return false;
  23668. }
  23669. }
  23670. return true;
  23671. }
  23672. };
  23673. return CMap;
  23674. })();
  23675. // A special case of CMap, where the _map array implicitly has a length of
  23676. // 65536 and each element is equal to its index.
  23677. var IdentityCMap = (function IdentityCMapClosure() {
  23678. function IdentityCMap(vertical, n) {
  23679. CMap.call(this);
  23680. this.vertical = vertical;
  23681. this.addCodespaceRange(n, 0, 0xffff);
  23682. }
  23683. Util.inherit(IdentityCMap, CMap, {});
  23684. IdentityCMap.prototype = {
  23685. addCodespaceRange: CMap.prototype.addCodespaceRange,
  23686. mapCidRange: function(low, high, dstLow) {
  23687. error('should not call mapCidRange');
  23688. },
  23689. mapBfRange: function(low, high, dstLow) {
  23690. error('should not call mapBfRange');
  23691. },
  23692. mapBfRangeToArray: function(low, high, array) {
  23693. error('should not call mapBfRangeToArray');
  23694. },
  23695. mapOne: function(src, dst) {
  23696. error('should not call mapCidOne');
  23697. },
  23698. lookup: function(code) {
  23699. return (isInt(code) && code <= 0xffff) ? code : undefined;
  23700. },
  23701. contains: function(code) {
  23702. return isInt(code) && code <= 0xffff;
  23703. },
  23704. forEach: function(callback) {
  23705. for (var i = 0; i <= 0xffff; i++) {
  23706. callback(i, i);
  23707. }
  23708. },
  23709. charCodeOf: function(value) {
  23710. return (isInt(value) && value <= 0xffff) ? value : -1;
  23711. },
  23712. getMap: function() {
  23713. // Sometimes identity maps must be instantiated, but it's rare.
  23714. var map = new Array(0x10000);
  23715. for (var i = 0; i <= 0xffff; i++) {
  23716. map[i] = i;
  23717. }
  23718. return map;
  23719. },
  23720. readCharCode: CMap.prototype.readCharCode,
  23721. get length() {
  23722. return 0x10000;
  23723. },
  23724. get isIdentityCMap() {
  23725. error('should not access .isIdentityCMap');
  23726. }
  23727. };
  23728. return IdentityCMap;
  23729. })();
  23730. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  23731. function fetchBinaryData(url) {
  23732. var nonBinaryRequest = PDFJS.disableWorker;
  23733. var request = new XMLHttpRequest();
  23734. request.open('GET', url, false);
  23735. if (!nonBinaryRequest) {
  23736. try {
  23737. request.responseType = 'arraybuffer';
  23738. nonBinaryRequest = request.responseType !== 'arraybuffer';
  23739. } catch (e) {
  23740. nonBinaryRequest = true;
  23741. }
  23742. }
  23743. if (nonBinaryRequest && request.overrideMimeType) {
  23744. request.overrideMimeType('text/plain; charset=x-user-defined');
  23745. }
  23746. request.send(null);
  23747. if (nonBinaryRequest ? !request.responseText : !request.response) {
  23748. error('Unable to get binary cMap at: ' + url);
  23749. }
  23750. if (nonBinaryRequest) {
  23751. var data = Array.prototype.map.call(request.responseText, function (ch) {
  23752. return ch.charCodeAt(0) & 255;
  23753. });
  23754. return new Uint8Array(data);
  23755. }
  23756. return new Uint8Array(request.response);
  23757. }
  23758. function hexToInt(a, size) {
  23759. var n = 0;
  23760. for (var i = 0; i <= size; i++) {
  23761. n = (n << 8) | a[i];
  23762. }
  23763. return n >>> 0;
  23764. }
  23765. function hexToStr(a, size) {
  23766. // This code is hot. Special-case some common values to avoid creating an
  23767. // object with subarray().
  23768. if (size === 1) {
  23769. return String.fromCharCode(a[0], a[1]);
  23770. }
  23771. if (size === 3) {
  23772. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  23773. }
  23774. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  23775. }
  23776. function addHex(a, b, size) {
  23777. var c = 0;
  23778. for (var i = size; i >= 0; i--) {
  23779. c += a[i] + b[i];
  23780. a[i] = c & 255;
  23781. c >>= 8;
  23782. }
  23783. }
  23784. function incHex(a, size) {
  23785. var c = 1;
  23786. for (var i = size; i >= 0 && c > 0; i--) {
  23787. c += a[i];
  23788. a[i] = c & 255;
  23789. c >>= 8;
  23790. }
  23791. }
  23792. var MAX_NUM_SIZE = 16;
  23793. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  23794. function BinaryCMapStream(data) {
  23795. this.buffer = data;
  23796. this.pos = 0;
  23797. this.end = data.length;
  23798. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  23799. }
  23800. BinaryCMapStream.prototype = {
  23801. readByte: function () {
  23802. if (this.pos >= this.end) {
  23803. return -1;
  23804. }
  23805. return this.buffer[this.pos++];
  23806. },
  23807. readNumber: function () {
  23808. var n = 0;
  23809. var last;
  23810. do {
  23811. var b = this.readByte();
  23812. if (b < 0) {
  23813. error('unexpected EOF in bcmap');
  23814. }
  23815. last = !(b & 0x80);
  23816. n = (n << 7) | (b & 0x7F);
  23817. } while (!last);
  23818. return n;
  23819. },
  23820. readSigned: function () {
  23821. var n = this.readNumber();
  23822. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  23823. },
  23824. readHex: function (num, size) {
  23825. num.set(this.buffer.subarray(this.pos,
  23826. this.pos + size + 1));
  23827. this.pos += size + 1;
  23828. },
  23829. readHexNumber: function (num, size) {
  23830. var last;
  23831. var stack = this.tmpBuf, sp = 0;
  23832. do {
  23833. var b = this.readByte();
  23834. if (b < 0) {
  23835. error('unexpected EOF in bcmap');
  23836. }
  23837. last = !(b & 0x80);
  23838. stack[sp++] = b & 0x7F;
  23839. } while (!last);
  23840. var i = size, buffer = 0, bufferSize = 0;
  23841. while (i >= 0) {
  23842. while (bufferSize < 8 && stack.length > 0) {
  23843. buffer = (stack[--sp] << bufferSize) | buffer;
  23844. bufferSize += 7;
  23845. }
  23846. num[i] = buffer & 255;
  23847. i--;
  23848. buffer >>= 8;
  23849. bufferSize -= 8;
  23850. }
  23851. },
  23852. readHexSigned: function (num, size) {
  23853. this.readHexNumber(num, size);
  23854. var sign = num[size] & 1 ? 255 : 0;
  23855. var c = 0;
  23856. for (var i = 0; i <= size; i++) {
  23857. c = ((c & 1) << 8) | num[i];
  23858. num[i] = (c >> 1) ^ sign;
  23859. }
  23860. },
  23861. readString: function () {
  23862. var len = this.readNumber();
  23863. var s = '';
  23864. for (var i = 0; i < len; i++) {
  23865. s += String.fromCharCode(this.readNumber());
  23866. }
  23867. return s;
  23868. }
  23869. };
  23870. function processBinaryCMap(url, cMap, extend) {
  23871. var data = fetchBinaryData(url);
  23872. var stream = new BinaryCMapStream(data);
  23873. var header = stream.readByte();
  23874. cMap.vertical = !!(header & 1);
  23875. var useCMap = null;
  23876. var start = new Uint8Array(MAX_NUM_SIZE);
  23877. var end = new Uint8Array(MAX_NUM_SIZE);
  23878. var char = new Uint8Array(MAX_NUM_SIZE);
  23879. var charCode = new Uint8Array(MAX_NUM_SIZE);
  23880. var tmp = new Uint8Array(MAX_NUM_SIZE);
  23881. var code;
  23882. var b;
  23883. while ((b = stream.readByte()) >= 0) {
  23884. var type = b >> 5;
  23885. if (type === 7) { // metadata, e.g. comment or usecmap
  23886. switch (b & 0x1F) {
  23887. case 0:
  23888. stream.readString(); // skipping comment
  23889. break;
  23890. case 1:
  23891. useCMap = stream.readString();
  23892. break;
  23893. }
  23894. continue;
  23895. }
  23896. var sequence = !!(b & 0x10);
  23897. var dataSize = b & 15;
  23898. assert(dataSize + 1 <= MAX_NUM_SIZE);
  23899. var ucs2DataSize = 1;
  23900. var subitemsCount = stream.readNumber();
  23901. var i;
  23902. switch (type) {
  23903. case 0: // codespacerange
  23904. stream.readHex(start, dataSize);
  23905. stream.readHexNumber(end, dataSize);
  23906. addHex(end, start, dataSize);
  23907. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  23908. hexToInt(end, dataSize));
  23909. for (i = 1; i < subitemsCount; i++) {
  23910. incHex(end, dataSize);
  23911. stream.readHexNumber(start, dataSize);
  23912. addHex(start, end, dataSize);
  23913. stream.readHexNumber(end, dataSize);
  23914. addHex(end, start, dataSize);
  23915. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  23916. hexToInt(end, dataSize));
  23917. }
  23918. break;
  23919. case 1: // notdefrange
  23920. stream.readHex(start, dataSize);
  23921. stream.readHexNumber(end, dataSize);
  23922. addHex(end, start, dataSize);
  23923. code = stream.readNumber();
  23924. // undefined range, skipping
  23925. for (i = 1; i < subitemsCount; i++) {
  23926. incHex(end, dataSize);
  23927. stream.readHexNumber(start, dataSize);
  23928. addHex(start, end, dataSize);
  23929. stream.readHexNumber(end, dataSize);
  23930. addHex(end, start, dataSize);
  23931. code = stream.readNumber();
  23932. // nop
  23933. }
  23934. break;
  23935. case 2: // cidchar
  23936. stream.readHex(char, dataSize);
  23937. code = stream.readNumber();
  23938. cMap.mapOne(hexToInt(char, dataSize), code);
  23939. for (i = 1; i < subitemsCount; i++) {
  23940. incHex(char, dataSize);
  23941. if (!sequence) {
  23942. stream.readHexNumber(tmp, dataSize);
  23943. addHex(char, tmp, dataSize);
  23944. }
  23945. code = stream.readSigned() + (code + 1);
  23946. cMap.mapOne(hexToInt(char, dataSize), code);
  23947. }
  23948. break;
  23949. case 3: // cidrange
  23950. stream.readHex(start, dataSize);
  23951. stream.readHexNumber(end, dataSize);
  23952. addHex(end, start, dataSize);
  23953. code = stream.readNumber();
  23954. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  23955. code);
  23956. for (i = 1; i < subitemsCount; i++) {
  23957. incHex(end, dataSize);
  23958. if (!sequence) {
  23959. stream.readHexNumber(start, dataSize);
  23960. addHex(start, end, dataSize);
  23961. } else {
  23962. start.set(end);
  23963. }
  23964. stream.readHexNumber(end, dataSize);
  23965. addHex(end, start, dataSize);
  23966. code = stream.readNumber();
  23967. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  23968. code);
  23969. }
  23970. break;
  23971. case 4: // bfchar
  23972. stream.readHex(char, ucs2DataSize);
  23973. stream.readHex(charCode, dataSize);
  23974. cMap.mapOne(hexToInt(char, ucs2DataSize),
  23975. hexToStr(charCode, dataSize));
  23976. for (i = 1; i < subitemsCount; i++) {
  23977. incHex(char, ucs2DataSize);
  23978. if (!sequence) {
  23979. stream.readHexNumber(tmp, ucs2DataSize);
  23980. addHex(char, tmp, ucs2DataSize);
  23981. }
  23982. incHex(charCode, dataSize);
  23983. stream.readHexSigned(tmp, dataSize);
  23984. addHex(charCode, tmp, dataSize);
  23985. cMap.mapOne(hexToInt(char, ucs2DataSize),
  23986. hexToStr(charCode, dataSize));
  23987. }
  23988. break;
  23989. case 5: // bfrange
  23990. stream.readHex(start, ucs2DataSize);
  23991. stream.readHexNumber(end, ucs2DataSize);
  23992. addHex(end, start, ucs2DataSize);
  23993. stream.readHex(charCode, dataSize);
  23994. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  23995. hexToInt(end, ucs2DataSize),
  23996. hexToStr(charCode, dataSize));
  23997. for (i = 1; i < subitemsCount; i++) {
  23998. incHex(end, ucs2DataSize);
  23999. if (!sequence) {
  24000. stream.readHexNumber(start, ucs2DataSize);
  24001. addHex(start, end, ucs2DataSize);
  24002. } else {
  24003. start.set(end);
  24004. }
  24005. stream.readHexNumber(end, ucs2DataSize);
  24006. addHex(end, start, ucs2DataSize);
  24007. stream.readHex(charCode, dataSize);
  24008. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  24009. hexToInt(end, ucs2DataSize),
  24010. hexToStr(charCode, dataSize));
  24011. }
  24012. break;
  24013. default:
  24014. error('Unknown type: ' + type);
  24015. break;
  24016. }
  24017. }
  24018. if (useCMap) {
  24019. extend(useCMap);
  24020. }
  24021. return cMap;
  24022. }
  24023. function BinaryCMapReader() {}
  24024. BinaryCMapReader.prototype = {
  24025. read: processBinaryCMap
  24026. };
  24027. return BinaryCMapReader;
  24028. })();
  24029. var CMapFactory = (function CMapFactoryClosure() {
  24030. function strToInt(str) {
  24031. var a = 0;
  24032. for (var i = 0; i < str.length; i++) {
  24033. a = (a << 8) | str.charCodeAt(i);
  24034. }
  24035. return a >>> 0;
  24036. }
  24037. function expectString(obj) {
  24038. if (!isString(obj)) {
  24039. error('Malformed CMap: expected string.');
  24040. }
  24041. }
  24042. function expectInt(obj) {
  24043. if (!isInt(obj)) {
  24044. error('Malformed CMap: expected int.');
  24045. }
  24046. }
  24047. function parseBfChar(cMap, lexer) {
  24048. while (true) {
  24049. var obj = lexer.getObj();
  24050. if (isEOF(obj)) {
  24051. break;
  24052. }
  24053. if (isCmd(obj, 'endbfchar')) {
  24054. return;
  24055. }
  24056. expectString(obj);
  24057. var src = strToInt(obj);
  24058. obj = lexer.getObj();
  24059. // TODO are /dstName used?
  24060. expectString(obj);
  24061. var dst = obj;
  24062. cMap.mapOne(src, dst);
  24063. }
  24064. }
  24065. function parseBfRange(cMap, lexer) {
  24066. while (true) {
  24067. var obj = lexer.getObj();
  24068. if (isEOF(obj)) {
  24069. break;
  24070. }
  24071. if (isCmd(obj, 'endbfrange')) {
  24072. return;
  24073. }
  24074. expectString(obj);
  24075. var low = strToInt(obj);
  24076. obj = lexer.getObj();
  24077. expectString(obj);
  24078. var high = strToInt(obj);
  24079. obj = lexer.getObj();
  24080. if (isInt(obj) || isString(obj)) {
  24081. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  24082. cMap.mapBfRange(low, high, dstLow);
  24083. } else if (isCmd(obj, '[')) {
  24084. obj = lexer.getObj();
  24085. var array = [];
  24086. while (!isCmd(obj, ']') && !isEOF(obj)) {
  24087. array.push(obj);
  24088. obj = lexer.getObj();
  24089. }
  24090. cMap.mapBfRangeToArray(low, high, array);
  24091. } else {
  24092. break;
  24093. }
  24094. }
  24095. error('Invalid bf range.');
  24096. }
  24097. function parseCidChar(cMap, lexer) {
  24098. while (true) {
  24099. var obj = lexer.getObj();
  24100. if (isEOF(obj)) {
  24101. break;
  24102. }
  24103. if (isCmd(obj, 'endcidchar')) {
  24104. return;
  24105. }
  24106. expectString(obj);
  24107. var src = strToInt(obj);
  24108. obj = lexer.getObj();
  24109. expectInt(obj);
  24110. var dst = obj;
  24111. cMap.mapOne(src, dst);
  24112. }
  24113. }
  24114. function parseCidRange(cMap, lexer) {
  24115. while (true) {
  24116. var obj = lexer.getObj();
  24117. if (isEOF(obj)) {
  24118. break;
  24119. }
  24120. if (isCmd(obj, 'endcidrange')) {
  24121. return;
  24122. }
  24123. expectString(obj);
  24124. var low = strToInt(obj);
  24125. obj = lexer.getObj();
  24126. expectString(obj);
  24127. var high = strToInt(obj);
  24128. obj = lexer.getObj();
  24129. expectInt(obj);
  24130. var dstLow = obj;
  24131. cMap.mapCidRange(low, high, dstLow);
  24132. }
  24133. }
  24134. function parseCodespaceRange(cMap, lexer) {
  24135. while (true) {
  24136. var obj = lexer.getObj();
  24137. if (isEOF(obj)) {
  24138. break;
  24139. }
  24140. if (isCmd(obj, 'endcodespacerange')) {
  24141. return;
  24142. }
  24143. if (!isString(obj)) {
  24144. break;
  24145. }
  24146. var low = strToInt(obj);
  24147. obj = lexer.getObj();
  24148. if (!isString(obj)) {
  24149. break;
  24150. }
  24151. var high = strToInt(obj);
  24152. cMap.addCodespaceRange(obj.length, low, high);
  24153. }
  24154. error('Invalid codespace range.');
  24155. }
  24156. function parseWMode(cMap, lexer) {
  24157. var obj = lexer.getObj();
  24158. if (isInt(obj)) {
  24159. cMap.vertical = !!obj;
  24160. }
  24161. }
  24162. function parseCMapName(cMap, lexer) {
  24163. var obj = lexer.getObj();
  24164. if (isName(obj) && isString(obj.name)) {
  24165. cMap.name = obj.name;
  24166. }
  24167. }
  24168. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  24169. var previous;
  24170. var embededUseCMap;
  24171. objLoop: while (true) {
  24172. var obj = lexer.getObj();
  24173. if (isEOF(obj)) {
  24174. break;
  24175. } else if (isName(obj)) {
  24176. if (obj.name === 'WMode') {
  24177. parseWMode(cMap, lexer);
  24178. } else if (obj.name === 'CMapName') {
  24179. parseCMapName(cMap, lexer);
  24180. }
  24181. previous = obj;
  24182. } else if (isCmd(obj)) {
  24183. switch (obj.cmd) {
  24184. case 'endcmap':
  24185. break objLoop;
  24186. case 'usecmap':
  24187. if (isName(previous)) {
  24188. embededUseCMap = previous.name;
  24189. }
  24190. break;
  24191. case 'begincodespacerange':
  24192. parseCodespaceRange(cMap, lexer);
  24193. break;
  24194. case 'beginbfchar':
  24195. parseBfChar(cMap, lexer);
  24196. break;
  24197. case 'begincidchar':
  24198. parseCidChar(cMap, lexer);
  24199. break;
  24200. case 'beginbfrange':
  24201. parseBfRange(cMap, lexer);
  24202. break;
  24203. case 'begincidrange':
  24204. parseCidRange(cMap, lexer);
  24205. break;
  24206. }
  24207. }
  24208. }
  24209. if (!useCMap && embededUseCMap) {
  24210. // Load the usecmap definition from the file only if there wasn't one
  24211. // specified.
  24212. useCMap = embededUseCMap;
  24213. }
  24214. if (useCMap) {
  24215. extendCMap(cMap, builtInCMapParams, useCMap);
  24216. }
  24217. }
  24218. function extendCMap(cMap, builtInCMapParams, useCMap) {
  24219. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  24220. // If there aren't any code space ranges defined clone all the parent ones
  24221. // into this cMap.
  24222. if (cMap.numCodespaceRanges === 0) {
  24223. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  24224. for (var i = 0; i < useCodespaceRanges.length; i++) {
  24225. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  24226. }
  24227. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  24228. }
  24229. // Merge the map into the current one, making sure not to override
  24230. // any previously defined entries.
  24231. cMap.useCMap.forEach(function(key, value) {
  24232. if (!cMap.contains(key)) {
  24233. cMap.mapOne(key, cMap.useCMap.lookup(key));
  24234. }
  24235. });
  24236. }
  24237. function parseBinaryCMap(name, builtInCMapParams) {
  24238. var url = builtInCMapParams.url + name + '.bcmap';
  24239. var cMap = new CMap(true);
  24240. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  24241. extendCMap(cMap, builtInCMapParams, useCMap);
  24242. });
  24243. return cMap;
  24244. }
  24245. function createBuiltInCMap(name, builtInCMapParams) {
  24246. if (name === 'Identity-H') {
  24247. return new IdentityCMap(false, 2);
  24248. } else if (name === 'Identity-V') {
  24249. return new IdentityCMap(true, 2);
  24250. }
  24251. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  24252. error('Unknown cMap name: ' + name);
  24253. }
  24254. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  24255. if (builtInCMapParams.packed) {
  24256. return parseBinaryCMap(name, builtInCMapParams);
  24257. }
  24258. var request = new XMLHttpRequest();
  24259. var url = builtInCMapParams.url + name;
  24260. request.open('GET', url, false);
  24261. request.send(null);
  24262. if (!request.responseText) {
  24263. error('Unable to get cMap at: ' + url);
  24264. }
  24265. var cMap = new CMap(true);
  24266. var lexer = new Lexer(new StringStream(request.responseText));
  24267. parseCMap(cMap, lexer, builtInCMapParams, null);
  24268. return cMap;
  24269. }
  24270. return {
  24271. create: function (encoding, builtInCMapParams, useCMap) {
  24272. if (isName(encoding)) {
  24273. return createBuiltInCMap(encoding.name, builtInCMapParams);
  24274. } else if (isStream(encoding)) {
  24275. var cMap = new CMap();
  24276. var lexer = new Lexer(encoding);
  24277. try {
  24278. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  24279. } catch (e) {
  24280. warn('Invalid CMap data. ' + e);
  24281. }
  24282. if (cMap.isIdentityCMap) {
  24283. return createBuiltInCMap(cMap.name, builtInCMapParams);
  24284. }
  24285. return cMap;
  24286. }
  24287. error('Encoding required.');
  24288. }
  24289. };
  24290. })();
  24291. exports.CMap = CMap;
  24292. exports.CMapFactory = CMapFactory;
  24293. exports.IdentityCMap = IdentityCMap;
  24294. }));
  24295. (function (root, factory) {
  24296. {
  24297. factory((root.pdfjsCorePsParser = {}), root.pdfjsSharedUtil,
  24298. root.pdfjsCoreParser);
  24299. }
  24300. }(this, function (exports, sharedUtil, coreParser) {
  24301. var error = sharedUtil.error;
  24302. var EOF = coreParser.EOF;
  24303. var Lexer = coreParser.Lexer;
  24304. var PostScriptParser = (function PostScriptParserClosure() {
  24305. function PostScriptParser(lexer) {
  24306. this.lexer = lexer;
  24307. this.operators = [];
  24308. this.token = null;
  24309. this.prev = null;
  24310. }
  24311. PostScriptParser.prototype = {
  24312. nextToken: function PostScriptParser_nextToken() {
  24313. this.prev = this.token;
  24314. this.token = this.lexer.getToken();
  24315. },
  24316. accept: function PostScriptParser_accept(type) {
  24317. if (this.token.type === type) {
  24318. this.nextToken();
  24319. return true;
  24320. }
  24321. return false;
  24322. },
  24323. expect: function PostScriptParser_expect(type) {
  24324. if (this.accept(type)) {
  24325. return true;
  24326. }
  24327. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  24328. type + '.');
  24329. },
  24330. parse: function PostScriptParser_parse() {
  24331. this.nextToken();
  24332. this.expect(PostScriptTokenTypes.LBRACE);
  24333. this.parseBlock();
  24334. this.expect(PostScriptTokenTypes.RBRACE);
  24335. return this.operators;
  24336. },
  24337. parseBlock: function PostScriptParser_parseBlock() {
  24338. while (true) {
  24339. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  24340. this.operators.push(this.prev.value);
  24341. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  24342. this.operators.push(this.prev.value);
  24343. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  24344. this.parseCondition();
  24345. } else {
  24346. return;
  24347. }
  24348. }
  24349. },
  24350. parseCondition: function PostScriptParser_parseCondition() {
  24351. // Add two place holders that will be updated later
  24352. var conditionLocation = this.operators.length;
  24353. this.operators.push(null, null);
  24354. this.parseBlock();
  24355. this.expect(PostScriptTokenTypes.RBRACE);
  24356. if (this.accept(PostScriptTokenTypes.IF)) {
  24357. // The true block is right after the 'if' so it just falls through on
  24358. // true else it jumps and skips the true block.
  24359. this.operators[conditionLocation] = this.operators.length;
  24360. this.operators[conditionLocation + 1] = 'jz';
  24361. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  24362. var jumpLocation = this.operators.length;
  24363. this.operators.push(null, null);
  24364. var endOfTrue = this.operators.length;
  24365. this.parseBlock();
  24366. this.expect(PostScriptTokenTypes.RBRACE);
  24367. this.expect(PostScriptTokenTypes.IFELSE);
  24368. // The jump is added at the end of the true block to skip the false
  24369. // block.
  24370. this.operators[jumpLocation] = this.operators.length;
  24371. this.operators[jumpLocation + 1] = 'j';
  24372. this.operators[conditionLocation] = endOfTrue;
  24373. this.operators[conditionLocation + 1] = 'jz';
  24374. } else {
  24375. error('PS Function: error parsing conditional.');
  24376. }
  24377. }
  24378. };
  24379. return PostScriptParser;
  24380. })();
  24381. var PostScriptTokenTypes = {
  24382. LBRACE: 0,
  24383. RBRACE: 1,
  24384. NUMBER: 2,
  24385. OPERATOR: 3,
  24386. IF: 4,
  24387. IFELSE: 5
  24388. };
  24389. var PostScriptToken = (function PostScriptTokenClosure() {
  24390. function PostScriptToken(type, value) {
  24391. this.type = type;
  24392. this.value = value;
  24393. }
  24394. var opCache = Object.create(null);
  24395. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  24396. var opValue = opCache[op];
  24397. if (opValue) {
  24398. return opValue;
  24399. }
  24400. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  24401. };
  24402. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  24403. '{');
  24404. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  24405. '}');
  24406. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  24407. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  24408. 'IFELSE');
  24409. return PostScriptToken;
  24410. })();
  24411. var PostScriptLexer = (function PostScriptLexerClosure() {
  24412. function PostScriptLexer(stream) {
  24413. this.stream = stream;
  24414. this.nextChar();
  24415. this.strBuf = [];
  24416. }
  24417. PostScriptLexer.prototype = {
  24418. nextChar: function PostScriptLexer_nextChar() {
  24419. return (this.currentChar = this.stream.getByte());
  24420. },
  24421. getToken: function PostScriptLexer_getToken() {
  24422. var comment = false;
  24423. var ch = this.currentChar;
  24424. // skip comments
  24425. while (true) {
  24426. if (ch < 0) {
  24427. return EOF;
  24428. }
  24429. if (comment) {
  24430. if (ch === 0x0A || ch === 0x0D) {
  24431. comment = false;
  24432. }
  24433. } else if (ch === 0x25) { // '%'
  24434. comment = true;
  24435. } else if (!Lexer.isSpace(ch)) {
  24436. break;
  24437. }
  24438. ch = this.nextChar();
  24439. }
  24440. switch (ch | 0) {
  24441. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  24442. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  24443. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  24444. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  24445. this.getNumber());
  24446. case 0x7B: // '{'
  24447. this.nextChar();
  24448. return PostScriptToken.LBRACE;
  24449. case 0x7D: // '}'
  24450. this.nextChar();
  24451. return PostScriptToken.RBRACE;
  24452. }
  24453. // operator
  24454. var strBuf = this.strBuf;
  24455. strBuf.length = 0;
  24456. strBuf[0] = String.fromCharCode(ch);
  24457. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  24458. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  24459. strBuf.push(String.fromCharCode(ch));
  24460. }
  24461. var str = strBuf.join('');
  24462. switch (str.toLowerCase()) {
  24463. case 'if':
  24464. return PostScriptToken.IF;
  24465. case 'ifelse':
  24466. return PostScriptToken.IFELSE;
  24467. default:
  24468. return PostScriptToken.getOperator(str);
  24469. }
  24470. },
  24471. getNumber: function PostScriptLexer_getNumber() {
  24472. var ch = this.currentChar;
  24473. var strBuf = this.strBuf;
  24474. strBuf.length = 0;
  24475. strBuf[0] = String.fromCharCode(ch);
  24476. while ((ch = this.nextChar()) >= 0) {
  24477. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  24478. ch === 0x2D || ch === 0x2E) { // '-', '.'
  24479. strBuf.push(String.fromCharCode(ch));
  24480. } else {
  24481. break;
  24482. }
  24483. }
  24484. var value = parseFloat(strBuf.join(''));
  24485. if (isNaN(value)) {
  24486. error('Invalid floating point number: ' + value);
  24487. }
  24488. return value;
  24489. }
  24490. };
  24491. return PostScriptLexer;
  24492. })();
  24493. exports.PostScriptLexer = PostScriptLexer;
  24494. exports.PostScriptParser = PostScriptParser;
  24495. }));
  24496. (function (root, factory) {
  24497. {
  24498. factory((root.pdfjsCoreFonts = {}), root.pdfjsSharedUtil,
  24499. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  24500. root.pdfjsCoreCMap, root.pdfjsCoreGlyphList, root.pdfjsCoreCharsets,
  24501. root.pdfjsCoreFontRenderer, root.pdfjsCoreEncodings,
  24502. root.pdfjsCoreStandardFonts, root.pdfjsCoreUnicode);
  24503. }
  24504. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  24505. coreCMap, coreGlyphList, coreCharsets, coreFontRenderer,
  24506. coreEncodings, coreStandardFonts, coreUnicode) {
  24507. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  24508. var FontType = sharedUtil.FontType;
  24509. var Util = sharedUtil.Util;
  24510. var assert = sharedUtil.assert;
  24511. var bytesToString = sharedUtil.bytesToString;
  24512. var error = sharedUtil.error;
  24513. var info = sharedUtil.info;
  24514. var isArray = sharedUtil.isArray;
  24515. var isInt = sharedUtil.isInt;
  24516. var isNum = sharedUtil.isNum;
  24517. var readUint32 = sharedUtil.readUint32;
  24518. var shadow = sharedUtil.shadow;
  24519. var stringToBytes = sharedUtil.stringToBytes;
  24520. var string32 = sharedUtil.string32;
  24521. var warn = sharedUtil.warn;
  24522. var Name = corePrimitives.Name;
  24523. var Stream = coreStream.Stream;
  24524. var Lexer = coreParser.Lexer;
  24525. var CMapFactory = coreCMap.CMapFactory;
  24526. var IdentityCMap = coreCMap.IdentityCMap;
  24527. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  24528. var getDingbatsGlyphsUnicode = coreGlyphList.getDingbatsGlyphsUnicode;
  24529. var ISOAdobeCharset = coreCharsets.ISOAdobeCharset;
  24530. var ExpertCharset = coreCharsets.ExpertCharset;
  24531. var ExpertSubsetCharset = coreCharsets.ExpertSubsetCharset;
  24532. var FontRendererFactory = coreFontRenderer.FontRendererFactory;
  24533. var WinAnsiEncoding = coreEncodings.WinAnsiEncoding;
  24534. var StandardEncoding = coreEncodings.StandardEncoding;
  24535. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  24536. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  24537. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  24538. var ExpertEncoding = coreEncodings.ExpertEncoding;
  24539. var getEncoding = coreEncodings.getEncoding;
  24540. var getStdFontMap = coreStandardFonts.getStdFontMap;
  24541. var getNonStdFontMap = coreStandardFonts.getNonStdFontMap;
  24542. var getGlyphMapForStandardFonts = coreStandardFonts.getGlyphMapForStandardFonts;
  24543. var getSupplementalGlyphMapForArialBlack =
  24544. coreStandardFonts.getSupplementalGlyphMapForArialBlack;
  24545. var getUnicodeRangeFor = coreUnicode.getUnicodeRangeFor;
  24546. var mapSpecialUnicodeValues = coreUnicode.mapSpecialUnicodeValues;
  24547. // Unicode Private Use Area
  24548. var PRIVATE_USE_OFFSET_START = 0xE000;
  24549. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  24550. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  24551. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  24552. // except for Type 3 fonts
  24553. var PDF_GLYPH_SPACE_UNITS = 1000;
  24554. // Hinting is currently disabled due to unknown problems on windows
  24555. // in tracemonkey and various other pdfs with type1 fonts.
  24556. var HINTING_ENABLED = false;
  24557. // Accented charactars are not displayed properly on windows, using this flag
  24558. // to control analysis of seac charstrings.
  24559. var SEAC_ANALYSIS_ENABLED = false;
  24560. // Maximum subroutine call depth of type 2 chartrings. Matches OTS.
  24561. var MAX_SUBR_NESTING = 10;
  24562. var FontFlags = {
  24563. FixedPitch: 1,
  24564. Serif: 2,
  24565. Symbolic: 4,
  24566. Script: 8,
  24567. Nonsymbolic: 32,
  24568. Italic: 64,
  24569. AllCap: 65536,
  24570. SmallCap: 131072,
  24571. ForceBold: 262144
  24572. };
  24573. var MacStandardGlyphOrdering = [
  24574. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  24575. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  24576. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  24577. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  24578. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  24579. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  24580. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  24581. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  24582. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  24583. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  24584. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  24585. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  24586. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  24587. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  24588. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  24589. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  24590. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  24591. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  24592. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  24593. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  24594. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  24595. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  24596. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  24597. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  24598. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  24599. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  24600. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  24601. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  24602. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  24603. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  24604. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  24605. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  24606. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  24607. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  24608. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  24609. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  24610. function adjustWidths(properties) {
  24611. if (!properties.fontMatrix) {
  24612. return;
  24613. }
  24614. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  24615. return;
  24616. }
  24617. // adjusting width to fontMatrix scale
  24618. var scale = 0.001 / properties.fontMatrix[0];
  24619. var glyphsWidths = properties.widths;
  24620. for (var glyph in glyphsWidths) {
  24621. glyphsWidths[glyph] *= scale;
  24622. }
  24623. properties.defaultWidth *= scale;
  24624. }
  24625. function getFontType(type, subtype) {
  24626. switch (type) {
  24627. case 'Type1':
  24628. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  24629. case 'CIDFontType0':
  24630. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  24631. FontType.CIDFONTTYPE0;
  24632. case 'OpenType':
  24633. return FontType.OPENTYPE;
  24634. case 'TrueType':
  24635. return FontType.TRUETYPE;
  24636. case 'CIDFontType2':
  24637. return FontType.CIDFONTTYPE2;
  24638. case 'MMType1':
  24639. return FontType.MMTYPE1;
  24640. case 'Type0':
  24641. return FontType.TYPE0;
  24642. default:
  24643. return FontType.UNKNOWN;
  24644. }
  24645. }
  24646. var Glyph = (function GlyphClosure() {
  24647. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId,
  24648. isSpace, isInFont) {
  24649. this.fontChar = fontChar;
  24650. this.unicode = unicode;
  24651. this.accent = accent;
  24652. this.width = width;
  24653. this.vmetric = vmetric;
  24654. this.operatorListId = operatorListId;
  24655. this.isSpace = isSpace;
  24656. this.isInFont = isInFont;
  24657. }
  24658. Glyph.prototype.matchesForCache = function(fontChar, unicode, accent, width,
  24659. vmetric, operatorListId, isSpace,
  24660. isInFont) {
  24661. return this.fontChar === fontChar &&
  24662. this.unicode === unicode &&
  24663. this.accent === accent &&
  24664. this.width === width &&
  24665. this.vmetric === vmetric &&
  24666. this.operatorListId === operatorListId &&
  24667. this.isSpace === isSpace &&
  24668. this.isInFont === isInFont;
  24669. };
  24670. return Glyph;
  24671. })();
  24672. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  24673. function ToUnicodeMap(cmap) {
  24674. // The elements of this._map can be integers or strings, depending on how
  24675. // |cmap| was created.
  24676. this._map = cmap;
  24677. }
  24678. ToUnicodeMap.prototype = {
  24679. get length() {
  24680. return this._map.length;
  24681. },
  24682. forEach: function(callback) {
  24683. for (var charCode in this._map) {
  24684. callback(charCode, this._map[charCode].charCodeAt(0));
  24685. }
  24686. },
  24687. has: function(i) {
  24688. return this._map[i] !== undefined;
  24689. },
  24690. get: function(i) {
  24691. return this._map[i];
  24692. },
  24693. charCodeOf: function(v) {
  24694. return this._map.indexOf(v);
  24695. }
  24696. };
  24697. return ToUnicodeMap;
  24698. })();
  24699. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  24700. function IdentityToUnicodeMap(firstChar, lastChar) {
  24701. this.firstChar = firstChar;
  24702. this.lastChar = lastChar;
  24703. }
  24704. IdentityToUnicodeMap.prototype = {
  24705. get length() {
  24706. return (this.lastChar + 1) - this.firstChar;
  24707. },
  24708. forEach: function (callback) {
  24709. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  24710. callback(i, i);
  24711. }
  24712. },
  24713. has: function (i) {
  24714. return this.firstChar <= i && i <= this.lastChar;
  24715. },
  24716. get: function (i) {
  24717. if (this.firstChar <= i && i <= this.lastChar) {
  24718. return String.fromCharCode(i);
  24719. }
  24720. return undefined;
  24721. },
  24722. charCodeOf: function (v) {
  24723. return (isInt(v) && v >= this.firstChar && v <= this.lastChar) ? v : -1;
  24724. }
  24725. };
  24726. return IdentityToUnicodeMap;
  24727. })();
  24728. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  24729. function writeInt16(dest, offset, num) {
  24730. dest[offset] = (num >> 8) & 0xFF;
  24731. dest[offset + 1] = num & 0xFF;
  24732. }
  24733. function writeInt32(dest, offset, num) {
  24734. dest[offset] = (num >> 24) & 0xFF;
  24735. dest[offset + 1] = (num >> 16) & 0xFF;
  24736. dest[offset + 2] = (num >> 8) & 0xFF;
  24737. dest[offset + 3] = num & 0xFF;
  24738. }
  24739. function writeData(dest, offset, data) {
  24740. var i, ii;
  24741. if (data instanceof Uint8Array) {
  24742. dest.set(data, offset);
  24743. } else if (typeof data === 'string') {
  24744. for (i = 0, ii = data.length; i < ii; i++) {
  24745. dest[offset++] = data.charCodeAt(i) & 0xFF;
  24746. }
  24747. } else {
  24748. // treating everything else as array
  24749. for (i = 0, ii = data.length; i < ii; i++) {
  24750. dest[offset++] = data[i] & 0xFF;
  24751. }
  24752. }
  24753. }
  24754. function OpenTypeFileBuilder(sfnt) {
  24755. this.sfnt = sfnt;
  24756. this.tables = Object.create(null);
  24757. }
  24758. OpenTypeFileBuilder.getSearchParams =
  24759. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  24760. var maxPower2 = 1, log2 = 0;
  24761. while ((maxPower2 ^ entriesCount) > maxPower2) {
  24762. maxPower2 <<= 1;
  24763. log2++;
  24764. }
  24765. var searchRange = maxPower2 * entrySize;
  24766. return {
  24767. range: searchRange,
  24768. entry: log2,
  24769. rangeShift: entrySize * entriesCount - searchRange
  24770. };
  24771. };
  24772. var OTF_HEADER_SIZE = 12;
  24773. var OTF_TABLE_ENTRY_SIZE = 16;
  24774. OpenTypeFileBuilder.prototype = {
  24775. toArray: function OpenTypeFileBuilder_toArray() {
  24776. var sfnt = this.sfnt;
  24777. // Tables needs to be written by ascendant alphabetic order
  24778. var tables = this.tables;
  24779. var tablesNames = Object.keys(tables);
  24780. tablesNames.sort();
  24781. var numTables = tablesNames.length;
  24782. var i, j, jj, table, tableName;
  24783. // layout the tables data
  24784. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  24785. var tableOffsets = [offset];
  24786. for (i = 0; i < numTables; i++) {
  24787. table = tables[tablesNames[i]];
  24788. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  24789. offset += paddedLength;
  24790. tableOffsets.push(offset);
  24791. }
  24792. var file = new Uint8Array(offset);
  24793. // write the table data first (mostly for checksum)
  24794. for (i = 0; i < numTables; i++) {
  24795. table = tables[tablesNames[i]];
  24796. writeData(file, tableOffsets[i], table);
  24797. }
  24798. // sfnt version (4 bytes)
  24799. if (sfnt === 'true') {
  24800. // Windows hates the Mac TrueType sfnt version number
  24801. sfnt = string32(0x00010000);
  24802. }
  24803. file[0] = sfnt.charCodeAt(0) & 0xFF;
  24804. file[1] = sfnt.charCodeAt(1) & 0xFF;
  24805. file[2] = sfnt.charCodeAt(2) & 0xFF;
  24806. file[3] = sfnt.charCodeAt(3) & 0xFF;
  24807. // numTables (2 bytes)
  24808. writeInt16(file, 4, numTables);
  24809. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  24810. // searchRange (2 bytes)
  24811. writeInt16(file, 6, searchParams.range);
  24812. // entrySelector (2 bytes)
  24813. writeInt16(file, 8, searchParams.entry);
  24814. // rangeShift (2 bytes)
  24815. writeInt16(file, 10, searchParams.rangeShift);
  24816. offset = OTF_HEADER_SIZE;
  24817. // writing table entries
  24818. for (i = 0; i < numTables; i++) {
  24819. tableName = tablesNames[i];
  24820. file[offset] = tableName.charCodeAt(0) & 0xFF;
  24821. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  24822. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  24823. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  24824. // checksum
  24825. var checksum = 0;
  24826. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  24827. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  24828. (file[j + 2] << 8) + file[j + 3];
  24829. checksum = (checksum + quad) | 0;
  24830. }
  24831. writeInt32(file, offset + 4, checksum);
  24832. // offset
  24833. writeInt32(file, offset + 8, tableOffsets[i]);
  24834. // length
  24835. writeInt32(file, offset + 12, tables[tableName].length);
  24836. offset += OTF_TABLE_ENTRY_SIZE;
  24837. }
  24838. return file;
  24839. },
  24840. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  24841. if (tag in this.tables) {
  24842. throw new Error('Table ' + tag + ' already exists');
  24843. }
  24844. this.tables[tag] = data;
  24845. }
  24846. };
  24847. return OpenTypeFileBuilder;
  24848. })();
  24849. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  24850. // issues when they are painted on the canvas, e.g. complex-script shaping or
  24851. // control/whitespace characters. The ranges are listed in pairs: the first item
  24852. // is a code of the first problematic code, the second one is the next
  24853. // non-problematic code. The ranges must be in sorted order.
  24854. var ProblematicCharRanges = new Int32Array([
  24855. // Control characters.
  24856. 0x0000, 0x0020,
  24857. 0x007F, 0x00A1,
  24858. 0x00AD, 0x00AE,
  24859. // Chars that is used in complex-script shaping.
  24860. 0x0600, 0x0780,
  24861. 0x08A0, 0x10A0,
  24862. 0x1780, 0x1800,
  24863. // General punctuation chars.
  24864. 0x2000, 0x2010,
  24865. 0x2011, 0x2012,
  24866. 0x2028, 0x2030,
  24867. 0x205F, 0x2070,
  24868. 0x25CC, 0x25CD,
  24869. // Chars that is used in complex-script shaping.
  24870. 0xAA60, 0xAA80,
  24871. // Specials Unicode block.
  24872. 0xFFF0, 0x10000
  24873. ]);
  24874. /**
  24875. * 'Font' is the class the outside world should use, it encapsulate all the font
  24876. * decoding logics whatever type it is (assuming the font type is supported).
  24877. *
  24878. * For example to read a Type1 font and to attach it to the document:
  24879. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  24880. * type1Font.bind();
  24881. */
  24882. var Font = (function FontClosure() {
  24883. function Font(name, file, properties) {
  24884. var charCode, glyphName, fontChar;
  24885. this.name = name;
  24886. this.loadedName = properties.loadedName;
  24887. this.isType3Font = properties.isType3Font;
  24888. this.sizes = [];
  24889. this.missingFile = false;
  24890. this.glyphCache = Object.create(null);
  24891. var names = name.split('+');
  24892. names = names.length > 1 ? names[1] : names[0];
  24893. names = names.split(/[-,_]/g)[0];
  24894. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  24895. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  24896. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  24897. var type = properties.type;
  24898. var subtype = properties.subtype;
  24899. this.type = type;
  24900. this.fallbackName = (this.isMonospace ? 'monospace' :
  24901. (this.isSerifFont ? 'serif' : 'sans-serif'));
  24902. this.differences = properties.differences;
  24903. this.widths = properties.widths;
  24904. this.defaultWidth = properties.defaultWidth;
  24905. this.composite = properties.composite;
  24906. this.wideChars = properties.wideChars;
  24907. this.cMap = properties.cMap;
  24908. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  24909. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  24910. this.fontMatrix = properties.fontMatrix;
  24911. this.bbox = properties.bbox;
  24912. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  24913. this.toFontChar = [];
  24914. if (properties.type === 'Type3') {
  24915. for (charCode = 0; charCode < 256; charCode++) {
  24916. this.toFontChar[charCode] = (this.differences[charCode] ||
  24917. properties.defaultEncoding[charCode]);
  24918. }
  24919. this.fontType = FontType.TYPE3;
  24920. return;
  24921. }
  24922. this.cidEncoding = properties.cidEncoding;
  24923. this.vertical = properties.vertical;
  24924. if (this.vertical) {
  24925. this.vmetrics = properties.vmetrics;
  24926. this.defaultVMetrics = properties.defaultVMetrics;
  24927. }
  24928. var glyphsUnicodeMap;
  24929. if (!file || file.isEmpty) {
  24930. if (file) {
  24931. // Some bad PDF generators will include empty font files,
  24932. // attempting to recover by assuming that no file exists.
  24933. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  24934. }
  24935. this.missingFile = true;
  24936. // The file data is not specified. Trying to fix the font name
  24937. // to be used with the canvas.font.
  24938. var fontName = name.replace(/[,_]/g, '-');
  24939. var stdFontMap = getStdFontMap(), nonStdFontMap = getNonStdFontMap();
  24940. var isStandardFont = !!stdFontMap[fontName] ||
  24941. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  24942. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  24943. this.bold = (fontName.search(/bold/gi) !== -1);
  24944. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  24945. (fontName.search(/italic/gi) !== -1));
  24946. // Use 'name' instead of 'fontName' here because the original
  24947. // name ArialBlack for example will be replaced by Helvetica.
  24948. this.black = (name.search(/Black/g) !== -1);
  24949. // if at least one width is present, remeasure all chars when exists
  24950. this.remeasure = Object.keys(this.widths).length > 0;
  24951. if (isStandardFont && type === 'CIDFontType2' &&
  24952. properties.cidEncoding.indexOf('Identity-') === 0) {
  24953. var GlyphMapForStandardFonts = getGlyphMapForStandardFonts();
  24954. // Standard fonts might be embedded as CID font without glyph mapping.
  24955. // Building one based on GlyphMapForStandardFonts.
  24956. var map = [];
  24957. for (charCode in GlyphMapForStandardFonts) {
  24958. map[+charCode] = GlyphMapForStandardFonts[charCode];
  24959. }
  24960. if (/ArialBlack/i.test(name)) {
  24961. var SupplementalGlyphMapForArialBlack =
  24962. getSupplementalGlyphMapForArialBlack();
  24963. for (charCode in SupplementalGlyphMapForArialBlack) {
  24964. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  24965. }
  24966. }
  24967. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  24968. if (!isIdentityUnicode) {
  24969. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  24970. map[+charCode] = unicodeCharCode;
  24971. });
  24972. }
  24973. this.toFontChar = map;
  24974. this.toUnicode = new ToUnicodeMap(map);
  24975. } else if (/Symbol/i.test(fontName)) {
  24976. var symbols = SymbolSetEncoding;
  24977. glyphsUnicodeMap = getGlyphsUnicode();
  24978. for (charCode in symbols) {
  24979. fontChar = glyphsUnicodeMap[symbols[charCode]];
  24980. if (!fontChar) {
  24981. continue;
  24982. }
  24983. this.toFontChar[charCode] = fontChar;
  24984. }
  24985. for (charCode in properties.differences) {
  24986. fontChar = glyphsUnicodeMap[properties.differences[charCode]];
  24987. if (!fontChar) {
  24988. continue;
  24989. }
  24990. this.toFontChar[charCode] = fontChar;
  24991. }
  24992. } else if (/Dingbats/i.test(fontName)) {
  24993. glyphsUnicodeMap = getDingbatsGlyphsUnicode();
  24994. if (/Wingdings/i.test(name)) {
  24995. warn('Wingdings font without embedded font file, ' +
  24996. 'falling back to the ZapfDingbats encoding.');
  24997. }
  24998. var dingbats = ZapfDingbatsEncoding;
  24999. for (charCode in dingbats) {
  25000. fontChar = glyphsUnicodeMap[dingbats[charCode]];
  25001. if (!fontChar) {
  25002. continue;
  25003. }
  25004. this.toFontChar[charCode] = fontChar;
  25005. }
  25006. for (charCode in properties.differences) {
  25007. fontChar = glyphsUnicodeMap[properties.differences[charCode]];
  25008. if (!fontChar) {
  25009. continue;
  25010. }
  25011. this.toFontChar[charCode] = fontChar;
  25012. }
  25013. } else if (isStandardFont) {
  25014. this.toFontChar = [];
  25015. glyphsUnicodeMap = getGlyphsUnicode();
  25016. for (charCode in properties.defaultEncoding) {
  25017. glyphName = (properties.differences[charCode] ||
  25018. properties.defaultEncoding[charCode]);
  25019. this.toFontChar[charCode] = glyphsUnicodeMap[glyphName];
  25020. }
  25021. } else {
  25022. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  25023. glyphsUnicodeMap = getGlyphsUnicode();
  25024. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  25025. if (notCidFont) {
  25026. glyphName = (properties.differences[charCode] ||
  25027. properties.defaultEncoding[charCode]);
  25028. unicodeCharCode = (glyphsUnicodeMap[glyphName] || unicodeCharCode);
  25029. }
  25030. this.toFontChar[charCode] = unicodeCharCode;
  25031. }.bind(this));
  25032. }
  25033. this.loadedName = fontName.split('-')[0];
  25034. this.loading = false;
  25035. this.fontType = getFontType(type, subtype);
  25036. return;
  25037. }
  25038. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  25039. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  25040. // Some TrueType fonts by mistake claim Type1C
  25041. if (isTrueTypeFile(file)) {
  25042. subtype = 'TrueType';
  25043. } else {
  25044. type = 'Type1';
  25045. }
  25046. }
  25047. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  25048. type = 'CIDFontType0';
  25049. }
  25050. if (subtype === 'OpenType') {
  25051. type = 'OpenType';
  25052. }
  25053. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  25054. if (type === 'CIDFontType0') {
  25055. if (isType1File(file)) {
  25056. subtype = 'CIDFontType0';
  25057. } else if (isOpenTypeFile(file)) {
  25058. // Sometimes the type/subtype can be a complete lie (see issue6782.pdf).
  25059. type = subtype = 'OpenType';
  25060. } else {
  25061. subtype = 'CIDFontType0C';
  25062. }
  25063. }
  25064. var data;
  25065. switch (type) {
  25066. case 'MMType1':
  25067. info('MMType1 font (' + name + '), falling back to Type1.');
  25068. /* falls through */
  25069. case 'Type1':
  25070. case 'CIDFontType0':
  25071. this.mimetype = 'font/opentype';
  25072. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  25073. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  25074. adjustWidths(properties);
  25075. // Wrap the CFF data inside an OTF font file
  25076. data = this.convert(name, cff, properties);
  25077. break;
  25078. case 'OpenType':
  25079. case 'TrueType':
  25080. case 'CIDFontType2':
  25081. this.mimetype = 'font/opentype';
  25082. // Repair the TrueType file. It is can be damaged in the point of
  25083. // view of the sanitizer
  25084. data = this.checkAndRepair(name, file, properties);
  25085. if (this.isOpenType) {
  25086. adjustWidths(properties);
  25087. type = 'OpenType';
  25088. }
  25089. break;
  25090. default:
  25091. error('Font ' + type + ' is not supported');
  25092. break;
  25093. }
  25094. this.data = data;
  25095. this.fontType = getFontType(type, subtype);
  25096. // Transfer some properties again that could change during font conversion
  25097. this.fontMatrix = properties.fontMatrix;
  25098. this.widths = properties.widths;
  25099. this.defaultWidth = properties.defaultWidth;
  25100. this.encoding = properties.baseEncoding;
  25101. this.seacMap = properties.seacMap;
  25102. this.loading = true;
  25103. }
  25104. Font.getFontID = (function () {
  25105. var ID = 1;
  25106. return function Font_getFontID() {
  25107. return String(ID++);
  25108. };
  25109. })();
  25110. function int16(b0, b1) {
  25111. return (b0 << 8) + b1;
  25112. }
  25113. function int32(b0, b1, b2, b3) {
  25114. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  25115. }
  25116. function string16(value) {
  25117. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  25118. }
  25119. function safeString16(value) {
  25120. // clamp value to the 16-bit int range
  25121. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  25122. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  25123. }
  25124. function isTrueTypeFile(file) {
  25125. var header = file.peekBytes(4);
  25126. return readUint32(header, 0) === 0x00010000;
  25127. }
  25128. function isOpenTypeFile(file) {
  25129. var header = file.peekBytes(4);
  25130. return bytesToString(header) === 'OTTO';
  25131. }
  25132. function isType1File(file) {
  25133. var header = file.peekBytes(2);
  25134. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  25135. if (header[0] === 0x25 && header[1] === 0x21) {
  25136. return true;
  25137. }
  25138. // ... obviously some fonts violate that part of the specification,
  25139. // please refer to the comment in |Type1Font| below.
  25140. if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
  25141. return true;
  25142. }
  25143. return false;
  25144. }
  25145. /**
  25146. * Helper function for |adjustMapping|.
  25147. * @return {boolean}
  25148. */
  25149. function isProblematicUnicodeLocation(code) {
  25150. // Using binary search to find a range start.
  25151. var i = 0, j = ProblematicCharRanges.length - 1;
  25152. while (i < j) {
  25153. var c = (i + j + 1) >> 1;
  25154. if (code < ProblematicCharRanges[c]) {
  25155. j = c - 1;
  25156. } else {
  25157. i = c;
  25158. }
  25159. }
  25160. // Even index means code in problematic range.
  25161. return !(i & 1);
  25162. }
  25163. /**
  25164. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  25165. * with their unicode value. It also moves char codes that are in known
  25166. * problematic locations.
  25167. * @return {Object} Two properties:
  25168. * 'toFontChar' - maps original char codes(the value that will be read
  25169. * from commands such as show text) to the char codes that will be used in the
  25170. * font that we build
  25171. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  25172. */
  25173. function adjustMapping(charCodeToGlyphId, properties) {
  25174. var toUnicode = properties.toUnicode;
  25175. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  25176. var isIdentityUnicode =
  25177. properties.toUnicode instanceof IdentityToUnicodeMap;
  25178. var newMap = Object.create(null);
  25179. var toFontChar = [];
  25180. var usedFontCharCodes = [];
  25181. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  25182. for (var originalCharCode in charCodeToGlyphId) {
  25183. originalCharCode |= 0;
  25184. var glyphId = charCodeToGlyphId[originalCharCode];
  25185. var fontCharCode = originalCharCode;
  25186. // First try to map the value to a unicode position if a non identity map
  25187. // was created.
  25188. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  25189. var unicode = toUnicode.get(fontCharCode);
  25190. // TODO: Try to map ligatures to the correct spot.
  25191. if (unicode.length === 1) {
  25192. fontCharCode = unicode.charCodeAt(0);
  25193. }
  25194. }
  25195. // Try to move control characters, special characters and already mapped
  25196. // characters to the private use area since they will not be drawn by
  25197. // canvas if left in their current position. Also, move characters if the
  25198. // font was symbolic and there is only an identity unicode map since the
  25199. // characters probably aren't in the correct position (fixes an issue
  25200. // with firefox and thuluthfont).
  25201. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  25202. isProblematicUnicodeLocation(fontCharCode) ||
  25203. (isSymbolic && isIdentityUnicode)) &&
  25204. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  25205. // Loop to try and find a free spot in the private use area.
  25206. do {
  25207. fontCharCode = nextAvailableFontCharCode++;
  25208. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  25209. fontCharCode = 0xF020;
  25210. nextAvailableFontCharCode = fontCharCode + 1;
  25211. }
  25212. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  25213. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  25214. }
  25215. newMap[fontCharCode] = glyphId;
  25216. toFontChar[originalCharCode] = fontCharCode;
  25217. usedFontCharCodes[fontCharCode] = true;
  25218. }
  25219. return {
  25220. toFontChar: toFontChar,
  25221. charCodeToGlyphId: newMap,
  25222. nextAvailableFontCharCode: nextAvailableFontCharCode
  25223. };
  25224. }
  25225. function getRanges(glyphs, numGlyphs) {
  25226. // Array.sort() sorts by characters, not numerically, so convert to an
  25227. // array of characters.
  25228. var codes = [];
  25229. for (var charCode in glyphs) {
  25230. // Remove an invalid glyph ID mappings to make OTS happy.
  25231. if (glyphs[charCode] >= numGlyphs) {
  25232. continue;
  25233. }
  25234. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  25235. }
  25236. codes.sort(function fontGetRangesSort(a, b) {
  25237. return a.fontCharCode - b.fontCharCode;
  25238. });
  25239. // Split the sorted codes into ranges.
  25240. var ranges = [];
  25241. var length = codes.length;
  25242. for (var n = 0; n < length; ) {
  25243. var start = codes[n].fontCharCode;
  25244. var codeIndices = [codes[n].glyphId];
  25245. ++n;
  25246. var end = start;
  25247. while (n < length && end + 1 === codes[n].fontCharCode) {
  25248. codeIndices.push(codes[n].glyphId);
  25249. ++end;
  25250. ++n;
  25251. if (end === 0xFFFF) {
  25252. break;
  25253. }
  25254. }
  25255. ranges.push([start, end, codeIndices]);
  25256. }
  25257. return ranges;
  25258. }
  25259. function createCmapTable(glyphs, numGlyphs) {
  25260. var ranges = getRanges(glyphs, numGlyphs);
  25261. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  25262. var cmap = '\x00\x00' + // version
  25263. string16(numTables) + // numTables
  25264. '\x00\x03' + // platformID
  25265. '\x00\x01' + // encodingID
  25266. string32(4 + numTables * 8); // start of the table record
  25267. var i, ii, j, jj;
  25268. for (i = ranges.length - 1; i >= 0; --i) {
  25269. if (ranges[i][0] <= 0xFFFF) { break; }
  25270. }
  25271. var bmpLength = i + 1;
  25272. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  25273. ranges[i][1] = 0xFFFE;
  25274. }
  25275. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  25276. var segCount = bmpLength + trailingRangesCount;
  25277. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  25278. // Fill up the 4 parallel arrays describing the segments.
  25279. var startCount = '';
  25280. var endCount = '';
  25281. var idDeltas = '';
  25282. var idRangeOffsets = '';
  25283. var glyphsIds = '';
  25284. var bias = 0;
  25285. var range, start, end, codes;
  25286. for (i = 0, ii = bmpLength; i < ii; i++) {
  25287. range = ranges[i];
  25288. start = range[0];
  25289. end = range[1];
  25290. startCount += string16(start);
  25291. endCount += string16(end);
  25292. codes = range[2];
  25293. var contiguous = true;
  25294. for (j = 1, jj = codes.length; j < jj; ++j) {
  25295. if (codes[j] !== codes[j - 1] + 1) {
  25296. contiguous = false;
  25297. break;
  25298. }
  25299. }
  25300. if (!contiguous) {
  25301. var offset = (segCount - i) * 2 + bias * 2;
  25302. bias += (end - start + 1);
  25303. idDeltas += string16(0);
  25304. idRangeOffsets += string16(offset);
  25305. for (j = 0, jj = codes.length; j < jj; ++j) {
  25306. glyphsIds += string16(codes[j]);
  25307. }
  25308. } else {
  25309. var startCode = codes[0];
  25310. idDeltas += string16((startCode - start) & 0xFFFF);
  25311. idRangeOffsets += string16(0);
  25312. }
  25313. }
  25314. if (trailingRangesCount > 0) {
  25315. endCount += '\xFF\xFF';
  25316. startCount += '\xFF\xFF';
  25317. idDeltas += '\x00\x01';
  25318. idRangeOffsets += '\x00\x00';
  25319. }
  25320. var format314 = '\x00\x00' + // language
  25321. string16(2 * segCount) +
  25322. string16(searchParams.range) +
  25323. string16(searchParams.entry) +
  25324. string16(searchParams.rangeShift) +
  25325. endCount + '\x00\x00' + startCount +
  25326. idDeltas + idRangeOffsets + glyphsIds;
  25327. var format31012 = '';
  25328. var header31012 = '';
  25329. if (numTables > 1) {
  25330. cmap += '\x00\x03' + // platformID
  25331. '\x00\x0A' + // encodingID
  25332. string32(4 + numTables * 8 +
  25333. 4 + format314.length); // start of the table record
  25334. format31012 = '';
  25335. for (i = 0, ii = ranges.length; i < ii; i++) {
  25336. range = ranges[i];
  25337. start = range[0];
  25338. codes = range[2];
  25339. var code = codes[0];
  25340. for (j = 1, jj = codes.length; j < jj; ++j) {
  25341. if (codes[j] !== codes[j - 1] + 1) {
  25342. end = range[0] + j - 1;
  25343. format31012 += string32(start) + // startCharCode
  25344. string32(end) + // endCharCode
  25345. string32(code); // startGlyphID
  25346. start = end + 1;
  25347. code = codes[j];
  25348. }
  25349. }
  25350. format31012 += string32(start) + // startCharCode
  25351. string32(range[1]) + // endCharCode
  25352. string32(code); // startGlyphID
  25353. }
  25354. header31012 = '\x00\x0C' + // format
  25355. '\x00\x00' + // reserved
  25356. string32(format31012.length + 16) + // length
  25357. '\x00\x00\x00\x00' + // language
  25358. string32(format31012.length / 12); // nGroups
  25359. }
  25360. return cmap + '\x00\x04' + // format
  25361. string16(format314.length + 4) + // length
  25362. format314 + header31012 + format31012;
  25363. }
  25364. function validateOS2Table(os2) {
  25365. var stream = new Stream(os2.data);
  25366. var version = stream.getUint16();
  25367. // TODO verify all OS/2 tables fields, but currently we validate only those
  25368. // that give us issues
  25369. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  25370. var selection = stream.getUint16();
  25371. if (version < 4 && (selection & 0x0300)) {
  25372. return false;
  25373. }
  25374. var firstChar = stream.getUint16();
  25375. var lastChar = stream.getUint16();
  25376. if (firstChar > lastChar) {
  25377. return false;
  25378. }
  25379. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  25380. var usWinAscent = stream.getUint16();
  25381. if (usWinAscent === 0) { // makes font unreadable by windows
  25382. return false;
  25383. }
  25384. // OS/2 appears to be valid, resetting some fields
  25385. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  25386. return true;
  25387. }
  25388. function createOS2Table(properties, charstrings, override) {
  25389. override = override || {
  25390. unitsPerEm: 0,
  25391. yMax: 0,
  25392. yMin: 0,
  25393. ascent: 0,
  25394. descent: 0
  25395. };
  25396. var ulUnicodeRange1 = 0;
  25397. var ulUnicodeRange2 = 0;
  25398. var ulUnicodeRange3 = 0;
  25399. var ulUnicodeRange4 = 0;
  25400. var firstCharIndex = null;
  25401. var lastCharIndex = 0;
  25402. if (charstrings) {
  25403. for (var code in charstrings) {
  25404. code |= 0;
  25405. if (firstCharIndex > code || !firstCharIndex) {
  25406. firstCharIndex = code;
  25407. }
  25408. if (lastCharIndex < code) {
  25409. lastCharIndex = code;
  25410. }
  25411. var position = getUnicodeRangeFor(code);
  25412. if (position < 32) {
  25413. ulUnicodeRange1 |= 1 << position;
  25414. } else if (position < 64) {
  25415. ulUnicodeRange2 |= 1 << position - 32;
  25416. } else if (position < 96) {
  25417. ulUnicodeRange3 |= 1 << position - 64;
  25418. } else if (position < 123) {
  25419. ulUnicodeRange4 |= 1 << position - 96;
  25420. } else {
  25421. error('Unicode ranges Bits > 123 are reserved for internal usage');
  25422. }
  25423. }
  25424. } else {
  25425. // TODO
  25426. firstCharIndex = 0;
  25427. lastCharIndex = 255;
  25428. }
  25429. var bbox = properties.bbox || [0, 0, 0, 0];
  25430. var unitsPerEm = (override.unitsPerEm ||
  25431. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  25432. // if the font units differ to the PDF glyph space units
  25433. // then scale up the values
  25434. var scale = (properties.ascentScaled ? 1.0 :
  25435. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  25436. var typoAscent = (override.ascent ||
  25437. Math.round(scale * (properties.ascent || bbox[3])));
  25438. var typoDescent = (override.descent ||
  25439. Math.round(scale * (properties.descent || bbox[1])));
  25440. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  25441. typoDescent = -typoDescent; // fixing incorrect descent
  25442. }
  25443. var winAscent = override.yMax || typoAscent;
  25444. var winDescent = -override.yMin || -typoDescent;
  25445. return '\x00\x03' + // version
  25446. '\x02\x24' + // xAvgCharWidth
  25447. '\x01\xF4' + // usWeightClass
  25448. '\x00\x05' + // usWidthClass
  25449. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  25450. '\x02\x8A' + // ySubscriptXSize
  25451. '\x02\xBB' + // ySubscriptYSize
  25452. '\x00\x00' + // ySubscriptXOffset
  25453. '\x00\x8C' + // ySubscriptYOffset
  25454. '\x02\x8A' + // ySuperScriptXSize
  25455. '\x02\xBB' + // ySuperScriptYSize
  25456. '\x00\x00' + // ySuperScriptXOffset
  25457. '\x01\xDF' + // ySuperScriptYOffset
  25458. '\x00\x31' + // yStrikeOutSize
  25459. '\x01\x02' + // yStrikeOutPosition
  25460. '\x00\x00' + // sFamilyClass
  25461. '\x00\x00\x06' +
  25462. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  25463. '\x00\x00\x00\x00\x00\x00' + // Panose
  25464. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  25465. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  25466. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  25467. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  25468. '\x2A\x32\x31\x2A' + // achVendID
  25469. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  25470. string16(firstCharIndex ||
  25471. properties.firstChar) + // usFirstCharIndex
  25472. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  25473. string16(typoAscent) + // sTypoAscender
  25474. string16(typoDescent) + // sTypoDescender
  25475. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  25476. string16(winAscent) + // usWinAscent
  25477. string16(winDescent) + // usWinDescent
  25478. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  25479. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  25480. string16(properties.xHeight) + // sxHeight
  25481. string16(properties.capHeight) + // sCapHeight
  25482. string16(0) + // usDefaultChar
  25483. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  25484. '\x00\x03'; // usMaxContext
  25485. }
  25486. function createPostTable(properties) {
  25487. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  25488. return ('\x00\x03\x00\x00' + // Version number
  25489. string32(angle) + // italicAngle
  25490. '\x00\x00' + // underlinePosition
  25491. '\x00\x00' + // underlineThickness
  25492. string32(properties.fixedPitch) + // isFixedPitch
  25493. '\x00\x00\x00\x00' + // minMemType42
  25494. '\x00\x00\x00\x00' + // maxMemType42
  25495. '\x00\x00\x00\x00' + // minMemType1
  25496. '\x00\x00\x00\x00'); // maxMemType1
  25497. }
  25498. function createNameTable(name, proto) {
  25499. if (!proto) {
  25500. proto = [[], []]; // no strings and unicode strings
  25501. }
  25502. var strings = [
  25503. proto[0][0] || 'Original licence', // 0.Copyright
  25504. proto[0][1] || name, // 1.Font family
  25505. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  25506. proto[0][3] || 'uniqueID', // 3.Unique ID
  25507. proto[0][4] || name, // 4.Full font name
  25508. proto[0][5] || 'Version 0.11', // 5.Version
  25509. proto[0][6] || '', // 6.Postscript name
  25510. proto[0][7] || 'Unknown', // 7.Trademark
  25511. proto[0][8] || 'Unknown', // 8.Manufacturer
  25512. proto[0][9] || 'Unknown' // 9.Designer
  25513. ];
  25514. // Mac want 1-byte per character strings while Windows want
  25515. // 2-bytes per character, so duplicate the names table
  25516. var stringsUnicode = [];
  25517. var i, ii, j, jj, str;
  25518. for (i = 0, ii = strings.length; i < ii; i++) {
  25519. str = proto[1][i] || strings[i];
  25520. var strBufUnicode = [];
  25521. for (j = 0, jj = str.length; j < jj; j++) {
  25522. strBufUnicode.push(string16(str.charCodeAt(j)));
  25523. }
  25524. stringsUnicode.push(strBufUnicode.join(''));
  25525. }
  25526. var names = [strings, stringsUnicode];
  25527. var platforms = ['\x00\x01', '\x00\x03'];
  25528. var encodings = ['\x00\x00', '\x00\x01'];
  25529. var languages = ['\x00\x00', '\x04\x09'];
  25530. var namesRecordCount = strings.length * platforms.length;
  25531. var nameTable =
  25532. '\x00\x00' + // format
  25533. string16(namesRecordCount) + // Number of names Record
  25534. string16(namesRecordCount * 12 + 6); // Storage
  25535. // Build the name records field
  25536. var strOffset = 0;
  25537. for (i = 0, ii = platforms.length; i < ii; i++) {
  25538. var strs = names[i];
  25539. for (j = 0, jj = strs.length; j < jj; j++) {
  25540. str = strs[j];
  25541. var nameRecord =
  25542. platforms[i] + // platform ID
  25543. encodings[i] + // encoding ID
  25544. languages[i] + // language ID
  25545. string16(j) + // name ID
  25546. string16(str.length) +
  25547. string16(strOffset);
  25548. nameTable += nameRecord;
  25549. strOffset += str.length;
  25550. }
  25551. }
  25552. nameTable += strings.join('') + stringsUnicode.join('');
  25553. return nameTable;
  25554. }
  25555. Font.prototype = {
  25556. name: null,
  25557. font: null,
  25558. mimetype: null,
  25559. encoding: null,
  25560. get renderer() {
  25561. var renderer = FontRendererFactory.create(this);
  25562. return shadow(this, 'renderer', renderer);
  25563. },
  25564. exportData: function Font_exportData() {
  25565. // TODO remove enumerating of the properties, e.g. hardcode exact names.
  25566. var data = {};
  25567. for (var i in this) {
  25568. if (this.hasOwnProperty(i)) {
  25569. data[i] = this[i];
  25570. }
  25571. }
  25572. return data;
  25573. },
  25574. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  25575. function readTableEntry(file) {
  25576. var tag = bytesToString(file.getBytes(4));
  25577. var checksum = file.getInt32();
  25578. var offset = file.getInt32() >>> 0;
  25579. var length = file.getInt32() >>> 0;
  25580. // Read the table associated data
  25581. var previousPosition = file.pos;
  25582. file.pos = file.start ? file.start : 0;
  25583. file.skip(offset);
  25584. var data = file.getBytes(length);
  25585. file.pos = previousPosition;
  25586. if (tag === 'head') {
  25587. // clearing checksum adjustment
  25588. data[8] = data[9] = data[10] = data[11] = 0;
  25589. data[17] |= 0x20; //Set font optimized for cleartype flag
  25590. }
  25591. return {
  25592. tag: tag,
  25593. checksum: checksum,
  25594. length: length,
  25595. offset: offset,
  25596. data: data
  25597. };
  25598. }
  25599. function readOpenTypeHeader(ttf) {
  25600. return {
  25601. version: bytesToString(ttf.getBytes(4)),
  25602. numTables: ttf.getUint16(),
  25603. searchRange: ttf.getUint16(),
  25604. entrySelector: ttf.getUint16(),
  25605. rangeShift: ttf.getUint16()
  25606. };
  25607. }
  25608. /**
  25609. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  25610. * PDF spec
  25611. */
  25612. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  25613. if (!cmap) {
  25614. warn('No cmap table available.');
  25615. return {
  25616. platformId: -1,
  25617. encodingId: -1,
  25618. mappings: [],
  25619. hasShortCmap: false
  25620. };
  25621. }
  25622. var segment;
  25623. var start = (font.start ? font.start : 0) + cmap.offset;
  25624. font.pos = start;
  25625. var version = font.getUint16();
  25626. var numTables = font.getUint16();
  25627. var potentialTable;
  25628. var canBreak = false;
  25629. // There's an order of preference in terms of which cmap subtable to
  25630. // use:
  25631. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  25632. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  25633. // The following takes advantage of the fact that the tables are sorted
  25634. // to work.
  25635. for (var i = 0; i < numTables; i++) {
  25636. var platformId = font.getUint16();
  25637. var encodingId = font.getUint16();
  25638. var offset = font.getInt32() >>> 0;
  25639. var useTable = false;
  25640. if (platformId === 0 && encodingId === 0) {
  25641. useTable = true;
  25642. // Continue the loop since there still may be a higher priority
  25643. // table.
  25644. } else if (platformId === 1 && encodingId === 0) {
  25645. useTable = true;
  25646. // Continue the loop since there still may be a higher priority
  25647. // table.
  25648. } else if (platformId === 3 && encodingId === 1 &&
  25649. ((!isSymbolicFont && hasEncoding) || !potentialTable)) {
  25650. useTable = true;
  25651. if (!isSymbolicFont) {
  25652. canBreak = true;
  25653. }
  25654. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  25655. useTable = true;
  25656. canBreak = true;
  25657. }
  25658. if (useTable) {
  25659. potentialTable = {
  25660. platformId: platformId,
  25661. encodingId: encodingId,
  25662. offset: offset
  25663. };
  25664. }
  25665. if (canBreak) {
  25666. break;
  25667. }
  25668. }
  25669. if (potentialTable) {
  25670. font.pos = start + potentialTable.offset;
  25671. }
  25672. if (!potentialTable || font.peekByte() === -1) {
  25673. warn('Could not find a preferred cmap table.');
  25674. return {
  25675. platformId: -1,
  25676. encodingId: -1,
  25677. mappings: [],
  25678. hasShortCmap: false
  25679. };
  25680. }
  25681. var format = font.getUint16();
  25682. var length = font.getUint16();
  25683. var language = font.getUint16();
  25684. var hasShortCmap = false;
  25685. var mappings = [];
  25686. var j, glyphId;
  25687. // TODO(mack): refactor this cmap subtable reading logic out
  25688. if (format === 0) {
  25689. for (j = 0; j < 256; j++) {
  25690. var index = font.getByte();
  25691. if (!index) {
  25692. continue;
  25693. }
  25694. mappings.push({
  25695. charCode: j,
  25696. glyphId: index
  25697. });
  25698. }
  25699. hasShortCmap = true;
  25700. } else if (format === 4) {
  25701. // re-creating the table in format 4 since the encoding
  25702. // might be changed
  25703. var segCount = (font.getUint16() >> 1);
  25704. font.getBytes(6); // skipping range fields
  25705. var segIndex, segments = [];
  25706. for (segIndex = 0; segIndex < segCount; segIndex++) {
  25707. segments.push({ end: font.getUint16() });
  25708. }
  25709. font.getUint16();
  25710. for (segIndex = 0; segIndex < segCount; segIndex++) {
  25711. segments[segIndex].start = font.getUint16();
  25712. }
  25713. for (segIndex = 0; segIndex < segCount; segIndex++) {
  25714. segments[segIndex].delta = font.getUint16();
  25715. }
  25716. var offsetsCount = 0;
  25717. for (segIndex = 0; segIndex < segCount; segIndex++) {
  25718. segment = segments[segIndex];
  25719. var rangeOffset = font.getUint16();
  25720. if (!rangeOffset) {
  25721. segment.offsetIndex = -1;
  25722. continue;
  25723. }
  25724. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  25725. segment.offsetIndex = offsetIndex;
  25726. offsetsCount = Math.max(offsetsCount, offsetIndex +
  25727. segment.end - segment.start + 1);
  25728. }
  25729. var offsets = [];
  25730. for (j = 0; j < offsetsCount; j++) {
  25731. offsets.push(font.getUint16());
  25732. }
  25733. for (segIndex = 0; segIndex < segCount; segIndex++) {
  25734. segment = segments[segIndex];
  25735. start = segment.start;
  25736. var end = segment.end;
  25737. var delta = segment.delta;
  25738. offsetIndex = segment.offsetIndex;
  25739. for (j = start; j <= end; j++) {
  25740. if (j === 0xFFFF) {
  25741. continue;
  25742. }
  25743. glyphId = (offsetIndex < 0 ?
  25744. j : offsets[offsetIndex + j - start]);
  25745. glyphId = (glyphId + delta) & 0xFFFF;
  25746. if (glyphId === 0) {
  25747. continue;
  25748. }
  25749. mappings.push({
  25750. charCode: j,
  25751. glyphId: glyphId
  25752. });
  25753. }
  25754. }
  25755. } else if (format === 6) {
  25756. // Format 6 is a 2-bytes dense mapping, which means the font data
  25757. // lives glue together even if they are pretty far in the unicode
  25758. // table. (This looks weird, so I can have missed something), this
  25759. // works on Linux but seems to fails on Mac so let's rewrite the
  25760. // cmap table to a 3-1-4 style
  25761. var firstCode = font.getUint16();
  25762. var entryCount = font.getUint16();
  25763. for (j = 0; j < entryCount; j++) {
  25764. glyphId = font.getUint16();
  25765. var charCode = firstCode + j;
  25766. mappings.push({
  25767. charCode: charCode,
  25768. glyphId: glyphId
  25769. });
  25770. }
  25771. } else {
  25772. warn('cmap table has unsupported format: ' + format);
  25773. return {
  25774. platformId: -1,
  25775. encodingId: -1,
  25776. mappings: [],
  25777. hasShortCmap: false
  25778. };
  25779. }
  25780. // removing duplicate entries
  25781. mappings.sort(function (a, b) {
  25782. return a.charCode - b.charCode;
  25783. });
  25784. for (i = 1; i < mappings.length; i++) {
  25785. if (mappings[i - 1].charCode === mappings[i].charCode) {
  25786. mappings.splice(i, 1);
  25787. i--;
  25788. }
  25789. }
  25790. return {
  25791. platformId: potentialTable.platformId,
  25792. encodingId: potentialTable.encodingId,
  25793. mappings: mappings,
  25794. hasShortCmap: hasShortCmap
  25795. };
  25796. }
  25797. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  25798. if (!header) {
  25799. if (metrics) {
  25800. metrics.data = null;
  25801. }
  25802. return;
  25803. }
  25804. font.pos = (font.start ? font.start : 0) + header.offset;
  25805. font.pos += header.length - 2;
  25806. var numOfMetrics = font.getUint16();
  25807. if (numOfMetrics > numGlyphs) {
  25808. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  25809. 'greater than the numGlyphs (' + numGlyphs + ')');
  25810. // Reduce numOfMetrics if it is greater than numGlyphs
  25811. numOfMetrics = numGlyphs;
  25812. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  25813. header.data[35] = numOfMetrics & 0x00ff;
  25814. }
  25815. var numOfSidebearings = numGlyphs - numOfMetrics;
  25816. var numMissing = numOfSidebearings -
  25817. ((metrics.length - numOfMetrics * 4) >> 1);
  25818. if (numMissing > 0) {
  25819. // For each missing glyph, we set both the width and lsb to 0 (zero).
  25820. // Since we need to add two properties for each glyph, this explains
  25821. // the use of |numMissing * 2| when initializing the typed array.
  25822. var entries = new Uint8Array(metrics.length + numMissing * 2);
  25823. entries.set(metrics.data);
  25824. metrics.data = entries;
  25825. }
  25826. }
  25827. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  25828. hintsValid) {
  25829. if (sourceEnd - sourceStart <= 12) {
  25830. // glyph with data less than 12 is invalid one
  25831. return 0;
  25832. }
  25833. var glyf = source.subarray(sourceStart, sourceEnd);
  25834. var contoursCount = (glyf[0] << 8) | glyf[1];
  25835. if (contoursCount & 0x8000) {
  25836. // complex glyph, writing as is
  25837. dest.set(glyf, destStart);
  25838. return glyf.length;
  25839. }
  25840. var i, j = 10, flagsCount = 0;
  25841. for (i = 0; i < contoursCount; i++) {
  25842. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  25843. flagsCount = endPoint + 1;
  25844. j += 2;
  25845. }
  25846. // skipping instructions
  25847. var instructionsStart = j;
  25848. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  25849. j += 2 + instructionsLength;
  25850. var instructionsEnd = j;
  25851. // validating flags
  25852. var coordinatesLength = 0;
  25853. for (i = 0; i < flagsCount; i++) {
  25854. var flag = glyf[j++];
  25855. if (flag & 0xC0) {
  25856. // reserved flags must be zero, cleaning up
  25857. glyf[j - 1] = flag & 0x3F;
  25858. }
  25859. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  25860. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  25861. coordinatesLength += xyLength;
  25862. if (flag & 8) {
  25863. var repeat = glyf[j++];
  25864. i += repeat;
  25865. coordinatesLength += repeat * xyLength;
  25866. }
  25867. }
  25868. // glyph without coordinates will be rejected
  25869. if (coordinatesLength === 0) {
  25870. return 0;
  25871. }
  25872. var glyphDataLength = j + coordinatesLength;
  25873. if (glyphDataLength > glyf.length) {
  25874. // not enough data for coordinates
  25875. return 0;
  25876. }
  25877. if (!hintsValid && instructionsLength > 0) {
  25878. dest.set(glyf.subarray(0, instructionsStart), destStart);
  25879. dest.set([0, 0], destStart + instructionsStart);
  25880. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  25881. destStart + instructionsStart + 2);
  25882. glyphDataLength -= instructionsLength;
  25883. if (glyf.length - glyphDataLength > 3) {
  25884. glyphDataLength = (glyphDataLength + 3) & ~3;
  25885. }
  25886. return glyphDataLength;
  25887. }
  25888. if (glyf.length - glyphDataLength > 3) {
  25889. // truncating and aligning to 4 bytes the long glyph data
  25890. glyphDataLength = (glyphDataLength + 3) & ~3;
  25891. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  25892. return glyphDataLength;
  25893. }
  25894. // glyph data is fine
  25895. dest.set(glyf, destStart);
  25896. return glyf.length;
  25897. }
  25898. function sanitizeHead(head, numGlyphs, locaLength) {
  25899. var data = head.data;
  25900. // Validate version:
  25901. // Should always be 0x00010000
  25902. var version = int32(data[0], data[1], data[2], data[3]);
  25903. if (version >> 16 !== 1) {
  25904. info('Attempting to fix invalid version in head table: ' + version);
  25905. data[0] = 0;
  25906. data[1] = 1;
  25907. data[2] = 0;
  25908. data[3] = 0;
  25909. }
  25910. var indexToLocFormat = int16(data[50], data[51]);
  25911. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  25912. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  25913. indexToLocFormat);
  25914. // The value of indexToLocFormat should be 0 if the loca table
  25915. // consists of short offsets, and should be 1 if the loca table
  25916. // consists of long offsets.
  25917. //
  25918. // The number of entries in the loca table should be numGlyphs + 1.
  25919. //
  25920. // Using this information, we can work backwards to deduce if the
  25921. // size of each offset in the loca table, and thus figure out the
  25922. // appropriate value for indexToLocFormat.
  25923. var numGlyphsPlusOne = numGlyphs + 1;
  25924. if (locaLength === numGlyphsPlusOne << 1) {
  25925. // 0x0000 indicates the loca table consists of short offsets
  25926. data[50] = 0;
  25927. data[51] = 0;
  25928. } else if (locaLength === numGlyphsPlusOne << 2) {
  25929. // 0x0001 indicates the loca table consists of long offsets
  25930. data[50] = 0;
  25931. data[51] = 1;
  25932. } else {
  25933. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  25934. }
  25935. }
  25936. }
  25937. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  25938. isGlyphLocationsLong, hintsValid,
  25939. dupFirstEntry) {
  25940. var itemSize, itemDecode, itemEncode;
  25941. if (isGlyphLocationsLong) {
  25942. itemSize = 4;
  25943. itemDecode = function fontItemDecodeLong(data, offset) {
  25944. return (data[offset] << 24) | (data[offset + 1] << 16) |
  25945. (data[offset + 2] << 8) | data[offset + 3];
  25946. };
  25947. itemEncode = function fontItemEncodeLong(data, offset, value) {
  25948. data[offset] = (value >>> 24) & 0xFF;
  25949. data[offset + 1] = (value >> 16) & 0xFF;
  25950. data[offset + 2] = (value >> 8) & 0xFF;
  25951. data[offset + 3] = value & 0xFF;
  25952. };
  25953. } else {
  25954. itemSize = 2;
  25955. itemDecode = function fontItemDecode(data, offset) {
  25956. return (data[offset] << 9) | (data[offset + 1] << 1);
  25957. };
  25958. itemEncode = function fontItemEncode(data, offset, value) {
  25959. data[offset] = (value >> 9) & 0xFF;
  25960. data[offset + 1] = (value >> 1) & 0xFF;
  25961. };
  25962. }
  25963. var locaData = loca.data;
  25964. var locaDataSize = itemSize * (1 + numGlyphs);
  25965. // is loca.data too short or long?
  25966. if (locaData.length !== locaDataSize) {
  25967. locaData = new Uint8Array(locaDataSize);
  25968. locaData.set(loca.data.subarray(0, locaDataSize));
  25969. loca.data = locaData;
  25970. }
  25971. // removing the invalid glyphs
  25972. var oldGlyfData = glyf.data;
  25973. var oldGlyfDataLength = oldGlyfData.length;
  25974. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  25975. var startOffset = itemDecode(locaData, 0);
  25976. var writeOffset = 0;
  25977. var missingGlyphData = Object.create(null);
  25978. itemEncode(locaData, 0, writeOffset);
  25979. var i, j;
  25980. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  25981. var endOffset = itemDecode(locaData, j);
  25982. if (endOffset > oldGlyfDataLength &&
  25983. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  25984. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  25985. // the glyf table size, which makes last glyph out of range.
  25986. endOffset = oldGlyfDataLength;
  25987. }
  25988. if (endOffset > oldGlyfDataLength) {
  25989. // glyph end offset points outside glyf data, rejecting the glyph
  25990. itemEncode(locaData, j, writeOffset);
  25991. startOffset = endOffset;
  25992. continue;
  25993. }
  25994. if (startOffset === endOffset) {
  25995. missingGlyphData[i] = true;
  25996. }
  25997. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  25998. newGlyfData, writeOffset, hintsValid);
  25999. writeOffset += newLength;
  26000. itemEncode(locaData, j, writeOffset);
  26001. startOffset = endOffset;
  26002. }
  26003. if (writeOffset === 0) {
  26004. // glyf table cannot be empty -- redoing the glyf and loca tables
  26005. // to have single glyph with one point
  26006. var simpleGlyph = new Uint8Array(
  26007. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  26008. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  26009. itemEncode(locaData, j, simpleGlyph.length);
  26010. }
  26011. glyf.data = simpleGlyph;
  26012. return missingGlyphData;
  26013. }
  26014. if (dupFirstEntry) {
  26015. var firstEntryLength = itemDecode(locaData, itemSize);
  26016. if (newGlyfData.length > firstEntryLength + writeOffset) {
  26017. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  26018. } else {
  26019. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  26020. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  26021. }
  26022. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  26023. itemEncode(loca.data, locaData.length - itemSize,
  26024. writeOffset + firstEntryLength);
  26025. } else {
  26026. glyf.data = newGlyfData.subarray(0, writeOffset);
  26027. }
  26028. return missingGlyphData;
  26029. }
  26030. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  26031. var start = (font.start ? font.start : 0) + post.offset;
  26032. font.pos = start;
  26033. var length = post.length, end = start + length;
  26034. var version = font.getInt32();
  26035. // skip rest to the tables
  26036. font.getBytes(28);
  26037. var glyphNames;
  26038. var valid = true;
  26039. var i;
  26040. switch (version) {
  26041. case 0x00010000:
  26042. glyphNames = MacStandardGlyphOrdering;
  26043. break;
  26044. case 0x00020000:
  26045. var numGlyphs = font.getUint16();
  26046. if (numGlyphs !== maxpNumGlyphs) {
  26047. valid = false;
  26048. break;
  26049. }
  26050. var glyphNameIndexes = [];
  26051. for (i = 0; i < numGlyphs; ++i) {
  26052. var index = font.getUint16();
  26053. if (index >= 32768) {
  26054. valid = false;
  26055. break;
  26056. }
  26057. glyphNameIndexes.push(index);
  26058. }
  26059. if (!valid) {
  26060. break;
  26061. }
  26062. var customNames = [];
  26063. var strBuf = [];
  26064. while (font.pos < end) {
  26065. var stringLength = font.getByte();
  26066. strBuf.length = stringLength;
  26067. for (i = 0; i < stringLength; ++i) {
  26068. strBuf[i] = String.fromCharCode(font.getByte());
  26069. }
  26070. customNames.push(strBuf.join(''));
  26071. }
  26072. glyphNames = [];
  26073. for (i = 0; i < numGlyphs; ++i) {
  26074. var j = glyphNameIndexes[i];
  26075. if (j < 258) {
  26076. glyphNames.push(MacStandardGlyphOrdering[j]);
  26077. continue;
  26078. }
  26079. glyphNames.push(customNames[j - 258]);
  26080. }
  26081. break;
  26082. case 0x00030000:
  26083. break;
  26084. default:
  26085. warn('Unknown/unsupported post table version ' + version);
  26086. valid = false;
  26087. if (properties.defaultEncoding) {
  26088. glyphNames = properties.defaultEncoding;
  26089. }
  26090. break;
  26091. }
  26092. properties.glyphNames = glyphNames;
  26093. return valid;
  26094. }
  26095. function readNameTable(nameTable) {
  26096. var start = (font.start ? font.start : 0) + nameTable.offset;
  26097. font.pos = start;
  26098. var names = [[], []];
  26099. var length = nameTable.length, end = start + length;
  26100. var format = font.getUint16();
  26101. var FORMAT_0_HEADER_LENGTH = 6;
  26102. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  26103. // unsupported name table format or table "too" small
  26104. return names;
  26105. }
  26106. var numRecords = font.getUint16();
  26107. var stringsStart = font.getUint16();
  26108. var records = [];
  26109. var NAME_RECORD_LENGTH = 12;
  26110. var i, ii;
  26111. for (i = 0; i < numRecords &&
  26112. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  26113. var r = {
  26114. platform: font.getUint16(),
  26115. encoding: font.getUint16(),
  26116. language: font.getUint16(),
  26117. name: font.getUint16(),
  26118. length: font.getUint16(),
  26119. offset: font.getUint16()
  26120. };
  26121. // using only Macintosh and Windows platform/encoding names
  26122. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  26123. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  26124. records.push(r);
  26125. }
  26126. }
  26127. for (i = 0, ii = records.length; i < ii; i++) {
  26128. var record = records[i];
  26129. if (record.length <= 0) {
  26130. continue; // Nothing to process, ignoring.
  26131. }
  26132. var pos = start + stringsStart + record.offset;
  26133. if (pos + record.length > end) {
  26134. continue; // outside of name table, ignoring
  26135. }
  26136. font.pos = pos;
  26137. var nameIndex = record.name;
  26138. if (record.encoding) {
  26139. // unicode
  26140. var str = '';
  26141. for (var j = 0, jj = record.length; j < jj; j += 2) {
  26142. str += String.fromCharCode(font.getUint16());
  26143. }
  26144. names[1][nameIndex] = str;
  26145. } else {
  26146. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  26147. }
  26148. }
  26149. return names;
  26150. }
  26151. var TTOpsStackDeltas = [
  26152. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  26153. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  26154. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  26155. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  26156. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  26157. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  26158. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  26159. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  26160. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  26161. // 0xC0-DF == -1 and 0xE0-FF == -2
  26162. function sanitizeTTProgram(table, ttContext) {
  26163. var data = table.data;
  26164. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  26165. var stack = [];
  26166. var callstack = [];
  26167. var functionsCalled = [];
  26168. var tooComplexToFollowFunctions =
  26169. ttContext.tooComplexToFollowFunctions;
  26170. var inFDEF = false, ifLevel = 0, inELSE = 0;
  26171. for (var ii = data.length; i < ii;) {
  26172. var op = data[i++];
  26173. // The TrueType instruction set docs can be found at
  26174. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  26175. if (op === 0x40) { // NPUSHB - pushes n bytes
  26176. n = data[i++];
  26177. if (inFDEF || inELSE) {
  26178. i += n;
  26179. } else {
  26180. for (j = 0; j < n; j++) {
  26181. stack.push(data[i++]);
  26182. }
  26183. }
  26184. } else if (op === 0x41) { // NPUSHW - pushes n words
  26185. n = data[i++];
  26186. if (inFDEF || inELSE) {
  26187. i += n * 2;
  26188. } else {
  26189. for (j = 0; j < n; j++) {
  26190. b = data[i++];
  26191. stack.push((b << 8) | data[i++]);
  26192. }
  26193. }
  26194. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  26195. n = op - 0xB0 + 1;
  26196. if (inFDEF || inELSE) {
  26197. i += n;
  26198. } else {
  26199. for (j = 0; j < n; j++) {
  26200. stack.push(data[i++]);
  26201. }
  26202. }
  26203. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  26204. n = op - 0xB8 + 1;
  26205. if (inFDEF || inELSE) {
  26206. i += n * 2;
  26207. } else {
  26208. for (j = 0; j < n; j++) {
  26209. b = data[i++];
  26210. stack.push((b << 8) | data[i++]);
  26211. }
  26212. }
  26213. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  26214. if (!inFDEF && !inELSE) {
  26215. // collecting inforamtion about which functions are used
  26216. funcId = stack[stack.length - 1];
  26217. ttContext.functionsUsed[funcId] = true;
  26218. if (funcId in ttContext.functionsStackDeltas) {
  26219. stack.length += ttContext.functionsStackDeltas[funcId];
  26220. } else if (funcId in ttContext.functionsDefined &&
  26221. functionsCalled.indexOf(funcId) < 0) {
  26222. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  26223. functionsCalled.push(funcId);
  26224. pc = ttContext.functionsDefined[funcId];
  26225. if (!pc) {
  26226. warn('TT: CALL non-existent function');
  26227. ttContext.hintsValid = false;
  26228. return;
  26229. }
  26230. data = pc.data;
  26231. i = pc.i;
  26232. }
  26233. }
  26234. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  26235. if (inFDEF || inELSE) {
  26236. warn('TT: nested FDEFs not allowed');
  26237. tooComplexToFollowFunctions = true;
  26238. }
  26239. inFDEF = true;
  26240. // collecting inforamtion about which functions are defined
  26241. lastDeff = i;
  26242. funcId = stack.pop();
  26243. ttContext.functionsDefined[funcId] = {data: data, i: i};
  26244. } else if (op === 0x2D) { // ENDF - end of function
  26245. if (inFDEF) {
  26246. inFDEF = false;
  26247. lastEndf = i;
  26248. } else {
  26249. pc = callstack.pop();
  26250. if (!pc) {
  26251. warn('TT: ENDF bad stack');
  26252. ttContext.hintsValid = false;
  26253. return;
  26254. }
  26255. funcId = functionsCalled.pop();
  26256. data = pc.data;
  26257. i = pc.i;
  26258. ttContext.functionsStackDeltas[funcId] =
  26259. stack.length - pc.stackTop;
  26260. }
  26261. } else if (op === 0x89) { // IDEF - instruction definition
  26262. if (inFDEF || inELSE) {
  26263. warn('TT: nested IDEFs not allowed');
  26264. tooComplexToFollowFunctions = true;
  26265. }
  26266. inFDEF = true;
  26267. // recording it as a function to track ENDF
  26268. lastDeff = i;
  26269. } else if (op === 0x58) { // IF
  26270. ++ifLevel;
  26271. } else if (op === 0x1B) { // ELSE
  26272. inELSE = ifLevel;
  26273. } else if (op === 0x59) { // EIF
  26274. if (inELSE === ifLevel) {
  26275. inELSE = 0;
  26276. }
  26277. --ifLevel;
  26278. } else if (op === 0x1C) { // JMPR
  26279. if (!inFDEF && !inELSE) {
  26280. var offset = stack[stack.length - 1];
  26281. // only jumping forward to prevent infinite loop
  26282. if (offset > 0) {
  26283. i += offset - 1;
  26284. }
  26285. }
  26286. }
  26287. // Adjusting stack not extactly, but just enough to get function id
  26288. if (!inFDEF && !inELSE) {
  26289. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  26290. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  26291. if (op >= 0x71 && op <= 0x75) {
  26292. n = stack.pop();
  26293. if (n === n) {
  26294. stackDelta = -n * 2;
  26295. }
  26296. }
  26297. while (stackDelta < 0 && stack.length > 0) {
  26298. stack.pop();
  26299. stackDelta++;
  26300. }
  26301. while (stackDelta > 0) {
  26302. stack.push(NaN); // pushing any number into stack
  26303. stackDelta--;
  26304. }
  26305. }
  26306. }
  26307. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  26308. var content = [data];
  26309. if (i > data.length) {
  26310. content.push(new Uint8Array(i - data.length));
  26311. }
  26312. if (lastDeff > lastEndf) {
  26313. warn('TT: complementing a missing function tail');
  26314. // new function definition started, but not finished
  26315. // complete function by [CLEAR, ENDF]
  26316. content.push(new Uint8Array([0x22, 0x2D]));
  26317. }
  26318. foldTTTable(table, content);
  26319. }
  26320. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  26321. if (ttContext.tooComplexToFollowFunctions) {
  26322. return;
  26323. }
  26324. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  26325. warn('TT: more functions defined than expected');
  26326. ttContext.hintsValid = false;
  26327. return;
  26328. }
  26329. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  26330. if (j > maxFunctionDefs) {
  26331. warn('TT: invalid function id: ' + j);
  26332. ttContext.hintsValid = false;
  26333. return;
  26334. }
  26335. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  26336. warn('TT: undefined function: ' + j);
  26337. ttContext.hintsValid = false;
  26338. return;
  26339. }
  26340. }
  26341. }
  26342. function foldTTTable(table, content) {
  26343. if (content.length > 1) {
  26344. // concatenating the content items
  26345. var newLength = 0;
  26346. var j, jj;
  26347. for (j = 0, jj = content.length; j < jj; j++) {
  26348. newLength += content[j].length;
  26349. }
  26350. newLength = (newLength + 3) & ~3;
  26351. var result = new Uint8Array(newLength);
  26352. var pos = 0;
  26353. for (j = 0, jj = content.length; j < jj; j++) {
  26354. result.set(content[j], pos);
  26355. pos += content[j].length;
  26356. }
  26357. table.data = result;
  26358. table.length = newLength;
  26359. }
  26360. }
  26361. function sanitizeTTPrograms(fpgm, prep, cvt) {
  26362. var ttContext = {
  26363. functionsDefined: [],
  26364. functionsUsed: [],
  26365. functionsStackDeltas: [],
  26366. tooComplexToFollowFunctions: false,
  26367. hintsValid: true
  26368. };
  26369. if (fpgm) {
  26370. sanitizeTTProgram(fpgm, ttContext);
  26371. }
  26372. if (prep) {
  26373. sanitizeTTProgram(prep, ttContext);
  26374. }
  26375. if (fpgm) {
  26376. checkInvalidFunctions(ttContext, maxFunctionDefs);
  26377. }
  26378. if (cvt && (cvt.length & 1)) {
  26379. var cvtData = new Uint8Array(cvt.length + 1);
  26380. cvtData.set(cvt.data);
  26381. cvt.data = cvtData;
  26382. }
  26383. return ttContext.hintsValid;
  26384. }
  26385. // The following steps modify the original font data, making copy
  26386. font = new Stream(new Uint8Array(font.getBytes()));
  26387. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  26388. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  26389. var header = readOpenTypeHeader(font);
  26390. var numTables = header.numTables;
  26391. var cff, cffFile;
  26392. var tables = Object.create(null);
  26393. tables['OS/2'] = null;
  26394. tables['cmap'] = null;
  26395. tables['head'] = null;
  26396. tables['hhea'] = null;
  26397. tables['hmtx'] = null;
  26398. tables['maxp'] = null;
  26399. tables['name'] = null;
  26400. tables['post'] = null;
  26401. var table;
  26402. for (var i = 0; i < numTables; i++) {
  26403. table = readTableEntry(font);
  26404. if (VALID_TABLES.indexOf(table.tag) < 0) {
  26405. continue; // skipping table if it's not a required or optional table
  26406. }
  26407. if (table.length === 0) {
  26408. continue; // skipping empty tables
  26409. }
  26410. tables[table.tag] = table;
  26411. }
  26412. var isTrueType = !tables['CFF '];
  26413. if (!isTrueType) {
  26414. // OpenType font
  26415. if ((header.version === 'OTTO' && properties.type !== 'CIDFontType2') ||
  26416. !tables['head'] || !tables['hhea'] || !tables['maxp'] ||
  26417. !tables['post']) {
  26418. // no major tables: throwing everything at CFFFont
  26419. cffFile = new Stream(tables['CFF '].data);
  26420. cff = new CFFFont(cffFile, properties);
  26421. adjustWidths(properties);
  26422. return this.convert(name, cff, properties);
  26423. }
  26424. delete tables['glyf'];
  26425. delete tables['loca'];
  26426. delete tables['fpgm'];
  26427. delete tables['prep'];
  26428. delete tables['cvt '];
  26429. this.isOpenType = true;
  26430. } else {
  26431. if (!tables['loca']) {
  26432. error('Required "loca" table is not found');
  26433. }
  26434. if (!tables['glyf']) {
  26435. warn('Required "glyf" table is not found -- trying to recover.');
  26436. // Note: We use `sanitizeGlyphLocations` to add dummy glyf data below.
  26437. tables['glyf'] = {
  26438. tag: 'glyf',
  26439. data: new Uint8Array(0),
  26440. };
  26441. }
  26442. this.isOpenType = false;
  26443. }
  26444. if (!tables['maxp']) {
  26445. error('Required "maxp" table is not found');
  26446. }
  26447. font.pos = (font.start || 0) + tables['maxp'].offset;
  26448. var version = font.getInt32();
  26449. var numGlyphs = font.getUint16();
  26450. var maxFunctionDefs = 0;
  26451. if (version >= 0x00010000 && tables['maxp'].length >= 22) {
  26452. // maxZones can be invalid
  26453. font.pos += 8;
  26454. var maxZones = font.getUint16();
  26455. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  26456. tables['maxp'].data[14] = 0;
  26457. tables['maxp'].data[15] = 2;
  26458. }
  26459. font.pos += 4;
  26460. maxFunctionDefs = font.getUint16();
  26461. }
  26462. var dupFirstEntry = false;
  26463. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  26464. properties.toUnicode.get(0) > '\u0000') {
  26465. // oracle's defect (see 3427), duplicating first entry
  26466. dupFirstEntry = true;
  26467. numGlyphs++;
  26468. tables['maxp'].data[4] = numGlyphs >> 8;
  26469. tables['maxp'].data[5] = numGlyphs & 255;
  26470. }
  26471. var hintsValid = sanitizeTTPrograms(tables['fpgm'], tables['prep'],
  26472. tables['cvt '], maxFunctionDefs);
  26473. if (!hintsValid) {
  26474. delete tables['fpgm'];
  26475. delete tables['prep'];
  26476. delete tables['cvt '];
  26477. }
  26478. // Ensure the hmtx table contains the advance width and
  26479. // sidebearings information for numGlyphs in the maxp table
  26480. sanitizeMetrics(font, tables['hhea'], tables['hmtx'], numGlyphs);
  26481. if (!tables['head']) {
  26482. error('Required "head" table is not found');
  26483. }
  26484. sanitizeHead(tables['head'], numGlyphs,
  26485. isTrueType ? tables['loca'].length : 0);
  26486. var missingGlyphs = Object.create(null);
  26487. if (isTrueType) {
  26488. var isGlyphLocationsLong = int16(tables['head'].data[50],
  26489. tables['head'].data[51]);
  26490. missingGlyphs = sanitizeGlyphLocations(tables['loca'], tables['glyf'],
  26491. numGlyphs, isGlyphLocationsLong,
  26492. hintsValid, dupFirstEntry);
  26493. }
  26494. if (!tables['hhea']) {
  26495. error('Required "hhea" table is not found');
  26496. }
  26497. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  26498. // Sometimes it's 0. That needs to be fixed
  26499. if (tables['hhea'].data[10] === 0 && tables['hhea'].data[11] === 0) {
  26500. tables['hhea'].data[10] = 0xFF;
  26501. tables['hhea'].data[11] = 0xFF;
  26502. }
  26503. // Extract some more font properties from the OpenType head and
  26504. // hhea tables; yMin and descent value are always negative.
  26505. var metricsOverride = {
  26506. unitsPerEm: int16(tables['head'].data[18], tables['head'].data[19]),
  26507. yMax: int16(tables['head'].data[42], tables['head'].data[43]),
  26508. yMin: int16(tables['head'].data[38], tables['head'].data[39]) - 0x10000,
  26509. ascent: int16(tables['hhea'].data[4], tables['hhea'].data[5]),
  26510. descent: int16(tables['hhea'].data[6], tables['hhea'].data[7]) - 0x10000
  26511. };
  26512. // PDF FontDescriptor metrics lie -- using data from actual font.
  26513. this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
  26514. this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
  26515. // The 'post' table has glyphs names.
  26516. if (tables['post']) {
  26517. var valid = readPostScriptTable(tables['post'], properties, numGlyphs);
  26518. if (!valid) {
  26519. tables['post'] = null;
  26520. }
  26521. }
  26522. var charCodeToGlyphId = [], charCode;
  26523. var toUnicode = properties.toUnicode, widths = properties.widths;
  26524. var skipToUnicode = (toUnicode instanceof IdentityToUnicodeMap ||
  26525. toUnicode.length === 0x10000);
  26526. // Helper function to try to skip mapping of empty glyphs.
  26527. // Note: In some cases, just relying on the glyph data doesn't work,
  26528. // hence we also use a few heuristics to fix various PDF files.
  26529. function hasGlyph(glyphId, charCode, widthCode) {
  26530. if (!missingGlyphs[glyphId]) {
  26531. return true;
  26532. }
  26533. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  26534. return true;
  26535. }
  26536. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  26537. return true;
  26538. }
  26539. return false;
  26540. }
  26541. if (properties.type === 'CIDFontType2') {
  26542. var cidToGidMap = properties.cidToGidMap || [];
  26543. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  26544. properties.cMap.forEach(function(charCode, cid) {
  26545. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  26546. var glyphId = -1;
  26547. if (isCidToGidMapEmpty) {
  26548. glyphId = cid;
  26549. } else if (cidToGidMap[cid] !== undefined) {
  26550. glyphId = cidToGidMap[cid];
  26551. }
  26552. if (glyphId >= 0 && glyphId < numGlyphs &&
  26553. hasGlyph(glyphId, charCode, cid)) {
  26554. charCodeToGlyphId[charCode] = glyphId;
  26555. }
  26556. });
  26557. if (dupFirstEntry) {
  26558. charCodeToGlyphId[0] = numGlyphs - 1;
  26559. }
  26560. } else {
  26561. // Most of the following logic in this code branch is based on the
  26562. // 9.6.6.4 of the PDF spec.
  26563. var hasEncoding =
  26564. properties.differences.length > 0 || !!properties.baseEncodingName;
  26565. var cmapTable =
  26566. readCmapTable(tables['cmap'], font, this.isSymbolicFont, hasEncoding);
  26567. var cmapPlatformId = cmapTable.platformId;
  26568. var cmapEncodingId = cmapTable.encodingId;
  26569. var cmapMappings = cmapTable.mappings;
  26570. var cmapMappingsLength = cmapMappings.length;
  26571. // The spec seems to imply that if the font is symbolic the encoding
  26572. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  26573. // where the the font is symbolic and it has an encoding.
  26574. if (hasEncoding &&
  26575. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  26576. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  26577. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  26578. !!getEncoding(properties.baseEncodingName))) { // Temporary hack
  26579. // When no preferred cmap table was found and |baseEncodingName| is
  26580. // one of the predefined encodings, we seem to obtain a better
  26581. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  26582. // TODO: Note that this is a hack which should be removed as soon as
  26583. // we have proper support for more exotic cmap tables.
  26584. var baseEncoding = [];
  26585. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  26586. properties.baseEncodingName === 'WinAnsiEncoding') {
  26587. baseEncoding = getEncoding(properties.baseEncodingName);
  26588. }
  26589. var glyphsUnicodeMap = getGlyphsUnicode();
  26590. for (charCode = 0; charCode < 256; charCode++) {
  26591. var glyphName;
  26592. if (this.differences && charCode in this.differences) {
  26593. glyphName = this.differences[charCode];
  26594. } else if (charCode in baseEncoding &&
  26595. baseEncoding[charCode] !== '') {
  26596. glyphName = baseEncoding[charCode];
  26597. } else {
  26598. glyphName = StandardEncoding[charCode];
  26599. }
  26600. if (!glyphName) {
  26601. continue;
  26602. }
  26603. var unicodeOrCharCode, isUnicode = false;
  26604. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  26605. unicodeOrCharCode = glyphsUnicodeMap[glyphName];
  26606. isUnicode = true;
  26607. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  26608. // TODO: the encoding needs to be updated with mac os table.
  26609. unicodeOrCharCode = MacRomanEncoding.indexOf(glyphName);
  26610. }
  26611. var found = false;
  26612. for (i = 0; i < cmapMappingsLength; ++i) {
  26613. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  26614. continue;
  26615. }
  26616. var code = isUnicode ? charCode : unicodeOrCharCode;
  26617. if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
  26618. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  26619. found = true;
  26620. break;
  26621. }
  26622. }
  26623. if (!found && properties.glyphNames) {
  26624. // Try to map using the post table.
  26625. var glyphId = properties.glyphNames.indexOf(glyphName);
  26626. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  26627. charCodeToGlyphId[charCode] = glyphId;
  26628. found = true;
  26629. }
  26630. }
  26631. if (!found) {
  26632. charCodeToGlyphId[charCode] = 0; // notdef
  26633. }
  26634. }
  26635. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  26636. // Default Unicode semantics, use the charcodes as is.
  26637. for (i = 0; i < cmapMappingsLength; ++i) {
  26638. charCodeToGlyphId[cmapMappings[i].charCode] =
  26639. cmapMappings[i].glyphId;
  26640. }
  26641. } else {
  26642. // For (3, 0) cmap tables:
  26643. // The charcode key being stored in charCodeToGlyphId is the lower
  26644. // byte of the two-byte charcodes of the cmap table since according to
  26645. // the spec: 'each byte from the string shall be prepended with the
  26646. // high byte of the range [of charcodes in the cmap table], to form
  26647. // a two-byte character, which shall be used to select the
  26648. // associated glyph description from the subtable'.
  26649. //
  26650. // For (1, 0) cmap tables:
  26651. // 'single bytes from the string shall be used to look up the
  26652. // associated glyph descriptions from the subtable'. This means
  26653. // charcodes in the cmap will be single bytes, so no-op since
  26654. // glyph.charCode & 0xFF === glyph.charCode
  26655. for (i = 0; i < cmapMappingsLength; ++i) {
  26656. charCode = cmapMappings[i].charCode & 0xFF;
  26657. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  26658. }
  26659. }
  26660. }
  26661. if (charCodeToGlyphId.length === 0) {
  26662. // defines at least one glyph
  26663. charCodeToGlyphId[0] = 0;
  26664. }
  26665. // Converting glyphs and ids into font's cmap table
  26666. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  26667. this.toFontChar = newMapping.toFontChar;
  26668. tables['cmap'] = {
  26669. tag: 'cmap',
  26670. data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphs)
  26671. };
  26672. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  26673. tables['OS/2'] = {
  26674. tag: 'OS/2',
  26675. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  26676. metricsOverride)
  26677. };
  26678. }
  26679. // Rewrite the 'post' table if needed
  26680. if (!tables['post']) {
  26681. tables['post'] = {
  26682. tag: 'post',
  26683. data: createPostTable(properties)
  26684. };
  26685. }
  26686. if (!isTrueType) {
  26687. try {
  26688. // Trying to repair CFF file
  26689. cffFile = new Stream(tables['CFF '].data);
  26690. var parser = new CFFParser(cffFile, properties);
  26691. cff = parser.parse();
  26692. var compiler = new CFFCompiler(cff);
  26693. tables['CFF '].data = compiler.compile();
  26694. } catch (e) {
  26695. warn('Failed to compile font ' + properties.loadedName);
  26696. }
  26697. }
  26698. // Re-creating 'name' table
  26699. if (!tables['name']) {
  26700. tables['name'] = {
  26701. tag: 'name',
  26702. data: createNameTable(this.name)
  26703. };
  26704. } else {
  26705. // ... using existing 'name' table as prototype
  26706. var namePrototype = readNameTable(tables['name']);
  26707. tables['name'].data = createNameTable(name, namePrototype);
  26708. }
  26709. var builder = new OpenTypeFileBuilder(header.version);
  26710. for (var tableTag in tables) {
  26711. builder.addTable(tableTag, tables[tableTag].data);
  26712. }
  26713. return builder.toArray();
  26714. },
  26715. convert: function Font_convert(fontName, font, properties) {
  26716. // TODO: Check the charstring widths to determine this.
  26717. properties.fixedPitch = false;
  26718. var mapping = font.getGlyphMapping(properties);
  26719. var newMapping = adjustMapping(mapping, properties);
  26720. this.toFontChar = newMapping.toFontChar;
  26721. var numGlyphs = font.numGlyphs;
  26722. function getCharCodes(charCodeToGlyphId, glyphId) {
  26723. var charCodes = null;
  26724. for (var charCode in charCodeToGlyphId) {
  26725. if (glyphId === charCodeToGlyphId[charCode]) {
  26726. if (!charCodes) {
  26727. charCodes = [];
  26728. }
  26729. charCodes.push(charCode | 0);
  26730. }
  26731. }
  26732. return charCodes;
  26733. }
  26734. function createCharCode(charCodeToGlyphId, glyphId) {
  26735. for (var charCode in charCodeToGlyphId) {
  26736. if (glyphId === charCodeToGlyphId[charCode]) {
  26737. return charCode | 0;
  26738. }
  26739. }
  26740. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  26741. glyphId;
  26742. return newMapping.nextAvailableFontCharCode++;
  26743. }
  26744. var seacs = font.seacs;
  26745. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  26746. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  26747. var charset = font.getCharset();
  26748. var seacMap = Object.create(null);
  26749. for (var glyphId in seacs) {
  26750. glyphId |= 0;
  26751. var seac = seacs[glyphId];
  26752. var baseGlyphName = StandardEncoding[seac[2]];
  26753. var accentGlyphName = StandardEncoding[seac[3]];
  26754. var baseGlyphId = charset.indexOf(baseGlyphName);
  26755. var accentGlyphId = charset.indexOf(accentGlyphName);
  26756. if (baseGlyphId < 0 || accentGlyphId < 0) {
  26757. continue;
  26758. }
  26759. var accentOffset = {
  26760. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  26761. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  26762. };
  26763. var charCodes = getCharCodes(mapping, glyphId);
  26764. if (!charCodes) {
  26765. // There's no point in mapping it if the char code was never mapped
  26766. // to begin with.
  26767. continue;
  26768. }
  26769. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  26770. var charCode = charCodes[i];
  26771. // Find a fontCharCode that maps to the base and accent glyphs.
  26772. // If one doesn't exists, create it.
  26773. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  26774. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  26775. baseGlyphId);
  26776. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  26777. accentGlyphId);
  26778. seacMap[charCode] = {
  26779. baseFontCharCode: baseFontCharCode,
  26780. accentFontCharCode: accentFontCharCode,
  26781. accentOffset: accentOffset
  26782. };
  26783. }
  26784. }
  26785. properties.seacMap = seacMap;
  26786. }
  26787. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  26788. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  26789. // PostScript Font Program
  26790. builder.addTable('CFF ', font.data);
  26791. // OS/2 and Windows Specific metrics
  26792. builder.addTable('OS/2', createOS2Table(properties,
  26793. newMapping.charCodeToGlyphId));
  26794. // Character to glyphs mapping
  26795. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId,
  26796. numGlyphs));
  26797. // Font header
  26798. builder.addTable('head',
  26799. '\x00\x01\x00\x00' + // Version number
  26800. '\x00\x00\x10\x00' + // fontRevision
  26801. '\x00\x00\x00\x00' + // checksumAdjustement
  26802. '\x5F\x0F\x3C\xF5' + // magicNumber
  26803. '\x00\x00' + // Flags
  26804. safeString16(unitsPerEm) + // unitsPerEM
  26805. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  26806. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  26807. '\x00\x00' + // xMin
  26808. safeString16(properties.descent) + // yMin
  26809. '\x0F\xFF' + // xMax
  26810. safeString16(properties.ascent) + // yMax
  26811. string16(properties.italicAngle ? 2 : 0) + // macStyle
  26812. '\x00\x11' + // lowestRecPPEM
  26813. '\x00\x00' + // fontDirectionHint
  26814. '\x00\x00' + // indexToLocFormat
  26815. '\x00\x00'); // glyphDataFormat
  26816. // Horizontal header
  26817. builder.addTable('hhea',
  26818. '\x00\x01\x00\x00' + // Version number
  26819. safeString16(properties.ascent) + // Typographic Ascent
  26820. safeString16(properties.descent) + // Typographic Descent
  26821. '\x00\x00' + // Line Gap
  26822. '\xFF\xFF' + // advanceWidthMax
  26823. '\x00\x00' + // minLeftSidebearing
  26824. '\x00\x00' + // minRightSidebearing
  26825. '\x00\x00' + // xMaxExtent
  26826. safeString16(properties.capHeight) + // caretSlopeRise
  26827. safeString16(Math.tan(properties.italicAngle) *
  26828. properties.xHeight) + // caretSlopeRun
  26829. '\x00\x00' + // caretOffset
  26830. '\x00\x00' + // -reserved-
  26831. '\x00\x00' + // -reserved-
  26832. '\x00\x00' + // -reserved-
  26833. '\x00\x00' + // -reserved-
  26834. '\x00\x00' + // metricDataFormat
  26835. string16(numGlyphs)); // Number of HMetrics
  26836. // Horizontal metrics
  26837. builder.addTable('hmtx', (function fontFieldsHmtx() {
  26838. var charstrings = font.charstrings;
  26839. var cffWidths = font.cff ? font.cff.widths : null;
  26840. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  26841. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  26842. var width = 0;
  26843. if (charstrings) {
  26844. var charstring = charstrings[i - 1];
  26845. width = 'width' in charstring ? charstring.width : 0;
  26846. } else if (cffWidths) {
  26847. width = Math.ceil(cffWidths[i] || 0);
  26848. }
  26849. hmtx += string16(width) + string16(0);
  26850. }
  26851. return hmtx;
  26852. })());
  26853. // Maximum profile
  26854. builder.addTable('maxp',
  26855. '\x00\x00\x50\x00' + // Version number
  26856. string16(numGlyphs)); // Num of glyphs
  26857. // Naming tables
  26858. builder.addTable('name', createNameTable(fontName));
  26859. // PostScript informations
  26860. builder.addTable('post', createPostTable(properties));
  26861. return builder.toArray();
  26862. },
  26863. /**
  26864. * Builds a char code to unicode map based on section 9.10 of the spec.
  26865. * @param {Object} properties Font properties object.
  26866. * @return {Object} A ToUnicodeMap object.
  26867. */
  26868. buildToUnicode: function Font_buildToUnicode(properties) {
  26869. // Section 9.10.2 Mapping Character Codes to Unicode Values
  26870. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  26871. return properties.toUnicode;
  26872. }
  26873. // According to the spec if the font is a simple font we should only map
  26874. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  26875. // the differences array only contains adobe standard or symbol set names,
  26876. // in pratice it seems better to always try to create a toUnicode
  26877. // map based of the default encoding.
  26878. var toUnicode, charcode;
  26879. if (!properties.composite /* is simple font */) {
  26880. toUnicode = [];
  26881. var encoding = properties.defaultEncoding.slice();
  26882. var baseEncodingName = properties.baseEncodingName;
  26883. // Merge in the differences array.
  26884. var differences = properties.differences;
  26885. for (charcode in differences) {
  26886. encoding[charcode] = differences[charcode];
  26887. }
  26888. var glyphsUnicodeMap = getGlyphsUnicode();
  26889. for (charcode in encoding) {
  26890. // a) Map the character code to a character name.
  26891. var glyphName = encoding[charcode];
  26892. // b) Look up the character name in the Adobe Glyph List (see the
  26893. // Bibliography) to obtain the corresponding Unicode value.
  26894. if (glyphName === '') {
  26895. continue;
  26896. } else if (glyphsUnicodeMap[glyphName] === undefined) {
  26897. // (undocumented) c) Few heuristics to recognize unknown glyphs
  26898. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  26899. var code = 0;
  26900. switch (glyphName[0]) {
  26901. case 'G': // Gxx glyph
  26902. if (glyphName.length === 3) {
  26903. code = parseInt(glyphName.substr(1), 16);
  26904. }
  26905. break;
  26906. case 'g': // g00xx glyph
  26907. if (glyphName.length === 5) {
  26908. code = parseInt(glyphName.substr(1), 16);
  26909. }
  26910. break;
  26911. case 'C': // Cddd glyph
  26912. case 'c': // cddd glyph
  26913. if (glyphName.length >= 3) {
  26914. code = +glyphName.substr(1);
  26915. }
  26916. break;
  26917. }
  26918. if (code) {
  26919. // If |baseEncodingName| is one the predefined encodings,
  26920. // and |code| equals |charcode|, using the glyph defined in the
  26921. // baseEncoding seems to yield a better |toUnicode| mapping
  26922. // (fixes issue 5070).
  26923. if (baseEncodingName && code === +charcode) {
  26924. var baseEncoding = getEncoding(baseEncodingName);
  26925. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  26926. toUnicode[charcode] =
  26927. String.fromCharCode(glyphsUnicodeMap[glyphName]);
  26928. continue;
  26929. }
  26930. }
  26931. toUnicode[charcode] = String.fromCharCode(code);
  26932. }
  26933. continue;
  26934. }
  26935. toUnicode[charcode] =
  26936. String.fromCharCode(glyphsUnicodeMap[glyphName]);
  26937. }
  26938. return new ToUnicodeMap(toUnicode);
  26939. }
  26940. // If the font is a composite font that uses one of the predefined CMaps
  26941. // listed in Table 118 (except Identity–H and Identity–V) or whose
  26942. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  26943. // Adobe-Korea1 character collection:
  26944. if (properties.composite && (
  26945. (properties.cMap.builtInCMap &&
  26946. !(properties.cMap instanceof IdentityCMap)) ||
  26947. (properties.cidSystemInfo.registry === 'Adobe' &&
  26948. (properties.cidSystemInfo.ordering === 'GB1' ||
  26949. properties.cidSystemInfo.ordering === 'CNS1' ||
  26950. properties.cidSystemInfo.ordering === 'Japan1' ||
  26951. properties.cidSystemInfo.ordering === 'Korea1')))) {
  26952. // Then:
  26953. // a) Map the character code to a character identifier (CID) according
  26954. // to the font’s CMap.
  26955. // b) Obtain the registry and ordering of the character collection used
  26956. // by the font’s CMap (for example, Adobe and Japan1) from its
  26957. // CIDSystemInfo dictionary.
  26958. var registry = properties.cidSystemInfo.registry;
  26959. var ordering = properties.cidSystemInfo.ordering;
  26960. // c) Construct a second CMap name by concatenating the registry and
  26961. // ordering obtained in step (b) in the format registry–ordering–UCS2
  26962. // (for example, Adobe–Japan1–UCS2).
  26963. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  26964. // d) Obtain the CMap with the name constructed in step (c) (available
  26965. // from the ASN Web site; see the Bibliography).
  26966. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  26967. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  26968. var cMap = properties.cMap;
  26969. toUnicode = [];
  26970. cMap.forEach(function(charcode, cid) {
  26971. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  26972. // e) Map the CID obtained in step (a) according to the CMap obtained
  26973. // in step (d), producing a Unicode value.
  26974. var ucs2 = ucs2CMap.lookup(cid);
  26975. if (ucs2) {
  26976. toUnicode[charcode] =
  26977. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  26978. ucs2.charCodeAt(1));
  26979. }
  26980. });
  26981. return new ToUnicodeMap(toUnicode);
  26982. }
  26983. // The viewer's choice, just use an identity map.
  26984. return new IdentityToUnicodeMap(properties.firstChar,
  26985. properties.lastChar);
  26986. },
  26987. get spaceWidth() {
  26988. if ('_shadowWidth' in this) {
  26989. return this._shadowWidth;
  26990. }
  26991. // trying to estimate space character width
  26992. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  26993. var width;
  26994. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  26995. var glyphName = possibleSpaceReplacements[i];
  26996. // if possible, getting width by glyph name
  26997. if (glyphName in this.widths) {
  26998. width = this.widths[glyphName];
  26999. break;
  27000. }
  27001. var glyphsUnicodeMap = getGlyphsUnicode();
  27002. var glyphUnicode = glyphsUnicodeMap[glyphName];
  27003. // finding the charcode via unicodeToCID map
  27004. var charcode = 0;
  27005. if (this.composite) {
  27006. if (this.cMap.contains(glyphUnicode)) {
  27007. charcode = this.cMap.lookup(glyphUnicode);
  27008. }
  27009. }
  27010. // ... via toUnicode map
  27011. if (!charcode && this.toUnicode) {
  27012. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  27013. }
  27014. // setting it to unicode if negative or undefined
  27015. if (charcode <= 0) {
  27016. charcode = glyphUnicode;
  27017. }
  27018. // trying to get width via charcode
  27019. width = this.widths[charcode];
  27020. if (width) {
  27021. break; // the non-zero width found
  27022. }
  27023. }
  27024. width = width || this.defaultWidth;
  27025. // Do not shadow the property here. See discussion:
  27026. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  27027. this._shadowWidth = width;
  27028. return width;
  27029. },
  27030. charToGlyph: function Font_charToGlyph(charcode, isSpace) {
  27031. var fontCharCode, width, operatorListId;
  27032. var widthCode = charcode;
  27033. if (this.cMap && this.cMap.contains(charcode)) {
  27034. widthCode = this.cMap.lookup(charcode);
  27035. }
  27036. width = this.widths[widthCode];
  27037. width = isNum(width) ? width : this.defaultWidth;
  27038. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  27039. var unicode = this.toUnicode.get(charcode) || charcode;
  27040. if (typeof unicode === 'number') {
  27041. unicode = String.fromCharCode(unicode);
  27042. }
  27043. var isInFont = charcode in this.toFontChar;
  27044. // First try the toFontChar map, if it's not there then try falling
  27045. // back to the char code.
  27046. fontCharCode = this.toFontChar[charcode] || charcode;
  27047. if (this.missingFile) {
  27048. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  27049. }
  27050. if (this.isType3Font) {
  27051. // Font char code in this case is actually a glyph name.
  27052. operatorListId = fontCharCode;
  27053. }
  27054. var accent = null;
  27055. if (this.seacMap && this.seacMap[charcode]) {
  27056. isInFont = true;
  27057. var seac = this.seacMap[charcode];
  27058. fontCharCode = seac.baseFontCharCode;
  27059. accent = {
  27060. fontChar: String.fromCharCode(seac.accentFontCharCode),
  27061. offset: seac.accentOffset
  27062. };
  27063. }
  27064. var fontChar = String.fromCharCode(fontCharCode);
  27065. var glyph = this.glyphCache[charcode];
  27066. if (!glyph ||
  27067. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  27068. operatorListId, isSpace, isInFont)) {
  27069. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  27070. operatorListId, isSpace, isInFont);
  27071. this.glyphCache[charcode] = glyph;
  27072. }
  27073. return glyph;
  27074. },
  27075. charsToGlyphs: function Font_charsToGlyphs(chars) {
  27076. var charsCache = this.charsCache;
  27077. var glyphs, glyph, charcode;
  27078. // if we translated this string before, just grab it from the cache
  27079. if (charsCache) {
  27080. glyphs = charsCache[chars];
  27081. if (glyphs) {
  27082. return glyphs;
  27083. }
  27084. }
  27085. // lazily create the translation cache
  27086. if (!charsCache) {
  27087. charsCache = this.charsCache = Object.create(null);
  27088. }
  27089. glyphs = [];
  27090. var charsCacheKey = chars;
  27091. var i = 0, ii;
  27092. if (this.cMap) {
  27093. // composite fonts have multi-byte strings convert the string from
  27094. // single-byte to multi-byte
  27095. var c = Object.create(null);
  27096. while (i < chars.length) {
  27097. this.cMap.readCharCode(chars, i, c);
  27098. charcode = c.charcode;
  27099. var length = c.length;
  27100. i += length;
  27101. // Space is char with code 0x20 and length 1 in multiple-byte codes.
  27102. var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
  27103. glyph = this.charToGlyph(charcode, isSpace);
  27104. glyphs.push(glyph);
  27105. }
  27106. } else {
  27107. for (i = 0, ii = chars.length; i < ii; ++i) {
  27108. charcode = chars.charCodeAt(i);
  27109. glyph = this.charToGlyph(charcode, charcode === 0x20);
  27110. glyphs.push(glyph);
  27111. }
  27112. }
  27113. // Enter the translated string into the cache
  27114. return (charsCache[charsCacheKey] = glyphs);
  27115. }
  27116. };
  27117. return Font;
  27118. })();
  27119. var ErrorFont = (function ErrorFontClosure() {
  27120. function ErrorFont(error) {
  27121. this.error = error;
  27122. this.loadedName = 'g_font_error';
  27123. this.loading = false;
  27124. }
  27125. ErrorFont.prototype = {
  27126. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  27127. return [];
  27128. },
  27129. exportData: function ErrorFont_exportData() {
  27130. return {error: this.error};
  27131. }
  27132. };
  27133. return ErrorFont;
  27134. })();
  27135. /**
  27136. * Shared logic for building a char code to glyph id mapping for Type1 and
  27137. * simple CFF fonts. See section 9.6.6.2 of the spec.
  27138. * @param {Object} properties Font properties object.
  27139. * @param {Object} builtInEncoding The encoding contained within the actual font
  27140. * data.
  27141. * @param {Array} Array of glyph names where the index is the glyph ID.
  27142. * @returns {Object} A char code to glyph ID map.
  27143. */
  27144. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  27145. var charCodeToGlyphId = Object.create(null);
  27146. var glyphId, charCode, baseEncoding;
  27147. if (properties.baseEncodingName) {
  27148. // If a valid base encoding name was used, the mapping is initialized with
  27149. // that.
  27150. baseEncoding = getEncoding(properties.baseEncodingName);
  27151. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  27152. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  27153. if (glyphId >= 0) {
  27154. charCodeToGlyphId[charCode] = glyphId;
  27155. } else {
  27156. charCodeToGlyphId[charCode] = 0; // notdef
  27157. }
  27158. }
  27159. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  27160. // For a symbolic font the encoding should be the fonts built-in
  27161. // encoding.
  27162. for (charCode in builtInEncoding) {
  27163. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  27164. }
  27165. } else {
  27166. // For non-symbolic fonts that don't have a base encoding the standard
  27167. // encoding should be used.
  27168. baseEncoding = StandardEncoding;
  27169. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  27170. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  27171. if (glyphId >= 0) {
  27172. charCodeToGlyphId[charCode] = glyphId;
  27173. } else {
  27174. charCodeToGlyphId[charCode] = 0; // notdef
  27175. }
  27176. }
  27177. }
  27178. // Lastly, merge in the differences.
  27179. var differences = properties.differences;
  27180. if (differences) {
  27181. for (charCode in differences) {
  27182. var glyphName = differences[charCode];
  27183. glyphId = glyphNames.indexOf(glyphName);
  27184. if (glyphId >= 0) {
  27185. charCodeToGlyphId[charCode] = glyphId;
  27186. } else {
  27187. charCodeToGlyphId[charCode] = 0; // notdef
  27188. }
  27189. }
  27190. }
  27191. return charCodeToGlyphId;
  27192. }
  27193. /*
  27194. * CharStrings are encoded following the the CharString Encoding sequence
  27195. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  27196. * The value in a byte indicates a command, a number, or subsequent bytes
  27197. * that are to be interpreted in a special way.
  27198. *
  27199. * CharString Number Encoding:
  27200. * A CharString byte containing the values from 32 through 255 inclusive
  27201. * indicate an integer. These values are decoded in four ranges.
  27202. *
  27203. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  27204. * indicate the integer v - 139. Thus, the integer values from -107 through
  27205. * 107 inclusive may be encoded in single byte.
  27206. *
  27207. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  27208. * indicates an integer involving the next byte, w, according to the formula:
  27209. * [(v - 247) x 256] + w + 108
  27210. *
  27211. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  27212. * indicates an integer involving the next byte, w, according to the formula:
  27213. * -[(v - 251) * 256] - w - 108
  27214. *
  27215. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  27216. * are a two complement signed integer. The first of these bytes contains the
  27217. * highest order bits, the second byte contains the next higher order bits
  27218. * and the fourth byte contain the lowest order bits.
  27219. *
  27220. *
  27221. * CharString Command Encoding:
  27222. * CharStrings commands are encoded in 1 or 2 bytes.
  27223. *
  27224. * Single byte commands are encoded in 1 byte that contains a value between
  27225. * 0 and 31 inclusive.
  27226. * If a command byte contains the value 12, then the value in the next byte
  27227. * indicates a command. This "escape" mechanism allows many extra commands
  27228. * to be encoded and this encoding technique helps to minimize the length of
  27229. * the charStrings.
  27230. */
  27231. var Type1CharString = (function Type1CharStringClosure() {
  27232. var COMMAND_MAP = {
  27233. 'hstem': [1],
  27234. 'vstem': [3],
  27235. 'vmoveto': [4],
  27236. 'rlineto': [5],
  27237. 'hlineto': [6],
  27238. 'vlineto': [7],
  27239. 'rrcurveto': [8],
  27240. 'callsubr': [10],
  27241. 'flex': [12, 35],
  27242. 'drop' : [12, 18],
  27243. 'endchar': [14],
  27244. 'rmoveto': [21],
  27245. 'hmoveto': [22],
  27246. 'vhcurveto': [30],
  27247. 'hvcurveto': [31]
  27248. };
  27249. function Type1CharString() {
  27250. this.width = 0;
  27251. this.lsb = 0;
  27252. this.flexing = false;
  27253. this.output = [];
  27254. this.stack = [];
  27255. }
  27256. Type1CharString.prototype = {
  27257. convert: function Type1CharString_convert(encoded, subrs) {
  27258. var count = encoded.length;
  27259. var error = false;
  27260. var wx, sbx, subrNumber;
  27261. for (var i = 0; i < count; i++) {
  27262. var value = encoded[i];
  27263. if (value < 32) {
  27264. if (value === 12) {
  27265. value = (value << 8) + encoded[++i];
  27266. }
  27267. switch (value) {
  27268. case 1: // hstem
  27269. if (!HINTING_ENABLED) {
  27270. this.stack = [];
  27271. break;
  27272. }
  27273. error = this.executeCommand(2, COMMAND_MAP.hstem);
  27274. break;
  27275. case 3: // vstem
  27276. if (!HINTING_ENABLED) {
  27277. this.stack = [];
  27278. break;
  27279. }
  27280. error = this.executeCommand(2, COMMAND_MAP.vstem);
  27281. break;
  27282. case 4: // vmoveto
  27283. if (this.flexing) {
  27284. if (this.stack.length < 1) {
  27285. error = true;
  27286. break;
  27287. }
  27288. // Add the dx for flex and but also swap the values so they are
  27289. // the right order.
  27290. var dy = this.stack.pop();
  27291. this.stack.push(0, dy);
  27292. break;
  27293. }
  27294. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  27295. break;
  27296. case 5: // rlineto
  27297. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  27298. break;
  27299. case 6: // hlineto
  27300. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  27301. break;
  27302. case 7: // vlineto
  27303. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  27304. break;
  27305. case 8: // rrcurveto
  27306. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  27307. break;
  27308. case 9: // closepath
  27309. // closepath is a Type1 command that does not take argument and is
  27310. // useless in Type2 and it can simply be ignored.
  27311. this.stack = [];
  27312. break;
  27313. case 10: // callsubr
  27314. if (this.stack.length < 1) {
  27315. error = true;
  27316. break;
  27317. }
  27318. subrNumber = this.stack.pop();
  27319. error = this.convert(subrs[subrNumber], subrs);
  27320. break;
  27321. case 11: // return
  27322. return error;
  27323. case 13: // hsbw
  27324. if (this.stack.length < 2) {
  27325. error = true;
  27326. break;
  27327. }
  27328. // To convert to type2 we have to move the width value to the
  27329. // first part of the charstring and then use hmoveto with lsb.
  27330. wx = this.stack.pop();
  27331. sbx = this.stack.pop();
  27332. this.lsb = sbx;
  27333. this.width = wx;
  27334. this.stack.push(wx, sbx);
  27335. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  27336. break;
  27337. case 14: // endchar
  27338. this.output.push(COMMAND_MAP.endchar[0]);
  27339. break;
  27340. case 21: // rmoveto
  27341. if (this.flexing) {
  27342. break;
  27343. }
  27344. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  27345. break;
  27346. case 22: // hmoveto
  27347. if (this.flexing) {
  27348. // Add the dy for flex.
  27349. this.stack.push(0);
  27350. break;
  27351. }
  27352. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  27353. break;
  27354. case 30: // vhcurveto
  27355. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  27356. break;
  27357. case 31: // hvcurveto
  27358. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  27359. break;
  27360. case (12 << 8) + 0: // dotsection
  27361. // dotsection is a Type1 command to specify some hinting feature
  27362. // for dots that do not take a parameter and it can safely be
  27363. // ignored for Type2.
  27364. this.stack = [];
  27365. break;
  27366. case (12 << 8) + 1: // vstem3
  27367. if (!HINTING_ENABLED) {
  27368. this.stack = [];
  27369. break;
  27370. }
  27371. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  27372. // multiple parameters, so instead of returning [vh]stem3 take a
  27373. // shortcut and return [vhstem] instead.
  27374. error = this.executeCommand(2, COMMAND_MAP.vstem);
  27375. break;
  27376. case (12 << 8) + 2: // hstem3
  27377. if (!HINTING_ENABLED) {
  27378. this.stack = [];
  27379. break;
  27380. }
  27381. // See vstem3.
  27382. error = this.executeCommand(2, COMMAND_MAP.hstem);
  27383. break;
  27384. case (12 << 8) + 6: // seac
  27385. // seac is like type 2's special endchar but it doesn't use the
  27386. // first argument asb, so remove it.
  27387. if (SEAC_ANALYSIS_ENABLED) {
  27388. this.seac = this.stack.splice(-4, 4);
  27389. error = this.executeCommand(0, COMMAND_MAP.endchar);
  27390. } else {
  27391. error = this.executeCommand(4, COMMAND_MAP.endchar);
  27392. }
  27393. break;
  27394. case (12 << 8) + 7: // sbw
  27395. if (this.stack.length < 4) {
  27396. error = true;
  27397. break;
  27398. }
  27399. // To convert to type2 we have to move the width value to the
  27400. // first part of the charstring and then use rmoveto with
  27401. // (dx, dy). The height argument will not be used for vmtx and
  27402. // vhea tables reconstruction -- ignoring it.
  27403. var wy = this.stack.pop();
  27404. wx = this.stack.pop();
  27405. var sby = this.stack.pop();
  27406. sbx = this.stack.pop();
  27407. this.lsb = sbx;
  27408. this.width = wx;
  27409. this.stack.push(wx, sbx, sby);
  27410. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  27411. break;
  27412. case (12 << 8) + 12: // div
  27413. if (this.stack.length < 2) {
  27414. error = true;
  27415. break;
  27416. }
  27417. var num2 = this.stack.pop();
  27418. var num1 = this.stack.pop();
  27419. this.stack.push(num1 / num2);
  27420. break;
  27421. case (12 << 8) + 16: // callothersubr
  27422. if (this.stack.length < 2) {
  27423. error = true;
  27424. break;
  27425. }
  27426. subrNumber = this.stack.pop();
  27427. var numArgs = this.stack.pop();
  27428. if (subrNumber === 0 && numArgs === 3) {
  27429. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  27430. this.stack.push(
  27431. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  27432. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  27433. flexArgs[4], // bcp2x
  27434. flexArgs[5], // bcp2y
  27435. flexArgs[6], // p2x
  27436. flexArgs[7], // p2y
  27437. flexArgs[8], // bcp3x
  27438. flexArgs[9], // bcp3y
  27439. flexArgs[10], // bcp4x
  27440. flexArgs[11], // bcp4y
  27441. flexArgs[12], // p3x
  27442. flexArgs[13], // p3y
  27443. flexArgs[14] // flexDepth
  27444. // 15 = finalx unused by flex
  27445. // 16 = finaly unused by flex
  27446. );
  27447. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  27448. this.flexing = false;
  27449. this.stack.push(flexArgs[15], flexArgs[16]);
  27450. } else if (subrNumber === 1 && numArgs === 0) {
  27451. this.flexing = true;
  27452. }
  27453. break;
  27454. case (12 << 8) + 17: // pop
  27455. // Ignore this since it is only used with othersubr.
  27456. break;
  27457. case (12 << 8) + 33: // setcurrentpoint
  27458. // Ignore for now.
  27459. this.stack = [];
  27460. break;
  27461. default:
  27462. warn('Unknown type 1 charstring command of "' + value + '"');
  27463. break;
  27464. }
  27465. if (error) {
  27466. break;
  27467. }
  27468. continue;
  27469. } else if (value <= 246) {
  27470. value = value - 139;
  27471. } else if (value <= 250) {
  27472. value = ((value - 247) * 256) + encoded[++i] + 108;
  27473. } else if (value <= 254) {
  27474. value = -((value - 251) * 256) - encoded[++i] - 108;
  27475. } else {
  27476. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  27477. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  27478. }
  27479. this.stack.push(value);
  27480. }
  27481. return error;
  27482. },
  27483. executeCommand: function(howManyArgs, command, keepStack) {
  27484. var stackLength = this.stack.length;
  27485. if (howManyArgs > stackLength) {
  27486. return true;
  27487. }
  27488. var start = stackLength - howManyArgs;
  27489. for (var i = start; i < stackLength; i++) {
  27490. var value = this.stack[i];
  27491. if (value === (value | 0)) { // int
  27492. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  27493. } else { // fixed point
  27494. value = (65536 * value) | 0;
  27495. this.output.push(255,
  27496. (value >> 24) & 0xFF,
  27497. (value >> 16) & 0xFF,
  27498. (value >> 8) & 0xFF,
  27499. value & 0xFF);
  27500. }
  27501. }
  27502. this.output.push.apply(this.output, command);
  27503. if (keepStack) {
  27504. this.stack.splice(start, howManyArgs);
  27505. } else {
  27506. this.stack.length = 0;
  27507. }
  27508. return false;
  27509. }
  27510. };
  27511. return Type1CharString;
  27512. })();
  27513. /*
  27514. * Type1Parser encapsulate the needed code for parsing a Type1 font
  27515. * program. Some of its logic depends on the Type2 charstrings
  27516. * structure.
  27517. * Note: this doesn't really parse the font since that would require evaluation
  27518. * of PostScript, but it is possible in most cases to extract what we need
  27519. * without a full parse.
  27520. */
  27521. var Type1Parser = (function Type1ParserClosure() {
  27522. /*
  27523. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  27524. * of Plaintext Bytes. The function took a key as a parameter which can be
  27525. * for decrypting the eexec block of for decoding charStrings.
  27526. */
  27527. var EEXEC_ENCRYPT_KEY = 55665;
  27528. var CHAR_STRS_ENCRYPT_KEY = 4330;
  27529. function isHexDigit(code) {
  27530. return code >= 48 && code <= 57 || // '0'-'9'
  27531. code >= 65 && code <= 70 || // 'A'-'F'
  27532. code >= 97 && code <= 102; // 'a'-'f'
  27533. }
  27534. function decrypt(data, key, discardNumber) {
  27535. if (discardNumber >= data.length) {
  27536. return new Uint8Array(0);
  27537. }
  27538. var r = key | 0, c1 = 52845, c2 = 22719, i, j;
  27539. for (i = 0; i < discardNumber; i++) {
  27540. r = ((data[i] + r) * c1 + c2) & ((1 << 16) - 1);
  27541. }
  27542. var count = data.length - discardNumber;
  27543. var decrypted = new Uint8Array(count);
  27544. for (i = discardNumber, j = 0; j < count; i++, j++) {
  27545. var value = data[i];
  27546. decrypted[j] = value ^ (r >> 8);
  27547. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  27548. }
  27549. return decrypted;
  27550. }
  27551. function decryptAscii(data, key, discardNumber) {
  27552. var r = key | 0, c1 = 52845, c2 = 22719;
  27553. var count = data.length, maybeLength = count >>> 1;
  27554. var decrypted = new Uint8Array(maybeLength);
  27555. var i, j;
  27556. for (i = 0, j = 0; i < count; i++) {
  27557. var digit1 = data[i];
  27558. if (!isHexDigit(digit1)) {
  27559. continue;
  27560. }
  27561. i++;
  27562. var digit2;
  27563. while (i < count && !isHexDigit(digit2 = data[i])) {
  27564. i++;
  27565. }
  27566. if (i < count) {
  27567. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  27568. decrypted[j++] = value ^ (r >> 8);
  27569. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  27570. }
  27571. }
  27572. return Array.prototype.slice.call(decrypted, discardNumber, j);
  27573. }
  27574. function isSpecial(c) {
  27575. return c === 0x2F || // '/'
  27576. c === 0x5B || c === 0x5D || // '[', ']'
  27577. c === 0x7B || c === 0x7D || // '{', '}'
  27578. c === 0x28 || c === 0x29; // '(', ')'
  27579. }
  27580. function Type1Parser(stream, encrypted) {
  27581. if (encrypted) {
  27582. var data = stream.getBytes();
  27583. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  27584. isHexDigit(data[2]) && isHexDigit(data[3]));
  27585. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  27586. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  27587. }
  27588. this.stream = stream;
  27589. this.nextChar();
  27590. }
  27591. Type1Parser.prototype = {
  27592. readNumberArray: function Type1Parser_readNumberArray() {
  27593. this.getToken(); // read '[' or '{' (arrays can start with either)
  27594. var array = [];
  27595. while (true) {
  27596. var token = this.getToken();
  27597. if (token === null || token === ']' || token === '}') {
  27598. break;
  27599. }
  27600. array.push(parseFloat(token || 0));
  27601. }
  27602. return array;
  27603. },
  27604. readNumber: function Type1Parser_readNumber() {
  27605. var token = this.getToken();
  27606. return parseFloat(token || 0);
  27607. },
  27608. readInt: function Type1Parser_readInt() {
  27609. // Use '| 0' to prevent setting a double into length such as the double
  27610. // does not flow into the loop variable.
  27611. var token = this.getToken();
  27612. return parseInt(token || 0, 10) | 0;
  27613. },
  27614. readBoolean: function Type1Parser_readBoolean() {
  27615. var token = this.getToken();
  27616. // Use 1 and 0 since that's what type2 charstrings use.
  27617. return token === 'true' ? 1 : 0;
  27618. },
  27619. nextChar : function Type1_nextChar() {
  27620. return (this.currentChar = this.stream.getByte());
  27621. },
  27622. getToken: function Type1Parser_getToken() {
  27623. // Eat whitespace and comments.
  27624. var comment = false;
  27625. var ch = this.currentChar;
  27626. while (true) {
  27627. if (ch === -1) {
  27628. return null;
  27629. }
  27630. if (comment) {
  27631. if (ch === 0x0A || ch === 0x0D) {
  27632. comment = false;
  27633. }
  27634. } else if (ch === 0x25) { // '%'
  27635. comment = true;
  27636. } else if (!Lexer.isSpace(ch)) {
  27637. break;
  27638. }
  27639. ch = this.nextChar();
  27640. }
  27641. if (isSpecial(ch)) {
  27642. this.nextChar();
  27643. return String.fromCharCode(ch);
  27644. }
  27645. var token = '';
  27646. do {
  27647. token += String.fromCharCode(ch);
  27648. ch = this.nextChar();
  27649. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  27650. return token;
  27651. },
  27652. /*
  27653. * Returns an object containing a Subrs array and a CharStrings
  27654. * array extracted from and eexec encrypted block of data
  27655. */
  27656. extractFontProgram: function Type1Parser_extractFontProgram() {
  27657. var stream = this.stream;
  27658. var subrs = [], charstrings = [];
  27659. var privateData = Object.create(null);
  27660. privateData['lenIV'] = 4;
  27661. var program = {
  27662. subrs: [],
  27663. charstrings: [],
  27664. properties: {
  27665. 'privateData': privateData
  27666. }
  27667. };
  27668. var token, length, data, lenIV, encoded;
  27669. while ((token = this.getToken()) !== null) {
  27670. if (token !== '/') {
  27671. continue;
  27672. }
  27673. token = this.getToken();
  27674. switch (token) {
  27675. case 'CharStrings':
  27676. // The number immediately following CharStrings must be greater or
  27677. // equal to the number of CharStrings.
  27678. this.getToken();
  27679. this.getToken(); // read in 'dict'
  27680. this.getToken(); // read in 'dup'
  27681. this.getToken(); // read in 'begin'
  27682. while(true) {
  27683. token = this.getToken();
  27684. if (token === null || token === 'end') {
  27685. break;
  27686. }
  27687. if (token !== '/') {
  27688. continue;
  27689. }
  27690. var glyph = this.getToken();
  27691. length = this.readInt();
  27692. this.getToken(); // read in 'RD' or '-|'
  27693. data = stream.makeSubStream(stream.pos, length);
  27694. lenIV = program.properties.privateData['lenIV'];
  27695. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  27696. // Skip past the required space and binary data.
  27697. stream.skip(length);
  27698. this.nextChar();
  27699. token = this.getToken(); // read in 'ND' or '|-'
  27700. if (token === 'noaccess') {
  27701. this.getToken(); // read in 'def'
  27702. }
  27703. charstrings.push({
  27704. glyph: glyph,
  27705. encoded: encoded
  27706. });
  27707. }
  27708. break;
  27709. case 'Subrs':
  27710. var num = this.readInt();
  27711. this.getToken(); // read in 'array'
  27712. while ((token = this.getToken()) === 'dup') {
  27713. var index = this.readInt();
  27714. length = this.readInt();
  27715. this.getToken(); // read in 'RD' or '-|'
  27716. data = stream.makeSubStream(stream.pos, length);
  27717. lenIV = program.properties.privateData['lenIV'];
  27718. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  27719. // Skip past the required space and binary data.
  27720. stream.skip(length);
  27721. this.nextChar();
  27722. token = this.getToken(); // read in 'NP' or '|'
  27723. if (token === 'noaccess') {
  27724. this.getToken(); // read in 'put'
  27725. }
  27726. subrs[index] = encoded;
  27727. }
  27728. break;
  27729. case 'BlueValues':
  27730. case 'OtherBlues':
  27731. case 'FamilyBlues':
  27732. case 'FamilyOtherBlues':
  27733. var blueArray = this.readNumberArray();
  27734. // *Blue* values may contain invalid data: disables reading of
  27735. // those values when hinting is disabled.
  27736. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  27737. HINTING_ENABLED) {
  27738. program.properties.privateData[token] = blueArray;
  27739. }
  27740. break;
  27741. case 'StemSnapH':
  27742. case 'StemSnapV':
  27743. program.properties.privateData[token] = this.readNumberArray();
  27744. break;
  27745. case 'StdHW':
  27746. case 'StdVW':
  27747. program.properties.privateData[token] =
  27748. this.readNumberArray()[0];
  27749. break;
  27750. case 'BlueShift':
  27751. case 'lenIV':
  27752. case 'BlueFuzz':
  27753. case 'BlueScale':
  27754. case 'LanguageGroup':
  27755. case 'ExpansionFactor':
  27756. program.properties.privateData[token] = this.readNumber();
  27757. break;
  27758. case 'ForceBold':
  27759. program.properties.privateData[token] = this.readBoolean();
  27760. break;
  27761. }
  27762. }
  27763. for (var i = 0; i < charstrings.length; i++) {
  27764. glyph = charstrings[i].glyph;
  27765. encoded = charstrings[i].encoded;
  27766. var charString = new Type1CharString();
  27767. var error = charString.convert(encoded, subrs);
  27768. var output = charString.output;
  27769. if (error) {
  27770. // It seems when FreeType encounters an error while evaluating a glyph
  27771. // that it completely ignores the glyph so we'll mimic that behaviour
  27772. // here and put an endchar to make the validator happy.
  27773. output = [14];
  27774. }
  27775. program.charstrings.push({
  27776. glyphName: glyph,
  27777. charstring: output,
  27778. width: charString.width,
  27779. lsb: charString.lsb,
  27780. seac: charString.seac
  27781. });
  27782. }
  27783. return program;
  27784. },
  27785. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  27786. var token;
  27787. while ((token = this.getToken()) !== null) {
  27788. if (token !== '/') {
  27789. continue;
  27790. }
  27791. token = this.getToken();
  27792. switch (token) {
  27793. case 'FontMatrix':
  27794. var matrix = this.readNumberArray();
  27795. properties.fontMatrix = matrix;
  27796. break;
  27797. case 'Encoding':
  27798. var encodingArg = this.getToken();
  27799. var encoding;
  27800. if (!/^\d+$/.test(encodingArg)) {
  27801. // encoding name is specified
  27802. encoding = getEncoding(encodingArg);
  27803. } else {
  27804. encoding = [];
  27805. var size = parseInt(encodingArg, 10) | 0;
  27806. this.getToken(); // read in 'array'
  27807. for (var j = 0; j < size; j++) {
  27808. token = this.getToken();
  27809. // skipping till first dup or def (e.g. ignoring for statement)
  27810. while (token !== 'dup' && token !== 'def') {
  27811. token = this.getToken();
  27812. if (token === null) {
  27813. return; // invalid header
  27814. }
  27815. }
  27816. if (token === 'def') {
  27817. break; // read all array data
  27818. }
  27819. var index = this.readInt();
  27820. this.getToken(); // read in '/'
  27821. var glyph = this.getToken();
  27822. encoding[index] = glyph;
  27823. this.getToken(); // read the in 'put'
  27824. }
  27825. }
  27826. properties.builtInEncoding = encoding;
  27827. break;
  27828. case 'FontBBox':
  27829. var fontBBox = this.readNumberArray();
  27830. // adjusting ascent/descent
  27831. properties.ascent = fontBBox[3];
  27832. properties.descent = fontBBox[1];
  27833. properties.ascentScaled = true;
  27834. break;
  27835. }
  27836. }
  27837. }
  27838. };
  27839. return Type1Parser;
  27840. })();
  27841. /**
  27842. * The CFF class takes a Type1 file and wrap it into a
  27843. * 'Compact Font Format' which itself embed Type2 charstrings.
  27844. */
  27845. var CFFStandardStrings = [
  27846. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  27847. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  27848. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  27849. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  27850. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  27851. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  27852. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  27853. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  27854. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  27855. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  27856. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  27857. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  27858. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  27859. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  27860. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  27861. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  27862. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  27863. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  27864. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  27865. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  27866. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  27867. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  27868. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  27869. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  27870. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  27871. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  27872. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  27873. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  27874. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  27875. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  27876. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  27877. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  27878. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  27879. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  27880. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  27881. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  27882. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  27883. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  27884. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  27885. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  27886. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  27887. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  27888. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  27889. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  27890. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  27891. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  27892. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  27893. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  27894. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  27895. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  27896. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  27897. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  27898. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  27899. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  27900. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  27901. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  27902. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  27903. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  27904. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  27905. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  27906. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  27907. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  27908. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  27909. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  27910. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  27911. ];
  27912. // Type1Font is also a CIDFontType0.
  27913. var Type1Font = function Type1Font(name, file, properties) {
  27914. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  27915. // Also, length1 and length2 might be off by 6 bytes as well.
  27916. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  27917. var PFB_HEADER_SIZE = 6;
  27918. var headerBlockLength = properties.length1;
  27919. var eexecBlockLength = properties.length2;
  27920. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  27921. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  27922. if (pfbHeaderPresent) {
  27923. file.skip(PFB_HEADER_SIZE);
  27924. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  27925. (pfbHeader[3] << 8) | pfbHeader[2];
  27926. }
  27927. // Get the data block containing glyphs and subrs informations
  27928. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  27929. var headerBlockParser = new Type1Parser(headerBlock);
  27930. headerBlockParser.extractFontHeader(properties);
  27931. if (pfbHeaderPresent) {
  27932. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  27933. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  27934. (pfbHeader[3] << 8) | pfbHeader[2];
  27935. }
  27936. // Decrypt the data blocks and retrieve it's content
  27937. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  27938. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  27939. var data = eexecBlockParser.extractFontProgram();
  27940. for (var info in data.properties) {
  27941. properties[info] = data.properties[info];
  27942. }
  27943. var charstrings = data.charstrings;
  27944. var type2Charstrings = this.getType2Charstrings(charstrings);
  27945. var subrs = this.getType2Subrs(data.subrs);
  27946. this.charstrings = charstrings;
  27947. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  27948. subrs, properties);
  27949. this.seacs = this.getSeacs(data.charstrings);
  27950. };
  27951. Type1Font.prototype = {
  27952. get numGlyphs() {
  27953. return this.charstrings.length + 1;
  27954. },
  27955. getCharset: function Type1Font_getCharset() {
  27956. var charset = ['.notdef'];
  27957. var charstrings = this.charstrings;
  27958. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  27959. charset.push(charstrings[glyphId].glyphName);
  27960. }
  27961. return charset;
  27962. },
  27963. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  27964. var charstrings = this.charstrings;
  27965. var glyphNames = ['.notdef'], glyphId;
  27966. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  27967. glyphNames.push(charstrings[glyphId].glyphName);
  27968. }
  27969. var encoding = properties.builtInEncoding;
  27970. if (encoding) {
  27971. var builtInEncoding = Object.create(null);
  27972. for (var charCode in encoding) {
  27973. glyphId = glyphNames.indexOf(encoding[charCode]);
  27974. if (glyphId >= 0) {
  27975. builtInEncoding[charCode] = glyphId;
  27976. }
  27977. }
  27978. }
  27979. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  27980. },
  27981. getSeacs: function Type1Font_getSeacs(charstrings) {
  27982. var i, ii;
  27983. var seacMap = [];
  27984. for (i = 0, ii = charstrings.length; i < ii; i++) {
  27985. var charstring = charstrings[i];
  27986. if (charstring.seac) {
  27987. // Offset by 1 for .notdef
  27988. seacMap[i + 1] = charstring.seac;
  27989. }
  27990. }
  27991. return seacMap;
  27992. },
  27993. getType2Charstrings: function Type1Font_getType2Charstrings(
  27994. type1Charstrings) {
  27995. var type2Charstrings = [];
  27996. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  27997. type2Charstrings.push(type1Charstrings[i].charstring);
  27998. }
  27999. return type2Charstrings;
  28000. },
  28001. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  28002. var bias = 0;
  28003. var count = type1Subrs.length;
  28004. if (count < 1133) {
  28005. bias = 107;
  28006. } else if (count < 33769) {
  28007. bias = 1131;
  28008. } else {
  28009. bias = 32768;
  28010. }
  28011. // Add a bunch of empty subrs to deal with the Type2 bias
  28012. var type2Subrs = [];
  28013. var i;
  28014. for (i = 0; i < bias; i++) {
  28015. type2Subrs.push([0x0B]);
  28016. }
  28017. for (i = 0; i < count; i++) {
  28018. type2Subrs.push(type1Subrs[i]);
  28019. }
  28020. return type2Subrs;
  28021. },
  28022. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  28023. var cff = new CFF();
  28024. cff.header = new CFFHeader(1, 0, 4, 4);
  28025. cff.names = [name];
  28026. var topDict = new CFFTopDict();
  28027. // CFF strings IDs 0...390 are predefined names, so refering
  28028. // to entries in our own String INDEX starts at SID 391.
  28029. topDict.setByName('version', 391);
  28030. topDict.setByName('Notice', 392);
  28031. topDict.setByName('FullName', 393);
  28032. topDict.setByName('FamilyName', 394);
  28033. topDict.setByName('Weight', 395);
  28034. topDict.setByName('Encoding', null); // placeholder
  28035. topDict.setByName('FontMatrix', properties.fontMatrix);
  28036. topDict.setByName('FontBBox', properties.bbox);
  28037. topDict.setByName('charset', null); // placeholder
  28038. topDict.setByName('CharStrings', null); // placeholder
  28039. topDict.setByName('Private', null); // placeholder
  28040. cff.topDict = topDict;
  28041. var strings = new CFFStrings();
  28042. strings.add('Version 0.11'); // Version
  28043. strings.add('See original notice'); // Notice
  28044. strings.add(name); // FullName
  28045. strings.add(name); // FamilyName
  28046. strings.add('Medium'); // Weight
  28047. cff.strings = strings;
  28048. cff.globalSubrIndex = new CFFIndex();
  28049. var count = glyphs.length;
  28050. var charsetArray = [0];
  28051. var i, ii;
  28052. for (i = 0; i < count; i++) {
  28053. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  28054. // TODO: Insert the string and correctly map it. Previously it was
  28055. // thought mapping names that aren't in the standard strings to .notdef
  28056. // was fine, however in issue818 when mapping them all to .notdef the
  28057. // adieresis glyph no longer worked.
  28058. if (index === -1) {
  28059. index = 0;
  28060. }
  28061. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  28062. }
  28063. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  28064. var charStringsIndex = new CFFIndex();
  28065. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  28066. for (i = 0; i < count; i++) {
  28067. charStringsIndex.add(glyphs[i]);
  28068. }
  28069. cff.charStrings = charStringsIndex;
  28070. var privateDict = new CFFPrivateDict();
  28071. privateDict.setByName('Subrs', null); // placeholder
  28072. var fields = [
  28073. 'BlueValues',
  28074. 'OtherBlues',
  28075. 'FamilyBlues',
  28076. 'FamilyOtherBlues',
  28077. 'StemSnapH',
  28078. 'StemSnapV',
  28079. 'BlueShift',
  28080. 'BlueFuzz',
  28081. 'BlueScale',
  28082. 'LanguageGroup',
  28083. 'ExpansionFactor',
  28084. 'ForceBold',
  28085. 'StdHW',
  28086. 'StdVW'
  28087. ];
  28088. for (i = 0, ii = fields.length; i < ii; i++) {
  28089. var field = fields[i];
  28090. if (!(field in properties.privateData)) {
  28091. continue;
  28092. }
  28093. var value = properties.privateData[field];
  28094. if (isArray(value)) {
  28095. // All of the private dictionary array data in CFF must be stored as
  28096. // "delta-encoded" numbers.
  28097. for (var j = value.length - 1; j > 0; j--) {
  28098. value[j] -= value[j - 1]; // ... difference from previous value
  28099. }
  28100. }
  28101. privateDict.setByName(field, value);
  28102. }
  28103. cff.topDict.privateDict = privateDict;
  28104. var subrIndex = new CFFIndex();
  28105. for (i = 0, ii = subrs.length; i < ii; i++) {
  28106. subrIndex.add(subrs[i]);
  28107. }
  28108. privateDict.subrsIndex = subrIndex;
  28109. var compiler = new CFFCompiler(cff);
  28110. return compiler.compile();
  28111. }
  28112. };
  28113. var CFFFont = (function CFFFontClosure() {
  28114. function CFFFont(file, properties) {
  28115. this.properties = properties;
  28116. var parser = new CFFParser(file, properties);
  28117. this.cff = parser.parse();
  28118. var compiler = new CFFCompiler(this.cff);
  28119. this.seacs = this.cff.seacs;
  28120. try {
  28121. this.data = compiler.compile();
  28122. } catch (e) {
  28123. warn('Failed to compile font ' + properties.loadedName);
  28124. // There may have just been an issue with the compiler, set the data
  28125. // anyway and hope the font loaded.
  28126. this.data = file;
  28127. }
  28128. }
  28129. CFFFont.prototype = {
  28130. get numGlyphs() {
  28131. return this.cff.charStrings.count;
  28132. },
  28133. getCharset: function CFFFont_getCharset() {
  28134. return this.cff.charset.charset;
  28135. },
  28136. getGlyphMapping: function CFFFont_getGlyphMapping() {
  28137. var cff = this.cff;
  28138. var properties = this.properties;
  28139. var charsets = cff.charset.charset;
  28140. var charCodeToGlyphId;
  28141. var glyphId;
  28142. if (properties.composite) {
  28143. charCodeToGlyphId = Object.create(null);
  28144. if (cff.isCIDFont) {
  28145. // If the font is actually a CID font then we should use the charset
  28146. // to map CIDs to GIDs.
  28147. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  28148. var cid = charsets[glyphId];
  28149. var charCode = properties.cMap.charCodeOf(cid);
  28150. charCodeToGlyphId[charCode] = glyphId;
  28151. }
  28152. } else {
  28153. // If it is NOT actually a CID font then CIDs should be mapped
  28154. // directly to GIDs.
  28155. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  28156. charCodeToGlyphId[glyphId] = glyphId;
  28157. }
  28158. }
  28159. return charCodeToGlyphId;
  28160. }
  28161. var encoding = cff.encoding ? cff.encoding.encoding : null;
  28162. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  28163. return charCodeToGlyphId;
  28164. }
  28165. };
  28166. return CFFFont;
  28167. })();
  28168. var CFFParser = (function CFFParserClosure() {
  28169. var CharstringValidationData = [
  28170. null,
  28171. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  28172. null,
  28173. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  28174. { id: 'vmoveto', min: 1, stackClearing: true },
  28175. { id: 'rlineto', min: 2, resetStack: true },
  28176. { id: 'hlineto', min: 1, resetStack: true },
  28177. { id: 'vlineto', min: 1, resetStack: true },
  28178. { id: 'rrcurveto', min: 6, resetStack: true },
  28179. null,
  28180. { id: 'callsubr', min: 1, undefStack: true },
  28181. { id: 'return', min: 0, undefStack: true },
  28182. null, // 12
  28183. null,
  28184. { id: 'endchar', min: 0, stackClearing: true },
  28185. null,
  28186. null,
  28187. null,
  28188. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  28189. { id: 'hintmask', min: 0, stackClearing: true },
  28190. { id: 'cntrmask', min: 0, stackClearing: true },
  28191. { id: 'rmoveto', min: 2, stackClearing: true },
  28192. { id: 'hmoveto', min: 1, stackClearing: true },
  28193. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  28194. { id: 'rcurveline', min: 8, resetStack: true },
  28195. { id: 'rlinecurve', min: 8, resetStack: true },
  28196. { id: 'vvcurveto', min: 4, resetStack: true },
  28197. { id: 'hhcurveto', min: 4, resetStack: true },
  28198. null, // shortint
  28199. { id: 'callgsubr', min: 1, undefStack: true },
  28200. { id: 'vhcurveto', min: 4, resetStack: true },
  28201. { id: 'hvcurveto', min: 4, resetStack: true }
  28202. ];
  28203. var CharstringValidationData12 = [
  28204. null,
  28205. null,
  28206. null,
  28207. { id: 'and', min: 2, stackDelta: -1 },
  28208. { id: 'or', min: 2, stackDelta: -1 },
  28209. { id: 'not', min: 1, stackDelta: 0 },
  28210. null,
  28211. null,
  28212. null,
  28213. { id: 'abs', min: 1, stackDelta: 0 },
  28214. { id: 'add', min: 2, stackDelta: -1,
  28215. stackFn: function stack_div(stack, index) {
  28216. stack[index - 2] = stack[index - 2] + stack[index - 1];
  28217. }
  28218. },
  28219. { id: 'sub', min: 2, stackDelta: -1,
  28220. stackFn: function stack_div(stack, index) {
  28221. stack[index - 2] = stack[index - 2] - stack[index - 1];
  28222. }
  28223. },
  28224. { id: 'div', min: 2, stackDelta: -1,
  28225. stackFn: function stack_div(stack, index) {
  28226. stack[index - 2] = stack[index - 2] / stack[index - 1];
  28227. }
  28228. },
  28229. null,
  28230. { id: 'neg', min: 1, stackDelta: 0,
  28231. stackFn: function stack_div(stack, index) {
  28232. stack[index - 1] = -stack[index - 1];
  28233. }
  28234. },
  28235. { id: 'eq', min: 2, stackDelta: -1 },
  28236. null,
  28237. null,
  28238. { id: 'drop', min: 1, stackDelta: -1 },
  28239. null,
  28240. { id: 'put', min: 2, stackDelta: -2 },
  28241. { id: 'get', min: 1, stackDelta: 0 },
  28242. { id: 'ifelse', min: 4, stackDelta: -3 },
  28243. { id: 'random', min: 0, stackDelta: 1 },
  28244. { id: 'mul', min: 2, stackDelta: -1,
  28245. stackFn: function stack_div(stack, index) {
  28246. stack[index - 2] = stack[index - 2] * stack[index - 1];
  28247. }
  28248. },
  28249. null,
  28250. { id: 'sqrt', min: 1, stackDelta: 0 },
  28251. { id: 'dup', min: 1, stackDelta: 1 },
  28252. { id: 'exch', min: 2, stackDelta: 0 },
  28253. { id: 'index', min: 2, stackDelta: 0 },
  28254. { id: 'roll', min: 3, stackDelta: -2 },
  28255. null,
  28256. null,
  28257. null,
  28258. { id: 'hflex', min: 7, resetStack: true },
  28259. { id: 'flex', min: 13, resetStack: true },
  28260. { id: 'hflex1', min: 9, resetStack: true },
  28261. { id: 'flex1', min: 11, resetStack: true }
  28262. ];
  28263. function CFFParser(file, properties) {
  28264. this.bytes = file.getBytes();
  28265. this.properties = properties;
  28266. }
  28267. CFFParser.prototype = {
  28268. parse: function CFFParser_parse() {
  28269. var properties = this.properties;
  28270. var cff = new CFF();
  28271. this.cff = cff;
  28272. // The first five sections must be in order, all the others are reached
  28273. // via offsets contained in one of the below.
  28274. var header = this.parseHeader();
  28275. var nameIndex = this.parseIndex(header.endPos);
  28276. var topDictIndex = this.parseIndex(nameIndex.endPos);
  28277. var stringIndex = this.parseIndex(topDictIndex.endPos);
  28278. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  28279. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  28280. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  28281. cff.header = header.obj;
  28282. cff.names = this.parseNameIndex(nameIndex.obj);
  28283. cff.strings = this.parseStringIndex(stringIndex.obj);
  28284. cff.topDict = topDict;
  28285. cff.globalSubrIndex = globalSubrIndex.obj;
  28286. this.parsePrivateDict(cff.topDict);
  28287. cff.isCIDFont = topDict.hasName('ROS');
  28288. var charStringOffset = topDict.getByName('CharStrings');
  28289. var charStringIndex = this.parseIndex(charStringOffset).obj;
  28290. var fontMatrix = topDict.getByName('FontMatrix');
  28291. if (fontMatrix) {
  28292. properties.fontMatrix = fontMatrix;
  28293. }
  28294. var fontBBox = topDict.getByName('FontBBox');
  28295. if (fontBBox) {
  28296. // adjusting ascent/descent
  28297. properties.ascent = fontBBox[3];
  28298. properties.descent = fontBBox[1];
  28299. properties.ascentScaled = true;
  28300. }
  28301. var charset, encoding;
  28302. if (cff.isCIDFont) {
  28303. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  28304. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  28305. var dictRaw = fdArrayIndex.get(i);
  28306. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  28307. cff.strings);
  28308. this.parsePrivateDict(fontDict);
  28309. cff.fdArray.push(fontDict);
  28310. }
  28311. // cid fonts don't have an encoding
  28312. encoding = null;
  28313. charset = this.parseCharsets(topDict.getByName('charset'),
  28314. charStringIndex.count, cff.strings, true);
  28315. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  28316. charStringIndex.count);
  28317. } else {
  28318. charset = this.parseCharsets(topDict.getByName('charset'),
  28319. charStringIndex.count, cff.strings, false);
  28320. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  28321. properties,
  28322. cff.strings, charset.charset);
  28323. }
  28324. cff.charset = charset;
  28325. cff.encoding = encoding;
  28326. var charStringsAndSeacs = this.parseCharStrings(
  28327. charStringIndex,
  28328. topDict.privateDict.subrsIndex,
  28329. globalSubrIndex.obj,
  28330. cff.fdSelect,
  28331. cff.fdArray);
  28332. cff.charStrings = charStringsAndSeacs.charStrings;
  28333. cff.seacs = charStringsAndSeacs.seacs;
  28334. cff.widths = charStringsAndSeacs.widths;
  28335. return cff;
  28336. },
  28337. parseHeader: function CFFParser_parseHeader() {
  28338. var bytes = this.bytes;
  28339. var bytesLength = bytes.length;
  28340. var offset = 0;
  28341. // Prevent an infinite loop, by checking that the offset is within the
  28342. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  28343. while (offset < bytesLength && bytes[offset] !== 1) {
  28344. ++offset;
  28345. }
  28346. if (offset >= bytesLength) {
  28347. error('Invalid CFF header');
  28348. } else if (offset !== 0) {
  28349. info('cff data is shifted');
  28350. bytes = bytes.subarray(offset);
  28351. this.bytes = bytes;
  28352. }
  28353. var major = bytes[0];
  28354. var minor = bytes[1];
  28355. var hdrSize = bytes[2];
  28356. var offSize = bytes[3];
  28357. var header = new CFFHeader(major, minor, hdrSize, offSize);
  28358. return { obj: header, endPos: hdrSize };
  28359. },
  28360. parseDict: function CFFParser_parseDict(dict) {
  28361. var pos = 0;
  28362. function parseOperand() {
  28363. var value = dict[pos++];
  28364. if (value === 30) {
  28365. return parseFloatOperand(pos);
  28366. } else if (value === 28) {
  28367. value = dict[pos++];
  28368. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  28369. return value;
  28370. } else if (value === 29) {
  28371. value = dict[pos++];
  28372. value = (value << 8) | dict[pos++];
  28373. value = (value << 8) | dict[pos++];
  28374. value = (value << 8) | dict[pos++];
  28375. return value;
  28376. } else if (value >= 32 && value <= 246) {
  28377. return value - 139;
  28378. } else if (value >= 247 && value <= 250) {
  28379. return ((value - 247) * 256) + dict[pos++] + 108;
  28380. } else if (value >= 251 && value <= 254) {
  28381. return -((value - 251) * 256) - dict[pos++] - 108;
  28382. } else {
  28383. error('255 is not a valid DICT command');
  28384. }
  28385. return -1;
  28386. }
  28387. function parseFloatOperand() {
  28388. var str = '';
  28389. var eof = 15;
  28390. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  28391. '9', '.', 'E', 'E-', null, '-'];
  28392. var length = dict.length;
  28393. while (pos < length) {
  28394. var b = dict[pos++];
  28395. var b1 = b >> 4;
  28396. var b2 = b & 15;
  28397. if (b1 === eof) {
  28398. break;
  28399. }
  28400. str += lookup[b1];
  28401. if (b2 === eof) {
  28402. break;
  28403. }
  28404. str += lookup[b2];
  28405. }
  28406. return parseFloat(str);
  28407. }
  28408. var operands = [];
  28409. var entries = [];
  28410. pos = 0;
  28411. var end = dict.length;
  28412. while (pos < end) {
  28413. var b = dict[pos];
  28414. if (b <= 21) {
  28415. if (b === 12) {
  28416. b = (b << 8) | dict[++pos];
  28417. }
  28418. entries.push([b, operands]);
  28419. operands = [];
  28420. ++pos;
  28421. } else {
  28422. operands.push(parseOperand());
  28423. }
  28424. }
  28425. return entries;
  28426. },
  28427. parseIndex: function CFFParser_parseIndex(pos) {
  28428. var cffIndex = new CFFIndex();
  28429. var bytes = this.bytes;
  28430. var count = (bytes[pos++] << 8) | bytes[pos++];
  28431. var offsets = [];
  28432. var end = pos;
  28433. var i, ii;
  28434. if (count !== 0) {
  28435. var offsetSize = bytes[pos++];
  28436. // add 1 for offset to determine size of last object
  28437. var startPos = pos + ((count + 1) * offsetSize) - 1;
  28438. for (i = 0, ii = count + 1; i < ii; ++i) {
  28439. var offset = 0;
  28440. for (var j = 0; j < offsetSize; ++j) {
  28441. offset <<= 8;
  28442. offset += bytes[pos++];
  28443. }
  28444. offsets.push(startPos + offset);
  28445. }
  28446. end = offsets[count];
  28447. }
  28448. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  28449. var offsetStart = offsets[i];
  28450. var offsetEnd = offsets[i + 1];
  28451. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  28452. }
  28453. return {obj: cffIndex, endPos: end};
  28454. },
  28455. parseNameIndex: function CFFParser_parseNameIndex(index) {
  28456. var names = [];
  28457. for (var i = 0, ii = index.count; i < ii; ++i) {
  28458. var name = index.get(i);
  28459. // OTS doesn't allow names to be over 127 characters.
  28460. var length = Math.min(name.length, 127);
  28461. var data = [];
  28462. // OTS also only permits certain characters in the name.
  28463. for (var j = 0; j < length; ++j) {
  28464. var c = name[j];
  28465. if (j === 0 && c === 0) {
  28466. data[j] = c;
  28467. continue;
  28468. }
  28469. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  28470. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  28471. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  28472. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  28473. data[j] = 95;
  28474. continue;
  28475. }
  28476. data[j] = c;
  28477. }
  28478. names.push(bytesToString(data));
  28479. }
  28480. return names;
  28481. },
  28482. parseStringIndex: function CFFParser_parseStringIndex(index) {
  28483. var strings = new CFFStrings();
  28484. for (var i = 0, ii = index.count; i < ii; ++i) {
  28485. var data = index.get(i);
  28486. strings.add(bytesToString(data));
  28487. }
  28488. return strings;
  28489. },
  28490. createDict: function CFFParser_createDict(Type, dict, strings) {
  28491. var cffDict = new Type(strings);
  28492. for (var i = 0, ii = dict.length; i < ii; ++i) {
  28493. var pair = dict[i];
  28494. var key = pair[0];
  28495. var value = pair[1];
  28496. cffDict.setByKey(key, value);
  28497. }
  28498. return cffDict;
  28499. },
  28500. parseCharString: function CFFParser_parseCharString(state, data,
  28501. localSubrIndex,
  28502. globalSubrIndex) {
  28503. if (state.callDepth > MAX_SUBR_NESTING) {
  28504. return false;
  28505. }
  28506. var stackSize = state.stackSize;
  28507. var stack = state.stack;
  28508. var length = data.length;
  28509. for (var j = 0; j < length;) {
  28510. var value = data[j++];
  28511. var validationCommand = null;
  28512. if (value === 12) {
  28513. var q = data[j++];
  28514. if (q === 0) {
  28515. // The CFF specification state that the 'dotsection' command
  28516. // (12, 0) is deprecated and treated as a no-op, but all Type2
  28517. // charstrings processors should support them. Unfortunately
  28518. // the font sanitizer don't. As a workaround the sequence (12, 0)
  28519. // is replaced by a useless (0, hmoveto).
  28520. data[j - 2] = 139;
  28521. data[j - 1] = 22;
  28522. stackSize = 0;
  28523. } else {
  28524. validationCommand = CharstringValidationData12[q];
  28525. }
  28526. } else if (value === 28) { // number (16 bit)
  28527. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  28528. j += 2;
  28529. stackSize++;
  28530. } else if (value === 14) {
  28531. if (stackSize >= 4) {
  28532. stackSize -= 4;
  28533. if (SEAC_ANALYSIS_ENABLED) {
  28534. state.seac = stack.slice(stackSize, stackSize + 4);
  28535. return false;
  28536. }
  28537. }
  28538. validationCommand = CharstringValidationData[value];
  28539. } else if (value >= 32 && value <= 246) { // number
  28540. stack[stackSize] = value - 139;
  28541. stackSize++;
  28542. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  28543. stack[stackSize] = (value < 251 ?
  28544. ((value - 247) << 8) + data[j] + 108 :
  28545. -((value - 251) << 8) - data[j] - 108);
  28546. j++;
  28547. stackSize++;
  28548. } else if (value === 255) { // number (32 bit)
  28549. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  28550. (data[j + 2] << 8) | data[j + 3]) / 65536;
  28551. j += 4;
  28552. stackSize++;
  28553. } else if (value === 19 || value === 20) {
  28554. state.hints += stackSize >> 1;
  28555. // skipping right amount of hints flag data
  28556. j += (state.hints + 7) >> 3;
  28557. stackSize %= 2;
  28558. validationCommand = CharstringValidationData[value];
  28559. } else if (value === 10 || value === 29) {
  28560. var subrsIndex;
  28561. if (value === 10) {
  28562. subrsIndex = localSubrIndex;
  28563. } else {
  28564. subrsIndex = globalSubrIndex;
  28565. }
  28566. if (!subrsIndex) {
  28567. validationCommand = CharstringValidationData[value];
  28568. warn('Missing subrsIndex for ' + validationCommand.id);
  28569. return false;
  28570. }
  28571. var bias = 32768;
  28572. if (subrsIndex.count < 1240) {
  28573. bias = 107;
  28574. } else if (subrsIndex.count < 33900) {
  28575. bias = 1131;
  28576. }
  28577. var subrNumber = stack[--stackSize] + bias;
  28578. if (subrNumber < 0 || subrNumber >= subrsIndex.count) {
  28579. validationCommand = CharstringValidationData[value];
  28580. warn('Out of bounds subrIndex for ' + validationCommand.id);
  28581. return false;
  28582. }
  28583. state.stackSize = stackSize;
  28584. state.callDepth++;
  28585. var valid = this.parseCharString(state, subrsIndex.get(subrNumber),
  28586. localSubrIndex, globalSubrIndex);
  28587. if (!valid) {
  28588. return false;
  28589. }
  28590. state.callDepth--;
  28591. stackSize = state.stackSize;
  28592. continue;
  28593. } else if (value === 11) {
  28594. state.stackSize = stackSize;
  28595. return true;
  28596. } else {
  28597. validationCommand = CharstringValidationData[value];
  28598. }
  28599. if (validationCommand) {
  28600. if (validationCommand.stem) {
  28601. state.hints += stackSize >> 1;
  28602. }
  28603. if ('min' in validationCommand) {
  28604. if (!state.undefStack && stackSize < validationCommand.min) {
  28605. warn('Not enough parameters for ' + validationCommand.id +
  28606. '; actual: ' + stackSize +
  28607. ', expected: ' + validationCommand.min);
  28608. return false;
  28609. }
  28610. }
  28611. if (state.firstStackClearing && validationCommand.stackClearing) {
  28612. state.firstStackClearing = false;
  28613. // the optional character width can be found before the first
  28614. // stack-clearing command arguments
  28615. stackSize -= validationCommand.min;
  28616. if (stackSize >= 2 && validationCommand.stem) {
  28617. // there are even amount of arguments for stem commands
  28618. stackSize %= 2;
  28619. } else if (stackSize > 1) {
  28620. warn('Found too many parameters for stack-clearing command');
  28621. }
  28622. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  28623. state.width = stack[stackSize - 1];
  28624. }
  28625. }
  28626. if ('stackDelta' in validationCommand) {
  28627. if ('stackFn' in validationCommand) {
  28628. validationCommand.stackFn(stack, stackSize);
  28629. }
  28630. stackSize += validationCommand.stackDelta;
  28631. } else if (validationCommand.stackClearing) {
  28632. stackSize = 0;
  28633. } else if (validationCommand.resetStack) {
  28634. stackSize = 0;
  28635. state.undefStack = false;
  28636. } else if (validationCommand.undefStack) {
  28637. stackSize = 0;
  28638. state.undefStack = true;
  28639. state.firstStackClearing = false;
  28640. }
  28641. }
  28642. }
  28643. state.stackSize = stackSize;
  28644. return true;
  28645. },
  28646. parseCharStrings: function CFFParser_parseCharStrings(charStrings,
  28647. localSubrIndex,
  28648. globalSubrIndex,
  28649. fdSelect,
  28650. fdArray) {
  28651. var seacs = [];
  28652. var widths = [];
  28653. var count = charStrings.count;
  28654. for (var i = 0; i < count; i++) {
  28655. var charstring = charStrings.get(i);
  28656. var state = {
  28657. callDepth: 0,
  28658. stackSize: 0,
  28659. stack: [],
  28660. undefStack: true,
  28661. hints: 0,
  28662. firstStackClearing: true,
  28663. seac: null,
  28664. width: null
  28665. };
  28666. var valid = true;
  28667. var localSubrToUse = null;
  28668. if (fdSelect && fdArray.length) {
  28669. var fdIndex = fdSelect.getFDIndex(i);
  28670. if (fdIndex === -1) {
  28671. warn('Glyph index is not in fd select.');
  28672. valid = false;
  28673. }
  28674. if (fdIndex >= fdArray.length) {
  28675. warn('Invalid fd index for glyph index.');
  28676. valid = false;
  28677. }
  28678. if (valid) {
  28679. localSubrToUse = fdArray[fdIndex].privateDict.subrsIndex;
  28680. }
  28681. } else if (localSubrIndex) {
  28682. localSubrToUse = localSubrIndex;
  28683. }
  28684. if (valid) {
  28685. valid = this.parseCharString(state, charstring, localSubrToUse,
  28686. globalSubrIndex);
  28687. }
  28688. if (state.width !== null) {
  28689. widths[i] = state.width;
  28690. }
  28691. if (state.seac !== null) {
  28692. seacs[i] = state.seac;
  28693. }
  28694. if (!valid) {
  28695. // resetting invalid charstring to single 'endchar'
  28696. charStrings.set(i, new Uint8Array([14]));
  28697. }
  28698. }
  28699. return { charStrings: charStrings, seacs: seacs, widths: widths };
  28700. },
  28701. emptyPrivateDictionary:
  28702. function CFFParser_emptyPrivateDictionary(parentDict) {
  28703. var privateDict = this.createDict(CFFPrivateDict, [],
  28704. parentDict.strings);
  28705. parentDict.setByKey(18, [0, 0]);
  28706. parentDict.privateDict = privateDict;
  28707. },
  28708. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  28709. // no private dict, do nothing
  28710. if (!parentDict.hasName('Private')) {
  28711. this.emptyPrivateDictionary(parentDict);
  28712. return;
  28713. }
  28714. var privateOffset = parentDict.getByName('Private');
  28715. // make sure the params are formatted correctly
  28716. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  28717. parentDict.removeByName('Private');
  28718. return;
  28719. }
  28720. var size = privateOffset[0];
  28721. var offset = privateOffset[1];
  28722. // remove empty dicts or ones that refer to invalid location
  28723. if (size === 0 || offset >= this.bytes.length) {
  28724. this.emptyPrivateDictionary(parentDict);
  28725. return;
  28726. }
  28727. var privateDictEnd = offset + size;
  28728. var dictData = this.bytes.subarray(offset, privateDictEnd);
  28729. var dict = this.parseDict(dictData);
  28730. var privateDict = this.createDict(CFFPrivateDict, dict,
  28731. parentDict.strings);
  28732. parentDict.privateDict = privateDict;
  28733. // Parse the Subrs index also since it's relative to the private dict.
  28734. if (!privateDict.getByName('Subrs')) {
  28735. return;
  28736. }
  28737. var subrsOffset = privateDict.getByName('Subrs');
  28738. var relativeOffset = offset + subrsOffset;
  28739. // Validate the offset.
  28740. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  28741. this.emptyPrivateDictionary(parentDict);
  28742. return;
  28743. }
  28744. var subrsIndex = this.parseIndex(relativeOffset);
  28745. privateDict.subrsIndex = subrsIndex.obj;
  28746. },
  28747. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  28748. if (pos === 0) {
  28749. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  28750. ISOAdobeCharset);
  28751. } else if (pos === 1) {
  28752. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  28753. ExpertCharset);
  28754. } else if (pos === 2) {
  28755. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  28756. ExpertSubsetCharset);
  28757. }
  28758. var bytes = this.bytes;
  28759. var start = pos;
  28760. var format = bytes[pos++];
  28761. var charset = ['.notdef'];
  28762. var id, count, i;
  28763. // subtract 1 for the .notdef glyph
  28764. length -= 1;
  28765. switch (format) {
  28766. case 0:
  28767. for (i = 0; i < length; i++) {
  28768. id = (bytes[pos++] << 8) | bytes[pos++];
  28769. charset.push(cid ? id : strings.get(id));
  28770. }
  28771. break;
  28772. case 1:
  28773. while (charset.length <= length) {
  28774. id = (bytes[pos++] << 8) | bytes[pos++];
  28775. count = bytes[pos++];
  28776. for (i = 0; i <= count; i++) {
  28777. charset.push(cid ? id++ : strings.get(id++));
  28778. }
  28779. }
  28780. break;
  28781. case 2:
  28782. while (charset.length <= length) {
  28783. id = (bytes[pos++] << 8) | bytes[pos++];
  28784. count = (bytes[pos++] << 8) | bytes[pos++];
  28785. for (i = 0; i <= count; i++) {
  28786. charset.push(cid ? id++ : strings.get(id++));
  28787. }
  28788. }
  28789. break;
  28790. default:
  28791. error('Unknown charset format');
  28792. }
  28793. // Raw won't be needed if we actually compile the charset.
  28794. var end = pos;
  28795. var raw = bytes.subarray(start, end);
  28796. return new CFFCharset(false, format, charset, raw);
  28797. },
  28798. parseEncoding: function CFFParser_parseEncoding(pos,
  28799. properties,
  28800. strings,
  28801. charset) {
  28802. var encoding = Object.create(null);
  28803. var bytes = this.bytes;
  28804. var predefined = false;
  28805. var hasSupplement = false;
  28806. var format, i, ii;
  28807. var raw = null;
  28808. function readSupplement() {
  28809. var supplementsCount = bytes[pos++];
  28810. for (i = 0; i < supplementsCount; i++) {
  28811. var code = bytes[pos++];
  28812. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  28813. encoding[code] = charset.indexOf(strings.get(sid));
  28814. }
  28815. }
  28816. if (pos === 0 || pos === 1) {
  28817. predefined = true;
  28818. format = pos;
  28819. var baseEncoding = pos ? ExpertEncoding : StandardEncoding;
  28820. for (i = 0, ii = charset.length; i < ii; i++) {
  28821. var index = baseEncoding.indexOf(charset[i]);
  28822. if (index !== -1) {
  28823. encoding[index] = i;
  28824. }
  28825. }
  28826. } else {
  28827. var dataStart = pos;
  28828. format = bytes[pos++];
  28829. switch (format & 0x7f) {
  28830. case 0:
  28831. var glyphsCount = bytes[pos++];
  28832. for (i = 1; i <= glyphsCount; i++) {
  28833. encoding[bytes[pos++]] = i;
  28834. }
  28835. break;
  28836. case 1:
  28837. var rangesCount = bytes[pos++];
  28838. var gid = 1;
  28839. for (i = 0; i < rangesCount; i++) {
  28840. var start = bytes[pos++];
  28841. var left = bytes[pos++];
  28842. for (var j = start; j <= start + left; j++) {
  28843. encoding[j] = gid++;
  28844. }
  28845. }
  28846. break;
  28847. default:
  28848. error('Unknow encoding format: ' + format + ' in CFF');
  28849. break;
  28850. }
  28851. var dataEnd = pos;
  28852. if (format & 0x80) {
  28853. // The font sanitizer does not support CFF encoding with a
  28854. // supplement, since the encoding is not really used to map
  28855. // between gid to glyph, let's overwrite what is declared in
  28856. // the top dictionary to let the sanitizer think the font use
  28857. // StandardEncoding, that's a lie but that's ok.
  28858. bytes[dataStart] &= 0x7f;
  28859. readSupplement();
  28860. hasSupplement = true;
  28861. }
  28862. raw = bytes.subarray(dataStart, dataEnd);
  28863. }
  28864. format = format & 0x7f;
  28865. return new CFFEncoding(predefined, format, encoding, raw);
  28866. },
  28867. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  28868. var start = pos;
  28869. var bytes = this.bytes;
  28870. var format = bytes[pos++];
  28871. var fdSelect = [];
  28872. var i;
  28873. switch (format) {
  28874. case 0:
  28875. for (i = 0; i < length; ++i) {
  28876. var id = bytes[pos++];
  28877. fdSelect.push(id);
  28878. }
  28879. break;
  28880. case 3:
  28881. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  28882. for (i = 0; i < rangesCount; ++i) {
  28883. var first = (bytes[pos++] << 8) | bytes[pos++];
  28884. var fdIndex = bytes[pos++];
  28885. var next = (bytes[pos] << 8) | bytes[pos + 1];
  28886. for (var j = first; j < next; ++j) {
  28887. fdSelect.push(fdIndex);
  28888. }
  28889. }
  28890. // Advance past the sentinel(next).
  28891. pos += 2;
  28892. break;
  28893. default:
  28894. error('Unknown fdselect format ' + format);
  28895. break;
  28896. }
  28897. var end = pos;
  28898. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  28899. }
  28900. };
  28901. return CFFParser;
  28902. })();
  28903. // Compact Font Format
  28904. var CFF = (function CFFClosure() {
  28905. function CFF() {
  28906. this.header = null;
  28907. this.names = [];
  28908. this.topDict = null;
  28909. this.strings = new CFFStrings();
  28910. this.globalSubrIndex = null;
  28911. // The following could really be per font, but since we only have one font
  28912. // store them here.
  28913. this.encoding = null;
  28914. this.charset = null;
  28915. this.charStrings = null;
  28916. this.fdArray = [];
  28917. this.fdSelect = null;
  28918. this.isCIDFont = false;
  28919. }
  28920. return CFF;
  28921. })();
  28922. var CFFHeader = (function CFFHeaderClosure() {
  28923. function CFFHeader(major, minor, hdrSize, offSize) {
  28924. this.major = major;
  28925. this.minor = minor;
  28926. this.hdrSize = hdrSize;
  28927. this.offSize = offSize;
  28928. }
  28929. return CFFHeader;
  28930. })();
  28931. var CFFStrings = (function CFFStringsClosure() {
  28932. function CFFStrings() {
  28933. this.strings = [];
  28934. }
  28935. CFFStrings.prototype = {
  28936. get: function CFFStrings_get(index) {
  28937. if (index >= 0 && index <= 390) {
  28938. return CFFStandardStrings[index];
  28939. }
  28940. if (index - 391 <= this.strings.length) {
  28941. return this.strings[index - 391];
  28942. }
  28943. return CFFStandardStrings[0];
  28944. },
  28945. add: function CFFStrings_add(value) {
  28946. this.strings.push(value);
  28947. },
  28948. get count() {
  28949. return this.strings.length;
  28950. }
  28951. };
  28952. return CFFStrings;
  28953. })();
  28954. var CFFIndex = (function CFFIndexClosure() {
  28955. function CFFIndex() {
  28956. this.objects = [];
  28957. this.length = 0;
  28958. }
  28959. CFFIndex.prototype = {
  28960. add: function CFFIndex_add(data) {
  28961. this.length += data.length;
  28962. this.objects.push(data);
  28963. },
  28964. set: function CFFIndex_set(index, data) {
  28965. this.length += data.length - this.objects[index].length;
  28966. this.objects[index] = data;
  28967. },
  28968. get: function CFFIndex_get(index) {
  28969. return this.objects[index];
  28970. },
  28971. get count() {
  28972. return this.objects.length;
  28973. }
  28974. };
  28975. return CFFIndex;
  28976. })();
  28977. var CFFDict = (function CFFDictClosure() {
  28978. function CFFDict(tables, strings) {
  28979. this.keyToNameMap = tables.keyToNameMap;
  28980. this.nameToKeyMap = tables.nameToKeyMap;
  28981. this.defaults = tables.defaults;
  28982. this.types = tables.types;
  28983. this.opcodes = tables.opcodes;
  28984. this.order = tables.order;
  28985. this.strings = strings;
  28986. this.values = Object.create(null);
  28987. }
  28988. CFFDict.prototype = {
  28989. // value should always be an array
  28990. setByKey: function CFFDict_setByKey(key, value) {
  28991. if (!(key in this.keyToNameMap)) {
  28992. return false;
  28993. }
  28994. // ignore empty values
  28995. if (value.length === 0) {
  28996. return true;
  28997. }
  28998. var type = this.types[key];
  28999. // remove the array wrapping these types of values
  29000. if (type === 'num' || type === 'sid' || type === 'offset') {
  29001. value = value[0];
  29002. }
  29003. this.values[key] = value;
  29004. return true;
  29005. },
  29006. setByName: function CFFDict_setByName(name, value) {
  29007. if (!(name in this.nameToKeyMap)) {
  29008. error('Invalid dictionary name "' + name + '"');
  29009. }
  29010. this.values[this.nameToKeyMap[name]] = value;
  29011. },
  29012. hasName: function CFFDict_hasName(name) {
  29013. return this.nameToKeyMap[name] in this.values;
  29014. },
  29015. getByName: function CFFDict_getByName(name) {
  29016. if (!(name in this.nameToKeyMap)) {
  29017. error('Invalid dictionary name "' + name + '"');
  29018. }
  29019. var key = this.nameToKeyMap[name];
  29020. if (!(key in this.values)) {
  29021. return this.defaults[key];
  29022. }
  29023. return this.values[key];
  29024. },
  29025. removeByName: function CFFDict_removeByName(name) {
  29026. delete this.values[this.nameToKeyMap[name]];
  29027. }
  29028. };
  29029. CFFDict.createTables = function CFFDict_createTables(layout) {
  29030. var tables = {
  29031. keyToNameMap: {},
  29032. nameToKeyMap: {},
  29033. defaults: {},
  29034. types: {},
  29035. opcodes: {},
  29036. order: []
  29037. };
  29038. for (var i = 0, ii = layout.length; i < ii; ++i) {
  29039. var entry = layout[i];
  29040. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  29041. tables.keyToNameMap[key] = entry[1];
  29042. tables.nameToKeyMap[entry[1]] = key;
  29043. tables.types[key] = entry[2];
  29044. tables.defaults[key] = entry[3];
  29045. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  29046. tables.order.push(key);
  29047. }
  29048. return tables;
  29049. };
  29050. return CFFDict;
  29051. })();
  29052. var CFFTopDict = (function CFFTopDictClosure() {
  29053. var layout = [
  29054. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  29055. [[12, 20], 'SyntheticBase', 'num', null],
  29056. [0, 'version', 'sid', null],
  29057. [1, 'Notice', 'sid', null],
  29058. [[12, 0], 'Copyright', 'sid', null],
  29059. [2, 'FullName', 'sid', null],
  29060. [3, 'FamilyName', 'sid', null],
  29061. [4, 'Weight', 'sid', null],
  29062. [[12, 1], 'isFixedPitch', 'num', 0],
  29063. [[12, 2], 'ItalicAngle', 'num', 0],
  29064. [[12, 3], 'UnderlinePosition', 'num', -100],
  29065. [[12, 4], 'UnderlineThickness', 'num', 50],
  29066. [[12, 5], 'PaintType', 'num', 0],
  29067. [[12, 6], 'CharstringType', 'num', 2],
  29068. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  29069. [0.001, 0, 0, 0.001, 0, 0]],
  29070. [13, 'UniqueID', 'num', null],
  29071. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  29072. [[12, 8], 'StrokeWidth', 'num', 0],
  29073. [14, 'XUID', 'array', null],
  29074. [15, 'charset', 'offset', 0],
  29075. [16, 'Encoding', 'offset', 0],
  29076. [17, 'CharStrings', 'offset', 0],
  29077. [18, 'Private', ['offset', 'offset'], null],
  29078. [[12, 21], 'PostScript', 'sid', null],
  29079. [[12, 22], 'BaseFontName', 'sid', null],
  29080. [[12, 23], 'BaseFontBlend', 'delta', null],
  29081. [[12, 31], 'CIDFontVersion', 'num', 0],
  29082. [[12, 32], 'CIDFontRevision', 'num', 0],
  29083. [[12, 33], 'CIDFontType', 'num', 0],
  29084. [[12, 34], 'CIDCount', 'num', 8720],
  29085. [[12, 35], 'UIDBase', 'num', null],
  29086. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  29087. // before FDArray.
  29088. [[12, 37], 'FDSelect', 'offset', null],
  29089. [[12, 36], 'FDArray', 'offset', null],
  29090. [[12, 38], 'FontName', 'sid', null]
  29091. ];
  29092. var tables = null;
  29093. function CFFTopDict(strings) {
  29094. if (tables === null) {
  29095. tables = CFFDict.createTables(layout);
  29096. }
  29097. CFFDict.call(this, tables, strings);
  29098. this.privateDict = null;
  29099. }
  29100. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  29101. return CFFTopDict;
  29102. })();
  29103. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  29104. var layout = [
  29105. [6, 'BlueValues', 'delta', null],
  29106. [7, 'OtherBlues', 'delta', null],
  29107. [8, 'FamilyBlues', 'delta', null],
  29108. [9, 'FamilyOtherBlues', 'delta', null],
  29109. [[12, 9], 'BlueScale', 'num', 0.039625],
  29110. [[12, 10], 'BlueShift', 'num', 7],
  29111. [[12, 11], 'BlueFuzz', 'num', 1],
  29112. [10, 'StdHW', 'num', null],
  29113. [11, 'StdVW', 'num', null],
  29114. [[12, 12], 'StemSnapH', 'delta', null],
  29115. [[12, 13], 'StemSnapV', 'delta', null],
  29116. [[12, 14], 'ForceBold', 'num', 0],
  29117. [[12, 17], 'LanguageGroup', 'num', 0],
  29118. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  29119. [[12, 19], 'initialRandomSeed', 'num', 0],
  29120. [20, 'defaultWidthX', 'num', 0],
  29121. [21, 'nominalWidthX', 'num', 0],
  29122. [19, 'Subrs', 'offset', null]
  29123. ];
  29124. var tables = null;
  29125. function CFFPrivateDict(strings) {
  29126. if (tables === null) {
  29127. tables = CFFDict.createTables(layout);
  29128. }
  29129. CFFDict.call(this, tables, strings);
  29130. this.subrsIndex = null;
  29131. }
  29132. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  29133. return CFFPrivateDict;
  29134. })();
  29135. var CFFCharsetPredefinedTypes = {
  29136. ISO_ADOBE: 0,
  29137. EXPERT: 1,
  29138. EXPERT_SUBSET: 2
  29139. };
  29140. var CFFCharset = (function CFFCharsetClosure() {
  29141. function CFFCharset(predefined, format, charset, raw) {
  29142. this.predefined = predefined;
  29143. this.format = format;
  29144. this.charset = charset;
  29145. this.raw = raw;
  29146. }
  29147. return CFFCharset;
  29148. })();
  29149. var CFFEncoding = (function CFFEncodingClosure() {
  29150. function CFFEncoding(predefined, format, encoding, raw) {
  29151. this.predefined = predefined;
  29152. this.format = format;
  29153. this.encoding = encoding;
  29154. this.raw = raw;
  29155. }
  29156. return CFFEncoding;
  29157. })();
  29158. var CFFFDSelect = (function CFFFDSelectClosure() {
  29159. function CFFFDSelect(fdSelect, raw) {
  29160. this.fdSelect = fdSelect;
  29161. this.raw = raw;
  29162. }
  29163. CFFFDSelect.prototype = {
  29164. getFDIndex: function CFFFDSelect_get(glyphIndex) {
  29165. if (glyphIndex < 0 || glyphIndex >= this.fdSelect.length) {
  29166. return -1;
  29167. }
  29168. return this.fdSelect[glyphIndex];
  29169. }
  29170. };
  29171. return CFFFDSelect;
  29172. })();
  29173. // Helper class to keep track of where an offset is within the data and helps
  29174. // filling in that offset once it's known.
  29175. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  29176. function CFFOffsetTracker() {
  29177. this.offsets = Object.create(null);
  29178. }
  29179. CFFOffsetTracker.prototype = {
  29180. isTracking: function CFFOffsetTracker_isTracking(key) {
  29181. return key in this.offsets;
  29182. },
  29183. track: function CFFOffsetTracker_track(key, location) {
  29184. if (key in this.offsets) {
  29185. error('Already tracking location of ' + key);
  29186. }
  29187. this.offsets[key] = location;
  29188. },
  29189. offset: function CFFOffsetTracker_offset(value) {
  29190. for (var key in this.offsets) {
  29191. this.offsets[key] += value;
  29192. }
  29193. },
  29194. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  29195. values,
  29196. output) {
  29197. if (!(key in this.offsets)) {
  29198. error('Not tracking location of ' + key);
  29199. }
  29200. var data = output.data;
  29201. var dataOffset = this.offsets[key];
  29202. var size = 5;
  29203. for (var i = 0, ii = values.length; i < ii; ++i) {
  29204. var offset0 = i * size + dataOffset;
  29205. var offset1 = offset0 + 1;
  29206. var offset2 = offset0 + 2;
  29207. var offset3 = offset0 + 3;
  29208. var offset4 = offset0 + 4;
  29209. // It's easy to screw up offsets so perform this sanity check.
  29210. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  29211. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  29212. error('writing to an offset that is not empty');
  29213. }
  29214. var value = values[i];
  29215. data[offset0] = 0x1d;
  29216. data[offset1] = (value >> 24) & 0xFF;
  29217. data[offset2] = (value >> 16) & 0xFF;
  29218. data[offset3] = (value >> 8) & 0xFF;
  29219. data[offset4] = value & 0xFF;
  29220. }
  29221. }
  29222. };
  29223. return CFFOffsetTracker;
  29224. })();
  29225. // Takes a CFF and converts it to the binary representation.
  29226. var CFFCompiler = (function CFFCompilerClosure() {
  29227. function CFFCompiler(cff) {
  29228. this.cff = cff;
  29229. }
  29230. CFFCompiler.prototype = {
  29231. compile: function CFFCompiler_compile() {
  29232. var cff = this.cff;
  29233. var output = {
  29234. data: [],
  29235. length: 0,
  29236. add: function CFFCompiler_add(data) {
  29237. this.data = this.data.concat(data);
  29238. this.length = this.data.length;
  29239. }
  29240. };
  29241. // Compile the five entries that must be in order.
  29242. var header = this.compileHeader(cff.header);
  29243. output.add(header);
  29244. var nameIndex = this.compileNameIndex(cff.names);
  29245. output.add(nameIndex);
  29246. if (cff.isCIDFont) {
  29247. // The spec is unclear on how font matrices should relate to each other
  29248. // when there is one in the main top dict and the sub top dicts.
  29249. // Windows handles this differently than linux and osx so we have to
  29250. // normalize to work on all.
  29251. // Rules based off of some mailing list discussions:
  29252. // - If main font has a matrix and subfont doesn't, use the main matrix.
  29253. // - If no main font matrix and there is a subfont matrix, use the
  29254. // subfont matrix.
  29255. // - If both have matrices, concat together.
  29256. // - If neither have matrices, use default.
  29257. // To make this work on all platforms we move the top matrix into each
  29258. // sub top dict and concat if necessary.
  29259. if (cff.topDict.hasName('FontMatrix')) {
  29260. var base = cff.topDict.getByName('FontMatrix');
  29261. cff.topDict.removeByName('FontMatrix');
  29262. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  29263. var subDict = cff.fdArray[i];
  29264. var matrix = base.slice(0);
  29265. if (subDict.hasName('FontMatrix')) {
  29266. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  29267. }
  29268. subDict.setByName('FontMatrix', matrix);
  29269. }
  29270. }
  29271. }
  29272. var compiled = this.compileTopDicts([cff.topDict],
  29273. output.length,
  29274. cff.isCIDFont);
  29275. output.add(compiled.output);
  29276. var topDictTracker = compiled.trackers[0];
  29277. var stringIndex = this.compileStringIndex(cff.strings.strings);
  29278. output.add(stringIndex);
  29279. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  29280. output.add(globalSubrIndex);
  29281. // Now start on the other entries that have no specfic order.
  29282. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  29283. if (cff.encoding.predefined) {
  29284. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  29285. output);
  29286. } else {
  29287. var encoding = this.compileEncoding(cff.encoding);
  29288. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  29289. output.add(encoding);
  29290. }
  29291. }
  29292. if (cff.charset && cff.topDict.hasName('charset')) {
  29293. if (cff.charset.predefined) {
  29294. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  29295. output);
  29296. } else {
  29297. var charset = this.compileCharset(cff.charset);
  29298. topDictTracker.setEntryLocation('charset', [output.length], output);
  29299. output.add(charset);
  29300. }
  29301. }
  29302. var charStrings = this.compileCharStrings(cff.charStrings);
  29303. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  29304. output.add(charStrings);
  29305. if (cff.isCIDFont) {
  29306. // For some reason FDSelect must be in front of FDArray on windows. OSX
  29307. // and linux don't seem to care.
  29308. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  29309. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  29310. output.add(fdSelect);
  29311. // It is unclear if the sub font dictionary can have CID related
  29312. // dictionary keys, but the sanitizer doesn't like them so remove them.
  29313. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  29314. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  29315. output.add(compiled.output);
  29316. var fontDictTrackers = compiled.trackers;
  29317. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  29318. }
  29319. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  29320. // If the font data ends with INDEX whose object data is zero-length,
  29321. // the sanitizer will bail out. Add a dummy byte to avoid that.
  29322. output.add([0]);
  29323. return output.data;
  29324. },
  29325. encodeNumber: function CFFCompiler_encodeNumber(value) {
  29326. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  29327. return this.encodeInteger(value);
  29328. } else {
  29329. return this.encodeFloat(value);
  29330. }
  29331. },
  29332. encodeFloat: function CFFCompiler_encodeFloat(num) {
  29333. var value = num.toString();
  29334. // rounding inaccurate doubles
  29335. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  29336. if (m) {
  29337. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  29338. value = (Math.round(num * epsilon) / epsilon).toString();
  29339. }
  29340. var nibbles = '';
  29341. var i, ii;
  29342. for (i = 0, ii = value.length; i < ii; ++i) {
  29343. var a = value[i];
  29344. if (a === 'e') {
  29345. nibbles += value[++i] === '-' ? 'c' : 'b';
  29346. } else if (a === '.') {
  29347. nibbles += 'a';
  29348. } else if (a === '-') {
  29349. nibbles += 'e';
  29350. } else {
  29351. nibbles += a;
  29352. }
  29353. }
  29354. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  29355. var out = [30];
  29356. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  29357. out.push(parseInt(nibbles.substr(i, 2), 16));
  29358. }
  29359. return out;
  29360. },
  29361. encodeInteger: function CFFCompiler_encodeInteger(value) {
  29362. var code;
  29363. if (value >= -107 && value <= 107) {
  29364. code = [value + 139];
  29365. } else if (value >= 108 && value <= 1131) {
  29366. value = [value - 108];
  29367. code = [(value >> 8) + 247, value & 0xFF];
  29368. } else if (value >= -1131 && value <= -108) {
  29369. value = -value - 108;
  29370. code = [(value >> 8) + 251, value & 0xFF];
  29371. } else if (value >= -32768 && value <= 32767) {
  29372. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  29373. } else {
  29374. code = [0x1d,
  29375. (value >> 24) & 0xFF,
  29376. (value >> 16) & 0xFF,
  29377. (value >> 8) & 0xFF,
  29378. value & 0xFF];
  29379. }
  29380. return code;
  29381. },
  29382. compileHeader: function CFFCompiler_compileHeader(header) {
  29383. return [
  29384. header.major,
  29385. header.minor,
  29386. header.hdrSize,
  29387. header.offSize
  29388. ];
  29389. },
  29390. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  29391. var nameIndex = new CFFIndex();
  29392. for (var i = 0, ii = names.length; i < ii; ++i) {
  29393. nameIndex.add(stringToBytes(names[i]));
  29394. }
  29395. return this.compileIndex(nameIndex);
  29396. },
  29397. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  29398. length,
  29399. removeCidKeys) {
  29400. var fontDictTrackers = [];
  29401. var fdArrayIndex = new CFFIndex();
  29402. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  29403. var fontDict = dicts[i];
  29404. if (removeCidKeys) {
  29405. fontDict.removeByName('CIDFontVersion');
  29406. fontDict.removeByName('CIDFontRevision');
  29407. fontDict.removeByName('CIDFontType');
  29408. fontDict.removeByName('CIDCount');
  29409. fontDict.removeByName('UIDBase');
  29410. }
  29411. var fontDictTracker = new CFFOffsetTracker();
  29412. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  29413. fontDictTrackers.push(fontDictTracker);
  29414. fdArrayIndex.add(fontDictData);
  29415. fontDictTracker.offset(length);
  29416. }
  29417. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  29418. return {
  29419. trackers: fontDictTrackers,
  29420. output: fdArrayIndex
  29421. };
  29422. },
  29423. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  29424. trackers,
  29425. output) {
  29426. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  29427. var fontDict = dicts[i];
  29428. assert(fontDict.privateDict && fontDict.hasName('Private'),
  29429. 'There must be an private dictionary.');
  29430. var privateDict = fontDict.privateDict;
  29431. var privateDictTracker = new CFFOffsetTracker();
  29432. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  29433. var outputLength = output.length;
  29434. privateDictTracker.offset(outputLength);
  29435. if (!privateDictData.length) {
  29436. // The private dictionary was empty, set the output length to zero to
  29437. // ensure the offset length isn't out of bounds in the eyes of the
  29438. // sanitizer.
  29439. outputLength = 0;
  29440. }
  29441. trackers[i].setEntryLocation('Private',
  29442. [privateDictData.length, outputLength],
  29443. output);
  29444. output.add(privateDictData);
  29445. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  29446. var subrs = this.compileIndex(privateDict.subrsIndex);
  29447. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  29448. output);
  29449. output.add(subrs);
  29450. }
  29451. }
  29452. },
  29453. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  29454. var out = [];
  29455. // The dictionary keys must be in a certain order.
  29456. var order = dict.order;
  29457. for (var i = 0; i < order.length; ++i) {
  29458. var key = order[i];
  29459. if (!(key in dict.values)) {
  29460. continue;
  29461. }
  29462. var values = dict.values[key];
  29463. var types = dict.types[key];
  29464. if (!isArray(types)) {
  29465. types = [types];
  29466. }
  29467. if (!isArray(values)) {
  29468. values = [values];
  29469. }
  29470. // Remove any empty dict values.
  29471. if (values.length === 0) {
  29472. continue;
  29473. }
  29474. for (var j = 0, jj = types.length; j < jj; ++j) {
  29475. var type = types[j];
  29476. var value = values[j];
  29477. switch (type) {
  29478. case 'num':
  29479. case 'sid':
  29480. out = out.concat(this.encodeNumber(value));
  29481. break;
  29482. case 'offset':
  29483. // For offsets we just insert a 32bit integer so we don't have to
  29484. // deal with figuring out the length of the offset when it gets
  29485. // replaced later on by the compiler.
  29486. var name = dict.keyToNameMap[key];
  29487. // Some offsets have the offset and the length, so just record the
  29488. // position of the first one.
  29489. if (!offsetTracker.isTracking(name)) {
  29490. offsetTracker.track(name, out.length);
  29491. }
  29492. out = out.concat([0x1d, 0, 0, 0, 0]);
  29493. break;
  29494. case 'array':
  29495. case 'delta':
  29496. out = out.concat(this.encodeNumber(value));
  29497. for (var k = 1, kk = values.length; k < kk; ++k) {
  29498. out = out.concat(this.encodeNumber(values[k]));
  29499. }
  29500. break;
  29501. default:
  29502. error('Unknown data type of ' + type);
  29503. break;
  29504. }
  29505. }
  29506. out = out.concat(dict.opcodes[key]);
  29507. }
  29508. return out;
  29509. },
  29510. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  29511. var stringIndex = new CFFIndex();
  29512. for (var i = 0, ii = strings.length; i < ii; ++i) {
  29513. stringIndex.add(stringToBytes(strings[i]));
  29514. }
  29515. return this.compileIndex(stringIndex);
  29516. },
  29517. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  29518. var globalSubrIndex = this.cff.globalSubrIndex;
  29519. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  29520. },
  29521. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  29522. return this.compileIndex(charStrings);
  29523. },
  29524. compileCharset: function CFFCompiler_compileCharset(charset) {
  29525. return this.compileTypedArray(charset.raw);
  29526. },
  29527. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  29528. return this.compileTypedArray(encoding.raw);
  29529. },
  29530. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  29531. return this.compileTypedArray(fdSelect);
  29532. },
  29533. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  29534. var out = [];
  29535. for (var i = 0, ii = data.length; i < ii; ++i) {
  29536. out[i] = data[i];
  29537. }
  29538. return out;
  29539. },
  29540. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  29541. trackers = trackers || [];
  29542. var objects = index.objects;
  29543. // First 2 bytes contains the number of objects contained into this index
  29544. var count = objects.length;
  29545. // If there is no object, just create an index. This technically
  29546. // should just be [0, 0] but OTS has an issue with that.
  29547. if (count === 0) {
  29548. return [0, 0, 0];
  29549. }
  29550. var data = [(count >> 8) & 0xFF, count & 0xff];
  29551. var lastOffset = 1, i;
  29552. for (i = 0; i < count; ++i) {
  29553. lastOffset += objects[i].length;
  29554. }
  29555. var offsetSize;
  29556. if (lastOffset < 0x100) {
  29557. offsetSize = 1;
  29558. } else if (lastOffset < 0x10000) {
  29559. offsetSize = 2;
  29560. } else if (lastOffset < 0x1000000) {
  29561. offsetSize = 3;
  29562. } else {
  29563. offsetSize = 4;
  29564. }
  29565. // Next byte contains the offset size use to reference object in the file
  29566. data.push(offsetSize);
  29567. // Add another offset after this one because we need a new offset
  29568. var relativeOffset = 1;
  29569. for (i = 0; i < count + 1; i++) {
  29570. if (offsetSize === 1) {
  29571. data.push(relativeOffset & 0xFF);
  29572. } else if (offsetSize === 2) {
  29573. data.push((relativeOffset >> 8) & 0xFF,
  29574. relativeOffset & 0xFF);
  29575. } else if (offsetSize === 3) {
  29576. data.push((relativeOffset >> 16) & 0xFF,
  29577. (relativeOffset >> 8) & 0xFF,
  29578. relativeOffset & 0xFF);
  29579. } else {
  29580. data.push((relativeOffset >>> 24) & 0xFF,
  29581. (relativeOffset >> 16) & 0xFF,
  29582. (relativeOffset >> 8) & 0xFF,
  29583. relativeOffset & 0xFF);
  29584. }
  29585. if (objects[i]) {
  29586. relativeOffset += objects[i].length;
  29587. }
  29588. }
  29589. for (i = 0; i < count; i++) {
  29590. // Notify the tracker where the object will be offset in the data.
  29591. if (trackers[i]) {
  29592. trackers[i].offset(data.length);
  29593. }
  29594. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  29595. data.push(objects[i][j]);
  29596. }
  29597. }
  29598. return data;
  29599. }
  29600. };
  29601. return CFFCompiler;
  29602. })();
  29603. function _enableSeacAnalysis(enabled) {
  29604. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED = enabled;
  29605. }
  29606. // Workaround for seac on Windows.
  29607. (function checkSeacSupport() {
  29608. if (typeof navigator !== 'undefined' && /Windows/.test(navigator.userAgent)) {
  29609. SEAC_ANALYSIS_ENABLED = true;
  29610. }
  29611. })();
  29612. // Workaround for Private Use Area characters in Chrome on Windows
  29613. // http://code.google.com/p/chromium/issues/detail?id=122465
  29614. // https://github.com/mozilla/pdf.js/issues/1689
  29615. (function checkChromeWindows() {
  29616. if (typeof navigator !== 'undefined' &&
  29617. /Windows.*Chrome/.test(navigator.userAgent)) {
  29618. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  29619. }
  29620. })();
  29621. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED;
  29622. exports.CFFCompiler = CFFCompiler;
  29623. exports.CFFIndex = CFFIndex;
  29624. exports.CFFParser = CFFParser;
  29625. exports.CFFStrings = CFFStrings;
  29626. exports.ErrorFont = ErrorFont;
  29627. exports.FontFlags = FontFlags;
  29628. exports.Font = Font;
  29629. exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
  29630. exports.ToUnicodeMap = ToUnicodeMap;
  29631. exports.Type1Parser = Type1Parser;
  29632. exports.getFontType = getFontType;
  29633. exports._enableSeacAnalysis = _enableSeacAnalysis;
  29634. // TODO refactor to remove cyclic dependency on font_renderer.js
  29635. coreFontRenderer._setCoreFonts(exports);
  29636. }));
  29637. (function (root, factory) {
  29638. {
  29639. factory((root.pdfjsCoreFunction = {}), root.pdfjsSharedUtil,
  29640. root.pdfjsCorePrimitives, root.pdfjsCorePsParser);
  29641. }
  29642. }(this, function (exports, sharedUtil, corePrimitives, corePsParser) {
  29643. var error = sharedUtil.error;
  29644. var info = sharedUtil.info;
  29645. var isArray = sharedUtil.isArray;
  29646. var isBool = sharedUtil.isBool;
  29647. var isDict = corePrimitives.isDict;
  29648. var isStream = corePrimitives.isStream;
  29649. var PostScriptLexer = corePsParser.PostScriptLexer;
  29650. var PostScriptParser = corePsParser.PostScriptParser;
  29651. var PDFFunction = (function PDFFunctionClosure() {
  29652. var CONSTRUCT_SAMPLED = 0;
  29653. var CONSTRUCT_INTERPOLATED = 2;
  29654. var CONSTRUCT_STICHED = 3;
  29655. var CONSTRUCT_POSTSCRIPT = 4;
  29656. return {
  29657. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  29658. str) {
  29659. var i, ii;
  29660. var length = 1;
  29661. for (i = 0, ii = size.length; i < ii; i++) {
  29662. length *= size[i];
  29663. }
  29664. length *= outputSize;
  29665. var array = new Array(length);
  29666. var codeSize = 0;
  29667. var codeBuf = 0;
  29668. // 32 is a valid bps so shifting won't work
  29669. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  29670. var strBytes = str.getBytes((length * bps + 7) / 8);
  29671. var strIdx = 0;
  29672. for (i = 0; i < length; i++) {
  29673. while (codeSize < bps) {
  29674. codeBuf <<= 8;
  29675. codeBuf |= strBytes[strIdx++];
  29676. codeSize += 8;
  29677. }
  29678. codeSize -= bps;
  29679. array[i] = (codeBuf >> codeSize) * sampleMul;
  29680. codeBuf &= (1 << codeSize) - 1;
  29681. }
  29682. return array;
  29683. },
  29684. getIR: function PDFFunction_getIR(xref, fn) {
  29685. var dict = fn.dict;
  29686. if (!dict) {
  29687. dict = fn;
  29688. }
  29689. var types = [this.constructSampled,
  29690. null,
  29691. this.constructInterpolated,
  29692. this.constructStiched,
  29693. this.constructPostScript];
  29694. var typeNum = dict.get('FunctionType');
  29695. var typeFn = types[typeNum];
  29696. if (!typeFn) {
  29697. error('Unknown type of function');
  29698. }
  29699. return typeFn.call(this, fn, dict, xref);
  29700. },
  29701. fromIR: function PDFFunction_fromIR(IR) {
  29702. var type = IR[0];
  29703. switch (type) {
  29704. case CONSTRUCT_SAMPLED:
  29705. return this.constructSampledFromIR(IR);
  29706. case CONSTRUCT_INTERPOLATED:
  29707. return this.constructInterpolatedFromIR(IR);
  29708. case CONSTRUCT_STICHED:
  29709. return this.constructStichedFromIR(IR);
  29710. //case CONSTRUCT_POSTSCRIPT:
  29711. default:
  29712. return this.constructPostScriptFromIR(IR);
  29713. }
  29714. },
  29715. parse: function PDFFunction_parse(xref, fn) {
  29716. var IR = this.getIR(xref, fn);
  29717. return this.fromIR(IR);
  29718. },
  29719. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  29720. if (!isArray(fnObj)) {
  29721. // not an array -- parsing as regular function
  29722. return this.parse(xref, fnObj);
  29723. }
  29724. var fnArray = [];
  29725. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  29726. var obj = xref.fetchIfRef(fnObj[j]);
  29727. fnArray.push(PDFFunction.parse(xref, obj));
  29728. }
  29729. return function (src, srcOffset, dest, destOffset) {
  29730. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  29731. fnArray[i](src, srcOffset, dest, destOffset + i);
  29732. }
  29733. };
  29734. },
  29735. constructSampled: function PDFFunction_constructSampled(str, dict) {
  29736. function toMultiArray(arr) {
  29737. var inputLength = arr.length;
  29738. var out = [];
  29739. var index = 0;
  29740. for (var i = 0; i < inputLength; i += 2) {
  29741. out[index] = [arr[i], arr[i + 1]];
  29742. ++index;
  29743. }
  29744. return out;
  29745. }
  29746. var domain = dict.get('Domain');
  29747. var range = dict.get('Range');
  29748. if (!domain || !range) {
  29749. error('No domain or range');
  29750. }
  29751. var inputSize = domain.length / 2;
  29752. var outputSize = range.length / 2;
  29753. domain = toMultiArray(domain);
  29754. range = toMultiArray(range);
  29755. var size = dict.get('Size');
  29756. var bps = dict.get('BitsPerSample');
  29757. var order = dict.get('Order') || 1;
  29758. if (order !== 1) {
  29759. // No description how cubic spline interpolation works in PDF32000:2008
  29760. // As in poppler, ignoring order, linear interpolation may work as good
  29761. info('No support for cubic spline interpolation: ' + order);
  29762. }
  29763. var encode = dict.get('Encode');
  29764. if (!encode) {
  29765. encode = [];
  29766. for (var i = 0; i < inputSize; ++i) {
  29767. encode.push(0);
  29768. encode.push(size[i] - 1);
  29769. }
  29770. }
  29771. encode = toMultiArray(encode);
  29772. var decode = dict.get('Decode');
  29773. if (!decode) {
  29774. decode = range;
  29775. } else {
  29776. decode = toMultiArray(decode);
  29777. }
  29778. var samples = this.getSampleArray(size, outputSize, bps, str);
  29779. return [
  29780. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  29781. outputSize, Math.pow(2, bps) - 1, range
  29782. ];
  29783. },
  29784. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  29785. // See chapter 3, page 109 of the PDF reference
  29786. function interpolate(x, xmin, xmax, ymin, ymax) {
  29787. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  29788. }
  29789. return function constructSampledFromIRResult(src, srcOffset,
  29790. dest, destOffset) {
  29791. // See chapter 3, page 110 of the PDF reference.
  29792. var m = IR[1];
  29793. var domain = IR[2];
  29794. var encode = IR[3];
  29795. var decode = IR[4];
  29796. var samples = IR[5];
  29797. var size = IR[6];
  29798. var n = IR[7];
  29799. //var mask = IR[8];
  29800. var range = IR[9];
  29801. // Building the cube vertices: its part and sample index
  29802. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  29803. var cubeVertices = 1 << m;
  29804. var cubeN = new Float64Array(cubeVertices);
  29805. var cubeVertex = new Uint32Array(cubeVertices);
  29806. var i, j;
  29807. for (j = 0; j < cubeVertices; j++) {
  29808. cubeN[j] = 1;
  29809. }
  29810. var k = n, pos = 1;
  29811. // Map x_i to y_j for 0 <= i < m using the sampled function.
  29812. for (i = 0; i < m; ++i) {
  29813. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  29814. var domain_2i = domain[i][0];
  29815. var domain_2i_1 = domain[i][1];
  29816. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  29817. domain_2i_1);
  29818. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  29819. // Encode_2i, Encode_2i+1)
  29820. var e = interpolate(xi, domain_2i, domain_2i_1,
  29821. encode[i][0], encode[i][1]);
  29822. // e_i' = min(max(e_i, 0), Size_i - 1)
  29823. var size_i = size[i];
  29824. e = Math.min(Math.max(e, 0), size_i - 1);
  29825. // Adjusting the cube: N and vertex sample index
  29826. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  29827. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  29828. var n1 = e - e0; // (e - e0) / (e1 - e0);
  29829. var offset0 = e0 * k;
  29830. var offset1 = offset0 + k; // e1 * k
  29831. for (j = 0; j < cubeVertices; j++) {
  29832. if (j & pos) {
  29833. cubeN[j] *= n1;
  29834. cubeVertex[j] += offset1;
  29835. } else {
  29836. cubeN[j] *= n0;
  29837. cubeVertex[j] += offset0;
  29838. }
  29839. }
  29840. k *= size_i;
  29841. pos <<= 1;
  29842. }
  29843. for (j = 0; j < n; ++j) {
  29844. // Sum all cube vertices' samples portions
  29845. var rj = 0;
  29846. for (i = 0; i < cubeVertices; i++) {
  29847. rj += samples[cubeVertex[i] + j] * cubeN[i];
  29848. }
  29849. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  29850. // Decode_2j, Decode_2j+1)
  29851. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  29852. // y_j = min(max(r_j, range_2j), range_2j+1)
  29853. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  29854. range[j][1]);
  29855. }
  29856. };
  29857. },
  29858. constructInterpolated: function PDFFunction_constructInterpolated(str,
  29859. dict) {
  29860. var c0 = dict.get('C0') || [0];
  29861. var c1 = dict.get('C1') || [1];
  29862. var n = dict.get('N');
  29863. if (!isArray(c0) || !isArray(c1)) {
  29864. error('Illegal dictionary for interpolated function');
  29865. }
  29866. var length = c0.length;
  29867. var diff = [];
  29868. for (var i = 0; i < length; ++i) {
  29869. diff.push(c1[i] - c0[i]);
  29870. }
  29871. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  29872. },
  29873. constructInterpolatedFromIR:
  29874. function PDFFunction_constructInterpolatedFromIR(IR) {
  29875. var c0 = IR[1];
  29876. var diff = IR[2];
  29877. var n = IR[3];
  29878. var length = diff.length;
  29879. return function constructInterpolatedFromIRResult(src, srcOffset,
  29880. dest, destOffset) {
  29881. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  29882. for (var j = 0; j < length; ++j) {
  29883. dest[destOffset + j] = c0[j] + (x * diff[j]);
  29884. }
  29885. };
  29886. },
  29887. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  29888. var domain = dict.get('Domain');
  29889. if (!domain) {
  29890. error('No domain');
  29891. }
  29892. var inputSize = domain.length / 2;
  29893. if (inputSize !== 1) {
  29894. error('Bad domain for stiched function');
  29895. }
  29896. var fnRefs = dict.get('Functions');
  29897. var fns = [];
  29898. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  29899. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  29900. }
  29901. var bounds = dict.get('Bounds');
  29902. var encode = dict.get('Encode');
  29903. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  29904. },
  29905. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  29906. var domain = IR[1];
  29907. var bounds = IR[2];
  29908. var encode = IR[3];
  29909. var fnsIR = IR[4];
  29910. var fns = [];
  29911. var tmpBuf = new Float32Array(1);
  29912. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  29913. fns.push(PDFFunction.fromIR(fnsIR[i]));
  29914. }
  29915. return function constructStichedFromIRResult(src, srcOffset,
  29916. dest, destOffset) {
  29917. var clip = function constructStichedFromIRClip(v, min, max) {
  29918. if (v > max) {
  29919. v = max;
  29920. } else if (v < min) {
  29921. v = min;
  29922. }
  29923. return v;
  29924. };
  29925. // clip to domain
  29926. var v = clip(src[srcOffset], domain[0], domain[1]);
  29927. // calulate which bound the value is in
  29928. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  29929. if (v < bounds[i]) {
  29930. break;
  29931. }
  29932. }
  29933. // encode value into domain of function
  29934. var dmin = domain[0];
  29935. if (i > 0) {
  29936. dmin = bounds[i - 1];
  29937. }
  29938. var dmax = domain[1];
  29939. if (i < bounds.length) {
  29940. dmax = bounds[i];
  29941. }
  29942. var rmin = encode[2 * i];
  29943. var rmax = encode[2 * i + 1];
  29944. // Prevent the value from becoming NaN as a result
  29945. // of division by zero (fixes issue6113.pdf).
  29946. tmpBuf[0] = dmin === dmax ? rmin :
  29947. rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  29948. // call the appropriate function
  29949. fns[i](tmpBuf, 0, dest, destOffset);
  29950. };
  29951. },
  29952. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  29953. xref) {
  29954. var domain = dict.get('Domain');
  29955. var range = dict.get('Range');
  29956. if (!domain) {
  29957. error('No domain.');
  29958. }
  29959. if (!range) {
  29960. error('No range.');
  29961. }
  29962. var lexer = new PostScriptLexer(fn);
  29963. var parser = new PostScriptParser(lexer);
  29964. var code = parser.parse();
  29965. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  29966. },
  29967. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  29968. IR) {
  29969. var domain = IR[1];
  29970. var range = IR[2];
  29971. var code = IR[3];
  29972. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  29973. if (compiled) {
  29974. // Compiled function consists of simple expressions such as addition,
  29975. // subtraction, Math.max, and also contains 'var' and 'return'
  29976. // statements. See the generation in the PostScriptCompiler below.
  29977. /*jshint -W054 */
  29978. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  29979. }
  29980. info('Unable to compile PS function');
  29981. var numOutputs = range.length >> 1;
  29982. var numInputs = domain.length >> 1;
  29983. var evaluator = new PostScriptEvaluator(code);
  29984. // Cache the values for a big speed up, the cache size is limited though
  29985. // since the number of possible values can be huge from a PS function.
  29986. var cache = Object.create(null);
  29987. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  29988. // seen in our tests.
  29989. var MAX_CACHE_SIZE = 2048 * 4;
  29990. var cache_available = MAX_CACHE_SIZE;
  29991. var tmpBuf = new Float32Array(numInputs);
  29992. return function constructPostScriptFromIRResult(src, srcOffset,
  29993. dest, destOffset) {
  29994. var i, value;
  29995. var key = '';
  29996. var input = tmpBuf;
  29997. for (i = 0; i < numInputs; i++) {
  29998. value = src[srcOffset + i];
  29999. input[i] = value;
  30000. key += value + '_';
  30001. }
  30002. var cachedValue = cache[key];
  30003. if (cachedValue !== undefined) {
  30004. dest.set(cachedValue, destOffset);
  30005. return;
  30006. }
  30007. var output = new Float32Array(numOutputs);
  30008. var stack = evaluator.execute(input);
  30009. var stackIndex = stack.length - numOutputs;
  30010. for (i = 0; i < numOutputs; i++) {
  30011. value = stack[stackIndex + i];
  30012. var bound = range[i * 2];
  30013. if (value < bound) {
  30014. value = bound;
  30015. } else {
  30016. bound = range[i * 2 +1];
  30017. if (value > bound) {
  30018. value = bound;
  30019. }
  30020. }
  30021. output[i] = value;
  30022. }
  30023. if (cache_available > 0) {
  30024. cache_available--;
  30025. cache[key] = output;
  30026. }
  30027. dest.set(output, destOffset);
  30028. };
  30029. }
  30030. };
  30031. })();
  30032. function isPDFFunction(v) {
  30033. var fnDict;
  30034. if (typeof v !== 'object') {
  30035. return false;
  30036. } else if (isDict(v)) {
  30037. fnDict = v;
  30038. } else if (isStream(v)) {
  30039. fnDict = v.dict;
  30040. } else {
  30041. return false;
  30042. }
  30043. return fnDict.has('FunctionType');
  30044. }
  30045. var PostScriptStack = (function PostScriptStackClosure() {
  30046. var MAX_STACK_SIZE = 100;
  30047. function PostScriptStack(initialStack) {
  30048. this.stack = !initialStack ? [] :
  30049. Array.prototype.slice.call(initialStack, 0);
  30050. }
  30051. PostScriptStack.prototype = {
  30052. push: function PostScriptStack_push(value) {
  30053. if (this.stack.length >= MAX_STACK_SIZE) {
  30054. error('PostScript function stack overflow.');
  30055. }
  30056. this.stack.push(value);
  30057. },
  30058. pop: function PostScriptStack_pop() {
  30059. if (this.stack.length <= 0) {
  30060. error('PostScript function stack underflow.');
  30061. }
  30062. return this.stack.pop();
  30063. },
  30064. copy: function PostScriptStack_copy(n) {
  30065. if (this.stack.length + n >= MAX_STACK_SIZE) {
  30066. error('PostScript function stack overflow.');
  30067. }
  30068. var stack = this.stack;
  30069. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  30070. stack.push(stack[i]);
  30071. }
  30072. },
  30073. index: function PostScriptStack_index(n) {
  30074. this.push(this.stack[this.stack.length - n - 1]);
  30075. },
  30076. // rotate the last n stack elements p times
  30077. roll: function PostScriptStack_roll(n, p) {
  30078. var stack = this.stack;
  30079. var l = stack.length - n;
  30080. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  30081. for (i = l, j = r; i < j; i++, j--) {
  30082. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  30083. }
  30084. for (i = l, j = c - 1; i < j; i++, j--) {
  30085. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  30086. }
  30087. for (i = c, j = r; i < j; i++, j--) {
  30088. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  30089. }
  30090. }
  30091. };
  30092. return PostScriptStack;
  30093. })();
  30094. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  30095. function PostScriptEvaluator(operators) {
  30096. this.operators = operators;
  30097. }
  30098. PostScriptEvaluator.prototype = {
  30099. execute: function PostScriptEvaluator_execute(initialStack) {
  30100. var stack = new PostScriptStack(initialStack);
  30101. var counter = 0;
  30102. var operators = this.operators;
  30103. var length = operators.length;
  30104. var operator, a, b;
  30105. while (counter < length) {
  30106. operator = operators[counter++];
  30107. if (typeof operator === 'number') {
  30108. // Operator is really an operand and should be pushed to the stack.
  30109. stack.push(operator);
  30110. continue;
  30111. }
  30112. switch (operator) {
  30113. // non standard ps operators
  30114. case 'jz': // jump if false
  30115. b = stack.pop();
  30116. a = stack.pop();
  30117. if (!a) {
  30118. counter = b;
  30119. }
  30120. break;
  30121. case 'j': // jump
  30122. a = stack.pop();
  30123. counter = a;
  30124. break;
  30125. // all ps operators in alphabetical order (excluding if/ifelse)
  30126. case 'abs':
  30127. a = stack.pop();
  30128. stack.push(Math.abs(a));
  30129. break;
  30130. case 'add':
  30131. b = stack.pop();
  30132. a = stack.pop();
  30133. stack.push(a + b);
  30134. break;
  30135. case 'and':
  30136. b = stack.pop();
  30137. a = stack.pop();
  30138. if (isBool(a) && isBool(b)) {
  30139. stack.push(a && b);
  30140. } else {
  30141. stack.push(a & b);
  30142. }
  30143. break;
  30144. case 'atan':
  30145. a = stack.pop();
  30146. stack.push(Math.atan(a));
  30147. break;
  30148. case 'bitshift':
  30149. b = stack.pop();
  30150. a = stack.pop();
  30151. if (a > 0) {
  30152. stack.push(a << b);
  30153. } else {
  30154. stack.push(a >> b);
  30155. }
  30156. break;
  30157. case 'ceiling':
  30158. a = stack.pop();
  30159. stack.push(Math.ceil(a));
  30160. break;
  30161. case 'copy':
  30162. a = stack.pop();
  30163. stack.copy(a);
  30164. break;
  30165. case 'cos':
  30166. a = stack.pop();
  30167. stack.push(Math.cos(a));
  30168. break;
  30169. case 'cvi':
  30170. a = stack.pop() | 0;
  30171. stack.push(a);
  30172. break;
  30173. case 'cvr':
  30174. // noop
  30175. break;
  30176. case 'div':
  30177. b = stack.pop();
  30178. a = stack.pop();
  30179. stack.push(a / b);
  30180. break;
  30181. case 'dup':
  30182. stack.copy(1);
  30183. break;
  30184. case 'eq':
  30185. b = stack.pop();
  30186. a = stack.pop();
  30187. stack.push(a === b);
  30188. break;
  30189. case 'exch':
  30190. stack.roll(2, 1);
  30191. break;
  30192. case 'exp':
  30193. b = stack.pop();
  30194. a = stack.pop();
  30195. stack.push(Math.pow(a, b));
  30196. break;
  30197. case 'false':
  30198. stack.push(false);
  30199. break;
  30200. case 'floor':
  30201. a = stack.pop();
  30202. stack.push(Math.floor(a));
  30203. break;
  30204. case 'ge':
  30205. b = stack.pop();
  30206. a = stack.pop();
  30207. stack.push(a >= b);
  30208. break;
  30209. case 'gt':
  30210. b = stack.pop();
  30211. a = stack.pop();
  30212. stack.push(a > b);
  30213. break;
  30214. case 'idiv':
  30215. b = stack.pop();
  30216. a = stack.pop();
  30217. stack.push((a / b) | 0);
  30218. break;
  30219. case 'index':
  30220. a = stack.pop();
  30221. stack.index(a);
  30222. break;
  30223. case 'le':
  30224. b = stack.pop();
  30225. a = stack.pop();
  30226. stack.push(a <= b);
  30227. break;
  30228. case 'ln':
  30229. a = stack.pop();
  30230. stack.push(Math.log(a));
  30231. break;
  30232. case 'log':
  30233. a = stack.pop();
  30234. stack.push(Math.log(a) / Math.LN10);
  30235. break;
  30236. case 'lt':
  30237. b = stack.pop();
  30238. a = stack.pop();
  30239. stack.push(a < b);
  30240. break;
  30241. case 'mod':
  30242. b = stack.pop();
  30243. a = stack.pop();
  30244. stack.push(a % b);
  30245. break;
  30246. case 'mul':
  30247. b = stack.pop();
  30248. a = stack.pop();
  30249. stack.push(a * b);
  30250. break;
  30251. case 'ne':
  30252. b = stack.pop();
  30253. a = stack.pop();
  30254. stack.push(a !== b);
  30255. break;
  30256. case 'neg':
  30257. a = stack.pop();
  30258. stack.push(-a);
  30259. break;
  30260. case 'not':
  30261. a = stack.pop();
  30262. if (isBool(a)) {
  30263. stack.push(!a);
  30264. } else {
  30265. stack.push(~a);
  30266. }
  30267. break;
  30268. case 'or':
  30269. b = stack.pop();
  30270. a = stack.pop();
  30271. if (isBool(a) && isBool(b)) {
  30272. stack.push(a || b);
  30273. } else {
  30274. stack.push(a | b);
  30275. }
  30276. break;
  30277. case 'pop':
  30278. stack.pop();
  30279. break;
  30280. case 'roll':
  30281. b = stack.pop();
  30282. a = stack.pop();
  30283. stack.roll(a, b);
  30284. break;
  30285. case 'round':
  30286. a = stack.pop();
  30287. stack.push(Math.round(a));
  30288. break;
  30289. case 'sin':
  30290. a = stack.pop();
  30291. stack.push(Math.sin(a));
  30292. break;
  30293. case 'sqrt':
  30294. a = stack.pop();
  30295. stack.push(Math.sqrt(a));
  30296. break;
  30297. case 'sub':
  30298. b = stack.pop();
  30299. a = stack.pop();
  30300. stack.push(a - b);
  30301. break;
  30302. case 'true':
  30303. stack.push(true);
  30304. break;
  30305. case 'truncate':
  30306. a = stack.pop();
  30307. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  30308. stack.push(a);
  30309. break;
  30310. case 'xor':
  30311. b = stack.pop();
  30312. a = stack.pop();
  30313. if (isBool(a) && isBool(b)) {
  30314. stack.push(a !== b);
  30315. } else {
  30316. stack.push(a ^ b);
  30317. }
  30318. break;
  30319. default:
  30320. error('Unknown operator ' + operator);
  30321. break;
  30322. }
  30323. }
  30324. return stack.stack;
  30325. }
  30326. };
  30327. return PostScriptEvaluator;
  30328. })();
  30329. // Most of the PDFs functions consist of simple operations such as:
  30330. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  30331. //
  30332. // We can compile most of such programs, and at the same moment, we can
  30333. // optimize some expressions using basic math properties. Keeping track of
  30334. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  30335. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  30336. function AstNode(type) {
  30337. this.type = type;
  30338. }
  30339. AstNode.prototype.visit = function (visitor) {
  30340. throw new Error('abstract method');
  30341. };
  30342. function AstArgument(index, min, max) {
  30343. AstNode.call(this, 'args');
  30344. this.index = index;
  30345. this.min = min;
  30346. this.max = max;
  30347. }
  30348. AstArgument.prototype = Object.create(AstNode.prototype);
  30349. AstArgument.prototype.visit = function (visitor) {
  30350. visitor.visitArgument(this);
  30351. };
  30352. function AstLiteral(number) {
  30353. AstNode.call(this, 'literal');
  30354. this.number = number;
  30355. this.min = number;
  30356. this.max = number;
  30357. }
  30358. AstLiteral.prototype = Object.create(AstNode.prototype);
  30359. AstLiteral.prototype.visit = function (visitor) {
  30360. visitor.visitLiteral(this);
  30361. };
  30362. function AstBinaryOperation(op, arg1, arg2, min, max) {
  30363. AstNode.call(this, 'binary');
  30364. this.op = op;
  30365. this.arg1 = arg1;
  30366. this.arg2 = arg2;
  30367. this.min = min;
  30368. this.max = max;
  30369. }
  30370. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  30371. AstBinaryOperation.prototype.visit = function (visitor) {
  30372. visitor.visitBinaryOperation(this);
  30373. };
  30374. function AstMin(arg, max) {
  30375. AstNode.call(this, 'max');
  30376. this.arg = arg;
  30377. this.min = arg.min;
  30378. this.max = max;
  30379. }
  30380. AstMin.prototype = Object.create(AstNode.prototype);
  30381. AstMin.prototype.visit = function (visitor) {
  30382. visitor.visitMin(this);
  30383. };
  30384. function AstVariable(index, min, max) {
  30385. AstNode.call(this, 'var');
  30386. this.index = index;
  30387. this.min = min;
  30388. this.max = max;
  30389. }
  30390. AstVariable.prototype = Object.create(AstNode.prototype);
  30391. AstVariable.prototype.visit = function (visitor) {
  30392. visitor.visitVariable(this);
  30393. };
  30394. function AstVariableDefinition(variable, arg) {
  30395. AstNode.call(this, 'definition');
  30396. this.variable = variable;
  30397. this.arg = arg;
  30398. }
  30399. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  30400. AstVariableDefinition.prototype.visit = function (visitor) {
  30401. visitor.visitVariableDefinition(this);
  30402. };
  30403. function ExpressionBuilderVisitor() {
  30404. this.parts = [];
  30405. }
  30406. ExpressionBuilderVisitor.prototype = {
  30407. visitArgument: function (arg) {
  30408. this.parts.push('Math.max(', arg.min, ', Math.min(',
  30409. arg.max, ', src[srcOffset + ', arg.index, ']))');
  30410. },
  30411. visitVariable: function (variable) {
  30412. this.parts.push('v', variable.index);
  30413. },
  30414. visitLiteral: function (literal) {
  30415. this.parts.push(literal.number);
  30416. },
  30417. visitBinaryOperation: function (operation) {
  30418. this.parts.push('(');
  30419. operation.arg1.visit(this);
  30420. this.parts.push(' ', operation.op, ' ');
  30421. operation.arg2.visit(this);
  30422. this.parts.push(')');
  30423. },
  30424. visitVariableDefinition: function (definition) {
  30425. this.parts.push('var ');
  30426. definition.variable.visit(this);
  30427. this.parts.push(' = ');
  30428. definition.arg.visit(this);
  30429. this.parts.push(';');
  30430. },
  30431. visitMin: function (max) {
  30432. this.parts.push('Math.min(');
  30433. max.arg.visit(this);
  30434. this.parts.push(', ', max.max, ')');
  30435. },
  30436. toString: function () {
  30437. return this.parts.join('');
  30438. }
  30439. };
  30440. function buildAddOperation(num1, num2) {
  30441. if (num2.type === 'literal' && num2.number === 0) {
  30442. // optimization: second operand is 0
  30443. return num1;
  30444. }
  30445. if (num1.type === 'literal' && num1.number === 0) {
  30446. // optimization: first operand is 0
  30447. return num2;
  30448. }
  30449. if (num2.type === 'literal' && num1.type === 'literal') {
  30450. // optimization: operands operand are literals
  30451. return new AstLiteral(num1.number + num2.number);
  30452. }
  30453. return new AstBinaryOperation('+', num1, num2,
  30454. num1.min + num2.min, num1.max + num2.max);
  30455. }
  30456. function buildMulOperation(num1, num2) {
  30457. if (num2.type === 'literal') {
  30458. // optimization: second operands is a literal...
  30459. if (num2.number === 0) {
  30460. return new AstLiteral(0); // and it's 0
  30461. } else if (num2.number === 1) {
  30462. return num1; // and it's 1
  30463. } else if (num1.type === 'literal') {
  30464. // ... and first operands is a literal too
  30465. return new AstLiteral(num1.number * num2.number);
  30466. }
  30467. }
  30468. if (num1.type === 'literal') {
  30469. // optimization: first operands is a literal...
  30470. if (num1.number === 0) {
  30471. return new AstLiteral(0); // and it's 0
  30472. } else if (num1.number === 1) {
  30473. return num2; // and it's 1
  30474. }
  30475. }
  30476. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  30477. num1.max * num2.min, num1.max * num2.max);
  30478. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  30479. num1.max * num2.min, num1.max * num2.max);
  30480. return new AstBinaryOperation('*', num1, num2, min, max);
  30481. }
  30482. function buildSubOperation(num1, num2) {
  30483. if (num2.type === 'literal') {
  30484. // optimization: second operands is a literal...
  30485. if (num2.number === 0) {
  30486. return num1; // ... and it's 0
  30487. } else if (num1.type === 'literal') {
  30488. // ... and first operands is a literal too
  30489. return new AstLiteral(num1.number - num2.number);
  30490. }
  30491. }
  30492. if (num2.type === 'binary' && num2.op === '-' &&
  30493. num1.type === 'literal' && num1.number === 1 &&
  30494. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  30495. // optimization for case: 1 - (1 - x)
  30496. return num2.arg2;
  30497. }
  30498. return new AstBinaryOperation('-', num1, num2,
  30499. num1.min - num2.max, num1.max - num2.min);
  30500. }
  30501. function buildMinOperation(num1, max) {
  30502. if (num1.min >= max) {
  30503. // optimization: num1 min value is not less than required max
  30504. return new AstLiteral(max); // just returning max
  30505. } else if (num1.max <= max) {
  30506. // optimization: num1 max value is not greater than required max
  30507. return num1; // just returning an argument
  30508. }
  30509. return new AstMin(num1, max);
  30510. }
  30511. function PostScriptCompiler() {}
  30512. PostScriptCompiler.prototype = {
  30513. compile: function PostScriptCompiler_compile(code, domain, range) {
  30514. var stack = [];
  30515. var i, ii;
  30516. var instructions = [];
  30517. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  30518. var lastRegister = 0;
  30519. var n, j;
  30520. var num1, num2, ast1, ast2, tmpVar, item;
  30521. for (i = 0; i < inputSize; i++) {
  30522. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  30523. }
  30524. for (i = 0, ii = code.length; i < ii; i++) {
  30525. item = code[i];
  30526. if (typeof item === 'number') {
  30527. stack.push(new AstLiteral(item));
  30528. continue;
  30529. }
  30530. switch (item) {
  30531. case 'add':
  30532. if (stack.length < 2) {
  30533. return null;
  30534. }
  30535. num2 = stack.pop();
  30536. num1 = stack.pop();
  30537. stack.push(buildAddOperation(num1, num2));
  30538. break;
  30539. case 'cvr':
  30540. if (stack.length < 1) {
  30541. return null;
  30542. }
  30543. break;
  30544. case 'mul':
  30545. if (stack.length < 2) {
  30546. return null;
  30547. }
  30548. num2 = stack.pop();
  30549. num1 = stack.pop();
  30550. stack.push(buildMulOperation(num1, num2));
  30551. break;
  30552. case 'sub':
  30553. if (stack.length < 2) {
  30554. return null;
  30555. }
  30556. num2 = stack.pop();
  30557. num1 = stack.pop();
  30558. stack.push(buildSubOperation(num1, num2));
  30559. break;
  30560. case 'exch':
  30561. if (stack.length < 2) {
  30562. return null;
  30563. }
  30564. ast1 = stack.pop(); ast2 = stack.pop();
  30565. stack.push(ast1, ast2);
  30566. break;
  30567. case 'pop':
  30568. if (stack.length < 1) {
  30569. return null;
  30570. }
  30571. stack.pop();
  30572. break;
  30573. case 'index':
  30574. if (stack.length < 1) {
  30575. return null;
  30576. }
  30577. num1 = stack.pop();
  30578. if (num1.type !== 'literal') {
  30579. return null;
  30580. }
  30581. n = num1.number;
  30582. if (n < 0 || (n|0) !== n || stack.length < n) {
  30583. return null;
  30584. }
  30585. ast1 = stack[stack.length - n - 1];
  30586. if (ast1.type === 'literal' || ast1.type === 'var') {
  30587. stack.push(ast1);
  30588. break;
  30589. }
  30590. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  30591. stack[stack.length - n - 1] = tmpVar;
  30592. stack.push(tmpVar);
  30593. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  30594. break;
  30595. case 'dup':
  30596. if (stack.length < 1) {
  30597. return null;
  30598. }
  30599. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  30600. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  30601. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  30602. // special case of the commands sequence for the min operation
  30603. num1 = stack.pop();
  30604. stack.push(buildMinOperation(num1, code[i + 1]));
  30605. i += 6;
  30606. break;
  30607. }
  30608. ast1 = stack[stack.length - 1];
  30609. if (ast1.type === 'literal' || ast1.type === 'var') {
  30610. // we don't have to save into intermediate variable a literal or
  30611. // variable.
  30612. stack.push(ast1);
  30613. break;
  30614. }
  30615. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  30616. stack[stack.length - 1] = tmpVar;
  30617. stack.push(tmpVar);
  30618. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  30619. break;
  30620. case 'roll':
  30621. if (stack.length < 2) {
  30622. return null;
  30623. }
  30624. num2 = stack.pop();
  30625. num1 = stack.pop();
  30626. if (num2.type !== 'literal' || num1.type !== 'literal') {
  30627. // both roll operands must be numbers
  30628. return null;
  30629. }
  30630. j = num2.number;
  30631. n = num1.number;
  30632. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  30633. // ... and integers
  30634. return null;
  30635. }
  30636. j = ((j % n) + n) % n;
  30637. if (j === 0) {
  30638. break; // just skipping -- there are nothing to rotate
  30639. }
  30640. Array.prototype.push.apply(stack,
  30641. stack.splice(stack.length - n, n - j));
  30642. break;
  30643. default:
  30644. return null; // unsupported operator
  30645. }
  30646. }
  30647. if (stack.length !== outputSize) {
  30648. return null;
  30649. }
  30650. var result = [];
  30651. instructions.forEach(function (instruction) {
  30652. var statementBuilder = new ExpressionBuilderVisitor();
  30653. instruction.visit(statementBuilder);
  30654. result.push(statementBuilder.toString());
  30655. });
  30656. stack.forEach(function (expr, i) {
  30657. var statementBuilder = new ExpressionBuilderVisitor();
  30658. expr.visit(statementBuilder);
  30659. var min = range[i * 2], max = range[i * 2 + 1];
  30660. var out = [statementBuilder.toString()];
  30661. if (min > expr.min) {
  30662. out.unshift('Math.max(', min, ', ');
  30663. out.push(')');
  30664. }
  30665. if (max < expr.max) {
  30666. out.unshift('Math.min(', max, ', ');
  30667. out.push(')');
  30668. }
  30669. out.unshift('dest[destOffset + ', i, '] = ');
  30670. out.push(';');
  30671. result.push(out.join(''));
  30672. });
  30673. return result.join('\n');
  30674. }
  30675. };
  30676. return PostScriptCompiler;
  30677. })();
  30678. exports.isPDFFunction = isPDFFunction;
  30679. exports.PDFFunction = PDFFunction;
  30680. exports.PostScriptEvaluator = PostScriptEvaluator;
  30681. exports.PostScriptCompiler = PostScriptCompiler;
  30682. }));
  30683. (function (root, factory) {
  30684. {
  30685. factory((root.pdfjsCoreColorSpace = {}), root.pdfjsSharedUtil,
  30686. root.pdfjsCorePrimitives, root.pdfjsCoreFunction, root.pdfjsCoreStream);
  30687. }
  30688. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  30689. coreStream) {
  30690. var error = sharedUtil.error;
  30691. var info = sharedUtil.info;
  30692. var isArray = sharedUtil.isArray;
  30693. var isString = sharedUtil.isString;
  30694. var shadow = sharedUtil.shadow;
  30695. var warn = sharedUtil.warn;
  30696. var isDict = corePrimitives.isDict;
  30697. var isName = corePrimitives.isName;
  30698. var isStream = corePrimitives.isStream;
  30699. var PDFFunction = coreFunction.PDFFunction;
  30700. var coreImage; // see _setCoreImage below
  30701. var PDFImage; // = coreImage.PDFImage;
  30702. var ColorSpace = (function ColorSpaceClosure() {
  30703. // Constructor should define this.numComps, this.defaultColor, this.name
  30704. function ColorSpace() {
  30705. error('should not call ColorSpace constructor');
  30706. }
  30707. ColorSpace.prototype = {
  30708. /**
  30709. * Converts the color value to the RGB color. The color components are
  30710. * located in the src array starting from the srcOffset. Returns the array
  30711. * of the rgb components, each value ranging from [0,255].
  30712. */
  30713. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  30714. var rgb = new Uint8Array(3);
  30715. this.getRgbItem(src, srcOffset, rgb, 0);
  30716. return rgb;
  30717. },
  30718. /**
  30719. * Converts the color value to the RGB color, similar to the getRgb method.
  30720. * The result placed into the dest array starting from the destOffset.
  30721. */
  30722. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  30723. dest, destOffset) {
  30724. error('Should not call ColorSpace.getRgbItem');
  30725. },
  30726. /**
  30727. * Converts the specified number of the color values to the RGB colors.
  30728. * The colors are located in the src array starting from the srcOffset.
  30729. * The result is placed into the dest array starting from the destOffset.
  30730. * The src array items shall be in [0,2^bits) range, the dest array items
  30731. * will be in [0,255] range. alpha01 indicates how many alpha components
  30732. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  30733. * array).
  30734. */
  30735. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  30736. dest, destOffset, bits,
  30737. alpha01) {
  30738. error('Should not call ColorSpace.getRgbBuffer');
  30739. },
  30740. /**
  30741. * Determines the number of bytes required to store the result of the
  30742. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  30743. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  30744. */
  30745. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  30746. alpha01) {
  30747. error('Should not call ColorSpace.getOutputLength');
  30748. },
  30749. /**
  30750. * Returns true if source data will be equal the result/output data.
  30751. */
  30752. isPassthrough: function ColorSpace_isPassthrough(bits) {
  30753. return false;
  30754. },
  30755. /**
  30756. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  30757. * how many alpha components there are in the dest array; it will be either
  30758. * 0 (RGB array) or 1 (RGBA array).
  30759. */
  30760. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  30761. originalHeight, width, height,
  30762. actualHeight, bpc, comps, alpha01) {
  30763. var count = originalWidth * originalHeight;
  30764. var rgbBuf = null;
  30765. var numComponentColors = 1 << bpc;
  30766. var needsResizing = originalHeight !== height || originalWidth !== width;
  30767. var i, ii;
  30768. if (this.isPassthrough(bpc)) {
  30769. rgbBuf = comps;
  30770. } else if (this.numComps === 1 && count > numComponentColors &&
  30771. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  30772. // Optimization: create a color map when there is just one component and
  30773. // we are converting more colors than the size of the color map. We
  30774. // don't build the map if the colorspace is gray or rgb since those
  30775. // methods are faster than building a map. This mainly offers big speed
  30776. // ups for indexed and alternate colorspaces.
  30777. //
  30778. // TODO it may be worth while to cache the color map. While running
  30779. // testing I never hit a cache so I will leave that out for now (perhaps
  30780. // we are reparsing colorspaces too much?).
  30781. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  30782. new Uint16Array(numComponentColors);
  30783. var key;
  30784. for (i = 0; i < numComponentColors; i++) {
  30785. allColors[i] = i;
  30786. }
  30787. var colorMap = new Uint8Array(numComponentColors * 3);
  30788. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  30789. /* alpha01 = */ 0);
  30790. var destPos, rgbPos;
  30791. if (!needsResizing) {
  30792. // Fill in the RGB values directly into |dest|.
  30793. destPos = 0;
  30794. for (i = 0; i < count; ++i) {
  30795. key = comps[i] * 3;
  30796. dest[destPos++] = colorMap[key];
  30797. dest[destPos++] = colorMap[key + 1];
  30798. dest[destPos++] = colorMap[key + 2];
  30799. destPos += alpha01;
  30800. }
  30801. } else {
  30802. rgbBuf = new Uint8Array(count * 3);
  30803. rgbPos = 0;
  30804. for (i = 0; i < count; ++i) {
  30805. key = comps[i] * 3;
  30806. rgbBuf[rgbPos++] = colorMap[key];
  30807. rgbBuf[rgbPos++] = colorMap[key + 1];
  30808. rgbBuf[rgbPos++] = colorMap[key + 2];
  30809. }
  30810. }
  30811. } else {
  30812. if (!needsResizing) {
  30813. // Fill in the RGB values directly into |dest|.
  30814. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  30815. alpha01);
  30816. } else {
  30817. rgbBuf = new Uint8Array(count * 3);
  30818. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  30819. /* alpha01 = */ 0);
  30820. }
  30821. }
  30822. if (rgbBuf) {
  30823. if (needsResizing) {
  30824. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  30825. height, dest, alpha01);
  30826. } else {
  30827. rgbPos = 0;
  30828. destPos = 0;
  30829. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  30830. dest[destPos++] = rgbBuf[rgbPos++];
  30831. dest[destPos++] = rgbBuf[rgbPos++];
  30832. dest[destPos++] = rgbBuf[rgbPos++];
  30833. destPos += alpha01;
  30834. }
  30835. }
  30836. }
  30837. },
  30838. /**
  30839. * True if the colorspace has components in the default range of [0, 1].
  30840. * This should be true for all colorspaces except for lab color spaces
  30841. * which are [0,100], [-128, 127], [-128, 127].
  30842. */
  30843. usesZeroToOneRange: true
  30844. };
  30845. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  30846. var IR = ColorSpace.parseToIR(cs, xref, res);
  30847. if (IR instanceof AlternateCS) {
  30848. return IR;
  30849. }
  30850. return ColorSpace.fromIR(IR);
  30851. };
  30852. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  30853. var name = isArray(IR) ? IR[0] : IR;
  30854. var whitePoint, blackPoint, gamma;
  30855. switch (name) {
  30856. case 'DeviceGrayCS':
  30857. return this.singletons.gray;
  30858. case 'DeviceRgbCS':
  30859. return this.singletons.rgb;
  30860. case 'DeviceCmykCS':
  30861. return this.singletons.cmyk;
  30862. case 'CalGrayCS':
  30863. whitePoint = IR[1];
  30864. blackPoint = IR[2];
  30865. gamma = IR[3];
  30866. return new CalGrayCS(whitePoint, blackPoint, gamma);
  30867. case 'CalRGBCS':
  30868. whitePoint = IR[1];
  30869. blackPoint = IR[2];
  30870. gamma = IR[3];
  30871. var matrix = IR[4];
  30872. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  30873. case 'PatternCS':
  30874. var basePatternCS = IR[1];
  30875. if (basePatternCS) {
  30876. basePatternCS = ColorSpace.fromIR(basePatternCS);
  30877. }
  30878. return new PatternCS(basePatternCS);
  30879. case 'IndexedCS':
  30880. var baseIndexedCS = IR[1];
  30881. var hiVal = IR[2];
  30882. var lookup = IR[3];
  30883. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  30884. case 'AlternateCS':
  30885. var numComps = IR[1];
  30886. var alt = IR[2];
  30887. var tintFnIR = IR[3];
  30888. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  30889. PDFFunction.fromIR(tintFnIR));
  30890. case 'LabCS':
  30891. whitePoint = IR[1];
  30892. blackPoint = IR[2];
  30893. var range = IR[3];
  30894. return new LabCS(whitePoint, blackPoint, range);
  30895. default:
  30896. error('Unknown name ' + name);
  30897. }
  30898. return null;
  30899. };
  30900. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  30901. if (isName(cs)) {
  30902. var colorSpaces = res.get('ColorSpace');
  30903. if (isDict(colorSpaces)) {
  30904. var refcs = colorSpaces.get(cs.name);
  30905. if (refcs) {
  30906. cs = refcs;
  30907. }
  30908. }
  30909. }
  30910. cs = xref.fetchIfRef(cs);
  30911. var mode;
  30912. if (isName(cs)) {
  30913. mode = cs.name;
  30914. this.mode = mode;
  30915. switch (mode) {
  30916. case 'DeviceGray':
  30917. case 'G':
  30918. return 'DeviceGrayCS';
  30919. case 'DeviceRGB':
  30920. case 'RGB':
  30921. return 'DeviceRgbCS';
  30922. case 'DeviceCMYK':
  30923. case 'CMYK':
  30924. return 'DeviceCmykCS';
  30925. case 'Pattern':
  30926. return ['PatternCS', null];
  30927. default:
  30928. error('unrecognized colorspace ' + mode);
  30929. }
  30930. } else if (isArray(cs)) {
  30931. mode = xref.fetchIfRef(cs[0]).name;
  30932. this.mode = mode;
  30933. var numComps, params, alt, whitePoint, blackPoint, gamma;
  30934. switch (mode) {
  30935. case 'DeviceGray':
  30936. case 'G':
  30937. return 'DeviceGrayCS';
  30938. case 'DeviceRGB':
  30939. case 'RGB':
  30940. return 'DeviceRgbCS';
  30941. case 'DeviceCMYK':
  30942. case 'CMYK':
  30943. return 'DeviceCmykCS';
  30944. case 'CalGray':
  30945. params = xref.fetchIfRef(cs[1]);
  30946. whitePoint = params.get('WhitePoint');
  30947. blackPoint = params.get('BlackPoint');
  30948. gamma = params.get('Gamma');
  30949. return ['CalGrayCS', whitePoint, blackPoint, gamma];
  30950. case 'CalRGB':
  30951. params = xref.fetchIfRef(cs[1]);
  30952. whitePoint = params.get('WhitePoint');
  30953. blackPoint = params.get('BlackPoint');
  30954. gamma = params.get('Gamma');
  30955. var matrix = params.get('Matrix');
  30956. return ['CalRGBCS', whitePoint, blackPoint, gamma, matrix];
  30957. case 'ICCBased':
  30958. var stream = xref.fetchIfRef(cs[1]);
  30959. var dict = stream.dict;
  30960. numComps = dict.get('N');
  30961. alt = dict.get('Alternate');
  30962. if (alt) {
  30963. var altIR = ColorSpace.parseToIR(alt, xref, res);
  30964. // Parse the /Alternate CS to ensure that the number of components
  30965. // are correct, and also (indirectly) that it is not a PatternCS.
  30966. var altCS = ColorSpace.fromIR(altIR);
  30967. if (altCS.numComps === numComps) {
  30968. return altIR;
  30969. }
  30970. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  30971. }
  30972. if (numComps === 1) {
  30973. return 'DeviceGrayCS';
  30974. } else if (numComps === 3) {
  30975. return 'DeviceRgbCS';
  30976. } else if (numComps === 4) {
  30977. return 'DeviceCmykCS';
  30978. }
  30979. break;
  30980. case 'Pattern':
  30981. var basePatternCS = cs[1] || null;
  30982. if (basePatternCS) {
  30983. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  30984. }
  30985. return ['PatternCS', basePatternCS];
  30986. case 'Indexed':
  30987. case 'I':
  30988. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  30989. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  30990. var lookup = xref.fetchIfRef(cs[3]);
  30991. if (isStream(lookup)) {
  30992. lookup = lookup.getBytes();
  30993. }
  30994. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  30995. case 'Separation':
  30996. case 'DeviceN':
  30997. var name = xref.fetchIfRef(cs[1]);
  30998. numComps = 1;
  30999. if (isName(name)) {
  31000. numComps = 1;
  31001. } else if (isArray(name)) {
  31002. numComps = name.length;
  31003. }
  31004. alt = ColorSpace.parseToIR(cs[2], xref, res);
  31005. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  31006. return ['AlternateCS', numComps, alt, tintFnIR];
  31007. case 'Lab':
  31008. params = xref.fetchIfRef(cs[1]);
  31009. whitePoint = params.get('WhitePoint');
  31010. blackPoint = params.get('BlackPoint');
  31011. var range = params.get('Range');
  31012. return ['LabCS', whitePoint, blackPoint, range];
  31013. default:
  31014. error('unimplemented color space object "' + mode + '"');
  31015. }
  31016. } else {
  31017. error('unrecognized color space object: "' + cs + '"');
  31018. }
  31019. return null;
  31020. };
  31021. /**
  31022. * Checks if a decode map matches the default decode map for a color space.
  31023. * This handles the general decode maps where there are two values per
  31024. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  31025. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  31026. * slightly different.
  31027. * @param {Array} decode Decode map (usually from an image).
  31028. * @param {Number} n Number of components the color space has.
  31029. */
  31030. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  31031. if (!isArray(decode)) {
  31032. return true;
  31033. }
  31034. if (n * 2 !== decode.length) {
  31035. warn('The decode map is not the correct length');
  31036. return true;
  31037. }
  31038. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  31039. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  31040. return false;
  31041. }
  31042. }
  31043. return true;
  31044. };
  31045. ColorSpace.singletons = {
  31046. get gray() {
  31047. return shadow(this, 'gray', new DeviceGrayCS());
  31048. },
  31049. get rgb() {
  31050. return shadow(this, 'rgb', new DeviceRgbCS());
  31051. },
  31052. get cmyk() {
  31053. return shadow(this, 'cmyk', new DeviceCmykCS());
  31054. }
  31055. };
  31056. return ColorSpace;
  31057. })();
  31058. /**
  31059. * Alternate color space handles both Separation and DeviceN color spaces. A
  31060. * Separation color space is actually just a DeviceN with one color component.
  31061. * Both color spaces use a tinting function to convert colors to a base color
  31062. * space.
  31063. */
  31064. var AlternateCS = (function AlternateCSClosure() {
  31065. function AlternateCS(numComps, base, tintFn) {
  31066. this.name = 'Alternate';
  31067. this.numComps = numComps;
  31068. this.defaultColor = new Float32Array(numComps);
  31069. for (var i = 0; i < numComps; ++i) {
  31070. this.defaultColor[i] = 1;
  31071. }
  31072. this.base = base;
  31073. this.tintFn = tintFn;
  31074. this.tmpBuf = new Float32Array(base.numComps);
  31075. }
  31076. AlternateCS.prototype = {
  31077. getRgb: ColorSpace.prototype.getRgb,
  31078. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  31079. dest, destOffset) {
  31080. var tmpBuf = this.tmpBuf;
  31081. this.tintFn(src, srcOffset, tmpBuf, 0);
  31082. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  31083. },
  31084. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  31085. dest, destOffset, bits,
  31086. alpha01) {
  31087. var tintFn = this.tintFn;
  31088. var base = this.base;
  31089. var scale = 1 / ((1 << bits) - 1);
  31090. var baseNumComps = base.numComps;
  31091. var usesZeroToOneRange = base.usesZeroToOneRange;
  31092. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  31093. alpha01 === 0;
  31094. var pos = isPassthrough ? destOffset : 0;
  31095. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  31096. var numComps = this.numComps;
  31097. var scaled = new Float32Array(numComps);
  31098. var tinted = new Float32Array(baseNumComps);
  31099. var i, j;
  31100. if (usesZeroToOneRange) {
  31101. for (i = 0; i < count; i++) {
  31102. for (j = 0; j < numComps; j++) {
  31103. scaled[j] = src[srcOffset++] * scale;
  31104. }
  31105. tintFn(scaled, 0, tinted, 0);
  31106. for (j = 0; j < baseNumComps; j++) {
  31107. baseBuf[pos++] = tinted[j] * 255;
  31108. }
  31109. }
  31110. } else {
  31111. for (i = 0; i < count; i++) {
  31112. for (j = 0; j < numComps; j++) {
  31113. scaled[j] = src[srcOffset++] * scale;
  31114. }
  31115. tintFn(scaled, 0, tinted, 0);
  31116. base.getRgbItem(tinted, 0, baseBuf, pos);
  31117. pos += baseNumComps;
  31118. }
  31119. }
  31120. if (!isPassthrough) {
  31121. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  31122. }
  31123. },
  31124. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  31125. alpha01) {
  31126. return this.base.getOutputLength(inputLength *
  31127. this.base.numComps / this.numComps,
  31128. alpha01);
  31129. },
  31130. isPassthrough: ColorSpace.prototype.isPassthrough,
  31131. fillRgb: ColorSpace.prototype.fillRgb,
  31132. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  31133. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31134. },
  31135. usesZeroToOneRange: true
  31136. };
  31137. return AlternateCS;
  31138. })();
  31139. var PatternCS = (function PatternCSClosure() {
  31140. function PatternCS(baseCS) {
  31141. this.name = 'Pattern';
  31142. this.base = baseCS;
  31143. }
  31144. PatternCS.prototype = {};
  31145. return PatternCS;
  31146. })();
  31147. var IndexedCS = (function IndexedCSClosure() {
  31148. function IndexedCS(base, highVal, lookup) {
  31149. this.name = 'Indexed';
  31150. this.numComps = 1;
  31151. this.defaultColor = new Uint8Array([0]);
  31152. this.base = base;
  31153. this.highVal = highVal;
  31154. var baseNumComps = base.numComps;
  31155. var length = baseNumComps * highVal;
  31156. var lookupArray;
  31157. if (isStream(lookup)) {
  31158. lookupArray = new Uint8Array(length);
  31159. var bytes = lookup.getBytes(length);
  31160. lookupArray.set(bytes);
  31161. } else if (isString(lookup)) {
  31162. lookupArray = new Uint8Array(length);
  31163. for (var i = 0; i < length; ++i) {
  31164. lookupArray[i] = lookup.charCodeAt(i);
  31165. }
  31166. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  31167. lookupArray = lookup;
  31168. } else {
  31169. error('Unrecognized lookup table: ' + lookup);
  31170. }
  31171. this.lookup = lookupArray;
  31172. }
  31173. IndexedCS.prototype = {
  31174. getRgb: ColorSpace.prototype.getRgb,
  31175. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  31176. dest, destOffset) {
  31177. var numComps = this.base.numComps;
  31178. var start = src[srcOffset] * numComps;
  31179. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  31180. },
  31181. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  31182. dest, destOffset, bits,
  31183. alpha01) {
  31184. var base = this.base;
  31185. var numComps = base.numComps;
  31186. var outputDelta = base.getOutputLength(numComps, alpha01);
  31187. var lookup = this.lookup;
  31188. for (var i = 0; i < count; ++i) {
  31189. var lookupPos = src[srcOffset++] * numComps;
  31190. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  31191. destOffset += outputDelta;
  31192. }
  31193. },
  31194. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  31195. return this.base.getOutputLength(inputLength * this.base.numComps,
  31196. alpha01);
  31197. },
  31198. isPassthrough: ColorSpace.prototype.isPassthrough,
  31199. fillRgb: ColorSpace.prototype.fillRgb,
  31200. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  31201. // indexed color maps shouldn't be changed
  31202. return true;
  31203. },
  31204. usesZeroToOneRange: true
  31205. };
  31206. return IndexedCS;
  31207. })();
  31208. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  31209. function DeviceGrayCS() {
  31210. this.name = 'DeviceGray';
  31211. this.numComps = 1;
  31212. this.defaultColor = new Float32Array([0]);
  31213. }
  31214. DeviceGrayCS.prototype = {
  31215. getRgb: ColorSpace.prototype.getRgb,
  31216. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  31217. dest, destOffset) {
  31218. var c = (src[srcOffset] * 255) | 0;
  31219. c = c < 0 ? 0 : c > 255 ? 255 : c;
  31220. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  31221. },
  31222. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  31223. dest, destOffset, bits,
  31224. alpha01) {
  31225. var scale = 255 / ((1 << bits) - 1);
  31226. var j = srcOffset, q = destOffset;
  31227. for (var i = 0; i < count; ++i) {
  31228. var c = (scale * src[j++]) | 0;
  31229. dest[q++] = c;
  31230. dest[q++] = c;
  31231. dest[q++] = c;
  31232. q += alpha01;
  31233. }
  31234. },
  31235. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  31236. alpha01) {
  31237. return inputLength * (3 + alpha01);
  31238. },
  31239. isPassthrough: ColorSpace.prototype.isPassthrough,
  31240. fillRgb: ColorSpace.prototype.fillRgb,
  31241. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  31242. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31243. },
  31244. usesZeroToOneRange: true
  31245. };
  31246. return DeviceGrayCS;
  31247. })();
  31248. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  31249. function DeviceRgbCS() {
  31250. this.name = 'DeviceRGB';
  31251. this.numComps = 3;
  31252. this.defaultColor = new Float32Array([0, 0, 0]);
  31253. }
  31254. DeviceRgbCS.prototype = {
  31255. getRgb: ColorSpace.prototype.getRgb,
  31256. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  31257. dest, destOffset) {
  31258. var r = (src[srcOffset] * 255) | 0;
  31259. var g = (src[srcOffset + 1] * 255) | 0;
  31260. var b = (src[srcOffset + 2] * 255) | 0;
  31261. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  31262. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  31263. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  31264. },
  31265. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  31266. dest, destOffset, bits,
  31267. alpha01) {
  31268. if (bits === 8 && alpha01 === 0) {
  31269. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  31270. return;
  31271. }
  31272. var scale = 255 / ((1 << bits) - 1);
  31273. var j = srcOffset, q = destOffset;
  31274. for (var i = 0; i < count; ++i) {
  31275. dest[q++] = (scale * src[j++]) | 0;
  31276. dest[q++] = (scale * src[j++]) | 0;
  31277. dest[q++] = (scale * src[j++]) | 0;
  31278. q += alpha01;
  31279. }
  31280. },
  31281. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  31282. alpha01) {
  31283. return (inputLength * (3 + alpha01) / 3) | 0;
  31284. },
  31285. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  31286. return bits === 8;
  31287. },
  31288. fillRgb: ColorSpace.prototype.fillRgb,
  31289. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  31290. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31291. },
  31292. usesZeroToOneRange: true
  31293. };
  31294. return DeviceRgbCS;
  31295. })();
  31296. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  31297. // The coefficients below was found using numerical analysis: the method of
  31298. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  31299. // where color_value is the tabular value from the table of sampled RGB colors
  31300. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  31301. // CMYK color conversion using the estimation below:
  31302. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  31303. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  31304. var c = src[srcOffset + 0] * srcScale;
  31305. var m = src[srcOffset + 1] * srcScale;
  31306. var y = src[srcOffset + 2] * srcScale;
  31307. var k = src[srcOffset + 3] * srcScale;
  31308. var r =
  31309. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  31310. 18.82290502165302 * y + 212.25662451639585 * k +
  31311. -285.2331026137004) +
  31312. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  31313. -17.873870861415444 * k - 5.497006427196366) +
  31314. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  31315. 17.5119270841813) +
  31316. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  31317. var g =
  31318. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  31319. 6.871425592049007 * y + 31.159100130055922 * k +
  31320. -79.2970844816548) +
  31321. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  31322. 131.35250912493976 * k - 190.9453302588951) +
  31323. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  31324. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  31325. var b =
  31326. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  31327. 30.89978309703729 * y - 0.23883238689178934 * k +
  31328. -14.183576799673286) +
  31329. m * (10.49593273432072 * m + 63.02378494754052 * y +
  31330. 50.606957656360734 * k - 112.23884253719248) +
  31331. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  31332. -193.58209356861505) +
  31333. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  31334. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  31335. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  31336. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  31337. }
  31338. function DeviceCmykCS() {
  31339. this.name = 'DeviceCMYK';
  31340. this.numComps = 4;
  31341. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  31342. }
  31343. DeviceCmykCS.prototype = {
  31344. getRgb: ColorSpace.prototype.getRgb,
  31345. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  31346. dest, destOffset) {
  31347. convertToRgb(src, srcOffset, 1, dest, destOffset);
  31348. },
  31349. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  31350. dest, destOffset, bits,
  31351. alpha01) {
  31352. var scale = 1 / ((1 << bits) - 1);
  31353. for (var i = 0; i < count; i++) {
  31354. convertToRgb(src, srcOffset, scale, dest, destOffset);
  31355. srcOffset += 4;
  31356. destOffset += 3 + alpha01;
  31357. }
  31358. },
  31359. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  31360. alpha01) {
  31361. return (inputLength / 4 * (3 + alpha01)) | 0;
  31362. },
  31363. isPassthrough: ColorSpace.prototype.isPassthrough,
  31364. fillRgb: ColorSpace.prototype.fillRgb,
  31365. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  31366. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31367. },
  31368. usesZeroToOneRange: true
  31369. };
  31370. return DeviceCmykCS;
  31371. })();
  31372. //
  31373. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  31374. //
  31375. var CalGrayCS = (function CalGrayCSClosure() {
  31376. function CalGrayCS(whitePoint, blackPoint, gamma) {
  31377. this.name = 'CalGray';
  31378. this.numComps = 1;
  31379. this.defaultColor = new Float32Array([0]);
  31380. if (!whitePoint) {
  31381. error('WhitePoint missing - required for color space CalGray');
  31382. }
  31383. blackPoint = blackPoint || [0, 0, 0];
  31384. gamma = gamma || 1;
  31385. // Translate arguments to spec variables.
  31386. this.XW = whitePoint[0];
  31387. this.YW = whitePoint[1];
  31388. this.ZW = whitePoint[2];
  31389. this.XB = blackPoint[0];
  31390. this.YB = blackPoint[1];
  31391. this.ZB = blackPoint[2];
  31392. this.G = gamma;
  31393. // Validate variables as per spec.
  31394. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  31395. error('Invalid WhitePoint components for ' + this.name +
  31396. ', no fallback available');
  31397. }
  31398. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  31399. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  31400. this.XB = this.YB = this.ZB = 0;
  31401. }
  31402. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  31403. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  31404. ', ZB: ' + this.ZB + ', only default values are supported.');
  31405. }
  31406. if (this.G < 1) {
  31407. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  31408. ', falling back to default');
  31409. this.G = 1;
  31410. }
  31411. }
  31412. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  31413. // A represents a gray component of a calibrated gray space.
  31414. // A <---> AG in the spec
  31415. var A = src[srcOffset] * scale;
  31416. var AG = Math.pow(A, cs.G);
  31417. // Computes L as per spec. ( = cs.YW * AG )
  31418. // Except if other than default BlackPoint values are used.
  31419. var L = cs.YW * AG;
  31420. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  31421. // Convert values to rgb range [0, 255].
  31422. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  31423. dest[destOffset] = val;
  31424. dest[destOffset + 1] = val;
  31425. dest[destOffset + 2] = val;
  31426. }
  31427. CalGrayCS.prototype = {
  31428. getRgb: ColorSpace.prototype.getRgb,
  31429. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  31430. dest, destOffset) {
  31431. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  31432. },
  31433. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  31434. dest, destOffset, bits,
  31435. alpha01) {
  31436. var scale = 1 / ((1 << bits) - 1);
  31437. for (var i = 0; i < count; ++i) {
  31438. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  31439. srcOffset += 1;
  31440. destOffset += 3 + alpha01;
  31441. }
  31442. },
  31443. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  31444. return inputLength * (3 + alpha01);
  31445. },
  31446. isPassthrough: ColorSpace.prototype.isPassthrough,
  31447. fillRgb: ColorSpace.prototype.fillRgb,
  31448. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  31449. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31450. },
  31451. usesZeroToOneRange: true
  31452. };
  31453. return CalGrayCS;
  31454. })();
  31455. //
  31456. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  31457. //
  31458. var CalRGBCS = (function CalRGBCSClosure() {
  31459. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  31460. // matrices.
  31461. var BRADFORD_SCALE_MATRIX = new Float32Array([
  31462. 0.8951, 0.2664, -0.1614,
  31463. -0.7502, 1.7135, 0.0367,
  31464. 0.0389, -0.0685, 1.0296]);
  31465. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  31466. 0.9869929, -0.1470543, 0.1599627,
  31467. 0.4323053, 0.5183603, 0.0492912,
  31468. -0.0085287, 0.0400428, 0.9684867]);
  31469. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  31470. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  31471. 3.2404542, -1.5371385, -0.4985314,
  31472. -0.9692660, 1.8760108, 0.0415560,
  31473. 0.0556434, -0.2040259, 1.0572252]);
  31474. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  31475. var tempNormalizeMatrix = new Float32Array(3);
  31476. var tempConvertMatrix1 = new Float32Array(3);
  31477. var tempConvertMatrix2 = new Float32Array(3);
  31478. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  31479. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  31480. this.name = 'CalRGB';
  31481. this.numComps = 3;
  31482. this.defaultColor = new Float32Array(3);
  31483. if (!whitePoint) {
  31484. error('WhitePoint missing - required for color space CalRGB');
  31485. }
  31486. blackPoint = blackPoint || new Float32Array(3);
  31487. gamma = gamma || new Float32Array([1, 1, 1]);
  31488. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  31489. // Translate arguments to spec variables.
  31490. var XW = whitePoint[0];
  31491. var YW = whitePoint[1];
  31492. var ZW = whitePoint[2];
  31493. this.whitePoint = whitePoint;
  31494. var XB = blackPoint[0];
  31495. var YB = blackPoint[1];
  31496. var ZB = blackPoint[2];
  31497. this.blackPoint = blackPoint;
  31498. this.GR = gamma[0];
  31499. this.GG = gamma[1];
  31500. this.GB = gamma[2];
  31501. this.MXA = matrix[0];
  31502. this.MYA = matrix[1];
  31503. this.MZA = matrix[2];
  31504. this.MXB = matrix[3];
  31505. this.MYB = matrix[4];
  31506. this.MZB = matrix[5];
  31507. this.MXC = matrix[6];
  31508. this.MYC = matrix[7];
  31509. this.MZC = matrix[8];
  31510. // Validate variables as per spec.
  31511. if (XW < 0 || ZW < 0 || YW !== 1) {
  31512. error('Invalid WhitePoint components for ' + this.name +
  31513. ', no fallback available');
  31514. }
  31515. if (XB < 0 || YB < 0 || ZB < 0) {
  31516. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  31517. ', ' + ZB + '], falling back to default');
  31518. this.blackPoint = new Float32Array(3);
  31519. }
  31520. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  31521. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  31522. '] for ' + this.name + ', falling back to default');
  31523. this.GR = this.GG = this.GB = 1;
  31524. }
  31525. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  31526. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  31527. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  31528. info('Invalid Matrix for ' + this.name + ' [' +
  31529. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  31530. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  31531. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  31532. '], falling back to default');
  31533. this.MXA = this.MYB = this.MZC = 1;
  31534. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  31535. }
  31536. }
  31537. function matrixProduct(a, b, result) {
  31538. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  31539. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  31540. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  31541. }
  31542. function convertToFlat(sourceWhitePoint, LMS, result) {
  31543. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  31544. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  31545. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  31546. }
  31547. function convertToD65(sourceWhitePoint, LMS, result) {
  31548. var D65X = 0.95047;
  31549. var D65Y = 1;
  31550. var D65Z = 1.08883;
  31551. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  31552. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  31553. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  31554. }
  31555. function sRGBTransferFunction(color) {
  31556. // See http://en.wikipedia.org/wiki/SRGB.
  31557. if (color <= 0.0031308){
  31558. return adjustToRange(0, 1, 12.92 * color);
  31559. }
  31560. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  31561. }
  31562. function adjustToRange(min, max, value) {
  31563. return Math.max(min, Math.min(max, value));
  31564. }
  31565. function decodeL(L) {
  31566. if (L < 0) {
  31567. return -decodeL(-L);
  31568. }
  31569. if (L > 8.0) {
  31570. return Math.pow(((L + 16) / 116), 3);
  31571. }
  31572. return L * DECODE_L_CONSTANT;
  31573. }
  31574. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  31575. // In case the blackPoint is already the default blackPoint then there is
  31576. // no need to do compensation.
  31577. if (sourceBlackPoint[0] === 0 &&
  31578. sourceBlackPoint[1] === 0 &&
  31579. sourceBlackPoint[2] === 0) {
  31580. result[0] = XYZ_Flat[0];
  31581. result[1] = XYZ_Flat[1];
  31582. result[2] = XYZ_Flat[2];
  31583. return;
  31584. }
  31585. // For the blackPoint calculation details, please see
  31586. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  31587. // AdobeBPC.pdf.
  31588. // The destination blackPoint is the default blackPoint [0, 0, 0].
  31589. var zeroDecodeL = decodeL(0);
  31590. var X_DST = zeroDecodeL;
  31591. var X_SRC = decodeL(sourceBlackPoint[0]);
  31592. var Y_DST = zeroDecodeL;
  31593. var Y_SRC = decodeL(sourceBlackPoint[1]);
  31594. var Z_DST = zeroDecodeL;
  31595. var Z_SRC = decodeL(sourceBlackPoint[2]);
  31596. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  31597. var X_Offset = 1 - X_Scale;
  31598. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  31599. var Y_Offset = 1 - Y_Scale;
  31600. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  31601. var Z_Offset = 1 - Z_Scale;
  31602. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  31603. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  31604. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  31605. }
  31606. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  31607. // In case the whitePoint is already flat then there is no need to do
  31608. // normalization.
  31609. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  31610. result[0] = XYZ_In[0];
  31611. result[1] = XYZ_In[1];
  31612. result[2] = XYZ_In[2];
  31613. return;
  31614. }
  31615. var LMS = result;
  31616. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  31617. var LMS_Flat = tempNormalizeMatrix;
  31618. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  31619. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  31620. }
  31621. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  31622. var LMS = result;
  31623. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  31624. var LMS_D65 = tempNormalizeMatrix;
  31625. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  31626. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  31627. }
  31628. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  31629. // A, B and C represent a red, green and blue components of a calibrated
  31630. // rgb space.
  31631. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  31632. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  31633. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  31634. // A <---> AGR in the spec
  31635. // B <---> BGG in the spec
  31636. // C <---> CGB in the spec
  31637. var AGR = Math.pow(A, cs.GR);
  31638. var BGG = Math.pow(B, cs.GG);
  31639. var CGB = Math.pow(C, cs.GB);
  31640. // Computes intermediate variables L, M, N as per spec.
  31641. // To decode X, Y, Z values map L, M, N directly to them.
  31642. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  31643. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  31644. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  31645. // The following calculations are based on this document:
  31646. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  31647. // AdobeBPC.pdf.
  31648. var XYZ = tempConvertMatrix1;
  31649. XYZ[0] = X;
  31650. XYZ[1] = Y;
  31651. XYZ[2] = Z;
  31652. var XYZ_Flat = tempConvertMatrix2;
  31653. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  31654. var XYZ_Black = tempConvertMatrix1;
  31655. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  31656. var XYZ_D65 = tempConvertMatrix2;
  31657. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  31658. var SRGB = tempConvertMatrix1;
  31659. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  31660. var sR = sRGBTransferFunction(SRGB[0]);
  31661. var sG = sRGBTransferFunction(SRGB[1]);
  31662. var sB = sRGBTransferFunction(SRGB[2]);
  31663. // Convert the values to rgb range [0, 255].
  31664. dest[destOffset] = Math.round(sR * 255);
  31665. dest[destOffset + 1] = Math.round(sG * 255);
  31666. dest[destOffset + 2] = Math.round(sB * 255);
  31667. }
  31668. CalRGBCS.prototype = {
  31669. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  31670. var rgb = new Uint8Array(3);
  31671. this.getRgbItem(src, srcOffset, rgb, 0);
  31672. return rgb;
  31673. },
  31674. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  31675. dest, destOffset) {
  31676. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  31677. },
  31678. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  31679. dest, destOffset, bits,
  31680. alpha01) {
  31681. var scale = 1 / ((1 << bits) - 1);
  31682. for (var i = 0; i < count; ++i) {
  31683. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  31684. srcOffset += 3;
  31685. destOffset += 3 + alpha01;
  31686. }
  31687. },
  31688. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  31689. return (inputLength * (3 + alpha01) / 3) | 0;
  31690. },
  31691. isPassthrough: ColorSpace.prototype.isPassthrough,
  31692. fillRgb: ColorSpace.prototype.fillRgb,
  31693. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  31694. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31695. },
  31696. usesZeroToOneRange: true
  31697. };
  31698. return CalRGBCS;
  31699. })();
  31700. //
  31701. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  31702. //
  31703. var LabCS = (function LabCSClosure() {
  31704. function LabCS(whitePoint, blackPoint, range) {
  31705. this.name = 'Lab';
  31706. this.numComps = 3;
  31707. this.defaultColor = new Float32Array([0, 0, 0]);
  31708. if (!whitePoint) {
  31709. error('WhitePoint missing - required for color space Lab');
  31710. }
  31711. blackPoint = blackPoint || [0, 0, 0];
  31712. range = range || [-100, 100, -100, 100];
  31713. // Translate args to spec variables
  31714. this.XW = whitePoint[0];
  31715. this.YW = whitePoint[1];
  31716. this.ZW = whitePoint[2];
  31717. this.amin = range[0];
  31718. this.amax = range[1];
  31719. this.bmin = range[2];
  31720. this.bmax = range[3];
  31721. // These are here just for completeness - the spec doesn't offer any
  31722. // formulas that use BlackPoint in Lab
  31723. this.XB = blackPoint[0];
  31724. this.YB = blackPoint[1];
  31725. this.ZB = blackPoint[2];
  31726. // Validate vars as per spec
  31727. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  31728. error('Invalid WhitePoint components, no fallback available');
  31729. }
  31730. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  31731. info('Invalid BlackPoint, falling back to default');
  31732. this.XB = this.YB = this.ZB = 0;
  31733. }
  31734. if (this.amin > this.amax || this.bmin > this.bmax) {
  31735. info('Invalid Range, falling back to defaults');
  31736. this.amin = -100;
  31737. this.amax = 100;
  31738. this.bmin = -100;
  31739. this.bmax = 100;
  31740. }
  31741. }
  31742. // Function g(x) from spec
  31743. function fn_g(x) {
  31744. if (x >= 6 / 29) {
  31745. return x * x * x;
  31746. } else {
  31747. return (108 / 841) * (x - 4 / 29);
  31748. }
  31749. }
  31750. function decode(value, high1, low2, high2) {
  31751. return low2 + (value) * (high2 - low2) / (high1);
  31752. }
  31753. // If decoding is needed maxVal should be 2^bits per component - 1.
  31754. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  31755. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  31756. // not the usual [0, 1]. If a command like setFillColor is used the src
  31757. // values will already be within the correct range. However, if we are
  31758. // converting an image we have to map the values to the correct range given
  31759. // above.
  31760. // Ls,as,bs <---> L*,a*,b* in the spec
  31761. var Ls = src[srcOffset];
  31762. var as = src[srcOffset + 1];
  31763. var bs = src[srcOffset + 2];
  31764. if (maxVal !== false) {
  31765. Ls = decode(Ls, maxVal, 0, 100);
  31766. as = decode(as, maxVal, cs.amin, cs.amax);
  31767. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  31768. }
  31769. // Adjust limits of 'as' and 'bs'
  31770. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  31771. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  31772. // Computes intermediate variables X,Y,Z as per spec
  31773. var M = (Ls + 16) / 116;
  31774. var L = M + (as / 500);
  31775. var N = M - (bs / 200);
  31776. var X = cs.XW * fn_g(L);
  31777. var Y = cs.YW * fn_g(M);
  31778. var Z = cs.ZW * fn_g(N);
  31779. var r, g, b;
  31780. // Using different conversions for D50 and D65 white points,
  31781. // per http://www.color.org/srgb.pdf
  31782. if (cs.ZW < 1) {
  31783. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  31784. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  31785. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  31786. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  31787. } else {
  31788. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  31789. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  31790. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  31791. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  31792. }
  31793. // clamp color values to [0,1] range then convert to [0,255] range.
  31794. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  31795. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  31796. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  31797. }
  31798. LabCS.prototype = {
  31799. getRgb: ColorSpace.prototype.getRgb,
  31800. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  31801. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  31802. },
  31803. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  31804. dest, destOffset, bits,
  31805. alpha01) {
  31806. var maxVal = (1 << bits) - 1;
  31807. for (var i = 0; i < count; i++) {
  31808. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  31809. srcOffset += 3;
  31810. destOffset += 3 + alpha01;
  31811. }
  31812. },
  31813. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  31814. return (inputLength * (3 + alpha01) / 3) | 0;
  31815. },
  31816. isPassthrough: ColorSpace.prototype.isPassthrough,
  31817. fillRgb: ColorSpace.prototype.fillRgb,
  31818. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  31819. // XXX: Decoding is handled with the lab conversion because of the strange
  31820. // ranges that are used.
  31821. return true;
  31822. },
  31823. usesZeroToOneRange: false
  31824. };
  31825. return LabCS;
  31826. })();
  31827. // TODO refactor to remove dependency on image.js
  31828. function _setCoreImage(coreImage_) {
  31829. coreImage = coreImage_;
  31830. PDFImage = coreImage_.PDFImage;
  31831. }
  31832. exports._setCoreImage = _setCoreImage;
  31833. exports.ColorSpace = ColorSpace;
  31834. // TODO refactor to remove dependency on colorspace.js
  31835. coreStream._setCoreColorSpace(exports);
  31836. }));
  31837. (function (root, factory) {
  31838. {
  31839. factory((root.pdfjsCoreImage = {}), root.pdfjsSharedUtil,
  31840. root.pdfjsCorePrimitives, root.pdfjsCoreColorSpace, root.pdfjsCoreStream,
  31841. root.pdfjsCoreJpx);
  31842. }
  31843. }(this, function (exports, sharedUtil, corePrimitives, coreColorSpace,
  31844. coreStream, coreJpx) {
  31845. var ImageKind = sharedUtil.ImageKind;
  31846. var assert = sharedUtil.assert;
  31847. var error = sharedUtil.error;
  31848. var info = sharedUtil.info;
  31849. var isArray = sharedUtil.isArray;
  31850. var warn = sharedUtil.warn;
  31851. var Name = corePrimitives.Name;
  31852. var isStream = corePrimitives.isStream;
  31853. var ColorSpace = coreColorSpace.ColorSpace;
  31854. var DecodeStream = coreStream.DecodeStream;
  31855. var Stream = coreStream.Stream;
  31856. var JpegStream = coreStream.JpegStream;
  31857. var JpxImage = coreJpx.JpxImage;
  31858. var PDFImage = (function PDFImageClosure() {
  31859. /**
  31860. * Decode the image in the main thread if it supported. Resovles the promise
  31861. * when the image data is ready.
  31862. */
  31863. function handleImageData(handler, xref, res, image) {
  31864. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  31865. // For natively supported jpegs send them to the main thread for decoding.
  31866. var dict = image.dict;
  31867. var colorSpace = dict.get('ColorSpace', 'CS');
  31868. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  31869. var numComps = colorSpace.numComps;
  31870. var decodePromise = handler.sendWithPromise('JpegDecode',
  31871. [image.getIR(), numComps]);
  31872. return decodePromise.then(function (message) {
  31873. var data = message.data;
  31874. return new Stream(data, 0, data.length, image.dict);
  31875. });
  31876. } else {
  31877. return Promise.resolve(image);
  31878. }
  31879. }
  31880. /**
  31881. * Decode and clamp a value. The formula is different from the spec because we
  31882. * don't decode to float range [0,1], we decode it in the [0,max] range.
  31883. */
  31884. function decodeAndClamp(value, addend, coefficient, max) {
  31885. value = addend + value * coefficient;
  31886. // Clamp the value to the range
  31887. return (value < 0 ? 0 : (value > max ? max : value));
  31888. }
  31889. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  31890. this.image = image;
  31891. var dict = image.dict;
  31892. if (dict.has('Filter')) {
  31893. var filter = dict.get('Filter').name;
  31894. if (filter === 'JPXDecode') {
  31895. var jpxImage = new JpxImage();
  31896. jpxImage.parseImageProperties(image.stream);
  31897. image.stream.reset();
  31898. image.bitsPerComponent = jpxImage.bitsPerComponent;
  31899. image.numComps = jpxImage.componentsCount;
  31900. } else if (filter === 'JBIG2Decode') {
  31901. image.bitsPerComponent = 1;
  31902. image.numComps = 1;
  31903. }
  31904. }
  31905. // TODO cache rendered images?
  31906. this.width = dict.get('Width', 'W');
  31907. this.height = dict.get('Height', 'H');
  31908. if (this.width < 1 || this.height < 1) {
  31909. error('Invalid image width: ' + this.width + ' or height: ' +
  31910. this.height);
  31911. }
  31912. this.interpolate = dict.get('Interpolate', 'I') || false;
  31913. this.imageMask = dict.get('ImageMask', 'IM') || false;
  31914. this.matte = dict.get('Matte') || false;
  31915. var bitsPerComponent = image.bitsPerComponent;
  31916. if (!bitsPerComponent) {
  31917. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  31918. if (!bitsPerComponent) {
  31919. if (this.imageMask) {
  31920. bitsPerComponent = 1;
  31921. } else {
  31922. error('Bits per component missing in image: ' + this.imageMask);
  31923. }
  31924. }
  31925. }
  31926. this.bpc = bitsPerComponent;
  31927. if (!this.imageMask) {
  31928. var colorSpace = dict.get('ColorSpace', 'CS');
  31929. if (!colorSpace) {
  31930. info('JPX images (which do not require color spaces)');
  31931. switch (image.numComps) {
  31932. case 1:
  31933. colorSpace = Name.get('DeviceGray');
  31934. break;
  31935. case 3:
  31936. colorSpace = Name.get('DeviceRGB');
  31937. break;
  31938. case 4:
  31939. colorSpace = Name.get('DeviceCMYK');
  31940. break;
  31941. default:
  31942. error('JPX images with ' + this.numComps +
  31943. ' color components not supported.');
  31944. }
  31945. }
  31946. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  31947. this.numComps = this.colorSpace.numComps;
  31948. }
  31949. this.decode = dict.get('Decode', 'D');
  31950. this.needsDecode = false;
  31951. if (this.decode &&
  31952. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  31953. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  31954. this.needsDecode = true;
  31955. // Do some preprocessing to avoid more math.
  31956. var max = (1 << bitsPerComponent) - 1;
  31957. this.decodeCoefficients = [];
  31958. this.decodeAddends = [];
  31959. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  31960. var dmin = this.decode[i];
  31961. var dmax = this.decode[i + 1];
  31962. this.decodeCoefficients[j] = dmax - dmin;
  31963. this.decodeAddends[j] = max * dmin;
  31964. }
  31965. }
  31966. if (smask) {
  31967. this.smask = new PDFImage(xref, res, smask, false);
  31968. } else if (mask) {
  31969. if (isStream(mask)) {
  31970. var maskDict = mask.dict, imageMask = maskDict.get('ImageMask', 'IM');
  31971. if (!imageMask) {
  31972. warn('Ignoring /Mask in image without /ImageMask.');
  31973. } else {
  31974. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  31975. }
  31976. } else {
  31977. // Color key mask (just an array).
  31978. this.mask = mask;
  31979. }
  31980. }
  31981. }
  31982. /**
  31983. * Handles processing of image data and returns the Promise that is resolved
  31984. * with a PDFImage when the image is ready to be used.
  31985. */
  31986. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  31987. res, image, inline) {
  31988. var imagePromise = handleImageData(handler, xref, res, image);
  31989. var smaskPromise;
  31990. var maskPromise;
  31991. var smask = image.dict.get('SMask');
  31992. var mask = image.dict.get('Mask');
  31993. if (smask) {
  31994. smaskPromise = handleImageData(handler, xref, res, smask);
  31995. maskPromise = Promise.resolve(null);
  31996. } else {
  31997. smaskPromise = Promise.resolve(null);
  31998. if (mask) {
  31999. if (isStream(mask)) {
  32000. maskPromise = handleImageData(handler, xref, res, mask);
  32001. } else if (isArray(mask)) {
  32002. maskPromise = Promise.resolve(mask);
  32003. } else {
  32004. warn('Unsupported mask format.');
  32005. maskPromise = Promise.resolve(null);
  32006. }
  32007. } else {
  32008. maskPromise = Promise.resolve(null);
  32009. }
  32010. }
  32011. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  32012. function(results) {
  32013. var imageData = results[0];
  32014. var smaskData = results[1];
  32015. var maskData = results[2];
  32016. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  32017. });
  32018. };
  32019. /**
  32020. * Resize an image using the nearest neighbor algorithm. Currently only
  32021. * supports one and three component images.
  32022. * @param {TypedArray} pixels The original image with one component.
  32023. * @param {Number} bpc Number of bits per component.
  32024. * @param {Number} components Number of color components, 1 or 3 is supported.
  32025. * @param {Number} w1 Original width.
  32026. * @param {Number} h1 Original height.
  32027. * @param {Number} w2 New width.
  32028. * @param {Number} h2 New height.
  32029. * @param {TypedArray} dest (Optional) The destination buffer.
  32030. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  32031. * @return {TypedArray} Resized image data.
  32032. */
  32033. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  32034. w1, h1, w2, h2, dest, alpha01) {
  32035. if (components !== 1 && components !== 3) {
  32036. error('Unsupported component count for resizing.');
  32037. }
  32038. var length = w2 * h2 * components;
  32039. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  32040. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  32041. var xRatio = w1 / w2;
  32042. var yRatio = h1 / h2;
  32043. var i, j, py, newIndex = 0, oldIndex;
  32044. var xScaled = new Uint16Array(w2);
  32045. var w1Scanline = w1 * components;
  32046. if (alpha01 !== 1) {
  32047. alpha01 = 0;
  32048. }
  32049. for (j = 0; j < w2; j++) {
  32050. xScaled[j] = Math.floor(j * xRatio) * components;
  32051. }
  32052. if (components === 1) {
  32053. for (i = 0; i < h2; i++) {
  32054. py = Math.floor(i * yRatio) * w1Scanline;
  32055. for (j = 0; j < w2; j++) {
  32056. oldIndex = py + xScaled[j];
  32057. temp[newIndex++] = pixels[oldIndex];
  32058. }
  32059. }
  32060. } else if (components === 3) {
  32061. for (i = 0; i < h2; i++) {
  32062. py = Math.floor(i * yRatio) * w1Scanline;
  32063. for (j = 0; j < w2; j++) {
  32064. oldIndex = py + xScaled[j];
  32065. temp[newIndex++] = pixels[oldIndex++];
  32066. temp[newIndex++] = pixels[oldIndex++];
  32067. temp[newIndex++] = pixels[oldIndex++];
  32068. newIndex += alpha01;
  32069. }
  32070. }
  32071. }
  32072. return temp;
  32073. };
  32074. PDFImage.createMask =
  32075. function PDFImage_createMask(imgArray, width, height,
  32076. imageIsFromDecodeStream, inverseDecode) {
  32077. // |imgArray| might not contain full data for every pixel of the mask, so
  32078. // we need to distinguish between |computedLength| and |actualLength|.
  32079. // In particular, if inverseDecode is true, then the array we return must
  32080. // have a length of |computedLength|.
  32081. var computedLength = ((width + 7) >> 3) * height;
  32082. var actualLength = imgArray.byteLength;
  32083. var haveFullData = computedLength === actualLength;
  32084. var data, i;
  32085. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  32086. // imgArray came from a DecodeStream and its data is in an appropriate
  32087. // form, so we can just transfer it.
  32088. data = imgArray;
  32089. } else if (!inverseDecode) {
  32090. data = new Uint8Array(actualLength);
  32091. data.set(imgArray);
  32092. } else {
  32093. data = new Uint8Array(computedLength);
  32094. data.set(imgArray);
  32095. for (i = actualLength; i < computedLength; i++) {
  32096. data[i] = 0xff;
  32097. }
  32098. }
  32099. // If necessary, invert the original mask data (but not any extra we might
  32100. // have added above). It's safe to modify the array -- whether it's the
  32101. // original or a copy, we're about to transfer it anyway, so nothing else
  32102. // in this thread can be relying on its contents.
  32103. if (inverseDecode) {
  32104. for (i = 0; i < actualLength; i++) {
  32105. data[i] = ~data[i];
  32106. }
  32107. }
  32108. return {data: data, width: width, height: height};
  32109. };
  32110. PDFImage.prototype = {
  32111. get drawWidth() {
  32112. return Math.max(this.width,
  32113. this.smask && this.smask.width || 0,
  32114. this.mask && this.mask.width || 0);
  32115. },
  32116. get drawHeight() {
  32117. return Math.max(this.height,
  32118. this.smask && this.smask.height || 0,
  32119. this.mask && this.mask.height || 0);
  32120. },
  32121. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  32122. var bpc = this.bpc;
  32123. var numComps = this.numComps;
  32124. var decodeAddends = this.decodeAddends;
  32125. var decodeCoefficients = this.decodeCoefficients;
  32126. var max = (1 << bpc) - 1;
  32127. var i, ii;
  32128. if (bpc === 1) {
  32129. // If the buffer needed decode that means it just needs to be inverted.
  32130. for (i = 0, ii = buffer.length; i < ii; i++) {
  32131. buffer[i] = +!(buffer[i]);
  32132. }
  32133. return;
  32134. }
  32135. var index = 0;
  32136. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  32137. for (var j = 0; j < numComps; j++) {
  32138. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  32139. decodeCoefficients[j], max);
  32140. index++;
  32141. }
  32142. }
  32143. },
  32144. getComponents: function PDFImage_getComponents(buffer) {
  32145. var bpc = this.bpc;
  32146. // This image doesn't require any extra work.
  32147. if (bpc === 8) {
  32148. return buffer;
  32149. }
  32150. var width = this.width;
  32151. var height = this.height;
  32152. var numComps = this.numComps;
  32153. var length = width * height * numComps;
  32154. var bufferPos = 0;
  32155. var output = (bpc <= 8 ? new Uint8Array(length) :
  32156. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  32157. var rowComps = width * numComps;
  32158. var max = (1 << bpc) - 1;
  32159. var i = 0, ii, buf;
  32160. if (bpc === 1) {
  32161. // Optimization for reading 1 bpc images.
  32162. var mask, loop1End, loop2End;
  32163. for (var j = 0; j < height; j++) {
  32164. loop1End = i + (rowComps & ~7);
  32165. loop2End = i + rowComps;
  32166. // unroll loop for all full bytes
  32167. while (i < loop1End) {
  32168. buf = buffer[bufferPos++];
  32169. output[i] = (buf >> 7) & 1;
  32170. output[i + 1] = (buf >> 6) & 1;
  32171. output[i + 2] = (buf >> 5) & 1;
  32172. output[i + 3] = (buf >> 4) & 1;
  32173. output[i + 4] = (buf >> 3) & 1;
  32174. output[i + 5] = (buf >> 2) & 1;
  32175. output[i + 6] = (buf >> 1) & 1;
  32176. output[i + 7] = buf & 1;
  32177. i += 8;
  32178. }
  32179. // handle remaing bits
  32180. if (i < loop2End) {
  32181. buf = buffer[bufferPos++];
  32182. mask = 128;
  32183. while (i < loop2End) {
  32184. output[i++] = +!!(buf & mask);
  32185. mask >>= 1;
  32186. }
  32187. }
  32188. }
  32189. } else {
  32190. // The general case that handles all other bpc values.
  32191. var bits = 0;
  32192. buf = 0;
  32193. for (i = 0, ii = length; i < ii; ++i) {
  32194. if (i % rowComps === 0) {
  32195. buf = 0;
  32196. bits = 0;
  32197. }
  32198. while (bits < bpc) {
  32199. buf = (buf << 8) | buffer[bufferPos++];
  32200. bits += 8;
  32201. }
  32202. var remainingBits = bits - bpc;
  32203. var value = buf >> remainingBits;
  32204. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  32205. buf = buf & ((1 << remainingBits) - 1);
  32206. bits = remainingBits;
  32207. }
  32208. }
  32209. return output;
  32210. },
  32211. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  32212. actualHeight, image) {
  32213. var smask = this.smask;
  32214. var mask = this.mask;
  32215. var alphaBuf, sw, sh, i, ii, j;
  32216. if (smask) {
  32217. sw = smask.width;
  32218. sh = smask.height;
  32219. alphaBuf = new Uint8Array(sw * sh);
  32220. smask.fillGrayBuffer(alphaBuf);
  32221. if (sw !== width || sh !== height) {
  32222. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  32223. height);
  32224. }
  32225. } else if (mask) {
  32226. if (mask instanceof PDFImage) {
  32227. sw = mask.width;
  32228. sh = mask.height;
  32229. alphaBuf = new Uint8Array(sw * sh);
  32230. mask.numComps = 1;
  32231. mask.fillGrayBuffer(alphaBuf);
  32232. // Need to invert values in rgbaBuf
  32233. for (i = 0, ii = sw * sh; i < ii; ++i) {
  32234. alphaBuf[i] = 255 - alphaBuf[i];
  32235. }
  32236. if (sw !== width || sh !== height) {
  32237. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  32238. height);
  32239. }
  32240. } else if (isArray(mask)) {
  32241. // Color key mask: if any of the compontents are outside the range
  32242. // then they should be painted.
  32243. alphaBuf = new Uint8Array(width * height);
  32244. var numComps = this.numComps;
  32245. for (i = 0, ii = width * height; i < ii; ++i) {
  32246. var opacity = 0;
  32247. var imageOffset = i * numComps;
  32248. for (j = 0; j < numComps; ++j) {
  32249. var color = image[imageOffset + j];
  32250. var maskOffset = j * 2;
  32251. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  32252. opacity = 255;
  32253. break;
  32254. }
  32255. }
  32256. alphaBuf[i] = opacity;
  32257. }
  32258. } else {
  32259. error('Unknown mask format.');
  32260. }
  32261. }
  32262. if (alphaBuf) {
  32263. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  32264. rgbaBuf[j] = alphaBuf[i];
  32265. }
  32266. } else {
  32267. // No mask.
  32268. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  32269. rgbaBuf[j] = 255;
  32270. }
  32271. }
  32272. },
  32273. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  32274. var matte = this.smask && this.smask.matte;
  32275. if (!matte) {
  32276. return;
  32277. }
  32278. var matteRgb = this.colorSpace.getRgb(matte, 0);
  32279. var matteR = matteRgb[0];
  32280. var matteG = matteRgb[1];
  32281. var matteB = matteRgb[2];
  32282. var length = width * height * 4;
  32283. var r, g, b;
  32284. for (var i = 0; i < length; i += 4) {
  32285. var alpha = buffer[i + 3];
  32286. if (alpha === 0) {
  32287. // according formula we have to get Infinity in all components
  32288. // making it white (typical paper color) should be okay
  32289. buffer[i] = 255;
  32290. buffer[i + 1] = 255;
  32291. buffer[i + 2] = 255;
  32292. continue;
  32293. }
  32294. var k = 255 / alpha;
  32295. r = (buffer[i] - matteR) * k + matteR;
  32296. g = (buffer[i + 1] - matteG) * k + matteG;
  32297. b = (buffer[i + 2] - matteB) * k + matteB;
  32298. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  32299. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  32300. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  32301. }
  32302. },
  32303. createImageData: function PDFImage_createImageData(forceRGBA) {
  32304. var drawWidth = this.drawWidth;
  32305. var drawHeight = this.drawHeight;
  32306. var imgData = { // other fields are filled in below
  32307. width: drawWidth,
  32308. height: drawHeight
  32309. };
  32310. var numComps = this.numComps;
  32311. var originalWidth = this.width;
  32312. var originalHeight = this.height;
  32313. var bpc = this.bpc;
  32314. // Rows start at byte boundary.
  32315. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  32316. var imgArray;
  32317. if (!forceRGBA) {
  32318. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  32319. // without any complications, we pass a same-sized copy to the main
  32320. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  32321. // of memory for many scanned documents. It's also much faster.
  32322. //
  32323. // Similarly, if it is a 24-bit-per pixel RGB image without any
  32324. // complications, we avoid expanding by 1.333x to RGBA form.
  32325. var kind;
  32326. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  32327. kind = ImageKind.GRAYSCALE_1BPP;
  32328. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  32329. !this.needsDecode) {
  32330. kind = ImageKind.RGB_24BPP;
  32331. }
  32332. if (kind && !this.smask && !this.mask &&
  32333. drawWidth === originalWidth && drawHeight === originalHeight) {
  32334. imgData.kind = kind;
  32335. imgArray = this.getImageBytes(originalHeight * rowBytes);
  32336. // If imgArray came from a DecodeStream, we're safe to transfer it
  32337. // (and thus detach its underlying buffer) because it will constitute
  32338. // the entire DecodeStream's data. But if it came from a Stream, we
  32339. // need to copy it because it'll only be a portion of the Stream's
  32340. // data, and the rest will be read later on.
  32341. if (this.image instanceof DecodeStream) {
  32342. imgData.data = imgArray;
  32343. } else {
  32344. var newArray = new Uint8Array(imgArray.length);
  32345. newArray.set(imgArray);
  32346. imgData.data = newArray;
  32347. }
  32348. if (this.needsDecode) {
  32349. // Invert the buffer (which must be grayscale if we reached here).
  32350. assert(kind === ImageKind.GRAYSCALE_1BPP);
  32351. var buffer = imgData.data;
  32352. for (var i = 0, ii = buffer.length; i < ii; i++) {
  32353. buffer[i] ^= 0xff;
  32354. }
  32355. }
  32356. return imgData;
  32357. }
  32358. if (this.image instanceof JpegStream && !this.smask && !this.mask &&
  32359. (this.colorSpace.name === 'DeviceGray' ||
  32360. this.colorSpace.name === 'DeviceRGB' ||
  32361. this.colorSpace.name === 'DeviceCMYK')) {
  32362. imgData.kind = ImageKind.RGB_24BPP;
  32363. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  32364. drawWidth, drawHeight, true);
  32365. return imgData;
  32366. }
  32367. }
  32368. imgArray = this.getImageBytes(originalHeight * rowBytes);
  32369. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  32370. var actualHeight = 0 | (imgArray.length / rowBytes *
  32371. drawHeight / originalHeight);
  32372. var comps = this.getComponents(imgArray);
  32373. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  32374. // more compact RGB_24BPP form if allowable.
  32375. var alpha01, maybeUndoPreblend;
  32376. if (!forceRGBA && !this.smask && !this.mask) {
  32377. imgData.kind = ImageKind.RGB_24BPP;
  32378. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  32379. alpha01 = 0;
  32380. maybeUndoPreblend = false;
  32381. } else {
  32382. imgData.kind = ImageKind.RGBA_32BPP;
  32383. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  32384. alpha01 = 1;
  32385. maybeUndoPreblend = true;
  32386. // Color key masking (opacity) must be performed before decoding.
  32387. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  32388. comps);
  32389. }
  32390. if (this.needsDecode) {
  32391. this.decodeBuffer(comps);
  32392. }
  32393. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  32394. drawWidth, drawHeight, actualHeight, bpc, comps,
  32395. alpha01);
  32396. if (maybeUndoPreblend) {
  32397. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  32398. }
  32399. return imgData;
  32400. },
  32401. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  32402. var numComps = this.numComps;
  32403. if (numComps !== 1) {
  32404. error('Reading gray scale from a color image: ' + numComps);
  32405. }
  32406. var width = this.width;
  32407. var height = this.height;
  32408. var bpc = this.bpc;
  32409. // rows start at byte boundary
  32410. var rowBytes = (width * numComps * bpc + 7) >> 3;
  32411. var imgArray = this.getImageBytes(height * rowBytes);
  32412. var comps = this.getComponents(imgArray);
  32413. var i, length;
  32414. if (bpc === 1) {
  32415. // inline decoding (= inversion) for 1 bpc images
  32416. length = width * height;
  32417. if (this.needsDecode) {
  32418. // invert and scale to {0, 255}
  32419. for (i = 0; i < length; ++i) {
  32420. buffer[i] = (comps[i] - 1) & 255;
  32421. }
  32422. } else {
  32423. // scale to {0, 255}
  32424. for (i = 0; i < length; ++i) {
  32425. buffer[i] = (-comps[i]) & 255;
  32426. }
  32427. }
  32428. return;
  32429. }
  32430. if (this.needsDecode) {
  32431. this.decodeBuffer(comps);
  32432. }
  32433. length = width * height;
  32434. // we aren't using a colorspace so we need to scale the value
  32435. var scale = 255 / ((1 << bpc) - 1);
  32436. for (i = 0; i < length; ++i) {
  32437. buffer[i] = (scale * comps[i]) | 0;
  32438. }
  32439. },
  32440. getImageBytes: function PDFImage_getImageBytes(length,
  32441. drawWidth, drawHeight,
  32442. forceRGB) {
  32443. this.image.reset();
  32444. this.image.drawWidth = drawWidth || this.width;
  32445. this.image.drawHeight = drawHeight || this.height;
  32446. this.image.forceRGB = !!forceRGB;
  32447. return this.image.getBytes(length);
  32448. }
  32449. };
  32450. return PDFImage;
  32451. })();
  32452. exports.PDFImage = PDFImage;
  32453. // TODO refactor to remove dependency on colorspace.js
  32454. coreColorSpace._setCoreImage(exports);
  32455. }));
  32456. (function (root, factory) {
  32457. {
  32458. factory((root.pdfjsCoreObj = {}), root.pdfjsSharedUtil,
  32459. root.pdfjsCorePrimitives, root.pdfjsCoreCrypto, root.pdfjsCoreParser,
  32460. root.pdfjsCoreChunkedStream, root.pdfjsCoreColorSpace);
  32461. }
  32462. }(this, function (exports, sharedUtil, corePrimitives, coreCrypto, coreParser,
  32463. coreChunkedStream, coreColorSpace) {
  32464. var InvalidPDFException = sharedUtil.InvalidPDFException;
  32465. var MissingDataException = sharedUtil.MissingDataException;
  32466. var XRefParseException = sharedUtil.XRefParseException;
  32467. var assert = sharedUtil.assert;
  32468. var bytesToString = sharedUtil.bytesToString;
  32469. var createPromiseCapability = sharedUtil.createPromiseCapability;
  32470. var error = sharedUtil.error;
  32471. var info = sharedUtil.info;
  32472. var isArray = sharedUtil.isArray;
  32473. var isInt = sharedUtil.isInt;
  32474. var isString = sharedUtil.isString;
  32475. var shadow = sharedUtil.shadow;
  32476. var stringToPDFString = sharedUtil.stringToPDFString;
  32477. var stringToUTF8String = sharedUtil.stringToUTF8String;
  32478. var warn = sharedUtil.warn;
  32479. var isValidUrl = sharedUtil.isValidUrl;
  32480. var Util = sharedUtil.Util;
  32481. var Ref = corePrimitives.Ref;
  32482. var RefSet = corePrimitives.RefSet;
  32483. var RefSetCache = corePrimitives.RefSetCache;
  32484. var isName = corePrimitives.isName;
  32485. var isCmd = corePrimitives.isCmd;
  32486. var isDict = corePrimitives.isDict;
  32487. var isRef = corePrimitives.isRef;
  32488. var isStream = corePrimitives.isStream;
  32489. var CipherTransformFactory = coreCrypto.CipherTransformFactory;
  32490. var Lexer = coreParser.Lexer;
  32491. var Parser = coreParser.Parser;
  32492. var ChunkedStream = coreChunkedStream.ChunkedStream;
  32493. var ColorSpace = coreColorSpace.ColorSpace;
  32494. var Catalog = (function CatalogClosure() {
  32495. function Catalog(pdfManager, xref, pageFactory) {
  32496. this.pdfManager = pdfManager;
  32497. this.xref = xref;
  32498. this.catDict = xref.getCatalogObj();
  32499. this.fontCache = new RefSetCache();
  32500. assert(isDict(this.catDict),
  32501. 'catalog object is not a dictionary');
  32502. // TODO refactor to move getPage() to the PDFDocument.
  32503. this.pageFactory = pageFactory;
  32504. this.pagePromises = [];
  32505. }
  32506. Catalog.prototype = {
  32507. get metadata() {
  32508. var streamRef = this.catDict.getRaw('Metadata');
  32509. if (!isRef(streamRef)) {
  32510. return shadow(this, 'metadata', null);
  32511. }
  32512. var encryptMetadata = (!this.xref.encrypt ? false :
  32513. this.xref.encrypt.encryptMetadata);
  32514. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  32515. var metadata;
  32516. if (stream && isDict(stream.dict)) {
  32517. var type = stream.dict.get('Type');
  32518. var subtype = stream.dict.get('Subtype');
  32519. if (isName(type) && isName(subtype) &&
  32520. type.name === 'Metadata' && subtype.name === 'XML') {
  32521. // XXX: This should examine the charset the XML document defines,
  32522. // however since there are currently no real means to decode
  32523. // arbitrary charsets, let's just hope that the author of the PDF
  32524. // was reasonable enough to stick with the XML default charset,
  32525. // which is UTF-8.
  32526. try {
  32527. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  32528. } catch (e) {
  32529. info('Skipping invalid metadata.');
  32530. }
  32531. }
  32532. }
  32533. return shadow(this, 'metadata', metadata);
  32534. },
  32535. get toplevelPagesDict() {
  32536. var pagesObj = this.catDict.get('Pages');
  32537. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  32538. // shadow the prototype getter
  32539. return shadow(this, 'toplevelPagesDict', pagesObj);
  32540. },
  32541. get documentOutline() {
  32542. var obj = null;
  32543. try {
  32544. obj = this.readDocumentOutline();
  32545. } catch (ex) {
  32546. if (ex instanceof MissingDataException) {
  32547. throw ex;
  32548. }
  32549. warn('Unable to read document outline');
  32550. }
  32551. return shadow(this, 'documentOutline', obj);
  32552. },
  32553. readDocumentOutline: function Catalog_readDocumentOutline() {
  32554. var obj = this.catDict.get('Outlines');
  32555. if (!isDict(obj)) {
  32556. return null;
  32557. }
  32558. obj = obj.getRaw('First');
  32559. if (!isRef(obj)) {
  32560. return null;
  32561. }
  32562. var root = { items: [] };
  32563. var queue = [{obj: obj, parent: root}];
  32564. // To avoid recursion, keep track of the already processed items.
  32565. var processed = new RefSet();
  32566. processed.put(obj);
  32567. var xref = this.xref, blackColor = new Uint8Array(3);
  32568. while (queue.length > 0) {
  32569. var i = queue.shift();
  32570. var outlineDict = xref.fetchIfRef(i.obj);
  32571. if (outlineDict === null) {
  32572. continue;
  32573. }
  32574. assert(outlineDict.has('Title'), 'Invalid outline item');
  32575. var actionDict = outlineDict.get('A'), dest = null, url = null;
  32576. if (actionDict) {
  32577. var destEntry = actionDict.get('D');
  32578. if (destEntry) {
  32579. dest = destEntry;
  32580. } else {
  32581. var uriEntry = actionDict.get('URI');
  32582. if (isString(uriEntry) && isValidUrl(uriEntry, false)) {
  32583. url = uriEntry;
  32584. }
  32585. }
  32586. } else if (outlineDict.has('Dest')) {
  32587. dest = outlineDict.getRaw('Dest');
  32588. if (isName(dest)) {
  32589. dest = dest.name;
  32590. }
  32591. }
  32592. var title = outlineDict.get('Title');
  32593. var flags = outlineDict.get('F') || 0;
  32594. var color = outlineDict.get('C'), rgbColor = blackColor;
  32595. // We only need to parse the color when it's valid, and non-default.
  32596. if (isArray(color) && color.length === 3 &&
  32597. (color[0] !== 0 || color[1] !== 0 || color[2] !== 0)) {
  32598. rgbColor = ColorSpace.singletons.rgb.getRgb(color, 0);
  32599. }
  32600. var outlineItem = {
  32601. dest: dest,
  32602. url: url,
  32603. title: stringToPDFString(title),
  32604. color: rgbColor,
  32605. count: outlineDict.get('Count'),
  32606. bold: !!(flags & 2),
  32607. italic: !!(flags & 1),
  32608. items: []
  32609. };
  32610. i.parent.items.push(outlineItem);
  32611. obj = outlineDict.getRaw('First');
  32612. if (isRef(obj) && !processed.has(obj)) {
  32613. queue.push({obj: obj, parent: outlineItem});
  32614. processed.put(obj);
  32615. }
  32616. obj = outlineDict.getRaw('Next');
  32617. if (isRef(obj) && !processed.has(obj)) {
  32618. queue.push({obj: obj, parent: i.parent});
  32619. processed.put(obj);
  32620. }
  32621. }
  32622. return (root.items.length > 0 ? root.items : null);
  32623. },
  32624. get numPages() {
  32625. var obj = this.toplevelPagesDict.get('Count');
  32626. assert(
  32627. isInt(obj),
  32628. 'page count in top level pages object is not an integer'
  32629. );
  32630. // shadow the prototype getter
  32631. return shadow(this, 'num', obj);
  32632. },
  32633. get destinations() {
  32634. function fetchDestination(dest) {
  32635. return isDict(dest) ? dest.get('D') : dest;
  32636. }
  32637. var xref = this.xref;
  32638. var dests = {}, nameTreeRef, nameDictionaryRef;
  32639. var obj = this.catDict.get('Names');
  32640. if (obj && obj.has('Dests')) {
  32641. nameTreeRef = obj.getRaw('Dests');
  32642. } else if (this.catDict.has('Dests')) {
  32643. nameDictionaryRef = this.catDict.get('Dests');
  32644. }
  32645. if (nameDictionaryRef) {
  32646. // reading simple destination dictionary
  32647. obj = nameDictionaryRef;
  32648. obj.forEach(function catalogForEach(key, value) {
  32649. if (!value) {
  32650. return;
  32651. }
  32652. dests[key] = fetchDestination(value);
  32653. });
  32654. }
  32655. if (nameTreeRef) {
  32656. var nameTree = new NameTree(nameTreeRef, xref);
  32657. var names = nameTree.getAll();
  32658. for (var name in names) {
  32659. dests[name] = fetchDestination(names[name]);
  32660. }
  32661. }
  32662. return shadow(this, 'destinations', dests);
  32663. },
  32664. getDestination: function Catalog_getDestination(destinationId) {
  32665. function fetchDestination(dest) {
  32666. return isDict(dest) ? dest.get('D') : dest;
  32667. }
  32668. var xref = this.xref;
  32669. var dest = null, nameTreeRef, nameDictionaryRef;
  32670. var obj = this.catDict.get('Names');
  32671. if (obj && obj.has('Dests')) {
  32672. nameTreeRef = obj.getRaw('Dests');
  32673. } else if (this.catDict.has('Dests')) {
  32674. nameDictionaryRef = this.catDict.get('Dests');
  32675. }
  32676. if (nameDictionaryRef) { // Simple destination dictionary.
  32677. var value = nameDictionaryRef.get(destinationId);
  32678. if (value) {
  32679. dest = fetchDestination(value);
  32680. }
  32681. }
  32682. if (nameTreeRef) {
  32683. var nameTree = new NameTree(nameTreeRef, xref);
  32684. dest = fetchDestination(nameTree.get(destinationId));
  32685. }
  32686. return dest;
  32687. },
  32688. get pageLabels() {
  32689. var obj = null;
  32690. try {
  32691. obj = this.readPageLabels();
  32692. } catch (ex) {
  32693. if (ex instanceof MissingDataException) {
  32694. throw ex;
  32695. }
  32696. warn('Unable to read page labels.');
  32697. }
  32698. return shadow(this, 'pageLabels', obj);
  32699. },
  32700. readPageLabels: function Catalog_readPageLabels() {
  32701. var obj = this.catDict.getRaw('PageLabels');
  32702. if (!obj) {
  32703. return null;
  32704. }
  32705. var pageLabels = new Array(this.numPages);
  32706. var style = null;
  32707. var prefix = '';
  32708. var start = 1;
  32709. var numberTree = new NumberTree(obj, this.xref);
  32710. var nums = numberTree.getAll();
  32711. var currentLabel = '', currentIndex = 1;
  32712. for (var i = 0, ii = this.numPages; i < ii; i++) {
  32713. if (i in nums) {
  32714. var labelDict = nums[i];
  32715. assert(isDict(labelDict), 'The PageLabel is not a dictionary.');
  32716. var type = labelDict.get('Type');
  32717. assert(!type || (isName(type) && type.name === 'PageLabel'),
  32718. 'Invalid type in PageLabel dictionary.');
  32719. var s = labelDict.get('S');
  32720. assert(!s || isName(s), 'Invalid style in PageLabel dictionary.');
  32721. style = (s ? s.name : null);
  32722. prefix = labelDict.get('P') || '';
  32723. assert(isString(prefix), 'Invalid prefix in PageLabel dictionary.');
  32724. start = labelDict.get('St') || 1;
  32725. assert(isInt(start), 'Invalid start in PageLabel dictionary.');
  32726. currentIndex = start;
  32727. }
  32728. switch (style) {
  32729. case 'D':
  32730. currentLabel = currentIndex;
  32731. break;
  32732. case 'R':
  32733. case 'r':
  32734. currentLabel = Util.toRoman(currentIndex, style === 'r');
  32735. break;
  32736. case 'A':
  32737. case 'a':
  32738. var LIMIT = 26; // Use only the characters A--Z, or a--z.
  32739. var A_UPPER_CASE = 0x41, A_LOWER_CASE = 0x61;
  32740. var baseCharCode = (style === 'a' ? A_LOWER_CASE : A_UPPER_CASE);
  32741. var letterIndex = currentIndex - 1;
  32742. var character = String.fromCharCode(baseCharCode +
  32743. (letterIndex % LIMIT));
  32744. var charBuf = [];
  32745. for (var j = 0, jj = (letterIndex / LIMIT) | 0; j <= jj; j++) {
  32746. charBuf.push(character);
  32747. }
  32748. currentLabel = charBuf.join('');
  32749. break;
  32750. default:
  32751. assert(!style,
  32752. 'Invalid style "' + style + '" in PageLabel dictionary.');
  32753. }
  32754. pageLabels[i] = prefix + currentLabel;
  32755. currentLabel = '';
  32756. currentIndex++;
  32757. }
  32758. return pageLabels;
  32759. },
  32760. get attachments() {
  32761. var xref = this.xref;
  32762. var attachments = null, nameTreeRef;
  32763. var obj = this.catDict.get('Names');
  32764. if (obj) {
  32765. nameTreeRef = obj.getRaw('EmbeddedFiles');
  32766. }
  32767. if (nameTreeRef) {
  32768. var nameTree = new NameTree(nameTreeRef, xref);
  32769. var names = nameTree.getAll();
  32770. for (var name in names) {
  32771. var fs = new FileSpec(names[name], xref);
  32772. if (!attachments) {
  32773. attachments = Object.create(null);
  32774. }
  32775. attachments[stringToPDFString(name)] = fs.serializable;
  32776. }
  32777. }
  32778. return shadow(this, 'attachments', attachments);
  32779. },
  32780. get javaScript() {
  32781. var xref = this.xref;
  32782. var obj = this.catDict.get('Names');
  32783. var javaScript = [];
  32784. function appendIfJavaScriptDict(jsDict) {
  32785. var type = jsDict.get('S');
  32786. if (!isName(type) || type.name !== 'JavaScript') {
  32787. return;
  32788. }
  32789. var js = jsDict.get('JS');
  32790. if (isStream(js)) {
  32791. js = bytesToString(js.getBytes());
  32792. } else if (!isString(js)) {
  32793. return;
  32794. }
  32795. javaScript.push(stringToPDFString(js));
  32796. }
  32797. if (obj && obj.has('JavaScript')) {
  32798. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  32799. var names = nameTree.getAll();
  32800. for (var name in names) {
  32801. // We don't really use the JavaScript right now. This code is
  32802. // defensive so we don't cause errors on document load.
  32803. var jsDict = names[name];
  32804. if (isDict(jsDict)) {
  32805. appendIfJavaScriptDict(jsDict);
  32806. }
  32807. }
  32808. }
  32809. // Append OpenAction actions to javaScript array
  32810. var openactionDict = this.catDict.get('OpenAction');
  32811. if (isDict(openactionDict, 'Action')) {
  32812. var actionType = openactionDict.get('S');
  32813. if (isName(actionType) && actionType.name === 'Named') {
  32814. // The named Print action is not a part of the PDF 1.7 specification,
  32815. // but is supported by many PDF readers/writers (including Adobe's).
  32816. var action = openactionDict.get('N');
  32817. if (isName(action) && action.name === 'Print') {
  32818. javaScript.push('print({});');
  32819. }
  32820. } else {
  32821. appendIfJavaScriptDict(openactionDict);
  32822. }
  32823. }
  32824. return shadow(this, 'javaScript', javaScript);
  32825. },
  32826. cleanup: function Catalog_cleanup() {
  32827. var promises = [];
  32828. this.fontCache.forEach(function (promise) {
  32829. promises.push(promise);
  32830. });
  32831. return Promise.all(promises).then(function (translatedFonts) {
  32832. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  32833. var font = translatedFonts[i].dict;
  32834. delete font.translated;
  32835. }
  32836. this.fontCache.clear();
  32837. }.bind(this));
  32838. },
  32839. getPage: function Catalog_getPage(pageIndex) {
  32840. if (!(pageIndex in this.pagePromises)) {
  32841. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  32842. function (a) {
  32843. var dict = a[0];
  32844. var ref = a[1];
  32845. return this.pageFactory.createPage(pageIndex, dict, ref,
  32846. this.fontCache);
  32847. }.bind(this)
  32848. );
  32849. }
  32850. return this.pagePromises[pageIndex];
  32851. },
  32852. getPageDict: function Catalog_getPageDict(pageIndex) {
  32853. var capability = createPromiseCapability();
  32854. var nodesToVisit = [this.catDict.getRaw('Pages')];
  32855. var currentPageIndex = 0;
  32856. var xref = this.xref;
  32857. var checkAllKids = false;
  32858. function next() {
  32859. while (nodesToVisit.length) {
  32860. var currentNode = nodesToVisit.pop();
  32861. if (isRef(currentNode)) {
  32862. xref.fetchAsync(currentNode).then(function (obj) {
  32863. if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
  32864. if (pageIndex === currentPageIndex) {
  32865. capability.resolve([obj, currentNode]);
  32866. } else {
  32867. currentPageIndex++;
  32868. next();
  32869. }
  32870. return;
  32871. }
  32872. nodesToVisit.push(obj);
  32873. next();
  32874. }, capability.reject);
  32875. return;
  32876. }
  32877. // Must be a child page dictionary.
  32878. assert(
  32879. isDict(currentNode),
  32880. 'page dictionary kid reference points to wrong type of object'
  32881. );
  32882. var count = currentNode.get('Count');
  32883. // If the current node doesn't have any children, avoid getting stuck
  32884. // in an empty node further down in the tree (see issue5644.pdf).
  32885. if (count === 0) {
  32886. checkAllKids = true;
  32887. }
  32888. // Skip nodes where the page can't be.
  32889. if (currentPageIndex + count <= pageIndex) {
  32890. currentPageIndex += count;
  32891. continue;
  32892. }
  32893. var kids = currentNode.get('Kids');
  32894. assert(isArray(kids), 'page dictionary kids object is not an array');
  32895. if (!checkAllKids && count === kids.length) {
  32896. // Nodes that don't have the page have been skipped and this is the
  32897. // bottom of the tree which means the page requested must be a
  32898. // descendant of this pages node. Ideally we would just resolve the
  32899. // promise with the page ref here, but there is the case where more
  32900. // pages nodes could link to single a page (see issue 3666 pdf). To
  32901. // handle this push it back on the queue so if it is a pages node it
  32902. // will be descended into.
  32903. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  32904. currentPageIndex = pageIndex;
  32905. continue;
  32906. } else {
  32907. for (var last = kids.length - 1; last >= 0; last--) {
  32908. nodesToVisit.push(kids[last]);
  32909. }
  32910. }
  32911. }
  32912. capability.reject('Page index ' + pageIndex + ' not found.');
  32913. }
  32914. next();
  32915. return capability.promise;
  32916. },
  32917. getPageIndex: function Catalog_getPageIndex(ref) {
  32918. // The page tree nodes have the count of all the leaves below them. To get
  32919. // how many pages are before we just have to walk up the tree and keep
  32920. // adding the count of siblings to the left of the node.
  32921. var xref = this.xref;
  32922. function pagesBeforeRef(kidRef) {
  32923. var total = 0;
  32924. var parentRef;
  32925. return xref.fetchAsync(kidRef).then(function (node) {
  32926. if (!node) {
  32927. return null;
  32928. }
  32929. parentRef = node.getRaw('Parent');
  32930. return node.getAsync('Parent');
  32931. }).then(function (parent) {
  32932. if (!parent) {
  32933. return null;
  32934. }
  32935. return parent.getAsync('Kids');
  32936. }).then(function (kids) {
  32937. if (!kids) {
  32938. return null;
  32939. }
  32940. var kidPromises = [];
  32941. var found = false;
  32942. for (var i = 0; i < kids.length; i++) {
  32943. var kid = kids[i];
  32944. assert(isRef(kid), 'kids must be a ref');
  32945. if (kid.num === kidRef.num) {
  32946. found = true;
  32947. break;
  32948. }
  32949. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  32950. if (kid.has('Count')) {
  32951. var count = kid.get('Count');
  32952. total += count;
  32953. } else { // page leaf node
  32954. total++;
  32955. }
  32956. }));
  32957. }
  32958. if (!found) {
  32959. error('kid ref not found in parents kids');
  32960. }
  32961. return Promise.all(kidPromises).then(function () {
  32962. return [total, parentRef];
  32963. });
  32964. });
  32965. }
  32966. var total = 0;
  32967. function next(ref) {
  32968. return pagesBeforeRef(ref).then(function (args) {
  32969. if (!args) {
  32970. return total;
  32971. }
  32972. var count = args[0];
  32973. var parentRef = args[1];
  32974. total += count;
  32975. return next(parentRef);
  32976. });
  32977. }
  32978. return next(ref);
  32979. }
  32980. };
  32981. return Catalog;
  32982. })();
  32983. var XRef = (function XRefClosure() {
  32984. function XRef(stream, password) {
  32985. this.stream = stream;
  32986. this.entries = [];
  32987. this.xrefstms = Object.create(null);
  32988. // prepare the XRef cache
  32989. this.cache = [];
  32990. this.password = password;
  32991. this.stats = {
  32992. streamTypes: [],
  32993. fontTypes: []
  32994. };
  32995. }
  32996. XRef.prototype = {
  32997. setStartXRef: function XRef_setStartXRef(startXRef) {
  32998. // Store the starting positions of xref tables as we process them
  32999. // so we can recover from missing data errors
  33000. this.startXRefQueue = [startXRef];
  33001. },
  33002. parse: function XRef_parse(recoveryMode) {
  33003. var trailerDict;
  33004. if (!recoveryMode) {
  33005. trailerDict = this.readXRef();
  33006. } else {
  33007. warn('Indexing all PDF objects');
  33008. trailerDict = this.indexObjects();
  33009. }
  33010. trailerDict.assignXref(this);
  33011. this.trailer = trailerDict;
  33012. var encrypt = trailerDict.get('Encrypt');
  33013. if (encrypt) {
  33014. var ids = trailerDict.get('ID');
  33015. var fileId = (ids && ids.length) ? ids[0] : '';
  33016. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  33017. this.password);
  33018. }
  33019. // get the root dictionary (catalog) object
  33020. if (!(this.root = trailerDict.get('Root'))) {
  33021. error('Invalid root reference');
  33022. }
  33023. },
  33024. processXRefTable: function XRef_processXRefTable(parser) {
  33025. if (!('tableState' in this)) {
  33026. // Stores state of the table as we process it so we can resume
  33027. // from middle of table in case of missing data error
  33028. this.tableState = {
  33029. entryNum: 0,
  33030. streamPos: parser.lexer.stream.pos,
  33031. parserBuf1: parser.buf1,
  33032. parserBuf2: parser.buf2
  33033. };
  33034. }
  33035. var obj = this.readXRefTable(parser);
  33036. // Sanity check
  33037. if (!isCmd(obj, 'trailer')) {
  33038. error('Invalid XRef table: could not find trailer dictionary');
  33039. }
  33040. // Read trailer dictionary, e.g.
  33041. // trailer
  33042. // << /Size 22
  33043. // /Root 20R
  33044. // /Info 10R
  33045. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  33046. // >>
  33047. // The parser goes through the entire stream << ... >> and provides
  33048. // a getter interface for the key-value table
  33049. var dict = parser.getObj();
  33050. // The pdflib PDF generator can generate a nested trailer dictionary
  33051. if (!isDict(dict) && dict.dict) {
  33052. dict = dict.dict;
  33053. }
  33054. if (!isDict(dict)) {
  33055. error('Invalid XRef table: could not parse trailer dictionary');
  33056. }
  33057. delete this.tableState;
  33058. return dict;
  33059. },
  33060. readXRefTable: function XRef_readXRefTable(parser) {
  33061. // Example of cross-reference table:
  33062. // xref
  33063. // 0 1 <-- subsection header (first obj #, obj count)
  33064. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  33065. // 23 2 <-- subsection header ... and so on ...
  33066. // 0000025518 00002 n
  33067. // 0000025635 00000 n
  33068. // trailer
  33069. // ...
  33070. var stream = parser.lexer.stream;
  33071. var tableState = this.tableState;
  33072. stream.pos = tableState.streamPos;
  33073. parser.buf1 = tableState.parserBuf1;
  33074. parser.buf2 = tableState.parserBuf2;
  33075. // Outer loop is over subsection headers
  33076. var obj;
  33077. while (true) {
  33078. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  33079. if (isCmd(obj = parser.getObj(), 'trailer')) {
  33080. break;
  33081. }
  33082. tableState.firstEntryNum = obj;
  33083. tableState.entryCount = parser.getObj();
  33084. }
  33085. var first = tableState.firstEntryNum;
  33086. var count = tableState.entryCount;
  33087. if (!isInt(first) || !isInt(count)) {
  33088. error('Invalid XRef table: wrong types in subsection header');
  33089. }
  33090. // Inner loop is over objects themselves
  33091. for (var i = tableState.entryNum; i < count; i++) {
  33092. tableState.streamPos = stream.pos;
  33093. tableState.entryNum = i;
  33094. tableState.parserBuf1 = parser.buf1;
  33095. tableState.parserBuf2 = parser.buf2;
  33096. var entry = {};
  33097. entry.offset = parser.getObj();
  33098. entry.gen = parser.getObj();
  33099. var type = parser.getObj();
  33100. if (isCmd(type, 'f')) {
  33101. entry.free = true;
  33102. } else if (isCmd(type, 'n')) {
  33103. entry.uncompressed = true;
  33104. }
  33105. // Validate entry obj
  33106. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  33107. !(entry.free || entry.uncompressed)) {
  33108. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  33109. }
  33110. if (!this.entries[i + first]) {
  33111. this.entries[i + first] = entry;
  33112. }
  33113. }
  33114. tableState.entryNum = 0;
  33115. tableState.streamPos = stream.pos;
  33116. tableState.parserBuf1 = parser.buf1;
  33117. tableState.parserBuf2 = parser.buf2;
  33118. delete tableState.firstEntryNum;
  33119. delete tableState.entryCount;
  33120. }
  33121. // Per issue 3248: hp scanners generate bad XRef
  33122. if (first === 1 && this.entries[1] && this.entries[1].free) {
  33123. // shifting the entries
  33124. this.entries.shift();
  33125. }
  33126. // Sanity check: as per spec, first object must be free
  33127. if (this.entries[0] && !this.entries[0].free) {
  33128. error('Invalid XRef table: unexpected first object');
  33129. }
  33130. return obj;
  33131. },
  33132. processXRefStream: function XRef_processXRefStream(stream) {
  33133. if (!('streamState' in this)) {
  33134. // Stores state of the stream as we process it so we can resume
  33135. // from middle of stream in case of missing data error
  33136. var streamParameters = stream.dict;
  33137. var byteWidths = streamParameters.get('W');
  33138. var range = streamParameters.get('Index');
  33139. if (!range) {
  33140. range = [0, streamParameters.get('Size')];
  33141. }
  33142. this.streamState = {
  33143. entryRanges: range,
  33144. byteWidths: byteWidths,
  33145. entryNum: 0,
  33146. streamPos: stream.pos
  33147. };
  33148. }
  33149. this.readXRefStream(stream);
  33150. delete this.streamState;
  33151. return stream.dict;
  33152. },
  33153. readXRefStream: function XRef_readXRefStream(stream) {
  33154. var i, j;
  33155. var streamState = this.streamState;
  33156. stream.pos = streamState.streamPos;
  33157. var byteWidths = streamState.byteWidths;
  33158. var typeFieldWidth = byteWidths[0];
  33159. var offsetFieldWidth = byteWidths[1];
  33160. var generationFieldWidth = byteWidths[2];
  33161. var entryRanges = streamState.entryRanges;
  33162. while (entryRanges.length > 0) {
  33163. var first = entryRanges[0];
  33164. var n = entryRanges[1];
  33165. if (!isInt(first) || !isInt(n)) {
  33166. error('Invalid XRef range fields: ' + first + ', ' + n);
  33167. }
  33168. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  33169. !isInt(generationFieldWidth)) {
  33170. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  33171. }
  33172. for (i = streamState.entryNum; i < n; ++i) {
  33173. streamState.entryNum = i;
  33174. streamState.streamPos = stream.pos;
  33175. var type = 0, offset = 0, generation = 0;
  33176. for (j = 0; j < typeFieldWidth; ++j) {
  33177. type = (type << 8) | stream.getByte();
  33178. }
  33179. // if type field is absent, its default value is 1
  33180. if (typeFieldWidth === 0) {
  33181. type = 1;
  33182. }
  33183. for (j = 0; j < offsetFieldWidth; ++j) {
  33184. offset = (offset << 8) | stream.getByte();
  33185. }
  33186. for (j = 0; j < generationFieldWidth; ++j) {
  33187. generation = (generation << 8) | stream.getByte();
  33188. }
  33189. var entry = {};
  33190. entry.offset = offset;
  33191. entry.gen = generation;
  33192. switch (type) {
  33193. case 0:
  33194. entry.free = true;
  33195. break;
  33196. case 1:
  33197. entry.uncompressed = true;
  33198. break;
  33199. case 2:
  33200. break;
  33201. default:
  33202. error('Invalid XRef entry type: ' + type);
  33203. }
  33204. if (!this.entries[first + i]) {
  33205. this.entries[first + i] = entry;
  33206. }
  33207. }
  33208. streamState.entryNum = 0;
  33209. streamState.streamPos = stream.pos;
  33210. entryRanges.splice(0, 2);
  33211. }
  33212. },
  33213. indexObjects: function XRef_indexObjects() {
  33214. // Simple scan through the PDF content to find objects,
  33215. // trailers and XRef streams.
  33216. var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
  33217. var PERCENT = 0x25, LT = 0x3C;
  33218. function readToken(data, offset) {
  33219. var token = '', ch = data[offset];
  33220. while (ch !== LF && ch !== CR && ch !== LT) {
  33221. if (++offset >= data.length) {
  33222. break;
  33223. }
  33224. token += String.fromCharCode(ch);
  33225. ch = data[offset];
  33226. }
  33227. return token;
  33228. }
  33229. function skipUntil(data, offset, what) {
  33230. var length = what.length, dataLength = data.length;
  33231. var skipped = 0;
  33232. // finding byte sequence
  33233. while (offset < dataLength) {
  33234. var i = 0;
  33235. while (i < length && data[offset + i] === what[i]) {
  33236. ++i;
  33237. }
  33238. if (i >= length) {
  33239. break; // sequence found
  33240. }
  33241. offset++;
  33242. skipped++;
  33243. }
  33244. return skipped;
  33245. }
  33246. var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  33247. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  33248. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  33249. 101, 102]);
  33250. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  33251. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  33252. // Clear out any existing entries, since they may be bogus.
  33253. this.entries.length = 0;
  33254. var stream = this.stream;
  33255. stream.pos = 0;
  33256. var buffer = stream.getBytes();
  33257. var position = stream.start, length = buffer.length;
  33258. var trailers = [], xrefStms = [];
  33259. while (position < length) {
  33260. var ch = buffer[position];
  33261. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  33262. ++position;
  33263. continue;
  33264. }
  33265. if (ch === PERCENT) { // %-comment
  33266. do {
  33267. ++position;
  33268. if (position >= length) {
  33269. break;
  33270. }
  33271. ch = buffer[position];
  33272. } while (ch !== LF && ch !== CR);
  33273. continue;
  33274. }
  33275. var token = readToken(buffer, position);
  33276. var m;
  33277. if (token.indexOf('xref') === 0 &&
  33278. (token.length === 4 || /\s/.test(token[4]))) {
  33279. position += skipUntil(buffer, position, trailerBytes);
  33280. trailers.push(position);
  33281. position += skipUntil(buffer, position, startxrefBytes);
  33282. } else if ((m = objRegExp.exec(token))) {
  33283. if (typeof this.entries[m[1]] === 'undefined') {
  33284. this.entries[m[1]] = {
  33285. offset: position - stream.start,
  33286. gen: m[2] | 0,
  33287. uncompressed: true
  33288. };
  33289. }
  33290. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  33291. var content = buffer.subarray(position, position + contentLength);
  33292. // checking XRef stream suspect
  33293. // (it shall have '/XRef' and next char is not a letter)
  33294. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  33295. if (xrefTagOffset < contentLength &&
  33296. content[xrefTagOffset + 5] < 64) {
  33297. xrefStms.push(position - stream.start);
  33298. this.xrefstms[position - stream.start] = 1; // Avoid recursion
  33299. }
  33300. position += contentLength;
  33301. } else if (token.indexOf('trailer') === 0 &&
  33302. (token.length === 7 || /\s/.test(token[7]))) {
  33303. trailers.push(position);
  33304. position += skipUntil(buffer, position, startxrefBytes);
  33305. } else {
  33306. position += token.length + 1;
  33307. }
  33308. }
  33309. // reading XRef streams
  33310. var i, ii;
  33311. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  33312. this.startXRefQueue.push(xrefStms[i]);
  33313. this.readXRef(/* recoveryMode */ true);
  33314. }
  33315. // finding main trailer
  33316. var dict;
  33317. for (i = 0, ii = trailers.length; i < ii; ++i) {
  33318. stream.pos = trailers[i];
  33319. var parser = new Parser(new Lexer(stream), true, this);
  33320. var obj = parser.getObj();
  33321. if (!isCmd(obj, 'trailer')) {
  33322. continue;
  33323. }
  33324. // read the trailer dictionary
  33325. if (!isDict(dict = parser.getObj())) {
  33326. continue;
  33327. }
  33328. // taking the first one with 'ID'
  33329. if (dict.has('ID')) {
  33330. return dict;
  33331. }
  33332. }
  33333. // no tailer with 'ID', taking last one (if exists)
  33334. if (dict) {
  33335. return dict;
  33336. }
  33337. // nothing helps
  33338. // calling error() would reject worker with an UnknownErrorException.
  33339. throw new InvalidPDFException('Invalid PDF structure');
  33340. },
  33341. readXRef: function XRef_readXRef(recoveryMode) {
  33342. var stream = this.stream;
  33343. try {
  33344. while (this.startXRefQueue.length) {
  33345. var startXRef = this.startXRefQueue[0];
  33346. stream.pos = startXRef + stream.start;
  33347. var parser = new Parser(new Lexer(stream), true, this);
  33348. var obj = parser.getObj();
  33349. var dict;
  33350. // Get dictionary
  33351. if (isCmd(obj, 'xref')) {
  33352. // Parse end-of-file XRef
  33353. dict = this.processXRefTable(parser);
  33354. if (!this.topDict) {
  33355. this.topDict = dict;
  33356. }
  33357. // Recursively get other XRefs 'XRefStm', if any
  33358. obj = dict.get('XRefStm');
  33359. if (isInt(obj)) {
  33360. var pos = obj;
  33361. // ignore previously loaded xref streams
  33362. // (possible infinite recursion)
  33363. if (!(pos in this.xrefstms)) {
  33364. this.xrefstms[pos] = 1;
  33365. this.startXRefQueue.push(pos);
  33366. }
  33367. }
  33368. } else if (isInt(obj)) {
  33369. // Parse in-stream XRef
  33370. if (!isInt(parser.getObj()) ||
  33371. !isCmd(parser.getObj(), 'obj') ||
  33372. !isStream(obj = parser.getObj())) {
  33373. error('Invalid XRef stream');
  33374. }
  33375. dict = this.processXRefStream(obj);
  33376. if (!this.topDict) {
  33377. this.topDict = dict;
  33378. }
  33379. if (!dict) {
  33380. error('Failed to read XRef stream');
  33381. }
  33382. } else {
  33383. error('Invalid XRef stream header');
  33384. }
  33385. // Recursively get previous dictionary, if any
  33386. obj = dict.get('Prev');
  33387. if (isInt(obj)) {
  33388. this.startXRefQueue.push(obj);
  33389. } else if (isRef(obj)) {
  33390. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  33391. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  33392. this.startXRefQueue.push(obj.num);
  33393. }
  33394. this.startXRefQueue.shift();
  33395. }
  33396. return this.topDict;
  33397. } catch (e) {
  33398. if (e instanceof MissingDataException) {
  33399. throw e;
  33400. }
  33401. info('(while reading XRef): ' + e);
  33402. }
  33403. if (recoveryMode) {
  33404. return;
  33405. }
  33406. throw new XRefParseException();
  33407. },
  33408. getEntry: function XRef_getEntry(i) {
  33409. var xrefEntry = this.entries[i];
  33410. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  33411. return xrefEntry;
  33412. }
  33413. return null;
  33414. },
  33415. fetchIfRef: function XRef_fetchIfRef(obj) {
  33416. if (!isRef(obj)) {
  33417. return obj;
  33418. }
  33419. return this.fetch(obj);
  33420. },
  33421. fetch: function XRef_fetch(ref, suppressEncryption) {
  33422. assert(isRef(ref), 'ref object is not a reference');
  33423. var num = ref.num;
  33424. if (num in this.cache) {
  33425. var cacheEntry = this.cache[num];
  33426. return cacheEntry;
  33427. }
  33428. var xrefEntry = this.getEntry(num);
  33429. // the referenced entry can be free
  33430. if (xrefEntry === null) {
  33431. return (this.cache[num] = null);
  33432. }
  33433. if (xrefEntry.uncompressed) {
  33434. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  33435. } else {
  33436. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  33437. }
  33438. if (isDict(xrefEntry)){
  33439. xrefEntry.objId = ref.toString();
  33440. } else if (isStream(xrefEntry)) {
  33441. xrefEntry.dict.objId = ref.toString();
  33442. }
  33443. return xrefEntry;
  33444. },
  33445. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  33446. suppressEncryption) {
  33447. var gen = ref.gen;
  33448. var num = ref.num;
  33449. if (xrefEntry.gen !== gen) {
  33450. error('inconsistent generation in XRef');
  33451. }
  33452. var stream = this.stream.makeSubStream(xrefEntry.offset +
  33453. this.stream.start);
  33454. var parser = new Parser(new Lexer(stream), true, this);
  33455. var obj1 = parser.getObj();
  33456. var obj2 = parser.getObj();
  33457. var obj3 = parser.getObj();
  33458. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  33459. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  33460. !isCmd(obj3)) {
  33461. error('bad XRef entry');
  33462. }
  33463. if (!isCmd(obj3, 'obj')) {
  33464. // some bad PDFs use "obj1234" and really mean 1234
  33465. if (obj3.cmd.indexOf('obj') === 0) {
  33466. num = parseInt(obj3.cmd.substring(3), 10);
  33467. if (!isNaN(num)) {
  33468. return num;
  33469. }
  33470. }
  33471. error('bad XRef entry');
  33472. }
  33473. if (this.encrypt && !suppressEncryption) {
  33474. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  33475. } else {
  33476. xrefEntry = parser.getObj();
  33477. }
  33478. if (!isStream(xrefEntry)) {
  33479. this.cache[num] = xrefEntry;
  33480. }
  33481. return xrefEntry;
  33482. },
  33483. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  33484. suppressEncryption) {
  33485. var tableOffset = xrefEntry.offset;
  33486. var stream = this.fetch(new Ref(tableOffset, 0));
  33487. if (!isStream(stream)) {
  33488. error('bad ObjStm stream');
  33489. }
  33490. var first = stream.dict.get('First');
  33491. var n = stream.dict.get('N');
  33492. if (!isInt(first) || !isInt(n)) {
  33493. error('invalid first and n parameters for ObjStm stream');
  33494. }
  33495. var parser = new Parser(new Lexer(stream), false, this);
  33496. parser.allowStreams = true;
  33497. var i, entries = [], num, nums = [];
  33498. // read the object numbers to populate cache
  33499. for (i = 0; i < n; ++i) {
  33500. num = parser.getObj();
  33501. if (!isInt(num)) {
  33502. error('invalid object number in the ObjStm stream: ' + num);
  33503. }
  33504. nums.push(num);
  33505. var offset = parser.getObj();
  33506. if (!isInt(offset)) {
  33507. error('invalid object offset in the ObjStm stream: ' + offset);
  33508. }
  33509. }
  33510. // read stream objects for cache
  33511. for (i = 0; i < n; ++i) {
  33512. entries.push(parser.getObj());
  33513. num = nums[i];
  33514. var entry = this.entries[num];
  33515. if (entry && entry.offset === tableOffset && entry.gen === i) {
  33516. this.cache[num] = entries[i];
  33517. }
  33518. }
  33519. xrefEntry = entries[xrefEntry.gen];
  33520. if (xrefEntry === undefined) {
  33521. error('bad XRef entry for compressed object');
  33522. }
  33523. return xrefEntry;
  33524. },
  33525. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  33526. if (!isRef(obj)) {
  33527. return Promise.resolve(obj);
  33528. }
  33529. return this.fetchAsync(obj);
  33530. },
  33531. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  33532. var streamManager = this.stream.manager;
  33533. var xref = this;
  33534. return new Promise(function tryFetch(resolve, reject) {
  33535. try {
  33536. resolve(xref.fetch(ref, suppressEncryption));
  33537. } catch (e) {
  33538. if (e instanceof MissingDataException) {
  33539. streamManager.requestRange(e.begin, e.end).then(function () {
  33540. tryFetch(resolve, reject);
  33541. }, reject);
  33542. return;
  33543. }
  33544. reject(e);
  33545. }
  33546. });
  33547. },
  33548. getCatalogObj: function XRef_getCatalogObj() {
  33549. return this.root;
  33550. }
  33551. };
  33552. return XRef;
  33553. })();
  33554. /**
  33555. * A NameTree/NumberTree is like a Dict but has some advantageous properties,
  33556. * see the specification (7.9.6 and 7.9.7) for additional details.
  33557. * TODO: implement all the Dict functions and make this more efficient.
  33558. */
  33559. var NameOrNumberTree = (function NameOrNumberTreeClosure() {
  33560. function NameOrNumberTree(root, xref) {
  33561. throw new Error('Cannot initialize NameOrNumberTree.');
  33562. }
  33563. NameOrNumberTree.prototype = {
  33564. getAll: function NameOrNumberTree_getAll() {
  33565. var dict = Object.create(null);
  33566. if (!this.root) {
  33567. return dict;
  33568. }
  33569. var xref = this.xref;
  33570. // Reading Name/Number tree.
  33571. var processed = new RefSet();
  33572. processed.put(this.root);
  33573. var queue = [this.root];
  33574. while (queue.length > 0) {
  33575. var i, n;
  33576. var obj = xref.fetchIfRef(queue.shift());
  33577. if (!isDict(obj)) {
  33578. continue;
  33579. }
  33580. if (obj.has('Kids')) {
  33581. var kids = obj.get('Kids');
  33582. for (i = 0, n = kids.length; i < n; i++) {
  33583. var kid = kids[i];
  33584. assert(!processed.has(kid),
  33585. 'Duplicate entry in "' + this._type + '" tree.');
  33586. queue.push(kid);
  33587. processed.put(kid);
  33588. }
  33589. continue;
  33590. }
  33591. var entries = obj.get(this._type);
  33592. if (isArray(entries)) {
  33593. for (i = 0, n = entries.length; i < n; i += 2) {
  33594. dict[xref.fetchIfRef(entries[i])] = xref.fetchIfRef(entries[i + 1]);
  33595. }
  33596. }
  33597. }
  33598. return dict;
  33599. },
  33600. get: function NameOrNumberTree_get(key) {
  33601. if (!this.root) {
  33602. return null;
  33603. }
  33604. var xref = this.xref;
  33605. var kidsOrEntries = xref.fetchIfRef(this.root);
  33606. var loopCount = 0;
  33607. var MAX_LEVELS = 10;
  33608. var l, r, m;
  33609. // Perform a binary search to quickly find the entry that
  33610. // contains the key we are looking for.
  33611. while (kidsOrEntries.has('Kids')) {
  33612. if (++loopCount > MAX_LEVELS) {
  33613. warn('Search depth limit reached for "' + this._type + '" tree.');
  33614. return null;
  33615. }
  33616. var kids = kidsOrEntries.get('Kids');
  33617. if (!isArray(kids)) {
  33618. return null;
  33619. }
  33620. l = 0;
  33621. r = kids.length - 1;
  33622. while (l <= r) {
  33623. m = (l + r) >> 1;
  33624. var kid = xref.fetchIfRef(kids[m]);
  33625. var limits = kid.get('Limits');
  33626. if (key < xref.fetchIfRef(limits[0])) {
  33627. r = m - 1;
  33628. } else if (key > xref.fetchIfRef(limits[1])) {
  33629. l = m + 1;
  33630. } else {
  33631. kidsOrEntries = xref.fetchIfRef(kids[m]);
  33632. break;
  33633. }
  33634. }
  33635. if (l > r) {
  33636. return null;
  33637. }
  33638. }
  33639. // If we get here, then we have found the right entry. Now go through the
  33640. // entries in the dictionary until we find the key we're looking for.
  33641. var entries = kidsOrEntries.get(this._type);
  33642. if (isArray(entries)) {
  33643. // Perform a binary search to reduce the lookup time.
  33644. l = 0;
  33645. r = entries.length - 2;
  33646. while (l <= r) {
  33647. // Check only even indices (0, 2, 4, ...) because the
  33648. // odd indices contain the actual data.
  33649. m = (l + r) & ~1;
  33650. var currentKey = xref.fetchIfRef(entries[m]);
  33651. if (key < currentKey) {
  33652. r = m - 2;
  33653. } else if (key > currentKey) {
  33654. l = m + 2;
  33655. } else {
  33656. return xref.fetchIfRef(entries[m + 1]);
  33657. }
  33658. }
  33659. }
  33660. return null;
  33661. }
  33662. };
  33663. return NameOrNumberTree;
  33664. })();
  33665. var NameTree = (function NameTreeClosure() {
  33666. function NameTree(root, xref) {
  33667. this.root = root;
  33668. this.xref = xref;
  33669. this._type = 'Names';
  33670. }
  33671. Util.inherit(NameTree, NameOrNumberTree, {});
  33672. return NameTree;
  33673. })();
  33674. var NumberTree = (function NumberTreeClosure() {
  33675. function NumberTree(root, xref) {
  33676. this.root = root;
  33677. this.xref = xref;
  33678. this._type = 'Nums';
  33679. }
  33680. Util.inherit(NumberTree, NameOrNumberTree, {});
  33681. return NumberTree;
  33682. })();
  33683. /**
  33684. * "A PDF file can refer to the contents of another file by using a File
  33685. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  33686. * NOTE: Only embedded files are supported (as part of the attachments support)
  33687. * TODO: support the 'URL' file system (with caching if !/V), portable
  33688. * collections attributes and related files (/RF)
  33689. */
  33690. var FileSpec = (function FileSpecClosure() {
  33691. function FileSpec(root, xref) {
  33692. if (!root || !isDict(root)) {
  33693. return;
  33694. }
  33695. this.xref = xref;
  33696. this.root = root;
  33697. if (root.has('FS')) {
  33698. this.fs = root.get('FS');
  33699. }
  33700. this.description = root.has('Desc') ?
  33701. stringToPDFString(root.get('Desc')) :
  33702. '';
  33703. if (root.has('RF')) {
  33704. warn('Related file specifications are not supported');
  33705. }
  33706. this.contentAvailable = true;
  33707. if (!root.has('EF')) {
  33708. this.contentAvailable = false;
  33709. warn('Non-embedded file specifications are not supported');
  33710. }
  33711. }
  33712. function pickPlatformItem(dict) {
  33713. // Look for the filename in this order:
  33714. // UF, F, Unix, Mac, DOS
  33715. if (dict.has('UF')) {
  33716. return dict.get('UF');
  33717. } else if (dict.has('F')) {
  33718. return dict.get('F');
  33719. } else if (dict.has('Unix')) {
  33720. return dict.get('Unix');
  33721. } else if (dict.has('Mac')) {
  33722. return dict.get('Mac');
  33723. } else if (dict.has('DOS')) {
  33724. return dict.get('DOS');
  33725. } else {
  33726. return null;
  33727. }
  33728. }
  33729. FileSpec.prototype = {
  33730. get filename() {
  33731. if (!this._filename && this.root) {
  33732. var filename = pickPlatformItem(this.root) || 'unnamed';
  33733. this._filename = stringToPDFString(filename).
  33734. replace(/\\\\/g, '\\').
  33735. replace(/\\\//g, '/').
  33736. replace(/\\/g, '/');
  33737. }
  33738. return this._filename;
  33739. },
  33740. get content() {
  33741. if (!this.contentAvailable) {
  33742. return null;
  33743. }
  33744. if (!this.contentRef && this.root) {
  33745. this.contentRef = pickPlatformItem(this.root.get('EF'));
  33746. }
  33747. var content = null;
  33748. if (this.contentRef) {
  33749. var xref = this.xref;
  33750. var fileObj = xref.fetchIfRef(this.contentRef);
  33751. if (fileObj && isStream(fileObj)) {
  33752. content = fileObj.getBytes();
  33753. } else {
  33754. warn('Embedded file specification points to non-existing/invalid ' +
  33755. 'content');
  33756. }
  33757. } else {
  33758. warn('Embedded file specification does not have a content');
  33759. }
  33760. return content;
  33761. },
  33762. get serializable() {
  33763. return {
  33764. filename: this.filename,
  33765. content: this.content
  33766. };
  33767. }
  33768. };
  33769. return FileSpec;
  33770. })();
  33771. /**
  33772. * A helper for loading missing data in object graphs. It traverses the graph
  33773. * depth first and queues up any objects that have missing data. Once it has
  33774. * has traversed as many objects that are available it attempts to bundle the
  33775. * missing data requests and then resume from the nodes that weren't ready.
  33776. *
  33777. * NOTE: It provides protection from circular references by keeping track of
  33778. * of loaded references. However, you must be careful not to load any graphs
  33779. * that have references to the catalog or other pages since that will cause the
  33780. * entire PDF document object graph to be traversed.
  33781. */
  33782. var ObjectLoader = (function() {
  33783. function mayHaveChildren(value) {
  33784. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  33785. }
  33786. function addChildren(node, nodesToVisit) {
  33787. var value;
  33788. if (isDict(node) || isStream(node)) {
  33789. var map;
  33790. if (isDict(node)) {
  33791. map = node.map;
  33792. } else {
  33793. map = node.dict.map;
  33794. }
  33795. for (var key in map) {
  33796. value = map[key];
  33797. if (mayHaveChildren(value)) {
  33798. nodesToVisit.push(value);
  33799. }
  33800. }
  33801. } else if (isArray(node)) {
  33802. for (var i = 0, ii = node.length; i < ii; i++) {
  33803. value = node[i];
  33804. if (mayHaveChildren(value)) {
  33805. nodesToVisit.push(value);
  33806. }
  33807. }
  33808. }
  33809. }
  33810. function ObjectLoader(obj, keys, xref) {
  33811. this.obj = obj;
  33812. this.keys = keys;
  33813. this.xref = xref;
  33814. this.refSet = null;
  33815. this.capability = null;
  33816. }
  33817. ObjectLoader.prototype = {
  33818. load: function ObjectLoader_load() {
  33819. var keys = this.keys;
  33820. this.capability = createPromiseCapability();
  33821. // Don't walk the graph if all the data is already loaded.
  33822. if (!(this.xref.stream instanceof ChunkedStream) ||
  33823. this.xref.stream.getMissingChunks().length === 0) {
  33824. this.capability.resolve();
  33825. return this.capability.promise;
  33826. }
  33827. this.refSet = new RefSet();
  33828. // Setup the initial nodes to visit.
  33829. var nodesToVisit = [];
  33830. for (var i = 0; i < keys.length; i++) {
  33831. nodesToVisit.push(this.obj[keys[i]]);
  33832. }
  33833. this._walk(nodesToVisit);
  33834. return this.capability.promise;
  33835. },
  33836. _walk: function ObjectLoader_walk(nodesToVisit) {
  33837. var nodesToRevisit = [];
  33838. var pendingRequests = [];
  33839. // DFS walk of the object graph.
  33840. while (nodesToVisit.length) {
  33841. var currentNode = nodesToVisit.pop();
  33842. // Only references or chunked streams can cause missing data exceptions.
  33843. if (isRef(currentNode)) {
  33844. // Skip nodes that have already been visited.
  33845. if (this.refSet.has(currentNode)) {
  33846. continue;
  33847. }
  33848. try {
  33849. var ref = currentNode;
  33850. this.refSet.put(ref);
  33851. currentNode = this.xref.fetch(currentNode);
  33852. } catch (e) {
  33853. if (!(e instanceof MissingDataException)) {
  33854. throw e;
  33855. }
  33856. nodesToRevisit.push(currentNode);
  33857. pendingRequests.push({ begin: e.begin, end: e.end });
  33858. }
  33859. }
  33860. if (currentNode && currentNode.getBaseStreams) {
  33861. var baseStreams = currentNode.getBaseStreams();
  33862. var foundMissingData = false;
  33863. for (var i = 0; i < baseStreams.length; i++) {
  33864. var stream = baseStreams[i];
  33865. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  33866. foundMissingData = true;
  33867. pendingRequests.push({
  33868. begin: stream.start,
  33869. end: stream.end
  33870. });
  33871. }
  33872. }
  33873. if (foundMissingData) {
  33874. nodesToRevisit.push(currentNode);
  33875. }
  33876. }
  33877. addChildren(currentNode, nodesToVisit);
  33878. }
  33879. if (pendingRequests.length) {
  33880. this.xref.stream.manager.requestRanges(pendingRequests).then(
  33881. function pendingRequestCallback() {
  33882. nodesToVisit = nodesToRevisit;
  33883. for (var i = 0; i < nodesToRevisit.length; i++) {
  33884. var node = nodesToRevisit[i];
  33885. // Remove any reference nodes from the currrent refset so they
  33886. // aren't skipped when we revist them.
  33887. if (isRef(node)) {
  33888. this.refSet.remove(node);
  33889. }
  33890. }
  33891. this._walk(nodesToVisit);
  33892. }.bind(this), this.capability.reject);
  33893. return;
  33894. }
  33895. // Everything is loaded.
  33896. this.refSet = null;
  33897. this.capability.resolve();
  33898. }
  33899. };
  33900. return ObjectLoader;
  33901. })();
  33902. exports.Catalog = Catalog;
  33903. exports.ObjectLoader = ObjectLoader;
  33904. exports.XRef = XRef;
  33905. exports.FileSpec = FileSpec;
  33906. }));
  33907. (function (root, factory) {
  33908. {
  33909. factory((root.pdfjsCorePattern = {}), root.pdfjsSharedUtil,
  33910. root.pdfjsCorePrimitives, root.pdfjsCoreFunction,
  33911. root.pdfjsCoreColorSpace);
  33912. }
  33913. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  33914. coreColorSpace) {
  33915. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  33916. var MissingDataException = sharedUtil.MissingDataException;
  33917. var Util = sharedUtil.Util;
  33918. var assert = sharedUtil.assert;
  33919. var error = sharedUtil.error;
  33920. var info = sharedUtil.info;
  33921. var warn = sharedUtil.warn;
  33922. var isStream = corePrimitives.isStream;
  33923. var PDFFunction = coreFunction.PDFFunction;
  33924. var ColorSpace = coreColorSpace.ColorSpace;
  33925. var ShadingType = {
  33926. FUNCTION_BASED: 1,
  33927. AXIAL: 2,
  33928. RADIAL: 3,
  33929. FREE_FORM_MESH: 4,
  33930. LATTICE_FORM_MESH: 5,
  33931. COONS_PATCH_MESH: 6,
  33932. TENSOR_PATCH_MESH: 7
  33933. };
  33934. var Pattern = (function PatternClosure() {
  33935. // Constructor should define this.getPattern
  33936. function Pattern() {
  33937. error('should not call Pattern constructor');
  33938. }
  33939. Pattern.prototype = {
  33940. // Input: current Canvas context
  33941. // Output: the appropriate fillStyle or strokeStyle
  33942. getPattern: function Pattern_getPattern(ctx) {
  33943. error('Should not call Pattern.getStyle: ' + ctx);
  33944. }
  33945. };
  33946. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  33947. res, handler) {
  33948. var dict = isStream(shading) ? shading.dict : shading;
  33949. var type = dict.get('ShadingType');
  33950. try {
  33951. switch (type) {
  33952. case ShadingType.AXIAL:
  33953. case ShadingType.RADIAL:
  33954. // Both radial and axial shadings are handled by RadialAxial shading.
  33955. return new Shadings.RadialAxial(dict, matrix, xref, res);
  33956. case ShadingType.FREE_FORM_MESH:
  33957. case ShadingType.LATTICE_FORM_MESH:
  33958. case ShadingType.COONS_PATCH_MESH:
  33959. case ShadingType.TENSOR_PATCH_MESH:
  33960. return new Shadings.Mesh(shading, matrix, xref, res);
  33961. default:
  33962. throw new Error('Unsupported ShadingType: ' + type);
  33963. }
  33964. } catch (ex) {
  33965. if (ex instanceof MissingDataException) {
  33966. throw ex;
  33967. }
  33968. handler.send('UnsupportedFeature',
  33969. {featureId: UNSUPPORTED_FEATURES.shadingPattern});
  33970. warn(ex);
  33971. return new Shadings.Dummy();
  33972. }
  33973. };
  33974. return Pattern;
  33975. })();
  33976. var Shadings = {};
  33977. // A small number to offset the first/last color stops so we can insert ones to
  33978. // support extend. Number.MIN_VALUE is too small and breaks the extend.
  33979. Shadings.SMALL_NUMBER = 1e-6;
  33980. // Radial and axial shading have very similar implementations
  33981. // If needed, the implementations can be broken into two classes
  33982. Shadings.RadialAxial = (function RadialAxialClosure() {
  33983. function RadialAxial(dict, matrix, xref, res) {
  33984. this.matrix = matrix;
  33985. this.coordsArr = dict.get('Coords');
  33986. this.shadingType = dict.get('ShadingType');
  33987. this.type = 'Pattern';
  33988. var cs = dict.get('ColorSpace', 'CS');
  33989. cs = ColorSpace.parse(cs, xref, res);
  33990. this.cs = cs;
  33991. var t0 = 0.0, t1 = 1.0;
  33992. if (dict.has('Domain')) {
  33993. var domainArr = dict.get('Domain');
  33994. t0 = domainArr[0];
  33995. t1 = domainArr[1];
  33996. }
  33997. var extendStart = false, extendEnd = false;
  33998. if (dict.has('Extend')) {
  33999. var extendArr = dict.get('Extend');
  34000. extendStart = extendArr[0];
  34001. extendEnd = extendArr[1];
  34002. }
  34003. if (this.shadingType === ShadingType.RADIAL &&
  34004. (!extendStart || !extendEnd)) {
  34005. // Radial gradient only currently works if either circle is fully within
  34006. // the other circle.
  34007. var x1 = this.coordsArr[0];
  34008. var y1 = this.coordsArr[1];
  34009. var r1 = this.coordsArr[2];
  34010. var x2 = this.coordsArr[3];
  34011. var y2 = this.coordsArr[4];
  34012. var r2 = this.coordsArr[5];
  34013. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  34014. if (r1 <= r2 + distance &&
  34015. r2 <= r1 + distance) {
  34016. warn('Unsupported radial gradient.');
  34017. }
  34018. }
  34019. this.extendStart = extendStart;
  34020. this.extendEnd = extendEnd;
  34021. var fnObj = dict.get('Function');
  34022. var fn = PDFFunction.parseArray(xref, fnObj);
  34023. // 10 samples seems good enough for now, but probably won't work
  34024. // if there are sharp color changes. Ideally, we would implement
  34025. // the spec faithfully and add lossless optimizations.
  34026. var diff = t1 - t0;
  34027. var step = diff / 10;
  34028. var colorStops = this.colorStops = [];
  34029. // Protect against bad domains so we don't end up in an infinte loop below.
  34030. if (t0 >= t1 || step <= 0) {
  34031. // Acrobat doesn't seem to handle these cases so we'll ignore for
  34032. // now.
  34033. info('Bad shading domain.');
  34034. return;
  34035. }
  34036. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  34037. var rgbColor;
  34038. for (var i = t0; i <= t1; i += step) {
  34039. ratio[0] = i;
  34040. fn(ratio, 0, color, 0);
  34041. rgbColor = cs.getRgb(color, 0);
  34042. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  34043. colorStops.push([(i - t0) / diff, cssColor]);
  34044. }
  34045. var background = 'transparent';
  34046. if (dict.has('Background')) {
  34047. rgbColor = cs.getRgb(dict.get('Background'), 0);
  34048. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  34049. }
  34050. if (!extendStart) {
  34051. // Insert a color stop at the front and offset the first real color stop
  34052. // so it doesn't conflict with the one we insert.
  34053. colorStops.unshift([0, background]);
  34054. colorStops[1][0] += Shadings.SMALL_NUMBER;
  34055. }
  34056. if (!extendEnd) {
  34057. // Same idea as above in extendStart but for the end.
  34058. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  34059. colorStops.push([1, background]);
  34060. }
  34061. this.colorStops = colorStops;
  34062. }
  34063. RadialAxial.prototype = {
  34064. getIR: function RadialAxial_getIR() {
  34065. var coordsArr = this.coordsArr;
  34066. var shadingType = this.shadingType;
  34067. var type, p0, p1, r0, r1;
  34068. if (shadingType === ShadingType.AXIAL) {
  34069. p0 = [coordsArr[0], coordsArr[1]];
  34070. p1 = [coordsArr[2], coordsArr[3]];
  34071. r0 = null;
  34072. r1 = null;
  34073. type = 'axial';
  34074. } else if (shadingType === ShadingType.RADIAL) {
  34075. p0 = [coordsArr[0], coordsArr[1]];
  34076. p1 = [coordsArr[3], coordsArr[4]];
  34077. r0 = coordsArr[2];
  34078. r1 = coordsArr[5];
  34079. type = 'radial';
  34080. } else {
  34081. error('getPattern type unknown: ' + shadingType);
  34082. }
  34083. var matrix = this.matrix;
  34084. if (matrix) {
  34085. p0 = Util.applyTransform(p0, matrix);
  34086. p1 = Util.applyTransform(p1, matrix);
  34087. if (shadingType === ShadingType.RADIAL) {
  34088. var scale = Util.singularValueDecompose2dScale(matrix);
  34089. r0 *= scale[0];
  34090. r1 *= scale[1];
  34091. }
  34092. }
  34093. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  34094. }
  34095. };
  34096. return RadialAxial;
  34097. })();
  34098. // All mesh shading. For now, they will be presented as set of the triangles
  34099. // to be drawn on the canvas and rgb color for each vertex.
  34100. Shadings.Mesh = (function MeshClosure() {
  34101. function MeshStreamReader(stream, context) {
  34102. this.stream = stream;
  34103. this.context = context;
  34104. this.buffer = 0;
  34105. this.bufferLength = 0;
  34106. var numComps = context.numComps;
  34107. this.tmpCompsBuf = new Float32Array(numComps);
  34108. var csNumComps = context.colorSpace.numComps;
  34109. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  34110. this.tmpCompsBuf;
  34111. }
  34112. MeshStreamReader.prototype = {
  34113. get hasData() {
  34114. if (this.stream.end) {
  34115. return this.stream.pos < this.stream.end;
  34116. }
  34117. if (this.bufferLength > 0) {
  34118. return true;
  34119. }
  34120. var nextByte = this.stream.getByte();
  34121. if (nextByte < 0) {
  34122. return false;
  34123. }
  34124. this.buffer = nextByte;
  34125. this.bufferLength = 8;
  34126. return true;
  34127. },
  34128. readBits: function MeshStreamReader_readBits(n) {
  34129. var buffer = this.buffer;
  34130. var bufferLength = this.bufferLength;
  34131. if (n === 32) {
  34132. if (bufferLength === 0) {
  34133. return ((this.stream.getByte() << 24) |
  34134. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  34135. this.stream.getByte()) >>> 0;
  34136. }
  34137. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  34138. (this.stream.getByte() << 8) | this.stream.getByte();
  34139. var nextByte = this.stream.getByte();
  34140. this.buffer = nextByte & ((1 << bufferLength) - 1);
  34141. return ((buffer << (8 - bufferLength)) |
  34142. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  34143. }
  34144. if (n === 8 && bufferLength === 0) {
  34145. return this.stream.getByte();
  34146. }
  34147. while (bufferLength < n) {
  34148. buffer = (buffer << 8) | this.stream.getByte();
  34149. bufferLength += 8;
  34150. }
  34151. bufferLength -= n;
  34152. this.bufferLength = bufferLength;
  34153. this.buffer = buffer & ((1 << bufferLength) - 1);
  34154. return buffer >> bufferLength;
  34155. },
  34156. align: function MeshStreamReader_align() {
  34157. this.buffer = 0;
  34158. this.bufferLength = 0;
  34159. },
  34160. readFlag: function MeshStreamReader_readFlag() {
  34161. return this.readBits(this.context.bitsPerFlag);
  34162. },
  34163. readCoordinate: function MeshStreamReader_readCoordinate() {
  34164. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  34165. var xi = this.readBits(bitsPerCoordinate);
  34166. var yi = this.readBits(bitsPerCoordinate);
  34167. var decode = this.context.decode;
  34168. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  34169. 2.3283064365386963e-10; // 2 ^ -32
  34170. return [
  34171. xi * scale * (decode[1] - decode[0]) + decode[0],
  34172. yi * scale * (decode[3] - decode[2]) + decode[2]
  34173. ];
  34174. },
  34175. readComponents: function MeshStreamReader_readComponents() {
  34176. var numComps = this.context.numComps;
  34177. var bitsPerComponent = this.context.bitsPerComponent;
  34178. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  34179. 2.3283064365386963e-10; // 2 ^ -32
  34180. var decode = this.context.decode;
  34181. var components = this.tmpCompsBuf;
  34182. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  34183. var ci = this.readBits(bitsPerComponent);
  34184. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  34185. }
  34186. var color = this.tmpCsCompsBuf;
  34187. if (this.context.colorFn) {
  34188. this.context.colorFn(components, 0, color, 0);
  34189. }
  34190. return this.context.colorSpace.getRgb(color, 0);
  34191. }
  34192. };
  34193. function decodeType4Shading(mesh, reader) {
  34194. var coords = mesh.coords;
  34195. var colors = mesh.colors;
  34196. var operators = [];
  34197. var ps = []; // not maintaining cs since that will match ps
  34198. var verticesLeft = 0; // assuming we have all data to start a new triangle
  34199. while (reader.hasData) {
  34200. var f = reader.readFlag();
  34201. var coord = reader.readCoordinate();
  34202. var color = reader.readComponents();
  34203. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  34204. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  34205. switch (f) {
  34206. case 0:
  34207. verticesLeft = 3;
  34208. break;
  34209. case 1:
  34210. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  34211. verticesLeft = 1;
  34212. break;
  34213. case 2:
  34214. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  34215. verticesLeft = 1;
  34216. break;
  34217. }
  34218. operators.push(f);
  34219. }
  34220. ps.push(coords.length);
  34221. coords.push(coord);
  34222. colors.push(color);
  34223. verticesLeft--;
  34224. reader.align();
  34225. }
  34226. mesh.figures.push({
  34227. type: 'triangles',
  34228. coords: new Int32Array(ps),
  34229. colors: new Int32Array(ps),
  34230. });
  34231. }
  34232. function decodeType5Shading(mesh, reader, verticesPerRow) {
  34233. var coords = mesh.coords;
  34234. var colors = mesh.colors;
  34235. var ps = []; // not maintaining cs since that will match ps
  34236. while (reader.hasData) {
  34237. var coord = reader.readCoordinate();
  34238. var color = reader.readComponents();
  34239. ps.push(coords.length);
  34240. coords.push(coord);
  34241. colors.push(color);
  34242. }
  34243. mesh.figures.push({
  34244. type: 'lattice',
  34245. coords: new Int32Array(ps),
  34246. colors: new Int32Array(ps),
  34247. verticesPerRow: verticesPerRow
  34248. });
  34249. }
  34250. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  34251. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  34252. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  34253. var getB = (function getBClosure() {
  34254. function buildB(count) {
  34255. var lut = [];
  34256. for (var i = 0; i <= count; i++) {
  34257. var t = i / count, t_ = 1 - t;
  34258. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  34259. 3 * t * t * t_, t * t * t]));
  34260. }
  34261. return lut;
  34262. }
  34263. var cache = [];
  34264. return function getB(count) {
  34265. if (!cache[count]) {
  34266. cache[count] = buildB(count);
  34267. }
  34268. return cache[count];
  34269. };
  34270. })();
  34271. function buildFigureFromPatch(mesh, index) {
  34272. var figure = mesh.figures[index];
  34273. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  34274. var coords = mesh.coords, colors = mesh.colors;
  34275. var pi = figure.coords;
  34276. var ci = figure.colors;
  34277. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  34278. coords[pi[12]][0], coords[pi[15]][0]);
  34279. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  34280. coords[pi[12]][1], coords[pi[15]][1]);
  34281. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  34282. coords[pi[12]][0], coords[pi[15]][0]);
  34283. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  34284. coords[pi[12]][1], coords[pi[15]][1]);
  34285. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  34286. (mesh.bounds[2] - mesh.bounds[0]));
  34287. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  34288. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  34289. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  34290. (mesh.bounds[3] - mesh.bounds[1]));
  34291. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  34292. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  34293. var verticesPerRow = splitXBy + 1;
  34294. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  34295. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  34296. var k = 0;
  34297. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  34298. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  34299. c2 = colors[ci[2]], c3 = colors[ci[3]];
  34300. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  34301. for (var row = 0; row <= splitYBy; row++) {
  34302. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  34303. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  34304. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  34305. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  34306. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  34307. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  34308. for (var col = 0; col <= splitXBy; col++, k++) {
  34309. if ((row === 0 || row === splitYBy) &&
  34310. (col === 0 || col === splitXBy)) {
  34311. continue;
  34312. }
  34313. var x = 0, y = 0;
  34314. var q = 0;
  34315. for (var i = 0; i <= 3; i++) {
  34316. for (var j = 0; j <= 3; j++, q++) {
  34317. var m = bRow[row][i] * bCol[col][j];
  34318. x += coords[pi[q]][0] * m;
  34319. y += coords[pi[q]][1] * m;
  34320. }
  34321. }
  34322. figureCoords[k] = coords.length;
  34323. coords.push([x, y]);
  34324. figureColors[k] = colors.length;
  34325. var newColor = new Uint8Array(3);
  34326. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  34327. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  34328. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  34329. colors.push(newColor);
  34330. }
  34331. }
  34332. figureCoords[0] = pi[0];
  34333. figureColors[0] = ci[0];
  34334. figureCoords[splitXBy] = pi[3];
  34335. figureColors[splitXBy] = ci[1];
  34336. figureCoords[verticesPerRow * splitYBy] = pi[12];
  34337. figureColors[verticesPerRow * splitYBy] = ci[2];
  34338. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  34339. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  34340. mesh.figures[index] = {
  34341. type: 'lattice',
  34342. coords: figureCoords,
  34343. colors: figureColors,
  34344. verticesPerRow: verticesPerRow
  34345. };
  34346. }
  34347. function decodeType6Shading(mesh, reader) {
  34348. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  34349. var coords = mesh.coords;
  34350. var colors = mesh.colors;
  34351. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  34352. var cs = new Int32Array(4); // c00, c30, c03, c33
  34353. while (reader.hasData) {
  34354. var f = reader.readFlag();
  34355. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  34356. var i, ii;
  34357. var pi = coords.length;
  34358. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  34359. coords.push(reader.readCoordinate());
  34360. }
  34361. var ci = colors.length;
  34362. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  34363. colors.push(reader.readComponents());
  34364. }
  34365. var tmp1, tmp2, tmp3, tmp4;
  34366. switch (f) {
  34367. case 0:
  34368. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  34369. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  34370. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  34371. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  34372. cs[2] = ci + 1; cs[3] = ci + 2;
  34373. cs[0] = ci; cs[1] = ci + 3;
  34374. break;
  34375. case 1:
  34376. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  34377. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34378. ps[ 8] = tmp3; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  34379. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  34380. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34381. tmp1 = cs[2]; tmp2 = cs[3];
  34382. cs[2] = tmp2; cs[3] = ci;
  34383. cs[0] = tmp1; cs[1] = ci + 1;
  34384. break;
  34385. case 2:
  34386. tmp1 = ps[15];
  34387. tmp2 = ps[11];
  34388. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34389. ps[ 8] = ps[7]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  34390. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  34391. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34392. tmp1 = cs[3];
  34393. cs[2] = cs[1]; cs[3] = ci;
  34394. cs[0] = tmp1; cs[1] = ci + 1;
  34395. break;
  34396. case 3:
  34397. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34398. ps[ 8] = ps[1]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  34399. ps[ 4] = ps[2]; /* calculated below */ ps[ 7] = pi + 4;
  34400. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34401. cs[2] = cs[0]; cs[3] = ci;
  34402. cs[0] = cs[1]; cs[1] = ci + 1;
  34403. break;
  34404. }
  34405. // set p11, p12, p21, p22
  34406. ps[5] = coords.length;
  34407. coords.push([
  34408. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  34409. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  34410. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  34411. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  34412. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  34413. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  34414. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  34415. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  34416. ]);
  34417. ps[6] = coords.length;
  34418. coords.push([
  34419. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  34420. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  34421. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  34422. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  34423. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  34424. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  34425. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  34426. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  34427. ]);
  34428. ps[9] = coords.length;
  34429. coords.push([
  34430. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  34431. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  34432. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  34433. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  34434. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  34435. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  34436. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  34437. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  34438. ]);
  34439. ps[10] = coords.length;
  34440. coords.push([
  34441. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  34442. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  34443. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  34444. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  34445. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  34446. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  34447. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  34448. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  34449. ]);
  34450. mesh.figures.push({
  34451. type: 'patch',
  34452. coords: new Int32Array(ps), // making copies of ps and cs
  34453. colors: new Int32Array(cs)
  34454. });
  34455. }
  34456. }
  34457. function decodeType7Shading(mesh, reader) {
  34458. var coords = mesh.coords;
  34459. var colors = mesh.colors;
  34460. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  34461. var cs = new Int32Array(4); // c00, c30, c03, c33
  34462. while (reader.hasData) {
  34463. var f = reader.readFlag();
  34464. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  34465. var i, ii;
  34466. var pi = coords.length;
  34467. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  34468. coords.push(reader.readCoordinate());
  34469. }
  34470. var ci = colors.length;
  34471. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  34472. colors.push(reader.readComponents());
  34473. }
  34474. var tmp1, tmp2, tmp3, tmp4;
  34475. switch (f) {
  34476. case 0:
  34477. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  34478. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  34479. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  34480. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  34481. cs[2] = ci + 1; cs[3] = ci + 2;
  34482. cs[0] = ci; cs[1] = ci + 3;
  34483. break;
  34484. case 1:
  34485. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  34486. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34487. ps[ 8] = tmp3; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  34488. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  34489. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34490. tmp1 = cs[2]; tmp2 = cs[3];
  34491. cs[2] = tmp2; cs[3] = ci;
  34492. cs[0] = tmp1; cs[1] = ci + 1;
  34493. break;
  34494. case 2:
  34495. tmp1 = ps[15];
  34496. tmp2 = ps[11];
  34497. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34498. ps[ 8] = ps[7]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  34499. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  34500. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34501. tmp1 = cs[3];
  34502. cs[2] = cs[1]; cs[3] = ci;
  34503. cs[0] = tmp1; cs[1] = ci + 1;
  34504. break;
  34505. case 3:
  34506. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34507. ps[ 8] = ps[1]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  34508. ps[ 4] = ps[2]; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  34509. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34510. cs[2] = cs[0]; cs[3] = ci;
  34511. cs[0] = cs[1]; cs[1] = ci + 1;
  34512. break;
  34513. }
  34514. mesh.figures.push({
  34515. type: 'patch',
  34516. coords: new Int32Array(ps), // making copies of ps and cs
  34517. colors: new Int32Array(cs)
  34518. });
  34519. }
  34520. }
  34521. function updateBounds(mesh) {
  34522. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  34523. maxX = minX, maxY = minY;
  34524. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  34525. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  34526. minX = minX > x ? x : minX;
  34527. minY = minY > y ? y : minY;
  34528. maxX = maxX < x ? x : maxX;
  34529. maxY = maxY < y ? y : maxY;
  34530. }
  34531. mesh.bounds = [minX, minY, maxX, maxY];
  34532. }
  34533. function packData(mesh) {
  34534. var i, ii, j, jj;
  34535. var coords = mesh.coords;
  34536. var coordsPacked = new Float32Array(coords.length * 2);
  34537. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  34538. var xy = coords[i];
  34539. coordsPacked[j++] = xy[0];
  34540. coordsPacked[j++] = xy[1];
  34541. }
  34542. mesh.coords = coordsPacked;
  34543. var colors = mesh.colors;
  34544. var colorsPacked = new Uint8Array(colors.length * 3);
  34545. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  34546. var c = colors[i];
  34547. colorsPacked[j++] = c[0];
  34548. colorsPacked[j++] = c[1];
  34549. colorsPacked[j++] = c[2];
  34550. }
  34551. mesh.colors = colorsPacked;
  34552. var figures = mesh.figures;
  34553. for (i = 0, ii = figures.length; i < ii; i++) {
  34554. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  34555. for (j = 0, jj = ps.length; j < jj; j++) {
  34556. ps[j] *= 2;
  34557. cs[j] *= 3;
  34558. }
  34559. }
  34560. }
  34561. function Mesh(stream, matrix, xref, res) {
  34562. assert(isStream(stream), 'Mesh data is not a stream');
  34563. var dict = stream.dict;
  34564. this.matrix = matrix;
  34565. this.shadingType = dict.get('ShadingType');
  34566. this.type = 'Pattern';
  34567. this.bbox = dict.get('BBox');
  34568. var cs = dict.get('ColorSpace', 'CS');
  34569. cs = ColorSpace.parse(cs, xref, res);
  34570. this.cs = cs;
  34571. this.background = dict.has('Background') ?
  34572. cs.getRgb(dict.get('Background'), 0) : null;
  34573. var fnObj = dict.get('Function');
  34574. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  34575. this.coords = [];
  34576. this.colors = [];
  34577. this.figures = [];
  34578. var decodeContext = {
  34579. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  34580. bitsPerComponent: dict.get('BitsPerComponent'),
  34581. bitsPerFlag: dict.get('BitsPerFlag'),
  34582. decode: dict.get('Decode'),
  34583. colorFn: fn,
  34584. colorSpace: cs,
  34585. numComps: fn ? 1 : cs.numComps
  34586. };
  34587. var reader = new MeshStreamReader(stream, decodeContext);
  34588. var patchMesh = false;
  34589. switch (this.shadingType) {
  34590. case ShadingType.FREE_FORM_MESH:
  34591. decodeType4Shading(this, reader);
  34592. break;
  34593. case ShadingType.LATTICE_FORM_MESH:
  34594. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  34595. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  34596. decodeType5Shading(this, reader, verticesPerRow);
  34597. break;
  34598. case ShadingType.COONS_PATCH_MESH:
  34599. decodeType6Shading(this, reader);
  34600. patchMesh = true;
  34601. break;
  34602. case ShadingType.TENSOR_PATCH_MESH:
  34603. decodeType7Shading(this, reader);
  34604. patchMesh = true;
  34605. break;
  34606. default:
  34607. error('Unsupported mesh type.');
  34608. break;
  34609. }
  34610. if (patchMesh) {
  34611. // dirty bounds calculation for determining, how dense shall be triangles
  34612. updateBounds(this);
  34613. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  34614. buildFigureFromPatch(this, i);
  34615. }
  34616. }
  34617. // calculate bounds
  34618. updateBounds(this);
  34619. packData(this);
  34620. }
  34621. Mesh.prototype = {
  34622. getIR: function Mesh_getIR() {
  34623. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  34624. this.bounds, this.matrix, this.bbox, this.background];
  34625. }
  34626. };
  34627. return Mesh;
  34628. })();
  34629. Shadings.Dummy = (function DummyClosure() {
  34630. function Dummy() {
  34631. this.type = 'Pattern';
  34632. }
  34633. Dummy.prototype = {
  34634. getIR: function Dummy_getIR() {
  34635. return ['Dummy'];
  34636. }
  34637. };
  34638. return Dummy;
  34639. })();
  34640. function getTilingPatternIR(operatorList, dict, args) {
  34641. var matrix = dict.get('Matrix');
  34642. var bbox = dict.get('BBox');
  34643. var xstep = dict.get('XStep');
  34644. var ystep = dict.get('YStep');
  34645. var paintType = dict.get('PaintType');
  34646. var tilingType = dict.get('TilingType');
  34647. return [
  34648. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  34649. paintType, tilingType
  34650. ];
  34651. }
  34652. exports.Pattern = Pattern;
  34653. exports.getTilingPatternIR = getTilingPatternIR;
  34654. }));
  34655. (function (root, factory) {
  34656. {
  34657. factory((root.pdfjsCoreEvaluator = {}), root.pdfjsSharedUtil,
  34658. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  34659. root.pdfjsCoreImage, root.pdfjsCoreColorSpace, root.pdfjsCoreMurmurHash3,
  34660. root.pdfjsCoreFonts, root.pdfjsCoreFunction, root.pdfjsCorePattern,
  34661. root.pdfjsCoreCMap, root.pdfjsCoreMetrics, root.pdfjsCoreBidi,
  34662. root.pdfjsCoreEncodings, root.pdfjsCoreStandardFonts,
  34663. root.pdfjsCoreUnicode);
  34664. }
  34665. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  34666. coreImage, coreColorSpace, coreMurmurHash3, coreFonts,
  34667. coreFunction, corePattern, coreCMap, coreMetrics, coreBidi,
  34668. coreEncodings, coreStandardFonts, coreUnicode) {
  34669. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  34670. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  34671. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  34672. var ImageKind = sharedUtil.ImageKind;
  34673. var OPS = sharedUtil.OPS;
  34674. var TextRenderingMode = sharedUtil.TextRenderingMode;
  34675. var Util = sharedUtil.Util;
  34676. var assert = sharedUtil.assert;
  34677. var createPromiseCapability = sharedUtil.createPromiseCapability;
  34678. var error = sharedUtil.error;
  34679. var info = sharedUtil.info;
  34680. var isArray = sharedUtil.isArray;
  34681. var isNum = sharedUtil.isNum;
  34682. var isString = sharedUtil.isString;
  34683. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  34684. var warn = sharedUtil.warn;
  34685. var Dict = corePrimitives.Dict;
  34686. var Name = corePrimitives.Name;
  34687. var isCmd = corePrimitives.isCmd;
  34688. var isDict = corePrimitives.isDict;
  34689. var isName = corePrimitives.isName;
  34690. var isRef = corePrimitives.isRef;
  34691. var isStream = corePrimitives.isStream;
  34692. var DecodeStream = coreStream.DecodeStream;
  34693. var JpegStream = coreStream.JpegStream;
  34694. var Lexer = coreParser.Lexer;
  34695. var Parser = coreParser.Parser;
  34696. var isEOF = coreParser.isEOF;
  34697. var PDFImage = coreImage.PDFImage;
  34698. var ColorSpace = coreColorSpace.ColorSpace;
  34699. var MurmurHash3_64 = coreMurmurHash3.MurmurHash3_64;
  34700. var ErrorFont = coreFonts.ErrorFont;
  34701. var FontFlags = coreFonts.FontFlags;
  34702. var Font = coreFonts.Font;
  34703. var IdentityToUnicodeMap = coreFonts.IdentityToUnicodeMap;
  34704. var ToUnicodeMap = coreFonts.ToUnicodeMap;
  34705. var getFontType = coreFonts.getFontType;
  34706. var isPDFFunction = coreFunction.isPDFFunction;
  34707. var PDFFunction = coreFunction.PDFFunction;
  34708. var Pattern = corePattern.Pattern;
  34709. var getTilingPatternIR = corePattern.getTilingPatternIR;
  34710. var CMapFactory = coreCMap.CMapFactory;
  34711. var IdentityCMap = coreCMap.IdentityCMap;
  34712. var getMetrics = coreMetrics.getMetrics;
  34713. var bidi = coreBidi.bidi;
  34714. var WinAnsiEncoding = coreEncodings.WinAnsiEncoding;
  34715. var StandardEncoding = coreEncodings.StandardEncoding;
  34716. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  34717. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  34718. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  34719. var getEncoding = coreEncodings.getEncoding;
  34720. var getStdFontMap = coreStandardFonts.getStdFontMap;
  34721. var getSerifFonts = coreStandardFonts.getSerifFonts;
  34722. var getSymbolsFonts = coreStandardFonts.getSymbolsFonts;
  34723. var getNormalizedUnicodes = coreUnicode.getNormalizedUnicodes;
  34724. var reverseIfRtl = coreUnicode.reverseIfRtl;
  34725. var PartialEvaluator = (function PartialEvaluatorClosure() {
  34726. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  34727. uniquePrefix, idCounters, fontCache) {
  34728. this.pdfManager = pdfManager;
  34729. this.xref = xref;
  34730. this.handler = handler;
  34731. this.pageIndex = pageIndex;
  34732. this.uniquePrefix = uniquePrefix;
  34733. this.idCounters = idCounters;
  34734. this.fontCache = fontCache;
  34735. }
  34736. // Trying to minimize Date.now() usage and check every 100 time
  34737. var TIME_SLOT_DURATION_MS = 20;
  34738. var CHECK_TIME_EVERY = 100;
  34739. function TimeSlotManager() {
  34740. this.reset();
  34741. }
  34742. TimeSlotManager.prototype = {
  34743. check: function TimeSlotManager_check() {
  34744. if (++this.checked < CHECK_TIME_EVERY) {
  34745. return false;
  34746. }
  34747. this.checked = 0;
  34748. return this.endTime <= Date.now();
  34749. },
  34750. reset: function TimeSlotManager_reset() {
  34751. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  34752. this.checked = 0;
  34753. }
  34754. };
  34755. var deferred = Promise.resolve();
  34756. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  34757. PartialEvaluator.prototype = {
  34758. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  34759. if (!isDict(resources)) {
  34760. return false;
  34761. }
  34762. var processed = Object.create(null);
  34763. if (resources.objId) {
  34764. processed[resources.objId] = true;
  34765. }
  34766. var nodes = [resources], xref = this.xref;
  34767. while (nodes.length) {
  34768. var key, i, ii;
  34769. var node = nodes.shift();
  34770. // First check the current resources for blend modes.
  34771. var graphicStates = node.get('ExtGState');
  34772. if (isDict(graphicStates)) {
  34773. var graphicStatesKeys = graphicStates.getKeys();
  34774. for (i = 0, ii = graphicStatesKeys.length; i < ii; i++) {
  34775. key = graphicStatesKeys[i];
  34776. var graphicState = graphicStates.get(key);
  34777. var bm = graphicState.get('BM');
  34778. if (isName(bm) && bm.name !== 'Normal') {
  34779. return true;
  34780. }
  34781. }
  34782. }
  34783. // Descend into the XObjects to look for more resources and blend modes.
  34784. var xObjects = node.get('XObject');
  34785. if (!isDict(xObjects)) {
  34786. continue;
  34787. }
  34788. var xObjectsKeys = xObjects.getKeys();
  34789. for (i = 0, ii = xObjectsKeys.length; i < ii; i++) {
  34790. key = xObjectsKeys[i];
  34791. var xObject = xObjects.getRaw(key);
  34792. if (isRef(xObject)) {
  34793. if (processed[xObject.toString()]) {
  34794. // The XObject has already been processed, and by avoiding a
  34795. // redundant `xref.fetch` we can *significantly* reduce the load
  34796. // time for badly generated PDF files (fixes issue6961.pdf).
  34797. continue;
  34798. }
  34799. xObject = xref.fetch(xObject);
  34800. }
  34801. if (!isStream(xObject)) {
  34802. continue;
  34803. }
  34804. if (xObject.dict.objId) {
  34805. if (processed[xObject.dict.objId]) {
  34806. // stream has objId and is processed already
  34807. continue;
  34808. }
  34809. processed[xObject.dict.objId] = true;
  34810. }
  34811. var xResources = xObject.dict.get('Resources');
  34812. // Checking objId to detect an infinite loop.
  34813. if (isDict(xResources) &&
  34814. (!xResources.objId || !processed[xResources.objId])) {
  34815. nodes.push(xResources);
  34816. if (xResources.objId) {
  34817. processed[xResources.objId] = true;
  34818. }
  34819. }
  34820. }
  34821. }
  34822. return false;
  34823. },
  34824. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  34825. xobj, smask,
  34826. operatorList,
  34827. task,
  34828. initialState) {
  34829. var matrix = xobj.dict.getArray('Matrix');
  34830. var bbox = xobj.dict.getArray('BBox');
  34831. var group = xobj.dict.get('Group');
  34832. if (group) {
  34833. var groupOptions = {
  34834. matrix: matrix,
  34835. bbox: bbox,
  34836. smask: smask,
  34837. isolated: false,
  34838. knockout: false
  34839. };
  34840. var groupSubtype = group.get('S');
  34841. var colorSpace;
  34842. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  34843. groupOptions.isolated = (group.get('I') || false);
  34844. groupOptions.knockout = (group.get('K') || false);
  34845. colorSpace = (group.has('CS') ?
  34846. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  34847. }
  34848. if (smask && smask.backdrop) {
  34849. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  34850. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  34851. }
  34852. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  34853. }
  34854. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  34855. return this.getOperatorList(xobj, task,
  34856. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  34857. then(function () {
  34858. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  34859. if (group) {
  34860. operatorList.addOp(OPS.endGroup, [groupOptions]);
  34861. }
  34862. });
  34863. },
  34864. buildPaintImageXObject:
  34865. function PartialEvaluator_buildPaintImageXObject(resources, image,
  34866. inline, operatorList,
  34867. cacheKey, imageCache) {
  34868. var self = this;
  34869. var dict = image.dict;
  34870. var w = dict.get('Width', 'W');
  34871. var h = dict.get('Height', 'H');
  34872. if (!(w && isNum(w)) || !(h && isNum(h))) {
  34873. warn('Image dimensions are missing, or not numbers.');
  34874. return;
  34875. }
  34876. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  34877. warn('Image exceeded maximum allowed size and was removed.');
  34878. return;
  34879. }
  34880. var imageMask = (dict.get('ImageMask', 'IM') || false);
  34881. var imgData, args;
  34882. if (imageMask) {
  34883. // This depends on a tmpCanvas being filled with the
  34884. // current fillStyle, such that processing the pixel
  34885. // data can't be done here. Instead of creating a
  34886. // complete PDFImage, only read the information needed
  34887. // for later.
  34888. var width = dict.get('Width', 'W');
  34889. var height = dict.get('Height', 'H');
  34890. var bitStrideLength = (width + 7) >> 3;
  34891. var imgArray = image.getBytes(bitStrideLength * height);
  34892. var decode = dict.get('Decode', 'D');
  34893. var inverseDecode = (!!decode && decode[0] > 0);
  34894. imgData = PDFImage.createMask(imgArray, width, height,
  34895. image instanceof DecodeStream,
  34896. inverseDecode);
  34897. imgData.cached = true;
  34898. args = [imgData];
  34899. operatorList.addOp(OPS.paintImageMaskXObject, args);
  34900. if (cacheKey) {
  34901. imageCache[cacheKey] = {
  34902. fn: OPS.paintImageMaskXObject,
  34903. args: args
  34904. };
  34905. }
  34906. return;
  34907. }
  34908. var softMask = (dict.get('SMask', 'SM') || false);
  34909. var mask = (dict.get('Mask') || false);
  34910. var SMALL_IMAGE_DIMENSIONS = 200;
  34911. // Inlining small images into the queue as RGB data
  34912. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  34913. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  34914. var imageObj = new PDFImage(this.xref, resources, image,
  34915. inline, null, null);
  34916. // We force the use of RGBA_32BPP images here, because we can't handle
  34917. // any other kind.
  34918. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  34919. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  34920. return;
  34921. }
  34922. // If there is no imageMask, create the PDFImage and a lot
  34923. // of image processing can be done here.
  34924. var uniquePrefix = (this.uniquePrefix || '');
  34925. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  34926. operatorList.addDependency(objId);
  34927. args = [objId, w, h];
  34928. if (!softMask && !mask && image instanceof JpegStream &&
  34929. image.isNativelySupported(this.xref, resources)) {
  34930. // These JPEGs don't need any more processing so we can just send it.
  34931. operatorList.addOp(OPS.paintJpegXObject, args);
  34932. this.handler.send('obj',
  34933. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  34934. return;
  34935. }
  34936. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  34937. then(function(imageObj) {
  34938. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  34939. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  34940. [imgData.data.buffer]);
  34941. }).then(undefined, function (reason) {
  34942. warn('Unable to decode image: ' + reason);
  34943. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  34944. });
  34945. operatorList.addOp(OPS.paintImageXObject, args);
  34946. if (cacheKey) {
  34947. imageCache[cacheKey] = {
  34948. fn: OPS.paintImageXObject,
  34949. args: args
  34950. };
  34951. }
  34952. },
  34953. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  34954. operatorList, task,
  34955. stateManager) {
  34956. var smaskContent = smask.get('G');
  34957. var smaskOptions = {
  34958. subtype: smask.get('S').name,
  34959. backdrop: smask.get('BC')
  34960. };
  34961. // The SMask might have a alpha/luminosity value transfer function --
  34962. // we will build a map of integer values in range 0..255 to be fast.
  34963. var transferObj = smask.get('TR');
  34964. if (isPDFFunction(transferObj)) {
  34965. var transferFn = PDFFunction.parse(this.xref, transferObj);
  34966. var transferMap = new Uint8Array(256);
  34967. var tmp = new Float32Array(1);
  34968. for (var i = 0; i < 256; i++) {
  34969. tmp[0] = i / 255;
  34970. transferFn(tmp, 0, tmp, 0);
  34971. transferMap[i] = (tmp[0] * 255) | 0;
  34972. }
  34973. smaskOptions.transferMap = transferMap;
  34974. }
  34975. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  34976. operatorList, task, stateManager.state.clone());
  34977. },
  34978. handleTilingType:
  34979. function PartialEvaluator_handleTilingType(fn, args, resources,
  34980. pattern, patternDict,
  34981. operatorList, task) {
  34982. // Create an IR of the pattern code.
  34983. var tilingOpList = new OperatorList();
  34984. // Merge the available resources, to prevent issues when the patternDict
  34985. // is missing some /Resources entries (fixes issue6541.pdf).
  34986. var resourcesArray = [patternDict.get('Resources'), resources];
  34987. var patternResources = Dict.merge(this.xref, resourcesArray);
  34988. return this.getOperatorList(pattern, task, patternResources,
  34989. tilingOpList).then(function () {
  34990. // Add the dependencies to the parent operator list so they are
  34991. // resolved before sub operator list is executed synchronously.
  34992. operatorList.addDependencies(tilingOpList.dependencies);
  34993. operatorList.addOp(fn, getTilingPatternIR({
  34994. fnArray: tilingOpList.fnArray,
  34995. argsArray: tilingOpList.argsArray
  34996. }, patternDict, args));
  34997. });
  34998. },
  34999. handleSetFont:
  35000. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  35001. operatorList, task, state) {
  35002. // TODO(mack): Not needed?
  35003. var fontName;
  35004. if (fontArgs) {
  35005. fontArgs = fontArgs.slice();
  35006. fontName = fontArgs[0].name;
  35007. }
  35008. var self = this;
  35009. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  35010. function (translated) {
  35011. if (!translated.font.isType3Font) {
  35012. return translated;
  35013. }
  35014. return translated.loadType3Data(self, resources, operatorList, task).
  35015. then(function () {
  35016. return translated;
  35017. }, function (reason) {
  35018. // Error in the font data -- sending unsupported feature notification.
  35019. self.handler.send('UnsupportedFeature',
  35020. {featureId: UNSUPPORTED_FEATURES.font});
  35021. return new TranslatedFont('g_font_error',
  35022. new ErrorFont('Type3 font load error: ' + reason), translated.font);
  35023. });
  35024. }).then(function (translated) {
  35025. state.font = translated.font;
  35026. translated.send(self.handler);
  35027. return translated.loadedName;
  35028. });
  35029. },
  35030. handleText: function PartialEvaluator_handleText(chars, state) {
  35031. var font = state.font;
  35032. var glyphs = font.charsToGlyphs(chars);
  35033. var isAddToPathSet = !!(state.textRenderingMode &
  35034. TextRenderingMode.ADD_TO_PATH_FLAG);
  35035. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  35036. var buildPath = function (fontChar) {
  35037. if (!font.renderer.hasBuiltPath(fontChar)) {
  35038. var path = font.renderer.getPathJs(fontChar);
  35039. this.handler.send('commonobj', [
  35040. font.loadedName + '_path_' + fontChar,
  35041. 'FontPath',
  35042. path
  35043. ]);
  35044. }
  35045. }.bind(this);
  35046. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  35047. var glyph = glyphs[i];
  35048. buildPath(glyph.fontChar);
  35049. // If the glyph has an accent we need to build a path for its
  35050. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  35051. var accent = glyph.accent;
  35052. if (accent && accent.fontChar) {
  35053. buildPath(accent.fontChar);
  35054. }
  35055. }
  35056. }
  35057. return glyphs;
  35058. },
  35059. setGState: function PartialEvaluator_setGState(resources, gState,
  35060. operatorList, task,
  35061. xref, stateManager) {
  35062. // This array holds the converted/processed state data.
  35063. var gStateObj = [];
  35064. var gStateKeys = gState.getKeys();
  35065. var self = this;
  35066. var promise = Promise.resolve();
  35067. for (var i = 0, ii = gStateKeys.length; i < ii; i++) {
  35068. var key = gStateKeys[i];
  35069. var value = gState.get(key);
  35070. switch (key) {
  35071. case 'Type':
  35072. break;
  35073. case 'LW':
  35074. case 'LC':
  35075. case 'LJ':
  35076. case 'ML':
  35077. case 'D':
  35078. case 'RI':
  35079. case 'FL':
  35080. case 'CA':
  35081. case 'ca':
  35082. gStateObj.push([key, value]);
  35083. break;
  35084. case 'Font':
  35085. promise = promise.then(function () {
  35086. return self.handleSetFont(resources, null, value[0], operatorList,
  35087. task, stateManager.state).
  35088. then(function (loadedName) {
  35089. operatorList.addDependency(loadedName);
  35090. gStateObj.push([key, [loadedName, value[1]]]);
  35091. });
  35092. });
  35093. break;
  35094. case 'BM':
  35095. gStateObj.push([key, value]);
  35096. break;
  35097. case 'SMask':
  35098. if (isName(value) && value.name === 'None') {
  35099. gStateObj.push([key, false]);
  35100. break;
  35101. }
  35102. if (isDict(value)) {
  35103. promise = promise.then(function (dict) {
  35104. return self.handleSMask(dict, resources, operatorList,
  35105. task, stateManager);
  35106. }.bind(this, value));
  35107. gStateObj.push([key, true]);
  35108. } else {
  35109. warn('Unsupported SMask type');
  35110. }
  35111. break;
  35112. // Only generate info log messages for the following since
  35113. // they are unlikely to have a big impact on the rendering.
  35114. case 'OP':
  35115. case 'op':
  35116. case 'OPM':
  35117. case 'BG':
  35118. case 'BG2':
  35119. case 'UCR':
  35120. case 'UCR2':
  35121. case 'TR':
  35122. case 'TR2':
  35123. case 'HT':
  35124. case 'SM':
  35125. case 'SA':
  35126. case 'AIS':
  35127. case 'TK':
  35128. // TODO implement these operators.
  35129. info('graphic state operator ' + key);
  35130. break;
  35131. default:
  35132. info('Unknown graphic state operator ' + key);
  35133. break;
  35134. }
  35135. }
  35136. return promise.then(function () {
  35137. if (gStateObj.length > 0) {
  35138. operatorList.addOp(OPS.setGState, [gStateObj]);
  35139. }
  35140. });
  35141. },
  35142. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  35143. resources) {
  35144. function errorFont() {
  35145. return Promise.resolve(new TranslatedFont('g_font_error',
  35146. new ErrorFont('Font ' + fontName + ' is not available'), font));
  35147. }
  35148. var fontRef;
  35149. if (font) { // Loading by ref.
  35150. assert(isRef(font));
  35151. fontRef = font;
  35152. } else { // Loading by name.
  35153. var fontRes = resources.get('Font');
  35154. if (fontRes) {
  35155. fontRef = fontRes.getRaw(fontName);
  35156. } else {
  35157. warn('fontRes not available');
  35158. return errorFont();
  35159. }
  35160. }
  35161. if (!fontRef) {
  35162. warn('fontRef not available');
  35163. return errorFont();
  35164. }
  35165. if (this.fontCache.has(fontRef)) {
  35166. return this.fontCache.get(fontRef);
  35167. }
  35168. font = xref.fetchIfRef(fontRef);
  35169. if (!isDict(font)) {
  35170. return errorFont();
  35171. }
  35172. // We are holding font.translated references just for fontRef that are not
  35173. // dictionaries (Dict). See explanation below.
  35174. if (font.translated) {
  35175. return font.translated;
  35176. }
  35177. var fontCapability = createPromiseCapability();
  35178. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  35179. var descriptor = preEvaluatedFont.descriptor;
  35180. var fontID = fontRef.num + '_' + fontRef.gen;
  35181. if (isDict(descriptor)) {
  35182. if (!descriptor.fontAliases) {
  35183. descriptor.fontAliases = Object.create(null);
  35184. }
  35185. var fontAliases = descriptor.fontAliases;
  35186. var hash = preEvaluatedFont.hash;
  35187. if (fontAliases[hash]) {
  35188. var aliasFontRef = fontAliases[hash].aliasRef;
  35189. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  35190. this.fontCache.putAlias(fontRef, aliasFontRef);
  35191. return this.fontCache.get(fontRef);
  35192. }
  35193. }
  35194. if (!fontAliases[hash]) {
  35195. fontAliases[hash] = {
  35196. fontID: Font.getFontID()
  35197. };
  35198. }
  35199. fontAliases[hash].aliasRef = fontRef;
  35200. fontID = fontAliases[hash].fontID;
  35201. }
  35202. // Workaround for bad PDF generators that don't reference fonts
  35203. // properly, i.e. by not using an object identifier.
  35204. // Check if the fontRef is a Dict (as opposed to a standard object),
  35205. // in which case we don't cache the font and instead reference it by
  35206. // fontName in font.loadedName below.
  35207. var fontRefIsDict = isDict(fontRef);
  35208. if (!fontRefIsDict) {
  35209. this.fontCache.put(fontRef, fontCapability.promise);
  35210. }
  35211. // Keep track of each font we translated so the caller can
  35212. // load them asynchronously before calling display on a page.
  35213. font.loadedName = 'g_' + this.pdfManager.docId + '_f' + (fontRefIsDict ?
  35214. fontName.replace(/\W/g, '') : fontID);
  35215. font.translated = fontCapability.promise;
  35216. // TODO move promises into translate font
  35217. var translatedPromise;
  35218. try {
  35219. translatedPromise = Promise.resolve(
  35220. this.translateFont(preEvaluatedFont, xref));
  35221. } catch (e) {
  35222. translatedPromise = Promise.reject(e);
  35223. }
  35224. var self = this;
  35225. translatedPromise.then(function (translatedFont) {
  35226. if (translatedFont.fontType !== undefined) {
  35227. var xrefFontStats = xref.stats.fontTypes;
  35228. xrefFontStats[translatedFont.fontType] = true;
  35229. }
  35230. fontCapability.resolve(new TranslatedFont(font.loadedName,
  35231. translatedFont, font));
  35232. }, function (reason) {
  35233. // TODO fontCapability.reject?
  35234. // Error in the font data -- sending unsupported feature notification.
  35235. self.handler.send('UnsupportedFeature',
  35236. {featureId: UNSUPPORTED_FEATURES.font});
  35237. try {
  35238. // error, but it's still nice to have font type reported
  35239. var descriptor = preEvaluatedFont.descriptor;
  35240. var fontFile3 = descriptor && descriptor.get('FontFile3');
  35241. var subtype = fontFile3 && fontFile3.get('Subtype');
  35242. var fontType = getFontType(preEvaluatedFont.type,
  35243. subtype && subtype.name);
  35244. var xrefFontStats = xref.stats.fontTypes;
  35245. xrefFontStats[fontType] = true;
  35246. } catch (ex) { }
  35247. fontCapability.resolve(new TranslatedFont(font.loadedName,
  35248. new ErrorFont(reason instanceof Error ? reason.message : reason),
  35249. font));
  35250. });
  35251. return fontCapability.promise;
  35252. },
  35253. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  35254. var lastIndex = operatorList.length - 1;
  35255. if (!args) {
  35256. args = [];
  35257. }
  35258. if (lastIndex < 0 ||
  35259. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  35260. operatorList.addOp(OPS.constructPath, [[fn], args]);
  35261. } else {
  35262. var opArgs = operatorList.argsArray[lastIndex];
  35263. opArgs[0].push(fn);
  35264. Array.prototype.push.apply(opArgs[1], args);
  35265. }
  35266. },
  35267. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  35268. cs, patterns, resources, task, xref) {
  35269. // compile tiling patterns
  35270. var patternName = args[args.length - 1];
  35271. // SCN/scn applies patterns along with normal colors
  35272. var pattern;
  35273. if (isName(patternName) &&
  35274. (pattern = patterns.get(patternName.name))) {
  35275. var dict = (isStream(pattern) ? pattern.dict : pattern);
  35276. var typeNum = dict.get('PatternType');
  35277. if (typeNum === TILING_PATTERN) {
  35278. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  35279. return this.handleTilingType(fn, color, resources, pattern,
  35280. dict, operatorList, task);
  35281. } else if (typeNum === SHADING_PATTERN) {
  35282. var shading = dict.get('Shading');
  35283. var matrix = dict.get('Matrix');
  35284. pattern = Pattern.parseShading(shading, matrix, xref, resources,
  35285. this.handler);
  35286. operatorList.addOp(fn, pattern.getIR());
  35287. return Promise.resolve();
  35288. } else {
  35289. return Promise.reject('Unknown PatternType: ' + typeNum);
  35290. }
  35291. }
  35292. // TODO shall we fail here?
  35293. operatorList.addOp(fn, args);
  35294. return Promise.resolve();
  35295. },
  35296. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  35297. task,
  35298. resources,
  35299. operatorList,
  35300. initialState) {
  35301. var self = this;
  35302. var xref = this.xref;
  35303. var imageCache = Object.create(null);
  35304. assert(operatorList);
  35305. resources = (resources || Dict.empty);
  35306. var xobjs = (resources.get('XObject') || Dict.empty);
  35307. var patterns = (resources.get('Pattern') || Dict.empty);
  35308. var stateManager = new StateManager(initialState || new EvalState());
  35309. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  35310. var timeSlotManager = new TimeSlotManager();
  35311. return new Promise(function next(resolve, reject) {
  35312. task.ensureNotTerminated();
  35313. timeSlotManager.reset();
  35314. var stop, operation = {}, i, ii, cs;
  35315. while (!(stop = timeSlotManager.check())) {
  35316. // The arguments parsed by read() are used beyond this loop, so we
  35317. // cannot reuse the same array on each iteration. Therefore we pass
  35318. // in |null| as the initial value (see the comment on
  35319. // EvaluatorPreprocessor_read() for why).
  35320. operation.args = null;
  35321. if (!(preprocessor.read(operation))) {
  35322. break;
  35323. }
  35324. var args = operation.args;
  35325. var fn = operation.fn;
  35326. switch (fn | 0) {
  35327. case OPS.paintXObject:
  35328. if (args[0].code) {
  35329. break;
  35330. }
  35331. // eagerly compile XForm objects
  35332. var name = args[0].name;
  35333. if (!name) {
  35334. warn('XObject must be referred to by name.');
  35335. continue;
  35336. }
  35337. if (imageCache[name] !== undefined) {
  35338. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  35339. args = null;
  35340. continue;
  35341. }
  35342. var xobj = xobjs.get(name);
  35343. if (xobj) {
  35344. assert(isStream(xobj), 'XObject should be a stream');
  35345. var type = xobj.dict.get('Subtype');
  35346. assert(isName(type),
  35347. 'XObject should have a Name subtype');
  35348. if (type.name === 'Form') {
  35349. stateManager.save();
  35350. return self.buildFormXObject(resources, xobj, null,
  35351. operatorList, task,
  35352. stateManager.state.clone()).
  35353. then(function () {
  35354. stateManager.restore();
  35355. next(resolve, reject);
  35356. }, reject);
  35357. } else if (type.name === 'Image') {
  35358. self.buildPaintImageXObject(resources, xobj, false,
  35359. operatorList, name, imageCache);
  35360. args = null;
  35361. continue;
  35362. } else if (type.name === 'PS') {
  35363. // PostScript XObjects are unused when viewing documents.
  35364. // See section 4.7.1 of Adobe's PDF reference.
  35365. info('Ignored XObject subtype PS');
  35366. continue;
  35367. } else {
  35368. error('Unhandled XObject subtype ' + type.name);
  35369. }
  35370. }
  35371. break;
  35372. case OPS.setFont:
  35373. var fontSize = args[1];
  35374. // eagerly collect all fonts
  35375. return self.handleSetFont(resources, args, null, operatorList,
  35376. task, stateManager.state).
  35377. then(function (loadedName) {
  35378. operatorList.addDependency(loadedName);
  35379. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  35380. next(resolve, reject);
  35381. }, reject);
  35382. case OPS.endInlineImage:
  35383. var cacheKey = args[0].cacheKey;
  35384. if (cacheKey) {
  35385. var cacheEntry = imageCache[cacheKey];
  35386. if (cacheEntry !== undefined) {
  35387. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  35388. args = null;
  35389. continue;
  35390. }
  35391. }
  35392. self.buildPaintImageXObject(resources, args[0], true,
  35393. operatorList, cacheKey, imageCache);
  35394. args = null;
  35395. continue;
  35396. case OPS.showText:
  35397. args[0] = self.handleText(args[0], stateManager.state);
  35398. break;
  35399. case OPS.showSpacedText:
  35400. var arr = args[0];
  35401. var combinedGlyphs = [];
  35402. var arrLength = arr.length;
  35403. var state = stateManager.state;
  35404. for (i = 0; i < arrLength; ++i) {
  35405. var arrItem = arr[i];
  35406. if (isString(arrItem)) {
  35407. Array.prototype.push.apply(combinedGlyphs,
  35408. self.handleText(arrItem, state));
  35409. } else if (isNum(arrItem)) {
  35410. combinedGlyphs.push(arrItem);
  35411. }
  35412. }
  35413. args[0] = combinedGlyphs;
  35414. fn = OPS.showText;
  35415. break;
  35416. case OPS.nextLineShowText:
  35417. operatorList.addOp(OPS.nextLine);
  35418. args[0] = self.handleText(args[0], stateManager.state);
  35419. fn = OPS.showText;
  35420. break;
  35421. case OPS.nextLineSetSpacingShowText:
  35422. operatorList.addOp(OPS.nextLine);
  35423. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  35424. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  35425. args[0] = self.handleText(args[0], stateManager.state);
  35426. fn = OPS.showText;
  35427. break;
  35428. case OPS.setTextRenderingMode:
  35429. stateManager.state.textRenderingMode = args[0];
  35430. break;
  35431. case OPS.setFillColorSpace:
  35432. stateManager.state.fillColorSpace =
  35433. ColorSpace.parse(args[0], xref, resources);
  35434. continue;
  35435. case OPS.setStrokeColorSpace:
  35436. stateManager.state.strokeColorSpace =
  35437. ColorSpace.parse(args[0], xref, resources);
  35438. continue;
  35439. case OPS.setFillColor:
  35440. cs = stateManager.state.fillColorSpace;
  35441. args = cs.getRgb(args, 0);
  35442. fn = OPS.setFillRGBColor;
  35443. break;
  35444. case OPS.setStrokeColor:
  35445. cs = stateManager.state.strokeColorSpace;
  35446. args = cs.getRgb(args, 0);
  35447. fn = OPS.setStrokeRGBColor;
  35448. break;
  35449. case OPS.setFillGray:
  35450. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  35451. args = ColorSpace.singletons.gray.getRgb(args, 0);
  35452. fn = OPS.setFillRGBColor;
  35453. break;
  35454. case OPS.setStrokeGray:
  35455. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  35456. args = ColorSpace.singletons.gray.getRgb(args, 0);
  35457. fn = OPS.setStrokeRGBColor;
  35458. break;
  35459. case OPS.setFillCMYKColor:
  35460. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  35461. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  35462. fn = OPS.setFillRGBColor;
  35463. break;
  35464. case OPS.setStrokeCMYKColor:
  35465. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  35466. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  35467. fn = OPS.setStrokeRGBColor;
  35468. break;
  35469. case OPS.setFillRGBColor:
  35470. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  35471. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  35472. break;
  35473. case OPS.setStrokeRGBColor:
  35474. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  35475. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  35476. break;
  35477. case OPS.setFillColorN:
  35478. cs = stateManager.state.fillColorSpace;
  35479. if (cs.name === 'Pattern') {
  35480. return self.handleColorN(operatorList, OPS.setFillColorN,
  35481. args, cs, patterns, resources, task, xref).then(function() {
  35482. next(resolve, reject);
  35483. }, reject);
  35484. }
  35485. args = cs.getRgb(args, 0);
  35486. fn = OPS.setFillRGBColor;
  35487. break;
  35488. case OPS.setStrokeColorN:
  35489. cs = stateManager.state.strokeColorSpace;
  35490. if (cs.name === 'Pattern') {
  35491. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  35492. args, cs, patterns, resources, task, xref).then(function() {
  35493. next(resolve, reject);
  35494. }, reject);
  35495. }
  35496. args = cs.getRgb(args, 0);
  35497. fn = OPS.setStrokeRGBColor;
  35498. break;
  35499. case OPS.shadingFill:
  35500. var shadingRes = resources.get('Shading');
  35501. if (!shadingRes) {
  35502. error('No shading resource found');
  35503. }
  35504. var shading = shadingRes.get(args[0].name);
  35505. if (!shading) {
  35506. error('No shading object found');
  35507. }
  35508. var shadingFill = Pattern.parseShading(shading, null, xref,
  35509. resources, self.handler);
  35510. var patternIR = shadingFill.getIR();
  35511. args = [patternIR];
  35512. fn = OPS.shadingFill;
  35513. break;
  35514. case OPS.setGState:
  35515. var dictName = args[0];
  35516. var extGState = resources.get('ExtGState');
  35517. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  35518. break;
  35519. }
  35520. var gState = extGState.get(dictName.name);
  35521. return self.setGState(resources, gState, operatorList, task,
  35522. xref, stateManager).then(function() {
  35523. next(resolve, reject);
  35524. }, reject);
  35525. case OPS.moveTo:
  35526. case OPS.lineTo:
  35527. case OPS.curveTo:
  35528. case OPS.curveTo2:
  35529. case OPS.curveTo3:
  35530. case OPS.closePath:
  35531. self.buildPath(operatorList, fn, args);
  35532. continue;
  35533. case OPS.rectangle:
  35534. self.buildPath(operatorList, fn, args);
  35535. continue;
  35536. case OPS.markPoint:
  35537. case OPS.markPointProps:
  35538. case OPS.beginMarkedContent:
  35539. case OPS.beginMarkedContentProps:
  35540. case OPS.endMarkedContent:
  35541. case OPS.beginCompat:
  35542. case OPS.endCompat:
  35543. // Ignore operators where the corresponding handlers are known to
  35544. // be no-op in CanvasGraphics (display/canvas.js). This prevents
  35545. // serialization errors and is also a bit more efficient.
  35546. // We could also try to serialize all objects in a general way,
  35547. // e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
  35548. // but doing so is meaningless without knowing the semantics.
  35549. continue;
  35550. default:
  35551. // Note: Ignore the operator if it has `Dict` arguments, since
  35552. // those are non-serializable, otherwise postMessage will throw
  35553. // "An object could not be cloned.".
  35554. if (args !== null) {
  35555. for (i = 0, ii = args.length; i < ii; i++) {
  35556. if (args[i] instanceof Dict) {
  35557. break;
  35558. }
  35559. }
  35560. if (i < ii) {
  35561. warn('getOperatorList - ignoring operator: ' + fn);
  35562. continue;
  35563. }
  35564. }
  35565. }
  35566. operatorList.addOp(fn, args);
  35567. }
  35568. if (stop) {
  35569. deferred.then(function () {
  35570. next(resolve, reject);
  35571. }, reject);
  35572. return;
  35573. }
  35574. // Some PDFs don't close all restores inside object/form.
  35575. // Closing those for them.
  35576. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  35577. operatorList.addOp(OPS.restore, []);
  35578. }
  35579. resolve();
  35580. });
  35581. },
  35582. getTextContent:
  35583. function PartialEvaluator_getTextContent(stream, task, resources,
  35584. stateManager,
  35585. normalizeWhitespace) {
  35586. stateManager = (stateManager || new StateManager(new TextState()));
  35587. var WhitespaceRegexp = /\s/g;
  35588. var textContent = {
  35589. items: [],
  35590. styles: Object.create(null)
  35591. };
  35592. var textContentItem = {
  35593. initialized: false,
  35594. str: [],
  35595. width: 0,
  35596. height: 0,
  35597. vertical: false,
  35598. lastAdvanceWidth: 0,
  35599. lastAdvanceHeight: 0,
  35600. textAdvanceScale: 0,
  35601. spaceWidth: 0,
  35602. fakeSpaceMin: Infinity,
  35603. fakeMultiSpaceMin: Infinity,
  35604. fakeMultiSpaceMax: -0,
  35605. textRunBreakAllowed: false,
  35606. transform: null,
  35607. fontName: null
  35608. };
  35609. var SPACE_FACTOR = 0.3;
  35610. var MULTI_SPACE_FACTOR = 1.5;
  35611. var MULTI_SPACE_FACTOR_MAX = 4;
  35612. var self = this;
  35613. var xref = this.xref;
  35614. resources = (xref.fetchIfRef(resources) || Dict.empty);
  35615. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  35616. var xobjs = null;
  35617. var xobjsCache = Object.create(null);
  35618. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  35619. var textState;
  35620. function ensureTextContentItem() {
  35621. if (textContentItem.initialized) {
  35622. return textContentItem;
  35623. }
  35624. var font = textState.font;
  35625. if (!(font.loadedName in textContent.styles)) {
  35626. textContent.styles[font.loadedName] = {
  35627. fontFamily: font.fallbackName,
  35628. ascent: font.ascent,
  35629. descent: font.descent,
  35630. vertical: font.vertical
  35631. };
  35632. }
  35633. textContentItem.fontName = font.loadedName;
  35634. // 9.4.4 Text Space Details
  35635. var tsm = [textState.fontSize * textState.textHScale, 0,
  35636. 0, textState.fontSize,
  35637. 0, textState.textRise];
  35638. if (font.isType3Font &&
  35639. textState.fontMatrix !== FONT_IDENTITY_MATRIX &&
  35640. textState.fontSize === 1) {
  35641. var glyphHeight = font.bbox[3] - font.bbox[1];
  35642. if (glyphHeight > 0) {
  35643. glyphHeight = glyphHeight * textState.fontMatrix[3];
  35644. tsm[3] *= glyphHeight;
  35645. }
  35646. }
  35647. var trm = Util.transform(textState.ctm,
  35648. Util.transform(textState.textMatrix, tsm));
  35649. textContentItem.transform = trm;
  35650. if (!font.vertical) {
  35651. textContentItem.width = 0;
  35652. textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  35653. textContentItem.vertical = false;
  35654. } else {
  35655. textContentItem.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  35656. textContentItem.height = 0;
  35657. textContentItem.vertical = true;
  35658. }
  35659. var a = textState.textLineMatrix[0];
  35660. var b = textState.textLineMatrix[1];
  35661. var scaleLineX = Math.sqrt(a * a + b * b);
  35662. a = textState.ctm[0];
  35663. b = textState.ctm[1];
  35664. var scaleCtmX = Math.sqrt(a * a + b * b);
  35665. textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
  35666. textContentItem.lastAdvanceWidth = 0;
  35667. textContentItem.lastAdvanceHeight = 0;
  35668. var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
  35669. if (spaceWidth) {
  35670. textContentItem.spaceWidth = spaceWidth;
  35671. textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
  35672. textContentItem.fakeMultiSpaceMin = spaceWidth * MULTI_SPACE_FACTOR;
  35673. textContentItem.fakeMultiSpaceMax =
  35674. spaceWidth * MULTI_SPACE_FACTOR_MAX;
  35675. // It's okay for monospace fonts to fake as much space as needed.
  35676. textContentItem.textRunBreakAllowed = !font.isMonospace;
  35677. } else {
  35678. textContentItem.spaceWidth = 0;
  35679. textContentItem.fakeSpaceMin = Infinity;
  35680. textContentItem.fakeMultiSpaceMin = Infinity;
  35681. textContentItem.fakeMultiSpaceMax = 0;
  35682. textContentItem.textRunBreakAllowed = false;
  35683. }
  35684. textContentItem.initialized = true;
  35685. return textContentItem;
  35686. }
  35687. function replaceWhitespace(str) {
  35688. // Replaces all whitespaces with standard spaces (0x20), to avoid
  35689. // alignment issues between the textLayer and the canvas if the text
  35690. // contains e.g. tabs (fixes issue6612.pdf).
  35691. var i = 0, ii = str.length, code;
  35692. while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7F) {
  35693. i++;
  35694. }
  35695. return (i < ii ? str.replace(WhitespaceRegexp, ' ') : str);
  35696. }
  35697. function runBidiTransform(textChunk) {
  35698. var str = textChunk.str.join('');
  35699. var bidiResult = PDFJS.bidi(str, -1, textChunk.vertical);
  35700. return {
  35701. str: (normalizeWhitespace ? replaceWhitespace(bidiResult.str) :
  35702. bidiResult.str),
  35703. dir: bidiResult.dir,
  35704. width: textChunk.width,
  35705. height: textChunk.height,
  35706. transform: textChunk.transform,
  35707. fontName: textChunk.fontName
  35708. };
  35709. }
  35710. function handleSetFont(fontName, fontRef) {
  35711. return self.loadFont(fontName, fontRef, xref, resources).
  35712. then(function (translated) {
  35713. textState.font = translated.font;
  35714. textState.fontMatrix = translated.font.fontMatrix ||
  35715. FONT_IDENTITY_MATRIX;
  35716. });
  35717. }
  35718. function buildTextContentItem(chars) {
  35719. var font = textState.font;
  35720. var textChunk = ensureTextContentItem();
  35721. var width = 0;
  35722. var height = 0;
  35723. var glyphs = font.charsToGlyphs(chars);
  35724. var defaultVMetrics = font.defaultVMetrics;
  35725. for (var i = 0; i < glyphs.length; i++) {
  35726. var glyph = glyphs[i];
  35727. var vMetricX = null;
  35728. var vMetricY = null;
  35729. var glyphWidth = null;
  35730. if (font.vertical) {
  35731. if (glyph.vmetric) {
  35732. glyphWidth = glyph.vmetric[0];
  35733. vMetricX = glyph.vmetric[1];
  35734. vMetricY = glyph.vmetric[2];
  35735. } else {
  35736. glyphWidth = glyph.width;
  35737. vMetricX = glyph.width * 0.5;
  35738. vMetricY = defaultVMetrics[2];
  35739. }
  35740. } else {
  35741. glyphWidth = glyph.width;
  35742. }
  35743. var glyphUnicode = glyph.unicode;
  35744. var NormalizedUnicodes = getNormalizedUnicodes();
  35745. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  35746. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  35747. }
  35748. glyphUnicode = reverseIfRtl(glyphUnicode);
  35749. // The following will calculate the x and y of the individual glyphs.
  35750. // if (font.vertical) {
  35751. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  35752. // textState.fontMatrix[0];
  35753. // tsm[5] -= vMetricY * textState.fontSize *
  35754. // textState.fontMatrix[0];
  35755. // }
  35756. // var trm = Util.transform(textState.textMatrix, tsm);
  35757. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  35758. // var x = pt[0];
  35759. // var y = pt[1];
  35760. var charSpacing = textState.charSpacing;
  35761. if (glyph.isSpace) {
  35762. var wordSpacing = textState.wordSpacing;
  35763. charSpacing += wordSpacing;
  35764. if (wordSpacing > 0) {
  35765. addFakeSpaces(wordSpacing, textChunk.str);
  35766. }
  35767. }
  35768. var tx = 0;
  35769. var ty = 0;
  35770. if (!font.vertical) {
  35771. var w0 = glyphWidth * textState.fontMatrix[0];
  35772. tx = (w0 * textState.fontSize + charSpacing) *
  35773. textState.textHScale;
  35774. width += tx;
  35775. } else {
  35776. var w1 = glyphWidth * textState.fontMatrix[0];
  35777. ty = w1 * textState.fontSize + charSpacing;
  35778. height += ty;
  35779. }
  35780. textState.translateTextMatrix(tx, ty);
  35781. textChunk.str.push(glyphUnicode);
  35782. }
  35783. if (!font.vertical) {
  35784. textChunk.lastAdvanceWidth = width;
  35785. textChunk.width += width * textChunk.textAdvanceScale;
  35786. } else {
  35787. textChunk.lastAdvanceHeight = height;
  35788. textChunk.height += Math.abs(height * textChunk.textAdvanceScale);
  35789. }
  35790. return textChunk;
  35791. }
  35792. function addFakeSpaces(width, strBuf) {
  35793. if (width < textContentItem.fakeSpaceMin) {
  35794. return;
  35795. }
  35796. if (width < textContentItem.fakeMultiSpaceMin) {
  35797. strBuf.push(' ');
  35798. return;
  35799. }
  35800. var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
  35801. while (fakeSpaces-- > 0) {
  35802. strBuf.push(' ');
  35803. }
  35804. }
  35805. function flushTextContentItem() {
  35806. if (!textContentItem.initialized) {
  35807. return;
  35808. }
  35809. textContent.items.push(runBidiTransform(textContentItem));
  35810. textContentItem.initialized = false;
  35811. textContentItem.str.length = 0;
  35812. }
  35813. var timeSlotManager = new TimeSlotManager();
  35814. return new Promise(function next(resolve, reject) {
  35815. task.ensureNotTerminated();
  35816. timeSlotManager.reset();
  35817. var stop, operation = {}, args = [];
  35818. while (!(stop = timeSlotManager.check())) {
  35819. // The arguments parsed by read() are not used beyond this loop, so
  35820. // we can reuse the same array on every iteration, thus avoiding
  35821. // unnecessary allocations.
  35822. args.length = 0;
  35823. operation.args = args;
  35824. if (!(preprocessor.read(operation))) {
  35825. break;
  35826. }
  35827. textState = stateManager.state;
  35828. var fn = operation.fn;
  35829. args = operation.args;
  35830. var advance;
  35831. switch (fn | 0) {
  35832. case OPS.setFont:
  35833. flushTextContentItem();
  35834. textState.fontSize = args[1];
  35835. return handleSetFont(args[0].name).then(function() {
  35836. next(resolve, reject);
  35837. }, reject);
  35838. case OPS.setTextRise:
  35839. flushTextContentItem();
  35840. textState.textRise = args[0];
  35841. break;
  35842. case OPS.setHScale:
  35843. flushTextContentItem();
  35844. textState.textHScale = args[0] / 100;
  35845. break;
  35846. case OPS.setLeading:
  35847. flushTextContentItem();
  35848. textState.leading = args[0];
  35849. break;
  35850. case OPS.moveText:
  35851. // Optimization to treat same line movement as advance
  35852. var isSameTextLine = !textState.font ? false :
  35853. ((textState.font.vertical ? args[0] : args[1]) === 0);
  35854. advance = args[0] - args[1];
  35855. if (isSameTextLine && textContentItem.initialized &&
  35856. advance > 0 &&
  35857. advance <= textContentItem.fakeMultiSpaceMax) {
  35858. textState.translateTextLineMatrix(args[0], args[1]);
  35859. textContentItem.width +=
  35860. (args[0] - textContentItem.lastAdvanceWidth);
  35861. textContentItem.height +=
  35862. (args[1] - textContentItem.lastAdvanceHeight);
  35863. var diff = (args[0] - textContentItem.lastAdvanceWidth) -
  35864. (args[1] - textContentItem.lastAdvanceHeight);
  35865. addFakeSpaces(diff, textContentItem.str);
  35866. break;
  35867. }
  35868. flushTextContentItem();
  35869. textState.translateTextLineMatrix(args[0], args[1]);
  35870. textState.textMatrix = textState.textLineMatrix.slice();
  35871. break;
  35872. case OPS.setLeadingMoveText:
  35873. flushTextContentItem();
  35874. textState.leading = -args[1];
  35875. textState.translateTextLineMatrix(args[0], args[1]);
  35876. textState.textMatrix = textState.textLineMatrix.slice();
  35877. break;
  35878. case OPS.nextLine:
  35879. flushTextContentItem();
  35880. textState.carriageReturn();
  35881. break;
  35882. case OPS.setTextMatrix:
  35883. flushTextContentItem();
  35884. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  35885. args[4], args[5]);
  35886. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  35887. args[4], args[5]);
  35888. break;
  35889. case OPS.setCharSpacing:
  35890. textState.charSpacing = args[0];
  35891. break;
  35892. case OPS.setWordSpacing:
  35893. textState.wordSpacing = args[0];
  35894. break;
  35895. case OPS.beginText:
  35896. flushTextContentItem();
  35897. textState.textMatrix = IDENTITY_MATRIX.slice();
  35898. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  35899. break;
  35900. case OPS.showSpacedText:
  35901. var items = args[0];
  35902. var offset;
  35903. for (var j = 0, jj = items.length; j < jj; j++) {
  35904. if (typeof items[j] === 'string') {
  35905. buildTextContentItem(items[j]);
  35906. } else {
  35907. ensureTextContentItem();
  35908. // PDF Specification 5.3.2 states:
  35909. // The number is expressed in thousandths of a unit of text
  35910. // space.
  35911. // This amount is subtracted from the current horizontal or
  35912. // vertical coordinate, depending on the writing mode.
  35913. // In the default coordinate system, a positive adjustment
  35914. // has the effect of moving the next glyph painted either to
  35915. // the left or down by the given amount.
  35916. advance = items[j] * textState.fontSize / 1000;
  35917. var breakTextRun = false;
  35918. if (textState.font.vertical) {
  35919. offset = advance *
  35920. (textState.textHScale * textState.textMatrix[2] +
  35921. textState.textMatrix[3]);
  35922. textState.translateTextMatrix(0, advance);
  35923. breakTextRun = textContentItem.textRunBreakAllowed &&
  35924. advance > textContentItem.fakeMultiSpaceMax;
  35925. if (!breakTextRun) {
  35926. // Value needs to be added to height to paint down.
  35927. textContentItem.height += offset;
  35928. }
  35929. } else {
  35930. advance = -advance;
  35931. offset = advance * (
  35932. textState.textHScale * textState.textMatrix[0] +
  35933. textState.textMatrix[1]);
  35934. textState.translateTextMatrix(advance, 0);
  35935. breakTextRun = textContentItem.textRunBreakAllowed &&
  35936. advance > textContentItem.fakeMultiSpaceMax;
  35937. if (!breakTextRun) {
  35938. // Value needs to be subtracted from width to paint left.
  35939. textContentItem.width += offset;
  35940. }
  35941. }
  35942. if (breakTextRun) {
  35943. flushTextContentItem();
  35944. } else if (advance > 0) {
  35945. addFakeSpaces(advance, textContentItem.str);
  35946. }
  35947. }
  35948. }
  35949. break;
  35950. case OPS.showText:
  35951. buildTextContentItem(args[0]);
  35952. break;
  35953. case OPS.nextLineShowText:
  35954. flushTextContentItem();
  35955. textState.carriageReturn();
  35956. buildTextContentItem(args[0]);
  35957. break;
  35958. case OPS.nextLineSetSpacingShowText:
  35959. flushTextContentItem();
  35960. textState.wordSpacing = args[0];
  35961. textState.charSpacing = args[1];
  35962. textState.carriageReturn();
  35963. buildTextContentItem(args[2]);
  35964. break;
  35965. case OPS.paintXObject:
  35966. flushTextContentItem();
  35967. if (args[0].code) {
  35968. break;
  35969. }
  35970. if (!xobjs) {
  35971. xobjs = (resources.get('XObject') || Dict.empty);
  35972. }
  35973. var name = args[0].name;
  35974. if (xobjsCache.key === name) {
  35975. if (xobjsCache.texts) {
  35976. Util.appendToArray(textContent.items, xobjsCache.texts.items);
  35977. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  35978. }
  35979. break;
  35980. }
  35981. var xobj = xobjs.get(name);
  35982. if (!xobj) {
  35983. break;
  35984. }
  35985. assert(isStream(xobj), 'XObject should be a stream');
  35986. var type = xobj.dict.get('Subtype');
  35987. assert(isName(type),
  35988. 'XObject should have a Name subtype');
  35989. if ('Form' !== type.name) {
  35990. xobjsCache.key = name;
  35991. xobjsCache.texts = null;
  35992. break;
  35993. }
  35994. stateManager.save();
  35995. var matrix = xobj.dict.get('Matrix');
  35996. if (isArray(matrix) && matrix.length === 6) {
  35997. stateManager.transform(matrix);
  35998. }
  35999. return self.getTextContent(xobj, task,
  36000. xobj.dict.get('Resources') || resources, stateManager,
  36001. normalizeWhitespace).then(function (formTextContent) {
  36002. Util.appendToArray(textContent.items, formTextContent.items);
  36003. Util.extendObj(textContent.styles, formTextContent.styles);
  36004. stateManager.restore();
  36005. xobjsCache.key = name;
  36006. xobjsCache.texts = formTextContent;
  36007. next(resolve, reject);
  36008. }, reject);
  36009. case OPS.setGState:
  36010. flushTextContentItem();
  36011. var dictName = args[0];
  36012. var extGState = resources.get('ExtGState');
  36013. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  36014. break;
  36015. }
  36016. var gsStateMap = extGState.get(dictName.name);
  36017. var gsStateFont = null;
  36018. for (var key in gsStateMap) {
  36019. if (key === 'Font') {
  36020. assert(!gsStateFont);
  36021. gsStateFont = gsStateMap[key];
  36022. }
  36023. }
  36024. if (gsStateFont) {
  36025. textState.fontSize = gsStateFont[1];
  36026. return handleSetFont(gsStateFont[0]).then(function() {
  36027. next(resolve, reject);
  36028. }, reject);
  36029. }
  36030. break;
  36031. } // switch
  36032. } // while
  36033. if (stop) {
  36034. deferred.then(function () {
  36035. next(resolve, reject);
  36036. }, reject);
  36037. return;
  36038. }
  36039. flushTextContentItem();
  36040. resolve(textContent);
  36041. });
  36042. },
  36043. extractDataStructures: function
  36044. partialEvaluatorExtractDataStructures(dict, baseDict,
  36045. xref, properties) {
  36046. // 9.10.2
  36047. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  36048. if (toUnicode) {
  36049. properties.toUnicode = this.readToUnicode(toUnicode);
  36050. }
  36051. if (properties.composite) {
  36052. // CIDSystemInfo helps to match CID to glyphs
  36053. var cidSystemInfo = dict.get('CIDSystemInfo');
  36054. if (isDict(cidSystemInfo)) {
  36055. properties.cidSystemInfo = {
  36056. registry: cidSystemInfo.get('Registry'),
  36057. ordering: cidSystemInfo.get('Ordering'),
  36058. supplement: cidSystemInfo.get('Supplement')
  36059. };
  36060. }
  36061. var cidToGidMap = dict.get('CIDToGIDMap');
  36062. if (isStream(cidToGidMap)) {
  36063. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  36064. }
  36065. }
  36066. // Based on 9.6.6 of the spec the encoding can come from multiple places
  36067. // and depends on the font type. The base encoding and differences are
  36068. // read here, but the encoding that is actually used is chosen during
  36069. // glyph mapping in the font.
  36070. // TODO: Loading the built in encoding in the font would allow the
  36071. // differences to be merged in here not require us to hold on to it.
  36072. var differences = [];
  36073. var baseEncodingName = null;
  36074. var encoding;
  36075. if (dict.has('Encoding')) {
  36076. encoding = dict.get('Encoding');
  36077. if (isDict(encoding)) {
  36078. baseEncodingName = encoding.get('BaseEncoding');
  36079. baseEncodingName = (isName(baseEncodingName) ?
  36080. baseEncodingName.name : null);
  36081. // Load the differences between the base and original
  36082. if (encoding.has('Differences')) {
  36083. var diffEncoding = encoding.get('Differences');
  36084. var index = 0;
  36085. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  36086. var data = xref.fetchIfRef(diffEncoding[j]);
  36087. if (isNum(data)) {
  36088. index = data;
  36089. } else if (isName(data)) {
  36090. differences[index++] = data.name;
  36091. } else {
  36092. error('Invalid entry in \'Differences\' array: ' + data);
  36093. }
  36094. }
  36095. }
  36096. } else if (isName(encoding)) {
  36097. baseEncodingName = encoding.name;
  36098. } else {
  36099. error('Encoding is not a Name nor a Dict');
  36100. }
  36101. // According to table 114 if the encoding is a named encoding it must be
  36102. // one of these predefined encodings.
  36103. if ((baseEncodingName !== 'MacRomanEncoding' &&
  36104. baseEncodingName !== 'MacExpertEncoding' &&
  36105. baseEncodingName !== 'WinAnsiEncoding')) {
  36106. baseEncodingName = null;
  36107. }
  36108. }
  36109. if (baseEncodingName) {
  36110. properties.defaultEncoding = getEncoding(baseEncodingName).slice();
  36111. } else {
  36112. encoding = (properties.type === 'TrueType' ?
  36113. WinAnsiEncoding : StandardEncoding);
  36114. // The Symbolic attribute can be misused for regular fonts
  36115. // Heuristic: we have to check if the font is a standard one also
  36116. if (!!(properties.flags & FontFlags.Symbolic)) {
  36117. encoding = MacRomanEncoding;
  36118. if (!properties.file) {
  36119. if (/Symbol/i.test(properties.name)) {
  36120. encoding = SymbolSetEncoding;
  36121. } else if (/Dingbats/i.test(properties.name)) {
  36122. encoding = ZapfDingbatsEncoding;
  36123. }
  36124. }
  36125. }
  36126. properties.defaultEncoding = encoding;
  36127. }
  36128. properties.differences = differences;
  36129. properties.baseEncodingName = baseEncodingName;
  36130. properties.dict = dict;
  36131. },
  36132. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  36133. var cmap, cmapObj = toUnicode;
  36134. if (isName(cmapObj)) {
  36135. cmap = CMapFactory.create(cmapObj,
  36136. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  36137. if (cmap instanceof IdentityCMap) {
  36138. return new IdentityToUnicodeMap(0, 0xFFFF);
  36139. }
  36140. return new ToUnicodeMap(cmap.getMap());
  36141. } else if (isStream(cmapObj)) {
  36142. cmap = CMapFactory.create(cmapObj,
  36143. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  36144. if (cmap instanceof IdentityCMap) {
  36145. return new IdentityToUnicodeMap(0, 0xFFFF);
  36146. }
  36147. var map = new Array(cmap.length);
  36148. // Convert UTF-16BE
  36149. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  36150. // to iterate over all keys.
  36151. cmap.forEach(function(charCode, token) {
  36152. var str = [];
  36153. for (var k = 0; k < token.length; k += 2) {
  36154. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  36155. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  36156. str.push(w1);
  36157. continue;
  36158. }
  36159. k += 2;
  36160. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  36161. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  36162. }
  36163. map[charCode] = String.fromCharCode.apply(String, str);
  36164. });
  36165. return new ToUnicodeMap(map);
  36166. }
  36167. return null;
  36168. },
  36169. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  36170. // Extract the encoding from the CIDToGIDMap
  36171. var glyphsData = cidToGidStream.getBytes();
  36172. // Set encoding 0 to later verify the font has an encoding
  36173. var result = [];
  36174. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  36175. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  36176. if (glyphID === 0) {
  36177. continue;
  36178. }
  36179. var code = j >> 1;
  36180. result[code] = glyphID;
  36181. }
  36182. return result;
  36183. },
  36184. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  36185. descriptor,
  36186. properties) {
  36187. var glyphsWidths = [];
  36188. var defaultWidth = 0;
  36189. var glyphsVMetrics = [];
  36190. var defaultVMetrics;
  36191. var i, ii, j, jj, start, code, widths;
  36192. if (properties.composite) {
  36193. defaultWidth = dict.get('DW') || 1000;
  36194. widths = dict.get('W');
  36195. if (widths) {
  36196. for (i = 0, ii = widths.length; i < ii; i++) {
  36197. start = widths[i++];
  36198. code = xref.fetchIfRef(widths[i]);
  36199. if (isArray(code)) {
  36200. for (j = 0, jj = code.length; j < jj; j++) {
  36201. glyphsWidths[start++] = code[j];
  36202. }
  36203. } else {
  36204. var width = widths[++i];
  36205. for (j = start; j <= code; j++) {
  36206. glyphsWidths[j] = width;
  36207. }
  36208. }
  36209. }
  36210. }
  36211. if (properties.vertical) {
  36212. var vmetrics = (dict.get('DW2') || [880, -1000]);
  36213. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  36214. vmetrics = dict.get('W2');
  36215. if (vmetrics) {
  36216. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  36217. start = vmetrics[i++];
  36218. code = xref.fetchIfRef(vmetrics[i]);
  36219. if (isArray(code)) {
  36220. for (j = 0, jj = code.length; j < jj; j++) {
  36221. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  36222. }
  36223. } else {
  36224. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  36225. for (j = start; j <= code; j++) {
  36226. glyphsVMetrics[j] = vmetric;
  36227. }
  36228. }
  36229. }
  36230. }
  36231. }
  36232. } else {
  36233. var firstChar = properties.firstChar;
  36234. widths = dict.get('Widths');
  36235. if (widths) {
  36236. j = firstChar;
  36237. for (i = 0, ii = widths.length; i < ii; i++) {
  36238. glyphsWidths[j++] = widths[i];
  36239. }
  36240. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  36241. } else {
  36242. // Trying get the BaseFont metrics (see comment above).
  36243. var baseFontName = dict.get('BaseFont');
  36244. if (isName(baseFontName)) {
  36245. var metrics = this.getBaseFontMetrics(baseFontName.name);
  36246. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  36247. properties);
  36248. defaultWidth = metrics.defaultWidth;
  36249. }
  36250. }
  36251. }
  36252. // Heuristic: detection of monospace font by checking all non-zero widths
  36253. var isMonospace = true;
  36254. var firstWidth = defaultWidth;
  36255. for (var glyph in glyphsWidths) {
  36256. var glyphWidth = glyphsWidths[glyph];
  36257. if (!glyphWidth) {
  36258. continue;
  36259. }
  36260. if (!firstWidth) {
  36261. firstWidth = glyphWidth;
  36262. continue;
  36263. }
  36264. if (firstWidth !== glyphWidth) {
  36265. isMonospace = false;
  36266. break;
  36267. }
  36268. }
  36269. if (isMonospace) {
  36270. properties.flags |= FontFlags.FixedPitch;
  36271. }
  36272. properties.defaultWidth = defaultWidth;
  36273. properties.widths = glyphsWidths;
  36274. properties.defaultVMetrics = defaultVMetrics;
  36275. properties.vmetrics = glyphsVMetrics;
  36276. },
  36277. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  36278. // Simulating descriptor flags attribute
  36279. var fontNameWoStyle = baseFontName.split('-')[0];
  36280. return (fontNameWoStyle in getSerifFonts()) ||
  36281. (fontNameWoStyle.search(/serif/gi) !== -1);
  36282. },
  36283. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  36284. var defaultWidth = 0;
  36285. var widths = [];
  36286. var monospace = false;
  36287. var stdFontMap = getStdFontMap();
  36288. var lookupName = (stdFontMap[name] || name);
  36289. var Metrics = getMetrics();
  36290. if (!(lookupName in Metrics)) {
  36291. // Use default fonts for looking up font metrics if the passed
  36292. // font is not a base font
  36293. if (this.isSerifFont(name)) {
  36294. lookupName = 'Times-Roman';
  36295. } else {
  36296. lookupName = 'Helvetica';
  36297. }
  36298. }
  36299. var glyphWidths = Metrics[lookupName];
  36300. if (isNum(glyphWidths)) {
  36301. defaultWidth = glyphWidths;
  36302. monospace = true;
  36303. } else {
  36304. widths = glyphWidths(); // expand lazy widths array
  36305. }
  36306. return {
  36307. defaultWidth: defaultWidth,
  36308. monospace: monospace,
  36309. widths: widths
  36310. };
  36311. },
  36312. buildCharCodeToWidth:
  36313. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  36314. properties) {
  36315. var widths = Object.create(null);
  36316. var differences = properties.differences;
  36317. var encoding = properties.defaultEncoding;
  36318. for (var charCode = 0; charCode < 256; charCode++) {
  36319. if (charCode in differences &&
  36320. widthsByGlyphName[differences[charCode]]) {
  36321. widths[charCode] = widthsByGlyphName[differences[charCode]];
  36322. continue;
  36323. }
  36324. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  36325. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  36326. continue;
  36327. }
  36328. }
  36329. return widths;
  36330. },
  36331. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  36332. var baseDict = dict;
  36333. var type = dict.get('Subtype');
  36334. assert(isName(type), 'invalid font Subtype');
  36335. var composite = false;
  36336. var uint8array;
  36337. if (type.name === 'Type0') {
  36338. // If font is a composite
  36339. // - get the descendant font
  36340. // - set the type according to the descendant font
  36341. // - get the FontDescriptor from the descendant font
  36342. var df = dict.get('DescendantFonts');
  36343. if (!df) {
  36344. error('Descendant fonts are not specified');
  36345. }
  36346. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  36347. type = dict.get('Subtype');
  36348. assert(isName(type), 'invalid font Subtype');
  36349. composite = true;
  36350. }
  36351. var descriptor = dict.get('FontDescriptor');
  36352. if (descriptor) {
  36353. var hash = new MurmurHash3_64();
  36354. var encoding = baseDict.getRaw('Encoding');
  36355. if (isName(encoding)) {
  36356. hash.update(encoding.name);
  36357. } else if (isRef(encoding)) {
  36358. hash.update(encoding.num + '_' + encoding.gen);
  36359. } else if (isDict(encoding)) {
  36360. var keys = encoding.getKeys();
  36361. for (var i = 0, ii = keys.length; i < ii; i++) {
  36362. var entry = encoding.getRaw(keys[i]);
  36363. if (isName(entry)) {
  36364. hash.update(entry.name);
  36365. } else if (isRef(entry)) {
  36366. hash.update(entry.num + '_' + entry.gen);
  36367. } else if (isArray(entry)) { // 'Differences' entry.
  36368. // Ideally we should check the contents of the array, but to avoid
  36369. // parsing it here and then again in |extractDataStructures|,
  36370. // we only use the array length for now (fixes bug1157493.pdf).
  36371. hash.update(entry.length.toString());
  36372. }
  36373. }
  36374. }
  36375. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  36376. if (isStream(toUnicode)) {
  36377. var stream = toUnicode.str || toUnicode;
  36378. uint8array = stream.buffer ?
  36379. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  36380. new Uint8Array(stream.bytes.buffer,
  36381. stream.start, stream.end - stream.start);
  36382. hash.update(uint8array);
  36383. } else if (isName(toUnicode)) {
  36384. hash.update(toUnicode.name);
  36385. }
  36386. var widths = dict.get('Widths') || baseDict.get('Widths');
  36387. if (widths) {
  36388. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  36389. hash.update(uint8array);
  36390. }
  36391. }
  36392. return {
  36393. descriptor: descriptor,
  36394. dict: dict,
  36395. baseDict: baseDict,
  36396. composite: composite,
  36397. type: type.name,
  36398. hash: hash ? hash.hexdigest() : ''
  36399. };
  36400. },
  36401. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  36402. xref) {
  36403. var baseDict = preEvaluatedFont.baseDict;
  36404. var dict = preEvaluatedFont.dict;
  36405. var composite = preEvaluatedFont.composite;
  36406. var descriptor = preEvaluatedFont.descriptor;
  36407. var type = preEvaluatedFont.type;
  36408. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  36409. var properties;
  36410. if (!descriptor) {
  36411. if (type === 'Type3') {
  36412. // FontDescriptor is only required for Type3 fonts when the document
  36413. // is a tagged pdf. Create a barbebones one to get by.
  36414. descriptor = new Dict(null);
  36415. descriptor.set('FontName', Name.get(type));
  36416. descriptor.set('FontBBox', dict.get('FontBBox'));
  36417. } else {
  36418. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  36419. // FontDescriptor was not required.
  36420. // This case is here for compatibility.
  36421. var baseFontName = dict.get('BaseFont');
  36422. if (!isName(baseFontName)) {
  36423. error('Base font is not specified');
  36424. }
  36425. // Using base font name as a font name.
  36426. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  36427. var metrics = this.getBaseFontMetrics(baseFontName);
  36428. // Simulating descriptor flags attribute
  36429. var fontNameWoStyle = baseFontName.split('-')[0];
  36430. var flags =
  36431. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  36432. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  36433. (getSymbolsFonts()[fontNameWoStyle] ? FontFlags.Symbolic :
  36434. FontFlags.Nonsymbolic);
  36435. properties = {
  36436. type: type,
  36437. name: baseFontName,
  36438. widths: metrics.widths,
  36439. defaultWidth: metrics.defaultWidth,
  36440. flags: flags,
  36441. firstChar: 0,
  36442. lastChar: maxCharIndex
  36443. };
  36444. this.extractDataStructures(dict, dict, xref, properties);
  36445. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  36446. properties);
  36447. return new Font(baseFontName, null, properties);
  36448. }
  36449. }
  36450. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  36451. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  36452. // to ignore this rule when a variant of a standart font is used.
  36453. // TODO Fill the width array depending on which of the base font this is
  36454. // a variant.
  36455. var firstChar = (dict.get('FirstChar') || 0);
  36456. var lastChar = (dict.get('LastChar') || maxCharIndex);
  36457. var fontName = descriptor.get('FontName');
  36458. var baseFont = dict.get('BaseFont');
  36459. // Some bad PDFs have a string as the font name.
  36460. if (isString(fontName)) {
  36461. fontName = Name.get(fontName);
  36462. }
  36463. if (isString(baseFont)) {
  36464. baseFont = Name.get(baseFont);
  36465. }
  36466. if (type !== 'Type3') {
  36467. var fontNameStr = fontName && fontName.name;
  36468. var baseFontStr = baseFont && baseFont.name;
  36469. if (fontNameStr !== baseFontStr) {
  36470. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  36471. '" but should be the same as the Font\'s BaseFont "' +
  36472. baseFontStr + '"');
  36473. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  36474. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  36475. if (fontNameStr && baseFontStr &&
  36476. baseFontStr.indexOf(fontNameStr) === 0) {
  36477. fontName = baseFont;
  36478. }
  36479. }
  36480. }
  36481. fontName = (fontName || baseFont);
  36482. assert(isName(fontName), 'invalid font name');
  36483. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  36484. if (fontFile) {
  36485. if (fontFile.dict) {
  36486. var subtype = fontFile.dict.get('Subtype');
  36487. if (subtype) {
  36488. subtype = subtype.name;
  36489. }
  36490. var length1 = fontFile.dict.get('Length1');
  36491. var length2 = fontFile.dict.get('Length2');
  36492. }
  36493. }
  36494. properties = {
  36495. type: type,
  36496. name: fontName.name,
  36497. subtype: subtype,
  36498. file: fontFile,
  36499. length1: length1,
  36500. length2: length2,
  36501. loadedName: baseDict.loadedName,
  36502. composite: composite,
  36503. wideChars: composite,
  36504. fixedPitch: false,
  36505. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  36506. firstChar: firstChar || 0,
  36507. lastChar: (lastChar || maxCharIndex),
  36508. bbox: descriptor.get('FontBBox'),
  36509. ascent: descriptor.get('Ascent'),
  36510. descent: descriptor.get('Descent'),
  36511. xHeight: descriptor.get('XHeight'),
  36512. capHeight: descriptor.get('CapHeight'),
  36513. flags: descriptor.get('Flags'),
  36514. italicAngle: descriptor.get('ItalicAngle'),
  36515. coded: false
  36516. };
  36517. if (composite) {
  36518. var cidEncoding = baseDict.get('Encoding');
  36519. if (isName(cidEncoding)) {
  36520. properties.cidEncoding = cidEncoding.name;
  36521. }
  36522. properties.cMap = CMapFactory.create(cidEncoding,
  36523. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  36524. properties.vertical = properties.cMap.vertical;
  36525. }
  36526. this.extractDataStructures(dict, baseDict, xref, properties);
  36527. this.extractWidths(dict, xref, descriptor, properties);
  36528. if (type === 'Type3') {
  36529. properties.isType3Font = true;
  36530. }
  36531. return new Font(fontName.name, fontFile, properties);
  36532. }
  36533. };
  36534. return PartialEvaluator;
  36535. })();
  36536. var TranslatedFont = (function TranslatedFontClosure() {
  36537. function TranslatedFont(loadedName, font, dict) {
  36538. this.loadedName = loadedName;
  36539. this.font = font;
  36540. this.dict = dict;
  36541. this.type3Loaded = null;
  36542. this.sent = false;
  36543. }
  36544. TranslatedFont.prototype = {
  36545. send: function (handler) {
  36546. if (this.sent) {
  36547. return;
  36548. }
  36549. var fontData = this.font.exportData();
  36550. handler.send('commonobj', [
  36551. this.loadedName,
  36552. 'Font',
  36553. fontData
  36554. ]);
  36555. this.sent = true;
  36556. },
  36557. loadType3Data: function (evaluator, resources, parentOperatorList, task) {
  36558. assert(this.font.isType3Font);
  36559. if (this.type3Loaded) {
  36560. return this.type3Loaded;
  36561. }
  36562. var translatedFont = this.font;
  36563. var loadCharProcsPromise = Promise.resolve();
  36564. var charProcs = this.dict.get('CharProcs');
  36565. var fontResources = this.dict.get('Resources') || resources;
  36566. var charProcKeys = charProcs.getKeys();
  36567. var charProcOperatorList = Object.create(null);
  36568. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  36569. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  36570. var glyphStream = charProcs.get(key);
  36571. var operatorList = new OperatorList();
  36572. return evaluator.getOperatorList(glyphStream, task, fontResources,
  36573. operatorList).then(function () {
  36574. charProcOperatorList[key] = operatorList.getIR();
  36575. // Add the dependencies to the parent operator list so they are
  36576. // resolved before sub operator list is executed synchronously.
  36577. parentOperatorList.addDependencies(operatorList.dependencies);
  36578. }, function (reason) {
  36579. warn('Type3 font resource \"' + key + '\" is not available');
  36580. var operatorList = new OperatorList();
  36581. charProcOperatorList[key] = operatorList.getIR();
  36582. });
  36583. }.bind(this, charProcKeys[i]));
  36584. }
  36585. this.type3Loaded = loadCharProcsPromise.then(function () {
  36586. translatedFont.charProcOperatorList = charProcOperatorList;
  36587. });
  36588. return this.type3Loaded;
  36589. }
  36590. };
  36591. return TranslatedFont;
  36592. })();
  36593. var OperatorList = (function OperatorListClosure() {
  36594. var CHUNK_SIZE = 1000;
  36595. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  36596. function getTransfers(queue) {
  36597. var transfers = [];
  36598. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  36599. for (var i = 0, ii = queue.length; i < ii; i++) {
  36600. switch (fnArray[i]) {
  36601. case OPS.paintInlineImageXObject:
  36602. case OPS.paintInlineImageXObjectGroup:
  36603. case OPS.paintImageMaskXObject:
  36604. var arg = argsArray[i][0]; // first param in imgData
  36605. if (!arg.cached) {
  36606. transfers.push(arg.data.buffer);
  36607. }
  36608. break;
  36609. }
  36610. }
  36611. return transfers;
  36612. }
  36613. function OperatorList(intent, messageHandler, pageIndex) {
  36614. this.messageHandler = messageHandler;
  36615. this.fnArray = [];
  36616. this.argsArray = [];
  36617. this.dependencies = Object.create(null);
  36618. this._totalLength = 0;
  36619. this.pageIndex = pageIndex;
  36620. this.intent = intent;
  36621. }
  36622. OperatorList.prototype = {
  36623. get length() {
  36624. return this.argsArray.length;
  36625. },
  36626. /**
  36627. * @returns {number} The total length of the entire operator list,
  36628. * since `this.length === 0` after flushing.
  36629. */
  36630. get totalLength() {
  36631. return (this._totalLength + this.length);
  36632. },
  36633. addOp: function(fn, args) {
  36634. this.fnArray.push(fn);
  36635. this.argsArray.push(args);
  36636. if (this.messageHandler) {
  36637. if (this.fnArray.length >= CHUNK_SIZE) {
  36638. this.flush();
  36639. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  36640. (fn === OPS.restore || fn === OPS.endText)) {
  36641. // heuristic to flush on boundary of restore or endText
  36642. this.flush();
  36643. }
  36644. }
  36645. },
  36646. addDependency: function(dependency) {
  36647. if (dependency in this.dependencies) {
  36648. return;
  36649. }
  36650. this.dependencies[dependency] = true;
  36651. this.addOp(OPS.dependency, [dependency]);
  36652. },
  36653. addDependencies: function(dependencies) {
  36654. for (var key in dependencies) {
  36655. this.addDependency(key);
  36656. }
  36657. },
  36658. addOpList: function(opList) {
  36659. Util.extendObj(this.dependencies, opList.dependencies);
  36660. for (var i = 0, ii = opList.length; i < ii; i++) {
  36661. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  36662. }
  36663. },
  36664. getIR: function() {
  36665. return {
  36666. fnArray: this.fnArray,
  36667. argsArray: this.argsArray,
  36668. length: this.length
  36669. };
  36670. },
  36671. flush: function(lastChunk) {
  36672. if (this.intent !== 'oplist') {
  36673. new QueueOptimizer().optimize(this);
  36674. }
  36675. var transfers = getTransfers(this);
  36676. var length = this.length;
  36677. this._totalLength += length;
  36678. this.messageHandler.send('RenderPageChunk', {
  36679. operatorList: {
  36680. fnArray: this.fnArray,
  36681. argsArray: this.argsArray,
  36682. lastChunk: lastChunk,
  36683. length: length
  36684. },
  36685. pageIndex: this.pageIndex,
  36686. intent: this.intent
  36687. }, transfers);
  36688. this.dependencies = Object.create(null);
  36689. this.fnArray.length = 0;
  36690. this.argsArray.length = 0;
  36691. }
  36692. };
  36693. return OperatorList;
  36694. })();
  36695. var StateManager = (function StateManagerClosure() {
  36696. function StateManager(initialState) {
  36697. this.state = initialState;
  36698. this.stateStack = [];
  36699. }
  36700. StateManager.prototype = {
  36701. save: function () {
  36702. var old = this.state;
  36703. this.stateStack.push(this.state);
  36704. this.state = old.clone();
  36705. },
  36706. restore: function () {
  36707. var prev = this.stateStack.pop();
  36708. if (prev) {
  36709. this.state = prev;
  36710. }
  36711. },
  36712. transform: function (args) {
  36713. this.state.ctm = Util.transform(this.state.ctm, args);
  36714. }
  36715. };
  36716. return StateManager;
  36717. })();
  36718. var TextState = (function TextStateClosure() {
  36719. function TextState() {
  36720. this.ctm = new Float32Array(IDENTITY_MATRIX);
  36721. this.fontSize = 0;
  36722. this.font = null;
  36723. this.fontMatrix = FONT_IDENTITY_MATRIX;
  36724. this.textMatrix = IDENTITY_MATRIX.slice();
  36725. this.textLineMatrix = IDENTITY_MATRIX.slice();
  36726. this.charSpacing = 0;
  36727. this.wordSpacing = 0;
  36728. this.leading = 0;
  36729. this.textHScale = 1;
  36730. this.textRise = 0;
  36731. }
  36732. TextState.prototype = {
  36733. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  36734. var m = this.textMatrix;
  36735. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  36736. },
  36737. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  36738. var m = this.textLineMatrix;
  36739. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  36740. },
  36741. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  36742. var m = this.textMatrix;
  36743. m[4] = m[0] * x + m[2] * y + m[4];
  36744. m[5] = m[1] * x + m[3] * y + m[5];
  36745. },
  36746. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  36747. var m = this.textLineMatrix;
  36748. m[4] = m[0] * x + m[2] * y + m[4];
  36749. m[5] = m[1] * x + m[3] * y + m[5];
  36750. },
  36751. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  36752. // 9.4.4 Text Space Details
  36753. var tsm = [this.fontSize * this.textHScale, 0,
  36754. 0, this.fontSize,
  36755. 0, this.textRise];
  36756. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  36757. },
  36758. carriageReturn: function TextState_carriageReturn() {
  36759. this.translateTextLineMatrix(0, -this.leading);
  36760. this.textMatrix = this.textLineMatrix.slice();
  36761. },
  36762. clone: function TextState_clone() {
  36763. var clone = Object.create(this);
  36764. clone.textMatrix = this.textMatrix.slice();
  36765. clone.textLineMatrix = this.textLineMatrix.slice();
  36766. clone.fontMatrix = this.fontMatrix.slice();
  36767. return clone;
  36768. }
  36769. };
  36770. return TextState;
  36771. })();
  36772. var EvalState = (function EvalStateClosure() {
  36773. function EvalState() {
  36774. this.ctm = new Float32Array(IDENTITY_MATRIX);
  36775. this.font = null;
  36776. this.textRenderingMode = TextRenderingMode.FILL;
  36777. this.fillColorSpace = ColorSpace.singletons.gray;
  36778. this.strokeColorSpace = ColorSpace.singletons.gray;
  36779. }
  36780. EvalState.prototype = {
  36781. clone: function CanvasExtraState_clone() {
  36782. return Object.create(this);
  36783. },
  36784. };
  36785. return EvalState;
  36786. })();
  36787. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  36788. // Specifies properties for each command
  36789. //
  36790. // If variableArgs === true: [0, `numArgs`] expected
  36791. // If variableArgs === false: exactly `numArgs` expected
  36792. var getOPMap = getLookupTableFactory(function (t) {
  36793. // Graphic state
  36794. t['w'] = { id: OPS.setLineWidth, numArgs: 1, variableArgs: false };
  36795. t['J'] = { id: OPS.setLineCap, numArgs: 1, variableArgs: false };
  36796. t['j'] = { id: OPS.setLineJoin, numArgs: 1, variableArgs: false };
  36797. t['M'] = { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false };
  36798. t['d'] = { id: OPS.setDash, numArgs: 2, variableArgs: false };
  36799. t['ri'] = { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false };
  36800. t['i'] = { id: OPS.setFlatness, numArgs: 1, variableArgs: false };
  36801. t['gs'] = { id: OPS.setGState, numArgs: 1, variableArgs: false };
  36802. t['q'] = { id: OPS.save, numArgs: 0, variableArgs: false };
  36803. t['Q'] = { id: OPS.restore, numArgs: 0, variableArgs: false };
  36804. t['cm'] = { id: OPS.transform, numArgs: 6, variableArgs: false };
  36805. // Path
  36806. t['m'] = { id: OPS.moveTo, numArgs: 2, variableArgs: false };
  36807. t['l'] = { id: OPS.lineTo, numArgs: 2, variableArgs: false };
  36808. t['c'] = { id: OPS.curveTo, numArgs: 6, variableArgs: false };
  36809. t['v'] = { id: OPS.curveTo2, numArgs: 4, variableArgs: false };
  36810. t['y'] = { id: OPS.curveTo3, numArgs: 4, variableArgs: false };
  36811. t['h'] = { id: OPS.closePath, numArgs: 0, variableArgs: false };
  36812. t['re'] = { id: OPS.rectangle, numArgs: 4, variableArgs: false };
  36813. t['S'] = { id: OPS.stroke, numArgs: 0, variableArgs: false };
  36814. t['s'] = { id: OPS.closeStroke, numArgs: 0, variableArgs: false };
  36815. t['f'] = { id: OPS.fill, numArgs: 0, variableArgs: false };
  36816. t['F'] = { id: OPS.fill, numArgs: 0, variableArgs: false };
  36817. t['f*'] = { id: OPS.eoFill, numArgs: 0, variableArgs: false };
  36818. t['B'] = { id: OPS.fillStroke, numArgs: 0, variableArgs: false };
  36819. t['B*'] = { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false };
  36820. t['b'] = { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false };
  36821. t['b*'] = { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false };
  36822. t['n'] = { id: OPS.endPath, numArgs: 0, variableArgs: false };
  36823. // Clipping
  36824. t['W'] = { id: OPS.clip, numArgs: 0, variableArgs: false };
  36825. t['W*'] = { id: OPS.eoClip, numArgs: 0, variableArgs: false };
  36826. // Text
  36827. t['BT'] = { id: OPS.beginText, numArgs: 0, variableArgs: false };
  36828. t['ET'] = { id: OPS.endText, numArgs: 0, variableArgs: false };
  36829. t['Tc'] = { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false };
  36830. t['Tw'] = { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false };
  36831. t['Tz'] = { id: OPS.setHScale, numArgs: 1, variableArgs: false };
  36832. t['TL'] = { id: OPS.setLeading, numArgs: 1, variableArgs: false };
  36833. t['Tf'] = { id: OPS.setFont, numArgs: 2, variableArgs: false };
  36834. t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false };
  36835. t['Ts'] = { id: OPS.setTextRise, numArgs: 1, variableArgs: false };
  36836. t['Td'] = { id: OPS.moveText, numArgs: 2, variableArgs: false };
  36837. t['TD'] = { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false };
  36838. t['Tm'] = { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false };
  36839. t['T*'] = { id: OPS.nextLine, numArgs: 0, variableArgs: false };
  36840. t['Tj'] = { id: OPS.showText, numArgs: 1, variableArgs: false };
  36841. t['TJ'] = { id: OPS.showSpacedText, numArgs: 1, variableArgs: false };
  36842. t['\''] = { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false };
  36843. t['"'] = { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  36844. variableArgs: false };
  36845. // Type3 fonts
  36846. t['d0'] = { id: OPS.setCharWidth, numArgs: 2, variableArgs: false };
  36847. t['d1'] = { id: OPS.setCharWidthAndBounds, numArgs: 6,
  36848. variableArgs: false };
  36849. // Color
  36850. t['CS'] = { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false };
  36851. t['cs'] = { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false };
  36852. t['SC'] = { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true };
  36853. t['SCN'] = { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true };
  36854. t['sc'] = { id: OPS.setFillColor, numArgs: 4, variableArgs: true };
  36855. t['scn'] = { id: OPS.setFillColorN, numArgs: 33, variableArgs: true };
  36856. t['G'] = { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false };
  36857. t['g'] = { id: OPS.setFillGray, numArgs: 1, variableArgs: false };
  36858. t['RG'] = { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false };
  36859. t['rg'] = { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false };
  36860. t['K'] = { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false };
  36861. t['k'] = { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false };
  36862. // Shading
  36863. t['sh'] = { id: OPS.shadingFill, numArgs: 1, variableArgs: false };
  36864. // Images
  36865. t['BI'] = { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false };
  36866. t['ID'] = { id: OPS.beginImageData, numArgs: 0, variableArgs: false };
  36867. t['EI'] = { id: OPS.endInlineImage, numArgs: 1, variableArgs: false };
  36868. // XObjects
  36869. t['Do'] = { id: OPS.paintXObject, numArgs: 1, variableArgs: false };
  36870. t['MP'] = { id: OPS.markPoint, numArgs: 1, variableArgs: false };
  36871. t['DP'] = { id: OPS.markPointProps, numArgs: 2, variableArgs: false };
  36872. t['BMC'] = { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false };
  36873. t['BDC'] = { id: OPS.beginMarkedContentProps, numArgs: 2,
  36874. variableArgs: false };
  36875. t['EMC'] = { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false };
  36876. // Compatibility
  36877. t['BX'] = { id: OPS.beginCompat, numArgs: 0, variableArgs: false };
  36878. t['EX'] = { id: OPS.endCompat, numArgs: 0, variableArgs: false };
  36879. // (reserved partial commands for the lexer)
  36880. t['BM'] = null;
  36881. t['BD'] = null;
  36882. t['true'] = null;
  36883. t['fa'] = null;
  36884. t['fal'] = null;
  36885. t['fals'] = null;
  36886. t['false'] = null;
  36887. t['nu'] = null;
  36888. t['nul'] = null;
  36889. t['null'] = null;
  36890. });
  36891. function EvaluatorPreprocessor(stream, xref, stateManager) {
  36892. this.opMap = getOPMap();
  36893. // TODO(mduan): pass array of knownCommands rather than this.opMap
  36894. // dictionary
  36895. this.parser = new Parser(new Lexer(stream, this.opMap), false, xref);
  36896. this.stateManager = stateManager;
  36897. this.nonProcessedArgs = [];
  36898. }
  36899. EvaluatorPreprocessor.prototype = {
  36900. get savedStatesDepth() {
  36901. return this.stateManager.stateStack.length;
  36902. },
  36903. // |operation| is an object with two fields:
  36904. //
  36905. // - |fn| is an out param.
  36906. //
  36907. // - |args| is an inout param. On entry, it should have one of two values.
  36908. //
  36909. // - An empty array. This indicates that the caller is providing the
  36910. // array in which the args will be stored in. The caller should use
  36911. // this value if it can reuse a single array for each call to read().
  36912. //
  36913. // - |null|. This indicates that the caller needs this function to create
  36914. // the array in which any args are stored in. If there are zero args,
  36915. // this function will leave |operation.args| as |null| (thus avoiding
  36916. // allocations that would occur if we used an empty array to represent
  36917. // zero arguments). Otherwise, it will replace |null| with a new array
  36918. // containing the arguments. The caller should use this value if it
  36919. // cannot reuse an array for each call to read().
  36920. //
  36921. // These two modes are present because this function is very hot and so
  36922. // avoiding allocations where possible is worthwhile.
  36923. //
  36924. read: function EvaluatorPreprocessor_read(operation) {
  36925. var args = operation.args;
  36926. while (true) {
  36927. var obj = this.parser.getObj();
  36928. if (isCmd(obj)) {
  36929. var cmd = obj.cmd;
  36930. // Check that the command is valid
  36931. var opSpec = this.opMap[cmd];
  36932. if (!opSpec) {
  36933. warn('Unknown command "' + cmd + '"');
  36934. continue;
  36935. }
  36936. var fn = opSpec.id;
  36937. var numArgs = opSpec.numArgs;
  36938. var argsLength = args !== null ? args.length : 0;
  36939. if (!opSpec.variableArgs) {
  36940. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  36941. if (argsLength !== numArgs) {
  36942. var nonProcessedArgs = this.nonProcessedArgs;
  36943. while (argsLength > numArgs) {
  36944. nonProcessedArgs.push(args.shift());
  36945. argsLength--;
  36946. }
  36947. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  36948. if (!args) {
  36949. args = [];
  36950. }
  36951. args.unshift(nonProcessedArgs.pop());
  36952. argsLength++;
  36953. }
  36954. }
  36955. if (argsLength < numArgs) {
  36956. // If we receive too few args, it's not possible to possible
  36957. // to execute the command, so skip the command
  36958. info('Command ' + fn + ': because expected ' +
  36959. numArgs + ' args, but received ' + argsLength +
  36960. ' args; skipping');
  36961. args = null;
  36962. continue;
  36963. }
  36964. } else if (argsLength > numArgs) {
  36965. info('Command ' + fn + ': expected [0,' + numArgs +
  36966. '] args, but received ' + argsLength + ' args');
  36967. }
  36968. // TODO figure out how to type-check vararg functions
  36969. this.preprocessCommand(fn, args);
  36970. operation.fn = fn;
  36971. operation.args = args;
  36972. return true;
  36973. } else {
  36974. if (isEOF(obj)) {
  36975. return false; // no more commands
  36976. }
  36977. // argument
  36978. if (obj !== null) {
  36979. if (!args) {
  36980. args = [];
  36981. }
  36982. args.push(obj);
  36983. assert(args.length <= 33, 'Too many arguments');
  36984. }
  36985. }
  36986. }
  36987. },
  36988. preprocessCommand:
  36989. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  36990. switch (fn | 0) {
  36991. case OPS.save:
  36992. this.stateManager.save();
  36993. break;
  36994. case OPS.restore:
  36995. this.stateManager.restore();
  36996. break;
  36997. case OPS.transform:
  36998. this.stateManager.transform(args);
  36999. break;
  37000. }
  37001. }
  37002. };
  37003. return EvaluatorPreprocessor;
  37004. })();
  37005. var QueueOptimizer = (function QueueOptimizerClosure() {
  37006. function addState(parentState, pattern, fn) {
  37007. var state = parentState;
  37008. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  37009. var item = pattern[i];
  37010. state = (state[item] || (state[item] = []));
  37011. }
  37012. state[pattern[pattern.length - 1]] = fn;
  37013. }
  37014. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  37015. argsArray) {
  37016. // Handles special case of mainly LaTeX documents which use image masks to
  37017. // draw lines with the current fill style.
  37018. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  37019. // have been found at iFirstSave.
  37020. var iFirstPIMXO = iFirstSave + 2;
  37021. for (var i = 0; i < count; i++) {
  37022. var arg = argsArray[iFirstPIMXO + 4 * i];
  37023. var imageMask = arg.length === 1 && arg[0];
  37024. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  37025. (!imageMask.data.length ||
  37026. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  37027. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  37028. continue;
  37029. }
  37030. break;
  37031. }
  37032. return count - i;
  37033. }
  37034. var InitialState = [];
  37035. // This replaces (save, transform, paintInlineImageXObject, restore)+
  37036. // sequences with one |paintInlineImageXObjectGroup| operation.
  37037. addState(InitialState,
  37038. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  37039. function foundInlineImageGroup(context) {
  37040. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  37041. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  37042. var MAX_WIDTH = 1000;
  37043. var IMAGE_PADDING = 1;
  37044. var fnArray = context.fnArray, argsArray = context.argsArray;
  37045. var curr = context.iCurr;
  37046. var iFirstSave = curr - 3;
  37047. var iFirstTransform = curr - 2;
  37048. var iFirstPIIXO = curr - 1;
  37049. // Look for the quartets.
  37050. var i = iFirstSave + 4;
  37051. var ii = fnArray.length;
  37052. while (i + 3 < ii) {
  37053. if (fnArray[i] !== OPS.save ||
  37054. fnArray[i + 1] !== OPS.transform ||
  37055. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  37056. fnArray[i + 3] !== OPS.restore) {
  37057. break; // ops don't match
  37058. }
  37059. i += 4;
  37060. }
  37061. // At this point, i is the index of the first op past the last valid
  37062. // quartet.
  37063. var count = Math.min((i - iFirstSave) / 4,
  37064. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  37065. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  37066. return i;
  37067. }
  37068. // assuming that heights of those image is too small (~1 pixel)
  37069. // packing as much as possible by lines
  37070. var maxX = 0;
  37071. var map = [], maxLineHeight = 0;
  37072. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  37073. var q;
  37074. for (q = 0; q < count; q++) {
  37075. var transform = argsArray[iFirstTransform + (q << 2)];
  37076. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  37077. if (currentX + img.width > MAX_WIDTH) {
  37078. // starting new line
  37079. maxX = Math.max(maxX, currentX);
  37080. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  37081. currentX = 0;
  37082. maxLineHeight = 0;
  37083. }
  37084. map.push({
  37085. transform: transform,
  37086. x: currentX, y: currentY,
  37087. w: img.width, h: img.height
  37088. });
  37089. currentX += img.width + 2 * IMAGE_PADDING;
  37090. maxLineHeight = Math.max(maxLineHeight, img.height);
  37091. }
  37092. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  37093. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  37094. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  37095. var imgRowSize = imgWidth << 2;
  37096. for (q = 0; q < count; q++) {
  37097. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  37098. // Copy image by lines and extends pixels into padding.
  37099. var rowSize = map[q].w << 2;
  37100. var dataOffset = 0;
  37101. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  37102. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  37103. for (var k = 0, kk = map[q].h; k < kk; k++) {
  37104. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  37105. dataOffset += rowSize;
  37106. offset += imgRowSize;
  37107. }
  37108. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  37109. while (offset >= 0) {
  37110. data[offset - 4] = data[offset];
  37111. data[offset - 3] = data[offset + 1];
  37112. data[offset - 2] = data[offset + 2];
  37113. data[offset - 1] = data[offset + 3];
  37114. data[offset + rowSize] = data[offset + rowSize - 4];
  37115. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  37116. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  37117. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  37118. offset -= imgRowSize;
  37119. }
  37120. }
  37121. // Replace queue items.
  37122. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  37123. argsArray.splice(iFirstSave, count * 4,
  37124. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  37125. data: imgData }, map]);
  37126. return iFirstSave + 1;
  37127. });
  37128. // This replaces (save, transform, paintImageMaskXObject, restore)+
  37129. // sequences with one |paintImageMaskXObjectGroup| or one
  37130. // |paintImageMaskXObjectRepeat| operation.
  37131. addState(InitialState,
  37132. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  37133. function foundImageMaskGroup(context) {
  37134. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  37135. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  37136. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  37137. var fnArray = context.fnArray, argsArray = context.argsArray;
  37138. var curr = context.iCurr;
  37139. var iFirstSave = curr - 3;
  37140. var iFirstTransform = curr - 2;
  37141. var iFirstPIMXO = curr - 1;
  37142. // Look for the quartets.
  37143. var i = iFirstSave + 4;
  37144. var ii = fnArray.length;
  37145. while (i + 3 < ii) {
  37146. if (fnArray[i] !== OPS.save ||
  37147. fnArray[i + 1] !== OPS.transform ||
  37148. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  37149. fnArray[i + 3] !== OPS.restore) {
  37150. break; // ops don't match
  37151. }
  37152. i += 4;
  37153. }
  37154. // At this point, i is the index of the first op past the last valid
  37155. // quartet.
  37156. var count = (i - iFirstSave) / 4;
  37157. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  37158. argsArray);
  37159. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  37160. return i;
  37161. }
  37162. var q;
  37163. var isSameImage = false;
  37164. var iTransform, transformArgs;
  37165. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  37166. if (argsArray[iFirstTransform][1] === 0 &&
  37167. argsArray[iFirstTransform][2] === 0) {
  37168. isSameImage = true;
  37169. var firstTransformArg0 = argsArray[iFirstTransform][0];
  37170. var firstTransformArg3 = argsArray[iFirstTransform][3];
  37171. iTransform = iFirstTransform + 4;
  37172. var iPIMXO = iFirstPIMXO + 4;
  37173. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  37174. transformArgs = argsArray[iTransform];
  37175. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  37176. transformArgs[0] !== firstTransformArg0 ||
  37177. transformArgs[1] !== 0 ||
  37178. transformArgs[2] !== 0 ||
  37179. transformArgs[3] !== firstTransformArg3) {
  37180. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  37181. isSameImage = false;
  37182. } else {
  37183. count = q;
  37184. }
  37185. break; // different image or transform
  37186. }
  37187. }
  37188. }
  37189. if (isSameImage) {
  37190. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  37191. var positions = new Float32Array(count * 2);
  37192. iTransform = iFirstTransform;
  37193. for (q = 0; q < count; q++, iTransform += 4) {
  37194. transformArgs = argsArray[iTransform];
  37195. positions[(q << 1)] = transformArgs[4];
  37196. positions[(q << 1) + 1] = transformArgs[5];
  37197. }
  37198. // Replace queue items.
  37199. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  37200. argsArray.splice(iFirstSave, count * 4,
  37201. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  37202. } else {
  37203. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  37204. var images = [];
  37205. for (q = 0; q < count; q++) {
  37206. transformArgs = argsArray[iFirstTransform + (q << 2)];
  37207. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  37208. images.push({ data: maskParams.data, width: maskParams.width,
  37209. height: maskParams.height,
  37210. transform: transformArgs });
  37211. }
  37212. // Replace queue items.
  37213. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  37214. argsArray.splice(iFirstSave, count * 4, [images]);
  37215. }
  37216. return iFirstSave + 1;
  37217. });
  37218. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  37219. // with one paintImageXObjectRepeat operation, if the |transform| and
  37220. // |paintImageXObjectRepeat| ops are appropriate.
  37221. addState(InitialState,
  37222. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  37223. function (context) {
  37224. var MIN_IMAGES_IN_BLOCK = 3;
  37225. var MAX_IMAGES_IN_BLOCK = 1000;
  37226. var fnArray = context.fnArray, argsArray = context.argsArray;
  37227. var curr = context.iCurr;
  37228. var iFirstSave = curr - 3;
  37229. var iFirstTransform = curr - 2;
  37230. var iFirstPIXO = curr - 1;
  37231. var iFirstRestore = curr;
  37232. if (argsArray[iFirstTransform][1] !== 0 ||
  37233. argsArray[iFirstTransform][2] !== 0) {
  37234. return iFirstRestore + 1; // transform has the wrong form
  37235. }
  37236. // Look for the quartets.
  37237. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  37238. var firstTransformArg0 = argsArray[iFirstTransform][0];
  37239. var firstTransformArg3 = argsArray[iFirstTransform][3];
  37240. var i = iFirstSave + 4;
  37241. var ii = fnArray.length;
  37242. while (i + 3 < ii) {
  37243. if (fnArray[i] !== OPS.save ||
  37244. fnArray[i + 1] !== OPS.transform ||
  37245. fnArray[i + 2] !== OPS.paintImageXObject ||
  37246. fnArray[i + 3] !== OPS.restore) {
  37247. break; // ops don't match
  37248. }
  37249. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  37250. argsArray[i + 1][1] !== 0 ||
  37251. argsArray[i + 1][2] !== 0 ||
  37252. argsArray[i + 1][3] !== firstTransformArg3) {
  37253. break; // transforms don't match
  37254. }
  37255. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  37256. break; // images don't match
  37257. }
  37258. i += 4;
  37259. }
  37260. // At this point, i is the index of the first op past the last valid
  37261. // quartet.
  37262. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  37263. if (count < MIN_IMAGES_IN_BLOCK) {
  37264. return i;
  37265. }
  37266. // Extract the (x,y) positions from all of the matching transforms.
  37267. var positions = new Float32Array(count * 2);
  37268. var iTransform = iFirstTransform;
  37269. for (var q = 0; q < count; q++, iTransform += 4) {
  37270. var transformArgs = argsArray[iTransform];
  37271. positions[(q << 1)] = transformArgs[4];
  37272. positions[(q << 1) + 1] = transformArgs[5];
  37273. }
  37274. // Replace queue items.
  37275. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  37276. positions];
  37277. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  37278. argsArray.splice(iFirstSave, count * 4, args);
  37279. return iFirstSave + 1;
  37280. });
  37281. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  37282. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  37283. // sequences, if the font for each one is the same.
  37284. addState(InitialState,
  37285. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  37286. function (context) {
  37287. var MIN_CHARS_IN_BLOCK = 3;
  37288. var MAX_CHARS_IN_BLOCK = 1000;
  37289. var fnArray = context.fnArray, argsArray = context.argsArray;
  37290. var curr = context.iCurr;
  37291. var iFirstBeginText = curr - 4;
  37292. var iFirstSetFont = curr - 3;
  37293. var iFirstSetTextMatrix = curr - 2;
  37294. var iFirstShowText = curr - 1;
  37295. var iFirstEndText = curr;
  37296. // Look for the quintets.
  37297. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  37298. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  37299. var i = iFirstBeginText + 5;
  37300. var ii = fnArray.length;
  37301. while (i + 4 < ii) {
  37302. if (fnArray[i] !== OPS.beginText ||
  37303. fnArray[i + 1] !== OPS.setFont ||
  37304. fnArray[i + 2] !== OPS.setTextMatrix ||
  37305. fnArray[i + 3] !== OPS.showText ||
  37306. fnArray[i + 4] !== OPS.endText) {
  37307. break; // ops don't match
  37308. }
  37309. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  37310. argsArray[i + 1][1] !== firstSetFontArg1) {
  37311. break; // fonts don't match
  37312. }
  37313. i += 5;
  37314. }
  37315. // At this point, i is the index of the first op past the last valid
  37316. // quintet.
  37317. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  37318. if (count < MIN_CHARS_IN_BLOCK) {
  37319. return i;
  37320. }
  37321. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  37322. // showText, endText), include that as well. (E.g. <something> might be
  37323. // |dependency|.)
  37324. var iFirst = iFirstBeginText;
  37325. if (iFirstBeginText >= 4 &&
  37326. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  37327. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  37328. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  37329. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  37330. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  37331. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  37332. count++;
  37333. iFirst -= 5;
  37334. }
  37335. // Remove (endText, beginText, setFont) trios.
  37336. var iEndText = iFirst + 4;
  37337. for (var q = 1; q < count; q++) {
  37338. fnArray.splice(iEndText, 3);
  37339. argsArray.splice(iEndText, 3);
  37340. iEndText += 2;
  37341. }
  37342. return iEndText + 1;
  37343. });
  37344. function QueueOptimizer() {}
  37345. QueueOptimizer.prototype = {
  37346. optimize: function QueueOptimizer_optimize(queue) {
  37347. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  37348. var context = {
  37349. iCurr: 0,
  37350. fnArray: fnArray,
  37351. argsArray: argsArray
  37352. };
  37353. var state;
  37354. var i = 0, ii = fnArray.length;
  37355. while (i < ii) {
  37356. state = (state || InitialState)[fnArray[i]];
  37357. if (typeof state === 'function') { // we found some handler
  37358. context.iCurr = i;
  37359. // state() returns the index of the first non-matching op (if we
  37360. // didn't match) or the first op past the modified ops (if we did
  37361. // match and replace).
  37362. i = state(context);
  37363. state = undefined; // reset the state machine
  37364. ii = context.fnArray.length;
  37365. } else {
  37366. i++;
  37367. }
  37368. }
  37369. }
  37370. };
  37371. return QueueOptimizer;
  37372. })();
  37373. exports.OperatorList = OperatorList;
  37374. exports.PartialEvaluator = PartialEvaluator;
  37375. }));
  37376. (function (root, factory) {
  37377. {
  37378. factory((root.pdfjsCoreAnnotation = {}), root.pdfjsSharedUtil,
  37379. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreColorSpace,
  37380. root.pdfjsCoreObj, root.pdfjsCoreEvaluator);
  37381. }
  37382. }(this, function (exports, sharedUtil, corePrimitives, coreStream,
  37383. coreColorSpace, coreObj, coreEvaluator) {
  37384. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  37385. var AnnotationFlag = sharedUtil.AnnotationFlag;
  37386. var AnnotationType = sharedUtil.AnnotationType;
  37387. var OPS = sharedUtil.OPS;
  37388. var Util = sharedUtil.Util;
  37389. var isArray = sharedUtil.isArray;
  37390. var isInt = sharedUtil.isInt;
  37391. var isValidUrl = sharedUtil.isValidUrl;
  37392. var stringToBytes = sharedUtil.stringToBytes;
  37393. var stringToPDFString = sharedUtil.stringToPDFString;
  37394. var stringToUTF8String = sharedUtil.stringToUTF8String;
  37395. var warn = sharedUtil.warn;
  37396. var Dict = corePrimitives.Dict;
  37397. var isDict = corePrimitives.isDict;
  37398. var isName = corePrimitives.isName;
  37399. var Stream = coreStream.Stream;
  37400. var ColorSpace = coreColorSpace.ColorSpace;
  37401. var ObjectLoader = coreObj.ObjectLoader;
  37402. var FileSpec = coreObj.FileSpec;
  37403. var OperatorList = coreEvaluator.OperatorList;
  37404. /**
  37405. * @class
  37406. * @alias AnnotationFactory
  37407. */
  37408. function AnnotationFactory() {}
  37409. AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
  37410. /**
  37411. * @param {XRef} xref
  37412. * @param {Object} ref
  37413. * @returns {Annotation}
  37414. */
  37415. create: function AnnotationFactory_create(xref, ref) {
  37416. var dict = xref.fetchIfRef(ref);
  37417. if (!isDict(dict)) {
  37418. return;
  37419. }
  37420. // Determine the annotation's subtype.
  37421. var subtype = dict.get('Subtype');
  37422. subtype = isName(subtype) ? subtype.name : '';
  37423. // Return the right annotation object based on the subtype and field type.
  37424. var parameters = {
  37425. xref: xref,
  37426. dict: dict,
  37427. ref: ref
  37428. };
  37429. switch (subtype) {
  37430. case 'Link':
  37431. return new LinkAnnotation(parameters);
  37432. case 'Text':
  37433. return new TextAnnotation(parameters);
  37434. case 'Widget':
  37435. var fieldType = Util.getInheritableProperty(dict, 'FT');
  37436. if (isName(fieldType) && fieldType.name === 'Tx') {
  37437. return new TextWidgetAnnotation(parameters);
  37438. }
  37439. return new WidgetAnnotation(parameters);
  37440. case 'Popup':
  37441. return new PopupAnnotation(parameters);
  37442. case 'Highlight':
  37443. return new HighlightAnnotation(parameters);
  37444. case 'Underline':
  37445. return new UnderlineAnnotation(parameters);
  37446. case 'Squiggly':
  37447. return new SquigglyAnnotation(parameters);
  37448. case 'StrikeOut':
  37449. return new StrikeOutAnnotation(parameters);
  37450. case 'FileAttachment':
  37451. return new FileAttachmentAnnotation(parameters);
  37452. default:
  37453. warn('Unimplemented annotation type "' + subtype + '", ' +
  37454. 'falling back to base annotation');
  37455. return new Annotation(parameters);
  37456. }
  37457. }
  37458. };
  37459. var Annotation = (function AnnotationClosure() {
  37460. // 12.5.5: Algorithm: Appearance streams
  37461. function getTransformMatrix(rect, bbox, matrix) {
  37462. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  37463. var minX = bounds[0];
  37464. var minY = bounds[1];
  37465. var maxX = bounds[2];
  37466. var maxY = bounds[3];
  37467. if (minX === maxX || minY === maxY) {
  37468. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  37469. // just apply the transform for rect
  37470. return [1, 0, 0, 1, rect[0], rect[1]];
  37471. }
  37472. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  37473. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  37474. return [
  37475. xRatio,
  37476. 0,
  37477. 0,
  37478. yRatio,
  37479. rect[0] - minX * xRatio,
  37480. rect[1] - minY * yRatio
  37481. ];
  37482. }
  37483. function getDefaultAppearance(dict) {
  37484. var appearanceState = dict.get('AP');
  37485. if (!isDict(appearanceState)) {
  37486. return;
  37487. }
  37488. var appearance;
  37489. var appearances = appearanceState.get('N');
  37490. if (isDict(appearances)) {
  37491. var as = dict.get('AS');
  37492. if (as && appearances.has(as.name)) {
  37493. appearance = appearances.get(as.name);
  37494. }
  37495. } else {
  37496. appearance = appearances;
  37497. }
  37498. return appearance;
  37499. }
  37500. function Annotation(params) {
  37501. var dict = params.dict;
  37502. this.setFlags(dict.get('F'));
  37503. this.setRectangle(dict.get('Rect'));
  37504. this.setColor(dict.get('C'));
  37505. this.setBorderStyle(dict);
  37506. this.appearance = getDefaultAppearance(dict);
  37507. // Expose public properties using a data object.
  37508. this.data = {};
  37509. this.data.id = params.ref.toString();
  37510. this.data.subtype = dict.get('Subtype').name;
  37511. this.data.annotationFlags = this.flags;
  37512. this.data.rect = this.rectangle;
  37513. this.data.color = this.color;
  37514. this.data.borderStyle = this.borderStyle;
  37515. this.data.hasAppearance = !!this.appearance;
  37516. }
  37517. Annotation.prototype = {
  37518. /**
  37519. * @return {boolean}
  37520. */
  37521. get viewable() {
  37522. if (this.flags) {
  37523. return !this.hasFlag(AnnotationFlag.INVISIBLE) &&
  37524. !this.hasFlag(AnnotationFlag.HIDDEN) &&
  37525. !this.hasFlag(AnnotationFlag.NOVIEW);
  37526. }
  37527. return true;
  37528. },
  37529. /**
  37530. * @return {boolean}
  37531. */
  37532. get printable() {
  37533. if (this.flags) {
  37534. return this.hasFlag(AnnotationFlag.PRINT) &&
  37535. !this.hasFlag(AnnotationFlag.INVISIBLE) &&
  37536. !this.hasFlag(AnnotationFlag.HIDDEN);
  37537. }
  37538. return false;
  37539. },
  37540. /**
  37541. * Set the flags.
  37542. *
  37543. * @public
  37544. * @memberof Annotation
  37545. * @param {number} flags - Unsigned 32-bit integer specifying annotation
  37546. * characteristics
  37547. * @see {@link shared/util.js}
  37548. */
  37549. setFlags: function Annotation_setFlags(flags) {
  37550. if (isInt(flags)) {
  37551. this.flags = flags;
  37552. } else {
  37553. this.flags = 0;
  37554. }
  37555. },
  37556. /**
  37557. * Check if a provided flag is set.
  37558. *
  37559. * @public
  37560. * @memberof Annotation
  37561. * @param {number} flag - Hexadecimal representation for an annotation
  37562. * characteristic
  37563. * @return {boolean}
  37564. * @see {@link shared/util.js}
  37565. */
  37566. hasFlag: function Annotation_hasFlag(flag) {
  37567. if (this.flags) {
  37568. return (this.flags & flag) > 0;
  37569. }
  37570. return false;
  37571. },
  37572. /**
  37573. * Set the rectangle.
  37574. *
  37575. * @public
  37576. * @memberof Annotation
  37577. * @param {Array} rectangle - The rectangle array with exactly four entries
  37578. */
  37579. setRectangle: function Annotation_setRectangle(rectangle) {
  37580. if (isArray(rectangle) && rectangle.length === 4) {
  37581. this.rectangle = Util.normalizeRect(rectangle);
  37582. } else {
  37583. this.rectangle = [0, 0, 0, 0];
  37584. }
  37585. },
  37586. /**
  37587. * Set the color and take care of color space conversion.
  37588. *
  37589. * @public
  37590. * @memberof Annotation
  37591. * @param {Array} color - The color array containing either 0
  37592. * (transparent), 1 (grayscale), 3 (RGB) or
  37593. * 4 (CMYK) elements
  37594. */
  37595. setColor: function Annotation_setColor(color) {
  37596. var rgbColor = new Uint8Array(3); // Black in RGB color space (default)
  37597. if (!isArray(color)) {
  37598. this.color = rgbColor;
  37599. return;
  37600. }
  37601. switch (color.length) {
  37602. case 0: // Transparent, which we indicate with a null value
  37603. this.color = null;
  37604. break;
  37605. case 1: // Convert grayscale to RGB
  37606. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  37607. this.color = rgbColor;
  37608. break;
  37609. case 3: // Convert RGB percentages to RGB
  37610. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  37611. this.color = rgbColor;
  37612. break;
  37613. case 4: // Convert CMYK to RGB
  37614. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  37615. this.color = rgbColor;
  37616. break;
  37617. default:
  37618. this.color = rgbColor;
  37619. break;
  37620. }
  37621. },
  37622. /**
  37623. * Set the border style (as AnnotationBorderStyle object).
  37624. *
  37625. * @public
  37626. * @memberof Annotation
  37627. * @param {Dict} borderStyle - The border style dictionary
  37628. */
  37629. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  37630. this.borderStyle = new AnnotationBorderStyle();
  37631. if (!isDict(borderStyle)) {
  37632. return;
  37633. }
  37634. if (borderStyle.has('BS')) {
  37635. var dict = borderStyle.get('BS');
  37636. var dictType;
  37637. if (!dict.has('Type') || (isName(dictType = dict.get('Type')) &&
  37638. dictType.name === 'Border')) {
  37639. this.borderStyle.setWidth(dict.get('W'));
  37640. this.borderStyle.setStyle(dict.get('S'));
  37641. this.borderStyle.setDashArray(dict.get('D'));
  37642. }
  37643. } else if (borderStyle.has('Border')) {
  37644. var array = borderStyle.get('Border');
  37645. if (isArray(array) && array.length >= 3) {
  37646. this.borderStyle.setHorizontalCornerRadius(array[0]);
  37647. this.borderStyle.setVerticalCornerRadius(array[1]);
  37648. this.borderStyle.setWidth(array[2]);
  37649. if (array.length === 4) { // Dash array available
  37650. this.borderStyle.setDashArray(array[3]);
  37651. }
  37652. }
  37653. } else {
  37654. // There are no border entries in the dictionary. According to the
  37655. // specification, we should draw a solid border of width 1 in that
  37656. // case, but Adobe Reader did not implement that part of the
  37657. // specification and instead draws no border at all, so we do the same.
  37658. // See also https://github.com/mozilla/pdf.js/issues/6179.
  37659. this.borderStyle.setWidth(0);
  37660. }
  37661. },
  37662. /**
  37663. * Prepare the annotation for working with a popup in the display layer.
  37664. *
  37665. * @private
  37666. * @memberof Annotation
  37667. * @param {Dict} dict - The annotation's data dictionary
  37668. */
  37669. _preparePopup: function Annotation_preparePopup(dict) {
  37670. if (!dict.has('C')) {
  37671. // Fall back to the default background color.
  37672. this.data.color = null;
  37673. }
  37674. this.data.hasPopup = dict.has('Popup');
  37675. this.data.title = stringToPDFString(dict.get('T') || '');
  37676. this.data.contents = stringToPDFString(dict.get('Contents') || '');
  37677. },
  37678. loadResources: function Annotation_loadResources(keys) {
  37679. return new Promise(function (resolve, reject) {
  37680. this.appearance.dict.getAsync('Resources').then(function (resources) {
  37681. if (!resources) {
  37682. resolve();
  37683. return;
  37684. }
  37685. var objectLoader = new ObjectLoader(resources.map,
  37686. keys,
  37687. resources.xref);
  37688. objectLoader.load().then(function() {
  37689. resolve(resources);
  37690. }, reject);
  37691. }, reject);
  37692. }.bind(this));
  37693. },
  37694. getOperatorList: function Annotation_getOperatorList(evaluator, task) {
  37695. if (!this.appearance) {
  37696. return Promise.resolve(new OperatorList());
  37697. }
  37698. var data = this.data;
  37699. var appearanceDict = this.appearance.dict;
  37700. var resourcesPromise = this.loadResources([
  37701. 'ExtGState',
  37702. 'ColorSpace',
  37703. 'Pattern',
  37704. 'Shading',
  37705. 'XObject',
  37706. 'Font'
  37707. // ProcSet
  37708. // Properties
  37709. ]);
  37710. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  37711. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  37712. var transform = getTransformMatrix(data.rect, bbox, matrix);
  37713. var self = this;
  37714. return resourcesPromise.then(function(resources) {
  37715. var opList = new OperatorList();
  37716. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  37717. return evaluator.getOperatorList(self.appearance, task,
  37718. resources, opList).
  37719. then(function () {
  37720. opList.addOp(OPS.endAnnotation, []);
  37721. self.appearance.reset();
  37722. return opList;
  37723. });
  37724. });
  37725. }
  37726. };
  37727. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  37728. annotations, opList, partialEvaluator, task, intent) {
  37729. var annotationPromises = [];
  37730. for (var i = 0, n = annotations.length; i < n; ++i) {
  37731. if ((intent === 'display' && annotations[i].viewable) ||
  37732. (intent === 'print' && annotations[i].printable)) {
  37733. annotationPromises.push(
  37734. annotations[i].getOperatorList(partialEvaluator, task));
  37735. }
  37736. }
  37737. return Promise.all(annotationPromises).then(function(operatorLists) {
  37738. opList.addOp(OPS.beginAnnotations, []);
  37739. for (var i = 0, n = operatorLists.length; i < n; ++i) {
  37740. opList.addOpList(operatorLists[i]);
  37741. }
  37742. opList.addOp(OPS.endAnnotations, []);
  37743. });
  37744. };
  37745. return Annotation;
  37746. })();
  37747. /**
  37748. * Contains all data regarding an annotation's border style.
  37749. *
  37750. * @class
  37751. */
  37752. var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() {
  37753. /**
  37754. * @constructor
  37755. * @private
  37756. */
  37757. function AnnotationBorderStyle() {
  37758. this.width = 1;
  37759. this.style = AnnotationBorderStyleType.SOLID;
  37760. this.dashArray = [3];
  37761. this.horizontalCornerRadius = 0;
  37762. this.verticalCornerRadius = 0;
  37763. }
  37764. AnnotationBorderStyle.prototype = {
  37765. /**
  37766. * Set the width.
  37767. *
  37768. * @public
  37769. * @memberof AnnotationBorderStyle
  37770. * @param {integer} width - The width
  37771. */
  37772. setWidth: function AnnotationBorderStyle_setWidth(width) {
  37773. if (width === (width | 0)) {
  37774. this.width = width;
  37775. }
  37776. },
  37777. /**
  37778. * Set the style.
  37779. *
  37780. * @public
  37781. * @memberof AnnotationBorderStyle
  37782. * @param {Object} style - The style object
  37783. * @see {@link shared/util.js}
  37784. */
  37785. setStyle: function AnnotationBorderStyle_setStyle(style) {
  37786. if (!style) {
  37787. return;
  37788. }
  37789. switch (style.name) {
  37790. case 'S':
  37791. this.style = AnnotationBorderStyleType.SOLID;
  37792. break;
  37793. case 'D':
  37794. this.style = AnnotationBorderStyleType.DASHED;
  37795. break;
  37796. case 'B':
  37797. this.style = AnnotationBorderStyleType.BEVELED;
  37798. break;
  37799. case 'I':
  37800. this.style = AnnotationBorderStyleType.INSET;
  37801. break;
  37802. case 'U':
  37803. this.style = AnnotationBorderStyleType.UNDERLINE;
  37804. break;
  37805. default:
  37806. break;
  37807. }
  37808. },
  37809. /**
  37810. * Set the dash array.
  37811. *
  37812. * @public
  37813. * @memberof AnnotationBorderStyle
  37814. * @param {Array} dashArray - The dash array with at least one element
  37815. */
  37816. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  37817. // We validate the dash array, but we do not use it because CSS does not
  37818. // allow us to change spacing of dashes. For more information, visit
  37819. // http://www.w3.org/TR/css3-background/#the-border-style.
  37820. if (isArray(dashArray) && dashArray.length > 0) {
  37821. // According to the PDF specification: the elements in a dashArray
  37822. // shall be numbers that are nonnegative and not all equal to zero.
  37823. var isValid = true;
  37824. var allZeros = true;
  37825. for (var i = 0, len = dashArray.length; i < len; i++) {
  37826. var element = dashArray[i];
  37827. var validNumber = (+element >= 0);
  37828. if (!validNumber) {
  37829. isValid = false;
  37830. break;
  37831. } else if (element > 0) {
  37832. allZeros = false;
  37833. }
  37834. }
  37835. if (isValid && !allZeros) {
  37836. this.dashArray = dashArray;
  37837. } else {
  37838. this.width = 0; // Adobe behavior when the array is invalid.
  37839. }
  37840. } else if (dashArray) {
  37841. this.width = 0; // Adobe behavior when the array is invalid.
  37842. }
  37843. },
  37844. /**
  37845. * Set the horizontal corner radius (from a Border dictionary).
  37846. *
  37847. * @public
  37848. * @memberof AnnotationBorderStyle
  37849. * @param {integer} radius - The horizontal corner radius
  37850. */
  37851. setHorizontalCornerRadius:
  37852. function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  37853. if (radius === (radius | 0)) {
  37854. this.horizontalCornerRadius = radius;
  37855. }
  37856. },
  37857. /**
  37858. * Set the vertical corner radius (from a Border dictionary).
  37859. *
  37860. * @public
  37861. * @memberof AnnotationBorderStyle
  37862. * @param {integer} radius - The vertical corner radius
  37863. */
  37864. setVerticalCornerRadius:
  37865. function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  37866. if (radius === (radius | 0)) {
  37867. this.verticalCornerRadius = radius;
  37868. }
  37869. }
  37870. };
  37871. return AnnotationBorderStyle;
  37872. })();
  37873. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  37874. function WidgetAnnotation(params) {
  37875. Annotation.call(this, params);
  37876. var dict = params.dict;
  37877. var data = this.data;
  37878. data.annotationType = AnnotationType.WIDGET;
  37879. data.fieldValue = stringToPDFString(
  37880. Util.getInheritableProperty(dict, 'V') || '');
  37881. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  37882. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  37883. var fieldType = Util.getInheritableProperty(dict, 'FT');
  37884. data.fieldType = isName(fieldType) ? fieldType.name : '';
  37885. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  37886. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  37887. // Hide unsupported Widget signatures.
  37888. if (data.fieldType === 'Sig') {
  37889. warn('unimplemented annotation type: Widget signature');
  37890. this.setFlags(AnnotationFlag.HIDDEN);
  37891. }
  37892. // Building the full field name by collecting the field and
  37893. // its ancestors 'T' data and joining them using '.'.
  37894. var fieldName = [];
  37895. var namedItem = dict;
  37896. var ref = params.ref;
  37897. while (namedItem) {
  37898. var parent = namedItem.get('Parent');
  37899. var parentRef = namedItem.getRaw('Parent');
  37900. var name = namedItem.get('T');
  37901. if (name) {
  37902. fieldName.unshift(stringToPDFString(name));
  37903. } else if (parent && ref) {
  37904. // The field name is absent, that means more than one field
  37905. // with the same name may exist. Replacing the empty name
  37906. // with the '`' plus index in the parent's 'Kids' array.
  37907. // This is not in the PDF spec but necessary to id the
  37908. // the input controls.
  37909. var kids = parent.get('Kids');
  37910. var j, jj;
  37911. for (j = 0, jj = kids.length; j < jj; j++) {
  37912. var kidRef = kids[j];
  37913. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  37914. break;
  37915. }
  37916. }
  37917. fieldName.unshift('`' + j);
  37918. }
  37919. namedItem = parent;
  37920. ref = parentRef;
  37921. }
  37922. data.fullName = fieldName.join('.');
  37923. }
  37924. Util.inherit(WidgetAnnotation, Annotation, {});
  37925. return WidgetAnnotation;
  37926. })();
  37927. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  37928. function TextWidgetAnnotation(params) {
  37929. WidgetAnnotation.call(this, params);
  37930. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  37931. }
  37932. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  37933. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator,
  37934. task) {
  37935. if (this.appearance) {
  37936. return Annotation.prototype.getOperatorList.call(this, evaluator, task);
  37937. }
  37938. var opList = new OperatorList();
  37939. var data = this.data;
  37940. // Even if there is an appearance stream, ignore it. This is the
  37941. // behaviour used by Adobe Reader.
  37942. if (!data.defaultAppearance) {
  37943. return Promise.resolve(opList);
  37944. }
  37945. var stream = new Stream(stringToBytes(data.defaultAppearance));
  37946. return evaluator.getOperatorList(stream, task,
  37947. this.fieldResources, opList).
  37948. then(function () {
  37949. return opList;
  37950. });
  37951. }
  37952. });
  37953. return TextWidgetAnnotation;
  37954. })();
  37955. var TextAnnotation = (function TextAnnotationClosure() {
  37956. var DEFAULT_ICON_SIZE = 22; // px
  37957. function TextAnnotation(parameters) {
  37958. Annotation.call(this, parameters);
  37959. this.data.annotationType = AnnotationType.TEXT;
  37960. if (this.data.hasAppearance) {
  37961. this.data.name = 'NoIcon';
  37962. } else {
  37963. this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE;
  37964. this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE;
  37965. this.data.name = parameters.dict.has('Name') ?
  37966. parameters.dict.get('Name').name : 'Note';
  37967. }
  37968. this._preparePopup(parameters.dict);
  37969. }
  37970. Util.inherit(TextAnnotation, Annotation, {});
  37971. return TextAnnotation;
  37972. })();
  37973. var LinkAnnotation = (function LinkAnnotationClosure() {
  37974. function LinkAnnotation(params) {
  37975. Annotation.call(this, params);
  37976. var dict = params.dict;
  37977. var data = this.data;
  37978. data.annotationType = AnnotationType.LINK;
  37979. var action = dict.get('A');
  37980. if (action && isDict(action)) {
  37981. var linkType = action.get('S').name;
  37982. if (linkType === 'URI') {
  37983. var url = action.get('URI');
  37984. if (isName(url)) {
  37985. // Some bad PDFs do not put parentheses around relative URLs.
  37986. url = '/' + url.name;
  37987. } else if (url) {
  37988. url = addDefaultProtocolToUrl(url);
  37989. }
  37990. // TODO: pdf spec mentions urls can be relative to a Base
  37991. // entry in the dictionary.
  37992. if (!isValidUrl(url, false)) {
  37993. url = '';
  37994. }
  37995. // According to ISO 32000-1:2008, section 12.6.4.7,
  37996. // URI should to be encoded in 7-bit ASCII.
  37997. // Some bad PDFs may have URIs in UTF-8 encoding, see Bugzilla 1122280.
  37998. try {
  37999. data.url = stringToUTF8String(url);
  38000. } catch (e) {
  38001. // Fall back to a simple copy.
  38002. data.url = url;
  38003. }
  38004. } else if (linkType === 'GoTo') {
  38005. data.dest = action.get('D');
  38006. } else if (linkType === 'GoToR') {
  38007. var urlDict = action.get('F');
  38008. if (isDict(urlDict)) {
  38009. // We assume that the 'url' is a Filspec dictionary
  38010. // and fetch the url without checking any further
  38011. url = urlDict.get('F') || '';
  38012. }
  38013. // TODO: pdf reference says that GoToR
  38014. // can also have 'NewWindow' attribute
  38015. if (!isValidUrl(url, false)) {
  38016. url = '';
  38017. }
  38018. data.url = url;
  38019. data.dest = action.get('D');
  38020. } else if (linkType === 'Named') {
  38021. data.action = action.get('N').name;
  38022. } else {
  38023. warn('unrecognized link type: ' + linkType);
  38024. }
  38025. } else if (dict.has('Dest')) {
  38026. // simple destination link
  38027. var dest = dict.get('Dest');
  38028. data.dest = isName(dest) ? dest.name : dest;
  38029. }
  38030. }
  38031. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  38032. function addDefaultProtocolToUrl(url) {
  38033. if (url && url.indexOf('www.') === 0) {
  38034. return ('http://' + url);
  38035. }
  38036. return url;
  38037. }
  38038. Util.inherit(LinkAnnotation, Annotation, {});
  38039. return LinkAnnotation;
  38040. })();
  38041. var PopupAnnotation = (function PopupAnnotationClosure() {
  38042. function PopupAnnotation(parameters) {
  38043. Annotation.call(this, parameters);
  38044. this.data.annotationType = AnnotationType.POPUP;
  38045. var dict = parameters.dict;
  38046. var parentItem = dict.get('Parent');
  38047. if (!parentItem) {
  38048. warn('Popup annotation has a missing or invalid parent annotation.');
  38049. return;
  38050. }
  38051. this.data.parentId = dict.getRaw('Parent').toString();
  38052. this.data.title = stringToPDFString(parentItem.get('T') || '');
  38053. this.data.contents = stringToPDFString(parentItem.get('Contents') || '');
  38054. if (!parentItem.has('C')) {
  38055. // Fall back to the default background color.
  38056. this.data.color = null;
  38057. } else {
  38058. this.setColor(parentItem.get('C'));
  38059. this.data.color = this.color;
  38060. }
  38061. }
  38062. Util.inherit(PopupAnnotation, Annotation, {});
  38063. return PopupAnnotation;
  38064. })();
  38065. var HighlightAnnotation = (function HighlightAnnotationClosure() {
  38066. function HighlightAnnotation(parameters) {
  38067. Annotation.call(this, parameters);
  38068. this.data.annotationType = AnnotationType.HIGHLIGHT;
  38069. this._preparePopup(parameters.dict);
  38070. // PDF viewers completely ignore any border styles.
  38071. this.data.borderStyle.setWidth(0);
  38072. }
  38073. Util.inherit(HighlightAnnotation, Annotation, {});
  38074. return HighlightAnnotation;
  38075. })();
  38076. var UnderlineAnnotation = (function UnderlineAnnotationClosure() {
  38077. function UnderlineAnnotation(parameters) {
  38078. Annotation.call(this, parameters);
  38079. this.data.annotationType = AnnotationType.UNDERLINE;
  38080. this._preparePopup(parameters.dict);
  38081. // PDF viewers completely ignore any border styles.
  38082. this.data.borderStyle.setWidth(0);
  38083. }
  38084. Util.inherit(UnderlineAnnotation, Annotation, {});
  38085. return UnderlineAnnotation;
  38086. })();
  38087. var SquigglyAnnotation = (function SquigglyAnnotationClosure() {
  38088. function SquigglyAnnotation(parameters) {
  38089. Annotation.call(this, parameters);
  38090. this.data.annotationType = AnnotationType.SQUIGGLY;
  38091. this._preparePopup(parameters.dict);
  38092. // PDF viewers completely ignore any border styles.
  38093. this.data.borderStyle.setWidth(0);
  38094. }
  38095. Util.inherit(SquigglyAnnotation, Annotation, {});
  38096. return SquigglyAnnotation;
  38097. })();
  38098. var StrikeOutAnnotation = (function StrikeOutAnnotationClosure() {
  38099. function StrikeOutAnnotation(parameters) {
  38100. Annotation.call(this, parameters);
  38101. this.data.annotationType = AnnotationType.STRIKEOUT;
  38102. this._preparePopup(parameters.dict);
  38103. // PDF viewers completely ignore any border styles.
  38104. this.data.borderStyle.setWidth(0);
  38105. }
  38106. Util.inherit(StrikeOutAnnotation, Annotation, {});
  38107. return StrikeOutAnnotation;
  38108. })();
  38109. var FileAttachmentAnnotation = (function FileAttachmentAnnotationClosure() {
  38110. function FileAttachmentAnnotation(parameters) {
  38111. Annotation.call(this, parameters);
  38112. var file = new FileSpec(parameters.dict.get('FS'), parameters.xref);
  38113. this.data.annotationType = AnnotationType.FILEATTACHMENT;
  38114. this.data.file = file.serializable;
  38115. this._preparePopup(parameters.dict);
  38116. }
  38117. Util.inherit(FileAttachmentAnnotation, Annotation, {});
  38118. return FileAttachmentAnnotation;
  38119. })();
  38120. exports.Annotation = Annotation;
  38121. exports.AnnotationBorderStyle = AnnotationBorderStyle;
  38122. exports.AnnotationFactory = AnnotationFactory;
  38123. }));
  38124. (function (root, factory) {
  38125. {
  38126. factory((root.pdfjsCoreDocument = {}), root.pdfjsSharedUtil,
  38127. root.pdfjsCorePrimitives, root.pdfjsCoreStream,
  38128. root.pdfjsCoreObj, root.pdfjsCoreParser, root.pdfjsCoreCrypto,
  38129. root.pdfjsCoreEvaluator, root.pdfjsCoreAnnotation);
  38130. }
  38131. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreObj,
  38132. coreParser, coreCrypto, coreEvaluator, coreAnnotation) {
  38133. var MissingDataException = sharedUtil.MissingDataException;
  38134. var Util = sharedUtil.Util;
  38135. var assert = sharedUtil.assert;
  38136. var error = sharedUtil.error;
  38137. var info = sharedUtil.info;
  38138. var isArray = sharedUtil.isArray;
  38139. var isArrayBuffer = sharedUtil.isArrayBuffer;
  38140. var isString = sharedUtil.isString;
  38141. var shadow = sharedUtil.shadow;
  38142. var stringToBytes = sharedUtil.stringToBytes;
  38143. var stringToPDFString = sharedUtil.stringToPDFString;
  38144. var warn = sharedUtil.warn;
  38145. var Dict = corePrimitives.Dict;
  38146. var isDict = corePrimitives.isDict;
  38147. var isName = corePrimitives.isName;
  38148. var isStream = corePrimitives.isStream;
  38149. var NullStream = coreStream.NullStream;
  38150. var Stream = coreStream.Stream;
  38151. var StreamsSequenceStream = coreStream.StreamsSequenceStream;
  38152. var Catalog = coreObj.Catalog;
  38153. var ObjectLoader = coreObj.ObjectLoader;
  38154. var XRef = coreObj.XRef;
  38155. var Lexer = coreParser.Lexer;
  38156. var Linearization = coreParser.Linearization;
  38157. var calculateMD5 = coreCrypto.calculateMD5;
  38158. var OperatorList = coreEvaluator.OperatorList;
  38159. var PartialEvaluator = coreEvaluator.PartialEvaluator;
  38160. var Annotation = coreAnnotation.Annotation;
  38161. var AnnotationFactory = coreAnnotation.AnnotationFactory;
  38162. var Page = (function PageClosure() {
  38163. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  38164. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  38165. this.pdfManager = pdfManager;
  38166. this.pageIndex = pageIndex;
  38167. this.pageDict = pageDict;
  38168. this.xref = xref;
  38169. this.ref = ref;
  38170. this.fontCache = fontCache;
  38171. this.idCounters = {
  38172. obj: 0
  38173. };
  38174. this.resourcesPromise = null;
  38175. }
  38176. Page.prototype = {
  38177. getPageProp: function Page_getPageProp(key) {
  38178. return this.pageDict.get(key);
  38179. },
  38180. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  38181. var dict = this.pageDict, valueArray = null, loopCount = 0;
  38182. var MAX_LOOP_COUNT = 100;
  38183. // Always walk up the entire parent chain, to be able to find
  38184. // e.g. \Resources placed on multiple levels of the tree.
  38185. while (dict) {
  38186. var value = dict.get(key);
  38187. if (value) {
  38188. if (!valueArray) {
  38189. valueArray = [];
  38190. }
  38191. valueArray.push(value);
  38192. }
  38193. if (++loopCount > MAX_LOOP_COUNT) {
  38194. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  38195. break;
  38196. }
  38197. dict = dict.get('Parent');
  38198. }
  38199. if (!valueArray) {
  38200. return Dict.empty;
  38201. }
  38202. if (valueArray.length === 1 || !isDict(valueArray[0]) ||
  38203. loopCount > MAX_LOOP_COUNT) {
  38204. return valueArray[0];
  38205. }
  38206. return Dict.merge(this.xref, valueArray);
  38207. },
  38208. get content() {
  38209. return this.getPageProp('Contents');
  38210. },
  38211. get resources() {
  38212. // For robustness: The spec states that a \Resources entry has to be
  38213. // present, but can be empty. Some document omit it still, in this case
  38214. // we return an empty dictionary.
  38215. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  38216. },
  38217. get mediaBox() {
  38218. var obj = this.getInheritedPageProp('MediaBox');
  38219. // Reset invalid media box to letter size.
  38220. if (!isArray(obj) || obj.length !== 4) {
  38221. obj = LETTER_SIZE_MEDIABOX;
  38222. }
  38223. return shadow(this, 'mediaBox', obj);
  38224. },
  38225. get view() {
  38226. var mediaBox = this.mediaBox;
  38227. var cropBox = this.getInheritedPageProp('CropBox');
  38228. if (!isArray(cropBox) || cropBox.length !== 4) {
  38229. return shadow(this, 'view', mediaBox);
  38230. }
  38231. // From the spec, 6th ed., p.963:
  38232. // "The crop, bleed, trim, and art boxes should not ordinarily
  38233. // extend beyond the boundaries of the media box. If they do, they are
  38234. // effectively reduced to their intersection with the media box."
  38235. cropBox = Util.intersect(cropBox, mediaBox);
  38236. if (!cropBox) {
  38237. return shadow(this, 'view', mediaBox);
  38238. }
  38239. return shadow(this, 'view', cropBox);
  38240. },
  38241. get rotate() {
  38242. var rotate = this.getInheritedPageProp('Rotate') || 0;
  38243. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  38244. if (rotate % 90 !== 0) {
  38245. rotate = 0;
  38246. } else if (rotate >= 360) {
  38247. rotate = rotate % 360;
  38248. } else if (rotate < 0) {
  38249. // The spec doesn't cover negatives, assume its counterclockwise
  38250. // rotation. The following is the other implementation of modulo.
  38251. rotate = ((rotate % 360) + 360) % 360;
  38252. }
  38253. return shadow(this, 'rotate', rotate);
  38254. },
  38255. getContentStream: function Page_getContentStream() {
  38256. var content = this.content;
  38257. var stream;
  38258. if (isArray(content)) {
  38259. // fetching items
  38260. var xref = this.xref;
  38261. var i, n = content.length;
  38262. var streams = [];
  38263. for (i = 0; i < n; ++i) {
  38264. streams.push(xref.fetchIfRef(content[i]));
  38265. }
  38266. stream = new StreamsSequenceStream(streams);
  38267. } else if (isStream(content)) {
  38268. stream = content;
  38269. } else {
  38270. // replacing non-existent page content with empty one
  38271. stream = new NullStream();
  38272. }
  38273. return stream;
  38274. },
  38275. loadResources: function Page_loadResources(keys) {
  38276. if (!this.resourcesPromise) {
  38277. // TODO: add async getInheritedPageProp and remove this.
  38278. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  38279. }
  38280. return this.resourcesPromise.then(function resourceSuccess() {
  38281. var objectLoader = new ObjectLoader(this.resources.map,
  38282. keys,
  38283. this.xref);
  38284. return objectLoader.load();
  38285. }.bind(this));
  38286. },
  38287. getOperatorList: function Page_getOperatorList(handler, task, intent) {
  38288. var self = this;
  38289. var pdfManager = this.pdfManager;
  38290. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  38291. []);
  38292. var resourcesPromise = this.loadResources([
  38293. 'ExtGState',
  38294. 'ColorSpace',
  38295. 'Pattern',
  38296. 'Shading',
  38297. 'XObject',
  38298. 'Font'
  38299. // ProcSet
  38300. // Properties
  38301. ]);
  38302. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  38303. handler, this.pageIndex,
  38304. 'p' + this.pageIndex + '_',
  38305. this.idCounters,
  38306. this.fontCache);
  38307. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  38308. var pageListPromise = dataPromises.then(function(data) {
  38309. var contentStream = data[0];
  38310. var opList = new OperatorList(intent, handler, self.pageIndex);
  38311. handler.send('StartRenderPage', {
  38312. transparency: partialEvaluator.hasBlendModes(self.resources),
  38313. pageIndex: self.pageIndex,
  38314. intent: intent
  38315. });
  38316. return partialEvaluator.getOperatorList(contentStream, task,
  38317. self.resources, opList).then(function () {
  38318. return opList;
  38319. });
  38320. });
  38321. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  38322. return Promise.all([pageListPromise, annotationsPromise]).then(
  38323. function(datas) {
  38324. var pageOpList = datas[0];
  38325. var annotations = datas[1];
  38326. if (annotations.length === 0) {
  38327. pageOpList.flush(true);
  38328. return pageOpList;
  38329. }
  38330. var annotationsReadyPromise = Annotation.appendToOperatorList(
  38331. annotations, pageOpList, partialEvaluator, task, intent);
  38332. return annotationsReadyPromise.then(function () {
  38333. pageOpList.flush(true);
  38334. return pageOpList;
  38335. });
  38336. });
  38337. },
  38338. extractTextContent: function Page_extractTextContent(task,
  38339. normalizeWhitespace) {
  38340. var handler = {
  38341. on: function nullHandlerOn() {},
  38342. send: function nullHandlerSend() {}
  38343. };
  38344. var self = this;
  38345. var pdfManager = this.pdfManager;
  38346. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  38347. []);
  38348. var resourcesPromise = this.loadResources([
  38349. 'ExtGState',
  38350. 'XObject',
  38351. 'Font'
  38352. ]);
  38353. var dataPromises = Promise.all([contentStreamPromise,
  38354. resourcesPromise]);
  38355. return dataPromises.then(function(data) {
  38356. var contentStream = data[0];
  38357. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  38358. handler, self.pageIndex,
  38359. 'p' + self.pageIndex + '_',
  38360. self.idCounters,
  38361. self.fontCache);
  38362. return partialEvaluator.getTextContent(contentStream,
  38363. task,
  38364. self.resources,
  38365. /* stateManager = */ null,
  38366. normalizeWhitespace);
  38367. });
  38368. },
  38369. getAnnotationsData: function Page_getAnnotationsData(intent) {
  38370. var annotations = this.annotations;
  38371. var annotationsData = [];
  38372. for (var i = 0, n = annotations.length; i < n; ++i) {
  38373. if (intent) {
  38374. if (!(intent === 'display' && annotations[i].viewable) &&
  38375. !(intent === 'print' && annotations[i].printable)) {
  38376. continue;
  38377. }
  38378. }
  38379. annotationsData.push(annotations[i].data);
  38380. }
  38381. return annotationsData;
  38382. },
  38383. get annotations() {
  38384. var annotations = [];
  38385. var annotationRefs = this.getInheritedPageProp('Annots') || [];
  38386. var annotationFactory = new AnnotationFactory();
  38387. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  38388. var annotationRef = annotationRefs[i];
  38389. var annotation = annotationFactory.create(this.xref, annotationRef);
  38390. if (annotation) {
  38391. annotations.push(annotation);
  38392. }
  38393. }
  38394. return shadow(this, 'annotations', annotations);
  38395. }
  38396. };
  38397. return Page;
  38398. })();
  38399. /**
  38400. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  38401. * `PDFDoc`, this one doesn't have any job management code.
  38402. * Right now there exists one PDFDocument on the main thread + one object
  38403. * for each worker. If there is no worker support enabled, there are two
  38404. * `PDFDocument` objects on the main thread created.
  38405. */
  38406. var PDFDocument = (function PDFDocumentClosure() {
  38407. var FINGERPRINT_FIRST_BYTES = 1024;
  38408. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  38409. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  38410. function PDFDocument(pdfManager, arg, password) {
  38411. if (isStream(arg)) {
  38412. init.call(this, pdfManager, arg, password);
  38413. } else if (isArrayBuffer(arg)) {
  38414. init.call(this, pdfManager, new Stream(arg), password);
  38415. } else {
  38416. error('PDFDocument: Unknown argument type');
  38417. }
  38418. }
  38419. function init(pdfManager, stream, password) {
  38420. assert(stream.length > 0, 'stream must have data');
  38421. this.pdfManager = pdfManager;
  38422. this.stream = stream;
  38423. var xref = new XRef(this.stream, password, pdfManager);
  38424. this.xref = xref;
  38425. }
  38426. function find(stream, needle, limit, backwards) {
  38427. var pos = stream.pos;
  38428. var end = stream.end;
  38429. var strBuf = [];
  38430. if (pos + limit > end) {
  38431. limit = end - pos;
  38432. }
  38433. for (var n = 0; n < limit; ++n) {
  38434. strBuf.push(String.fromCharCode(stream.getByte()));
  38435. }
  38436. var str = strBuf.join('');
  38437. stream.pos = pos;
  38438. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  38439. if (index === -1) {
  38440. return false; /* not found */
  38441. }
  38442. stream.pos += index;
  38443. return true; /* found */
  38444. }
  38445. var DocumentInfoValidators = {
  38446. get entries() {
  38447. // Lazily build this since all the validation functions below are not
  38448. // defined until after this file loads.
  38449. return shadow(this, 'entries', {
  38450. Title: isString,
  38451. Author: isString,
  38452. Subject: isString,
  38453. Keywords: isString,
  38454. Creator: isString,
  38455. Producer: isString,
  38456. CreationDate: isString,
  38457. ModDate: isString,
  38458. Trapped: isName
  38459. });
  38460. }
  38461. };
  38462. PDFDocument.prototype = {
  38463. parse: function PDFDocument_parse(recoveryMode) {
  38464. this.setup(recoveryMode);
  38465. var version = this.catalog.catDict.get('Version');
  38466. if (isName(version)) {
  38467. this.pdfFormatVersion = version.name;
  38468. }
  38469. try {
  38470. // checking if AcroForm is present
  38471. this.acroForm = this.catalog.catDict.get('AcroForm');
  38472. if (this.acroForm) {
  38473. this.xfa = this.acroForm.get('XFA');
  38474. var fields = this.acroForm.get('Fields');
  38475. if ((!fields || !isArray(fields) || fields.length === 0) &&
  38476. !this.xfa) {
  38477. // no fields and no XFA -- not a form (?)
  38478. this.acroForm = null;
  38479. }
  38480. }
  38481. } catch (ex) {
  38482. info('Something wrong with AcroForm entry');
  38483. this.acroForm = null;
  38484. }
  38485. },
  38486. get linearization() {
  38487. var linearization = null;
  38488. if (this.stream.length) {
  38489. try {
  38490. linearization = Linearization.create(this.stream);
  38491. } catch (err) {
  38492. if (err instanceof MissingDataException) {
  38493. throw err;
  38494. }
  38495. info(err);
  38496. }
  38497. }
  38498. // shadow the prototype getter with a data property
  38499. return shadow(this, 'linearization', linearization);
  38500. },
  38501. get startXRef() {
  38502. var stream = this.stream;
  38503. var startXRef = 0;
  38504. var linearization = this.linearization;
  38505. if (linearization) {
  38506. // Find end of first obj.
  38507. stream.reset();
  38508. if (find(stream, 'endobj', 1024)) {
  38509. startXRef = stream.pos + 6;
  38510. }
  38511. } else {
  38512. // Find startxref by jumping backward from the end of the file.
  38513. var step = 1024;
  38514. var found = false, pos = stream.end;
  38515. while (!found && pos > 0) {
  38516. pos -= step - 'startxref'.length;
  38517. if (pos < 0) {
  38518. pos = 0;
  38519. }
  38520. stream.pos = pos;
  38521. found = find(stream, 'startxref', step, true);
  38522. }
  38523. if (found) {
  38524. stream.skip(9);
  38525. var ch;
  38526. do {
  38527. ch = stream.getByte();
  38528. } while (Lexer.isSpace(ch));
  38529. var str = '';
  38530. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  38531. str += String.fromCharCode(ch);
  38532. ch = stream.getByte();
  38533. }
  38534. startXRef = parseInt(str, 10);
  38535. if (isNaN(startXRef)) {
  38536. startXRef = 0;
  38537. }
  38538. }
  38539. }
  38540. // shadow the prototype getter with a data property
  38541. return shadow(this, 'startXRef', startXRef);
  38542. },
  38543. get mainXRefEntriesOffset() {
  38544. var mainXRefEntriesOffset = 0;
  38545. var linearization = this.linearization;
  38546. if (linearization) {
  38547. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  38548. }
  38549. // shadow the prototype getter with a data property
  38550. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  38551. },
  38552. // Find the header, remove leading garbage and setup the stream
  38553. // starting from the header.
  38554. checkHeader: function PDFDocument_checkHeader() {
  38555. var stream = this.stream;
  38556. stream.reset();
  38557. if (find(stream, '%PDF-', 1024)) {
  38558. // Found the header, trim off any garbage before it.
  38559. stream.moveStart();
  38560. // Reading file format version
  38561. var MAX_VERSION_LENGTH = 12;
  38562. var version = '', ch;
  38563. while ((ch = stream.getByte()) > 0x20) { // SPACE
  38564. if (version.length >= MAX_VERSION_LENGTH) {
  38565. break;
  38566. }
  38567. version += String.fromCharCode(ch);
  38568. }
  38569. if (!this.pdfFormatVersion) {
  38570. // removing "%PDF-"-prefix
  38571. this.pdfFormatVersion = version.substring(5);
  38572. }
  38573. return;
  38574. }
  38575. // May not be a PDF file, continue anyway.
  38576. },
  38577. parseStartXRef: function PDFDocument_parseStartXRef() {
  38578. var startXRef = this.startXRef;
  38579. this.xref.setStartXRef(startXRef);
  38580. },
  38581. setup: function PDFDocument_setup(recoveryMode) {
  38582. this.xref.parse(recoveryMode);
  38583. var self = this;
  38584. var pageFactory = {
  38585. createPage: function (pageIndex, dict, ref, fontCache) {
  38586. return new Page(self.pdfManager, self.xref, pageIndex, dict, ref,
  38587. fontCache);
  38588. }
  38589. };
  38590. this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);
  38591. },
  38592. get numPages() {
  38593. var linearization = this.linearization;
  38594. var num = linearization ? linearization.numPages : this.catalog.numPages;
  38595. // shadow the prototype getter
  38596. return shadow(this, 'numPages', num);
  38597. },
  38598. get documentInfo() {
  38599. var docInfo = {
  38600. PDFFormatVersion: this.pdfFormatVersion,
  38601. IsAcroFormPresent: !!this.acroForm,
  38602. IsXFAPresent: !!this.xfa
  38603. };
  38604. var infoDict;
  38605. try {
  38606. infoDict = this.xref.trailer.get('Info');
  38607. } catch (err) {
  38608. info('The document information dictionary is invalid.');
  38609. }
  38610. if (infoDict) {
  38611. var validEntries = DocumentInfoValidators.entries;
  38612. // Only fill the document info with valid entries from the spec.
  38613. for (var key in validEntries) {
  38614. if (infoDict.has(key)) {
  38615. var value = infoDict.get(key);
  38616. // Make sure the value conforms to the spec.
  38617. if (validEntries[key](value)) {
  38618. docInfo[key] = (typeof value !== 'string' ?
  38619. value : stringToPDFString(value));
  38620. } else {
  38621. info('Bad value in document info for "' + key + '"');
  38622. }
  38623. }
  38624. }
  38625. }
  38626. return shadow(this, 'documentInfo', docInfo);
  38627. },
  38628. get fingerprint() {
  38629. var xref = this.xref, hash, fileID = '';
  38630. var idArray = xref.trailer.get('ID');
  38631. if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) &&
  38632. idArray[0] !== EMPTY_FINGERPRINT) {
  38633. hash = stringToBytes(idArray[0]);
  38634. } else {
  38635. if (this.stream.ensureRange) {
  38636. this.stream.ensureRange(0,
  38637. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  38638. }
  38639. hash = calculateMD5(this.stream.bytes.subarray(0,
  38640. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  38641. }
  38642. for (var i = 0, n = hash.length; i < n; i++) {
  38643. var hex = hash[i].toString(16);
  38644. fileID += hex.length === 1 ? '0' + hex : hex;
  38645. }
  38646. return shadow(this, 'fingerprint', fileID);
  38647. },
  38648. getPage: function PDFDocument_getPage(pageIndex) {
  38649. return this.catalog.getPage(pageIndex);
  38650. },
  38651. cleanup: function PDFDocument_cleanup() {
  38652. return this.catalog.cleanup();
  38653. }
  38654. };
  38655. return PDFDocument;
  38656. })();
  38657. exports.Page = Page;
  38658. exports.PDFDocument = PDFDocument;
  38659. }));
  38660. (function (root, factory) {
  38661. {
  38662. factory((root.pdfjsCorePdfManager = {}), root.pdfjsSharedUtil,
  38663. root.pdfjsCoreStream, root.pdfjsCoreChunkedStream,
  38664. root.pdfjsCoreDocument);
  38665. }
  38666. }(this, function (exports, sharedUtil, coreStream, coreChunkedStream,
  38667. coreDocument) {
  38668. var NotImplementedException = sharedUtil.NotImplementedException;
  38669. var MissingDataException = sharedUtil.MissingDataException;
  38670. var createPromiseCapability = sharedUtil.createPromiseCapability;
  38671. var Util = sharedUtil.Util;
  38672. var Stream = coreStream.Stream;
  38673. var ChunkedStreamManager = coreChunkedStream.ChunkedStreamManager;
  38674. var PDFDocument = coreDocument.PDFDocument;
  38675. var BasePdfManager = (function BasePdfManagerClosure() {
  38676. function BasePdfManager() {
  38677. throw new Error('Cannot initialize BaseManagerManager');
  38678. }
  38679. BasePdfManager.prototype = {
  38680. get docId() {
  38681. return this._docId;
  38682. },
  38683. onLoadedStream: function BasePdfManager_onLoadedStream() {
  38684. throw new NotImplementedException();
  38685. },
  38686. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  38687. return this.ensure(this.pdfDocument, prop, args);
  38688. },
  38689. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  38690. return this.ensure(this.pdfDocument.xref, prop, args);
  38691. },
  38692. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  38693. return this.ensure(this.pdfDocument.catalog, prop, args);
  38694. },
  38695. getPage: function BasePdfManager_getPage(pageIndex) {
  38696. return this.pdfDocument.getPage(pageIndex);
  38697. },
  38698. cleanup: function BasePdfManager_cleanup() {
  38699. return this.pdfDocument.cleanup();
  38700. },
  38701. ensure: function BasePdfManager_ensure(obj, prop, args) {
  38702. return new NotImplementedException();
  38703. },
  38704. requestRange: function BasePdfManager_requestRange(begin, end) {
  38705. return new NotImplementedException();
  38706. },
  38707. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  38708. return new NotImplementedException();
  38709. },
  38710. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  38711. return new NotImplementedException();
  38712. },
  38713. updatePassword: function BasePdfManager_updatePassword(password) {
  38714. this.pdfDocument.xref.password = this.password = password;
  38715. if (this._passwordChangedCapability) {
  38716. this._passwordChangedCapability.resolve();
  38717. }
  38718. },
  38719. passwordChanged: function BasePdfManager_passwordChanged() {
  38720. this._passwordChangedCapability = createPromiseCapability();
  38721. return this._passwordChangedCapability.promise;
  38722. },
  38723. terminate: function BasePdfManager_terminate() {
  38724. return new NotImplementedException();
  38725. }
  38726. };
  38727. return BasePdfManager;
  38728. })();
  38729. var LocalPdfManager = (function LocalPdfManagerClosure() {
  38730. function LocalPdfManager(docId, data, password) {
  38731. this._docId = docId;
  38732. var stream = new Stream(data);
  38733. this.pdfDocument = new PDFDocument(this, stream, password);
  38734. this._loadedStreamCapability = createPromiseCapability();
  38735. this._loadedStreamCapability.resolve(stream);
  38736. }
  38737. Util.inherit(LocalPdfManager, BasePdfManager, {
  38738. ensure: function LocalPdfManager_ensure(obj, prop, args) {
  38739. return new Promise(function (resolve, reject) {
  38740. try {
  38741. var value = obj[prop];
  38742. var result;
  38743. if (typeof value === 'function') {
  38744. result = value.apply(obj, args);
  38745. } else {
  38746. result = value;
  38747. }
  38748. resolve(result);
  38749. } catch (e) {
  38750. reject(e);
  38751. }
  38752. });
  38753. },
  38754. requestRange: function LocalPdfManager_requestRange(begin, end) {
  38755. return Promise.resolve();
  38756. },
  38757. requestLoadedStream: function LocalPdfManager_requestLoadedStream() {
  38758. return;
  38759. },
  38760. onLoadedStream: function LocalPdfManager_onLoadedStream() {
  38761. return this._loadedStreamCapability.promise;
  38762. },
  38763. terminate: function LocalPdfManager_terminate() {
  38764. return;
  38765. }
  38766. });
  38767. return LocalPdfManager;
  38768. })();
  38769. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  38770. function NetworkPdfManager(docId, pdfNetworkStream, args) {
  38771. this._docId = docId;
  38772. this.msgHandler = args.msgHandler;
  38773. var params = {
  38774. msgHandler: args.msgHandler,
  38775. url: args.url,
  38776. length: args.length,
  38777. disableAutoFetch: args.disableAutoFetch,
  38778. rangeChunkSize: args.rangeChunkSize
  38779. };
  38780. this.streamManager = new ChunkedStreamManager(pdfNetworkStream, params);
  38781. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  38782. args.password);
  38783. }
  38784. Util.inherit(NetworkPdfManager, BasePdfManager, {
  38785. ensure: function NetworkPdfManager_ensure(obj, prop, args) {
  38786. var pdfManager = this;
  38787. return new Promise(function (resolve, reject) {
  38788. function ensureHelper() {
  38789. try {
  38790. var result;
  38791. var value = obj[prop];
  38792. if (typeof value === 'function') {
  38793. result = value.apply(obj, args);
  38794. } else {
  38795. result = value;
  38796. }
  38797. resolve(result);
  38798. } catch(e) {
  38799. if (!(e instanceof MissingDataException)) {
  38800. reject(e);
  38801. return;
  38802. }
  38803. pdfManager.streamManager.requestRange(e.begin, e.end).
  38804. then(ensureHelper, reject);
  38805. }
  38806. }
  38807. ensureHelper();
  38808. });
  38809. },
  38810. requestRange: function NetworkPdfManager_requestRange(begin, end) {
  38811. return this.streamManager.requestRange(begin, end);
  38812. },
  38813. requestLoadedStream: function NetworkPdfManager_requestLoadedStream() {
  38814. this.streamManager.requestAllChunks();
  38815. },
  38816. sendProgressiveData:
  38817. function NetworkPdfManager_sendProgressiveData(chunk) {
  38818. this.streamManager.onReceiveData({ chunk: chunk });
  38819. },
  38820. onLoadedStream: function NetworkPdfManager_onLoadedStream() {
  38821. return this.streamManager.onLoadedStream();
  38822. },
  38823. terminate: function NetworkPdfManager_terminate() {
  38824. this.streamManager.abort();
  38825. }
  38826. });
  38827. return NetworkPdfManager;
  38828. })();
  38829. exports.LocalPdfManager = LocalPdfManager;
  38830. exports.NetworkPdfManager = NetworkPdfManager;
  38831. }));
  38832. (function (root, factory) {
  38833. {
  38834. factory((root.pdfjsCoreWorker = {}), root.pdfjsSharedUtil,
  38835. root.pdfjsCorePrimitives, root.pdfjsCorePdfManager,
  38836. root.pdfjsSharedGlobal);
  38837. }
  38838. }(this, function (exports, sharedUtil, corePrimitives, corePdfManager,
  38839. sharedGlobal) {
  38840. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  38841. var InvalidPDFException = sharedUtil.InvalidPDFException;
  38842. var MessageHandler = sharedUtil.MessageHandler;
  38843. var MissingPDFException = sharedUtil.MissingPDFException;
  38844. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  38845. var PasswordException = sharedUtil.PasswordException;
  38846. var PasswordResponses = sharedUtil.PasswordResponses;
  38847. var UnknownErrorException = sharedUtil.UnknownErrorException;
  38848. var XRefParseException = sharedUtil.XRefParseException;
  38849. var arrayByteLength = sharedUtil.arrayByteLength;
  38850. var arraysToBytes = sharedUtil.arraysToBytes;
  38851. var assert = sharedUtil.assert;
  38852. var createPromiseCapability = sharedUtil.createPromiseCapability;
  38853. var error = sharedUtil.error;
  38854. var info = sharedUtil.info;
  38855. var warn = sharedUtil.warn;
  38856. var Ref = corePrimitives.Ref;
  38857. var LocalPdfManager = corePdfManager.LocalPdfManager;
  38858. var NetworkPdfManager = corePdfManager.NetworkPdfManager;
  38859. var globalScope = sharedGlobal.globalScope;
  38860. var PDFJS = sharedGlobal.PDFJS;
  38861. var WorkerTask = (function WorkerTaskClosure() {
  38862. function WorkerTask(name) {
  38863. this.name = name;
  38864. this.terminated = false;
  38865. this._capability = createPromiseCapability();
  38866. }
  38867. WorkerTask.prototype = {
  38868. get finished() {
  38869. return this._capability.promise;
  38870. },
  38871. finish: function () {
  38872. this._capability.resolve();
  38873. },
  38874. terminate: function () {
  38875. this.terminated = true;
  38876. },
  38877. ensureNotTerminated: function () {
  38878. if (this.terminated) {
  38879. throw new Error('Worker task was terminated');
  38880. }
  38881. }
  38882. };
  38883. return WorkerTask;
  38884. })();
  38885. /** @implements {IPDFStream} */
  38886. var PDFWorkerStream = (function PDFWorkerStreamClosure() {
  38887. function PDFWorkerStream(params, msgHandler) {
  38888. this._queuedChunks = [];
  38889. var initialData = params.initialData;
  38890. if (initialData && initialData.length > 0) {
  38891. this._queuedChunks.push(initialData);
  38892. }
  38893. this._msgHandler = msgHandler;
  38894. this._isRangeSupported = !(params.disableRange);
  38895. this._isStreamingSupported = !(params.disableStream);
  38896. this._contentLength = params.length;
  38897. this._fullRequestReader = null;
  38898. this._rangeReaders = [];
  38899. msgHandler.on('OnDataRange', this._onReceiveData.bind(this));
  38900. msgHandler.on('OnDataProgress', this._onProgress.bind(this));
  38901. }
  38902. PDFWorkerStream.prototype = {
  38903. _onReceiveData: function PDFWorkerStream_onReceiveData(args) {
  38904. if (args.begin === undefined) {
  38905. if (this._fullRequestReader) {
  38906. this._fullRequestReader._enqueue(args.chunk);
  38907. } else {
  38908. this._queuedChunks.push(args.chunk);
  38909. }
  38910. } else {
  38911. var found = this._rangeReaders.some(function (rangeReader) {
  38912. if (rangeReader._begin !== args.begin) {
  38913. return false;
  38914. }
  38915. rangeReader._enqueue(args.chunk);
  38916. return true;
  38917. });
  38918. assert(found);
  38919. }
  38920. },
  38921. _onProgress: function PDFWorkerStream_onProgress(evt) {
  38922. if (this._rangeReaders.length > 0) {
  38923. // Reporting to first range reader.
  38924. var firstReader = this._rangeReaders[0];
  38925. if (firstReader.onProgress) {
  38926. firstReader.onProgress({loaded: evt.loaded});
  38927. }
  38928. }
  38929. },
  38930. _removeRangeReader: function PDFWorkerStream_removeRangeReader(reader) {
  38931. var i = this._rangeReaders.indexOf(reader);
  38932. if (i >= 0) {
  38933. this._rangeReaders.splice(i, 1);
  38934. }
  38935. },
  38936. getFullReader: function PDFWorkerStream_getFullReader() {
  38937. assert(!this._fullRequestReader);
  38938. var queuedChunks = this._queuedChunks;
  38939. this._queuedChunks = null;
  38940. return new PDFWorkerStreamReader(this, queuedChunks);
  38941. },
  38942. getRangeReader: function PDFWorkerStream_getRangeReader(begin, end) {
  38943. var reader = new PDFWorkerStreamRangeReader(this, begin, end);
  38944. this._msgHandler.send('RequestDataRange', { begin: begin, end: end });
  38945. this._rangeReaders.push(reader);
  38946. return reader;
  38947. },
  38948. cancelAllRequests: function PDFWorkerStream_cancelAllRequests(reason) {
  38949. if (this._fullRequestReader) {
  38950. this._fullRequestReader.cancel(reason);
  38951. }
  38952. var readers = this._rangeReaders.slice(0);
  38953. readers.forEach(function (rangeReader) {
  38954. rangeReader.cancel(reason);
  38955. });
  38956. }
  38957. };
  38958. /** @implements {IPDFStreamReader} */
  38959. function PDFWorkerStreamReader(stream, queuedChunks) {
  38960. this._stream = stream;
  38961. this._done = false;
  38962. this._queuedChunks = queuedChunks || [];
  38963. this._requests = [];
  38964. this._headersReady = Promise.resolve();
  38965. stream._fullRequestReader = this;
  38966. this.onProgress = null; // not used
  38967. }
  38968. PDFWorkerStreamReader.prototype = {
  38969. _enqueue: function PDFWorkerStreamReader_enqueue(chunk) {
  38970. if (this._done) {
  38971. return; // ignore new data
  38972. }
  38973. if (this._requests.length > 0) {
  38974. var requestCapability = this._requests.shift();
  38975. requestCapability.resolve({value: chunk, done: false});
  38976. return;
  38977. }
  38978. this._queuedChunks.push(chunk);
  38979. },
  38980. get headersReady() {
  38981. return this._headersReady;
  38982. },
  38983. get isRangeSupported() {
  38984. return this._stream._isRangeSupported;
  38985. },
  38986. get isStreamingSupported() {
  38987. return this._stream._isStreamingSupported;
  38988. },
  38989. get contentLength() {
  38990. return this._stream._contentLength;
  38991. },
  38992. read: function PDFWorkerStreamReader_read() {
  38993. if (this._queuedChunks.length > 0) {
  38994. var chunk = this._queuedChunks.shift();
  38995. return Promise.resolve({value: chunk, done: false});
  38996. }
  38997. if (this._done) {
  38998. return Promise.resolve({value: undefined, done: true});
  38999. }
  39000. var requestCapability = createPromiseCapability();
  39001. this._requests.push(requestCapability);
  39002. return requestCapability.promise;
  39003. },
  39004. cancel: function PDFWorkerStreamReader_cancel(reason) {
  39005. this._done = true;
  39006. this._requests.forEach(function (requestCapability) {
  39007. requestCapability.resolve({value: undefined, done: true});
  39008. });
  39009. this._requests = [];
  39010. }
  39011. };
  39012. /** @implements {IPDFStreamRangeReader} */
  39013. function PDFWorkerStreamRangeReader(stream, begin, end) {
  39014. this._stream = stream;
  39015. this._begin = begin;
  39016. this._end = end;
  39017. this._queuedChunk = null;
  39018. this._requests = [];
  39019. this._done = false;
  39020. this.onProgress = null;
  39021. }
  39022. PDFWorkerStreamRangeReader.prototype = {
  39023. _enqueue: function PDFWorkerStreamRangeReader_enqueue(chunk) {
  39024. if (this._done) {
  39025. return; // ignore new data
  39026. }
  39027. if (this._requests.length === 0) {
  39028. this._queuedChunk = chunk;
  39029. } else {
  39030. var requestsCapability = this._requests.shift();
  39031. requestsCapability.resolve({value: chunk, done: false});
  39032. this._requests.forEach(function (requestCapability) {
  39033. requestCapability.resolve({value: undefined, done: true});
  39034. });
  39035. this._requests = [];
  39036. }
  39037. this._done = true;
  39038. this._stream._removeRangeReader(this);
  39039. },
  39040. get isStreamingSupported() {
  39041. return false;
  39042. },
  39043. read: function PDFWorkerStreamRangeReader_read() {
  39044. if (this._queuedChunk) {
  39045. return Promise.resolve({value: this._queuedChunk, done: false});
  39046. }
  39047. if (this._done) {
  39048. return Promise.resolve({value: undefined, done: true});
  39049. }
  39050. var requestCapability = createPromiseCapability();
  39051. this._requests.push(requestCapability);
  39052. return requestCapability.promise;
  39053. },
  39054. cancel: function PDFWorkerStreamRangeReader_cancel(reason) {
  39055. this._done = true;
  39056. this._requests.forEach(function (requestCapability) {
  39057. requestCapability.resolve({value: undefined, done: true});
  39058. });
  39059. this._requests = [];
  39060. this._stream._removeRangeReader(this);
  39061. }
  39062. };
  39063. return PDFWorkerStream;
  39064. })();
  39065. /** @type IPDFStream */
  39066. var PDFNetworkStream;
  39067. /**
  39068. * Sets PDFNetworkStream class to be used as alternative PDF data transport.
  39069. * @param {IPDFStream} cls - the PDF data transport.
  39070. */
  39071. function setPDFNetworkStreamClass(cls) {
  39072. PDFNetworkStream = cls;
  39073. }
  39074. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  39075. setup: function wphSetup(handler, port) {
  39076. var testMessageProcessed = false;
  39077. handler.on('test', function wphSetupTest(data) {
  39078. if (testMessageProcessed) {
  39079. return; // we already processed 'test' message once
  39080. }
  39081. testMessageProcessed = true;
  39082. // check if Uint8Array can be sent to worker
  39083. if (!(data instanceof Uint8Array)) {
  39084. handler.send('test', 'main', false);
  39085. return;
  39086. }
  39087. // making sure postMessage transfers are working
  39088. var supportTransfers = data[0] === 255;
  39089. handler.postMessageTransfers = supportTransfers;
  39090. // check if the response property is supported by xhr
  39091. var xhr = new XMLHttpRequest();
  39092. var responseExists = 'response' in xhr;
  39093. // check if the property is actually implemented
  39094. try {
  39095. var dummy = xhr.responseType;
  39096. } catch (e) {
  39097. responseExists = false;
  39098. }
  39099. if (!responseExists) {
  39100. handler.send('test', false);
  39101. return;
  39102. }
  39103. handler.send('test', {
  39104. supportTypedArray: true,
  39105. supportTransfers: supportTransfers
  39106. });
  39107. });
  39108. handler.on('GetDocRequest', function wphSetupDoc(data) {
  39109. return WorkerMessageHandler.createDocumentHandler(data, port);
  39110. });
  39111. },
  39112. createDocumentHandler: function wphCreateDocumentHandler(docParams, port) {
  39113. // This context is actually holds references on pdfManager and handler,
  39114. // until the latter is destroyed.
  39115. var pdfManager;
  39116. var terminated = false;
  39117. var cancelXHRs = null;
  39118. var WorkerTasks = [];
  39119. var docId = docParams.docId;
  39120. var workerHandlerName = docParams.docId + '_worker';
  39121. var handler = new MessageHandler(workerHandlerName, docId, port);
  39122. function ensureNotTerminated() {
  39123. if (terminated) {
  39124. throw new Error('Worker was terminated');
  39125. }
  39126. }
  39127. function startWorkerTask(task) {
  39128. WorkerTasks.push(task);
  39129. }
  39130. function finishWorkerTask(task) {
  39131. task.finish();
  39132. var i = WorkerTasks.indexOf(task);
  39133. WorkerTasks.splice(i, 1);
  39134. }
  39135. function loadDocument(recoveryMode) {
  39136. var loadDocumentCapability = createPromiseCapability();
  39137. var parseSuccess = function parseSuccess() {
  39138. var numPagesPromise = pdfManager.ensureDoc('numPages');
  39139. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  39140. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  39141. Promise.all([numPagesPromise, fingerprintPromise,
  39142. encryptedPromise]).then(function onDocReady(results) {
  39143. var doc = {
  39144. numPages: results[0],
  39145. fingerprint: results[1],
  39146. encrypted: !!results[2],
  39147. };
  39148. loadDocumentCapability.resolve(doc);
  39149. },
  39150. parseFailure);
  39151. };
  39152. var parseFailure = function parseFailure(e) {
  39153. loadDocumentCapability.reject(e);
  39154. };
  39155. pdfManager.ensureDoc('checkHeader', []).then(function() {
  39156. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  39157. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  39158. parseSuccess, parseFailure);
  39159. }, parseFailure);
  39160. }, parseFailure);
  39161. return loadDocumentCapability.promise;
  39162. }
  39163. function getPdfManager(data) {
  39164. var pdfManagerCapability = createPromiseCapability();
  39165. var pdfManager;
  39166. var source = data.source;
  39167. if (source.data) {
  39168. try {
  39169. pdfManager = new LocalPdfManager(docId, source.data, source.password);
  39170. pdfManagerCapability.resolve(pdfManager);
  39171. } catch (ex) {
  39172. pdfManagerCapability.reject(ex);
  39173. }
  39174. return pdfManagerCapability.promise;
  39175. }
  39176. var pdfStream;
  39177. try {
  39178. if (source.chunkedViewerLoading) {
  39179. pdfStream = new PDFWorkerStream(source, handler);
  39180. } else {
  39181. assert(PDFNetworkStream, 'pdfjs/core/network module is not loaded');
  39182. pdfStream = new PDFNetworkStream(data);
  39183. }
  39184. } catch (ex) {
  39185. pdfManagerCapability.reject(ex);
  39186. return pdfManagerCapability.promise;
  39187. }
  39188. var fullRequest = pdfStream.getFullReader();
  39189. fullRequest.headersReady.then(function () {
  39190. if (!fullRequest.isStreamingSupported ||
  39191. !fullRequest.isRangeSupported) {
  39192. // If stream or range are disabled, it's our only way to report
  39193. // loading progress.
  39194. fullRequest.onProgress = function (evt) {
  39195. handler.send('DocProgress', {
  39196. loaded: evt.loaded,
  39197. total: evt.total
  39198. });
  39199. };
  39200. }
  39201. if (!fullRequest.isRangeSupported) {
  39202. return;
  39203. }
  39204. // We don't need auto-fetch when streaming is enabled.
  39205. var disableAutoFetch = source.disableAutoFetch ||
  39206. fullRequest.isStreamingSupported;
  39207. pdfManager = new NetworkPdfManager(docId, pdfStream, {
  39208. msgHandler: handler,
  39209. url: source.url,
  39210. password: source.password,
  39211. length: fullRequest.contentLength,
  39212. disableAutoFetch: disableAutoFetch,
  39213. rangeChunkSize: source.rangeChunkSize
  39214. });
  39215. pdfManagerCapability.resolve(pdfManager);
  39216. cancelXHRs = null;
  39217. }).catch(function (reason) {
  39218. pdfManagerCapability.reject(reason);
  39219. cancelXHRs = null;
  39220. });
  39221. var cachedChunks = [], loaded = 0;
  39222. var flushChunks = function () {
  39223. var pdfFile = arraysToBytes(cachedChunks);
  39224. if (source.length && pdfFile.length !== source.length) {
  39225. warn('reported HTTP length is different from actual');
  39226. }
  39227. // the data is array, instantiating directly from it
  39228. try {
  39229. pdfManager = new LocalPdfManager(docId, pdfFile, source.password);
  39230. pdfManagerCapability.resolve(pdfManager);
  39231. } catch (ex) {
  39232. pdfManagerCapability.reject(ex);
  39233. }
  39234. cachedChunks = [];
  39235. };
  39236. var readPromise = new Promise(function (resolve, reject) {
  39237. var readChunk = function (chunk) {
  39238. try {
  39239. ensureNotTerminated();
  39240. if (chunk.done) {
  39241. if (!pdfManager) {
  39242. flushChunks();
  39243. }
  39244. cancelXHRs = null;
  39245. return;
  39246. }
  39247. var data = chunk.value;
  39248. loaded += arrayByteLength(data);
  39249. if (!fullRequest.isStreamingSupported) {
  39250. handler.send('DocProgress', {
  39251. loaded: loaded,
  39252. total: Math.max(loaded, fullRequest.contentLength || 0)
  39253. });
  39254. }
  39255. if (pdfManager) {
  39256. pdfManager.sendProgressiveData(data);
  39257. } else {
  39258. cachedChunks.push(data);
  39259. }
  39260. fullRequest.read().then(readChunk, reject);
  39261. } catch (e) {
  39262. reject(e);
  39263. }
  39264. };
  39265. fullRequest.read().then(readChunk, reject);
  39266. });
  39267. readPromise.catch(function (e) {
  39268. pdfManagerCapability.reject(e);
  39269. cancelXHRs = null;
  39270. });
  39271. cancelXHRs = function () {
  39272. pdfStream.cancelAllRequests('abort');
  39273. };
  39274. return pdfManagerCapability.promise;
  39275. }
  39276. var setupDoc = function(data) {
  39277. var onSuccess = function(doc) {
  39278. ensureNotTerminated();
  39279. handler.send('GetDoc', { pdfInfo: doc });
  39280. };
  39281. var onFailure = function(e) {
  39282. if (e instanceof PasswordException) {
  39283. if (e.code === PasswordResponses.NEED_PASSWORD) {
  39284. handler.send('NeedPassword', e);
  39285. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  39286. handler.send('IncorrectPassword', e);
  39287. }
  39288. } else if (e instanceof InvalidPDFException) {
  39289. handler.send('InvalidPDF', e);
  39290. } else if (e instanceof MissingPDFException) {
  39291. handler.send('MissingPDF', e);
  39292. } else if (e instanceof UnexpectedResponseException) {
  39293. handler.send('UnexpectedResponse', e);
  39294. } else {
  39295. handler.send('UnknownError',
  39296. new UnknownErrorException(e.message, e.toString()));
  39297. }
  39298. };
  39299. ensureNotTerminated();
  39300. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  39301. -1 : data.maxImageSize;
  39302. PDFJS.disableFontFace = data.disableFontFace;
  39303. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  39304. PDFJS.verbosity = data.verbosity;
  39305. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  39306. null : data.cMapUrl;
  39307. PDFJS.cMapPacked = data.cMapPacked === true;
  39308. getPdfManager(data).then(function (newPdfManager) {
  39309. if (terminated) {
  39310. // We were in a process of setting up the manager, but it got
  39311. // terminated in the middle.
  39312. newPdfManager.terminate();
  39313. throw new Error('Worker was terminated');
  39314. }
  39315. pdfManager = newPdfManager;
  39316. handler.send('PDFManagerReady', null);
  39317. pdfManager.onLoadedStream().then(function(stream) {
  39318. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  39319. });
  39320. }).then(function pdfManagerReady() {
  39321. ensureNotTerminated();
  39322. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  39323. ensureNotTerminated();
  39324. // Try again with recoveryMode == true
  39325. if (!(ex instanceof XRefParseException)) {
  39326. if (ex instanceof PasswordException) {
  39327. // after password exception prepare to receive a new password
  39328. // to repeat loading
  39329. pdfManager.passwordChanged().then(pdfManagerReady);
  39330. }
  39331. onFailure(ex);
  39332. return;
  39333. }
  39334. pdfManager.requestLoadedStream();
  39335. pdfManager.onLoadedStream().then(function() {
  39336. ensureNotTerminated();
  39337. loadDocument(true).then(onSuccess, onFailure);
  39338. });
  39339. }, onFailure);
  39340. }, onFailure);
  39341. };
  39342. handler.on('GetPage', function wphSetupGetPage(data) {
  39343. return pdfManager.getPage(data.pageIndex).then(function(page) {
  39344. var rotatePromise = pdfManager.ensure(page, 'rotate');
  39345. var refPromise = pdfManager.ensure(page, 'ref');
  39346. var viewPromise = pdfManager.ensure(page, 'view');
  39347. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  39348. function(results) {
  39349. return {
  39350. rotate: results[0],
  39351. ref: results[1],
  39352. view: results[2]
  39353. };
  39354. });
  39355. });
  39356. });
  39357. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  39358. var ref = new Ref(data.ref.num, data.ref.gen);
  39359. var catalog = pdfManager.pdfDocument.catalog;
  39360. return catalog.getPageIndex(ref);
  39361. });
  39362. handler.on('GetDestinations',
  39363. function wphSetupGetDestinations(data) {
  39364. return pdfManager.ensureCatalog('destinations');
  39365. }
  39366. );
  39367. handler.on('GetDestination',
  39368. function wphSetupGetDestination(data) {
  39369. return pdfManager.ensureCatalog('getDestination', [data.id]);
  39370. }
  39371. );
  39372. handler.on('GetPageLabels',
  39373. function wphSetupGetPageLabels(data) {
  39374. return pdfManager.ensureCatalog('pageLabels');
  39375. }
  39376. );
  39377. handler.on('GetAttachments',
  39378. function wphSetupGetAttachments(data) {
  39379. return pdfManager.ensureCatalog('attachments');
  39380. }
  39381. );
  39382. handler.on('GetJavaScript',
  39383. function wphSetupGetJavaScript(data) {
  39384. return pdfManager.ensureCatalog('javaScript');
  39385. }
  39386. );
  39387. handler.on('GetOutline',
  39388. function wphSetupGetOutline(data) {
  39389. return pdfManager.ensureCatalog('documentOutline');
  39390. }
  39391. );
  39392. handler.on('GetMetadata',
  39393. function wphSetupGetMetadata(data) {
  39394. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  39395. pdfManager.ensureCatalog('metadata')]);
  39396. }
  39397. );
  39398. handler.on('GetData', function wphSetupGetData(data) {
  39399. pdfManager.requestLoadedStream();
  39400. return pdfManager.onLoadedStream().then(function(stream) {
  39401. return stream.bytes;
  39402. });
  39403. });
  39404. handler.on('GetStats',
  39405. function wphSetupGetStats(data) {
  39406. return pdfManager.pdfDocument.xref.stats;
  39407. }
  39408. );
  39409. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  39410. pdfManager.updatePassword(data);
  39411. });
  39412. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  39413. return pdfManager.getPage(data.pageIndex).then(function(page) {
  39414. return pdfManager.ensure(page, 'getAnnotationsData', [data.intent]);
  39415. });
  39416. });
  39417. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  39418. var pageIndex = data.pageIndex;
  39419. pdfManager.getPage(pageIndex).then(function(page) {
  39420. var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
  39421. startWorkerTask(task);
  39422. var pageNum = pageIndex + 1;
  39423. var start = Date.now();
  39424. // Pre compile the pdf page and fetch the fonts/images.
  39425. page.getOperatorList(handler, task, data.intent).then(
  39426. function(operatorList) {
  39427. finishWorkerTask(task);
  39428. info('page=' + pageNum + ' - getOperatorList: time=' +
  39429. (Date.now() - start) + 'ms, len=' + operatorList.totalLength);
  39430. }, function(e) {
  39431. finishWorkerTask(task);
  39432. if (task.terminated) {
  39433. return; // ignoring errors from the terminated thread
  39434. }
  39435. // For compatibility with older behavior, generating unknown
  39436. // unsupported feature notification on errors.
  39437. handler.send('UnsupportedFeature',
  39438. {featureId: UNSUPPORTED_FEATURES.unknown});
  39439. var minimumStackMessage =
  39440. 'worker.js: while trying to getPage() and getOperatorList()';
  39441. var wrappedException;
  39442. // Turn the error into an obj that can be serialized
  39443. if (typeof e === 'string') {
  39444. wrappedException = {
  39445. message: e,
  39446. stack: minimumStackMessage
  39447. };
  39448. } else if (typeof e === 'object') {
  39449. wrappedException = {
  39450. message: e.message || e.toString(),
  39451. stack: e.stack || minimumStackMessage
  39452. };
  39453. } else {
  39454. wrappedException = {
  39455. message: 'Unknown exception type: ' + (typeof e),
  39456. stack: minimumStackMessage
  39457. };
  39458. }
  39459. handler.send('PageError', {
  39460. pageNum: pageNum,
  39461. error: wrappedException,
  39462. intent: data.intent
  39463. });
  39464. });
  39465. });
  39466. }, this);
  39467. handler.on('GetTextContent', function wphExtractText(data) {
  39468. var pageIndex = data.pageIndex;
  39469. var normalizeWhitespace = data.normalizeWhitespace;
  39470. return pdfManager.getPage(pageIndex).then(function(page) {
  39471. var task = new WorkerTask('GetTextContent: page ' + pageIndex);
  39472. startWorkerTask(task);
  39473. var pageNum = pageIndex + 1;
  39474. var start = Date.now();
  39475. return page.extractTextContent(task, normalizeWhitespace).then(
  39476. function(textContent) {
  39477. finishWorkerTask(task);
  39478. info('text indexing: page=' + pageNum + ' - time=' +
  39479. (Date.now() - start) + 'ms');
  39480. return textContent;
  39481. }, function (reason) {
  39482. finishWorkerTask(task);
  39483. if (task.terminated) {
  39484. return; // ignoring errors from the terminated thread
  39485. }
  39486. throw reason;
  39487. });
  39488. });
  39489. });
  39490. handler.on('Cleanup', function wphCleanup(data) {
  39491. return pdfManager.cleanup();
  39492. });
  39493. handler.on('Terminate', function wphTerminate(data) {
  39494. terminated = true;
  39495. if (pdfManager) {
  39496. pdfManager.terminate();
  39497. pdfManager = null;
  39498. }
  39499. if (cancelXHRs) {
  39500. cancelXHRs();
  39501. }
  39502. var waitOn = [];
  39503. WorkerTasks.forEach(function (task) {
  39504. waitOn.push(task.finished);
  39505. task.terminate();
  39506. });
  39507. return Promise.all(waitOn).then(function () {
  39508. // Notice that even if we destroying handler, resolved response promise
  39509. // must be sent back.
  39510. handler.destroy();
  39511. handler = null;
  39512. });
  39513. });
  39514. handler.on('Ready', function wphReady(data) {
  39515. setupDoc(docParams);
  39516. docParams = null; // we don't need docParams anymore -- saving memory.
  39517. });
  39518. return workerHandlerName;
  39519. }
  39520. };
  39521. function initializeWorker() {
  39522. if (!('console' in globalScope)) {
  39523. var consoleTimer = {};
  39524. var workerConsole = {
  39525. log: function log() {
  39526. var args = Array.prototype.slice.call(arguments);
  39527. globalScope.postMessage({
  39528. targetName: 'main',
  39529. action: 'console_log',
  39530. data: args
  39531. });
  39532. },
  39533. error: function error() {
  39534. var args = Array.prototype.slice.call(arguments);
  39535. globalScope.postMessage({
  39536. targetName: 'main',
  39537. action: 'console_error',
  39538. data: args
  39539. });
  39540. throw 'pdf.js execution error';
  39541. },
  39542. time: function time(name) {
  39543. consoleTimer[name] = Date.now();
  39544. },
  39545. timeEnd: function timeEnd(name) {
  39546. var time = consoleTimer[name];
  39547. if (!time) {
  39548. error('Unknown timer name ' + name);
  39549. }
  39550. this.log('Timer:', name, Date.now() - time);
  39551. }
  39552. };
  39553. globalScope.console = workerConsole;
  39554. }
  39555. var handler = new MessageHandler('worker', 'main', self);
  39556. WorkerMessageHandler.setup(handler, self);
  39557. handler.send('ready', null);
  39558. }
  39559. // Worker thread (and not node.js)?
  39560. if (typeof window === 'undefined' &&
  39561. !(typeof module !== 'undefined' && module.require)) {
  39562. initializeWorker();
  39563. }
  39564. exports.setPDFNetworkStreamClass = setPDFNetworkStreamClass;
  39565. exports.WorkerTask = WorkerTask;
  39566. exports.WorkerMessageHandler = WorkerMessageHandler;
  39567. }));
  39568. var NetworkManager = (function NetworkManagerClosure() {
  39569. var OK_RESPONSE = 200;
  39570. var PARTIAL_CONTENT_RESPONSE = 206;
  39571. function NetworkManager(url, args) {
  39572. this.url = url;
  39573. args = args || {};
  39574. this.isHttp = /^https?:/i.test(url);
  39575. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  39576. this.withCredentials = args.withCredentials || false;
  39577. this.getXhr = args.getXhr ||
  39578. function NetworkManager_getXhr() {
  39579. return new XMLHttpRequest();
  39580. };
  39581. this.currXhrId = 0;
  39582. this.pendingRequests = Object.create(null);
  39583. this.loadedRequests = Object.create(null);
  39584. }
  39585. function getArrayBuffer(xhr) {
  39586. var data = xhr.response;
  39587. if (typeof data !== 'string') {
  39588. return data;
  39589. }
  39590. var length = data.length;
  39591. var array = new Uint8Array(length);
  39592. for (var i = 0; i < length; i++) {
  39593. array[i] = data.charCodeAt(i) & 0xFF;
  39594. }
  39595. return array.buffer;
  39596. }
  39597. var supportsMozChunked = (function supportsMozChunkedClosure() {
  39598. try {
  39599. var x = new XMLHttpRequest();
  39600. // Firefox 37- required .open() to be called before setting responseType.
  39601. // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
  39602. // Even though the URL is not visited, .open() could fail if the URL is
  39603. // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
  39604. // When this error occurs, this feature detection method will mistakenly
  39605. // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
  39606. x.open('GET', 'https://example.com');
  39607. x.responseType = 'moz-chunked-arraybuffer';
  39608. return x.responseType === 'moz-chunked-arraybuffer';
  39609. } catch (e) {
  39610. return false;
  39611. }
  39612. })();
  39613. NetworkManager.prototype = {
  39614. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  39615. var args = {
  39616. begin: begin,
  39617. end: end
  39618. };
  39619. for (var prop in listeners) {
  39620. args[prop] = listeners[prop];
  39621. }
  39622. return this.request(args);
  39623. },
  39624. requestFull: function NetworkManager_requestFull(listeners) {
  39625. return this.request(listeners);
  39626. },
  39627. request: function NetworkManager_request(args) {
  39628. var xhr = this.getXhr();
  39629. var xhrId = this.currXhrId++;
  39630. var pendingRequest = this.pendingRequests[xhrId] = {
  39631. xhr: xhr
  39632. };
  39633. xhr.open('GET', this.url);
  39634. xhr.withCredentials = this.withCredentials;
  39635. for (var property in this.httpHeaders) {
  39636. var value = this.httpHeaders[property];
  39637. if (typeof value === 'undefined') {
  39638. continue;
  39639. }
  39640. xhr.setRequestHeader(property, value);
  39641. }
  39642. if (this.isHttp && 'begin' in args && 'end' in args) {
  39643. var rangeStr = args.begin + '-' + (args.end - 1);
  39644. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  39645. pendingRequest.expectedStatus = 206;
  39646. } else {
  39647. pendingRequest.expectedStatus = 200;
  39648. }
  39649. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  39650. if (useMozChunkedLoading) {
  39651. xhr.responseType = 'moz-chunked-arraybuffer';
  39652. pendingRequest.onProgressiveData = args.onProgressiveData;
  39653. pendingRequest.mozChunked = true;
  39654. } else {
  39655. xhr.responseType = 'arraybuffer';
  39656. }
  39657. if (args.onError) {
  39658. xhr.onerror = function(evt) {
  39659. args.onError(xhr.status);
  39660. };
  39661. }
  39662. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  39663. xhr.onprogress = this.onProgress.bind(this, xhrId);
  39664. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  39665. pendingRequest.onDone = args.onDone;
  39666. pendingRequest.onError = args.onError;
  39667. pendingRequest.onProgress = args.onProgress;
  39668. xhr.send(null);
  39669. return xhrId;
  39670. },
  39671. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  39672. var pendingRequest = this.pendingRequests[xhrId];
  39673. if (!pendingRequest) {
  39674. // Maybe abortRequest was called...
  39675. return;
  39676. }
  39677. if (pendingRequest.mozChunked) {
  39678. var chunk = getArrayBuffer(pendingRequest.xhr);
  39679. pendingRequest.onProgressiveData(chunk);
  39680. }
  39681. var onProgress = pendingRequest.onProgress;
  39682. if (onProgress) {
  39683. onProgress(evt);
  39684. }
  39685. },
  39686. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  39687. var pendingRequest = this.pendingRequests[xhrId];
  39688. if (!pendingRequest) {
  39689. // Maybe abortRequest was called...
  39690. return;
  39691. }
  39692. var xhr = pendingRequest.xhr;
  39693. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  39694. pendingRequest.onHeadersReceived();
  39695. delete pendingRequest.onHeadersReceived;
  39696. }
  39697. if (xhr.readyState !== 4) {
  39698. return;
  39699. }
  39700. if (!(xhrId in this.pendingRequests)) {
  39701. // The XHR request might have been aborted in onHeadersReceived()
  39702. // callback, in which case we should abort request
  39703. return;
  39704. }
  39705. delete this.pendingRequests[xhrId];
  39706. // success status == 0 can be on ftp, file and other protocols
  39707. if (xhr.status === 0 && this.isHttp) {
  39708. if (pendingRequest.onError) {
  39709. pendingRequest.onError(xhr.status);
  39710. }
  39711. return;
  39712. }
  39713. var xhrStatus = xhr.status || OK_RESPONSE;
  39714. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  39715. // "A server MAY ignore the Range header". This means it's possible to
  39716. // get a 200 rather than a 206 response from a range request.
  39717. var ok_response_on_range_request =
  39718. xhrStatus === OK_RESPONSE &&
  39719. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  39720. if (!ok_response_on_range_request &&
  39721. xhrStatus !== pendingRequest.expectedStatus) {
  39722. if (pendingRequest.onError) {
  39723. pendingRequest.onError(xhr.status);
  39724. }
  39725. return;
  39726. }
  39727. this.loadedRequests[xhrId] = true;
  39728. var chunk = getArrayBuffer(xhr);
  39729. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  39730. var rangeHeader = xhr.getResponseHeader('Content-Range');
  39731. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  39732. var begin = parseInt(matches[1], 10);
  39733. pendingRequest.onDone({
  39734. begin: begin,
  39735. chunk: chunk
  39736. });
  39737. } else if (pendingRequest.onProgressiveData) {
  39738. pendingRequest.onDone(null);
  39739. } else if (chunk) {
  39740. pendingRequest.onDone({
  39741. begin: 0,
  39742. chunk: chunk
  39743. });
  39744. } else if (pendingRequest.onError) {
  39745. pendingRequest.onError(xhr.status);
  39746. }
  39747. },
  39748. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  39749. for (var xhrId in this.pendingRequests) {
  39750. return true;
  39751. }
  39752. return false;
  39753. },
  39754. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  39755. return this.pendingRequests[xhrId].xhr;
  39756. },
  39757. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  39758. return !!(this.pendingRequests[xhrId].onProgressiveData);
  39759. },
  39760. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  39761. return xhrId in this.pendingRequests;
  39762. },
  39763. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  39764. return xhrId in this.loadedRequests;
  39765. },
  39766. abortAllRequests: function NetworkManager_abortAllRequests() {
  39767. for (var xhrId in this.pendingRequests) {
  39768. this.abortRequest(xhrId | 0);
  39769. }
  39770. },
  39771. abortRequest: function NetworkManager_abortRequest(xhrId) {
  39772. var xhr = this.pendingRequests[xhrId].xhr;
  39773. delete this.pendingRequests[xhrId];
  39774. xhr.abort();
  39775. }
  39776. };
  39777. return NetworkManager;
  39778. })();
  39779. (function (root, factory) {
  39780. {
  39781. factory((root.pdfjsCoreNetwork = {}), root.pdfjsSharedUtil,
  39782. root.pdfjsCoreWorker);
  39783. }
  39784. }(this, function (exports, sharedUtil, coreWorker) {
  39785. var assert = sharedUtil.assert;
  39786. var createPromiseCapability = sharedUtil.createPromiseCapability;
  39787. var isInt = sharedUtil.isInt;
  39788. var MissingPDFException = sharedUtil.MissingPDFException;
  39789. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  39790. /** @implements {IPDFStream} */
  39791. function PDFNetworkStream(options) {
  39792. this._options = options;
  39793. var source = options.source;
  39794. this._manager = new NetworkManager(source.url, {
  39795. httpHeaders: source.httpHeaders,
  39796. withCredentials: source.withCredentials
  39797. });
  39798. this._rangeChunkSize = source.rangeChunkSize;
  39799. this._fullRequestReader = null;
  39800. this._rangeRequestReaders = [];
  39801. }
  39802. PDFNetworkStream.prototype = {
  39803. _onRangeRequestReaderClosed:
  39804. function PDFNetworkStream_onRangeRequestReaderClosed(reader) {
  39805. var i = this._rangeRequestReaders.indexOf(reader);
  39806. if (i >= 0) {
  39807. this._rangeRequestReaders.splice(i, 1);
  39808. }
  39809. },
  39810. getFullReader: function PDFNetworkStream_getFullReader() {
  39811. assert(!this._fullRequestReader);
  39812. this._fullRequestReader =
  39813. new PDFNetworkStreamFullRequestReader(this._manager, this._options);
  39814. return this._fullRequestReader;
  39815. },
  39816. getRangeReader: function PDFNetworkStream_getRangeReader(begin, end) {
  39817. var reader = new PDFNetworkStreamRangeRequestReader(this._manager,
  39818. begin, end);
  39819. reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
  39820. this._rangeRequestReaders.push(reader);
  39821. return reader;
  39822. },
  39823. cancelAllRequests: function PDFNetworkStream_cancelAllRequests(reason) {
  39824. if (this._fullRequestReader) {
  39825. this._fullRequestReader.cancel(reason);
  39826. }
  39827. var readers = this._rangeRequestReaders.slice(0);
  39828. readers.forEach(function (reader) {
  39829. reader.cancel(reason);
  39830. });
  39831. }
  39832. };
  39833. /** @implements {IPDFStreamReader} */
  39834. function PDFNetworkStreamFullRequestReader(manager, options) {
  39835. this._manager = manager;
  39836. var source = options.source;
  39837. var args = {
  39838. onHeadersReceived: this._onHeadersReceived.bind(this),
  39839. onProgressiveData: source.disableStream ? null :
  39840. this._onProgressiveData.bind(this),
  39841. onDone: this._onDone.bind(this),
  39842. onError: this._onError.bind(this),
  39843. onProgress: this._onProgress.bind(this)
  39844. };
  39845. this._url = source.url;
  39846. this._fullRequestId = manager.requestFull(args);
  39847. this._headersReceivedCapability = createPromiseCapability();
  39848. this._disableRange = options.disableRange || false;
  39849. this._contentLength = source.length; // optional
  39850. this._rangeChunkSize = source.rangeChunkSize;
  39851. if (!this._rangeChunkSize && !this._disableRange) {
  39852. this._disableRange = true;
  39853. }
  39854. this._isStreamingSupported = false;
  39855. this._isRangeSupported = false;
  39856. this._cachedChunks = [];
  39857. this._requests = [];
  39858. this._done = false;
  39859. this._storedError = undefined;
  39860. this.onProgress = null;
  39861. }
  39862. PDFNetworkStreamFullRequestReader.prototype = {
  39863. _validateRangeRequestCapabilities: function
  39864. PDFNetworkStreamFullRequestReader_validateRangeRequestCapabilities() {
  39865. if (this._disableRange) {
  39866. return false;
  39867. }
  39868. var networkManager = this._manager;
  39869. var fullRequestXhrId = this._fullRequestId;
  39870. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  39871. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  39872. return false;
  39873. }
  39874. var contentEncoding =
  39875. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  39876. if (contentEncoding !== 'identity') {
  39877. return false;
  39878. }
  39879. var length = fullRequestXhr.getResponseHeader('Content-Length');
  39880. length = parseInt(length, 10);
  39881. if (!isInt(length)) {
  39882. return false;
  39883. }
  39884. this._contentLength = length; // setting right content length
  39885. if (length <= 2 * this._rangeChunkSize) {
  39886. // The file size is smaller than the size of two chunks, so it does
  39887. // not make any sense to abort the request and retry with a range
  39888. // request.
  39889. return false;
  39890. }
  39891. return true;
  39892. },
  39893. _onHeadersReceived:
  39894. function PDFNetworkStreamFullRequestReader_onHeadersReceived() {
  39895. if (this._validateRangeRequestCapabilities()) {
  39896. this._isRangeSupported = true;
  39897. }
  39898. var networkManager = this._manager;
  39899. var fullRequestXhrId = this._fullRequestId;
  39900. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  39901. // We can continue fetching when progressive loading is enabled,
  39902. // and we don't need the autoFetch feature.
  39903. this._isStreamingSupported = true;
  39904. } else if (this._isRangeSupported) {
  39905. // NOTE: by cancelling the full request, and then issuing range
  39906. // requests, there will be an issue for sites where you can only
  39907. // request the pdf once. However, if this is the case, then the
  39908. // server should not be returning that it can support range
  39909. // requests.
  39910. networkManager.abortRequest(fullRequestXhrId);
  39911. }
  39912. this._headersReceivedCapability.resolve();
  39913. },
  39914. _onProgressiveData:
  39915. function PDFNetworkStreamFullRequestReader_onProgressiveData(chunk) {
  39916. if (this._requests.length > 0) {
  39917. var requestCapability = this._requests.shift();
  39918. requestCapability.resolve({value: chunk, done: false});
  39919. } else {
  39920. this._cachedChunks.push(chunk);
  39921. }
  39922. },
  39923. _onDone: function PDFNetworkStreamFullRequestReader_onDone(args) {
  39924. if (args) {
  39925. this._onProgressiveData(args.chunk);
  39926. }
  39927. this._done = true;
  39928. if (this._cachedChunks.length > 0) {
  39929. return;
  39930. }
  39931. this._requests.forEach(function (requestCapability) {
  39932. requestCapability.resolve({value: undefined, done: true});
  39933. });
  39934. this._requests = [];
  39935. },
  39936. _onError: function PDFNetworkStreamFullRequestReader_onError(status) {
  39937. var url = this._url;
  39938. var exception;
  39939. if (status === 404 || status === 0 && /^file:/.test(url)) {
  39940. exception = new MissingPDFException('Missing PDF "' + url + '".');
  39941. } else {
  39942. exception = new UnexpectedResponseException(
  39943. 'Unexpected server response (' + status +
  39944. ') while retrieving PDF "' + url + '".', status);
  39945. }
  39946. this._storedError = exception;
  39947. this._headersReceivedCapability.reject(exception);
  39948. this._requests.forEach(function (requestCapability) {
  39949. requestCapability.reject(exception);
  39950. });
  39951. this._requests = [];
  39952. this._cachedChunks = [];
  39953. },
  39954. _onProgress: function PDFNetworkStreamFullRequestReader_onProgress(data) {
  39955. if (this.onProgress) {
  39956. this.onProgress({
  39957. loaded: data.loaded,
  39958. total: data.lengthComputable ? data.total : this._contentLength
  39959. });
  39960. }
  39961. },
  39962. get isRangeSupported() {
  39963. return this._isRangeSupported;
  39964. },
  39965. get isStreamingSupported() {
  39966. return this._isStreamingSupported;
  39967. },
  39968. get contentLength() {
  39969. return this._contentLength;
  39970. },
  39971. get headersReady() {
  39972. return this._headersReceivedCapability.promise;
  39973. },
  39974. read: function PDFNetworkStreamFullRequestReader_read() {
  39975. if (this._storedError) {
  39976. return Promise.reject(this._storedError);
  39977. }
  39978. if (this._cachedChunks.length > 0) {
  39979. var chunk = this._cachedChunks.shift();
  39980. return Promise.resolve(chunk);
  39981. }
  39982. if (this._done) {
  39983. return Promise.resolve({value: undefined, done: true});
  39984. }
  39985. var requestCapability = createPromiseCapability();
  39986. this._requests.push(requestCapability);
  39987. return requestCapability.promise;
  39988. },
  39989. cancel: function PDFNetworkStreamFullRequestReader_cancel(reason) {
  39990. this._done = true;
  39991. this._headersReceivedCapability.reject(reason);
  39992. this._requests.forEach(function (requestCapability) {
  39993. requestCapability.resolve({value: undefined, done: true});
  39994. });
  39995. this._requests = [];
  39996. if (this._manager.isPendingRequest(this._fullRequestId)) {
  39997. this._manager.abortRequest(this._fullRequestId);
  39998. }
  39999. this._fullRequestReader = null;
  40000. }
  40001. };
  40002. /** @implements {IPDFStreamRangeReader} */
  40003. function PDFNetworkStreamRangeRequestReader(manager, begin, end) {
  40004. this._manager = manager;
  40005. var args = {
  40006. onDone: this._onDone.bind(this),
  40007. onProgress: this._onProgress.bind(this)
  40008. };
  40009. this._requestId = manager.requestRange(begin, end, args);
  40010. this._requests = [];
  40011. this._queuedChunk = null;
  40012. this._done = false;
  40013. this.onProgress = null;
  40014. this.onClosed = null;
  40015. }
  40016. PDFNetworkStreamRangeRequestReader.prototype = {
  40017. _close: function PDFNetworkStreamRangeRequestReader_close() {
  40018. if (this.onClosed) {
  40019. this.onClosed(this);
  40020. }
  40021. },
  40022. _onDone: function PDFNetworkStreamRangeRequestReader_onDone(data) {
  40023. var chunk = data.chunk;
  40024. if (this._requests.length > 0) {
  40025. var requestCapability = this._requests.shift();
  40026. requestCapability.resolve({value: chunk, done: false});
  40027. } else {
  40028. this._queuedChunk = chunk;
  40029. }
  40030. this._done = true;
  40031. this._requests.forEach(function (requestCapability) {
  40032. requestCapability.resolve({value: undefined, done: true});
  40033. });
  40034. this._requests = [];
  40035. this._close();
  40036. },
  40037. _onProgress: function PDFNetworkStreamRangeRequestReader_onProgress(evt) {
  40038. if (!this.isStreamingSupported && this.onProgress) {
  40039. this.onProgress({
  40040. loaded: evt.loaded
  40041. });
  40042. }
  40043. },
  40044. get isStreamingSupported() {
  40045. return false; // TODO allow progressive range bytes loading
  40046. },
  40047. read: function PDFNetworkStreamRangeRequestReader_read() {
  40048. if (this._queuedChunk !== null) {
  40049. var chunk = this._queuedChunk;
  40050. this._queuedChunk = null;
  40051. return Promise.resolve({value: chunk, done: false});
  40052. }
  40053. if (this._done) {
  40054. return Promise.resolve({value: undefined, done: true});
  40055. }
  40056. var requestCapability = createPromiseCapability();
  40057. this._requests.push(requestCapability);
  40058. return requestCapability.promise;
  40059. },
  40060. cancel: function PDFNetworkStreamRangeRequestReader_cancel(reason) {
  40061. this._done = true;
  40062. this._requests.forEach(function (requestCapability) {
  40063. requestCapability.resolve({value: undefined, done: true});
  40064. });
  40065. this._requests = [];
  40066. if (this._manager.isPendingRequest(this._requestId)) {
  40067. this._manager.abortRequest(this._requestId);
  40068. }
  40069. this._close();
  40070. }
  40071. };
  40072. coreWorker.setPDFNetworkStreamClass(PDFNetworkStream);
  40073. exports.PDFNetworkStream = PDFNetworkStream;
  40074. exports.NetworkManager = NetworkManager;
  40075. }));
  40076. }).call(pdfjsLibs);
  40077. exports.PDFJS = pdfjsLibs.pdfjsSharedGlobal.PDFJS;
  40078. }));